socket-function 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generateIndexDts.js +1 -1
- package/index.d.ts +108 -0
- package/package.json +1 -1
- package/require/RequireController.ts +1 -1
package/generateIndexDts.js
CHANGED
|
@@ -24,7 +24,7 @@ function generateIndexDts() {
|
|
|
24
24
|
const renderUtilsPath = __dirname;
|
|
25
25
|
const dtsFiles = getAllDtsFiles(renderUtilsPath);
|
|
26
26
|
|
|
27
|
-
const excludedModules = ["socket-function/
|
|
27
|
+
const excludedModules = ["socket-function/index"];
|
|
28
28
|
|
|
29
29
|
const modules = dtsFiles
|
|
30
30
|
.map(filePath => {
|
package/index.d.ts
CHANGED
|
@@ -6,6 +6,114 @@ declare module "socket-function/SetProcessVariables" {
|
|
|
6
6
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
declare module "socket-function/SocketFunction" {
|
|
10
|
+
/// <reference path="require/RequireController.d.ts" />
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
/// <reference types="node" />
|
|
13
|
+
import { SocketExposedInterface, SocketFunctionHook, SocketFunctionClientHook, SocketExposedShape, SocketRegistered, CallerContext, FullCallType, SocketRegisterType } from "socket-function/SocketFunctionTypes";
|
|
14
|
+
import { SocketServerConfig } from "socket-function/src/webSocketServer";
|
|
15
|
+
import { Args, MaybePromise } from "socket-function/src/types";
|
|
16
|
+
import "./SetProcessVariables";
|
|
17
|
+
type ExtractShape<ClassType, Shape> = {
|
|
18
|
+
[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");
|
|
19
|
+
};
|
|
20
|
+
export declare class SocketFunction {
|
|
21
|
+
static logMessages: boolean;
|
|
22
|
+
static trackMessageSizes: {
|
|
23
|
+
upload: ((size: number) => void)[];
|
|
24
|
+
download: ((size: number) => void)[];
|
|
25
|
+
callTimes: ((obj: {
|
|
26
|
+
start: number;
|
|
27
|
+
end: number;
|
|
28
|
+
}) => void)[];
|
|
29
|
+
};
|
|
30
|
+
static MAX_MESSAGE_SIZE: number;
|
|
31
|
+
static HTTP_ETAG_CACHE: boolean;
|
|
32
|
+
static silent: boolean;
|
|
33
|
+
static HTTP_COMPRESS: boolean;
|
|
34
|
+
static COEP: string;
|
|
35
|
+
static COOP: string;
|
|
36
|
+
static readonly WIRE_SERIALIZER: {
|
|
37
|
+
serialize: (obj: unknown) => MaybePromise<Buffer[]>;
|
|
38
|
+
deserialize: (buffers: Buffer[]) => MaybePromise<unknown>;
|
|
39
|
+
};
|
|
40
|
+
static WIRE_WARN_TIME: number;
|
|
41
|
+
private static onMountCallbacks;
|
|
42
|
+
static exposedClasses: Set<string>;
|
|
43
|
+
static callerContext: CallerContext | undefined;
|
|
44
|
+
static getCaller(): CallerContext;
|
|
45
|
+
static harvestFailedCallCount: () => number;
|
|
46
|
+
static getPendingCallCount: () => number;
|
|
47
|
+
static harvestCallTimes: () => {
|
|
48
|
+
start: number;
|
|
49
|
+
end: number;
|
|
50
|
+
}[];
|
|
51
|
+
static register<ClassInstance extends object, Shape extends SocketExposedShape<{
|
|
52
|
+
[key in keyof ClassInstance]: (...args: any[]) => Promise<unknown>;
|
|
53
|
+
}>, Statics>(classGuid: string, instance: ClassInstance | (() => ClassInstance), shapeFnc: () => Shape, defaultHooksFnc?: () => SocketExposedShape[""] & {
|
|
54
|
+
onMount?: () => MaybePromise<void>;
|
|
55
|
+
}, config?: {
|
|
56
|
+
/** @noAutoExpose If true SocketFunction.expose(Controller) must be called explicitly. */
|
|
57
|
+
noAutoExpose?: boolean;
|
|
58
|
+
statics?: Statics;
|
|
59
|
+
/** Skip timing functions calls. Useful if a lot of functions have wait time that
|
|
60
|
+
is unrelated to processing, and therefore their timings won't be useful.
|
|
61
|
+
- Also useful if our auto function wrapping code is breaking functionality,
|
|
62
|
+
such as if you have a singleton function which you compare with ===,
|
|
63
|
+
which will breaks because we replaced it with a wrapped measure function.
|
|
64
|
+
*/
|
|
65
|
+
noFunctionMeasure?: boolean;
|
|
66
|
+
}): SocketRegistered<ExtractShape<ClassInstance, Shape>> & Statics;
|
|
67
|
+
private static socketCache;
|
|
68
|
+
static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
|
|
69
|
+
private static callFromGuid;
|
|
70
|
+
static onNextDisconnect(nodeId: string, callback: () => void): void;
|
|
71
|
+
static getLastDisconnectTime(nodeId: string): number | undefined;
|
|
72
|
+
static isNodeConnected(nodeId: string): boolean;
|
|
73
|
+
/** NOTE: Only works if the nodeIs used is from SocketFunction.connect (we can't convert arbitrary nodeIds into urls,
|
|
74
|
+
* as we have no way of knowing how to contain a nodeId).
|
|
75
|
+
* */
|
|
76
|
+
static getHTTPCallLink(call: FullCallType): string;
|
|
77
|
+
private static ignoreExposeCount;
|
|
78
|
+
static ignoreExposeCalls<T>(code: () => Promise<T>): Promise<T>;
|
|
79
|
+
/** Expose should be called before your mounting occurs. It mostly just exists to ensure you include the class type,
|
|
80
|
+
* so the class type's module construction runs, which should trigger register. Otherwise you would have
|
|
81
|
+
* to add additional imports to ensure the register call runs.
|
|
82
|
+
*/
|
|
83
|
+
static expose(socketRegistered: SocketRegistered): void;
|
|
84
|
+
static mountedNodeId: string;
|
|
85
|
+
static isMounted(): boolean;
|
|
86
|
+
static mountedIP: string;
|
|
87
|
+
private static hasMounted;
|
|
88
|
+
private static onMountCallback;
|
|
89
|
+
static mountPromise: Promise<void>;
|
|
90
|
+
static mount(config: SocketServerConfig): Promise<string>;
|
|
91
|
+
/** Sets the default call when an http request is made, but no classGuid is set.
|
|
92
|
+
* NOTE: All other calls should be endpoint calls, even if those endpoints return a static file with an HTML content type.
|
|
93
|
+
* - However, to load new content, you should probably just use `require("./example.ts")`, which works on any files
|
|
94
|
+
* clientside that have also been required serverside (and whitelisted with module.allowclient = true,
|
|
95
|
+
* or with an `allowclient.flag` file in the directory or parent directory).
|
|
96
|
+
*/
|
|
97
|
+
static setDefaultHTTPCall<Registered extends SocketRegistered, FunctionName extends keyof Registered["nodes"][""] & string>(registered: Registered, functionName: FunctionName, ...args: Args<Registered["nodes"][""][FunctionName]>): void;
|
|
98
|
+
static connect(location: {
|
|
99
|
+
address: string;
|
|
100
|
+
port: number;
|
|
101
|
+
}): string;
|
|
102
|
+
static browserNodeId(): string;
|
|
103
|
+
static getBrowserNodeId(): string;
|
|
104
|
+
static addGlobalHook(hook: SocketFunctionHook): void;
|
|
105
|
+
static addGlobalClientHook(hook: SocketFunctionClientHook): void;
|
|
106
|
+
}
|
|
107
|
+
declare global {
|
|
108
|
+
var BOOTED_EDGE_NODE: {
|
|
109
|
+
host: string;
|
|
110
|
+
} | undefined;
|
|
111
|
+
}
|
|
112
|
+
export declare function _setSocketContext<T>(caller: CallerContext, code: () => T): T;
|
|
113
|
+
export {};
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
9
117
|
declare module "socket-function/SocketFunctionTypes" {
|
|
10
118
|
/// <reference path="require/RequireController.d.ts" />
|
|
11
119
|
import { getCallObj } from "socket-function/src/nodeProxy";
|
package/package.json
CHANGED
|
@@ -126,7 +126,7 @@ class RequireControllerBase {
|
|
|
126
126
|
}
|
|
127
127
|
if (httpRequest) {
|
|
128
128
|
let urlObj = new URL("https://" + httpRequest.headers.host + httpRequest.url);
|
|
129
|
-
if (urlObj.pathname !== "/" &&
|
|
129
|
+
if (urlObj.pathname !== "/" && staticRoots.length > 0) {
|
|
130
130
|
if (urlObj.pathname.includes("..")) {
|
|
131
131
|
throw new Error(`Invalid path, may not have ".." in the path, ${urlObj.pathname}`);
|
|
132
132
|
}
|