@fluojs/core 1.0.0 → 1.0.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/metadata/validation.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EAGzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/metadata/validation.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EAGzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA0FpE;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,GAAG,uBAAuB,GAAG,SAAS,CAiBhI;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,mBAAmB,EAChC,QAAQ,EAAE,uBAAuB,GAChC,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,mBAAmB,EAChC,IAAI,EAAE,sBAAsB,GAC3B,IAAI,CAEN;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAI3F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,WAAW,GAAG,qBAAqB,EAAE,CA8B7E;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,GAAG,SAAS,sBAAsB,EAAE,CAQ9H;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,WAAW,GAAG,wBAAwB,EAAE,CAiBnF;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,mBAAmB,EAAE,CAExF"}
|
|
@@ -3,6 +3,54 @@ import { createClonedWeakMapStore } from './store.js';
|
|
|
3
3
|
const dtoFieldBindingStore = new WeakMap();
|
|
4
4
|
const dtoFieldValidationStore = new WeakMap();
|
|
5
5
|
const classValidationStore = createClonedWeakMapStore(rules => rules.map(rule => cloneMutableValue(rule)));
|
|
6
|
+
function getInheritedTargets(target) {
|
|
7
|
+
const targets = [];
|
|
8
|
+
let current = target;
|
|
9
|
+
while (current && current !== Object.prototype) {
|
|
10
|
+
targets.unshift(current);
|
|
11
|
+
current = Object.getPrototypeOf(current);
|
|
12
|
+
}
|
|
13
|
+
return targets;
|
|
14
|
+
}
|
|
15
|
+
function getInheritedConstructors(target) {
|
|
16
|
+
const targets = [];
|
|
17
|
+
let current = target;
|
|
18
|
+
while (current && current !== Function.prototype) {
|
|
19
|
+
targets.unshift(current);
|
|
20
|
+
current = Object.getPrototypeOf(current);
|
|
21
|
+
}
|
|
22
|
+
return targets;
|
|
23
|
+
}
|
|
24
|
+
function getInheritedStoredDtoBindingMap(target) {
|
|
25
|
+
const merged = new Map();
|
|
26
|
+
for (const current of getInheritedTargets(target)) {
|
|
27
|
+
const stored = dtoFieldBindingStore.get(current);
|
|
28
|
+
if (!stored) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
for (const [propertyKey, metadata] of stored) {
|
|
32
|
+
merged.set(propertyKey, cloneMutableValue(metadata));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return merged;
|
|
36
|
+
}
|
|
37
|
+
function getInheritedStoredDtoValidationMap(target) {
|
|
38
|
+
const merged = new Map();
|
|
39
|
+
for (const current of getInheritedTargets(target)) {
|
|
40
|
+
const stored = dtoFieldValidationStore.get(current);
|
|
41
|
+
if (!stored) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
for (const [propertyKey, rules] of stored) {
|
|
45
|
+
const existing = merged.get(propertyKey) ?? [];
|
|
46
|
+
merged.set(propertyKey, [...existing, ...rules.map(rule => cloneMutableValue(rule))]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return merged;
|
|
50
|
+
}
|
|
51
|
+
function getInheritedStoredClassValidationRules(target) {
|
|
52
|
+
return getInheritedConstructors(target).flatMap(current => classValidationStore.read(current) ?? []);
|
|
53
|
+
}
|
|
6
54
|
function getStandardDtoBindingMap(target) {
|
|
7
55
|
return getStandardConstructorMetadataMap(target, standardMetadataKeys.dtoFieldBinding);
|
|
8
56
|
}
|
|
@@ -22,7 +70,7 @@ function getStandardClassValidationRules(target) {
|
|
|
22
70
|
* @returns The get dto field binding metadata result.
|
|
23
71
|
*/
|
|
24
72
|
export function getDtoFieldBindingMetadata(target, propertyKey) {
|
|
25
|
-
const stored =
|
|
73
|
+
const stored = getInheritedStoredDtoBindingMap(target).get(propertyKey);
|
|
26
74
|
const standard = getStandardDtoBindingMap(target)?.get(propertyKey);
|
|
27
75
|
const source = stored?.source ?? standard?.source;
|
|
28
76
|
if (!source) {
|
|
@@ -82,7 +130,7 @@ export function appendClassValidationRule(target, rule) {
|
|
|
82
130
|
* @returns The get dto binding schema result.
|
|
83
131
|
*/
|
|
84
132
|
export function getDtoBindingSchema(dto) {
|
|
85
|
-
const stored =
|
|
133
|
+
const stored = getInheritedStoredDtoBindingMap(dto.prototype);
|
|
86
134
|
const standard = getStandardMetadataBag(dto)?.[standardMetadataKeys.dtoFieldBinding] ?? new Map();
|
|
87
135
|
const keys = mergeMetadataPropertyKeys(stored, standard);
|
|
88
136
|
return keys.flatMap(propertyKey => {
|
|
@@ -115,7 +163,7 @@ export function getDtoBindingSchema(dto) {
|
|
|
115
163
|
* @returns The get dto field validation rules result.
|
|
116
164
|
*/
|
|
117
165
|
export function getDtoFieldValidationRules(target, propertyKey) {
|
|
118
|
-
const stored =
|
|
166
|
+
const stored = getInheritedStoredDtoValidationMap(target).get(propertyKey) ?? [];
|
|
119
167
|
const standard = getStandardDtoValidationMap(target)?.get(propertyKey) ?? [];
|
|
120
168
|
return [...standard.map(rule => cloneMutableValue(rule)), ...stored.map(rule => cloneMutableValue(rule))];
|
|
121
169
|
}
|
|
@@ -127,7 +175,7 @@ export function getDtoFieldValidationRules(target, propertyKey) {
|
|
|
127
175
|
* @returns The get dto validation schema result.
|
|
128
176
|
*/
|
|
129
177
|
export function getDtoValidationSchema(dto) {
|
|
130
|
-
const stored =
|
|
178
|
+
const stored = getInheritedStoredDtoValidationMap(dto.prototype);
|
|
131
179
|
const standard = getStandardDtoValidationMap(dto.prototype) ?? new Map();
|
|
132
180
|
const keys = mergeMetadataPropertyKeys(stored, standard);
|
|
133
181
|
return keys.flatMap(propertyKey => {
|
|
@@ -149,5 +197,5 @@ export function getDtoValidationSchema(dto) {
|
|
|
149
197
|
* @returns The get class validation rules result.
|
|
150
198
|
*/
|
|
151
199
|
export function getClassValidationRules(target) {
|
|
152
|
-
return [...(getStandardClassValidationRules(target) ?? []), ...(
|
|
200
|
+
return [...(getStandardClassValidationRules(target) ?? []), ...getInheritedStoredClassValidationRules(target)];
|
|
153
201
|
}
|