@questpie/tanstack-query 3.15.2 → 3.16.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.
Files changed (2) hide show
  1. package/dist/index.mjs +23 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -3,6 +3,25 @@ import { buildCollectionTopic, buildCollectionTopic as buildCollectionTopic$1, b
3
3
 
4
4
  //#region src/index.ts
5
5
  const defaultErrorMap = (error) => error instanceof Error ? error : new Error(typeof error === "string" ? error : "Unknown error");
6
+ const isNonRetryableError = (error) => Boolean(error && typeof error === "object" && "retryable" in error && error.retryable === false);
7
+ const mapRealtimeError = (error, errorMap) => {
8
+ const mapped = errorMap(error);
9
+ if (isNonRetryableError(error) && (!mapped || typeof mapped !== "object" || !("retryable" in mapped))) {
10
+ if (mapped && typeof mapped === "object" && Object.isExtensible(mapped)) {
11
+ Object.defineProperty(mapped, "retryable", {
12
+ value: false,
13
+ enumerable: true
14
+ });
15
+ return mapped;
16
+ }
17
+ return Object.assign(/* @__PURE__ */ new Error("Non-retryable realtime query failed"), {
18
+ cause: mapped,
19
+ retryable: false
20
+ });
21
+ }
22
+ return mapped;
23
+ };
24
+ const realtimeRetry = (failureCount, error) => !isNonRetryableError(error) && failureCount < 3;
6
25
  const buildKey = (prefix, parts) => prefix.length ? [...prefix, ...parts] : parts;
7
26
  const sanitizeKeyPart = (value) => {
8
27
  if (value === null || value === void 0) return value;
@@ -43,7 +62,7 @@ async function* streamRealtimeQuery(options) {
43
62
  try {
44
63
  for await (const snapshot of realtime.stream(topic, signal)) yield snapshot;
45
64
  } catch (error) {
46
- throw errorMap(error);
65
+ throw mapRealtimeError(error, errorMap);
47
66
  }
48
67
  }
49
68
  /**
@@ -90,6 +109,7 @@ function createQuestpieQueryOptions(client, config = {}) {
90
109
  const topic = buildCollectionTopic$1(collectionName, options);
91
110
  return queryOptions({
92
111
  queryKey: qKey,
112
+ retry: realtimeRetry,
93
113
  queryFn: experimental_streamedQuery({
94
114
  streamFn: ({ signal }) => streamRealtimeQuery({
95
115
  realtime: client.realtime,
@@ -120,6 +140,7 @@ function createQuestpieQueryOptions(client, config = {}) {
120
140
  const topic = buildCollectionTopic$1(collectionName, options, "count");
121
141
  return queryOptions({
122
142
  queryKey: qKey,
143
+ retry: realtimeRetry,
123
144
  queryFn: experimental_streamedQuery({
124
145
  streamFn: ({ signal }) => streamRealtimeQuery({
125
146
  realtime: client.realtime,
@@ -276,6 +297,7 @@ function createQuestpieQueryOptions(client, config = {}) {
276
297
  const topic = buildGlobalTopic$1(globalName, options);
277
298
  return queryOptions({
278
299
  queryKey: qKey,
300
+ retry: realtimeRetry,
279
301
  queryFn: experimental_streamedQuery({
280
302
  streamFn: ({ signal }) => streamRealtimeQuery({
281
303
  realtime: client.realtime,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@questpie/tanstack-query",
3
- "version": "3.15.2",
3
+ "version": "3.16.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/questpie/questpie.git",