@rpack-dev/core 0.1.6 → 0.1.7-dev-8c5eef6

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.
@@ -0,0 +1,1244 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /**
4
+ * The main entrypoint for rPack.dev
5
+ */
6
+ declare class RPack {
7
+ private static instance;
8
+ private static platform;
9
+ private static readonly platformLoadPromise;
10
+ static initPlatform(platform: RPPlatform): void;
11
+ /**
12
+ * Creates an instance of the RPack class.
13
+ * Use this when instantiating RPack as a library.
14
+ * @return a Promise that will resolve with the RPack instance.
15
+ */
16
+ static createInstance(defaultInstance?: boolean): Promise<RPack>;
17
+ static getInstance(): RPack;
18
+ private readonly pluginThread;
19
+ private readonly loadPromise;
20
+ private readonly platform;
21
+ private readonly version;
22
+ private readonly proxyManager;
23
+ private readonly registryManager;
24
+ private readonly pluginManager;
25
+ private readonly networkManager;
26
+ private constructor();
27
+ /**
28
+ * Returns a promise that completes when this RPack instance has fully loaded.
29
+ * Note that this Promise resolves before any plugins are loaded.
30
+ * @return a Promise
31
+ */
32
+ getLoadPromise(): Promise<void>;
33
+ /**
34
+ * Returns the platform instance used to create this RPack instance.
35
+ * @return the platform instance
36
+ */
37
+ getPlatform(): RPPlatform;
38
+ /**
39
+ * Returns a class that contains version information about rPack and its platform implementation.
40
+ * @return an RPVersion instance
41
+ */
42
+ getVersion(): RPVersion;
43
+ getProxyManager(): ProxyManager;
44
+ getRegistryManager(): RegistryManager;
45
+ getPluginManager(): PluginManager;
46
+ getNetworkManager(): NetworkManager;
47
+ isPluginThread(): boolean;
48
+ /**
49
+ * Shorthand for getNetworkManager().getPlugin().
50
+ *
51
+ * @param key the plugin key
52
+ * @return a Promise that will resolve with the plugin instance, or `undefined` if the plugin cannot be found
53
+ */
54
+ getPlugin<T extends RPPlugin>(key: string): Promise<RegistryDataFiltered<T> | undefined>;
55
+ }
56
+ export declare abstract class PluginArchive {
57
+ private readonly map;
58
+ private manifest;
59
+ protected constructor();
60
+ protected abstract resolveEntry(path: string): Promise<Blob | null>;
61
+ getEntry(path: string): Promise<Blob | null>;
62
+ abstract getEntries(): Promise<string[]>;
63
+ getPluginManifest(): Promise<PluginManifest>;
64
+ }
65
+ export declare abstract class RPPlatform {
66
+ private readonly id;
67
+ protected constructor(id: string);
68
+ abstract createRPackInstance(constructor: (options: RPackConstructorOptions) => RPack): Promise<RPack>;
69
+ abstract createRPackThread(threadId: string, pluginId: string): Promise<RPackThread>;
70
+ }
71
+ export declare abstract class RPackThread {
72
+ private readonly threadId;
73
+ private readonly messenger;
74
+ protected constructor(threadId: string, messenger: Messenger<W2HPackets, H2WPackets>);
75
+ getThreadId(): string;
76
+ getMessenger(): Messenger<W2HPackets, H2WPackets>;
77
+ abstract disable(): Promise<void>;
78
+ abstract terminate(): Promise<void>;
79
+ }
80
+ export declare class AsyncIterableIteratorMirror<T, E> implements AsyncIterableIterator<T> {
81
+ private readonly it;
82
+ private readonly converter;
83
+ constructor(it: Iterator<T>);
84
+ constructor(it: Iterator<E>, converter: (e: E) => T);
85
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
86
+ next(...args: [
87
+ ] | [
88
+ any
89
+ ]): Promise<IteratorResult<T>>;
90
+ return(value?: any): Promise<IteratorResult<T>>;
91
+ throw(e?: any): Promise<IteratorResult<T>>;
92
+ }
93
+ export declare class DevPluginServerClient {
94
+ private readonly parent;
95
+ private readonly port;
96
+ private readonly manifest;
97
+ private socket?;
98
+ constructor(parent: DevPluginSource, port: number, manifest: DevPluginSourceServerManifest);
99
+ init(): void;
100
+ getAllPlugins(): AsyncIterableIterator<PluginManifest>;
101
+ getPlugin(groupId: string, pluginId: string): Promise<PluginManifest | null>;
102
+ getPluginArchive(groupId: string, pluginId: string): Promise<ArrayBuffer>;
103
+ remove(): void;
104
+ }
105
+ export declare class DevPluginSource implements PluginSource {
106
+ private static readonly RATE_MULTIPLIER;
107
+ static DEFAULT_PORT_RANGES: [
108
+ number,
109
+ number
110
+ ][];
111
+ private readonly rpack;
112
+ private portRanges;
113
+ private autoScanRate;
114
+ private autoScanPromise;
115
+ private autoScanTimeout;
116
+ private lastFoundPorts;
117
+ private servers;
118
+ constructor(rpack: RPack, portRanges: [
119
+ number,
120
+ number
121
+ ][], autoScanRate: number);
122
+ performScan(): Promise<null | undefined>;
123
+ private scanPorts;
124
+ getRPack(): RPack;
125
+ getSourceId(): string;
126
+ remove(): void;
127
+ setAutoScanRate(rate: number): void;
128
+ reloadPlugin(groupId: string, pluginId: string): Promise<void>;
129
+ getAllPlugins(): AsyncIterableIterator<PluginManifest>;
130
+ getPlugin(groupId: string, pluginId: string, version?: string): Promise<PluginManifest | null>;
131
+ getPluginArchive(groupId: string, pluginId: string, version: string): Promise<PluginArchive>;
132
+ }
133
+ export declare class FilteredIterableIterator<T> implements IterableIterator<T> {
134
+ private readonly it;
135
+ private readonly filter;
136
+ constructor(it: Iterator<T>, filter: (t: T) => boolean);
137
+ constructor(it: Iterator<T>, filter: (t: T) => boolean, undefinedAllowed: false);
138
+ constructor(it: Iterator<T>, filter: (t: T | undefined) => boolean, undefinedAllowed: true);
139
+ [Symbol.iterator](): IterableIterator<T>;
140
+ next(...args: [
141
+ ] | [
142
+ any
143
+ ]): IteratorResult<T>;
144
+ return(value?: any): IteratorResult<T>;
145
+ throw(e?: any): IteratorResult<T>;
146
+ }
147
+ export declare class LazyBatchedAsyncIterableIterator<T> implements AsyncIterableIterator<T> {
148
+ private readonly supplier;
149
+ private readonly completeHandler?;
150
+ private readonly errorHandler?;
151
+ private lastBatch;
152
+ private lastIndex;
153
+ private result?;
154
+ constructor(supplier: () => Promise<BatchResult<T>>, completeHandler?: (value?: T) => Promise<void>, errorHandler?: (value?: T) => Promise<void>);
155
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
156
+ next(): Promise<IteratorResult<T, T | undefined>>;
157
+ return(value?: T): Promise<IteratorResult<T, T | undefined>>;
158
+ throw(e?: any): Promise<IteratorResult<T, T | undefined>>;
159
+ }
160
+ export declare class LazyPromise<T> {
161
+ private readonly promise;
162
+ private completed;
163
+ private errored;
164
+ private resolveFunc;
165
+ private rejectFunc;
166
+ constructor(promise?: Promise<T>);
167
+ resolve(result: T): void;
168
+ reject(error: any): void;
169
+ getPromise(): Promise<T>;
170
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
171
+ isComplete(): boolean;
172
+ isErrored(): boolean;
173
+ }
174
+ export declare class LocalObject<T extends object> implements ProxyHandler<T> {
175
+ get(target: T, p: string | symbol, receiver: any): any;
176
+ }
177
+ export declare class LocalRegistry<Data, Key extends JSONLike = string> implements Registry<Data, Key> {
178
+ private readonly manager;
179
+ private readonly options;
180
+ private readonly publicOptions;
181
+ private readonly registryId;
182
+ private readonly map;
183
+ constructor(manager: RegistryManager, registryId: string, options: RegistryOptions);
184
+ getRegistryManager(): RegistryManager;
185
+ getRegistryId(): string;
186
+ getOptions(): PublicRegistryOptions;
187
+ getAllEntriesByThread(ownerThread: string): AsyncIterableIterator<RegistryEntry<Data, Key>>;
188
+ getAllEntries(): AsyncIterableIterator<RegistryEntry<Data, Key>>;
189
+ getAll(): AsyncIterableIterator<RegistryDataFiltered<Data>>;
190
+ get(key: Key): Promise<RegistryDataFiltered<Data> | undefined>;
191
+ getEntry(key: Key): Promise<RegistryEntry<Data, Key> | undefined>;
192
+ has(key: Key): Promise<boolean>;
193
+ add(key: Key, data: Data): Promise<boolean>;
194
+ remove(key: Key): Promise<boolean>;
195
+ size(): Promise<number>;
196
+ /**
197
+ * Internal method, do not use.
198
+ *
199
+ * Remove all values contained by this registry from the target thread.
200
+ * @param ownerThread the target thread ID
201
+ */
202
+ __removeAll(ownerThread: string): void;
203
+ /**
204
+ * Internal method, do not use.
205
+ *
206
+ * Try to add a local value to the registry.
207
+ * @param key the key to use
208
+ * @param ownerThread the owner thread, or null if sharing is allowed (requires allowShared in the options)
209
+ * @param data the data to store
210
+ *
211
+ * @return true if adding was successful, false otherwise
212
+ */
213
+ __localAdd(key: Key, ownerThread: string | null, data: Data): boolean;
214
+ __localRemove(key: Key, ownerThread: string): boolean;
215
+ __localGet(key: Key): RegistryDataFiltered<Data> | undefined;
216
+ }
217
+ export declare class LocalRemoteMap<Local, Remote> {
218
+ private parent;
219
+ private localMap;
220
+ private remoteSet;
221
+ private registry;
222
+ constructor(parent: RemoteProxyManager, messenger: Messenger<ProxyPackets, ProxyPackets>, type: ProxyCleanupTarget, cleanup?: (value: Local) => void);
223
+ private generateKey;
224
+ addLocal(local: Local, key?: string): string;
225
+ get(key: string): Local | undefined;
226
+ delete(key: string): Local | undefined;
227
+ registerRemote(key: string, remote: Remote): void;
228
+ has(key: string): boolean;
229
+ hasRemote(key: string): boolean;
230
+ deleteRemote(key: string): boolean;
231
+ }
232
+ export declare class Messenger<InPackets extends PacketsType<InPackets>, OutPackets extends PacketsType<OutPackets>> {
233
+ private readonly handlerLists;
234
+ private readonly sender;
235
+ constructor(sender: SenderFunction<OutPackets>);
236
+ private getHandlerList;
237
+ /**
238
+ * Adds a handler function that will get
239
+ * executed whenever a party
240
+ * @param key the packet key
241
+ * @param handler the packet handler
242
+ */
243
+ addHandler<K extends keyof InPackets>(key: K, handler: PacketHandler<InPackets[K]>): void;
244
+ removeHandler<K extends keyof InPackets>(key: K, handler: PacketHandler<InPackets[K]>): boolean;
245
+ private promiseHandlerImpl;
246
+ addPromiseNonceHandler<K extends keyof OnlyNoncePackets<InPackets>>(key: K, nonce: string, timeout?: number): Promise<InPackets[K]>;
247
+ addPromiseHandler<K extends keyof InPackets>(key: K, timeout?: number): Promise<InPackets[K]>;
248
+ receivePacket<K extends keyof InPackets>(packet: InPackets[K]): void;
249
+ sendPacket<K extends keyof OutPackets>(packet: OutPackets[K]): void;
250
+ sendPacketWithNoncePromise<O extends keyof OnlyNoncePackets<OutPackets>, I extends keyof OnlyNoncePackets<InPackets>>(outPacketKey: O, outPacket: Omit<OutPackets[O], "nonce" | "id">, inPacket: I, timeout?: number): Promise<InPackets[I]>;
251
+ static cast<SIn extends TIn, SOut extends TOut, TIn extends PacketsType<TIn>, TOut extends PacketsType<TOut>>(source: Messenger<SIn, SOut>): Messenger<TIn, TOut>;
252
+ }
253
+ export declare class NetworkManager {
254
+ static readonly HOST_THREAD_ID = "host";
255
+ private readonly rpack;
256
+ private hostMessenger?;
257
+ private threads?;
258
+ private readonly pluginRegistry;
259
+ private plugin;
260
+ private threadId;
261
+ private readonly wellKnownMap;
262
+ private readonly wellKnownReverseMap;
263
+ constructor(rpack: RPack, threadId: string, hostMessenger?: Messenger<H2WPackets, W2HPackets>);
264
+ private mapWellKnown;
265
+ __initPlugin(scriptUrl: string): Promise<void>;
266
+ getRPack(): RPack;
267
+ getHostMessenger(): Messenger<H2WPackets, W2HPackets> | undefined;
268
+ getCurrentThreadId(): string;
269
+ getPlugin<T extends RPPlugin>(key: string): Promise<RegistryDataFiltered<T> | undefined>;
270
+ getPluginRegistry(): Registry<RPPlugin, string>;
271
+ __initRemotes(threadId: string, messenger: Messenger<H2WPackets | W2HPackets, H2WPackets | W2HPackets>): void;
272
+ __createThread(scriptUrl: string): Promise<string>;
273
+ private ensureJSONInner;
274
+ private ensureJSON;
275
+ private getFunctionNames;
276
+ serialize<T extends Serializable>(threadId: string, target: T, options?: {
277
+ objectMode?: "registry" | "default";
278
+ }): MappedSerializedData<T>;
279
+ deserialize<T extends RegistrySerializedData>(threadId: string, serialized: T): MappedDeserializedData<T>;
280
+ }
281
+ export declare class PluginManager {
282
+ private readonly rpack;
283
+ private readonly sources?;
284
+ constructor(rpack: RPack);
285
+ getRPack(): RPack;
286
+ }
287
+ export declare class ProxyManager {
288
+ private readonly rpack;
289
+ private readonly remotes;
290
+ constructor(rpack: RPack);
291
+ createRemote(threadId: string, messenger: Messenger<ProxyPackets, ProxyPackets>): RemoteProxyManager;
292
+ getRPack(): RPack;
293
+ getRemote(threadId: string): RemoteProxyManager | undefined;
294
+ }
295
+ /**
296
+ * Represents the main entrypoint of a plugin.
297
+ */
298
+ export declare class RPPlugin {
299
+ /**
300
+ * The owning RPack instance.
301
+ */
302
+ private rpack;
303
+ /**
304
+ * Retrieves the RPack instance associated with this plugin..
305
+ *
306
+ * @return the RPack instance
307
+ */
308
+ getRPack(): RPack;
309
+ onInit(): Promise<void>;
310
+ onShutdown(): Promise<void>;
311
+ /**
312
+ * Internal method, do not use.
313
+ *
314
+ * Sets the underlying RPack property on a
315
+ * given RPPlugin instance. This can only
316
+ * be done once.
317
+ * @param plugin the plugin to modify
318
+ * @param rpack the RPack instance
319
+ */
320
+ static __setInstance(plugin: RPPlugin, rpack: RPack): void;
321
+ }
322
+ export declare class RPVersion {
323
+ private readonly rpackChannel;
324
+ private readonly rpackVersion;
325
+ private readonly rpackRepository;
326
+ private readonly implementationName;
327
+ private readonly implementationChannel;
328
+ private readonly implementationVersion;
329
+ private readonly implementationRepository;
330
+ constructor(implementationName: string, implementationChannel: string, implementationVersion: string, implementationRepository: string);
331
+ getRPackChannel(): string;
332
+ getRPackVersion(): string;
333
+ getRPackRepository(): string;
334
+ getImplementationName(): string;
335
+ getImplementationChannel(): string;
336
+ getImplementationVersion(): string;
337
+ getImplementationRepository(): string;
338
+ }
339
+ export declare class RegistryManager {
340
+ private static readonly META_REGISTRY_ID;
341
+ static readonly PLUGIN_REGISTRY_ID = "rpack:plugin";
342
+ private readonly rpack;
343
+ private readonly remotes;
344
+ private readonly metaRegistry;
345
+ constructor(rpack: RPack);
346
+ createRegistry<Data extends RegistryObject<Data>, Key extends JSONLike = string>(registryId: string, options?: Partial<RegistryOptions>): Promise<Registry<Data, Key>>;
347
+ createRegistry<Data, Key extends JSONLike = string>(registryId: string, options?: Partial<RegistryOptions> & {
348
+ localsAreProxied: true;
349
+ }): Promise<Registry<Data, Key>>;
350
+ getRPack(): RPack;
351
+ createRemote(threadId: string, messenger: Messenger<RegistryPackets, RegistryPackets>): RemoteRegistryManager;
352
+ getRemote(remoteThread: string): RemoteRegistryManager | undefined;
353
+ getRegistry(registryId: string): Promise<Registry<any, any> | undefined>;
354
+ __createInternalRegistry<Data, Key extends JSONLike = string>(registryId: string, options: Partial<RegistryOptions>): Registry<Data, Key>;
355
+ __deserializeRegistry<Data, Key extends JSONLike>(registryId: string, ownerThread: string, options: Required<PublicRegistryOptions>): Registry<Data, Key>;
356
+ }
357
+ /**
358
+ * A remote asynchronous iterator that operates over
359
+ * a remotely managed iterator.
360
+ *
361
+ * @template T The type of the elements in the remote iterator.
362
+ */
363
+ export declare class RemoteAsyncIterator<T> implements AsyncIterableIterator<T> {
364
+ private readonly manager;
365
+ private readonly iteratorKeySupplier;
366
+ private iteratorKeyPromise;
367
+ private iteratorKey;
368
+ private finished;
369
+ constructor(manager: RemoteProxyManager, iteratorKeySupplier: () => Promise<string>);
370
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
371
+ getIteratorKey(): Promise<string>;
372
+ next(...[value]: [
373
+ ] | [
374
+ any
375
+ ]): Promise<IteratorResult<T>>;
376
+ return(value?: any): Promise<IteratorResult<T>>;
377
+ throw(e?: any): Promise<IteratorResult<T>>;
378
+ }
379
+ export declare class RemoteObject<T extends object> implements ProxyHandler<T> {
380
+ private readonly remoteProxy;
381
+ private readonly objectKey;
382
+ private readonly typeName;
383
+ private readonly knownProps;
384
+ private readonly functions;
385
+ private readonly iterable;
386
+ private constructor();
387
+ get(_target: T, prop: string | symbol, _receiver: any): any;
388
+ ownKeys(_target: T): ArrayLike<string | symbol>;
389
+ getOwnPropertyDescriptor(target: T, p: string | symbol): PropertyDescriptor | undefined;
390
+ has(_target: T, prop: string | symbol): boolean;
391
+ static fromObject(remoteProxy: RemoteProxyManager, serialized: SerializedObject): RemoteObject<object>;
392
+ static fromRegistryEntry(remoteProxy: RemoteProxyManager, serialized: SerializedRegistryEntry): RemoteObject<object>;
393
+ static isProxy(object: any): boolean;
394
+ static getFunctions(object: any): any;
395
+ }
396
+ export declare class RemoteProxyManager {
397
+ private readonly parent;
398
+ private readonly threadId;
399
+ private readonly messenger;
400
+ private readonly objects;
401
+ private readonly functions;
402
+ private readonly iterators;
403
+ constructor(parent: ProxyManager, threadId: string, messenger: Messenger<ProxyPackets, ProxyPackets>);
404
+ getThreadId(): string;
405
+ serialize<T extends Serializable>(target: T, options?: {
406
+ objectMode?: "registry" | "default";
407
+ }): MappedSerializedData<T>;
408
+ deserialize<T extends RegistrySerializedData>(serialized: T): MappedDeserializedData<T>;
409
+ /**
410
+ * Shorthand for sending a response packet that has a value with the messenger.
411
+ * Automatically serializes the value passed.
412
+ * @param id the packet id
413
+ * @param nonce the packet nonce (single use token)
414
+ * @param value the value to serialize
415
+ * @param data any extra data that is needed
416
+ */
417
+ private sendValue;
418
+ /**
419
+ * Shorthand for sending a response packet that has an error with the messenger.
420
+ * Automatically serializes the error passed.
421
+ * @param id the packet id
422
+ * @param nonce the packet nonce (single use token)
423
+ * @param error the error to serialize
424
+ */
425
+ private sendError;
426
+ /**
427
+ * Shorthand for sending a response packet with an error string with the messenger.
428
+ * Automatically converts the error string to an error.
429
+ * @param id the packet id
430
+ * @param nonce the packet nonce (single use token)
431
+ * @param errorMsg the value to serialize
432
+ */
433
+ private sendErrorRaw;
434
+ onObjectRefresh(packet: ProxyRefreshObjectRequestPacket): void;
435
+ onMethod(packet: ProxyMethodRequestPacket): void;
436
+ onFunction(packet: ProxyFunctionRequestPacket): void;
437
+ onIteratorCreate(packet: ProxyCreateIteratorRequestPacket): void;
438
+ onIteratorNext(packet: ProxyIteratorNextRequestPacket): void;
439
+ onIteratorClose(packet: ProxyIteratorCloseRequestPacket): void;
440
+ declareLocalObject(value: any, key?: string): string;
441
+ declareLocalIterator(it: Iterator<any>): string;
442
+ declareLocalAsyncIterator(it: AsyncIterator<any>): string;
443
+ declareFunction(target: SerializableFunction): string;
444
+ declareRemoteIterator(iteratorKey: string, iterator: RemoteAsyncIterator<any>): void;
445
+ requestRemoteObjectIterator<T>(objectKey: string): RemoteAsyncIterator<T>;
446
+ requestRemoteIteratorNext<T>(iteratorKey: string, value?: Serializable): Promise<IteratorResult<T>>;
447
+ requestRemoteIteratorClose(iteratorKey: string): void;
448
+ refreshRemote<T>(objectKey: string): Promise<T>;
449
+ requestRemoteMethod(objectKey: string, method: string, args: any[]): Promise<any>;
450
+ requestRemoteFunction(functionKey: string, args: Serializable[]): Promise<any>;
451
+ }
452
+ export declare class RemoteRegistry<Data, Key extends JSONLike = string> implements Registry<Data, Key> {
453
+ private readonly manager;
454
+ private readonly options;
455
+ private remoteThread;
456
+ private registryId;
457
+ private localEntries;
458
+ constructor(manager: RegistryManager, remoteThread: string, registryId: string, options: PublicRegistryOptions);
459
+ private getRemote;
460
+ getRegistryManager(): RegistryManager;
461
+ getRegistryId(): string;
462
+ getOptions(): PublicRegistryOptions;
463
+ get(key: Key): Promise<RegistryDataFiltered<Data> | undefined>;
464
+ getEntry(key: Key): Promise<RegistryEntry<Data, Key> | undefined>;
465
+ getAllEntriesByThread(ownerThread: string): AsyncIterableIterator<RegistryEntry<Data, Key>>;
466
+ getAllEntries(): AsyncIterableIterator<RegistryEntry<Data, Key>>;
467
+ getAll(): AsyncIterableIterator<RegistryDataFiltered<Data>>;
468
+ has(key: Key): Promise<boolean>;
469
+ add(key: Key, data: Data): Promise<boolean>;
470
+ remove(key: Key): Promise<boolean>;
471
+ size(): Promise<number>;
472
+ __forwardAdd(key: Key, ownerThread: string, data: RegistryDataFiltered<Data>): Promise<boolean>;
473
+ __forwardRemove(key: Key, ownerThread: string): Promise<boolean>;
474
+ __localAdd(key: Key, ownerThread: string | null, data: Data): boolean;
475
+ __localGet(key: Key): RegistryDataFiltered<Data> | undefined;
476
+ }
477
+ export declare class RemoteRegistryManager {
478
+ private readonly parent;
479
+ private readonly remoteThreadId;
480
+ private readonly messenger;
481
+ constructor(parent: RegistryManager, threadId: string, messenger: Messenger<RegistryPackets, RegistryPackets>);
482
+ getCurrentThread(): string;
483
+ private getRemote;
484
+ private serialize;
485
+ private deserialize;
486
+ /**
487
+ * Shorthand for sending a response packet that has an error with the messenger.
488
+ * Automatically serializes the error passed.
489
+ * @param id the packet id
490
+ * @param nonce the packet nonce (single use token)
491
+ * @param error the error to serialize
492
+ */
493
+ private sendError;
494
+ /**
495
+ * Shorthand for sending a response packet with an error string with the messenger.
496
+ * Automatically converts the error string to an error.
497
+ * @param id the packet id
498
+ * @param nonce the packet nonce (single use token)
499
+ * @param errorMsg the value to serialize
500
+ */
501
+ private sendErrorRaw;
502
+ onAdd(packet: RegistryAddRequestPacket): Promise<void>;
503
+ onHas(packet: RegistryHasRequestPacket): Promise<void>;
504
+ onRemove(packet: RegistryRemoveRequestPacket): Promise<void>;
505
+ onSize(packet: RegistrySizeRequestPacket): Promise<void>;
506
+ onGet(packet: RegistryGetRequestPacket): Promise<void>;
507
+ onGetEntry(packet: RegistryGetEntryRequestPacket): Promise<void>;
508
+ onGetAllEntries(packet: RegistryGetAllEntriesRequestPacket): Promise<void>;
509
+ onGetAllEntriesByThread(packet: RegistryGetAllEntriesByThreadRequestPacket): Promise<void>;
510
+ onGetAll(packet: RegistryGetAllRequestPacket): Promise<void>;
511
+ requestAdd(registryId: string, originThread: string | null, key: JSONLike, value: any): Promise<boolean>;
512
+ requestHas(registryId: string, key: JSONLike): Promise<boolean>;
513
+ requestRemove(registryId: string, originThread: string | null, key: JSONLike): Promise<boolean>;
514
+ requestSize(registryId: string): Promise<number>;
515
+ requestGet<Data>(registryId: string, key: JSONLike): Promise<RegistryDataFiltered<Data> | undefined>;
516
+ requestGetEntry<Data, Key extends JSONLike>(registryId: string, key: JSONLike): Promise<RegistryEntry<Data, Key> | undefined>;
517
+ requestGetAllEntries<Data, Key extends JSONLike>(registryId: string): RemoteAsyncIterator<RegistryEntry<Data, Key>>;
518
+ requestGetAllEntriesByThread<Data, Key extends JSONLike>(registryId: string, ownerThread: string): RemoteAsyncIterator<RegistryEntry<Data, Key>>;
519
+ requestGetAll<Data>(registryId: string): RemoteAsyncIterator<Data>;
520
+ }
521
+ /**
522
+ * A collection of string-related utilities.
523
+ */
524
+ export declare class StringUtils {
525
+ /** A string containing all lowercase letters from a to z */
526
+ static readonly LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz";
527
+ /** A string containing all uppercase letters from A to Z */
528
+ static readonly UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
529
+ /** A string containing all numeric digits from 0 to 9 */
530
+ static readonly NUMBERS = "0123456789";
531
+ /** A string containing both lowercase and uppercase letters */
532
+ static readonly LOWERCASE_UPPERCASE: string;
533
+ /** A string containing all alphanumeric characters (letters and numbers) */
534
+ static readonly ALPHANUMERIC: string;
535
+ static generateNonce(): string;
536
+ static generateString(chars: string, length: number): string;
537
+ static capitalize<K extends string>(str: K): Capitalize<K>;
538
+ static count(source: string, target: string): number;
539
+ static escapeRegExp(string: string): string;
540
+ }
541
+ /**
542
+ * A collection of some utilities.
543
+ */
544
+ export declare class Utils {
545
+ private static readonly NATURAL_COLLATOR;
546
+ /**
547
+ * Returns the contents of the specified url.
548
+ *
549
+ * If the body of the request is not present,
550
+ * then the promise completes with undefined.
551
+ * Otherwise, the promise will be completed
552
+ * with the read binary data as an ArrayBuffer.
553
+ *
554
+ * @param url the URL to get
555
+ * @param fetchOptions request init data
556
+ * @param progressConsumer a callback containing
557
+ */
558
+ static getLargeFile(url: string, fetchOptions: RequestInit, progressConsumer: (read: number, length: number) => void): Promise<ArrayBuffer | undefined>;
559
+ /**
560
+ * Performs a binary search on the specified ordered array for the specified element.
561
+ * If the object is found within the array, the index of the element is returned.
562
+ *
563
+ * Let x be the position at which the element should be placed in the array.
564
+ * If the object is not found within the array, this method will return -(x + 1).
565
+ * @param array the ordered array to search
566
+ * @param element the element to search for
567
+ * @param compareFunction the function to use for comparing elements
568
+ * @returns the index of the element, or the insertion index
569
+ */
570
+ static binarySearch<T>(array: Array<T>, element: T, compareFunction: (a: T, b: T) => number): number;
571
+ /**
572
+ * Performs a binary search on the specified ordered array for the specified element.
573
+ * The element being searched is a property of an element in the array.
574
+ * If the object is found within the array, the index of the element is returned.
575
+ *
576
+ * Let x be the position at which the element should be placed in the array.
577
+ * If the object is not found within the array, this method will return -(x + 1).
578
+ * @param array the ordered array to search
579
+ * @param element the element to search for
580
+ * @param compareFunction the function to use for comparing elements
581
+ * @param convertFunction the function to use to convert an array element to the searched type
582
+ * @returns the index of the element, or the insertion index
583
+ */
584
+ static binarySearch2<T, K>(array: Array<T>, element: K, convertFunction: (element: T) => K, compareFunction: (a: K, b: K) => number): number;
585
+ /**
586
+ * Loads the image at the specified source URL in an asynchronous way.
587
+ * @param src the URL to load the image from
588
+ * @returns a Future which will complete with an Image object
589
+ */
590
+ static loadImageAsync(src: string): Promise<HTMLImageElement>;
591
+ /**
592
+ * Returns a comparator function using natural sorting
593
+ * for the specified type, using the specified string
594
+ * extractor function.
595
+ * @param func string extractor function
596
+ * @template T the original type
597
+ * @returns the comparator function
598
+ */
599
+ static naturalComparator<T>(func?: (element: T) => string): (a: T, b: T) => number;
600
+ /**
601
+ * Sorts the array of type T `array` naturally, with
602
+ * the string extractor function `func`.
603
+ * @param array the array to sort
604
+ * @param func the string extractor function
605
+ * @returns the same array
606
+ * @template T the original type
607
+ */
608
+ static naturalSort<T>(array: T[], func?: (element: T) => string): T[];
609
+ /**
610
+ * Asynchronously sorts an array with a merge sort algorithm, using an async comparator.
611
+ * This method is useful when comparison of elements requires asynchronous operations.
612
+ * After the Promise returned by this method resolves, the original array will be sorted.
613
+ * This same array will be used to resolve the Promise.
614
+ *
615
+ * @param array the array to be sorted
616
+ * @param comparator an async function that compares two elements and returns a Promise
617
+ * that resolves to a number (negative if a < b, zero if a = b, positive if a > b)
618
+ * @returns a Promise that resolves to the sorted array
619
+ */
620
+ static asyncSort<T>(array: T[], comparator: (a: T, b: T) => Promise<number>): Promise<T[]>;
621
+ /**
622
+ * Compares two arrays and returns the differences between them as added and removed elements.
623
+ *
624
+ * This method is O(n * m) where n is the length of newArray and m is the length of oldArray
625
+ *
626
+ * @param newArray The new array to compare
627
+ * @param oldArray The old array to compare against
628
+ * @param equality Optional function to determine equality between elements.
629
+ * Default compares elements using == operator
630
+ * @returns An object containing two arrays:
631
+ * - added: elements present in newArray but not in oldArray
632
+ * - removed: elements present in oldArray but not in newArray
633
+ */
634
+ static diff<T>(newArray: T[], oldArray: T[], equality?: (a: T, b: T) => boolean): {
635
+ added: T[];
636
+ removed: T[];
637
+ };
638
+ static tableString<T, N extends number>(elements: T[], func: (element: T) => FixedLengthArray<string, N>, options?: TableOptions<N>): string;
639
+ /**
640
+ * Returns an array of string keys from an enum class.
641
+ *
642
+ * @param enumClass the enum class to get keys from
643
+ * @returns array of string keys from the enum
644
+ * @template E the enum type with (string or number)
645
+ */
646
+ static getEnumKeys<E extends {
647
+ [x: string]: string | number;
648
+ }>(enumClass: {
649
+ [x: string]: E;
650
+ }): string[];
651
+ /**
652
+ * Returns an array of enum values/constants from an enum class.
653
+ * This method extracts the actual values of the named enum members.
654
+ *
655
+ * @param enumClass the enum class to get values from
656
+ * @returns array of enum values
657
+ * @template E the enum type (string or number)
658
+ */
659
+ static getEnumConstants<E extends string | number>(enumClass: {
660
+ [x: string]: E;
661
+ }): E[];
662
+ static presentOrDefault<T>(value: T | undefined, defaultValue: T): T;
663
+ /**
664
+ * Generates a random integer
665
+ * between 0 (inclusive) and `to` (exclusive)
666
+ *
667
+ * `to` will be rounded up to the nearest integer.
668
+ * @param to the maximum bound (exclusive)
669
+ */
670
+ static generateRandomInt(to: number): number;
671
+ /**
672
+ * Generates a random integer
673
+ * between `from` (inclusive) and `to` (exclusive)
674
+ *
675
+ * `to` will be rounded up to the nearest integer,
676
+ * while `from` will be rounded down to the nearest integer.
677
+ * @param from the minimum bound (inclusive)
678
+ * @param to the maximum bound (exclusive)
679
+ */
680
+ static generateRandomInt(from: number, to: number): number;
681
+ /**
682
+ * Picks a random character from the
683
+ * specified string.
684
+ * @param string the string to pick from
685
+ * @returns a random character
686
+ */
687
+ static pickRandomElement(string: string): string;
688
+ /**
689
+ * Picks a random element from the
690
+ * specified array.
691
+ * @param array the array to pick from
692
+ * @returns a random element
693
+ */
694
+ static pickRandomElement<T>(array: T[]): T;
695
+ }
696
+ export declare class ZipPluginArchive extends PluginArchive {
697
+ private zip;
698
+ constructor(zip: JSZip);
699
+ protected resolveEntry(path: string): Promise<Blob | null>;
700
+ getEntries(): Promise<string[]>;
701
+ }
702
+ export declare const DefaultPublicRegistryOptions: {
703
+ /**
704
+ * Whether the local objects in this registry are also proxied.
705
+ * This is necessary for classes that do not conform to the
706
+ * RegistryObject type, and thus must always be proxied.
707
+ *
708
+ * Defaults to false.
709
+ */
710
+ localsAreProxied: boolean;
711
+ /**
712
+ * Whether to always verify that this thread actually owns local entries.
713
+ *
714
+ * Defaults to true.
715
+ */
716
+ verifyLocals: boolean;
717
+ /**
718
+ * Allows shared values in the registry (this means that the ownerThread
719
+ * field is allowed to be null). This allows remote registry instances of
720
+ * this registry to cache values for shared entries.
721
+ *
722
+ * In practice, this is only used for the internal meta-registry.
723
+ *
724
+ * Defaults to false.
725
+ */
726
+ allowShared: boolean;
727
+ };
728
+ export declare const DefaultRegistryOptions: {
729
+ /**
730
+ * Whether the local objects in this registry are also proxied.
731
+ * This is necessary for classes that do not conform to the
732
+ * RegistryObject type, and thus must always be proxied.
733
+ *
734
+ * Defaults to false.
735
+ */
736
+ localsAreProxied: boolean;
737
+ /**
738
+ * Whether to always verify that this thread actually owns local entries.
739
+ *
740
+ * Defaults to true.
741
+ */
742
+ verifyLocals: boolean;
743
+ /**
744
+ * Allows shared values in the registry (this means that the ownerThread
745
+ * field is allowed to be null). This allows remote registry instances of
746
+ * this registry to cache values for shared entries.
747
+ *
748
+ * In practice, this is only used for the internal meta-registry.
749
+ *
750
+ * Defaults to false.
751
+ */
752
+ allowShared: boolean;
753
+ };
754
+ export declare namespace Constructor {
755
+ /**
756
+ * Determines whether a given class type is a subclass of another class type.
757
+ *
758
+ * @param child the class constructor to check if it is a subclass.
759
+ * @param parent the class constructor to act as the parent/superclass.
760
+ * @return returns true if the child class is a subclass of the parent class, false otherwise.
761
+ *
762
+ * @template Child - The child class type
763
+ * @template Parent - The parent class type
764
+ */
765
+ function isSubclass<Child, Parent>(child: Constructor<Child>, parent: Constructor<Parent>): Child extends Parent ? true : false;
766
+ }
767
+ export declare namespace Registry {
768
+ function withDefaultOptions(options?: Partial<RegistryOptions>): RegistryOptions;
769
+ function withPublicDefaultOptions(options?: Partial<RegistryOptions>): PublicRegistryOptions;
770
+ }
771
+ export interface DevPluginSourceR2SHelloPacket {
772
+ id: "hello_request";
773
+ rpackChannel: string;
774
+ rpackVersion: string;
775
+ implementationName: string;
776
+ implementationChannel: string;
777
+ implementationVersion: string;
778
+ }
779
+ export interface DevPluginSourceR2SPackets {
780
+ "hello_request": DevPluginSourceR2SHelloPacket;
781
+ }
782
+ export interface DevPluginSourceS2RHelloPacket {
783
+ id: "hello_response";
784
+ serverVersion: string;
785
+ serverBrand: string;
786
+ }
787
+ export interface DevPluginSourceS2RPackets {
788
+ "hello_response": DevPluginSourceS2RHelloPacket;
789
+ "plugin_update": DevPluginSourceS2RPluginUpdatePacket;
790
+ }
791
+ export interface DevPluginSourceS2RPluginUpdatePacket {
792
+ id: "plugin_update";
793
+ groupId: string;
794
+ pluginId: string;
795
+ }
796
+ export interface DevPluginSourceServerManifest {
797
+ rpackDevServer: boolean;
798
+ protocolVersion: number;
799
+ brand: string;
800
+ version: string;
801
+ websocketRefresh?: boolean;
802
+ }
803
+ export interface H2WHelloRequestPacket extends NoncePacket {
804
+ id: "thread:hello_request";
805
+ threadId: string;
806
+ scriptUrl: string;
807
+ }
808
+ export interface H2WShutdownRequestPacket extends NoncePacket {
809
+ id: "thread:shutdown_request";
810
+ }
811
+ export interface MultiSetRegistry<Data, Key extends JSONLike = string> extends RegistryBase {
812
+ append(key: Key, value: Data): Promise<string>;
813
+ remove(key: Key, value: Data): Promise<boolean>;
814
+ removeByKey(arrayKey: Key, entryKey: string): Promise<boolean>;
815
+ get(key: Key): Promise<AsyncIterableIterator<Data> | undefined>;
816
+ getEntries(key: Key): Promise<AsyncIterableIterator<RegistryEntry<Data, string>> | undefined>;
817
+ getAllEntriesByThread(ownerThread: string): AsyncIterableIterator<MultiSetRegistryEntry<Data, Key>>;
818
+ getAllEntries(): AsyncIterableIterator<MultiSetRegistryEntry<Data, Key>>;
819
+ has(key: string): Promise<boolean>;
820
+ size(): Promise<number>;
821
+ }
822
+ export interface MultiSetRegistryEntry<Data, Key extends JSONLike> {
823
+ key: Key;
824
+ ownerThread: string | null;
825
+ data: () => AsyncIterableIterator<RegistryDataFiltered<Data>>;
826
+ }
827
+ export interface NoncePacket {
828
+ nonce: string;
829
+ }
830
+ export interface Packet {
831
+ id: string;
832
+ }
833
+ export interface PluginManifest {
834
+ groupId: string;
835
+ pluginId: string;
836
+ version: string;
837
+ authors?: string | string[];
838
+ name?: string;
839
+ description?: string;
840
+ mainClass: string;
841
+ }
842
+ export interface PluginSource {
843
+ getSourceId(): string;
844
+ remove(): void;
845
+ getAllPlugins(): AsyncIterableIterator<PluginManifest>;
846
+ getPlugin(groupId: string, pluginId: string, version?: string): Promise<PluginManifest | null>;
847
+ getPluginArchive(groupId: string, pluginId: string, version: string): Promise<PluginArchive>;
848
+ }
849
+ export interface ProxyCleanupPacket {
850
+ id: "proxy:cleanup";
851
+ type: ProxyCleanupTarget;
852
+ key: string;
853
+ }
854
+ export interface ProxyCreateIteratorRequestPacket extends NoncePacket {
855
+ id: "proxy:create_iterator_request";
856
+ objectKey: string;
857
+ }
858
+ export interface ProxyCreateIteratorResponsePacket extends NoncePacket {
859
+ id: "proxy:create_iterator_response";
860
+ iteratorKey?: string;
861
+ error?: SerializedData;
862
+ }
863
+ export interface ProxyFunctionRequestPacket extends NoncePacket {
864
+ id: "proxy:function_request";
865
+ functionKey: string;
866
+ args: SerializedData[];
867
+ }
868
+ export interface ProxyFunctionResponsePacket extends NoncePacket {
869
+ id: "proxy:function_response";
870
+ value?: SerializedData;
871
+ error?: SerializedData;
872
+ }
873
+ export interface ProxyIteratorCloseRequestPacket {
874
+ id: "proxy:iterator_close_request";
875
+ iteratorKey: string;
876
+ }
877
+ export interface ProxyIteratorNextRequestPacket extends NoncePacket {
878
+ id: "proxy:iterator_next_request";
879
+ iteratorKey: string;
880
+ value?: SerializedData;
881
+ }
882
+ export interface ProxyIteratorNextResponsePacket extends NoncePacket {
883
+ id: "proxy:iterator_next_response";
884
+ done?: boolean;
885
+ value?: SerializedData;
886
+ error?: SerializedData;
887
+ }
888
+ export interface ProxyMethodRequestPacket extends NoncePacket {
889
+ id: "proxy:method_request";
890
+ objectKey: string;
891
+ method: string;
892
+ args: SerializedData[];
893
+ }
894
+ export interface ProxyMethodResponsePacket extends NoncePacket {
895
+ id: "proxy:method_response";
896
+ value?: SerializedData;
897
+ error?: SerializedData;
898
+ }
899
+ export interface ProxyPackets {
900
+ "proxy:refresh_object_request": ProxyRefreshObjectRequestPacket;
901
+ "proxy:refresh_object_response": ProxyRefreshObjectResponsePacket;
902
+ "proxy:method_request": ProxyMethodRequestPacket;
903
+ "proxy:method_response": ProxyMethodResponsePacket;
904
+ "proxy:function_request": ProxyFunctionRequestPacket;
905
+ "proxy:function_response": ProxyFunctionResponsePacket;
906
+ "proxy:create_iterator_request": ProxyCreateIteratorRequestPacket;
907
+ "proxy:create_iterator_response": ProxyCreateIteratorResponsePacket;
908
+ "proxy:iterator_next_request": ProxyIteratorNextRequestPacket;
909
+ "proxy:iterator_next_response": ProxyIteratorNextResponsePacket;
910
+ "proxy:iterator_close_request": ProxyIteratorCloseRequestPacket;
911
+ "proxy:cleanup": ProxyCleanupPacket;
912
+ }
913
+ export interface ProxyRefreshObjectRequestPacket extends NoncePacket {
914
+ id: "proxy:refresh_object_request";
915
+ objectKey: string;
916
+ }
917
+ export interface ProxyRefreshObjectResponsePacket extends NoncePacket {
918
+ id: "proxy:refresh_object_response";
919
+ value?: SerializedData;
920
+ error?: SerializedData;
921
+ }
922
+ export interface Registry<Data, Key extends JSONLike = string> extends RegistryBase {
923
+ get(key: Key): Promise<RegistryDataFiltered<Data> | undefined>;
924
+ getEntry(key: Key): Promise<RegistryEntry<Data, Key> | undefined>;
925
+ getAllEntriesByThread(ownerThread: string): AsyncIterableIterator<RegistryEntry<Data, Key>>;
926
+ getAllEntries(): AsyncIterableIterator<RegistryEntry<Data, Key>>;
927
+ getAll(): AsyncIterableIterator<RegistryDataFiltered<Data>>;
928
+ has(key: Key): Promise<boolean>;
929
+ add(key: Key, data: Data): Promise<boolean>;
930
+ remove(key: Key): Promise<boolean>;
931
+ size(): Promise<number>;
932
+ }
933
+ export interface RegistryAddRequestPacket extends NoncePacket {
934
+ id: "registry:add_request";
935
+ registryId: string;
936
+ key: JSONLike;
937
+ ownerThread: string;
938
+ value: RegistrySerializedData;
939
+ }
940
+ export interface RegistryAddResponsePacket extends NoncePacket {
941
+ id: "registry:add_response";
942
+ value?: boolean;
943
+ error?: SerializedData;
944
+ }
945
+ export interface RegistryBase {
946
+ getRegistryId(): string;
947
+ getRegistryManager(): RegistryManager;
948
+ getOptions(): PublicRegistryOptions;
949
+ }
950
+ export interface RegistryEntry<Data, Key extends JSONLike> {
951
+ key: Key;
952
+ ownerThread: string | null;
953
+ data: RegistryDataFiltered<Data>;
954
+ }
955
+ export interface RegistryGetAllEntriesByThreadRequestPacket extends NoncePacket {
956
+ id: "registry:get_all_entries_by_thread_request";
957
+ registryId: string;
958
+ ownerThread: string;
959
+ }
960
+ export interface RegistryGetAllEntriesByThreadResponsePacket extends NoncePacket {
961
+ id: "registry:get_all_entries_by_thread_response";
962
+ iteratorKey?: string;
963
+ error?: SerializedData;
964
+ }
965
+ export interface RegistryGetAllEntriesRequestPacket extends NoncePacket {
966
+ id: "registry:get_all_entries_request";
967
+ registryId: string;
968
+ }
969
+ export interface RegistryGetAllEntriesResponsePacket extends NoncePacket {
970
+ id: "registry:get_all_entries_response";
971
+ iteratorKey?: string;
972
+ error?: SerializedData;
973
+ }
974
+ export interface RegistryGetAllRequestPacket extends NoncePacket {
975
+ id: "registry:get_all_request";
976
+ registryId: string;
977
+ }
978
+ export interface RegistryGetAllResponsePacket extends NoncePacket {
979
+ id: "registry:get_all_response";
980
+ iteratorKey?: string;
981
+ error?: SerializedData;
982
+ }
983
+ export interface RegistryGetEntryRequestPacket extends NoncePacket {
984
+ id: "registry:get_entry_request";
985
+ registryId: string;
986
+ key: JSONLike;
987
+ }
988
+ export interface RegistryGetEntryResponsePacket extends NoncePacket {
989
+ id: "registry:get_entry_response";
990
+ value?: {
991
+ key: SerializedData;
992
+ ownerThread: string | null;
993
+ data: SerializedData;
994
+ } | null;
995
+ error?: SerializedData;
996
+ }
997
+ export interface RegistryGetRequestPacket extends NoncePacket {
998
+ id: "registry:get_request";
999
+ registryId: string;
1000
+ key: JSONLike;
1001
+ }
1002
+ export interface RegistryGetResponsePacket extends NoncePacket {
1003
+ id: "registry:get_response";
1004
+ value?: SerializedData;
1005
+ error?: SerializedData;
1006
+ }
1007
+ export interface RegistryHasRequestPacket extends NoncePacket {
1008
+ id: "registry:has_request";
1009
+ registryId: string;
1010
+ key: JSONLike;
1011
+ }
1012
+ export interface RegistryHasResponsePacket extends NoncePacket {
1013
+ id: "registry:has_response";
1014
+ value?: boolean;
1015
+ error?: SerializedData;
1016
+ }
1017
+ export interface RegistryPackets {
1018
+ "registry:add_request": RegistryAddRequestPacket;
1019
+ "registry:add_response": RegistryAddResponsePacket;
1020
+ "registry:has_request": RegistryHasRequestPacket;
1021
+ "registry:has_response": RegistryHasResponsePacket;
1022
+ "registry:remove_request": RegistryRemoveRequestPacket;
1023
+ "registry:remove_response": RegistryRemoveResponsePacket;
1024
+ "registry:size_request": RegistrySizeRequestPacket;
1025
+ "registry:size_response": RegistrySizeResponsePacket;
1026
+ "registry:get_request": RegistryGetRequestPacket;
1027
+ "registry:get_response": RegistryGetResponsePacket;
1028
+ "registry:get_entry_request": RegistryGetEntryRequestPacket;
1029
+ "registry:get_entry_response": RegistryGetEntryResponsePacket;
1030
+ "registry:get_all_entries_by_thread_request": RegistryGetAllEntriesByThreadRequestPacket;
1031
+ "registry:get_all_entries_by_thread_response": RegistryGetAllEntriesByThreadResponsePacket;
1032
+ "registry:get_all_entries_request": RegistryGetAllEntriesRequestPacket;
1033
+ "registry:get_all_entries_response": RegistryGetAllEntriesResponsePacket;
1034
+ "registry:get_all_request": RegistryGetAllRequestPacket;
1035
+ "registry:get_all_response": RegistryGetAllResponsePacket;
1036
+ }
1037
+ export interface RegistryRemoveRequestPacket extends NoncePacket {
1038
+ id: "registry:remove_request";
1039
+ registryId: string;
1040
+ key: JSONLike;
1041
+ ownerThread: string;
1042
+ }
1043
+ export interface RegistryRemoveResponsePacket extends NoncePacket {
1044
+ id: "registry:remove_response";
1045
+ value?: boolean;
1046
+ error?: SerializedData;
1047
+ }
1048
+ export interface RegistrySizeRequestPacket extends NoncePacket {
1049
+ id: "registry:size_request";
1050
+ registryId: string;
1051
+ }
1052
+ export interface RegistrySizeResponsePacket extends NoncePacket {
1053
+ id: "registry:size_response";
1054
+ value?: number;
1055
+ error?: SerializedData;
1056
+ }
1057
+ export interface SerializedError {
1058
+ type: "error";
1059
+ errorType: "Error" | "EvalError" | "RangeError" | "ReferenceError" | "SyntaxError" | "TypeError" | "URIError";
1060
+ name: string;
1061
+ message: string;
1062
+ stack: string | undefined;
1063
+ }
1064
+ export interface SerializedFunction {
1065
+ type: "function";
1066
+ functionKey: string;
1067
+ }
1068
+ export interface SerializedJSON {
1069
+ type: "json";
1070
+ value: JSONLike;
1071
+ }
1072
+ export interface SerializedObject {
1073
+ type: "object";
1074
+ objectKey: string;
1075
+ typeName: string;
1076
+ props: string[];
1077
+ functions: string[];
1078
+ iterable: boolean;
1079
+ }
1080
+ export interface SerializedRegistry {
1081
+ type: "registry";
1082
+ registryId: string;
1083
+ options: PublicRegistryOptions;
1084
+ }
1085
+ export interface SerializedRegistryEntry extends Omit<SerializedObject, "type" | "props"> {
1086
+ type: "registry_entry";
1087
+ props: Record<string, SerializedData>;
1088
+ }
1089
+ export interface SerializedUndefined {
1090
+ type: "undefined";
1091
+ }
1092
+ export interface SerializedWellKnown {
1093
+ type: "well_known";
1094
+ kind: "RPack" | "NetworkManager" | "ProxyManager" | "RegistryManager";
1095
+ }
1096
+ export interface SetRegistry<Data> extends RegistryBase {
1097
+ add(value: Data): Promise<string>;
1098
+ remove(value: Data): Promise<boolean>;
1099
+ removeByKey(key: string): Promise<boolean>;
1100
+ getByKey(key: string): Promise<RegistryDataFiltered<Data> | undefined>;
1101
+ getEntryByKey(key: string): Promise<RegistryEntry<Data, string> | undefined>;
1102
+ getAllEntriesByThread(ownerThread: string): AsyncIterableIterator<RegistryEntry<Data, string>>;
1103
+ getAllEntries(): AsyncIterableIterator<RegistryEntry<Data, string>>;
1104
+ getAll(): AsyncIterableIterator<RegistryDataFiltered<Data>>;
1105
+ has(value: Data): Promise<boolean>;
1106
+ hasKey(key: string): Promise<boolean>;
1107
+ size(): Promise<number>;
1108
+ }
1109
+ export interface TableOptions<N extends number> {
1110
+ separator?: string | string[];
1111
+ headers?: FixedLengthArray<string, N>;
1112
+ padding?: string;
1113
+ textAlign?: "left" | "center" | "right";
1114
+ }
1115
+ export interface W2HHelloResponsePacket extends NoncePacket {
1116
+ id: "thread:hello_response";
1117
+ }
1118
+ export interface W2HPluginLoadPacket extends NoncePacket {
1119
+ id: "thread:plugin_load";
1120
+ }
1121
+ export interface W2HShutdownResponsePacket extends NoncePacket {
1122
+ id: "thread:shutdown_response";
1123
+ }
1124
+ export type BatchResult<T> = {
1125
+ done: boolean;
1126
+ values: T[];
1127
+ };
1128
+ /**
1129
+ * A type alias representing a constructor signature for creating instances of type `T`.
1130
+ *
1131
+ * This type can be used to define or constrain the shape of classes or functions
1132
+ * that act as constructors. It accepts an arbitrary number of arguments of any type
1133
+ * and returns an instance of the specified type `T`.
1134
+ *
1135
+ * @template T the type of object that the constructor creates
1136
+ */
1137
+ export type Constructor<T> = T extends {
1138
+ new (...args: infer P): infer R;
1139
+ } ? {
1140
+ new (...args: P): R;
1141
+ } : {
1142
+ new (...args: any[]): T;
1143
+ };
1144
+ export type DeserializedFilter<T> = Pick<T, {
1145
+ [K in keyof T]: T[K] extends ((...args: infer P) => Promise<Serializable | void>) ? P extends [
1146
+ ] ? K : P[number] extends Serializable ? K : never : never;
1147
+ }[keyof T]>;
1148
+ export type ErrorType = Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError;
1149
+ export type FixedLengthArray<T, L extends number, TObj = [
1150
+ T,
1151
+ ...Array<T>
1152
+ ]> = TObj & {
1153
+ readonly length: L;
1154
+ [I: number]: T;
1155
+ [Symbol.iterator]: () => IterableIterator<T>;
1156
+ };
1157
+ export type H2WPackets = {
1158
+ "thread:hello_request": H2WHelloRequestPacket;
1159
+ "thread:shutdown_request": H2WShutdownRequestPacket;
1160
+ } & ProxyPackets & RegistryPackets;
1161
+ export type JSONLike = string | number | boolean | null | {
1162
+ [key: string]: JSONLike;
1163
+ } | JSONLike[];
1164
+ export type MappedDeserializedData<T> = T extends SerializedUndefined ? undefined : T extends SerializedJSON ? JSONLike : T extends SerializedRegistry ? Registry<any, any> : T extends SerializedError ? ErrorType : T extends SerializedObject ? SerializableObject : T extends SerializedRegistryEntry ? RegistryObject<any> : T extends SerializedFunction ? SerializableFunction : T extends {
1165
+ "type": "well_known";
1166
+ "kind": "RPack";
1167
+ } ? RPack : T extends {
1168
+ "type": "well_known";
1169
+ "kind": "NetworkManager";
1170
+ } ? NetworkManager : T extends {
1171
+ "type": "well_known";
1172
+ "kind": "ProxyManager";
1173
+ } ? ProxyManager : T extends {
1174
+ "type": "well_known";
1175
+ "kind": "RegistryManager";
1176
+ } ? RegistryManager : T extends SerializedWellKnown ? WellKnownType : never;
1177
+ export type MappedSerializedData<T> = T extends undefined ? SerializedUndefined : T extends JSONLike ? SerializedJSON : T extends RegistryType ? SerializedRegistry : T extends ErrorType ? SerializedError : T extends SerializableObject ? SerializedObject : T extends SerializableFunction ? SerializedFunction : T extends RPack ? {
1178
+ "type": "well_known";
1179
+ "kind": "RPack";
1180
+ } : T extends NetworkManager ? {
1181
+ "type": "well_known";
1182
+ "kind": "NetworkManager";
1183
+ } : T extends ProxyManager ? {
1184
+ "type": "well_known";
1185
+ "kind": "ProxyManager";
1186
+ } : T extends RegistryManager ? {
1187
+ "type": "well_known";
1188
+ "kind": "RegistryManager";
1189
+ } : never;
1190
+ export type OnlyNoncePacketTypes<Packets extends PacketsType<Packets>> = {
1191
+ [Key in keyof Packets]: Packets[Key] extends NoncePacket ? Key : never;
1192
+ }[keyof Packets];
1193
+ export type OnlyNoncePackets<Packets extends PacketsType<Packets>> = {
1194
+ [Key in OnlyNoncePacketTypes<Packets>]: Packets[Key] & NoncePacket;
1195
+ };
1196
+ export type PacketHandler<T> = (packet: T) => unknown | false;
1197
+ export type PacketHandlers<T> = {
1198
+ [Key in keyof T]?: (T[Key] extends void ? () => (void | false) : PacketHandler<T[Key]>)[];
1199
+ };
1200
+ export type PacketsType<Packets extends Record<string, Packet>> = {
1201
+ [Key in keyof Packets]: Packets[Key];
1202
+ };
1203
+ export type PromiseFunction<F, K> = F extends (...args: any[]) => PromiseLike<unknown> ? K : never;
1204
+ export type PromisesOnly<T> = {
1205
+ [K in keyof T]: PromiseFunction<T[K], K>;
1206
+ };
1207
+ export type ProxyCleanupTarget = "object" | "iterator" | "array" | "function";
1208
+ export type PublicRegistryOptions = typeof DefaultPublicRegistryOptions;
1209
+ export type RPackConstructorOptions = {
1210
+ pluginThread: boolean;
1211
+ loadPromise: Promise<void>;
1212
+ platform: RPPlatform;
1213
+ threadId: string;
1214
+ hostMessenger?: Messenger<H2WPackets, W2HPackets>;
1215
+ version: RPVersion;
1216
+ };
1217
+ export type RegistryDataFiltered<Data> = Data extends Serializable ? Data : {
1218
+ readonly [Key in keyof Data]: Data[Key] extends Serializable ? Data[Key] : Data[Key] extends (...args: any) => Promise<any> ? Data[Key] : Data[Key] extends (...args: infer P) => infer R ? (...args: P) => Promise<R> : never;
1219
+ };
1220
+ export type RegistryObject<T> = {
1221
+ readonly [Key in keyof T]: Serializable | ((...args: any) => Promise<any>);
1222
+ };
1223
+ export type RegistryOptions = typeof DefaultRegistryOptions;
1224
+ export type RegistrySerializedData = SerializedUndefined | SerializedJSON | SerializedRegistry | SerializedError | SerializedObject | SerializedFunction | SerializedWellKnown | SerializedRegistryEntry;
1225
+ export type RegistryType = LocalRegistry<any, any> | Registry<any, any> | RemoteRegistry<any, any>;
1226
+ export type RegistryWrapped<T> = Pick<T, PromisesOnly<T>[keyof T]>;
1227
+ export type SenderFunction<T> = (packet: T[keyof T]) => void;
1228
+ export type Serializable = undefined | JSONLike | RegistryType | ErrorType | WellKnownType | SerializableFunction;
1229
+ export type SerializableFunction = (...args: Serializable[]) => Promise<Serializable>;
1230
+ export type SerializableObject = Record<string, SerializableFunction>;
1231
+ export type SerializedData = SerializedUndefined | SerializedJSON | SerializedRegistry | SerializedError | SerializedObject | SerializedFunction | SerializedWellKnown;
1232
+ export type W2HPackets = {
1233
+ "thread:hello_response": W2HHelloResponsePacket;
1234
+ "thread:plugin_load": W2HPluginLoadPacket;
1235
+ "thread:shutdown_response": W2HShutdownResponsePacket;
1236
+ } & ProxyPackets & RegistryPackets;
1237
+ export type WellKnownType = RPack | NetworkManager | ProxyManager | RegistryManager;
1238
+
1239
+ export {
1240
+ RPack as default,
1241
+ };
1242
+
1243
+ export as namespace RPack;
1244
+