osra 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +224 -231
  2. package/build/connections/bidirectional.d.ts +25 -15
  3. package/build/connections/index.d.ts +8 -8
  4. package/build/connections/relay.d.ts +1 -1
  5. package/build/connections/utils.d.ts +6 -5
  6. package/build/index.d.ts +11 -11
  7. package/build/index.js +782 -513
  8. package/build/index.js.map +1 -1
  9. package/build/revivables/abort-signal.d.ts +6 -4
  10. package/build/revivables/array-buffer.d.ts +2 -2
  11. package/build/revivables/async-iterator.d.ts +16 -0
  12. package/build/revivables/bigint.d.ts +1 -1
  13. package/build/revivables/blob.d.ts +3 -3
  14. package/build/revivables/date.d.ts +1 -1
  15. package/build/revivables/error.d.ts +5 -2
  16. package/build/revivables/event-target.d.ts +5 -4
  17. package/build/revivables/event.d.ts +2 -2
  18. package/build/revivables/fallbacks.d.ts +1 -1
  19. package/build/revivables/function.d.ts +4 -4
  20. package/build/revivables/headers.d.ts +1 -1
  21. package/build/revivables/identity.d.ts +3 -3
  22. package/build/revivables/index.d.ts +48 -39
  23. package/build/revivables/json-primitives.d.ts +17 -0
  24. package/build/revivables/map.d.ts +2 -2
  25. package/build/revivables/message-port.d.ts +6 -6
  26. package/build/revivables/promise.d.ts +5 -5
  27. package/build/revivables/readable-stream.d.ts +8 -4
  28. package/build/revivables/request.d.ts +4 -2
  29. package/build/revivables/response.d.ts +2 -2
  30. package/build/revivables/set.d.ts +2 -2
  31. package/build/revivables/symbol.d.ts +5 -3
  32. package/build/revivables/transfer.d.ts +2 -2
  33. package/build/revivables/typed-array.d.ts +3 -3
  34. package/build/revivables/utils.d.ts +5 -10
  35. package/build/revivables/writable-stream.d.ts +4 -4
  36. package/build/types.d.ts +12 -4
  37. package/build/utils/event-channel.d.ts +1 -1
  38. package/build/utils/index.d.ts +11 -12
  39. package/build/utils/replace.d.ts +0 -3
  40. package/build/utils/teardown.d.ts +7 -0
  41. package/build/utils/transferable.d.ts +1 -1
  42. package/build/utils/transport.d.ts +13 -15
  43. package/build/utils/type-guards.d.ts +12 -4
  44. package/build/utils/typed-event-target.d.ts +1 -1
  45. package/build/utils/typed-message-channel.d.ts +3 -2
  46. package/package.json +21 -8
@@ -1,6 +1,6 @@
1
- import type { Capable } from '../types';
2
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
3
- import type { BoxedMessagePort } from './message-port';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
+ import type { BoxedMessagePort } from './message-port.js';
4
4
  export declare const type: 'abortSignal';
5
5
  type AbortMessage = {
6
6
  type: 'abort';
@@ -9,7 +9,9 @@ type AbortMessage = {
9
9
  export type BoxedAbortSignal = BoxBaseType<typeof type> & {
10
10
  aborted: boolean;
11
11
  reason?: Capable;
12
- port: BoxedMessagePort<AbortMessage>;
12
+ /** Absent when the signal was already aborted at box time — the reason
13
+ * rides the wrapper and no live channel is needed. */
14
+ port?: BoxedMessagePort<AbortMessage>;
13
15
  };
14
16
  export declare const isType: (value: unknown) => value is AbortSignal;
15
17
  export declare const box: <T extends AbortSignal, T2 extends RevivableContext>(value: T, context: T2) => BoxedAbortSignal;
@@ -1,8 +1,8 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'arrayBuffer';
3
3
  export declare const isType: (value: unknown) => value is ArrayBuffer;
4
4
  export declare const box: <T extends ArrayBuffer, T2 extends RevivableContext>(value: T, context: T2) => {
5
5
  __OSRA_BOX__: 'revivable';
6
6
  type: "arrayBuffer";
7
- } & import("./utils").BoxedBuffer<T2>;
7
+ } & import("./utils.js").BoxedBuffer<T2>;
8
8
  export declare const revive: <T extends ReturnType<typeof box>>(value: T, _context: RevivableContext) => ArrayBuffer;
@@ -0,0 +1,16 @@
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
+ import { BoxedFunction } from './function.js';
4
+ export declare const type: 'asyncIterator';
5
+ type AnyAsyncIterable = {
6
+ [Symbol.asyncIterator]: () => AsyncIterator<unknown>;
7
+ };
8
+ export type BoxedAsyncIterator = BoxBaseType<typeof type> & {
9
+ next: BoxedFunction;
10
+ return: BoxedFunction;
11
+ throw: BoxedFunction;
12
+ };
13
+ export declare const isType: (value: unknown) => value is AnyAsyncIterable;
14
+ export declare const box: <T extends AnyAsyncIterable, T2 extends RevivableContext>(value: T, context: T2) => BoxedAsyncIterator;
15
+ export declare const revive: <T extends BoxedAsyncIterator, T2 extends RevivableContext>(value: T, context: T2) => AsyncIterableIterator<Capable>;
16
+ export {};
@@ -1,4 +1,4 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'bigint';
3
3
  export declare const isType: (value: unknown) => value is bigint;
4
4
  export declare const box: <T extends bigint, T2 extends RevivableContext>(value: T, _context: T2) => {
@@ -1,6 +1,6 @@
1
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
2
- import type { UnderlyingType } from '../utils/type';
3
- import type { BoxedPromise } from './promise';
1
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
2
+ import type { UnderlyingType } from '../utils/type.js';
3
+ import type { BoxedPromise } from './promise.js';
4
4
  export declare const type: 'blob';
5
5
  export type BoxedBlob<T extends Blob = Blob> = BoxBaseType<typeof type> & {
6
6
  mimeType: string;
@@ -1,4 +1,4 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'date';
3
3
  export declare const isType: (value: unknown) => value is Date;
4
4
  export declare const box: <T extends Date, T2 extends RevivableContext>(value: T, _context: T2) => {
@@ -1,11 +1,14 @@
1
- import type { Capable } from '../types';
2
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
3
  export declare const type: 'error';
4
4
  export type BoxedError = BoxBaseType<typeof type> & {
5
5
  name: string;
6
6
  message: string;
7
7
  stack: string;
8
8
  cause?: Capable;
9
+ /** AggregateError only */
10
+ errors?: Capable;
11
+ isDOMException?: boolean;
9
12
  };
10
13
  export declare const isType: (value: unknown) => value is Error;
11
14
  export declare const box: <T extends Error, T2 extends RevivableContext>(value: T, context: T2) => BoxedError;
@@ -1,4 +1,4 @@
1
- import { type RevivableContext } from './utils';
1
+ import { type RevivableContext } from './utils.js';
2
2
  export declare const type: 'eventTarget';
3
3
  type ListenerOpts = boolean | {
4
4
  capture?: boolean;
@@ -10,9 +10,10 @@ export declare const isType: (value: unknown) => value is EventTarget;
10
10
  export declare const box: <T extends EventTarget, T2 extends RevivableContext>(value: T, context: T2) => {
11
11
  __OSRA_BOX__: 'revivable';
12
12
  type: "eventTarget";
13
- addListener: import("./function").BoxedFunction<(type: string, listener: EventListener, options?: ListenerOpts) => void>;
14
- removeListener: import("./function").BoxedFunction<(type: string, listener: EventListener, options?: ListenerOpts) => void>;
13
+ addListener: import("./function.js").BoxedFunction<(eventType: string, listener: EventListener, options?: ListenerOpts) => void>;
14
+ removeListener: import("./function.js").BoxedFunction<(eventType: string, listener: EventListener, options?: ListenerOpts) => void>;
15
+ removeAllListeners: import("./function.js").BoxedFunction<() => void>;
15
16
  };
16
17
  export type BoxedEventTarget = ReturnType<typeof box>;
17
- export declare const revive: <T extends ReturnType<typeof box>, T2 extends RevivableContext>(value: T, context: T2) => EventTarget;
18
+ export declare const revive: <T extends BoxedEventTarget, T2 extends RevivableContext>(value: T, context: T2) => EventTarget;
18
19
  export {};
@@ -1,5 +1,5 @@
1
- import type { Capable } from '../types';
2
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
3
  export declare const type: 'event';
4
4
  /** Boxes Event/CustomEvent only. Subclass-specific fields (MessageEvent.data,
5
5
  * ErrorEvent.error, ProgressEvent.loaded, etc.) are dropped on the wire. */
@@ -1,4 +1,4 @@
1
- import type { BoxBase as BoxBaseType, RevivableContext } from './utils';
1
+ import type { BoxBase as BoxBaseType, RevivableContext } from './utils.js';
2
2
  declare const TYPED_CLONABLE_CTORS: readonly [{
3
3
  new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
4
4
  prototype: File;
@@ -1,7 +1,7 @@
1
- import type { Capable } from '../types';
2
- import type { UnderlyingType, RevivableContext, BoxBase as BoxBaseType } from './utils';
3
- import { type EventPort } from '../utils/event-channel';
4
- import { BoxedMessagePort } from './message-port';
1
+ import type { Capable } from '../types.js';
2
+ import type { UnderlyingType, RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
+ import { type EventPort } from '../utils/event-channel.js';
4
+ import { BoxedMessagePort } from './message-port.js';
5
5
  export declare const type: 'function';
6
6
  type CallContext = [EventPort<Capable>, Capable[]];
7
7
  export type BoxedFunction<T extends (...args: any[]) => any = (...args: any[]) => any> = BoxBaseType<typeof type> & {
@@ -1,4 +1,4 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'headers';
3
3
  export declare const isType: (value: unknown) => value is Headers;
4
4
  export declare const box: <T extends Headers, T2 extends RevivableContext>(value: T, _context: T2) => {
@@ -1,6 +1,6 @@
1
- import type { Capable, Uuid } from '../types';
2
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
3
- import type { UnderlyingType } from '../utils/type';
1
+ import type { Capable, Uuid } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
+ import type { UnderlyingType } from '../utils/type.js';
4
4
  export declare const type: 'identity';
5
5
  export type Messages = {
6
6
  type: 'identity-dispose';
@@ -1,31 +1,32 @@
1
- import type { BoxBase, RevivableContext } from './utils';
2
- import type { DeepReplaceWithBox, DeepReplaceWithRevive, ReplaceWithBox, ReplaceWithRevive } from '../utils/replace';
3
- import type { MessageFields, Capable } from '../types';
4
- import * as arrayBuffer from './array-buffer';
5
- import * as date from './date';
6
- import * as headers from './headers';
7
- import * as error from './error';
8
- import * as typedArray from './typed-array';
9
- import * as promise from './promise';
10
- import * as func from './function';
11
- import * as messagePort from './message-port';
12
- import * as readableStream from './readable-stream';
13
- import * as writableStream from './writable-stream';
14
- import * as abortSignal from './abort-signal';
15
- import * as response from './response';
16
- import * as request from './request';
17
- import * as identity from './identity';
18
- import * as transfer from './transfer';
19
- import * as map from './map';
20
- import * as set from './set';
21
- import * as bigInt from './bigint';
22
- import * as event from './event';
23
- import * as eventTarget from './event-target';
24
- import * as blob from './blob';
25
- import * as symbol from './symbol';
26
- export { identity } from './identity';
27
- export { transfer } from './transfer';
28
- export * from './utils';
1
+ import type { BoxBase, RevivableContext } from './utils.js';
2
+ import type { DeepReplaceWithBox, DeepReplaceWithRevive } from '../utils/replace.js';
3
+ import type { MessageFields, Capable } from '../types.js';
4
+ import * as arrayBuffer from './array-buffer.js';
5
+ import * as date from './date.js';
6
+ import * as headers from './headers.js';
7
+ import * as error from './error.js';
8
+ import * as typedArray from './typed-array.js';
9
+ import * as promise from './promise.js';
10
+ import * as func from './function.js';
11
+ import * as messagePort from './message-port.js';
12
+ import * as readableStream from './readable-stream.js';
13
+ import * as writableStream from './writable-stream.js';
14
+ import * as abortSignal from './abort-signal.js';
15
+ import * as response from './response.js';
16
+ import * as request from './request.js';
17
+ import * as identity from './identity.js';
18
+ import * as transfer from './transfer.js';
19
+ import * as map from './map.js';
20
+ import * as set from './set.js';
21
+ import * as bigInt from './bigint.js';
22
+ import * as event from './event.js';
23
+ import * as eventTarget from './event-target.js';
24
+ import * as blob from './blob.js';
25
+ import * as symbol from './symbol.js';
26
+ import * as asyncIterator from './async-iterator.js';
27
+ export { identity } from './identity.js';
28
+ export { transfer } from './transfer.js';
29
+ export * from './utils.js';
29
30
  export type RevivableModule<T extends string = string, T2 = any, T3 extends BoxBase<T> = any, T4 extends MessageFields = MessageFields> = {
30
31
  readonly type: T;
31
32
  readonly isType: (value: unknown) => value is T2;
@@ -34,27 +35,35 @@ export type RevivableModule<T extends string = string, T2 = any, T3 extends BoxB
34
35
  readonly init?: (context: RevivableContext<any>) => void;
35
36
  readonly Messages?: T4;
36
37
  };
37
- export declare const defaultRevivableModules: readonly [typeof transfer, typeof identity, typeof arrayBuffer, typeof date, typeof headers, typeof error, typeof typedArray, typeof blob, typeof promise, typeof func, typeof messagePort, typeof readableStream, typeof writableStream, typeof abortSignal, typeof response, typeof request, typeof map, typeof set, typeof bigInt, typeof symbol, typeof event, {
38
+ export declare const defaultRevivableModules: readonly [typeof transfer, typeof identity, typeof arrayBuffer, typeof date, typeof headers, typeof error, typeof typedArray, typeof blob, typeof promise, typeof func, typeof messagePort, typeof readableStream, typeof writableStream, typeof abortSignal, typeof response, typeof request, typeof map, typeof set, typeof bigInt, typeof symbol, typeof event, typeof asyncIterator, {
39
+ readonly type: 'nonFiniteNumber';
40
+ readonly isType: (value: unknown) => value is number;
41
+ readonly box: (value: number, context: RevivableContext<any>) => import("./json-primitives.js").BoxedNonFiniteNumber | number;
42
+ readonly revive: (value: import("./json-primitives.js").BoxedNonFiniteNumber, _context: RevivableContext<any>) => number;
43
+ }, {
44
+ readonly type: 'undefined';
45
+ readonly isType: (value: unknown) => value is undefined;
46
+ readonly box: (value: undefined, context: RevivableContext<any>) => import("./json-primitives.js").BoxedUndefined | undefined;
47
+ readonly revive: (_value: import("./json-primitives.js").BoxedUndefined, _context: RevivableContext<any>) => undefined;
48
+ }, {
38
49
  readonly type: 'clonable';
39
50
  readonly capableOnly: true;
40
- readonly isType: (value: unknown) => value is import("./fallbacks").Clonable;
41
- readonly box: (value: import("./fallbacks").Clonable, _context: RevivableContext<any>) => import("./fallbacks").Clonable;
42
- readonly revive: (value: import("./fallbacks").BoxedClonable, _context: RevivableContext<any>) => import("./fallbacks").Clonable;
51
+ readonly isType: (value: unknown) => value is import("./fallbacks.js").Clonable;
52
+ readonly box: (value: import("./fallbacks.js").Clonable, _context: RevivableContext<any>) => import("./fallbacks.js").Clonable;
53
+ readonly revive: (value: import("./fallbacks.js").BoxedClonable, _context: RevivableContext<any>) => import("./fallbacks.js").Clonable;
43
54
  }, {
44
55
  readonly type: 'transferable';
45
56
  readonly capableOnly: true;
46
- readonly isType: (value: unknown) => value is import("./fallbacks").Transferable;
47
- readonly box: (value: import("./fallbacks").Transferable, _context: RevivableContext<any>) => import("./fallbacks").Transferable;
48
- readonly revive: (value: import("./fallbacks").BoxedTransferable, _context: RevivableContext<any>) => import("./fallbacks").Transferable;
57
+ readonly isType: (value: unknown) => value is import("./fallbacks.js").Transferable;
58
+ readonly box: (value: import("./fallbacks.js").Transferable, _context: RevivableContext<any>) => import("./fallbacks.js").Transferable;
59
+ readonly revive: (value: import("./fallbacks.js").BoxedTransferable, _context: RevivableContext<any>) => import("./fallbacks.js").Transferable;
49
60
  }, typeof eventTarget, {
50
61
  readonly type: 'unclonable';
51
62
  readonly isType: (value: unknown) => value is never;
52
- readonly box: (_value: never, _context: RevivableContext<any>) => import("./fallbacks").BoxedUnclonable;
53
- readonly revive: (_value: import("./fallbacks").BoxedUnclonable, _context: RevivableContext<any>) => Record<string, never>;
63
+ readonly box: (_value: never, _context: RevivableContext<any>) => import("./fallbacks.js").BoxedUnclonable;
64
+ readonly revive: (_value: import("./fallbacks.js").BoxedUnclonable, _context: RevivableContext<any>) => Record<string, never>;
54
65
  }];
55
66
  export type DefaultRevivableModules = typeof defaultRevivableModules;
56
67
  export type DefaultRevivableModule = DefaultRevivableModules[number];
57
- export declare const box: <T extends Capable, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>) => ReplaceWithBox<T, TModules[number]>;
58
68
  export declare const recursiveBox: <T extends Capable, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>) => DeepReplaceWithBox<T, TModules[number]>;
59
- export declare const revive: <T extends ReturnType<typeof box>, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>) => ReplaceWithRevive<T, TModules[number]>;
60
69
  export declare const recursiveRevive: <T extends Capable, TModules extends readonly RevivableModule[]>(value: T, context: RevivableContext<TModules>) => DeepReplaceWithRevive<T, TModules[number]>;
@@ -0,0 +1,17 @@
1
+ import type { BoxBase as BoxBaseType, RevivableContext } from './utils.js';
2
+ export type BoxedNonFiniteNumber = BoxBaseType<'nonFiniteNumber'> & {
3
+ value: 'NaN' | 'Infinity' | '-Infinity';
4
+ };
5
+ export declare const nonFiniteNumber: {
6
+ readonly type: 'nonFiniteNumber';
7
+ readonly isType: (value: unknown) => value is number;
8
+ readonly box: (value: number, context: RevivableContext<any>) => BoxedNonFiniteNumber | number;
9
+ readonly revive: (value: BoxedNonFiniteNumber, _context: RevivableContext<any>) => number;
10
+ };
11
+ export type BoxedUndefined = BoxBaseType<'undefined'>;
12
+ export declare const undefinedValue: {
13
+ readonly type: 'undefined';
14
+ readonly isType: (value: unknown) => value is undefined;
15
+ readonly box: (value: undefined, context: RevivableContext<any>) => BoxedUndefined | undefined;
16
+ readonly revive: (_value: BoxedUndefined, _context: RevivableContext<any>) => undefined;
17
+ };
@@ -1,5 +1,5 @@
1
- import type { Capable } from '../types';
2
- import type { RevivableContext, UnderlyingType, BoxBase as BoxBaseType } from './utils';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, UnderlyingType, BoxBase as BoxBaseType } from './utils.js';
3
3
  export declare const type: 'map';
4
4
  export type BoxedMap<T extends Map<Capable, Capable> = Map<Capable, Capable>> = BoxBaseType<typeof type> & {
5
5
  entries: Array<[Capable, Capable]>;
@@ -1,9 +1,9 @@
1
- import type { Capable, StructurableTransferable, Uuid } from '../types';
2
- import type { TypedMessagePort } from '../utils/typed-message-channel';
3
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
4
- import type { UnderlyingType } from '../utils/type';
5
- import type { BadFieldValue, BadFieldPath, BadFieldParent, ErrorMessage, BadValue, Path, ParentObject } from '../utils/capable-check';
6
- import { EventPort } from '../utils/event-channel';
1
+ import type { Capable, StructurableTransferable, Uuid } from '../types.js';
2
+ import type { TypedMessagePort } from '../utils/typed-message-channel.js';
3
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
4
+ import type { UnderlyingType } from '../utils/type.js';
5
+ import type { BadFieldValue, BadFieldPath, BadFieldParent, ErrorMessage, BadValue, Path, ParentObject } from '../utils/capable-check.js';
6
+ import { EventPort } from '../utils/event-channel.js';
7
7
  export declare const type: 'messagePort';
8
8
  export type Messages = {
9
9
  type: 'message';
@@ -1,8 +1,8 @@
1
- import type { Capable } from '../types';
2
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
3
- import type { UnderlyingType } from '.';
4
- import type { BadFieldValue, BadFieldPath, BadFieldParent, ErrorMessage, BadValue, Path, ParentObject } from '../utils/capable-check';
5
- import { BoxedMessagePort } from './message-port';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
+ import type { UnderlyingType } from './index.js';
4
+ import type { BadFieldValue, BadFieldPath, BadFieldParent, ErrorMessage, BadValue, Path, ParentObject } from '../utils/capable-check.js';
5
+ import { BoxedMessagePort } from './message-port.js';
6
6
  export declare const type: 'promise';
7
7
  export type Context = {
8
8
  type: 'resolve';
@@ -1,9 +1,13 @@
1
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
2
- import type { UnderlyingType } from '.';
3
- import { BoxedMessagePort } from './message-port';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
3
+ import type { UnderlyingType } from './index.js';
4
+ import { BoxedMessagePort } from './message-port.js';
4
5
  export declare const type: 'readableStream';
5
6
  export type PullContext = {
6
- type: 'pull' | 'cancel';
7
+ type: 'pull';
8
+ } | {
9
+ type: 'cancel';
10
+ reason?: Capable;
7
11
  };
8
12
  type ChunkMessage<T = unknown> = Promise<ReadableStreamReadResult<T>>;
9
13
  type Msg = PullContext | ChunkMessage;
@@ -1,4 +1,4 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'request';
3
3
  export declare const isType: (value: unknown) => value is Request;
4
4
  export declare const box: <T extends Request, T2 extends RevivableContext>(value: T, context: T2) => {
@@ -11,13 +11,15 @@ export declare const box: <T extends Request, T2 extends RevivableContext>(value
11
11
  type: "headers";
12
12
  entries: [string, string][];
13
13
  };
14
- body: import("./readable-stream").BoxedReadableStream<ReadableStream<Uint8Array<ArrayBuffer>>> | null;
14
+ body: import("./readable-stream.js").BoxedReadableStream<ReadableStream<Uint8Array<ArrayBuffer>>> | null;
15
15
  credentials: RequestCredentials;
16
16
  cache: RequestCache;
17
+ mode: RequestMode;
17
18
  redirect: RequestRedirect;
18
19
  referrer: string;
19
20
  referrerPolicy: ReferrerPolicy;
20
21
  integrity: string;
21
22
  keepalive: boolean;
23
+ signal: import("./abort-signal.js").BoxedAbortSignal;
22
24
  };
23
25
  export declare const revive: <T extends ReturnType<typeof box>, T2 extends RevivableContext>(value: T, context: T2) => Request;
@@ -1,4 +1,4 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'response';
3
3
  export declare const isType: (value: unknown) => value is Response;
4
4
  export declare const box: <T extends Response, T2 extends RevivableContext>(value: T, context: T2) => {
@@ -11,7 +11,7 @@ export declare const box: <T extends Response, T2 extends RevivableContext>(valu
11
11
  type: "headers";
12
12
  entries: [string, string][];
13
13
  };
14
- body: import("./readable-stream").BoxedReadableStream<ReadableStream<Uint8Array<ArrayBuffer>>> | null;
14
+ body: import("./readable-stream.js").BoxedReadableStream<ReadableStream<Uint8Array<ArrayBuffer>>> | null;
15
15
  url: string;
16
16
  redirected: boolean;
17
17
  };
@@ -1,5 +1,5 @@
1
- import type { Capable } from '../types';
2
- import type { RevivableContext, UnderlyingType, BoxBase as BoxBaseType } from './utils';
1
+ import type { Capable } from '../types.js';
2
+ import type { RevivableContext, UnderlyingType, BoxBase as BoxBaseType } from './utils.js';
3
3
  export declare const type: 'set';
4
4
  export type BoxedSet<T extends Set<Capable> = Set<Capable>> = BoxBaseType<typeof type> & {
5
5
  values: Array<Capable>;
@@ -1,11 +1,13 @@
1
- import type { RevivableContext } from './utils';
1
+ import type { RevivableContext } from './utils.js';
2
2
  export declare const type: 'symbol';
3
3
  export declare const isType: (value: unknown) => value is symbol;
4
4
  export declare const box: <T extends symbol, T2 extends RevivableContext>(value: T, context: T2) => {
5
5
  __OSRA_BOX__: 'revivable';
6
6
  type: "symbol";
7
- description: string | undefined;
8
- } | import("./identity").BoxedIdentity<import("..").Capable>;
7
+ registryKey: string;
8
+ } | import("./identity.js").BoxedIdentity<import("../types.js").Capable>;
9
9
  export declare const revive: <T extends {
10
+ registryKey: string;
11
+ } | {
10
12
  description: string | undefined;
11
13
  }, T2 extends RevivableContext>(value: T, _context: T2) => symbol;
@@ -1,5 +1,5 @@
1
- import type { Capable } from '../types';
2
- import type { BoxBase as BoxBaseType, RevivableContext, UnderlyingType } from './utils';
1
+ import type { Capable } from '../types.js';
2
+ import type { BoxBase as BoxBaseType, RevivableContext, UnderlyingType } from './utils.js';
3
3
  export declare const type: 'transfer';
4
4
  declare const TRANSFER_MARKER: unique symbol;
5
5
  type TransferWrapper<T = unknown> = {
@@ -1,6 +1,6 @@
1
- import type { RevivableContext, UnderlyingType, BoxedBuffer } from './utils';
2
- import type { TypedArray, TypedArrayType } from '../utils/type-guards';
3
- import { BoxBase } from './utils';
1
+ import type { RevivableContext, UnderlyingType, BoxedBuffer } from './utils.js';
2
+ import type { TypedArray, TypedArrayType } from '../utils/type-guards.js';
3
+ import { BoxBase } from './utils.js';
4
4
  export declare const type: 'typedArray';
5
5
  type BoxedTypedArray<T extends TypedArray, T2 extends RevivableContext> = typeof BoxBase & {
6
6
  type: typeof type;
@@ -1,8 +1,8 @@
1
- import type { DefaultRevivableModules, RevivableModule } from '.';
2
- import type { MessageEventTarget, MessageFields, Uuid } from '../types';
3
- import type { Transport } from '../utils/transport';
4
- import type { IsJsonOnlyTransport } from '../utils/type-guards';
5
- export type { UnderlyingType } from '../utils/type';
1
+ import type { DefaultRevivableModules, RevivableModule } from './index.js';
2
+ import type { MessageEventTarget, MessageFields, Uuid } from '../types.js';
3
+ import type { Transport } from '../utils/transport.js';
4
+ import type { IsJsonOnlyTransport } from '../utils/type-guards.js';
5
+ export type { UnderlyingType } from '../utils/type.js';
6
6
  export declare const BoxBase: {
7
7
  readonly __OSRA_BOX__: 'revivable';
8
8
  };
@@ -12,7 +12,6 @@ export type BoxBase<T extends string = string> = typeof BoxBase & {
12
12
  export type RevivableContext<TModules extends readonly RevivableModule[] = DefaultRevivableModules> = {
13
13
  transport: Transport;
14
14
  remoteUuid: Uuid;
15
- unregisterSignal?: AbortSignal;
16
15
  /** Typed as a broad dispatcher so revivables can post their own message
17
16
  * variants without triggering contravariant function-parameter mismatches
18
17
  * across modules. The shape is enforced structurally via `MessageFields`. */
@@ -30,9 +29,6 @@ export type ExtractType<T, Ctx extends RevivableContext = RevivableContext> = T
30
29
  } ? S : never : T extends {
31
30
  isType: (value: unknown) => value is infer S;
32
31
  } ? S : never;
33
- export type ExtractBox<T> = T extends {
34
- box: (...args: any[]) => infer B;
35
- } ? B : never;
36
32
  export type ExtractMessages<T> = T extends {
37
33
  Messages?: infer B;
38
34
  } ? B extends {
@@ -40,7 +36,6 @@ export type ExtractMessages<T> = T extends {
40
36
  } ? string extends B['type'] ? never : B : never : never;
41
37
  export type InferMessages<TModules extends readonly unknown[]> = ExtractMessages<TModules[number]>;
42
38
  export type InferRevivables<TModules extends readonly unknown[], Ctx extends RevivableContext = RevivableContext> = ExtractType<TModules[number], Ctx>;
43
- export type InferRevivableBox<TModules extends readonly unknown[]> = ExtractBox<TModules[number]>;
44
39
  export declare const isRevivableBox: (value: unknown) => value is BoxBase;
45
40
  /** Wire shape for an ArrayBuffer: base64 on JSON, raw on clone. */
46
41
  export type BoxedBuffer<TCtx extends RevivableContext = RevivableContext> = IsJsonOnlyTransport<TCtx['transport']> extends true ? {
@@ -1,7 +1,7 @@
1
- import type { RevivableContext, BoxBase as BoxBaseType } from './utils';
2
- import type { UnderlyingType } from '.';
3
- import type { Capable } from '../types';
4
- import { BoxedMessagePort } from './message-port';
1
+ import type { RevivableContext, BoxBase as BoxBaseType } from './utils.js';
2
+ import type { UnderlyingType } from './index.js';
3
+ import type { Capable } from '../types.js';
4
+ import { BoxedMessagePort } from './message-port.js';
5
5
  export declare const type: 'writableStream';
6
6
  export type WriteContext = {
7
7
  type: 'write';
package/build/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ConnectionMessage } from './connections';
2
- import type { TypedEventTarget } from './utils';
3
- import type { IsJsonOnlyTransport } from './utils/type-guards';
4
- import type { DefaultRevivableModules, RevivableModule, InferMessages, InferRevivables, RevivableContext } from './revivables';
1
+ import type { ConnectionMessage } from './connections/index.js';
2
+ import type { TypedEventTarget } from './utils/typed-event-target.js';
3
+ import type { IsJsonOnlyTransport } from './utils/type-guards.js';
4
+ import type { DefaultRevivableModules, RevivableModule, InferMessages, InferRevivables, RevivableContext } from './revivables/index.js';
5
5
  export declare const OSRA_KEY: '__OSRA_KEY__';
6
6
  export declare const OSRA_DEFAULT_KEY: '__OSRA_DEFAULT_KEY__';
7
7
  export declare const OSRA_BOX: '__OSRA_BOX__';
@@ -25,6 +25,14 @@ type CapableBase<Ctx extends RevivableContext> = IsJsonOnlyTransport<Ctx['transp
25
25
  export type Capable<TModules extends readonly RevivableModule[] = DefaultRevivableModules, Ctx extends RevivableContext = RevivableContext> = CapableBase<Ctx> | InferRevivables<TModules, Ctx> | {
26
26
  [key: string]: Capable<TModules, Ctx>;
27
27
  } | Array<Capable<TModules, Ctx>> | Map<Capable<TModules, Ctx>, Capable<TModules, Ctx>> | Set<Capable<TModules, Ctx>>;
28
+ /** What a value looks like from the far side of the connection: functions
29
+ * become async (calls cross the wire), Blobs arrive as Promise<Blob>,
30
+ * containers map recursively, 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 Blob ? Promise<T> : T extends Promise<infer U> ? Promise<Remote<U>> : T extends Map<any, any> | Set<any> | Date | Error | RegExp | ArrayBuffer | ArrayBufferView | ReadableStream | WritableStream | MessagePort | EventTarget | Request | Response | Headers ? T : T extends AsyncIterable<infer U> ? AsyncIterableIterator<Remote<U>> : T extends ReadonlyArray<unknown> ? {
32
+ [K in keyof T]: Remote<T[K]>;
33
+ } : T extends object ? {
34
+ [K in keyof T]: Remote<T[K]>;
35
+ } : T;
28
36
  export type MessageFields = {
29
37
  type: string;
30
38
  remoteUuid: Uuid;
@@ -1,4 +1,4 @@
1
- import type { TypedMessagePort, TypedMessagePortEventMap } from './typed-message-channel';
1
+ import type { TypedMessagePort, TypedMessagePortEventMap } from './typed-message-channel.js';
2
2
  export declare class EventPort<T> extends EventTarget {
3
3
  addEventListener<K extends keyof TypedMessagePortEventMap<T> & string>(type: K, listener: ((event: TypedMessagePortEventMap<T>[K]) => void) | null, options?: boolean | AddEventListenerOptions): void;
4
4
  addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
@@ -1,12 +1,11 @@
1
- export * from './transport';
2
- export * from '../revivables';
3
- export * from './replace';
4
- export * from '../connections';
5
- export * from './transferable';
6
- export * from './type-guards';
7
- export * from './typed-event-target';
8
- export * from './typed-message-channel';
9
- export * from './event-channel';
10
- export * from './type';
11
- export * from './capable-check';
12
- export * from './gc-tracker';
1
+ export * from './transport.js';
2
+ export * from './replace.js';
3
+ export * from './transferable.js';
4
+ export * from './type-guards.js';
5
+ export * from './typed-event-target.js';
6
+ export * from './typed-message-channel.js';
7
+ export * from './event-channel.js';
8
+ export * from './type.js';
9
+ export * from './capable-check.js';
10
+ export * from './gc-tracker.js';
11
+ export * from './teardown.js';
@@ -14,9 +14,6 @@ type FindMatchingRevive<T, M> = M extends {
14
14
  box: (...args: any[]) => infer S;
15
15
  revive: (...args: any[]) => infer R;
16
16
  } ? T extends S ? R : never : never;
17
- export type ReplaceWithRevive<T, M> = [
18
- FindMatchingRevive<T, M>
19
- ] extends [never] ? T : FindMatchingRevive<T, M>;
20
17
  export type DeepReplaceWithRevive<T, M> = [
21
18
  FindMatchingRevive<T, M>
22
19
  ] extends [never] ? T extends Array<infer U> ? Array<DeepReplaceWithRevive<U, M>> : T extends object ? {
@@ -0,0 +1,7 @@
1
+ /** Per-connection teardown registry. Revivables register cleanup for state
2
+ * tied to a connection (pending RPC settlements, port routing, caches);
3
+ * the connection layer runs it on protocol close or unregisterSignal abort.
4
+ * Registering against an already-torn-down scope runs the callback
5
+ * immediately so late registrations fail fast instead of leaking. */
6
+ export declare const onTeardown: (scope: WeakKey, fn: () => void) => (() => void);
7
+ export declare const runTeardown: (scope: WeakKey) => void;
@@ -1,4 +1,4 @@
1
- import { transfer } from '../revivables/transfer';
1
+ import { transfer } from '../revivables/transfer.js';
2
2
  export { transfer };
3
3
  /** Walk a boxed message and collect Transferables to move (rather than copy)
4
4
  * on postMessage: