@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,511 +0,0 @@
1
- import { In } from 'typeorm'
2
- import { Args, Arg, Ctx, Directive, Int, Query, Resolver, UseMiddleware } from 'type-graphql'
3
- import { GraphQLJSON } from 'graphql-scalars'
4
-
5
- import {
6
- countListByField,
7
- Domain,
8
- getQueryBuilderFromListParams,
9
- getRepository,
10
- ListParam,
11
- ListValueCount,
12
- Refusal,
13
- SpeakRefusals,
14
- refusalKey
15
- } from '@things-factory/shell'
16
- import { formatFigureRef, parseFigureName, type FigureName } from '@hatiolab/figure-model'
17
-
18
- import { Figure } from './figure.js'
19
- import { FigureHistory } from './figure-history.js'
20
- import { consumablePayloadOf, inspectSource } from './figure-format.js'
21
- import { FigureInspection, FigureList, FigureProposalOutcome } from './figure-type.js'
22
- import { FigureReplacedDraft } from './figure-replaced-draft.js'
23
- import { replacedDraftsOf } from './figure-revert.js'
24
- import { proposalOutcomeOf } from './figure-proposal.js'
25
- import { meshSummaryOf } from './figure-mesh-store.js'
26
- import { readableFigure, publicFigureOfName } from './figure-public.js'
27
- import { figureCategories } from './figure-categories.js'
28
-
29
- /** What a figure list finds figures by - tags too, see `figures` - and its state counts alike. */
30
- const FIGURE_SEARCHABLES = ['type', 'name', 'description', 'category', 'tags']
31
- /** A release records no tags (`FigureHistory`). */
32
- const PUBLIC_FIGURE_SEARCHABLES = ['type', 'name', 'description', 'category']
33
-
34
- @Resolver(Figure)
35
- @UseMiddleware(SpeakRefusals)
36
- export class FigureQuery {
37
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
38
- @Query(returns => Figure, { nullable: true, description: 'Finds a single figure by its ID.' })
39
- async figure(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Figure> {
40
- const { domain } = context.state
41
-
42
- // 부모 도메인의 Figure 도 보인다 — Board 와 같은 범위 규칙이다.
43
- return await getRepository(Figure).findOne({
44
- where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id }
45
- })
46
- }
47
-
48
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
49
- @Query(returns => FigureList, { description: 'Lists figures. Sortable by score, triangles, name, updatedAt.' })
50
- async figures(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<FigureList> {
51
- const { domain } = context.state
52
-
53
- const queryBuilder = getQueryBuilderFromListParams({
54
- repository: getRepository(Figure),
55
- params,
56
- domain,
57
- alias: 'figure',
58
- /*
59
- `tags` 도 찾을 수 있어야 한다 — 태그의 값은 붙이는 데 있지 않고 **찾는 데** 있다.
60
-
61
- `simple-json` 이라 칸에는 `["반출","자동"]` 이 통째로 들어 있고, LIKE 는 그 글자를
62
- 본다. 「반출」로 찾으면 걸린다. 정확히 그 태그만 걸리는 것은 아니지만(이름에 「반출」이
63
- 든 피규어도 걸린다) 찾기로는 그것이 오히려 낫다.
64
- */
65
- searchables: FIGURE_SEARCHABLES
66
- })
67
-
68
- const [items, total] = await queryBuilder.getManyAndCount()
69
-
70
- return { items, total }
71
- }
72
-
73
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
74
- @Query(returns => [ListValueCount], { description: "How many of the domain's figures hold each state (draft, released), under the list conditions other than the state." })
75
- async figureStateCounts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ListValueCount[]> {
76
- const counted = await countListByField({
77
- repository: getRepository(Figure),
78
- params,
79
- domain: context.state.domain,
80
- alias: 'figure',
81
- searchables: FIGURE_SEARCHABLES,
82
- field: 'state'
83
- })
84
- return ['draft', 'released'].map(value => ({ value, count: counted.get(value) ?? 0 }))
85
- }
86
-
87
- /**
88
- * Other domains' public figures (LV figure-server design G2): what this domain may read, package and draw besides its
89
- * own and its parent's. The rows carry their domain, so a screen says whose each is.
90
- *
91
- * **Each is its latest release, never its row** (2026-11-03 audit 1). A public figure edited after its release has a
92
- * draft on its row -- its source, name, description, category and picture -- and listing the row gave that draft to
93
- * every domain that asked for `source`. So the list is read from the releases, and searched by them too: a search
94
- * on the row's name would tell another domain what the draft is called. Of the row only what its domain says of the
95
- * figure as a whole is shown: that it is public and whether it is retired. Tags are not recorded with a release, so a
96
- * public figure shows none.
97
- */
98
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
99
- @Query(returns => FigureList, { description: "Other domains' public figures, each as its latest release. Read only: their releases, never their drafts." })
100
- async publicFigures(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<FigureList> {
101
- const { domain } = context.state
102
- const mine = [domain.id, domain.parentId].filter(Boolean)
103
- const queryBuilder = getQueryBuilderFromListParams({
104
- repository: getRepository(FigureHistory),
105
- params,
106
- alias: 'figure',
107
- searchables: PUBLIC_FIGURE_SEARCHABLES
108
- })
109
- .innerJoinAndMapOne('figure.row', Figure, 'row', 'row.id = figure.originalId AND row.public = :public AND row.deletedAt IS NULL', { public: true })
110
- .leftJoinAndSelect('figure.domain', 'owner')
111
- .leftJoinAndSelect('figure.updater', 'releaser')
112
- .andWhere('owner.id NOT IN (:...mine)', { mine })
113
- .andWhere(query => {
114
- const latest = query.subQuery().select('MAX(latest.version)').from(FigureHistory, 'latest').where('latest.originalId = figure.originalId').getQuery()
115
- return `figure.version = ${latest}`
116
- })
117
- const [releases, total] = await queryBuilder.getManyAndCount()
118
- const items = releases.map(({ row, ...release }: FigureHistory & { row: Figure }) => ({
119
- ...release,
120
- id: release.originalId,
121
- state: 'released' as const,
122
- public: true,
123
- deprecated: row.deprecated,
124
- supersededBy: row.supersededBy,
125
- tags: [],
126
- /* The card asks for its picture by this stamp; the picture served to another domain is the release's. */
127
- thumbnailUpdatedAt: release.thumbnailHash ? release.updatedAt : null
128
- })) as unknown as Figure[]
129
- return { items, total }
130
- }
131
-
132
- /**
133
- * 등록된 타입 이름 목록.
134
- *
135
- * 저작 화면이 **새 타입 이름이 이미 쓰이는지** 물어보는 데 쓴다. `type` 은 저장되는
136
- * 식별자라 만든 뒤에 고칠 수 없으므로, 만들기 전에 알려 줘야 한다.
137
- *
138
- * `state` 로 걸러지지 않는다 — `draft` 인 Figure 의 이름도 이미 점유된 것이다.
139
- */
140
- /**
141
- * 발행된 버전들 — 최근 것부터.
142
- *
143
- * 저작 중 저장은 여기 없다. 버전은 발행에서만 생기므로(`releaseFigure`), 이 목록이 곧
144
- * 「이 피규어가 몇 번 약속되었나」다.
145
- */
146
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
147
- @Query(returns => [FigureHistory], { description: 'Released versions of a figure, newest first.' })
148
- async figureVersions(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureHistory[]> {
149
- const { domain } = context.state
150
-
151
- /* Its own, its parent's, or another domain's public figure (G2): releases are what a public figure shows. */
152
- if (!(await readableFigure(domain, id, { id: true, public: true, domain: { id: true } }))) return []
153
- return await getRepository(FigureHistory).find({
154
- where: { originalId: id },
155
- relations: ['updater'],
156
- order: { version: 'DESC' },
157
- take: 10
158
- })
159
- }
160
-
161
- /**
162
- * 지금 소비처가 쓰는 버전.
163
- *
164
- * 피규어의 현재 정본은 저작 중일 수 있다(초안). 배치된 것이 보는 것은 **마지막으로 발행된 버전**이고,
165
- * 그것을 이 자리가 답한다.
166
- */
167
- /** What a kept GLB holds, read again from its bytes (ADR-0129): the modeller asks when it reopens a figure. */
168
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
169
- @Query(returns => GraphQLJSON, { nullable: true, description: 'What a kept GLB holds, by its hash: bounds in mm, triangles, primitives and nodes. None when this domain does not hold it.' })
170
- async figureMeshSummary(@Arg('hash') hash: string, @Ctx() context: ResolverContext): Promise<unknown> {
171
- const { domain, tx } = context.state
172
- return (await meshSummaryOf(getRepository(Figure, tx).manager, domain, hash)) ?? null
173
- }
174
-
175
- /** What became of an AI proposal: the figures a save put it into (ADR-0097 §5.6 item 5). */
176
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
177
- @Query(returns => [FigureProposalOutcome], {
178
- description: 'The figures an AI proposal was saved into, oldest first. None: it was not saved, or not in this domain.'
179
- })
180
- async figureProposalOutcome(@Arg('proposalKey') proposalKey: string, @Ctx() context: ResolverContext): Promise<FigureProposalOutcome[]> {
181
- const { domain, tx } = context.state
182
- return await proposalOutcomeOf(getRepository(Figure, tx).manager, domain, proposalKey)
183
- }
184
-
185
- /** The drafts reverts kept for a figure, newest first -- apart from its released versions (ADR-0097 §5.6). */
186
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
187
- @Query(returns => [FigureReplacedDraft], { description: 'Drafts kept when a revert wrote over them, newest first. Not released versions.' })
188
- async figureReplacedDrafts(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureReplacedDraft[]> {
189
- const { domain, tx } = context.state
190
- return await replacedDraftsOf(getRepository(FigureReplacedDraft, tx).manager, domain, id)
191
- }
192
-
193
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
194
- @Query(returns => FigureHistory, { nullable: true, description: 'The most recently released version of a figure.' })
195
- async figureReleased(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureHistory> {
196
- const { domain } = context.state
197
-
198
- if (!(await readableFigure(domain, id, { id: true, public: true, domain: { id: true } }))) return null
199
- return await getRepository(FigureHistory).findOne({
200
- where: { originalId: id },
201
- order: { version: 'DESC' }
202
- })
203
- }
204
-
205
- /**
206
- * 발행해도 되나 — **누르기 전에** 묻는 자리.
207
- *
208
- * 판정은 `figure-gate.ts` 가 하고 이 자리는 정본을 꺼내 넘긴다. 같은 판정을 `releaseFigure` 도
209
- * 부른다 — 화면이 물어 보고 통과했더라도 그 사이에 정본이 바뀌었을 수 있으므로, 막는 것은 언제나
210
- * 뮤테이션이다. 이 질의는 **이유를 미리 보여 주기 위한 것**이고 허가증이 아니다.
211
- */
212
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
213
- @Query(returns => FigureInspection, { description: 'Whether a figure may be released, with the reasons.' })
214
- async inspectFigure(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureInspection> {
215
- const { domain } = context.state
216
-
217
- const figure = await getRepository(Figure).findOne({
218
- where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id },
219
- /*
220
- `type` is read too. A asset carries no type, so the temporary-type refusal reads the row's; with only
221
- id and source selected it saw `undefined`, the panel enabled 「발행하기」, and the release mutation — which
222
- loads the whole row — refused on the press (2026-09-24). `category` likewise: an app's check by category saw
223
- `undefined` here and the whole row's on the release (2026-11-03 audit 3).
224
- */
225
- select: { id: true, source: true, type: true, category: true }
226
- })
227
-
228
- if (!figure) {
229
- throw new Error(`Figure ${id} 를 찾을 수 없다`)
230
- }
231
-
232
- /*
233
- **화면이 발행 문과 같은 것을 본다.** 직전 발행 버전을 여기서도 함께 넘기지 않으면, 저작 화면은
234
- 조용한데 발행을 누른 순간 계약 위반으로 막힌다 — 그때는 이미 열 군데를 고친 뒤다.
235
- */
236
- const released = await getRepository(FigureHistory)
237
- .createQueryBuilder('history')
238
- .where('history.originalId = :id', { id })
239
- .orderBy('history.version', 'DESC')
240
- .limit(1)
241
- .getOne()
242
-
243
- return inspectSource(figure.source, released?.source, context.t, figure.type, figure.category)
244
- }
245
-
246
- /**
247
- * The same judgement for a source that has not been saved — what the modeller shows **while** the author edits.
248
- *
249
- * Without it a author saw nothing until they saved and opened the release panel. The judgement runs here, not
250
- * in the browser, because the sentences are made from the request's language (`inspectAnySource` with `context.t`)
251
- * and a second copy on the screen would drift from the one the release refuses with. When `id` names a saved
252
- * figure, its row type and last release are read as `inspectFigure` does; a figure never saved has neither.
253
- */
254
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
255
- @Query(returns => FigureInspection, { description: 'Whether an unsaved figure source would be released, with the reasons.' })
256
- async inspectFigureDraft(
257
- @Arg('source') source: string,
258
- @Ctx() context: ResolverContext,
259
- @Arg('id', { nullable: true }) id?: string
260
- ): Promise<FigureInspection> {
261
- const { domain } = context.state
262
- if (!id) return inspectSource(source, null, context.t)
263
-
264
- const figure = await getRepository(Figure).findOne({
265
- where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id },
266
- select: { id: true, type: true, category: true }
267
- })
268
- if (!figure) throw new Error(`Figure ${id} 를 찾을 수 없다`)
269
-
270
- const released = await getRepository(FigureHistory)
271
- .createQueryBuilder('history')
272
- .where('history.originalId = :id', { id })
273
- .orderBy('history.version', 'DESC')
274
- .limit(1)
275
- .getOne()
276
-
277
- return inspectSource(source, released?.source, context.t, figure.type, figure.category)
278
- }
279
-
280
- /** The categories this server allows (G5), or null when a category is free text: the modeller offers them to choose from. */
281
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
282
- @Query(returns => [String], { nullable: true, description: 'The categories this server allows, or null when a category is free text.' })
283
- async figureCategories(): Promise<string[] | null> {
284
- const codes = figureCategories()
285
- return codes ? [...codes] : null
286
- }
287
-
288
- @Directive('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)')
289
- @Query(returns => [String], { description: 'All figure type names in scope — used to check name collisions before create.' })
290
- async figureTypeNames(@Ctx() context: ResolverContext): Promise<string[]> {
291
- const { domain } = context.state
292
-
293
- const rows = await getRepository(Figure).find({
294
- where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) } },
295
- select: { type: true }
296
- })
297
-
298
- return rows.map(r => r.type).filter(Boolean)
299
- }
300
-
301
- /**
302
- * 소비처(operato-board, operato-twin, things-scene)가 발행된 피규어를 받아 가는 문.
303
- *
304
- * 이름은 보드와의 계약이라 그대로 둔다(바꾸는 일은 따로 한다). 돌려주는 것은 자산이다 —
305
- * `{ type, asset }`. 그리는 쪽(`registerFigure`)이 커널로 컴파일한다.
306
- *
307
- * ## 규칙
308
- * 1. 소비처는 초안(draft)을 볼 수 없다 — **반드시 발행된(released) 버전만 전달**한다.
309
- * 2. 현재 Figure가 released 상태이면 현재 source를 넘긴다.
310
- * 3. 현재 Figure가 저작 중(draft)이더라도 이전에 발행된 이력(FigureHistory)이 있으면
311
- * 가장 최근의 released 버전을 넘긴다.
312
- * 4. 한 번도 발행된 적 없는 초안 자산이거나 존재하지 않는 타입인 경우 null을 반환하여
313
- * 미완성 자산이 씬 화면에 유출되는 것을 엄격히 차단한다.
314
- * 5. 도메인 상속 시 자식 도메인의 타입이 부모 도메인의 동일 타입을 항상 오버라이드한다.
315
- * 6. 권한은 저작(`figure`)과 **다른 category** 인 `figure-published` 다. 소비처 사용자에게
316
- * 저작 권한을 요구하면 board·twin 의 팔레트가 안 뜨고, 그렇다고 선언을 비우면 이 집에서는
317
- * 로그인조차 안 한 사람에게 열린다(`auth-rebuild.md` §1). `<module>-published` 는
318
- * 「그 모듈이 발행한 것을 남이 읽는 문」이라는 규약이다 — 아키텍트 판정(2026-09-15).
319
- *
320
- * ## 열거는 막혀 있다 — 지금은 우연이다
321
- *
322
- * 이 문의 열쇠는 `type` 하나뿐이라 이름을 모르면 못 꺼낸다. 그런데 그것이 **설계가 아니다** —
323
- * 목록을 내는 `figures`·`figureTypeNames` 가 `figure` category 로 잠겨 있어서 결과적으로
324
- * 그런 것뿐이다. 나중에 누가 소비처용 목록 문을 하나 더 열고 `figure-published` 를 붙이면
325
- * 열거가 함께 열리고, 「이름을 알아야 한다」에 기대고 있던 가정이 조용히 사라진다.
326
- * 그 문을 낼 사람이 이 단락을 읽고 그때 정하면 된다.
327
- */
328
- /*
329
- This directive is attached by schema assembly, so a test that calls the resolver method
330
- directly never exercises it. `figure-blueprint-query.test.ts` reads this source for the
331
- declaration instead — see the test named for it there.
332
- */
333
- @Directive('@privilege(category: "figure-published", privilege: "query", domainOwnerGranted: true)')
334
- @Query(returns => GraphQLJSON, {
335
- nullable: true,
336
- description:
337
- 'A released figure for its consumers (board, twin, things-scene): { type, version, asset }. The latest release, or the one numbered `version` for a consumer that pins releases (ADR-0104). Only returns released figures.'
338
- })
339
- async figureBlueprint(
340
- @Arg('type') type: string,
341
- @Ctx() context: ResolverContext,
342
- @Arg('version', type => Int, { nullable: true, description: 'A release number. Absent: the latest release.' }) pinned?: number
343
- ): Promise<any> {
344
- const { domain } = context.state
345
-
346
- /*
347
- A child domain shadows the same type in its parent, which is how a tenant replaces the standard
348
- CONVEYOR with its own. Only a released version shadows. When the child has just a draft, the
349
- parent's release is used, so starting a draft never makes placed figures disappear (chief
350
- architect ruling, 2026-09-17). This used to skip the fallback as soon as a child row existed and
351
- return null.
352
- */
353
- const latest =
354
- (await releasedSourceOf(domain.id, type)) ?? (domain.parentId ? await releasedSourceOf(domain.parentId, type) : null)
355
-
356
- if (!latest) {
357
- return null
358
- }
359
-
360
- /*
361
- A pinned release is read from the same figure the latest comes from -- the shadowing rule decides whose
362
- releases these are, then the number picks one. Releases are never deleted, so a number once handed out is
363
- always there; a number that never was is refused by name rather than answered with another release.
364
- */
365
- const found = pinned === undefined || pinned === null || pinned === latest.version ? latest : await releaseNumbered(latest.figure, pinned)
366
- if (!found) {
367
- throw new Refusal(
368
- 'figure-release-not-found',
369
- { type, version: pinned, latest: latest.version },
370
- '{type} has no release {version}. its latest release is {latest}.'
371
- )
372
- }
373
-
374
- const { figure, source: sourceToCompile, version } = found
375
-
376
- try {
377
- const text = typeof sourceToCompile === 'string' ? sourceToCompile : JSON.stringify(sourceToCompile)
378
- return { type, version, asset: consumablePayloadOf(text).asset }
379
- } catch (err) {
380
- console.error(`[figureBlueprint] 타입 '${type}' (figure id: ${figure.id}) 자산 컴파일 실패:`, err)
381
-
382
- /*
383
- Null says one thing here: nobody published this type (ADR-0063 결정 2 보탬). A released figure
384
- whose stored source no longer compiles is a different fact, and answering null for it makes the
385
- board draw a stand-in with the reason nowhere on screen — the author published, the catalogue
386
- says released, and the only trace is the line above. That is the silence ADR-0053 refuses.
387
-
388
- The board asks per type inside a Promise.all and collects a rejection into `failed`, so this
389
- refusal costs that one figure its drawing and the scene still opens.
390
- */
391
- throw new Refusal(
392
- 'figure-release-does-not-compile',
393
- { type, figureId: figure.id, version },
394
- 'the released source of {type} does not compile. open it in the modeller and release it again.'
395
- )
396
- }
397
- }
398
-
399
- /**
400
- * Released figures a board asks for together, by full name `{namespace}/{type}` (ADR-0114 결정 14).
401
- *
402
- * One answer per name: an item, or a refusal that names why. A refusal never takes another item away -- the board
403
- * draws what it got and a stand-in with the reason for the rest. This server keeps its policy: the latest release,
404
- * shadowed by the child domain as `figureBlueprint` does. A type map is the board server's.
405
- */
406
- @Directive('@privilege(category: "figure-published", privilege: "query", domainOwnerGranted: true)')
407
- @Query(returns => GraphQLJSON, {
408
- description:
409
- 'Released figures asked together by full name {namespace}/{type}: { items: [{ type, ref, asset }], refused: [{ type, code, message }] }. The latest release of each; one refusal never removes another item.'
410
- })
411
- async figureBlueprints(
412
- @Arg('types', type => [String], { description: 'Full figure names {namespace}/{type}. At most 500.' }) types: string[],
413
- @Ctx() context: ResolverContext
414
- ): Promise<any> {
415
- const { domain } = context.state
416
- const names = [...new Set(types)]
417
- if (names.length > FIGURE_BLUEPRINTS_MAX) {
418
- throw new Refusal('figure-names-too-many', { count: names.length, max: FIGURE_BLUEPRINTS_MAX }, 'at most {max} figure names can be asked at once, not {count}.')
419
- }
420
-
421
- const items: { type: string; ref: string; asset: unknown }[] = []
422
- const refused: { type: string; code: string; message: string }[] = []
423
- /* Plain text: a board draws the reason on a canvas, so a name with `/` is not escaped. */
424
- const refuse = (type: string, refusal: Refusal) =>
425
- refused.push({
426
- type,
427
- code: refusal.code,
428
- message: context.t
429
- ? context.t(refusalKey(refusal.code), { ...refusal.params, defaultValue: refusal.message, interpolation: { escapeValue: false } })
430
- : refusal.message
431
- })
432
-
433
- for (const type of names) {
434
- const name = parseFigureName(type)
435
- if (!name) {
436
- refuse(type, new Refusal('figure-name-malformed', { type }, '{type} is not a full figure name of the form namespace/type.'))
437
- continue
438
- }
439
- const found =
440
- (await releasedSourceOfName(domain.id, name)) ??
441
- (domain.parentId ? await releasedSourceOfName(domain.parentId, name) : null) ??
442
- (await publicReleasedSourceOf(name))
443
- if (!found) {
444
- refuse(type, new Refusal('figure-not-released', { type }, 'no release is published here.'))
445
- continue
446
- }
447
- try {
448
- items.push({ type, ref: formatFigureRef({ ...name, version: found.version }), asset: consumablePayloadOf(found.source).asset })
449
- } catch {
450
- refuse(
451
- type,
452
- new Refusal(
453
- 'figure-release-does-not-compile',
454
- { type, figureId: found.figure.id, version: found.version },
455
- 'the released source of {type} does not compile. open it in the modeller and release it again.'
456
- )
457
- )
458
- }
459
- }
460
-
461
- return { items, refused }
462
- }
463
- }
464
-
465
- const FIGURE_BLUEPRINTS_MAX = 500
466
-
467
- /** The released source of a full name in one domain: the type there, published under that namespace. */
468
- async function releasedSourceOfName(domainId: string, name: FigureName) {
469
- const found = await releasedSourceOf(domainId, name.type)
470
- return found && found.figure.namespace === name.namespace ? found : null
471
- }
472
-
473
- /** The released source of another domain's public figure by full name (G2): looked at after the reader's own. */
474
- async function publicReleasedSourceOf(name: FigureName) {
475
- const figure = await publicFigureOfName(name.namespace, name.type)
476
- return figure?.domain ? releasedSourceOfName(figure.domain.id, name) : null
477
- }
478
-
479
- /** One numbered release of a figure, or null when it has none by that number. */
480
- async function releaseNumbered(figure: Figure, version: number): Promise<{ figure: Figure; source: string; version: number } | null> {
481
- const row = await getRepository(FigureHistory).findOne({
482
- where: { originalId: figure.id, state: 'released', version }
483
- })
484
- return row?.source ? { figure, source: row.source, version: row.version } : null
485
- }
486
-
487
- /**
488
- * Finds the released source of a type in one domain, or null.
489
- *
490
- * Always the latest release's own copy, from history: it carries the size range written down at release (ADR-0087
491
- * decision 6), and the figure's row -- released or a draft -- keeps only the ends its author narrowed. A figure that
492
- * was never released gives null, because drafts never reach consumers.
493
- */
494
- async function releasedSourceOf(
495
- domainId: string,
496
- type: string
497
- ): Promise<{ figure: Figure; source: string; version: number } | null> {
498
- const figure = await getRepository(Figure).findOne({ where: { domain: { id: domainId }, type } })
499
- if (!figure) return null
500
-
501
- const latestReleased = await getRepository(FigureHistory).findOne({
502
- where: { domain: { id: domainId }, originalId: figure.id, state: 'released' },
503
- order: { version: 'DESC' }
504
- })
505
-
506
- /* The version travels with the source: a refusal names the edition that does not compile, and the
507
- row's own version is the draft being edited, not the one the board was handed. */
508
- return latestReleased?.source
509
- ? { figure, source: latestReleased.source, version: latestReleased.version }
510
- : null
511
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * Release checks an app adds (LV figure-server design G10): they see the asset, the row's type and category and the
3
- * reader's words, and their findings join the gate's -- a blocking one blocks, a said one does not; a check that
4
- * throws blocks by name rather than being skipped; one taken off is gone.
5
- */
6
- import { createFigureAsset, addFigureBox, serializeFigureAsset, applyFigureAuthoring } from '@hatiolab/figure-model'
7
-
8
- import { inspectSource, registerFigureReleaseCheck } from './figure-format'
9
-
10
- const source = () => {
11
- let asset = addFigureBox(createFigureAsset('Mixer'), { id: 'body', size: { x: 100, y: 100, z: 100 }, position: { x: 0, y: 50, z: 0 } })
12
- asset = applyFigureAuthoring(asset, { kind: 'attach', part: 'body', to: { plane: 'mounting-plane' } })
13
- return serializeFigureAsset(applyFigureAuthoring(asset, { kind: 'set-placement', placement: 'floor' }))
14
- }
15
- const codes = (inspection: { findings: { code: string; blocking: boolean }[] }) => inspection.findings.map(f => [f.code, f.blocking])
16
-
17
- describe('release checks an app adds', () => {
18
- const off: Array<() => void> = []
19
- afterEach(() => off.splice(0).forEach(take => take()))
20
-
21
- it('none: the gate as it was', () => {
22
- const inspection = inspectSource(source(), null, undefined, 'mixer', 'EQUIPMENT')
23
- expect(inspection.blocked).toBe(false)
24
- expect(inspection.findings.filter(f => f.code.startsWith('app-'))).toEqual([])
25
- })
26
-
27
- it('see the asset, the type and the category; a blocking finding blocks, a said one does not', () => {
28
- const seen: unknown[] = []
29
- off.push(
30
- registerFigureReleaseCheck(input => {
31
- seen.push([input.asset.version, input.type, input.category])
32
- return input.category === 'CARRIER'
33
- ? [{ code: 'app-carrier-one-part', message: 'a carrier is one part', blocking: false }]
34
- : [{ code: 'app-origin-off', message: 'the origin is off the middle', blocking: true }]
35
- })
36
- )
37
- const equipment = inspectSource(source(), null, undefined, 'mixer', 'EQUIPMENT')
38
- expect(codes(equipment)).toContainEqual(['app-origin-off', true])
39
- expect(equipment.blocked).toBe(true)
40
- const carrier = inspectSource(source(), null, undefined, 'roll', 'CARRIER')
41
- expect(codes(carrier)).toContainEqual(['app-carrier-one-part', false])
42
- expect(carrier.blocked).toBe(false)
43
- expect(seen).toEqual([['figure-asset-1', 'mixer', 'EQUIPMENT'], ['figure-asset-1', 'roll', 'CARRIER']])
44
- })
45
-
46
- it('a check that throws blocks by name; one taken off is gone', () => {
47
- const take = registerFigureReleaseCheck(() => {
48
- throw new Error('no budget table')
49
- })
50
- const inspection = inspectSource(source(), null, undefined, 'mixer', 'EQUIPMENT')
51
- expect(codes(inspection)).toContainEqual(['release-check-failed', true])
52
- expect(inspection.findings.find(f => f.code === 'release-check-failed')?.message).toMatch(/no budget table/)
53
- take()
54
- expect(inspectSource(source(), null, undefined, 'mixer', 'EQUIPMENT').blocked).toBe(false)
55
- })
56
-
57
- it('a source the kernel refuses is not shown to them', () => {
58
- let called = false
59
- off.push(registerFigureReleaseCheck(() => ((called = true), [])))
60
- expect(inspectSource('{"version":"figure-asset-1"}', null, undefined, 'x', null).blocked).toBe(true)
61
- expect(called).toBe(false)
62
- })
63
- })