@takeshape/schema 9.80.4 → 9.81.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/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/es/schema-util.js
CHANGED
|
@@ -42,8 +42,9 @@ export const commonSchemaKeys = ['type', 'default', 'readOnly', ...schemaMetadat
|
|
|
42
42
|
export const scalarSchemaKeys = [...commonSchemaKeys, 'format', 'oneOf', 'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum', 'maxLength', 'minLength', 'pattern'];
|
|
43
43
|
export const objectSchemaKeys = [...commonSchemaKeys, 'properties', 'required'];
|
|
44
44
|
export const arraySchemaKeys = [...commonSchemaKeys, 'items', 'additionalItems', 'maxItems', 'minItems', 'uniqueItems'];
|
|
45
|
-
export const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems'];
|
|
45
|
+
export const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems'];
|
|
46
46
|
|
|
47
|
+
// All properties except properties, items, additionalItems
|
|
47
48
|
export const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@resolver', '@input', '@output', '@backreference', '@args', 'required', 'maxItems', 'minItems', 'uniqueItems'];
|
|
48
49
|
export function getServiceIdFieldName(serviceFieldName) {
|
|
49
50
|
return `${serviceFieldName}Id`;
|
|
@@ -53,33 +54,30 @@ const generatorVersions = {
|
|
|
53
54
|
};
|
|
54
55
|
export function getGeneratorVersion(generator) {
|
|
55
56
|
return generatorVersions[generator];
|
|
56
|
-
}
|
|
57
|
+
}
|
|
57
58
|
|
|
59
|
+
// Returns info for all services found in shape, keyed by provider
|
|
58
60
|
export function getServiceInfo(projectSchema, shape) {
|
|
59
|
-
const result = {};
|
|
61
|
+
const result = {};
|
|
60
62
|
|
|
63
|
+
// Get inline dependencies by not following refs with @resolver
|
|
61
64
|
const inlineDepShapes = getShapeDependencies(projectSchema, shape, prop => !prop['@resolver']).map(name => projectSchema.shapes[name]);
|
|
62
65
|
const shapesToCheck = [shape, ...inlineDepShapes];
|
|
63
66
|
shapesToCheck.forEach(thisShape => {
|
|
64
67
|
createSchemaPropertyList(projectSchema, thisShape).forEach(([key, value]) => {
|
|
65
68
|
const resolver = value['@resolver'];
|
|
66
|
-
|
|
67
69
|
if (!isServiceResolver(resolver)) {
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
70
|
-
|
|
71
72
|
const serviceConfig = getStoredServiceConfig(projectSchema, resolver.service);
|
|
72
|
-
|
|
73
73
|
if (!serviceConfig) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
76
|
const {
|
|
78
77
|
provider
|
|
79
78
|
} = serviceConfig;
|
|
80
79
|
const generators = {};
|
|
81
80
|
const tag = value['@tag'];
|
|
82
|
-
|
|
83
81
|
if (tag !== null && tag !== void 0 && tag.startsWith(SERVICE_OBJECT_PATTERN_NAME)) {
|
|
84
82
|
const idFieldName = getServiceIdFieldName(key);
|
|
85
83
|
const version = tag.substr(tag.lastIndexOf(':') + 1);
|
|
@@ -90,14 +88,12 @@ export function getServiceInfo(projectSchema, shape) {
|
|
|
90
88
|
serviceObjectType: resolver.fieldName
|
|
91
89
|
};
|
|
92
90
|
}
|
|
93
|
-
|
|
94
91
|
const serviceInfo = {
|
|
95
92
|
service: resolver.service,
|
|
96
93
|
fieldName: key,
|
|
97
94
|
path: pathBetween(shape, thisShape, projectSchema),
|
|
98
95
|
generators
|
|
99
96
|
};
|
|
100
|
-
|
|
101
97
|
if (Array.isArray(result[provider])) {
|
|
102
98
|
// Dedupe service info
|
|
103
99
|
if (!result[provider].find(existingServiceInfo => isEqual(existingServiceInfo, serviceInfo))) {
|
|
@@ -109,32 +105,27 @@ export function getServiceInfo(projectSchema, shape) {
|
|
|
109
105
|
});
|
|
110
106
|
});
|
|
111
107
|
return result;
|
|
112
|
-
}
|
|
108
|
+
}
|
|
113
109
|
|
|
110
|
+
// Follow refs to find the path between two shapes in a schema
|
|
114
111
|
export function pathBetween(fromShape, toShape, projectSchema, depthLimit = 4) {
|
|
115
112
|
if (fromShape.name === toShape.name) {
|
|
116
113
|
return [];
|
|
117
114
|
}
|
|
118
|
-
|
|
119
115
|
const toShapeName = toShape.name;
|
|
120
116
|
let shortestPath;
|
|
121
117
|
let shortestPathLength = Number.MAX_SAFE_INTEGER;
|
|
122
|
-
|
|
123
118
|
const pathBetweenHelper = (schema, pathSoFar, seen, depth) => {
|
|
124
119
|
if (depth > depthLimit) {
|
|
125
120
|
return;
|
|
126
121
|
}
|
|
127
|
-
|
|
128
122
|
if (schema.items) {
|
|
129
123
|
pathBetweenHelper(schema.items, pathSoFar, seen, depth);
|
|
130
124
|
return;
|
|
131
125
|
}
|
|
132
|
-
|
|
133
126
|
const refItem = getRef(projectSchema, schema);
|
|
134
|
-
|
|
135
127
|
if (refItem) {
|
|
136
128
|
const referenced = refItemToShape(projectSchema, refItem);
|
|
137
|
-
|
|
138
129
|
if (referenced) {
|
|
139
130
|
if (referenced.name === toShapeName && pathSoFar.length < shortestPathLength) {
|
|
140
131
|
shortestPath = pathSoFar;
|
|
@@ -155,26 +146,21 @@ export function pathBetween(fromShape, toShape, projectSchema, depthLimit = 4) {
|
|
|
155
146
|
}
|
|
156
147
|
}
|
|
157
148
|
};
|
|
158
|
-
|
|
159
149
|
pathBetweenHelper(fromShape.schema, [], new Set([fromShape.name]), 0);
|
|
160
|
-
|
|
161
150
|
if (!shortestPath) {
|
|
162
151
|
throw new Error(`No path between ${fromShape.name} and ${toShape.name}`);
|
|
163
152
|
}
|
|
164
|
-
|
|
165
153
|
return shortestPath;
|
|
166
154
|
}
|
|
167
155
|
export function getShapeQueriesAndMutations(shapes) {
|
|
168
156
|
const queries = {};
|
|
169
157
|
const mutations = {};
|
|
170
|
-
|
|
171
158
|
for (const shape of ensureArray(shapes)) {
|
|
172
159
|
const {
|
|
173
160
|
name,
|
|
174
161
|
model
|
|
175
162
|
} = shape;
|
|
176
163
|
const service = 'shapedb';
|
|
177
|
-
|
|
178
164
|
if (model) {
|
|
179
165
|
const isSingleton = model.type === 'single';
|
|
180
166
|
queries[`get${name}`] = {
|
|
@@ -197,7 +183,6 @@ export function getShapeQueriesAndMutations(shapes) {
|
|
|
197
183
|
description: `Update ${name}`,
|
|
198
184
|
args: createTemplateShapeName('UpdateArgs', name)
|
|
199
185
|
};
|
|
200
|
-
|
|
201
186
|
if (!isSingleton) {
|
|
202
187
|
queries[`get${name}List`] = {
|
|
203
188
|
shape: createTemplateShapeName('PaginatedList', name),
|
|
@@ -242,7 +227,6 @@ export function getShapeQueriesAndMutations(shapes) {
|
|
|
242
227
|
}
|
|
243
228
|
}
|
|
244
229
|
}
|
|
245
|
-
|
|
246
230
|
return {
|
|
247
231
|
queries,
|
|
248
232
|
mutations
|
|
@@ -252,18 +236,15 @@ export function getBuiltinPropertiesSet(shape) {
|
|
|
252
236
|
if (isModelShape(shape)) {
|
|
253
237
|
return 'model';
|
|
254
238
|
}
|
|
255
|
-
|
|
256
239
|
if (isCachedShape(shape)) {
|
|
257
240
|
return 'indexed';
|
|
258
241
|
}
|
|
259
|
-
|
|
260
242
|
return 'none';
|
|
261
243
|
}
|
|
262
244
|
export function getBuiltinProperties(shapeId, builtinPropertiesSet, apiVersion = CURRENT_API_VERSION) {
|
|
263
245
|
if (builtinPropertiesSet === 'none') {
|
|
264
246
|
return {};
|
|
265
247
|
}
|
|
266
|
-
|
|
267
248
|
const commonFields = {
|
|
268
249
|
_shapeId: {
|
|
269
250
|
type: 'string',
|
|
@@ -275,13 +256,12 @@ export function getBuiltinProperties(shapeId, builtinPropertiesSet, apiVersion =
|
|
|
275
256
|
type: 'string'
|
|
276
257
|
}
|
|
277
258
|
};
|
|
278
|
-
|
|
279
259
|
if (builtinPropertiesSet === 'indexed') {
|
|
280
260
|
return commonFields;
|
|
281
261
|
}
|
|
282
|
-
|
|
283
262
|
const showV1Deprecation = apiVersion !== '1';
|
|
284
|
-
return {
|
|
263
|
+
return {
|
|
264
|
+
...commonFields,
|
|
285
265
|
_version: {
|
|
286
266
|
title: 'Version',
|
|
287
267
|
type: 'integer'
|
|
@@ -339,21 +319,22 @@ export function getBuiltinProperties(shapeId, builtinPropertiesSet, apiVersion =
|
|
|
339
319
|
}
|
|
340
320
|
};
|
|
341
321
|
}
|
|
322
|
+
|
|
342
323
|
/**
|
|
343
324
|
* Return all the built in property names,
|
|
344
325
|
*/
|
|
345
|
-
|
|
346
326
|
export const getBuiltinPropertyNames = (builtinPropertiesSet, apiVersion = CURRENT_API_VERSION) => new Set([...Object.keys(getBuiltinProperties('shape-id', builtinPropertiesSet, apiVersion)), workflowsEnabled(apiVersion) ? '_status' : undefined].filter(isDefined));
|
|
347
327
|
export function applyBuiltinPropertiesToShape(projectSchema, shape) {
|
|
348
328
|
const builtinSet = getBuiltinPropertiesSet(shape);
|
|
349
|
-
|
|
350
329
|
if (builtinSet === 'none') {
|
|
351
330
|
return shape;
|
|
352
331
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
schema: {
|
|
356
|
-
|
|
332
|
+
return {
|
|
333
|
+
...shape,
|
|
334
|
+
schema: {
|
|
335
|
+
...shape.schema,
|
|
336
|
+
properties: {
|
|
337
|
+
...omitBy(dereferenceObjectSchema(projectSchema, shape.schema, ['shapes', shape.name]).properties, (_, name) => name.startsWith('_')),
|
|
357
338
|
...getBuiltinProperties(shape.id, builtinSet, projectSchema.apiVersion),
|
|
358
339
|
...(builtinSet === 'model' && workflowsEnabled(projectSchema.apiVersion) && {
|
|
359
340
|
_status: getStatusField(projectSchema.workflows, shape)
|
|
@@ -361,18 +342,20 @@ export function applyBuiltinPropertiesToShape(projectSchema, shape) {
|
|
|
361
342
|
}
|
|
362
343
|
}
|
|
363
344
|
};
|
|
364
|
-
}
|
|
345
|
+
}
|
|
365
346
|
|
|
347
|
+
// Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
|
|
366
348
|
const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TSStaticSite', 'TSUser'];
|
|
349
|
+
|
|
367
350
|
/**
|
|
368
351
|
* Get all built-in shapes that are depended on by the given project schema.
|
|
369
352
|
* Required built-in shapes are always included.
|
|
370
353
|
*/
|
|
371
|
-
|
|
372
354
|
export function getBuiltinsUsed(projectSchema) {
|
|
373
355
|
const builtinsUsed = {};
|
|
374
356
|
const shapeNames = uniq(requiredBuiltinShapes.concat(getAllRefs(projectSchema, refItem => refItem.serviceKey === 'local' && isBuiltinShape(refItem.typeName)).map(refItemToShapeName)));
|
|
375
|
-
const schemaWithAllBuiltins = {
|
|
357
|
+
const schemaWithAllBuiltins = {
|
|
358
|
+
...emptySchema('project-id'),
|
|
376
359
|
shapes: builtInShapes
|
|
377
360
|
};
|
|
378
361
|
shapeNames.forEach(builtinShapeName => {
|
|
@@ -385,42 +368,46 @@ export function getBuiltinsUsed(projectSchema) {
|
|
|
385
368
|
}
|
|
386
369
|
export function applyDefaultsToSchema(projectSchema) {
|
|
387
370
|
const builtinsUsed = getBuiltinsUsed(projectSchema);
|
|
388
|
-
return {
|
|
389
|
-
|
|
371
|
+
return {
|
|
372
|
+
...projectSchema,
|
|
373
|
+
workflows: {
|
|
374
|
+
...projectSchema.workflows,
|
|
390
375
|
...(workflowsEnabled(projectSchema.apiVersion) && {
|
|
391
376
|
default: defaultWorkflow
|
|
392
377
|
})
|
|
393
378
|
},
|
|
394
|
-
queries: {
|
|
379
|
+
queries: {
|
|
380
|
+
...builtInQueriesAndMutations.queries,
|
|
395
381
|
...projectSchema.queries
|
|
396
382
|
},
|
|
397
|
-
mutations: {
|
|
383
|
+
mutations: {
|
|
384
|
+
...builtInQueriesAndMutations.mutations,
|
|
398
385
|
...projectSchema.mutations
|
|
399
386
|
},
|
|
400
|
-
shapes: mapValues({
|
|
387
|
+
shapes: mapValues({
|
|
388
|
+
...builtinsUsed,
|
|
401
389
|
...projectSchema.shapes
|
|
402
390
|
}, shape => {
|
|
403
391
|
const builtInShape = builtinsUsed[shape.name];
|
|
404
|
-
|
|
405
392
|
if (builtInShape && builtInShape !== shape) {
|
|
406
|
-
shape = {
|
|
393
|
+
shape = {
|
|
394
|
+
...shape,
|
|
407
395
|
schema: mergeSchemaProperties(dereferenceObjectSchema(projectSchema, shape.schema), dereferenceObjectSchema(projectSchema, builtInShape.schema))
|
|
408
396
|
};
|
|
409
397
|
}
|
|
410
|
-
|
|
411
398
|
return applyBuiltinPropertiesToShape(projectSchema, shape);
|
|
412
399
|
}),
|
|
413
|
-
forms: mapValues({
|
|
400
|
+
forms: mapValues({
|
|
401
|
+
...builtInForms,
|
|
414
402
|
...projectSchema.forms
|
|
415
403
|
}, (formsConfig, shapeName) => {
|
|
416
404
|
const builtInFormsConfig = builtInForms[shapeName];
|
|
417
|
-
|
|
418
405
|
if (builtInFormsConfig && builtInFormsConfig !== formsConfig) {
|
|
419
|
-
formsConfig = {
|
|
406
|
+
formsConfig = {
|
|
407
|
+
...formsConfig,
|
|
420
408
|
default: mergeFormProperties(formsConfig.default, builtInFormsConfig.default)
|
|
421
409
|
};
|
|
422
410
|
}
|
|
423
|
-
|
|
424
411
|
return formsConfig;
|
|
425
412
|
})
|
|
426
413
|
};
|
|
@@ -433,11 +420,9 @@ export function getShapeByRef(projectSchema, shapeRef) {
|
|
|
433
420
|
}
|
|
434
421
|
export function ensureShapeById(projectSchema, shapeId) {
|
|
435
422
|
const shape = getShapeById(projectSchema, shapeId);
|
|
436
|
-
|
|
437
423
|
if (!shape) {
|
|
438
424
|
throw new NotFoundError(`Shape ${shapeId} Not found`);
|
|
439
425
|
}
|
|
440
|
-
|
|
441
426
|
return shape;
|
|
442
427
|
}
|
|
443
428
|
export function getShape(context, name) {
|
|
@@ -448,12 +433,10 @@ export function isModelShape(shape) {
|
|
|
448
433
|
}
|
|
449
434
|
export function isCachedShape(shape) {
|
|
450
435
|
var _shape$cache;
|
|
451
|
-
|
|
452
436
|
return ((_shape$cache = shape.cache) === null || _shape$cache === void 0 ? void 0 : _shape$cache.enabled) === true && shape.loaders !== undefined;
|
|
453
437
|
}
|
|
454
438
|
export function getArgsReference(projectSchema, argsSchema) {
|
|
455
439
|
const args = getArgs(argsSchema);
|
|
456
|
-
|
|
457
440
|
if (args && typeof args === 'string') {
|
|
458
441
|
// @args: ShapeName OR Namespace_TypeName
|
|
459
442
|
return refExpressionToRefItem(projectSchema, args);
|
|
@@ -461,21 +444,19 @@ export function getArgsReference(projectSchema, argsSchema) {
|
|
|
461
444
|
}
|
|
462
445
|
export function getArgsReferenceWithPath(context, argsSchema, schemaPath = []) {
|
|
463
446
|
const refItem = getArgsReference(context, argsSchema);
|
|
464
|
-
|
|
465
447
|
if (refItem) {
|
|
466
448
|
const argsType = getArgsType(argsSchema);
|
|
467
|
-
return {
|
|
449
|
+
return {
|
|
450
|
+
...refItem,
|
|
468
451
|
path: schemaPath.concat([argsType])
|
|
469
452
|
};
|
|
470
453
|
}
|
|
471
454
|
}
|
|
472
455
|
export function getArgsShapeSchema(context, argsSchema) {
|
|
473
456
|
const args = getArgs(argsSchema);
|
|
474
|
-
|
|
475
457
|
if (args) {
|
|
476
458
|
if (typeof args === 'string') {
|
|
477
459
|
const refItem = getArgsReference(context, argsSchema);
|
|
478
|
-
|
|
479
460
|
if (refItem) {
|
|
480
461
|
return refItemToShapeSchema(context, refItem);
|
|
481
462
|
}
|
|
@@ -484,7 +465,6 @@ export function getArgsShapeSchema(context, argsSchema) {
|
|
|
484
465
|
}
|
|
485
466
|
}
|
|
486
467
|
}
|
|
487
|
-
|
|
488
468
|
const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, {
|
|
489
469
|
useShapeIdDiscriminator
|
|
490
470
|
}) => {
|
|
@@ -492,24 +472,21 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
|
|
|
492
472
|
const handleSchema = propSchema => {
|
|
493
473
|
// Unwrap array schema
|
|
494
474
|
propSchema = propSchema.items ?? propSchema;
|
|
495
|
-
|
|
496
475
|
if (isOneOfSchema(propSchema)) {
|
|
497
476
|
const isUnion = isUnionSchema(propSchema);
|
|
498
|
-
|
|
499
477
|
if (useShapeIdDiscriminator && isUnion) {
|
|
500
478
|
propSchema.discriminator = {
|
|
501
479
|
propertyName: '_shapeId'
|
|
502
480
|
};
|
|
503
481
|
propSchema.required = ['_shapeId'];
|
|
504
482
|
}
|
|
505
|
-
|
|
506
483
|
propSchema.oneOf.forEach(schema => {
|
|
507
484
|
handleSchema(schema);
|
|
508
485
|
});
|
|
509
486
|
return;
|
|
510
|
-
}
|
|
511
|
-
|
|
487
|
+
}
|
|
512
488
|
|
|
489
|
+
// Add workflow validation
|
|
513
490
|
if (propSchema['@workflow']) {
|
|
514
491
|
const workflowName = propSchema['@workflow'];
|
|
515
492
|
const workflow = projectSchema.workflows[workflowName] || defaultWorkflow;
|
|
@@ -518,67 +495,54 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
|
|
|
518
495
|
title: step.title
|
|
519
496
|
}));
|
|
520
497
|
}
|
|
521
|
-
|
|
522
498
|
const refItem = getRef(projectSchema, propSchema);
|
|
523
|
-
|
|
524
499
|
if (refItem) {
|
|
525
500
|
const shapeName = refItemToShapeName(refItem);
|
|
526
501
|
const shape = refItemToShape(projectSchema, refItem);
|
|
527
|
-
|
|
528
502
|
if (shape) {
|
|
529
503
|
delete propSchema['@ref'];
|
|
530
504
|
propSchema.$ref = `#/definitions/${shapeName}`;
|
|
531
|
-
|
|
532
505
|
if (!definitionNames.has(shapeName)) {
|
|
533
506
|
definitionNames.add(shapeName);
|
|
534
507
|
const rewritten = rewriteRefs(shape);
|
|
535
|
-
|
|
536
508
|
if (useShapeIdDiscriminator && isObjectSchema(rewritten)) {
|
|
537
509
|
rewritten.properties._shapeId = {
|
|
538
510
|
type: 'string',
|
|
539
511
|
enum: [shape.id]
|
|
540
512
|
};
|
|
541
513
|
}
|
|
542
|
-
|
|
543
514
|
definitions[shapeName] = rewritten;
|
|
544
515
|
}
|
|
545
516
|
}
|
|
546
517
|
}
|
|
547
518
|
};
|
|
548
|
-
|
|
549
519
|
const shapeSchema = deepClone(shape.schema);
|
|
550
|
-
|
|
551
520
|
if (isOneOfSchema(shapeSchema)) {
|
|
552
521
|
handleSchema(shapeSchema);
|
|
553
522
|
return shapeSchema;
|
|
554
523
|
}
|
|
555
|
-
|
|
556
524
|
if (shapeSchema.enum) {
|
|
557
525
|
return shapeSchema;
|
|
558
526
|
}
|
|
559
|
-
|
|
560
527
|
const shapeSchemaCopy = dereferenceObjectSchema(projectSchema, shapeSchema);
|
|
561
|
-
|
|
562
528
|
if (shape.title) {
|
|
563
529
|
shapeSchemaCopy.title = shape.title;
|
|
564
530
|
}
|
|
565
|
-
|
|
566
531
|
Object.values(shapeSchemaCopy.properties).forEach(schema => {
|
|
567
532
|
handleSchema(schema);
|
|
568
533
|
});
|
|
569
534
|
return shapeSchemaCopy;
|
|
570
535
|
};
|
|
571
|
-
|
|
572
536
|
return rewriteRefs;
|
|
573
537
|
};
|
|
574
|
-
|
|
575
538
|
export function shapeToPropertySchema(projectSchema, shape) {
|
|
576
539
|
const definitions = {};
|
|
577
540
|
const definitionNames = new Set();
|
|
578
541
|
const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
|
|
579
542
|
useShapeIdDiscriminator: true
|
|
580
543
|
});
|
|
581
|
-
return {
|
|
544
|
+
return {
|
|
545
|
+
...convert(shape),
|
|
582
546
|
definitions
|
|
583
547
|
};
|
|
584
548
|
}
|
|
@@ -588,29 +552,23 @@ export function projectSchemaToJSONSchema(projectSchema) {
|
|
|
588
552
|
const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
|
|
589
553
|
useShapeIdDiscriminator: false
|
|
590
554
|
});
|
|
591
|
-
|
|
592
555
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
593
556
|
definitions[shape.name] = convert(shape);
|
|
594
557
|
definitionNames.add(shape.name);
|
|
595
558
|
}
|
|
596
|
-
|
|
597
559
|
return {
|
|
598
560
|
definitions
|
|
599
561
|
};
|
|
600
562
|
}
|
|
601
563
|
export function getShapeDependencies(projectSchema, shape, predicate) {
|
|
602
564
|
const shapeNames = new Set();
|
|
603
|
-
|
|
604
565
|
const findDependencies = schema => {
|
|
605
566
|
const shouldFollow = Boolean(!predicate || predicate(schema));
|
|
606
|
-
|
|
607
567
|
if (shouldFollow) {
|
|
608
568
|
schema = schema.items ?? schema;
|
|
609
569
|
const refItem = getRef(projectSchema, schema);
|
|
610
|
-
|
|
611
570
|
if (refItem) {
|
|
612
571
|
const refShape = refItemToShape(projectSchema, refItem);
|
|
613
|
-
|
|
614
572
|
if (refShape && !shapeNames.has(refShape.name)) {
|
|
615
573
|
shapeNames.add(refShape.name);
|
|
616
574
|
findDependencies(dereferenceSchema(projectSchema, refShape.schema, ['shapes', refShape.name]));
|
|
@@ -619,10 +577,8 @@ export function getShapeDependencies(projectSchema, shape, predicate) {
|
|
|
619
577
|
visitSchemaProperties(schema, [], findDependencies);
|
|
620
578
|
}
|
|
621
579
|
}
|
|
622
|
-
|
|
623
580
|
return shouldFollow;
|
|
624
581
|
};
|
|
625
|
-
|
|
626
582
|
findDependencies(shape.schema);
|
|
627
583
|
return [...shapeNames];
|
|
628
584
|
}
|
|
@@ -633,39 +589,31 @@ export function getRelevantShapes(projectSchema, params) {
|
|
|
633
589
|
byId = false,
|
|
634
590
|
includeDependencies = true
|
|
635
591
|
} = params;
|
|
636
|
-
|
|
637
592
|
if (shapeNames !== null && shapeNames !== void 0 && shapeNames.length || shapeIds !== null && shapeIds !== void 0 && shapeIds.length) {
|
|
638
593
|
const ids = new Set(shapeIds);
|
|
639
594
|
const names = new Set(shapeNames);
|
|
640
595
|
const shapes = {};
|
|
641
|
-
|
|
642
596
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
643
597
|
if (ids.has(shape.id) || names.has(shape.name)) {
|
|
644
598
|
const shapeNames = includeDependencies ? [shape.name].concat(getShapeDependencies(projectSchema, shape)) : [shape.name];
|
|
645
|
-
|
|
646
599
|
for (const shapeName of shapeNames) {
|
|
647
600
|
const dependentShape = projectSchema.shapes[shapeName];
|
|
648
601
|
shapes[byId ? dependentShape.id : dependentShape.name] = dependentShape;
|
|
649
602
|
}
|
|
650
603
|
}
|
|
651
604
|
}
|
|
652
|
-
|
|
653
605
|
return shapes;
|
|
654
606
|
}
|
|
655
|
-
|
|
656
607
|
return {};
|
|
657
608
|
}
|
|
658
|
-
|
|
659
609
|
function visitSchemaPropertiesHelper(entries, path, callback) {
|
|
660
610
|
for (const [name, propSchema] of entries) {
|
|
661
611
|
const newPath = [...path, name];
|
|
662
|
-
|
|
663
612
|
if (callback(propSchema, newPath) !== false && (isObjectSchema(propSchema) || isExtendsSchema(propSchema) || isAllOfSchema(propSchema) || isOneOfSchema(propSchema))) {
|
|
664
613
|
visitSchemaProperties(propSchema, newPath, callback);
|
|
665
614
|
}
|
|
666
615
|
}
|
|
667
616
|
}
|
|
668
|
-
|
|
669
617
|
export function visitSchemaProperties(schema, path, callback) {
|
|
670
618
|
if (isArraySchema(schema)) {
|
|
671
619
|
visitSchemaPropertiesHelper(Object.entries(schema.items), [...path, 'items'], callback);
|
|
@@ -686,17 +634,15 @@ export function visitShapeProperties(shapes, callback) {
|
|
|
686
634
|
visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], callback);
|
|
687
635
|
}
|
|
688
636
|
}
|
|
689
|
-
|
|
690
637
|
function addRef(refs, ref, predicate) {
|
|
691
638
|
if (ref && (!predicate || predicate(ref))) {
|
|
692
639
|
refs.push(ref);
|
|
693
640
|
}
|
|
694
641
|
}
|
|
642
|
+
|
|
695
643
|
/**
|
|
696
644
|
* Walk through a `ProjectSchemaJSON` and collect all the `ref`s.
|
|
697
645
|
*/
|
|
698
|
-
|
|
699
|
-
|
|
700
646
|
export function getAllRefsInShapes(projectSchema, predicate) {
|
|
701
647
|
const items = [];
|
|
702
648
|
const refPropNames = ['$ref', '@ref', '@args', 'args'];
|
|
@@ -707,93 +653,85 @@ export function getAllRefsInShapes(projectSchema, predicate) {
|
|
|
707
653
|
if (!isString(ref)) {
|
|
708
654
|
return;
|
|
709
655
|
}
|
|
710
|
-
|
|
711
656
|
const propName = refPath[refPath.length - 1];
|
|
712
657
|
const path = ['shapes', ...refPath];
|
|
713
658
|
let refItem = {};
|
|
714
|
-
|
|
715
659
|
if (propName === '@ref') {
|
|
716
660
|
const {
|
|
717
661
|
shapeName,
|
|
718
662
|
template
|
|
719
663
|
} = parseTemplateShape(ref);
|
|
720
|
-
refItem = {
|
|
664
|
+
refItem = {
|
|
665
|
+
...atRefToRefItem(projectSchema, shapeName, template),
|
|
721
666
|
path
|
|
722
667
|
};
|
|
723
668
|
} else if (propName === '$ref') {
|
|
724
|
-
refItem = {
|
|
669
|
+
refItem = {
|
|
670
|
+
...refToRefItem(projectSchema, ref),
|
|
725
671
|
path
|
|
726
672
|
};
|
|
727
673
|
} else if (propName === '@args' || propName === 'args') {
|
|
728
|
-
refItem = {
|
|
674
|
+
refItem = {
|
|
675
|
+
...refExpressionToRefItem(projectSchema, ref),
|
|
729
676
|
path
|
|
730
677
|
};
|
|
731
678
|
}
|
|
732
|
-
|
|
733
679
|
if (isRefItemWithPath(refItem)) {
|
|
734
680
|
addRef(items, refItem, predicate);
|
|
735
681
|
}
|
|
736
682
|
});
|
|
737
683
|
return items;
|
|
738
684
|
}
|
|
685
|
+
|
|
739
686
|
/**
|
|
740
687
|
* Get all refs
|
|
741
688
|
*/
|
|
742
|
-
|
|
743
689
|
export function getAllRefsInQuery(projectSchema, queryPath, query, predicate) {
|
|
744
690
|
const refItems = [];
|
|
745
|
-
|
|
746
691
|
const propertyVisitor = (propSchema, propSchemaPath) => {
|
|
747
692
|
addRef(refItems, getRefOrItemsRef(projectSchema, propSchema, propSchemaPath), predicate);
|
|
748
693
|
};
|
|
749
|
-
|
|
750
694
|
if (query.args && typeof query.args === 'string') {
|
|
751
695
|
addRef(refItems, getArgsReferenceWithPath(projectSchema, query, queryPath), predicate);
|
|
752
696
|
}
|
|
753
|
-
|
|
754
697
|
if (query.args && typeof query.args === 'object') {
|
|
755
698
|
visitSchemaProperties(dereferenceObjectSchema(projectSchema, query.args), [...queryPath, 'args'], propertyVisitor);
|
|
756
699
|
}
|
|
757
|
-
|
|
758
700
|
if (query.shape) {
|
|
759
701
|
const {
|
|
760
702
|
isArray,
|
|
761
703
|
ref
|
|
762
704
|
} = parseReturnShape(projectSchema, query.shape);
|
|
763
|
-
|
|
764
705
|
if (ref) {
|
|
765
|
-
addRef(refItems, {
|
|
706
|
+
addRef(refItems, {
|
|
707
|
+
...ref,
|
|
766
708
|
path: queryPath.concat(isArray ? ['shape', 'items', '@ref'] : ['shape'])
|
|
767
709
|
}, predicate);
|
|
768
710
|
}
|
|
769
711
|
}
|
|
770
|
-
|
|
771
712
|
return refItems;
|
|
772
713
|
}
|
|
714
|
+
|
|
773
715
|
/**
|
|
774
716
|
* Collect refs from `queries` or `mutations`.
|
|
775
717
|
*/
|
|
776
|
-
|
|
777
718
|
export function getAllRefsInQueries(projectSchema, rootPropertyName, predicate) {
|
|
778
719
|
const refItems = [];
|
|
779
720
|
const rootPath = [rootPropertyName];
|
|
780
|
-
|
|
781
721
|
for (const [queryName, query] of Object.entries(projectSchema[rootPropertyName])) {
|
|
782
722
|
const queryPath = rootPath.concat([queryName]);
|
|
783
723
|
const queryRefs = getAllRefsInQuery(projectSchema, queryPath, query, predicate);
|
|
784
|
-
|
|
785
724
|
if (queryRefs.length) {
|
|
786
725
|
refItems.push(...queryRefs);
|
|
787
726
|
}
|
|
788
727
|
}
|
|
789
|
-
|
|
790
728
|
return refItems;
|
|
791
729
|
}
|
|
730
|
+
|
|
792
731
|
/**
|
|
793
732
|
* Get all refs in a ProjectSchemaJSON
|
|
794
733
|
* @param predicate return true to include the ref in
|
|
795
734
|
*/
|
|
796
|
-
|
|
797
735
|
export function getAllRefs(projectSchema, predicate) {
|
|
798
736
|
return [...getAllRefsInShapes(projectSchema, predicate), ...getAllRefsInQueries(projectSchema, 'queries', predicate), ...getAllRefsInQueries(projectSchema, 'mutations', predicate)];
|
|
799
737
|
}
|
|
@@ -812,11 +750,9 @@ export function splitMapping(mapping) {
|
|
|
812
750
|
}
|
|
813
751
|
export function findMapping(schema, predicate) {
|
|
814
752
|
const mapping = schema['@mapping'];
|
|
815
|
-
|
|
816
753
|
if (Array.isArray(mapping)) {
|
|
817
754
|
return mapping.find(predicate);
|
|
818
755
|
}
|
|
819
|
-
|
|
820
756
|
return mapping && predicate(mapping) ? mapping : undefined;
|
|
821
757
|
}
|
|
822
758
|
export function getFirstMapping(schema) {
|
|
@@ -826,12 +762,12 @@ export function getFullyQualifiedShapeName(schema) {
|
|
|
826
762
|
const first = getFirstMapping(schema);
|
|
827
763
|
return first ? splitMapping(first)[0] : undefined;
|
|
828
764
|
}
|
|
765
|
+
|
|
829
766
|
/**
|
|
830
767
|
* Find key for use storing data in ShapeDB or API Indexing this allows renaming of properties without db migration
|
|
831
768
|
* Mapping must be using the shapedb service id
|
|
832
769
|
* @param schema
|
|
833
770
|
*/
|
|
834
|
-
|
|
835
771
|
export function getStorageKey(schema) {
|
|
836
772
|
const first = findMapping(schema, mapping => mapping.startsWith('shapedb:'));
|
|
837
773
|
return first ? splitMapping(first)[1] : undefined;
|
|
@@ -858,6 +794,7 @@ export function emptySchema(projectId) {
|
|
|
858
794
|
export function getShapesById(projectSchema) {
|
|
859
795
|
return keyBy(Object.values(projectSchema.shapes), 'id');
|
|
860
796
|
}
|
|
797
|
+
|
|
861
798
|
/**
|
|
862
799
|
* Walk through the project schema and return an array of all
|
|
863
800
|
* referenced shape names that are in a service namespace.
|
|
@@ -866,12 +803,11 @@ export function getShapesById(projectSchema) {
|
|
|
866
803
|
*
|
|
867
804
|
* @returns A `string` array with all the shapes that are in namespaces.
|
|
868
805
|
*/
|
|
869
|
-
|
|
870
806
|
export function getAllNamespaceShapes(projectSchema) {
|
|
871
807
|
const isServiceRef = refItem => Boolean(refItem.serviceNamespace);
|
|
872
|
-
|
|
873
808
|
return uniq(getAllRefs(projectSchema, isServiceRef).map(refItemToShapeName));
|
|
874
809
|
}
|
|
810
|
+
|
|
875
811
|
/**
|
|
876
812
|
* Returns a list of all shape names in a service namespace, excluding any
|
|
877
813
|
* that have been set directly in the project schema
|
|
@@ -884,15 +820,17 @@ export function getAllNamespaceShapes(projectSchema) {
|
|
|
884
820
|
*
|
|
885
821
|
* @returns A `Set` of shape names.
|
|
886
822
|
*/
|
|
887
|
-
|
|
888
823
|
export function getNamespacedShapeNameList(projectSchema) {
|
|
889
|
-
const requiredShapeNames = new Set();
|
|
824
|
+
const requiredShapeNames = new Set();
|
|
890
825
|
|
|
891
|
-
|
|
826
|
+
// All the shape names
|
|
827
|
+
const existingShapeNames = new Set(Object.keys(projectSchema.shapes));
|
|
892
828
|
|
|
893
|
-
|
|
894
|
-
|
|
829
|
+
// All the referenced shape names with namespaces that belong to a service
|
|
830
|
+
const namespacedShapeNames = new Set(getAllNamespaceShapes(projectSchema));
|
|
895
831
|
|
|
832
|
+
// Add all namespaced shapes to the schema if they are not already present,
|
|
833
|
+
// e.g. Shopify_Product
|
|
896
834
|
namespacedShapeNames.forEach(name => {
|
|
897
835
|
if (!existingShapeNames.has(name)) {
|
|
898
836
|
requiredShapeNames.add(name);
|
|
@@ -900,6 +838,7 @@ export function getNamespacedShapeNameList(projectSchema) {
|
|
|
900
838
|
});
|
|
901
839
|
return requiredShapeNames;
|
|
902
840
|
}
|
|
841
|
+
|
|
903
842
|
/**
|
|
904
843
|
* Filter the service map to return only services passing the GraphQL Service
|
|
905
844
|
* typeguard.
|
|
@@ -908,71 +847,58 @@ export function getNamespacedShapeNameList(projectSchema) {
|
|
|
908
847
|
*
|
|
909
848
|
* @returns A new map with the filtered list of services
|
|
910
849
|
*/
|
|
911
|
-
|
|
912
850
|
export function filterGraphQLServiceMap(serviceMap) {
|
|
913
851
|
const filtered = new Map();
|
|
914
|
-
|
|
915
852
|
for (const [serviceKey, serviceConfig] of serviceMap) {
|
|
916
853
|
if (serviceConfig.serviceType === 'graphql') {
|
|
917
854
|
filtered.set(serviceKey, serviceConfig);
|
|
918
855
|
}
|
|
919
856
|
}
|
|
920
|
-
|
|
921
857
|
return filtered;
|
|
922
858
|
}
|
|
859
|
+
|
|
923
860
|
/**
|
|
924
861
|
* Add all referenced shape names to the refSet meant to be used as a callback to visitSchemaProperties
|
|
925
862
|
*/
|
|
926
|
-
|
|
927
863
|
export function collectReferencedShapeNames(context, shapeNames) {
|
|
928
864
|
const addRef = refItem => {
|
|
929
865
|
shapeNames.add(refItemToShapeName(refItem));
|
|
930
866
|
};
|
|
931
|
-
|
|
932
867
|
const collect = schema => {
|
|
933
868
|
const args = schema['@args'];
|
|
934
|
-
|
|
935
869
|
if (args && isObject(args) && isObjectSchema(args)) {
|
|
936
870
|
Object.values(args.properties).forEach(collect);
|
|
937
871
|
}
|
|
938
|
-
|
|
939
872
|
const argsRefItem = getArgsReference(context, schema);
|
|
940
|
-
|
|
941
873
|
if (argsRefItem) {
|
|
942
874
|
addRef(argsRefItem);
|
|
943
875
|
}
|
|
944
|
-
|
|
945
876
|
const refItem = getRefOrItemsRef(context, schema);
|
|
946
|
-
|
|
947
877
|
if (refItem) {
|
|
948
878
|
addRef(refItem);
|
|
949
879
|
}
|
|
950
880
|
};
|
|
951
|
-
|
|
952
881
|
return collect;
|
|
953
882
|
}
|
|
883
|
+
|
|
954
884
|
/**
|
|
955
885
|
* Creates a schema property list chainable fn, allowing you to manipulate and
|
|
956
886
|
* iterate the properties in a schema.
|
|
957
887
|
*/
|
|
958
|
-
|
|
959
888
|
export const createSchemaPropertyList = curry((context, shapeOrSchema) => {
|
|
960
889
|
const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
|
|
961
890
|
const schema = dereferenceSchema(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
|
|
962
891
|
const propertyIterator = new Map(isObjectSchema(schema) ? Object.entries(schema.properties) : undefined);
|
|
963
892
|
const defaultOrderByIteratees = [n => n[0]];
|
|
964
893
|
const defaultOrderByOrders = ['asc'];
|
|
965
|
-
|
|
966
894
|
const _orderBy = (iteratees = defaultOrderByIteratees, orders = defaultOrderByOrders) => {
|
|
967
895
|
self._propertyIterator = new Map(orderBy(iteratees, orders, Array.from(self._propertyIterator)));
|
|
968
896
|
return self;
|
|
969
897
|
};
|
|
970
|
-
|
|
971
898
|
const _sortWith = comparator => {
|
|
972
899
|
self._propertyIterator = new Map(Array.from(self._propertyIterator).sort(comparator));
|
|
973
900
|
return self;
|
|
974
901
|
};
|
|
975
|
-
|
|
976
902
|
const _sortByNamesWithList = comparatorArray => {
|
|
977
903
|
// If no array is provided, the original sort is preserved
|
|
978
904
|
if (comparatorArray) {
|
|
@@ -982,38 +908,30 @@ export const createSchemaPropertyList = curry((context, shapeOrSchema) => {
|
|
|
982
908
|
return (indexA > -1 ? indexA : Infinity) - (indexB > -1 ? indexB : Infinity);
|
|
983
909
|
}));
|
|
984
910
|
}
|
|
985
|
-
|
|
986
911
|
return self;
|
|
987
912
|
};
|
|
988
|
-
|
|
989
913
|
const _filterBy = predicate => {
|
|
990
914
|
self._propertyIterator = new Map(Array.from(self._propertyIterator).filter(predicate));
|
|
991
915
|
return self;
|
|
992
916
|
};
|
|
993
|
-
|
|
994
917
|
const _forEach = iteratee => {
|
|
995
918
|
Array.from(self._propertyIterator).forEach(iteratee);
|
|
996
919
|
return self;
|
|
997
920
|
};
|
|
998
|
-
|
|
999
921
|
const _getNodes = () => {
|
|
1000
922
|
return Array.from(self._propertyIterator);
|
|
1001
923
|
};
|
|
1002
|
-
|
|
1003
924
|
const _getObject = () => {
|
|
1004
925
|
return Array.from(self._propertyIterator).reduce((curr, node) => Object.assign(curr, {
|
|
1005
926
|
[node[0]]: node[1]
|
|
1006
927
|
}), {});
|
|
1007
928
|
};
|
|
1008
|
-
|
|
1009
929
|
const _getNames = () => {
|
|
1010
930
|
return Array.from(self._propertyIterator, ([name]) => name);
|
|
1011
931
|
};
|
|
1012
|
-
|
|
1013
932
|
const _getValues = () => {
|
|
1014
933
|
return Array.from(self._propertyIterator, ([, value]) => value);
|
|
1015
934
|
};
|
|
1016
|
-
|
|
1017
935
|
const self = {
|
|
1018
936
|
_propertyIterator: propertyIterator,
|
|
1019
937
|
orderBy: _orderBy,
|
|
@@ -1028,11 +946,9 @@ export const createSchemaPropertyList = curry((context, shapeOrSchema) => {
|
|
|
1028
946
|
};
|
|
1029
947
|
return self;
|
|
1030
948
|
});
|
|
1031
|
-
|
|
1032
949
|
function isShape(shapeOrSchema) {
|
|
1033
950
|
return 'schema' in shapeOrSchema;
|
|
1034
951
|
}
|
|
1035
|
-
|
|
1036
952
|
class SchemaPropertyAccessor {
|
|
1037
953
|
constructor(context, shapeOrSchema) {
|
|
1038
954
|
const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
|
|
@@ -1040,33 +956,24 @@ class SchemaPropertyAccessor {
|
|
|
1040
956
|
this.entries = isObjectSchema(this.schema) ? Object.entries(this.schema.properties) : [];
|
|
1041
957
|
this.properties = new Map(this.entries);
|
|
1042
958
|
}
|
|
1043
|
-
|
|
1044
959
|
getValue(propertyName) {
|
|
1045
960
|
return this.properties.get(propertyName);
|
|
1046
961
|
}
|
|
1047
|
-
|
|
1048
962
|
findValue(predicate) {
|
|
1049
963
|
var _this$entries$find;
|
|
1050
|
-
|
|
1051
964
|
return (_this$entries$find = this.entries.find(predicate)) === null || _this$entries$find === void 0 ? void 0 : _this$entries$find[1];
|
|
1052
965
|
}
|
|
1053
|
-
|
|
1054
966
|
findName(predicate) {
|
|
1055
967
|
var _this$entries$find2;
|
|
1056
|
-
|
|
1057
968
|
return (_this$entries$find2 = this.entries.find(predicate)) === null || _this$entries$find2 === void 0 ? void 0 : _this$entries$find2[0];
|
|
1058
969
|
}
|
|
1059
|
-
|
|
1060
970
|
getKey(propertyName) {
|
|
1061
971
|
const value = this.properties.get(propertyName);
|
|
1062
|
-
|
|
1063
972
|
if (value) {
|
|
1064
973
|
return getStorageKey(value);
|
|
1065
974
|
}
|
|
1066
975
|
}
|
|
1067
|
-
|
|
1068
976
|
}
|
|
1069
|
-
|
|
1070
977
|
/**
|
|
1071
978
|
* Creates a schema property accessor, allowing you to safely access schema
|
|
1072
979
|
* properties.
|
|
@@ -1074,7 +981,6 @@ class SchemaPropertyAccessor {
|
|
|
1074
981
|
export const createSchemaPropertyAccessor = curry((context, shapeOrSchema) => {
|
|
1075
982
|
return new SchemaPropertyAccessor(context, shapeOrSchema);
|
|
1076
983
|
});
|
|
1077
|
-
|
|
1078
984
|
function findQueryHelper(slice, shapeName, resolver, type) {
|
|
1079
985
|
const schemaPath = type === 'query' ? 'queries' : 'mutations';
|
|
1080
986
|
return Object.keys(slice[schemaPath]).find(queryName => {
|
|
@@ -1082,40 +988,33 @@ function findQueryHelper(slice, shapeName, resolver, type) {
|
|
|
1082
988
|
return queryOrMutation.resolver.name === resolver && queryOrMutation.resolver.shapeName === shapeName;
|
|
1083
989
|
});
|
|
1084
990
|
}
|
|
1085
|
-
|
|
1086
991
|
function ensureQueryHelper(slice, shapeName, resolver, type) {
|
|
1087
992
|
const foundQuery = findQueryHelper(slice, shapeName, resolver, type);
|
|
1088
|
-
|
|
1089
993
|
if (!foundQuery) {
|
|
1090
994
|
throw new Error(`Failed to find a "${resolver}" ${type} for shape "${shapeName}"`);
|
|
1091
995
|
}
|
|
1092
|
-
|
|
1093
996
|
return foundQuery;
|
|
1094
997
|
}
|
|
998
|
+
|
|
1095
999
|
/**
|
|
1096
1000
|
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1097
1001
|
*/
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
1002
|
export const findQueryByShape = (projectSchema, shapeName, resolver) => findQueryHelper(projectSchema, shapeName, resolver, 'query');
|
|
1101
1003
|
/**
|
|
1102
1004
|
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1103
1005
|
*/
|
|
1104
|
-
|
|
1105
1006
|
export const findMutationByShape = (projectSchema, shapeName, resolver) => findQueryHelper(projectSchema, shapeName, resolver, 'mutation');
|
|
1007
|
+
|
|
1106
1008
|
/**
|
|
1107
1009
|
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1108
1010
|
* Throw an error if that query does not exist
|
|
1109
1011
|
*/
|
|
1110
|
-
|
|
1111
1012
|
export const ensureQueryByShape = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'query');
|
|
1112
1013
|
/**
|
|
1113
1014
|
* Find the mutation in the schema that corresponds to the given shape and resolver.
|
|
1114
1015
|
* Throw an error if that mutation does not exist
|
|
1115
1016
|
*/
|
|
1116
|
-
|
|
1117
1017
|
export const ensureMutationByShape = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'mutation');
|
|
1118
|
-
|
|
1119
1018
|
/**
|
|
1120
1019
|
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1121
1020
|
*/
|
|
@@ -1134,7 +1033,6 @@ export function createShape(name, schema, rest) {
|
|
|
1134
1033
|
}
|
|
1135
1034
|
export function queryToPropertySchema(projectSchema, query) {
|
|
1136
1035
|
let mapping;
|
|
1137
|
-
|
|
1138
1036
|
if (isGraphqlResolver(query.resolver)) {
|
|
1139
1037
|
mapping = serializePropertyRef({
|
|
1140
1038
|
serviceId: query.resolver.service,
|
|
@@ -1142,8 +1040,8 @@ export function queryToPropertySchema(projectSchema, query) {
|
|
|
1142
1040
|
propertyName: query.resolver.fieldName
|
|
1143
1041
|
});
|
|
1144
1042
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1043
|
+
return {
|
|
1044
|
+
...returnShapeToSchema(projectSchema, query.shape),
|
|
1147
1045
|
...(mapping ? {
|
|
1148
1046
|
'@mapping': mapping
|
|
1149
1047
|
} : {}),
|
|
@@ -1161,35 +1059,32 @@ export function fieldMappingContainsKey(fieldMapping, key) {
|
|
|
1161
1059
|
if (isArray(fieldMapping)) {
|
|
1162
1060
|
return some(fieldMapping, mapping => parseMapping(mapping).key === key);
|
|
1163
1061
|
}
|
|
1164
|
-
|
|
1165
1062
|
return parseMapping(fieldMapping).key === key;
|
|
1166
1063
|
}
|
|
1064
|
+
|
|
1167
1065
|
/**
|
|
1168
1066
|
* Return true if `schemaWithRef` is a ref to a shape named `shapeName`
|
|
1169
1067
|
*/
|
|
1170
|
-
|
|
1171
1068
|
export const schemaMatchesShapeName = (workingCopy, schemaWithRef, shapeName) => {
|
|
1172
1069
|
const arrayOfShapeRef = getRef(workingCopy, schemaWithRef);
|
|
1173
1070
|
invariant(arrayOfShapeRef);
|
|
1174
1071
|
const arrayOfShapeName = refItemToShapeName(arrayOfShapeRef);
|
|
1175
1072
|
return arrayOfShapeName === shapeName;
|
|
1176
1073
|
};
|
|
1074
|
+
|
|
1177
1075
|
/**
|
|
1178
1076
|
* Return true if `shape` has a property that is an array of refs to `shapeName`
|
|
1179
1077
|
*/
|
|
1180
|
-
|
|
1181
1078
|
export const shapeHasArrayPropOfShape = (projectSchema, shape, shapeName) => {
|
|
1182
1079
|
if (shape && isObjectSchema(shape.schema)) {
|
|
1183
1080
|
for (const propName in shape.schema.properties) {
|
|
1184
1081
|
if (Object.prototype.hasOwnProperty.call(shape.schema.properties, propName)) {
|
|
1185
1082
|
const propSchema = shape.schema.properties[propName];
|
|
1186
|
-
|
|
1187
1083
|
if (propSchema.items && isRefSchema(propSchema.items) && schemaMatchesShapeName(projectSchema, propSchema.items, shapeName)) {
|
|
1188
1084
|
return true;
|
|
1189
1085
|
}
|
|
1190
1086
|
}
|
|
1191
1087
|
}
|
|
1192
1088
|
}
|
|
1193
|
-
|
|
1194
1089
|
return false;
|
|
1195
1090
|
};
|