@sprucelabs/schema 30.0.594 → 30.1.1

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.
@@ -33,6 +33,8 @@ export { default as getFields } from './utilities/getFields';
33
33
  export { default as pickFields } from './utilities/pickFields';
34
34
  export { default as isIdWithVersion } from './utilities/isIdWithVersion';
35
35
  export { default as normalizeSchemaToIdWithVersion } from './utilities/normalizeSchemaToIdWithVersion';
36
+ export { default as flattenValues } from './utilities/flattenValues';
37
+ export { default as expandValues } from './utilities/expandValues';
36
38
  export * from './utilities/formatPhoneNumber';
37
39
  export { default as FieldFactory } from './factories/FieldFactory';
38
40
  export { default as SchemaEntityFactory } from './factories/SchemaEntityFactory';
@@ -48,6 +48,8 @@ export { default as getFields } from './utilities/getFields.js';
48
48
  export { default as pickFields } from './utilities/pickFields.js';
49
49
  export { default as isIdWithVersion } from './utilities/isIdWithVersion.js';
50
50
  export { default as normalizeSchemaToIdWithVersion } from './utilities/normalizeSchemaToIdWithVersion.js';
51
+ export { default as flattenValues } from './utilities/flattenValues.js';
52
+ export { default as expandValues } from './utilities/expandValues.js';
51
53
  export * from './utilities/formatPhoneNumber.js';
52
54
  export { default as FieldFactory } from './factories/FieldFactory.js';
53
55
  export { default as SchemaEntityFactory } from './factories/SchemaEntityFactory.js';
@@ -0,0 +1 @@
1
+ export default function expandValues(values?: Record<string, any>): Record<string, any>;
@@ -0,0 +1,21 @@
1
+ export default function expandValues(values = {}) {
2
+ const result = {};
3
+ for (const key in values) {
4
+ const value = values[key];
5
+ const keys = key.split('.');
6
+ let current = result;
7
+ for (let i = 0; i < keys.length; i++) {
8
+ const k = keys[i];
9
+ if (i === keys.length - 1) {
10
+ current[k] = value;
11
+ }
12
+ else {
13
+ if (!(k in current) || typeof current[k] !== 'object') {
14
+ current[k] = {};
15
+ }
16
+ current = current[k];
17
+ }
18
+ }
19
+ }
20
+ return result;
21
+ }
@@ -0,0 +1 @@
1
+ export default function flattenValues(values: Record<string, any>): Record<string, any>;
@@ -0,0 +1,19 @@
1
+ export default function flattenValues(values) {
2
+ const flattened = flattenValue(values);
3
+ return flattened;
4
+ }
5
+ function flattenValue(values, prefix = '') {
6
+ const keys = Object.keys(values);
7
+ let flattened = {};
8
+ for (const key of keys) {
9
+ const value = values[key];
10
+ const dotKey = prefix ? `${prefix}.${key}` : key;
11
+ if (value && typeof value === 'object') {
12
+ flattened = { ...flattened, ...flattenValue(value, dotKey) };
13
+ }
14
+ else {
15
+ flattened[dotKey] = value;
16
+ }
17
+ }
18
+ return flattened;
19
+ }
@@ -1,5 +1,6 @@
1
1
  import get from 'just-safe-get';
2
2
  import EntityFactory from '../factories/SchemaEntityFactory.js';
3
+ import expandValues from './expandValues.js';
3
4
  export default function normalizeSchemaValues(schema, values, options) {
4
5
  const instance = EntityFactory.Entity(schema, expandValues(values));
5
6
  const { shouldCreateEntityInstances = false, fields, shouldRetainDotNotationKeys, ...rest } = options || {};
@@ -29,24 +30,3 @@ export default function normalizeSchemaValues(schema, values, options) {
29
30
  }
30
31
  return normalized;
31
32
  }
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
- }
package/build/index.d.ts CHANGED
@@ -33,6 +33,8 @@ export { default as getFields } from './utilities/getFields';
33
33
  export { default as pickFields } from './utilities/pickFields';
34
34
  export { default as isIdWithVersion } from './utilities/isIdWithVersion';
35
35
  export { default as normalizeSchemaToIdWithVersion } from './utilities/normalizeSchemaToIdWithVersion';
36
+ export { default as flattenValues } from './utilities/flattenValues';
37
+ export { default as expandValues } from './utilities/expandValues';
36
38
  export * from './utilities/formatPhoneNumber';
37
39
  export { default as FieldFactory } from './factories/FieldFactory';
38
40
  export { default as SchemaEntityFactory } from './factories/SchemaEntityFactory';
package/build/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
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;
20
+ exports.mapFieldErrorsToParameterErrors = exports.assertOptions = exports.fieldRegistrations = exports.SchemaRegistry = exports.SchemaEntityFactory = exports.FieldFactory = exports.expandValues = exports.flattenValues = 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
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"));
@@ -93,6 +93,10 @@ var isIdWithVersion_1 = require("./utilities/isIdWithVersion");
93
93
  Object.defineProperty(exports, "isIdWithVersion", { enumerable: true, get: function () { return __importDefault(isIdWithVersion_1).default; } });
94
94
  var normalizeSchemaToIdWithVersion_1 = require("./utilities/normalizeSchemaToIdWithVersion");
95
95
  Object.defineProperty(exports, "normalizeSchemaToIdWithVersion", { enumerable: true, get: function () { return __importDefault(normalizeSchemaToIdWithVersion_1).default; } });
96
+ var flattenValues_1 = require("./utilities/flattenValues");
97
+ Object.defineProperty(exports, "flattenValues", { enumerable: true, get: function () { return __importDefault(flattenValues_1).default; } });
98
+ var expandValues_1 = require("./utilities/expandValues");
99
+ Object.defineProperty(exports, "expandValues", { enumerable: true, get: function () { return __importDefault(expandValues_1).default; } });
96
100
  __exportStar(require("./utilities/formatPhoneNumber"), exports);
97
101
  var FieldFactory_1 = require("./factories/FieldFactory");
98
102
  Object.defineProperty(exports, "FieldFactory", { enumerable: true, get: function () { return __importDefault(FieldFactory_1).default; } });
@@ -0,0 +1 @@
1
+ export default function expandValues(values?: Record<string, any>): Record<string, any>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = expandValues;
4
+ function expandValues(values = {}) {
5
+ const result = {};
6
+ for (const key in values) {
7
+ const value = values[key];
8
+ const keys = key.split('.');
9
+ let current = result;
10
+ for (let i = 0; i < keys.length; i++) {
11
+ const k = keys[i];
12
+ if (i === keys.length - 1) {
13
+ current[k] = value;
14
+ }
15
+ else {
16
+ if (!(k in current) || typeof current[k] !== 'object') {
17
+ current[k] = {};
18
+ }
19
+ current = current[k];
20
+ }
21
+ }
22
+ }
23
+ return result;
24
+ }
@@ -0,0 +1 @@
1
+ export default function flattenValues(values: Record<string, any>): Record<string, any>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = flattenValues;
4
+ function flattenValues(values) {
5
+ const flattened = flattenValue(values);
6
+ return flattened;
7
+ }
8
+ function flattenValue(values, prefix = '') {
9
+ const keys = Object.keys(values);
10
+ let flattened = {};
11
+ for (const key of keys) {
12
+ const value = values[key];
13
+ const dotKey = prefix ? `${prefix}.${key}` : key;
14
+ if (value && typeof value === 'object') {
15
+ flattened = { ...flattened, ...flattenValue(value, dotKey) };
16
+ }
17
+ else {
18
+ flattened[dotKey] = value;
19
+ }
20
+ }
21
+ return flattened;
22
+ }
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  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
+ const expandValues_1 = __importDefault(require("./expandValues"));
9
10
  function normalizeSchemaValues(schema, values, options) {
10
- const instance = SchemaEntityFactory_1.default.Entity(schema, expandValues(values));
11
+ const instance = SchemaEntityFactory_1.default.Entity(schema, (0, expandValues_1.default)(values));
11
12
  const { shouldCreateEntityInstances = false, fields, shouldRetainDotNotationKeys, ...rest } = options || {};
12
13
  let areAnyKeysDotted = false;
13
14
  let normalizedFields = fields?.map((f) => {
@@ -31,28 +32,7 @@ function normalizeSchemaValues(schema, values, options) {
31
32
  normalized = normalizedWithKeys;
32
33
  }
33
34
  if (!shouldRetainDotNotationKeys && shouldConvertToDotNotation) {
34
- normalized = expandValues(normalized);
35
+ normalized = (0, expandValues_1.default)(normalized);
35
36
  }
36
37
  return normalized;
37
38
  }
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.594",
11
+ "version": "30.1.1",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",