sonamu 0.14.2 → 0.15.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/auth/better-auth-entities.d.ts.map +1 -1
- package/dist/auth/better-auth-entities.js +35 -35
- package/dist/auth/plugins/entity-definitions/admin.js +6 -6
- package/dist/auth/plugins/entity-definitions/anonymous.js +2 -2
- package/dist/auth/plugins/entity-definitions/api-key.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/api-key.js +23 -23
- package/dist/auth/plugins/entity-definitions/audit-log.d.ts.map +1 -1
- package/dist/auth/plugins/entity-definitions/audit-log.js +28 -28
- package/dist/auth/plugins/entity-definitions/jwt.js +6 -6
- package/dist/auth/plugins/entity-definitions/organization.js +32 -32
- package/dist/auth/plugins/entity-definitions/passkey.js +12 -12
- package/dist/auth/plugins/entity-definitions/phone-number.js +3 -3
- package/dist/auth/plugins/entity-definitions/sso.js +9 -9
- package/dist/auth/plugins/entity-definitions/two-factor.js +11 -11
- package/dist/auth/plugins/entity-definitions/username.js +3 -3
- package/dist/dict/sonamu-dictionary.js +9 -9
- package/dist/dict/types.d.ts +1 -1
- package/dist/dict/types.d.ts.map +1 -1
- package/dist/entity/entity-codegen-safety.d.ts +2 -1
- package/dist/entity/entity-codegen-safety.d.ts.map +1 -1
- package/dist/entity/entity-codegen-safety.js +3 -2
- package/dist/entity/entity-manager.d.ts +40 -20
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +4 -2
- package/dist/index.js +2 -2
- package/dist/template/helpers.js +3 -3
- package/dist/template/implementations/entity.template.js +4 -4
- package/dist/template/implementations/generated.template.d.ts.map +1 -1
- package/dist/template/implementations/generated.template.js +3 -4
- package/dist/template/implementations/sd.template.js +3 -3
- package/dist/template/implementations/view_form.template.js +2 -2
- package/dist/template/zod-converter.d.ts +12 -2
- package/dist/template/zod-converter.d.ts.map +1 -1
- package/dist/template/zod-converter.js +31 -18
- package/dist/types/types.d.ts +153 -64
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +19 -7
- package/dist/ui/ai-client.js +3 -3
- package/dist/ui/api.js +2 -2
- package/dist/ui-web/assets/{index-ChMwt-QA.js → index-CdZtV4yt.js} +5 -5
- package/dist/ui-web/index.html +1 -1
- package/package.json +1 -1
- package/src/auth/better-auth-entities.ts +40 -34
- package/src/auth/plugins/entity-definitions/admin.ts +5 -5
- package/src/auth/plugins/entity-definitions/anonymous.ts +1 -1
- package/src/auth/plugins/entity-definitions/api-key.ts +28 -22
- package/src/auth/plugins/entity-definitions/audit-log.ts +34 -27
- package/src/auth/plugins/entity-definitions/jwt.ts +5 -5
- package/src/auth/plugins/entity-definitions/organization.ts +31 -31
- package/src/auth/plugins/entity-definitions/passkey.ts +11 -11
- package/src/auth/plugins/entity-definitions/phone-number.ts +2 -2
- package/src/auth/plugins/entity-definitions/sso.ts +8 -8
- package/src/auth/plugins/entity-definitions/two-factor.ts +10 -10
- package/src/auth/plugins/entity-definitions/username.ts +2 -2
- package/src/dict/sonamu-dictionary.ts +6 -6
- package/src/dict/types.ts +1 -1
- package/src/entity/__tests__/entity-codegen-safety.test.ts +44 -12
- package/src/entity/__tests__/entity-subset-query.test.ts +35 -7
- package/src/entity/entity-codegen-safety.ts +2 -1
- package/src/entity/entity.ts +3 -0
- package/src/shared/app.shared.ts.txt +1 -2
- package/src/shared/web.shared.ts.txt +1 -2
- package/src/template/helpers.ts +3 -3
- package/src/template/implementations/entity.template.ts +3 -3
- package/src/template/implementations/generated.template.ts +4 -3
- package/src/template/implementations/sd.template.ts +2 -2
- package/src/template/implementations/view_form.template.ts +1 -1
- package/src/template/zod-converter.ts +84 -19
- package/src/types/types.ts +42 -8
- package/src/ui/ai-client.ts +2 -2
- package/src/ui/api.ts +2 -2
- package/src/ui/entity.instructions.md +45 -43
|
@@ -51,7 +51,7 @@ export class Template__entity extends Template {
|
|
|
51
51
|
props: options.props?.length
|
|
52
52
|
? options.props
|
|
53
53
|
: [
|
|
54
|
-
{ name: "id", type: "integer",
|
|
54
|
+
{ name: "id", type: "integer", title: "ID" },
|
|
55
55
|
...(parent
|
|
56
56
|
? [
|
|
57
57
|
{
|
|
@@ -61,14 +61,14 @@ export class Template__entity extends Template {
|
|
|
61
61
|
with: parentId,
|
|
62
62
|
onUpdate: "CASCADE",
|
|
63
63
|
onDelete: "CASCADE",
|
|
64
|
-
|
|
64
|
+
title: parent.entity.title,
|
|
65
65
|
},
|
|
66
66
|
]
|
|
67
67
|
: []),
|
|
68
68
|
{
|
|
69
69
|
name: "created_at",
|
|
70
70
|
type: "date",
|
|
71
|
-
|
|
71
|
+
title: "등록일시",
|
|
72
72
|
dbDefault: "CURRENT_TIMESTAMP",
|
|
73
73
|
},
|
|
74
74
|
],
|
|
@@ -128,7 +128,6 @@ export class Template__generated extends Template {
|
|
|
128
128
|
const builtInSchemas = sourceCode.importKeys.filter((key) => builtInSchemaNames.includes(key));
|
|
129
129
|
const sonamuImports = [
|
|
130
130
|
"zArrayable",
|
|
131
|
-
"SQLDateTimeString",
|
|
132
131
|
"SubsetQuery",
|
|
133
132
|
"SonamuQueryMode",
|
|
134
133
|
"ApplySonamuFilter",
|
|
@@ -163,9 +162,10 @@ export class Template__generated extends Template {
|
|
|
163
162
|
.filter(([, enumLabel]) => Object.keys(enumLabel).length > 0)
|
|
164
163
|
.flatMap(([enumId, enumLabel]) => [
|
|
165
164
|
// enum 키는 자유 문자열이므로 JSON 문자열 리터럴로 출력합니다.
|
|
165
|
+
// SonamuEnumId는 필터 UI가 enum.{EnumId}.{값} 라벨 키를 만들 때 읽습니다.
|
|
166
166
|
`export const ${enumId} = z.enum([${Object.keys(enumLabel).map((el) =>
|
|
167
167
|
JSON.stringify(el),
|
|
168
|
-
)}]).
|
|
168
|
+
)}]).meta({ SonamuEnumId: ${JSON.stringify(enumId)} });`,
|
|
169
169
|
`export type ${enumId} = z.infer<typeof ${enumId}>;`,
|
|
170
170
|
`export const ${enumId}Label = ${JSON.stringify(enumLabel)};`,
|
|
171
171
|
]),
|
|
@@ -460,7 +460,8 @@ z.object({
|
|
|
460
460
|
};
|
|
461
461
|
|
|
462
462
|
// EntityPropNode[]로 ZodTypeDef(string)을 가져옴
|
|
463
|
-
|
|
463
|
+
// 서브셋은 API 응답 스키마라 칸의 title·description을 메타로 실어 명세에 나오게 합니다.
|
|
464
|
+
const body = propNodeToZodTypeDef(propNode, importKeys, { withPropMeta: true });
|
|
464
465
|
|
|
465
466
|
return [
|
|
466
467
|
`export const ${schemaName} = ${body.replace(/,$/, "")};`,
|
|
@@ -386,8 +386,8 @@ SD.enumLabels = (enumName: string): Record<string, LocalizedString> => {
|
|
|
386
386
|
|
|
387
387
|
// prop labels (entity.json에서 관리)
|
|
388
388
|
for (const prop of entity.props) {
|
|
389
|
-
if (prop.
|
|
390
|
-
labels.push({ key: `entity.${entityId}.${prop.name}`, value: prop.
|
|
389
|
+
if (prop.title) {
|
|
390
|
+
labels.push({ key: `entity.${entityId}.${prop.name}`, value: prop.title });
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
|
|
@@ -222,7 +222,7 @@ export class Template__view_form extends Template {
|
|
|
222
222
|
.filter((col) => col.name !== "id")
|
|
223
223
|
.map((col) => {
|
|
224
224
|
const propCandidate = entity.props.find((prop) => prop.name === col.name);
|
|
225
|
-
col.label = propCandidate?.
|
|
225
|
+
col.label = propCandidate?.title ?? col.label;
|
|
226
226
|
return col;
|
|
227
227
|
});
|
|
228
228
|
|
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
isVectorArrayProp,
|
|
54
54
|
isVectorSingleProp,
|
|
55
55
|
isVirtualProp,
|
|
56
|
+
getSonamuType,
|
|
56
57
|
SonamuFileArraySchema,
|
|
57
58
|
SonamuFileSchema,
|
|
58
59
|
} from "../types/types";
|
|
@@ -93,7 +94,9 @@ export const BUILT_IN_TYPES = {
|
|
|
93
94
|
} as const;
|
|
94
95
|
|
|
95
96
|
function getBuiltInSchemaName(zodType: z.ZodType): string | undefined {
|
|
96
|
-
const matched = Object.entries(BUILT_IN_TYPES).find(
|
|
97
|
+
const matched = Object.entries(BUILT_IN_TYPES).find(
|
|
98
|
+
([typeId]) => getSonamuType(zodType) === typeId,
|
|
99
|
+
);
|
|
97
100
|
return matched?.[1].schemaName;
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -210,7 +213,8 @@ export async function getZodTypeById(zodTypeId: string): Promise<z.ZodTypeAny> {
|
|
|
210
213
|
if (!builtInType) {
|
|
211
214
|
throw new Error(`내장 타입 ${zodTypeId}의 스키마가 정의되지 않았습니다`);
|
|
212
215
|
}
|
|
213
|
-
|
|
216
|
+
// 내장 스키마는 정의할 때 이미 타입 표식을 걸어 두었습니다.
|
|
217
|
+
return builtInType.schema;
|
|
214
218
|
}
|
|
215
219
|
|
|
216
220
|
// 프로젝트에서 정의한 타입 동적 로드
|
|
@@ -225,7 +229,9 @@ export async function getZodTypeById(zodTypeId: string): Promise<z.ZodTypeAny> {
|
|
|
225
229
|
if (!imported[zodTypeId]) {
|
|
226
230
|
throw new Error(`존재하지 않는 zodTypeId ${zodTypeId}`);
|
|
227
231
|
}
|
|
228
|
-
|
|
232
|
+
// `.meta()`는 복제본에 메타를 걸므로 사용자 스키마는 그대로입니다. 복제본은 사용자가 단 description 등을 키별로 물려받습니다.
|
|
233
|
+
const marked: z.ZodTypeAny = imported[zodTypeId].meta({ SonamuType: zodTypeId });
|
|
234
|
+
return marked;
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
/**
|
|
@@ -336,10 +342,67 @@ export async function propToZodType(prop: EntityProp): Promise<z.ZodTypeAny> {
|
|
|
336
342
|
return zodType;
|
|
337
343
|
}
|
|
338
344
|
|
|
345
|
+
/**
|
|
346
|
+
* 생성 코드에 칸 메타를 실을지 정하는 옵션입니다.
|
|
347
|
+
*/
|
|
348
|
+
export type PropZodTypeDefOptions = {
|
|
349
|
+
/**
|
|
350
|
+
* true이면 칸의 title·description을 `.meta({ title, description })`로 싣습니다.
|
|
351
|
+
* `z.toJSONSchema` 결과에 그대로 나옵니다. 서브셋 스키마에서 켭니다.
|
|
352
|
+
*/
|
|
353
|
+
withPropMeta?: boolean;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 생성 코드의 `.meta()`에 싣는 칸 메타입니다.
|
|
358
|
+
*
|
|
359
|
+
* zod 기본 레지스트리 메타에 평평한 키로 실립니다. `title`·`description`은 zod 표준 키이고,
|
|
360
|
+
* `Sonamu`로 시작하는 키는 Sonamu와 react-components가 읽는 표식입니다.
|
|
361
|
+
*/
|
|
362
|
+
type PropMeta = {
|
|
363
|
+
/** 칸의 표시 이름 */
|
|
364
|
+
title?: string;
|
|
365
|
+
/** 칸의 뜻 */
|
|
366
|
+
description?: string;
|
|
367
|
+
/** numeric 칸 표시. 필터 UI가 읽습니다. */
|
|
368
|
+
SonamuPropType?: "numeric";
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 칸의 zod 정의 코드 뒤에 붙일 `.meta({...})` 코드를 만듭니다.
|
|
373
|
+
*
|
|
374
|
+
* `.nullable()` 뒤 맨 바깥에 붙여 nullable 칸도 메타가 바깥에 실리게 합니다.
|
|
375
|
+
*/
|
|
376
|
+
function propMetaCode(
|
|
377
|
+
prop: { title?: string; description?: string },
|
|
378
|
+
options: PropZodTypeDefOptions,
|
|
379
|
+
extraMeta: PropMeta = {},
|
|
380
|
+
): string {
|
|
381
|
+
const meta: PropMeta = {};
|
|
382
|
+
if (options.withPropMeta && prop.title) {
|
|
383
|
+
meta.title = prop.title;
|
|
384
|
+
}
|
|
385
|
+
if (options.withPropMeta && prop.description) {
|
|
386
|
+
meta.description = prop.description;
|
|
387
|
+
}
|
|
388
|
+
Object.assign(meta, extraMeta);
|
|
389
|
+
|
|
390
|
+
if (Object.keys(meta).length === 0) {
|
|
391
|
+
return "";
|
|
392
|
+
}
|
|
393
|
+
// 값은 자유 문자열이므로 JSON 문자열 리터럴로 출력합니다.
|
|
394
|
+
const entries = Object.entries(meta).map(([key, value]) => `${key}: ${JSON.stringify(value)}`);
|
|
395
|
+
return `.meta({ ${entries.join(", ")} })`;
|
|
396
|
+
}
|
|
397
|
+
|
|
339
398
|
/**
|
|
340
399
|
* EntityProp을 Zod 타입 정의 코드 문자열로 변환합니다.
|
|
341
400
|
*/
|
|
342
|
-
export function propToZodTypeDef(
|
|
401
|
+
export function propToZodTypeDef(
|
|
402
|
+
prop: EntityProp,
|
|
403
|
+
injectImportKeys: string[],
|
|
404
|
+
options: PropZodTypeDefOptions = {},
|
|
405
|
+
): string {
|
|
343
406
|
let stmt: string;
|
|
344
407
|
if (isIntegerSingleProp(prop)) {
|
|
345
408
|
stmt = `${prop.name}: z.int()`;
|
|
@@ -456,9 +519,9 @@ export function propToZodTypeDef(prop: EntityProp, injectImportKeys: string[]):
|
|
|
456
519
|
}
|
|
457
520
|
|
|
458
521
|
// numeric 타입의 경우 nullable 이후에 meta 추가 (메타데이터가 최상위 레벨에 있어야 함)
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
522
|
+
const numericMeta: PropMeta =
|
|
523
|
+
isNumericSingleProp(prop) || isNumericArrayProp(prop) ? { SonamuPropType: "numeric" } : {};
|
|
524
|
+
stmt += propMetaCode(prop, options, numericMeta);
|
|
462
525
|
|
|
463
526
|
return `${stmt},`;
|
|
464
527
|
}
|
|
@@ -467,28 +530,32 @@ export function propToZodTypeDef(prop: EntityProp, injectImportKeys: string[]):
|
|
|
467
530
|
* EntityPropNode를 Zod 타입 정의 코드 문자열로 변환합니다.
|
|
468
531
|
* plain, array, object 노드 타입을 재귀적으로 처리하여 중첩 구조를 지원합니다.
|
|
469
532
|
*/
|
|
470
|
-
export function propNodeToZodTypeDef(
|
|
533
|
+
export function propNodeToZodTypeDef(
|
|
534
|
+
propNode: EntityPropNode,
|
|
535
|
+
injectImportKeys: string[],
|
|
536
|
+
options: PropZodTypeDefOptions = {},
|
|
537
|
+
): string {
|
|
471
538
|
if (propNode.nodeType === "plain") {
|
|
472
|
-
return propToZodTypeDef(propNode.prop, injectImportKeys);
|
|
539
|
+
return propToZodTypeDef(propNode.prop, injectImportKeys, options);
|
|
473
540
|
} else if (propNode.nodeType === "array") {
|
|
474
541
|
return [
|
|
475
542
|
propNode.prop ? `${propNode.prop.name}: ` : "",
|
|
476
543
|
"z.array(z.object({",
|
|
477
544
|
propNode.children
|
|
478
|
-
.map((childPropNode) => propNodeToZodTypeDef(childPropNode, injectImportKeys))
|
|
545
|
+
.map((childPropNode) => propNodeToZodTypeDef(childPropNode, injectImportKeys, options))
|
|
479
546
|
.join("\n"),
|
|
480
547
|
"",
|
|
481
|
-
|
|
548
|
+
`}))${propNode.prop ? propMetaCode(propNode.prop, options) : ""},`,
|
|
482
549
|
].join("\n");
|
|
483
550
|
} else if (propNode.nodeType === "object") {
|
|
484
551
|
return [
|
|
485
552
|
propNode.prop ? `${propNode.prop.name}: ` : "",
|
|
486
553
|
"z.object({",
|
|
487
554
|
propNode.children
|
|
488
|
-
.map((childPropNode) => propNodeToZodTypeDef(childPropNode, injectImportKeys))
|
|
555
|
+
.map((childPropNode) => propNodeToZodTypeDef(childPropNode, injectImportKeys, options))
|
|
489
556
|
.join("\n"),
|
|
490
557
|
"",
|
|
491
|
-
`})${propNode.prop?.nullable ? ".nullable()" : ""},`,
|
|
558
|
+
`})${propNode.prop?.nullable ? ".nullable()" : ""}${propNode.prop ? propMetaCode(propNode.prop, options) : ""},`,
|
|
492
559
|
].join("\n");
|
|
493
560
|
} else {
|
|
494
561
|
throw Error;
|
|
@@ -791,7 +858,7 @@ export function zodTypeToRenderingNode(
|
|
|
791
858
|
/**
|
|
792
859
|
* 케이스 처리 순서
|
|
793
860
|
*
|
|
794
|
-
* 1. 특수 케이스 (
|
|
861
|
+
* 1. 특수 케이스 (Sonamu 타입 표식 기반)
|
|
795
862
|
* - SonamuFile/SonamuFile[] : z.object/z.array이지만 파일 업로드용 내장 타입
|
|
796
863
|
*
|
|
797
864
|
* 2. 일반 케이스 (instanceof 기반)
|
|
@@ -804,12 +871,12 @@ export function zodTypeToRenderingNode(
|
|
|
804
871
|
*/
|
|
805
872
|
|
|
806
873
|
// 특수 케이스: SonamuFile[] 타입 감지
|
|
807
|
-
if (zodType
|
|
874
|
+
if (getSonamuType(zodType) === "SonamuFile[]") {
|
|
808
875
|
return { ...def, renderType: "json-sonamufile-array" };
|
|
809
876
|
}
|
|
810
877
|
|
|
811
878
|
// 특수 케이스: SonamuFile 단일 타입 감지
|
|
812
|
-
if (zodType
|
|
879
|
+
if (getSonamuType(zodType) === "SonamuFile") {
|
|
813
880
|
return { ...def, renderType: "json-sonamufile" };
|
|
814
881
|
}
|
|
815
882
|
|
|
@@ -889,9 +956,7 @@ function resolveRenderType(key: string, zodType: z.ZodTypeAny): RenderingNode["r
|
|
|
889
956
|
} else if (zodType instanceof z.core.$ZodString) {
|
|
890
957
|
// NOTE: z.ZodString으로 비교하면 z.url(), z.email() 등의 타입에서 문제가 생기므로 z.core.$ZodString으로 비교함
|
|
891
958
|
// FIXME: email이나 url 타입 등에 대한 처리가 필요함
|
|
892
|
-
if (
|
|
893
|
-
return "string-datetime";
|
|
894
|
-
} else if (key.endsWith("date")) {
|
|
959
|
+
if (key.endsWith("date")) {
|
|
895
960
|
return "string-date";
|
|
896
961
|
} else if (key === "id") {
|
|
897
962
|
return "string-id";
|
package/src/types/types.ts
CHANGED
|
@@ -77,7 +77,10 @@ export type CommonProp = {
|
|
|
77
77
|
name: string;
|
|
78
78
|
nullable?: boolean;
|
|
79
79
|
toFilter?: true;
|
|
80
|
-
|
|
80
|
+
/** 칸의 표시 이름입니다. 서브셋 스키마에 zod 메타 `title`로 실립니다. */
|
|
81
|
+
title?: string;
|
|
82
|
+
/** 칸이 무슨 뜻인지 적는 설명입니다. 서브셋 스키마에 zod `description`으로 실립니다. */
|
|
83
|
+
description?: string;
|
|
81
84
|
dbDefault?: string;
|
|
82
85
|
generated?: GeneratedColumn;
|
|
83
86
|
/**
|
|
@@ -91,10 +94,10 @@ export type CommonProp = {
|
|
|
91
94
|
/**
|
|
92
95
|
* prop의 설명을 반환합니다.
|
|
93
96
|
*
|
|
94
|
-
* cone.note가 있으면 우선 사용하고, 없으면 prop.
|
|
97
|
+
* cone.note가 있으면 우선 사용하고, 없으면 prop.title을 사용합니다.
|
|
95
98
|
*/
|
|
96
|
-
export function getDescription(item: {
|
|
97
|
-
return item.cone?.note || item.
|
|
99
|
+
export function getDescription(item: { title?: string; cone?: Cone }): string | undefined {
|
|
100
|
+
return item.cone?.note || item.title;
|
|
98
101
|
}
|
|
99
102
|
export type IntegerProp = CommonProp & {
|
|
100
103
|
type: "integer";
|
|
@@ -248,7 +251,10 @@ type _RelationProp = {
|
|
|
248
251
|
with: string;
|
|
249
252
|
nullable?: boolean; // DEFAULT: false
|
|
250
253
|
toFilter?: true; // DEFAULT: false
|
|
251
|
-
|
|
254
|
+
/** 칸의 표시 이름입니다. */
|
|
255
|
+
title?: string;
|
|
256
|
+
/** 칸이 무슨 뜻인지 적는 설명입니다. */
|
|
257
|
+
description?: string;
|
|
252
258
|
/** true이면 생성되는 `{Entity}BaseSaveParams`에서 FK 컬럼(`{name}_id`)을 제외합니다. */
|
|
253
259
|
readonly?: boolean;
|
|
254
260
|
cone?: Cone; // cone 메타데이터
|
|
@@ -346,6 +352,33 @@ export interface SonamuFile extends SonamuFileBase, SonamuFileExtend {}
|
|
|
346
352
|
*/
|
|
347
353
|
export interface UploadParams {}
|
|
348
354
|
|
|
355
|
+
declare module "zod" {
|
|
356
|
+
/**
|
|
357
|
+
* Sonamu가 zod 기본 레지스트리 메타에 평평한 키로 싣는 표식입니다.
|
|
358
|
+
* zod 메타는 키별로 합쳐지므로 사용자가 `title`·`description`을 더해도 표식이 남습니다.
|
|
359
|
+
*/
|
|
360
|
+
interface GlobalMeta {
|
|
361
|
+
/** 칸 종류 표식. 내장 타입(`SonamuFile`, `SonamuFile[]`)이나 사용자 JSON 타입 이름입니다. */
|
|
362
|
+
SonamuType?: string;
|
|
363
|
+
/** 생성된 enum의 ID. 필터 UI가 `enum.{EnumId}.{값}` 라벨 키를 만들 때 읽습니다. */
|
|
364
|
+
SonamuEnumId?: string;
|
|
365
|
+
/** numeric 칸 표시. 필터 UI가 읽습니다. */
|
|
366
|
+
SonamuPropType?: "numeric";
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* 스키마의 zod 기본 레지스트리 메타에서 Sonamu 타입 표식(`SonamuType`)을 읽습니다.
|
|
372
|
+
*
|
|
373
|
+
* 표식은 `.meta({ SonamuType: "..." })`로 겁니다. `title`·`description` 같은 zod 표준 메타와
|
|
374
|
+
* 같은 레지스트리에 평평한 키로 두므로, 사용자가 `.describe()`·`.meta()`로 메타를 더해도 키별로 합쳐져
|
|
375
|
+
* 표식이 지워지지 않습니다. `.optional()`·`.nullable()`·`z.array()`로 감싼 스키마는 메타를 물려받지
|
|
376
|
+
* 않으므로 감싼 스키마는 벗겨서 넘겨야 합니다.
|
|
377
|
+
*/
|
|
378
|
+
export function getSonamuType(schema: z.core.$ZodType): string | undefined {
|
|
379
|
+
return z.globalRegistry.get(schema)?.SonamuType;
|
|
380
|
+
}
|
|
381
|
+
|
|
349
382
|
export const SonamuFileSchema: z.ZodType<SonamuFile> = z
|
|
350
383
|
.looseObject({
|
|
351
384
|
name: z.string(),
|
|
@@ -353,9 +386,9 @@ export const SonamuFileSchema: z.ZodType<SonamuFile> = z
|
|
|
353
386
|
mime_type: z.string(),
|
|
354
387
|
size: z.number(),
|
|
355
388
|
})
|
|
356
|
-
.
|
|
389
|
+
.meta({ SonamuType: "SonamuFile" });
|
|
357
390
|
|
|
358
|
-
export const SonamuFileArraySchema = z.array(SonamuFileSchema).
|
|
391
|
+
export const SonamuFileArraySchema = z.array(SonamuFileSchema).meta({ SonamuType: "SonamuFile[]" });
|
|
359
392
|
|
|
360
393
|
/**
|
|
361
394
|
* Sonamu 코어에서 제공하는 내장 JSON 타입 ID 목록
|
|
@@ -1172,7 +1205,8 @@ const GeneratedColumnSchema = z.object({
|
|
|
1172
1205
|
|
|
1173
1206
|
const BasePropFields = {
|
|
1174
1207
|
name: z.string(),
|
|
1175
|
-
|
|
1208
|
+
title: z.string().optional(),
|
|
1209
|
+
description: z.string().optional(),
|
|
1176
1210
|
nullable: z.boolean().optional(),
|
|
1177
1211
|
toFilter: z.boolean().default(false).optional(),
|
|
1178
1212
|
dbDefault: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
package/src/ui/ai-client.ts
CHANGED
|
@@ -281,7 +281,7 @@ class AIClient {
|
|
|
281
281
|
props: entity.props.map((p) => ({
|
|
282
282
|
name: p.name,
|
|
283
283
|
type: p.type,
|
|
284
|
-
|
|
284
|
+
title: p.title,
|
|
285
285
|
})),
|
|
286
286
|
};
|
|
287
287
|
});
|
|
@@ -327,7 +327,7 @@ ${JSON.stringify(existingEntities, null, 2)}
|
|
|
327
327
|
updateEntity({ entityId: "Employee", updates: { enumLabels: { "EmployeeRole": { "admin": "관리자", "user": "일반" } } } })
|
|
328
328
|
|
|
329
329
|
예시: Project에 새 프로퍼티 추가
|
|
330
|
-
updateEntity({ entityId: "Project", updates: { props: [{ name: "priority", type: "integer",
|
|
330
|
+
updateEntity({ entityId: "Project", updates: { props: [{ name: "priority", type: "integer", title: "우선순위" }] } })
|
|
331
331
|
|
|
332
332
|
## 필수 사항
|
|
333
333
|
- Entity의 props에는 최소한 id(integer, unsigned), created_at(timestamp)가 포함되어야 합니다.
|
package/src/ui/api.ts
CHANGED
|
@@ -202,10 +202,10 @@ export async function sonamuUIApiPlugin(fastify: FastifyInstance) {
|
|
|
202
202
|
if (glossary.has(prop.name)) {
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
|
-
if (prop.
|
|
205
|
+
if (prop.title) {
|
|
206
206
|
glossary.set(
|
|
207
207
|
prop.name,
|
|
208
|
-
prop.
|
|
208
|
+
prop.title.replace(glossaryEntity.title ?? "", "{EntityID}"),
|
|
209
209
|
);
|
|
210
210
|
}
|
|
211
211
|
});
|