schyma 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/App.js +26 -23
- package/dist/cjs/components/App.js.map +1 -1
- package/dist/cjs/components/Code.js +8 -5
- package/dist/cjs/components/Code.js.map +1 -1
- package/dist/cjs/components/CustomNode.js +15 -12
- package/dist/cjs/components/CustomNode.js.map +1 -1
- package/dist/cjs/components/Nodes.js +56 -54
- package/dist/cjs/components/Nodes.js.map +1 -1
- package/dist/cjs/components/Panel.js +44 -41
- package/dist/cjs/components/Panel.js.map +1 -1
- package/dist/cjs/components/Tables.js +20 -17
- package/dist/cjs/components/Tables.js.map +1 -1
- package/dist/cjs/constants/node.js +15 -12
- package/dist/cjs/constants/node.js.map +1 -1
- package/dist/cjs/helpers/__tests__/conditions.test.js +13 -11
- package/dist/cjs/helpers/__tests__/conditions.test.js.map +1 -1
- package/dist/cjs/helpers/ajv.js +12 -7
- package/dist/cjs/helpers/ajv.js.map +1 -1
- package/dist/cjs/helpers/conditions.js +5 -1
- package/dist/cjs/helpers/conditions.js.map +1 -1
- package/dist/cjs/helpers/formatRequired.js +4 -1
- package/dist/cjs/helpers/formatRequired.js.map +1 -1
- package/dist/cjs/helpers/rules.js +4 -1
- package/dist/cjs/helpers/rules.js.map +1 -1
- package/dist/cjs/icons/Loader.js +8 -5
- package/dist/cjs/icons/Loader.js.map +1 -1
- package/dist/cjs/icons/SidebarIcon.js +8 -5
- package/dist/cjs/icons/SidebarIcon.js.map +1 -1
- package/dist/cjs/index.js +5 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.js +5 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/__tests__/compositions.test.js +18 -16
- package/dist/cjs/utils/__tests__/compositions.test.js.map +1 -1
- package/dist/cjs/utils/__tests__/dagreLayout.test.js +10 -8
- package/dist/cjs/utils/__tests__/dagreLayout.test.js.map +1 -1
- package/dist/cjs/utils/__tests__/reusables.test.js +32 -30
- package/dist/cjs/utils/__tests__/reusables.test.js.map +1 -1
- package/dist/cjs/utils/compositions.js +25 -19
- package/dist/cjs/utils/compositions.js.map +1 -1
- package/dist/cjs/utils/dagreLayout.js +16 -11
- package/dist/cjs/utils/dagreLayout.js.map +1 -1
- package/dist/cjs/utils/reusables.js +28 -17
- package/dist/cjs/utils/reusables.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const reusables_1 = require("../reusables");
|
|
4
|
+
const types_1 = require("../../types");
|
|
3
5
|
describe('getCompositionType', () => {
|
|
4
6
|
it('returns OneOf for oneOf schemas', () => {
|
|
5
|
-
expect(getCompositionType({ oneOf: [] })).toBe(CompositionType.OneOf);
|
|
7
|
+
expect((0, reusables_1.getCompositionType)({ oneOf: [] })).toBe(types_1.CompositionType.OneOf);
|
|
6
8
|
});
|
|
7
9
|
it('returns AnyOf for anyOf schemas', () => {
|
|
8
|
-
expect(getCompositionType({ anyOf: [] })).toBe(CompositionType.AnyOf);
|
|
10
|
+
expect((0, reusables_1.getCompositionType)({ anyOf: [] })).toBe(types_1.CompositionType.AnyOf);
|
|
9
11
|
});
|
|
10
12
|
it('returns AllOf for allOf schemas', () => {
|
|
11
|
-
expect(getCompositionType({ allOf: [] })).toBe(CompositionType.AllOf);
|
|
13
|
+
expect((0, reusables_1.getCompositionType)({ allOf: [] })).toBe(types_1.CompositionType.AllOf);
|
|
12
14
|
});
|
|
13
15
|
it('returns Not for not schemas', () => {
|
|
14
|
-
expect(getCompositionType({ not: {} })).toBe(CompositionType.Not);
|
|
16
|
+
expect((0, reusables_1.getCompositionType)({ not: {} })).toBe(types_1.CompositionType.Not);
|
|
15
17
|
});
|
|
16
18
|
it('returns null for regular schemas', () => {
|
|
17
|
-
expect(getCompositionType({ type: 'object', properties: {} })).toBe(null);
|
|
19
|
+
expect((0, reusables_1.getCompositionType)({ type: 'object', properties: {} })).toBe(null);
|
|
18
20
|
});
|
|
19
21
|
});
|
|
20
22
|
describe('getNameFromRef', () => {
|
|
21
23
|
it('extracts name from definition ref', () => {
|
|
22
|
-
expect(nameFromRef('#/definitions/Message')).toBe('Message');
|
|
24
|
+
expect((0, reusables_1.nameFromRef)('#/definitions/Message')).toBe('Message');
|
|
23
25
|
});
|
|
24
26
|
it('extracts name from components ref', () => {
|
|
25
|
-
expect(nameFromRef('#/components/schemas/User')).toBe('User');
|
|
27
|
+
expect((0, reusables_1.nameFromRef)('#/components/schemas/User')).toBe('User');
|
|
26
28
|
});
|
|
27
29
|
// Coming back to this test... gave me an idea for external
|
|
28
30
|
// referencing
|
|
29
31
|
it('handles file refs', () => {
|
|
30
|
-
expect(nameFromRef('./common/types.json')).toBe('types');
|
|
32
|
+
expect((0, reusables_1.nameFromRef)('./common/types.json')).toBe('types');
|
|
31
33
|
});
|
|
32
34
|
});
|
|
33
35
|
describe('convertArrayToPropertyObject', () => {
|
|
34
36
|
it('uses title for named schemas', () => {
|
|
35
37
|
const schemas = [{ title: 'Queue', type: 'object' }];
|
|
36
|
-
const result = arrayToProps(schemas, 'destination');
|
|
38
|
+
const result = (0, reusables_1.arrayToProps)(schemas, 'destination');
|
|
37
39
|
expect(Object.keys(result)).toEqual(['Queue']);
|
|
38
40
|
});
|
|
39
41
|
it('uses $ref name for ref schemas', () => {
|
|
40
42
|
const schemas = [{ $ref: '#/definitions/Message' }];
|
|
41
|
-
const result = arrayToProps(schemas, 'item');
|
|
43
|
+
const result = (0, reusables_1.arrayToProps)(schemas, 'item');
|
|
42
44
|
expect(Object.keys(result)).toEqual(['Message']);
|
|
43
45
|
});
|
|
44
46
|
it('uses const discriminator for objects with const', () => {
|
|
45
47
|
const schemas = [{ properties: { type: { const: 'queue' } } }, { properties: { type: { const: 'topic' } } }];
|
|
46
|
-
const result = arrayToProps(schemas, 'destination');
|
|
48
|
+
const result = (0, reusables_1.arrayToProps)(schemas, 'destination');
|
|
47
49
|
expect(Object.keys(result)).toEqual(['queue', 'topic']);
|
|
48
50
|
});
|
|
49
51
|
it('uses primitive type as name', () => {
|
|
50
52
|
const schemas = [{ type: 'string' }, { type: 'number' }];
|
|
51
|
-
const result = arrayToProps(schemas, 'value');
|
|
53
|
+
const result = (0, reusables_1.arrayToProps)(schemas, 'value');
|
|
52
54
|
expect(Object.keys(result)).toEqual(['string', 'number']);
|
|
53
55
|
});
|
|
54
56
|
it('falls back to indexed name for unnamed object schemas', () => {
|
|
@@ -56,7 +58,7 @@ describe('convertArrayToPropertyObject', () => {
|
|
|
56
58
|
{ type: 'object', properties: { foo: {} } },
|
|
57
59
|
{ type: 'object', properties: { bar: {} } },
|
|
58
60
|
];
|
|
59
|
-
const result = arrayToProps(schemas, 'item');
|
|
61
|
+
const result = (0, reusables_1.arrayToProps)(schemas, 'item');
|
|
60
62
|
expect(Object.keys(result)).toEqual(['item 1', 'item 2']);
|
|
61
63
|
});
|
|
62
64
|
});
|
|
@@ -67,7 +69,7 @@ describe('propertiesMerge', () => {
|
|
|
67
69
|
'^x-': { type: 'string' },
|
|
68
70
|
},
|
|
69
71
|
};
|
|
70
|
-
const result = propMerge(schema, 'test');
|
|
72
|
+
const result = (0, reusables_1.propMerge)(schema, 'test');
|
|
71
73
|
expect(Object.keys(result)).toEqual(['^x-']);
|
|
72
74
|
});
|
|
73
75
|
it('flattens oneOf into merged props', () => {
|
|
@@ -77,7 +79,7 @@ describe('propertiesMerge', () => {
|
|
|
77
79
|
{ title: 'BankTransfer', type: 'object', properties: { accountNumber: { type: 'string' } } },
|
|
78
80
|
],
|
|
79
81
|
};
|
|
80
|
-
const result = propMerge(schema, 'paymentMethod');
|
|
82
|
+
const result = (0, reusables_1.propMerge)(schema, 'paymentMethod');
|
|
81
83
|
expect(Object.keys(result)).toContain('CreditCard');
|
|
82
84
|
expect(Object.keys(result)).toContain('BankTransfer');
|
|
83
85
|
});
|
|
@@ -85,8 +87,8 @@ describe('propertiesMerge', () => {
|
|
|
85
87
|
const schema = {
|
|
86
88
|
oneOf: [{ title: 'Queue', type: 'object' }],
|
|
87
89
|
};
|
|
88
|
-
const result = propMerge(schema, 'test');
|
|
89
|
-
expect(result.Queue).toHaveProperty('_compositionSource', CompositionType.OneOf);
|
|
90
|
+
const result = (0, reusables_1.propMerge)(schema, 'test');
|
|
91
|
+
expect(result.Queue).toHaveProperty('_compositionSource', types_1.CompositionType.OneOf);
|
|
90
92
|
});
|
|
91
93
|
it('tags anyOf children with _compositionSource', () => {
|
|
92
94
|
const schema = {
|
|
@@ -95,9 +97,9 @@ describe('propertiesMerge', () => {
|
|
|
95
97
|
{ title: 'SMS', type: 'object', properties: { phoneNumber: { type: 'string' } } },
|
|
96
98
|
],
|
|
97
99
|
};
|
|
98
|
-
const result = propMerge(schema, 'notification');
|
|
99
|
-
expect(result.Email).toHaveProperty('_compositionSource', CompositionType.AnyOf);
|
|
100
|
-
expect(result.SMS).toHaveProperty('_compositionSource', CompositionType.AnyOf);
|
|
100
|
+
const result = (0, reusables_1.propMerge)(schema, 'notification');
|
|
101
|
+
expect(result.Email).toHaveProperty('_compositionSource', types_1.CompositionType.AnyOf);
|
|
102
|
+
expect(result.SMS).toHaveProperty('_compositionSource', types_1.CompositionType.AnyOf);
|
|
101
103
|
});
|
|
102
104
|
it('recursively processes items schema', () => {
|
|
103
105
|
const schema = {
|
|
@@ -108,7 +110,7 @@ describe('propertiesMerge', () => {
|
|
|
108
110
|
},
|
|
109
111
|
},
|
|
110
112
|
};
|
|
111
|
-
const result = propMerge(schema, 'test');
|
|
113
|
+
const result = (0, reusables_1.propMerge)(schema, 'test');
|
|
112
114
|
expect(Object.keys(result)).toContain('name');
|
|
113
115
|
});
|
|
114
116
|
it('propagates _nestedComposition from items with composition', () => {
|
|
@@ -121,8 +123,8 @@ describe('propertiesMerge', () => {
|
|
|
121
123
|
],
|
|
122
124
|
},
|
|
123
125
|
};
|
|
124
|
-
const result = propMerge(schema, 'shapes');
|
|
125
|
-
expect(result._nestedComposition).toBe(CompositionType.OneOf);
|
|
126
|
+
const result = (0, reusables_1.propMerge)(schema, 'shapes');
|
|
127
|
+
expect(result._nestedComposition).toBe(types_1.CompositionType.OneOf);
|
|
126
128
|
});
|
|
127
129
|
it('handles if/then/else conditions', () => {
|
|
128
130
|
const schema = {
|
|
@@ -130,7 +132,7 @@ describe('propertiesMerge', () => {
|
|
|
130
132
|
then: { properties: { discount: { type: 'number' } } },
|
|
131
133
|
else: { properties: { standard: { type: 'boolean' } } },
|
|
132
134
|
};
|
|
133
|
-
const result = propMerge(schema, 'test');
|
|
135
|
+
const result = (0, reusables_1.propMerge)(schema, 'test');
|
|
134
136
|
expect(Object.keys(result)).toContain('if type = premium');
|
|
135
137
|
expect(Object.keys(result)).toContain('else (type)');
|
|
136
138
|
});
|
|
@@ -147,19 +149,19 @@ describe('propertiesMerge', () => {
|
|
|
147
149
|
],
|
|
148
150
|
},
|
|
149
151
|
};
|
|
150
|
-
const result = propMerge(schema, 'destinations');
|
|
152
|
+
const result = (0, reusables_1.propMerge)(schema, 'destinations');
|
|
151
153
|
// Should have deliveryMode from properties
|
|
152
154
|
expect(Object.keys(result)).toContain('deliveryMode');
|
|
153
155
|
// Should have queue and topic from oneOf
|
|
154
156
|
expect(Object.keys(result)).toContain('queue');
|
|
155
157
|
expect(Object.keys(result)).toContain('topic');
|
|
156
158
|
// oneOf items should be tagged
|
|
157
|
-
expect(result.queue).toHaveProperty('_compositionSource', CompositionType.OneOf);
|
|
158
|
-
expect(result.topic).toHaveProperty('_compositionSource', CompositionType.OneOf);
|
|
159
|
+
expect(result.queue).toHaveProperty('_compositionSource', types_1.CompositionType.OneOf);
|
|
160
|
+
expect(result.topic).toHaveProperty('_compositionSource', types_1.CompositionType.OneOf);
|
|
159
161
|
// deliveryMode should NOT be tagged
|
|
160
162
|
expect(result.deliveryMode).not.toHaveProperty('_compositionSource');
|
|
161
163
|
// Should propagate nested composition
|
|
162
|
-
expect(result._nestedComposition).toBe(CompositionType.OneOf);
|
|
164
|
+
expect(result._nestedComposition).toBe(types_1.CompositionType.OneOf);
|
|
163
165
|
});
|
|
164
166
|
});
|
|
165
167
|
//# sourceMappingURL=reusables.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reusables.test.js","sourceRoot":"","sources":["../../../../src/utils/__tests__/reusables.test.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"reusables.test.js","sourceRoot":"","sources":["../../../../src/utils/__tests__/reusables.test.ts"],"names":[],"mappings":";;AAAA,4CAAuF;AACvF,uCAA6C;AAE7C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,IAAA,8BAAkB,EAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAe,CAAC,KAAK,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,IAAA,8BAAkB,EAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAe,CAAC,KAAK,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,IAAA,8BAAkB,EAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAe,CAAC,KAAK,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,CAAC,IAAA,8BAAkB,EAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAe,CAAC,GAAG,CAAC,CAAA;IACnE,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C,CAAA;QAC9C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QAC9C,+BAA+B;QAC/B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,oBAAoB,EAAE,uBAAe,CAAC,KAAK,CAAC,CAAA;QAChF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,oBAAoB,EAAE,uBAAe,CAAC,KAAK,CAAC,CAAA;QAChF,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAA;QACpE,sCAAsC;QACtC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,uBAAe,CAAC,KAAK,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleCompositions = void 0;
|
|
4
|
+
exports.getCompositionType = getCompositionType;
|
|
5
|
+
exports.arrayToProps = arrayToProps;
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const reusables_1 = require("./reusables");
|
|
8
|
+
const conditions_1 = require("../helpers/conditions");
|
|
9
|
+
function getCompositionType(schema) {
|
|
5
10
|
if (schema.oneOf)
|
|
6
|
-
return CompositionType.OneOf;
|
|
11
|
+
return types_1.CompositionType.OneOf;
|
|
7
12
|
if (schema.anyOf)
|
|
8
|
-
return CompositionType.AnyOf;
|
|
13
|
+
return types_1.CompositionType.AnyOf;
|
|
9
14
|
if (schema.allOf)
|
|
10
|
-
return CompositionType.AllOf;
|
|
15
|
+
return types_1.CompositionType.AllOf;
|
|
11
16
|
if (schema.not)
|
|
12
|
-
return CompositionType.Not;
|
|
17
|
+
return types_1.CompositionType.Not;
|
|
13
18
|
return null;
|
|
14
19
|
}
|
|
15
20
|
function getSchemaName(schema, label, index) {
|
|
@@ -17,7 +22,7 @@ function getSchemaName(schema, label, index) {
|
|
|
17
22
|
return schema.title;
|
|
18
23
|
}
|
|
19
24
|
if (schema.$ref) {
|
|
20
|
-
return nameFromRef(schema.$ref);
|
|
25
|
+
return (0, reusables_1.nameFromRef)(schema.$ref);
|
|
21
26
|
}
|
|
22
27
|
if (schema.properties) {
|
|
23
28
|
for (const key of Object.keys(schema.properties)) {
|
|
@@ -35,7 +40,7 @@ function getSchemaName(schema, label, index) {
|
|
|
35
40
|
}
|
|
36
41
|
return `${label} ${index + 1}`;
|
|
37
42
|
}
|
|
38
|
-
|
|
43
|
+
function arrayToProps(props, label) {
|
|
39
44
|
const propObj = {};
|
|
40
45
|
for (let i = 0; i < props.length; i++) {
|
|
41
46
|
const name = getSchemaName(props[i], label, i);
|
|
@@ -43,15 +48,15 @@ export function arrayToProps(props, label) {
|
|
|
43
48
|
}
|
|
44
49
|
return propObj;
|
|
45
50
|
}
|
|
46
|
-
|
|
51
|
+
const handleCompositions = (schema, mergedProps, label) => {
|
|
47
52
|
if (schema.allOf) {
|
|
48
53
|
let propObj = {};
|
|
49
54
|
for (const item of schema.allOf) {
|
|
50
55
|
if (item.if) {
|
|
51
|
-
handleConditions(item, propObj);
|
|
56
|
+
(0, conditions_1.handleConditions)(item, propObj);
|
|
52
57
|
}
|
|
53
58
|
else if (item.$ref) {
|
|
54
|
-
const name = nameFromRef(item.$ref);
|
|
59
|
+
const name = (0, reusables_1.nameFromRef)(item.$ref);
|
|
55
60
|
propObj[name] = item;
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
@@ -63,7 +68,7 @@ export const handleCompositions = (schema, mergedProps, label) => {
|
|
|
63
68
|
}
|
|
64
69
|
if (item.additionalProperties && typeof item.additionalProperties === 'object') {
|
|
65
70
|
if (item.additionalProperties.$ref) {
|
|
66
|
-
const name = nameFromRef(item.additionalProperties.$ref);
|
|
71
|
+
const name = (0, reusables_1.nameFromRef)(item.additionalProperties.$ref);
|
|
67
72
|
propObj[name] = item.additionalProperties;
|
|
68
73
|
}
|
|
69
74
|
}
|
|
@@ -77,13 +82,13 @@ export const handleCompositions = (schema, mergedProps, label) => {
|
|
|
77
82
|
}
|
|
78
83
|
if (schema.oneOf || schema.anyOf) {
|
|
79
84
|
const items = schema.oneOf || schema.anyOf;
|
|
80
|
-
const compositionType = schema.oneOf ? CompositionType.OneOf : CompositionType.AnyOf;
|
|
85
|
+
const compositionType = schema.oneOf ? types_1.CompositionType.OneOf : types_1.CompositionType.AnyOf;
|
|
81
86
|
for (let i = 0; i < items.length; i++) {
|
|
82
87
|
const item = items[i];
|
|
83
88
|
// Only flatten if item is ONLY a condition (no other schema content)
|
|
84
89
|
const isOnlyCondition = item.if && !item.title && !item.properties && !item.$ref && !item.type;
|
|
85
90
|
if (isOnlyCondition) {
|
|
86
|
-
handleConditions(item, mergedProps);
|
|
91
|
+
(0, conditions_1.handleConditions)(item, mergedProps);
|
|
87
92
|
}
|
|
88
93
|
else {
|
|
89
94
|
const name = getSchemaName(item, label, i);
|
|
@@ -93,12 +98,13 @@ export const handleCompositions = (schema, mergedProps, label) => {
|
|
|
93
98
|
}
|
|
94
99
|
if (schema.not) {
|
|
95
100
|
if (schema.not.$ref) {
|
|
96
|
-
const name = nameFromRef(schema.not.$ref);
|
|
97
|
-
mergedProps[name] = Object.assign(Object.assign({}, schema.not), { _compositionSource: CompositionType.Not });
|
|
101
|
+
const name = (0, reusables_1.nameFromRef)(schema.not.$ref);
|
|
102
|
+
mergedProps[name] = Object.assign(Object.assign({}, schema.not), { _compositionSource: types_1.CompositionType.Not });
|
|
98
103
|
}
|
|
99
104
|
else if (schema.not.type) {
|
|
100
|
-
mergedProps[schema.not.type] = Object.assign(Object.assign({}, schema.not), { _compositionSource: CompositionType.Not });
|
|
105
|
+
mergedProps[schema.not.type] = Object.assign(Object.assign({}, schema.not), { _compositionSource: types_1.CompositionType.Not });
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
};
|
|
109
|
+
exports.handleCompositions = handleCompositions;
|
|
104
110
|
//# sourceMappingURL=compositions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compositions.js","sourceRoot":"","sources":["../../../src/utils/compositions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compositions.js","sourceRoot":"","sources":["../../../src/utils/compositions.ts"],"names":[],"mappings":";;;AAIA,gDAMC;AA0BD,oCAOC;AA3CD,oCAA0C;AAC1C,2CAAyC;AACzC,sDAAwD;AAExD,SAAgB,kBAAkB,CAAC,MAAW;IAC5C,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,uBAAe,CAAC,KAAK,CAAA;IAC9C,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,uBAAe,CAAC,KAAK,CAAA;IAC9C,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,uBAAe,CAAC,KAAK,CAAA;IAC9C,IAAI,MAAM,CAAC,GAAG;QAAE,OAAO,uBAAe,CAAC,GAAG,CAAA;IAC1C,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,aAAa,CAAC,MAAW,EAAE,KAAa,EAAE,KAAa;IAC9D,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC,KAAK,CAAA;IACrB,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,IAAA,uBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YAC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;AAvDY,QAAA,kBAAkB,sBAuD9B"}
|
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLayoutedElements = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const reactflow_1 = require("reactflow");
|
|
6
|
+
const node_1 = require("../constants/node");
|
|
7
|
+
const dagre_1 = tslib_1.__importDefault(require("@dagrejs/dagre"));
|
|
8
|
+
const getLayoutedElements = (nodes, edges, direction = 'LR') => {
|
|
9
|
+
const dagreGraph = new dagre_1.default.graphlib.Graph();
|
|
6
10
|
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
|
7
11
|
dagreGraph.setGraph({ rankdir: direction });
|
|
8
12
|
nodes.forEach((node) => {
|
|
9
|
-
dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });
|
|
13
|
+
dagreGraph.setNode(node.id, { width: node_1.nodeWidth, height: node_1.nodeHeight });
|
|
10
14
|
});
|
|
11
15
|
edges.forEach((edge) => {
|
|
12
16
|
dagreGraph.setEdge(edge.source, edge.target);
|
|
13
17
|
});
|
|
14
|
-
|
|
18
|
+
dagre_1.default.layout(dagreGraph, {
|
|
15
19
|
disableOptimalOrderHeuristic: true,
|
|
16
20
|
});
|
|
17
21
|
nodes.forEach((node) => {
|
|
18
22
|
const nodeId = node.id;
|
|
19
23
|
const nodeWithPosition = dagreGraph.node(nodeId);
|
|
20
|
-
node.sourcePosition = Position.Right;
|
|
21
|
-
node.targetPosition = Position.Left;
|
|
24
|
+
node.sourcePosition = reactflow_1.Position.Right;
|
|
25
|
+
node.targetPosition = reactflow_1.Position.Left;
|
|
22
26
|
node.position = {
|
|
23
|
-
x: nodeWithPosition.x - nodeWidth / 3,
|
|
24
|
-
y: nodeWithPosition.y - nodeHeight / 3,
|
|
27
|
+
x: nodeWithPosition.x - node_1.nodeWidth / 3,
|
|
28
|
+
y: nodeWithPosition.y - node_1.nodeHeight / 3,
|
|
25
29
|
};
|
|
26
30
|
return node;
|
|
27
31
|
});
|
|
28
32
|
return { nodes, edges };
|
|
29
33
|
};
|
|
34
|
+
exports.getLayoutedElements = getLayoutedElements;
|
|
30
35
|
//# sourceMappingURL=dagreLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dagreLayout.js","sourceRoot":"","sources":["../../../src/utils/dagreLayout.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"dagreLayout.js","sourceRoot":"","sources":["../../../src/utils/dagreLayout.ts"],"names":[],"mappings":";;;;AAAA,yCAAgD;AAChD,4CAAyD;AACzD,mEAAkC;AAE3B,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAE,KAAa,EAAE,SAAS,GAAG,IAAI,EAAE,EAAE;IACpF,MAAM,UAAU,GAAG,IAAI,eAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IAE7C,UAAU,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1C,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;IAE3C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAS,EAAE,MAAM,EAAE,iBAAU,EAAE,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,EAAE;QAC3B,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IAEF,eAAK,CAAC,MAAM,CAAC,UAAU,EAAE;QACvB,4BAA4B,EAAE,IAAI;KACnC,CAAC,CAAA;IAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,EAAE;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;QACtB,MAAM,gBAAgB,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAChD,IAAI,CAAC,cAAc,GAAG,oBAAQ,CAAC,KAAK,CAAA;QACpC,IAAI,CAAC,cAAc,GAAG,oBAAQ,CAAC,IAAI,CAAA;QACnC,IAAI,CAAC,QAAQ,GAAG;YACd,CAAC,EAAE,gBAAgB,CAAC,CAAC,GAAG,gBAAS,GAAG,CAAC;YACrC,CAAC,EAAE,gBAAgB,CAAC,CAAC,GAAG,iBAAU,GAAG,CAAC;SACvC,CAAA;QACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzB,CAAC,CAAA;AA/BY,QAAA,mBAAmB,uBA+B/B"}
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arrayToProps = exports.getCompositionType = void 0;
|
|
4
|
+
exports.resolveRef = resolveRef;
|
|
5
|
+
exports.nameFromRef = nameFromRef;
|
|
6
|
+
exports.propMerge = propMerge;
|
|
7
|
+
exports.removeElementsByParent = removeElementsByParent;
|
|
8
|
+
exports.removeEdgesByParent = removeEdgesByParent;
|
|
9
|
+
exports.retrieveObj = retrieveObj;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const reference_resolver_1 = tslib_1.__importDefault(require("@json-schema-tools/reference-resolver"));
|
|
12
|
+
const conditions_1 = require("../helpers/conditions");
|
|
13
|
+
const compositions_1 = require("./compositions");
|
|
5
14
|
// Re-export for backwards compatibility
|
|
6
|
-
|
|
15
|
+
var compositions_2 = require("./compositions");
|
|
16
|
+
Object.defineProperty(exports, "getCompositionType", { enumerable: true, get: function () { return compositions_2.getCompositionType; } });
|
|
17
|
+
Object.defineProperty(exports, "arrayToProps", { enumerable: true, get: function () { return compositions_2.arrayToProps; } });
|
|
7
18
|
const memoizedNameFromRef = {};
|
|
8
|
-
|
|
9
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
-
const resolver = yield
|
|
19
|
+
function resolveRef(ref, schema) {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const resolver = yield reference_resolver_1.default.resolve(ref, schema);
|
|
11
22
|
return resolver;
|
|
12
23
|
});
|
|
13
24
|
}
|
|
14
|
-
|
|
25
|
+
function nameFromRef(ref) {
|
|
15
26
|
if (memoizedNameFromRef[ref]) {
|
|
16
27
|
return memoizedNameFromRef[ref];
|
|
17
28
|
}
|
|
@@ -20,13 +31,13 @@ export function nameFromRef(ref) {
|
|
|
20
31
|
memoizedNameFromRef[ref] = name;
|
|
21
32
|
return name;
|
|
22
33
|
}
|
|
23
|
-
|
|
34
|
+
function propMerge(schema, label) {
|
|
24
35
|
let mergedProps = {};
|
|
25
36
|
const { properties, patternProperties, additionalProperties, items, oneOf, allOf, anyOf, not, if: ifSchema } = schema;
|
|
26
37
|
const compositions = oneOf || anyOf || not || allOf;
|
|
27
38
|
const conditions = ifSchema;
|
|
28
39
|
if (conditions) {
|
|
29
|
-
handleConditions(schema, mergedProps);
|
|
40
|
+
(0, conditions_1.handleConditions)(schema, mergedProps);
|
|
30
41
|
}
|
|
31
42
|
if (patternProperties) {
|
|
32
43
|
Object.assign(mergedProps, patternProperties);
|
|
@@ -35,7 +46,7 @@ export function propMerge(schema, label) {
|
|
|
35
46
|
Object.assign(mergedProps, properties);
|
|
36
47
|
}
|
|
37
48
|
if (items) {
|
|
38
|
-
const itemsComposition = getCompositionType(items);
|
|
49
|
+
const itemsComposition = (0, compositions_1.getCompositionType)(items);
|
|
39
50
|
const itemsProps = propMerge(items, label);
|
|
40
51
|
Object.assign(mergedProps, itemsProps);
|
|
41
52
|
// Propagate composition type from items to parent
|
|
@@ -44,7 +55,7 @@ export function propMerge(schema, label) {
|
|
|
44
55
|
}
|
|
45
56
|
}
|
|
46
57
|
if (additionalProperties && typeof additionalProperties === 'object') {
|
|
47
|
-
const additionalComposition = getCompositionType(additionalProperties);
|
|
58
|
+
const additionalComposition = (0, compositions_1.getCompositionType)(additionalProperties);
|
|
48
59
|
const additionalProps = propMerge(additionalProperties, label);
|
|
49
60
|
Object.assign(mergedProps, additionalProps);
|
|
50
61
|
// Propagate composition type from additionalProperties to parent
|
|
@@ -53,11 +64,11 @@ export function propMerge(schema, label) {
|
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
if (compositions) {
|
|
56
|
-
handleCompositions(schema, mergedProps, label);
|
|
67
|
+
(0, compositions_1.handleCompositions)(schema, mergedProps, label);
|
|
57
68
|
}
|
|
58
69
|
return mergedProps;
|
|
59
70
|
}
|
|
60
|
-
|
|
71
|
+
function removeElementsByParent(nodes, id) {
|
|
61
72
|
const result = nodes.filter((node) => {
|
|
62
73
|
const relations = node.data.relations;
|
|
63
74
|
if (relations) {
|
|
@@ -72,7 +83,7 @@ export function removeElementsByParent(nodes, id) {
|
|
|
72
83
|
});
|
|
73
84
|
return result;
|
|
74
85
|
}
|
|
75
|
-
|
|
86
|
+
function removeEdgesByParent(edges, id) {
|
|
76
87
|
const result = edges.filter((edge) => {
|
|
77
88
|
if (edge.source === id) {
|
|
78
89
|
return false;
|
|
@@ -81,7 +92,7 @@ export function removeEdgesByParent(edges, id) {
|
|
|
81
92
|
});
|
|
82
93
|
return result;
|
|
83
94
|
}
|
|
84
|
-
|
|
95
|
+
function retrieveObj(theObject, key) {
|
|
85
96
|
var result = null;
|
|
86
97
|
if (theObject instanceof Array) {
|
|
87
98
|
for (var i = 0; i < theObject.length; i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reusables.js","sourceRoot":"","sources":["../../../src/utils/reusables.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"reusables.js","sourceRoot":"","sources":["../../../src/utils/reusables.ts"],"names":[],"mappings":";;;AASA,gCAGC;AAED,kCAQC;AAED,8BAsCC;AAED,wDAcC;AAED,kDASC;AAED,kCAuBC;;AAlHD,uGAA0D;AAC1D,sDAAwD;AACxD,iDAAuE;AAEvE,wCAAwC;AACxC,+CAAiE;AAAxD,kHAAA,kBAAkB,OAAA;AAAE,4GAAA,YAAY,OAAA;AAEzC,MAAM,mBAAmB,GAA2B,EAAE,CAAA;AAEtD,SAAsB,UAAU,CAAC,GAAW,EAAE,MAAW;;QACvD,MAAM,QAAQ,GAAG,MAAM,4BAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAClD,OAAO,QAAQ,CAAA;IACjB,CAAC;CAAA;AAED,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAA;IACjC,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAChD,mBAAmB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAC/B,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAgB,SAAS,CAAC,MAAW,EAAE,KAAa;IAClD,IAAI,WAAW,GAA4B,EAAE,CAAA;IAC7C,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IACr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C3B,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;gBAChB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;YACxB,CAAC;YACD,IAAI,SAAS,CAAC,IAAI,CAAC,YAAY,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBAC1E,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAA;gBAC1C,IAAI,MAAM,EAAE,CAAC;oBACX,MAAK;gBACP,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "schyma",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "JSON Schemas Visualizer React component",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"author": "Azeez Elegbede",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"
|
|
15
|
+
"clean:dist": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
16
|
+
"build": "npm run clean:dist && npm run build:esm && npm run build:cjs && npm run copy-files",
|
|
16
17
|
"build:esm": "tsc -p tsconfig.json",
|
|
17
18
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
18
19
|
"prepare": "npm run build",
|