@sprucelabs/schema 30.0.12 → 30.0.13

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 (38) hide show
  1. package/build/AbstractEntity.js +0 -1
  2. package/build/AbstractSchemaTest.js +0 -1
  3. package/build/DynamicSchemaEntityImplementation.js +1 -2
  4. package/build/StaticSchemaEntityImpl.js +10 -10
  5. package/build/errors/SpruceError.js +4 -3
  6. package/build/errors/ValidateErrorMessageFormatter.js +7 -6
  7. package/build/fields/AbstractField.js +9 -12
  8. package/build/fields/AddressField.js +1 -1
  9. package/build/fields/BooleanField.js +1 -1
  10. package/build/fields/DateField.js +1 -1
  11. package/build/fields/DateTimeField.js +3 -2
  12. package/build/fields/DirectoryField.js +2 -2
  13. package/build/fields/DurationField.js +3 -2
  14. package/build/fields/EmailField.js +1 -1
  15. package/build/fields/FileField.js +4 -3
  16. package/build/fields/IdField.js +1 -1
  17. package/build/fields/ImageField.js +5 -3
  18. package/build/fields/NumberField.js +1 -1
  19. package/build/fields/PhoneField.js +1 -1
  20. package/build/fields/RawField.js +1 -1
  21. package/build/fields/SchemaField.js +4 -3
  22. package/build/fields/SelectField.js +1 -1
  23. package/build/fields/TextField.js +3 -2
  24. package/build/singletons/SchemaRegistry.js +6 -4
  25. package/build/tests/AbstractDateFieldTest.js +0 -2
  26. package/build/tests/validationErrorAssert.utility.js +3 -2
  27. package/build/utilities/KeyMapper.js +4 -3
  28. package/build/utilities/areSchemasTheSame.js +3 -2
  29. package/build/utilities/assertOptions.js +1 -1
  30. package/build/utilities/cloneDeep.js +3 -2
  31. package/build/utilities/cloneDeepPreservingInstances.js +2 -1
  32. package/build/utilities/formatPhoneNumber.js +3 -2
  33. package/build/utilities/getFields.js +2 -1
  34. package/build/utilities/normalizeFieldValue.js +3 -2
  35. package/build/utilities/selectChoicesToHash.js +2 -1
  36. package/build/utilities/validateSchema.js +2 -1
  37. package/build/utilities/validateSchemaValues.js +1 -1
  38. package/package.json +4 -4
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class AbstractEntity {
4
- schema;
5
4
  get schemaId() {
6
5
  return this.schema.id;
7
6
  }
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const test_utils_1 = __importDefault(require("@sprucelabs/test-utils"));
7
7
  const _1 = require(".");
8
8
  class AbstractSchemaTest extends test_utils_1.default {
9
- static registry;
10
9
  static async beforeEach() {
11
10
  await super.beforeEach();
12
11
  this.registry = _1.SchemaRegistry.getInstance();
@@ -8,10 +8,9 @@ const SpruceError_1 = __importDefault(require("./errors/SpruceError"));
8
8
  const FieldFactory_1 = __importDefault(require("./factories/FieldFactory"));
9
9
  const normalizeFieldValue_1 = __importDefault(require("./utilities/normalizeFieldValue"));
10
10
  class DynamicSchemaEntityImplementation extends AbstractEntity_1.default {
11
- values = {};
12
- dynamicField;
13
11
  constructor(schema, values) {
14
12
  super(schema);
13
+ this.values = {};
15
14
  if (!schema.dynamicFieldSignature) {
16
15
  throw new Error(`DynamicSchemaEntity only works with with schemas with dynamicFieldSignature set.`);
17
16
  }
@@ -32,12 +32,9 @@ const FieldFactory_1 = __importDefault(require("./factories/FieldFactory"));
32
32
  const cloneDeepPreservingInstances_1 = __importDefault(require("./utilities/cloneDeepPreservingInstances"));
33
33
  const normalizeFieldValue_1 = __importStar(require("./utilities/normalizeFieldValue"));
34
34
  class StaticSchemaEntityImpl extends AbstractEntity_1.default {
35
- static enableDuplicateCheckWhenTracking = true;
36
- schema;
37
- values = {};
38
- fields;
39
35
  constructor(schema, values) {
40
36
  super(schema);
37
+ this.values = {};
41
38
  this.schema = schema;
42
39
  this.fields = {};
43
40
  this.buildFields();
@@ -62,10 +59,11 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
62
59
  });
63
60
  }
64
61
  normalizeValue(forField, value, options) {
62
+ var _a, _b;
65
63
  const field = this.fields[forField];
66
64
  const overrideOptions = {
67
- ...(options ?? {}),
68
- ...(options?.byField?.[forField] ?? {}),
65
+ ...(options !== null && options !== void 0 ? options : {}),
66
+ ...((_b = (_a = options === null || options === void 0 ? void 0 : options.byField) === null || _a === void 0 ? void 0 : _a[forField]) !== null && _b !== void 0 ? _b : {}),
69
67
  };
70
68
  return (0, normalizeFieldValue_1.default)(this.schemaId, this.name, {}, field, value, overrideOptions);
71
69
  }
@@ -115,24 +113,25 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
115
113
  });
116
114
  }
117
115
  this.getNamedFields(options).forEach((namedField) => {
116
+ var _a, _b, _c, _d;
118
117
  const { name, field } = namedField;
119
118
  let valueAsArray = (0, normalizeFieldValue_1.normalizeValueToArray)(this.values[name]);
120
119
  if (field.isRequired &&
121
120
  field.isArray &&
122
121
  (!this.values[name] ||
123
- valueAsArray.length < (field.minArrayLength ?? 1))) {
122
+ valueAsArray.length < ((_a = field.minArrayLength) !== null && _a !== void 0 ? _a : 1))) {
124
123
  errors.push({
125
124
  code: !this.values[name]
126
125
  ? 'MISSING_PARAMETER'
127
126
  : 'INVALID_PARAMETER',
128
127
  name,
129
128
  friendlyMessage: !this.values[name]
130
- ? `'${field.label ?? field.name}' is required!`
131
- : `'${field.label ?? field.name}' must have at least ${field.minArrayLength} value${field.minArrayLength === 1 ? '' : 's'}. I found ${valueAsArray.length}!`,
129
+ ? `'${(_b = field.label) !== null && _b !== void 0 ? _b : field.name}' is required!`
130
+ : `'${(_c = field.label) !== null && _c !== void 0 ? _c : field.name}' must have at least ${field.minArrayLength} value${field.minArrayLength === 1 ? '' : 's'}. I found ${valueAsArray.length}!`,
132
131
  });
133
132
  }
134
133
  else {
135
- if ((!field.isArray || (field.minArrayLength ?? 0) > 0) &&
134
+ if ((!field.isArray || ((_d = field.minArrayLength) !== null && _d !== void 0 ? _d : 0) > 0) &&
136
135
  valueAsArray.length === 0) {
137
136
  valueAsArray = [undefined];
138
137
  }
@@ -206,4 +205,5 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
206
205
  return namedFields;
207
206
  }
208
207
  }
208
+ StaticSchemaEntityImpl.enableDuplicateCheckWhenTracking = true;
209
209
  exports.default = StaticSchemaEntityImpl;
@@ -7,12 +7,13 @@ const error_1 = __importDefault(require("@sprucelabs/error"));
7
7
  const ValidateErrorMessageFormatter_1 = require("./ValidateErrorMessageFormatter");
8
8
  class SpruceError extends error_1.default {
9
9
  friendlyMessage() {
10
+ var _a;
10
11
  const { options } = this;
11
12
  if (options.friendlyMessage) {
12
13
  return options.friendlyMessage;
13
14
  }
14
15
  let message;
15
- switch (options?.code) {
16
+ switch (options === null || options === void 0 ? void 0 : options.code) {
16
17
  case 'DUPLICATE_SCHEMA':
17
18
  message = `Duplicate schema -> '${this.buildSchemaName(options)}'.`;
18
19
  break;
@@ -21,7 +22,7 @@ class SpruceError extends error_1.default {
21
22
  break;
22
23
  case 'TRANSFORMATION_ERROR':
23
24
  message = '';
24
- options.errors?.forEach((error) => {
25
+ (_a = options.errors) === null || _a === void 0 ? void 0 : _a.forEach((error) => {
25
26
  message += `Error on ${error.name}:\n`;
26
27
  if (error.originalError) {
27
28
  message += ` ${error.originalError.message}`;
@@ -64,7 +65,7 @@ class SpruceError extends error_1.default {
64
65
  return message;
65
66
  }
66
67
  renderParametersWithFriendlyMessages(parameters, friendlyMessages) {
67
- const friendly = (friendlyMessages ?? parameters)
68
+ const friendly = (friendlyMessages !== null && friendlyMessages !== void 0 ? friendlyMessages : parameters)
68
69
  .filter((m) => !!m)
69
70
  .map((m) => `${m}`)
70
71
  .join('\n');
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ValidateErrorMessageFormatter = void 0;
7
7
  const SpruceError_1 = __importDefault(require("./SpruceError"));
8
8
  class ValidateErrorMessageFormatter {
9
- error;
10
9
  constructor(error) {
10
+ var _a;
11
11
  if (!error) {
12
12
  throw new SpruceError_1.default({
13
13
  code: 'MISSING_PARAMETERS',
14
14
  parameters: ['error'],
15
15
  });
16
16
  }
17
- else if (error.options?.code !== 'VALIDATION_FAILED') {
17
+ else if (((_a = error.options) === null || _a === void 0 ? void 0 : _a.code) !== 'VALIDATION_FAILED') {
18
18
  throw new SpruceError_1.default({
19
19
  code: 'INVALID_PARAMETERS',
20
20
  parameters: ['error'],
@@ -28,7 +28,7 @@ class ValidateErrorMessageFormatter {
28
28
  let count = countOption;
29
29
  const lines = [];
30
30
  const name = this.renderFieldName(fieldError, namePrefix);
31
- if (fieldError?.errors) {
31
+ if (fieldError === null || fieldError === void 0 ? void 0 : fieldError.errors) {
32
32
  for (const error of fieldError.errors) {
33
33
  lines.push(this.renderError({
34
34
  fieldError: error,
@@ -75,15 +75,16 @@ class ValidateErrorMessageFormatter {
75
75
  return count;
76
76
  }
77
77
  renderSchemaName(shouldUseReadableNames = false) {
78
+ var _a;
78
79
  return shouldUseReadableNames
79
- ? this.error.options.schemaName ?? this.error.options.schemaId
80
+ ? (_a = this.error.options.schemaName) !== null && _a !== void 0 ? _a : this.error.options.schemaId
80
81
  : this.error.options.schemaId;
81
82
  }
82
83
  render(options) {
83
84
  const totalErrors = this.getTotalErrors();
84
- let message = options?.shouldRenderHeadline === false
85
+ let message = (options === null || options === void 0 ? void 0 : options.shouldRenderHeadline) === false
85
86
  ? ''
86
- : `'${this.renderSchemaName(options?.shouldUseReadableNames)}' has ${totalErrors} error${totalErrors === 1 ? '' : 's'}!\n\n`;
87
+ : `'${this.renderSchemaName(options === null || options === void 0 ? void 0 : options.shouldUseReadableNames)}' has ${totalErrors} error${totalErrors === 1 ? '' : 's'}!\n\n`;
87
88
  const errors = this.error.options.errors;
88
89
  let count = 1;
89
90
  const lines = [];
@@ -2,27 +2,17 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a;
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
6
7
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
8
  const isUndefinedOrNull_1 = __importDefault(require("../utilities/isUndefinedOrNull"));
8
9
  class AbstractField {
9
- /** The definition for this field */
10
- definition;
11
- /** Shortcut to this field */
12
- type;
13
- /** The name of this field (camel case) */
14
- name;
15
10
  constructor(name, definition) {
16
11
  this.definition = definition;
17
12
  this.name = name;
18
13
  this.type = definition.type;
19
14
  return this;
20
15
  }
21
- static description = `Please set the description for your field ${this.name}:
22
-
23
- public static description = '*** describe your field here ***'
24
-
25
- `;
26
16
  /** For mapping schemas to types dynamically in schema values */
27
17
  static generateTypeDetails() {
28
18
  return {
@@ -64,7 +54,8 @@ public static generateTemplateDetails(
64
54
  return this.definition.hint;
65
55
  }
66
56
  get minArrayLength() {
67
- return this.definition.minArrayLength ?? 1;
57
+ var _b;
58
+ return (_b = this.definition.minArrayLength) !== null && _b !== void 0 ? _b : 1;
68
59
  }
69
60
  validate(value, _) {
70
61
  const errors = [];
@@ -82,4 +73,10 @@ public static generateTemplateDetails(
82
73
  return value;
83
74
  }
84
75
  }
76
+ _a = AbstractField;
77
+ AbstractField.description = `Please set the description for your field ${_a.name}:
78
+
79
+ public static description = '*** describe your field here ***'
80
+
81
+ `;
85
82
  exports.default = AbstractField;
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
7
7
  class AddressField extends AbstractField_1.default {
8
- static description = 'An address with geocoding ability *coming soon*';
9
8
  static generateTemplateDetails(options) {
10
9
  return {
11
10
  valueType: `${options.importAs}.AddressFieldValue${options.definition.isArray ? '[]' : ''}`,
12
11
  };
13
12
  }
14
13
  }
14
+ AddressField.description = 'An address with geocoding ability *coming soon*';
15
15
  exports.default = AddressField;
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
7
7
  class BooleanField extends AbstractField_1.default {
8
- static description = 'A true/false. Converts false string to false, all other strings to true.';
9
8
  static generateTemplateDetails(options) {
10
9
  return {
11
10
  valueType: `boolean${options.definition.isArray ? '[]' : ''}`,
@@ -22,4 +21,5 @@ class BooleanField extends AbstractField_1.default {
22
21
  return !!value;
23
22
  }
24
23
  }
24
+ BooleanField.description = 'A true/false. Converts false string to false, all other strings to true.';
25
25
  exports.default = BooleanField;
@@ -8,7 +8,6 @@ const getStartOfDay_1 = __importDefault(require("../utilities/getStartOfDay"));
8
8
  const isUndefinedOrNull_1 = __importDefault(require("../utilities/isUndefinedOrNull"));
9
9
  const AbstractField_1 = __importDefault(require("./AbstractField"));
10
10
  class DateField extends AbstractField_1.default {
11
- static description = 'Date and time support.';
12
11
  static generateTemplateDetails(options) {
13
12
  return {
14
13
  valueType: `${options.importAs}.DateFieldValue${options.definition.isArray ? '[]' : ''}`,
@@ -29,6 +28,7 @@ class DateField extends AbstractField_1.default {
29
28
  return value ? (0, getStartOfDay_1.default)(+value) : value;
30
29
  }
31
30
  }
31
+ DateField.description = 'Date and time support.';
32
32
  exports.default = DateField;
33
33
  function validateDateValue(options) {
34
34
  const { value, isRequired, name } = options;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
7
7
  const DateField_1 = require("./DateField");
8
8
  class DateTimeField extends AbstractField_1.default {
9
- static description = 'Date and time support.';
10
9
  static generateTemplateDetails(options) {
11
10
  return {
12
11
  valueType: `${options.importAs}.DateTimeFieldValue${options.definition.isArray ? '[]' : ''}`,
@@ -24,11 +23,12 @@ class DateTimeField extends AbstractField_1.default {
24
23
  });
25
24
  }
26
25
  toValueType(value) {
26
+ var _a;
27
27
  let normalized = value;
28
28
  if (normalized instanceof Date) {
29
29
  normalized = normalized.getTime();
30
30
  }
31
- if (this.options?.dateTimeFormat === 'iso_8601') {
31
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.dateTimeFormat) === 'iso_8601') {
32
32
  return new Date(value).toISOString();
33
33
  }
34
34
  if (typeof normalized === 'string') {
@@ -37,4 +37,5 @@ class DateTimeField extends AbstractField_1.default {
37
37
  return normalized ? +normalized : normalized;
38
38
  }
39
39
  }
40
+ DateTimeField.description = 'Date and time support.';
40
41
  exports.default = DateTimeField;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  const AbstractField_1 = __importDefault(require("./AbstractField"));
8
8
  class DirectoryField extends AbstractField_1.default {
9
- static description = 'A way to select entire directories once!';
10
9
  static generateTemplateDetails(options) {
11
10
  const { definition } = options;
12
11
  return {
@@ -18,7 +17,7 @@ class DirectoryField extends AbstractField_1.default {
18
17
  ? value.toString()
19
18
  : undefined;
20
19
  let path;
21
- const relativeTo = options?.relativeTo;
20
+ const relativeTo = options === null || options === void 0 ? void 0 : options.relativeTo;
22
21
  if (stringValue) {
23
22
  path = stringValue;
24
23
  }
@@ -43,4 +42,5 @@ class DirectoryField extends AbstractField_1.default {
43
42
  return { path };
44
43
  }
45
44
  }
45
+ DirectoryField.description = 'A way to select entire directories once!';
46
46
  exports.default = DirectoryField;
@@ -49,13 +49,13 @@ function buildDuration(value) {
49
49
  }
50
50
  exports.buildDuration = buildDuration;
51
51
  class DurationField extends AbstractField_1.default {
52
- static description = 'A span of time represented in { hours, minutes, seconds, ms }';
53
52
  static generateTemplateDetails(options) {
54
53
  return {
55
54
  valueType: `${options.importAs}.DurationFieldValue${options.definition.isArray ? '[]' : ''}`,
56
55
  };
57
56
  }
58
57
  validate(value, _) {
58
+ var _a;
59
59
  const errors = [];
60
60
  try {
61
61
  buildDuration(value);
@@ -65,7 +65,7 @@ class DurationField extends AbstractField_1.default {
65
65
  code: 'INVALID_PARAMETER',
66
66
  name: this.name,
67
67
  originalError: err,
68
- friendlyMessage: err.options?.friendlyMessage,
68
+ friendlyMessage: (_a = err.options) === null || _a === void 0 ? void 0 : _a.friendlyMessage,
69
69
  });
70
70
  }
71
71
  return errors;
@@ -74,4 +74,5 @@ class DurationField extends AbstractField_1.default {
74
74
  return buildDuration(value);
75
75
  }
76
76
  }
77
+ DurationField.description = 'A span of time represented in { hours, minutes, seconds, ms }';
77
78
  exports.default = DurationField;
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const EmailValidator = __importStar(require("email-validator"));
30
30
  const AbstractField_1 = __importDefault(require("./AbstractField"));
31
31
  class EmailField extends AbstractField_1.default {
32
- static description = 'Email support.';
33
32
  static generateTemplateDetails(options) {
34
33
  return {
35
34
  valueType: `string${options.definition.isArray ? '[]' : ''}`,
@@ -43,4 +42,5 @@ class EmailField extends AbstractField_1.default {
43
42
  return errors;
44
43
  }
45
44
  }
45
+ EmailField.description = 'Email support.';
46
46
  exports.default = EmailField;
@@ -5,15 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
7
7
  class FileField extends AbstractField_1.default {
8
- static description = 'A way to handle files. Supports mime-type lookups.';
9
8
  static generateTemplateDetails(options) {
10
9
  return {
11
10
  valueType: `${options.importAs}.FileFieldValue${options.definition.isArray ? '[]' : ''}`,
12
11
  };
13
12
  }
14
13
  validate(value, _) {
14
+ var _a, _b, _c;
15
15
  const errors = super.validate(value);
16
- const acceptableTypes = this.definition.options?.acceptableTypes ?? [];
16
+ const acceptableTypes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.acceptableTypes) !== null && _b !== void 0 ? _b : [];
17
17
  if (value &&
18
18
  !value.base64 &&
19
19
  acceptableTypes[0] !== '*' &&
@@ -21,7 +21,7 @@ class FileField extends AbstractField_1.default {
21
21
  errors.push({
22
22
  code: 'INVALID_PARAMETER',
23
23
  name: this.name,
24
- friendlyMessage: `You sent a '${value.type}' to '${this.label ?? this.name}' and it only accepts '${acceptableTypes.join("', '")}'.`,
24
+ friendlyMessage: `You sent a '${value.type}' to '${(_c = this.label) !== null && _c !== void 0 ? _c : this.name}' and it only accepts '${acceptableTypes.join("', '")}'.`,
25
25
  });
26
26
  }
27
27
  return errors;
@@ -30,4 +30,5 @@ class FileField extends AbstractField_1.default {
30
30
  return value;
31
31
  }
32
32
  }
33
+ FileField.description = 'A way to handle files. Supports mime-type lookups.';
33
34
  exports.default = FileField;
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
7
7
  class IdField extends AbstractField_1.default {
8
- static description = 'A unique identifier field.';
9
8
  static generateTemplateDetails(options) {
10
9
  return {
11
10
  valueType: `string${options.definition.isArray ? '[]' : ''}`,
@@ -15,4 +14,5 @@ class IdField extends AbstractField_1.default {
15
14
  return `${value}`;
16
15
  }
17
16
  }
17
+ IdField.description = 'A unique identifier field.';
18
18
  exports.default = IdField;
@@ -12,8 +12,8 @@ class ImageField extends AbstractField_1.default {
12
12
  valueType: `${importAs}.ImageFieldValue${definition.isArray ? '[]' : ''}`,
13
13
  };
14
14
  }
15
- static description = 'Images of various sizes!';
16
15
  validate(value) {
16
+ var _a;
17
17
  const errors = super.validate(value);
18
18
  if (value && errors.length === 0 && !value.base64) {
19
19
  let sizes = this.getRequiredSizes();
@@ -29,18 +29,20 @@ class ImageField extends AbstractField_1.default {
29
29
  errors.push({
30
30
  code: 'INVALID_PARAMETER',
31
31
  name: this.name,
32
- friendlyMessage: `You need to supply the remaining sizes to upload an image to ${this.label ?? this.name}: '${missing.join("', '")}'`,
32
+ friendlyMessage: `You need to supply the remaining sizes to upload an image to ${(_a = this.label) !== null && _a !== void 0 ? _a : this.name}: '${missing.join("', '")}'`,
33
33
  });
34
34
  }
35
35
  }
36
36
  return errors;
37
37
  }
38
38
  getRequiredSizes() {
39
- let sizes = this.definition.options?.requiredSizes ?? [];
39
+ var _a, _b;
40
+ let sizes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.requiredSizes) !== null && _b !== void 0 ? _b : [];
40
41
  if (sizes[0] === '*') {
41
42
  sizes = ImageField_types_1.requiredImageSizes.filter((s) => s !== '*');
42
43
  }
43
44
  return sizes;
44
45
  }
45
46
  }
47
+ ImageField.description = 'Images of various sizes!';
46
48
  exports.default = ImageField;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  const AbstractField_1 = __importDefault(require("./AbstractField"));
8
8
  class NumberField extends AbstractField_1.default {
9
- static description = 'Handles all types of numbers with min/max and clamp support';
10
9
  static generateTemplateDetails(options) {
11
10
  return {
12
11
  valueType: `number${options.definition.isArray ? '[]' : ''}`,
@@ -48,4 +47,5 @@ class NumberField extends AbstractField_1.default {
48
47
  return typeof value === 'undefined' || value === null || !isNaN(value);
49
48
  }
50
49
  }
50
+ NumberField.description = 'Handles all types of numbers with min/max and clamp support';
51
51
  exports.default = NumberField;
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const formatPhoneNumber_1 = __importStar(require("../utilities/formatPhoneNumber"));
30
30
  const AbstractField_1 = __importDefault(require("./AbstractField"));
31
31
  class PhoneField extends AbstractField_1.default {
32
- static description = 'Takes anything close to a phone number and formats it. Also great at validating numbers.';
33
32
  static generateTemplateDetails(options) {
34
33
  return {
35
34
  valueType: `string${options.definition.isArray ? '[]' : ''}`,
@@ -60,4 +59,5 @@ class PhoneField extends AbstractField_1.default {
60
59
  return errors;
61
60
  }
62
61
  }
62
+ PhoneField.description = 'Takes anything close to a phone number and formats it. Also great at validating numbers.';
63
63
  exports.default = PhoneField;
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
7
7
  class RawField extends AbstractField_1.default {
8
- static description = 'Set an interface directly.';
9
8
  static generateTemplateDetails(options) {
10
9
  return {
11
10
  valueType: `(${options.definition.options.valueType})${options.definition.isArray ? '[]' : ''}`,
12
11
  };
13
12
  }
14
13
  }
14
+ RawField.description = 'Set an interface directly.';
15
15
  exports.default = RawField;
@@ -12,7 +12,6 @@ const normalizeSchemaToIdWithVersion_1 = __importDefault(require("../utilities/n
12
12
  const validateSchema_1 = __importDefault(require("../utilities/validateSchema"));
13
13
  const AbstractField_1 = __importDefault(require("./AbstractField"));
14
14
  class SchemaField extends AbstractField_1.default {
15
- static description = 'A way to map relationships.';
16
15
  static mapFieldDefinitionToSchemasOrIdsWithVersion(field) {
17
16
  const { options } = field;
18
17
  const schemasOrIds = [
@@ -112,7 +111,7 @@ class SchemaField extends AbstractField_1.default {
112
111
  throw new SpruceError_1.default({
113
112
  code: 'SCHEMA_NOT_FOUND',
114
113
  schemaId: id,
115
- 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 ?? '**missing**'}'.`,
114
+ 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**'}'.`,
116
115
  });
117
116
  }
118
117
  });
@@ -154,6 +153,7 @@ class SchemaField extends AbstractField_1.default {
154
153
  return schemas;
155
154
  }
156
155
  validate(value, options) {
156
+ var _a;
157
157
  const errors = super.validate(value, options);
158
158
  // do not validate schemas by default, very heavy and only needed when explicitly asked to
159
159
  if (value instanceof AbstractEntity_1.default) {
@@ -175,7 +175,7 @@ class SchemaField extends AbstractField_1.default {
175
175
  errors.push({
176
176
  code: 'INVALID_PARAMETER',
177
177
  name: this.name,
178
- friendlyMessage: `${this.label ?? this.name} must be an object!`,
178
+ friendlyMessage: `${(_a = this.label) !== null && _a !== void 0 ? _a : this.name} must be an object!`,
179
179
  });
180
180
  }
181
181
  else {
@@ -336,6 +336,7 @@ class SchemaField extends AbstractField_1.default {
336
336
  return instance.getValues(getValueOptions);
337
337
  }
338
338
  }
339
+ SchemaField.description = 'A way to map relationships.';
339
340
  exports.default = SchemaField;
340
341
  function throwInvalidReferenceError(item) {
341
342
  throw new SpruceError_1.default({
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const selectChoicesToHash_1 = require("../utilities/selectChoicesToHash");
7
7
  const AbstractField_1 = __importDefault(require("./AbstractField"));
8
8
  class SelectField extends AbstractField_1.default {
9
- static description = 'Stored as string, lets user select between available options.';
10
9
  constructor(name, definition) {
11
10
  super(name, definition);
12
11
  if (!definition.options || !definition.options.choices) {
@@ -44,4 +43,5 @@ class SelectField extends AbstractField_1.default {
44
43
  return this.definition.options.choices;
45
44
  }
46
45
  }
46
+ SelectField.description = 'Stored as string, lets user select between available options.';
47
47
  exports.default = SelectField;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  const AbstractField_1 = __importDefault(require("./AbstractField"));
8
8
  class TextField extends AbstractField_1.default {
9
- static description = 'A text field. Converts non-strings into strings by calling toString(). Size set by options.';
10
9
  static generateTemplateDetails(options) {
11
10
  const { definition } = options;
12
11
  return {
@@ -35,9 +34,10 @@ class TextField extends AbstractField_1.default {
35
34
  return errors;
36
35
  }
37
36
  toValueType(value, options) {
37
+ var _a;
38
38
  let transformed = this.convertToString(value);
39
39
  if (typeof transformed === 'string') {
40
- const maxLength = options?.maxLength ?? 0;
40
+ const maxLength = (_a = options === null || options === void 0 ? void 0 : options.maxLength) !== null && _a !== void 0 ? _a : 0;
41
41
  if (maxLength > 0 && transformed.length > maxLength) {
42
42
  transformed = transformed.substr(0, maxLength);
43
43
  }
@@ -67,4 +67,5 @@ class TextField extends AbstractField_1.default {
67
67
  value.toString();
68
68
  }
69
69
  }
70
+ TextField.description = 'A text field. Converts non-strings into strings by calling toString(). Size set by options.';
70
71
  exports.default = TextField;
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  const validateSchema_1 = __importDefault(require("../utilities/validateSchema"));
8
8
  class SchemaRegistry {
9
- schemasById = {};
10
- static instance;
9
+ constructor() {
10
+ this.schemasById = {};
11
+ }
11
12
  static getInstance() {
12
13
  if (!this.instance) {
13
14
  this.instance = new SchemaRegistry();
@@ -83,8 +84,9 @@ class SchemaRegistry {
83
84
  return true;
84
85
  }
85
86
  forgetSchema(id, version) {
86
- this.schemasById[id] = this.schemasById[id]?.filter((schema) => !(schema.id === id && schema.version === version));
87
- if (this.schemasById[id]?.length === 0) {
87
+ var _a, _b;
88
+ this.schemasById[id] = (_a = this.schemasById[id]) === null || _a === void 0 ? void 0 : _a.filter((schema) => !(schema.id === id && schema.version === version));
89
+ if (((_b = this.schemasById[id]) === null || _b === void 0 ? void 0 : _b.length) === 0) {
88
90
  delete this.schemasById[id];
89
91
  }
90
92
  }
@@ -8,8 +8,6 @@ const __1 = require("..");
8
8
  const AbstractSchemaTest_1 = __importDefault(require("../AbstractSchemaTest"));
9
9
  const SchemaEntityFactory_1 = __importDefault(require("../factories/SchemaEntityFactory"));
10
10
  class AbstractDateFieldTest extends AbstractSchemaTest_1.default {
11
- static schema;
12
- static entity;
13
11
  static async beforeEach() {
14
12
  await super.beforeEach();
15
13
  this.entity = SchemaEntityFactory_1.default.Entity(this.schema);
@@ -24,6 +24,7 @@ function flattenFields(fieldErrors, flattened, namePrefix = '') {
24
24
  }
25
25
  const validationErrorAssert = {
26
26
  assertError(error, options) {
27
+ var _a, _b;
27
28
  const missing = [];
28
29
  const err = error;
29
30
  if (!err) {
@@ -38,7 +39,7 @@ const validationErrorAssert = {
38
39
  parameters: missing,
39
40
  });
40
41
  }
41
- if (err.options?.code !== 'VALIDATION_FAILED') {
42
+ if (((_a = err.options) === null || _a === void 0 ? void 0 : _a.code) !== 'VALIDATION_FAILED') {
42
43
  throw new SpruceError_1.default({
43
44
  code: 'INVALID_PARAMETERS',
44
45
  parameters: ['error'],
@@ -61,7 +62,7 @@ const validationErrorAssert = {
61
62
  for (let idx = 0; idx < keys.length; idx++) {
62
63
  const code = codes[idx];
63
64
  const key = keys[idx];
64
- for (const lookup of options?.[key] ?? []) {
65
+ for (const lookup of (_b = options === null || options === void 0 ? void 0 : options[key]) !== null && _b !== void 0 ? _b : []) {
65
66
  const match = flattened[lookup] === code;
66
67
  if (!match) {
67
68
  test_utils_1.assert.fail(buildFailMessage(code, lookup, flattened));
@@ -5,15 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  class KeyMapper {
8
- map;
9
8
  constructor(map) {
10
9
  this.map = map;
11
10
  }
12
11
  mapTo(values, options) {
13
- return this._mapTo(values, this.map, options?.shouldThrowOnUnmapped ?? true);
12
+ var _a;
13
+ return this._mapTo(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
14
14
  }
15
15
  mapFrom(values, options) {
16
- return this._mapFrom(values, this.map, options?.shouldThrowOnUnmapped ?? true);
16
+ var _a;
17
+ return this._mapFrom(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
17
18
  }
18
19
  mapFieldNameTo(name) {
19
20
  if (!this.map[name]) {
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function areSchemasTheSame(left, right) {
4
+ var _a, _b;
4
5
  if (left.id !== right.id) {
5
6
  return false;
6
7
  }
7
- const fields1 = Object.keys(left.fields ?? {}).sort();
8
- const fields2 = Object.keys(right.fields ?? {}).sort();
8
+ const fields1 = Object.keys((_a = left.fields) !== null && _a !== void 0 ? _a : {}).sort();
9
+ const fields2 = Object.keys((_b = right.fields) !== null && _b !== void 0 ? _b : {}).sort();
9
10
  if (fields1.join('|') !== fields2.join('|')) {
10
11
  return false;
11
12
  }
@@ -8,7 +8,7 @@ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
8
8
  function assertOptions(options, toCheck, friendlyMessage) {
9
9
  const missing = [];
10
10
  for (const check of toCheck) {
11
- const value = (0, just_safe_get_1.default)(options ?? {}, check);
11
+ const value = (0, just_safe_get_1.default)(options !== null && options !== void 0 ? options : {}, check);
12
12
  //@ts-ignore
13
13
  if (value === null || typeof value === 'undefined') {
14
14
  missing.push(check);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function cloneDeep(obj, transformer) {
4
+ var _a;
4
5
  const o = obj;
5
6
  let result = o;
6
7
  let type = {}.toString.call(o).slice(8, -1);
@@ -10,7 +11,7 @@ function cloneDeep(obj, transformer) {
10
11
  if (type == 'Map') {
11
12
  const items = [];
12
13
  [...o.entries()].forEach((kv) => {
13
- if (transformer?.(kv[1], kv[0]) !== false) {
14
+ if ((transformer === null || transformer === void 0 ? void 0 : transformer(kv[1], kv[0])) !== false) {
14
15
  items.push([cloneDeep(kv[0]), cloneDeep(kv[1])]);
15
16
  }
16
17
  });
@@ -26,7 +27,7 @@ function cloneDeep(obj, transformer) {
26
27
  result = Array.isArray(o) ? [] : {};
27
28
  for (let key in o) {
28
29
  result[key] =
29
- transformer?.(o[key], key) ?? cloneDeep(o[key], transformer);
30
+ (_a = transformer === null || transformer === void 0 ? void 0 : transformer(o[key], key)) !== null && _a !== void 0 ? _a : cloneDeep(o[key], transformer);
30
31
  }
31
32
  }
32
33
  // primitives and non-supported objects (e.g. functions) land here
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const cloneDeep_1 = __importDefault(require("./cloneDeep"));
7
7
  function cloneDeepPreservingInstances(v) {
8
8
  return (0, cloneDeep_1.default)(v, (value) => {
9
- const name = value?.__proto__?.constructor?.name;
9
+ var _a, _b;
10
+ const name = (_b = (_a = value === null || value === void 0 ? void 0 : value.__proto__) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name;
10
11
  if (name && name !== 'Object') {
11
12
  return value;
12
13
  }
@@ -28,9 +28,10 @@ function formatNumberWithCode(phoneNumberString, code = '1') {
28
28
  return null;
29
29
  }
30
30
  function isValidNumber(number) {
31
+ var _a;
31
32
  const code = getCode(number);
32
- const formatted = formatNumberWithCode(number, code)?.replace(/[^0-9]/g, '');
33
- return formatted?.length === 11 || formatted?.length === 12;
33
+ const formatted = (_a = formatNumberWithCode(number, code)) === null || _a === void 0 ? void 0 : _a.replace(/[^0-9]/g, '');
34
+ return (formatted === null || formatted === void 0 ? void 0 : formatted.length) === 11 || (formatted === null || formatted === void 0 ? void 0 : formatted.length) === 12;
34
35
  }
35
36
  exports.isValidNumber = isValidNumber;
36
37
  function getCode(number) {
@@ -5,7 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  function getFields(schema) {
8
- const names = Object.keys(schema?.fields ?? {});
8
+ var _a;
9
+ const names = Object.keys((_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : {});
9
10
  if (names.length === 0) {
10
11
  throw new SpruceError_1.default({
11
12
  code: 'INVALID_PARAMETERS',
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.normalizeValueToArray = void 0;
7
7
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
8
8
  function normalizeFieldValue(schemaId, schemaName, schemasById, field, value, options) {
9
+ var _a;
9
10
  let localValue = normalizeValueToArray(value);
10
11
  if (!Array.isArray(localValue)) {
11
12
  throw new SpruceError_1.default({
@@ -14,10 +15,10 @@ function normalizeFieldValue(schemaId, schemaName, schemasById, field, value, op
14
15
  friendlyMessages: [`I was expecting an array for ${field.name}.`],
15
16
  });
16
17
  }
17
- const { shouldValidate: validate = true, shouldCreateEntityInstances: createEntityInstances = true, ...extraOptions } = options ?? {};
18
+ const { shouldValidate: validate = true, shouldCreateEntityInstances: createEntityInstances = true, ...extraOptions } = options !== null && options !== void 0 ? options : {};
18
19
  const baseOptions = {
19
20
  schemasById,
20
- ...(field.definition.options ?? {}),
21
+ ...((_a = field.definition.options) !== null && _a !== void 0 ? _a : {}),
21
22
  ...extraOptions,
22
23
  };
23
24
  if (value === null || typeof value === 'undefined') {
@@ -13,9 +13,10 @@ function selectChoicesToHash(options) {
13
13
  exports.selectChoicesToHash = selectChoicesToHash;
14
14
  /** Take a definition and a field name and returns a value/label hash */
15
15
  function schemaChoicesToHash(definition, fieldName) {
16
+ var _a, _b, _c, _d;
16
17
  // @ts-ignore
17
18
  return selectChoicesToHash(
18
19
  // @ts-ignore
19
- definition.fields?.[fieldName]?.options?.choices ?? []);
20
+ (_d = (_c = (_b = (_a = definition.fields) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.choices) !== null && _d !== void 0 ? _d : []);
20
21
  }
21
22
  exports.schemaChoicesToHash = schemaChoicesToHash;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  function validateSchema(schema) {
8
+ var _a;
8
9
  const errors = [];
9
10
  if (!schema) {
10
11
  errors.push('definition_empty');
@@ -26,7 +27,7 @@ function validateSchema(schema) {
26
27
  if (errors.length > 0) {
27
28
  throw new SpruceError_1.default({
28
29
  code: 'INVALID_SCHEMA',
29
- schemaId: schema?.id ?? 'ID MISSING',
30
+ schemaId: (_a = schema === null || schema === void 0 ? void 0 : schema.id) !== null && _a !== void 0 ? _a : 'ID MISSING',
30
31
  errors,
31
32
  });
32
33
  }
@@ -7,7 +7,7 @@ const just_safe_set_1 = __importDefault(require("just-safe-set"));
7
7
  const __1 = require("..");
8
8
  const SchemaEntityFactory_1 = __importDefault(require("../factories/SchemaEntityFactory"));
9
9
  function validateSchemaValues(schema, values, options) {
10
- const { ...opts } = options ?? {};
10
+ const { ...opts } = options !== null && options !== void 0 ? options : {};
11
11
  (0, __1.validateSchema)(schema);
12
12
  const mapped = Object.keys(values).reduce((mapped, key) => {
13
13
  //@ts-ignore
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "30.0.12",
11
+ "version": "30.0.13",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",
@@ -62,7 +62,7 @@
62
62
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/"
63
63
  },
64
64
  "dependencies": {
65
- "@sprucelabs/error": "^6.0.8",
65
+ "@sprucelabs/error": "^6.0.9",
66
66
  "@sprucelabs/test-utils": "^5.0.9",
67
67
  "email-validator": "^2.0.4",
68
68
  "just-safe-get": "^4.2.0",
@@ -70,10 +70,10 @@
70
70
  },
71
71
  "devDependencies": {
72
72
  "@sprucelabs/esm-postbuild": "^6.0.8",
73
- "@sprucelabs/jest-json-reporter": "^8.0.6",
73
+ "@sprucelabs/jest-json-reporter": "^8.0.7",
74
74
  "@sprucelabs/resolve-path-aliases": "^2.0.10",
75
75
  "@sprucelabs/semantic-release": "^5.0.1",
76
- "@sprucelabs/test": "^9.0.6",
76
+ "@sprucelabs/test": "^9.0.7",
77
77
  "chokidar-cli": "^3.0.0",
78
78
  "concurrently": "^8.2.2",
79
79
  "eslint": "^9.1.1",