sonamu 0.4.7 → 0.4.9
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/dist/bin/cli.js +51 -51
- package/dist/bin/cli.mjs +2 -2
- package/dist/{chunk-54T42DSA.js → chunk-2VEHSKNA.js} +55 -43
- package/dist/chunk-2VEHSKNA.js.map +1 -0
- package/dist/{chunk-5CB4CKVQ.mjs → chunk-AK547YMV.mjs} +2 -2
- package/dist/{chunk-JNQQ3K3E.js → chunk-GHF56FO6.js} +7 -7
- package/dist/{chunk-COZNUCYR.js → chunk-IDNBP4MH.js} +4 -4
- package/dist/{chunk-YOH4CHWQ.mjs → chunk-IV7ZWWBN.mjs} +36 -24
- package/dist/chunk-IV7ZWWBN.mjs.map +1 -0
- package/dist/{chunk-VOEEO52Y.mjs → chunk-L3RJSG2K.mjs} +2 -2
- package/dist/{chunk-6HM2HY4W.js → chunk-LD7OHPVK.js} +100 -100
- package/dist/{chunk-HRZ23FCT.mjs → chunk-OTL37JQ4.mjs} +2 -2
- package/dist/database/drivers/knex/base-model.js +8 -8
- package/dist/database/drivers/knex/base-model.mjs +3 -3
- package/dist/database/drivers/kysely/base-model.js +9 -9
- package/dist/database/drivers/kysely/base-model.mjs +3 -3
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -7
- package/dist/index.mjs +3 -3
- package/package.json +1 -1
- package/src/api/sonamu.ts +43 -25
- package/src/entity/entity-manager.ts +1 -1
- package/src/templates/generated.template.ts +1 -1
- package/dist/chunk-54T42DSA.js.map +0 -1
- package/dist/chunk-YOH4CHWQ.mjs.map +0 -1
- /package/dist/{chunk-5CB4CKVQ.mjs.map → chunk-AK547YMV.mjs.map} +0 -0
- /package/dist/{chunk-JNQQ3K3E.js.map → chunk-GHF56FO6.js.map} +0 -0
- /package/dist/{chunk-COZNUCYR.js.map → chunk-IDNBP4MH.js.map} +0 -0
- /package/dist/{chunk-VOEEO52Y.mjs.map → chunk-L3RJSG2K.mjs.map} +0 -0
- /package/dist/{chunk-6HM2HY4W.js.map → chunk-LD7OHPVK.js.map} +0 -0
- /package/dist/{chunk-HRZ23FCT.mjs.map → chunk-OTL37JQ4.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
DB,
|
|
3
3
|
EntityManager,
|
|
4
4
|
nonNullable
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-IV7ZWWBN.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-
|
|
280
|
+
//# sourceMappingURL=chunk-AK547YMV.mjs.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk2VEHSKNAjs = require('./chunk-2VEHSKNA.js');
|
|
6
6
|
|
|
7
7
|
// src/database/upsert-builder.ts
|
|
8
8
|
var _uuid = require('uuid');
|
|
@@ -20,7 +20,7 @@ async function batchUpdate(db, tableName, ids, rows, chunkSize = 50, trx = null)
|
|
|
20
20
|
};
|
|
21
21
|
if (trx) {
|
|
22
22
|
for (const chunk of chunks) {
|
|
23
|
-
await executeUpdate(chunk,
|
|
23
|
+
await executeUpdate(chunk, _chunk2VEHSKNAjs.DB.toClient(trx));
|
|
24
24
|
}
|
|
25
25
|
} else {
|
|
26
26
|
await db.trx(async (newTrx) => {
|
|
@@ -87,7 +87,7 @@ var UpsertBuilder = class {
|
|
|
87
87
|
if (table === void 0) {
|
|
88
88
|
const tableSpec = (() => {
|
|
89
89
|
try {
|
|
90
|
-
return
|
|
90
|
+
return _chunk2VEHSKNAjs.EntityManager.getTableSpec(tableName);
|
|
91
91
|
} catch (e) {
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
@@ -119,7 +119,7 @@ var UpsertBuilder = class {
|
|
|
119
119
|
return null;
|
|
120
120
|
}
|
|
121
121
|
return uniqueKeyArray.join("---delimiter--");
|
|
122
|
-
}).filter(
|
|
122
|
+
}).filter(_chunk2VEHSKNAjs.nonNullable);
|
|
123
123
|
const uuid = (() => {
|
|
124
124
|
if (uniqueKeys.length > 0) {
|
|
125
125
|
for (const uniqueKey of uniqueKeys) {
|
|
@@ -180,7 +180,7 @@ var UpsertBuilder = class {
|
|
|
180
180
|
)) {
|
|
181
181
|
throw new Error(`${tableName} \uD574\uACB0\uB418\uC9C0 \uC54A\uC740 \uCC38\uC870\uAC00 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
182
182
|
}
|
|
183
|
-
const wdb =
|
|
183
|
+
const wdb = _chunk2VEHSKNAjs.DB.toClient(_wdb);
|
|
184
184
|
const { references, refTables } = Array.from(this.tables).reduce(
|
|
185
185
|
(r, [, table2]) => {
|
|
186
186
|
const reference = Array.from(table2.references.values()).find(
|
|
@@ -264,7 +264,7 @@ var UpsertBuilder = class {
|
|
|
264
264
|
return row;
|
|
265
265
|
});
|
|
266
266
|
await batchUpdate(
|
|
267
|
-
|
|
267
|
+
_chunk2VEHSKNAjs.DB.toClient(wdb),
|
|
268
268
|
tableName,
|
|
269
269
|
whereColumns,
|
|
270
270
|
rows,
|
|
@@ -277,4 +277,4 @@ var UpsertBuilder = class {
|
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
exports.isRefField = isRefField; exports.UpsertBuilder = UpsertBuilder;
|
|
280
|
-
//# sourceMappingURL=chunk-
|
|
280
|
+
//# sourceMappingURL=chunk-GHF56FO6.js.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
|
|
3
|
+
var _chunk2VEHSKNAjs = require('./chunk-2VEHSKNA.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, () => (
|
|
57
|
-
const dbClient =
|
|
56
|
+
const db = _nullishCoalesce(_db, () => ( _chunk2VEHSKNAjs.DB.getDB(subset.startsWith("A") ? "w" : "r")));
|
|
57
|
+
const dbClient = _chunk2VEHSKNAjs.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-
|
|
231
|
+
//# sourceMappingURL=chunk-IDNBP4MH.js.map
|
|
@@ -1076,7 +1076,7 @@ var Template__generated = class extends Template {
|
|
|
1076
1076
|
}
|
|
1077
1077
|
return {
|
|
1078
1078
|
lines: [...result.lines, `// ${ts2.label}`, ...ts2.lines, ""],
|
|
1079
|
-
importKeys: _2.uniq([...result.importKeys, ...ts2.importKeys])
|
|
1079
|
+
importKeys: _2.uniq([...result.importKeys, ...ts2.importKeys].sort())
|
|
1080
1080
|
};
|
|
1081
1081
|
},
|
|
1082
1082
|
{
|
|
@@ -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
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
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
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
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
|
});
|
|
@@ -6742,7 +6754,7 @@ var EntityManagerClass = class {
|
|
|
6742
6754
|
return entity !== void 0;
|
|
6743
6755
|
}
|
|
6744
6756
|
getAllIds() {
|
|
6745
|
-
return Array.from(EntityManager.entities.keys());
|
|
6757
|
+
return Array.from(EntityManager.entities.keys()).sort();
|
|
6746
6758
|
}
|
|
6747
6759
|
getAllParentIds() {
|
|
6748
6760
|
return this.getAllIds().filter((entityId) => {
|
|
@@ -7528,4 +7540,4 @@ export {
|
|
|
7528
7540
|
isTest,
|
|
7529
7541
|
Sonamu
|
|
7530
7542
|
};
|
|
7531
|
-
//# sourceMappingURL=chunk-
|
|
7543
|
+
//# sourceMappingURL=chunk-IV7ZWWBN.mjs.map
|