@takeshape/schema 8.59.3 → 8.61.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 (91) hide show
  1. package/es/index.js +2 -1
  2. package/es/migration/index.js +11 -1
  3. package/es/migration/to/v3.0.0.js +19 -1
  4. package/es/migration/to/v3.12.3.js +81 -0
  5. package/es/migration/to/v3.13.0.js +21 -0
  6. package/es/migration/utils.js +0 -17
  7. package/es/project-schema/index.js +2 -0
  8. package/es/project-schema/v3.12.3.js +1 -0
  9. package/es/project-schema/v3.13.0.js +1 -0
  10. package/es/relationships.js +17 -0
  11. package/es/schema-util.js +9 -4
  12. package/es/schemas/index.js +5 -3
  13. package/es/schemas/index.ts +6 -2
  14. package/es/schemas/project-schema/v3.12.3.json +2358 -0
  15. package/es/schemas/project-schema/v3.13.0.json +2371 -0
  16. package/es/types/utils.js +7 -1
  17. package/es/validate.js +11 -14
  18. package/examples/latest/betzino.json +2325 -516
  19. package/examples/latest/blog-schema.json +14 -5
  20. package/examples/latest/brewery-schema.json +4 -1
  21. package/examples/latest/complex-project-schema.json +100 -1
  22. package/examples/latest/fabric-ecommerce.json +1 -1
  23. package/examples/latest/frank-and-fred-schema.json +673 -1
  24. package/examples/latest/massive-schema.json +272 -17
  25. package/examples/latest/mill-components-schema.json +43 -4
  26. package/examples/latest/pet-oneof-array.json +1 -1
  27. package/examples/latest/post-schema.json +6 -3
  28. package/examples/latest/pruned-shopify-product-schema.json +1 -1
  29. package/examples/latest/real-world-schema.json +18 -3
  30. package/examples/latest/recursive-repeater-schema.json +4 -1
  31. package/examples/latest/recursive-schema.json +4 -1
  32. package/examples/latest/rick-and-morty-ast.json +43 -10
  33. package/examples/latest/rick-and-morty-graphql.json +24 -6
  34. package/examples/latest/rick-and-morty-rest.json +1 -1
  35. package/examples/latest/schema-with-repeater-draftjs.json +10 -1
  36. package/examples/latest/shape-books-v3_2_0.json +40 -7
  37. package/examples/latest/shape-books.json +40 -7
  38. package/examples/latest/shopify-lookbook.json +11 -5
  39. package/examples/latest/shopify-store-with-widget.json +1 -1
  40. package/examples/latest/stripe-starter-resolved.json +5 -2
  41. package/examples/latest/user-schema-no-required.json +1 -1
  42. package/examples/latest/user-schema-with-defaults.json +1 -1
  43. package/lib/index.d.ts +1 -0
  44. package/lib/index.d.ts.map +1 -1
  45. package/lib/index.js +14 -0
  46. package/lib/migration/index.d.ts.map +1 -1
  47. package/lib/migration/index.js +12 -0
  48. package/lib/migration/to/v3.0.0.d.ts.map +1 -1
  49. package/lib/migration/to/v3.0.0.js +19 -1
  50. package/lib/migration/to/v3.12.3.d.ts +4 -0
  51. package/lib/migration/to/v3.12.3.d.ts.map +1 -0
  52. package/lib/migration/to/v3.12.3.js +91 -0
  53. package/lib/migration/to/v3.13.0.d.ts +4 -0
  54. package/lib/migration/to/v3.13.0.d.ts.map +1 -0
  55. package/lib/migration/to/v3.13.0.js +32 -0
  56. package/lib/migration/utils.d.ts +0 -2
  57. package/lib/migration/utils.d.ts.map +1 -1
  58. package/lib/migration/utils.js +0 -19
  59. package/lib/project-schema/index.d.ts +5 -1
  60. package/lib/project-schema/index.d.ts.map +1 -1
  61. package/lib/project-schema/index.js +43 -17
  62. package/lib/project-schema/latest.d.ts +50 -16
  63. package/lib/project-schema/latest.d.ts.map +1 -1
  64. package/lib/project-schema/v3.12.3.d.ts +1307 -0
  65. package/lib/project-schema/v3.12.3.d.ts.map +1 -0
  66. package/lib/project-schema/v3.12.3.js +5 -0
  67. package/lib/project-schema/v3.13.0.d.ts +1318 -0
  68. package/lib/project-schema/v3.13.0.d.ts.map +1 -0
  69. package/lib/project-schema/v3.13.0.js +5 -0
  70. package/lib/project-schema/v4.0.0.d.ts +69 -0
  71. package/lib/project-schema/v4.0.0.d.ts.map +1 -1
  72. package/lib/relationships.d.ts +3 -0
  73. package/lib/relationships.d.ts.map +1 -0
  74. package/lib/relationships.js +24 -0
  75. package/lib/schema-util.d.ts +1 -0
  76. package/lib/schema-util.d.ts.map +1 -1
  77. package/lib/schema-util.js +9 -4
  78. package/lib/schemas/index.d.ts +2 -2
  79. package/lib/schemas/index.d.ts.map +1 -1
  80. package/lib/schemas/index.js +23 -19
  81. package/lib/schemas/index.ts +6 -2
  82. package/lib/schemas/project-schema/v3.12.3.json +2358 -0
  83. package/lib/schemas/project-schema/v3.13.0.json +2371 -0
  84. package/lib/types/types.d.ts +2 -2
  85. package/lib/types/types.d.ts.map +1 -1
  86. package/lib/types/utils.d.ts +4 -1
  87. package/lib/types/utils.d.ts.map +1 -1
  88. package/lib/types/utils.js +13 -2
  89. package/lib/validate.d.ts.map +1 -1
  90. package/lib/validate.js +11 -14
  91. package/package.json +4 -4
package/es/index.js CHANGED
@@ -23,4 +23,5 @@ export * from './enum';
23
23
  export * from './patterns';
24
24
  export * from './types/types';
25
25
  export * from './types/utils';
26
- export * from './flatten-templates';
26
+ export * from './flatten-templates';
27
+ export * from './relationships';
@@ -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 } 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 } 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';
@@ -15,6 +15,8 @@ import migrateToV3_11_0 from './to/v3.11.0';
15
15
  import migrateToV3_12_0 from './to/v3.12.0';
16
16
  import migrateToV3_12_1 from './to/v3.12.1';
17
17
  import migrateToV3_12_2 from './to/v3.12.2';
18
+ import migrateToV3_12_3 from './to/v3.12.3';
19
+ import migrateToV3_13_0 from './to/v3.13.0';
18
20
  export * from './utils';
19
21
  export const listTypePrefix = 'PaginatedList';
20
22
  export async function migrateToLatestProjectSchema(context, projectSchema) {
@@ -86,6 +88,14 @@ export async function migrateToLatestProjectSchema(context, projectSchema) {
86
88
  projectSchema = migrateToV3_12_2(projectSchema);
87
89
  }
88
90
 
91
+ if (isProjectSchemaV3_12_2(projectSchema)) {
92
+ projectSchema = migrateToV3_12_3(projectSchema);
93
+ }
94
+
95
+ if (isProjectSchemaV3_12_3(projectSchema)) {
96
+ projectSchema = migrateToV3_13_0(projectSchema);
97
+ }
98
+
89
99
  return projectSchema;
90
100
  }
91
101
  export async function ensureLatest(context, schema) {
@@ -2,7 +2,7 @@ import forEach from 'lodash/forEach';
2
2
  import pick from 'lodash/pick';
3
3
  import { pascalCase, deepClone } from '@takeshape/util';
4
4
  import { arraySchemaKeys, getShapeQueriesAndMutations, multipleRelationshipSchemaKeys, objectSchemaKeys, scalarSchemaKeys, schemaMetadataKeys } from '../../schema-util';
5
- import { formatDate, getRelationshipSchema } from '../utils';
5
+ import { formatDate } from '../utils';
6
6
  const annotationMap = {
7
7
  l10n: '@l10n',
8
8
  sensitive: '@sensitive',
@@ -27,6 +27,24 @@ function getModelType(contentType) {
27
27
  }
28
28
 
29
29
  return 'multiple';
30
+ }
31
+
32
+ function getRelationshipSchema(relationship) {
33
+ const itemSchema = {
34
+ $ref: '#/shapes/TSRelationship/schema'
35
+ };
36
+
37
+ if (relationship.type === 'multiple') {
38
+ return {
39
+ type: 'array',
40
+ items: itemSchema,
41
+ '@relationship': relationship
42
+ };
43
+ }
44
+
45
+ return { ...itemSchema,
46
+ '@relationship': relationship
47
+ };
30
48
  } // eslint-disable-next-line complexity
31
49
 
32
50
 
@@ -0,0 +1,81 @@
1
+ import omit from 'lodash/omit';
2
+
3
+ function hasWebhook(projectSchema, config) {
4
+ var _config$queries, _config$queries$singl, _projectSchema$querie, _projectSchema$servic;
5
+
6
+ const queryName = (_config$queries = config.queries) === null || _config$queries === void 0 ? void 0 : (_config$queries$singl = _config$queries.single) === null || _config$queries$singl === void 0 ? void 0 : _config$queries$singl.name;
7
+
8
+ if (!queryName) {
9
+ return false;
10
+ }
11
+
12
+ const resolver = projectSchema === null || projectSchema === void 0 ? void 0 : (_projectSchema$querie = projectSchema.queries[queryName]) === null || _projectSchema$querie === void 0 ? void 0 : _projectSchema$querie.resolver;
13
+ return resolver && 'service' in resolver && (projectSchema === null || projectSchema === void 0 ? void 0 : (_projectSchema$servic = projectSchema.services) === null || _projectSchema$servic === void 0 ? void 0 : _projectSchema$servic[resolver.service].provider) === 'shopify';
14
+ }
15
+
16
+ function migrateToV3_12_3({
17
+ indexedShapes: oldIndexedShapes,
18
+ ...projectSchema
19
+ }) {
20
+ if (!oldIndexedShapes) {
21
+ return { ...projectSchema,
22
+ schemaVersion: '3.12.3'
23
+ };
24
+ }
25
+
26
+ const indexedShapes = Object.fromEntries(Object.entries(oldIndexedShapes).map(([shapeName, config]) => {
27
+ var _config$queries$all;
28
+
29
+ const queries = {};
30
+ const triggers = [];
31
+
32
+ if (!config.queries) {
33
+ return [shapeName, { ...config,
34
+ queries,
35
+ triggers
36
+ }];
37
+ }
38
+
39
+ if (hasWebhook(projectSchema, config)) {
40
+ queries.get = config.queries.single;
41
+ triggers.push({
42
+ type: 'webhook',
43
+ query: 'get',
44
+ service: 'shopify',
45
+ events: ['products/create', 'products/update', 'products/delete']
46
+ });
47
+ }
48
+
49
+ const oldPagination = (_config$queries$all = config.queries.all) === null || _config$queries$all === void 0 ? void 0 : _config$queries$all.pagination;
50
+ const pagination = oldPagination === undefined ? undefined : oldPagination.type === 'cursor' ? { ...oldPagination,
51
+ itemsToIndexPath: oldPagination.itemsPath,
52
+ pageSize: oldPagination.size,
53
+ pageSizeArg: oldPagination.sizeArg
54
+ } : oldPagination.type === 'offset' ? { ...oldPagination,
55
+ itemsToIndexPath: oldPagination.itemsPath,
56
+ itemTotalPath: oldPagination.totalPath,
57
+ offsetArg: oldPagination.offsetParam
58
+ } : { ...oldPagination,
59
+ itemsToIndexPath: oldPagination.itemsPath,
60
+ pageTotalPath: oldPagination.totalPagesPath
61
+ };
62
+ queries.list = pagination ? { ...omit(config.queries.all, 'interval'),
63
+ pagination
64
+ } : omit(config.queries.all, 'interval', 'pagination');
65
+ triggers.push({
66
+ type: 'schedule',
67
+ query: 'list',
68
+ interval: config.queries.all.interval ?? 60 * 24
69
+ });
70
+ return [shapeName, { ...config,
71
+ queries,
72
+ triggers
73
+ }];
74
+ }));
75
+ return { ...projectSchema,
76
+ schemaVersion: '3.12.3',
77
+ indexedShapes
78
+ };
79
+ }
80
+
81
+ export default migrateToV3_12_3;
@@ -0,0 +1,21 @@
1
+ import { visit } from '@takeshape/util';
2
+ import get from 'lodash/get';
3
+
4
+ function migrateToV3_13_0(projectSchema) {
5
+ visit(projectSchema, ['@relationship'], (relationship, path) => {
6
+ const parent = get(projectSchema, path.slice(0, -1));
7
+ parent['@backReference'] = {
8
+ enabled: true
9
+ };
10
+
11
+ if (relationship.relatedName) {
12
+ parent['@backReference'].name = relationship.relatedName;
13
+ delete relationship.relatedName;
14
+ }
15
+ });
16
+ return { ...projectSchema,
17
+ schemaVersion: '3.13.0'
18
+ };
19
+ }
20
+
21
+ export default migrateToV3_13_0;
@@ -1,23 +1,6 @@
1
1
  export function formatDate(timestamp) {
2
2
  return (timestamp ? new Date(timestamp) : new Date()).toISOString();
3
3
  }
4
- export function getRelationshipSchema(relationship) {
5
- const itemSchema = {
6
- $ref: '#/shapes/TSRelationship/schema'
7
- };
8
-
9
- if (relationship.type === 'multiple') {
10
- return {
11
- type: 'array',
12
- items: itemSchema,
13
- '@relationship': relationship
14
- };
15
- }
16
-
17
- return { ...itemSchema,
18
- '@relationship': relationship
19
- };
20
- }
21
4
  export function normalizeSchemaVersion(version) {
22
5
  return version === undefined ? '1' : version;
23
6
  }
@@ -1,6 +1,8 @@
1
1
  // This file is generated by "pnpm json2ts"
2
2
  export * from './latest';
3
3
  export * from './v4.0.0';
4
+ export * from './v3.13.0';
5
+ export * from './v3.12.3';
4
6
  export * from './v3.12.2';
5
7
  export * from './v3.12.1';
6
8
  export * from './v3.12.0';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ export function getRelationshipSchema(relationship) {
2
+ const itemSchema = {
3
+ $ref: '#/shapes/TSRelationship/schema'
4
+ };
5
+
6
+ if (relationship.type === 'multiple') {
7
+ return {
8
+ type: 'array',
9
+ items: itemSchema,
10
+ '@relationship': relationship
11
+ };
12
+ }
13
+
14
+ return { ...itemSchema,
15
+ '@relationship': relationship
16
+ };
17
+ }
package/es/schema-util.js CHANGED
@@ -44,7 +44,7 @@ export const objectSchemaKeys = [...commonSchemaKeys, 'properties', 'required'];
44
44
  export const arraySchemaKeys = [...commonSchemaKeys, 'items', 'additionalItems', 'maxItems', 'minItems', 'uniqueItems'];
45
45
  export const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems']; // All properties except properties, items, additionalItems
46
46
 
47
- export const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@relationship', 'required', 'maxItems', 'minItems', 'uniqueItems'];
47
+ export const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@relationship', '@backReference', 'required', 'maxItems', 'minItems', 'uniqueItems'];
48
48
  const commonProperties = {
49
49
  _id: {
50
50
  title: 'Id',
@@ -426,17 +426,22 @@ export function findExistingRelationships(projectSchema, shapes) {
426
426
 
427
427
  const findRelationships = (schema, path) => {
428
428
  if (schema['@relationship']) {
429
+ var _schema$BackReferenc;
430
+
429
431
  const {
430
- shapeIds: relatedShapeIds,
431
- relatedName
432
+ shapeIds: relatedShapeIds
432
433
  } = schema['@relationship'];
434
+ const relatedName = (_schema$BackReferenc = schema['@backReference']) === null || _schema$BackReferenc === void 0 ? void 0 : _schema$BackReferenc.name;
433
435
 
434
436
  for (const shapeId of relatedShapeIds) {
435
437
  if (shapeIds.has(shapeId)) {
438
+ var _schema$BackReferenc2;
439
+
436
440
  addRelationship(relationships, shapeId, {
437
441
  relatedName,
438
442
  path: path.slice(1),
439
- shapeId: path[0]
443
+ shapeId: path[0],
444
+ hasBackreference: Boolean((_schema$BackReferenc2 = schema['@backReference']) === null || _schema$BackReferenc2 === void 0 ? void 0 : _schema$BackReferenc2.enabled)
440
445
  });
441
446
  }
442
447
  }
@@ -1,8 +1,10 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.12.2';
2
+ export const CURRENT_SCHEMA_VERSION = '3.13.0';
3
3
  export { default as anyProjectSchema } from './project-schema.json';
4
- export { default as latestSchemaJson } from './project-schema/v3.12.2.json';
4
+ export { default as latestSchemaJson } from './project-schema/v3.13.0.json';
5
5
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
6
+ import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
7
+ import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
6
8
  import projectSchemaV3_12_2 from './project-schema/v3.12.2.json';
7
9
  import projectSchemaV3_12_1 from './project-schema/v3.12.1.json';
8
10
  import projectSchemaV3_12_0 from './project-schema/v3.12.0.json';
@@ -32,4 +34,4 @@ import projectSchemaV3_0_0 from './project-schema/v3.0.0.json';
32
34
  import metaSchemaV3_0_0 from './project-schema/meta-schema-v3.0.0.json';
33
35
  import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
34
36
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
35
- export const allProjectSchemas = [projectSchemaV4_0_0, 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];
37
+ export const allProjectSchemas = [projectSchemaV4_0_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];
@@ -1,8 +1,10 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.12.2';
2
+ export const CURRENT_SCHEMA_VERSION = '3.13.0';
3
3
  export {default as anyProjectSchema} from './project-schema.json';
4
- export {default as latestSchemaJson} from './project-schema/v3.12.2.json';
4
+ export {default as latestSchemaJson} from './project-schema/v3.13.0.json';
5
5
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
6
+ import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
7
+ import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
6
8
  import projectSchemaV3_12_2 from './project-schema/v3.12.2.json';
7
9
  import projectSchemaV3_12_1 from './project-schema/v3.12.1.json';
8
10
  import projectSchemaV3_12_0 from './project-schema/v3.12.0.json';
@@ -34,6 +36,8 @@ import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
34
36
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
35
37
  export const allProjectSchemas = [
36
38
  projectSchemaV4_0_0,
39
+ projectSchemaV3_13_0,
40
+ projectSchemaV3_12_3,
37
41
  projectSchemaV3_12_2,
38
42
  projectSchemaV3_12_1,
39
43
  projectSchemaV3_12_0,