@thisisagile/easy 8.37.7 → 8.38.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/dist/sql/Table.d.ts +2 -1
- package/dist/types/Json.js +2 -2
- package/dist/types/Json.js.map +1 -1
- package/dist/utils/Mapper.d.ts +4 -2
- package/dist/utils/Mapper.js +12 -2
- package/dist/utils/Mapper.js.map +1 -1
- package/package.json +2 -2
- package/src/types/Json.ts +2 -2
- package/src/utils/Mapper.ts +23 -8
package/dist/sql/Table.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare class Table extends Mapper {
|
|
|
13
13
|
column: <T = unknown>(name: string, options?: PropertyOptions<T> | undefined) => Column;
|
|
14
14
|
item: (property: string, options?: PropertyOptions<unknown> | undefined) => import("../utils").Property<unknown>;
|
|
15
15
|
ignore: (property?: string) => import("../utils").Mapping;
|
|
16
|
-
|
|
16
|
+
skipIn: (property: string) => import("../utils").Mapping;
|
|
17
|
+
skipOut: (property: string) => import("../utils").Mapping;
|
|
17
18
|
func: (property: string, funcIn: import("../types").Get<import("../types").JsonValue | undefined, Json>, funcOut: import("../types").Get<import("../types").JsonValue | undefined, Json>) => import("../utils").Mapping;
|
|
18
19
|
add: (funcIn: import("../types").Get<import("../types").JsonValue, Json>) => import("../utils").Mapping;
|
|
19
20
|
map: (mapper: import("../types").Construct<Mapper>, property?: string) => import("../utils").Mapping;
|
package/dist/types/Json.js
CHANGED
|
@@ -8,13 +8,13 @@ const isJson = (subject) => (0, IsA_1.isA)(subject, 'toJSON');
|
|
|
8
8
|
exports.isJson = isJson;
|
|
9
9
|
exports.json = {
|
|
10
10
|
parse: (subject) => JSON.parse(JSON.stringify(subject ?? {})),
|
|
11
|
-
merge: (...subjects) => subjects.map(s => exports.json.parse(s)).reduce((js, j) => ({ ...js, ...j }), {}),
|
|
11
|
+
merge: (...subjects) => exports.json.parse(subjects.map(s => (0, exports.asJson)(s, s => exports.json.parse(s))).reduce((js, j) => ({ ...js, ...j }), {})),
|
|
12
12
|
omit: (subject, ...keys) => keys.reduce((js, k) => {
|
|
13
13
|
delete js[k];
|
|
14
14
|
return js;
|
|
15
15
|
}, exports.json.parse(subject)),
|
|
16
16
|
};
|
|
17
17
|
exports.toJson = exports.json.merge;
|
|
18
|
-
const asJson = (j, alt = {}) => ((0, exports.isJson)(j) ? j.toJSON() : (0, Is_1.isObject)(j) ? j : (0, Get_1.ofGet)(alt));
|
|
18
|
+
const asJson = (j, alt = {}) => ((0, exports.isJson)(j) ? j.toJSON() : (0, Is_1.isObject)(j) ? j : (0, Get_1.ofGet)(alt, j));
|
|
19
19
|
exports.asJson = asJson;
|
|
20
20
|
//# sourceMappingURL=Json.js.map
|
package/dist/types/Json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Json.js","sourceRoot":"","sources":["../../src/types/Json.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,6BAAgC;AAChC,+BAAmC;AAK5B,MAAM,MAAM,GAAG,CAAC,OAAiB,EAAqC,EAAE,CAAC,IAAA,SAAG,EAAyB,OAAO,EAAE,QAAQ,CAAC,CAAC;AAAlH,QAAA,MAAM,UAA4G;AAElH,QAAA,IAAI,GAAG;IAClB,KAAK,EAAE,CAAC,OAAgB,EAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAC5E,KAAK,EAAE,CAAC,GAAG,QAAmB,EAAQ,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,YAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Json.js","sourceRoot":"","sources":["../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Q,EAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAU,CAAC,CAAC,CAAC,IAAA,WAAK,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAA1H,QAAA,MAAM,UAAoH"}
|
package/dist/utils/Mapper.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export declare class Mapper extends State implements Mapping {
|
|
|
17
17
|
protected readonly map: {
|
|
18
18
|
item: (property: string, options?: PropertyOptions<unknown> | undefined) => Property<unknown>;
|
|
19
19
|
ignore: (property?: string) => Mapping;
|
|
20
|
-
|
|
20
|
+
skipIn: (property: string) => Mapping;
|
|
21
|
+
skipOut: (property: string) => Mapping;
|
|
21
22
|
func: (property: string, funcIn: Get<JsonValue | undefined, Json>, funcOut: Get<JsonValue | undefined, Json>) => Mapping;
|
|
22
23
|
add: (funcIn: Get<JsonValue, Json>) => Mapping;
|
|
23
24
|
map: (mapper: Construct<Mapper>, property?: string) => Mapping;
|
|
@@ -37,7 +38,8 @@ export declare class Mapper extends State implements Mapping {
|
|
|
37
38
|
export declare const mappings: {
|
|
38
39
|
item: (property: string, options?: PropertyOptions<unknown> | undefined) => Property;
|
|
39
40
|
ignore: (property?: string) => Mapping;
|
|
40
|
-
|
|
41
|
+
skipIn: (property: string) => Mapping;
|
|
42
|
+
skipOut: (property: string) => Mapping;
|
|
41
43
|
func: (property: string, funcIn: Get<JsonValue | undefined, Json>, funcOut: Get<JsonValue | undefined, Json>) => Mapping;
|
|
42
44
|
add: (funcIn: Get<JsonValue, Json>) => Mapping;
|
|
43
45
|
map: (mapper: Construct<Mapper>, property?: string) => Mapping;
|
package/dist/utils/Mapper.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.mappings = exports.Mapper = exports.isMapping = void 0;
|
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const Property_1 = require("./Property");
|
|
6
6
|
const State_1 = require("./State");
|
|
7
|
+
const If_1 = require("./If");
|
|
7
8
|
const isMapping = (m) => (0, types_1.isA)(m, 'in', 'out');
|
|
8
9
|
exports.isMapping = isMapping;
|
|
9
10
|
class Mapper extends State_1.State {
|
|
@@ -22,7 +23,7 @@ class Mapper extends State_1.State {
|
|
|
22
23
|
return this.get('keys', () => this.properties.map(([k]) => k));
|
|
23
24
|
}
|
|
24
25
|
get columns() {
|
|
25
|
-
return this.get('columns', () => this.properties.
|
|
26
|
+
return this.get('columns', () => this.properties.mapDefined(([, p]) => (0, If_1.ifNotEmpty)(p.property, p.property))).distinct();
|
|
26
27
|
}
|
|
27
28
|
get droppedIn() {
|
|
28
29
|
return this.get('droppedIn', () => this.columns.filter(c => !this.keys.some(k => k === c)));
|
|
@@ -48,7 +49,16 @@ exports.mappings = {
|
|
|
48
49
|
in: () => undefined,
|
|
49
50
|
out: () => undefined,
|
|
50
51
|
}),
|
|
51
|
-
|
|
52
|
+
skipIn: (property) => ({
|
|
53
|
+
property,
|
|
54
|
+
in: () => undefined,
|
|
55
|
+
out: (source = {}) => source[property],
|
|
56
|
+
}),
|
|
57
|
+
skipOut: (property) => ({
|
|
58
|
+
property,
|
|
59
|
+
in: (source = {}) => source[property],
|
|
60
|
+
out: () => undefined,
|
|
61
|
+
}),
|
|
52
62
|
func: (property, funcIn, funcOut) => ({
|
|
53
63
|
property,
|
|
54
64
|
in: (source = {}) => (0, types_1.ofGet)(funcIn, source),
|
package/dist/utils/Mapper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mapper.js","sourceRoot":"","sources":["../../src/utils/Mapper.ts"],"names":[],"mappings":";;;AAAA,oCAAuH;AACvH,yCAAuD;AACvD,mCAAgC;
|
|
1
|
+
{"version":3,"file":"Mapper.js","sourceRoot":"","sources":["../../src/utils/Mapper.ts"],"names":[],"mappings":";;;AAAA,oCAAuH;AACvH,yCAAuD;AACvD,mCAAgC;AAChC,6BAAkC;AAO3B,MAAM,SAAS,GAAG,CAAC,CAAW,EAAgB,EAAE,CAAC,IAAA,WAAG,EAAU,CAAC,EAAE,IAAI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isagile/easy",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.38.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "8.
|
|
34
|
+
"@thisisagile/easy-test": "8.38.0",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.8",
|
|
37
37
|
"@types/validator": "^13.7.1"
|
package/src/types/Json.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const isJson = (subject?: unknown): subject is { toJSON: () => Json } =>
|
|
|
9
9
|
|
|
10
10
|
export const json = {
|
|
11
11
|
parse: (subject: unknown): Json => JSON.parse(JSON.stringify(subject ?? {})),
|
|
12
|
-
merge: (...subjects: unknown[]): Json => subjects.map(s => json.parse(s)).reduce((js, j) => ({ ...js, ...j }), {}),
|
|
12
|
+
merge: (...subjects: unknown[]): Json => json.parse(subjects.map(s => asJson(s, s => json.parse(s))).reduce((js, j) => ({ ...js, ...j }), {})),
|
|
13
13
|
omit: (subject: unknown, ...keys: string[]): Json =>
|
|
14
14
|
keys.reduce((js, k) => {
|
|
15
15
|
delete js[k];
|
|
@@ -19,4 +19,4 @@ export const json = {
|
|
|
19
19
|
|
|
20
20
|
export const toJson = json.merge;
|
|
21
21
|
|
|
22
|
-
export const asJson = (j?: unknown, alt: Get<Json> = {}): Json => (isJson(j) ? j.toJSON() : isObject(j) ? (j as Json) : ofGet(alt));
|
|
22
|
+
export const asJson = (j?: unknown, alt: Get<Json> = {}): Json => (isJson(j) ? j.toJSON() : isObject(j) ? (j as Json) : ofGet(alt, j));
|
package/src/utils/Mapper.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Construct, Get, isA, isEmpty, json, Json, JsonValue, List, meta, ofConstruct, ofGet, toList } from '../types';
|
|
2
2
|
import { Property, PropertyOptions } from './Property';
|
|
3
3
|
import { State } from './State';
|
|
4
|
+
import { ifNotEmpty } from './If';
|
|
4
5
|
|
|
5
6
|
export type Mapping = {
|
|
6
7
|
property: string;
|
|
@@ -19,34 +20,40 @@ export class Mapper extends State implements Mapping {
|
|
|
19
20
|
super();
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
// All properties that are a mapping
|
|
22
24
|
get properties(): List<[string, Mapping]> {
|
|
23
25
|
return this.get('props', () =>
|
|
24
26
|
meta(this)
|
|
25
27
|
.entries<Mapping>()
|
|
26
|
-
.filter(([, v]) => isMapping(v))
|
|
28
|
+
.filter(([, v]) => isMapping(v)),
|
|
27
29
|
);
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
// All names of properties (in target) that have a Mapping
|
|
30
33
|
get keys(): List<string> {
|
|
31
34
|
return this.get('keys', () => this.properties.map(([k]) => k));
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
// All names of properties (in source) that are named in a Mapping
|
|
34
38
|
get columns(): List<string> {
|
|
35
|
-
return this.get('columns', () => this.properties.
|
|
39
|
+
return this.get('columns', () => this.properties.mapDefined(([, p]) => ifNotEmpty(p.property, p.property))).distinct();
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
// All names of properties (in source) that are NOT properties in target
|
|
38
43
|
private get droppedIn(): List<string> {
|
|
39
44
|
return this.get('droppedIn', () => this.columns.filter(c => !this.keys.some(k => k === c)));
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
// All names op properties (in target) that are NOT properties in source
|
|
42
48
|
private get droppedOut(): List<string> {
|
|
43
49
|
return this.get('droppedOut', () => this.properties.filter(([, p]) => !this.keys.some(k => k === p.property ?? '')).map(([k]) => k));
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
public in(from: Json = {}): Json {
|
|
47
53
|
return json.omit(
|
|
48
|
-
this.properties.reduce((a, [k, p]) => json.merge(a, { [k]: p.in({ ...a, ...from }) }),
|
|
49
|
-
|
|
54
|
+
this.properties.reduce((a, [k, p]) => json.merge(a, { [k]: p.in({ ...a, ...from }) }),
|
|
55
|
+
this.options.startFrom === 'source' ? from : {}),
|
|
56
|
+
...this.droppedIn,
|
|
50
57
|
);
|
|
51
58
|
}
|
|
52
59
|
|
|
@@ -54,9 +61,9 @@ export class Mapper extends State implements Mapping {
|
|
|
54
61
|
return json.omit(
|
|
55
62
|
this.properties.reduce(
|
|
56
63
|
(a, [k, p]) => json.merge(a, isEmpty(p.property) ? p.out(to, k) : { [p.property ?? '']: p.out({ ...a, ...to }, k) }),
|
|
57
|
-
this.options.startFrom === 'source' ? to : {}
|
|
64
|
+
this.options.startFrom === 'source' ? to : {},
|
|
58
65
|
),
|
|
59
|
-
...this.droppedOut
|
|
66
|
+
...this.droppedOut,
|
|
60
67
|
);
|
|
61
68
|
}
|
|
62
69
|
|
|
@@ -72,7 +79,16 @@ export const mappings = {
|
|
|
72
79
|
in: (): JsonValue | undefined => undefined,
|
|
73
80
|
out: (): JsonValue | undefined => undefined,
|
|
74
81
|
}),
|
|
75
|
-
|
|
82
|
+
skipIn: (property : string): Mapping => ({
|
|
83
|
+
property,
|
|
84
|
+
in: (): JsonValue | undefined => undefined,
|
|
85
|
+
out: (source: Json = {}): JsonValue => source[property],
|
|
86
|
+
}),
|
|
87
|
+
skipOut: (property: string ): Mapping => ({
|
|
88
|
+
property,
|
|
89
|
+
in: (source: Json = {}): JsonValue => source[property],
|
|
90
|
+
out: (): JsonValue | undefined => undefined,
|
|
91
|
+
}),
|
|
76
92
|
func: (property: string, funcIn: Get<JsonValue | undefined, Json>, funcOut: Get<JsonValue | undefined, Json>): Mapping => ({
|
|
77
93
|
property,
|
|
78
94
|
in: (source: Json = {}): JsonValue | undefined => ofGet(funcIn, source),
|
|
@@ -98,7 +114,6 @@ export const mappings = {
|
|
|
98
114
|
return { ...a, [m.property]: out ?? {} };
|
|
99
115
|
}, {}),
|
|
100
116
|
}),
|
|
101
|
-
|
|
102
117
|
list: (mapper: Mapping, property: string): Mapping => ({
|
|
103
118
|
property: property,
|
|
104
119
|
in: (source: Json = {}): JsonValue =>
|