@common-stack/server-core 7.2.1-alpha.32 → 7.2.1-alpha.33
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/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{Feature,featureCatalog}from'./connector/connector.js';export{GraphqlRootType}from'./interfaces/rules.js';export{TYPES}from'./constants/types.js';export{CACHE_CONTROL_DIRECTIVE}from'./constants/directives.js';export{logger}from'./logger/logger.js';export{getCurrentPreferences,transformPrefsToArray}from'./utils/preferences.js';export{generateQueryCacheKey}from'./utils/generate-query-cache-key.js';export{extractTenantId}from'./utils/extract-tenant-id.js';export{getDirectiveArgsFromSchema}from'./utils/get-directive-args-from-schema.js';export{buildActionPath,getActionName,getAllMethodNames,isExcludedMethod,toPascalCase}from'./moleculer-generation/serviceGenerationUtils.js';export{Moleculer}from'./moleculer-generation/moleculerEventHandler.js';export{createTypedAction,debugServiceParams,generateAutoInferredServiceActions,generateServiceActions,generateServiceActionsAndEvents,generateTypeSafeServiceActions,printServiceParams,verifyAllParamsDefined}from'./moleculer-generation/typedMoleculerService.js';export{ProxyService,generateProxyMethods}from'./moleculer-generation/typedProxyService.js';//# sourceMappingURL=index.js.map
|
|
1
|
+
export{Feature,featureCatalog}from'./connector/connector.js';export{GraphqlRootType}from'./interfaces/rules.js';export{TYPES}from'./constants/types.js';export{CACHE_CONTROL_DIRECTIVE}from'./constants/directives.js';export{logger}from'./logger/logger.js';export{getCurrentPreferences,transformPrefsToArray}from'./utils/preferences.js';export{generateQueryCacheKey}from'./utils/generate-query-cache-key.js';export{extractTenantId}from'./utils/extract-tenant-id.js';export{getDirectiveArgsFromSchema}from'./utils/get-directive-args-from-schema.js';export{buildActionPath,getActionName,getAllMethodNames,isExcludedMethod,toPascalCase}from'./moleculer-generation/serviceGenerationUtils.js';export{Moleculer}from'./moleculer-generation/moleculerEventHandler.js';export{createTypedAction,debugServiceParams,generateAutoInferredServiceActions,generateServiceActions,generateServiceActionsAndEvents,generateTypeSafeServiceActions,printServiceParams,verifyAllParamsDefined}from'./moleculer-generation/typedMoleculerService.js';export{ProxyService,generateProxyMethods}from'./moleculer-generation/typedProxyService.js';export{zodSchemasToMoleculer,zodToMoleculerParams}from'./moleculer-generation/zodToMoleculer.js';//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts Zod schemas to Moleculer parameter validation schemas
|
|
3
|
+
*
|
|
4
|
+
* This utility bridges the gap between Zod's rich type system and Moleculer's
|
|
5
|
+
* validator format, allowing us to use TypeScript-derived Zod schemas for
|
|
6
|
+
* runtime parameter validation in Moleculer services.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/**
|
|
10
|
+
* Converts a Zod schema object to Moleculer parameter schema format
|
|
11
|
+
*
|
|
12
|
+
* @param zodSchema - Zod object schema with parameter definitions
|
|
13
|
+
* @returns Moleculer-compatible parameter schema
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const zodSchema = z.object({
|
|
18
|
+
* email: z.string(),
|
|
19
|
+
* age: z.number().optional(),
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const moleculerParams = zodToMoleculerParams(zodSchema);
|
|
23
|
+
* // Returns: { email: 'string', age: { type: 'number', optional: true } }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function zodToMoleculerParams(zodSchema: z.ZodObject<any>): Record<string, any>;
|
|
27
|
+
/**
|
|
28
|
+
* Batch converts multiple Zod schemas to Moleculer parameter schemas
|
|
29
|
+
*
|
|
30
|
+
* @param schemas - Object mapping method names to Zod schemas
|
|
31
|
+
* @returns Object mapping method names to Moleculer parameter schemas
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const schemas = {
|
|
36
|
+
* findById: z.object({ id: z.string() }),
|
|
37
|
+
* update: z.object({ id: z.string(), data: z.object({}) }),
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* const moleculerSchemas = zodSchemasToMoleculer(schemas);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function zodSchemasToMoleculer(schemas: Record<string, z.ZodObject<any>>): Record<string, Record<string, any>>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {z}from'zod';// from package: store-mongo
|
|
2
|
+
/**
|
|
3
|
+
* Converts Zod schemas to Moleculer parameter validation schemas
|
|
4
|
+
*
|
|
5
|
+
* This utility bridges the gap between Zod's rich type system and Moleculer's
|
|
6
|
+
* validator format, allowing us to use TypeScript-derived Zod schemas for
|
|
7
|
+
* runtime parameter validation in Moleculer services.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Converts a Zod schema object to Moleculer parameter schema format
|
|
11
|
+
*
|
|
12
|
+
* @param zodSchema - Zod object schema with parameter definitions
|
|
13
|
+
* @returns Moleculer-compatible parameter schema
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const zodSchema = z.object({
|
|
18
|
+
* email: z.string(),
|
|
19
|
+
* age: z.number().optional(),
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const moleculerParams = zodToMoleculerParams(zodSchema);
|
|
23
|
+
* // Returns: { email: 'string', age: { type: 'number', optional: true } }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function zodToMoleculerParams(zodSchema) {
|
|
27
|
+
const { shape } = zodSchema;
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
30
|
+
result[key] = zodTypeToMoleculer(value);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts a single Zod type to Moleculer validator format
|
|
36
|
+
*/
|
|
37
|
+
function zodTypeToMoleculer(zodType) {
|
|
38
|
+
// Handle optional types
|
|
39
|
+
if (zodType instanceof z.ZodOptional) {
|
|
40
|
+
const innerType = zodTypeToMoleculer(zodType.def.innerType);
|
|
41
|
+
if (typeof innerType === 'string') {
|
|
42
|
+
return { type: innerType, optional: true };
|
|
43
|
+
}
|
|
44
|
+
return { ...innerType, optional: true };
|
|
45
|
+
}
|
|
46
|
+
// Handle nullable types
|
|
47
|
+
if (zodType instanceof z.ZodNullable) {
|
|
48
|
+
return zodTypeToMoleculer(zodType.def.innerType);
|
|
49
|
+
}
|
|
50
|
+
// Primitive types
|
|
51
|
+
if (zodType instanceof z.ZodString) {
|
|
52
|
+
return 'string';
|
|
53
|
+
}
|
|
54
|
+
if (zodType instanceof z.ZodNumber) {
|
|
55
|
+
return 'number';
|
|
56
|
+
}
|
|
57
|
+
if (zodType instanceof z.ZodBoolean) {
|
|
58
|
+
return 'boolean';
|
|
59
|
+
}
|
|
60
|
+
if (zodType instanceof z.ZodDate) {
|
|
61
|
+
return 'date';
|
|
62
|
+
}
|
|
63
|
+
// Array types
|
|
64
|
+
if (zodType instanceof z.ZodArray) {
|
|
65
|
+
return 'array';
|
|
66
|
+
}
|
|
67
|
+
// Enum types
|
|
68
|
+
if (zodType instanceof z.ZodEnum || zodType.type === 'enum') {
|
|
69
|
+
return 'string'; // Moleculer doesn't have enum type, use string
|
|
70
|
+
}
|
|
71
|
+
// Object types
|
|
72
|
+
if (zodType instanceof z.ZodObject) {
|
|
73
|
+
return 'object';
|
|
74
|
+
}
|
|
75
|
+
// Union types - use the first non-undefined/null type
|
|
76
|
+
if (zodType instanceof z.ZodUnion) {
|
|
77
|
+
const { options } = zodType.def;
|
|
78
|
+
for (const option of options) {
|
|
79
|
+
if (!(option instanceof z.ZodUndefined) && !(option instanceof z.ZodNull)) {
|
|
80
|
+
return zodTypeToMoleculer(option);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return 'any';
|
|
84
|
+
}
|
|
85
|
+
// Any type
|
|
86
|
+
if (zodType instanceof z.ZodAny) {
|
|
87
|
+
return 'any';
|
|
88
|
+
}
|
|
89
|
+
// Default to object for complex types
|
|
90
|
+
return 'object';
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Batch converts multiple Zod schemas to Moleculer parameter schemas
|
|
94
|
+
*
|
|
95
|
+
* @param schemas - Object mapping method names to Zod schemas
|
|
96
|
+
* @returns Object mapping method names to Moleculer parameter schemas
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const schemas = {
|
|
101
|
+
* findById: z.object({ id: z.string() }),
|
|
102
|
+
* update: z.object({ id: z.string(), data: z.object({}) }),
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* const moleculerSchemas = zodSchemasToMoleculer(schemas);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function zodSchemasToMoleculer(schemas) {
|
|
109
|
+
const result = {};
|
|
110
|
+
for (const [methodName, schema] of Object.entries(schemas)) {
|
|
111
|
+
result[methodName] = zodToMoleculerParams(schema);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}export{zodSchemasToMoleculer,zodToMoleculerParams};//# sourceMappingURL=zodToMoleculer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodToMoleculer.js","sources":["../../src/moleculer-generation/zodToMoleculer.ts"],"sourcesContent":[null],"names":[],"mappings":"oBAAA;AACA;;;;;;AAMG;AAIH;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,oBAAoB,CAAC,SAA2B,EAAA;AAC5D,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IAC5B,MAAM,MAAM,GAAwB,EAAE,CAAC;AAEvC,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC9C,MAAM,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KA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AAA,OAAO,QAAQ,CAAC;KACnB;;AAGD,IAAA,IAAI,OAAO,YAAY,CAAC,CAAC,QAAQ,EAAE;AAC/B,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAChC,QAAA,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;AAC1B,YAAA,IAAI,EAAE,MAAM,YAAY,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE;AACvE,gBAAA,OAAO,kBAAkB,CAAC,MAAsB,CAAC,CAAC;aACrD;SACJ;AACD,QAAA,OAAO,KAAK,CAAC;KAChB;;AAGD,IAAA,IAAI,OAAO,YAAY,CAAC,CAAC,MAAM,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC;KAChB;;AAGD,IAAA,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;;;;;AAeG;AACG,SAAU,qBAAqB,CACjC,OAAyC,EAAA;IAEzC,MAAM,MAAM,GAAwC,EAAE,CAAC;AAEvD,IAAA,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACxD,MAAM,CAAC,UAAU,CAAC,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;KACrD;AAED,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/server-core",
|
|
3
|
-
"version": "7.2.1-alpha.
|
|
3
|
+
"version": "7.2.1-alpha.33",
|
|
4
4
|
"description": "common core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a3dd530984e7d5e278d5ee6867afc5df393eb1de",
|
|
37
37
|
"typescript": {
|
|
38
38
|
"definition": "lib/index.d.ts"
|
|
39
39
|
}
|