@takeshape/schema 8.66.2 → 8.67.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 (79) hide show
  1. package/es/index.js +2 -1
  2. package/es/migration/index.js +8 -2
  3. package/es/migration/to/v3.14.0.js +10 -0
  4. package/es/project-schema/index.js +1 -0
  5. package/es/project-schema/v3.13.1.js +1 -0
  6. package/es/project-schema/v3.14.0.js +1 -0
  7. package/es/rewrite.js +59 -0
  8. package/es/schemas/index.js +4 -3
  9. package/es/schemas/index.ts +4 -2
  10. package/es/schemas/project-schema/v3.14.0.json +2379 -0
  11. package/es/schemas/project-schema.json +2 -1
  12. package/es/template-shapes/templates.js +56 -45
  13. package/es/template-shapes/types.js +8 -1
  14. package/es/types/utils.js +1 -0
  15. package/examples/latest/betzino.json +1 -1
  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 +1 -1
  30. package/examples/latest/rick-and-morty-graphql.json +1 -1
  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 +1 -1
  37. package/examples/latest/stripe-starter-resolved.json +1 -1
  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/index.d.ts +1 -0
  41. package/lib/index.d.ts.map +1 -1
  42. package/lib/index.js +14 -0
  43. package/lib/migration/index.d.ts.map +1 -1
  44. package/lib/migration/index.js +8 -1
  45. package/lib/migration/to/v3.14.0.d.ts +4 -0
  46. package/lib/migration/to/v3.14.0.d.ts.map +1 -0
  47. package/lib/migration/to/v3.14.0.js +18 -0
  48. package/lib/project-schema/index.d.ts +3 -1
  49. package/lib/project-schema/index.d.ts.map +1 -1
  50. package/lib/project-schema/index.js +32 -19
  51. package/lib/project-schema/latest.d.ts +120 -1
  52. package/lib/project-schema/latest.d.ts.map +1 -1
  53. package/lib/project-schema/v3.13.1.d.ts +1413 -0
  54. package/lib/project-schema/v3.13.1.d.ts.map +1 -0
  55. package/lib/project-schema/v3.13.1.js +5 -0
  56. package/lib/project-schema/v3.14.0.d.ts +1437 -0
  57. package/lib/project-schema/v3.14.0.d.ts.map +1 -0
  58. package/lib/project-schema/v3.14.0.js +5 -0
  59. package/lib/rewrite.d.ts +10 -0
  60. package/lib/rewrite.d.ts.map +1 -0
  61. package/lib/rewrite.js +69 -0
  62. package/lib/schemas/index.d.ts +2 -2
  63. package/lib/schemas/index.d.ts.map +1 -1
  64. package/lib/schemas/index.js +23 -21
  65. package/lib/schemas/index.ts +4 -2
  66. package/lib/schemas/project-schema/v3.14.0.json +2379 -0
  67. package/lib/schemas/project-schema.json +2 -1
  68. package/lib/template-shapes/templates.d.ts +11 -4
  69. package/lib/template-shapes/templates.d.ts.map +1 -1
  70. package/lib/template-shapes/templates.js +60 -49
  71. package/lib/template-shapes/types.d.ts +6 -0
  72. package/lib/template-shapes/types.d.ts.map +1 -1
  73. package/lib/template-shapes/types.js +11 -1
  74. package/lib/types/types.d.ts +2 -2
  75. package/lib/types/types.d.ts.map +1 -1
  76. package/lib/types/utils.d.ts +2 -1
  77. package/lib/types/utils.d.ts.map +1 -1
  78. package/lib/types/utils.js +3 -1
  79. package/package.json +4 -4
package/es/index.js CHANGED
@@ -24,4 +24,5 @@ export * from './patterns';
24
24
  export * from './types/types';
25
25
  export * from './types/utils';
26
26
  export * from './flatten-templates';
27
- export * from './relationships';
27
+ export * from './relationships';
28
+ export * from './rewrite';
@@ -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, isProjectSchemaV3_12_2, isProjectSchemaV3_12_3 } 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, isProjectSchemaV3_13_0 } 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';
@@ -17,8 +17,10 @@ import migrateToV3_12_1 from './to/v3.12.1';
17
17
  import migrateToV3_12_2 from './to/v3.12.2';
18
18
  import migrateToV3_12_3 from './to/v3.12.3';
19
19
  import migrateToV3_13_0 from './to/v3.13.0';
20
+ import migrateToV3_14_0 from './to/v3.14.0';
20
21
  export * from './utils';
21
- export const listTypePrefix = 'PaginatedList';
22
+ export const listTypePrefix = 'PaginatedList'; // eslint-disable-next-line complexity
23
+
22
24
  export async function migrateToLatestProjectSchema(context, projectSchema) {
23
25
  if (projectSchema.schemaVersion === '4.0.0') {
24
26
  throw new Error('You are using an unreleased schema version. Migration is not possible');
@@ -96,6 +98,10 @@ export async function migrateToLatestProjectSchema(context, projectSchema) {
96
98
  projectSchema = migrateToV3_13_0(projectSchema);
97
99
  }
98
100
 
101
+ if (isProjectSchemaV3_13_0(projectSchema)) {
102
+ projectSchema = migrateToV3_14_0(projectSchema);
103
+ }
104
+
99
105
  return projectSchema;
100
106
  }
101
107
  export async function ensureLatest(context, schema) {
@@ -0,0 +1,10 @@
1
+ function migrateToV3_14_0(projectSchema) {
2
+ /**
3
+ * No migration needed all changes are backwards compatible.
4
+ */
5
+ return { ...projectSchema,
6
+ schemaVersion: '3.14.0'
7
+ };
8
+ }
9
+
10
+ export default migrateToV3_14_0;
@@ -1,6 +1,7 @@
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.14.0';
4
5
  export * from './v3.13.0';
5
6
  export * from './v3.12.3';
6
7
  export * from './v3.12.2';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/es/rewrite.js ADDED
@@ -0,0 +1,59 @@
1
+ import defaults from 'lodash/fp/defaults';
2
+ const rewriteSchemaCache = new Map();
3
+
4
+ function getRewriteCache(options) {
5
+ // Ensure key order does not invalidate the cache
6
+ const key = JSON.stringify(options, Object.keys(options).sort());
7
+ let cache = rewriteSchemaCache.get(key);
8
+
9
+ if (!cache) {
10
+ cache = new WeakMap();
11
+ rewriteSchemaCache.set(key, cache);
12
+ }
13
+
14
+ return cache;
15
+ }
16
+ /**
17
+ * Rewrite a schema, applying optional modifications.
18
+ */
19
+ // eslint-disable-next-line @typescript-eslint/ban-types
20
+
21
+
22
+ export function rewriteSchema(schema, options) {
23
+ const rewriteCache = getRewriteCache(defaults({
24
+ removeDefault: false,
25
+ removeRequired: false,
26
+ replaceInput: false
27
+ }, options));
28
+ let rewrittenSchema = rewriteCache.get(schema);
29
+
30
+ if (rewrittenSchema) {
31
+ return rewrittenSchema;
32
+ }
33
+
34
+ rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
35
+ if (typeof value === 'object') {
36
+ var _value$required;
37
+
38
+ // Remove required
39
+ if (options.removeRequired && (_value$required = value.required) !== null && _value$required !== void 0 && _value$required.length) {
40
+ delete value.required;
41
+ } // Remove default
42
+
43
+
44
+ if (options.removeDefault && value.type !== undefined && value.default !== undefined) {
45
+ delete value.default;
46
+ }
47
+
48
+ if (options.replaceInput && value['@input']) {
49
+ return { ...value['@input'],
50
+ '@mapping': value['@mapping']
51
+ };
52
+ }
53
+ }
54
+
55
+ return value;
56
+ });
57
+ rewriteCache.set(schema, rewrittenSchema);
58
+ return rewrittenSchema;
59
+ }
@@ -1,8 +1,9 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.13.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.14.0';
3
3
  export { default as anyProjectSchema } from './project-schema.json';
4
- export { default as latestSchemaJson } from './project-schema/v3.13.0.json';
4
+ export { default as latestSchemaJson } from './project-schema/v3.14.0.json';
5
5
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
6
+ import projectSchemaV3_14_0 from './project-schema/v3.14.0.json';
6
7
  import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
7
8
  import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
8
9
  import projectSchemaV3_12_2 from './project-schema/v3.12.2.json';
@@ -34,4 +35,4 @@ import projectSchemaV3_0_0 from './project-schema/v3.0.0.json';
34
35
  import metaSchemaV3_0_0 from './project-schema/meta-schema-v3.0.0.json';
35
36
  import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
36
37
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
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];
38
+ export const allProjectSchemas = [projectSchemaV4_0_0, projectSchemaV3_14_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,9 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.13.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.14.0';
3
3
  export {default as anyProjectSchema} from './project-schema.json';
4
- export {default as latestSchemaJson} from './project-schema/v3.13.0.json';
4
+ export {default as latestSchemaJson} from './project-schema/v3.14.0.json';
5
5
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
6
+ import projectSchemaV3_14_0 from './project-schema/v3.14.0.json';
6
7
  import projectSchemaV3_13_0 from './project-schema/v3.13.0.json';
7
8
  import projectSchemaV3_12_3 from './project-schema/v3.12.3.json';
8
9
  import projectSchemaV3_12_2 from './project-schema/v3.12.2.json';
@@ -36,6 +37,7 @@ import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
36
37
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
37
38
  export const allProjectSchemas = [
38
39
  projectSchemaV4_0_0,
40
+ projectSchemaV3_14_0,
39
41
  projectSchemaV3_13_0,
40
42
  projectSchemaV3_12_3,
41
43
  projectSchemaV3_12_2,