sonamu 0.0.7 → 0.0.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/.pnp.cjs +13 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/init.d.ts +35 -5
- package/dist/api/init.d.ts.map +1 -1
- package/dist/api/init.js +142 -79
- package/dist/api/init.js.map +1 -1
- package/dist/api/sonamu.d.ts +42 -0
- package/dist/api/sonamu.d.ts.map +1 -0
- package/dist/api/sonamu.js +175 -0
- package/dist/api/sonamu.js.map +1 -0
- package/dist/bin/cli.js +152 -67
- package/dist/bin/cli.js.map +1 -1
- package/dist/database/db.d.ts +1 -3
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +12 -23
- package/dist/database/db.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/smd/migrator.d.ts +0 -5
- package/dist/smd/migrator.d.ts.map +1 -1
- package/dist/smd/migrator.js +18 -19
- package/dist/smd/migrator.js.map +1 -1
- package/dist/smd/smd-manager.js +2 -2
- package/dist/smd/smd-manager.js.map +1 -1
- package/dist/smd/smd.d.ts.map +1 -1
- package/dist/smd/smd.js +4 -5
- package/dist/smd/smd.js.map +1 -1
- package/dist/syncer/syncer.d.ts +8 -12
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +43 -43
- package/dist/syncer/syncer.js.map +1 -1
- package/dist/templates/generated_http.template.js +2 -2
- package/dist/templates/generated_http.template.js.map +1 -1
- package/dist/templates/init_enums.template.js +1 -1
- package/dist/templates/init_generated.template.d.ts.map +1 -1
- package/dist/templates/init_generated.template.js +8 -1
- package/dist/templates/init_generated.template.js.map +1 -1
- package/dist/templates/service.template.d.ts +1 -1
- package/dist/templates/service.template.d.ts.map +1 -1
- package/dist/templates/service.template.js +3 -2
- package/dist/templates/service.template.js.map +1 -1
- package/dist/templates/smd.template.js +2 -2
- package/dist/templates/smd.template.js.map +1 -1
- package/dist/templates/view_form.template.d.ts +2 -2
- package/dist/templates/view_list.template.d.ts +2 -2
- package/dist/testing/fixture-manager.d.ts +6 -7
- package/dist/testing/fixture-manager.d.ts.map +1 -1
- package/dist/testing/fixture-manager.js +35 -41
- package/dist/testing/fixture-manager.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +13 -3
- package/dist/utils/utils.js.map +1 -1
- package/package.json +8 -4
- package/src/api/index.ts +1 -1
- package/src/api/sonamu.ts +212 -0
- package/src/bin/cli.ts +159 -70
- package/src/database/db.ts +15 -27
- package/src/index.ts +1 -1
- package/src/smd/migrator.ts +18 -31
- package/src/smd/smd-manager.ts +3 -3
- package/src/smd/smd.ts +10 -9
- package/src/syncer/syncer.ts +49 -68
- package/src/templates/generated_http.template.ts +2 -2
- package/src/templates/init_enums.template.ts +1 -1
- package/src/templates/init_generated.template.ts +8 -1
- package/src/templates/service.template.ts +6 -5
- package/src/templates/smd.template.ts +2 -2
- package/src/testing/fixture-manager.ts +44 -53
- package/src/utils/utils.ts +9 -1
- package/src/api/init.ts +0 -129
package/src/api/init.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
3
|
-
import { IncomingMessage, Server, ServerResponse } from "http";
|
|
4
|
-
import { ZodError } from "zod";
|
|
5
|
-
import { getZodObjectFromApi } from "./code-converters";
|
|
6
|
-
import { Context } from "./context";
|
|
7
|
-
import { BadRequestException } from "../exceptions/so-exceptions";
|
|
8
|
-
import { SMDManager } from "../smd/smd-manager";
|
|
9
|
-
import { fastifyCaster } from "../api/caster";
|
|
10
|
-
import { ApiParamType } from "../types/types";
|
|
11
|
-
import { Syncer } from "../syncer/syncer";
|
|
12
|
-
import { isLocal } from "../utils/controller";
|
|
13
|
-
import { DB } from "../database/db";
|
|
14
|
-
import { BaseModel } from "../database/base-model";
|
|
15
|
-
import { findAppRootPath } from "../utils/utils";
|
|
16
|
-
|
|
17
|
-
export type SonamuInitConfig = {
|
|
18
|
-
prefix: string;
|
|
19
|
-
syncTargets: string[];
|
|
20
|
-
contextProvider: (
|
|
21
|
-
defaultContext: Pick<Context, "headers" | "reply">,
|
|
22
|
-
request: FastifyRequest,
|
|
23
|
-
reply: FastifyReply
|
|
24
|
-
) => Context;
|
|
25
|
-
};
|
|
26
|
-
export async function init(
|
|
27
|
-
server: FastifyInstance<Server, IncomingMessage, ServerResponse>,
|
|
28
|
-
config: SonamuInitConfig
|
|
29
|
-
) {
|
|
30
|
-
// 전체 라우팅 리스트
|
|
31
|
-
server.get(
|
|
32
|
-
`${config.prefix}/routes`,
|
|
33
|
-
async (_request, _reply): Promise<any> => {
|
|
34
|
-
return apis;
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// Healthcheck API
|
|
39
|
-
server.get(
|
|
40
|
-
`${config.prefix}/healthcheck`,
|
|
41
|
-
async (_request, _reply): Promise<string> => {
|
|
42
|
-
return "ok";
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// Syncer
|
|
47
|
-
const appRootPath = await findAppRootPath();
|
|
48
|
-
const syncer = Syncer.getInstance({
|
|
49
|
-
appRootPath: appRootPath,
|
|
50
|
-
targets: config.syncTargets,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// DB 설정파일 확인
|
|
54
|
-
await DB.readKnexfile();
|
|
55
|
-
console.log(chalk.green("DB Config Loaded!"));
|
|
56
|
-
|
|
57
|
-
// Autoload: SMD / Models / Types / APIs
|
|
58
|
-
console.time(chalk.cyan("autoload&sync:"));
|
|
59
|
-
await SMDManager.autoload();
|
|
60
|
-
const importedModels = await syncer.autoloadModels(appRootPath);
|
|
61
|
-
const references = await syncer.autoloadTypes(appRootPath);
|
|
62
|
-
const apis = await syncer.autoloadApis(appRootPath);
|
|
63
|
-
if (isLocal()) {
|
|
64
|
-
await syncer.sync();
|
|
65
|
-
}
|
|
66
|
-
console.timeEnd(chalk.cyan("autoload&sync:"));
|
|
67
|
-
|
|
68
|
-
// API 라우팅 등록
|
|
69
|
-
apis.map((api) => {
|
|
70
|
-
// model
|
|
71
|
-
if (importedModels[api.modelName] === undefined) {
|
|
72
|
-
throw new Error(`정의되지 않은 모델에 접근 ${api.modelName}`);
|
|
73
|
-
}
|
|
74
|
-
const model = importedModels[api.modelName];
|
|
75
|
-
|
|
76
|
-
// 파라미터 정보로 zod 스키마 빌드
|
|
77
|
-
const ReqType = getZodObjectFromApi(api, references);
|
|
78
|
-
|
|
79
|
-
// route
|
|
80
|
-
server.route({
|
|
81
|
-
method: api.options.httpMethod!,
|
|
82
|
-
url: config.prefix + api.path,
|
|
83
|
-
handler: async (request, reply): Promise<unknown> => {
|
|
84
|
-
const which = api.options.httpMethod === "GET" ? "query" : "body";
|
|
85
|
-
let reqBody: {
|
|
86
|
-
[key: string]: unknown;
|
|
87
|
-
};
|
|
88
|
-
try {
|
|
89
|
-
reqBody = fastifyCaster(ReqType).parse(request[which] ?? {});
|
|
90
|
-
} catch (e) {
|
|
91
|
-
if (e instanceof ZodError) {
|
|
92
|
-
// TODO: BadRequest 에러 핸들링 (ZodError issues를 humanize하여 출력하는 로직 필요)
|
|
93
|
-
throw new BadRequestException(
|
|
94
|
-
`${(e as ZodError).issues[0].message}`,
|
|
95
|
-
e.errors
|
|
96
|
-
);
|
|
97
|
-
} else {
|
|
98
|
-
throw e;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const result = await (model as any)[api.methodName].apply(
|
|
103
|
-
model,
|
|
104
|
-
api.parameters.map((param) => {
|
|
105
|
-
// Context 인젝션
|
|
106
|
-
if (ApiParamType.isContext(param.type)) {
|
|
107
|
-
return config.contextProvider(
|
|
108
|
-
{
|
|
109
|
-
headers: request.headers,
|
|
110
|
-
reply,
|
|
111
|
-
},
|
|
112
|
-
request,
|
|
113
|
-
reply
|
|
114
|
-
);
|
|
115
|
-
} else {
|
|
116
|
-
return reqBody[param.name];
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
reply.type(api.options.contentType ?? "application/json");
|
|
121
|
-
return result;
|
|
122
|
-
},
|
|
123
|
-
}); // END server.route
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function destroy(): Promise<void> {
|
|
128
|
-
await BaseModel.destroy();
|
|
129
|
-
}
|