@takeshape/schema 9.80.4 → 9.81.3
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/api-version.js +0 -9
- package/dist/builtin-schema.js +0 -5
- package/dist/content-schema-transform.js +4 -52
- package/dist/create-input-schema.js +7 -19
- package/dist/enum.js +0 -3
- package/dist/flatten-templates.js +0 -11
- package/dist/get-is-leaf.js +8 -18
- package/dist/index.js +0 -58
- package/dist/interfaces.js +2 -26
- package/dist/layers/layers.js +23 -103
- package/dist/layers/refs.js +26 -69
- package/dist/layers/type-utils.js +11 -43
- package/dist/layers/visitor.js +0 -6
- package/dist/migration/index.js +0 -51
- package/dist/migration/to/v3.0.0.js +31 -45
- package/dist/migration/to/v3.1.0.js +15 -41
- package/dist/migration/to/v3.10.0.js +6 -20
- package/dist/migration/to/v3.11.0.js +8 -20
- package/dist/migration/to/v3.12.0.js +2 -3
- package/dist/migration/to/v3.12.1.js +2 -3
- package/dist/migration/to/v3.12.2.js +2 -3
- package/dist/migration/to/v3.12.3.js +16 -21
- package/dist/migration/to/v3.13.0.js +2 -7
- package/dist/migration/to/v3.14.0.js +2 -3
- package/dist/migration/to/v3.15.0.js +2 -3
- package/dist/migration/to/v3.16.0.js +2 -3
- package/dist/migration/to/v3.17.0.js +4 -9
- package/dist/migration/to/v3.17.1.js +2 -3
- package/dist/migration/to/v3.18.0.js +2 -15
- package/dist/migration/to/v3.18.1.js +2 -7
- package/dist/migration/to/v3.18.2.js +8 -10
- package/dist/migration/to/v3.19.0.js +2 -3
- package/dist/migration/to/v3.2.0.js +2 -3
- package/dist/migration/to/v3.20.0.js +10 -11
- package/dist/migration/to/v3.21.0.js +2 -3
- package/dist/migration/to/v3.22.0.js +4 -9
- package/dist/migration/to/v3.23.0.js +2 -3
- package/dist/migration/to/v3.24.0.js +2 -3
- package/dist/migration/to/v3.25.0.js +2 -3
- package/dist/migration/to/v3.26.0.js +2 -3
- package/dist/migration/to/v3.27.0.js +2 -3
- package/dist/migration/to/v3.28.0.js +2 -3
- package/dist/migration/to/v3.29.0.js +2 -3
- package/dist/migration/to/v3.3.0.js +3 -4
- package/dist/migration/to/v3.30.0.js +2 -3
- package/dist/migration/to/v3.31.0.js +2 -12
- package/dist/migration/to/v3.32.0.js +12 -22
- package/dist/migration/to/v3.33.0.js +2 -3
- package/dist/migration/to/v3.34.0.js +14 -43
- package/dist/migration/to/v3.35.0.js +2 -3
- package/dist/migration/to/v3.36.0.js +6 -10
- package/dist/migration/to/v3.37.0.js +2 -3
- package/dist/migration/to/v3.38.0.js +2 -3
- package/dist/migration/to/v3.39.0.js +6 -13
- package/dist/migration/to/v3.4.0.js +2 -3
- package/dist/migration/to/v3.5.0.js +2 -3
- package/dist/migration/to/v3.5.1.js +2 -3
- package/dist/migration/to/v3.6.0.js +2 -3
- package/dist/migration/to/v3.7.0.js +2 -3
- package/dist/migration/to/v3.8.0.js +2 -3
- package/dist/migration/to/v3.9.0.js +8 -24
- package/dist/migration/utils.js +0 -2
- package/dist/mocks.js +9 -12
- package/dist/models/project-schema.js +0 -34
- package/dist/models/query.js +0 -9
- package/dist/models/service.js +0 -8
- package/dist/models/shape.js +0 -29
- package/dist/project-schema/index.js +1 -105
- package/dist/project-schema/migrate.js +1 -54
- package/dist/refs.js +39 -159
- package/dist/relationships.js +13 -57
- package/dist/scalars.js +0 -1
- package/dist/schema-transform.js +0 -11
- package/dist/schema-util.js +75 -271
- package/dist/schemas/index.js +0 -64
- package/dist/services.js +24 -44
- package/dist/taxonomies.js +0 -13
- package/dist/template-shapes/index.js +1 -8
- package/dist/template-shapes/templates.js +9 -40
- package/dist/template-shapes/types.js +4 -5
- package/dist/template-shapes/where.js +14 -110
- package/dist/types/index.js +0 -4
- package/dist/types/types.js +41 -13
- package/dist/types/utils.js +15 -89
- package/dist/unions.js +8 -38
- package/dist/util/api-indexing.js +2 -19
- package/dist/util/detect-cycles.js +2 -16
- package/dist/util/find-shape-at-path.js +1 -15
- package/dist/util/form-config.js +6 -23
- package/dist/util/get-conflicting-properties.js +7 -17
- package/dist/util/get-return-shape.js +0 -11
- package/dist/util/has-arg.js +0 -6
- package/dist/util/index.js +0 -18
- package/dist/util/merge.js +28 -74
- package/dist/util/patch-schema.js +5 -13
- package/dist/validate.js +15 -234
- package/dist/versions.js +0 -2
- package/dist/workflows.js +0 -15
- package/es/api-version.js +0 -4
- package/es/content-schema-transform.js +4 -38
- package/es/create-input-schema.js +7 -14
- package/es/enum.js +0 -2
- package/es/flatten-templates.js +0 -4
- package/es/get-is-leaf.js +8 -13
- package/es/index.js +1 -0
- package/es/interfaces.js +2 -14
- package/es/layers/layers.js +23 -90
- package/es/layers/refs.js +22 -45
- package/es/layers/type-utils.js +11 -16
- package/es/layers/visitor.js +0 -3
- package/es/migration/to/v3.0.0.js +31 -38
- package/es/migration/to/v3.1.0.js +16 -34
- package/es/migration/to/v3.10.0.js +6 -17
- package/es/migration/to/v3.11.0.js +8 -18
- package/es/migration/to/v3.12.0.js +2 -2
- package/es/migration/to/v3.12.1.js +2 -2
- package/es/migration/to/v3.12.2.js +2 -2
- package/es/migration/to/v3.12.3.js +16 -19
- package/es/migration/to/v3.13.0.js +2 -4
- package/es/migration/to/v3.14.0.js +2 -2
- package/es/migration/to/v3.15.0.js +2 -2
- package/es/migration/to/v3.16.0.js +2 -2
- package/es/migration/to/v3.17.0.js +4 -4
- package/es/migration/to/v3.17.1.js +2 -2
- package/es/migration/to/v3.18.0.js +2 -10
- package/es/migration/to/v3.18.1.js +2 -3
- package/es/migration/to/v3.18.2.js +8 -8
- package/es/migration/to/v3.19.0.js +2 -2
- package/es/migration/to/v3.2.0.js +2 -2
- package/es/migration/to/v3.20.0.js +10 -9
- package/es/migration/to/v3.21.0.js +2 -2
- package/es/migration/to/v3.22.0.js +4 -6
- package/es/migration/to/v3.23.0.js +2 -2
- package/es/migration/to/v3.24.0.js +2 -2
- package/es/migration/to/v3.25.0.js +2 -2
- package/es/migration/to/v3.26.0.js +2 -2
- package/es/migration/to/v3.27.0.js +2 -2
- package/es/migration/to/v3.28.0.js +2 -2
- package/es/migration/to/v3.29.0.js +2 -2
- package/es/migration/to/v3.3.0.js +3 -3
- package/es/migration/to/v3.30.0.js +2 -2
- package/es/migration/to/v3.31.0.js +2 -5
- package/es/migration/to/v3.32.0.js +12 -21
- package/es/migration/to/v3.33.0.js +2 -2
- package/es/migration/to/v3.34.0.js +16 -32
- package/es/migration/to/v3.35.0.js +2 -2
- package/es/migration/to/v3.36.0.js +6 -8
- package/es/migration/to/v3.37.0.js +2 -2
- package/es/migration/to/v3.38.0.js +2 -2
- package/es/migration/to/v3.39.0.js +6 -12
- package/es/migration/to/v3.4.0.js +2 -2
- package/es/migration/to/v3.5.0.js +2 -2
- package/es/migration/to/v3.5.1.js +2 -2
- package/es/migration/to/v3.6.0.js +2 -2
- package/es/migration/to/v3.7.0.js +2 -2
- package/es/migration/to/v3.8.0.js +2 -2
- package/es/migration/to/v3.9.0.js +8 -20
- package/es/mocks.js +10 -6
- package/es/models/project-schema.js +0 -26
- package/es/models/query.js +0 -7
- package/es/models/service.js +0 -6
- package/es/models/shape.js +1 -25
- package/es/project-schema/index.js +0 -5
- package/es/project-schema/migrate.js +3 -51
- package/es/refs.js +40 -96
- package/es/relationships.js +14 -42
- package/es/schema-transform.js +0 -7
- package/es/schema-util.js +75 -180
- package/es/services.js +18 -27
- package/es/taxonomies.js +0 -9
- package/es/template-shapes/index.js +1 -4
- package/es/template-shapes/templates.js +9 -18
- package/es/template-shapes/types.js +3 -4
- package/es/template-shapes/where.js +14 -94
- package/es/types/types.js +43 -10
- package/es/types/utils.js +16 -24
- package/es/unions.js +8 -22
- package/es/util/api-indexing.js +2 -12
- package/es/util/detect-cycles.js +2 -14
- package/es/util/find-shape-at-path.js +2 -12
- package/es/util/form-config.js +7 -19
- package/es/util/get-conflicting-properties.js +8 -14
- package/es/util/get-return-shape.js +0 -8
- package/es/util/has-arg.js +0 -3
- package/es/util/merge.js +28 -55
- package/es/util/patch-schema.js +5 -7
- package/es/validate.js +15 -194
- package/es/workflows.js +0 -6
- package/package.json +5 -5
package/dist/layers/layers.js
CHANGED
|
@@ -10,33 +10,21 @@ exports.getAllRefsInQueries = getAllRefsInQueries;
|
|
|
10
10
|
exports.getAllRefsInQuery = getAllRefsInQuery;
|
|
11
11
|
exports.getAllRefsInShapes = getAllRefsInShapes;
|
|
12
12
|
exports.isObjectSchemaV4_0_0 = isObjectSchemaV4_0_0;
|
|
13
|
-
|
|
14
13
|
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
15
|
-
|
|
16
14
|
var _util = require("@takeshape/util");
|
|
17
|
-
|
|
18
15
|
var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
|
19
|
-
|
|
20
16
|
var _refs = require("./refs");
|
|
21
|
-
|
|
22
17
|
var _typeUtils = require("./type-utils");
|
|
23
|
-
|
|
24
18
|
var _visitor = require("./visitor");
|
|
25
|
-
|
|
26
19
|
var _set = _interopRequireDefault(require("lodash/set"));
|
|
27
|
-
|
|
28
20
|
var _refs2 = require("../refs");
|
|
29
|
-
|
|
30
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
22
|
const layerDefaults = {
|
|
33
23
|
namespace: '',
|
|
34
24
|
visibility: []
|
|
35
25
|
};
|
|
36
|
-
|
|
37
26
|
function filterMap(prefix, fields, filters) {
|
|
38
27
|
const result = {};
|
|
39
|
-
|
|
40
28
|
for (const [name, value] of Object.entries(fields)) {
|
|
41
29
|
for (const filter of filters) {
|
|
42
30
|
if ((0, _minimatch.default)(`${prefix}.${name}`, filter)) {
|
|
@@ -44,211 +32,173 @@ function filterMap(prefix, fields, filters) {
|
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
return result;
|
|
49
36
|
}
|
|
50
|
-
|
|
51
37
|
function filterLayer(layerSchema, filters) {
|
|
52
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
...layerSchema,
|
|
53
40
|
queries: filterMap('queries', layerSchema.queries ?? {}, filters),
|
|
54
41
|
mutations: filterMap('mutations', layerSchema.mutations ?? {}, filters),
|
|
55
42
|
shapes: filterMap('shapes', layerSchema.shapes ?? {}, filters),
|
|
56
43
|
workflows: filterMap('workflows', layerSchema.workflows ?? {}, filters)
|
|
57
44
|
};
|
|
58
|
-
}
|
|
59
|
-
|
|
45
|
+
}
|
|
60
46
|
|
|
47
|
+
// TODO use non-versioned util eventually
|
|
61
48
|
function isObjectSchemaV4_0_0(maybeObjectSchema) {
|
|
62
49
|
return maybeObjectSchema.type === 'object' && (0, _util.isRecord)(maybeObjectSchema.properties);
|
|
63
50
|
}
|
|
64
|
-
|
|
65
51
|
function mergeShape(a, b) {
|
|
66
52
|
if (b.override === 'extend') {
|
|
67
53
|
if (isObjectSchemaV4_0_0(a.schema) && isObjectSchemaV4_0_0(b.schema)) {
|
|
68
54
|
const combinedRequired = (0, _uniq.default)((a.schema.required ?? []).concat(b.schema.required ?? []));
|
|
69
55
|
const combinedSchema = {
|
|
70
56
|
type: 'object',
|
|
71
|
-
properties: {
|
|
57
|
+
properties: {
|
|
58
|
+
...a.schema.properties,
|
|
72
59
|
...b.schema.properties
|
|
73
60
|
}
|
|
74
61
|
};
|
|
75
|
-
|
|
76
62
|
if (combinedRequired.length) {
|
|
77
63
|
combinedSchema.required = combinedRequired;
|
|
78
64
|
}
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
return {
|
|
66
|
+
...a,
|
|
81
67
|
...b,
|
|
82
68
|
schema: combinedSchema
|
|
83
69
|
};
|
|
84
70
|
}
|
|
85
71
|
}
|
|
86
|
-
|
|
87
72
|
return b;
|
|
88
73
|
}
|
|
89
|
-
|
|
90
74
|
function assignShapes(flattenedShapes, layerShapes) {
|
|
91
75
|
for (const [shapeName, shape] of Object.entries(layerShapes)) {
|
|
92
76
|
flattenedShapes[shapeName] = flattenedShapes[shapeName] ? mergeShape(flattenedShapes[shapeName], shape) : shape;
|
|
93
77
|
}
|
|
94
78
|
}
|
|
95
|
-
|
|
96
79
|
function addRef(refs, ref, predicate) {
|
|
97
80
|
if (ref && (!predicate || predicate(ref))) {
|
|
98
81
|
refs.push(ref);
|
|
99
82
|
}
|
|
100
83
|
}
|
|
84
|
+
|
|
101
85
|
/**
|
|
102
86
|
* Walk through a `ProjectSchema` and collect all the `ref`s.
|
|
103
87
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
88
|
function getAllRefsInShapes(shapes, predicate) {
|
|
107
89
|
const items = [];
|
|
108
|
-
|
|
109
90
|
const shapeVisitor = (schema, schemaPath) => {
|
|
110
91
|
if (schema['@args'] && typeof schema['@args'] === 'object') {
|
|
111
92
|
(0, _visitor.visitSchemaProperties)(schema['@args'], schemaPath.concat(['@args']), (argSchema, argPath) => {
|
|
112
93
|
addRef(items, (0, _refs.getRefOrItemsRef)(argSchema, argPath), predicate);
|
|
113
94
|
});
|
|
114
95
|
}
|
|
115
|
-
|
|
116
96
|
addRef(items, (0, _refs.getArgsReferenceWithPath)(schema, schemaPath), predicate);
|
|
117
97
|
const newPath = schema.items ? schemaPath.concat('items') : schemaPath;
|
|
118
98
|
const newSchema = schema.items ?? schema;
|
|
119
|
-
|
|
120
99
|
if ((0, _typeUtils.isRefSchema)(newSchema)) {
|
|
121
100
|
addRef(items, (0, _refs.getRefOrItemsRef)(newSchema, newPath), predicate);
|
|
122
101
|
} else if ((0, _typeUtils.isObjectSchema)(newSchema) || (0, _typeUtils.isAllOfSchema)(newSchema) || (0, _typeUtils.isOneOfSchema)(newSchema)) {
|
|
123
102
|
(0, _visitor.visitSchemaProperties)(newSchema, newPath, shapeVisitor);
|
|
124
103
|
}
|
|
125
104
|
};
|
|
126
|
-
|
|
127
105
|
for (const [shapeName, shape] of Object.entries(shapes)) {
|
|
128
106
|
(0, _visitor.visitSchemaProperties)(shape.schema, ['shapes', shapeName, 'schema'], shapeVisitor);
|
|
129
107
|
}
|
|
130
|
-
|
|
131
108
|
return items;
|
|
132
109
|
}
|
|
110
|
+
|
|
133
111
|
/**
|
|
134
112
|
* Get all refs
|
|
135
113
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
114
|
function getAllRefsInQuery(shapes, queryPath, query, predicate) {
|
|
139
115
|
const refItems = [];
|
|
140
|
-
|
|
141
116
|
const propertyVisitor = (propSchema, propSchemaPath) => {
|
|
142
117
|
addRef(refItems, (0, _refs.getRefOrItemsRef)(propSchema, propSchemaPath), predicate);
|
|
143
118
|
};
|
|
144
|
-
|
|
145
119
|
if (query.args && typeof query.args === 'string') {
|
|
146
120
|
addRef(refItems, (0, _refs.getArgsReferenceWithPath)(query, queryPath), predicate);
|
|
147
121
|
}
|
|
148
|
-
|
|
149
122
|
if (query.args && typeof query.args === 'object') {
|
|
150
123
|
(0, _visitor.visitSchemaProperties)((0, _refs.dereferenceSchema)(shapes, query.args), queryPath, propertyVisitor);
|
|
151
124
|
}
|
|
152
|
-
|
|
153
125
|
if (query.shape) {
|
|
154
126
|
const refItem = (0, _refs.parseReturnShape)(query.shape).ref;
|
|
155
|
-
|
|
156
127
|
if (refItem) {
|
|
157
|
-
addRef(refItems, {
|
|
128
|
+
addRef(refItems, {
|
|
129
|
+
...refItem,
|
|
158
130
|
path: queryPath.concat(['shape'])
|
|
159
131
|
}, predicate);
|
|
160
132
|
}
|
|
161
133
|
}
|
|
162
|
-
|
|
163
134
|
return refItems;
|
|
164
135
|
}
|
|
165
|
-
|
|
166
136
|
/**
|
|
167
137
|
* Collect refs from `queries` or `mutations`.
|
|
168
138
|
*/
|
|
169
139
|
function getAllRefsInQueries(context, rootPropertyName, predicate) {
|
|
170
140
|
const refItems = [];
|
|
171
141
|
const rootPath = [rootPropertyName];
|
|
172
|
-
|
|
173
142
|
for (const [queryName, query] of Object.entries(context[rootPropertyName])) {
|
|
174
143
|
const queryPath = rootPath.concat([queryName]);
|
|
175
144
|
const queryRefs = getAllRefsInQuery(context.shapes, queryPath, query, predicate);
|
|
176
|
-
|
|
177
145
|
if (queryRefs.length) {
|
|
178
146
|
refItems.push(...queryRefs);
|
|
179
147
|
}
|
|
180
148
|
}
|
|
181
|
-
|
|
182
149
|
return refItems;
|
|
183
150
|
}
|
|
151
|
+
|
|
184
152
|
/**
|
|
185
153
|
* Get all refs in a ProjectSchema
|
|
186
154
|
* @param predicate return true to include the ref in
|
|
187
155
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
156
|
function getAllRefs(projectSchema, predicate) {
|
|
191
157
|
return [...getAllRefsInShapes(projectSchema.shapes, predicate), ...getAllRefsInQueries(projectSchema, 'queries', predicate), ...getAllRefsInQueries(projectSchema, 'mutations', predicate)];
|
|
192
158
|
}
|
|
193
|
-
|
|
194
159
|
function collectReferencedShapeNames(layerId, refSet) {
|
|
195
|
-
const addLayerId = ref => ({
|
|
160
|
+
const addLayerId = ref => ({
|
|
161
|
+
...ref,
|
|
196
162
|
layerId
|
|
197
163
|
});
|
|
198
|
-
|
|
199
164
|
const collect = schema => {
|
|
200
165
|
const args = schema['@args'];
|
|
201
|
-
|
|
202
166
|
if (args && typeof args === 'object') {
|
|
203
167
|
Object.values(args.properties).forEach(collect);
|
|
204
168
|
}
|
|
205
|
-
|
|
206
169
|
const argsRefItem = (0, _refs.getArgsReferenceWithPath)(schema);
|
|
207
|
-
|
|
208
170
|
if (argsRefItem) {
|
|
209
171
|
refSet.add((0, _refs.refItemToString)(addLayerId(argsRefItem)));
|
|
210
172
|
}
|
|
211
|
-
|
|
212
173
|
const refItem = (0, _refs.getRefOrItemsRef)(schema);
|
|
213
|
-
|
|
214
174
|
if (refItem) {
|
|
215
175
|
refSet.add((0, _refs.refItemToString)(addLayerId(refItem)));
|
|
216
176
|
}
|
|
217
177
|
};
|
|
218
|
-
|
|
219
178
|
return collect;
|
|
220
179
|
}
|
|
221
|
-
|
|
222
180
|
function collectServiceRefs(flattenedSchema, getLayer) {
|
|
223
181
|
const refs = new Set(getAllRefs(flattenedSchema, refItem => refItem.layerId !== 'local').map(_refs.refItemToString));
|
|
224
|
-
|
|
225
182
|
if (refs.size) {
|
|
226
183
|
for (const ref of refs) {
|
|
227
184
|
const [layerId, shapeName] = (0, _refs.splitAtRef)(ref);
|
|
228
|
-
|
|
229
185
|
if (layerId !== 'local') {
|
|
230
186
|
var _layer$shapes;
|
|
231
|
-
|
|
232
187
|
const layer = getLayer(layerId);
|
|
233
188
|
const shape = layer === null || layer === void 0 ? void 0 : (_layer$shapes = layer.shapes) === null || _layer$shapes === void 0 ? void 0 : _layer$shapes[shapeName];
|
|
234
|
-
|
|
235
189
|
if (shape) {
|
|
236
190
|
(0, _visitor.visitSchemaProperties)(shape.schema, ['schema'], collectReferencedShapeNames(layerId, refs));
|
|
237
191
|
}
|
|
238
192
|
}
|
|
239
193
|
}
|
|
240
194
|
}
|
|
241
|
-
|
|
242
195
|
return refs;
|
|
243
196
|
}
|
|
244
|
-
|
|
245
197
|
function ensureServiceLayer(flattenedSchema, layerId) {
|
|
246
198
|
if (!flattenedSchema.serviceLayers) {
|
|
247
199
|
flattenedSchema.serviceLayers = {};
|
|
248
200
|
}
|
|
249
|
-
|
|
250
201
|
let serviceLayer = flattenedSchema.serviceLayers[layerId];
|
|
251
|
-
|
|
252
202
|
if (!serviceLayer) {
|
|
253
203
|
serviceLayer = {
|
|
254
204
|
layerId,
|
|
@@ -259,30 +209,23 @@ function ensureServiceLayer(flattenedSchema, layerId) {
|
|
|
259
209
|
};
|
|
260
210
|
flattenedSchema.serviceLayers[layerId] = serviceLayer;
|
|
261
211
|
}
|
|
262
|
-
|
|
263
212
|
return serviceLayer;
|
|
264
213
|
}
|
|
265
|
-
|
|
266
214
|
function rewriteLayerId(localShapes, layerId, query) {
|
|
267
215
|
const newQuery = (0, _util.deepClone)(query);
|
|
268
|
-
|
|
269
216
|
const propertyVisitor = (propSchema, propSchemaPath) => {
|
|
270
217
|
const ref = (propSchema.items ?? propSchema)['@ref'];
|
|
271
|
-
|
|
272
218
|
if (ref) {
|
|
273
219
|
const [argsLayerId, shapeName] = (0, _refs.splitAtRef)(ref);
|
|
274
|
-
|
|
275
220
|
if (argsLayerId === 'local' && !localShapes[shapeName]) {
|
|
276
221
|
const path = propSchemaPath.concat(propSchema.items ? ['items', '@ref'] : ['@ref']);
|
|
277
222
|
(0, _set.default)(newQuery, path, `${layerId}:${shapeName}`);
|
|
278
223
|
}
|
|
279
224
|
}
|
|
280
225
|
};
|
|
281
|
-
|
|
282
226
|
if (query.args) {
|
|
283
227
|
if (typeof query.args === 'string') {
|
|
284
228
|
const [argsLayerId, shapeName] = (0, _refs.splitAtRef)((0, _refs2.parseTemplateShape)(query.args).shapeName);
|
|
285
|
-
|
|
286
229
|
if (argsLayerId === 'local' && !localShapes[shapeName]) {
|
|
287
230
|
newQuery.args = `${layerId}:${shapeName}`;
|
|
288
231
|
}
|
|
@@ -290,40 +233,34 @@ function rewriteLayerId(localShapes, layerId, query) {
|
|
|
290
233
|
(0, _visitor.visitSchemaProperties)(query.args, ['args'], propertyVisitor);
|
|
291
234
|
}
|
|
292
235
|
}
|
|
293
|
-
|
|
294
236
|
if (typeof query.shape === 'string') {
|
|
295
237
|
const [argsLayerId, shapeName] = (0, _refs.splitAtRef)((0, _refs2.parseTemplateShape)(query.shape).shapeName);
|
|
296
|
-
|
|
297
238
|
if (argsLayerId === 'local' && !localShapes[shapeName]) {
|
|
298
239
|
newQuery.shape = `${layerId}:${shapeName}`;
|
|
299
240
|
}
|
|
300
241
|
} else {
|
|
301
242
|
const ref = query.shape.items['@ref'];
|
|
302
|
-
|
|
303
243
|
if (ref) {
|
|
304
244
|
const [argsLayerId, shapeName] = (0, _refs.splitAtRef)(ref);
|
|
305
|
-
|
|
306
245
|
if (argsLayerId === 'local' && !localShapes[shapeName]) {
|
|
307
246
|
(0, _set.default)(newQuery, ['shape', 'items', '@ref'], `${layerId}:${shapeName}`);
|
|
308
247
|
}
|
|
309
248
|
}
|
|
310
249
|
}
|
|
311
|
-
|
|
312
250
|
return newQuery;
|
|
313
251
|
}
|
|
314
|
-
|
|
315
252
|
function assignQueries(localShapes, queries, layerId, layerQueries) {
|
|
316
253
|
for (const [queryName, query] of Object.entries(layerQueries)) {
|
|
317
254
|
queries[queryName] = rewriteLayerId(localShapes, layerId, query);
|
|
318
255
|
}
|
|
319
256
|
}
|
|
320
|
-
|
|
321
257
|
function flattenSchema(projectSchema, getLayer) {
|
|
322
258
|
const {
|
|
323
259
|
layers,
|
|
324
260
|
...rest
|
|
325
261
|
} = projectSchema;
|
|
326
|
-
const flattenedSchema = {
|
|
262
|
+
const flattenedSchema = {
|
|
263
|
+
...rest,
|
|
327
264
|
shapes: {},
|
|
328
265
|
queries: {},
|
|
329
266
|
mutations: {},
|
|
@@ -332,81 +269,64 @@ function flattenSchema(projectSchema, getLayer) {
|
|
|
332
269
|
};
|
|
333
270
|
const filteredLayers = layers.reverse().map(layer => {
|
|
334
271
|
var _config$visibility;
|
|
335
|
-
|
|
336
|
-
|
|
272
|
+
const config = typeof layer === 'string' ? {
|
|
273
|
+
...layerDefaults,
|
|
337
274
|
id: layer
|
|
338
275
|
} : layer;
|
|
339
276
|
const layerSchema = getLayer(config.id);
|
|
340
|
-
|
|
341
277
|
if (!layerSchema) {
|
|
342
278
|
throw new Error(`Unable to flatten schema for project ${projectSchema.projectId}. Cannot get layer ${config.id}`);
|
|
343
279
|
}
|
|
344
|
-
|
|
345
280
|
return (_config$visibility = config.visibility) !== null && _config$visibility !== void 0 && _config$visibility.length ? filterLayer(layerSchema, config.visibility) : undefined;
|
|
346
281
|
}).filter(_util.isDefined);
|
|
347
|
-
|
|
348
282
|
for (const filteredLayer of filteredLayers) {
|
|
349
283
|
var _projectSchema$servic;
|
|
350
|
-
|
|
351
284
|
const {
|
|
352
285
|
layerId
|
|
353
|
-
} = filteredLayer;
|
|
354
|
-
|
|
286
|
+
} = filteredLayer;
|
|
287
|
+
// Preserve original queries
|
|
355
288
|
if ((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[layerId]) {
|
|
356
289
|
const serviceLayer = ensureServiceLayer(flattenedSchema, layerId);
|
|
357
|
-
|
|
358
290
|
if (serviceLayer.queries && filteredLayer.queries) {
|
|
359
291
|
Object.assign(serviceLayer.queries, filteredLayer.queries);
|
|
360
292
|
}
|
|
361
|
-
|
|
362
293
|
if (serviceLayer.mutations && filteredLayer.mutations) {
|
|
363
294
|
Object.assign(serviceLayer.mutations, filteredLayer.mutations);
|
|
364
295
|
}
|
|
365
296
|
}
|
|
366
|
-
|
|
367
297
|
if (filteredLayer.workflows) {
|
|
368
298
|
Object.assign(flattenedSchema.workflows, filteredLayer.workflows);
|
|
369
299
|
}
|
|
370
|
-
|
|
371
300
|
if (flattenedSchema.forms && filteredLayer.forms) {
|
|
372
301
|
Object.assign(flattenedSchema.forms, filteredLayer.forms);
|
|
373
302
|
}
|
|
374
|
-
|
|
375
303
|
if (filteredLayer.shapes) {
|
|
376
304
|
assignShapes(flattenedSchema.shapes, filteredLayer.shapes);
|
|
377
305
|
}
|
|
378
306
|
}
|
|
379
|
-
|
|
380
307
|
for (const filteredLayer of filteredLayers) {
|
|
381
308
|
if (filteredLayer.queries) {
|
|
382
309
|
assignQueries(flattenedSchema.shapes, flattenedSchema.queries, filteredLayer.layerId, filteredLayer.queries);
|
|
383
310
|
}
|
|
384
|
-
|
|
385
311
|
if (filteredLayer.mutations) {
|
|
386
312
|
assignQueries(flattenedSchema.shapes, flattenedSchema.mutations, filteredLayer.layerId, filteredLayer.mutations);
|
|
387
313
|
}
|
|
388
|
-
}
|
|
389
|
-
|
|
314
|
+
}
|
|
390
315
|
|
|
316
|
+
// Preserve original service schema shapes
|
|
391
317
|
for (const refStr of collectServiceRefs(flattenedSchema, getLayer)) {
|
|
392
318
|
const [layerId, shapeName] = (0, _refs.splitAtRef)(refStr);
|
|
393
|
-
|
|
394
319
|
if (layerId !== 'local') {
|
|
395
320
|
var _getLayer, _getLayer$shapes;
|
|
396
|
-
|
|
397
321
|
const shape = (_getLayer = getLayer(layerId)) === null || _getLayer === void 0 ? void 0 : (_getLayer$shapes = _getLayer.shapes) === null || _getLayer$shapes === void 0 ? void 0 : _getLayer$shapes[shapeName];
|
|
398
|
-
|
|
399
322
|
if (shape) {
|
|
400
323
|
const serviceLayer = ensureServiceLayer(flattenedSchema, layerId);
|
|
401
|
-
|
|
402
324
|
if (!serviceLayer.shapes) {
|
|
403
325
|
serviceLayer.shapes = {};
|
|
404
326
|
}
|
|
405
|
-
|
|
406
327
|
serviceLayer.shapes[shapeName] = shape;
|
|
407
328
|
}
|
|
408
329
|
}
|
|
409
330
|
}
|
|
410
|
-
|
|
411
331
|
return flattenedSchema;
|
|
412
332
|
}
|