@orpc/experimental-durable-iterator 1.15.7 → 1.16.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.
@@ -70,23 +70,28 @@ class DurableIteratorLinkPlugin {
70
70
  }
71
71
  refreshTokenBeforeExpireTimeoutId = setTimeout(
72
72
  async () => {
73
- const newTokenAndPayload = await retry({ times: Number.POSITIVE_INFINITY, delay: delayMilliseconds }, async (exit) => {
73
+ const newTokenAndPayload = await retry({ times: Number.POSITIVE_INFINITY, delay: delayMilliseconds }, async () => {
74
+ if (isFinished) {
75
+ return void 0;
76
+ }
74
77
  try {
75
78
  const output2 = await next();
76
79
  return this.validateToken(output2, options2.path);
77
80
  } catch (err) {
78
81
  if (isFinished) {
79
- exit(err);
82
+ return void 0;
80
83
  }
81
84
  throw err;
82
85
  }
83
86
  });
87
+ if (!newTokenAndPayload || isFinished) {
88
+ return;
89
+ }
84
90
  const canProactivelyUpdateToken = newTokenAndPayload.payload.chn === tokenAndPayload.payload.chn && stringifyJSON(newTokenAndPayload.payload.tags) === stringifyJSON(tokenAndPayload.payload.tags);
85
91
  tokenAndPayload = newTokenAndPayload;
86
92
  await refreshTokenBeforeExpire();
87
- if (canProactivelyUpdateToken) {
88
- await durableClient.updateToken({ token: tokenAndPayload.token });
89
- } else {
93
+ const isTokenUpdated = canProactivelyUpdateToken && await durableClient.updateToken({ token: tokenAndPayload.token }).then(() => true, () => false);
94
+ if (!isTokenUpdated && !isFinished) {
90
95
  websocket.reconnect();
91
96
  }
92
97
  },
@@ -105,7 +110,12 @@ class DurableIteratorLinkPlugin {
105
110
  options2?.signal?.addEventListener("abort", closeConnection, { once: true });
106
111
  const iterator_ = await durableClient.subscribe(void 0, {
107
112
  context: {
108
- retry: Number.POSITIVE_INFINITY
113
+ retry: Number.POSITIVE_INFINITY,
114
+ /**
115
+ * Stop retrying once the iterator is closed (aborted or returned),
116
+ * otherwise it would retry forever against the closed websocket.
117
+ */
118
+ shouldRetry: () => !isFinished
109
119
  },
110
120
  lastEventId: options2.lastEventId
111
121
  // we can use user provided lastEventId for initial connection
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/experimental-durable-iterator",
3
3
  "type": "module",
4
- "version": "1.15.7",
4
+ "version": "1.16.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -36,15 +36,15 @@
36
36
  "dependencies": {
37
37
  "partysocket": "^1.1.16",
38
38
  "valibot": "^1.2.0",
39
- "@orpc/client": "1.15.7",
40
- "@orpc/contract": "1.15.7",
41
- "@orpc/shared": "1.15.7",
42
- "@orpc/server": "1.15.7"
39
+ "@orpc/client": "1.16.1",
40
+ "@orpc/server": "1.16.1",
41
+ "@orpc/contract": "1.16.1",
42
+ "@orpc/shared": "1.16.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@cloudflare/workers-types": "^4.20260313.1",
46
46
  "@types/node": "^22.19.3",
47
- "@orpc/standard-server-peer": "1.15.7"
47
+ "@orpc/standard-server-peer": "1.16.1"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "unbuild",