@sprucelabs/schema 30.0.189 → 30.0.191
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/esm/fields/SchemaField.js +0 -11
- package/build/esm/schemas.static.types.d.ts +1 -1
- package/build/esm/utilities/normalizeFieldValue.js +4 -3
- package/build/fields/SchemaField.js +0 -11
- package/build/schemas.static.types.d.ts +1 -1
- package/build/utilities/normalizeFieldValue.js +4 -3
- package/package.json +6 -6
|
@@ -259,17 +259,6 @@ class SchemaField extends AbstractField {
|
|
|
259
259
|
return new Class(schema, value);
|
|
260
260
|
}
|
|
261
261
|
toValueType(value, options) {
|
|
262
|
-
const errors = this.validate(value, options);
|
|
263
|
-
if (errors.length > 0) {
|
|
264
|
-
throw new SpruceError({
|
|
265
|
-
code: 'TRANSFORMATION_ERROR',
|
|
266
|
-
fieldType: 'schema',
|
|
267
|
-
incomingTypeof: typeof value,
|
|
268
|
-
incomingValue: value,
|
|
269
|
-
errors,
|
|
270
|
-
name: this.name,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
262
|
const { createEntityInstances, schemasById: schemasById = {} } = options || {};
|
|
274
263
|
// try and pull the schema definition from the options and by id
|
|
275
264
|
const destinationSchemas = SchemaField.mapFieldDefinitionToSchemas(this.definition, {
|
|
@@ -120,7 +120,7 @@ export interface SchemaNormalizeOptions<S extends Schema, CreateEntityInstances
|
|
|
120
120
|
}
|
|
121
121
|
export interface DynamicSchemaNormalizeOptions<CreateEntityInstances extends boolean> extends SchemaNormalizeFieldValueOptions<CreateEntityInstances> {
|
|
122
122
|
}
|
|
123
|
-
export type SchemaGetValuesOptions<T extends Schema, F extends SchemaFieldNames<T>, PF extends SchemaPublicFieldNames<T>, CreateEntityInstances extends boolean, IncludePrivateFields extends boolean, ShouldIncludeNullAndUndefinedFields extends boolean = true> = SchemaNormalizeOptions<T, CreateEntityInstances, ShouldIncludeNullAndUndefinedFields> & (IncludePrivateFields extends false ? {
|
|
123
|
+
export type SchemaGetValuesOptions<T extends Schema, F extends SchemaFieldNames<T> = SchemaFieldNames<T>, PF extends SchemaPublicFieldNames<T> = SchemaPublicFieldNames<T>, CreateEntityInstances extends boolean = false, IncludePrivateFields extends boolean = true, ShouldIncludeNullAndUndefinedFields extends boolean = true> = SchemaNormalizeOptions<T, CreateEntityInstances, ShouldIncludeNullAndUndefinedFields> & (IncludePrivateFields extends false ? {
|
|
124
124
|
shouldIncludePrivateFields: IncludePrivateFields;
|
|
125
125
|
fields?: PF[];
|
|
126
126
|
} : {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import SpruceError from '../errors/SpruceError.js';
|
|
2
2
|
export default function normalizeFieldValue(schemaId, schemaName, schemasById, field, value, options) {
|
|
3
|
-
var _a;
|
|
3
|
+
var _a, _b;
|
|
4
4
|
let localValue = normalizeValueToArray(value);
|
|
5
5
|
if (!Array.isArray(localValue)) {
|
|
6
6
|
throw new SpruceError({
|
|
@@ -9,10 +9,11 @@ export default function normalizeFieldValue(schemaId, schemaName, schemasById, f
|
|
|
9
9
|
friendlyMessages: [`I was expecting an array for ${field.name}.`],
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
const {
|
|
12
|
+
const { shouldCreateEntityInstances: createEntityInstances = true, ...extraOptions } = options !== null && options !== void 0 ? options : {};
|
|
13
|
+
const validate = (_a = extraOptions.shouldValidate) !== null && _a !== void 0 ? _a : true;
|
|
13
14
|
const baseOptions = {
|
|
14
15
|
schemasById,
|
|
15
|
-
...((
|
|
16
|
+
...((_b = field.definition.options) !== null && _b !== void 0 ? _b : {}),
|
|
16
17
|
...extraOptions,
|
|
17
18
|
};
|
|
18
19
|
if (value === null || typeof value === 'undefined') {
|
|
@@ -264,17 +264,6 @@ class SchemaField extends AbstractField_1.default {
|
|
|
264
264
|
return new Class(schema, value);
|
|
265
265
|
}
|
|
266
266
|
toValueType(value, options) {
|
|
267
|
-
const errors = this.validate(value, options);
|
|
268
|
-
if (errors.length > 0) {
|
|
269
|
-
throw new SpruceError_1.default({
|
|
270
|
-
code: 'TRANSFORMATION_ERROR',
|
|
271
|
-
fieldType: 'schema',
|
|
272
|
-
incomingTypeof: typeof value,
|
|
273
|
-
incomingValue: value,
|
|
274
|
-
errors,
|
|
275
|
-
name: this.name,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
267
|
const { createEntityInstances, schemasById: schemasById = {} } = options || {};
|
|
279
268
|
// try and pull the schema definition from the options and by id
|
|
280
269
|
const destinationSchemas = SchemaField.mapFieldDefinitionToSchemas(this.definition, {
|
|
@@ -120,7 +120,7 @@ export interface SchemaNormalizeOptions<S extends Schema, CreateEntityInstances
|
|
|
120
120
|
}
|
|
121
121
|
export interface DynamicSchemaNormalizeOptions<CreateEntityInstances extends boolean> extends SchemaNormalizeFieldValueOptions<CreateEntityInstances> {
|
|
122
122
|
}
|
|
123
|
-
export type SchemaGetValuesOptions<T extends Schema, F extends SchemaFieldNames<T>, PF extends SchemaPublicFieldNames<T>, CreateEntityInstances extends boolean, IncludePrivateFields extends boolean, ShouldIncludeNullAndUndefinedFields extends boolean = true> = SchemaNormalizeOptions<T, CreateEntityInstances, ShouldIncludeNullAndUndefinedFields> & (IncludePrivateFields extends false ? {
|
|
123
|
+
export type SchemaGetValuesOptions<T extends Schema, F extends SchemaFieldNames<T> = SchemaFieldNames<T>, PF extends SchemaPublicFieldNames<T> = SchemaPublicFieldNames<T>, CreateEntityInstances extends boolean = false, IncludePrivateFields extends boolean = true, ShouldIncludeNullAndUndefinedFields extends boolean = true> = SchemaNormalizeOptions<T, CreateEntityInstances, ShouldIncludeNullAndUndefinedFields> & (IncludePrivateFields extends false ? {
|
|
124
124
|
shouldIncludePrivateFields: IncludePrivateFields;
|
|
125
125
|
fields?: PF[];
|
|
126
126
|
} : {
|
|
@@ -7,7 +7,7 @@ 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;
|
|
10
|
+
var _a, _b;
|
|
11
11
|
let localValue = normalizeValueToArray(value);
|
|
12
12
|
if (!Array.isArray(localValue)) {
|
|
13
13
|
throw new SpruceError_1.default({
|
|
@@ -16,10 +16,11 @@ function normalizeFieldValue(schemaId, schemaName, schemasById, field, value, op
|
|
|
16
16
|
friendlyMessages: [`I was expecting an array for ${field.name}.`],
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
const {
|
|
19
|
+
const { shouldCreateEntityInstances: createEntityInstances = true, ...extraOptions } = options !== null && options !== void 0 ? options : {};
|
|
20
|
+
const validate = (_a = extraOptions.shouldValidate) !== null && _a !== void 0 ? _a : true;
|
|
20
21
|
const baseOptions = {
|
|
21
22
|
schemasById,
|
|
22
|
-
...((
|
|
23
|
+
...((_b = field.definition.options) !== null && _b !== void 0 ? _b : {}),
|
|
23
24
|
...extraOptions,
|
|
24
25
|
};
|
|
25
26
|
if (value === null || typeof value === 'undefined') {
|
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.191",
|
|
12
12
|
"main": "./build/index.js",
|
|
13
13
|
"types": "./build/index.d.ts",
|
|
14
14
|
"module": "./build/esm/index.js",
|
|
@@ -58,16 +58,16 @@
|
|
|
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.144",
|
|
62
|
+
"@sprucelabs/test-utils": "^5.1.79",
|
|
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.128",
|
|
69
|
+
"@sprucelabs/jest-json-reporter": "^8.0.146",
|
|
70
|
+
"@sprucelabs/resolve-path-aliases": "^2.0.124",
|
|
71
71
|
"@sprucelabs/semantic-release": "^5.0.2",
|
|
72
72
|
"@sprucelabs/test": "^9.0.38",
|
|
73
73
|
"chokidar-cli": "^3.0.0",
|