@warp-drive-mirror/experiments 0.2.7-beta.0 → 0.2.7-beta.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/CHANGELOG.md +70 -0
- package/README.md +2 -1
- package/dist/data-worker.d.ts +35 -0
- package/dist/data-worker.d.ts.map +1 -0
- package/dist/data-worker.js +235 -339
- package/dist/data-worker.js.map +1 -0
- package/dist/document-storage-CwwTQ49-.d.ts +91 -0
- package/dist/document-storage-CwwTQ49-.d.ts.map +1 -0
- package/dist/document-storage-LM925Stz.js +270 -0
- package/dist/document-storage-LM925Stz.js.map +1 -0
- package/dist/document-storage.d.ts +2 -0
- package/dist/document-storage.js +3 -1
- package/dist/image-fetch.d.ts +60 -0
- package/dist/image-fetch.d.ts.map +1 -0
- package/dist/image-fetch.js +108 -79
- package/dist/image-fetch.js.map +1 -0
- package/dist/image-worker.d.ts +40 -0
- package/dist/image-worker.d.ts.map +1 -0
- package/dist/image-worker.js +95 -95
- package/dist/image-worker.js.map +1 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +3 -0
- package/dist/storage.d.ts +354 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +914 -0
- package/dist/storage.js.map +1 -0
- package/dist/types-CRs-Qww6.d.ts +17 -0
- package/dist/types-CRs-Qww6.d.ts.map +1 -0
- package/dist/unpkg/dev/data-worker.js +231 -338
- package/dist/unpkg/dev/data-worker.js.map +1 -0
- package/dist/unpkg/dev/document-storage-DkiEg9rY.js +268 -0
- package/dist/unpkg/dev/document-storage-DkiEg9rY.js.map +1 -0
- package/dist/unpkg/dev/document-storage.js +2 -348
- package/dist/unpkg/dev/image-fetch.js +104 -71
- package/dist/unpkg/dev/image-fetch.js.map +1 -0
- package/dist/unpkg/dev/image-worker.js +93 -94
- package/dist/unpkg/dev/image-worker.js.map +1 -0
- package/dist/unpkg/dev/pagination.js +3 -0
- package/dist/unpkg/dev/storage.js +913 -0
- package/dist/unpkg/dev/storage.js.map +1 -0
- package/dist/unpkg/dev/worker-fetch.js +112 -145
- package/dist/unpkg/dev/worker-fetch.js.map +1 -0
- package/dist/unpkg/dev-deprecated/data-worker.js +231 -338
- package/dist/unpkg/dev-deprecated/data-worker.js.map +1 -0
- package/dist/unpkg/dev-deprecated/document-storage-DkiEg9rY.js +268 -0
- package/dist/unpkg/dev-deprecated/document-storage-DkiEg9rY.js.map +1 -0
- package/dist/unpkg/dev-deprecated/document-storage.js +2 -348
- package/dist/unpkg/dev-deprecated/image-fetch.js +104 -71
- package/dist/unpkg/dev-deprecated/image-fetch.js.map +1 -0
- package/dist/unpkg/dev-deprecated/image-worker.js +93 -94
- package/dist/unpkg/dev-deprecated/image-worker.js.map +1 -0
- package/dist/unpkg/dev-deprecated/pagination.js +3 -0
- package/dist/unpkg/dev-deprecated/storage.js +913 -0
- package/dist/unpkg/dev-deprecated/storage.js.map +1 -0
- package/dist/unpkg/dev-deprecated/worker-fetch.js +112 -145
- package/dist/unpkg/dev-deprecated/worker-fetch.js.map +1 -0
- package/dist/unpkg/prod/data-worker.js +224 -324
- package/dist/unpkg/prod/data-worker.js.map +1 -0
- package/dist/unpkg/prod/document-storage-D0k_6GM9.js +262 -0
- package/dist/unpkg/prod/document-storage-D0k_6GM9.js.map +1 -0
- package/dist/unpkg/prod/document-storage.js +2 -338
- package/dist/unpkg/prod/image-fetch.js +101 -71
- package/dist/unpkg/prod/image-fetch.js.map +1 -0
- package/dist/unpkg/prod/image-worker.js +93 -94
- package/dist/unpkg/prod/image-worker.js.map +1 -0
- package/dist/unpkg/prod/pagination.js +3 -0
- package/dist/unpkg/prod/storage.js +844 -0
- package/dist/unpkg/prod/storage.js.map +1 -0
- package/dist/unpkg/prod/worker-fetch.js +109 -145
- package/dist/unpkg/prod/worker-fetch.js.map +1 -0
- package/dist/unpkg/prod-deprecated/data-worker.js +224 -324
- package/dist/unpkg/prod-deprecated/data-worker.js.map +1 -0
- package/dist/unpkg/prod-deprecated/document-storage-D0k_6GM9.js +262 -0
- package/dist/unpkg/prod-deprecated/document-storage-D0k_6GM9.js.map +1 -0
- package/dist/unpkg/prod-deprecated/document-storage.js +2 -338
- package/dist/unpkg/prod-deprecated/image-fetch.js +101 -71
- package/dist/unpkg/prod-deprecated/image-fetch.js.map +1 -0
- package/dist/unpkg/prod-deprecated/image-worker.js +93 -94
- package/dist/unpkg/prod-deprecated/image-worker.js.map +1 -0
- package/dist/unpkg/prod-deprecated/pagination.js +3 -0
- package/dist/unpkg/prod-deprecated/storage.js +844 -0
- package/dist/unpkg/prod-deprecated/storage.js.map +1 -0
- package/dist/unpkg/prod-deprecated/worker-fetch.js +109 -145
- package/dist/unpkg/prod-deprecated/worker-fetch.js.map +1 -0
- package/dist/worker-fetch.d.ts +23 -0
- package/dist/worker-fetch.d.ts.map +1 -0
- package/dist/worker-fetch.js +116 -153
- package/dist/worker-fetch.js.map +1 -0
- package/package.json +27 -23
- package/declarations/data-worker/cache-handler.d.ts +0 -7
- package/declarations/data-worker/fetch.d.ts +0 -21
- package/declarations/data-worker/types.d.ts +0 -31
- package/declarations/data-worker/utils.d.ts +0 -12
- package/declarations/data-worker/worker.d.ts +0 -23
- package/declarations/data-worker.d.ts +0 -2
- package/declarations/document-storage/index.d.ts +0 -90
- package/declarations/document-storage.d.ts +0 -1
- package/declarations/image-fetch.d.ts +0 -1
- package/declarations/image-worker/fetch.d.ts +0 -18
- package/declarations/image-worker/types.d.ts +0 -21
- package/declarations/image-worker/worker.d.ts +0 -14
- package/declarations/image-worker.d.ts +0 -1
- package/declarations/worker-fetch.d.ts +0 -1
- package/dist/index-CGCX7hY2.js +0 -349
package/dist/worker-fetch.js
CHANGED
|
@@ -1,164 +1,127 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getGlobalConfig, macroCondition } from "@embroider/macros";
|
|
2
|
+
import { createDeferred } from "@warp-drive-mirror/core/request";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
const isServerEnv = typeof FastBoot !==
|
|
4
|
+
//#region src/data-worker/fetch.ts
|
|
5
|
+
const isServerEnv = typeof FastBoot !== "undefined";
|
|
6
6
|
function isAggregateError(error) {
|
|
7
|
-
|
|
7
|
+
return error instanceof AggregateError || error.name === "AggregateError" && Array.isArray(error.errors);
|
|
8
8
|
}
|
|
9
9
|
function stitchTrace(stack, origin) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return origin + '\n' + stack;
|
|
10
|
+
if (origin.startsWith("Error\n")) return origin.slice(6) + "\n" + stack;
|
|
11
|
+
return origin + "\n" + stack;
|
|
14
12
|
}
|
|
15
13
|
function cloneError(error, stack) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// copy over enumerable properties
|
|
22
|
-
Object.assign(cloned, error);
|
|
23
|
-
return cloned;
|
|
24
|
-
}
|
|
25
|
-
class WorkerFetch {
|
|
26
|
-
constructor(worker) {
|
|
27
|
-
this.threadId = isServerEnv ? '' : crypto.randomUUID();
|
|
28
|
-
this.pending = new Map();
|
|
29
|
-
const isTesting = macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING) ? true : false;
|
|
30
|
-
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
31
|
-
if (!test) {
|
|
32
|
-
throw new Error(`Expected a SharedWorker instance`);
|
|
33
|
-
}
|
|
34
|
-
})(isTesting || isServerEnv || worker instanceof SharedWorker) : {};
|
|
35
|
-
this.worker = worker;
|
|
36
|
-
if (!isServerEnv) {
|
|
37
|
-
const fn = event => {
|
|
38
|
-
const {
|
|
39
|
-
type,
|
|
40
|
-
id,
|
|
41
|
-
data
|
|
42
|
-
} = event.data;
|
|
43
|
-
const info = this.cleanupRequest(id);
|
|
44
|
-
|
|
45
|
-
// typically this means the request was aborted
|
|
46
|
-
if (!info) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (type === 'success-response') {
|
|
50
|
-
const {
|
|
51
|
-
deferred
|
|
52
|
-
} = info;
|
|
53
|
-
const {
|
|
54
|
-
response,
|
|
55
|
-
content
|
|
56
|
-
} = data;
|
|
57
|
-
if (response) {
|
|
58
|
-
response.headers = new Headers(response.headers);
|
|
59
|
-
info.context.setResponse(new Response(null, response));
|
|
60
|
-
}
|
|
61
|
-
deferred.resolve(content);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (type === 'error-response') {
|
|
65
|
-
const {
|
|
66
|
-
deferred,
|
|
67
|
-
stack
|
|
68
|
-
} = info;
|
|
69
|
-
deferred.reject(cloneError(data, stack));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
if (worker instanceof SharedWorker) {
|
|
74
|
-
worker.port.postMessage({
|
|
75
|
-
type: 'connect',
|
|
76
|
-
thread: this.threadId
|
|
77
|
-
});
|
|
78
|
-
worker.port.onmessage = fn;
|
|
79
|
-
} else if (worker) {
|
|
80
|
-
this.channel = new MessageChannel();
|
|
81
|
-
worker.postMessage({
|
|
82
|
-
type: 'connect',
|
|
83
|
-
thread: this.threadId
|
|
84
|
-
}, [this.channel.port2]);
|
|
85
|
-
this.channel.port1.onmessage = fn;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
cleanupRequest(id) {
|
|
90
|
-
const info = this.pending.get(id);
|
|
91
|
-
this.pending.delete(id);
|
|
92
|
-
if (info?.signal) {
|
|
93
|
-
info.signal.removeEventListener('abort', info.abortFn);
|
|
94
|
-
}
|
|
95
|
-
return info;
|
|
96
|
-
}
|
|
97
|
-
send(event) {
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
99
|
-
this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);
|
|
100
|
-
}
|
|
101
|
-
request(context, next) {
|
|
102
|
-
if (isServerEnv) {
|
|
103
|
-
return next(context.request);
|
|
104
|
-
}
|
|
105
|
-
const deferred = createDeferred();
|
|
106
|
-
const {
|
|
107
|
-
signal,
|
|
108
|
-
request
|
|
109
|
-
} = prepareRequest(context.request);
|
|
110
|
-
const abortFn = signal ? () => {
|
|
111
|
-
deferred.reject(enhanceReason(signal.reason));
|
|
112
|
-
this.send({
|
|
113
|
-
type: 'abort',
|
|
114
|
-
thread: this.threadId,
|
|
115
|
-
id: context.id,
|
|
116
|
-
data: signal.reason
|
|
117
|
-
});
|
|
118
|
-
this.cleanupRequest(context.id);
|
|
119
|
-
} : () => {
|
|
120
|
-
return;
|
|
121
|
-
};
|
|
122
|
-
signal?.addEventListener('abort', abortFn);
|
|
123
|
-
try {
|
|
124
|
-
throw new Error();
|
|
125
|
-
} catch (e) {
|
|
126
|
-
this.pending.set(context.id, {
|
|
127
|
-
context,
|
|
128
|
-
deferred,
|
|
129
|
-
signal,
|
|
130
|
-
abortFn,
|
|
131
|
-
stack: e.stack
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
this.send({
|
|
135
|
-
type: 'request',
|
|
136
|
-
thread: this.threadId,
|
|
137
|
-
id: context.id,
|
|
138
|
-
data: request
|
|
139
|
-
});
|
|
140
|
-
return deferred.promise;
|
|
141
|
-
}
|
|
14
|
+
const cloned = isAggregateError(error) ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message);
|
|
15
|
+
cloned.stack = stitchTrace(error.stack || "", stack);
|
|
16
|
+
cloned.error = error.error;
|
|
17
|
+
Object.assign(cloned, error);
|
|
18
|
+
return cloned;
|
|
142
19
|
}
|
|
20
|
+
var WorkerFetch = class {
|
|
21
|
+
constructor(worker) {
|
|
22
|
+
this.threadId = isServerEnv ? "" : crypto.randomUUID();
|
|
23
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
24
|
+
const isTesting = macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING) ? true : false;
|
|
25
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) && ((test) => {
|
|
26
|
+
if (!test) throw new Error(`Expected a SharedWorker instance`);
|
|
27
|
+
})(isTesting || isServerEnv || worker instanceof SharedWorker);
|
|
28
|
+
this.worker = worker;
|
|
29
|
+
if (!isServerEnv) {
|
|
30
|
+
const fn = (event) => {
|
|
31
|
+
const { type, id, data } = event.data;
|
|
32
|
+
const info = this.cleanupRequest(id);
|
|
33
|
+
if (!info) return;
|
|
34
|
+
if (type === "success-response") {
|
|
35
|
+
const { deferred } = info;
|
|
36
|
+
const { response, content } = data;
|
|
37
|
+
if (response) {
|
|
38
|
+
response.headers = new Headers(response.headers);
|
|
39
|
+
info.context.setResponse(new Response(null, response));
|
|
40
|
+
}
|
|
41
|
+
deferred.resolve(content);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (type === "error-response") {
|
|
45
|
+
const { deferred, stack } = info;
|
|
46
|
+
deferred.reject(cloneError(data, stack));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
if (worker instanceof SharedWorker) {
|
|
51
|
+
worker.port.postMessage({
|
|
52
|
+
type: "connect",
|
|
53
|
+
thread: this.threadId
|
|
54
|
+
});
|
|
55
|
+
worker.port.onmessage = fn;
|
|
56
|
+
} else if (worker) {
|
|
57
|
+
this.channel = new MessageChannel();
|
|
58
|
+
worker.postMessage({
|
|
59
|
+
type: "connect",
|
|
60
|
+
thread: this.threadId
|
|
61
|
+
}, [this.channel.port2]);
|
|
62
|
+
this.channel.port1.onmessage = fn;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
cleanupRequest(id) {
|
|
67
|
+
const info = this.pending.get(id);
|
|
68
|
+
this.pending.delete(id);
|
|
69
|
+
if (info?.signal) info.signal.removeEventListener("abort", info.abortFn);
|
|
70
|
+
return info;
|
|
71
|
+
}
|
|
72
|
+
send(event) {
|
|
73
|
+
this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);
|
|
74
|
+
}
|
|
75
|
+
request(context, next) {
|
|
76
|
+
if (isServerEnv) return next(context.request);
|
|
77
|
+
const deferred = createDeferred();
|
|
78
|
+
const { signal, request } = prepareRequest(context.request);
|
|
79
|
+
const abortFn = signal ? () => {
|
|
80
|
+
deferred.reject(enhanceReason(signal.reason));
|
|
81
|
+
this.send({
|
|
82
|
+
type: "abort",
|
|
83
|
+
thread: this.threadId,
|
|
84
|
+
id: context.id,
|
|
85
|
+
data: signal.reason
|
|
86
|
+
});
|
|
87
|
+
this.cleanupRequest(context.id);
|
|
88
|
+
} : () => {};
|
|
89
|
+
signal?.addEventListener("abort", abortFn);
|
|
90
|
+
try {
|
|
91
|
+
throw new Error();
|
|
92
|
+
} catch (e) {
|
|
93
|
+
this.pending.set(context.id, {
|
|
94
|
+
context,
|
|
95
|
+
deferred,
|
|
96
|
+
signal,
|
|
97
|
+
abortFn,
|
|
98
|
+
stack: e.stack
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
this.send({
|
|
102
|
+
type: "request",
|
|
103
|
+
thread: this.threadId,
|
|
104
|
+
id: context.id,
|
|
105
|
+
data: request
|
|
106
|
+
});
|
|
107
|
+
return deferred.promise;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
143
110
|
function enhanceReason(reason) {
|
|
144
|
-
|
|
111
|
+
return new DOMException(reason || "The user aborted a request.", "AbortError");
|
|
145
112
|
}
|
|
146
113
|
function prepareRequest(request) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (headers instanceof Headers) {
|
|
157
|
-
requestCopy.headers = Array.from(headers);
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
signal: signal || null,
|
|
161
|
-
request: requestCopy
|
|
162
|
-
};
|
|
114
|
+
const { signal, headers } = request;
|
|
115
|
+
const requestCopy = Object.assign({}, request);
|
|
116
|
+
delete requestCopy.store;
|
|
117
|
+
if (signal instanceof AbortSignal) delete requestCopy.signal;
|
|
118
|
+
if (headers instanceof Headers) requestCopy.headers = Array.from(headers);
|
|
119
|
+
return {
|
|
120
|
+
signal: signal || null,
|
|
121
|
+
request: requestCopy
|
|
122
|
+
};
|
|
163
123
|
}
|
|
164
|
-
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { WorkerFetch };
|
|
127
|
+
//# sourceMappingURL=worker-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-fetch.js","names":["createDeferred","getGlobalConfig","macroCondition","isServerEnv","FastBoot","isAggregateError","error","AggregateError","name","Array","isArray","errors","stitchTrace","stack","origin","startsWith","slice","cloneError","isAggregate","cloned","structuredClone","message","Error","Object","assign","WorkerFetch","constructor","worker","threadId","crypto","randomUUID","pending","Map","isTesting","WarpDrive","env","TESTING","DEBUG","test","SharedWorker","fn","event","type","id","data","info","cleanupRequest","deferred","response","content","headers","Headers","context","setResponse","Response","resolve","reject","port","postMessage","thread","onmessage","channel","MessageChannel","port2","port1","get","delete","signal","removeEventListener","abortFn","send","request","next","prepareRequest","enhanceReason","reason","addEventListener","e","set","promise","DOMException","requestCopy","store","AbortSignal","from"],"sources":["../src/data-worker/fetch.ts"],"sourcesContent":["import { TESTING } from '@warp-drive-mirror/core/build-config/env';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { Context, Deferred, Future, NextFn } from '@warp-drive-mirror/core/request';\nimport { createDeferred } from '@warp-drive-mirror/core/request';\nimport type { RequestInfo } from '@warp-drive-mirror/core/types/request';\nimport type { ApiError } from '@warp-drive-mirror/core/types/spec/error';\n\nimport type { AbortEventData, MainThreadEvent, RequestEventData } from './types';\n\n// @ts-expect-error untyped global\nconst isServerEnv = typeof FastBoot !== 'undefined';\n\nfunction isAggregateError(error: Error & { errors?: ApiError[] }): error is AggregateError & { errors: ApiError[] } {\n return error instanceof AggregateError || (error.name === 'AggregateError' && Array.isArray(error.errors));\n}\n\ntype RobustError = Error & { error: string | object; errors?: ApiError[]; content?: unknown };\n\nfunction stitchTrace(stack: string, origin: string) {\n if (origin.startsWith('Error\\n')) {\n return origin.slice(6) + '\\n' + stack;\n }\n return origin + '\\n' + stack;\n}\n\nfunction cloneError(error: RobustError, stack: string) {\n const isAggregate = isAggregateError(error);\n\n const cloned = (\n isAggregate ? new AggregateError(structuredClone(error.errors), error.message) : new Error(error.message)\n ) as RobustError;\n cloned.stack = stitchTrace(error.stack || '', stack);\n cloned.error = error.error;\n\n // copy over enumerable properties\n Object.assign(cloned, error);\n\n return cloned;\n}\n\ninterface PendingItem {\n context: Context;\n signal: AbortSignal | null;\n abortFn: () => void;\n deferred: Deferred<unknown>;\n stack: string;\n}\n\nexport class WorkerFetch {\n declare worker: Worker | SharedWorker;\n declare threadId: string;\n declare pending: Map<number, PendingItem>;\n declare channel: MessageChannel;\n\n constructor(worker: Worker | SharedWorker | null) {\n this.threadId = isServerEnv ? '' : crypto.randomUUID();\n this.pending = new Map();\n\n const isTesting = TESTING ? true : false;\n assert(`Expected a SharedWorker instance`, isTesting || isServerEnv || worker instanceof SharedWorker);\n this.worker = worker as SharedWorker;\n\n if (!isServerEnv) {\n const fn = (event: MainThreadEvent<unknown>) => {\n const { type, id, data } = event.data;\n const info = this.cleanupRequest(id);\n\n // typically this means the request was aborted\n if (!info) {\n return;\n }\n\n if (type === 'success-response') {\n const { deferred } = info;\n\n const { response, content } = data;\n\n if (response) {\n (response as { headers: Headers }).headers = new Headers(response.headers);\n info.context.setResponse(new Response(null, response));\n }\n\n deferred.resolve(content);\n return;\n }\n\n if (type === 'error-response') {\n const { deferred, stack } = info;\n\n deferred.reject(cloneError(data, stack));\n return;\n }\n };\n\n if (worker instanceof SharedWorker) {\n worker.port.postMessage({ type: 'connect', thread: this.threadId });\n worker.port.onmessage = fn;\n } else if (worker) {\n this.channel = new MessageChannel();\n worker.postMessage({ type: 'connect', thread: this.threadId }, [this.channel.port2]);\n\n this.channel.port1.onmessage = fn;\n }\n }\n }\n\n cleanupRequest(id: number): PendingItem | undefined {\n const info = this.pending.get(id);\n this.pending.delete(id);\n\n if (info?.signal) {\n info.signal.removeEventListener('abort', info.abortFn);\n }\n\n return info;\n }\n\n send(event: RequestEventData | AbortEventData): void {\n // oxlint-disable-next-line no-unused-expressions\n this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);\n }\n\n request<T>(context: Context, next: NextFn<T>): Promise<T> | Future<T> {\n if (isServerEnv) {\n return next(context.request);\n }\n\n const deferred = createDeferred<T>();\n const { signal, request } = prepareRequest(context.request);\n const abortFn = signal\n ? () => {\n deferred.reject(enhanceReason(signal.reason as string));\n this.send({ type: 'abort', thread: this.threadId, id: context.id, data: signal.reason as string });\n this.cleanupRequest(context.id);\n }\n : () => {\n return;\n };\n\n signal?.addEventListener('abort', abortFn);\n\n try {\n throw new Error();\n } catch (e: unknown) {\n this.pending.set(context.id, {\n context,\n deferred,\n signal,\n abortFn,\n stack: (e as Error).stack!,\n });\n }\n\n this.send({\n type: 'request',\n thread: this.threadId,\n id: context.id,\n data: request,\n });\n\n return deferred.promise;\n }\n}\n\nexport function enhanceReason(reason?: string): DOMException {\n return new DOMException(reason || 'The user aborted a request.', 'AbortError');\n}\n\nfunction prepareRequest(request: Context['request']): { signal: AbortSignal | null; request: RequestInfo } {\n const { signal, headers } = request;\n const requestCopy = Object.assign({}, request) as RequestInfo;\n\n delete requestCopy.store;\n\n if (signal instanceof AbortSignal) {\n delete requestCopy.signal;\n }\n\n if (headers instanceof Headers) {\n requestCopy.headers = Array.from(headers as unknown as Iterable<[string, string][]>) as unknown as Headers;\n }\n\n return { signal: signal || null, request: requestCopy };\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive-mirror/experiments",
|
|
3
3
|
"description": "Experimental features for WarpDrive",
|
|
4
|
-
"version": "0.2.7-beta.
|
|
4
|
+
"version": "0.2.7-beta.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"unpkg-dev": "./dist/unpkg/dev/document-storage.js",
|
|
18
18
|
"unpkg-deprecated": "./dist/unpkg/prod-deprecated/document-storage.js",
|
|
19
19
|
"unpkg": "./dist/unpkg/prod/document-storage.js",
|
|
20
|
-
"types": "./
|
|
20
|
+
"types": "./dist/document-storage.d.ts",
|
|
21
21
|
"default": "./dist/document-storage.js"
|
|
22
22
|
},
|
|
23
23
|
"./data-worker": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"unpkg-dev": "./dist/unpkg/dev/data-worker.js",
|
|
26
26
|
"unpkg-deprecated": "./dist/unpkg/prod-deprecated/data-worker.js",
|
|
27
27
|
"unpkg": "./dist/unpkg/prod/data-worker.js",
|
|
28
|
-
"types": "./
|
|
28
|
+
"types": "./dist/data-worker.d.ts",
|
|
29
29
|
"default": "./dist/data-worker.js"
|
|
30
30
|
},
|
|
31
31
|
"./worker-fetch": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"unpkg-dev": "./dist/unpkg/dev/worker-fetch.js",
|
|
34
34
|
"unpkg-deprecated": "./dist/unpkg/prod-deprecated/worker-fetch.js",
|
|
35
35
|
"unpkg": "./dist/unpkg/prod/worker-fetch.js",
|
|
36
|
-
"types": "./
|
|
36
|
+
"types": "./dist/worker-fetch.d.ts",
|
|
37
37
|
"default": "./dist/worker-fetch.js"
|
|
38
38
|
},
|
|
39
39
|
"./image-worker": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"unpkg-dev": "./dist/unpkg/dev/image-worker.js",
|
|
42
42
|
"unpkg-deprecated": "./dist/unpkg/prod-deprecated/image-worker.js",
|
|
43
43
|
"unpkg": "./dist/unpkg/prod/image-worker.js",
|
|
44
|
-
"types": "./
|
|
44
|
+
"types": "./dist/image-worker.d.ts",
|
|
45
45
|
"default": "./dist/image-worker.js"
|
|
46
46
|
},
|
|
47
47
|
"./image-fetch": {
|
|
@@ -49,14 +49,21 @@
|
|
|
49
49
|
"unpkg-dev": "./dist/unpkg/dev/image-fetch.js",
|
|
50
50
|
"unpkg-deprecated": "./dist/unpkg/prod-deprecated/image-fetch.js",
|
|
51
51
|
"unpkg": "./dist/unpkg/prod/image-fetch.js",
|
|
52
|
-
"types": "./
|
|
52
|
+
"types": "./dist/image-fetch.d.ts",
|
|
53
53
|
"default": "./dist/image-fetch.js"
|
|
54
|
+
},
|
|
55
|
+
"./pagination": {
|
|
56
|
+
"unpkg-dev-deprecated": "./dist/unpkg/dev-deprecated/pagination.js",
|
|
57
|
+
"unpkg-dev": "./dist/unpkg/dev/pagination.js",
|
|
58
|
+
"unpkg-deprecated": "./dist/unpkg/prod-deprecated/pagination.js",
|
|
59
|
+
"unpkg": "./dist/unpkg/prod/pagination.js",
|
|
60
|
+
"types": "./declarations/pagination.d.ts",
|
|
61
|
+
"default": "./dist/pagination.js"
|
|
54
62
|
}
|
|
55
63
|
},
|
|
56
64
|
"files": [
|
|
57
65
|
"addon-main.cjs",
|
|
58
66
|
"dist",
|
|
59
|
-
"declarations",
|
|
60
67
|
"CHANGELOG.md",
|
|
61
68
|
"README.md",
|
|
62
69
|
"LICENSE.md",
|
|
@@ -64,7 +71,7 @@
|
|
|
64
71
|
],
|
|
65
72
|
"peerDependencies": {
|
|
66
73
|
"@sqlite.org/sqlite-wasm": "3.46.0-build2",
|
|
67
|
-
"@warp-drive-mirror/core": "5.9.0-beta.
|
|
74
|
+
"@warp-drive-mirror/core": "5.9.0-beta.2"
|
|
68
75
|
},
|
|
69
76
|
"peerDependenciesMeta": {
|
|
70
77
|
"@sqlite.org/sqlite-wasm": {
|
|
@@ -72,21 +79,18 @@
|
|
|
72
79
|
}
|
|
73
80
|
},
|
|
74
81
|
"dependencies": {
|
|
75
|
-
"@embroider/macros": "^1.
|
|
82
|
+
"@embroider/macros": "^1.20.6"
|
|
76
83
|
},
|
|
77
84
|
"devDependencies": {
|
|
78
|
-
"@babel/core": "^7.
|
|
79
|
-
"@babel/plugin-transform-typescript": "^7.
|
|
80
|
-
"@babel/preset-env": "^7.
|
|
81
|
-
"@babel/preset-typescript": "^7.
|
|
82
|
-
"@warp-drive/internal-config": "5.9.0-beta.0",
|
|
83
|
-
"@warp-drive-mirror/core": "5.9.0-beta.0",
|
|
85
|
+
"@babel/core": "^7.29.7",
|
|
86
|
+
"@babel/plugin-transform-typescript": "^7.29.7",
|
|
87
|
+
"@babel/preset-env": "^7.29.7",
|
|
88
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
84
89
|
"@sqlite.org/sqlite-wasm": "3.46.0-build2",
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"extends": "../../../../../../package.json"
|
|
90
|
+
"@warp-drive-mirror/core": "5.9.0-beta.2",
|
|
91
|
+
"@warp-drive/internal-config": "5.9.0-beta.2",
|
|
92
|
+
"tsdown": "^0.22.14",
|
|
93
|
+
"typescript-7": "npm:typescript@7.1.0-dev.20260828.1"
|
|
90
94
|
},
|
|
91
95
|
"keywords": [
|
|
92
96
|
"ember-addon"
|
|
@@ -97,9 +101,9 @@
|
|
|
97
101
|
"version": 2
|
|
98
102
|
},
|
|
99
103
|
"scripts": {
|
|
100
|
-
"
|
|
101
|
-
"build:pkg": "
|
|
104
|
+
"check:types": "node ./node_modules/typescript-7/bin/tsc --noEmit",
|
|
105
|
+
"build:pkg": "node node_modules/tsdown/dist/run.mjs",
|
|
102
106
|
"sync": "echo \"syncing\"",
|
|
103
|
-
"start": "
|
|
107
|
+
"start": "node node_modules/tsdown/dist/run.mjs --watch"
|
|
104
108
|
}
|
|
105
109
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CacheHandler as CacheHandlerType } from "@warp-drive-mirror/core/request";
|
|
2
|
-
/**
|
|
3
|
-
* A simplified CacheHandler that hydrates ResourceDataDocuments from the cache
|
|
4
|
-
* with their referenced resources.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export declare const CacheHandler: CacheHandlerType;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Context, Deferred, Future, NextFn } from "@warp-drive-mirror/core/request";
|
|
2
|
-
import type { AbortEventData, RequestEventData } from "./types.js";
|
|
3
|
-
interface PendingItem {
|
|
4
|
-
context: Context;
|
|
5
|
-
signal: AbortSignal | null;
|
|
6
|
-
abortFn: () => void;
|
|
7
|
-
deferred: Deferred<unknown>;
|
|
8
|
-
stack: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class WorkerFetch {
|
|
11
|
-
worker: Worker | SharedWorker;
|
|
12
|
-
threadId: string;
|
|
13
|
-
pending: Map<number, PendingItem>;
|
|
14
|
-
channel: MessageChannel;
|
|
15
|
-
constructor(worker: Worker | SharedWorker | null);
|
|
16
|
-
cleanupRequest(id: number): PendingItem | undefined;
|
|
17
|
-
send(event: RequestEventData | AbortEventData): void;
|
|
18
|
-
request<T>(context: Context, next: NextFn<T>): Promise<T> | Future<T>;
|
|
19
|
-
}
|
|
20
|
-
export declare function enhanceReason(reason?: string): DOMException;
|
|
21
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { RequestInfo, StructuredDataDocument, StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
|
|
2
|
-
export type SuccessResponseEventData<T> = {
|
|
3
|
-
type: "success-response";
|
|
4
|
-
thread: string;
|
|
5
|
-
id: number;
|
|
6
|
-
data: StructuredDataDocument<T>;
|
|
7
|
-
};
|
|
8
|
-
export type ErrorResponseEventData<T> = {
|
|
9
|
-
type: "error-response";
|
|
10
|
-
thread: string;
|
|
11
|
-
id: number;
|
|
12
|
-
data: StructuredErrorDocument<T>;
|
|
13
|
-
};
|
|
14
|
-
export type RequestEventData = {
|
|
15
|
-
type: "request";
|
|
16
|
-
thread: string;
|
|
17
|
-
id: number;
|
|
18
|
-
data: RequestInfo;
|
|
19
|
-
};
|
|
20
|
-
export type AbortEventData = {
|
|
21
|
-
type: "abort";
|
|
22
|
-
thread: string;
|
|
23
|
-
id: number;
|
|
24
|
-
data: string;
|
|
25
|
-
};
|
|
26
|
-
export type ThreadInitEventData = {
|
|
27
|
-
type: "connect";
|
|
28
|
-
thread: string;
|
|
29
|
-
};
|
|
30
|
-
export type MainThreadEvent<T> = MessageEvent<SuccessResponseEventData<T> | ErrorResponseEventData<T>>;
|
|
31
|
-
export type WorkerThreadEvent = MessageEvent<RequestEventData> | MessageEvent<ThreadInitEventData> | MessageEvent<AbortEventData>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ImmutableCreateRequestOptions, ImmutableDeleteRequestOptions, ImmutableRequestInfo, ImmutableUpdateRequestOptions, StructuredDataDocument } from "@warp-drive-mirror/core/types/request";
|
|
2
|
-
import type { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
3
|
-
export declare const MUTATION_OPS: Set<string>;
|
|
4
|
-
export declare function isMutation(request: Partial<ImmutableRequestInfo>): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions;
|
|
5
|
-
export declare function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean;
|
|
6
|
-
type RobustError = Error & {
|
|
7
|
-
error: string | object;
|
|
8
|
-
errors?: ApiError[];
|
|
9
|
-
content?: unknown;
|
|
10
|
-
};
|
|
11
|
-
export declare function cloneError(error: RobustError): RobustError;
|
|
12
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Store } from "@warp-drive-mirror/core";
|
|
2
|
-
import type { Future } from "@warp-drive-mirror/core/request";
|
|
3
|
-
import { DocumentStorage } from "../document-storage.js";
|
|
4
|
-
import type { AbortEventData, RequestEventData } from "./types.js";
|
|
5
|
-
export declare class DataWorker {
|
|
6
|
-
store: Store;
|
|
7
|
-
threads: Map<string, MessagePort>;
|
|
8
|
-
pending: Map<string, Map<number, Future<unknown>>>;
|
|
9
|
-
isSharedWorker: boolean;
|
|
10
|
-
options: {
|
|
11
|
-
persisted: boolean;
|
|
12
|
-
scope?: string;
|
|
13
|
-
};
|
|
14
|
-
storage: DocumentStorage;
|
|
15
|
-
constructor(UserStore: typeof Store, options?: {
|
|
16
|
-
persisted: boolean;
|
|
17
|
-
scope?: string;
|
|
18
|
-
});
|
|
19
|
-
initialize(): void;
|
|
20
|
-
setupThread(thread: string, port: MessagePort): void;
|
|
21
|
-
abortRequest(event: AbortEventData): void;
|
|
22
|
-
request(event: RequestEventData): Promise<void>;
|
|
23
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { PersistedResourceKey } from "@warp-drive-mirror/core/types/identifier";
|
|
2
|
-
import type { StructuredDocument } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { ResourceDataDocument, ResourceDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
|
-
import type { ExistingResourceObject } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
5
|
-
export declare const WARP_DRIVE_STORAGE_FILE_NAME = "warp-drive_document-storage";
|
|
6
|
-
export declare const WARP_DRIVE_STORAGE_VERSION = 1;
|
|
7
|
-
export type DocumentStorageOptions = {
|
|
8
|
-
/**
|
|
9
|
-
* The scope of the storage. This is used to enable multiple distinct
|
|
10
|
-
* storage areas within the same origin.
|
|
11
|
-
*
|
|
12
|
-
* One use case for this is to have a separate storage area for each
|
|
13
|
-
* user credential. So for instance, in applications that allow a single
|
|
14
|
-
* user to have multiple accounts, each account can have its own storage!
|
|
15
|
-
*/
|
|
16
|
-
scope: string;
|
|
17
|
-
/**
|
|
18
|
-
* When set to true, if other instances of the storage are created with
|
|
19
|
-
* the same scope, they will not share the same in-memory cache and BroadcastChannel.
|
|
20
|
-
*
|
|
21
|
-
* This is mostly useful for testing purposes to replicate the behavior of
|
|
22
|
-
* multiple tabs or workers.
|
|
23
|
-
*/
|
|
24
|
-
isolated: boolean;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* DocumentStorage is specifically designed around WarpDrive Cache and Request concepts.
|
|
28
|
-
*
|
|
29
|
-
* CacheFileDocument is a StructuredDocument (request response) whose `content` is
|
|
30
|
-
* the ResourceDocument returned by inserting the request into a Store's Cache.
|
|
31
|
-
*/
|
|
32
|
-
type CacheFileDocument = StructuredDocument<ResourceDocument>;
|
|
33
|
-
/**
|
|
34
|
-
* A CacheDocument is a reconstructed request response that rehydrates ResourceDocument
|
|
35
|
-
* with the associated resources based on their identifiers.
|
|
36
|
-
*/
|
|
37
|
-
type CacheDocument = StructuredDocument<ResourceDocument<ExistingResourceObject>>;
|
|
38
|
-
type DocumentIdentifier = {
|
|
39
|
-
lid: string;
|
|
40
|
-
};
|
|
41
|
-
type MemCache = {
|
|
42
|
-
documents: Map<string, CacheFileDocument>;
|
|
43
|
-
resources: Map<string, ExistingResourceObject>;
|
|
44
|
-
};
|
|
45
|
-
declare class InternalDocumentStorage {
|
|
46
|
-
readonly options: DocumentStorageOptions;
|
|
47
|
-
_fileHandle: Promise<FileSystemFileHandle>;
|
|
48
|
-
_channel: BroadcastChannel;
|
|
49
|
-
_invalidated: boolean;
|
|
50
|
-
_lastModified: number;
|
|
51
|
-
_cache: MemCache | null;
|
|
52
|
-
_filePromise: Promise<MemCache> | null;
|
|
53
|
-
constructor(options: DocumentStorageOptions);
|
|
54
|
-
_onMessage(_event: MessageEvent): void;
|
|
55
|
-
_open(scope: string): Promise<FileSystemFileHandle>;
|
|
56
|
-
_read(): Promise<MemCache>;
|
|
57
|
-
_patch(documentKey: string, document: CacheFileDocument, updatedResources: Map<string, ExistingResourceObject>): Promise<void>;
|
|
58
|
-
getDocument(key: DocumentIdentifier): Promise<CacheDocument | null>;
|
|
59
|
-
putDocument(document: CacheFileDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
|
|
60
|
-
_getResources(document: ResourceDataDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject, resources?: Map<string, ExistingResourceObject>): Map<string, ExistingResourceObject>;
|
|
61
|
-
putResources(document: ResourceDataDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
|
|
62
|
-
clear(reset?: boolean): Promise<void>;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* DocumentStorage is a wrapper around the StorageManager API that provides
|
|
66
|
-
* a simple interface for reading and updating documents and requests.
|
|
67
|
-
*
|
|
68
|
-
* Some goals for this experiment:
|
|
69
|
-
*
|
|
70
|
-
* - optimize for storing requests/documents
|
|
71
|
-
* - optimize for storing resources
|
|
72
|
-
* - optimize for looking up resources associated to a document
|
|
73
|
-
* - optimize for notifying cross-tab when data is updated
|
|
74
|
-
*
|
|
75
|
-
* optional features:
|
|
76
|
-
*
|
|
77
|
-
* - support for offline mode
|
|
78
|
-
* - ?? support for relationship based cache traversal
|
|
79
|
-
* - a way to index records by type + another field (e.g updatedAt/createAt/name)
|
|
80
|
-
* such that simple queries can be done without having to scan all records
|
|
81
|
-
*/
|
|
82
|
-
export declare class DocumentStorage {
|
|
83
|
-
readonly _storage: InternalDocumentStorage;
|
|
84
|
-
constructor(options?: Partial<DocumentStorageOptions>);
|
|
85
|
-
getDocument(key: DocumentIdentifier): Promise<CacheDocument | null>;
|
|
86
|
-
putDocument(document: CacheFileDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
|
|
87
|
-
putResources(document: ResourceDataDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
|
|
88
|
-
clear(reset?: boolean): Promise<void>;
|
|
89
|
-
}
|
|
90
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DocumentStorage } from "./document-storage/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ImageFetch } from "./image-worker/fetch.js";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Deferred } from "@warp-drive-mirror/core/request";
|
|
2
|
-
import type { RequestEventData } from "./types.js";
|
|
3
|
-
export interface FastBoot {
|
|
4
|
-
require(moduleName: string): unknown;
|
|
5
|
-
isFastBoot: boolean;
|
|
6
|
-
request: Request;
|
|
7
|
-
}
|
|
8
|
-
export declare class ImageFetch {
|
|
9
|
-
worker: Worker | SharedWorker;
|
|
10
|
-
threadId: string;
|
|
11
|
-
pending: Map<string, Deferred<string>>;
|
|
12
|
-
channel: MessageChannel;
|
|
13
|
-
cache: Map<string, string>;
|
|
14
|
-
constructor(worker: Worker | SharedWorker | null);
|
|
15
|
-
cleanupRequest(url: string): Deferred<string> | undefined;
|
|
16
|
-
_send(event: RequestEventData): void;
|
|
17
|
-
load(url: string): Promise<string>;
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type SuccessResponseEventData = {
|
|
2
|
-
type: "success-response";
|
|
3
|
-
thread: string;
|
|
4
|
-
url: string;
|
|
5
|
-
};
|
|
6
|
-
export type ErrorResponseEventData = {
|
|
7
|
-
type: "error-response";
|
|
8
|
-
thread: string;
|
|
9
|
-
url: string;
|
|
10
|
-
};
|
|
11
|
-
export type RequestEventData = {
|
|
12
|
-
type: "load";
|
|
13
|
-
thread: string;
|
|
14
|
-
url: string;
|
|
15
|
-
};
|
|
16
|
-
export type ThreadInitEventData = {
|
|
17
|
-
type: "connect";
|
|
18
|
-
thread: string;
|
|
19
|
-
};
|
|
20
|
-
export type MainThreadEvent = MessageEvent<SuccessResponseEventData | ErrorResponseEventData>;
|
|
21
|
-
export type WorkerThreadEvent = MessageEvent<RequestEventData> | MessageEvent<ThreadInitEventData>;
|