osra 0.6.5 → 0.6.7

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.
@@ -9,24 +9,26 @@ export type Messages = {
9
9
  };
10
10
  export declare const Messages: Messages;
11
11
  declare const IDENTITY_MARKER: unique symbol;
12
- type IdentityWrapper<T = unknown> = {
12
+ /** Phantom shape. A tracked value carries no marker of its own, the mark lives in a WeakMap, so
13
+ * this is what `isType` declares instead: matching it at the type level would widen `Capable` to
14
+ * every object, and nothing a user writes structurally matches this. */
15
+ type IdentityMarked = {
13
16
  readonly [IDENTITY_MARKER]: true;
14
- readonly value: T;
15
17
  };
16
18
  export type BoxedIdentity<T extends Capable = Capable> = BoxBaseType<typeof type> & {
17
19
  id: string;
18
20
  inner?: Capable;
19
21
  [UnderlyingType]: T;
20
22
  };
21
- /** Wrap a value so osra preserves reference identity across the RPC
22
- * boundary. Idempotent; primitives pass through unchanged. Lies at the
23
- * type level - runtime value is an IdentityWrapper<T> typed as T. */
23
+ /** Mark a value so osra preserves its reference identity across the boundary. The peer's revived
24
+ * value stands for this one, and handing it back - to you, or onward to a further context and back
25
+ * again - resolves to this very reference. The mark sticks to the value, so only the side that
26
+ * owns it has to opt in. Idempotent, and primitives pass through unchanged. */
24
27
  export declare const identity: <T>(value: T) => T;
25
- export declare const isType: (value: unknown) => value is IdentityWrapper;
26
- export declare const box: <T extends Capable, TContext extends RevivableContext>(wrapper: IdentityWrapper<T>, context: TContext) => BoxedIdentity<T>;
27
- /** Identity-box a referenceable value with a caller-supplied inner box,
28
- * bypassing the recursive-box step. Used by revivables (symbol with
29
- * description=undefined) where recursing back through their own box
28
+ export declare const isType: (value: unknown) => value is IdentityMarked;
29
+ export declare const box: <T extends Capable, TContext extends RevivableContext>(value: T, context: TContext) => BoxedIdentity<T>;
30
+ /** Identity-box a referenceable value with a caller-supplied inner box, bypassing the walker. Used
31
+ * by revivables (symbol with description=undefined) where recursing back through their own box
30
32
  * would loop into this module again. */
31
33
  export declare const boxByReference: <T extends WeakKey, TContext extends RevivableContext>(value: T, innerBox: Capable, context: TContext) => BoxedIdentity;
32
34
  export declare const revive: <T extends BoxedIdentity, TContext extends RevivableContext>(value: T, context: TContext) => T[UnderlyingType];
@@ -71,4 +71,11 @@ export declare const defaultRevivableModules: readonly [typeof transfer, typeof
71
71
  export type DefaultRevivableModules = typeof defaultRevivableModules;
72
72
  export type DefaultRevivableModule = DefaultRevivableModules[number];
73
73
  export declare const recursiveBox: <T extends Capable, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>) => DeepReplaceWithBox<T, TModules[number]>;
74
+ /** Box a value your own module claimed in place: every other module gets its turn and children are
75
+ * walked as usual, but `claimedBy` is skipped, and the cycle guard the caller's `recursiveBox`
76
+ * frame already holds for this value is not re-entered.
77
+ * A module needs this when its `isType` matches a bare value rather than a wrapper around one, the
78
+ * way `identity()` marks a reference in place: `recursiveBox` on that same value would come
79
+ * straight back to the module, and the guard would report it as a cycle. */
80
+ export declare const boxClaimedValue: <T extends Capable, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>, claimedBy: string) => DeepReplaceWithBox<T, TModules[number]>;
74
81
  export declare const recursiveRevive: <T extends Capable, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>) => DeepReplaceWithRevive<T, TModules[number]>;
@@ -16,6 +16,19 @@ export type BoxedTransfer<T extends Capable = Capable> = BoxBaseType<typeof type
16
16
  * copy when the platform/transport can't transfer the given type. Lies at
17
17
  * the type level - runtime value is a TransferWrapper<T> typed as T. */
18
18
  export declare const transfer: <T>(value: T) => T;
19
+ /** Whether boxing is happening inside a transfer() wrapper's extent. Streams read
20
+ * this at box time so transfer(stream) propagates move semantics to their chunks. */
21
+ export declare const isInTransfer: () => boolean;
22
+ /** Internal chunk marker: unlike the public transfer(), wraps containers too, so
23
+ * transferables nested anywhere inside a chunk move. Not part of the public API. */
24
+ export declare const forceTransfer: <T>(value: T) => T;
25
+ /** Runs fn with the ambient transfer extent suspended. Boxing at independent walk
26
+ * entry points (protocol ports, revived-function calls) can fire synchronously
27
+ * inside someone else's transfer() extent - an EventPort.start() flush during
28
+ * boxing, or user code (a getter) calling a revived function mid-walk. Those
29
+ * values are not part of the wrapper's graph, so their move semantics must come
30
+ * from a wrapper in their own data, never from the ambient counter. */
31
+ export declare const outsideTransfer: <T>(fn: () => T) => T;
19
32
  export declare const isType: (value: unknown) => value is TransferWrapper;
20
33
  export declare const box: <T extends Capable, TContext extends RevivableContext>(wrapper: TransferWrapper<T>, context: TContext) => BoxedTransfer<T>;
21
34
  export declare const revive: <T extends BoxedTransfer, TContext extends RevivableContext>(value: T, context: TContext) => T[UnderlyingType];
@@ -21,6 +21,7 @@ export type WriteAck = {
21
21
  export type Msg = WriteContext | WriteAck;
22
22
  export type BoxedWritableStream<T extends WritableStream = WritableStream> = BoxBaseType<typeof type> & {
23
23
  port: BoxedMessagePort<Msg>;
24
+ transferChunks?: true;
24
25
  } & {
25
26
  [UnderlyingType]: T;
26
27
  };
package/build/types.d.ts CHANGED
@@ -9,9 +9,7 @@ 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
- export type Structurable = Jsonable
13
- /** not really structureable but here for convenience */
14
- | void | undefined | bigint | Date | RegExp | Blob | File | FileList | ArrayBuffer | ArrayBufferView | ImageBitmap | ImageData | {
12
+ export type Structurable = Jsonable | void | undefined | bigint | Date | RegExp | Blob | File | FileList | ArrayBuffer | ArrayBufferView | ImageBitmap | ImageData | {
15
13
  [key: string]: Structurable;
16
14
  } | ReadonlyArray<Structurable> | Map<Structurable, Structurable> | Set<Structurable>;
17
15
  /** lib.dom declares some `Transferable` members as EMPTY interfaces
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osra",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "Easy communication between workers",
5
5
  "homepage": "https://github.com/Banou26/osra#readme",
6
6
  "bugs": {
@@ -57,19 +57,19 @@
57
57
  "docs-dev": "npm run dev -w docs",
58
58
  "docs-build": "npm run build -w docs",
59
59
  "docs-preview": "npm run preview -w docs",
60
+ "docs-gen-reference": "npm run gen:reference -w docs",
61
+ "docs-check-links": "npm run check-links -w docs",
60
62
  "docs-check-twoslash": "npm run check-twoslash -w docs"
61
63
  },
62
- "dependencies": {
63
- "@types/webextension-polyfill": "^0.12.4"
64
- },
65
64
  "devDependencies": {
66
65
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
67
66
  "@playwright/test": "1.58.2",
68
67
  "@types/chai": "^5.2.3",
69
68
  "@types/chai-as-promised": "^8.0.2",
70
- "@types/chrome": "^0.1.27",
69
+ "@types/chrome": "^0.1.43",
71
70
  "@types/firefox-webext-browser": "^143.0.0",
72
71
  "@types/node": "^25.0.2",
72
+ "@types/webextension-polyfill": "^0.12.5",
73
73
  "chai": "^5.3.3",
74
74
  "chai-as-promised": "^8.0.1",
75
75
  "concurrently": "^9.1.0",