@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
@@ -10,23 +10,18 @@ import {
10
10
  createBinding,
11
11
  createInvalidationCoordinator,
12
12
  createMutationTrace,
13
- createQuickdrawConnection,
14
13
  entityScopes,
15
14
  entryQuery,
16
15
  feedKey,
17
16
  invalidateWith,
18
- isTimeLimit,
19
17
  isWatchedQuery,
20
18
  liveDataOf,
21
19
  loopGuardOf,
22
20
  newItem,
23
- notifyEach,
24
21
  overlaysOf,
25
22
  reconnectJitter,
26
23
  refetchOnAccessChanges,
27
24
  registerQuery,
28
- reloadOncePerSession,
29
- retryAfterOf,
30
25
  searchCall,
31
26
  searchTargetOf,
32
27
  serverStateOf,
@@ -43,167 +38,45 @@ import {
43
38
  useQuickdrawContext,
44
39
  userOf,
45
40
  viewPredicate
46
- } from "./chunk-GSIPUNJL.js";
41
+ } from "./chunk-64I6MYBC.js";
47
42
  import {
48
- CLIENT_EVENTS,
49
- SERVICE_TOPIC,
50
- collectionTopic
51
- } from "./chunk-753VJIUP.js";
43
+ call,
44
+ callData,
45
+ channelRoomOf,
46
+ isNotModified,
47
+ isUnknownOutcome,
48
+ shouldRetry,
49
+ streamRoomOf
50
+ } from "./chunk-NX2V6SIL.js";
52
51
  import {
53
- isScopedStream
54
- } from "./chunk-5CGO426C.js";
52
+ createQuickdrawConnection,
53
+ hostLinksOf,
54
+ hostsOf,
55
+ mayConnect,
56
+ reloadOncePerSession
57
+ } from "./chunk-STH5DLQP.js";
55
58
  import {
56
59
  buildCaller,
57
60
  collectionKey,
58
61
  entityKey,
59
62
  methodKey,
60
63
  methodKeyPrefix
61
- } from "./chunk-X5CWPX7H.js";
64
+ } from "./chunk-IIQ3WMJK.js";
65
+ import {
66
+ CLIENT_EVENTS,
67
+ SERVICE_TOPIC,
68
+ collectionTopic
69
+ } from "./chunk-X4ZU4QH5.js";
70
+ import {
71
+ isHostServed,
72
+ isScopedStream
73
+ } from "./chunk-GYLWEJHW.js";
74
+ import {
75
+ QuickdrawError
76
+ } from "./chunk-Q4OGQM5I.js";
62
77
  import {
63
- QuickdrawError,
64
- fromWire,
65
78
  isRecord
66
- } from "./chunk-4YO5H5ON.js";
67
-
68
- // src/client/call.ts
69
- var UNSENT_TIMEOUT = "operation has timed out";
70
- function isNotModified(result) {
71
- return result.nm === true;
72
- }
73
- function cancelledError() {
74
- return new QuickdrawError("CANCELLED", "The call was cancelled");
75
- }
76
- function internalError(message) {
77
- return new QuickdrawError("INTERNAL", message);
78
- }
79
- var lostInFlight = /* @__PURE__ */ new WeakSet();
80
- function isUnknownOutcome(error) {
81
- return error instanceof QuickdrawError && (error.code === "TIMEOUT" || lostInFlight.has(error));
82
- }
83
- function lostError() {
84
- const error = internalError("No answer: the connection to the server is down");
85
- lostInFlight.add(error);
86
- return error;
87
- }
88
- function refusedBeforeSending(connection, kind, signal) {
89
- if (signal?.aborted === true) {
90
- return cancelledError();
91
- }
92
- const { socket } = connection;
93
- if (!socket.connected && !socket.active) {
94
- return internalError("Not connected to the server");
95
- }
96
- const remaining = connection.backoffRemaining(kind);
97
- if (remaining > 0) {
98
- return new QuickdrawError(
99
- "RATE_LIMITED",
100
- `Waiting before more ${kind} calls: the server answered RATE_LIMITED`,
101
- { retryAfterMs: Math.ceil(remaining) }
102
- );
103
- }
104
- return void 0;
105
- }
106
- function envelopeOf(id, request) {
107
- return {
108
- id,
109
- s: request.service,
110
- m: request.method,
111
- ...request.input === void 0 ? {} : { i: request.input },
112
- ...request.v === void 0 ? {} : { v: request.v }
113
- };
114
- }
115
- function readReply(connection, kind, reply) {
116
- if (isRecord(reply) && reply.ok === true) {
117
- const versioned = typeof reply.v === "string" || typeof reply.v === "number";
118
- if (reply.nm === true && !versioned) {
119
- return internalError("The server answered not modified without a version");
120
- }
121
- return reply;
122
- }
123
- if (isRecord(reply) && reply.ok === false) {
124
- const error = fromWire(reply.e);
125
- if (error.code === "RATE_LIMITED") {
126
- connection.reportRateLimited(kind, retryAfterOf(error));
127
- }
128
- return error;
129
- }
130
- return internalError("The server's reply is not a call reply");
131
- }
132
- function isQueuedCall(data, id) {
133
- return Array.isArray(data) && data[0] === CLIENT_EVENTS.call && isRecord(data[1]) && data[1].id === id;
134
- }
135
- function cancelCall(socket, id) {
136
- const queued = socket.sendBuffer.findIndex((packet) => isQueuedCall(packet.data, id));
137
- if (queued >= 0) {
138
- socket.sendBuffer.splice(queued, 1);
139
- } else if (socket.connected) {
140
- socket.emit(CLIENT_EVENTS.cancel, { id });
141
- }
142
- }
143
- function call(connection, request) {
144
- const kind = request.kind ?? "query";
145
- const { signal } = request;
146
- const refused = refusedBeforeSending(connection, kind, signal);
147
- if (refused !== void 0) {
148
- return Promise.reject(refused);
149
- }
150
- const { socket } = connection;
151
- const timeoutMs = request.timeoutMs ?? connection.timeoutMs;
152
- if (!isTimeLimit(timeoutMs)) {
153
- return Promise.reject(
154
- new TypeError(
155
- "call: timeoutMs must be a number of milliseconds, above 0 and at most 2^31 - 1"
156
- )
157
- );
158
- }
159
- const id = connection.nextCallId();
160
- return new Promise((resolve, reject) => {
161
- let settled = false;
162
- const settle = (outcome) => {
163
- if (settled) {
164
- return;
165
- }
166
- settled = true;
167
- signal?.removeEventListener("abort", onAbort);
168
- if (outcome instanceof QuickdrawError) {
169
- reject(outcome);
170
- } else {
171
- notifyEach([request.onReply], (onReply) => {
172
- onReply?.(outcome);
173
- });
174
- resolve(outcome);
175
- }
176
- };
177
- function onAbort() {
178
- cancelCall(socket, id);
179
- settle(cancelledError());
180
- }
181
- socket.timeout(timeoutMs).emit(CLIENT_EVENTS.call, envelopeOf(id, request), (error, reply) => {
182
- if (error === null) {
183
- settle(readReply(connection, kind, reply));
184
- } else if (error instanceof QuickdrawError) {
185
- settle(error);
186
- } else if (socket.connected) {
187
- settle(new QuickdrawError("TIMEOUT", `No answer within ${timeoutMs} ms`));
188
- } else if (error.message === UNSENT_TIMEOUT) {
189
- settle(internalError("No answer: the connection to the server is down"));
190
- } else {
191
- settle(lostError());
192
- }
193
- });
194
- signal?.addEventListener("abort", onAbort, { once: true });
195
- });
196
- }
197
- async function callData(connection, request) {
198
- const result = await call(connection, request);
199
- if (isNotModified(result)) {
200
- throw internalError("The server answered not modified to a call that sent no version");
201
- }
202
- return result.d;
203
- }
204
- function shouldRetry(failureCount, error) {
205
- return failureCount < 1 && (!(error instanceof QuickdrawError) || error.code === "INTERNAL");
206
- }
79
+ } from "./chunk-QSU47XEX.js";
207
80
 
208
81
  // src/client/live/useSearch.ts
209
82
  import { useQuery as useQuery2 } from "@tanstack/react-query";
@@ -310,7 +183,7 @@ async function fetchVersioned(connection, queryClient, query, signal) {
310
183
  return fetchFresh(connection, query, signal);
311
184
  }
312
185
  async function helloKnown(connection, signal) {
313
- const ready = () => connection.getState().hello !== null || !connection.socket.active || signal?.aborted === true;
186
+ const ready = () => connection.getState().hello !== null || !mayConnect(connection) || signal?.aborted === true;
314
187
  if (ready()) {
315
188
  return;
316
189
  }
@@ -356,7 +229,9 @@ async function fetchMethodQuery(connection, queryClient, query, signal) {
356
229
  }
357
230
 
358
231
  // src/client/queryHooks.ts
359
- import { hashKey } from "@tanstack/react-query";
232
+ import {
233
+ hashKey
234
+ } from "@tanstack/react-query";
360
235
  import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
361
236
  function watchedModelsOf(target) {
362
237
  const { watch } = target;
@@ -465,6 +340,19 @@ function useOverlaySelect(queryClient, target, select) {
465
340
  };
466
341
  }, [shape, view, select]);
467
342
  }
343
+ function placeholderFromCache(queryClient, placeholderData) {
344
+ if (typeof placeholderData !== "function") {
345
+ return placeholderData;
346
+ }
347
+ const asked = placeholderData;
348
+ const fromCache = (previousData, previousQuery) => previousQuery === void 0 || queryClient.getQueryCache().get(previousQuery.queryHash) === previousQuery ? asked(previousData, previousQuery) : void 0;
349
+ return fromCache;
350
+ }
351
+ function placeholderOption(queryClient, queryKey, options) {
352
+ const keyDefaults = queryClient.getQueryDefaults(queryKey);
353
+ const given = "placeholderData" in options ? options.placeholderData : Object.hasOwn(keyDefaults, "placeholderData") ? keyDefaults.placeholderData : queryClient.getDefaultOptions().queries?.placeholderData;
354
+ return placeholderFromCache(queryClient, given);
355
+ }
468
356
  function hiddenResult(result) {
469
357
  return {
470
358
  ...result,
@@ -725,6 +613,7 @@ function useMethodQuery(target, input, options = {}) {
725
613
  enabled: live ? enabled ?? true : false,
726
614
  retry: retry ?? shouldRetry,
727
615
  structuralSharing: shareKeepingVersion(structuralSharing),
616
+ placeholderData: placeholderOption(queryClient, queryKey, options),
728
617
  ...shown2 === void 0 ? {} : { select: shown2 }
729
618
  });
730
619
  return awaiting ? hiddenResult(result) : result;
@@ -939,17 +828,25 @@ function clientAdminNamespace(contract, methods) {
939
828
 
940
829
  // src/client/live/useChannel.ts
941
830
  import { useCallback, useMemo as useMemo4 } from "react";
942
- function useChannel(service, channel) {
831
+ function useChannel(service, channel, def) {
943
832
  const { connection } = useQuickdrawContext(`${service}.${channel}.useChannel`);
944
833
  const state = useConnectionState(connection);
945
834
  const send = useCallback(
946
835
  (payload) => {
947
836
  const { socket } = connection;
948
- if (socket.connected) {
949
- socket.volatile.emit(CLIENT_EVENTS.channel, [service, channel, payload]);
837
+ if (!socket.connected) {
838
+ return;
839
+ }
840
+ if (def !== void 0 && isHostServed(def)) {
841
+ const room = channelRoomOf(def, payload, hostsOf(connection).rooms.keys());
842
+ if (room !== void 0) {
843
+ hostLinksOf(connection).send(room, service, channel, payload);
844
+ }
845
+ return;
950
846
  }
847
+ socket.volatile.emit(CLIENT_EVENTS.channel, [service, channel, payload]);
951
848
  },
952
- [connection, service, channel]
849
+ [connection, service, channel, def]
953
850
  );
954
851
  const isReady = state.status === "connected" && state.hello !== null;
955
852
  return useMemo4(() => ({ send, isReady }), [send, isReady]);
@@ -1016,13 +913,16 @@ function streamMember(target) {
1016
913
  }
1017
914
  function realtimeMembers(contract) {
1018
915
  const service = contract.name;
1019
- const streams = Object.entries(contract.streams).map(([stream, def]) => [
1020
- stream,
1021
- streamMember(Object.freeze({ service, stream, scoped: isScopedStream(def) }))
1022
- ]);
1023
- const channels = Object.keys(contract.channels).map((channel) => [
916
+ const streams = Object.entries(contract.streams).map(([stream, def]) => {
917
+ const host = isHostServed(def) ? { host: (scope) => streamRoomOf(def, scope) } : {};
918
+ return [
919
+ stream,
920
+ streamMember(Object.freeze({ service, stream, scoped: isScopedStream(def), ...host }))
921
+ ];
922
+ });
923
+ const channels = Object.entries(contract.channels).map(([channel, def]) => [
1024
924
  channel,
1025
- Object.freeze({ useChannel: () => useChannel(service, channel) })
925
+ Object.freeze({ useChannel: () => useChannel(service, channel, def) })
1026
926
  ]);
1027
927
  const events = Object.keys(contract.events).map((event) => [
1028
928
  event,
@@ -1244,9 +1144,11 @@ function searchMember(target, definition, contract) {
1244
1144
  var RESERVED_KEYS = ["invalidate"];
1245
1145
  function queryMember(binding, target, extra) {
1246
1146
  const key = (input) => methodKey(target.service, target.method, input);
1147
+ const defaults = target.queryDefaults;
1247
1148
  const member = Object.freeze({
1248
1149
  ...extra,
1249
- useQuery: (input, options) => useMethodQuery(target, input, options),
1150
+ // The caller's options over the method's defaults (the admin kit's reads of rows: `staleTime: 0`).
1151
+ useQuery: (input, options) => useMethodQuery(target, input, defaults === void 0 ? options : { ...defaults, ...options }),
1250
1152
  call: async (input, options) => await callData(connectionOf(binding, target, "call"), {
1251
1153
  ...target,
1252
1154
  input,
@@ -1399,15 +1301,10 @@ function useQuickdraw() {
1399
1301
  }
1400
1302
 
1401
1303
  export {
1402
- isNotModified,
1403
- isUnknownOutcome,
1404
- call,
1405
- callData,
1406
- shouldRetry,
1407
1304
  useLiveData,
1408
1305
  SEARCH_DEBOUNCE_MS,
1409
1306
  createQuickdrawClient,
1410
1307
  QuickdrawProvider,
1411
1308
  useQuickdraw
1412
1309
  };
1413
- //# sourceMappingURL=chunk-7QCUX4TK.js.map
1310
+ //# sourceMappingURL=chunk-NZHA4TZD.js.map