socket-function 1.1.3 → 1.1.5
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/SocketFunction.d.ts +1 -0
- package/SocketFunction.ts +5 -2
- package/SocketFunctionTypes.d.ts +1 -1
- package/SocketFunctionTypes.ts +2 -1
- package/index.d.ts +84 -3
- package/package.json +1 -1
- package/src/CallFactory.d.ts +5 -0
- package/src/CallFactory.ts +261 -94
- package/src/batching.d.ts +8 -1
- package/src/batching.ts +37 -0
- package/src/callManager.d.ts +1 -1
- package/src/callManager.ts +1 -1
- package/src/lz4/LZ4.d.ts +7 -0
- package/src/lz4/LZ4.ts +32 -0
- package/src/lz4/lz4_wasm_nodejs.d.ts +34 -0
- package/src/lz4/lz4_wasm_nodejs.js +178 -0
- package/src/lz4/lz4_wasm_nodejs_bg.js +94 -0
- package/src/lz4/lz4_wasm_nodejs_bg.wasm +0 -0
- package/src/lz4/lz4_wasm_nodejs_bg.wasm.d.ts +15 -0
package/SocketFunction.d.ts
CHANGED
package/SocketFunction.ts
CHANGED
|
@@ -17,6 +17,7 @@ import cborx from "cbor-x";
|
|
|
17
17
|
import { setFlag } from "./require/compileFlags";
|
|
18
18
|
import { isNode } from "./src/misc";
|
|
19
19
|
import { getPendingCallCount, harvestCallTimes, harvestFailedCallCount } from "./src/CallFactory";
|
|
20
|
+
import { measureWrap } from "./src/profiling/measure";
|
|
20
21
|
|
|
21
22
|
setFlag(require, "cbor-x", "allowclient", true);
|
|
22
23
|
let cborxInstance = new cborx.Encoder({ structuredClone: true });
|
|
@@ -60,6 +61,8 @@ export class SocketFunction {
|
|
|
60
61
|
|
|
61
62
|
public static HTTP_COMPRESS = false;
|
|
62
63
|
|
|
64
|
+
public static LEGACY_INITIALIZE = false;
|
|
65
|
+
|
|
63
66
|
// If you have HTTP resources that require cookies you might to set `SocketFunction.COEP = "require-corp"`
|
|
64
67
|
// - Cross-origin-resource-policy.
|
|
65
68
|
public static COEP = "credentialless";
|
|
@@ -70,8 +73,8 @@ export class SocketFunction {
|
|
|
70
73
|
// before it is changed, things just break. Also, it needs to be changed on both sides,
|
|
71
74
|
// or else things break. Also, it is very hard to detect when the issue is different serializers
|
|
72
75
|
public static readonly WIRE_SERIALIZER = {
|
|
73
|
-
serialize: (obj: unknown): MaybePromise<Buffer[]> => [cborxInstance.encode(obj)],
|
|
74
|
-
deserialize: (buffers: Buffer[]): MaybePromise<unknown> => cborxInstance.decode(buffers[0]),
|
|
76
|
+
serialize: measureWrap((obj: unknown): MaybePromise<Buffer[]> => [cborxInstance.encode(obj)], "WIRE_SERIALIZER|serialize"),
|
|
77
|
+
deserialize: measureWrap((buffers: Buffer[]): MaybePromise<unknown> => cborxInstance.decode(buffers[0]), "WIRE_SERIALIZER|deserialize"),
|
|
75
78
|
};
|
|
76
79
|
|
|
77
80
|
public static WIRE_WARN_TIME = 100;
|
package/SocketFunctionTypes.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type SocketExposedInterfaceClass = {
|
|
|
16
16
|
prototype: unknown;
|
|
17
17
|
};
|
|
18
18
|
export type FunctionFlags = {
|
|
19
|
-
compress?: boolean;
|
|
19
|
+
compress?: boolean | "LZ4";
|
|
20
20
|
/** Indicates with the same input, we give the same output, forever,
|
|
21
21
|
* independent of code changes. This only works for data storage.
|
|
22
22
|
*/
|
package/SocketFunctionTypes.ts
CHANGED
|
@@ -23,7 +23,8 @@ export type SocketExposedInterfaceClass = {
|
|
|
23
23
|
prototype: unknown;
|
|
24
24
|
};
|
|
25
25
|
export type FunctionFlags = {
|
|
26
|
-
|
|
26
|
+
// If the other side of the connection supports it, this will default to LZ4. True will also remap to LZ4, the only way to turn it off is by setting false.
|
|
27
|
+
compress?: boolean | "LZ4";
|
|
27
28
|
|
|
28
29
|
/** Indicates with the same input, we give the same output, forever,
|
|
29
30
|
* independent of code changes. This only works for data storage.
|
package/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ declare module "socket-function/SocketFunction" {
|
|
|
31
31
|
static HTTP_ETAG_CACHE: boolean;
|
|
32
32
|
static silent: boolean;
|
|
33
33
|
static HTTP_COMPRESS: boolean;
|
|
34
|
+
static LEGACY_INITIALIZE: boolean;
|
|
34
35
|
static COEP: string;
|
|
35
36
|
static COOP: string;
|
|
36
37
|
static readonly WIRE_SERIALIZER: {
|
|
@@ -133,7 +134,7 @@ declare module "socket-function/SocketFunctionTypes" {
|
|
|
133
134
|
prototype: unknown;
|
|
134
135
|
};
|
|
135
136
|
export type FunctionFlags = {
|
|
136
|
-
compress?: boolean;
|
|
137
|
+
compress?: boolean | "LZ4";
|
|
137
138
|
/** Indicates with the same input, we give the same output, forever,
|
|
138
139
|
* independent of code changes. This only works for data storage.
|
|
139
140
|
*/
|
|
@@ -463,6 +464,7 @@ declare module "socket-function/src/CallFactory" {
|
|
|
463
464
|
lastClosed: number;
|
|
464
465
|
closedForever?: boolean;
|
|
465
466
|
isConnected?: boolean;
|
|
467
|
+
receivedInitializeState?: InitializeState;
|
|
466
468
|
performCall(call: CallType): Promise<unknown>;
|
|
467
469
|
onNextDisconnect(callback: () => void): void;
|
|
468
470
|
connectionId: {
|
|
@@ -482,6 +484,9 @@ declare module "socket-function/src/CallFactory" {
|
|
|
482
484
|
readyState: number;
|
|
483
485
|
ping?(): void;
|
|
484
486
|
}
|
|
487
|
+
type InitializeState = {
|
|
488
|
+
supportsLZ4?: boolean;
|
|
489
|
+
};
|
|
485
490
|
export declare function harvestFailedCallCount(): number;
|
|
486
491
|
export declare function getPendingCallCount(): number;
|
|
487
492
|
export declare function harvestCallTimes(): {
|
|
@@ -489,6 +494,7 @@ declare module "socket-function/src/CallFactory" {
|
|
|
489
494
|
end: number;
|
|
490
495
|
}[];
|
|
491
496
|
export declare function createCallFactory(webSocketBase: SenderInterface | undefined, nodeId: string, localNodeId?: string): Promise<CallFactory>;
|
|
497
|
+
export {};
|
|
492
498
|
|
|
493
499
|
}
|
|
494
500
|
|
|
@@ -559,7 +565,7 @@ declare module "socket-function/src/args" {
|
|
|
559
565
|
}
|
|
560
566
|
|
|
561
567
|
declare module "socket-function/src/batching" {
|
|
562
|
-
import { AnyFunction } from "socket-function/src/types";
|
|
568
|
+
import { AnyFunction, MaybePromise } from "socket-function/src/types";
|
|
563
569
|
export type DelayType = (number | "afterio" | "immediate" | "afterpromises" | "paintLoop" | "afterPaint");
|
|
564
570
|
export declare function delay(delayTime: DelayType, immediateShortDelays?: "immediateShortDelays"): Promise<void>;
|
|
565
571
|
export declare function batchFunctionNone<Arg, Result = void>(config: unknown, fnc: (arg: Arg[]) => (Promise<Result> | Result)): (arg: Arg) => Promise<Result>;
|
|
@@ -590,6 +596,13 @@ declare module "socket-function/src/batching" {
|
|
|
590
596
|
minDelay?: number;
|
|
591
597
|
maxDelay?: number;
|
|
592
598
|
}): T;
|
|
599
|
+
export declare const safeLoop: typeof unblockLoop;
|
|
600
|
+
export declare const throttledLoop: typeof unblockLoop;
|
|
601
|
+
export declare function unblockLoop<T, R>(config: {
|
|
602
|
+
data: T[];
|
|
603
|
+
maxBlockingTime?: number;
|
|
604
|
+
backOffTime?: number;
|
|
605
|
+
} | T[], fnc: (item: T) => MaybePromise<R>): Promise<R[]>;
|
|
593
606
|
|
|
594
607
|
}
|
|
595
608
|
|
|
@@ -690,7 +703,7 @@ declare module "socket-function/src/callManager" {
|
|
|
690
703
|
/// <reference path="../hot/HotReloadController.d.ts" />
|
|
691
704
|
import { CallerContext, CallType, ClientHookContext, FullCallType, FunctionFlags, HookContext, SocketExposedInterface, SocketExposedShape, SocketFunctionClientHook, SocketFunctionHook, SocketRegistered } from "socket-function/SocketFunctionTypes";
|
|
692
705
|
export declare function getCallFlags(call: CallType): FunctionFlags | undefined;
|
|
693
|
-
export declare function shouldCompressCall(call: CallType): boolean;
|
|
706
|
+
export declare function shouldCompressCall(call: CallType): boolean | "LZ4" | undefined;
|
|
694
707
|
export declare function performLocalCall(config: {
|
|
695
708
|
call: FullCallType;
|
|
696
709
|
caller: CallerContext;
|
|
@@ -837,6 +850,74 @@ declare module "socket-function/src/https" {
|
|
|
837
850
|
|
|
838
851
|
}
|
|
839
852
|
|
|
853
|
+
declare module "socket-function/src/lz4/LZ4" {
|
|
854
|
+
/// <reference types="node" />
|
|
855
|
+
/// <reference types="node" />
|
|
856
|
+
export declare class LZ4 {
|
|
857
|
+
static compress(data: Buffer): Buffer;
|
|
858
|
+
static compressUntracked(data: Buffer): Buffer;
|
|
859
|
+
static decompress(data: Buffer): Buffer;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
declare module "socket-function/src/lz4/lz4_wasm_nodejs" {
|
|
865
|
+
/* tslint:disable */
|
|
866
|
+
/* eslint-disable */
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Streaming LZ4 compressor (frame format with linked blocks).
|
|
870
|
+
* Concatenate all output chunks to form a complete LZ4 frame.
|
|
871
|
+
*/
|
|
872
|
+
export class Lz4StreamCompressor {
|
|
873
|
+
free(): void;
|
|
874
|
+
[Symbol.dispose](): void;
|
|
875
|
+
compress(input: Uint8Array): Uint8Array;
|
|
876
|
+
constructor();
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* One-shot block compression with size prepended.
|
|
881
|
+
*/
|
|
882
|
+
export function compress(input: Uint8Array): Uint8Array;
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* One-shot block decompression with size prepended.
|
|
886
|
+
*/
|
|
887
|
+
export function decompress(input: Uint8Array): Uint8Array;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Decompress an LZ4 stream (frame format).
|
|
891
|
+
* Auto-injects end marker if missing. On error, returns partial data and sets a warning.
|
|
892
|
+
*/
|
|
893
|
+
export function decompress_stream(input: Uint8Array): Uint8Array;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Get and clear the last warning from decompression.
|
|
897
|
+
*/
|
|
898
|
+
export function get_last_warning(): string | undefined;
|
|
899
|
+
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
declare module "socket-function/src/lz4/lz4_wasm_nodejs_bg.wasm" {
|
|
903
|
+
/* tslint:disable */
|
|
904
|
+
/* eslint-disable */
|
|
905
|
+
export const memory: WebAssembly.Memory;
|
|
906
|
+
export const __wbg_lz4streamcompressor_free: (a: number, b: number) => void;
|
|
907
|
+
export const compress: (a: number, b: number) => [number, number];
|
|
908
|
+
export const decompress: (a: number, b: number) => [number, number, number, number];
|
|
909
|
+
export const decompress_stream: (a: number, b: number) => [number, number];
|
|
910
|
+
export const get_last_warning: () => [number, number];
|
|
911
|
+
export const lz4streamcompressor_compress: (a: number, b: number, c: number) => [number, number];
|
|
912
|
+
export const lz4streamcompressor_new: () => number;
|
|
913
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
914
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
915
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
916
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
917
|
+
export const __wbindgen_start: () => void;
|
|
918
|
+
|
|
919
|
+
}
|
|
920
|
+
|
|
840
921
|
declare module "socket-function/src/misc" {
|
|
841
922
|
/// <reference types="node" />
|
|
842
923
|
/// <reference types="node" />
|
package/package.json
CHANGED
package/src/CallFactory.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface CallFactory {
|
|
|
9
9
|
lastClosed: number;
|
|
10
10
|
closedForever?: boolean;
|
|
11
11
|
isConnected?: boolean;
|
|
12
|
+
receivedInitializeState?: InitializeState;
|
|
12
13
|
performCall(call: CallType): Promise<unknown>;
|
|
13
14
|
onNextDisconnect(callback: () => void): void;
|
|
14
15
|
connectionId: {
|
|
@@ -28,6 +29,9 @@ export interface SenderInterface {
|
|
|
28
29
|
readyState: number;
|
|
29
30
|
ping?(): void;
|
|
30
31
|
}
|
|
32
|
+
type InitializeState = {
|
|
33
|
+
supportsLZ4?: boolean;
|
|
34
|
+
};
|
|
31
35
|
export declare function harvestFailedCallCount(): number;
|
|
32
36
|
export declare function getPendingCallCount(): number;
|
|
33
37
|
export declare function harvestCallTimes(): {
|
|
@@ -35,3 +39,4 @@ export declare function harvestCallTimes(): {
|
|
|
35
39
|
end: number;
|
|
36
40
|
}[];
|
|
37
41
|
export declare function createCallFactory(webSocketBase: SenderInterface | undefined, nodeId: string, localNodeId?: string): Promise<CallFactory>;
|
|
42
|
+
export {};
|