sonamu 0.4.7 → 0.4.8

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.
Files changed (30) hide show
  1. package/dist/bin/cli.js +51 -51
  2. package/dist/bin/cli.mjs +2 -2
  3. package/dist/{chunk-54T42DSA.js → chunk-FXWN5PEO.js} +53 -41
  4. package/dist/chunk-FXWN5PEO.js.map +1 -0
  5. package/dist/{chunk-HRZ23FCT.mjs → chunk-GQVZQZ5J.mjs} +2 -2
  6. package/dist/{chunk-5CB4CKVQ.mjs → chunk-IEP5SWTY.mjs} +2 -2
  7. package/dist/{chunk-COZNUCYR.js → chunk-IEXW7P6A.js} +4 -4
  8. package/dist/{chunk-VOEEO52Y.mjs → chunk-OBPWSOYN.mjs} +2 -2
  9. package/dist/{chunk-YOH4CHWQ.mjs → chunk-VBBKB2LD.mjs} +34 -22
  10. package/dist/chunk-VBBKB2LD.mjs.map +1 -0
  11. package/dist/{chunk-JNQQ3K3E.js → chunk-WZJODZL6.js} +7 -7
  12. package/dist/{chunk-6HM2HY4W.js → chunk-ZNWZQLRN.js} +100 -100
  13. package/dist/database/drivers/knex/base-model.js +8 -8
  14. package/dist/database/drivers/knex/base-model.mjs +3 -3
  15. package/dist/database/drivers/kysely/base-model.js +9 -9
  16. package/dist/database/drivers/kysely/base-model.mjs +3 -3
  17. package/dist/index.d.mts +5 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +7 -7
  20. package/dist/index.mjs +3 -3
  21. package/package.json +1 -1
  22. package/src/api/sonamu.ts +43 -25
  23. package/dist/chunk-54T42DSA.js.map +0 -1
  24. package/dist/chunk-YOH4CHWQ.mjs.map +0 -1
  25. /package/dist/{chunk-HRZ23FCT.mjs.map → chunk-GQVZQZ5J.mjs.map} +0 -0
  26. /package/dist/{chunk-5CB4CKVQ.mjs.map → chunk-IEP5SWTY.mjs.map} +0 -0
  27. /package/dist/{chunk-COZNUCYR.js.map → chunk-IEXW7P6A.js.map} +0 -0
  28. /package/dist/{chunk-VOEEO52Y.mjs.map → chunk-OBPWSOYN.mjs.map} +0 -0
  29. /package/dist/{chunk-JNQQ3K3E.js.map → chunk-WZJODZL6.js.map} +0 -0
  30. /package/dist/{chunk-6HM2HY4W.js.map → chunk-ZNWZQLRN.js.map} +0 -0
@@ -16,7 +16,7 @@ import {
16
16
  isStringProp,
17
17
  isTextProp,
18
18
  isVirtualProp
19
- } from "./chunk-YOH4CHWQ.mjs";
19
+ } from "./chunk-VBBKB2LD.mjs";
20
20
 
21
21
  // src/entity/migrator.ts
22
22
  import _ from "lodash";
@@ -1576,4 +1576,4 @@ export {
1576
1576
  FixtureManagerClass,
1577
1577
  FixtureManager
1578
1578
  };
1579
- //# sourceMappingURL=chunk-HRZ23FCT.mjs.map
1579
+ //# sourceMappingURL=chunk-GQVZQZ5J.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  DB,
3
3
  EntityManager,
4
4
  nonNullable
5
- } from "./chunk-YOH4CHWQ.mjs";
5
+ } from "./chunk-VBBKB2LD.mjs";
6
6
 
7
7
  // src/database/upsert-builder.ts
8
8
  import { v4 as uuidv4 } from "uuid";
@@ -277,4 +277,4 @@ export {
277
277
  isRefField,
278
278
  UpsertBuilder
279
279
  };
280
- //# sourceMappingURL=chunk-5CB4CKVQ.mjs.map
280
+ //# sourceMappingURL=chunk-IEP5SWTY.mjs.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
2
 
3
- var _chunk54T42DSAjs = require('./chunk-54T42DSA.js');
3
+ var _chunkFXWN5PEOjs = require('./chunk-FXWN5PEO.js');
4
4
 
5
5
  // src/database/base-model.ts
6
6
  var _luxon = require('luxon');
@@ -53,8 +53,8 @@ var BaseModelClassAbstract = (_class = class {constructor() { _class.prototype._
53
53
  db: _db,
54
54
  optimizeCountQuery
55
55
  }) {
56
- const db = _nullishCoalesce(_db, () => ( _chunk54T42DSAjs.DB.getDB(subset.startsWith("A") ? "w" : "r")));
57
- const dbClient = _chunk54T42DSAjs.DB.toClient(db);
56
+ const db = _nullishCoalesce(_db, () => ( _chunkFXWN5PEOjs.DB.getDB(subset.startsWith("A") ? "w" : "r")));
57
+ const dbClient = _chunkFXWN5PEOjs.DB.toClient(db);
58
58
  baseTable = _nullishCoalesce(baseTable, () => ( _inflection2.default.pluralize(_inflection2.default.underscore(this.modelName))));
59
59
  const queryMode = _nullishCoalesce(params.queryMode, () => ( (params.id !== void 0 ? "list" : "both")));
60
60
  const { select, virtual, joins, loaders } = subsetQuery;
@@ -228,4 +228,4 @@ var BaseModelClassAbstract = (_class = class {constructor() { _class.prototype._
228
228
 
229
229
 
230
230
  exports.BaseModelClassAbstract = BaseModelClassAbstract;
231
- //# sourceMappingURL=chunk-COZNUCYR.js.map
231
+ //# sourceMappingURL=chunk-IEXW7P6A.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DB
3
- } from "./chunk-YOH4CHWQ.mjs";
3
+ } from "./chunk-VBBKB2LD.mjs";
4
4
 
5
5
  // src/database/base-model.ts
6
6
  import { DateTime } from "luxon";
@@ -228,4 +228,4 @@ var BaseModelClassAbstract = class {
228
228
  export {
229
229
  BaseModelClassAbstract
230
230
  };
231
- //# sourceMappingURL=chunk-VOEEO52Y.mjs.map
231
+ //# sourceMappingURL=chunk-OBPWSOYN.mjs.map
@@ -6474,8 +6474,17 @@ function formatDateConstraint(value) {
6474
6474
  }
6475
6475
 
6476
6476
  // src/api/sonamu.ts
6477
+ import { AsyncLocalStorage } from "async_hooks";
6477
6478
  var SonamuClass = class {
6478
6479
  isInitialized = false;
6480
+ asyncLocalStorage = new AsyncLocalStorage();
6481
+ getContext() {
6482
+ const store = this.asyncLocalStorage.getStore();
6483
+ if (store?.context) {
6484
+ return store.context;
6485
+ }
6486
+ throw new Error("Sonamu cannot find context");
6487
+ }
6479
6488
  _apiRootPath = null;
6480
6489
  set apiRootPath(apiRootPath) {
6481
6490
  this._apiRootPath = apiRootPath;
@@ -6647,28 +6656,31 @@ var SonamuClass = class {
6647
6656
  if (cachedData !== null) {
6648
6657
  return cachedData;
6649
6658
  }
6650
- const result = await model[api2.methodName].apply(
6651
- model,
6652
- api2.parameters.map((param) => {
6653
- if (ApiParamType.isContext(param.type)) {
6654
- return config.contextProvider(
6655
- {
6656
- headers: request.headers,
6657
- reply
6658
- },
6659
- request,
6660
- reply
6661
- );
6662
- } else {
6663
- return reqBody[param.name];
6664
- }
6665
- })
6659
+ const context = config.contextProvider(
6660
+ {
6661
+ headers: request.headers,
6662
+ reply
6663
+ },
6664
+ request,
6665
+ reply
6666
6666
  );
6667
- reply.type(api2.options.contentType ?? "application/json");
6668
- if (config.cache && cacheKey) {
6669
- await config.cache.put(cacheKey, result, cacheTtl);
6670
- }
6671
- return result;
6667
+ return this.asyncLocalStorage.run({ context }, async () => {
6668
+ const result = await model[api2.methodName].apply(
6669
+ model,
6670
+ api2.parameters.map((param) => {
6671
+ if (ApiParamType.isContext(param.type)) {
6672
+ return context;
6673
+ } else {
6674
+ return reqBody[param.name];
6675
+ }
6676
+ })
6677
+ );
6678
+ reply.type(api2.options.contentType ?? "application/json");
6679
+ if (config.cache && cacheKey) {
6680
+ await config.cache.put(cacheKey, result, cacheTtl);
6681
+ }
6682
+ return result;
6683
+ });
6672
6684
  }
6673
6685
  });
6674
6686
  });
@@ -7528,4 +7540,4 @@ export {
7528
7540
  isTest,
7529
7541
  Sonamu
7530
7542
  };
7531
- //# sourceMappingURL=chunk-YOH4CHWQ.mjs.map
7543
+ //# sourceMappingURL=chunk-VBBKB2LD.mjs.map