@takeshape/schema 8.66.2 → 8.68.4

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.
Files changed (113) hide show
  1. package/es/content-schema-transform.js +2 -2
  2. package/es/index.js +2 -1
  3. package/es/migration/index.js +13 -2
  4. package/es/migration/to/v3.14.0.js +10 -0
  5. package/es/migration/to/v3.15.0.js +10 -0
  6. package/es/project-schema/index.js +2 -0
  7. package/es/project-schema/v3.13.1.js +1 -0
  8. package/es/project-schema/v3.14.0.js +1 -0
  9. package/es/project-schema/v3.15.0.js +1 -0
  10. package/es/refs.js +78 -1
  11. package/es/rewrite.js +58 -0
  12. package/es/schema-util.js +32 -118
  13. package/es/schemas/index.js +5 -3
  14. package/es/schemas/index.ts +6 -2
  15. package/es/schemas/project-schema/v3.14.0.json +2379 -0
  16. package/es/schemas/project-schema/v3.15.0.json +2359 -0
  17. package/es/schemas/project-schema.json +2 -1
  18. package/es/template-shapes/templates.js +56 -52
  19. package/es/template-shapes/types.js +8 -1
  20. package/es/types/utils.js +5 -0
  21. package/es/util/detect-cycles.js +2 -2
  22. package/es/util/index.js +2 -1
  23. package/es/util/merge.js +36 -0
  24. package/es/validate.js +2 -10
  25. package/examples/latest/betzino.json +1 -1
  26. package/examples/latest/blog-schema.json +1 -1
  27. package/examples/latest/brewery-schema.json +1 -1
  28. package/examples/latest/complex-project-schema.json +1 -1
  29. package/examples/latest/fabric-ecommerce.json +1 -1
  30. package/examples/latest/frank-and-fred-schema.json +1 -1
  31. package/examples/latest/massive-schema.json +1 -1
  32. package/examples/latest/mill-components-schema.json +1 -1
  33. package/examples/latest/pet-oneof-array.json +1 -1
  34. package/examples/latest/post-schema.json +1 -1
  35. package/examples/latest/pruned-shopify-product-schema.json +1 -1
  36. package/examples/latest/real-world-schema.json +1 -1
  37. package/examples/latest/recursive-repeater-schema.json +1 -1
  38. package/examples/latest/recursive-schema.json +1 -1
  39. package/examples/latest/rick-and-morty-ast.json +1 -1
  40. package/examples/latest/rick-and-morty-graphql.json +1 -1
  41. package/examples/latest/rick-and-morty-rest.json +1 -1
  42. package/examples/latest/schema-with-repeater-draftjs.json +1 -1
  43. package/examples/latest/shape-books-v3_2_0.json +1 -1
  44. package/examples/latest/shape-books.json +1 -1
  45. package/examples/latest/shopify-lookbook.json +1 -1
  46. package/examples/latest/shopify-store-with-widget.json +1 -1
  47. package/examples/latest/stripe-starter-resolved.json +1 -1
  48. package/examples/latest/user-schema-no-required.json +1 -1
  49. package/examples/latest/user-schema-with-defaults.json +1 -1
  50. package/lib/content-schema-transform.js +6 -6
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.d.ts.map +1 -1
  53. package/lib/index.js +14 -0
  54. package/lib/migration/index.d.ts.map +1 -1
  55. package/lib/migration/index.js +14 -1
  56. package/lib/migration/to/v3.14.0.d.ts +4 -0
  57. package/lib/migration/to/v3.14.0.d.ts.map +1 -0
  58. package/lib/migration/to/v3.14.0.js +18 -0
  59. package/lib/migration/to/v3.15.0.d.ts +4 -0
  60. package/lib/migration/to/v3.15.0.d.ts.map +1 -0
  61. package/lib/migration/to/v3.15.0.js +18 -0
  62. package/lib/project-schema/index.d.ts +5 -1
  63. package/lib/project-schema/index.d.ts.map +1 -1
  64. package/lib/project-schema/index.js +45 -19
  65. package/lib/project-schema/latest.d.ts +164 -23
  66. package/lib/project-schema/latest.d.ts.map +1 -1
  67. package/lib/project-schema/v3.13.1.d.ts +1413 -0
  68. package/lib/project-schema/v3.13.1.d.ts.map +1 -0
  69. package/lib/project-schema/v3.13.1.js +5 -0
  70. package/lib/project-schema/v3.14.0.d.ts +1437 -0
  71. package/lib/project-schema/v3.14.0.d.ts.map +1 -0
  72. package/lib/project-schema/v3.14.0.js +5 -0
  73. package/lib/project-schema/v3.15.0.d.ts +1459 -0
  74. package/lib/project-schema/v3.15.0.d.ts.map +1 -0
  75. package/lib/project-schema/v3.15.0.js +5 -0
  76. package/lib/refs.d.ts +11 -2
  77. package/lib/refs.d.ts.map +1 -1
  78. package/lib/refs.js +83 -0
  79. package/lib/rewrite.d.ts +10 -0
  80. package/lib/rewrite.d.ts.map +1 -0
  81. package/lib/rewrite.js +69 -0
  82. package/lib/schema-util.d.ts +3 -15
  83. package/lib/schema-util.d.ts.map +1 -1
  84. package/lib/schema-util.js +36 -135
  85. package/lib/schemas/index.d.ts +2302 -2
  86. package/lib/schemas/index.d.ts.map +1 -1
  87. package/lib/schemas/index.js +25 -21
  88. package/lib/schemas/index.ts +6 -2
  89. package/lib/schemas/project-schema/v3.14.0.json +2379 -0
  90. package/lib/schemas/project-schema/v3.15.0.json +2359 -0
  91. package/lib/schemas/project-schema.json +2 -1
  92. package/lib/template-shapes/templates.d.ts +11 -4
  93. package/lib/template-shapes/templates.d.ts.map +1 -1
  94. package/lib/template-shapes/templates.js +63 -57
  95. package/lib/template-shapes/types.d.ts +6 -0
  96. package/lib/template-shapes/types.d.ts.map +1 -1
  97. package/lib/template-shapes/types.js +11 -1
  98. package/lib/types/types.d.ts +2 -2
  99. package/lib/types/types.d.ts.map +1 -1
  100. package/lib/types/utils.d.ts +4 -1
  101. package/lib/types/utils.d.ts.map +1 -1
  102. package/lib/types/utils.js +10 -1
  103. package/lib/util/detect-cycles.d.ts +1 -1
  104. package/lib/util/detect-cycles.js +2 -2
  105. package/lib/util/index.d.ts +1 -0
  106. package/lib/util/index.d.ts.map +1 -1
  107. package/lib/util/index.js +13 -0
  108. package/lib/util/merge.d.ts +5 -0
  109. package/lib/util/merge.d.ts.map +1 -0
  110. package/lib/util/merge.js +51 -0
  111. package/lib/validate.d.ts.map +1 -1
  112. package/lib/validate.js +3 -10
  113. package/package.json +4 -4
@@ -10,8 +10,6 @@ exports.arraySchemaKeys = void 0;
10
10
  exports.collectReferencedShapeNames = collectReferencedShapeNames;
11
11
  exports.createSchemaPropertyList = exports.createSchemaPropertyAccessor = exports.commonSchemaKeys = void 0;
12
12
  exports.createShape = createShape;
13
- exports.dereferenceObjectSchema = dereferenceObjectSchema;
14
- exports.dereferenceSchema = dereferenceSchema;
15
13
  exports.emptySchema = emptySchema;
16
14
  exports.ensureQuery = exports.ensureMutation = void 0;
17
15
  exports.filterGraphQLServiceMap = filterGraphQLServiceMap;
@@ -51,8 +49,6 @@ exports.isBuiltinShape = isBuiltinShape;
51
49
  exports.isBuiltinType = isBuiltinType;
52
50
  exports.isIndexedRemoteShape = void 0;
53
51
  exports.isModelShape = isModelShape;
54
- exports.mergeFormProperties = mergeFormProperties;
55
- exports.mergeSchemaProperties = mergeSchemaProperties;
56
52
  exports.objectSchemaKeys = exports.nonStructuralSchemaKeys = exports.multipleRelationshipSchemaKeys = void 0;
57
53
  exports.parseMapping = parseMapping;
58
54
  exports.parseQueryResolver = parseQueryResolver;
@@ -72,20 +68,12 @@ var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
72
68
 
73
69
  var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
74
70
 
75
- var _omit = _interopRequireDefault(require("lodash/fp/omit"));
76
-
77
- var _assign = _interopRequireDefault(require("lodash/fp/assign"));
78
-
79
71
  var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
80
72
 
81
73
  var _get = _interopRequireDefault(require("lodash/get"));
82
74
 
83
- var _union = _interopRequireDefault(require("lodash/union"));
84
-
85
75
  var _keyBy = _interopRequireDefault(require("lodash/keyBy"));
86
76
 
87
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
88
-
89
77
  var _isObject = _interopRequireDefault(require("lodash/isObject"));
90
78
 
91
79
  var _curry = _interopRequireDefault(require("lodash/fp/curry"));
@@ -114,6 +102,8 @@ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
114
102
 
115
103
  var _unions = require("./unions");
116
104
 
105
+ var _merge = require("./util/merge");
106
+
117
107
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
118
108
 
119
109
  const SERVICE_OBJECT_PATTERN_NAME = 'pattern:service-object';
@@ -423,7 +413,7 @@ exports.getBuiltInPropertyNames = getBuiltInPropertyNames;
423
413
  function applyBuiltinPropertiesToShape(projectSchema, shape) {
424
414
  return { ...shape,
425
415
  schema: { ...shape.schema,
426
- properties: { ...(0, _omitBy.default)(dereferenceObjectSchema(projectSchema, shape.schema).properties, (_, name) => name.startsWith('_')),
416
+ properties: { ...(0, _omitBy.default)((0, _refs.dereferenceObjectSchema)(projectSchema, shape.schema).properties, (_, name) => name.startsWith('_')),
427
417
  ...getBuiltInProperties(projectSchema.apiVersion),
428
418
  ...((0, _apiVersion.workflowsEnabled)(projectSchema.apiVersion) && {
429
419
  _status: (0, _workflows.getStatusField)(projectSchema.workflows, shape)
@@ -431,36 +421,6 @@ function applyBuiltinPropertiesToShape(projectSchema, shape) {
431
421
  }
432
422
  }
433
423
  };
434
- }
435
-
436
- function mergeSchemaProperties(base, overrides) {
437
- const result = { ...base,
438
- properties: { ...base.properties,
439
- ...overrides.properties
440
- }
441
- };
442
- const required = (0, _union.default)(base.required, overrides.required);
443
-
444
- if (required.length) {
445
- result.required = required;
446
- }
447
-
448
- return result;
449
- }
450
-
451
- function mergeFormProperties(base, overrides) {
452
- const result = { ...base,
453
- properties: { ...base.properties,
454
- ...overrides.properties
455
- }
456
- };
457
- const order = (0, _union.default)(base.order, overrides.order);
458
-
459
- if (order.length) {
460
- result.order = order;
461
- }
462
-
463
- return result;
464
424
  } // Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
465
425
 
466
426
 
@@ -506,7 +466,7 @@ function applyDefaultsToSchema(projectSchema) {
506
466
 
507
467
  if (builtInShape && builtInShape !== shape) {
508
468
  shape = { ...shape,
509
- schema: mergeSchemaProperties(dereferenceObjectSchema(projectSchema, shape.schema), dereferenceObjectSchema(projectSchema, builtInShape.schema))
469
+ schema: (0, _merge.mergeSchemaProperties)((0, _refs.dereferenceObjectSchema)(projectSchema, shape.schema), (0, _refs.dereferenceObjectSchema)(projectSchema, builtInShape.schema))
510
470
  };
511
471
  }
512
472
 
@@ -519,7 +479,7 @@ function applyDefaultsToSchema(projectSchema) {
519
479
 
520
480
  if (builtInFormsConfig && builtInFormsConfig !== formsConfig) {
521
481
  formsConfig = { ...formsConfig,
522
- default: mergeFormProperties(formsConfig.default, builtInFormsConfig.default)
482
+ default: (0, _merge.mergeFormProperties)(formsConfig.default, builtInFormsConfig.default)
523
483
  };
524
484
  }
525
485
 
@@ -681,12 +641,6 @@ function getArgsShapeSchema(context, argsSchema) {
681
641
  return args;
682
642
  }
683
643
  }
684
- /**
685
- * Helper fn to omit `allOf` props from the target schema, and then extend it with the source schema.
686
- */
687
-
688
-
689
- const omitAllOfAndExtend = (targetSchema, sourceSchema) => (0, _assign.default)((0, _omit.default)(['allOf'], targetSchema), sourceSchema);
690
644
 
691
645
  const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, useShapeIdDiscriminator = true) => {
692
646
  const rewriteRefs = (shape, addDiscriminator = false) => {
@@ -740,7 +694,7 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
740
694
  return shapeSchema;
741
695
  }
742
696
 
743
- const shapeSchemaCopy = dereferenceObjectSchema(projectSchema, shapeSchema);
697
+ const shapeSchemaCopy = (0, _refs.dereferenceObjectSchema)(projectSchema, shapeSchema);
744
698
 
745
699
  if (useShapeIdDiscriminator) {
746
700
  if (addDiscriminator && shapeSchemaCopy.properties) {
@@ -802,7 +756,7 @@ function getShapeDependencies(projectSchema, shape, predicate) {
802
756
 
803
757
  if (refShape && !shapeNames.has(refShape.name)) {
804
758
  shapeNames.add(refShape.name);
805
- findDependencies(dereferenceSchema(projectSchema, refShape.schema));
759
+ findDependencies((0, _refs.dereferenceSchema)(projectSchema, refShape.schema));
806
760
  }
807
761
  } else if ((0, _utils.isObjectSchema)(schema) || (0, _utils.isAllOfSchema)(schema) || (0, _utils.isOneOfSchema)(schema)) {
808
762
  visitSchemaProperties(schema, [], findDependencies);
@@ -844,34 +798,26 @@ function getRelevantShapes(projectSchema, params) {
844
798
  return {};
845
799
  }
846
800
 
847
- function visitSchemaProperties(schema, path, callback) {
848
- if ((0, _utils.isObjectSchema)(schema)) {
849
- for (const [name, propSchema] of Object.entries(schema.properties)) {
850
- const newPath = [...path, 'properties', name];
851
- callback(propSchema, newPath);
801
+ function visitSchemaPropertiesHelper(entries, path, callback) {
802
+ for (const [name, propSchema] of entries) {
803
+ const newPath = [...path, name];
804
+ callback(propSchema, newPath);
852
805
 
853
- if ((0, _utils.isObjectSchema)(propSchema) || (0, _utils.isAllOfSchema)(propSchema) || (0, _utils.isOneOfSchema)(propSchema)) {
854
- visitSchemaProperties(propSchema, newPath, callback);
855
- }
806
+ if ((0, _utils.isObjectSchema)(propSchema) || (0, _utils.isExtendsSchema)(propSchema) || (0, _utils.isAllOfSchema)(propSchema) || (0, _utils.isOneOfSchema)(propSchema)) {
807
+ visitSchemaProperties(propSchema, newPath, callback);
856
808
  }
857
- } else if ((0, _utils.isAllOfSchema)(schema)) {
858
- for (const [index, propSchema] of Object.entries(schema.allOf)) {
859
- const newPath = [...path, 'allOf', index];
860
- callback(propSchema, newPath);
809
+ }
810
+ }
861
811
 
862
- if ((0, _utils.isObjectSchema)(propSchema) || (0, _utils.isAllOfSchema)(propSchema) || (0, _utils.isOneOfSchema)(propSchema)) {
863
- visitSchemaProperties(propSchema, newPath, callback);
864
- }
865
- }
812
+ function visitSchemaProperties(schema, path, callback) {
813
+ if ((0, _utils.isObjectSchema)(schema)) {
814
+ visitSchemaPropertiesHelper(Object.entries(schema.properties), [...path, 'properties'], callback);
815
+ } else if ((0, _utils.isExtendsSchema)(schema)) {
816
+ visitSchemaPropertiesHelper(Object.entries(schema.extends), [...path, 'extends'], callback);
817
+ } else if ((0, _utils.isAllOfSchema)(schema)) {
818
+ visitSchemaPropertiesHelper(Object.entries(schema.allOf), [...path, 'allOf'], callback);
866
819
  } else if ((0, _utils.isOneOfSchema)(schema)) {
867
- for (const [index, propSchema] of Object.entries(schema.oneOf)) {
868
- const newPath = [...path, 'oneOf', index];
869
- callback(propSchema, newPath);
870
-
871
- if ((0, _utils.isObjectSchema)(propSchema) || (0, _utils.isAllOfSchema)(propSchema) || (0, _utils.isOneOfSchema)(propSchema)) {
872
- visitSchemaProperties(propSchema, newPath, callback);
873
- }
874
- }
820
+ visitSchemaPropertiesHelper(Object.entries(schema.oneOf), [...path, 'oneOf'], callback);
875
821
  } else {
876
822
  callback(schema, path);
877
823
  }
@@ -937,7 +883,7 @@ function getAllRefsInQuery(projectSchema, queryPath, query, predicate) {
937
883
  }
938
884
 
939
885
  if (query.args && typeof query.args === 'object') {
940
- visitSchemaProperties(dereferenceObjectSchema(projectSchema, query.args), queryPath, propertyVisitor);
886
+ visitSchemaProperties((0, _refs.dereferenceObjectSchema)(projectSchema, query.args), queryPath, propertyVisitor);
941
887
  }
942
888
 
943
889
  if (query.shape) {
@@ -1164,66 +1110,15 @@ function getProtectedSchema(schema) {
1164
1110
  })
1165
1111
  };
1166
1112
  }
1167
- /**
1168
- * Given a schema, will resolve any `allOf` or `ref` objects. This function has
1169
- * to fully resolve all refs, because attempting to extend an object schema with
1170
- * a ref property would create an invalid schema, potentially containing both
1171
- * a ref and properties.
1172
- *
1173
- * If it can't create a valid schema it returns the input.
1174
- */
1175
-
1176
-
1177
- function dereferenceSchema(context, shapeOrFieldSchema, schemaPath = []) {
1178
- const resolveAll = (resolveSchema, resolvePath) => {
1179
- try {
1180
- if ((0, _utils.isAllOfSchema)(resolveSchema)) {
1181
- const allOfSchema = resolveSchema.allOf.map((stub, index) => resolveAll(stub, [...resolvePath, 'allOf', index])).reduce((prev, curr) => (0, _util.mergeWithArrayConcat)(prev, curr), {});
1182
- return (0, _isEmpty.default)(allOfSchema) ? undefined : omitAllOfAndExtend(resolveSchema, allOfSchema);
1183
- }
1184
-
1185
- if ((0, _utils.isRefSchema)(resolveSchema)) {
1186
- const refItem = (0, _refs.getRefWithPath)(context, resolveSchema);
1187
-
1188
- if (!refItem) {
1189
- throw new Error('ref could not be parsed');
1190
- }
1191
-
1192
- const refSchema = (0, _refs.refItemToShapeSchema)(context, refItem);
1193
-
1194
- if (refSchema) {
1195
- return resolveAll((0, _refs.omitRefAndExtend)(resolveSchema, refSchema), refItem.path);
1196
- }
1197
-
1198
- return;
1199
- }
1200
-
1201
- return resolveSchema;
1202
- } catch (err) {
1203
- throw new Error(`error at '${resolvePath.join('.')}', ${err.message}`);
1204
- }
1205
- };
1206
-
1207
- return resolveAll(shapeOrFieldSchema, schemaPath) ?? shapeOrFieldSchema;
1208
- }
1209
-
1210
- function dereferenceObjectSchema(context, shapeOrFieldSchema, schemaPath = []) {
1211
- const schema = dereferenceSchema(context, shapeOrFieldSchema, schemaPath);
1212
-
1213
- if (!(0, _utils.isObjectSchema)(schema)) {
1214
- throw new Error(`provided schema at '${schemaPath.join('.')}' could not be resolved to an object schema`);
1215
- }
1216
-
1217
- return schema;
1218
- }
1219
1113
  /**
1220
1114
  * Creates a schema property list chainable fn, allowing you to manipulate and
1221
1115
  * iterate the properties in a schema.
1222
1116
  */
1223
1117
 
1224
1118
 
1225
- const createSchemaPropertyList = (0, _curry.default)((context, shapeOrFieldSchema) => {
1226
- const schema = dereferenceSchema(context, shapeOrFieldSchema);
1119
+ const createSchemaPropertyList = (0, _curry.default)((context, shapeOrSchema) => {
1120
+ const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
1121
+ const schema = (0, _refs.dereferenceSchema)(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
1227
1122
  const propertyIterator = new Map((0, _utils.isObjectSchema)(schema) ? Object.entries(schema.properties) : undefined);
1228
1123
  const defaultOrderByIteratees = [n => n[0]];
1229
1124
  const defaultOrderByOrders = ['asc'];
@@ -1293,14 +1188,20 @@ const createSchemaPropertyList = (0, _curry.default)((context, shapeOrFieldSchem
1293
1188
  };
1294
1189
  return self;
1295
1190
  });
1191
+ exports.createSchemaPropertyList = createSchemaPropertyList;
1192
+
1193
+ function isShape(shapeOrSchema) {
1194
+ return 'schema' in shapeOrSchema;
1195
+ }
1296
1196
  /**
1297
1197
  * Creates a schema property accessor, allowing you to safely access schema
1298
1198
  * properties.
1299
1199
  */
1300
1200
 
1301
- exports.createSchemaPropertyList = createSchemaPropertyList;
1302
- const createSchemaPropertyAccessor = (0, _curry.default)((context, shapeOrFieldSchema) => {
1303
- const schema = dereferenceSchema(context, shapeOrFieldSchema);
1201
+
1202
+ const createSchemaPropertyAccessor = (0, _curry.default)((context, shapeOrSchema) => {
1203
+ const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
1204
+ const schema = (0, _refs.dereferenceSchema)(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
1304
1205
  const propertyIterator = new Map((0, _utils.isObjectSchema)(schema) ? Object.entries(schema.properties) : undefined);
1305
1206
 
1306
1207
  const _getValue = propertyName => {