@takeshape/schema 8.86.3 → 8.87.3

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 (66) hide show
  1. package/es/migration/index.js +3 -1
  2. package/es/migration/to/v3.16.0.js +10 -0
  3. package/es/project-schema/index.js +3 -1
  4. package/es/project-schema/migrate.js +5 -1
  5. package/es/project-schema/v3.16.0.js +1 -0
  6. package/es/schema-util.js +32 -17
  7. package/es/schemas/index.js +4 -3
  8. package/es/schemas/index.ts +4 -2
  9. package/es/schemas/project-schema/latest.json +10 -2
  10. package/es/schemas/project-schema/v3.16.0.json +2367 -0
  11. package/es/schemas/project-schema.json +3 -0
  12. package/es/validate.js +1 -1
  13. package/examples/latest/betzino.json +1 -1
  14. package/examples/latest/blog-schema.json +1 -1
  15. package/examples/latest/brewery-schema.json +1 -1
  16. package/examples/latest/complex-project-schema.json +1 -1
  17. package/examples/latest/fabric-ecommerce.json +1 -1
  18. package/examples/latest/frank-and-fred-schema.json +1 -1
  19. package/examples/latest/massive-schema.json +1 -1
  20. package/examples/latest/mill-components-schema.json +1 -1
  21. package/examples/latest/pet-oneof-array.json +1 -1
  22. package/examples/latest/post-schema.json +1 -1
  23. package/examples/latest/pruned-shopify-product-schema.json +1 -1
  24. package/examples/latest/real-world-schema.json +1 -1
  25. package/examples/latest/recursive-repeater-schema.json +1 -1
  26. package/examples/latest/recursive-schema.json +1 -1
  27. package/examples/latest/rick-and-morty-ast.json +1 -1
  28. package/examples/latest/rick-and-morty-graphql.json +1 -1
  29. package/examples/latest/rick-and-morty-rest.json +1 -1
  30. package/examples/latest/schema-with-repeater-draftjs.json +1 -1
  31. package/examples/latest/shape-books-v3_2_0.json +1 -1
  32. package/examples/latest/shape-books.json +1 -1
  33. package/examples/latest/shopify-lookbook.json +1 -1
  34. package/examples/latest/shopify-store-with-widget.json +1 -1
  35. package/examples/latest/stripe-starter-resolved.json +1 -1
  36. package/examples/latest/user-schema-no-required.json +1 -1
  37. package/examples/latest/user-schema-with-defaults.json +1 -1
  38. package/lib/migration/index.d.ts +1 -0
  39. package/lib/migration/index.d.ts.map +1 -1
  40. package/lib/migration/index.js +4 -1
  41. package/lib/migration/to/v3.16.0.d.ts +5 -0
  42. package/lib/migration/to/v3.16.0.d.ts.map +1 -0
  43. package/lib/migration/to/v3.16.0.js +18 -0
  44. package/lib/project-schema/index.d.ts +4 -1
  45. package/lib/project-schema/index.d.ts.map +1 -1
  46. package/lib/project-schema/index.js +20 -3
  47. package/lib/project-schema/latest.d.ts +13 -1
  48. package/lib/project-schema/latest.d.ts.map +1 -1
  49. package/lib/project-schema/migrate.d.ts.map +1 -1
  50. package/lib/project-schema/migrate.js +4 -0
  51. package/lib/project-schema/v3.16.0.d.ts +1471 -0
  52. package/lib/project-schema/v3.16.0.d.ts.map +1 -0
  53. package/lib/project-schema/v3.16.0.js +5 -0
  54. package/lib/schema-util.d.ts.map +1 -1
  55. package/lib/schema-util.js +32 -17
  56. package/lib/schemas/index.d.ts +4583 -4583
  57. package/lib/schemas/index.d.ts.map +1 -1
  58. package/lib/schemas/index.js +6 -4
  59. package/lib/schemas/index.ts +4 -2
  60. package/lib/schemas/project-schema/latest.json +10 -2
  61. package/lib/schemas/project-schema/v3.16.0.json +2367 -0
  62. package/lib/schemas/project-schema.json +3 -0
  63. package/lib/types/types.d.ts +2 -2
  64. package/lib/types/types.d.ts.map +1 -1
  65. package/lib/validate.js +1 -1
  66. package/package.json +6 -6
@@ -18,6 +18,7 @@ import migrateToV3_12_3 from './to/v3.12.3';
18
18
  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
+ import migrateToV3_16_0 from './to/v3.16.0';
21
22
  export const migrateTo = {
22
23
  'v3.0.0': migrateToV3_0_0,
23
24
  'v3.1.0': migrateToV3_1_0,
@@ -38,7 +39,8 @@ export const migrateTo = {
38
39
  'v3.12.3': migrateToV3_12_3,
39
40
  'v3.13.0': migrateToV3_13_0,
40
41
  'v3.14.0': migrateToV3_14_0,
41
- 'v3.15.0': migrateToV3_15_0
42
+ 'v3.15.0': migrateToV3_15_0,
43
+ 'v3.16.0': migrateToV3_16_0
42
44
  };
43
45
  export * from './utils';
44
46
  export const listTypePrefix = 'PaginatedList';
@@ -0,0 +1,10 @@
1
+ const migrate = async (_, projectSchema) => {
2
+ /**
3
+ * No migration needed all changes are backwards compatible.
4
+ */
5
+ return { ...projectSchema,
6
+ schemaVersion: '3.16.0'
7
+ };
8
+ };
9
+
10
+ export default migrate;
@@ -21,6 +21,7 @@ export * from './v3.12.3';
21
21
  export * from './v3.13.0';
22
22
  export * from './v3.14.0';
23
23
  export * from './v3.15.0';
24
+ export * from './v3.16.0';
24
25
  export * from './v4.0.0';
25
26
 
26
27
  // Schema type utilities
@@ -63,5 +64,6 @@ export const isProjectSchemaV3_12_3 = createVersionPredicate('3.12.3');
63
64
  export const isProjectSchemaV3_13_0 = createVersionPredicate('3.13.0');
64
65
  export const isProjectSchemaV3_14_0 = createVersionPredicate('3.14.0');
65
66
  export const isProjectSchemaV3_15_0 = createVersionPredicate('3.15.0');
66
- export const isLatestProjectSchema = createVersionPredicate('3.15.0');
67
+ export const isProjectSchemaV3_16_0 = createVersionPredicate('3.16.0');
68
+ export const isLatestProjectSchema = createVersionPredicate('3.16.0');
67
69
  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, 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, 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)) {
@@ -87,6 +87,10 @@ export async function migrateToLatestProjectSchema(context, projectSchema) {
87
87
  projectSchema = await migrateTo['v3.15.0'](context, projectSchema);
88
88
  }
89
89
 
90
+ if (isProjectSchemaV3_15_0(projectSchema)) {
91
+ projectSchema = await migrateTo['v3.16.0'](context, projectSchema);
92
+ }
93
+
90
94
  if (isProjectSchemaV4_0_0(projectSchema)) {
91
95
  throw new Error('You are using an unreleased schema version. Migration is not possible');
92
96
  }
@@ -0,0 +1 @@
1
+ export {};
package/es/schema-util.js CHANGED
@@ -518,15 +518,26 @@ export function getArgsShapeSchema(context, argsSchema) {
518
518
  }
519
519
  }
520
520
 
521
- const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, useShapeIdDiscriminator = true) => {
521
+ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, {
522
+ useShapeIdDiscriminator
523
+ }) => {
522
524
  const rewriteRefs = (shape, addDiscriminator = false) => {
523
525
  const handleSchema = (propSchema, addDiscriminator = false) => {
524
526
  // Unwrap array schema
525
527
  propSchema = propSchema.items ?? propSchema;
526
528
 
527
529
  if (isOneOfSchema(propSchema)) {
530
+ const isUnion = isUnionSchema(propSchema);
531
+
532
+ if (useShapeIdDiscriminator && isUnion) {
533
+ propSchema.discriminator = {
534
+ propertyName: '_shapeId'
535
+ };
536
+ propSchema.required = ['_shapeId'];
537
+ }
538
+
528
539
  propSchema.oneOf.forEach(schema => {
529
- handleSchema(schema, true);
540
+ handleSchema(schema, isUnion);
530
541
  });
531
542
  return;
532
543
  } // Add workflow validation
@@ -553,7 +564,16 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
553
564
 
554
565
  if (!definitionNames.has(shapeName)) {
555
566
  definitionNames.add(shapeName);
556
- definitions[shapeName] = rewriteRefs(shape, addDiscriminator);
567
+ const rewritten = rewriteRefs(shape, addDiscriminator);
568
+
569
+ if (useShapeIdDiscriminator && isObjectSchema(rewritten)) {
570
+ rewritten.properties._shapeId = {
571
+ type: 'string',
572
+ enum: [shape.id]
573
+ };
574
+ }
575
+
576
+ definitions[shapeName] = rewritten;
557
577
  }
558
578
  }
559
579
  }
@@ -572,17 +592,8 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
572
592
 
573
593
  const shapeSchemaCopy = dereferenceObjectSchema(projectSchema, shapeSchema);
574
594
 
575
- if (useShapeIdDiscriminator) {
576
- if (addDiscriminator && shapeSchemaCopy.properties) {
577
- shapeSchemaCopy.properties._shapeId = {
578
- type: 'string',
579
- enum: [shape.id]
580
- };
581
- }
582
-
583
- if (addDiscriminator && shape.title) {
584
- shapeSchemaCopy.title = shape.title;
585
- }
595
+ if (useShapeIdDiscriminator && addDiscriminator && shape.title) {
596
+ shapeSchemaCopy.title = shape.title;
586
597
  }
587
598
 
588
599
  Object.values(shapeSchemaCopy.properties).forEach(schema => {
@@ -597,7 +608,9 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
597
608
  export function shapeToPropertySchema(projectSchema, shape) {
598
609
  const definitions = {};
599
610
  const definitionNames = new Set();
600
- const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames);
611
+ const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
612
+ useShapeIdDiscriminator: true
613
+ });
601
614
  return { ...convert(shape),
602
615
  definitions
603
616
  };
@@ -605,7 +618,9 @@ export function shapeToPropertySchema(projectSchema, shape) {
605
618
  export function projectSchemaToJSONSchema(projectSchema) {
606
619
  const definitions = {};
607
620
  const definitionNames = new Set();
608
- const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, false);
621
+ const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
622
+ useShapeIdDiscriminator: false
623
+ });
609
624
 
610
625
  for (const shape of Object.values(projectSchema.shapes)) {
611
626
  definitions[shape.name] = convert(shape);
@@ -630,7 +645,7 @@ export function getShapeDependencies(projectSchema, shape, predicate) {
630
645
 
631
646
  if (refShape && !shapeNames.has(refShape.name)) {
632
647
  shapeNames.add(refShape.name);
633
- findDependencies(dereferenceSchema(projectSchema, refShape.schema));
648
+ findDependencies(dereferenceSchema(projectSchema, refShape.schema, ['shapes', refShape.name]));
634
649
  }
635
650
  } else if (isObjectSchema(schema) || isAllOfSchema(schema) || isOneOfSchema(schema)) {
636
651
  visitSchemaProperties(schema, [], findDependencies);
@@ -1,7 +1,7 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.15.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.16.0';
3
3
  export { default as anyProjectSchema } from './project-schema.json';
4
- export { default as latestSchemaJson } from './project-schema/v3.15.0.json';
4
+ export { default as latestSchemaJson } from './project-schema/v3.16.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';
@@ -35,5 +35,6 @@ import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
35
35
  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
+ import projectSchemaV3_16_0 from './project-schema/v3.16.0.json';
38
39
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
39
- 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, projectSchemaV4_0_0];
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];
@@ -1,7 +1,7 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.15.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.16.0';
3
3
  export {default as anyProjectSchema} from './project-schema.json';
4
- export {default as latestSchemaJson} from './project-schema/v3.15.0.json';
4
+ export {default as latestSchemaJson} from './project-schema/v3.16.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';
@@ -35,6 +35,7 @@ import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
35
35
  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
+ import projectSchemaV3_16_0 from './project-schema/v3.16.0.json';
38
39
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
39
40
  export const allProjectSchemas = [
40
41
  metaSchemaV1_0_0,
@@ -70,5 +71,6 @@ export const allProjectSchemas = [
70
71
  projectSchemaV3_13_0,
71
72
  projectSchemaV3_14_0,
72
73
  projectSchemaV3_15_0,
74
+ projectSchemaV3_16_0,
73
75
  projectSchemaV4_0_0
74
76
  ];
@@ -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.15.0#",
3
+ "$id": "https://schema.takeshape.io/project-schema/v3.16.0#",
4
4
  "title": "Project Schema",
5
5
  "definitions": {
6
6
  "schemaArray": {
@@ -1435,6 +1435,14 @@
1435
1435
  "allOf": {
1436
1436
  "$ref": "#/definitions/schemaArray"
1437
1437
  },
1438
+ "discriminator": {
1439
+ "type": "object",
1440
+ "properties": {
1441
+ "propertyName": {
1442
+ "type": "string"
1443
+ }
1444
+ }
1445
+ },
1438
1446
  "oneOf": {
1439
1447
  "$ref": "#/definitions/schemaArray"
1440
1448
  },
@@ -2269,7 +2277,7 @@
2269
2277
  },
2270
2278
  "schemaVersion": {
2271
2279
  "type": "string",
2272
- "enum": ["3.15.0"],
2280
+ "enum": ["3.16.0"],
2273
2281
  "description": "The version of the schema format your project is using. We increase the version as we make breaking changes to the schema format."
2274
2282
  },
2275
2283
  "projectId": {