socket-function 0.8.17 → 0.8.19

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.
@@ -3,7 +3,7 @@ module.allowclient = true;
3
3
  import debugbreak from "debugbreak";
4
4
  import * as tls from "tls";
5
5
  import { getCallObj } from "./src/nodeProxy";
6
- import { Args } from "./src/types";
6
+ import { Args, MaybePromise } from "./src/types";
7
7
 
8
8
  export const socket = Symbol("socket");
9
9
 
@@ -45,7 +45,7 @@ export interface FullCallType extends CallType {
45
45
  }
46
46
 
47
47
  export interface SocketFunctionHook<ExposedType extends SocketExposedInterface = SocketExposedInterface, CallContext extends CallContextType = CallContextType> {
48
- (config: HookContext<ExposedType, CallContext>): Promise<void>;
48
+ (config: HookContext<ExposedType, CallContext>): MaybePromise<void>;
49
49
  }
50
50
  export type HookContext<ExposedType extends SocketExposedInterface = SocketExposedInterface, CallContext extends CallContextType = CallContextType> = {
51
51
  call: CallType;
@@ -60,7 +60,7 @@ export type ClientHookContext<ExposedType extends SocketExposedInterface = Socke
60
60
  overrideResult?: unknown;
61
61
  };
62
62
  export interface SocketFunctionClientHook<ExposedType extends SocketExposedInterface = SocketExposedInterface, CallContext extends CallContextType = CallContextType> {
63
- (config: ClientHookContext<ExposedType, CallContext>): Promise<void>;
63
+ (config: ClientHookContext<ExposedType, CallContext>): MaybePromise<void>;
64
64
  }
65
65
 
66
66
  export type CallContextType = {
@@ -34,9 +34,9 @@ export function promiseToObservable<T>(promise: Promise<T>): { value: T | undefi
34
34
  };
35
35
  }
36
36
 
37
- export function asyncObservable<Output, Key>(maxCount: number, getValue: (key: Key) => Promise<Output>): {
38
- (key: Key): Output | undefined;
39
- invalidate(key: Key): void;
37
+ export function asyncObservable<Output, Args extends any[]>(maxCount: number, getValue: (...args: Args) => Promise<Output>): {
38
+ (...args: Args): Output | undefined;
39
+ invalidate(...args: Args): void;
40
40
  invalidateAll(): void;
41
41
  } {
42
42
  let invalidateAllSeqNum = observable({ seqNum: 1 }, undefined, { deep: false, proxy: false });
@@ -46,8 +46,8 @@ export function asyncObservable<Output, Key>(maxCount: number, getValue: (key: K
46
46
  seqNum: { value: number };
47
47
  }>();
48
48
 
49
- get["invalidate"] = (key: Key) => {
50
- let hash = JSON.stringify(key);
49
+ get["invalidate"] = (...args: Args) => {
50
+ let hash = JSON.stringify(args);
51
51
  let value = values.get(hash);
52
52
  if (!value) return;
53
53
  values.delete(hash);
@@ -59,9 +59,9 @@ export function asyncObservable<Output, Key>(maxCount: number, getValue: (key: K
59
59
  values.clear();
60
60
  invalidateAllSeqNum.seqNum++;
61
61
  };
62
- function get(key: Key) {
62
+ function get(...args: Args) {
63
63
 
64
- let hash = JSON.stringify(key);
64
+ let hash = JSON.stringify(args);
65
65
  let value = values.get(hash);
66
66
  if (!value) {
67
67
 
@@ -79,7 +79,7 @@ export function asyncObservable<Output, Key>(maxCount: number, getValue: (key: K
79
79
  }
80
80
 
81
81
  // We call inside another function so that synchronous errors still get wrapped in the observable
82
- let valueObs = promiseToObservable((async () => getValue(key))());
82
+ let valueObs = promiseToObservable((async () => getValue(...args))());
83
83
  value = {
84
84
  valueObs,
85
85
  seqNum: observable({ value: 1 }, undefined, { deep: false, proxy: false }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.8.17",
3
+ "version": "0.8.19",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {