@takeshape/schema 9.80.3 → 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
@@ -11,45 +11,34 @@ import { isObjectSchema, isPropertySchemaWithRelationship } from '../types/utils
11
11
  import { isEqualRelationship, getRelationship, getRelationshipShapes } from '../relationships';
12
12
  export const MAX_RELATIONSHIP_DEPTH = 1;
13
13
  export const exceededRelationshipDepth = (depth = 0) => depth >= MAX_RELATIONSHIP_DEPTH;
14
-
15
14
  class ShapeCache {
16
15
  thunks = new Map();
17
16
  unresolved = new Set();
18
-
19
17
  has(shapeName) {
20
18
  return this.thunks.has(shapeName);
21
19
  }
22
-
23
20
  set(shapeName, thunk) {
24
21
  this.thunks.set(shapeName, thunk);
25
-
26
22
  if (isFunction(thunk)) {
27
23
  this.unresolved.add(shapeName);
28
24
  }
29
25
  }
30
-
31
26
  resolveAll() {
32
27
  while (this.unresolved.size) {
33
28
  const shapeName = this.unresolved.values().next().value;
34
29
  const thunk = this.thunks.get(shapeName);
35
-
36
30
  if (isFunction(thunk)) {
37
31
  this.thunks.set(shapeName, thunk());
38
32
  this.unresolved.delete(shapeName);
39
33
  }
40
34
  }
41
-
42
35
  const result = {};
43
-
44
36
  for (const [shapeName, shape] of this.thunks) {
45
37
  result[shapeName] = shape;
46
38
  }
47
-
48
39
  return result;
49
40
  }
50
-
51
41
  }
52
-
53
42
  export const fieldTypeComparison = {
54
43
  id: {
55
44
  comparators: ['eq', 'in'],
@@ -104,39 +93,31 @@ export const boolOpDescriptionMap = {
104
93
  OR: 'OR takes an array of conditions that should appear in the matching results. Nested boolean operators can be used to create complex filters.',
105
94
  NOT: 'NOT takes a single condition that must not appear in the matching results.'
106
95
  };
107
-
108
96
  function getConflictingProperties(projectSchema, shapes) {
109
97
  const conflicts = new Set();
110
98
  const allProps = {};
111
-
112
99
  for (const shape of Object.values(shapes)) {
113
100
  for (const [name, prop] of createSchemaPropertyList(projectSchema, shape).getNodes()) {
114
101
  if (name in allProps && (allProps[name].type !== prop.type || !isEqualRelationship(allProps[name], prop))) {
115
102
  conflicts.add(name);
116
103
  }
117
104
  }
118
-
119
105
  if (isObjectSchema(shape.schema)) {
120
106
  Object.assign(allProps, shape.schema.properties);
121
107
  }
122
108
  }
123
-
124
109
  return conflicts;
125
110
  }
126
-
127
111
  export function getFieldTypeComparison(fieldType) {
128
112
  const comparison = fieldTypeComparison[fieldType];
129
-
130
113
  if (!comparison) {
131
114
  return undefined;
132
115
  }
133
-
134
116
  const {
135
117
  comparators,
136
118
  type
137
119
  } = comparison;
138
120
  const result = {};
139
-
140
121
  for (const op of comparators) {
141
122
  const description = comparatorDescriptions[op];
142
123
  result[op] = op === 'in' ? {
@@ -150,73 +131,57 @@ export function getFieldTypeComparison(fieldType) {
150
131
  type
151
132
  };
152
133
  }
153
-
154
134
  return result;
155
135
  }
156
-
157
136
  function isId(name) {
158
137
  return name === '_id' || name === '_contentTypeId' || name === '_shapeId';
159
138
  }
160
-
161
139
  function isNonRelationshipRef(prop) {
162
140
  return Boolean(hasRefProperty(prop) && !getRelationship(prop));
163
141
  }
164
-
165
142
  function getPropType(projectSchema, name, prop) {
166
143
  if (prop['@workflow']) {
167
144
  return 'workflow';
168
145
  }
169
-
170
146
  if (prop['@tag'] === 'draftjs') {
171
147
  return 'draftjs';
172
148
  }
173
-
174
149
  if (prop['@tag'] === 'mdx') {
175
150
  return 'mdx';
176
151
  }
177
-
178
152
  if (prop.format === 'date-time') {
179
153
  return 'date';
180
154
  }
181
-
182
155
  if (isId(name)) {
183
156
  return 'id';
184
157
  }
185
-
186
158
  if (isNonRelationshipRef(prop)) {
187
159
  const followed = followRef(projectSchema, prop);
188
-
189
160
  if (followed.enum) {
190
161
  return 'string';
191
162
  }
192
-
193
163
  return 'object';
194
164
  }
195
-
196
165
  return prop.type;
197
166
  }
198
-
199
167
  function truncateNames(names) {
200
168
  // For unions of many types hash the names this reduces shape name size while still allowing reuse
201
169
  return names.length > 80 ? md5(names) : names;
202
170
  }
171
+
203
172
  /**
204
173
  * Get a formatted string of related shape names from a property schema with a
205
174
  * relationship resolver
206
175
  */
207
-
208
-
209
176
  function getRelationshipShapeName(refs) {
210
177
  return refs.map(ref => {
211
178
  const shapeName = ref.split(':')[1];
212
179
  return formatShapeName(shapeName);
213
180
  }).sort().join('');
214
181
  }
215
-
216
182
  function joinShapeNames(shapes) {
217
183
  return shapes.sort().join('');
218
184
  }
219
-
220
185
  function getTypeName(name, prop, shapeName, context) {
221
186
  const {
222
187
  projectSchema,
@@ -224,34 +189,26 @@ function getTypeName(name, prop, shapeName, context) {
224
189
  conflictingProperties
225
190
  } = context;
226
191
  let type = getPropType(projectSchema, name, prop);
227
-
228
192
  if (isId(name)) {
229
193
  return `TSWhereID`;
230
194
  }
231
-
232
195
  const relationship = getRelationship(prop);
233
-
234
196
  if (relationship) {
235
197
  const relationshipName = getRelationshipShapeName(relationship.refs);
236
-
237
198
  if (!relationshipName) {
238
199
  throw new Error(`Relationship property "${prop.title ?? ''}" is missing related shapes`);
239
200
  }
240
-
241
201
  const shapeNames = truncateNames(relationshipName);
242
202
  return `TSWhere${shapeNames}Relationship`;
243
203
  }
244
-
245
204
  if (isUnionSchema(prop)) {
246
205
  if (prop.oneOf.length > 1) {
247
206
  const shapeNames = truncateNames(joinShapeNames(enumerateOneOfKeys(projectSchema, prop.oneOf).map(child => child.shapeName)));
248
207
  return `TSWhere${shapeNames}Union`;
249
208
  }
250
-
251
209
  type = 'object';
252
210
  prop = prop.oneOf[0];
253
211
  }
254
-
255
212
  if (type === 'object' || type === 'array') {
256
213
  const prefix = `TS${relationshipDepth >= MAX_RELATIONSHIP_DEPTH ? 'Shallow' : ''}Where`;
257
214
  const fieldName = `${conflictingProperties !== null && conflictingProperties !== void 0 && conflictingProperties.has(name) ? '_' : ''}${formatShapeName(name)}`;
@@ -259,10 +216,8 @@ function getTypeName(name, prop, shapeName, context) {
259
216
  const suffix = refItem ? refItemToShapeName(refItem) : `${shapeName}${fieldName}`;
260
217
  return `${prefix}${suffix}`;
261
218
  }
262
-
263
219
  return `TSWhere${pascalCase(type)}`;
264
220
  }
265
-
266
221
  function skipField({
267
222
  name,
268
223
  prop,
@@ -273,7 +228,6 @@ function skipField({
273
228
  const isRelationship = isPropertySchemaWithRelationship(prop);
274
229
  return Boolean(prop['@sensitive'] || prop['@resolver'] && !isIndexedShape && !isRelationship || isRelationship && exceededRelationshipDepth || (name === '_enabled' || name === '_enabledAt') && workflowsEnabled);
275
230
  }
276
-
277
231
  export function getFields(typeName, shapes, context) {
278
232
  const {
279
233
  relationshipDepth,
@@ -283,10 +237,10 @@ export function getFields(typeName, shapes, context) {
283
237
  const result = {};
284
238
  const tooDeep = exceededRelationshipDepth(relationshipDepth);
285
239
  const conflictingProperties = shapes.length ? getConflictingProperties(projectSchema, shapes) : undefined;
286
- const fieldContext = { ...context,
240
+ const fieldContext = {
241
+ ...context,
287
242
  conflictingProperties
288
243
  };
289
-
290
244
  for (const shape of shapes) {
291
245
  const nodes = createSchemaPropertyList(projectSchema, shape).filterBy(([name, prop]) => !skipField({
292
246
  name,
@@ -295,18 +249,14 @@ export function getFields(typeName, shapes, context) {
295
249
  isIndexedShape: isCachedShape(shape),
296
250
  exceededRelationshipDepth: exceededRelationshipDepth(relationshipDepth)
297
251
  })).getNodes();
298
-
299
252
  for (const [name, property] of nodes) {
300
253
  Object.assign(result, getPropertyComparisonType(name, property, shape.name, fieldContext));
301
254
  }
302
255
  }
303
-
304
256
  return tooDeep || booleanOperators === false ? result : Object.assign(result, getBooleanOperatorTypes(typeName));
305
257
  }
306
-
307
258
  function getBooleanOperatorTypes(typeName) {
308
259
  const result = {};
309
-
310
260
  for (const op of booleanOperators) {
311
261
  const refSchema = {
312
262
  '@ref': `local:${typeName}`
@@ -316,10 +266,8 @@ function getBooleanOperatorTypes(typeName) {
316
266
  items: refSchema
317
267
  };
318
268
  }
319
-
320
269
  return result;
321
270
  }
322
-
323
271
  export function getPropertyComparisonType(name, prop, shapeName, context) {
324
272
  const {
325
273
  shapeCache,
@@ -327,7 +275,6 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
327
275
  relationshipDepth,
328
276
  conflictingProperties
329
277
  } = context;
330
-
331
278
  if (skipField({
332
279
  name,
333
280
  prop,
@@ -337,54 +284,49 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
337
284
  })) {
338
285
  return undefined;
339
286
  }
340
-
341
287
  const fieldType = getPropType(projectSchema, name, prop) ?? 'string';
342
288
  const typeName = getTypeName(name, prop, shapeName, context);
343
289
  const relationship = getRelationship(prop);
344
-
345
290
  if (hasRefProperty(prop.items ?? prop)) {
346
291
  if (!hasResolvableRef(projectSchema, prop.items ?? prop)) {
347
292
  return undefined;
348
293
  }
349
-
350
294
  if (prop.items) {
351
- prop = { ...prop,
295
+ prop = {
296
+ ...prop,
352
297
  items: followRef(projectSchema, prop.items)
353
298
  };
354
299
  } else {
355
300
  prop = followRef(projectSchema, prop);
356
301
  }
357
302
  }
358
-
359
303
  if (!shapeCache.has(typeName) && !projectSchema.shapes[typeName]) {
360
304
  shapeCache.set(typeName, () => {
361
305
  var _prop$items;
362
-
363
306
  let props;
364
307
  const propOrItems = prop.items ?? prop;
365
-
366
308
  if (isId(name)) {
367
309
  props = getFieldTypeComparison('id');
368
310
  } else if (relationship) {
369
311
  const shapes = getRelationshipShapes(projectSchema.shapes, relationship.refs);
370
- props = getFields(typeName, shapes, { ...context,
312
+ props = getFields(typeName, shapes, {
313
+ ...context,
371
314
  relationshipDepth: relationshipDepth + 1
372
315
  });
373
316
  } else if (isUnionSchema(propOrItems)) {
374
317
  const shapes = enumerateOneOfKeys(projectSchema, propOrItems.oneOf).map(option => projectSchema.shapes[option.shapeName]);
375
- props = getFields(typeName, shapes, { ...context,
318
+ props = getFields(typeName, shapes, {
319
+ ...context,
376
320
  booleanOperators: false
377
321
  });
378
322
  } else if (fieldType === 'object' || fieldType === 'array' && ((_prop$items = prop.items) === null || _prop$items === void 0 ? void 0 : _prop$items.type) === 'object') {
379
323
  var _prop$items2;
380
-
381
324
  const properties = ((_prop$items2 = prop.items) === null || _prop$items2 === void 0 ? void 0 : _prop$items2.properties) ?? prop.properties;
382
-
383
325
  if (properties) {
384
326
  props = props ?? {};
385
- const fieldContext = { ...context,
327
+ const fieldContext = {
328
+ ...context,
386
329
  conflictingProperties: undefined // non-union objects have no conflicts
387
-
388
330
  };
389
331
 
390
332
  for (const propName of Object.keys(properties)) {
@@ -393,26 +335,21 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
393
335
  }
394
336
  } else {
395
337
  var _prop$items3;
396
-
397
338
  // Treat non-object arrays as their base type
398
339
  let type;
399
-
400
340
  if (typeof ((_prop$items3 = prop.items) === null || _prop$items3 === void 0 ? void 0 : _prop$items3.type) === 'string') {
401
341
  type = prop.items.type;
402
342
  } else {
403
343
  type = fieldType;
404
344
  }
405
-
406
345
  props = getFieldTypeComparison(type);
407
346
  }
408
-
409
347
  return createShape(typeName, {
410
348
  type: 'object',
411
349
  properties: props ?? {}
412
350
  });
413
351
  });
414
352
  }
415
-
416
353
  if (shapeCache.has(typeName) || projectSchema.shapes[typeName]) {
417
354
  const fieldName = `${conflictingProperties !== null && conflictingProperties !== void 0 && conflictingProperties.has(name) ? `${shapeName}_` : ''}${name}`;
418
355
  return {
@@ -422,85 +359,67 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
422
359
  };
423
360
  }
424
361
  }
425
-
426
362
  function findEmpty(shapes) {
427
363
  const empty = new Set();
428
-
429
364
  for (const [shapeName, shape] of Object.entries(shapes)) {
430
365
  if (isObjectSchema(shape.schema) && Object.keys(shape.schema.properties).length === 0) {
431
366
  empty.add(shapeName);
432
367
  }
433
368
  }
434
-
435
369
  return empty;
436
370
  }
437
-
438
371
  function getRefSummary(shapes) {
439
372
  const result = {};
440
-
441
373
  for (const ref of getAllRefsInShapes({
442
374
  shapes,
443
375
  services: {}
444
376
  })) {
445
377
  const path = ref.path.slice(1, ref.path.length - 1);
446
-
447
378
  if (result[ref.typeName]) {
448
379
  result[ref.typeName].push(path);
449
380
  } else {
450
381
  result[ref.typeName] = [path];
451
382
  }
452
383
  }
453
-
454
384
  return result;
455
385
  }
456
-
457
386
  function pruneEmpty(shapes) {
458
387
  let toPrune = findEmpty(shapes);
459
-
460
388
  if (toPrune.size) {
461
389
  const refSummary = getRefSummary(shapes);
462
-
463
390
  while (toPrune.size) {
464
391
  for (const shapeName of toPrune) {
465
392
  unset(shapes, shapeName);
466
-
467
393
  for (const path of refSummary[shapeName] ?? []) {
468
394
  unset(shapes, path);
469
395
  }
470
396
  }
471
-
472
397
  toPrune = findEmpty(shapes);
473
398
  }
474
399
  }
475
-
476
400
  return shapes;
477
401
  }
478
-
479
402
  function getReferencedShape(context) {
480
403
  return prop => {
481
404
  const ref = getRef(context, prop);
482
405
  return ref && refItemToShape(context, ref);
483
406
  };
484
407
  }
408
+
485
409
  /**
486
410
  * Expand union shapes
487
411
  */
488
-
489
-
490
412
  function expandUnionShapes(projectSchema, shapes) {
491
413
  return uniqBy(shapes.flatMap(shape => isUnionSchema(shape.schema) ? shape.schema.oneOf.map(getReferencedShape(projectSchema)).filter(isDefined) : shape), 'name');
492
414
  }
493
-
494
415
  export function getWhereShape(projectSchema, selectedShapes) {
495
416
  const shapeName = selectedShapes.length === 1 ? `TSWhere${pascalCase(selectedShapes[0].name)}Input` : 'TSWhereInput';
496
-
497
417
  if (projectSchema.shapes[shapeName]) {
498
418
  return {
499
419
  shapeName,
500
420
  dependencies: {}
501
421
  };
502
422
  }
503
-
504
423
  const expandedShapes = expandUnionShapes(projectSchema, selectedShapes);
505
424
  const isManyContentTypes = expandedShapes.length > 1;
506
425
  const shapeCache = new ShapeCache();
@@ -514,7 +433,8 @@ export function getWhereShape(projectSchema, selectedShapes) {
514
433
  dependencies: pruneEmpty({
515
434
  [shapeName]: createShape(shapeName, {
516
435
  type: 'object',
517
- properties: { ...fields,
436
+ properties: {
437
+ ...fields,
518
438
  ...(isManyContentTypes && getBooleanOperatorTypes(shapeName))
519
439
  }
520
440
  }),
package/es/types/types.js CHANGED
@@ -2,24 +2,57 @@ export const projectSchemaImportOptionalProps = ['projectId', 'locales', 'defaul
2
2
  export const legacyProjectSchemaImportOptionalProps = ['created', 'updated', 'version', 'dataKey'];
3
3
 
4
4
  /**
5
- * Types of refs
5
+ * Remote service configuration types
6
6
  */
7
- export let RefType;
8
7
  /**
9
- * Stub of a PropertySchema that may contain a `$ref` or `@ref`.
8
+ * Old service authentication
9
+ * @deprecated
10
10
  */
11
-
12
- (function (RefType) {
11
+ /**
12
+ * Support null sentinels for authentication
13
+ */
14
+ /**
15
+ * A type suitable for service object updates, mostly concerns authentication
16
+ * requirements.
17
+ */
18
+ /**
19
+ * Types of refs
20
+ */
21
+ export let RefType = /*#__PURE__*/function (RefType) {
13
22
  RefType["@ref"] = "@ref";
14
23
  RefType["$ref"] = "$ref";
15
- })(RefType || (RefType = {}));
24
+ return RefType;
25
+ }({});
16
26
 
17
27
  /**
18
- * Types of args
28
+ * Stub of a PropertySchema that may contain a `$ref` or `@ref`.
19
29
  */
20
- export let ArgsType;
21
30
 
22
- (function (ArgsType) {
31
+ /**
32
+ * Types of args
33
+ */
34
+ export let ArgsType = /*#__PURE__*/function (ArgsType) {
23
35
  ArgsType["@args"] = "@args";
24
36
  ArgsType["args"] = "args";
25
- })(ArgsType || (ArgsType = {}));
37
+ return ArgsType;
38
+ }({});
39
+
40
+ /**
41
+ * Types supporting schema iterators
42
+ */
43
+
44
+ /**
45
+ * Shapes
46
+ */
47
+
48
+ /**
49
+ * Relationships
50
+ */
51
+
52
+ /**
53
+ * New relationship data, drawn from a PropertySchema.
54
+ */
55
+
56
+ /**
57
+ * The old relationship format, used in client UI.
58
+ */