@spfn/cms 0.1.0-alpha.5 → 0.1.0-alpha.60

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.
Files changed (176) hide show
  1. package/dist/actions.d.ts +140 -6
  2. package/dist/actions.js +97 -10
  3. package/dist/actions.js.map +1 -1
  4. package/dist/client.d.ts +43 -9
  5. package/dist/client.js +406 -56
  6. package/dist/client.js.map +1 -1
  7. package/dist/contracts/labels.d.ts +149 -0
  8. package/dist/contracts/labels.js +166 -0
  9. package/dist/contracts/labels.js.map +1 -0
  10. package/dist/contracts/published-cache.d.ts +25 -0
  11. package/dist/contracts/published-cache.js +32 -0
  12. package/dist/contracts/published-cache.js.map +1 -0
  13. package/dist/contracts/values.d.ts +69 -0
  14. package/dist/contracts/values.js +100 -0
  15. package/dist/contracts/values.js.map +1 -0
  16. package/dist/entities/cms-audit-logs.d.ts +15 -70
  17. package/dist/entities/cms-audit-logs.js +75 -100
  18. package/dist/entities/cms-audit-logs.js.map +1 -1
  19. package/dist/entities/cms-draft-cache.d.ts +13 -73
  20. package/dist/entities/cms-draft-cache.js +35 -109
  21. package/dist/entities/cms-draft-cache.js.map +1 -1
  22. package/dist/entities/cms-label-values.d.ts +14 -65
  23. package/dist/entities/cms-label-values.js +78 -102
  24. package/dist/entities/cms-label-values.js.map +1 -1
  25. package/dist/entities/cms-label-versions.d.ts +16 -49
  26. package/dist/entities/cms-label-versions.js +73 -77
  27. package/dist/entities/cms-label-versions.js.map +1 -1
  28. package/dist/entities/cms-labels.d.ts +17 -14
  29. package/dist/entities/cms-labels.js +39 -45
  30. package/dist/entities/cms-labels.js.map +1 -1
  31. package/dist/entities/cms-published-cache.d.ts +14 -69
  32. package/dist/entities/cms-published-cache.js +33 -100
  33. package/dist/entities/cms-published-cache.js.map +1 -1
  34. package/dist/entities/index.d.ts +7 -10
  35. package/dist/entities/index.js +217 -9
  36. package/dist/entities/index.js.map +1 -1
  37. package/dist/generators/index.d.ts +8 -7
  38. package/dist/generators/index.js +657 -17
  39. package/dist/generators/index.js.map +1 -1
  40. package/dist/index.d.ts +134 -20
  41. package/dist/index.js +1115 -23
  42. package/dist/index.js.map +1 -1
  43. package/dist/{generators/label-sync-generator.d.ts → label-sync-generator-lQrcVfja.d.ts} +9 -6
  44. package/dist/labels/index.d.ts +31 -4
  45. package/dist/labels/index.js +31 -6
  46. package/dist/labels/index.js.map +1 -1
  47. package/dist/repositories/index.d.ts +205 -6
  48. package/dist/repositories/index.js +435 -8
  49. package/dist/repositories/index.js.map +1 -1
  50. package/dist/routes/labels/[id]/index.js +499 -89
  51. package/dist/routes/labels/[id]/index.js.map +1 -1
  52. package/dist/routes/labels/{[id] → _id_}/index.d.ts +5 -3
  53. package/dist/routes/labels/by-key/[key]/index.js +453 -29
  54. package/dist/routes/labels/by-key/[key]/index.js.map +1 -1
  55. package/dist/routes/labels/by-key/_key_/index.d.ts +10 -0
  56. package/dist/routes/labels/index.d.ts +5 -3
  57. package/dist/routes/labels/index.js +488 -68
  58. package/dist/routes/labels/index.js.map +1 -1
  59. package/dist/routes/published-cache/index.d.ts +5 -3
  60. package/dist/routes/published-cache/index.js +325 -30
  61. package/dist/routes/published-cache/index.js.map +1 -1
  62. package/dist/routes/values/[labelId]/[version]/index.js +467 -41
  63. package/dist/routes/values/[labelId]/[version]/index.js.map +1 -1
  64. package/dist/routes/values/[labelId]/index.js +463 -39
  65. package/dist/routes/values/[labelId]/index.js.map +1 -1
  66. package/dist/routes/values/_labelId_/_version_/index.d.ts +10 -0
  67. package/dist/routes/values/_labelId_/index.d.ts +10 -0
  68. package/dist/server.d.ts +17 -7
  69. package/dist/server.js +263 -244
  70. package/dist/server.js.map +1 -1
  71. package/dist/store.d.ts +8 -14
  72. package/dist/store.js +396 -198
  73. package/dist/store.js.map +1 -1
  74. package/dist/types.d.ts +14 -7
  75. package/dist/types.js +0 -6
  76. package/dist/types.js.map +1 -1
  77. package/migrations/0000_condemned_centennial.sql +89 -0
  78. package/migrations/meta/0000_snapshot.json +687 -0
  79. package/migrations/meta/_journal.json +13 -0
  80. package/package.json +33 -16
  81. package/dist/actions.d.ts.map +0 -1
  82. package/dist/client.d.ts.map +0 -1
  83. package/dist/cms.config.d.ts +0 -77
  84. package/dist/cms.config.d.ts.map +0 -1
  85. package/dist/cms.config.js +0 -111
  86. package/dist/cms.config.js.map +0 -1
  87. package/dist/entities/cms-audit-logs.d.ts.map +0 -1
  88. package/dist/entities/cms-draft-cache.d.ts.map +0 -1
  89. package/dist/entities/cms-label-values.d.ts.map +0 -1
  90. package/dist/entities/cms-label-versions.d.ts.map +0 -1
  91. package/dist/entities/cms-labels.d.ts.map +0 -1
  92. package/dist/entities/cms-published-cache.d.ts.map +0 -1
  93. package/dist/entities/index.d.ts.map +0 -1
  94. package/dist/generators/index.d.ts.map +0 -1
  95. package/dist/generators/label-sync-generator.d.ts.map +0 -1
  96. package/dist/generators/label-sync-generator.js +0 -87
  97. package/dist/generators/label-sync-generator.js.map +0 -1
  98. package/dist/helpers/locale.actions.d.ts +0 -132
  99. package/dist/helpers/locale.actions.d.ts.map +0 -1
  100. package/dist/helpers/locale.actions.js +0 -210
  101. package/dist/helpers/locale.actions.js.map +0 -1
  102. package/dist/helpers/locale.constants.d.ts +0 -10
  103. package/dist/helpers/locale.constants.d.ts.map +0 -1
  104. package/dist/helpers/locale.constants.js +0 -10
  105. package/dist/helpers/locale.constants.js.map +0 -1
  106. package/dist/helpers/locale.d.ts +0 -17
  107. package/dist/helpers/locale.d.ts.map +0 -1
  108. package/dist/helpers/locale.js +0 -20
  109. package/dist/helpers/locale.js.map +0 -1
  110. package/dist/helpers/sync.d.ts +0 -41
  111. package/dist/helpers/sync.d.ts.map +0 -1
  112. package/dist/helpers/sync.js +0 -309
  113. package/dist/helpers/sync.js.map +0 -1
  114. package/dist/index.d.ts.map +0 -1
  115. package/dist/init.d.ts +0 -31
  116. package/dist/init.d.ts.map +0 -1
  117. package/dist/init.js +0 -36
  118. package/dist/init.js.map +0 -1
  119. package/dist/labels/helpers.d.ts +0 -31
  120. package/dist/labels/helpers.d.ts.map +0 -1
  121. package/dist/labels/helpers.js +0 -60
  122. package/dist/labels/helpers.js.map +0 -1
  123. package/dist/labels/index.d.ts.map +0 -1
  124. package/dist/repositories/cms-draft-cache.repository.d.ts +0 -62
  125. package/dist/repositories/cms-draft-cache.repository.d.ts.map +0 -1
  126. package/dist/repositories/cms-draft-cache.repository.js +0 -56
  127. package/dist/repositories/cms-draft-cache.repository.js.map +0 -1
  128. package/dist/repositories/cms-label-values.repository.d.ts +0 -32
  129. package/dist/repositories/cms-label-values.repository.d.ts.map +0 -1
  130. package/dist/repositories/cms-label-values.repository.js +0 -72
  131. package/dist/repositories/cms-label-values.repository.js.map +0 -1
  132. package/dist/repositories/cms-labels.repository.d.ts +0 -53
  133. package/dist/repositories/cms-labels.repository.d.ts.map +0 -1
  134. package/dist/repositories/cms-labels.repository.js +0 -77
  135. package/dist/repositories/cms-labels.repository.js.map +0 -1
  136. package/dist/repositories/cms-published-cache.repository.d.ts +0 -53
  137. package/dist/repositories/cms-published-cache.repository.d.ts.map +0 -1
  138. package/dist/repositories/cms-published-cache.repository.js +0 -54
  139. package/dist/repositories/cms-published-cache.repository.js.map +0 -1
  140. package/dist/repositories/index.d.ts.map +0 -1
  141. package/dist/routes/labels/[id]/contract.d.ts +0 -68
  142. package/dist/routes/labels/[id]/contract.d.ts.map +0 -1
  143. package/dist/routes/labels/[id]/contract.js +0 -84
  144. package/dist/routes/labels/[id]/contract.js.map +0 -1
  145. package/dist/routes/labels/[id]/index.d.ts.map +0 -1
  146. package/dist/routes/labels/by-key/[key]/contract.d.ts +0 -24
  147. package/dist/routes/labels/by-key/[key]/contract.d.ts.map +0 -1
  148. package/dist/routes/labels/by-key/[key]/contract.js +0 -28
  149. package/dist/routes/labels/by-key/[key]/contract.js.map +0 -1
  150. package/dist/routes/labels/by-key/[key]/index.d.ts +0 -8
  151. package/dist/routes/labels/by-key/[key]/index.d.ts.map +0 -1
  152. package/dist/routes/labels/contract.d.ts +0 -59
  153. package/dist/routes/labels/contract.d.ts.map +0 -1
  154. package/dist/routes/labels/contract.js +0 -75
  155. package/dist/routes/labels/contract.js.map +0 -1
  156. package/dist/routes/labels/index.d.ts.map +0 -1
  157. package/dist/routes/published-cache/contract.d.ts +0 -25
  158. package/dist/routes/published-cache/contract.d.ts.map +0 -1
  159. package/dist/routes/published-cache/contract.js +0 -35
  160. package/dist/routes/published-cache/contract.js.map +0 -1
  161. package/dist/routes/published-cache/index.d.ts.map +0 -1
  162. package/dist/routes/values/[labelId]/[version]/contract.d.ts +0 -29
  163. package/dist/routes/values/[labelId]/[version]/contract.d.ts.map +0 -1
  164. package/dist/routes/values/[labelId]/[version]/contract.js +0 -33
  165. package/dist/routes/values/[labelId]/[version]/contract.js.map +0 -1
  166. package/dist/routes/values/[labelId]/[version]/index.d.ts +0 -8
  167. package/dist/routes/values/[labelId]/[version]/index.d.ts.map +0 -1
  168. package/dist/routes/values/[labelId]/contract.d.ts +0 -38
  169. package/dist/routes/values/[labelId]/contract.d.ts.map +0 -1
  170. package/dist/routes/values/[labelId]/contract.js +0 -59
  171. package/dist/routes/values/[labelId]/contract.js.map +0 -1
  172. package/dist/routes/values/[labelId]/index.d.ts +0 -8
  173. package/dist/routes/values/[labelId]/index.d.ts.map +0 -1
  174. package/dist/server.d.ts.map +0 -1
  175. package/dist/store.d.ts.map +0 -1
  176. package/dist/types.d.ts.map +0 -1
@@ -1,19 +1,659 @@
1
- /**
2
- * SPFN CMS Generators Registry
3
- *
4
- * Exports generators for use with package-based naming convention
5
- * e.g., @spfn/cms:label-sync
6
- */
7
- import { createLabelSyncGenerator } from './label-sync-generator.js';
8
- /**
9
- * Generators registry
10
- * Maps generator names to their factory functions
11
- */
12
- export const generators = {
13
- 'label-sync': createLabelSyncGenerator,
1
+ // src/generators/label-sync-generator.ts
2
+ import { logger } from "@spfn/core";
3
+ import { join as join2 } from "path";
4
+
5
+ // src/helpers/sync.ts
6
+ import { existsSync, readdirSync, readFileSync, statSync } from "fs";
7
+ import { basename, extname, join } from "path";
8
+
9
+ // src/labels/helpers.ts
10
+ function flattenLabels(labels) {
11
+ const result = [];
12
+ function isLabelDefinition(obj) {
13
+ return "key" in obj && "defaultValue" in obj && typeof obj.key === "string" && (typeof obj.defaultValue === "string" || typeof obj.defaultValue === "object");
14
+ }
15
+ function traverse(obj) {
16
+ if (isLabelDefinition(obj)) {
17
+ result.push({
18
+ key: obj.key,
19
+ defaultValue: obj.defaultValue,
20
+ description: obj.description
21
+ });
22
+ } else {
23
+ Object.values(obj).forEach((value) => {
24
+ if (typeof value === "object" && value !== null) {
25
+ traverse(value);
26
+ }
27
+ });
28
+ }
29
+ }
30
+ traverse(labels);
31
+ return result;
32
+ }
33
+ function extractLabels(definition) {
34
+ return flattenLabels(definition.labels);
35
+ }
36
+
37
+ // src/repositories/cms-labels.repository.ts
38
+ import { findOne, findMany as findManyHelper, create as createHelper, updateOne, deleteOne, count as countHelper } from "@spfn/core/db";
39
+ import { desc } from "drizzle-orm";
40
+
41
+ // src/entities/cms-labels.ts
42
+ import { index, integer, serial, text, timestamp } from "drizzle-orm/pg-core";
43
+ import { createFunctionSchema } from "@spfn/core/db";
44
+ var schema = createFunctionSchema("@spfn/cms");
45
+ var cmsLabels = schema.table("labels", {
46
+ // Primary Key
47
+ id: serial("id").primaryKey(),
48
+ // 라벨 식별자
49
+ key: text("key").notNull().unique(),
50
+ // 예: "home.hero.title", "why-futureplay.hero.subtitle"
51
+ // 구조: {section}.{component}.{property}
52
+ // 섹션 분류 (페이지 단위)
53
+ section: text("section").notNull(),
54
+ // 예: "home", "why-futureplay", "team"
55
+ // 값 타입
56
+ type: text("type").notNull(),
57
+ // "text" | "image" | "video" | "file" | "object"
58
+ // 기본값
59
+ defaultValue: text("default_value"),
60
+ // 라벨의 기본값 (sync 시 설정)
61
+ // 설명
62
+ description: text("description"),
63
+ // 라벨에 대한 설명 (optional)
64
+ // 현재 발행된 버전 번호
65
+ publishedVersion: integer("published_version"),
66
+ // null = 미발행 상태
67
+ // 1, 2, 3... = 발행된 버전 번호
68
+ // 생성자 추적
69
+ createdBy: text("created_by"),
70
+ // 타임스탬프
71
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
72
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
73
+ }, (table) => [
74
+ // 인덱스: 섹션별 조회 최적화
75
+ index("cms_labels_section_idx").on(table.section),
76
+ // 인덱스: key로 조회 최적화 (unique 제약으로 자동 생성되지만 명시)
77
+ index("cms_labels_key_idx").on(table.key)
78
+ ]);
79
+
80
+ // src/entities/cms-label-values.ts
81
+ import { serial as serial2, integer as integer2, text as text2, jsonb, timestamp as timestamp2, index as index2, unique } from "drizzle-orm/pg-core";
82
+ import { createFunctionSchema as createFunctionSchema2 } from "@spfn/core/db";
83
+ var schema2 = createFunctionSchema2("@spfn/cms");
84
+ var cmsLabelValues = schema2.table("label_values", {
85
+ // Primary Key
86
+ id: serial2("id").primaryKey(),
87
+ // Foreign Key: cms_labels
88
+ labelId: integer2("label_id").notNull().references(() => cmsLabels.id, { onDelete: "cascade" }),
89
+ // 버전 번호
90
+ version: integer2("version").notNull().default(1),
91
+ // 언어 코드
92
+ locale: text2("locale").notNull().default("ko"),
93
+ // "ko" | "en" | "ja"
94
+ // 반응형 브레이크포인트
95
+ breakpoint: text2("breakpoint"),
96
+ // null = 기본값 (모든 화면 크기)
97
+ // "sm" | "md" | "lg" | "xl" | "2xl"
98
+ // 실제 값 (JSONB)
99
+ value: jsonb("value").notNull(),
100
+ // LabelValue 타입:
101
+ // - TextValue: { type: "text", content: string }
102
+ // - ImageValue: { type: "image", url: string, alt?: string, width?: number, height?: number }
103
+ // - VideoValue: { type: "video", url: string, thumbnail?: string, duration?: number }
104
+ // - FileValue: { type: "file", url: string, filename: string, size?: number }
105
+ // - ObjectValue: { type: "object", fields: Record<string, LabelValue> }
106
+ // 생성 시각
107
+ createdAt: timestamp2("created_at", { withTimezone: true }).notNull().defaultNow()
108
+ }, (table) => [
109
+ // UNIQUE 제약: 같은 버전에서 locale + breakpoint 조합은 유일
110
+ unique("cms_label_values_locale_breakpoint_unique").on(table.labelId, table.version, table.locale, table.breakpoint),
111
+ // 인덱스: labelId + version 복합 조회 최적화
112
+ index2("cms_label_values_label_version_idx").on(table.labelId, table.version),
113
+ // 인덱스: locale 필터링 최적화
114
+ index2("cms_label_values_locale_idx").on(table.locale)
115
+ ]);
116
+
117
+ // src/entities/cms-label-versions.ts
118
+ import { serial as serial3, integer as integer3, text as text3, timestamp as timestamp3, index as index3, unique as unique2 } from "drizzle-orm/pg-core";
119
+ import { createFunctionSchema as createFunctionSchema3 } from "@spfn/core/db";
120
+ var schema3 = createFunctionSchema3("@spfn/cms");
121
+ var cmsLabelVersions = schema3.table("label_versions", {
122
+ // Primary Key
123
+ id: serial3("id").primaryKey(),
124
+ // Foreign Key: cms_labels
125
+ labelId: integer3("label_id").notNull().references(() => cmsLabels.id, { onDelete: "cascade" }),
126
+ // 버전 번호
127
+ version: integer3("version").notNull(),
128
+ // 버전 상태
129
+ status: text3("status").notNull(),
130
+ // "draft" | "published" | "archived"
131
+ // 발행 정보
132
+ publishedAt: timestamp3("published_at", { withTimezone: true }),
133
+ publishedBy: text3("published_by"),
134
+ // 버전 노트 (변경사항 설명)
135
+ notes: text3("notes"),
136
+ // 버전 생성자
137
+ createdBy: text3("created_by"),
138
+ // 생성 시각
139
+ createdAt: timestamp3("created_at", { withTimezone: true }).notNull().defaultNow()
140
+ }, (table) => [
141
+ // UNIQUE 제약: 각 라벨의 버전 번호는 고유
142
+ unique2("cms_label_versions_label_version_unique").on(table.labelId, table.version),
143
+ // 인덱스: labelId로 버전 목록 조회 최적화
144
+ index3("cms_label_versions_label_id_idx").on(table.labelId),
145
+ // 인덱스: status 필터링 최적화
146
+ index3("cms_label_versions_status_idx").on(table.status)
147
+ ]);
148
+
149
+ // src/entities/cms-draft-cache.ts
150
+ import { serial as serial4, text as text4, jsonb as jsonb2, timestamp as timestamp4, index as index4, unique as unique3 } from "drizzle-orm/pg-core";
151
+ import { createFunctionSchema as createFunctionSchema4 } from "@spfn/core/db";
152
+ var schema4 = createFunctionSchema4("@spfn/cms");
153
+ var cmsDraftCache = schema4.table("draft_cache", {
154
+ // Primary Key
155
+ id: serial4("id").primaryKey(),
156
+ // 섹션 (페이지 단위)
157
+ section: text4("section").notNull(),
158
+ // "home" | "why-futureplay" | "team" | "our-companies" | "apply"
159
+ // 언어
160
+ locale: text4("locale").notNull(),
161
+ // "ko" | "en" | "ja"
162
+ // 사용자 ID (핵심 필드!)
163
+ userId: text4("user_id").notNull(),
164
+ // 각 관리자의 독립적인 작업 공간
165
+ // Draft 콘텐츠 (JSONB)
166
+ content: jsonb2("content").notNull(),
167
+ // Record<string, LabelValue>
168
+ // {
169
+ // "home.hero.title": { type: "text", content: "수정 중..." },
170
+ // "home.hero.subtitle": { type: "text", content: "새로운 문구" },
171
+ // ...
172
+ // }
173
+ // 최종 수정 시각
174
+ updatedAt: timestamp4("updated_at", { withTimezone: true }).notNull().defaultNow()
175
+ }, (table) => [
176
+ // UNIQUE 제약: section + locale + userId 조합은 유일
177
+ unique3("cms_draft_cache_unique").on(table.section, table.locale, table.userId),
178
+ // 인덱스: section으로 조회 최적화
179
+ index4("cms_draft_cache_section_idx").on(table.section),
180
+ // 인덱스: userId로 사용자의 모든 draft 조회 최적화
181
+ index4("cms_draft_cache_user_idx").on(table.userId)
182
+ ]);
183
+
184
+ // src/entities/cms-published-cache.ts
185
+ import { serial as serial5, text as text5, jsonb as jsonb3, integer as integer4, timestamp as timestamp5, index as index5, unique as unique4 } from "drizzle-orm/pg-core";
186
+ import { createFunctionSchema as createFunctionSchema5 } from "@spfn/core/db";
187
+ var schema5 = createFunctionSchema5("@spfn/cms");
188
+ var cmsPublishedCache = schema5.table("published_cache", {
189
+ // Primary Key
190
+ id: serial5("id").primaryKey(),
191
+ // 섹션 (페이지 단위)
192
+ section: text5("section").notNull(),
193
+ // "home" | "why-futureplay" | "team" | "our-companies" | "apply"
194
+ // 언어
195
+ locale: text5("locale").notNull(),
196
+ // "ko" | "en" | "ja"
197
+ // 캐시된 콘텐츠 (JSONB)
198
+ content: jsonb3("content").notNull(),
199
+ // Record<string, LabelValue>
200
+ // {
201
+ // "home.hero.title": { type: "text", content: "..." },
202
+ // "home.hero.image": { type: "image", url: "...", alt: "..." },
203
+ // ...
204
+ // }
205
+ // 발행 정보
206
+ publishedAt: timestamp5("published_at", { withTimezone: true }).notNull(),
207
+ publishedBy: text5("published_by"),
208
+ // 캐시 버전 (클라이언트 캐싱용)
209
+ version: integer4("version").notNull().default(1)
210
+ }, (table) => [
211
+ // UNIQUE 제약: section + locale 조합은 유일
212
+ unique4("cms_published_cache_unique").on(table.section, table.locale),
213
+ // 인덱스: section으로 조회 최적화
214
+ index5("cms_published_cache_section_idx").on(table.section)
215
+ ]);
216
+
217
+ // src/entities/cms-audit-logs.ts
218
+ import { serial as serial6, integer as integer5, text as text6, jsonb as jsonb4, timestamp as timestamp6, index as index6 } from "drizzle-orm/pg-core";
219
+ import { createFunctionSchema as createFunctionSchema6 } from "@spfn/core/db";
220
+ var schema6 = createFunctionSchema6("@spfn/cms");
221
+ var cmsAuditLogs = schema6.table("audit_logs", {
222
+ // Primary Key
223
+ id: serial6("id").primaryKey(),
224
+ // Foreign Key: cms_labels (nullable - 라벨 삭제 시 로그는 유지)
225
+ labelId: integer5("label_id").references(() => cmsLabels.id, { onDelete: "set null" }),
226
+ // 작업 유형
227
+ action: text6("action").notNull(),
228
+ // "create" | "update" | "publish" | "unpublish" | "archive" | "delete" | "rollback" | "duplicate"
229
+ // 사용자 정보
230
+ userId: text6("user_id").notNull(),
231
+ userName: text6("user_name"),
232
+ // 변경 내용 (before/after)
233
+ changes: jsonb4("changes"),
234
+ // { before: {...}, after: {...} }
235
+ // 추가 메타데이터
236
+ metadata: jsonb4("metadata"),
237
+ // { version: number, ip: string, userAgent: string, ... }
238
+ // 작업 시각
239
+ createdAt: timestamp6("created_at", { withTimezone: true }).notNull().defaultNow()
240
+ }, (table) => [
241
+ // 인덱스: labelId로 이력 조회 최적화
242
+ index6("cms_audit_logs_label_id_idx").on(table.labelId),
243
+ // 인덱스: userId로 사용자 활동 조회 최적화
244
+ index6("cms_audit_logs_user_id_idx").on(table.userId),
245
+ // 인덱스: action 필터링 최적화
246
+ index6("cms_audit_logs_action_idx").on(table.action),
247
+ // 인덱스: 시간순 조회 최적화
248
+ index6("cms_audit_logs_created_at_idx").on(table.createdAt)
249
+ ]);
250
+
251
+ // src/repositories/cms-labels.repository.ts
252
+ async function findMany(options) {
253
+ const { section, limit = 20, offset = 0 } = options || {};
254
+ return findManyHelper(cmsLabels, {
255
+ where: section ? { section } : void 0,
256
+ orderBy: desc(cmsLabels.updatedAt),
257
+ limit,
258
+ offset
259
+ });
260
+ }
261
+ async function count(section) {
262
+ return countHelper(cmsLabels, section ? { section } : void 0);
263
+ }
264
+ async function findById(id) {
265
+ return findOne(cmsLabels, { id });
266
+ }
267
+ async function findByKey(key) {
268
+ return findOne(cmsLabels, { key });
269
+ }
270
+ async function findBySection(section) {
271
+ return findManyHelper(cmsLabels, {
272
+ where: { section },
273
+ orderBy: desc(cmsLabels.updatedAt)
274
+ });
275
+ }
276
+ async function create(data) {
277
+ return createHelper(cmsLabels, data);
278
+ }
279
+ async function updateById(id, data) {
280
+ return updateOne(cmsLabels, { id }, { ...data, updatedAt: /* @__PURE__ */ new Date() });
281
+ }
282
+ async function deleteById(id) {
283
+ return deleteOne(cmsLabels, { id });
284
+ }
285
+ var cmsLabelsRepository = {
286
+ findMany,
287
+ count,
288
+ findById,
289
+ findByKey,
290
+ findBySection,
291
+ create,
292
+ updateById,
293
+ deleteById
294
+ };
295
+
296
+ // src/repositories/cms-label-values.repository.ts
297
+ import { findOne as findOne2, findMany as findMany2, create as create2, updateOne as updateOne2, deleteMany } from "@spfn/core/db";
298
+ import { eq, and, isNull } from "drizzle-orm";
299
+
300
+ // src/repositories/cms-draft-cache.repository.ts
301
+ import { findOne as findOne3, findMany as findMany3, deleteOne as deleteOne2, deleteMany as deleteMany2, upsert as upsertHelper } from "@spfn/core/db";
302
+ import { eq as eq2, and as and2, lt } from "drizzle-orm";
303
+
304
+ // src/repositories/cms-published-cache.repository.ts
305
+ import { findOne as findOne4, findMany as findMany4, deleteOne as deleteOne3, deleteMany as deleteMany3, upsert as upsertHelper2 } from "@spfn/core/db";
306
+ import { eq as eq3, and as and3, sql } from "drizzle-orm";
307
+ async function findBySection2(section, locale = "ko") {
308
+ return findOne4(
309
+ cmsPublishedCache,
310
+ and3(
311
+ eq3(cmsPublishedCache.section, section),
312
+ eq3(cmsPublishedCache.locale, locale)
313
+ )
314
+ );
315
+ }
316
+ async function upsert(data) {
317
+ return upsertHelper2(cmsPublishedCache, data, {
318
+ target: [cmsPublishedCache.section, cmsPublishedCache.locale],
319
+ set: {
320
+ content: data.content,
321
+ publishedAt: data.publishedAt,
322
+ publishedBy: data.publishedBy,
323
+ version: sql`${cmsPublishedCache.version} + 1`
324
+ // 버전 증가로 클라이언트 캐시 무효화
325
+ }
326
+ });
327
+ }
328
+ async function findAllLanguages(section) {
329
+ return findMany4(cmsPublishedCache, {
330
+ where: eq3(cmsPublishedCache.section, section)
331
+ });
332
+ }
333
+ async function deleteBySection(section, locale) {
334
+ if (locale) {
335
+ await deleteOne3(
336
+ cmsPublishedCache,
337
+ and3(
338
+ eq3(cmsPublishedCache.section, section),
339
+ eq3(cmsPublishedCache.locale, locale)
340
+ )
341
+ );
342
+ } else {
343
+ await deleteMany3(
344
+ cmsPublishedCache,
345
+ eq3(cmsPublishedCache.section, section)
346
+ );
347
+ }
348
+ }
349
+ var cmsPublishedCacheRepository = {
350
+ findBySection: findBySection2,
351
+ upsert,
352
+ findAllLanguages,
353
+ deleteBySection
354
+ };
355
+
356
+ // src/helpers/sync.ts
357
+ async function syncAll(sections, options = {}) {
358
+ const results = [];
359
+ for (const definition of sections) {
360
+ const result = await syncSection(definition, options);
361
+ results.push(result);
362
+ }
363
+ return results;
364
+ }
365
+ function loadLabelsFromJson(labelsDir) {
366
+ const sections = [];
367
+ if (!existsSync(labelsDir)) {
368
+ console.warn(`[CMS] Labels directory not found: ${labelsDir}`);
369
+ console.warn(`[CMS] Expected directory structure:`);
370
+ console.warn(`[CMS] ${labelsDir}/`);
371
+ console.warn(`[CMS] \u251C\u2500\u2500 common/ # Section directory`);
372
+ console.warn(`[CMS] \u2502 \u251C\u2500\u2500 messages.json`);
373
+ console.warn(`[CMS] \u2502 \u2514\u2500\u2500 errors.json`);
374
+ console.warn(`[CMS] \u2514\u2500\u2500 home/ # Section directory`);
375
+ console.warn(`[CMS] \u2514\u2500\u2500 hero.json`);
376
+ return sections;
377
+ }
378
+ try {
379
+ const entries = readdirSync(labelsDir);
380
+ if (entries.length === 0) {
381
+ console.warn(`[CMS] Labels directory is empty: ${labelsDir}`);
382
+ console.warn(`[CMS] Create section directories with JSON files inside`);
383
+ return sections;
384
+ }
385
+ const jsonFiles = entries.filter((e) => extname(e) === ".json");
386
+ if (jsonFiles.length > 0) {
387
+ console.warn(`[CMS] Found JSON files directly in ${labelsDir}:`);
388
+ jsonFiles.forEach((f) => console.warn(`[CMS] - ${f} (will be ignored)`));
389
+ console.warn(`[CMS] JSON files should be inside section directories`);
390
+ console.warn(`[CMS] Example: Move ${jsonFiles[0]} to ${labelsDir}/${basename(jsonFiles[0], ".json")}/${jsonFiles[0]}`);
391
+ }
392
+ for (const entry of entries) {
393
+ const sectionPath = join(labelsDir, entry);
394
+ const stat = statSync(sectionPath);
395
+ if (stat.isDirectory()) {
396
+ const sectionName = entry;
397
+ const labels = loadSectionLabels(sectionPath);
398
+ if (Object.keys(labels).length > 0) {
399
+ sections.push({ section: sectionName, labels });
400
+ } else {
401
+ console.warn(`[CMS] Section directory "${sectionName}" has no valid JSON files`);
402
+ }
403
+ }
404
+ }
405
+ if (sections.length === 0) {
406
+ console.warn(`[CMS] No valid section directories found in ${labelsDir}`);
407
+ }
408
+ } catch (error) {
409
+ console.warn(`[CMS] Could not scan labels directory: ${labelsDir}`);
410
+ console.error(`[CMS] Error:`, error);
411
+ }
412
+ return sections;
413
+ }
414
+ function loadSectionLabels(sectionPath) {
415
+ const labels = {};
416
+ try {
417
+ const files = readdirSync(sectionPath);
418
+ for (const file of files) {
419
+ if (extname(file) === ".json") {
420
+ const filePath = join(sectionPath, file);
421
+ const categoryName = basename(file, ".json");
422
+ try {
423
+ const content = readFileSync(filePath, "utf-8");
424
+ labels[categoryName] = JSON.parse(content);
425
+ } catch (error) {
426
+ console.warn(`[CMS] Failed to parse ${filePath}`);
427
+ }
428
+ }
429
+ }
430
+ } catch (error) {
431
+ console.warn(`[CMS] Could not read section directory: ${sectionPath}`);
432
+ }
433
+ return labels;
434
+ }
435
+ async function syncSection(definition, options = {}) {
436
+ const {
437
+ dryRun = false,
438
+ updateExisting = false,
439
+ removeUnused = false,
440
+ verbose = false
441
+ } = options;
442
+ const { section } = definition;
443
+ const result = {
444
+ section,
445
+ created: 0,
446
+ updated: 0,
447
+ deleted: 0,
448
+ unchanged: 0,
449
+ errors: []
450
+ };
451
+ try {
452
+ const definedLabels = extractLabels(definition);
453
+ const definedKeys = new Set(definedLabels.map((l) => l.key));
454
+ const existingLabels = await cmsLabelsRepository.findBySection(section);
455
+ const existingMap = new Map(existingLabels.map((l) => [l.key, l]));
456
+ if (verbose) {
457
+ console.log(`
458
+ [${section}] Found ${definedLabels.length} labels in definition`);
459
+ console.log(`[${section}] Found ${existingLabels.length} labels in DB`);
460
+ }
461
+ for (const label of definedLabels) {
462
+ const existing = existingMap.get(label.key);
463
+ if (!existing) {
464
+ if (verbose) console.log(` [CREATE] ${label.key}`);
465
+ if (!dryRun) {
466
+ try {
467
+ const defaultValue = typeof label.defaultValue === "object" ? JSON.stringify(label.defaultValue) : label.defaultValue;
468
+ await cmsLabelsRepository.create({
469
+ section,
470
+ key: label.key,
471
+ type: label.type || "text",
472
+ // 라벨 타입 (기본값: 'text')
473
+ defaultValue,
474
+ description: label.description
475
+ });
476
+ } catch (error) {
477
+ result.errors.push({
478
+ key: label.key,
479
+ error: error instanceof Error ? error.message : String(error)
480
+ });
481
+ continue;
482
+ }
483
+ }
484
+ result.created++;
485
+ } else if (updateExisting) {
486
+ const newDefaultValue = typeof label.defaultValue === "object" ? JSON.stringify(label.defaultValue) : label.defaultValue;
487
+ const hasChanged = existing.defaultValue !== newDefaultValue;
488
+ if (hasChanged) {
489
+ if (verbose) {
490
+ console.log(` [UPDATE] ${label.key}`);
491
+ console.log(` Old: "${existing.defaultValue}"`);
492
+ console.log(` New: "${newDefaultValue}"`);
493
+ }
494
+ if (!dryRun) {
495
+ try {
496
+ await cmsLabelsRepository.updateById(existing.id, {
497
+ defaultValue: newDefaultValue,
498
+ description: label.description
499
+ });
500
+ } catch (error) {
501
+ result.errors.push({
502
+ key: label.key,
503
+ error: error instanceof Error ? error.message : String(error)
504
+ });
505
+ continue;
506
+ }
507
+ }
508
+ result.updated++;
509
+ } else {
510
+ result.unchanged++;
511
+ }
512
+ } else {
513
+ result.unchanged++;
514
+ }
515
+ }
516
+ if (removeUnused) {
517
+ for (const existing of existingLabels) {
518
+ if (!definedKeys.has(existing.key)) {
519
+ if (verbose) console.log(` [DELETE] ${existing.key}`);
520
+ if (!dryRun) {
521
+ try {
522
+ await cmsLabelsRepository.deleteById(existing.id);
523
+ } catch (error) {
524
+ result.errors.push({
525
+ key: existing.key,
526
+ error: error instanceof Error ? error.message : String(error)
527
+ });
528
+ continue;
529
+ }
530
+ }
531
+ result.deleted++;
532
+ }
533
+ }
534
+ }
535
+ if (!dryRun && (result.created > 0 || result.updated > 0 || result.deleted > 0)) {
536
+ if (verbose) console.log(` [CACHE] Updating published cache for section: ${section}`);
537
+ await updatePublishedCache(section);
538
+ }
539
+ } catch (error) {
540
+ result.errors.push({
541
+ key: "__section__",
542
+ error: error instanceof Error ? error.message : String(error)
543
+ });
544
+ }
545
+ return result;
546
+ }
547
+ async function updatePublishedCache(section) {
548
+ const labels = await cmsLabelsRepository.findBySection(section);
549
+ const localesSet = /* @__PURE__ */ new Set();
550
+ const labelsByLocale = {};
551
+ labels.forEach((label) => {
552
+ try {
553
+ const parsed = JSON.parse(label.defaultValue || "{}");
554
+ if (typeof parsed === "object" && !Array.isArray(parsed)) {
555
+ Object.keys(parsed).forEach((locale) => localesSet.add(locale));
556
+ Object.entries(parsed).forEach(([locale, value]) => {
557
+ if (!labelsByLocale[locale]) labelsByLocale[locale] = {};
558
+ labelsByLocale[locale][label.key] = value;
559
+ });
560
+ } else {
561
+ if (!labelsByLocale.ko) labelsByLocale.ko = {};
562
+ labelsByLocale.ko[label.key] = label.defaultValue;
563
+ localesSet.add("ko");
564
+ }
565
+ } catch {
566
+ if (!labelsByLocale.ko) labelsByLocale.ko = {};
567
+ labelsByLocale.ko[label.key] = label.defaultValue;
568
+ localesSet.add("ko");
569
+ }
570
+ });
571
+ const timestamp7 = /* @__PURE__ */ new Date();
572
+ for (const locale of localesSet) {
573
+ await cmsPublishedCacheRepository.upsert({
574
+ section,
575
+ locale,
576
+ content: labelsByLocale[locale] || {},
577
+ publishedAt: timestamp7,
578
+ publishedBy: "system"
579
+ });
580
+ }
581
+ }
582
+
583
+ // src/generators/label-sync-generator.ts
584
+ var syncLogger = logger.child("label-sync");
585
+ var LabelSyncGenerator = class {
586
+ name = "label-sync";
587
+ labelsDir;
588
+ constructor(config = {}) {
589
+ this.labelsDir = config.labelsDir ?? "src/cms/labels";
590
+ }
591
+ /**
592
+ * Watch patterns for label definition files
593
+ */
594
+ get watchPatterns() {
595
+ return [
596
+ `${this.labelsDir}/**/*.json`
597
+ ];
598
+ }
599
+ async generate(options) {
600
+ if (options.debug) {
601
+ syncLogger.info("Starting label sync...");
602
+ }
603
+ try {
604
+ const labelsPath = join2(options.cwd, this.labelsDir);
605
+ const sections = loadLabelsFromJson(labelsPath);
606
+ if (sections.length === 0) {
607
+ syncLogger.warn(`No labels found in ${labelsPath}`);
608
+ return;
609
+ }
610
+ syncLogger.info(`Found ${sections.length} sections`);
611
+ const results = await syncAll(sections, {
612
+ verbose: options.debug ?? false,
613
+ updateExisting: true
614
+ // 항상 업데이트 (프로덕션 포함)
615
+ });
616
+ const totalCreated = results.reduce((sum, r) => sum + r.created, 0);
617
+ const totalUpdated = results.reduce((sum, r) => sum + r.updated, 0);
618
+ const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
619
+ if (options.debug || totalCreated > 0 || totalUpdated > 0) {
620
+ syncLogger.info("Label sync completed", {
621
+ sections: results.length,
622
+ created: totalCreated,
623
+ updated: totalUpdated,
624
+ errors: totalErrors
625
+ });
626
+ }
627
+ if (totalErrors > 0) {
628
+ results.forEach((result) => {
629
+ result.errors.forEach((error) => {
630
+ syncLogger.error(`[${result.section}] ${error.key}: ${error.error}`);
631
+ });
632
+ });
633
+ }
634
+ } catch (error) {
635
+ syncLogger.error(
636
+ "Label sync failed",
637
+ error instanceof Error ? error : new Error(String(error))
638
+ );
639
+ }
640
+ }
641
+ async onFileChange(filePath, event) {
642
+ syncLogger.info(`Label file ${event}`, { file: filePath });
643
+ await this.generate({ cwd: process.cwd(), debug: true });
644
+ }
645
+ };
646
+ function createLabelSyncGenerator(config) {
647
+ return new LabelSyncGenerator(config);
648
+ }
649
+
650
+ // src/generators/index.ts
651
+ var generators = {
652
+ "label-sync": createLabelSyncGenerator
653
+ };
654
+ export {
655
+ LabelSyncGenerator,
656
+ createLabelSyncGenerator,
657
+ generators
14
658
  };
15
- /**
16
- * Re-export individual generator factories
17
- */
18
- export { createLabelSyncGenerator, LabelSyncGenerator } from './label-sync-generator.js';
19
659
  //# sourceMappingURL=index.js.map