socket-function 1.0.0 → 1.0.2

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.
@@ -24,20 +24,27 @@ function generateIndexDts() {
24
24
  const renderUtilsPath = __dirname;
25
25
  const dtsFiles = getAllDtsFiles(renderUtilsPath);
26
26
 
27
+ const excludedModules = ["socket-function/SocketFunction", "socket-function/index"];
28
+
27
29
  const modules = dtsFiles
28
- .filter(filePath => {
29
- // Exclude SocketFunction.d.ts and index.d.ts from being wrapped in a module declaration
30
- const relativePath = path.relative(renderUtilsPath, filePath);
31
- const withoutExt = relativePath.replace(/\.d\.ts$/, "");
32
- const modulePath = "socket-function/" + withoutExt.replace(/\\/g, "/");
33
- return modulePath !== "socket-function/SocketFunction" && modulePath !== "socket-function/index";
34
- })
35
30
  .map(filePath => {
36
31
  const relativePath = path.relative(renderUtilsPath, filePath);
37
32
  const withoutExt = relativePath.replace(/\.d\.ts$/, "");
38
33
  const modulePath = "socket-function/" + withoutExt.replace(/\\/g, "/");
34
+ if (excludedModules.includes(modulePath)) return undefined;
35
+
36
+ let content = fs.readFileSync(filePath, "utf8");
37
+
38
+ // Resolve relative imports to absolute module paths
39
+ const moduleDir = path.dirname(modulePath);
40
+ content = content.replace(
41
+ /(import|export)\s+([^"']*)\s+from\s+["'](\.[^"']+)["']/g,
42
+ (match, keyword, imported, relativeImport) => {
43
+ const absoluteModulePath = path.join(moduleDir, relativeImport).replace(/\\/g, "/");
44
+ return `${keyword} ${imported} from "${absoluteModulePath}"`;
45
+ }
46
+ );
39
47
 
40
- const content = fs.readFileSync(filePath, "utf8");
41
48
  const indentedContent = content
42
49
  .split("\n")
43
50
  .map(line => line ? " " + line : line)
@@ -45,6 +52,7 @@ function generateIndexDts() {
45
52
 
46
53
  return `declare module "${modulePath}" {\n${indentedContent}\n}`;
47
54
  })
55
+ .filter(x => x)
48
56
  .sort()
49
57
  .join("\n\n");
50
58
 
package/index.d.ts CHANGED
@@ -8,8 +8,8 @@ declare module "socket-function/SetProcessVariables" {
8
8
 
9
9
  declare module "socket-function/SocketFunctionTypes" {
10
10
  /// <reference path="require/RequireController.d.ts" />
11
- import { getCallObj } from "./src/nodeProxy";
12
- import { Args, MaybePromise } from "./src/types";
11
+ import { getCallObj } from "socket-function/src/nodeProxy";
12
+ import { Args, MaybePromise } from "socket-function/src/types";
13
13
  export declare const socket: unique symbol;
14
14
  export type SocketExposedInterface = {
15
15
  [functionName: string]: (...args: any[]) => Promise<unknown>;
@@ -191,6 +191,116 @@ declare module "socket-function/require/CSSShim" {
191
191
 
192
192
  }
193
193
 
194
+ declare module "socket-function/require/RequireController" {
195
+ /// <reference path="../../typenode/index.d.ts" />
196
+ /// <reference types="node" />
197
+ declare global {
198
+ namespace NodeJS {
199
+ interface Module {
200
+ /** Indicates the module is allowed clientside.
201
+ * NOTE: Set with `module.allowclient = true`. HOWEVER, access via getIsAllowClient, which will check
202
+ */
203
+ allowclient?: boolean;
204
+ /** Causes the module to not preload, requiring `await import()` for it to load correctly
205
+ * - Shouldn't be set recursively, otherwise nested packages will break.
206
+ */
207
+ lazyload?: boolean;
208
+ /** Indicates the module is definitely not allowed clientside */
209
+ serveronly?: boolean;
210
+ /** Used internally by RequireController */
211
+ requireControllerSeqNum?: number;
212
+ evalStartTime?: number;
213
+ evalEndTime?: number;
214
+ /** (Presently only called by require.js)
215
+ * Called on require calls, to allow providers to create custom exports depending on the caller.
216
+ * - Mostly used to allow functions to know the calling module.
217
+ */
218
+ remapExports?: (exports: {
219
+ [key: string]: unknown;
220
+ }, callerModule: NodeJS.Module) => {
221
+ [key: string]: unknown;
222
+ };
223
+ /** Only set if clientside (and allowed clientside) */
224
+ source?: string;
225
+ }
226
+ }
227
+ interface Window {
228
+ clientsideBootTime: number;
229
+ }
230
+ var suppressUnexpectedModuleWarning: number | undefined;
231
+ }
232
+ /** Imports it, serverside, delayed. For dynamic imports, which we need to include once, but don't want to include
233
+ * immediately (due to cyclic issues), and isn't included initially.
234
+ */
235
+ export declare function lazyImport(getModule: () => Promise<unknown>): void;
236
+ declare const requireSeqNumProcessId: string;
237
+ declare function injectHTMLBeforeStartup(text: string | (() => Promise<string>)): void;
238
+ declare function addStaticRoot(root: string): void;
239
+ type GetModulesResult = ReturnType<RequireControllerBase["getModules"]> extends Promise<infer T> ? T : never;
240
+ export type GetModulesArgs = Parameters<RequireControllerBase["getModules"]>;
241
+ declare let mapGetModules: {
242
+ remap(result: GetModulesResult, args: GetModulesArgs): Promise<GetModulesResult>;
243
+ }[];
244
+ declare function addMapGetModules(remap: typeof mapGetModules[number]["remap"]): void;
245
+ declare class RequireControllerBase {
246
+ rootResolvePath: string;
247
+ requireHTML(config?: {
248
+ requireCalls?: string[];
249
+ cacheTime?: number;
250
+ }): Promise<Buffer>;
251
+ getModules(pathRequests: string[], alreadyHave?: {
252
+ requireSeqNumProcessId: string;
253
+ seqNumRanges: {
254
+ s: number;
255
+ e?: number;
256
+ }[];
257
+ }, config?: {}): Promise<{
258
+ requestsResolvedPaths: string[];
259
+ modules: {
260
+ [resolvedPath: string]: SerializedModule;
261
+ };
262
+ requireSeqNumProcessId: string;
263
+ }>;
264
+ }
265
+ export declare function getIsAllowClient(module: NodeJS.Module): boolean | undefined;
266
+ type ClientRemapCallback = (args: GetModulesArgs) => Promise<GetModulesArgs>;
267
+ declare global {
268
+ /** Must be set clientside BEFORE requests are made (so you likely want to use RequireController.addMapGetModules
269
+ * to inject code that will use this) */
270
+ var remapImportRequestsClientside: undefined | ClientRemapCallback[];
271
+ }
272
+ /** @deprecated, not needed, as this defaults to ".", which is a lot easier to reason about anyways. */
273
+ export declare function setRequireBootRequire(dir: string): void;
274
+ export declare function allowAllNodeModules(): void;
275
+ export declare const RequireController: import("../SocketFunctionTypes").SocketRegistered<{
276
+ rootResolvePath: "Function has implementation but is not exposed in the SocketFunction.register call";
277
+ requireHTML: (config?: {
278
+ requireCalls?: string[];
279
+ cacheTime?: number;
280
+ }) => Promise<Buffer>;
281
+ getModules: (pathRequests: string[], alreadyHave?: {
282
+ requireSeqNumProcessId: string;
283
+ seqNumRanges: {
284
+ s: number;
285
+ e?: number;
286
+ }[];
287
+ }, config?: {}) => Promise<{
288
+ requestsResolvedPaths: string[];
289
+ modules: {
290
+ [resolvedPath: string]: SerializedModule;
291
+ };
292
+ requireSeqNumProcessId: string;
293
+ }>;
294
+ }> & {
295
+ injectHTMLBeforeStartup: typeof injectHTMLBeforeStartup;
296
+ addMapGetModules: typeof addMapGetModules;
297
+ addStaticRoot: typeof addStaticRoot;
298
+ allowAllNodeModules: typeof allowAllNodeModules;
299
+ };
300
+ export {};
301
+
302
+ }
303
+
194
304
  declare module "socket-function/require/compileFlags" {
195
305
  /// <reference path="RequireController.d.ts" />
196
306
  /// <reference types="node" />
@@ -234,7 +344,7 @@ declare module "socket-function/require/require" {
234
344
  declare module "socket-function/src/CallFactory" {
235
345
  /// <reference types="node" />
236
346
  /// <reference types="node" />
237
- import { CallType } from "../SocketFunctionTypes";
347
+ import { CallType } from "socket-function/SocketFunctionTypes";
238
348
  import * as ws from "ws";
239
349
  import * as tls from "tls";
240
350
  export interface CallFactory {
@@ -320,7 +430,7 @@ declare module "socket-function/src/args" {
320
430
  }
321
431
 
322
432
  declare module "socket-function/src/batching" {
323
- import { AnyFunction } from "./types";
433
+ import { AnyFunction } from "socket-function/src/types";
324
434
  export type DelayType = (number | "afterio" | "immediate" | "afterpromises" | "paintLoop" | "afterPaint");
325
435
  export declare function delay(delayTime: DelayType, immediateShortDelays?: "immediateShortDelays"): Promise<void>;
326
436
  export declare function batchFunctionNone<Arg, Result = void>(config: unknown, fnc: (arg: Arg[]) => (Promise<Result> | Result)): (arg: Arg) => Promise<Result>;
@@ -355,7 +465,7 @@ declare module "socket-function/src/batching" {
355
465
  }
356
466
 
357
467
  declare module "socket-function/src/caching" {
358
- import { AnyFunction, Args } from "./types";
468
+ import { AnyFunction, Args } from "socket-function/src/types";
359
469
  export declare function lazy<T>(factory: () => T): {
360
470
  (): T;
361
471
  reset(): void;
@@ -421,7 +531,7 @@ declare module "socket-function/src/callHTTPHandler" {
421
531
  /// <reference types="node" />
422
532
  /// <reference types="node" />
423
533
  import http from "http";
424
- import { CallType } from "../SocketFunctionTypes";
534
+ import { CallType } from "socket-function/SocketFunctionTypes";
425
535
  export declare function setDefaultHTTPCall(call: CallType): void;
426
536
  export declare function getServerLocationFromRequest(request: http.IncomingMessage): {
427
537
  address: string;
@@ -448,7 +558,7 @@ declare module "socket-function/src/callHTTPHandler" {
448
558
 
449
559
  declare module "socket-function/src/callManager" {
450
560
  /// <reference path="../hot/HotReloadController.d.ts" />
451
- import { CallerContext, CallType, ClientHookContext, FullCallType, FunctionFlags, HookContext, SocketExposedInterface, SocketExposedShape, SocketFunctionClientHook, SocketFunctionHook, SocketRegistered } from "../SocketFunctionTypes";
561
+ import { CallerContext, CallType, ClientHookContext, FullCallType, FunctionFlags, HookContext, SocketExposedInterface, SocketExposedShape, SocketFunctionClientHook, SocketFunctionHook, SocketRegistered } from "socket-function/SocketFunctionTypes";
452
562
  export declare function getCallFlags(call: CallType): FunctionFlags | undefined;
453
563
  export declare function shouldCompressCall(call: CallType): boolean;
454
564
  export declare function performLocalCall(config: {
@@ -597,7 +707,7 @@ declare module "socket-function/src/https" {
597
707
 
598
708
  declare module "socket-function/src/misc" {
599
709
  /// <reference types="node" />
600
- import { MaybePromise } from "./types";
710
+ import { MaybePromise } from "socket-function/src/types";
601
711
  export declare const timeInSecond = 1000;
602
712
  export declare const timeInMinute: number;
603
713
  export declare const timeInHour: number;
@@ -712,8 +822,8 @@ declare module "socket-function/src/networking" {
712
822
  }
713
823
 
714
824
  declare module "socket-function/src/nodeCache" {
715
- import { CallFactory } from "./CallFactory";
716
- import { MaybePromise } from "./types";
825
+ import { CallFactory } from "socket-function/src/CallFactory";
826
+ import { MaybePromise } from "socket-function/src/types";
717
827
  export declare function getNodeId(domain: string, port: number): string;
718
828
  /** @deprecated, call getBrowserUrlNode instead, which does important additional checks. */
719
829
  export declare function getNodeIdFromLocation(): string;
@@ -740,7 +850,7 @@ declare module "socket-function/src/nodeCache" {
740
850
  }
741
851
 
742
852
  declare module "socket-function/src/nodeProxy" {
743
- import { FullCallType, SocketInternalInterface } from "../SocketFunctionTypes";
853
+ import { FullCallType, SocketInternalInterface } from "socket-function/SocketFunctionTypes";
744
854
  type CallProxyType = {
745
855
  [nodeId: string]: SocketInternalInterface;
746
856
  };
@@ -767,7 +877,7 @@ declare module "socket-function/src/profiling/getOwnTime" {
767
877
  }
768
878
 
769
879
  declare module "socket-function/src/profiling/measure" {
770
- import { StatsValue } from "./stats";
880
+ import { StatsValue } from "socket-function/src/profiling/stats";
771
881
  /** NOTE: Must be called BEFORE anything else is imported!
772
882
  * NOTE: Measurements on on by default now, so this doesn't really need to be called...
773
883
  */
@@ -888,7 +998,7 @@ declare module "socket-function/src/profiling/stats" {
888
998
  }
889
999
 
890
1000
  declare module "socket-function/src/profiling/statsFormat" {
891
- import { StatsValue } from "./stats";
1001
+ import { StatsValue } from "socket-function/src/profiling/stats";
892
1002
  export declare function percent(value: number): string;
893
1003
  export declare function formatStats(stats: StatsValue, config?: {
894
1004
  noColor?: boolean;
@@ -1033,7 +1143,7 @@ declare module "socket-function/src/webSocketServer" {
1033
1143
  /// <reference types="node" />
1034
1144
  /// <reference types="node" />
1035
1145
  import https from "https";
1036
- import { Watchable } from "./misc";
1146
+ import { Watchable } from "socket-function/src/misc";
1037
1147
  export type SocketServerConfig = (https.ServerOptions & {
1038
1148
  key: string | Buffer;
1039
1149
  cert: string | Buffer;
@@ -1065,7 +1175,7 @@ declare module "socket-function/src/webSocketServer" {
1065
1175
  declare module "socket-function/src/websocketFactory" {
1066
1176
  /// <reference types="node" />
1067
1177
  import tls from "tls";
1068
- import { SenderInterface } from "./CallFactory";
1178
+ import { SenderInterface } from "socket-function/src/CallFactory";
1069
1179
  import type * as ws from "ws";
1070
1180
  export declare function getTLSSocket(webSocket: ws.WebSocket): tls.TLSSocket;
1071
1181
  /** NOTE: We create a factory, which embeds the key/cert information. Otherwise retries might use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -0,0 +1,106 @@
1
+ /// <reference path="../../typenode/index.d.ts" />
2
+ /// <reference types="node" />
3
+ declare global {
4
+ namespace NodeJS {
5
+ interface Module {
6
+ /** Indicates the module is allowed clientside.
7
+ * NOTE: Set with `module.allowclient = true`. HOWEVER, access via getIsAllowClient, which will check
8
+ */
9
+ allowclient?: boolean;
10
+ /** Causes the module to not preload, requiring `await import()` for it to load correctly
11
+ * - Shouldn't be set recursively, otherwise nested packages will break.
12
+ */
13
+ lazyload?: boolean;
14
+ /** Indicates the module is definitely not allowed clientside */
15
+ serveronly?: boolean;
16
+ /** Used internally by RequireController */
17
+ requireControllerSeqNum?: number;
18
+ evalStartTime?: number;
19
+ evalEndTime?: number;
20
+ /** (Presently only called by require.js)
21
+ * Called on require calls, to allow providers to create custom exports depending on the caller.
22
+ * - Mostly used to allow functions to know the calling module.
23
+ */
24
+ remapExports?: (exports: {
25
+ [key: string]: unknown;
26
+ }, callerModule: NodeJS.Module) => {
27
+ [key: string]: unknown;
28
+ };
29
+ /** Only set if clientside (and allowed clientside) */
30
+ source?: string;
31
+ }
32
+ }
33
+ interface Window {
34
+ clientsideBootTime: number;
35
+ }
36
+ var suppressUnexpectedModuleWarning: number | undefined;
37
+ }
38
+ /** Imports it, serverside, delayed. For dynamic imports, which we need to include once, but don't want to include
39
+ * immediately (due to cyclic issues), and isn't included initially.
40
+ */
41
+ export declare function lazyImport(getModule: () => Promise<unknown>): void;
42
+ declare const requireSeqNumProcessId: string;
43
+ declare function injectHTMLBeforeStartup(text: string | (() => Promise<string>)): void;
44
+ declare function addStaticRoot(root: string): void;
45
+ type GetModulesResult = ReturnType<RequireControllerBase["getModules"]> extends Promise<infer T> ? T : never;
46
+ export type GetModulesArgs = Parameters<RequireControllerBase["getModules"]>;
47
+ declare let mapGetModules: {
48
+ remap(result: GetModulesResult, args: GetModulesArgs): Promise<GetModulesResult>;
49
+ }[];
50
+ declare function addMapGetModules(remap: typeof mapGetModules[number]["remap"]): void;
51
+ declare class RequireControllerBase {
52
+ rootResolvePath: string;
53
+ requireHTML(config?: {
54
+ requireCalls?: string[];
55
+ cacheTime?: number;
56
+ }): Promise<Buffer>;
57
+ getModules(pathRequests: string[], alreadyHave?: {
58
+ requireSeqNumProcessId: string;
59
+ seqNumRanges: {
60
+ s: number;
61
+ e?: number;
62
+ }[];
63
+ }, config?: {}): Promise<{
64
+ requestsResolvedPaths: string[];
65
+ modules: {
66
+ [resolvedPath: string]: SerializedModule;
67
+ };
68
+ requireSeqNumProcessId: string;
69
+ }>;
70
+ }
71
+ export declare function getIsAllowClient(module: NodeJS.Module): boolean | undefined;
72
+ type ClientRemapCallback = (args: GetModulesArgs) => Promise<GetModulesArgs>;
73
+ declare global {
74
+ /** Must be set clientside BEFORE requests are made (so you likely want to use RequireController.addMapGetModules
75
+ * to inject code that will use this) */
76
+ var remapImportRequestsClientside: undefined | ClientRemapCallback[];
77
+ }
78
+ /** @deprecated, not needed, as this defaults to ".", which is a lot easier to reason about anyways. */
79
+ export declare function setRequireBootRequire(dir: string): void;
80
+ export declare function allowAllNodeModules(): void;
81
+ export declare const RequireController: import("../SocketFunctionTypes").SocketRegistered<{
82
+ rootResolvePath: "Function has implementation but is not exposed in the SocketFunction.register call";
83
+ requireHTML: (config?: {
84
+ requireCalls?: string[];
85
+ cacheTime?: number;
86
+ }) => Promise<Buffer>;
87
+ getModules: (pathRequests: string[], alreadyHave?: {
88
+ requireSeqNumProcessId: string;
89
+ seqNumRanges: {
90
+ s: number;
91
+ e?: number;
92
+ }[];
93
+ }, config?: {}) => Promise<{
94
+ requestsResolvedPaths: string[];
95
+ modules: {
96
+ [resolvedPath: string]: SerializedModule;
97
+ };
98
+ requireSeqNumProcessId: string;
99
+ }>;
100
+ }> & {
101
+ injectHTMLBeforeStartup: typeof injectHTMLBeforeStartup;
102
+ addMapGetModules: typeof addMapGetModules;
103
+ addStaticRoot: typeof addStaticRoot;
104
+ allowAllNodeModules: typeof allowAllNodeModules;
105
+ };
106
+ export {};
@@ -115,7 +115,7 @@ class RequireControllerBase {
115
115
  public async requireHTML(config?: {
116
116
  requireCalls?: string[];
117
117
  cacheTime?: number;
118
- }) {
118
+ }): Promise<Buffer> {
119
119
  let { requireCalls, cacheTime } = config || {};
120
120
  let httpRequest = getCurrentHTTPRequest();
121
121
  let headers: Record<string, string> = {