osra 0.0.11 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/build/index.js CHANGED
@@ -1,181 +1,280 @@
1
- const g = "osra-message", l = ({
2
- target: e,
3
- resolvers: t,
4
- filter: r,
5
- map: n,
6
- key: a = g
7
- }) => {
8
- const o = (s) => {
9
- if (!s.data || typeof s.data != "object" || s.data?.source !== a || r && !r(s))
10
- return;
11
- const { type: c, data: i, port: d } = s.data, m = t[c];
12
- if (!m)
13
- throw new Error(`Osra received a message of type "${String(c)}" but no resolver was found for type.`);
14
- n ? m(...n(i, { event: s, type: c, port: d })) : m(i, { event: s, type: c, port: d });
1
+ const p = [];
2
+ for (let e = 0; e < 256; ++e)
3
+ p.push((e + 256).toString(16).slice(1));
4
+ function N(e, t = 0) {
5
+ return (p[e[t + 0]] + p[e[t + 1]] + p[e[t + 2]] + p[e[t + 3]] + "-" + p[e[t + 4]] + p[e[t + 5]] + "-" + p[e[t + 6]] + p[e[t + 7]] + "-" + p[e[t + 8]] + p[e[t + 9]] + "-" + p[e[t + 10]] + p[e[t + 11]] + p[e[t + 12]] + p[e[t + 13]] + p[e[t + 14]] + p[e[t + 15]]).toLowerCase();
6
+ }
7
+ let _;
8
+ const D = new Uint8Array(16);
9
+ function z() {
10
+ if (!_) {
11
+ if (typeof crypto > "u" || !crypto.getRandomValues)
12
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
13
+ _ = crypto.getRandomValues.bind(crypto);
14
+ }
15
+ return _(D);
16
+ }
17
+ const Y = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), j = { randomUUID: Y };
18
+ function V(e, t, r) {
19
+ if (j.randomUUID && !t && !e)
20
+ return j.randomUUID();
21
+ e = e || {};
22
+ const o = e.random || (e.rng || z)();
23
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, N(o);
24
+ }
25
+ const E = "__OSRA__", G = "__OSRA_DEFAULT_KEY__", w = "__OSRA_PROXY__", x = (e) => !!(globalThis.SharedArrayBuffer && e instanceof globalThis.SharedArrayBuffer), B = (e) => globalThis.ArrayBuffer && e instanceof globalThis.ArrayBuffer || globalThis.MessagePort && e instanceof globalThis.MessagePort || globalThis.ReadableStream && e instanceof globalThis.ReadableStream || globalThis.WritableStream && e instanceof globalThis.WritableStream || globalThis.TransformStream && e instanceof globalThis.TransformStream ? !0 : !!(globalThis.ImageBitmap && e instanceof globalThis.ImageBitmap), M = (e) => {
26
+ const t = [], r = (o) => x(o) ? void 0 : B(o) ? t.push(o) : Array.isArray(o) ? o.map(r) : o && typeof o == "object" ? Object.values(o).map(r) : void 0;
27
+ return r(e), t;
28
+ }, K = (e, t) => {
29
+ const r = "portId" in e ? e.portId : void 0, o = "port" in e ? e.port : r ? t.addIncomingProxiedMessagePort(r) : void 0;
30
+ if (!o) throw new Error("No ports received for proxied function");
31
+ const c = (...n) => new Promise((i, f) => {
32
+ const { port1: g, port2: l } = new MessageChannel(), m = y([l, n], t), A = M(m), S = (h) => {
33
+ const b = R(h.data, t);
34
+ if (!(b instanceof Promise)) throw new Error("Proxied function did not return a promise");
35
+ b.then(i).catch(f).finally(() => g.close());
36
+ };
37
+ g.addEventListener("message", S, { once: !0 }), g.start(), o.postMessage(m, { transfer: A });
38
+ });
39
+ return r && t.finalizationRegistry.register(c, Number(r.split("/")[1])), c;
40
+ }, W = (e, t) => {
41
+ const r = t.envCheck.supportsPorts && "port" in e ? e.port : "portId" in e ? t.addIncomingProxiedMessagePort(e.portId) : void 0;
42
+ if (!r) throw new Error("No ports received for proxied message port");
43
+ return r;
44
+ }, X = (e, t) => new Error(e.message, { cause: e.stack }), H = (e, t) => new Promise((r, o) => {
45
+ const c = "port" in e ? e.port : "portId" in e ? t.addIncomingProxiedMessagePort(e.portId) : void 0;
46
+ if (!c) throw new Error("No ports received for proxied promise");
47
+ const n = async (i) => {
48
+ const f = await R(i.data, t);
49
+ f instanceof Error ? o(f) : r(f), c.close();
15
50
  };
16
- return e.addEventListener("message", o), {
17
- listener: o,
18
- resolvers: t
51
+ c.addEventListener("message", n, { once: !0 }), c.start();
52
+ }), R = (e, t) => O(
53
+ e,
54
+ (r) => !!(r && typeof r == "object" && w in r && r[w]),
55
+ (r) => {
56
+ if (r.type === "function")
57
+ return K(r, t);
58
+ if (r.type === "error")
59
+ return X(r);
60
+ if (r.type === "messagePort")
61
+ return W(r, t);
62
+ if (r.type === "promise")
63
+ return H(r, t);
64
+ throw new Error(`Unknown incoming proxied type: ${e}`);
65
+ }
66
+ ), q = (e, t) => ({
67
+ [w]: !0,
68
+ type: "error",
69
+ message: e.message,
70
+ stack: e.stack
71
+ }), F = (e, t) => ({
72
+ [w]: !0,
73
+ type: "messagePort",
74
+ ...t.envCheck.supportsPorts ? { port: e } : { portId: t.addOutgoingProxiedMessagePort(e) }
75
+ }), J = (e, t) => {
76
+ const { port1: r, port2: o } = new MessageChannel(), c = (n) => {
77
+ const i = y(n, t), f = M(i);
78
+ r.postMessage(i, { transfer: f }), r.close();
19
79
  };
20
- }, b = (e) => !!(globalThis.SharedArrayBuffer && e instanceof globalThis.SharedArrayBuffer), y = (e) => globalThis.ArrayBuffer && e instanceof globalThis.ArrayBuffer || globalThis.MessagePort && e instanceof globalThis.MessagePort || globalThis.ReadableStream && e instanceof globalThis.ReadableStream || globalThis.WritableStream && e instanceof globalThis.WritableStream || globalThis.TransformStream && e instanceof globalThis.TransformStream ? !0 : !!(globalThis.ImageBitmap && e instanceof globalThis.ImageBitmap), h = (e) => {
21
- const t = [], r = (n) => b(n) ? void 0 : y(n) ? t.push(n) : Array.isArray(n) ? n.map(r) : n && typeof n == "object" ? Object.values(n).map(r) : void 0;
22
- return r(e), t;
23
- }, p = "__proxyFunctionPort__", M = "__proxyMessageChannelPort__", j = (e) => {
24
- const { port1: t, port2: r } = new MessageChannel();
25
- return t.addEventListener("message", async (n) => {
26
- try {
27
- const a = await e(...n.data), o = f(a), s = h(o);
28
- t.postMessage({ result: o }, { transfer: s });
29
- } catch (a) {
30
- t.postMessage({ error: a });
31
- }
32
- }), t.start(), r;
33
- }, f = (e) => b(e) || y(e) ? e : typeof e == "function" ? { [p]: j(e) } : Array.isArray(e) ? e.map(f) : e && typeof e == "object" ? Object.fromEntries(
34
- Object.entries(e).map(([t, r]) => [
35
- t,
36
- f(r)
37
- ])
38
- ) : e, x = (e) => (...t) => new Promise((r, n) => {
39
- const a = f(t), o = h(a), s = (c) => {
40
- c.data.error ? n(c.data.error) : r(E(c.data.result)), e.removeEventListener("message", s);
80
+ return e.then(c).catch(c), {
81
+ [w]: !0,
82
+ type: "promise",
83
+ port: y(o, t)
41
84
  };
42
- e.addEventListener("message", s), e.start(), e.postMessage(a, { transfer: o });
43
- }), E = (e) => b(e) || y(e) ? e : e && typeof e == "object" && e[p] ? x(e[p]) : Array.isArray(e) ? e.map(f) : e && typeof e == "object" ? Object.fromEntries(
44
- Object.entries(e).map(([t, r]) => [
45
- t,
46
- E(r)
85
+ }, Q = (e, t) => {
86
+ const { port1: r, port2: o } = new MessageChannel();
87
+ return r.addEventListener("message", async (c) => {
88
+ const [n, i] = R(c.data, t), f = (async () => e(...i))(), g = y(f, t), l = M(g);
89
+ n.postMessage(g, { transfer: l }), n.close();
90
+ }), r.start(), {
91
+ [w]: !0,
92
+ type: "function",
93
+ port: y(o, t)
94
+ };
95
+ }, y = (e, t) => O(
96
+ e,
97
+ (r) => typeof r == "function" || r instanceof Error || r instanceof MessagePort || r instanceof Promise,
98
+ (r) => {
99
+ if (typeof r == "function")
100
+ return Q(r, t);
101
+ if (r instanceof Error)
102
+ return q(r);
103
+ if (r instanceof MessagePort)
104
+ return F(r, t);
105
+ if (r instanceof Promise)
106
+ return J(r, t);
107
+ throw new Error(`Unknown outgoing proxied type: ${r}`);
108
+ }
109
+ ), O = (e, t, r) => x(e) || B(e) ? e : t(e) ? r(e) : Array.isArray(e) ? e.map((o) => O(o, t, r)) : e && typeof e == "object" ? Object.fromEntries(
110
+ Object.entries(e).map(([o, c]) => [
111
+ o,
112
+ O(c, t, r)
47
113
  ])
48
- ) : e, A = (e, { key: t = g } = { key: g }) => (r, n) => new Promise((a, o) => {
49
- const { port1: s, port2: c } = new MessageChannel();
50
- s.addEventListener(
51
- "message",
52
- ({ data: m }) => {
53
- if (m.error)
54
- o(m.error);
55
- else {
56
- const L = E(m.result);
57
- a(L);
114
+ ) : e, Z = () => {
115
+ let e = 0;
116
+ const t = /* @__PURE__ */ new Set();
117
+ return {
118
+ alloc: () => {
119
+ if (t.size > 0) {
120
+ const r = t.values().next().value;
121
+ if (r === void 0)
122
+ throw new Error("Tried to allocate number from freedUnused but result was undefined");
123
+ return t.delete(r), r;
58
124
  }
59
- s.close(), c.close();
60
- },
61
- { once: !0 }
62
- ), s.start();
63
- const i = f(n), d = h(i);
64
- e.postMessage(
65
- {
66
- source: t,
67
- type: r,
68
- data: i,
69
- port: c
125
+ return e++, e;
70
126
  },
71
- {
72
- targetOrigin: "*",
73
- transfer: [c, ...d ?? []]
74
- }
75
- );
76
- }), _ = (e) => async (t, r) => {
77
- const { port: n } = r, a = E(t);
78
- try {
79
- const o = await e(a, r), s = f(o), c = h(s);
80
- return n.postMessage({ result: s }, { transfer: c }), n.close(), o;
81
- } catch (o) {
82
- throw n.postMessage({ error: o }), n.close(), o;
83
- }
84
- }, w = ({ key: e = g }) => {
85
- const t = /* @__PURE__ */ new Map(), r = async (a) => t.get(a) ?? new Promise((o, s) => {
86
- let c = !1;
87
- setTimeout(() => {
88
- c || s(new Error(`Osra getPort for "${a}" timed out`));
89
- }, 1e3), chrome.runtime.onConnect.addListener((i) => {
90
- i.name === `${e}:${a}` && (t.set(a, i), o(i), c = !0);
91
- });
92
- }), n = {
93
- addPort: (a, o) => t.set(a, o),
94
- proxyPort: (a) => {
95
- const o = self.crypto.randomUUID(), s = chrome.runtime.connect({ name: `${e}:${o}` });
96
- return t.set(o, s), s.onDisconnect.addListener(() => {
97
- t.delete(o);
98
- }), s.onMessage.addListener((c) => {
99
- a.postMessage(c);
100
- }), a.addEventListener("message", async (c) => {
101
- s.postMessage(c.data);
102
- }), a.addEventListener("close", () => {
103
- s.disconnect();
104
- }), {
105
- [M]: o
106
- };
107
- },
108
- proxiedPort: async ({ [M]: a }) => {
109
- const { port1: o, port2: s } = new MessageChannel(), c = await r(a);
110
- c.onMessage.addListener((d) => {
111
- o.postMessage(d);
112
- }), c.onDisconnect.addListener(() => {
113
- o.close();
114
- }), o.addEventListener("close", () => {
115
- c.disconnect();
116
- }), o.addEventListener("message", async (d) => {
117
- c.postMessage(d.data);
118
- }), o.start(), s.addEventListener("message", async (d) => {
119
- c.postMessage(d.data);
120
- }), s.start();
121
- const i = O(n, s);
122
- return i.uuid = a, i;
127
+ free: (r) => {
128
+ t.add(r);
123
129
  }
124
130
  };
125
- return n;
126
- }, P = (e, t) => t instanceof MessagePort ? e.proxyPort(t) : b(t) || y(t) ? t : typeof t == "object" && p in t ? { [p]: e.proxyPort(t[p]) } : Array.isArray(t) ? t.map((r) => P(e, r)) : t && typeof t == "object" ? Object.fromEntries(
127
- Object.entries(t).map(([r, n]) => [
128
- r,
129
- P(e, n)
130
- ])
131
- ) : t, T = async (e, t) => b(t) || y(t) ? t : typeof t == "object" && M in t ? await e.proxiedPort(t) : typeof t == "object" && p in t ? { [p]: await e.proxiedPort(t[p]) } : Array.isArray(t) ? await Promise.all(t.map((r) => T(e, r))) : t && typeof t == "object" ? Object.fromEntries(
132
- await Promise.all(
133
- Object.entries(t).map(async ([r, n]) => [
134
- r,
135
- await T(e, n)
136
- ])
137
- )
138
- ) : t, O = (e, t) => {
139
- const r = t.postMessage;
140
- return t.postMessage = (n) => {
141
- r.apply(t, [P(e, n)]);
142
- }, t;
143
- }, S = ({
144
- target: e,
145
- key: t = g
146
- }) => {
147
- const r = w({ key: t });
131
+ }, v = ({ numberAllocator: e }) => {
132
+ const t = /* @__PURE__ */ new Map();
148
133
  return {
149
- ...e,
150
- postMessage: (n) => {
151
- e.runtime.sendMessage(P(r, n));
134
+ alloc: (n) => {
135
+ const i = e.alloc();
136
+ return t.set(i, n), i;
137
+ },
138
+ get: (n) => t.get(n),
139
+ free: (n) => {
140
+ t.delete(n), e.free(n);
152
141
  }
153
142
  };
154
- }, C = ({
155
- target: e,
156
- key: t = g
143
+ }, ee = async (e, {
144
+ remote: t,
145
+ local: r,
146
+ key: o = G,
147
+ origin: c = "*"
157
148
  }) => {
158
- const r = w({ key: t });
159
- return {
160
- ...e,
161
- addEventListener: (n, a, o) => {
162
- if (n !== "message")
163
- return e.addEventListener(n, a, o);
164
- chrome.runtime.onMessage.addListener((s, c, i) => {
165
- T(r, s).then((d) => a({ data: d }));
166
- }), chrome.runtime.onConnect.addListener((s) => {
167
- s.name.startsWith(`${t}:`) && r.addPort(s.name.split(":")[1], s);
168
- });
169
- }
149
+ const n = V();
150
+ let i;
151
+ const f = new FinalizationRegistry((s) => {
152
+ const a = l.get(s);
153
+ if (!a) throw new Error(`Osra received a port-closed message with an invalid portId "${s}".`);
154
+ a(), l.free(s);
155
+ }), g = Z(), l = v({ numberAllocator: g }), m = /* @__PURE__ */ new Map(), A = (s) => {
156
+ const { port1: a, port2: d } = new MessageChannel();
157
+ return m.set(s, a), d;
158
+ }, S = (s) => {
159
+ const a = l.alloc(() => {
160
+ s.close();
161
+ });
162
+ return s.addEventListener("message", async (d) => {
163
+ T(
164
+ {
165
+ [E]: !0,
166
+ key: o,
167
+ type: "message",
168
+ portId: `${n}/${a}`,
169
+ data: y(d.data, h())
170
+ },
171
+ []
172
+ );
173
+ }), s.addEventListener("close", () => {
174
+ g.free(a), T(
175
+ {
176
+ [E]: !0,
177
+ key: o,
178
+ type: "port-closed",
179
+ portId: `${n}/${a}`
180
+ },
181
+ []
182
+ );
183
+ }), `${n}/${a}`;
184
+ }, h = () => {
185
+ if (!i) throw new Error("Osra context was accessed before the ready message was received.");
186
+ return {
187
+ addIncomingProxiedMessagePort: A,
188
+ addOutgoingProxiedMessagePort: S,
189
+ envCheck: i,
190
+ finalizationRegistry: f
191
+ };
170
192
  };
193
+ let b;
194
+ const L = new Promise((s, a) => {
195
+ b = s;
196
+ }), U = () => {
197
+ const s = new ArrayBuffer(1), { port1: a } = new MessageChannel();
198
+ T(
199
+ {
200
+ [E]: !0,
201
+ key: o,
202
+ type: "ready",
203
+ envCheck: { buffer: s, port: a }
204
+ },
205
+ [s, a]
206
+ );
207
+ };
208
+ let C = !1;
209
+ const $ = async (s) => {
210
+ if (!s.data || typeof s.data != "object" || !s.data[E] || s.data.key !== o) return;
211
+ const { type: a } = s.data;
212
+ if (a === "ready" && !C) {
213
+ C = !0, i = {
214
+ uuid: n,
215
+ supportsPorts: s.data.envCheck.port instanceof MessagePort,
216
+ jsonOnly: s.data.envCheck.buffer instanceof ArrayBuffer
217
+ }, U();
218
+ const d = y(e, h()), u = M(d);
219
+ T(
220
+ {
221
+ [E]: !0,
222
+ key: o,
223
+ type: "init",
224
+ data: d
225
+ },
226
+ u
227
+ );
228
+ return;
229
+ }
230
+ if (!C || !i) throw new Error("Osra received a message before the ready message.");
231
+ if (a === "init") {
232
+ b(
233
+ R(
234
+ s.data.data,
235
+ h()
236
+ )
237
+ );
238
+ return;
239
+ }
240
+ if (a === "message") {
241
+ const { portId: d, data: u } = s.data, I = m.get(d);
242
+ if (!I) throw new Error(`Osra received a message with portId set to "${d}" but no port was found.`);
243
+ I.postMessage(u);
244
+ } else if (a === "port-closed") {
245
+ const { portId: d } = s.data, [u, I] = d.split("/"), k = Number(I);
246
+ if (!k) throw new Error(`Osra received a port-closed message with an invalid portId "${d}".`);
247
+ if (u !== n && u !== i.uuid) throw new Error(`Osra received a port-closed message with an invalid portId's uuid "${d}".`);
248
+ if (u === n) {
249
+ const P = l.get(k);
250
+ if (!P) throw new Error(`Osra received a port-closed message with an invalid portId "${d}".`);
251
+ P();
252
+ } else if (u === i.uuid) {
253
+ const P = m.get(d);
254
+ if (!P) throw new Error(`Osra received a message with portId set to "${d}" but no port was found.`);
255
+ P.close(), m.delete(d);
256
+ }
257
+ }
258
+ }, T = typeof t == "function" ? t : (s, a = []) => t.postMessage(s, { targetOrigin: c, transfer: a });
259
+ return typeof r == "function" ? r($) : r.addEventListener("message", $), U(), L;
171
260
  };
172
261
  export {
173
- A as call,
174
- _ as makeCallListener,
175
- l as registerListener,
176
- T as replaceProxied,
177
- P as replaceProxies,
178
- S as wrapExtensionTarget,
179
- C as wrapListenerExtensionTarget,
180
- O as wrapPort
262
+ q as errorToProxiedError,
263
+ ee as expose,
264
+ Q as functionToProxiedFunction,
265
+ M as getTransferableObjects,
266
+ x as isClonable,
267
+ B as isTransferable,
268
+ v as makeAllocator,
269
+ Z as makeNumberAllocator,
270
+ F as messagePortToProxiedMessagePort,
271
+ J as promiseToProxiedPromise,
272
+ X as proxiedErrorToError,
273
+ K as proxiedFunctionToFunction,
274
+ W as proxiedMessagePortToMessagePort,
275
+ H as proxiedPromiseToPromise,
276
+ R as replaceIncomingProxiedTypes,
277
+ y as replaceOutgoingProxiedTypes,
278
+ O as replaceRecursive
181
279
  };
280
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../node_modules/uuid/dist/esm-browser/stringify.js","../node_modules/uuid/dist/esm-browser/rng.js","../node_modules/uuid/dist/esm-browser/native.js","../node_modules/uuid/dist/esm-browser/v4.js","../src/types.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","let getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n if (!getRandomValues) {\n if (typeof crypto === 'undefined' || !crypto.getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n getRandomValues = crypto.getRandomValues.bind(crypto);\n }\n return getRandomValues(rnds8);\n}\n","const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random || (options.rng || rng)();\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","export const OSRA_MESSAGE_PROPERTY = '__OSRA__' as const\r\nexport const OSRA_MESSAGE_KEY = '__OSRA_DEFAULT_KEY__' as const\r\nexport const OSRA_PROXY = '__OSRA_PROXY__' as const\r\n\r\nexport type JsonPropertyKey = string | number\r\nexport type JsonCloneType =\r\n | boolean\r\n | null\r\n | number\r\n | string\r\n | { [key: string]: JsonCloneType }\r\n | Array<JsonCloneType>\r\n\r\nexport type StructuredCloneType =\r\n | JsonCloneType\r\n | void\r\n | undefined\r\n | BigInt\r\n | Date\r\n | RegExp\r\n | Blob\r\n | File\r\n | FileList\r\n | ArrayBuffer\r\n | ArrayBufferView\r\n | ImageBitmap\r\n | ImageData\r\n | { [key: string]: StructuredCloneType }\r\n | Array<StructuredCloneType>\r\n | Map<StructuredCloneType, StructuredCloneType>\r\n | Set<StructuredCloneType>\r\n\r\nexport type TransferableObject =\r\n | SharedArrayBuffer\r\n | ArrayBuffer\r\n | MessagePort\r\n | ReadableStream\r\n /*\r\n | WritableStream\r\n | TransformStream\r\n | ImageBitmap\r\n | AudioData\r\n | VideoFrame\r\n | OffscreenCanvas\r\n */\r\n\r\nexport type StructuredCloneTransferableType =\r\n | StructuredCloneType\r\n | TransferableObject\r\n | { [key: string]: StructuredCloneTransferableType }\r\n | Array<StructuredCloneTransferableType>\r\n | Map<StructuredCloneTransferableType, StructuredCloneTransferableType>\r\n | Set<StructuredCloneTransferableType>\r\n\r\nexport type ProxiableType =\r\n | Promise<StructuredCloneTransferableProxiableType>\r\n | Error\r\n | MessagePort\r\n | ReadableStream\r\n | ((...args: any[]) => Promise<StructuredCloneTransferableProxiableType>)\r\n // | ((...args: StructuredCloneTransferableProxiableType[]) => StructuredCloneTransferableProxiableType)\r\n | { [key: string]: StructuredCloneTransferableProxiableType }\r\n | Array<StructuredCloneTransferableProxiableType>\r\n | Map<StructuredCloneTransferableProxiableType, StructuredCloneTransferableProxiableType>\r\n | Set<StructuredCloneTransferableProxiableType>\r\n\r\nexport type StructuredCloneTransferableProxiableType = ProxiableType | StructuredCloneTransferableType\r\n\r\ntype PortOrJsonPort<JsonOnly extends boolean> = JsonOnly extends true ? { portId: string } : { port: MessagePort }\r\ntype StructuredCloneDataOrJsonData<JsonOnly extends boolean> = JsonOnly extends true ? JsonCloneType : StructuredCloneType\r\n\r\nexport type ProxiedFunctionType<JsonOnly extends boolean> = ({ type: 'function' } & PortOrJsonPort<JsonOnly>)\r\nexport type ProxiedMessagePortType<JsonOnly extends boolean> = ({ type: 'messagePort' } & PortOrJsonPort<JsonOnly>)\r\nexport type ProxiedPromiseType<JsonOnly extends boolean> = ({ type: 'promise' } & PortOrJsonPort<JsonOnly>)\r\nexport type ProxiedReadableStreamType<JsonOnly extends boolean> = ({ type: 'readableStream' } & PortOrJsonPort<JsonOnly>)\r\nexport type ProxiedErrorType = ({ type: 'error', message: string, stack?: string })\r\n\r\nexport type ProxiedType<JsonOnly extends boolean> =\r\n { [OSRA_PROXY]: true } & (\r\n | ProxiedFunctionType<JsonOnly>\r\n | ProxiedMessagePortType<JsonOnly>\r\n | ProxiedPromiseType<JsonOnly>\r\n | ProxiedReadableStreamType<JsonOnly>\r\n | ProxiedErrorType\r\n )\r\nexport type OsraMessage =\r\n { [OSRA_MESSAGE_PROPERTY]: true, key: string } & (\r\n | { type: 'ready', envCheck: { buffer: ArrayBuffer, port: MessagePort } }\r\n | { type: 'init', data: StructuredCloneTransferableType }\r\n | { type: 'message', portId: string, data: any } // message not needed if transferring MessagePort is supported\r\n | { type: 'port-closed', portId: string } // message not needed if transferring MessagePort is supported\r\n )\r\n\r\nexport type RemoteTarget = Window | ServiceWorker | Worker | MessagePort\r\nexport type LocalTarget = WindowEventHandlers | ServiceWorkerContainer | Worker | SharedWorker\r\n","import type {\r\n StructuredCloneTransferableType, TransferableObject, ProxiedErrorType,\r\n ProxiedFunctionType, ProxiedMessagePortType, ProxiedPromiseType,\r\n ProxiedType, StructuredCloneTransferableProxiableType,\r\n} from './types'\r\n\r\nimport { OSRA_PROXY } from './types'\r\n\r\nexport const isClonable = (value: any) =>\r\n globalThis.SharedArrayBuffer && value instanceof globalThis.SharedArrayBuffer ? true\r\n : false\r\n\r\nexport const isTransferable = (value: any) =>\r\n globalThis.ArrayBuffer && value instanceof globalThis.ArrayBuffer ? true\r\n : globalThis.MessagePort && value instanceof globalThis.MessagePort ? true\r\n : globalThis.ReadableStream && value instanceof globalThis.ReadableStream ? true\r\n : globalThis.WritableStream && value instanceof globalThis.WritableStream ? true\r\n : globalThis.TransformStream && value instanceof globalThis.TransformStream ? true\r\n : globalThis.ImageBitmap && value instanceof globalThis.ImageBitmap ? true\r\n : false\r\n\r\nexport const getTransferableObjects = (value: any): TransferableObject[] => {\r\n const transferables: TransferableObject[] = []\r\n const recurse = (value: any) => \r\n isClonable(value) ? undefined\r\n : isTransferable(value) ? transferables.push(value)\r\n : Array.isArray(value) ? value.map(recurse)\r\n : value && typeof value === 'object' ? Object.values(value).map(recurse)\r\n : undefined\r\n\r\n recurse(value)\r\n return transferables\r\n}\r\n\r\nexport type EnvCheck = {\r\n uuid: string\r\n supportsPorts: boolean\r\n jsonOnly: boolean\r\n}\r\n\r\nexport type Context = {\r\n envCheck: EnvCheck\r\n addIncomingProxiedMessagePort: (portId: string) => MessagePort\r\n addOutgoingProxiedMessagePort: (port: MessagePort) => string\r\n finalizationRegistry: FinalizationRegistry<number>\r\n}\r\n\r\nexport const proxiedFunctionToFunction = <JsonOnly extends boolean>(proxiedFunction: ProxiedFunctionType<JsonOnly>, context: Context) => {\r\n const portId = 'portId' in proxiedFunction ? proxiedFunction.portId : undefined\r\n const port =\r\n 'port' in proxiedFunction ? proxiedFunction.port\r\n : portId ? context.addIncomingProxiedMessagePort(portId)\r\n : undefined\r\n if (!port) throw new Error(`No ports received for proxied function`)\r\n\r\n const func = (...args: StructuredCloneTransferableType[]) =>\r\n new Promise((resolve, reject) => {\r\n const { port1: returnValueLocalPort, port2: returnValueRemotePort } = new MessageChannel()\r\n const functionContext = replaceOutgoingProxiedTypes([returnValueRemotePort, args], context)\r\n const functionContextTransferables = getTransferableObjects(functionContext)\r\n const listener = (event: MessageEvent) => {\r\n const result = replaceIncomingProxiedTypes(event.data, context)\r\n if (!(result instanceof Promise)) throw new Error(`Proxied function did not return a promise`)\r\n\r\n result\r\n .then(resolve)\r\n .catch(reject)\r\n .finally(() => returnValueLocalPort.close())\r\n }\r\n returnValueLocalPort.addEventListener('message', listener, { once: true })\r\n returnValueLocalPort.start()\r\n port.postMessage(functionContext, { transfer: functionContextTransferables })\r\n })\r\n\r\n if (portId) {\r\n context.finalizationRegistry.register(func, Number(portId.split('/')[1]))\r\n }\r\n\r\n return func\r\n}\r\n\r\nexport const proxiedMessagePortToMessagePort = <JsonOnly extends boolean>(proxiedMessagePort: ProxiedMessagePortType<JsonOnly>, context: Context) => {\r\n const port =\r\n context.envCheck.supportsPorts && 'port' in proxiedMessagePort ? proxiedMessagePort.port\r\n : 'portId' in proxiedMessagePort ? context.addIncomingProxiedMessagePort(proxiedMessagePort.portId)\r\n : undefined\r\n if (!port) throw new Error(`No ports received for proxied message port`)\r\n return port\r\n}\r\n\r\nexport const proxiedErrorToError = (proxiedError: ProxiedErrorType, context: Context) =>\r\n new Error(proxiedError.message, { cause: proxiedError.stack })\r\n\r\nexport const proxiedPromiseToPromise = <JsonOnly extends boolean>(proxiedPromise: ProxiedPromiseType<JsonOnly>, context: Context) =>\r\n new Promise((resolve, reject) => {\r\n const port =\r\n 'port' in proxiedPromise ? proxiedPromise.port\r\n : 'portId' in proxiedPromise ? context.addIncomingProxiedMessagePort(proxiedPromise.portId)\r\n : undefined\r\n if (!port) throw new Error(`No ports received for proxied promise`)\r\n const listener = async (event: MessageEvent) => {\r\n const result = await replaceIncomingProxiedTypes(event.data, context)\r\n if (result instanceof Error) reject(result)\r\n else resolve(result)\r\n port.close()\r\n }\r\n port.addEventListener('message', listener, { once: true })\r\n port.start()\r\n })\r\n\r\nexport const replaceIncomingProxiedTypes = (value: StructuredCloneTransferableType, context: Context): StructuredCloneTransferableProxiableType =>\r\n replaceRecursive(\r\n value,\r\n (value) => Boolean(\r\n value && typeof value === 'object' && OSRA_PROXY in value && value[OSRA_PROXY]\r\n ),\r\n (proxiedValue: ProxiedType<boolean>) => {\r\n if (proxiedValue.type === 'function') {\r\n return proxiedFunctionToFunction(proxiedValue, context)\r\n } else if (proxiedValue.type === 'error') {\r\n return proxiedErrorToError(proxiedValue, context)\r\n } else if (proxiedValue.type === 'messagePort') {\r\n return proxiedMessagePortToMessagePort(proxiedValue, context)\r\n } else if (proxiedValue.type === 'promise') {\r\n return proxiedPromiseToPromise(proxiedValue, context)\r\n }\r\n throw new Error(`Unknown incoming proxied type: ${value}`)\r\n })\r\n\r\nexport const errorToProxiedError = (error: Error, _: Context) => ({\r\n [OSRA_PROXY]: true,\r\n type: 'error',\r\n message: error.message,\r\n stack: error.stack\r\n})\r\n\r\nexport const messagePortToProxiedMessagePort = (port: MessagePort, context: Context) => ({\r\n [OSRA_PROXY]: true,\r\n type: 'messagePort',\r\n ...context.envCheck.supportsPorts\r\n ? { port }\r\n : { portId: context.addOutgoingProxiedMessagePort(port) }\r\n})\r\n\r\nexport const promiseToProxiedPromise = (promise: Promise<StructuredCloneTransferableType>, context: Context) => {\r\n const { port1: localPort, port2: remotePort } = new MessageChannel()\r\n\r\n const sendResult = (resultOrError: StructuredCloneTransferableType) => {\r\n const proxiedResult = replaceOutgoingProxiedTypes(resultOrError, context)\r\n const transferables = getTransferableObjects(proxiedResult)\r\n localPort.postMessage(proxiedResult, { transfer: transferables })\r\n localPort.close()\r\n }\r\n\r\n promise\r\n .then(sendResult)\r\n .catch(sendResult)\r\n\r\n return {\r\n [OSRA_PROXY]: true,\r\n type: 'promise',\r\n port: replaceOutgoingProxiedTypes(remotePort, context)\r\n }\r\n}\r\n\r\nexport const functionToProxiedFunction = (func: Function, context: Context) => {\r\n const { port1: localPort, port2: remotePort } = new MessageChannel()\r\n localPort.addEventListener('message', async (ev: MessageEvent<[ProxiedType<boolean>, StructuredCloneTransferableType[]]>) => {\r\n const [returnValuePort, args] = replaceIncomingProxiedTypes(ev.data, context) as [MessagePort, StructuredCloneTransferableType[]]\r\n const result = (async () => func(...args))()\r\n const proxiedResult = replaceOutgoingProxiedTypes(result, context)\r\n const transferables = getTransferableObjects(proxiedResult)\r\n returnValuePort.postMessage(proxiedResult, { transfer: transferables })\r\n returnValuePort.close()\r\n })\r\n localPort.start()\r\n return {\r\n [OSRA_PROXY]: true,\r\n type: 'function',\r\n port: replaceOutgoingProxiedTypes(remotePort, context)\r\n }\r\n}\r\n\r\nexport const replaceOutgoingProxiedTypes = <T extends StructuredCloneTransferableProxiableType>(value: T, context: Context) =>\r\n replaceRecursive(\r\n value,\r\n (value) => typeof value === 'function' || value instanceof Error || value instanceof MessagePort || value instanceof Promise,\r\n (value) => {\r\n if (typeof value === 'function') {\r\n return functionToProxiedFunction(value, context)\r\n } else if (value instanceof Error) {\r\n return errorToProxiedError(value, context)\r\n } else if (value instanceof MessagePort) {\r\n return messagePortToProxiedMessagePort(value, context)\r\n } else if (value instanceof Promise) {\r\n return promiseToProxiedPromise(value, context)\r\n }\r\n throw new Error(`Unknown outgoing proxied type: ${value}`)\r\n }\r\n )\r\n\r\nexport const replaceRecursive = <\r\n T extends StructuredCloneTransferableProxiableType,\r\n T2 extends (value: any) => any\r\n>(\r\n value: T,\r\n shouldReplace: (value: Parameters<T2>[0]) => boolean,\r\n replaceFunction: T2\r\n) =>\r\n isClonable(value) ? value\r\n : isTransferable(value) ? value\r\n : shouldReplace(value) ? replaceFunction(value)\r\n : Array.isArray(value) ? value.map(value => replaceRecursive(value, shouldReplace, replaceFunction))\r\n : value && typeof value === 'object' ? (\r\n Object.fromEntries(\r\n Object\r\n .entries(value)\r\n .map(([key, value]) => [\r\n key,\r\n replaceRecursive(value, shouldReplace, replaceFunction)\r\n ])\r\n )\r\n )\r\n : value\r\n\r\nexport const makeNumberAllocator = () => {\r\n let highest = 0\r\n const freedUnused = new Set<number>()\r\n return {\r\n alloc: () => {\r\n if (freedUnused.size > 0) {\r\n const number = freedUnused.values().next().value\r\n if (number === undefined) {\r\n throw new Error(`Tried to allocate number from freedUnused but result was undefined`)\r\n }\r\n freedUnused.delete(number)\r\n return number\r\n }\r\n highest++\r\n return highest\r\n },\r\n free: (number) => {\r\n freedUnused.add(number)\r\n }\r\n }\r\n}\r\n\r\ntype NumberAllocator = ReturnType<typeof makeNumberAllocator>\r\n\r\nexport const makeAllocator = <T>({ numberAllocator }: { numberAllocator: NumberAllocator }) => {\r\n const channels = new Map<number, T>()\r\n\r\n const alloc = (value: T) => {\r\n const id = numberAllocator.alloc()\r\n channels.set(id, value)\r\n return id\r\n }\r\n const get = (id: number) => channels.get(id)\r\n const free = (id: number) => {\r\n channels.delete(id)\r\n numberAllocator.free(id)\r\n }\r\n\r\n return {\r\n alloc,\r\n get,\r\n free\r\n }\r\n}\r\ntype Allocator<T> = ReturnType<typeof makeAllocator<T>>\r\n","import type { RemoteTarget, StructuredCloneTransferableType, LocalTarget, OsraMessage, StructuredCloneTransferableProxiableType } from './types'\r\nimport type { Context, EnvCheck } from './utils'\r\n\r\nimport { v4 as uuidv4 } from 'uuid'\r\n\r\nimport { OSRA_MESSAGE_KEY, OSRA_MESSAGE_PROPERTY } from './types'\r\nimport { getTransferableObjects, makeAllocator, makeNumberAllocator, replaceIncomingProxiedTypes, replaceOutgoingProxiedTypes } from './utils'\r\n\r\nexport * from './utils'\r\n\r\nexport const expose = async <T extends StructuredCloneTransferableProxiableType>(\r\n value: StructuredCloneTransferableProxiableType,\r\n {\r\n remote: _remote,\r\n local: _local,\r\n key = OSRA_MESSAGE_KEY,\r\n origin = '*'\r\n }: {\r\n remote: RemoteTarget | ((osraMessage: OsraMessage, transferables: Transferable[]) => void)\r\n local: LocalTarget | ((listener: (event: MessageEvent<OsraMessage>) => void) => void)\r\n key?: string,\r\n origin?: string\r\n }\r\n): Promise<T> => {\r\n const uuid = uuidv4()\r\n\r\n let envCheck: EnvCheck | undefined\r\n const finalizationRegistry = new FinalizationRegistry<number>((value) => {\r\n const allocCallback = allocator.get(value)\r\n if (!allocCallback) throw new Error(`Osra received a port-closed message with an invalid portId \"${value}\".`)\r\n allocCallback()\r\n allocator.free(value)\r\n })\r\n const idAllocator = makeNumberAllocator()\r\n const allocator = makeAllocator<() => void>({ numberAllocator: idAllocator })\r\n const incomingSerializedPorts = new Map<string, MessagePort>()\r\n\r\n const addIncomingProxiedMessagePort = (portId: string) => {\r\n const { port1, port2 } = new MessageChannel()\r\n incomingSerializedPorts.set(portId, port1)\r\n return port2\r\n }\r\n\r\n const addOutgoingProxiedMessagePort = (port: MessagePort) => {\r\n const id = allocator.alloc(() => {\r\n port.close()\r\n })\r\n port.addEventListener('message', async (ev) => {\r\n remote(\r\n {\r\n [OSRA_MESSAGE_PROPERTY]: true,\r\n key,\r\n type: 'message',\r\n portId: `${uuid}/${id}`,\r\n data: replaceOutgoingProxiedTypes(ev.data, getContext())\r\n },\r\n []\r\n )\r\n })\r\n\r\n port.addEventListener('close', () => {\r\n idAllocator.free(id)\r\n remote(\r\n {\r\n [OSRA_MESSAGE_PROPERTY]: true,\r\n key,\r\n type: 'port-closed',\r\n portId: `${uuid}/${id}`\r\n },\r\n []\r\n )\r\n })\r\n return `${uuid}/${id}`\r\n }\r\n\r\n const getContext = (): Context => {\r\n if (!envCheck) throw new Error(`Osra context was accessed before the ready message was received.`)\r\n return {\r\n addIncomingProxiedMessagePort,\r\n addOutgoingProxiedMessagePort,\r\n envCheck,\r\n finalizationRegistry\r\n }\r\n }\r\n\r\n let resolveRemoteValues, rejectRemoteValues\r\n const remoteValues = new Promise<T2>((res, rej) => {\r\n resolveRemoteValues = res\r\n rejectRemoteValues = rej\r\n })\r\n\r\n const sendReady = () => {\r\n const buffer = new ArrayBuffer(1)\r\n const { port1 } = new MessageChannel()\r\n remote(\r\n {\r\n [OSRA_MESSAGE_PROPERTY]: true,\r\n key,\r\n type: 'ready',\r\n envCheck: { buffer: buffer, port: port1 }\r\n },\r\n [buffer, port1]\r\n )\r\n }\r\n\r\n let receivedReady = false\r\n const listener = async (event: MessageEvent<OsraMessage>) => {\r\n if (!event.data || typeof event.data !== 'object' || !event.data[OSRA_MESSAGE_PROPERTY] || event.data.key !== key) return\r\n const { type } = event.data\r\n\r\n if (type === 'ready' && !receivedReady) {\r\n receivedReady = true\r\n envCheck = {\r\n uuid,\r\n supportsPorts: event.data.envCheck.port instanceof MessagePort,\r\n jsonOnly: event.data.envCheck.buffer instanceof ArrayBuffer\r\n }\r\n sendReady()\r\n\r\n const proxiedValue = replaceOutgoingProxiedTypes(value, getContext())\r\n const transferables = getTransferableObjects(proxiedValue)\r\n remote(\r\n {\r\n [OSRA_MESSAGE_PROPERTY]: true,\r\n key,\r\n type: 'init',\r\n data: proxiedValue\r\n },\r\n transferables\r\n )\r\n return\r\n }\r\n\r\n if (!receivedReady || !envCheck) throw new Error(`Osra received a message before the ready message.`)\r\n\r\n if (type === 'init') {\r\n resolveRemoteValues(\r\n replaceIncomingProxiedTypes(\r\n event.data.data,\r\n getContext()\r\n )\r\n )\r\n return\r\n }\r\n\r\n if (type === 'message') {\r\n const { portId, data } = event.data\r\n const port = incomingSerializedPorts.get(portId)\r\n if (!port) throw new Error(`Osra received a message with portId set to \"${portId}\" but no port was found.`)\r\n port.postMessage(data)\r\n } else if (type === 'port-closed') {\r\n const { portId } = event.data\r\n const [messageUuid, _portNumberId] = portId.split('/')\r\n const messagePortId = Number(_portNumberId)\r\n if (!messagePortId) throw new Error(`Osra received a port-closed message with an invalid portId \"${portId}\".`)\r\n if (messageUuid !== uuid && messageUuid !== envCheck.uuid) throw new Error(`Osra received a port-closed message with an invalid portId's uuid \"${portId}\".`)\r\n\r\n if (messageUuid === uuid) {\r\n const unregisterCallback = allocator.get(messagePortId)\r\n if (!unregisterCallback) throw new Error(`Osra received a port-closed message with an invalid portId \"${portId}\".`)\r\n unregisterCallback()\r\n } else if (messageUuid === envCheck.uuid) {\r\n const port = incomingSerializedPorts.get(portId)\r\n if (!port) throw new Error(`Osra received a message with portId set to \"${portId}\" but no port was found.`)\r\n port.close()\r\n incomingSerializedPorts.delete(portId)\r\n }\r\n }\r\n }\r\n\r\n const remote =\r\n typeof _remote === 'function' ? _remote\r\n : (\r\n (osraMessage: OsraMessage, transferables: Transferable[] = []) =>\r\n _remote.postMessage(osraMessage, { targetOrigin: origin, transfer: transferables })\r\n )\r\n\r\n if (typeof _local === 'function') {\r\n _local(listener)\r\n } else {\r\n _local.addEventListener('message', listener as EventListener)\r\n }\r\n\r\n sendReady()\r\n\r\n return remoteValues\r\n}\r\n"],"names":["byteToHex","i","unsafeStringify","arr","offset","getRandomValues","rnds8","rng","randomUUID","native","v4","options","buf","rnds","OSRA_MESSAGE_PROPERTY","OSRA_MESSAGE_KEY","OSRA_PROXY","isClonable","value","isTransferable","getTransferableObjects","transferables","recurse","proxiedFunctionToFunction","proxiedFunction","context","portId","port","func","args","resolve","reject","returnValueLocalPort","returnValueRemotePort","functionContext","replaceOutgoingProxiedTypes","functionContextTransferables","listener","event","result","replaceIncomingProxiedTypes","proxiedMessagePortToMessagePort","proxiedMessagePort","proxiedErrorToError","proxiedError","proxiedPromiseToPromise","proxiedPromise","replaceRecursive","proxiedValue","errorToProxiedError","error","_","messagePortToProxiedMessagePort","promiseToProxiedPromise","promise","localPort","remotePort","sendResult","resultOrError","proxiedResult","functionToProxiedFunction","ev","returnValuePort","shouldReplace","replaceFunction","key","makeNumberAllocator","highest","freedUnused","number","makeAllocator","numberAllocator","channels","id","expose","_remote","_local","origin","uuid","uuidv4","envCheck","finalizationRegistry","allocCallback","allocator","idAllocator","incomingSerializedPorts","addIncomingProxiedMessagePort","port1","port2","addOutgoingProxiedMessagePort","remote","getContext","resolveRemoteValues","remoteValues","res","rej","sendReady","buffer","receivedReady","type","data","messageUuid","_portNumberId","messagePortId","unregisterCallback","osraMessage"],"mappings":"AACA,MAAMA,IAAY,CAAE;AACpB,SAAS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C/C,YAAI,CAACC,EAAM,OAAM,IAAI,MAAM,+CAA+CD,CAAM,0BAA0B;AAC1G,QAAAC,EAAK,MAAM,GACX0D,EAAwB,OAAO3D,CAAM;AAAA,MAAA;AAAA,IACvC;AAAA,EAEJ,GAEMgE,IACJ,OAAOf,KAAY,aAAaA,IAE9B,CAAC8B,GAA0BpF,IAAgC,CAAA,MACzDsD,EAAQ,YAAY8B,GAAa,EAAE,cAAc5B,GAAQ,UAAUxD,GAAe;AAGpF,SAAA,OAAOuD,KAAW,aACpBA,EAAOvC,CAAQ,IAERuC,EAAA,iBAAiB,WAAWvC,CAAyB,GAGpD2D,EAAA,GAEHH;AACT;","x_google_ignoreList":[0,1,2,3]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osra",
3
- "version": "0.0.11",
3
+ "version": "0.1.0",
4
4
  "description": "Easy communication between workers",
5
5
  "files": [
6
6
  "build"
@@ -8,16 +8,15 @@
8
8
  "main": "build/index.js",
9
9
  "type": "module",
10
10
  "scripts": {
11
- "type-check": "tsc",
12
- "type-check-watch": "tsc --watch",
13
- "build": "vite build && npm run type-check",
14
- "build-watch": "esbuild --watch ./src/index.ts --format=esm --bundle --outfile=build/index.js",
15
- "dev": "concurrently \"npm run build-watch\" \"npm run type-check-watch\"",
16
- "copy-tests-html": "copyfiles -u 1 ./tests/*/index.html tests/build",
17
- "build-tests": "npm run copy-tests-html && esbuild ./tests/call/iframe.ts ./tests/event-channel/iframe.ts --format=esm --bundle --outdir=tests/build",
18
- "build-tests-watch": "npm run copy-tests-html && esbuild --watch ./tests/call/iframe.ts ./tests/event-channel/iframe.ts --format=esm --bundle --outdir=tests/build",
19
- "test": "epk",
20
- "test-watch": "epk -w"
11
+ "build": "vite build",
12
+ "build-watch": "vite build --watch",
13
+ "build-test": "vite build --config vite.test.config.ts",
14
+ "build-test-watch": "vite build --config vite.test.config.ts --watch",
15
+ "dev": "concurrently \"npm run build-watch\" \"npm run build-test-watch\" \"npm run test-watch\"",
16
+ "dev2": "concurrently \"npm run build-watch\" \"npm run build-test-watch\" \"npm run test-watch-headful\"",
17
+ "test": "npx playwright test",
18
+ "test-watch": "set PWTEST_WATCH=1 & npx playwright test",
19
+ "test-watch-headful": "npx playwright test --ui"
21
20
  },
22
21
  "repository": {
23
22
  "type": "git",
@@ -30,18 +29,19 @@
30
29
  },
31
30
  "homepage": "https://github.com/Banou26/osra#readme",
32
31
  "devDependencies": {
33
- "@types/chai-as-promised": "^7.1.5",
34
- "@types/chrome": "^0.0.237",
35
- "@types/node": "^18.11.18",
36
- "@types/webextension-polyfill": "^0.10.0",
37
- "chai": "^4.3.6",
38
- "chai-as-promised": "^7.1.1",
39
- "concurrently": "^7.0.0",
40
- "copyfiles": "^2.4.1",
41
- "epk": "^0.16.0",
42
- "mime": "^3.0.0",
43
- "typescript": "^4.9.4",
44
- "vite": "^4.0.4",
45
- "webextension-polyfill": "^0.10.0"
32
+ "@playwright/test": "^1.49.1",
33
+ "@types/chai": "^5.0.1",
34
+ "@types/chai-as-promised": "^8.0.1",
35
+ "chai": "^5.1.2",
36
+ "chai-as-promised": "^8.0.1",
37
+ "concurrently": "^9.1.0",
38
+ "i": "^0.3.7",
39
+ "npm": "^11.0.0",
40
+ "playwright": "^1.49.1",
41
+ "typescript": "^5.7.2",
42
+ "vite": "^6.0.4"
43
+ },
44
+ "dependencies": {
45
+ "uuid": "^11.0.3"
46
46
  }
47
47
  }
package/build/call.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { Target, Resolvers, ApiResolverOptions } from './types';
2
- /**
3
- * Call a function with the provided arguments and get its return value back
4
- */
5
- export declare const call: <T2 extends Resolvers>(target: Target, { key }?: {
6
- key?: string | undefined;
7
- }) => <T3 extends keyof T2>(type: T3, data?: Parameters<T2[T3]>[0] | undefined) => Promise<Awaited<ReturnType<T2[T3]>>>;
8
- /**
9
- * Make a listener for a call
10
- */
11
- export declare const makeCallListener: <T extends (data: any, extra: ApiResolverOptions) => unknown>(func: T) => T;
@@ -1,7 +0,0 @@
1
- declare const _default: () => {
2
- dispatchAll: <T = any>(type: string, value?: any) => Promise<T[]>;
3
- dispatch: <T_1 = any>(type: string, value?: any) => Promise<T_1>;
4
- addEventListener: (type: string, listener: Function) => Map<string, Function[]>;
5
- removeEventListener: (type: string, listener: Function) => Map<string, Function[]>;
6
- };
7
- export default _default;
package/build/events.d.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Call a package function and get its return value back
3
- */
4
- export declare const makeEventChannelListener: <T = any, U = any>(func: (data: any) => U | [U, any]) => ({ port, data }: {
5
- port: MessagePort;
6
- data: T;
7
- }) => Promise<void>;
8
- /**
9
- * Call a host API function
10
- */
11
- export declare const makeEventChannel: (port: MessagePort) => {
12
- send: (type: string, data?: any, transfer?: Transferable[]) => void;
13
- events: {
14
- dispatchAll: <T = any>(type: string, value?: any) => Promise<T[]>;
15
- dispatch: <T_1 = any>(type: string, value?: any) => Promise<T_1>;
16
- addEventListener: (type: string, listener: Function) => Map<string, Function[]>;
17
- removeEventListener: (type: string, listener: Function) => Map<string, Function[]>;
18
- };
19
- };
package/build/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { ApiMessageData, ApiResolverOptions, Resolvers, StructuredCloneTransferableObject, StructuredCloneTransferableType, StructuredCloneObject, StructuredCloneType, Target, TransferableObject } from './types';
2
- export type { ApiMessageData, ApiResolverOptions, Resolvers, StructuredCloneTransferableObject, StructuredCloneTransferableType, StructuredCloneObject, StructuredCloneType, Target, TransferableObject };
3
- export * from './register';
4
- export * from './call';
5
- export * from './webextension';
@@ -1,19 +0,0 @@
1
- import type { ApiMessageData, ApiResolverOptions, Resolvers, ValidateResolvers } from './types';
2
- export declare const registerListener: <T extends Record<PropertyKey, (data: any, extra: ApiResolverOptions) => unknown>>({ target, resolvers, filter, map, key }: {
3
- target: WindowEventHandlers | ServiceWorkerContainer | Worker | SharedWorker;
4
- resolvers: ValidateResolvers<T>;
5
- filter?: ((event: MessageEvent<any>) => boolean) | undefined;
6
- map?: ((data: any, extra: {
7
- event: MessageEvent<any>;
8
- type: PropertyKey;
9
- port: MessagePort;
10
- }) => [data: any, extra: {
11
- event: MessageEvent<any>;
12
- type: PropertyKey;
13
- port: MessagePort;
14
- }]) | undefined;
15
- key?: string | undefined;
16
- }) => {
17
- listener: (event: MessageEvent<ApiMessageData<Resolvers>>) => void;
18
- resolvers: ValidateResolvers<T>;
19
- };
package/build/shared.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const MESSAGE_SOURCE_KEY = "osra-message";
package/build/types.d.ts DELETED
@@ -1,39 +0,0 @@
1
- export type TransferableObject = SharedArrayBuffer | ArrayBuffer | MessagePort | ReadableStream | WritableStream | TransformStream | /* AudioData | */ ImageBitmap;
2
- export type StructuredCloneObject = {
3
- [key: string]: StructuredCloneType;
4
- };
5
- export type StructuredCloneType = void | boolean | null | undefined | number | BigInt | string | Date | RegExp | Blob | File | FileList | ArrayBuffer | ArrayBufferView | ImageBitmap | ImageData | Array<StructuredCloneType> | StructuredCloneObject | Map<StructuredCloneType, StructuredCloneType> | Set<StructuredCloneType>;
6
- export type StructuredCloneTransferableObject = {
7
- [key: string]: StructuredCloneTransferableType;
8
- };
9
- export type ProxiedType = (...args: StructuredCloneTransferableType[]) => StructuredCloneTransferableType | Promise<StructuredCloneTransferableType>;
10
- export type StructuredCloneTransferableType = StructuredCloneType | TransferableObject | Array<StructuredCloneTransferableType> | StructuredCloneTransferableObject | Map<StructuredCloneTransferableType, StructuredCloneTransferableType> | Set<StructuredCloneTransferableType> | ProxiedType;
11
- export type Target = Window | ServiceWorker | Worker;
12
- type NormalizeRecord<T> = T extends Record<any, any> ? {
13
- [K in keyof T]: NormalizeRecord<T[K]>;
14
- } : T;
15
- /**
16
- * Solution by mkantor#7432
17
- * https://www.typescriptlang.org/play#code/C4TwDgpgBACghgJzgWwsCCDOBBBEBCcA5pgPIBmAysAgJYB2J29AJgHICuyARhpgDwAVKBAAe6VpigAKFnGBwAXFHoQAbhgCUUALwA+KB3oBregHsA7vQM6AUFBmz5SqACUIAYzMIW-GAjNIBFAAaQgQABooTBoGIigAHxUuXgQ9bX0VdS0RcQhJKGEAfkKoZVUNBFtbUEgoADU4ABtaOXR3TDMmyoFhMQkWKXcvHz8AoNDwqKcFcuyEDIMjU0trG3tS-vzBqABvKABtEKgGKGNws3JCgF1leCRUdCxcAmIyKljGHFZOHj4hI7XAwAXygJUEGzmlWqXnoMSgeHiOigQlyAyGnm8vn8gQwk0iMjaLgqOUyy3MVj0emkeE63T4ykaLTaEA6XR6QnSymEmV2GzwwA4CHohlYEHIDAgLCgcCk5NWMqkEOBMLMcOACIgUmRiOkfIc5DMZmUspA9A8hOcyn2huN0U+8WBiz2wIiG24iBNmDNFr1UFtUGB1v9RvKKQwgedu1d7rgAC8vT6ZPsPQhA8HU2G-mmnboDNHbE6gA
18
- * https://discord.gg/typescript
19
- * https://discord.com/channels/508357248330760243/1041386152315342999
20
- * +
21
- * saghen#6423 from friend discord https://discord.com/channels/790293936589504523/819301407215190026/1067635967801962587
22
- */
23
- export type RestrictedParametersType<T extends (data: any, extra: ApiResolverOptions) => unknown> = NormalizeRecord<Parameters<T>[0]> extends Record<PropertyKey, StructuredCloneTransferableType> ? T : never;
24
- export type ValidateResolvers<T extends Record<PropertyKey, (data: any, extra: ApiResolverOptions) => unknown>> = T extends {
25
- [K in keyof T]: RestrictedParametersType<T[K]>;
26
- } ? T : never;
27
- export type Resolvers = Record<PropertyKey, (data: any, extra: ApiResolverOptions) => unknown>;
28
- export type ApiResolverOptions<T2 extends Resolvers = Resolvers, T3 = {}> = T3 & {
29
- event: MessageEvent<any>;
30
- type: keyof T2;
31
- port: MessagePort;
32
- };
33
- export type ApiMessageData<T2 extends Resolvers = Resolvers> = {
34
- type: keyof T2;
35
- data: any;
36
- port: MessagePort;
37
- source: string;
38
- };
39
- export {};
package/build/utils.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { TransferableObject } from './types';
2
- export declare const isClonable: (value: any) => boolean;
3
- export declare const isTransferable: (value: any) => boolean;
4
- export declare const getTransferableObjects: (value: any) => TransferableObject[];
5
- export declare const PROXY_FUNCTION_PROPERTY = "__proxyFunctionPort__";
6
- export declare const PROXY_MESSAGE_CHANNEL_PROPERTY = "__proxyMessageChannelPort__";
7
- export declare const makeProxyFunction: (func: any) => MessagePort;
8
- export declare const proxyObjectFunctions: (value: any) => any;
9
- export declare const makeProxiedFunction: (port: MessagePort) => (...args: any[]) => Promise<unknown>;
10
- export declare const makeObjectProxiedFunctions: (value: any) => any;
@@ -1,137 +0,0 @@
1
- import type browser from 'webextension-polyfill';
2
- import { PROXY_MESSAGE_CHANNEL_PROPERTY } from './utils';
3
- type PortManager = ReturnType<typeof makePortManager>;
4
- declare const makePortManager: ({ key }: {
5
- key?: string | undefined;
6
- }) => {
7
- addPort: (name: string, port: browser.Runtime.Port) => Map<string, browser.Runtime.Port>;
8
- proxyPort: (messagePort: MessagePort) => {
9
- __proxyMessageChannelPort__: string;
10
- };
11
- proxiedPort: ({ [PROXY_MESSAGE_CHANNEL_PROPERTY]: uuid }: {
12
- [PROXY_MESSAGE_CHANNEL_PROPERTY]: string;
13
- }) => Promise<MessagePort>;
14
- };
15
- export declare const replaceProxies: (portManager: PortManager, value: any) => any;
16
- export declare const replaceProxied: (portManager: PortManager, value: any) => any;
17
- export declare const wrapPort: (portManager: any, port: MessagePort) => MessagePort;
18
- export declare const wrapExtensionTarget: ({ target, key }: {
19
- target: browser.Browser;
20
- key?: string | undefined;
21
- }) => {
22
- postMessage: (message: any) => void;
23
- activityLog: browser.ActivityLog.Static;
24
- alarms: browser.Alarms.Static;
25
- bookmarks: browser.Bookmarks.Static;
26
- action: browser.Action.Static;
27
- browserAction: browser.BrowserAction.Static;
28
- browserSettings: browser.BrowserSettings.Static;
29
- browsingData: browser.BrowsingData.Static;
30
- captivePortal: browser.CaptivePortal.Static;
31
- clipboard: browser.Clipboard.Static;
32
- commands: browser.Commands.Static;
33
- contentScripts: browser.ContentScripts.Static;
34
- contextualIdentities: browser.ContextualIdentities.Static;
35
- cookies: browser.Cookies.Static;
36
- declarativeNetRequest: browser.DeclarativeNetRequest.Static;
37
- devtools: browser.Devtools.Static;
38
- dns: browser.Dns.Static;
39
- downloads: browser.Downloads.Static;
40
- events: browser.Events.Static;
41
- experiments: browser.Experiments.Static;
42
- extension: browser.Extension.Static;
43
- extensionTypes: browser.ExtensionTypes.Static;
44
- find: browser.Find.Static;
45
- geckoProfiler: browser.GeckoProfiler.Static;
46
- history: browser.History.Static;
47
- i18n: browser.I18n.Static;
48
- identity: browser.Identity.Static;
49
- idle: browser.Idle.Static;
50
- management: browser.Management.Static;
51
- manifest: browser.Manifest.Static;
52
- contextMenus: browser.ContextMenus.Static;
53
- menus: browser.Menus.Static;
54
- networkStatus: browser.NetworkStatus.Static;
55
- normandyAddonStudy: browser.NormandyAddonStudy.Static;
56
- notifications: browser.Notifications.Static;
57
- omnibox: browser.Omnibox.Static;
58
- pageAction: browser.PageAction.Static;
59
- permissions: browser.Permissions.Static;
60
- pkcs11: browser.Pkcs11.Static;
61
- privacy: browser.Privacy.Static;
62
- proxy: browser.Proxy.Static;
63
- runtime: browser.Runtime.Static;
64
- scripting: browser.Scripting.Static;
65
- search: browser.Search.Static;
66
- sessions: browser.Sessions.Static;
67
- sidebarAction: browser.SidebarAction.Static;
68
- storage: browser.Storage.Static;
69
- tabs: browser.Tabs.Static;
70
- theme: browser.Theme.Static;
71
- topSites: browser.TopSites.Static;
72
- types: browser.Types.Static;
73
- urlbar: browser.Urlbar.Static;
74
- userScripts: browser.UserScripts.Static;
75
- webNavigation: browser.WebNavigation.Static;
76
- webRequest: browser.WebRequest.Static;
77
- windows: browser.Windows.Static;
78
- };
79
- export declare const wrapListenerExtensionTarget: ({ target, key }: {
80
- target: WindowEventHandlers | ServiceWorkerContainer | Worker | SharedWorker;
81
- key?: string | undefined;
82
- }) => {
83
- addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
84
- onafterprint: ((this: WindowEventHandlers, ev: Event) => any) | null;
85
- onbeforeprint: ((this: WindowEventHandlers, ev: Event) => any) | null;
86
- onbeforeunload: ((this: WindowEventHandlers, ev: BeforeUnloadEvent) => any) | null;
87
- ongamepadconnected: ((this: WindowEventHandlers, ev: GamepadEvent) => any) | null;
88
- ongamepaddisconnected: ((this: WindowEventHandlers, ev: GamepadEvent) => any) | null;
89
- onhashchange: ((this: WindowEventHandlers, ev: HashChangeEvent) => any) | null;
90
- onlanguagechange: ((this: WindowEventHandlers, ev: Event) => any) | null;
91
- onmessage: ((this: WindowEventHandlers, ev: MessageEvent<any>) => any) | null;
92
- onmessageerror: ((this: WindowEventHandlers, ev: MessageEvent<any>) => any) | null;
93
- onoffline: ((this: WindowEventHandlers, ev: Event) => any) | null;
94
- ononline: ((this: WindowEventHandlers, ev: Event) => any) | null;
95
- onpagehide: ((this: WindowEventHandlers, ev: PageTransitionEvent) => any) | null;
96
- onpageshow: ((this: WindowEventHandlers, ev: PageTransitionEvent) => any) | null;
97
- onpopstate: ((this: WindowEventHandlers, ev: PopStateEvent) => any) | null;
98
- onrejectionhandled: ((this: WindowEventHandlers, ev: PromiseRejectionEvent) => any) | null;
99
- onstorage: ((this: WindowEventHandlers, ev: StorageEvent) => any) | null;
100
- onunhandledrejection: ((this: WindowEventHandlers, ev: PromiseRejectionEvent) => any) | null;
101
- onunload: ((this: WindowEventHandlers, ev: Event) => any) | null;
102
- removeEventListener<K extends keyof WindowEventHandlersEventMap>(type: K, listener: (this: WindowEventHandlers, ev: WindowEventHandlersEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void;
103
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
104
- } | {
105
- addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
106
- controller: ServiceWorker | null;
107
- oncontrollerchange: ((this: ServiceWorkerContainer, ev: Event) => any) | null;
108
- onmessage: ((this: ServiceWorkerContainer, ev: MessageEvent<any>) => any) | null;
109
- onmessageerror: ((this: ServiceWorkerContainer, ev: MessageEvent<any>) => any) | null;
110
- ready: Promise<ServiceWorkerRegistration>;
111
- getRegistration(clientURL?: string | URL | undefined): Promise<ServiceWorkerRegistration | undefined>;
112
- getRegistrations(): Promise<readonly ServiceWorkerRegistration[]>;
113
- register(scriptURL: string | URL, options?: RegistrationOptions | undefined): Promise<ServiceWorkerRegistration>;
114
- startMessages(): void;
115
- removeEventListener<K_1 extends keyof ServiceWorkerContainerEventMap>(type: K_1, listener: (this: ServiceWorkerContainer, ev: ServiceWorkerContainerEventMap[K_1]) => any, options?: boolean | EventListenerOptions | undefined): void;
116
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
117
- dispatchEvent(event: Event): boolean;
118
- } | {
119
- addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
120
- port: MessagePort;
121
- removeEventListener<K_2 extends "error">(type: K_2, listener: (this: SharedWorker, ev: AbstractWorkerEventMap[K_2]) => any, options?: boolean | EventListenerOptions | undefined): void;
122
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
123
- dispatchEvent(event: Event): boolean;
124
- onerror: ((this: AbstractWorker, ev: ErrorEvent) => any) | null;
125
- } | {
126
- addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
127
- onmessage: ((this: Worker, ev: MessageEvent<any>) => any) | null;
128
- onmessageerror: ((this: Worker, ev: MessageEvent<any>) => any) | null;
129
- postMessage(message: any, transfer: Transferable[]): void;
130
- postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;
131
- terminate(): void;
132
- removeEventListener<K_3 extends keyof WorkerEventMap>(type: K_3, listener: (this: Worker, ev: WorkerEventMap[K_3]) => any, options?: boolean | EventListenerOptions | undefined): void;
133
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
134
- dispatchEvent(event: Event): boolean;
135
- onerror: ((this: AbstractWorker, ev: ErrorEvent) => any) | null;
136
- };
137
- export {};