@graview/ship 0.1.29 → 0.1.32

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 (53) hide show
  1. package/README.md +25 -0
  2. package/dist/browser.d.ts +3 -1
  3. package/dist/browser.d.ts.map +1 -1
  4. package/dist/browser.js +2 -0
  5. package/dist/browser.js.map +1 -1
  6. package/dist/cli.d.ts +21 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +99 -10
  9. package/dist/cli.js.map +1 -1
  10. package/dist/connections-file.d.ts +6 -0
  11. package/dist/connections-file.d.ts.map +1 -0
  12. package/dist/connections-file.js +35 -0
  13. package/dist/connections-file.js.map +1 -0
  14. package/dist/connections.d.ts +74 -0
  15. package/dist/connections.d.ts.map +1 -0
  16. package/dist/connections.js +160 -0
  17. package/dist/connections.js.map +1 -0
  18. package/dist/file-subscriptions.d.ts +15 -0
  19. package/dist/file-subscriptions.d.ts.map +1 -0
  20. package/dist/file-subscriptions.js +65 -0
  21. package/dist/file-subscriptions.js.map +1 -0
  22. package/dist/handler.d.ts +20 -1
  23. package/dist/handler.d.ts.map +1 -1
  24. package/dist/handler.js +46 -1
  25. package/dist/handler.js.map +1 -1
  26. package/dist/index.d.ts +10 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +7 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/remote.d.ts +25 -0
  31. package/dist/remote.d.ts.map +1 -1
  32. package/dist/remote.js +3 -2
  33. package/dist/remote.js.map +1 -1
  34. package/dist/runtime.d.ts +5 -1
  35. package/dist/runtime.d.ts.map +1 -1
  36. package/dist/runtime.js +3 -0
  37. package/dist/runtime.js.map +1 -1
  38. package/dist/serve-preview.d.ts +9 -0
  39. package/dist/serve-preview.d.ts.map +1 -1
  40. package/dist/serve-preview.js +38 -4
  41. package/dist/serve-preview.js.map +1 -1
  42. package/dist/serve.d.ts.map +1 -1
  43. package/dist/serve.js +24 -3
  44. package/dist/serve.js.map +1 -1
  45. package/dist/store-hold.d.ts +53 -0
  46. package/dist/store-hold.d.ts.map +1 -0
  47. package/dist/store-hold.js +113 -0
  48. package/dist/store-hold.js.map +1 -0
  49. package/dist/subscriptions.d.ts +51 -0
  50. package/dist/subscriptions.d.ts.map +1 -0
  51. package/dist/subscriptions.js +94 -0
  52. package/dist/subscriptions.js.map +1 -0
  53. package/package.json +2 -2
@@ -0,0 +1,53 @@
1
+ /**
2
+ * ONE WRITER AT A TIME ON A STORE ON DISK.
3
+ *
4
+ * A running `graview preview` or `graview serve` holds the graph in memory
5
+ * and writes it back as it changes. Anything else that wrote to the same
6
+ * folder while it ran — `graview sync-seed --apply`, `graview apply`, a
7
+ * second preview — was invisible to its open pages, and the server's next
8
+ * write could put the old records back over it. Both commands said they
9
+ * had succeeded, so the loss was silent.
10
+ *
11
+ * So a process that writes a store says so in a file beside it, and every
12
+ * other writer reads that file first and refuses in a sentence that names
13
+ * who holds it and how to go on. A hold left by a process that has since
14
+ * died is noticed (its pid answers nobody) and taken over; nothing has to
15
+ * be deleted by hand after a crash.
16
+ */
17
+ export interface StoreHolder {
18
+ /** The command holding it: `preview`, `serve`, `mcp`, `apply`, `sync-seed`. */
19
+ readonly command: string;
20
+ readonly pid: number;
21
+ /** Where its server answers, once it listens: the way to act through it instead. */
22
+ readonly url?: string;
23
+ readonly since: string;
24
+ }
25
+ export interface StoreHold {
26
+ readonly file: string;
27
+ /** Says where the holder now answers, once its server listens. */
28
+ serving(url: string): void;
29
+ release(): void;
30
+ }
31
+ /** The file that says who holds a store: inside a data folder, or beside a SQLite file. */
32
+ export declare function holdFileOf(where: string, kind: "folder" | "file"): string;
33
+ /** Who holds the store whose hold file is `file` right now, or null: a hold whose process is gone is nobody's. */
34
+ export declare function heldBy(file: string): StoreHolder | null;
35
+ /**
36
+ * The refusal, as a sentence a person can act on: who holds the store,
37
+ * why writing beside it would lose something, and what to do instead.
38
+ */
39
+ export declare function sayHeld(holder: StoreHolder, where: string, wanted: string, options?: {
40
+ readonly remote?: boolean;
41
+ }): string;
42
+ /**
43
+ * Takes the store whose hold file is `file` for this process, or says who
44
+ * has it.
45
+ *
46
+ * The file is created exclusively, so two writers starting at once cannot
47
+ * both believe they won; a stale hold is replaced. Released on `release()`
48
+ * and, failing that, when the process exits.
49
+ */
50
+ export declare function holdStore(file: string, command: string): StoreHold | {
51
+ readonly heldBy: StoreHolder;
52
+ };
53
+ //# sourceMappingURL=store-hold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-hold.d.ts","sourceRoot":"","sources":["../src/store-hold.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,WAAW;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,2FAA2F;AAC3F,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAEzE;AAaD,kHAAkH;AAClH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CASvD;AAUD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,CAQ/H;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CA4CrG"}
@@ -0,0 +1,113 @@
1
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ /** The file that says who holds a store: inside a data folder, or beside a SQLite file. */
4
+ export function holdFileOf(where, kind) {
5
+ return kind === "folder" ? join(where, "graview.lock") : `${where}.graview.lock`;
6
+ }
7
+ const alive = (pid) => {
8
+ if (pid === process.pid)
9
+ return true;
10
+ try {
11
+ process.kill(pid, 0);
12
+ return true;
13
+ }
14
+ catch (error) {
15
+ // EPERM: it exists, and it is somebody else's.
16
+ return error.code === "EPERM";
17
+ }
18
+ };
19
+ /** Who holds the store whose hold file is `file` right now, or null: a hold whose process is gone is nobody's. */
20
+ export function heldBy(file) {
21
+ if (!existsSync(file))
22
+ return null;
23
+ let holder;
24
+ try {
25
+ holder = JSON.parse(readFileSync(file, "utf8"));
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ return typeof holder.pid === "number" && alive(holder.pid) ? holder : null;
31
+ }
32
+ const portOf = (url) => {
33
+ try {
34
+ return `:${new URL(url).port}`;
35
+ }
36
+ catch {
37
+ return url;
38
+ }
39
+ };
40
+ /**
41
+ * The refusal, as a sentence a person can act on: who holds the store,
42
+ * why writing beside it would lose something, and what to do instead.
43
+ */
44
+ export function sayHeld(holder, where, wanted, options = {}) {
45
+ const who = `a ${holder.command}${holder.url ? ` on ${portOf(holder.url)}` : ""} (pid ${holder.pid}, since ${holder.since})`;
46
+ const server = holder.command === "preview" || holder.command === "serve";
47
+ const through = options.remote && holder.url ? ` Or act through it instead: add --remote-url ${holder.url} in place of --data or --sqlite.` : "";
48
+ return (`${who} holds ${where}. ${wanted} would not reach the pages it has open, and its next write could put the old records back, so nothing was written.\n` +
49
+ ` Stop the ${holder.command} (Ctrl-C in its shell) and run this again${server ? `, then start the ${holder.command} once more` : ""}.${through}\n`);
50
+ }
51
+ /**
52
+ * Takes the store whose hold file is `file` for this process, or says who
53
+ * has it.
54
+ *
55
+ * The file is created exclusively, so two writers starting at once cannot
56
+ * both believe they won; a stale hold is replaced. Released on `release()`
57
+ * and, failing that, when the process exits.
58
+ */
59
+ export function holdStore(file, command) {
60
+ mkdirSync(dirname(file), { recursive: true });
61
+ const mine = { command, pid: process.pid, since: new Date().toISOString() };
62
+ const write = (holder, flag) => writeFileSync(file, `${JSON.stringify(holder, null, 2)}\n`, { flag });
63
+ for (let attempt = 0;; attempt++) {
64
+ try {
65
+ write(mine, "wx");
66
+ break;
67
+ }
68
+ catch (error) {
69
+ if (error.code !== "EEXIST")
70
+ throw error;
71
+ const holder = heldBy(file);
72
+ if (holder)
73
+ return { heldBy: holder };
74
+ if (attempt > 0)
75
+ throw error;
76
+ // Stale: whoever wrote it is gone. Take it over and try once more.
77
+ try {
78
+ unlinkSync(file);
79
+ }
80
+ catch {
81
+ /* someone else took it over first; the second attempt says who */
82
+ }
83
+ }
84
+ }
85
+ let held = true;
86
+ let current = mine;
87
+ const release = () => {
88
+ if (!held)
89
+ return;
90
+ held = false;
91
+ process.off("exit", release);
92
+ try {
93
+ const there = JSON.parse(readFileSync(file, "utf8"));
94
+ if (there.pid === process.pid)
95
+ unlinkSync(file);
96
+ }
97
+ catch {
98
+ /* already gone */
99
+ }
100
+ };
101
+ process.on("exit", release);
102
+ return {
103
+ file,
104
+ serving(url) {
105
+ if (!held)
106
+ return;
107
+ current = { ...current, url };
108
+ write(current, "w");
109
+ },
110
+ release,
111
+ };
112
+ }
113
+ //# sourceMappingURL=store-hold.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-hold.js","sourceRoot":"","sources":["../src/store-hold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAA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ACH,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,OAAO;QACL,IAAI;QACJ,OAAO,CAAC,GAAG;YACT,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC;YAC9B,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC;QACD,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { type AnySchema, type Principal, type Store, type SubscriptionStore, type SubscriptionWhen } from "@graview/core";
2
+ /**
3
+ * SUBSCRIPTIONS ON THE WIRE (Roadmap f-notify-subscriptions): one route,
4
+ * `/graview/subscriptions`, answering only the asking seat's own — read
5
+ * with `GET`, kept and taken away with `POST { add }` and `POST { remove }`.
6
+ * A subscription is the person's, never their agent's: a chat that
7
+ * subscribes subscribes its person (`subscriberOf`), and a seat the host
8
+ * knows by no id cannot subscribe — there would be nobody to tell.
9
+ *
10
+ * Nothing here reaches a `node:` builtin, so the handler serves it in any
11
+ * runtime; `remoteSubscriptions` is the client half, a `SubscriptionStore`
12
+ * a page or `graview mcp --remote-url` hands its surfaces.
13
+ */
14
+ export declare const SUBSCRIPTIONS_PATH = "/graview/subscriptions";
15
+ /** What `POST /graview/subscriptions` takes. */
16
+ export type SubscriptionsPost = {
17
+ readonly add: {
18
+ readonly when: SubscriptionWhen;
19
+ readonly alsoMine?: boolean;
20
+ };
21
+ } | {
22
+ readonly remove: string;
23
+ };
24
+ /** An answer of the route: a status and a body. */
25
+ export interface SubscriptionsAnswer {
26
+ readonly status: number;
27
+ readonly body: unknown;
28
+ }
29
+ /** The asking seat's subscriptions, or one kept or taken away for it. */
30
+ export declare function answerSubscriptions(method: string, body: unknown, seat: Principal, where: {
31
+ readonly store: Store<AnySchema>;
32
+ readonly app: string;
33
+ readonly subscriptions: SubscriptionStore;
34
+ }): Promise<SubscriptionsAnswer>;
35
+ export interface RemoteSubscriptionsOptions {
36
+ /** Where the server is, as `openRemote` is told. */
37
+ readonly url: string;
38
+ /** Who is asking: sent as the seat headers, which a server believes only where it trusts them. */
39
+ readonly principal?: Principal;
40
+ /** A host's own headers — its `authorization` — sent with every request. */
41
+ readonly headers?: Readonly<Record<string, string>>;
42
+ readonly fetch?: typeof fetch;
43
+ }
44
+ /**
45
+ * THE ASKING SEAT'S SUBSCRIPTIONS ON A SERVED STORE: a `SubscriptionStore`
46
+ * over `/graview/subscriptions`. `list` answers the seat's own whatever it
47
+ * is asked; `add` keeps the draft's `when` and `alsoMine` for the seat (the
48
+ * server says who); `remove` takes one of the seat's away.
49
+ */
50
+ export declare function remoteSubscriptions(options: RemoteSubscriptionsOptions): SubscriptionStore;
51
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../src/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAqB,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAI3J;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAE3D,gDAAgD;AAChD,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjJ,mDAAmD;AACnD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAID,yEAAyE;AACzE,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,SAAS,EACf,KAAK,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAA;CAAE,GAC3G,OAAO,CAAC,mBAAmB,CAAC,CA0B9B;AAED,MAAM,WAAW,0BAA0B;IACzC,oDAAoD;IACpD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,iBAAiB,CAiC1F"}
@@ -0,0 +1,94 @@
1
+ import { subscriberOf } from "@graview/core";
2
+ import { subscriptionProblem } from "@graview/core/subscriptions";
3
+ import { seatHeaders } from "./remote.js";
4
+ /**
5
+ * SUBSCRIPTIONS ON THE WIRE (Roadmap f-notify-subscriptions): one route,
6
+ * `/graview/subscriptions`, answering only the asking seat's own — read
7
+ * with `GET`, kept and taken away with `POST { add }` and `POST { remove }`.
8
+ * A subscription is the person's, never their agent's: a chat that
9
+ * subscribes subscribes its person (`subscriberOf`), and a seat the host
10
+ * knows by no id cannot subscribe — there would be nobody to tell.
11
+ *
12
+ * Nothing here reaches a `node:` builtin, so the handler serves it in any
13
+ * runtime; `remoteSubscriptions` is the client half, a `SubscriptionStore`
14
+ * a page or `graview mcp --remote-url` hands its surfaces.
15
+ */
16
+ export const SUBSCRIPTIONS_PATH = "/graview/subscriptions";
17
+ const NOBODY = "Only somebody this store knows by id can be told of changes.";
18
+ /** The asking seat's subscriptions, or one kept or taken away for it. */
19
+ export async function answerSubscriptions(method, body, seat, where) {
20
+ const who = subscriberOf(seat);
21
+ if (method === "GET") {
22
+ if (who.id === undefined)
23
+ return { status: 200, body: { subscriptions: [] } };
24
+ const mine = (await where.subscriptions.list(who.id)).filter((one) => one.app === where.app);
25
+ return { status: 200, body: { subscriptions: mine } };
26
+ }
27
+ if (method !== "POST")
28
+ return { status: 405, body: { error: `${SUBSCRIPTIONS_PATH} is read with GET and changed with POST.`, reason: "invalid" } };
29
+ if (who.id === undefined)
30
+ return { status: 403, body: { error: NOBODY, reason: "forbidden" } };
31
+ const asked = (body ?? {});
32
+ if (typeof asked.remove === "string") {
33
+ const mine = await where.subscriptions.list(who.id);
34
+ // Only your own: a seat takes away its subscription, never somebody else's — and cannot tell one is there.
35
+ if (!mine.some((one) => one.id === asked.remove))
36
+ return { status: 200, body: { removed: false } };
37
+ return { status: 200, body: { removed: await where.subscriptions.remove(asked.remove) } };
38
+ }
39
+ const when = asked.add?.when;
40
+ if (!when || typeof when !== "object" || !["act", "created", "changed", "reaches"].includes(when.on)) {
41
+ return { status: 400, body: { error: "Say what to be told of: { add: { when: { on: \"act\" | \"created\" | \"changed\" | \"reaches\", … } } }, or { remove: <id> }.", reason: "invalid" } };
42
+ }
43
+ // Judged as the person sees the app: a record they cannot see is not one they can be told about.
44
+ const seen = where.store.seenBy(who);
45
+ const problem = subscriptionProblem({ schema: seen.schema, allMutations: () => where.store.allMutations(), graph: seen.graph }, when);
46
+ if (problem)
47
+ return { status: 400, body: { error: problem, reason: "invalid" } };
48
+ const kept = await where.subscriptions.add({ who, app: where.app, when, ...(asked.add?.alsoMine === true ? { alsoMine: true } : {}) });
49
+ return { status: 201, body: { subscription: kept } };
50
+ }
51
+ /**
52
+ * THE ASKING SEAT'S SUBSCRIPTIONS ON A SERVED STORE: a `SubscriptionStore`
53
+ * over `/graview/subscriptions`. `list` answers the seat's own whatever it
54
+ * is asked; `add` keeps the draft's `when` and `alsoMine` for the seat (the
55
+ * server says who); `remove` takes one of the seat's away.
56
+ */
57
+ export function remoteSubscriptions(options) {
58
+ const doFetch = options.fetch ?? fetch;
59
+ const base = options.url.replace(/\/$/, "");
60
+ const headers = { "content-type": "application/json", ...(options.principal ? seatHeaders(options.principal) : {}), ...(options.headers ?? {}) };
61
+ const listeners = new Set();
62
+ const changed = () => {
63
+ for (const listener of listeners)
64
+ listener();
65
+ };
66
+ const call = async (method, body) => {
67
+ const response = await doFetch(`${base}${SUBSCRIPTIONS_PATH}`, { method, headers, ...(body !== undefined ? { body: JSON.stringify(body) } : {}) });
68
+ const answer = (await response.json());
69
+ if (!response.ok)
70
+ throw new Error(answer.error ?? `The store answered ${response.status}.`);
71
+ return answer;
72
+ };
73
+ return {
74
+ async list() {
75
+ return (await call("GET")).subscriptions;
76
+ },
77
+ async add(draft) {
78
+ const { subscription } = await call("POST", { add: { when: draft.when, ...(draft.alsoMine ? { alsoMine: true } : {}) } });
79
+ changed();
80
+ return subscription;
81
+ },
82
+ async remove(id) {
83
+ const { removed } = await call("POST", { remove: id });
84
+ if (removed)
85
+ changed();
86
+ return removed;
87
+ },
88
+ onChange(listener) {
89
+ listeners.add(listener);
90
+ return () => listeners.delete(listener);
91
+ },
92
+ };
93
+ }
94
+ //# sourceMappingURL=subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../src/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgH,MAAM,eAAe,CAAC;AAC3J,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAW3D,MAAM,MAAM,GAAG,8DAA8D,CAAC;AAE9E,yEAAyE;AACz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  "name": "@graview/ship",
3
- "version": "0.1.29",
3
+ "version": "0.1.32",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@graview/core": "0.1.29"
30
+ "@graview/core": "0.1.32"
31
31
  },
32
32
  "devDependencies": {
33
33
  "zod": "^4.6.5"