@takeshape/schema 8.67.0 → 8.68.7
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/es/content-schema-transform.js +2 -2
- package/es/layers/layers.js +2 -2
- package/es/layers/type-utils.js +4 -4
- package/es/migration/index.js +6 -1
- package/es/migration/to/v3.15.0.js +10 -0
- package/es/project-schema/index.js +1 -0
- package/es/project-schema/v3.15.0.js +1 -0
- package/es/refs.js +78 -1
- package/es/rewrite.js +4 -5
- package/es/schema-util.js +32 -118
- package/es/schemas/index.js +4 -3
- package/es/schemas/index.ts +4 -2
- package/es/schemas/project-schema/v3.15.0.json +2359 -0
- package/es/schemas/project-schema.json +1 -1
- package/es/template-shapes/templates.js +4 -11
- package/es/types/utils.js +12 -8
- package/es/unions.js +5 -5
- package/es/util/detect-cycles.js +2 -2
- package/es/util/index.js +2 -1
- package/es/util/merge.js +36 -0
- package/es/validate.js +2 -10
- package/examples/latest/betzino.json +1 -1
- package/examples/latest/blog-schema.json +1 -1
- package/examples/latest/brewery-schema.json +1 -1
- package/examples/latest/complex-project-schema.json +1 -1
- package/examples/latest/fabric-ecommerce.json +1 -1
- package/examples/latest/frank-and-fred-schema.json +1 -1
- package/examples/latest/massive-schema.json +1 -1
- package/examples/latest/mill-components-schema.json +1 -1
- package/examples/latest/pet-oneof-array.json +1 -1
- package/examples/latest/post-schema.json +1 -1
- package/examples/latest/pruned-shopify-product-schema.json +1 -1
- package/examples/latest/real-world-schema.json +1 -1
- package/examples/latest/recursive-repeater-schema.json +1 -1
- package/examples/latest/recursive-schema.json +1 -1
- package/examples/latest/rick-and-morty-ast.json +1 -1
- package/examples/latest/rick-and-morty-graphql.json +1 -1
- package/examples/latest/rick-and-morty-rest.json +1 -1
- package/examples/latest/schema-with-repeater-draftjs.json +1 -1
- package/examples/latest/shape-books-v3_2_0.json +1 -1
- package/examples/latest/shape-books.json +1 -1
- package/examples/latest/shopify-lookbook.json +1 -1
- package/examples/latest/shopify-store-with-widget.json +1 -1
- package/examples/latest/stripe-starter-resolved.json +1 -1
- package/examples/latest/user-schema-no-required.json +1 -1
- package/examples/latest/user-schema-with-defaults.json +1 -1
- package/lib/content-schema-transform.js +6 -6
- package/lib/layers/layers.js +1 -1
- package/lib/layers/type-utils.js +3 -3
- package/lib/migration/index.d.ts.map +1 -1
- package/lib/migration/index.js +6 -0
- package/lib/migration/to/v3.15.0.d.ts +4 -0
- package/lib/migration/to/v3.15.0.d.ts.map +1 -0
- package/lib/migration/to/v3.15.0.js +18 -0
- package/lib/project-schema/index.d.ts +3 -1
- package/lib/project-schema/index.d.ts.map +1 -1
- package/lib/project-schema/index.js +33 -20
- package/lib/project-schema/latest.d.ts +45 -23
- package/lib/project-schema/latest.d.ts.map +1 -1
- package/lib/project-schema/v3.15.0.d.ts +1459 -0
- package/lib/project-schema/v3.15.0.d.ts.map +1 -0
- package/lib/project-schema/v3.15.0.js +5 -0
- package/lib/refs.d.ts +11 -2
- package/lib/refs.d.ts.map +1 -1
- package/lib/refs.js +83 -0
- package/lib/rewrite.d.ts.map +1 -1
- package/lib/rewrite.js +5 -5
- package/lib/schema-util.d.ts +3 -15
- package/lib/schema-util.d.ts.map +1 -1
- package/lib/schema-util.js +36 -135
- package/lib/schemas/index.d.ts +2302 -2
- package/lib/schemas/index.d.ts.map +1 -1
- package/lib/schemas/index.js +24 -22
- package/lib/schemas/index.ts +4 -2
- package/lib/schemas/project-schema/v3.15.0.json +2359 -0
- package/lib/schemas/project-schema.json +1 -1
- package/lib/template-shapes/templates.d.ts.map +1 -1
- package/lib/template-shapes/templates.js +8 -13
- package/lib/types/types.d.ts +2 -2
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils.d.ts +3 -1
- package/lib/types/utils.d.ts.map +1 -1
- package/lib/types/utils.js +15 -8
- package/lib/unions.js +4 -4
- package/lib/util/detect-cycles.d.ts +1 -1
- package/lib/util/detect-cycles.js +2 -2
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +13 -0
- package/lib/util/merge.d.ts +5 -0
- package/lib/util/merge.d.ts.map +1 -0
- package/lib/util/merge.js +51 -0
- package/lib/validate.d.ts.map +1 -1
- package/lib/validate.js +3 -10
- package/package.json +4 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import forEach from 'lodash/forEach';
|
|
2
2
|
import difference from 'lodash/difference';
|
|
3
3
|
import pick from 'lodash/pick';
|
|
4
|
-
import { getKey
|
|
4
|
+
import { getKey } from './schema-util';
|
|
5
5
|
import { isArraySchema, isObjectSchema } from './types/utils';
|
|
6
|
-
import { getRefShapeName } from './refs';
|
|
6
|
+
import { getRefShapeName, dereferenceSchema } from './refs';
|
|
7
7
|
import { enumerateOneOfKeys, isUnionSchema } from './unions';
|
|
8
8
|
const typeCache = new WeakMap();
|
|
9
9
|
export function getType(schema) {
|
package/es/layers/layers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import minimatch from 'minimatch';
|
|
2
|
-
import { deepClone, isDefined,
|
|
2
|
+
import { deepClone, isDefined, isRecord } from '@takeshape/util';
|
|
3
3
|
import uniq from 'lodash/uniq';
|
|
4
4
|
import { getArgsReferenceWithPath, getRefOrItemsRef, dereferenceSchema, parseReturnShape, refItemToString, splitAtRef } from './refs';
|
|
5
5
|
import { isAllOfSchema, isObjectSchema, isOneOfSchema, isRefSchema } from './type-utils';
|
|
@@ -36,7 +36,7 @@ function filterLayer(layerSchema, filters) {
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
export function isObjectSchemaV4_0_0(maybeObjectSchema) {
|
|
39
|
-
return maybeObjectSchema.type === 'object' &&
|
|
39
|
+
return maybeObjectSchema.type === 'object' && isRecord(maybeObjectSchema.properties);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function mergeShape(a, b) {
|
package/es/layers/type-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isRecord } from '@takeshape/util';
|
|
2
2
|
import isPlainObject from 'lodash/isPlainObject';
|
|
3
3
|
import isString from 'lodash/isString';
|
|
4
4
|
import isArray from 'lodash/isArray';
|
|
@@ -60,7 +60,7 @@ export function isDirectiveMappingArray(maybeArray) {
|
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
62
|
export function isDirectiveConfig(maybeConfig) {
|
|
63
|
-
return isArray(maybeConfig) && isArray(maybeConfig[0]) && isString(maybeConfig[0][0]) &&
|
|
63
|
+
return isArray(maybeConfig) && isArray(maybeConfig[0]) && isString(maybeConfig[0][0]) && isRecord(maybeConfig[0][1]);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Determine whether a ParameterSerializeOption is a content type serializer
|
|
@@ -135,8 +135,8 @@ export function isOneOfSchema(schema) {
|
|
|
135
135
|
return isArray(schema.oneOf);
|
|
136
136
|
}
|
|
137
137
|
export function isArraySchema(schema) {
|
|
138
|
-
return schema.type === 'array' &&
|
|
138
|
+
return schema.type === 'array' && isRecord(schema.items);
|
|
139
139
|
}
|
|
140
140
|
export function isObjectSchema(schema) {
|
|
141
|
-
return schema.type === 'object' &&
|
|
141
|
+
return schema.type === 'object' && isRecord(schema.properties);
|
|
142
142
|
}
|
package/es/migration/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isLatestProjectSchema, isProjectSchemaV1, isProjectSchemaV3, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1, isProjectSchemaV3_6, isProjectSchemaV3_7, isProjectSchemaV3_8, isProjectSchemaV3_9, isProjectSchemaV3_10, isProjectSchemaV3_11, isProjectSchemaV3_12, isProjectSchemaV3_12_1, isProjectSchemaV3_12_2, isProjectSchemaV3_12_3, isProjectSchemaV3_13_0 } from '../types/utils';
|
|
1
|
+
import { isLatestProjectSchema, isProjectSchemaV1, isProjectSchemaV3, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1, isProjectSchemaV3_6, isProjectSchemaV3_7, isProjectSchemaV3_8, isProjectSchemaV3_9, isProjectSchemaV3_10, isProjectSchemaV3_11, isProjectSchemaV3_12, isProjectSchemaV3_12_1, isProjectSchemaV3_12_2, isProjectSchemaV3_12_3, isProjectSchemaV3_13_0, isProjectSchemaV3_14_0 } from '../types/utils';
|
|
2
2
|
import migrateToV3 from './to/v3.0.0';
|
|
3
3
|
import migrateToV3_1 from './to/v3.1.0';
|
|
4
4
|
import migrateToV3_2 from './to/v3.2.0';
|
|
@@ -18,6 +18,7 @@ import migrateToV3_12_2 from './to/v3.12.2';
|
|
|
18
18
|
import migrateToV3_12_3 from './to/v3.12.3';
|
|
19
19
|
import migrateToV3_13_0 from './to/v3.13.0';
|
|
20
20
|
import migrateToV3_14_0 from './to/v3.14.0';
|
|
21
|
+
import migrateToV3_15_0 from './to/v3.15.0';
|
|
21
22
|
export * from './utils';
|
|
22
23
|
export const listTypePrefix = 'PaginatedList'; // eslint-disable-next-line complexity
|
|
23
24
|
|
|
@@ -102,6 +103,10 @@ export async function migrateToLatestProjectSchema(context, projectSchema) {
|
|
|
102
103
|
projectSchema = migrateToV3_14_0(projectSchema);
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
if (isProjectSchemaV3_14_0(projectSchema)) {
|
|
107
|
+
projectSchema = migrateToV3_15_0(projectSchema);
|
|
108
|
+
}
|
|
109
|
+
|
|
105
110
|
return projectSchema;
|
|
106
111
|
}
|
|
107
112
|
export async function ensureLatest(context, schema) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/es/refs.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { getRefType, isAllOfSchema, isOneOfSchema, isRefSchema, isRefSchemaLegacy } from './types';
|
|
1
|
+
import { getRefType, isAllOfSchema, isExtendsSchema, isObjectSchema, isOneOfSchema, isRefSchema, isRefSchemaLegacy } from './types';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
3
|
import assign from 'lodash/fp/assign';
|
|
4
4
|
import omit from 'lodash/fp/omit';
|
|
5
5
|
import { getServiceNamespace, getServiceNamespaces } from './services';
|
|
6
|
+
import { mergeObjectSchemas } from './util/merge';
|
|
7
|
+
import { resolveSchema } from 'ajv/dist/compile';
|
|
8
|
+
import { isIntegerLike } from '@takeshape/util';
|
|
6
9
|
const templateShapeRegex = /^(\w+)<([\w:-]+)>$/;
|
|
7
10
|
/**
|
|
8
11
|
* Parse a template like `PaginatedList<Post>` and return both the template and the shape name.
|
|
@@ -370,4 +373,78 @@ export function hasResolvableRef(context, schema) {
|
|
|
370
373
|
}
|
|
371
374
|
|
|
372
375
|
return false;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function isSelfReferential(path, shapeName) {
|
|
379
|
+
if (path[0] !== 'shapes' || path[1] !== shapeName) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const index = path.findIndex(part => part === 'allOf' || part === 'extends');
|
|
384
|
+
return index !== -1 && isIntegerLike(path[index + 1]);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Given a schema, will resolve any `allOf` or `ref` objects. This function has
|
|
388
|
+
* to fully resolve all refs, because attempting to extend an object schema with
|
|
389
|
+
* a ref property would create an invalid schema, potentially containing both
|
|
390
|
+
* a ref and properties.
|
|
391
|
+
*
|
|
392
|
+
* If it can't create a valid schema it returns the input.
|
|
393
|
+
*/
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
export function dereferenceSchema(context, shapeOrFieldSchema, schemaPath = []) {
|
|
397
|
+
const resolveAll = (resolveSchema, resolvePath) => {
|
|
398
|
+
try {
|
|
399
|
+
if (isAllOfSchema(resolveSchema)) {
|
|
400
|
+
return merge(resolveSchema.allOf, 'allOf', resolvePath);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (isExtendsSchema(resolveSchema)) {
|
|
404
|
+
return merge(resolveSchema.extends, 'extends', resolvePath);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (isRefSchema(resolveSchema)) {
|
|
408
|
+
const refItem = getRefWithPath(context, resolveSchema);
|
|
409
|
+
|
|
410
|
+
if (!refItem) {
|
|
411
|
+
throw new Error('ref could not be parsed');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const shape = refItemToShape(context, refItem);
|
|
415
|
+
|
|
416
|
+
if (shape && !isSelfReferential(resolvePath, shape.name)) {
|
|
417
|
+
return resolveAll(omitRefAndExtend(resolveSchema, shape.schema), refItem.path);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return resolveSchema;
|
|
424
|
+
} catch (err) {
|
|
425
|
+
throw new Error(`error at '${resolvePath.join('.')}', ${err.message}`);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
const merge = (schemas, propName, path) => {
|
|
430
|
+
const mergedSchema = schemas.map((schema, index) => {
|
|
431
|
+
const resolved = resolveAll(schema, [...path, propName, index]);
|
|
432
|
+
return resolved && isObjectSchema(resolved) ? resolved : undefined;
|
|
433
|
+
}).reduce((prev, curr) => mergeObjectSchemas(prev, curr), {
|
|
434
|
+
type: 'object',
|
|
435
|
+
properties: {}
|
|
436
|
+
});
|
|
437
|
+
return assign(omit(propName, resolveSchema), mergedSchema);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
return resolveAll(shapeOrFieldSchema, schemaPath) ?? shapeOrFieldSchema;
|
|
441
|
+
}
|
|
442
|
+
export function dereferenceObjectSchema(context, shapeOrFieldSchema, schemaPath = []) {
|
|
443
|
+
const schema = dereferenceSchema(context, shapeOrFieldSchema, schemaPath);
|
|
444
|
+
|
|
445
|
+
if (!isObjectSchema(schema)) {
|
|
446
|
+
throw new Error(`provided schema at '${schemaPath.join('.')}' could not be resolved to an object schema`);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return schema;
|
|
373
450
|
}
|
package/es/rewrite.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import defaults from 'lodash/fp/defaults';
|
|
2
|
+
import { isRecord } from '@takeshape/util';
|
|
2
3
|
const rewriteSchemaCache = new Map();
|
|
3
4
|
|
|
4
5
|
function getRewriteCache(options) {
|
|
@@ -32,11 +33,9 @@ export function rewriteSchema(schema, options) {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
|
|
35
|
-
if (
|
|
36
|
-
var _value$required;
|
|
37
|
-
|
|
36
|
+
if (isRecord(value)) {
|
|
38
37
|
// Remove required
|
|
39
|
-
if (options.removeRequired && (
|
|
38
|
+
if (options.removeRequired && Array.isArray(value.required) && value.required.length) {
|
|
40
39
|
delete value.required;
|
|
41
40
|
} // Remove default
|
|
42
41
|
|
|
@@ -45,7 +44,7 @@ export function rewriteSchema(schema, options) {
|
|
|
45
44
|
delete value.default;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
if (options.replaceInput && value['@input']) {
|
|
47
|
+
if (options.replaceInput && isRecord(value['@input'])) {
|
|
49
48
|
return { ...value['@input'],
|
|
50
49
|
'@mapping': value['@mapping']
|
|
51
50
|
};
|
package/es/schema-util.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import find from 'lodash/find';
|
|
2
2
|
import mapValues from 'lodash/mapValues';
|
|
3
3
|
import omitBy from 'lodash/omitBy';
|
|
4
|
-
import omit from 'lodash/fp/omit';
|
|
5
|
-
import assign from 'lodash/fp/assign';
|
|
6
4
|
import pickBy from 'lodash/pickBy';
|
|
7
5
|
import get from 'lodash/get';
|
|
8
|
-
import union from 'lodash/union';
|
|
9
6
|
import keyBy from 'lodash/keyBy';
|
|
10
|
-
import isEmpty from 'lodash/isEmpty';
|
|
11
7
|
import isObject from 'lodash/isObject';
|
|
12
8
|
import curry from 'lodash/fp/curry';
|
|
13
9
|
import orderBy from 'lodash/fp/orderBy';
|
|
14
10
|
import uniq from 'lodash/uniq';
|
|
15
|
-
import { deepClone, isDefined
|
|
11
|
+
import { deepClone, isDefined } from '@takeshape/util';
|
|
16
12
|
import { defaultWorkflow, getStatusField } from './workflows';
|
|
17
13
|
import { CURRENT_API_VERSION, CURRENT_SCHEMA_VERSION } from './versions';
|
|
18
14
|
import { workflowsEnabled } from './api-version';
|
|
19
15
|
import { builtInShapes, builtInForms } from './builtin-schema';
|
|
20
|
-
import { getArgsType, isBasicResolver, isObjectSchema, isAllOfSchema, isRefSchema, isOneOfSchema } from './types/utils';
|
|
16
|
+
import { getArgsType, isBasicResolver, isObjectSchema, isAllOfSchema, isRefSchema, isOneOfSchema, isExtendsSchema } from './types/utils';
|
|
21
17
|
import { getStoredServiceConfig } from './services';
|
|
22
|
-
import { createTemplateShapeName, followRef, getRef, getRefOrItemsRef, getRefShapeName,
|
|
18
|
+
import { createTemplateShapeName, dereferenceObjectSchema, dereferenceSchema, followRef, getRef, getRefOrItemsRef, getRefShapeName, parseReturnShape, refExpressionToRefItem, refItemToShape, refItemToShapeName, refItemToShapeSchema } from './refs';
|
|
23
19
|
import isEqual from 'lodash/isEqual';
|
|
24
20
|
import { isUnionSchema } from './unions';
|
|
21
|
+
import { mergeFormProperties, mergeSchemaProperties } from './util/merge';
|
|
25
22
|
export const SERVICE_OBJECT_PATTERN_NAME = 'pattern:service-object';
|
|
26
23
|
export function isBuiltinShape(shapeName) {
|
|
27
24
|
return Boolean(builtInShapes[shapeName]);
|
|
@@ -312,34 +309,6 @@ export function applyBuiltinPropertiesToShape(projectSchema, shape) {
|
|
|
312
309
|
}
|
|
313
310
|
}
|
|
314
311
|
};
|
|
315
|
-
}
|
|
316
|
-
export function mergeSchemaProperties(base, overrides) {
|
|
317
|
-
const result = { ...base,
|
|
318
|
-
properties: { ...base.properties,
|
|
319
|
-
...overrides.properties
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
const required = union(base.required, overrides.required);
|
|
323
|
-
|
|
324
|
-
if (required.length) {
|
|
325
|
-
result.required = required;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return result;
|
|
329
|
-
}
|
|
330
|
-
export function mergeFormProperties(base, overrides) {
|
|
331
|
-
const result = { ...base,
|
|
332
|
-
properties: { ...base.properties,
|
|
333
|
-
...overrides.properties
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
const order = union(base.order, overrides.order);
|
|
337
|
-
|
|
338
|
-
if (order.length) {
|
|
339
|
-
result.order = order;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
return result;
|
|
343
312
|
} // Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
|
|
344
313
|
|
|
345
314
|
const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TsStaticSite'];
|
|
@@ -548,11 +517,6 @@ export function getArgsShapeSchema(context, argsSchema) {
|
|
|
548
517
|
return args;
|
|
549
518
|
}
|
|
550
519
|
}
|
|
551
|
-
/**
|
|
552
|
-
* Helper fn to omit `allOf` props from the target schema, and then extend it with the source schema.
|
|
553
|
-
*/
|
|
554
|
-
|
|
555
|
-
const omitAllOfAndExtend = (targetSchema, sourceSchema) => assign(omit(['allOf'], targetSchema), sourceSchema);
|
|
556
520
|
|
|
557
521
|
const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, useShapeIdDiscriminator = true) => {
|
|
558
522
|
const rewriteRefs = (shape, addDiscriminator = false) => {
|
|
@@ -706,34 +670,27 @@ export function getRelevantShapes(projectSchema, params) {
|
|
|
706
670
|
|
|
707
671
|
return {};
|
|
708
672
|
}
|
|
709
|
-
export function visitSchemaProperties(schema, path, callback) {
|
|
710
|
-
if (isObjectSchema(schema)) {
|
|
711
|
-
for (const [name, propSchema] of Object.entries(schema.properties)) {
|
|
712
|
-
const newPath = [...path, 'properties', name];
|
|
713
|
-
callback(propSchema, newPath);
|
|
714
673
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
} else if (isAllOfSchema(schema)) {
|
|
720
|
-
for (const [index, propSchema] of Object.entries(schema.allOf)) {
|
|
721
|
-
const newPath = [...path, 'allOf', index];
|
|
722
|
-
callback(propSchema, newPath);
|
|
674
|
+
function visitSchemaPropertiesHelper(entries, path, callback) {
|
|
675
|
+
for (const [name, propSchema] of entries) {
|
|
676
|
+
const newPath = [...path, name];
|
|
677
|
+
callback(propSchema, newPath);
|
|
723
678
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
679
|
+
if (isObjectSchema(propSchema) || isExtendsSchema(propSchema) || isAllOfSchema(propSchema) || isOneOfSchema(propSchema)) {
|
|
680
|
+
visitSchemaProperties(propSchema, newPath, callback);
|
|
727
681
|
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
const newPath = [...path, 'oneOf', index];
|
|
731
|
-
callback(propSchema, newPath);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
732
684
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
685
|
+
export function visitSchemaProperties(schema, path, callback) {
|
|
686
|
+
if (isObjectSchema(schema)) {
|
|
687
|
+
visitSchemaPropertiesHelper(Object.entries(schema.properties), [...path, 'properties'], callback);
|
|
688
|
+
} else if (isExtendsSchema(schema)) {
|
|
689
|
+
visitSchemaPropertiesHelper(Object.entries(schema.extends), [...path, 'extends'], callback);
|
|
690
|
+
} else if (isAllOfSchema(schema)) {
|
|
691
|
+
visitSchemaPropertiesHelper(Object.entries(schema.allOf), [...path, 'allOf'], callback);
|
|
692
|
+
} else if (isOneOfSchema(schema)) {
|
|
693
|
+
visitSchemaPropertiesHelper(Object.entries(schema.oneOf), [...path, 'oneOf'], callback);
|
|
737
694
|
} else {
|
|
738
695
|
callback(schema, path);
|
|
739
696
|
}
|
|
@@ -1008,63 +965,14 @@ export function getProtectedSchema(schema) {
|
|
|
1008
965
|
})
|
|
1009
966
|
};
|
|
1010
967
|
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Given a schema, will resolve any `allOf` or `ref` objects. This function has
|
|
1013
|
-
* to fully resolve all refs, because attempting to extend an object schema with
|
|
1014
|
-
* a ref property would create an invalid schema, potentially containing both
|
|
1015
|
-
* a ref and properties.
|
|
1016
|
-
*
|
|
1017
|
-
* If it can't create a valid schema it returns the input.
|
|
1018
|
-
*/
|
|
1019
|
-
|
|
1020
|
-
export function dereferenceSchema(context, shapeOrFieldSchema, schemaPath = []) {
|
|
1021
|
-
const resolveAll = (resolveSchema, resolvePath) => {
|
|
1022
|
-
try {
|
|
1023
|
-
if (isAllOfSchema(resolveSchema)) {
|
|
1024
|
-
const allOfSchema = resolveSchema.allOf.map((stub, index) => resolveAll(stub, [...resolvePath, 'allOf', index])).reduce((prev, curr) => mergeWithArrayConcat(prev, curr), {});
|
|
1025
|
-
return isEmpty(allOfSchema) ? undefined : omitAllOfAndExtend(resolveSchema, allOfSchema);
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
if (isRefSchema(resolveSchema)) {
|
|
1029
|
-
const refItem = getRefWithPath(context, resolveSchema);
|
|
1030
|
-
|
|
1031
|
-
if (!refItem) {
|
|
1032
|
-
throw new Error('ref could not be parsed');
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
const refSchema = refItemToShapeSchema(context, refItem);
|
|
1036
|
-
|
|
1037
|
-
if (refSchema) {
|
|
1038
|
-
return resolveAll(omitRefAndExtend(resolveSchema, refSchema), refItem.path);
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
return;
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
return resolveSchema;
|
|
1045
|
-
} catch (err) {
|
|
1046
|
-
throw new Error(`error at '${resolvePath.join('.')}', ${err.message}`);
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
|
|
1050
|
-
return resolveAll(shapeOrFieldSchema, schemaPath) ?? shapeOrFieldSchema;
|
|
1051
|
-
}
|
|
1052
|
-
export function dereferenceObjectSchema(context, shapeOrFieldSchema, schemaPath = []) {
|
|
1053
|
-
const schema = dereferenceSchema(context, shapeOrFieldSchema, schemaPath);
|
|
1054
|
-
|
|
1055
|
-
if (!isObjectSchema(schema)) {
|
|
1056
|
-
throw new Error(`provided schema at '${schemaPath.join('.')}' could not be resolved to an object schema`);
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
return schema;
|
|
1060
|
-
}
|
|
1061
968
|
/**
|
|
1062
969
|
* Creates a schema property list chainable fn, allowing you to manipulate and
|
|
1063
970
|
* iterate the properties in a schema.
|
|
1064
971
|
*/
|
|
1065
972
|
|
|
1066
|
-
export const createSchemaPropertyList = curry((context,
|
|
1067
|
-
const
|
|
973
|
+
export const createSchemaPropertyList = curry((context, shapeOrSchema) => {
|
|
974
|
+
const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
|
|
975
|
+
const schema = dereferenceSchema(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
|
|
1068
976
|
const propertyIterator = new Map(isObjectSchema(schema) ? Object.entries(schema.properties) : undefined);
|
|
1069
977
|
const defaultOrderByIteratees = [n => n[0]];
|
|
1070
978
|
const defaultOrderByOrders = ['asc'];
|
|
@@ -1134,13 +1042,19 @@ export const createSchemaPropertyList = curry((context, shapeOrFieldSchema) => {
|
|
|
1134
1042
|
};
|
|
1135
1043
|
return self;
|
|
1136
1044
|
});
|
|
1045
|
+
|
|
1046
|
+
function isShape(shapeOrSchema) {
|
|
1047
|
+
return 'schema' in shapeOrSchema;
|
|
1048
|
+
}
|
|
1137
1049
|
/**
|
|
1138
1050
|
* Creates a schema property accessor, allowing you to safely access schema
|
|
1139
1051
|
* properties.
|
|
1140
1052
|
*/
|
|
1141
1053
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1054
|
+
|
|
1055
|
+
export const createSchemaPropertyAccessor = curry((context, shapeOrSchema) => {
|
|
1056
|
+
const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
|
|
1057
|
+
const schema = dereferenceSchema(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
|
|
1144
1058
|
const propertyIterator = new Map(isObjectSchema(schema) ? Object.entries(schema.properties) : undefined);
|
|
1145
1059
|
|
|
1146
1060
|
const _getValue = propertyName => {
|
package/es/schemas/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// This file is generated by "pnpm json2ts"
|
|
2
|
-
export const CURRENT_SCHEMA_VERSION = '3.
|
|
2
|
+
export const CURRENT_SCHEMA_VERSION = '3.15.0';
|
|
3
3
|
export { default as anyProjectSchema } from './project-schema.json';
|
|
4
|
-
export { default as latestSchemaJson } from './project-schema/v3.
|
|
4
|
+
export { default as latestSchemaJson } from './project-schema/v3.15.0.json';
|
|
5
5
|
import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
|
|
6
|
+
import projectSchemaV3_15_0 from './project-schema/v3.15.0.json';
|
|
6
7
|
import projectSchemaV3_14_0 from './project-schema/v3.14.0.json';
|
|
7
8
|
import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
|
|
8
9
|
import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
|
|
@@ -35,4 +36,4 @@ import projectSchemaV3_0_0 from './project-schema/v3.0.0.json';
|
|
|
35
36
|
import metaSchemaV3_0_0 from './project-schema/meta-schema-v3.0.0.json';
|
|
36
37
|
import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
|
|
37
38
|
import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
|
|
38
|
-
export const allProjectSchemas = [projectSchemaV4_0_0, projectSchemaV3_14_0, projectSchemaV3_13_0, projectSchemaV3_12_3, projectSchemaV3_12_2, projectSchemaV3_12_1, projectSchemaV3_12_0, projectSchemaV3_11_0, projectSchemaV3_10_0, projectSchemaV3_9_0, metaSchemaV3_9_0, projectSchemaV3_8_0, metaSchemaV3_8_0, projectSchemaV3_7_0, metaSchemaV3_7_0, projectSchemaV3_6_0, metaSchemaV3_6_0, projectSchemaV3_5_1, metaSchemaV3_5_1, projectSchemaV3_5_0, metaSchemaV3_5_0, projectSchemaV3_4_0, metaSchemaV3_4_0, projectSchemaV3_3_0, metaSchemaV3_3_0, projectSchemaV3_2_0, metaSchemaV3_2_0, projectSchemaV3_1_0, metaSchemaV3_1_0, projectSchemaV3_0_0, metaSchemaV3_0_0, projectSchemaV1_0_0, metaSchemaV1_0_0];
|
|
39
|
+
export const allProjectSchemas = [projectSchemaV4_0_0, projectSchemaV3_15_0, projectSchemaV3_14_0, projectSchemaV3_13_0, projectSchemaV3_12_3, projectSchemaV3_12_2, projectSchemaV3_12_1, projectSchemaV3_12_0, projectSchemaV3_11_0, projectSchemaV3_10_0, projectSchemaV3_9_0, metaSchemaV3_9_0, projectSchemaV3_8_0, metaSchemaV3_8_0, projectSchemaV3_7_0, metaSchemaV3_7_0, projectSchemaV3_6_0, metaSchemaV3_6_0, projectSchemaV3_5_1, metaSchemaV3_5_1, projectSchemaV3_5_0, metaSchemaV3_5_0, projectSchemaV3_4_0, metaSchemaV3_4_0, projectSchemaV3_3_0, metaSchemaV3_3_0, projectSchemaV3_2_0, metaSchemaV3_2_0, projectSchemaV3_1_0, metaSchemaV3_1_0, projectSchemaV3_0_0, metaSchemaV3_0_0, projectSchemaV1_0_0, metaSchemaV1_0_0];
|
package/es/schemas/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// This file is generated by "pnpm json2ts"
|
|
2
|
-
export const CURRENT_SCHEMA_VERSION = '3.
|
|
2
|
+
export const CURRENT_SCHEMA_VERSION = '3.15.0';
|
|
3
3
|
export {default as anyProjectSchema} from './project-schema.json';
|
|
4
|
-
export {default as latestSchemaJson} from './project-schema/v3.
|
|
4
|
+
export {default as latestSchemaJson} from './project-schema/v3.15.0.json';
|
|
5
5
|
import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
|
|
6
|
+
import projectSchemaV3_15_0 from './project-schema/v3.15.0.json';
|
|
6
7
|
import projectSchemaV3_14_0 from './project-schema/v3.14.0.json';
|
|
7
8
|
import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
|
|
8
9
|
import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
|
|
@@ -37,6 +38,7 @@ import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
|
|
|
37
38
|
import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
|
|
38
39
|
export const allProjectSchemas = [
|
|
39
40
|
projectSchemaV4_0_0,
|
|
41
|
+
projectSchemaV3_15_0,
|
|
40
42
|
projectSchemaV3_14_0,
|
|
41
43
|
projectSchemaV3_13_0,
|
|
42
44
|
projectSchemaV3_12_3,
|