@takeshape/schema 8.87.1 → 8.89.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 (73) hide show
  1. package/es/builtin-schema.js +23 -0
  2. package/es/migration/index.js +3 -1
  3. package/es/migration/to/v3.17.0.js +27 -0
  4. package/es/project-schema/index.js +3 -1
  5. package/es/project-schema/migrate.js +5 -1
  6. package/es/project-schema/v3.17.0.js +1 -0
  7. package/es/schema-util.js +30 -18
  8. package/es/schemas/index.js +4 -3
  9. package/es/schemas/index.ts +4 -2
  10. package/es/schemas/project-schema/latest.json +7 -8
  11. package/es/schemas/project-schema/v3.17.0.json +2358 -0
  12. package/es/schemas/project-schema.json +3 -0
  13. package/es/template-shapes/where.js +1 -1
  14. package/es/validate.js +12 -8
  15. package/examples/latest/betzino.json +1393 -349
  16. package/examples/latest/blog-schema.json +1 -1
  17. package/examples/latest/brewery-schema.json +1 -1
  18. package/examples/latest/complex-project-schema.json +1 -1
  19. package/examples/latest/fabric-ecommerce.json +1 -1
  20. package/examples/latest/frank-and-fred-schema.json +1 -1
  21. package/examples/latest/massive-schema.json +1 -1
  22. package/examples/latest/mill-components-schema.json +1 -1
  23. package/examples/latest/pet-oneof-array.json +1 -1
  24. package/examples/latest/post-schema.json +1 -1
  25. package/examples/latest/pruned-shopify-product-schema.json +1 -1
  26. package/examples/latest/real-world-schema.json +1 -1
  27. package/examples/latest/recursive-repeater-schema.json +1 -1
  28. package/examples/latest/recursive-schema.json +1 -1
  29. package/examples/latest/rick-and-morty-ast.json +145 -37
  30. package/examples/latest/rick-and-morty-graphql.json +113 -29
  31. package/examples/latest/rick-and-morty-rest.json +1 -1
  32. package/examples/latest/schema-with-repeater-draftjs.json +1 -1
  33. package/examples/latest/shape-books-v3_2_0.json +1 -1
  34. package/examples/latest/shape-books.json +1 -1
  35. package/examples/latest/shopify-lookbook.json +1 -1
  36. package/examples/latest/shopify-store-with-widget.json +81 -21
  37. package/examples/latest/stripe-starter-resolved.json +49 -13
  38. package/examples/latest/user-schema-no-required.json +1 -1
  39. package/examples/latest/user-schema-with-defaults.json +1 -1
  40. package/lib/builtin-schema.d.ts.map +1 -1
  41. package/lib/builtin-schema.js +23 -0
  42. package/lib/migration/index.d.ts +1 -0
  43. package/lib/migration/index.d.ts.map +1 -1
  44. package/lib/migration/index.js +4 -1
  45. package/lib/migration/to/v3.17.0.d.ts +5 -0
  46. package/lib/migration/to/v3.17.0.d.ts.map +1 -0
  47. package/lib/migration/to/v3.17.0.js +40 -0
  48. package/lib/project-schema/index.d.ts +4 -1
  49. package/lib/project-schema/index.d.ts.map +1 -1
  50. package/lib/project-schema/index.js +20 -3
  51. package/lib/project-schema/latest.d.ts +2 -5
  52. package/lib/project-schema/latest.d.ts.map +1 -1
  53. package/lib/project-schema/migrate.d.ts.map +1 -1
  54. package/lib/project-schema/migrate.js +4 -0
  55. package/lib/project-schema/v3.17.0.d.ts +1456 -0
  56. package/lib/project-schema/v3.17.0.d.ts.map +1 -0
  57. package/lib/project-schema/v3.17.0.js +5 -0
  58. package/lib/schema-util.d.ts.map +1 -1
  59. package/lib/schema-util.js +30 -18
  60. package/lib/schemas/index.d.ts +2301 -2
  61. package/lib/schemas/index.d.ts.map +1 -1
  62. package/lib/schemas/index.js +6 -4
  63. package/lib/schemas/index.ts +4 -2
  64. package/lib/schemas/project-schema/latest.json +7 -8
  65. package/lib/schemas/project-schema/v3.17.0.json +2358 -0
  66. package/lib/schemas/project-schema.json +3 -0
  67. package/lib/template-shapes/where.d.ts.map +1 -1
  68. package/lib/template-shapes/where.js +1 -1
  69. package/lib/types/types.d.ts +2 -2
  70. package/lib/types/types.d.ts.map +1 -1
  71. package/lib/validate.d.ts.map +1 -1
  72. package/lib/validate.js +12 -8
  73. package/package.json +4 -4
@@ -121,6 +121,29 @@ export const builtInShapes = {
121
121
  }
122
122
  }
123
123
  },
124
+ TSUser: {
125
+ id: 'TSUser',
126
+ name: 'TSUser',
127
+ title: 'TSUser',
128
+ schema: {
129
+ type: 'object',
130
+ properties: {
131
+ id: {
132
+ type: 'string'
133
+ },
134
+ email: {
135
+ type: 'string'
136
+ },
137
+ fullName: {
138
+ type: 'string'
139
+ },
140
+ avatarPath: {
141
+ type: 'string'
142
+ }
143
+ },
144
+ required: ['id', 'email', 'fullName']
145
+ }
146
+ },
124
147
  Asset: {
125
148
  id: 'ASSET',
126
149
  name: 'Asset',
@@ -19,6 +19,7 @@ import migrateToV3_13_0 from './to/v3.13.0';
19
19
  import migrateToV3_14_0 from './to/v3.14.0';
20
20
  import migrateToV3_15_0 from './to/v3.15.0';
21
21
  import migrateToV3_16_0 from './to/v3.16.0';
22
+ import migrateToV3_17_0 from './to/v3.17.0';
22
23
  export const migrateTo = {
23
24
  'v3.0.0': migrateToV3_0_0,
24
25
  'v3.1.0': migrateToV3_1_0,
@@ -40,7 +41,8 @@ export const migrateTo = {
40
41
  'v3.13.0': migrateToV3_13_0,
41
42
  'v3.14.0': migrateToV3_14_0,
42
43
  'v3.15.0': migrateToV3_15_0,
43
- 'v3.16.0': migrateToV3_16_0
44
+ 'v3.16.0': migrateToV3_16_0,
45
+ 'v3.17.0': migrateToV3_17_0
44
46
  };
45
47
  export * from './utils';
46
48
  export const listTypePrefix = 'PaginatedList';
@@ -0,0 +1,27 @@
1
+ import { visit } from '@takeshape/util';
2
+ import get from 'lodash/get';
3
+ import set from 'lodash/set';
4
+ import omit from 'lodash/omit';
5
+
6
+ const migrate = async (_, projectSchema) => {
7
+ visit(projectSchema, ['@user'], (_, path) => {
8
+ const parentPath = path.slice(0, -1);
9
+ const oldSchema = get(projectSchema, parentPath);
10
+ const newSchema = { ...omit(oldSchema, ['@user', 'type']),
11
+ '@ref': 'local:TSUser',
12
+ '@input': {
13
+ type: 'string'
14
+ },
15
+ '@resolver': {
16
+ name: 'takeshape:getUser',
17
+ service: 'takeshape:local'
18
+ }
19
+ };
20
+ set(projectSchema, parentPath, newSchema);
21
+ });
22
+ return { ...projectSchema,
23
+ schemaVersion: '3.17.0'
24
+ };
25
+ };
26
+
27
+ export default migrate;
@@ -22,6 +22,7 @@ export * from './v3.13.0';
22
22
  export * from './v3.14.0';
23
23
  export * from './v3.15.0';
24
24
  export * from './v3.16.0';
25
+ export * from './v3.17.0';
25
26
  export * from './v4.0.0';
26
27
 
27
28
  // Schema type utilities
@@ -65,5 +66,6 @@ export const isProjectSchemaV3_13_0 = createVersionPredicate('3.13.0');
65
66
  export const isProjectSchemaV3_14_0 = createVersionPredicate('3.14.0');
66
67
  export const isProjectSchemaV3_15_0 = createVersionPredicate('3.15.0');
67
68
  export const isProjectSchemaV3_16_0 = createVersionPredicate('3.16.0');
68
- export const isLatestProjectSchema = createVersionPredicate('3.16.0');
69
+ export const isProjectSchemaV3_17_0 = createVersionPredicate('3.17.0');
70
+ export const isLatestProjectSchema = createVersionPredicate('3.17.0');
69
71
  export const isProjectSchemaV4_0_0 = createVersionPredicate('4.0.0');
@@ -1,6 +1,6 @@
1
1
  // This file is generated by "pnpm json2ts"
2
2
  import { migrateTo } from '../migration';
3
- import { isProjectSchemaV1_0_0, isProjectSchemaV3_0_0, isProjectSchemaV3_1_0, isProjectSchemaV3_2_0, isProjectSchemaV3_3_0, isProjectSchemaV3_4_0, isProjectSchemaV3_5_0, isProjectSchemaV3_5_1, isProjectSchemaV3_6_0, isProjectSchemaV3_7_0, isProjectSchemaV3_8_0, isProjectSchemaV3_9_0, isProjectSchemaV3_10_0, isProjectSchemaV3_11_0, isProjectSchemaV3_12_0, isProjectSchemaV3_12_1, isProjectSchemaV3_12_2, isProjectSchemaV3_12_3, isProjectSchemaV3_13_0, isProjectSchemaV3_14_0, isProjectSchemaV3_15_0, isProjectSchemaV4_0_0, isLatestProjectSchema } from './index'; // eslint-disable-next-line complexity
3
+ import { isProjectSchemaV1_0_0, isProjectSchemaV3_0_0, isProjectSchemaV3_1_0, isProjectSchemaV3_2_0, isProjectSchemaV3_3_0, isProjectSchemaV3_4_0, isProjectSchemaV3_5_0, isProjectSchemaV3_5_1, isProjectSchemaV3_6_0, isProjectSchemaV3_7_0, isProjectSchemaV3_8_0, isProjectSchemaV3_9_0, isProjectSchemaV3_10_0, isProjectSchemaV3_11_0, isProjectSchemaV3_12_0, isProjectSchemaV3_12_1, isProjectSchemaV3_12_2, isProjectSchemaV3_12_3, isProjectSchemaV3_13_0, isProjectSchemaV3_14_0, isProjectSchemaV3_15_0, isProjectSchemaV3_16_0, isProjectSchemaV4_0_0, isLatestProjectSchema } from './index'; // eslint-disable-next-line complexity
4
4
 
5
5
  export async function migrateToLatestProjectSchema(context, projectSchema) {
6
6
  if (isLatestProjectSchema(projectSchema)) {
@@ -91,6 +91,10 @@ export async function migrateToLatestProjectSchema(context, projectSchema) {
91
91
  projectSchema = await migrateTo['v3.16.0'](context, projectSchema);
92
92
  }
93
93
 
94
+ if (isProjectSchemaV3_16_0(projectSchema)) {
95
+ projectSchema = await migrateTo['v3.17.0'](context, projectSchema);
96
+ }
97
+
94
98
  if (isProjectSchemaV4_0_0(projectSchema)) {
95
99
  throw new Error('You are using an unreleased schema version. Migration is not possible');
96
100
  }
@@ -0,0 +1 @@
1
+ export {};
package/es/schema-util.js CHANGED
@@ -66,8 +66,14 @@ const commonProperties = {
66
66
  },
67
67
  _createdBy: {
68
68
  title: 'Created By',
69
- type: 'string',
70
- '@user': true
69
+ '@ref': 'local:TSUser',
70
+ '@input': {
71
+ type: 'string'
72
+ },
73
+ '@resolver': {
74
+ name: 'takeshape:getUser',
75
+ service: 'takeshape:local'
76
+ }
71
77
  },
72
78
  _updatedAt: {
73
79
  title: 'Updated',
@@ -76,8 +82,14 @@ const commonProperties = {
76
82
  },
77
83
  _updatedBy: {
78
84
  title: 'Updated By',
79
- type: 'string',
80
- '@user': true
85
+ '@ref': 'local:TSUser',
86
+ '@input': {
87
+ type: 'string'
88
+ },
89
+ '@resolver': {
90
+ name: 'takeshape:getUser',
91
+ service: 'takeshape:local'
92
+ }
81
93
  },
82
94
  _schemaVersion: {
83
95
  title: 'Schema Version',
@@ -311,7 +323,7 @@ export function applyBuiltinPropertiesToShape(projectSchema, shape) {
311
323
  };
312
324
  } // Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
313
325
 
314
- const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TsStaticSite'];
326
+ const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TsStaticSite', 'TSUser'];
315
327
  /**
316
328
  * Get all built-in shapes that are depended on by the given project schema.
317
329
  * Required built-in shapes are always included.
@@ -564,7 +576,16 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
564
576
 
565
577
  if (!definitionNames.has(shapeName)) {
566
578
  definitionNames.add(shapeName);
567
- definitions[shapeName] = rewriteRefs(shape, addDiscriminator);
579
+ const rewritten = rewriteRefs(shape, addDiscriminator);
580
+
581
+ if (useShapeIdDiscriminator && isObjectSchema(rewritten)) {
582
+ rewritten.properties._shapeId = {
583
+ type: 'string',
584
+ enum: [shape.id]
585
+ };
586
+ }
587
+
588
+ definitions[shapeName] = rewritten;
568
589
  }
569
590
  }
570
591
  }
@@ -583,17 +604,8 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
583
604
 
584
605
  const shapeSchemaCopy = dereferenceObjectSchema(projectSchema, shapeSchema);
585
606
 
586
- if (useShapeIdDiscriminator) {
587
- if (addDiscriminator && shapeSchemaCopy.properties) {
588
- shapeSchemaCopy.properties._shapeId = {
589
- type: 'string',
590
- enum: [shape.id]
591
- };
592
- }
593
-
594
- if (addDiscriminator && shape.title) {
595
- shapeSchemaCopy.title = shape.title;
596
- }
607
+ if (useShapeIdDiscriminator && addDiscriminator && shape.title) {
608
+ shapeSchemaCopy.title = shape.title;
597
609
  }
598
610
 
599
611
  Object.values(shapeSchemaCopy.properties).forEach(schema => {
@@ -645,7 +657,7 @@ export function getShapeDependencies(projectSchema, shape, predicate) {
645
657
 
646
658
  if (refShape && !shapeNames.has(refShape.name)) {
647
659
  shapeNames.add(refShape.name);
648
- findDependencies(dereferenceSchema(projectSchema, refShape.schema));
660
+ findDependencies(dereferenceSchema(projectSchema, refShape.schema, ['shapes', refShape.name]));
649
661
  }
650
662
  } else if (isObjectSchema(schema) || isAllOfSchema(schema) || isOneOfSchema(schema)) {
651
663
  visitSchemaProperties(schema, [], findDependencies);
@@ -1,7 +1,7 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.16.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.17.0';
3
3
  export { default as anyProjectSchema } from './project-schema.json';
4
- export { default as latestSchemaJson } from './project-schema/v3.16.0.json';
4
+ export { default as latestSchemaJson } from './project-schema/v3.17.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';
@@ -36,5 +36,6 @@ import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
36
36
  import projectSchemaV3_14_0 from './project-schema/v3.14.0.json';
37
37
  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
+ import projectSchemaV3_17_0 from './project-schema/v3.17.0.json';
39
40
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
40
- export const allProjectSchemas = [metaSchemaV1_0_0, projectSchemaV1_0_0, metaSchemaV3_0_0, projectSchemaV3_0_0, metaSchemaV3_1_0, projectSchemaV3_1_0, metaSchemaV3_2_0, projectSchemaV3_2_0, metaSchemaV3_3_0, projectSchemaV3_3_0, metaSchemaV3_4_0, projectSchemaV3_4_0, metaSchemaV3_5_0, projectSchemaV3_5_0, metaSchemaV3_5_1, projectSchemaV3_5_1, metaSchemaV3_6_0, projectSchemaV3_6_0, metaSchemaV3_7_0, projectSchemaV3_7_0, metaSchemaV3_8_0, projectSchemaV3_8_0, metaSchemaV3_9_0, projectSchemaV3_9_0, projectSchemaV3_10_0, projectSchemaV3_11_0, projectSchemaV3_12_0, projectSchemaV3_12_1, projectSchemaV3_12_2, projectSchemaV3_12_3, projectSchemaV3_13_0, projectSchemaV3_14_0, projectSchemaV3_15_0, projectSchemaV3_16_0, projectSchemaV4_0_0];
41
+ export const allProjectSchemas = [metaSchemaV1_0_0, projectSchemaV1_0_0, metaSchemaV3_0_0, projectSchemaV3_0_0, metaSchemaV3_1_0, projectSchemaV3_1_0, metaSchemaV3_2_0, projectSchemaV3_2_0, metaSchemaV3_3_0, projectSchemaV3_3_0, metaSchemaV3_4_0, projectSchemaV3_4_0, metaSchemaV3_5_0, projectSchemaV3_5_0, metaSchemaV3_5_1, projectSchemaV3_5_1, metaSchemaV3_6_0, projectSchemaV3_6_0, metaSchemaV3_7_0, projectSchemaV3_7_0, metaSchemaV3_8_0, projectSchemaV3_8_0, metaSchemaV3_9_0, projectSchemaV3_9_0, projectSchemaV3_10_0, projectSchemaV3_11_0, projectSchemaV3_12_0, projectSchemaV3_12_1, projectSchemaV3_12_2, projectSchemaV3_12_3, projectSchemaV3_13_0, projectSchemaV3_14_0, projectSchemaV3_15_0, projectSchemaV3_16_0, projectSchemaV3_17_0, projectSchemaV4_0_0];
@@ -1,7 +1,7 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.16.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.17.0';
3
3
  export {default as anyProjectSchema} from './project-schema.json';
4
- export {default as latestSchemaJson} from './project-schema/v3.16.0.json';
4
+ export {default as latestSchemaJson} from './project-schema/v3.17.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';
@@ -36,6 +36,7 @@ import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
36
36
  import projectSchemaV3_14_0 from './project-schema/v3.14.0.json';
37
37
  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
+ import projectSchemaV3_17_0 from './project-schema/v3.17.0.json';
39
40
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
40
41
  export const allProjectSchemas = [
41
42
  metaSchemaV1_0_0,
@@ -72,5 +73,6 @@ export const allProjectSchemas = [
72
73
  projectSchemaV3_14_0,
73
74
  projectSchemaV3_15_0,
74
75
  projectSchemaV3_16_0,
76
+ projectSchemaV3_17_0,
75
77
  projectSchemaV4_0_0
76
78
  ];
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://schema.takeshape.io/project-schema/v3.16.0#",
3
+ "$id": "https://schema.takeshape.io/project-schema/v3.17.0#",
4
4
  "title": "Project Schema",
5
5
  "definitions": {
6
6
  "schemaArray": {
@@ -980,7 +980,8 @@
980
980
  },
981
981
  "shapeName": {
982
982
  "description": "A Shape name for the resolver to use.",
983
- "type": "string"
983
+ "type": "string",
984
+ "minLength": 1
984
985
  },
985
986
  "args": {
986
987
  "description": "Mapping and serialization configuration for args.",
@@ -1009,7 +1010,7 @@
1009
1010
  "title": "InternalTakeshapeResolverName",
1010
1011
  "type": "string",
1011
1012
  "description": "Name of the resolver function.",
1012
- "enum": ["takeshape:getRelationship", "takeshape:taxonomySuggest", "takeshape:list", "takeshape:search"]
1013
+ "enum": ["takeshape:getRelationship", "takeshape:taxonomySuggest", "takeshape:list", "takeshape:search", "takeshape:getUser"]
1013
1014
  },
1014
1015
  "service": {
1015
1016
  "type": "string",
@@ -1023,7 +1024,8 @@
1023
1024
  },
1024
1025
  "shapeName": {
1025
1026
  "description": "An optional Shape name for the resolver.",
1026
- "type": "string"
1027
+ "type": "string",
1028
+ "minLength": 1
1027
1029
  },
1028
1030
  "args": {
1029
1031
  "description": "Mapping and serialization configuration for args.",
@@ -1492,9 +1494,6 @@
1492
1494
  "@deprecationReason": {
1493
1495
  "type": "string"
1494
1496
  },
1495
- "@user": {
1496
- "type": "boolean"
1497
- },
1498
1497
  "@args": {
1499
1498
  "$ref": "#/definitions/args"
1500
1499
  },
@@ -2277,7 +2276,7 @@
2277
2276
  },
2278
2277
  "schemaVersion": {
2279
2278
  "type": "string",
2280
- "enum": ["3.16.0"],
2279
+ "enum": ["3.17.0"],
2281
2280
  "description": "The version of the schema format your project is using. We increase the version as we make breaking changes to the schema format."
2282
2281
  },
2283
2282
  "projectId": {