sonamu 0.13.11 → 0.14.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/dist/api/caster.d.ts.map +1 -1
- package/dist/api/caster.js +2 -1
- package/dist/api/code-converters.d.ts +5 -1
- package/dist/api/code-converters.d.ts.map +1 -1
- package/dist/api/code-converters.js +24 -7
- package/dist/api/config.d.ts +7 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +1 -1
- package/dist/api/decorators.d.ts +1 -0
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +1 -1
- package/dist/api/guards.d.ts +37 -0
- package/dist/api/guards.d.ts.map +1 -0
- package/dist/api/guards.js +96 -0
- package/dist/api/sonamu.d.ts +14 -1
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +121 -25
- package/dist/api/websocket-helpers.d.ts +6 -1
- package/dist/api/websocket-helpers.d.ts.map +1 -1
- package/dist/api/websocket-helpers.js +7 -4
- package/dist/auth/auth-entity-policy.d.ts +32 -0
- package/dist/auth/auth-entity-policy.d.ts.map +1 -0
- package/dist/auth/auth-entity-policy.js +44 -0
- package/dist/auth/auth-secret.d.ts +24 -0
- package/dist/auth/auth-secret.d.ts.map +1 -0
- package/dist/auth/auth-secret.js +46 -0
- package/dist/auth/base-url.d.ts +39 -0
- package/dist/auth/base-url.d.ts.map +1 -0
- package/dist/auth/base-url.js +84 -0
- package/dist/auth/better-auth-entities.js +20 -7
- package/dist/auth/better-auth-options.d.ts +15 -0
- package/dist/auth/better-auth-options.d.ts.map +1 -0
- package/dist/auth/better-auth-options.js +38 -0
- package/dist/auth/better-auth-request.d.ts +8 -1
- package/dist/auth/better-auth-request.d.ts.map +1 -1
- package/dist/auth/better-auth-request.js +26 -3
- package/dist/auth/plugins/entity-definitions/admin.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/admin.js +6 -1
- package/dist/auth/plugins/entity-definitions/anonymous.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/anonymous.js +2 -1
- package/dist/auth/plugins/entity-definitions/api-key.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/api-key.js +18 -2
- package/dist/auth/plugins/entity-definitions/audit-log.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/audit-log.js +27 -1
- package/dist/auth/plugins/entity-definitions/jwt.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/jwt.js +4 -2
- package/dist/auth/plugins/entity-definitions/organization.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/organization.js +15 -1
- package/dist/auth/plugins/entity-definitions/passkey.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/passkey.js +9 -1
- package/dist/auth/plugins/entity-definitions/phone-number.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/phone-number.js +2 -1
- package/dist/auth/plugins/entity-definitions/sso.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/sso.js +7 -3
- package/dist/auth/plugins/entity-definitions/two-factor.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/two-factor.js +8 -3
- package/dist/auth/verify-email-guard.d.ts +37 -0
- package/dist/auth/verify-email-guard.d.ts.map +1 -0
- package/dist/auth/verify-email-guard.js +48 -0
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +6 -2
- package/dist/bin/typecheck-web.js +1 -1
- package/dist/cache/decorator.d.ts +12 -0
- package/dist/cache/decorator.d.ts.map +1 -1
- package/dist/cache/decorator.js +86 -19
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +3 -3
- package/dist/cache/types.d.ts +16 -0
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/cli/plugin-loader.d.ts +17 -0
- package/dist/cli/plugin-loader.d.ts.map +1 -0
- package/dist/cli/plugin-loader.js +178 -0
- package/dist/cli/plugin.d.ts +65 -0
- package/dist/cli/plugin.d.ts.map +1 -0
- package/dist/cli/plugin.js +7 -0
- package/dist/code-formatting/oxfmt.js +1 -1
- package/dist/code-formatting/oxlint.js +1 -1
- package/dist/database/db.d.ts +35 -10
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +37 -4
- package/dist/database/puri.d.ts +8 -0
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +108 -171
- package/dist/database/puri.types.d.ts +2 -0
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +1 -1
- package/dist/database/sql-expression-brand.d.ts +10 -0
- package/dist/database/sql-expression-brand.d.ts.map +1 -0
- package/dist/database/sql-expression-brand.js +10 -0
- package/dist/dict/en.d.ts +1 -0
- package/dist/dict/en.d.ts.map +1 -1
- package/dist/dict/en.js +2 -1
- package/dist/dict/ko.d.ts +1 -0
- package/dist/dict/ko.d.ts.map +1 -1
- package/dist/dict/ko.js +2 -1
- package/dist/dict/sonamu-dictionary.d.ts +23 -1
- package/dist/dict/sonamu-dictionary.d.ts.map +1 -1
- package/dist/dict/sonamu-dictionary.js +187 -32
- package/dist/entity/entity-codegen-safety.d.ts +105 -0
- package/dist/entity/entity-codegen-safety.d.ts.map +1 -0
- package/dist/entity/entity-codegen-safety.js +70 -0
- package/dist/entity/entity-manager.d.ts +32 -0
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +21 -2
- package/dist/entity/entity.d.ts +5 -2
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +19 -8
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +31 -3
- package/dist/filter/utils.d.ts +2 -2
- package/dist/filter/utils.d.ts.map +1 -1
- package/dist/filter/utils.js +16 -11
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/logger/configure.d.ts.map +1 -1
- package/dist/logger/configure.js +10 -3
- package/dist/migration/code-generation.d.ts.map +1 -1
- package/dist/migration/code-generation.js +177 -96
- package/dist/migration/migrator.d.ts +16 -0
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +28 -3
- package/dist/migration/slack-confirm.d.ts +6 -2
- package/dist/migration/slack-confirm.d.ts.map +1 -1
- package/dist/migration/slack-confirm.js +11 -9
- package/dist/ssr/errors.d.ts +13 -0
- package/dist/ssr/errors.d.ts.map +1 -0
- package/dist/ssr/errors.js +12 -0
- package/dist/ssr/index.d.ts +1 -0
- package/dist/ssr/index.d.ts.map +1 -1
- package/dist/ssr/index.js +5 -2
- package/dist/ssr/renderer.d.ts +6 -0
- package/dist/ssr/renderer.d.ts.map +1 -1
- package/dist/ssr/renderer.js +10 -1
- package/dist/storage/base-file.d.ts +6 -2
- package/dist/storage/base-file.d.ts.map +1 -1
- package/dist/storage/base-file.js +10 -5
- package/dist/storage/buffered-file.d.ts +1 -0
- package/dist/storage/buffered-file.d.ts.map +1 -1
- package/dist/storage/buffered-file.js +5 -2
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +4 -2
- package/dist/storage/upload-safety.d.ts +47 -0
- package/dist/storage/upload-safety.d.ts.map +1 -0
- package/dist/storage/upload-safety.js +112 -0
- package/dist/stream/ws.d.ts +6 -0
- package/dist/stream/ws.d.ts.map +1 -1
- package/dist/stream/ws.js +52 -6
- package/dist/syncer/code-generator.d.ts +2 -0
- package/dist/syncer/code-generator.d.ts.map +1 -1
- package/dist/syncer/code-generator.js +21 -7
- package/dist/template/implementations/entity.template.d.ts.map +1 -1
- package/dist/template/implementations/entity.template.js +40 -35
- package/dist/template/implementations/generated.template.d.ts +10 -0
- package/dist/template/implementations/generated.template.d.ts.map +1 -1
- package/dist/template/implementations/generated.template.js +46 -7
- package/dist/template/implementations/generated_http.template.d.ts.map +1 -1
- package/dist/template/implementations/generated_http.template.js +3 -1
- package/dist/template/implementations/init_types.template.d.ts.map +1 -1
- package/dist/template/implementations/init_types.template.js +3 -8
- package/dist/template/implementations/model.template.d.ts.map +1 -1
- package/dist/template/implementations/model.template.js +9 -2
- package/dist/template/implementations/sd.template.d.ts +0 -1
- package/dist/template/implementations/sd.template.d.ts.map +1 -1
- package/dist/template/implementations/sd.template.js +2 -5
- package/dist/template/implementations/view_form.template.d.ts.map +1 -1
- package/dist/template/implementations/view_form.template.js +8 -6
- package/dist/template/implementations/view_list.template.d.ts.map +1 -1
- package/dist/template/implementations/view_list.template.js +8 -4
- package/dist/testing/dev-test-routes.d.ts.map +1 -1
- package/dist/testing/dev-test-routes.js +7 -4
- package/dist/tooling/__tests__/helpers/sonamu-test-root.js +1 -1
- package/dist/tooling/cdd-service.js +1 -1
- package/dist/tooling/index.d.ts +1 -0
- package/dist/tooling/index.d.ts.map +1 -1
- package/dist/tooling/index.js +3 -1
- package/dist/tsdown.api.config.js +1 -1
- package/dist/types/types.d.ts +81 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +2 -1
- package/dist/ui/__tests__/ui-test-helpers.d.ts +10 -0
- package/dist/ui/__tests__/ui-test-helpers.d.ts.map +1 -0
- package/dist/ui/__tests__/ui-test-helpers.js +75 -0
- package/dist/ui/access-guard.d.ts +42 -0
- package/dist/ui/access-guard.d.ts.map +1 -0
- package/dist/ui/access-guard.js +94 -0
- package/dist/ui/api.d.ts.map +1 -1
- package/dist/ui/api.js +40 -95
- package/dist/ui/dev-host-guard.d.ts +28 -0
- package/dist/ui/dev-host-guard.d.ts.map +1 -0
- package/dist/ui/dev-host-guard.js +67 -0
- package/dist/ui/migrations-api.d.ts.map +1 -1
- package/dist/ui/migrations-api.js +72 -16
- package/dist/ui/open-vscode-api.d.ts +4 -0
- package/dist/ui/open-vscode-api.d.ts.map +1 -0
- package/dist/ui/open-vscode-api.js +65 -0
- package/dist/ui/scaffolding-api.d.ts +18 -0
- package/dist/ui/scaffolding-api.d.ts.map +1 -0
- package/dist/ui/scaffolding-api.js +111 -0
- package/dist/ui/ui-db-presets.d.ts +19 -0
- package/dist/ui/ui-db-presets.d.ts.map +1 -0
- package/dist/ui/ui-db-presets.js +34 -0
- package/dist/ui/ui-request-guard.d.ts +11 -0
- package/dist/ui/ui-request-guard.d.ts.map +1 -0
- package/dist/ui/ui-request-guard.js +38 -0
- package/dist/ui-web/assets/{index-QDMyy31K.js → index-BPqP-tug.js} +39 -39
- package/dist/ui-web/index.html +2 -1
- package/package.json +1 -1
- package/src/__tests__/env.test.ts +121 -2
- package/src/api/__tests__/code-converters.union.test.ts +97 -0
- package/src/api/__tests__/guards.test.ts +233 -0
- package/src/api/__tests__/sonamu.auth-secret.test.ts +77 -0
- package/src/api/__tests__/sonamu.dev-host-guard.test.ts +130 -0
- package/src/api/__tests__/sonamu.guards.test.ts +327 -0
- package/src/api/__tests__/sonamu.upload-limits.test.ts +156 -0
- package/src/api/__tests__/websocket-helpers.test.ts +101 -0
- package/src/api/caster.ts +7 -0
- package/src/api/code-converters.ts +44 -12
- package/src/api/config.ts +8 -0
- package/src/api/decorators.ts +1 -0
- package/src/api/guards.ts +130 -0
- package/src/api/sonamu.ts +195 -39
- package/src/api/websocket-helpers.ts +11 -6
- package/src/auth/__tests__/auth-entity-policy.test.ts +59 -0
- package/src/auth/__tests__/auth-secret.test.ts +133 -0
- package/src/auth/__tests__/base-url-host-poisoning.test.ts +193 -0
- package/src/auth/__tests__/base-url.test.ts +117 -0
- package/src/auth/__tests__/better-auth-options.test.ts +194 -0
- package/src/auth/__tests__/better-auth-request.test.ts +45 -0
- package/src/auth/__tests__/verify-email-guard.test.ts +228 -0
- package/src/auth/auth-entity-policy.ts +48 -0
- package/src/auth/auth-secret.ts +77 -0
- package/src/auth/base-url.ts +109 -0
- package/src/auth/better-auth-entities.ts +30 -30
- package/src/auth/better-auth-options.ts +39 -0
- package/src/auth/better-auth-request.ts +28 -1
- package/src/auth/plugins/entity-definitions/admin.ts +5 -0
- package/src/auth/plugins/entity-definitions/anonymous.ts +9 -1
- package/src/auth/plugins/entity-definitions/api-key.ts +53 -16
- package/src/auth/plugins/entity-definitions/audit-log.ts +122 -21
- package/src/auth/plugins/entity-definitions/jwt.ts +5 -4
- package/src/auth/plugins/entity-definitions/organization.ts +26 -6
- package/src/auth/plugins/entity-definitions/passkey.ts +8 -7
- package/src/auth/plugins/entity-definitions/phone-number.ts +1 -0
- package/src/auth/plugins/entity-definitions/sso.ts +20 -15
- package/src/auth/plugins/entity-definitions/two-factor.ts +21 -5
- package/src/auth/verify-email-guard.ts +82 -0
- package/src/bin/__tests__/build-web-command.test.ts +24 -0
- package/src/bin/build-config.ts +5 -0
- package/src/cache/decorator.ts +116 -21
- package/src/cache/index.ts +6 -1
- package/src/cache/types.ts +18 -0
- package/src/cli/plugin-loader.ts +238 -0
- package/src/cli/plugin.ts +82 -0
- package/src/database/__tests__/db.test.ts +64 -1
- package/src/database/__tests__/puri.test.ts +56 -0
- package/src/database/db.ts +56 -6
- package/src/database/puri.ts +135 -125
- package/src/database/puri.types.test-d.ts +12 -0
- package/src/database/puri.types.ts +3 -0
- package/src/database/sql-expression-brand.ts +9 -0
- package/src/dict/__tests__/sonamu-dictionary.test.ts +217 -0
- package/src/dict/en.ts +2 -0
- package/src/dict/ko.ts +2 -0
- package/src/dict/sonamu-dictionary.ts +298 -38
- package/src/entity/__tests__/entity-codegen-safety.test.ts +326 -0
- package/src/entity/entity-codegen-safety.ts +126 -0
- package/src/entity/entity-manager.ts +29 -1
- package/src/entity/entity.ts +26 -12
- package/src/env.ts +52 -1
- package/src/filter/utils.ts +19 -7
- package/src/index.ts +4 -3
- package/src/logger/__tests__/configure.test.ts +51 -1
- package/src/logger/configure.ts +14 -1
- package/src/migration/__tests__/code-generation.escape.test.ts +322 -0
- package/src/migration/__tests__/migrator.test.ts +76 -1
- package/src/migration/code-generation.ts +247 -117
- package/src/migration/migrator.ts +45 -4
- package/src/migration/slack-confirm.ts +19 -5
- package/src/ssr/__tests__/preload-guard.test.ts +274 -0
- package/src/ssr/errors.ts +11 -0
- package/src/ssr/index.ts +1 -0
- package/src/ssr/renderer.ts +12 -0
- package/src/storage/__tests__/upload-safety.test.ts +179 -0
- package/src/storage/base-file.ts +8 -4
- package/src/storage/buffered-file.ts +3 -1
- package/src/storage/index.ts +9 -0
- package/src/storage/upload-safety.ts +155 -0
- package/src/stream/__tests__/ws.test.ts +97 -0
- package/src/stream/ws.ts +67 -5
- package/src/syncer/__tests__/code-generator-path-containment.test.ts +105 -0
- package/src/syncer/code-generator.ts +34 -6
- package/src/template/__tests__/generated.template.search-text.test.ts +5 -1
- package/src/template/__tests__/model.template.auth-entity.test.ts +42 -0
- package/src/template/__tests__/save-params.template.test.ts +219 -0
- package/src/template/implementations/entity.template.ts +53 -48
- package/src/template/implementations/generated.template.ts +87 -12
- package/src/template/implementations/generated_http.template.ts +5 -0
- package/src/template/implementations/init_types.template.ts +4 -22
- package/src/template/implementations/model.template.ts +15 -1
- package/src/template/implementations/sd.template.ts +4 -5
- package/src/template/implementations/view_form.template.ts +13 -5
- package/src/template/implementations/view_list.template.ts +12 -3
- package/src/testing/__tests__/dev-test-routes.test.ts +99 -0
- package/src/testing/dev-test-routes.ts +7 -3
- package/src/tooling/__tests__/cli-plugins.contract.test.ts +273 -0
- package/src/tooling/index.ts +1 -0
- package/src/types/types.ts +22 -1
- package/src/ui/__tests__/access-guard.test.ts +217 -0
- package/src/ui/__tests__/dev-host-guard.test.ts +161 -0
- package/src/ui/__tests__/fixture-api.test.ts +92 -0
- package/src/ui/__tests__/migrations-api.test.ts +352 -0
- package/src/ui/__tests__/open-vscode.test.ts +151 -0
- package/src/ui/__tests__/scaffolding-api.test.ts +232 -0
- package/src/ui/__tests__/ui-process-routes.test.ts +166 -0
- package/src/ui/__tests__/ui-test-helpers.ts +71 -0
- package/src/ui/access-guard.ts +115 -0
- package/src/ui/api.ts +65 -198
- package/src/ui/dev-host-guard.ts +109 -0
- package/src/ui/migrations-api.ts +130 -24
- package/src/ui/open-vscode-api.ts +82 -0
- package/src/ui/scaffolding-api.ts +177 -0
- package/src/ui/ui-db-presets.ts +41 -0
- package/src/ui/ui-request-guard.ts +53 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { setSDConfig } from "../../dict/sd";
|
|
4
|
+
import { Entity } from "../../entity/entity";
|
|
5
|
+
import { EntityManager } from "../../entity/entity-manager";
|
|
6
|
+
import { BadRequestException } from "../../exceptions/so-exceptions";
|
|
7
|
+
import { Template__model } from "../implementations/model.template";
|
|
8
|
+
|
|
9
|
+
function mockEntity(id: string, table: string) {
|
|
10
|
+
// render는 거부 판단에 id와 table만 사용한다.
|
|
11
|
+
const entity = new Entity({ id, table, props: [], indexes: [], subsets: {}, enums: {} });
|
|
12
|
+
vi.spyOn(EntityManager, "exists").mockReturnValue(true);
|
|
13
|
+
vi.spyOn(EntityManager, "get").mockReturnValue(entity);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("Template__model better-auth 자격 증명 엔티티 스캐폴드 거부", () => {
|
|
17
|
+
beforeAll(() => {
|
|
18
|
+
setSDConfig({ defaultLocale: "ko", supportedLocales: ["ko"] });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it.each([
|
|
26
|
+
["Session", "sessions"],
|
|
27
|
+
["Account", "accounts"],
|
|
28
|
+
["Verification", "verifications"],
|
|
29
|
+
["TwoFactor", "two_factors"],
|
|
30
|
+
["Passkey", "passkeys"],
|
|
31
|
+
["Jwks", "jwks"],
|
|
32
|
+
["ApiKey", "api_keys"],
|
|
33
|
+
["SsoProvider", "sso_providers"],
|
|
34
|
+
])("%s 모델은 가드 없는 API를 만들지 않고 거부한다", async (entityId, table) => {
|
|
35
|
+
mockEntity(entityId, table);
|
|
36
|
+
|
|
37
|
+
const rendering = new Template__model().render({ entityId });
|
|
38
|
+
|
|
39
|
+
await expect(rendering).rejects.toBeInstanceOf(BadRequestException);
|
|
40
|
+
await expect(rendering).rejects.toThrow(entityId);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { Sonamu } from "../../api";
|
|
4
|
+
import { betterAuthV1 } from "../../auth/better-auth-entities";
|
|
5
|
+
import { ENTITY_DEFINITIONS } from "../../auth/plugins/entity-definitions";
|
|
6
|
+
import { EntityManager } from "../../entity/entity-manager";
|
|
7
|
+
import { type EntityJson, EntityJsonSchema } from "../../types/types";
|
|
8
|
+
import { Template__generated } from "../implementations/generated.template";
|
|
9
|
+
import { Template__init_types } from "../implementations/init_types.template";
|
|
10
|
+
|
|
11
|
+
const TEST_API_ROOT = "/Users/Nebuleto/Workspace/sonamu/modules/sonamu";
|
|
12
|
+
|
|
13
|
+
Sonamu.apiRootPath = TEST_API_ROOT;
|
|
14
|
+
|
|
15
|
+
let entitySeq = 0;
|
|
16
|
+
|
|
17
|
+
async function registerEntity(props: EntityJson["props"], subsetFields: string[]) {
|
|
18
|
+
entitySeq += 1;
|
|
19
|
+
const entity = {
|
|
20
|
+
id: `SaveParamsTemplate${entitySeq}`,
|
|
21
|
+
title: `SaveParamsTemplate${entitySeq}`,
|
|
22
|
+
table: `save_params_template_${entitySeq}`,
|
|
23
|
+
props,
|
|
24
|
+
indexes: [],
|
|
25
|
+
subsets: { A: subsetFields },
|
|
26
|
+
enums: {},
|
|
27
|
+
};
|
|
28
|
+
await EntityManager.register(entity, { deferSearchTextJsonSourceValidation: true });
|
|
29
|
+
return EntityManager.get(entity.id);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function registerTargetEntity() {
|
|
33
|
+
entitySeq += 1;
|
|
34
|
+
const entity = {
|
|
35
|
+
id: `SaveParamsTarget${entitySeq}`,
|
|
36
|
+
title: `SaveParamsTarget${entitySeq}`,
|
|
37
|
+
table: `save_params_target_${entitySeq}`,
|
|
38
|
+
props: [{ name: "id", type: "integer" as const }],
|
|
39
|
+
indexes: [],
|
|
40
|
+
subsets: { A: ["id"] },
|
|
41
|
+
enums: {},
|
|
42
|
+
};
|
|
43
|
+
await EntityManager.register(entity);
|
|
44
|
+
return entity.id;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe("BaseSaveParams 생성", () => {
|
|
48
|
+
test("created_at·generated·searchText·readonly 컬럼과 readonly relation의 FK를 제외해야 한다", async () => {
|
|
49
|
+
const targetId = await registerTargetEntity();
|
|
50
|
+
const entity = await registerEntity(
|
|
51
|
+
[
|
|
52
|
+
{ name: "id", type: "integer" },
|
|
53
|
+
{ name: "created_at", type: "date", dbDefault: "CURRENT_TIMESTAMP" },
|
|
54
|
+
{ name: "title", type: "string" },
|
|
55
|
+
{ name: "role", type: "string", readonly: true },
|
|
56
|
+
{ name: "password", type: "string", nullable: true, readonly: true },
|
|
57
|
+
{ name: "slug", type: "string", generated: { type: "STORED", expression: "title" } },
|
|
58
|
+
{
|
|
59
|
+
name: "search_text",
|
|
60
|
+
type: "searchText",
|
|
61
|
+
sourceColumns: [{ name: "title", caseInsensitive: true }],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "relation",
|
|
65
|
+
name: "owner",
|
|
66
|
+
with: targetId,
|
|
67
|
+
relationType: "BelongsToOne",
|
|
68
|
+
readonly: true,
|
|
69
|
+
},
|
|
70
|
+
{ type: "relation", name: "editor", with: targetId, relationType: "BelongsToOne" },
|
|
71
|
+
],
|
|
72
|
+
["id", "title"],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const { lines } = new Template__generated().getBaseSaveParamsSourceCode(entity);
|
|
76
|
+
|
|
77
|
+
expect(lines).toEqual([
|
|
78
|
+
`export const ${entity.id}BaseSaveParams = ${entity.id}BaseSchema.omit({ created_at: true, role: true, password: true, slug: true, search_text: true, owner_id: true });`,
|
|
79
|
+
`export type ${entity.id}BaseSaveParams = z.infer<typeof ${entity.id}BaseSaveParams>;`,
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("제외할 컬럼이 없으면 BaseSchema를 그대로 써야 한다", async () => {
|
|
84
|
+
const entity = await registerEntity(
|
|
85
|
+
[
|
|
86
|
+
{ name: "id", type: "integer" },
|
|
87
|
+
{ name: "title", type: "string" },
|
|
88
|
+
],
|
|
89
|
+
["id", "title"],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const { lines } = new Template__generated().getBaseSaveParamsSourceCode(entity);
|
|
93
|
+
|
|
94
|
+
expect(lines[0]).toBe(`export const ${entity.id}BaseSaveParams = ${entity.id}BaseSchema;`);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("sonamu.generated.ts에서 BaseSaveParams를 BaseSchema 뒤에 출력해야 한다", async () => {
|
|
98
|
+
const entity = await registerEntity(
|
|
99
|
+
[
|
|
100
|
+
{ name: "id", type: "integer" },
|
|
101
|
+
{ name: "created_at", type: "date", dbDefault: "CURRENT_TIMESTAMP" },
|
|
102
|
+
],
|
|
103
|
+
["id"],
|
|
104
|
+
);
|
|
105
|
+
const template = new Template__generated();
|
|
106
|
+
template.getTargetAndPath = () => ({ target: "", path: "" });
|
|
107
|
+
|
|
108
|
+
const { body } = template.render();
|
|
109
|
+
const baseSchemaAt = body.indexOf(`export const ${entity.id}BaseSchema = `);
|
|
110
|
+
const saveParamsAt = body.indexOf(
|
|
111
|
+
`export const ${entity.id}BaseSaveParams = ${entity.id}BaseSchema.omit({ created_at: true });`,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(baseSchemaAt).toBeGreaterThanOrEqual(0);
|
|
115
|
+
expect(saveParamsAt).toBeGreaterThan(baseSchemaAt);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("init_types의 SaveParams는 BaseSaveParams에서 id만 optional로 만들어야 한다", async () => {
|
|
119
|
+
const entity = await registerEntity(
|
|
120
|
+
[
|
|
121
|
+
{ name: "id", type: "integer" },
|
|
122
|
+
{ name: "created_at", type: "date", dbDefault: "CURRENT_TIMESTAMP" },
|
|
123
|
+
{ name: "title", type: "string" },
|
|
124
|
+
],
|
|
125
|
+
["id", "title"],
|
|
126
|
+
);
|
|
127
|
+
const template = new Template__init_types();
|
|
128
|
+
template.getTargetAndPath = () => ({ target: "", path: "" });
|
|
129
|
+
|
|
130
|
+
const { body } = template.render({ entityId: entity.id });
|
|
131
|
+
|
|
132
|
+
expect(body).toContain(
|
|
133
|
+
`import { ${entity.id}BaseSaveParams, ${entity.id}BaseListParams } from "../sonamu.generated";`,
|
|
134
|
+
);
|
|
135
|
+
expect(body).toContain(
|
|
136
|
+
`export const ${entity.id}SaveParams = ${entity.id}BaseSaveParams.partial({ id: true });`,
|
|
137
|
+
);
|
|
138
|
+
expect(body).not.toContain("created_at");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("better-auth User의 권한·인증 상태 컬럼을 SaveParams에서 제외해야 한다", async () => {
|
|
142
|
+
const userDef = betterAuthV1.find((entity) => entity.id === "User");
|
|
143
|
+
if (!userDef) {
|
|
144
|
+
throw new Error("better-auth User 엔티티 정의를 찾을 수 없습니다");
|
|
145
|
+
}
|
|
146
|
+
// 플러그인이 나중에 추가하는 prop도 재생성되는 BaseSaveParams에 반영되는지 함께 확인합니다.
|
|
147
|
+
const pluginProps = [
|
|
148
|
+
...(ENTITY_DEFINITIONS.admin.additionalProps.User ?? []),
|
|
149
|
+
...(ENTITY_DEFINITIONS["2fa"].additionalProps.User ?? []),
|
|
150
|
+
...(ENTITY_DEFINITIONS["phone-number"].additionalProps.User ?? []),
|
|
151
|
+
...(ENTITY_DEFINITIONS.anonymous.additionalProps.User ?? []),
|
|
152
|
+
];
|
|
153
|
+
const entity = await registerEntity(
|
|
154
|
+
[...(userDef.props ?? []), ...pluginProps],
|
|
155
|
+
["id", "name", "email"],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const [line] = new Template__generated().getBaseSaveParamsSourceCode(entity).lines;
|
|
159
|
+
|
|
160
|
+
for (const column of [
|
|
161
|
+
"email_verified",
|
|
162
|
+
"created_at",
|
|
163
|
+
"role",
|
|
164
|
+
"banned",
|
|
165
|
+
"ban_reason",
|
|
166
|
+
"ban_expires",
|
|
167
|
+
"two_factor_enabled",
|
|
168
|
+
"phone_number_verified",
|
|
169
|
+
"is_anonymous",
|
|
170
|
+
]) {
|
|
171
|
+
expect(line).toContain(`${column}: true`);
|
|
172
|
+
}
|
|
173
|
+
for (const column of ["name", "email", "image", "phone_number"]) {
|
|
174
|
+
expect(line).not.toContain(` ${column}: true`);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("entity.json readonly 옵션", () => {
|
|
180
|
+
const baseEntity = {
|
|
181
|
+
id: "ReadonlyOption",
|
|
182
|
+
title: "ReadonlyOption",
|
|
183
|
+
table: "readonly_options",
|
|
184
|
+
indexes: [],
|
|
185
|
+
subsets: { A: ["id"] },
|
|
186
|
+
enums: {},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
test("prop의 readonly를 boolean으로 받아야 한다", () => {
|
|
190
|
+
const result = EntityJsonSchema.safeParse({
|
|
191
|
+
...baseEntity,
|
|
192
|
+
props: [
|
|
193
|
+
{ name: "id", type: "integer" },
|
|
194
|
+
{ name: "role", type: "string", readonly: true },
|
|
195
|
+
{
|
|
196
|
+
type: "relation",
|
|
197
|
+
name: "owner",
|
|
198
|
+
with: "User",
|
|
199
|
+
relationType: "BelongsToOne",
|
|
200
|
+
readonly: true,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
expect(result.success).toBe(true);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("boolean이 아닌 readonly는 거부해야 한다", () => {
|
|
209
|
+
const result = EntityJsonSchema.safeParse({
|
|
210
|
+
...baseEntity,
|
|
211
|
+
props: [
|
|
212
|
+
{ name: "id", type: "integer" },
|
|
213
|
+
{ name: "role", type: "string", readonly: "yes" },
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
expect(result.success).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Sonamu } from "../../api";
|
|
2
|
+
import { assertEntityJsonCodegenSafe } from "../../entity/entity-codegen-safety";
|
|
2
3
|
import { EntityManager } from "../../entity/entity-manager";
|
|
3
4
|
import { type EntityNamesRecord } from "../../entity/entity-manager";
|
|
4
5
|
import { type TemplateOptions } from "../../types/types";
|
|
@@ -33,56 +34,60 @@ export class Template__entity extends Template {
|
|
|
33
34
|
}
|
|
34
35
|
})();
|
|
35
36
|
|
|
37
|
+
// 계산된 키를 쓰는 객체 리터럴은 값 타입이 서로 다른 객체의 유니온으로 추론되므로, enum 정의 타입을 명시합니다.
|
|
38
|
+
const defaultEnums: Record<string, Record<string, string>> = parentId
|
|
39
|
+
? {}
|
|
40
|
+
: {
|
|
41
|
+
[`${names.capital}OrderBy`]: {
|
|
42
|
+
"id-desc": "ID최신순",
|
|
43
|
+
},
|
|
44
|
+
[`${names.capital}SearchField`]: { id: "ID" },
|
|
45
|
+
};
|
|
46
|
+
const entityJson = {
|
|
47
|
+
id: entityId,
|
|
48
|
+
title: title ?? entityId,
|
|
49
|
+
parentId,
|
|
50
|
+
table: table ?? names.fsPlural.replace(/-/g, "_"),
|
|
51
|
+
props: options.props?.length
|
|
52
|
+
? options.props
|
|
53
|
+
: [
|
|
54
|
+
{ name: "id", type: "integer", desc: "ID" },
|
|
55
|
+
...(parent
|
|
56
|
+
? [
|
|
57
|
+
{
|
|
58
|
+
type: "relation",
|
|
59
|
+
name: parent.names.camel,
|
|
60
|
+
relationType: "BelongsToOne",
|
|
61
|
+
with: parentId,
|
|
62
|
+
onUpdate: "CASCADE",
|
|
63
|
+
onDelete: "CASCADE",
|
|
64
|
+
desc: parent.entity.title,
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
: []),
|
|
68
|
+
{
|
|
69
|
+
name: "created_at",
|
|
70
|
+
type: "date",
|
|
71
|
+
desc: "등록일시",
|
|
72
|
+
dbDefault: "CURRENT_TIMESTAMP",
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
indexes: [...(options.indexes ?? [])],
|
|
76
|
+
subsets:
|
|
77
|
+
options.subsets ??
|
|
78
|
+
(parentId
|
|
79
|
+
? {}
|
|
80
|
+
: {
|
|
81
|
+
A: ["id", "created_at"],
|
|
82
|
+
}),
|
|
83
|
+
enums: options.enums ?? defaultEnums,
|
|
84
|
+
};
|
|
85
|
+
// 새 entity.json을 파일로 쓰기 전에 생성 코드에 들어갈 값을 검증합니다.
|
|
86
|
+
assertEntityJsonCodegenSafe(entityJson);
|
|
87
|
+
|
|
36
88
|
return {
|
|
37
89
|
...this.getTargetAndPath(names, parent?.names ?? names),
|
|
38
|
-
body: JSON.stringify(
|
|
39
|
-
id: entityId,
|
|
40
|
-
title: title ?? entityId,
|
|
41
|
-
parentId,
|
|
42
|
-
table: table ?? names.fsPlural.replace(/-/g, "_"),
|
|
43
|
-
props: options.props?.length
|
|
44
|
-
? options.props
|
|
45
|
-
: [
|
|
46
|
-
{ name: "id", type: "integer", desc: "ID" },
|
|
47
|
-
...(parent
|
|
48
|
-
? [
|
|
49
|
-
{
|
|
50
|
-
type: "relation",
|
|
51
|
-
name: parent.names.camel,
|
|
52
|
-
relationType: "BelongsToOne",
|
|
53
|
-
with: parentId,
|
|
54
|
-
onUpdate: "CASCADE",
|
|
55
|
-
onDelete: "CASCADE",
|
|
56
|
-
desc: parent.entity.title,
|
|
57
|
-
},
|
|
58
|
-
]
|
|
59
|
-
: []),
|
|
60
|
-
{
|
|
61
|
-
name: "created_at",
|
|
62
|
-
type: "date",
|
|
63
|
-
desc: "등록일시",
|
|
64
|
-
dbDefault: "CURRENT_TIMESTAMP",
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
indexes: [...(options.indexes ?? [])],
|
|
68
|
-
subsets:
|
|
69
|
-
options.subsets ??
|
|
70
|
-
(parentId
|
|
71
|
-
? {}
|
|
72
|
-
: {
|
|
73
|
-
A: ["id", "created_at"],
|
|
74
|
-
}),
|
|
75
|
-
enums:
|
|
76
|
-
options.enums ??
|
|
77
|
-
(parentId
|
|
78
|
-
? {}
|
|
79
|
-
: {
|
|
80
|
-
[`${names.capital}OrderBy`]: {
|
|
81
|
-
"id-desc": "ID최신순",
|
|
82
|
-
},
|
|
83
|
-
[`${names.capital}SearchField`]: { id: "ID" },
|
|
84
|
-
}),
|
|
85
|
-
}).trim(),
|
|
90
|
+
body: JSON.stringify(entityJson).trim(),
|
|
86
91
|
importKeys: [],
|
|
87
92
|
};
|
|
88
93
|
}
|
|
@@ -6,7 +6,12 @@ import { Sonamu } from "../../api";
|
|
|
6
6
|
import { type Entity } from "../../entity/entity";
|
|
7
7
|
import { EntityManager } from "../../entity/entity-manager";
|
|
8
8
|
import { Naite } from "../../naite/naite";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
isBelongsToOneRelationProp,
|
|
11
|
+
isOneToOneRelationProp,
|
|
12
|
+
isVirtualCodeProp,
|
|
13
|
+
isVirtualQueryProp,
|
|
14
|
+
} from "../../types/types";
|
|
10
15
|
import { type EntityIndex, type EntityPropNode } from "../../types/types";
|
|
11
16
|
import { nonNullable } from "../../utils/utils";
|
|
12
17
|
import { Template } from "../template";
|
|
@@ -38,6 +43,7 @@ export class Template__generated extends Template {
|
|
|
38
43
|
return [
|
|
39
44
|
this.getEnumsSourceCode(entity),
|
|
40
45
|
this.getBaseSchemaSourceCode(entity),
|
|
46
|
+
this.getBaseSaveParamsSourceCode(entity),
|
|
41
47
|
this.getBaseListParamsSourceCode(entity),
|
|
42
48
|
this.getSubsetSourceCode(entity),
|
|
43
49
|
].filter(nonNullable);
|
|
@@ -45,7 +51,14 @@ export class Template__generated extends Template {
|
|
|
45
51
|
Naite.t("Template__generated:sourceCodes", sourceCodes);
|
|
46
52
|
|
|
47
53
|
// Sort
|
|
48
|
-
const LABEL_KEY_ORDER = [
|
|
54
|
+
const LABEL_KEY_ORDER = [
|
|
55
|
+
"Enums",
|
|
56
|
+
"BaseSchema",
|
|
57
|
+
"BaseSaveParams",
|
|
58
|
+
"BaseListParams",
|
|
59
|
+
"Subsets",
|
|
60
|
+
"SubsetQueries",
|
|
61
|
+
];
|
|
49
62
|
sourceCodes.sort((a, b) => {
|
|
50
63
|
const [aKey] = a.label.split(":");
|
|
51
64
|
const [bKey] = b.label.split(":");
|
|
@@ -149,9 +162,10 @@ export class Template__generated extends Template {
|
|
|
149
162
|
lines: Object.entries(entity.enumLabels)
|
|
150
163
|
.filter(([, enumLabel]) => Object.keys(enumLabel).length > 0)
|
|
151
164
|
.flatMap(([enumId, enumLabel]) => [
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
// enum 키는 자유 문자열이므로 JSON 문자열 리터럴로 출력합니다.
|
|
166
|
+
`export const ${enumId} = z.enum([${Object.keys(enumLabel).map((el) =>
|
|
167
|
+
JSON.stringify(el),
|
|
168
|
+
)}]).describe(${JSON.stringify(enumId)});`,
|
|
155
169
|
`export type ${enumId} = z.infer<typeof ${enumId}>;`,
|
|
156
170
|
`export const ${enumId}Label = ${JSON.stringify(enumLabel)};`,
|
|
157
171
|
]),
|
|
@@ -292,6 +306,54 @@ export class Template__generated extends Template {
|
|
|
292
306
|
};
|
|
293
307
|
}
|
|
294
308
|
|
|
309
|
+
/**
|
|
310
|
+
* 클라이언트 저장 입력(SaveParams)의 기반 스키마를 생성합니다.
|
|
311
|
+
*
|
|
312
|
+
* sonamu.generated.ts는 sync마다 다시 생성되므로, 나중에 추가된 prop(예: 인증 플러그인의 role)도
|
|
313
|
+
* 제외 목록에 바로 반영됩니다. 다음 컬럼을 BaseSchema에서 제외합니다.
|
|
314
|
+
* - generated/searchText 컬럼: DB가 계산하므로 값을 쓸 수 없음
|
|
315
|
+
* - `created_at`: 시스템이 기록하는 생성 시각
|
|
316
|
+
* - `readonly: true` prop: 권한·인증 상태·비밀값 등 시스템 컬럼 (relation은 FK 컬럼 `{name}_id`)
|
|
317
|
+
*/
|
|
318
|
+
getBaseSaveParamsSourceCode(entity: Entity): SourceCode {
|
|
319
|
+
const schemaName = `${entity.names.module}BaseSaveParams`;
|
|
320
|
+
const baseSchemaName = `${entity.names.module}BaseSchema`;
|
|
321
|
+
|
|
322
|
+
const omitColumns = unique(
|
|
323
|
+
entity.props.flatMap((prop) => {
|
|
324
|
+
if (prop.type === "relation") {
|
|
325
|
+
const hasJoinColumn =
|
|
326
|
+
isBelongsToOneRelationProp(prop) ||
|
|
327
|
+
(isOneToOneRelationProp(prop) && prop.hasJoinColumn === true);
|
|
328
|
+
return prop.readonly === true && hasJoinColumn ? [`${prop.name}_id`] : [];
|
|
329
|
+
}
|
|
330
|
+
if (
|
|
331
|
+
prop.readonly === true ||
|
|
332
|
+
prop.name === "created_at" ||
|
|
333
|
+
prop.generated !== undefined ||
|
|
334
|
+
prop.type === "searchText"
|
|
335
|
+
) {
|
|
336
|
+
return [prop.name];
|
|
337
|
+
}
|
|
338
|
+
return [];
|
|
339
|
+
}),
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const schemaBody =
|
|
343
|
+
omitColumns.length > 0
|
|
344
|
+
? `${baseSchemaName}.omit({ ${omitColumns.map((column) => `${column}: true`).join(", ")} })`
|
|
345
|
+
: baseSchemaName;
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
label: `BaseSaveParams: ${entity.id}`,
|
|
349
|
+
importKeys: [],
|
|
350
|
+
lines: [
|
|
351
|
+
`export const ${schemaName} = ${schemaBody};`,
|
|
352
|
+
`export type ${schemaName} = z.infer<typeof ${schemaName}>;`,
|
|
353
|
+
],
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
295
357
|
getBaseListParamsSourceCode(entity: Entity): SourceCode | null {
|
|
296
358
|
// Prop 없는 MD인 경우 생성 제외
|
|
297
359
|
if (entity.props.length === 0) {
|
|
@@ -302,7 +364,20 @@ export class Template__generated extends Template {
|
|
|
302
364
|
|
|
303
365
|
const schemaName = `${entity.names.module}BaseListParams`;
|
|
304
366
|
|
|
305
|
-
|
|
367
|
+
// 기본 ListParams 키와 이름이 겹치는 toFilter prop은 개별 필드로 만들지 않음 (sonamuFilter로만 필터)
|
|
368
|
+
const reservedListParamKeys = new Set([
|
|
369
|
+
"num",
|
|
370
|
+
"page",
|
|
371
|
+
"search",
|
|
372
|
+
"keyword",
|
|
373
|
+
"orderBy",
|
|
374
|
+
"queryMode",
|
|
375
|
+
"id",
|
|
376
|
+
"sonamuFilter",
|
|
377
|
+
]);
|
|
378
|
+
const filterProps = entity.props.filter(
|
|
379
|
+
(prop) => prop.toFilter === true && !reservedListParamKeys.has(prop.name),
|
|
380
|
+
);
|
|
306
381
|
|
|
307
382
|
const propNodes: EntityPropNode[] = filterProps.map((prop) => {
|
|
308
383
|
return {
|
|
@@ -317,18 +392,18 @@ export class Template__generated extends Template {
|
|
|
317
392
|
.map((propNode) => propNodeToZodTypeDef(propNode, importKeys))
|
|
318
393
|
.join("\n");
|
|
319
394
|
|
|
320
|
-
//
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
// numeric 타입인 props 추출
|
|
324
|
-
const numericProps = entity.props.filter((p) => p.type === "numeric");
|
|
395
|
+
// sonamuFilter 타입은 런타임 허용 목록(getFilterableProps)과 같은 필드만 남긴다
|
|
396
|
+
const filterableProps = entity.getFilterableProps();
|
|
397
|
+
const numericProps = filterableProps.filter((p) => p.type === "numeric");
|
|
325
398
|
|
|
326
399
|
// ApplySonamuFilter 타입 인자 생성
|
|
327
400
|
const entityType = `${entity.id}BaseSchema`;
|
|
328
401
|
const numericKeysUnion =
|
|
329
402
|
numericProps.length > 0 ? numericProps.map((prop) => `"${prop.name}"`).join(" | ") : "never";
|
|
330
403
|
const omitKeysUnion =
|
|
331
|
-
|
|
404
|
+
filterableProps.length > 0
|
|
405
|
+
? `Exclude<keyof ${entityType}, ${filterableProps.map((prop) => `"${prop.name}"`).join(" | ")}>`
|
|
406
|
+
: `keyof ${entityType}`;
|
|
332
407
|
|
|
333
408
|
// PK 타입에 따른 id Zod 타입 결정
|
|
334
409
|
const pkType = entity.getPkType();
|
|
@@ -603,6 +603,11 @@ export class Template__generated_http extends Template {
|
|
|
603
603
|
);
|
|
604
604
|
} else if (zodType instanceof z.ZodUnknown) {
|
|
605
605
|
return "unknown";
|
|
606
|
+
} else if (zodType instanceof z.ZodUndefined) {
|
|
607
|
+
// undefined 전용 파라미터는 보낼 값이 없으므로 z.unknown()으로 변환되던 때의 예시를 유지한다.
|
|
608
|
+
return "unknown";
|
|
609
|
+
} else if (zodType instanceof z.ZodNull) {
|
|
610
|
+
return null;
|
|
606
611
|
} else if (zodType instanceof z.ZodTuple) {
|
|
607
612
|
// oxlint-disable-next-line @typescript-eslint/no-explicit-any -- ZodTuple 타입 사용
|
|
608
613
|
return zodType.def.items.map((item: any) => this.zodTypeToReqDefault(item, name));
|
|
@@ -20,39 +20,21 @@ export class Template__init_types extends Template {
|
|
|
20
20
|
|
|
21
21
|
render({ entityId }: TemplateOptions["init_types"]) {
|
|
22
22
|
const names = EntityManager.getNamesFromId(entityId);
|
|
23
|
-
const entity = EntityManager.get(entityId);
|
|
24
|
-
|
|
25
|
-
const partialColumns = ["id"];
|
|
26
|
-
if (entity.props.some((prop) => prop.name === "created_at")) {
|
|
27
|
-
partialColumns.push("created_at");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const writeIneligibleColumns = entity.props
|
|
31
|
-
.filter(
|
|
32
|
-
(prop) =>
|
|
33
|
-
prop.type !== "relation" && (prop.generated !== undefined || prop.type === "searchText"),
|
|
34
|
-
)
|
|
35
|
-
.map((prop) => prop.name);
|
|
36
|
-
|
|
37
|
-
const omitGeneratedColumns =
|
|
38
|
-
writeIneligibleColumns.length > 0
|
|
39
|
-
? `.omit({ ${writeIneligibleColumns.map((column) => `${column}: true`).join(", ")} })`
|
|
40
|
-
: "";
|
|
41
23
|
|
|
42
24
|
return {
|
|
43
25
|
...this.getTargetAndPath(names),
|
|
26
|
+
// 쓰기 불가 컬럼 제외는 sync마다 재생성되는 BaseSaveParams가 담당하므로,
|
|
27
|
+
// 사용자 소유인 이 파일에는 제외 목록을 고정하지 않습니다.
|
|
44
28
|
body: `
|
|
45
29
|
import { z } from "zod";
|
|
46
|
-
import { ${entityId}
|
|
30
|
+
import { ${entityId}BaseSaveParams, ${entityId}BaseListParams } from "../sonamu.generated";
|
|
47
31
|
|
|
48
32
|
// ${entityId} - ListParams
|
|
49
33
|
export const ${entityId}ListParams = ${entityId}BaseListParams;
|
|
50
34
|
export type ${entityId}ListParams = z.infer<typeof ${entityId}ListParams>;
|
|
51
35
|
|
|
52
36
|
// ${entityId} - SaveParams
|
|
53
|
-
export const ${entityId}SaveParams = ${entityId}
|
|
54
|
-
.map((column) => `${column}: true`)
|
|
55
|
-
.join(", ")} });
|
|
37
|
+
export const ${entityId}SaveParams = ${entityId}BaseSaveParams.partial({ id: true });
|
|
56
38
|
export type ${entityId}SaveParams = z.infer<typeof ${entityId}SaveParams>;
|
|
57
39
|
|
|
58
40
|
`.trim(),
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type z from "zod";
|
|
2
2
|
|
|
3
3
|
import { Sonamu } from "../../api";
|
|
4
|
+
import { findBetterAuthCredentialEntity } from "../../auth/auth-entity-policy";
|
|
5
|
+
import { SD } from "../../dict/sd";
|
|
4
6
|
import { EntityManager } from "../../entity/entity-manager";
|
|
5
7
|
import { type EntityNamesRecord } from "../../entity/entity-manager";
|
|
8
|
+
import { BadRequestException } from "../../exceptions/so-exceptions";
|
|
6
9
|
import { Naite } from "../../naite/naite";
|
|
7
10
|
import { type TemplateOptions } from "../../types/types";
|
|
8
11
|
import { Template } from "../template";
|
|
@@ -29,6 +32,16 @@ export class Template__model extends Template {
|
|
|
29
32
|
async render({ entityId }: TemplateOptions["model"]) {
|
|
30
33
|
Naite.t("render", { entityId });
|
|
31
34
|
|
|
35
|
+
// 이 템플릿은 가드 없는 findById/findMany/save를 만든다. better-auth 자격 증명 테이블에 쓰면
|
|
36
|
+
// 세션 토큰·비밀번호 해시를 비인증으로 읽거나 덮어쓸 수 있으므로 스캐폴드를 거부한다.
|
|
37
|
+
// 존재하지 않는 엔티티는 기존 경로의 에러 메시지를 그대로 유지한다.
|
|
38
|
+
if (
|
|
39
|
+
EntityManager.exists(entityId) &&
|
|
40
|
+
findBetterAuthCredentialEntity(EntityManager.get(entityId))
|
|
41
|
+
) {
|
|
42
|
+
throw new BadRequestException(SD("sonamu.error.authEntityModelScaffoldRefused")(entityId));
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
const listParamsZodType = await getZodTypeById(`${entityId}ListParams`);
|
|
33
46
|
const listParamsNode = zodTypeToRenderingNode(listParamsZodType);
|
|
34
47
|
|
|
@@ -175,7 +188,8 @@ class ${entityId}ModelClass extends BaseModelClass<
|
|
|
175
188
|
});
|
|
176
189
|
}
|
|
177
190
|
|
|
178
|
-
|
|
191
|
+
// 쓰기 API는 기본으로 관리자 전용입니다. 공개 범위를 넓히려면 guards를 직접 조정하세요.
|
|
192
|
+
@api({ httpMethod: "POST", clients: ["axios", "tanstack-mutation"], guards: [ "admin" ] })
|
|
179
193
|
async save(
|
|
180
194
|
spa: ${entityId}SaveParams[]
|
|
181
195
|
): Promise<${idTsType}[]> {
|
|
@@ -410,14 +410,13 @@ SD.enumLabels = (enumName: string): Record<string, LocalizedString> => {
|
|
|
410
410
|
return "const entityLabels = {} as const;";
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
|
|
413
|
+
// 키(enum 값 포함)와 라벨은 자유 문자열이므로 JSON 문자열 리터럴로 출력합니다(따옴표·역슬래시·개행 문자 모두 이스케이프).
|
|
414
|
+
const entries = labels.map(
|
|
415
|
+
({ key, value }) => ` ${JSON.stringify(key)}: ${JSON.stringify(value)},`,
|
|
416
|
+
);
|
|
414
417
|
|
|
415
418
|
return `const entityLabels = {
|
|
416
419
|
${entries.join("\n")}
|
|
417
420
|
} as const;`;
|
|
418
421
|
}
|
|
419
|
-
|
|
420
|
-
private escapeString(str: string): string {
|
|
421
|
-
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
|
|
422
|
-
}
|
|
423
422
|
}
|