osra 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # osra
2
+ what that? https://github.com/GoogleChromeLabs/comlink but nicer to use.
3
+ thats about it
4
+
5
+ how to?
6
+ register your functions in the other context like so
7
+ ```ts
8
+ import { makeCallListener, registerListener } from 'osra'
9
+
10
+ const resolvers = {
11
+ 'test': makeCallListener(async (myData) => {
12
+ // do work...
13
+ return {
14
+ foo: 1,
15
+ bar: 'bar',
16
+ baz: () => true
17
+ }
18
+ })
19
+ }
20
+
21
+ registerListener({ target: globalThis, resolvers })
22
+ ```
23
+
24
+ and on your current context you can call it easily like
25
+ ```ts
26
+ import { call } from 'osra'
27
+
28
+ const worker = new Worker('/worker.js', { type: 'module' })
29
+
30
+ call(worker)('test', { theDataThatWillBeSentToTheOtherContext: 1 })
31
+ .then(({ foo, bar, baz }) => {
32
+ // foo === 1
33
+ // bar === 'bar'
34
+ // baz === callable function that will return a promise with its response
35
+ })
36
+ ```
37
+
38
+ all types of data supported by osra that will be correctly proxied/sent to the other context in addition of functions:
39
+
40
+ ```ts
41
+ export type TransferableObject =
42
+ ArrayBuffer | MessagePort | ReadableStream | WritableStream |
43
+ TransformStream | /* AudioData | */ ImageBitmap /* | VideoFrame | OffscreenCanvas */
44
+
45
+ export interface StructuredCloneObject {
46
+ [key: string | number | symbol]: StructuredCloneType
47
+ }
48
+
49
+ export type StructuredCloneType =
50
+ boolean | null | undefined | number | BigInt | string | Date | RegExp | Blob | File | FileList | ArrayBuffer | ArrayBufferView |
51
+ ImageBitmap | ImageData | Array<StructuredCloneType> | StructuredCloneObject | Map<StructuredCloneType, StructuredCloneType> | Set<StructuredCloneType>
52
+
53
+ export interface StructruredCloneTransferableObject {
54
+ [key: string | number | symbol]: StructruredCloneTransferableType
55
+ }
56
+
57
+ export type StructruredCloneTransferableType =
58
+ StructuredCloneType | TransferableObject | Array<StructruredCloneTransferableType> | StructruredCloneTransferableObject |
59
+ Map<StructruredCloneTransferableType, StructruredCloneTransferableType> | Set<StructruredCloneTransferableType>
60
+ ```
@@ -0,0 +1,11 @@
1
+ import type { Target, Resolvers, Resolver } from './types';
2
+ /**
3
+ * Call a function with the provided arguments and get its return value back
4
+ */
5
+ export declare const call: <T extends Resolvers>(target: Target, { key }?: {
6
+ key?: string | undefined;
7
+ }) => <T2 extends keyof T>(type: T2, data?: Parameters<T[T2]>[0] | undefined) => Promise<Awaited<ReturnType<T[T2]>>>;
8
+ /**
9
+ * Make a listener for a call
10
+ */
11
+ export declare const makeCallListener: <T extends Resolver>(func: T) => (data: Parameters<T>[0], extra: Parameters<T>[1]) => Promise<Awaited<ReturnType<T>>>;
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,19 @@
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
+ };
@@ -0,0 +1,4 @@
1
+ import type { ApiMessageData, ApiResolverOptions, Resolver, Resolvers, StructruredCloneTransferableObject, StructruredCloneTransferableType, StructuredCloneObject, StructuredCloneType, Target, TransferableObject } from './types';
2
+ export type { ApiMessageData, ApiResolverOptions, Resolver, Resolvers, StructruredCloneTransferableObject, StructruredCloneTransferableType, StructuredCloneObject, StructuredCloneType, Target, TransferableObject };
3
+ export * from './register';
4
+ export * from './call';
package/build/index.js CHANGED
@@ -6,6 +6,7 @@ var registerListener = ({
6
6
  target,
7
7
  resolvers,
8
8
  filter,
9
+ map,
9
10
  key = MESSAGE_SOURCE_KEY
10
11
  }) => {
11
12
  const listener = async (event) => {
@@ -19,7 +20,10 @@ var registerListener = ({
19
20
  const resolver = resolvers[type];
20
21
  if (!resolver)
21
22
  throw new Error(`Osra received a message of type "${type}" but no resolver was found for type.`);
22
- resolver(data, { event, type, port });
23
+ if (map)
24
+ resolver(...map(data, { event, type, port }));
25
+ else
26
+ resolver(data, { event, type, port });
23
27
  };
24
28
  target.addEventListener("message", listener);
25
29
  return {
@@ -29,7 +33,7 @@ var registerListener = ({
29
33
  };
30
34
 
31
35
  // src/utils.ts
32
- var isTransferable = (value) => value instanceof ArrayBuffer ? true : value instanceof MessagePort ? true : value instanceof ReadableStream ? true : value instanceof WritableStream ? true : value instanceof TransformStream ? true : value instanceof ImageBitmap ? true : false;
36
+ var isTransferable = (value) => globalThis.ArrayBuffer && value instanceof globalThis.ArrayBuffer ? true : globalThis.MessagePort && value instanceof globalThis.MessagePort ? true : globalThis.ReadableStream && value instanceof globalThis.ReadableStream ? true : globalThis.WritableStream && value instanceof globalThis.WritableStream ? true : globalThis.TransformStream && value instanceof globalThis.TransformStream ? true : globalThis.ImageBitmap && value instanceof globalThis.ImageBitmap ? true : false;
33
37
  var getTransferableObjects = (value) => {
34
38
  const transferables = [];
35
39
  const recurse = (value2) => isTransferable(value2) ? transferables.push(value2) : Array.isArray(value2) ? value2.map(recurse) : value2 && typeof value2 === "object" ? Object.values(value2).map(recurse) : void 0;
@@ -39,11 +43,15 @@ var getTransferableObjects = (value) => {
39
43
  var PROXY_FUNCTION_PROPERTY = "__proxyFunctionPort__";
40
44
  var makeProxyFunction = (func) => {
41
45
  const { port1, port2 } = new MessageChannel();
42
- port1.addEventListener("message", (ev) => {
43
- const result = func(...ev.data);
44
- const proxiedResult = proxyObjectFunctions(result);
45
- const transferables = getTransferableObjects(proxiedResult);
46
- port1.postMessage(proxiedResult, { transfer: transferables });
46
+ port1.addEventListener("message", async (ev) => {
47
+ try {
48
+ const result = await func(...ev.data);
49
+ const proxiedResult = proxyObjectFunctions(result);
50
+ const transferables = getTransferableObjects(proxiedResult);
51
+ port1.postMessage({ result: proxiedResult }, { transfer: transferables });
52
+ } catch (err) {
53
+ port1.postMessage({ error: err });
54
+ }
47
55
  });
48
56
  port1.start();
49
57
  return port2;
@@ -56,7 +64,10 @@ var makeProxiedFunction = (port) => (...args) => new Promise((resolve, reject) =
56
64
  const proxiedArguments = proxyObjectFunctions(args);
57
65
  const transferables = getTransferableObjects(proxiedArguments);
58
66
  port.addEventListener("message", (ev) => {
59
- resolve(makeObjectProxiedFunctions(ev.data));
67
+ if (ev.data.error)
68
+ reject(ev.data.error);
69
+ else
70
+ resolve(makeObjectProxiedFunctions(ev.data.result));
60
71
  });
61
72
  port.start();
62
73
  port.postMessage(proxiedArguments, { transfer: transferables });
@@ -67,11 +78,15 @@ var makeObjectProxiedFunctions = (value) => isTransferable(value) ? value : valu
67
78
  ])) : value;
68
79
 
69
80
  // src/call.ts
70
- var call = (target, { key = MESSAGE_SOURCE_KEY } = { key: MESSAGE_SOURCE_KEY }) => (type, data) => new Promise((resolve) => {
81
+ var call = (target, { key = MESSAGE_SOURCE_KEY } = { key: MESSAGE_SOURCE_KEY }) => (type, data) => new Promise((resolve, reject) => {
71
82
  const { port1, port2 } = new MessageChannel();
72
83
  port1.addEventListener("message", ({ data: data2 }) => {
73
- const proxiedData2 = makeObjectProxiedFunctions(data2);
74
- resolve(proxiedData2);
84
+ if (data2.error) {
85
+ reject(data2.error);
86
+ } else {
87
+ const proxiedData2 = makeObjectProxiedFunctions(data2.result);
88
+ resolve(proxiedData2);
89
+ }
75
90
  port1.close();
76
91
  port2.close();
77
92
  }, { once: true });
@@ -91,12 +106,18 @@ var call = (target, { key = MESSAGE_SOURCE_KEY } = { key: MESSAGE_SOURCE_KEY })
91
106
  var makeCallListener = (func) => async (data, extra) => {
92
107
  const { port } = extra;
93
108
  const proxiedData = makeObjectProxiedFunctions(data);
94
- const result = await func(proxiedData, extra);
95
- const proxyData = proxyObjectFunctions(result);
96
- const transferables = getTransferableObjects(proxyData);
97
- port.postMessage(proxyData, { transfer: transferables });
98
- port.close();
99
- return result;
109
+ try {
110
+ const result = await func(proxiedData, extra);
111
+ const proxyData = proxyObjectFunctions(result);
112
+ const transferables = getTransferableObjects(proxyData);
113
+ port.postMessage({ result: proxyData }, { transfer: transferables });
114
+ port.close();
115
+ return result;
116
+ } catch (error) {
117
+ port.postMessage({ error });
118
+ port.close();
119
+ throw error;
120
+ }
100
121
  };
101
122
  export {
102
123
  call,
File without changes
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ import type { ApiMessageData, Resolver, Resolvers } from './types';
2
+ export declare const registerListener: <T extends Resolvers>({ target, resolvers, filter, map, key }: {
3
+ target: WindowEventHandlers;
4
+ resolvers: T;
5
+ filter?: ((event: MessageEvent<any>) => boolean) | undefined;
6
+ map?: ((data: import("./types").StructruredCloneTransferableType, extra: {
7
+ event: MessageEvent<any>;
8
+ type: string | number;
9
+ port: MessagePort;
10
+ }) => [data: import("./types").StructruredCloneTransferableType, extra: {
11
+ event: MessageEvent<any>;
12
+ type: string | number;
13
+ port: MessagePort;
14
+ }]) | undefined;
15
+ key?: string | undefined;
16
+ }) => {
17
+ listener: (event: MessageEvent<ApiMessageData>) => Promise<void>;
18
+ resolvers: T;
19
+ };
File without changes
@@ -0,0 +1 @@
1
+ export declare const MESSAGE_SOURCE_KEY = "osra-message";
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/typescript/lib/lib.esnext.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../src/types.ts","../src/shared.ts","../src/utils.ts","../src/call.ts","../src/event-target.ts","../src/events.ts","../src/register.ts","../src/index.ts","../src/iterator.ts","../src/promise.ts","../src/pull.ts","../src/send.ts","../node_modules/@types/chai/index.d.ts","../node_modules/@types/chai-as-promised/index.d.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/yoga-layout/index.d.ts"],"fileInfos":[{"version":"3ac1b83264055b28c0165688fda6dfcc39001e9e7828f649299101c23ad0a0c3","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940","746d62152361558ea6d6115cf0da4dd10ede041d14882ede3568bce5dc4b4f1f","2f93dda35dafec68ec217c9ce67f0f4fbbbb030c055ac312641565ad60dd7e26","aea179452def8a6152f98f63b191b84e7cbd69b0e248c91e61fb2e52328abe8c",{"version":"72704b10d97777e15f1a581b73f88273037ef752d2e50b72287bd0a90af64fe6","affectsGlobalScope":true},{"version":"dbb73d4d99be496175cb432c74c2615f78c76f4272f1d83cba11ee0ed6dbddf0","affectsGlobalScope":true},{"version":"d8996609230d17e90484a2dd58f22668f9a05a3bfe00bfb1d6271171e54a31fb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"5075b36ab861c8c0c45377cb8c96270d7c65f0eeaf105d53fac6850da61f1027","affectsGlobalScope":true},{"version":"6c55633c733c8378db65ac3da7a767c3cf2cf3057f0565a9124a16a3a2019e87","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"e8c9f4e445a489991ca1a4232667de3ac36b07ba75ea335971fbeacf2d26fe67","affectsGlobalScope":true},{"version":"34478567f8a80171f88f2f30808beb7da15eac0538ae91282dd33dce928d98ed","affectsGlobalScope":true},{"version":"6ea9ab679ea030cf46c16a711a316078e9e02619ebaf07a7fcd16964aba88f2d","affectsGlobalScope":true},{"version":"aedb8de1abb2ff1095c153854a6df7deae4a5709c37297f9d6e9948b6806fa66","affectsGlobalScope":true},{"version":"11ffe3c281f375fff9ffdde8bbec7669b4dd671905509079f866f2354a788064","affectsGlobalScope":true},{"version":"10bbdc1981b8d9310ee75bfac28ee0477bb2353e8529da8cff7cb26c409cb5e8","affectsGlobalScope":true},{"version":"a019484328a90f3941b5bf2faf71ca8d4cd629c6e3455a56b5aade46c786a7a1","signature":"b988072dc02c976c9d42b9c8875eecfbea1fcc0822a25c823eed0638ff1934a7"},{"version":"05937501605ada7f9817ccf33f105ee25f49184975d9e6d72f7f79d060ece585","signature":"91196572ac171e385c355366d8c95f41584259576e8f2553fae310712fa2e7a2"},{"version":"42913ab24052c73290f042b1dd630a9a304fbd63ead1b79bd1bf3ecd1722977f","signature":"f224fce8893370dc397dac71391abacdd5e7f53b7c872cd0d04c651353a9b46f"},{"version":"5ce328fa1ec1c12c6fee319f57aeb4a8823298edce178da4d7725f40518dab9d","signature":"953a7c1d206fa48292f393b08ebfcdd541356f0e50a8dddb6f0452582308a33b"},{"version":"471a9874ad00882e700297c1941d262ddbbb38eec1d8b33d4c274cc90147f639","signature":"1d75deb0420956855c83394733e35c44fd1c478d70269f85c5b40a9864cfe68d"},{"version":"99a5f708f77c622ca352fd11001c4b41e49dae8fb7cb9eccc235d3db2aa6dbb1","signature":"f7c69f81d580fe173a2007da69c9ea008e9a1a996761329afc51e3c518df023e"},{"version":"fc63b47809372a705821bb012953bd825ca21e35581a678451bd35db77b1189c","signature":"474e9ae0fdb707a15108b58ec6347d22a1760c2f7d0cbe987a4a7bd346f43456"},{"version":"559c64d95d4f57cabfa2db4779acc26586625b879a90f83264c24a6c8d2f614a","signature":"dd8f496778f0fbd1e80624acecaa811f723fb77ccee03188497d316462c821c1"},{"version":"0af48ab96fcd4372caa919fab979abc41bbb090b6c2f3390245388bcd5e1afd9","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},{"version":"a865def279ea542d3025ee9dece6bb7484acee979758aa1314bac4f17207f200","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},{"version":"ce4b42df217bb63f0f788ebb195b26abb35e4df5194f6efd8aaf27a29dbf0683","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},{"version":"2fab913ef715208c4337bdcaf6e84acc484f02be7cdb64920d2af7d36cf2ac00","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},{"version":"3a15910b7f45dfc393f010ee8f913580b08d65752800fc48147ea13445acd5f7","affectsGlobalScope":true},{"version":"63e2182615c513e89bb8a3e749d08f7c379e86490fcdbf6d35f2c14b3507a6e8","affectsGlobalScope":true},"0cba3a5d7b81356222594442753cf90dd2892e5ccfe1d262aaca6896ba6c1380","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"77f0b5c6a193a699c9f7d7fb0578e64e562d271afa740783665d2a827104a873","affectsGlobalScope":true},"e5979905796fe2740d85fbaf4f11f42b7ee1851421afe750823220813421b1af",{"version":"fcdcb42da18dd98dc286b1876dd425791772036012ae61263c011a76b13a190f","affectsGlobalScope":true},"1dab5ab6bcf11de47ab9db295df8c4f1d92ffa750e8f095e88c71ce4c3299628","f71f46ccd5a90566f0a37b25b23bc4684381ab2180bdf6733f4e6624474e1894",{"version":"54e65985a3ee3cec182e6a555e20974ea936fc8b8d1738c14e8ed8a42bd921d4","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","5b30f550565fd0a7524282c81c27fe8534099e2cd26170ca80852308f07ae68d","34e5de87d983bc6aefef8b17658556e3157003e8d9555d3cb098c6bef0b5fbc8","d97cd8a4a42f557fc62271369ed0461c8e50d47b7f9c8ad0b5462f53306f6060","f27371653aded82b2b160f7a7033fb4a5b1534b6f6081ef7be1468f0f15327d3","c762cd6754b13a461c54b59d0ae0ab7aeef3c292c6cf889873f786ee4d8e75c9","f4ea7d5df644785bd9fbf419930cbaec118f0d8b4160037d2339b8e23c059e79",{"version":"bfea28e6162ed21a0aeed181b623dcf250aa79abf49e24a6b7e012655af36d81","affectsGlobalScope":true},"b8aca9d0c81abb02bec9b7621983ae65bde71da6727580070602bd2500a9ce2a","ae97e20f2e10dbeec193d6a2f9cd9a367a1e293e7d6b33b68bacea166afd7792","10d4796a130577d57003a77b95d8723530bbec84718e364aa2129fa8ffba0378","063f53ff674228c190efa19dd9448bcbd540acdbb48a928f4cf3a1b9f9478e43","bf73c576885408d4a176f44a9035d798827cc5020d58284cb18d7573430d9022","7ae078ca42a670445ae0c6a97c029cb83d143d62abd1730efb33f68f0b2c0e82",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"963fe86b2ebd07a34b92b52c6532ab45ec5ccda218a6c477de354fcad2aae0cb","12eea70b5e11e924bb0543aea5eadc16ced318aa26001b453b0d561c2fd0bd1e","08777cd9318d294646b121838574e1dd7acbb22c21a03df84e1f2c87b1ad47f2","08a90bcdc717df3d50a2ce178d966a8c353fd23e5c392fd3594a6e39d9bb6304",{"version":"4cd4cff679c9b3d9239fd7bf70293ca4594583767526916af8e5d5a47d0219c7","affectsGlobalScope":true},"2a12d2da5ac4c4979401a3f6eaafa874747a37c365e4bc18aa2b171ae134d21b","002b837927b53f3714308ecd96f72ee8a053b8aeb28213d8ec6de23ed1608b66","1dc9c847473bb47279e398b22c740c83ea37a5c88bf66629666e3cf4c5b9f99c","a9e4a5a24bf2c44de4c98274975a1a705a0abbaad04df3557c2d3cd8b1727949","821dcb2b571bf698841d8ec25fde9d5f615ef3958957227962602f9dbfa8d800","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","5f0ed51db151c2cdc4fa3bb0f44ce6066912ad001b607a34e65a96c52eb76248",{"version":"af9771b066ec35ffa1c7db391b018d2469d55e51b98ae95e62b6cbef1b0169ca","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","103d70bfbeb3cd3a3f26d1705bf986322d8738c2c143f38ebb743b1e228d7444","f52fbf64c7e480271a9096763c4882d356b05cab05bf56a64e68a95313cd2ce2","59bdb65f28d7ce52ccfc906e9aaf422f8b8534b2d21c32a27d7819be5ad81df7",{"version":"3a2da34079a2567161c1359316a32e712404b56566c45332ac9dcee015ecce9f","affectsGlobalScope":true},"28a2e7383fd898c386ffdcacedf0ec0845e5d1a86b5a43f25b86bc315f556b79","3aff9c8c36192e46a84afe7b926136d520487155154ab9ba982a8b544ea8fc95","a880cf8d85af2e4189c709b0fea613741649c0e40fffb4360ec70762563d5de0","85bbf436a15bbeda4db888be3062d47f99c66fd05d7c50f0f6473a9151b6a070","9f9c49c95ecd25e0cb2587751925976cf64fd184714cb11e213749c80cf0f927","f0c75c08a71f9212c93a719a25fb0320d53f2e50ca89a812640e08f8ad8c408c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"aee3379fb20741a337a779530cc3e608aba5f34776511033d1d2db7ca45c4193","7693b0547e3b004443fa1f4327b61617e7317757a3e947ccc200c91111c77eca"],"options":{"composite":false,"declaration":true,"emitDeclarationOnly":true,"module":99,"noImplicitAny":false,"noUncheckedIndexedAccess":true,"outDir":"./","sourceMap":true,"strictNullChecks":true,"target":99},"fileIdsList":[[64,109],[109],[66,109],[69,109],[70,75,109],[71,81,82,89,98,108,109],[71,72,81,89,109],[73,109],[74,75,82,90,109],[75,98,105,109],[76,78,81,89,109],[77,109],[78,79,109],[80,81,109],[81,109],[81,82,83,98,108,109],[81,82,83,98,109],[109,113],[84,89,98,108,109],[81,82,84,85,89,98,105,108,109],[84,86,98,105,108,109],[66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115],[81,87,109],[88,108,109],[78,81,89,98,109],[90,109],[91,109],[69,92,109],[93,107,109,113],[94,109],[95,109],[81,96,109],[96,97,109,111],[81,98,99,100,109],[98,100,109],[98,99,109],[101,109],[102,109],[81,103,104,109],[103,104,109],[75,89,98,105,109],[106,109],[89,107,109],[70,84,95,108,109],[75,109],[98,109,110],[109,111],[109,112],[70,75,81,83,92,98,108,109,111,113],[98,109,114],[52,53,54,109],[56,109],[52,55,58,109],[52,53,109],[52,109],[52],[52,55,58]],"referencedMap":[[65,1],[64,2],[66,3],[67,3],[69,4],[70,5],[71,6],[72,7],[73,8],[74,9],[75,10],[76,11],[77,12],[78,13],[79,13],[80,14],[81,15],[82,16],[83,17],[68,18],[115,2],[84,19],[85,20],[86,21],[116,22],[87,23],[88,24],[89,25],[90,26],[91,27],[92,28],[93,29],[94,30],[95,31],[96,32],[97,33],[98,34],[100,35],[99,36],[101,37],[102,38],[103,39],[104,40],[105,41],[106,42],[107,43],[108,44],[109,45],[110,46],[111,47],[112,48],[113,49],[114,50],[117,2],[11,2],[12,2],[14,2],[13,2],[2,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[21,2],[22,2],[3,2],[4,2],[26,2],[23,2],[24,2],[25,2],[27,2],[28,2],[29,2],[5,2],[30,2],[31,2],[32,2],[33,2],[6,2],[34,2],[35,2],[36,2],[37,2],[7,2],[42,2],[38,2],[39,2],[40,2],[41,2],[8,2],[46,2],[43,2],[44,2],[45,2],[47,2],[9,2],[48,2],[49,2],[50,2],[1,2],[10,2],[51,2],[55,51],[56,2],[57,52],[59,53],[60,2],[61,2],[62,2],[58,54],[63,2],[53,2],[52,2],[54,55]],"exportedModulesMap":[[65,1],[64,2],[66,3],[67,3],[69,4],[70,5],[71,6],[72,7],[73,8],[74,9],[75,10],[76,11],[77,12],[78,13],[79,13],[80,14],[81,15],[82,16],[83,17],[68,18],[115,2],[84,19],[85,20],[86,21],[116,22],[87,23],[88,24],[89,25],[90,26],[91,27],[92,28],[93,29],[94,30],[95,31],[96,32],[97,33],[98,34],[100,35],[99,36],[101,37],[102,38],[103,39],[104,40],[105,41],[106,42],[107,43],[108,44],[109,45],[110,46],[111,47],[112,48],[113,49],[114,50],[117,2],[55,56],[59,57],[58,56],[54,56]],"semanticDiagnosticsPerFile":[65,64,66,67,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,68,115,84,85,86,116,87,88,89,90,91,92,93,94,95,96,97,98,100,99,101,102,103,104,105,106,107,108,109,110,111,112,113,114,117,11,12,14,13,2,15,16,17,18,19,20,21,22,3,4,26,23,24,25,27,28,29,5,30,31,32,33,6,34,35,36,37,7,42,38,39,40,41,8,46,43,44,45,47,9,48,49,50,1,10,51,55,56,57,59,60,61,62,58,63,53,52,54]},"version":"4.6.3"}
@@ -0,0 +1,25 @@
1
+ export declare type TransferableObject = ArrayBuffer | MessagePort | ReadableStream | WritableStream | TransformStream | /* AudioData | */ ImageBitmap;
2
+ export interface StructuredCloneObject {
3
+ [key: keyof any]: StructuredCloneType;
4
+ }
5
+ export declare type StructuredCloneType = 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 interface StructruredCloneTransferableObject {
7
+ [key: keyof any]: StructruredCloneTransferableType;
8
+ }
9
+ export declare type StructruredCloneTransferableType = StructuredCloneType | TransferableObject | Array<StructruredCloneTransferableType> | StructruredCloneTransferableObject | Map<StructruredCloneTransferableType, StructruredCloneTransferableType> | Set<StructruredCloneTransferableType>;
10
+ export declare type Target = Window | ServiceWorker | Worker;
11
+ export declare type Resolver = (data: StructruredCloneTransferableType, extra: ApiResolverOptions) => any;
12
+ export declare type Resolvers = {
13
+ [key: string]: Resolver;
14
+ };
15
+ export declare type ApiResolverOptions<T extends Resolvers = Resolvers, T2 = {}> = T2 & {
16
+ event: MessageEvent<any>;
17
+ type: keyof T;
18
+ port: MessagePort;
19
+ };
20
+ export declare type ApiMessageData<T extends Resolvers = Resolvers> = {
21
+ type: keyof T;
22
+ data: any;
23
+ port: MessagePort;
24
+ source: string;
25
+ };
@@ -0,0 +1,6 @@
1
+ import { TransferableObject } from './types';
2
+ export declare const getTransferableObjects: (value: any) => TransferableObject[];
3
+ export declare const makeProxyFunction: (func: any) => MessagePort;
4
+ export declare const proxyObjectFunctions: (value: any) => any;
5
+ export declare const makeProxiedFunction: (port: MessagePort) => (...args: any[]) => Promise<unknown>;
6
+ export declare const makeObjectProxiedFunctions: (value: any) => any;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "osra",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "Easy communication between workers",
5
5
  "files": [
6
- "./build"
6
+ "build"
7
7
  ],
8
8
  "main": "build/index.js",
9
9
  "scripts": {
@@ -11,7 +11,12 @@
11
11
  "type-check-watch": "tsc --watch --incremental",
12
12
  "build": "esbuild ./src/index.ts --format=esm --bundle --outfile=build/index.js && npm run type-check",
13
13
  "build-watch": "esbuild --watch ./src/index.ts --format=esm --bundle --outfile=build/index.js",
14
- "dev": "concurrently \"npm run build-watch\" \"npm run type-check-watch\""
14
+ "dev": "concurrently \"npm run build-watch\" \"npm run type-check-watch\"",
15
+ "copy-tests-html": "copyfiles -u 1 ./tests/*/index.html tests/build",
16
+ "build-tests": "npm run copy-tests-html && esbuild ./tests/call/iframe.ts ./tests/event-channel/iframe.ts --format=esm --bundle --outdir=tests/build",
17
+ "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",
18
+ "test": "epk",
19
+ "test-watch": "epk -w"
15
20
  },
16
21
  "repository": {
17
22
  "type": "git",
@@ -24,8 +29,15 @@
24
29
  },
25
30
  "homepage": "https://github.com/Banou26/osra#readme",
26
31
  "devDependencies": {
32
+ "@types/chai-as-promised": "^7.1.5",
33
+ "@types/node": "^17.0.35",
34
+ "chai": "^4.3.6",
35
+ "chai-as-promised": "^7.1.1",
27
36
  "concurrently": "^7.0.0",
37
+ "copyfiles": "^2.4.1",
38
+ "epk": "^0.16.0",
28
39
  "esbuild": "^0.14.28",
40
+ "mime": "^3.0.0",
29
41
  "typescript": "^4.6.3"
30
42
  }
31
43
  }