experimental-a2 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +169 -0
- package/dist/ai-B4YhEnfw.d.ts +333 -0
- package/dist/ai-server.d.ts +48 -9
- package/dist/ai-server.js +121 -49
- package/dist/ai.d.ts +2 -303
- package/dist/ai.js +231 -86
- package/dist/cli-B3VuxoDe.js +597 -0
- package/dist/cli-bin.d.ts +1 -0
- package/dist/cli-bin.js +5 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +2 -0
- package/dist/client-BrfDXQ8A.d.ts +155 -0
- package/dist/client-Bt4tAKi9.js +798 -0
- package/dist/client.d.ts +2 -90
- package/dist/client.js +1 -409
- package/dist/{contract-CG_adnu_.js → contract-48bUMgcL.js} +10 -2
- package/dist/{contract-C_3dIIEU.d.ts → contract-jIfaR085.d.ts} +62 -8
- package/dist/devtools-J_jZ2vQf.d.ts +151 -0
- package/dist/devtools-kJJaORn-.js +338 -0
- package/dist/devtools-server.browser.js +1 -1
- package/dist/devtools-server.d.ts +2 -2
- package/dist/devtools-server.js +224 -43
- package/dist/devtools.d.ts +2 -0
- package/dist/devtools.js +2 -0
- package/dist/{errors-BJRMd-h6.js → errors-BQuJpe82.js} +4 -4
- package/dist/{errors-xL_JTXsY.d.ts → errors-W6nwJ-fm.d.ts} +1 -1
- package/dist/http.d.ts +71 -13
- package/dist/http.js +302 -41
- package/dist/{idempotent-replay-BMyHrP0L.js → idempotent-replay-DuqEkYA7.js} +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/{inspection-E7qbD0Xj.js → inspection-DaxB5jM2.js} +2 -1
- package/dist/internal-aEotMzu_.js +209 -0
- package/dist/otel.d.ts +1 -1
- package/dist/platform-B4TnJtWu.js +32 -0
- package/dist/react.d.ts +37 -14
- package/dist/react.js +26 -15
- package/dist/scheduler-qstash.d.ts +78 -0
- package/dist/scheduler-qstash.js +499 -0
- package/dist/scheduler-task-BpzhPnRS.js +54 -0
- package/dist/{recovery-vercel.d.ts → scheduler-vercel.d.ts} +17 -24
- package/dist/scheduler-vercel.js +226 -0
- package/dist/server-CcNnFnoW.js +1405 -0
- package/dist/server-YtPq7hjw.d.ts +260 -0
- package/dist/server.d.ts +4 -155
- package/dist/server.js +2 -2
- package/dist/{log-ldf5g8Cx.d.ts → store-C3sNAaBT.d.ts} +111 -35
- package/dist/{log-yJbXUf72.js → store-N8PXxDAS.js} +1 -1
- package/dist/store-codec-DTG0Ftek.js +8 -0
- package/dist/store-memory.d.ts +11 -0
- package/dist/{log-memory.js → store-memory.js} +127 -24
- package/dist/{log-polling-6COoN60V.js → store-polling-DgrrAE3d.js} +7 -6
- package/dist/{log-postgres.d.ts → store-postgres.d.ts} +6 -6
- package/dist/{log-postgres.js → store-postgres.js} +158 -24
- package/dist/{log-redis.js → store-redis-core-DWqx3F47.js} +294 -156
- package/dist/store-redis-http.d.ts +21 -0
- package/dist/store-redis-http.js +70 -0
- package/dist/store-redis.d.ts +37 -0
- package/dist/store-redis.js +298 -0
- package/dist/{log-sqlite.d.ts → store-sqlite.d.ts} +6 -6
- package/dist/{log-sqlite.js → store-sqlite.js} +116 -22
- package/dist/{telemetry-Cso0qyHQ.d.ts → telemetry-BjYHTfh2.d.ts} +1 -1
- package/dist/testing.browser.d.ts +1 -0
- package/dist/testing.browser.js +4 -0
- package/dist/testing.d.ts +31 -0
- package/dist/testing.js +101 -0
- package/dist/wire-DCUZBUlT.js +222 -0
- package/docs/01-quickstart.mdx +4 -5
- package/docs/concepts/01-contracts.mdx +21 -17
- package/docs/concepts/02-handlers.mdx +7 -7
- package/docs/concepts/03-durability.mdx +26 -29
- package/docs/concepts/04-state.mdx +18 -21
- package/docs/guides/01-timers.mdx +154 -54
- package/docs/guides/02-cancellation.mdx +30 -4
- package/docs/guides/03-react.mdx +20 -21
- package/docs/guides/04-local-first.mdx +1 -1
- package/docs/guides/05-production.mdx +321 -60
- package/docs/guides/06-ai-agents.mdx +249 -49
- package/docs/guides/07-devtools.mdx +137 -12
- package/docs/guides/08-application-data.mdx +1 -1
- package/docs/guides/09-presence.mdx +284 -0
- package/docs/guides/10-transports.mdx +131 -0
- package/docs/index.mdx +22 -46
- package/docs/reference/01-api.mdx +751 -102
- package/docs/reference/02-errors.mdx +10 -5
- package/package.json +23 -6
- package/dist/internal-D6wNxTck.js +0 -36
- package/dist/log-memory.d.ts +0 -11
- package/dist/log-redis.d.ts +0 -31
- package/dist/recovery-vercel.js +0 -119
- package/dist/server-DJgD2YWP.js +0 -877
- package/dist/wire-BVsgR8o9.js +0 -62
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { a as EventDefs, c as PresencePatch, d as WithPresence, o as PresenceDefs, p as Reducer, r as ContractEvent, s as PresenceMap, t as AppendInput } from "./contract-jIfaR085.js";
|
|
2
|
+
//#region src/client.d.ts
|
|
3
|
+
type ConnectionStatus = "idle" | "connecting" | "live" | "closed";
|
|
4
|
+
/**
|
|
5
|
+
* The connection, as a discriminated union — impossible states are
|
|
6
|
+
* unrepresentable: an error only exists while disconnected,
|
|
7
|
+
* `reconnects` only once a connection has been attempted.
|
|
8
|
+
* "Reconnecting…" is `status === 'connecting' && reconnects > 0`.
|
|
9
|
+
*/
|
|
10
|
+
type Connection = {
|
|
11
|
+
status: "idle";
|
|
12
|
+
} | {
|
|
13
|
+
status: "connecting";
|
|
14
|
+
/** Drops of an established stream so far. `0` = first connect. */
|
|
15
|
+
reconnects: number;
|
|
16
|
+
/** Why the last connection ended; `null` on the first connect. */
|
|
17
|
+
error: Error | null;
|
|
18
|
+
} | {
|
|
19
|
+
status: "live";
|
|
20
|
+
reconnects: number;
|
|
21
|
+
} | {
|
|
22
|
+
status: "closed";
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* What `push` returns: resolves at the server ack (exactly like a
|
|
26
|
+
* plain promise — `await push(...)` gives the acked events), and
|
|
27
|
+
* carries `confirmed` for the later moment when the live stream has
|
|
28
|
+
* delivered the whole batch back and the optimistic overlay entry
|
|
29
|
+
* retired — the view now shows server truth. `confirmed` is lazy:
|
|
30
|
+
* never accessed, never created. A rejected push rejects both.
|
|
31
|
+
*/
|
|
32
|
+
type PushResult<D extends EventDefs> = Promise<ContractEvent<D>[]> & {
|
|
33
|
+
readonly confirmed: Promise<ContractEvent<D>[]>;
|
|
34
|
+
};
|
|
35
|
+
/** One immutable view of the session — stable identity between changes. */
|
|
36
|
+
type SessionSnapshot<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = WithPresence<P, {
|
|
37
|
+
/** The replicated presence map, this client included (local echo). */
|
|
38
|
+
presence: PresenceMap<P>;
|
|
39
|
+
}> & {
|
|
40
|
+
/** The live view: server events folded, optimistic pushes applied. */
|
|
41
|
+
state: S;
|
|
42
|
+
/** The observed feed `state` is folded from — server truth plus
|
|
43
|
+
* pending optimistic events (provisional indexes past the frontier). */
|
|
44
|
+
events: ContractEvent<D>[];
|
|
45
|
+
/** The stream frontier: the last server-confirmed index. This is the
|
|
46
|
+
* `lastSeenIndex` cancellation wants. */
|
|
47
|
+
index: number;
|
|
48
|
+
connection: Connection;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The presence member of a client session — intersected in via
|
|
52
|
+
* `WithPresence`, so it exists exactly when the contract declares
|
|
53
|
+
* presence fields.
|
|
54
|
+
*/
|
|
55
|
+
type SessionClientPresence<P extends PresenceDefs> = {
|
|
56
|
+
/**
|
|
57
|
+
* Fire-and-forget presence: validates locally against the reducer's
|
|
58
|
+
* presence schemas, merges into the local map immediately (the
|
|
59
|
+
* echo), and coalesces on the wire to a fixed cadence — a leading
|
|
60
|
+
* send immediately, then at most one merged send per interval,
|
|
61
|
+
* later values winning field-wise. `null` clears a field. No ack,
|
|
62
|
+
* no retry, no rollback: a lost patch is repainted by the next one.
|
|
63
|
+
* Requires the session's `participant`.
|
|
64
|
+
*/
|
|
65
|
+
setPresence(values: PresencePatch<P>["values"]): void;
|
|
66
|
+
};
|
|
67
|
+
type SessionClient<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = WithPresence<P, SessionClientPresence<P>> & {
|
|
68
|
+
readonly sessionId: string;
|
|
69
|
+
subscribe(listener: () => void): () => void;
|
|
70
|
+
getSnapshot(): SessionSnapshot<D, S, P>;
|
|
71
|
+
/**
|
|
72
|
+
* Optimistic append: validates locally against the reducer's event
|
|
73
|
+
* schemas (instant `INVALID_PAYLOAD`, no flicker), applies to the
|
|
74
|
+
* local fold, POSTs, swaps in the ack, rolls back on rejection.
|
|
75
|
+
* Auto-retries only `STORE_UNAVAILABLE`. Resolves with the appended
|
|
76
|
+
* events as the server recorded them. Overlapping calls on this
|
|
77
|
+
* handle enter the transport in invocation order without delaying
|
|
78
|
+
* their optimistic folds.
|
|
79
|
+
*/
|
|
80
|
+
push(...events: AppendInput<D>[]): PushResult<D>;
|
|
81
|
+
/** Open the live stream (idempotent while open). Reconnects with
|
|
82
|
+
* backoff and resumes from the frontier until `close()`. */
|
|
83
|
+
connect(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Stop the live stream. Not terminal: `connect()` starts it again
|
|
86
|
+
* from the current frontier — which is what makes the React
|
|
87
|
+
* StrictMode mount dance (setup → cleanup → setup) work.
|
|
88
|
+
*/
|
|
89
|
+
close(): void;
|
|
90
|
+
};
|
|
91
|
+
type SessionOptions<D extends EventDefs, S> = {
|
|
92
|
+
initialState?: S;
|
|
93
|
+
initialIndex?: number;
|
|
94
|
+
/** Server-rendered history through `initialIndex`. Seeds the event feed. */
|
|
95
|
+
initialEvents?: ContractEvent<D>[];
|
|
96
|
+
/**
|
|
97
|
+
* This client's presence identity — required to call `setPresence`.
|
|
98
|
+
* Caller-supplied (a user id, a tab nonce, a guest name): A2 does
|
|
99
|
+
* not invent an identity story. Bound once per session handle.
|
|
100
|
+
*/
|
|
101
|
+
participant?: string;
|
|
102
|
+
};
|
|
103
|
+
type A2Client<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = {
|
|
104
|
+
session(sessionId: string, options?: SessionOptions<D, S>): SessionClient<D, S, P>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* The wire the client rides. The string form is one route serving GET
|
|
108
|
+
* (SSE stream) + POST (push). `http` splits the verbs across two
|
|
109
|
+
* routes, for when platform duration limits differ per verb. `ws`
|
|
110
|
+
* rides everything over one WebSocket.
|
|
111
|
+
*/
|
|
112
|
+
type ClientApi = string | {
|
|
113
|
+
type: "http";
|
|
114
|
+
push: string;
|
|
115
|
+
stream: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: "ws";
|
|
118
|
+
url: string;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The socket surface the `ws` transport drives — satisfied structurally
|
|
122
|
+
* by the DOM `WebSocket` and Node's alike, and small enough to fake in
|
|
123
|
+
* tests.
|
|
124
|
+
*/
|
|
125
|
+
type ClientWebSocket = {
|
|
126
|
+
readonly readyState: number;
|
|
127
|
+
send(data: string): void;
|
|
128
|
+
close(code?: number, reason?: string): void;
|
|
129
|
+
addEventListener(type: "open", listener: () => void): void;
|
|
130
|
+
addEventListener(type: "message", listener: (event: {
|
|
131
|
+
data: unknown;
|
|
132
|
+
}) => void): void;
|
|
133
|
+
addEventListener(type: "close", listener: (event: {
|
|
134
|
+
code: number;
|
|
135
|
+
reason: string;
|
|
136
|
+
}) => void): void;
|
|
137
|
+
addEventListener(type: "error", listener: () => void): void;
|
|
138
|
+
};
|
|
139
|
+
type ClientWebSocketConstructor = new (url: string) => ClientWebSocket;
|
|
140
|
+
type CreateClientOptions<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = {
|
|
141
|
+
reducer: Reducer<D, S, P>;
|
|
142
|
+
/** The route (or routes) the client speaks — see `ClientApi`. */
|
|
143
|
+
api: ClientApi;
|
|
144
|
+
/** Injectable fetch — defaults to the global. */
|
|
145
|
+
fetch?: typeof globalThis.fetch;
|
|
146
|
+
/** Injectable WebSocket constructor for the `ws` api — defaults to
|
|
147
|
+
* the global. The http transports never touch it. */
|
|
148
|
+
webSocket?: ClientWebSocketConstructor;
|
|
149
|
+
/** How long an idle session keeps its in-memory identity, in
|
|
150
|
+
* milliseconds. Defaults to five minutes; `Infinity` disables GC. */
|
|
151
|
+
gcTime?: number;
|
|
152
|
+
};
|
|
153
|
+
declare function createClient<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>>(options: CreateClientOptions<D, S, P>): A2Client<D, S, P>;
|
|
154
|
+
//#endregion
|
|
155
|
+
export { Connection as a, PushResult as c, SessionOptions as d, SessionSnapshot as f, ClientWebSocketConstructor as i, SessionClient as l, ClientApi as n, ConnectionStatus as o, createClient as p, ClientWebSocket as r, CreateClientOptions as s, A2Client as t, SessionClientPresence as u };
|