@agoric/internal 0.3.3-other-dev-d15096d.0.d15096d → 0.3.3-other-dev-ecf44df.0.ecf44df
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 +32 -36
- package/src/action-types.d.ts +47 -20
- package/src/action-types.d.ts.map +1 -1
- package/src/action-types.js +21 -21
- package/src/ava-force-exit.d.mts +2 -0
- package/src/ava-force-exit.d.mts.map +1 -0
- package/src/ava-force-exit.mjs +7 -0
- package/src/batched-deliver.d.ts +2 -2
- package/src/batched-deliver.d.ts.map +1 -1
- package/src/batched-deliver.js +2 -3
- package/src/build-cache-types.d.ts +33 -0
- package/src/build-cache-types.d.ts.map +1 -0
- package/src/build-cache-types.js +42 -0
- package/src/build-cache.d.ts +12 -0
- package/src/build-cache.d.ts.map +1 -0
- package/src/build-cache.js +184 -0
- package/src/callback.d.ts +1 -1
- package/src/callback.d.ts.map +1 -1
- package/src/callback.js +1 -0
- package/src/chain-storage-paths.d.ts.map +1 -1
- package/src/chain-storage-paths.js +0 -2
- package/src/config.d.ts +3 -3
- package/src/config.d.ts.map +1 -1
- package/src/config.js +6 -5
- package/src/debug.d.ts +2 -2
- package/src/debug.d.ts.map +1 -1
- package/src/debug.js +19 -5
- package/src/hex.d.ts.map +1 -1
- package/src/hex.js +18 -22
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -2
- package/src/js-utils.d.ts +17 -2
- package/src/js-utils.d.ts.map +1 -1
- package/src/js-utils.js +49 -3
- package/src/keyMirror.d.ts +3 -0
- package/src/keyMirror.d.ts.map +1 -0
- package/src/keyMirror.js +45 -0
- package/src/kv-store.d.ts +33 -0
- package/src/kv-store.d.ts.map +1 -0
- package/src/kv-store.js +265 -0
- package/src/lib-chainStorage.d.ts +25 -42
- package/src/lib-chainStorage.d.ts.map +1 -1
- package/src/lib-chainStorage.js +38 -14
- package/src/lib-nodejs/ava-unhandled-rejection.d.ts +18 -3
- package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -1
- package/src/lib-nodejs/ava-unhandled-rejection.js +217 -20
- package/src/lib-nodejs/engine-gc.js +2 -2
- package/src/lib-nodejs/gc-and-finalize.d.ts +2 -1
- package/src/lib-nodejs/gc-and-finalize.d.ts.map +1 -1
- package/src/lib-nodejs/gc-and-finalize.js +1 -0
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts +11 -4
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
- package/src/lib-nodejs/spawnSubprocessWorker.js +14 -4
- package/src/lib-nodejs/worker-protocol.d.ts +1 -1
- package/src/lib-nodejs/worker-protocol.d.ts.map +1 -1
- package/src/lib-nodejs/worker-protocol.js +5 -6
- package/src/magic-cookie-test-only.d.ts.map +1 -1
- package/src/magic-cookie-test-only.js +0 -2
- package/src/marshal/board-client-utils.d.ts.map +1 -1
- package/src/marshal/board-client-utils.js +4 -1
- package/src/marshal/cap-data.d.ts +9 -1
- package/src/marshal/cap-data.d.ts.map +1 -1
- package/src/marshal/cap-data.js +1 -2
- package/src/marshal/wrap-marshaller.d.ts +34 -7
- package/src/marshal/wrap-marshaller.d.ts.map +1 -1
- package/src/marshal/wrap-marshaller.js +64 -68
- package/src/metrics.d.ts +1 -4
- package/src/metrics.d.ts.map +1 -1
- package/src/metrics.js +7 -2
- package/src/module-utils.d.ts +1 -0
- package/src/module-utils.d.ts.map +1 -1
- package/src/module-utils.js +17 -0
- package/src/natural-sort.d.ts.map +1 -1
- package/src/natural-sort.js +7 -3
- package/src/netstring.d.ts +1 -1
- package/src/netstring.d.ts.map +1 -1
- package/src/netstring.js +5 -6
- package/src/node/buffer-line-transform.d.ts.map +1 -1
- package/src/node/buffer-line-transform.js +0 -1
- package/src/node/createBundles.d.ts +7 -3
- package/src/node/createBundles.d.ts.map +1 -1
- package/src/node/createBundles.js +31 -10
- package/src/node/fs-stream.d.ts +8 -5
- package/src/node/fs-stream.d.ts.map +1 -1
- package/src/node/fs-stream.js +120 -8
- package/src/node/read-json.d.ts +2 -0
- package/src/node/read-json.d.ts.map +1 -0
- package/src/node/read-json.js +16 -0
- package/src/node/shutdown.d.ts +6 -2
- package/src/node/shutdown.d.ts.map +1 -1
- package/src/node/shutdown.js +9 -3
- package/src/priority-senders.d.ts.map +1 -1
- package/src/priority-senders.js +1 -0
- package/src/queue.d.ts.map +1 -1
- package/src/queue.js +10 -2
- package/src/scratch.d.ts +32 -10
- package/src/scratch.d.ts.map +1 -1
- package/src/scratch.js +11 -0
- package/src/ses-utils.d.ts +14 -3
- package/src/ses-utils.d.ts.map +1 -1
- package/src/ses-utils.js +13 -15
- package/src/storage-test-utils.d.ts +4 -11
- package/src/storage-test-utils.d.ts.map +1 -1
- package/src/storage-test-utils.js +16 -14
- package/src/tagged.d.ts +18 -1
- package/src/testing-utils.d.ts +22 -1
- package/src/testing-utils.d.ts.map +1 -1
- package/src/testing-utils.js +131 -6
- package/src/tmpDir.d.ts.map +1 -1
- package/src/tmpDir.js +1 -1
- package/src/typeCheck.d.ts +4 -8
- package/src/typeCheck.d.ts.map +1 -1
- package/src/typeCheck.js +13 -6
- package/src/typeGuards.d.ts +5 -5
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +4 -5
- package/src/types-index.d.ts +1 -0
- package/src/types.d.ts +41 -14
- package/src/types.d.ts.map +1 -1
- package/src/types.js +161 -0
- package/src/upgrade-api.d.ts +2 -2
- package/src/upgrade-api.d.ts.map +1 -1
- package/src/upgrade-api.js +4 -3
- package/src/work-pool.d.ts.map +1 -1
- package/src/work-pool.js +9 -2
- package/vendor/anylogger.d.ts +98 -0
- package/vendor/anylogger.d.ts.map +1 -0
- package/vendor/anylogger.js +60 -0
- package/vendor/anylogger.ts +160 -0
- package/vendor/tsconfig.anylogger.json +15 -0
- package/exported.js +0 -2
- package/src/types.ts +0 -133
package/src/config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { keyMirror } from './keyMirror.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @file
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
/**
|
|
38
39
|
* Event source ids used by the bridge device.
|
|
39
40
|
*
|
|
40
|
-
* @
|
|
41
|
+
* @typedef {(typeof BridgeId)[keyof typeof BridgeId]} BridgeId
|
|
41
42
|
*/
|
|
42
43
|
export const BridgeId = /** @type {const} */ ({
|
|
43
44
|
BANK: 'bank',
|
|
@@ -52,15 +53,15 @@ export const BridgeId = /** @type {const} */ ({
|
|
|
52
53
|
});
|
|
53
54
|
harden(BridgeId);
|
|
54
55
|
|
|
55
|
-
/** @satisfies {Record<string, BridgeId>} */
|
|
56
|
+
/** @satisfies {Record<string, typeof BridgeId[keyof typeof BridgeId]>} */
|
|
56
57
|
export const CosmosInitKeyToBridgeId = {
|
|
57
58
|
vbankPort: 'bank',
|
|
58
59
|
vibcPort: 'dibc',
|
|
59
60
|
};
|
|
60
61
|
harden(CosmosInitKeyToBridgeId);
|
|
61
62
|
|
|
62
|
-
export const WalletName =
|
|
63
|
-
depositFacet:
|
|
63
|
+
export const WalletName = keyMirror({
|
|
64
|
+
depositFacet: null,
|
|
64
65
|
});
|
|
65
66
|
harden(WalletName);
|
|
66
67
|
|
package/src/debug.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function makeTracer(label: string, enable?: boolean | "verbose"): ((..._args:
|
|
2
|
-
sub: (subLabel:
|
|
1
|
+
export function makeTracer(label: string, enable?: boolean | "verbose"): ((..._args: unknown[]) => void) & {
|
|
2
|
+
sub: (subLabel: string, subEnable?: boolean | "verbose") => ((..._args: unknown[]) => void) & /*elided*/ any;
|
|
3
3
|
};
|
|
4
4
|
export type TraceLogger = ReturnType<typeof makeTracer>;
|
|
5
5
|
//# sourceMappingURL=debug.d.ts.map
|
package/src/debug.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.js"],"names":[],"mappings":"AAQO,kCAHI,MAAM,WACN,OAAO,GAAG,SAAS,eAcT,OAAO,EAAA;oBAVf,MAAM,cACN,OAAO,GAAG,SAAS,iBASX,OAAO,EAAA;EA0C3B;0BAIY,UAAU,CAAC,OAAO,UAAU,CAAC"}
|
package/src/debug.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @jessie-check
|
|
2
|
-
|
|
3
1
|
// See https://github.com/Agoric/agoric-sdk/issues/11844
|
|
4
2
|
// See https://github.com/Agoric/agoric-sdk/issues/11845
|
|
5
3
|
let debugInstance = 1;
|
|
@@ -9,6 +7,10 @@ let debugInstance = 1;
|
|
|
9
7
|
* @param {boolean | 'verbose'} enable
|
|
10
8
|
*/
|
|
11
9
|
export const makeTracer = (label, enable = true) => {
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} subLabel
|
|
12
|
+
* @param {boolean | 'verbose'} [subEnable]
|
|
13
|
+
*/
|
|
12
14
|
const sub = (subLabel, subEnable = enable) =>
|
|
13
15
|
makeTracer(`${label}.${subLabel}`, subEnable);
|
|
14
16
|
const key = `----- ${label},${debugInstance} `;
|
|
@@ -16,17 +18,23 @@ export const makeTracer = (label, enable = true) => {
|
|
|
16
18
|
// the cases below define a named variable to provide better debug info
|
|
17
19
|
switch (enable) {
|
|
18
20
|
case false: {
|
|
21
|
+
/** @param {...unknown} _args */
|
|
19
22
|
const logDisabled = (..._args) => {};
|
|
20
23
|
return harden(Object.assign(logDisabled, { sub }));
|
|
21
24
|
}
|
|
22
25
|
case 'verbose': {
|
|
26
|
+
/**
|
|
27
|
+
* @param {unknown} optLog
|
|
28
|
+
* @param {...unknown} args
|
|
29
|
+
*/
|
|
23
30
|
const infoTick = (optLog, ...args) => {
|
|
24
31
|
// XXX Sniff tests such as this are inherently unreliable and smell bad.
|
|
25
32
|
// Even aside from the security hazard of
|
|
26
33
|
// https://github.com/Agoric/agoric-sdk/issues/11845
|
|
27
34
|
// an object intended as a normal logging argument may accidentally
|
|
28
35
|
// pass this sniff test, causing confusion.
|
|
29
|
-
|
|
36
|
+
const maybeLogger = /** @type {{ log?: unknown }} */ (optLog);
|
|
37
|
+
if (typeof maybeLogger?.log === 'function') {
|
|
30
38
|
console.info(key, ...args);
|
|
31
39
|
} else {
|
|
32
40
|
console.info(key, optLog, ...args);
|
|
@@ -35,10 +43,16 @@ export const makeTracer = (label, enable = true) => {
|
|
|
35
43
|
return harden(Object.assign(infoTick, { sub }));
|
|
36
44
|
}
|
|
37
45
|
default: {
|
|
46
|
+
/**
|
|
47
|
+
* @param {unknown} optLog
|
|
48
|
+
* @param {...unknown} args
|
|
49
|
+
*/
|
|
38
50
|
const debugTick = (optLog, ...args) => {
|
|
39
51
|
// Another unreliable sniff test like the one above
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
const maybeLogger =
|
|
53
|
+
/** @type {{ log?: (...args: unknown[]) => void }} */ (optLog);
|
|
54
|
+
if (typeof maybeLogger?.log === 'function') {
|
|
55
|
+
maybeLogger.log(key, ...args);
|
|
42
56
|
} else {
|
|
43
57
|
console.info(key, optLog, ...args);
|
|
44
58
|
}
|
package/src/hex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["hex.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["hex.js"],"names":[],"mappings":"AAkCO,wCAFM,QAAQ,CAyBpB;AAgBM,iDAJI,oBAAoB,GAElB,QAAQ,CAoBpB;8BAzFmB,UAAU,KAAK,MAAM;8BACrB,MAAM,KAAK,UAAU;;eAD3B,CAAC,GAAG,EAAE,UAAU,KAAK,MAAM;eAC3B,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU;;;;;mCAyD5B,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG;IACvD,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC;CAClD"}
|
package/src/hex.js
CHANGED
|
@@ -5,31 +5,27 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/** @type {string[]} */
|
|
8
|
-
const encodings = Array
|
|
9
|
-
// Write the hex representation of the byte.
|
|
10
|
-
b.toString(16).padStart(2, '0'),
|
|
11
|
-
);
|
|
8
|
+
const encodings = new Array(256);
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
|
-
*
|
|
11
|
+
* Map entries for all four permutations of lowercase and uppercase
|
|
15
12
|
* transformations of the two hex digits per byte. The map is keyed by the hex
|
|
16
13
|
* string and the value is the byte value. This allows for fast lookups when
|
|
17
14
|
* decoding hex strings.
|
|
18
15
|
*
|
|
19
16
|
* @type {Map<string, number>}
|
|
20
17
|
*/
|
|
21
|
-
const decodings = new Map(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
18
|
+
const decodings = new Map();
|
|
19
|
+
for (let b = 0; b < 256; b += 1) {
|
|
20
|
+
// Write the hex representation of the byte.
|
|
21
|
+
const lo = b.toString(16).padStart(2, '0');
|
|
22
|
+
const UP = lo.toUpperCase();
|
|
23
|
+
encodings[b] = lo;
|
|
24
|
+
decodings.set(lo, b);
|
|
25
|
+
decodings.set(`${lo[0]}${UP[1]}`, b);
|
|
26
|
+
decodings.set(`${UP[0]}${lo[1]}`, b);
|
|
27
|
+
decodings.set(UP, b);
|
|
28
|
+
}
|
|
33
29
|
|
|
34
30
|
/**
|
|
35
31
|
* Create a hex codec that is portable across standard JS environments.
|
|
@@ -83,12 +79,12 @@ export const makeBufferishHexCodec = Bufferish => {
|
|
|
83
79
|
decodeHex: hex => {
|
|
84
80
|
const buf = Bufferish.from(hex, 'hex');
|
|
85
81
|
|
|
82
|
+
if (buf.byteLength * 2 !== hex.length) {
|
|
83
|
+
throw new Error(`Invalid hex string: ${hex}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
86
|
// Coerce to Uint8Array to avoid leaking the abstraction.
|
|
87
|
-
const u8a = new Uint8Array(
|
|
88
|
-
buf.buffer,
|
|
89
|
-
buf.byteOffset,
|
|
90
|
-
buf.byteLength / Uint8Array.BYTES_PER_ELEMENT,
|
|
91
|
-
);
|
|
87
|
+
const u8a = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
92
88
|
return u8a;
|
|
93
89
|
},
|
|
94
90
|
};
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @jessie-check
|
|
2
|
-
|
|
3
1
|
/// <reference types="ses" />
|
|
4
2
|
|
|
5
3
|
// NOTE: Because @endo/bundle-source does not do tree-shaking (at least as of
|
|
@@ -15,6 +13,7 @@ export * from './config.js';
|
|
|
15
13
|
export * from './debug.js';
|
|
16
14
|
export * from './errors.js';
|
|
17
15
|
export * from './js-utils.js';
|
|
16
|
+
export * from './keyMirror.js';
|
|
18
17
|
export { pureDataMarshaller } from './marshal/pure-data.js';
|
|
19
18
|
export * from './method-tools.js';
|
|
20
19
|
export * from './metrics.js';
|
package/src/js-utils.d.ts
CHANGED
|
@@ -25,12 +25,27 @@ export const fromTypedEntries: FromTypedEntries;
|
|
|
25
25
|
*/
|
|
26
26
|
export const typedMap: TypedMap;
|
|
27
27
|
export const logLevels: readonly ["debug", "log", "info", "warn", "error"];
|
|
28
|
+
/** @typedef {(typeof logLevels)[keyof typeof logLevels & number]} LogLevel */
|
|
29
|
+
/** @typedef {Pick<Console, LogLevel>} LimitedConsole */
|
|
30
|
+
/**
|
|
31
|
+
* Compare two same-type values using built-in operators.
|
|
32
|
+
* All zeros are placed in an equivalence class that ignores their sign, all
|
|
33
|
+
* NaNs are placed in an equivalence class after all other numbers, and strings
|
|
34
|
+
* are compared lexicographically by UTF-16 code unit.
|
|
35
|
+
*
|
|
36
|
+
* @type {((a: bigint, b: bigint) => -1 | 0 | 1) &
|
|
37
|
+
* ((a: number, b: number) => -1 | 0 | 1) &
|
|
38
|
+
* ((a: string, b: string) => -1 | 0 | 1)
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
export const naiveCompare: ((a: bigint, b: bigint) => -1 | 0 | 1) & ((a: number, b: number) => -1 | 0 | 1) & ((a: string, b: string) => -1 | 0 | 1);
|
|
28
42
|
export function deepCopyJsonable<T>(value: T): T;
|
|
29
43
|
export function deepMapObject<O extends Record<string, unknown>, M>(obj: O, mapper: <T extends Record<string, unknown>, K extends string & keyof T>(value: T[K], name: K, record: T) => T[K] | M): O | { [K_1 in keyof O]: K_1 extends string ? O[K_1] | M : never; };
|
|
30
44
|
export function defineName<F extends Function>(name: string, fn: F): F;
|
|
45
|
+
export function groupDecimalDigits(decimal: bigint | `${bigint}` | `${bigint}.${bigint}`, groupSize?: number): string;
|
|
31
46
|
export function objectMapMutable<O extends Record<string, unknown>, M>(obj: O, mapper: <K extends keyof O>(value: O[K], key: K) => M): { [K in keyof O]: K extends string ? M : never; };
|
|
32
47
|
export function partialMap<T, U>(arr: T[], mapOrDrop: (value: T, index: number, arr: T[]) => U | undefined | false): U[];
|
|
33
|
-
export function provideLazyMap<K, V>(map: K extends WeakKey ? WeakMap<K, V> : Map<K, V>, key: K, makeValue: (key: K) => V): V;
|
|
48
|
+
export function provideLazyMap<K, V>(map: [K] extends [WeakKey] ? WeakMap<K, V> : Map<K, V>, key: K, makeValue: (key: K) => V): V;
|
|
34
49
|
export function makeMeasureSeconds(currentTimeMillisec: () => number): <T>(fn: () => Promise<T>) => Promise<{
|
|
35
50
|
result: T;
|
|
36
51
|
duration: number;
|
|
@@ -39,6 +54,6 @@ export function unprefixedProperties<P extends string, K extends string, V>(obj:
|
|
|
39
54
|
export type TypedEntries = <O extends Record<string, unknown>>(obj: O) => Exclude<{ [K in keyof O]: K extends string ? [K, O[K]] : never; }[keyof O], undefined>[];
|
|
40
55
|
export type FromTypedEntries = <const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>>(entries: Entries) => { [Entry in Entries[number] as Entry[0]]: Entry[1]; };
|
|
41
56
|
export type TypedMap = <A extends unknown[], V>(arr: A, mapper: <K extends number>(el: A[K], idx: K, arr: A) => V) => V[];
|
|
42
|
-
export type LogLevel = (typeof logLevels)[keyof
|
|
57
|
+
export type LogLevel = (typeof logLevels)[keyof typeof logLevels & number];
|
|
43
58
|
export type LimitedConsole = Pick<Console, LogLevel>;
|
|
44
59
|
//# sourceMappingURL=js-utils.d.ts.map
|
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":"
|
|
1
|
+
{"version":3,"file":"js-utils.d.ts","sourceRoot":"","sources":["js-utils.js"],"names":[],"mappings":"AAQA,yEAAyE;AACzE,mBAA0C,IAAI,CAAE;AAEhD;;;;;;;GAOG;AACH,2BAAuC,YAAY,CAAsB;AAEzE;;;;;;GAMG;AACH,+BAA2C,gBAAgB,CAEzD;AAEF;;;;;GAKG;AACH,uBAAmC,QAAQ,CAEzC;AAEF,2EAMG;AAGH,8EAA8E;AAE9E,wDAAwD;AAExD;;;;;;;;;;GAUG;AACH,2BALU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAC/C,CAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAC1C,CAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CASzC;AAWK,iCAJ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CAAC,KACtD,CAAC,EAAE;uBAeG,CAAC,OAAO,SAAS,EAAE,MAAM,OAAO,SAAS,GAAG,MAAM,CAAC;6BAEnD,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC"}
|
package/src/js-utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// @jessie-check
|
|
3
2
|
/**
|
|
4
3
|
* @file Pure JavaScript utility functions that are compatible with but not
|
|
5
4
|
* dependent upon a hardened environment.
|
|
@@ -50,10 +49,29 @@ export const logLevels = /** @type {const} */ ([
|
|
|
50
49
|
]);
|
|
51
50
|
Object.freeze(logLevels);
|
|
52
51
|
|
|
53
|
-
/** @typedef {(typeof logLevels)[keyof logLevels & number]} LogLevel */
|
|
52
|
+
/** @typedef {(typeof logLevels)[keyof typeof logLevels & number]} LogLevel */
|
|
54
53
|
|
|
55
54
|
/** @typedef {Pick<Console, LogLevel>} LimitedConsole */
|
|
56
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Compare two same-type values using built-in operators.
|
|
58
|
+
* All zeros are placed in an equivalence class that ignores their sign, all
|
|
59
|
+
* NaNs are placed in an equivalence class after all other numbers, and strings
|
|
60
|
+
* are compared lexicographically by UTF-16 code unit.
|
|
61
|
+
*
|
|
62
|
+
* @type {((a: bigint, b: bigint) => -1 | 0 | 1) &
|
|
63
|
+
* ((a: number, b: number) => -1 | 0 | 1) &
|
|
64
|
+
* ((a: string, b: string) => -1 | 0 | 1)
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
export const naiveCompare = (a, b) => {
|
|
68
|
+
if (a < b) return -1;
|
|
69
|
+
if (a > b) return 1;
|
|
70
|
+
return /** @type {-1 | 0 | 1} */ (
|
|
71
|
+
(Number.isNaN(a) ? 1 : 0) - (Number.isNaN(b) ? 1 : 0)
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
57
75
|
/**
|
|
58
76
|
* Deep-copy a value by round-tripping it through JSON (which drops
|
|
59
77
|
* function/symbol/undefined values and properties that are non-enumerable
|
|
@@ -153,6 +171,34 @@ export const deepMapObject = (obj, mapper) =>
|
|
|
153
171
|
export const defineName = (name, fn) =>
|
|
154
172
|
defineProperty(fn, 'name', { value: name });
|
|
155
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Add underscore separators to a decimal string.
|
|
176
|
+
*
|
|
177
|
+
* @param {bigint | `${bigint}` | `${bigint}.${bigint}`} decimal
|
|
178
|
+
* @param {number} [groupSize]
|
|
179
|
+
*/
|
|
180
|
+
export const groupDecimalDigits = (decimal, groupSize = 3) =>
|
|
181
|
+
`${decimal}`.replace(
|
|
182
|
+
/^([+-]?)([0-9]+)([.][0-9]+)?$|.*/,
|
|
183
|
+
(_x, s, w, f = '') => {
|
|
184
|
+
if (!w) throw Error('input must be a decimal string');
|
|
185
|
+
const wCount = w.length;
|
|
186
|
+
const wGroups =
|
|
187
|
+
w.slice(wCount % groupSize).match(RegExp(`[0-9]{${groupSize}}`, 'g')) ||
|
|
188
|
+
[];
|
|
189
|
+
if (wCount % groupSize) wGroups.unshift(w.slice(0, wCount % groupSize));
|
|
190
|
+
|
|
191
|
+
const fGroups = f.match(RegExp(`[0-9]{1,${groupSize}}`, 'g')) || [];
|
|
192
|
+
const lastFGroup = fGroups.pop();
|
|
193
|
+
if (lastFGroup) {
|
|
194
|
+
fGroups.push(lastFGroup.padEnd(groupSize, '0'));
|
|
195
|
+
fGroups[0] = `.${fGroups[0]}`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return `${s}${wGroups.join('_')}${fGroups.join('_')}`;
|
|
199
|
+
},
|
|
200
|
+
);
|
|
201
|
+
|
|
156
202
|
/**
|
|
157
203
|
* By analogy with how `Array.prototype.map` will map the elements of an array
|
|
158
204
|
* to transformed elements of an array of the same shape, `objectMapMutable`
|
|
@@ -201,7 +247,7 @@ export const partialMap = (arr, mapOrDrop) =>
|
|
|
201
247
|
*
|
|
202
248
|
* @template K
|
|
203
249
|
* @template V
|
|
204
|
-
* @param {K extends WeakKey ? WeakMap<K, V> : Map<K, V>} map
|
|
250
|
+
* @param {[K] extends [WeakKey] ? WeakMap<K, V> : Map<K, V>} map
|
|
205
251
|
* @param {K} key
|
|
206
252
|
* @param {(key: K) => V} makeValue
|
|
207
253
|
* @returns {V}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export function keyMirror<Init extends Record<string, string | null> & Record<Exclude<PropertyKey, string>, never>>(record: Init & { readonly [K in keyof Init]: Init[K] extends null ? null : K; }): KeyMirrorResult<Init>;
|
|
2
|
+
export type KeyMirrorResult<Init extends Record<string, string | null> & Record<Exclude<PropertyKey, string>, never>> = { readonly [K in keyof Init]: K; };
|
|
3
|
+
//# sourceMappingURL=keyMirror.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyMirror.d.ts","sourceRoot":"","sources":["keyMirror.js"],"names":[],"mappings":"AA0BO,0BAJoF,IAAI,SAAjF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAAK,CAAE,UAC/E,IAAI,GAAG,EAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,GAAE,GACpE,eAAe,CAAC,IAAI,CAAC,CAkBjC;4BArC0F,IAAI,SAAjF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAAK,CAAE,IAC7E,EAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,IAAI,GAAG,CAAC,GAAE"}
|
package/src/keyMirror.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const { freeze, entries } = Object;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @template {Record<string, string | null> & Record<Exclude<PropertyKey, string>, never>} Init
|
|
7
|
+
* @typedef {{ readonly [K in keyof Init]: K }} KeyMirrorResult
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Mirror the keys of an object to string values that match the key names. This
|
|
12
|
+
* works well to define a TypeScript enum type compatible with erasable syntax.
|
|
13
|
+
* Declare the companion type with `@typedef` (whose name matches the const) so
|
|
14
|
+
* it resolves under both `tsc` and `tsgo`; the `@enum` tag is not honored by
|
|
15
|
+
* `tsgo`:
|
|
16
|
+
*
|
|
17
|
+
* `@typedef {(typeof MyEnum)[keyof typeof MyEnum]} MyEnum`
|
|
18
|
+
*
|
|
19
|
+
* The provided record must only map property names to either `null` or the
|
|
20
|
+
* property name itself. The returned object has identical keys whose values are
|
|
21
|
+
* the string form of the key.
|
|
22
|
+
*
|
|
23
|
+
* @template {Record<string, string | null> & Record<Exclude<PropertyKey, string>, never>} Init
|
|
24
|
+
* @param {Init & { readonly [K in keyof Init]: Init[K] extends null ? null : K }} record
|
|
25
|
+
* @returns {KeyMirrorResult<Init>}
|
|
26
|
+
*/
|
|
27
|
+
export const keyMirror = record => {
|
|
28
|
+
if (record === null || typeof record !== 'object') {
|
|
29
|
+
throw TypeError('keyMirror expects a record of string keys.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @type {Record<string, string>} */
|
|
33
|
+
const mirrored = Object.create(null);
|
|
34
|
+
for (const [key, value] of entries(record)) {
|
|
35
|
+
if (value !== null && value !== key) {
|
|
36
|
+
throw TypeError(
|
|
37
|
+
`Value for key "${key}" must be null or the key string; got ${String(value)}.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
mirrored[key] = key;
|
|
41
|
+
}
|
|
42
|
+
return /** @type {KeyMirrorResult<Init>} */ (freeze(mirrored));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
freeze(keyMirror);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Database} from 'better-sqlite3';
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @template [T=string]
|
|
6
|
+
* @typedef {{
|
|
7
|
+
* has: (key: string) => boolean;
|
|
8
|
+
* get: (key: string) => T | undefined;
|
|
9
|
+
* getNextKey: (previousKey: string) => string | undefined;
|
|
10
|
+
* set: (key: string, value: T) => void;
|
|
11
|
+
* delete: (key: string) => void;
|
|
12
|
+
* }} KVStore
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @param {Database} db The SQLite database connection.
|
|
16
|
+
* @param {() => void} beforeMutation Called before mutating methods to
|
|
17
|
+
* establish a DB transaction if needed
|
|
18
|
+
* @param {(...args: string[]) => void} trace Called after set/delete to record
|
|
19
|
+
* a debug log
|
|
20
|
+
* @returns {KVStore}
|
|
21
|
+
*/
|
|
22
|
+
export function makeKVStore(db: Database, beforeMutation: () => void, trace: (...args: string[]) => void): KVStore;
|
|
23
|
+
export function compareByCodePoints(left: string, right: string): 0 | 1 | -1;
|
|
24
|
+
export function makeKVStoreFromMap<T = unknown>(map: Map<string, T>): KVStore<T>;
|
|
25
|
+
export type KVStore<T = string> = {
|
|
26
|
+
has: (key: string) => boolean;
|
|
27
|
+
get: (key: string) => T | undefined;
|
|
28
|
+
getNextKey: (previousKey: string) => string | undefined;
|
|
29
|
+
set: (key: string, value: T) => void;
|
|
30
|
+
delete: (key: string) => void;
|
|
31
|
+
};
|
|
32
|
+
import type { Database } from 'better-sqlite3';
|
|
33
|
+
//# sourceMappingURL=kv-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["kv-store.js"],"names":[],"mappings":"AAGA;;GAEG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;GAOG;AAEH,gCARW,QAAQ,kBACR,MAAM,IAAI,SAEV,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAEzB,OAAO,CA0InB;AAWM,0CAHI,MAAM,SACN,MAAM,cAsBhB;AAOM,mCAJO,CAAC,iBACJ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GACZ,OAAO,CAAC,CAAC,CAAC,CAkEtB;oBAhQa,CAAC,aACF;IACR,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9B,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,CAAC;IACpC,UAAU,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACxD,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACrC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;8BAXuB,gBAAgB"}
|