sonamu 0.13.10 → 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/api-parser.js +6 -1
- 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__/api-parser.readonly.test.ts +55 -0
- package/src/syncer/__tests__/code-generator-path-containment.test.ts +105 -0
- package/src/syncer/api-parser.ts +12 -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
|
@@ -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
|
}
|
|
@@ -228,6 +228,9 @@ export class Template__view_form extends Template {
|
|
|
228
228
|
|
|
229
229
|
const defaultValue = this.resolveDefaultValue(columns);
|
|
230
230
|
|
|
231
|
+
// created_at은 SaveParams에서 빠지므로, 조회한 행에서 따로 받아 표시만 합니다.
|
|
232
|
+
const showCreatedAt = entity.subsets.A?.includes("created_at") ?? false;
|
|
233
|
+
|
|
231
234
|
// enum과 FK에 대한 import 정보 수집
|
|
232
235
|
const enumImports = new Set<string>();
|
|
233
236
|
const fkConfigImports = new Set<string>();
|
|
@@ -285,7 +288,7 @@ import {
|
|
|
285
288
|
import { useTypeForm } from "@sonamu-kit/react-components/lib";
|
|
286
289
|
import { useQueryClient } from "@tanstack/react-query";
|
|
287
290
|
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
|
288
|
-
import { useEffect } from "react";
|
|
291
|
+
import { useEffect${showCreatedAt ? ", useState" : ""} } from "react";
|
|
289
292
|
import { z } from "zod";
|
|
290
293
|
import { ${names.capital}Service } from "@/services/services.generated";
|
|
291
294
|
import type { ${names.capital}SubsetA } from "@/services/sonamu.generated";${
|
|
@@ -346,6 +349,7 @@ export function ${names.capitalPlural}Form({ id, mode }: ${names.capitalPlural}F
|
|
|
346
349
|
const queryClient = useQueryClient();
|
|
347
350
|
|
|
348
351
|
const { form, setForm, register${columns.some((col) => ["json-sonamufile", "json-sonamufile-array"].includes(col.renderType)) ? ", submit" : ""} } = useTypeForm(${names.capital}SaveParams, ${JSON.stringify(defaultValue).replace(/"now\(\)"/g, '""')});
|
|
352
|
+
${showCreatedAt ? " const [createdAt, setCreatedAt] = useState<string>();\n" : ""}
|
|
349
353
|
${(() => {
|
|
350
354
|
const hasDatetime = columns.some((col) => col.renderType === "string-datetime");
|
|
351
355
|
const hasDate = columns.some((col) => col.renderType === "string-date");
|
|
@@ -387,7 +391,7 @@ ${(() => {
|
|
|
387
391
|
useEffect(() => {
|
|
388
392
|
if (id) {
|
|
389
393
|
${names.capital}Service.get${names.capital}("A", id).then((row) => {
|
|
390
|
-
setForm((prevForm) => ({
|
|
394
|
+
${showCreatedAt ? "setCreatedAt(String(row.created_at));\n " : ""}setForm((prevForm) => ({
|
|
391
395
|
...prevForm,
|
|
392
396
|
...row,${(() => {
|
|
393
397
|
// relation 필드들을 찾아서 변환 코드 생성
|
|
@@ -523,14 +527,18 @@ ${columns
|
|
|
523
527
|
|
|
524
528
|
{/* Save Button */}
|
|
525
529
|
<div className="flex items-center justify-between pt-4">
|
|
526
|
-
{
|
|
530
|
+
${
|
|
531
|
+
showCreatedAt
|
|
532
|
+
? `{form.id && createdAt && (
|
|
527
533
|
<div className="flex items-center">
|
|
528
534
|
<label className="mr-2 text-xs text-gray-600">{SD("form.createdAt")}:</label>
|
|
529
535
|
<span className="text-xs text-gray-600">
|
|
530
|
-
{
|
|
536
|
+
{createdAt}
|
|
531
537
|
</span>
|
|
532
538
|
</div>
|
|
533
|
-
)}
|
|
539
|
+
)}`
|
|
540
|
+
: ""
|
|
541
|
+
}
|
|
534
542
|
<Button
|
|
535
543
|
onClick={handleSubmit}
|
|
536
544
|
icon={<SaveIcon />}
|
|
@@ -269,6 +269,13 @@ export class Template__view_list extends Template {
|
|
|
269
269
|
const pkType = entity.getPkType();
|
|
270
270
|
const idTsType = pkType === "string" || pkType === "uuid" ? "string" : "number";
|
|
271
271
|
|
|
272
|
+
// 필터 UI는 서버가 허용하는 toFilter 필드만 노출한다
|
|
273
|
+
const filterSchemaName = `${names.capital}FilterSchema`;
|
|
274
|
+
const filterSchemaPick = entity
|
|
275
|
+
.getFilterableProps()
|
|
276
|
+
.map((prop) => `${prop.name}: true`)
|
|
277
|
+
.join(", ");
|
|
278
|
+
|
|
272
279
|
// 실제 리스트 컬럼
|
|
273
280
|
const columns = /* SAFETY: Columns 렌더링 노드의 자식은 모두 컬럼 노드다. */ (
|
|
274
281
|
columnsNode.children as RenderingNode[]
|
|
@@ -420,7 +427,9 @@ import ListIcon from "~icons/mdi/format-list-bulleted";
|
|
|
420
427
|
import SearchIcon from "~icons/mdi/magnify";
|
|
421
428
|
import { SD } from "@/i18n/sd.generated";
|
|
422
429
|
|
|
423
|
-
|
|
430
|
+
const ${filterSchemaName} = ${names.capital}BaseSchema.pick({ ${filterSchemaPick} });
|
|
431
|
+
|
|
432
|
+
export const Route = createFileRoute("/admin/${names.fsPlural}/")({\n head: () => ({\n meta: [\n { title: ${JSON.stringify(`${entity.title ?? names.capital} List`)} },\n { name: "description", content: SD("entity.listManage")(${JSON.stringify(entity.title ?? names.capital)}) },\n ],\n }),\n component: ${names.capital}List,\n});\n\ntype ${names.capital}ListProps = {};
|
|
424
433
|
|
|
425
434
|
function ${names.capital}List({}: ${names.capital}ListProps) {
|
|
426
435
|
const navigate = useNavigate();
|
|
@@ -594,7 +603,7 @@ ${
|
|
|
594
603
|
<SonamuFilterPopover
|
|
595
604
|
rules={appliedRules}
|
|
596
605
|
fieldMeta={extractFieldMetaFromSchema(
|
|
597
|
-
${
|
|
606
|
+
${filterSchemaName},
|
|
598
607
|
SD as (key: string) => string,
|
|
599
608
|
)}
|
|
600
609
|
>
|
|
@@ -742,7 +751,7 @@ ${
|
|
|
742
751
|
|
|
743
752
|
{/* Sonamu Filter Modal */}
|
|
744
753
|
<SonamuFilterModal
|
|
745
|
-
baseSchema={${
|
|
754
|
+
baseSchema={${filterSchemaName}}
|
|
746
755
|
open={filterModalOpen}
|
|
747
756
|
onOpenChange={setFilterModalOpen}
|
|
748
757
|
initialRules={appliedRules}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import formbody from "@fastify/formbody";
|
|
1
2
|
import Fastify from "fastify";
|
|
2
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
4
|
|
|
@@ -123,6 +124,104 @@ describe("registerDevTestRoutes", () => {
|
|
|
123
124
|
});
|
|
124
125
|
});
|
|
125
126
|
|
|
127
|
+
describe("교차 출처 요청 차단", () => {
|
|
128
|
+
// 스캐폴드 기본값처럼 formbody를 켠 서버에서 단순 요청 형식을 검증합니다.
|
|
129
|
+
let formApp: ReturnType<typeof Fastify>;
|
|
130
|
+
|
|
131
|
+
beforeEach(async () => {
|
|
132
|
+
formApp = Fastify();
|
|
133
|
+
await formApp.register(formbody);
|
|
134
|
+
await registerDevTestRoutes(formApp, defaultConfig, dependencies);
|
|
135
|
+
vi.clearAllMocks();
|
|
136
|
+
mockManager.run.mockResolvedValue(okRunResult);
|
|
137
|
+
mockManager.getStatus.mockReturnValue(okStatus);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
afterEach(async () => {
|
|
141
|
+
await formApp.close();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("다른 출처 웹페이지의 form·no-cors·본문 없는 POST는 테스트를 실행하지 않는다", async () => {
|
|
145
|
+
const requests: { headers: Record<string, string>; payload?: string }[] = [
|
|
146
|
+
{
|
|
147
|
+
headers: {
|
|
148
|
+
origin: "http://evil.example",
|
|
149
|
+
"sec-fetch-site": "cross-site",
|
|
150
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
151
|
+
},
|
|
152
|
+
payload: "pattern=x",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
headers: {
|
|
156
|
+
origin: "http://localhost:3000",
|
|
157
|
+
"sec-fetch-site": "same-site",
|
|
158
|
+
"content-type": "text/plain;charset=UTF-8",
|
|
159
|
+
},
|
|
160
|
+
payload: "{}",
|
|
161
|
+
},
|
|
162
|
+
// Sec-Fetch-Site를 보내지 않는 브라우저는 Origin과 Host를 비교합니다.
|
|
163
|
+
{ headers: { origin: "http://evil.example" } },
|
|
164
|
+
{ headers: { origin: "null", "content-type": "application/json" }, payload: "{}" },
|
|
165
|
+
];
|
|
166
|
+
for (const { headers, payload } of requests) {
|
|
167
|
+
const res = await formApp.inject({
|
|
168
|
+
method: "POST",
|
|
169
|
+
url: "/__test__/run",
|
|
170
|
+
headers: { host: "localhost:10280", ...headers },
|
|
171
|
+
payload,
|
|
172
|
+
});
|
|
173
|
+
expect(res.statusCode, JSON.stringify(headers)).toBe(403);
|
|
174
|
+
}
|
|
175
|
+
expect(mockManager.run).not.toHaveBeenCalled();
|
|
176
|
+
expect(mockManager.emitEvent).not.toHaveBeenCalled();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("JSON이 아닌 POST는 출처 표시가 없어도 415로 거부한다", async () => {
|
|
180
|
+
const requests: { headers: Record<string, string>; payload?: string }[] = [
|
|
181
|
+
{ headers: {} },
|
|
182
|
+
{ headers: { "content-type": "application/x-www-form-urlencoded" }, payload: "pattern=x" },
|
|
183
|
+
{ headers: { "content-type": "text/plain" }, payload: "{}" },
|
|
184
|
+
];
|
|
185
|
+
for (const { headers, payload } of requests) {
|
|
186
|
+
const res = await formApp.inject({
|
|
187
|
+
method: "POST",
|
|
188
|
+
url: "/__test__/run",
|
|
189
|
+
headers,
|
|
190
|
+
payload,
|
|
191
|
+
});
|
|
192
|
+
expect(res.statusCode, JSON.stringify(headers)).toBe(415);
|
|
193
|
+
}
|
|
194
|
+
expect(mockManager.run).not.toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("다른 출처의 GET /__test__/status는 403으로 거부한다", async () => {
|
|
198
|
+
const res = await formApp.inject({
|
|
199
|
+
method: "GET",
|
|
200
|
+
url: "/__test__/status",
|
|
201
|
+
headers: { origin: "http://evil.example", "sec-fetch-site": "cross-site" },
|
|
202
|
+
});
|
|
203
|
+
expect(res.statusCode).toBe(403);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("sonamu test CLI의 JSON 요청과 동일 출처 Sonamu UI 요청은 통과한다", async () => {
|
|
207
|
+
const cliRes = await formApp.inject({
|
|
208
|
+
method: "POST",
|
|
209
|
+
url: "/__test__/run",
|
|
210
|
+
headers: { "content-type": "application/json" },
|
|
211
|
+
payload: JSON.stringify({ files: ["foo.test.ts"] }),
|
|
212
|
+
});
|
|
213
|
+
expect(cliRes.statusCode).toBe(200);
|
|
214
|
+
expect(mockManager.run).toHaveBeenCalledTimes(1);
|
|
215
|
+
|
|
216
|
+
const uiRes = await formApp.inject({
|
|
217
|
+
method: "GET",
|
|
218
|
+
url: "/__test__/status",
|
|
219
|
+
headers: { origin: "http://localhost:65000", "sec-fetch-site": "same-origin" },
|
|
220
|
+
});
|
|
221
|
+
expect(uiRes.statusCode).toBe(200);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
126
225
|
describe("server.close() onClose hook", () => {
|
|
127
226
|
it("서버 종료 시 manager.shutdown()이 호출된다", async () => {
|
|
128
227
|
await app.close();
|
|
@@ -8,6 +8,7 @@ import { Sonamu } from "../api/sonamu";
|
|
|
8
8
|
import { type SerializedTrace } from "../naite/naite";
|
|
9
9
|
import { createSSEFactory } from "../stream/sse";
|
|
10
10
|
import { type SSEConnection } from "../stream/sse";
|
|
11
|
+
import { rejectCrossOriginDevRequest } from "../ui/access-guard";
|
|
11
12
|
import {
|
|
12
13
|
type ManagerStatus,
|
|
13
14
|
type RunResult,
|
|
@@ -202,8 +203,11 @@ export async function registerDevTestRoutes(
|
|
|
202
203
|
|
|
203
204
|
const sseAvailable = dependencies?.sseAvailable ?? !!Sonamu.config.server.plugins?.sse;
|
|
204
205
|
|
|
206
|
+
// 루트 서버에 직접 등록되므로 전역 훅 대신 라우트마다 교차 출처 차단 훅을 붙입니다.
|
|
207
|
+
const routeOptions = { onRequest: rejectCrossOriginDevRequest };
|
|
208
|
+
|
|
205
209
|
if (sseAvailable) {
|
|
206
|
-
server.get(`${prefix}/events`, (request, reply): void => {
|
|
210
|
+
server.get(`${prefix}/events`, routeOptions, (request, reply): void => {
|
|
207
211
|
const sse: SSEConnection<typeof TestEventSchema> = createSSEFactory(
|
|
208
212
|
request.socket,
|
|
209
213
|
reply,
|
|
@@ -263,7 +267,7 @@ export async function registerDevTestRoutes(
|
|
|
263
267
|
});
|
|
264
268
|
}
|
|
265
269
|
|
|
266
|
-
server.post(`${prefix}/run`, async (request, reply) => {
|
|
270
|
+
server.post(`${prefix}/run`, routeOptions, async (request, reply) => {
|
|
267
271
|
const runId = randomUUID();
|
|
268
272
|
const runRequest = RunRequestSchema.parse(request.body ?? {});
|
|
269
273
|
|
|
@@ -312,7 +316,7 @@ export async function registerDevTestRoutes(
|
|
|
312
316
|
}
|
|
313
317
|
});
|
|
314
318
|
|
|
315
|
-
server.get(`${prefix}/status`, async () => {
|
|
319
|
+
server.get(`${prefix}/status`, routeOptions, async () => {
|
|
316
320
|
const status: ManagerStatus = manager.getStatus();
|
|
317
321
|
return { ...status, sseAvailable };
|
|
318
322
|
});
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { Sonamu } from "../../api/sonamu";
|
|
8
|
+
import { DB } from "../../database/db";
|
|
9
|
+
import { EntityManager } from "../../entity/entity-manager";
|
|
10
|
+
import { Syncer } from "../../syncer/syncer";
|
|
11
|
+
import { TemplateManager } from "../../template";
|
|
12
|
+
import { type AbsolutePath } from "../../utils/path-utils";
|
|
13
|
+
import { loadCliPlugins, SonamuCliPluginError, validateCliPlugins } from "../index";
|
|
14
|
+
|
|
15
|
+
const temporaryRoots: string[] = [];
|
|
16
|
+
const envBeforeTest = { ...process.env };
|
|
17
|
+
|
|
18
|
+
function restoreEnv(snapshot: NodeJS.ProcessEnv): void {
|
|
19
|
+
for (const key of Object.keys(process.env)) {
|
|
20
|
+
if (!Object.hasOwn(snapshot, key)) delete process.env[key];
|
|
21
|
+
}
|
|
22
|
+
Object.assign(process.env, snapshot);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function createProject(): Promise<string> {
|
|
26
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "sonamu-cli-plugins-"));
|
|
27
|
+
temporaryRoots.push(root);
|
|
28
|
+
await mkdir(path.join(root, "src"), { recursive: true });
|
|
29
|
+
await writeFile(path.join(root, ".env"), "SONAMU_DB_HOST=common-host\n");
|
|
30
|
+
await writeFile(path.join(root, ".env.development"), "SONAMU_DB_NAME=dev_db\n");
|
|
31
|
+
await writeFile(path.join(root, ".env.production"), "SONAMU_DB_NAME=prod_db\n");
|
|
32
|
+
await writeFile(
|
|
33
|
+
path.join(root, "src", "sonamu.config.ts"),
|
|
34
|
+
`
|
|
35
|
+
export default {
|
|
36
|
+
projectName: "PluginEnv",
|
|
37
|
+
api: { dir: "api", route: { prefix: "/api" } },
|
|
38
|
+
database: {},
|
|
39
|
+
i18n: { defaultLocale: "ko", supportedLocales: ["ko"] },
|
|
40
|
+
sync: { targets: [] },
|
|
41
|
+
logging: false,
|
|
42
|
+
server: { apiConfig: { contextProvider: (context) => context, guardHandler: () => {} } },
|
|
43
|
+
cli: { plugins: [{ name: "probe", commands: [{ path: ["probe"], run: () => null }] }] },
|
|
44
|
+
};
|
|
45
|
+
`,
|
|
46
|
+
);
|
|
47
|
+
return root;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const run = () => null;
|
|
51
|
+
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
vi.restoreAllMocks();
|
|
54
|
+
vi.unstubAllEnvs();
|
|
55
|
+
restoreEnv(envBeforeTest);
|
|
56
|
+
await Promise.all(
|
|
57
|
+
temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("CLI 플러그인 로딩", () => {
|
|
62
|
+
it("설정의 플러그인을 검증한 원본 객체 그대로 반환한다", async () => {
|
|
63
|
+
const root = await createProject();
|
|
64
|
+
|
|
65
|
+
const plugins = await loadCliPlugins(root);
|
|
66
|
+
|
|
67
|
+
expect(plugins.map((plugin) => plugin.name)).toEqual(["probe"]);
|
|
68
|
+
expect(plugins[0].commands[0].path).toEqual(["probe"]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("sonamu 설정이 없는 디렉터리에는 플러그인이 없다", async () => {
|
|
72
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "sonamu-cli-plugins-empty-"));
|
|
73
|
+
temporaryRoots.push(root);
|
|
74
|
+
|
|
75
|
+
await expect(loadCliPlugins(root)).resolves.toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("빌드되지 않은 프로젝트는 빌드가 필요하다는 오류로 실패한다", async () => {
|
|
79
|
+
const root = await createProject();
|
|
80
|
+
// Without VITEST or HOT the loader reads dist/sonamu.config.js, which this project lacks.
|
|
81
|
+
delete process.env.VITEST;
|
|
82
|
+
delete process.env.HOT;
|
|
83
|
+
|
|
84
|
+
await expect(loadCliPlugins(root)).rejects.toMatchObject({
|
|
85
|
+
code: "CONFIG_NOT_BUILT",
|
|
86
|
+
message: expect.stringMatching(/Build the project first/),
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("미리 로딩해도 이후 Sonamu.init의 dbConfig와 process.env가 달라지지 않는다", async () => {
|
|
91
|
+
const root = await createProject();
|
|
92
|
+
vi.stubEnv("NODE_ENV", "development");
|
|
93
|
+
vi.spyOn(DB, "setConfig").mockImplementation(() => {});
|
|
94
|
+
vi.spyOn(EntityManager, "autoload").mockResolvedValue(undefined);
|
|
95
|
+
vi.spyOn(Syncer.prototype, "autoloadTypes").mockResolvedValue(undefined);
|
|
96
|
+
vi.spyOn(Syncer.prototype, "autoloadModels").mockResolvedValue(undefined);
|
|
97
|
+
vi.spyOn(Syncer.prototype, "autoloadApis").mockResolvedValue(undefined);
|
|
98
|
+
vi.spyOn(Syncer.prototype, "autoloadWorkflows").mockResolvedValue(undefined);
|
|
99
|
+
vi.spyOn(Syncer.prototype, "autoloadSsrRoutes").mockResolvedValue(undefined);
|
|
100
|
+
vi.spyOn(TemplateManager, "autoload").mockResolvedValue(undefined);
|
|
101
|
+
const snapshot = Sonamu.captureTestingSnapshot();
|
|
102
|
+
const initialized = Sonamu.isInitialized;
|
|
103
|
+
const initializeWorkflows = Sonamu["initializeWorkflows"];
|
|
104
|
+
const dbConfig = Sonamu["dbConfigValue"];
|
|
105
|
+
Sonamu["initializeWorkflows"] = async () => {};
|
|
106
|
+
const envBefore = { ...process.env };
|
|
107
|
+
|
|
108
|
+
async function initialize(earlyLoad: boolean) {
|
|
109
|
+
restoreEnv(envBefore);
|
|
110
|
+
Sonamu.isInitialized = false;
|
|
111
|
+
if (earlyLoad) {
|
|
112
|
+
await loadCliPlugins(root);
|
|
113
|
+
expect({ ...process.env }).toEqual(envBefore);
|
|
114
|
+
}
|
|
115
|
+
// SAFETY: mkdtemp returns an absolute path.
|
|
116
|
+
await Sonamu.init(true, false, root as AbsolutePath);
|
|
117
|
+
return { dbConfig: structuredClone(Sonamu.dbConfig), env: { ...process.env } };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const withoutEarlyLoad = await initialize(false);
|
|
122
|
+
const withEarlyLoad = await initialize(true);
|
|
123
|
+
|
|
124
|
+
expect(withoutEarlyLoad.dbConfig.production.connection).toMatchObject({
|
|
125
|
+
database: "prod_db",
|
|
126
|
+
});
|
|
127
|
+
expect(withEarlyLoad).toEqual(withoutEarlyLoad);
|
|
128
|
+
} finally {
|
|
129
|
+
Sonamu.restoreTestingSnapshot(snapshot);
|
|
130
|
+
Sonamu.isInitialized = initialized;
|
|
131
|
+
Sonamu["initializeWorkflows"] = initializeWorkflows;
|
|
132
|
+
Reflect.set(Sonamu, "dbConfigValue", dbConfig);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("CLI 플러그인 선언 검증", () => {
|
|
138
|
+
it.each([
|
|
139
|
+
["빈 플러그인 이름", [{ name: " ", commands: [] }], " ", undefined, /name must not be empty/],
|
|
140
|
+
[
|
|
141
|
+
"CLI 단어가 아닌 경로",
|
|
142
|
+
[{ name: "p", commands: [{ path: ["Search"], run }] }],
|
|
143
|
+
"p",
|
|
144
|
+
"Search",
|
|
145
|
+
/path words/,
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
"camelCase가 아닌 옵션 키",
|
|
149
|
+
[
|
|
150
|
+
{
|
|
151
|
+
name: "p",
|
|
152
|
+
commands: [{ path: ["a"], options: { "max-rounds": { type: "integer" } }, run }],
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
"p",
|
|
156
|
+
"a",
|
|
157
|
+
/option key "max-rounds"/,
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
"camelCase가 아닌 인자 이름",
|
|
161
|
+
[{ name: "p", commands: [{ path: ["a"], arguments: [{ name: "Index" }], run }] }],
|
|
162
|
+
"p",
|
|
163
|
+
"a",
|
|
164
|
+
/argument names/,
|
|
165
|
+
],
|
|
166
|
+
[
|
|
167
|
+
"중복된 인자 이름",
|
|
168
|
+
[{ name: "p", commands: [{ path: ["a"], arguments: [{ name: "x" }, { name: "x" }], run }] }],
|
|
169
|
+
"p",
|
|
170
|
+
"a",
|
|
171
|
+
/declared twice/,
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
"선택 인자 뒤의 필수 인자",
|
|
175
|
+
[
|
|
176
|
+
{
|
|
177
|
+
name: "p",
|
|
178
|
+
commands: [
|
|
179
|
+
{ path: ["a"], arguments: [{ name: "x", required: false }, { name: "y" }], run },
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
"p",
|
|
184
|
+
"a",
|
|
185
|
+
/required arguments must come before optional/,
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
"마지막이 아닌 가변 인자",
|
|
189
|
+
[
|
|
190
|
+
{
|
|
191
|
+
name: "p",
|
|
192
|
+
commands: [
|
|
193
|
+
{ path: ["a"], arguments: [{ name: "x", variadic: true }, { name: "y" }], run },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
"p",
|
|
198
|
+
"a",
|
|
199
|
+
/only the last argument may be variadic/,
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
"boolean 옵션의 required",
|
|
203
|
+
[
|
|
204
|
+
{
|
|
205
|
+
name: "p",
|
|
206
|
+
commands: [{ path: ["a"], options: { force: { type: "boolean", required: true } }, run }],
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
"p",
|
|
210
|
+
"a",
|
|
211
|
+
/required and multiple apply only/,
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
"string이 아닌 옵션의 choices",
|
|
215
|
+
[
|
|
216
|
+
{
|
|
217
|
+
name: "p",
|
|
218
|
+
commands: [{ path: ["a"], options: { size: { type: "integer", choices: ["1"] } }, run }],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
"p",
|
|
222
|
+
"a",
|
|
223
|
+
/choices apply only to string/,
|
|
224
|
+
],
|
|
225
|
+
[
|
|
226
|
+
"함수가 아닌 run",
|
|
227
|
+
[{ name: "p", commands: [{ path: ["a"], run: "noop" }] }],
|
|
228
|
+
"p",
|
|
229
|
+
"a",
|
|
230
|
+
/run must be a function/,
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
"플러그인 간 중복 경로",
|
|
234
|
+
[
|
|
235
|
+
{ name: "p", commands: [{ path: ["a", "b"], run }] },
|
|
236
|
+
{ name: "q", commands: [{ path: ["a", "b"], run }] },
|
|
237
|
+
],
|
|
238
|
+
"q",
|
|
239
|
+
"a b",
|
|
240
|
+
/already declared by plugin "p"/,
|
|
241
|
+
],
|
|
242
|
+
[
|
|
243
|
+
"다른 명령의 접두사인 경로",
|
|
244
|
+
[
|
|
245
|
+
{
|
|
246
|
+
name: "p",
|
|
247
|
+
commands: [
|
|
248
|
+
{ path: ["a", "b"], run },
|
|
249
|
+
{ path: ["a"], run },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
"p",
|
|
254
|
+
"a",
|
|
255
|
+
/must not be a prefix/,
|
|
256
|
+
],
|
|
257
|
+
])("%s 선언을 거부한다", (_title, plugins, plugin, command, rule) => {
|
|
258
|
+
let thrown: unknown;
|
|
259
|
+
try {
|
|
260
|
+
validateCliPlugins(plugins);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
thrown = error;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
expect(thrown).toBeInstanceOf(SonamuCliPluginError);
|
|
266
|
+
expect(thrown).toMatchObject({
|
|
267
|
+
code: "INVALID_CLI_PLUGIN",
|
|
268
|
+
plugin,
|
|
269
|
+
command,
|
|
270
|
+
rule: expect.stringMatching(rule),
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
});
|
package/src/tooling/index.ts
CHANGED
package/src/types/types.ts
CHANGED
|
@@ -80,6 +80,11 @@ export type CommonProp = {
|
|
|
80
80
|
desc?: string;
|
|
81
81
|
dbDefault?: string;
|
|
82
82
|
generated?: GeneratedColumn;
|
|
83
|
+
/**
|
|
84
|
+
* true이면 생성되는 `{Entity}BaseSaveParams`(클라이언트 저장 입력)에서 제외합니다.
|
|
85
|
+
* 권한·인증 상태·비밀값처럼 클라이언트가 직접 바꾸면 안 되는 시스템 컬럼에 지정합니다.
|
|
86
|
+
*/
|
|
87
|
+
readonly?: boolean;
|
|
83
88
|
cone?: Cone; // cone 메타데이터
|
|
84
89
|
};
|
|
85
90
|
|
|
@@ -244,6 +249,8 @@ type _RelationProp = {
|
|
|
244
249
|
nullable?: boolean; // DEFAULT: false
|
|
245
250
|
toFilter?: true; // DEFAULT: false
|
|
246
251
|
desc?: string;
|
|
252
|
+
/** true이면 생성되는 `{Entity}BaseSaveParams`에서 FK 컬럼(`{name}_id`)을 제외합니다. */
|
|
253
|
+
readonly?: boolean;
|
|
247
254
|
cone?: Cone; // cone 메타데이터
|
|
248
255
|
};
|
|
249
256
|
export type OneToOneRelationProp = _RelationProp & {
|
|
@@ -1170,6 +1177,7 @@ const BasePropFields = {
|
|
|
1170
1177
|
toFilter: z.boolean().default(false).optional(),
|
|
1171
1178
|
dbDefault: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
|
1172
1179
|
generated: GeneratedColumnSchema.optional(),
|
|
1180
|
+
readonly: z.boolean().optional(),
|
|
1173
1181
|
cone: ConeSchema.optional(),
|
|
1174
1182
|
};
|
|
1175
1183
|
|
|
@@ -1849,6 +1857,11 @@ export type SonamuFastifyConfig = {
|
|
|
1849
1857
|
) =>
|
|
1850
1858
|
| import("../api/context").WebSocketContext
|
|
1851
1859
|
| Promise<import("../api/context").WebSocketContext>;
|
|
1860
|
+
/**
|
|
1861
|
+
* API의 `guards` 키마다 순서대로 호출되는 가드 핸들러입니다.
|
|
1862
|
+
* 반환한 Promise는 기다리며, 예외를 던지거나 `false`를 반환하면 요청을 거부합니다.
|
|
1863
|
+
* `false` 반환은 UnauthorizedException(401)으로 처리됩니다.
|
|
1864
|
+
*/
|
|
1852
1865
|
guardHandler: (
|
|
1853
1866
|
guard: GuardKey,
|
|
1854
1867
|
request: FastifyRequest,
|
|
@@ -1861,7 +1874,15 @@ export type SonamuFastifyConfig = {
|
|
|
1861
1874
|
path: string;
|
|
1862
1875
|
options: ApiDecoratorOptions;
|
|
1863
1876
|
},
|
|
1864
|
-
) => void
|
|
1877
|
+
) => void | boolean | Promise<void | boolean>;
|
|
1878
|
+
/**
|
|
1879
|
+
* guardHandler가 실제로 검사하는 가드 키 목록입니다.
|
|
1880
|
+
*
|
|
1881
|
+
* 설정하면 목록에 없는 가드 키는 guardHandler를 호출하지 않고 거부(401)하며,
|
|
1882
|
+
* 목록에 없는 키를 쓰는 API가 있으면 부팅을 중단합니다.
|
|
1883
|
+
* 설정하지 않으면 모든 키를 guardHandler에 넘기는 기존 동작을 유지하고 부팅 시 경고합니다.
|
|
1884
|
+
*/
|
|
1885
|
+
guardKeys?: readonly GuardKey[];
|
|
1865
1886
|
/**
|
|
1866
1887
|
* 전역 Cache-Control 핸들러입니다.
|
|
1867
1888
|
* 요청 타입(api, assets, ssr, csr)에 따라 Cache-Control 설정을 반환합니다.
|