@common-stack/store-mongo 7.2.1-alpha.22 → 7.2.1-alpha.25
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,3 +1,4 @@
|
|
|
1
|
+
// from package: store-mongo
|
|
1
2
|
/**
|
|
2
3
|
* Converts Zod schemas to Moleculer parameter validation schemas
|
|
3
4
|
*
|
|
@@ -26,7 +27,7 @@ import { z } from 'zod';
|
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
29
|
export function zodToMoleculerParams(zodSchema: z.ZodObject<any>): Record<string, any> {
|
|
29
|
-
const shape = zodSchema
|
|
30
|
+
const { shape } = zodSchema;
|
|
30
31
|
const result: Record<string, any> = {};
|
|
31
32
|
|
|
32
33
|
for (const [key, value] of Object.entries(shape)) {
|
|
@@ -42,7 +43,7 @@ export function zodToMoleculerParams(zodSchema: z.ZodObject<any>): Record<string
|
|
|
42
43
|
function zodTypeToMoleculer(zodType: z.ZodTypeAny): any {
|
|
43
44
|
// Handle optional types
|
|
44
45
|
if (zodType instanceof z.ZodOptional) {
|
|
45
|
-
const innerType = zodTypeToMoleculer(zodType.
|
|
46
|
+
const innerType = zodTypeToMoleculer(zodType.def.innerType as z.ZodTypeAny);
|
|
46
47
|
if (typeof innerType === 'string') {
|
|
47
48
|
return { type: innerType, optional: true };
|
|
48
49
|
}
|
|
@@ -51,7 +52,7 @@ function zodTypeToMoleculer(zodType: z.ZodTypeAny): any {
|
|
|
51
52
|
|
|
52
53
|
// Handle nullable types
|
|
53
54
|
if (zodType instanceof z.ZodNullable) {
|
|
54
|
-
return zodTypeToMoleculer(zodType.
|
|
55
|
+
return zodTypeToMoleculer(zodType.def.innerType as z.ZodTypeAny);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
// Primitive types
|
|
@@ -74,7 +75,7 @@ function zodTypeToMoleculer(zodType: z.ZodTypeAny): any {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
// Enum types
|
|
77
|
-
if (zodType instanceof z.
|
|
78
|
+
if (zodType instanceof z.ZodEnum || zodType.type === 'enum') {
|
|
78
79
|
return 'string'; // Moleculer doesn't have enum type, use string
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -85,10 +86,10 @@ function zodTypeToMoleculer(zodType: z.ZodTypeAny): any {
|
|
|
85
86
|
|
|
86
87
|
// Union types - use the first non-undefined/null type
|
|
87
88
|
if (zodType instanceof z.ZodUnion) {
|
|
88
|
-
const options = zodType.
|
|
89
|
+
const { options } = zodType.def;
|
|
89
90
|
for (const option of options) {
|
|
90
91
|
if (!(option instanceof z.ZodUndefined) && !(option instanceof z.ZodNull)) {
|
|
91
|
-
return zodTypeToMoleculer(option);
|
|
92
|
+
return zodTypeToMoleculer(option as z.ZodTypeAny);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
return 'any';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/store-mongo",
|
|
3
|
-
"version": "7.2.1-alpha.
|
|
3
|
+
"version": "7.2.1-alpha.25",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
]
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "d91749dc28ce303e6e02fa6db7c82cbb67b603c5",
|
|
62
62
|
"typescript": {
|
|
63
63
|
"definition": "lib/index.d.ts"
|
|
64
64
|
}
|