@sprucelabs/schema 26.0.138 → 27.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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() {
@@ -61,7 +61,15 @@ export default class SchemaField extends AbstractField {
61
61
  const { id, version, namespace } = idWithVersion;
62
62
  let allMatches = templateItems.filter((item) => item.id.toLowerCase() === id.toLowerCase());
63
63
  if (namespace) {
64
- allMatches = allMatches.filter((item) => item.namespace.toLowerCase() === namespace.toLowerCase());
64
+ allMatches = allMatches.filter((item) => {
65
+ if (!item.namespace) {
66
+ throw new SpruceError({
67
+ code: 'INVALID_SCHEMA_REFERENCE',
68
+ 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)}`,
69
+ });
70
+ }
71
+ return item.namespace.toLowerCase() === namespace.toLowerCase();
72
+ });
65
73
  }
66
74
  let matchedTemplateItem;
67
75
  if (allMatches.length === 0) {
@@ -100,7 +108,7 @@ export default class SchemaField extends AbstractField {
100
108
  throw new SpruceError({
101
109
  code: 'SCHEMA_NOT_FOUND',
102
110
  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).',
111
+ 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
112
  });
105
113
  }
106
114
  });
@@ -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
  }
@@ -66,7 +66,15 @@ class SchemaField extends AbstractField_1.default {
66
66
  const { id, version, namespace } = idWithVersion;
67
67
  let allMatches = templateItems.filter((item) => item.id.toLowerCase() === id.toLowerCase());
68
68
  if (namespace) {
69
- allMatches = allMatches.filter((item) => item.namespace.toLowerCase() === namespace.toLowerCase());
69
+ allMatches = allMatches.filter((item) => {
70
+ if (!item.namespace) {
71
+ throw new SpruceError_1.default({
72
+ code: 'INVALID_SCHEMA_REFERENCE',
73
+ 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)}`,
74
+ });
75
+ }
76
+ return item.namespace.toLowerCase() === namespace.toLowerCase();
77
+ });
70
78
  }
71
79
  let matchedTemplateItem;
72
80
  if (allMatches.length === 0) {
@@ -105,7 +113,7 @@ class SchemaField extends AbstractField_1.default {
105
113
  throw new SpruceError_1.default({
106
114
  code: 'SCHEMA_NOT_FOUND',
107
115
  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).',
116
+ 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
117
  });
110
118
  }
111
119
  });
@@ -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.138",
11
+ "version": "27.0.0",
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.406",
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.476",
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",