@akanjs/service 0.0.40 → 0.0.41

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