@sprucelabs/schema 28.6.48 → 28.7.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.
- package/build/StaticSchemaEntityImplementation.js +4 -1
- package/build/esm/StaticSchemaEntityImplementation.js +4 -1
- package/build/esm/schemas.static.types.d.ts +1 -0
- package/build/esm/utilities/normalizePartialSchemaValues.d.ts +2 -0
- package/build/esm/utilities/normalizePartialSchemaValues.js +5 -0
- package/build/esm/utilities/normalizeSchemaValues.js +2 -2
- package/build/schemas.static.types.d.ts +1 -0
- package/build/utilities/normalizePartialSchemaValues.d.ts +2 -0
- package/build/utilities/normalizePartialSchemaValues.js +11 -0
- package/build/utilities/normalizeSchemaValues.js +2 -2
- package/package.json +2 -2
|
@@ -158,9 +158,12 @@ class StaticSchemaEntityImplementation extends AbstractEntity_1.default {
|
|
|
158
158
|
}
|
|
159
159
|
getValues(options) {
|
|
160
160
|
const values = {};
|
|
161
|
-
const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, } = options || {};
|
|
161
|
+
const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldOnlyIncludeFieldsWithValues, } = options || {};
|
|
162
162
|
this.getNamedFields().forEach((namedField) => {
|
|
163
163
|
const { name, field } = namedField;
|
|
164
|
+
if (shouldOnlyIncludeFieldsWithValues && !(name in this.values)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
164
167
|
if (fields.indexOf(name) > -1 &&
|
|
165
168
|
(includePrivateFields || !field.isPrivate)) {
|
|
166
169
|
const value = this.get(name, options);
|
|
@@ -130,9 +130,12 @@ class StaticSchemaEntityImplementation extends AbstractEntity {
|
|
|
130
130
|
}
|
|
131
131
|
getValues(options) {
|
|
132
132
|
const values = {};
|
|
133
|
-
const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, } = options || {};
|
|
133
|
+
const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldOnlyIncludeFieldsWithValues, } = options || {};
|
|
134
134
|
this.getNamedFields().forEach((namedField) => {
|
|
135
135
|
const { name, field } = namedField;
|
|
136
|
+
if (shouldOnlyIncludeFieldsWithValues && !(name in this.values)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
136
139
|
if (fields.indexOf(name) > -1 &&
|
|
137
140
|
(includePrivateFields || !field.isPrivate)) {
|
|
138
141
|
const value = this.get(name, options);
|
|
@@ -121,6 +121,7 @@ export interface SchemaNormalizeOptions<S extends Schema, CreateEntityInstances
|
|
|
121
121
|
byField?: {
|
|
122
122
|
[K in SchemaFieldNames<S>]?: S['fields'][K] extends FieldDefinition ? Partial<FieldDefinitionMap[S['fields'][K]['type']]['options']> : never;
|
|
123
123
|
};
|
|
124
|
+
shouldOnlyIncludeFieldsWithValues?: boolean;
|
|
124
125
|
}
|
|
125
126
|
export interface DynamicSchemaNormalizeOptions<CreateEntityInstances extends boolean> extends SchemaNormalizeFieldValueOptions<CreateEntityInstances> {
|
|
126
127
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Schema, SchemaPartialValues, SchemaGetValuesOptions, SchemaFieldNames, SchemaPublicFieldNames, SchemaValues } from '../schemas.static.types';
|
|
2
|
+
export default function normalizePartialSchemaValues<S extends Schema, F extends SchemaFieldNames<S> = SchemaFieldNames<S>, PF extends SchemaPublicFieldNames<S> = SchemaPublicFieldNames<S>, CreateEntityInstances extends boolean = false, IncludePrivateFields extends boolean = true, Values extends SchemaPartialValues<S, CreateEntityInstances> = SchemaPartialValues<S, CreateEntityInstances>, Fields extends keyof Values = keyof Values>(schema: S, values: Values, options?: SchemaGetValuesOptions<S, F, PF, CreateEntityInstances, IncludePrivateFields>): Required<Pick<SchemaValues<S, CreateEntityInstances>, Fields>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import normalizeSchemaValues from './normalizeSchemaValues.js';
|
|
2
|
+
export default function normalizePartialSchemaValues(schema, values, options) {
|
|
3
|
+
const normalized = normalizeSchemaValues(schema, values, Object.assign(Object.assign({}, options), { shouldOnlyIncludeFieldsWithValues: true }));
|
|
4
|
+
return normalized;
|
|
5
|
+
}
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import EntityFactory from '../factories/SchemaEntityFactory.js';
|
|
13
13
|
export default function normalizeSchemaValues(schema, values, options) {
|
|
14
14
|
const instance = EntityFactory.Entity(schema, values);
|
|
15
|
-
const _a = options || {}, { shouldCreateEntityInstances
|
|
16
|
-
const normalizedOptions = Object.assign({ shouldCreateEntityInstances
|
|
15
|
+
const _a = options || {}, { shouldCreateEntityInstances = false } = _a, rest = __rest(_a, ["shouldCreateEntityInstances"]);
|
|
16
|
+
const normalizedOptions = Object.assign({ shouldCreateEntityInstances }, rest);
|
|
17
17
|
return instance.getValues(normalizedOptions);
|
|
18
18
|
}
|
|
@@ -121,6 +121,7 @@ export interface SchemaNormalizeOptions<S extends Schema, CreateEntityInstances
|
|
|
121
121
|
byField?: {
|
|
122
122
|
[K in SchemaFieldNames<S>]?: S['fields'][K] extends FieldDefinition ? Partial<FieldDefinitionMap[S['fields'][K]['type']]['options']> : never;
|
|
123
123
|
};
|
|
124
|
+
shouldOnlyIncludeFieldsWithValues?: boolean;
|
|
124
125
|
}
|
|
125
126
|
export interface DynamicSchemaNormalizeOptions<CreateEntityInstances extends boolean> extends SchemaNormalizeFieldValueOptions<CreateEntityInstances> {
|
|
126
127
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Schema, SchemaPartialValues, SchemaGetValuesOptions, SchemaFieldNames, SchemaPublicFieldNames, SchemaValues } from '../schemas.static.types';
|
|
2
|
+
export default function normalizePartialSchemaValues<S extends Schema, F extends SchemaFieldNames<S> = SchemaFieldNames<S>, PF extends SchemaPublicFieldNames<S> = SchemaPublicFieldNames<S>, CreateEntityInstances extends boolean = false, IncludePrivateFields extends boolean = true, Values extends SchemaPartialValues<S, CreateEntityInstances> = SchemaPartialValues<S, CreateEntityInstances>, Fields extends keyof Values = keyof Values>(schema: S, values: Values, options?: SchemaGetValuesOptions<S, F, PF, CreateEntityInstances, IncludePrivateFields>): Required<Pick<SchemaValues<S, CreateEntityInstances>, Fields>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const normalizeSchemaValues_1 = __importDefault(require("./normalizeSchemaValues"));
|
|
7
|
+
function normalizePartialSchemaValues(schema, values, options) {
|
|
8
|
+
const normalized = (0, normalizeSchemaValues_1.default)(schema, values, Object.assign(Object.assign({}, options), { shouldOnlyIncludeFieldsWithValues: true }));
|
|
9
|
+
return normalized;
|
|
10
|
+
}
|
|
11
|
+
exports.default = normalizePartialSchemaValues;
|
|
@@ -17,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const SchemaEntityFactory_1 = __importDefault(require("../factories/SchemaEntityFactory"));
|
|
18
18
|
function normalizeSchemaValues(schema, values, options) {
|
|
19
19
|
const instance = SchemaEntityFactory_1.default.Entity(schema, values);
|
|
20
|
-
const _a = options || {}, { shouldCreateEntityInstances
|
|
21
|
-
const normalizedOptions = Object.assign({ shouldCreateEntityInstances
|
|
20
|
+
const _a = options || {}, { shouldCreateEntityInstances = false } = _a, rest = __rest(_a, ["shouldCreateEntityInstances"]);
|
|
21
|
+
const normalizedOptions = Object.assign({ shouldCreateEntityInstances }, rest);
|
|
22
22
|
return instance.getValues(normalizedOptions);
|
|
23
23
|
}
|
|
24
24
|
exports.default = normalizeSchemaValues;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"!build/__tests__",
|
|
9
9
|
"esm"
|
|
10
10
|
],
|
|
11
|
-
"version": "28.
|
|
11
|
+
"version": "28.7.0",
|
|
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.11",
|
|
70
|
-
"@sprucelabs/test-utils": "^3.4.
|
|
70
|
+
"@sprucelabs/test-utils": "^3.4.75",
|
|
71
71
|
"email-validator": "^2.0.4",
|
|
72
72
|
"just-safe-get": "^4.2.0",
|
|
73
73
|
"just-safe-set": "^4.2.1"
|