zeed 0.9.2 → 0.9.4
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/chunk-VBENGHAN.js +12 -0
- package/dist/chunk-VBENGHAN.js.map +1 -0
- package/dist/index.all.d.ts +270 -228
- package/dist/index.browser.cjs +6 -6
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +11 -11
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +3 -3
- package/dist/index.node.js +6 -6
- package/dist/index.node.js.map +1 -1
- package/dist/{uuid-c2cc7aa0.d.ts → uuid-bcd51568.d.ts} +269 -227
- package/package.json +4 -4
- package/dist/chunk-5KHLXHN6.js +0 -12
- package/dist/chunk-5KHLXHN6.js.map +0 -1
|
@@ -405,6 +405,7 @@ declare function useDispose(config?: string | UseDisposeConfig): (() => Promise<
|
|
|
405
405
|
dispose: () => Promise<void>;
|
|
406
406
|
exec: () => Promise<void>;
|
|
407
407
|
getSize(): number;
|
|
408
|
+
isDisposed(): boolean;
|
|
408
409
|
};
|
|
409
410
|
type UseDispose = ReturnType<typeof useDispose>;
|
|
410
411
|
/** @deprecated use `useDispose` instead */
|
|
@@ -437,6 +438,7 @@ declare interface DefaultListener {
|
|
|
437
438
|
declare class Emitter<RemoteListener extends ListenerSignature<RemoteListener> = DefaultListener, LocalListener extends ListenerSignature<LocalListener> = RemoteListener> implements Disposable {
|
|
438
439
|
subscribers: any;
|
|
439
440
|
subscribersOnAny: any[];
|
|
441
|
+
/** Unused, but here for historical reasons */
|
|
440
442
|
dispose: (() => Promise<void>) & {
|
|
441
443
|
track: (obj?: Disposer | undefined) => DisposerFunction | undefined;
|
|
442
444
|
add: (obj?: Disposer | undefined) => DisposerFunction | undefined;
|
|
@@ -444,6 +446,7 @@ declare class Emitter<RemoteListener extends ListenerSignature<RemoteListener> =
|
|
|
444
446
|
dispose: () => Promise<void>;
|
|
445
447
|
exec: () => Promise<void>;
|
|
446
448
|
getSize(): number;
|
|
449
|
+
isDisposed(): boolean;
|
|
447
450
|
};
|
|
448
451
|
call: RemoteListener;
|
|
449
452
|
emit<U extends keyof RemoteListener>(event: U, ...args: Parameters<RemoteListener[U]>): Promise<boolean>;
|
|
@@ -466,89 +469,55 @@ declare function getGlobalEmitter(): Emitter<ZeedGlobalEmitter>;
|
|
|
466
469
|
declare const messages: Emitter<DefaultListener, DefaultListener>;
|
|
467
470
|
declare function lazyListener(emitter: any, listenerKey?: string): (key?: string, skipUnmatched?: boolean) => Promise<any>;
|
|
468
471
|
|
|
469
|
-
|
|
470
|
-
|
|
472
|
+
/** See http://developer.mozilla.org/en-US/docs/Web/API/MessageEvent */
|
|
473
|
+
interface ChannelMessageEvent {
|
|
474
|
+
data: any;
|
|
475
|
+
origin?: string;
|
|
476
|
+
lastEventId?: string;
|
|
471
477
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
478
|
+
/**
|
|
479
|
+
* Inspired by
|
|
480
|
+
* http://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
|
|
481
|
+
* https://deno.com/deploy/docs/runtime-broadcast-channel
|
|
482
|
+
* */
|
|
483
|
+
declare abstract class Channel extends Emitter<{
|
|
484
|
+
message(event: ChannelMessageEvent): void;
|
|
485
|
+
messageerror(event: ChannelMessageEvent): void;
|
|
486
|
+
connect(): void;
|
|
487
|
+
disconnect(): void;
|
|
488
|
+
close(): void;
|
|
489
|
+
}> {
|
|
490
|
+
id: string;
|
|
491
|
+
abstract isConnected?: boolean;
|
|
492
|
+
abstract postMessage(data: any): void;
|
|
493
|
+
close(): void;
|
|
477
494
|
}
|
|
478
|
-
/**
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
readonly setMax: (max: number) => void;
|
|
484
|
-
readonly setResolved: (resolved: number) => void;
|
|
485
|
-
readonly incResolved: (inc?: number) => void;
|
|
486
|
-
state: PoolTaskState;
|
|
487
|
-
priority: number;
|
|
488
|
-
/** Same groups are executed only one at a time */
|
|
489
|
-
group?: string;
|
|
490
|
-
max: number;
|
|
491
|
-
resolved: number;
|
|
492
|
-
result?: T;
|
|
493
|
-
payload?: unknown;
|
|
495
|
+
/** Very basic channel demonstrating local communication */
|
|
496
|
+
declare class LocalChannel extends Channel {
|
|
497
|
+
isConnected: boolean;
|
|
498
|
+
other?: LocalChannel;
|
|
499
|
+
postMessage(data: any): void;
|
|
494
500
|
}
|
|
495
|
-
declare
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
/** Tasks with same `id` throw error */
|
|
501
|
-
error = 2
|
|
501
|
+
declare function createLocalChannelPair(): [LocalChannel, LocalChannel];
|
|
502
|
+
|
|
503
|
+
interface Encoder {
|
|
504
|
+
encode(data: any): Promise<Uint8Array>;
|
|
505
|
+
decode(data: Uint8Array): Promise<any>;
|
|
502
506
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
507
|
+
declare class NoopEncoder implements Encoder {
|
|
508
|
+
encode(data: any): Promise<Uint8Array>;
|
|
509
|
+
decode(data: Uint8Array): Promise<any>;
|
|
510
|
+
}
|
|
511
|
+
declare class JsonEncoder implements Encoder {
|
|
512
|
+
encode(data: any): Promise<Uint8Array>;
|
|
513
|
+
decode(data: Uint8Array): Promise<any>;
|
|
514
|
+
}
|
|
515
|
+
declare class CryptoEncoder implements Encoder {
|
|
516
|
+
key: CryptoKey;
|
|
517
|
+
constructor(key: CryptoKey);
|
|
518
|
+
encode(data: any): Promise<Uint8Array>;
|
|
519
|
+
decode(data: Uint8Array): Promise<any>;
|
|
510
520
|
}
|
|
511
|
-
declare function usePool<T = any>(config?: PoolConfig): {
|
|
512
|
-
events: Emitter<PoolTaskEvents, PoolTaskEvents>;
|
|
513
|
-
cancel: (id: string) => void;
|
|
514
|
-
cancelAll: () => void;
|
|
515
|
-
enqueue: <P>(task: PoolTaskFn<T>, config?: {
|
|
516
|
-
id?: string | undefined;
|
|
517
|
-
max?: number | undefined;
|
|
518
|
-
resolved?: number | undefined;
|
|
519
|
-
group?: string | undefined;
|
|
520
|
-
idConflictResolution?: PoolTaskIdConflictResolution | undefined;
|
|
521
|
-
payload?: P | undefined;
|
|
522
|
-
}) => {
|
|
523
|
-
id: string;
|
|
524
|
-
promise: Promise<any>;
|
|
525
|
-
dispose: () => void;
|
|
526
|
-
cancel: () => void;
|
|
527
|
-
};
|
|
528
|
-
dispose: () => void;
|
|
529
|
-
waitFinishAll: () => Promise<unknown>;
|
|
530
|
-
};
|
|
531
|
-
type Pool = ReturnType<typeof usePool>;
|
|
532
|
-
|
|
533
|
-
declare function createPromise<T>(): [Promise<T>, any, any];
|
|
534
|
-
/** Sleep for `milliSeconds`. Example 1s: `await sleep(1000)` */
|
|
535
|
-
declare function sleep(milliSeconds: number): Promise<void>;
|
|
536
|
-
declare function immediate(): Promise<void>;
|
|
537
|
-
declare const timeoutReached: unique symbol;
|
|
538
|
-
declare function timeout<T>(promise: Promise<T>, milliSeconds: number, timeoutValue?: symbol): Promise<T | typeof timeoutValue>;
|
|
539
|
-
declare const timoutError: Error;
|
|
540
|
-
declare function isTimeout(value: any): boolean;
|
|
541
|
-
declare function tryTimeout<T>(promise: Promise<T>, milliSeconds: number): Promise<T | undefined>;
|
|
542
|
-
/** Wait for `event` on `obj` to emit. Resolve with result or reject on `timeout` */
|
|
543
|
-
declare function waitOn(obj: any, event: string, timeoutMS?: number): Promise<any>;
|
|
544
|
-
declare function isPromise<T>(value: Promise<T> | T): value is Promise<T>;
|
|
545
|
-
/** This is exactly what Prose.resolve(x) is supposed to be: return a Promise no matter what type x is */
|
|
546
|
-
declare function promisify<T>(value: Promise<T> | T): Promise<T>;
|
|
547
|
-
/**
|
|
548
|
-
* Like ReturnType but for async functions.
|
|
549
|
-
* From https://www.jpwilliams.dev/how-to-unpack-the-return-type-of-a-promise-in-typescript
|
|
550
|
-
*/
|
|
551
|
-
type AsyncReturnType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer U> ? U : T extends (...args: any) => infer U ? U : any;
|
|
552
521
|
|
|
553
522
|
declare enum LogLevel {
|
|
554
523
|
all = -1,
|
|
@@ -635,6 +604,227 @@ interface LogHandlerOptions {
|
|
|
635
604
|
}
|
|
636
605
|
declare function LoggerContext(_prefix?: string): LoggerContextInterface;
|
|
637
606
|
|
|
607
|
+
interface MessageAction {
|
|
608
|
+
name: string;
|
|
609
|
+
id: string;
|
|
610
|
+
args?: Json[];
|
|
611
|
+
}
|
|
612
|
+
interface MessageResult {
|
|
613
|
+
id: string;
|
|
614
|
+
result?: Json;
|
|
615
|
+
error?: {
|
|
616
|
+
stack?: string;
|
|
617
|
+
name: string;
|
|
618
|
+
message: string;
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
type Message = MessageAction | MessageResult;
|
|
622
|
+
interface MessagesOptions {
|
|
623
|
+
timeout?: number;
|
|
624
|
+
}
|
|
625
|
+
interface MessagesDefaultMethods<L> {
|
|
626
|
+
dispose(): void;
|
|
627
|
+
connect?(channel: Channel): void;
|
|
628
|
+
options(opt: MessagesOptions): L;
|
|
629
|
+
}
|
|
630
|
+
type MessagesMethods<L> = L & MessagesDefaultMethods<L>;
|
|
631
|
+
type MessageDefinitions = Record<any, (...args: any) => Promise<any>>;
|
|
632
|
+
interface MessageHub {
|
|
633
|
+
dispose(): void;
|
|
634
|
+
connect: (newChannel: Channel) => void;
|
|
635
|
+
listen<L extends MessageDefinitions>(newHandlers: L): void;
|
|
636
|
+
send<L extends MessageDefinitions>(): MessagesMethods<L>;
|
|
637
|
+
}
|
|
638
|
+
declare const createPromiseProxy: <P extends object>(fn: (name: string, args: any[], opt: any) => Promise<unknown>, opt: MessagesOptions, predefinedMethods?: any) => P;
|
|
639
|
+
/**
|
|
640
|
+
* RPC
|
|
641
|
+
*
|
|
642
|
+
* Features:
|
|
643
|
+
* - Waits for connection
|
|
644
|
+
* - Retries after fail
|
|
645
|
+
* - Timeouts
|
|
646
|
+
*/
|
|
647
|
+
declare function useMessageHub(opt?: {
|
|
648
|
+
name?: string;
|
|
649
|
+
channel?: Channel;
|
|
650
|
+
encoder?: Encoder;
|
|
651
|
+
retryAfter?: number;
|
|
652
|
+
ignoreUnhandled?: boolean;
|
|
653
|
+
debug?: boolean;
|
|
654
|
+
logLevel?: LogLevelAliasType;
|
|
655
|
+
}): MessageHub;
|
|
656
|
+
|
|
657
|
+
interface PubSubConfig {
|
|
658
|
+
channel: Channel;
|
|
659
|
+
encoder?: Encoder;
|
|
660
|
+
name?: string;
|
|
661
|
+
debug?: boolean;
|
|
662
|
+
}
|
|
663
|
+
declare class PubSub<L extends ListenerSignature<L> = DefaultListener> extends Emitter<L> {
|
|
664
|
+
name: string;
|
|
665
|
+
channel: Channel;
|
|
666
|
+
encoder: Encoder;
|
|
667
|
+
log: any;
|
|
668
|
+
debug: boolean;
|
|
669
|
+
get shortId(): string;
|
|
670
|
+
constructor(opt: PubSubConfig);
|
|
671
|
+
private emitSuper;
|
|
672
|
+
emit<U extends keyof L>(event: U, ...args: Parameters<L[U]>): Promise<boolean>;
|
|
673
|
+
publish: <U extends keyof L>(event: U, ...args: Parameters<L[U]>) => Promise<boolean>;
|
|
674
|
+
subscribe: <U extends keyof L>(event: U, listener: L[U]) => DisposerFunction;
|
|
675
|
+
}
|
|
676
|
+
declare function usePubSub<L extends ListenerSignature<L> = DefaultListener>(opt: PubSubConfig): PubSub<L>;
|
|
677
|
+
|
|
678
|
+
type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
|
|
679
|
+
type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
|
|
680
|
+
interface RPCOptions<Remote> {
|
|
681
|
+
/** No return values expected */
|
|
682
|
+
onlyEvents?: boolean;
|
|
683
|
+
/** Names of remote functions that do not need response. */
|
|
684
|
+
eventNames?: (keyof Remote)[];
|
|
685
|
+
/** Function to post raw message */
|
|
686
|
+
post: (data: any) => void;
|
|
687
|
+
/** Listener to receive raw message */
|
|
688
|
+
on: (fn: (data: any) => void) => void;
|
|
689
|
+
/** Custom function to serialize data */
|
|
690
|
+
serialize?: (data: any) => any;
|
|
691
|
+
/** Custom function to deserialize data */
|
|
692
|
+
deserialize?: (data: any) => any;
|
|
693
|
+
}
|
|
694
|
+
interface RPCFn<T> {
|
|
695
|
+
/** Call the remote function and wait for the result. */
|
|
696
|
+
(...args: ArgumentsType<T>): Promise<Awaited<ReturnType$1<T>>>;
|
|
697
|
+
/** Send event without asking for response */
|
|
698
|
+
asEvent(...args: ArgumentsType<T>): void;
|
|
699
|
+
}
|
|
700
|
+
type RPCReturn<RemoteFunctions> = {
|
|
701
|
+
[K in keyof RemoteFunctions]: RPCFn<RemoteFunctions[K]>;
|
|
702
|
+
};
|
|
703
|
+
declare function useRPC<RemoteFunctions = {}, LocalFunctions = {}>(functions: LocalFunctions, options: RPCOptions<RemoteFunctions>): RPCReturn<RemoteFunctions>;
|
|
704
|
+
|
|
705
|
+
declare class Progress extends Emitter<{
|
|
706
|
+
progressCancelled(progress: Progress): void;
|
|
707
|
+
progressChanged(progress: Progress): void;
|
|
708
|
+
progressDispose(progress: Progress): void;
|
|
709
|
+
}> {
|
|
710
|
+
private _totalUnits;
|
|
711
|
+
private _completedUnits;
|
|
712
|
+
private _isCancelled;
|
|
713
|
+
private _isCancelable;
|
|
714
|
+
private _children;
|
|
715
|
+
constructor(opt?: {
|
|
716
|
+
totalUnits?: number;
|
|
717
|
+
completeUnits?: number;
|
|
718
|
+
isIndeterminate?: boolean;
|
|
719
|
+
isCancelable?: boolean;
|
|
720
|
+
});
|
|
721
|
+
private update;
|
|
722
|
+
/** Notify and mark as cancelled. May take some time before having an effect. */
|
|
723
|
+
cancel(): Promise<void>;
|
|
724
|
+
addChild(child: Progress): void;
|
|
725
|
+
removeChild(child: Progress): void;
|
|
726
|
+
/** Total units including children */
|
|
727
|
+
getTotalUnits(): number;
|
|
728
|
+
/** Completed units including children */
|
|
729
|
+
getCompletedUnits(): number;
|
|
730
|
+
/** Cannot calculate progress, because totalUnits are missing. Special representation in UI. */
|
|
731
|
+
isIndeterminate(): boolean;
|
|
732
|
+
isCancelled(): boolean;
|
|
733
|
+
/** Either disposed or all units completed. */
|
|
734
|
+
isFinished(): boolean;
|
|
735
|
+
/** Value from 0 to 1, where 1 is 100% completeness. */
|
|
736
|
+
getFraction(): number;
|
|
737
|
+
getChildrenCount(): number;
|
|
738
|
+
setTotalUnit(unit: number): void;
|
|
739
|
+
setCompletetedUnit(unit: number): void;
|
|
740
|
+
incCompletedUnit(step?: number): void;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
interface PoolConfig {
|
|
744
|
+
maxParallel?: number;
|
|
745
|
+
}
|
|
746
|
+
type PoolTaskFn<T = any> = (taskInfo?: PoolTask<T>) => Promise<T>;
|
|
747
|
+
declare enum PoolTaskState {
|
|
748
|
+
waiting = 0,
|
|
749
|
+
running = 1,
|
|
750
|
+
finished = 2
|
|
751
|
+
}
|
|
752
|
+
/** Task */
|
|
753
|
+
interface PoolTask<T> {
|
|
754
|
+
readonly id: string;
|
|
755
|
+
readonly task: PoolTaskFn<T>;
|
|
756
|
+
readonly done: Function;
|
|
757
|
+
readonly setMax: (max: number) => void;
|
|
758
|
+
readonly setResolved: (resolved: number) => void;
|
|
759
|
+
readonly incResolved: (inc?: number) => void;
|
|
760
|
+
state: PoolTaskState;
|
|
761
|
+
priority: number;
|
|
762
|
+
/** Same groups are executed only one at a time */
|
|
763
|
+
group?: string;
|
|
764
|
+
progress: Progress;
|
|
765
|
+
max: number;
|
|
766
|
+
resolved: number;
|
|
767
|
+
result?: T;
|
|
768
|
+
payload?: unknown;
|
|
769
|
+
}
|
|
770
|
+
declare enum PoolTaskIdConflictResolution {
|
|
771
|
+
/** Tasks with same `id` are replaced. Last wins */
|
|
772
|
+
replace = 0,
|
|
773
|
+
/** Tasks with same `id` ??? */
|
|
774
|
+
memoize = 1,
|
|
775
|
+
/** Tasks with same `id` throw error */
|
|
776
|
+
error = 2
|
|
777
|
+
}
|
|
778
|
+
interface PoolTaskEvents {
|
|
779
|
+
didUpdate(max: number, resolved: number, presentMax: number, presentResolved: number): void;
|
|
780
|
+
didStart(id: string): void;
|
|
781
|
+
didCancel(id: string): void;
|
|
782
|
+
didFinish(): void;
|
|
783
|
+
didResolve(id: string, value: any): void;
|
|
784
|
+
didReject(id: string, error: any): void;
|
|
785
|
+
}
|
|
786
|
+
declare function usePool<T = any>(config?: PoolConfig): {
|
|
787
|
+
events: Emitter<PoolTaskEvents, PoolTaskEvents>;
|
|
788
|
+
cancel: (id: string) => void;
|
|
789
|
+
cancelAll: () => void;
|
|
790
|
+
enqueue: <P>(task: PoolTaskFn<T>, config?: {
|
|
791
|
+
id?: string | undefined;
|
|
792
|
+
max?: number | undefined;
|
|
793
|
+
resolved?: number | undefined;
|
|
794
|
+
group?: string | undefined;
|
|
795
|
+
idConflictResolution?: PoolTaskIdConflictResolution | undefined;
|
|
796
|
+
payload?: P | undefined;
|
|
797
|
+
}) => {
|
|
798
|
+
id: string;
|
|
799
|
+
promise: Promise<any>;
|
|
800
|
+
dispose: () => void;
|
|
801
|
+
cancel: () => void;
|
|
802
|
+
};
|
|
803
|
+
dispose: () => void;
|
|
804
|
+
waitFinishAll: () => Promise<unknown>;
|
|
805
|
+
};
|
|
806
|
+
type Pool = ReturnType<typeof usePool>;
|
|
807
|
+
|
|
808
|
+
declare function createPromise<T>(): [Promise<T>, any, any];
|
|
809
|
+
/** Sleep for `milliSeconds`. Example 1s: `await sleep(1000)` */
|
|
810
|
+
declare function sleep(milliSeconds: number): Promise<void>;
|
|
811
|
+
declare function immediate(): Promise<void>;
|
|
812
|
+
declare const timeoutReached: unique symbol;
|
|
813
|
+
declare function timeout<T>(promise: Promise<T>, milliSeconds: number, timeoutValue?: symbol): Promise<T | typeof timeoutValue>;
|
|
814
|
+
declare const timoutError: Error;
|
|
815
|
+
declare function isTimeout(value: any): boolean;
|
|
816
|
+
declare function tryTimeout<T>(promise: Promise<T>, milliSeconds: number): Promise<T | undefined>;
|
|
817
|
+
/** Wait for `event` on `obj` to emit. Resolve with result or reject on `timeout` */
|
|
818
|
+
declare function waitOn(obj: any, event: string, timeoutMS?: number): Promise<any>;
|
|
819
|
+
declare function isPromise<T>(value: Promise<T> | T): value is Promise<T>;
|
|
820
|
+
/** This is exactly what Prose.resolve(x) is supposed to be: return a Promise no matter what type x is */
|
|
821
|
+
declare function promisify<T>(value: Promise<T> | T): Promise<T>;
|
|
822
|
+
/**
|
|
823
|
+
* Like ReturnType but for async functions.
|
|
824
|
+
* From https://www.jpwilliams.dev/how-to-unpack-the-return-type-of-a-promise-in-typescript
|
|
825
|
+
*/
|
|
826
|
+
type AsyncReturnType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer U> ? U : T extends (...args: any) => infer U ? U : any;
|
|
827
|
+
|
|
638
828
|
type TaskFn<T = any> = () => Promise<T>;
|
|
639
829
|
interface TaskEvents {
|
|
640
830
|
didUpdate(max: number, resolved: number): void;
|
|
@@ -768,154 +958,6 @@ declare function LoggerMemoryHandler(opt: LogHandlerOptions & {
|
|
|
768
958
|
messages: LogMessage[];
|
|
769
959
|
}): LogHandler;
|
|
770
960
|
|
|
771
|
-
/** See http://developer.mozilla.org/en-US/docs/Web/API/MessageEvent */
|
|
772
|
-
interface ChannelMessageEvent {
|
|
773
|
-
data: any;
|
|
774
|
-
origin?: string;
|
|
775
|
-
lastEventId?: string;
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Inspired by
|
|
779
|
-
* http://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
|
|
780
|
-
* https://deno.com/deploy/docs/runtime-broadcast-channel
|
|
781
|
-
* */
|
|
782
|
-
declare abstract class Channel extends Emitter<{
|
|
783
|
-
message(event: ChannelMessageEvent): void;
|
|
784
|
-
messageerror(event: ChannelMessageEvent): void;
|
|
785
|
-
connect(): void;
|
|
786
|
-
disconnect(): void;
|
|
787
|
-
close(): void;
|
|
788
|
-
}> {
|
|
789
|
-
id: string;
|
|
790
|
-
abstract isConnected?: boolean;
|
|
791
|
-
abstract postMessage(data: any): void;
|
|
792
|
-
close(): void;
|
|
793
|
-
}
|
|
794
|
-
/** Very basic channel demonstrating local communication */
|
|
795
|
-
declare class LocalChannel extends Channel {
|
|
796
|
-
isConnected: boolean;
|
|
797
|
-
other?: LocalChannel;
|
|
798
|
-
postMessage(data: any): void;
|
|
799
|
-
}
|
|
800
|
-
declare function createLocalChannelPair(): [LocalChannel, LocalChannel];
|
|
801
|
-
|
|
802
|
-
interface Encoder {
|
|
803
|
-
encode(data: any): Promise<Uint8Array>;
|
|
804
|
-
decode(data: Uint8Array): Promise<any>;
|
|
805
|
-
}
|
|
806
|
-
declare class NoopEncoder implements Encoder {
|
|
807
|
-
encode(data: any): Promise<Uint8Array>;
|
|
808
|
-
decode(data: Uint8Array): Promise<any>;
|
|
809
|
-
}
|
|
810
|
-
declare class JsonEncoder implements Encoder {
|
|
811
|
-
encode(data: any): Promise<Uint8Array>;
|
|
812
|
-
decode(data: Uint8Array): Promise<any>;
|
|
813
|
-
}
|
|
814
|
-
declare class CryptoEncoder implements Encoder {
|
|
815
|
-
key: CryptoKey;
|
|
816
|
-
constructor(key: CryptoKey);
|
|
817
|
-
encode(data: any): Promise<Uint8Array>;
|
|
818
|
-
decode(data: Uint8Array): Promise<any>;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
interface MessageAction {
|
|
822
|
-
name: string;
|
|
823
|
-
id: string;
|
|
824
|
-
args?: Json[];
|
|
825
|
-
}
|
|
826
|
-
interface MessageResult {
|
|
827
|
-
id: string;
|
|
828
|
-
result?: Json;
|
|
829
|
-
error?: {
|
|
830
|
-
stack?: string;
|
|
831
|
-
name: string;
|
|
832
|
-
message: string;
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
type Message = MessageAction | MessageResult;
|
|
836
|
-
interface MessagesOptions {
|
|
837
|
-
timeout?: number;
|
|
838
|
-
}
|
|
839
|
-
interface MessagesDefaultMethods<L> {
|
|
840
|
-
dispose(): void;
|
|
841
|
-
connect?(channel: Channel): void;
|
|
842
|
-
options(opt: MessagesOptions): L;
|
|
843
|
-
}
|
|
844
|
-
type MessagesMethods<L> = L & MessagesDefaultMethods<L>;
|
|
845
|
-
type MessageDefinitions = Record<any, (...args: any) => Promise<any>>;
|
|
846
|
-
interface MessageHub {
|
|
847
|
-
dispose(): void;
|
|
848
|
-
connect: (newChannel: Channel) => void;
|
|
849
|
-
listen<L extends MessageDefinitions>(newHandlers: L): void;
|
|
850
|
-
send<L extends MessageDefinitions>(): MessagesMethods<L>;
|
|
851
|
-
}
|
|
852
|
-
declare const createPromiseProxy: <P extends object>(fn: (name: string, args: any[], opt: any) => Promise<unknown>, opt: MessagesOptions, predefinedMethods?: any) => P;
|
|
853
|
-
/**
|
|
854
|
-
* RPC
|
|
855
|
-
*
|
|
856
|
-
* Features:
|
|
857
|
-
* - Waits for connection
|
|
858
|
-
* - Retries after fail
|
|
859
|
-
* - Timeouts
|
|
860
|
-
*/
|
|
861
|
-
declare function useMessageHub(opt?: {
|
|
862
|
-
name?: string;
|
|
863
|
-
channel?: Channel;
|
|
864
|
-
encoder?: Encoder;
|
|
865
|
-
retryAfter?: number;
|
|
866
|
-
ignoreUnhandled?: boolean;
|
|
867
|
-
debug?: boolean;
|
|
868
|
-
logLevel?: LogLevelAliasType;
|
|
869
|
-
}): MessageHub;
|
|
870
|
-
|
|
871
|
-
interface PubSubConfig {
|
|
872
|
-
channel: Channel;
|
|
873
|
-
encoder?: Encoder;
|
|
874
|
-
name?: string;
|
|
875
|
-
debug?: boolean;
|
|
876
|
-
}
|
|
877
|
-
declare class PubSub<L extends ListenerSignature<L> = DefaultListener> extends Emitter<L> {
|
|
878
|
-
name: string;
|
|
879
|
-
channel: Channel;
|
|
880
|
-
encoder: Encoder;
|
|
881
|
-
log: any;
|
|
882
|
-
debug: boolean;
|
|
883
|
-
get shortId(): string;
|
|
884
|
-
constructor(opt: PubSubConfig);
|
|
885
|
-
private emitSuper;
|
|
886
|
-
emit<U extends keyof L>(event: U, ...args: Parameters<L[U]>): Promise<boolean>;
|
|
887
|
-
publish: <U extends keyof L>(event: U, ...args: Parameters<L[U]>) => Promise<boolean>;
|
|
888
|
-
subscribe: <U extends keyof L>(event: U, listener: L[U]) => DisposerFunction;
|
|
889
|
-
}
|
|
890
|
-
declare function usePubSub<L extends ListenerSignature<L> = DefaultListener>(opt: PubSubConfig): PubSub<L>;
|
|
891
|
-
|
|
892
|
-
type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
|
|
893
|
-
type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
|
|
894
|
-
interface RPCOptions<Remote> {
|
|
895
|
-
/** No return values expected */
|
|
896
|
-
onlyEvents?: boolean;
|
|
897
|
-
/** Names of remote functions that do not need response. */
|
|
898
|
-
eventNames?: (keyof Remote)[];
|
|
899
|
-
/** Function to post raw message */
|
|
900
|
-
post: (data: any) => void;
|
|
901
|
-
/** Listener to receive raw message */
|
|
902
|
-
on: (fn: (data: any) => void) => void;
|
|
903
|
-
/** Custom function to serialize data */
|
|
904
|
-
serialize?: (data: any) => any;
|
|
905
|
-
/** Custom function to deserialize data */
|
|
906
|
-
deserialize?: (data: any) => any;
|
|
907
|
-
}
|
|
908
|
-
interface RPCFn<T> {
|
|
909
|
-
/** Call the remote function and wait for the result. */
|
|
910
|
-
(...args: ArgumentsType<T>): Promise<Awaited<ReturnType$1<T>>>;
|
|
911
|
-
/** Send event without asking for response */
|
|
912
|
-
asEvent(...args: ArgumentsType<T>): void;
|
|
913
|
-
}
|
|
914
|
-
type RPCReturn<RemoteFunctions> = {
|
|
915
|
-
[K in keyof RemoteFunctions]: RPCFn<RemoteFunctions[K]>;
|
|
916
|
-
};
|
|
917
|
-
declare function useRPC<RemoteFunctions = {}, LocalFunctions = {}>(functions: LocalFunctions, options: RPCOptions<RemoteFunctions>): RPCReturn<RemoteFunctions>;
|
|
918
|
-
|
|
919
961
|
interface fetchOptionType {
|
|
920
962
|
/** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
|
|
921
963
|
cache?: RequestCache;
|
|
@@ -1094,4 +1136,4 @@ declare function uuidIsValid(uuid: string): boolean;
|
|
|
1094
1136
|
declare function uname(name?: string): string;
|
|
1095
1137
|
declare function qid(): string;
|
|
1096
1138
|
|
|
1097
|
-
export { _encodeUtf8Polyfill as $, arraySortedNumbers as A, arrayIsEqual as B, CRYPTO_DEFAULT_HASH_ALG as C, arrayShuffleInPlace as D, arrayShuffle as E, arrayShuffleForce as F, arrayRandomElement as G, arrayMax as H, arrayMin as I, Json as J, arraySum as K, LogHandlerOptions as L, arrayAvg as M, arrayBatches as N, ObjectStorage as O, createArray as P, encodeBase32 as Q, decodeBase32 as R, useBase as S, encodeBase16 as T, decodeBase16 as U, encodeBase58 as V, decodeBase58 as W, encodeBase62 as X, decodeBase62 as Y, estimateSizeForBase as Z, BinInput as _, LogHandler as a, dateStringToDays as a$, _decodeUtf8Polyfill as a0, stringToUInt8Array as a1, Uint8ArrayToString as a2, toUint8Array as a3, joinToUint8Array as a4, toHex as a5, fromHex as a6, toBase64 as a7, toBase64Url as a8, fromBase64 as a9, DayInput as aA, dayYear as aB, dayMonth as aC, dayDay as aD, dayToParts as aE, dayToDate as aF, dayFromToday as aG, dayFromAny as aH, dayToDateGMT as aI, dayFromDate as aJ, dayFromDateGMT as aK, dayToTimestamp as aL, dayFromTimestamp as aM, dayToString as aN, dayFromParts as aO, dayFromString as aP, dayMonthStart as aQ, dayYearStart as aR, dayOffset as aS, dayDiff as aT, dayRange as aU, dayIterator as aV, DayInputLegacy as aW, Day as aX, forEachDay as aY, today as aZ, day as a_, fromBase64String as aa, equalBinary as ab, jsonToUint8Array as ac, Uint8ArrayToJson as ad, Uint8ArrayToHexDump as ae, toCamelCase as af, toCapitalize as ag, toCapitalizeWords as ah, fromCamelCase as ai, stringToBoolean as aj, stringToInteger as ak, stringToFloat as al, valueToBoolean as am, valueToInteger as an, valueToFloat as ao, valueToString as ap, toFloat as aq, toInt as ar, toString as as, toBool as at, RenderMessagesOptions as au, formatMessages as av, renderMessages as aw, fixBrokenUth8String as ax, DAY_MS as ay, DayValue as az, LogLevelAliasType as b, roundHalfAwayFromZero as b$, DecimalValue as b0, DecimalInput as b1, decimal as b2, decimalFromCents as b3, decimalToCents as b4, decimalCentsPart as b5, deepEqual as b6, deepStripUndefinedInPlace as b7, deepMerge as b8, escapeHTML as b9, getSecureRandom as bA, getSecureRandomIfPossible as bB, randomBoolean as bC, randomInt as bD, randomFloat as bE, between as bF, sum as bG, avg as bH, isPrimeRX as bI, isPrime as bJ, seededRandom as bK, objectMap as bL, objectMergeDisposable as bM, objectIsEmpty as bN, parseOrderby as bO, composeOrderby as bP, cmp as bQ, sortedOrderby as bR, toValidFilename as bS, escapeRegExp as bT, RoundingMode as bU, isHalf as bV, isEven as bW, roundUp as bX, roundDown as bY, roundHalfUp as bZ, roundHalfOdd as b_, unescapeHTML as ba, Primitive as bb, isObject as bc, isPrimitive as bd, isArray as be, isRecord as bf, isRecordPlain as bg, isString as bh, isNumber as bi, isInteger as bj, isSafeInteger as bk, isBoolean as bl, isNullOrUndefined as bm, isNull as bn, isUint8Array as bo, isNotNull as bp, isValue as bq, jsonStringifySorted as br, jsonStringifySafe as bs, jsonStringify as bt, FilterFunction as bu, MapperFunction as bv, listQuery as bw, listGroupBy as bx, listDistinctUnion as by, listOfKey as bz, LoggerInterface as c,
|
|
1139
|
+
export { _encodeUtf8Polyfill as $, arraySortedNumbers as A, arrayIsEqual as B, CRYPTO_DEFAULT_HASH_ALG as C, arrayShuffleInPlace as D, arrayShuffle as E, arrayShuffleForce as F, arrayRandomElement as G, arrayMax as H, arrayMin as I, Json as J, arraySum as K, LogHandlerOptions as L, arrayAvg as M, arrayBatches as N, ObjectStorage as O, createArray as P, encodeBase32 as Q, decodeBase32 as R, useBase as S, encodeBase16 as T, decodeBase16 as U, encodeBase58 as V, decodeBase58 as W, encodeBase62 as X, decodeBase62 as Y, estimateSizeForBase as Z, BinInput as _, LogHandler as a, dateStringToDays as a$, _decodeUtf8Polyfill as a0, stringToUInt8Array as a1, Uint8ArrayToString as a2, toUint8Array as a3, joinToUint8Array as a4, toHex as a5, fromHex as a6, toBase64 as a7, toBase64Url as a8, fromBase64 as a9, DayInput as aA, dayYear as aB, dayMonth as aC, dayDay as aD, dayToParts as aE, dayToDate as aF, dayFromToday as aG, dayFromAny as aH, dayToDateGMT as aI, dayFromDate as aJ, dayFromDateGMT as aK, dayToTimestamp as aL, dayFromTimestamp as aM, dayToString as aN, dayFromParts as aO, dayFromString as aP, dayMonthStart as aQ, dayYearStart as aR, dayOffset as aS, dayDiff as aT, dayRange as aU, dayIterator as aV, DayInputLegacy as aW, Day as aX, forEachDay as aY, today as aZ, day as a_, fromBase64String as aa, equalBinary as ab, jsonToUint8Array as ac, Uint8ArrayToJson as ad, Uint8ArrayToHexDump as ae, toCamelCase as af, toCapitalize as ag, toCapitalizeWords as ah, fromCamelCase as ai, stringToBoolean as aj, stringToInteger as ak, stringToFloat as al, valueToBoolean as am, valueToInteger as an, valueToFloat as ao, valueToString as ap, toFloat as aq, toInt as ar, toString as as, toBool as at, RenderMessagesOptions as au, formatMessages as av, renderMessages as aw, fixBrokenUth8String as ax, DAY_MS as ay, DayValue as az, LogLevelAliasType as b, roundHalfAwayFromZero as b$, DecimalValue as b0, DecimalInput as b1, decimal as b2, decimalFromCents as b3, decimalToCents as b4, decimalCentsPart as b5, deepEqual as b6, deepStripUndefinedInPlace as b7, deepMerge as b8, escapeHTML as b9, getSecureRandom as bA, getSecureRandomIfPossible as bB, randomBoolean as bC, randomInt as bD, randomFloat as bE, between as bF, sum as bG, avg as bH, isPrimeRX as bI, isPrime as bJ, seededRandom as bK, objectMap as bL, objectMergeDisposable as bM, objectIsEmpty as bN, parseOrderby as bO, composeOrderby as bP, cmp as bQ, sortedOrderby as bR, toValidFilename as bS, escapeRegExp as bT, RoundingMode as bU, isHalf as bV, isEven as bW, roundUp as bX, roundDown as bY, roundHalfUp as bZ, roundHalfOdd as b_, unescapeHTML as ba, Primitive as bb, isObject as bc, isPrimitive as bd, isArray as be, isRecord as bf, isRecordPlain as bg, isString as bh, isNumber as bi, isInteger as bj, isSafeInteger as bk, isBoolean as bl, isNullOrUndefined as bm, isNull as bn, isUint8Array as bo, isNotNull as bp, isValue as bq, jsonStringifySorted as br, jsonStringifySafe as bs, jsonStringify as bt, FilterFunction as bu, MapperFunction as bv, listQuery as bw, listGroupBy as bx, listDistinctUnion as by, listOfKey as bz, LoggerInterface as c, SerialQueue as c$, roundHalfDown as c0, roundHalfEven as c1, roundHalfTowardsZero as c2, SortableItem as c3, startSortWeight as c4, endSortWeight as c5, moveSortWeight as c6, sortedItems as c7, useSorted as c8, linkifyPlainText as c9, useEventListener as cA, Mutex as cB, AsyncMutex as cC, useMutex as cD, useAsyncMutex as cE, PoolTaskFn as cF, PoolTaskState as cG, PoolTask as cH, PoolTaskIdConflictResolution as cI, PoolTaskEvents as cJ, usePool as cK, Pool as cL, Progress as cM, createPromise as cN, sleep as cO, immediate as cP, timeoutReached as cQ, timeout as cR, timoutError as cS, isTimeout as cT, tryTimeout as cU, waitOn as cV, isPromise as cW, promisify as cX, AsyncReturnType as cY, TaskFn as cZ, TaskEvents as c_, toHumanReadableUrl as ca, encodeQuery as cb, parseQuery as cc, ensureKey as cd, ensureKeyAsync as ce, size as cf, last as cg, empty as ch, cloneObject as ci, cloneJsonObject as cj, memoize as ck, memoizeAsync as cl, forTimes as cm, regExpString as cn, regExpEscape as co, XRX as cp, DisposerFunction as cq, Disposer as cr, Disposable as cs, useDispose as ct, UseDispose as cu, useDisposer as cv, useDefer as cw, UseDefer as cx, useTimeout as cy, useInterval as cz, CRYPTO_DEFAULT_ALG as d, getGlobal as d$, throttle as d0, debounce as d1, getGlobalContext as d2, isLocalHost as d3, getGlobalLogger as d4, Logger as d5, LogLevel as d6, LogLevelAlias as d7, LogLevelAliasKey as d8, LogMessage as d9, MessageResult as dA, Message as dB, MessagesOptions as dC, MessagesDefaultMethods as dD, MessagesMethods as dE, MessageDefinitions as dF, MessageHub as dG, createPromiseProxy as dH, useMessageHub as dI, PubSub as dJ, usePubSub as dK, ArgumentsType as dL, ReturnType$1 as dM, RPCOptions as dN, RPCFn as dO, RPCReturn as dP, useRPC as dQ, httpMethod as dR, parseBasicAuth as dS, fetchBasic as dT, fetchJson as dU, fetchText as dV, fetchOptionsFormURLEncoded as dW, fetchOptionsJson as dX, fetchOptionsBasicAuth as dY, getWindow as dZ, getNavigator as d_, LoggerContextInterface as da, LoggerContext as db, LoggerConsoleHandler as dc, getNamespaceFilterString as dd, useNamespaceFilter as de, parseLogLevel as df, useLevelFilter as dg, LoggerMemoryHandler as dh, ChannelMessageEvent as di, Channel as dj, LocalChannel as dk, createLocalChannelPair as dl, EmitterHandler as dm, EmitterAllHandler as dn, ListenerSignature as dp, DefaultListener as dq, Emitter as dr, getGlobalEmitter as ds, messages as dt, lazyListener as du, Encoder as dv, NoopEncoder as dw, JsonEncoder as dx, CryptoEncoder as dy, MessageAction as dz, CRYPTO_DEFAULT_DERIVE_ALG as e, detect as e0, isBrowser as e1, platform as e2, useExitHandler as e3, MemStorageOptions as e4, MemStorage as e5, getTimestamp as e6, formatMilliseconds as e7, parseDate as e8, NestedArray as e9, noop as ea, uuidBytes as eb, uuidB62 as ec, uuidEncodeB62 as ed, uuidDecodeB62 as ee, uuidB32 as ef, uuidEncodeB32 as eg, uuidDecodeB32 as eh, uuidv4 as ei, uuidEncodeV4 as ej, uuidDecodeV4 as ek, suidBytes as el, suid as em, suidDate as en, suidBytesDate as eo, uuid32bit as ep, setUuidDefaultEncoding as eq, uuid as er, uuidDecode as es, uuidEncode as et, uuidIsValid as eu, uname as ev, qid as ew, CRYPTO_DEFAULT_DERIVE_ITERATIONS as f, digest as g, deriveKeyPbkdf2 as h, encrypt as i, decrypt as j, csvStringify as k, csvParse as l, csvParseToObjects as m, arrayUnique as n, arrayMinus as o, arrayUnion as p, arrayFlatten as q, randomUint8Array as r, arrayIntersection as s, arraySymmetricDifference as t, arrayRemoveElement as u, arraySetElement as v, arrayFilterInPlace as w, arrayToggleInPlace as x, arrayEmptyInPlace as y, arraySorted as z };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zeed",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.4",
|
|
5
5
|
"description": "🌱 Simple foundation library",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Dirk Holtwick",
|
|
@@ -68,14 +68,14 @@
|
|
|
68
68
|
"@antfu/eslint-config": "^0.35.1",
|
|
69
69
|
"@antfu/ni": "^0.19.0",
|
|
70
70
|
"@types/jest": "^29.4.0",
|
|
71
|
-
"@types/node": "^18.11.
|
|
71
|
+
"@types/node": "^18.11.19",
|
|
72
72
|
"c8": "^7.12.0",
|
|
73
73
|
"cross-fetch": "^3.1.5",
|
|
74
74
|
"esbuild": "^0.17.5",
|
|
75
75
|
"eslint": "^8.33.0",
|
|
76
76
|
"tsup": "^6.5.0",
|
|
77
77
|
"typescript": "^4.9.5",
|
|
78
|
-
"vite": "^4.
|
|
79
|
-
"vitest": "^0.28.
|
|
78
|
+
"vite": "^4.1.1",
|
|
79
|
+
"vitest": "^0.28.4"
|
|
80
80
|
}
|
|
81
81
|
}
|