@simplito/privmx-webendpoint 2.6.2 → 2.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/Types.d.ts +55 -1
- package/Types.js +4 -0
- package/assets/endpoint-wasm-module.js +2 -19
- package/assets/endpoint-wasm-module.wasm +0 -0
- package/extra/PrivmxClient.d.ts +13 -1
- package/extra/PrivmxClient.js +34 -2
- package/extra/__mocks__/constants.d.ts +5 -0
- package/extra/__mocks__/constants.js +52 -1
- package/extra/__tests__/connectionEventManager.test.d.ts +1 -0
- package/extra/__tests__/connectionEventManager.test.js +29 -0
- package/extra/__tests__/customEventManager.test.d.ts +1 -0
- package/extra/__tests__/customEventManager.test.js +65 -0
- package/extra/__tests__/userEventManager.test.d.ts +1 -0
- package/extra/__tests__/userEventManager.test.js +52 -0
- package/extra/events.d.ts +4 -2
- package/extra/events.js +13 -3
- package/extra/index.d.ts +1 -1
- package/extra/index.js +4 -1
- package/extra/managers.d.ts +18 -11
- package/extra/managers.js +55 -7
- package/extra/subscriptions.d.ts +36 -14
- package/extra/subscriptions.js +30 -13
- package/package.json +1 -1
- package/assets/endpoint-wasm-module.worker.js +0 -1
package/extra/subscriptions.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Types } from "..";
|
|
2
|
-
import { ThreadEventSelectorType, ThreadEventType } from "../Types";
|
|
3
2
|
import { GenericEvent } from "./managers";
|
|
4
3
|
export type ThreadCallbackPayload = {
|
|
5
4
|
[Types.ThreadEventType.THREAD_CREATE]: Types.Thread;
|
|
@@ -75,8 +74,14 @@ export type KvdbCallbackPayload = {
|
|
|
75
74
|
};
|
|
76
75
|
[Types.KvdbEventType.COLLECTION_CHANGE]: Types.CollectionChangedEventData;
|
|
77
76
|
};
|
|
77
|
+
export type UserEventCallbackPayload = {
|
|
78
|
+
[Types.ConnectionEventType.USER_ADD]: Types.ContextUserEventData;
|
|
79
|
+
[Types.ConnectionEventType.USER_REMOVE]: Types.ContextUserEventData;
|
|
80
|
+
[Types.ConnectionEventType.USER_STATUS]: Types.ContextUsersStatusChangedEventData;
|
|
81
|
+
};
|
|
82
|
+
export type EventsCallbackPayload = Types.ContextCustomEventData;
|
|
78
83
|
export type EventCallback = {
|
|
79
|
-
callback: (e: Types.Event) => void;
|
|
84
|
+
callback: (e: Types.Event | GenericEvent<unknown>) => void;
|
|
80
85
|
symbol: Symbol;
|
|
81
86
|
};
|
|
82
87
|
export interface Subscription<T, S> {
|
|
@@ -129,37 +134,54 @@ export declare function createInboxSubscription<T extends Types.InboxEventType,
|
|
|
129
134
|
selector: S;
|
|
130
135
|
id: string;
|
|
131
136
|
};
|
|
132
|
-
export declare
|
|
137
|
+
export declare function createEventSubscription(s: {
|
|
138
|
+
channel: string;
|
|
139
|
+
selector: Types.EventsEventSelectorType;
|
|
140
|
+
id: string;
|
|
141
|
+
callbacks: ((arg: GenericEvent<EventsCallbackPayload>) => void)[];
|
|
142
|
+
}): Subscription<string, Types.EventsEventSelectorType> & {
|
|
143
|
+
channel: string;
|
|
144
|
+
};
|
|
145
|
+
export declare enum ConnectionStatusEventType {
|
|
133
146
|
LIB_DISCONNECTED = 0,
|
|
134
147
|
LIB_PLATFORM_DISCONNECTED = 1,
|
|
135
148
|
LIB_CONNECTED = 2
|
|
136
149
|
}
|
|
137
|
-
export
|
|
138
|
-
type:
|
|
139
|
-
callbacks: ((arg: GenericEvent<undefined>) => void)[];
|
|
140
|
-
}): {
|
|
150
|
+
export type ConnectionSubscription = {
|
|
151
|
+
type: ConnectionStatusEventType;
|
|
141
152
|
callbacks: EventCallback[];
|
|
142
|
-
type: ConnectionEventType;
|
|
143
153
|
};
|
|
154
|
+
export declare function createConnectionSubscription(s: {
|
|
155
|
+
type: ConnectionStatusEventType;
|
|
156
|
+
callbacks: ((arg: GenericEvent<undefined>) => void)[];
|
|
157
|
+
}): ConnectionSubscription;
|
|
158
|
+
export declare function createUserEventSubscription<T extends Types.ConnectionEventType, S extends Types.ConnectionEventSelectorType>(s: {
|
|
159
|
+
type: T;
|
|
160
|
+
selector: S;
|
|
161
|
+
id: string;
|
|
162
|
+
callbacks: ((arg: GenericEvent<UserEventCallbackPayload[T]>) => void)[];
|
|
163
|
+
}): Subscription<T, S>;
|
|
144
164
|
export interface EventSubscriber<E, S> {
|
|
145
165
|
/**
|
|
146
|
-
* Subscribe for
|
|
166
|
+
* Subscribe for events on the given subscription queries.
|
|
147
167
|
* @param {string[]} subscriptionQueries list of queries
|
|
148
168
|
*/
|
|
149
169
|
subscribeFor(subscriptionQueries: string[]): Promise<string[]>;
|
|
150
170
|
/**
|
|
151
|
-
*
|
|
171
|
+
* Unsubscribe from events for the given subscriptionIds.
|
|
152
172
|
*/
|
|
153
173
|
unsubscribeFrom(subscriptionIds: string[]): Promise<void>;
|
|
154
174
|
/**
|
|
155
|
-
* Generate subscription
|
|
156
|
-
* @param {
|
|
157
|
-
* @param {
|
|
175
|
+
* Generate subscription query string for the requested event scope.
|
|
176
|
+
* @param {E} eventType type of event which you listen for
|
|
177
|
+
* @param {S} selectorType scope on which you listen for events
|
|
158
178
|
* @param {string} selectorId ID of the selector
|
|
159
179
|
*/
|
|
160
180
|
buildSubscriptionQuery(eventType: E, selectorType: S, selectorId: string): Promise<string>;
|
|
161
181
|
}
|
|
162
|
-
export type SubscriberForThreadsEvents = EventSubscriber<ThreadEventType, ThreadEventSelectorType>;
|
|
182
|
+
export type SubscriberForThreadsEvents = EventSubscriber<Types.ThreadEventType, Types.ThreadEventSelectorType>;
|
|
163
183
|
export type SubscriberForStoreEvents = EventSubscriber<Types.StoreEventType, Types.StoreEventSelectorType>;
|
|
164
184
|
export type SubscriberForInboxEvents = EventSubscriber<Types.InboxEventType, Types.InboxEventSelectorType>;
|
|
165
185
|
export type SubscriberForKvdbEvents = EventSubscriber<Types.KvdbEventType, Types.KvdbEventSelectorType>;
|
|
186
|
+
export type SubscriberForUserEvents = EventSubscriber<Types.ConnectionEventType, Types.ConnectionEventSelectorType>;
|
|
187
|
+
export type SubscriberForEvents = EventSubscriber<string, Types.EventsEventSelectorType>;
|
package/extra/subscriptions.js
CHANGED
|
@@ -1,51 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ConnectionStatusEventType = void 0;
|
|
4
4
|
exports.createThreadSubscription = createThreadSubscription;
|
|
5
5
|
exports.createStoreSubscription = createStoreSubscription;
|
|
6
6
|
exports.createKvdbSubscription = createKvdbSubscription;
|
|
7
7
|
exports.createInboxSubscription = createInboxSubscription;
|
|
8
|
+
exports.createEventSubscription = createEventSubscription;
|
|
8
9
|
exports.createConnectionSubscription = createConnectionSubscription;
|
|
10
|
+
exports.createUserEventSubscription = createUserEventSubscription;
|
|
9
11
|
const __1 = require("..");
|
|
10
12
|
function toEventCallback(f) {
|
|
11
13
|
return {
|
|
12
14
|
callback: f,
|
|
13
|
-
symbol: Symbol()
|
|
15
|
+
symbol: Symbol(),
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
function createThreadSubscription(s) {
|
|
17
19
|
return {
|
|
18
20
|
...s,
|
|
19
|
-
callbacks: s.callbacks.map(toEventCallback)
|
|
21
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
24
|
function createStoreSubscription(s) {
|
|
23
25
|
return {
|
|
24
26
|
...s,
|
|
25
|
-
callbacks: s.callbacks.map(toEventCallback)
|
|
27
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
30
|
function createKvdbSubscription(s) {
|
|
29
31
|
return {
|
|
30
32
|
...s,
|
|
31
|
-
callbacks: s.callbacks.map(toEventCallback)
|
|
33
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
function createInboxSubscription(s) {
|
|
35
37
|
return {
|
|
36
38
|
...s,
|
|
37
|
-
callbacks: s.callbacks.map(toEventCallback)
|
|
39
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
function createEventSubscription(s) {
|
|
43
|
+
return {
|
|
44
|
+
type: s.channel,
|
|
45
|
+
selector: s.selector,
|
|
46
|
+
id: s.id,
|
|
47
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
48
|
+
channel: s.channel,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var ConnectionStatusEventType;
|
|
52
|
+
(function (ConnectionStatusEventType) {
|
|
53
|
+
ConnectionStatusEventType[ConnectionStatusEventType["LIB_DISCONNECTED"] = 0] = "LIB_DISCONNECTED";
|
|
54
|
+
ConnectionStatusEventType[ConnectionStatusEventType["LIB_PLATFORM_DISCONNECTED"] = 1] = "LIB_PLATFORM_DISCONNECTED";
|
|
55
|
+
ConnectionStatusEventType[ConnectionStatusEventType["LIB_CONNECTED"] = 2] = "LIB_CONNECTED";
|
|
56
|
+
})(ConnectionStatusEventType || (exports.ConnectionStatusEventType = ConnectionStatusEventType = {}));
|
|
46
57
|
function createConnectionSubscription(s) {
|
|
47
58
|
return {
|
|
48
59
|
...s,
|
|
49
|
-
callbacks: s.callbacks.map(toEventCallback)
|
|
60
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function createUserEventSubscription(s) {
|
|
64
|
+
return {
|
|
65
|
+
...s,
|
|
66
|
+
callbacks: s.callbacks.map(toEventCallback),
|
|
50
67
|
};
|
|
51
68
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var Module={};var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";if(ENVIRONMENT_IS_NODE){var nodeWorkerThreads=require("worker_threads");var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",data=>onmessage({data:data}));var fs=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:f=>(0,eval)(fs.readFileSync(f,"utf8")+"//# sourceURL="+f),postMessage:msg=>parentPort.postMessage(msg),performance:global.performance||{now:Date.now}})}var initializedJS=false;function assert(condition,text){if(!condition)abort("Assertion failed: "+text)}function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(" ");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+"\n");return}console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:text,threadId:Module["_pthread_self"]()})}var out=()=>{throw"out() is not defined in worker.js."};var err=threadPrintErr;self.alert=threadAlert;var dbg=threadPrintErr;Module["instantiateWasm"]=(info,receiveInstance)=>{var module=Module["wasmModule"];Module["wasmModule"]=null;var instance=new WebAssembly.Instance(module,info);return receiveInstance(instance)};self.onunhandledrejection=e=>{throw e.reason||e};function handleMessage(e){try{if(e.data.cmd==="load"){let messageQueue=[];self.onmessage=e=>messageQueue.push(e);self.startWorker=instance=>{Module=instance;postMessage({"cmd":"loaded"});for(let msg of messageQueue){handleMessage(msg)}self.onmessage=handleMessage};Module["wasmModule"]=e.data.wasmModule;for(const handler of e.data.handlers){Module[handler]=(...args)=>{postMessage({cmd:"callHandler",handler:handler,args:args})}}Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["workerID"]=e.data.workerID;Module["ENVIRONMENT_IS_PTHREAD"]=true;if(typeof e.data.urlOrBlob=="string"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}endpointWasmModule(Module)}else if(e.data.cmd==="run"){Module["__emscripten_thread_init"](e.data.pthread_ptr,0,0,1);Module["__emscripten_thread_mailbox_await"](e.data.pthread_ptr);assert(e.data.pthread_ptr);Module["establishStackSpace"]();Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInitTLS();if(!initializedJS){Module["__embind_initialize_bindings"]();initializedJS=true}try{Module["invokeEntryPoint"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!="unwind"){throw ex}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["__emscripten_thread_exit"](-1)}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="checkMailbox"){if(initializedJS){Module["checkMailbox"]()}}else if(e.data.cmd){err(`worker.js received unknown command ${e.data.cmd}`);err(e.data)}}catch(ex){err(`worker.js onmessage() captured an uncaught exception: ${ex}`);if(ex&&ex.stack)err(ex.stack);if(Module["__emscripten_thread_crashed"]){Module["__emscripten_thread_crashed"]()}throw ex}}self.onmessage=handleMessage;
|