socket-function 0.160.0 → 0.161.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -417,114 +417,6 @@ declare module "socket-function/index" {
417
417
 
418
418
  }
419
419
 
420
- declare module "socket-function/SocketFunction" {
421
- /// <reference path="require/RequireController.d.ts" />
422
- /// <reference types="node" />
423
- /// <reference types="node" />
424
- import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, SocketRegisterType } from "./SocketFunctionTypes";
425
- import { SocketServerConfig } from "./src/webSocketServer";
426
- import { Args, MaybePromise } from "./src/types";
427
- import "./SetProcessVariables";
428
- type ExtractShape<ClassType, Shape> = {
429
- [key in keyof ClassType]: (key extends keyof Shape ? ClassType[key] extends SocketExposedInterface[""] ? ClassType[key] : ClassType[key] extends Function ? "All exposed function must be async (or return a Promise)" : never : "Function has implementation but is not exposed in the SocketFunction.register call");
430
- };
431
- export declare class SocketFunction {
432
- static logMessages: boolean;
433
- static trackMessageSizes: {
434
- upload: ((size: number) => void)[];
435
- download: ((size: number) => void)[];
436
- callTimes: ((obj: {
437
- start: number;
438
- end: number;
439
- }) => void)[];
440
- };
441
- static MAX_MESSAGE_SIZE: number;
442
- static HTTP_ETAG_CACHE: boolean;
443
- static silent: boolean;
444
- static HTTP_COMPRESS: boolean;
445
- static COEP: string;
446
- static COOP: string;
447
- static readonly WIRE_SERIALIZER: {
448
- serialize: (obj: unknown) => MaybePromise<Buffer[]>;
449
- deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
450
- };
451
- static WIRE_WARN_TIME: number;
452
- private static onMountCallbacks;
453
- static exposedClasses: Set<string>;
454
- static callerContext: CallerContext | undefined;
455
- static getCaller(): CallerContext;
456
- static harvestFailedCallCount: () => number;
457
- static getPendingCallCount: () => number;
458
- static harvestCallTimes: () => {
459
- start: number;
460
- end: number;
461
- }[];
462
- static register<ClassInstance extends object, Shape extends SocketExposedShape<{
463
- [key in keyof ClassInstance]: (...args: any[]) => Promise<unknown>;
464
- }>, Statics>(classGuid: string, instance: ClassInstance | (() => ClassInstance), shapeFnc: () => Shape, defaultHooksFnc?: () => SocketExposedShape[""] & {
465
- onMount?: () => MaybePromise<void>;
466
- }, config?: {
467
- /** @noAutoExpose If true SocketFunction.expose(Controller) must be called explicitly. */
468
- noAutoExpose?: boolean;
469
- statics?: Statics;
470
- /** Skip timing functions calls. Useful if a lot of functions have wait time that
471
- is unrelated to processing, and therefore their timings won't be useful.
472
- - Also useful if our auto function wrapping code is breaking functionality,
473
- such as if you have a singleton function which you compare with ===,
474
- which will breaks because we replaced it with a wrapped measure function.
475
- */
476
- noFunctionMeasure?: boolean;
477
- }): SocketRegistered<ExtractShape<ClassInstance, Shape>> & Statics;
478
- private static socketCache;
479
- static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
480
- private static callFromGuid;
481
- static onNextDisconnect(nodeId: string, callback: () => void): void;
482
- static getLastDisconnectTime(nodeId: string): number | undefined;
483
- static isNodeConnected(nodeId: string): boolean;
484
- /** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
485
- * as we have no way of knowing how to contain a nodeId).
486
- * */
487
- static getHTTPCallLink(call: FullCallType): string;
488
- private static ignoreExposeCount;
489
- static ignoreExposeCalls<T>(code: () => Promise<T>): Promise<T>;
490
- /** Expose should be called before your mounting occurs. It mostly just exists to ensure you include the class type,
491
- * so the class type's module construction runs, which should trigger register. Otherwise you would have
492
- * to add additional imports to ensure the register call runs.
493
- */
494
- static expose(socketRegistered: SocketRegistered): void;
495
- static mountedNodeId: string;
496
- static isMounted(): boolean;
497
- static mountedIP: string;
498
- private static hasMounted;
499
- private static onMountCallback;
500
- static mountPromise: Promise<void>;
501
- static mount(config: SocketServerConfig): Promise<string>;
502
- /** Sets the default call when an http request is made, but no classGuid is set.
503
- * NOTE: All other calls should be endpoint calls, even if those endpoints return a static file with an HTML content type.
504
- * - However, to load new content, you should probably just use `require("./example.ts")`, which works on any files
505
- * clientside that have also been required serverside (and whitelisted with module.allowclient = true,
506
- * or with an `allowclient.flag` file in the directory or parent directory).
507
- */
508
- static setDefaultHTTPCall<Registered extends SocketRegistered, FunctionName extends keyof Registered["nodes"][""] & string>(registered: Registered, functionName: FunctionName, ...args: Args<Registered["nodes"][""][FunctionName]>): void;
509
- static connect(location: {
510
- address: string;
511
- port: number;
512
- }): string;
513
- static browserNodeId(): string;
514
- static getBrowserNodeId(): string;
515
- static addGlobalHook(hook: SocketFunctionHook): void;
516
- static addGlobalClientHook(hook: SocketFunctionClientHook): void;
517
- }
518
- declare global {
519
- var BOOTED_EDGE_NODE: {
520
- host: string;
521
- } | undefined;
522
- }
523
- export declare function _setSocketContext<T>(caller: CallerContext, code: () => T): T;
524
- export {};
525
-
526
- }
527
-
528
420
  declare module "socket-function/SocketFunctionTypes" {
529
421
  /// <reference path="require/RequireController.d.ts" />
530
422
  import { getCallObj } from "./src/nodeProxy";
@@ -671,7 +563,7 @@ declare module "socket-function/index" {
671
563
  import { Args, MaybePromise } from "./src/types";
672
564
  import "./SetProcessVariables";
673
565
  type ExtractShape<ClassType, Shape> = {
674
- [key in keyof ClassType]: (key extends keyof Shape ? ClassType[key] extends SocketExposedInterface[""] ? ClassType[key] : ClassType[key] extends Function ? "All exposed function must be async (or return a Promise)" : never : "Function is in shape, but not in class");
566
+ [key in keyof ClassType]: (key extends keyof Shape ? ClassType[key] extends SocketExposedInterface[""] ? ClassType[key] : ClassType[key] extends Function ? "All exposed function must be async (or return a Promise)" : never : "Function has implementation but is not exposed in the SocketFunction.register call");
675
567
  };
676
568
  export declare class SocketFunction {
677
569
  static logMessages: boolean;
@@ -899,49 +791,1215 @@ declare module "socket-function/index" {
899
791
  }
900
792
 
901
793
  declare module "socket-function/index" {
902
- /// <reference path="./node_modules/typenode/index.d.ts" />
794
+ // Auto-generated file. Do not edit manually.
795
+ // Generated by: yarn generate-index-dts
903
796
 
904
- export { };
797
+ declare module "socket-function/SetProcessVariables" {
798
+ export {};
905
799
 
906
- declare global {
907
- namespace NodeJS {
908
- interface Module {
909
- original?: SerializedModule;
800
+ }
801
+
802
+ declare module "socket-function/SocketFunction" {
803
+ /// <reference path="require/RequireController.d.ts" />
804
+ /// <reference types="node" />
805
+ /// <reference types="node" />
806
+ import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, SocketRegisterType } from "./SocketFunctionTypes";
807
+ import { SocketServerConfig } from "./src/webSocketServer";
808
+ import { Args, MaybePromise } from "./src/types";
809
+ import "./SetProcessVariables";
810
+ type ExtractShape<ClassType, Shape> = {
811
+ [key in keyof ClassType]: (key extends keyof Shape ? ClassType[key] extends SocketExposedInterface[""] ? ClassType[key] : ClassType[key] extends Function ? "All exposed function must be async (or return a Promise)" : never : "Function is in shape, but not in class");
812
+ };
813
+ export declare class SocketFunction {
814
+ static logMessages: boolean;
815
+ static trackMessageSizes: {
816
+ upload: ((size: number) => void)[];
817
+ download: ((size: number) => void)[];
818
+ callTimes: ((obj: {
819
+ start: number;
820
+ end: number;
821
+ }) => void)[];
822
+ };
823
+ static MAX_MESSAGE_SIZE: number;
824
+ static HTTP_ETAG_CACHE: boolean;
825
+ static silent: boolean;
826
+ static HTTP_COMPRESS: boolean;
827
+ static COEP: string;
828
+ static COOP: string;
829
+ static readonly WIRE_SERIALIZER: {
830
+ serialize: (obj: unknown) => MaybePromise<Buffer[]>;
831
+ deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
832
+ };
833
+ static WIRE_WARN_TIME: number;
834
+ private static onMountCallbacks;
835
+ static exposedClasses: Set<string>;
836
+ static callerContext: CallerContext | undefined;
837
+ static getCaller(): CallerContext;
838
+ static harvestFailedCallCount: () => number;
839
+ static getPendingCallCount: () => number;
840
+ static harvestCallTimes: () => {
841
+ start: number;
842
+ end: number;
843
+ }[];
844
+ static register<ClassInstance extends object, Shape extends SocketExposedShape<{
845
+ [key in keyof ClassInstance]: (...args: any[]) => Promise<unknown>;
846
+ }>, Statics>(classGuid: string, instance: ClassInstance | (() => ClassInstance), shapeFnc: () => Shape, defaultHooksFnc?: () => SocketExposedShape[""] & {
847
+ onMount?: () => MaybePromise<void>;
848
+ }, config?: {
849
+ /** @noAutoExpose If true SocketFunction.expose(Controller) must be called explicitly. */
850
+ noAutoExpose?: boolean;
851
+ statics?: Statics;
852
+ /** Skip timing functions calls. Useful if a lot of functions have wait time that
853
+ is unrelated to processing, and therefore their timings won't be useful.
854
+ - Also useful if our auto function wrapping code is breaking functionality,
855
+ such as if you have a singleton function which you compare with ===,
856
+ which will breaks because we replaced it with a wrapped measure function.
857
+ */
858
+ noFunctionMeasure?: boolean;
859
+ }): SocketRegistered<ExtractShape<ClassInstance, Shape>> & Statics;
860
+ private static socketCache;
861
+ static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
862
+ private static callFromGuid;
863
+ static onNextDisconnect(nodeId: string, callback: () => void): void;
864
+ static getLastDisconnectTime(nodeId: string): number | undefined;
865
+ static isNodeConnected(nodeId: string): boolean;
866
+ /** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
867
+ * as we have no way of knowing how to contain a nodeId).
868
+ * */
869
+ static getHTTPCallLink(call: FullCallType): string;
870
+ private static ignoreExposeCount;
871
+ static ignoreExposeCalls<T>(code: () => Promise<T>): Promise<T>;
872
+ /** Expose should be called before your mounting occurs. It mostly just exists to ensure you include the class type,
873
+ * so the class type's module construction runs, which should trigger register. Otherwise you would have
874
+ * to add additional imports to ensure the register call runs.
875
+ */
876
+ static expose(socketRegistered: SocketRegistered): void;
877
+ static mountedNodeId: string;
878
+ static isMounted(): boolean;
879
+ static mountedIP: string;
880
+ private static hasMounted;
881
+ private static onMountCallback;
882
+ static mountPromise: Promise<void>;
883
+ static mount(config: SocketServerConfig): Promise<string>;
884
+ /** Sets the default call when an http request is made, but no classGuid is set.
885
+ * NOTE: All other calls should be endpoint calls, even if those endpoints return a static file with an HTML content type.
886
+ * - However, to load new content, you should probably just use `require("./example.ts")`, which works on any files
887
+ * clientside that have also been required serverside (and whitelisted with module.allowclient = true,
888
+ * or with an `allowclient.flag` file in the directory or parent directory).
889
+ */
890
+ static setDefaultHTTPCall<Registered extends SocketRegistered, FunctionName extends keyof Registered["nodes"][""] & string>(registered: Registered, functionName: FunctionName, ...args: Args<Registered["nodes"][""][FunctionName]>): void;
891
+ static connect(location: {
892
+ address: string;
893
+ port: number;
894
+ }): string;
895
+ static browserNodeId(): string;
896
+ static getBrowserNodeId(): string;
897
+ static addGlobalHook(hook: SocketFunctionHook): void;
898
+ static addGlobalClientHook(hook: SocketFunctionClientHook): void;
899
+ }
900
+ declare global {
901
+ var BOOTED_EDGE_NODE: {
902
+ host: string;
903
+ } | undefined;
904
+ }
905
+ export declare function _setSocketContext<T>(caller: CallerContext, code: () => T): T;
906
+ export {};
907
+
908
+ }
909
+
910
+ declare module "socket-function/SocketFunctionTypes" {
911
+ /// <reference path="require/RequireController.d.ts" />
912
+ import { getCallObj } from "./src/nodeProxy";
913
+ import { Args, MaybePromise } from "./src/types";
914
+ export declare const socket: unique symbol;
915
+ export type SocketExposedInterface = {
916
+ [functionName: string]: (...args: any[]) => Promise<unknown>;
917
+ };
918
+ export type SocketInternalInterface = {
919
+ [functionName: string]: {
920
+ [getCallObj]: (...args: any[]) => FullCallType;
921
+ (...args: any[]): Promise<unknown>;
922
+ };
923
+ };
924
+ export type SocketExposedInterfaceClass = {
925
+ new (): unknown;
926
+ prototype: unknown;
927
+ };
928
+ export type FunctionFlags = {
929
+ compress?: boolean;
930
+ /** Indicates with the same input, we give the same output, forever,
931
+ * independent of code changes. This only works for data storage.
932
+ */
933
+ dataImmutable?: boolean;
934
+ /** Allows overriding SocketFunction.MAX_MESSAGE_SIZE for responses from this function. */
935
+ responseLimit?: number;
936
+ };
937
+ export type SocketExposedShape<ExposedType extends SocketExposedInterface = SocketExposedInterface> = {
938
+ [functionName in keyof ExposedType]?: FunctionFlags & {
939
+ hooks?: SocketFunctionHook[];
940
+ clientHooks?: SocketFunctionClientHook[];
941
+ noDefaultHooks?: boolean;
942
+ /** BUG: I think this is broken if it is on the default hooks function? */
943
+ noClientHooks?: boolean;
944
+ };
945
+ };
946
+ export type FncType = (...args: any[]) => Promise<unknown>;
947
+ export interface CallType<FncT extends FncType = FncType, FncName extends string = string> {
948
+ classGuid: string;
949
+ functionName: FncName;
950
+ args: unknown[];
951
+ }
952
+ export interface FullCallType<FncT extends FncType = FncType, FncName extends string = string> extends CallType<FncT, FncName> {
953
+ nodeId: string;
954
+ }
955
+ export interface SocketFunctionHook {
956
+ (config: HookContext): MaybePromise<void>;
957
+ /** NOTE: This is useful when we need a clientside hook to set up state specifically for our serverside hook. */
958
+ clientHook?: SocketFunctionClientHook;
959
+ }
960
+ export type HookContext = {
961
+ call: FullCallType;
962
+ overrideResult?: unknown;
963
+ onResult: ((result: unknown) => MaybePromise<void>)[];
964
+ };
965
+ export type ClientHookContext = {
966
+ call: FullCallType;
967
+ overrideResult?: unknown;
968
+ onResult: ((result: unknown) => MaybePromise<void>)[];
969
+ connectionId: {
970
+ nodeId: string;
971
+ };
972
+ };
973
+ export interface SocketFunctionClientHook {
974
+ (config: ClientHookContext): MaybePromise<void>;
975
+ }
976
+ export interface SocketRegisterType<ExposedType = any> {
977
+ _classGuid: string;
978
+ _internalType: ExposedType;
979
+ }
980
+ export interface SocketRegistered<ExposedType = any> {
981
+ nodes: {
982
+ [nodeId: string]: {
983
+ [functionName in keyof ExposedType]: ExposedType[functionName] & {
984
+ [getCallObj]: (...args: Args<ExposedType[functionName]>) => FullCallType;
985
+ };
986
+ };
987
+ };
988
+ _classGuid: string;
989
+ _internalType: ExposedType;
990
+ }
991
+ export type ControllerPick<T extends SocketRegistered, K extends keyof T["_internalType"]> = (SocketRegistered<Pick<T["_internalType"], K>>);
992
+ export type CallerContext = Readonly<CallerContextBase>;
993
+ export type CallerContextBase = {
994
+ nodeId: string;
995
+ localNodeId: string;
996
+ };
997
+
998
+ }
999
+
1000
+ declare module "socket-function/hot/HotReloadController" {
1001
+ /// <reference path="../../typenode/index.d.ts" />
1002
+ /// <reference path="../require/RequireController.d.ts" />
1003
+ /** Enables some hot reload functionality.
1004
+ * - Triggers a refresh clientside
1005
+ * - Triggers a reload server, for modules marked with `module.hotreload`
1006
+ */
1007
+ export declare function watchFilesAndTriggerHotReloading(noAutomaticBrowserWatch?: boolean): void;
1008
+ declare global {
1009
+ namespace NodeJS {
1010
+ interface Module {
1011
+ /** Causes us to hotreload the file. Applies both serverside and clientside.
1012
+ * - If not set for any files clientside, we will refresh.
1013
+ * - If not set for any files serverside, we will do nothing (and just leave old code running).
1014
+ */
1015
+ hotreload?: boolean;
1016
+ /** Overrides hotreload to disable hot reloading. Useful if you add "hotreload.flag" to a directory
1017
+ * (which sets hotreload on all files in and under that directory), but want a specific file
1018
+ * to not hotreload.
1019
+ * - Also useful if you want files to hotreload clientside, but not serverside.
1020
+ */
1021
+ noserverhotreload?: boolean;
1022
+ watchAdditionalFiles?: string[];
1023
+ }
910
1024
  }
1025
+ var isHotReloading: (() => boolean) | undefined;
911
1026
  }
912
- interface SerializedModule {
913
- originalId: string;
914
- filename: string;
915
- // If a module is not allowed clientside it is likely requests will be empty,
916
- // to save effort parsing requests for modules that only exist to give better
917
- // error messages.
918
- requests: {
919
- // request => resolvedPath
920
- [request: string]: string;
1027
+ export declare function isHotReloading(): boolean;
1028
+ export declare function hotReloadingGuard(): true;
1029
+ export declare function setExternalHotReloading(value: boolean): void;
1030
+ export declare function onHotReload(callback: (modules: NodeJS.Module[]) => void): void;
1031
+ export declare const HotReloadController: import("../SocketFunctionTypes").SocketRegistered<{
1032
+ watchFiles: () => Promise<void>;
1033
+ fileUpdated: (files: string[], changeTime: number) => Promise<void>;
1034
+ }>;
1035
+
1036
+ }
1037
+
1038
+ declare module "socket-function/index" {
1039
+ /// <reference path="./node_modules/typenode/index.d.ts" />
1040
+
1041
+ export { };
1042
+
1043
+ declare global {
1044
+ namespace NodeJS {
1045
+ interface Module {
1046
+ original?: SerializedModule;
1047
+ }
1048
+ }
1049
+ interface SerializedModule {
1050
+ originalId: string;
1051
+ filename: string;
1052
+ // If a module is not allowed clientside it is likely requests will be empty,
1053
+ // to save effort parsing requests for modules that only exist to give better
1054
+ // error messages.
1055
+ requests: {
1056
+ // request => resolvedPath
1057
+ [request: string]: string;
1058
+ };
1059
+ asyncRequests: { [request: string]: true };
1060
+ // NOTE: IF !allowclient && !serveronly, it might just mean we didn't add allowclient
1061
+ // to the module yet. BUT, if serveronly, then we know for sure we don't want it client.
1062
+ // So the messages and behavior will be different.
1063
+ allowclient?: boolean;
1064
+ serveronly?: boolean;
1065
+ // Just for errors mostly
1066
+ alwayssend?: boolean;
1067
+
1068
+ /** Only set if allowclient. */
1069
+ source?: string;
1070
+
1071
+ seqNum: number;
1072
+
1073
+ size?: number;
1074
+ version?: number;
1075
+
1076
+ flags?: {
1077
+ [flag: string]: true;
1078
+ };
1079
+ }
1080
+
1081
+ }
1082
+ }
1083
+
1084
+ declare module "socket-function/mobx/UrlParam" {
1085
+ export declare class UrlParam<T> {
1086
+ private key;
1087
+ private defaultValue;
1088
+ constructor(key: string, defaultValue: T);
1089
+ valueSeqNum: {
1090
+ value: number;
921
1091
  };
922
- asyncRequests: { [request: string]: true };
923
- // NOTE: IF !allowclient && !serveronly, it might just mean we didn't add allowclient
924
- // to the module yet. BUT, if serveronly, then we know for sure we don't want it client.
925
- // So the messages and behavior will be different.
926
- allowclient?: boolean;
927
- serveronly?: boolean;
928
- // Just for errors mostly
929
- alwayssend?: boolean;
1092
+ get(): T;
1093
+ set(value: T): void;
1094
+ reset(): void;
1095
+ get value(): T;
1096
+ set value(value: T);
1097
+ }
930
1098
 
931
- /** Only set if allowclient. */
932
- source?: string;
1099
+ }
933
1100
 
934
- seqNum: number;
1101
+ declare module "socket-function/mobx/observer" {
1102
+ import type preact from "preact";
1103
+ import { Reaction } from "mobx";
1104
+ export declare function observer<T extends {
1105
+ new (...args: any[]): {
1106
+ render(): preact.ComponentChild;
1107
+ forceUpdate(callback?: () => void): void;
1108
+ componentWillUnmount?(): void;
1109
+ };
1110
+ }>(Constructor: T): {
1111
+ new (...args: any[]): {
1112
+ constructOrder: number;
1113
+ reaction: Reaction;
1114
+ componentWillUnmount(): void;
1115
+ render(): preact.ComponentChild;
1116
+ forceUpdate(callback?: () => void): void;
1117
+ };
1118
+ readonly name: string;
1119
+ } & T;
935
1120
 
936
- size?: number;
937
- version?: number;
1121
+ }
938
1122
 
939
- flags?: {
940
- [flag: string]: true;
1123
+ declare module "socket-function/mobx/promiseToObservable" {
1124
+ export interface InternalResult {
1125
+ result: {
1126
+ value: unknown;
1127
+ } | undefined;
1128
+ }
1129
+ export declare function promiseToObservable<T>(promise: Promise<T>, staleValue?: T): {
1130
+ value: T | undefined;
1131
+ };
1132
+
1133
+ }
1134
+
1135
+ declare module "socket-function/require/CSSShim" {
1136
+ /// <reference path="RequireController.d.ts" />
1137
+ export {};
1138
+
1139
+ }
1140
+
1141
+ declare module "socket-function/require/compileFlags" {
1142
+ /// <reference path="RequireController.d.ts" />
1143
+ /// <reference types="node" />
1144
+ /**
1145
+ * Adds a global function setFlag(require, "typescript", flag) which sets a flag on the client
1146
+ * - Ex, setFlag(require, "typescript", "allowclient") so allowclient = true on the typescript module.
1147
+ * - Passing true as the fourth argument sets it recursively
1148
+ */
1149
+ export declare const forceModule = true;
1150
+ declare global {
1151
+ }
1152
+ export declare function setFlag(require: NodeRequire, request: string, flag: string, recursive?: boolean): void;
1153
+
1154
+ }
1155
+
1156
+ declare module "socket-function/require/extMapper" {
1157
+ /// <reference types="node" />
1158
+ /// <reference types="node" />
1159
+ export declare function getExtContentType(ext: string): string;
1160
+ export declare function getContentTypeFromBuffer(buffer: Buffer): string | undefined;
1161
+
1162
+ }
1163
+
1164
+ declare module "socket-function/require/require" {
1165
+ /// <reference path="../index.d.ts" />
1166
+ declare global {
1167
+ var onProgressHandler: undefined | ((progress: {
1168
+ type: string;
1169
+ addValue: number;
1170
+ addMax: number;
1171
+ }) => void);
1172
+ var onErrorHandler: undefined | ((error: string) => void);
1173
+ var BOOT_TIME: number;
1174
+ var builtInModuleExports: {
1175
+ [key: string]: unknown;
1176
+ };
1177
+ }
1178
+ export declare function requireMain(): void;
1179
+
1180
+ }
1181
+
1182
+ declare module "socket-function/src/CallFactory" {
1183
+ /// <reference types="node" />
1184
+ /// <reference types="node" />
1185
+ /// <reference types="node" />
1186
+ import { CallType } from "../SocketFunctionTypes";
1187
+ import * as ws from "ws";
1188
+ import * as tls from "tls";
1189
+ export interface CallFactory {
1190
+ nodeId: string;
1191
+ lastClosed: number;
1192
+ closedForever?: boolean;
1193
+ isConnected?: boolean;
1194
+ performCall(call: CallType): Promise<unknown>;
1195
+ onNextDisconnect(callback: () => void): void;
1196
+ connectionId: {
1197
+ nodeId: string;
941
1198
  };
942
1199
  }
1200
+ export interface SenderInterface {
1201
+ nodeId?: string;
1202
+ _socket?: tls.TLSSocket;
1203
+ send(data: string | Buffer): void;
1204
+ addEventListener(event: "open", listener: () => void): void;
1205
+ addEventListener(event: "close", listener: () => void): void;
1206
+ addEventListener(event: "error", listener: (err: {
1207
+ message: string;
1208
+ }) => void): void;
1209
+ addEventListener(event: "message", listener: (data: ws.RawData | ws.MessageEvent | string) => void): void;
1210
+ readyState: number;
1211
+ ping?(): void;
1212
+ }
1213
+ export declare function harvestFailedCallCount(): number;
1214
+ export declare function getPendingCallCount(): number;
1215
+ export declare function harvestCallTimes(): {
1216
+ start: number;
1217
+ end: number;
1218
+ }[];
1219
+ export declare function createCallFactory(webSocketBase: SenderInterface | undefined, nodeId: string, localNodeId?: string): Promise<CallFactory>;
943
1220
 
944
1221
  }
1222
+
1223
+ declare module "socket-function/src/JSONLACKS/JSONLACKS" {
1224
+ /// <reference types="node" />
1225
+ /// <reference types="node" />
1226
+ export interface JSONLACKS_ParseConfig {
1227
+ extended?: boolean;
1228
+ discardMissingReferences?: boolean;
1229
+ }
1230
+ export interface JSONLACKS_StringifyConfig {
1231
+ allowObjectMutation?: boolean;
1232
+ }
1233
+ interface HydrateState {
1234
+ references: Map<string, unknown>;
1235
+ visited: Set<unknown>;
1236
+ }
1237
+ export declare class JSONLACKS {
1238
+ static readonly LACKS_KEY = "__JSONLACKS__98cfb4a05fa34d828661cae15b8779ce__";
1239
+ /** If set to true parses non-quoted field names, comments, trailing commas, etc */
1240
+ static EXTENDED_PARSER: boolean;
1241
+ static IGNORE_MISSING_REFERENCES: boolean;
1242
+ static stringify(obj: unknown, config?: JSONLACKS_StringifyConfig): string;
1243
+ /** Is useful when serializing an array to a file with one object per line */
1244
+ static stringifyFile(obj: unknown[], config?: JSONLACKS_StringifyConfig): Promise<Buffer>;
1245
+ static stringifyFileSync(obj: unknown[], config?: JSONLACKS_StringifyConfig): Buffer;
1246
+ static parse<T>(text: string, config?: JSONLACKS_ParseConfig, hydrateState?: HydrateState): T;
1247
+ static parseLines<T>(buffer: Buffer, config?: JSONLACKS_ParseConfig): Promise<T[]>;
1248
+ private static escapeSpecialObjects;
1249
+ private static hydrateSpecialObjects;
1250
+ }
1251
+ export {};
1252
+
1253
+ }
1254
+
1255
+ declare module "socket-function/src/JSONLACKS/JSONLACKS.generated.js" {
1256
+ export function parse(text: string): unknown;
1257
+ }
1258
+
1259
+ declare module "socket-function/src/args" {
1260
+ export declare const getArgs: {
1261
+ (): {
1262
+ [key: string]: string | undefined;
1263
+ };
1264
+ reset(): void;
1265
+ set(newValue: {
1266
+ [key: string]: string | undefined;
1267
+ }): void;
1268
+ };
1269
+
1270
+ }
1271
+
1272
+ declare module "socket-function/src/batching" {
1273
+ import { AnyFunction } from "./types";
1274
+ export type DelayType = (number | "afterio" | "immediate" | "afterpromises" | "paintLoop" | "afterPaint");
1275
+ export declare function delay(delayTime: DelayType, immediateShortDelays?: "immediateShortDelays"): Promise<void>;
1276
+ export declare function batchFunctionNone<Arg, Result = void>(config: unknown, fnc: (arg: Arg[]) => (Promise<Result> | Result)): (arg: Arg) => Promise<Result>;
1277
+ export declare function batchFunction<Arg, Result = void>(config: {
1278
+ delay: DelayType;
1279
+ /** Instead of immediately waiting delay, starts by waiting 0ms, and every call increments the delay factor
1280
+ * by 1. Delay is `factor * (delay / throttleWindow)`. For every delay interval we have no calls, we decrease by
1281
+ * no_calls/delay.
1282
+ * - This essentially turns delay into a `calls per second` type indicator (ex, 10ms is 100 callers
1283
+ * per second, 500ms is 2 calls, etc), which is accurate over delay * throttleWindow time.
1284
+ */
1285
+ throttleWindow?: number;
1286
+ name?: string;
1287
+ noMeasure?: boolean;
1288
+ }, fnc: (arg: Arg[]) => (Promise<Result> | Result)): (arg: Arg) => Promise<Result>;
1289
+ export declare function runInSerial<T extends (...args: any[]) => Promise<any>>(fnc: T): T;
1290
+ export declare function runInParallel<T extends (...args: any[]) => Promise<any>>(config: {
1291
+ parallelCount: number;
1292
+ callTimeout?: number;
1293
+ }, fnc: T): T;
1294
+ export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void): void;
1295
+ export declare function runInfinitePollCallAtStart(delayTime: number, fnc: () => Promise<void> | void): Promise<void>;
1296
+ /** Disables polling, called on shutdown. Blocks until all pending poll loops finish */
1297
+ export declare function shutdownPolling(): Promise<void>;
1298
+ export declare function retryFunctional<T extends AnyFunction>(fnc: T, config?: {
1299
+ maxRetries?: number;
1300
+ shouldRetry?: (message: string) => boolean;
1301
+ minDelay?: number;
1302
+ maxDelay?: number;
1303
+ }): T;
1304
+
1305
+ }
1306
+
1307
+ declare module "socket-function/src/caching" {
1308
+ import { AnyFunction, Args } from "./types";
1309
+ export declare function lazy<T>(factory: () => T): {
1310
+ (): T;
1311
+ reset(): void;
1312
+ set(newValue: T): void;
1313
+ };
1314
+ export declare function cacheEmptyArray<T>(array: T[]): T[];
1315
+ export declare function cache<Output, Key, Untracked extends unknown[]>(getValue: (key: Key, ...untracked: Untracked) => Output): {
1316
+ (key: Key, ...untracked: Untracked): Output;
1317
+ clear(key: Key): void;
1318
+ clearAll(): void;
1319
+ forceSet(key: Key, value: Output): void;
1320
+ getAllKeys(): Key[];
1321
+ get(key: Key): Output | undefined;
1322
+ };
1323
+ /** Makes a cache that limits the number of entries, allowing you to put arbitrary data in it
1324
+ * without worrying about leaking memory
1325
+ */
1326
+ export declare function cacheLimited<Output, Key>(maxCount: number, getValue: (key: Key) => Output): {
1327
+ (input: Key): Output;
1328
+ forceSet(key: Key, value: Output): void;
1329
+ clearKey(key: Key): void;
1330
+ clear(): void;
1331
+ };
1332
+ export declare function cacheWeak<Output, Key extends object>(getValue: (key: Key) => Output): (key: Key) => Output;
1333
+ export declare function cacheList<Value>(getLength: () => number, getValue: (index: number) => Value): {
1334
+ (index: number): Value;
1335
+ };
1336
+ /** A cache half way between caching based on === and caching based on hash. Caches
1337
+ * based on arrayEqual, which does === on all values in an array. Requires localized
1338
+ * caching (as the comparisons don't scale with many candidates, unlike hashing),
1339
+ * however works with non trival transformations (ex, resolving many persisted overrides
1340
+ * to get a value), unlike cache().
1341
+ * Also, limits itself, more of a performance optimization than memory optimization, as it scales
1342
+ * very poorly with the number of candidates.
1343
+ *
1344
+ * TIMING: About 6us with limit = 100, array size = 294, and the cache being full.
1345
+ */
1346
+ export declare function cacheArrayEqual<Input extends unknown[] | undefined, Output>(map: (arrays: Input) => Output, limit?: number): {
1347
+ (array: Input): Output;
1348
+ clear(array: Input): void;
1349
+ clearAll(): void;
1350
+ };
1351
+ /** Caches when arguments are ===. See cacheArrayEqual */
1352
+ export declare function cacheArgsEqual<Fnc extends AnyFunction>(fnc: Fnc, limit?: number): Fnc & {
1353
+ clear(...args: Args<Fnc>): void;
1354
+ };
1355
+ export declare function cacheJSONArgsEqual<Fnc extends AnyFunction>(fnc: Fnc, limit?: number): Fnc & {
1356
+ clear(...args: unknown[]): void;
1357
+ clearAll(): void;
1358
+ };
1359
+ export declare function cacheShallowConfigArgEqual<Fnc extends AnyFunction>(fnc: Fnc, limit?: number): Fnc & {
1360
+ clear(configObj: Args<Fnc>[0]): void;
1361
+ clearAll(): void;
1362
+ };
1363
+ export declare function externalCache<Key, Value>(): {
1364
+ get: (key: Key) => Value | undefined;
1365
+ set: (key: Key, value: Value) => void;
1366
+ };
1367
+
1368
+ }
1369
+
1370
+ declare module "socket-function/src/callHTTPHandler" {
1371
+ /// <reference types="node" />
1372
+ /// <reference types="node" />
1373
+ /// <reference types="node" />
1374
+ import http from "http";
1375
+ import { CallType } from "../SocketFunctionTypes";
1376
+ export declare function setDefaultHTTPCall(call: CallType): void;
1377
+ export declare function getServerLocationFromRequest(request: http.IncomingMessage): {
1378
+ address: string;
1379
+ port: number;
1380
+ };
1381
+ export declare function getNodeIdsFromRequest(request: http.IncomingMessage): {
1382
+ nodeId: string;
1383
+ localNodeId: string;
1384
+ };
1385
+ export declare function getCurrentHTTPRequest(): http.IncomingMessage | undefined;
1386
+ export declare function httpCallHandler(request: http.IncomingMessage, response: http.ServerResponse): Promise<void>;
1387
+ declare const resultHeaders: unique symbol;
1388
+ type HTTPResultType = Buffer & {
1389
+ [resultHeaders]?: {
1390
+ [header: string]: string;
1391
+ };
1392
+ };
1393
+ export declare function setHTTPResultHeaders(result: HTTPResultType, headers: {
1394
+ [header: string]: string;
1395
+ }): HTTPResultType;
1396
+ export {};
1397
+
1398
+ }
1399
+
1400
+ declare module "socket-function/src/callManager" {
1401
+ /// <reference path="../hot/HotReloadController.d.ts" />
1402
+ import { CallerContext, CallType, ClientHookContext, FullCallType, FunctionFlags, HookContext, SocketExposedInterface, SocketExposedShape, SocketFunctionClientHook, SocketFunctionHook, SocketRegistered } from "../SocketFunctionTypes";
1403
+ export declare function getCallFlags(call: CallType): FunctionFlags | undefined;
1404
+ export declare function shouldCompressCall(call: CallType): boolean;
1405
+ export declare function performLocalCall(config: {
1406
+ call: FullCallType;
1407
+ caller: CallerContext;
1408
+ }): Promise<unknown>;
1409
+ export declare function isDataImmutable(call: CallType): boolean;
1410
+ export declare function registerClass(classGuid: string, controller: SocketExposedInterface, shape: SocketExposedShape, config?: {
1411
+ noFunctionMeasure?: boolean;
1412
+ }): void;
1413
+ export declare function exposeClass(exposedClass: SocketRegistered): void;
1414
+ export declare function registerGlobalHook(hook: SocketFunctionHook): void;
1415
+ export declare function unregisterGlobalHook(hook: SocketFunctionHook): void;
1416
+ export declare function registerGlobalClientHook(hook: SocketFunctionClientHook): void;
1417
+ export declare function unregisterGlobalClientHook(hook: SocketFunctionClientHook): void;
1418
+ export declare const runClientHooks: (callType: FullCallType, hooks: Exclude<SocketExposedShape[""], undefined>, connectionId: {
1419
+ nodeId: string;
1420
+ }) => Promise<ClientHookContext>;
1421
+ export declare const runServerHooks: (callType: FullCallType, caller: CallerContext, hooks: Exclude<SocketExposedShape[""], undefined>) => Promise<HookContext>;
1422
+
1423
+ }
1424
+
1425
+ declare module "socket-function/src/certStore" {
1426
+ /// <reference types="node" />
1427
+ /// <reference types="node" />
1428
+ /** Must be populated before the server starts */
1429
+ export declare function trustCertificate(cert: string | Buffer): void;
1430
+ export declare function getTrustedCertificates(): string[];
1431
+ export declare function watchTrustedCertificates(callback: (certs: string[]) => void): () => boolean;
1432
+
1433
+ }
1434
+
1435
+ declare module "socket-function/src/corsCheck" {
1436
+
1437
+ }
1438
+
1439
+ declare module "socket-function/src/fixLargeNetworkCalls" {
1440
+ export declare function markArrayAsSplitable<T>(data: T[]): T[];
1441
+ export declare function isSplitableArray<T>(data: T): data is T & (unknown[]);
1442
+
1443
+ }
1444
+
1445
+ declare module "socket-function/src/formatting/colors" {
1446
+ export type HSL = {
1447
+ h: number;
1448
+ s: number;
1449
+ l: number;
1450
+ };
1451
+ export declare function hslText(color: HSL): string;
1452
+ export declare function hslToRGB(color: HSL): {
1453
+ r: number;
1454
+ g: number;
1455
+ b: number;
1456
+ };
1457
+ export declare function hslToHex(color: HSL): string;
1458
+ export declare function hslLightenGamma(hsl: HSL, fraction: number): {
1459
+ h: number;
1460
+ s: number;
1461
+ l: number;
1462
+ };
1463
+ export declare function hslLightenLinear(hsl: HSL, lightness: number): {
1464
+ h: number;
1465
+ s: number;
1466
+ l: number;
1467
+ };
1468
+ export declare function hslDarkenGamma(hsl: HSL, fraction: number): {
1469
+ h: number;
1470
+ s: number;
1471
+ l: number;
1472
+ };
1473
+ export declare function hslDarkenLinear(hsl: HSL, lightness: number): {
1474
+ h: number;
1475
+ s: number;
1476
+ l: number;
1477
+ };
1478
+ export declare function hslAddSaturate(hsl: HSL, saturation: number): {
1479
+ h: number;
1480
+ s: number;
1481
+ l: number;
1482
+ };
1483
+ export declare function hslSetSaturate(hsl: HSL, saturation: number): {
1484
+ h: number;
1485
+ s: number;
1486
+ l: number;
1487
+ };
1488
+
1489
+ }
1490
+
1491
+ declare module "socket-function/src/formatting/format" {
1492
+ export declare function formatTime(milliseconds: number | undefined, maxAbsoluteValue?: number): string;
1493
+ export declare function getTargetDecimals(maxAbsoluteValue: number, targetDigits: number): number;
1494
+ /** Adds decimal digits to reach digits. If the number is simply too large, it won't remove
1495
+ * digits, there will instead just be no decimal point.
1496
+ */
1497
+ export declare function formatMaxDecimals(num: number, targetDigits: number, maxAbsoluteValue?: number, exactDecimals?: number): string;
1498
+ /** Actually formats any number, including decimals, by using K, M and B suffixes to get smaller values
1499
+ * TODO: Support uK, uM and uB suffixes for very small numbers?
1500
+ * <= 6 characters (<= 5 if positive)
1501
+ */
1502
+ export declare function formatNumber(count: number | undefined, maxAbsoluteValue?: number, noDecimal?: boolean, specialCurrency?: boolean): string;
1503
+ export declare function formatBinaryNumber(count: number | undefined, maxAbsoluteValue?: number, noDecimal?: boolean, specialCurrency?: boolean): string;
1504
+ /** YYYY/MM/DD HH:MM:SS PM/AM */
1505
+ export declare function formatDateTime(time: number): string;
1506
+ export declare function formatDateTimeDetailed(time: number): string;
1507
+ export declare function formatFileTimestampLocal(time: number): string;
1508
+ /** 2024 January 1, Monday, 12:53:02pm */
1509
+ export declare function formatNiceDateTime(time: number): string;
1510
+ /** 2024 January 1, Monday, 12:53:02pm (4 months ago) */
1511
+ export declare function formatVeryNiceDateTime(time: number): string;
1512
+ /** YYYY/MM/DD */
1513
+ export declare function formatDate(time: number): string;
1514
+ /** <= 6 characters (<= 5 if positive) */
1515
+ export declare function formatPercent(value: number): string;
1516
+
1517
+ }
1518
+
1519
+ declare module "socket-function/src/formatting/logColors" {
1520
+ export declare const blue: (text: string) => string;
1521
+ export declare const red: (text: string) => string;
1522
+ export declare const green: (text: string) => string;
1523
+ export declare const yellow: (text: string) => string;
1524
+ export declare const white: (text: string) => string;
1525
+ export declare const gray: (text: string) => string;
1526
+ export declare const magenta: (text: string) => string;
1527
+
1528
+ }
1529
+
1530
+ declare module "socket-function/src/forwardPort" {
1531
+ export declare function forwardPort(config: {
1532
+ externalPort: number;
1533
+ internalPort: number;
1534
+ duration?: number;
1535
+ }): Promise<void>;
1536
+
1537
+ }
1538
+
1539
+ declare module "socket-function/src/https" {
1540
+ /// <reference types="node" />
1541
+ /// <reference types="node" />
1542
+ export declare function httpsRequest(url: string, payload?: Buffer | Buffer[], method?: string, sendSessionCookies?: boolean, config?: {
1543
+ headers?: {
1544
+ [key: string]: string | undefined;
1545
+ };
1546
+ cancel?: Promise<void>;
1547
+ }): Promise<Buffer>;
1548
+
1549
+ }
1550
+
1551
+ declare module "socket-function/src/misc" {
1552
+ /// <reference types="node" />
1553
+ /// <reference types="node" />
1554
+ import { MaybePromise } from "./types";
1555
+ export declare const timeInSecond = 1000;
1556
+ export declare const timeInMinute: number;
1557
+ export declare const timeInHour: number;
1558
+ export declare const timeInDay: number;
1559
+ export declare const timeInWeek: number;
1560
+ export declare const timeInYear: number;
1561
+ export type Watchable<T> = (callback: (value: T) => void) => MaybePromise<void>;
1562
+ export declare function convertErrorStackToError(error: string): Error;
1563
+ export declare function sha256Hash(buffer: Buffer | string): string;
1564
+ export declare function sha256HashBuffer(buffer: Buffer | string): Buffer;
1565
+ /** Async, but works both clientside and serverside. */
1566
+ export declare function sha256HashPromise(buffer: Buffer): Promise<any>;
1567
+ export declare function sha256BufferPromise(buffer: Buffer): Promise<Buffer>;
1568
+ export declare function arrayEqual(a: {
1569
+ [key: number]: unknown;
1570
+ length: number;
1571
+ }, b: {
1572
+ [key: number]: unknown;
1573
+ length: number;
1574
+ }): boolean;
1575
+ export declare function isNode(): boolean;
1576
+ export declare function isNodeTrue(): true;
1577
+ export declare function formatNumberSuffixed(count: number): string;
1578
+ export declare function list(count: number): number[];
1579
+ export declare function recursiveFreeze<T>(obj: T): T;
1580
+ export type ArrayBufferViewTypes = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | BigUint64Array | BigInt64Array | Float64Array | Float32Array | Uint8ClampedArray;
1581
+ export type BufferType = ArrayBuffer | SharedArrayBuffer | ArrayBufferViewTypes;
1582
+ export declare function isBufferType(obj: unknown): obj is BufferType;
1583
+ export declare function getKeys(obj: unknown): PropertyKey[];
1584
+ export declare function getStringKeys<T extends {}>(obj: T): ((keyof T) & string)[];
1585
+ export declare function keyBy<T, K>(arr: T[], getKey: (value: T) => K): Map<K, T>;
1586
+ export declare function keyByArray<T, K>(arr: T[], getKey: (value: T) => K): Map<K, T[]>;
1587
+ export declare function deepCloneJSON<T>(obj: T): T;
1588
+ export declare class PromiseObj<T = void> {
1589
+ promise: Promise<T>;
1590
+ value: {
1591
+ value?: T;
1592
+ error?: string;
1593
+ } | undefined;
1594
+ /** Resolve called does not mean the value is ready, as it may be resolved with a promise. */
1595
+ resolveCalled?: boolean;
1596
+ resolve: (value: T | Promise<T>) => void;
1597
+ reject: (error: any) => void;
1598
+ private baseResolve;
1599
+ private baseReject;
1600
+ constructor();
1601
+ }
1602
+ export declare function promiseObj<T = void>(): PromiseObj<T>;
1603
+ export declare function throttleFunction<Args extends any[]>(delay: number, fnc: (...args: Args) => MaybePromise<void>): (...args: Args) => Promise<void>;
1604
+ export declare function nextId(): string;
1605
+ export declare function arrayFromOrderObject<T>(obj: {
1606
+ [order: number]: T;
1607
+ }): T[];
1608
+ export declare function last<T>(arr: T[]): T | undefined;
1609
+ export type ObjectValues<T> = T[keyof T];
1610
+ export declare function entries<Obj extends {
1611
+ [key: string]: unknown;
1612
+ }>(obj: Obj): [keyof Obj, ObjectValues<Obj>][];
1613
+ export declare function keys<Obj extends {
1614
+ [key: string]: unknown;
1615
+ }>(obj: Obj): (keyof Obj)[];
1616
+ export declare function sort<T>(arr: T[], sortKey: (obj: T) => unknown): T[];
1617
+ export declare function getRootDomain(hostname: string): string;
1618
+ export declare class QueueLimited<T> {
1619
+ private readonly maxCount;
1620
+ private items;
1621
+ private nextIndex;
1622
+ constructor(maxCount: number);
1623
+ push(item: T): void;
1624
+ getAllUnordered(): T[];
1625
+ reset(): void;
1626
+ clear(): void;
1627
+ getOldest(): T | undefined;
1628
+ }
1629
+ export declare function binarySearchBasic<T, V>(array: T[], getVal: (val: T) => V, searchValue: V): number;
1630
+ export declare function binarySearchBasic2<T, V>(array: T[], getVal: (val: T) => V, searchValue: T): number;
1631
+ /**
1632
+ * Searches indexes, allowing you to query structures that aren't arrays. To search an array, use:
1633
+ * `binarySearchIndex(array.length, i => compare(array[i], searchValue))`
1634
+ *
1635
+ * NOTE: If there are duplicates, returns the first match.
1636
+ *
1637
+ * NOTE: If the value can't be found, returns the bitwise negation of the index where it should be inserted.
1638
+ *
1639
+ * NOTE: With `if (index < 0) index = ~index;` you will get an index of the value >= the target value.
1640
+ */
1641
+ export declare function binarySearchIndex(listCount: number, compare: (lhsIndex: number) => number): number;
1642
+ export declare function compare(lhs: unknown, rhs: unknown): number;
1643
+ export declare function compareArray(lhs: unknown[], rhs: unknown[]): number;
1644
+ export declare function insertIntoSortedList<T>(list: T[], map: (val: T) => string | number, element: T): void;
1645
+ export declare function removeFromSortedList<T>(list: T[], map: (val: T) => string | number, searchValue: string | number): void;
1646
+ export declare function timeoutToError<T>(time: number, p: Promise<T>, err: () => Error): Promise<T>;
1647
+ export declare function timeoutToUndefined<T>(time: number, p: Promise<T>): Promise<T | undefined>;
1648
+ export declare function timeoutToUndefinedSilent<T>(time: number, p: Promise<T>): Promise<T | undefined>;
1649
+ export declare function errorToWarning<T>(promise: Promise<T>): void;
1650
+
1651
+ }
1652
+
1653
+ declare module "socket-function/src/networking" {
1654
+ export declare const testTCPIsListening: (host: string, port: number) => Promise<boolean>;
1655
+ export declare const getExternalIP: {
1656
+ (): Promise<string>;
1657
+ reset(): void;
1658
+ set(newValue: Promise<string>): void;
1659
+ };
1660
+ export declare const getPublicIP: {
1661
+ (): Promise<string>;
1662
+ reset(): void;
1663
+ set(newValue: Promise<string>): void;
1664
+ };
1665
+
1666
+ }
1667
+
1668
+ declare module "socket-function/src/nodeCache" {
1669
+ import { CallFactory } from "./CallFactory";
1670
+ import { MaybePromise } from "./types";
1671
+ export declare function getNodeId(domain: string, port: number): string;
1672
+ /** @deprecated, call getBrowserUrlNode instead, which does important additional checks. */
1673
+ export declare function getNodeIdFromLocation(): string;
1674
+ /** A nodeId not available for reconnecting. */
1675
+ export declare function getClientNodeId(address: string): string;
1676
+ export declare function isClientNodeId(nodeId: string): boolean;
1677
+ /** Will always be available, even if getNodeIdLocation is not (as we don't always have the port,
1678
+ * but we should always have an address).
1679
+ * - Rarely used, as for logging you can just log the nodeId. ALSO, it isn't sufficient to reconnect, as the port is also needed!
1680
+ * */
1681
+ export declare function getNodeIdIP(nodeId: string): string;
1682
+ export declare function getNodeIdLocation(nodeId: string): {
1683
+ address: string;
1684
+ port: number;
1685
+ } | undefined;
1686
+ export declare function getNodeIdDomain(nodeId: string): string;
1687
+ export declare function getNodeIdDomainMaybeUndefined(nodeId: string): string | undefined;
1688
+ export declare function registerNodeClient(callFactory: CallFactory): void;
1689
+ export declare function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory>;
1690
+ export declare function getCallFactory(nodeId: string): MaybePromise<CallFactory | undefined>;
1691
+ export declare function resetAllNodeCallFactories(): void;
1692
+ export declare function countOpenConnections(): number;
1693
+
1694
+ }
1695
+
1696
+ declare module "socket-function/src/nodeProxy" {
1697
+ import { FullCallType, SocketInternalInterface } from "../SocketFunctionTypes";
1698
+ type CallProxyType = {
1699
+ [nodeId: string]: SocketInternalInterface;
1700
+ };
1701
+ export declare const getCallObj: unique symbol;
1702
+ export declare function getCallProxy(id: string, callback: (callType: FullCallType) => Promise<unknown>): CallProxyType;
1703
+ export {};
1704
+
1705
+ }
1706
+
1707
+ declare module "socket-function/src/profiling/getOwnTime" {
1708
+ export type OwnTimeObj = {
1709
+ name: string;
1710
+ time: number;
1711
+ ownTime: number;
1712
+ };
1713
+ export type OwnTimeObjInternal = OwnTimeObj & {
1714
+ lastStartTime: number;
1715
+ firstStartTime: number;
1716
+ };
1717
+ export declare function getOpenTimesBase(): OwnTimeObjInternal[];
1718
+ export declare const measureOverheadTime: number;
1719
+ export declare function getOwnTime<T>(name: string, code: () => T, onTime: (obj: OwnTimeObj) => void): T;
1720
+
1721
+ }
1722
+
1723
+ declare module "socket-function/src/profiling/measure" {
1724
+ import { StatsValue } from "./stats";
1725
+ /** NOTE: Must be called BEFORE anything else is imported!
1726
+ * NOTE: Measurements on on by default now, so this doesn't really need to be called...
1727
+ */
1728
+ export declare function enableMeasurements(): void;
1729
+ /** NOTE: Must be called BEFORE anything else is imported! */
1730
+ export declare function disableMeasurements(): void;
1731
+ export declare function measureFnc(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
1732
+ export declare function nameFunction<T extends Function>(name: string, fnc: T): T;
1733
+ export declare function measureWrap<T extends (...args: any[]) => any>(fnc: T, name?: string): T;
1734
+ export declare function measureBlock<T extends (...args: any[]) => any>(fnc: T, name?: string): ReturnType<T>;
1735
+ /** NOTE: You should often call registerNodeMetadata for this as well. registerMeasureInfo
1736
+ * is for logs, while registerNodeMetadata is for the overview page.
1737
+ */
1738
+ export declare function registerMeasureInfo(getInfo: () => string | undefined): void;
1739
+ /** IMPORTANT! Always finish the profile! If you don't, you will leak A LOT of memory
1740
+ * (you leak all future measures, PER unfinished profile)!
1741
+ */
1742
+ export declare function startMeasure(): {
1743
+ finish: () => MeasureProfile;
1744
+ };
1745
+ export interface LogMeasureTableConfig {
1746
+ useTotalTime?: boolean;
1747
+ name?: string;
1748
+ setTitle?: boolean;
1749
+ thresholdInTable?: number;
1750
+ minTimeToLog?: number;
1751
+ mergeDepth?: number;
1752
+ maxTableEntries?: number;
1753
+ returnOnly?: boolean;
1754
+ }
1755
+ export interface FormattedMeasureTable {
1756
+ title: string;
1757
+ entries: {
1758
+ name: string;
1759
+ ownTime: number;
1760
+ fraction: number;
1761
+ equation: string;
1762
+ }[];
1763
+ }
1764
+ export declare function logMeasureTable(profile: MeasureProfile, config?: LogMeasureTableConfig): FormattedMeasureTable | undefined;
1765
+ export declare function measureCode<T>(code: () => Promise<T>, config?: LogMeasureTableConfig): Promise<T>;
1766
+ export declare function measureCodeSync<T>(code: () => T, config?: LogMeasureTableConfig): T;
1767
+ export interface MeasureProfile {
1768
+ startTime: number;
1769
+ endTime: number;
1770
+ entries: {
1771
+ [name: string]: ProfileEntry;
1772
+ };
1773
+ }
1774
+ export declare function createMeasureProfile(): MeasureProfile;
1775
+ export declare function addToMeasureProfile(base: MeasureProfile, other: MeasureProfile): void;
1776
+ interface ProfileEntry {
1777
+ name: string;
1778
+ ownTime: StatsValue;
1779
+ totalTime: StatsValue;
1780
+ stillOpenCount: number;
1781
+ }
1782
+ export {};
1783
+
1784
+ }
1785
+
1786
+ declare module "socket-function/src/profiling/stats" {
1787
+ export interface StatsValue {
1788
+ count: number;
1789
+ sum: number;
1790
+ sumSquares: number;
1791
+ logn7Value: number;
1792
+ logn7Count: number;
1793
+ logn6Value: number;
1794
+ logn6Count: number;
1795
+ logn5Value: number;
1796
+ logn5Count: number;
1797
+ logn4Value: number;
1798
+ logn4Count: number;
1799
+ logn3Value: number;
1800
+ logn3Count: number;
1801
+ logn2Value: number;
1802
+ logn2Count: number;
1803
+ logn1Value: number;
1804
+ logn1Count: number;
1805
+ log0Value: number;
1806
+ log0VCount: number;
1807
+ log1Value: number;
1808
+ log1VCount: number;
1809
+ log2Value: number;
1810
+ log2VCount: number;
1811
+ log3Value: number;
1812
+ log3VCount: number;
1813
+ log4Value: number;
1814
+ log4VCount: number;
1815
+ log5Value: number;
1816
+ log5VCount: number;
1817
+ log6Value: number;
1818
+ log6VCount: number;
1819
+ log7Value: number;
1820
+ log7VCount: number;
1821
+ log8Value: number;
1822
+ log8VCount: number;
1823
+ log9Value: number;
1824
+ log9VCount: number;
1825
+ }
1826
+ export declare function createStatsValue(): StatsValue;
1827
+ export declare function addToStatsValue(stats: StatsValue, value: number): void;
1828
+ export declare function addToStats(stats: StatsValue, other: StatsValue): void;
1829
+ export interface StatsTop {
1830
+ countFraction: number;
1831
+ valueFraction: number;
1832
+ count: number;
1833
+ value: number;
1834
+ topHeavy: boolean;
1835
+ }
1836
+ /** Identifies cases where the value is concentrated in few instances. This indicates most of the value (time)
1837
+ * is not spent on the common case, but on an outlier. Which isn't a problem, it just means that the measurements
1838
+ * should be more precise, to pull that heavy case out.
1839
+ */
1840
+ export declare function getStatsTop(stats: StatsValue): StatsTop;
1841
+
1842
+ }
1843
+
1844
+ declare module "socket-function/src/profiling/statsFormat" {
1845
+ import { StatsValue } from "./stats";
1846
+ export declare function percent(value: number): string;
1847
+ export declare function formatStats(stats: StatsValue, config?: {
1848
+ noColor?: boolean;
1849
+ noSum?: boolean;
1850
+ noSpaces?: boolean;
1851
+ }): string;
1852
+
1853
+ }
1854
+
1855
+ declare module "socket-function/src/profiling/tcpLagProxy" {
1856
+ export declare function tcpLagProxy(config: {
1857
+ localPort: number;
1858
+ remoteHost: string;
1859
+ remotePort: number;
1860
+ lag: number;
1861
+ networkWriteSize?: {
1862
+ value: number;
1863
+ };
1864
+ networkReadSize?: {
1865
+ value: number;
1866
+ };
1867
+ networkWritePackets?: {
1868
+ value: number;
1869
+ };
1870
+ networkReadPackets?: {
1871
+ value: number;
1872
+ };
1873
+ }): Promise<void>;
1874
+
1875
+ }
1876
+
1877
+ declare module "socket-function/src/promiseRace" {
1878
+ export declare class PromiseLessLeaky<T> extends Promise<T> {
1879
+ constructor(executor: ((resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) | undefined);
1880
+ }
1881
+ /** A promise race function which doesn't leak, unlike Promise.race
1882
+
1883
+ See https://github.com/nodejs/node/issues/17469
1884
+ See https://bugs.chromium.org/p/v8/issues/detail?id=9858#c9
1885
+
1886
+ */
1887
+ export declare function promiseRace<T extends readonly unknown[] | []>(promises: T): Promise<Awaited<T[number]>>;
1888
+
1889
+ }
1890
+
1891
+ declare module "socket-function/src/runPromise" {
1892
+ export declare const runAsync: typeof runPromise;
1893
+ export declare function runPromise(command: string, config?: {
1894
+ cwd?: string;
1895
+ quiet?: boolean;
1896
+ nothrow?: boolean;
1897
+ detach?: boolean;
1898
+ }): Promise<string>;
1899
+
1900
+ }
1901
+
1902
+ declare module "socket-function/src/sniTest" {
1903
+ export {};
1904
+
1905
+ }
1906
+
1907
+ declare module "socket-function/src/storagePath" {
1908
+ export declare const getAppFolder: {
1909
+ (): string;
1910
+ reset(): void;
1911
+ set(newValue: string): void;
1912
+ };
1913
+
1914
+ }
1915
+
1916
+ declare module "socket-function/src/tlsParsing" {
1917
+ /// <reference types="node" />
1918
+ /// <reference types="node" />
1919
+ export declare function parseTLSHello(buffer: Buffer): {
1920
+ extensions: {
1921
+ type: number;
1922
+ data: Buffer;
1923
+ }[];
1924
+ missingBytes: number;
1925
+ };
1926
+ export declare const SNIType = 0;
1927
+ export declare function parseSNIExtension(data: Buffer): string[];
1928
+
1929
+ }
1930
+
1931
+ declare module "socket-function/src/types" {
1932
+ export type MaybePromise<T> = T | Promise<T>;
1933
+ export type Args<T> = T extends (...args: infer V) => any ? V : never;
1934
+ export type AnyFunction = (...args: any) => any;
1935
+ export declare function canHaveChildren(value: unknown): value is {
1936
+ [key in PropertyKey]: unknown;
1937
+ };
1938
+
1939
+ }
1940
+
1941
+ declare module "socket-function/src/webSocketServer" {
1942
+ /// <reference types="node" />
1943
+ /// <reference types="node" />
1944
+ /// <reference types="node" />
1945
+ import https from "https";
1946
+ import { Watchable } from "./misc";
1947
+ export type SocketServerConfig = (https.ServerOptions & {
1948
+ key: string | Buffer;
1949
+ cert: string | Buffer;
1950
+ port: number;
1951
+ /** You can also set `port: 0` if you don't care what port you want at all. */
1952
+ useAvailablePortIfPortInUse?: boolean;
1953
+ public?: boolean;
1954
+ /** Tries forwarding ports (using UPnP), if we detect they aren't externally reachable.
1955
+ * - This causes an extra request and delay during startup, so should only be used
1956
+ * during development.
1957
+ * - Ignored if public is false (in which case we mount on 127.0.0.1, so port forwarding
1958
+ * wouldn't matter anyways).
1959
+ */
1960
+ autoForwardPort?: boolean;
1961
+ ip?: string;
1962
+ allowHostnames?: string[];
1963
+ allowHostnameFnc?: (hostname: string) => boolean;
1964
+ /** If the SNI matches this domain, we use a different key/cert.
1965
+ * We remove subdomains until we find a match
1966
+ */
1967
+ SNICerts?: {
1968
+ [domain: string]: Watchable<https.ServerOptions>;
1969
+ };
1970
+ });
1971
+ export declare function startSocketServer(config: SocketServerConfig): Promise<string>;
1972
+
1973
+ }
1974
+
1975
+ declare module "socket-function/src/websocketFactory" {
1976
+ /// <reference types="node" />
1977
+ import tls from "tls";
1978
+ import { SenderInterface } from "./CallFactory";
1979
+ import type * as ws from "ws";
1980
+ export declare function getTLSSocket(webSocket: ws.WebSocket): tls.TLSSocket;
1981
+ /** NOTE: We create a factory, which embeds the key/cert information. Otherwise retries might use
1982
+ * a different key/cert context.
1983
+ */
1984
+ export declare function createWebsocketFactory(): (nodeId: string) => SenderInterface;
1985
+
1986
+ }
1987
+
1988
+ declare module "socket-function/test" {
1989
+ export {};
1990
+
1991
+ }
1992
+
1993
+ declare module "socket-function/time/trueTimeShim" {
1994
+ export declare function getTrueTime(): number;
1995
+ export declare function getTrueTimeOffset(): number;
1996
+ export declare function waitForFirstTimeSync(): Promise<void> | undefined;
1997
+ export declare function shimDateNow(): void;
1998
+ export declare function getBrowserTime(): number;
1999
+ export declare function setGetTimeOffsetBase(base: () => Promise<number>): void;
2000
+
2001
+ }
2002
+
945
2003
  }
946
2004
 
947
2005
  declare module "socket-function/mobx/UrlParam" {
@@ -3788,7 +4846,7 @@ declare module "socket-function/index" {
3788
4846
  }
3789
4847
 
3790
4848
  declare module "socket-function/require/require" {
3791
- /// <reference path="../index.d.ts" />
4849
+ /// <reference path="../src/src.d.ts" />
3792
4850
  declare global {
3793
4851
  var onProgressHandler: undefined | ((progress: {
3794
4852
  type: string;
@@ -4530,6 +5588,52 @@ declare module "socket-function/index" {
4530
5588
 
4531
5589
  }
4532
5590
 
5591
+ declare module "socket-function/src/src" {
5592
+ /// <reference path="./node_modules/typenode/index.d.ts" />
5593
+
5594
+ export { };
5595
+
5596
+ declare global {
5597
+ namespace NodeJS {
5598
+ interface Module {
5599
+ original?: SerializedModule;
5600
+ }
5601
+ }
5602
+ interface SerializedModule {
5603
+ originalId: string;
5604
+ filename: string;
5605
+ // If a module is not allowed clientside it is likely requests will be empty,
5606
+ // to save effort parsing requests for modules that only exist to give better
5607
+ // error messages.
5608
+ requests: {
5609
+ // request => resolvedPath
5610
+ [request: string]: string;
5611
+ };
5612
+ asyncRequests: { [request: string]: true };
5613
+ // NOTE: IF !allowclient && !serveronly, it might just mean we didn't add allowclient
5614
+ // to the module yet. BUT, if serveronly, then we know for sure we don't want it client.
5615
+ // So the messages and behavior will be different.
5616
+ allowclient?: boolean;
5617
+ serveronly?: boolean;
5618
+ // Just for errors mostly
5619
+ alwayssend?: boolean;
5620
+
5621
+ /** Only set if allowclient. */
5622
+ source?: string;
5623
+
5624
+ seqNum: number;
5625
+
5626
+ size?: number;
5627
+ version?: number;
5628
+
5629
+ flags?: {
5630
+ [flag: string]: true;
5631
+ };
5632
+ }
5633
+
5634
+ }
5635
+ }
5636
+
4533
5637
  declare module "socket-function/src/storagePath" {
4534
5638
  export declare const getAppFolder: {
4535
5639
  (): string;