sonamu 0.2.32 → 0.2.34
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 +11 -10
- package/.vscode/settings.json +1 -1
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +3 -0
- package/dist/api/sonamu.js.map +1 -1
- package/dist/bin/cli.js +6 -3
- package/dist/bin/cli.js.map +1 -1
- package/dist/database/base-model.d.ts +2 -1
- package/dist/database/base-model.d.ts.map +1 -1
- package/dist/database/base-model.js +46 -32
- package/dist/database/base-model.js.map +1 -1
- package/dist/entity/entity.js +1 -1
- package/dist/entity/entity.js.map +1 -1
- package/dist/entity/migrator.d.ts +4 -4
- package/dist/entity/migrator.d.ts.map +1 -1
- package/dist/entity/migrator.js +213 -205
- package/dist/entity/migrator.js.map +1 -1
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +26 -26
- package/dist/syncer/syncer.js.map +1 -1
- package/dist/templates/base-template.d.ts +1 -1
- package/dist/templates/base-template.d.ts.map +1 -1
- package/dist/templates/generated_http.template.d.ts +2 -2
- package/dist/templates/generated_http.template.d.ts.map +1 -1
- package/dist/templates/generated_http.template.js +49 -38
- package/dist/templates/generated_http.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/package.json +3 -3
- package/src/api/sonamu.ts +4 -0
- package/src/bin/cli.ts +10 -5
- package/src/database/base-model.ts +67 -42
- package/src/entity/entity.ts +1 -1
- package/src/entity/migrator.ts +106 -103
- package/src/syncer/syncer.ts +58 -58
- package/src/templates/base-template.ts +1 -1
- package/src/templates/generated_http.template.ts +37 -35
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -22,45 +31,47 @@ class Template__generated_http extends base_template_1.Template {
|
|
|
22
31
|
};
|
|
23
32
|
}
|
|
24
33
|
render({}) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
[
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const { syncer: { types, apis }, config: { route: { prefix }, }, } = sonamu_1.Sonamu;
|
|
36
|
+
const lines = yield Promise.all(apis.map((api) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const reqObject = this.resolveApiParams(api, types);
|
|
39
|
+
const dataLines = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _c;
|
|
41
|
+
if (((_c = api.options.httpMethod) !== null && _c !== void 0 ? _c : "GET") === "GET") {
|
|
42
|
+
return {
|
|
43
|
+
querystring: [
|
|
44
|
+
qs_1.default
|
|
45
|
+
.stringify(reqObject, { encode: false })
|
|
46
|
+
.split("&")
|
|
47
|
+
.join("\n\t&"),
|
|
48
|
+
],
|
|
49
|
+
body: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return {
|
|
54
|
+
querystring: [],
|
|
55
|
+
body: [
|
|
56
|
+
"",
|
|
57
|
+
yield prettier_1.default.format(JSON.stringify(reqObject), {
|
|
58
|
+
parser: "json",
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}))();
|
|
64
|
+
return [
|
|
65
|
+
[
|
|
66
|
+
`${(_a = api.options.httpMethod) !== null && _a !== void 0 ? _a : "GET"} {{baseUrl}}${prefix}${api.path}`,
|
|
67
|
+
...dataLines.querystring,
|
|
68
|
+
].join("\n\t?"),
|
|
69
|
+
`Content-Type: ${(_b = api.options.contentType) !== null && _b !== void 0 ? _b : "application/json"}`,
|
|
70
|
+
...dataLines.body,
|
|
71
|
+
].join("\n");
|
|
72
|
+
})));
|
|
73
|
+
return Object.assign(Object.assign({}, this.getTargetAndPath()), { body: lines.join("\n\n###\n\n"), importKeys: [] });
|
|
62
74
|
});
|
|
63
|
-
return Object.assign(Object.assign({}, this.getTargetAndPath()), { body: lines.join("\n\n###\n\n"), importKeys: [] });
|
|
64
75
|
}
|
|
65
76
|
zodTypeToReqDefault(zodType, name) {
|
|
66
77
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated_http.template.js","sourceRoot":"","sources":["../../src/templates/generated_http.template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generated_http.template.js","sourceRoot":"","sources":["../../src/templates/generated_http.template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAA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CAAC,KAAK,EAAE,CAAC;SACnC;IACH,CAAC;IAED,gBAAgB,CACd,GAAgB,EAChB,UAAoD;QAEpD,MAAM,OAAO,GAAG,IAAA,qCAAmB,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAErD,CAAC;IACJ,CAAC;CACF;AAxHD,4DAwHC"}
|
|
@@ -18,8 +18,8 @@ export declare class Template__view_form extends Template {
|
|
|
18
18
|
preTemplates: {
|
|
19
19
|
key: "entity" | "init_types" | "generated" | "generated_sso" | "generated_http" | "model" | "model_test" | "bridge" | "service" | "view_list" | "view_list_columns" | "view_search_input" | "view_form" | "view_id_all_select" | "view_id_async_select" | "view_enums_select" | "view_enums_dropdown" | "view_enums_buttonset";
|
|
20
20
|
options: {
|
|
21
|
-
entityId: string;
|
|
22
21
|
title: string;
|
|
22
|
+
entityId: string;
|
|
23
23
|
parentId?: string | undefined;
|
|
24
24
|
table?: string | undefined;
|
|
25
25
|
} | {
|
|
@@ -40,12 +40,12 @@ export declare class Template__view_form extends Template {
|
|
|
40
40
|
entityId: string;
|
|
41
41
|
extra?: unknown;
|
|
42
42
|
} | {
|
|
43
|
+
entityId: string;
|
|
43
44
|
columns: {
|
|
44
45
|
name: string;
|
|
45
46
|
label: string;
|
|
46
47
|
tc: string;
|
|
47
48
|
}[];
|
|
48
|
-
entityId: string;
|
|
49
49
|
columnImports: string;
|
|
50
50
|
} | {
|
|
51
51
|
entityId: string;
|
|
@@ -23,8 +23,8 @@ export declare class Template__view_list extends Template {
|
|
|
23
23
|
preTemplates: {
|
|
24
24
|
key: "entity" | "init_types" | "generated" | "generated_sso" | "generated_http" | "model" | "model_test" | "bridge" | "service" | "view_list" | "view_list_columns" | "view_search_input" | "view_form" | "view_id_all_select" | "view_id_async_select" | "view_enums_select" | "view_enums_dropdown" | "view_enums_buttonset";
|
|
25
25
|
options: {
|
|
26
|
-
entityId: string;
|
|
27
26
|
title: string;
|
|
27
|
+
entityId: string;
|
|
28
28
|
parentId?: string | undefined;
|
|
29
29
|
table?: string | undefined;
|
|
30
30
|
} | {
|
|
@@ -45,12 +45,12 @@ export declare class Template__view_list extends Template {
|
|
|
45
45
|
entityId: string;
|
|
46
46
|
extra?: unknown;
|
|
47
47
|
} | {
|
|
48
|
+
entityId: string;
|
|
48
49
|
columns: {
|
|
49
50
|
name: string;
|
|
50
51
|
label: string;
|
|
51
52
|
tc: string;
|
|
52
53
|
}[];
|
|
53
|
-
entityId: string;
|
|
54
54
|
columnImports: string;
|
|
55
55
|
} | {
|
|
56
56
|
entityId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sonamu",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"description": "Sonamu — TypeScript Fullstack API Framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"@types/lodash": "^4.14.198",
|
|
49
49
|
"@types/luxon": "^3.0.1",
|
|
50
50
|
"@types/node": "^20.6.3",
|
|
51
|
-
"@types/prettier": "^
|
|
51
|
+
"@types/prettier": "^3.0.0",
|
|
52
52
|
"@types/prompts": "^2.0.14",
|
|
53
53
|
"@types/qs": "^6.9.7",
|
|
54
54
|
"@types/uuid": "^8.3.4",
|
|
55
|
-
"prettier": "^2.
|
|
55
|
+
"prettier": "^3.2.5",
|
|
56
56
|
"source-map-support": "^0.5.21",
|
|
57
57
|
"typescript": "^5.2.2"
|
|
58
58
|
},
|
package/src/api/sonamu.ts
CHANGED
|
@@ -152,6 +152,10 @@ class SonamuClass {
|
|
|
152
152
|
|
|
153
153
|
if (isLocal() && !isTest() && enableSync) {
|
|
154
154
|
await this.syncer.sync();
|
|
155
|
+
|
|
156
|
+
fetch("http://localhost:57001/api/reload", {
|
|
157
|
+
method: "GET",
|
|
158
|
+
}).catch(() => console.log("Failed to reload Sonamu UI"));
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
this.isInitialized = true;
|
package/src/bin/cli.ts
CHANGED
|
@@ -29,7 +29,7 @@ import process from "process";
|
|
|
29
29
|
let migrator: Migrator;
|
|
30
30
|
|
|
31
31
|
async function bootstrap() {
|
|
32
|
-
await Sonamu.init();
|
|
32
|
+
await Sonamu.init(false, false);
|
|
33
33
|
|
|
34
34
|
await tsicli(process.argv, {
|
|
35
35
|
types: {
|
|
@@ -210,10 +210,15 @@ async function fixture_init() {
|
|
|
210
210
|
// 3. knex migration 정보 복사
|
|
211
211
|
await Promise.all(
|
|
212
212
|
["knex_migrations", "knex_migrations_lock"].map(async (tableName) => {
|
|
213
|
-
await db.raw(
|
|
214
|
-
`
|
|
215
|
-
SELECT * FROM \`${srcConn.database}\`.${tableName}`
|
|
213
|
+
const [table] = await db.raw(
|
|
214
|
+
`SHOW TABLES FROM \`${srcConn.database}\` LIKE '${tableName}'`
|
|
216
215
|
);
|
|
216
|
+
if (table?.length) {
|
|
217
|
+
await db.raw(
|
|
218
|
+
`INSERT INTO \`${conn.database}\`.${tableName}
|
|
219
|
+
SELECT * FROM \`${srcConn.database}\`.${tableName}`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
217
222
|
})
|
|
218
223
|
);
|
|
219
224
|
|
|
@@ -365,7 +370,7 @@ async function smd_migration() {
|
|
|
365
370
|
`${names.fs}.entity.json`
|
|
366
371
|
);
|
|
367
372
|
|
|
368
|
-
const formatted = prettier.format(JSON.stringify(entityJson), {
|
|
373
|
+
const formatted = await prettier.format(JSON.stringify(entityJson), {
|
|
369
374
|
parser: "json",
|
|
370
375
|
});
|
|
371
376
|
writeFileSync(dstPath, formatted);
|
|
@@ -202,6 +202,7 @@ export class BaseModelClass {
|
|
|
202
202
|
build,
|
|
203
203
|
debug,
|
|
204
204
|
db: _db,
|
|
205
|
+
optimizeCountQuery,
|
|
205
206
|
}: {
|
|
206
207
|
subset: U;
|
|
207
208
|
params: T;
|
|
@@ -216,6 +217,7 @@ export class BaseModelClass {
|
|
|
216
217
|
baseTable?: string;
|
|
217
218
|
debug?: boolean | "list" | "count";
|
|
218
219
|
db?: Knex;
|
|
220
|
+
optimizeCountQuery?: boolean;
|
|
219
221
|
}): Promise<{
|
|
220
222
|
rows: any[];
|
|
221
223
|
total?: number | undefined;
|
|
@@ -236,20 +238,71 @@ export class BaseModelClass {
|
|
|
236
238
|
virtual,
|
|
237
239
|
});
|
|
238
240
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
const applyJoinClause = (
|
|
242
|
+
qb: Knex.QueryBuilder,
|
|
243
|
+
joins: SubsetQuery["joins"]
|
|
244
|
+
) => {
|
|
245
|
+
joins.map((join) => {
|
|
246
|
+
if (join.join == "inner") {
|
|
247
|
+
qb.innerJoin(
|
|
248
|
+
`${join.table} as ${join.as}`,
|
|
249
|
+
this.getJoinClause(db, join)
|
|
250
|
+
);
|
|
251
|
+
} else if (join.join == "outer") {
|
|
252
|
+
qb.leftOuterJoin(
|
|
253
|
+
`${join.table} as ${join.as}`,
|
|
254
|
+
this.getJoinClause(db, join)
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// countQuery
|
|
261
|
+
const total = await (async () => {
|
|
262
|
+
if (queryMode === "list") {
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const clonedQb = qb.clone().clear("order").clear("offset").clear("limit");
|
|
267
|
+
|
|
268
|
+
// optmizeCountQuery가 true인 경우 다른 clause에 영향을 주지 않는 모든 join을 제외함
|
|
269
|
+
if (optimizeCountQuery) {
|
|
270
|
+
const queryThatNotYetAppliedJoins = clonedQb.toQuery();
|
|
271
|
+
const afterWhereClause =
|
|
272
|
+
queryThatNotYetAppliedJoins.split("where")[1] ?? "";
|
|
273
|
+
applyJoinClause(
|
|
274
|
+
clonedQb,
|
|
275
|
+
joins.filter((j) => {
|
|
276
|
+
return afterWhereClause.includes(`\`${j.as}\``);
|
|
277
|
+
})
|
|
245
278
|
);
|
|
246
|
-
} else
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
279
|
+
} else {
|
|
280
|
+
applyJoinClause(clonedQb, joins);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const [, matched] =
|
|
284
|
+
clonedQb
|
|
285
|
+
.toQuery()
|
|
286
|
+
.toLowerCase()
|
|
287
|
+
.match(/select (distinct .+) from/) ?? [];
|
|
288
|
+
const countQuery = matched
|
|
289
|
+
? clonedQb
|
|
290
|
+
.clear("select")
|
|
291
|
+
.select(db.raw(`COUNT(${matched.split(",")[0]}) as total`))
|
|
292
|
+
.first()
|
|
293
|
+
: clonedQb.clear("select").count("*", { as: "total" }).first();
|
|
294
|
+
const countRow: { total?: number } = await countQuery;
|
|
295
|
+
|
|
296
|
+
// debug: countQuery
|
|
297
|
+
if (debug === true || debug === "count") {
|
|
298
|
+
console.debug(
|
|
299
|
+
"DEBUG: count query",
|
|
300
|
+
chalk.blue(countQuery.toQuery().toString())
|
|
250
301
|
);
|
|
251
302
|
}
|
|
252
|
-
|
|
303
|
+
|
|
304
|
+
return countRow?.total ?? 0;
|
|
305
|
+
})();
|
|
253
306
|
|
|
254
307
|
// listQuery
|
|
255
308
|
const rows = await (async () => {
|
|
@@ -266,6 +319,9 @@ export class BaseModelClass {
|
|
|
266
319
|
// select, rows
|
|
267
320
|
const listQuery = qb.clone().select(select);
|
|
268
321
|
|
|
322
|
+
// join
|
|
323
|
+
applyJoinClause(listQuery, joins);
|
|
324
|
+
|
|
269
325
|
let rows = await listQuery;
|
|
270
326
|
// debug: listQuery
|
|
271
327
|
if (debug === true || debug === "list") {
|
|
@@ -280,37 +336,6 @@ export class BaseModelClass {
|
|
|
280
336
|
return rows;
|
|
281
337
|
})();
|
|
282
338
|
|
|
283
|
-
// countQuery
|
|
284
|
-
const total = await (async () => {
|
|
285
|
-
if (queryMode === "list") {
|
|
286
|
-
return undefined;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const clonedQb = qb.clone().clear("order").clear("offset").clear("limit");
|
|
290
|
-
const [, matched] =
|
|
291
|
-
clonedQb
|
|
292
|
-
.toQuery()
|
|
293
|
-
.toLowerCase()
|
|
294
|
-
.match(/select (distinct .+) from/) ?? [];
|
|
295
|
-
const countQuery = matched
|
|
296
|
-
? clonedQb
|
|
297
|
-
.clear("select")
|
|
298
|
-
.select(db.raw(`COUNT(${matched.split(",")[0]}) as total`))
|
|
299
|
-
.first()
|
|
300
|
-
: clonedQb.clear("select").count("*", { as: "total" }).first();
|
|
301
|
-
const countRow: { total?: number } = await countQuery;
|
|
302
|
-
|
|
303
|
-
// debug: countQuery
|
|
304
|
-
if (debug === true || debug === "count") {
|
|
305
|
-
console.debug(
|
|
306
|
-
"DEBUG: count query",
|
|
307
|
-
chalk.blue(countQuery.toQuery().toString())
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return countRow?.total ?? 0;
|
|
312
|
-
})();
|
|
313
|
-
|
|
314
339
|
return { rows, total, subsetQuery, qb };
|
|
315
340
|
}
|
|
316
341
|
|