@velajs/vela 1.5.0 → 1.5.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,17 +1,18 @@
|
|
|
1
1
|
export function createZodDto(schema, options = {}) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
// Computed-property-name idiom: NamedEvaluation reads the property key and
|
|
3
|
+
// stamps `name` on the class at creation, so callers see `MyDto` (or the
|
|
4
|
+
// override) directly in stack traces and OpenAPI output — no post-hoc
|
|
5
|
+
// `Object.defineProperty` patching of the class's `name` slot.
|
|
6
|
+
const className = options.name ?? 'ZodDto';
|
|
7
|
+
const ZodDto = {
|
|
8
|
+
[className]: class {
|
|
9
|
+
static schema = schema;
|
|
10
|
+
constructor(initial){
|
|
11
|
+
if (initial && typeof initial === 'object') {
|
|
12
|
+
Object.assign(this, initial);
|
|
13
|
+
}
|
|
7
14
|
}
|
|
8
15
|
}
|
|
9
|
-
};
|
|
10
|
-
if (options.name) {
|
|
11
|
-
Object.defineProperty(ZodDto, 'name', {
|
|
12
|
-
value: options.name,
|
|
13
|
-
configurable: true
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
+
}[className];
|
|
16
17
|
return ZodDto;
|
|
17
18
|
}
|