@common-stack/store-mongo 6.0.8-alpha.16 → 6.0.8-alpha.2

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 (88) hide show
  1. package/lib/containers/container.d.ts +14 -0
  2. package/lib/containers/container.js +17 -0
  3. package/lib/containers/container.js.map +1 -0
  4. package/lib/containers/index.d.ts +1 -0
  5. package/lib/dataloaders/bulk-dataloader-v2.d.ts +40 -0
  6. package/lib/dataloaders/bulk-dataloader-v2.js +117 -0
  7. package/lib/dataloaders/bulk-dataloader-v2.js.map +1 -0
  8. package/lib/dataloaders/bulk-dataloader-v2.test.d.ts +1 -0
  9. package/lib/dataloaders/bulk-dataloader.d.ts +1 -1
  10. package/lib/dataloaders/bulk-dataloader.js +3 -3
  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 +253 -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 +2 -1
  20. package/lib/interfaces/dataloaders.d.ts +1 -1
  21. package/lib/interfaces/getAllArgs.d.ts +135 -0
  22. package/lib/interfaces/getAllArgs.js +39 -0
  23. package/lib/interfaces/getAllArgs.js.map +1 -0
  24. package/lib/interfaces/index.d.ts +1 -5
  25. package/lib/interfaces/index.old.d.ts +3 -0
  26. package/lib/mixins/BaseServiceMixin.d.ts +45 -0
  27. package/lib/mixins/BaseServiceMixin.js +212 -0
  28. package/lib/mixins/BaseServiceMixin.js.map +1 -0
  29. package/lib/mixins/__tests__/BaseServiceMixin.test.d.ts +1 -0
  30. package/lib/mixins/base-service-mixin.d.ts +3 -2
  31. package/lib/mixins/base-service-mixin.js +29 -29
  32. package/lib/mixins/base-service-mixin.js.map +1 -1
  33. package/lib/mixins/index.d.ts +1 -0
  34. package/lib/module.d.ts +3 -0
  35. package/lib/module.js +4 -0
  36. package/lib/module.js.map +1 -0
  37. package/lib/services/BaseProxyService.d.ts +28 -0
  38. package/lib/services/BaseProxyService.js +52 -0
  39. package/lib/services/BaseProxyService.js.map +1 -0
  40. package/lib/services/BaseService.d.ts +23 -0
  41. package/lib/services/BaseService.js +64 -0
  42. package/lib/services/BaseService.js.map +1 -0
  43. package/lib/services/BaseService.test.d.ts +1 -0
  44. package/lib/services/ConnectionPoolManager.d.ts +54 -0
  45. package/lib/services/ConnectionPoolManager.js +163 -0
  46. package/lib/services/ConnectionPoolManager.js.map +1 -0
  47. package/lib/services/base-proxy-service.d.ts +3 -1
  48. package/lib/services/base-proxy-service.js +14 -11
  49. package/lib/services/base-proxy-service.js.map +1 -1
  50. package/lib/services/base-service.d.ts +3 -2
  51. package/lib/services/base-service.js +1 -1
  52. package/lib/services/base-service.js.map +1 -1
  53. package/lib/services/index.d.ts +3 -0
  54. package/lib/store/models/common-options-v2.d.ts +16 -0
  55. package/lib/store/models/common-options-v2.js +40 -0
  56. package/lib/store/models/common-options-v2.js.map +1 -0
  57. package/lib/store/models/common-options.d.ts +21 -0
  58. package/lib/store/models/common-options.js +33 -2
  59. package/lib/store/models/common-options.js.map +1 -1
  60. package/lib/store/models/index.d.ts +1 -0
  61. package/lib/store/repositories/BaseMongoRepository.d.ts +85 -0
  62. package/lib/store/repositories/BaseMongoRepository.js +424 -0
  63. package/lib/store/repositories/BaseMongoRepository.js.map +1 -0
  64. package/lib/store/repositories/BaseMongoRepository.test.d.ts +1 -0
  65. package/lib/store/repositories/CustomIdRepository.test.d.ts +1 -0
  66. package/lib/store/repositories/base-repository.d.ts +2 -1
  67. package/lib/store/repositories/base-repository.js +1 -1
  68. package/lib/store/repositories/base-repository.js.map +1 -1
  69. package/lib/store/repositories/index.d.ts +1 -0
  70. package/lib/templates/constants/SERVER_TYPES.ts.template +7 -0
  71. package/lib/templates/repositories/DataLoader.ts.template +211 -0
  72. package/lib/templates/repositories/DatabaseMigration.ts.template +13 -0
  73. package/lib/templates/repositories/IBaseMongoRepository.ts.template +284 -0
  74. package/lib/templates/repositories/IBaseService.ts.template +231 -0
  75. package/lib/templates/repositories/IBaseServiceMixin.ts.template +477 -0
  76. package/lib/templates/repositories/dbCommonTypes.ts.template +140 -0
  77. package/lib/templates/repositories/moleculerEventHandler.ts.template.toberemoved +118 -0
  78. package/lib/templates/repositories/mongoCommonTypes.ts.template +21 -0
  79. package/lib/templates/repositories/typedMoleculerService.ts.template.toberemoved +1188 -0
  80. package/lib/templates/repositories/zodToMoleculer.ts.template.toberemoved +133 -0
  81. package/package.json +21 -4
  82. package/LICENSE +0 -21
  83. package/lib/interfaces/base-repository.js +0 -5
  84. package/lib/interfaces/base-repository.js.map +0 -1
  85. package/lib/interfaces/generated-models.d.ts +0 -148
  86. package/lib/interfaces/generated-models.js +0 -24
  87. package/lib/interfaces/generated-models.js.map +0 -1
  88. 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": "6.0.8-alpha.16",
3
+ "version": "6.0.8-alpha.2",
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,11 @@
24
24
  "watch": "npm run build:lib:watch"
25
25
  },
26
26
  "dependencies": {
27
- "@common-stack/core": "6.0.8-alpha.16"
27
+ "@common-stack/core": "link:../common-core",
28
+ "mongoose-lean-virtuals": "^0.9.1"
28
29
  },
29
30
  "devDependencies": {
31
+ "common": "link:../common",
30
32
  "moleculer": "^0.14.33",
31
33
  "mongoose": "^6.12.8"
32
34
  },
@@ -38,7 +40,22 @@
38
40
  "publishConfig": {
39
41
  "access": "public"
40
42
  },
41
- "gitHead": "49b753608c1c3cb71fbe3555a23544d7f2a87ddd",
43
+ "cdecode": {
44
+ "common": {
45
+ "constants": [
46
+ "./${libDir}/templates/constants/SERVER_TYPES.ts.template"
47
+ ],
48
+ "repositories": [
49
+ "./${libDir}/templates/repositories/IBaseMongoRepository.ts.template",
50
+ "./${libDir}/templates/repositories/IBaseService.ts.template",
51
+ "./${libDir}/templates/repositories/IBaseServiceMixin.ts.template",
52
+ "./${libDir}/templates/repositories/DataLoader.ts.template",
53
+ "./${libDir}/templates/repositories/mongoCommonTypes.ts.template",
54
+ "./${libDir}/templates/repositories/dbCommonTypes.ts.template",
55
+ "./${libDir}/templates/repositories/DatabaseMigration.ts.template"
56
+ ]
57
+ }
58
+ },
42
59
  "typescript": {
43
60
  "definition": "lib/index.d.ts"
44
61
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2017 CDMBase LLC.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -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,148 +0,0 @@
1
- export type Maybe<T> = T | null;
2
- export type InputMaybe<T> = Maybe<T>;
3
- export type Exact<T extends {
4
- [key: string]: unknown;
5
- }> = {
6
- [K in keyof T]: T[K];
7
- };
8
- export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
9
- [SubKey in K]?: Maybe<T[SubKey]>;
10
- };
11
- export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
12
- [SubKey in K]: Maybe<T[SubKey]>;
13
- };
14
- export type MakeEmpty<T extends {
15
- [key: string]: unknown;
16
- }, K extends keyof T> = {
17
- [_ in K]?: never;
18
- };
19
- export type Incremental<T> = T | {
20
- [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never;
21
- };
22
- /** All built-in and custom scalars, mapped to their actual values */
23
- export type Scalars = {
24
- ID: {
25
- input: string;
26
- output: string;
27
- };
28
- String: {
29
- input: string;
30
- output: string;
31
- };
32
- Boolean: {
33
- input: boolean;
34
- output: boolean;
35
- };
36
- Int: {
37
- input: number;
38
- output: number;
39
- };
40
- Float: {
41
- input: number;
42
- output: number;
43
- };
44
- AnyObject: {
45
- input: any;
46
- output: any;
47
- };
48
- Date: {
49
- input: any;
50
- output: any;
51
- };
52
- DateTime: {
53
- input: any;
54
- output: any;
55
- };
56
- JSON: {
57
- input: any;
58
- output: any;
59
- };
60
- JSONObject: {
61
- input: any;
62
- output: any;
63
- };
64
- Observable: {
65
- input: any;
66
- output: any;
67
- };
68
- Time: {
69
- input: any;
70
- output: any;
71
- };
72
- Timestamp: {
73
- input: any;
74
- output: any;
75
- };
76
- URI: {
77
- input: any;
78
- output: any;
79
- };
80
- URIInput: {
81
- input: any;
82
- output: any;
83
- };
84
- };
85
- export type IAdminIdeSettings = {
86
- __typename?: 'AdminIdeSettings';
87
- dummy?: Maybe<Scalars['Int']['output']>;
88
- };
89
- export declare enum IBaseServiceCommands {
90
- BulkCreate = "bulkCreate",
91
- Count = "count",
92
- Create = "create",
93
- Delete = "delete",
94
- DeleteMany = "deleteMany",
95
- Get = "get",
96
- GetAll = "getAll",
97
- GetAllWithCount = "getAllWithCount",
98
- GetByIds = "getByIds",
99
- Insert = "insert",
100
- Update = "update"
101
- }
102
- /** Represents a null return value. */
103
- export type IEmptyResponse = {
104
- __typename?: 'EmptyResponse';
105
- alwaysNil?: Maybe<Scalars['String']['output']>;
106
- };
107
- export type IFieldError = {
108
- __typename?: 'FieldError';
109
- field: Scalars['String']['output'];
110
- message: Scalars['String']['output'];
111
- };
112
- /** All Moleculer Topic names are extended from this. */
113
- export declare enum IMoleculerServiceName {
114
- Dummy = "dummy"
115
- }
116
- export type IMutation = {
117
- __typename?: 'Mutation';
118
- dummy?: Maybe<Scalars['Int']['output']>;
119
- };
120
- /** An object with an ID. */
121
- export type INode = {
122
- /** The ID of the node. */
123
- id: Scalars['ID']['output'];
124
- };
125
- export type IPageInfo = {
126
- __typename?: 'PageInfo';
127
- hasNextPage: Scalars['Boolean']['output'];
128
- };
129
- export type IQuery = {
130
- __typename?: 'Query';
131
- /** Looks up a node by ID. */
132
- node?: Maybe<INode>;
133
- };
134
- export type IQueryNodeArgs = {
135
- id: Scalars['ID']['input'];
136
- };
137
- export type ISort = {
138
- key: Scalars['String']['input'];
139
- value: ISortEnum;
140
- };
141
- export declare enum ISortEnum {
142
- Asc = "ASC",
143
- Desc = "DESC"
144
- }
145
- export type ISubscription = {
146
- __typename?: 'Subscription';
147
- dummy?: Maybe<Scalars['Int']['output']>;
148
- };
@@ -1,24 +0,0 @@
1
- var IBaseServiceCommands;
2
- (function (IBaseServiceCommands) {
3
- IBaseServiceCommands["BulkCreate"] = "bulkCreate";
4
- IBaseServiceCommands["Count"] = "count";
5
- IBaseServiceCommands["Create"] = "create";
6
- IBaseServiceCommands["Delete"] = "delete";
7
- IBaseServiceCommands["DeleteMany"] = "deleteMany";
8
- IBaseServiceCommands["Get"] = "get";
9
- IBaseServiceCommands["GetAll"] = "getAll";
10
- IBaseServiceCommands["GetAllWithCount"] = "getAllWithCount";
11
- IBaseServiceCommands["GetByIds"] = "getByIds";
12
- IBaseServiceCommands["Insert"] = "insert";
13
- IBaseServiceCommands["Update"] = "update";
14
- })(IBaseServiceCommands || (IBaseServiceCommands = {}));
15
- /** All Moleculer Topic names are extended from this. */
16
- var IMoleculerServiceName;
17
- (function (IMoleculerServiceName) {
18
- IMoleculerServiceName["Dummy"] = "dummy";
19
- })(IMoleculerServiceName || (IMoleculerServiceName = {}));
20
- var ISortEnum;
21
- (function (ISortEnum) {
22
- ISortEnum["Asc"] = "ASC";
23
- ISortEnum["Desc"] = "DESC";
24
- })(ISortEnum || (ISortEnum = {}));export{IBaseServiceCommands,IMoleculerServiceName,ISortEnum};//# sourceMappingURL=generated-models.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generated-models.js","sources":["../../src/interfaces/generated-models.ts"],"sourcesContent":[null],"names":[],"mappings":"IAgCY,qBAYX;AAZD,CAAA,UAAY,oBAAoB,EAAA;AAC9B,IAAA,oBAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB,IAAA,oBAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACf,IAAA,oBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,oBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,oBAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB,IAAA,oBAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,oBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,oBAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnC,IAAA,oBAAA,CAAA,UAAA,CAAA,GAAA,UAAqB,CAAA;AACrB,IAAA,oBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,oBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACnB,CAAC,EAZW,oBAAoB,KAApB,oBAAoB,GAY/B,EAAA,CAAA,CAAA,CAAA;AAcD;IACY,sBAEX;AAFD,CAAA,UAAY,qBAAqB,EAAA;AAC/B,IAAA,qBAAA,CAAA,OAAA,CAAA,GAAA,OAAe,CAAA;AACjB,CAAC,EAFW,qBAAqB,KAArB,qBAAqB,GAEhC,EAAA,CAAA,CAAA,CAAA;IAkCW,UAGX;AAHD,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,SAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACf,CAAC,EAHW,SAAS,KAAT,SAAS,GAGpB,EAAA,CAAA,CAAA"}
@@ -1,9 +0,0 @@
1
- import { FilterQuery } from 'mongoose';
2
- import { ISort } from './generated-models';
3
- export interface GetAllArgs<T> {
4
- criteria?: FilterQuery<T>;
5
- sort?: ISort;
6
- skip?: number;
7
- limit?: number;
8
- selectedFields?: string;
9
- }