@jay-framework/secure 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.
- package/dist/index.d.ts +284 -0
- package/dist/index.js +1027 -0
- package/package.json +57 -0
- package/readme.md +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import * as _jay_framework_runtime from '@jay-framework/runtime';
|
|
2
|
+
import { Coordinate, JayEventHandler, JayNativeFunction, JayElement, PreRenderElement, BaseJayElement, JayComponent, JayComponentConstructor, PrivateRef, HTMLElementCollectionProxy, HTMLElementProxy, ComponentCollectionProxy, updateFunc, MountFunc, BaseReferencesManager, JayEventHandlerWrapper, ManagedRefType, ManagedRefs, PrivateRefConstructor, HTMLElementProxyTarget, HTMLElementCollectionProxyTarget, GlobalJayEvents } from '@jay-framework/runtime';
|
|
3
|
+
import { JSONPatch, ArrayContexts } from '@jay-framework/json-patch';
|
|
4
|
+
import * as _jay_framework_component from '@jay-framework/component';
|
|
5
|
+
import { JayComponentCore } from '@jay-framework/component';
|
|
6
|
+
import { Reactive } from '@jay-framework/reactive';
|
|
7
|
+
|
|
8
|
+
declare enum JayPortMessageType {
|
|
9
|
+
render = 0,
|
|
10
|
+
addEventListener = 1,
|
|
11
|
+
root = 2,
|
|
12
|
+
eventInvocation = 3,
|
|
13
|
+
removeEventListener = 4,
|
|
14
|
+
nativeExec = 5,
|
|
15
|
+
nativeExecResult = 6,
|
|
16
|
+
rootApiInvoke = 7,
|
|
17
|
+
rootApiReturns = 8
|
|
18
|
+
}
|
|
19
|
+
interface JayPortMessage {
|
|
20
|
+
readonly type: JayPortMessageType;
|
|
21
|
+
}
|
|
22
|
+
interface JPMRender extends JayPortMessage {
|
|
23
|
+
readonly type: JayPortMessageType.render;
|
|
24
|
+
patch: JSONPatch;
|
|
25
|
+
}
|
|
26
|
+
interface JPMAddEventListener extends JayPortMessage {
|
|
27
|
+
readonly type: JayPortMessageType.addEventListener;
|
|
28
|
+
eventType: string;
|
|
29
|
+
refName: string;
|
|
30
|
+
nativeId?: string;
|
|
31
|
+
}
|
|
32
|
+
interface JPMNativeExec extends JayPortMessage {
|
|
33
|
+
readonly type: JayPortMessageType.nativeExec;
|
|
34
|
+
refName?: string;
|
|
35
|
+
nativeId: string;
|
|
36
|
+
correlationId: number;
|
|
37
|
+
coordinate?: Coordinate;
|
|
38
|
+
}
|
|
39
|
+
interface JPMNativeExecResult extends JayPortMessage {
|
|
40
|
+
readonly type: JayPortMessageType.nativeExecResult;
|
|
41
|
+
refName?: string;
|
|
42
|
+
correlationId: number;
|
|
43
|
+
result: any;
|
|
44
|
+
error: any;
|
|
45
|
+
}
|
|
46
|
+
interface JPMRemoveEventListener extends JayPortMessage {
|
|
47
|
+
readonly type: JayPortMessageType.removeEventListener;
|
|
48
|
+
eventType: string;
|
|
49
|
+
refName: string;
|
|
50
|
+
}
|
|
51
|
+
interface JPMDomEvent extends JayPortMessage {
|
|
52
|
+
readonly type: JayPortMessageType.eventInvocation;
|
|
53
|
+
eventType: string;
|
|
54
|
+
coordinate: Coordinate;
|
|
55
|
+
eventData: any;
|
|
56
|
+
}
|
|
57
|
+
interface JPMRootComponentViewState extends JayPortMessage {
|
|
58
|
+
readonly type: JayPortMessageType.root;
|
|
59
|
+
patch: JSONPatch;
|
|
60
|
+
}
|
|
61
|
+
interface JPMRootAPIInvoke extends JayPortMessage {
|
|
62
|
+
readonly type: JayPortMessageType.rootApiInvoke;
|
|
63
|
+
apiName: string;
|
|
64
|
+
callId: number;
|
|
65
|
+
params: Array<any>;
|
|
66
|
+
}
|
|
67
|
+
interface JPMRootAPIReturns extends JayPortMessage {
|
|
68
|
+
readonly type: JayPortMessageType.rootApiReturns;
|
|
69
|
+
callId: number;
|
|
70
|
+
returns: any;
|
|
71
|
+
error?: any;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type JPMMessage = JPMRootComponentViewState | JPMRender | JPMAddEventListener | JPMDomEvent | JPMNativeExecResult | JPMNativeExec | JPMRootAPIInvoke | JPMRootAPIReturns | JPMRemoveEventListener;
|
|
75
|
+
type JayPortInMessageHandler = (inMessage: JPMMessage) => void;
|
|
76
|
+
interface JayChannel {
|
|
77
|
+
postMessages(messages: Array<[number, JPMMessage]>, newCompIdMessages: Array<[string, number]>): any;
|
|
78
|
+
onMessages(handler: (messages: Array<[number, JPMMessage]>, newCompIdMessages: Array<[string, number]>) => void): any;
|
|
79
|
+
}
|
|
80
|
+
interface IJayPort {
|
|
81
|
+
getRootEndpoint(): IJayEndpoint;
|
|
82
|
+
getEndpoint(parentCompId: number, parentCoordinate: Coordinate): IJayEndpoint;
|
|
83
|
+
batch<T>(handler: () => T): T;
|
|
84
|
+
flush(): any;
|
|
85
|
+
}
|
|
86
|
+
interface IJayEndpoint {
|
|
87
|
+
port: IJayPort;
|
|
88
|
+
post(outMessage: JPMMessage): any;
|
|
89
|
+
onUpdate(handler: JayPortInMessageHandler): any;
|
|
90
|
+
readonly compId: number;
|
|
91
|
+
}
|
|
92
|
+
declare function setMainPort(port: IJayPort): void;
|
|
93
|
+
declare function useMainPort(): IJayPort;
|
|
94
|
+
declare function setWorkerPort(port: IJayPort): void;
|
|
95
|
+
declare function useWorkerPort(): IJayPort;
|
|
96
|
+
|
|
97
|
+
interface JayPortLogger {
|
|
98
|
+
logPost(compId: number, message: JPMMessage): void;
|
|
99
|
+
logInvoke(compId: number, message: JPMMessage, endpointFound: boolean): void;
|
|
100
|
+
}
|
|
101
|
+
declare class JayPortLoggerConsole implements JayPortLogger {
|
|
102
|
+
logPost(compId: number, message: JPMMessage): void;
|
|
103
|
+
logInvoke(compId: number, message: JPMMessage, endpointFound: boolean): void;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare class JayPort implements IJayPort {
|
|
107
|
+
private channel;
|
|
108
|
+
private logger?;
|
|
109
|
+
private messages;
|
|
110
|
+
private endpoints;
|
|
111
|
+
private futureEndpointMessages;
|
|
112
|
+
private inBatch;
|
|
113
|
+
private comps;
|
|
114
|
+
private lastCompId;
|
|
115
|
+
private newCompIdMessages;
|
|
116
|
+
private isAutoFlushScheduled;
|
|
117
|
+
private autoFlushTimeout;
|
|
118
|
+
constructor(channel: JayChannel, logger?: JayPortLogger);
|
|
119
|
+
private getCompId;
|
|
120
|
+
getEndpoint(parentCompId: number, parentCoordinate: Coordinate): IJayEndpoint;
|
|
121
|
+
getRootEndpoint(): IJayEndpoint;
|
|
122
|
+
post(compId: number, outMessage: JPMMessage): void;
|
|
123
|
+
batch<T>(handler: () => T): T;
|
|
124
|
+
invoke(messages: Array<[number, JPMMessage]>, newCompIdMessages: Array<[string, number]>): void;
|
|
125
|
+
flush(): void;
|
|
126
|
+
private scheduleFlush;
|
|
127
|
+
}
|
|
128
|
+
declare class JayEndpoint implements IJayEndpoint {
|
|
129
|
+
readonly compId: number;
|
|
130
|
+
readonly port: JayPort;
|
|
131
|
+
private handler;
|
|
132
|
+
private initMessages;
|
|
133
|
+
constructor(compId: number, port: JayPort);
|
|
134
|
+
post(outMessage: JPMMessage): void;
|
|
135
|
+
onUpdate(handler: JayPortInMessageHandler): void;
|
|
136
|
+
invoke(inMessage: JPMMessage): void;
|
|
137
|
+
setInitMessages(initMessages: JPMMessage[]): void;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface WorkerSelf {
|
|
141
|
+
postMessage(message: any): void;
|
|
142
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
143
|
+
}
|
|
144
|
+
declare class HandshakeMessageJayChannel implements JayChannel {
|
|
145
|
+
private handler;
|
|
146
|
+
private worker;
|
|
147
|
+
private handshakeComplete;
|
|
148
|
+
private pendingMessages;
|
|
149
|
+
constructor(worker: Worker | WorkerSelf);
|
|
150
|
+
workerOnMessage: (ev: MessageEvent) => void;
|
|
151
|
+
onMessages(handler: (messages: Array<[number, JPMMessage]>, newCompIdMessages: Array<[string, number]>) => void): void;
|
|
152
|
+
postMessages(messages: Array<[number, JPMMessage]>, newCompIdMessages: Array<[string, number]>): void;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type FunctionsRepository = Record<string, JayEventHandler<Event, any, any> | JayNativeFunction<any, any, any>>;
|
|
156
|
+
type JayNativeFunction$<ElementType extends HTMLElement, ViewState, ResultType> = JayNativeFunction<ElementType, ViewState, ResultType> & {
|
|
157
|
+
id: string;
|
|
158
|
+
};
|
|
159
|
+
type JayGlobalNativeFunction<R> = () => Promise<R> | R;
|
|
160
|
+
type JayGlobalNativeFunction$<R> = JayGlobalNativeFunction<R> & {
|
|
161
|
+
id: string;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
interface CompBridgeOptions {
|
|
165
|
+
events?: Array<string>;
|
|
166
|
+
functions?: Array<string>;
|
|
167
|
+
funcRepository?: FunctionsRepository;
|
|
168
|
+
}
|
|
169
|
+
declare function makeJayComponentBridge<PropsT extends object, ViewState extends object, Refs extends object, JayElementT extends JayElement<ViewState, Refs>>(render: PreRenderElement<ViewState, Refs, JayElementT>, options?: CompBridgeOptions): (props: PropsT) => _jay_framework_component.ConcreteJayComponent<object, ViewState, Refs, JayComponentCore<object, ViewState>, JayElementT>;
|
|
170
|
+
|
|
171
|
+
interface SecureCoordinateContext {
|
|
172
|
+
coordinate: Coordinate;
|
|
173
|
+
}
|
|
174
|
+
declare const SECURE_COORDINATE_MARKER: _jay_framework_runtime.ContextMarker<SecureCoordinateContext>;
|
|
175
|
+
declare function secureChildComp<ParentVS, Props, ChildT, ChildElement extends BaseJayElement<ChildT>, ChildComp extends JayComponent<Props, ChildT, ChildElement>>(compCreator: JayComponentConstructor<Props>, getProps: (t: ParentVS) => Props, ref: PrivateRef<ParentVS, ChildComp>): BaseJayElement<ParentVS>;
|
|
176
|
+
|
|
177
|
+
declare function mainRoot<ViewState>(viewState: ViewState, elementConstructor: () => BaseJayElement<ViewState>, funcRepository?: FunctionsRepository): BaseJayElement<ViewState>;
|
|
178
|
+
|
|
179
|
+
type Refs = Record<string, HTMLElementCollectionProxy<any, any> | HTMLElementProxy<any, any> | JayComponent<any, any, any> | ComponentCollectionProxy<any, JayComponent<any, any, any>>>;
|
|
180
|
+
|
|
181
|
+
interface SandboxElement<ViewState> {
|
|
182
|
+
update: updateFunc<ViewState>;
|
|
183
|
+
mount: MountFunc;
|
|
184
|
+
unmount: MountFunc;
|
|
185
|
+
}
|
|
186
|
+
declare function sandboxElement<ViewState>(ref: SecureElementRef<any, any>): SandboxElement<ViewState>;
|
|
187
|
+
declare function sandboxChildComp<ParentVS, Props, ChildT, ChildElement extends BaseJayElement<ChildT>, ChildComp extends JayComponent<Props, ChildT, ChildElement>>(compCreator: JayComponentConstructor<Props>, getProps: (t: ParentVS) => Props, ref: PrivateRef<ParentVS, ChildComp>): SandboxElement<ParentVS>;
|
|
188
|
+
declare function sandboxForEach<ParentViewState, ItemViewState extends object>(getItems: (viewState: ParentViewState) => ItemViewState[], matchBy: string, children: () => SandboxElement<ItemViewState>[]): SandboxElement<ParentViewState>;
|
|
189
|
+
declare function sandboxCondition<ViewState>(condition: (newData: ViewState) => boolean, children: SandboxElement<ViewState>[]): SandboxElement<ViewState>;
|
|
190
|
+
|
|
191
|
+
interface SandboxBridgeElement<ViewState> {
|
|
192
|
+
update: updateFunc<ViewState>;
|
|
193
|
+
mount: MountFunc;
|
|
194
|
+
unmount: MountFunc;
|
|
195
|
+
refs: Refs;
|
|
196
|
+
}
|
|
197
|
+
interface RefImplementation<ViewState> {
|
|
198
|
+
addEventListener<E extends Event>(type: string, listener: JayEventHandler<E, any, any>, options?: boolean | AddEventListenerOptions, nativeId?: string): void;
|
|
199
|
+
removeEventListener<E extends Event>(type: string, listener: JayEventHandler<E, any, any>, options?: EventListenerOptions | boolean): void;
|
|
200
|
+
invoke: (type: string, coordinate: Coordinate, eventData?: any) => void;
|
|
201
|
+
}
|
|
202
|
+
interface SecureElementRef<ViewState, PublicRefAPI> {
|
|
203
|
+
update: updateFunc<ViewState>;
|
|
204
|
+
mount: MountFunc;
|
|
205
|
+
unmount: MountFunc;
|
|
206
|
+
}
|
|
207
|
+
declare class SecureReferencesManager extends BaseReferencesManager {
|
|
208
|
+
private ep;
|
|
209
|
+
readonly eventWrapper: JayEventHandlerWrapper<any, any, any>;
|
|
210
|
+
constructor(ep: IJayEndpoint, eventWrapper: JayEventHandlerWrapper<any, any, any>);
|
|
211
|
+
mkManagedRef(refType: ManagedRefType, refName: string): ManagedRefs;
|
|
212
|
+
currentContext(): {
|
|
213
|
+
currData: any;
|
|
214
|
+
coordinate: (refName: string) => Coordinate;
|
|
215
|
+
};
|
|
216
|
+
static for(endpoint: IJayEndpoint, eventWrapper: JayEventHandlerWrapper<any, any, any>, elem: string[], elemCollection: string[], comp: string[], compCollection: string[], childRefManagers?: Record<string, SecureReferencesManager>): [SecureReferencesManager, PrivateRefConstructor<any>[]];
|
|
217
|
+
static forElement(elem: string[], elemCollection: string[], comp: string[], compCollection: string[], childRefManagers?: Record<string, SecureReferencesManager>): [SecureReferencesManager, PrivateRefConstructor<any>[]];
|
|
218
|
+
static forSandboxRoot(elem: string[], elemCollection: string[], comp: string[], compCollection: string[], childRefManagers?: Record<string, SecureReferencesManager>): [SecureReferencesManager, PrivateRefConstructor<any>[]];
|
|
219
|
+
}
|
|
220
|
+
declare abstract class SecurePrivateRefs<ViewState, ElementType extends HTMLElement> implements RefImplementation<ViewState> {
|
|
221
|
+
protected ref: string;
|
|
222
|
+
protected ep: IJayEndpoint;
|
|
223
|
+
listeners: Map<string, JayEventHandler<any, any, any>>;
|
|
224
|
+
items: Map<string, SecureHTMLElementRefImpl<ViewState, ElementType>>;
|
|
225
|
+
constructor(ref: string, ep: IJayEndpoint);
|
|
226
|
+
addEventListener<E extends Event>(type: string, listener: JayEventHandler<E, ViewState, any> | null, options?: boolean | AddEventListenerOptions, nativeId?: string): void;
|
|
227
|
+
removeEventListener<E extends Event>(type: string, listener: JayEventHandler<E, ViewState, any> | null, options?: EventListenerOptions | boolean): void;
|
|
228
|
+
invoke: (type: string, coordinate: Coordinate, eventData?: any) => void;
|
|
229
|
+
addRef(ref: SecureHTMLElementRefImpl<ViewState, ElementType>): void;
|
|
230
|
+
removeRef(ref: SecureHTMLElementRefImpl<ViewState, ElementType>): void;
|
|
231
|
+
}
|
|
232
|
+
declare class SecureHTMLElementRefImpl<ViewState, ElementType extends HTMLElement> implements SecureElementRef<ViewState, HTMLElementProxy<ViewState, ElementType>>, HTMLElementProxyTarget<ViewState, ElementType>, RefImplementation<ViewState> {
|
|
233
|
+
private ref;
|
|
234
|
+
private ep;
|
|
235
|
+
viewState: ViewState;
|
|
236
|
+
readonly coordinate: Coordinate;
|
|
237
|
+
private parentCollection?;
|
|
238
|
+
listeners: Map<string, JayEventHandler<any, any, any>>;
|
|
239
|
+
constructor(ref: string, ep: IJayEndpoint, viewState: ViewState, coordinate: Coordinate, parentCollection?: SecurePrivateRefs<ViewState, ElementType>);
|
|
240
|
+
addEventListener<E extends Event>(type: string, listener: JayEventHandler<E, any, any>, options?: boolean | AddEventListenerOptions, nativeId?: string): void;
|
|
241
|
+
removeEventListener<E extends Event>(type: string, listener: JayEventHandler<E, any, any>, options?: EventListenerOptions | boolean): void;
|
|
242
|
+
invoke: (type: string, coordinate: Coordinate, eventData?: any) => void;
|
|
243
|
+
exec$<ResultType>(handler: JayNativeFunction<any, any, ResultType>): Promise<ResultType>;
|
|
244
|
+
update: (newViewState: ViewState) => void;
|
|
245
|
+
mount(): void;
|
|
246
|
+
unmount(): void;
|
|
247
|
+
getPublicAPI(): HTMLElementProxy<ViewState, ElementType>;
|
|
248
|
+
}
|
|
249
|
+
declare class SecureHTMLElementRefsImpl<ViewState, ElementType extends HTMLElement> extends SecurePrivateRefs<ViewState, ElementType> implements HTMLElementProxyTarget<ViewState, ElementType>, RefImplementation<ViewState>, ManagedRefs {
|
|
250
|
+
mkManagedRef(currData: any, coordinate: Coordinate, eventWrapper: JayEventHandlerWrapper<any, any, any>): SecureHTMLElementRefImpl<ViewState, ElementType>;
|
|
251
|
+
getPublicAPI(): HTMLElementProxy<ViewState, ElementType>;
|
|
252
|
+
exec$<T>(handler: (elem: ElementType, viewState: ViewState) => T): Promise<T>;
|
|
253
|
+
}
|
|
254
|
+
declare class SecureHTMLElementCollectionRefsImpl<ViewState, ElementType extends HTMLElement> extends SecurePrivateRefs<ViewState, ElementType> implements HTMLElementCollectionProxyTarget<ViewState, ElementType>, RefImplementation<ViewState>, ManagedRefs {
|
|
255
|
+
mkManagedRef(currData: any, coordinate: Coordinate, eventWrapper: JayEventHandlerWrapper<any, any, any>): SecureHTMLElementRefImpl<ViewState, ElementType>;
|
|
256
|
+
getPublicAPI(): HTMLElementCollectionProxy<ViewState, ElementType>;
|
|
257
|
+
find(predicate: (t: ViewState, c: Coordinate) => boolean): HTMLElementProxy<ViewState, ElementType> | undefined;
|
|
258
|
+
map<ResultType>(handler: (element: HTMLElementProxy<ViewState, ElementType>, viewState: ViewState, coordinate: Coordinate) => ResultType): Array<ResultType>;
|
|
259
|
+
}
|
|
260
|
+
declare function newSecureHTMLElementPublicApiProxy<ViewState, ElementType extends HTMLElement, Target extends SecureHTMLElementRefImpl<ViewState, ElementType> | SecureHTMLElementRefsImpl<ViewState, ElementType> | SecureHTMLElementCollectionRefsImpl<ViewState, ElementType>>(ref: Target): Target & GlobalJayEvents<ViewState>;
|
|
261
|
+
declare function mkBridgeElement<ViewState>(viewState: ViewState, sandboxElements: () => SandboxElement<ViewState>[], endpoint: IJayEndpoint, reactive: Reactive, refManager: SecureReferencesManager, getComponentInstance: () => JayComponent<any, any, any>, arraySerializationContext: ArrayContexts): SandboxBridgeElement<ViewState>;
|
|
262
|
+
|
|
263
|
+
declare function elementBridge<ElementViewState, ElementRef>(viewState: ElementViewState, refManager: SecureReferencesManager, sandboxElements: () => SandboxElement<ElementViewState>[], arraySerializationContext?: ArrayContexts): JayElement<ElementViewState, ElementRef>;
|
|
264
|
+
|
|
265
|
+
declare function sandboxRoot<ViewState extends object>(sandboxElements: () => Array<SandboxElement<ViewState>>): void;
|
|
266
|
+
|
|
267
|
+
type NativeIdMarker = {
|
|
268
|
+
(): void;
|
|
269
|
+
id: number;
|
|
270
|
+
};
|
|
271
|
+
declare function handler$<EventType, ViewState, Returns>(id: string): JayEventHandler<EventType, ViewState, Returns>;
|
|
272
|
+
declare function func$<ElementType extends HTMLElement, ViewState, ResultType>(id: string): JayNativeFunction<ElementType, ViewState, ResultType>;
|
|
273
|
+
declare function funcGlobal$<R>(id: string): JayGlobalNativeFunction<R>;
|
|
274
|
+
declare function correlatedPromise<T>(): {
|
|
275
|
+
correlationId: number;
|
|
276
|
+
execPromise$: Promise<T>;
|
|
277
|
+
resolve: (t: T) => void;
|
|
278
|
+
reject: (R: any) => void;
|
|
279
|
+
};
|
|
280
|
+
declare function completeCorrelatedPromise(message: JPMNativeExecResult): void;
|
|
281
|
+
|
|
282
|
+
declare function exec$<R>(handler: JayGlobalNativeFunction<R>): Promise<R>;
|
|
283
|
+
|
|
284
|
+
export { type FunctionsRepository, HandshakeMessageJayChannel, type IJayEndpoint, type IJayPort, type JPMMessage, type JayChannel, JayEndpoint, type JayGlobalNativeFunction, type JayGlobalNativeFunction$, type JayNativeFunction$, JayPort, type JayPortInMessageHandler, type JayPortLogger, JayPortLoggerConsole, type NativeIdMarker, SECURE_COORDINATE_MARKER, type SandboxBridgeElement, type SandboxElement, type SecureCoordinateContext, type SecureElementRef, SecureHTMLElementCollectionRefsImpl, SecureHTMLElementRefImpl, SecurePrivateRefs, SecureReferencesManager, completeCorrelatedPromise, correlatedPromise, elementBridge, exec$, func$, funcGlobal$, handler$, mainRoot, makeJayComponentBridge, mkBridgeElement, newSecureHTMLElementPublicApiProxy, sandboxChildComp, sandboxCondition, sandboxElement, sandboxForEach, sandboxRoot, secureChildComp, setMainPort, setWorkerPort, useMainPort, useWorkerPort };
|