@sprucelabs/schema 29.2.3 → 29.3.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.
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export default class KeyMapper {
|
|
2
2
|
private map;
|
|
3
3
|
constructor(map: Record<string, any>);
|
|
4
|
-
mapTo(values: Record<string, any
|
|
5
|
-
mapFrom(values: Record<string, any
|
|
4
|
+
mapTo(values: Record<string, any>, options?: MapOptions): any;
|
|
5
|
+
mapFrom(values: Record<string, any>, options?: MapOptions): any;
|
|
6
6
|
mapFieldNameTo(name: string): any;
|
|
7
7
|
private throwFieldsNotMapped;
|
|
8
8
|
mapFieldNameFrom(name: string): string;
|
|
9
9
|
private _mapTo;
|
|
10
10
|
private _mapFrom;
|
|
11
11
|
}
|
|
12
|
+
export interface MapOptions {
|
|
13
|
+
shouldThrowOnUnmapped: boolean;
|
|
14
|
+
}
|
|
@@ -3,11 +3,13 @@ export default class KeyMapper {
|
|
|
3
3
|
constructor(map) {
|
|
4
4
|
this.map = map;
|
|
5
5
|
}
|
|
6
|
-
mapTo(values) {
|
|
7
|
-
|
|
6
|
+
mapTo(values, options) {
|
|
7
|
+
var _a;
|
|
8
|
+
return this._mapTo(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
|
|
8
9
|
}
|
|
9
|
-
mapFrom(values) {
|
|
10
|
-
|
|
10
|
+
mapFrom(values, options) {
|
|
11
|
+
var _a;
|
|
12
|
+
return this._mapFrom(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
|
|
11
13
|
}
|
|
12
14
|
mapFieldNameTo(name) {
|
|
13
15
|
if (!this.map[name]) {
|
|
@@ -33,7 +35,7 @@ export default class KeyMapper {
|
|
|
33
35
|
this.throwFieldsNotMapped([name]);
|
|
34
36
|
return 'never hit';
|
|
35
37
|
}
|
|
36
|
-
_mapTo(values, map) {
|
|
38
|
+
_mapTo(values, map, shouldThrowOnUnmapped = true) {
|
|
37
39
|
const foundFields = [];
|
|
38
40
|
let target = {};
|
|
39
41
|
for (const key in map) {
|
|
@@ -44,12 +46,12 @@ export default class KeyMapper {
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
const missingFields = Object.keys(values).filter((key) => !foundFields.includes(key));
|
|
47
|
-
if (missingFields.length > 0) {
|
|
49
|
+
if (shouldThrowOnUnmapped && missingFields.length > 0) {
|
|
48
50
|
this.throwFieldsNotMapped(missingFields);
|
|
49
51
|
}
|
|
50
52
|
return target;
|
|
51
53
|
}
|
|
52
|
-
_mapFrom(values, map) {
|
|
54
|
+
_mapFrom(values, map, shouldThrowOnUnmapped = true) {
|
|
53
55
|
const foundFields = [];
|
|
54
56
|
let target = {};
|
|
55
57
|
for (const targetKey in map) {
|
|
@@ -61,7 +63,7 @@ export default class KeyMapper {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
const missingFields = Object.keys(values).filter((key) => !foundFields.includes(key));
|
|
64
|
-
if (missingFields.length > 0) {
|
|
66
|
+
if (shouldThrowOnUnmapped && missingFields.length > 0) {
|
|
65
67
|
this.throwFieldsNotMapped(missingFields);
|
|
66
68
|
}
|
|
67
69
|
return target;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export default class KeyMapper {
|
|
2
2
|
private map;
|
|
3
3
|
constructor(map: Record<string, any>);
|
|
4
|
-
mapTo(values: Record<string, any
|
|
5
|
-
mapFrom(values: Record<string, any
|
|
4
|
+
mapTo(values: Record<string, any>, options?: MapOptions): any;
|
|
5
|
+
mapFrom(values: Record<string, any>, options?: MapOptions): any;
|
|
6
6
|
mapFieldNameTo(name: string): any;
|
|
7
7
|
private throwFieldsNotMapped;
|
|
8
8
|
mapFieldNameFrom(name: string): string;
|
|
9
9
|
private _mapTo;
|
|
10
10
|
private _mapFrom;
|
|
11
11
|
}
|
|
12
|
+
export interface MapOptions {
|
|
13
|
+
shouldThrowOnUnmapped: boolean;
|
|
14
|
+
}
|
|
@@ -8,11 +8,13 @@ class KeyMapper {
|
|
|
8
8
|
constructor(map) {
|
|
9
9
|
this.map = map;
|
|
10
10
|
}
|
|
11
|
-
mapTo(values) {
|
|
12
|
-
|
|
11
|
+
mapTo(values, options) {
|
|
12
|
+
var _a;
|
|
13
|
+
return this._mapTo(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
|
|
13
14
|
}
|
|
14
|
-
mapFrom(values) {
|
|
15
|
-
|
|
15
|
+
mapFrom(values, options) {
|
|
16
|
+
var _a;
|
|
17
|
+
return this._mapFrom(values, this.map, (_a = options === null || options === void 0 ? void 0 : options.shouldThrowOnUnmapped) !== null && _a !== void 0 ? _a : true);
|
|
16
18
|
}
|
|
17
19
|
mapFieldNameTo(name) {
|
|
18
20
|
if (!this.map[name]) {
|
|
@@ -38,7 +40,7 @@ class KeyMapper {
|
|
|
38
40
|
this.throwFieldsNotMapped([name]);
|
|
39
41
|
return 'never hit';
|
|
40
42
|
}
|
|
41
|
-
_mapTo(values, map) {
|
|
43
|
+
_mapTo(values, map, shouldThrowOnUnmapped = true) {
|
|
42
44
|
const foundFields = [];
|
|
43
45
|
let target = {};
|
|
44
46
|
for (const key in map) {
|
|
@@ -49,12 +51,12 @@ class KeyMapper {
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
const missingFields = Object.keys(values).filter((key) => !foundFields.includes(key));
|
|
52
|
-
if (missingFields.length > 0) {
|
|
54
|
+
if (shouldThrowOnUnmapped && missingFields.length > 0) {
|
|
53
55
|
this.throwFieldsNotMapped(missingFields);
|
|
54
56
|
}
|
|
55
57
|
return target;
|
|
56
58
|
}
|
|
57
|
-
_mapFrom(values, map) {
|
|
59
|
+
_mapFrom(values, map, shouldThrowOnUnmapped = true) {
|
|
58
60
|
const foundFields = [];
|
|
59
61
|
let target = {};
|
|
60
62
|
for (const targetKey in map) {
|
|
@@ -66,7 +68,7 @@ class KeyMapper {
|
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
const missingFields = Object.keys(values).filter((key) => !foundFields.includes(key));
|
|
69
|
-
if (missingFields.length > 0) {
|
|
71
|
+
if (shouldThrowOnUnmapped && missingFields.length > 0) {
|
|
70
72
|
this.throwFieldsNotMapped(missingFields);
|
|
71
73
|
}
|
|
72
74
|
return target;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"!build/__tests__",
|
|
9
9
|
"esm"
|
|
10
10
|
],
|
|
11
|
-
"version": "29.
|
|
11
|
+
"version": "29.3.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.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"
|