@adobe/uix-core 0.6.3
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.
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/debug-emitter.d.ts +25 -0
- package/dist/debug-emitter.d.ts.map +1 -0
- package/dist/debuglog.d.ts +70 -0
- package/dist/debuglog.d.ts.map +1 -0
- package/dist/emitter.d.ts +62 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/esm/index.js +259 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +266 -0
- package/dist/index.js.map +1 -0
- package/dist/namespace-proxy.d.ts +32 -0
- package/dist/namespace-proxy.d.ts.map +1 -0
- package/dist/timeout-promise.d.ts +12 -0
- package/dist/timeout-promise.d.ts.map +1 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +36 -0
- package/src/debug-emitter.ts +83 -0
- package/src/debuglog.ts +284 -0
- package/src/emitter.ts +90 -0
- package/src/index.ts +23 -0
- package/src/namespace-proxy.ts +82 -0
- package/src/timeout-promise.ts +36 -0
- package/src/types.ts +224 -0
- package/tsconfig.json +14 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extract keys of T whose values are are assignable to U.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
type ExtractKeys<T, U> = {
|
|
20
|
+
[P in keyof T]: T[P] extends U ? P : never;
|
|
21
|
+
}[keyof T];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
type GuestApiMethod = (...args: any[]) => any;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export interface GuestApiNS {
|
|
32
|
+
[k: string]: GuestApiMethod;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export interface GuestApis {
|
|
39
|
+
[k: string]: GuestApiNS;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export type RemoteGuestApiNS<G extends GuestApiNS = GuestApiNS> = {
|
|
46
|
+
[K in ExtractKeys<G, GuestApiMethod>]: (
|
|
47
|
+
...args: Parameters<G[K]>
|
|
48
|
+
) => Promise<ReturnType<G[K]>>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export type RemoteGuestApis<G extends GuestApis = GuestApis> = {
|
|
55
|
+
[K in ExtractKeys<G, GuestApiNS>]: RemoteGuestApiNS<GuestApiNS>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export type VirtualApi = Record<
|
|
62
|
+
string,
|
|
63
|
+
object | ((...args: unknown[]) => unknown)
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export type RemoteHostApis<Api = VirtualApi> = {
|
|
70
|
+
[K in ExtractKeys<Api, CallableFunction | object>]: Api[K] extends (
|
|
71
|
+
...args: unknown[]
|
|
72
|
+
) => PromiseLike<any>
|
|
73
|
+
? Api[K]
|
|
74
|
+
: Api[K] extends (...args: infer A) => infer R
|
|
75
|
+
? (...args: A) => Promise<R>
|
|
76
|
+
: RemoteHostApis<Api[K]>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* An individual UI extension retrieved from the registry.
|
|
82
|
+
*
|
|
83
|
+
* @remarks This interface is likely to expand. As the metadata from the
|
|
84
|
+
* extension registry stabilizes, it should probably be passed through.
|
|
85
|
+
* Right now, there are too many cases where an extension string ID
|
|
86
|
+
* is directly used; this should probably be an opaque, structured object.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export interface Extension {
|
|
91
|
+
/**
|
|
92
|
+
* Unique ID of the extension. Must be unique across entire app
|
|
93
|
+
*/
|
|
94
|
+
id: string;
|
|
95
|
+
/**
|
|
96
|
+
* Location of the document to load for the {@link @adobe/uix-guest#GuestServer}
|
|
97
|
+
*/
|
|
98
|
+
url: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Describes a method invocation to/from a remote realm, such as an iframe.
|
|
103
|
+
*
|
|
104
|
+
* @example Calling a host API method
|
|
105
|
+
*
|
|
106
|
+
* #### `extension.ts`
|
|
107
|
+
* ```ts
|
|
108
|
+
* // The following line causes the Guest object to build a `HostMethodAddress`
|
|
109
|
+
* // and dispatch it to the parent app
|
|
110
|
+
* uix.host.accounts.lookup.byQuery('Kevin', { pick: 'homeAddress' });
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* The above call produces this `HostMethodAddress` and sends it to the invoker:
|
|
114
|
+
* ```json
|
|
115
|
+
* {
|
|
116
|
+
* path: ["accounts","lookup"],
|
|
117
|
+
* name: "byQuery",
|
|
118
|
+
* args: ["Kevin", { "pick": "homeAddress" }]
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
* @internal
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
export interface HostMethodAddress<Args = unknown[]> {
|
|
125
|
+
/**
|
|
126
|
+
* Consecutive dot lookups on nested objects before the actual function call.
|
|
127
|
+
*/
|
|
128
|
+
path: string[];
|
|
129
|
+
/**
|
|
130
|
+
* Name of the method to be called as a function.
|
|
131
|
+
*/
|
|
132
|
+
name: string;
|
|
133
|
+
/**
|
|
134
|
+
* Any (serializable) arguments to the remote function.
|
|
135
|
+
*/
|
|
136
|
+
args: Args;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A callback to pass to a new namespace proxy. It will call that
|
|
141
|
+
* call back with a {@link HostMethodAddress} when one of its properties is
|
|
142
|
+
* invoked as a method.
|
|
143
|
+
*
|
|
144
|
+
* Because the typical use case is for asynchronous cross-realm communication,
|
|
145
|
+
* the callback is expected to return a Promise for the return value.
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
export type RemoteMethodInvoker<T> = (address: HostMethodAddress) => Promise<T>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Interface for decoupling Port from GuestServer.host
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export interface HostConnection<T = unknown> {
|
|
155
|
+
/**
|
|
156
|
+
* see {@link @adobe/uix-host#Port}
|
|
157
|
+
*/
|
|
158
|
+
getSharedContext(): Record<string, unknown>;
|
|
159
|
+
/**
|
|
160
|
+
* see {@link @adobe/uix-host#Port}
|
|
161
|
+
*/
|
|
162
|
+
invokeHostMethod: RemoteMethodInvoker<T>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* {@inheritDoc @adobe/uix-host#Port}
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
export interface GuestConnection {
|
|
170
|
+
id: string;
|
|
171
|
+
url: URL;
|
|
172
|
+
attachUI(
|
|
173
|
+
frame: HTMLIFrameElement,
|
|
174
|
+
privateMethods?: RemoteHostApis
|
|
175
|
+
): {
|
|
176
|
+
promise: Promise<unknown>;
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
178
|
+
destroy: Function;
|
|
179
|
+
};
|
|
180
|
+
load(): Promise<unknown>;
|
|
181
|
+
error?: Error;
|
|
182
|
+
hasCapabilities(capabilities: unknown): boolean;
|
|
183
|
+
isReady(): boolean;
|
|
184
|
+
provide(apis: unknown): void;
|
|
185
|
+
unload(): Promise<unknown>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* BEGIN EVENTS
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Returned from {@link Emitter.addEventListener}. Unsubscribes the original
|
|
194
|
+
* handler when called.
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
export type Unsubscriber = () => void;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Strongly typed event with a string `type` parameter.
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
export type NamedEvent<
|
|
204
|
+
Type extends string = string,
|
|
205
|
+
Detail = Record<string, unknown>
|
|
206
|
+
> = CustomEvent<Detail> & {
|
|
207
|
+
readonly type: Type;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Typed EventTarget
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
export interface Emits<Events extends NamedEvent = NamedEvent>
|
|
215
|
+
extends EventTarget {
|
|
216
|
+
id: string;
|
|
217
|
+
/**
|
|
218
|
+
* Same as EventTarget.addEventListener but returns an unsubscribe callback.
|
|
219
|
+
*/
|
|
220
|
+
addEventListener<Type extends Events["type"]>(
|
|
221
|
+
type: Type,
|
|
222
|
+
listener: (ev: Extract<Events, { type: Type }>) => unknown
|
|
223
|
+
): () => void;
|
|
224
|
+
}
|
package/tsconfig.json
ADDED