socket-function 0.129.0 → 0.131.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/SocketFunctionTypes.ts +2 -0
- package/package.json +2 -2
- package/src/batching.ts +5 -2
- package/src/caching.ts +1 -1
- package/src/callManager.ts +4 -2
- package/src/misc.ts +2 -1
- package/src/profiling/measure.ts +2 -2
- package/time/trueTimeShim.ts +2 -1
package/SocketFunctionTypes.ts
CHANGED
|
@@ -84,6 +84,8 @@ export type ClientHookContext = {
|
|
|
84
84
|
overrideResult?: unknown;
|
|
85
85
|
// Is called on a result, even if it is from overrideResult
|
|
86
86
|
onResult: ((result: unknown) => MaybePromise<void>)[];
|
|
87
|
+
// IMPORTANT! This is a unique object per connection, reused within the connection. This
|
|
88
|
+
// is allows it to be used as a cache key for connection related info (in a WeakMap).
|
|
87
89
|
connectionId: { nodeId: string };
|
|
88
90
|
};
|
|
89
91
|
export interface SocketFunctionClientHook {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "socket-function",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.131.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"cbor-x": "^1.6.0",
|
|
10
10
|
"mobx": "^6.6.2",
|
|
11
11
|
"pako": "^2.1.0",
|
|
12
|
-
"preact": "10.
|
|
12
|
+
"preact": "10.11.3",
|
|
13
13
|
"typedev": "^0.4.0",
|
|
14
14
|
"typenode": "^5.12.0",
|
|
15
15
|
"ws": "^8.17.1"
|
package/src/batching.ts
CHANGED
|
@@ -97,10 +97,13 @@ export function batchFunction<Arg, Result = void>(
|
|
|
97
97
|
*/
|
|
98
98
|
throttleWindow?: number;
|
|
99
99
|
name?: string;
|
|
100
|
+
noMeasure?: boolean;
|
|
100
101
|
},
|
|
101
102
|
fnc: (arg: Arg[]) => (Promise<Result> | Result)
|
|
102
103
|
): (arg: Arg) => Promise<Result> {
|
|
103
|
-
|
|
104
|
+
if (!config.noMeasure) {
|
|
105
|
+
fnc = measureWrap(fnc, config.name);
|
|
106
|
+
}
|
|
104
107
|
|
|
105
108
|
let prevPromise: Promise<Result> | undefined;
|
|
106
109
|
let batching: {
|
|
@@ -171,7 +174,7 @@ export function batchFunction<Arg, Result = void>(
|
|
|
171
174
|
export function runInSerial<T extends (...args: any[]) => Promise<any>>(fnc: T): T {
|
|
172
175
|
let updateQueue: { promise: Promise<void>; resolve: () => void; }[] = [];
|
|
173
176
|
|
|
174
|
-
return (async (...args: any[])
|
|
177
|
+
return (async function runInSerial(...args: any[]) {
|
|
175
178
|
let promise = {
|
|
176
179
|
promise: null as any as Promise<void>,
|
|
177
180
|
resolve: () => { },
|
package/src/caching.ts
CHANGED
|
@@ -263,7 +263,7 @@ export function cacheArgsEqual<Fnc extends AnyFunction>(
|
|
|
263
263
|
fnc: Fnc,
|
|
264
264
|
limit = 10
|
|
265
265
|
): Fnc & { clear(...args: Args<Fnc>): void } {
|
|
266
|
-
let cache = cacheArrayEqual((args: unknown[])
|
|
266
|
+
let cache = cacheArrayEqual(function cacheArgsEqual(args: unknown[]) {
|
|
267
267
|
return fnc(...args);
|
|
268
268
|
}, limit);
|
|
269
269
|
return Object.assign(
|
package/src/callManager.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CallerContext, CallType, ClientHookContext, FullCallType, FunctionFlags
|
|
|
3
3
|
import { _setSocketContext } from "../SocketFunction";
|
|
4
4
|
import { entries, isNode } from "./misc";
|
|
5
5
|
import debugbreak from "debugbreak";
|
|
6
|
-
import { measureWrap } from "./profiling/measure";
|
|
6
|
+
import { measureBlock, measureWrap } from "./profiling/measure";
|
|
7
7
|
import { formatTime } from "./formatting/format";
|
|
8
8
|
|
|
9
9
|
let classes: {
|
|
@@ -146,7 +146,9 @@ export const runClientHooks = measureWrap(async function runClientHooks(
|
|
|
146
146
|
}
|
|
147
147
|
for (let hook of clientHooks) {
|
|
148
148
|
let time = Date.now();
|
|
149
|
-
await
|
|
149
|
+
await measureBlock(async () => {
|
|
150
|
+
await hook(context);
|
|
151
|
+
}, `clientHook|${hook.name || hook.toString().slice(0, 100)}`);
|
|
150
152
|
time = Date.now() - time;
|
|
151
153
|
if (time > 500) {
|
|
152
154
|
console.warn(`Slow (${formatTime(time)}) client hook: ${JSON.stringify(hook.name || hook.toString().slice(0, 100))} for ${callType.classGuid}.${callType.functionName}(...)`);
|
package/src/misc.ts
CHANGED
|
@@ -346,7 +346,8 @@ export function binarySearchBasic<T, V>(array: T[], getVal: (val: T) => V, searc
|
|
|
346
346
|
* NOTE: If there are duplicates, returns the first match.
|
|
347
347
|
*
|
|
348
348
|
* NOTE: If the value can't be found, returns the bitwise negation of the index where it should be inserted.
|
|
349
|
-
*
|
|
349
|
+
*
|
|
350
|
+
* NOTE: With `if (index < 0) index = ~index;` you will get an index of the value >= the target value.
|
|
350
351
|
*/
|
|
351
352
|
export function binarySearchIndex(listCount: number, compare: (lhsIndex: number) => number): number {
|
|
352
353
|
if (listCount === 0) {
|
package/src/profiling/measure.ts
CHANGED
|
@@ -163,8 +163,8 @@ export function logMeasureTable(
|
|
|
163
163
|
config?: LogMeasureTableConfig
|
|
164
164
|
): FormattedMeasureTable | undefined {
|
|
165
165
|
let { useTotalTime, name } = config || {};
|
|
166
|
-
const thresholdInTable = config?.thresholdInTable ?? 0.
|
|
167
|
-
let minTimeToLog = config?.minTimeToLog ??
|
|
166
|
+
const thresholdInTable = config?.thresholdInTable ?? 0.02;
|
|
167
|
+
let minTimeToLog = config?.minTimeToLog ?? 20;
|
|
168
168
|
const maxTableEntries = config?.maxTableEntries ?? 10;
|
|
169
169
|
|
|
170
170
|
function getTime(entry: ProfileEntry) {
|
package/time/trueTimeShim.ts
CHANGED
|
@@ -54,7 +54,8 @@ export function getTrueTime() {
|
|
|
54
54
|
export function getTrueTimeOffset() {
|
|
55
55
|
return trueTimeOffset;
|
|
56
56
|
}
|
|
57
|
-
export function waitForFirstTimeSync() {
|
|
57
|
+
export function waitForFirstTimeSync(): Promise<void> | undefined {
|
|
58
|
+
if (didFirstTimeSync) return undefined;
|
|
58
59
|
return firstTimeSyncPromise;
|
|
59
60
|
}
|
|
60
61
|
let shimmed = false;
|