@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.
Files changed (55) hide show
  1. package/dist/content-schema-transform.js +4 -5
  2. package/dist/interfaces.js +3 -4
  3. package/dist/layers/layers.js +4 -8
  4. package/dist/layers/refs.js +1 -2
  5. package/dist/layers/type-utils.js +2 -2
  6. package/dist/migration/to/v3.1.0.js +1 -1
  7. package/dist/migration/to/v3.12.3.js +4 -6
  8. package/dist/migration/to/v3.9.0.js +5 -10
  9. package/dist/models/service.js +1 -2
  10. package/dist/models/shape.js +1 -2
  11. package/dist/refs.js +3 -7
  12. package/dist/relationships.js +6 -9
  13. package/dist/schema-transform.js +1 -1
  14. package/dist/schema-util.d.ts +1 -0
  15. package/dist/schema-util.d.ts.map +1 -1
  16. package/dist/schema-util.js +20 -13
  17. package/dist/services.js +3 -6
  18. package/dist/taxonomies.js +3 -10
  19. package/dist/template-shapes/templates.js +1 -2
  20. package/dist/template-shapes/where.js +5 -8
  21. package/dist/types/utils.js +10 -12
  22. package/dist/unions.js +1 -2
  23. package/dist/util/api-indexing.js +3 -4
  24. package/dist/util/form-config.js +1 -2
  25. package/dist/util/has-arg.js +1 -2
  26. package/dist/util/merge.js +5 -7
  27. package/dist/validate.js +16 -25
  28. package/dist/workflows.js +1 -2
  29. package/es/content-schema-transform.js +4 -5
  30. package/es/interfaces.js +3 -4
  31. package/es/layers/layers.js +4 -8
  32. package/es/layers/refs.js +1 -2
  33. package/es/layers/type-utils.js +2 -2
  34. package/es/migration/to/v3.1.0.js +1 -1
  35. package/es/migration/to/v3.12.3.js +4 -6
  36. package/es/migration/to/v3.9.0.js +5 -10
  37. package/es/models/service.js +1 -2
  38. package/es/models/shape.js +1 -2
  39. package/es/refs.js +3 -7
  40. package/es/relationships.js +6 -9
  41. package/es/schema-transform.js +1 -1
  42. package/es/schema-util.js +16 -12
  43. package/es/services.js +3 -6
  44. package/es/taxonomies.js +3 -10
  45. package/es/template-shapes/templates.js +1 -2
  46. package/es/template-shapes/where.js +5 -8
  47. package/es/types/utils.js +10 -12
  48. package/es/unions.js +1 -2
  49. package/es/util/api-indexing.js +3 -4
  50. package/es/util/form-config.js +1 -2
  51. package/es/util/has-arg.js +1 -2
  52. package/es/util/merge.js +5 -7
  53. package/es/validate.js +13 -22
  54. package/es/workflows.js +1 -2
  55. package/package.json +7 -7
@@ -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 === null || resolver === void 0 ? void 0 : resolver.compose) && resolver.compose.length && resolver.compose.every(isBasicResolver));
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
- var _maybeConfig$options;
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 === null || maybeAuthentication === void 0 ? void 0 : maybeAuthentication.type;
270
+ return maybeAuthentication?.type;
272
271
  }
273
272
  function isBearerAuthentication(authentication) {
274
- return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'bearer';
273
+ return authentication?.type === 'bearer';
275
274
  }
276
275
  function isBasicAuthentication(authentication) {
277
- return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'basic';
276
+ return authentication?.type === 'basic';
278
277
  }
279
278
  function isSearchParamsAuthentication(authentication) {
280
- return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'searchParams';
279
+ return authentication?.type === 'searchParams';
281
280
  }
282
281
  function isOAuth2Authentication(authentication) {
283
- return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'oauth2';
282
+ return authentication?.type === 'oauth2';
284
283
  }
285
284
  function isOAuth2BearerAuthentication(authentication) {
286
- return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'oauth2Bearer';
285
+ return authentication?.type === 'oauth2Bearer';
287
286
  }
288
287
  function isCustomAuthentication(authentication) {
289
- return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'custom';
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
- var _schema$Resolver;
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
- var _schema$oneOf;
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 = (_shape$loaders = shape.loaders) === null || _shape$loaders === void 0 ? void 0 : _shape$loaders.list;
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 !== null && queryConfig !== void 0 && queryConfig.query ? (0, _refs.getQuery)(projectSchema, queryConfig.query) : undefined;
36
- return resolved !== null && resolved !== void 0 && resolved.query ? [...services, ...(0, _services.getResolverServices)(resolved.query.resolver)] : services;
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) {
@@ -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 (_normalizedForms$shap = normalizedForms[shapeName]) === null || _normalizedForms$shap === void 0 ? void 0 : _normalizedForms$shap[formName];
82
+ return normalizedForms[shapeName]?.[formName];
84
83
  }
@@ -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' ? (_projectSchema$shapes = projectSchema.shapes[args]) === null || _projectSchema$shapes === void 0 ? void 0 : _projectSchema$shapes.schema : args;
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
  }
@@ -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 === null || baseShape === void 0 ? void 0 : baseShape.schema;
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 === null || baseShape === void 0 ? void 0 : baseShape.schema;
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 = (_base$forms = base.forms) === null || _base$forms === void 0 ? void 0 : (_base$forms$shapeName = _base$forms[shapeName]) === null || _base$forms$shapeName === void 0 ? void 0 : _base$forms$shapeName.default;
236
- const fromForm = (_head$forms = head.forms) === null || _head$forms === void 0 ? void 0 : (_head$forms$shapeName = _head$forms[shapeName]) === null || _head$forms$shapeName === void 0 ? void 0 : _head$forms$shapeName.default;
234
+ const toForm = base.forms?.[shapeName]?.default;
235
+ const fromForm = head.forms?.[shapeName]?.default;
237
236
  if (toForm && fromForm) {
238
- var _parent$forms, _parent$forms$shapeNa;
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 _coerce2 = _interopRequireDefault(require("semver/functions/coerce"));
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, _coerce2.default)(schemaVersion) ?? _versions.LEGACY_SCHEMA_VERSION;
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 !== null && shape !== void 0 && shape.model) {
159
+ if (shape?.model) {
161
160
  return true;
162
161
  }
163
- return Boolean((shape === null || shape === void 0 ? void 0 : (_shape$cache = shape.cache) === null || _shape$cache === void 0 ? void 0 : _shape$cache.enabled) && shape.loaders);
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
- var _projectSchema$servic;
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 ((_shape$cache2 = shape.cache) !== null && _shape$cache2 !== void 0 && _shape$cache2.triggers) {
398
- var _context$entitlements;
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 = (layer === null || layer === void 0 ? void 0 : layer.schema) ?? projectSchema;
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
- var _schema$required, _interfaceSchema$requ;
647
- const propRequired = Boolean((_schema$required = schema.required) === null || _schema$required === void 0 ? void 0 : _schema$required.includes(name));
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
- var _shape$interfaces;
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
- var _coerce, _ajv$errors;
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 = ((_ajv$errors = ajv.errors) === null || _ajv$errors === void 0 ? void 0 : _ajv$errors.map(formatError)) ?? [];
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, _coerce2.default)(schema.schemaVersion) ?? _versions.LEGACY_SCHEMA_VERSION)) {
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', (_validate$errors = validate.errors) === null || _validate$errors === void 0 ? void 0 : _validate$errors.map(formatError));
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', (_validate$errors2 = validate.errors) === null || _validate$errors2 === void 0 ? void 0 : _validate$errors2.map(formatError));
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
- var _getShapeById;
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 === null || obj === void 0 ? void 0 : obj[sourceKey], name);
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 !== null && transform !== void 0 && transform.keyTransform ? transform.keyTransform : keyTransform;
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 !== null && schemaTransform !== void 0 && schemaTransform.keyTransform) {
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 = ((_currentSchema$requir = currentSchema.required) === null || _currentSchema$requir === void 0 ? void 0 : _currentSchema$requir.includes(name)) ?? false;
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 (shape === null || shape === void 0 ? void 0 : shape.type) === 'interface';
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 !== null && interfaces !== void 0 && interfaces.length) {
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
- var _shape$interfaces;
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
  }
@@ -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 === null || layer === void 0 ? void 0 : (_layer$shapes = layer.shapes) === null || _layer$shapes === void 0 ? void 0 : _layer$shapes[shapeName];
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 (_config$visibility = config.visibility) !== null && _config$visibility !== void 0 && _config$visibility.length ? filterLayer(layerSchema, config.visibility) : undefined;
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 ((_projectSchema$servic = projectSchema.services) !== null && _projectSchema$servic !== void 0 && _projectSchema$servic[layerId]) {
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
- var _getLayer, _getLayer$shapes;
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
- var _refItemToShape;
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
  }
@@ -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 === null || resolver === void 0 ? void 0 : resolver.name) && isString(resolver.service);
11
+ return isString(resolver?.name) && isString(resolver.service);
12
12
  }
13
13
  export function isComposeResolver(resolver) {
14
- return Boolean(isArray(resolver === null || resolver === void 0 ? void 0 : resolver.compose) && resolver.compose.length && resolver.compose.every(isBasicResolver));
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 === null || updatedServiceConfig === void 0 ? void 0 : updatedServiceConfig.authentication;
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
- var _config$queries, _config$queries$singl, _projectSchema$querie, _projectSchema$servic;
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 === null || projectSchema === void 0 ? void 0 : (_projectSchema$querie = projectSchema.queries[queryName]) === null || _projectSchema$querie === void 0 ? void 0 : _projectSchema$querie.resolver;
9
- return resolver && 'service' in resolver && (projectSchema === null || projectSchema === void 0 ? void 0 : (_projectSchema$servic = projectSchema.services) === null || _projectSchema$servic === void 0 ? void 0 : _projectSchema$servic[resolver.service].provider) === 'shopify';
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 = (_config$queries$all = config.queries.all) === null || _config$queries$all === void 0 ? void 0 : _config$queries$all.pagination;
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
- var _resolver$options, _resolver$options2;
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
- var _resolver$options3;
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
- var _resolver$options4;
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: (_resolver$options5 = resolver.options) === null || _resolver$options5 === void 0 ? void 0 : _resolver$options5.path
45
+ template: resolver.options?.path
50
46
  }
51
47
  };
52
48
  } else {
53
- var _resolver$options6;
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
  }
@@ -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 (!((_projectSchemaModel$j = projectSchemaModel.json.services) !== null && _projectSchemaModel$j !== void 0 && _projectSchemaModel$j[_serviceId])) {
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];
@@ -60,8 +60,7 @@ export class ShapeModel {
60
60
  return this._shapeRefItem.serviceKey;
61
61
  }
62
62
  get modelType() {
63
- var _this$_rawShape$model;
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 = (_context$services = context.services) === null || _context$services === void 0 ? void 0 : _context$services[serviceKey];
195
- const serviceNamespace = serviceConfig === null || serviceConfig === void 0 ? void 0 : serviceConfig.namespace;
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(':');