measure-fn 3.9.0 → 3.10.1
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/bench.ts +1 -1
- package/example.ts +1 -1
- package/index.test.ts +3 -3
- package/index.ts +6 -6
- package/package.json +33 -33
package/bench.ts
CHANGED
package/example.ts
CHANGED
|
@@ -116,7 +116,7 @@ async function bunServeExample() {
|
|
|
116
116
|
return new Response(`ok: ${url.pathname}`);
|
|
117
117
|
},
|
|
118
118
|
(error) => new Response(`Error: ${(error as Error).message}`, { status: 500 })
|
|
119
|
-
),
|
|
119
|
+
) as any,
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
// ✅ Pattern 2: measure.assert — throws on error (sugar for onError + throw)
|
package/index.test.ts
CHANGED
|
@@ -527,7 +527,7 @@ describe("onError (3rd argument)", () => {
|
|
|
527
527
|
throw new Error('not found');
|
|
528
528
|
}, () => 'fallback');
|
|
529
529
|
out.restore();
|
|
530
|
-
expect(result).toBe('fallback');
|
|
530
|
+
expect(result).toBe('fallback' as any);
|
|
531
531
|
});
|
|
532
532
|
|
|
533
533
|
test("returns normal result on success (onError ignored)", async () => {
|
|
@@ -565,7 +565,7 @@ describe("onError (3rd argument)", () => {
|
|
|
565
565
|
throw error;
|
|
566
566
|
});
|
|
567
567
|
out.restore();
|
|
568
|
-
expect(result).toBe('recovered');
|
|
568
|
+
expect(result).toBe('recovered' as any);
|
|
569
569
|
});
|
|
570
570
|
|
|
571
571
|
test("still logs error even when onError handles it", async () => {
|
|
@@ -774,7 +774,7 @@ describe("custom logger", () => {
|
|
|
774
774
|
const events: MeasureEvent[] = [];
|
|
775
775
|
configure({ logger: (e) => events.push(e) });
|
|
776
776
|
await measure({ label: "op", budget: 100 }, async () => 1);
|
|
777
|
-
expect(events[1]
|
|
777
|
+
expect(events[1]!.budget).toBe(100);
|
|
778
778
|
});
|
|
779
779
|
});
|
|
780
780
|
|
package/index.ts
CHANGED
|
@@ -298,8 +298,8 @@ const createMeasureImpl = (prefix?: string, counterRef?: { value: number }, scop
|
|
|
298
298
|
const localMaxLen = extractMaxResultLength(actionInternal);
|
|
299
299
|
const effectiveMaxLen = localMaxLen ?? inheritedMaxLen;
|
|
300
300
|
|
|
301
|
-
const currentId = toAlpha(parentIdChain.pop() ?? 0);
|
|
302
|
-
const fullIdChain = [...parentIdChain, currentId];
|
|
301
|
+
const currentId = toAlpha(Number(parentIdChain.pop() ?? 0));
|
|
302
|
+
const fullIdChain: string[] = [...parentIdChain.map(String), currentId];
|
|
303
303
|
const idStr = fullIdChain.join('-');
|
|
304
304
|
|
|
305
305
|
emit({
|
|
@@ -349,7 +349,7 @@ const createMeasureImpl = (prefix?: string, counterRef?: { value: number }, scop
|
|
|
349
349
|
actionInternal: string | object,
|
|
350
350
|
parentIdChain: (string | number)[],
|
|
351
351
|
depth: number,
|
|
352
|
-
_onError?: undefined,
|
|
352
|
+
_onError?: ((error: unknown) => any) | undefined,
|
|
353
353
|
inheritedMaxLen?: number
|
|
354
354
|
): U | null => {
|
|
355
355
|
const start = performance.now();
|
|
@@ -360,8 +360,8 @@ const createMeasureImpl = (prefix?: string, counterRef?: { value: number }, scop
|
|
|
360
360
|
const localMaxLen = extractMaxResultLength(actionInternal);
|
|
361
361
|
const effectiveMaxLen = localMaxLen ?? inheritedMaxLen;
|
|
362
362
|
|
|
363
|
-
const currentId = toAlpha(parentIdChain.pop() ?? 0);
|
|
364
|
-
const fullIdChain = [...parentIdChain, currentId];
|
|
363
|
+
const currentId = toAlpha(Number(parentIdChain.pop() ?? 0));
|
|
364
|
+
const fullIdChain: string[] = [...parentIdChain.map(String), currentId];
|
|
365
365
|
const idStr = fullIdChain.join('-');
|
|
366
366
|
|
|
367
367
|
if (hasNested) {
|
|
@@ -505,7 +505,7 @@ const createMeasureImpl = (prefix?: string, counterRef?: { value: number }, scop
|
|
|
505
505
|
const results: (R | null)[] = [];
|
|
506
506
|
for (let i = 0; i < items.length; i++) {
|
|
507
507
|
try {
|
|
508
|
-
results.push(await fn(items[i]
|
|
508
|
+
results.push(await fn(items[i]!, i));
|
|
509
509
|
} catch {
|
|
510
510
|
results.push(null);
|
|
511
511
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "measure-fn",
|
|
3
|
-
"module": "index.ts",
|
|
4
|
-
"main": "./index.ts",
|
|
5
|
-
"types": "./index.ts",
|
|
6
|
-
"version": "3.
|
|
7
|
-
"type": "module",
|
|
8
|
-
"private": false,
|
|
9
|
-
"description": "Zero-dependency function performance measurement with hierarchical logging",
|
|
10
|
-
"keywords": [
|
|
11
|
-
"measure",
|
|
12
|
-
"performance",
|
|
13
|
-
"timing",
|
|
14
|
-
"logging",
|
|
15
|
-
"tracing",
|
|
16
|
-
"hierarchical"
|
|
17
|
-
],
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "https://github.com/7flash/measure-fn"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/bun": "latest"
|
|
25
|
-
},
|
|
26
|
-
"peerDependencies": {
|
|
27
|
-
"typescript": "^5"
|
|
28
|
-
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"test": "bun test",
|
|
31
|
-
"example": "bun run example.ts"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "measure-fn",
|
|
3
|
+
"module": "index.ts",
|
|
4
|
+
"main": "./index.ts",
|
|
5
|
+
"types": "./index.ts",
|
|
6
|
+
"version": "3.10.1",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"private": false,
|
|
9
|
+
"description": "Zero-dependency function performance measurement with hierarchical logging",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"measure",
|
|
12
|
+
"performance",
|
|
13
|
+
"timing",
|
|
14
|
+
"logging",
|
|
15
|
+
"tracing",
|
|
16
|
+
"hierarchical"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/7flash/measure-fn"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/bun": "latest"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"typescript": "^5"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"example": "bun run example.ts"
|
|
32
|
+
}
|
|
33
|
+
}
|