@sprucelabs/schema 30.0.574 → 30.0.576

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.
@@ -50,7 +50,7 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
50
50
  this.buildFields();
51
51
  const v = {
52
52
  ...this.values,
53
- ...expandValues(values),
53
+ ...values,
54
54
  };
55
55
  this.values = (0, cloneDeepPreservingInstances_1.default)(v);
56
56
  }
@@ -175,7 +175,7 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
175
175
  }
176
176
  getValues(options) {
177
177
  const values = {};
178
- const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldIncludeNullAndUndefinedFields = true, } = options || {};
178
+ let { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldIncludeNullAndUndefinedFields = true, } = options || {};
179
179
  this.getNamedFields().forEach((namedField) => {
180
180
  const { name, field } = namedField;
181
181
  const shouldSkipBecauseNotSet = !shouldIncludeNullAndUndefinedFields && !(name in this.values);
@@ -190,7 +190,6 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
190
190
  values[name] = value;
191
191
  }
192
192
  });
193
- //@ts-ignore
194
193
  return values;
195
194
  }
196
195
  setValues(values) {
@@ -215,24 +214,3 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
215
214
  }
216
215
  StaticSchemaEntityImpl.enableDuplicateCheckWhenTracking = true;
217
216
  exports.default = StaticSchemaEntityImpl;
218
- function expandValues(values = {}) {
219
- const result = {};
220
- for (const key in values) {
221
- const value = values[key];
222
- const keys = key.split('.');
223
- let current = result;
224
- for (let i = 0; i < keys.length; i++) {
225
- const k = keys[i];
226
- if (i === keys.length - 1) {
227
- current[k] = value;
228
- }
229
- else {
230
- if (!(k in current) || typeof current[k] !== 'object') {
231
- current[k] = {};
232
- }
233
- current = current[k];
234
- }
235
- }
236
- }
237
- return result;
238
- }
@@ -12,7 +12,7 @@ class StaticSchemaEntityImpl extends AbstractEntity {
12
12
  this.buildFields();
13
13
  const v = {
14
14
  ...this.values,
15
- ...expandValues(values),
15
+ ...values,
16
16
  };
17
17
  this.values = cloneDeepPreservingInstances(v);
18
18
  }
@@ -139,7 +139,7 @@ class StaticSchemaEntityImpl extends AbstractEntity {
139
139
  }
140
140
  getValues(options) {
141
141
  const values = {};
142
- const { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldIncludeNullAndUndefinedFields = true, } = options || {};
142
+ let { fields = Object.keys(this.fields), shouldIncludePrivateFields: includePrivateFields = true, shouldIncludeNullAndUndefinedFields = true, } = options || {};
143
143
  this.getNamedFields().forEach((namedField) => {
144
144
  const { name, field } = namedField;
145
145
  const shouldSkipBecauseNotSet = !shouldIncludeNullAndUndefinedFields && !(name in this.values);
@@ -154,7 +154,6 @@ class StaticSchemaEntityImpl extends AbstractEntity {
154
154
  values[name] = value;
155
155
  }
156
156
  });
157
- //@ts-ignore
158
157
  return values;
159
158
  }
160
159
  setValues(values) {
@@ -179,24 +178,3 @@ class StaticSchemaEntityImpl extends AbstractEntity {
179
178
  }
180
179
  StaticSchemaEntityImpl.enableDuplicateCheckWhenTracking = true;
181
180
  export default StaticSchemaEntityImpl;
182
- function expandValues(values = {}) {
183
- const result = {};
184
- for (const key in values) {
185
- const value = values[key];
186
- const keys = key.split('.');
187
- let current = result;
188
- for (let i = 0; i < keys.length; i++) {
189
- const k = keys[i];
190
- if (i === keys.length - 1) {
191
- current[k] = value;
192
- }
193
- else {
194
- if (!(k in current) || typeof current[k] !== 'object') {
195
- current[k] = {};
196
- }
197
- current = current[k];
198
- }
199
- }
200
- }
201
- return result;
202
- }
@@ -1,19 +1,52 @@
1
1
  import get from 'just-safe-get';
2
2
  import EntityFactory from '../factories/SchemaEntityFactory.js';
3
3
  export default function normalizeSchemaValues(schema, values, options) {
4
- const instance = EntityFactory.Entity(schema, values);
5
- const { shouldCreateEntityInstances = false, shouldRetainDotSyntaxKeys, ...rest } = options || {};
4
+ const instance = EntityFactory.Entity(schema, expandValues(values));
5
+ const { shouldCreateEntityInstances = false, fields, shouldRetainDotSyntaxKeys, ...rest } = options || {};
6
+ let areAnyKeysDotted = false;
7
+ let normalizedFields = fields === null || fields === void 0 ? void 0 : fields.map((f) => {
8
+ const hasDotKey = f.includes('.');
9
+ areAnyKeysDotted = areAnyKeysDotted || hasDotKey;
10
+ return hasDotKey ? f.split('.')[0] : f;
11
+ });
6
12
  const normalizedOptions = {
7
13
  shouldCreateEntityInstances,
14
+ fields: normalizedFields,
8
15
  ...rest,
9
16
  };
10
17
  let normalized = instance.getValues(normalizedOptions);
11
- if (shouldRetainDotSyntaxKeys) {
18
+ const shouldConvertToDotSyntax = areAnyKeysDotted || shouldRetainDotSyntaxKeys;
19
+ if (shouldRetainDotSyntaxKeys || shouldConvertToDotSyntax) {
12
20
  const normalizedWithKeys = {};
13
- for (const key of Object.keys(values)) {
21
+ const keys = fields || Object.keys(values);
22
+ for (const key of keys) {
14
23
  normalizedWithKeys[key] = get(normalized, key);
15
24
  }
16
25
  normalized = normalizedWithKeys;
17
26
  }
27
+ if (!shouldRetainDotSyntaxKeys && shouldConvertToDotSyntax) {
28
+ normalized = expandValues(normalized);
29
+ }
18
30
  return normalized;
19
31
  }
32
+ function expandValues(values = {}) {
33
+ const result = {};
34
+ for (const key in values) {
35
+ const value = values[key];
36
+ const keys = key.split('.');
37
+ let current = result;
38
+ for (let i = 0; i < keys.length; i++) {
39
+ const k = keys[i];
40
+ if (i === keys.length - 1) {
41
+ current[k] = value;
42
+ }
43
+ else {
44
+ if (!(k in current) || typeof current[k] !== 'object') {
45
+ current[k] = {};
46
+ }
47
+ current = current[k];
48
+ }
49
+ }
50
+ }
51
+ return result;
52
+ }
@@ -7,19 +7,52 @@ exports.default = normalizeSchemaValues;
7
7
  const just_safe_get_1 = __importDefault(require("just-safe-get"));
8
8
  const SchemaEntityFactory_1 = __importDefault(require("../factories/SchemaEntityFactory"));
9
9
  function normalizeSchemaValues(schema, values, options) {
10
- const instance = SchemaEntityFactory_1.default.Entity(schema, values);
11
- const { shouldCreateEntityInstances = false, shouldRetainDotSyntaxKeys, ...rest } = options || {};
10
+ const instance = SchemaEntityFactory_1.default.Entity(schema, expandValues(values));
11
+ const { shouldCreateEntityInstances = false, fields, shouldRetainDotSyntaxKeys, ...rest } = options || {};
12
+ let areAnyKeysDotted = false;
13
+ let normalizedFields = fields?.map((f) => {
14
+ const hasDotKey = f.includes('.');
15
+ areAnyKeysDotted = areAnyKeysDotted || hasDotKey;
16
+ return hasDotKey ? f.split('.')[0] : f;
17
+ });
12
18
  const normalizedOptions = {
13
19
  shouldCreateEntityInstances,
20
+ fields: normalizedFields,
14
21
  ...rest,
15
22
  };
16
23
  let normalized = instance.getValues(normalizedOptions);
17
- if (shouldRetainDotSyntaxKeys) {
24
+ const shouldConvertToDotSyntax = areAnyKeysDotted || shouldRetainDotSyntaxKeys;
25
+ if (shouldRetainDotSyntaxKeys || shouldConvertToDotSyntax) {
18
26
  const normalizedWithKeys = {};
19
- for (const key of Object.keys(values)) {
27
+ const keys = fields || Object.keys(values);
28
+ for (const key of keys) {
20
29
  normalizedWithKeys[key] = (0, just_safe_get_1.default)(normalized, key);
21
30
  }
22
31
  normalized = normalizedWithKeys;
23
32
  }
33
+ if (!shouldRetainDotSyntaxKeys && shouldConvertToDotSyntax) {
34
+ normalized = expandValues(normalized);
35
+ }
24
36
  return normalized;
25
37
  }
38
+ function expandValues(values = {}) {
39
+ const result = {};
40
+ for (const key in values) {
41
+ const value = values[key];
42
+ const keys = key.split('.');
43
+ let current = result;
44
+ for (let i = 0; i < keys.length; i++) {
45
+ const k = keys[i];
46
+ if (i === keys.length - 1) {
47
+ current[k] = value;
48
+ }
49
+ else {
50
+ if (!(k in current) || typeof current[k] !== 'object') {
51
+ current[k] = {};
52
+ }
53
+ current = current[k];
54
+ }
55
+ }
56
+ }
57
+ return result;
58
+ }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "30.0.574",
11
+ "version": "30.0.576",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",
@@ -58,24 +58,24 @@
58
58
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/"
59
59
  },
60
60
  "dependencies": {
61
- "@sprucelabs/error": "^6.0.546",
62
- "@sprucelabs/test-utils": "^5.1.513",
61
+ "@sprucelabs/error": "^6.0.548",
62
+ "@sprucelabs/test-utils": "^5.1.514",
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.526",
69
- "@sprucelabs/jest-json-reporter": "^8.0.548",
70
- "@sprucelabs/resolve-path-aliases": "^2.0.517",
68
+ "@sprucelabs/esm-postbuild": "^6.0.527",
69
+ "@sprucelabs/jest-json-reporter": "^8.0.549",
70
+ "@sprucelabs/resolve-path-aliases": "^2.0.518",
71
71
  "@sprucelabs/semantic-release": "^5.0.2",
72
- "@sprucelabs/test": "^9.0.61",
72
+ "@sprucelabs/test": "^9.0.62",
73
73
  "chokidar-cli": "^3.0.0",
74
- "eslint": "^9.15.0",
74
+ "eslint": "^9.16.0",
75
75
  "eslint-config-spruce": "^11.2.26",
76
76
  "jest": "^29.7.0",
77
77
  "jest-circus": "^29.7.0",
78
- "prettier": "^3.4.0",
78
+ "prettier": "^3.4.1",
79
79
  "ts-node": "^10.9.2",
80
80
  "tsc-watch": "^6.2.1",
81
81
  "tsconfig-paths": "^4.2.0",