@xconnio/xconn 0.0.0-stage → 0.6.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +22 -0
  3. package/README.md +281 -2
  4. package/dist/auth.d.ts +51 -0
  5. package/dist/auth.js +57 -0
  6. package/dist/call.d.ts +38 -0
  7. package/dist/call.js +146 -0
  8. package/dist/client.d.ts +21 -0
  9. package/dist/client.js +62 -0
  10. package/dist/constants.d.ts +60 -0
  11. package/dist/constants.js +61 -0
  12. package/dist/crypto.d.ts +9 -0
  13. package/dist/crypto.js +25 -0
  14. package/dist/discovery.d.ts +20 -0
  15. package/dist/discovery.js +25 -0
  16. package/dist/exception.d.ts +12 -0
  17. package/dist/exception.js +28 -0
  18. package/dist/inbox.d.ts +14 -0
  19. package/dist/inbox.js +71 -0
  20. package/dist/index.d.ts +26 -0
  21. package/dist/index.js +15 -0
  22. package/dist/message.d.ts +33 -0
  23. package/dist/message.js +59 -0
  24. package/dist/native.d.ts +6 -0
  25. package/dist/native.js +35 -0
  26. package/dist/package.json +1 -0
  27. package/dist/payload.d.ts +48 -0
  28. package/dist/payload.js +314 -0
  29. package/dist/peer.d.ts +16 -0
  30. package/dist/peer.js +124 -0
  31. package/dist/requests.d.ts +57 -0
  32. package/dist/requests.js +121 -0
  33. package/dist/rpc-streams.d.ts +13 -0
  34. package/dist/rpc-streams.js +31 -0
  35. package/dist/serializers.d.ts +29 -0
  36. package/dist/serializers.js +44 -0
  37. package/dist/session.d.ts +67 -0
  38. package/dist/session.js +528 -0
  39. package/dist/toolchain.txt +3 -0
  40. package/dist/transport.d.ts +47 -0
  41. package/dist/transport.js +201 -0
  42. package/dist/types.d.ts +70 -0
  43. package/dist/types.js +140 -0
  44. package/dist/util.d.ts +2 -0
  45. package/dist/util.js +20 -0
  46. package/dist/wasm/xconn_browser.d.ts +176 -0
  47. package/dist/wasm/xconn_browser.js +1467 -0
  48. package/dist/wasm/xconn_browser_bg.wasm +0 -0
  49. package/dist/wasm/xconn_browser_bg.wasm.d.ts +53 -0
  50. package/dist/webrtc.d.ts +98 -0
  51. package/dist/webrtc.js +712 -0
  52. package/dist/webtransport.d.ts +31 -0
  53. package/dist/webtransport.js +242 -0
  54. package/package.json +48 -4
package/dist/client.js ADDED
@@ -0,0 +1,62 @@
1
+ import { AnonymousAuthenticator, TicketAuthenticator, WAMPCRAAuthenticator, CryptoSignAuthenticator } from "./auth.js";
2
+ import { getSubProtocol } from "./serializers.js";
3
+ import { ProtocolError } from "./exception.js";
4
+ import { SocketInbox, sendPayload } from "./transport.js";
5
+ import { connectPeer } from "./peer.js";
6
+ import { abortable } from "./util.js";
7
+ export class Client {
8
+ options;
9
+ constructor(options = {}) {
10
+ this.options = options;
11
+ }
12
+ connect(uri, realm) {
13
+ return connect(uri, realm, this.options);
14
+ }
15
+ }
16
+ export async function connect(uri, realm, options = {}) {
17
+ return connectPeer(async (serializer, signal) => {
18
+ const subprotocol = getSubProtocol(serializer);
19
+ const socket = options.webSocketFactory?.(uri, [subprotocol]) ?? new WebSocket(uri, [subprotocol]);
20
+ const inbox = new SocketInbox(socket);
21
+ try {
22
+ await abortable(inbox.opened, signal);
23
+ if (socket.protocol !== subprotocol) {
24
+ throw new ProtocolError("Router did not negotiate the requested WAMP subprotocol");
25
+ }
26
+ return {
27
+ send: (data) => sendPayload(socket, data),
28
+ receive: () => inbox.receive(),
29
+ onDisconnect: (callback) => inbox.onDisconnect(callback),
30
+ isConnected: () => inbox.connected(),
31
+ close: async () => {
32
+ inbox.stop(new ProtocolError("Connection closed"));
33
+ if (socket.readyState < WebSocket.CLOSING) {
34
+ socket.close();
35
+ }
36
+ },
37
+ };
38
+ }
39
+ catch (error) {
40
+ inbox.stop(new ProtocolError("Connection setup failed"));
41
+ if (socket.readyState < WebSocket.CLOSING) {
42
+ socket.close();
43
+ }
44
+ throw error;
45
+ }
46
+ }, realm, options);
47
+ }
48
+ export function connectAnonymous(uri, realm) {
49
+ return connect(uri, realm);
50
+ }
51
+ export function connectTicket(uri, realm, authid, ticket) {
52
+ const authenticator = new TicketAuthenticator(authid, ticket, null);
53
+ return connect(uri, realm, { authenticator }).finally(() => authenticator.free());
54
+ }
55
+ export function connectCRA(uri, realm, authid, secret) {
56
+ const authenticator = new WAMPCRAAuthenticator(authid, secret, null);
57
+ return connect(uri, realm, { authenticator }).finally(() => authenticator.free());
58
+ }
59
+ export function connectCryptosign(uri, realm, authid, key) {
60
+ const authenticator = new CryptoSignAuthenticator(authid, key, {});
61
+ return connect(uri, realm, { authenticator }).finally(() => authenticator.free());
62
+ }
@@ -0,0 +1,60 @@
1
+ export declare const Code: {
2
+ readonly HELLO: 1;
3
+ readonly WELCOME: 2;
4
+ readonly ABORT: 3;
5
+ readonly CHALLENGE: 4;
6
+ readonly AUTHENTICATE: 5;
7
+ readonly GOODBYE: 6;
8
+ readonly ERROR: 8;
9
+ readonly PUBLISH: 16;
10
+ readonly PUBLISHED: 17;
11
+ readonly SUBSCRIBE: 32;
12
+ readonly SUBSCRIBED: 33;
13
+ readonly UNSUBSCRIBE: 34;
14
+ readonly UNSUBSCRIBED: 35;
15
+ readonly EVENT: 36;
16
+ readonly CALL: 48;
17
+ readonly CANCEL: 49;
18
+ readonly RESULT: 50;
19
+ readonly REGISTER: 64;
20
+ readonly REGISTERED: 65;
21
+ readonly UNREGISTER: 66;
22
+ readonly UNREGISTERED: 67;
23
+ readonly INVOCATION: 68;
24
+ readonly INTERRUPT: 69;
25
+ readonly YIELD: 70;
26
+ };
27
+ export declare const URI: {
28
+ readonly INVALID_ARGUMENT: "wamp.error.invalid_argument";
29
+ readonly PROCEDURE_ALREADY_EXISTS: "wamp.error.procedure_already_exists";
30
+ readonly INVALID_URI: "wamp.error.invalid_uri";
31
+ readonly AUTHENTICATION_FAILED: "wamp.error.authentication_failed";
32
+ readonly CLOSE_REALM: "wamp.close.close_realm";
33
+ readonly CLOSE_GOOD_BYE_AND_OUT: "wamp.close.goodbye_and_out";
34
+ readonly CLOSE_SYSTEM_SHUTDOWN: "wamp.close.system_shutdown";
35
+ readonly CLOSE_KILLED: "wamp.close.killed";
36
+ readonly NO_MATCHING_AUTH_METHOD: "wamp.error.no_matching_auth_method";
37
+ readonly NO_SUCH_REALM: "wamp.error.no_such_realm";
38
+ readonly NO_SUCH_ROLE: "wamp.error.no_such_role";
39
+ readonly NO_SUCH_PRINCIPAL: "wamp.error.no_such_principal";
40
+ readonly NO_SUCH_SESSION: "wamp.error.no_such_session";
41
+ readonly AUTHENTICATION_DENIED: "wamp.error.authentication_denied";
42
+ readonly AUTHENTICATION_REQUIRED: "wamp.error.authentication_required";
43
+ readonly AUTHORIZATION_DENIED: "wamp.error.authorization_denied";
44
+ readonly AUTHORIZATION_FAILED: "wamp.error.authorization_failed";
45
+ readonly AUTHORIZATION_REQUIRED: "wamp.error.authorization_required";
46
+ readonly TIMEOUT: "wamp.error.timeout";
47
+ readonly OPTION_NOT_ALLOWED: "wamp.error.option_not_allowed";
48
+ readonly OPTION_DISALLOWED_DISCLOSE_ME: "wamp.error.option_disallowed.disclose_me";
49
+ readonly NETWORK_FAILURE: "wamp.error.network_failure";
50
+ readonly UNAVAILABLE: "wamp.error.unavailable";
51
+ readonly NO_AVAILABLE_CALLEE: "wamp.error.no_available_callee";
52
+ readonly FEATURE_NOT_SUPPORTED: "wamp.error.feature_not_supported";
53
+ readonly NO_SUCH_PROCEDURE: "wamp.error.no_such_procedure";
54
+ readonly NO_SUCH_REGISTRATION: "wamp.error.no_such_registration";
55
+ readonly NO_SUCH_SUBSCRIPTION: "wamp.error.no_such_subscription";
56
+ readonly CANCELED: "wamp.error.canceled";
57
+ readonly PAYLOAD_SIZE_EXCEEDED: "wamp.error.payload_size_exceeded";
58
+ readonly PROTOCOL_VIOLATION: "wamp.error.protocol_violation";
59
+ readonly NOT_AUTHORIZED: "wamp.error.not_authorized";
60
+ };
@@ -0,0 +1,61 @@
1
+ // Generated from the Rust WAMP schema and URIs. Do not edit.
2
+ export const Code = {
3
+ HELLO: 1,
4
+ WELCOME: 2,
5
+ ABORT: 3,
6
+ CHALLENGE: 4,
7
+ AUTHENTICATE: 5,
8
+ GOODBYE: 6,
9
+ ERROR: 8,
10
+ PUBLISH: 16,
11
+ PUBLISHED: 17,
12
+ SUBSCRIBE: 32,
13
+ SUBSCRIBED: 33,
14
+ UNSUBSCRIBE: 34,
15
+ UNSUBSCRIBED: 35,
16
+ EVENT: 36,
17
+ CALL: 48,
18
+ CANCEL: 49,
19
+ RESULT: 50,
20
+ REGISTER: 64,
21
+ REGISTERED: 65,
22
+ UNREGISTER: 66,
23
+ UNREGISTERED: 67,
24
+ INVOCATION: 68,
25
+ INTERRUPT: 69,
26
+ YIELD: 70,
27
+ };
28
+ export const URI = {
29
+ INVALID_ARGUMENT: "wamp.error.invalid_argument",
30
+ PROCEDURE_ALREADY_EXISTS: "wamp.error.procedure_already_exists",
31
+ INVALID_URI: "wamp.error.invalid_uri",
32
+ AUTHENTICATION_FAILED: "wamp.error.authentication_failed",
33
+ CLOSE_REALM: "wamp.close.close_realm",
34
+ CLOSE_GOOD_BYE_AND_OUT: "wamp.close.goodbye_and_out",
35
+ CLOSE_SYSTEM_SHUTDOWN: "wamp.close.system_shutdown",
36
+ CLOSE_KILLED: "wamp.close.killed",
37
+ NO_MATCHING_AUTH_METHOD: "wamp.error.no_matching_auth_method",
38
+ NO_SUCH_REALM: "wamp.error.no_such_realm",
39
+ NO_SUCH_ROLE: "wamp.error.no_such_role",
40
+ NO_SUCH_PRINCIPAL: "wamp.error.no_such_principal",
41
+ NO_SUCH_SESSION: "wamp.error.no_such_session",
42
+ AUTHENTICATION_DENIED: "wamp.error.authentication_denied",
43
+ AUTHENTICATION_REQUIRED: "wamp.error.authentication_required",
44
+ AUTHORIZATION_DENIED: "wamp.error.authorization_denied",
45
+ AUTHORIZATION_FAILED: "wamp.error.authorization_failed",
46
+ AUTHORIZATION_REQUIRED: "wamp.error.authorization_required",
47
+ TIMEOUT: "wamp.error.timeout",
48
+ OPTION_NOT_ALLOWED: "wamp.error.option_not_allowed",
49
+ OPTION_DISALLOWED_DISCLOSE_ME: "wamp.error.option_disallowed.disclose_me",
50
+ NETWORK_FAILURE: "wamp.error.network_failure",
51
+ UNAVAILABLE: "wamp.error.unavailable",
52
+ NO_AVAILABLE_CALLEE: "wamp.error.no_available_callee",
53
+ FEATURE_NOT_SUPPORTED: "wamp.error.feature_not_supported",
54
+ NO_SUCH_PROCEDURE: "wamp.error.no_such_procedure",
55
+ NO_SUCH_REGISTRATION: "wamp.error.no_such_registration",
56
+ NO_SUCH_SUBSCRIPTION: "wamp.error.no_such_subscription",
57
+ CANCELED: "wamp.error.canceled",
58
+ PAYLOAD_SIZE_EXCEEDED: "wamp.error.payload_size_exceeded",
59
+ PROTOCOL_VIOLATION: "wamp.error.protocol_violation",
60
+ NOT_AUTHORIZED: "wamp.error.not_authorized",
61
+ };
@@ -0,0 +1,9 @@
1
+ /** Peer-key trust is supplied by the application. All cryptography runs in Rust/WASM. */
2
+ export declare function generateKeyPair(): {
3
+ publicKey: Uint8Array;
4
+ privateKey: Uint8Array;
5
+ };
6
+ export declare function sharedSecret(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
7
+ export declare function deriveKey(secret: Uint8Array, info: Uint8Array): Uint8Array;
8
+ export declare function encrypt(plaintext: Uint8Array, key: Uint8Array, additionalData?: Uint8Array<ArrayBuffer>): Uint8Array;
9
+ export declare function decrypt(packet: Uint8Array, key: Uint8Array, additionalData?: Uint8Array<ArrayBuffer>): Uint8Array;
package/dist/crypto.js ADDED
@@ -0,0 +1,25 @@
1
+ import { getNative, rustCall } from "./native.js";
2
+ import { ProtocolError } from "./exception.js";
3
+ function packetCrypto() {
4
+ const api = getNative().PacketCrypto;
5
+ if (!api)
6
+ throw new ProtocolError("Packet encryption is not included in this WASM build");
7
+ return api;
8
+ }
9
+ /** Peer-key trust is supplied by the application. All cryptography runs in Rust/WASM. */
10
+ export function generateKeyPair() {
11
+ const pair = rustCall(() => packetCrypto().key_pair());
12
+ return { publicKey: pair.public, privateKey: pair.private };
13
+ }
14
+ export function sharedSecret(privateKey, publicKey) {
15
+ return rustCall(() => packetCrypto().shared_secret(privateKey, publicKey));
16
+ }
17
+ export function deriveKey(secret, info) {
18
+ return rustCall(() => packetCrypto().derive_key(secret, info));
19
+ }
20
+ export function encrypt(plaintext, key, additionalData = new Uint8Array()) {
21
+ return rustCall(() => packetCrypto().encrypt(plaintext, key, additionalData));
22
+ }
23
+ export function decrypt(packet, key, additionalData = new Uint8Array()) {
24
+ return rustCall(() => packetCrypto().decrypt(packet, key, additionalData));
25
+ }
@@ -0,0 +1,20 @@
1
+ import type { Session } from "./session.js";
2
+ import type { CallControl } from "./types.js";
3
+ /** Connection hints and capabilities, without secret credentials. */
4
+ export interface Endpoint {
5
+ id: string;
6
+ addresses: string[];
7
+ capabilities: string[];
8
+ metadata: Record<string, unknown>;
9
+ }
10
+ /** Uses the same WAMP service contract as the native Rust discovery client. */
11
+ export declare class Discovery {
12
+ private readonly session;
13
+ private readonly prefix;
14
+ constructor(session: Session, prefix: string);
15
+ private request;
16
+ advertise(endpoint: Endpoint, control?: CallControl): Promise<void>;
17
+ withdraw(id: string, control?: CallControl): Promise<void>;
18
+ get(id: string, control?: CallControl): Promise<Endpoint>;
19
+ list(control?: CallControl): Promise<Endpoint[]>;
20
+ }
@@ -0,0 +1,25 @@
1
+ /** Uses the same WAMP service contract as the native Rust discovery client. */
2
+ export class Discovery {
3
+ session;
4
+ prefix;
5
+ constructor(session, prefix) {
6
+ this.session = session;
7
+ this.prefix = prefix;
8
+ }
9
+ async request(action, args, control) {
10
+ const result = await this.session.executeCall(`${this.prefix}.${action}`, args, {}, {}, control);
11
+ return result.arg(0);
12
+ }
13
+ async advertise(endpoint, control = {}) {
14
+ await this.request("advertise", [endpoint], control);
15
+ }
16
+ async withdraw(id, control = {}) {
17
+ await this.request("withdraw", [id], control);
18
+ }
19
+ async get(id, control = {}) {
20
+ return (await this.request("get", [id], control));
21
+ }
22
+ async list(control = {}) {
23
+ return (await this.request("list", [], control));
24
+ }
25
+ }
@@ -0,0 +1,12 @@
1
+ export declare class ApplicationError extends Error {
2
+ readonly args?: any[];
3
+ readonly kwargs?: Record<string, any> | null;
4
+ constructor(message: string, options?: {
5
+ args?: unknown[];
6
+ kwargs?: Record<string, unknown> | null;
7
+ });
8
+ toString(): string;
9
+ }
10
+ export declare class ProtocolError extends Error {
11
+ constructor(message: string);
12
+ }
@@ -0,0 +1,28 @@
1
+ export class ApplicationError extends Error {
2
+ args;
3
+ kwargs;
4
+ constructor(message, options) {
5
+ super(message);
6
+ this.name = "ApplicationError";
7
+ this.args = options?.args;
8
+ this.kwargs = options?.kwargs;
9
+ }
10
+ toString() {
11
+ let text = this.message;
12
+ if (this.args?.length) {
13
+ text += `: ${this.args.map(String).join(", ")}`;
14
+ }
15
+ if (this.kwargs && Object.keys(this.kwargs).length) {
16
+ text += `: ${Object.entries(this.kwargs)
17
+ .map(([key, value]) => `${key}=${String(value)}`)
18
+ .join(", ")}`;
19
+ }
20
+ return text;
21
+ }
22
+ }
23
+ export class ProtocolError extends Error {
24
+ constructor(message) {
25
+ super(message);
26
+ this.name = "ProtocolError";
27
+ }
28
+ }
@@ -0,0 +1,14 @@
1
+ /** Bounded host-side queue; aborting a receive removes only that waiter. */
2
+ export declare class Inbox<T> {
3
+ private readonly size;
4
+ private readonly maximumBytes;
5
+ private readonly maximumItems;
6
+ private readonly values;
7
+ private readonly waiters;
8
+ private bytes;
9
+ private failure?;
10
+ constructor(size: (value: T) => number, maximumBytes: number, maximumItems: number);
11
+ push(value: T): void;
12
+ receive(signal?: AbortSignal): Promise<T>;
13
+ close(error: Error): void;
14
+ }
package/dist/inbox.js ADDED
@@ -0,0 +1,71 @@
1
+ import { ProtocolError } from "./exception.js";
2
+ /** Bounded host-side queue; aborting a receive removes only that waiter. */
3
+ export class Inbox {
4
+ size;
5
+ maximumBytes;
6
+ maximumItems;
7
+ values = [];
8
+ waiters = [];
9
+ bytes = 0;
10
+ failure;
11
+ constructor(size, maximumBytes, maximumItems) {
12
+ this.size = size;
13
+ this.maximumBytes = maximumBytes;
14
+ this.maximumItems = maximumItems;
15
+ }
16
+ push(value) {
17
+ if (this.failure) {
18
+ throw this.failure;
19
+ }
20
+ const waiter = this.waiters.shift();
21
+ if (waiter) {
22
+ waiter.cleanup();
23
+ waiter.resolve(value);
24
+ return;
25
+ }
26
+ const size = this.size(value);
27
+ if (this.values.length >= this.maximumItems || this.bytes + size > this.maximumBytes) {
28
+ throw new ProtocolError("Transport receive queue exceeded its limit");
29
+ }
30
+ this.values.push({ value, size });
31
+ this.bytes += size;
32
+ }
33
+ receive(signal) {
34
+ if (signal?.aborted) {
35
+ return Promise.reject(signal.reason);
36
+ }
37
+ const next = this.values.shift();
38
+ if (next) {
39
+ this.bytes -= next.size;
40
+ return Promise.resolve(next.value);
41
+ }
42
+ if (this.failure) {
43
+ return Promise.reject(this.failure);
44
+ }
45
+ return new Promise((resolve, reject) => {
46
+ const waiter = { resolve, reject, cleanup: () => signal?.removeEventListener("abort", abort) };
47
+ const abort = () => {
48
+ const index = this.waiters.indexOf(waiter);
49
+ if (index !== -1) {
50
+ this.waiters.splice(index, 1);
51
+ }
52
+ waiter.cleanup();
53
+ reject(signal?.reason);
54
+ };
55
+ signal?.addEventListener("abort", abort, { once: true });
56
+ this.waiters.push(waiter);
57
+ });
58
+ }
59
+ close(error) {
60
+ if (this.failure) {
61
+ return;
62
+ }
63
+ this.failure = error;
64
+ this.values.length = 0;
65
+ this.bytes = 0;
66
+ for (const waiter of this.waiters.splice(0)) {
67
+ waiter.cleanup();
68
+ waiter.reject(error);
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,26 @@
1
+ export { Client, connect, connectAnonymous, connectTicket, connectCRA, connectCryptosign } from "./client.js";
2
+ export type { ClientOptions } from "./client.js";
3
+ export { Session } from "./session.js";
4
+ export type { SessionOptions } from "./session.js";
5
+ export { WebSocketBaseSession } from "./transport.js";
6
+ export { BaseSession, SessionDetails, Result, Registration, Invocation, Subscription, Event } from "./types.js";
7
+ export type { CallControl, InvocationHandler, EventHandler } from "./types.js";
8
+ export { ApplicationError, ProtocolError } from "./exception.js";
9
+ export { JSONSerializer, CBORSerializer, MsgPackSerializer } from "./serializers.js";
10
+ export type { Serializer, Payload } from "./serializers.js";
11
+ export { AnonymousAuthenticator, TicketAuthenticator, WAMPCRAAuthenticator, CryptoSignAuthenticator } from "./auth.js";
12
+ export type { ClientAuthenticator, Challenge, Authenticate } from "./auth.js";
13
+ export type { Message } from "./message.js";
14
+ export { initializeWasm } from "./native.js";
15
+ export { CallRequest, RegisterRequest, PublishRequest, SubscribeRequest } from "./requests.js";
16
+ export { PayloadError } from "./payload.js";
17
+ export { Discovery } from "./discovery.js";
18
+ export type { Endpoint } from "./discovery.js";
19
+ export * as crypto from "./crypto.js";
20
+ export { Call } from "./call.js";
21
+ export type { StreamOptions, CallTransport } from "./call.js";
22
+ export { ByteStream, WebTransportConnection } from "./webtransport.js";
23
+ export type { WebTransportOptions } from "./webtransport.js";
24
+ export { DataChannel, WebRTCConnection, WebRTCSession } from "./webrtc.js";
25
+ export type { WebRTCOptions, ChannelOptions } from "./webrtc.js";
26
+ export type { RPCStream } from "./rpc-streams.js";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ export { Client, connect, connectAnonymous, connectTicket, connectCRA, connectCryptosign } from "./client.js";
2
+ export { Session } from "./session.js";
3
+ export { WebSocketBaseSession } from "./transport.js";
4
+ export { BaseSession, SessionDetails, Result, Registration, Invocation, Subscription, Event } from "./types.js";
5
+ export { ApplicationError, ProtocolError } from "./exception.js";
6
+ export { JSONSerializer, CBORSerializer, MsgPackSerializer } from "./serializers.js";
7
+ export { AnonymousAuthenticator, TicketAuthenticator, WAMPCRAAuthenticator, CryptoSignAuthenticator } from "./auth.js";
8
+ export { initializeWasm } from "./native.js";
9
+ export { CallRequest, RegisterRequest, PublishRequest, SubscribeRequest } from "./requests.js";
10
+ export { PayloadError } from "./payload.js";
11
+ export { Discovery } from "./discovery.js";
12
+ export * as crypto from "./crypto.js";
13
+ export { Call } from "./call.js";
14
+ export { ByteStream, WebTransportConnection } from "./webtransport.js";
15
+ export { DataChannel, WebRTCConnection, WebRTCSession } from "./webrtc.js";
@@ -0,0 +1,33 @@
1
+ export type Dictionary = Record<string, any>;
2
+ export interface Message {
3
+ marshal(): any[];
4
+ type(): number;
5
+ }
6
+ interface Description {
7
+ code: number;
8
+ wire: any[];
9
+ fields: Dictionary;
10
+ }
11
+ /** Structural message adapter; parsing and field layouts come from Rust. */
12
+ export declare class WireMessage implements Message {
13
+ private readonly description;
14
+ constructor(description: Description);
15
+ type(): number;
16
+ marshal(): any[];
17
+ get fields(): Dictionary;
18
+ get authmethod(): string;
19
+ get extra(): Dictionary;
20
+ get signature(): string;
21
+ get requestID(): number;
22
+ get registrationID(): number;
23
+ get subscriptionID(): number;
24
+ get args(): any[];
25
+ get kwargs(): Dictionary;
26
+ get details(): Dictionary;
27
+ get options(): Dictionary;
28
+ get uri(): string;
29
+ get reason(): string;
30
+ }
31
+ export declare function makeMessage(code: number, fields: Dictionary): WireMessage;
32
+ export declare function inspectMessage(message: Message): WireMessage;
33
+ export {};
@@ -0,0 +1,59 @@
1
+ import { getNative, rustCall } from "./native.js";
2
+ /** Structural message adapter; parsing and field layouts come from Rust. */
3
+ export class WireMessage {
4
+ description;
5
+ constructor(description) {
6
+ this.description = description;
7
+ }
8
+ type() {
9
+ return this.description.code;
10
+ }
11
+ marshal() {
12
+ return this.description.wire;
13
+ }
14
+ get fields() {
15
+ return this.description.fields;
16
+ }
17
+ get authmethod() {
18
+ return this.fields.authmethod;
19
+ }
20
+ get extra() {
21
+ return this.fields.extra;
22
+ }
23
+ get signature() {
24
+ return this.fields.signature;
25
+ }
26
+ get requestID() {
27
+ return this.fields.request_id;
28
+ }
29
+ get registrationID() {
30
+ return this.fields.registration_id;
31
+ }
32
+ get subscriptionID() {
33
+ return this.fields.subscription_id;
34
+ }
35
+ get args() {
36
+ return this.fields.args ?? [];
37
+ }
38
+ get kwargs() {
39
+ return this.fields.kwargs ?? {};
40
+ }
41
+ get details() {
42
+ return this.fields.details ?? {};
43
+ }
44
+ get options() {
45
+ return this.fields.options ?? this.fields.details ?? {};
46
+ }
47
+ get uri() {
48
+ return this.fields.uri;
49
+ }
50
+ get reason() {
51
+ return this.fields.reason;
52
+ }
53
+ }
54
+ export function makeMessage(code, fields) {
55
+ return new WireMessage(rustCall(() => getNative().make_message(code, fields)));
56
+ }
57
+ export function inspectMessage(message) {
58
+ return new WireMessage(rustCall(() => getNative().inspect_message(message.marshal())));
59
+ }
@@ -0,0 +1,6 @@
1
+ import * as native from "./wasm/xconn_browser.js";
2
+ import type { InitInput } from "./wasm/xconn_browser.js";
3
+ /** Client.connect initializes automatically. Await this before using synchronous codec/auth APIs directly. */
4
+ export declare function initializeWasm(input?: InitInput | Promise<InitInput>): Promise<void>;
5
+ export declare function getNative(): typeof native;
6
+ export declare function rustCall<T>(action: () => T): T;
package/dist/native.js ADDED
@@ -0,0 +1,35 @@
1
+ import init, * as native from "./wasm/xconn_browser.js";
2
+ import { ProtocolError } from "./exception.js";
3
+ let initialization;
4
+ let ready = false;
5
+ /** Client.connect initializes automatically. Await this before using synchronous codec/auth APIs directly. */
6
+ export function initializeWasm(input) {
7
+ if (!initialization) {
8
+ initialization = init(input === undefined ? undefined : { module_or_path: input })
9
+ .then(() => {
10
+ ready = true;
11
+ })
12
+ .catch((error) => {
13
+ initialization = undefined;
14
+ throw error;
15
+ });
16
+ }
17
+ return initialization;
18
+ }
19
+ export function getNative() {
20
+ if (!ready) {
21
+ throw new ProtocolError("Await initializeWasm() before using synchronous protocol APIs");
22
+ }
23
+ return native;
24
+ }
25
+ export function rustCall(action) {
26
+ try {
27
+ return action();
28
+ }
29
+ catch (error) {
30
+ if (error instanceof Error) {
31
+ throw error;
32
+ }
33
+ throw new ProtocolError(String(error));
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,48 @@
1
+ import type { Dictionary } from "./message.js";
2
+ export declare class PayloadError extends Error {
3
+ readonly kind: "missing" | "null" | "type" | "range";
4
+ constructor(kind: "missing" | "null" | "type" | "range", message: string);
5
+ }
6
+ export declare class Payload {
7
+ args: any[];
8
+ kwargs: Dictionary;
9
+ constructor(args?: any[], kwargs?: Dictionary);
10
+ requireArg(index: number): any;
11
+ requireKwarg(key: string): any;
12
+ arg(index: number): any;
13
+ kwarg(key: string): any;
14
+ argOr(index: number, fallback: unknown): any;
15
+ kwargOr(key: string, fallback: unknown): any;
16
+ argString(index: number): string;
17
+ argStringOr(index: number, fallback: string): string;
18
+ argBool(index: number): boolean;
19
+ argBoolOr(index: number, fallback: boolean): boolean;
20
+ argInt64(index: number): bigint;
21
+ argInt64Or(index: number, fallback: bigint): bigint;
22
+ argUInt64(index: number): bigint;
23
+ argUInt64Or(index: number, fallback: bigint): bigint;
24
+ argFloat64(index: number): number;
25
+ argFloat64Or(index: number, fallback: number): number;
26
+ argBytes(index: number): Uint8Array;
27
+ argBytesOr(index: number, fallback: Uint8Array): Uint8Array;
28
+ argList(index: number): any[];
29
+ argListOr(index: number, fallback: any[]): any[];
30
+ argDict(index: number): Dictionary;
31
+ argDictOr(index: number, fallback: Dictionary): Dictionary;
32
+ kwargString(key: string): string;
33
+ kwargStringOr(key: string, fallback: string): string;
34
+ kwargBool(key: string): boolean;
35
+ kwargBoolOr(key: string, fallback: boolean): boolean;
36
+ kwargInt64(key: string): bigint;
37
+ kwargInt64Or(key: string, fallback: bigint): bigint;
38
+ kwargUInt64(key: string): bigint;
39
+ kwargUInt64Or(key: string, fallback: bigint): bigint;
40
+ kwargFloat64(key: string): number;
41
+ kwargFloat64Or(key: string, fallback: number): number;
42
+ kwargBytes(key: string): Uint8Array;
43
+ kwargBytesOr(key: string, fallback: Uint8Array): Uint8Array;
44
+ kwargList(key: string): any[];
45
+ kwargListOr(key: string, fallback: any[]): any[];
46
+ kwargDict(key: string): Dictionary;
47
+ kwargDictOr(key: string, fallback: Dictionary): Dictionary;
48
+ }