osra 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +8 -0
- package/build/index.js.map +1 -1
- package/build/test.js +3544 -0
- package/build/test.js.map +1 -0
- package/build/types.d.ts +66 -0
- package/build/utils.d.ts +60 -0
- package/package.json +2 -2
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RemoteTarget, LocalTarget, OsraMessage, StructuredCloneTransferableProxiableType } from './types';
|
|
2
|
+
export * from './utils';
|
|
3
|
+
export declare const expose: <T extends StructuredCloneTransferableProxiableType>(value: StructuredCloneTransferableProxiableType, { remote: _remote, local: _local, key, origin }: {
|
|
4
|
+
remote: RemoteTarget | ((osraMessage: OsraMessage, transferables: Transferable[]) => void);
|
|
5
|
+
local: LocalTarget | ((listener: (event: MessageEvent<OsraMessage>) => void) => void);
|
|
6
|
+
key?: string;
|
|
7
|
+
origin?: string;
|
|
8
|
+
}) => Promise<T>;
|
package/build/index.js.map
CHANGED
|
@@ -1 +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,SAASC,IAAI,GAAGA,IAAI,KAAK,EAAEA;AACvB,EAAAD,EAAU,MAAMC,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAE7C,SAASC,EAAgBC,GAAKC,IAAS,GAAG;AAC7C,UAAQJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAC7BJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzB,MACAJ,EAAU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CAAQ,IAERuC,EAAA,iBAAiB,WAAWvC,CAAyB,GAGpD2D,EAAA,GAEHH;AACT;","x_google_ignoreList":[0,1,2,3]}
|
|
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 | WritableStream\r\n | TransformStream\r\n /*\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<T>((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 unknown 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,SAASC,IAAI,GAAGA,IAAI,KAAK,EAAEA;AACvB,EAAAD,EAAU,MAAMC,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAE7C,SAASC,EAAgBC,GAAKC,IAAS,GAAG;AAC7C,UAAQJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAC7BJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzB,MACAJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzB,MACAJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzB,MACAJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzBJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IACzB,MACAJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAC1BJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAC1BJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAC1BJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAC1BJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAC1BJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,GAAG,YAAa;AAClD;AC1BA,IAAIC;AACJ,MAAMC,IAAQ,IAAI,WAAW,EAAE;AAChB,SAASC,IAAM;AA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