@sprucelabs/schema 30.0.486 → 30.0.488
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/StaticSchemaEntityImpl.js +6 -8
- package/build/errors/SpruceError.js +3 -4
- package/build/errors/ValidateErrorMessageFormatter.js +5 -7
- package/build/fields/AbstractField.js +1 -2
- package/build/fields/DateTimeField.js +1 -2
- package/build/fields/DirectoryField.js +1 -1
- package/build/fields/DurationField.js +1 -2
- package/build/fields/FileField.js +2 -3
- package/build/fields/ImageField.js +2 -4
- package/build/fields/SchemaField.js +2 -3
- package/build/fields/TextField.js +1 -2
- package/build/singletons/SchemaRegistry.js +2 -3
- package/build/tests/validationErrorAssert.utility.js +2 -3
- package/build/utilities/KeyMapper.js +2 -4
- package/build/utilities/areSchemasTheSame.js +2 -3
- package/build/utilities/assertOptions.js +1 -1
- package/build/utilities/cloneDeep.js +2 -3
- package/build/utilities/cloneDeepPreservingInstances.js +1 -2
- package/build/utilities/formatPhoneNumber.js +2 -3
- package/build/utilities/getFields.js +1 -2
- package/build/utilities/normalizeFieldValue.js +3 -4
- package/build/utilities/selectChoicesToHash.js +1 -2
- package/build/utilities/validateSchema.js +1 -2
- package/build/utilities/validateSchemaValues.js +1 -1
- package/package.json +7 -7
|
@@ -59,11 +59,10 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
normalizeValue(forField, value, options) {
|
|
62
|
-
var _a, _b;
|
|
63
62
|
const field = this.fields[forField];
|
|
64
63
|
const overrideOptions = {
|
|
65
|
-
...(options
|
|
66
|
-
...(
|
|
64
|
+
...(options ?? {}),
|
|
65
|
+
...(options?.byField?.[forField] ?? {}),
|
|
67
66
|
};
|
|
68
67
|
return (0, normalizeFieldValue_1.default)(this.schemaId, this.name, {}, field, value, overrideOptions);
|
|
69
68
|
}
|
|
@@ -113,25 +112,24 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
|
|
|
113
112
|
});
|
|
114
113
|
}
|
|
115
114
|
this.getNamedFields(options).forEach((namedField) => {
|
|
116
|
-
var _a, _b, _c, _d;
|
|
117
115
|
const { name, field } = namedField;
|
|
118
116
|
let valueAsArray = (0, normalizeFieldValue_1.normalizeValueToArray)(this.values[name]);
|
|
119
117
|
if (field.isRequired &&
|
|
120
118
|
field.isArray &&
|
|
121
119
|
(!this.values[name] ||
|
|
122
|
-
valueAsArray.length < (
|
|
120
|
+
valueAsArray.length < (field.minArrayLength ?? 1))) {
|
|
123
121
|
errors.push({
|
|
124
122
|
code: !this.values[name]
|
|
125
123
|
? 'MISSING_PARAMETER'
|
|
126
124
|
: 'INVALID_PARAMETER',
|
|
127
125
|
name,
|
|
128
126
|
friendlyMessage: !this.values[name]
|
|
129
|
-
? `'${
|
|
130
|
-
: `'${
|
|
127
|
+
? `'${field.label ?? field.name}' is required!`
|
|
128
|
+
: `'${field.label ?? field.name}' must have at least ${field.minArrayLength} value${field.minArrayLength === 1 ? '' : 's'}. I found ${valueAsArray.length}!`,
|
|
131
129
|
});
|
|
132
130
|
}
|
|
133
131
|
else {
|
|
134
|
-
if ((!field.isArray || (
|
|
132
|
+
if ((!field.isArray || (field.minArrayLength ?? 0) > 0) &&
|
|
135
133
|
valueAsArray.length === 0) {
|
|
136
134
|
valueAsArray = [undefined];
|
|
137
135
|
}
|
|
@@ -7,13 +7,12 @@ 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;
|
|
11
10
|
const { options } = this;
|
|
12
11
|
if (options.friendlyMessage) {
|
|
13
12
|
return options.friendlyMessage;
|
|
14
13
|
}
|
|
15
14
|
let message;
|
|
16
|
-
switch (options
|
|
15
|
+
switch (options?.code) {
|
|
17
16
|
case 'DUPLICATE_SCHEMA':
|
|
18
17
|
message = `Duplicate schema -> '${this.buildSchemaName(options)}'.`;
|
|
19
18
|
break;
|
|
@@ -22,7 +21,7 @@ class SpruceError extends error_1.default {
|
|
|
22
21
|
break;
|
|
23
22
|
case 'TRANSFORMATION_ERROR':
|
|
24
23
|
message = '';
|
|
25
|
-
|
|
24
|
+
options.errors?.forEach((error) => {
|
|
26
25
|
message += `Error on ${error.name}:\n`;
|
|
27
26
|
if (error.originalError) {
|
|
28
27
|
message += ` ${error.originalError.message}`;
|
|
@@ -65,7 +64,7 @@ class SpruceError extends error_1.default {
|
|
|
65
64
|
return message;
|
|
66
65
|
}
|
|
67
66
|
renderParametersWithFriendlyMessages(parameters, friendlyMessages) {
|
|
68
|
-
const friendly = (friendlyMessages
|
|
67
|
+
const friendly = (friendlyMessages ?? parameters)
|
|
69
68
|
.filter((m) => !!m)
|
|
70
69
|
.map((m) => `${m}`)
|
|
71
70
|
.join('\n');
|
|
@@ -7,14 +7,13 @@ exports.ValidateErrorMessageFormatter = void 0;
|
|
|
7
7
|
const SpruceError_1 = __importDefault(require("./SpruceError"));
|
|
8
8
|
class ValidateErrorMessageFormatter {
|
|
9
9
|
constructor(error) {
|
|
10
|
-
var _a;
|
|
11
10
|
if (!error) {
|
|
12
11
|
throw new SpruceError_1.default({
|
|
13
12
|
code: 'MISSING_PARAMETERS',
|
|
14
13
|
parameters: ['error'],
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
|
-
else if (
|
|
16
|
+
else if (error.options?.code !== 'VALIDATION_FAILED') {
|
|
18
17
|
throw new SpruceError_1.default({
|
|
19
18
|
code: 'INVALID_PARAMETERS',
|
|
20
19
|
parameters: ['error'],
|
|
@@ -28,7 +27,7 @@ class ValidateErrorMessageFormatter {
|
|
|
28
27
|
let count = countOption;
|
|
29
28
|
const lines = [];
|
|
30
29
|
const name = this.renderFieldName(fieldError, namePrefix);
|
|
31
|
-
if (fieldError
|
|
30
|
+
if (fieldError?.errors) {
|
|
32
31
|
for (const error of fieldError.errors) {
|
|
33
32
|
lines.push(this.renderError({
|
|
34
33
|
fieldError: error,
|
|
@@ -75,16 +74,15 @@ class ValidateErrorMessageFormatter {
|
|
|
75
74
|
return count;
|
|
76
75
|
}
|
|
77
76
|
renderSchemaName(shouldUseReadableNames = false) {
|
|
78
|
-
var _a;
|
|
79
77
|
return shouldUseReadableNames
|
|
80
|
-
? (
|
|
78
|
+
? (this.error.options.schemaName ?? this.error.options.schemaId)
|
|
81
79
|
: this.error.options.schemaId;
|
|
82
80
|
}
|
|
83
81
|
render(options) {
|
|
84
82
|
const totalErrors = this.getTotalErrors();
|
|
85
|
-
let message =
|
|
83
|
+
let message = options?.shouldRenderHeadline === false
|
|
86
84
|
? ''
|
|
87
|
-
: `'${this.renderSchemaName(options
|
|
85
|
+
: `'${this.renderSchemaName(options?.shouldUseReadableNames)}' has ${totalErrors} error${totalErrors === 1 ? '' : 's'}!\n\n`;
|
|
88
86
|
const errors = this.error.options.errors;
|
|
89
87
|
let count = 1;
|
|
90
88
|
const lines = [];
|
|
@@ -54,8 +54,7 @@ public static generateTemplateDetails(
|
|
|
54
54
|
return this.definition.hint;
|
|
55
55
|
}
|
|
56
56
|
get minArrayLength() {
|
|
57
|
-
|
|
58
|
-
return (_b = this.definition.minArrayLength) !== null && _b !== void 0 ? _b : 1;
|
|
57
|
+
return this.definition.minArrayLength ?? 1;
|
|
59
58
|
}
|
|
60
59
|
validate(value, _) {
|
|
61
60
|
const errors = [];
|
|
@@ -23,12 +23,11 @@ class DateTimeField extends AbstractField_1.default {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
toValueType(value) {
|
|
26
|
-
var _a;
|
|
27
26
|
let normalized = value;
|
|
28
27
|
if (normalized instanceof Date) {
|
|
29
28
|
normalized = normalized.getTime();
|
|
30
29
|
}
|
|
31
|
-
if (
|
|
30
|
+
if (this.options?.dateTimeFormat === 'iso_8601') {
|
|
32
31
|
return new Date(value).toISOString();
|
|
33
32
|
}
|
|
34
33
|
if (typeof normalized === 'string') {
|
|
@@ -17,7 +17,7 @@ class DirectoryField extends AbstractField_1.default {
|
|
|
17
17
|
? value.toString()
|
|
18
18
|
: undefined;
|
|
19
19
|
let path;
|
|
20
|
-
const relativeTo = options
|
|
20
|
+
const relativeTo = options?.relativeTo;
|
|
21
21
|
if (stringValue) {
|
|
22
22
|
path = stringValue;
|
|
23
23
|
}
|
|
@@ -54,7 +54,6 @@ class DurationField extends AbstractField_1.default {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
validate(value, _) {
|
|
57
|
-
var _a;
|
|
58
57
|
const errors = [];
|
|
59
58
|
try {
|
|
60
59
|
buildDuration(value);
|
|
@@ -64,7 +63,7 @@ class DurationField extends AbstractField_1.default {
|
|
|
64
63
|
code: 'INVALID_PARAMETER',
|
|
65
64
|
name: this.name,
|
|
66
65
|
originalError: err,
|
|
67
|
-
friendlyMessage:
|
|
66
|
+
friendlyMessage: err.options?.friendlyMessage,
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
69
|
return errors;
|
|
@@ -11,9 +11,8 @@ class FileField extends AbstractField_1.default {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
validate(value, _) {
|
|
14
|
-
var _a, _b, _c;
|
|
15
14
|
const errors = super.validate(value);
|
|
16
|
-
const acceptableTypes =
|
|
15
|
+
const acceptableTypes = this.definition.options?.acceptableTypes ?? [];
|
|
17
16
|
if (value &&
|
|
18
17
|
!value.base64 &&
|
|
19
18
|
acceptableTypes[0] !== '*' &&
|
|
@@ -21,7 +20,7 @@ class FileField extends AbstractField_1.default {
|
|
|
21
20
|
errors.push({
|
|
22
21
|
code: 'INVALID_PARAMETER',
|
|
23
22
|
name: this.name,
|
|
24
|
-
friendlyMessage: `You sent a '${value.type}' to '${
|
|
23
|
+
friendlyMessage: `You sent a '${value.type}' to '${this.label ?? this.name}' and it only accepts '${acceptableTypes.join("', '")}'.`,
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
26
|
return errors;
|
|
@@ -13,7 +13,6 @@ class ImageField extends AbstractField_1.default {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
validate(value) {
|
|
16
|
-
var _a;
|
|
17
16
|
const errors = super.validate(value);
|
|
18
17
|
if (value && errors.length === 0 && !value.base64) {
|
|
19
18
|
let sizes = this.getRequiredSizes();
|
|
@@ -29,15 +28,14 @@ class ImageField extends AbstractField_1.default {
|
|
|
29
28
|
errors.push({
|
|
30
29
|
code: 'INVALID_PARAMETER',
|
|
31
30
|
name: this.name,
|
|
32
|
-
friendlyMessage: `You need to supply the remaining sizes to upload an image to ${
|
|
31
|
+
friendlyMessage: `You need to supply the remaining sizes to upload an image to ${this.label ?? this.name}: '${missing.join("', '")}'`,
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
return errors;
|
|
37
36
|
}
|
|
38
37
|
getRequiredSizes() {
|
|
39
|
-
|
|
40
|
-
let sizes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.requiredSizes) !== null && _b !== void 0 ? _b : [];
|
|
38
|
+
let sizes = this.definition.options?.requiredSizes ?? [];
|
|
41
39
|
if (sizes[0] === '*') {
|
|
42
40
|
sizes = ImageField_types_1.requiredImageSizes.filter((s) => s !== '*');
|
|
43
41
|
}
|
|
@@ -111,7 +111,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
111
111
|
throw new SpruceError_1.default({
|
|
112
112
|
code: 'SCHEMA_NOT_FOUND',
|
|
113
113
|
schemaId: id,
|
|
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
|
|
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 ?? '**missing**'}'.`,
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
});
|
|
@@ -153,7 +153,6 @@ class SchemaField extends AbstractField_1.default {
|
|
|
153
153
|
return schemas;
|
|
154
154
|
}
|
|
155
155
|
validate(value, options) {
|
|
156
|
-
var _a;
|
|
157
156
|
const errors = super.validate(value, options);
|
|
158
157
|
// do not validate schemas by default, very heavy and only needed when explicitly asked to
|
|
159
158
|
if (value instanceof AbstractEntity_1.default) {
|
|
@@ -175,7 +174,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
175
174
|
errors.push({
|
|
176
175
|
code: 'INVALID_PARAMETER',
|
|
177
176
|
name: this.name,
|
|
178
|
-
friendlyMessage: `${
|
|
177
|
+
friendlyMessage: `${this.label ?? this.name} must be an object!`,
|
|
179
178
|
});
|
|
180
179
|
}
|
|
181
180
|
else {
|
|
@@ -34,10 +34,9 @@ class TextField extends AbstractField_1.default {
|
|
|
34
34
|
return errors;
|
|
35
35
|
}
|
|
36
36
|
toValueType(value, options) {
|
|
37
|
-
var _a;
|
|
38
37
|
let transformed = this.convertToString(value);
|
|
39
38
|
if (typeof transformed === 'string') {
|
|
40
|
-
const maxLength =
|
|
39
|
+
const maxLength = options?.maxLength ?? 0;
|
|
41
40
|
if (maxLength > 0 && transformed.length > maxLength) {
|
|
42
41
|
transformed = transformed.substr(0, maxLength);
|
|
43
42
|
}
|
|
@@ -84,9 +84,8 @@ class SchemaRegistry {
|
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
86
86
|
forgetSchema(id, version) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (((_b = this.schemasById[id]) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
87
|
+
this.schemasById[id] = this.schemasById[id]?.filter((schema) => !(schema.id === id && schema.version === version));
|
|
88
|
+
if (this.schemasById[id]?.length === 0) {
|
|
90
89
|
delete this.schemasById[id];
|
|
91
90
|
}
|
|
92
91
|
}
|
|
@@ -24,7 +24,6 @@ function flattenFields(fieldErrors, flattened, namePrefix = '') {
|
|
|
24
24
|
}
|
|
25
25
|
const validationErrorAssert = {
|
|
26
26
|
assertError(error, options) {
|
|
27
|
-
var _a, _b;
|
|
28
27
|
const missing = [];
|
|
29
28
|
const err = error;
|
|
30
29
|
if (!err) {
|
|
@@ -39,7 +38,7 @@ const validationErrorAssert = {
|
|
|
39
38
|
parameters: missing,
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
|
-
if (
|
|
41
|
+
if (err.options?.code !== 'VALIDATION_FAILED') {
|
|
43
42
|
throw new SpruceError_1.default({
|
|
44
43
|
code: 'INVALID_PARAMETERS',
|
|
45
44
|
parameters: ['error'],
|
|
@@ -62,7 +61,7 @@ const validationErrorAssert = {
|
|
|
62
61
|
for (let idx = 0; idx < keys.length; idx++) {
|
|
63
62
|
const code = codes[idx];
|
|
64
63
|
const key = keys[idx];
|
|
65
|
-
for (const lookup of
|
|
64
|
+
for (const lookup of options?.[key] ?? []) {
|
|
66
65
|
const match = flattened[lookup] === code;
|
|
67
66
|
if (!match) {
|
|
68
67
|
test_utils_1.assert.fail(buildFailMessage(code, lookup, flattened));
|
|
@@ -9,12 +9,10 @@ class KeyMapper {
|
|
|
9
9
|
this.map = map;
|
|
10
10
|
}
|
|
11
11
|
mapTo(values, options) {
|
|
12
|
-
|
|
13
|
-
return this._mapTo(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
|
|
12
|
+
return this._mapTo(values, this.map, options?.shouldThrowOnUnmapped ?? true);
|
|
14
13
|
}
|
|
15
14
|
mapFrom(values, options) {
|
|
16
|
-
|
|
17
|
-
return this._mapFrom(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
|
|
15
|
+
return this._mapFrom(values, this.map, options?.shouldThrowOnUnmapped ?? true);
|
|
18
16
|
}
|
|
19
17
|
mapFieldNameTo(name) {
|
|
20
18
|
if (!this.map[name]) {
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = areSchemasTheSame;
|
|
4
4
|
function areSchemasTheSame(left, right) {
|
|
5
|
-
var _a, _b;
|
|
6
5
|
if (left.id !== right.id) {
|
|
7
6
|
return false;
|
|
8
7
|
}
|
|
9
|
-
const fields1 = Object.keys(
|
|
10
|
-
const fields2 = Object.keys(
|
|
8
|
+
const fields1 = Object.keys(left.fields ?? {}).sort();
|
|
9
|
+
const fields2 = Object.keys(right.fields ?? {}).sort();
|
|
11
10
|
if (fields1.join('|') !== fields2.join('|')) {
|
|
12
11
|
return false;
|
|
13
12
|
}
|
|
@@ -9,7 +9,7 @@ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
|
9
9
|
function assertOptions(options, toCheck, friendlyMessage) {
|
|
10
10
|
const missing = [];
|
|
11
11
|
for (const check of toCheck) {
|
|
12
|
-
const value = (0, just_safe_get_1.default)(options
|
|
12
|
+
const value = (0, just_safe_get_1.default)(options ?? {}, check);
|
|
13
13
|
//@ts-ignore
|
|
14
14
|
if (value === null || typeof value === 'undefined') {
|
|
15
15
|
missing.push(check);
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = cloneDeep;
|
|
4
4
|
function cloneDeep(obj, transformer) {
|
|
5
|
-
var _a;
|
|
6
5
|
const o = obj;
|
|
7
6
|
let result = o;
|
|
8
7
|
let type = {}.toString.call(o).slice(8, -1);
|
|
@@ -12,7 +11,7 @@ function cloneDeep(obj, transformer) {
|
|
|
12
11
|
if (type == 'Map') {
|
|
13
12
|
const items = [];
|
|
14
13
|
[...o.entries()].forEach((kv) => {
|
|
15
|
-
if (
|
|
14
|
+
if (transformer?.(kv[1], kv[0]) !== false) {
|
|
16
15
|
items.push([cloneDeep(kv[0]), cloneDeep(kv[1])]);
|
|
17
16
|
}
|
|
18
17
|
});
|
|
@@ -28,7 +27,7 @@ function cloneDeep(obj, transformer) {
|
|
|
28
27
|
result = Array.isArray(o) ? [] : {};
|
|
29
28
|
for (let key in o) {
|
|
30
29
|
result[key] =
|
|
31
|
-
|
|
30
|
+
transformer?.(o[key], key) ?? cloneDeep(o[key], transformer);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
// primitives and non-supported objects (e.g. functions) land here
|
|
@@ -7,8 +7,7 @@ exports.default = cloneDeepPreservingInstances;
|
|
|
7
7
|
const cloneDeep_1 = __importDefault(require("./cloneDeep"));
|
|
8
8
|
function cloneDeepPreservingInstances(v) {
|
|
9
9
|
return (0, cloneDeep_1.default)(v, (value) => {
|
|
10
|
-
|
|
11
|
-
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
|
+
const name = value?.__proto__?.constructor?.name;
|
|
12
11
|
if (name && name !== 'Object') {
|
|
13
12
|
return value;
|
|
14
13
|
}
|
|
@@ -30,10 +30,9 @@ function formatNumberWithCode(phoneNumberString, code = '1') {
|
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
function isValidNumber(number) {
|
|
33
|
-
var _a;
|
|
34
33
|
const { code } = stripCode(number);
|
|
35
|
-
const formatted =
|
|
36
|
-
return
|
|
34
|
+
const formatted = formatNumberWithCode(number, code)?.replace(/[^0-9]/g, '');
|
|
35
|
+
return formatted?.length === 11 || formatted?.length === 12;
|
|
37
36
|
}
|
|
38
37
|
function stripCode(number) {
|
|
39
38
|
let code = `1`; // Default to North American country code
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = getFields;
|
|
7
7
|
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
8
8
|
function getFields(schema) {
|
|
9
|
-
|
|
10
|
-
const names = Object.keys((_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : {});
|
|
9
|
+
const names = Object.keys(schema?.fields ?? {});
|
|
11
10
|
if (names.length === 0) {
|
|
12
11
|
throw new SpruceError_1.default({
|
|
13
12
|
code: 'INVALID_PARAMETERS',
|
|
@@ -7,7 +7,6 @@ exports.default = normalizeFieldValue;
|
|
|
7
7
|
exports.normalizeValueToArray = normalizeValueToArray;
|
|
8
8
|
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
9
9
|
function normalizeFieldValue(schemaId, schemaName, schemasById, field, value, options) {
|
|
10
|
-
var _a, _b;
|
|
11
10
|
let localValue = normalizeValueToArray(value);
|
|
12
11
|
if (!Array.isArray(localValue)) {
|
|
13
12
|
throw new SpruceError_1.default({
|
|
@@ -16,11 +15,11 @@ function normalizeFieldValue(schemaId, schemaName, schemasById, field, value, op
|
|
|
16
15
|
friendlyMessages: [`I was expecting an array for ${field.name}.`],
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
|
-
const { shouldCreateEntityInstances: createEntityInstances = true, ...extraOptions } = options
|
|
20
|
-
const validate =
|
|
18
|
+
const { shouldCreateEntityInstances: createEntityInstances = true, ...extraOptions } = options ?? {};
|
|
19
|
+
const validate = extraOptions.shouldValidate ?? true;
|
|
21
20
|
const baseOptions = {
|
|
22
21
|
schemasById,
|
|
23
|
-
...(
|
|
22
|
+
...(field.definition.options ?? {}),
|
|
24
23
|
...extraOptions,
|
|
25
24
|
};
|
|
26
25
|
if (value === null || typeof value === 'undefined') {
|
|
@@ -13,9 +13,8 @@ function selectChoicesToHash(options) {
|
|
|
13
13
|
}
|
|
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;
|
|
17
16
|
// @ts-ignore
|
|
18
17
|
return selectChoicesToHash(
|
|
19
18
|
// @ts-ignore
|
|
20
|
-
|
|
19
|
+
definition.fields?.[fieldName]?.options?.choices ?? []);
|
|
21
20
|
}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = validateSchema;
|
|
7
7
|
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
8
8
|
function validateSchema(schema) {
|
|
9
|
-
var _a;
|
|
10
9
|
const errors = [];
|
|
11
10
|
if (!schema) {
|
|
12
11
|
errors.push('definition_empty');
|
|
@@ -28,7 +27,7 @@ function validateSchema(schema) {
|
|
|
28
27
|
if (errors.length > 0) {
|
|
29
28
|
throw new SpruceError_1.default({
|
|
30
29
|
code: 'INVALID_SCHEMA',
|
|
31
|
-
schemaId:
|
|
30
|
+
schemaId: schema?.id ?? 'ID MISSING',
|
|
32
31
|
errors,
|
|
33
32
|
});
|
|
34
33
|
}
|
|
@@ -8,7 +8,7 @@ const just_safe_set_1 = __importDefault(require("just-safe-set"));
|
|
|
8
8
|
const __1 = require("..");
|
|
9
9
|
const SchemaEntityFactory_1 = __importDefault(require("../factories/SchemaEntityFactory"));
|
|
10
10
|
function validateSchemaValues(schema, values, options) {
|
|
11
|
-
const { ...opts } = options
|
|
11
|
+
const { ...opts } = options ?? {};
|
|
12
12
|
(0, __1.validateSchema)(schema);
|
|
13
13
|
const mapped = Object.keys(values).reduce((mapped, key) => {
|
|
14
14
|
//@ts-ignore
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"!build/__tests__",
|
|
9
9
|
"esm"
|
|
10
10
|
],
|
|
11
|
-
"version": "30.0.
|
|
11
|
+
"version": "30.0.488",
|
|
12
12
|
"main": "./build/index.js",
|
|
13
13
|
"types": "./build/index.d.ts",
|
|
14
14
|
"module": "./build/esm/index.js",
|
|
@@ -58,18 +58,18 @@
|
|
|
58
58
|
"build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@sprucelabs/error": "^6.0.
|
|
62
|
-
"@sprucelabs/test-utils": "^5.1.
|
|
61
|
+
"@sprucelabs/error": "^6.0.479",
|
|
62
|
+
"@sprucelabs/test-utils": "^5.1.432",
|
|
63
63
|
"email-validator": "^2.0.4",
|
|
64
64
|
"just-safe-get": "^4.2.0",
|
|
65
65
|
"just-safe-set": "^4.2.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@sprucelabs/esm-postbuild": "^6.0.
|
|
69
|
-
"@sprucelabs/jest-json-reporter": "^8.0.
|
|
70
|
-
"@sprucelabs/resolve-path-aliases": "^2.0.
|
|
68
|
+
"@sprucelabs/esm-postbuild": "^6.0.461",
|
|
69
|
+
"@sprucelabs/jest-json-reporter": "^8.0.478",
|
|
70
|
+
"@sprucelabs/resolve-path-aliases": "^2.0.456",
|
|
71
71
|
"@sprucelabs/semantic-release": "^5.0.2",
|
|
72
|
-
"@sprucelabs/test": "^9.0.
|
|
72
|
+
"@sprucelabs/test": "^9.0.51",
|
|
73
73
|
"chokidar-cli": "^3.0.0",
|
|
74
74
|
"eslint": "^9.12.0",
|
|
75
75
|
"eslint-config-spruce": "^11.2.26",
|