socket-function 0.159.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
@@ -280,114 +280,6 @@ declare module "socket-function/index" {
280
280
 
281
281
  }
282
282
 
283
- declare module "socket-function/SocketFunction" {
284
- /// <reference path="require/RequireController.d.ts" />
285
- /// <reference types="node" />
286
- /// <reference types="node" />
287
- import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, SocketRegisterType } from "./SocketFunctionTypes";
288
- import { SocketServerConfig } from "./src/webSocketServer";
289
- import { Args, MaybePromise } from "./src/types";
290
- import "./SetProcessVariables";
291
- type ExtractShape<ClassType, Shape> = {
292
- [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");
293
- };
294
- export declare class SocketFunction {
295
- static logMessages: boolean;
296
- static trackMessageSizes: {
297
- upload: ((size: number) => void)[];
298
- download: ((size: number) => void)[];
299
- callTimes: ((obj: {
300
- start: number;
301
- end: number;
302
- }) => void)[];
303
- };
304
- static MAX_MESSAGE_SIZE: number;
305
- static HTTP_ETAG_CACHE: boolean;
306
- static silent: boolean;
307
- static HTTP_COMPRESS: boolean;
308
- static COEP: string;
309
- static COOP: string;
310
- static readonly WIRE_SERIALIZER: {
311
- serialize: (obj: unknown) => MaybePromise<Buffer[]>;
312
- deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
313
- };
314
- static WIRE_WARN_TIME: number;
315
- private static onMountCallbacks;
316
- static exposedClasses: Set<string>;
317
- static callerContext: CallerContext | undefined;
318
- static getCaller(): CallerContext;
319
- static harvestFailedCallCount: () => number;
320
- static getPendingCallCount: () => number;
321
- static harvestCallTimes: () => {
322
- start: number;
323
- end: number;
324
- }[];
325
- static register<ClassInstance extends object, Shape extends SocketExposedShape<{
326
- [key in keyof ClassInstance]: (...args: any[]) => Promise<unknown>;
327
- }>, Statics>(classGuid: string, instance: ClassInstance | (() => ClassInstance), shapeFnc: () => Shape, defaultHooksFnc?: () => SocketExposedShape[""] & {
328
- onMount?: () => MaybePromise<void>;
329
- }, config?: {
330
- /** @noAutoExpose If true SocketFunction.expose(Controller) must be called explicitly. */
331
- noAutoExpose?: boolean;
332
- statics?: Statics;
333
- /** Skip timing functions calls. Useful if a lot of functions have wait time that
334
- is unrelated to processing, and therefore their timings won't be useful.
335
- - Also useful if our auto function wrapping code is breaking functionality,
336
- such as if you have a singleton function which you compare with ===,
337
- which will breaks because we replaced it with a wrapped measure function.
338
- */
339
- noFunctionMeasure?: boolean;
340
- }): SocketRegistered<ExtractShape<ClassInstance, Shape>> & Statics;
341
- private static socketCache;
342
- static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
343
- private static callFromGuid;
344
- static onNextDisconnect(nodeId: string, callback: () => void): void;
345
- static getLastDisconnectTime(nodeId: string): number | undefined;
346
- static isNodeConnected(nodeId: string): boolean;
347
- /** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
348
- * as we have no way of knowing how to contain a nodeId).
349
- * */
350
- static getHTTPCallLink(call: FullCallType): string;
351
- private static ignoreExposeCount;
352
- static ignoreExposeCalls<T>(code: () => Promise<T>): Promise<T>;
353
- /** Expose should be called before your mounting occurs. It mostly just exists to ensure you include the class type,
354
- * so the class type's module construction runs, which should trigger register. Otherwise you would have
355
- * to add additional imports to ensure the register call runs.
356
- */
357
- static expose(socketRegistered: SocketRegistered): void;
358
- static mountedNodeId: string;
359
- static isMounted(): boolean;
360
- static mountedIP: string;
361
- private static hasMounted;
362
- private static onMountCallback;
363
- static mountPromise: Promise<void>;
364
- static mount(config: SocketServerConfig): Promise<string>;
365
- /** Sets the default call when an http request is made, but no classGuid is set.
366
- * NOTE: All other calls should be endpoint calls, even if those endpoints return a static file with an HTML content type.
367
- * - However, to load new content, you should probably just use `require("./example.ts")`, which works on any files
368
- * clientside that have also been required serverside (and whitelisted with module.allowclient = true,
369
- * or with an `allowclient.flag` file in the directory or parent directory).
370
- */
371
- static setDefaultHTTPCall<Registered extends SocketRegistered, FunctionName extends keyof Registered["nodes"][""] & string>(registered: Registered, functionName: FunctionName, ...args: Args<Registered["nodes"][""][FunctionName]>): void;
372
- static connect(location: {
373
- address: string;
374
- port: number;
375
- }): string;
376
- static browserNodeId(): string;
377
- static getBrowserNodeId(): string;
378
- static addGlobalHook(hook: SocketFunctionHook): void;
379
- static addGlobalClientHook(hook: SocketFunctionClientHook): void;
380
- }
381
- declare global {
382
- var BOOTED_EDGE_NODE: {
383
- host: string;
384
- } | undefined;
385
- }
386
- export declare function _setSocketContext<T>(caller: CallerContext, code: () => T): T;
387
- export {};
388
-
389
- }
390
-
391
283
  declare module "socket-function/SocketFunctionTypes" {
392
284
  /// <reference path="require/RequireController.d.ts" />
393
285
  import { getCallObj } from "./src/nodeProxy";
@@ -514,297 +406,2521 @@ declare module "socket-function/index" {
514
406
  fileUpdated: (files: string[], changeTime: number) => Promise<void>;
515
407
  }>;
516
408
 
517
- }
409
+ }
410
+
411
+ declare module "socket-function/index" {
412
+ // Auto-generated file. Do not edit manually.
413
+ // Generated by: yarn generate-index-dts
414
+
415
+ declare module "socket-function/SetProcessVariables" {
416
+ export {};
417
+
418
+ }
419
+
420
+ declare module "socket-function/SocketFunctionTypes" {
421
+ /// <reference path="require/RequireController.d.ts" />
422
+ import { getCallObj } from "./src/nodeProxy";
423
+ import { Args, MaybePromise } from "./src/types";
424
+ export declare const socket: unique symbol;
425
+ export type SocketExposedInterface = {
426
+ [functionName: string]: (...args: any[]) => Promise<unknown>;
427
+ };
428
+ export type SocketInternalInterface = {
429
+ [functionName: string]: {
430
+ [getCallObj]: (...args: any[]) => FullCallType;
431
+ (...args: any[]): Promise<unknown>;
432
+ };
433
+ };
434
+ export type SocketExposedInterfaceClass = {
435
+ new (): unknown;
436
+ prototype: unknown;
437
+ };
438
+ export type FunctionFlags = {
439
+ compress?: boolean;
440
+ /** Indicates with the same input, we give the same output, forever,
441
+ * independent of code changes. This only works for data storage.
442
+ */
443
+ dataImmutable?: boolean;
444
+ /** Allows overriding SocketFunction.MAX_MESSAGE_SIZE for responses from this function. */
445
+ responseLimit?: number;
446
+ };
447
+ export type SocketExposedShape<ExposedType extends SocketExposedInterface = SocketExposedInterface> = {
448
+ [functionName in keyof ExposedType]?: FunctionFlags & {
449
+ hooks?: SocketFunctionHook[];
450
+ clientHooks?: SocketFunctionClientHook[];
451
+ noDefaultHooks?: boolean;
452
+ /** BUG: I think this is broken if it is on the default hooks function? */
453
+ noClientHooks?: boolean;
454
+ };
455
+ };
456
+ export type FncType = (...args: any[]) => Promise<unknown>;
457
+ export interface CallType<FncT extends FncType = FncType, FncName extends string = string> {
458
+ classGuid: string;
459
+ functionName: FncName;
460
+ args: unknown[];
461
+ }
462
+ export interface FullCallType<FncT extends FncType = FncType, FncName extends string = string> extends CallType<FncT, FncName> {
463
+ nodeId: string;
464
+ }
465
+ export interface SocketFunctionHook {
466
+ (config: HookContext): MaybePromise<void>;
467
+ /** NOTE: This is useful when we need a clientside hook to set up state specifically for our serverside hook. */
468
+ clientHook?: SocketFunctionClientHook;
469
+ }
470
+ export type HookContext = {
471
+ call: FullCallType;
472
+ overrideResult?: unknown;
473
+ onResult: ((result: unknown) => MaybePromise<void>)[];
474
+ };
475
+ export type ClientHookContext = {
476
+ call: FullCallType;
477
+ overrideResult?: unknown;
478
+ onResult: ((result: unknown) => MaybePromise<void>)[];
479
+ connectionId: {
480
+ nodeId: string;
481
+ };
482
+ };
483
+ export interface SocketFunctionClientHook {
484
+ (config: ClientHookContext): MaybePromise<void>;
485
+ }
486
+ export interface SocketRegisterType<ExposedType = any> {
487
+ _classGuid: string;
488
+ _internalType: ExposedType;
489
+ }
490
+ export interface SocketRegistered<ExposedType = any> {
491
+ nodes: {
492
+ [nodeId: string]: {
493
+ [functionName in keyof ExposedType]: ExposedType[functionName] & {
494
+ [getCallObj]: (...args: Args<ExposedType[functionName]>) => FullCallType;
495
+ };
496
+ };
497
+ };
498
+ _classGuid: string;
499
+ _internalType: ExposedType;
500
+ }
501
+ export type ControllerPick<T extends SocketRegistered, K extends keyof T["_internalType"]> = (SocketRegistered<Pick<T["_internalType"], K>>);
502
+ export type CallerContext = Readonly<CallerContextBase>;
503
+ export type CallerContextBase = {
504
+ nodeId: string;
505
+ localNodeId: string;
506
+ };
507
+
508
+ }
509
+
510
+ declare module "socket-function/hot/HotReloadController" {
511
+ /// <reference path="../../typenode/index.d.ts" />
512
+ /// <reference path="../require/RequireController.d.ts" />
513
+ /** Enables some hot reload functionality.
514
+ * - Triggers a refresh clientside
515
+ * - Triggers a reload server, for modules marked with `module.hotreload`
516
+ */
517
+ export declare function watchFilesAndTriggerHotReloading(noAutomaticBrowserWatch?: boolean): void;
518
+ declare global {
519
+ namespace NodeJS {
520
+ interface Module {
521
+ /** Causes us to hotreload the file. Applies both serverside and clientside.
522
+ * - If not set for any files clientside, we will refresh.
523
+ * - If not set for any files serverside, we will do nothing (and just leave old code running).
524
+ */
525
+ hotreload?: boolean;
526
+ /** Overrides hotreload to disable hot reloading. Useful if you add "hotreload.flag" to a directory
527
+ * (which sets hotreload on all files in and under that directory), but want a specific file
528
+ * to not hotreload.
529
+ * - Also useful if you want files to hotreload clientside, but not serverside.
530
+ */
531
+ noserverhotreload?: boolean;
532
+ watchAdditionalFiles?: string[];
533
+ }
534
+ }
535
+ var isHotReloading: (() => boolean) | undefined;
536
+ }
537
+ export declare function isHotReloading(): boolean;
538
+ export declare function hotReloadingGuard(): true;
539
+ export declare function setExternalHotReloading(value: boolean): void;
540
+ export declare function onHotReload(callback: (modules: NodeJS.Module[]) => void): void;
541
+ export declare const HotReloadController: import("../SocketFunctionTypes").SocketRegistered<{
542
+ watchFiles: () => Promise<void>;
543
+ fileUpdated: (files: string[], changeTime: number) => Promise<void>;
544
+ }>;
545
+
546
+ }
547
+
548
+ declare module "socket-function/index" {
549
+ // Auto-generated file. Do not edit manually.
550
+ // Generated by: yarn generate-index-dts
551
+
552
+ declare module "socket-function/SetProcessVariables" {
553
+ export {};
554
+
555
+ }
556
+
557
+ declare module "socket-function/SocketFunction" {
558
+ /// <reference path="require/RequireController.d.ts" />
559
+ /// <reference types="node" />
560
+ /// <reference types="node" />
561
+ import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, SocketRegisterType } from "./SocketFunctionTypes";
562
+ import { SocketServerConfig } from "./src/webSocketServer";
563
+ import { Args, MaybePromise } from "./src/types";
564
+ import "./SetProcessVariables";
565
+ type ExtractShape<ClassType, Shape> = {
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");
567
+ };
568
+ export declare class SocketFunction {
569
+ static logMessages: boolean;
570
+ static trackMessageSizes: {
571
+ upload: ((size: number) => void)[];
572
+ download: ((size: number) => void)[];
573
+ callTimes: ((obj: {
574
+ start: number;
575
+ end: number;
576
+ }) => void)[];
577
+ };
578
+ static MAX_MESSAGE_SIZE: number;
579
+ static HTTP_ETAG_CACHE: boolean;
580
+ static silent: boolean;
581
+ static HTTP_COMPRESS: boolean;
582
+ static COEP: string;
583
+ static COOP: string;
584
+ static readonly WIRE_SERIALIZER: {
585
+ serialize: (obj: unknown) => MaybePromise<Buffer[]>;
586
+ deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
587
+ };
588
+ static WIRE_WARN_TIME: number;
589
+ private static onMountCallbacks;
590
+ static exposedClasses: Set<string>;
591
+ static callerContext: CallerContext | undefined;
592
+ static getCaller(): CallerContext;
593
+ static harvestFailedCallCount: () => number;
594
+ static getPendingCallCount: () => number;
595
+ static harvestCallTimes: () => {
596
+ start: number;
597
+ end: number;
598
+ }[];
599
+ static register<ClassInstance extends object, Shape extends SocketExposedShape<{
600
+ [key in keyof ClassInstance]: (...args: any[]) => Promise<unknown>;
601
+ }>, Statics>(classGuid: string, instance: ClassInstance | (() => ClassInstance), shapeFnc: () => Shape, defaultHooksFnc?: () => SocketExposedShape[""] & {
602
+ onMount?: () => MaybePromise<void>;
603
+ }, config?: {
604
+ /** @noAutoExpose If true SocketFunction.expose(Controller) must be called explicitly. */
605
+ noAutoExpose?: boolean;
606
+ statics?: Statics;
607
+ /** Skip timing functions calls. Useful if a lot of functions have wait time that
608
+ is unrelated to processing, and therefore their timings won't be useful.
609
+ - Also useful if our auto function wrapping code is breaking functionality,
610
+ such as if you have a singleton function which you compare with ===,
611
+ which will breaks because we replaced it with a wrapped measure function.
612
+ */
613
+ noFunctionMeasure?: boolean;
614
+ }): SocketRegistered<ExtractShape<ClassInstance, Shape>> & Statics;
615
+ private static socketCache;
616
+ static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
617
+ private static callFromGuid;
618
+ static onNextDisconnect(nodeId: string, callback: () => void): void;
619
+ static getLastDisconnectTime(nodeId: string): number | undefined;
620
+ static isNodeConnected(nodeId: string): boolean;
621
+ /** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
622
+ * as we have no way of knowing how to contain a nodeId).
623
+ * */
624
+ static getHTTPCallLink(call: FullCallType): string;
625
+ private static ignoreExposeCount;
626
+ static ignoreExposeCalls<T>(code: () => Promise<T>): Promise<T>;
627
+ /** Expose should be called before your mounting occurs. It mostly just exists to ensure you include the class type,
628
+ * so the class type's module construction runs, which should trigger register. Otherwise you would have
629
+ * to add additional imports to ensure the register call runs.
630
+ */
631
+ static expose(socketRegistered: SocketRegistered): void;
632
+ static mountedNodeId: string;
633
+ static isMounted(): boolean;
634
+ static mountedIP: string;
635
+ private static hasMounted;
636
+ private static onMountCallback;
637
+ static mountPromise: Promise<void>;
638
+ static mount(config: SocketServerConfig): Promise<string>;
639
+ /** Sets the default call when an http request is made, but no classGuid is set.
640
+ * NOTE: All other calls should be endpoint calls, even if those endpoints return a static file with an HTML content type.
641
+ * - However, to load new content, you should probably just use `require("./example.ts")`, which works on any files
642
+ * clientside that have also been required serverside (and whitelisted with module.allowclient = true,
643
+ * or with an `allowclient.flag` file in the directory or parent directory).
644
+ */
645
+ static setDefaultHTTPCall<Registered extends SocketRegistered, FunctionName extends keyof Registered["nodes"][""] & string>(registered: Registered, functionName: FunctionName, ...args: Args<Registered["nodes"][""][FunctionName]>): void;
646
+ static connect(location: {
647
+ address: string;
648
+ port: number;
649
+ }): string;
650
+ static browserNodeId(): string;
651
+ static getBrowserNodeId(): string;
652
+ static addGlobalHook(hook: SocketFunctionHook): void;
653
+ static addGlobalClientHook(hook: SocketFunctionClientHook): void;
654
+ }
655
+ declare global {
656
+ var BOOTED_EDGE_NODE: {
657
+ host: string;
658
+ } | undefined;
659
+ }
660
+ export declare function _setSocketContext<T>(caller: CallerContext, code: () => T): T;
661
+ export {};
662
+
663
+ }
664
+
665
+ declare module "socket-function/SocketFunctionTypes" {
666
+ /// <reference path="require/RequireController.d.ts" />
667
+ import { getCallObj } from "./src/nodeProxy";
668
+ import { Args, MaybePromise } from "./src/types";
669
+ export declare const socket: unique symbol;
670
+ export type SocketExposedInterface = {
671
+ [functionName: string]: (...args: any[]) => Promise<unknown>;
672
+ };
673
+ export type SocketInternalInterface = {
674
+ [functionName: string]: {
675
+ [getCallObj]: (...args: any[]) => FullCallType;
676
+ (...args: any[]): Promise<unknown>;
677
+ };
678
+ };
679
+ export type SocketExposedInterfaceClass = {
680
+ new (): unknown;
681
+ prototype: unknown;
682
+ };
683
+ export type FunctionFlags = {
684
+ compress?: boolean;
685
+ /** Indicates with the same input, we give the same output, forever,
686
+ * independent of code changes. This only works for data storage.
687
+ */
688
+ dataImmutable?: boolean;
689
+ /** Allows overriding SocketFunction.MAX_MESSAGE_SIZE for responses from this function. */
690
+ responseLimit?: number;
691
+ };
692
+ export type SocketExposedShape<ExposedType extends SocketExposedInterface = SocketExposedInterface> = {
693
+ [functionName in keyof ExposedType]?: FunctionFlags & {
694
+ hooks?: SocketFunctionHook[];
695
+ clientHooks?: SocketFunctionClientHook[];
696
+ noDefaultHooks?: boolean;
697
+ /** BUG: I think this is broken if it is on the default hooks function? */
698
+ noClientHooks?: boolean;
699
+ };
700
+ };
701
+ export type FncType = (...args: any[]) => Promise<unknown>;
702
+ export interface CallType<FncT extends FncType = FncType, FncName extends string = string> {
703
+ classGuid: string;
704
+ functionName: FncName;
705
+ args: unknown[];
706
+ }
707
+ export interface FullCallType<FncT extends FncType = FncType, FncName extends string = string> extends CallType<FncT, FncName> {
708
+ nodeId: string;
709
+ }
710
+ export interface SocketFunctionHook {
711
+ (config: HookContext): MaybePromise<void>;
712
+ /** NOTE: This is useful when we need a clientside hook to set up state specifically for our serverside hook. */
713
+ clientHook?: SocketFunctionClientHook;
714
+ }
715
+ export type HookContext = {
716
+ call: FullCallType;
717
+ overrideResult?: unknown;
718
+ onResult: ((result: unknown) => MaybePromise<void>)[];
719
+ };
720
+ export type ClientHookContext = {
721
+ call: FullCallType;
722
+ overrideResult?: unknown;
723
+ onResult: ((result: unknown) => MaybePromise<void>)[];
724
+ connectionId: {
725
+ nodeId: string;
726
+ };
727
+ };
728
+ export interface SocketFunctionClientHook {
729
+ (config: ClientHookContext): MaybePromise<void>;
730
+ }
731
+ export interface SocketRegisterType<ExposedType = any> {
732
+ _classGuid: string;
733
+ _internalType: ExposedType;
734
+ }
735
+ export interface SocketRegistered<ExposedType = any> {
736
+ nodes: {
737
+ [nodeId: string]: {
738
+ [functionName in keyof ExposedType]: ExposedType[functionName] & {
739
+ [getCallObj]: (...args: Args<ExposedType[functionName]>) => FullCallType;
740
+ };
741
+ };
742
+ };
743
+ _classGuid: string;
744
+ _internalType: ExposedType;
745
+ }
746
+ export type ControllerPick<T extends SocketRegistered, K extends keyof T["_internalType"]> = (SocketRegistered<Pick<T["_internalType"], K>>);
747
+ export type CallerContext = Readonly<CallerContextBase>;
748
+ export type CallerContextBase = {
749
+ nodeId: string;
750
+ localNodeId: string;
751
+ };
752
+
753
+ }
754
+
755
+ declare module "socket-function/hot/HotReloadController" {
756
+ /// <reference path="../../typenode/index.d.ts" />
757
+ /// <reference path="../require/RequireController.d.ts" />
758
+ /** Enables some hot reload functionality.
759
+ * - Triggers a refresh clientside
760
+ * - Triggers a reload server, for modules marked with `module.hotreload`
761
+ */
762
+ export declare function watchFilesAndTriggerHotReloading(noAutomaticBrowserWatch?: boolean): void;
763
+ declare global {
764
+ namespace NodeJS {
765
+ interface Module {
766
+ /** Causes us to hotreload the file. Applies both serverside and clientside.
767
+ * - If not set for any files clientside, we will refresh.
768
+ * - If not set for any files serverside, we will do nothing (and just leave old code running).
769
+ */
770
+ hotreload?: boolean;
771
+ /** Overrides hotreload to disable hot reloading. Useful if you add "hotreload.flag" to a directory
772
+ * (which sets hotreload on all files in and under that directory), but want a specific file
773
+ * to not hotreload.
774
+ * - Also useful if you want files to hotreload clientside, but not serverside.
775
+ */
776
+ noserverhotreload?: boolean;
777
+ watchAdditionalFiles?: string[];
778
+ }
779
+ }
780
+ var isHotReloading: (() => boolean) | undefined;
781
+ }
782
+ export declare function isHotReloading(): boolean;
783
+ export declare function hotReloadingGuard(): true;
784
+ export declare function setExternalHotReloading(value: boolean): void;
785
+ export declare function onHotReload(callback: (modules: NodeJS.Module[]) => void): void;
786
+ export declare const HotReloadController: import("../SocketFunctionTypes").SocketRegistered<{
787
+ watchFiles: () => Promise<void>;
788
+ fileUpdated: (files: string[], changeTime: number) => Promise<void>;
789
+ }>;
790
+
791
+ }
792
+
793
+ declare module "socket-function/index" {
794
+ // Auto-generated file. Do not edit manually.
795
+ // Generated by: yarn generate-index-dts
796
+
797
+ declare module "socket-function/SetProcessVariables" {
798
+ export {};
799
+
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
+ }
1024
+ }
1025
+ var isHotReloading: (() => boolean) | undefined;
1026
+ }
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;
1091
+ };
1092
+ get(): T;
1093
+ set(value: T): void;
1094
+ reset(): void;
1095
+ get value(): T;
1096
+ set value(value: T);
1097
+ }
1098
+
1099
+ }
1100
+
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;
1120
+
1121
+ }
1122
+
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;
1198
+ };
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>;
1220
+
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
+
2003
+ }
2004
+
2005
+ declare module "socket-function/mobx/UrlParam" {
2006
+ export declare class UrlParam<T> {
2007
+ private key;
2008
+ private defaultValue;
2009
+ constructor(key: string, defaultValue: T);
2010
+ valueSeqNum: {
2011
+ value: number;
2012
+ };
2013
+ get(): T;
2014
+ set(value: T): void;
2015
+ reset(): void;
2016
+ get value(): T;
2017
+ set value(value: T);
2018
+ }
2019
+
2020
+ }
2021
+
2022
+ declare module "socket-function/mobx/observer" {
2023
+ import type preact from "preact";
2024
+ import { Reaction } from "mobx";
2025
+ export declare function observer<T extends {
2026
+ new (...args: any[]): {
2027
+ render(): preact.ComponentChild;
2028
+ forceUpdate(callback?: () => void): void;
2029
+ componentWillUnmount?(): void;
2030
+ };
2031
+ }>(Constructor: T): {
2032
+ new (...args: any[]): {
2033
+ constructOrder: number;
2034
+ reaction: Reaction;
2035
+ componentWillUnmount(): void;
2036
+ render(): preact.ComponentChild;
2037
+ forceUpdate(callback?: () => void): void;
2038
+ };
2039
+ readonly name: string;
2040
+ } & T;
2041
+
2042
+ }
2043
+
2044
+ declare module "socket-function/mobx/promiseToObservable" {
2045
+ export interface InternalResult {
2046
+ result: {
2047
+ value: unknown;
2048
+ } | undefined;
2049
+ }
2050
+ export declare function promiseToObservable<T>(promise: Promise<T>, staleValue?: T): {
2051
+ value: T | undefined;
2052
+ };
2053
+
2054
+ }
2055
+
2056
+ declare module "socket-function/require/CSSShim" {
2057
+ /// <reference path="RequireController.d.ts" />
2058
+ export {};
2059
+
2060
+ }
2061
+
2062
+ declare module "socket-function/require/compileFlags" {
2063
+ /// <reference path="RequireController.d.ts" />
2064
+ /// <reference types="node" />
2065
+ /**
2066
+ * Adds a global function setFlag(require, "typescript", flag) which sets a flag on the client
2067
+ * - Ex, setFlag(require, "typescript", "allowclient") so allowclient = true on the typescript module.
2068
+ * - Passing true as the fourth argument sets it recursively
2069
+ */
2070
+ export declare const forceModule = true;
2071
+ declare global {
2072
+ }
2073
+ export declare function setFlag(require: NodeRequire, request: string, flag: string, recursive?: boolean): void;
2074
+
2075
+ }
2076
+
2077
+ declare module "socket-function/require/extMapper" {
2078
+ /// <reference types="node" />
2079
+ /// <reference types="node" />
2080
+ export declare function getExtContentType(ext: string): string;
2081
+ export declare function getContentTypeFromBuffer(buffer: Buffer): string | undefined;
2082
+
2083
+ }
2084
+
2085
+ declare module "socket-function/require/require" {
2086
+ /// <reference path="../index.d.ts" />
2087
+ declare global {
2088
+ var onProgressHandler: undefined | ((progress: {
2089
+ type: string;
2090
+ addValue: number;
2091
+ addMax: number;
2092
+ }) => void);
2093
+ var onErrorHandler: undefined | ((error: string) => void);
2094
+ var BOOT_TIME: number;
2095
+ var builtInModuleExports: {
2096
+ [key: string]: unknown;
2097
+ };
2098
+ }
2099
+ export declare function requireMain(): void;
2100
+
2101
+ }
2102
+
2103
+ declare module "socket-function/src/CallFactory" {
2104
+ /// <reference types="node" />
2105
+ /// <reference types="node" />
2106
+ /// <reference types="node" />
2107
+ import { CallType } from "../SocketFunctionTypes";
2108
+ import * as ws from "ws";
2109
+ import * as tls from "tls";
2110
+ export interface CallFactory {
2111
+ nodeId: string;
2112
+ lastClosed: number;
2113
+ closedForever?: boolean;
2114
+ isConnected?: boolean;
2115
+ performCall(call: CallType): Promise<unknown>;
2116
+ onNextDisconnect(callback: () => void): void;
2117
+ connectionId: {
2118
+ nodeId: string;
2119
+ };
2120
+ }
2121
+ export interface SenderInterface {
2122
+ nodeId?: string;
2123
+ _socket?: tls.TLSSocket;
2124
+ send(data: string | Buffer): void;
2125
+ addEventListener(event: "open", listener: () => void): void;
2126
+ addEventListener(event: "close", listener: () => void): void;
2127
+ addEventListener(event: "error", listener: (err: {
2128
+ message: string;
2129
+ }) => void): void;
2130
+ addEventListener(event: "message", listener: (data: ws.RawData | ws.MessageEvent | string) => void): void;
2131
+ readyState: number;
2132
+ ping?(): void;
2133
+ }
2134
+ export declare function harvestFailedCallCount(): number;
2135
+ export declare function getPendingCallCount(): number;
2136
+ export declare function harvestCallTimes(): {
2137
+ start: number;
2138
+ end: number;
2139
+ }[];
2140
+ export declare function createCallFactory(webSocketBase: SenderInterface | undefined, nodeId: string, localNodeId?: string): Promise<CallFactory>;
2141
+
2142
+ }
2143
+
2144
+ declare module "socket-function/src/JSONLACKS/JSONLACKS" {
2145
+ /// <reference types="node" />
2146
+ /// <reference types="node" />
2147
+ export interface JSONLACKS_ParseConfig {
2148
+ extended?: boolean;
2149
+ discardMissingReferences?: boolean;
2150
+ }
2151
+ export interface JSONLACKS_StringifyConfig {
2152
+ allowObjectMutation?: boolean;
2153
+ }
2154
+ interface HydrateState {
2155
+ references: Map<string, unknown>;
2156
+ visited: Set<unknown>;
2157
+ }
2158
+ export declare class JSONLACKS {
2159
+ static readonly LACKS_KEY = "__JSONLACKS__98cfb4a05fa34d828661cae15b8779ce__";
2160
+ /** If set to true parses non-quoted field names, comments, trailing commas, etc */
2161
+ static EXTENDED_PARSER: boolean;
2162
+ static IGNORE_MISSING_REFERENCES: boolean;
2163
+ static stringify(obj: unknown, config?: JSONLACKS_StringifyConfig): string;
2164
+ /** Is useful when serializing an array to a file with one object per line */
2165
+ static stringifyFile(obj: unknown[], config?: JSONLACKS_StringifyConfig): Promise<Buffer>;
2166
+ static stringifyFileSync(obj: unknown[], config?: JSONLACKS_StringifyConfig): Buffer;
2167
+ static parse<T>(text: string, config?: JSONLACKS_ParseConfig, hydrateState?: HydrateState): T;
2168
+ static parseLines<T>(buffer: Buffer, config?: JSONLACKS_ParseConfig): Promise<T[]>;
2169
+ private static escapeSpecialObjects;
2170
+ private static hydrateSpecialObjects;
2171
+ }
2172
+ export {};
2173
+
2174
+ }
2175
+
2176
+ declare module "socket-function/src/JSONLACKS/JSONLACKS.generated.js" {
2177
+ export function parse(text: string): unknown;
2178
+ }
2179
+
2180
+ declare module "socket-function/src/args" {
2181
+ export declare const getArgs: {
2182
+ (): {
2183
+ [key: string]: string | undefined;
2184
+ };
2185
+ reset(): void;
2186
+ set(newValue: {
2187
+ [key: string]: string | undefined;
2188
+ }): void;
2189
+ };
2190
+
2191
+ }
2192
+
2193
+ declare module "socket-function/src/batching" {
2194
+ import { AnyFunction } from "./types";
2195
+ export type DelayType = (number | "afterio" | "immediate" | "afterpromises" | "paintLoop" | "afterPaint");
2196
+ export declare function delay(delayTime: DelayType, immediateShortDelays?: "immediateShortDelays"): Promise<void>;
2197
+ export declare function batchFunctionNone<Arg, Result = void>(config: unknown, fnc: (arg: Arg[]) => (Promise<Result> | Result)): (arg: Arg) => Promise<Result>;
2198
+ export declare function batchFunction<Arg, Result = void>(config: {
2199
+ delay: DelayType;
2200
+ /** Instead of immediately waiting delay, starts by waiting 0ms, and every call increments the delay factor
2201
+ * by 1. Delay is `factor * (delay / throttleWindow)`. For every delay interval we have no calls, we decrease by
2202
+ * no_calls/delay.
2203
+ * - This essentially turns delay into a `calls per second` type indicator (ex, 10ms is 100 callers
2204
+ * per second, 500ms is 2 calls, etc), which is accurate over delay * throttleWindow time.
2205
+ */
2206
+ throttleWindow?: number;
2207
+ name?: string;
2208
+ noMeasure?: boolean;
2209
+ }, fnc: (arg: Arg[]) => (Promise<Result> | Result)): (arg: Arg) => Promise<Result>;
2210
+ export declare function runInSerial<T extends (...args: any[]) => Promise<any>>(fnc: T): T;
2211
+ export declare function runInParallel<T extends (...args: any[]) => Promise<any>>(config: {
2212
+ parallelCount: number;
2213
+ callTimeout?: number;
2214
+ }, fnc: T): T;
2215
+ export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void): void;
2216
+ export declare function runInfinitePollCallAtStart(delayTime: number, fnc: () => Promise<void> | void): Promise<void>;
2217
+ /** Disables polling, called on shutdown. Blocks until all pending poll loops finish */
2218
+ export declare function shutdownPolling(): Promise<void>;
2219
+ export declare function retryFunctional<T extends AnyFunction>(fnc: T, config?: {
2220
+ maxRetries?: number;
2221
+ shouldRetry?: (message: string) => boolean;
2222
+ minDelay?: number;
2223
+ maxDelay?: number;
2224
+ }): T;
2225
+
2226
+ }
2227
+
2228
+ declare module "socket-function/src/caching" {
2229
+ import { AnyFunction, Args } from "./types";
2230
+ export declare function lazy<T>(factory: () => T): {
2231
+ (): T;
2232
+ reset(): void;
2233
+ set(newValue: T): void;
2234
+ };
2235
+ export declare function cacheEmptyArray<T>(array: T[]): T[];
2236
+ export declare function cache<Output, Key, Untracked extends unknown[]>(getValue: (key: Key, ...untracked: Untracked) => Output): {
2237
+ (key: Key, ...untracked: Untracked): Output;
2238
+ clear(key: Key): void;
2239
+ clearAll(): void;
2240
+ forceSet(key: Key, value: Output): void;
2241
+ getAllKeys(): Key[];
2242
+ get(key: Key): Output | undefined;
2243
+ };
2244
+ /** Makes a cache that limits the number of entries, allowing you to put arbitrary data in it
2245
+ * without worrying about leaking memory
2246
+ */
2247
+ export declare function cacheLimited<Output, Key>(maxCount: number, getValue: (key: Key) => Output): {
2248
+ (input: Key): Output;
2249
+ forceSet(key: Key, value: Output): void;
2250
+ clearKey(key: Key): void;
2251
+ clear(): void;
2252
+ };
2253
+ export declare function cacheWeak<Output, Key extends object>(getValue: (key: Key) => Output): (key: Key) => Output;
2254
+ export declare function cacheList<Value>(getLength: () => number, getValue: (index: number) => Value): {
2255
+ (index: number): Value;
2256
+ };
2257
+ /** A cache half way between caching based on === and caching based on hash. Caches
2258
+ * based on arrayEqual, which does === on all values in an array. Requires localized
2259
+ * caching (as the comparisons don't scale with many candidates, unlike hashing),
2260
+ * however works with non trival transformations (ex, resolving many persisted overrides
2261
+ * to get a value), unlike cache().
2262
+ * Also, limits itself, more of a performance optimization than memory optimization, as it scales
2263
+ * very poorly with the number of candidates.
2264
+ *
2265
+ * TIMING: About 6us with limit = 100, array size = 294, and the cache being full.
2266
+ */
2267
+ export declare function cacheArrayEqual<Input extends unknown[] | undefined, Output>(map: (arrays: Input) => Output, limit?: number): {
2268
+ (array: Input): Output;
2269
+ clear(array: Input): void;
2270
+ clearAll(): void;
2271
+ };
2272
+ /** Caches when arguments are ===. See cacheArrayEqual */
2273
+ export declare function cacheArgsEqual<Fnc extends AnyFunction>(fnc: Fnc, limit?: number): Fnc & {
2274
+ clear(...args: Args<Fnc>): void;
2275
+ };
2276
+ export declare function cacheJSONArgsEqual<Fnc extends AnyFunction>(fnc: Fnc, limit?: number): Fnc & {
2277
+ clear(...args: unknown[]): void;
2278
+ clearAll(): void;
2279
+ };
2280
+ export declare function cacheShallowConfigArgEqual<Fnc extends AnyFunction>(fnc: Fnc, limit?: number): Fnc & {
2281
+ clear(configObj: Args<Fnc>[0]): void;
2282
+ clearAll(): void;
2283
+ };
2284
+ export declare function externalCache<Key, Value>(): {
2285
+ get: (key: Key) => Value | undefined;
2286
+ set: (key: Key, value: Value) => void;
2287
+ };
2288
+
2289
+ }
2290
+
2291
+ declare module "socket-function/src/callHTTPHandler" {
2292
+ /// <reference types="node" />
2293
+ /// <reference types="node" />
2294
+ /// <reference types="node" />
2295
+ import http from "http";
2296
+ import { CallType } from "../SocketFunctionTypes";
2297
+ export declare function setDefaultHTTPCall(call: CallType): void;
2298
+ export declare function getServerLocationFromRequest(request: http.IncomingMessage): {
2299
+ address: string;
2300
+ port: number;
2301
+ };
2302
+ export declare function getNodeIdsFromRequest(request: http.IncomingMessage): {
2303
+ nodeId: string;
2304
+ localNodeId: string;
2305
+ };
2306
+ export declare function getCurrentHTTPRequest(): http.IncomingMessage | undefined;
2307
+ export declare function httpCallHandler(request: http.IncomingMessage, response: http.ServerResponse): Promise<void>;
2308
+ declare const resultHeaders: unique symbol;
2309
+ type HTTPResultType = Buffer & {
2310
+ [resultHeaders]?: {
2311
+ [header: string]: string;
2312
+ };
2313
+ };
2314
+ export declare function setHTTPResultHeaders(result: HTTPResultType, headers: {
2315
+ [header: string]: string;
2316
+ }): HTTPResultType;
2317
+ export {};
2318
+
2319
+ }
2320
+
2321
+ declare module "socket-function/src/callManager" {
2322
+ /// <reference path="../hot/HotReloadController.d.ts" />
2323
+ import { CallerContext, CallType, ClientHookContext, FullCallType, FunctionFlags, HookContext, SocketExposedInterface, SocketExposedShape, SocketFunctionClientHook, SocketFunctionHook, SocketRegistered } from "../SocketFunctionTypes";
2324
+ export declare function getCallFlags(call: CallType): FunctionFlags | undefined;
2325
+ export declare function shouldCompressCall(call: CallType): boolean;
2326
+ export declare function performLocalCall(config: {
2327
+ call: FullCallType;
2328
+ caller: CallerContext;
2329
+ }): Promise<unknown>;
2330
+ export declare function isDataImmutable(call: CallType): boolean;
2331
+ export declare function registerClass(classGuid: string, controller: SocketExposedInterface, shape: SocketExposedShape, config?: {
2332
+ noFunctionMeasure?: boolean;
2333
+ }): void;
2334
+ export declare function exposeClass(exposedClass: SocketRegistered): void;
2335
+ export declare function registerGlobalHook(hook: SocketFunctionHook): void;
2336
+ export declare function unregisterGlobalHook(hook: SocketFunctionHook): void;
2337
+ export declare function registerGlobalClientHook(hook: SocketFunctionClientHook): void;
2338
+ export declare function unregisterGlobalClientHook(hook: SocketFunctionClientHook): void;
2339
+ export declare const runClientHooks: (callType: FullCallType, hooks: Exclude<SocketExposedShape[""], undefined>, connectionId: {
2340
+ nodeId: string;
2341
+ }) => Promise<ClientHookContext>;
2342
+ export declare const runServerHooks: (callType: FullCallType, caller: CallerContext, hooks: Exclude<SocketExposedShape[""], undefined>) => Promise<HookContext>;
2343
+
2344
+ }
2345
+
2346
+ declare module "socket-function/src/certStore" {
2347
+ /// <reference types="node" />
2348
+ /// <reference types="node" />
2349
+ /** Must be populated before the server starts */
2350
+ export declare function trustCertificate(cert: string | Buffer): void;
2351
+ export declare function getTrustedCertificates(): string[];
2352
+ export declare function watchTrustedCertificates(callback: (certs: string[]) => void): () => boolean;
2353
+
2354
+ }
2355
+
2356
+ declare module "socket-function/src/corsCheck" {
2357
+
2358
+ }
2359
+
2360
+ declare module "socket-function/src/fixLargeNetworkCalls" {
2361
+ export declare function markArrayAsSplitable<T>(data: T[]): T[];
2362
+ export declare function isSplitableArray<T>(data: T): data is T & (unknown[]);
2363
+
2364
+ }
2365
+
2366
+ declare module "socket-function/src/formatting/colors" {
2367
+ export type HSL = {
2368
+ h: number;
2369
+ s: number;
2370
+ l: number;
2371
+ };
2372
+ export declare function hslText(color: HSL): string;
2373
+ export declare function hslToRGB(color: HSL): {
2374
+ r: number;
2375
+ g: number;
2376
+ b: number;
2377
+ };
2378
+ export declare function hslToHex(color: HSL): string;
2379
+ export declare function hslLightenGamma(hsl: HSL, fraction: number): {
2380
+ h: number;
2381
+ s: number;
2382
+ l: number;
2383
+ };
2384
+ export declare function hslLightenLinear(hsl: HSL, lightness: number): {
2385
+ h: number;
2386
+ s: number;
2387
+ l: number;
2388
+ };
2389
+ export declare function hslDarkenGamma(hsl: HSL, fraction: number): {
2390
+ h: number;
2391
+ s: number;
2392
+ l: number;
2393
+ };
2394
+ export declare function hslDarkenLinear(hsl: HSL, lightness: number): {
2395
+ h: number;
2396
+ s: number;
2397
+ l: number;
2398
+ };
2399
+ export declare function hslAddSaturate(hsl: HSL, saturation: number): {
2400
+ h: number;
2401
+ s: number;
2402
+ l: number;
2403
+ };
2404
+ export declare function hslSetSaturate(hsl: HSL, saturation: number): {
2405
+ h: number;
2406
+ s: number;
2407
+ l: number;
2408
+ };
2409
+
2410
+ }
2411
+
2412
+ declare module "socket-function/src/formatting/format" {
2413
+ export declare function formatTime(milliseconds: number | undefined, maxAbsoluteValue?: number): string;
2414
+ export declare function getTargetDecimals(maxAbsoluteValue: number, targetDigits: number): number;
2415
+ /** Adds decimal digits to reach digits. If the number is simply too large, it won't remove
2416
+ * digits, there will instead just be no decimal point.
2417
+ */
2418
+ export declare function formatMaxDecimals(num: number, targetDigits: number, maxAbsoluteValue?: number, exactDecimals?: number): string;
2419
+ /** Actually formats any number, including decimals, by using K, M and B suffixes to get smaller values
2420
+ * TODO: Support uK, uM and uB suffixes for very small numbers?
2421
+ * <= 6 characters (<= 5 if positive)
2422
+ */
2423
+ export declare function formatNumber(count: number | undefined, maxAbsoluteValue?: number, noDecimal?: boolean, specialCurrency?: boolean): string;
2424
+ export declare function formatBinaryNumber(count: number | undefined, maxAbsoluteValue?: number, noDecimal?: boolean, specialCurrency?: boolean): string;
2425
+ /** YYYY/MM/DD HH:MM:SS PM/AM */
2426
+ export declare function formatDateTime(time: number): string;
2427
+ export declare function formatDateTimeDetailed(time: number): string;
2428
+ export declare function formatFileTimestampLocal(time: number): string;
2429
+ /** 2024 January 1, Monday, 12:53:02pm */
2430
+ export declare function formatNiceDateTime(time: number): string;
2431
+ /** 2024 January 1, Monday, 12:53:02pm (4 months ago) */
2432
+ export declare function formatVeryNiceDateTime(time: number): string;
2433
+ /** YYYY/MM/DD */
2434
+ export declare function formatDate(time: number): string;
2435
+ /** <= 6 characters (<= 5 if positive) */
2436
+ export declare function formatPercent(value: number): string;
2437
+
2438
+ }
2439
+
2440
+ declare module "socket-function/src/formatting/logColors" {
2441
+ export declare const blue: (text: string) => string;
2442
+ export declare const red: (text: string) => string;
2443
+ export declare const green: (text: string) => string;
2444
+ export declare const yellow: (text: string) => string;
2445
+ export declare const white: (text: string) => string;
2446
+ export declare const gray: (text: string) => string;
2447
+ export declare const magenta: (text: string) => string;
2448
+
2449
+ }
2450
+
2451
+ declare module "socket-function/src/forwardPort" {
2452
+ export declare function forwardPort(config: {
2453
+ externalPort: number;
2454
+ internalPort: number;
2455
+ duration?: number;
2456
+ }): Promise<void>;
2457
+
2458
+ }
2459
+
2460
+ declare module "socket-function/src/https" {
2461
+ /// <reference types="node" />
2462
+ /// <reference types="node" />
2463
+ export declare function httpsRequest(url: string, payload?: Buffer | Buffer[], method?: string, sendSessionCookies?: boolean, config?: {
2464
+ headers?: {
2465
+ [key: string]: string | undefined;
2466
+ };
2467
+ cancel?: Promise<void>;
2468
+ }): Promise<Buffer>;
518
2469
 
519
- declare module "socket-function/index" {
520
- // Auto-generated file. Do not edit manually.
521
- // Generated by: yarn generate-index-dts
2470
+ }
522
2471
 
523
- declare module "socket-function/SetProcessVariables" {
524
- export {};
2472
+ declare module "socket-function/src/misc" {
2473
+ /// <reference types="node" />
2474
+ /// <reference types="node" />
2475
+ import { MaybePromise } from "./types";
2476
+ export declare const timeInSecond = 1000;
2477
+ export declare const timeInMinute: number;
2478
+ export declare const timeInHour: number;
2479
+ export declare const timeInDay: number;
2480
+ export declare const timeInWeek: number;
2481
+ export declare const timeInYear: number;
2482
+ export type Watchable<T> = (callback: (value: T) => void) => MaybePromise<void>;
2483
+ export declare function convertErrorStackToError(error: string): Error;
2484
+ export declare function sha256Hash(buffer: Buffer | string): string;
2485
+ export declare function sha256HashBuffer(buffer: Buffer | string): Buffer;
2486
+ /** Async, but works both clientside and serverside. */
2487
+ export declare function sha256HashPromise(buffer: Buffer): Promise<any>;
2488
+ export declare function sha256BufferPromise(buffer: Buffer): Promise<Buffer>;
2489
+ export declare function arrayEqual(a: {
2490
+ [key: number]: unknown;
2491
+ length: number;
2492
+ }, b: {
2493
+ [key: number]: unknown;
2494
+ length: number;
2495
+ }): boolean;
2496
+ export declare function isNode(): boolean;
2497
+ export declare function isNodeTrue(): true;
2498
+ export declare function formatNumberSuffixed(count: number): string;
2499
+ export declare function list(count: number): number[];
2500
+ export declare function recursiveFreeze<T>(obj: T): T;
2501
+ export type ArrayBufferViewTypes = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | BigUint64Array | BigInt64Array | Float64Array | Float32Array | Uint8ClampedArray;
2502
+ export type BufferType = ArrayBuffer | SharedArrayBuffer | ArrayBufferViewTypes;
2503
+ export declare function isBufferType(obj: unknown): obj is BufferType;
2504
+ export declare function getKeys(obj: unknown): PropertyKey[];
2505
+ export declare function getStringKeys<T extends {}>(obj: T): ((keyof T) & string)[];
2506
+ export declare function keyBy<T, K>(arr: T[], getKey: (value: T) => K): Map<K, T>;
2507
+ export declare function keyByArray<T, K>(arr: T[], getKey: (value: T) => K): Map<K, T[]>;
2508
+ export declare function deepCloneJSON<T>(obj: T): T;
2509
+ export declare class PromiseObj<T = void> {
2510
+ promise: Promise<T>;
2511
+ value: {
2512
+ value?: T;
2513
+ error?: string;
2514
+ } | undefined;
2515
+ /** Resolve called does not mean the value is ready, as it may be resolved with a promise. */
2516
+ resolveCalled?: boolean;
2517
+ resolve: (value: T | Promise<T>) => void;
2518
+ reject: (error: any) => void;
2519
+ private baseResolve;
2520
+ private baseReject;
2521
+ constructor();
2522
+ }
2523
+ export declare function promiseObj<T = void>(): PromiseObj<T>;
2524
+ export declare function throttleFunction<Args extends any[]>(delay: number, fnc: (...args: Args) => MaybePromise<void>): (...args: Args) => Promise<void>;
2525
+ export declare function nextId(): string;
2526
+ export declare function arrayFromOrderObject<T>(obj: {
2527
+ [order: number]: T;
2528
+ }): T[];
2529
+ export declare function last<T>(arr: T[]): T | undefined;
2530
+ export type ObjectValues<T> = T[keyof T];
2531
+ export declare function entries<Obj extends {
2532
+ [key: string]: unknown;
2533
+ }>(obj: Obj): [keyof Obj, ObjectValues<Obj>][];
2534
+ export declare function keys<Obj extends {
2535
+ [key: string]: unknown;
2536
+ }>(obj: Obj): (keyof Obj)[];
2537
+ export declare function sort<T>(arr: T[], sortKey: (obj: T) => unknown): T[];
2538
+ export declare function getRootDomain(hostname: string): string;
2539
+ export declare class QueueLimited<T> {
2540
+ private readonly maxCount;
2541
+ private items;
2542
+ private nextIndex;
2543
+ constructor(maxCount: number);
2544
+ push(item: T): void;
2545
+ getAllUnordered(): T[];
2546
+ reset(): void;
2547
+ clear(): void;
2548
+ getOldest(): T | undefined;
2549
+ }
2550
+ export declare function binarySearchBasic<T, V>(array: T[], getVal: (val: T) => V, searchValue: V): number;
2551
+ export declare function binarySearchBasic2<T, V>(array: T[], getVal: (val: T) => V, searchValue: T): number;
2552
+ /**
2553
+ * Searches indexes, allowing you to query structures that aren't arrays. To search an array, use:
2554
+ * `binarySearchIndex(array.length, i => compare(array[i], searchValue))`
2555
+ *
2556
+ * NOTE: If there are duplicates, returns the first match.
2557
+ *
2558
+ * NOTE: If the value can't be found, returns the bitwise negation of the index where it should be inserted.
2559
+ *
2560
+ * NOTE: With `if (index < 0) index = ~index;` you will get an index of the value >= the target value.
2561
+ */
2562
+ export declare function binarySearchIndex(listCount: number, compare: (lhsIndex: number) => number): number;
2563
+ export declare function compare(lhs: unknown, rhs: unknown): number;
2564
+ export declare function compareArray(lhs: unknown[], rhs: unknown[]): number;
2565
+ export declare function insertIntoSortedList<T>(list: T[], map: (val: T) => string | number, element: T): void;
2566
+ export declare function removeFromSortedList<T>(list: T[], map: (val: T) => string | number, searchValue: string | number): void;
2567
+ export declare function timeoutToError<T>(time: number, p: Promise<T>, err: () => Error): Promise<T>;
2568
+ export declare function timeoutToUndefined<T>(time: number, p: Promise<T>): Promise<T | undefined>;
2569
+ export declare function timeoutToUndefinedSilent<T>(time: number, p: Promise<T>): Promise<T | undefined>;
2570
+ export declare function errorToWarning<T>(promise: Promise<T>): void;
525
2571
 
526
- }
2572
+ }
527
2573
 
528
- declare module "socket-function/SocketFunction" {
529
- /// <reference path="require/RequireController.d.ts" />
530
- /// <reference types="node" />
531
- /// <reference types="node" />
532
- import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, SocketRegisterType } from "./SocketFunctionTypes";
533
- import { SocketServerConfig } from "./src/webSocketServer";
534
- import { Args, MaybePromise } from "./src/types";
535
- import "./SetProcessVariables";
536
- type ExtractShape<ClassType, Shape> = {
537
- [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");
538
- };
539
- export declare class SocketFunction {
540
- static logMessages: boolean;
541
- static trackMessageSizes: {
542
- upload: ((size: number) => void)[];
543
- download: ((size: number) => void)[];
544
- callTimes: ((obj: {
545
- start: number;
546
- end: number;
547
- }) => void)[];
2574
+ declare module "socket-function/src/networking" {
2575
+ export declare const testTCPIsListening: (host: string, port: number) => Promise<boolean>;
2576
+ export declare const getExternalIP: {
2577
+ (): Promise<string>;
2578
+ reset(): void;
2579
+ set(newValue: Promise<string>): void;
548
2580
  };
549
- static MAX_MESSAGE_SIZE: number;
550
- static HTTP_ETAG_CACHE: boolean;
551
- static silent: boolean;
552
- static HTTP_COMPRESS: boolean;
553
- static COEP: string;
554
- static COOP: string;
555
- static readonly WIRE_SERIALIZER: {
556
- serialize: (obj: unknown) => MaybePromise<Buffer[]>;
557
- deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
2581
+ export declare const getPublicIP: {
2582
+ (): Promise<string>;
2583
+ reset(): void;
2584
+ set(newValue: Promise<string>): void;
558
2585
  };
559
- static WIRE_WARN_TIME: number;
560
- private static onMountCallbacks;
561
- static exposedClasses: Set<string>;
562
- static callerContext: CallerContext | undefined;
563
- static getCaller(): CallerContext;
564
- static harvestFailedCallCount: () => number;
565
- static getPendingCallCount: () => number;
566
- static harvestCallTimes: () => {
567
- start: number;
568
- end: number;
569
- }[];
570
- static register<ClassInstance extends object, Shape extends SocketExposedShape<{
571
- [key in keyof ClassInstance]: (...args: any[]) => Promise<unknown>;
572
- }>, Statics>(classGuid: string, instance: ClassInstance | (() => ClassInstance), shapeFnc: () => Shape, defaultHooksFnc?: () => SocketExposedShape[""] & {
573
- onMount?: () => MaybePromise<void>;
574
- }, config?: {
575
- /** @noAutoExpose If true SocketFunction.expose(Controller) must be called explicitly. */
576
- noAutoExpose?: boolean;
577
- statics?: Statics;
578
- /** Skip timing functions calls. Useful if a lot of functions have wait time that
579
- is unrelated to processing, and therefore their timings won't be useful.
580
- - Also useful if our auto function wrapping code is breaking functionality,
581
- such as if you have a singleton function which you compare with ===,
582
- which will breaks because we replaced it with a wrapped measure function.
583
- */
584
- noFunctionMeasure?: boolean;
585
- }): SocketRegistered<ExtractShape<ClassInstance, Shape>> & Statics;
586
- private static socketCache;
587
- static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
588
- private static callFromGuid;
589
- static onNextDisconnect(nodeId: string, callback: () => void): void;
590
- static getLastDisconnectTime(nodeId: string): number | undefined;
591
- static isNodeConnected(nodeId: string): boolean;
592
- /** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
593
- * as we have no way of knowing how to contain a nodeId).
2586
+
2587
+ }
2588
+
2589
+ declare module "socket-function/src/nodeCache" {
2590
+ import { CallFactory } from "./CallFactory";
2591
+ import { MaybePromise } from "./types";
2592
+ export declare function getNodeId(domain: string, port: number): string;
2593
+ /** @deprecated, call getBrowserUrlNode instead, which does important additional checks. */
2594
+ export declare function getNodeIdFromLocation(): string;
2595
+ /** A nodeId not available for reconnecting. */
2596
+ export declare function getClientNodeId(address: string): string;
2597
+ export declare function isClientNodeId(nodeId: string): boolean;
2598
+ /** Will always be available, even if getNodeIdLocation is not (as we don't always have the port,
2599
+ * but we should always have an address).
2600
+ * - Rarely used, as for logging you can just log the nodeId. ALSO, it isn't sufficient to reconnect, as the port is also needed!
594
2601
  * */
595
- static getHTTPCallLink(call: FullCallType): string;
596
- private static ignoreExposeCount;
597
- static ignoreExposeCalls<T>(code: () => Promise<T>): Promise<T>;
598
- /** Expose should be called before your mounting occurs. It mostly just exists to ensure you include the class type,
599
- * so the class type's module construction runs, which should trigger register. Otherwise you would have
600
- * to add additional imports to ensure the register call runs.
601
- */
602
- static expose(socketRegistered: SocketRegistered): void;
603
- static mountedNodeId: string;
604
- static isMounted(): boolean;
605
- static mountedIP: string;
606
- private static hasMounted;
607
- private static onMountCallback;
608
- static mountPromise: Promise<void>;
609
- static mount(config: SocketServerConfig): Promise<string>;
610
- /** Sets the default call when an http request is made, but no classGuid is set.
611
- * NOTE: All other calls should be endpoint calls, even if those endpoints return a static file with an HTML content type.
612
- * - However, to load new content, you should probably just use `require("./example.ts")`, which works on any files
613
- * clientside that have also been required serverside (and whitelisted with module.allowclient = true,
614
- * or with an `allowclient.flag` file in the directory or parent directory).
615
- */
616
- static setDefaultHTTPCall<Registered extends SocketRegistered, FunctionName extends keyof Registered["nodes"][""] & string>(registered: Registered, functionName: FunctionName, ...args: Args<Registered["nodes"][""][FunctionName]>): void;
617
- static connect(location: {
2602
+ export declare function getNodeIdIP(nodeId: string): string;
2603
+ export declare function getNodeIdLocation(nodeId: string): {
618
2604
  address: string;
619
2605
  port: number;
620
- }): string;
621
- static browserNodeId(): string;
622
- static getBrowserNodeId(): string;
623
- static addGlobalHook(hook: SocketFunctionHook): void;
624
- static addGlobalClientHook(hook: SocketFunctionClientHook): void;
625
- }
626
- declare global {
627
- var BOOTED_EDGE_NODE: {
628
- host: string;
629
2606
  } | undefined;
2607
+ export declare function getNodeIdDomain(nodeId: string): string;
2608
+ export declare function getNodeIdDomainMaybeUndefined(nodeId: string): string | undefined;
2609
+ export declare function registerNodeClient(callFactory: CallFactory): void;
2610
+ export declare function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory>;
2611
+ export declare function getCallFactory(nodeId: string): MaybePromise<CallFactory | undefined>;
2612
+ export declare function resetAllNodeCallFactories(): void;
2613
+ export declare function countOpenConnections(): number;
2614
+
630
2615
  }
631
- export declare function _setSocketContext<T>(caller: CallerContext, code: () => T): T;
632
- export {};
633
2616
 
634
- }
2617
+ declare module "socket-function/src/nodeProxy" {
2618
+ import { FullCallType, SocketInternalInterface } from "../SocketFunctionTypes";
2619
+ type CallProxyType = {
2620
+ [nodeId: string]: SocketInternalInterface;
2621
+ };
2622
+ export declare const getCallObj: unique symbol;
2623
+ export declare function getCallProxy(id: string, callback: (callType: FullCallType) => Promise<unknown>): CallProxyType;
2624
+ export {};
635
2625
 
636
- declare module "socket-function/SocketFunctionTypes" {
637
- /// <reference path="require/RequireController.d.ts" />
638
- import { getCallObj } from "./src/nodeProxy";
639
- import { Args, MaybePromise } from "./src/types";
640
- export declare const socket: unique symbol;
641
- export type SocketExposedInterface = {
642
- [functionName: string]: (...args: any[]) => Promise<unknown>;
643
- };
644
- export type SocketInternalInterface = {
645
- [functionName: string]: {
646
- [getCallObj]: (...args: any[]) => FullCallType;
647
- (...args: any[]): Promise<unknown>;
2626
+ }
2627
+
2628
+ declare module "socket-function/src/profiling/getOwnTime" {
2629
+ export type OwnTimeObj = {
2630
+ name: string;
2631
+ time: number;
2632
+ ownTime: number;
648
2633
  };
649
- };
650
- export type SocketExposedInterfaceClass = {
651
- new (): unknown;
652
- prototype: unknown;
653
- };
654
- export type FunctionFlags = {
655
- compress?: boolean;
656
- /** Indicates with the same input, we give the same output, forever,
657
- * independent of code changes. This only works for data storage.
2634
+ export type OwnTimeObjInternal = OwnTimeObj & {
2635
+ lastStartTime: number;
2636
+ firstStartTime: number;
2637
+ };
2638
+ export declare function getOpenTimesBase(): OwnTimeObjInternal[];
2639
+ export declare const measureOverheadTime: number;
2640
+ export declare function getOwnTime<T>(name: string, code: () => T, onTime: (obj: OwnTimeObj) => void): T;
2641
+
2642
+ }
2643
+
2644
+ declare module "socket-function/src/profiling/measure" {
2645
+ import { StatsValue } from "./stats";
2646
+ /** NOTE: Must be called BEFORE anything else is imported!
2647
+ * NOTE: Measurements on on by default now, so this doesn't really need to be called...
2648
+ */
2649
+ export declare function enableMeasurements(): void;
2650
+ /** NOTE: Must be called BEFORE anything else is imported! */
2651
+ export declare function disableMeasurements(): void;
2652
+ export declare function measureFnc(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
2653
+ export declare function nameFunction<T extends Function>(name: string, fnc: T): T;
2654
+ export declare function measureWrap<T extends (...args: any[]) => any>(fnc: T, name?: string): T;
2655
+ export declare function measureBlock<T extends (...args: any[]) => any>(fnc: T, name?: string): ReturnType<T>;
2656
+ /** NOTE: You should often call registerNodeMetadata for this as well. registerMeasureInfo
2657
+ * is for logs, while registerNodeMetadata is for the overview page.
658
2658
  */
659
- dataImmutable?: boolean;
660
- /** Allows overriding SocketFunction.MAX_MESSAGE_SIZE for responses from this function. */
661
- responseLimit?: number;
662
- };
663
- export type SocketExposedShape<ExposedType extends SocketExposedInterface = SocketExposedInterface> = {
664
- [functionName in keyof ExposedType]?: FunctionFlags & {
665
- hooks?: SocketFunctionHook[];
666
- clientHooks?: SocketFunctionClientHook[];
667
- noDefaultHooks?: boolean;
668
- /** BUG: I think this is broken if it is on the default hooks function? */
669
- noClientHooks?: boolean;
2659
+ export declare function registerMeasureInfo(getInfo: () => string | undefined): void;
2660
+ /** IMPORTANT! Always finish the profile! If you don't, you will leak A LOT of memory
2661
+ * (you leak all future measures, PER unfinished profile)!
2662
+ */
2663
+ export declare function startMeasure(): {
2664
+ finish: () => MeasureProfile;
670
2665
  };
671
- };
672
- export type FncType = (...args: any[]) => Promise<unknown>;
673
- export interface CallType<FncT extends FncType = FncType, FncName extends string = string> {
674
- classGuid: string;
675
- functionName: FncName;
676
- args: unknown[];
2666
+ export interface LogMeasureTableConfig {
2667
+ useTotalTime?: boolean;
2668
+ name?: string;
2669
+ setTitle?: boolean;
2670
+ thresholdInTable?: number;
2671
+ minTimeToLog?: number;
2672
+ mergeDepth?: number;
2673
+ maxTableEntries?: number;
2674
+ returnOnly?: boolean;
2675
+ }
2676
+ export interface FormattedMeasureTable {
2677
+ title: string;
2678
+ entries: {
2679
+ name: string;
2680
+ ownTime: number;
2681
+ fraction: number;
2682
+ equation: string;
2683
+ }[];
2684
+ }
2685
+ export declare function logMeasureTable(profile: MeasureProfile, config?: LogMeasureTableConfig): FormattedMeasureTable | undefined;
2686
+ export declare function measureCode<T>(code: () => Promise<T>, config?: LogMeasureTableConfig): Promise<T>;
2687
+ export declare function measureCodeSync<T>(code: () => T, config?: LogMeasureTableConfig): T;
2688
+ export interface MeasureProfile {
2689
+ startTime: number;
2690
+ endTime: number;
2691
+ entries: {
2692
+ [name: string]: ProfileEntry;
2693
+ };
2694
+ }
2695
+ export declare function createMeasureProfile(): MeasureProfile;
2696
+ export declare function addToMeasureProfile(base: MeasureProfile, other: MeasureProfile): void;
2697
+ interface ProfileEntry {
2698
+ name: string;
2699
+ ownTime: StatsValue;
2700
+ totalTime: StatsValue;
2701
+ stillOpenCount: number;
2702
+ }
2703
+ export {};
2704
+
677
2705
  }
678
- export interface FullCallType<FncT extends FncType = FncType, FncName extends string = string> extends CallType<FncT, FncName> {
679
- nodeId: string;
2706
+
2707
+ declare module "socket-function/src/profiling/stats" {
2708
+ export interface StatsValue {
2709
+ count: number;
2710
+ sum: number;
2711
+ sumSquares: number;
2712
+ logn7Value: number;
2713
+ logn7Count: number;
2714
+ logn6Value: number;
2715
+ logn6Count: number;
2716
+ logn5Value: number;
2717
+ logn5Count: number;
2718
+ logn4Value: number;
2719
+ logn4Count: number;
2720
+ logn3Value: number;
2721
+ logn3Count: number;
2722
+ logn2Value: number;
2723
+ logn2Count: number;
2724
+ logn1Value: number;
2725
+ logn1Count: number;
2726
+ log0Value: number;
2727
+ log0VCount: number;
2728
+ log1Value: number;
2729
+ log1VCount: number;
2730
+ log2Value: number;
2731
+ log2VCount: number;
2732
+ log3Value: number;
2733
+ log3VCount: number;
2734
+ log4Value: number;
2735
+ log4VCount: number;
2736
+ log5Value: number;
2737
+ log5VCount: number;
2738
+ log6Value: number;
2739
+ log6VCount: number;
2740
+ log7Value: number;
2741
+ log7VCount: number;
2742
+ log8Value: number;
2743
+ log8VCount: number;
2744
+ log9Value: number;
2745
+ log9VCount: number;
2746
+ }
2747
+ export declare function createStatsValue(): StatsValue;
2748
+ export declare function addToStatsValue(stats: StatsValue, value: number): void;
2749
+ export declare function addToStats(stats: StatsValue, other: StatsValue): void;
2750
+ export interface StatsTop {
2751
+ countFraction: number;
2752
+ valueFraction: number;
2753
+ count: number;
2754
+ value: number;
2755
+ topHeavy: boolean;
2756
+ }
2757
+ /** Identifies cases where the value is concentrated in few instances. This indicates most of the value (time)
2758
+ * is not spent on the common case, but on an outlier. Which isn't a problem, it just means that the measurements
2759
+ * should be more precise, to pull that heavy case out.
2760
+ */
2761
+ export declare function getStatsTop(stats: StatsValue): StatsTop;
2762
+
680
2763
  }
681
- export interface SocketFunctionHook {
682
- (config: HookContext): MaybePromise<void>;
683
- /** NOTE: This is useful when we need a clientside hook to set up state specifically for our serverside hook. */
684
- clientHook?: SocketFunctionClientHook;
2764
+
2765
+ declare module "socket-function/src/profiling/statsFormat" {
2766
+ import { StatsValue } from "./stats";
2767
+ export declare function percent(value: number): string;
2768
+ export declare function formatStats(stats: StatsValue, config?: {
2769
+ noColor?: boolean;
2770
+ noSum?: boolean;
2771
+ noSpaces?: boolean;
2772
+ }): string;
2773
+
685
2774
  }
686
- export type HookContext = {
687
- call: FullCallType;
688
- overrideResult?: unknown;
689
- onResult: ((result: unknown) => MaybePromise<void>)[];
690
- };
691
- export type ClientHookContext = {
692
- call: FullCallType;
693
- overrideResult?: unknown;
694
- onResult: ((result: unknown) => MaybePromise<void>)[];
695
- connectionId: {
696
- nodeId: string;
697
- };
698
- };
699
- export interface SocketFunctionClientHook {
700
- (config: ClientHookContext): MaybePromise<void>;
2775
+
2776
+ declare module "socket-function/src/profiling/tcpLagProxy" {
2777
+ export declare function tcpLagProxy(config: {
2778
+ localPort: number;
2779
+ remoteHost: string;
2780
+ remotePort: number;
2781
+ lag: number;
2782
+ networkWriteSize?: {
2783
+ value: number;
2784
+ };
2785
+ networkReadSize?: {
2786
+ value: number;
2787
+ };
2788
+ networkWritePackets?: {
2789
+ value: number;
2790
+ };
2791
+ networkReadPackets?: {
2792
+ value: number;
2793
+ };
2794
+ }): Promise<void>;
2795
+
701
2796
  }
702
- export interface SocketRegisterType<ExposedType = any> {
703
- _classGuid: string;
704
- _internalType: ExposedType;
2797
+
2798
+ declare module "socket-function/src/promiseRace" {
2799
+ export declare class PromiseLessLeaky<T> extends Promise<T> {
2800
+ constructor(executor: ((resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) | undefined);
2801
+ }
2802
+ /** A promise race function which doesn't leak, unlike Promise.race
2803
+
2804
+ See https://github.com/nodejs/node/issues/17469
2805
+ See https://bugs.chromium.org/p/v8/issues/detail?id=9858#c9
2806
+
2807
+ */
2808
+ export declare function promiseRace<T extends readonly unknown[] | []>(promises: T): Promise<Awaited<T[number]>>;
2809
+
705
2810
  }
706
- export interface SocketRegistered<ExposedType = any> {
707
- nodes: {
708
- [nodeId: string]: {
709
- [functionName in keyof ExposedType]: ExposedType[functionName] & {
710
- [getCallObj]: (...args: Args<ExposedType[functionName]>) => FullCallType;
711
- };
712
- };
713
- };
714
- _classGuid: string;
715
- _internalType: ExposedType;
2811
+
2812
+ declare module "socket-function/src/runPromise" {
2813
+ export declare const runAsync: typeof runPromise;
2814
+ export declare function runPromise(command: string, config?: {
2815
+ cwd?: string;
2816
+ quiet?: boolean;
2817
+ nothrow?: boolean;
2818
+ detach?: boolean;
2819
+ }): Promise<string>;
2820
+
716
2821
  }
717
- export type ControllerPick<T extends SocketRegistered, K extends keyof T["_internalType"]> = (SocketRegistered<Pick<T["_internalType"], K>>);
718
- export type CallerContext = Readonly<CallerContextBase>;
719
- export type CallerContextBase = {
720
- nodeId: string;
721
- localNodeId: string;
722
- };
723
2822
 
724
- }
2823
+ declare module "socket-function/src/sniTest" {
2824
+ export {};
725
2825
 
726
- declare module "socket-function/hot/HotReloadController" {
727
- /// <reference path="../../typenode/index.d.ts" />
728
- /// <reference path="../require/RequireController.d.ts" />
729
- /** Enables some hot reload functionality.
730
- * - Triggers a refresh clientside
731
- * - Triggers a reload server, for modules marked with `module.hotreload`
732
- */
733
- export declare function watchFilesAndTriggerHotReloading(noAutomaticBrowserWatch?: boolean): void;
734
- declare global {
735
- namespace NodeJS {
736
- interface Module {
737
- /** Causes us to hotreload the file. Applies both serverside and clientside.
738
- * - If not set for any files clientside, we will refresh.
739
- * - If not set for any files serverside, we will do nothing (and just leave old code running).
740
- */
741
- hotreload?: boolean;
742
- /** Overrides hotreload to disable hot reloading. Useful if you add "hotreload.flag" to a directory
743
- * (which sets hotreload on all files in and under that directory), but want a specific file
744
- * to not hotreload.
745
- * - Also useful if you want files to hotreload clientside, but not serverside.
746
- */
747
- noserverhotreload?: boolean;
748
- watchAdditionalFiles?: string[];
749
- }
750
- }
751
- var isHotReloading: (() => boolean) | undefined;
752
2826
  }
753
- export declare function isHotReloading(): boolean;
754
- export declare function hotReloadingGuard(): true;
755
- export declare function setExternalHotReloading(value: boolean): void;
756
- export declare function onHotReload(callback: (modules: NodeJS.Module[]) => void): void;
757
- export declare const HotReloadController: import("../SocketFunctionTypes").SocketRegistered<{
758
- watchFiles: () => Promise<void>;
759
- fileUpdated: (files: string[], changeTime: number) => Promise<void>;
760
- }>;
761
2827
 
762
- }
2828
+ declare module "socket-function/src/storagePath" {
2829
+ export declare const getAppFolder: {
2830
+ (): string;
2831
+ reset(): void;
2832
+ set(newValue: string): void;
2833
+ };
763
2834
 
764
- declare module "socket-function/index" {
765
- /// <reference path="./node_modules/typenode/index.d.ts" />
2835
+ }
766
2836
 
767
- export { };
2837
+ declare module "socket-function/src/tlsParsing" {
2838
+ /// <reference types="node" />
2839
+ /// <reference types="node" />
2840
+ export declare function parseTLSHello(buffer: Buffer): {
2841
+ extensions: {
2842
+ type: number;
2843
+ data: Buffer;
2844
+ }[];
2845
+ missingBytes: number;
2846
+ };
2847
+ export declare const SNIType = 0;
2848
+ export declare function parseSNIExtension(data: Buffer): string[];
768
2849
 
769
- declare global {
770
- namespace NodeJS {
771
- interface Module {
772
- original?: SerializedModule;
773
- }
774
- }
775
- interface SerializedModule {
776
- originalId: string;
777
- filename: string;
778
- // If a module is not allowed clientside it is likely requests will be empty,
779
- // to save effort parsing requests for modules that only exist to give better
780
- // error messages.
781
- requests: {
782
- // request => resolvedPath
783
- [request: string]: string;
2850
+ }
2851
+
2852
+ declare module "socket-function/src/types" {
2853
+ export type MaybePromise<T> = T | Promise<T>;
2854
+ export type Args<T> = T extends (...args: infer V) => any ? V : never;
2855
+ export type AnyFunction = (...args: any) => any;
2856
+ export declare function canHaveChildren(value: unknown): value is {
2857
+ [key in PropertyKey]: unknown;
2858
+ };
2859
+
2860
+ }
2861
+
2862
+ declare module "socket-function/src/webSocketServer" {
2863
+ /// <reference types="node" />
2864
+ /// <reference types="node" />
2865
+ /// <reference types="node" />
2866
+ import https from "https";
2867
+ import { Watchable } from "./misc";
2868
+ export type SocketServerConfig = (https.ServerOptions & {
2869
+ key: string | Buffer;
2870
+ cert: string | Buffer;
2871
+ port: number;
2872
+ /** You can also set `port: 0` if you don't care what port you want at all. */
2873
+ useAvailablePortIfPortInUse?: boolean;
2874
+ public?: boolean;
2875
+ /** Tries forwarding ports (using UPnP), if we detect they aren't externally reachable.
2876
+ * - This causes an extra request and delay during startup, so should only be used
2877
+ * during development.
2878
+ * - Ignored if public is false (in which case we mount on 127.0.0.1, so port forwarding
2879
+ * wouldn't matter anyways).
2880
+ */
2881
+ autoForwardPort?: boolean;
2882
+ ip?: string;
2883
+ allowHostnames?: string[];
2884
+ allowHostnameFnc?: (hostname: string) => boolean;
2885
+ /** If the SNI matches this domain, we use a different key/cert.
2886
+ * We remove subdomains until we find a match
2887
+ */
2888
+ SNICerts?: {
2889
+ [domain: string]: Watchable<https.ServerOptions>;
784
2890
  };
785
- asyncRequests: { [request: string]: true };
786
- // NOTE: IF !allowclient && !serveronly, it might just mean we didn't add allowclient
787
- // to the module yet. BUT, if serveronly, then we know for sure we don't want it client.
788
- // So the messages and behavior will be different.
789
- allowclient?: boolean;
790
- serveronly?: boolean;
791
- // Just for errors mostly
792
- alwayssend?: boolean;
2891
+ });
2892
+ export declare function startSocketServer(config: SocketServerConfig): Promise<string>;
793
2893
 
794
- /** Only set if allowclient. */
795
- source?: string;
2894
+ }
796
2895
 
797
- seqNum: number;
2896
+ declare module "socket-function/src/websocketFactory" {
2897
+ /// <reference types="node" />
2898
+ import tls from "tls";
2899
+ import { SenderInterface } from "./CallFactory";
2900
+ import type * as ws from "ws";
2901
+ export declare function getTLSSocket(webSocket: ws.WebSocket): tls.TLSSocket;
2902
+ /** NOTE: We create a factory, which embeds the key/cert information. Otherwise retries might use
2903
+ * a different key/cert context.
2904
+ */
2905
+ export declare function createWebsocketFactory(): (nodeId: string) => SenderInterface;
798
2906
 
799
- size?: number;
800
- version?: number;
2907
+ }
801
2908
 
802
- flags?: {
803
- [flag: string]: true;
804
- };
805
- }
2909
+ declare module "socket-function/test" {
2910
+ export {};
806
2911
 
807
2912
  }
2913
+
2914
+ declare module "socket-function/time/trueTimeShim" {
2915
+ export declare function getTrueTime(): number;
2916
+ export declare function getTrueTimeOffset(): number;
2917
+ export declare function waitForFirstTimeSync(): Promise<void> | undefined;
2918
+ export declare function shimDateNow(): void;
2919
+ export declare function getBrowserTime(): number;
2920
+ export declare function setGetTimeOffsetBase(base: () => Promise<number>): void;
2921
+
2922
+ }
2923
+
808
2924
  }
809
2925
 
810
2926
  declare module "socket-function/mobx/UrlParam" {
@@ -2730,7 +4846,7 @@ declare module "socket-function/index" {
2730
4846
  }
2731
4847
 
2732
4848
  declare module "socket-function/require/require" {
2733
- /// <reference path="../index.d.ts" />
4849
+ /// <reference path="../src/src.d.ts" />
2734
4850
  declare global {
2735
4851
  var onProgressHandler: undefined | ((progress: {
2736
4852
  type: string;
@@ -3472,6 +5588,52 @@ declare module "socket-function/index" {
3472
5588
 
3473
5589
  }
3474
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
+
3475
5637
  declare module "socket-function/src/storagePath" {
3476
5638
  export declare const getAppFolder: {
3477
5639
  (): string;
@@ -3651,7 +5813,7 @@ declare module "socket-function/require/extMapper" {
3651
5813
  }
3652
5814
 
3653
5815
  declare module "socket-function/require/require" {
3654
- /// <reference path="../index.d.ts" />
5816
+ /// <reference path="../src/src.d.ts" />
3655
5817
  declare global {
3656
5818
  var onProgressHandler: undefined | ((progress: {
3657
5819
  type: string;
@@ -4393,6 +6555,52 @@ declare module "socket-function/src/sniTest" {
4393
6555
 
4394
6556
  }
4395
6557
 
6558
+ declare module "socket-function/src/src" {
6559
+ /// <reference path="./node_modules/typenode/index.d.ts" />
6560
+
6561
+ export { };
6562
+
6563
+ declare global {
6564
+ namespace NodeJS {
6565
+ interface Module {
6566
+ original?: SerializedModule;
6567
+ }
6568
+ }
6569
+ interface SerializedModule {
6570
+ originalId: string;
6571
+ filename: string;
6572
+ // If a module is not allowed clientside it is likely requests will be empty,
6573
+ // to save effort parsing requests for modules that only exist to give better
6574
+ // error messages.
6575
+ requests: {
6576
+ // request => resolvedPath
6577
+ [request: string]: string;
6578
+ };
6579
+ asyncRequests: { [request: string]: true };
6580
+ // NOTE: IF !allowclient && !serveronly, it might just mean we didn't add allowclient
6581
+ // to the module yet. BUT, if serveronly, then we know for sure we don't want it client.
6582
+ // So the messages and behavior will be different.
6583
+ allowclient?: boolean;
6584
+ serveronly?: boolean;
6585
+ // Just for errors mostly
6586
+ alwayssend?: boolean;
6587
+
6588
+ /** Only set if allowclient. */
6589
+ source?: string;
6590
+
6591
+ seqNum: number;
6592
+
6593
+ size?: number;
6594
+ version?: number;
6595
+
6596
+ flags?: {
6597
+ [flag: string]: true;
6598
+ };
6599
+ }
6600
+
6601
+ }
6602
+ }
6603
+
4396
6604
  declare module "socket-function/src/storagePath" {
4397
6605
  export declare const getAppFolder: {
4398
6606
  (): string;