@sprucelabs/schema 28.7.1 → 28.8.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.
@@ -158,10 +158,13 @@ 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, shouldOnlyIncludeFieldsWithValues, } = options || {};
161
+ const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldIncludeOnlyFieldsWithValues, shouldStripUndefinedAndNullValues = false, } = options || {};
162
162
  this.getNamedFields().forEach((namedField) => {
163
163
  const { name, field } = namedField;
164
- if (shouldOnlyIncludeFieldsWithValues && !(name in this.values)) {
164
+ const shouldSkipBecauseNotSet = shouldIncludeOnlyFieldsWithValues && !(name in this.values);
165
+ const shouldSkipBecauseUndefinedOrNull = shouldStripUndefinedAndNullValues &&
166
+ (this.values[name] === undefined || this.values[name] === null);
167
+ if (shouldSkipBecauseNotSet || shouldSkipBecauseUndefinedOrNull) {
165
168
  return;
166
169
  }
167
170
  if (fields.indexOf(name) > -1 &&
@@ -130,10 +130,13 @@ class StaticSchemaEntityImplementation extends AbstractEntity {
130
130
  }
131
131
  getValues(options) {
132
132
  const values = {};
133
- const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldOnlyIncludeFieldsWithValues, } = options || {};
133
+ const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldIncludeOnlyFieldsWithValues, shouldStripUndefinedAndNullValues = false, } = options || {};
134
134
  this.getNamedFields().forEach((namedField) => {
135
135
  const { name, field } = namedField;
136
- if (shouldOnlyIncludeFieldsWithValues && !(name in this.values)) {
136
+ const shouldSkipBecauseNotSet = shouldIncludeOnlyFieldsWithValues && !(name in this.values);
137
+ const shouldSkipBecauseUndefinedOrNull = shouldStripUndefinedAndNullValues &&
138
+ (this.values[name] === undefined || this.values[name] === null);
139
+ if (shouldSkipBecauseNotSet || shouldSkipBecauseUndefinedOrNull) {
137
140
  return;
138
141
  }
139
142
  if (fields.indexOf(name) > -1 &&
@@ -121,7 +121,8 @@ 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
+ shouldIncludeOnlyFieldsWithValues?: boolean;
125
+ shouldStripUndefinedAndNullValues?: boolean;
125
126
  }
126
127
  export interface DynamicSchemaNormalizeOptions<CreateEntityInstances extends boolean> extends SchemaNormalizeFieldValueOptions<CreateEntityInstances> {
127
128
  }
@@ -1,5 +1,5 @@
1
1
  import normalizeSchemaValues from './normalizeSchemaValues.js';
2
2
  export default function normalizePartialSchemaValues(schema, values, options) {
3
- const normalized = normalizeSchemaValues(schema, values, Object.assign(Object.assign({}, options), { shouldOnlyIncludeFieldsWithValues: true }));
3
+ const normalized = normalizeSchemaValues(schema, values, Object.assign(Object.assign({}, options), { shouldIncludeOnlyFieldsWithValues: true }));
4
4
  return normalized;
5
5
  }
@@ -121,7 +121,8 @@ 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
+ shouldIncludeOnlyFieldsWithValues?: boolean;
125
+ shouldStripUndefinedAndNullValues?: boolean;
125
126
  }
126
127
  export interface DynamicSchemaNormalizeOptions<CreateEntityInstances extends boolean> extends SchemaNormalizeFieldValueOptions<CreateEntityInstances> {
127
128
  }
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const normalizeSchemaValues_1 = __importDefault(require("./normalizeSchemaValues"));
7
7
  function normalizePartialSchemaValues(schema, values, options) {
8
- const normalized = (0, normalizeSchemaValues_1.default)(schema, values, Object.assign(Object.assign({}, options), { shouldOnlyIncludeFieldsWithValues: true }));
8
+ const normalized = (0, normalizeSchemaValues_1.default)(schema, values, Object.assign(Object.assign({}, options), { shouldIncludeOnlyFieldsWithValues: true }));
9
9
  return normalized;
10
10
  }
11
11
  exports.default = normalizePartialSchemaValues;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "28.7.1",
11
+ "version": "28.8.0",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",