@takeshape/schema 10.2.0 → 10.2.6
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/content-schema-transform.js +4 -5
- package/dist/interfaces.js +3 -4
- package/dist/layers/layers.js +4 -8
- package/dist/layers/refs.js +1 -2
- package/dist/layers/type-utils.js +2 -2
- package/dist/migration/to/v3.1.0.js +1 -1
- package/dist/migration/to/v3.12.3.js +4 -6
- package/dist/migration/to/v3.9.0.js +5 -10
- package/dist/models/service.js +1 -2
- package/dist/models/shape.js +1 -2
- package/dist/refs.js +3 -7
- package/dist/relationships.js +6 -9
- package/dist/schema-transform.js +1 -1
- package/dist/schema-util.d.ts +1 -0
- package/dist/schema-util.d.ts.map +1 -1
- package/dist/schema-util.js +20 -13
- package/dist/services.js +3 -6
- package/dist/taxonomies.js +3 -10
- package/dist/template-shapes/templates.js +1 -2
- package/dist/template-shapes/where.js +5 -8
- package/dist/types/utils.js +10 -12
- package/dist/unions.js +1 -2
- package/dist/util/api-indexing.js +3 -4
- package/dist/util/form-config.js +1 -2
- package/dist/util/has-arg.js +1 -2
- package/dist/util/merge.js +5 -7
- package/dist/validate.js +16 -25
- package/dist/workflows.js +1 -2
- package/es/content-schema-transform.js +4 -5
- package/es/interfaces.js +3 -4
- package/es/layers/layers.js +4 -8
- package/es/layers/refs.js +1 -2
- package/es/layers/type-utils.js +2 -2
- package/es/migration/to/v3.1.0.js +1 -1
- package/es/migration/to/v3.12.3.js +4 -6
- package/es/migration/to/v3.9.0.js +5 -10
- package/es/models/service.js +1 -2
- package/es/models/shape.js +1 -2
- package/es/refs.js +3 -7
- package/es/relationships.js +6 -9
- package/es/schema-transform.js +1 -1
- package/es/schema-util.js +16 -12
- package/es/services.js +3 -6
- package/es/taxonomies.js +3 -10
- package/es/template-shapes/templates.js +1 -2
- package/es/template-shapes/where.js +5 -8
- package/es/types/utils.js +10 -12
- package/es/unions.js +1 -2
- package/es/util/api-indexing.js +3 -4
- package/es/util/form-config.js +1 -2
- package/es/util/has-arg.js +1 -2
- package/es/util/merge.js +5 -7
- package/es/validate.js +13 -22
- package/es/workflows.js +1 -2
- package/package.json +7 -7
package/es/relationships.js
CHANGED
|
@@ -114,14 +114,13 @@ export function getLegacyRelationship(projectSchema, relationship) {
|
|
|
114
114
|
* Get relationship details from a PropertySchema.
|
|
115
115
|
*/
|
|
116
116
|
export function getRelationship(propertySchema) {
|
|
117
|
-
var _propertySchema$Back, _propertySchema$Back2;
|
|
118
117
|
propertySchema = propertySchema['@output'] ?? propertySchema;
|
|
119
118
|
if (!isPropertySchemaWithRelationship(propertySchema)) {
|
|
120
119
|
return;
|
|
121
120
|
}
|
|
122
121
|
const isMultiple = propertySchema.type === 'array';
|
|
123
|
-
const hasBackreference = Boolean(
|
|
124
|
-
const backreferenceName =
|
|
122
|
+
const hasBackreference = Boolean(propertySchema['@backreference']?.enabled);
|
|
123
|
+
const backreferenceName = propertySchema['@backreference']?.name;
|
|
125
124
|
const refs = getRelationshipShapeRefs(propertySchema);
|
|
126
125
|
return {
|
|
127
126
|
isMultiple,
|
|
@@ -144,17 +143,15 @@ export function findExistingRelationships(projectSchema, shapes) {
|
|
|
144
143
|
const findRelationships = (schema, path, parentShapeName) => {
|
|
145
144
|
const relationship = getRelationship(schema);
|
|
146
145
|
if (relationship) {
|
|
147
|
-
var _schema$Backreferenc;
|
|
148
146
|
const relatedShapeIds = getRelationshipShapeIds(shapes, relationship.refs);
|
|
149
|
-
const relatedName =
|
|
147
|
+
const relatedName = schema['@backreference']?.name;
|
|
150
148
|
for (const shapeId of relatedShapeIds) {
|
|
151
149
|
if (shapeIds.has(shapeId)) {
|
|
152
|
-
var _schema$Backreferenc2;
|
|
153
150
|
addRelationship(relationships, shapeId, {
|
|
154
151
|
relatedName,
|
|
155
152
|
path: path.slice(1),
|
|
156
153
|
shapeId: path[0],
|
|
157
|
-
hasBackreference: Boolean(
|
|
154
|
+
hasBackreference: Boolean(schema['@backreference']?.enabled),
|
|
158
155
|
schema,
|
|
159
156
|
shapeName: parentShapeName
|
|
160
157
|
});
|
|
@@ -211,11 +208,11 @@ export function isEqualRelationship(a, b) {
|
|
|
211
208
|
if (!relationshipA && !relationshipB) {
|
|
212
209
|
return true;
|
|
213
210
|
}
|
|
214
|
-
const refsA = relationshipA
|
|
211
|
+
const refsA = relationshipA?.refs;
|
|
215
212
|
if (!refsA) {
|
|
216
213
|
return false;
|
|
217
214
|
}
|
|
218
|
-
const refsB = relationshipB
|
|
215
|
+
const refsB = relationshipB?.refs;
|
|
219
216
|
if (!refsB || refsA.length !== refsB.length) {
|
|
220
217
|
return false;
|
|
221
218
|
}
|
package/es/schema-transform.js
CHANGED
|
@@ -14,7 +14,7 @@ function createPropertiesPredicate(propertyNames) {
|
|
|
14
14
|
}
|
|
15
15
|
return (shapeName, name) => {
|
|
16
16
|
const blacklist = byShape.get(byShape.has(shapeName) ? shapeName : '*');
|
|
17
|
-
return Boolean(blacklist
|
|
17
|
+
return Boolean(blacklist?.has(name));
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
export function removePropertiesTransform(propertyNames) {
|
package/es/schema-util.js
CHANGED
|
@@ -77,7 +77,7 @@ export function getServiceInfo(projectSchema, shape) {
|
|
|
77
77
|
} = serviceConfig;
|
|
78
78
|
const generators = {};
|
|
79
79
|
const tag = value['@tag'];
|
|
80
|
-
if (tag
|
|
80
|
+
if (tag?.startsWith(SERVICE_OBJECT_PATTERN_NAME)) {
|
|
81
81
|
const idFieldName = getServiceIdFieldName(key);
|
|
82
82
|
const version = tag.substr(tag.lastIndexOf(':') + 1);
|
|
83
83
|
generators[SERVICE_OBJECT_PATTERN_NAME] = {
|
|
@@ -246,14 +246,13 @@ export function getCommonBuiltInProperties(shape) {
|
|
|
246
246
|
}
|
|
247
247
|
export const DEFAULT_ID_FIELD = 'id';
|
|
248
248
|
export function getIdField(obj) {
|
|
249
|
-
return
|
|
249
|
+
return obj?.idField ?? DEFAULT_ID_FIELD;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
253
|
* Get properties necessary for cached / remote data to work with the TSSearchable interface.
|
|
254
254
|
*/
|
|
255
255
|
function getCachedBuiltInProperties(projectSchema, shape, properties) {
|
|
256
|
-
var _properties$idField;
|
|
257
256
|
const idField = getIdField(shape.cache);
|
|
258
257
|
|
|
259
258
|
// TODO Implement `searchSummary` and `_shapeId` here, and remove `getRemoteShapeTSSearchableFields`
|
|
@@ -262,7 +261,7 @@ function getCachedBuiltInProperties(projectSchema, shape, properties) {
|
|
|
262
261
|
title: 'Id',
|
|
263
262
|
type: 'string',
|
|
264
263
|
...properties._id,
|
|
265
|
-
...(
|
|
264
|
+
...(properties[idField]?.['@mapping'] ? {
|
|
266
265
|
'@mapping': properties[idField]['@mapping']
|
|
267
266
|
} : {})
|
|
268
267
|
}
|
|
@@ -362,6 +361,14 @@ export let BuiltInPropertiesProfile = /*#__PURE__*/function (BuiltInPropertiesPr
|
|
|
362
361
|
BuiltInPropertiesProfile[BuiltInPropertiesProfile["None"] = 2] = "None";
|
|
363
362
|
return BuiltInPropertiesProfile;
|
|
364
363
|
}({});
|
|
364
|
+
const BUILT_IN_PROPERTY_NAMES = {
|
|
365
|
+
[BuiltInPropertiesProfile.Model]: getBuiltInPropertyNames(BuiltInPropertiesProfile.Model),
|
|
366
|
+
[BuiltInPropertiesProfile.Cached]: getBuiltInPropertyNames(BuiltInPropertiesProfile.Cached),
|
|
367
|
+
[BuiltInPropertiesProfile.None]: getBuiltInPropertyNames(BuiltInPropertiesProfile.None)
|
|
368
|
+
};
|
|
369
|
+
export const isBuiltInPropertyName = (name, profile = BuiltInPropertiesProfile.Model) => {
|
|
370
|
+
return BUILT_IN_PROPERTY_NAMES[profile].has(name);
|
|
371
|
+
};
|
|
365
372
|
|
|
366
373
|
/**
|
|
367
374
|
* Get the profile to use for loading built-in properties
|
|
@@ -488,8 +495,7 @@ export function isModelShape(shape) {
|
|
|
488
495
|
return Boolean(shape.model);
|
|
489
496
|
}
|
|
490
497
|
export function isCachedShape(shape) {
|
|
491
|
-
|
|
492
|
-
return ((_shape$cache = shape.cache) === null || _shape$cache === void 0 ? void 0 : _shape$cache.enabled) === true && shape.loaders !== undefined;
|
|
498
|
+
return shape.cache?.enabled === true && shape.loaders !== undefined;
|
|
493
499
|
}
|
|
494
500
|
export function getArgsReference(projectSchema, argsSchema) {
|
|
495
501
|
const args = getArgs(argsSchema);
|
|
@@ -645,7 +651,7 @@ export function getRelevantShapes(projectSchema, params) {
|
|
|
645
651
|
byId = false,
|
|
646
652
|
includeDependencies = true
|
|
647
653
|
} = params;
|
|
648
|
-
if (shapeNames
|
|
654
|
+
if (shapeNames?.length || shapeIds?.length) {
|
|
649
655
|
const ids = new Set(shapeIds);
|
|
650
656
|
const names = new Set(shapeNames);
|
|
651
657
|
const shapes = {};
|
|
@@ -835,7 +841,7 @@ export function getStorageKey(schema) {
|
|
|
835
841
|
}
|
|
836
842
|
export function getPropertyService(schema) {
|
|
837
843
|
const first = getFirstMapping(schema);
|
|
838
|
-
const split = first
|
|
844
|
+
const split = first?.split(':');
|
|
839
845
|
return split ? `${split[0]}:${split[1]}` : undefined;
|
|
840
846
|
}
|
|
841
847
|
export function emptySchema(projectId) {
|
|
@@ -1021,12 +1027,10 @@ class SchemaPropertyAccessor {
|
|
|
1021
1027
|
return this.properties.get(propertyName);
|
|
1022
1028
|
}
|
|
1023
1029
|
findValue(predicate) {
|
|
1024
|
-
|
|
1025
|
-
return (_this$entries$find = this.entries.find(predicate)) === null || _this$entries$find === void 0 ? void 0 : _this$entries$find[1];
|
|
1030
|
+
return this.entries.find(predicate)?.[1];
|
|
1026
1031
|
}
|
|
1027
1032
|
findName(predicate) {
|
|
1028
|
-
|
|
1029
|
-
return (_this$entries$find2 = this.entries.find(predicate)) === null || _this$entries$find2 === void 0 ? void 0 : _this$entries$find2[0];
|
|
1033
|
+
return this.entries.find(predicate)?.[0];
|
|
1030
1034
|
}
|
|
1031
1035
|
getKey(propertyName) {
|
|
1032
1036
|
const value = this.properties.get(propertyName);
|
package/es/services.js
CHANGED
|
@@ -65,11 +65,10 @@ const serviceConfigValidator = createServiceConfigValidator();
|
|
|
65
65
|
* Validates a `ServiceConfig` validator based on the JSON-schema.
|
|
66
66
|
*/
|
|
67
67
|
export function validateServiceConfig(maybeServiceConfig) {
|
|
68
|
-
var _serviceConfigValidat;
|
|
69
68
|
if (serviceConfigValidator(maybeServiceConfig)) {
|
|
70
69
|
return maybeServiceConfig;
|
|
71
70
|
}
|
|
72
|
-
throw new SchemaValidationError('ServiceConfig was invalid',
|
|
71
|
+
throw new SchemaValidationError('ServiceConfig was invalid', serviceConfigValidator.errors?.map(formatError));
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
/**
|
|
@@ -115,8 +114,7 @@ export function prepareServiceUpdate(encryptFn, decryptFn, projectSchema, servic
|
|
|
115
114
|
* Get a service config from a project schema.
|
|
116
115
|
*/
|
|
117
116
|
export function getStoredServiceConfig(projectSchema, serviceKey) {
|
|
118
|
-
|
|
119
|
-
return (_projectSchema$servic = projectSchema.services) === null || _projectSchema$servic === void 0 ? void 0 : _projectSchema$servic[serviceKey];
|
|
117
|
+
return projectSchema.services?.[serviceKey];
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
/**
|
|
@@ -133,8 +131,7 @@ export function getServiceNamespaces(context) {
|
|
|
133
131
|
} = context;
|
|
134
132
|
if (services) {
|
|
135
133
|
Object.keys(services).forEach(serviceKey => {
|
|
136
|
-
|
|
137
|
-
const namespace = (_services$serviceKey = services[serviceKey]) === null || _services$serviceKey === void 0 ? void 0 : _services$serviceKey.namespace;
|
|
134
|
+
const namespace = services[serviceKey]?.namespace;
|
|
138
135
|
if (namespace) {
|
|
139
136
|
namespaces.set(namespace, serviceKey);
|
|
140
137
|
}
|
package/es/taxonomies.js
CHANGED
|
@@ -6,8 +6,7 @@ function weakMemoize(fn) {
|
|
|
6
6
|
return memoized;
|
|
7
7
|
}
|
|
8
8
|
export function getFirstStringFieldV3(shape, projectSchema) {
|
|
9
|
-
|
|
10
|
-
const forms = (_projectSchema$forms = projectSchema.forms) === null || _projectSchema$forms === void 0 ? void 0 : _projectSchema$forms[shape.name];
|
|
9
|
+
const forms = projectSchema.forms?.[shape.name];
|
|
11
10
|
if (!forms || !forms.default) {
|
|
12
11
|
return null;
|
|
13
12
|
}
|
|
@@ -15,19 +14,13 @@ export function getFirstStringFieldV3(shape, projectSchema) {
|
|
|
15
14
|
const {
|
|
16
15
|
order
|
|
17
16
|
} = forms.default;
|
|
18
|
-
const name = order.find(name =>
|
|
19
|
-
var _schemaProperties$get;
|
|
20
|
-
return ((_schemaProperties$get = schemaProperties.getValue(name)) === null || _schemaProperties$get === void 0 ? void 0 : _schemaProperties$get.type) === 'string';
|
|
21
|
-
});
|
|
17
|
+
const name = order.find(name => schemaProperties.getValue(name)?.type === 'string');
|
|
22
18
|
return name ? {
|
|
23
19
|
name,
|
|
24
20
|
key: schemaProperties.getKey(name)
|
|
25
21
|
} : null;
|
|
26
22
|
}
|
|
27
|
-
export const getTaxonomyField = weakMemoize((shape, projectSchema) =>
|
|
28
|
-
var _shape$model;
|
|
29
|
-
return ((_shape$model = shape.model) === null || _shape$model === void 0 ? void 0 : _shape$model.type) === 'taxonomy' ? getFirstStringFieldV3(shape, projectSchema) : null;
|
|
30
|
-
});
|
|
23
|
+
export const getTaxonomyField = weakMemoize((shape, projectSchema) => shape.model?.type === 'taxonomy' ? getFirstStringFieldV3(shape, projectSchema) : null);
|
|
31
24
|
export const getTaxonomies = weakMemoize(projectSchema => {
|
|
32
25
|
const {
|
|
33
26
|
shapes
|
|
@@ -168,8 +168,7 @@ const idSchema = {
|
|
|
168
168
|
};
|
|
169
169
|
export function getIDQueryArgs(templateName) {
|
|
170
170
|
return (context, shape) => {
|
|
171
|
-
|
|
172
|
-
const schema = ((_shape$model = shape.model) === null || _shape$model === void 0 ? void 0 : _shape$model.type) !== 'single' ? mergeSchemaProperties(idSchema, localeProps) : localeProps;
|
|
171
|
+
const schema = shape.model?.type !== 'single' ? mergeSchemaProperties(idSchema, localeProps) : localeProps;
|
|
173
172
|
const shapeName = getFlattenedTemplateShapeName(shape.name, templateName);
|
|
174
173
|
return {
|
|
175
174
|
shapeName,
|
|
@@ -211,7 +211,7 @@ function getTypeName(name, prop, shapeName, context) {
|
|
|
211
211
|
}
|
|
212
212
|
if (type === 'object' || type === 'array') {
|
|
213
213
|
const prefix = `TS${relationshipDepth >= MAX_RELATIONSHIP_DEPTH ? 'Shallow' : ''}Where`;
|
|
214
|
-
const fieldName = `${conflictingProperties
|
|
214
|
+
const fieldName = `${conflictingProperties?.has(name) ? '_' : ''}${formatShapeName(name)}`;
|
|
215
215
|
const refItem = getRefOrItemsRef(projectSchema, prop);
|
|
216
216
|
const suffix = refItem ? refItemToNamespacedShapeName(refItem) : `${shapeName}${fieldName}`;
|
|
217
217
|
return `${prefix}${suffix}`;
|
|
@@ -302,7 +302,6 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
302
302
|
}
|
|
303
303
|
if (!shapeCache.has(typeName) && !projectSchema.shapes[typeName]) {
|
|
304
304
|
shapeCache.set(typeName, () => {
|
|
305
|
-
var _prop$items;
|
|
306
305
|
let props;
|
|
307
306
|
const propOrItems = prop.items ?? prop;
|
|
308
307
|
if (isId(name)) {
|
|
@@ -319,9 +318,8 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
319
318
|
...context,
|
|
320
319
|
booleanOperators: false
|
|
321
320
|
});
|
|
322
|
-
} else if (fieldType === 'object' || fieldType === 'array' &&
|
|
323
|
-
|
|
324
|
-
const properties = ((_prop$items2 = prop.items) === null || _prop$items2 === void 0 ? void 0 : _prop$items2.properties) ?? prop.properties;
|
|
321
|
+
} else if (fieldType === 'object' || fieldType === 'array' && prop.items?.type === 'object') {
|
|
322
|
+
const properties = prop.items?.properties ?? prop.properties;
|
|
325
323
|
if (properties) {
|
|
326
324
|
props = props ?? {};
|
|
327
325
|
const fieldContext = {
|
|
@@ -334,10 +332,9 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
334
332
|
}
|
|
335
333
|
}
|
|
336
334
|
} else {
|
|
337
|
-
var _prop$items3;
|
|
338
335
|
// Treat non-object arrays as their base type
|
|
339
336
|
let type;
|
|
340
|
-
if (typeof
|
|
337
|
+
if (typeof prop.items?.type === 'string') {
|
|
341
338
|
type = prop.items.type;
|
|
342
339
|
} else {
|
|
343
340
|
type = fieldType;
|
|
@@ -351,7 +348,7 @@ export function getPropertyComparisonType(name, prop, shapeName, context) {
|
|
|
351
348
|
});
|
|
352
349
|
}
|
|
353
350
|
if (shapeCache.has(typeName) || projectSchema.shapes[typeName]) {
|
|
354
|
-
const fieldName = `${conflictingProperties
|
|
351
|
+
const fieldName = `${conflictingProperties?.has(name) ? `${shapeName}_` : ''}${name}`;
|
|
355
352
|
return {
|
|
356
353
|
[fieldName]: {
|
|
357
354
|
'@ref': `local:${typeName}`
|
package/es/types/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ export function isServiceResolver(resolver) {
|
|
|
20
20
|
return isRecord(resolver) && isString(resolver.name) && isString(resolver.service);
|
|
21
21
|
}
|
|
22
22
|
export function isComposeResolver(resolver) {
|
|
23
|
-
return Boolean(isArray(resolver
|
|
23
|
+
return Boolean(isArray(resolver?.compose) && resolver.compose.length && resolver.compose.every(isBasicResolver));
|
|
24
24
|
}
|
|
25
25
|
const {
|
|
26
26
|
definitions: {
|
|
@@ -186,8 +186,7 @@ export function isAnyServiceConfig(maybeConfig) {
|
|
|
186
186
|
return maybeConfig && isString(maybeConfig.title) && isString(maybeConfig.id) && isString(maybeConfig.provider) && isString(maybeConfig.serviceType) && isString(maybeConfig.authenticationType);
|
|
187
187
|
}
|
|
188
188
|
export function isGraphQLServiceConfig(maybeConfig) {
|
|
189
|
-
|
|
190
|
-
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && isString((_maybeConfig$options = maybeConfig.options) === null || _maybeConfig$options === void 0 ? void 0 : _maybeConfig$options.endpoint);
|
|
189
|
+
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && isString(maybeConfig.options?.endpoint);
|
|
191
190
|
}
|
|
192
191
|
export function isRESTServiceConfig(maybeConfig) {
|
|
193
192
|
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'rest';
|
|
@@ -211,25 +210,25 @@ export function isServiceConfigWithCustomAuthentication(maybeServiceConfig) {
|
|
|
211
210
|
/** Authentication Utils **/
|
|
212
211
|
|
|
213
212
|
export function isServiceAuthentication(maybeAuthentication) {
|
|
214
|
-
return maybeAuthentication
|
|
213
|
+
return maybeAuthentication?.type;
|
|
215
214
|
}
|
|
216
215
|
export function isBearerAuthentication(authentication) {
|
|
217
|
-
return
|
|
216
|
+
return authentication?.type === 'bearer';
|
|
218
217
|
}
|
|
219
218
|
export function isBasicAuthentication(authentication) {
|
|
220
|
-
return
|
|
219
|
+
return authentication?.type === 'basic';
|
|
221
220
|
}
|
|
222
221
|
export function isSearchParamsAuthentication(authentication) {
|
|
223
|
-
return
|
|
222
|
+
return authentication?.type === 'searchParams';
|
|
224
223
|
}
|
|
225
224
|
export function isOAuth2Authentication(authentication) {
|
|
226
|
-
return
|
|
225
|
+
return authentication?.type === 'oauth2';
|
|
227
226
|
}
|
|
228
227
|
export function isOAuth2BearerAuthentication(authentication) {
|
|
229
|
-
return
|
|
228
|
+
return authentication?.type === 'oauth2Bearer';
|
|
230
229
|
}
|
|
231
230
|
export function isCustomAuthentication(authentication) {
|
|
232
|
-
return
|
|
231
|
+
return authentication?.type === 'custom';
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
/** Miscellaneous Utils **/
|
|
@@ -262,8 +261,7 @@ export const getRefType = refSchema => {
|
|
|
262
261
|
}
|
|
263
262
|
};
|
|
264
263
|
export function isPropertySchemaWithRelationship(schema) {
|
|
265
|
-
|
|
266
|
-
return ((_schema$Resolver = schema['@resolver']) === null || _schema$Resolver === void 0 ? void 0 : _schema$Resolver.name) === 'shapedb:getRelated';
|
|
264
|
+
return schema['@resolver']?.name === 'shapedb:getRelated';
|
|
267
265
|
}
|
|
268
266
|
export function listCachedShapes(shapes) {
|
|
269
267
|
return Object.values(shapes).filter(isCachedShape);
|
package/es/unions.js
CHANGED
|
@@ -32,8 +32,7 @@ function getOneOf(schema) {
|
|
|
32
32
|
return schema.oneOf;
|
|
33
33
|
}
|
|
34
34
|
export function isUnionSchema(schema) {
|
|
35
|
-
|
|
36
|
-
return Boolean((_schema$oneOf = schema.oneOf) === null || _schema$oneOf === void 0 ? void 0 : _schema$oneOf.every(isRefSchema));
|
|
35
|
+
return Boolean(schema.oneOf?.every(isRefSchema));
|
|
37
36
|
}
|
|
38
37
|
export function oneOfToObject(projectSchema, schema) {
|
|
39
38
|
const properties = {};
|
package/es/util/api-indexing.js
CHANGED
|
@@ -5,9 +5,8 @@ import { getIdField, isCachedShape } from '../schema-util';
|
|
|
5
5
|
import { getQuery } from '../refs';
|
|
6
6
|
export function serviceHasIndexedShapes(schema, serviceId) {
|
|
7
7
|
for (const shape of Object.values(schema.shapes ?? {})) {
|
|
8
|
-
var _shape$loaders;
|
|
9
8
|
const indexingEnabled = isCachedShape(shape);
|
|
10
|
-
const listConfigs =
|
|
9
|
+
const listConfigs = shape.loaders?.list;
|
|
11
10
|
if (indexingEnabled && listConfigs) {
|
|
12
11
|
for (const {
|
|
13
12
|
query: queryRef
|
|
@@ -23,8 +22,8 @@ export function serviceHasIndexedShapes(schema, serviceId) {
|
|
|
23
22
|
}
|
|
24
23
|
export function getIndexedServices(projectSchema, configs) {
|
|
25
24
|
return ensureArray(configs).reduce((services, queryConfig) => {
|
|
26
|
-
const resolved = queryConfig
|
|
27
|
-
return resolved
|
|
25
|
+
const resolved = queryConfig?.query ? getQuery(projectSchema, queryConfig.query) : undefined;
|
|
26
|
+
return resolved?.query ? [...services, ...getResolverServices(resolved.query.resolver)] : services;
|
|
28
27
|
}, []);
|
|
29
28
|
}
|
|
30
29
|
function flattenListQueryConfigs(base, queryConfig, maybeConfigArray) {
|
package/es/util/form-config.js
CHANGED
|
@@ -65,7 +65,6 @@ const cache = new WeakMap();
|
|
|
65
65
|
* Find the form config for a given shape name and the form key.
|
|
66
66
|
*/
|
|
67
67
|
export function findShapeFormConfig(projectSchema, shapeName, formName) {
|
|
68
|
-
var _normalizedForms$shap;
|
|
69
68
|
if (!projectSchema.forms) {
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
@@ -74,5 +73,5 @@ export function findShapeFormConfig(projectSchema, shapeName, formName) {
|
|
|
74
73
|
normalizedForms = normalizeForms(projectSchema);
|
|
75
74
|
cache.set(projectSchema, normalizedForms);
|
|
76
75
|
}
|
|
77
|
-
return
|
|
76
|
+
return normalizedForms[shapeName]?.[formName];
|
|
78
77
|
}
|
package/es/util/has-arg.js
CHANGED
|
@@ -3,12 +3,11 @@ export function getArgs(prop) {
|
|
|
3
3
|
return '@args' in prop ? prop['@args'] : 'args' in prop ? prop.args : undefined;
|
|
4
4
|
}
|
|
5
5
|
export function hasArg(projectSchema, prop, argPath) {
|
|
6
|
-
var _projectSchema$shapes;
|
|
7
6
|
const args = getArgs(prop);
|
|
8
7
|
if (!args) {
|
|
9
8
|
return false;
|
|
10
9
|
}
|
|
11
|
-
const schema = typeof args === 'string' ?
|
|
10
|
+
const schema = typeof args === 'string' ? projectSchema.shapes[args]?.schema : args;
|
|
12
11
|
const pathArray = Array.isArray(argPath) ? argPath : argPath.split('.');
|
|
13
12
|
return Boolean(findSchemaAtPath(projectSchema, schema, pathArray));
|
|
14
13
|
}
|
package/es/util/merge.js
CHANGED
|
@@ -172,7 +172,7 @@ function attemptToMerge(base, parent, head, change) {
|
|
|
172
172
|
}
|
|
173
173
|
if (isObjectSchema(toSchema) && isObjectSchema(fromSchema)) {
|
|
174
174
|
const baseShape = findChangedShape(parent, change);
|
|
175
|
-
const baseSchema = baseShape
|
|
175
|
+
const baseSchema = baseShape?.schema;
|
|
176
176
|
return {
|
|
177
177
|
...rebaseShapeProperties(toShape, fromShape, baseShape),
|
|
178
178
|
schema: change.op === 'update' && baseSchema && isObjectSchema(baseSchema) ? rebaseSchemaProperties(toSchema, baseSchema, fromSchema) : mergeSchemaProperties(toSchema, fromSchema)
|
|
@@ -185,7 +185,7 @@ function attemptToMerge(base, parent, head, change) {
|
|
|
185
185
|
if (toObj && isObjectSchema(toObj) && fromObj && isObjectSchema(fromObj) && toSchema.extends.slice(0, toSchema.extends.length - 1).every((item, i) => isEqual(item, fromExtends[i]))) {
|
|
186
186
|
let mergedObjSchema;
|
|
187
187
|
const baseShape = findChangedShape(parent, change);
|
|
188
|
-
const baseSchema = baseShape
|
|
188
|
+
const baseSchema = baseShape?.schema;
|
|
189
189
|
if (change.op === 'update' && baseSchema && isExtendsSchema(baseSchema)) {
|
|
190
190
|
const baseObj = last(baseSchema.extends);
|
|
191
191
|
if (baseObj && isObjectSchema(baseObj)) {
|
|
@@ -217,13 +217,11 @@ function applyChange(base, parent, head, change) {
|
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
219
|
} else if (change.section === 'forms') {
|
|
220
|
-
var _base$forms, _base$forms$shapeName, _head$forms, _head$forms$shapeName;
|
|
221
220
|
const shapeName = change.path[1];
|
|
222
|
-
const toForm =
|
|
223
|
-
const fromForm =
|
|
221
|
+
const toForm = base.forms?.[shapeName]?.default;
|
|
222
|
+
const fromForm = head.forms?.[shapeName]?.default;
|
|
224
223
|
if (toForm && fromForm) {
|
|
225
|
-
|
|
226
|
-
const baseForm = (_parent$forms = parent.forms) === null || _parent$forms === void 0 ? void 0 : (_parent$forms$shapeNa = _parent$forms[shapeName]) === null || _parent$forms$shapeNa === void 0 ? void 0 : _parent$forms$shapeNa.default;
|
|
224
|
+
const baseForm = parent.forms?.[shapeName]?.default;
|
|
227
225
|
set(base, change.path, {
|
|
228
226
|
default: baseForm ? rebaseFormProperties(toForm, baseForm, fromForm) : mergeFormConfigs(toForm, fromForm)
|
|
229
227
|
});
|
package/es/validate.js
CHANGED
|
@@ -138,15 +138,14 @@ function enumerateBasicResolvers(resolver, path) {
|
|
|
138
138
|
function validateResolver(projectSchema, basePath, baseResolver) {
|
|
139
139
|
const errors = [];
|
|
140
140
|
const isValidShapeName = shapeName => {
|
|
141
|
-
var _shape$cache;
|
|
142
141
|
if (!shapeName) {
|
|
143
142
|
return false;
|
|
144
143
|
}
|
|
145
144
|
const shape = getShape(projectSchema, shapeName);
|
|
146
|
-
if (shape
|
|
145
|
+
if (shape?.model) {
|
|
147
146
|
return true;
|
|
148
147
|
}
|
|
149
|
-
return Boolean(
|
|
148
|
+
return Boolean(shape?.cache?.enabled && shape.loaders);
|
|
150
149
|
};
|
|
151
150
|
const delegateResolverMissingConfig = (parsed, resolver) => {
|
|
152
151
|
if (parsed.serviceId === 'local') {
|
|
@@ -163,8 +162,7 @@ function validateResolver(projectSchema, basePath, baseResolver) {
|
|
|
163
162
|
const getNamespace = createGetNamespace(projectSchema);
|
|
164
163
|
for (const [resolver, path] of enumerateBasicResolvers(baseResolver, basePath)) {
|
|
165
164
|
if (isBasicResolver(resolver)) {
|
|
166
|
-
|
|
167
|
-
if ('service' in resolver && resolver.service !== 'shapedb' && resolver.service !== 'takeshape' && !((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[resolver.service])) {
|
|
165
|
+
if ('service' in resolver && resolver.service !== 'shapedb' && resolver.service !== 'takeshape' && !projectSchema.services?.[resolver.service]) {
|
|
168
166
|
errors.push({
|
|
169
167
|
type: 'notFound',
|
|
170
168
|
path: path.concat(['service']),
|
|
@@ -349,7 +347,6 @@ async function validateShapeJoins(context, projectSchema) {
|
|
|
349
347
|
return flatten(await Promise.all(promises));
|
|
350
348
|
}
|
|
351
349
|
function validateShapeLoaders(context, projectSchema, shape) {
|
|
352
|
-
var _shape$cache2;
|
|
353
350
|
const errors = [];
|
|
354
351
|
if (shape.loaders) {
|
|
355
352
|
const getNamespace = createGetNamespace(projectSchema);
|
|
@@ -380,9 +377,8 @@ function validateShapeLoaders(context, projectSchema, shape) {
|
|
|
380
377
|
}
|
|
381
378
|
}
|
|
382
379
|
}
|
|
383
|
-
if (
|
|
384
|
-
|
|
385
|
-
const min = ((_context$entitlements = context.entitlements) === null || _context$entitlements === void 0 ? void 0 : _context$entitlements.minScheduleTriggerInterval) ?? DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL;
|
|
380
|
+
if (shape.cache?.triggers) {
|
|
381
|
+
const min = context.entitlements?.minScheduleTriggerInterval ?? DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL;
|
|
386
382
|
for (let i = 0; i < shape.cache.triggers.length; i++) {
|
|
387
383
|
const trigger = shape.cache.triggers[i];
|
|
388
384
|
if (trigger.type === 'schedule' && trigger.interval < min) {
|
|
@@ -536,7 +532,7 @@ async function validateRefs(context, projectSchema) {
|
|
|
536
532
|
message: `Invalid ref "${get(projectSchema, item.path)}"`
|
|
537
533
|
});
|
|
538
534
|
} else if (mustBeInterface(item)) {
|
|
539
|
-
const context =
|
|
535
|
+
const context = layer?.schema ?? projectSchema;
|
|
540
536
|
const shape = get(context, item.path.slice(0, 2));
|
|
541
537
|
errors.push(...validateShapeImplementsInterface(context, shape, item, item.path));
|
|
542
538
|
}
|
|
@@ -629,9 +625,8 @@ function matchesInterface(shape, interfaceShape, path) {
|
|
|
629
625
|
message: `"${shape.name}.${name}" must match "${interfaceShape.name}.${name}"`
|
|
630
626
|
});
|
|
631
627
|
} else {
|
|
632
|
-
|
|
633
|
-
const
|
|
634
|
-
const interfacePropRequired = Boolean((_interfaceSchema$requ = interfaceSchema.required) === null || _interfaceSchema$requ === void 0 ? void 0 : _interfaceSchema$requ.includes(name));
|
|
628
|
+
const propRequired = Boolean(schema.required?.includes(name));
|
|
629
|
+
const interfacePropRequired = Boolean(interfaceSchema.required?.includes(name));
|
|
635
630
|
if (interfacePropRequired !== propRequired) {
|
|
636
631
|
errors.push({
|
|
637
632
|
type: 'conflict',
|
|
@@ -671,8 +666,7 @@ function validateShapeImplementsInterface(projectSchema, shape, interfaceRefItem
|
|
|
671
666
|
function validateInterfaceImplementations(projectSchema) {
|
|
672
667
|
const errors = [];
|
|
673
668
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
674
|
-
|
|
675
|
-
if ((_shape$interfaces = shape.interfaces) !== null && _shape$interfaces !== void 0 && _shape$interfaces.length) {
|
|
669
|
+
if (shape.interfaces?.length) {
|
|
676
670
|
if (!isObjectSchema(shape.schema) && !isExtendsSchema(shape.schema)) {
|
|
677
671
|
return [{
|
|
678
672
|
path: ['shapes', shape.name, 'schema'],
|
|
@@ -739,8 +733,7 @@ function isValidateReferencesContext(context) {
|
|
|
739
733
|
}
|
|
740
734
|
const ajv = createAjv();
|
|
741
735
|
function validateStructure(schemaVersion, context, schema, ref) {
|
|
742
|
-
|
|
743
|
-
const versionStr = (_coerce = coerce(schemaVersion)) === null || _coerce === void 0 ? void 0 : _coerce.format();
|
|
736
|
+
const versionStr = coerce(schemaVersion)?.format();
|
|
744
737
|
const relevantSchemas = allProjectSchemas.filter(metaSchema => metaSchema.$id.endsWith(`v${versionStr}#`));
|
|
745
738
|
for (const relevantSchema of relevantSchemas) {
|
|
746
739
|
if (!ajv.getSchema(relevantSchema.$id)) {
|
|
@@ -748,7 +741,7 @@ function validateStructure(schemaVersion, context, schema, ref) {
|
|
|
748
741
|
}
|
|
749
742
|
}
|
|
750
743
|
ajv.validate(`https://schema.takeshape.io/project-schema/v${versionStr}#${ref ?? ''}`, schema);
|
|
751
|
-
let errors =
|
|
744
|
+
let errors = ajv.errors?.map(formatError) ?? [];
|
|
752
745
|
const {
|
|
753
746
|
suppressErrorPaths
|
|
754
747
|
} = context;
|
|
@@ -905,12 +898,11 @@ function createRoleInputValidator() {
|
|
|
905
898
|
* type's properties suitable for importing.
|
|
906
899
|
*/
|
|
907
900
|
export function validateRoleInput(maybeRoleInput) {
|
|
908
|
-
var _validate$errors;
|
|
909
901
|
const validate = createRoleInputValidator();
|
|
910
902
|
if (validate(maybeRoleInput)) {
|
|
911
903
|
return maybeRoleInput;
|
|
912
904
|
}
|
|
913
|
-
throw new SchemaValidationError('RoleInput was invalid',
|
|
905
|
+
throw new SchemaValidationError('RoleInput was invalid', validate.errors?.map(formatError));
|
|
914
906
|
}
|
|
915
907
|
|
|
916
908
|
/**
|
|
@@ -936,12 +928,11 @@ function createRoleImportValidator() {
|
|
|
936
928
|
* Validates and returns a `RoleImport` array, which is a collection of `RoleInput`s.
|
|
937
929
|
*/
|
|
938
930
|
export function ensureValidRoleImport(maybeRoles) {
|
|
939
|
-
var _validate$errors2;
|
|
940
931
|
const validate = createRoleImportValidator();
|
|
941
932
|
if (validate(maybeRoles)) {
|
|
942
933
|
return maybeRoles;
|
|
943
934
|
}
|
|
944
|
-
throw new SchemaValidationError('Roles were invalid',
|
|
935
|
+
throw new SchemaValidationError('Roles were invalid', validate.errors?.map(formatError));
|
|
945
936
|
}
|
|
946
937
|
/**
|
|
947
938
|
* Only use when validating an imported schema! ignore fields optional when importing
|
package/es/workflows.js
CHANGED
|
@@ -17,8 +17,7 @@ export const defaultWorkflow = {
|
|
|
17
17
|
}]
|
|
18
18
|
};
|
|
19
19
|
export function getWorkflow(projectSchema, shapeId) {
|
|
20
|
-
|
|
21
|
-
const workflow = (_getShapeById = getShapeById(projectSchema, shapeId)) === null || _getShapeById === void 0 ? void 0 : _getShapeById.workflow;
|
|
20
|
+
const workflow = getShapeById(projectSchema, shapeId)?.workflow;
|
|
22
21
|
if (workflow) {
|
|
23
22
|
return projectSchema.workflows[workflow] ?? defaultWorkflow;
|
|
24
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.6",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"p-reduce": "^2.1.0",
|
|
29
29
|
"semver": "^7.3.2",
|
|
30
30
|
"tiny-invariant": "^1.2.0",
|
|
31
|
-
"@takeshape/errors": "10.2.
|
|
32
|
-
"@takeshape/json-schema": "10.2.
|
|
33
|
-
"@takeshape/util": "10.2.
|
|
31
|
+
"@takeshape/errors": "10.2.6",
|
|
32
|
+
"@takeshape/json-schema": "10.2.6",
|
|
33
|
+
"@takeshape/util": "10.2.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@takeshape/json-schema-to-typescript": "^11.0.0",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"meow": "^9.0.0",
|
|
47
47
|
"p-map": "^5.0.0",
|
|
48
48
|
"shortid": "^2.2.15",
|
|
49
|
-
"@takeshape/
|
|
50
|
-
"@takeshape/
|
|
49
|
+
"@takeshape/typescript-jest-junit-reporter": "10.2.6",
|
|
50
|
+
"@takeshape/infra": "10.2.6"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
53
|
+
"node": ">=18"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "pnpm build:js && pnpm build:es && pnpm build:types && pnpm build:json && pnpm build:copy",
|