@takeshape/schema 8.46.0 → 8.49.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.
- package/es/flatten-templates.js +1 -1
- package/es/template-shapes/templates.js +1 -1
- package/es/template-shapes/where.js +55 -19
- package/examples/latest/betzino.json +43364 -0
- package/examples/source/betzino.json +43364 -0
- package/lib/flatten-templates.js +1 -1
- package/lib/template-shapes/templates.js +1 -1
- package/lib/template-shapes/where.d.ts +2 -1
- package/lib/template-shapes/where.d.ts.map +1 -1
- package/lib/template-shapes/where.js +57 -21
- package/package.json +4 -4
package/lib/flatten-templates.js
CHANGED
|
@@ -31,7 +31,7 @@ function flattenTemplates(projectSchema) {
|
|
|
31
31
|
const {
|
|
32
32
|
shapeName,
|
|
33
33
|
dependencies
|
|
34
|
-
} = (0, _templateShapes.resolveTemplate)(
|
|
34
|
+
} = (0, _templateShapes.resolveTemplate)(newSchema, ref.template, (0, _refs.refItemToShapeName)(ref));
|
|
35
35
|
(0, _set.default)(newSchema, ref.path, ref.path[ref.path.length - 1] === '@ref' ? `local:${shapeName}` : shapeName);
|
|
36
36
|
Object.assign(newSchema.shapes, dependencies);
|
|
37
37
|
}
|
|
@@ -297,7 +297,7 @@ function getMutationArgs(templateName, verb) {
|
|
|
297
297
|
const shapeName = (0, _refs.getRefShapeName)(projectSchema, propSchema);
|
|
298
298
|
|
|
299
299
|
if (shapeName) {
|
|
300
|
-
return !projectSchema.shapes[getInputShapeName(shapeName)];
|
|
300
|
+
return shapeName !== 'TSRelationship' && !projectSchema.shapes[getInputShapeName(shapeName)];
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
return true;
|
|
@@ -20,10 +20,11 @@ export declare const fieldTypeComparison: Record<string, {
|
|
|
20
20
|
export declare const comparatorDescriptions: Record<string, string>;
|
|
21
21
|
export declare const booleanOperators: string[];
|
|
22
22
|
export declare const boolOpDescriptionMap: Record<string, string>;
|
|
23
|
+
export declare function isEqualRelationship(a: PropertySchema, b: PropertySchema): boolean;
|
|
23
24
|
export declare function getFieldTypeComparison(fieldType: string): Maybe<Record<string, PropertySchema>>;
|
|
24
25
|
export interface PropertyContext {
|
|
25
26
|
shapeCache: ShapeCache;
|
|
26
|
-
conflictingProperties
|
|
27
|
+
conflictingProperties?: Set<string>;
|
|
27
28
|
projectSchema: ProjectSchema;
|
|
28
29
|
relationshipDepth: number;
|
|
29
30
|
booleanOperators?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"where.d.ts","sourceRoot":"","sources":["../../../src/template-shapes/where.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,EAAY,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAC,cAAc,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"where.d.ts","sourceRoot":"","sources":["../../../src/template-shapes/where.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,EAAY,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAC,cAAc,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAI5E,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAczD,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAIzC,eAAO,MAAM,sBAAsB,IAAI,CAAC;AACxC,eAAO,MAAM,yBAAyB,sBAAgB,OAA0C,CAAC;AAEjG,aAAK,qBAAqB,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5F,aAAK,UAAU,GAAG,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC;AAExC,cAAM,UAAU;IACd,MAAM,0BAAiC;IACvC,UAAU,cAAqB;IAE/B,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;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,CAAC,CAkFvC;AAkED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,gBAAgB,CA4BrG;AAED,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,KAAK,EAAE,GACtB;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,YAAY,EAAE,QAAQ,CAAA;CAAC,CAchD"}
|
|
@@ -9,13 +9,10 @@ exports.getFields = getFields;
|
|
|
9
9
|
exports.getPropertyComparisonType = getPropertyComparisonType;
|
|
10
10
|
exports.getWhereSearchArg = getWhereSearchArg;
|
|
11
11
|
exports.getWhereShape = getWhereShape;
|
|
12
|
+
exports.isEqualRelationship = isEqualRelationship;
|
|
12
13
|
|
|
13
14
|
var _util = require("@takeshape/util");
|
|
14
15
|
|
|
15
|
-
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
16
|
-
|
|
17
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
18
|
-
|
|
19
16
|
var _unset = _interopRequireDefault(require("lodash/unset"));
|
|
20
17
|
|
|
21
18
|
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
|
|
@@ -145,13 +142,40 @@ const boolOpDescriptionMap = {
|
|
|
145
142
|
};
|
|
146
143
|
exports.boolOpDescriptionMap = boolOpDescriptionMap;
|
|
147
144
|
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
function isEqualRelationship(a, b) {
|
|
146
|
+
var _a$Relationship, _b$Relationship;
|
|
147
|
+
|
|
148
|
+
// non-relationships are considered equal in that they are both equal that regard
|
|
149
|
+
if (!a['@relationship'] && !b['@relationship']) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const idsA = (_a$Relationship = a['@relationship']) === null || _a$Relationship === void 0 ? void 0 : _a$Relationship.shapeIds;
|
|
154
|
+
|
|
155
|
+
if (!idsA) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const idsB = (_b$Relationship = b['@relationship']) === null || _b$Relationship === void 0 ? void 0 : _b$Relationship.shapeIds;
|
|
160
|
+
|
|
161
|
+
if (!idsB || idsA.length !== idsB.length) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const idSet = new Set(idsA);
|
|
166
|
+
return idsB.every(id => idSet.has(id));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function getConflictingProperties(projectSchema, shapes) {
|
|
170
|
+
const conflicts = new Set();
|
|
150
171
|
const allProps = {};
|
|
151
172
|
|
|
152
173
|
for (const shape of Object.values(shapes)) {
|
|
153
|
-
|
|
154
|
-
|
|
174
|
+
for (const [name, prop] of (0, _schemaUtil.createSchemaPropertyList)(projectSchema, shape.schema).getNodes()) {
|
|
175
|
+
if (name in allProps && (allProps[name].type !== prop.type || !isEqualRelationship(allProps[name], prop))) {
|
|
176
|
+
conflicts.add(name);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
155
179
|
|
|
156
180
|
if ((0, _types.isObjectSchema)(shape.schema)) {
|
|
157
181
|
Object.assign(allProps, shape.schema.properties);
|
|
@@ -159,7 +183,7 @@ const getConflictingProperties = (projectSchema, shapes) => {
|
|
|
159
183
|
}
|
|
160
184
|
|
|
161
185
|
return conflicts;
|
|
162
|
-
}
|
|
186
|
+
}
|
|
163
187
|
|
|
164
188
|
function getFieldTypeComparison(fieldType) {
|
|
165
189
|
const comparison = fieldTypeComparison[fieldType];
|
|
@@ -286,7 +310,7 @@ function getTypeName(name, prop, shapeName, context) {
|
|
|
286
310
|
|
|
287
311
|
if (type === 'object' || type === 'array') {
|
|
288
312
|
const prefix = `TS${relationshipDepth >= MAX_RELATIONSHIP_DEPTH ? 'Shallow' : ''}Where`;
|
|
289
|
-
const fieldName = `${conflictingProperties.
|
|
313
|
+
const fieldName = `${conflictingProperties !== null && conflictingProperties !== void 0 && conflictingProperties.has(name) ? '_' : ''}${(0, _util.pascalCase)(name)}`;
|
|
290
314
|
const refItem = (0, _refs.getRefOrItemsRef)(projectSchema, prop);
|
|
291
315
|
const suffix = refItem ? (0, _refs.refItemToShapeName)(refItem) : `${shapeName}${fieldName}`;
|
|
292
316
|
return `${prefix}${suffix}`;
|
|
@@ -307,12 +331,16 @@ function getFields(typeName, shapes, context) {
|
|
|
307
331
|
} = context;
|
|
308
332
|
const result = {};
|
|
309
333
|
const tooDeep = exceededRelationshipDepth(relationshipDepth);
|
|
334
|
+
const conflictingProperties = shapes.length ? getConflictingProperties(projectSchema, shapes) : undefined;
|
|
335
|
+
const fieldContext = { ...context,
|
|
336
|
+
conflictingProperties
|
|
337
|
+
};
|
|
310
338
|
|
|
311
339
|
for (const shape of shapes) {
|
|
312
340
|
const nodes = (0, _schemaUtil.createSchemaPropertyList)(projectSchema, shape.schema).filterBy(([name, property]) => !skipField(name, property, projectSchema, tooDeep)).getNodes();
|
|
313
341
|
|
|
314
342
|
for (const [name, property] of nodes) {
|
|
315
|
-
Object.assign(result, getPropertyComparisonType(name, property, shape.name,
|
|
343
|
+
Object.assign(result, getPropertyComparisonType(name, property, shape.name, fieldContext));
|
|
316
344
|
}
|
|
317
345
|
}
|
|
318
346
|
|
|
@@ -364,7 +392,7 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
364
392
|
}
|
|
365
393
|
}
|
|
366
394
|
|
|
367
|
-
if (!shapeCache.has(typeName)) {
|
|
395
|
+
if (!shapeCache.has(typeName) && !projectSchema.shapes[typeName]) {
|
|
368
396
|
shapeCache.set(typeName, () => {
|
|
369
397
|
var _prop$items;
|
|
370
398
|
|
|
@@ -376,13 +404,11 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
376
404
|
} else if (prop['@relationship']) {
|
|
377
405
|
const shapes = prop['@relationship'].shapeIds.map(id => (0, _schemaUtil.getShapeById)(projectSchema, id)).filter(_util.isDefined);
|
|
378
406
|
props = getFields(typeName, shapes, { ...context,
|
|
379
|
-
conflictingProperties: getConflictingProperties(context.projectSchema, shapes),
|
|
380
407
|
relationshipDepth: relationshipDepth + 1
|
|
381
408
|
});
|
|
382
409
|
} else if ((0, _unions.isUnionSchema)(propOrItems)) {
|
|
383
410
|
const shapes = (0, _unions.enumerateOneOfKeys)(projectSchema, propOrItems.oneOf).map(option => projectSchema.shapes[option.shapeName]);
|
|
384
411
|
props = getFields(typeName, shapes, { ...context,
|
|
385
|
-
conflictingProperties: getConflictingProperties(context.projectSchema, shapes),
|
|
386
412
|
relationshipDepth,
|
|
387
413
|
booleanOperators: false
|
|
388
414
|
});
|
|
@@ -392,10 +418,14 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
392
418
|
const properties = ((_prop$items2 = prop.items) === null || _prop$items2 === void 0 ? void 0 : _prop$items2.properties) ?? prop.properties;
|
|
393
419
|
|
|
394
420
|
if (properties) {
|
|
421
|
+
props = props ?? {};
|
|
422
|
+
const fieldContext = { ...context,
|
|
423
|
+
conflictingProperties: undefined // non-union objects have no conflicts
|
|
424
|
+
|
|
425
|
+
};
|
|
426
|
+
|
|
395
427
|
for (const propName of Object.keys(properties)) {
|
|
396
|
-
props
|
|
397
|
-
...getPropertyComparisonType(propName, properties[propName], shapeName, context)
|
|
398
|
-
};
|
|
428
|
+
Object.assign(props, getPropertyComparisonType(propName, properties[propName], shapeName, fieldContext));
|
|
399
429
|
}
|
|
400
430
|
}
|
|
401
431
|
} else {
|
|
@@ -420,8 +450,8 @@ function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
420
450
|
});
|
|
421
451
|
}
|
|
422
452
|
|
|
423
|
-
if (shapeCache.has(typeName)) {
|
|
424
|
-
const fieldName = `${conflictingProperties.
|
|
453
|
+
if (shapeCache.has(typeName) || projectSchema.shapes[typeName]) {
|
|
454
|
+
const fieldName = `${conflictingProperties !== null && conflictingProperties !== void 0 && conflictingProperties.has(name) ? `${shapeName}_` : ''}${name}`;
|
|
425
455
|
return {
|
|
426
456
|
[fieldName]: {
|
|
427
457
|
'@ref': `local:${typeName}`
|
|
@@ -500,14 +530,20 @@ function expandUnionShapes(projectSchema, shapes) {
|
|
|
500
530
|
|
|
501
531
|
function getWhereShape(projectSchema, selectedShapes) {
|
|
502
532
|
const shapeName = selectedShapes.length === 1 ? `TSWhere${(0, _util.pascalCase)(selectedShapes[0].name)}Input` : 'TSWhereInput';
|
|
533
|
+
|
|
534
|
+
if (projectSchema.shapes[shapeName]) {
|
|
535
|
+
return {
|
|
536
|
+
shapeName,
|
|
537
|
+
dependencies: {}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
503
541
|
const expandedShapes = expandUnionShapes(projectSchema, selectedShapes);
|
|
504
542
|
const isManyContentTypes = expandedShapes.length > 1;
|
|
505
543
|
const shapeCache = new ShapeCache();
|
|
506
|
-
const conflictingProperties = getConflictingProperties(projectSchema, expandedShapes);
|
|
507
544
|
const fields = getFields(shapeName, expandedShapes, {
|
|
508
545
|
projectSchema,
|
|
509
546
|
shapeCache,
|
|
510
|
-
conflictingProperties,
|
|
511
547
|
relationshipDepth: 0
|
|
512
548
|
});
|
|
513
549
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.49.0",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"examples"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@takeshape/errors": "8.
|
|
25
|
-
"@takeshape/json-schema": "8.
|
|
26
|
-
"@takeshape/util": "8.
|
|
24
|
+
"@takeshape/errors": "8.49.0",
|
|
25
|
+
"@takeshape/json-schema": "8.49.0",
|
|
26
|
+
"@takeshape/util": "8.49.0",
|
|
27
27
|
"ajv": "^7.0.4",
|
|
28
28
|
"ajv-formats": "^1.5.1",
|
|
29
29
|
"blueimp-md5": "^2.10.0",
|