UNPKG

2.4 kBPlain TextView Raw
1/**
2 * Copyright 2019 Google Inc. All Rights Reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
12 */
13
14export interface EventSource {
15 addEventListener(
16 type: string,
17 listener: EventListenerOrEventListenerObject,
18 options?: {}
19 ): void;
20 removeEventListener(
21 type: string,
22 listener: EventListenerOrEventListenerObject,
23 options?: {}
24 ): void;
25}
26
27export interface PostMessageWithOrigin {
28 postMessage(
29 message: any,
30 targetOrigin: string,
31 transfer?: Transferable[]
32 ): void;
33}
34
35export interface Endpoint extends EventSource {
36 postMessage(message: any, transfer?: Transferable[]): void;
37 start?: () => void;
38}
39
40export const enum WireValueType {
41 RAW,
42 PROXY,
43 THROW,
44 HANDLER
45}
46
47export interface RawWireValue {
48 id?: string;
49 type: WireValueType.RAW;
50 value: {};
51}
52
53export interface HandlerWireValue {
54 id?: string;
55 type: WireValueType.HANDLER;
56 name: string;
57 value: {};
58}
59
60export type WireValue = RawWireValue | HandlerWireValue;
61
62export type MessageID = string;
63
64export const enum MessageType {
65 GET,
66 SET,
67 APPLY,
68 CONSTRUCT,
69 ENDPOINT,
70 RELEASE
71}
72
73export interface GetMessage {
74 id?: MessageID;
75 type: MessageType.GET;
76 path: string[];
77}
78
79export interface SetMessage {
80 id?: MessageID;
81 type: MessageType.SET;
82 path: string[];
83 value: WireValue;
84}
85
86export interface ApplyMessage {
87 id?: MessageID;
88 type: MessageType.APPLY;
89 path: string[];
90 argumentList: WireValue[];
91}
92
93export interface ConstructMessage {
94 id?: MessageID;
95 type: MessageType.CONSTRUCT;
96 path: string[];
97 argumentList: WireValue[];
98}
99
100export interface EndpointMessage {
101 id?: MessageID;
102 type: MessageType.ENDPOINT;
103}
104
105export interface ReleaseMessage {
106 id?: MessageID;
107 type: MessageType.RELEASE;
108 path: string[];
109}
110
111export type Message =
112 | GetMessage
113 | SetMessage
114 | ApplyMessage
115 | ConstructMessage
116 | EndpointMessage
117 | ReleaseMessage;