sonamu 0.4.14 → 0.5.0
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/.swcrc +15 -0
- package/dist/api/base-frame.d.ts +8 -0
- package/dist/api/base-frame.d.ts.map +1 -0
- package/dist/api/base-frame.js +2 -0
- package/dist/api/base-frame.js.map +1 -0
- package/dist/api/caster.d.ts +5 -0
- package/dist/api/caster.d.ts.map +1 -0
- package/dist/api/caster.js +2 -0
- package/dist/api/caster.js.map +1 -0
- package/dist/api/code-converters.d.ts +23 -0
- package/dist/api/code-converters.d.ts.map +1 -0
- package/dist/api/code-converters.js +2 -0
- package/dist/api/code-converters.js.map +1 -0
- package/dist/api/context.d.ts +16 -0
- package/dist/api/context.d.ts.map +1 -0
- package/dist/api/context.js +2 -0
- package/dist/api/context.js.map +1 -0
- package/dist/api/decorators.d.ts +50 -0
- package/dist/api/decorators.d.ts.map +1 -0
- package/dist/api/decorators.js +2 -0
- package/dist/api/decorators.js.map +1 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/sonamu.d.ts +83 -0
- package/dist/api/sonamu.d.ts.map +1 -0
- package/dist/api/sonamu.js +2 -0
- package/dist/api/sonamu.js.map +1 -0
- package/dist/api/sonamu.types.d.ts +30 -0
- package/dist/api/sonamu.types.d.ts.map +1 -0
- package/dist/api/sonamu.types.js +2 -0
- package/dist/api/sonamu.types.js.map +1 -0
- package/dist/bin/build-config.d.ts +5 -0
- package/dist/bin/build-config.d.ts.map +1 -0
- package/dist/bin/build-config.js +2 -0
- package/dist/bin/build-config.js.map +1 -0
- package/dist/bin/cli-wrapper.d.ts +2 -0
- package/dist/bin/cli-wrapper.d.ts.map +1 -0
- package/dist/bin/cli-wrapper.js +1 -38
- package/dist/bin/cli-wrapper.js.map +1 -1
- package/dist/bin/cli.d.ts +2 -2
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +1 -903
- package/dist/bin/cli.js.map +1 -1
- package/dist/database/_batch_update.d.ts +15 -0
- package/dist/database/_batch_update.d.ts.map +1 -0
- package/dist/database/_batch_update.js +2 -0
- package/dist/database/_batch_update.js.map +1 -0
- package/dist/database/base-model.d.ts +41 -0
- package/dist/database/base-model.d.ts.map +1 -0
- package/dist/database/base-model.js +2 -0
- package/dist/database/base-model.js.map +1 -0
- package/dist/database/code-generator.d.ts +13 -0
- package/dist/database/code-generator.d.ts.map +1 -0
- package/dist/database/code-generator.js +2 -0
- package/dist/database/code-generator.js.map +1 -0
- package/dist/database/db.d.ts +40 -0
- package/dist/database/db.d.ts.map +1 -0
- package/dist/database/db.js +2 -0
- package/dist/database/db.js.map +1 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
- package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
- package/dist/database/puri-wrapper.d.ts +34 -0
- package/dist/database/puri-wrapper.d.ts.map +1 -0
- package/dist/database/puri-wrapper.js +2 -0
- package/dist/database/puri-wrapper.js.map +1 -0
- package/dist/database/puri.d.ts +83 -0
- package/dist/database/puri.d.ts.map +1 -0
- package/dist/database/puri.js +2 -0
- package/dist/database/puri.js.map +1 -0
- package/dist/database/puri.types.d.ts +60 -0
- package/dist/database/puri.types.d.ts.map +1 -0
- package/dist/database/puri.types.js +2 -0
- package/dist/database/puri.types.js.map +1 -0
- package/dist/database/transaction-context.d.ts +9 -0
- package/dist/database/transaction-context.d.ts.map +1 -0
- package/dist/database/transaction-context.js +2 -0
- package/dist/database/transaction-context.js.map +1 -0
- package/dist/database/types.d.ts +39 -0
- package/dist/database/types.d.ts.map +1 -0
- package/dist/database/types.js +2 -0
- package/dist/database/types.js.map +1 -0
- package/dist/database/upsert-builder.d.ts +34 -0
- package/dist/database/upsert-builder.d.ts.map +1 -0
- package/dist/database/upsert-builder.js +2 -0
- package/dist/database/upsert-builder.js.map +1 -0
- package/dist/entity/entity-manager.d.ts +32 -0
- package/dist/entity/entity-manager.d.ts.map +1 -0
- package/dist/entity/entity-manager.js +2 -0
- package/dist/entity/entity-manager.js.map +1 -0
- package/dist/entity/entity-utils.d.ts +61 -0
- package/dist/entity/entity-utils.d.ts.map +1 -0
- package/dist/entity/entity-utils.js +2 -0
- package/dist/entity/entity-utils.js.map +1 -0
- package/dist/entity/entity.d.ts +62 -0
- package/dist/entity/entity.d.ts.map +1 -0
- package/dist/entity/entity.js +2 -0
- package/dist/entity/entity.js.map +1 -0
- package/dist/entity/migrator.d.ts +135 -0
- package/dist/entity/migrator.d.ts.map +1 -0
- package/dist/entity/migrator.js +2 -0
- package/dist/entity/migrator.js.map +1 -0
- package/dist/exceptions/error-handler.d.ts +3 -0
- package/dist/exceptions/error-handler.d.ts.map +1 -0
- package/dist/exceptions/error-handler.js +2 -0
- package/dist/exceptions/error-handler.js.map +1 -0
- package/dist/exceptions/so-exceptions.d.ts +48 -0
- package/dist/exceptions/so-exceptions.d.ts.map +1 -0
- package/dist/exceptions/so-exceptions.js +2 -0
- package/dist/exceptions/so-exceptions.js.map +1 -0
- package/dist/file-storage/driver.d.ts +45 -0
- package/dist/file-storage/driver.d.ts.map +1 -0
- package/dist/file-storage/driver.js +2 -0
- package/dist/file-storage/driver.js.map +1 -0
- package/dist/file-storage/file-storage.d.ts +50 -0
- package/dist/file-storage/file-storage.d.ts.map +1 -0
- package/dist/file-storage/file-storage.js +2 -0
- package/dist/file-storage/file-storage.js.map +1 -0
- package/dist/index.d.ts +22 -813
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -433
- package/dist/index.js.map +1 -1
- package/dist/migration/code-generation.d.ts +15 -0
- package/dist/migration/code-generation.d.ts.map +1 -0
- package/dist/migration/code-generation.js +2 -0
- package/dist/migration/code-generation.js.map +1 -0
- package/dist/migration/migration-set.d.ts +17 -0
- package/dist/migration/migration-set.d.ts.map +1 -0
- package/dist/migration/migration-set.js +2 -0
- package/dist/migration/migration-set.js.map +1 -0
- package/dist/migration/migrator.d.ts +130 -0
- package/dist/migration/migrator.d.ts.map +1 -0
- package/dist/migration/migrator.js +2 -0
- package/dist/migration/migrator.js.map +1 -0
- package/dist/migration/types.d.ts +52 -0
- package/dist/migration/types.d.ts.map +1 -0
- package/dist/migration/types.js +2 -0
- package/dist/migration/types.js.map +1 -0
- package/dist/smd/smd-manager.d.ts +28 -0
- package/dist/smd/smd-manager.d.ts.map +1 -0
- package/dist/smd/smd-manager.js +2 -0
- package/dist/smd/smd-manager.js.map +1 -0
- package/dist/smd/smd.d.ts +40 -0
- package/dist/smd/smd.d.ts.map +1 -0
- package/dist/smd/smd.js +2 -0
- package/dist/smd/smd.js.map +1 -0
- package/dist/syncer/index.d.ts +2 -0
- package/dist/syncer/index.d.ts.map +1 -0
- package/dist/syncer/index.js +2 -0
- package/dist/syncer/index.js.map +1 -0
- package/dist/syncer/syncer.d.ts +127 -0
- package/dist/syncer/syncer.d.ts.map +1 -0
- package/dist/syncer/syncer.js +2 -0
- package/dist/syncer/syncer.js.map +1 -0
- package/dist/templates/base-template.d.ts +13 -0
- package/dist/templates/base-template.d.ts.map +1 -0
- package/dist/templates/base-template.js +2 -0
- package/dist/templates/base-template.js.map +1 -0
- package/dist/templates/entity.template.d.ts +17 -0
- package/dist/templates/entity.template.d.ts.map +1 -0
- package/dist/templates/entity.template.js +2 -0
- package/dist/templates/entity.template.js.map +1 -0
- package/dist/templates/generated.template.d.ts +27 -0
- package/dist/templates/generated.template.d.ts.map +1 -0
- package/dist/templates/generated.template.js +2 -0
- package/dist/templates/generated.template.js.map +1 -0
- package/dist/templates/generated_http.template.d.ts +24 -0
- package/dist/templates/generated_http.template.d.ts.map +1 -0
- package/dist/templates/generated_http.template.js +2 -0
- package/dist/templates/generated_http.template.js.map +1 -0
- package/dist/templates/generated_sso.template.d.ts +20 -0
- package/dist/templates/generated_sso.template.d.ts.map +1 -0
- package/dist/templates/generated_sso.template.js +2 -0
- package/dist/templates/generated_sso.template.js.map +1 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +2 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/init_types.template.d.ts +17 -0
- package/dist/templates/init_types.template.d.ts.map +1 -0
- package/dist/templates/init_types.template.js +2 -0
- package/dist/templates/init_types.template.js.map +1 -0
- package/dist/templates/model.template.d.ts +17 -0
- package/dist/templates/model.template.d.ts.map +1 -0
- package/dist/templates/model.template.js +2 -0
- package/dist/templates/model.template.js.map +1 -0
- package/dist/templates/model_test.template.d.ts +17 -0
- package/dist/templates/model_test.template.d.ts.map +1 -0
- package/dist/templates/model_test.template.js +2 -0
- package/dist/templates/model_test.template.js.map +1 -0
- package/dist/templates/service.template.d.ts +29 -0
- package/dist/templates/service.template.d.ts.map +1 -0
- package/dist/templates/service.template.js +2 -0
- package/dist/templates/service.template.js.map +1 -0
- package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
- package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
- package/dist/templates/view_enums_buttonset.template.js +2 -0
- package/dist/templates/view_enums_buttonset.template.js.map +1 -0
- package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
- package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
- package/dist/templates/view_enums_dropdown.template.js +2 -0
- package/dist/templates/view_enums_dropdown.template.js.map +1 -0
- package/dist/templates/view_enums_select.template.d.ts +17 -0
- package/dist/templates/view_enums_select.template.d.ts.map +1 -0
- package/dist/templates/view_enums_select.template.js +2 -0
- package/dist/templates/view_enums_select.template.js.map +1 -0
- package/dist/templates/view_form.template.d.ts +26 -0
- package/dist/templates/view_form.template.d.ts.map +1 -0
- package/dist/templates/view_form.template.js +2 -0
- package/dist/templates/view_form.template.js.map +1 -0
- package/dist/templates/view_id_all_select.template.d.ts +17 -0
- package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
- package/dist/templates/view_id_all_select.template.js +2 -0
- package/dist/templates/view_id_all_select.template.js.map +1 -0
- package/dist/templates/view_id_async_select.template.d.ts +17 -0
- package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
- package/dist/templates/view_id_async_select.template.js +2 -0
- package/dist/templates/view_id_async_select.template.js.map +1 -0
- package/dist/templates/view_list.template.d.ts +38 -0
- package/dist/templates/view_list.template.d.ts.map +1 -0
- package/dist/templates/view_list.template.js +2 -0
- package/dist/templates/view_list.template.js.map +1 -0
- package/dist/templates/view_list_columns.template.d.ts +17 -0
- package/dist/templates/view_list_columns.template.d.ts.map +1 -0
- package/dist/templates/view_list_columns.template.js +2 -0
- package/dist/templates/view_list_columns.template.js.map +1 -0
- package/dist/templates/view_search_input.template.d.ts +17 -0
- package/dist/templates/view_search_input.template.d.ts.map +1 -0
- package/dist/templates/view_search_input.template.js +2 -0
- package/dist/templates/view_search_input.template.js.map +1 -0
- package/dist/testing/_relation-graph.d.ts +7 -0
- package/dist/testing/_relation-graph.d.ts.map +1 -0
- package/dist/testing/_relation-graph.js +2 -0
- package/dist/testing/_relation-graph.js.map +1 -0
- package/dist/testing/fixture-manager.d.ts +35 -0
- package/dist/testing/fixture-manager.d.ts.map +1 -0
- package/dist/testing/fixture-manager.js +2 -0
- package/dist/testing/fixture-manager.js.map +1 -0
- package/dist/types/types.d.ts +609 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/typings/knex.d.js +2 -0
- package/dist/typings/knex.d.js.map +1 -0
- package/dist/utils/async-utils.d.ts +25 -0
- package/dist/utils/async-utils.d.ts.map +1 -0
- package/dist/utils/async-utils.js +2 -0
- package/dist/utils/async-utils.js.map +1 -0
- package/dist/utils/controller.d.ts +9 -0
- package/dist/utils/controller.d.ts.map +1 -0
- package/dist/utils/controller.js +2 -0
- package/dist/utils/controller.js.map +1 -0
- package/dist/utils/fs-utils.d.ts +9 -0
- package/dist/utils/fs-utils.d.ts.map +1 -0
- package/dist/utils/fs-utils.js +2 -0
- package/dist/utils/fs-utils.js.map +1 -0
- package/dist/utils/lodash-able.d.ts +2 -0
- package/dist/utils/lodash-able.d.ts.map +1 -0
- package/dist/utils/lodash-able.js +2 -0
- package/dist/utils/lodash-able.js.map +1 -0
- package/dist/utils/model.d.ts +17 -0
- package/dist/utils/model.d.ts.map +1 -0
- package/dist/utils/model.js +2 -0
- package/dist/utils/model.js.map +1 -0
- package/dist/utils/sql-parser.d.ts +4 -0
- package/dist/utils/sql-parser.d.ts.map +1 -0
- package/dist/utils/sql-parser.js +2 -0
- package/dist/utils/sql-parser.js.map +1 -0
- package/dist/utils/utils.d.ts +9 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +2 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/zod-error.d.ts +8 -0
- package/dist/utils/zod-error.d.ts.map +1 -0
- package/dist/utils/zod-error.js +2 -0
- package/dist/utils/zod-error.js.map +1 -0
- package/nodemon.json +6 -0
- package/package.json +29 -44
- package/src/api/base-frame.ts +3 -4
- package/src/api/caster.ts +22 -23
- package/src/api/code-converters.ts +170 -134
- package/src/api/context.ts +13 -6
- package/src/api/decorators.ts +146 -20
- package/src/api/index.ts +2 -0
- package/src/api/sonamu.ts +374 -165
- package/src/bin/build-config.ts +5 -0
- package/src/bin/cli-wrapper.ts +29 -40
- package/src/bin/cli.ts +132 -190
- package/src/database/_batch_update.ts +10 -15
- package/src/database/base-model.ts +300 -216
- package/src/database/db.ts +191 -21
- package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
- package/src/database/puri-wrapper.ts +129 -0
- package/src/database/puri.ts +808 -0
- package/src/database/puri.types.ts +222 -0
- package/src/database/transaction-context.ts +18 -0
- package/src/database/upsert-builder.ts +32 -35
- package/src/entity/entity-manager.ts +7 -15
- package/src/entity/entity.ts +9 -31
- package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
- package/src/file-storage/driver.ts +121 -0
- package/src/file-storage/file-storage.ts +100 -0
- package/src/index.ts +14 -11
- package/src/migration/code-generation.ts +777 -0
- package/src/migration/migration-set.ts +453 -0
- package/src/migration/migrator.ts +823 -0
- package/src/migration/types.ts +53 -0
- package/src/shared/web.shared.ts.txt +33 -2
- package/src/syncer/syncer.ts +294 -127
- package/src/templates/generated.template.ts +13 -1
- package/src/templates/generated_http.template.ts +15 -12
- package/src/templates/generated_sso.template.ts +50 -2
- package/src/templates/model.template.ts +138 -2
- package/src/templates/service.template.ts +0 -1
- package/src/templates/view_form.template.ts +11 -7
- package/src/templates/view_list.template.ts +12 -4
- package/src/testing/fixture-manager.ts +229 -174
- package/src/types/types.ts +102 -14
- package/src/utils/async-utils.ts +64 -0
- package/src/utils/fs-utils.ts +17 -0
- package/src/utils/model.ts +0 -2
- package/src/utils/utils.ts +14 -58
- package/src/utils/zod-error.ts +12 -176
- package/tsconfig.json +2 -0
- package/tsup.config.js +4 -2
- package/.pnp.cjs +0 -14363
- package/.pnp.loader.mjs +0 -2047
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -9
- package/.yarnrc.yml +0 -5
- package/src/database/base-model.abstract.ts +0 -97
- package/src/database/db.abstract.ts +0 -75
- package/src/database/drivers/knex/base-model.ts +0 -55
- package/src/database/drivers/knex/client.ts +0 -209
- package/src/database/drivers/knex/db.ts +0 -232
- package/src/database/drivers/knex/generator.ts +0 -659
- package/src/database/drivers/kysely/base-model.ts +0 -89
- package/src/database/drivers/kysely/client.ts +0 -309
- package/src/database/drivers/kysely/db.ts +0 -238
- package/src/database/drivers/kysely/generator.ts +0 -714
- package/src/database/types.ts +0 -118
- package/src/entity/migrator.ts +0 -1400
- package/src/smd/smd-manager.ts +0 -139
- package/src/smd/smd.ts +0 -571
- package/src/templates/kysely_types.template.ts +0 -205
package/src/types/types.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
import type { GuardKey } from "./../api/decorators";
|
|
2
|
+
import type { FastifyCorsOptions } from "@fastify/cors";
|
|
3
|
+
import type { FastifyFormbodyOptions } from "@fastify/formbody";
|
|
4
|
+
import type {
|
|
5
|
+
FastifyInstance,
|
|
6
|
+
FastifyReply,
|
|
7
|
+
FastifyRequest,
|
|
8
|
+
FastifyServerOptions,
|
|
9
|
+
} from "fastify";
|
|
10
|
+
import type { QsPluginOptions } from "fastify-qs";
|
|
1
11
|
import { z } from "zod";
|
|
12
|
+
import type { Context, ApiDecoratorOptions } from "../api";
|
|
13
|
+
import type { FastifyMultipartOptions } from "@fastify/multipart";
|
|
14
|
+
import type { Driver } from "../file-storage/driver";
|
|
2
15
|
|
|
3
|
-
/*
|
|
16
|
+
/*
|
|
4
17
|
Enums
|
|
5
18
|
*/
|
|
6
19
|
export type EnumsLabel<T extends string, L extends "ko" | "en"> = {
|
|
@@ -26,7 +39,7 @@ export type SQLDateTimeString = z.infer<typeof SQLDateTimeString>;
|
|
|
26
39
|
*/
|
|
27
40
|
export function zArrayable<T extends z.ZodTypeAny>(
|
|
28
41
|
shape: T
|
|
29
|
-
): z.ZodUnion<[T, z.ZodArray<T
|
|
42
|
+
): z.ZodUnion<[T, z.ZodArray<T>]> {
|
|
30
43
|
return z.union([shape, shape.array()]);
|
|
31
44
|
}
|
|
32
45
|
export type DistributiveOmit<T, K extends keyof any> = T extends any
|
|
@@ -186,9 +199,10 @@ export type EntityProp =
|
|
|
186
199
|
| RelationProp;
|
|
187
200
|
|
|
188
201
|
export type EntityIndex = {
|
|
189
|
-
type: "index" | "unique";
|
|
202
|
+
type: "index" | "unique" | "fulltext";
|
|
190
203
|
columns: string[];
|
|
191
204
|
name?: string;
|
|
205
|
+
parser?: "built-in" | "ngram";
|
|
192
206
|
};
|
|
193
207
|
export type EntityJson = {
|
|
194
208
|
id: string;
|
|
@@ -412,9 +426,6 @@ export type KnexError = {
|
|
|
412
426
|
export function isKnexError(e: any): e is KnexError {
|
|
413
427
|
return e.code && e.sqlMessage && e.sqlState;
|
|
414
428
|
}
|
|
415
|
-
export function isKyselyError(e: any): e is KnexError {
|
|
416
|
-
return e.code && e.sqlMessage && e.sqlState;
|
|
417
|
-
}
|
|
418
429
|
|
|
419
430
|
export type KnexColumnType =
|
|
420
431
|
| "string"
|
|
@@ -446,7 +457,8 @@ export type MigrationColumn = {
|
|
|
446
457
|
};
|
|
447
458
|
export type MigrationIndex = {
|
|
448
459
|
columns: string[];
|
|
449
|
-
type: "unique" | "index";
|
|
460
|
+
type: "unique" | "index" | "fulltext";
|
|
461
|
+
parser?: "built-in" | "ngram";
|
|
450
462
|
};
|
|
451
463
|
export type MigrationForeign = {
|
|
452
464
|
columns: string[];
|
|
@@ -593,11 +605,6 @@ export namespace ApiParamType {
|
|
|
593
605
|
export function isRefKnex(v: any): v is ApiParamType.Ref {
|
|
594
606
|
return v?.t === "ref" && v.id === "Knex";
|
|
595
607
|
}
|
|
596
|
-
export function isRefKysely(v: any): v is ApiParamType.Ref {
|
|
597
|
-
return (
|
|
598
|
-
v?.t === "ref" && (v.id === "Kysely" || v.id.startsWith("Transaction"))
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
608
|
export function isTypeParam(v: any): v is ApiParamType.TypeParam {
|
|
602
609
|
return v?.t === "type-param";
|
|
603
610
|
}
|
|
@@ -635,6 +642,7 @@ export type RenderingNode = {
|
|
|
635
642
|
| "string-image"
|
|
636
643
|
| "string-datetime"
|
|
637
644
|
| "string-date"
|
|
645
|
+
| "datetime"
|
|
638
646
|
| "number-plain"
|
|
639
647
|
| "number-id"
|
|
640
648
|
| "number-fk_id"
|
|
@@ -738,7 +746,6 @@ export const TemplateOptions = z.object({
|
|
|
738
746
|
entityId: z.string(),
|
|
739
747
|
enumId: z.string(),
|
|
740
748
|
}),
|
|
741
|
-
kysely_interface: z.object({}),
|
|
742
749
|
});
|
|
743
750
|
export type TemplateOptions = z.infer<typeof TemplateOptions>;
|
|
744
751
|
|
|
@@ -761,7 +768,6 @@ export const TemplateKey = z.enum([
|
|
|
761
768
|
"view_enums_select",
|
|
762
769
|
"view_enums_dropdown",
|
|
763
770
|
"view_enums_buttonset",
|
|
764
|
-
"kysely_interface",
|
|
765
771
|
]);
|
|
766
772
|
export type TemplateKey = z.infer<typeof TemplateKey>;
|
|
767
773
|
|
|
@@ -812,3 +818,85 @@ export type RelationNode = {
|
|
|
812
818
|
entityId: string;
|
|
813
819
|
related: Set<string>;
|
|
814
820
|
};
|
|
821
|
+
|
|
822
|
+
export interface DatabaseSchemaExtend {}
|
|
823
|
+
export type ManyToManyBaseSchema<
|
|
824
|
+
FromIdKey extends string,
|
|
825
|
+
ToIdKey extends string
|
|
826
|
+
> = {
|
|
827
|
+
id: number;
|
|
828
|
+
} & {
|
|
829
|
+
[K in `${FromIdKey}_id`]: number;
|
|
830
|
+
} & {
|
|
831
|
+
[K in `${ToIdKey}_id`]: number;
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
export type SonamuFastifyConfig = {
|
|
835
|
+
contextProvider: (
|
|
836
|
+
defaultContext: Pick<Context, "request" | "reply" | "headers">,
|
|
837
|
+
request: FastifyRequest,
|
|
838
|
+
reply: FastifyReply
|
|
839
|
+
) => Context;
|
|
840
|
+
guardHandler: (
|
|
841
|
+
guard: GuardKey,
|
|
842
|
+
request: FastifyRequest,
|
|
843
|
+
api: {
|
|
844
|
+
typeParameters: ApiParamType.TypeParam[];
|
|
845
|
+
parameters: ApiParam[];
|
|
846
|
+
returnType: ApiParamType;
|
|
847
|
+
modelName: string;
|
|
848
|
+
methodName: string;
|
|
849
|
+
path: string;
|
|
850
|
+
options: ApiDecoratorOptions;
|
|
851
|
+
}
|
|
852
|
+
) => void;
|
|
853
|
+
cache?: {
|
|
854
|
+
get: (key: string) => Promise<unknown | null>;
|
|
855
|
+
put: (key: string, value: unknown, ttl?: number) => Promise<void>;
|
|
856
|
+
resolveKey: (
|
|
857
|
+
path: string,
|
|
858
|
+
reqBody: {
|
|
859
|
+
[key: string]: unknown;
|
|
860
|
+
}
|
|
861
|
+
) =>
|
|
862
|
+
| {
|
|
863
|
+
cache: false;
|
|
864
|
+
}
|
|
865
|
+
| {
|
|
866
|
+
cache: true;
|
|
867
|
+
key: string;
|
|
868
|
+
ttl?: number;
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
export type SonamuServerOptions = {
|
|
874
|
+
fastify?: FastifyServerOptions;
|
|
875
|
+
|
|
876
|
+
listen?: {
|
|
877
|
+
port: number;
|
|
878
|
+
host?: string;
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
plugins?: {
|
|
882
|
+
formbody?: boolean | FastifyFormbodyOptions;
|
|
883
|
+
qs?: boolean | QsPluginOptions;
|
|
884
|
+
cors?: boolean | FastifyCorsOptions;
|
|
885
|
+
multipart?: boolean | FastifyMultipartOptions;
|
|
886
|
+
custom?: (server: FastifyInstance) => void;
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
apiConfig: SonamuFastifyConfig;
|
|
890
|
+
|
|
891
|
+
storage?: Driver;
|
|
892
|
+
|
|
893
|
+
lifecycle?: {
|
|
894
|
+
onStart?: (server: FastifyInstance) => Promise<void> | void;
|
|
895
|
+
onShutdown?: (server: FastifyInstance) => Promise<void> | void;
|
|
896
|
+
onError?: (
|
|
897
|
+
error: Error,
|
|
898
|
+
request: FastifyRequest,
|
|
899
|
+
reply: FastifyReply
|
|
900
|
+
) => Promise<void> | void;
|
|
901
|
+
};
|
|
902
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 비동기 조건으로 배열을 필터링합니다
|
|
3
|
+
* @example
|
|
4
|
+
* const filtered = await filterAsync([1, 2, 3], async (x) => x > 1);
|
|
5
|
+
*/
|
|
6
|
+
export async function filterAsync<T>(
|
|
7
|
+
arr: T[],
|
|
8
|
+
predicate: (item: T, index: number, array: T[]) => Promise<boolean>
|
|
9
|
+
): Promise<T[]> {
|
|
10
|
+
const results = await Promise.all(
|
|
11
|
+
arr.map((item, index) =>
|
|
12
|
+
predicate(item, index, arr).then((keep) => ({ item, keep }))
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
return results.filter((r) => r.keep).map((r) => r.item);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 비동기 조건이 모든 요소에 대해 참인지 확인합니다
|
|
20
|
+
* @example
|
|
21
|
+
* const allValid = await everyAsync([1, 2, 3], async (x) => x > 0);
|
|
22
|
+
*/
|
|
23
|
+
export async function everyAsync<T>(
|
|
24
|
+
arr: T[],
|
|
25
|
+
predicate: (item: T, index: number, array: T[]) => Promise<boolean>
|
|
26
|
+
): Promise<boolean> {
|
|
27
|
+
for (let i = 0; i < arr.length; i++) {
|
|
28
|
+
if (!(await predicate(arr[i], i, arr))) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 비동기 변환 함수를 배열의 각 요소에 적용합니다
|
|
37
|
+
* @example
|
|
38
|
+
* const doubled = await mapAsync([1, 2, 3], async (x) => x * 2);
|
|
39
|
+
*/
|
|
40
|
+
export async function mapAsync<T, U>(
|
|
41
|
+
arr: T[],
|
|
42
|
+
mapper: (item: T, index: number, array: T[]) => Promise<U>
|
|
43
|
+
): Promise<U[]> {
|
|
44
|
+
return Promise.all(
|
|
45
|
+
arr.map((item, index) => mapper(item, index, arr))
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 비동기 리듀서로 배열을 축약합니다
|
|
51
|
+
* @example
|
|
52
|
+
* const sum = await reduceAsync([1, 2, 3], async (acc, x) => acc + x, 0);
|
|
53
|
+
*/
|
|
54
|
+
export async function reduceAsync<T, U>(
|
|
55
|
+
arr: T[],
|
|
56
|
+
reducer: (accumulator: U, currentValue: T, index: number, array: T[]) => Promise<U>,
|
|
57
|
+
initialValue: U
|
|
58
|
+
): Promise<U> {
|
|
59
|
+
let accumulator = initialValue;
|
|
60
|
+
for (let i = 0; i < arr.length; i++) {
|
|
61
|
+
accumulator = await reducer(accumulator, arr[i], i, arr);
|
|
62
|
+
}
|
|
63
|
+
return accumulator;
|
|
64
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PathLike, constants } from "fs";
|
|
2
|
+
import { access } from "fs/promises";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* fs/promises에는 exists가 없어요. 대신 access가 있습니다.
|
|
6
|
+
* 근데 얘는 인터페이스가 쓰기 불편해요. 그래서 감싸주었습니다.
|
|
7
|
+
* @param path
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export async function exists(path: PathLike): Promise<boolean> {
|
|
11
|
+
try {
|
|
12
|
+
await access(path, constants.F_OK);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/utils/model.ts
CHANGED
package/src/utils/utils.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import glob from "
|
|
3
|
-
import fs from "fs
|
|
4
|
-
import _ from "lodash";
|
|
2
|
+
import { glob } from "fs/promises";
|
|
3
|
+
import fs from "fs";
|
|
5
4
|
|
|
6
|
-
export function globAsync(pathPattern: string): Promise<string[]> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
resolve(files);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
});
|
|
5
|
+
export async function globAsync(pathPattern: string): Promise<string[]> {
|
|
6
|
+
const files: string[] = [];
|
|
7
|
+
for await (const file of glob(path.resolve(pathPattern))) {
|
|
8
|
+
files.push(file);
|
|
9
|
+
}
|
|
10
|
+
return files;
|
|
16
11
|
}
|
|
17
12
|
export async function importMultiple(
|
|
18
13
|
filePaths: string[],
|
|
@@ -46,6 +41,12 @@ export async function findAppRootPath() {
|
|
|
46
41
|
}
|
|
47
42
|
|
|
48
43
|
export function findApiRootPath() {
|
|
44
|
+
// NOTE: for support npm / yarn workspaces
|
|
45
|
+
const workspacePath = process.env["INIT_CWD"];
|
|
46
|
+
if (workspacePath && workspacePath.length !== 0) {
|
|
47
|
+
return workspacePath;
|
|
48
|
+
}
|
|
49
|
+
|
|
49
50
|
const basePath = require.main?.path ?? __dirname;
|
|
50
51
|
let dir = path.dirname(basePath);
|
|
51
52
|
if (dir.includes("/.yarn/")) {
|
|
@@ -63,48 +64,3 @@ export function findApiRootPath() {
|
|
|
63
64
|
export function nonNullable<T>(value: T): value is NonNullable<T> {
|
|
64
65
|
return value !== null && value !== undefined;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
export function hydrate<T>(rows: T[]): T[] {
|
|
68
|
-
return rows.map((row: any) => {
|
|
69
|
-
// nullable relation인 경우 관련된 필드가 전부 null로 생성되는 것 방지하는 코드
|
|
70
|
-
const nestedKeys = Object.keys(row).filter((key) => key.includes("__"));
|
|
71
|
-
const groups = _.groupBy(nestedKeys, (key) => key.split("__")[0]);
|
|
72
|
-
const nullKeys = Object.keys(groups).filter(
|
|
73
|
-
(key) =>
|
|
74
|
-
groups[key].length > 1 &&
|
|
75
|
-
groups[key].every((field) => row[field] === null)
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const hydrated = Object.keys(row).reduce((r, field) => {
|
|
79
|
-
if (!field.includes("__")) {
|
|
80
|
-
if (Array.isArray(row[field]) && _.isObject(row[field][0])) {
|
|
81
|
-
r[field] = hydrate(row[field]);
|
|
82
|
-
return r;
|
|
83
|
-
} else {
|
|
84
|
-
r[field] = row[field];
|
|
85
|
-
return r;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const parts = field.split("__");
|
|
90
|
-
const objPath =
|
|
91
|
-
parts[0] +
|
|
92
|
-
parts
|
|
93
|
-
.slice(1)
|
|
94
|
-
.map((part) => `[${part}]`)
|
|
95
|
-
.join("");
|
|
96
|
-
_.set(
|
|
97
|
-
r,
|
|
98
|
-
objPath,
|
|
99
|
-
row[field] && Array.isArray(row[field]) && _.isObject(row[field][0])
|
|
100
|
-
? hydrate(row[field])
|
|
101
|
-
: row[field]
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
return r;
|
|
105
|
-
}, {} as any);
|
|
106
|
-
nullKeys.map((nullKey) => (hydrated[nullKey] = null));
|
|
107
|
-
|
|
108
|
-
return hydrated;
|
|
109
|
-
});
|
|
110
|
-
}
|
package/src/utils/zod-error.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
type ValidationError = {
|
|
4
5
|
path: string[];
|
|
@@ -6,184 +7,19 @@ type ValidationError = {
|
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export function humanizeZodError(error: z.ZodError): ValidationError[] {
|
|
9
|
-
return error.issues.map((
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return `${acc}[${cur}]`;
|
|
10
|
+
return error.issues.map(({ path: originPath, message }) => {
|
|
11
|
+
const path = originPath.map(item => {
|
|
12
|
+
if (typeof item === "symbol") {
|
|
13
|
+
return item.description ?? item.toString();
|
|
14
14
|
}
|
|
15
|
-
return i === 0 ? cur : `${acc}.${cur}`;
|
|
16
|
-
}, "");
|
|
17
|
-
|
|
18
|
-
switch (issue.code) {
|
|
19
|
-
case z.ZodIssueCode.invalid_type:
|
|
20
|
-
return {
|
|
21
|
-
path: pathAsStrings,
|
|
22
|
-
message: `${path} should be a ${issue.expected}, received ${issue.received}.`,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
case z.ZodIssueCode.unrecognized_keys:
|
|
26
|
-
return {
|
|
27
|
-
path: pathAsStrings,
|
|
28
|
-
message: `Unrecognized keys in ${path}: ${issue.keys.join(", ")}.`,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
case z.ZodIssueCode.invalid_union:
|
|
32
|
-
return {
|
|
33
|
-
path: pathAsStrings,
|
|
34
|
-
message: `${path} failed union validation. Inner errors: ${issue.unionErrors
|
|
35
|
-
.map((e) => e.issues.map((i) => i.message).join("; "))
|
|
36
|
-
.join(" OR ")}.`,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
case z.ZodIssueCode.invalid_enum_value:
|
|
40
|
-
return {
|
|
41
|
-
path: pathAsStrings,
|
|
42
|
-
message: `${path} must be one of: ${issue.options.join(", ")}.`,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
case z.ZodIssueCode.invalid_arguments:
|
|
46
|
-
return {
|
|
47
|
-
path: pathAsStrings,
|
|
48
|
-
message: `Invalid function arguments: ${issue.argumentsError.issues
|
|
49
|
-
.map((i) => i.message)
|
|
50
|
-
.join("; ")}.`,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
case z.ZodIssueCode.invalid_return_type:
|
|
54
|
-
return {
|
|
55
|
-
path: pathAsStrings,
|
|
56
|
-
message: `Invalid function return type: ${issue.returnTypeError.issues
|
|
57
|
-
.map((i) => i.message)
|
|
58
|
-
.join("; ")}.`,
|
|
59
|
-
};
|
|
60
15
|
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
|
|
64
|
-
message: `${path} must be a valid date.`,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
case z.ZodIssueCode.invalid_string:
|
|
68
|
-
const validationType = issue.validation;
|
|
69
|
-
return {
|
|
70
|
-
path: pathAsStrings,
|
|
71
|
-
message: `${path} must be a valid ${validationType}.`,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
case z.ZodIssueCode.too_small:
|
|
75
|
-
return {
|
|
76
|
-
path: pathAsStrings,
|
|
77
|
-
message: `${path} ${getMinimumMessage(issue)}.`,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
case z.ZodIssueCode.too_big:
|
|
81
|
-
return {
|
|
82
|
-
path: pathAsStrings,
|
|
83
|
-
message: `${path} ${getMaximumMessage(issue)}`,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
case z.ZodIssueCode.not_multiple_of:
|
|
87
|
-
return {
|
|
88
|
-
path: pathAsStrings,
|
|
89
|
-
message: `${path} must be a multiple of ${issue.multipleOf.toString()}.`,
|
|
90
|
-
};
|
|
16
|
+
if (typeof item === "number") {
|
|
17
|
+
return `[${item}]`;
|
|
18
|
+
}
|
|
91
19
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
path: pathAsStrings,
|
|
95
|
-
message: issue.message || `${path} failed custom validation.`,
|
|
96
|
-
};
|
|
20
|
+
return item;
|
|
21
|
+
});
|
|
97
22
|
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
path: pathAsStrings,
|
|
101
|
-
message: issue.message,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
23
|
+
return { path, message: message };
|
|
104
24
|
});
|
|
105
25
|
}
|
|
106
|
-
|
|
107
|
-
function getMinimumMessage(
|
|
108
|
-
issue: z.ZodIssue & { code: typeof z.ZodIssueCode.too_small }
|
|
109
|
-
) {
|
|
110
|
-
switch (issue.type) {
|
|
111
|
-
case "string":
|
|
112
|
-
return `must be ${
|
|
113
|
-
issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than"
|
|
114
|
-
} ${issue.minimum} character${issue.minimum === 1 ? "" : "s"}`;
|
|
115
|
-
|
|
116
|
-
case "number":
|
|
117
|
-
return `must be ${
|
|
118
|
-
issue.exact
|
|
119
|
-
? "exactly"
|
|
120
|
-
: issue.inclusive
|
|
121
|
-
? "greater than or equal to"
|
|
122
|
-
: "greater than"
|
|
123
|
-
} ${issue.minimum.toString()}`;
|
|
124
|
-
|
|
125
|
-
case "array":
|
|
126
|
-
case "set":
|
|
127
|
-
return `must contain ${
|
|
128
|
-
issue.exact ? "exactly" : issue.inclusive ? "at least" : "more than"
|
|
129
|
-
} ${issue.minimum} item${issue.minimum === 1 ? "" : "s"}`;
|
|
130
|
-
|
|
131
|
-
case "date":
|
|
132
|
-
return `must be ${
|
|
133
|
-
issue.exact ? "exactly" : issue.inclusive ? "at or after" : "after"
|
|
134
|
-
} ${formatDateConstraint(issue.minimum)}`;
|
|
135
|
-
|
|
136
|
-
default:
|
|
137
|
-
return "is too small";
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function getMaximumMessage(
|
|
142
|
-
issue: z.ZodIssue & { code: typeof z.ZodIssueCode.too_big }
|
|
143
|
-
) {
|
|
144
|
-
switch (issue.type) {
|
|
145
|
-
case "string":
|
|
146
|
-
return `must be ${
|
|
147
|
-
issue.exact ? "exactly" : issue.inclusive ? "at most" : "less than"
|
|
148
|
-
} ${issue.maximum} character${issue.maximum === 1 ? "" : "s"}`;
|
|
149
|
-
|
|
150
|
-
case "number":
|
|
151
|
-
return `must be ${
|
|
152
|
-
issue.exact
|
|
153
|
-
? "exactly"
|
|
154
|
-
: issue.inclusive
|
|
155
|
-
? "less than or equal to"
|
|
156
|
-
: "less than"
|
|
157
|
-
} ${issue.maximum.toString()}`;
|
|
158
|
-
|
|
159
|
-
case "array":
|
|
160
|
-
case "set":
|
|
161
|
-
return `must contain ${
|
|
162
|
-
issue.exact ? "exactly" : issue.inclusive ? "at most" : "fewer than"
|
|
163
|
-
} ${issue.maximum} item${issue.maximum === 1 ? "" : "s"}`;
|
|
164
|
-
|
|
165
|
-
case "date":
|
|
166
|
-
return `must be ${
|
|
167
|
-
issue.exact ? "exactly" : issue.inclusive ? "at or before" : "before"
|
|
168
|
-
} ${formatDateConstraint(issue.maximum)}`;
|
|
169
|
-
|
|
170
|
-
default:
|
|
171
|
-
return "is too big";
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function formatDateConstraint(value: number | bigint): string {
|
|
176
|
-
try {
|
|
177
|
-
if (typeof value === "bigint") {
|
|
178
|
-
if (
|
|
179
|
-
value > BigInt(Number.MAX_SAFE_INTEGER) ||
|
|
180
|
-
value < BigInt(Number.MIN_SAFE_INTEGER)
|
|
181
|
-
) {
|
|
182
|
-
return value.toString();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return new Date(Number(value)).toISOString();
|
|
186
|
-
} catch {
|
|
187
|
-
return value.toString();
|
|
188
|
-
}
|
|
189
|
-
}
|
package/tsconfig.json
CHANGED
package/tsup.config.js
CHANGED
|
@@ -11,7 +11,10 @@ export default defineConfig({
|
|
|
11
11
|
"src/database/drivers/kysely/base-model.ts",
|
|
12
12
|
],
|
|
13
13
|
dts: true,
|
|
14
|
-
format: [
|
|
14
|
+
format: [
|
|
15
|
+
"cjs",
|
|
16
|
+
// "esm"
|
|
17
|
+
],
|
|
15
18
|
target: "esnext",
|
|
16
19
|
clean: true,
|
|
17
20
|
sourcemap: true,
|
|
@@ -24,7 +27,6 @@ export default defineConfig({
|
|
|
24
27
|
"dotenv",
|
|
25
28
|
"fast-deep-equal",
|
|
26
29
|
"fastify",
|
|
27
|
-
"fs-extra",
|
|
28
30
|
"glob",
|
|
29
31
|
"inflection",
|
|
30
32
|
"knex",
|