@common-stack/store-mongo 8.0.2-alpha.0 → 8.1.1-alpha.13

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.
Files changed (77) hide show
  1. package/LICENSE +34 -21
  2. package/lib/containers/container.d.ts +14 -0
  3. package/lib/containers/container.js +17 -0
  4. package/lib/containers/container.js.map +1 -0
  5. package/lib/containers/index.d.ts +1 -0
  6. package/lib/dataloaders/bulk-dataloader-v2.d.ts +40 -0
  7. package/lib/dataloaders/bulk-dataloader-v2.js +118 -0
  8. package/lib/dataloaders/bulk-dataloader-v2.js.map +1 -0
  9. package/lib/dataloaders/bulk-dataloader-v2.test.d.ts +1 -0
  10. package/lib/dataloaders/bulk-dataloader.d.ts +1 -1
  11. package/lib/dataloaders/bulk-dataloader.js.map +1 -1
  12. package/lib/dataloaders/bulk-dataloader.test.d.ts +1 -0
  13. package/lib/dataloaders/index.d.ts +1 -0
  14. package/lib/graphql/schema/base-services.graphql +238 -0
  15. package/lib/helpers/mongoose-connection.js.map +1 -1
  16. package/lib/index.d.ts +2 -1
  17. package/lib/index.js +1 -1
  18. package/lib/interfaces/base-repository.d.ts +1 -5
  19. package/lib/interfaces/base-service.d.ts +1 -1
  20. package/lib/interfaces/getAllArgs.d.ts +135 -0
  21. package/lib/interfaces/getAllArgs.js +39 -0
  22. package/lib/interfaces/getAllArgs.js.map +1 -0
  23. package/lib/interfaces/index.d.ts +1 -4
  24. package/lib/interfaces/index.old.d.ts +3 -0
  25. package/lib/mixins/BaseServiceMixin.d.ts +45 -0
  26. package/lib/mixins/BaseServiceMixin.js +212 -0
  27. package/lib/mixins/BaseServiceMixin.js.map +1 -0
  28. package/lib/mixins/__tests__/BaseServiceMixin.test.d.ts +1 -0
  29. package/lib/mixins/base-service-mixin.js.map +1 -1
  30. package/lib/mixins/index.d.ts +1 -0
  31. package/lib/module.d.ts +2 -0
  32. package/lib/module.js +4 -0
  33. package/lib/module.js.map +1 -0
  34. package/lib/services/BaseProxyService.d.ts +28 -0
  35. package/lib/services/BaseProxyService.js +52 -0
  36. package/lib/services/BaseProxyService.js.map +1 -0
  37. package/lib/services/BaseService.d.ts +23 -0
  38. package/lib/services/BaseService.js +65 -0
  39. package/lib/services/BaseService.js.map +1 -0
  40. package/lib/services/BaseService.test.d.ts +1 -0
  41. package/lib/services/ConnectionPoolManager.d.ts +54 -0
  42. package/lib/services/ConnectionPoolManager.js +163 -0
  43. package/lib/services/ConnectionPoolManager.js.map +1 -0
  44. package/lib/services/base-proxy-service.d.ts +2 -1
  45. package/lib/services/base-proxy-service.js.map +1 -1
  46. package/lib/services/base-service.d.ts +2 -1
  47. package/lib/services/base-service.js.map +1 -1
  48. package/lib/services/index.d.ts +3 -0
  49. package/lib/store/models/common-options-v2.d.ts +16 -0
  50. package/lib/store/models/common-options-v2.js +40 -0
  51. package/lib/store/models/common-options-v2.js.map +1 -0
  52. package/lib/store/models/common-options.js.map +1 -1
  53. package/lib/store/models/index.d.ts +1 -0
  54. package/lib/store/repositories/BaseMongoRepository.d.ts +72 -0
  55. package/lib/store/repositories/BaseMongoRepository.js +423 -0
  56. package/lib/store/repositories/BaseMongoRepository.js.map +1 -0
  57. package/lib/store/repositories/BaseMongoRepository.test.d.ts +1 -0
  58. package/lib/store/repositories/CustomIdRepository.test.d.ts +1 -0
  59. package/lib/store/repositories/base-repository.d.ts +2 -1
  60. package/lib/store/repositories/base-repository.js +1 -1
  61. package/lib/store/repositories/base-repository.js.map +1 -1
  62. package/lib/store/repositories/index.d.ts +1 -0
  63. package/lib/templates/constants/SERVER_TYPES.ts.template +7 -0
  64. package/lib/templates/repositories/DataLoader.ts.template +211 -0
  65. package/lib/templates/repositories/DatabaseMigration.ts.template +13 -0
  66. package/lib/templates/repositories/IBaseMongoRepository.ts.template +284 -0
  67. package/lib/templates/repositories/IBaseService.ts.template +231 -0
  68. package/lib/templates/repositories/IBaseServiceMixin.ts.template +477 -0
  69. package/lib/templates/repositories/dbCommonTypes.ts.template +140 -0
  70. package/lib/templates/repositories/moleculerEventHandler.ts.template.toberemoved +118 -0
  71. package/lib/templates/repositories/mongoCommonTypes.ts.template +21 -0
  72. package/lib/templates/repositories/typedMoleculerService.ts.template.toberemoved +1188 -0
  73. package/lib/templates/repositories/zodToMoleculer.ts.template.toberemoved +133 -0
  74. package/package.json +22 -5
  75. package/lib/interfaces/base-repository.js +0 -5
  76. package/lib/interfaces/base-repository.js.map +0 -1
  77. package/lib/interfaces/get-all-args.d.ts +0 -9
@@ -0,0 +1,133 @@
1
+ // 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
+ import { z } from 'zod';
11
+
12
+ /**
13
+ * Converts a Zod schema object to Moleculer parameter schema format
14
+ *
15
+ * @param zodSchema - Zod object schema with parameter definitions
16
+ * @returns Moleculer-compatible parameter schema
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const zodSchema = z.object({
21
+ * email: z.string(),
22
+ * age: z.number().optional(),
23
+ * });
24
+ *
25
+ * const moleculerParams = zodToMoleculerParams(zodSchema);
26
+ * // Returns: { email: 'string', age: { type: 'number', optional: true } }
27
+ * ```
28
+ */
29
+ export function zodToMoleculerParams(zodSchema: z.ZodObject<any>): Record<string, any> {
30
+ const { shape } = zodSchema;
31
+ const result: Record<string, any> = {};
32
+
33
+ for (const [key, value] of Object.entries(shape)) {
34
+ result[key] = zodTypeToMoleculer(value as z.ZodTypeAny);
35
+ }
36
+
37
+ return result;
38
+ }
39
+
40
+ /**
41
+ * Converts a single Zod type to Moleculer validator format
42
+ */
43
+ function zodTypeToMoleculer(zodType: z.ZodTypeAny): any {
44
+ // Handle optional types
45
+ if (zodType instanceof z.ZodOptional) {
46
+ const innerType = zodTypeToMoleculer(zodType.def.innerType as z.ZodTypeAny);
47
+ if (typeof innerType === 'string') {
48
+ return { type: innerType, optional: true };
49
+ }
50
+ return { ...innerType, optional: true };
51
+ }
52
+
53
+ // Handle nullable types
54
+ if (zodType instanceof z.ZodNullable) {
55
+ return zodTypeToMoleculer(zodType.def.innerType as z.ZodTypeAny);
56
+ }
57
+
58
+ // Primitive types
59
+ if (zodType instanceof z.ZodString) {
60
+ return 'string';
61
+ }
62
+ if (zodType instanceof z.ZodNumber) {
63
+ return 'number';
64
+ }
65
+ if (zodType instanceof z.ZodBoolean) {
66
+ return 'boolean';
67
+ }
68
+ if (zodType instanceof z.ZodDate) {
69
+ return 'date';
70
+ }
71
+
72
+ // Array types
73
+ if (zodType instanceof z.ZodArray) {
74
+ return 'array';
75
+ }
76
+
77
+ // Enum types
78
+ if (zodType instanceof z.ZodEnum || zodType.type === 'enum') {
79
+ return 'string'; // Moleculer doesn't have enum type, use string
80
+ }
81
+
82
+ // Object types
83
+ if (zodType instanceof z.ZodObject) {
84
+ return 'object';
85
+ }
86
+
87
+ // Union types - use the first non-undefined/null type
88
+ if (zodType instanceof z.ZodUnion) {
89
+ const { options } = zodType.def;
90
+ for (const option of options) {
91
+ if (!(option instanceof z.ZodUndefined) && !(option instanceof z.ZodNull)) {
92
+ return zodTypeToMoleculer(option as z.ZodTypeAny);
93
+ }
94
+ }
95
+ return 'any';
96
+ }
97
+
98
+ // Any type
99
+ if (zodType instanceof z.ZodAny) {
100
+ return 'any';
101
+ }
102
+
103
+ // Default to object for complex types
104
+ return 'object';
105
+ }
106
+
107
+ /**
108
+ * Batch converts multiple Zod schemas to Moleculer parameter schemas
109
+ *
110
+ * @param schemas - Object mapping method names to Zod schemas
111
+ * @returns Object mapping method names to Moleculer parameter schemas
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const schemas = {
116
+ * findById: z.object({ id: z.string() }),
117
+ * update: z.object({ id: z.string(), data: z.object({}) }),
118
+ * };
119
+ *
120
+ * const moleculerSchemas = zodSchemasToMoleculer(schemas);
121
+ * ```
122
+ */
123
+ export function zodSchemasToMoleculer(
124
+ schemas: Record<string, z.ZodObject<any>>
125
+ ): Record<string, Record<string, any>> {
126
+ const result: Record<string, Record<string, any>> = {};
127
+
128
+ for (const [methodName, schema] of Object.entries(schemas)) {
129
+ result[methodName] = zodToMoleculerParams(schema);
130
+ }
131
+
132
+ return result;
133
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@common-stack/store-mongo",
3
- "version": "8.0.2-alpha.0",
3
+ "version": "8.1.1-alpha.13",
4
4
  "description": "Sample core for higher packages to depend on",
5
- "license": "ISC",
5
+ "license": "UNLICENSED",
6
6
  "author": "CDMBase LLC",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",
@@ -24,9 +24,10 @@
24
24
  "watch": "npm run build:lib:watch"
25
25
  },
26
26
  "dependencies": {
27
- "@common-stack/core": "8.0.2-alpha.0"
27
+ "@common-stack/core": "8.1.1-alpha.13"
28
28
  },
29
29
  "devDependencies": {
30
+ "common": "8.1.1-alpha.13",
30
31
  "moleculer": "^0.14.33",
31
32
  "mongoose": "^6.12.8"
32
33
  },
@@ -38,8 +39,24 @@
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
42
+ "cdecode": {
43
+ "common": {
44
+ "constants": [
45
+ "./${libDir}/templates/constants/SERVER_TYPES.ts.template"
46
+ ],
47
+ "repositories": [
48
+ "./${libDir}/templates/repositories/IBaseMongoRepository.ts.template",
49
+ "./${libDir}/templates/repositories/IBaseService.ts.template",
50
+ "./${libDir}/templates/repositories/IBaseServiceMixin.ts.template",
51
+ "./${libDir}/templates/repositories/DataLoader.ts.template",
52
+ "./${libDir}/templates/repositories/mongoCommonTypes.ts.template",
53
+ "./${libDir}/templates/repositories/dbCommonTypes.ts.template",
54
+ "./${libDir}/templates/repositories/DatabaseMigration.ts.template"
55
+ ]
56
+ }
57
+ },
58
+ "gitHead": "8cf4283c047e82372cca32e222fa576167a5fa8d",
41
59
  "typescript": {
42
60
  "definition": "lib/index.d.ts"
43
- },
44
- "gitHead": "d45864ba7429065d7b67e573e909ecf762ffc150"
61
+ }
45
62
  }
@@ -1,5 +0,0 @@
1
- var PAGINATION_OPTIONS;
2
- (function (PAGINATION_OPTIONS) {
3
- PAGINATION_OPTIONS[PAGINATION_OPTIONS["limit"] = 10] = "limit";
4
- PAGINATION_OPTIONS[PAGINATION_OPTIONS["skip"] = 0] = "skip";
5
- })(PAGINATION_OPTIONS || (PAGINATION_OPTIONS = {}));export{PAGINATION_OPTIONS};//# sourceMappingURL=base-repository.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-repository.js","sources":["../../src/interfaces/base-repository.ts"],"sourcesContent":[null],"names":[],"mappings":"IAGY,mBAGX;AAHD,CAAA,UAAY,kBAAkB,EAAA;AAC1B,IAAA,kBAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,GAAA,EAAA,CAAA,GAAA,OAAU,CAAA;AACV,IAAA,kBAAA,CAAA,kBAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ,CAAA;AACZ,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,GAG7B,EAAA,CAAA,CAAA"}
@@ -1,9 +0,0 @@
1
- import { FilterQuery } from 'mongoose';
2
- import { ISort } from 'common';
3
- export interface GetAllArgs<T> {
4
- criteria?: FilterQuery<T>;
5
- sort?: ISort;
6
- skip?: number;
7
- limit?: number;
8
- selectedFields?: string;
9
- }