@sprucelabs/schema 26.0.139 → 27.0.1

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.
@@ -1,6 +1,6 @@
1
1
  import AbstractSpruceError, { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
2
2
  import { FieldType } from '../fields/field.static.types';
3
- export declare type SchemaErrorOptions = DuplicateSchemaErrorOptions | SchemaErrorOptionsNotFound | TransformationFailedErrorOptions | InvalidSchemaDefinitionErrorOptions | NotImplementedErrorOptions | InvalidFieldRegistrationErrorOptions | VersionRequiredErrorOptions | MissingParametersOptions | InvalidParametersOptions | UnexpectedParametersOptions | ValidationFailedErrorOptions;
3
+ export declare type SchemaErrorOptions = DuplicateSchemaErrorOptions | SchemaErrorOptionsNotFound | TransformationFailedErrorOptions | InvalidSchemaDefinitionErrorOptions | NotImplementedErrorOptions | InvalidFieldRegistrationErrorOptions | VersionRequiredErrorOptions | MissingParametersOptions | InvalidParametersOptions | UnexpectedParametersOptions | ValidationFailedErrorOptions | InvalidSchemaReferenceErrorOptions;
4
4
  export declare type FieldErrorCode = 'MISSING_PARAMETER' | 'INVALID_PARAMETER' | 'UNEXPECTED_PARAMETER';
5
5
  export interface FieldError {
6
6
  code: FieldErrorCode;
@@ -54,18 +54,18 @@ export interface VersionRequiredErrorOptions extends ISpruceErrorOptions {
54
54
  schemaId?: string;
55
55
  namespace?: string;
56
56
  }
57
- interface ParamaterOptions extends ISpruceErrorOptions {
57
+ interface ParameterOptions extends ISpruceErrorOptions {
58
58
  parameters: string[];
59
59
  friendlyMessages?: string[];
60
60
  errors?: FieldError[];
61
61
  }
62
- export interface MissingParametersOptions extends ParamaterOptions {
62
+ export interface MissingParametersOptions extends ParameterOptions {
63
63
  code: 'MISSING_PARAMETERS';
64
64
  }
65
- export interface InvalidParametersOptions extends ParamaterOptions {
65
+ export interface InvalidParametersOptions extends ParameterOptions {
66
66
  code: 'INVALID_PARAMETERS';
67
67
  }
68
- export interface UnexpectedParametersOptions extends ParamaterOptions {
68
+ export interface UnexpectedParametersOptions extends ParameterOptions {
69
69
  code: 'UNEXPECTED_PARAMETERS';
70
70
  }
71
71
  export interface ValidationFailedErrorOptions extends ISpruceErrorOptions {
@@ -74,5 +74,8 @@ export interface ValidationFailedErrorOptions extends ISpruceErrorOptions {
74
74
  schemaName?: string;
75
75
  errors: FieldError[];
76
76
  }
77
+ export interface InvalidSchemaReferenceErrorOptions extends ISpruceErrorOptions {
78
+ code: 'INVALID_SCHEMA_REFERENCE';
79
+ }
77
80
  export declare type ValidationError = AbstractSpruceError<MissingParametersOptions | InvalidParametersOptions | UnexpectedParametersOptions>;
78
81
  export {};
@@ -1,6 +1,6 @@
1
1
  import AbstractSpruceError, { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
2
2
  import { FieldType } from '../fields/field.static.types';
3
- export declare type SchemaErrorOptions = DuplicateSchemaErrorOptions | SchemaErrorOptionsNotFound | TransformationFailedErrorOptions | InvalidSchemaDefinitionErrorOptions | NotImplementedErrorOptions | InvalidFieldRegistrationErrorOptions | VersionRequiredErrorOptions | MissingParametersOptions | InvalidParametersOptions | UnexpectedParametersOptions | ValidationFailedErrorOptions;
3
+ export declare type SchemaErrorOptions = DuplicateSchemaErrorOptions | SchemaErrorOptionsNotFound | TransformationFailedErrorOptions | InvalidSchemaDefinitionErrorOptions | NotImplementedErrorOptions | InvalidFieldRegistrationErrorOptions | VersionRequiredErrorOptions | MissingParametersOptions | InvalidParametersOptions | UnexpectedParametersOptions | ValidationFailedErrorOptions | InvalidSchemaReferenceErrorOptions;
4
4
  export declare type FieldErrorCode = 'MISSING_PARAMETER' | 'INVALID_PARAMETER' | 'UNEXPECTED_PARAMETER';
5
5
  export interface FieldError {
6
6
  code: FieldErrorCode;
@@ -54,18 +54,18 @@ export interface VersionRequiredErrorOptions extends ISpruceErrorOptions {
54
54
  schemaId?: string;
55
55
  namespace?: string;
56
56
  }
57
- interface ParamaterOptions extends ISpruceErrorOptions {
57
+ interface ParameterOptions extends ISpruceErrorOptions {
58
58
  parameters: string[];
59
59
  friendlyMessages?: string[];
60
60
  errors?: FieldError[];
61
61
  }
62
- export interface MissingParametersOptions extends ParamaterOptions {
62
+ export interface MissingParametersOptions extends ParameterOptions {
63
63
  code: 'MISSING_PARAMETERS';
64
64
  }
65
- export interface InvalidParametersOptions extends ParamaterOptions {
65
+ export interface InvalidParametersOptions extends ParameterOptions {
66
66
  code: 'INVALID_PARAMETERS';
67
67
  }
68
- export interface UnexpectedParametersOptions extends ParamaterOptions {
68
+ export interface UnexpectedParametersOptions extends ParameterOptions {
69
69
  code: 'UNEXPECTED_PARAMETERS';
70
70
  }
71
71
  export interface ValidationFailedErrorOptions extends ISpruceErrorOptions {
@@ -74,5 +74,8 @@ export interface ValidationFailedErrorOptions extends ISpruceErrorOptions {
74
74
  schemaName?: string;
75
75
  errors: FieldError[];
76
76
  }
77
+ export interface InvalidSchemaReferenceErrorOptions extends ISpruceErrorOptions {
78
+ code: 'INVALID_SCHEMA_REFERENCE';
79
+ }
77
80
  export declare type ValidationError = AbstractSpruceError<MissingParametersOptions | InvalidParametersOptions | UnexpectedParametersOptions>;
78
81
  export {};
@@ -5,7 +5,7 @@ import SchemaRegistry from '../singletons/SchemaRegistry.js';
5
5
  import StaticSchemaEntity from '../StaticSchemaEntityImplementation.js';
6
6
  import { TemplateRenderAs, } from '../types/template.types.js';
7
7
  import isIdWithVersion from '../utilities/isIdWithVersion.js';
8
- import normaizeSchemaToIdWithVersion from '../utilities/normalizeSchemaToIdWithVersion.js';
8
+ import normalizeSchemaToIdWithVersion from '../utilities/normalizeSchemaToIdWithVersion.js';
9
9
  import validateSchema from '../utilities/validateSchema.js';
10
10
  import AbstractField from './AbstractField.js';
11
11
  export default class SchemaField extends AbstractField {
@@ -44,7 +44,7 @@ export default class SchemaField extends AbstractField {
44
44
  }
45
45
  static mapFieldDefinitionToSchemaIdsWithVersion(field) {
46
46
  const schemasOrIds = this.mapFieldDefinitionToSchemasOrIdsWithVersion(field);
47
- const ids = schemasOrIds.map((item) => normaizeSchemaToIdWithVersion(item));
47
+ const ids = schemasOrIds.map((item) => normalizeSchemaToIdWithVersion(item));
48
48
  return ids;
49
49
  }
50
50
  static generateTypeDetails() {
@@ -59,9 +59,19 @@ export default class SchemaField extends AbstractField {
59
59
  const unions = [];
60
60
  idsWithVersion.forEach((idWithVersion) => {
61
61
  const { id, version, namespace } = idWithVersion;
62
- let allMatches = templateItems.filter((item) => item.id.toLowerCase() === id.toLowerCase());
62
+ let allMatches = templateItems.filter((item) => {
63
+ if (!item.id) {
64
+ throwInvalidReferenceError(item);
65
+ }
66
+ return item.id.toLowerCase() === id.toLowerCase();
67
+ });
63
68
  if (namespace) {
64
- allMatches = allMatches.filter((item) => item.namespace.toLowerCase() === namespace.toLowerCase());
69
+ allMatches = allMatches.filter((item) => {
70
+ if (!item.namespace) {
71
+ throwInvalidReferenceError(item);
72
+ }
73
+ return item.namespace.toLowerCase() === namespace.toLowerCase();
74
+ });
65
75
  }
66
76
  let matchedTemplateItem;
67
77
  if (allMatches.length === 0) {
@@ -100,7 +110,7 @@ export default class SchemaField extends AbstractField {
100
110
  throw new SpruceError({
101
111
  code: 'SCHEMA_NOT_FOUND',
102
112
  schemaId: id,
103
- friendlyMessage: 'Failed during generation of value type on the Schema field. This can happen if schema id "${schemaId}" is not in "templateItems" (which should hold every schema in your skill).',
113
+ friendlyMessage: `Template generation failed. I could not find a schema that was being referenced. I was looking for a schema with the id of '${id}' and namespace '${namespace !== null && namespace !== void 0 ? namespace : '**missing**'}'.`,
104
114
  });
105
115
  }
106
116
  });
@@ -312,3 +322,9 @@ export default class SchemaField extends AbstractField {
312
322
  });
313
323
  }
314
324
  }
325
+ function throwInvalidReferenceError(item) {
326
+ throw new SpruceError({
327
+ code: 'INVALID_SCHEMA_REFERENCE',
328
+ friendlyMessage: `Generating template failed because one of your schema references (the schema a field with 'type=schema' points to) is missing a namespace. Look through your builders for a field pointing to something like:\n\n${JSON.stringify(item, null, 2)}`,
329
+ });
330
+ }
@@ -5,7 +5,7 @@ import dateRegistration from './addons/dateField.addon.js';
5
5
  import dateTimeRegistration from './addons/dateTimeField.addon.js';
6
6
  import directoryRegistration from './addons/directoryField.addon.js';
7
7
  import durationRegistration from './addons/durationField.addon.js';
8
- import emailRegisteration from './addons/emailField.addon.js';
8
+ import emailRegistration from './addons/emailField.addon.js';
9
9
  import fileRegistration from './addons/fileField.addon.js';
10
10
  import idRegistration from './addons/idField.addon.js';
11
11
  import numberRegistration from './addons/numberField.addon.js';
@@ -63,7 +63,7 @@ export const fieldRegistrations = [
63
63
  schemaRegistration,
64
64
  selectRegistration,
65
65
  textRegistration,
66
- emailRegisteration,
66
+ emailRegistration,
67
67
  ];
68
68
  export { default as assertOptions } from './utilities/assertOptions.js';
69
69
  export { default as mapFieldErrorsToParameterErrors } from './utilities/mapFieldErrorsToParameterErrors.js';
@@ -1,2 +1,2 @@
1
1
  import { Schema, SchemaIdWithVersion } from '../schemas.static.types';
2
- export default function normaizeSchemaToIdWithVersion(schemaOrIdWithVersion: Schema | SchemaIdWithVersion): SchemaIdWithVersion;
2
+ export default function normalizeSchemaToIdWithVersion(schemaOrIdWithVersion: Schema | SchemaIdWithVersion): SchemaIdWithVersion;
@@ -1,5 +1,5 @@
1
1
  import isIdWithVersion from './isIdWithVersion.js';
2
- export default function normaizeSchemaToIdWithVersion(schemaOrIdWithVersion) {
2
+ export default function normalizeSchemaToIdWithVersion(schemaOrIdWithVersion) {
3
3
  if (isIdWithVersion(schemaOrIdWithVersion)) {
4
4
  return schemaOrIdWithVersion;
5
5
  }
@@ -64,9 +64,19 @@ class SchemaField extends AbstractField_1.default {
64
64
  const unions = [];
65
65
  idsWithVersion.forEach((idWithVersion) => {
66
66
  const { id, version, namespace } = idWithVersion;
67
- let allMatches = templateItems.filter((item) => item.id.toLowerCase() === id.toLowerCase());
67
+ let allMatches = templateItems.filter((item) => {
68
+ if (!item.id) {
69
+ throwInvalidReferenceError(item);
70
+ }
71
+ return item.id.toLowerCase() === id.toLowerCase();
72
+ });
68
73
  if (namespace) {
69
- allMatches = allMatches.filter((item) => item.namespace.toLowerCase() === namespace.toLowerCase());
74
+ allMatches = allMatches.filter((item) => {
75
+ if (!item.namespace) {
76
+ throwInvalidReferenceError(item);
77
+ }
78
+ return item.namespace.toLowerCase() === namespace.toLowerCase();
79
+ });
70
80
  }
71
81
  let matchedTemplateItem;
72
82
  if (allMatches.length === 0) {
@@ -105,7 +115,7 @@ class SchemaField extends AbstractField_1.default {
105
115
  throw new SpruceError_1.default({
106
116
  code: 'SCHEMA_NOT_FOUND',
107
117
  schemaId: id,
108
- friendlyMessage: 'Failed during generation of value type on the Schema field. This can happen if schema id "${schemaId}" is not in "templateItems" (which should hold every schema in your skill).',
118
+ friendlyMessage: `Template generation failed. I could not find a schema that was being referenced. I was looking for a schema with the id of '${id}' and namespace '${namespace !== null && namespace !== void 0 ? namespace : '**missing**'}'.`,
109
119
  });
110
120
  }
111
121
  });
@@ -318,3 +328,9 @@ class SchemaField extends AbstractField_1.default {
318
328
  }
319
329
  }
320
330
  exports.default = SchemaField;
331
+ function throwInvalidReferenceError(item) {
332
+ throw new SpruceError_1.default({
333
+ code: 'INVALID_SCHEMA_REFERENCE',
334
+ friendlyMessage: `Generating template failed because one of your schema references (the schema a field with 'type=schema' points to) is missing a namespace. Look through your builders for a field pointing to something like:\n\n${JSON.stringify(item, null, 2)}`,
335
+ });
336
+ }
@@ -1,2 +1,2 @@
1
1
  import { Schema, SchemaIdWithVersion } from '../schemas.static.types';
2
- export default function normaizeSchemaToIdWithVersion(schemaOrIdWithVersion: Schema | SchemaIdWithVersion): SchemaIdWithVersion;
2
+ export default function normalizeSchemaToIdWithVersion(schemaOrIdWithVersion: Schema | SchemaIdWithVersion): SchemaIdWithVersion;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const isIdWithVersion_1 = __importDefault(require("./isIdWithVersion"));
7
- function normaizeSchemaToIdWithVersion(schemaOrIdWithVersion) {
7
+ function normalizeSchemaToIdWithVersion(schemaOrIdWithVersion) {
8
8
  if ((0, isIdWithVersion_1.default)(schemaOrIdWithVersion)) {
9
9
  return schemaOrIdWithVersion;
10
10
  }
@@ -17,4 +17,4 @@ function normaizeSchemaToIdWithVersion(schemaOrIdWithVersion) {
17
17
  }
18
18
  return idWithVersion;
19
19
  }
20
- exports.default = normaizeSchemaToIdWithVersion;
20
+ exports.default = normalizeSchemaToIdWithVersion;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "26.0.139",
11
+ "version": "27.0.1",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",
@@ -70,12 +70,12 @@
70
70
  "mime-type": "^4.0.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@sprucelabs/esm-postbuild": "^1.0.407",
73
+ "@sprucelabs/esm-postbuild": "^1.0.409",
74
74
  "@sprucelabs/jest-json-reporter": "^6.0.331",
75
75
  "@sprucelabs/jest-sheets-reporter": "^1.3.15",
76
76
  "@sprucelabs/resolve-path-aliases": "^1.0.261",
77
77
  "@sprucelabs/semantic-release": "^4.0.8",
78
- "@sprucelabs/test-utils": "^3.0.477",
78
+ "@sprucelabs/test-utils": "^3.0.479",
79
79
  "@types/lodash": "^4.14.178",
80
80
  "@types/mime-db": "^1.43.1",
81
81
  "chokidar-cli": "^3.0.0",