@takeshape/schema 9.80.4 → 9.81.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 (189) hide show
  1. package/dist/api-version.js +0 -9
  2. package/dist/builtin-schema.js +0 -5
  3. package/dist/content-schema-transform.js +4 -52
  4. package/dist/create-input-schema.js +7 -19
  5. package/dist/enum.js +0 -3
  6. package/dist/flatten-templates.js +0 -11
  7. package/dist/get-is-leaf.js +8 -18
  8. package/dist/index.js +0 -58
  9. package/dist/interfaces.js +2 -26
  10. package/dist/layers/layers.js +23 -103
  11. package/dist/layers/refs.js +26 -69
  12. package/dist/layers/type-utils.js +11 -43
  13. package/dist/layers/visitor.js +0 -6
  14. package/dist/migration/index.js +0 -51
  15. package/dist/migration/to/v3.0.0.js +31 -45
  16. package/dist/migration/to/v3.1.0.js +15 -41
  17. package/dist/migration/to/v3.10.0.js +6 -20
  18. package/dist/migration/to/v3.11.0.js +8 -20
  19. package/dist/migration/to/v3.12.0.js +2 -3
  20. package/dist/migration/to/v3.12.1.js +2 -3
  21. package/dist/migration/to/v3.12.2.js +2 -3
  22. package/dist/migration/to/v3.12.3.js +16 -21
  23. package/dist/migration/to/v3.13.0.js +2 -7
  24. package/dist/migration/to/v3.14.0.js +2 -3
  25. package/dist/migration/to/v3.15.0.js +2 -3
  26. package/dist/migration/to/v3.16.0.js +2 -3
  27. package/dist/migration/to/v3.17.0.js +4 -9
  28. package/dist/migration/to/v3.17.1.js +2 -3
  29. package/dist/migration/to/v3.18.0.js +2 -15
  30. package/dist/migration/to/v3.18.1.js +2 -7
  31. package/dist/migration/to/v3.18.2.js +8 -10
  32. package/dist/migration/to/v3.19.0.js +2 -3
  33. package/dist/migration/to/v3.2.0.js +2 -3
  34. package/dist/migration/to/v3.20.0.js +10 -11
  35. package/dist/migration/to/v3.21.0.js +2 -3
  36. package/dist/migration/to/v3.22.0.js +4 -9
  37. package/dist/migration/to/v3.23.0.js +2 -3
  38. package/dist/migration/to/v3.24.0.js +2 -3
  39. package/dist/migration/to/v3.25.0.js +2 -3
  40. package/dist/migration/to/v3.26.0.js +2 -3
  41. package/dist/migration/to/v3.27.0.js +2 -3
  42. package/dist/migration/to/v3.28.0.js +2 -3
  43. package/dist/migration/to/v3.29.0.js +2 -3
  44. package/dist/migration/to/v3.3.0.js +3 -4
  45. package/dist/migration/to/v3.30.0.js +2 -3
  46. package/dist/migration/to/v3.31.0.js +2 -12
  47. package/dist/migration/to/v3.32.0.js +12 -22
  48. package/dist/migration/to/v3.33.0.js +2 -3
  49. package/dist/migration/to/v3.34.0.js +14 -43
  50. package/dist/migration/to/v3.35.0.js +2 -3
  51. package/dist/migration/to/v3.36.0.js +6 -10
  52. package/dist/migration/to/v3.37.0.js +2 -3
  53. package/dist/migration/to/v3.38.0.js +2 -3
  54. package/dist/migration/to/v3.39.0.js +6 -13
  55. package/dist/migration/to/v3.4.0.js +2 -3
  56. package/dist/migration/to/v3.5.0.js +2 -3
  57. package/dist/migration/to/v3.5.1.js +2 -3
  58. package/dist/migration/to/v3.6.0.js +2 -3
  59. package/dist/migration/to/v3.7.0.js +2 -3
  60. package/dist/migration/to/v3.8.0.js +2 -3
  61. package/dist/migration/to/v3.9.0.js +8 -24
  62. package/dist/migration/utils.js +0 -2
  63. package/dist/mocks.js +9 -12
  64. package/dist/models/project-schema.js +0 -34
  65. package/dist/models/query.js +0 -9
  66. package/dist/models/service.js +0 -8
  67. package/dist/models/shape.js +0 -29
  68. package/dist/project-schema/index.js +1 -105
  69. package/dist/project-schema/migrate.js +1 -54
  70. package/dist/refs.js +39 -159
  71. package/dist/relationships.js +13 -57
  72. package/dist/scalars.js +0 -1
  73. package/dist/schema-transform.js +0 -11
  74. package/dist/schema-util.js +75 -271
  75. package/dist/schemas/index.js +0 -64
  76. package/dist/services.js +24 -44
  77. package/dist/taxonomies.js +0 -13
  78. package/dist/template-shapes/index.js +1 -8
  79. package/dist/template-shapes/templates.js +9 -40
  80. package/dist/template-shapes/types.js +4 -5
  81. package/dist/template-shapes/where.js +14 -110
  82. package/dist/types/index.js +0 -4
  83. package/dist/types/types.js +41 -13
  84. package/dist/types/utils.js +15 -89
  85. package/dist/unions.js +8 -38
  86. package/dist/util/api-indexing.js +2 -19
  87. package/dist/util/detect-cycles.js +2 -16
  88. package/dist/util/find-shape-at-path.js +1 -15
  89. package/dist/util/form-config.js +6 -23
  90. package/dist/util/get-conflicting-properties.js +7 -17
  91. package/dist/util/get-return-shape.js +0 -11
  92. package/dist/util/has-arg.js +0 -6
  93. package/dist/util/index.js +0 -18
  94. package/dist/util/merge.js +28 -74
  95. package/dist/util/patch-schema.js +5 -13
  96. package/dist/validate.js +15 -234
  97. package/dist/versions.js +0 -2
  98. package/dist/workflows.js +0 -15
  99. package/es/api-version.js +0 -4
  100. package/es/content-schema-transform.js +4 -38
  101. package/es/create-input-schema.js +7 -14
  102. package/es/enum.js +0 -2
  103. package/es/flatten-templates.js +0 -4
  104. package/es/get-is-leaf.js +8 -13
  105. package/es/index.js +1 -0
  106. package/es/interfaces.js +2 -14
  107. package/es/layers/layers.js +23 -90
  108. package/es/layers/refs.js +22 -45
  109. package/es/layers/type-utils.js +11 -16
  110. package/es/layers/visitor.js +0 -3
  111. package/es/migration/to/v3.0.0.js +31 -38
  112. package/es/migration/to/v3.1.0.js +16 -34
  113. package/es/migration/to/v3.10.0.js +6 -17
  114. package/es/migration/to/v3.11.0.js +8 -18
  115. package/es/migration/to/v3.12.0.js +2 -2
  116. package/es/migration/to/v3.12.1.js +2 -2
  117. package/es/migration/to/v3.12.2.js +2 -2
  118. package/es/migration/to/v3.12.3.js +16 -19
  119. package/es/migration/to/v3.13.0.js +2 -4
  120. package/es/migration/to/v3.14.0.js +2 -2
  121. package/es/migration/to/v3.15.0.js +2 -2
  122. package/es/migration/to/v3.16.0.js +2 -2
  123. package/es/migration/to/v3.17.0.js +4 -4
  124. package/es/migration/to/v3.17.1.js +2 -2
  125. package/es/migration/to/v3.18.0.js +2 -10
  126. package/es/migration/to/v3.18.1.js +2 -3
  127. package/es/migration/to/v3.18.2.js +8 -8
  128. package/es/migration/to/v3.19.0.js +2 -2
  129. package/es/migration/to/v3.2.0.js +2 -2
  130. package/es/migration/to/v3.20.0.js +10 -9
  131. package/es/migration/to/v3.21.0.js +2 -2
  132. package/es/migration/to/v3.22.0.js +4 -6
  133. package/es/migration/to/v3.23.0.js +2 -2
  134. package/es/migration/to/v3.24.0.js +2 -2
  135. package/es/migration/to/v3.25.0.js +2 -2
  136. package/es/migration/to/v3.26.0.js +2 -2
  137. package/es/migration/to/v3.27.0.js +2 -2
  138. package/es/migration/to/v3.28.0.js +2 -2
  139. package/es/migration/to/v3.29.0.js +2 -2
  140. package/es/migration/to/v3.3.0.js +3 -3
  141. package/es/migration/to/v3.30.0.js +2 -2
  142. package/es/migration/to/v3.31.0.js +2 -5
  143. package/es/migration/to/v3.32.0.js +12 -21
  144. package/es/migration/to/v3.33.0.js +2 -2
  145. package/es/migration/to/v3.34.0.js +16 -32
  146. package/es/migration/to/v3.35.0.js +2 -2
  147. package/es/migration/to/v3.36.0.js +6 -8
  148. package/es/migration/to/v3.37.0.js +2 -2
  149. package/es/migration/to/v3.38.0.js +2 -2
  150. package/es/migration/to/v3.39.0.js +6 -12
  151. package/es/migration/to/v3.4.0.js +2 -2
  152. package/es/migration/to/v3.5.0.js +2 -2
  153. package/es/migration/to/v3.5.1.js +2 -2
  154. package/es/migration/to/v3.6.0.js +2 -2
  155. package/es/migration/to/v3.7.0.js +2 -2
  156. package/es/migration/to/v3.8.0.js +2 -2
  157. package/es/migration/to/v3.9.0.js +8 -20
  158. package/es/mocks.js +10 -6
  159. package/es/models/project-schema.js +0 -26
  160. package/es/models/query.js +0 -7
  161. package/es/models/service.js +0 -6
  162. package/es/models/shape.js +1 -25
  163. package/es/project-schema/index.js +0 -5
  164. package/es/project-schema/migrate.js +3 -51
  165. package/es/refs.js +40 -96
  166. package/es/relationships.js +14 -42
  167. package/es/schema-transform.js +0 -7
  168. package/es/schema-util.js +75 -180
  169. package/es/services.js +18 -27
  170. package/es/taxonomies.js +0 -9
  171. package/es/template-shapes/index.js +1 -4
  172. package/es/template-shapes/templates.js +9 -18
  173. package/es/template-shapes/types.js +3 -4
  174. package/es/template-shapes/where.js +14 -94
  175. package/es/types/types.js +43 -10
  176. package/es/types/utils.js +16 -24
  177. package/es/unions.js +8 -22
  178. package/es/util/api-indexing.js +2 -12
  179. package/es/util/detect-cycles.js +2 -14
  180. package/es/util/find-shape-at-path.js +2 -12
  181. package/es/util/form-config.js +7 -19
  182. package/es/util/get-conflicting-properties.js +8 -14
  183. package/es/util/get-return-shape.js +0 -8
  184. package/es/util/has-arg.js +0 -3
  185. package/es/util/merge.js +28 -55
  186. package/es/util/patch-schema.js +5 -7
  187. package/es/validate.js +15 -194
  188. package/es/workflows.js +0 -6
  189. package/package.json +5 -5
package/dist/versions.js CHANGED
@@ -11,9 +11,7 @@ Object.defineProperty(exports, "CURRENT_SCHEMA_VERSION", {
11
11
  }
12
12
  });
13
13
  exports.LEGACY_SCHEMA_VERSION = exports.LEGACY_API_VERSION = void 0;
14
-
15
14
  var _schemas = require("./schemas");
16
-
17
15
  const LEGACY_SCHEMA_VERSION = '1.0.0';
18
16
  exports.LEGACY_SCHEMA_VERSION = LEGACY_SCHEMA_VERSION;
19
17
  const CURRENT_API_VERSION = '2';
package/dist/workflows.js CHANGED
@@ -11,9 +11,7 @@ exports.getStepRange = getStepRange;
11
11
  exports.getWorkflow = getWorkflow;
12
12
  exports.getWorkflowStepKeys = getWorkflowStepKeys;
13
13
  exports.statusFallback = statusFallback;
14
-
15
14
  var _schemaUtil = require("./schema-util");
16
-
17
15
  const defaultWorkflow = {
18
16
  name: 'default',
19
17
  title: 'Default',
@@ -32,23 +30,17 @@ const defaultWorkflow = {
32
30
  }]
33
31
  };
34
32
  exports.defaultWorkflow = defaultWorkflow;
35
-
36
33
  function getWorkflow(projectSchema, shapeId) {
37
34
  var _getShapeById;
38
-
39
35
  const workflow = (_getShapeById = (0, _schemaUtil.getShapeById)(projectSchema, shapeId)) === null || _getShapeById === void 0 ? void 0 : _getShapeById.workflow;
40
-
41
36
  if (workflow) {
42
37
  return projectSchema.workflows[workflow] ?? defaultWorkflow;
43
38
  }
44
-
45
39
  return defaultWorkflow;
46
40
  }
47
-
48
41
  function statusFallback(workflow, enabled) {
49
42
  return workflow.steps.find(workflow => workflow.live === enabled) ?? workflow.steps[0];
50
43
  }
51
-
52
44
  function findWorkflowStep(workflow, keyOrName) {
53
45
  const index = workflow.steps.findIndex(workflow => workflow.key === keyOrName || workflow.name === keyOrName);
54
46
  return index === -1 ? undefined : {
@@ -56,7 +48,6 @@ function findWorkflowStep(workflow, keyOrName) {
56
48
  step: workflow.steps[index]
57
49
  };
58
50
  }
59
-
60
51
  function getStatusField(workflows, shape) {
61
52
  const workflow = shape.workflow && workflows[shape.workflow] || defaultWorkflow;
62
53
  return {
@@ -65,31 +56,25 @@ function getStatusField(workflows, shape) {
65
56
  '@workflow': workflow.name
66
57
  };
67
58
  }
68
-
69
59
  function getStepRange(steps, index, op) {
70
60
  if (op === 'eq' || op === 'in') {
71
61
  return [steps[index]];
72
62
  }
73
-
74
63
  const offset = op === 'lte' || op === 'gte' ? 0 : 1;
75
64
  const start = op === 'gt' || op === 'gte' ? index + offset : 0;
76
65
  const end = op === 'lt' || op === 'lte' ? index + 1 - offset : steps.length;
77
66
  return steps.slice(start, end);
78
67
  }
79
-
80
68
  function getWorkflowStepKeys(workflow, stepKey, op) {
81
69
  const context = findWorkflowStep(workflow, stepKey);
82
-
83
70
  if (!context) {
84
71
  throw new Error(`Cannot find step "${stepKey}" in workflow "${workflow.title}"`);
85
72
  }
86
-
87
73
  const {
88
74
  index
89
75
  } = context;
90
76
  return getStepRange(workflow.steps, index, op).map(step => step.key);
91
77
  }
92
-
93
78
  function getLiveStepKeys(workflow) {
94
79
  return workflow.steps.filter(step => step.live).map(step => step.key);
95
80
  }
package/es/api-version.js CHANGED
@@ -2,18 +2,14 @@ import gte from 'semver/functions/gte';
2
2
  import coerce from 'semver/functions/coerce';
3
3
  export const createVersionPredicate = (featureVersion, comparison) => {
4
4
  const coercedFeatureVersion = coerce(featureVersion);
5
-
6
5
  if (!coercedFeatureVersion) {
7
6
  throw new Error(`Could not create predicate version "${featureVersion}" is not valid`);
8
7
  }
9
-
10
8
  return apiVersion => {
11
9
  const coercedApiVersion = coerce(apiVersion);
12
-
13
10
  if (!coercedApiVersion) {
14
11
  throw new Error(`Version "${apiVersion}" is not valid and could not be coerced`);
15
12
  }
16
-
17
13
  return comparison(coercedApiVersion, coercedFeatureVersion);
18
14
  };
19
15
  };
@@ -8,34 +8,28 @@ import { enumerateOneOfKeys, isUnionSchema } from './unions';
8
8
  const typeCache = new WeakMap();
9
9
  export function getType(schema) {
10
10
  let type = typeCache.get(schema);
11
-
12
11
  if (type) {
13
12
  return type;
14
13
  }
14
+ type = schema.type;
15
15
 
16
- type = schema.type; // Handle nullable types for example: ['object', 'null']
17
-
16
+ // Handle nullable types for example: ['object', 'null']
18
17
  if (Array.isArray(type)) {
19
18
  const filtered = type.filter(name => name !== 'null');
20
-
21
19
  if (!filtered.length) {
22
20
  throw new Error(`Invalid schema`);
23
21
  }
24
-
25
22
  type = filtered[0];
26
23
  }
27
-
28
24
  typeCache.set(schema, type);
29
25
  return type;
30
26
  }
31
27
  export function toName(name) {
32
28
  return name;
33
29
  }
34
-
35
30
  function ensureArray(value) {
36
31
  return Array.isArray(value) ? value : [value];
37
32
  }
38
-
39
33
  export function preferKey(name, schema) {
40
34
  return getStorageKey(schema) ?? name;
41
35
  }
@@ -45,12 +39,10 @@ export function preferSourceKey(name, schema) {
45
39
  }
46
40
  export function findTransforms(pluginMap, schema, name, shape) {
47
41
  const type = getType(schema);
48
-
49
42
  if (pluginMap && (pluginMap[type] || pluginMap['*'])) {
50
43
  const plugins = (pluginMap[type] ?? []).concat(pluginMap['*'] ?? []);
51
44
  return plugins.find(plugin => plugin.filter(schema, name, shape));
52
45
  }
53
-
54
46
  return undefined;
55
47
  }
56
48
  export function getContentTransform({
@@ -65,22 +57,17 @@ export function getContentTransform({
65
57
  const prepare = (schema, obj, name = '') => {
66
58
  const shapeName = getRefShapeName(projectSchema, schema);
67
59
  schema = dereferenceSchema(projectSchema, schema);
68
-
69
60
  if (accumulators) {
70
61
  accumulators.forEach(accumulator => {
71
62
  accumulator.accumulate(obj, schema, name);
72
63
  });
73
64
  }
74
-
75
65
  const shape = shapeName ? projectSchema.shapes[shapeName] : undefined;
76
66
  const transform = findTransforms(transforms, schema, name, shape);
77
-
78
67
  if (transform) {
79
68
  const next = (value, schema, name) => prepare(schema, value, name);
80
-
81
69
  return transform.process(obj, schema, name, shape, next);
82
70
  }
83
-
84
71
  if (obj && isUnionSchema(schema)) {
85
72
  for (const {
86
73
  shapeId,
@@ -91,16 +78,13 @@ export function getContentTransform({
91
78
  }
92
79
  }
93
80
  }
94
-
95
81
  if (obj && isObjectSchema(schema)) {
96
82
  const result = {};
97
83
  const assigned = new Set();
98
84
  forEach(schema.properties, (fieldSchema, name) => {
99
85
  const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema, obj));
100
-
101
86
  for (const sourceKey of sourceKeys) {
102
87
  const value = prepare(fieldSchema, obj === null || obj === void 0 ? void 0 : obj[sourceKey], name);
103
-
104
88
  if (value !== undefined) {
105
89
  assigned.add(sourceKey);
106
90
  const transform = findTransforms(transforms, dereferenceSchema(projectSchema, fieldSchema), name);
@@ -109,51 +93,39 @@ export function getContentTransform({
109
93
  }
110
94
  }
111
95
  });
112
-
113
96
  if (passThrough && obj) {
114
97
  const keys = difference(Object.keys(obj), [...assigned]);
115
-
116
98
  if (keys.length) {
117
99
  Object.assign(result, pick(obj, keys));
118
100
  }
119
101
  }
120
-
121
102
  return result;
122
103
  }
123
-
124
104
  if (isArraySchema(schema)) {
125
105
  const itemSchema = schema.items;
126
-
127
106
  if (Array.isArray(obj)) {
128
107
  return obj.map(item => prepare(itemSchema, item, name));
129
108
  }
130
-
131
109
  if (obj === undefined) {
132
110
  prepare(itemSchema, obj, name);
133
111
  }
134
112
  }
135
-
136
113
  if (allowNullObjects && isObjectSchema(schema) && obj === null) {
137
114
  return null;
138
- } // Allow properties that have not been transformed
139
-
115
+ }
140
116
 
117
+ // Allow properties that have not been transformed
141
118
  return passThrough ? obj : undefined;
142
119
  };
143
-
144
120
  return prepare;
145
121
  }
146
-
147
122
  function transformKey(transforms, propSchema, name, transform = preferKey) {
148
123
  const schemaTransform = findTransforms(transforms, propSchema, name);
149
-
150
124
  if (schemaTransform !== null && schemaTransform !== void 0 && schemaTransform.keyTransform) {
151
125
  transform = schemaTransform.keyTransform;
152
126
  }
153
-
154
127
  return transform(name, propSchema);
155
128
  }
156
-
157
129
  export function getPropertyInfo(context, schema, path) {
158
130
  const {
159
131
  projectSchema,
@@ -161,21 +133,16 @@ export function getPropertyInfo(context, schema, path) {
161
133
  keyTransform
162
134
  } = context;
163
135
  const result = [];
164
-
165
136
  const findProperty = (currentSchema, name, rest, path) => {
166
137
  if (isObjectSchema(currentSchema)) {
167
138
  var _currentSchema$requir;
168
-
169
139
  const propSchema = currentSchema.properties[name];
170
140
  const isRequired = ((_currentSchema$requir = currentSchema.required) === null || _currentSchema$requir === void 0 ? void 0 : _currentSchema$requir.includes(name)) ?? false;
171
-
172
141
  if (!propSchema) {
173
142
  return;
174
143
  }
175
-
176
144
  const refSchema = dereferenceSchema(projectSchema, propSchema);
177
145
  const nextPath = path.concat(transformKey(transforms, refSchema, name, keyTransform));
178
-
179
146
  if (rest.length) {
180
147
  const [nextName, ...nextRest] = rest;
181
148
  findProperty(refSchema, nextName, nextRest, nextPath);
@@ -194,7 +161,6 @@ export function getPropertyInfo(context, schema, path) {
194
161
  findProperty(dereferenceSchema(projectSchema, currentSchema.items), name, rest, path);
195
162
  }
196
163
  };
197
-
198
164
  const [first, ...rest] = path.split('.');
199
165
  findProperty(dereferenceSchema(projectSchema, schema), first, rest, []);
200
166
  return result;
@@ -2,53 +2,46 @@ import defaults from 'lodash/fp/defaults';
2
2
  import { isRecord } from '@takeshape/util';
3
3
  import omitBy from 'lodash/omitBy';
4
4
  const inputSchemaCache = new Map();
5
-
6
5
  function getInputSchemaCache(options) {
7
6
  // Ensure key order does not invalidate the cache
8
7
  const key = JSON.stringify(options, Object.keys(options).sort());
9
8
  let cache = inputSchemaCache.get(key);
10
-
11
9
  if (!cache) {
12
10
  cache = new WeakMap();
13
11
  inputSchemaCache.set(key, cache);
14
12
  }
15
-
16
13
  return cache;
17
14
  }
15
+
18
16
  /**
19
17
  * Convert all output properties in the schema to be input properties,
20
18
  * For an update, remove `required` and `default` fields as well.
21
19
  */
22
-
23
-
24
20
  export function createInputSchema(schema, options = {}) {
25
21
  const inputSchemaCache = getInputSchemaCache(defaults({
26
22
  isUpdate: false
27
23
  }, options));
28
24
  let rewrittenSchema = inputSchemaCache.get(schema);
29
-
30
25
  if (rewrittenSchema) {
31
26
  return rewrittenSchema;
32
27
  }
33
-
34
28
  rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
35
29
  if (isRecord(value)) {
36
30
  // Remove required
37
31
  if (options.isUpdate && Array.isArray(value.required) && value.required.length) {
38
32
  delete value.required;
39
- } // Remove default
40
-
33
+ }
41
34
 
35
+ // Remove default
42
36
  if (options.isUpdate && value.type !== undefined && value.default !== undefined) {
43
37
  delete value.default;
44
38
  }
45
-
46
39
  if (value.type === 'object' && isRecord(value.properties)) {
47
- return { ...value,
40
+ return {
41
+ ...value,
48
42
  properties: omitBy(value.properties, prop => isRecord(prop) && prop['@resolver'] && !prop['@input'])
49
43
  };
50
44
  }
51
-
52
45
  if (isRecord(value['@input'])) {
53
46
  const {
54
47
  '@input': input,
@@ -58,7 +51,8 @@ export function createInputSchema(schema, options = {}) {
58
51
  title,
59
52
  ...output
60
53
  } = value;
61
- return { ...input,
54
+ return {
55
+ ...input,
62
56
  title,
63
57
  '@l10n': l10n,
64
58
  '@syncLocaleStructure': syncLocaleStructure,
@@ -67,7 +61,6 @@ export function createInputSchema(schema, options = {}) {
67
61
  };
68
62
  }
69
63
  }
70
-
71
64
  return value;
72
65
  });
73
66
  inputSchemaCache.set(schema, rewrittenSchema);
package/es/enum.js CHANGED
@@ -2,10 +2,8 @@ export function isEnumLikeSchema(schema) {
2
2
  if (schema.enum) {
3
3
  return true;
4
4
  }
5
-
6
5
  if (schema.oneOf) {
7
6
  return schema.oneOf.every(optionSchema => optionSchema.title !== undefined && (optionSchema.enum || optionSchema.const));
8
7
  }
9
-
10
8
  return false;
11
9
  }
@@ -5,13 +5,10 @@ import { deepClone } from '@takeshape/util';
5
5
  import { refItemToShapeName } from './refs';
6
6
  export function flattenTemplates(projectSchema) {
7
7
  const templateRefs = getAllRefs(projectSchema, ref => Boolean(ref.template));
8
-
9
8
  if (!templateRefs.length) {
10
9
  return projectSchema;
11
10
  }
12
-
13
11
  const newSchema = deepClone(projectSchema);
14
-
15
12
  for (const ref of templateRefs) {
16
13
  if (ref.template && isValidTemplate(ref.template)) {
17
14
  const {
@@ -22,6 +19,5 @@ export function flattenTemplates(projectSchema) {
22
19
  Object.assign(newSchema.shapes, dependencies);
23
20
  }
24
21
  }
25
-
26
22
  return newSchema;
27
23
  }
package/es/get-is-leaf.js CHANGED
@@ -3,40 +3,36 @@ import { getStorageKey, isBuiltinType } from './schema-util';
3
3
  import { followRef, getRefShapeName } from './refs';
4
4
  import { isPropertySchemaWithRelationship } from './types';
5
5
  const scalarTags = new Set(['draftjs']);
6
-
7
6
  function isLeafTypeV3(projectSchema, propertySchema) {
8
7
  const type = getType(propertySchema);
9
- return Boolean( // Must have key
10
- getStorageKey(propertySchema) && ( // If is not a structure, then is a leaf
11
- !['object', 'array'].includes(type) || // If is relationship, then is a leaf
12
- isPropertySchemaWithRelationship(propertySchema['@output'] ?? propertySchema) || propertySchema['@tag'] && scalarTags.has(propertySchema['@tag']) || // If is array, then should not be a synchronized structure
8
+ return Boolean(
9
+ // Must have key
10
+ getStorageKey(propertySchema) && (
11
+ // If is not a structure, then is a leaf
12
+ !['object', 'array'].includes(type) ||
13
+ // If is relationship, then is a leaf
14
+ isPropertySchemaWithRelationship(propertySchema['@output'] ?? propertySchema) || propertySchema['@tag'] && scalarTags.has(propertySchema['@tag']) ||
15
+ // If is array, then should not be a synchronized structure
13
16
  type === 'array' && !propertySchema['@syncLocaleStructure'] || isBuiltinType(projectSchema, propertySchema)));
14
17
  }
15
-
16
18
  export function getIsLeaf(projectSchema, shapeSchema) {
17
19
  const leafMap = new Set();
18
20
  const shapesSeen = new Set();
19
-
20
21
  const collectLeaves = schema => {
21
22
  const shapeName = getRefShapeName(projectSchema, schema);
22
23
  schema = shapeName ? followRef(projectSchema, schema) : schema;
23
24
  const key = getStorageKey(schema);
24
-
25
25
  if (key && isLeafTypeV3(projectSchema, schema)) {
26
26
  leafMap.add(key);
27
27
  }
28
-
29
28
  if (shapeName) {
30
29
  // Skip shapes we have already seen to avoid cycles
31
30
  if (shapesSeen.has(shapeName)) {
32
31
  return;
33
32
  }
34
-
35
33
  shapesSeen.add(shapeName);
36
34
  }
37
-
38
35
  const combo = schema.oneOf ?? schema.allOf;
39
-
40
36
  if (combo) {
41
37
  combo.map(collectLeaves);
42
38
  } else if (schema.properties) {
@@ -47,7 +43,6 @@ export function getIsLeaf(projectSchema, shapeSchema) {
47
43
  collectLeaves(schema.items);
48
44
  }
49
45
  };
50
-
51
46
  collectLeaves(shapeSchema);
52
47
  return key => {
53
48
  // Remove locale suffix
package/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Only export User here since AccessPolicyDocument is in auth-schemas
2
+
2
3
  export * from './content-schema-transform';
3
4
  export * from './get-is-leaf';
4
5
  export * from './project-schema';
package/es/interfaces.js CHANGED
@@ -9,7 +9,6 @@ export function isInterfaceRef(context, propertySchema) {
9
9
  const ref = getRef(context, propertySchema);
10
10
  return Boolean(ref && isInterfaceShape(refItemToShape(context, ref)));
11
11
  }
12
-
13
12
  function add(record, key, value) {
14
13
  if (!record[key]) {
15
14
  record[key] = new Set([value]);
@@ -17,19 +16,15 @@ function add(record, key, value) {
17
16
  record[key].add(value);
18
17
  }
19
18
  }
20
-
21
19
  function getImplementationsHelper(shapeMap, mapFn) {
22
20
  const result = {};
23
-
24
21
  for (const shape of Object.values(shapeMap)) {
25
22
  for (const interfaceName of shape.interfaces ?? []) {
26
23
  add(result, interfaceName, mapFn(shape));
27
24
  }
28
25
  }
29
-
30
26
  return result;
31
27
  }
32
-
33
28
  export function getImplementationShapeMap(shapeMap) {
34
29
  return getImplementationsHelper(shapeMap, x => x);
35
30
  }
@@ -41,31 +36,26 @@ export function pruneUnusedInterfaces(shapeMap) {
41
36
  const {
42
37
  interfaces
43
38
  } = shape;
44
-
45
39
  if (interfaces !== null && interfaces !== void 0 && interfaces.length) {
46
40
  const filteredInterfaces = interfaces.filter(name => shapeMap[name]);
47
-
48
41
  if (interfaces.length !== filteredInterfaces.length) {
49
- return { ...shape,
42
+ return {
43
+ ...shape,
50
44
  interfaces: filteredInterfaces
51
45
  };
52
46
  }
53
47
  }
54
-
55
48
  return shape;
56
49
  });
57
50
  }
58
51
  export function getImplementingShapes(shapeMap, interfaceName) {
59
52
  const implementingShapes = [];
60
-
61
53
  for (const shape of Object.values(shapeMap)) {
62
54
  var _shape$interfaces;
63
-
64
55
  if ((_shape$interfaces = shape.interfaces) !== null && _shape$interfaces !== void 0 && _shape$interfaces.includes(interfaceName)) {
65
56
  implementingShapes.push(shape);
66
57
  }
67
58
  }
68
-
69
59
  return implementingShapes;
70
60
  }
71
61
  export function interfaceToUnion(context, interfaceName) {
@@ -78,7 +68,6 @@ export function interfaceToUnion(context, interfaceName) {
78
68
  }
79
69
  export function getPossibleShapeNames(projectSchema, shape) {
80
70
  let names;
81
-
82
71
  if (isInterfaceShape(shape)) {
83
72
  names = getImplementingShapes(projectSchema.shapes, shape.name).map(shape => shape.name);
84
73
  } else if (isUnionSchema(shape.schema)) {
@@ -89,6 +78,5 @@ export function getPossibleShapeNames(projectSchema, shape) {
89
78
  } else {
90
79
  names = [shape.name];
91
80
  }
92
-
93
81
  return names;
94
82
  }