@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
@@ -62,79 +62,47 @@ exports.shapeToPropertySchema = shapeToPropertySchema;
62
62
  exports.splitMapping = splitMapping;
63
63
  exports.visitSchemaProperties = visitSchemaProperties;
64
64
  exports.visitShapeProperties = visitShapeProperties;
65
-
66
65
  var _find = _interopRequireDefault(require("lodash/find"));
67
-
68
66
  var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
69
-
70
67
  var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
71
-
72
68
  var _keyBy = _interopRequireDefault(require("lodash/keyBy"));
73
-
74
69
  var _isObject = _interopRequireDefault(require("lodash/isObject"));
75
-
76
70
  var _curry = _interopRequireDefault(require("lodash/fp/curry"));
77
-
78
71
  var _orderBy2 = _interopRequireDefault(require("lodash/fp/orderBy"));
79
-
80
72
  var _uniq = _interopRequireDefault(require("lodash/uniq"));
81
-
82
73
  var _util = require("@takeshape/util");
83
-
84
74
  var _workflows = require("./workflows");
85
-
86
75
  var _versions = require("./versions");
87
-
88
76
  var _apiVersion = require("./api-version");
89
-
90
77
  var _builtinSchema = require("./builtin-schema");
91
-
92
78
  var _utils = require("./types/utils");
93
-
94
79
  var _services = require("./services");
95
-
96
80
  var _refs = require("./refs");
97
-
98
81
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
99
-
100
82
  var _isString = _interopRequireDefault(require("lodash/isString"));
101
-
102
83
  var _unions = require("./unions");
103
-
104
84
  var _util2 = require("./util");
105
-
106
85
  var _errors = require("@takeshape/errors");
107
-
108
86
  var _isArray = _interopRequireDefault(require("lodash/isArray"));
109
-
110
87
  var _some = _interopRequireDefault(require("lodash/some"));
111
-
112
88
  var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
113
-
114
89
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
115
-
116
90
  const SERVICE_OBJECT_PATTERN_NAME = 'pattern:service-object';
117
91
  exports.SERVICE_OBJECT_PATTERN_NAME = SERVICE_OBJECT_PATTERN_NAME;
118
-
119
92
  function isBuiltinShape(shapeName) {
120
93
  return Boolean(_builtinSchema.builtInShapes[shapeName]);
121
94
  }
122
-
123
95
  const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(_builtinSchema.builtInShapes));
124
-
125
96
  function isBuiltinQuery(name) {
126
97
  return builtInQueriesAndMutations.queries[name] !== undefined;
127
98
  }
128
-
129
99
  function isBuiltinMutation(name) {
130
100
  return builtInQueriesAndMutations.mutations[name] !== undefined;
131
101
  }
132
-
133
102
  function isBuiltinType(projectSchema, refSchema) {
134
103
  const shapeName = (0, _refs.getRefShapeName)(projectSchema, refSchema);
135
104
  return shapeName !== undefined && isBuiltinShape(shapeName);
136
105
  }
137
-
138
106
  const schemaMetadataKeys = ['$comment', 'title', 'description', '@l10n', '@deprecationReason', '@tag', '@tags', '@syncLocaleStructure', '@sensitive'];
139
107
  exports.schemaMetadataKeys = schemaMetadataKeys;
140
108
  const commonSchemaKeys = ['type', 'default', 'readOnly', ...schemaMetadataKeys];
@@ -145,50 +113,44 @@ const objectSchemaKeys = [...commonSchemaKeys, 'properties', 'required'];
145
113
  exports.objectSchemaKeys = objectSchemaKeys;
146
114
  const arraySchemaKeys = [...commonSchemaKeys, 'items', 'additionalItems', 'maxItems', 'minItems', 'uniqueItems'];
147
115
  exports.arraySchemaKeys = arraySchemaKeys;
148
- const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems']; // All properties except properties, items, additionalItems
116
+ const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems'];
149
117
 
118
+ // All properties except properties, items, additionalItems
150
119
  exports.multipleRelationshipSchemaKeys = multipleRelationshipSchemaKeys;
151
120
  const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@resolver', '@input', '@output', '@backreference', '@args', 'required', 'maxItems', 'minItems', 'uniqueItems'];
152
121
  exports.nonStructuralSchemaKeys = nonStructuralSchemaKeys;
153
-
154
122
  function getServiceIdFieldName(serviceFieldName) {
155
123
  return `${serviceFieldName}Id`;
156
124
  }
157
-
158
125
  const generatorVersions = {
159
126
  [SERVICE_OBJECT_PATTERN_NAME]: '1'
160
127
  };
161
-
162
128
  function getGeneratorVersion(generator) {
163
129
  return generatorVersions[generator];
164
- } // Returns info for all services found in shape, keyed by provider
165
-
130
+ }
166
131
 
132
+ // Returns info for all services found in shape, keyed by provider
167
133
  function getServiceInfo(projectSchema, shape) {
168
- const result = {}; // Get inline dependencies by not following refs with @resolver
134
+ const result = {};
169
135
 
136
+ // Get inline dependencies by not following refs with @resolver
170
137
  const inlineDepShapes = getShapeDependencies(projectSchema, shape, prop => !prop['@resolver']).map(name => projectSchema.shapes[name]);
171
138
  const shapesToCheck = [shape, ...inlineDepShapes];
172
139
  shapesToCheck.forEach(thisShape => {
173
140
  createSchemaPropertyList(projectSchema, thisShape).forEach(([key, value]) => {
174
141
  const resolver = value['@resolver'];
175
-
176
142
  if (!(0, _utils.isServiceResolver)(resolver)) {
177
143
  return;
178
144
  }
179
-
180
145
  const serviceConfig = (0, _services.getStoredServiceConfig)(projectSchema, resolver.service);
181
-
182
146
  if (!serviceConfig) {
183
147
  return;
184
148
  }
185
-
186
149
  const {
187
150
  provider
188
151
  } = serviceConfig;
189
152
  const generators = {};
190
153
  const tag = value['@tag'];
191
-
192
154
  if (tag !== null && tag !== void 0 && tag.startsWith(SERVICE_OBJECT_PATTERN_NAME)) {
193
155
  const idFieldName = getServiceIdFieldName(key);
194
156
  const version = tag.substr(tag.lastIndexOf(':') + 1);
@@ -199,14 +161,12 @@ function getServiceInfo(projectSchema, shape) {
199
161
  serviceObjectType: resolver.fieldName
200
162
  };
201
163
  }
202
-
203
164
  const serviceInfo = {
204
165
  service: resolver.service,
205
166
  fieldName: key,
206
167
  path: pathBetween(shape, thisShape, projectSchema),
207
168
  generators
208
169
  };
209
-
210
170
  if (Array.isArray(result[provider])) {
211
171
  // Dedupe service info
212
172
  if (!result[provider].find(existingServiceInfo => (0, _isEqual.default)(existingServiceInfo, serviceInfo))) {
@@ -218,33 +178,27 @@ function getServiceInfo(projectSchema, shape) {
218
178
  });
219
179
  });
220
180
  return result;
221
- } // Follow refs to find the path between two shapes in a schema
222
-
181
+ }
223
182
 
183
+ // Follow refs to find the path between two shapes in a schema
224
184
  function pathBetween(fromShape, toShape, projectSchema, depthLimit = 4) {
225
185
  if (fromShape.name === toShape.name) {
226
186
  return [];
227
187
  }
228
-
229
188
  const toShapeName = toShape.name;
230
189
  let shortestPath;
231
190
  let shortestPathLength = Number.MAX_SAFE_INTEGER;
232
-
233
191
  const pathBetweenHelper = (schema, pathSoFar, seen, depth) => {
234
192
  if (depth > depthLimit) {
235
193
  return;
236
194
  }
237
-
238
195
  if (schema.items) {
239
196
  pathBetweenHelper(schema.items, pathSoFar, seen, depth);
240
197
  return;
241
198
  }
242
-
243
199
  const refItem = (0, _refs.getRef)(projectSchema, schema);
244
-
245
200
  if (refItem) {
246
201
  const referenced = (0, _refs.refItemToShape)(projectSchema, refItem);
247
-
248
202
  if (referenced) {
249
203
  if (referenced.name === toShapeName && pathSoFar.length < shortestPathLength) {
250
204
  shortestPath = pathSoFar;
@@ -265,27 +219,21 @@ function pathBetween(fromShape, toShape, projectSchema, depthLimit = 4) {
265
219
  }
266
220
  }
267
221
  };
268
-
269
222
  pathBetweenHelper(fromShape.schema, [], new Set([fromShape.name]), 0);
270
-
271
223
  if (!shortestPath) {
272
224
  throw new Error(`No path between ${fromShape.name} and ${toShape.name}`);
273
225
  }
274
-
275
226
  return shortestPath;
276
227
  }
277
-
278
228
  function getShapeQueriesAndMutations(shapes) {
279
229
  const queries = {};
280
230
  const mutations = {};
281
-
282
231
  for (const shape of (0, _util.ensureArray)(shapes)) {
283
232
  const {
284
233
  name,
285
234
  model
286
235
  } = shape;
287
236
  const service = 'shapedb';
288
-
289
237
  if (model) {
290
238
  const isSingleton = model.type === 'single';
291
239
  queries[`get${name}`] = {
@@ -308,7 +256,6 @@ function getShapeQueriesAndMutations(shapes) {
308
256
  description: `Update ${name}`,
309
257
  args: (0, _refs.createTemplateShapeName)('UpdateArgs', name)
310
258
  };
311
-
312
259
  if (!isSingleton) {
313
260
  queries[`get${name}List`] = {
314
261
  shape: (0, _refs.createTemplateShapeName)('PaginatedList', name),
@@ -353,30 +300,24 @@ function getShapeQueriesAndMutations(shapes) {
353
300
  }
354
301
  }
355
302
  }
356
-
357
303
  return {
358
304
  queries,
359
305
  mutations
360
306
  };
361
307
  }
362
-
363
308
  function getBuiltinPropertiesSet(shape) {
364
309
  if (isModelShape(shape)) {
365
310
  return 'model';
366
311
  }
367
-
368
312
  if (isCachedShape(shape)) {
369
313
  return 'indexed';
370
314
  }
371
-
372
315
  return 'none';
373
316
  }
374
-
375
317
  function getBuiltinProperties(shapeId, builtinPropertiesSet, apiVersion = _versions.CURRENT_API_VERSION) {
376
318
  if (builtinPropertiesSet === 'none') {
377
319
  return {};
378
320
  }
379
-
380
321
  const commonFields = {
381
322
  _shapeId: {
382
323
  type: 'string',
@@ -388,13 +329,12 @@ function getBuiltinProperties(shapeId, builtinPropertiesSet, apiVersion = _versi
388
329
  type: 'string'
389
330
  }
390
331
  };
391
-
392
332
  if (builtinPropertiesSet === 'indexed') {
393
333
  return commonFields;
394
334
  }
395
-
396
335
  const showV1Deprecation = apiVersion !== '1';
397
- return { ...commonFields,
336
+ return {
337
+ ...commonFields,
398
338
  _version: {
399
339
  title: 'Version',
400
340
  type: 'integer'
@@ -452,25 +392,23 @@ function getBuiltinProperties(shapeId, builtinPropertiesSet, apiVersion = _versi
452
392
  }
453
393
  };
454
394
  }
395
+
455
396
  /**
456
397
  * Return all the built in property names,
457
398
  */
458
-
459
-
460
399
  const getBuiltinPropertyNames = (builtinPropertiesSet, apiVersion = _versions.CURRENT_API_VERSION) => new Set([...Object.keys(getBuiltinProperties('shape-id', builtinPropertiesSet, apiVersion)), (0, _apiVersion.workflowsEnabled)(apiVersion) ? '_status' : undefined].filter(_util.isDefined));
461
-
462
400
  exports.getBuiltinPropertyNames = getBuiltinPropertyNames;
463
-
464
401
  function applyBuiltinPropertiesToShape(projectSchema, shape) {
465
402
  const builtinSet = getBuiltinPropertiesSet(shape);
466
-
467
403
  if (builtinSet === 'none') {
468
404
  return shape;
469
405
  }
470
-
471
- return { ...shape,
472
- schema: { ...shape.schema,
473
- properties: { ...(0, _omitBy.default)((0, _refs.dereferenceObjectSchema)(projectSchema, shape.schema, ['shapes', shape.name]).properties, (_, name) => name.startsWith('_')),
406
+ return {
407
+ ...shape,
408
+ schema: {
409
+ ...shape.schema,
410
+ properties: {
411
+ ...(0, _omitBy.default)((0, _refs.dereferenceObjectSchema)(projectSchema, shape.schema, ['shapes', shape.name]).properties, (_, name) => name.startsWith('_')),
474
412
  ...getBuiltinProperties(shape.id, builtinSet, projectSchema.apiVersion),
475
413
  ...(builtinSet === 'model' && (0, _apiVersion.workflowsEnabled)(projectSchema.apiVersion) && {
476
414
  _status: (0, _workflows.getStatusField)(projectSchema.workflows, shape)
@@ -478,19 +416,20 @@ function applyBuiltinPropertiesToShape(projectSchema, shape) {
478
416
  }
479
417
  }
480
418
  };
481
- } // Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
482
-
419
+ }
483
420
 
421
+ // Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
484
422
  const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TSStaticSite', 'TSUser'];
423
+
485
424
  /**
486
425
  * Get all built-in shapes that are depended on by the given project schema.
487
426
  * Required built-in shapes are always included.
488
427
  */
489
-
490
428
  function getBuiltinsUsed(projectSchema) {
491
429
  const builtinsUsed = {};
492
430
  const shapeNames = (0, _uniq.default)(requiredBuiltinShapes.concat(getAllRefs(projectSchema, refItem => refItem.serviceKey === 'local' && isBuiltinShape(refItem.typeName)).map(_refs.refItemToShapeName)));
493
- const schemaWithAllBuiltins = { ...emptySchema('project-id'),
431
+ const schemaWithAllBuiltins = {
432
+ ...emptySchema('project-id'),
494
433
  shapes: _builtinSchema.builtInShapes
495
434
  };
496
435
  shapeNames.forEach(builtinShapeName => {
@@ -501,109 +440,97 @@ function getBuiltinsUsed(projectSchema) {
501
440
  });
502
441
  return builtinsUsed;
503
442
  }
504
-
505
443
  function applyDefaultsToSchema(projectSchema) {
506
444
  const builtinsUsed = getBuiltinsUsed(projectSchema);
507
- return { ...projectSchema,
508
- workflows: { ...projectSchema.workflows,
445
+ return {
446
+ ...projectSchema,
447
+ workflows: {
448
+ ...projectSchema.workflows,
509
449
  ...((0, _apiVersion.workflowsEnabled)(projectSchema.apiVersion) && {
510
450
  default: _workflows.defaultWorkflow
511
451
  })
512
452
  },
513
- queries: { ...builtInQueriesAndMutations.queries,
453
+ queries: {
454
+ ...builtInQueriesAndMutations.queries,
514
455
  ...projectSchema.queries
515
456
  },
516
- mutations: { ...builtInQueriesAndMutations.mutations,
457
+ mutations: {
458
+ ...builtInQueriesAndMutations.mutations,
517
459
  ...projectSchema.mutations
518
460
  },
519
- shapes: (0, _mapValues.default)({ ...builtinsUsed,
461
+ shapes: (0, _mapValues.default)({
462
+ ...builtinsUsed,
520
463
  ...projectSchema.shapes
521
464
  }, shape => {
522
465
  const builtInShape = builtinsUsed[shape.name];
523
-
524
466
  if (builtInShape && builtInShape !== shape) {
525
- shape = { ...shape,
467
+ shape = {
468
+ ...shape,
526
469
  schema: (0, _util2.mergeSchemaProperties)((0, _refs.dereferenceObjectSchema)(projectSchema, shape.schema), (0, _refs.dereferenceObjectSchema)(projectSchema, builtInShape.schema))
527
470
  };
528
471
  }
529
-
530
472
  return applyBuiltinPropertiesToShape(projectSchema, shape);
531
473
  }),
532
- forms: (0, _mapValues.default)({ ..._builtinSchema.builtInForms,
474
+ forms: (0, _mapValues.default)({
475
+ ..._builtinSchema.builtInForms,
533
476
  ...projectSchema.forms
534
477
  }, (formsConfig, shapeName) => {
535
478
  const builtInFormsConfig = _builtinSchema.builtInForms[shapeName];
536
-
537
479
  if (builtInFormsConfig && builtInFormsConfig !== formsConfig) {
538
- formsConfig = { ...formsConfig,
480
+ formsConfig = {
481
+ ...formsConfig,
539
482
  default: (0, _util2.mergeFormProperties)(formsConfig.default, builtInFormsConfig.default)
540
483
  };
541
484
  }
542
-
543
485
  return formsConfig;
544
486
  })
545
487
  };
546
488
  }
547
-
548
489
  function getShapeById(projectSchema, shapeId) {
549
490
  return (0, _find.default)(projectSchema.shapes, shape => shape.id === shapeId);
550
491
  }
551
-
552
492
  function getShapeByRef(projectSchema, shapeRef) {
553
493
  return (0, _refs.refItemToShape)(projectSchema, (0, _refs.atRefToRefItem)(projectSchema, shapeRef));
554
494
  }
555
-
556
495
  function ensureShapeById(projectSchema, shapeId) {
557
496
  const shape = getShapeById(projectSchema, shapeId);
558
-
559
497
  if (!shape) {
560
498
  throw new _errors.NotFoundError(`Shape ${shapeId} Not found`);
561
499
  }
562
-
563
500
  return shape;
564
501
  }
565
-
566
502
  function getShape(context, name) {
567
503
  return context.shapes[name];
568
504
  }
569
-
570
505
  function isModelShape(shape) {
571
506
  return Boolean(shape.model);
572
507
  }
573
-
574
508
  function isCachedShape(shape) {
575
509
  var _shape$cache;
576
-
577
510
  return ((_shape$cache = shape.cache) === null || _shape$cache === void 0 ? void 0 : _shape$cache.enabled) === true && shape.loaders !== undefined;
578
511
  }
579
-
580
512
  function getArgsReference(projectSchema, argsSchema) {
581
513
  const args = (0, _util2.getArgs)(argsSchema);
582
-
583
514
  if (args && typeof args === 'string') {
584
515
  // @args: ShapeName OR Namespace_TypeName
585
516
  return (0, _refs.refExpressionToRefItem)(projectSchema, args);
586
517
  }
587
518
  }
588
-
589
519
  function getArgsReferenceWithPath(context, argsSchema, schemaPath = []) {
590
520
  const refItem = getArgsReference(context, argsSchema);
591
-
592
521
  if (refItem) {
593
522
  const argsType = (0, _utils.getArgsType)(argsSchema);
594
- return { ...refItem,
523
+ return {
524
+ ...refItem,
595
525
  path: schemaPath.concat([argsType])
596
526
  };
597
527
  }
598
528
  }
599
-
600
529
  function getArgsShapeSchema(context, argsSchema) {
601
530
  const args = (0, _util2.getArgs)(argsSchema);
602
-
603
531
  if (args) {
604
532
  if (typeof args === 'string') {
605
533
  const refItem = getArgsReference(context, argsSchema);
606
-
607
534
  if (refItem) {
608
535
  return (0, _refs.refItemToShapeSchema)(context, refItem);
609
536
  }
@@ -612,7 +539,6 @@ function getArgsShapeSchema(context, argsSchema) {
612
539
  }
613
540
  }
614
541
  }
615
-
616
542
  const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, {
617
543
  useShapeIdDiscriminator
618
544
  }) => {
@@ -620,24 +546,21 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
620
546
  const handleSchema = propSchema => {
621
547
  // Unwrap array schema
622
548
  propSchema = propSchema.items ?? propSchema;
623
-
624
549
  if ((0, _utils.isOneOfSchema)(propSchema)) {
625
550
  const isUnion = (0, _unions.isUnionSchema)(propSchema);
626
-
627
551
  if (useShapeIdDiscriminator && isUnion) {
628
552
  propSchema.discriminator = {
629
553
  propertyName: '_shapeId'
630
554
  };
631
555
  propSchema.required = ['_shapeId'];
632
556
  }
633
-
634
557
  propSchema.oneOf.forEach(schema => {
635
558
  handleSchema(schema);
636
559
  });
637
560
  return;
638
- } // Add workflow validation
639
-
561
+ }
640
562
 
563
+ // Add workflow validation
641
564
  if (propSchema['@workflow']) {
642
565
  const workflowName = propSchema['@workflow'];
643
566
  const workflow = projectSchema.workflows[workflowName] || _workflows.defaultWorkflow;
@@ -646,101 +569,80 @@ const createShapeToPropertySchema = (projectSchema, definitions, definitionNames
646
569
  title: step.title
647
570
  }));
648
571
  }
649
-
650
572
  const refItem = (0, _refs.getRef)(projectSchema, propSchema);
651
-
652
573
  if (refItem) {
653
574
  const shapeName = (0, _refs.refItemToShapeName)(refItem);
654
575
  const shape = (0, _refs.refItemToShape)(projectSchema, refItem);
655
-
656
576
  if (shape) {
657
577
  delete propSchema['@ref'];
658
578
  propSchema.$ref = `#/definitions/${shapeName}`;
659
-
660
579
  if (!definitionNames.has(shapeName)) {
661
580
  definitionNames.add(shapeName);
662
581
  const rewritten = rewriteRefs(shape);
663
-
664
582
  if (useShapeIdDiscriminator && (0, _utils.isObjectSchema)(rewritten)) {
665
583
  rewritten.properties._shapeId = {
666
584
  type: 'string',
667
585
  enum: [shape.id]
668
586
  };
669
587
  }
670
-
671
588
  definitions[shapeName] = rewritten;
672
589
  }
673
590
  }
674
591
  }
675
592
  };
676
-
677
593
  const shapeSchema = (0, _util.deepClone)(shape.schema);
678
-
679
594
  if ((0, _utils.isOneOfSchema)(shapeSchema)) {
680
595
  handleSchema(shapeSchema);
681
596
  return shapeSchema;
682
597
  }
683
-
684
598
  if (shapeSchema.enum) {
685
599
  return shapeSchema;
686
600
  }
687
-
688
601
  const shapeSchemaCopy = (0, _refs.dereferenceObjectSchema)(projectSchema, shapeSchema);
689
-
690
602
  if (shape.title) {
691
603
  shapeSchemaCopy.title = shape.title;
692
604
  }
693
-
694
605
  Object.values(shapeSchemaCopy.properties).forEach(schema => {
695
606
  handleSchema(schema);
696
607
  });
697
608
  return shapeSchemaCopy;
698
609
  };
699
-
700
610
  return rewriteRefs;
701
611
  };
702
-
703
612
  function shapeToPropertySchema(projectSchema, shape) {
704
613
  const definitions = {};
705
614
  const definitionNames = new Set();
706
615
  const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
707
616
  useShapeIdDiscriminator: true
708
617
  });
709
- return { ...convert(shape),
618
+ return {
619
+ ...convert(shape),
710
620
  definitions
711
621
  };
712
622
  }
713
-
714
623
  function projectSchemaToJSONSchema(projectSchema) {
715
624
  const definitions = {};
716
625
  const definitionNames = new Set();
717
626
  const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
718
627
  useShapeIdDiscriminator: false
719
628
  });
720
-
721
629
  for (const shape of Object.values(projectSchema.shapes)) {
722
630
  definitions[shape.name] = convert(shape);
723
631
  definitionNames.add(shape.name);
724
632
  }
725
-
726
633
  return {
727
634
  definitions
728
635
  };
729
636
  }
730
-
731
637
  function getShapeDependencies(projectSchema, shape, predicate) {
732
638
  const shapeNames = new Set();
733
-
734
639
  const findDependencies = schema => {
735
640
  const shouldFollow = Boolean(!predicate || predicate(schema));
736
-
737
641
  if (shouldFollow) {
738
642
  schema = schema.items ?? schema;
739
643
  const refItem = (0, _refs.getRef)(projectSchema, schema);
740
-
741
644
  if (refItem) {
742
645
  const refShape = (0, _refs.refItemToShape)(projectSchema, refItem);
743
-
744
646
  if (refShape && !shapeNames.has(refShape.name)) {
745
647
  shapeNames.add(refShape.name);
746
648
  findDependencies((0, _refs.dereferenceSchema)(projectSchema, refShape.schema, ['shapes', refShape.name]));
@@ -749,14 +651,11 @@ function getShapeDependencies(projectSchema, shape, predicate) {
749
651
  visitSchemaProperties(schema, [], findDependencies);
750
652
  }
751
653
  }
752
-
753
654
  return shouldFollow;
754
655
  };
755
-
756
656
  findDependencies(shape.schema);
757
657
  return [...shapeNames];
758
658
  }
759
-
760
659
  function getRelevantShapes(projectSchema, params) {
761
660
  const {
762
661
  shapeIds,
@@ -764,39 +663,31 @@ function getRelevantShapes(projectSchema, params) {
764
663
  byId = false,
765
664
  includeDependencies = true
766
665
  } = params;
767
-
768
666
  if (shapeNames !== null && shapeNames !== void 0 && shapeNames.length || shapeIds !== null && shapeIds !== void 0 && shapeIds.length) {
769
667
  const ids = new Set(shapeIds);
770
668
  const names = new Set(shapeNames);
771
669
  const shapes = {};
772
-
773
670
  for (const shape of Object.values(projectSchema.shapes)) {
774
671
  if (ids.has(shape.id) || names.has(shape.name)) {
775
672
  const shapeNames = includeDependencies ? [shape.name].concat(getShapeDependencies(projectSchema, shape)) : [shape.name];
776
-
777
673
  for (const shapeName of shapeNames) {
778
674
  const dependentShape = projectSchema.shapes[shapeName];
779
675
  shapes[byId ? dependentShape.id : dependentShape.name] = dependentShape;
780
676
  }
781
677
  }
782
678
  }
783
-
784
679
  return shapes;
785
680
  }
786
-
787
681
  return {};
788
682
  }
789
-
790
683
  function visitSchemaPropertiesHelper(entries, path, callback) {
791
684
  for (const [name, propSchema] of entries) {
792
685
  const newPath = [...path, name];
793
-
794
686
  if (callback(propSchema, newPath) !== false && ((0, _utils.isObjectSchema)(propSchema) || (0, _utils.isExtendsSchema)(propSchema) || (0, _utils.isAllOfSchema)(propSchema) || (0, _utils.isOneOfSchema)(propSchema))) {
795
687
  visitSchemaProperties(propSchema, newPath, callback);
796
688
  }
797
689
  }
798
690
  }
799
-
800
691
  function visitSchemaProperties(schema, path, callback) {
801
692
  if ((0, _utils.isArraySchema)(schema)) {
802
693
  visitSchemaPropertiesHelper(Object.entries(schema.items), [...path, 'items'], callback);
@@ -812,23 +703,20 @@ function visitSchemaProperties(schema, path, callback) {
812
703
  callback(schema, path);
813
704
  }
814
705
  }
815
-
816
706
  function visitShapeProperties(shapes, callback) {
817
707
  for (const [shapeName, shape] of Object.entries(shapes)) {
818
708
  visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], callback);
819
709
  }
820
710
  }
821
-
822
711
  function addRef(refs, ref, predicate) {
823
712
  if (ref && (!predicate || predicate(ref))) {
824
713
  refs.push(ref);
825
714
  }
826
715
  }
716
+
827
717
  /**
828
718
  * Walk through a `ProjectSchemaJSON` and collect all the `ref`s.
829
719
  */
830
-
831
-
832
720
  function getAllRefsInShapes(projectSchema, predicate) {
833
721
  const items = [];
834
722
  const refPropNames = ['$ref', '@ref', '@args', 'args'];
@@ -839,100 +727,88 @@ function getAllRefsInShapes(projectSchema, predicate) {
839
727
  if (!(0, _isString.default)(ref)) {
840
728
  return;
841
729
  }
842
-
843
730
  const propName = refPath[refPath.length - 1];
844
731
  const path = ['shapes', ...refPath];
845
732
  let refItem = {};
846
-
847
733
  if (propName === '@ref') {
848
734
  const {
849
735
  shapeName,
850
736
  template
851
737
  } = (0, _refs.parseTemplateShape)(ref);
852
- refItem = { ...(0, _refs.atRefToRefItem)(projectSchema, shapeName, template),
738
+ refItem = {
739
+ ...(0, _refs.atRefToRefItem)(projectSchema, shapeName, template),
853
740
  path
854
741
  };
855
742
  } else if (propName === '$ref') {
856
- refItem = { ...(0, _refs.refToRefItem)(projectSchema, ref),
743
+ refItem = {
744
+ ...(0, _refs.refToRefItem)(projectSchema, ref),
857
745
  path
858
746
  };
859
747
  } else if (propName === '@args' || propName === 'args') {
860
- refItem = { ...(0, _refs.refExpressionToRefItem)(projectSchema, ref),
748
+ refItem = {
749
+ ...(0, _refs.refExpressionToRefItem)(projectSchema, ref),
861
750
  path
862
751
  };
863
752
  }
864
-
865
753
  if ((0, _refs.isRefItemWithPath)(refItem)) {
866
754
  addRef(items, refItem, predicate);
867
755
  }
868
756
  });
869
757
  return items;
870
758
  }
759
+
871
760
  /**
872
761
  * Get all refs
873
762
  */
874
-
875
-
876
763
  function getAllRefsInQuery(projectSchema, queryPath, query, predicate) {
877
764
  const refItems = [];
878
-
879
765
  const propertyVisitor = (propSchema, propSchemaPath) => {
880
766
  addRef(refItems, (0, _refs.getRefOrItemsRef)(projectSchema, propSchema, propSchemaPath), predicate);
881
767
  };
882
-
883
768
  if (query.args && typeof query.args === 'string') {
884
769
  addRef(refItems, getArgsReferenceWithPath(projectSchema, query, queryPath), predicate);
885
770
  }
886
-
887
771
  if (query.args && typeof query.args === 'object') {
888
772
  visitSchemaProperties((0, _refs.dereferenceObjectSchema)(projectSchema, query.args), [...queryPath, 'args'], propertyVisitor);
889
773
  }
890
-
891
774
  if (query.shape) {
892
775
  const {
893
776
  isArray,
894
777
  ref
895
778
  } = (0, _refs.parseReturnShape)(projectSchema, query.shape);
896
-
897
779
  if (ref) {
898
- addRef(refItems, { ...ref,
780
+ addRef(refItems, {
781
+ ...ref,
899
782
  path: queryPath.concat(isArray ? ['shape', 'items', '@ref'] : ['shape'])
900
783
  }, predicate);
901
784
  }
902
785
  }
903
-
904
786
  return refItems;
905
787
  }
788
+
906
789
  /**
907
790
  * Collect refs from `queries` or `mutations`.
908
791
  */
909
-
910
-
911
792
  function getAllRefsInQueries(projectSchema, rootPropertyName, predicate) {
912
793
  const refItems = [];
913
794
  const rootPath = [rootPropertyName];
914
-
915
795
  for (const [queryName, query] of Object.entries(projectSchema[rootPropertyName])) {
916
796
  const queryPath = rootPath.concat([queryName]);
917
797
  const queryRefs = getAllRefsInQuery(projectSchema, queryPath, query, predicate);
918
-
919
798
  if (queryRefs.length) {
920
799
  refItems.push(...queryRefs);
921
800
  }
922
801
  }
923
-
924
802
  return refItems;
925
803
  }
804
+
926
805
  /**
927
806
  * Get all refs in a ProjectSchemaJSON
928
807
  * @param predicate return true to include the ref in
929
808
  */
930
-
931
-
932
809
  function getAllRefs(projectSchema, predicate) {
933
810
  return [...getAllRefsInShapes(projectSchema, predicate), ...getAllRefsInQueries(projectSchema, 'queries', predicate), ...getAllRefsInQueries(projectSchema, 'mutations', predicate)];
934
811
  }
935
-
936
812
  function parseMapping(mapping) {
937
813
  const [providerId, serviceId, coordinate] = mapping.split(':');
938
814
  const [shapeName, key] = coordinate.split('.');
@@ -943,47 +819,38 @@ function parseMapping(mapping) {
943
819
  key
944
820
  };
945
821
  }
946
-
947
822
  function splitMapping(mapping) {
948
823
  return mapping.split('.');
949
824
  }
950
-
951
825
  function findMapping(schema, predicate) {
952
826
  const mapping = schema['@mapping'];
953
-
954
827
  if (Array.isArray(mapping)) {
955
828
  return mapping.find(predicate);
956
829
  }
957
-
958
830
  return mapping && predicate(mapping) ? mapping : undefined;
959
831
  }
960
-
961
832
  function getFirstMapping(schema) {
962
833
  return Array.isArray(schema['@mapping']) ? schema['@mapping'][0] : schema['@mapping'];
963
834
  }
964
-
965
835
  function getFullyQualifiedShapeName(schema) {
966
836
  const first = getFirstMapping(schema);
967
837
  return first ? splitMapping(first)[0] : undefined;
968
838
  }
839
+
969
840
  /**
970
841
  * Find key for use storing data in ShapeDB or API Indexing this allows renaming of properties without db migration
971
842
  * Mapping must be using the shapedb service id
972
843
  * @param schema
973
844
  */
974
-
975
-
976
845
  function getStorageKey(schema) {
977
846
  const first = findMapping(schema, mapping => mapping.startsWith('shapedb:'));
978
847
  return first ? splitMapping(first)[1] : undefined;
979
848
  }
980
-
981
849
  function getPropertyService(schema) {
982
850
  const first = getFirstMapping(schema);
983
851
  const split = first === null || first === void 0 ? void 0 : first.split(':');
984
852
  return split ? `${split[0]}:${split[1]}` : undefined;
985
853
  }
986
-
987
854
  function emptySchema(projectId) {
988
855
  return {
989
856
  projectId,
@@ -998,10 +865,10 @@ function emptySchema(projectId) {
998
865
  forms: {}
999
866
  };
1000
867
  }
1001
-
1002
868
  function getShapesById(projectSchema) {
1003
869
  return (0, _keyBy.default)(Object.values(projectSchema.shapes), 'id');
1004
870
  }
871
+
1005
872
  /**
1006
873
  * Walk through the project schema and return an array of all
1007
874
  * referenced shape names that are in a service namespace.
@@ -1010,13 +877,11 @@ function getShapesById(projectSchema) {
1010
877
  *
1011
878
  * @returns A `string` array with all the shapes that are in namespaces.
1012
879
  */
1013
-
1014
-
1015
880
  function getAllNamespaceShapes(projectSchema) {
1016
881
  const isServiceRef = refItem => Boolean(refItem.serviceNamespace);
1017
-
1018
882
  return (0, _uniq.default)(getAllRefs(projectSchema, isServiceRef).map(_refs.refItemToShapeName));
1019
883
  }
884
+
1020
885
  /**
1021
886
  * Returns a list of all shape names in a service namespace, excluding any
1022
887
  * that have been set directly in the project schema
@@ -1029,16 +894,17 @@ function getAllNamespaceShapes(projectSchema) {
1029
894
  *
1030
895
  * @returns A `Set` of shape names.
1031
896
  */
1032
-
1033
-
1034
897
  function getNamespacedShapeNameList(projectSchema) {
1035
- const requiredShapeNames = new Set(); // All the shape names
898
+ const requiredShapeNames = new Set();
1036
899
 
1037
- const existingShapeNames = new Set(Object.keys(projectSchema.shapes)); // All the referenced shape names with namespaces that belong to a service
900
+ // All the shape names
901
+ const existingShapeNames = new Set(Object.keys(projectSchema.shapes));
1038
902
 
1039
- const namespacedShapeNames = new Set(getAllNamespaceShapes(projectSchema)); // Add all namespaced shapes to the schema if they are not already present,
1040
- // e.g. Shopify_Product
903
+ // All the referenced shape names with namespaces that belong to a service
904
+ const namespacedShapeNames = new Set(getAllNamespaceShapes(projectSchema));
1041
905
 
906
+ // Add all namespaced shapes to the schema if they are not already present,
907
+ // e.g. Shopify_Product
1042
908
  namespacedShapeNames.forEach(name => {
1043
909
  if (!existingShapeNames.has(name)) {
1044
910
  requiredShapeNames.add(name);
@@ -1046,6 +912,7 @@ function getNamespacedShapeNameList(projectSchema) {
1046
912
  });
1047
913
  return requiredShapeNames;
1048
914
  }
915
+
1049
916
  /**
1050
917
  * Filter the service map to return only services passing the GraphQL Service
1051
918
  * typeguard.
@@ -1054,74 +921,58 @@ function getNamespacedShapeNameList(projectSchema) {
1054
921
  *
1055
922
  * @returns A new map with the filtered list of services
1056
923
  */
1057
-
1058
-
1059
924
  function filterGraphQLServiceMap(serviceMap) {
1060
925
  const filtered = new Map();
1061
-
1062
926
  for (const [serviceKey, serviceConfig] of serviceMap) {
1063
927
  if (serviceConfig.serviceType === 'graphql') {
1064
928
  filtered.set(serviceKey, serviceConfig);
1065
929
  }
1066
930
  }
1067
-
1068
931
  return filtered;
1069
932
  }
933
+
1070
934
  /**
1071
935
  * Add all referenced shape names to the refSet meant to be used as a callback to visitSchemaProperties
1072
936
  */
1073
-
1074
-
1075
937
  function collectReferencedShapeNames(context, shapeNames) {
1076
938
  const addRef = refItem => {
1077
939
  shapeNames.add((0, _refs.refItemToShapeName)(refItem));
1078
940
  };
1079
-
1080
941
  const collect = schema => {
1081
942
  const args = schema['@args'];
1082
-
1083
943
  if (args && (0, _isObject.default)(args) && (0, _utils.isObjectSchema)(args)) {
1084
944
  Object.values(args.properties).forEach(collect);
1085
945
  }
1086
-
1087
946
  const argsRefItem = getArgsReference(context, schema);
1088
-
1089
947
  if (argsRefItem) {
1090
948
  addRef(argsRefItem);
1091
949
  }
1092
-
1093
950
  const refItem = (0, _refs.getRefOrItemsRef)(context, schema);
1094
-
1095
951
  if (refItem) {
1096
952
  addRef(refItem);
1097
953
  }
1098
954
  };
1099
-
1100
955
  return collect;
1101
956
  }
957
+
1102
958
  /**
1103
959
  * Creates a schema property list chainable fn, allowing you to manipulate and
1104
960
  * iterate the properties in a schema.
1105
961
  */
1106
-
1107
-
1108
962
  const createSchemaPropertyList = (0, _curry.default)((context, shapeOrSchema) => {
1109
963
  const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
1110
964
  const schema = (0, _refs.dereferenceSchema)(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
1111
965
  const propertyIterator = new Map((0, _utils.isObjectSchema)(schema) ? Object.entries(schema.properties) : undefined);
1112
966
  const defaultOrderByIteratees = [n => n[0]];
1113
967
  const defaultOrderByOrders = ['asc'];
1114
-
1115
968
  const _orderBy = (iteratees = defaultOrderByIteratees, orders = defaultOrderByOrders) => {
1116
969
  self._propertyIterator = new Map((0, _orderBy2.default)(iteratees, orders, Array.from(self._propertyIterator)));
1117
970
  return self;
1118
971
  };
1119
-
1120
972
  const _sortWith = comparator => {
1121
973
  self._propertyIterator = new Map(Array.from(self._propertyIterator).sort(comparator));
1122
974
  return self;
1123
975
  };
1124
-
1125
976
  const _sortByNamesWithList = comparatorArray => {
1126
977
  // If no array is provided, the original sort is preserved
1127
978
  if (comparatorArray) {
@@ -1131,38 +982,30 @@ const createSchemaPropertyList = (0, _curry.default)((context, shapeOrSchema) =>
1131
982
  return (indexA > -1 ? indexA : Infinity) - (indexB > -1 ? indexB : Infinity);
1132
983
  }));
1133
984
  }
1134
-
1135
985
  return self;
1136
986
  };
1137
-
1138
987
  const _filterBy = predicate => {
1139
988
  self._propertyIterator = new Map(Array.from(self._propertyIterator).filter(predicate));
1140
989
  return self;
1141
990
  };
1142
-
1143
991
  const _forEach = iteratee => {
1144
992
  Array.from(self._propertyIterator).forEach(iteratee);
1145
993
  return self;
1146
994
  };
1147
-
1148
995
  const _getNodes = () => {
1149
996
  return Array.from(self._propertyIterator);
1150
997
  };
1151
-
1152
998
  const _getObject = () => {
1153
999
  return Array.from(self._propertyIterator).reduce((curr, node) => Object.assign(curr, {
1154
1000
  [node[0]]: node[1]
1155
1001
  }), {});
1156
1002
  };
1157
-
1158
1003
  const _getNames = () => {
1159
1004
  return Array.from(self._propertyIterator, ([name]) => name);
1160
1005
  };
1161
-
1162
1006
  const _getValues = () => {
1163
1007
  return Array.from(self._propertyIterator, ([, value]) => value);
1164
1008
  };
1165
-
1166
1009
  const self = {
1167
1010
  _propertyIterator: propertyIterator,
1168
1011
  orderBy: _orderBy,
@@ -1178,11 +1021,9 @@ const createSchemaPropertyList = (0, _curry.default)((context, shapeOrSchema) =>
1178
1021
  return self;
1179
1022
  });
1180
1023
  exports.createSchemaPropertyList = createSchemaPropertyList;
1181
-
1182
1024
  function isShape(shapeOrSchema) {
1183
1025
  return 'schema' in shapeOrSchema;
1184
1026
  }
1185
-
1186
1027
  class SchemaPropertyAccessor {
1187
1028
  constructor(context, shapeOrSchema) {
1188
1029
  const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
@@ -1190,33 +1031,24 @@ class SchemaPropertyAccessor {
1190
1031
  this.entries = (0, _utils.isObjectSchema)(this.schema) ? Object.entries(this.schema.properties) : [];
1191
1032
  this.properties = new Map(this.entries);
1192
1033
  }
1193
-
1194
1034
  getValue(propertyName) {
1195
1035
  return this.properties.get(propertyName);
1196
1036
  }
1197
-
1198
1037
  findValue(predicate) {
1199
1038
  var _this$entries$find;
1200
-
1201
1039
  return (_this$entries$find = this.entries.find(predicate)) === null || _this$entries$find === void 0 ? void 0 : _this$entries$find[1];
1202
1040
  }
1203
-
1204
1041
  findName(predicate) {
1205
1042
  var _this$entries$find2;
1206
-
1207
1043
  return (_this$entries$find2 = this.entries.find(predicate)) === null || _this$entries$find2 === void 0 ? void 0 : _this$entries$find2[0];
1208
1044
  }
1209
-
1210
1045
  getKey(propertyName) {
1211
1046
  const value = this.properties.get(propertyName);
1212
-
1213
1047
  if (value) {
1214
1048
  return getStorageKey(value);
1215
1049
  }
1216
1050
  }
1217
-
1218
1051
  }
1219
-
1220
1052
  /**
1221
1053
  * Creates a schema property accessor, allowing you to safely access schema
1222
1054
  * properties.
@@ -1225,7 +1057,6 @@ const createSchemaPropertyAccessor = (0, _curry.default)((context, shapeOrSchema
1225
1057
  return new SchemaPropertyAccessor(context, shapeOrSchema);
1226
1058
  });
1227
1059
  exports.createSchemaPropertyAccessor = createSchemaPropertyAccessor;
1228
-
1229
1060
  function findQueryHelper(slice, shapeName, resolver, type) {
1230
1061
  const schemaPath = type === 'query' ? 'queries' : 'mutations';
1231
1062
  return Object.keys(slice[schemaPath]).find(queryName => {
@@ -1233,51 +1064,37 @@ function findQueryHelper(slice, shapeName, resolver, type) {
1233
1064
  return queryOrMutation.resolver.name === resolver && queryOrMutation.resolver.shapeName === shapeName;
1234
1065
  });
1235
1066
  }
1236
-
1237
1067
  function ensureQueryHelper(slice, shapeName, resolver, type) {
1238
1068
  const foundQuery = findQueryHelper(slice, shapeName, resolver, type);
1239
-
1240
1069
  if (!foundQuery) {
1241
1070
  throw new Error(`Failed to find a "${resolver}" ${type} for shape "${shapeName}"`);
1242
1071
  }
1243
-
1244
1072
  return foundQuery;
1245
1073
  }
1074
+
1246
1075
  /**
1247
1076
  * Find the query in the schema that corresponds to the given shape and resolver.
1248
1077
  */
1249
-
1250
-
1251
1078
  const findQueryByShape = (projectSchema, shapeName, resolver) => findQueryHelper(projectSchema, shapeName, resolver, 'query');
1252
1079
  /**
1253
1080
  * Find the query in the schema that corresponds to the given shape and resolver.
1254
1081
  */
1255
-
1256
-
1257
1082
  exports.findQueryByShape = findQueryByShape;
1258
-
1259
1083
  const findMutationByShape = (projectSchema, shapeName, resolver) => findQueryHelper(projectSchema, shapeName, resolver, 'mutation');
1084
+
1260
1085
  /**
1261
1086
  * Find the query in the schema that corresponds to the given shape and resolver.
1262
1087
  * Throw an error if that query does not exist
1263
1088
  */
1264
-
1265
-
1266
1089
  exports.findMutationByShape = findMutationByShape;
1267
-
1268
1090
  const ensureQueryByShape = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'query');
1269
1091
  /**
1270
1092
  * Find the mutation in the schema that corresponds to the given shape and resolver.
1271
1093
  * Throw an error if that mutation does not exist
1272
1094
  */
1273
-
1274
-
1275
1095
  exports.ensureQueryByShape = ensureQueryByShape;
1276
-
1277
1096
  const ensureMutationByShape = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'mutation');
1278
-
1279
1097
  exports.ensureMutationByShape = ensureMutationByShape;
1280
-
1281
1098
  /**
1282
1099
  * Find the query in the schema that corresponds to the given shape and resolver.
1283
1100
  */
@@ -1285,9 +1102,7 @@ const getDefaultMutationName = (shapeName, resolver) => {
1285
1102
  const action = resolver.substring(resolver.indexOf(':') + 1);
1286
1103
  return `${action}${shapeName}`;
1287
1104
  };
1288
-
1289
1105
  exports.getDefaultMutationName = getDefaultMutationName;
1290
-
1291
1106
  function createShape(name, schema, rest) {
1292
1107
  return {
1293
1108
  name,
@@ -1297,10 +1112,8 @@ function createShape(name, schema, rest) {
1297
1112
  ...rest
1298
1113
  };
1299
1114
  }
1300
-
1301
1115
  function queryToPropertySchema(projectSchema, query) {
1302
1116
  let mapping;
1303
-
1304
1117
  if ((0, _utils.isGraphqlResolver)(query.resolver)) {
1305
1118
  mapping = (0, _refs.serializePropertyRef)({
1306
1119
  serviceId: query.resolver.service,
@@ -1308,8 +1121,8 @@ function queryToPropertySchema(projectSchema, query) {
1308
1121
  propertyName: query.resolver.fieldName
1309
1122
  });
1310
1123
  }
1311
-
1312
- return { ...(0, _refs.returnShapeToSchema)(projectSchema, query.shape),
1124
+ return {
1125
+ ...(0, _refs.returnShapeToSchema)(projectSchema, query.shape),
1313
1126
  ...(mapping ? {
1314
1127
  '@mapping': mapping
1315
1128
  } : {}),
@@ -1317,53 +1130,44 @@ function queryToPropertySchema(projectSchema, query) {
1317
1130
  '@args': query.args
1318
1131
  };
1319
1132
  }
1320
-
1321
1133
  function getQueriesShape(projectSchema, operation) {
1322
1134
  return createShape((0, _util.pascalCase)(operation), {
1323
1135
  type: 'object',
1324
1136
  properties: (0, _mapValues.default)(projectSchema[operation === 'query' ? 'queries' : 'mutations'], query => queryToPropertySchema(projectSchema, query))
1325
1137
  });
1326
1138
  }
1327
-
1328
1139
  function fieldMappingContainsKey(fieldMapping, key) {
1329
1140
  if ((0, _isArray.default)(fieldMapping)) {
1330
1141
  return (0, _some.default)(fieldMapping, mapping => parseMapping(mapping).key === key);
1331
1142
  }
1332
-
1333
1143
  return parseMapping(fieldMapping).key === key;
1334
1144
  }
1145
+
1335
1146
  /**
1336
1147
  * Return true if `schemaWithRef` is a ref to a shape named `shapeName`
1337
1148
  */
1338
-
1339
-
1340
1149
  const schemaMatchesShapeName = (workingCopy, schemaWithRef, shapeName) => {
1341
1150
  const arrayOfShapeRef = (0, _refs.getRef)(workingCopy, schemaWithRef);
1342
1151
  (0, _tinyInvariant.default)(arrayOfShapeRef);
1343
1152
  const arrayOfShapeName = (0, _refs.refItemToShapeName)(arrayOfShapeRef);
1344
1153
  return arrayOfShapeName === shapeName;
1345
1154
  };
1155
+
1346
1156
  /**
1347
1157
  * Return true if `shape` has a property that is an array of refs to `shapeName`
1348
1158
  */
1349
-
1350
-
1351
1159
  exports.schemaMatchesShapeName = schemaMatchesShapeName;
1352
-
1353
1160
  const shapeHasArrayPropOfShape = (projectSchema, shape, shapeName) => {
1354
1161
  if (shape && (0, _utils.isObjectSchema)(shape.schema)) {
1355
1162
  for (const propName in shape.schema.properties) {
1356
1163
  if (Object.prototype.hasOwnProperty.call(shape.schema.properties, propName)) {
1357
1164
  const propSchema = shape.schema.properties[propName];
1358
-
1359
1165
  if (propSchema.items && (0, _utils.isRefSchema)(propSchema.items) && schemaMatchesShapeName(projectSchema, propSchema.items, shapeName)) {
1360
1166
  return true;
1361
1167
  }
1362
1168
  }
1363
1169
  }
1364
1170
  }
1365
-
1366
1171
  return false;
1367
1172
  };
1368
-
1369
1173
  exports.shapeHasArrayPropOfShape = shapeHasArrayPropOfShape;