1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.mergeSchemas = exports.isJsonSchema = void 0;
|
11 | const interface_1 = require("../interface");
|
12 | function isJsonSchema(value) {
|
13 | return interface_1.isJsonObject(value) || value === false || value === true;
|
14 | }
|
15 | exports.isJsonSchema = isJsonSchema;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function mergeSchemas(...schemas) {
|
23 | return schemas.reduce((prev, curr) => {
|
24 | if (curr === undefined) {
|
25 | return prev;
|
26 | }
|
27 | if (prev === false || curr === false) {
|
28 | return false;
|
29 | }
|
30 | else if (prev === true) {
|
31 | return curr;
|
32 | }
|
33 | else if (curr === true) {
|
34 | return prev;
|
35 | }
|
36 | else if (Array.isArray(prev.allOf)) {
|
37 | if (Array.isArray(curr.allOf)) {
|
38 | return { ...prev, allOf: [...prev.allOf, ...curr.allOf] };
|
39 | }
|
40 | else {
|
41 | return { ...prev, allOf: [...prev.allOf, curr] };
|
42 | }
|
43 | }
|
44 | else if (Array.isArray(curr.allOf)) {
|
45 | return { ...prev, allOf: [prev, ...curr.allOf] };
|
46 | }
|
47 | else {
|
48 | return { ...prev, allOf: [prev, curr] };
|
49 | }
|
50 | }, true);
|
51 | }
|
52 | exports.mergeSchemas = mergeSchemas;
|