@graview/ship 0.1.0 → 0.1.2
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 +54 -6
- package/dist/browser-adapter.d.ts +9 -9
- package/dist/browser-adapter.d.ts.map +1 -1
- package/dist/browser-adapter.js +6 -3
- package/dist/browser-adapter.js.map +1 -1
- package/dist/browser.d.ts +10 -6
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +4 -2
- package/dist/browser.js.map +1 -1
- package/dist/cli.d.ts +17 -7
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +41 -7
- package/dist/cli.js.map +1 -1
- package/dist/export.d.ts +27 -2
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +38 -5
- package/dist/export.js.map +1 -1
- package/dist/file-adapter.d.ts +8 -8
- package/dist/file-adapter.d.ts.map +1 -1
- package/dist/file-adapter.js +58 -8
- package/dist/file-adapter.js.map +1 -1
- package/dist/handler.d.ts +162 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +585 -0
- package/dist/handler.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.d.ts.map +1 -1
- package/dist/health.js +5 -1
- package/dist/health.js.map +1 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/live.d.ts +150 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +44 -0
- package/dist/live.js.map +1 -0
- package/dist/meta.d.ts +13 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +2 -0
- package/dist/meta.js.map +1 -0
- package/dist/open-store.d.ts +56 -7
- package/dist/open-store.d.ts.map +1 -1
- package/dist/open-store.js +141 -12
- package/dist/open-store.js.map +1 -1
- package/dist/remote.d.ts +93 -12
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +446 -76
- package/dist/remote.js.map +1 -1
- package/dist/runtime.d.ts +32 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +21 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seat-headers.d.ts +20 -0
- package/dist/seat-headers.d.ts.map +1 -0
- package/dist/seat-headers.js +20 -0
- package/dist/seat-headers.js.map +1 -0
- package/dist/serve.d.ts +15 -107
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +82 -217
- package/dist/serve.js.map +1 -1
- package/dist/source-edit.d.ts.map +1 -1
- package/dist/source-edit.js +6 -1
- package/dist/source-edit.js.map +1 -1
- package/dist/steps.d.ts +43 -0
- package/dist/steps.d.ts.map +1 -1
- package/dist/steps.js +69 -0
- package/dist/steps.js.map +1 -1
- package/dist/websocket.d.ts +14 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +155 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +6 -2
package/dist/file-adapter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, rmSync, writeFileSync, appendFileSync, existsSync } from "node:fs";
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, appendFileSync, existsSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
export function createFileAdapter(root) {
|
|
4
4
|
const place = (scope, file) => join(root, scope, file);
|
|
@@ -11,6 +11,26 @@ export function createFileAdapter(root) {
|
|
|
11
11
|
mkdirSync(dirname(path), { recursive: true });
|
|
12
12
|
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
13
13
|
};
|
|
14
|
+
/** Written whole and moved into place, so a crash leaves the old file or the new one. */
|
|
15
|
+
const replace = (path, text) => {
|
|
16
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
17
|
+
writeFileSync(`${path}.tmp`, text);
|
|
18
|
+
renameSync(`${path}.tmp`, path);
|
|
19
|
+
};
|
|
20
|
+
const lines = (path) => existsSync(path)
|
|
21
|
+
? readFileSync(path, "utf8")
|
|
22
|
+
.split("\n")
|
|
23
|
+
.filter((line) => line.trim().length > 0)
|
|
24
|
+
.map((line) => JSON.parse(line))
|
|
25
|
+
: [];
|
|
26
|
+
const jsonl = (ops) => ops.map((op) => `${JSON.stringify(op)}\n`).join("");
|
|
27
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
28
|
+
/** The seq the log begins at: its checkpoint's, once compacted (FR-23). */
|
|
29
|
+
const horizonOf = (scope) => [...(read(place(scope, "epochs.json")) ?? [])].reverse().find((epoch) => epoch.horizon)?.seq ?? 0;
|
|
30
|
+
const archiveOf = (scope) => ({
|
|
31
|
+
ops: lines(place(scope, join("archive", "log.jsonl"))),
|
|
32
|
+
epochs: read(place(scope, join("archive", "epochs.json"))) ?? [],
|
|
33
|
+
});
|
|
14
34
|
return {
|
|
15
35
|
name: "file",
|
|
16
36
|
root,
|
|
@@ -24,13 +44,15 @@ export function createFileAdapter(root) {
|
|
|
24
44
|
rmSync(join(root, scope), { recursive: true, force: true });
|
|
25
45
|
},
|
|
26
46
|
async loadLog(scope) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
/*
|
|
48
|
+
* From the horizon on. A compaction writes the archive, then the
|
|
49
|
+
* checkpoint, then the tail: a crash before the tail is rewritten
|
|
50
|
+
* leaves ops behind the checkpoint here, already archived, and they
|
|
51
|
+
* are not loaded twice.
|
|
52
|
+
*/
|
|
53
|
+
const horizon = horizonOf(scope);
|
|
54
|
+
const ops = lines(place(scope, "log.jsonl"));
|
|
55
|
+
return horizon > 0 ? ops.filter((op) => op.seq >= horizon) : ops;
|
|
34
56
|
},
|
|
35
57
|
async appendOps(scope, ops) {
|
|
36
58
|
if (ops.length === 0)
|
|
@@ -39,6 +61,34 @@ export function createFileAdapter(root) {
|
|
|
39
61
|
mkdirSync(dirname(path), { recursive: true });
|
|
40
62
|
appendFileSync(path, ops.map((op) => JSON.stringify(op)).join("\n") + "\n");
|
|
41
63
|
},
|
|
64
|
+
async loadEpochs(scope) {
|
|
65
|
+
return read(place(scope, "epochs.json")) ?? [];
|
|
66
|
+
},
|
|
67
|
+
async saveEpochs(scope, epochs) {
|
|
68
|
+
write(place(scope, "epochs.json"), epochs);
|
|
69
|
+
},
|
|
70
|
+
async compact(scope, checkpoint) {
|
|
71
|
+
const at = checkpoint.seq;
|
|
72
|
+
const ops = lines(place(scope, "log.jsonl"));
|
|
73
|
+
const epochs = read(place(scope, "epochs.json")) ?? [];
|
|
74
|
+
const held = archiveOf(scope);
|
|
75
|
+
// Keyed, so a compaction run again after a crash archives nothing twice.
|
|
76
|
+
const archivedOps = new Map(held.ops.map((op) => [op.seq, op]));
|
|
77
|
+
for (const op of ops)
|
|
78
|
+
if (op.seq < at)
|
|
79
|
+
archivedOps.set(op.seq, op);
|
|
80
|
+
const archivedEpochs = new Map(held.epochs.map((epoch) => [JSON.stringify(epoch), epoch]));
|
|
81
|
+
for (const epoch of epochs)
|
|
82
|
+
if (epoch.seq < at)
|
|
83
|
+
archivedEpochs.set(JSON.stringify(epoch), epoch);
|
|
84
|
+
replace(place(scope, join("archive", "log.jsonl")), jsonl([...archivedOps.values()].sort((a, b) => a.seq - b.seq)));
|
|
85
|
+
replace(place(scope, join("archive", "epochs.json")), json([...archivedEpochs.values()]));
|
|
86
|
+
replace(place(scope, "epochs.json"), json([{ ...checkpoint, horizon: true }, ...epochs.filter((epoch) => epoch.seq > at)]));
|
|
87
|
+
replace(place(scope, "log.jsonl"), jsonl(ops.filter((op) => op.seq >= at)));
|
|
88
|
+
},
|
|
89
|
+
async loadArchive(scope) {
|
|
90
|
+
return archiveOf(scope);
|
|
91
|
+
},
|
|
42
92
|
loadMeta(scope) {
|
|
43
93
|
return read(place(scope, "meta.json"));
|
|
44
94
|
},
|
package/dist/file-adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-adapter.js","sourceRoot":"","sources":["../src/file-adapter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,WAAW,CAAC,KAAK;YACrB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,QAAQ,CAAC,KAAK;YACZ,OAAO,IAAI,CAAa,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,QAAQ,CAAC,KAAK,EAAE,IAAI;YAClB,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { type AnySchema, type GraviewApp, type PersistenceAdapter, type Presence, type Principal, type Store } from "@graview/core";
|
|
2
|
+
import { type LiveConnection, type LiveSocket } from "./live.js";
|
|
3
|
+
import { type OpenedStore } from "./open-store.js";
|
|
4
|
+
import { SEAT_HEADERS } from "./seat-headers.js";
|
|
5
|
+
import type { GraphSnapshot } from "./snapshot.js";
|
|
6
|
+
/**
|
|
7
|
+
* THE STORE, BEHIND ANY RUNTIME'S FETCH — and the op log is the wire (FR-09).
|
|
8
|
+
*
|
|
9
|
+
* Every route is one function from a `Request` to a `Response`, which is
|
|
10
|
+
* what a Cloudflare Worker, a Durable Object, Deno, Bun and a service worker
|
|
11
|
+
* all call a handler. `serveStore` is a thin `node:http` wrapper around it;
|
|
12
|
+
* nothing in this module reaches a `node:` builtin, so a host that runs
|
|
13
|
+
* somewhere other than Node serves the same wire without a fork.
|
|
14
|
+
*
|
|
15
|
+
* What is deliberately NOT here: a second way to change the graph. A client
|
|
16
|
+
* sends CALLS, not primitives; the handler applies them through an ordinary
|
|
17
|
+
* `Store` under the principal the request carries, so the policy judges
|
|
18
|
+
* them exactly as it judges them in a browser, the invariants run, and the
|
|
19
|
+
* op that comes back is the same shape the browser would have made. A
|
|
20
|
+
* client that could post primitives would be a client that could write past
|
|
21
|
+
* every rule the app declares.
|
|
22
|
+
*
|
|
23
|
+
* The protocol is four routes:
|
|
24
|
+
*
|
|
25
|
+
* GET /graview/state the graph, the log, the stored version and the modules on
|
|
26
|
+
* POST /graview/ops calls in, the ops they produced out — or `undo`, batches to take back
|
|
27
|
+
* GET /graview/since?seq=N the ops appended after N — everyone else's
|
|
28
|
+
* GET /graview/health ship's own report, plus where the data is
|
|
29
|
+
*
|
|
30
|
+
* And three for WHO IS HERE, which is not the op log and never touches it:
|
|
31
|
+
*
|
|
32
|
+
* POST /graview/here say where you are; answers with who else is, and the ops since `seq`
|
|
33
|
+
* GET /graview/who who is here right now
|
|
34
|
+
* POST /graview/leave say you have gone
|
|
35
|
+
*
|
|
36
|
+
* Presence lives in a map inside this closure with a time to live — not in
|
|
37
|
+
* the store, not in the adapter, not in the log. A tab that dies without a
|
|
38
|
+
* word is gone after three missed heartbeats.
|
|
39
|
+
*
|
|
40
|
+
* Polling is the floor, on purpose: a poll is a thing a person can
|
|
41
|
+
* reproduce with `curl`, and a thing every runtime can answer. Beside it,
|
|
42
|
+
* `connect` serves the live wire (FR-05, `./live.ts`) to whatever socket a
|
|
43
|
+
* host hands it, and `GET /graview/live` names it on the wire.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* THE WIRE, AS A CONTRACT. Every route the handler answers, in one place a
|
|
47
|
+
* test pins and a README repeats: what a host in front of this — Graview
|
|
48
|
+
* Cloud, or anybody's — must keep answering for `openRemote`, `graview mcp
|
|
49
|
+
* --remote-url` and `graview apply --remote-url` to work unchanged. What a
|
|
50
|
+
* host adds (who a bearer token is, which tenant, how much) goes in
|
|
51
|
+
* `seatOf` and around these routes, never inside them.
|
|
52
|
+
*/
|
|
53
|
+
export declare const WIRE: readonly [{
|
|
54
|
+
readonly method: "GET";
|
|
55
|
+
readonly path: "/graview/state";
|
|
56
|
+
readonly says: "the graph, the log, the stored version and the modules on";
|
|
57
|
+
}, {
|
|
58
|
+
readonly method: "POST";
|
|
59
|
+
readonly path: "/graview/ops";
|
|
60
|
+
readonly says: "calls in, the ops they produced out — or `undo`, batches to take back; 409 with the policy's sentence when refused";
|
|
61
|
+
}, {
|
|
62
|
+
readonly method: "GET";
|
|
63
|
+
readonly path: "/graview/since";
|
|
64
|
+
readonly says: "the ops appended after ?seq=N — everyone else's";
|
|
65
|
+
}, {
|
|
66
|
+
readonly method: "GET";
|
|
67
|
+
readonly path: "/graview/health";
|
|
68
|
+
readonly says: "ship's own report, plus where the data is";
|
|
69
|
+
}, {
|
|
70
|
+
readonly method: "GET";
|
|
71
|
+
readonly path: "/graview/export";
|
|
72
|
+
readonly says: "the whole store as one bundle, the way out";
|
|
73
|
+
}, {
|
|
74
|
+
readonly method: "POST";
|
|
75
|
+
readonly path: "/graview/here";
|
|
76
|
+
readonly says: "say where you are; answers with who else is, and the ops since `seq`";
|
|
77
|
+
}, {
|
|
78
|
+
readonly method: "GET";
|
|
79
|
+
readonly path: "/graview/who";
|
|
80
|
+
readonly says: "who is here right now";
|
|
81
|
+
}, {
|
|
82
|
+
readonly method: "POST";
|
|
83
|
+
readonly path: "/graview/leave";
|
|
84
|
+
readonly says: "say you have gone";
|
|
85
|
+
}, {
|
|
86
|
+
readonly method: "GET";
|
|
87
|
+
readonly path: "/graview/live";
|
|
88
|
+
readonly says: "the live wire: a WebSocket of hello/welcome, call/undo/ack/refused/conflict, ops and presence; 426 to a plain request";
|
|
89
|
+
}];
|
|
90
|
+
export { SEAT_HEADERS };
|
|
91
|
+
export interface StoreHandlerOptions<S extends AnySchema> {
|
|
92
|
+
readonly app: GraviewApp<S>;
|
|
93
|
+
/** Where the graph lives: any `PersistenceAdapter` — a file, SQLite, Durable Object storage. */
|
|
94
|
+
readonly adapter: PersistenceAdapter<string>;
|
|
95
|
+
/** What to put in an empty store on first start. */
|
|
96
|
+
readonly seed?: GraphSnapshot;
|
|
97
|
+
readonly scope?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Who a request is. The host's to say — from a session, a bearer token,
|
|
100
|
+
* whatever it authenticates with — and the store judges every call under
|
|
101
|
+
* the principal it returns. It may answer a promise, for a host that
|
|
102
|
+
* verifies a token with `crypto.subtle`.
|
|
103
|
+
*/
|
|
104
|
+
readonly seatOf?: (request: Request) => Principal | Promise<Principal>;
|
|
105
|
+
/**
|
|
106
|
+
* BELIEVE THE SEAT HEADERS (`SEAT_HEADERS`) — off by default (FR-06).
|
|
107
|
+
*
|
|
108
|
+
* A header is a claim, and anyone who could reach a served store used to
|
|
109
|
+
* claim any seat by sending one, and every remote agent was recorded as
|
|
110
|
+
* a person. A store that neither trusts headers nor is given a `seatOf`
|
|
111
|
+
* answers 401: it cannot say who is asking. `graview serve` turns this on
|
|
112
|
+
* for a server bound to loopback only, and says so.
|
|
113
|
+
*/
|
|
114
|
+
readonly trustSeatHeaders?: boolean;
|
|
115
|
+
/** Where the data is, for the health report to say out loud. */
|
|
116
|
+
readonly where?: string;
|
|
117
|
+
/** How long a presence stands after its last word. Three heartbeats by default. */
|
|
118
|
+
readonly presenceTtlMs?: number;
|
|
119
|
+
/**
|
|
120
|
+
* THE MODULES THIS WORKSPACE HAS ON (FR-12) — usually what it pays for.
|
|
121
|
+
* Handed to `openStore`, which records a change from what the store's
|
|
122
|
+
* log last said as an op; absent, the log's word stands (every module,
|
|
123
|
+
* when it never said one). A module off has its acts refused and its
|
|
124
|
+
* kinds kept from every route, as a sight keeps a record.
|
|
125
|
+
*/
|
|
126
|
+
readonly enabledModules?: readonly string[];
|
|
127
|
+
}
|
|
128
|
+
export interface StoreHandler<S extends AnySchema> {
|
|
129
|
+
readonly store: Store<S>;
|
|
130
|
+
readonly opened: OpenedStore<S>;
|
|
131
|
+
/** Every WIRE route: a `Request` in, a `Response` out. Bound, so it can be handed on as it is. */
|
|
132
|
+
readonly handle: (request: Request) => Promise<Response>;
|
|
133
|
+
/**
|
|
134
|
+
* THE LIVE WIRE, ON ANY SOCKET (FR-05). Hand it the upgrade `Request`
|
|
135
|
+
* (the seat is read from it, as on every route) and a way to send text
|
|
136
|
+
* down the socket; it answers with the connection to hand each message
|
|
137
|
+
* the client sends and the close, or with the `Response` refusing it (a
|
|
138
|
+
* 401 when it cannot say who is asking). A Worker or Durable Object
|
|
139
|
+
* attaches a `WebSocketPair`'s server end here; `serveStore` attaches
|
|
140
|
+
* Node's upgrade.
|
|
141
|
+
*/
|
|
142
|
+
readonly connect: (request: Request, socket: LiveSocket) => Promise<LiveConnection | Response>;
|
|
143
|
+
/** Writes what is pending and lets the adapter go. */
|
|
144
|
+
close(): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
/** A seat read from a request's headers — only ever when the host trusts them. */
|
|
147
|
+
export declare function seatFromHeaders(request: Request): Principal;
|
|
148
|
+
/**
|
|
149
|
+
* WHO IS HERE, AS ONE SEAT MAY BE TOLD (FR-02). Somebody whose own record
|
|
150
|
+
* the seat may not see is not shown to it at all; anybody else is, without
|
|
151
|
+
* where they stand or what they hover when that names a record the seat
|
|
152
|
+
* may not see. A participant whose id is no record is shown as they are.
|
|
153
|
+
*/
|
|
154
|
+
export declare function presenceSeenBy(who: readonly Presence[], sees: (id: string) => boolean): Presence[];
|
|
155
|
+
/**
|
|
156
|
+
* Open the store and answer the wire for it. The migration runs HERE, once,
|
|
157
|
+
* against the stored graph — which is the whole reason a server is the
|
|
158
|
+
* honest place for it. A browser that migrates its own copy migrates it once
|
|
159
|
+
* per browser; a server that migrates the roster migrates the roster.
|
|
160
|
+
*/
|
|
161
|
+
export declare function createStoreHandler<S extends AnySchema>(options: StoreHandlerOptions<S>): Promise<StoreHandler<S>>;
|
|
162
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,KAAK,SAAS,EAGd,KAAK,UAAU,EAGf,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAuD,KAAK,cAAc,EAA0B,KAAK,UAA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