@sprucelabs/schema 29.2.2 → 29.2.4
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/{StaticSchemaEntityImplementation.d.ts → StaticSchemaEntityImpl.d.ts} +1 -1
- package/build/{StaticSchemaEntityImplementation.js → StaticSchemaEntityImpl.js} +3 -3
- package/build/esm/{StaticSchemaEntityImplementation.d.ts → StaticSchemaEntityImpl.d.ts} +1 -1
- package/build/esm/{StaticSchemaEntityImplementation.js → StaticSchemaEntityImpl.js} +3 -3
- package/build/esm/factories/SchemaEntityFactory.d.ts +1 -1
- package/build/esm/factories/SchemaEntityFactory.js +1 -1
- package/build/esm/fields/DateTimeField.js +4 -1
- package/build/esm/fields/SchemaField.js +1 -1
- package/build/esm/index.d.ts +3 -3
- package/build/esm/index.js +3 -3
- package/build/esm/tests/AbstractDateFieldTest.d.ts +2 -2
- package/build/esm/utilities/defaultSchemaValues.js +2 -2
- package/build/factories/SchemaEntityFactory.d.ts +1 -1
- package/build/factories/SchemaEntityFactory.js +2 -2
- package/build/fields/DateTimeField.js +4 -1
- package/build/fields/SchemaField.js +2 -2
- package/build/index.d.ts +3 -3
- package/build/index.js +3 -3
- package/build/tests/AbstractDateFieldTest.d.ts +2 -2
- package/build/utilities/defaultSchemaValues.js +2 -2
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import AbstractEntity from './AbstractEntity';
|
|
2
2
|
import { Schema, StaticSchemaPartialValues, SchemaFieldNames, SchemaNormalizeOptions, SchemaFieldValueType, SchemaValidateOptions, SchemaDefaultValues, SchemaGetValuesOptions, SchemaAllValues, SchemaNamedFieldsOptions, SchemaNamedField, SchemaGetDefaultValuesOptions, SchemaFieldNamesWithDefaultValue, StaticSchemaEntity, SchemaPublicValues, SchemaPublicFieldNames } from './schemas.static.types';
|
|
3
|
-
export default class
|
|
3
|
+
export default class StaticSchemaEntityImpl<S extends Schema> extends AbstractEntity implements StaticSchemaEntity<S> {
|
|
4
4
|
static enableDuplicateCheckWhenTracking: boolean;
|
|
5
5
|
protected schema: S;
|
|
6
6
|
private values;
|
|
@@ -31,7 +31,7 @@ const SpruceError_1 = __importDefault(require("./errors/SpruceError"));
|
|
|
31
31
|
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
|
-
class
|
|
34
|
+
class StaticSchemaEntityImpl extends AbstractEntity_1.default {
|
|
35
35
|
constructor(schema, values) {
|
|
36
36
|
super(schema);
|
|
37
37
|
this.values = {};
|
|
@@ -195,5 +195,5 @@ class StaticSchemaEntityImplementation extends AbstractEntity_1.default {
|
|
|
195
195
|
return namedFields;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
|
|
199
|
-
exports.default =
|
|
198
|
+
StaticSchemaEntityImpl.enableDuplicateCheckWhenTracking = true;
|
|
199
|
+
exports.default = StaticSchemaEntityImpl;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import AbstractEntity from './AbstractEntity';
|
|
2
2
|
import { Schema, StaticSchemaPartialValues, SchemaFieldNames, SchemaNormalizeOptions, SchemaFieldValueType, SchemaValidateOptions, SchemaDefaultValues, SchemaGetValuesOptions, SchemaAllValues, SchemaNamedFieldsOptions, SchemaNamedField, SchemaGetDefaultValuesOptions, SchemaFieldNamesWithDefaultValue, StaticSchemaEntity, SchemaPublicValues, SchemaPublicFieldNames } from './schemas.static.types';
|
|
3
|
-
export default class
|
|
3
|
+
export default class StaticSchemaEntityImpl<S extends Schema> extends AbstractEntity implements StaticSchemaEntity<S> {
|
|
4
4
|
static enableDuplicateCheckWhenTracking: boolean;
|
|
5
5
|
protected schema: S;
|
|
6
6
|
private values;
|
|
@@ -3,7 +3,7 @@ import SpruceError from './errors/SpruceError.js';
|
|
|
3
3
|
import FieldFactory from './factories/FieldFactory.js';
|
|
4
4
|
import cloneDeepPreservingInstances from './utilities/cloneDeepPreservingInstances.js';
|
|
5
5
|
import normalizeFieldValue, { normalizeValueToArray, } from './utilities/normalizeFieldValue.js';
|
|
6
|
-
class
|
|
6
|
+
class StaticSchemaEntityImpl extends AbstractEntity {
|
|
7
7
|
constructor(schema, values) {
|
|
8
8
|
super(schema);
|
|
9
9
|
this.values = {};
|
|
@@ -167,5 +167,5 @@ class StaticSchemaEntityImplementation extends AbstractEntity {
|
|
|
167
167
|
return namedFields;
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
export default
|
|
170
|
+
StaticSchemaEntityImpl.enableDuplicateCheckWhenTracking = true;
|
|
171
|
+
export default StaticSchemaEntityImpl;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DynamicSchemaEntityImplementation from '../DynamicSchemaEntityImplementation';
|
|
2
2
|
import { Schema, IsDynamicSchema, SchemaPartialValues } from '../schemas.static.types';
|
|
3
|
-
import StaticSchemaEntity from '../
|
|
3
|
+
import StaticSchemaEntity from '../StaticSchemaEntityImpl';
|
|
4
4
|
export default class SchemaEntityFactory {
|
|
5
5
|
static Entity<S extends Schema, IsDynamic extends boolean = IsDynamicSchema<S>>(schema: S, values?: SchemaPartialValues<S>): IsDynamic extends true ? DynamicSchemaEntityImplementation<S> : StaticSchemaEntity<S>;
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DynamicSchemaEntityImplementation from '../DynamicSchemaEntityImplementation.js';
|
|
2
|
-
import StaticSchemaEntity from '../
|
|
2
|
+
import StaticSchemaEntity from '../StaticSchemaEntityImpl.js';
|
|
3
3
|
export default class SchemaEntityFactory {
|
|
4
4
|
static Entity(schema, values) {
|
|
5
5
|
const instance = schema.dynamicFieldSignature
|
|
@@ -29,6 +29,9 @@ export default class DateTimeField extends AbstractField {
|
|
|
29
29
|
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.dateTimeFormat) === 'iso_8601') {
|
|
30
30
|
return new Date(value).toISOString();
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
if (typeof normalized === 'string') {
|
|
33
|
+
normalized = new Date(normalized).getTime();
|
|
34
|
+
}
|
|
35
|
+
return normalized ? +normalized : normalized;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -2,7 +2,7 @@ import AbstractEntity from '../AbstractEntity.js';
|
|
|
2
2
|
import DynamicSchemaEntityImplementation from '../DynamicSchemaEntityImplementation.js';
|
|
3
3
|
import SpruceError from '../errors/SpruceError.js';
|
|
4
4
|
import SchemaRegistry from '../singletons/SchemaRegistry.js';
|
|
5
|
-
import StaticSchemaEntity from '../
|
|
5
|
+
import StaticSchemaEntity from '../StaticSchemaEntityImpl.js';
|
|
6
6
|
import { TemplateRenderAs, } from '../types/template.types.js';
|
|
7
7
|
import isIdWithVersion from '../utilities/isIdWithVersion.js';
|
|
8
8
|
import normalizeSchemaToIdWithVersion from '../utilities/normalizeSchemaToIdWithVersion.js';
|
package/build/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
import
|
|
1
|
+
export * from './StaticSchemaEntityImpl';
|
|
2
|
+
import StaticSchemaEntityImpl from './StaticSchemaEntityImpl';
|
|
3
3
|
import { FieldRegistration } from './utilities/registerFieldType';
|
|
4
|
-
export default
|
|
4
|
+
export default StaticSchemaEntityImpl;
|
|
5
5
|
export { default as validationErrorAssert } from './tests/validationErrorAssert.utility';
|
|
6
6
|
export { default as selectAssert } from './tests/selectAssert.utility';
|
|
7
7
|
export { default as cloneDeep } from './utilities/cloneDeep';
|
package/build/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './StaticSchemaEntityImpl.js';
|
|
2
2
|
import addressRegistration from './addons/addressField.addon.js';
|
|
3
3
|
import booleanRegistration from './addons/booleanField.addon.js';
|
|
4
4
|
import dateRegistration from './addons/dateField.addon.js';
|
|
@@ -15,8 +15,8 @@ import rawRegistration from './addons/rawField.addon.js';
|
|
|
15
15
|
import schemaRegistration from './addons/schemaField.addon.js';
|
|
16
16
|
import selectRegistration from './addons/selectField.addon.js';
|
|
17
17
|
import textRegistration from './addons/textField.addon.js';
|
|
18
|
-
import
|
|
19
|
-
export default
|
|
18
|
+
import StaticSchemaEntityImpl from './StaticSchemaEntityImpl.js';
|
|
19
|
+
export default StaticSchemaEntityImpl;
|
|
20
20
|
export { default as validationErrorAssert } from './tests/validationErrorAssert.utility.js';
|
|
21
21
|
export { default as selectAssert } from './tests/selectAssert.utility.js';
|
|
22
22
|
export { default as cloneDeep } from './utilities/cloneDeep.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import StaticSchemaEntityImpl from '..';
|
|
2
2
|
import AbstractSchemaTest from '../AbstractSchemaTest';
|
|
3
3
|
export default abstract class AbstractDateFieldTest extends AbstractSchemaTest {
|
|
4
4
|
protected static schema: any;
|
|
5
|
-
protected static entity:
|
|
5
|
+
protected static entity: StaticSchemaEntityImpl<any>;
|
|
6
6
|
protected static beforeEach(): Promise<void>;
|
|
7
7
|
protected static canSetDateAsDateObject(): void;
|
|
8
8
|
protected static failsValidationIfPassedString(fieldName: any, value: any): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import StaticSchemaEntityImpl from '../StaticSchemaEntityImpl.js';
|
|
2
2
|
export default function defaultSchemaValues(definition, options = {}) {
|
|
3
|
-
const instance = new
|
|
3
|
+
const instance = new StaticSchemaEntityImpl(definition);
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
return instance.getDefaultValues(Object.assign({ shouldCreateEntityInstances: false }, options));
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DynamicSchemaEntityImplementation from '../DynamicSchemaEntityImplementation';
|
|
2
2
|
import { Schema, IsDynamicSchema, SchemaPartialValues } from '../schemas.static.types';
|
|
3
|
-
import StaticSchemaEntity from '../
|
|
3
|
+
import StaticSchemaEntity from '../StaticSchemaEntityImpl';
|
|
4
4
|
export default class SchemaEntityFactory {
|
|
5
5
|
static Entity<S extends Schema, IsDynamic extends boolean = IsDynamicSchema<S>>(schema: S, values?: SchemaPartialValues<S>): IsDynamic extends true ? DynamicSchemaEntityImplementation<S> : StaticSchemaEntity<S>;
|
|
6
6
|
}
|
|
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const DynamicSchemaEntityImplementation_1 = __importDefault(require("../DynamicSchemaEntityImplementation"));
|
|
7
|
-
const
|
|
7
|
+
const StaticSchemaEntityImpl_1 = __importDefault(require("../StaticSchemaEntityImpl"));
|
|
8
8
|
class SchemaEntityFactory {
|
|
9
9
|
static Entity(schema, values) {
|
|
10
10
|
const instance = schema.dynamicFieldSignature
|
|
11
11
|
? new DynamicSchemaEntityImplementation_1.default(schema, values)
|
|
12
|
-
: new
|
|
12
|
+
: new StaticSchemaEntityImpl_1.default(schema, values);
|
|
13
13
|
return instance;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -34,7 +34,10 @@ class DateTimeField extends AbstractField_1.default {
|
|
|
34
34
|
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.dateTimeFormat) === 'iso_8601') {
|
|
35
35
|
return new Date(value).toISOString();
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
if (typeof normalized === 'string') {
|
|
38
|
+
normalized = new Date(normalized).getTime();
|
|
39
|
+
}
|
|
40
|
+
return normalized ? +normalized : normalized;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
exports.default = DateTimeField;
|
|
@@ -7,7 +7,7 @@ const AbstractEntity_1 = __importDefault(require("../AbstractEntity"));
|
|
|
7
7
|
const DynamicSchemaEntityImplementation_1 = __importDefault(require("../DynamicSchemaEntityImplementation"));
|
|
8
8
|
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
9
9
|
const SchemaRegistry_1 = __importDefault(require("../singletons/SchemaRegistry"));
|
|
10
|
-
const
|
|
10
|
+
const StaticSchemaEntityImpl_1 = __importDefault(require("../StaticSchemaEntityImpl"));
|
|
11
11
|
const template_types_1 = require("../types/template.types");
|
|
12
12
|
const isIdWithVersion_1 = __importDefault(require("../utilities/isIdWithVersion"));
|
|
13
13
|
const normalizeSchemaToIdWithVersion_1 = __importDefault(require("../utilities/normalizeSchemaToIdWithVersion"));
|
|
@@ -256,7 +256,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
256
256
|
Schema(schema, value) {
|
|
257
257
|
return schema.dynamicFieldSignature
|
|
258
258
|
? new DynamicSchemaEntityImplementation_1.default(schema, value)
|
|
259
|
-
: new
|
|
259
|
+
: new StaticSchemaEntityImpl_1.default(schema, value);
|
|
260
260
|
}
|
|
261
261
|
toValueType(value, options) {
|
|
262
262
|
const errors = this.validate(value, options);
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
import
|
|
1
|
+
export * from './StaticSchemaEntityImpl';
|
|
2
|
+
import StaticSchemaEntityImpl from './StaticSchemaEntityImpl';
|
|
3
3
|
import { FieldRegistration } from './utilities/registerFieldType';
|
|
4
|
-
export default
|
|
4
|
+
export default StaticSchemaEntityImpl;
|
|
5
5
|
export { default as validationErrorAssert } from './tests/validationErrorAssert.utility';
|
|
6
6
|
export { default as selectAssert } from './tests/selectAssert.utility';
|
|
7
7
|
export { default as cloneDeep } from './utilities/cloneDeep';
|
package/build/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.mapFieldErrorsToParameterErrors = exports.assertOptions = exports.fieldRegistrations = exports.SchemaRegistry = exports.SchemaEntityFactory = exports.FieldFactory = exports.normalizeSchemaToIdWithVersion = exports.isIdWithVersion = exports.pickFields = exports.getFields = exports.formatPhoneNumber = exports.areSchemasTheSame = exports.isSchemaValid = exports.validateSchema = exports.dropPrivateFields = exports.dropFields = exports.makeFieldsOptional = exports.areSchemaValuesValid = exports.normalizeSchemaValues = exports.validateSchemaValues = exports.defaultSchemaValues = exports.registerFieldType = exports.buildSchema = exports.buildErrorSchema = exports.SchemaError = exports.KeyMapper = exports.selectAssertUtil = exports.cloneDeepPreservingInstances = exports.cloneDeep = exports.selectAssert = exports.validationErrorAssert = void 0;
|
|
21
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./StaticSchemaEntityImpl"), exports);
|
|
22
22
|
const addressField_addon_1 = __importDefault(require("./addons/addressField.addon"));
|
|
23
23
|
const booleanField_addon_1 = __importDefault(require("./addons/booleanField.addon"));
|
|
24
24
|
const dateField_addon_1 = __importDefault(require("./addons/dateField.addon"));
|
|
@@ -35,8 +35,8 @@ const rawField_addon_1 = __importDefault(require("./addons/rawField.addon"));
|
|
|
35
35
|
const schemaField_addon_1 = __importDefault(require("./addons/schemaField.addon"));
|
|
36
36
|
const selectField_addon_1 = __importDefault(require("./addons/selectField.addon"));
|
|
37
37
|
const textField_addon_1 = __importDefault(require("./addons/textField.addon"));
|
|
38
|
-
const
|
|
39
|
-
exports.default =
|
|
38
|
+
const StaticSchemaEntityImpl_1 = __importDefault(require("./StaticSchemaEntityImpl"));
|
|
39
|
+
exports.default = StaticSchemaEntityImpl_1.default;
|
|
40
40
|
var validationErrorAssert_utility_1 = require("./tests/validationErrorAssert.utility");
|
|
41
41
|
Object.defineProperty(exports, "validationErrorAssert", { enumerable: true, get: function () { return __importDefault(validationErrorAssert_utility_1).default; } });
|
|
42
42
|
var selectAssert_utility_1 = require("./tests/selectAssert.utility");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import StaticSchemaEntityImpl from '..';
|
|
2
2
|
import AbstractSchemaTest from '../AbstractSchemaTest';
|
|
3
3
|
export default abstract class AbstractDateFieldTest extends AbstractSchemaTest {
|
|
4
4
|
protected static schema: any;
|
|
5
|
-
protected static entity:
|
|
5
|
+
protected static entity: StaticSchemaEntityImpl<any>;
|
|
6
6
|
protected static beforeEach(): Promise<void>;
|
|
7
7
|
protected static canSetDateAsDateObject(): void;
|
|
8
8
|
protected static failsValidationIfPassedString(fieldName: any, value: any): void;
|
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const StaticSchemaEntityImpl_1 = __importDefault(require("../StaticSchemaEntityImpl"));
|
|
7
7
|
function defaultSchemaValues(definition, options = {}) {
|
|
8
|
-
const instance = new
|
|
8
|
+
const instance = new StaticSchemaEntityImpl_1.default(definition);
|
|
9
9
|
// @ts-ignore
|
|
10
10
|
return instance.getDefaultValues(Object.assign({ shouldCreateEntityInstances: false }, options));
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"!build/__tests__",
|
|
9
9
|
"esm"
|
|
10
10
|
],
|
|
11
|
-
"version": "29.2.
|
|
11
|
+
"version": "29.2.4",
|
|
12
12
|
"main": "./build/index.js",
|
|
13
13
|
"types": "./build/index.d.ts",
|
|
14
14
|
"module": "./build/esm/index.js",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@sprucelabs/error": "^5.1.52",
|
|
70
|
-
"@sprucelabs/test-utils": "^4.0.
|
|
70
|
+
"@sprucelabs/test-utils": "^4.0.86",
|
|
71
71
|
"email-validator": "^2.0.4",
|
|
72
72
|
"just-safe-get": "^4.2.0",
|
|
73
73
|
"just-safe-set": "^4.2.1"
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"jest": "^29.7.0",
|
|
87
87
|
"jest-circus": "^29.7.0",
|
|
88
88
|
"prettier": "^3.1.0",
|
|
89
|
-
"ts-node": "^10.9.
|
|
89
|
+
"ts-node": "^10.9.2",
|
|
90
90
|
"tsc-watch": "^6.0.4",
|
|
91
91
|
"tsconfig-paths": "^4.2.0",
|
|
92
92
|
"typescript": "^5.3.3"
|