@takeshape/schema 10.2.0 → 10.2.4
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/dist/types/utils.js
CHANGED
|
@@ -77,7 +77,7 @@ function isServiceResolver(resolver) {
|
|
|
77
77
|
return (0, _util.isRecord)(resolver) && (0, _isString.default)(resolver.name) && (0, _isString.default)(resolver.service);
|
|
78
78
|
}
|
|
79
79
|
function isComposeResolver(resolver) {
|
|
80
|
-
return Boolean((0, _isArray.default)(resolver
|
|
80
|
+
return Boolean((0, _isArray.default)(resolver?.compose) && resolver.compose.length && resolver.compose.every(isBasicResolver));
|
|
81
81
|
}
|
|
82
82
|
const {
|
|
83
83
|
definitions: {
|
|
@@ -243,8 +243,7 @@ function isAnyServiceConfig(maybeConfig) {
|
|
|
243
243
|
return maybeConfig && (0, _isString.default)(maybeConfig.title) && (0, _isString.default)(maybeConfig.id) && (0, _isString.default)(maybeConfig.provider) && (0, _isString.default)(maybeConfig.serviceType) && (0, _isString.default)(maybeConfig.authenticationType);
|
|
244
244
|
}
|
|
245
245
|
function isGraphQLServiceConfig(maybeConfig) {
|
|
246
|
-
|
|
247
|
-
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && (0, _isString.default)((_maybeConfig$options = maybeConfig.options) === null || _maybeConfig$options === void 0 ? void 0 : _maybeConfig$options.endpoint);
|
|
246
|
+
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && (0, _isString.default)(maybeConfig.options?.endpoint);
|
|
248
247
|
}
|
|
249
248
|
function isRESTServiceConfig(maybeConfig) {
|
|
250
249
|
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'rest';
|
|
@@ -268,25 +267,25 @@ function isServiceConfigWithCustomAuthentication(maybeServiceConfig) {
|
|
|
268
267
|
/** Authentication Utils **/
|
|
269
268
|
|
|
270
269
|
function isServiceAuthentication(maybeAuthentication) {
|
|
271
|
-
return maybeAuthentication
|
|
270
|
+
return maybeAuthentication?.type;
|
|
272
271
|
}
|
|
273
272
|
function isBearerAuthentication(authentication) {
|
|
274
|
-
return
|
|
273
|
+
return authentication?.type === 'bearer';
|
|
275
274
|
}
|
|
276
275
|
function isBasicAuthentication(authentication) {
|
|
277
|
-
return
|
|
276
|
+
return authentication?.type === 'basic';
|
|
278
277
|
}
|
|
279
278
|
function isSearchParamsAuthentication(authentication) {
|
|
280
|
-
return
|
|
279
|
+
return authentication?.type === 'searchParams';
|
|
281
280
|
}
|
|
282
281
|
function isOAuth2Authentication(authentication) {
|
|
283
|
-
return
|
|
282
|
+
return authentication?.type === 'oauth2';
|
|
284
283
|
}
|
|
285
284
|
function isOAuth2BearerAuthentication(authentication) {
|
|
286
|
-
return
|
|
285
|
+
return authentication?.type === 'oauth2Bearer';
|
|
287
286
|
}
|
|
288
287
|
function isCustomAuthentication(authentication) {
|
|
289
|
-
return
|
|
288
|
+
return authentication?.type === 'custom';
|
|
290
289
|
}
|
|
291
290
|
|
|
292
291
|
/** Miscellaneous Utils **/
|
|
@@ -321,8 +320,7 @@ const getRefType = refSchema => {
|
|
|
321
320
|
};
|
|
322
321
|
exports.getRefType = getRefType;
|
|
323
322
|
function isPropertySchemaWithRelationship(schema) {
|
|
324
|
-
|
|
325
|
-
return ((_schema$Resolver = schema['@resolver']) === null || _schema$Resolver === void 0 ? void 0 : _schema$Resolver.name) === 'shapedb:getRelated';
|
|
323
|
+
return schema['@resolver']?.name === 'shapedb:getRelated';
|
|
326
324
|
}
|
|
327
325
|
function listCachedShapes(shapes) {
|
|
328
326
|
return Object.values(shapes).filter(_schemaUtil.isCachedShape);
|
package/dist/unions.js
CHANGED
|
@@ -44,8 +44,7 @@ function getOneOf(schema) {
|
|
|
44
44
|
return schema.oneOf;
|
|
45
45
|
}
|
|
46
46
|
function isUnionSchema(schema) {
|
|
47
|
-
|
|
48
|
-
return Boolean((_schema$oneOf = schema.oneOf) === null || _schema$oneOf === void 0 ? void 0 : _schema$oneOf.every(_utils.isRefSchema));
|
|
47
|
+
return Boolean(schema.oneOf?.every(_utils.isRefSchema));
|
|
49
48
|
}
|
|
50
49
|
function oneOfToObject(projectSchema, schema) {
|
|
51
50
|
const properties = {};
|
|
@@ -14,9 +14,8 @@ var _schemaUtil = require("../schema-util");
|
|
|
14
14
|
var _refs = require("../refs");
|
|
15
15
|
function serviceHasIndexedShapes(schema, serviceId) {
|
|
16
16
|
for (const shape of Object.values(schema.shapes ?? {})) {
|
|
17
|
-
var _shape$loaders;
|
|
18
17
|
const indexingEnabled = (0, _schemaUtil.isCachedShape)(shape);
|
|
19
|
-
const listConfigs =
|
|
18
|
+
const listConfigs = shape.loaders?.list;
|
|
20
19
|
if (indexingEnabled && listConfigs) {
|
|
21
20
|
for (const {
|
|
22
21
|
query: queryRef
|
|
@@ -32,8 +31,8 @@ function serviceHasIndexedShapes(schema, serviceId) {
|
|
|
32
31
|
}
|
|
33
32
|
function getIndexedServices(projectSchema, configs) {
|
|
34
33
|
return (0, _util.ensureArray)(configs).reduce((services, queryConfig) => {
|
|
35
|
-
const resolved = queryConfig
|
|
36
|
-
return resolved
|
|
34
|
+
const resolved = queryConfig?.query ? (0, _refs.getQuery)(projectSchema, queryConfig.query) : undefined;
|
|
35
|
+
return resolved?.query ? [...services, ...(0, _services.getResolverServices)(resolved.query.resolver)] : services;
|
|
37
36
|
}, []);
|
|
38
37
|
}
|
|
39
38
|
function flattenListQueryConfigs(base, queryConfig, maybeConfigArray) {
|
package/dist/util/form-config.js
CHANGED
|
@@ -71,7 +71,6 @@ const cache = new WeakMap();
|
|
|
71
71
|
* Find the form config for a given shape name and the form key.
|
|
72
72
|
*/
|
|
73
73
|
function findShapeFormConfig(projectSchema, shapeName, formName) {
|
|
74
|
-
var _normalizedForms$shap;
|
|
75
74
|
if (!projectSchema.forms) {
|
|
76
75
|
return;
|
|
77
76
|
}
|
|
@@ -80,5 +79,5 @@ function findShapeFormConfig(projectSchema, shapeName, formName) {
|
|
|
80
79
|
normalizedForms = normalizeForms(projectSchema);
|
|
81
80
|
cache.set(projectSchema, normalizedForms);
|
|
82
81
|
}
|
|
83
|
-
return
|
|
82
|
+
return normalizedForms[shapeName]?.[formName];
|
|
84
83
|
}
|
package/dist/util/has-arg.js
CHANGED
|
@@ -10,12 +10,11 @@ function getArgs(prop) {
|
|
|
10
10
|
return '@args' in prop ? prop['@args'] : 'args' in prop ? prop.args : undefined;
|
|
11
11
|
}
|
|
12
12
|
function hasArg(projectSchema, prop, argPath) {
|
|
13
|
-
var _projectSchema$shapes;
|
|
14
13
|
const args = getArgs(prop);
|
|
15
14
|
if (!args) {
|
|
16
15
|
return false;
|
|
17
16
|
}
|
|
18
|
-
const schema = typeof args === 'string' ?
|
|
17
|
+
const schema = typeof args === 'string' ? projectSchema.shapes[args]?.schema : args;
|
|
19
18
|
const pathArray = Array.isArray(argPath) ? argPath : argPath.split('.');
|
|
20
19
|
return Boolean((0, _findShapeAtPath.findSchemaAtPath)(projectSchema, schema, pathArray));
|
|
21
20
|
}
|
package/dist/util/merge.js
CHANGED
|
@@ -185,7 +185,7 @@ function attemptToMerge(base, parent, head, change) {
|
|
|
185
185
|
}
|
|
186
186
|
if ((0, _types.isObjectSchema)(toSchema) && (0, _types.isObjectSchema)(fromSchema)) {
|
|
187
187
|
const baseShape = findChangedShape(parent, change);
|
|
188
|
-
const baseSchema = baseShape
|
|
188
|
+
const baseSchema = baseShape?.schema;
|
|
189
189
|
return {
|
|
190
190
|
...rebaseShapeProperties(toShape, fromShape, baseShape),
|
|
191
191
|
schema: change.op === 'update' && baseSchema && (0, _types.isObjectSchema)(baseSchema) ? rebaseSchemaProperties(toSchema, baseSchema, fromSchema) : mergeSchemaProperties(toSchema, fromSchema)
|
|
@@ -198,7 +198,7 @@ function attemptToMerge(base, parent, head, change) {
|
|
|
198
198
|
if (toObj && (0, _types.isObjectSchema)(toObj) && fromObj && (0, _types.isObjectSchema)(fromObj) && toSchema.extends.slice(0, toSchema.extends.length - 1).every((item, i) => (0, _isEqual.default)(item, fromExtends[i]))) {
|
|
199
199
|
let mergedObjSchema;
|
|
200
200
|
const baseShape = findChangedShape(parent, change);
|
|
201
|
-
const baseSchema = baseShape
|
|
201
|
+
const baseSchema = baseShape?.schema;
|
|
202
202
|
if (change.op === 'update' && baseSchema && (0, _types.isExtendsSchema)(baseSchema)) {
|
|
203
203
|
const baseObj = (0, _last.default)(baseSchema.extends);
|
|
204
204
|
if (baseObj && (0, _types.isObjectSchema)(baseObj)) {
|
|
@@ -230,13 +230,11 @@ function applyChange(base, parent, head, change) {
|
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
} else if (change.section === 'forms') {
|
|
233
|
-
var _base$forms, _base$forms$shapeName, _head$forms, _head$forms$shapeName;
|
|
234
233
|
const shapeName = change.path[1];
|
|
235
|
-
const toForm =
|
|
236
|
-
const fromForm =
|
|
234
|
+
const toForm = base.forms?.[shapeName]?.default;
|
|
235
|
+
const fromForm = head.forms?.[shapeName]?.default;
|
|
237
236
|
if (toForm && fromForm) {
|
|
238
|
-
|
|
239
|
-
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;
|
|
237
|
+
const baseForm = parent.forms?.[shapeName]?.default;
|
|
240
238
|
(0, _set.default)(base, change.path, {
|
|
241
239
|
default: baseForm ? rebaseFormProperties(toForm, baseForm, fromForm) : mergeFormConfigs(toForm, fromForm)
|
|
242
240
|
});
|
package/dist/validate.js
CHANGED
|
@@ -15,7 +15,7 @@ var _types = require("./types/types");
|
|
|
15
15
|
var _jsonpathPlus = require("jsonpath-plus");
|
|
16
16
|
var _jsonSchema = require("@takeshape/json-schema");
|
|
17
17
|
var _errors = require("@takeshape/errors");
|
|
18
|
-
var
|
|
18
|
+
var _coerce = _interopRequireDefault(require("semver/functions/coerce"));
|
|
19
19
|
var _neq = _interopRequireDefault(require("semver/functions/neq"));
|
|
20
20
|
var _lt = _interopRequireDefault(require("semver/functions/lt"));
|
|
21
21
|
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
@@ -131,7 +131,7 @@ function validateWorkflows(projectSchema) {
|
|
|
131
131
|
return errors;
|
|
132
132
|
}
|
|
133
133
|
function getSemver(schemaVersion) {
|
|
134
|
-
return (0,
|
|
134
|
+
return (0, _coerce.default)(schemaVersion) ?? _versions.LEGACY_SCHEMA_VERSION;
|
|
135
135
|
}
|
|
136
136
|
function enumerateBasicResolvers(resolver, path) {
|
|
137
137
|
const results = [];
|
|
@@ -152,15 +152,14 @@ function enumerateBasicResolvers(resolver, path) {
|
|
|
152
152
|
function validateResolver(projectSchema, basePath, baseResolver) {
|
|
153
153
|
const errors = [];
|
|
154
154
|
const isValidShapeName = shapeName => {
|
|
155
|
-
var _shape$cache;
|
|
156
155
|
if (!shapeName) {
|
|
157
156
|
return false;
|
|
158
157
|
}
|
|
159
158
|
const shape = (0, _schemaUtil.getShape)(projectSchema, shapeName);
|
|
160
|
-
if (shape
|
|
159
|
+
if (shape?.model) {
|
|
161
160
|
return true;
|
|
162
161
|
}
|
|
163
|
-
return Boolean(
|
|
162
|
+
return Boolean(shape?.cache?.enabled && shape.loaders);
|
|
164
163
|
};
|
|
165
164
|
const delegateResolverMissingConfig = (parsed, resolver) => {
|
|
166
165
|
if (parsed.serviceId === 'local') {
|
|
@@ -177,8 +176,7 @@ function validateResolver(projectSchema, basePath, baseResolver) {
|
|
|
177
176
|
const getNamespace = (0, _refs.createGetNamespace)(projectSchema);
|
|
178
177
|
for (const [resolver, path] of enumerateBasicResolvers(baseResolver, basePath)) {
|
|
179
178
|
if ((0, _utils.isBasicResolver)(resolver)) {
|
|
180
|
-
|
|
181
|
-
if ('service' in resolver && resolver.service !== 'shapedb' && resolver.service !== 'takeshape' && !((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[resolver.service])) {
|
|
179
|
+
if ('service' in resolver && resolver.service !== 'shapedb' && resolver.service !== 'takeshape' && !projectSchema.services?.[resolver.service]) {
|
|
182
180
|
errors.push({
|
|
183
181
|
type: 'notFound',
|
|
184
182
|
path: path.concat(['service']),
|
|
@@ -363,7 +361,6 @@ async function validateShapeJoins(context, projectSchema) {
|
|
|
363
361
|
return (0, _lodash.flatten)(await Promise.all(promises));
|
|
364
362
|
}
|
|
365
363
|
function validateShapeLoaders(context, projectSchema, shape) {
|
|
366
|
-
var _shape$cache2;
|
|
367
364
|
const errors = [];
|
|
368
365
|
if (shape.loaders) {
|
|
369
366
|
const getNamespace = (0, _refs.createGetNamespace)(projectSchema);
|
|
@@ -394,9 +391,8 @@ function validateShapeLoaders(context, projectSchema, shape) {
|
|
|
394
391
|
}
|
|
395
392
|
}
|
|
396
393
|
}
|
|
397
|
-
if (
|
|
398
|
-
|
|
399
|
-
const min = ((_context$entitlements = context.entitlements) === null || _context$entitlements === void 0 ? void 0 : _context$entitlements.minScheduleTriggerInterval) ?? _util.DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL;
|
|
394
|
+
if (shape.cache?.triggers) {
|
|
395
|
+
const min = context.entitlements?.minScheduleTriggerInterval ?? _util.DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL;
|
|
400
396
|
for (let i = 0; i < shape.cache.triggers.length; i++) {
|
|
401
397
|
const trigger = shape.cache.triggers[i];
|
|
402
398
|
if (trigger.type === 'schedule' && trigger.interval < min) {
|
|
@@ -550,7 +546,7 @@ async function validateRefs(context, projectSchema) {
|
|
|
550
546
|
message: `Invalid ref "${(0, _get.default)(projectSchema, item.path)}"`
|
|
551
547
|
});
|
|
552
548
|
} else if (mustBeInterface(item)) {
|
|
553
|
-
const context =
|
|
549
|
+
const context = layer?.schema ?? projectSchema;
|
|
554
550
|
const shape = (0, _get.default)(context, item.path.slice(0, 2));
|
|
555
551
|
errors.push(...validateShapeImplementsInterface(context, shape, item, item.path));
|
|
556
552
|
}
|
|
@@ -643,9 +639,8 @@ function matchesInterface(shape, interfaceShape, path) {
|
|
|
643
639
|
message: `"${shape.name}.${name}" must match "${interfaceShape.name}.${name}"`
|
|
644
640
|
});
|
|
645
641
|
} else {
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
const interfacePropRequired = Boolean((_interfaceSchema$requ = interfaceSchema.required) === null || _interfaceSchema$requ === void 0 ? void 0 : _interfaceSchema$requ.includes(name));
|
|
642
|
+
const propRequired = Boolean(schema.required?.includes(name));
|
|
643
|
+
const interfacePropRequired = Boolean(interfaceSchema.required?.includes(name));
|
|
649
644
|
if (interfacePropRequired !== propRequired) {
|
|
650
645
|
errors.push({
|
|
651
646
|
type: 'conflict',
|
|
@@ -685,8 +680,7 @@ function validateShapeImplementsInterface(projectSchema, shape, interfaceRefItem
|
|
|
685
680
|
function validateInterfaceImplementations(projectSchema) {
|
|
686
681
|
const errors = [];
|
|
687
682
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
688
|
-
|
|
689
|
-
if ((_shape$interfaces = shape.interfaces) !== null && _shape$interfaces !== void 0 && _shape$interfaces.length) {
|
|
683
|
+
if (shape.interfaces?.length) {
|
|
690
684
|
if (!(0, _utils.isObjectSchema)(shape.schema) && !(0, _utils.isExtendsSchema)(shape.schema)) {
|
|
691
685
|
return [{
|
|
692
686
|
path: ['shapes', shape.name, 'schema'],
|
|
@@ -753,8 +747,7 @@ function isValidateReferencesContext(context) {
|
|
|
753
747
|
}
|
|
754
748
|
const ajv = (0, _jsonSchema.createAjv)();
|
|
755
749
|
function validateStructure(schemaVersion, context, schema, ref) {
|
|
756
|
-
|
|
757
|
-
const versionStr = (_coerce = (0, _coerce2.default)(schemaVersion)) === null || _coerce === void 0 ? void 0 : _coerce.format();
|
|
750
|
+
const versionStr = (0, _coerce.default)(schemaVersion)?.format();
|
|
758
751
|
const relevantSchemas = _schemas.allProjectSchemas.filter(metaSchema => metaSchema.$id.endsWith(`v${versionStr}#`));
|
|
759
752
|
for (const relevantSchema of relevantSchemas) {
|
|
760
753
|
if (!ajv.getSchema(relevantSchema.$id)) {
|
|
@@ -762,7 +755,7 @@ function validateStructure(schemaVersion, context, schema, ref) {
|
|
|
762
755
|
}
|
|
763
756
|
}
|
|
764
757
|
ajv.validate(`https://schema.takeshape.io/project-schema/v${versionStr}#${ref ?? ''}`, schema);
|
|
765
|
-
let errors =
|
|
758
|
+
let errors = ajv.errors?.map(formatError) ?? [];
|
|
766
759
|
const {
|
|
767
760
|
suppressErrorPaths
|
|
768
761
|
} = context;
|
|
@@ -889,7 +882,7 @@ function ensureValidLatestSchemaSyntax(obj) {
|
|
|
889
882
|
if ((0, _isUndefined.default)(schema)) {
|
|
890
883
|
throw new Error(`Invalid schema: schema is undefined`);
|
|
891
884
|
}
|
|
892
|
-
if ((0, _neq.default)(_versions.CURRENT_SCHEMA_VERSION, (0,
|
|
885
|
+
if ((0, _neq.default)(_versions.CURRENT_SCHEMA_VERSION, (0, _coerce.default)(schema.schemaVersion) ?? _versions.LEGACY_SCHEMA_VERSION)) {
|
|
893
886
|
throw new Error(`Expected schemaVersion: "${_versions.CURRENT_SCHEMA_VERSION}", got "${schema.schemaVersion}"`);
|
|
894
887
|
}
|
|
895
888
|
return schema;
|
|
@@ -919,12 +912,11 @@ function createRoleInputValidator() {
|
|
|
919
912
|
* type's properties suitable for importing.
|
|
920
913
|
*/
|
|
921
914
|
function validateRoleInput(maybeRoleInput) {
|
|
922
|
-
var _validate$errors;
|
|
923
915
|
const validate = createRoleInputValidator();
|
|
924
916
|
if (validate(maybeRoleInput)) {
|
|
925
917
|
return maybeRoleInput;
|
|
926
918
|
}
|
|
927
|
-
throw new _errors.SchemaValidationError('RoleInput was invalid',
|
|
919
|
+
throw new _errors.SchemaValidationError('RoleInput was invalid', validate.errors?.map(formatError));
|
|
928
920
|
}
|
|
929
921
|
|
|
930
922
|
/**
|
|
@@ -950,12 +942,11 @@ function createRoleImportValidator() {
|
|
|
950
942
|
* Validates and returns a `RoleImport` array, which is a collection of `RoleInput`s.
|
|
951
943
|
*/
|
|
952
944
|
function ensureValidRoleImport(maybeRoles) {
|
|
953
|
-
var _validate$errors2;
|
|
954
945
|
const validate = createRoleImportValidator();
|
|
955
946
|
if (validate(maybeRoles)) {
|
|
956
947
|
return maybeRoles;
|
|
957
948
|
}
|
|
958
|
-
throw new _errors.SchemaValidationError('Roles were invalid',
|
|
949
|
+
throw new _errors.SchemaValidationError('Roles were invalid', validate.errors?.map(formatError));
|
|
959
950
|
}
|
|
960
951
|
/**
|
|
961
952
|
* Only use when validating an imported schema! ignore fields optional when importing
|
package/dist/workflows.js
CHANGED
|
@@ -31,8 +31,7 @@ const defaultWorkflow = {
|
|
|
31
31
|
};
|
|
32
32
|
exports.defaultWorkflow = defaultWorkflow;
|
|
33
33
|
function getWorkflow(projectSchema, shapeId) {
|
|
34
|
-
|
|
35
|
-
const workflow = (_getShapeById = (0, _schemaUtil.getShapeById)(projectSchema, shapeId)) === null || _getShapeById === void 0 ? void 0 : _getShapeById.workflow;
|
|
34
|
+
const workflow = (0, _schemaUtil.getShapeById)(projectSchema, shapeId)?.workflow;
|
|
36
35
|
if (workflow) {
|
|
37
36
|
return projectSchema.workflows[workflow] ?? defaultWorkflow;
|
|
38
37
|
}
|
|
@@ -84,11 +84,11 @@ export function getContentTransform({
|
|
|
84
84
|
forEach(schema.properties, (fieldSchema, name) => {
|
|
85
85
|
const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema, obj));
|
|
86
86
|
for (const sourceKey of sourceKeys) {
|
|
87
|
-
const value = prepare(fieldSchema, obj
|
|
87
|
+
const value = prepare(fieldSchema, obj?.[sourceKey], name);
|
|
88
88
|
if (value !== undefined) {
|
|
89
89
|
assigned.add(sourceKey);
|
|
90
90
|
const transform = findTransforms(transforms, dereferenceSchema(projectSchema, fieldSchema), name);
|
|
91
|
-
const getKey = transform
|
|
91
|
+
const getKey = transform?.keyTransform ? transform.keyTransform : keyTransform;
|
|
92
92
|
result[getKey(name, fieldSchema, sourceKey)] = value;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -121,7 +121,7 @@ export function getContentTransform({
|
|
|
121
121
|
}
|
|
122
122
|
function transformKey(transforms, propSchema, name, transform = preferKey) {
|
|
123
123
|
const schemaTransform = findTransforms(transforms, propSchema, name);
|
|
124
|
-
if (schemaTransform
|
|
124
|
+
if (schemaTransform?.keyTransform) {
|
|
125
125
|
transform = schemaTransform.keyTransform;
|
|
126
126
|
}
|
|
127
127
|
return transform(name, propSchema);
|
|
@@ -135,9 +135,8 @@ export function getPropertyInfo(context, schema, path) {
|
|
|
135
135
|
const result = [];
|
|
136
136
|
const findProperty = (currentSchema, name, rest, path) => {
|
|
137
137
|
if (isObjectSchema(currentSchema)) {
|
|
138
|
-
var _currentSchema$requir;
|
|
139
138
|
const propSchema = currentSchema.properties[name];
|
|
140
|
-
const isRequired =
|
|
139
|
+
const isRequired = currentSchema.required?.includes(name) ?? false;
|
|
141
140
|
if (!propSchema) {
|
|
142
141
|
return;
|
|
143
142
|
}
|
package/es/interfaces.js
CHANGED
|
@@ -3,7 +3,7 @@ import mapValues from 'lodash/mapValues';
|
|
|
3
3
|
import { isUnionSchema } from './unions';
|
|
4
4
|
import { isDefined } from '@takeshape/util';
|
|
5
5
|
export function isInterfaceShape(shape) {
|
|
6
|
-
return
|
|
6
|
+
return shape?.type === 'interface';
|
|
7
7
|
}
|
|
8
8
|
export function isInterfaceRef(context, propertySchema) {
|
|
9
9
|
const ref = getRef(context, propertySchema);
|
|
@@ -36,7 +36,7 @@ export function pruneUnusedInterfaces(projectSchema, shapeMap) {
|
|
|
36
36
|
const {
|
|
37
37
|
interfaces
|
|
38
38
|
} = shape;
|
|
39
|
-
if (interfaces
|
|
39
|
+
if (interfaces?.length) {
|
|
40
40
|
const filteredInterfaces = interfaces.filter(refExpression => shapeMap[refItemToNamespacedShapeName(refExpressionToRefItem(projectSchema, refExpression))]);
|
|
41
41
|
if (interfaces.length !== filteredInterfaces.length) {
|
|
42
42
|
return {
|
|
@@ -55,8 +55,7 @@ export function getImplementingShapes(context, interfaceRef) {
|
|
|
55
55
|
const shapeMap = context.shapes;
|
|
56
56
|
const implementingShapes = [];
|
|
57
57
|
for (const shape of Object.values(shapeMap)) {
|
|
58
|
-
|
|
59
|
-
if ((_shape$interfaces = shape.interfaces) !== null && _shape$interfaces !== void 0 && _shape$interfaces.find(interfaceRefExpression => compareRefItems(refExpressionToRefItem(context, interfaceRefExpression), interfaceRef))) {
|
|
58
|
+
if (shape.interfaces?.find(interfaceRefExpression => compareRefItems(refExpressionToRefItem(context, interfaceRefExpression), interfaceRef))) {
|
|
60
59
|
implementingShapes.push(shape);
|
|
61
60
|
}
|
|
62
61
|
}
|
package/es/layers/layers.js
CHANGED
|
@@ -170,9 +170,8 @@ function collectServiceRefs(flattenedSchema, getLayer) {
|
|
|
170
170
|
for (const ref of refs) {
|
|
171
171
|
const [layerId, shapeName] = splitAtRef(ref);
|
|
172
172
|
if (layerId !== 'local') {
|
|
173
|
-
var _layer$shapes;
|
|
174
173
|
const layer = getLayer(layerId);
|
|
175
|
-
const shape = layer
|
|
174
|
+
const shape = layer?.shapes?.[shapeName];
|
|
176
175
|
if (shape) {
|
|
177
176
|
visitSchemaProperties(shape.schema, ['schema'], collectReferencedShapeNames(layerId, refs));
|
|
178
177
|
}
|
|
@@ -255,7 +254,6 @@ export function flattenSchema(projectSchema, getLayer) {
|
|
|
255
254
|
forms: {}
|
|
256
255
|
};
|
|
257
256
|
const filteredLayers = layers.reverse().map(layer => {
|
|
258
|
-
var _config$visibility;
|
|
259
257
|
const config = typeof layer === 'string' ? {
|
|
260
258
|
...layerDefaults,
|
|
261
259
|
id: layer
|
|
@@ -264,15 +262,14 @@ export function flattenSchema(projectSchema, getLayer) {
|
|
|
264
262
|
if (!layerSchema) {
|
|
265
263
|
throw new Error(`Unable to flatten schema for project ${projectSchema.projectId}. Cannot get layer ${config.id}`);
|
|
266
264
|
}
|
|
267
|
-
return
|
|
265
|
+
return config.visibility?.length ? filterLayer(layerSchema, config.visibility) : undefined;
|
|
268
266
|
}).filter(isDefined);
|
|
269
267
|
for (const filteredLayer of filteredLayers) {
|
|
270
|
-
var _projectSchema$servic;
|
|
271
268
|
const {
|
|
272
269
|
layerId
|
|
273
270
|
} = filteredLayer;
|
|
274
271
|
// Preserve original queries
|
|
275
|
-
if (
|
|
272
|
+
if (projectSchema.services?.[layerId]) {
|
|
276
273
|
const serviceLayer = ensureServiceLayer(flattenedSchema, layerId);
|
|
277
274
|
if (serviceLayer.queries && filteredLayer.queries) {
|
|
278
275
|
Object.assign(serviceLayer.queries, filteredLayer.queries);
|
|
@@ -304,8 +301,7 @@ export function flattenSchema(projectSchema, getLayer) {
|
|
|
304
301
|
for (const refStr of collectServiceRefs(flattenedSchema, getLayer)) {
|
|
305
302
|
const [layerId, shapeName] = splitAtRef(refStr);
|
|
306
303
|
if (layerId !== 'local') {
|
|
307
|
-
|
|
308
|
-
const shape = (_getLayer = getLayer(layerId)) === null || _getLayer === void 0 ? void 0 : (_getLayer$shapes = _getLayer.shapes) === null || _getLayer$shapes === void 0 ? void 0 : _getLayer$shapes[shapeName];
|
|
304
|
+
const shape = getLayer(layerId)?.shapes?.[shapeName];
|
|
309
305
|
if (shape) {
|
|
310
306
|
const serviceLayer = ensureServiceLayer(flattenedSchema, layerId);
|
|
311
307
|
if (!serviceLayer.shapes) {
|
package/es/layers/refs.js
CHANGED
|
@@ -144,8 +144,7 @@ export const omitRefAndExtend = (targetSchema, sourceSchema) => assign(omit(['@r
|
|
|
144
144
|
export function followRef(shapes, contentSchema) {
|
|
145
145
|
const refItem = getRef(contentSchema);
|
|
146
146
|
if (refItem) {
|
|
147
|
-
|
|
148
|
-
const referencedSchema = (_refItemToShape = refItemToShape(shapes, refItem)) === null || _refItemToShape === void 0 ? void 0 : _refItemToShape.schema;
|
|
147
|
+
const referencedSchema = refItemToShape(shapes, refItem)?.schema;
|
|
149
148
|
if (referencedSchema) {
|
|
150
149
|
return omitRefAndExtend(contentSchema, referencedSchema);
|
|
151
150
|
}
|
package/es/layers/type-utils.js
CHANGED
|
@@ -8,10 +8,10 @@ import { latestSchemaJson } from '../schemas';
|
|
|
8
8
|
* Only tests that the shape is right, not that the name is correct. That's a job for the validator.
|
|
9
9
|
*/
|
|
10
10
|
export function isBasicResolver(resolver) {
|
|
11
|
-
return isString(resolver
|
|
11
|
+
return isString(resolver?.name) && isString(resolver.service);
|
|
12
12
|
}
|
|
13
13
|
export function isComposeResolver(resolver) {
|
|
14
|
-
return Boolean(isArray(resolver
|
|
14
|
+
return Boolean(isArray(resolver?.compose) && resolver.compose.length && resolver.compose.every(isBasicResolver));
|
|
15
15
|
}
|
|
16
16
|
const {
|
|
17
17
|
definitions: {
|
|
@@ -183,7 +183,7 @@ const migrate = async (context, projectSchema) => {
|
|
|
183
183
|
...serviceConfig,
|
|
184
184
|
auth
|
|
185
185
|
}, serviceKey);
|
|
186
|
-
const authentication = updatedServiceConfig
|
|
186
|
+
const authentication = updatedServiceConfig?.authentication;
|
|
187
187
|
serviceMap[serviceKey] = {
|
|
188
188
|
...updatedServiceConfig,
|
|
189
189
|
authentication: authentication && isObject(authentication) ? encryptFn(authentication) : authentication
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import omit from 'lodash/omit';
|
|
2
2
|
function hasWebhook(projectSchema, config) {
|
|
3
|
-
|
|
4
|
-
const queryName = (_config$queries = config.queries) === null || _config$queries === void 0 ? void 0 : (_config$queries$singl = _config$queries.single) === null || _config$queries$singl === void 0 ? void 0 : _config$queries$singl.name;
|
|
3
|
+
const queryName = config.queries?.single?.name;
|
|
5
4
|
if (!queryName) {
|
|
6
5
|
return false;
|
|
7
6
|
}
|
|
8
|
-
const resolver = projectSchema
|
|
9
|
-
return resolver && 'service' in resolver &&
|
|
7
|
+
const resolver = projectSchema?.queries[queryName]?.resolver;
|
|
8
|
+
return resolver && 'service' in resolver && projectSchema?.services?.[resolver.service].provider === 'shopify';
|
|
10
9
|
}
|
|
11
10
|
const migrate = async (_, {
|
|
12
11
|
indexedShapes: oldIndexedShapes,
|
|
@@ -19,7 +18,6 @@ const migrate = async (_, {
|
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
const indexedShapes = Object.fromEntries(Object.entries(oldIndexedShapes).map(([shapeName, config]) => {
|
|
22
|
-
var _config$queries$all;
|
|
23
21
|
const queries = {};
|
|
24
22
|
const triggers = [];
|
|
25
23
|
if (!config.queries) {
|
|
@@ -38,7 +36,7 @@ const migrate = async (_, {
|
|
|
38
36
|
events: ['products/create', 'products/update', 'products/delete']
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
|
-
const oldPagination =
|
|
39
|
+
const oldPagination = config.queries.all?.pagination;
|
|
42
40
|
const pagination = oldPagination === undefined ? undefined : oldPagination.type === 'cursor' ? {
|
|
43
41
|
...oldPagination,
|
|
44
42
|
itemsToIndexPath: oldPagination.itemsPath,
|
|
@@ -19,39 +19,34 @@ const migrate = async (_, projectSchema) => {
|
|
|
19
19
|
const ensureResolverOptions = resolver => {
|
|
20
20
|
if (resolver.name.startsWith('takeshape')) {
|
|
21
21
|
if (!resolver.shapeName) {
|
|
22
|
-
|
|
23
|
-
resolver.shapeName = ((_resolver$options = resolver.options) === null || _resolver$options === void 0 ? void 0 : _resolver$options.model) ?? ((_resolver$options2 = resolver.options) === null || _resolver$options2 === void 0 ? void 0 : _resolver$options2.indexedShape) ?? '';
|
|
22
|
+
resolver.shapeName = resolver.options?.model ?? resolver.options?.indexedShape ?? '';
|
|
24
23
|
omitOptions(resolver, ['model', 'indexedShape']);
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
if (resolver.name.startsWith('graphql')) {
|
|
28
27
|
if (!resolver.fieldName) {
|
|
29
|
-
|
|
30
|
-
resolver.fieldName = ((_resolver$options3 = resolver.options) === null || _resolver$options3 === void 0 ? void 0 : _resolver$options3.fieldName) ?? '';
|
|
28
|
+
resolver.fieldName = resolver.options?.fieldName ?? '';
|
|
31
29
|
omitOptions(resolver, ['fieldName']);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
if (resolver.name.startsWith('awsLambda')) {
|
|
35
33
|
if (!resolver.functionName) {
|
|
36
|
-
|
|
37
|
-
resolver.functionName = ((_resolver$options4 = resolver.options) === null || _resolver$options4 === void 0 ? void 0 : _resolver$options4.functionName) ?? '';
|
|
34
|
+
resolver.functionName = resolver.options?.functionName ?? '';
|
|
38
35
|
omitOptions(resolver, ['functionName']);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
if (resolver.name.startsWith('rest')) {
|
|
42
39
|
if (!resolver.path) {
|
|
43
40
|
if (resolver.pathParams) {
|
|
44
|
-
var _resolver$options5;
|
|
45
41
|
resolver.path = {
|
|
46
42
|
...resolver.pathParams,
|
|
47
43
|
serialize: {
|
|
48
44
|
...resolver.pathParams.serialize,
|
|
49
|
-
template:
|
|
45
|
+
template: resolver.options?.path
|
|
50
46
|
}
|
|
51
47
|
};
|
|
52
48
|
} else {
|
|
53
|
-
|
|
54
|
-
resolver.path = ((_resolver$options6 = resolver.options) === null || _resolver$options6 === void 0 ? void 0 : _resolver$options6.path) ?? '';
|
|
49
|
+
resolver.path = resolver.options?.path ?? '';
|
|
55
50
|
}
|
|
56
51
|
omitOptions(resolver, ['path']);
|
|
57
52
|
}
|
package/es/models/service.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class ServiceConfig {
|
|
5
5
|
constructor(projectSchemaModel, _serviceId) {
|
|
6
|
-
var _projectSchemaModel$j;
|
|
7
6
|
this._serviceId = _serviceId;
|
|
8
|
-
if (!
|
|
7
|
+
if (!projectSchemaModel.json.services?.[_serviceId]) {
|
|
9
8
|
throw new Error(`Could not create service model for ${_serviceId}`);
|
|
10
9
|
}
|
|
11
10
|
this._storedServiceConfig = projectSchemaModel.json.services[_serviceId];
|
package/es/models/shape.js
CHANGED
|
@@ -60,8 +60,7 @@ export class ShapeModel {
|
|
|
60
60
|
return this._shapeRefItem.serviceKey;
|
|
61
61
|
}
|
|
62
62
|
get modelType() {
|
|
63
|
-
|
|
64
|
-
return (_this$_rawShape$model = this._rawShape.model) === null || _this$_rawShape$model === void 0 ? void 0 : _this$_rawShape$model.type;
|
|
63
|
+
return this._rawShape.model?.type;
|
|
65
64
|
}
|
|
66
65
|
get interfaces() {
|
|
67
66
|
return this._rawShape.interfaces;
|
package/es/refs.js
CHANGED
|
@@ -187,12 +187,11 @@ export function splitAtRef(atRef) {
|
|
|
187
187
|
* the type.
|
|
188
188
|
*/
|
|
189
189
|
export function atRefToRefItem(context, atRef, template) {
|
|
190
|
-
var _context$services;
|
|
191
190
|
const [serviceKey, typeName] = splitAtRef(atRef);
|
|
192
191
|
// It's possible the service doesn't have a namespace, or is local and has
|
|
193
192
|
// no service config.
|
|
194
|
-
const serviceConfig =
|
|
195
|
-
const serviceNamespace = serviceConfig
|
|
193
|
+
const serviceConfig = context.services?.[serviceKey];
|
|
194
|
+
const serviceNamespace = serviceConfig?.namespace;
|
|
196
195
|
return {
|
|
197
196
|
typeName,
|
|
198
197
|
serviceKey,
|
|
@@ -486,10 +485,7 @@ export function dereferenceObjectSchema(context, shapeOrFieldSchema, schemaPath
|
|
|
486
485
|
return schema;
|
|
487
486
|
}
|
|
488
487
|
export function createGetNamespace(context) {
|
|
489
|
-
return serviceId =>
|
|
490
|
-
var _context$services2, _context$services2$se;
|
|
491
|
-
return (_context$services2 = context.services) === null || _context$services2 === void 0 ? void 0 : (_context$services2$se = _context$services2[serviceId]) === null || _context$services2$se === void 0 ? void 0 : _context$services2$se.namespace;
|
|
492
|
-
};
|
|
488
|
+
return serviceId => context.services?.[serviceId]?.namespace;
|
|
493
489
|
}
|
|
494
490
|
export function parsePropertyRef(refStr) {
|
|
495
491
|
const index = refStr.lastIndexOf(':');
|