statewire 0.21.0 → 0.22.1

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 (134) hide show
  1. package/dist/client/changes.d.ts +3 -6
  2. package/dist/client/changes.d.ts.map +1 -1
  3. package/dist/client/changes.js +1 -2
  4. package/dist/client/connection.d.ts +80 -83
  5. package/dist/client/connection.d.ts.map +1 -1
  6. package/dist/client/connection.js +2 -3
  7. package/dist/client/connection.js.map +1 -1
  8. package/dist/client/core.d.ts +39 -41
  9. package/dist/client/core.d.ts.map +1 -1
  10. package/dist/client/core.js +2 -3
  11. package/dist/client/session.d.ts +93 -95
  12. package/dist/client/session.d.ts.map +1 -1
  13. package/dist/client/session.js +6 -7
  14. package/dist/client/session.js.map +1 -1
  15. package/dist/client/sessionStore.d.ts +11 -14
  16. package/dist/client/sessionStore.d.ts.map +1 -1
  17. package/dist/client/sessionStore.js +1 -2
  18. package/dist/client/storageError.d.ts +2 -5
  19. package/dist/client/storageError.d.ts.map +1 -1
  20. package/dist/client/storageError.js +1 -2
  21. package/dist/client/timing.d.ts +11 -14
  22. package/dist/client/timing.d.ts.map +1 -1
  23. package/dist/client/timing.js +1 -2
  24. package/dist/document.d.ts +17 -20
  25. package/dist/document.d.ts.map +1 -1
  26. package/dist/document.js +1 -2
  27. package/dist/host/adapter.d.ts +4 -7
  28. package/dist/host/adapter.d.ts.map +1 -1
  29. package/dist/host/adapter.js +1 -2
  30. package/dist/host/draft.d.ts +13 -16
  31. package/dist/host/draft.d.ts.map +1 -1
  32. package/dist/host/draft.js +1 -2
  33. package/dist/host/engine.d.ts +7 -10
  34. package/dist/host/engine.d.ts.map +1 -1
  35. package/dist/host/engine.js +1 -2
  36. package/dist/host/host.d.ts +42 -45
  37. package/dist/host/host.d.ts.map +1 -1
  38. package/dist/host/host.js +1 -2
  39. package/dist/host/http.d.ts +4 -7
  40. package/dist/host/http.d.ts.map +1 -1
  41. package/dist/host/http.js +2 -3
  42. package/dist/host/socket.d.ts +148 -145
  43. package/dist/host/socket.d.ts.map +1 -1
  44. package/dist/host/socket.js +30 -12
  45. package/dist/host/socket.js.map +1 -1
  46. package/dist/host/synced.d.ts +3 -6
  47. package/dist/host/synced.d.ts.map +1 -1
  48. package/dist/host/synced.js +1 -2
  49. package/dist/host/work.d.ts +2 -5
  50. package/dist/host/work.d.ts.map +1 -1
  51. package/dist/host/work.js +1 -2
  52. package/dist/host-internal.d.ts +101 -93
  53. package/dist/host-internal.d.ts.map +1 -1
  54. package/dist/host.d.ts +90 -91
  55. package/dist/host.d.ts.map +1 -1
  56. package/dist/index.d.ts +11 -8
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +1 -1
  59. package/dist/statewire.d.ts +265 -268
  60. package/dist/statewire.d.ts.map +1 -1
  61. package/dist/statewire.js +1 -2
  62. package/dist/storage.d.ts +23 -26
  63. package/dist/storage.d.ts.map +1 -1
  64. package/dist/storage.js +1 -2
  65. package/dist/transports/fake-sse.d.ts +7 -10
  66. package/dist/transports/fake-sse.d.ts.map +1 -1
  67. package/dist/transports/fake-sse.js +1 -2
  68. package/dist/transports/fixtures.d.ts +19 -25
  69. package/dist/transports/fixtures.d.ts.map +1 -1
  70. package/dist/transports/fixtures.js +1 -2
  71. package/dist/transports/remote.d.ts +8 -11
  72. package/dist/transports/remote.d.ts.map +1 -1
  73. package/dist/transports/remote.js +1 -2
  74. package/dist/transports/sse-parser.d.ts +1 -4
  75. package/dist/transports/sse-parser.d.ts.map +1 -1
  76. package/dist/transports/sse-parser.js +1 -2
  77. package/dist/transports/sse.d.ts +50 -53
  78. package/dist/transports/sse.d.ts.map +1 -1
  79. package/dist/transports/sse.js +2 -3
  80. package/dist/transports/testing.d.ts +31 -34
  81. package/dist/transports/testing.d.ts.map +1 -1
  82. package/dist/transports/testing.js +1 -2
  83. package/dist/transports/ws.d.ts +5 -7
  84. package/dist/transports/ws.d.ts.map +1 -1
  85. package/dist/transports/ws.js +3 -4
  86. package/dist/transports/ws.js.map +1 -1
  87. package/dist/types.d.ts +81 -78
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js +1 -2
  90. package/dist/util/draftTraps.d.ts +2 -4
  91. package/dist/util/draftTraps.d.ts.map +1 -1
  92. package/dist/util/draftTraps.js +1 -2
  93. package/dist/util/macrotask.d.ts +1 -4
  94. package/dist/util/macrotask.d.ts.map +1 -1
  95. package/dist/util/macrotask.js +1 -2
  96. package/dist/util/methodProxy.d.ts +1 -4
  97. package/dist/util/methodProxy.d.ts.map +1 -1
  98. package/dist/util/methodProxy.js +1 -2
  99. package/dist/util/randomId.d.ts +1 -4
  100. package/dist/util/randomId.d.ts.map +1 -1
  101. package/dist/util/randomId.js +1 -2
  102. package/dist/util/recordMutations.d.ts +5 -7
  103. package/dist/util/recordMutations.d.ts.map +1 -1
  104. package/dist/util/recordMutations.js +1 -2
  105. package/dist/util/statePath.d.ts +9 -12
  106. package/dist/util/statePath.d.ts.map +1 -1
  107. package/dist/util/statePath.js +1 -2
  108. package/dist/wire/context.d.ts +7 -12
  109. package/dist/wire/context.d.ts.map +1 -1
  110. package/dist/wire/context.js +2 -3
  111. package/dist/wire/documents.d.ts +36 -39
  112. package/dist/wire/documents.d.ts.map +1 -1
  113. package/dist/wire/documents.js +2 -3
  114. package/dist/wire/documents.js.map +1 -1
  115. package/dist/wire/limits.d.ts +7 -10
  116. package/dist/wire/limits.d.ts.map +1 -1
  117. package/dist/wire/limits.js +1 -2
  118. package/dist/wire/meta.d.ts +9 -11
  119. package/dist/wire/meta.d.ts.map +1 -1
  120. package/dist/wire/meta.js +1 -2
  121. package/dist/wire/meta.js.map +1 -1
  122. package/dist/wire/ops.d.ts +9 -12
  123. package/dist/wire/ops.d.ts.map +1 -1
  124. package/dist/wire/ops.js +1 -2
  125. package/dist/wire/protocol.d.ts +53 -56
  126. package/dist/wire/protocol.d.ts.map +1 -1
  127. package/dist/wire/protocol.js +1 -2
  128. package/dist/wire/version.d.ts +1 -4
  129. package/dist/wire/version.d.ts.map +1 -1
  130. package/dist/wire/version.js +1 -2
  131. package/package.json +6 -6
  132. package/src/client/connection.ts +13 -15
  133. package/src/host/socket.ts +63 -6
  134. package/src/host-internal.ts +12 -0
@@ -1,96 +1,104 @@
1
- import { StatewireHost } from "./host.js";
2
- import { StatewireProtocol } from "./wire/protocol.js";
3
- import { WS_SUBPROTOCOL } from "./wire/version.js";
4
- import { StatewireSocketHost } from "./host/socket.js";
5
- import { clientIdFromUrl, textFrameOrClose } from "./host/adapter.js";
6
- //#region src/host-internal.d.ts
7
- declare namespace StatewireHostInternal {
8
- type Socket = {
9
- send: (data: string) => void;
10
- close: (code?: number, reason?: string) => void;
11
- };
12
- type SocketConnection = {
13
- readonly clientId: string;
14
- message: (data: string) => void;
15
- close: () => void;
16
- };
17
- type SocketConnectOptions = {
18
- /** Upgrade headers take precedence over initialization headers. */
19
- headers?: Record<string, string>;
20
- /** The adapter restored this socket from an already-authorized session. */
21
- authorized?: boolean;
22
- authorizedAt?: number;
23
- selection?: StatewireProtocol.Selection;
24
- /** The restored session's captured auth value; it must satisfy the client record's principal binding. */
25
- auth?: unknown;
26
- /** Persist authorization (and the captured auth value) before the first snapshot is released. */
27
- onAuthorized?: (auth: unknown, selection: StatewireProtocol.Selection, authorizedAt: number) => void;
28
- };
29
- type SocketHost = {
30
- /** Null means refused: the socket was told (fin and/or close) and is dead. */
31
- connect: (clientId: string, socket: Socket, options?: SocketConnectOptions) => SocketConnection | null;
32
- stream: (request: Request) => Promise<Response>;
33
- frames: (request: Request) => Promise<Response>;
34
- finish: (fin: StatewireHost.Fin) => void;
35
- dispose: () => void;
36
- };
37
- type Cmd = {
38
- protocol: string;
39
- seq: number;
40
- type?: "applied" | "result" | "rejected" | "failed" | "crashed" | "expired";
41
- code?: string;
42
- message?: string;
43
- payload?: unknown;
44
- meta?: unknown;
45
- /** Cumulative per lane: resending through this seq will never be needed. */
46
- dur?: boolean;
47
- };
48
- type ClientRecord = {
49
- id: string;
50
- touched: number;
51
- lanes: Readonly<Record<string, {
52
- lastSeq: number;
53
- results: readonly {
1
+ import type { StatewireProtocol } from "./wire/protocol.js";
2
+ import type { StatewireHost } from "./host.js";
3
+ export { StatewireSocketHost } from "./host/socket.js";
4
+ export { clientIdFromUrl, textFrameOrClose } from "./host/adapter.js";
5
+ export { WS_SUBPROTOCOL } from "./wire/version.js";
6
+ export declare namespace StatewireHostInternal {
7
+ type Socket = {
8
+ send: (data: string) => void;
9
+ close: (code?: number, reason?: string) => void;
10
+ };
11
+ type SocketConnection = {
12
+ readonly clientId: string;
13
+ message: (data: string) => void;
14
+ close: () => void;
15
+ };
16
+ type SocketConnectOptions = {
17
+ /** Upgrade headers take precedence over initialization headers. */
18
+ headers?: Record<string, string>;
19
+ /** The adapter restored this socket from an already-authorized session. */
20
+ authorized?: boolean;
21
+ authorizedAt?: number;
22
+ selection?: StatewireProtocol.Selection;
23
+ /** The restored session's captured auth value; it must satisfy the client record's principal binding. */
24
+ auth?: unknown;
25
+ /** Persist authorization (and the captured auth value) before the first snapshot is released. */
26
+ onAuthorized?: (auth: unknown, selection: StatewireProtocol.Selection, authorizedAt: number) => void;
27
+ /** Documents the attach had included before the adapter retained its socket; they ride the hello. */
28
+ included?: readonly IncludedDocument[];
29
+ /** Called with the attach's whole include set each time `include` or `exclude` changes it. */
30
+ onIncludedChange?: (included: readonly IncludedDocument[]) => void;
31
+ };
32
+ /** A durable document an attach included: `[protocol, key]`. */
33
+ type IncludedDocument = readonly [
34
+ protocol: string,
35
+ key: readonly string[] | null
36
+ ];
37
+ type SocketHost = {
38
+ /** Null means refused: the socket was told (fin and/or close) and is dead. */
39
+ connect: (clientId: string, socket: Socket, options?: SocketConnectOptions) => SocketConnection | null;
40
+ stream: (request: Request) => Promise<Response>;
41
+ frames: (request: Request) => Promise<Response>;
42
+ finish: (fin: StatewireHost.Fin) => void;
43
+ dispose: () => void;
44
+ };
45
+ type Cmd = {
46
+ protocol: string;
54
47
  seq: number;
55
- ts: number;
56
- cmd: Cmd;
57
- }[];
58
- }>>;
59
- principal: unknown;
60
- };
61
- type SocketHostPersistence = {
62
- clientRecords?: readonly ClientRecord[];
63
- onClientRecordsChange?: (records: readonly ClientRecord[]) => void;
64
- };
65
- type SocketHostOptions<TAuth = unknown> = {
66
- protocol?: StatewireProtocol.Definition;
67
- /** Key of the host protocol's main document. */
68
- key?: readonly string[];
69
- wireVersion?: StatewireProtocol.Range;
70
- /** Gates every attach; the awaited return value is the attach's auth, exposed to command handlers as `this.caller.auth`. The first attach binds the client id's record to this value; a later attach whose value is not structurally equal is refused (HTTP 403, socket close 1008). */
71
- authorize?: (ctx: {
72
- headers: Record<string, string>;
73
- }) => TAuth | Promise<TAuth>;
74
- /** Time allowed to complete WebSocket initialization and authorization. */
75
- wsInitTimeoutMs?: number;
76
- heartbeatIntervalMs?: number;
77
- /** Maximum attach lifetime in milliseconds; defaults to 24 hours, null disables expiry. */
78
- maxLeaseLifetimeMs?: number | null;
79
- /** Maximum number of concurrently attached WebSocket and SSE streams. */
80
- maxSubscribers?: number;
81
- /** Maximum number of admitted commands still running across all clients. */
82
- maxInflightCommands?: number;
83
- /** Maximum number of queued SSE packets before a lagging stream is closed. */
84
- streamQueueSize?: number;
85
- /** LRU cap on stored client records; live or in-flight records are exempt. */
86
- clientRecordLimit?: number;
87
- /** Hang every attach up with `fin: idle` at the idle flag's rising edge. */
88
- finOnIdle?: boolean;
89
- /** Milliseconds to defer admission, or null to admit. */
90
- pushback?: () => number | null;
91
- };
92
- type Fin = StatewireHost.Fin;
48
+ type?: "applied" | "result" | "rejected" | "failed" | "crashed" | "expired";
49
+ code?: string;
50
+ message?: string;
51
+ payload?: unknown;
52
+ meta?: unknown;
53
+ /** Cumulative per lane: resending through this seq will never be needed. */
54
+ dur?: boolean;
55
+ };
56
+ type ClientRecord = {
57
+ id: string;
58
+ touched: number;
59
+ lanes: Readonly<Record<string, {
60
+ lastSeq: number;
61
+ results: readonly {
62
+ seq: number;
63
+ ts: number;
64
+ cmd: Cmd;
65
+ }[];
66
+ }>>;
67
+ principal: unknown;
68
+ };
69
+ type SocketHostPersistence = {
70
+ clientRecords?: readonly ClientRecord[];
71
+ onClientRecordsChange?: (records: readonly ClientRecord[]) => void;
72
+ /** The adapter can evict the host while its WebSockets stay open: their leases arm no timer and are checked on every message, delivery and restore instead. */
73
+ hibernatable?: boolean;
74
+ };
75
+ type SocketHostOptions<TAuth = unknown> = {
76
+ protocol?: StatewireProtocol.Definition;
77
+ /** Key of the host protocol's main document. */
78
+ key?: readonly string[];
79
+ wireVersion?: StatewireProtocol.Range;
80
+ /** Gates every attach; the awaited return value is the attach's auth, exposed to command handlers as `this.caller.auth`. The first attach binds the client id's record to this value; a later attach whose value is not structurally equal is refused (HTTP 403, socket close 1008). */
81
+ authorize?: (ctx: {
82
+ headers: Record<string, string>;
83
+ }) => TAuth | Promise<TAuth>;
84
+ /** Time allowed to complete WebSocket initialization and authorization. */
85
+ wsInitTimeoutMs?: number;
86
+ heartbeatIntervalMs?: number;
87
+ /** Maximum attach lifetime in milliseconds; defaults to 24 hours, null disables expiry. */
88
+ maxLeaseLifetimeMs?: number | null;
89
+ /** Maximum number of concurrently attached WebSocket and SSE streams. */
90
+ maxSubscribers?: number;
91
+ /** Maximum number of admitted commands still running across all clients. */
92
+ maxInflightCommands?: number;
93
+ /** Maximum number of queued SSE packets before a lagging stream is closed. */
94
+ streamQueueSize?: number;
95
+ /** LRU cap on stored client records; live or in-flight records are exempt. */
96
+ clientRecordLimit?: number;
97
+ /** Hang every attach up with `fin: idle` at the idle flag's rising edge. */
98
+ finOnIdle?: boolean;
99
+ /** Milliseconds to defer admission, or null to admit. */
100
+ pushback?: () => number | null;
101
+ };
102
+ type Fin = StatewireHost.Fin;
93
103
  }
94
- //#endregion
95
- export { StatewireHostInternal, StatewireSocketHost, WS_SUBPROTOCOL, clientIdFromUrl, textFrameOrClose };
96
104
  //# sourceMappingURL=host-internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host-internal.d.ts","names":[],"sources":["../src/host-internal.ts"],"mappings":";;;;;;kBAMiB;OACH;IACV,OAAO;IACP,QAAQ,eAAe;;OAGb;aACD;IACT,UAAU;IACV;;OAGU;;IAEV,UAAU;;IAEV;IACA;IACA,YAAY,kBAAkB;;IAE9B;;IAEA,gBACE,eACA,WAAW,kBAAkB,WAC7B;;OAIQ;;IAEV,UACE,kBACA,QAAQ,QACR,UAAU,yBACP;IACL,SAAS,SAAS,YAAY,QAAQ;IACtC,SAAS,SAAS,YAAY,QAAQ;IACtC,SAAS,KAAK,cAAc;IAC5B;;OAGU;IACV;IACA;IACA;IACA;IACA;IACA;IACA;;IAEA;;OAGU;IACV;IACA;IACA,OAAO,SACL;MAGI;MACA;QAAoB;QAAa;QAAY,KAAK;;;IAIxD;;OAGU;IACV,yBAAyB;IACzB,yBAAyB,kBAAkB;;OAGjC,kBAAkB;IAC5B,WAAW,kBAAkB;;IAE7B;IACA,cAAc,kBAAkB;;IAEhC,aAAa;MACX,SAAS;UACL,QAAQ,QAAQ;;IAEtB;IACA;;IAEA;;IAEA;;IAEA;;IAEA;;IAEA;;IAEA;;IAEA;;OAGU,MAAM,cAAc"}
1
+ {"version":3,"file":"host-internal.d.ts","sourceRoot":"","sources":["../src/host-internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAwB;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAe;AAE5C,OAAO,EAAE,mBAAmB,EAAE,yBAAsB;AACpD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,0BAAuB;AACnE,OAAO,EAAE,cAAc,EAAE,0BAAuB;AAChD,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,MAAM,GAAG;QACnB,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QAC7B,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;KACjD,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xC,gDAAgD;QAChD,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;QACxB,WAAW,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC;QACtC,wRAAwR;QACxR,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE;YAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACjC,KAAK,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,2EAA2E;QAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,2FAA2F;QAC3F,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACnC,yEAAyE;QACzE,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,4EAA4E;QAC5E,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,8EAA8E;QAC9E,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,8EAA8E;QAC9E,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,4EAA4E;QAC5E,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,yDAAyD;QACzD,QAAQ,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;KAChC,CAAC;IAEF,KAAY,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC;CACrC"}
package/dist/host.d.ts CHANGED
@@ -1,93 +1,92 @@
1
- import { StatewireReject } from "./host/engine.js";
2
- import { useStatewireWork } from "./host/work.js";
3
- import { append } from "./host/draft.js";
4
- import { getStateHost, useStatewireCommands, useStatewireState } from "./host/host.js";
5
- import { syncedDocument } from "./host/synced.js";
6
- import { Statewire } from "./types.js";
7
- //#region src/host.d.ts
8
- declare namespace StatewireHost {
9
- type Work = {
10
- readonly isIdle: boolean;
11
- track: <T>(task: Promise<T>) => Promise<T>;
12
- schedule: (callback: () => void) => void;
13
- };
14
- type StateCtl<TState = unknown> = {
15
- /** Apply server-vocabulary ops (root replace = whole-state swap). */
16
- apply: (ops: readonly Statewire.Op[]) => void;
17
- /** The committed plain state — immutably replaced per op, so a captured value is a stable snapshot. */
18
- snapshot: () => TState;
19
- };
20
- type Document = {
21
- protocol: string;
22
- key: readonly string[] | null;
23
- main: boolean;
24
- value: unknown;
25
- };
26
- type StateHost = Statewire.StateSource & {
27
- /** Synchronous, per locally-recorded op; the host owns batching. */
28
- setOnOp: (listener: ((op: Statewire.Op) => void) | null) => void;
29
- /** Mount or replace the shared document `(protocol, key)`; keyed documents reach an attach only once it `include`s them. */
30
- mount: (protocol: string, value: unknown, options?: {
31
- key?: readonly string[];
32
- main?: boolean;
33
- }) => void;
34
- unmount: (protocol: string, key?: readonly string[]) => void;
35
- documents: () => ReadonlyMap<string, Document>;
36
- setOnDocuments: (listener: (() => void) | null) => void;
37
- };
38
- /**
39
- * Per-invocation handle bound as `this` of a command handler: `caller` is
40
- * the submitting client, `attach` the admitting attach's document view
41
- * (in-process dispatch has none — reading it throws), `applied()` states the
42
- * broadcast state now contains the command's effects — the client drops its
43
- * optimistic overlay — before the handler settles (idempotent, a no-op after
44
- * settle). The command settles when the handler's returned promise does.
45
- */
46
- type CommandsOptions = {
47
- context?: () => Statewire.Context;
48
- };
49
- type Ctx = {
50
- readonly caller: Caller;
51
- readonly context: Statewire.Context;
52
- readonly attach: Attach;
53
- readonly signal: AbortSignal;
54
- readonly applied: () => void;
55
- };
56
- /**
57
- * The submitting client (`this.caller` in a command handler). Holdable
58
- * across a long run: `clientId` is the client's `Statewire-Client-Id`
59
- * (in-process dispatch has none — reading it throws), `auth` is the value
60
- * `authorize` returned for the attach that admitted the command (undefined
61
- * for a void `authorize` and for in-process dispatch), `isConnected`
62
- * reports whether the client has an active stream attachment.
63
- */
64
- type Caller = {
65
- readonly clientId: string;
66
- readonly auth: unknown;
67
- readonly isConnected: boolean;
68
- };
69
- /** The admitting attach's view: its ephemeral documents plus the shared documents included for it. */
70
- type Attach = {
71
- readonly caller: Caller;
72
- context: (protocol: string) => Statewire.Context;
73
- document: (protocol: string, key?: readonly string[]) => unknown;
74
- /** `protocol` must be ephemeral; the encoded value is bounded by `MAX_EPHEMERAL_DOCUMENT_BYTES`. */
75
- mount: (protocol: string, value: unknown, key?: readonly string[], main?: boolean) => void;
76
- unmount: (protocol: string, key?: readonly string[]) => void;
77
- include: (protocol: string, key: readonly string[]) => void;
78
- exclude: (protocol: string, key: readonly string[]) => void;
79
- };
80
- type HandledCommands<THandlers extends Statewire.Commands> = { [K in keyof THandlers]: (...args: Parameters<THandlers[K]>) => Awaited<ReturnType<THandlers[K]>>; };
81
- type Fin = {
82
- reason: "reconnect" | "error" | "protocol-error" | "forbidden" | "unauthorized" | "gone" | "idle" | (string & {});
83
- message?: string;
84
- code?: string;
85
- status?: number;
86
- retry?: number;
87
- payload?: unknown;
88
- meta?: unknown;
89
- };
1
+ import type { Statewire } from "./types.js";
2
+ export { StatewireReject } from "./host/engine.js";
3
+ export { useStatewireWork } from "./host/work.js";
4
+ export { append } from "./host/draft.js";
5
+ export { getStateHost, useStatewireState, useStatewireCommands, } from "./host/host.js";
6
+ export { syncedDocument } from "./host/synced.js";
7
+ export declare namespace StatewireHost {
8
+ type Work = {
9
+ readonly isIdle: boolean;
10
+ track: <T>(task: Promise<T>) => Promise<T>;
11
+ schedule: (callback: () => void) => void;
12
+ };
13
+ type StateCtl<TState = unknown> = {
14
+ /** Apply server-vocabulary ops (root replace = whole-state swap). */
15
+ apply: (ops: readonly Statewire.Op[]) => void;
16
+ /** The committed plain state — immutably replaced per op, so a captured value is a stable snapshot. */
17
+ snapshot: () => TState;
18
+ };
19
+ type Document = {
20
+ protocol: string;
21
+ key: readonly string[] | null;
22
+ main: boolean;
23
+ value: unknown;
24
+ };
25
+ type StateHost = Statewire.StateSource & {
26
+ /** Synchronous, per locally-recorded op; the host owns batching. */
27
+ setOnOp: (listener: ((op: Statewire.Op) => void) | null) => void;
28
+ /** Mount or replace the shared document `(protocol, key)`; keyed documents reach an attach only once it `include`s them. */
29
+ mount: (protocol: string, value: unknown, options?: {
30
+ key?: readonly string[];
31
+ main?: boolean;
32
+ }) => void;
33
+ unmount: (protocol: string, key?: readonly string[]) => void;
34
+ documents: () => ReadonlyMap<string, Document>;
35
+ setOnDocuments: (listener: (() => void) | null) => void;
36
+ };
37
+ /**
38
+ * Per-invocation handle bound as `this` of a command handler: `caller` is
39
+ * the submitting client, `attach` the admitting attach's document view
40
+ * (in-process dispatch has none — reading it throws), `applied()` states the
41
+ * broadcast state now contains the command's effects — the client drops its
42
+ * optimistic overlay — before the handler settles (idempotent, a no-op after
43
+ * settle). The command settles when the handler's returned promise does.
44
+ */
45
+ type CommandsOptions = {
46
+ context?: () => Statewire.Context;
47
+ };
48
+ type Ctx = {
49
+ readonly caller: Caller;
50
+ readonly context: Statewire.Context;
51
+ readonly attach: Attach;
52
+ readonly signal: AbortSignal;
53
+ readonly applied: () => void;
54
+ };
55
+ /**
56
+ * The submitting client (`this.caller` in a command handler). Holdable
57
+ * across a long run: `clientId` is the client's `Statewire-Client-Id`
58
+ * (in-process dispatch has none — reading it throws), `auth` is the value
59
+ * `authorize` returned for the attach that admitted the command (undefined
60
+ * for a void `authorize` and for in-process dispatch), `isConnected`
61
+ * reports whether the client has an active stream attachment.
62
+ */
63
+ type Caller = {
64
+ readonly clientId: string;
65
+ readonly auth: unknown;
66
+ readonly isConnected: boolean;
67
+ };
68
+ /** The admitting attach's view: its ephemeral documents plus the shared documents included for it. */
69
+ type Attach = {
70
+ readonly caller: Caller;
71
+ context: (protocol: string) => Statewire.Context;
72
+ document: (protocol: string, key?: readonly string[]) => unknown;
73
+ /** `protocol` must be ephemeral; the encoded value is bounded by `MAX_EPHEMERAL_DOCUMENT_BYTES`. */
74
+ mount: (protocol: string, value: unknown, key?: readonly string[], main?: boolean) => void;
75
+ unmount: (protocol: string, key?: readonly string[]) => void;
76
+ include: (protocol: string, key: readonly string[]) => void;
77
+ exclude: (protocol: string, key: readonly string[]) => void;
78
+ };
79
+ type HandledCommands<THandlers extends Statewire.Commands> = {
80
+ [K in keyof THandlers]: (...args: Parameters<THandlers[K]>) => Awaited<ReturnType<THandlers[K]>>;
81
+ };
82
+ type Fin = {
83
+ reason: "reconnect" | "error" | "protocol-error" | "forbidden" | "unauthorized" | "gone" | "idle" | (string & {});
84
+ message?: string;
85
+ code?: string;
86
+ status?: number;
87
+ retry?: number;
88
+ payload?: unknown;
89
+ meta?: unknown;
90
+ };
90
91
  }
91
- //#endregion
92
- export { StatewireHost, StatewireReject, append, getStateHost, syncedDocument, useStatewireCommands, useStatewireState, useStatewireWork };
93
92
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","names":[],"sources":["../src/host.ts"],"mappings":";;;;;;;kBAYiB;OACH;aACD;IACT,QAAQ,GAAG,MAAM,QAAQ,OAAO,QAAQ;IACxC,WAAW;;OAGD,SAAS;;IAEnB,QAAQ,cAAc,UAAU;;IAEhC,gBAAgB;;OAGN;IACV;IACA;IACA;IACA;;OAGU,YAAY,UAAU;;IAEhC,UAAU,YAAY,IAAI,UAAU;;IAEpC,QACE,kBACA,gBACA;MAAY;MAAyB;;IAEvC,UAAU,kBAAkB;IAC5B,iBAAiB,oBAAoB;IACrC,iBAAiB;;;;;;;;;;OAWP;IAAoB,gBAAgB,UAAU;;OAE9C;aACD,QAAQ;aACR,SAAS,UAAU;aACnB,QAAQ;aACR,QAAQ;aACR;;;;;;;;;;OAWC;aACD;aACA;aACA;;;OAIC;aACD,QAAQ;IACjB,UAAU,qBAAqB,UAAU;IACzC,WAAW,kBAAkB;;IAE7B,QACE,kBACA,gBACA,yBACA;IAEF,UAAU,kBAAkB;IAC5B,UAAU,kBAAkB;IAC5B,UAAU,kBAAkB;;OAGlB,gBAAgB,kBAAkB,UAAU,eACrD,WAAW,gBACP,MAAM,WAAW,UAAU,QAC3B,QAAQ,WAAW,UAAU;OAGxB;IACV;IASA;IACA;IACA;IACA;IACA;IACA"}
1
+ {"version":3,"file":"host.d.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DEFAULT_PROTOCOL, StatewireProtocol } from "./wire/protocol.js";
3
- import { StatewireDocument, decodeDocument, encodeDocument } from "./document.js";
4
- import { StatewireHttp } from "./transports/sse.js";
5
- import { StatewireClient, StatewireResource, useStatewire } from "./statewire.js";
6
- import { Statewire, StatewireSendError } from "./types.js";
7
- import { StatewireWebsocket } from "./transports/ws.js";
8
- export { DEFAULT_PROTOCOL, type Statewire, StatewireClient, type StatewireDocument, type StatewireDocuments, StatewireHttp, type StatewireProtocol, StatewireResource, StatewireSendError, StatewireWebsocket, decodeDocument, encodeDocument, useStatewire };
1
+ export type { Statewire } from "./types.js";
2
+ export { encodeDocument, decodeDocument } from "./document.js";
3
+ export type { StatewireDocument } from "./document.js";
4
+ export { StatewireClient, useStatewire, StatewireResource } from "./statewire.js";
5
+ export { StatewireHttp } from "./transports/sse.js";
6
+ export { StatewireWebsocket } from "./transports/ws.js";
7
+ export { StatewireSendError } from "./types.js";
8
+ export type { StatewireProtocol } from "./wire/protocol.js";
9
+ export { DEFAULT_PROTOCOL } from "./wire/protocol.js";
10
+ export type { StatewireDocuments } from "./wire/documents.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,mBAAgB;AACzC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,sBAAmB;AAC5D,YAAY,EAAE,iBAAiB,EAAE,sBAAmB;AACpD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,uBAAoB;AAC/E,OAAO,EAAE,aAAa,EAAE,4BAAyB;AACjD,OAAO,EAAE,kBAAkB,EAAE,2BAAwB;AACrD,OAAO,EAAE,kBAAkB,EAAE,mBAAgB;AAE7C,YAAY,EAAE,iBAAiB,EAAE,2BAAwB;AACzD,OAAO,EAAE,gBAAgB,EAAE,2BAAwB;AACnD,YAAY,EAAE,kBAAkB,EAAE,4BAAyB"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { decodeDocument, encodeDocument } from "./document.js";
2
1
  import { DEFAULT_PROTOCOL } from "./wire/protocol.js";
2
+ import { decodeDocument, encodeDocument } from "./document.js";
3
3
  import { StatewireSendError } from "./types.js";
4
4
  import { StatewireClient, StatewireResource, useStatewire } from "./statewire.js";
5
5
  import { StatewireHttp } from "./transports/sse.js";