@things-factory/figure-service 10.1.278 → 10.1.279

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 (149) hide show
  1. package/package.json +23 -8
  2. package/coverage/clover.xml +0 -6
  3. package/coverage/coverage-final.json +0 -1
  4. package/coverage/lcov-report/base.css +0 -224
  5. package/coverage/lcov-report/block-navigation.js +0 -87
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +0 -101
  8. package/coverage/lcov-report/prettify.css +0 -1
  9. package/coverage/lcov-report/prettify.js +0 -2
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +0 -210
  12. package/coverage/lcov.info +0 -0
  13. package/dist-server/index.js.map +0 -1
  14. package/dist-server/migrations/index.js.map +0 -1
  15. package/dist-server/routers/figure-mesh-router.js.map +0 -1
  16. package/dist-server/routers/figure-package-router.js.map +0 -1
  17. package/dist-server/routers/figure-thumbnail-router.js.map +0 -1
  18. package/dist-server/routes.js.map +0 -1
  19. package/dist-server/service/figure/event-subscriber.js.map +0 -1
  20. package/dist-server/service/figure/figure-ai-scenarios-run.js.map +0 -1
  21. package/dist-server/service/figure/figure-ai-scenarios.js.map +0 -1
  22. package/dist-server/service/figure/figure-categories.js.map +0 -1
  23. package/dist-server/service/figure/figure-context.js.map +0 -1
  24. package/dist-server/service/figure/figure-format.js.map +0 -1
  25. package/dist-server/service/figure/figure-glb.js.map +0 -1
  26. package/dist-server/service/figure/figure-history.js.map +0 -1
  27. package/dist-server/service/figure/figure-llm-provider.js.map +0 -1
  28. package/dist-server/service/figure/figure-mesh-store.js.map +0 -1
  29. package/dist-server/service/figure/figure-mutation.js.map +0 -1
  30. package/dist-server/service/figure/figure-namespace-entity.js.map +0 -1
  31. package/dist-server/service/figure/figure-namespace-resolver.js.map +0 -1
  32. package/dist-server/service/figure/figure-namespace.js.map +0 -1
  33. package/dist-server/service/figure/figure-package-export.js.map +0 -1
  34. package/dist-server/service/figure/figure-proposal-record.js.map +0 -1
  35. package/dist-server/service/figure/figure-proposal.js.map +0 -1
  36. package/dist-server/service/figure/figure-propose-steps.js.map +0 -1
  37. package/dist-server/service/figure/figure-propose-type.js.map +0 -1
  38. package/dist-server/service/figure/figure-public.js.map +0 -1
  39. package/dist-server/service/figure/figure-query.js.map +0 -1
  40. package/dist-server/service/figure/figure-rename.js.map +0 -1
  41. package/dist-server/service/figure/figure-replaced-draft.js.map +0 -1
  42. package/dist-server/service/figure/figure-revert.js.map +0 -1
  43. package/dist-server/service/figure/figure-subject.js.map +0 -1
  44. package/dist-server/service/figure/figure-thumbnail-reader.js.map +0 -1
  45. package/dist-server/service/figure/figure-thumbnail-store.js.map +0 -1
  46. package/dist-server/service/figure/figure-thumbnail-upgrade.js.map +0 -1
  47. package/dist-server/service/figure/figure-tools.js.map +0 -1
  48. package/dist-server/service/figure/figure-type.js.map +0 -1
  49. package/dist-server/service/figure/figure-write.js.map +0 -1
  50. package/dist-server/service/figure/figure.js.map +0 -1
  51. package/dist-server/service/figure/index.js.map +0 -1
  52. package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +0 -1
  53. package/dist-server/service/figure-recipe/figure-recipe-templates.js.map +0 -1
  54. package/dist-server/service/figure-recipe/figure-recipe-type.js.map +0 -1
  55. package/dist-server/service/figure-recipe/index.js.map +0 -1
  56. package/dist-server/service/index.js.map +0 -1
  57. package/dist-server/tsconfig.tsbuildinfo +0 -1
  58. package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -15
  59. package/logs/application-2026-09-14-23.log +0 -0
  60. package/logs/figure-ai-scenarios/2026-11-03T09-31-35-151Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1167
  61. package/logs/figure-ai-scenarios/2026-11-03T09-39-05-265Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -904
  62. package/logs/figure-ai-scenarios/2026-11-03T09-41-49-107Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1629
  63. package/logs/figure-ai-scenarios/2026-11-03T09-58-26-681Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4412
  64. package/logs/figure-ai-scenarios/2026-11-03T10-16-46-212Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4513
  65. package/logs/figure-ai-scenarios/2026-11-03T10-21-07-872Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4202
  66. package/logs/figure-ai-scenarios/2026-11-03T10-25-21-721Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1665
  67. package/logs/figure-ai-scenarios/2026-11-09T01-28-51-664Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4484
  68. package/scripts/build-templates.mts +0 -64
  69. package/scripts/figure-ai-scenarios-agent.cjs +0 -98
  70. package/scripts/rename-figures-to-full-names.mjs +0 -211
  71. package/scripts/templates.test.mts +0 -112
  72. package/server/index.ts +0 -46
  73. package/server/migrations/index.ts +0 -9
  74. package/server/routers/figure-mesh-router.ts +0 -63
  75. package/server/routers/figure-package-router.ts +0 -53
  76. package/server/routers/figure-thumbnail-router.ts +0 -159
  77. package/server/routes.ts +0 -30
  78. package/server/service/figure/catalog-db.test.ts +0 -162
  79. package/server/service/figure/event-subscriber.ts +0 -66
  80. package/server/service/figure/figure-ai-scenarios-run.ts +0 -127
  81. package/server/service/figure/figure-ai-scenarios.live.test.ts +0 -59
  82. package/server/service/figure/figure-ai-scenarios.test.ts +0 -109
  83. package/server/service/figure/figure-ai-scenarios.ts +0 -798
  84. package/server/service/figure/figure-blueprint-query.test.ts +0 -536
  85. package/server/service/figure/figure-catalog-seen-db.test.ts +0 -153
  86. package/server/service/figure/figure-categories.ts +0 -50
  87. package/server/service/figure/figure-category-db.test.ts +0 -127
  88. package/server/service/figure/figure-context.test.ts +0 -402
  89. package/server/service/figure/figure-context.ts +0 -510
  90. package/server/service/figure/figure-deprecation-db.test.ts +0 -218
  91. package/server/service/figure/figure-format.test.ts +0 -423
  92. package/server/service/figure/figure-format.ts +0 -783
  93. package/server/service/figure/figure-glb.test.ts +0 -112
  94. package/server/service/figure/figure-glb.ts +0 -251
  95. package/server/service/figure/figure-history.ts +0 -192
  96. package/server/service/figure/figure-inspect-db.test.ts +0 -131
  97. package/server/service/figure/figure-llm-provider.ts +0 -20
  98. package/server/service/figure/figure-llm-smoke.test.ts +0 -95
  99. package/server/service/figure/figure-mesh-db.test.ts +0 -246
  100. package/server/service/figure/figure-mesh-store.ts +0 -91
  101. package/server/service/figure/figure-mutation.ts +0 -656
  102. package/server/service/figure/figure-namespace-db.test.ts +0 -315
  103. package/server/service/figure/figure-namespace-entity.ts +0 -67
  104. package/server/service/figure/figure-namespace-resolver.ts +0 -54
  105. package/server/service/figure/figure-namespace.ts +0 -156
  106. package/server/service/figure/figure-package-export.ts +0 -136
  107. package/server/service/figure/figure-proposal-db.test.ts +0 -117
  108. package/server/service/figure/figure-proposal-record.ts +0 -38
  109. package/server/service/figure/figure-proposal.ts +0 -41
  110. package/server/service/figure/figure-propose-clips.test.ts +0 -69
  111. package/server/service/figure/figure-propose-steps.test.ts +0 -324
  112. package/server/service/figure/figure-propose-steps.ts +0 -354
  113. package/server/service/figure/figure-propose-type.ts +0 -46
  114. package/server/service/figure/figure-public-db.test.ts +0 -288
  115. package/server/service/figure/figure-public.ts +0 -60
  116. package/server/service/figure/figure-query.ts +0 -511
  117. package/server/service/figure/figure-release-check.test.ts +0 -63
  118. package/server/service/figure/figure-release-record-db.test.ts +0 -153
  119. package/server/service/figure/figure-release-size-db.test.ts +0 -156
  120. package/server/service/figure/figure-rename-db.test.ts +0 -237
  121. package/server/service/figure/figure-rename.test.ts +0 -117
  122. package/server/service/figure/figure-rename.ts +0 -143
  123. package/server/service/figure/figure-replaced-draft.ts +0 -99
  124. package/server/service/figure/figure-revert-db.test.ts +0 -163
  125. package/server/service/figure/figure-revert-race.pg.test.ts +0 -168
  126. package/server/service/figure/figure-revert.ts +0 -186
  127. package/server/service/figure/figure-subject.test.ts +0 -41
  128. package/server/service/figure/figure-subject.ts +0 -21
  129. package/server/service/figure/figure-thumbnail-db.test.ts +0 -279
  130. package/server/service/figure/figure-thumbnail-reader.ts +0 -20
  131. package/server/service/figure/figure-thumbnail-store.ts +0 -111
  132. package/server/service/figure/figure-thumbnail-upgrade.pg.test.ts +0 -93
  133. package/server/service/figure/figure-thumbnail-upgrade.ts +0 -70
  134. package/server/service/figure/figure-tool-doors.test.ts +0 -127
  135. package/server/service/figure/figure-tools-door-db.test.ts +0 -227
  136. package/server/service/figure/figure-tools.test.ts +0 -817
  137. package/server/service/figure/figure-tools.ts +0 -611
  138. package/server/service/figure/figure-type.ts +0 -241
  139. package/server/service/figure/figure-write.test.ts +0 -15
  140. package/server/service/figure/figure-write.ts +0 -131
  141. package/server/service/figure/figure.ts +0 -241
  142. package/server/service/figure/index.ts +0 -13
  143. package/server/service/figure-recipe/figure-recipe-resolver.ts +0 -38
  144. package/server/service/figure-recipe/figure-recipe-templates.test.ts +0 -47
  145. package/server/service/figure-recipe/figure-recipe-templates.ts +0 -70
  146. package/server/service/figure-recipe/figure-recipe-type.ts +0 -31
  147. package/server/service/figure-recipe/index.ts +0 -3
  148. package/server/service/index.ts +0 -34
  149. package/tsconfig.json +0 -14
@@ -1,241 +0,0 @@
1
- import { FigureReplacedDraft } from './figure-replaced-draft.js'
2
- import { Field, InputType, Int, ObjectType } from 'type-graphql'
3
- import { GraphQLJSON } from 'graphql-scalars'
4
-
5
- import { Figure } from './figure.js'
6
-
7
- /**
8
- * 새 Figure.
9
- *
10
- * `score`·`triangles`·`groups` 는 **받지 않는다.** 서버가 `source` 에서 계산한다 —
11
- * 받으면 거짓이 들어오고 목록이 실물과 다른 것을 보여 준다.
12
- */
13
- /** The catalogue fields as the editor saw them; an update of them goes on only while the row still holds these. */
14
- @InputType({ description: 'The type, category and tags as the editor saw them. A field left out is not checked; null means it was empty.' })
15
- export class FigureCatalogSeen {
16
- @Field({ nullable: true, description: 'The type the editor saw before changing it.' })
17
- type?: string
18
-
19
- @Field({ nullable: true, description: 'The category the editor saw before changing it; null when it was empty.' })
20
- category?: string
21
-
22
- @Field(type => [String], { nullable: true, description: 'The tags the editor saw before changing them, in their order; null when there were none.' })
23
- tags?: string[]
24
- }
25
-
26
- @InputType({ description: 'Input for creating a new figure.' })
27
- export class NewFigure {
28
- @Field({ description: 'Component type name. Immutable once created, unique per domain.' })
29
- type: string
30
-
31
- @Field({ description: 'Display name shown to authors.' })
32
- name: string
33
-
34
- @Field({ nullable: true, description: 'A detailed description for the figure.' })
35
- description?: string
36
-
37
- @Field({ nullable: true, description: 'Classification code used to group figures in the palette.' })
38
- category?: string
39
-
40
- @Field(type => [String], { nullable: true, description: 'Free-form tags. A figure may carry several.' })
41
- tags?: string[]
42
-
43
- @Field({ description: 'The figure asset JSON (figure-asset-1).' })
44
- source: string
45
-
46
- @Field({ nullable: true, description: 'JSON definition of the master-data fields an instance carries.' })
47
- properties?: string
48
-
49
- @Field({ nullable: true, description: "Lifecycle state — defaults to 'draft'." })
50
- state?: 'draft' | 'released'
51
-
52
- @Field({ nullable: true, description: 'A base64 encoded thumbnail image.' })
53
- thumbnail?: string
54
-
55
- @Field({ nullable: true, description: "The domain's namespace to create it under; the domain's default when none." })
56
- namespace?: string
57
- }
58
-
59
- /**
60
- * 수정.
61
- *
62
- * `type` 은 **한 번도 발행되지 않은 초안에서만** 바뀐다(ADR-0063 결정 4). 저장되는 식별자라
63
- * 발행된 뒤에 바꾸면 이미 배치된 보드가 타입을 못 찾아 오류 없이 빈 화면이 된다. 발행 전에는
64
- * 그 피규어를 가리키는 도면이 있을 수 없다 — 도면은 최신 발행 버전을 그리므로 발행된 적 없는
65
- * 피규어는 그려질 자리가 없다.
66
- *
67
- * 닫아 두었더니 저작자가 이름을 한 번도 정하지 못했다. 새 Figure 에는 기계가 지은 이름이
68
- * 붙고(`FIGURE_MU6RJH47`) 칸에 자물쇠가 걸려서, 그 이름이 그대로 도면에 적히는 이름이 됐다.
69
- */
70
- @InputType({ description: 'Input for updating an existing figure. `type` is accepted only while the figure has never been released.' })
71
- export class FigurePatch {
72
- @Field({ nullable: true, description: 'The stored identifier. Accepted only before the first release; rejected once a version exists.' })
73
- type?: string
74
-
75
- @Field({ nullable: true, description: 'The new display name.' })
76
- name?: string
77
-
78
- @Field({ nullable: true, description: 'The new description.' })
79
- description?: string
80
-
81
- /* 언어별 표시 이름. 안 준 것은 그대로, `{}` 는 전부 지운다. */
82
- @Field(type => GraphQLJSON, { nullable: true, description: 'Display names by language. {} clears them; omitting the field leaves them.' })
83
- names?: Record<string, string>
84
-
85
- @Field({ nullable: true, description: 'The new classification code.' })
86
- category?: string
87
-
88
- /*
89
- 빈 배열과 안 준 것을 가른다. `undefined` 는 「건드리지 않는다」, `[]` 는 「전부 지운다」다.
90
- 둘을 뭉개면 태그를 다 지우려는 저작자가 지울 방법을 잃는다.
91
- */
92
- @Field(type => [String], { nullable: true, description: 'The new tags. An empty list clears them; omitting the field leaves them.' })
93
- tags?: string[]
94
-
95
- @Field({ nullable: true, description: 'The new figure asset JSON (figure-asset-1).' })
96
- source?: string
97
-
98
- @Field({ nullable: true, description: 'The new master-data field definition.' })
99
- properties?: string
100
-
101
- /*
102
- `state` 는 여기 없다 — **상태는 저장이 정하지 않는다.**
103
-
104
- 발행은 `releaseFigure` 가 한다. 저장으로 상태를 바꿀 수 있게 두면 발행된 버전을 덮어쓰면서 같은
105
- 버전 번호로 버전을 또 뜨게 되고(유니크 충돌), 무엇이 약속된 버전인지도 흐려진다. board 도 같다.
106
- */
107
-
108
- @Field({ nullable: true, description: 'A base64 encoded thumbnail image.' })
109
- thumbnail?: string
110
- }
111
-
112
- @ObjectType({ description: 'A paginated list of figures.' })
113
- export class FigureList {
114
- @Field(type => [Figure], { description: 'The figures on this page.' })
115
- items: Figure[]
116
-
117
- @Field(type => Int, { description: 'Total number of figures matching the query.' })
118
- total: number
119
- }
120
-
121
- /**
122
- * 검증 결과 한 줄.
123
- *
124
- * 정본 형식의 검증은 `@hatiolab/figure-model` 이 두 단계로 나눈다 — `errors` 는
125
- * 막고, `violations` 는 알린다. 그 경계를 서버가 다시 정하지 않는다.
126
- */
127
- @ObjectType({ description: 'One validation finding from figure-model.' })
128
- export class FigureFinding {
129
- @Field({ description: 'Stable code from figure-model (ERROR_CODES / VIOLATION_CODES).' })
130
- code: string
131
-
132
- @Field({ description: 'Human-readable message.' })
133
- message: string
134
-
135
- @Field({ nullable: true, description: 'Path within the source that the finding points at.' })
136
- at?: string
137
- }
138
-
139
- /**
140
- * 저장 결과.
141
- *
142
- * `violations` 가 있어도 저장은 된다 — 막는 것과 알리는 것을 가른다. 화면이
143
- * 이것을 그대로 보여 줘야 한다. 조용히 버리면 저작자가 모른다.
144
- */
145
- @ObjectType({ description: 'Result of saving a figure, carrying non-blocking violations.' })
146
- export class FigureSaveResult {
147
- @Field(type => Figure, { description: 'The saved figure.' })
148
- figure: Figure
149
-
150
- @Field(type => [FigureFinding], { description: 'Non-blocking findings. The save succeeded despite these.' })
151
- violations: FigureFinding[]
152
- }
153
-
154
- /** An AI proposal saved into a figure, with the figure's names as they are now (ADR-0097 §5.6 item 5). */
155
- @ObjectType({ description: 'A figure an AI proposal was saved into.' })
156
- export class FigureProposalOutcome {
157
- @Field({ description: 'The figure it was saved into.' })
158
- figureId: string
159
-
160
- @Field({ nullable: true, description: "The figure's type name now." })
161
- type?: string
162
-
163
- @Field({ nullable: true, description: "The figure's display name now." })
164
- name?: string
165
-
166
- @Field({ nullable: true, description: 'When the save that held it was made.' })
167
- recordedAt?: Date
168
- }
169
-
170
- /** A revert's outcome: the figure as it now is, and the draft kept for it (ADR-0097 §5.6). */
171
- @ObjectType({ description: 'The result of a revert, or of an undo of one.' })
172
- export class FigureRevertResult {
173
- @Field(type => Figure, { description: 'The figure, as it now is.' })
174
- figure: Figure
175
-
176
- @Field(type => [FigureFinding], { description: 'Non-blocking findings on the source written.' })
177
- violations: FigureFinding[]
178
-
179
- @Field(type => FigureReplacedDraft, { description: 'The draft kept for this revert -- or, for an undo, the one brought back.' })
180
- kept: FigureReplacedDraft
181
- }
182
-
183
- /**
184
- * 발행 판정 한 줄.
185
- *
186
- * `FigureFinding` 과 칸이 겹치지만 **`blocking` 이 하나 더 있다.** 저장 쪽 발견은 정의상 막지 않는
187
- * 것들이라 그 칸이 필요 없었다. 발행 판정은 막는 것과 알리는 것을 함께 내므로, 어느 쪽인지를 값이
188
- * 스스로 말해야 한다 — 코드를 보고 화면이 다시 분류하면 규칙이 두 벌이 된다.
189
- */
190
- @ObjectType({ description: 'One finding from the release gate.' })
191
- export class FigureGateFinding {
192
- @Field({ description: 'Stable code of the gate finding, for example parts-off-placement-face or parts-split-on-resize.' })
193
- code: string
194
-
195
- @Field({ description: 'Human-readable message.' })
196
- message: string
197
-
198
- @Field({ nullable: true, description: 'Why this is a problem — what a person sees when it happens.' })
199
- why?: string
200
-
201
- @Field({ nullable: true, description: 'What to change, naming the part and the value.' })
202
- how?: string
203
-
204
- @Field({ nullable: true, description: 'Where it points: part names that came apart, or a path in the source.' })
205
- at?: string
206
-
207
- @Field({ description: 'True when this finding blocks the release.' })
208
- blocking: boolean
209
-
210
- @Field({
211
- nullable: true,
212
- description:
213
- 'True when the change breaks the released contract: saved as a new figure type, the edits release and the placed figures keep the old one.'
214
- })
215
- asNewType?: boolean
216
- }
217
-
218
- /**
219
- * 발행 판정.
220
- *
221
- * 화면이 **발행을 누르기 전에** 물어보는 자리다. 눌러 보고 거절당하는 것으로 알게 되면, 무엇을
222
- * 고쳐야 하는지 모른 채 단추만 두드리게 된다.
223
- */
224
- @ObjectType({ description: 'Whether a figure may be released, and why not.' })
225
- export class FigureInspection {
226
- @Field({ description: 'True when at least one finding blocks the release.' })
227
- blocked: boolean
228
-
229
- @Field(type => [FigureGateFinding], { description: 'Findings, blocking and advisory together.' })
230
- findings: FigureGateFinding[]
231
- }
232
-
233
- /** A GLB kept for mesh parts (ADR-0129): its hash, and what it holds as the upload read it. */
234
- @ObjectType({ description: 'A GLB kept for mesh parts: its hash and what it holds.' })
235
- export class FigureMeshUpload {
236
- @Field({ description: "The file's SHA-256, lower-case hex: what a mesh part names it by." })
237
- hash: string
238
-
239
- @Field(type => GraphQLJSON, { description: 'Bounds in mm, triangles, primitives and nodes, as read from the file.' })
240
- summary: unknown
241
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * A stale expected source is refused with a code of its own (FIGURE_SOURCE_CONFLICT), so the modeller can tell it from a
3
- * refusal on grounds and read the row back before saying its save failed (D, designer 2026-09-27).
4
- */
5
- import { compareAndSwapFigure, prepareFigureWrite } from './figure-write'
6
-
7
- describe('a write whose expected source is not the row', () => {
8
- it('is refused as a source conflict, by code', async () => {
9
- await expect(compareAndSwapFigure(async () => ({ affected: 0 }), 'id', 'domain', 'old')).rejects.toMatchObject({ extensions: { code: 'FIGURE_SOURCE_CONFLICT' } })
10
- expect(() => prepareFigureWrite('{}', { source: 'theirs' }, 'mine')).toThrow(expect.objectContaining({ extensions: { code: 'FIGURE_SOURCE_CONFLICT' } }))
11
- })
12
- it('passes when the row is what was expected', async () => {
13
- await expect(compareAndSwapFigure(async () => ({ affected: 1 }), 'id', 'domain', 'same')).resolves.toBeUndefined()
14
- })
15
- })
@@ -1,131 +0,0 @@
1
- import { keepThumbnail, type ThumbnailFiles } from './figure-thumbnail-store.js'
2
- import { GraphQLError } from 'graphql'
3
- import { IsNull, Raw } from 'typeorm'
4
- import { parseFigureAsset, serializeFigureAsset, compileFigureAsset, figureCostOf, figureScoreOf } from '@hatiolab/figure-model'
5
-
6
- /**
7
- * The row is not what the writer expected: another edit, or the writer's own earlier save whose answer it never got.
8
- * Coded, so a client can tell it from a refusal on grounds (permission, validation) and read the row back before
9
- * saying its save failed (D, designer 2026-09-27).
10
- */
11
- export function sourceConflict(message: string) {
12
- return new GraphQLError(message, { extensions: { code: 'FIGURE_SOURCE_CONFLICT' } })
13
- }
14
-
15
- /**
16
- * The catalogue fields as the editor saw them when it changed them: the type, the category, the tags. Kept on the row,
17
- * not in the source, so the source's compare-and-swap does not hold them; a save of these alone is checked against
18
- * these (outside review 2026-11-09: two tabs set the category, the later one wrote over the first without a word).
19
- * A field left out is not checked; null is "was empty".
20
- */
21
- export interface FigureCatalogSeen {
22
- type?: string | null
23
- category?: string | null
24
- tags?: string[] | null
25
- }
26
-
27
- export const CATALOG_FIELDS = ['type', 'category', 'tags'] as const
28
- type CatalogField = (typeof CATALOG_FIELDS)[number]
29
-
30
- /** A catalogue value as compared: an empty category or tag list is no value; tags as the row stores them (simple-json). */
31
- function comparedCatalogValue(field: CatalogField, value: unknown): string | null {
32
- if (field === 'tags') return Array.isArray(value) && value.length ? JSON.stringify(value) : null
33
- return typeof value === 'string' && value ? value : null
34
- }
35
-
36
- /** The fields the row no longer holds as the editor saw them, each with what it holds now. */
37
- export function catalogConflictsOf(row: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen): { field: CatalogField; now: string | string[] | null }[] {
38
- return CATALOG_FIELDS.filter(field => seen[field] !== undefined && comparedCatalogValue(field, row[field]) !== comparedCatalogValue(field, seen[field])).map(field => ({
39
- field,
40
- now: field === 'tags' ? ((row.tags as string[] | null | undefined)?.length ? (row.tags as string[]) : null) : ((row[field] as string | null | undefined) || null)
41
- }))
42
- }
43
-
44
- /** The same check in the UPDATE's criteria: a write between the check and the update finds nothing to update. */
45
- export function catalogCriteriaOf(seen: FigureCatalogSeen): Record<string, unknown> {
46
- const criteria: Record<string, unknown> = {}
47
- for (const field of CATALOG_FIELDS) {
48
- if (seen[field] === undefined) continue
49
- const value = comparedCatalogValue(field, seen[field])
50
- if (value !== null) criteria[field] = field === 'tags' ? Raw(column => `${column} = :seenTags`, { seenTags: value }) : value
51
- else if (field === 'type') criteria[field] = IsNull()
52
- else criteria[field] = Raw(column => `(${column} IS NULL OR ${column} = '${field === 'tags' ? '[]' : ''}')`)
53
- }
54
- return criteria
55
- }
56
-
57
- /**
58
- * A patch that changes a catalogue field says what it saw of that field: there is no unchecked way to write one
59
- * (outside review 2026-11-09). A field the patch leaves out is neither written nor checked.
60
- */
61
- export function assertCatalogSeen(patch: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen | undefined) {
62
- const unseen = CATALOG_FIELDS.filter(field => patch[field] !== undefined && seen?.[field] === undefined)
63
- if (unseen.length)
64
- throw new GraphQLError(`변경할 항목의 기존 값이 필요합니다: ${unseen.join(', ')}`, { extensions: { code: 'FIGURE_CATALOG_SEEN_REQUIRED', fields: unseen } })
65
- }
66
-
67
- /** Another edit changed a catalogue field first: which, and what it holds now, for the editor to say in its words. */
68
- export function catalogConflict(fields: { field: string; now: string | string[] | null }[]) {
69
- return new GraphQLError(`다른 사용자가 먼저 변경한 항목이 있습니다: ${fields.map(f => f.field).join(', ')}`, {
70
- extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields }
71
- })
72
- }
73
-
74
- export interface FigureWriteCriteria {
75
- id: string
76
- domain: { id: string }
77
- source: string
78
- }
79
- export async function compareAndSwapFigure(
80
- update: (criteria: FigureWriteCriteria) => Promise<{ affected?: number | null }>,
81
- id: string,
82
- domainId: string,
83
- expectedSource: string | undefined
84
- ) {
85
- if (expectedSource === undefined) throw Error('수정 전 정본이 필요합니다.')
86
- const result = await update({ id, domain: { id: domainId }, source: expectedSource })
87
- if (result.affected !== 1) throw sourceConflict('다른 편집에서 모델이 변경되었습니다. 최신 모델을 다시 열어 주세요.')
88
- }
89
-
90
- /** Early validation only. The repository must also compare expectedSource in its atomic UPDATE. */
91
- export function prepareFigureWrite(source: string, existing?: { source?: string }, expectedSource?: string) {
92
- if (existing && (expectedSource === undefined || existing.source !== expectedSource)) {
93
- throw sourceConflict('다른 편집에서 모델이 변경되었습니다. 최신 모델을 다시 연 뒤 적용해 주세요.')
94
- }
95
- const asset = parseFigureAsset(source)
96
- compileFigureAsset(asset)
97
- /*
98
- The same measure `parseSource` uses, so the catalogue's columns do not depend on which mutation wrote the row.
99
- */
100
- const cost = figureCostOf(asset)
101
- return {
102
- source: serializeFigureAsset(asset),
103
- name: asset.name,
104
- score: figureScoreOf(asset)?.score ?? null,
105
- triangles: cost.triangles,
106
- groups: cost.groups,
107
- state: 'draft' as const
108
- }
109
- }
110
-
111
- /**
112
- * The picture a card shows, when the modeller sent one: kept by its content (`keepThumbnail`) and named on the row by
113
- * its hash.
114
- *
115
- * Absent means the author saved without one — a tab in the background cannot draw, and the source matters more
116
- * than the picture, so the save goes on and the modeller fills it in next time. The timestamp moves only when
117
- * the picture itself is new, so renaming a figure does not make every card look freshly drawn.
118
- */
119
- export async function pictureOf(
120
- tx: { getRepository: (target: any) => any },
121
- domain: { id: string },
122
- user: unknown,
123
- thumbnail?: string,
124
- existing?: { thumbnailHash?: string | null },
125
- files?: ThumbnailFiles
126
- ): Promise<{ thumbnailHash?: string; thumbnail?: null; thumbnailUpdatedAt?: Date }> {
127
- if (thumbnail === undefined) return {}
128
- const thumbnailHash = await keepThumbnail(tx, domain, user, thumbnail, files)
129
- if (thumbnailHash === existing?.thumbnailHash) return {}
130
- return { thumbnailHash, thumbnail: null, thumbnailUpdatedAt: new Date() }
131
- }
@@ -1,241 +0,0 @@
1
- import {
2
- Column,
3
- CreateDateColumn,
4
- DeleteDateColumn,
5
- Entity,
6
- Index,
7
- ManyToOne,
8
- PrimaryGeneratedColumn,
9
- RelationId,
10
- UpdateDateColumn
11
- } from 'typeorm'
12
- import { Field, Float, ID, Int, ObjectType } from 'type-graphql'
13
- import { GraphQLJSON } from 'graphql-scalars'
14
-
15
- import { User } from '@things-factory/auth-base'
16
- import { Domain, longTextColumn } from '@things-factory/shell'
17
-
18
- /**
19
- * Figure — 저작된 3D 컴포넌트 한 종류.
20
- *
21
- * `Board` 를 준용한다. 다른 점만 주석으로 적는다.
22
- *
23
- * ## 무엇을 담나 — 피규어 자산이다, 씬 모델이 아니다
24
- *
25
- * 형식은 `@hatiolab/figure-model` 이 정한다(`figure-asset-1`). 씬 컴포넌트 트리를 담지 않는다.
26
- * 컴파일한 것도 저장하지 않는다 — 원본에서 파생되므로 소비하는 쪽이 커널로 컴파일한다. 저장하면 원본과 갈린다.
27
- *
28
- * 그래서 부품·움직임·자리 같은 것을 컬럼으로 두지 않는다 — 전부 `source` 안에 이미 있다. 두 벌이면 갈린다.
29
- *
30
- * 설계: `docs/design/figure-modules.md` §2
31
- */
32
- @Entity()
33
- @Index('ix_figure_1', (figure: Figure) => [figure.domain, figure.type], {
34
- unique: true,
35
- where: '"deleted_at" IS NULL'
36
- })
37
- @Index('ix_figure_2', (figure: Figure) => [figure.domain, figure.category])
38
- @ObjectType({ description: 'An authored 3D component type — its figure asset plus its metadata.' })
39
- export class Figure {
40
- @PrimaryGeneratedColumn('uuid')
41
- @Field(type => ID, { nullable: true, description: 'Unique identifier for the figure.' })
42
- readonly id?: string
43
-
44
- /**
45
- * 발행된 버전의 번호 — **발행할 때만 올라간다.**
46
- *
47
- * 저장 횟수가 아니다. 저작 중에는 몇 번을 고쳐 저장하든 그대로이고, `draft` 가 `released` 가
48
- * 되는 순간에만 하나 오른다. 소비처가 「몇 번째 버전을 쓰고 있나」를 이 값으로 말한다.
49
- *
50
- * 한 번도 발행되지 않았으면 **0** 이다. 1 로 시작하면 아직 아무에게도 약속하지 않은 초안이
51
- * 첫 버전인 것처럼 보인다.
52
- */
53
- @Column({ nullable: true, default: 0 })
54
- @Field(type => Int, {
55
- nullable: true,
56
- description: 'Published version. Raised when the figure is released, not when it is saved. 0 means never released.'
57
- })
58
- version?: number = 0
59
-
60
- @ManyToOne(type => Domain)
61
- @Field(type => Domain, { nullable: true, description: 'The domain this figure belongs to.' })
62
- domain?: Domain
63
-
64
- @RelationId((figure: Figure) => figure.domain)
65
- domainId?: string
66
-
67
- /**
68
- * 컴포넌트 타입 이름. **저장되는 식별자다.**
69
- *
70
- * 배치된 도면이 이 이름으로 타입을 찾는다. 바꾸면 그 도면은 타입을 못 찾아
71
- * **오류 없이 빈 화면**이 된다. 그래서 만들 때 정하고 잠근다 — 고칠 수 있는 것은
72
- * 표시 이름(`name`)뿐이다. 수정 리졸버가 이 필드를 받지 않는다.
73
- *
74
- * `Board.type`(main/sub/popup)과 뜻이 전혀 다르다. 혼동하지 않는다.
75
- */
76
- @Column()
77
- @Field({ description: 'Component type name. A stored identifier — unique per domain and immutable once created.' })
78
- type?: string
79
-
80
- /**
81
- * The namespace the figure is published under, copied from the domain setting `figure-namespace` when the figure is
82
- * made. With the type it forms the full name `{namespace}/{type}` boards store (ADR-0114). Never changes.
83
- */
84
- @Column({ nullable: true })
85
- @Field({ nullable: true, description: 'Namespace of the full name {namespace}/{type}. Copied from the domain setting when created; never changes.' })
86
- namespace?: string
87
-
88
- @Column()
89
- @Field({ description: 'Display name shown to authors. Safe to rename.' })
90
- name?: string
91
-
92
- @Column({ nullable: true })
93
- @Field({ nullable: true, description: 'A detailed description for the figure.' })
94
- description?: string
95
-
96
- /*
97
- 언어별 표시 이름(ADR-0104 결정 6). 없는 언어는 `name` 을 보인다. 식별자는 여전히 `type` 이다 — 이름은 몇 번을
98
- 바꿔도 도면이 가리키는 것이 달라지지 않는다.
99
- */
100
- @Column('simple-json', { nullable: true, default: null })
101
- @Field(type => GraphQLJSON, { nullable: true, description: 'Display names by language, e.g. { "en": "...", "ko": "..." }. A language not here shows `name`.' })
102
- names?: Record<string, string>
103
-
104
- /*
105
- 퇴역(ADR-0104 결정 6). 표시일 뿐이다 — 발행 버전은 지우지 않고 받는 쪽은 그대로 받는다. 무엇으로 대신하라는지는
106
- `supersededBy`(그 도메인의 type)가 말한다. 퇴역은 저장이 아니라 `setFigureDeprecation` 이 정하고, 발행을 풀지 않는다.
107
- */
108
- @Column({ nullable: true, default: false })
109
- @Field({ nullable: true, description: 'Retired: still released and still served, but not to be chosen for new work.' })
110
- deprecated?: boolean
111
-
112
- @Column({ nullable: true })
113
- @Field({ nullable: true, description: 'The type to use instead of a retired figure.' })
114
- supersededBy?: string
115
-
116
- /*
117
- 공개(LV figure-server design G2). 다른 도메인도 이 figure 의 **발행본**을 읽고 패키지에 담고 도면에서 정식 이름으로
118
- 부른다. 초안은 소유 도메인만 본다. 고치고 발행하는 것은 소유 도메인뿐이다(G3). `setFigurePublic` 이 정한다.
119
- */
120
- @Column({ nullable: true, default: false })
121
- @Field({ nullable: true, description: 'Public: other domains read its releases, put them in packages and draw them by full name. Only its domain changes it.' })
122
- public?: boolean
123
-
124
- /**
125
- * 분류 하나. **팔레트에서 묶어 보이는 기준이다.**
126
- *
127
- * 피규어 하나에 하나뿐이다 — 팔레트는 목록을 한 벌로 나눠 보여 주므로, 한 피규어가 두 묶음에
128
- * 동시에 있으면 저작자가 같은 것을 두 번 만난다.
129
- */
130
- @Column({ nullable: true })
131
- @Field({ nullable: true, description: 'Classification code used to group figures in the palette. One per figure.' })
132
- category?: string
133
-
134
- /**
135
- * 태그. **여럿 붙는다.**
136
- *
137
- * 분류와 다른 일을 한다. 분류는 「이것이 무엇인가」를 한 번 정하는 것이고, 태그는 「어디에
138
- * 걸리는가」를 여러 갈래로 적는 것이다 — 컨베이어이면서 반출 구역의 것일 수 있다. 그래서
139
- * 분류로는 못 하는 찾기가 된다.
140
- *
141
- * `simple-json` 으로 담는다. 사내 선례가 그것이고(`ops-master` · `organization` ·
142
- * `personalization`), 드라이버마다 배열 타입이 다른 것을 피한다.
143
- */
144
- /* `simple-json` 과 `default: null` 은 사내 선례 그대로다 — board-template · attachment 가 같은 모양이다. */
145
- @Column('simple-json', { nullable: true, default: null })
146
- @Field(type => [String], { nullable: true, description: 'Free-form tags. A figure may carry several.' })
147
- tags?: string[]
148
-
149
- @Column({ nullable: true, default: 'draft' })
150
- @Field({ nullable: true, description: "Lifecycle state — 'draft' figures do not appear in the board palette." })
151
- state?: 'draft' | 'released'
152
-
153
- /**
154
- * The figure asset JSON (`figure-asset-1`).
155
- *
156
- * `Board.model` 자리이지만 이름을 바꿨다 — 「씬 모델이 아니다」를 필드 이름이
157
- * 드러내야 한다.
158
- */
159
- @Column({ nullable: true, ...longTextColumn() })
160
- @Field({ nullable: true, description: 'The figure asset JSON (figure-asset-1) authored by the modeller.' })
161
- source?: string
162
-
163
- // ── 파생값 — 저장하는 이유가 하나뿐이다 ──────────────────────────────────
164
- //
165
- // 셋 다 `source` 에서 계산된다. 그런데도 컬럼으로 두는 이유는 **목록 화면이
166
- // 정렬·필터를 해야** 하기 때문이다. JSON 을 파싱해 정렬할 수는 없다.
167
- //
168
- // 저장할 때 `figure-model` 로 계산해 채운다. **클라이언트가 준 값을 받지 않는다** —
169
- // 받으면 거짓이 들어오고, 목록이 실물과 다른 것을 보여 준다.
170
-
171
- /** 재활용 점수 0~100. `scoreOf()` 가 계산한다. */
172
- @Column({ type: 'float', nullable: true })
173
- @Field(type => Float, { nullable: true, description: 'Reuse score 0-100, computed from source on save.' })
174
- score?: number
175
-
176
- /** 삼각형 수. `costOf()` 가 계산한다. */
177
- @Column({ nullable: true })
178
- @Field(type => Int, { nullable: true, description: 'Triangle count, computed from source on save.' })
179
- triangles?: number
180
-
181
- /** 재질 묶음 수 — 인스턴스당 draw call 의 근거. */
182
- @Column({ nullable: true })
183
- @Field(type => Int, { nullable: true, description: 'Material group count — the basis of per-instance draw calls.' })
184
- groups?: number
185
-
186
- /** 기준정보 항목 정의. Figure 를 배치할 때 인스턴스가 채우는 자리. */
187
- @Column({ nullable: true, ...longTextColumn() })
188
- @Field({ nullable: true, description: 'JSON definition of the master-data fields an instance of this figure carries.' })
189
- properties?: string
190
-
191
- @Column({ nullable: true, ...longTextColumn() })
192
- @Field({ nullable: true, description: 'A base64 encoded thumbnail image of the figure.' })
193
- thumbnail?: string
194
-
195
- /*
196
- * 그림의 내용 해시(SHA-256). 그림 자체는 attachment-base 가 갖고(refType `figure-thumbnail`, refBy 이 해시),
197
- * `/figure-thumbnail/:id` 가 권한을 본 뒤 내준다(ADR-0104 결정 6). `thumbnail` 칸은 옛 base64 가 남은 행을
198
- * 기동 때 옮기기 위한 칸이다 — 옮긴 뒤에는 비어 있고, 새 그림은 그 칸에 쓰지 않는다.
199
- */
200
- @Column({ nullable: true })
201
- @Field({ nullable: true, description: 'SHA-256 of the thumbnail picture; the picture is served by /figure-thumbnail/:id.' })
202
- thumbnailHash?: string
203
-
204
- /**
205
- * 썸네일이 **썸네일로서** 마지막으로 갱신된 시각. `updatedAt` 과는 별개 도메인이다 —
206
- * 이름·설명만 고쳤을 때는 갱신되지 않는다. `Board` 와 같은 방식.
207
- */
208
- @Column({ nullable: true })
209
- @Field({ nullable: true, description: 'Timestamp of the last thumbnail generation. Separate lifecycle from updatedAt.' })
210
- thumbnailUpdatedAt?: Date
211
-
212
- @Column({ type: 'float', nullable: true, default: 0 })
213
- @Field(type => Float, { nullable: true, description: 'Sort order within a listing.' })
214
- sortOrder?: number
215
-
216
- @CreateDateColumn()
217
- @Field({ nullable: true, description: 'Creation timestamp.' })
218
- createdAt?: Date
219
-
220
- @UpdateDateColumn()
221
- @Field({ nullable: true, description: 'Last update timestamp.' })
222
- updatedAt?: Date
223
-
224
- @DeleteDateColumn()
225
- @Field({ nullable: true, description: 'Soft-delete timestamp.' })
226
- deletedAt?: Date
227
-
228
- @ManyToOne(type => User, { nullable: true })
229
- @Field(type => User, { nullable: true, description: 'The user who created this figure.' })
230
- creator?: User
231
-
232
- @RelationId((figure: Figure) => figure.creator)
233
- creatorId?: string
234
-
235
- @ManyToOne(type => User, { nullable: true })
236
- @Field(type => User, { nullable: true, description: 'The user who last updated this figure.' })
237
- updater?: User
238
-
239
- @RelationId((figure: Figure) => figure.updater)
240
- updaterId?: string
241
- }
@@ -1,13 +0,0 @@
1
- import { Figure } from './figure.js'
2
- import { FigureHistory } from './figure-history.js'
3
- import { FigureReplacedDraft } from './figure-replaced-draft.js'
4
- import { FigureProposalRecord } from './figure-proposal-record.js'
5
- import { FigureNamespace } from './figure-namespace-entity.js'
6
- import { FigureQuery } from './figure-query.js'
7
- import { FigureMutation } from './figure-mutation.js'
8
- import { FigureNamespaceResolver } from './figure-namespace-resolver.js'
9
- import { FigureHistoryEntitySubscriber } from './event-subscriber.js'
10
-
11
- export const entities = [Figure, FigureHistory, FigureReplacedDraft, FigureProposalRecord, FigureNamespace]
12
- export const resolvers = [FigureQuery, FigureMutation, FigureNamespaceResolver]
13
- export const subscribers = [FigureHistoryEntitySubscriber]