@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.
- package/dist/api-version.js +0 -9
- package/dist/builtin-schema.js +0 -5
- package/dist/content-schema-transform.js +4 -52
- package/dist/create-input-schema.js +7 -19
- package/dist/enum.js +0 -3
- package/dist/flatten-templates.js +0 -11
- package/dist/get-is-leaf.js +8 -18
- package/dist/index.js +0 -58
- package/dist/interfaces.js +2 -26
- package/dist/layers/layers.js +23 -103
- package/dist/layers/refs.js +26 -69
- package/dist/layers/type-utils.js +11 -43
- package/dist/layers/visitor.js +0 -6
- package/dist/migration/index.js +0 -51
- package/dist/migration/to/v3.0.0.js +31 -45
- package/dist/migration/to/v3.1.0.js +15 -41
- package/dist/migration/to/v3.10.0.js +6 -20
- package/dist/migration/to/v3.11.0.js +8 -20
- package/dist/migration/to/v3.12.0.js +2 -3
- package/dist/migration/to/v3.12.1.js +2 -3
- package/dist/migration/to/v3.12.2.js +2 -3
- package/dist/migration/to/v3.12.3.js +16 -21
- package/dist/migration/to/v3.13.0.js +2 -7
- package/dist/migration/to/v3.14.0.js +2 -3
- package/dist/migration/to/v3.15.0.js +2 -3
- package/dist/migration/to/v3.16.0.js +2 -3
- package/dist/migration/to/v3.17.0.js +4 -9
- package/dist/migration/to/v3.17.1.js +2 -3
- package/dist/migration/to/v3.18.0.js +2 -15
- package/dist/migration/to/v3.18.1.js +2 -7
- package/dist/migration/to/v3.18.2.js +8 -10
- package/dist/migration/to/v3.19.0.js +2 -3
- package/dist/migration/to/v3.2.0.js +2 -3
- package/dist/migration/to/v3.20.0.js +10 -11
- package/dist/migration/to/v3.21.0.js +2 -3
- package/dist/migration/to/v3.22.0.js +4 -9
- package/dist/migration/to/v3.23.0.js +2 -3
- package/dist/migration/to/v3.24.0.js +2 -3
- package/dist/migration/to/v3.25.0.js +2 -3
- package/dist/migration/to/v3.26.0.js +2 -3
- package/dist/migration/to/v3.27.0.js +2 -3
- package/dist/migration/to/v3.28.0.js +2 -3
- package/dist/migration/to/v3.29.0.js +2 -3
- package/dist/migration/to/v3.3.0.js +3 -4
- package/dist/migration/to/v3.30.0.js +2 -3
- package/dist/migration/to/v3.31.0.js +2 -12
- package/dist/migration/to/v3.32.0.js +12 -22
- package/dist/migration/to/v3.33.0.js +2 -3
- package/dist/migration/to/v3.34.0.js +14 -43
- package/dist/migration/to/v3.35.0.js +2 -3
- package/dist/migration/to/v3.36.0.js +6 -10
- package/dist/migration/to/v3.37.0.js +2 -3
- package/dist/migration/to/v3.38.0.js +2 -3
- package/dist/migration/to/v3.39.0.js +6 -13
- package/dist/migration/to/v3.4.0.js +2 -3
- package/dist/migration/to/v3.5.0.js +2 -3
- package/dist/migration/to/v3.5.1.js +2 -3
- package/dist/migration/to/v3.6.0.js +2 -3
- package/dist/migration/to/v3.7.0.js +2 -3
- package/dist/migration/to/v3.8.0.js +2 -3
- package/dist/migration/to/v3.9.0.js +8 -24
- package/dist/migration/utils.js +0 -2
- package/dist/mocks.js +9 -12
- package/dist/models/project-schema.js +0 -34
- package/dist/models/query.js +0 -9
- package/dist/models/service.js +0 -8
- package/dist/models/shape.js +0 -29
- package/dist/project-schema/index.js +1 -105
- package/dist/project-schema/migrate.js +1 -54
- package/dist/refs.js +39 -159
- package/dist/relationships.js +13 -57
- package/dist/scalars.js +0 -1
- package/dist/schema-transform.js +0 -11
- package/dist/schema-util.js +75 -271
- package/dist/schemas/index.js +0 -64
- package/dist/services.js +24 -44
- package/dist/taxonomies.js +0 -13
- package/dist/template-shapes/index.js +1 -8
- package/dist/template-shapes/templates.js +9 -40
- package/dist/template-shapes/types.js +4 -5
- package/dist/template-shapes/where.js +14 -110
- package/dist/types/index.js +0 -4
- package/dist/types/types.js +41 -13
- package/dist/types/utils.js +15 -89
- package/dist/unions.js +8 -38
- package/dist/util/api-indexing.js +2 -19
- package/dist/util/detect-cycles.js +2 -16
- package/dist/util/find-shape-at-path.js +1 -15
- package/dist/util/form-config.js +6 -23
- package/dist/util/get-conflicting-properties.js +7 -17
- package/dist/util/get-return-shape.js +0 -11
- package/dist/util/has-arg.js +0 -6
- package/dist/util/index.js +0 -18
- package/dist/util/merge.js +28 -74
- package/dist/util/patch-schema.js +5 -13
- package/dist/validate.js +15 -234
- package/dist/versions.js +0 -2
- package/dist/workflows.js +0 -15
- package/es/api-version.js +0 -4
- package/es/content-schema-transform.js +4 -38
- package/es/create-input-schema.js +7 -14
- package/es/enum.js +0 -2
- package/es/flatten-templates.js +0 -4
- package/es/get-is-leaf.js +8 -13
- package/es/index.js +1 -0
- package/es/interfaces.js +2 -14
- package/es/layers/layers.js +23 -90
- package/es/layers/refs.js +22 -45
- package/es/layers/type-utils.js +11 -16
- package/es/layers/visitor.js +0 -3
- package/es/migration/to/v3.0.0.js +31 -38
- package/es/migration/to/v3.1.0.js +16 -34
- package/es/migration/to/v3.10.0.js +6 -17
- package/es/migration/to/v3.11.0.js +8 -18
- package/es/migration/to/v3.12.0.js +2 -2
- package/es/migration/to/v3.12.1.js +2 -2
- package/es/migration/to/v3.12.2.js +2 -2
- package/es/migration/to/v3.12.3.js +16 -19
- package/es/migration/to/v3.13.0.js +2 -4
- package/es/migration/to/v3.14.0.js +2 -2
- package/es/migration/to/v3.15.0.js +2 -2
- package/es/migration/to/v3.16.0.js +2 -2
- package/es/migration/to/v3.17.0.js +4 -4
- package/es/migration/to/v3.17.1.js +2 -2
- package/es/migration/to/v3.18.0.js +2 -10
- package/es/migration/to/v3.18.1.js +2 -3
- package/es/migration/to/v3.18.2.js +8 -8
- package/es/migration/to/v3.19.0.js +2 -2
- package/es/migration/to/v3.2.0.js +2 -2
- package/es/migration/to/v3.20.0.js +10 -9
- package/es/migration/to/v3.21.0.js +2 -2
- package/es/migration/to/v3.22.0.js +4 -6
- package/es/migration/to/v3.23.0.js +2 -2
- package/es/migration/to/v3.24.0.js +2 -2
- package/es/migration/to/v3.25.0.js +2 -2
- package/es/migration/to/v3.26.0.js +2 -2
- package/es/migration/to/v3.27.0.js +2 -2
- package/es/migration/to/v3.28.0.js +2 -2
- package/es/migration/to/v3.29.0.js +2 -2
- package/es/migration/to/v3.3.0.js +3 -3
- package/es/migration/to/v3.30.0.js +2 -2
- package/es/migration/to/v3.31.0.js +2 -5
- package/es/migration/to/v3.32.0.js +12 -21
- package/es/migration/to/v3.33.0.js +2 -2
- package/es/migration/to/v3.34.0.js +16 -32
- package/es/migration/to/v3.35.0.js +2 -2
- package/es/migration/to/v3.36.0.js +6 -8
- package/es/migration/to/v3.37.0.js +2 -2
- package/es/migration/to/v3.38.0.js +2 -2
- package/es/migration/to/v3.39.0.js +6 -12
- package/es/migration/to/v3.4.0.js +2 -2
- package/es/migration/to/v3.5.0.js +2 -2
- package/es/migration/to/v3.5.1.js +2 -2
- package/es/migration/to/v3.6.0.js +2 -2
- package/es/migration/to/v3.7.0.js +2 -2
- package/es/migration/to/v3.8.0.js +2 -2
- package/es/migration/to/v3.9.0.js +8 -20
- package/es/mocks.js +10 -6
- package/es/models/project-schema.js +0 -26
- package/es/models/query.js +0 -7
- package/es/models/service.js +0 -6
- package/es/models/shape.js +1 -25
- package/es/project-schema/index.js +0 -5
- package/es/project-schema/migrate.js +3 -51
- package/es/refs.js +40 -96
- package/es/relationships.js +14 -42
- package/es/schema-transform.js +0 -7
- package/es/schema-util.js +75 -180
- package/es/services.js +18 -27
- package/es/taxonomies.js +0 -9
- package/es/template-shapes/index.js +1 -4
- package/es/template-shapes/templates.js +9 -18
- package/es/template-shapes/types.js +3 -4
- package/es/template-shapes/where.js +14 -94
- package/es/types/types.js +43 -10
- package/es/types/utils.js +16 -24
- package/es/unions.js +8 -22
- package/es/util/api-indexing.js +2 -12
- package/es/util/detect-cycles.js +2 -14
- package/es/util/find-shape-at-path.js +2 -12
- package/es/util/form-config.js +7 -19
- package/es/util/get-conflicting-properties.js +8 -14
- package/es/util/get-return-shape.js +0 -8
- package/es/util/has-arg.js +0 -3
- package/es/util/merge.js +28 -55
- package/es/util/patch-schema.js +5 -7
- package/es/validate.js +15 -194
- package/es/workflows.js +0 -6
- package/package.json +5 -5
|
@@ -9,76 +9,50 @@ exports.getFields = getFields;
|
|
|
9
9
|
exports.getPropertyComparisonType = getPropertyComparisonType;
|
|
10
10
|
exports.getWhereSearchArg = getWhereSearchArg;
|
|
11
11
|
exports.getWhereShape = getWhereShape;
|
|
12
|
-
|
|
13
12
|
var _unset = _interopRequireDefault(require("lodash/unset"));
|
|
14
|
-
|
|
15
13
|
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
|
|
16
|
-
|
|
17
14
|
var _schemaUtil = require("../schema-util");
|
|
18
|
-
|
|
19
15
|
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
|
|
20
|
-
|
|
21
16
|
var _blueimpMd = _interopRequireDefault(require("blueimp-md5"));
|
|
22
|
-
|
|
23
17
|
var _util = require("@takeshape/util");
|
|
24
|
-
|
|
25
18
|
var _apiVersion = require("../api-version");
|
|
26
|
-
|
|
27
19
|
var _refs = require("../refs");
|
|
28
|
-
|
|
29
20
|
var _unions = require("../unions");
|
|
30
|
-
|
|
31
21
|
var _utils = require("../types/utils");
|
|
32
|
-
|
|
33
22
|
var _relationships = require("../relationships");
|
|
34
|
-
|
|
35
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
-
|
|
37
24
|
const MAX_RELATIONSHIP_DEPTH = 1;
|
|
38
25
|
exports.MAX_RELATIONSHIP_DEPTH = MAX_RELATIONSHIP_DEPTH;
|
|
39
|
-
|
|
40
26
|
const exceededRelationshipDepth = (depth = 0) => depth >= MAX_RELATIONSHIP_DEPTH;
|
|
41
|
-
|
|
42
27
|
exports.exceededRelationshipDepth = exceededRelationshipDepth;
|
|
43
|
-
|
|
44
28
|
class ShapeCache {
|
|
45
29
|
thunks = new Map();
|
|
46
30
|
unresolved = new Set();
|
|
47
|
-
|
|
48
31
|
has(shapeName) {
|
|
49
32
|
return this.thunks.has(shapeName);
|
|
50
33
|
}
|
|
51
|
-
|
|
52
34
|
set(shapeName, thunk) {
|
|
53
35
|
this.thunks.set(shapeName, thunk);
|
|
54
|
-
|
|
55
36
|
if ((0, _isFunction.default)(thunk)) {
|
|
56
37
|
this.unresolved.add(shapeName);
|
|
57
38
|
}
|
|
58
39
|
}
|
|
59
|
-
|
|
60
40
|
resolveAll() {
|
|
61
41
|
while (this.unresolved.size) {
|
|
62
42
|
const shapeName = this.unresolved.values().next().value;
|
|
63
43
|
const thunk = this.thunks.get(shapeName);
|
|
64
|
-
|
|
65
44
|
if ((0, _isFunction.default)(thunk)) {
|
|
66
45
|
this.thunks.set(shapeName, thunk());
|
|
67
46
|
this.unresolved.delete(shapeName);
|
|
68
47
|
}
|
|
69
48
|
}
|
|
70
|
-
|
|
71
49
|
const result = {};
|
|
72
|
-
|
|
73
50
|
for (const [shapeName, shape] of this.thunks) {
|
|
74
51
|
result[shapeName] = shape;
|
|
75
52
|
}
|
|
76
|
-
|
|
77
53
|
return result;
|
|
78
54
|
}
|
|
79
|
-
|
|
80
55
|
}
|
|
81
|
-
|
|
82
56
|
const fieldTypeComparison = {
|
|
83
57
|
id: {
|
|
84
58
|
comparators: ['eq', 'in'],
|
|
@@ -137,39 +111,31 @@ const boolOpDescriptionMap = {
|
|
|
137
111
|
NOT: 'NOT takes a single condition that must not appear in the matching results.'
|
|
138
112
|
};
|
|
139
113
|
exports.boolOpDescriptionMap = boolOpDescriptionMap;
|
|
140
|
-
|
|
141
114
|
function getConflictingProperties(projectSchema, shapes) {
|
|
142
115
|
const conflicts = new Set();
|
|
143
116
|
const allProps = {};
|
|
144
|
-
|
|
145
117
|
for (const shape of Object.values(shapes)) {
|
|
146
118
|
for (const [name, prop] of (0, _schemaUtil.createSchemaPropertyList)(projectSchema, shape).getNodes()) {
|
|
147
119
|
if (name in allProps && (allProps[name].type !== prop.type || !(0, _relationships.isEqualRelationship)(allProps[name], prop))) {
|
|
148
120
|
conflicts.add(name);
|
|
149
121
|
}
|
|
150
122
|
}
|
|
151
|
-
|
|
152
123
|
if ((0, _utils.isObjectSchema)(shape.schema)) {
|
|
153
124
|
Object.assign(allProps, shape.schema.properties);
|
|
154
125
|
}
|
|
155
126
|
}
|
|
156
|
-
|
|
157
127
|
return conflicts;
|
|
158
128
|
}
|
|
159
|
-
|
|
160
129
|
function getFieldTypeComparison(fieldType) {
|
|
161
130
|
const comparison = fieldTypeComparison[fieldType];
|
|
162
|
-
|
|
163
131
|
if (!comparison) {
|
|
164
132
|
return undefined;
|
|
165
133
|
}
|
|
166
|
-
|
|
167
134
|
const {
|
|
168
135
|
comparators,
|
|
169
136
|
type
|
|
170
137
|
} = comparison;
|
|
171
138
|
const result = {};
|
|
172
|
-
|
|
173
139
|
for (const op of comparators) {
|
|
174
140
|
const description = comparatorDescriptions[op];
|
|
175
141
|
result[op] = op === 'in' ? {
|
|
@@ -183,73 +149,57 @@ function getFieldTypeComparison(fieldType) {
|
|
|
183
149
|
type
|
|
184
150
|
};
|
|
185
151
|
}
|
|
186
|
-
|
|
187
152
|
return result;
|
|
188
153
|
}
|
|
189
|
-
|
|
190
154
|
function isId(name) {
|
|
191
155
|
return name === '_id' || name === '_contentTypeId' || name === '_shapeId';
|
|
192
156
|
}
|
|
193
|
-
|
|
194
157
|
function isNonRelationshipRef(prop) {
|
|
195
158
|
return Boolean((0, _refs.hasRefProperty)(prop) && !(0, _relationships.getRelationship)(prop));
|
|
196
159
|
}
|
|
197
|
-
|
|
198
160
|
function getPropType(projectSchema, name, prop) {
|
|
199
161
|
if (prop['@workflow']) {
|
|
200
162
|
return 'workflow';
|
|
201
163
|
}
|
|
202
|
-
|
|
203
164
|
if (prop['@tag'] === 'draftjs') {
|
|
204
165
|
return 'draftjs';
|
|
205
166
|
}
|
|
206
|
-
|
|
207
167
|
if (prop['@tag'] === 'mdx') {
|
|
208
168
|
return 'mdx';
|
|
209
169
|
}
|
|
210
|
-
|
|
211
170
|
if (prop.format === 'date-time') {
|
|
212
171
|
return 'date';
|
|
213
172
|
}
|
|
214
|
-
|
|
215
173
|
if (isId(name)) {
|
|
216
174
|
return 'id';
|
|
217
175
|
}
|
|
218
|
-
|
|
219
176
|
if (isNonRelationshipRef(prop)) {
|
|
220
177
|
const followed = (0, _refs.followRef)(projectSchema, prop);
|
|
221
|
-
|
|
222
178
|
if (followed.enum) {
|
|
223
179
|
return 'string';
|
|
224
180
|
}
|
|
225
|
-
|
|
226
181
|
return 'object';
|
|
227
182
|
}
|
|
228
|
-
|
|
229
183
|
return prop.type;
|
|
230
184
|
}
|
|
231
|
-
|
|
232
185
|
function truncateNames(names) {
|
|
233
186
|
// For unions of many types hash the names this reduces shape name size while still allowing reuse
|
|
234
187
|
return names.length > 80 ? (0, _blueimpMd.default)(names) : names;
|
|
235
188
|
}
|
|
189
|
+
|
|
236
190
|
/**
|
|
237
191
|
* Get a formatted string of related shape names from a property schema with a
|
|
238
192
|
* relationship resolver
|
|
239
193
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
194
|
function getRelationshipShapeName(refs) {
|
|
243
195
|
return refs.map(ref => {
|
|
244
196
|
const shapeName = ref.split(':')[1];
|
|
245
197
|
return (0, _util.formatShapeName)(shapeName);
|
|
246
198
|
}).sort().join('');
|
|
247
199
|
}
|
|
248
|
-
|
|
249
200
|
function joinShapeNames(shapes) {
|
|
250
201
|
return shapes.sort().join('');
|
|
251
202
|
}
|
|
252
|
-
|
|
253
203
|
function getTypeName(name, prop, shapeName, context) {
|
|
254
204
|
const {
|
|
255
205
|
projectSchema,
|
|
@@ -257,34 +207,26 @@ function getTypeName(name, prop, shapeName, context) {
|
|
|
257
207
|
conflictingProperties
|
|
258
208
|
} = context;
|
|
259
209
|
let type = getPropType(projectSchema, name, prop);
|
|
260
|
-
|
|
261
210
|
if (isId(name)) {
|
|
262
211
|
return `TSWhereID`;
|
|
263
212
|
}
|
|
264
|
-
|
|
265
213
|
const relationship = (0, _relationships.getRelationship)(prop);
|
|
266
|
-
|
|
267
214
|
if (relationship) {
|
|
268
215
|
const relationshipName = getRelationshipShapeName(relationship.refs);
|
|
269
|
-
|
|
270
216
|
if (!relationshipName) {
|
|
271
217
|
throw new Error(`Relationship property "${prop.title ?? ''}" is missing related shapes`);
|
|
272
218
|
}
|
|
273
|
-
|
|
274
219
|
const shapeNames = truncateNames(relationshipName);
|
|
275
220
|
return `TSWhere${shapeNames}Relationship`;
|
|
276
221
|
}
|
|
277
|
-
|
|
278
222
|
if ((0, _unions.isUnionSchema)(prop)) {
|
|
279
223
|
if (prop.oneOf.length > 1) {
|
|
280
224
|
const shapeNames = truncateNames(joinShapeNames((0, _unions.enumerateOneOfKeys)(projectSchema, prop.oneOf).map(child => child.shapeName)));
|
|
281
225
|
return `TSWhere${shapeNames}Union`;
|
|
282
226
|
}
|
|
283
|
-
|
|
284
227
|
type = 'object';
|
|
285
228
|
prop = prop.oneOf[0];
|
|
286
229
|
}
|
|
287
|
-
|
|
288
230
|
if (type === 'object' || type === 'array') {
|
|
289
231
|
const prefix = `TS${relationshipDepth >= MAX_RELATIONSHIP_DEPTH ? 'Shallow' : ''}Where`;
|
|
290
232
|
const fieldName = `${conflictingProperties !== null && conflictingProperties !== void 0 && conflictingProperties.has(name) ? '_' : ''}${(0, _util.formatShapeName)(name)}`;
|
|
@@ -292,10 +234,8 @@ function getTypeName(name, prop, shapeName, context) {
|
|
|
292
234
|
const suffix = refItem ? (0, _refs.refItemToShapeName)(refItem) : `${shapeName}${fieldName}`;
|
|
293
235
|
return `${prefix}${suffix}`;
|
|
294
236
|
}
|
|
295
|
-
|
|
296
237
|
return `TSWhere${(0, _util.pascalCase)(type)}`;
|
|
297
238
|
}
|
|
298
|
-
|
|
299
239
|
function skipField({
|
|
300
240
|
name,
|
|
301
241
|
prop,
|
|
@@ -306,7 +246,6 @@ function skipField({
|
|
|
306
246
|
const isRelationship = (0, _utils.isPropertySchemaWithRelationship)(prop);
|
|
307
247
|
return Boolean(prop['@sensitive'] || prop['@resolver'] && !isIndexedShape && !isRelationship || isRelationship && exceededRelationshipDepth || (name === '_enabled' || name === '_enabledAt') && workflowsEnabled);
|
|
308
248
|
}
|
|
309
|
-
|
|
310
249
|
function getFields(typeName, shapes, context) {
|
|
311
250
|
const {
|
|
312
251
|
relationshipDepth,
|
|
@@ -316,10 +255,10 @@ function getFields(typeName, shapes, context) {
|
|
|
316
255
|
const result = {};
|
|
317
256
|
const tooDeep = exceededRelationshipDepth(relationshipDepth);
|
|
318
257
|
const conflictingProperties = shapes.length ? getConflictingProperties(projectSchema, shapes) : undefined;
|
|
319
|
-
const fieldContext = {
|
|
258
|
+
const fieldContext = {
|
|
259
|
+
...context,
|
|
320
260
|
conflictingProperties
|
|
321
261
|
};
|
|
322
|
-
|
|
323
262
|
for (const shape of shapes) {
|
|
324
263
|
const nodes = (0, _schemaUtil.createSchemaPropertyList)(projectSchema, shape).filterBy(([name, prop]) => !skipField({
|
|
325
264
|
name,
|
|
@@ -328,18 +267,14 @@ function getFields(typeName, shapes, context) {
|
|
|
328
267
|
isIndexedShape: (0, _schemaUtil.isCachedShape)(shape),
|
|
329
268
|
exceededRelationshipDepth: exceededRelationshipDepth(relationshipDepth)
|
|
330
269
|
})).getNodes();
|
|
331
|
-
|
|
332
270
|
for (const [name, property] of nodes) {
|
|
333
271
|
Object.assign(result, getPropertyComparisonType(name, property, shape.name, fieldContext));
|
|
334
272
|
}
|
|
335
273
|
}
|
|
336
|
-
|
|
337
274
|
return tooDeep || booleanOperators === false ? result : Object.assign(result, getBooleanOperatorTypes(typeName));
|
|
338
275
|
}
|
|
339
|
-
|
|
340
276
|
function getBooleanOperatorTypes(typeName) {
|
|
341
277
|
const result = {};
|
|
342
|
-
|
|
343
278
|
for (const op of booleanOperators) {
|
|
344
279
|
const refSchema = {
|
|
345
280
|
'@ref': `local:${typeName}`
|
|
@@ -349,10 +284,8 @@ function getBooleanOperatorTypes(typeName) {
|
|
|
349
284
|
items: refSchema
|
|
350
285
|
};
|
|
351
286
|
}
|
|
352
|
-
|
|
353
287
|
return result;
|
|
354
288
|
}
|
|
355
|
-
|
|
356
289
|
function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
357
290
|
const {
|
|
358
291
|
shapeCache,
|
|
@@ -360,7 +293,6 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
360
293
|
relationshipDepth,
|
|
361
294
|
conflictingProperties
|
|
362
295
|
} = context;
|
|
363
|
-
|
|
364
296
|
if (skipField({
|
|
365
297
|
name,
|
|
366
298
|
prop,
|
|
@@ -370,54 +302,49 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
370
302
|
})) {
|
|
371
303
|
return undefined;
|
|
372
304
|
}
|
|
373
|
-
|
|
374
305
|
const fieldType = getPropType(projectSchema, name, prop) ?? 'string';
|
|
375
306
|
const typeName = getTypeName(name, prop, shapeName, context);
|
|
376
307
|
const relationship = (0, _relationships.getRelationship)(prop);
|
|
377
|
-
|
|
378
308
|
if ((0, _refs.hasRefProperty)(prop.items ?? prop)) {
|
|
379
309
|
if (!(0, _refs.hasResolvableRef)(projectSchema, prop.items ?? prop)) {
|
|
380
310
|
return undefined;
|
|
381
311
|
}
|
|
382
|
-
|
|
383
312
|
if (prop.items) {
|
|
384
|
-
prop = {
|
|
313
|
+
prop = {
|
|
314
|
+
...prop,
|
|
385
315
|
items: (0, _refs.followRef)(projectSchema, prop.items)
|
|
386
316
|
};
|
|
387
317
|
} else {
|
|
388
318
|
prop = (0, _refs.followRef)(projectSchema, prop);
|
|
389
319
|
}
|
|
390
320
|
}
|
|
391
|
-
|
|
392
321
|
if (!shapeCache.has(typeName) && !projectSchema.shapes[typeName]) {
|
|
393
322
|
shapeCache.set(typeName, () => {
|
|
394
323
|
var _prop$items;
|
|
395
|
-
|
|
396
324
|
let props;
|
|
397
325
|
const propOrItems = prop.items ?? prop;
|
|
398
|
-
|
|
399
326
|
if (isId(name)) {
|
|
400
327
|
props = getFieldTypeComparison('id');
|
|
401
328
|
} else if (relationship) {
|
|
402
329
|
const shapes = (0, _relationships.getRelationshipShapes)(projectSchema.shapes, relationship.refs);
|
|
403
|
-
props = getFields(typeName, shapes, {
|
|
330
|
+
props = getFields(typeName, shapes, {
|
|
331
|
+
...context,
|
|
404
332
|
relationshipDepth: relationshipDepth + 1
|
|
405
333
|
});
|
|
406
334
|
} else if ((0, _unions.isUnionSchema)(propOrItems)) {
|
|
407
335
|
const shapes = (0, _unions.enumerateOneOfKeys)(projectSchema, propOrItems.oneOf).map(option => projectSchema.shapes[option.shapeName]);
|
|
408
|
-
props = getFields(typeName, shapes, {
|
|
336
|
+
props = getFields(typeName, shapes, {
|
|
337
|
+
...context,
|
|
409
338
|
booleanOperators: false
|
|
410
339
|
});
|
|
411
340
|
} else if (fieldType === 'object' || fieldType === 'array' && ((_prop$items = prop.items) === null || _prop$items === void 0 ? void 0 : _prop$items.type) === 'object') {
|
|
412
341
|
var _prop$items2;
|
|
413
|
-
|
|
414
342
|
const properties = ((_prop$items2 = prop.items) === null || _prop$items2 === void 0 ? void 0 : _prop$items2.properties) ?? prop.properties;
|
|
415
|
-
|
|
416
343
|
if (properties) {
|
|
417
344
|
props = props ?? {};
|
|
418
|
-
const fieldContext = {
|
|
345
|
+
const fieldContext = {
|
|
346
|
+
...context,
|
|
419
347
|
conflictingProperties: undefined // non-union objects have no conflicts
|
|
420
|
-
|
|
421
348
|
};
|
|
422
349
|
|
|
423
350
|
for (const propName of Object.keys(properties)) {
|
|
@@ -426,26 +353,21 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
426
353
|
}
|
|
427
354
|
} else {
|
|
428
355
|
var _prop$items3;
|
|
429
|
-
|
|
430
356
|
// Treat non-object arrays as their base type
|
|
431
357
|
let type;
|
|
432
|
-
|
|
433
358
|
if (typeof ((_prop$items3 = prop.items) === null || _prop$items3 === void 0 ? void 0 : _prop$items3.type) === 'string') {
|
|
434
359
|
type = prop.items.type;
|
|
435
360
|
} else {
|
|
436
361
|
type = fieldType;
|
|
437
362
|
}
|
|
438
|
-
|
|
439
363
|
props = getFieldTypeComparison(type);
|
|
440
364
|
}
|
|
441
|
-
|
|
442
365
|
return (0, _schemaUtil.createShape)(typeName, {
|
|
443
366
|
type: 'object',
|
|
444
367
|
properties: props ?? {}
|
|
445
368
|
});
|
|
446
369
|
});
|
|
447
370
|
}
|
|
448
|
-
|
|
449
371
|
if (shapeCache.has(typeName) || projectSchema.shapes[typeName]) {
|
|
450
372
|
const fieldName = `${conflictingProperties !== null && conflictingProperties !== void 0 && conflictingProperties.has(name) ? `${shapeName}_` : ''}${name}`;
|
|
451
373
|
return {
|
|
@@ -455,85 +377,67 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
455
377
|
};
|
|
456
378
|
}
|
|
457
379
|
}
|
|
458
|
-
|
|
459
380
|
function findEmpty(shapes) {
|
|
460
381
|
const empty = new Set();
|
|
461
|
-
|
|
462
382
|
for (const [shapeName, shape] of Object.entries(shapes)) {
|
|
463
383
|
if ((0, _utils.isObjectSchema)(shape.schema) && Object.keys(shape.schema.properties).length === 0) {
|
|
464
384
|
empty.add(shapeName);
|
|
465
385
|
}
|
|
466
386
|
}
|
|
467
|
-
|
|
468
387
|
return empty;
|
|
469
388
|
}
|
|
470
|
-
|
|
471
389
|
function getRefSummary(shapes) {
|
|
472
390
|
const result = {};
|
|
473
|
-
|
|
474
391
|
for (const ref of (0, _schemaUtil.getAllRefsInShapes)({
|
|
475
392
|
shapes,
|
|
476
393
|
services: {}
|
|
477
394
|
})) {
|
|
478
395
|
const path = ref.path.slice(1, ref.path.length - 1);
|
|
479
|
-
|
|
480
396
|
if (result[ref.typeName]) {
|
|
481
397
|
result[ref.typeName].push(path);
|
|
482
398
|
} else {
|
|
483
399
|
result[ref.typeName] = [path];
|
|
484
400
|
}
|
|
485
401
|
}
|
|
486
|
-
|
|
487
402
|
return result;
|
|
488
403
|
}
|
|
489
|
-
|
|
490
404
|
function pruneEmpty(shapes) {
|
|
491
405
|
let toPrune = findEmpty(shapes);
|
|
492
|
-
|
|
493
406
|
if (toPrune.size) {
|
|
494
407
|
const refSummary = getRefSummary(shapes);
|
|
495
|
-
|
|
496
408
|
while (toPrune.size) {
|
|
497
409
|
for (const shapeName of toPrune) {
|
|
498
410
|
(0, _unset.default)(shapes, shapeName);
|
|
499
|
-
|
|
500
411
|
for (const path of refSummary[shapeName] ?? []) {
|
|
501
412
|
(0, _unset.default)(shapes, path);
|
|
502
413
|
}
|
|
503
414
|
}
|
|
504
|
-
|
|
505
415
|
toPrune = findEmpty(shapes);
|
|
506
416
|
}
|
|
507
417
|
}
|
|
508
|
-
|
|
509
418
|
return shapes;
|
|
510
419
|
}
|
|
511
|
-
|
|
512
420
|
function getReferencedShape(context) {
|
|
513
421
|
return prop => {
|
|
514
422
|
const ref = (0, _refs.getRef)(context, prop);
|
|
515
423
|
return ref && (0, _refs.refItemToShape)(context, ref);
|
|
516
424
|
};
|
|
517
425
|
}
|
|
426
|
+
|
|
518
427
|
/**
|
|
519
428
|
* Expand union shapes
|
|
520
429
|
*/
|
|
521
|
-
|
|
522
|
-
|
|
523
430
|
function expandUnionShapes(projectSchema, shapes) {
|
|
524
431
|
return (0, _uniqBy.default)(shapes.flatMap(shape => (0, _unions.isUnionSchema)(shape.schema) ? shape.schema.oneOf.map(getReferencedShape(projectSchema)).filter(_util.isDefined) : shape), 'name');
|
|
525
432
|
}
|
|
526
|
-
|
|
527
433
|
function getWhereShape(projectSchema, selectedShapes) {
|
|
528
434
|
const shapeName = selectedShapes.length === 1 ? `TSWhere${(0, _util.pascalCase)(selectedShapes[0].name)}Input` : 'TSWhereInput';
|
|
529
|
-
|
|
530
435
|
if (projectSchema.shapes[shapeName]) {
|
|
531
436
|
return {
|
|
532
437
|
shapeName,
|
|
533
438
|
dependencies: {}
|
|
534
439
|
};
|
|
535
440
|
}
|
|
536
|
-
|
|
537
441
|
const expandedShapes = expandUnionShapes(projectSchema, selectedShapes);
|
|
538
442
|
const isManyContentTypes = expandedShapes.length > 1;
|
|
539
443
|
const shapeCache = new ShapeCache();
|
|
@@ -547,7 +451,8 @@ function getWhereShape(projectSchema, selectedShapes) {
|
|
|
547
451
|
dependencies: pruneEmpty({
|
|
548
452
|
[shapeName]: (0, _schemaUtil.createShape)(shapeName, {
|
|
549
453
|
type: 'object',
|
|
550
|
-
properties: {
|
|
454
|
+
properties: {
|
|
455
|
+
...fields,
|
|
551
456
|
...(isManyContentTypes && getBooleanOperatorTypes(shapeName))
|
|
552
457
|
}
|
|
553
458
|
}),
|
|
@@ -555,7 +460,6 @@ function getWhereShape(projectSchema, selectedShapes) {
|
|
|
555
460
|
})
|
|
556
461
|
};
|
|
557
462
|
}
|
|
558
|
-
|
|
559
463
|
function getWhereSearchArg(projectSchema, selectedShapes) {
|
|
560
464
|
const {
|
|
561
465
|
shapeName,
|
package/dist/types/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _types = require("./types");
|
|
8
|
-
|
|
9
7
|
Object.keys(_types).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _types[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _utils = require("./utils");
|
|
21
|
-
|
|
22
18
|
Object.keys(_utils).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _utils[key]) return;
|
package/dist/types/types.js
CHANGED
|
@@ -7,30 +7,58 @@ exports.projectSchemaImportOptionalProps = exports.legacyProjectSchemaImportOpti
|
|
|
7
7
|
const projectSchemaImportOptionalProps = ['projectId', 'locales', 'defaultLocale', 'author'];
|
|
8
8
|
exports.projectSchemaImportOptionalProps = projectSchemaImportOptionalProps;
|
|
9
9
|
const legacyProjectSchemaImportOptionalProps = ['created', 'updated', 'version', 'dataKey'];
|
|
10
|
-
exports.legacyProjectSchemaImportOptionalProps = legacyProjectSchemaImportOptionalProps;
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* Remote service configuration types
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* Old service authentication
|
|
17
|
+
* @deprecated
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Support null sentinels for authentication
|
|
22
|
+
*/
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
* A type suitable for service object updates, mostly concerns authentication
|
|
26
|
+
* requirements.
|
|
27
|
+
*/
|
|
28
|
+
exports.legacyProjectSchemaImportOptionalProps = legacyProjectSchemaImportOptionalProps;
|
|
29
|
+
/**
|
|
30
|
+
* Types of refs
|
|
31
|
+
*/
|
|
32
|
+
let RefType = /*#__PURE__*/function (RefType) {
|
|
23
33
|
RefType["@ref"] = "@ref";
|
|
24
34
|
RefType["$ref"] = "$ref";
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
return RefType;
|
|
36
|
+
}({});
|
|
37
|
+
/**
|
|
38
|
+
* Stub of a PropertySchema that may contain a `$ref` or `@ref`.
|
|
39
|
+
*/
|
|
40
|
+
exports.RefType = RefType;
|
|
27
41
|
/**
|
|
28
42
|
* Types of args
|
|
29
43
|
*/
|
|
30
|
-
let ArgsType
|
|
31
|
-
exports.ArgsType = ArgsType;
|
|
32
|
-
|
|
33
|
-
(function (ArgsType) {
|
|
44
|
+
let ArgsType = /*#__PURE__*/function (ArgsType) {
|
|
34
45
|
ArgsType["@args"] = "@args";
|
|
35
46
|
ArgsType["args"] = "args";
|
|
36
|
-
|
|
47
|
+
return ArgsType;
|
|
48
|
+
}({});
|
|
49
|
+
/**
|
|
50
|
+
* Types supporting schema iterators
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Shapes
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Relationships
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* New relationship data, drawn from a PropertySchema.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* The old relationship format, used in client UI.
|
|
63
|
+
*/
|
|
64
|
+
exports.ArgsType = ArgsType;
|