@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.
- package/LICENSE +34 -21
- package/lib/containers/container.d.ts +14 -0
- package/lib/containers/container.js +17 -0
- package/lib/containers/container.js.map +1 -0
- package/lib/containers/index.d.ts +1 -0
- package/lib/dataloaders/bulk-dataloader-v2.d.ts +40 -0
- package/lib/dataloaders/bulk-dataloader-v2.js +118 -0
- package/lib/dataloaders/bulk-dataloader-v2.js.map +1 -0
- package/lib/dataloaders/bulk-dataloader-v2.test.d.ts +1 -0
- package/lib/dataloaders/bulk-dataloader.d.ts +1 -1
- package/lib/dataloaders/bulk-dataloader.js.map +1 -1
- package/lib/dataloaders/bulk-dataloader.test.d.ts +1 -0
- package/lib/dataloaders/index.d.ts +1 -0
- package/lib/graphql/schema/base-services.graphql +238 -0
- package/lib/helpers/mongoose-connection.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/interfaces/base-repository.d.ts +1 -5
- package/lib/interfaces/base-service.d.ts +1 -1
- package/lib/interfaces/getAllArgs.d.ts +135 -0
- package/lib/interfaces/getAllArgs.js +39 -0
- package/lib/interfaces/getAllArgs.js.map +1 -0
- package/lib/interfaces/index.d.ts +1 -4
- package/lib/interfaces/index.old.d.ts +3 -0
- package/lib/mixins/BaseServiceMixin.d.ts +45 -0
- package/lib/mixins/BaseServiceMixin.js +212 -0
- package/lib/mixins/BaseServiceMixin.js.map +1 -0
- package/lib/mixins/__tests__/BaseServiceMixin.test.d.ts +1 -0
- package/lib/mixins/base-service-mixin.js.map +1 -1
- package/lib/mixins/index.d.ts +1 -0
- package/lib/module.d.ts +2 -0
- package/lib/module.js +4 -0
- package/lib/module.js.map +1 -0
- package/lib/services/BaseProxyService.d.ts +28 -0
- package/lib/services/BaseProxyService.js +52 -0
- package/lib/services/BaseProxyService.js.map +1 -0
- package/lib/services/BaseService.d.ts +23 -0
- package/lib/services/BaseService.js +65 -0
- package/lib/services/BaseService.js.map +1 -0
- package/lib/services/BaseService.test.d.ts +1 -0
- package/lib/services/ConnectionPoolManager.d.ts +54 -0
- package/lib/services/ConnectionPoolManager.js +163 -0
- package/lib/services/ConnectionPoolManager.js.map +1 -0
- package/lib/services/base-proxy-service.d.ts +2 -1
- package/lib/services/base-proxy-service.js.map +1 -1
- package/lib/services/base-service.d.ts +2 -1
- package/lib/services/base-service.js.map +1 -1
- package/lib/services/index.d.ts +3 -0
- package/lib/store/models/common-options-v2.d.ts +16 -0
- package/lib/store/models/common-options-v2.js +40 -0
- package/lib/store/models/common-options-v2.js.map +1 -0
- package/lib/store/models/common-options.js.map +1 -1
- package/lib/store/models/index.d.ts +1 -0
- package/lib/store/repositories/BaseMongoRepository.d.ts +72 -0
- package/lib/store/repositories/BaseMongoRepository.js +423 -0
- package/lib/store/repositories/BaseMongoRepository.js.map +1 -0
- package/lib/store/repositories/BaseMongoRepository.test.d.ts +1 -0
- package/lib/store/repositories/CustomIdRepository.test.d.ts +1 -0
- package/lib/store/repositories/base-repository.d.ts +2 -1
- package/lib/store/repositories/base-repository.js +1 -1
- package/lib/store/repositories/base-repository.js.map +1 -1
- package/lib/store/repositories/index.d.ts +1 -0
- package/lib/templates/constants/SERVER_TYPES.ts.template +7 -0
- package/lib/templates/repositories/DataLoader.ts.template +211 -0
- package/lib/templates/repositories/DatabaseMigration.ts.template +13 -0
- package/lib/templates/repositories/IBaseMongoRepository.ts.template +284 -0
- package/lib/templates/repositories/IBaseService.ts.template +231 -0
- package/lib/templates/repositories/IBaseServiceMixin.ts.template +477 -0
- package/lib/templates/repositories/dbCommonTypes.ts.template +140 -0
- package/lib/templates/repositories/moleculerEventHandler.ts.template.toberemoved +118 -0
- package/lib/templates/repositories/mongoCommonTypes.ts.template +21 -0
- package/lib/templates/repositories/typedMoleculerService.ts.template.toberemoved +1188 -0
- package/lib/templates/repositories/zodToMoleculer.ts.template.toberemoved +133 -0
- package/package.json +22 -5
- package/lib/interfaces/base-repository.js +0 -5
- package/lib/interfaces/base-repository.js.map +0 -1
- package/lib/interfaces/get-all-args.d.ts +0 -9
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-all-args.ts
|
|
3
|
+
* @description Defines common types and interfaces used across the data access layer for MongoDB operations.
|
|
4
|
+
* This file contains essential type definitions that standardize how data is queried, transformed, and returned.
|
|
5
|
+
*
|
|
6
|
+
* Key components include:
|
|
7
|
+
* - GetAllArgs: Interface for pagination, sorting, and filtering when retrieving collections of documents
|
|
8
|
+
* - AsDomainType: Type transformer that converts MongoDB schema types (with _id) to domain types (with id)
|
|
9
|
+
* - GetAllWithCountResult: Type for paginated results that include both data and total count
|
|
10
|
+
* - CreateType/UpdateType: Utility types that define the shape of data for create and update operations
|
|
11
|
+
* - PAGINATION_OPTIONS: Default pagination settings used throughout the application
|
|
12
|
+
*
|
|
13
|
+
* Usage examples:
|
|
14
|
+
* 1. Retrieving paginated data:
|
|
15
|
+
* const result = await repository.getAllWithCount({ limit: 10, skip: 0, sort: { createdAt: -1 } });
|
|
16
|
+
*
|
|
17
|
+
* 2. Converting MongoDB documents to domain objects:
|
|
18
|
+
* const domainUser: AsDomainType<UserSchema> = { ...userDoc, id: userDoc._id.toString() };
|
|
19
|
+
*
|
|
20
|
+
* 3. Creating new documents with proper typing:
|
|
21
|
+
* const newUser: CreateType<UserSchema> = { name: 'John', email: 'john@example.com' };
|
|
22
|
+
*
|
|
23
|
+
* These types ensure consistency across repositories and services, providing type safety and
|
|
24
|
+
* clear contracts for data manipulation throughout the application. They form the foundation
|
|
25
|
+
* of the data access pattern used across the entire system.
|
|
26
|
+
*
|
|
27
|
+
* @see IBaseMongoRepository - Uses these types for repository operations
|
|
28
|
+
* @see IBaseService2 - Implements service methods using these types
|
|
29
|
+
* @see IDataLoader2 - Utilizes these types for efficient data loading
|
|
30
|
+
*/
|
|
31
|
+
import type { FilterQuery, ObjectId } from 'mongoose';
|
|
32
|
+
import type { ISort } from 'common';
|
|
33
|
+
/**
|
|
34
|
+
* Interface for the arguments used in the getAll method
|
|
35
|
+
*
|
|
36
|
+
* @property criteria - MongoDB filter query to narrow down results
|
|
37
|
+
* @property sort - Sorting configuration with field names and directions (1 for ascending, -1 for descending)
|
|
38
|
+
* @property skip - Number of documents to skip (for pagination)
|
|
39
|
+
* @property limit - Maximum number of documents to return (for pagination)
|
|
40
|
+
* @property selectedFields - String of space-separated field names to include in the results
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Get active users, sorted by creation date, second page with 10 items per page
|
|
44
|
+
* const options: GetAllArgs<UserSchema> = {
|
|
45
|
+
* criteria: { active: true },
|
|
46
|
+
* sort: { createdAt: -1 },
|
|
47
|
+
* skip: 10,
|
|
48
|
+
* limit: 10,
|
|
49
|
+
* selectedFields: 'name email createdAt'
|
|
50
|
+
* };
|
|
51
|
+
*/
|
|
52
|
+
export interface GetAllArgs<T> {
|
|
53
|
+
criteria?: FilterQuery<T>;
|
|
54
|
+
sort?: ISort;
|
|
55
|
+
skip?: number;
|
|
56
|
+
limit?: number;
|
|
57
|
+
selectedFields?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Type that converts a schema type with _id to a domain type with id
|
|
61
|
+
* This transformation is essential for presenting MongoDB documents as domain objects
|
|
62
|
+
* throughout the application, hiding the database-specific _id field.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // MongoDB document
|
|
66
|
+
* const userDoc = { _id: '123', name: 'John', email: 'john@example.com' };
|
|
67
|
+
*
|
|
68
|
+
* // Transformed domain object
|
|
69
|
+
* const user: AsDomainType<UserSchema> = { id: '123', name: 'John', email: 'john@example.com' };
|
|
70
|
+
*/
|
|
71
|
+
export type AsDomainType<SchemaType> = Omit<SchemaType, '_id'> & {
|
|
72
|
+
_id?: ObjectId;
|
|
73
|
+
} & {
|
|
74
|
+
id: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Type for the result of getAllWithCount
|
|
78
|
+
* Provides both the paginated data and the total count of matching documents
|
|
79
|
+
* This is used for implementing pagination UI components that need to know
|
|
80
|
+
* the total number of pages or items.
|
|
81
|
+
*
|
|
82
|
+
* @property data - Array of domain objects matching the query criteria
|
|
83
|
+
* @property totalCount - Total number of documents that match the criteria (without pagination)
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const result: GetAllWithCountResult<UserSchema> = {
|
|
87
|
+
* data: [{ id: '1', name: 'John' }, { id: '2', name: 'Jane' }],
|
|
88
|
+
* totalCount: 50
|
|
89
|
+
* };
|
|
90
|
+
*/
|
|
91
|
+
export type GetAllWithCountResult<SchemaType> = {
|
|
92
|
+
data: AsDomainType<SchemaType>[];
|
|
93
|
+
totalCount: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Default pagination settings used throughout the application
|
|
97
|
+
* These values are used when no explicit pagination parameters are provided
|
|
98
|
+
*/
|
|
99
|
+
export declare enum PAGINATION_OPTIONS {
|
|
100
|
+
limit = 10,
|
|
101
|
+
skip = 0
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Type for create operations - omits _id, id, and auto-generated fields
|
|
105
|
+
* This ensures that clients cannot specify fields that should be generated by the database
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* // Valid create operation data
|
|
109
|
+
* const newUser: CreateType<UserSchema> = {
|
|
110
|
+
* name: 'John Doe',
|
|
111
|
+
* email: 'john@example.com',
|
|
112
|
+
* role: 'user'
|
|
113
|
+
* };
|
|
114
|
+
*
|
|
115
|
+
* // The following fields will be generated automatically and should not be included:
|
|
116
|
+
* // - _id (MongoDB document ID)
|
|
117
|
+
* // - id (Domain object ID)
|
|
118
|
+
* // - createdAt (Creation timestamp)
|
|
119
|
+
* // - updatedAt (Last update timestamp)
|
|
120
|
+
*/
|
|
121
|
+
export type CreateType<SchemaType> = Omit<Partial<SchemaType>, '_id' | 'id' | 'createdAt' | 'updatedAt'>;
|
|
122
|
+
/**
|
|
123
|
+
* Type for update operations - partial of the schema without _id
|
|
124
|
+
* This allows for partial updates where only changed fields are specified
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* // Update a user's email and role
|
|
128
|
+
* const updateData: UpdateType<UserSchema> = {
|
|
129
|
+
* email: 'new.email@example.com',
|
|
130
|
+
* role: 'admin'
|
|
131
|
+
* };
|
|
132
|
+
*
|
|
133
|
+
* // Fields not specified will remain unchanged
|
|
134
|
+
*/
|
|
135
|
+
export type UpdateType<SchemaType> = Partial<Omit<SchemaType, '_id'>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-all-args.ts
|
|
3
|
+
* @description Defines common types and interfaces used across the data access layer for MongoDB operations.
|
|
4
|
+
* This file contains essential type definitions that standardize how data is queried, transformed, and returned.
|
|
5
|
+
*
|
|
6
|
+
* Key components include:
|
|
7
|
+
* - GetAllArgs: Interface for pagination, sorting, and filtering when retrieving collections of documents
|
|
8
|
+
* - AsDomainType: Type transformer that converts MongoDB schema types (with _id) to domain types (with id)
|
|
9
|
+
* - GetAllWithCountResult: Type for paginated results that include both data and total count
|
|
10
|
+
* - CreateType/UpdateType: Utility types that define the shape of data for create and update operations
|
|
11
|
+
* - PAGINATION_OPTIONS: Default pagination settings used throughout the application
|
|
12
|
+
*
|
|
13
|
+
* Usage examples:
|
|
14
|
+
* 1. Retrieving paginated data:
|
|
15
|
+
* const result = await repository.getAllWithCount({ limit: 10, skip: 0, sort: { createdAt: -1 } });
|
|
16
|
+
*
|
|
17
|
+
* 2. Converting MongoDB documents to domain objects:
|
|
18
|
+
* const domainUser: AsDomainType<UserSchema> = { ...userDoc, id: userDoc._id.toString() };
|
|
19
|
+
*
|
|
20
|
+
* 3. Creating new documents with proper typing:
|
|
21
|
+
* const newUser: CreateType<UserSchema> = { name: 'John', email: 'john@example.com' };
|
|
22
|
+
*
|
|
23
|
+
* These types ensure consistency across repositories and services, providing type safety and
|
|
24
|
+
* clear contracts for data manipulation throughout the application. They form the foundation
|
|
25
|
+
* of the data access pattern used across the entire system.
|
|
26
|
+
*
|
|
27
|
+
* @see IBaseMongoRepository - Uses these types for repository operations
|
|
28
|
+
* @see IBaseService2 - Implements service methods using these types
|
|
29
|
+
* @see IDataLoader2 - Utilizes these types for efficient data loading
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Default pagination settings used throughout the application
|
|
33
|
+
* These values are used when no explicit pagination parameters are provided
|
|
34
|
+
*/
|
|
35
|
+
var PAGINATION_OPTIONS;
|
|
36
|
+
(function (PAGINATION_OPTIONS) {
|
|
37
|
+
PAGINATION_OPTIONS[PAGINATION_OPTIONS["limit"] = 10] = "limit";
|
|
38
|
+
PAGINATION_OPTIONS[PAGINATION_OPTIONS["skip"] = 0] = "skip";
|
|
39
|
+
})(PAGINATION_OPTIONS || (PAGINATION_OPTIONS = {}));export{PAGINATION_OPTIONS};//# sourceMappingURL=getAllArgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllArgs.js","sources":["../../src/interfaces/getAllArgs.ts"],"sourcesContent":["/**\n * @file get-all-args.ts\n * @description Defines common types and interfaces used across the data access layer for MongoDB operations.\n * This file contains essential type definitions that standardize how data is queried, transformed, and returned.\n *\n * Key components include:\n * - GetAllArgs: Interface for pagination, sorting, and filtering when retrieving collections of documents\n * - AsDomainType: Type transformer that converts MongoDB schema types (with _id) to domain types (with id)\n * - GetAllWithCountResult: Type for paginated results that include both data and total count\n * - CreateType/UpdateType: Utility types that define the shape of data for create and update operations\n * - PAGINATION_OPTIONS: Default pagination settings used throughout the application\n *\n * Usage examples:\n * 1. Retrieving paginated data:\n * const result = await repository.getAllWithCount({ limit: 10, skip: 0, sort: { createdAt: -1 } });\n *\n * 2. Converting MongoDB documents to domain objects:\n * const domainUser: AsDomainType<UserSchema> = { ...userDoc, id: userDoc._id.toString() };\n *\n * 3. Creating new documents with proper typing:\n * const newUser: CreateType<UserSchema> = { name: 'John', email: 'john@example.com' };\n *\n * These types ensure consistency across repositories and services, providing type safety and\n * clear contracts for data manipulation throughout the application. They form the foundation\n * of the data access pattern used across the entire system.\n *\n * @see IBaseMongoRepository - Uses these types for repository operations\n * @see IBaseService2 - Implements service methods using these types\n * @see IDataLoader2 - Utilizes these types for efficient data loading\n */\n\nimport type { FilterQuery, ObjectId } from 'mongoose';\nimport type { ISort } from 'common';\n\n/**\n * Interface for the arguments used in the getAll method\n *\n * @property criteria - MongoDB filter query to narrow down results\n * @property sort - Sorting configuration with field names and directions (1 for ascending, -1 for descending)\n * @property skip - Number of documents to skip (for pagination)\n * @property limit - Maximum number of documents to return (for pagination)\n * @property selectedFields - String of space-separated field names to include in the results\n *\n * @example\n * // Get active users, sorted by creation date, second page with 10 items per page\n * const options: GetAllArgs<UserSchema> = {\n * criteria: { active: true },\n * sort: { createdAt: -1 },\n * skip: 10,\n * limit: 10,\n * selectedFields: 'name email createdAt'\n * };\n */\nexport interface GetAllArgs<T> {\n criteria?: FilterQuery<T>;\n sort?: ISort;\n skip?: number;\n limit?: number;\n selectedFields?: string;\n}\n\n/**\n * Type that converts a schema type with _id to a domain type with id\n * This transformation is essential for presenting MongoDB documents as domain objects\n * throughout the application, hiding the database-specific _id field.\n *\n * @example\n * // MongoDB document\n * const userDoc = { _id: '123', name: 'John', email: 'john@example.com' };\n *\n * // Transformed domain object\n * const user: AsDomainType<UserSchema> = { id: '123', name: 'John', email: 'john@example.com' };\n */\nexport type AsDomainType<SchemaType> = Omit<SchemaType, '_id'> & { _id?: ObjectId } & { id: string };\n\n/**\n * Type for the result of getAllWithCount\n * Provides both the paginated data and the total count of matching documents\n * This is used for implementing pagination UI components that need to know\n * the total number of pages or items.\n *\n * @property data - Array of domain objects matching the query criteria\n * @property totalCount - Total number of documents that match the criteria (without pagination)\n *\n * @example\n * const result: GetAllWithCountResult<UserSchema> = {\n * data: [{ id: '1', name: 'John' }, { id: '2', name: 'Jane' }],\n * totalCount: 50\n * };\n */\nexport type GetAllWithCountResult<SchemaType> = {\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n};\n\n/**\n * Default pagination settings used throughout the application\n * These values are used when no explicit pagination parameters are provided\n */\nexport enum PAGINATION_OPTIONS {\n limit = 10,\n skip = 0,\n}\n\n/**\n * Type for create operations - omits _id, id, and auto-generated fields\n * This ensures that clients cannot specify fields that should be generated by the database\n *\n * @example\n * // Valid create operation data\n * const newUser: CreateType<UserSchema> = {\n * name: 'John Doe',\n * email: 'john@example.com',\n * role: 'user'\n * };\n *\n * // The following fields will be generated automatically and should not be included:\n * // - _id (MongoDB document ID)\n * // - id (Domain object ID)\n * // - createdAt (Creation timestamp)\n * // - updatedAt (Last update timestamp)\n */\nexport type CreateType<SchemaType> = Omit<Partial<SchemaType>, '_id' | 'id' | 'createdAt' | 'updatedAt'>;\n\n/**\n * Type for update operations - partial of the schema without _id\n * This allows for partial updates where only changed fields are specified\n *\n * @example\n * // Update a user's email and role\n * const updateData: UpdateType<UserSchema> = {\n * email: 'new.email@example.com',\n * role: 'admin'\n * };\n *\n * // Fields not specified will remain unchanged\n */\nexport type UpdateType<SchemaType> = Partial<Omit<SchemaType, '_id'>>;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AAkEH;;;AAGG;IACS,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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file BaseServiceMixin.ts
|
|
3
|
+
* @description Provides a mixin function that adds standardized service methods to Moleculer service schemas.
|
|
4
|
+
* This mixin implements the IBaseService interface and connects it to Moleculer's service framework,
|
|
5
|
+
* creating action handlers for all standard service operations.
|
|
6
|
+
*
|
|
7
|
+
* The mixin pattern allows for composable service functionality, where multiple mixins can be combined
|
|
8
|
+
* to create feature-rich services without code duplication. This particular mixin handles the core CRUD
|
|
9
|
+
* operations and emits events when data changes.
|
|
10
|
+
*
|
|
11
|
+
* Key features:
|
|
12
|
+
* - Automatic action creation for all IBaseService methods
|
|
13
|
+
* - Event emission for data changes (create, update, delete)
|
|
14
|
+
* - Parameter validation for all actions
|
|
15
|
+
* - Consistent error handling
|
|
16
|
+
* - Type safety through generics
|
|
17
|
+
*
|
|
18
|
+
* @see IBaseService - The interface this mixin implements
|
|
19
|
+
* @see IBaseMongoRepository - The repository interface used for data access
|
|
20
|
+
*/
|
|
21
|
+
import { ServiceBroker, ServiceSchema } from 'moleculer';
|
|
22
|
+
import { IBaseService, BaseServiceCommands } from 'common';
|
|
23
|
+
/**
|
|
24
|
+
* Creates a mixin that implements the IBaseService interface as Moleculer actions
|
|
25
|
+
*
|
|
26
|
+
* @param service - Implementation of IBaseService that will handle the actual business logic
|
|
27
|
+
* @param broker - Moleculer service broker for event emission
|
|
28
|
+
* @param name - Service name used for event naming
|
|
29
|
+
* @param events - List of operations that should emit events
|
|
30
|
+
* @returns A partial ServiceSchema that can be merged with other service definitions
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Create a user service with the base service mixin
|
|
34
|
+
* const UserService: ServiceSchema = {
|
|
35
|
+
* name: "users",
|
|
36
|
+
* mixins: [
|
|
37
|
+
* BaseServiceMixin(userService, broker, "users")
|
|
38
|
+
* ],
|
|
39
|
+
* // Additional service-specific actions and methods
|
|
40
|
+
* actions: {
|
|
41
|
+
* changePassword: { ... }
|
|
42
|
+
* }
|
|
43
|
+
* };
|
|
44
|
+
*/
|
|
45
|
+
export declare const BaseServiceMixin: <T>(service: IBaseService<T>, broker?: ServiceBroker, name?: string, events?: BaseServiceCommands[]) => Partial<ServiceSchema>;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {upperFirst}from'lodash-es';import {BaseServiceCommands}from'common';/**
|
|
2
|
+
* @file BaseServiceMixin.ts
|
|
3
|
+
* @description Provides a mixin function that adds standardized service methods to Moleculer service schemas.
|
|
4
|
+
* This mixin implements the IBaseService interface and connects it to Moleculer's service framework,
|
|
5
|
+
* creating action handlers for all standard service operations.
|
|
6
|
+
*
|
|
7
|
+
* The mixin pattern allows for composable service functionality, where multiple mixins can be combined
|
|
8
|
+
* to create feature-rich services without code duplication. This particular mixin handles the core CRUD
|
|
9
|
+
* operations and emits events when data changes.
|
|
10
|
+
*
|
|
11
|
+
* Key features:
|
|
12
|
+
* - Automatic action creation for all IBaseService methods
|
|
13
|
+
* - Event emission for data changes (create, update, delete)
|
|
14
|
+
* - Parameter validation for all actions
|
|
15
|
+
* - Consistent error handling
|
|
16
|
+
* - Type safety through generics
|
|
17
|
+
*
|
|
18
|
+
* @see IBaseService - The interface this mixin implements
|
|
19
|
+
* @see IBaseMongoRepository - The repository interface used for data access
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Default events that will trigger event emissions when data changes
|
|
23
|
+
* Services can customize this list to control which operations emit events
|
|
24
|
+
*/
|
|
25
|
+
const defaultEvents = [
|
|
26
|
+
BaseServiceCommands.Create,
|
|
27
|
+
BaseServiceCommands.BulkCreate,
|
|
28
|
+
BaseServiceCommands.Update,
|
|
29
|
+
BaseServiceCommands.Delete,
|
|
30
|
+
BaseServiceCommands.DeleteMany,
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Creates a mixin that implements the IBaseService interface as Moleculer actions
|
|
34
|
+
*
|
|
35
|
+
* @param service - Implementation of IBaseService that will handle the actual business logic
|
|
36
|
+
* @param broker - Moleculer service broker for event emission
|
|
37
|
+
* @param name - Service name used for event naming
|
|
38
|
+
* @param events - List of operations that should emit events
|
|
39
|
+
* @returns A partial ServiceSchema that can be merged with other service definitions
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Create a user service with the base service mixin
|
|
43
|
+
* const UserService: ServiceSchema = {
|
|
44
|
+
* name: "users",
|
|
45
|
+
* mixins: [
|
|
46
|
+
* BaseServiceMixin(userService, broker, "users")
|
|
47
|
+
* ],
|
|
48
|
+
* // Additional service-specific actions and methods
|
|
49
|
+
* actions: {
|
|
50
|
+
* changePassword: { ... }
|
|
51
|
+
* }
|
|
52
|
+
* };
|
|
53
|
+
*/
|
|
54
|
+
const BaseServiceMixin = (service, broker, name, events = defaultEvents) => ({
|
|
55
|
+
name: 'BaseServiceMixin',
|
|
56
|
+
actions: {
|
|
57
|
+
/**
|
|
58
|
+
* Get a single document by ID
|
|
59
|
+
*/
|
|
60
|
+
[BaseServiceCommands.Get]: {
|
|
61
|
+
params: {
|
|
62
|
+
id: 'string',
|
|
63
|
+
},
|
|
64
|
+
handler: async (ctx) => service.get({ id: ctx.params.id }),
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Get multiple documents by their IDs
|
|
68
|
+
*/
|
|
69
|
+
[BaseServiceCommands.GetByIds]: {
|
|
70
|
+
params: {
|
|
71
|
+
ids: {
|
|
72
|
+
type: 'array',
|
|
73
|
+
items: 'string',
|
|
74
|
+
optional: false,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
handler: async (ctx) => service.getByIds(ctx.params.ids),
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Count documents matching criteria
|
|
81
|
+
*/
|
|
82
|
+
[BaseServiceCommands.Count]: {
|
|
83
|
+
params: {
|
|
84
|
+
criteria: { type: 'object', optional: true },
|
|
85
|
+
},
|
|
86
|
+
handler: async (ctx) => service.count(ctx.params.criteria),
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Create multiple documents
|
|
90
|
+
*/
|
|
91
|
+
[BaseServiceCommands.BulkCreate]: {
|
|
92
|
+
params: {
|
|
93
|
+
data: { type: 'array', items: 'object' },
|
|
94
|
+
},
|
|
95
|
+
handler: async (ctx) => {
|
|
96
|
+
const response = await service.bulkCreate(ctx.params.data);
|
|
97
|
+
if (events.includes(BaseServiceCommands.BulkCreate)) {
|
|
98
|
+
await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.BulkCreate)}`, response);
|
|
99
|
+
}
|
|
100
|
+
return response;
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Create a single document
|
|
105
|
+
*/
|
|
106
|
+
[BaseServiceCommands.Create]: {
|
|
107
|
+
params: {
|
|
108
|
+
data: 'object',
|
|
109
|
+
},
|
|
110
|
+
handler: async (ctx) => {
|
|
111
|
+
const response = await service.create(ctx.params.data);
|
|
112
|
+
if (events.includes(BaseServiceCommands.Create)) {
|
|
113
|
+
await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Create)}`, response);
|
|
114
|
+
}
|
|
115
|
+
return response;
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Delete a document by ID
|
|
120
|
+
*/
|
|
121
|
+
[BaseServiceCommands.Delete]: {
|
|
122
|
+
params: {
|
|
123
|
+
id: 'string',
|
|
124
|
+
},
|
|
125
|
+
handler: async (ctx) => {
|
|
126
|
+
const { id } = ctx.params;
|
|
127
|
+
const response = await service.delete({ id });
|
|
128
|
+
if (events.includes(BaseServiceCommands.Delete)) {
|
|
129
|
+
await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Delete)}`, { id });
|
|
130
|
+
}
|
|
131
|
+
return response;
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Get documents with pagination
|
|
136
|
+
*/
|
|
137
|
+
[BaseServiceCommands.GetAll]: {
|
|
138
|
+
params: {
|
|
139
|
+
criteria: 'object|optional',
|
|
140
|
+
sort: 'object|optional',
|
|
141
|
+
skip: 'number|optional',
|
|
142
|
+
limit: 'number|optional',
|
|
143
|
+
selectedFields: 'string|optional',
|
|
144
|
+
},
|
|
145
|
+
handler: async (ctx) => service.getAll(ctx.params),
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* Get documents with pagination and total count
|
|
149
|
+
*/
|
|
150
|
+
[BaseServiceCommands.GetAllWithCount]: {
|
|
151
|
+
params: {
|
|
152
|
+
criteria: 'object|optional',
|
|
153
|
+
sort: 'object|optional',
|
|
154
|
+
skip: 'number|optional',
|
|
155
|
+
limit: 'number|optional',
|
|
156
|
+
selectedFields: 'string|optional',
|
|
157
|
+
},
|
|
158
|
+
handler: async (ctx) => service.getAllWithCount(ctx.params),
|
|
159
|
+
},
|
|
160
|
+
/**
|
|
161
|
+
* Create or update a document
|
|
162
|
+
*/
|
|
163
|
+
[BaseServiceCommands.Insert]: {
|
|
164
|
+
params: {
|
|
165
|
+
data: 'object',
|
|
166
|
+
overwrite: 'boolean|optional',
|
|
167
|
+
},
|
|
168
|
+
handler: async (ctx) => {
|
|
169
|
+
const { data } = ctx.params;
|
|
170
|
+
const response = await service.insert(data, ctx.params.overwrite);
|
|
171
|
+
const action = data?.id ? BaseServiceCommands.Update : BaseServiceCommands.Create;
|
|
172
|
+
if (events.includes(action)) {
|
|
173
|
+
await broker?.emit(`${name}.on${upperFirst(action)}`, response);
|
|
174
|
+
}
|
|
175
|
+
return response;
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* Update a document by ID
|
|
180
|
+
*/
|
|
181
|
+
[BaseServiceCommands.Update]: {
|
|
182
|
+
params: {
|
|
183
|
+
id: 'string',
|
|
184
|
+
data: 'object',
|
|
185
|
+
overwrite: 'boolean|optional',
|
|
186
|
+
},
|
|
187
|
+
handler: async (ctx) => {
|
|
188
|
+
const response = await service.update(ctx.params.id, ctx.params.data, ctx.params.overwrite);
|
|
189
|
+
if (events.includes(BaseServiceCommands.Update)) {
|
|
190
|
+
await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Update)}`, response);
|
|
191
|
+
}
|
|
192
|
+
return response;
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* Delete multiple documents matching criteria
|
|
197
|
+
*/
|
|
198
|
+
[BaseServiceCommands.DeleteMany]: {
|
|
199
|
+
params: {
|
|
200
|
+
criteria: 'object',
|
|
201
|
+
},
|
|
202
|
+
handler: async (ctx) => {
|
|
203
|
+
const { criteria } = ctx.params;
|
|
204
|
+
const response = await service.delete(criteria);
|
|
205
|
+
if (events.includes(BaseServiceCommands.DeleteMany)) {
|
|
206
|
+
await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.DeleteMany)}`, criteria);
|
|
207
|
+
}
|
|
208
|
+
return response;
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
});export{BaseServiceMixin};//# sourceMappingURL=BaseServiceMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseServiceMixin.js","sources":["../../src/mixins/BaseServiceMixin.ts"],"sourcesContent":["/**\n * @file BaseServiceMixin.ts\n * @description Provides a mixin function that adds standardized service methods to Moleculer service schemas.\n * This mixin implements the IBaseService interface and connects it to Moleculer's service framework,\n * creating action handlers for all standard service operations.\n *\n * The mixin pattern allows for composable service functionality, where multiple mixins can be combined\n * to create feature-rich services without code duplication. This particular mixin handles the core CRUD\n * operations and emits events when data changes.\n *\n * Key features:\n * - Automatic action creation for all IBaseService methods\n * - Event emission for data changes (create, update, delete)\n * - Parameter validation for all actions\n * - Consistent error handling\n * - Type safety through generics\n *\n * @see IBaseService - The interface this mixin implements\n * @see IBaseMongoRepository - The repository interface used for data access\n */\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport { Context, ServiceBroker, ServiceSchema } from 'moleculer';\nimport { Document, FilterQuery } from 'mongoose';\nimport { upperFirst } from 'lodash-es';\nimport { GetAllArgs, IBaseService, BaseServiceCommands } from 'common';\n\n/**\n * Default events that will trigger event emissions when data changes\n * Services can customize this list to control which operations emit events\n */\nconst defaultEvents = [\n BaseServiceCommands.Create,\n BaseServiceCommands.BulkCreate,\n BaseServiceCommands.Update,\n BaseServiceCommands.Delete,\n BaseServiceCommands.DeleteMany,\n];\n\n/**\n * Creates a mixin that implements the IBaseService interface as Moleculer actions\n *\n * @param service - Implementation of IBaseService that will handle the actual business logic\n * @param broker - Moleculer service broker for event emission\n * @param name - Service name used for event naming\n * @param events - List of operations that should emit events\n * @returns A partial ServiceSchema that can be merged with other service definitions\n *\n * @example\n * // Create a user service with the base service mixin\n * const UserService: ServiceSchema = {\n * name: \"users\",\n * mixins: [\n * BaseServiceMixin(userService, broker, \"users\")\n * ],\n * // Additional service-specific actions and methods\n * actions: {\n * changePassword: { ... }\n * }\n * };\n */\nexport const BaseServiceMixin = <T>(\n service: IBaseService<T>,\n broker?: ServiceBroker,\n name?: string,\n events = defaultEvents,\n): Partial<ServiceSchema> => ({\n name: 'BaseServiceMixin',\n actions: {\n /**\n * Get a single document by ID\n */\n [BaseServiceCommands.Get]: {\n params: {\n id: 'string',\n },\n handler: async (ctx: Context<{ id: string }>) =>\n service.get({ id: ctx.params.id } as FilterQuery<Document<T>>),\n },\n\n /**\n * Get multiple documents by their IDs\n */\n [BaseServiceCommands.GetByIds]: {\n params: {\n ids: {\n type: 'array',\n items: 'string',\n optional: false,\n },\n },\n handler: async (ctx: Context<{ ids: string[] }>) => service.getByIds(ctx.params.ids),\n },\n\n /**\n * Count documents matching criteria\n */\n [BaseServiceCommands.Count]: {\n params: {\n criteria: { type: 'object', optional: true },\n },\n handler: async (ctx: Context<{ criteria?: FilterQuery<Document<T>> }>) =>\n service.count(ctx.params.criteria),\n },\n\n /**\n * Create multiple documents\n */\n [BaseServiceCommands.BulkCreate]: {\n params: {\n data: { type: 'array', items: 'object' },\n },\n handler: async (ctx: Context<{ data: never[] }>) => {\n const response = await service.bulkCreate(ctx.params.data);\n if (events.includes(BaseServiceCommands.BulkCreate)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.BulkCreate)}`, response);\n }\n return response;\n },\n },\n\n /**\n * Create a single document\n */\n [BaseServiceCommands.Create]: {\n params: {\n data: 'object',\n },\n handler: async (ctx: Context<{ data: never }>) => {\n const response = await service.create(ctx.params.data);\n if (events.includes(BaseServiceCommands.Create)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Create)}`, response);\n }\n return response;\n },\n },\n\n /**\n * Delete a document by ID\n */\n [BaseServiceCommands.Delete]: {\n params: {\n id: 'string',\n },\n handler: async (ctx: Context<{ id: string }>) => {\n const { id } = ctx.params;\n const response = await service.delete({ id } as FilterQuery<Document<T>>);\n if (events.includes(BaseServiceCommands.Delete)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Delete)}`, { id });\n }\n return response;\n },\n },\n\n /**\n * Get documents with pagination\n */\n [BaseServiceCommands.GetAll]: {\n params: {\n criteria: 'object|optional',\n sort: 'object|optional',\n skip: 'number|optional',\n limit: 'number|optional',\n selectedFields: 'string|optional',\n },\n handler: async (ctx: Context<GetAllArgs<Document<T>>>) => service.getAll(ctx.params),\n },\n\n /**\n * Get documents with pagination and total count\n */\n [BaseServiceCommands.GetAllWithCount]: {\n params: {\n criteria: 'object|optional',\n sort: 'object|optional',\n skip: 'number|optional',\n limit: 'number|optional',\n selectedFields: 'string|optional',\n },\n handler: async (ctx: Context<GetAllArgs<Document<T>>>) => service.getAllWithCount(ctx.params),\n },\n\n /**\n * Create or update a document\n */\n [BaseServiceCommands.Insert]: {\n params: {\n data: 'object',\n overwrite: 'boolean|optional',\n },\n handler: async (ctx: Context<{ data: never & { id?: string }; overwrite: boolean }>) => {\n const { data } = ctx.params;\n const response = await service.insert(data, ctx.params.overwrite);\n const action = (data as { id: string })?.id ? BaseServiceCommands.Update : BaseServiceCommands.Create;\n if (events.includes(action)) {\n await broker?.emit(`${name}.on${upperFirst(action)}`, response);\n }\n return response;\n },\n },\n\n /**\n * Update a document by ID\n */\n [BaseServiceCommands.Update]: {\n params: {\n id: 'string',\n data: 'object',\n overwrite: 'boolean|optional',\n },\n handler: async (ctx: Context<{ id: string; data: never; overwrite: boolean }>) => {\n const response = await service.update(ctx.params.id, ctx.params.data, ctx.params.overwrite);\n if (events.includes(BaseServiceCommands.Update)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Update)}`, response);\n }\n return response;\n },\n },\n\n /**\n * Delete multiple documents matching criteria\n */\n [BaseServiceCommands.DeleteMany]: {\n params: {\n criteria: 'object',\n },\n handler: async (ctx: Context<{ criteria: FilterQuery<Document<T>> }>) => {\n const { criteria } = ctx.params;\n const response = await service.delete(criteria);\n if (events.includes(BaseServiceCommands.DeleteMany)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.DeleteMany)}`, criteria);\n }\n return response;\n },\n },\n },\n});\n"],"names":[],"mappings":"4EAAA;;;;;;;;;;;;;;;;;;;AAmBG;AAQH;;;AAGG;AACH,MAAM,aAAa,GAAG;AAClB,IAAA,mBAAmB,CAAC,MAAM;AAC1B,IAAA,mBAAmB,CAAC,UAAU;AAC9B,IAAA,mBAAmB,CAAC,MAAM;AAC1B,IAAA,mBAAmB,CAAC,MAAM;AAC1B,IAAA,mBAAmB,CAAC,UAAU;CACjC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;AAqBG;AACU,MAAA,gBAAgB,GAAG,CAC5B,OAAwB,EACxB,MAAsB,EACtB,IAAa,EACb,MAAM,GAAG,aAAa,MACI;AAC1B,IAAA,IAAI,EAAE,kBAAkB;AACxB,IAAA,OAAO,EAAE;AACL;;AAEG;AACH,QAAA,CAAC,mBAAmB,CAAC,GAAG,GAAG;AACvB,YAAA,MAAM,EAAE;AACJ,gBAAA,EAAE,EAAE,QAAQ;AACf,aAAA;YACD,OAAO,EAAE,OAAO,GAA4B,KACxC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,EAA8B,CAAC;AACrE,SAAA;AAED;;A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U,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;iBACvF;AACD,gBAAA,OAAO,QAAQ,CAAC;aACnB;AACJ,SAAA;AACD,QAAA,CAAC,mBAAmB,CAAC,UAAU,GAAG;AAC9B,YAAA,MAAM,EAAE;AACJ,gBAAA,QAAQ,EAAE,QAAQ;AACrB,aAAA;AACD,YAAA,OAAO,EAAE,OAAO,GAA0B,KAAI;AAC1C,gBAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;gBAChC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAChD,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE;AACjD,oBAAA,MAAM,MAAM,EAAE,IAAI,CAAC,CAAA,EAAG,IAAI,CAAM,GAAA,EAAA,UAAU,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;iBAC3F;AACD,gBAAA,OAAO,QAAQ,CAAC;aACnB;AACJ,SAAA;AACJ,KAAA;AACJ,CAAA"}
|
|
1
|
+
{"version":3,"file":"base-service-mixin.js","sources":["../../src/mixins/base-service-mixin.ts"],"sourcesContent":["import { Context, ServiceBroker, ServiceSchema } from 'moleculer';\nimport { Document, FilterQuery } from 'mongoose';\nimport { upperFirst } from 'lodash-es';\nimport { BaseServiceCommands } from 'common';\nimport { GetAllArgs, IBaseService } from '../interfaces';\n\nconst defaultEvents = [\n BaseServiceCommands.Create,\n BaseServiceCommands.BulkCreate,\n BaseServiceCommands.Update,\n BaseServiceCommands.Delete,\n BaseServiceCommands.DeleteMany,\n];\n\nexport const BaseServiceMixin = <T, C, U>(\n service: IBaseService<T, C, U>,\n broker?: ServiceBroker,\n name?: string,\n events = defaultEvents,\n): Partial<ServiceSchema> => ({\n name: 'BaseServiceMixin',\n actions: {\n [BaseServiceCommands.Get]: {\n params: {\n id: 'string',\n },\n handler: async (ctx: Context<{ id: string }>) => service.get(ctx.params.id),\n },\n [BaseServiceCommands.Count]: {\n params: {\n criteria: { type: 'object', optional: true },\n },\n handler: async (ctx: Context<{ criteria?: FilterQuery<Document<T>> }>) =>\n service.count(ctx.params.criteria),\n },\n [BaseServiceCommands.BulkCreate]: {\n params: {\n data: { type: 'array', items: 'object' },\n },\n handler: async (ctx: Context<{ data: never[] }>) => {\n const response = await service.bulkCreate(ctx.params.data);\n if (events.includes(BaseServiceCommands.BulkCreate)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.BulkCreate)}`, response);\n }\n return response;\n },\n },\n [BaseServiceCommands.Create]: {\n params: {\n data: 'object',\n },\n handler: async (ctx: Context<{ data: never }>) => {\n const response = await service.create(ctx.params.data);\n if (events.includes(BaseServiceCommands.Create)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Create)}`, response);\n }\n return response;\n },\n },\n [BaseServiceCommands.Delete]: {\n params: {\n id: 'string',\n },\n handler: async (ctx: Context<{ id: string | FilterQuery<Document<T>> }>) => {\n const { id } = ctx.params;\n const response = await service.delete(id as never);\n if (events.includes(BaseServiceCommands.Delete)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Delete)}`, { id });\n }\n return response;\n },\n },\n [BaseServiceCommands.GetAll]: {\n params: {\n criteria: 'object|optional',\n sort: 'object|optional',\n skip: 'number|optional',\n limit: 'number|optional',\n selectedFields: 'string|optional',\n },\n handler: async (ctx: Context<GetAllArgs<Document<T>>>) => service.getAll(ctx.params),\n },\n [BaseServiceCommands.GetAllWithCount]: {\n params: {\n criteria: 'object|optional',\n sort: 'object|optional',\n skip: 'number|optional',\n limit: 'number|optional',\n selectedFields: 'string|optional',\n },\n handler: async (ctx: Context<GetAllArgs<Document<T>>>) => service.getAllWithCount(ctx.params),\n },\n [BaseServiceCommands.Insert]: {\n params: {\n data: 'object',\n overwrite: 'boolean|optional',\n },\n handler: async (ctx: Context<{ data: never & { id?: string }; overwrite: boolean }>) => {\n const { data } = ctx.params;\n const response = await service.insert(data, ctx.params.overwrite);\n const action = (data as { id: string })?.id ? BaseServiceCommands.Update : BaseServiceCommands.Create;\n if (events.includes(action)) {\n await broker?.emit(`${name}.on${upperFirst(action)}`, response);\n }\n return response;\n },\n },\n [BaseServiceCommands.Update]: {\n params: {\n id: 'string',\n data: 'object',\n overwrite: 'boolean|optional',\n },\n handler: async (ctx: Context<{ id: string; data: never; overwrite: boolean }>) => {\n const response = await service.update(ctx.params.id, ctx.params.data, ctx.params.overwrite);\n if (events.includes(BaseServiceCommands.Update)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.Update)}`, response);\n }\n return response;\n },\n },\n [BaseServiceCommands.DeleteMany]: {\n params: {\n criteria: 'object',\n },\n handler: async (ctx: Context<{ criteria }>) => {\n const { criteria } = ctx.params;\n const response = await service.delete(criteria);\n if (events.includes(BaseServiceCommands.DeleteMany)) {\n await broker?.emit(`${name}.on${upperFirst(BaseServiceCommands.DeleteMany)}`, criteria);\n }\n return response;\n },\n },\n },\n});\n"],"names":[],"mappings":"4EAMA,MAAM,aAAa,GAAG;AAClB,IAAA,mBAAmB,CAAC,MAAM;AAC1B,IAAA,mBAAmB,CAAC,UAAU;AAC9B,IAAA,mBAAmB,CAAC,MAAM;AAC1B,IAAA,mBAAmB,CAAC,MAAM;AAC1B,IAAA,mBAAmB,CAAC,UAAU;CACjC,CAAC;AAEW,MAAA,gBAAgB,GAAG,CAC5B,OAA8B,EAC9B,MAAsB,EACtB,IAAa,EACb,MAAM,GAAG,aAAa,MACI;AAC1B,IAAA,IAAI,EAAE,kBAAkB;AACxB,IAAA,OAAO,EAAE;AACL,QAAA,CAAC,mBAAmB,CAAC,GAAG,GAAG;AACvB,YAAA,MAAM,EAAE;AACJ,gBAAA,EAAE,EAAE,QAAQ;AACf,aAAA;AACD,YAAA,OAAO,EAAE,OAAO,GAA4B,KAAK,OAAO,CAAC,GAAG,CAAC,G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AAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAC5F,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE;AAC7C,oBAAA,MAAM,MAAM,EAAE,IAAI,CAAC,CAAA,EAAG,IAAI,CAAM,GAAA,EAAA,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;iBACvF;AACD,gBAAA,OAAO,QAAQ,CAAC;aACnB;AACJ,SAAA;AACD,QAAA,CAAC,mBAAmB,CAAC,UAAU,GAAG;AAC9B,YAAA,MAAM,EAAE;AACJ,gBAAA,QAAQ,EAAE,QAAQ;AACrB,aAAA;AACD,YAAA,OAAO,EAAE,OAAO,GAA0B,KAAI;AAC1C,gBAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;gBAChC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAChD,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE;AACjD,oBAAA,MAAM,MAAM,EAAE,IAAI,CAAC,CAAA,EAAG,IAAI,CAAM,GAAA,EAAA,UAAU,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;iBAC3F;AACD,gBAAA,OAAO,QAAQ,CAAC;aACnB;AACJ,SAAA;AACJ,KAAA;AACJ,CAAA"}
|
package/lib/mixins/index.d.ts
CHANGED
package/lib/module.d.ts
ADDED
package/lib/module.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {Feature}from'@common-stack/server-core';import {localContainerModule,externalContainerModule}from'./containers/container.js';var module = new Feature({
|
|
2
|
+
createContainerFunc: [localContainerModule],
|
|
3
|
+
createMicroServiceContainerFunc: [externalContainerModule],
|
|
4
|
+
});export{module as default};//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sources":["../src/module.ts"],"sourcesContent":["import { Feature } from '@common-stack/server-core';\nimport { externalContainerModule, localContainerModule } from './containers';\n\nexport default new Feature({\n createContainerFunc: [localContainerModule],\n createMicroServiceContainerFunc: [externalContainerModule],\n});\n"],"names":[],"mappings":"qIAGA,aAAe,IAAI,OAAO,CAAC;IACvB,mBAAmB,EAAE,CAAC,oBAAoB,CAAC;IAC3C,+BAA+B,EAAE,CAAC,uBAAuB,CAAC;AAC7D,CAAA,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ServiceBroker } from 'moleculer';
|
|
2
|
+
import { FilterQuery } from 'mongoose';
|
|
3
|
+
import { CdmLogger } from '@cdm-logger/core';
|
|
4
|
+
import { GetAllArgs, IBaseService, AsDomainType, CreateType, UpdateType } from 'common/server';
|
|
5
|
+
export declare abstract class BaseProxyService2<SchemaType> implements IBaseService<SchemaType> {
|
|
6
|
+
protected readonly broker: ServiceBroker;
|
|
7
|
+
protected abstract logger?: CdmLogger.ILogger;
|
|
8
|
+
protected abstract topic: string;
|
|
9
|
+
constructor(broker: ServiceBroker, logger: CdmLogger.ILogger);
|
|
10
|
+
getByName(name: string): Promise<AsDomainType<SchemaType> | null>;
|
|
11
|
+
bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]>;
|
|
12
|
+
count(criteria?: FilterQuery<SchemaType>): Promise<number>;
|
|
13
|
+
create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>>;
|
|
14
|
+
delete(id: string | FilterQuery<SchemaType>): Promise<boolean>;
|
|
15
|
+
bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number>;
|
|
16
|
+
get(id?: string | FilterQuery<SchemaType>): Promise<AsDomainType<SchemaType> | null>;
|
|
17
|
+
getAll(options?: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]>;
|
|
18
|
+
getByIds(ids: string[]): Promise<AsDomainType<SchemaType>[]>;
|
|
19
|
+
getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{
|
|
20
|
+
data: AsDomainType<SchemaType>[];
|
|
21
|
+
totalCount: number;
|
|
22
|
+
}>;
|
|
23
|
+
insert<T = CreateType<SchemaType>>(data: T & {
|
|
24
|
+
id?: string;
|
|
25
|
+
}, overwrite?: boolean): Promise<AsDomainType<SchemaType>>;
|
|
26
|
+
update<T = UpdateType<SchemaType>>(id: string, data: T, overwrite?: boolean): Promise<AsDomainType<SchemaType>>;
|
|
27
|
+
protected callAction<T, P = unknown>(command: string, params?: P): Promise<T>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {__decorate,__param,__metadata}from'tslib';import {injectable,inject,optional}from'inversify';import {ServiceBroker}from'moleculer';import'@cdm-logger/core';import {CommonType}from'@common-stack/core';import {BaseServiceCommands}from'common/server';let BaseProxyService2 = class BaseProxyService2 {
|
|
2
|
+
broker;
|
|
3
|
+
constructor(broker, logger) {
|
|
4
|
+
this.broker = broker;
|
|
5
|
+
}
|
|
6
|
+
getByName(name) {
|
|
7
|
+
return this.callAction(BaseServiceCommands.GetByName, { name });
|
|
8
|
+
}
|
|
9
|
+
bulkCreate(data) {
|
|
10
|
+
return this.callAction(BaseServiceCommands.BulkCreate, { data });
|
|
11
|
+
}
|
|
12
|
+
count(criteria) {
|
|
13
|
+
return this.callAction(BaseServiceCommands.Count, { criteria });
|
|
14
|
+
}
|
|
15
|
+
create(data) {
|
|
16
|
+
return this.callAction(BaseServiceCommands.Create, { data });
|
|
17
|
+
}
|
|
18
|
+
delete(id) {
|
|
19
|
+
return this.callAction(BaseServiceCommands.Delete, { id });
|
|
20
|
+
}
|
|
21
|
+
bulkDelete(criteria) {
|
|
22
|
+
return this.callAction(BaseServiceCommands.BulkDelete, { criteria });
|
|
23
|
+
}
|
|
24
|
+
get(id) {
|
|
25
|
+
return this.callAction(BaseServiceCommands.Get, { id });
|
|
26
|
+
}
|
|
27
|
+
getAll(options) {
|
|
28
|
+
return this.callAction(BaseServiceCommands.GetAll, options);
|
|
29
|
+
}
|
|
30
|
+
getByIds(ids) {
|
|
31
|
+
return this.callAction(BaseServiceCommands.GetByIds, { ids });
|
|
32
|
+
}
|
|
33
|
+
getAllWithCount(options) {
|
|
34
|
+
return this.callAction(BaseServiceCommands.GetAllWithCount, options);
|
|
35
|
+
}
|
|
36
|
+
insert(data, overwrite) {
|
|
37
|
+
return this.callAction(BaseServiceCommands.Insert, { data, overwrite });
|
|
38
|
+
}
|
|
39
|
+
update(id, data, overwrite) {
|
|
40
|
+
return this.callAction(BaseServiceCommands.Update, { id, data, overwrite });
|
|
41
|
+
}
|
|
42
|
+
async callAction(command, params) {
|
|
43
|
+
return this.broker.call(`${this.topic}.${command}`, params);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
BaseProxyService2 = __decorate([
|
|
47
|
+
injectable(),
|
|
48
|
+
__param(0, inject(CommonType.MOLECULER_BROKER)),
|
|
49
|
+
__param(1, inject(CommonType.LOGGER)),
|
|
50
|
+
__param(1, optional()),
|
|
51
|
+
__metadata("design:paramtypes", [ServiceBroker, Object])
|
|
52
|
+
], BaseProxyService2);export{BaseProxyService2};//# sourceMappingURL=BaseProxyService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseProxyService.js","sources":["../../src/services/BaseProxyService.ts"],"sourcesContent":["/* eslint-disable import/no-unresolved */\n/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable no-useless-constructor */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-empty-function */\nimport { inject, injectable, optional } from 'inversify';\nimport { ServiceBroker } from 'moleculer';\nimport { FilterQuery } from 'mongoose';\nimport { CdmLogger } from '@cdm-logger/core';\nimport { CommonType } from '@common-stack/core';\nimport { GetAllArgs, IBaseService, AsDomainType, CreateType, UpdateType, BaseServiceCommands } from 'common/server';\n\n@injectable()\nexport abstract class BaseProxyService2<SchemaType> implements IBaseService<SchemaType> {\n protected abstract logger?: CdmLogger.ILogger;\n\n protected abstract topic: string;\n\n constructor(\n @inject(CommonType.MOLECULER_BROKER)\n protected readonly broker: ServiceBroker,\n @inject(CommonType.LOGGER)\n @optional()\n logger: CdmLogger.ILogger,\n ) {}\n\n getByName(name: string): Promise<AsDomainType<SchemaType> | null> {\n return this.callAction(BaseServiceCommands.GetByName, { name });\n }\n\n bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]> {\n return this.callAction(BaseServiceCommands.BulkCreate, { data });\n }\n\n count(criteria?: FilterQuery<SchemaType>): Promise<number> {\n return this.callAction(BaseServiceCommands.Count, { criteria });\n }\n\n create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>> {\n return this.callAction(BaseServiceCommands.Create, { data });\n }\n\n delete(id: string | FilterQuery<SchemaType>): Promise<boolean> {\n return this.callAction(BaseServiceCommands.Delete, { id });\n }\n\n bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number> {\n return this.callAction(BaseServiceCommands.BulkDelete, { criteria });\n }\n\n get(id?: string | FilterQuery<SchemaType>): Promise<AsDomainType<SchemaType> | null> {\n return this.callAction(BaseServiceCommands.Get, { id });\n }\n\n getAll(options?: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]> {\n return this.callAction(BaseServiceCommands.GetAll, options);\n }\n\n getByIds(ids: string[]): Promise<AsDomainType<SchemaType>[]> {\n return this.callAction(BaseServiceCommands.GetByIds, { ids });\n }\n\n getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n }> {\n return this.callAction(BaseServiceCommands.GetAllWithCount, options);\n }\n\n insert<T = CreateType<SchemaType>>(\n data: T & { id?: string },\n overwrite?: boolean,\n ): Promise<AsDomainType<SchemaType>> {\n return this.callAction(BaseServiceCommands.Insert, { data, overwrite });\n }\n\n update<T = UpdateType<SchemaType>>(id: string, data: T, overwrite?: boolean): Promise<AsDomainType<SchemaType>> {\n return this.callAction(BaseServiceCommands.Update, { id, data, overwrite });\n }\n\n protected async callAction<T, P = unknown>(command: string, params?: P): Promise<T> {\n return this.broker.call<T, P>(`${this.topic}.${command}`, params);\n }\n}\n"],"names":[],"mappings":"gQAasB,IAAA,iBAAiB,GAAhC,MAAe,iBAAiB,CAAA;AAOZ,IAAA,MAAA,CAAA;IAFvB,WAEuB,CAAA,MAAqB,EAGxC,MAAyB,EAAA;QAHN,IAAM,CAAA,MAAA,GAAN,MAAM,CAAe;KAIxC;AAEJ,IAAA,SAAS,CAAC,IAAY,EAAA;AAClB,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;KACnE;AAED,IAAA,UAAU,CAA6B,IAAS,EAAA;AAC5C,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;KACpE;AAED,IAAA,KAAK,CAAC,QAAkC,EAAA;AACpC,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;KACnE;AAED,IAAA,MAAM,CAA6B,IAAO,EAAA;AACtC,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;KAChE;AAED,IAAA,MAAM,CAAC,EAAoC,EAAA;AACvC,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;KAC9D;AAED,IAAA,UAAU,CAAC,QAAiC,EAAA;AACxC,QAAA,OAAO,IAAI,C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