@takeshape/schema 9.80.4 → 9.81.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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/es/types/utils.js CHANGED
@@ -7,12 +7,12 @@ import has from 'lodash/has';
7
7
  import { latestSchemaJson } from '../schemas';
8
8
  import isUndefined from 'lodash/isUndefined';
9
9
  import { isCachedShape } from '../schema-util';
10
+
10
11
  /** Resolver Type Utils **/
11
12
 
12
13
  /**
13
14
  * Only tests that the shape is right, not that the name is correct. That's a job for the validator.
14
15
  */
15
-
16
16
  export function isBasicResolver(resolver) {
17
17
  return isRecord(resolver) && isString(resolver.name);
18
18
  }
@@ -53,81 +53,77 @@ export function isUtilResolver(resolver) {
53
53
  export function isProjectSchemaWithServices(schema) {
54
54
  return !isUndefined(schema.services);
55
55
  }
56
+
56
57
  /** Directive Mapping Utils **/
57
58
 
58
59
  /**
59
60
  * Determine whether the ambiguous Directive structure is a DirectiveMappingMap
60
61
  */
61
-
62
62
  export function isDirectiveMappingMap(maybeMap) {
63
63
  return isPlainObject(maybeMap) && Object.keys(maybeMap).length > 0;
64
64
  }
65
+
65
66
  /**
66
67
  * Determine whether the ambiguous Directive structure is a DirectiveMappingArray
67
68
  */
68
-
69
69
  export function isDirectiveMappingArray(maybeArray) {
70
70
  return isArray(maybeArray) && isArray(maybeArray[0]) && isString(maybeArray[0][0]) && isArray(maybeArray[0][1]);
71
71
  }
72
+
72
73
  /**
73
74
  * Determine whether the ambiguous Directive structure is a DirectiveConfig array
74
75
  */
75
-
76
76
  export function isDirectiveConfig(maybeConfig) {
77
77
  return isArray(maybeConfig) && isArray(maybeConfig[0]) && isString(maybeConfig[0][0]) && isRecord(maybeConfig[0][1]);
78
78
  }
79
+
79
80
  /**
80
81
  * Determine whether a ParameterSerializeOption is a content type serializer
81
82
  */
82
-
83
83
  export function isParameterSerializeContentOptions(maybeContent) {
84
84
  return Boolean(maybeContent.contentType);
85
85
  }
86
+
86
87
  /**
87
88
  * Determine whether an unknown variable is a `ParameterOp`
88
89
  */
89
-
90
90
  export function isParameterOp(maybeOp) {
91
91
  const op = maybeOp;
92
-
93
92
  if (!op.path) {
94
93
  return false;
95
94
  }
96
-
97
95
  return isParameterOpNested(op) || isParameterOpMapping(op) || isParameterOpValue(op) || isParameterOpOp(op);
98
96
  }
97
+
99
98
  /**
100
99
  * Determine whether a `ParameterOp` is a `ParameterOpNested`
101
100
  */
102
-
103
101
  export function isParameterOpNested(maybeOp) {
104
102
  return Boolean(maybeOp.ops);
105
103
  }
104
+
106
105
  /**
107
106
  * Determine whether a `ParameterOp` is a `ParameterOpMapping`
108
107
  */
109
-
110
108
  export function isParameterOpMapping(maybeOp) {
111
109
  return Boolean(maybeOp.mapping);
112
110
  }
111
+
113
112
  /**
114
113
  * Determine whether a `ParameterOp` is a `ParameterOpMapping`
115
114
  */
116
-
117
115
  export function isParameterOpValue(maybeOp) {
118
116
  return Boolean(maybeOp.value);
119
117
  }
118
+
120
119
  /**
121
120
  * Determine whether a `ParameterOp` is a `ParameterOpOp`
122
121
  */
123
-
124
122
  export function isParameterOpOp(maybeOp) {
125
123
  const op = maybeOp;
126
-
127
124
  if (!op.op) {
128
125
  return false;
129
126
  }
130
-
131
127
  return !(isParameterOpNested(op) || isParameterOpMapping(op) || isParameterOpValue(op));
132
128
  }
133
129
  const {
@@ -142,13 +138,14 @@ export function isParameterSerializeStyleForSearchParams(maybeParam) {
142
138
  export function isParameterSerializeStyleForPathParams(maybeParam) {
143
139
  return Boolean(maybeParam && parameterSerializeStyleOptionsForPathParams.properties.style.enum.includes(maybeParam));
144
140
  }
141
+
145
142
  /**
146
143
  * Determine whether a ParameterSerializeOption is a style serializer
147
144
  */
148
-
149
145
  export function isParameterSerializeStyleOptions(maybeStyle) {
150
146
  return Boolean(maybeStyle.style);
151
147
  }
148
+
152
149
  /** Typeguards for different types of shape schemas **/
153
150
 
154
151
  export function isRefSchema(propertySchema) {
@@ -178,19 +175,18 @@ export function isReturnShapeArraySchema(returnShape) {
178
175
  export function isObjectSchema(propertySchema) {
179
176
  return isRecord(propertySchema) && propertySchema.type === 'object' && isRecord(propertySchema.properties);
180
177
  }
178
+
181
179
  /** Service Config Utils **/
182
180
 
183
181
  /**
184
182
  * Test all required props, currently:
185
183
  * "name", "slug", "provider", "serviceType", "authenticationType"
186
184
  */
187
-
188
185
  export function isAnyServiceConfig(maybeConfig) {
189
186
  return maybeConfig && isString(maybeConfig.title) && isString(maybeConfig.id) && isString(maybeConfig.provider) && isString(maybeConfig.serviceType) && isString(maybeConfig.authenticationType);
190
187
  }
191
188
  export function isGraphQLServiceConfig(maybeConfig) {
192
189
  var _maybeConfig$options;
193
-
194
190
  return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && isString((_maybeConfig$options = maybeConfig.options) === null || _maybeConfig$options === void 0 ? void 0 : _maybeConfig$options.endpoint);
195
191
  }
196
192
  export function isRESTServiceConfig(maybeConfig) {
@@ -211,6 +207,7 @@ export function isServiceConfigWithOAuth2Authentication(maybeServiceConfig) {
211
207
  export function isServiceConfigWithCustomAuthentication(maybeServiceConfig) {
212
208
  return isAnyServiceConfig(maybeServiceConfig) && isServiceAuthentication(maybeServiceConfig.authentication) && isCustomAuthentication(maybeServiceConfig.authentication);
213
209
  }
210
+
214
211
  /** Authentication Utils **/
215
212
 
216
213
  export function isServiceAuthentication(maybeAuthentication) {
@@ -234,6 +231,7 @@ export function isOAuth2BearerAuthentication(authentication) {
234
231
  export function isCustomAuthentication(authentication) {
235
232
  return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'custom';
236
233
  }
234
+
237
235
  /** Miscellaneous Utils **/
238
236
 
239
237
  /**
@@ -241,34 +239,30 @@ export function isCustomAuthentication(authentication) {
241
239
  *
242
240
  * @param argsSchema Any schema that may have an `args` property.
243
241
  */
244
-
245
242
  export const getArgsType = argsSchema => {
246
243
  if (has(argsSchema, '@args')) {
247
244
  return ArgsType['@args'];
248
245
  }
249
-
250
246
  if (has(argsSchema, 'args')) {
251
247
  return ArgsType.args;
252
248
  }
253
249
  };
250
+
254
251
  /**
255
252
  * A utility to return the type of ref present on a schema.
256
253
  *
257
254
  * @param refSchema Any schema that may have a `ref` property.
258
255
  */
259
-
260
256
  export const getRefType = refSchema => {
261
257
  if (has(refSchema, '@ref')) {
262
258
  return RefType['@ref'];
263
259
  }
264
-
265
260
  if (has(refSchema, '$ref')) {
266
261
  return RefType.$ref;
267
262
  }
268
263
  };
269
264
  export function isPropertySchemaWithRelationship(schema) {
270
265
  var _schema$Resolver;
271
-
272
266
  return ((_schema$Resolver = schema['@resolver']) === null || _schema$Resolver === void 0 ? void 0 : _schema$Resolver.name) === 'shapedb:getRelated';
273
267
  }
274
268
  export function listCachedShapes(shapes) {
@@ -276,13 +270,11 @@ export function listCachedShapes(shapes) {
276
270
  }
277
271
  export function getCachedShapeMap(shapes) {
278
272
  const results = {};
279
-
280
273
  for (const shape of Object.values(shapes)) {
281
274
  if (isCachedShape(shape)) {
282
275
  results[shape.name] = shape;
283
276
  }
284
277
  }
285
-
286
278
  return results;
287
279
  }
288
280
  export function isMeshShape(shape) {
package/es/unions.js CHANGED
@@ -8,13 +8,10 @@ import { getShapeById } from './schema-util';
8
8
  import { getOutputShapeName } from './template-shapes/templates';
9
9
  export function enumerateOneOfKeys(projectSchema, oneOf) {
10
10
  const result = [];
11
-
12
11
  for (const child of oneOf) {
13
12
  const refItem = getRef(projectSchema, child);
14
-
15
13
  if (refItem) {
16
14
  const shapeName = refItemToShapeName(refItem);
17
-
18
15
  if (projectSchema.shapes[shapeName]) {
19
16
  const shapeId = projectSchema.shapes[shapeName].id;
20
17
  result.push({
@@ -26,78 +23,67 @@ export function enumerateOneOfKeys(projectSchema, oneOf) {
26
23
  }
27
24
  }
28
25
  }
29
-
30
26
  return result;
31
27
  }
32
-
33
28
  function getOneOf(schema) {
34
29
  if (!schema.oneOf) {
35
30
  throw new Error(`Expected ${JSON.stringify(schema)} to be a oneOf schema`);
36
31
  }
37
-
38
32
  return schema.oneOf;
39
33
  }
40
-
41
34
  export function isUnionSchema(schema) {
42
35
  var _schema$oneOf;
43
-
44
36
  return Boolean((_schema$oneOf = schema.oneOf) === null || _schema$oneOf === void 0 ? void 0 : _schema$oneOf.every(isRefSchema));
45
37
  }
46
38
  export function oneOfToObject(projectSchema, schema) {
47
39
  const properties = {};
48
-
49
40
  for (const {
50
41
  propName,
51
42
  propSchema: child
52
43
  } of enumerateOneOfKeys(projectSchema, getOneOf(schema))) {
53
44
  properties[propName] = child;
54
45
  }
55
-
56
- return { ...omit(schema, 'oneOf'),
46
+ return {
47
+ ...omit(schema, 'oneOf'),
57
48
  type: 'object',
58
49
  properties
59
50
  };
60
51
  }
61
-
62
52
  function formatKeys(keys) {
63
53
  return keys.map(k => `"${k}"`).join(', ');
64
54
  }
65
-
66
55
  // eslint-disable-next-line max-params
67
56
  export const createUnwrapTransform = projectSchema => (obj, schema, name, shape, next) => {
68
57
  if (isRecord(obj)) {
69
58
  const oneOfKeys = enumerateOneOfKeys(projectSchema, getOneOf(schema));
70
59
  const objectKeys = Object.keys(obj);
71
-
72
60
  if (objectKeys.length !== 1) {
73
61
  const propNames = oneOfKeys.map(k => k.propName);
74
62
  throw new BadDataError(`Object should only specify one of the following keys: ${formatKeys(propNames)}, but found keys: ${formatKeys(objectKeys)}`);
75
63
  }
76
-
77
64
  for (const {
78
65
  propName,
79
66
  shapeId,
80
67
  propSchema
81
68
  } of oneOfKeys) {
82
69
  const propValue = obj[propName];
83
-
84
70
  if (isRecord(propValue)) {
85
71
  const transformedPropValue = next(propValue, propSchema, name);
86
-
87
72
  if (isRecord(transformedPropValue)) {
88
- return { ...transformedPropValue,
73
+ return {
74
+ ...transformedPropValue,
89
75
  _shapeId: shapeId
90
76
  };
91
77
  }
92
78
  }
93
79
  }
94
80
  }
95
- }; // eslint-disable-next-line max-params
81
+ };
96
82
 
83
+ // eslint-disable-next-line max-params
97
84
  export const createWrapTransform = projectSchema => (obj, schema, name, shape, next) => {
98
85
  if (isRecord(obj) && typeof obj._shapeId === 'string') {
99
86
  const shape = getShapeById(projectSchema, obj._shapeId);
100
-
101
87
  if (shape) {
102
88
  return {
103
89
  [camelCase(shape.name)]: next(omit(obj, '_shapeId'), shape.schema, name)
@@ -122,17 +108,17 @@ export function transformOneOf(process) {
122
108
  return transform(schema, obj);
123
109
  };
124
110
  }
111
+
125
112
  /**
126
113
  * Unwrap oneOf objects in "GraphQL oneOf" style wrapper objects
127
114
  * See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
128
115
  * Opposite of `wrapOneOfObjects`
129
116
  */
130
-
131
117
  export const unwrapOneOfObjects = transformOneOf(createUnwrapTransform);
118
+
132
119
  /**
133
120
  * Wrap oneOf objects in "GraphQL oneOf" style wrapper objects
134
121
  * See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
135
122
  * Opposite of `unwrapOneOfObjects`
136
123
  */
137
-
138
124
  export const wrapOneOfObjects = transformOneOf(createWrapTransform);
@@ -6,23 +6,19 @@ import { getQuery } from '../refs';
6
6
  export function serviceHasIndexedShapes(schema, serviceId) {
7
7
  for (const shape of Object.values(schema.shapes ?? {})) {
8
8
  var _shape$loaders;
9
-
10
9
  const indexingEnabled = isCachedShape(shape);
11
10
  const listConfigs = (_shape$loaders = shape.loaders) === null || _shape$loaders === void 0 ? void 0 : _shape$loaders.list;
12
-
13
11
  if (indexingEnabled && listConfigs) {
14
12
  for (const {
15
13
  query: queryRef
16
14
  } of ensureArray(listConfigs)) {
17
15
  const resolved = getQuery(schema, queryRef);
18
-
19
16
  if (resolved && isServiceResolver(resolved.query.resolver) && resolved.query.resolver.service === serviceId) {
20
17
  return true;
21
18
  }
22
19
  }
23
20
  }
24
21
  }
25
-
26
22
  return false;
27
23
  }
28
24
  export function getIndexedServices(projectSchema, configs) {
@@ -31,15 +27,14 @@ export function getIndexedServices(projectSchema, configs) {
31
27
  return resolved !== null && resolved !== void 0 && resolved.query ? [...services, ...getResolverServices(resolved.query.resolver)] : services;
32
28
  }, []);
33
29
  }
34
-
35
30
  function flattenListQueryConfigs(base, queryConfig, maybeConfigArray) {
36
- return maybeConfigArray && ensureArray(maybeConfigArray).flatMap(config => ensureArray(config.args).map(args => ({ ...base,
31
+ return maybeConfigArray && ensureArray(maybeConfigArray).flatMap(config => ensureArray(config.args).map(args => ({
32
+ ...base,
37
33
  ...queryConfig,
38
34
  ...config,
39
35
  args
40
36
  })));
41
37
  }
42
-
43
38
  function getQueryIndexConfigHelper(op) {
44
39
  return ({
45
40
  shapes
@@ -48,19 +43,15 @@ function getQueryIndexConfigHelper(op) {
48
43
  cache,
49
44
  loaders
50
45
  } = shapes[shapeName] ?? {};
51
-
52
46
  if (cache && loaders) {
53
47
  const idField = cache.idField ?? 'id';
54
-
55
48
  if (op === 'list') {
56
49
  return flattenListQueryConfigs({
57
50
  shapeName,
58
51
  idField
59
52
  }, cache.fragment, loaders.list);
60
53
  }
61
-
62
54
  const queryConfig = loaders.get;
63
-
64
55
  if (queryConfig) {
65
56
  return {
66
57
  idField,
@@ -72,6 +63,5 @@ function getQueryIndexConfigHelper(op) {
72
63
  }
73
64
  };
74
65
  }
75
-
76
66
  export const getListQueryIndexConfigs = getQueryIndexConfigHelper('list');
77
67
  export const getGetQueryIndexConfig = getQueryIndexConfigHelper('get');
@@ -1,12 +1,10 @@
1
1
  import { getRef, refItemToShape } from '../refs';
2
2
  import { value } from '@takeshape/util';
3
-
4
3
  function immutableSetAdd(set, str) {
5
4
  const result = new Set(set);
6
5
  result.add(str);
7
6
  return result;
8
7
  }
9
-
10
8
  /**
11
9
  * Use a basic depth-first search to determine whether a schema contains a cycle
12
10
  */
@@ -15,46 +13,36 @@ export function hasCycle(projectSchema, schema, predicate = value(true)) {
15
13
  if (!predicate(projectSchema, schema, shapeName, propName)) {
16
14
  return false;
17
15
  }
18
-
19
16
  const refItem = getRef(projectSchema, schema);
20
-
21
17
  if (refItem) {
22
- const refShape = refItemToShape(projectSchema, refItem); // If we have a refItem, but no shape, this is a dangling ref and has no cycles
18
+ const refShape = refItemToShape(projectSchema, refItem);
23
19
 
20
+ // If we have a refItem, but no shape, this is a dangling ref and has no cycles
24
21
  if (!refShape) {
25
22
  return false;
26
23
  }
27
-
28
24
  if (shapesSeen.has(refShape.name)) {
29
25
  return true;
30
26
  }
31
-
32
27
  return hasCycleHelper(refShape.schema, immutableSetAdd(shapesSeen, refShape.name), refShape.name);
33
28
  }
34
-
35
29
  const combo = schema.oneOf ?? schema.allOf ?? schema.extends;
36
-
37
30
  if (combo) {
38
31
  return combo.some(childSchema => hasCycleHelper(childSchema, shapesSeen, shapeName, propName));
39
32
  }
40
-
41
33
  if (schema.items) {
42
34
  return hasCycleHelper(schema.items, shapesSeen, shapeName, propName);
43
35
  }
44
-
45
36
  const {
46
37
  properties
47
38
  } = schema;
48
-
49
39
  if (properties) {
50
40
  return Object.keys(properties).some(name => {
51
41
  const propSchema = properties[name];
52
42
  return hasCycleHelper(propSchema, shapesSeen, shapeName, name);
53
43
  });
54
44
  }
55
-
56
45
  return false;
57
46
  };
58
-
59
47
  return hasCycleHelper(schema);
60
48
  }
@@ -1,5 +1,6 @@
1
1
  import { isArraySchema, isObjectSchema, isRefSchema } from '../types';
2
2
  import { getRef, refItemToShape, refItemToShapeSchema } from '../refs';
3
+
3
4
  /**
4
5
  *
5
6
  * @param projectSchema
@@ -9,42 +10,33 @@ import { getRef, refItemToShape, refItemToShapeSchema } from '../refs';
9
10
  * @example
10
11
  * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds {'@ref': Shopify_Product}
11
12
  */
12
-
13
13
  export function findSchemaAtPath(projectSchema, schema, queryPath) {
14
14
  if (queryPath.length === 0) {
15
15
  return schema;
16
16
  }
17
-
18
17
  const [prop, ...rest] = queryPath;
19
-
20
18
  if (isRefSchema(schema)) {
21
19
  const ref = getRef(projectSchema, schema);
22
-
23
20
  if (ref) {
24
21
  const shapeSchema = refItemToShapeSchema(projectSchema, ref);
25
-
26
22
  if (shapeSchema) {
27
23
  return findSchemaAtPath(projectSchema, shapeSchema, queryPath);
28
24
  }
29
25
  }
30
-
31
26
  return undefined;
32
27
  }
33
-
34
28
  if (isArraySchema(schema)) {
35
29
  return findSchemaAtPath(projectSchema, schema.items, queryPath);
36
30
  }
37
-
38
31
  if (isObjectSchema(schema)) {
39
32
  const propSchema = schema.properties[prop];
40
-
41
33
  if (propSchema) {
42
34
  return findSchemaAtPath(projectSchema, propSchema, rest);
43
35
  }
44
36
  }
45
-
46
37
  return undefined;
47
38
  }
39
+
48
40
  /**
49
41
  *
50
42
  * @param projectSchema
@@ -54,10 +46,8 @@ export function findSchemaAtPath(projectSchema, schema, queryPath) {
54
46
  * @example
55
47
  * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds Shopify_Product
56
48
  */
57
-
58
49
  export function findShapeAtPath(projectSchema, propSchema, queryPath) {
59
50
  const result = findSchemaAtPath(projectSchema, propSchema, queryPath);
60
-
61
51
  if (result) {
62
52
  const refItem = getRef(projectSchema, result.items ?? result);
63
53
  return refItem && refItemToShape(projectSchema, refItem);
@@ -1,17 +1,16 @@
1
1
  import { deepClone } from '@takeshape/util';
2
2
  import { getRefOrItemsRef, refItemToShapeName } from '../refs';
3
3
  import { createSchemaPropertyAccessor } from '../schema-util';
4
+
4
5
  /**
5
6
  * If there any non-normal (nested) forms in the schema, create forms for referenced shapes.
6
7
  * The original forms are left intact.
7
8
  */
8
-
9
9
  export function normalizeForms(projectSchema) {
10
10
  const normalizedForms = {};
11
11
  const {
12
12
  forms = {}
13
13
  } = projectSchema;
14
-
15
14
  const storeSourceForm = (shapeName, formConfig, propName) => {
16
15
  // Leave original forms intact for backwards compatibility
17
16
  if (!forms[shapeName]) {
@@ -19,30 +18,24 @@ export function normalizeForms(projectSchema) {
19
18
  normalizedForms[shapeName] = {
20
19
  default: deepClone(formConfig)
21
20
  };
22
- } // Remove prop now that it has been normalized
23
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
24
-
21
+ }
25
22
 
23
+ // Remove prop now that it has been normalized
24
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
26
25
  delete normalizedForms[shapeName].default.properties[propName];
27
26
  }
28
27
  };
29
-
30
28
  const normalizeNested = (shapeName, formConfig) => {
31
29
  const shape = projectSchema.shapes[shapeName];
32
-
33
30
  if (!shape || !formConfig.properties) {
34
31
  return;
35
32
  }
36
-
37
33
  const propertyAccessor = createSchemaPropertyAccessor(projectSchema, shape);
38
-
39
34
  for (const propName of Object.keys(formConfig.properties)) {
40
35
  const propConfig = formConfig.properties[propName];
41
36
  const propSchema = propertyAccessor.getValue(propName);
42
-
43
37
  if (propSchema) {
44
38
  const ref = getRefOrItemsRef(projectSchema, propSchema);
45
-
46
39
  if (ref && propConfig.properties) {
47
40
  const nestedShapeName = refItemToShapeName(ref);
48
41
  normalizedForms[nestedShapeName] = {
@@ -54,37 +47,32 @@ export function normalizeForms(projectSchema) {
54
47
  }
55
48
  }
56
49
  };
57
-
58
50
  if (forms) {
59
51
  for (const shapeName of Object.keys(forms)) {
60
- normalizeNested(shapeName, forms[shapeName].default); // copy forms with no changes
52
+ normalizeNested(shapeName, forms[shapeName].default);
61
53
 
54
+ // copy forms with no changes
62
55
  if (!normalizedForms[shapeName]) {
63
56
  normalizedForms[shapeName] = forms[shapeName];
64
57
  }
65
58
  }
66
59
  }
67
-
68
60
  return normalizedForms;
69
61
  }
70
62
  const cache = new WeakMap();
63
+
71
64
  /**
72
65
  * Find the form config for a given shape name and the form key.
73
66
  */
74
-
75
67
  export function findShapeFormConfig(projectSchema, shapeName, formName) {
76
68
  var _normalizedForms$shap;
77
-
78
69
  if (!projectSchema.forms) {
79
70
  return;
80
71
  }
81
-
82
72
  let normalizedForms = cache.get(projectSchema);
83
-
84
73
  if (!normalizedForms) {
85
74
  normalizedForms = normalizeForms(projectSchema);
86
75
  cache.set(projectSchema, normalizedForms);
87
76
  }
88
-
89
77
  return (_normalizedForms$shap = normalizedForms[shapeName]) === null || _normalizedForms$shap === void 0 ? void 0 : _normalizedForms$shap[formName];
90
78
  }
@@ -1,10 +1,10 @@
1
1
  import { dereferenceSchema, getRef, refItemToAtRef } from '../refs';
2
2
  import { isDefined, setIsEqual } from '@takeshape/util';
3
3
  import { isObjectSchema } from '../types';
4
+
4
5
  /**
5
6
  * Normalize ref, oneOf and array schemas and get a list of @ref expressions
6
7
  */
7
-
8
8
  function getRefStrings(context, propertySchema) {
9
9
  const schema = propertySchema.items ?? propertySchema;
10
10
  const schemas = schema.oneOf ? schema.oneOf : [schema];
@@ -13,40 +13,35 @@ function getRefStrings(context, propertySchema) {
13
13
  return ref ? refItemToAtRef(ref) : undefined;
14
14
  }).filter(isDefined);
15
15
  }
16
-
17
16
  function isRefEqual(context, a, b) {
18
17
  return setIsEqual(getRefStrings(context, a), getRefStrings(context, b));
19
18
  }
19
+
20
20
  /**
21
21
  * Given a list of shapes find the conflicting props
22
22
  */
23
-
24
-
25
23
  export function getConflictingProperties(context, shapes) {
26
24
  const conflicts = new Set();
27
25
  const allProps = {};
28
-
29
26
  for (const shape of Object.values(shapes)) {
30
27
  const schema = dereferenceSchema(context, shape.schema, ['shapes', shape.name]);
31
-
32
28
  if (!isObjectSchema(schema)) {
33
29
  continue;
34
30
  }
35
-
36
31
  const required = new Set(schema.required ?? []);
37
-
38
32
  for (const [name, prop] of Object.entries(schema.properties)) {
39
33
  // skip props that we know already have conflict
40
34
  if (conflicts.has(name)) {
41
35
  continue;
42
36
  }
43
-
44
37
  const isRequired = required.has(name);
45
-
46
38
  if (allProps[name]) {
47
- if ( // same type
48
- allProps[name][0].type !== prop.type || // same refs
49
- !isRefEqual(context, allProps[name][0], prop) || // same nullability
39
+ if (
40
+ // same type
41
+ allProps[name][0].type !== prop.type ||
42
+ // same refs
43
+ !isRefEqual(context, allProps[name][0], prop) ||
44
+ // same nullability
50
45
  isRequired !== allProps[name][1]) {
51
46
  conflicts.add(name);
52
47
  }
@@ -55,6 +50,5 @@ export function getConflictingProperties(context, shapes) {
55
50
  }
56
51
  }
57
52
  }
58
-
59
53
  return conflicts;
60
54
  }