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
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkIDNBP4MHjs = require('../../../chunk-IDNBP4MH.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkGHF56FO6js = require('../../../chunk-GHF56FO6.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunk2VEHSKNAjs = require('../../../chunk-2VEHSKNA.js');
|
|
11
11
|
|
|
12
12
|
// src/database/drivers/knex/base-model.ts
|
|
13
|
-
var BaseModelClass = class extends
|
|
13
|
+
var BaseModelClass = class extends _chunkIDNBP4MHjs.BaseModelClassAbstract {
|
|
14
14
|
getDB(which) {
|
|
15
|
-
return
|
|
15
|
+
return _chunk2VEHSKNAjs.DB.getDB(which);
|
|
16
16
|
}
|
|
17
17
|
async destroy() {
|
|
18
|
-
return
|
|
18
|
+
return _chunk2VEHSKNAjs.DB.destroy();
|
|
19
19
|
}
|
|
20
20
|
getUpsertBuilder() {
|
|
21
|
-
return new (0,
|
|
21
|
+
return new (0, _chunkGHF56FO6js.UpsertBuilder)();
|
|
22
22
|
}
|
|
23
23
|
applyJoins(clonedQb, joins) {
|
|
24
24
|
for (const join of joins) {
|
|
25
|
-
if (
|
|
25
|
+
if (_chunk2VEHSKNAjs.isCustomJoinClause.call(void 0, join)) {
|
|
26
26
|
if (join.join === "inner") {
|
|
27
27
|
clonedQb.qb = clonedQb.qb.innerJoin(
|
|
28
28
|
`${join.table} as ${join.as}`,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseModelClassAbstract
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-L3RJSG2K.mjs";
|
|
4
4
|
import {
|
|
5
5
|
UpsertBuilder
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-AK547YMV.mjs";
|
|
7
7
|
import {
|
|
8
8
|
DB,
|
|
9
9
|
isCustomJoinClause
|
|
10
|
-
} from "../../../chunk-
|
|
10
|
+
} from "../../../chunk-IV7ZWWBN.mjs";
|
|
11
11
|
import "../../../chunk-PTFDTOJU.mjs";
|
|
12
12
|
|
|
13
13
|
// src/database/drivers/knex/base-model.ts
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkIDNBP4MHjs = require('../../../chunk-IDNBP4MH.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkGHF56FO6js = require('../../../chunk-GHF56FO6.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunk2VEHSKNAjs = require('../../../chunk-2VEHSKNA.js');
|
|
12
12
|
|
|
13
13
|
// src/database/drivers/kysely/base-model.ts
|
|
14
14
|
var _inflection = require('inflection'); var _inflection2 = _interopRequireDefault(_inflection);
|
|
15
|
-
var BaseModelClass = class extends
|
|
15
|
+
var BaseModelClass = class extends _chunkIDNBP4MHjs.BaseModelClassAbstract {
|
|
16
16
|
getDB(which) {
|
|
17
|
-
return
|
|
17
|
+
return _chunk2VEHSKNAjs.DB.getDB(which);
|
|
18
18
|
}
|
|
19
19
|
async destroy() {
|
|
20
|
-
return
|
|
20
|
+
return _chunk2VEHSKNAjs.DB.destroy();
|
|
21
21
|
}
|
|
22
22
|
getUpsertBuilder() {
|
|
23
|
-
return new (0,
|
|
23
|
+
return new (0, _chunkGHF56FO6js.UpsertBuilder)();
|
|
24
24
|
}
|
|
25
25
|
applyJoins(clonedQb, joins) {
|
|
26
26
|
for (const join of joins) {
|
|
27
|
-
if (
|
|
27
|
+
if (_chunk2VEHSKNAjs.isCustomJoinClause.call(void 0, join)) {
|
|
28
28
|
throw new Error("Custom join clause is not supported in Kysely");
|
|
29
29
|
}
|
|
30
30
|
if (join.join === "inner") {
|
|
@@ -48,7 +48,7 @@ var BaseModelClass = class extends _chunkCOZNUCYRjs.BaseModelClassAbstract {
|
|
|
48
48
|
if (!column) {
|
|
49
49
|
throw new Error("parseOrderBy: Invalid column");
|
|
50
50
|
}
|
|
51
|
-
const entity =
|
|
51
|
+
const entity = _chunk2VEHSKNAjs.EntityManager.get(_inflection2.default.classify(table));
|
|
52
52
|
if (!entity.props.find((p) => p.name === column)) {
|
|
53
53
|
throw new Error("parseOrderBy: \uD604\uC7AC \uC5D4\uD2F0\uD2F0\uC5D0 \uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uCEEC\uB7FC\uC785\uB2C8\uB2E4: ");
|
|
54
54
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseModelClassAbstract
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-L3RJSG2K.mjs";
|
|
4
4
|
import {
|
|
5
5
|
UpsertBuilder
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-AK547YMV.mjs";
|
|
7
7
|
import {
|
|
8
8
|
DB,
|
|
9
9
|
EntityManager,
|
|
10
10
|
isCustomJoinClause
|
|
11
|
-
} from "../../../chunk-
|
|
11
|
+
} from "../../../chunk-IV7ZWWBN.mjs";
|
|
12
12
|
import "../../../chunk-PTFDTOJU.mjs";
|
|
13
13
|
|
|
14
14
|
// src/database/drivers/kysely/base-model.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ import { HTTPMethods, FastifyReply, FastifyInstance, FastifyRequest } from 'fast
|
|
|
5
5
|
import { RouteGenericInterface } from 'fastify/types/route';
|
|
6
6
|
import { Server, IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
|
|
7
7
|
import ts from 'typescript';
|
|
8
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
8
9
|
import knex, { Knex } from 'knex';
|
|
9
10
|
import * as kysely from 'kysely';
|
|
10
11
|
import { Kysely } from 'kysely';
|
|
@@ -305,6 +306,10 @@ type SonamuFastifyConfig = {
|
|
|
305
306
|
};
|
|
306
307
|
declare class SonamuClass {
|
|
307
308
|
isInitialized: boolean;
|
|
309
|
+
asyncLocalStorage: AsyncLocalStorage<{
|
|
310
|
+
context: Context;
|
|
311
|
+
}>;
|
|
312
|
+
getContext(): Context;
|
|
308
313
|
private _apiRootPath;
|
|
309
314
|
set apiRootPath(apiRootPath: string);
|
|
310
315
|
get apiRootPath(): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { HTTPMethods, FastifyReply, FastifyInstance, FastifyRequest } from 'fast
|
|
|
5
5
|
import { RouteGenericInterface } from 'fastify/types/route';
|
|
6
6
|
import { Server, IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
|
|
7
7
|
import ts from 'typescript';
|
|
8
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
8
9
|
import knex, { Knex } from 'knex';
|
|
9
10
|
import * as kysely from 'kysely';
|
|
10
11
|
import { Kysely } from 'kysely';
|
|
@@ -305,6 +306,10 @@ type SonamuFastifyConfig = {
|
|
|
305
306
|
};
|
|
306
307
|
declare class SonamuClass {
|
|
307
308
|
isInitialized: boolean;
|
|
309
|
+
asyncLocalStorage: AsyncLocalStorage<{
|
|
310
|
+
context: Context;
|
|
311
|
+
}>;
|
|
312
|
+
getContext(): Context;
|
|
308
313
|
private _apiRootPath;
|
|
309
314
|
set apiRootPath(apiRootPath: string);
|
|
310
315
|
get apiRootPath(): string;
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkLD7OHPVKjs = require('./chunk-LD7OHPVK.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkGHF56FO6js = require('./chunk-GHF56FO6.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -88,13 +88,13 @@ var _chunkJNQQ3K3Ejs = require('./chunk-JNQQ3K3E.js');
|
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
|
|
91
|
-
var
|
|
91
|
+
var _chunk2VEHSKNAjs = require('./chunk-2VEHSKNA.js');
|
|
92
92
|
|
|
93
93
|
// src/exceptions/error-handler.ts
|
|
94
94
|
function setupErrorHandler(server) {
|
|
95
95
|
server.setErrorHandler((error, request, reply) => {
|
|
96
96
|
error.statusCode ??= 400;
|
|
97
|
-
if (
|
|
97
|
+
if (_chunk2VEHSKNAjs.isSoException.call(void 0, error) && error.payload && Array.isArray(error.payload)) {
|
|
98
98
|
const issues = error.payload;
|
|
99
99
|
const [issue] = issues;
|
|
100
100
|
const message = `${issue.message} (${issue.path.join("/")})`;
|
|
@@ -316,13 +316,13 @@ var i = {
|
|
|
316
316
|
function index(columns) {
|
|
317
317
|
return {
|
|
318
318
|
type: "index",
|
|
319
|
-
columns:
|
|
319
|
+
columns: _chunk2VEHSKNAjs.asArray.call(void 0, columns)
|
|
320
320
|
};
|
|
321
321
|
}
|
|
322
322
|
function unique(columns) {
|
|
323
323
|
return {
|
|
324
324
|
type: "unique",
|
|
325
|
-
columns:
|
|
325
|
+
columns: _chunk2VEHSKNAjs.asArray.call(void 0, columns)
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -414,5 +414,5 @@ function unique(columns) {
|
|
|
414
414
|
|
|
415
415
|
|
|
416
416
|
|
|
417
|
-
exports.AlreadyProcessedException =
|
|
417
|
+
exports.AlreadyProcessedException = _chunk2VEHSKNAjs.AlreadyProcessedException; exports.ApiParamType = _chunk2VEHSKNAjs.ApiParamType; exports.BadRequestException = _chunk2VEHSKNAjs.BadRequestException; exports.DB = _chunk2VEHSKNAjs.DB; exports.DBKnexClass = _chunk2VEHSKNAjs.DBKnexClass; exports.DBKyselyClass = _chunk2VEHSKNAjs.DBKyselyClass; exports.DuplicateRowException = _chunk2VEHSKNAjs.DuplicateRowException; exports.Entity = _chunk2VEHSKNAjs.Entity; exports.EntityManager = _chunk2VEHSKNAjs.EntityManager; exports.FixtureManager = _chunkLD7OHPVKjs.FixtureManager; exports.FixtureManagerClass = _chunkLD7OHPVKjs.FixtureManagerClass; exports.GenerateOptions = _chunk2VEHSKNAjs.GenerateOptions; exports.InternalServerErrorException = _chunk2VEHSKNAjs.InternalServerErrorException; exports.Migrator = _chunkLD7OHPVKjs.Migrator; exports.NotFoundException = _chunk2VEHSKNAjs.NotFoundException; exports.PathAndCode = _chunk2VEHSKNAjs.PathAndCode; exports.RenderingNode = _chunk2VEHSKNAjs.RenderingNode; exports.SQLDateTimeString = _chunk2VEHSKNAjs.SQLDateTimeString; exports.ServiceUnavailableException = _chunk2VEHSKNAjs.ServiceUnavailableException; exports.SoException = _chunk2VEHSKNAjs.SoException; exports.Sonamu = _chunk2VEHSKNAjs.Sonamu; exports.SonamuQueryMode = _chunk2VEHSKNAjs.SonamuQueryMode; exports.Syncer = _chunk2VEHSKNAjs.Syncer; exports.TargetNotFoundException = _chunk2VEHSKNAjs.TargetNotFoundException; exports.TemplateKey = _chunk2VEHSKNAjs.TemplateKey; exports.TemplateOptions = _chunk2VEHSKNAjs.TemplateOptions; exports.UnauthorizedException = _chunk2VEHSKNAjs.UnauthorizedException; exports.UpsertBuilder = _chunkGHF56FO6js.UpsertBuilder; exports.api = _chunk2VEHSKNAjs.api; exports.apiParamToTsCode = _chunk2VEHSKNAjs.apiParamToTsCode; exports.apiParamTypeToTsType = _chunk2VEHSKNAjs.apiParamTypeToTsType; exports.asArray = _chunk2VEHSKNAjs.asArray; exports.findApiRootPath = _chunk2VEHSKNAjs.findApiRootPath; exports.findAppRootPath = _chunk2VEHSKNAjs.findAppRootPath; exports.getTextTypeLength = _chunk2VEHSKNAjs.getTextTypeLength; exports.getZodObjectFromApi = _chunk2VEHSKNAjs.getZodObjectFromApi; exports.getZodObjectFromApiParams = _chunk2VEHSKNAjs.getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = _chunk2VEHSKNAjs.getZodTypeFromApiParamType; exports.globAsync = _chunk2VEHSKNAjs.globAsync; exports.hydrate = _chunk2VEHSKNAjs.hydrate; exports.i = i; exports.importMultiple = _chunk2VEHSKNAjs.importMultiple; exports.isBelongsToOneRelationProp = _chunk2VEHSKNAjs.isBelongsToOneRelationProp; exports.isBigIntegerProp = _chunk2VEHSKNAjs.isBigIntegerProp; exports.isBooleanProp = _chunk2VEHSKNAjs.isBooleanProp; exports.isCustomJoinClause = _chunk2VEHSKNAjs.isCustomJoinClause; exports.isDaemonServer = _chunk2VEHSKNAjs.isDaemonServer; exports.isDateProp = _chunk2VEHSKNAjs.isDateProp; exports.isDateTimeProp = _chunk2VEHSKNAjs.isDateTimeProp; exports.isDecimalProp = _chunk2VEHSKNAjs.isDecimalProp; exports.isDevelopment = _chunk2VEHSKNAjs.isDevelopment; exports.isDoubleProp = _chunk2VEHSKNAjs.isDoubleProp; exports.isEnumProp = _chunk2VEHSKNAjs.isEnumProp; exports.isFloatProp = _chunk2VEHSKNAjs.isFloatProp; exports.isHasManyRelationProp = _chunk2VEHSKNAjs.isHasManyRelationProp; exports.isInDocker = _chunk2VEHSKNAjs.isInDocker; exports.isIntegerProp = _chunk2VEHSKNAjs.isIntegerProp; exports.isJsonProp = _chunk2VEHSKNAjs.isJsonProp; exports.isKnexError = _chunk2VEHSKNAjs.isKnexError; exports.isKyselyError = _chunk2VEHSKNAjs.isKyselyError; exports.isLocal = _chunk2VEHSKNAjs.isLocal; exports.isManyToManyRelationProp = _chunk2VEHSKNAjs.isManyToManyRelationProp; exports.isOneToOneRelationProp = _chunk2VEHSKNAjs.isOneToOneRelationProp; exports.isProduction = _chunk2VEHSKNAjs.isProduction; exports.isRefField = _chunkGHF56FO6js.isRefField; exports.isRelationProp = _chunk2VEHSKNAjs.isRelationProp; exports.isRemote = _chunk2VEHSKNAjs.isRemote; exports.isSoException = _chunk2VEHSKNAjs.isSoException; exports.isStaging = _chunk2VEHSKNAjs.isStaging; exports.isStringProp = _chunk2VEHSKNAjs.isStringProp; exports.isTest = _chunk2VEHSKNAjs.isTest; exports.isTextProp = _chunk2VEHSKNAjs.isTextProp; exports.isTimeProp = _chunk2VEHSKNAjs.isTimeProp; exports.isTimestampProp = _chunk2VEHSKNAjs.isTimestampProp; exports.isUuidProp = _chunk2VEHSKNAjs.isUuidProp; exports.isVirtualProp = _chunk2VEHSKNAjs.isVirtualProp; exports.nonNullable = _chunk2VEHSKNAjs.nonNullable; exports.objToMap = _chunk2VEHSKNAjs.objToMap; exports.p = p; exports.propNodeToZodTypeDef = _chunk2VEHSKNAjs.propNodeToZodTypeDef; exports.propToZodTypeDef = _chunk2VEHSKNAjs.propToZodTypeDef; exports.registeredApis = _chunk2VEHSKNAjs.registeredApis; exports.serializeZodType = _chunk2VEHSKNAjs.serializeZodType; exports.setupErrorHandler = setupErrorHandler; exports.unwrapPromiseOnce = _chunk2VEHSKNAjs.unwrapPromiseOnce; exports.zArrayable = _chunk2VEHSKNAjs.zArrayable; exports.zodTypeToTsTypeDef = _chunk2VEHSKNAjs.zodTypeToTsTypeDef; exports.zodTypeToZodCode = _chunk2VEHSKNAjs.zodTypeToZodCode;
|
|
418
418
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
FixtureManager,
|
|
3
3
|
FixtureManagerClass,
|
|
4
4
|
Migrator
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-OTL37JQ4.mjs";
|
|
6
6
|
import {
|
|
7
7
|
UpsertBuilder,
|
|
8
8
|
isRefField
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AK547YMV.mjs";
|
|
10
10
|
import {
|
|
11
11
|
AlreadyProcessedException,
|
|
12
12
|
ApiParamType,
|
|
@@ -88,7 +88,7 @@ import {
|
|
|
88
88
|
zArrayable,
|
|
89
89
|
zodTypeToTsTypeDef,
|
|
90
90
|
zodTypeToZodCode
|
|
91
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-IV7ZWWBN.mjs";
|
|
92
92
|
import "./chunk-PTFDTOJU.mjs";
|
|
93
93
|
|
|
94
94
|
// src/exceptions/error-handler.ts
|
package/package.json
CHANGED
package/src/api/sonamu.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { ApiDecoratorOptions } from "./decorators";
|
|
|
17
17
|
import { humanizeZodError } from "../utils/zod-error";
|
|
18
18
|
import { DatabaseDriver, SonamuDBConfig } from "../database/types";
|
|
19
19
|
import { DB } from "../database/db";
|
|
20
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
20
21
|
|
|
21
22
|
export type SonamuConfig = {
|
|
22
23
|
projectName?: string;
|
|
@@ -73,6 +74,17 @@ type SonamuFastifyConfig = {
|
|
|
73
74
|
};
|
|
74
75
|
class SonamuClass {
|
|
75
76
|
public isInitialized: boolean = false;
|
|
77
|
+
public asyncLocalStorage: AsyncLocalStorage<{
|
|
78
|
+
context: Context;
|
|
79
|
+
}> = new AsyncLocalStorage();
|
|
80
|
+
|
|
81
|
+
public getContext(): Context {
|
|
82
|
+
const store = this.asyncLocalStorage.getStore();
|
|
83
|
+
if (store?.context) {
|
|
84
|
+
return store.context;
|
|
85
|
+
}
|
|
86
|
+
throw new Error("Sonamu cannot find context");
|
|
87
|
+
}
|
|
76
88
|
|
|
77
89
|
private _apiRootPath: string | null = null;
|
|
78
90
|
set apiRootPath(apiRootPath: string) {
|
|
@@ -214,7 +226,10 @@ class SonamuClass {
|
|
|
214
226
|
async withFastify(
|
|
215
227
|
server: FastifyInstance<Server, IncomingMessage, ServerResponse>,
|
|
216
228
|
config: SonamuFastifyConfig,
|
|
217
|
-
options?: {
|
|
229
|
+
options?: {
|
|
230
|
+
enableSync?: boolean;
|
|
231
|
+
doSilent?: boolean;
|
|
232
|
+
}
|
|
218
233
|
) {
|
|
219
234
|
if (this.isInitialized === false) {
|
|
220
235
|
await this.init(options?.doSilent, options?.enableSync);
|
|
@@ -301,32 +316,35 @@ class SonamuClass {
|
|
|
301
316
|
return cachedData;
|
|
302
317
|
}
|
|
303
318
|
|
|
304
|
-
// 결과
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
headers: request.headers,
|
|
313
|
-
reply,
|
|
314
|
-
},
|
|
315
|
-
request,
|
|
316
|
-
reply
|
|
317
|
-
);
|
|
318
|
-
} else {
|
|
319
|
-
return reqBody[param.name];
|
|
320
|
-
}
|
|
321
|
-
})
|
|
319
|
+
// 결과 (AsyncLocalStorage 적용)
|
|
320
|
+
const context = config.contextProvider(
|
|
321
|
+
{
|
|
322
|
+
headers: request.headers,
|
|
323
|
+
reply,
|
|
324
|
+
},
|
|
325
|
+
request,
|
|
326
|
+
reply
|
|
322
327
|
);
|
|
323
|
-
|
|
328
|
+
return this.asyncLocalStorage.run({ context }, async () => {
|
|
329
|
+
const result = await (model as any)[api.methodName].apply(
|
|
330
|
+
model,
|
|
331
|
+
api.parameters.map((param) => {
|
|
332
|
+
// Context 인젝션
|
|
333
|
+
if (ApiParamType.isContext(param.type)) {
|
|
334
|
+
return context;
|
|
335
|
+
} else {
|
|
336
|
+
return reqBody[param.name];
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
);
|
|
340
|
+
reply.type(api.options.contentType ?? "application/json");
|
|
324
341
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
342
|
+
// 캐시 키 있는 경우 갱신 후 저장
|
|
343
|
+
if (config.cache && cacheKey) {
|
|
344
|
+
await config.cache.put(cacheKey, result, cacheTtl);
|
|
345
|
+
}
|
|
346
|
+
return result;
|
|
347
|
+
});
|
|
330
348
|
},
|
|
331
349
|
}); // END server.route
|
|
332
350
|
});
|
|
@@ -72,7 +72,7 @@ export class Template__generated extends Template {
|
|
|
72
72
|
}
|
|
73
73
|
return {
|
|
74
74
|
lines: [...result!.lines, `// ${ts.label}`, ...ts.lines, ""],
|
|
75
|
-
importKeys: _.uniq([...result!.importKeys, ...ts.importKeys]),
|
|
75
|
+
importKeys: _.uniq([...result!.importKeys, ...ts.importKeys].sort()),
|
|
76
76
|
};
|
|
77
77
|
},
|
|
78
78
|
{
|