@mainframework/api-request-worker 1.0.0 → 1.0.2
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 +134 -43
- package/dist/shared/output/react.d.ts +6 -0
- package/dist/shared/output/react.js +247 -0
- package/dist/shared/output/react.js.map +1 -0
- package/dist/shared/output/vanilla.d.ts +9 -0
- package/dist/shared/output/vanilla.js +4 -0
- package/dist/shared/output/vanilla.js.map +1 -0
- package/dist/{shared/types/types.d.ts → types-Bbz0QMYB.d.ts} +21 -34
- package/dist/workers/api/api.worker.js +433 -0
- package/dist/workers/api/api.worker.js.map +1 -0
- package/package.json +32 -32
- package/dist/api.worker.js +0 -463
- package/dist/api.worker.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -223
- package/dist/index.js.map +0 -1
- package/dist/shared/hooks/useApiWorker.d.ts +0 -4
- package/dist/shared/hooks/useApiWorker.d.ts.map +0 -1
- package/dist/shared/hooks/useCustomCallback.d.ts +0 -2
- package/dist/shared/hooks/useCustomCallback.d.ts.map +0 -1
- package/dist/shared/types/types.d.ts.map +0 -1
- package/dist/shared/utils/uniqueId.d.ts +0 -6
- package/dist/shared/utils/uniqueId.d.ts.map +0 -1
- package/dist/shared/workers/api/api.worker.d.ts +0 -2
- package/dist/shared/workers/api/api.worker.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ The library supports three response types to handle different use cases:
|
|
|
29
29
|
|
|
30
30
|
- **`responseType: "binary"`**: Full binary response is buffered in the worker and sent as an `ArrayBuffer` in a single message. Perfect for complete binary files like images, PDFs, or downloadable documents.
|
|
31
31
|
|
|
32
|
-
- **`responseType: "stream"`**: Responses are streamed incrementally to the client. The worker sends chunks as they arrive (`start` → `chunk` → `chunk` → ... → `end`), enabling playback of audio/video streams to begin before the full file downloads. The React hook
|
|
32
|
+
- **`responseType: "stream"`**: Responses are streamed incrementally to the client. The worker sends chunks as they arrive (`start` → `chunk` → `chunk` → ... → `end`), enabling playback of audio/video streams to begin before the full file downloads. The React hook returns `streamChunks` (batches of `ArrayBuffer[]`) as they arrive and a final `Blob` in `data` when complete. Throttling (default: every 5 chunks or 50ms) minimizes re-renders. For vanilla JavaScript, you handle stream events manually for maximum control.
|
|
33
33
|
|
|
34
34
|
Binary and stream responses are not stored in the worker cache; only json/text responses are cached.
|
|
35
35
|
|
|
@@ -47,29 +47,97 @@ If you use the optional React hook, a peer dependency `react >= 19` is required.
|
|
|
47
47
|
|
|
48
48
|
---
|
|
49
49
|
|
|
50
|
-
##
|
|
50
|
+
## Quickstart
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
### React
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
```ts
|
|
55
|
+
import { useApiWorker } from "@mainframework/api-request-worker/react";
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
export function Todos() {
|
|
58
|
+
const { data, loading, error, refetch } = useApiWorker<{ id: string; title: string }[]>({
|
|
59
|
+
cacheName: "todos",
|
|
60
|
+
request: { url: "https://api.example.com/todos", method: "GET" },
|
|
61
|
+
runMode: "auto",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (loading) return null;
|
|
65
|
+
if (error) return null;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<button onClick={refetch}>Refresh</button>
|
|
70
|
+
<pre>{JSON.stringify(data, null, 2)}</pre>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Vanilla JS/TS
|
|
57
77
|
|
|
58
78
|
```ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
79
|
+
import { createApiWorker } from "@mainframework/api-request-worker";
|
|
80
|
+
|
|
81
|
+
const worker = createApiWorker();
|
|
82
|
+
const cacheName = "todos";
|
|
83
|
+
|
|
84
|
+
worker.onmessage = (event) => {
|
|
85
|
+
const msg = event.data;
|
|
86
|
+
if (msg.cacheName !== cacheName) return;
|
|
87
|
+
if (msg.error?.message) throw new Error(msg.error.message);
|
|
88
|
+
console.log(msg.data);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
worker.postMessage({
|
|
92
|
+
dataRequest: {
|
|
93
|
+
type: "set",
|
|
94
|
+
cacheName,
|
|
95
|
+
request: { url: "https://api.example.com/todos", method: "GET" },
|
|
96
|
+
},
|
|
97
|
+
});
|
|
63
98
|
```
|
|
64
99
|
|
|
65
|
-
|
|
100
|
+
### Public imports only
|
|
66
101
|
|
|
67
|
-
|
|
102
|
+
Use only these import paths. Do not import the worker script directly.
|
|
103
|
+
|
|
104
|
+
| Use case | Import from | What you get |
|
|
105
|
+
| ----------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
106
|
+
| **Vanilla** | `@mainframework/api-request-worker` | `createApiWorker`, `RequestConfig`, `DataRequest`, `BinaryResponseMeta`, `WorkerMessagePayload`, and other protocol types |
|
|
107
|
+
| **React** | `@mainframework/api-request-worker/react` | `useApiWorker`, `RequestConfig`, hook types |
|
|
108
|
+
|
|
109
|
+
The worker is not a public entry. Obtain it only by calling `createApiWorker()` from the main package (or use the React hook, which uses `createApiWorker` internally).
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Bundler notes (Vite / Webpack / Next.js)
|
|
114
|
+
|
|
115
|
+
- **Vite**: Works out of the box. The worker is created via `new Worker(new URL(..., import.meta.url), { type: "module" })`.
|
|
116
|
+
|
|
117
|
+
- **Webpack**: Must support ESM module workers. Ensure your build supports `new URL(..., import.meta.url)` for assets and that module workers are enabled.
|
|
118
|
+
|
|
119
|
+
- **Next.js**: Use **client-only** code paths.
|
|
120
|
+
- Add `"use client";` at the top of any file that imports `@mainframework/api-request-worker/react`.
|
|
121
|
+
- Do not call `createApiWorker()` during SSR.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Usage with Vanilla TypeScript / JavaScript
|
|
126
|
+
|
|
127
|
+
Import from the main package entry and create the worker with `createApiWorker`. You then talk to the worker via the standard `postMessage` API: send **dataRequests** with `worker.postMessage`, and handle responses in `worker.onmessage`. No framework required.
|
|
128
|
+
|
|
129
|
+
### Setting Up the Worker
|
|
130
|
+
|
|
131
|
+
Create the worker with `createApiWorker`. This is the only way to obtain the worker.
|
|
68
132
|
|
|
69
133
|
```ts
|
|
70
|
-
|
|
134
|
+
import { createApiWorker } from "@mainframework/api-request-worker";
|
|
135
|
+
|
|
136
|
+
const worker = createApiWorker();
|
|
71
137
|
```
|
|
72
138
|
|
|
139
|
+
Set `worker.onmessage` to handle responses (see [Message Protocol](#message-protocol)). Use the built-in `worker.postMessage` to send requests; do not overwrite `postMessage`.
|
|
140
|
+
|
|
73
141
|
### Message Protocol
|
|
74
142
|
|
|
75
143
|
**Outgoing messages (main thread → worker):**
|
|
@@ -131,19 +199,22 @@ interface RequestConfig {
|
|
|
131
199
|
formDataFileFieldName?: string; // FormData field name for File/Blob parts (default: "Files")
|
|
132
200
|
formDataKey?: string; // FormData key for root payload when building multipart form data
|
|
133
201
|
retries?: number; // For responseType "stream": retry attempts on connection loss (default: 3, max: 5)
|
|
202
|
+
streamChunkBatchSize?: number; // For responseType "stream": flush to streamChunks every N chunks (default: 5)
|
|
134
203
|
}
|
|
135
204
|
```
|
|
136
205
|
|
|
137
206
|
- **`responseType: "binary"`**: Use for complete binary files. The worker returns an `ArrayBuffer` and sets `meta.contentType` and `meta.contentDisposition` so you can construct a proper `Blob`: `new Blob([data], { type: meta?.contentType })`.
|
|
138
207
|
|
|
139
|
-
- **`responseType: "stream"`**: Use for streaming audio/video or large files. The worker sends chunks incrementally. Supports automatic reconnection with configurable retries (default 3, max 5).
|
|
208
|
+
- **`responseType: "stream"`**: Use for streaming audio/video or large files. The worker sends chunks incrementally. The hook returns `streamChunks` (batches of `ArrayBuffer[]`) as they arrive and a final `Blob` in `data` when complete. Batching via `streamChunkBatchSize` (default 5) controls how many chunks are delivered per update. Supports automatic reconnection with configurable retries (default 3, max 5).
|
|
140
209
|
|
|
141
210
|
### Vanilla JavaScript Examples
|
|
142
211
|
|
|
143
212
|
**GET request from API (JSON response):**
|
|
144
213
|
|
|
145
214
|
```ts
|
|
146
|
-
|
|
215
|
+
import { createApiWorker } from "@mainframework/api-request-worker";
|
|
216
|
+
|
|
217
|
+
const worker = createApiWorker();
|
|
147
218
|
const cacheName = "api-get-" + Date.now();
|
|
148
219
|
|
|
149
220
|
worker.onmessage = (event) => {
|
|
@@ -396,7 +467,7 @@ For React applications, the library provides an optional `useApiWorker` hook tha
|
|
|
396
467
|
### Hook API
|
|
397
468
|
|
|
398
469
|
```ts
|
|
399
|
-
import { useApiWorker } from "@mainframework/api-request-worker";
|
|
470
|
+
import { useApiWorker } from "@mainframework/api-request-worker/react";
|
|
400
471
|
|
|
401
472
|
const result = useApiWorker({
|
|
402
473
|
cacheName: "my-cache", // required
|
|
@@ -422,14 +493,15 @@ const result = useApiWorker({
|
|
|
422
493
|
|
|
423
494
|
**Return value:**
|
|
424
495
|
|
|
425
|
-
| Property
|
|
426
|
-
|
|
|
427
|
-
| `data`
|
|
428
|
-
| `meta`
|
|
429
|
-
| `loading`
|
|
430
|
-
| `error`
|
|
431
|
-
| `refetch`
|
|
432
|
-
| `deleteCache`
|
|
496
|
+
| Property | Type | Description |
|
|
497
|
+
| -------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
498
|
+
| `data` | `T \| null` | Response body: JSON/text for `responseType: "json"`, `ArrayBuffer` for `responseType: "binary"`, `Blob` for `responseType: "stream"`. |
|
|
499
|
+
| `meta` | `BinaryResponseMeta \| null` | For binary and stream responses: `contentType`, `contentDisposition`. |
|
|
500
|
+
| `loading` | `boolean` | `true` while a request is in flight. |
|
|
501
|
+
| `error` | `string \| null` | Error message when the request failed; `null` when there is no error. See [Errors](#errors). |
|
|
502
|
+
| `refetch` | `() => void` | Re-runs the same logical request. See [Refetch semantics](#refetch-semantics). |
|
|
503
|
+
| `deleteCache` | `() => void` | Tells the worker to delete the cache entry for this `cacheName`. |
|
|
504
|
+
| `streamChunks` | `ArrayBuffer[] \| undefined` | For `responseType: "stream"`: batches of chunks as they arrive. Append to `MediaSource` or process incrementally. `undefined` for non-stream. |
|
|
433
505
|
|
|
434
506
|
### React Examples
|
|
435
507
|
|
|
@@ -552,20 +624,21 @@ const { data, meta, loading } = useApiWorker({
|
|
|
552
624
|
**Streaming response (audio/video):**
|
|
553
625
|
|
|
554
626
|
```ts
|
|
555
|
-
const { data, meta, loading, error } = useApiWorker({
|
|
627
|
+
const { data, meta, loading, error, streamChunks } = useApiWorker({
|
|
556
628
|
cacheName: "video-stream",
|
|
557
629
|
request: {
|
|
558
630
|
url: "https://example.com/video.mp4",
|
|
559
631
|
method: "GET",
|
|
560
632
|
responseType: "stream",
|
|
561
633
|
retries: 3, // Retry on connection loss (default 3, max 5)
|
|
634
|
+
streamChunkBatchSize: 5, // Optional: flush every N chunks (default 5)
|
|
562
635
|
},
|
|
563
636
|
runMode: "auto",
|
|
564
637
|
});
|
|
565
638
|
|
|
566
|
-
//
|
|
567
|
-
//
|
|
568
|
-
//
|
|
639
|
+
// streamChunks: batches of ArrayBuffer[] as chunks arrive (append to MediaSource, etc.)
|
|
640
|
+
// data: Blob when the stream completes
|
|
641
|
+
// loading: true until stream ends
|
|
569
642
|
// const videoUrl = data ? URL.createObjectURL(data) : null;
|
|
570
643
|
// <video src={videoUrl} controls />
|
|
571
644
|
```
|
|
@@ -623,48 +696,66 @@ Responses are routed to the requesting component by `cacheName` or, when `cacheN
|
|
|
623
696
|
|
|
624
697
|
## TypeScript Types
|
|
625
698
|
|
|
626
|
-
**
|
|
699
|
+
**Vanilla (main entry):** Request and protocol types:
|
|
627
700
|
|
|
628
701
|
```ts
|
|
629
|
-
import type {
|
|
702
|
+
import type {
|
|
703
|
+
RequestConfig,
|
|
704
|
+
DataRequest,
|
|
705
|
+
BinaryResponseMeta,
|
|
706
|
+
WorkerMessagePayload,
|
|
707
|
+
WorkerErrorPayload,
|
|
708
|
+
WorkerResponseMessage,
|
|
709
|
+
ResponseType,
|
|
710
|
+
RunMode,
|
|
711
|
+
WorkerDataRequestType,
|
|
712
|
+
WorkerMessageData,
|
|
713
|
+
BinaryParseResult,
|
|
714
|
+
ContentType,
|
|
715
|
+
} from "@mainframework/api-request-worker";
|
|
630
716
|
```
|
|
631
717
|
|
|
632
|
-
|
|
718
|
+
- `WorkerDataRequestType`: `"get" | "set" | "delete" | "cancel"` — for narrowing `DataRequest.type`
|
|
719
|
+
- `WorkerMessageData`: `{ dataRequest?: DataRequest }` — shape for `postMessage` payloads
|
|
720
|
+
- `BinaryParseResult`: internal binary marker type; mainly for advanced worker extensions
|
|
721
|
+
|
|
722
|
+
**React:**
|
|
633
723
|
|
|
634
|
-
|
|
724
|
+
```ts
|
|
725
|
+
import type { RequestConfig, UseApiWorkerConfig, UseApiWorkerReturn } from "@mainframework/api-request-worker/react";
|
|
726
|
+
```
|
|
635
727
|
|
|
636
728
|
---
|
|
637
729
|
|
|
638
730
|
## Quick Reference
|
|
639
731
|
|
|
640
|
-
| Use case | Entry point
|
|
641
|
-
| ----------------- |
|
|
642
|
-
| **Vanilla JS/TS** |
|
|
643
|
-
| **React** |
|
|
732
|
+
| Use case | Entry point | Primary API |
|
|
733
|
+
| ----------------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
734
|
+
| **Vanilla JS/TS** | `@mainframework/api-request-worker` | `createApiWorker()`; set `worker.onmessage`, use `worker.postMessage` |
|
|
735
|
+
| **React** | `@mainframework/api-request-worker/react` | `useApiWorker({ cacheName, request?, data?, runMode?, enabled? })` → `{ data, meta, loading, error, refetch, deleteCache }` |
|
|
644
736
|
|
|
645
737
|
---
|
|
646
738
|
|
|
647
739
|
## Framework Integrations
|
|
648
740
|
|
|
649
|
-
**Core:** The worker and message protocol work
|
|
741
|
+
**Core:** The worker and message protocol work in any environment (vanilla JavaScript/TypeScript or any framework). The worker is always created via `createApiWorker`; the vanilla bundle and the React hook both use it.
|
|
650
742
|
|
|
651
|
-
**
|
|
743
|
+
**React:** A hook (`useApiWorker`) is included; it uses `createApiWorker` internally and exposes a simple API. You can instead use the [Message Protocol](#message-protocol) from React with your own `createApiWorker()` instance.
|
|
652
744
|
|
|
653
|
-
**
|
|
745
|
+
**Other frameworks:** Use the main package entry and the protocol as with vanilla JS (Angular, Vue, Preact, SolidJS, etc.).
|
|
654
746
|
|
|
655
747
|
---
|
|
656
748
|
|
|
657
749
|
## Testing
|
|
658
750
|
|
|
659
|
-
|
|
751
|
+
Tests use Vitest in browser mode (Playwright Chromium). The worker is created inside `useApiWorker`; there are no mocks.
|
|
660
752
|
|
|
661
|
-
-
|
|
662
|
-
- Worker protocol tests (`api.worker.test.ts`)
|
|
753
|
+
- **useApiWorker** — `src/shared/hooks/useApiWorker.test.ts` (React hook, real Worker and network)
|
|
663
754
|
|
|
664
|
-
|
|
755
|
+
Run tests: `yarn test` (or `yarn test:watch`, `yarn test:coverage`). Ensure Chromium is installed: `npx playwright install chromium`.
|
|
665
756
|
|
|
666
757
|
---
|
|
667
758
|
|
|
668
759
|
## License
|
|
669
760
|
|
|
670
|
-
See
|
|
761
|
+
See LICENSE in the repository.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { U as UseApiWorkerConfig, h as UseApiWorkerReturn } from '../../types-Bbz0QMYB.js';
|
|
2
|
+
export { R as RequestConfig } from '../../types-Bbz0QMYB.js';
|
|
3
|
+
|
|
4
|
+
declare const useApiWorker: <T>(config: UseApiWorkerConfig) => UseApiWorkerReturn<T>;
|
|
5
|
+
|
|
6
|
+
export { UseApiWorkerConfig, UseApiWorkerReturn, useApiWorker };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { useRef, useState, useCallback } from 'react';
|
|
2
|
+
import { createApiWorker } from './vanilla.js';
|
|
3
|
+
|
|
4
|
+
let idCounter = 0;
|
|
5
|
+
const uniqueId = () => {
|
|
6
|
+
idCounter += 1;
|
|
7
|
+
return idCounter.toString();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const e=e=>"object"==typeof e&&null!==e,t=e=>"function"==typeof e,r=e=>e instanceof Date,n=e=>e instanceof RegExp,o=e=>e instanceof Set,f=e=>e instanceof Map,i=e=>e instanceof String||e instanceof Number||e instanceof Boolean,a=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),s=e=>Object.getPrototypeOf(e),u=e=>null==e||"object"!=typeof e&&"function"!=typeof e,c=(l,y,p=new WeakMap,b={})=>{if(l===y)return true;if("number"==typeof l&&"number"==typeof y&&Number.isNaN(l)&&Number.isNaN(y))return true;if(b.normalizeBoxedPrimitives&&(i(l)&&(l=l.valueOf()),i(y)&&(y=y.valueOf()),u(l)&&u(y)))return l===y;if(u(l)||u(y))return false;if(t(l)||t(y))return l===y;if(!e(l)||!e(y))return false;let g=p.get(l)??(()=>{const e=new WeakMap;return p.set(l,e),e})();const h=g.get(y);if(void 0!==h)return h;g.set(y,true);const w=s(l),A=s(y);let m;return m=Array.isArray(l)&&Array.isArray(y)?((e,t,r,n)=>{if(e.length!==t.length)return false;for(let o=0;o<e.length;o++){if(n.strictSparseArrays){const r=Object.prototype.hasOwnProperty.call(e,o),n=Object.prototype.hasOwnProperty.call(t,o);if(r!==n)return false;if(!r&&!n)continue}if(!c(e[o],t[o],r,n))return false}return true})(l,y,p,b):!Array.isArray(l)&&!Array.isArray(y)&&(r(l)&&r(y)?((e,t)=>e.getTime()===t.getTime())(l,y):n(l)&&n(y)?((e,t)=>e.source===t.source&&e.flags===t.flags)(l,y):a(l)&&a(y)?((e,t)=>{if(e.constructor!==t.constructor||e.byteLength!==t.byteLength)return false;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<r.length;e++)if(r[e]!==n[e])return false;return true})(l,y):o(l)&&o(y)?((e,t,r,n)=>{if(e.size!==t.size)return false;const o=Array.from(t),f=new Set;for(const t of e){const e=o.findIndex((e,r)=>!f.has(r)&&t===e);if(-1!==e){f.add(e);continue}let i=false;for(let e=0;e<o.length;e++)if(!f.has(e)&&c(t,o[e],r,n)){f.add(e),i=true;break}if(!i)return false}return true})(l,y,p,b):f(l)&&f(y)?((e,t,r,n)=>{if(e.size!==t.size)return false;const o=Array.from(t),f=new Set;for(const[i,a]of e){if(u(i)){const e=t.get(i);if(void 0===e&&!t.has(i))return false;if(!c(a,e,r,n))return false;continue}let e=false;for(let t=0;t<o.length;t++)if(!f.has(t)){const[s,u]=o[t];if(c(i,s,r,n)&&c(a,u,r,n)){f.add(t),e=true;break}}if(!e)return false}return true})(l,y,p,b):!(!b.allowPrototypeMismatch&&w!==A)&&((e,t,r,n)=>{let o=0;for(const f of Reflect.ownKeys(e)){if(!Object.prototype.hasOwnProperty.call(t,f))return false;if(!c(e[f],t[f],r,n))return false;o++;}return Reflect.ownKeys(t).length===o})(l,y,p,b)),g.set(y,m),m},l=(e,t,r)=>c(e,t,new WeakMap,r);
|
|
11
|
+
|
|
12
|
+
const useCustomCallback = (callback, dependencies) => {
|
|
13
|
+
const refCallback = useRef(callback);
|
|
14
|
+
const refDependencies = useRef(dependencies);
|
|
15
|
+
if (!dependencies.every((dep, index) => l(dep, refDependencies.current[index]))) {
|
|
16
|
+
refDependencies.current = dependencies;
|
|
17
|
+
refCallback.current = callback;
|
|
18
|
+
}
|
|
19
|
+
const stableCallback = useRef(
|
|
20
|
+
(...args) => refCallback.current(...args)
|
|
21
|
+
).current;
|
|
22
|
+
return stableCallback;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const DEFAULT_CHUNK_BATCH = 5;
|
|
26
|
+
const toNumber = (val, fallback) => typeof val === "number" && Number.isFinite(val) ? val : fallback;
|
|
27
|
+
const toStreamChunks = (val) => val === void 0 || val === null ? void 0 : Array.isArray(val) ? val : void 0;
|
|
28
|
+
let apiWorker = null;
|
|
29
|
+
let workerInitialized = false;
|
|
30
|
+
let cleanupTimer = null;
|
|
31
|
+
const STALE_ENTRY_MS = 5e3;
|
|
32
|
+
const CLEANUP_INTERVAL_MS = 3e4;
|
|
33
|
+
const normalizeKey = (key) => key.toLocaleLowerCase();
|
|
34
|
+
const cleanupState = { isDeleting: false, lastRun: 0 };
|
|
35
|
+
const runStaleEntryCleanup = () => {
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
if (cleanupState.isDeleting || now < cleanupState.lastRun + CLEANUP_INTERVAL_MS) return;
|
|
38
|
+
cleanupState.isDeleting = true;
|
|
39
|
+
try {
|
|
40
|
+
const keys = Object.keys(responseQueue);
|
|
41
|
+
let i = 0;
|
|
42
|
+
while (i < keys.length) {
|
|
43
|
+
const key = keys[i];
|
|
44
|
+
const entry = responseQueue[key];
|
|
45
|
+
const streamInProgress = streamThrottleState[key] != null || streamAccumulators[key] != null;
|
|
46
|
+
if (entry && !streamInProgress && entry.data != null && entry.lastActivityAt != null && now - entry.lastActivityAt >= STALE_ENTRY_MS) {
|
|
47
|
+
entry.loading = null;
|
|
48
|
+
entry.data = null;
|
|
49
|
+
entry.meta = null;
|
|
50
|
+
entry.error = null;
|
|
51
|
+
entry.setUpdateTrigger = null;
|
|
52
|
+
entry.requestId = null;
|
|
53
|
+
delete entry.streamChunks;
|
|
54
|
+
delete streamThrottleState[key];
|
|
55
|
+
}
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
cleanupState.isDeleting = false;
|
|
60
|
+
cleanupState.lastRun = now;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const responseQueue = {};
|
|
64
|
+
const streamAccumulators = {};
|
|
65
|
+
const streamThrottleState = {};
|
|
66
|
+
const updater = (n) => n + 1;
|
|
67
|
+
const flushStreamBatch = (key, entry) => {
|
|
68
|
+
const state = streamThrottleState[key];
|
|
69
|
+
if (!state || state.pendingChunks.length === 0) return;
|
|
70
|
+
entry.streamChunks = state.pendingChunks.slice();
|
|
71
|
+
state.pendingChunks.length = 0;
|
|
72
|
+
entry.setUpdateTrigger?.(updater);
|
|
73
|
+
};
|
|
74
|
+
const findEntry = (cacheName, hookId) => cacheName ? responseQueue[normalizeKey(cacheName)] : hookId ? Object.values(responseQueue).find((e) => e.hookId === hookId) ?? null : null;
|
|
75
|
+
const finalizeEntry = (entry) => {
|
|
76
|
+
entry.requestId = null;
|
|
77
|
+
entry.setUpdateTrigger?.(updater);
|
|
78
|
+
};
|
|
79
|
+
const getApiWorker = () => {
|
|
80
|
+
if (apiWorker) return apiWorker;
|
|
81
|
+
apiWorker = createApiWorker();
|
|
82
|
+
return apiWorker;
|
|
83
|
+
};
|
|
84
|
+
const ensureWorkerInitialized = () => {
|
|
85
|
+
const worker = getApiWorker();
|
|
86
|
+
if (workerInitialized) return worker;
|
|
87
|
+
workerInitialized = true;
|
|
88
|
+
if (!cleanupTimer) {
|
|
89
|
+
cleanupTimer = setInterval(() => runStaleEntryCleanup(), CLEANUP_INTERVAL_MS);
|
|
90
|
+
}
|
|
91
|
+
worker.onmessage = (event) => {
|
|
92
|
+
const msg = event.data;
|
|
93
|
+
const cacheName = msg.cacheName;
|
|
94
|
+
const hookId = msg.hookId;
|
|
95
|
+
const error = msg.error;
|
|
96
|
+
const key = cacheName ? normalizeKey(cacheName) : "";
|
|
97
|
+
if ("stream" in msg && msg.stream) {
|
|
98
|
+
const entry2 = findEntry(cacheName, hookId);
|
|
99
|
+
if (!entry2) return;
|
|
100
|
+
const batchSize = toNumber(entry2.streamChunkBatchSize, DEFAULT_CHUNK_BATCH);
|
|
101
|
+
switch (msg.stream) {
|
|
102
|
+
case "start": {
|
|
103
|
+
streamAccumulators[key] = { chunks: [], meta: msg.meta ?? null };
|
|
104
|
+
streamThrottleState[key] = { pendingChunks: [] };
|
|
105
|
+
entry2.streamChunks = [];
|
|
106
|
+
entry2.meta = msg.meta ?? null;
|
|
107
|
+
entry2.setUpdateTrigger?.(updater);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
case "resume":
|
|
111
|
+
if (!streamAccumulators[key]) streamAccumulators[key] = { chunks: [], meta: msg.meta ?? null };
|
|
112
|
+
else if (msg.meta) streamAccumulators[key].meta = msg.meta;
|
|
113
|
+
if (!streamThrottleState[key]) streamThrottleState[key] = { pendingChunks: [] };
|
|
114
|
+
if (msg.meta) entry2.meta = msg.meta ?? null;
|
|
115
|
+
return;
|
|
116
|
+
case "chunk": {
|
|
117
|
+
const acc = streamAccumulators[key];
|
|
118
|
+
const throttle = streamThrottleState[key];
|
|
119
|
+
if (acc && msg.data) acc.chunks.push(msg.data);
|
|
120
|
+
if (throttle && msg.data) {
|
|
121
|
+
throttle.pendingChunks.push(msg.data);
|
|
122
|
+
if (throttle.pendingChunks.length >= batchSize) {
|
|
123
|
+
flushStreamBatch(key, entry2);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
case "end": {
|
|
129
|
+
const acc = streamAccumulators[key];
|
|
130
|
+
const throttle = streamThrottleState[key];
|
|
131
|
+
if (throttle?.pendingChunks.length) flushStreamBatch(key, entry2);
|
|
132
|
+
delete streamThrottleState[key];
|
|
133
|
+
delete streamAccumulators[key];
|
|
134
|
+
const errMsg = error?.message ?? "";
|
|
135
|
+
if (errMsg !== "") {
|
|
136
|
+
entry2.error = errMsg;
|
|
137
|
+
} else if (acc) {
|
|
138
|
+
entry2.data = new Blob(acc.chunks, acc.meta?.contentType ? { type: acc.meta.contentType } : void 0);
|
|
139
|
+
entry2.meta = acc.meta ?? null;
|
|
140
|
+
entry2.error = null;
|
|
141
|
+
entry2.lastActivityAt = Date.now();
|
|
142
|
+
}
|
|
143
|
+
entry2.loading = false;
|
|
144
|
+
finalizeEntry(entry2);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const entry = findEntry(cacheName, hookId);
|
|
150
|
+
if (!entry) return;
|
|
151
|
+
const message = error?.message ?? "";
|
|
152
|
+
if (message !== "") {
|
|
153
|
+
entry.error = message;
|
|
154
|
+
entry.loading = false;
|
|
155
|
+
} else {
|
|
156
|
+
entry.data = msg.data ?? null;
|
|
157
|
+
entry.meta = msg.meta ?? null;
|
|
158
|
+
entry.lastActivityAt = Date.now();
|
|
159
|
+
entry.error = null;
|
|
160
|
+
entry.loading = false;
|
|
161
|
+
}
|
|
162
|
+
finalizeEntry(entry);
|
|
163
|
+
};
|
|
164
|
+
return worker;
|
|
165
|
+
};
|
|
166
|
+
const useApiWorker = (config) => {
|
|
167
|
+
const { cacheName, request: requestConfig, data: configData, runMode = "auto", enabled = true } = config;
|
|
168
|
+
const worker = ensureWorkerInitialized();
|
|
169
|
+
const hookIdRef = useRef("");
|
|
170
|
+
const queueKey = normalizeKey(cacheName);
|
|
171
|
+
const hasExecutedRef = useRef(false);
|
|
172
|
+
const [, setUpdateTrigger] = useState(0);
|
|
173
|
+
let storeEntry = responseQueue[queueKey];
|
|
174
|
+
if (!storeEntry) {
|
|
175
|
+
const hookId2 = uniqueId();
|
|
176
|
+
storeEntry = responseQueue[queueKey] = {
|
|
177
|
+
hookId: hookId2,
|
|
178
|
+
cacheName,
|
|
179
|
+
data: null,
|
|
180
|
+
loading: false,
|
|
181
|
+
error: null,
|
|
182
|
+
setUpdateTrigger: () => {
|
|
183
|
+
},
|
|
184
|
+
requestId: null,
|
|
185
|
+
meta: null,
|
|
186
|
+
lastActivityAt: null
|
|
187
|
+
};
|
|
188
|
+
hookIdRef.current = hookId2;
|
|
189
|
+
} else {
|
|
190
|
+
hookIdRef.current = storeEntry.hookId;
|
|
191
|
+
storeEntry.lastActivityAt = Date.now();
|
|
192
|
+
}
|
|
193
|
+
const entry = storeEntry;
|
|
194
|
+
entry.setUpdateTrigger = setUpdateTrigger;
|
|
195
|
+
const hookId = hookIdRef.current;
|
|
196
|
+
const deleteCache = useCallback(() => {
|
|
197
|
+
if (cacheName) {
|
|
198
|
+
worker.postMessage({
|
|
199
|
+
dataRequest: { type: "delete", cacheName, hookId: hookIdRef.current }
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}, [cacheName, worker]);
|
|
203
|
+
const doRequest = useCallback(() => {
|
|
204
|
+
const entry2 = responseQueue[queueKey];
|
|
205
|
+
if (!entry2 || entry2.loading) return;
|
|
206
|
+
entry2.loading = true;
|
|
207
|
+
entry2.error = null;
|
|
208
|
+
entry2.lastActivityAt = Date.now();
|
|
209
|
+
entry2.setUpdateTrigger?.(updater);
|
|
210
|
+
if (requestConfig) {
|
|
211
|
+
const requestId = uniqueId();
|
|
212
|
+
entry2.requestId = requestId;
|
|
213
|
+
const isStream = requestConfig.responseType?.toLowerCase() === "stream";
|
|
214
|
+
if (isStream) {
|
|
215
|
+
entry2.streamChunkBatchSize = toNumber(requestConfig.streamChunkBatchSize, DEFAULT_CHUNK_BATCH);
|
|
216
|
+
}
|
|
217
|
+
const request = isStream && requestConfig.retries === void 0 ? { ...requestConfig, retries: 3 } : requestConfig;
|
|
218
|
+
worker.postMessage({
|
|
219
|
+
dataRequest: { type: "set", cacheName, hookId, requestId, payload: configData, request }
|
|
220
|
+
});
|
|
221
|
+
} else {
|
|
222
|
+
worker.postMessage({ dataRequest: { type: "get", cacheName, hookId } });
|
|
223
|
+
}
|
|
224
|
+
hasExecutedRef.current = true;
|
|
225
|
+
}, [queueKey, cacheName, hookId, requestConfig, configData, worker]);
|
|
226
|
+
const makeRequest = useCustomCallback(() => {
|
|
227
|
+
if (!enabled || runMode === "once" && hasExecutedRef.current) return;
|
|
228
|
+
doRequest();
|
|
229
|
+
}, [enabled, runMode, doRequest]);
|
|
230
|
+
const hasAlreadyRunOnce = runMode === "once" && hasExecutedRef.current;
|
|
231
|
+
const shouldRun = (runMode === "auto" || runMode === "once") && enabled && (requestConfig || cacheName);
|
|
232
|
+
if (shouldRun && !hasAlreadyRunOnce && !entry.loading) {
|
|
233
|
+
doRequest();
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
data: entry.data ?? null,
|
|
237
|
+
meta: entry.meta ?? null,
|
|
238
|
+
loading: entry.loading ?? false,
|
|
239
|
+
error: entry.error ?? null,
|
|
240
|
+
refetch: makeRequest,
|
|
241
|
+
deleteCache,
|
|
242
|
+
streamChunks: toStreamChunks(entry.streamChunks)
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export { useApiWorker };
|
|
247
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sources":["../../../src/shared/utils/uniqueId.ts","../../../node_modules/@mainframework/is-deep-equal/dist/index.mjs","../../../src/shared/hooks/useCustomCallback.ts","../../../src/shared/hooks/useApiWorker.ts"],"sourcesContent":["// utils/uniqueId.ts\r\nlet idCounter = 0;\r\n\r\n/**\r\n * Generates a stable, unique string ID.\r\n * SSR-safe and works in any environment.\r\n */\r\nexport const uniqueId = (): string => {\r\n idCounter += 1;\r\n return idCounter.toString();\r\n};\r\n","const e=e=>\"object\"==typeof e&&null!==e,t=e=>\"function\"==typeof e,r=e=>e instanceof Date,n=e=>e instanceof RegExp,o=e=>e instanceof Set,f=e=>e instanceof Map,i=e=>e instanceof String||e instanceof Number||e instanceof Boolean,a=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),s=e=>Object.getPrototypeOf(e),u=e=>null==e||\"object\"!=typeof e&&\"function\"!=typeof e,c=(l,y,p=new WeakMap,b={})=>{if(l===y)return!0;if(\"number\"==typeof l&&\"number\"==typeof y&&Number.isNaN(l)&&Number.isNaN(y))return!0;if(b.normalizeBoxedPrimitives&&(i(l)&&(l=l.valueOf()),i(y)&&(y=y.valueOf()),u(l)&&u(y)))return l===y;if(u(l)||u(y))return!1;if(t(l)||t(y))return l===y;if(!e(l)||!e(y))return!1;let g=p.get(l)??(()=>{const e=new WeakMap;return p.set(l,e),e})();const h=g.get(y);if(void 0!==h)return h;g.set(y,!0);const w=s(l),A=s(y);let m;return m=Array.isArray(l)&&Array.isArray(y)?((e,t,r,n)=>{if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++){if(n.strictSparseArrays){const r=Object.prototype.hasOwnProperty.call(e,o),n=Object.prototype.hasOwnProperty.call(t,o);if(r!==n)return!1;if(!r&&!n)continue}if(!c(e[o],t[o],r,n))return!1}return!0})(l,y,p,b):!Array.isArray(l)&&!Array.isArray(y)&&(r(l)&&r(y)?((e,t)=>e.getTime()===t.getTime())(l,y):n(l)&&n(y)?((e,t)=>e.source===t.source&&e.flags===t.flags)(l,y):a(l)&&a(y)?((e,t)=>{if(e.constructor!==t.constructor||e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<r.length;e++)if(r[e]!==n[e])return!1;return!0})(l,y):o(l)&&o(y)?((e,t,r,n)=>{if(e.size!==t.size)return!1;const o=Array.from(t),f=new Set;for(const t of e){const e=o.findIndex((e,r)=>!f.has(r)&&t===e);if(-1!==e){f.add(e);continue}let i=!1;for(let e=0;e<o.length;e++)if(!f.has(e)&&c(t,o[e],r,n)){f.add(e),i=!0;break}if(!i)return!1}return!0})(l,y,p,b):f(l)&&f(y)?((e,t,r,n)=>{if(e.size!==t.size)return!1;const o=Array.from(t),f=new Set;for(const[i,a]of e){if(u(i)){const e=t.get(i);if(void 0===e&&!t.has(i))return!1;if(!c(a,e,r,n))return!1;continue}let e=!1;for(let t=0;t<o.length;t++)if(!f.has(t)){const[s,u]=o[t];if(c(i,s,r,n)&&c(a,u,r,n)){f.add(t),e=!0;break}}if(!e)return!1}return!0})(l,y,p,b):!(!b.allowPrototypeMismatch&&w!==A)&&((e,t,r,n)=>{let o=0;for(const f of Reflect.ownKeys(e)){if(!Object.prototype.hasOwnProperty.call(t,f))return!1;if(!c(e[f],t[f],r,n))return!1;o++}return Reflect.ownKeys(t).length===o})(l,y,p,b)),g.set(y,m),m},l=(e,t,r)=>c(e,t,new WeakMap,r);export{l as isEqual};\n//# sourceMappingURL=index.mjs.map\n","\"use client\";\r\nimport { useRef } from \"react\";\r\nimport { isEqual } from \"@mainframework/is-deep-equal\";\r\n\r\nexport const useCustomCallback = <T extends (...args: unknown[]) => unknown>(\r\n callback: T,\r\n dependencies: unknown[],\r\n): T => {\r\n const refCallback = useRef<T>(callback);\r\n const refDependencies = useRef<unknown[]>(dependencies);\r\n\r\n // Update refs synchronously during render\r\n if (!dependencies.every((dep, index) => isEqual(dep, refDependencies.current[index]))) {\r\n refDependencies.current = dependencies;\r\n refCallback.current = callback;\r\n }\r\n\r\n // Stable callback, always calls latest callback\r\n const stableCallback = useRef(\r\n (...args: Parameters<T>): ReturnType<T> => refCallback.current(...args) as ReturnType<T>,\r\n ).current;\r\n\r\n return stableCallback as T;\r\n};\r\n","// useApiWorker.ts\r\nimport { useRef, useState, useCallback } from \"react\";\r\nimport { createApiWorker } from \"../utils/createApiWorker\";\r\nimport { uniqueId } from \"../utils/uniqueId\";\r\nimport type {\r\n BinaryResponseMeta,\r\n DataRequest,\r\n QueueEntry,\r\n UseApiWorkerConfig,\r\n UseApiWorkerReturn,\r\n WorkerMessagePayload,\r\n} from \"../types/types\";\r\n\r\ntype StreamAccumulator = { chunks: ArrayBuffer[]; meta: BinaryResponseMeta | null };\r\n\r\ntype StreamThrottleState = {\r\n pendingChunks: ArrayBuffer[];\r\n};\r\n\r\nconst DEFAULT_CHUNK_BATCH = 5;\r\n\r\nconst toNumber = (val: unknown, fallback: number): number =>\r\n typeof val === \"number\" && Number.isFinite(val) ? val : fallback;\r\n\r\nconst toStreamChunks = (val: unknown): ArrayBuffer[] | undefined =>\r\n val === undefined || val === null ? undefined : Array.isArray(val) ? (val as ArrayBuffer[]) : undefined;\r\n\r\nimport { useCustomCallback } from \"./useCustomCallback\";\r\n\r\n// ============================================================================\r\n// MODULE-LEVEL WORKER & QUEUE\r\n// ============================================================================\r\n\r\nlet apiWorker: Worker | null = null;\r\nlet workerInitialized = false;\r\nlet cleanupTimer: ReturnType<typeof setInterval> | null = null;\r\n\r\nconst STALE_ENTRY_MS = 5000;\r\nconst CLEANUP_INTERVAL_MS = 30000;\r\n\r\nconst normalizeKey = (key: string) => key.toLocaleLowerCase();\r\n\r\nconst cleanupState = { isDeleting: false, lastRun: 0 };\r\n\r\nconst runStaleEntryCleanup = (): void => {\r\n const now = Date.now();\r\n if (cleanupState.isDeleting || now < cleanupState.lastRun + CLEANUP_INTERVAL_MS) return;\r\n\r\n cleanupState.isDeleting = true;\r\n\r\n try {\r\n const keys = Object.keys(responseQueue);\r\n let i = 0;\r\n while (i < keys.length) {\r\n const key = keys[i] as string;\r\n const entry = responseQueue[key];\r\n const streamInProgress = streamThrottleState[key] != null || streamAccumulators[key] != null;\r\n if (\r\n entry &&\r\n !streamInProgress &&\r\n entry.data != null &&\r\n entry.lastActivityAt != null &&\r\n now - entry.lastActivityAt >= STALE_ENTRY_MS\r\n ) {\r\n entry.loading = null;\r\n entry.data = null;\r\n entry.meta = null;\r\n entry.error = null;\r\n entry.setUpdateTrigger = null;\r\n entry.requestId = null;\r\n delete entry.streamChunks;\r\n delete streamThrottleState[key];\r\n }\r\n i++;\r\n }\r\n } finally {\r\n cleanupState.isDeleting = false;\r\n cleanupState.lastRun = now;\r\n }\r\n};\r\n\r\nconst responseQueue: Record<string, QueueEntry<unknown>> = {};\r\n\r\nconst streamAccumulators: Record<string, StreamAccumulator> = {};\r\nconst streamThrottleState: Record<string, StreamThrottleState> = {};\r\n\r\nconst updater = (n: number) => n + 1;\r\n\r\nconst flushStreamBatch = (key: string, entry: QueueEntry<unknown>): void => {\r\n const state = streamThrottleState[key];\r\n if (!state || state.pendingChunks.length === 0) return;\r\n entry.streamChunks = state.pendingChunks.slice();\r\n state.pendingChunks.length = 0;\r\n entry.setUpdateTrigger?.(updater);\r\n};\r\n\r\nconst findEntry = (cacheName: string | undefined, hookId: string | undefined) =>\r\n cacheName\r\n ? responseQueue[normalizeKey(cacheName)]\r\n : hookId\r\n ? (Object.values(responseQueue).find((e) => e.hookId === hookId) ?? null)\r\n : null;\r\n\r\nconst finalizeEntry = (entry: QueueEntry<unknown>): void => {\r\n entry.requestId = null;\r\n entry.setUpdateTrigger?.(updater);\r\n};\r\n\r\nconst getApiWorker = (): Worker => {\r\n if (apiWorker) return apiWorker;\r\n apiWorker = createApiWorker();\r\n return apiWorker;\r\n};\r\n\r\nconst ensureWorkerInitialized = (): Worker => {\r\n const worker = getApiWorker();\r\n if (workerInitialized) return worker;\r\n workerInitialized = true;\r\n\r\n if (!cleanupTimer) {\r\n cleanupTimer = setInterval(() => runStaleEntryCleanup(), CLEANUP_INTERVAL_MS);\r\n }\r\n\r\n // Worker always sends error ({ message: string }). Entry is found by cacheName or hookId.\r\n // Stream responses: start → chunk(s) → end; we accumulate chunks then set data = new Blob(chunks) on end.\r\n worker.onmessage = (event: MessageEvent<WorkerMessagePayload>) => {\r\n const msg = event.data;\r\n const cacheName = msg.cacheName;\r\n const hookId = msg.hookId;\r\n const error = msg.error;\r\n const key = cacheName ? normalizeKey(cacheName) : \"\";\r\n\r\n if (\"stream\" in msg && msg.stream) {\r\n const entry = findEntry(cacheName, hookId);\r\n if (!entry) return;\r\n const batchSize = toNumber(entry.streamChunkBatchSize, DEFAULT_CHUNK_BATCH);\r\n switch (msg.stream) {\r\n case \"start\": {\r\n streamAccumulators[key] = { chunks: [], meta: msg.meta ?? null };\r\n streamThrottleState[key] = { pendingChunks: [] };\r\n entry.streamChunks = [];\r\n entry.meta = msg.meta ?? null;\r\n entry.setUpdateTrigger?.(updater);\r\n return;\r\n }\r\n case \"resume\":\r\n if (!streamAccumulators[key]) streamAccumulators[key] = { chunks: [], meta: msg.meta ?? null };\r\n else if (msg.meta) streamAccumulators[key].meta = msg.meta;\r\n if (!streamThrottleState[key]) streamThrottleState[key] = { pendingChunks: [] };\r\n if (msg.meta) entry.meta = msg.meta ?? null;\r\n return;\r\n case \"chunk\": {\r\n const acc = streamAccumulators[key];\r\n const throttle = streamThrottleState[key];\r\n if (acc && msg.data) acc.chunks.push(msg.data);\r\n if (throttle && msg.data) {\r\n throttle.pendingChunks.push(msg.data);\r\n if (throttle.pendingChunks.length >= batchSize) {\r\n flushStreamBatch(key, entry);\r\n }\r\n }\r\n return;\r\n }\r\n case \"end\": {\r\n const acc = streamAccumulators[key];\r\n const throttle = streamThrottleState[key];\r\n if (throttle?.pendingChunks.length) flushStreamBatch(key, entry);\r\n delete streamThrottleState[key];\r\n delete streamAccumulators[key];\r\n const errMsg = error?.message ?? \"\";\r\n if (errMsg !== \"\") {\r\n entry.error = errMsg;\r\n } else if (acc) {\r\n entry.data = new Blob(acc.chunks, acc.meta?.contentType ? { type: acc.meta.contentType } : undefined);\r\n entry.meta = acc.meta ?? null;\r\n entry.error = null;\r\n entry.lastActivityAt = Date.now();\r\n }\r\n entry.loading = false;\r\n finalizeEntry(entry);\r\n return;\r\n }\r\n }\r\n }\r\n\r\n const entry = findEntry(cacheName, hookId);\r\n if (!entry) return;\r\n\r\n const message = error?.message ?? \"\";\r\n if (message !== \"\") {\r\n entry.error = message;\r\n entry.loading = false;\r\n } else {\r\n entry.data = msg.data ?? null;\r\n entry.meta = msg.meta ?? null;\r\n entry.lastActivityAt = Date.now();\r\n entry.error = null;\r\n entry.loading = false;\r\n }\r\n finalizeEntry(entry);\r\n };\r\n\r\n return worker;\r\n};\r\n\r\n// ============================================================================\r\n// HOOK\r\n// ============================================================================\r\n\r\nexport type { RequestConfig, UseApiWorkerConfig, UseApiWorkerReturn } from \"../types/types\";\r\n\r\nexport const useApiWorker = <T>(config: UseApiWorkerConfig): UseApiWorkerReturn<T> => {\r\n const { cacheName, request: requestConfig, data: configData, runMode = \"auto\", enabled = true } = config;\r\n\r\n const worker = ensureWorkerInitialized();\r\n\r\n const hookIdRef = useRef<string>(\"\");\r\n const queueKey = normalizeKey(cacheName);\r\n\r\n const hasExecutedRef = useRef(false);\r\n const [, setUpdateTrigger] = useState(0);\r\n\r\n let storeEntry = responseQueue[queueKey];\r\n\r\n if (!storeEntry) {\r\n const hookId = uniqueId();\r\n storeEntry = responseQueue[queueKey] = {\r\n hookId,\r\n cacheName,\r\n data: null,\r\n loading: false,\r\n error: null,\r\n setUpdateTrigger: () => {},\r\n requestId: null,\r\n meta: null,\r\n lastActivityAt: null,\r\n };\r\n hookIdRef.current = hookId;\r\n } else {\r\n hookIdRef.current = storeEntry.hookId;\r\n storeEntry.lastActivityAt = Date.now();\r\n }\r\n const entry = storeEntry;\r\n entry.setUpdateTrigger = setUpdateTrigger;\r\n\r\n const hookId = hookIdRef.current;\r\n\r\n const deleteCache = useCallback(() => {\r\n if (cacheName) {\r\n worker.postMessage({\r\n dataRequest: { type: \"delete\", cacheName, hookId: hookIdRef.current },\r\n });\r\n }\r\n }, [cacheName, worker]);\r\n\r\n const doRequest = useCallback(() => {\r\n const entry = responseQueue[queueKey];\r\n if (!entry || entry.loading) return;\r\n entry.loading = true;\r\n entry.error = null;\r\n entry.lastActivityAt = Date.now();\r\n entry.setUpdateTrigger?.(updater);\r\n if (requestConfig) {\r\n const requestId = uniqueId();\r\n entry.requestId = requestId;\r\n const isStream = requestConfig.responseType?.toLowerCase() === \"stream\";\r\n if (isStream) {\r\n entry.streamChunkBatchSize = toNumber(requestConfig.streamChunkBatchSize, DEFAULT_CHUNK_BATCH);\r\n }\r\n const request =\r\n isStream && requestConfig.retries === undefined ? { ...requestConfig, retries: 3 } : requestConfig;\r\n worker.postMessage({\r\n dataRequest: { type: \"set\", cacheName, hookId, requestId, payload: configData, request },\r\n });\r\n } else {\r\n worker.postMessage({ dataRequest: { type: \"get\", cacheName, hookId } as DataRequest<unknown> });\r\n }\r\n hasExecutedRef.current = true;\r\n }, [queueKey, cacheName, hookId, requestConfig, configData, worker]);\r\n\r\n const makeRequest = useCustomCallback(() => {\r\n if (!enabled || (runMode === \"once\" && hasExecutedRef.current)) return;\r\n doRequest();\r\n }, [enabled, runMode, doRequest]);\r\n\r\n const hasAlreadyRunOnce = runMode === \"once\" && hasExecutedRef.current;\r\n const shouldRun = (runMode === \"auto\" || runMode === \"once\") && enabled && (requestConfig || cacheName);\r\n if (shouldRun && !hasAlreadyRunOnce && !entry.loading) {\r\n doRequest();\r\n }\r\n return {\r\n data: (entry.data as T) ?? null,\r\n meta: entry.meta ?? null,\r\n loading: entry.loading ?? false,\r\n error: entry.error ?? null,\r\n refetch: makeRequest,\r\n deleteCache,\r\n streamChunks: toStreamChunks(entry.streamChunks),\r\n };\r\n};\r\n"],"names":["isEqual","entry","hookId"],"mappings":";;;AACA,IAAI,SAAA,GAAY,CAAA;AAMT,MAAM,WAAW,MAAc;AACpC,EAAA,SAAA,IAAa,CAAA;AACb,EAAA,OAAO,UAAU,QAAA,EAAS;AAC5B,CAAA;;ACVA,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,MAAM,EAAE,CAAC,YAAY,MAAM,EAAE,CAAC,YAAY,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,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IAC1B,KAAA,EAAO,MAAM,KAAA,IAAS,IAAA;AAAA,IACtB,OAAA,EAAS,WAAA;AAAA,IACT,WAAA;AAAA,IACA,YAAA,EAAc,cAAA,CAAe,KAAA,CAAM,YAAY;AAAA,GACjD;AACF;;;;","x_google_ignoreList":[1]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { B as BinaryParseResult, a as BinaryResponseMeta, C as ContentType, D as DataRequest, R as RequestConfig, b as ResponseType, c as RunMode, W as WorkerDataRequestType, d as WorkerErrorPayload, e as WorkerMessageData, f as WorkerMessagePayload, g as WorkerResponseMessage } from '../../types-Bbz0QMYB.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Worker instance for the API request worker.
|
|
5
|
+
* Use this for vanilla JS/TS or to build your own framework integration.
|
|
6
|
+
*/
|
|
7
|
+
declare const createApiWorker: () => Worker;
|
|
8
|
+
|
|
9
|
+
export { createApiWorker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanilla.js","sources":["../../../src/shared/utils/createApiWorker.ts"],"sourcesContent":["/**\r\n * Creates a Worker instance for the API request worker.\r\n * Use this for vanilla JS/TS or to build your own framework integration.\r\n */\r\nexport const createApiWorker = (): Worker =>\r\n new Worker(new URL(\"../../workers/api/api.worker.js\", import.meta.url), { type: \"module\" });\r\n"],"names":[],"mappings":"AAIO,MAAM,eAAA,GAAkB,MAC7B,IAAI,MAAA,CAAO,IAAI,GAAA,CAAI,iCAAA,EAAmC,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA,EAAG,EAAE,IAAA,EAAM,UAAU;;;;"}
|