osra 0.6.2 → 0.6.4
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 +148 -231
- package/build/connections/bidirectional.d.ts +5 -4
- package/build/connections/index.d.ts +2 -1
- package/build/connections/utils.d.ts +86 -4
- package/build/index.d.ts +52 -6
- package/build/index.js +683 -541
- package/build/index.js.map +1 -1
- package/build/revivables/fallbacks.d.ts +8 -6
- package/build/revivables/index.d.ts +5 -4
- package/build/types.d.ts +13 -7
- package/build/utils/transport.d.ts +17 -0
- package/package.json +14 -7
|
@@ -128,12 +128,14 @@ export declare const transferable: {
|
|
|
128
128
|
readonly box: (value: Transferable, _context: RevivableContext<any>) => Transferable;
|
|
129
129
|
readonly revive: (value: BoxedTransferable, _context: RevivableContext<any>) => Transferable;
|
|
130
130
|
};
|
|
131
|
-
export type
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
readonly
|
|
135
|
-
readonly
|
|
136
|
-
readonly
|
|
131
|
+
export type BoxedBlob = BoxBaseType<'blob'>;
|
|
132
|
+
declare const isBlob: (value: unknown) => value is Blob;
|
|
133
|
+
export declare const blob: {
|
|
134
|
+
readonly type: 'blob';
|
|
135
|
+
readonly capableOnly: true;
|
|
136
|
+
readonly isType: typeof isBlob;
|
|
137
|
+
readonly box: (value: Blob, context: RevivableContext<any>) => Blob;
|
|
138
|
+
readonly revive: (value: BoxedBlob, _context: RevivableContext<any>) => Blob;
|
|
137
139
|
};
|
|
138
140
|
export type BoxedUnclonable = BoxBaseType<'unclonable'>;
|
|
139
141
|
export declare const unclonable: {
|
|
@@ -57,10 +57,11 @@ export declare const defaultRevivableModules: readonly [typeof transfer, typeof
|
|
|
57
57
|
readonly box: (value: import("./fallbacks.js").Transferable, _context: RevivableContext<any>) => import("./fallbacks.js").Transferable;
|
|
58
58
|
readonly revive: (value: import("./fallbacks.js").BoxedTransferable, _context: RevivableContext<any>) => import("./fallbacks.js").Transferable;
|
|
59
59
|
}, {
|
|
60
|
-
readonly type: '
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
63
|
-
readonly
|
|
60
|
+
readonly type: 'blob';
|
|
61
|
+
readonly capableOnly: true;
|
|
62
|
+
readonly isType: (value: unknown) => value is Blob;
|
|
63
|
+
readonly box: (value: Blob, context: RevivableContext<any>) => Blob;
|
|
64
|
+
readonly revive: (value: import("./fallbacks.js").BoxedBlob, _context: RevivableContext<any>) => Blob;
|
|
64
65
|
}, typeof eventTarget, {
|
|
65
66
|
readonly type: 'unclonable';
|
|
66
67
|
readonly isType: (value: unknown) => value is never;
|
package/build/types.d.ts
CHANGED
|
@@ -8,15 +8,21 @@ export declare const OSRA_BOX: '__OSRA_BOX__';
|
|
|
8
8
|
export type Uuid = `${string}-${string}-${string}-${string}-${string}`;
|
|
9
9
|
export type Jsonable = boolean | null | number | string | {
|
|
10
10
|
[key: string]: Jsonable;
|
|
11
|
-
} |
|
|
11
|
+
} | ReadonlyArray<Jsonable>;
|
|
12
12
|
export type Structurable = Jsonable
|
|
13
13
|
/** not really structureable but here for convenience */
|
|
14
|
-
| void | undefined | bigint | Date | RegExp | File | FileList | ArrayBuffer | ArrayBufferView | ImageBitmap | ImageData | {
|
|
14
|
+
| void | undefined | bigint | Date | RegExp | Blob | File | FileList | ArrayBuffer | ArrayBufferView | ImageBitmap | ImageData | {
|
|
15
15
|
[key: string]: Structurable;
|
|
16
|
-
} |
|
|
17
|
-
|
|
16
|
+
} | ReadonlyArray<Structurable> | Map<Structurable, Structurable> | Set<Structurable>;
|
|
17
|
+
/** lib.dom declares some `Transferable` members as EMPTY interfaces
|
|
18
|
+
* (`MediaSourceHandle` as of TS 5.x/7.x). With no members they structurally
|
|
19
|
+
* absorb every object type, which would let `WeakMap` & co. slip past the
|
|
20
|
+
* `Capable` check unnoticed. Drop member-less types from the compile-time
|
|
21
|
+
* union; runtime transfer of those exotic types is unaffected. */
|
|
22
|
+
type NonAbsorbing<T> = T extends unknown ? keyof T extends never ? never : T : never;
|
|
23
|
+
export type StructurableTransferable = Structurable | NonAbsorbing<Transferable> | {
|
|
18
24
|
[key: string]: StructurableTransferable;
|
|
19
|
-
} |
|
|
25
|
+
} | ReadonlyArray<StructurableTransferable> | Map<StructurableTransferable, StructurableTransferable> | Set<StructurableTransferable>;
|
|
20
26
|
/** "Free" types in `Capable` - narrows to `Jsonable` on JSON transports so
|
|
21
27
|
* user code can't type a `Date`/`File`/etc. that JSON would silently coerce.
|
|
22
28
|
* Modules that DO support JSON (date, map, set, bigint, …) put their type
|
|
@@ -24,11 +30,11 @@ export type StructurableTransferable = Structurable | Transferable | {
|
|
|
24
30
|
type CapableBase<Ctx extends RevivableContext> = IsJsonOnlyTransport<Ctx['transport']> extends true ? Jsonable | undefined | void : StructurableTransferable;
|
|
25
31
|
export type Capable<TModules extends readonly RevivableModule[] = DefaultRevivableModules, Ctx extends RevivableContext = RevivableContext> = CapableBase<Ctx> | InferRevivables<TModules, Ctx> | {
|
|
26
32
|
[key: string]: Capable<TModules, Ctx>;
|
|
27
|
-
} |
|
|
33
|
+
} | ReadonlyArray<Capable<TModules, Ctx>> | Map<Capable<TModules, Ctx>, Capable<TModules, Ctx>> | Set<Capable<TModules, Ctx>>;
|
|
28
34
|
/** What a value looks like from the far side of the connection: functions
|
|
29
35
|
* become async (calls cross the wire), containers map recursively,
|
|
30
36
|
* everything else revives as itself. */
|
|
31
|
-
export type Remote<T> = T extends (...args: infer P) => infer R ? (...args: P) => Promise<Remote<Awaited<R>>> : T extends Promise<infer U> ? Promise<Remote<U>> : T extends Map<any, any> | Set<any> | Date | Error | RegExp | ArrayBuffer | ArrayBufferView | File | FileList | ReadableStream | WritableStream | MessagePort | EventTarget | Request | Response | Headers ? T : T extends AsyncIterable<infer U> ? AsyncIterableIterator<Remote<U>> : T extends ReadonlyArray<unknown> ? {
|
|
37
|
+
export type Remote<T> = T extends (...args: infer P) => infer R ? (...args: P) => Promise<Remote<Awaited<R>>> : T extends Promise<infer U> ? Promise<Remote<U>> : T extends Map<any, any> | Set<any> | Date | Error | RegExp | ArrayBuffer | ArrayBufferView | Blob | File | FileList | ReadableStream | WritableStream | MessagePort | EventTarget | Request | Response | Headers ? T : T extends AsyncIterable<infer U> ? AsyncIterableIterator<Remote<U>> : T extends ReadonlyArray<unknown> ? {
|
|
32
38
|
[K in keyof T]: Remote<T[K]>;
|
|
33
39
|
} : T extends object ? {
|
|
34
40
|
[K in keyof T]: Remote<T[K]>;
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { Browser } from 'webextension-polyfill';
|
|
2
2
|
import type { Message } from '../types.js';
|
|
3
3
|
import type { WebExtOnConnect, WebExtOnMessage, WebExtPort, WebExtRuntime, WebExtSender } from './type-guards.js';
|
|
4
|
+
/** What the local side knows about the realm on the other end of a connection.
|
|
5
|
+
*
|
|
6
|
+
* `origin` and `source` are only OBSERVABLE on window transports. A MessagePort message carries
|
|
7
|
+
* origin "" and source null, so for a port the identity has to be declared by whoever created the
|
|
8
|
+
* transport, which is the side that received the port over a trustworthy window message. That is why
|
|
9
|
+
* `expose` takes a `context` option rather than only reporting what it can see: without it, every
|
|
10
|
+
* port-based consumer would rebuild the same out-of-band handshake to learn who it is talking to. */
|
|
11
|
+
export type Context = {
|
|
12
|
+
/** Tears down THIS connection and nothing else: the peer is sent a close, its revivables are torn
|
|
13
|
+
* down, and it stops being tracked. `unregisterSignal` is the whole-expose equivalent; this is the
|
|
14
|
+
* one a server reaches for when a single realm misbehaves or is finished with. */
|
|
15
|
+
abort?: () => void;
|
|
16
|
+
origin?: string;
|
|
17
|
+
source?: MessageEventSource | null;
|
|
18
|
+
port?: MessagePort | WebExtPort;
|
|
19
|
+
sender?: WebExtSender;
|
|
20
|
+
};
|
|
4
21
|
export type MessageContext = {
|
|
5
22
|
port?: MessagePort | WebExtPort;
|
|
6
23
|
sender?: WebExtSender;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osra",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Easy communication between workers",
|
|
5
5
|
"homepage": "https://github.com/Banou26/osra#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
],
|
|
18
18
|
"type": "module",
|
|
19
19
|
"sideEffects": false,
|
|
20
|
+
"workspaces": [
|
|
21
|
+
"docs"
|
|
22
|
+
],
|
|
20
23
|
"main": "build/index.js",
|
|
21
24
|
"types": "./build/index.d.ts",
|
|
22
25
|
"exports": {
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
"./package.json": "./package.json"
|
|
32
35
|
},
|
|
33
36
|
"scripts": {
|
|
34
|
-
"build": "vp build && tsc --declaration --emitDeclarationOnly",
|
|
37
|
+
"build": "vp build && node ./node_modules/typescript7/bin/tsc --declaration --emitDeclarationOnly",
|
|
35
38
|
"build-watch": "vp build --watch",
|
|
36
39
|
"clean": "rimraf build",
|
|
37
40
|
"prepublishOnly": "npm run clean && npm run build",
|
|
@@ -46,18 +49,22 @@
|
|
|
46
49
|
"test-with-coverage": "npm run build-test && npx playwright test && npm run print-coverage && npm run clean-coverage",
|
|
47
50
|
"print-coverage": "npx nyc report",
|
|
48
51
|
"clean-coverage": "rimraf .nyc_output coverage",
|
|
49
|
-
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.tests.json",
|
|
52
|
+
"type-check": "node ./node_modules/typescript7/bin/tsc --noEmit && node ./node_modules/typescript7/bin/tsc --noEmit -p tsconfig.tests.json",
|
|
50
53
|
"start-server": "http-server -p 3000",
|
|
51
54
|
"build-extension-test": "node build-extension-test.mjs",
|
|
52
55
|
"test-extension": "npm run build-extension-test && npx playwright test -c playwright.extension.config.ts",
|
|
53
|
-
"check-consumer-types": "npm run build && tsc --noEmit -p tsconfig.consumer.json"
|
|
56
|
+
"check-consumer-types": "npm run build && node ./node_modules/typescript7/bin/tsc --noEmit -p tsconfig.consumer.json",
|
|
57
|
+
"docs-dev": "npm run dev -w docs",
|
|
58
|
+
"docs-build": "npm run build -w docs",
|
|
59
|
+
"docs-preview": "npm run preview -w docs",
|
|
60
|
+
"docs-check-twoslash": "npm run check-twoslash -w docs"
|
|
54
61
|
},
|
|
55
62
|
"dependencies": {
|
|
56
63
|
"@types/webextension-polyfill": "^0.12.4"
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
59
66
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
60
|
-
"@playwright/test": "
|
|
67
|
+
"@playwright/test": "1.58.2",
|
|
61
68
|
"@types/chai": "^5.2.3",
|
|
62
69
|
"@types/chai-as-promised": "^8.0.2",
|
|
63
70
|
"@types/chrome": "^0.1.27",
|
|
@@ -69,8 +76,8 @@
|
|
|
69
76
|
"http-server": "^14.1.1",
|
|
70
77
|
"nodemon": "^3.1.10",
|
|
71
78
|
"nyc": "^17.1.0",
|
|
72
|
-
"playwright": "
|
|
73
|
-
"
|
|
79
|
+
"playwright": "1.58.2",
|
|
80
|
+
"typescript7": "npm:typescript@^7.0.2",
|
|
74
81
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
75
82
|
"vite-plugin-istanbul": "^8.0.0",
|
|
76
83
|
"vite-plus": "0.2.4",
|