@agoric/internal 0.3.3-dev-07cb543.0 → 0.3.3-dev-2a71f04.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/package.json +4 -4
- package/src/js-utils.d.ts +1 -0
- package/src/js-utils.d.ts.map +1 -1
- package/src/js-utils.js +14 -0
- package/src/lib-nodejs/ava-unhandled-rejection.d.ts +13 -0
- package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -0
- package/src/lib-nodejs/ava-unhandled-rejection.js +66 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/internal",
|
|
3
|
-
"version": "0.3.3-dev-
|
|
3
|
+
"version": "0.3.3-dev-2a71f04.0+2a71f04",
|
|
4
4
|
"description": "Externally unsupported utilities internal to agoric-sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint:types": "tsc"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-2a71f04.0+2a71f04",
|
|
24
24
|
"@endo/common": "^1.2.9",
|
|
25
25
|
"@endo/errors": "^1.2.9",
|
|
26
26
|
"@endo/far": "^1.1.10",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"jessie.js": "^0.3.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
37
|
+
"@agoric/cosmic-proto": "0.4.1-dev-2a71f04.0+2a71f04",
|
|
38
38
|
"@endo/exo": "^1.5.8",
|
|
39
39
|
"@endo/init": "^1.1.8",
|
|
40
40
|
"ava": "^5.3.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"typeCoverage": {
|
|
61
61
|
"atLeast": 93.04
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "2a71f04176f1a27be8e0356595d3dcd62f6d9186"
|
|
64
64
|
}
|
package/src/js-utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export const logLevels: readonly ["debug", "log", "info", "warn", "error"];
|
|
6
6
|
export function deepCopyJsonable<T>(value: T): T;
|
|
7
7
|
export function deepMapObject(obj: object, mapper: (value: any, name: string, record: object) => any): object;
|
|
8
|
+
export function objectMapMutable<O extends Record<PropertyKey, any>, V>(obj: O, mapFn: <K extends keyof O>(value: O[K], key: K) => V): { [K in keyof O]: V; };
|
|
8
9
|
export function makeMeasureSeconds(currentTimeMillisec: () => number): <T>(fn: () => Promise<T>) => Promise<{
|
|
9
10
|
result: T;
|
|
10
11
|
duration: number;
|
package/src/js-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js-utils.d.ts","sourceRoot":"","sources":["js-utils.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,2EAMG;
|
|
1
|
+
{"version":3,"file":"js-utils.d.ts","sourceRoot":"","sources":["js-utils.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,2EAMG;AAkBI,iCAJM,CAAC,SACH,CAAC,GACC,CAAC,CAE4D;AAiDnE,mCAJI,MAAM,UACN,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,GAAG,GAC/C,MAAM,CAGuC;AASnD,iCANiC,CAAC,SAA3B,MAAM,CAAC,WAAW,EAAE,GAAG,CAAE,EAC1B,CAAC,OACH,CAAC,SACD,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,GAC3C,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAE,CAKjC;AASM,wDAFI,MAAM,MAAM,IAIR,CAAC,MACH,MAAM,OAAO,CAAC,CAAC,CAAC,KACd,OAAO,CAAC;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAStD;uBAnGa,CAAC,OAAO,SAAS,EAAE,2DAAkB,MAAM,CAAC;6BAE5C,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC"}
|
package/src/js-utils.js
CHANGED
|
@@ -18,6 +18,8 @@ Object.freeze(logLevels);
|
|
|
18
18
|
|
|
19
19
|
/** @typedef {Pick<Console, LogLevel>} LimitedConsole */
|
|
20
20
|
|
|
21
|
+
const { entries, fromEntries } = Object;
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* Deep-copy a value by round-tripping it through JSON (which drops
|
|
23
25
|
* function/symbol/undefined values and properties that are non-enumerable
|
|
@@ -79,6 +81,18 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
|
|
|
79
81
|
export const deepMapObject = (obj, mapper) =>
|
|
80
82
|
deepMapObjectInternal(obj, undefined, undefined, mapper);
|
|
81
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @template {Record<PropertyKey, any>} O
|
|
86
|
+
* @template V
|
|
87
|
+
* @param {O} obj
|
|
88
|
+
* @param {<K extends keyof O>(value: O[K], key: K) => V} mapFn
|
|
89
|
+
* @returns {{ [K in keyof O]: V }}
|
|
90
|
+
*/
|
|
91
|
+
export const objectMapMutable = (obj, mapFn) => {
|
|
92
|
+
const newEntries = entries(obj).map(([k, v]) => [k, mapFn(v, k)]);
|
|
93
|
+
return /** @type {{ [K in keyof O]: V }} */ (fromEntries(newEntries));
|
|
94
|
+
};
|
|
95
|
+
|
|
82
96
|
/**
|
|
83
97
|
* Returns a function that uses a millisecond-based current-time capability
|
|
84
98
|
* (such as `performance.now`) to measure execution duration of an async
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {ExecutionContext, Macro, TestFn} from 'ava';
|
|
3
|
+
*/
|
|
4
|
+
export const AVA_EXPECT_UNHANDLED_REJECTIONS: "AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS";
|
|
5
|
+
export const SUBTEST_PREFIX: "(unhandled rejection subprocess): ";
|
|
6
|
+
export function makeExpectUnhandledRejection<C>({ test, importMetaUrl }: {
|
|
7
|
+
test: TestFn<C>;
|
|
8
|
+
importMetaUrl: string;
|
|
9
|
+
}): (expectedUnhandled: number) => Macro<[name: string, impl: (t: ExecutionContext<C>) => any], C>;
|
|
10
|
+
import type { TestFn } from 'ava';
|
|
11
|
+
import type { ExecutionContext } from 'ava';
|
|
12
|
+
import type { Macro } from 'ava';
|
|
13
|
+
//# sourceMappingURL=ava-unhandled-rejection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ava-unhandled-rejection.d.ts","sourceRoot":"","sources":["ava-unhandled-rejection.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH,8CACE,wCAAwC,CAAC;AAE3C,6BAA8B,oCAAoC,CAAC;AAW5D,6CARM,CAAC,2BAEX;IAA0B,IAAI,EAAtB,OAAO,CAAC,CAAC;IACM,aAAa,EAA5B,MAAM;CACd,GAAU,CACR,iBAAiB,EAAE,MAAM,KACtB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CA0CtE;4BAzDiD,KAAK;sCAAL,KAAK;2BAAL,KAAK"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
import engineGC from './engine-gc.js';
|
|
6
|
+
import { makeGcAndFinalize } from './gc-and-finalize.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @import {ExecutionContext, Macro, TestFn} from 'ava';
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const AVA_EXPECT_UNHANDLED_REJECTIONS =
|
|
13
|
+
'AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS';
|
|
14
|
+
|
|
15
|
+
export const SUBTEST_PREFIX = '(unhandled rejection subprocess): ';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @template C
|
|
19
|
+
* @param {object} powers
|
|
20
|
+
* @param {TestFn<C>} powers.test
|
|
21
|
+
* @param {string} powers.importMetaUrl
|
|
22
|
+
* @returns {(
|
|
23
|
+
* expectedUnhandled: number,
|
|
24
|
+
* ) => Macro<[name: string, impl: (t: ExecutionContext<C>) => any], C>}
|
|
25
|
+
*/
|
|
26
|
+
export const makeExpectUnhandledRejection = ({ test, importMetaUrl }) => {
|
|
27
|
+
const self = fileURLToPath(importMetaUrl);
|
|
28
|
+
const gcAndFinalize = makeGcAndFinalize(engineGC);
|
|
29
|
+
|
|
30
|
+
if (process.env[AVA_EXPECT_UNHANDLED_REJECTIONS]) {
|
|
31
|
+
return _expectedUnhandled =>
|
|
32
|
+
test.macro({
|
|
33
|
+
title: (_, name, _impl) => SUBTEST_PREFIX + name,
|
|
34
|
+
exec: async (t, _name, impl) => {
|
|
35
|
+
await null;
|
|
36
|
+
try {
|
|
37
|
+
const result = await impl(t);
|
|
38
|
+
return result;
|
|
39
|
+
} finally {
|
|
40
|
+
await gcAndFinalize();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return expectedUnhandled =>
|
|
47
|
+
test.macro({
|
|
48
|
+
title: (_, name, _impl) => name,
|
|
49
|
+
exec: async (t, name, _impl) =>
|
|
50
|
+
new Promise((resolve, reject) => {
|
|
51
|
+
const ps = spawn('ava', [self, '-m', SUBTEST_PREFIX + name], {
|
|
52
|
+
env: {
|
|
53
|
+
...process.env,
|
|
54
|
+
[AVA_EXPECT_UNHANDLED_REJECTIONS]: `${expectedUnhandled}`,
|
|
55
|
+
},
|
|
56
|
+
stdio: ['ignore', 'inherit', 'inherit', 'ignore'],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
ps.on('close', code => {
|
|
60
|
+
t.is(code, 0, `got exit code ${code}, expected 0 for ${name}`);
|
|
61
|
+
resolve();
|
|
62
|
+
});
|
|
63
|
+
ps.on('error', reject);
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
};
|