@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
@@ -12,23 +12,14 @@ exports.getRelationshipShapeRefs = getRelationshipShapeRefs;
12
12
  exports.getRelationshipShapes = getRelationshipShapes;
13
13
  exports.hasUnequalRelationships = hasUnequalRelationships;
14
14
  exports.isEqualRelationship = isEqualRelationship;
15
-
16
15
  var _util = require("@takeshape/util");
17
-
18
16
  var _types = require("./types");
19
-
20
17
  var _schemaUtil = require("./schema-util");
21
-
22
18
  var _refs = require("./refs");
23
-
24
19
  var _unions = require("./unions");
25
-
26
20
  var _builtinSchema = require("./builtin-schema");
27
-
28
21
  var _find = _interopRequireDefault(require("lodash/find"));
29
-
30
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
23
  /**
33
24
  * Turn a LegacyRelationship into a partial PropertySchemaWithRelationship.
34
25
  */
@@ -45,7 +36,6 @@ function getRelationshipSchema(projectSchema, relationship) {
45
36
  };
46
37
  let isMultiple;
47
38
  let shapeRefs;
48
-
49
39
  if ('shapeIds' in relationship) {
50
40
  shapeRefs = relationship.shapeIds.map(shapeId => {
51
41
  const shape = (0, _schemaUtil.getShapeById)(projectSchema, shapeId) ?? (0, _find.default)(_builtinSchema.builtInShapes, shape => shape.id === shapeId);
@@ -60,17 +50,15 @@ function getRelationshipSchema(projectSchema, relationship) {
60
50
  }));
61
51
  isMultiple = relationship.isMultiple;
62
52
  }
63
-
64
53
  if (!shapeRefs.length) {
65
54
  throw new Error(`Invalid empty relationship ${JSON.stringify(relationship)}`);
66
55
  }
67
-
68
56
  const shapeRefsSchema = shapeRefs.length === 1 ? shapeRefs[0] : {
69
57
  oneOf: shapeRefs
70
58
  };
71
-
72
59
  if (isMultiple) {
73
- return { ...propertySchema,
60
+ return {
61
+ ...propertySchema,
74
62
  type: 'array',
75
63
  items: shapeRefsSchema,
76
64
  '@input': {
@@ -81,36 +69,32 @@ function getRelationshipSchema(projectSchema, relationship) {
81
69
  }
82
70
  };
83
71
  }
84
-
85
- return { ...propertySchema,
72
+ return {
73
+ ...propertySchema,
86
74
  ...shapeRefsSchema,
87
75
  '@input': {
88
76
  '@ref': 'local:TSRelationship'
89
77
  }
90
78
  };
91
79
  }
80
+
92
81
  /**
93
82
  * Get a list of refs given a property schema with a relationship resolver.
94
83
  */
95
-
96
-
97
84
  function getRelationshipShapeRefs(propertySchema) {
98
85
  let refs = [];
99
86
  const schema = propertySchema.items ?? propertySchema;
100
-
101
87
  if (schema.oneOf) {
102
88
  refs = schema.oneOf.map(schema => schema['@ref']).filter(_util.isDefined);
103
89
  } else if (schema['@ref']) {
104
90
  refs = [schema['@ref']];
105
91
  }
106
-
107
92
  return refs;
108
93
  }
94
+
109
95
  /**
110
96
  * Get a list of shapes given a property schema with a relationship resolver.
111
97
  */
112
-
113
-
114
98
  function getRelationshipShapes(shapes, refs) {
115
99
  return refs.map(ref => {
116
100
  const shapeName = ref.split(':')[1];
@@ -118,11 +102,10 @@ function getRelationshipShapes(shapes, refs) {
118
102
  return shape ? shape : undefined;
119
103
  }).filter(_util.isDefined);
120
104
  }
105
+
121
106
  /**
122
107
  * Get a list of shape ids given a property schema with a relationship resolver.
123
108
  */
124
-
125
-
126
109
  function getRelationshipShapeIds(shapes, refs) {
127
110
  return refs.map(ref => {
128
111
  const shapeName = ref.split(':')[1];
@@ -130,31 +113,26 @@ function getRelationshipShapeIds(shapes, refs) {
130
113
  return shape ? shape.id : undefined;
131
114
  }).filter(_util.isDefined);
132
115
  }
116
+
133
117
  /**
134
118
  * Turn a Relationship into a LegacyRelationship object.
135
119
  */
136
-
137
-
138
120
  function getLegacyRelationship(projectSchema, relationship) {
139
121
  return {
140
122
  type: relationship.isMultiple ? 'multiple' : 'single',
141
123
  shapeIds: getRelationshipShapeIds(projectSchema.shapes, relationship.refs)
142
124
  };
143
125
  }
126
+
144
127
  /**
145
128
  * Get relationship details from a PropertySchema.
146
129
  */
147
-
148
-
149
130
  function getRelationship(propertySchema) {
150
131
  var _propertySchema$Back, _propertySchema$Back2;
151
-
152
132
  propertySchema = propertySchema['@output'] ?? propertySchema;
153
-
154
133
  if (!(0, _types.isPropertySchemaWithRelationship)(propertySchema)) {
155
134
  return;
156
135
  }
157
-
158
136
  const isMultiple = propertySchema.type === 'array';
159
137
  const hasBackreference = Boolean((_propertySchema$Back = propertySchema['@backreference']) === null || _propertySchema$Back === void 0 ? void 0 : _propertySchema$Back.enabled);
160
138
  const backreferenceName = (_propertySchema$Back2 = propertySchema['@backreference']) === null || _propertySchema$Back2 === void 0 ? void 0 : _propertySchema$Back2.name;
@@ -166,34 +144,26 @@ function getRelationship(propertySchema) {
166
144
  backreferenceName
167
145
  };
168
146
  }
169
-
170
147
  function addRelationship(relationships, id, env) {
171
148
  if (!relationships[id]) {
172
149
  relationships[id] = [];
173
150
  }
174
-
175
151
  relationships[id].push(env);
176
152
  }
177
-
178
153
  function findExistingRelationships(projectSchema, shapes) {
179
154
  const relationships = {};
180
155
  const shapeArray = Object.values(shapes);
181
156
  const shapesSeen = new Set();
182
157
  const shapeIds = new Set(shapeArray.map(shape => shape.id));
183
-
184
158
  const findRelationships = (schema, path, parentShapeName) => {
185
159
  const relationship = getRelationship(schema);
186
-
187
160
  if (relationship) {
188
161
  var _schema$Backreferenc;
189
-
190
162
  const relatedShapeIds = getRelationshipShapeIds(shapes, relationship.refs);
191
163
  const relatedName = (_schema$Backreferenc = schema['@backreference']) === null || _schema$Backreferenc === void 0 ? void 0 : _schema$Backreferenc.name;
192
-
193
164
  for (const shapeId of relatedShapeIds) {
194
165
  if (shapeIds.has(shapeId)) {
195
166
  var _schema$Backreferenc2;
196
-
197
167
  addRelationship(relationships, shapeId, {
198
168
  relatedName,
199
169
  path: path.slice(1),
@@ -205,24 +175,18 @@ function findExistingRelationships(projectSchema, shapes) {
205
175
  }
206
176
  }
207
177
  }
208
-
209
178
  const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
210
-
211
179
  if (shapeName && !shapes[shapeName]) {
212
180
  return;
213
181
  }
214
-
215
182
  const prop = shapeName ? (0, _refs.followRef)(projectSchema, schema) : schema;
216
-
217
183
  if (shapeName) {
218
184
  // Skip shapes we have already seen to avoid cycles
219
185
  if (shapesSeen.has(shapeName)) {
220
186
  return;
221
187
  }
222
-
223
188
  shapesSeen.add(shapeName);
224
189
  }
225
-
226
190
  if (!relationship) {
227
191
  if (prop.properties) {
228
192
  for (const name of Object.keys(prop.properties)) {
@@ -237,7 +201,6 @@ function findExistingRelationships(projectSchema, shapes) {
237
201
  }
238
202
  }
239
203
  };
240
-
241
204
  for (const shape of shapeArray) {
242
205
  if ((0, _schemaUtil.isModelShape)(shape)) {
243
206
  const {
@@ -248,42 +211,35 @@ function findExistingRelationships(projectSchema, shapes) {
248
211
  findRelationships(schema, [id], name);
249
212
  }
250
213
  }
251
-
252
214
  return relationships;
253
215
  }
216
+
254
217
  /**
255
218
  * Test whether two PropertySchemas have equal realtionships
256
219
  */
257
-
258
-
259
220
  function isEqualRelationship(a, b) {
260
221
  const relationshipA = getRelationship(a);
261
- const relationshipB = getRelationship(b); // non-relationships are considered equal in that they are both equal that regard
222
+ const relationshipB = getRelationship(b);
262
223
 
224
+ // non-relationships are considered equal in that they are both equal that regard
263
225
  if (!relationshipA && !relationshipB) {
264
226
  return true;
265
227
  }
266
-
267
228
  const refsA = relationshipA === null || relationshipA === void 0 ? void 0 : relationshipA.refs;
268
-
269
229
  if (!refsA) {
270
230
  return false;
271
231
  }
272
-
273
232
  const refsB = relationshipB === null || relationshipB === void 0 ? void 0 : relationshipB.refs;
274
-
275
233
  if (!refsB || refsA.length !== refsB.length) {
276
234
  return false;
277
235
  }
278
-
279
236
  const refSet = new Set(refsA);
280
237
  return refsB.every(ref => refSet.has(ref));
281
238
  }
239
+
282
240
  /**
283
241
  * Test whether an array of PropertySchemas have unequal relationships
284
242
  */
285
-
286
-
287
243
  function hasUnequalRelationships(relationships) {
288
244
  return Boolean(relationships.find((propertySchema, index, allRelationships) => {
289
245
  const nextPropertySchema = allRelationships[index + 1];
package/dist/scalars.js CHANGED
@@ -7,7 +7,6 @@ exports.isScalar = isScalar;
7
7
  exports.scalars = void 0;
8
8
  const scalars = ['string', 'boolean', 'integer', 'number'];
9
9
  exports.scalars = scalars;
10
-
11
10
  function isScalar(str) {
12
11
  return Array.from(scalars).includes(str);
13
12
  }
@@ -4,49 +4,38 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.removePropertiesTransform = removePropertiesTransform;
7
-
8
7
  var _util = require("@takeshape/util");
9
-
10
8
  var _types = require("./types");
11
-
12
9
  var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  function createPropertiesPredicate(propertyNames) {
17
12
  const byShape = new Map();
18
-
19
13
  for (const name of propertyNames) {
20
14
  const [shapeName, propName] = name.split('.');
21
15
  const blacklist = byShape.get(shapeName);
22
-
23
16
  if (!blacklist) {
24
17
  byShape.set(shapeName, new Set([propName]));
25
18
  } else {
26
19
  blacklist.add(propName);
27
20
  }
28
21
  }
29
-
30
22
  return (shapeName, name) => {
31
23
  const blacklist = byShape.get(byShape.has(shapeName) ? shapeName : '*');
32
24
  return Boolean(blacklist === null || blacklist === void 0 ? void 0 : blacklist.has(name));
33
25
  };
34
26
  }
35
-
36
27
  function removePropertiesTransform(propertyNames) {
37
28
  const isBlacklisted = createPropertiesPredicate(propertyNames);
38
29
  return projectSchema => {
39
30
  (0, _util.visit)(projectSchema, ['schema'], (value, path) => {
40
31
  if (path.length === 3 && path[0] === 'shapes' && path[2] === 'schema') {
41
32
  const shapeSchema = value;
42
-
43
33
  if ((0, _types.isObjectSchema)(shapeSchema)) {
44
34
  const {
45
35
  properties,
46
36
  required
47
37
  } = shapeSchema;
48
38
  shapeSchema.properties = (0, _pickBy.default)(properties, (_, name) => !isBlacklisted(path[1], name));
49
-
50
39
  if (required) {
51
40
  shapeSchema.required = required.filter(name => !isBlacklisted(path[1], name));
52
41
  }