@takeshape/schema 8.145.0 → 8.149.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.
Files changed (125) hide show
  1. package/dist/builtin-schema.d.ts.map +1 -1
  2. package/dist/builtin-schema.js +17 -0
  3. package/dist/get-is-leaf.d.ts +1 -1
  4. package/dist/get-is-leaf.d.ts.map +1 -1
  5. package/dist/get-is-leaf.js +3 -1
  6. package/dist/migration/index.d.ts +1 -0
  7. package/dist/migration/index.d.ts.map +1 -1
  8. package/dist/migration/index.js +4 -1
  9. package/dist/migration/to/v3.0.0.d.ts.map +1 -1
  10. package/dist/migration/to/v3.18.0.d.ts +5 -0
  11. package/dist/migration/to/v3.18.0.d.ts.map +1 -0
  12. package/dist/migration/to/v3.18.0.js +85 -0
  13. package/dist/mocks.d.ts.map +1 -1
  14. package/dist/mocks.js +4 -2
  15. package/dist/project-schema/index.d.ts +4 -1
  16. package/dist/project-schema/index.d.ts.map +1 -1
  17. package/dist/project-schema/index.js +20 -3
  18. package/dist/project-schema/latest.d.ts +4 -139
  19. package/dist/project-schema/latest.d.ts.map +1 -1
  20. package/dist/project-schema/migrate.d.ts.map +1 -1
  21. package/dist/project-schema/migrate.js +4 -0
  22. package/dist/project-schema/v3.18.0.d.ts +1334 -0
  23. package/dist/project-schema/v3.18.0.d.ts.map +1 -0
  24. package/dist/project-schema/v3.18.0.js +5 -0
  25. package/dist/refs.d.ts +14 -2
  26. package/dist/refs.d.ts.map +1 -1
  27. package/dist/refs.js +26 -0
  28. package/dist/relationships.d.ts +28 -2
  29. package/dist/relationships.d.ts.map +1 -1
  30. package/dist/relationships.js +234 -19
  31. package/dist/rewrite.d.ts.map +1 -1
  32. package/dist/rewrite.js +10 -2
  33. package/dist/schema-util.d.ts +1 -18
  34. package/dist/schema-util.d.ts.map +1 -1
  35. package/dist/schema-util.js +36 -120
  36. package/dist/schemas/index.d.ts +2 -2
  37. package/dist/schemas/index.d.ts.map +1 -1
  38. package/dist/schemas/index.js +6 -4
  39. package/dist/schemas/index.ts +4 -2
  40. package/dist/schemas/project-schema/latest.json +2175 -2195
  41. package/dist/schemas/project-schema/v3.18.0.json +2350 -0
  42. package/dist/schemas/project-schema.json +3 -0
  43. package/dist/template-shapes/templates.d.ts +5 -0
  44. package/dist/template-shapes/templates.d.ts.map +1 -1
  45. package/dist/template-shapes/templates.js +59 -28
  46. package/dist/template-shapes/where.d.ts +3 -4
  47. package/dist/template-shapes/where.d.ts.map +1 -1
  48. package/dist/template-shapes/where.js +32 -26
  49. package/dist/types/types.d.ts +42 -2
  50. package/dist/types/types.d.ts.map +1 -1
  51. package/dist/types/utils.d.ts +2 -0
  52. package/dist/types/utils.d.ts.map +1 -1
  53. package/dist/types/utils.js +9 -1
  54. package/dist/unions.d.ts.map +1 -1
  55. package/dist/unions.js +3 -1
  56. package/dist/util/detect-cycles.d.ts +3 -1
  57. package/dist/util/detect-cycles.d.ts.map +1 -1
  58. package/dist/util/detect-cycles.js +37 -28
  59. package/dist/util/form-config.d.ts +9 -0
  60. package/dist/util/form-config.d.ts.map +1 -0
  61. package/dist/util/form-config.js +97 -0
  62. package/dist/util/index.d.ts +1 -0
  63. package/dist/util/index.d.ts.map +1 -1
  64. package/dist/util/index.js +13 -0
  65. package/dist/validate.d.ts.map +1 -1
  66. package/dist/validate.js +75 -45
  67. package/es/builtin-schema.js +17 -0
  68. package/es/get-is-leaf.js +2 -1
  69. package/es/migration/index.js +3 -1
  70. package/es/migration/to/v3.18.0.js +72 -0
  71. package/es/mocks.js +4 -2
  72. package/es/project-schema/index.js +3 -1
  73. package/es/project-schema/migrate.js +5 -1
  74. package/es/project-schema/v3.18.0.js +1 -0
  75. package/es/refs.js +22 -1
  76. package/es/relationships.js +215 -19
  77. package/es/rewrite.js +10 -2
  78. package/es/schema-util.js +38 -119
  79. package/es/schemas/index.js +4 -3
  80. package/es/schemas/index.ts +4 -2
  81. package/es/schemas/project-schema/latest.json +2175 -2195
  82. package/es/schemas/project-schema/v3.18.0.json +2350 -0
  83. package/es/schemas/project-schema.json +3 -0
  84. package/es/template-shapes/templates.js +55 -29
  85. package/es/template-shapes/where.js +29 -23
  86. package/es/types/utils.js +8 -2
  87. package/es/unions.js +2 -1
  88. package/es/util/detect-cycles.js +36 -28
  89. package/es/util/form-config.js +85 -0
  90. package/es/util/index.js +2 -1
  91. package/es/validate.js +74 -46
  92. package/examples/latest/betzino.json +12383 -6066
  93. package/examples/latest/blog-schema.json +46 -25
  94. package/examples/latest/brewery-schema.json +14 -9
  95. package/examples/latest/complex-project-schema.json +442 -244
  96. package/examples/latest/complex-schema.json +17205 -0
  97. package/examples/latest/fabric-ecommerce.json +2 -2
  98. package/examples/latest/frank-and-fred-schema.json +5141 -2391
  99. package/examples/latest/klirr-schema.json +35445 -0
  100. package/examples/latest/massive-schema.json +1205 -640
  101. package/examples/latest/mill-components-schema.json +241 -113
  102. package/examples/latest/one-earth.json +14429 -0
  103. package/examples/latest/pet-oneof-array.json +2 -2
  104. package/examples/latest/post-schema.json +18 -11
  105. package/examples/latest/pruned-shopify-product-schema.json +2 -2
  106. package/examples/latest/real-world-schema.json +81 -41
  107. package/examples/latest/recursive-repeater-schema.json +14 -9
  108. package/examples/latest/recursive-schema.json +14 -9
  109. package/examples/latest/rick-and-morty-ast.json +138 -80
  110. package/examples/latest/rick-and-morty-graphql.json +78 -45
  111. package/examples/latest/rick-and-morty-rest.json +2 -2
  112. package/examples/latest/schema-with-repeater-draftjs.json +38 -23
  113. package/examples/latest/shape-books-v3_2_0.json +138 -80
  114. package/examples/latest/shape-books.json +138 -80
  115. package/examples/latest/shopify-lookbook.json +30 -16
  116. package/examples/latest/shopify-namespace-schema.json +364 -0
  117. package/examples/latest/shopify-store-with-widget.json +2 -2
  118. package/examples/latest/stripe-starter-resolved.json +14 -8
  119. package/examples/latest/user-schema-no-required.json +2 -2
  120. package/examples/latest/user-schema-with-defaults.json +2 -2
  121. package/examples/source/complex-schema.json +12760 -0
  122. package/examples/source/klirr-schema.json +27716 -0
  123. package/examples/source/one-earth.json +11897 -0
  124. package/examples/source/post-schema.json +0 -1
  125. package/package.json +5 -4
@@ -13,10 +13,8 @@ exports.createShape = createShape;
13
13
  exports.emptySchema = emptySchema;
14
14
  exports.ensureQuery = exports.ensureMutation = void 0;
15
15
  exports.filterGraphQLServiceMap = filterGraphQLServiceMap;
16
- exports.findExistingRelationships = findExistingRelationships;
17
16
  exports.findMapping = findMapping;
18
17
  exports.findQuery = exports.findMutation = void 0;
19
- exports.findShapeFormConfig = findShapeFormConfig;
20
18
  exports.getAllNamespaceShapes = getAllNamespaceShapes;
21
19
  exports.getAllRefs = getAllRefs;
22
20
  exports.getAllRefsInQueries = getAllRefsInQueries;
@@ -71,8 +69,6 @@ var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
71
69
 
72
70
  var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
73
71
 
74
- var _get = _interopRequireDefault(require("lodash/get"));
75
-
76
72
  var _keyBy = _interopRequireDefault(require("lodash/keyBy"));
77
73
 
78
74
  var _isObject = _interopRequireDefault(require("lodash/isObject"));
@@ -101,6 +97,8 @@ var _refs = require("./refs");
101
97
 
102
98
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
103
99
 
100
+ var _isString = _interopRequireDefault(require("lodash/isString"));
101
+
104
102
  var _unions = require("./unions");
105
103
 
106
104
  var _merge = require("./util/merge");
@@ -142,7 +140,7 @@ exports.arraySchemaKeys = arraySchemaKeys;
142
140
  const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems']; // All properties except properties, items, additionalItems
143
141
 
144
142
  exports.multipleRelationshipSchemaKeys = multipleRelationshipSchemaKeys;
145
- const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@relationship', '@backreference', 'required', 'maxItems', 'minItems', 'uniqueItems'];
143
+ const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@resolver', '@input', '@output', '@backreference', '@args', 'required', 'maxItems', 'minItems', 'uniqueItems'];
146
144
  exports.nonStructuralSchemaKeys = nonStructuralSchemaKeys;
147
145
 
148
146
  function getServiceIdFieldName(serviceFieldName) {
@@ -530,94 +528,6 @@ function applyDefaultsToSchema(projectSchema) {
530
528
  };
531
529
  }
532
530
 
533
- function addRelationship(relationships, id, env) {
534
- if (!relationships[id]) {
535
- relationships[id] = [];
536
- }
537
-
538
- relationships[id].push(env);
539
- }
540
- /**
541
- * Finds all relationships in the schema and returns an object indexed by shape.id that lists all of the shapes
542
- * properties that reference it
543
- */
544
-
545
-
546
- function findExistingRelationships(projectSchema, shapes) {
547
- const relationships = {};
548
- const shapeArray = Object.values(shapes);
549
- const shapesSeen = new Set();
550
- const shapeIds = new Set(shapeArray.map(shape => shape.id));
551
-
552
- const findRelationships = (schema, path, parentShapeName) => {
553
- if (schema['@relationship']) {
554
- var _schema$Backreferenc;
555
-
556
- const {
557
- shapeIds: relatedShapeIds
558
- } = schema['@relationship'];
559
- const relatedName = (_schema$Backreferenc = schema['@backreference']) === null || _schema$Backreferenc === void 0 ? void 0 : _schema$Backreferenc.name;
560
-
561
- for (const shapeId of relatedShapeIds) {
562
- if (shapeIds.has(shapeId)) {
563
- var _schema$Backreferenc2;
564
-
565
- addRelationship(relationships, shapeId, {
566
- relatedName,
567
- path: path.slice(1),
568
- shapeId: path[0],
569
- hasBackreference: Boolean((_schema$Backreferenc2 = schema['@backreference']) === null || _schema$Backreferenc2 === void 0 ? void 0 : _schema$Backreferenc2.enabled),
570
- schema,
571
- shapeName: parentShapeName
572
- });
573
- }
574
- }
575
- }
576
-
577
- const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
578
-
579
- if (shapeName && !shapes[shapeName]) {
580
- return;
581
- }
582
-
583
- const prop = shapeName ? (0, _refs.followRef)(projectSchema, schema) : schema;
584
-
585
- if (shapeName) {
586
- // Skip shapes we have already seen to avoid cycles
587
- if (shapesSeen.has(shapeName)) {
588
- return;
589
- }
590
-
591
- shapesSeen.add(shapeName);
592
- }
593
-
594
- if (prop.properties) {
595
- for (const name of Object.keys(prop.properties)) {
596
- findRelationships(prop.properties[name], path.concat(name), shapeName ?? parentShapeName);
597
- }
598
- } else if (prop.items) {
599
- findRelationships(prop.items, path, shapeName ?? parentShapeName);
600
- } else if ((0, _unions.isUnionSchema)(prop)) {
601
- for (const child of prop.oneOf) {
602
- findRelationships(child, path, shapeName ?? parentShapeName);
603
- }
604
- }
605
- };
606
-
607
- for (const shape of shapeArray) {
608
- if (isModelShape(shape)) {
609
- const {
610
- schema,
611
- id,
612
- name
613
- } = shape;
614
- findRelationships(schema, [id], name);
615
- }
616
- }
617
-
618
- return relationships;
619
- }
620
-
621
531
  function stringifyQuerySource(providerId, serviceId) {
622
532
  return `${providerId}:${serviceId}`;
623
533
  }
@@ -870,7 +780,9 @@ function visitSchemaPropertiesHelper(entries, path, callback) {
870
780
  }
871
781
 
872
782
  function visitSchemaProperties(schema, path, callback) {
873
- if ((0, _utils.isObjectSchema)(schema)) {
783
+ if ((0, _utils.isArraySchema)(schema)) {
784
+ visitSchemaPropertiesHelper(Object.entries(schema.items), [...path, 'items'], callback);
785
+ } else if ((0, _utils.isObjectSchema)(schema)) {
874
786
  visitSchemaPropertiesHelper(Object.entries(schema.properties), [...path, 'properties'], callback);
875
787
  } else if ((0, _utils.isExtendsSchema)(schema)) {
876
788
  visitSchemaPropertiesHelper(Object.entries(schema.extends), [...path, 'extends'], callback);
@@ -901,29 +813,41 @@ function addRef(refs, ref, predicate) {
901
813
 
902
814
  function getAllRefsInShapes(projectSchema, predicate) {
903
815
  const items = [];
904
-
905
- const shapeVisitor = (schema, schemaPath) => {
906
- if (schema['@args'] && typeof schema['@args'] === 'object') {
907
- visitSchemaProperties(schema['@args'], schemaPath.concat(['@args']), (argSchema, argPath) => {
908
- addRef(items, (0, _refs.getRefOrItemsRef)(projectSchema, argSchema, argPath), predicate);
909
- });
816
+ const refPropNames = ['$ref', '@ref', '@args', 'args'];
817
+ (0, _util.visit)(projectSchema.shapes, refPropNames, (ref, refPath) => {
818
+ // The client sometimes generates invalid schemas, like refs that are
819
+ // undefined. Treat ref as unknown and toss those out.
820
+ // See the `useShapeEditor > can deal with renames test`
821
+ if (!(0, _isString.default)(ref)) {
822
+ return;
910
823
  }
911
824
 
912
- addRef(items, getArgsReferenceWithPath(projectSchema, schema, schemaPath), predicate);
913
- const newPath = schema.items ? schemaPath.concat('items') : schemaPath;
914
- const newSchema = schema.items ?? schema;
825
+ const propName = refPath[refPath.length - 1];
826
+ const path = ['shapes', ...refPath];
827
+ let refItem = {};
915
828
 
916
- if ((0, _utils.isRefSchema)(newSchema)) {
917
- addRef(items, (0, _refs.getRefOrItemsRef)(projectSchema, newSchema, newPath), predicate);
918
- } else if ((0, _utils.isObjectSchema)(newSchema) || (0, _utils.isAllOfSchema)(newSchema) || (0, _utils.isOneOfSchema)(newSchema)) {
919
- visitSchemaProperties(newSchema, newPath, shapeVisitor);
829
+ if (propName === '@ref') {
830
+ const {
831
+ shapeName,
832
+ template
833
+ } = (0, _refs.parseTemplateShape)(ref);
834
+ refItem = { ...(0, _refs.atRefToRefItem)(projectSchema, shapeName, template),
835
+ path
836
+ };
837
+ } else if (propName === '$ref') {
838
+ refItem = { ...(0, _refs.refToRefItem)(projectSchema, ref),
839
+ path
840
+ };
841
+ } else if (propName === '@args' || propName === 'args') {
842
+ refItem = { ...(0, _refs.refExpressionToRefItem)(projectSchema, ref),
843
+ path
844
+ };
920
845
  }
921
- };
922
-
923
- for (const [shapeName, shape] of Object.entries(projectSchema.shapes)) {
924
- visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], shapeVisitor);
925
- }
926
846
 
847
+ if ((0, _refs.isRefItemWithPath)(refItem)) {
848
+ addRef(items, refItem, predicate);
849
+ }
850
+ });
927
851
  return items;
928
852
  }
929
853
  /**
@@ -1346,17 +1270,9 @@ const ensureQuery = (projectSchema, shapeName, resolver) => ensureQueryHelper(pr
1346
1270
  exports.ensureQuery = ensureQuery;
1347
1271
 
1348
1272
  const ensureMutation = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'mutation');
1349
- /**
1350
- * Find the form config for a given shape name and the form key.
1351
- */
1352
-
1353
1273
 
1354
1274
  exports.ensureMutation = ensureMutation;
1355
1275
 
1356
- function findShapeFormConfig(projectSchema, shapeName, formName) {
1357
- return (0, _get.default)(projectSchema, ['forms', shapeName, formName]);
1358
- }
1359
-
1360
1276
  /**
1361
1277
  * Find the query in the schema that corresponds to the given shape and resolver.
1362
1278
  */
@@ -1,5 +1,5 @@
1
- export declare const CURRENT_SCHEMA_VERSION = "3.17.1";
1
+ export declare const CURRENT_SCHEMA_VERSION = "3.18.0";
2
2
  export { default as anyProjectSchema } from './project-schema.json';
3
- export { default as latestSchemaJson } from './project-schema/v3.17.1.json';
3
+ export { default as latestSchemaJson } from './project-schema/v3.18.0.json';
4
4
  export declare const allProjectSchemas: any[];
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,sBAAsB,WAAW,CAAC;AAC/C,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAsC1E,eAAO,MAAM,iBAAiB,OAsC7B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schemas/index.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,sBAAsB,WAAW,CAAC;AAC/C,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAuC1E,eAAO,MAAM,iBAAiB,OAuC7B,CAAC"}
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "latestSchemaJson", {
19
19
 
20
20
  var _projectSchema = _interopRequireDefault(require("./project-schema.json"));
21
21
 
22
- var _v = _interopRequireDefault(require("./project-schema/v3.17.1.json"));
22
+ var _v = _interopRequireDefault(require("./project-schema/v3.18.0.json"));
23
23
 
24
24
  var _metaSchemaV = _interopRequireDefault(require("./project-schema/meta-schema-v1.0.0.json"));
25
25
 
@@ -91,12 +91,14 @@ var _v23 = _interopRequireDefault(require("./project-schema/v3.16.0.json"));
91
91
 
92
92
  var _v24 = _interopRequireDefault(require("./project-schema/v3.17.0.json"));
93
93
 
94
- var _v25 = _interopRequireDefault(require("./project-schema/v4.0.0.json"));
94
+ var _v25 = _interopRequireDefault(require("./project-schema/v3.17.1.json"));
95
+
96
+ var _v26 = _interopRequireDefault(require("./project-schema/v4.0.0.json"));
95
97
 
96
98
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
97
99
 
98
100
  // This file is generated by "pnpm json2ts"
99
- const CURRENT_SCHEMA_VERSION = '3.17.1';
101
+ const CURRENT_SCHEMA_VERSION = '3.18.0';
100
102
  exports.CURRENT_SCHEMA_VERSION = CURRENT_SCHEMA_VERSION;
101
- const allProjectSchemas = [_metaSchemaV.default, _v2.default, _metaSchemaV2.default, _v3.default, _metaSchemaV3.default, _v4.default, _metaSchemaV4.default, _v5.default, _metaSchemaV5.default, _v6.default, _metaSchemaV6.default, _v7.default, _metaSchemaV7.default, _v8.default, _metaSchemaV8.default, _v9.default, _metaSchemaV9.default, _v10.default, _metaSchemaV10.default, _v11.default, _metaSchemaV11.default, _v12.default, _metaSchemaV12.default, _v13.default, _v14.default, _v15.default, _v16.default, _v17.default, _v18.default, _v19.default, _v20.default, _v21.default, _v22.default, _v23.default, _v24.default, _v.default, _v25.default];
103
+ const allProjectSchemas = [_metaSchemaV.default, _v2.default, _metaSchemaV2.default, _v3.default, _metaSchemaV3.default, _v4.default, _metaSchemaV4.default, _v5.default, _metaSchemaV5.default, _v6.default, _metaSchemaV6.default, _v7.default, _metaSchemaV7.default, _v8.default, _metaSchemaV8.default, _v9.default, _metaSchemaV9.default, _v10.default, _metaSchemaV10.default, _v11.default, _metaSchemaV11.default, _v12.default, _metaSchemaV12.default, _v13.default, _v14.default, _v15.default, _v16.default, _v17.default, _v18.default, _v19.default, _v20.default, _v21.default, _v22.default, _v23.default, _v24.default, _v25.default, _v.default, _v26.default];
102
104
  exports.allProjectSchemas = allProjectSchemas;
@@ -1,7 +1,7 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.17.1';
2
+ export const CURRENT_SCHEMA_VERSION = '3.18.0';
3
3
  export {default as anyProjectSchema} from './project-schema.json';
4
- export {default as latestSchemaJson} from './project-schema/v3.17.1.json';
4
+ export {default as latestSchemaJson} from './project-schema/v3.18.0.json';
5
5
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
6
6
  import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
7
7
  import metaSchemaV3_0_0 from './project-schema/meta-schema-v3.0.0.json';
@@ -38,6 +38,7 @@ import projectSchemaV3_15_0 from './project-schema/v3.15.0.json';
38
38
  import projectSchemaV3_16_0 from './project-schema/v3.16.0.json';
39
39
  import projectSchemaV3_17_0 from './project-schema/v3.17.0.json';
40
40
  import projectSchemaV3_17_1 from './project-schema/v3.17.1.json';
41
+ import projectSchemaV3_18_0 from './project-schema/v3.18.0.json';
41
42
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
42
43
  export const allProjectSchemas = [
43
44
  metaSchemaV1_0_0,
@@ -76,5 +77,6 @@ export const allProjectSchemas = [
76
77
  projectSchemaV3_16_0,
77
78
  projectSchemaV3_17_0,
78
79
  projectSchemaV3_17_1,
80
+ projectSchemaV3_18_0,
79
81
  projectSchemaV4_0_0
80
82
  ];