UNPKG

2 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2019 Google LLC
4 * SPDX-License-Identifier: Apache-2.0
5 */
6export interface EventSource {
7 addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: {}): void;
8 removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: {}): void;
9}
10export interface PostMessageWithOrigin {
11 postMessage(message: any, targetOrigin: string, transfer?: Transferable[]): void;
12}
13export interface Endpoint extends EventSource {
14 postMessage(message: any, transfer?: Transferable[]): void;
15 start?: () => void;
16}
17export declare const enum WireValueType {
18 RAW = "RAW",
19 PROXY = "PROXY",
20 THROW = "THROW",
21 HANDLER = "HANDLER"
22}
23export interface RawWireValue {
24 id?: string;
25 type: WireValueType.RAW;
26 value: {};
27}
28export interface HandlerWireValue {
29 id?: string;
30 type: WireValueType.HANDLER;
31 name: string;
32 value: unknown;
33}
34export type WireValue = RawWireValue | HandlerWireValue;
35export type MessageID = string;
36export declare const enum MessageType {
37 GET = "GET",
38 SET = "SET",
39 APPLY = "APPLY",
40 CONSTRUCT = "CONSTRUCT",
41 ENDPOINT = "ENDPOINT",
42 RELEASE = "RELEASE"
43}
44export interface GetMessage {
45 id?: MessageID;
46 type: MessageType.GET;
47 path: string[];
48}
49export interface SetMessage {
50 id?: MessageID;
51 type: MessageType.SET;
52 path: string[];
53 value: WireValue;
54}
55export interface ApplyMessage {
56 id?: MessageID;
57 type: MessageType.APPLY;
58 path: string[];
59 argumentList: WireValue[];
60}
61export interface ConstructMessage {
62 id?: MessageID;
63 type: MessageType.CONSTRUCT;
64 path: string[];
65 argumentList: WireValue[];
66}
67export interface EndpointMessage {
68 id?: MessageID;
69 type: MessageType.ENDPOINT;
70}
71export interface ReleaseMessage {
72 id?: MessageID;
73 type: MessageType.RELEASE;
74}
75export type Message = GetMessage | SetMessage | ApplyMessage | ConstructMessage | EndpointMessage | ReleaseMessage;