@akanjs/service 0.0.97 → 0.0.98
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.cjs +21 -0
- package/index.js +1 -21
- package/package.json +2 -2
- package/src/index.cjs +21 -0
- package/src/index.js +1 -21
- package/src/{serviceDecorators.mjs → serviceDecorators.cjs} +73 -41
- package/src/serviceDecorators.js +41 -73
- package/index.mjs +0 -1
- package/src/index.mjs +0 -1
package/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 service_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(service_exports);
|
|
17
|
+
__reExport(service_exports, require("./src"), module.exports);
|
|
18
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
+
0 && (module.exports = {
|
|
20
|
+
...require("./src")
|
|
21
|
+
});
|
package/index.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
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 service_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(service_exports);
|
|
17
|
-
__reExport(service_exports, require("./src"), module.exports);
|
|
18
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
-
0 && (module.exports = {
|
|
20
|
-
...require("./src")
|
|
21
|
-
});
|
|
1
|
+
export * from "./src";
|
package/package.json
CHANGED
package/src/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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);
|
|
18
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
+
0 && (module.exports = {
|
|
20
|
+
...require("./serviceDecorators")
|
|
21
|
+
});
|
package/src/index.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
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);
|
|
18
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
-
0 && (module.exports = {
|
|
20
|
-
...require("./serviceDecorators")
|
|
21
|
-
});
|
|
1
|
+
export * from "./serviceDecorators";
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
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);
|
|
3
18
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
19
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
20
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -9,14 +24,30 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
24
|
__defProp(target, key, result);
|
|
10
25
|
return result;
|
|
11
26
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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");
|
|
20
51
|
class ServiceStorage {
|
|
21
52
|
}
|
|
22
53
|
const getServiceRefs = (refName) => {
|
|
@@ -61,28 +92,28 @@ function Service(name, { enabled = true, serverMode } = {}) {
|
|
|
61
92
|
function Srv(name) {
|
|
62
93
|
return function(prototype, key) {
|
|
63
94
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
64
|
-
metadataMap.set(key, { type: "Srv", key, name: name ?? capitalize(key) });
|
|
95
|
+
metadataMap.set(key, { type: "Srv", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
65
96
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
66
97
|
};
|
|
67
98
|
}
|
|
68
99
|
function Use(name) {
|
|
69
100
|
return function(prototype, key) {
|
|
70
101
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
71
|
-
metadataMap.set(key, { type: "Use", key, name: name ?? capitalize(key) });
|
|
102
|
+
metadataMap.set(key, { type: "Use", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
72
103
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
73
104
|
};
|
|
74
105
|
}
|
|
75
106
|
function Queue(name) {
|
|
76
107
|
return function(prototype, key) {
|
|
77
108
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
78
|
-
metadataMap.set(key, { type: "Queue", key, name: name ?? capitalize(key) });
|
|
109
|
+
metadataMap.set(key, { type: "Queue", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
79
110
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
80
111
|
};
|
|
81
112
|
}
|
|
82
113
|
function Websocket(name) {
|
|
83
114
|
return function(prototype, key) {
|
|
84
115
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
85
|
-
metadataMap.set(key, { type: "Websocket", key, name: name ?? capitalize(key) });
|
|
116
|
+
metadataMap.set(key, { type: "Websocket", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
86
117
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
87
118
|
};
|
|
88
119
|
}
|
|
@@ -99,21 +130,21 @@ const serviceOf = (srvRef) => {
|
|
|
99
130
|
const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
|
|
100
131
|
for (const injectMeta of [...injectMetaMap.values()]) {
|
|
101
132
|
if (injectMeta.type === "Db")
|
|
102
|
-
InjectModel(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
133
|
+
(0, import_mongoose.InjectModel)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
103
134
|
else if (injectMeta.type === "Use")
|
|
104
|
-
Inject(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
135
|
+
(0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
105
136
|
else if (injectMeta.type === "Srv") {
|
|
106
137
|
const services = getServiceRefs(injectMeta.name);
|
|
107
138
|
if (!services.length)
|
|
108
139
|
throw new Error(`Service ${injectMeta.name} not found`);
|
|
109
|
-
Inject(services.at(-1))(srvRef.prototype, injectMeta.key);
|
|
140
|
+
(0, import_common2.Inject)(services.at(-1))(srvRef.prototype, injectMeta.key);
|
|
110
141
|
} else if (injectMeta.type === "Queue")
|
|
111
|
-
Inject(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
142
|
+
(0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
112
143
|
else
|
|
113
|
-
Inject(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
144
|
+
(0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
114
145
|
}
|
|
115
|
-
InjectConnection()(srvRef.prototype, "connection");
|
|
116
|
-
Injectable()(srvRef);
|
|
146
|
+
(0, import_mongoose.InjectConnection)()(srvRef.prototype, "connection");
|
|
147
|
+
(0, import_common2.Injectable)()(srvRef);
|
|
117
148
|
setServiceDefined(srvRef);
|
|
118
149
|
return srvRef;
|
|
119
150
|
};
|
|
@@ -124,7 +155,7 @@ function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t1
|
|
|
124
155
|
const injectMetadataMap = new Map(
|
|
125
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) => {
|
|
126
157
|
const injectMetadataMap2 = getServiceInjectMetaMapOnPrototype(srvRef);
|
|
127
|
-
applyMixins(Mix, [srvRef], AVOID_MIX_SRV_KEY_SET);
|
|
158
|
+
(0, import_common.applyMixins)(Mix, [srvRef], AVOID_MIX_SRV_KEY_SET);
|
|
128
159
|
return [...acc, ...injectMetadataMap2];
|
|
129
160
|
}, [])
|
|
130
161
|
);
|
|
@@ -134,14 +165,14 @@ function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t1
|
|
|
134
165
|
}
|
|
135
166
|
const LogService = (name) => {
|
|
136
167
|
class LogService2 {
|
|
137
|
-
logger = new Logger(name);
|
|
168
|
+
logger = new import_common.Logger(name);
|
|
138
169
|
}
|
|
139
170
|
return LogService2;
|
|
140
171
|
};
|
|
141
172
|
const DbService = (database, sigRef) => {
|
|
142
|
-
const [modelName, className] = [database.refName, capitalize(database.refName)];
|
|
173
|
+
const [modelName, className] = [database.refName, (0, import_common.capitalize)(database.refName)];
|
|
143
174
|
class DbService2 {
|
|
144
|
-
logger = new Logger(`${modelName}Service`);
|
|
175
|
+
logger = new import_common.Logger(`${modelName}Service`);
|
|
145
176
|
__databaseModel;
|
|
146
177
|
async __list(query, queryOption) {
|
|
147
178
|
return await this.__databaseModel.__list(query, queryOption);
|
|
@@ -237,48 +268,48 @@ const DbService = (database, sigRef) => {
|
|
|
237
268
|
const getQueryDataFromKey = (queryKey, args) => {
|
|
238
269
|
const lastArg = args.at(-1);
|
|
239
270
|
const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
|
|
240
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
271
|
+
const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
|
|
241
272
|
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
242
273
|
const queryOption = hasQueryOption ? lastArg : {};
|
|
243
274
|
return { query, queryOption };
|
|
244
275
|
};
|
|
245
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
276
|
+
const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
|
|
246
277
|
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
247
278
|
queryKeys.forEach((queryKey) => {
|
|
248
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
249
|
-
DbService2.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
279
|
+
const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
|
|
280
|
+
DbService2.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
250
281
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
251
282
|
return this.__list(query, queryOption);
|
|
252
283
|
};
|
|
253
|
-
DbService2.prototype[`listIds${capitalize(queryKey)}`] = async function(...args) {
|
|
284
|
+
DbService2.prototype[`listIds${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
254
285
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
255
286
|
return this.__listIds(query, queryOption);
|
|
256
287
|
};
|
|
257
|
-
DbService2.prototype[`find${capitalize(queryKey)}`] = async function(...args) {
|
|
288
|
+
DbService2.prototype[`find${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
258
289
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
259
290
|
return this.__find(query, queryOption);
|
|
260
291
|
};
|
|
261
|
-
DbService2.prototype[`findId${capitalize(queryKey)}`] = async function(...args) {
|
|
292
|
+
DbService2.prototype[`findId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
262
293
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
263
294
|
return this.__findId(query, queryOption);
|
|
264
295
|
};
|
|
265
|
-
DbService2.prototype[`pick${capitalize(queryKey)}`] = async function(...args) {
|
|
296
|
+
DbService2.prototype[`pick${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
266
297
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
267
298
|
return this.__pick(query, queryOption);
|
|
268
299
|
};
|
|
269
|
-
DbService2.prototype[`pickId${capitalize(queryKey)}`] = async function(...args) {
|
|
300
|
+
DbService2.prototype[`pickId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
270
301
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
271
302
|
return this.__pickId(query, queryOption);
|
|
272
303
|
};
|
|
273
|
-
DbService2.prototype[`exists${capitalize(queryKey)}`] = async function(...args) {
|
|
304
|
+
DbService2.prototype[`exists${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
274
305
|
const query = queryFn(...args);
|
|
275
306
|
return this.__exists(query);
|
|
276
307
|
};
|
|
277
|
-
DbService2.prototype[`count${capitalize(queryKey)}`] = async function(...args) {
|
|
308
|
+
DbService2.prototype[`count${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
278
309
|
const query = queryFn(...args);
|
|
279
310
|
return this.__count(query);
|
|
280
311
|
};
|
|
281
|
-
DbService2.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
312
|
+
DbService2.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
282
313
|
const query = queryFn(...args);
|
|
283
314
|
return this.__insight(query);
|
|
284
315
|
};
|
|
@@ -287,17 +318,17 @@ const DbService = (database, sigRef) => {
|
|
|
287
318
|
return DbService2;
|
|
288
319
|
};
|
|
289
320
|
const ExtendedUserService = (database, srvRef, sigRef) => {
|
|
290
|
-
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
321
|
+
const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
|
|
291
322
|
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
292
323
|
queryKeys.forEach((queryKey) => {
|
|
293
|
-
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
294
|
-
srvRef.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
324
|
+
const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
|
|
325
|
+
srvRef.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
295
326
|
const queryOption = args.at(-1);
|
|
296
327
|
const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
|
|
297
328
|
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
298
329
|
return this.__list(query, queryOption);
|
|
299
330
|
};
|
|
300
|
-
srvRef.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
331
|
+
srvRef.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
301
332
|
const query = queryFn(...args);
|
|
302
333
|
return this.__insight(query);
|
|
303
334
|
};
|
|
@@ -310,7 +341,8 @@ const ExtendedSummaryService = (database, srvRef, sigRef) => {
|
|
|
310
341
|
const ExtendedSettingService = (database, srvRef, sigRef) => {
|
|
311
342
|
return srvRef;
|
|
312
343
|
};
|
|
313
|
-
export
|
|
344
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
345
|
+
0 && (module.exports = {
|
|
314
346
|
Db,
|
|
315
347
|
DbService,
|
|
316
348
|
ExtendedSettingService,
|
|
@@ -326,4 +358,4 @@ export {
|
|
|
326
358
|
Websocket,
|
|
327
359
|
isServiceEnabled,
|
|
328
360
|
serviceOf
|
|
329
|
-
};
|
|
361
|
+
});
|
package/src/serviceDecorators.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
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
3
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
4
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
5
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -24,30 +9,14 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
24
9
|
__defProp(target, key, result);
|
|
25
10
|
return result;
|
|
26
11
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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");
|
|
12
|
+
import "reflect-metadata";
|
|
13
|
+
import { applyMixins, capitalize, Logger } from "@akanjs/common";
|
|
14
|
+
import {
|
|
15
|
+
getFilterKeyMetaMapOnPrototype,
|
|
16
|
+
getFilterQuery
|
|
17
|
+
} from "@akanjs/constant";
|
|
18
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
19
|
+
import { InjectConnection, InjectModel } from "@nestjs/mongoose";
|
|
51
20
|
class ServiceStorage {
|
|
52
21
|
}
|
|
53
22
|
const getServiceRefs = (refName) => {
|
|
@@ -92,28 +61,28 @@ function Service(name, { enabled = true, serverMode } = {}) {
|
|
|
92
61
|
function Srv(name) {
|
|
93
62
|
return function(prototype, key) {
|
|
94
63
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
95
|
-
metadataMap.set(key, { type: "Srv", key, name: name ??
|
|
64
|
+
metadataMap.set(key, { type: "Srv", key, name: name ?? capitalize(key) });
|
|
96
65
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
97
66
|
};
|
|
98
67
|
}
|
|
99
68
|
function Use(name) {
|
|
100
69
|
return function(prototype, key) {
|
|
101
70
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
102
|
-
metadataMap.set(key, { type: "Use", key, name: name ??
|
|
71
|
+
metadataMap.set(key, { type: "Use", key, name: name ?? capitalize(key) });
|
|
103
72
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
104
73
|
};
|
|
105
74
|
}
|
|
106
75
|
function Queue(name) {
|
|
107
76
|
return function(prototype, key) {
|
|
108
77
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
109
|
-
metadataMap.set(key, { type: "Queue", key, name: name ??
|
|
78
|
+
metadataMap.set(key, { type: "Queue", key, name: name ?? capitalize(key) });
|
|
110
79
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
111
80
|
};
|
|
112
81
|
}
|
|
113
82
|
function Websocket(name) {
|
|
114
83
|
return function(prototype, key) {
|
|
115
84
|
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
116
|
-
metadataMap.set(key, { type: "Websocket", key, name: name ??
|
|
85
|
+
metadataMap.set(key, { type: "Websocket", key, name: name ?? capitalize(key) });
|
|
117
86
|
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
118
87
|
};
|
|
119
88
|
}
|
|
@@ -130,21 +99,21 @@ const serviceOf = (srvRef) => {
|
|
|
130
99
|
const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
|
|
131
100
|
for (const injectMeta of [...injectMetaMap.values()]) {
|
|
132
101
|
if (injectMeta.type === "Db")
|
|
133
|
-
|
|
102
|
+
InjectModel(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
134
103
|
else if (injectMeta.type === "Use")
|
|
135
|
-
|
|
104
|
+
Inject(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
136
105
|
else if (injectMeta.type === "Srv") {
|
|
137
106
|
const services = getServiceRefs(injectMeta.name);
|
|
138
107
|
if (!services.length)
|
|
139
108
|
throw new Error(`Service ${injectMeta.name} not found`);
|
|
140
|
-
|
|
109
|
+
Inject(services.at(-1))(srvRef.prototype, injectMeta.key);
|
|
141
110
|
} else if (injectMeta.type === "Queue")
|
|
142
|
-
|
|
111
|
+
Inject(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
143
112
|
else
|
|
144
|
-
|
|
113
|
+
Inject(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
145
114
|
}
|
|
146
|
-
|
|
147
|
-
|
|
115
|
+
InjectConnection()(srvRef.prototype, "connection");
|
|
116
|
+
Injectable()(srvRef);
|
|
148
117
|
setServiceDefined(srvRef);
|
|
149
118
|
return srvRef;
|
|
150
119
|
};
|
|
@@ -155,7 +124,7 @@ function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t1
|
|
|
155
124
|
const injectMetadataMap = new Map(
|
|
156
125
|
[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
126
|
const injectMetadataMap2 = getServiceInjectMetaMapOnPrototype(srvRef);
|
|
158
|
-
|
|
127
|
+
applyMixins(Mix, [srvRef], AVOID_MIX_SRV_KEY_SET);
|
|
159
128
|
return [...acc, ...injectMetadataMap2];
|
|
160
129
|
}, [])
|
|
161
130
|
);
|
|
@@ -165,14 +134,14 @@ function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t1
|
|
|
165
134
|
}
|
|
166
135
|
const LogService = (name) => {
|
|
167
136
|
class LogService2 {
|
|
168
|
-
logger = new
|
|
137
|
+
logger = new Logger(name);
|
|
169
138
|
}
|
|
170
139
|
return LogService2;
|
|
171
140
|
};
|
|
172
141
|
const DbService = (database, sigRef) => {
|
|
173
|
-
const [modelName, className] = [database.refName,
|
|
142
|
+
const [modelName, className] = [database.refName, capitalize(database.refName)];
|
|
174
143
|
class DbService2 {
|
|
175
|
-
logger = new
|
|
144
|
+
logger = new Logger(`${modelName}Service`);
|
|
176
145
|
__databaseModel;
|
|
177
146
|
async __list(query, queryOption) {
|
|
178
147
|
return await this.__databaseModel.__list(query, queryOption);
|
|
@@ -268,48 +237,48 @@ const DbService = (database, sigRef) => {
|
|
|
268
237
|
const getQueryDataFromKey = (queryKey, args) => {
|
|
269
238
|
const lastArg = args.at(-1);
|
|
270
239
|
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 =
|
|
240
|
+
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
272
241
|
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
273
242
|
const queryOption = hasQueryOption ? lastArg : {};
|
|
274
243
|
return { query, queryOption };
|
|
275
244
|
};
|
|
276
|
-
const filterKeyMetaMap =
|
|
245
|
+
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
277
246
|
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
278
247
|
queryKeys.forEach((queryKey) => {
|
|
279
|
-
const queryFn =
|
|
280
|
-
DbService2.prototype[`list${
|
|
248
|
+
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
249
|
+
DbService2.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
281
250
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
282
251
|
return this.__list(query, queryOption);
|
|
283
252
|
};
|
|
284
|
-
DbService2.prototype[`listIds${
|
|
253
|
+
DbService2.prototype[`listIds${capitalize(queryKey)}`] = async function(...args) {
|
|
285
254
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
286
255
|
return this.__listIds(query, queryOption);
|
|
287
256
|
};
|
|
288
|
-
DbService2.prototype[`find${
|
|
257
|
+
DbService2.prototype[`find${capitalize(queryKey)}`] = async function(...args) {
|
|
289
258
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
290
259
|
return this.__find(query, queryOption);
|
|
291
260
|
};
|
|
292
|
-
DbService2.prototype[`findId${
|
|
261
|
+
DbService2.prototype[`findId${capitalize(queryKey)}`] = async function(...args) {
|
|
293
262
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
294
263
|
return this.__findId(query, queryOption);
|
|
295
264
|
};
|
|
296
|
-
DbService2.prototype[`pick${
|
|
265
|
+
DbService2.prototype[`pick${capitalize(queryKey)}`] = async function(...args) {
|
|
297
266
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
298
267
|
return this.__pick(query, queryOption);
|
|
299
268
|
};
|
|
300
|
-
DbService2.prototype[`pickId${
|
|
269
|
+
DbService2.prototype[`pickId${capitalize(queryKey)}`] = async function(...args) {
|
|
301
270
|
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
302
271
|
return this.__pickId(query, queryOption);
|
|
303
272
|
};
|
|
304
|
-
DbService2.prototype[`exists${
|
|
273
|
+
DbService2.prototype[`exists${capitalize(queryKey)}`] = async function(...args) {
|
|
305
274
|
const query = queryFn(...args);
|
|
306
275
|
return this.__exists(query);
|
|
307
276
|
};
|
|
308
|
-
DbService2.prototype[`count${
|
|
277
|
+
DbService2.prototype[`count${capitalize(queryKey)}`] = async function(...args) {
|
|
309
278
|
const query = queryFn(...args);
|
|
310
279
|
return this.__count(query);
|
|
311
280
|
};
|
|
312
|
-
DbService2.prototype[`insight${
|
|
281
|
+
DbService2.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
313
282
|
const query = queryFn(...args);
|
|
314
283
|
return this.__insight(query);
|
|
315
284
|
};
|
|
@@ -318,17 +287,17 @@ const DbService = (database, sigRef) => {
|
|
|
318
287
|
return DbService2;
|
|
319
288
|
};
|
|
320
289
|
const ExtendedUserService = (database, srvRef, sigRef) => {
|
|
321
|
-
const filterKeyMetaMap =
|
|
290
|
+
const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
|
|
322
291
|
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
323
292
|
queryKeys.forEach((queryKey) => {
|
|
324
|
-
const queryFn =
|
|
325
|
-
srvRef.prototype[`list${
|
|
293
|
+
const queryFn = getFilterQuery(database.Filter, queryKey);
|
|
294
|
+
srvRef.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
|
|
326
295
|
const queryOption = args.at(-1);
|
|
327
296
|
const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
|
|
328
297
|
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
329
298
|
return this.__list(query, queryOption);
|
|
330
299
|
};
|
|
331
|
-
srvRef.prototype[`insight${
|
|
300
|
+
srvRef.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
|
|
332
301
|
const query = queryFn(...args);
|
|
333
302
|
return this.__insight(query);
|
|
334
303
|
};
|
|
@@ -341,8 +310,7 @@ const ExtendedSummaryService = (database, srvRef, sigRef) => {
|
|
|
341
310
|
const ExtendedSettingService = (database, srvRef, sigRef) => {
|
|
342
311
|
return srvRef;
|
|
343
312
|
};
|
|
344
|
-
|
|
345
|
-
0 && (module.exports = {
|
|
313
|
+
export {
|
|
346
314
|
Db,
|
|
347
315
|
DbService,
|
|
348
316
|
ExtendedSettingService,
|
|
@@ -358,4 +326,4 @@ const ExtendedSettingService = (database, srvRef, sigRef) => {
|
|
|
358
326
|
Websocket,
|
|
359
327
|
isServiceEnabled,
|
|
360
328
|
serviceOf
|
|
361
|
-
}
|
|
329
|
+
};
|
package/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src";
|
package/src/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./serviceDecorators";
|