@fitzzero/quickdraw-core 5.1.2 → 5.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.
Files changed (124) hide show
  1. package/README.md +793 -57
  2. package/dist/{admin-DWWrT1h6.d.ts → admin-CS7JB_UH.d.ts} +2 -2
  3. package/dist/{adminSchemas-D4bFKsrb.d.ts → adminSchemas-29cGgrg5.d.ts} +1 -1
  4. package/dist/{auth-DXiSJZaf.d.ts → auth-DtdYjrZ9.d.ts} +11 -7
  5. package/dist/{caller-BT-Mv4bD.d.ts → caller-BTwGl7vm.d.ts} +183 -15
  6. package/dist/chunk-2FDSKLBO.js +82 -0
  7. package/dist/chunk-2FDSKLBO.js.map +1 -0
  8. package/dist/{chunk-GSIPUNJL.js → chunk-64I6MYBC.js} +139 -792
  9. package/dist/chunk-64I6MYBC.js.map +1 -0
  10. package/dist/chunk-7473HK24.js +17 -0
  11. package/dist/chunk-7473HK24.js.map +1 -0
  12. package/dist/chunk-7Y5ROPXL.js +33 -0
  13. package/dist/chunk-7Y5ROPXL.js.map +1 -0
  14. package/dist/chunk-A2RBQD66.js +7 -0
  15. package/dist/chunk-A2RBQD66.js.map +1 -0
  16. package/dist/chunk-ASAMUGHG.js +651 -0
  17. package/dist/chunk-ASAMUGHG.js.map +1 -0
  18. package/dist/{chunk-B2P7AZ25.js → chunk-CYE4UBOB.js} +6 -4
  19. package/dist/chunk-CYE4UBOB.js.map +1 -0
  20. package/dist/chunk-DNP65TD5.js +832 -0
  21. package/dist/chunk-DNP65TD5.js.map +1 -0
  22. package/dist/{chunk-5CGO426C.js → chunk-GYLWEJHW.js} +5 -1
  23. package/dist/chunk-GYLWEJHW.js.map +1 -0
  24. package/dist/{chunk-AONAFOYU.js → chunk-I3JCFS7H.js} +25 -13
  25. package/dist/chunk-I3JCFS7H.js.map +1 -0
  26. package/dist/{chunk-X5CWPX7H.js → chunk-IIQ3WMJK.js} +13 -2
  27. package/dist/chunk-IIQ3WMJK.js.map +1 -0
  28. package/dist/{chunk-6K5BY47X.js → chunk-JVTONQFI.js} +1277 -277
  29. package/dist/chunk-JVTONQFI.js.map +1 -0
  30. package/dist/{chunk-RL4VKLBX.js → chunk-KKQANRLG.js} +2 -2
  31. package/dist/{chunk-RL4VKLBX.js.map → chunk-KKQANRLG.js.map} +1 -1
  32. package/dist/{chunk-GKH3LJ7N.js → chunk-MPQAT55F.js} +38 -205
  33. package/dist/chunk-MPQAT55F.js.map +1 -0
  34. package/dist/chunk-NX2V6SIL.js +202 -0
  35. package/dist/chunk-NX2V6SIL.js.map +1 -0
  36. package/dist/{chunk-7QCUX4TK.js → chunk-NZHA4TZD.js} +72 -175
  37. package/dist/chunk-NZHA4TZD.js.map +1 -0
  38. package/dist/{chunk-MBH6IDSM.js → chunk-OCZJ4EYV.js} +40 -17
  39. package/dist/chunk-OCZJ4EYV.js.map +1 -0
  40. package/dist/{chunk-RJ5I2VO3.js → chunk-PHCURHC7.js} +6 -6
  41. package/dist/chunk-PHCURHC7.js.map +1 -0
  42. package/dist/{chunk-4YO5H5ON.js → chunk-Q4OGQM5I.js} +4 -10
  43. package/dist/chunk-Q4OGQM5I.js.map +1 -0
  44. package/dist/chunk-QSU47XEX.js +13 -0
  45. package/dist/chunk-QSU47XEX.js.map +1 -0
  46. package/dist/{chunk-LCC7HNFP.js → chunk-RZXJTDH5.js} +2 -2
  47. package/dist/{chunk-Z2LZ7IZ7.js → chunk-SN3OZVEQ.js} +5 -31
  48. package/dist/chunk-SN3OZVEQ.js.map +1 -0
  49. package/dist/{chunk-Z5ILULF2.js → chunk-SQ5VUG77.js} +4 -3
  50. package/dist/{chunk-Z5ILULF2.js.map → chunk-SQ5VUG77.js.map} +1 -1
  51. package/dist/chunk-STH5DLQP.js +1192 -0
  52. package/dist/chunk-STH5DLQP.js.map +1 -0
  53. package/dist/{chunk-NMXYENH4.js → chunk-VZFJTKIW.js} +6 -6
  54. package/dist/{chunk-753VJIUP.js → chunk-X4ZU4QH5.js} +43 -9
  55. package/dist/chunk-X4ZU4QH5.js.map +1 -0
  56. package/dist/chunk-XD7SRDUY.js +188 -0
  57. package/dist/chunk-XD7SRDUY.js.map +1 -0
  58. package/dist/chunk-Z7I6SONO.js +825 -0
  59. package/dist/chunk-Z7I6SONO.js.map +1 -0
  60. package/dist/cli/quickdraw-docs.js +131 -113
  61. package/dist/cli/quickdraw-docs.js.map +1 -1
  62. package/dist/client/core.d.ts +387 -0
  63. package/dist/client/core.js +109 -0
  64. package/dist/client/core.js.map +1 -0
  65. package/dist/client/index.d.ts +30 -193
  66. package/dist/client/index.js +56 -217
  67. package/dist/client/index.js.map +1 -1
  68. package/dist/{clientTypes-hWcPUVS9.d.ts → clientTypes-CUUNJwWs.d.ts} +3 -3
  69. package/dist/{connection-CgijdGpT.d.ts → connection-2EeQ_Et0.d.ts} +16 -9
  70. package/dist/{createServer-Cp-Wk500.d.ts → createServer-Bx5HOcYK.d.ts} +37 -9
  71. package/dist/{createTestApp-BB_PkqQ7.d.ts → createTestApp-DAMANT79.d.ts} +36 -9
  72. package/dist/{envelope-DzWyIXjj.d.ts → envelope-BMBaxppV.d.ts} +200 -8
  73. package/dist/{http-DotQ5bj8.d.ts → http-YzLAar3w.d.ts} +15 -50
  74. package/dist/index.d.ts +7 -6
  75. package/dist/index.js +61 -28
  76. package/dist/index.js.map +1 -1
  77. package/dist/{infer-BmoZsL9a.d.ts → infer-Br62cnyW.d.ts} +39 -1
  78. package/dist/{metrics-DW80Exve.d.ts → metrics-CTVpw0gu.d.ts} +2 -2
  79. package/dist/parser.js +2 -1
  80. package/dist/prisma/index.d.ts +13 -6
  81. package/dist/prisma/index.js +155 -9
  82. package/dist/prisma/index.js.map +1 -1
  83. package/dist/remote-N7OUAGOW.js +15 -0
  84. package/dist/remote-N7OUAGOW.js.map +1 -0
  85. package/dist/server/auth/index.d.ts +3 -3
  86. package/dist/server/auth/index.js +5 -3
  87. package/dist/server/auth/index.js.map +1 -1
  88. package/dist/server/index.d.ts +140 -36
  89. package/dist/server/index.js +162 -55
  90. package/dist/server/index.js.map +1 -1
  91. package/dist/server/mcp/index.d.ts +34 -18
  92. package/dist/server/mcp/index.js +29 -12
  93. package/dist/server/mcp/index.js.map +1 -1
  94. package/dist/server/otel.d.ts +3 -3
  95. package/dist/{sharing-UDLn1049.d.ts → sharing-BrsmlDv_.d.ts} +3 -3
  96. package/dist/testing/client.d.ts +13 -13
  97. package/dist/testing/client.js +17 -10
  98. package/dist/testing/client.js.map +1 -1
  99. package/dist/testing/index.d.ts +49 -12
  100. package/dist/testing/index.js +102 -19
  101. package/dist/testing/index.js.map +1 -1
  102. package/dist/testing/mock.d.ts +5 -5
  103. package/dist/testing/mock.js +15 -9
  104. package/dist/tracked-BR5b2O-U.d.ts +43 -0
  105. package/dist/{types-CYliTP65.d.ts → types-CLRCQGnO.d.ts} +4 -3
  106. package/dist/types-tMagHbjy.d.ts +151 -0
  107. package/dist/utils/index.d.ts +16 -4
  108. package/dist/utils/index.js +6 -3
  109. package/package.json +5 -1
  110. package/dist/chunk-4YO5H5ON.js.map +0 -1
  111. package/dist/chunk-5CGO426C.js.map +0 -1
  112. package/dist/chunk-6K5BY47X.js.map +0 -1
  113. package/dist/chunk-753VJIUP.js.map +0 -1
  114. package/dist/chunk-7QCUX4TK.js.map +0 -1
  115. package/dist/chunk-AONAFOYU.js.map +0 -1
  116. package/dist/chunk-B2P7AZ25.js.map +0 -1
  117. package/dist/chunk-GKH3LJ7N.js.map +0 -1
  118. package/dist/chunk-GSIPUNJL.js.map +0 -1
  119. package/dist/chunk-MBH6IDSM.js.map +0 -1
  120. package/dist/chunk-RJ5I2VO3.js.map +0 -1
  121. package/dist/chunk-X5CWPX7H.js.map +0 -1
  122. package/dist/chunk-Z2LZ7IZ7.js.map +0 -1
  123. /package/dist/{chunk-LCC7HNFP.js.map → chunk-RZXJTDH5.js.map} +0 -0
  124. /package/dist/{chunk-NMXYENH4.js.map → chunk-VZFJTKIW.js.map} +0 -0
@@ -0,0 +1,387 @@
1
+ export { BreadcrumbItem, JWTPayload, NavItem, QueryClientLike, ServerCallOptions, ServerCaller, ServerCallerHeaders, ServerCallerOptions, ServerMethod, ServerMutation, ServerQuery, buildBreadcrumbs, createServerCaller, findNavItemByHref, findParentNavItem, formatCurrency, formatDate, formatDateTime, formatNumber, formatPercent, parseJWTPayload, routeRequiresAuth, truncate } from '../utils/index.js';
2
+ export { C as CollectionQueryKey, E as EntityQueryKey, K as KEY_ROOT, b as MethodKeyPrefix, M as MethodQueryKey, S as ServiceKeyPrefix, c as collectionKey, e as entityKey, m as methodKey, a as methodKeyPrefix, s as serviceKeyPrefix } from '../keys-CqKkljVN.js';
3
+ import { Q as QuickdrawConnection } from '../connection-2EeQ_Et0.js';
4
+ export { B as BackoffKind, g as BackoffWindows, C as ConnectionAuth, c as ConnectionRefusal, e as ConnectionState, b as ConnectionStatus, D as DEFAULT_BACKOFF_MS, h as DEFAULT_SUBSCRIPTION_LANE, J as JoinWait, L as LaneCallback, a as QuickdrawConnectionOptions, f as QuickdrawSocket, S as SocketClientOptions, i as SubscriptionEvent, j as SubscriptionLane, T as TopicWatch, d as createQuickdrawConnection } from '../connection-2EeQ_Et0.js';
5
+ import { k as MethodKind, J as AnyContract, aD as HostStreamName, ay as StreamItemOf, aE as HostChannelName, ab as ChannelPayloadOf } from '../infer-Br62cnyW.js';
6
+ import { aA as Version, D as CallSuccess, z as CallNotModified, q as ProtocolMismatch } from '../envelope-BMBaxppV.js';
7
+ export { ab as PeerLabel } from '../envelope-BMBaxppV.js';
8
+ import { a as PeerLink } from '../types-tMagHbjy.js';
9
+ export { b as PeerClock, c as PeerCloseReason, d as PeerLinkEvents, e as PeerLinkLag, f as PeerLinkLagOptions, g as PeerLinkState, h as PeerLinkStats, P as PeerPath } from '../types-tMagHbjy.js';
10
+ import 'socket.io-client';
11
+ import '../errors-S-bxEIBC.js';
12
+
13
+ /**
14
+ * Get the stored auth token: from `localStorage`, or from memory where it
15
+ * cannot be used; `null` without a `window`.
16
+ */
17
+ declare function getAuthToken(): string | null;
18
+ /**
19
+ * Store the auth token (in `localStorage`, else in memory) and dispatch a
20
+ * change event. Does nothing without a `window`.
21
+ */
22
+ declare function setAuthToken(token: string): void;
23
+ /**
24
+ * Remove the auth token and dispatch a change event. Does nothing without a
25
+ * `window`.
26
+ */
27
+ declare function clearAuthToken(): void;
28
+ /** Where the auth routes are, for the browser helpers. */
29
+ interface AuthRoutesTarget {
30
+ /**
31
+ * The API's URL, where `createAuthRoutes` is mounted:
32
+ * `"https://api.example.com"`. Default: `NEXT_PUBLIC_API_URL` where it can
33
+ * be read, else `http://localhost:4000`.
34
+ */
35
+ readonly apiUrl?: string;
36
+ /** The routes' `basePath`, as `createAuthRoutes` was given it. Default `/auth`. */
37
+ readonly basePath?: string;
38
+ }
39
+ /** Options of {@link signInUrl}. */
40
+ interface SignInUrlOptions extends AuthRoutesTarget {
41
+ /**
42
+ * The page to come back to: an origin or a URL on one, of which the
43
+ * routes keep the origin when `allowedOrigins` lists it, and land on
44
+ * `{origin}{successPath}`. Default: the current page's origin where there
45
+ * is a page; elsewhere the routes take their first allowed origin.
46
+ */
47
+ readonly returnTo?: string;
48
+ }
49
+ /**
50
+ * The URL that starts a sign-in with `provider`: the auth routes' `GET
51
+ * {basePath}/{provider}/start?returnTo=`, which redirects to the provider
52
+ * and, once the user consents, back to `returnTo`'s origin with the session
53
+ * cookie set (or to the routes' `errorPath` with `?error=`). Navigate to it:
54
+ * a link, or `location.assign`. Throws a `TypeError` for a provider id the
55
+ * routes cannot have (lowercase letters, digits and hyphens).
56
+ *
57
+ * @example
58
+ * <a href={signInUrl("google", { apiUrl: API_URL })}>Sign in with Google</a>
59
+ */
60
+ declare function signInUrl(provider: string, options?: SignInUrlOptions): string;
61
+ /**
62
+ * Signs out: `POST {basePath}/logout`, which revokes the request's session
63
+ * and clears its cookie, sent with the session cookie and, when one is
64
+ * stored, the bearer token; the stored token is forgotten either way.
65
+ * Rejects with a `QuickdrawError` when the server cannot be reached or
66
+ * refuses (`RATE_LIMITED`, say), so the app knows the session may still be
67
+ * live. The connection keeps the user it signed in as until it connects
68
+ * again: with cookie sessions, reconnect it (`connection.close()`, then
69
+ * `open()`), or load the next page; a provider whose `auth` was the stored
70
+ * token reconnects when the app clears it.
71
+ *
72
+ * @example
73
+ * await signOut({ apiUrl: API_URL });
74
+ */
75
+ declare function signOut(options?: AuthRoutesTarget): Promise<void>;
76
+ /** A sign-in the API's auth routes serve, as `GET {basePath}/providers` lists it ({@link authProviders}). */
77
+ interface AuthProviderInfo {
78
+ /** Its id: `signInUrl(id)` starts it; a guest's is `POST {basePath}/guest`. */
79
+ readonly id: string;
80
+ /** A name for its button: `"Google"`, `"Discord"`, `"Mock"`, `"Guest"`, or an OAuth provider's own. */
81
+ readonly name: string;
82
+ /** `"oauth"` (a redirecting provider), `"mock"` (the development picker) or `"guest"`. */
83
+ readonly kind: "oauth" | "mock" | "guest";
84
+ }
85
+ /**
86
+ * The sign-ins the API serves, in the order its routes list them: `GET
87
+ * {basePath}/providers` (finding F9.1 of the owner's QA of the template), so
88
+ * a login page renders a button only for a provider that is there, whatever
89
+ * the web app was built with: a provider whose credentials the server lacks
90
+ * is not listed, nor the mock where it is off. Rejects with a
91
+ * `QuickdrawError` when the server cannot be reached or refuses.
92
+ *
93
+ * @example
94
+ * const { data: providers = [] } = useQuery({
95
+ * queryKey: ["auth", "providers"],
96
+ * queryFn: () => authProviders({ apiUrl: API_URL }),
97
+ * });
98
+ */
99
+ declare function authProviders(options?: AuthRoutesTarget): Promise<readonly AuthProviderInfo[]>;
100
+ /**
101
+ * Signs the user out everywhere: `POST {basePath}/logout-all`, which
102
+ * revokes every session of the user (the app's `onRevoke` can disconnect
103
+ * their sockets) and clears this browser's cookie; the stored token is
104
+ * forgotten either way. Rejects with `UNAUTHENTICATED` when the request
105
+ * carries no live session, and with a `QuickdrawError` when the server
106
+ * cannot be reached or refuses.
107
+ */
108
+ declare function signOutEverywhere(options?: AuthRoutesTarget): Promise<void>;
109
+
110
+ /** One call, as {@link call} takes it. */
111
+ interface CallRequest {
112
+ /** The service's name on the wire: the contract's `name`. */
113
+ readonly service: string;
114
+ readonly method: string;
115
+ /** The input; left out of the envelope when `undefined`. */
116
+ readonly input?: unknown;
117
+ /** The method's kind, which picks the backoff a `RATE_LIMITED` answer starts. Default `"query"`. */
118
+ readonly kind?: MethodKind;
119
+ /** Aborting it cancels the call. */
120
+ readonly signal?: AbortSignal;
121
+ /** How long to wait for the answer. Default: the connection's `timeoutMs`. */
122
+ readonly timeoutMs?: number;
123
+ /** The version of the result the caller holds; the server answers "not modified" while it is current. */
124
+ readonly v?: Version;
125
+ /**
126
+ * Called with the result the moment the reply arrives, before any frame
127
+ * the server sent after it is handled; the returned promise settles only
128
+ * after more microtasks, and a client on Node can handle several frames in
129
+ * between. What must follow reply order goes here: an optimistic layer
130
+ * ends at the first newer frame after its call's reply.
131
+ */
132
+ readonly onReply?: (result: CallResult) => void;
133
+ }
134
+ /** What a call resolves with: the data, or "not modified" when the `v` it sent is current. */
135
+ type CallResult<Output = unknown> = CallSuccess<Output> | CallNotModified;
136
+ /** True when the server answered that the caller's version is current. */
137
+ declare function isNotModified(result: CallResult): result is CallNotModified;
138
+ /**
139
+ * True when `error` leaves a call's outcome unknown: a `TIMEOUT` (the
140
+ * server may still be running it, or ran it and the answer was lost), or the
141
+ * `INTERNAL` of a call whose connection dropped after it was sent. The write
142
+ * may have been made: before sending it again, make sure the call is
143
+ * idempotent (a create that carries an id the client made, which the server
144
+ * keeps, fails `CONFLICT` the second time instead of writing a second row).
145
+ * False for a refusal, and for a call that was never sent.
146
+ *
147
+ * @example
148
+ * onError: (error) => setStatus(isUnknownOutcome(error) ? "checking" : "failed")
149
+ */
150
+ declare function isUnknownOutcome(error: unknown): boolean;
151
+ /**
152
+ * Calls `request.method` of `request.service` over `connection`. Resolves
153
+ * with `{ ok: true, d, v? }`, or `{ ok: true, nm: true, v }` when the `v` it
154
+ * sent is current; rejects with a `QuickdrawError` (see the top of this file
155
+ * for which code when).
156
+ *
157
+ * @example
158
+ * const reply = await call(connection, { service: "taskService", method: "get", input: { id } });
159
+ * const task = isNotModified(reply) ? cached : reply.d;
160
+ */
161
+ declare function call<Output = unknown>(connection: QuickdrawConnection, request: CallRequest): Promise<CallResult<Output>>;
162
+ /**
163
+ * Calls a method and resolves with its data. For a caller that sends no
164
+ * version, which is never answered "not modified".
165
+ */
166
+ declare function callData<Output = unknown>(connection: QuickdrawConnection, request: Omit<CallRequest, "v">): Promise<Output>;
167
+ /**
168
+ * The default `retry` of query hooks: one more attempt after an `INTERNAL`
169
+ * error, which includes a dropped connection, or an error that is not a
170
+ * `QuickdrawError`; none for any other code. A `TIMEOUT` is not retried,
171
+ * because the server may still be running the call, and `RATE_LIMITED`
172
+ * waits for the backoff instead.
173
+ */
174
+ declare function shouldRetry(failureCount: number, error: unknown): boolean;
175
+
176
+ /** The default `onProtocolMismatch`: reloads the page once per session and server protocol. */
177
+ declare function reloadOncePerSession(mismatch: ProtocolMismatch): void;
178
+
179
+ /**
180
+ * A new id for a row the client creates and the server keeps: a version 4
181
+ * UUID, from `crypto.randomUUID()`, or from `crypto.getRandomValues()` where
182
+ * that is missing (a page over plain http, which browsers do not give
183
+ * `randomUUID`). Give it to an item an optimistic update adds and to the
184
+ * create's input, so the scope's next load can find the item after a lost
185
+ * answer and `retry()` cannot write twice. Throws a `TypeError` in a runtime
186
+ * without Web Crypto.
187
+ *
188
+ * @example
189
+ * create.mutate({ id: newId(), chatId, content });
190
+ */
191
+ declare function newId(): string;
192
+
193
+ /** A STUN or TURN server, as `RTCIceServer` takes it. */
194
+ interface PeerIceServer {
195
+ urls: string | string[];
196
+ username?: string;
197
+ credential?: string;
198
+ }
199
+ /** What a link makes its `RTCPeerConnection` with. */
200
+ interface PeerConnectionConfig {
201
+ iceServers: PeerIceServer[];
202
+ }
203
+
204
+ /**
205
+ * When a link uses the server's relay: `auto` when the direct path cannot
206
+ * form or fails, `always` instead of it (no WebRTC at all), `never` (a link
207
+ * whose direct path fails closes).
208
+ */
209
+ type RelayMode = "auto" | "always" | "never";
210
+ /** Options of {@link createPeerLink}. */
211
+ interface PeerLinkOptions {
212
+ /** The app room both sockets are in; the link belongs to it, and ends when this socket leaves it. */
213
+ readonly room: string;
214
+ /** The peer's socket id. */
215
+ readonly to: string;
216
+ /**
217
+ * Whether this side makes the offer. One side of a link does; when both
218
+ * do, the side whose socket id sorts after the other's answers instead.
219
+ */
220
+ readonly offerer: boolean;
221
+ /**
222
+ * STUN and TURN servers. Default Google's and Cloudflare's public STUN
223
+ * servers, and no TURN: a pair that cannot reach each other uses the
224
+ * relay, which is expected, not an error.
225
+ */
226
+ readonly iceServers?: readonly PeerIceServer[];
227
+ /** When the link may use the server's relay. Default `"auto"`. */
228
+ readonly relay?: RelayMode;
229
+ /**
230
+ * Makes the link's `RTCPeerConnection`. Default the platform's
231
+ * `RTCPeerConnection` when it has one; React Native passes
232
+ * react-native-webrtc's, Node a WebRTC package's. A link without one uses
233
+ * the relay.
234
+ */
235
+ readonly peerConnection?: (configuration: PeerConnectionConfig) => unknown;
236
+ }
237
+ /** The STUN servers a link asks by default. */
238
+ declare const DEFAULT_ICE_SERVERS: readonly PeerIceServer[];
239
+ /**
240
+ * Opens a link to socket `options.to` in app room `options.room`, over
241
+ * WebRTC data channels when it can and the server's relay when it cannot.
242
+ * The server must serve peer links (`createServer({ peers: true })`), and
243
+ * both sockets must be in the room. Throws a `TypeError` for bad options,
244
+ * or when the connection has a link to that peer in that room already.
245
+ *
246
+ * @example
247
+ * const link = createPeerLink(connection, { room: "match:7", to: rivalSocketId, offerer: true });
248
+ * link.on("message", (data, label) => applyRemote(data));
249
+ * link.on("open", () => link.send("rel", { hello: "rival" }));
250
+ */
251
+ declare function createPeerLink(connection: QuickdrawConnection, options: PeerLinkOptions): PeerLink;
252
+ /** A socket of the room signalled this one with no link to it: a link it asks for. */
253
+ interface PeerRequest {
254
+ readonly room: string;
255
+ /** The peer's socket id. */
256
+ readonly from: string;
257
+ /** The peer's user, as the server named it. */
258
+ readonly userId: string;
259
+ /** Answers with a link: `createPeerLink(connection, { room, to: from, offerer: false, ...options })`. */
260
+ accept(options?: Omit<PeerLinkOptions, "room" | "to" | "offerer">): PeerLink;
261
+ /** Refuses: the peer's link closes, with `bye`. */
262
+ reject(): void;
263
+ }
264
+ /**
265
+ * Calls `listener` when a socket of an app room this connection's socket is
266
+ * in signals it with no link to it yet: answer with `request.accept()` (or
267
+ * `createPeerLink` with `offerer: false`) within 15 seconds, or
268
+ * `request.reject()`. Returns its removal.
269
+ */
270
+ declare function onPeerRequest(connection: QuickdrawConnection, listener: (request: PeerRequest) => void): () => void;
271
+
272
+ /** A peer of a host: its socket and its user, as the server named them, and its link. */
273
+ interface HostPeer {
274
+ readonly socketId: string;
275
+ readonly userId: string;
276
+ /**
277
+ * The host's end of the peer's link: its `clock` (the peer's round trip,
278
+ * `rtt`) and `setLag`, which lags the peer's messages both ways. The
279
+ * host's own client has one too, in process.
280
+ */
281
+ readonly link: PeerLink;
282
+ }
283
+ /** What a host-served channel's handler receives beside the payload. */
284
+ interface HostChannelContext {
285
+ /** Who sent it: the user the server named for the peer's socket, and the peer's link. */
286
+ readonly peer: HostPeer;
287
+ /** The host's room. */
288
+ readonly room: string;
289
+ }
290
+
291
+ /** A host-served channel's handler: it runs once per message, with the payload its schema parsed. */
292
+ type HostChannelHandler<Payload> = (payload: Payload, ctx: HostChannelContext) => void;
293
+ /** One host-served stream's options. */
294
+ interface HostStreamOptions<Item> {
295
+ /**
296
+ * Computes a subscriber's seed when it subscribes, at once: the current
297
+ * state, where the items that follow are deltas. Each item is checked
298
+ * against the stream's schema. Without it the seed is the latest items
299
+ * pushed to the scope, as many as the contract's `seed` (default none).
300
+ */
301
+ readonly seed?: (scope: string) => readonly Item[];
302
+ }
303
+ /**
304
+ * `defineHost`'s second argument: one handler per host-served channel of
305
+ * the contract, and options per host-served stream.
306
+ */
307
+ type HostImplementation<C extends AnyContract> = {
308
+ readonly streams?: {
309
+ readonly [K in HostStreamName<C>]?: HostStreamOptions<StreamItemOf<C, K>>;
310
+ };
311
+ } & ([HostChannelName<C>] extends [never] ? {
312
+ readonly channels?: Readonly<Record<string, never>>;
313
+ } : {
314
+ readonly channels: {
315
+ readonly [K in HostChannelName<C>]: HostChannelHandler<ChannelPayloadOf<C, K>>;
316
+ };
317
+ });
318
+ /** A host-served stream, as its host pushes to it. */
319
+ interface HostStream<Item> {
320
+ /**
321
+ * Sends `item` to the subscribers of the feed of `scope`, after checking
322
+ * it against the stream's schema (a `TypeError` when it fails), and keeps
323
+ * it for the seed. A `RangeError` for an item over the message limit
324
+ * (`limits.peers.maxMessageBytes` with its message).
325
+ */
326
+ push(scope: string, item: Item): void;
327
+ }
328
+ /** A room served by its host's client. */
329
+ interface Host<C extends AnyContract> {
330
+ readonly room: string;
331
+ /**
332
+ * The peers linked to the host now, each with the host's end of its link
333
+ * (this client too, in process, while its own channels or feeds use the
334
+ * room).
335
+ */
336
+ readonly peers: readonly HostPeer[];
337
+ /** A host-served stream of the contract. */
338
+ stream<K extends HostStreamName<C>>(name: K): HostStream<StreamItemOf<C, K>>;
339
+ /** Stops serving the room: closes every peer's link, and answers no request of it. */
340
+ close(): void;
341
+ }
342
+ /** What `defineHost` returns: the contract, and how to serve one of its rooms. */
343
+ interface HostDefinition<C extends AnyContract> {
344
+ readonly contract: C;
345
+ /**
346
+ * Serves app room `room` on `connection`, whose socket a method made the
347
+ * room's host (`ctx.rooms.setHost`). Call it once per room, and `close()`
348
+ * when the socket is no longer the host (`onHostChange`, a reconnect).
349
+ */
350
+ serve(connection: QuickdrawConnection, options: {
351
+ readonly room: string;
352
+ }): Host<C>;
353
+ }
354
+ /**
355
+ * Declares how a client serves a contract's host-served channels and
356
+ * streams (`serve: "host"`) as the host of an app room: one handler per
357
+ * channel, and options per stream. Throws a `TypeError` for a handler a
358
+ * host-served channel lacks, or for a member the room's host does not
359
+ * serve.
360
+ *
361
+ * @example
362
+ * const worldHost = defineHost(game, {
363
+ * channels: { move: (move, { peer }) => world.input(peer.userId, move) },
364
+ * streams: { world: { seed: () => [world.snapshot()] } },
365
+ * });
366
+ * const host = worldHost.serve(connection, { room: `world:${worldId}` });
367
+ * host.stream("world").push(worldId, world.snapshot());
368
+ */
369
+ declare function defineHost<const C extends AnyContract>(contract: C, implementation: HostImplementation<C>): HostDefinition<C>;
370
+
371
+ /** Hears a room's host change: its socket id, or `null` when the room has none now. */
372
+ type HostListener = (room: string, host: string | null) => void;
373
+ /**
374
+ * The host of app room `room` (host mode): the socket id the server named
375
+ * in `qd:host`, or `null` when the room has none or this connection's
376
+ * socket is not in it. Without React, call it (or `onHostChange`) before
377
+ * the joining call, so the connection hears the room's host as it joins.
378
+ */
379
+ declare function hostOf(connection: QuickdrawConnection, room: string): string | null;
380
+ /**
381
+ * Calls `listener(room, host)` whenever the host of a room this
382
+ * connection's socket is in changes (`null`: none now, or the socket left
383
+ * the room or disconnected); returns its removal.
384
+ */
385
+ declare function onHostChange(connection: QuickdrawConnection, listener: HostListener): () => void;
386
+
387
+ export { type AuthProviderInfo, type AuthRoutesTarget, type CallRequest, type CallResult, DEFAULT_ICE_SERVERS, type Host, type HostChannelContext, type HostChannelHandler, type HostDefinition, type HostImplementation, type HostListener, type HostPeer, type HostStream, type HostStreamOptions, type PeerConnectionConfig, type PeerIceServer, PeerLink, type PeerLinkOptions, type PeerRequest, QuickdrawConnection, type RelayMode, type SignInUrlOptions, authProviders, call, callData, clearAuthToken, createPeerLink, defineHost, getAuthToken, hostOf, isNotModified, isUnknownOutcome, newId, onHostChange, onPeerRequest, reloadOncePerSession, setAuthToken, shouldRetry, signInUrl, signOut, signOutEverywhere };
@@ -0,0 +1,109 @@
1
+ import {
2
+ authProviders,
3
+ clearAuthToken,
4
+ defineHost,
5
+ getAuthToken,
6
+ newId,
7
+ setAuthToken,
8
+ signInUrl,
9
+ signOut,
10
+ signOutEverywhere
11
+ } from "../chunk-Z7I6SONO.js";
12
+ import {
13
+ DEFAULT_ICE_SERVERS,
14
+ createPeerLink,
15
+ onPeerRequest
16
+ } from "../chunk-DNP65TD5.js";
17
+ import {
18
+ buildBreadcrumbs,
19
+ createServerCaller,
20
+ findNavItemByHref,
21
+ findParentNavItem,
22
+ formatCurrency,
23
+ formatDate,
24
+ formatDateTime,
25
+ formatNumber,
26
+ formatPercent,
27
+ parseJWTPayload,
28
+ routeRequiresAuth,
29
+ truncate
30
+ } from "../chunk-CYE4UBOB.js";
31
+ import "../chunk-ASAMUGHG.js";
32
+ import {
33
+ call,
34
+ callData,
35
+ isNotModified,
36
+ isUnknownOutcome,
37
+ shouldRetry
38
+ } from "../chunk-NX2V6SIL.js";
39
+ import {
40
+ DEFAULT_BACKOFF_MS,
41
+ DEFAULT_SUBSCRIPTION_LANE,
42
+ createQuickdrawConnection,
43
+ hostOf,
44
+ onHostChange,
45
+ reloadOncePerSession
46
+ } from "../chunk-STH5DLQP.js";
47
+ import {
48
+ KEY_ROOT,
49
+ collectionKey,
50
+ entityKey,
51
+ methodKey,
52
+ methodKeyPrefix,
53
+ serviceKeyPrefix
54
+ } from "../chunk-IIQ3WMJK.js";
55
+ import "../chunk-7473HK24.js";
56
+ import "../chunk-2FDSKLBO.js";
57
+ import "../chunk-MPQAT55F.js";
58
+ import "../chunk-A2RBQD66.js";
59
+ import "../chunk-X4ZU4QH5.js";
60
+ import "../chunk-GYLWEJHW.js";
61
+ import "../chunk-47AEXVDM.js";
62
+ import "../chunk-SN3OZVEQ.js";
63
+ import "../chunk-7Y5ROPXL.js";
64
+ import "../chunk-Q4OGQM5I.js";
65
+ import "../chunk-QSU47XEX.js";
66
+ export {
67
+ DEFAULT_BACKOFF_MS,
68
+ DEFAULT_ICE_SERVERS,
69
+ DEFAULT_SUBSCRIPTION_LANE,
70
+ KEY_ROOT,
71
+ authProviders,
72
+ buildBreadcrumbs,
73
+ call,
74
+ callData,
75
+ clearAuthToken,
76
+ collectionKey,
77
+ createPeerLink,
78
+ createQuickdrawConnection,
79
+ createServerCaller,
80
+ defineHost,
81
+ entityKey,
82
+ findNavItemByHref,
83
+ findParentNavItem,
84
+ formatCurrency,
85
+ formatDate,
86
+ formatDateTime,
87
+ formatNumber,
88
+ formatPercent,
89
+ getAuthToken,
90
+ hostOf,
91
+ isNotModified,
92
+ isUnknownOutcome,
93
+ methodKey,
94
+ methodKeyPrefix,
95
+ newId,
96
+ onHostChange,
97
+ onPeerRequest,
98
+ parseJWTPayload,
99
+ reloadOncePerSession,
100
+ routeRequiresAuth,
101
+ serviceKeyPrefix,
102
+ setAuthToken,
103
+ shouldRetry,
104
+ signInUrl,
105
+ signOut,
106
+ signOutEverywhere,
107
+ truncate
108
+ };
109
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}