@graview/ship 0.1.0 → 0.1.3
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 +165 -9
- 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 +271 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +581 -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 +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/live-protocol.d.ts +208 -0
- package/dist/live-protocol.d.ts.map +1 -0
- package/dist/live-protocol.js +380 -0
- package/dist/live-protocol.js.map +1 -0
- package/dist/live.d.ts +266 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +74 -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 +237 -13
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +1033 -88
- package/dist/remote.js.map +1 -1
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +22 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seat-headers.d.ts +26 -0
- package/dist/seat-headers.d.ts.map +1 -0
- package/dist/seat-headers.js +26 -0
- package/dist/seat-headers.js.map +1 -0
- package/dist/serve.d.ts +16 -106
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +95 -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 +163 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +6 -2
package/dist/health.js
CHANGED
|
@@ -3,13 +3,17 @@ export function health(store, options = {}) {
|
|
|
3
3
|
const dangling = [...store.graph.allEdges()]
|
|
4
4
|
.filter((edge) => !ids.has(edge.from) || !ids.has(edge.to))
|
|
5
5
|
.map((edge) => `${edge.kind}:${edge.from}->${edge.to}`);
|
|
6
|
-
const
|
|
6
|
+
const all = store.violations();
|
|
7
|
+
const violations = all.length;
|
|
7
8
|
return {
|
|
8
9
|
ok: dangling.length === 0,
|
|
9
10
|
nodes: ids.size,
|
|
10
11
|
edges: [...store.graph.allEdges()].length,
|
|
11
12
|
violations,
|
|
13
|
+
couldNotJudge: all.filter((violation) => violation.status === "could-not-judge").length,
|
|
14
|
+
overBudget: all.filter((violation) => violation.status === "over-budget").length,
|
|
12
15
|
danglingEdges: dangling,
|
|
16
|
+
findings: store.findings().length,
|
|
13
17
|
at: (options.now ?? (() => new Date().toISOString()))(),
|
|
14
18
|
};
|
|
15
19
|
}
|
package/dist/health.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AA0BA,MAAM,UAAU,MAAM,CACpB,KAAe,EACf,UAA2C,EAAE;IAE7C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAC1D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC;IAC9B,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;QACzB,KAAK,EAAE,GAAG,CAAC,IAAI;QACf,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM;QACzC,UAAU;QACV,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,KAAK,iBAAiB,CAAC,CAAC,MAAM;QACvF,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,KAAK,aAAa,CAAC,CAAC,MAAM;QAChF,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM;QACjC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE;KACxD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,24 +3,31 @@ export type { FileAdapter } from "./file-adapter.js";
|
|
|
3
3
|
export { browserStartsFresh, createBrowserAdapter, forgetFreshParam, freshHref, } from "./browser-adapter.js";
|
|
4
4
|
export type { BrowserAdapter, BrowserAdapterOptions, StorageLike } from "./browser-adapter.js";
|
|
5
5
|
export { migrateSnapshot, pendingMigrations } from "./migrations.js";
|
|
6
|
-
export { primitivesFor, primitivesForSteps, sayStep, stepsMigration } from "./steps.js";
|
|
6
|
+
export { countSteps, primitivesFor, primitivesForSteps, sayStep, stepsMigration } from "./steps.js";
|
|
7
7
|
export { applySteps, contentOperation, SEED_SYNC_AUTHOR, seedSteps } from "./sync-seed.js";
|
|
8
8
|
export type { SeedSyncOptions } from "./sync-seed.js";
|
|
9
|
-
export type { MigrationStep } from "./steps.js";
|
|
9
|
+
export type { MigrationStep, StepCount } from "./steps.js";
|
|
10
10
|
export type { MigrationRun } from "./migrations.js";
|
|
11
11
|
export { openStore } from "./open-store.js";
|
|
12
|
-
export type { OpenStoreOptions, OpenedStore } from "./open-store.js";
|
|
12
|
+
export type { Compaction, OpenStoreOptions, OpenedStore } from "./open-store.js";
|
|
13
13
|
export { applyToSnapshot } from "./snapshot.js";
|
|
14
14
|
export type { GraphSnapshot } from "./snapshot.js";
|
|
15
15
|
export { assertBundle, exportBundle } from "./export.js";
|
|
16
|
-
export type { AppBundle } from "./export.js";
|
|
16
|
+
export type { AppBundle, ExportOptions } from "./export.js";
|
|
17
|
+
export type { StoredMeta } from "./meta.js";
|
|
17
18
|
export { health } from "./health.js";
|
|
18
19
|
export type { HealthReport } from "./health.js";
|
|
19
|
-
export { openRemote } from "./remote.js";
|
|
20
|
+
export { openRemote, RemoteRefusedError, seatHeaders } from "./remote.js";
|
|
20
21
|
export { createBroadcastPresence, presenceChannelName } from "./presence.js";
|
|
21
22
|
export type { BroadcastPresenceOptions, ChannelLike } from "./presence.js";
|
|
22
|
-
export type { RemoteOptions, RemoteStore } from "./remote.js";
|
|
23
|
-
export {
|
|
23
|
+
export type { LiveSocketLike, RemoteBackoff, RemoteConflict, RemoteCounters, RemoteOptions, RemoteRefusal, RemoteStatus, RemoteStore } from "./remote.js";
|
|
24
|
+
export { conflictSentence, LIVE_PATH, LIVE_SUBPROTOCOL, LIVE_WIRE, liveSubprotocol, REFUSAL_REASONS } from "./live.js";
|
|
25
|
+
export type { Limit, LimitAnswer, LimitAsked, LiveClientMessage, LiveConnection, LiveServerMessage, LiveSocket, RefusalReason, WireRefusal } from "./live.js";
|
|
26
|
+
export { createStoreHandler, presenceSeenBy } from "./handler.js";
|
|
27
|
+
export type { AdapterStoreHandlerOptions, DeclarationChange, HeldStoreHandlerOptions, StoreHandler, StoreHandlerOptions } from "./handler.js";
|
|
28
|
+
export { announcePresence, liveProtocol, presenceFrom, visitorPresence } from "./live-protocol.js";
|
|
29
|
+
export type { LivePeer, LiveProtocol, LiveProtocolOptions, LiveReceived, LiveSocketState } from "./live-protocol.js";
|
|
30
|
+
export { SEAT_HEADERS, seatFromHeaders, serveStore, WIRE } from "./serve.js";
|
|
24
31
|
export type { ServeOptions, ServedStore } from "./serve.js";
|
|
25
32
|
export { backendFrom, serve, SERVE_USAGE, syncSeed } from "./cli.js";
|
|
26
33
|
export type { StoreBackend } from "./cli.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3F,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB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EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC9I,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACnG,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
export { createFileAdapter } from "./file-adapter.js";
|
|
2
2
|
export { browserStartsFresh, createBrowserAdapter, forgetFreshParam, freshHref, } from "./browser-adapter.js";
|
|
3
3
|
export { migrateSnapshot, pendingMigrations } from "./migrations.js";
|
|
4
|
-
export { primitivesFor, primitivesForSteps, sayStep, stepsMigration } from "./steps.js";
|
|
4
|
+
export { countSteps, primitivesFor, primitivesForSteps, sayStep, stepsMigration } from "./steps.js";
|
|
5
5
|
export { applySteps, contentOperation, SEED_SYNC_AUTHOR, seedSteps } from "./sync-seed.js";
|
|
6
6
|
export { openStore } from "./open-store.js";
|
|
7
7
|
export { applyToSnapshot } from "./snapshot.js";
|
|
8
8
|
export { assertBundle, exportBundle } from "./export.js";
|
|
9
9
|
export { health } from "./health.js";
|
|
10
|
-
export { openRemote } from "./remote.js";
|
|
10
|
+
export { openRemote, RemoteRefusedError, seatHeaders } from "./remote.js";
|
|
11
11
|
export { createBroadcastPresence, presenceChannelName } from "./presence.js";
|
|
12
|
-
export {
|
|
12
|
+
export { conflictSentence, LIVE_PATH, LIVE_SUBPROTOCOL, LIVE_WIRE, liveSubprotocol, REFUSAL_REASONS } from "./live.js";
|
|
13
|
+
export { createStoreHandler, presenceSeenBy } from "./handler.js";
|
|
14
|
+
export { announcePresence, liveProtocol, presenceFrom, visitorPresence } from "./live-protocol.js";
|
|
15
|
+
export { SEAT_HEADERS, seatFromHeaders, serveStore, WIRE } from "./serve.js";
|
|
13
16
|
export { backendFrom, serve, SERVE_USAGE, syncSeed } from "./cli.js";
|
|
14
17
|
export { assertPhotoFits, photosUsed, storageBytes, PhotoTooLarge, PHOTO_BUDGET_BYTES, PHOTO_MAX_BYTES, } from "./photos.js";
|
|
15
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAG7E,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEvH,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEnG,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAErE,OAAO,EACL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,eAAe,GAChB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { type AnySchema, type Author, type FieldConflict, type MutationCall, type Operation, type Presence, type Principal, type Store } from "@graview/core";
|
|
2
|
+
import { type Limit } from "./live.js";
|
|
3
|
+
/**
|
|
4
|
+
* THE LIVE WIRE AS FUNCTIONS OVER STATE THE HOST HOLDS (FR-41, FR-42).
|
|
5
|
+
*
|
|
6
|
+
* `connect()` used to keep everything about a socket in a closure: who it
|
|
7
|
+
* is, the last seq it was sent, where it said it stood. A Durable Object
|
|
8
|
+
* that hibernates wakes on the next message with no closure left, so it
|
|
9
|
+
* could not serve ship's wire without staying awake. Here the protocol is
|
|
10
|
+
* a handful of functions over two things a host already keeps:
|
|
11
|
+
*
|
|
12
|
+
* - a `Store` it opened, migrates, heals and meters itself, and
|
|
13
|
+
* - one `LiveSocketState` per socket, plain JSON — what a Durable Object
|
|
14
|
+
* puts in `serializeAttachment` and reads back on a wake.
|
|
15
|
+
*
|
|
16
|
+
* Everything else `liveProtocol` holds is derived from the store and may
|
|
17
|
+
* be thrown away at any moment: make it again on the wake and the next
|
|
18
|
+
* message is answered exactly as it would have been.
|
|
19
|
+
*
|
|
20
|
+
* `createStoreHandler`'s `connect` is this, with the state in memory: one
|
|
21
|
+
* implementation, two ways to hold it.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* ONE SOCKET, AS A HOST KEEPS IT BETWEEN MESSAGES. Plain JSON on purpose:
|
|
25
|
+
* it survives `JSON.stringify` and `JSON.parse` unchanged, which is all a
|
|
26
|
+
* hibernating host can promise.
|
|
27
|
+
*/
|
|
28
|
+
export interface LiveSocketState {
|
|
29
|
+
/** Who this socket is: read once, from its upgrade, by the host's `seatOf`. */
|
|
30
|
+
readonly seat: Principal;
|
|
31
|
+
/** What its calls come through, recorded on every op they make: the host's word, never the client's (FR-52). */
|
|
32
|
+
readonly via: string;
|
|
33
|
+
/** The last seq this socket has been sent. Absent until it says hello: a call before that is refused. */
|
|
34
|
+
cursor?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Its presence key: built from the seat at hello (or at its first `here`),
|
|
37
|
+
* said back in the welcome, and the key every later `here` on this
|
|
38
|
+
* socket is held under — never taken from the client (FR-47).
|
|
39
|
+
*/
|
|
40
|
+
participant?: string;
|
|
41
|
+
/** The build its hello said it runs (FR-44): the client's word, kept for the host to count, never judged. */
|
|
42
|
+
build?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The call this socket was told is busy (FR-45), and when (epoch ms) it
|
|
45
|
+
* may come again. Every other call is busy too until it does, so nothing
|
|
46
|
+
* made after it overtakes it.
|
|
47
|
+
*/
|
|
48
|
+
held?: {
|
|
49
|
+
readonly cid: string;
|
|
50
|
+
readonly until: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** A socket as the protocol is handed it: its state, and a way to send it text. */
|
|
54
|
+
export interface LivePeer extends LiveSocketState {
|
|
55
|
+
send(text: string): void;
|
|
56
|
+
}
|
|
57
|
+
/** What one message did, for the host to keep and pass on. */
|
|
58
|
+
export interface LiveReceived {
|
|
59
|
+
/** The socket's cursor now; the protocol has also set it on the peer it was handed. Absent before hello. */
|
|
60
|
+
readonly cursor?: number;
|
|
61
|
+
/**
|
|
62
|
+
* The socket said where it is (`here`): its presence as the server built
|
|
63
|
+
* it, for the host to hold and tell the others; or `null` — it said
|
|
64
|
+
* `bye`, and the host forgets it. Absent: nothing changed.
|
|
65
|
+
*/
|
|
66
|
+
readonly presence?: Presence | null;
|
|
67
|
+
/** The ops this message landed in the store, unredacted, for the host to `publish` to every other socket. */
|
|
68
|
+
readonly landed?: readonly Operation[];
|
|
69
|
+
}
|
|
70
|
+
export interface LiveProtocolOptions<S extends AnySchema> {
|
|
71
|
+
/** The store the wire serves: the host's own (FR-42). */
|
|
72
|
+
readonly store: Store<S>;
|
|
73
|
+
/** The declaration's version, said in a welcome's state. 1 when unsaid. */
|
|
74
|
+
readonly version?: number;
|
|
75
|
+
/** What opening the store migrated, said in a welcome's state. */
|
|
76
|
+
readonly migrated?: readonly string[];
|
|
77
|
+
/** Resolves once what landed is durable: an ack waits for it. */
|
|
78
|
+
readonly flush?: () => Promise<void>;
|
|
79
|
+
/** The host's build, an opaque string said in every welcome (FR-44): a client on another one is told once and keeps working. */
|
|
80
|
+
readonly build?: string;
|
|
81
|
+
/**
|
|
82
|
+
* THE LOWEST PROTOCOL SERVED (FR-44). A hello on an older one is answered
|
|
83
|
+
* `reload` and nothing else: its calls are refused until it says hello
|
|
84
|
+
* on one served. Absent, every protocol is served.
|
|
85
|
+
*/
|
|
86
|
+
readonly minProtocol?: number;
|
|
87
|
+
/**
|
|
88
|
+
* THE HOST'S LIMITS (FR-45, FR-46), asked of every call and undo before
|
|
89
|
+
* it is judged: busy (`{ retryAfter }`, try again), refused at a hard cap
|
|
90
|
+
* (`{ refuse }`, reason `limit`), or nothing.
|
|
91
|
+
*/
|
|
92
|
+
readonly limit?: Limit;
|
|
93
|
+
}
|
|
94
|
+
export interface LiveProtocol<S extends AnySchema> {
|
|
95
|
+
readonly store: Store<S>;
|
|
96
|
+
/** The state a socket starts with: its seat and its channel, and no cursor until it says hello. */
|
|
97
|
+
open(seat: Principal, via: string): LiveSocketState;
|
|
98
|
+
/**
|
|
99
|
+
* Hand it one message the client sent. It answers down `peer.send`,
|
|
100
|
+
* moves `peer.cursor` (and `peer.participant`) as it goes, and says what
|
|
101
|
+
* the host should keep and pass on. `who` is everybody the host has
|
|
102
|
+
* here, for the presence a welcome is followed by.
|
|
103
|
+
*
|
|
104
|
+
* Messages on one socket are handed in the order they came, each after
|
|
105
|
+
* the one before has resolved. A host that publishes while a receive
|
|
106
|
+
* awaits its flush reads the cursor off the same peer object, or
|
|
107
|
+
* leaves the receiving socket out: its ops reach it in the ack.
|
|
108
|
+
*/
|
|
109
|
+
receive(peer: LivePeer, text: string, who?: readonly Presence[]): Promise<LiveReceived>;
|
|
110
|
+
/**
|
|
111
|
+
* Ops that landed, down every socket that has said hello and has not had
|
|
112
|
+
* them, each as its own seat may see them (FR-02, FR-16): in seq order,
|
|
113
|
+
* none skipped, caught up from the peer's own cursor. Sets each peer's
|
|
114
|
+
* cursor; the host keeps it.
|
|
115
|
+
*/
|
|
116
|
+
publish(ops: readonly Operation[], peers: Iterable<LivePeer>): void;
|
|
117
|
+
/** Who is here, told to every socket that has said hello: as its seat may be told it, and without itself. */
|
|
118
|
+
tell(who: readonly Presence[], peers: Iterable<LivePeer>): void;
|
|
119
|
+
/**
|
|
120
|
+
* THE DECLARATION CHANGED (FR-43), and this protocol is the one over the
|
|
121
|
+
* store migrated to it. Every socket that has said hello is told
|
|
122
|
+
* `{ t: "declaration", version }` and its cursor is forgotten: a seq of
|
|
123
|
+
* the old store means nothing on the new one, so nothing is pushed and
|
|
124
|
+
* no call is served until it says hello again. The host keeps the
|
|
125
|
+
* cursors as it keeps them after `receive`.
|
|
126
|
+
*/
|
|
127
|
+
declared(peers: Iterable<LivePeer>): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A PRESENCE AS THE SERVER BUILDS IT. Keyed by the seat — a client cannot
|
|
131
|
+
* claim to be somebody else — with only the session taken from what it
|
|
132
|
+
* said, and stamped with the server's clock. What it is, and for whom it
|
|
133
|
+
* acts, are the seat's (FR-47): a claimed `kind`, `onBehalfOf` or `until`
|
|
134
|
+
* is dropped, and the seat's name stands over a claimed one. `participant`
|
|
135
|
+
* is the key the server already gave this socket (its welcome said it):
|
|
136
|
+
* given, the claimed key is not read at all.
|
|
137
|
+
*/
|
|
138
|
+
export declare function presenceFrom(told: Presence, seat: Principal, now?: Date, participant?: string): Presence;
|
|
139
|
+
/**
|
|
140
|
+
* A VISITOR WITHOUT A SOCKET, as a host announces it (FR-47): an agent
|
|
141
|
+
* acting over MCP or an RPC, a polling tab. Built from the author the host
|
|
142
|
+
* already trusts — what it is, what it is called, for whom — keyed
|
|
143
|
+
* `kind:id:visit` unless a session is given, so every call by one agent
|
|
144
|
+
* refreshes one figure rather than adding another.
|
|
145
|
+
*/
|
|
146
|
+
export declare function visitorPresence(author: Author, options?: {
|
|
147
|
+
readonly session?: string;
|
|
148
|
+
readonly stop?: string;
|
|
149
|
+
readonly over?: string | null;
|
|
150
|
+
readonly hue?: number;
|
|
151
|
+
readonly now?: Date;
|
|
152
|
+
}): Presence;
|
|
153
|
+
/**
|
|
154
|
+
* WHO IS HERE, WITH ONE MORE (FR-47) — for a host that holds `who` itself,
|
|
155
|
+
* as a hibernating one does. The visitor is stamped now and stands until
|
|
156
|
+
* `ttlMs` from now; the same participant announced again replaces it, and
|
|
157
|
+
* anybody whose announced time has passed is dropped. Pure: keep what it
|
|
158
|
+
* answers, and hand it to `receive` and `tell`.
|
|
159
|
+
*/
|
|
160
|
+
export declare function announcePresence(who: readonly Presence[], presence: Presence, ttlMs?: number, now?: number): Presence[];
|
|
161
|
+
/**
|
|
162
|
+
* WHO IS HERE, AS ONE SEAT MAY BE TOLD (FR-02). Somebody whose own record
|
|
163
|
+
* the seat may not see is not shown to it at all; anybody else is, without
|
|
164
|
+
* where they stand or what they hover when that names a record the seat
|
|
165
|
+
* may not see. A participant whose id is no record is shown as they are.
|
|
166
|
+
*/
|
|
167
|
+
export declare function presenceSeenBy(who: readonly Presence[], sees: (id: string) => boolean): Presence[];
|
|
168
|
+
/**
|
|
169
|
+
* THE STORE AS EACH SEAT SEES IT, on the wire — shared by the HTTP routes
|
|
170
|
+
* and the socket, so the two can never disagree. Internal: everything in
|
|
171
|
+
* it is derived from the store, and kept only to save reading the log
|
|
172
|
+
* again; a field's revisions are caught up from the log as it grew, so a
|
|
173
|
+
* wake that made this again reads the same revisions the sleeper had.
|
|
174
|
+
*/
|
|
175
|
+
export interface Wire<S extends AnySchema> {
|
|
176
|
+
readonly store: Store<S>;
|
|
177
|
+
lastSeq(): number;
|
|
178
|
+
/** Kept from a seat: what its sight does not reach (FR-02), and the kinds of a module that is off (FR-12). */
|
|
179
|
+
sighted(principal: Principal): boolean;
|
|
180
|
+
/** Ops as the seat may see them, withheld in place (FR-16). */
|
|
181
|
+
shown(principal: Principal, ops: readonly Operation[]): Operation[];
|
|
182
|
+
/** The ops after `seq`, as the seat sees them. */
|
|
183
|
+
since(principal: Principal, seq: number): Operation[];
|
|
184
|
+
/** The store as the seat sees it. */
|
|
185
|
+
seenFor(principal: Principal): Store<S>;
|
|
186
|
+
whoFor(principal: Principal, who: readonly Presence[]): Presence[];
|
|
187
|
+
/** The fields a call would write that moved since the caller's base: a stale write (FR-05). */
|
|
188
|
+
conflictsOf(author: Principal, calls: readonly MutationCall[], base: unknown): FieldConflict[];
|
|
189
|
+
/**
|
|
190
|
+
* SENT TWICE, ANSWERED ONCE: the ops already in the log under the batch a
|
|
191
|
+
* call or an undo names, or none. A client that never heard the answer
|
|
192
|
+
* sends again under the same batch — down the socket or over HTTP — and
|
|
193
|
+
* is answered with what it made the first time (FR-49).
|
|
194
|
+
*/
|
|
195
|
+
answered(batch: unknown): Operation[];
|
|
196
|
+
/** `{ horizon }` when the log was compacted (FR-23); nothing otherwise. */
|
|
197
|
+
horizonOf(): {
|
|
198
|
+
horizon?: number;
|
|
199
|
+
};
|
|
200
|
+
enabledModules(): string[];
|
|
201
|
+
}
|
|
202
|
+
export declare function wireOf<S extends AnySchema>(store: Store<S>): Wire<S>;
|
|
203
|
+
/**
|
|
204
|
+
* THE PROTOCOL OVER A STORE. Cheap to make, and safe to make again on
|
|
205
|
+
* every wake: what it keeps is derived from the store.
|
|
206
|
+
*/
|
|
207
|
+
export declare function liveProtocol<S extends AnySchema>(options: LiveProtocolOptions<S>): LiveProtocol<S>;
|
|
208
|
+
//# sourceMappingURL=live-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-protocol.d.ts","sourceRoot":"","sources":["../src/live-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,aAAa,EAElB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAwC,KAAK,KAAK,EAAkD,MAAM,WA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