@things-factory/figure-service 10.1.263 → 10.1.266
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist-server/service/figure/figure-ai-scenarios.js +11 -3
- package/dist-server/service/figure/figure-ai-scenarios.js.map +1 -1
- package/dist-server/service/figure/figure-context.d.ts +10 -13
- package/dist-server/service/figure/figure-context.js +64 -4
- package/dist-server/service/figure/figure-context.js.map +1 -1
- package/dist-server/service/figure/figure-format.d.ts +2 -0
- package/dist-server/service/figure/figure-format.js +1 -1
- package/dist-server/service/figure/figure-format.js.map +1 -1
- package/dist-server/service/figure/figure-mutation.d.ts +2 -2
- package/dist-server/service/figure/figure-mutation.js +25 -4
- package/dist-server/service/figure/figure-mutation.js.map +1 -1
- package/dist-server/service/figure/figure-propose-steps.d.ts +5 -1
- package/dist-server/service/figure/figure-propose-steps.js +11 -7
- package/dist-server/service/figure/figure-propose-steps.js.map +1 -1
- package/dist-server/service/figure/figure-type.d.ts +6 -0
- package/dist-server/service/figure/figure-type.js +20 -1
- package/dist-server/service/figure/figure-type.js.map +1 -1
- package/dist-server/service/figure/figure-write.d.ts +31 -0
- package/dist-server/service/figure/figure-write.js +51 -0
- package/dist-server/service/figure/figure-write.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/server/service/figure/figure-ai-scenarios.test.ts +32 -0
- package/server/service/figure/figure-ai-scenarios.ts +9 -3
- package/server/service/figure/figure-catalog-seen-db.test.ts +153 -0
- package/server/service/figure/figure-category-db.test.ts +6 -6
- package/server/service/figure/figure-context.test.ts +116 -2
- package/server/service/figure/figure-context.ts +55 -3
- package/server/service/figure/figure-format.ts +3 -2
- package/server/service/figure/figure-mutation.ts +27 -6
- package/server/service/figure/figure-propose-steps.ts +19 -8
- package/server/service/figure/figure-public-db.test.ts +1 -1
- package/server/service/figure/figure-rename-db.test.ts +1 -1
- package/server/service/figure/figure-revert-db.test.ts +3 -0
- package/server/service/figure/figure-type.ts +13 -0
- package/server/service/figure/figure-write.ts +60 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figure-type.js","sourceRoot":"","sources":["../../../server/service/figure/figure-type.ts"],"names":[],"mappings":";;;;AAAA,yEAAgE;AAChE,+CAAgE;AAChE,qDAA6C;AAE7C,2CAAoC;AAEpC;;;;;GAKG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;CA8BrB,CAAA;AA9BY,8BAAS;AAEpB;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,iEAAiE,EAAE,CAAC;;uCAC9E;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;;uCAC7C;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;;8CAC7D;AAGpB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,2DAA2D,EAAE,CAAC;;2CACnF;AAGjB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,6CAA6C,EAAE,CAAC;;uCACzF;AAGf;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAAC;;yCACpD;AAGd;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,gEAAgE,EAAE,CAAC;;6CACtF;AAGnB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;;wCACrD;AAG5B;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,mCAAmC,EAAE,CAAC;;4CAC1D;AAGlB;IADC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AAE,CAAC;GACjE,gBAAgB,CAM5B;AAED,+FAA+F;AAExF,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAM5B,CAAA;AANY,4CAAgB;AAE3B;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,mEAAmE,EAAE,CAAC;;8CAChF;AAGZ;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,6BAAW,EAAE,EAAE,WAAW,EAAE,uEAAuE,EAAE,CAAC;;iDACrG;2BALL,gBAAgB;IAD5B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,wDAAwD,EAAE,CAAC;GACzE,gBAAgB,CAM5B","sourcesContent":["import { FigureReplacedDraft } from './figure-replaced-draft.js'\nimport { Field, InputType, Int, ObjectType } from 'type-graphql'\nimport { GraphQLJSON } from 'graphql-scalars'\n\nimport { Figure } from './figure.js'\n\n/**\n * 새 Figure.\n *\n * `score`·`triangles`·`groups` 는 **받지 않는다.** 서버가 `source` 에서 계산한다 —\n * 받으면 거짓이 들어오고 목록이 실물과 다른 것을 보여 준다.\n */\n@InputType({ description: 'Input for creating a new figure.' })\nexport class NewFigure {\n @Field({ description: 'Component type name. Immutable once created, unique per domain.' })\n type: string\n\n @Field({ description: 'Display name shown to authors.' })\n name: string\n\n @Field({ nullable: true, description: 'A detailed description for the figure.' })\n description?: string\n\n @Field({ nullable: true, description: 'Classification code used to group figures in the palette.' })\n category?: string\n\n @Field(type => [String], { nullable: true, description: 'Free-form tags. A figure may carry several.' })\n tags?: string[]\n\n @Field({ description: 'The figure asset JSON (figure-asset-1).' })\n source: string\n\n @Field({ nullable: true, description: 'JSON definition of the master-data fields an instance carries.' })\n properties?: string\n\n @Field({ nullable: true, description: \"Lifecycle state — defaults to 'draft'.\" })\n state?: 'draft' | 'released'\n\n @Field({ nullable: true, description: 'A base64 encoded thumbnail image.' })\n thumbnail?: string\n\n @Field({ nullable: true, description: \"The domain's namespace to create it under; the domain's default when none.\" })\n namespace?: string\n}\n\n/**\n * 수정.\n *\n * `type` 은 **한 번도 발행되지 않은 초안에서만** 바뀐다(ADR-0063 결정 4). 저장되는 식별자라\n * 발행된 뒤에 바꾸면 이미 배치된 보드가 타입을 못 찾아 오류 없이 빈 화면이 된다. 발행 전에는\n * 그 피규어를 가리키는 도면이 있을 수 없다 — 도면은 최신 발행 버전을 그리므로 발행된 적 없는\n * 피규어는 그려질 자리가 없다.\n *\n * 닫아 두었더니 저작자가 이름을 한 번도 정하지 못했다. 새 Figure 에는 기계가 지은 이름이\n * 붙고(`FIGURE_MU6RJH47`) 칸에 자물쇠가 걸려서, 그 이름이 그대로 도면에 적히는 이름이 됐다.\n */\n@InputType({ description: 'Input for updating an existing figure. `type` is accepted only while the figure has never been released.' })\nexport class FigurePatch {\n @Field({ nullable: true, description: 'The stored identifier. Accepted only before the first release; rejected once a version exists.' })\n type?: string\n\n @Field({ nullable: true, description: 'The new display name.' })\n name?: string\n\n @Field({ nullable: true, description: 'The new description.' })\n description?: string\n\n /* 언어별 표시 이름. 안 준 것은 그대로, `{}` 는 전부 지운다. */\n @Field(type => GraphQLJSON, { nullable: true, description: 'Display names by language. {} clears them; omitting the field leaves them.' })\n names?: Record<string, string>\n\n @Field({ nullable: true, description: 'The new classification code.' })\n category?: string\n\n /*\n 빈 배열과 안 준 것을 가른다. `undefined` 는 「건드리지 않는다」, `[]` 는 「전부 지운다」다.\n 둘을 뭉개면 태그를 다 지우려는 저작자가 지울 방법을 잃는다.\n */\n @Field(type => [String], { nullable: true, description: 'The new tags. An empty list clears them; omitting the field leaves them.' })\n tags?: string[]\n\n @Field({ nullable: true, description: 'The new figure asset JSON (figure-asset-1).' })\n source?: string\n\n @Field({ nullable: true, description: 'The new master-data field definition.' })\n properties?: string\n\n /*\n `state` 는 여기 없다 — **상태는 저장이 정하지 않는다.**\n\n 발행은 `releaseFigure` 가 한다. 저장으로 상태를 바꿀 수 있게 두면 발행된 버전을 덮어쓰면서 같은\n 버전 번호로 버전을 또 뜨게 되고(유니크 충돌), 무엇이 약속된 버전인지도 흐려진다. board 도 같다.\n */\n\n @Field({ nullable: true, description: 'A base64 encoded thumbnail image.' })\n thumbnail?: string\n}\n\n@ObjectType({ description: 'A paginated list of figures.' })\nexport class FigureList {\n @Field(type => [Figure], { description: 'The figures on this page.' })\n items: Figure[]\n\n @Field(type => Int, { description: 'Total number of figures matching the query.' })\n total: number\n}\n\n/**\n * 검증 결과 한 줄.\n *\n * 정본 형식의 검증은 `@hatiolab/figure-model` 이 두 단계로 나눈다 — `errors` 는\n * 막고, `violations` 는 알린다. 그 경계를 서버가 다시 정하지 않는다.\n */\n@ObjectType({ description: 'One validation finding from figure-model.' })\nexport class FigureFinding {\n @Field({ description: 'Stable code from figure-model (ERROR_CODES / VIOLATION_CODES).' })\n code: string\n\n @Field({ description: 'Human-readable message.' })\n message: string\n\n @Field({ nullable: true, description: 'Path within the source that the finding points at.' })\n at?: string\n}\n\n/**\n * 저장 결과.\n *\n * `violations` 가 있어도 저장은 된다 — 막는 것과 알리는 것을 가른다. 화면이\n * 이것을 그대로 보여 줘야 한다. 조용히 버리면 저작자가 모른다.\n */\n@ObjectType({ description: 'Result of saving a figure, carrying non-blocking violations.' })\nexport class FigureSaveResult {\n @Field(type => Figure, { description: 'The saved figure.' })\n figure: Figure\n\n @Field(type => [FigureFinding], { description: 'Non-blocking findings. The save succeeded despite these.' })\n violations: FigureFinding[]\n}\n\n/** An AI proposal saved into a figure, with the figure's names as they are now (ADR-0097 §5.6 item 5). */\n@ObjectType({ description: 'A figure an AI proposal was saved into.' })\nexport class FigureProposalOutcome {\n @Field({ description: 'The figure it was saved into.' })\n figureId: string\n\n @Field({ nullable: true, description: \"The figure's type name now.\" })\n type?: string\n\n @Field({ nullable: true, description: \"The figure's display name now.\" })\n name?: string\n\n @Field({ nullable: true, description: 'When the save that held it was made.' })\n recordedAt?: Date\n}\n\n/** A revert's outcome: the figure as it now is, and the draft kept for it (ADR-0097 §5.6). */\n@ObjectType({ description: 'The result of a revert, or of an undo of one.' })\nexport class FigureRevertResult {\n @Field(type => Figure, { description: 'The figure, as it now is.' })\n figure: Figure\n\n @Field(type => [FigureFinding], { description: 'Non-blocking findings on the source written.' })\n violations: FigureFinding[]\n\n @Field(type => FigureReplacedDraft, { description: 'The draft kept for this revert -- or, for an undo, the one brought back.' })\n kept: FigureReplacedDraft\n}\n\n/**\n * 발행 판정 한 줄.\n *\n * `FigureFinding` 과 칸이 겹치지만 **`blocking` 이 하나 더 있다.** 저장 쪽 발견은 정의상 막지 않는\n * 것들이라 그 칸이 필요 없었다. 발행 판정은 막는 것과 알리는 것을 함께 내므로, 어느 쪽인지를 값이\n * 스스로 말해야 한다 — 코드를 보고 화면이 다시 분류하면 규칙이 두 벌이 된다.\n */\n@ObjectType({ description: 'One finding from the release gate.' })\nexport class FigureGateFinding {\n @Field({ description: 'Stable code of the gate finding, for example parts-off-placement-face or parts-split-on-resize.' })\n code: string\n\n @Field({ description: 'Human-readable message.' })\n message: string\n\n @Field({ nullable: true, description: 'Why this is a problem — what a person sees when it happens.' })\n why?: string\n\n @Field({ nullable: true, description: 'What to change, naming the part and the value.' })\n how?: string\n\n @Field({ nullable: true, description: 'Where it points: part names that came apart, or a path in the source.' })\n at?: string\n\n @Field({ description: 'True when this finding blocks the release.' })\n blocking: boolean\n}\n\n/**\n * 발행 판정.\n *\n * 화면이 **발행을 누르기 전에** 물어보는 자리다. 눌러 보고 거절당하는 것으로 알게 되면, 무엇을\n * 고쳐야 하는지 모른 채 단추만 두드리게 된다.\n */\n@ObjectType({ description: 'Whether a figure may be released, and why not.' })\nexport class FigureInspection {\n @Field({ description: 'True when at least one finding blocks the release.' })\n blocked: boolean\n\n @Field(type => [FigureGateFinding], { description: 'Findings, blocking and advisory together.' })\n findings: FigureGateFinding[]\n}\n\n/** A GLB kept for mesh parts (ADR-0129): its hash, and what it holds as the upload read it. */\n@ObjectType({ description: 'A GLB kept for mesh parts: its hash and what it holds.' })\nexport class FigureMeshUpload {\n @Field({ description: \"The file's SHA-256, lower-case hex: what a mesh part names it by.\" })\n hash: string\n\n @Field(type => GraphQLJSON, { description: 'Bounds in mm, triangles, primitives and nodes, as read from the file.' })\n summary: unknown\n}\n"]}
|
|
1
|
+
{"version":3,"file":"figure-type.js","sourceRoot":"","sources":["../../../server/service/figure/figure-type.ts"],"names":[],"mappings":";;;;AAAA,yEAAgE;AAChE,+CAAgE;AAChE,qDAA6C;AAE7C,2CAAoC;AAEpC;;;;;GAKG;AACH,mHAAmH;AAE5G,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAS7B,CAAA;AATY,8CAAiB;AAE5B;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,6CAA6C,EAAE,CAAC;;+CACzE;AAGb;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,yEAAyE,EAAE,CAAC;;mDACjG;AAGjB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,0FAA0F,EAAE,CAAC;;+CACtI;4BARJ,iBAAiB;IAD7B,IAAA,wBAAS,EAAC,EAAE,WAAW,EAAE,+GAA+G,EAAE,CAAC;GAC/H,iBAAiB,CAS7B;AAGM,IAAM,SAAS,GAAf,MAAM,SAAS;CA8BrB,CAAA;AA9BY,8BAAS;AAEpB;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,iEAAiE,EAAE,CAAC;;uCAC9E;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;;uCAC7C;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;;8CAC7D;AAGpB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,2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AAE,uEAAuE,EAAE,CAAC;;6CACrG;AAGX;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,4CAA4C,EAAE,CAAC;;mDACpD;4BAjBN,iBAAiB;IAD7B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;GACrD,iBAAiB,CAkB7B;AAED;;;;;GAKG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAM5B,CAAA;AANY,4CAAgB;AAE3B;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAAC;;iDAC7D;AAGhB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC,EAAE,EAAE,WAAW,EAAE,2CAA2C,EAAE,CAAC;;kDACpE;2BALlB,gBAAgB;IAD5B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,gDAAgD,EAAE,CAAC;GACjE,gBAAgB,CAM5B;AAED,+FAA+F;AAExF,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAM5B,CAAA;AANY,4CAAgB;AAE3B;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,mEAAmE,EAAE,CAAC;;8CAChF;AAGZ;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,6BAAW,EAAE,EAAE,WAAW,EAAE,uEAAuE,EAAE,CAAC;;iDACrG;2BALL,gBAAgB;IAD5B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,wDAAwD,EAAE,CAAC;GACzE,gBAAgB,CAM5B","sourcesContent":["import { FigureReplacedDraft } from './figure-replaced-draft.js'\nimport { Field, InputType, Int, ObjectType } from 'type-graphql'\nimport { GraphQLJSON } from 'graphql-scalars'\n\nimport { Figure } from './figure.js'\n\n/**\n * 새 Figure.\n *\n * `score`·`triangles`·`groups` 는 **받지 않는다.** 서버가 `source` 에서 계산한다 —\n * 받으면 거짓이 들어오고 목록이 실물과 다른 것을 보여 준다.\n */\n/** The catalogue fields as the editor saw them; an update of them goes on only while the row still holds these. */\n@InputType({ description: 'The type, category and tags as the editor saw them. A field left out is not checked; null means it was empty.' })\nexport class FigureCatalogSeen {\n @Field({ nullable: true, description: 'The type the editor saw before changing it.' })\n type?: string\n\n @Field({ nullable: true, description: 'The category the editor saw before changing it; null when it was empty.' })\n category?: string\n\n @Field(type => [String], { nullable: true, description: 'The tags the editor saw before changing them, in their order; null when there were none.' })\n tags?: string[]\n}\n\n@InputType({ description: 'Input for creating a new figure.' })\nexport class NewFigure {\n @Field({ description: 'Component type name. Immutable once created, unique per domain.' })\n type: string\n\n @Field({ description: 'Display name shown to authors.' })\n name: string\n\n @Field({ nullable: true, description: 'A detailed description for the figure.' })\n description?: string\n\n @Field({ nullable: true, description: 'Classification code used to group figures in the palette.' })\n category?: string\n\n @Field(type => [String], { nullable: true, description: 'Free-form tags. A figure may carry several.' })\n tags?: string[]\n\n @Field({ description: 'The figure asset JSON (figure-asset-1).' })\n source: string\n\n @Field({ nullable: true, description: 'JSON definition of the master-data fields an instance carries.' })\n properties?: string\n\n @Field({ nullable: true, description: \"Lifecycle state — defaults to 'draft'.\" })\n state?: 'draft' | 'released'\n\n @Field({ nullable: true, description: 'A base64 encoded thumbnail image.' })\n thumbnail?: string\n\n @Field({ nullable: true, description: \"The domain's namespace to create it under; the domain's default when none.\" })\n namespace?: string\n}\n\n/**\n * 수정.\n *\n * `type` 은 **한 번도 발행되지 않은 초안에서만** 바뀐다(ADR-0063 결정 4). 저장되는 식별자라\n * 발행된 뒤에 바꾸면 이미 배치된 보드가 타입을 못 찾아 오류 없이 빈 화면이 된다. 발행 전에는\n * 그 피규어를 가리키는 도면이 있을 수 없다 — 도면은 최신 발행 버전을 그리므로 발행된 적 없는\n * 피규어는 그려질 자리가 없다.\n *\n * 닫아 두었더니 저작자가 이름을 한 번도 정하지 못했다. 새 Figure 에는 기계가 지은 이름이\n * 붙고(`FIGURE_MU6RJH47`) 칸에 자물쇠가 걸려서, 그 이름이 그대로 도면에 적히는 이름이 됐다.\n */\n@InputType({ description: 'Input for updating an existing figure. `type` is accepted only while the figure has never been released.' })\nexport class FigurePatch {\n @Field({ nullable: true, description: 'The stored identifier. Accepted only before the first release; rejected once a version exists.' })\n type?: string\n\n @Field({ nullable: true, description: 'The new display name.' })\n name?: string\n\n @Field({ nullable: true, description: 'The new description.' })\n description?: string\n\n /* 언어별 표시 이름. 안 준 것은 그대로, `{}` 는 전부 지운다. */\n @Field(type => GraphQLJSON, { nullable: true, description: 'Display names by language. {} clears them; omitting the field leaves them.' })\n names?: Record<string, string>\n\n @Field({ nullable: true, description: 'The new classification code.' })\n category?: string\n\n /*\n 빈 배열과 안 준 것을 가른다. `undefined` 는 「건드리지 않는다」, `[]` 는 「전부 지운다」다.\n 둘을 뭉개면 태그를 다 지우려는 저작자가 지울 방법을 잃는다.\n */\n @Field(type => [String], { nullable: true, description: 'The new tags. An empty list clears them; omitting the field leaves them.' })\n tags?: string[]\n\n @Field({ nullable: true, description: 'The new figure asset JSON (figure-asset-1).' })\n source?: string\n\n @Field({ nullable: true, description: 'The new master-data field definition.' })\n properties?: string\n\n /*\n `state` 는 여기 없다 — **상태는 저장이 정하지 않는다.**\n\n 발행은 `releaseFigure` 가 한다. 저장으로 상태를 바꿀 수 있게 두면 발행된 버전을 덮어쓰면서 같은\n 버전 번호로 버전을 또 뜨게 되고(유니크 충돌), 무엇이 약속된 버전인지도 흐려진다. board 도 같다.\n */\n\n @Field({ nullable: true, description: 'A base64 encoded thumbnail image.' })\n thumbnail?: string\n}\n\n@ObjectType({ description: 'A paginated list of figures.' })\nexport class FigureList {\n @Field(type => [Figure], { description: 'The figures on this page.' })\n items: Figure[]\n\n @Field(type => Int, { description: 'Total number of figures matching the query.' })\n total: number\n}\n\n/**\n * 검증 결과 한 줄.\n *\n * 정본 형식의 검증은 `@hatiolab/figure-model` 이 두 단계로 나눈다 — `errors` 는\n * 막고, `violations` 는 알린다. 그 경계를 서버가 다시 정하지 않는다.\n */\n@ObjectType({ description: 'One validation finding from figure-model.' })\nexport class FigureFinding {\n @Field({ description: 'Stable code from figure-model (ERROR_CODES / VIOLATION_CODES).' })\n code: string\n\n @Field({ description: 'Human-readable message.' })\n message: string\n\n @Field({ nullable: true, description: 'Path within the source that the finding points at.' })\n at?: string\n}\n\n/**\n * 저장 결과.\n *\n * `violations` 가 있어도 저장은 된다 — 막는 것과 알리는 것을 가른다. 화면이\n * 이것을 그대로 보여 줘야 한다. 조용히 버리면 저작자가 모른다.\n */\n@ObjectType({ description: 'Result of saving a figure, carrying non-blocking violations.' })\nexport class FigureSaveResult {\n @Field(type => Figure, { description: 'The saved figure.' })\n figure: Figure\n\n @Field(type => [FigureFinding], { description: 'Non-blocking findings. The save succeeded despite these.' })\n violations: FigureFinding[]\n}\n\n/** An AI proposal saved into a figure, with the figure's names as they are now (ADR-0097 §5.6 item 5). */\n@ObjectType({ description: 'A figure an AI proposal was saved into.' })\nexport class FigureProposalOutcome {\n @Field({ description: 'The figure it was saved into.' })\n figureId: string\n\n @Field({ nullable: true, description: \"The figure's type name now.\" })\n type?: string\n\n @Field({ nullable: true, description: \"The figure's display name now.\" })\n name?: string\n\n @Field({ nullable: true, description: 'When the save that held it was made.' })\n recordedAt?: Date\n}\n\n/** A revert's outcome: the figure as it now is, and the draft kept for it (ADR-0097 §5.6). */\n@ObjectType({ description: 'The result of a revert, or of an undo of one.' })\nexport class FigureRevertResult {\n @Field(type => Figure, { description: 'The figure, as it now is.' })\n figure: Figure\n\n @Field(type => [FigureFinding], { description: 'Non-blocking findings on the source written.' })\n violations: FigureFinding[]\n\n @Field(type => FigureReplacedDraft, { description: 'The draft kept for this revert -- or, for an undo, the one brought back.' })\n kept: FigureReplacedDraft\n}\n\n/**\n * 발행 판정 한 줄.\n *\n * `FigureFinding` 과 칸이 겹치지만 **`blocking` 이 하나 더 있다.** 저장 쪽 발견은 정의상 막지 않는\n * 것들이라 그 칸이 필요 없었다. 발행 판정은 막는 것과 알리는 것을 함께 내므로, 어느 쪽인지를 값이\n * 스스로 말해야 한다 — 코드를 보고 화면이 다시 분류하면 규칙이 두 벌이 된다.\n */\n@ObjectType({ description: 'One finding from the release gate.' })\nexport class FigureGateFinding {\n @Field({ description: 'Stable code of the gate finding, for example parts-off-placement-face or parts-split-on-resize.' })\n code: string\n\n @Field({ description: 'Human-readable message.' })\n message: string\n\n @Field({ nullable: true, description: 'Why this is a problem — what a person sees when it happens.' })\n why?: string\n\n @Field({ nullable: true, description: 'What to change, naming the part and the value.' })\n how?: string\n\n @Field({ nullable: true, description: 'Where it points: part names that came apart, or a path in the source.' })\n at?: string\n\n @Field({ description: 'True when this finding blocks the release.' })\n blocking: boolean\n}\n\n/**\n * 발행 판정.\n *\n * 화면이 **발행을 누르기 전에** 물어보는 자리다. 눌러 보고 거절당하는 것으로 알게 되면, 무엇을\n * 고쳐야 하는지 모른 채 단추만 두드리게 된다.\n */\n@ObjectType({ description: 'Whether a figure may be released, and why not.' })\nexport class FigureInspection {\n @Field({ description: 'True when at least one finding blocks the release.' })\n blocked: boolean\n\n @Field(type => [FigureGateFinding], { description: 'Findings, blocking and advisory together.' })\n findings: FigureGateFinding[]\n}\n\n/** A GLB kept for mesh parts (ADR-0129): its hash, and what it holds as the upload read it. */\n@ObjectType({ description: 'A GLB kept for mesh parts: its hash and what it holds.' })\nexport class FigureMeshUpload {\n @Field({ description: \"The file's SHA-256, lower-case hex: what a mesh part names it by.\" })\n hash: string\n\n @Field(type => GraphQLJSON, { description: 'Bounds in mm, triangles, primitives and nodes, as read from the file.' })\n summary: unknown\n}\n"]}
|
|
@@ -6,6 +6,36 @@ import { GraphQLError } from 'graphql';
|
|
|
6
6
|
* saying its save failed (D, designer 2026-09-27).
|
|
7
7
|
*/
|
|
8
8
|
export declare function sourceConflict(message: string): GraphQLError;
|
|
9
|
+
/**
|
|
10
|
+
* The catalogue fields as the editor saw them when it changed them: the type, the category, the tags. Kept on the row,
|
|
11
|
+
* not in the source, so the source's compare-and-swap does not hold them; a save of these alone is checked against
|
|
12
|
+
* these (outside review 2026-11-09: two tabs set the category, the later one wrote over the first without a word).
|
|
13
|
+
* A field left out is not checked; null is "was empty".
|
|
14
|
+
*/
|
|
15
|
+
export interface FigureCatalogSeen {
|
|
16
|
+
type?: string | null;
|
|
17
|
+
category?: string | null;
|
|
18
|
+
tags?: string[] | null;
|
|
19
|
+
}
|
|
20
|
+
export declare const CATALOG_FIELDS: readonly ["type", "category", "tags"];
|
|
21
|
+
type CatalogField = (typeof CATALOG_FIELDS)[number];
|
|
22
|
+
/** The fields the row no longer holds as the editor saw them, each with what it holds now. */
|
|
23
|
+
export declare function catalogConflictsOf(row: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen): {
|
|
24
|
+
field: CatalogField;
|
|
25
|
+
now: string | string[] | null;
|
|
26
|
+
}[];
|
|
27
|
+
/** The same check in the UPDATE's criteria: a write between the check and the update finds nothing to update. */
|
|
28
|
+
export declare function catalogCriteriaOf(seen: FigureCatalogSeen): Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* A patch that changes a catalogue field says what it saw of that field: there is no unchecked way to write one
|
|
31
|
+
* (outside review 2026-11-09). A field the patch leaves out is neither written nor checked.
|
|
32
|
+
*/
|
|
33
|
+
export declare function assertCatalogSeen(patch: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen | undefined): void;
|
|
34
|
+
/** Another edit changed a catalogue field first: which, and what it holds now, for the editor to say in its words. */
|
|
35
|
+
export declare function catalogConflict(fields: {
|
|
36
|
+
field: string;
|
|
37
|
+
now: string | string[] | null;
|
|
38
|
+
}[]): GraphQLError;
|
|
9
39
|
export interface FigureWriteCriteria {
|
|
10
40
|
id: string;
|
|
11
41
|
domain: {
|
|
@@ -46,3 +76,4 @@ export declare function pictureOf(tx: {
|
|
|
46
76
|
thumbnail?: null;
|
|
47
77
|
thumbnailUpdatedAt?: Date;
|
|
48
78
|
}>;
|
|
79
|
+
export {};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CATALOG_FIELDS = void 0;
|
|
3
4
|
exports.sourceConflict = sourceConflict;
|
|
5
|
+
exports.catalogConflictsOf = catalogConflictsOf;
|
|
6
|
+
exports.catalogCriteriaOf = catalogCriteriaOf;
|
|
7
|
+
exports.assertCatalogSeen = assertCatalogSeen;
|
|
8
|
+
exports.catalogConflict = catalogConflict;
|
|
4
9
|
exports.compareAndSwapFigure = compareAndSwapFigure;
|
|
5
10
|
exports.prepareFigureWrite = prepareFigureWrite;
|
|
6
11
|
exports.pictureOf = pictureOf;
|
|
7
12
|
const figure_thumbnail_store_js_1 = require("./figure-thumbnail-store.js");
|
|
8
13
|
const graphql_1 = require("graphql");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
9
15
|
const figure_model_1 = require("@hatiolab/figure-model");
|
|
10
16
|
/**
|
|
11
17
|
* The row is not what the writer expected: another edit, or the writer's own earlier save whose answer it never got.
|
|
@@ -15,6 +21,51 @@ const figure_model_1 = require("@hatiolab/figure-model");
|
|
|
15
21
|
function sourceConflict(message) {
|
|
16
22
|
return new graphql_1.GraphQLError(message, { extensions: { code: 'FIGURE_SOURCE_CONFLICT' } });
|
|
17
23
|
}
|
|
24
|
+
exports.CATALOG_FIELDS = ['type', 'category', 'tags'];
|
|
25
|
+
/** A catalogue value as compared: an empty category or tag list is no value; tags as the row stores them (simple-json). */
|
|
26
|
+
function comparedCatalogValue(field, value) {
|
|
27
|
+
if (field === 'tags')
|
|
28
|
+
return Array.isArray(value) && value.length ? JSON.stringify(value) : null;
|
|
29
|
+
return typeof value === 'string' && value ? value : null;
|
|
30
|
+
}
|
|
31
|
+
/** The fields the row no longer holds as the editor saw them, each with what it holds now. */
|
|
32
|
+
function catalogConflictsOf(row, seen) {
|
|
33
|
+
return exports.CATALOG_FIELDS.filter(field => seen[field] !== undefined && comparedCatalogValue(field, row[field]) !== comparedCatalogValue(field, seen[field])).map(field => ({
|
|
34
|
+
field,
|
|
35
|
+
now: field === 'tags' ? (row.tags?.length ? row.tags : null) : (row[field] || null)
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/** The same check in the UPDATE's criteria: a write between the check and the update finds nothing to update. */
|
|
39
|
+
function catalogCriteriaOf(seen) {
|
|
40
|
+
const criteria = {};
|
|
41
|
+
for (const field of exports.CATALOG_FIELDS) {
|
|
42
|
+
if (seen[field] === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
const value = comparedCatalogValue(field, seen[field]);
|
|
45
|
+
if (value !== null)
|
|
46
|
+
criteria[field] = field === 'tags' ? (0, typeorm_1.Raw)(column => `${column} = :seenTags`, { seenTags: value }) : value;
|
|
47
|
+
else if (field === 'type')
|
|
48
|
+
criteria[field] = (0, typeorm_1.IsNull)();
|
|
49
|
+
else
|
|
50
|
+
criteria[field] = (0, typeorm_1.Raw)(column => `(${column} IS NULL OR ${column} = '${field === 'tags' ? '[]' : ''}')`);
|
|
51
|
+
}
|
|
52
|
+
return criteria;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A patch that changes a catalogue field says what it saw of that field: there is no unchecked way to write one
|
|
56
|
+
* (outside review 2026-11-09). A field the patch leaves out is neither written nor checked.
|
|
57
|
+
*/
|
|
58
|
+
function assertCatalogSeen(patch, seen) {
|
|
59
|
+
const unseen = exports.CATALOG_FIELDS.filter(field => patch[field] !== undefined && seen?.[field] === undefined);
|
|
60
|
+
if (unseen.length)
|
|
61
|
+
throw new graphql_1.GraphQLError(`변경할 항목의 기존 값이 필요합니다: ${unseen.join(', ')}`, { extensions: { code: 'FIGURE_CATALOG_SEEN_REQUIRED', fields: unseen } });
|
|
62
|
+
}
|
|
63
|
+
/** Another edit changed a catalogue field first: which, and what it holds now, for the editor to say in its words. */
|
|
64
|
+
function catalogConflict(fields) {
|
|
65
|
+
return new graphql_1.GraphQLError(`다른 사용자가 먼저 변경한 항목이 있습니다: ${fields.map(f => f.field).join(', ')}`, {
|
|
66
|
+
extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
18
69
|
async function compareAndSwapFigure(update, id, domainId, expectedSource) {
|
|
19
70
|
if (expectedSource === undefined)
|
|
20
71
|
throw Error('수정 전 정본이 필요합니다.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figure-write.js","sourceRoot":"","sources":["../../../server/service/figure/figure-write.ts"],"names":[],"mappings":";;AASA,wCAEC;AAOD,oDASC;AAGD,gDAkBC;AAUD,8BAYC;AAtED,2EAAgF;AAChF,qCAAsC;AACtC,yDAAgI;AAEhI;;;;GAIG;AACH,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO,IAAI,sBAAY,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,EAAE,CAAC,CAAA;AACtF,CAAC;AAOM,KAAK,UAAU,oBAAoB,CACxC,MAAgF,EAChF,EAAU,EACV,QAAgB,EAChB,cAAkC;IAElC,IAAI,cAAc,KAAK,SAAS;QAAE,MAAM,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAChE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAA;IACrF,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;QAAE,MAAM,cAAc,CAAC,wCAAwC,CAAC,CAAA;AAC3F,CAAC;AAED,mGAAmG;AACnG,SAAgB,kBAAkB,CAAC,MAAc,EAAE,QAA8B,EAAE,cAAuB;IACxG,IAAI,QAAQ,IAAI,CAAC,cAAc,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,cAAc,CAAC,EAAE,CAAC;QACrF,MAAM,cAAc,CAAC,6CAA6C,CAAC,CAAA;IACrE,CAAC;IACD,MAAM,KAAK,GAAG,IAAA,+BAAgB,EAAC,MAAM,CAAC,CAAA;IACtC,IAAA,iCAAkB,EAAC,KAAK,CAAC,CAAA;IACzB;;MAEE;IACF,MAAM,IAAI,GAAG,IAAA,2BAAY,EAAC,KAAK,CAAC,CAAA;IAChC,OAAO;QACL,MAAM,EAAE,IAAA,mCAAoB,EAAC,KAAK,CAAC;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,IAAA,4BAAa,EAAC,KAAK,CAAC,EAAE,KAAK,IAAI,IAAI;QAC1C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,OAAgB;KACxB,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,SAAS,CAC7B,EAA2C,EAC3C,MAAsB,EACtB,IAAa,EACb,SAAkB,EAClB,QAA4C,EAC5C,KAAsB;IAEtB,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,CAAA;IACtC,MAAM,aAAa,GAAG,MAAM,IAAA,yCAAa,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;IAC7E,IAAI,aAAa,KAAK,QAAQ,EAAE,aAAa;QAAE,OAAO,EAAE,CAAA;IACxD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;AAC3E,CAAC","sourcesContent":["import { keepThumbnail, type ThumbnailFiles } from './figure-thumbnail-store.js'\nimport { GraphQLError } from 'graphql'\nimport { parseFigureAsset, serializeFigureAsset, compileFigureAsset, figureCostOf, figureScoreOf } from '@hatiolab/figure-model'\n\n/**\n * The row is not what the writer expected: another edit, or the writer's own earlier save whose answer it never got.\n * Coded, so a client can tell it from a refusal on grounds (permission, validation) and read the row back before\n * saying its save failed (D, designer 2026-09-27).\n */\nexport function sourceConflict(message: string) {\n return new GraphQLError(message, { extensions: { code: 'FIGURE_SOURCE_CONFLICT' } })\n}\n\nexport interface FigureWriteCriteria {\n id: string\n domain: { id: string }\n source: string\n}\nexport async function compareAndSwapFigure(\n update: (criteria: FigureWriteCriteria) => Promise<{ affected?: number | null }>,\n id: string,\n domainId: string,\n expectedSource: string | undefined\n) {\n if (expectedSource === undefined) throw Error('수정 전 정본이 필요합니다.')\n const result = await update({ id, domain: { id: domainId }, source: expectedSource })\n if (result.affected !== 1) throw sourceConflict('다른 편집에서 모델이 변경되었습니다. 최신 모델을 다시 열어 주세요.')\n}\n\n/** Early validation only. The repository must also compare expectedSource in its atomic UPDATE. */\nexport function prepareFigureWrite(source: string, existing?: { source?: string }, expectedSource?: string) {\n if (existing && (expectedSource === undefined || existing.source !== expectedSource)) {\n throw sourceConflict('다른 편집에서 모델이 변경되었습니다. 최신 모델을 다시 연 뒤 적용해 주세요.')\n }\n const asset = parseFigureAsset(source)\n compileFigureAsset(asset)\n /*\n The same measure `parseSource` uses, so the catalogue's columns do not depend on which mutation wrote the row.\n */\n const cost = figureCostOf(asset)\n return {\n source: serializeFigureAsset(asset),\n name: asset.name,\n score: figureScoreOf(asset)?.score ?? null,\n triangles: cost.triangles,\n groups: cost.groups,\n state: 'draft' as const\n }\n}\n\n/**\n * The picture a card shows, when the modeller sent one: kept by its content (`keepThumbnail`) and named on the row by\n * its hash.\n *\n * Absent means the author saved without one — a tab in the background cannot draw, and the source matters more\n * than the picture, so the save goes on and the modeller fills it in next time. The timestamp moves only when\n * the picture itself is new, so renaming a figure does not make every card look freshly drawn.\n */\nexport async function pictureOf(\n tx: { getRepository: (target: any) => any },\n domain: { id: string },\n user: unknown,\n thumbnail?: string,\n existing?: { thumbnailHash?: string | null },\n files?: ThumbnailFiles\n): Promise<{ thumbnailHash?: string; thumbnail?: null; thumbnailUpdatedAt?: Date }> {\n if (thumbnail === undefined) return {}\n const thumbnailHash = await keepThumbnail(tx, domain, user, thumbnail, files)\n if (thumbnailHash === existing?.thumbnailHash) return {}\n return { thumbnailHash, thumbnail: null, thumbnailUpdatedAt: new Date() }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"figure-write.js","sourceRoot":"","sources":["../../../server/service/figure/figure-write.ts"],"names":[],"mappings":";;;AAUA,wCAEC;AAwBD,gDAKC;AAGD,8CAUC;AAMD,8CAIC;AAGD,0CAIC;AAOD,oDASC;AAGD,gDAkBC;AAUD,8BAYC;AAlID,2EAAgF;AAChF,qCAAsC;AACtC,qCAAqC;AACrC,yDAAgI;AAEhI;;;;GAIG;AACH,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO,IAAI,sBAAY,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,EAAE,CAAC,CAAA;AACtF,CAAC;AAcY,QAAA,cAAc,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAU,CAAA;AAGnE,2HAA2H;AAC3H,SAAS,oBAAoB,CAAC,KAAmB,EAAE,KAAc;IAC/D,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAChG,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC1D,CAAC;AAED,8FAA8F;AAC9F,SAAgB,kBAAkB,CAAC,GAA2C,EAAE,IAAuB;IACrG,OAAO,sBAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,SAAS,IAAI,oBAAoB,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG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,cAAc,CAAC,EAAE,CAAC;QACrF,MAAM,cAAc,CAAC,6CAA6C,CAAC,CAAA;IACrE,CAAC;IACD,MAAM,KAAK,GAAG,IAAA,+BAAgB,EAAC,MAAM,CAAC,CAAA;IACtC,IAAA,iCAAkB,EAAC,KAAK,CAAC,CAAA;IACzB;;MAEE;IACF,MAAM,IAAI,GAAG,IAAA,2BAAY,EAAC,KAAK,CAAC,CAAA;IAChC,OAAO;QACL,MAAM,EAAE,IAAA,mCAAoB,EAAC,KAAK,CAAC;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,IAAA,4BAAa,EAAC,KAAK,CAAC,EAAE,KAAK,IAAI,IAAI;QAC1C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,OAAgB;KACxB,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,SAAS,CAC7B,EAA2C,EAC3C,MAAsB,EACtB,IAAa,EACb,SAAkB,EAClB,QAA4C,EAC5C,KAAsB;IAEtB,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,CAAA;IACtC,MAAM,aAAa,GAAG,MAAM,IAAA,yCAAa,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;IAC7E,IAAI,aAAa,KAAK,QAAQ,EAAE,aAAa;QAAE,OAAO,EAAE,CAAA;IACxD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,IAAI,EAAE,EAAE,CAAA;AAC3E,CAAC","sourcesContent":["import { keepThumbnail, type ThumbnailFiles } from './figure-thumbnail-store.js'\nimport { GraphQLError } from 'graphql'\nimport { IsNull, Raw } from 'typeorm'\nimport { parseFigureAsset, serializeFigureAsset, compileFigureAsset, figureCostOf, figureScoreOf } from '@hatiolab/figure-model'\n\n/**\n * The row is not what the writer expected: another edit, or the writer's own earlier save whose answer it never got.\n * Coded, so a client can tell it from a refusal on grounds (permission, validation) and read the row back before\n * saying its save failed (D, designer 2026-09-27).\n */\nexport function sourceConflict(message: string) {\n return new GraphQLError(message, { extensions: { code: 'FIGURE_SOURCE_CONFLICT' } })\n}\n\n/**\n * The catalogue fields as the editor saw them when it changed them: the type, the category, the tags. Kept on the row,\n * not in the source, so the source's compare-and-swap does not hold them; a save of these alone is checked against\n * these (outside review 2026-11-09: two tabs set the category, the later one wrote over the first without a word).\n * A field left out is not checked; null is \"was empty\".\n */\nexport interface FigureCatalogSeen {\n type?: string | null\n category?: string | null\n tags?: string[] | null\n}\n\nexport const CATALOG_FIELDS = ['type', 'category', 'tags'] as const\ntype CatalogField = (typeof CATALOG_FIELDS)[number]\n\n/** A catalogue value as compared: an empty category or tag list is no value; tags as the row stores them (simple-json). */\nfunction comparedCatalogValue(field: CatalogField, value: unknown): string | null {\n if (field === 'tags') return Array.isArray(value) && value.length ? JSON.stringify(value) : null\n return typeof value === 'string' && value ? value : null\n}\n\n/** The fields the row no longer holds as the editor saw them, each with what it holds now. */\nexport function catalogConflictsOf(row: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen): { field: CatalogField; now: string | string[] | null }[] {\n return CATALOG_FIELDS.filter(field => seen[field] !== undefined && comparedCatalogValue(field, row[field]) !== comparedCatalogValue(field, seen[field])).map(field => ({\n field,\n now: field === 'tags' ? ((row.tags as string[] | null | undefined)?.length ? (row.tags as string[]) : null) : ((row[field] as string | null | undefined) || null)\n }))\n}\n\n/** The same check in the UPDATE's criteria: a write between the check and the update finds nothing to update. */\nexport function catalogCriteriaOf(seen: FigureCatalogSeen): Record<string, unknown> {\n const criteria: Record<string, unknown> = {}\n for (const field of CATALOG_FIELDS) {\n if (seen[field] === undefined) continue\n const value = comparedCatalogValue(field, seen[field])\n if (value !== null) criteria[field] = field === 'tags' ? Raw(column => `${column} = :seenTags`, { seenTags: value }) : value\n else if (field === 'type') criteria[field] = IsNull()\n else criteria[field] = Raw(column => `(${column} IS NULL OR ${column} = '${field === 'tags' ? '[]' : ''}')`)\n }\n return criteria\n}\n\n/**\n * A patch that changes a catalogue field says what it saw of that field: there is no unchecked way to write one\n * (outside review 2026-11-09). A field the patch leaves out is neither written nor checked.\n */\nexport function assertCatalogSeen(patch: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen | undefined) {\n const unseen = CATALOG_FIELDS.filter(field => patch[field] !== undefined && seen?.[field] === undefined)\n if (unseen.length)\n throw new GraphQLError(`변경할 항목의 기존 값이 필요합니다: ${unseen.join(', ')}`, { extensions: { code: 'FIGURE_CATALOG_SEEN_REQUIRED', fields: unseen } })\n}\n\n/** Another edit changed a catalogue field first: which, and what it holds now, for the editor to say in its words. */\nexport function catalogConflict(fields: { field: string; now: string | string[] | null }[]) {\n return new GraphQLError(`다른 사용자가 먼저 변경한 항목이 있습니다: ${fields.map(f => f.field).join(', ')}`, {\n extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields }\n })\n}\n\nexport interface FigureWriteCriteria {\n id: string\n domain: { id: string }\n source: string\n}\nexport async function compareAndSwapFigure(\n update: (criteria: FigureWriteCriteria) => Promise<{ affected?: number | null }>,\n id: string,\n domainId: string,\n expectedSource: string | undefined\n) {\n if (expectedSource === undefined) throw Error('수정 전 정본이 필요합니다.')\n const result = await update({ id, domain: { id: domainId }, source: expectedSource })\n if (result.affected !== 1) throw sourceConflict('다른 편집에서 모델이 변경되었습니다. 최신 모델을 다시 열어 주세요.')\n}\n\n/** Early validation only. The repository must also compare expectedSource in its atomic UPDATE. */\nexport function prepareFigureWrite(source: string, existing?: { source?: string }, expectedSource?: string) {\n if (existing && (expectedSource === undefined || existing.source !== expectedSource)) {\n throw sourceConflict('다른 편집에서 모델이 변경되었습니다. 최신 모델을 다시 연 뒤 적용해 주세요.')\n }\n const asset = parseFigureAsset(source)\n compileFigureAsset(asset)\n /*\n The same measure `parseSource` uses, so the catalogue's columns do not depend on which mutation wrote the row.\n */\n const cost = figureCostOf(asset)\n return {\n source: serializeFigureAsset(asset),\n name: asset.name,\n score: figureScoreOf(asset)?.score ?? null,\n triangles: cost.triangles,\n groups: cost.groups,\n state: 'draft' as const\n }\n}\n\n/**\n * The picture a card shows, when the modeller sent one: kept by its content (`keepThumbnail`) and named on the row by\n * its hash.\n *\n * Absent means the author saved without one — a tab in the background cannot draw, and the source matters more\n * than the picture, so the save goes on and the modeller fills it in next time. The timestamp moves only when\n * the picture itself is new, so renaming a figure does not make every card look freshly drawn.\n */\nexport async function pictureOf(\n tx: { getRepository: (target: any) => any },\n domain: { id: string },\n user: unknown,\n thumbnail?: string,\n existing?: { thumbnailHash?: string | null },\n files?: ThumbnailFiles\n): Promise<{ thumbnailHash?: string; thumbnail?: null; thumbnailUpdatedAt?: Date }> {\n if (thumbnail === undefined) return {}\n const thumbnailHash = await keepThumbnail(tx, domain, user, thumbnail, files)\n if (thumbnailHash === existing?.thumbnailHash) return {}\n return { thumbnailHash, thumbnail: null, thumbnailUpdatedAt: new Date() }\n}\n"]}
|