@akanjs/service 0.9.43 → 0.9.45

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.
@@ -30,10 +30,25 @@ __export(base_service_exports, {
30
30
  allSrvs: () => allSrvs
31
31
  });
32
32
  module.exports = __toCommonJS(base_service_exports);
33
+ var import_dictionary = require("@akanjs/dictionary");
33
34
  var import_serviceDecorators = require("./serviceDecorators");
34
35
  let BaseService = class extends (0, import_serviceDecorators.LogService)("BaseService") {
35
36
  onCleanup;
36
37
  baseSignal;
38
+ publishPing() {
39
+ this.baseSignal.pubsubPing("ping");
40
+ }
41
+ l(lang, key) {
42
+ try {
43
+ const res = { lang, key, str: (0, import_dictionary.translate)(lang, key) };
44
+ return res;
45
+ } catch (e) {
46
+ return { lang, key, str: key };
47
+ }
48
+ }
49
+ getDictionary(lang) {
50
+ return (0, import_dictionary.getDictionary)(lang);
51
+ }
37
52
  async cleanup() {
38
53
  if (!this.onCleanup)
39
54
  throw new Error("onCleanup is not defined");
@@ -29,9 +29,6 @@ __export(serviceDecorators_exports, {
29
29
  Db: () => Db,
30
30
  DbService: () => DbService,
31
31
  Env: () => Env,
32
- ExtendedSettingService: () => ExtendedSettingService,
33
- ExtendedSummaryService: () => ExtendedSummaryService,
34
- ExtendedUserService: () => ExtendedUserService,
35
32
  Gen: () => Gen,
36
33
  LogService: () => LogService,
37
34
  MixSrvs: () => MixSrvs,
@@ -194,111 +191,112 @@ const LogService = (name) => {
194
191
  }
195
192
  return LogService2;
196
193
  };
197
- const DbService = (database, sigRef) => {
194
+ const DbService = (database, ...libSrvRefs) => {
198
195
  const [modelName, className] = [database.refName, (0, import_common.capitalize)(database.refName)];
199
- class DbService2 {
200
- logger = new import_common.Logger(`${(0, import_common.capitalize)(modelName)}Service`);
201
- __databaseModel;
202
- async __list(query, queryOption) {
203
- return await this.__databaseModel.__list(query, queryOption);
196
+ const getDefaultDbService = () => {
197
+ class DbService3 {
198
+ logger = new import_common.Logger(`${(0, import_common.capitalize)(modelName)}Service`);
199
+ __databaseModel;
200
+ async __list(query, queryOption) {
201
+ return await this.__databaseModel.__list(query, queryOption);
202
+ }
203
+ async __listIds(query, queryOption) {
204
+ return await this.__databaseModel.__listIds(query, queryOption);
205
+ }
206
+ async __find(query, queryOption) {
207
+ return await this.__databaseModel.__find(query, queryOption);
208
+ }
209
+ async __findId(query, queryOption) {
210
+ return await this.__databaseModel.__findId(query, queryOption);
211
+ }
212
+ async __pick(query, queryOption) {
213
+ return await this.__databaseModel.__pick(query, queryOption);
214
+ }
215
+ async __pickId(query, queryOption) {
216
+ return await this.__databaseModel.__pickId(query, queryOption);
217
+ }
218
+ async __exists(query) {
219
+ return await this.__databaseModel.__exists(query);
220
+ }
221
+ async __count(query) {
222
+ return await this.__databaseModel.__count(query);
223
+ }
224
+ async __insight(query) {
225
+ return await this.__databaseModel.__insight(query);
226
+ }
227
+ async __search(searchText, queryOption) {
228
+ return await this.__databaseModel[`search${className}`](searchText, queryOption);
229
+ }
230
+ async __searchDocs(searchText, queryOption) {
231
+ return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
232
+ }
233
+ async __searchCount(searchText) {
234
+ return await this.__databaseModel[`searchCount${className}`](searchText);
235
+ }
236
+ async _preCreate(data) {
237
+ return data;
238
+ }
239
+ async _postCreate(doc) {
240
+ return doc;
241
+ }
242
+ async _preUpdate(id, data) {
243
+ return data;
244
+ }
245
+ async _postUpdate(doc) {
246
+ return doc;
247
+ }
248
+ async _preRemove(id) {
249
+ return;
250
+ }
251
+ async _postRemove(doc) {
252
+ return doc;
253
+ }
254
+ listenPre(type, listener) {
255
+ return this.__databaseModel.listenPre(type, listener);
256
+ }
257
+ listenPost(type, listener) {
258
+ return this.__databaseModel.listenPost(type, listener);
259
+ }
260
+ async [`get${className}`](id) {
261
+ return await this.__databaseModel[`get${className}`](id);
262
+ }
263
+ async [`load${className}`](id) {
264
+ return await this.__databaseModel[`load${className}`](id);
265
+ }
266
+ async [`load${className}Many`](ids) {
267
+ return await this.__databaseModel[`load${className}Many`](ids);
268
+ }
269
+ async [`create${className}`](data) {
270
+ const input = await this._preCreate(data);
271
+ const doc = await this.__databaseModel[`create${className}`](input);
272
+ return await this._postCreate(doc);
273
+ }
274
+ async [`update${className}`](id, data) {
275
+ const input = await this._preUpdate(id, data);
276
+ const doc = await this.__databaseModel[`update${className}`](id, input);
277
+ return await this._postUpdate(doc);
278
+ }
279
+ async [`remove${className}`](id) {
280
+ await this._preRemove(id);
281
+ const doc = await this.__databaseModel[`remove${className}`](id);
282
+ return await this._postRemove(doc);
283
+ }
284
+ async [`search${className}`](query, queryOption) {
285
+ return await this.__databaseModel[`search${className}`](query, queryOption);
286
+ }
287
+ async [`searchDocs${className}`](query, queryOption) {
288
+ return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
289
+ }
290
+ async [`searchCount${className}`](query) {
291
+ return await this.__databaseModel[`searchCount${className}`](query);
292
+ }
204
293
  }
205
- async __listIds(query, queryOption) {
206
- return await this.__databaseModel.__listIds(query, queryOption);
207
- }
208
- async __find(query, queryOption) {
209
- return await this.__databaseModel.__find(query, queryOption);
210
- }
211
- async __findId(query, queryOption) {
212
- return await this.__databaseModel.__findId(query, queryOption);
213
- }
214
- async __pick(query, queryOption) {
215
- return await this.__databaseModel.__pick(query, queryOption);
216
- }
217
- async __pickId(query, queryOption) {
218
- return await this.__databaseModel.__pickId(query, queryOption);
219
- }
220
- async __exists(query) {
221
- return await this.__databaseModel.__exists(query);
222
- }
223
- async __count(query) {
224
- return await this.__databaseModel.__count(query);
225
- }
226
- async __insight(query) {
227
- return await this.__databaseModel.__insight(query);
228
- }
229
- async __search(searchText, queryOption) {
230
- return await this.__databaseModel[`search${className}`](searchText, queryOption);
231
- }
232
- async __searchDocs(searchText, queryOption) {
233
- return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
234
- }
235
- async __searchCount(searchText) {
236
- return await this.__databaseModel[`searchCount${className}`](searchText);
237
- }
238
- async _preCreate(data) {
239
- return data;
240
- }
241
- async _postCreate(doc) {
242
- return doc;
243
- }
244
- async _preUpdate(id, data) {
245
- return data;
246
- }
247
- async _postUpdate(doc) {
248
- return doc;
249
- }
250
- async _preRemove(id) {
251
- return;
252
- }
253
- async _postRemove(doc) {
254
- return doc;
255
- }
256
- async _preSummarize() {
257
- return {};
258
- }
259
- async summarize() {
260
- if (!database.Summary)
261
- return {};
262
- const [dbSummary, serviceSummary] = await Promise.all([this.__databaseModel.getSummary(), this._preSummarize()]);
263
- return { ...dbSummary, ...serviceSummary };
264
- }
265
- async [`get${className}`](id) {
266
- return await this.__databaseModel[`get${className}`](id);
267
- }
268
- async [`load${className}`](id) {
269
- return await this.__databaseModel[`load${className}`](id);
270
- }
271
- async [`load${className}Many`](ids) {
272
- return await this.__databaseModel[`load${className}Many`](ids);
273
- }
274
- async [`create${className}`](data) {
275
- const input = await this._preCreate(data);
276
- const doc = await this.__databaseModel[`create${className}`](input);
277
- return await this._postCreate(doc);
278
- }
279
- async [`update${className}`](id, data) {
280
- const input = await this._preUpdate(id, data);
281
- const doc = await this.__databaseModel[`update${className}`](id, input);
282
- return await this._postUpdate(doc);
283
- }
284
- async [`remove${className}`](id) {
285
- await this._preRemove(id);
286
- const doc = await this.__databaseModel[`remove${className}`](id);
287
- return await this._postRemove(doc);
288
- }
289
- async [`search${className}`](query, queryOption) {
290
- return await this.__databaseModel[`search${className}`](query, queryOption);
291
- }
292
- async [`searchDocs${className}`](query, queryOption) {
293
- return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
294
- }
295
- async [`searchCount${className}`](query) {
296
- return await this.__databaseModel[`searchCount${className}`](query);
297
- }
298
- }
299
- __decorateClass([
300
- Use(`${modelName}Model`)
301
- ], DbService2.prototype, "__databaseModel", 2);
294
+ __decorateClass([
295
+ Use(`${modelName}Model`)
296
+ ], DbService3.prototype, "__databaseModel", 2);
297
+ Use(`${modelName}Model`)(DbService3.prototype, `${modelName}Model`);
298
+ return DbService3;
299
+ };
302
300
  const getQueryDataFromKey = (queryKey, args) => {
303
301
  const lastArg = args.at(-1);
304
302
  const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
@@ -307,6 +305,7 @@ const DbService = (database, sigRef) => {
307
305
  const queryOption = hasQueryOption ? lastArg : {};
308
306
  return { query, queryOption };
309
307
  };
308
+ const DbService2 = libSrvRefs.length > 0 ? MixSrvs(...libSrvRefs) : getDefaultDbService();
310
309
  const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
311
310
  const queryKeys = [...filterKeyMetaMap.keys()];
312
311
  queryKeys.forEach((queryKey) => {
@@ -348,33 +347,8 @@ const DbService = (database, sigRef) => {
348
347
  return this.__insight(query);
349
348
  };
350
349
  });
351
- Use(`${modelName}Model`)(DbService2.prototype, `${modelName}Model`);
352
350
  return DbService2;
353
351
  };
354
- const ExtendedUserService = (database, srvRef, sigRef) => {
355
- const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
356
- const queryKeys = [...filterKeyMetaMap.keys()];
357
- queryKeys.forEach((queryKey) => {
358
- const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
359
- srvRef.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
360
- const queryOption = args.at(-1);
361
- const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
362
- const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
363
- return this.__list(query, queryOption);
364
- };
365
- srvRef.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
366
- const query = queryFn(...args);
367
- return this.__insight(query);
368
- };
369
- });
370
- return srvRef;
371
- };
372
- const ExtendedSummaryService = (database, srvRef, sigRef) => {
373
- return srvRef;
374
- };
375
- const ExtendedSettingService = (database, srvRef, sigRef) => {
376
- return srvRef;
377
- };
378
352
  const makeProvidersForSrv = (srvRef) => {
379
353
  const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
380
354
  const providers = [];
@@ -403,9 +377,6 @@ const makeProvidersForSrv = (srvRef) => {
403
377
  Db,
404
378
  DbService,
405
379
  Env,
406
- ExtendedSettingService,
407
- ExtendedSummaryService,
408
- ExtendedUserService,
409
380
  Gen,
410
381
  LogService,
411
382
  MixSrvs,
@@ -9,10 +9,25 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  __defProp(target, key, result);
10
10
  return result;
11
11
  };
12
+ import { getDictionary, translate } from "@akanjs/dictionary";
12
13
  import { Gen, LogService, Service, Sig } from "./serviceDecorators";
13
14
  let BaseService = class extends LogService("BaseService") {
14
15
  onCleanup;
15
16
  baseSignal;
17
+ publishPing() {
18
+ this.baseSignal.pubsubPing("ping");
19
+ }
20
+ l(lang, key) {
21
+ try {
22
+ const res = { lang, key, str: translate(lang, key) };
23
+ return res;
24
+ } catch (e) {
25
+ return { lang, key, str: key };
26
+ }
27
+ }
28
+ getDictionary(lang) {
29
+ return getDictionary(lang);
30
+ }
16
31
  async cleanup() {
17
32
  if (!this.onCleanup)
18
33
  throw new Error("onCleanup is not defined");
@@ -158,111 +158,112 @@ const LogService = (name) => {
158
158
  }
159
159
  return LogService2;
160
160
  };
161
- const DbService = (database, sigRef) => {
161
+ const DbService = (database, ...libSrvRefs) => {
162
162
  const [modelName, className] = [database.refName, capitalize(database.refName)];
163
- class DbService2 {
164
- logger = new Logger(`${capitalize(modelName)}Service`);
165
- __databaseModel;
166
- async __list(query, queryOption) {
167
- return await this.__databaseModel.__list(query, queryOption);
163
+ const getDefaultDbService = () => {
164
+ class DbService3 {
165
+ logger = new Logger(`${capitalize(modelName)}Service`);
166
+ __databaseModel;
167
+ async __list(query, queryOption) {
168
+ return await this.__databaseModel.__list(query, queryOption);
169
+ }
170
+ async __listIds(query, queryOption) {
171
+ return await this.__databaseModel.__listIds(query, queryOption);
172
+ }
173
+ async __find(query, queryOption) {
174
+ return await this.__databaseModel.__find(query, queryOption);
175
+ }
176
+ async __findId(query, queryOption) {
177
+ return await this.__databaseModel.__findId(query, queryOption);
178
+ }
179
+ async __pick(query, queryOption) {
180
+ return await this.__databaseModel.__pick(query, queryOption);
181
+ }
182
+ async __pickId(query, queryOption) {
183
+ return await this.__databaseModel.__pickId(query, queryOption);
184
+ }
185
+ async __exists(query) {
186
+ return await this.__databaseModel.__exists(query);
187
+ }
188
+ async __count(query) {
189
+ return await this.__databaseModel.__count(query);
190
+ }
191
+ async __insight(query) {
192
+ return await this.__databaseModel.__insight(query);
193
+ }
194
+ async __search(searchText, queryOption) {
195
+ return await this.__databaseModel[`search${className}`](searchText, queryOption);
196
+ }
197
+ async __searchDocs(searchText, queryOption) {
198
+ return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
199
+ }
200
+ async __searchCount(searchText) {
201
+ return await this.__databaseModel[`searchCount${className}`](searchText);
202
+ }
203
+ async _preCreate(data) {
204
+ return data;
205
+ }
206
+ async _postCreate(doc) {
207
+ return doc;
208
+ }
209
+ async _preUpdate(id, data) {
210
+ return data;
211
+ }
212
+ async _postUpdate(doc) {
213
+ return doc;
214
+ }
215
+ async _preRemove(id) {
216
+ return;
217
+ }
218
+ async _postRemove(doc) {
219
+ return doc;
220
+ }
221
+ listenPre(type, listener) {
222
+ return this.__databaseModel.listenPre(type, listener);
223
+ }
224
+ listenPost(type, listener) {
225
+ return this.__databaseModel.listenPost(type, listener);
226
+ }
227
+ async [`get${className}`](id) {
228
+ return await this.__databaseModel[`get${className}`](id);
229
+ }
230
+ async [`load${className}`](id) {
231
+ return await this.__databaseModel[`load${className}`](id);
232
+ }
233
+ async [`load${className}Many`](ids) {
234
+ return await this.__databaseModel[`load${className}Many`](ids);
235
+ }
236
+ async [`create${className}`](data) {
237
+ const input = await this._preCreate(data);
238
+ const doc = await this.__databaseModel[`create${className}`](input);
239
+ return await this._postCreate(doc);
240
+ }
241
+ async [`update${className}`](id, data) {
242
+ const input = await this._preUpdate(id, data);
243
+ const doc = await this.__databaseModel[`update${className}`](id, input);
244
+ return await this._postUpdate(doc);
245
+ }
246
+ async [`remove${className}`](id) {
247
+ await this._preRemove(id);
248
+ const doc = await this.__databaseModel[`remove${className}`](id);
249
+ return await this._postRemove(doc);
250
+ }
251
+ async [`search${className}`](query, queryOption) {
252
+ return await this.__databaseModel[`search${className}`](query, queryOption);
253
+ }
254
+ async [`searchDocs${className}`](query, queryOption) {
255
+ return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
256
+ }
257
+ async [`searchCount${className}`](query) {
258
+ return await this.__databaseModel[`searchCount${className}`](query);
259
+ }
168
260
  }
169
- async __listIds(query, queryOption) {
170
- return await this.__databaseModel.__listIds(query, queryOption);
171
- }
172
- async __find(query, queryOption) {
173
- return await this.__databaseModel.__find(query, queryOption);
174
- }
175
- async __findId(query, queryOption) {
176
- return await this.__databaseModel.__findId(query, queryOption);
177
- }
178
- async __pick(query, queryOption) {
179
- return await this.__databaseModel.__pick(query, queryOption);
180
- }
181
- async __pickId(query, queryOption) {
182
- return await this.__databaseModel.__pickId(query, queryOption);
183
- }
184
- async __exists(query) {
185
- return await this.__databaseModel.__exists(query);
186
- }
187
- async __count(query) {
188
- return await this.__databaseModel.__count(query);
189
- }
190
- async __insight(query) {
191
- return await this.__databaseModel.__insight(query);
192
- }
193
- async __search(searchText, queryOption) {
194
- return await this.__databaseModel[`search${className}`](searchText, queryOption);
195
- }
196
- async __searchDocs(searchText, queryOption) {
197
- return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
198
- }
199
- async __searchCount(searchText) {
200
- return await this.__databaseModel[`searchCount${className}`](searchText);
201
- }
202
- async _preCreate(data) {
203
- return data;
204
- }
205
- async _postCreate(doc) {
206
- return doc;
207
- }
208
- async _preUpdate(id, data) {
209
- return data;
210
- }
211
- async _postUpdate(doc) {
212
- return doc;
213
- }
214
- async _preRemove(id) {
215
- return;
216
- }
217
- async _postRemove(doc) {
218
- return doc;
219
- }
220
- async _preSummarize() {
221
- return {};
222
- }
223
- async summarize() {
224
- if (!database.Summary)
225
- return {};
226
- const [dbSummary, serviceSummary] = await Promise.all([this.__databaseModel.getSummary(), this._preSummarize()]);
227
- return { ...dbSummary, ...serviceSummary };
228
- }
229
- async [`get${className}`](id) {
230
- return await this.__databaseModel[`get${className}`](id);
231
- }
232
- async [`load${className}`](id) {
233
- return await this.__databaseModel[`load${className}`](id);
234
- }
235
- async [`load${className}Many`](ids) {
236
- return await this.__databaseModel[`load${className}Many`](ids);
237
- }
238
- async [`create${className}`](data) {
239
- const input = await this._preCreate(data);
240
- const doc = await this.__databaseModel[`create${className}`](input);
241
- return await this._postCreate(doc);
242
- }
243
- async [`update${className}`](id, data) {
244
- const input = await this._preUpdate(id, data);
245
- const doc = await this.__databaseModel[`update${className}`](id, input);
246
- return await this._postUpdate(doc);
247
- }
248
- async [`remove${className}`](id) {
249
- await this._preRemove(id);
250
- const doc = await this.__databaseModel[`remove${className}`](id);
251
- return await this._postRemove(doc);
252
- }
253
- async [`search${className}`](query, queryOption) {
254
- return await this.__databaseModel[`search${className}`](query, queryOption);
255
- }
256
- async [`searchDocs${className}`](query, queryOption) {
257
- return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
258
- }
259
- async [`searchCount${className}`](query) {
260
- return await this.__databaseModel[`searchCount${className}`](query);
261
- }
262
- }
263
- __decorateClass([
264
- Use(`${modelName}Model`)
265
- ], DbService2.prototype, "__databaseModel", 2);
261
+ __decorateClass([
262
+ Use(`${modelName}Model`)
263
+ ], DbService3.prototype, "__databaseModel", 2);
264
+ Use(`${modelName}Model`)(DbService3.prototype, `${modelName}Model`);
265
+ return DbService3;
266
+ };
266
267
  const getQueryDataFromKey = (queryKey, args) => {
267
268
  const lastArg = args.at(-1);
268
269
  const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
@@ -271,6 +272,7 @@ const DbService = (database, sigRef) => {
271
272
  const queryOption = hasQueryOption ? lastArg : {};
272
273
  return { query, queryOption };
273
274
  };
275
+ const DbService2 = libSrvRefs.length > 0 ? MixSrvs(...libSrvRefs) : getDefaultDbService();
274
276
  const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
275
277
  const queryKeys = [...filterKeyMetaMap.keys()];
276
278
  queryKeys.forEach((queryKey) => {
@@ -312,33 +314,8 @@ const DbService = (database, sigRef) => {
312
314
  return this.__insight(query);
313
315
  };
314
316
  });
315
- Use(`${modelName}Model`)(DbService2.prototype, `${modelName}Model`);
316
317
  return DbService2;
317
318
  };
318
- const ExtendedUserService = (database, srvRef, sigRef) => {
319
- const filterKeyMetaMap = getFilterKeyMetaMapOnPrototype(database.Filter.prototype);
320
- const queryKeys = [...filterKeyMetaMap.keys()];
321
- queryKeys.forEach((queryKey) => {
322
- const queryFn = getFilterQuery(database.Filter, queryKey);
323
- srvRef.prototype[`list${capitalize(queryKey)}`] = async function(...args) {
324
- const queryOption = args.at(-1);
325
- const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
326
- const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
327
- return this.__list(query, queryOption);
328
- };
329
- srvRef.prototype[`insight${capitalize(queryKey)}`] = async function(...args) {
330
- const query = queryFn(...args);
331
- return this.__insight(query);
332
- };
333
- });
334
- return srvRef;
335
- };
336
- const ExtendedSummaryService = (database, srvRef, sigRef) => {
337
- return srvRef;
338
- };
339
- const ExtendedSettingService = (database, srvRef, sigRef) => {
340
- return srvRef;
341
- };
342
319
  const makeProvidersForSrv = (srvRef) => {
343
320
  const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
344
321
  const providers = [];
@@ -366,9 +343,6 @@ export {
366
343
  Db,
367
344
  DbService,
368
345
  Env,
369
- ExtendedSettingService,
370
- ExtendedSummaryService,
371
- ExtendedUserService,
372
346
  Gen,
373
347
  LogService,
374
348
  MixSrvs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/service",
3
- "version": "0.9.43",
3
+ "version": "0.9.45",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,6 +8,17 @@ declare const BaseService_base: {
8
8
  export declare class BaseService extends BaseService_base {
9
9
  onCleanup?: () => Promise<void>;
10
10
  baseSignal: Sig<BaseSignal>;
11
+ publishPing(): void;
12
+ l(lang: string, key: string): {
13
+ lang: string;
14
+ key: string;
15
+ str: string;
16
+ };
17
+ getDictionary(lang: string): {
18
+ [key: string]: {
19
+ [key: string]: string;
20
+ };
21
+ };
11
22
  cleanup(): Promise<void>;
12
23
  }
13
24
  export declare const allSrvs: {
@@ -1,8 +1,8 @@
1
1
  import "reflect-metadata";
2
- import { BaseObject, type MergeAllTypes, type Prettify, type PromiseOrObject, Type, type UnType } from "@akanjs/base";
2
+ import type { GetActionObject, MergeAllTypes, Prettify, PromiseOrObject, Type, UnType } from "@akanjs/base";
3
3
  import { Logger } from "@akanjs/common";
4
- import { type DocumentModel, type FilterType, FindQueryOption, type GetActionObject, ListQueryOption, QueryOf, type SortOf } from "@akanjs/constant";
5
- import type { BaseMiddleware, Database, DatabaseModel, DataInputOf, QueryMethodPart } from "@akanjs/document";
4
+ import { type DocumentModel, type FilterType, FindQueryOption, ListQueryOption, QueryOf, type SortOf } from "@akanjs/constant";
5
+ import type { BaseMiddleware, CRUDEventType, Database, DatabaseModel, DataInputOf, Doc as DbDoc, GetDocObject, QueryMethodPart, SaveEventType } from "@akanjs/document";
6
6
  import { FilterOutInternalArgs } from "@akanjs/signal";
7
7
  import { type Provider } from "@nestjs/common";
8
8
  import type { Job, Queue as BullQueue } from "bull";
@@ -62,8 +62,8 @@ export declare const LogService: <T extends string>(name: T) => {
62
62
  logger: Logger;
63
63
  };
64
64
  };
65
- type DatabaseService<T extends string, Input, Doc, Obj, Model, Insight, Filter, Summary> = DatabaseServiceWithQuerySort<T, Input, Doc, Obj, Model, Insight, Summary, GetActionObject<Filter>, SortOf<Filter>>;
66
- type DatabaseServiceWithQuerySort<T extends string, Input, Doc, Obj, Model, Insight, Summary, Query, Sort, _CapitalizedT extends Capitalize<T> = Capitalize<T>, _DataInputOfDoc extends DataInputOf<Input, Doc> = DataInputOf<Input, Doc>, _QueryOfDoc extends QueryOf<Doc> = QueryOf<Doc>, _FindQueryOption extends FindQueryOption<Sort, Obj> = FindQueryOption<Sort, Obj>, _ListQueryOption extends ListQueryOption<Sort, Obj> = ListQueryOption<Sort, Obj>> = {
65
+ type DatabaseService<T extends string, Input, Doc, Obj, Model, Insight, Filter> = DatabaseServiceWithQuerySort<T, Input, Doc, Obj, Model, Insight, GetActionObject<Filter>, SortOf<Filter>>;
66
+ type DatabaseServiceWithQuerySort<T extends string, Input, Doc, Obj, Model, Insight, Query, Sort, _CapitalizedT extends Capitalize<T> = Capitalize<T>, _DataInputOfDoc extends DataInputOf<Input, Doc> = DataInputOf<Input, Doc>, _QueryOfDoc extends QueryOf<Doc> = QueryOf<Doc>, _FindQueryOption extends FindQueryOption<Sort, Obj> = FindQueryOption<Sort, Obj>, _ListQueryOption extends ListQueryOption<Sort, Obj> = ListQueryOption<Sort, Obj>> = {
67
67
  logger: Logger;
68
68
  __databaseModel: Model;
69
69
  __list(query?: _QueryOfDoc, queryOption?: _ListQueryOption): Promise<Doc[]>;
@@ -87,8 +87,8 @@ type DatabaseServiceWithQuerySort<T extends string, Input, Doc, Obj, Model, Insi
87
87
  _postUpdate(doc: Doc): Promise<Doc> | Doc;
88
88
  _preRemove(id: string): Promise<void> | void;
89
89
  _postRemove(doc: Doc): Promise<Doc> | Doc;
90
- _preSummarize(): PromiseOrObject<Partial<Summary>>;
91
- summarize(): Promise<Summary>;
90
+ listenPre: (type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => () => void;
91
+ listenPost: (type: SaveEventType, listener: (doc: Doc, type: CRUDEventType) => PromiseOrObject<void>) => () => void;
92
92
  } & Prettify<{
93
93
  [key in `${T}Model`]: Model;
94
94
  } & {
@@ -113,9 +113,6 @@ type DatabaseServiceWithQuerySort<T extends string, Input, Doc, Obj, Model, Insi
113
113
  } & {
114
114
  [K in `searchCount${_CapitalizedT}`]: (searchText: string) => Promise<number>;
115
115
  } & QueryMethodPart<Query, Sort, Obj, Doc, Insight, _FindQueryOption, _ListQueryOption>>;
116
- export declare const DbService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, Summary, _CapitalizedT, _QueryOfDoc, _Query, _Sort, _DataInputOfDoc, _FindQueryOption, _ListQueryOption>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Signal = unknown, _CapitalizedT extends string = Capitalize<T>, _QueryOfDoc extends QueryOf<Doc> = QueryOf<Doc>, _Query extends GetActionObject<Filter> = GetActionObject<Filter>, _Sort extends SortOf<Filter> = SortOf<Filter>, _DataInputOfDoc extends DataInputOf<Input, Doc> = DataInputOf<Input, Doc>, _FindQueryOption extends FindQueryOption<_Sort, Obj> = FindQueryOption<_Sort, Obj>, _ListQueryOption extends ListQueryOption<_Sort, Obj> = ListQueryOption<_Sort, Obj>>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, sigRef?: Type<Signal>) => Type<DatabaseService<T, Input, Doc, Obj, Model, Insight, Filter, Summary>>;
117
- export declare const ExtendedUserService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, Summary>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Srv, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, srvRef: Type<Srv>, sigRef?: Type<Signal>) => Type<DatabaseService<T, Input, Doc, BaseObject, Model, Insight, Filter, Summary> & { [K in keyof Srv]: Srv[K] extends (...args: infer Args) => Promise<BaseObject> ? (...args: Args) => Promise<Doc> : Srv[K] extends (...args: infer Args) => Promise<BaseObject[]> ? (...args: Args) => Promise<Doc[]> : Srv[K] extends BaseObject ? Doc : Srv[K] extends BaseObject[] ? Doc[] : Srv[K]; }>;
118
- export declare const ExtendedSummaryService: <T extends string, Input, Doc extends HydratedDocument<any>, Model, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Srv, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, srvRef: Type<Srv>, sigRef?: Type<Signal>) => Type<Omit<DatabaseService<T, Input, Doc, Obj, Model, Insight, Filter, Summary> & { [K in keyof Srv]: Srv[K] extends (...args: infer Args) => Promise<BaseObject> ? (...args: Args) => Promise<Doc> : Srv[K] extends (...args: infer Args) => Promise<BaseObject[]> ? (...args: Args) => Promise<Doc[]> : Srv[K] extends BaseObject ? Doc : Srv[K] extends BaseObject[] ? Doc[] : Srv[K]; }, "userService">>;
119
- export declare const ExtendedSettingService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, Summary>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Srv, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, srvRef: Type<Srv>, sigRef?: Type<Signal>) => Type<DatabaseService<T, Input, Doc, BaseObject, Model, Insight, Filter, Summary> & { [K in keyof Srv]: Srv[K] extends (...args: infer Args) => Promise<BaseObject> ? (...args: Args) => Promise<Doc> : Srv[K] extends (...args: infer Args) => Promise<BaseObject[]> ? (...args: Args) => Promise<Doc[]> : Srv[K] extends BaseObject ? Doc : Srv[K] extends BaseObject[] ? Doc[] : Srv[K]; }>;
116
+ export declare const DbService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, _CapitalizedT, _QueryOfDoc, _Query, _Sort, _DataInputOfDoc, _FindQueryOption, _ListQueryOption>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, LibSrvs extends Type[], _CapitalizedT extends string = Capitalize<T>, _QueryOfDoc extends QueryOf<Doc> = QueryOf<Doc>, _Query extends GetActionObject<Filter> = GetActionObject<Filter>, _Sort extends SortOf<Filter> = SortOf<Filter>, _DataInputOfDoc extends DataInputOf<Input, Doc> = DataInputOf<Input, Doc>, _FindQueryOption extends FindQueryOption<_Sort, Obj> = FindQueryOption<_Sort, Obj>, _ListQueryOption extends ListQueryOption<_Sort, Obj> = ListQueryOption<_Sort, Obj>, _DocObjectOfDoc = GetDocObject<Doc>, _MixedLibSrv = MergeAllTypes<LibSrvs>>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter>, ...libSrvRefs: LibSrvs) => Type<DatabaseService<T, Input, Doc, Obj, Model, Insight, Filter> & { [K in keyof _MixedLibSrv]: _MixedLibSrv[K] extends (...args: infer Args) => Promise<infer Value> ? Value extends (infer SingleValue)[] ? SingleValue extends DbDoc<any> ? _DocObjectOfDoc extends GetDocObject<SingleValue> ? (...args: Args) => Promise<Doc[]> : _MixedLibSrv[K] : _MixedLibSrv[K] : Value extends DbDoc<any> ? _DocObjectOfDoc extends GetDocObject<Value> ? (...args: Args) => Promise<Doc> : _MixedLibSrv[K] : _MixedLibSrv[K] : _MixedLibSrv[K]; }>;
120
117
  export declare const makeProvidersForSrv: (srvRef: Type) => Provider[];
121
118
  export {};