@akanjs/service 0.0.46 → 0.0.47

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/index.js CHANGED
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
5
  var __copyProps = (to, from, except, desc) => {
10
6
  if (from && typeof from === "object" || typeof from === "function") {
11
7
  for (let key of __getOwnPropNames(from))
@@ -14,334 +10,8 @@ var __copyProps = (to, from, except, desc) => {
14
10
  }
15
11
  return to;
16
12
  };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var __decorateClass = (decorators, target, key, kind) => {
19
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
- if (decorator = decorators[i])
22
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
- if (kind && result)
24
- __defProp(target, key, result);
25
- return result;
26
- };
27
-
28
- // pkgs/@akanjs/service/index.ts
29
15
  var service_exports = {};
30
- __export(service_exports, {
31
- Db: () => Db,
32
- DbService: () => DbService,
33
- ExtendedSettingService: () => ExtendedSettingService,
34
- ExtendedSummaryService: () => ExtendedSummaryService,
35
- ExtendedUserService: () => ExtendedUserService,
36
- LogService: () => LogService,
37
- MixSrvs: () => MixSrvs,
38
- Queue: () => Queue,
39
- Service: () => Service,
40
- ServiceStorage: () => ServiceStorage,
41
- Srv: () => Srv,
42
- Use: () => Use,
43
- Websocket: () => Websocket,
44
- isServiceEnabled: () => isServiceEnabled,
45
- serviceOf: () => serviceOf
46
- });
47
16
  module.exports = __toCommonJS(service_exports);
48
-
49
- // pkgs/@akanjs/service/src/serviceDecorators.ts
50
- var import_reflect_metadata = require("reflect-metadata");
51
- var import_common = require("@akanjs/common");
52
- var import_constant = require("@akanjs/constant");
53
- var import_common2 = require("@nestjs/common");
54
- var import_mongoose = require("@nestjs/mongoose");
55
- var ServiceStorage = class {
56
- };
57
- var getServiceRefs = (refName) => {
58
- return Reflect.getMetadata(refName, ServiceStorage.prototype) ?? [];
59
- };
60
- var setServiceRefs = (refName, services) => {
61
- Reflect.defineMetadata(refName, services, ServiceStorage.prototype);
62
- };
63
- var isServiceDefined = (srvRef) => {
64
- return Reflect.getMetadata("service", srvRef.prototype) ?? false;
65
- };
66
- var setServiceDefined = (srvRef) => {
67
- Reflect.defineMetadata("service", true, srvRef.prototype);
68
- };
69
- var setServiceMeta = (srvRef, meta) => {
70
- Reflect.defineMetadata("serviceMeta", meta, srvRef.prototype);
71
- };
72
- var getServiceMeta = (srvRef) => {
73
- return Reflect.getMetadata("serviceMeta", srvRef.prototype);
74
- };
75
- var isServiceEnabled = (srvRef) => {
76
- const meta = getServiceMeta(srvRef);
77
- return meta?.enabled ?? false;
78
- };
79
- var getServiceInjectMetaMapOnPrototype = (prototype) => {
80
- return Reflect.getMetadata("inject", prototype) ?? /* @__PURE__ */ new Map();
81
- };
82
- var setServiceInjectMetaMapOnPrototype = (prototype, injectMetaMap) => {
83
- Reflect.defineMetadata("inject", injectMetaMap, prototype);
84
- };
85
- function Service(name, { enabled = true, serverMode } = {}) {
86
- return function(target) {
87
- const services = getServiceRefs(name);
88
- const isEnabled = enabled && (!serverMode || process.env.SERVER_MODE === serverMode || process.env.SERVER_MODE === "all");
89
- setServiceMeta(target, { name, enabled: isEnabled });
90
- if (!isEnabled)
91
- return target;
92
- setServiceRefs(name, [...services, target]);
93
- return target;
94
- };
95
- }
96
- function Srv(name) {
97
- return function(prototype, key) {
98
- const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
99
- metadataMap.set(key, { type: "Srv", key, name: name ?? (0, import_common.capitalize)(key) });
100
- setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
101
- };
102
- }
103
- function Use(name) {
104
- return function(prototype, key) {
105
- const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
106
- metadataMap.set(key, { type: "Use", key, name: name ?? (0, import_common.capitalize)(key) });
107
- setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
108
- };
109
- }
110
- function Queue(name) {
111
- return function(prototype, key) {
112
- const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
113
- metadataMap.set(key, { type: "Queue", key, name: name ?? (0, import_common.capitalize)(key) });
114
- setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
115
- };
116
- }
117
- function Websocket(name) {
118
- return function(prototype, key) {
119
- const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
120
- metadataMap.set(key, { type: "Websocket", key, name: name ?? (0, import_common.capitalize)(key) });
121
- setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
122
- };
123
- }
124
- function Db(name) {
125
- return function(prototype, key) {
126
- const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
127
- metadataMap.set(key, { type: "Db", key, name });
128
- setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
129
- };
130
- }
131
- var serviceOf = (srvRef) => {
132
- if (isServiceDefined(srvRef))
133
- return srvRef;
134
- const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
135
- for (const injectMeta of [...injectMetaMap.values()]) {
136
- if (injectMeta.type === "Db")
137
- (0, import_mongoose.InjectModel)(injectMeta.name)(srvRef.prototype, injectMeta.key);
138
- else if (injectMeta.type === "Use")
139
- (0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
140
- else if (injectMeta.type === "Srv") {
141
- const services = getServiceRefs(injectMeta.name);
142
- if (!services.length)
143
- throw new Error(`Service ${injectMeta.name} not found`);
144
- (0, import_common2.Inject)(services.at(-1))(srvRef.prototype, injectMeta.key);
145
- } else if (injectMeta.type === "Queue")
146
- (0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
147
- else
148
- (0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
149
- }
150
- (0, import_mongoose.InjectConnection)()(srvRef.prototype, "connection");
151
- (0, import_common2.Injectable)()(srvRef);
152
- setServiceDefined(srvRef);
153
- return srvRef;
154
- };
155
- var AVOID_MIX_SRV_KEY_SET = /* @__PURE__ */ new Set(["onModuleInit", "onModuleDestroy"]);
156
- function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) {
157
- class Mix extends t1 {
158
- }
159
- const injectMetadataMap = new Map(
160
- [t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20].filter((t) => !!t).reduce((acc, srvRef) => {
161
- const injectMetadataMap2 = getServiceInjectMetaMapOnPrototype(srvRef);
162
- (0, import_common.applyMixins)(Mix, [srvRef], AVOID_MIX_SRV_KEY_SET);
163
- return [...acc, ...injectMetadataMap2];
164
- }, [])
165
- );
166
- Reflect.defineMetadata("service", false, Mix.prototype);
167
- Reflect.defineMetadata("inject", injectMetadataMap, Mix.prototype);
168
- return Mix;
169
- }
170
- var LogService = (name) => {
171
- class LogService2 {
172
- logger = new import_common.Logger(name);
173
- }
174
- return LogService2;
175
- };
176
- var DbService = (database, sigRef) => {
177
- const [modelName, className] = [database.refName, (0, import_common.capitalize)(database.refName)];
178
- class DbService2 {
179
- logger = new import_common.Logger(`${modelName}Service`);
180
- __databaseModel;
181
- async __list(query, queryOption) {
182
- return await this.__databaseModel.__list(query, queryOption);
183
- }
184
- async __listIds(query, queryOption) {
185
- return await this.__databaseModel.__listIds(query, queryOption);
186
- }
187
- async __find(query, queryOption) {
188
- return await this.__databaseModel.__find(query, queryOption);
189
- }
190
- async __findId(query, queryOption) {
191
- return await this.__databaseModel.__findId(query, queryOption);
192
- }
193
- async __pick(query, queryOption) {
194
- return await this.__databaseModel.__pick(query, queryOption);
195
- }
196
- async __pickId(query, queryOption) {
197
- return await this.__databaseModel.__pickId(query, queryOption);
198
- }
199
- async __exists(query) {
200
- return await this.__databaseModel.__exists(query);
201
- }
202
- async __count(query) {
203
- return await this.__databaseModel.__count(query);
204
- }
205
- async __insight(query) {
206
- return await this.__databaseModel.__insight(query);
207
- }
208
- async __search(searchText, queryOption) {
209
- return await this.__databaseModel[`search${className}`](searchText, queryOption);
210
- }
211
- async __searchDocs(searchText, queryOption) {
212
- return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
213
- }
214
- async __searchCount(searchText) {
215
- return await this.__databaseModel[`searchCount${className}`](searchText);
216
- }
217
- async _preCreate(data) {
218
- return data;
219
- }
220
- async _postCreate(doc) {
221
- return doc;
222
- }
223
- async _preUpdate(id, data) {
224
- return data;
225
- }
226
- async _postUpdate(doc) {
227
- return doc;
228
- }
229
- async _preRemove(id) {
230
- return;
231
- }
232
- async _postRemove(doc) {
233
- return doc;
234
- }
235
- async [`get${className}`](id) {
236
- return await this.__databaseModel[`get${className}`](id);
237
- }
238
- async [`load${className}`](id) {
239
- return await this.__databaseModel[`load${className}`](id);
240
- }
241
- async [`load${className}Many`](ids) {
242
- return await this.__databaseModel[`load${className}Many`](ids);
243
- }
244
- async [`create${className}`](data) {
245
- const input = await this._preCreate(data);
246
- const doc = await this.__databaseModel[`create${className}`](input);
247
- return await this._postCreate(doc);
248
- }
249
- async [`update${className}`](id, data) {
250
- const input = await this._preUpdate(id, data);
251
- const doc = await this.__databaseModel[`update${className}`](id, input);
252
- return await this._postUpdate(doc);
253
- }
254
- async [`remove${className}`](id) {
255
- await this._preRemove(id);
256
- const doc = await this.__databaseModel[`remove${className}`](id);
257
- return await this._postRemove(doc);
258
- }
259
- async [`search${className}`](query, queryOption) {
260
- return await this.__databaseModel[`search${className}`](query, queryOption);
261
- }
262
- async [`searchDocs${className}`](query, queryOption) {
263
- return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
264
- }
265
- async [`searchCount${className}`](query) {
266
- return await this.__databaseModel[`searchCount${className}`](query);
267
- }
268
- }
269
- __decorateClass([
270
- Use(`${modelName}Model`)
271
- ], DbService2.prototype, "__databaseModel", 2);
272
- const getQueryDataFromKey = (queryKey, args) => {
273
- const lastArg = args.at(-1);
274
- const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
275
- const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
276
- const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
277
- const queryOption = hasQueryOption ? lastArg : {};
278
- return { query, queryOption };
279
- };
280
- const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
281
- const queryKeys = [...filterKeyMetaMap.keys()];
282
- queryKeys.forEach((queryKey) => {
283
- const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
284
- DbService2.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
285
- const { query, queryOption } = getQueryDataFromKey(queryKey, args);
286
- return this.__list(query, queryOption);
287
- };
288
- DbService2.prototype[`listIds${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
289
- const { query, queryOption } = getQueryDataFromKey(queryKey, args);
290
- return this.__listIds(query, queryOption);
291
- };
292
- DbService2.prototype[`find${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
293
- const { query, queryOption } = getQueryDataFromKey(queryKey, args);
294
- return this.__find(query, queryOption);
295
- };
296
- DbService2.prototype[`findId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
297
- const { query, queryOption } = getQueryDataFromKey(queryKey, args);
298
- return this.__findId(query, queryOption);
299
- };
300
- DbService2.prototype[`pick${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
301
- const { query, queryOption } = getQueryDataFromKey(queryKey, args);
302
- return this.__pick(query, queryOption);
303
- };
304
- DbService2.prototype[`pickId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
305
- const { query, queryOption } = getQueryDataFromKey(queryKey, args);
306
- return this.__pickId(query, queryOption);
307
- };
308
- DbService2.prototype[`exists${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
309
- const query = queryFn(...args);
310
- return this.__exists(query);
311
- };
312
- DbService2.prototype[`count${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
313
- const query = queryFn(...args);
314
- return this.__count(query);
315
- };
316
- DbService2.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
317
- const query = queryFn(...args);
318
- return this.__insight(query);
319
- };
320
- });
321
- Use(`${modelName}Model`)(DbService2.prototype, `${modelName}Model`);
322
- return DbService2;
323
- };
324
- var ExtendedUserService = (database, srvRef, sigRef) => {
325
- const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
326
- const queryKeys = [...filterKeyMetaMap.keys()];
327
- queryKeys.forEach((queryKey) => {
328
- const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
329
- srvRef.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
330
- const queryOption = args.at(-1);
331
- const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
332
- const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
333
- return this.__list(query, queryOption);
334
- };
335
- srvRef.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
336
- const query = queryFn(...args);
337
- return this.__insight(query);
338
- };
339
- });
340
- return srvRef;
341
- };
342
- var ExtendedSummaryService = (database, srvRef, sigRef) => {
343
- return srvRef;
344
- };
345
- var ExtendedSettingService = (database, srvRef, sigRef) => {
346
- return srvRef;
347
- };
17
+ __reExport(service_exports, require("./src"), module.exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/service",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/index.js ADDED
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var src_exports = {};
16
+ module.exports = __toCommonJS(src_exports);
17
+ __reExport(src_exports, require("./serviceDecorators"), module.exports);
@@ -0,0 +1,343 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __decorateClass = (decorators, target, key, kind) => {
19
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
+ if (decorator = decorators[i])
22
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
+ if (kind && result)
24
+ __defProp(target, key, result);
25
+ return result;
26
+ };
27
+ var serviceDecorators_exports = {};
28
+ __export(serviceDecorators_exports, {
29
+ Db: () => Db,
30
+ DbService: () => DbService,
31
+ ExtendedSettingService: () => ExtendedSettingService,
32
+ ExtendedSummaryService: () => ExtendedSummaryService,
33
+ ExtendedUserService: () => ExtendedUserService,
34
+ LogService: () => LogService,
35
+ MixSrvs: () => MixSrvs,
36
+ Queue: () => Queue,
37
+ Service: () => Service,
38
+ ServiceStorage: () => ServiceStorage,
39
+ Srv: () => Srv,
40
+ Use: () => Use,
41
+ Websocket: () => Websocket,
42
+ isServiceEnabled: () => isServiceEnabled,
43
+ serviceOf: () => serviceOf
44
+ });
45
+ module.exports = __toCommonJS(serviceDecorators_exports);
46
+ var import_reflect_metadata = require("reflect-metadata");
47
+ var import_common = require("@akanjs/common");
48
+ var import_constant = require("@akanjs/constant");
49
+ var import_common2 = require("@nestjs/common");
50
+ var import_mongoose = require("@nestjs/mongoose");
51
+ class ServiceStorage {
52
+ }
53
+ const getServiceRefs = (refName) => {
54
+ return Reflect.getMetadata(refName, ServiceStorage.prototype) ?? [];
55
+ };
56
+ const setServiceRefs = (refName, services) => {
57
+ Reflect.defineMetadata(refName, services, ServiceStorage.prototype);
58
+ };
59
+ const isServiceDefined = (srvRef) => {
60
+ return Reflect.getMetadata("service", srvRef.prototype) ?? false;
61
+ };
62
+ const setServiceDefined = (srvRef) => {
63
+ Reflect.defineMetadata("service", true, srvRef.prototype);
64
+ };
65
+ const setServiceMeta = (srvRef, meta) => {
66
+ Reflect.defineMetadata("serviceMeta", meta, srvRef.prototype);
67
+ };
68
+ const getServiceMeta = (srvRef) => {
69
+ return Reflect.getMetadata("serviceMeta", srvRef.prototype);
70
+ };
71
+ const isServiceEnabled = (srvRef) => {
72
+ const meta = getServiceMeta(srvRef);
73
+ return meta?.enabled ?? false;
74
+ };
75
+ const getServiceInjectMetaMapOnPrototype = (prototype) => {
76
+ return Reflect.getMetadata("inject", prototype) ?? /* @__PURE__ */ new Map();
77
+ };
78
+ const setServiceInjectMetaMapOnPrototype = (prototype, injectMetaMap) => {
79
+ Reflect.defineMetadata("inject", injectMetaMap, prototype);
80
+ };
81
+ function Service(name, { enabled = true, serverMode } = {}) {
82
+ return function(target) {
83
+ const services = getServiceRefs(name);
84
+ const isEnabled = enabled && (!serverMode || process.env.SERVER_MODE === serverMode || process.env.SERVER_MODE === "all");
85
+ setServiceMeta(target, { name, enabled: isEnabled });
86
+ if (!isEnabled)
87
+ return target;
88
+ setServiceRefs(name, [...services, target]);
89
+ return target;
90
+ };
91
+ }
92
+ function Srv(name) {
93
+ return function(prototype, key) {
94
+ const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
95
+ metadataMap.set(key, { type: "Srv", key, name: name ?? (0, import_common.capitalize)(key) });
96
+ setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
97
+ };
98
+ }
99
+ function Use(name) {
100
+ return function(prototype, key) {
101
+ const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
102
+ metadataMap.set(key, { type: "Use", key, name: name ?? (0, import_common.capitalize)(key) });
103
+ setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
104
+ };
105
+ }
106
+ function Queue(name) {
107
+ return function(prototype, key) {
108
+ const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
109
+ metadataMap.set(key, { type: "Queue", key, name: name ?? (0, import_common.capitalize)(key) });
110
+ setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
111
+ };
112
+ }
113
+ function Websocket(name) {
114
+ return function(prototype, key) {
115
+ const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
116
+ metadataMap.set(key, { type: "Websocket", key, name: name ?? (0, import_common.capitalize)(key) });
117
+ setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
118
+ };
119
+ }
120
+ function Db(name) {
121
+ return function(prototype, key) {
122
+ const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
123
+ metadataMap.set(key, { type: "Db", key, name });
124
+ setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
125
+ };
126
+ }
127
+ const serviceOf = (srvRef) => {
128
+ if (isServiceDefined(srvRef))
129
+ return srvRef;
130
+ const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
131
+ for (const injectMeta of [...injectMetaMap.values()]) {
132
+ if (injectMeta.type === "Db")
133
+ (0, import_mongoose.InjectModel)(injectMeta.name)(srvRef.prototype, injectMeta.key);
134
+ else if (injectMeta.type === "Use")
135
+ (0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
136
+ else if (injectMeta.type === "Srv") {
137
+ const services = getServiceRefs(injectMeta.name);
138
+ if (!services.length)
139
+ throw new Error(`Service ${injectMeta.name} not found`);
140
+ (0, import_common2.Inject)(services.at(-1))(srvRef.prototype, injectMeta.key);
141
+ } else if (injectMeta.type === "Queue")
142
+ (0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
143
+ else
144
+ (0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
145
+ }
146
+ (0, import_mongoose.InjectConnection)()(srvRef.prototype, "connection");
147
+ (0, import_common2.Injectable)()(srvRef);
148
+ setServiceDefined(srvRef);
149
+ return srvRef;
150
+ };
151
+ const AVOID_MIX_SRV_KEY_SET = /* @__PURE__ */ new Set(["onModuleInit", "onModuleDestroy"]);
152
+ function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) {
153
+ class Mix extends t1 {
154
+ }
155
+ const injectMetadataMap = new Map(
156
+ [t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20].filter((t) => !!t).reduce((acc, srvRef) => {
157
+ const injectMetadataMap2 = getServiceInjectMetaMapOnPrototype(srvRef);
158
+ (0, import_common.applyMixins)(Mix, [srvRef], AVOID_MIX_SRV_KEY_SET);
159
+ return [...acc, ...injectMetadataMap2];
160
+ }, [])
161
+ );
162
+ Reflect.defineMetadata("service", false, Mix.prototype);
163
+ Reflect.defineMetadata("inject", injectMetadataMap, Mix.prototype);
164
+ return Mix;
165
+ }
166
+ const LogService = (name) => {
167
+ class LogService2 {
168
+ logger = new import_common.Logger(name);
169
+ }
170
+ return LogService2;
171
+ };
172
+ const DbService = (database, sigRef) => {
173
+ const [modelName, className] = [database.refName, (0, import_common.capitalize)(database.refName)];
174
+ class DbService2 {
175
+ logger = new import_common.Logger(`${modelName}Service`);
176
+ __databaseModel;
177
+ async __list(query, queryOption) {
178
+ return await this.__databaseModel.__list(query, queryOption);
179
+ }
180
+ async __listIds(query, queryOption) {
181
+ return await this.__databaseModel.__listIds(query, queryOption);
182
+ }
183
+ async __find(query, queryOption) {
184
+ return await this.__databaseModel.__find(query, queryOption);
185
+ }
186
+ async __findId(query, queryOption) {
187
+ return await this.__databaseModel.__findId(query, queryOption);
188
+ }
189
+ async __pick(query, queryOption) {
190
+ return await this.__databaseModel.__pick(query, queryOption);
191
+ }
192
+ async __pickId(query, queryOption) {
193
+ return await this.__databaseModel.__pickId(query, queryOption);
194
+ }
195
+ async __exists(query) {
196
+ return await this.__databaseModel.__exists(query);
197
+ }
198
+ async __count(query) {
199
+ return await this.__databaseModel.__count(query);
200
+ }
201
+ async __insight(query) {
202
+ return await this.__databaseModel.__insight(query);
203
+ }
204
+ async __search(searchText, queryOption) {
205
+ return await this.__databaseModel[`search${className}`](searchText, queryOption);
206
+ }
207
+ async __searchDocs(searchText, queryOption) {
208
+ return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
209
+ }
210
+ async __searchCount(searchText) {
211
+ return await this.__databaseModel[`searchCount${className}`](searchText);
212
+ }
213
+ async _preCreate(data) {
214
+ return data;
215
+ }
216
+ async _postCreate(doc) {
217
+ return doc;
218
+ }
219
+ async _preUpdate(id, data) {
220
+ return data;
221
+ }
222
+ async _postUpdate(doc) {
223
+ return doc;
224
+ }
225
+ async _preRemove(id) {
226
+ return;
227
+ }
228
+ async _postRemove(doc) {
229
+ return doc;
230
+ }
231
+ async [`get${className}`](id) {
232
+ return await this.__databaseModel[`get${className}`](id);
233
+ }
234
+ async [`load${className}`](id) {
235
+ return await this.__databaseModel[`load${className}`](id);
236
+ }
237
+ async [`load${className}Many`](ids) {
238
+ return await this.__databaseModel[`load${className}Many`](ids);
239
+ }
240
+ async [`create${className}`](data) {
241
+ const input = await this._preCreate(data);
242
+ const doc = await this.__databaseModel[`create${className}`](input);
243
+ return await this._postCreate(doc);
244
+ }
245
+ async [`update${className}`](id, data) {
246
+ const input = await this._preUpdate(id, data);
247
+ const doc = await this.__databaseModel[`update${className}`](id, input);
248
+ return await this._postUpdate(doc);
249
+ }
250
+ async [`remove${className}`](id) {
251
+ await this._preRemove(id);
252
+ const doc = await this.__databaseModel[`remove${className}`](id);
253
+ return await this._postRemove(doc);
254
+ }
255
+ async [`search${className}`](query, queryOption) {
256
+ return await this.__databaseModel[`search${className}`](query, queryOption);
257
+ }
258
+ async [`searchDocs${className}`](query, queryOption) {
259
+ return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
260
+ }
261
+ async [`searchCount${className}`](query) {
262
+ return await this.__databaseModel[`searchCount${className}`](query);
263
+ }
264
+ }
265
+ __decorateClass([
266
+ Use(`${modelName}Model`)
267
+ ], DbService2.prototype, "__databaseModel", 2);
268
+ const getQueryDataFromKey = (queryKey, args) => {
269
+ const lastArg = args.at(-1);
270
+ const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
271
+ const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
272
+ const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
273
+ const queryOption = hasQueryOption ? lastArg : {};
274
+ return { query, queryOption };
275
+ };
276
+ const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
277
+ const queryKeys = [...filterKeyMetaMap.keys()];
278
+ queryKeys.forEach((queryKey) => {
279
+ const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
280
+ DbService2.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
281
+ const { query, queryOption } = getQueryDataFromKey(queryKey, args);
282
+ return this.__list(query, queryOption);
283
+ };
284
+ DbService2.prototype[`listIds${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
285
+ const { query, queryOption } = getQueryDataFromKey(queryKey, args);
286
+ return this.__listIds(query, queryOption);
287
+ };
288
+ DbService2.prototype[`find${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
289
+ const { query, queryOption } = getQueryDataFromKey(queryKey, args);
290
+ return this.__find(query, queryOption);
291
+ };
292
+ DbService2.prototype[`findId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
293
+ const { query, queryOption } = getQueryDataFromKey(queryKey, args);
294
+ return this.__findId(query, queryOption);
295
+ };
296
+ DbService2.prototype[`pick${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
297
+ const { query, queryOption } = getQueryDataFromKey(queryKey, args);
298
+ return this.__pick(query, queryOption);
299
+ };
300
+ DbService2.prototype[`pickId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
301
+ const { query, queryOption } = getQueryDataFromKey(queryKey, args);
302
+ return this.__pickId(query, queryOption);
303
+ };
304
+ DbService2.prototype[`exists${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
305
+ const query = queryFn(...args);
306
+ return this.__exists(query);
307
+ };
308
+ DbService2.prototype[`count${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
309
+ const query = queryFn(...args);
310
+ return this.__count(query);
311
+ };
312
+ DbService2.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
313
+ const query = queryFn(...args);
314
+ return this.__insight(query);
315
+ };
316
+ });
317
+ Use(`${modelName}Model`)(DbService2.prototype, `${modelName}Model`);
318
+ return DbService2;
319
+ };
320
+ const ExtendedUserService = (database, srvRef, sigRef) => {
321
+ const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
322
+ const queryKeys = [...filterKeyMetaMap.keys()];
323
+ queryKeys.forEach((queryKey) => {
324
+ const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
325
+ srvRef.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
326
+ const queryOption = args.at(-1);
327
+ const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
328
+ const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
329
+ return this.__list(query, queryOption);
330
+ };
331
+ srvRef.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
332
+ const query = queryFn(...args);
333
+ return this.__insight(query);
334
+ };
335
+ });
336
+ return srvRef;
337
+ };
338
+ const ExtendedSummaryService = (database, srvRef, sigRef) => {
339
+ return srvRef;
340
+ };
341
+ const ExtendedSettingService = (database, srvRef, sigRef) => {
342
+ return srvRef;
343
+ };