@takeshape/schema 9.49.0 → 9.49.2
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/migration/to/v3.32.0.d.ts.map +1 -1
- package/dist/migration/to/v3.32.0.js +10 -7
- package/dist/refs.d.ts +3 -3
- package/dist/refs.d.ts.map +1 -1
- package/dist/refs.js +3 -4
- package/dist/schema-util.d.ts +7 -7
- package/dist/schema-util.d.ts.map +1 -1
- package/dist/schema-util.js +2 -2
- package/dist/services.d.ts +3 -4
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +3 -19
- package/dist/types/types.d.ts +1 -7
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +0 -6
- package/dist/types/utils.d.ts +1 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/utils.js +0 -14
- package/dist/unions.d.ts +2 -3
- package/dist/unions.d.ts.map +1 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +68 -277
- package/es/migration/to/v3.32.0.js +10 -6
- package/es/refs.js +4 -5
- package/es/schema-util.js +2 -2
- package/es/services.js +3 -17
- package/es/types/types.js +0 -5
- package/es/types/utils.js +0 -10
- package/es/validate.js +68 -272
- package/package.json +5 -5
package/dist/validate.js
CHANGED
|
@@ -22,14 +22,10 @@ var _errors = require("@takeshape/errors");
|
|
|
22
22
|
|
|
23
23
|
var _coerce2 = _interopRequireDefault(require("semver/functions/coerce"));
|
|
24
24
|
|
|
25
|
-
var _satisfies = _interopRequireDefault(require("semver/functions/satisfies"));
|
|
26
|
-
|
|
27
25
|
var _neq = _interopRequireDefault(require("semver/functions/neq"));
|
|
28
26
|
|
|
29
27
|
var _lt = _interopRequireDefault(require("semver/functions/lt"));
|
|
30
28
|
|
|
31
|
-
var _gt = _interopRequireDefault(require("semver/functions/gt"));
|
|
32
|
-
|
|
33
29
|
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
34
30
|
|
|
35
31
|
var _versions = require("./versions");
|
|
@@ -56,12 +52,8 @@ var _unions = require("./unions");
|
|
|
56
52
|
|
|
57
53
|
var _enum = require("./enum");
|
|
58
54
|
|
|
59
|
-
var _metaSchemaV = _interopRequireDefault(require("./schemas/project-schema/meta-schema-v3.9.0.json"));
|
|
60
|
-
|
|
61
55
|
var _util = require("@takeshape/util");
|
|
62
56
|
|
|
63
|
-
var _forOwn = _interopRequireDefault(require("lodash/forOwn"));
|
|
64
|
-
|
|
65
57
|
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
|
|
66
58
|
|
|
67
59
|
var _initial = _interopRequireDefault(require("lodash/initial"));
|
|
@@ -72,10 +64,6 @@ var _relationships = require("./relationships");
|
|
|
72
64
|
|
|
73
65
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
74
66
|
|
|
75
|
-
var _gte = _interopRequireDefault(require("semver/functions/gte"));
|
|
76
|
-
|
|
77
|
-
var _lte = _interopRequireDefault(require("semver/functions/lte"));
|
|
78
|
-
|
|
79
67
|
var _size = _interopRequireDefault(require("lodash/size"));
|
|
80
68
|
|
|
81
69
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
@@ -86,6 +74,8 @@ var _pMap = _interopRequireDefault(require("p-map"));
|
|
|
86
74
|
|
|
87
75
|
var _lodash = require("lodash");
|
|
88
76
|
|
|
77
|
+
var _projectSchema = require("./project-schema");
|
|
78
|
+
|
|
89
79
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
90
80
|
|
|
91
81
|
const builtInShapeNames = new Set([...Object.keys(_builtinSchema.builtInShapes), ..._scalars.scalars, 'object']);
|
|
@@ -107,18 +97,6 @@ function findDuplicates(items) {
|
|
|
107
97
|
}));
|
|
108
98
|
}
|
|
109
99
|
|
|
110
|
-
function checkContentTypeNames(contentTypes) {
|
|
111
|
-
const items = Object.entries(contentTypes).map(entry => ({
|
|
112
|
-
path: ['contentType', entry[0], 'name'],
|
|
113
|
-
value: entry[1].name.toLowerCase()
|
|
114
|
-
}));
|
|
115
|
-
return findDuplicates(items).flatMap(dupe => dupe.paths.map(path => ({
|
|
116
|
-
path,
|
|
117
|
-
type: 'conflict',
|
|
118
|
-
message: `Content types must have unique names. "${dupe.value}" is not unique.`
|
|
119
|
-
})));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
100
|
function checkShapeIds(shapes) {
|
|
123
101
|
const items = Object.entries(shapes).map(entry => ({
|
|
124
102
|
path: ['shapes', entry[0], 'id'],
|
|
@@ -183,25 +161,7 @@ function validateWorkflowVersion(projectSchema) {
|
|
|
183
161
|
return errors;
|
|
184
162
|
}
|
|
185
163
|
|
|
186
|
-
function
|
|
187
|
-
const errors = validateWorkflowVersion(projectSchema);
|
|
188
|
-
|
|
189
|
-
for (const key of Object.keys(projectSchema.contentTypes)) {
|
|
190
|
-
const contentType = projectSchema.contentTypes[key];
|
|
191
|
-
|
|
192
|
-
if (contentType.workflow && contentType.workflow !== _workflows.defaultWorkflow.name && !projectSchema.workflows[contentType.workflow]) {
|
|
193
|
-
errors.push({
|
|
194
|
-
type: 'notFound',
|
|
195
|
-
path: ['contentTypes', key, 'workflow'],
|
|
196
|
-
message: `Invalid Workflow "${contentType.workflow}" for content type "${contentType.name}"`
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return errors;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function validateWorkflowsV3(projectSchema) {
|
|
164
|
+
function validateWorkflows(projectSchema) {
|
|
205
165
|
const errors = validateWorkflowVersion(projectSchema);
|
|
206
166
|
|
|
207
167
|
for (const name of Object.keys(projectSchema.shapes)) {
|
|
@@ -243,43 +203,21 @@ function enumerateBasicResolvers(resolver, path) {
|
|
|
243
203
|
|
|
244
204
|
function validateResolver(projectSchema, basePath, baseResolver) {
|
|
245
205
|
const errors = [];
|
|
246
|
-
/**
|
|
247
|
-
* V3.9 Resolver name enums are the set used for earlier v3 validations
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
const {
|
|
251
|
-
definitions: {
|
|
252
|
-
takeshapeResolver,
|
|
253
|
-
utilResolver,
|
|
254
|
-
graphqlResolver,
|
|
255
|
-
restResolver,
|
|
256
|
-
awsLambdaResolver
|
|
257
|
-
}
|
|
258
|
-
} = _metaSchemaV.default;
|
|
259
|
-
|
|
260
|
-
const isValidResolverNameV3_9_0 = resolverName => {
|
|
261
|
-
return [takeshapeResolver, utilResolver, graphqlResolver, restResolver, awsLambdaResolver].flatMap(resolver => resolver.properties.name.enum).includes(resolverName);
|
|
262
|
-
};
|
|
263
206
|
|
|
264
207
|
const isValidShapeName = shapeName => {
|
|
265
|
-
var
|
|
208
|
+
var _shape$cache;
|
|
266
209
|
|
|
267
210
|
if (!shapeName) {
|
|
268
211
|
return false;
|
|
269
212
|
}
|
|
270
213
|
|
|
271
|
-
const shape = projectSchema
|
|
214
|
+
const shape = (0, _schemaUtil.getShape)(projectSchema, shapeName);
|
|
272
215
|
|
|
273
216
|
if (shape !== null && shape !== void 0 && shape.model) {
|
|
274
217
|
return true;
|
|
275
218
|
}
|
|
276
219
|
|
|
277
|
-
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const modernShape = shape;
|
|
282
|
-
return Boolean((modernShape === null || modernShape === void 0 ? void 0 : (_modernShape$cache = modernShape.cache) === null || _modernShape$cache === void 0 ? void 0 : _modernShape$cache.enabled) && modernShape.loaders);
|
|
220
|
+
return Boolean((shape === null || shape === void 0 ? void 0 : (_shape$cache = shape.cache) === null || _shape$cache === void 0 ? void 0 : _shape$cache.enabled) && shape.loaders);
|
|
283
221
|
};
|
|
284
222
|
|
|
285
223
|
const delegateResolverMissingConfig = (parsed, resolver) => {
|
|
@@ -296,23 +234,13 @@ function validateResolver(projectSchema, basePath, baseResolver) {
|
|
|
296
234
|
}
|
|
297
235
|
};
|
|
298
236
|
|
|
299
|
-
const isLessThanV3_9_0 = (0, _lt.default)(getSemver(projectSchema.schemaVersion), '3.9.0');
|
|
300
|
-
const isLessThanV3_31_0 = (0, _lt.default)(getSemver(projectSchema.schemaVersion), '3.31.0');
|
|
301
237
|
const getNamespace = (0, _refs.createGetNamespace)(projectSchema);
|
|
302
238
|
|
|
303
239
|
for (const [resolver, path] of enumerateBasicResolvers(baseResolver, basePath)) {
|
|
304
240
|
if ((0, _utils.isBasicResolver)(resolver)) {
|
|
305
|
-
var _projectSchema$servic
|
|
306
|
-
|
|
307
|
-
if (isLessThanV3_31_0 && 'service' in resolver && resolver.service !== 'takeshape:local' && !((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[resolver.service])) {
|
|
308
|
-
errors.push({
|
|
309
|
-
type: 'notFound',
|
|
310
|
-
path: path.concat(['service']),
|
|
311
|
-
message: `Invalid service "${resolver.service}"`
|
|
312
|
-
});
|
|
313
|
-
}
|
|
241
|
+
var _projectSchema$servic;
|
|
314
242
|
|
|
315
|
-
if (
|
|
243
|
+
if ('service' in resolver && resolver.service !== 'shapedb' && resolver.service !== 'takeshape' && !((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[resolver.service])) {
|
|
316
244
|
errors.push({
|
|
317
245
|
type: 'notFound',
|
|
318
246
|
path: path.concat(['service']),
|
|
@@ -320,32 +248,6 @@ function validateResolver(projectSchema, basePath, baseResolver) {
|
|
|
320
248
|
});
|
|
321
249
|
}
|
|
322
250
|
|
|
323
|
-
if (isLessThanV3_9_0 && !isValidResolverNameV3_9_0(resolver.name)) {
|
|
324
|
-
errors.push({
|
|
325
|
-
type: 'notFound',
|
|
326
|
-
path: path.concat(['name']),
|
|
327
|
-
message: `Invalid resolver name "${resolver.name}"`
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (isLessThanV3_9_0 && resolver.name.startsWith('takeshape')) {
|
|
332
|
-
var _options;
|
|
333
|
-
|
|
334
|
-
if ((_options = resolver.options) !== null && _options !== void 0 && _options.model) {
|
|
335
|
-
var _options2;
|
|
336
|
-
|
|
337
|
-
const shapeName = (_options2 = resolver.options) === null || _options2 === void 0 ? void 0 : _options2.model;
|
|
338
|
-
|
|
339
|
-
if (!isValidShapeName(shapeName)) {
|
|
340
|
-
errors.push({
|
|
341
|
-
type: 'notFound',
|
|
342
|
-
path: path.concat(['options', 'model']),
|
|
343
|
-
message: `Invalid Model Shape "${shapeName ?? ''}"`
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
251
|
if (resolver.shapeName) {
|
|
350
252
|
const {
|
|
351
253
|
shapeName
|
|
@@ -497,7 +399,7 @@ function listShapeJoins(projectSchema) {
|
|
|
497
399
|
for (const shapeKey of Object.keys(projectSchema.shapes)) {
|
|
498
400
|
const shape = projectSchema.shapes[shapeKey];
|
|
499
401
|
|
|
500
|
-
if (
|
|
402
|
+
if (shape.joins) {
|
|
501
403
|
for (const joinRef of Object.keys(shape.joins)) {
|
|
502
404
|
const join = shape.joins[joinRef];
|
|
503
405
|
joins.push({
|
|
@@ -563,34 +465,12 @@ async function validateShapeJoins(context, projectSchema) {
|
|
|
563
465
|
return (0, _lodash.flatten)(await Promise.all(promises));
|
|
564
466
|
}
|
|
565
467
|
|
|
566
|
-
function validateIndexedShapeConfig(projectSchema, shapeName, config) {
|
|
567
|
-
var _config$queries;
|
|
568
|
-
|
|
569
|
-
const errors = [];
|
|
570
|
-
|
|
571
|
-
if ((_config$queries = config.queries) !== null && _config$queries !== void 0 && _config$queries.list) {
|
|
572
|
-
(0, _util.ensureArray)(config.queries.list).forEach((list, i) => {
|
|
573
|
-
if (projectSchema.queries[list.name] === undefined) {
|
|
574
|
-
errors.push({
|
|
575
|
-
path: Array.isArray(config.queries.list) ? ['indexedShapes', shapeName, 'queries', 'list', i, 'name'] : ['indexedShapes', shapeName, 'queries', 'list', 'name'],
|
|
576
|
-
type: 'notFound',
|
|
577
|
-
message: `Invalid query "${list.name}"`
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
return errors;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
468
|
function validateShapeLoaders(projectSchema, shape) {
|
|
587
469
|
const errors = [];
|
|
588
470
|
|
|
589
|
-
if (
|
|
590
|
-
var _loaders, _loaders2;
|
|
591
|
-
|
|
471
|
+
if (shape.loaders) {
|
|
592
472
|
const getNamespace = (0, _refs.createGetNamespace)(projectSchema);
|
|
593
|
-
const listLoader =
|
|
473
|
+
const listLoader = shape.loaders.list;
|
|
594
474
|
|
|
595
475
|
if (listLoader) {
|
|
596
476
|
(0, _util.ensureArray)(listLoader).forEach((config, i) => {
|
|
@@ -607,7 +487,7 @@ function validateShapeLoaders(projectSchema, shape) {
|
|
|
607
487
|
});
|
|
608
488
|
}
|
|
609
489
|
|
|
610
|
-
const getLoader =
|
|
490
|
+
const getLoader = shape.loaders.get;
|
|
611
491
|
|
|
612
492
|
if (getLoader) {
|
|
613
493
|
const ref = (0, _refs.parsePropertyRef)(getLoader.query);
|
|
@@ -636,71 +516,50 @@ function visitProperties(projectSchema, callback) {
|
|
|
636
516
|
|
|
637
517
|
function validateIndexedShapes(projectSchema) {
|
|
638
518
|
const errors = [];
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const {
|
|
643
|
-
indexedShapes
|
|
644
|
-
} = projectSchema;
|
|
645
|
-
|
|
646
|
-
if (indexedShapes) {
|
|
647
|
-
(0, _forOwn.default)(indexedShapes, (config, shapeName) => {
|
|
648
|
-
errors.push(...validateIndexedShapeConfig(projectSchema, shapeName, config));
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
} else if ((0, _gt.default)(version, '3.31.0')) {
|
|
652
|
-
const {
|
|
653
|
-
shapes
|
|
654
|
-
} = projectSchema;
|
|
519
|
+
const {
|
|
520
|
+
shapes
|
|
521
|
+
} = projectSchema;
|
|
655
522
|
|
|
656
|
-
|
|
657
|
-
|
|
523
|
+
for (const shape of Object.values(shapes)) {
|
|
524
|
+
const newErrors = validateShapeLoaders(projectSchema, shape);
|
|
658
525
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
526
|
+
if (newErrors.length) {
|
|
527
|
+
errors.push(...newErrors);
|
|
662
528
|
}
|
|
663
529
|
}
|
|
664
530
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
const indexed = property['@indexed'];
|
|
531
|
+
let nestedCount = 0;
|
|
532
|
+
visitProperties(projectSchema, (property, propertyPath) => {
|
|
533
|
+
const indexed = property['@indexed'];
|
|
669
534
|
|
|
670
|
-
|
|
671
|
-
|
|
535
|
+
if ((0, _util.isRecord)(indexed) && indexed.nested) {
|
|
536
|
+
nestedCount += 1;
|
|
672
537
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
}
|
|
538
|
+
if (property.type !== 'array') {
|
|
539
|
+
errors.push({
|
|
540
|
+
path: propertyPath,
|
|
541
|
+
type: 'location',
|
|
542
|
+
message: 'Nested indexes may only appear next to fields of type: "array"'
|
|
543
|
+
});
|
|
680
544
|
}
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
if (nestedCount > 50) {
|
|
684
|
-
errors.push({
|
|
685
|
-
path: ['shapes'],
|
|
686
|
-
type: 'tooMany',
|
|
687
|
-
message: `${nestedCount} nested indexes found`
|
|
688
|
-
});
|
|
689
545
|
}
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
if (nestedCount > 50) {
|
|
549
|
+
errors.push({
|
|
550
|
+
path: ['shapes'],
|
|
551
|
+
type: 'tooMany',
|
|
552
|
+
message: `${nestedCount} nested indexes found`
|
|
553
|
+
});
|
|
690
554
|
}
|
|
691
555
|
|
|
692
556
|
return errors;
|
|
693
557
|
}
|
|
694
|
-
|
|
695
|
-
function getModelShapeIds(shapes) {
|
|
696
|
-
return Object.values(shapes).filter(shape => shape.model).map(shape => shape.id);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
const builtInModelShapeIds = getModelShapeIds(_builtinSchema.builtInShapes);
|
|
700
558
|
/**
|
|
701
559
|
* Verify the path has an allOf schema and not just prop named "allOf"
|
|
702
560
|
*/
|
|
703
561
|
|
|
562
|
+
|
|
704
563
|
function isAllOfPath(path) {
|
|
705
564
|
const index = path.indexOf('allOf');
|
|
706
565
|
return index !== -1 && (0, _util.isIntegerLike)(path[index + 1]);
|
|
@@ -817,31 +676,9 @@ function visitShapePropertiesJson(projectSchema, callback) {
|
|
|
817
676
|
}, undefined);
|
|
818
677
|
}
|
|
819
678
|
|
|
820
|
-
function validateDirectives(projectSchema
|
|
679
|
+
function validateDirectives(projectSchema) {
|
|
821
680
|
const errors = [];
|
|
822
|
-
const projectShapeIds = new Set([...getModelShapeIds(projectSchema.shapes), ...additionalShapeIds]);
|
|
823
|
-
const isLessThanV3_18_0 = (0, _lt.default)(getSemver(projectSchema.schemaVersion), '3.18.0');
|
|
824
681
|
visitShapePropertiesJson(projectSchema, (property, propertyPath) => {
|
|
825
|
-
if (isLessThanV3_18_0) {
|
|
826
|
-
const propSchema = property;
|
|
827
|
-
|
|
828
|
-
if (propSchema['@relationship']) {
|
|
829
|
-
var _propSchema$Relation;
|
|
830
|
-
|
|
831
|
-
const shapeIds = (_propSchema$Relation = propSchema['@relationship']) === null || _propSchema$Relation === void 0 ? void 0 : _propSchema$Relation.shapeIds;
|
|
832
|
-
shapeIds.forEach(shapeId => {
|
|
833
|
-
if (!projectShapeIds.has(shapeId)) {
|
|
834
|
-
const propPath = propertyPath.concat('@relationship');
|
|
835
|
-
errors.push({
|
|
836
|
-
type: 'notFound',
|
|
837
|
-
path: propPath,
|
|
838
|
-
message: `Invalid shapeId relationship "${shapeId}" for property "${propPath[4]}" in shape "${propPath[1]}"`
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
682
|
const resolver = property['@resolver'];
|
|
846
683
|
|
|
847
684
|
if (resolver) {
|
|
@@ -978,10 +815,6 @@ function validateShapeImplementsInterface(projectSchema, shape, interfaceShapeNa
|
|
|
978
815
|
}
|
|
979
816
|
|
|
980
817
|
function validateInterfaceImplementations(projectSchema) {
|
|
981
|
-
if (!(0, _gte.default)(getSemver(projectSchema.schemaVersion), '3.21.0')) {
|
|
982
|
-
return [];
|
|
983
|
-
}
|
|
984
|
-
|
|
985
818
|
const errors = [];
|
|
986
819
|
|
|
987
820
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
@@ -1011,10 +844,6 @@ function validateInterfaceImplementations(projectSchema) {
|
|
|
1011
844
|
}
|
|
1012
845
|
|
|
1013
846
|
function validateInterfaces(projectSchema) {
|
|
1014
|
-
if (!(0, _gte.default)(getSemver(projectSchema.schemaVersion), '3.21.0')) {
|
|
1015
|
-
return [];
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
847
|
const errors = []; // Validate interface shapes must be an object schema with at least one property
|
|
1019
848
|
|
|
1020
849
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
@@ -1139,53 +968,15 @@ function formatValidationResult(context, errors, schema) {
|
|
|
1139
968
|
};
|
|
1140
969
|
}
|
|
1141
970
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
let errors = [];
|
|
1148
|
-
errors = errors.concat(checkContentTypeNames(schemaV1.contentTypes)).concat(validateWorkflowsV1(schemaV1)).concat(checkWorkflowStepNames(schemaV1.workflows)).concat(checkWorkflowStepKeys(schemaV1.workflows));
|
|
1149
|
-
return formatValidationResult(context, errors, schemaV1);
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
}, {
|
|
1153
|
-
range: '^3.0.0',
|
|
1154
|
-
|
|
1155
|
-
validateSyntax(schemaVersion, context, obj) {
|
|
1156
|
-
const schema = obj;
|
|
1157
|
-
let errors = [];
|
|
1158
|
-
errors = errors.concat(checkShapeNames(schema.shapes)).concat(checkShapeIds(schema.shapes)).concat(validateWorkflowsV3(schema)).concat(validateLocalQueryConfigs(schema)).concat(validateLocalRefs(schema)).concat(validateLocalShapeJoins(schema)).concat(validateDirectives(schema)).concat(validateLocales(schema)).concat(checkWorkflowStepNames(schema.workflows)).concat(checkWorkflowStepKeys(schema.workflows)).concat(validateOneOfs(schema)).concat(validateIndexedShapes(schema)).concat(validateInterfaces(schema)).concat(validateInterfaceImplementations(schema));
|
|
1159
|
-
return formatValidationResult(context, errors, schema);
|
|
1160
|
-
},
|
|
1161
|
-
|
|
1162
|
-
async validateReferences(schemaVersion, context, obj) {
|
|
1163
|
-
const schema = obj;
|
|
1164
|
-
const errors = (0, _lodash.flatten)(await Promise.all([validateRefs(context, schema), validateQueryConfigs(context, schema), validateShapeJoins(context, schema)]));
|
|
1165
|
-
return formatValidationResult(context, errors, schema);
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
}];
|
|
1169
|
-
|
|
1170
|
-
function findValidator(schemaVersion) {
|
|
1171
|
-
const schemaSemVer = (0, _coerce2.default)(schemaVersion);
|
|
1172
|
-
|
|
1173
|
-
if (schemaSemVer) {
|
|
1174
|
-
const validator = validators.find(v => (0, _satisfies.default)(schemaSemVer, v.range));
|
|
971
|
+
function validateSyntax(context, schema) {
|
|
972
|
+
let errors = [];
|
|
973
|
+
errors = errors.concat(checkShapeNames(schema.shapes)).concat(checkShapeIds(schema.shapes)).concat(validateWorkflows(schema)).concat(validateLocalQueryConfigs(schema)).concat(validateLocalRefs(schema)).concat(validateLocalShapeJoins(schema)).concat(validateDirectives(schema)).concat(validateLocales(schema)).concat(checkWorkflowStepNames(schema.workflows)).concat(checkWorkflowStepKeys(schema.workflows)).concat(validateOneOfs(schema)).concat(validateIndexedShapes(schema)).concat(validateInterfaces(schema)).concat(validateInterfaceImplementations(schema));
|
|
974
|
+
return formatValidationResult(context, errors, schema);
|
|
975
|
+
}
|
|
1175
976
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
validateReferences
|
|
1180
|
-
} = validator;
|
|
1181
|
-
return {
|
|
1182
|
-
validateSyntax: validateSyntax.bind(null, schemaVersion),
|
|
1183
|
-
...(validateReferences ? {
|
|
1184
|
-
validateReferences: validateReferences.bind(null, schemaVersion)
|
|
1185
|
-
} : {})
|
|
1186
|
-
};
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
977
|
+
async function validateReferences(context, schema) {
|
|
978
|
+
const errors = (0, _lodash.flatten)(await Promise.all([validateRefs(context, schema), validateQueryConfigs(context, schema), validateShapeJoins(context, schema)]));
|
|
979
|
+
return formatValidationResult(context, errors, schema);
|
|
1189
980
|
}
|
|
1190
981
|
|
|
1191
982
|
const schemaUndefinedResult = {
|
|
@@ -1207,8 +998,10 @@ const invalidVersionResult = {
|
|
|
1207
998
|
}]
|
|
1208
999
|
};
|
|
1209
1000
|
|
|
1210
|
-
function normalizeSchemaVersion(
|
|
1211
|
-
|
|
1001
|
+
function normalizeSchemaVersion(obj) {
|
|
1002
|
+
if ((0, _util.isRecord)(obj)) {
|
|
1003
|
+
return typeof obj.schemaVersion === 'string' ? obj.schemaVersion : '1';
|
|
1004
|
+
}
|
|
1212
1005
|
}
|
|
1213
1006
|
|
|
1214
1007
|
function validateSchemaSyntax(obj, options = {}) {
|
|
@@ -1216,21 +1009,13 @@ function validateSchemaSyntax(obj, options = {}) {
|
|
|
1216
1009
|
return schemaUndefinedResult;
|
|
1217
1010
|
}
|
|
1218
1011
|
|
|
1219
|
-
const
|
|
1220
|
-
const schemaVersion = normalizeSchemaVersion(schema);
|
|
1221
|
-
const validator = findValidator(schemaVersion);
|
|
1012
|
+
const schemaVersion = normalizeSchemaVersion(obj);
|
|
1222
1013
|
|
|
1223
|
-
if (!
|
|
1014
|
+
if (!schemaVersion) {
|
|
1224
1015
|
return invalidVersionResult;
|
|
1225
1016
|
}
|
|
1226
1017
|
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
if (!structuralValidation.valid) {
|
|
1230
|
-
return structuralValidation;
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
return validator.validateSyntax(options, schema);
|
|
1018
|
+
return validateStructure(schemaVersion, options, obj);
|
|
1234
1019
|
}
|
|
1235
1020
|
/**
|
|
1236
1021
|
* Validates a schema using a matching validation based on the `schemaVersion` property.
|
|
@@ -1246,11 +1031,9 @@ async function validateSchema(context, obj) {
|
|
|
1246
1031
|
allowDisconnectedLayers: true,
|
|
1247
1032
|
...context
|
|
1248
1033
|
};
|
|
1249
|
-
const
|
|
1250
|
-
const schemaVersion = normalizeSchemaVersion(schema);
|
|
1251
|
-
const validator = findValidator(schemaVersion);
|
|
1034
|
+
const schemaVersion = normalizeSchemaVersion(obj);
|
|
1252
1035
|
|
|
1253
|
-
if (!
|
|
1036
|
+
if (!schemaVersion) {
|
|
1254
1037
|
return invalidVersionResult;
|
|
1255
1038
|
}
|
|
1256
1039
|
|
|
@@ -1260,13 +1043,21 @@ async function validateSchema(context, obj) {
|
|
|
1260
1043
|
return structuralValidation;
|
|
1261
1044
|
}
|
|
1262
1045
|
|
|
1263
|
-
const
|
|
1046
|
+
const {
|
|
1047
|
+
schema
|
|
1048
|
+
} = structuralValidation;
|
|
1049
|
+
|
|
1050
|
+
if (!(0, _projectSchema.isLatestProjectSchemaJSON)(schema)) {
|
|
1051
|
+
return invalidVersionResult;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
const syntaxValidation = validateSyntax(contextWithDefaults, schema);
|
|
1264
1055
|
|
|
1265
|
-
if (!syntaxValidation.valid || !
|
|
1056
|
+
if (!syntaxValidation.valid || !isValidateReferencesContext(contextWithDefaults)) {
|
|
1266
1057
|
return syntaxValidation;
|
|
1267
1058
|
}
|
|
1268
1059
|
|
|
1269
|
-
return
|
|
1060
|
+
return validateReferences(contextWithDefaults, schema);
|
|
1270
1061
|
}
|
|
1271
1062
|
|
|
1272
1063
|
function ensureValidLatestSchemaSyntax(obj) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { shapeNameToRef } from '../../refs';
|
|
2
|
-
import { createShape } from '../../schema-util';
|
|
3
2
|
|
|
4
3
|
function migrateListQuery(listConfig) {
|
|
5
4
|
const {
|
|
@@ -67,11 +66,16 @@ const migrate = async (_, projectSchema) => {
|
|
|
67
66
|
let shape = updatedShapes[name];
|
|
68
67
|
|
|
69
68
|
if (!shape) {
|
|
70
|
-
shape =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
shape = {
|
|
70
|
+
name,
|
|
71
|
+
id: name,
|
|
72
|
+
title: name,
|
|
73
|
+
schema: {
|
|
74
|
+
extends: [{
|
|
75
|
+
'@ref': shapeNameToRef(projectSchema, name)
|
|
76
|
+
}]
|
|
77
|
+
}
|
|
78
|
+
};
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
const loaders = queriesToLoaders(config.queries);
|
package/es/refs.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getRefType, isAllOfSchema, isExtendsSchema, isObjectSchema, isOneOfSche
|
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import assign from 'lodash/fp/assign';
|
|
5
5
|
import omit from 'lodash/fp/omit';
|
|
6
|
-
import {
|
|
6
|
+
import { getServiceNamespaces } from './services';
|
|
7
7
|
import { mergeObjectSchemas } from './util/merge';
|
|
8
8
|
import { resolveSchema } from 'ajv/dist/compile';
|
|
9
9
|
import isString from 'lodash/isString';
|
|
@@ -202,7 +202,7 @@ export function atRefToRefItem(context, atRef, template) {
|
|
|
202
202
|
// no service config.
|
|
203
203
|
|
|
204
204
|
const serviceConfig = (_context$services = context.services) === null || _context$services === void 0 ? void 0 : _context$services[serviceKey];
|
|
205
|
-
const serviceNamespace = serviceConfig
|
|
205
|
+
const serviceNamespace = serviceConfig === null || serviceConfig === void 0 ? void 0 : serviceConfig.namespace;
|
|
206
206
|
return {
|
|
207
207
|
typeName,
|
|
208
208
|
serviceKey,
|
|
@@ -525,10 +525,9 @@ export function dereferenceObjectSchema(context, shapeOrFieldSchema, schemaPath
|
|
|
525
525
|
}
|
|
526
526
|
export function createGetNamespace(context) {
|
|
527
527
|
return serviceId => {
|
|
528
|
-
var _context$services2;
|
|
528
|
+
var _context$services2, _context$services2$se;
|
|
529
529
|
|
|
530
|
-
|
|
531
|
-
return service && getServiceNamespace(service);
|
|
530
|
+
return (_context$services2 = context.services) === null || _context$services2 === void 0 ? void 0 : (_context$services2$se = _context$services2[serviceId]) === null || _context$services2$se === void 0 ? void 0 : _context$services2$se.namespace;
|
|
532
531
|
};
|
|
533
532
|
}
|
|
534
533
|
export function parsePropertyRef(refStr) {
|
package/es/schema-util.js
CHANGED
|
@@ -693,7 +693,7 @@ function addRef(refs, ref, predicate) {
|
|
|
693
693
|
}
|
|
694
694
|
}
|
|
695
695
|
/**
|
|
696
|
-
* Walk through a `
|
|
696
|
+
* Walk through a `ProjectSchemaJSON` and collect all the `ref`s.
|
|
697
697
|
*/
|
|
698
698
|
|
|
699
699
|
|
|
@@ -787,7 +787,7 @@ export function getAllRefsInQueries(projectSchema, rootPropertyName, predicate)
|
|
|
787
787
|
return refItems;
|
|
788
788
|
}
|
|
789
789
|
/**
|
|
790
|
-
* Get all refs in a
|
|
790
|
+
* Get all refs in a ProjectSchemaJSON
|
|
791
791
|
* @param predicate return true to include the ref in
|
|
792
792
|
*/
|
|
793
793
|
|
package/es/services.js
CHANGED
|
@@ -123,22 +123,6 @@ export function getStoredServiceConfig(projectSchema, serviceKey) {
|
|
|
123
123
|
|
|
124
124
|
return (_projectSchema$servic = projectSchema.services) === null || _projectSchema$servic === void 0 ? void 0 : _projectSchema$servic[serviceKey];
|
|
125
125
|
}
|
|
126
|
-
export function getServiceNamespace(serviceConfig) {
|
|
127
|
-
var _serviceConfig$params;
|
|
128
|
-
|
|
129
|
-
if ('namespace' in serviceConfig && serviceConfig.namespace) {
|
|
130
|
-
return serviceConfig.namespace;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* TODO This is only necessary if this fn gets called on a schema before migration.
|
|
134
|
-
* Figure that out and remove if possible.
|
|
135
|
-
**/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if ('params' in serviceConfig && (_serviceConfig$params = serviceConfig.params) !== null && _serviceConfig$params !== void 0 && _serviceConfig$params.namespace) {
|
|
139
|
-
return serviceConfig.params.namespace;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
126
|
/**
|
|
143
127
|
* Get a `Map` keyed with all the service namespaces.
|
|
144
128
|
*
|
|
@@ -155,7 +139,9 @@ export function getServiceNamespaces(context) {
|
|
|
155
139
|
|
|
156
140
|
if (services) {
|
|
157
141
|
Object.keys(services).forEach(serviceKey => {
|
|
158
|
-
|
|
142
|
+
var _services$serviceKey;
|
|
143
|
+
|
|
144
|
+
const namespace = (_services$serviceKey = services[serviceKey]) === null || _services$serviceKey === void 0 ? void 0 : _services$serviceKey.namespace;
|
|
159
145
|
|
|
160
146
|
if (namespace) {
|
|
161
147
|
namespaces.set(namespace, serviceKey);
|
package/es/types/types.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An alias for the latest version of the project schema. This should be the
|
|
3
|
-
* only type used in most runtime code. Updating this to a new version should
|
|
4
|
-
* trigger type errors that clue you in to code that needs review.
|
|
5
|
-
*/
|
|
6
1
|
export const projectSchemaImportOptionalProps = ['projectId', 'locales', 'defaultLocale', 'author'];
|
|
7
2
|
export const legacyProjectSchemaImportOptionalProps = ['created', 'updated', 'version', 'dataKey'];
|
|
8
3
|
|