@diagc/cli 1.1.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/assets/guide/index.md +2 -2
  2. package/assets/studio/assets/index-B-KI19Kg.js +110 -0
  3. package/assets/studio/index.html +1 -1
  4. package/assets/viewer/index.html +33 -33
  5. package/dist/api/assets.d.ts +8 -0
  6. package/dist/api/assets.js +54 -0
  7. package/dist/api/diagrams.d.ts +27 -0
  8. package/dist/api/diagrams.js +269 -0
  9. package/dist/api/files.d.ts +7 -0
  10. package/dist/api/files.js +30 -0
  11. package/dist/api/handlers.d.ts +7 -62
  12. package/dist/api/handlers.js +10 -488
  13. package/dist/api/library.d.ts +5 -0
  14. package/dist/api/library.js +88 -0
  15. package/dist/api/result.d.ts +8 -0
  16. package/dist/api/result.js +5 -0
  17. package/dist/api/sidecars.d.ts +13 -0
  18. package/dist/api/sidecars.js +78 -0
  19. package/dist/cli/command.d.ts +26 -0
  20. package/dist/cli/command.js +1 -0
  21. package/dist/cli/io.d.ts +13 -0
  22. package/dist/cli/io.js +7 -0
  23. package/dist/cli/parse.d.ts +51 -0
  24. package/dist/cli/parse.js +109 -0
  25. package/dist/cli/run.d.ts +10 -0
  26. package/dist/cli/run.js +67 -0
  27. package/dist/cli.d.ts +1 -52
  28. package/dist/cli.js +5 -475
  29. package/dist/commands/compile.d.ts +3 -0
  30. package/dist/commands/compile.js +38 -0
  31. package/dist/commands/diff.d.ts +10 -0
  32. package/dist/commands/diff.js +96 -0
  33. package/dist/commands/eject.d.ts +3 -0
  34. package/dist/commands/eject.js +32 -0
  35. package/dist/commands/guide.d.ts +3 -0
  36. package/dist/commands/guide.js +13 -0
  37. package/dist/commands/init.d.ts +3 -0
  38. package/dist/commands/init.js +23 -0
  39. package/dist/commands/lint.d.ts +3 -0
  40. package/dist/commands/lint.js +27 -0
  41. package/dist/commands/publish.d.ts +11 -0
  42. package/dist/commands/publish.js +83 -0
  43. package/dist/commands/shared.d.ts +19 -0
  44. package/dist/commands/shared.js +34 -0
  45. package/dist/commands/studio.d.ts +3 -0
  46. package/dist/commands/studio.js +14 -0
  47. package/dist/commands/watch.d.ts +8 -0
  48. package/dist/commands/watch.js +45 -0
  49. package/dist/compile.d.ts +4 -1
  50. package/dist/compile.js +8 -13
  51. package/dist/diff/compare.d.ts +36 -0
  52. package/dist/diff/compare.js +36 -0
  53. package/dist/diff/describe.d.ts +8 -0
  54. package/dist/diff/describe.js +70 -0
  55. package/dist/diff/index.d.ts +4 -0
  56. package/dist/diff/index.js +6 -0
  57. package/dist/diff/load.d.ts +22 -0
  58. package/dist/diff/load.js +62 -0
  59. package/dist/diff/overview.d.ts +17 -0
  60. package/dist/diff/overview.js +86 -0
  61. package/dist/diff/pages.d.ts +27 -0
  62. package/dist/diff/pages.js +55 -0
  63. package/dist/diff/summary.d.ts +18 -0
  64. package/dist/diff/summary.js +26 -0
  65. package/dist/eject.js +2 -6
  66. package/dist/git-ref.js +21 -3
  67. package/dist/glob.d.ts +5 -0
  68. package/dist/glob.js +7 -0
  69. package/dist/init.d.ts +0 -3
  70. package/dist/init.js +14 -15
  71. package/dist/names.d.ts +3 -0
  72. package/dist/names.js +8 -0
  73. package/dist/paths.d.ts +29 -0
  74. package/dist/paths.js +25 -0
  75. package/dist/publish/discover.js +2 -1
  76. package/dist/publish/publish.d.ts +21 -5
  77. package/dist/publish/publish.js +46 -12
  78. package/dist/publish/snapshot.d.ts +4 -1
  79. package/dist/publish/snapshot.js +8 -3
  80. package/dist/snapshots.d.ts +11 -0
  81. package/dist/snapshots.js +20 -3
  82. package/dist/studio.js +8 -8
  83. package/package.json +2 -2
  84. package/assets/studio/assets/index-Cn03lgc3.js +0 -110
  85. package/dist/command-args.d.ts +0 -9
  86. package/dist/command-args.js +0 -56
  87. package/dist/diff.d.ts +0 -61
  88. package/dist/diff.js +0 -244
@@ -0,0 +1,8 @@
1
+ import { type HandlerResult } from './result.js';
2
+ export declare const MAX_ASSET_BYTES: number;
3
+ /** store image bytes under their content hash; identical drops dedupe to one file */
4
+ export declare function saveAsset(diagramsDir: string, contentType: string, bytes: Buffer): Promise<HandlerResult>;
5
+ export declare function readAsset(diagramsDir: string, name: string): Promise<HandlerResult & {
6
+ bytes?: Buffer;
7
+ contentType?: string;
8
+ }>;
@@ -0,0 +1,54 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { access, mkdir, readFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { IMAGE_REF } from '@diagc/core/internal';
5
+ import { writeFileAtomic } from '../atomic-write.js';
6
+ import { refuse } from './result.js';
7
+ // Keys here must stay in sync with IMAGE_REF's extension group (@diagc/core) —
8
+ // an extension accepted by the regex but missing here would 404 on read.
9
+ const ASSET_EXT = {
10
+ 'image/png': 'png',
11
+ 'image/jpeg': 'jpg',
12
+ 'image/svg+xml': 'svg',
13
+ 'image/webp': 'webp',
14
+ 'image/gif': 'gif',
15
+ };
16
+ const ASSET_TYPE = Object.fromEntries(Object.entries(ASSET_EXT).map(([t, e]) => [e, t]));
17
+ export const MAX_ASSET_BYTES = 5 * 1024 * 1024;
18
+ /** store image bytes under their content hash; identical drops dedupe to one file */
19
+ export async function saveAsset(diagramsDir, contentType, bytes) {
20
+ const ext = ASSET_EXT[contentType.split(';')[0]?.trim() ?? ''];
21
+ if (ext === undefined) {
22
+ return refuse(400, `Unsupported image type '${contentType}'`);
23
+ }
24
+ if (bytes.length === 0 || bytes.length > MAX_ASSET_BYTES) {
25
+ return refuse(400, `Image must be 1 byte to ${MAX_ASSET_BYTES / 1024 / 1024} MB`);
26
+ }
27
+ const name = `${createHash('sha256').update(bytes).digest('hex').slice(0, 12)}.${ext}`;
28
+ const target = path.join(diagramsDir, 'assets', name);
29
+ await mkdir(path.dirname(target), { recursive: true });
30
+ try {
31
+ await access(target); // already stored — content hash guarantees same bytes
32
+ }
33
+ catch {
34
+ await writeFileAtomic(target, bytes);
35
+ }
36
+ return { status: 200, body: { name } };
37
+ }
38
+ export async function readAsset(diagramsDir, name) {
39
+ if (!IMAGE_REF.test(name))
40
+ return refuse(400, `Unsafe asset name '${name}'`);
41
+ try {
42
+ const bytes = await readFile(path.join(diagramsDir, 'assets', name));
43
+ const ext = name.split('.').at(-1) ?? '';
44
+ return {
45
+ status: 200,
46
+ body: null,
47
+ bytes,
48
+ contentType: ASSET_TYPE[ext === 'jpeg' ? 'jpg' : ext] ?? 'application/octet-stream',
49
+ };
50
+ }
51
+ catch {
52
+ return refuse(404, `No asset '${name}'`);
53
+ }
54
+ }
@@ -0,0 +1,27 @@
1
+ import { type DiagramModel } from '@diagc/core/internal';
2
+ import { type HandlerResult } from './result.js';
3
+ export interface DiagramEntry {
4
+ name: string;
5
+ model: DiagramModel | null;
6
+ issues: {
7
+ message: string;
8
+ }[];
9
+ editable: boolean;
10
+ }
11
+ /** Render-ready models for the studio boot: JSON sources (editable) served from
12
+ * `diagramsDir`, compiled TS artifacts from `artifactsDir`. A source shadows its
13
+ * artifact so unsaved-compile staleness never shows. */
14
+ export declare function listDiagramModels(diagramsDir: string, artifactsDir: string): Promise<HandlerResult>;
15
+ /** the JSON source (+ sibling layout and drawings) of a designer-owned diagram — the studio
16
+ * reads these directly so it never depends on a compile watcher for its own files */
17
+ export declare function readDiagram(diagramsDir: string, name: string): Promise<HandlerResult>;
18
+ /** Composed read of an editable source — the studio's view-refresh after a
19
+ * save. Sources without includes pass through untouched. */
20
+ export declare function readComposedDiagram(diagramsDir: string, name: string): Promise<HandlerResult>;
21
+ export declare function saveDiagram(diagramsDir: string, name: string, payload: unknown): Promise<HandlerResult>;
22
+ /** Move a designer-owned diagram (and its sibling layout, if any) to a new name,
23
+ * rewriting the model's id to match so the file stays self-consistent. */
24
+ export declare function renameDiagram(diagramsDir: string, from: string, to: string): Promise<HandlerResult>;
25
+ /** Promote a JSON-owned diagram to a generated `.diagram.ts`. See `ejectDiagram`
26
+ * for the round-trip guarantee; this just maps its failure codes to statuses. */
27
+ export declare function ejectDiagramSource(diagramsDir: string, artifactsDir: string, name: string): Promise<HandlerResult>;
@@ -0,0 +1,269 @@
1
+ import { access, mkdir, readFile, rename, unlink } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { composeIncludes, errMessage, validate } from '@diagc/core/internal';
4
+ import { writeFileAtomic } from '../atomic-write.js';
5
+ import { EjectError, ejectDiagram } from '../eject.js';
6
+ import { isSafeName } from '../names.js';
7
+ import { lockedResolverFor } from '../snapshots.js';
8
+ import { walkDiagramJson } from './files.js';
9
+ import { refuse } from './result.js';
10
+ const hasIncludes = (m) => m !== null && Array.isArray(m.nodes) && m.nodes.some((n) => n.include !== undefined);
11
+ /** Render-ready models for the studio boot: JSON sources (editable) served from
12
+ * `diagramsDir`, compiled TS artifacts from `artifactsDir`. A source shadows its
13
+ * artifact so unsaved-compile staleness never shows. */
14
+ export async function listDiagramModels(diagramsDir, artifactsDir) {
15
+ const sourceNames = new Set(await walkDiagramJson(diagramsDir));
16
+ const artifactNames = await walkDiagramJson(artifactsDir);
17
+ const all = [...new Set([...sourceNames, ...artifactNames])].sort();
18
+ const diagrams = [];
19
+ for (const name of all) {
20
+ const isSource = sourceNames.has(name);
21
+ // Every read and save refuses a name isSafeName refuses, so such a source is shown but not offered for editing.
22
+ const editable = isSource && isSafeName(name);
23
+ const file = isSource
24
+ ? path.join(diagramsDir, `${name}.diagram.json`)
25
+ : path.join(artifactsDir, `${name}.diagram.json`);
26
+ let model = null;
27
+ const issues = [];
28
+ if (isSource && !editable) {
29
+ issues.push({
30
+ message: `'${name}' is read-only here: the studio saves names of lowercase letters, digits, '-' and '/', none ending in /rename, /eject or /composed. Rename the file to edit it.`,
31
+ });
32
+ }
33
+ try {
34
+ model = JSON.parse(await readFile(file, 'utf8'));
35
+ }
36
+ catch {
37
+ issues.push({ message: `Could not read model for '${name}'` });
38
+ }
39
+ if (isSource && hasIncludes(model))
40
+ model = await composedForList(model, file, diagramsDir, issues);
41
+ diagrams.push({ name, model, issues, editable });
42
+ }
43
+ return { status: 200, body: { diagrams } };
44
+ }
45
+ /** `model` with its includes expanded for the list, or `model` itself when they
46
+ * cannot be, with what went wrong added to `issues`. */
47
+ async function composedForList(model, file, diagramsDir, issues) {
48
+ try {
49
+ const { model: composed, warnings } = await composeIncludes(model, path.resolve(file), lockedResolverFor(diagramsDir));
50
+ // compileFile refuses an invalid composed result outright, because the
51
+ // renderer assumes a validated model — an id collision
52
+ // between an umbrella-declared node and a namespaced include can pass
53
+ // composeIncludes (which only grafts) while still being invalid, so
54
+ // this must be checked here too, not just on compile.
55
+ const validationIssues = validate(composed);
56
+ if (validationIssues.length > 0) {
57
+ // fall back to the raw model (include nodes as placeholders); it
58
+ // still renders, unlike the unsound composed result
59
+ issues.push(...validationIssues);
60
+ return model;
61
+ }
62
+ for (const w of warnings)
63
+ issues.push({ message: w });
64
+ return composed;
65
+ }
66
+ catch (e) {
67
+ // the raw model still renders (include nodes as placeholders); say why
68
+ issues.push({ message: `Includes not expanded: ${errMessage(e)}` });
69
+ return model;
70
+ }
71
+ }
72
+ /** the JSON source (+ sibling layout and drawings) of a designer-owned diagram — the studio
73
+ * reads these directly so it never depends on a compile watcher for its own files */
74
+ export async function readDiagram(diagramsDir, name) {
75
+ if (!isSafeName(name))
76
+ return refuse(400, `Unsafe name '${name}'`);
77
+ let model;
78
+ try {
79
+ model = JSON.parse(await readFile(path.join(diagramsDir, `${name}.diagram.json`), 'utf8'));
80
+ }
81
+ catch {
82
+ return refuse(404, `No diagram source '${name}'`);
83
+ }
84
+ let layout;
85
+ try {
86
+ layout = JSON.parse(await readFile(path.join(diagramsDir, `${name}.layout.json`), 'utf8'));
87
+ }
88
+ catch {
89
+ layout = undefined;
90
+ }
91
+ let drawings;
92
+ try {
93
+ drawings = JSON.parse(await readFile(path.join(diagramsDir, `${name}.drawings.json`), 'utf8'));
94
+ }
95
+ catch {
96
+ drawings = undefined;
97
+ }
98
+ return {
99
+ status: 200,
100
+ body: {
101
+ model,
102
+ ...(layout !== undefined ? { layout } : {}),
103
+ ...(drawings !== undefined ? { drawings } : {}),
104
+ },
105
+ };
106
+ }
107
+ /** Composed read of an editable source — the studio's view-refresh after a
108
+ * save. Sources without includes pass through untouched. */
109
+ export async function readComposedDiagram(diagramsDir, name) {
110
+ if (!isSafeName(name))
111
+ return refuse(400, `Unsafe name '${name}'`);
112
+ const file = path.join(diagramsDir, `${name}.diagram.json`);
113
+ let model;
114
+ try {
115
+ model = JSON.parse(await readFile(file, 'utf8'));
116
+ }
117
+ catch {
118
+ return refuse(404, `No diagram source '${name}'`);
119
+ }
120
+ if (!hasIncludes(model))
121
+ return { status: 200, body: { model } };
122
+ try {
123
+ const { model: composed, warnings } = await composeIncludes(model, path.resolve(file), lockedResolverFor(diagramsDir));
124
+ // Same soundness check as composedForList: a composed model that fails
125
+ // validation must never reach the renderer, so refuse it like a failed
126
+ // compose instead of returning 200 with an unsound model.
127
+ const issues = validate(composed);
128
+ if (issues.length > 0)
129
+ return { status: 409, body: { issues } };
130
+ return { status: 200, body: { model: composed, ...(warnings.length > 0 ? { warnings } : {}) } };
131
+ }
132
+ catch (e) {
133
+ return refuse(409, errMessage(e));
134
+ }
135
+ }
136
+ /** A 409 when `<name>.diagram.ts` exists: that diagram is TypeScript's, and a JSON
137
+ * twin beside it would compile to the same artifact, the last compile winning. */
138
+ async function ownedByTs(diagramsDir, name) {
139
+ const tsPath = path.join(diagramsDir, `${name}.diagram.ts`);
140
+ try {
141
+ await access(tsPath);
142
+ }
143
+ catch {
144
+ return undefined;
145
+ }
146
+ return refuse(409, `'${name}' is already TypeScript-owned (${tsPath})`);
147
+ }
148
+ export async function saveDiagram(diagramsDir, name, payload) {
149
+ if (!isSafeName(name))
150
+ return refuse(400, `Unsafe name '${name}'`);
151
+ const owned = await ownedByTs(diagramsDir, name);
152
+ if (owned !== undefined)
153
+ return owned;
154
+ const p = payload;
155
+ const arraysOk = p !== null &&
156
+ p.version === 1 &&
157
+ Array.isArray(p.nodes) &&
158
+ Array.isArray(p.containment) &&
159
+ Array.isArray(p.relations) &&
160
+ Array.isArray(p.layers) &&
161
+ Array.isArray(p.planes);
162
+ if (!arraysOk) {
163
+ return refuse(400, 'Not a version-1 diagram model');
164
+ }
165
+ const issues = validate(payload);
166
+ if (issues.length > 0)
167
+ return { status: 400, body: { issues } };
168
+ const target = path.join(diagramsDir, `${name}.diagram.json`);
169
+ await mkdir(path.dirname(target), { recursive: true });
170
+ await writeFileAtomic(target, `${JSON.stringify(payload, null, 2)}\n`);
171
+ return { status: 200, body: { ok: true } };
172
+ }
173
+ /** Move a designer-owned diagram (and its sibling layout, if any) to a new name,
174
+ * rewriting the model's id to match so the file stays self-consistent. */
175
+ export async function renameDiagram(diagramsDir, from, to) {
176
+ if (!isSafeName(from) || !isSafeName(to)) {
177
+ return refuse(400, `Unsafe name '${isSafeName(from) ? to : from}'`);
178
+ }
179
+ if (from === to)
180
+ return refuse(400, 'New name is the same as the old');
181
+ const fromDiagram = path.join(diagramsDir, `${from}.diagram.json`);
182
+ const toDiagram = path.join(diagramsDir, `${to}.diagram.json`);
183
+ let raw;
184
+ try {
185
+ raw = await readFile(fromDiagram, 'utf8');
186
+ }
187
+ catch {
188
+ return refuse(404, `No diagram source '${from}'`);
189
+ }
190
+ try {
191
+ await access(toDiagram);
192
+ return refuse(409, `A diagram named '${to}' already exists`);
193
+ }
194
+ catch {
195
+ /* target free — proceed */
196
+ }
197
+ const owned = await ownedByTs(diagramsDir, to);
198
+ if (owned !== undefined)
199
+ return owned;
200
+ let model;
201
+ try {
202
+ model = JSON.parse(raw);
203
+ }
204
+ catch {
205
+ return refuse(400, `Corrupt diagram source '${from}'`);
206
+ }
207
+ // The id follows the file. The name is the diagram's title, so it follows only
208
+ // when it was the id, a title nobody set.
209
+ if (model['name'] === model['id'])
210
+ model['name'] = to;
211
+ model['id'] = to;
212
+ await mkdir(path.dirname(toDiagram), { recursive: true });
213
+ // Sidecars first, the source last, so the old name keeps its source until every
214
+ // other step has worked. A failure undoes the steps before it, in reverse, and
215
+ // the error answers 500.
216
+ const moved = [];
217
+ let written = false;
218
+ try {
219
+ for (const sidecar of ['layout', 'drawings']) {
220
+ const move = [
221
+ path.join(diagramsDir, `${from}.${sidecar}.json`),
222
+ path.join(diagramsDir, `${to}.${sidecar}.json`),
223
+ ];
224
+ if (await moveIfPresent(...move))
225
+ moved.push(move);
226
+ }
227
+ await writeFileAtomic(toDiagram, `${JSON.stringify(model, null, 2)}\n`);
228
+ written = true;
229
+ await unlink(fromDiagram);
230
+ }
231
+ catch (e) {
232
+ if (written)
233
+ await unlink(toDiagram).catch(() => { });
234
+ for (const [src, dst] of moved.reverse())
235
+ await rename(dst, src).catch(() => { });
236
+ throw e;
237
+ }
238
+ return { status: 200, body: { ok: true } };
239
+ }
240
+ /** `rename(src, dst)`, false when there is no `src` to move: a diagram need not have
241
+ * a sidecar. Any other failure throws. */
242
+ async function moveIfPresent(src, dst) {
243
+ try {
244
+ await rename(src, dst);
245
+ return true;
246
+ }
247
+ catch (e) {
248
+ if (e.code === 'ENOENT')
249
+ return false;
250
+ throw e;
251
+ }
252
+ }
253
+ /** Promote a JSON-owned diagram to a generated `.diagram.ts`. See `ejectDiagram`
254
+ * for the round-trip guarantee; this just maps its failure codes to statuses. */
255
+ export async function ejectDiagramSource(diagramsDir, artifactsDir, name) {
256
+ if (!isSafeName(name))
257
+ return refuse(400, `Unsafe name '${name}'`);
258
+ try {
259
+ await ejectDiagram(diagramsDir, artifactsDir, name);
260
+ return { status: 200, body: { ok: true } };
261
+ }
262
+ catch (e) {
263
+ if (e instanceof EjectError) {
264
+ const status = e.code === 'not-found' ? 404 : e.code === 'invalid' ? 400 : 409;
265
+ return refuse(status, e.message);
266
+ }
267
+ throw e;
268
+ }
269
+ }
@@ -0,0 +1,7 @@
1
+ /** Recursively collect every file under `dir` whose name ends in `suffix`,
2
+ * posix-joined relative to `dir` with the suffix stripped. Missing dir → [].
3
+ * Shared by the diagram-source and layout-overlay walks. */
4
+ export declare function walkFiles(dir: string, suffix: string): Promise<string[]>;
5
+ /** Recursively collect `<name>` for every `*.diagram.json` under `dir`
6
+ * (posix-joined, suffix stripped). Missing dir → []. */
7
+ export declare function walkDiagramJson(dir: string): Promise<string[]>;
@@ -0,0 +1,30 @@
1
+ import { readdir } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ /** Recursively collect every file under `dir` whose name ends in `suffix`,
4
+ * posix-joined relative to `dir` with the suffix stripped. Missing dir → [].
5
+ * Shared by the diagram-source and layout-overlay walks. */
6
+ export async function walkFiles(dir, suffix) {
7
+ const names = [];
8
+ const walk = async (d, prefix) => {
9
+ let entries;
10
+ try {
11
+ entries = await readdir(d, { withFileTypes: true });
12
+ }
13
+ catch {
14
+ return;
15
+ }
16
+ for (const e of entries) {
17
+ if (e.isDirectory())
18
+ await walk(path.join(d, e.name), `${prefix}${e.name}/`);
19
+ else if (e.name.endsWith(suffix))
20
+ names.push(`${prefix}${e.name.slice(0, -suffix.length)}`);
21
+ }
22
+ };
23
+ await walk(dir, '');
24
+ return names;
25
+ }
26
+ /** Recursively collect `<name>` for every `*.diagram.json` under `dir`
27
+ * (posix-joined, suffix stripped). Missing dir → []. */
28
+ export async function walkDiagramJson(dir) {
29
+ return walkFiles(dir, '.diagram.json');
30
+ }
@@ -1,62 +1,7 @@
1
- import { type DiagramModel } from '@diagc/core/internal';
2
- import { isSafeName } from '../names.js';
3
- export interface HandlerResult {
4
- status: number;
5
- body: unknown;
6
- }
7
- export { isSafeName };
8
- /** Recursively collect every file under `dir` whose name ends in `suffix`,
9
- * posix-joined relative to `dir` with the suffix stripped. Missing dir → [].
10
- * Shared by the diagram-source and layout-overlay walks. */
11
- export declare function walkFiles(dir: string, suffix: string): Promise<string[]>;
12
- /** Recursively collect `<name>` for every `*.diagram.json` under `dir`
13
- * (posix-joined, suffix stripped). Missing dir → []. */
14
- export declare function walkDiagramJson(dir: string): Promise<string[]>;
15
- export interface DiagramEntry {
16
- name: string;
17
- model: DiagramModel | null;
18
- issues: {
19
- message: string;
20
- }[];
21
- editable: boolean;
22
- }
23
- /** Render-ready models for the studio boot: JSON sources (editable) served from
24
- * `diagramsDir`, compiled TS artifacts from `artifactsDir`. A source shadows its
25
- * artifact so unsaved-compile staleness never shows. */
26
- export declare function listDiagramModels(diagramsDir: string, artifactsDir: string): Promise<HandlerResult>;
27
- /** All layout overlays under `diagramsDir`, keyed by diagram name. Corrupt
28
- * overlays are skipped, never fatal. */
29
- export declare function listLayouts(diagramsDir: string): Promise<HandlerResult>;
30
- /** All drawings sidecars under `diagramsDir`, keyed by diagram name. Corrupt
31
- * files are skipped, never fatal — same contract as listLayouts. */
32
- export declare function listDrawings(diagramsDir: string): Promise<HandlerResult>;
33
- /** the JSON source (+ sibling layout and drawings) of a designer-owned diagram — the studio
34
- * reads these directly so it never depends on a compile watcher for its own files */
35
- export declare function readDiagram(diagramsDir: string, name: string): Promise<HandlerResult>;
36
- /** Composed read of an editable source — the studio's view-refresh after a
37
- * save. Sources without includes pass through untouched. */
38
- export declare function readComposedDiagram(diagramsDir: string, name: string): Promise<HandlerResult>;
39
- export declare function saveDiagram(diagramsDir: string, name: string, payload: unknown): Promise<HandlerResult>;
40
- /** Move a designer-owned diagram (and its sibling layout, if any) to a new name,
41
- * rewriting the model's id to match so the file stays self-consistent. */
42
- export declare function renameDiagram(diagramsDir: string, from: string, to: string): Promise<HandlerResult>;
43
- /** Promote a JSON-owned diagram to a generated `.diagram.ts`. See `ejectDiagram`
44
- * for the round-trip guarantee; this just maps its failure codes to statuses. */
45
- export declare function ejectDiagramSource(diagramsDir: string, artifactsDir: string, name: string): Promise<HandlerResult>;
46
- export declare function saveLayout(diagramsDir: string, name: string, payload: unknown): Promise<HandlerResult>;
47
- /** Persist the drawings sidecar. An overlay in which no bucket holds a stroke
48
- * DELETES the file instead of writing it: a diagram that never had drawings
49
- * must never grow an empty `<name>.drawings.json`, and erasing the last stroke
50
- * should leave the tree as it was. */
51
- export declare function saveDrawings(diagramsDir: string, name: string, payload: unknown): Promise<HandlerResult>;
52
- export declare function readLibrary(diagramsDir: string): Promise<HandlerResult>;
53
- /** Persist the whole user library. Validates internal consistency only — bundled
54
- * packs are merged client-side and never written here. */
55
- export declare function saveLibrary(diagramsDir: string, payload: unknown): Promise<HandlerResult>;
56
- export declare const MAX_ASSET_BYTES: number;
57
- /** store image bytes under their content hash; identical drops dedupe to one file */
58
- export declare function saveAsset(diagramsDir: string, contentType: string, bytes: Buffer): Promise<HandlerResult>;
59
- export declare function readAsset(diagramsDir: string, name: string): Promise<HandlerResult & {
60
- bytes?: Buffer;
61
- contentType?: string;
62
- }>;
1
+ export { MAX_ASSET_BYTES, readAsset, saveAsset } from './assets.js';
2
+ export { ejectDiagramSource, listDiagramModels, readComposedDiagram, readDiagram, renameDiagram, saveDiagram, type DiagramEntry, } from './diagrams.js';
3
+ export { walkDiagramJson, walkFiles } from './files.js';
4
+ export { readLibrary, saveLibrary } from './library.js';
5
+ export type { HandlerResult } from './result.js';
6
+ export { listDrawings, listLayouts, saveDrawings, saveLayout } from './sidecars.js';
7
+ export { isSafeName } from '../names.js';