@orpc/swr 0.0.0 → 1.14.11

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/README.md CHANGED
@@ -109,11 +109,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
109
109
  <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&amp;v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
110
110
  <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&amp;v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
111
111
  <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&amp;v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
112
- <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
113
112
  <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
113
+ <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
114
114
  </tr>
115
115
  <tr>
116
- <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
117
116
  <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="139" alt="shota"/><br />shota</a></td>
118
117
  </tr>
119
118
  </table>
@@ -173,6 +172,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
173
172
  <a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&amp;v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
174
173
  <a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&amp;v=4" width="32" height="32" alt="Robert Soriano" /></a>
175
174
  <a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
175
+ <a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="32" height="32" alt="Ryan Vogel" /></a>
176
176
  <a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
177
177
  <a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&amp;v=4" width="32" height="32" alt="Peter Adam" /></a>
178
178
  <a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
package/dist/index.d.mts CHANGED
@@ -53,13 +53,15 @@ type FetcherOptions<TClientContext extends ClientContext> = object extends TClie
53
53
  };
54
54
  type SubscriberOptions<TClientContext extends ClientContext> = FetcherOptions<TClientContext> & {
55
55
  /**
56
- * Determines how data is handled when the subscription refetches.
57
- * - `reset`: Replace existing data with new data
58
- * - `append`: Add new data to existing data
56
+ * Determines how data is handled when the subscription is subscribed again
57
+ *
58
+ * - `'reset'`: Clears existing data before streaming new data.
59
+ * - `'append'`: Adds new streamed chunks to the existing data.
60
+ * - `'replace'`: Buffers streamed data and replaces existing data after the stream completes.
59
61
  *
60
62
  * @default 'reset'
61
63
  */
62
- refetchMode?: 'reset' | 'append';
64
+ refetchMode?: 'append' | 'reset' | 'replace';
63
65
  /**
64
66
  * Maximum number of chunks to store.
65
67
  * When exceeded, the oldest chunks will be removed.
package/dist/index.d.ts CHANGED
@@ -53,13 +53,15 @@ type FetcherOptions<TClientContext extends ClientContext> = object extends TClie
53
53
  };
54
54
  type SubscriberOptions<TClientContext extends ClientContext> = FetcherOptions<TClientContext> & {
55
55
  /**
56
- * Determines how data is handled when the subscription refetches.
57
- * - `reset`: Replace existing data with new data
58
- * - `append`: Add new data to existing data
56
+ * Determines how data is handled when the subscription is subscribed again
57
+ *
58
+ * - `'reset'`: Clears existing data before streaming new data.
59
+ * - `'append'`: Adds new streamed chunks to the existing data.
60
+ * - `'replace'`: Buffers streamed data and replaces existing data after the stream completes.
59
61
  *
60
62
  * @default 'reset'
61
63
  */
62
- refetchMode?: 'reset' | 'append';
64
+ refetchMode?: 'append' | 'reset' | 'replace';
63
65
  /**
64
66
  * Maximum number of chunks to store.
65
67
  * When exceeded, the oldest chunks will be removed.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isPlainObject, resolveMaybeOptionalOptions, isAsyncIteratorObject, toArray, bindMethods, getOrBind, get, isTypescriptObject } from '@orpc/shared';
1
+ import { isPlainObject, resolveMaybeOptionalOptions, isAsyncIteratorObject, toArray, bindMethods, getOrBind, isTypescriptObject } from '@orpc/shared';
2
2
  import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
3
3
 
4
4
  function generateOperationKey(path, options = {}) {
@@ -101,17 +101,35 @@ class ProcedureUtils extends SharedUtils {
101
101
  if (!isAsyncIteratorObject(iterator)) {
102
102
  throw new TypeError(".subscriber requires an AsyncIteratorObject output");
103
103
  }
104
+ let hasPreviousData = false;
104
105
  if (refetchMode === "reset") {
105
106
  next(void 0, void 0);
107
+ } else if (refetchMode === "replace") {
108
+ next(void 0, (old) => {
109
+ hasPreviousData = old !== void 0;
110
+ return old;
111
+ });
106
112
  }
113
+ const shouldUpdateDataDuringStream = refetchMode !== "replace" || !hasPreviousData;
114
+ let buffer = [];
107
115
  for await (const event of iterator) {
108
- next(void 0, (old) => {
109
- const newData = Array.isArray(old) ? [...old, event] : [event];
110
- if (typeof maxChunks === "number" && newData.length > maxChunks) {
111
- return newData.slice(newData.length - maxChunks);
116
+ if (shouldUpdateDataDuringStream) {
117
+ next(void 0, (old) => {
118
+ const newData = Array.isArray(old) ? [...old, event] : [event];
119
+ if (typeof maxChunks === "number" && newData.length > maxChunks) {
120
+ return newData.slice(newData.length - maxChunks);
121
+ }
122
+ return newData;
123
+ });
124
+ } else {
125
+ buffer = [...buffer, event];
126
+ if (typeof maxChunks === "number" && buffer.length > maxChunks) {
127
+ buffer = buffer.slice(buffer.length - maxChunks);
112
128
  }
113
- return newData;
114
- });
129
+ }
130
+ }
131
+ if (!shouldUpdateDataDuringStream) {
132
+ next(void 0, buffer);
115
133
  }
116
134
  } catch (error) {
117
135
  if (!controller.signal.aborted) {
@@ -182,7 +200,7 @@ function createRouterUtils(client, options = {}) {
182
200
  const recursive = new Proxy(utils, {
183
201
  get(target, prop) {
184
202
  const value = getOrBind(target, prop);
185
- const nextClient = get(client, [prop]);
203
+ const nextClient = client[prop];
186
204
  if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop) || !isTypescriptObject(nextClient)) {
187
205
  return value;
188
206
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/swr",
3
3
  "type": "module",
4
- "version": "0.0.0",
4
+ "version": "1.14.11",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -30,8 +30,8 @@
30
30
  "swr": ">=2.4.2"
31
31
  },
32
32
  "dependencies": {
33
- "@orpc/client": "*",
34
- "@orpc/shared": "*"
33
+ "@orpc/client": "1.14.11",
34
+ "@orpc/shared": "1.14.11"
35
35
  },
36
36
  "devDependencies": {
37
37
  "swr": "^2.4.2",