@agoric/internal 0.4.0-u19.2 → 0.4.0-u21.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 CHANGED
@@ -1,42 +1,46 @@
1
1
  {
2
2
  "name": "@agoric/internal",
3
- "version": "0.4.0-u19.2",
3
+ "version": "0.4.0-u21.0",
4
4
  "description": "Externally unsupported utilities internal to agoric-sdk",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "engines": {
8
- "node": "^18.12 || ^20.9"
8
+ "node": "^20.9 || ^22.11"
9
9
  },
10
10
  "scripts": {
11
11
  "build": "exit 0",
12
- "prepack": "tsc --build tsconfig.build.json",
12
+ "prepack": "yarn run -T tsc --build tsconfig.build.json",
13
13
  "postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
14
14
  "test": "ava",
15
15
  "test:nyc": "exit 0",
16
16
  "test:xs": "exit 0",
17
17
  "lint-fix": "yarn lint:eslint --fix",
18
- "lint": "run-s --continue-on-error lint:*",
19
- "lint:eslint": "eslint .",
20
- "lint:types": "tsc"
18
+ "lint": "yarn run -T run-s --continue-on-error 'lint:*'",
19
+ "lint:eslint": "yarn run -T eslint .",
20
+ "lint:types": "yarn run -T tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/base-zone": "^0.1.1-u19.0",
24
- "@endo/common": "^1.2.9",
25
- "@endo/errors": "^1.2.9",
26
- "@endo/far": "^1.1.10",
27
- "@endo/init": "^1.1.8",
28
- "@endo/marshal": "^1.6.3",
29
- "@endo/pass-style": "^1.4.8",
30
- "@endo/patterns": "^1.4.8",
31
- "@endo/promise-kit": "^1.1.9",
32
- "@endo/stream": "^1.2.9",
23
+ "@agoric/base-zone": "workspace:*",
24
+ "@endo/common": "^1.2.10",
25
+ "@endo/compartment-mapper": "^1.6.0",
26
+ "@endo/errors": "^1.2.10",
27
+ "@endo/eventual-send": "^1.3.1",
28
+ "@endo/far": "^1.1.11",
29
+ "@endo/init": "^1.1.9",
30
+ "@endo/marshal": "^1.6.4",
31
+ "@endo/nat": "^5.1.0",
32
+ "@endo/pass-style": "^1.5.0",
33
+ "@endo/patterns": "^1.5.0",
34
+ "@endo/promise-kit": "^1.1.10",
35
+ "@endo/stream": "^1.2.10",
33
36
  "anylogger": "^0.21.0",
34
37
  "jessie.js": "^0.3.4"
35
38
  },
36
39
  "devDependencies": {
37
- "@agoric/cosmic-proto": "^0.5.0-u19.2",
38
- "@endo/exo": "^1.5.8",
39
- "@endo/init": "^1.1.8",
40
+ "@agoric/cosmic-proto": "workspace:*",
41
+ "@endo/exo": "^1.5.9",
42
+ "@endo/init": "^1.1.9",
43
+ "@fast-check/ava": "^2.0.1",
40
44
  "ava": "^5.3.0",
41
45
  "tsd": "^0.31.1"
42
46
  },
@@ -58,7 +62,7 @@
58
62
  "access": "public"
59
63
  },
60
64
  "typeCoverage": {
61
- "atLeast": 93.04
65
+ "atLeast": 92.98
62
66
  },
63
- "gitHead": "f0ae74b84cb6de3724bfdcd18b4bea7e8199dee1"
67
+ "gitHead": "e4dd46857133403d584bcf822a81817b355532f9"
64
68
  }
package/src/config.d.ts CHANGED
@@ -14,10 +14,8 @@ export namespace BridgeId {
14
14
  let WALLET: "wallet";
15
15
  }
16
16
  export namespace CosmosInitKeyToBridgeId {
17
- import vbankPort = BANK;
18
- export { vbankPort };
19
- import vibcPort = DIBC;
20
- export { vibcPort };
17
+ let vbankPort: "bank";
18
+ let vibcPort: "dibc";
21
19
  }
22
20
  export namespace WalletName {
23
21
  let depositFacet: "depositFacet";
package/src/config.js CHANGED
@@ -31,10 +31,12 @@ export const BridgeId = /** @type {const} */ ({
31
31
  });
32
32
  harden(BridgeId);
33
33
 
34
+ /** @satisfies {Record<string, BridgeId>} */
34
35
  export const CosmosInitKeyToBridgeId = {
35
- vbankPort: BridgeId.BANK,
36
- vibcPort: BridgeId.DIBC,
36
+ vbankPort: 'bank',
37
+ vibcPort: 'dibc',
37
38
  };
39
+ harden(CosmosInitKeyToBridgeId);
38
40
 
39
41
  export const WalletName = /** @type {const} */ ({
40
42
  depositFacet: 'depositFacet',
package/src/hex.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export function makePortableHexCodec(): HexCodec;
2
+ export function makeBufferishHexCodec(Bufferish: BufferishConstructor): HexCodec;
3
+ export const encodeHex: (buf: Uint8Array) => string;
4
+ export const decodeHex: (hex: string) => Uint8Array;
5
+ export type HexCodec = {
6
+ encodeHex: (buf: Uint8Array) => string;
7
+ decodeHex: (hex: string) => Uint8Array;
8
+ };
9
+ /**
10
+ * is the portion of the Node.js Buffer API we need for hex conversion.
11
+ */
12
+ export type BufferishConstructor = Pick<BufferConstructor, "from" | "isBuffer"> & {
13
+ prototype: Pick<Buffer, "toString"> & Uint8Array;
14
+ };
15
+ //# sourceMappingURL=hex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["hex.js"],"names":[],"mappings":"AAsCO,wCAFM,QAAQ,CAyBpB;AAgBM,iDAJI,oBAAoB,GAElB,QAAQ,CAoBpB;8BA7FmB,UAAU,KAAK,MAAM;8BACrB,MAAM,KAAK,UAAU;;eAD3B,CAAC,GAAG,EAAE,UAAU,KAAK,MAAM;eAC3B,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU;;;;;mCA6D5B,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 ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @typedef {object} HexCodec
3
+ * @property {(buf: Uint8Array) => string} encodeHex
4
+ * @property {(hex: string) => Uint8Array} decodeHex
5
+ */
6
+
7
+ /** @type {string[]} */
8
+ const encodings = Array.from({ length: 256 }, (_, b) =>
9
+ // Write the hex representation of the byte.
10
+ b.toString(16).padStart(2, '0'),
11
+ );
12
+
13
+ /**
14
+ * Create map entries for all four permutations of lowercase and uppercase
15
+ * transformations of the two hex digits per byte. The map is keyed by the hex
16
+ * string and the value is the byte value. This allows for fast lookups when
17
+ * decoding hex strings.
18
+ *
19
+ * @type {Map<string, number>}
20
+ */
21
+ const decodings = new Map(
22
+ encodings.flatMap((hexdigits, b) => {
23
+ const lo = hexdigits.toLowerCase();
24
+ const UP = hexdigits.toUpperCase();
25
+ return [
26
+ [lo, b],
27
+ [`${lo[0]}${UP[1]}`, b],
28
+ [`${UP[0]}${lo[1]}`, b],
29
+ [UP, b],
30
+ ];
31
+ }),
32
+ );
33
+
34
+ /**
35
+ * Create a hex codec that is portable across standard JS environments.
36
+ *
37
+ * @returns {HexCodec}
38
+ */
39
+ export const makePortableHexCodec = () => {
40
+ /** @type {HexCodec} */
41
+ const portableHexCodec = {
42
+ encodeHex: buf => Array.from(buf, b => encodings[b]).join(''),
43
+ decodeHex: hex => {
44
+ const inputLen = hex.length;
45
+ if (inputLen % 2 !== 0) {
46
+ throw new Error(`Invalid hex string: ${hex}`);
47
+ }
48
+ const buf = new Uint8Array(inputLen / 2);
49
+ for (let i = 0; i < inputLen; i += 2) {
50
+ const b = decodings.get(hex.slice(i, i + 2));
51
+ if (b === undefined) {
52
+ throw new Error(`Invalid hex string: ${hex}`);
53
+ }
54
+ // eslint-disable-next-line no-bitwise
55
+ buf[i >> 1] = b;
56
+ }
57
+ return buf;
58
+ },
59
+ };
60
+
61
+ return portableHexCodec;
62
+ };
63
+
64
+ /**
65
+ * @typedef {Pick<BufferConstructor, 'from' | 'isBuffer'> & {
66
+ * prototype: Pick<Buffer, 'toString'> & Uint8Array;
67
+ * }} BufferishConstructor
68
+ * is the portion of the Node.js Buffer API we need for hex conversion.
69
+ */
70
+
71
+ /**
72
+ * Create a hex codec using parts of the Node.js Buffer API.
73
+ *
74
+ * @param {BufferishConstructor} Bufferish the object that implements the
75
+ * necessary pieces of Buffer
76
+ * @returns {HexCodec}
77
+ */
78
+ export const makeBufferishHexCodec = Bufferish => {
79
+ /** @type {HexCodec} */
80
+ const attenuatedBufferHexCodec = {
81
+ encodeHex: buf =>
82
+ (Bufferish.isBuffer?.(buf) ? buf : Bufferish.from(buf)).toString('hex'),
83
+ decodeHex: hex => {
84
+ const buf = Bufferish.from(hex, 'hex');
85
+
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
+ );
92
+ return u8a;
93
+ },
94
+ };
95
+ return attenuatedBufferHexCodec;
96
+ };
97
+
98
+ /**
99
+ * Export a hex codec that can work with standard JS engines, but takes
100
+ * advantage of optimizations on some platforms (like Node.js's Buffer API).
101
+ */
102
+ export const { encodeHex, decodeHex } =
103
+ typeof Buffer === 'undefined'
104
+ ? makePortableHexCodec()
105
+ : makeBufferishHexCodec(Buffer);
package/src/index.d.ts CHANGED
@@ -3,12 +3,12 @@ export * from "./debug.js";
3
3
  export * from "./errors.js";
4
4
  export * from "./js-utils.js";
5
5
  export * from "./method-tools.js";
6
+ export * from "./metrics.js";
7
+ export * from "./natural-sort.js";
6
8
  export * from "./ses-utils.js";
9
+ export * from "./tmpDir.js";
7
10
  export * from "./typeCheck.js";
8
11
  export * from "./typeGuards.js";
9
12
  export * from "./types-index.js";
10
13
  export { pureDataMarshaller } from "./marshal.js";
11
- export { objectMap } from "@endo/common/object-map.js";
12
- export { objectMetaMap } from "@endo/common/object-meta-map.js";
13
- export { fromUniqueEntries } from "@endo/common/from-unique-entries.js";
14
14
  //# sourceMappingURL=index.d.ts.map
package/src/index.js CHANGED
@@ -8,13 +8,12 @@ export * from './errors.js';
8
8
  export * from './js-utils.js';
9
9
  export { pureDataMarshaller } from './marshal.js';
10
10
  export * from './method-tools.js';
11
+ export * from './metrics.js';
12
+ export * from './natural-sort.js';
11
13
  export * from './ses-utils.js';
14
+ export * from './tmpDir.js';
12
15
  export * from './typeCheck.js';
13
16
  export * from './typeGuards.js';
14
17
 
15
18
  // eslint-disable-next-line import/export -- just types
16
19
  export * from './types-index.js';
17
-
18
- export { objectMap } from '@endo/common/object-map.js';
19
- export { objectMetaMap } from '@endo/common/object-meta-map.js';
20
- export { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
package/src/js-utils.d.ts CHANGED
@@ -1,15 +1,40 @@
1
+ /** For overriding TypeScript inferring the type of `true` as boolean. */
2
+ export const TRUE: true;
1
3
  /**
2
- * @file Pure JavaScript utility functions that are compatible with but not
3
- * dependent upon a hardened environment.
4
+ * @typedef {<O extends Record<string, unknown>>(
5
+ * obj: O,
6
+ * ) => { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O][]} TypedEntries
4
7
  */
8
+ export const typedEntries: TypedEntries;
9
+ /**
10
+ * @typedef {<
11
+ * const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>,
12
+ * >(
13
+ * entries: Entries,
14
+ * ) => { [Entry in Entries[number] as Entry[0]]: Entry[1] }} FromTypedEntries
15
+ */
16
+ export const fromTypedEntries: FromTypedEntries;
17
+ /**
18
+ * @typedef {<A extends unknown[], V>(
19
+ * arr: A,
20
+ * mapper: <K extends number>(el: A[K], idx: K, arr: A) => V,
21
+ * ) => V[]} TypedMap
22
+ */
23
+ export const typedMap: TypedMap;
5
24
  export const logLevels: readonly ["debug", "log", "info", "warn", "error"];
6
25
  export function deepCopyJsonable<T>(value: T): T;
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; };
26
+ 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; };
27
+ export function defineName<F extends Function>(name: string, fn: F): F;
28
+ 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; };
29
+ export function provideLazyMap<K, V>(map: K extends WeakKey ? WeakMap<K, V> : Map<K, V>, key: K, makeValue: (key: K) => V): V;
9
30
  export function makeMeasureSeconds(currentTimeMillisec: () => number): <T>(fn: () => Promise<T>) => Promise<{
10
31
  result: T;
11
32
  duration: number;
12
33
  }>;
34
+ export function unprefixedProperties<P extends string, K extends string, V>(obj: Record<`${P}${K}`, V>, prefix: P): Record<K, V>;
35
+ export type TypedEntries = <O extends Record<string, unknown>>(obj: O) => { [K in keyof O]: K extends string ? [K, O[K]] : never; }[keyof O][];
36
+ export type FromTypedEntries = <const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>>(entries: Entries) => { [Entry in Entries[number] as Entry[0]]: Entry[1]; };
37
+ export type TypedMap = <A extends unknown[], V>(arr: A, mapper: <K extends number>(el: A[K], idx: K, arr: A) => V) => V[];
13
38
  export type LogLevel = (typeof logLevels)[keyof readonly ["debug", "log", "info", "warn", "error"] & number];
14
39
  export type LimitedConsole = Pick<Console, LogLevel>;
15
40
  //# sourceMappingURL=js-utils.d.ts.map
@@ -1 +1 @@
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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,GAAG,KAAK,CAAC,CAAC,CAAC,GAAE;uBAO/C,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC/B,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KACtD,CAAC,EAAE;uBAeG,CAAC,OAAO,SAAS,EAAE,2DAAkB,MAAM,CAAC;6BAE5C,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC"}
package/src/js-utils.js CHANGED
@@ -5,6 +5,39 @@
5
5
  * dependent upon a hardened environment.
6
6
  */
7
7
 
8
+ const { defineProperty } = Object;
9
+
10
+ /** For overriding TypeScript inferring the type of `true` as boolean. */
11
+ export const TRUE = /** @type {const} */ (true);
12
+
13
+ /**
14
+ * @typedef {<O extends Record<string, unknown>>(
15
+ * obj: O,
16
+ * ) => { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O][]} TypedEntries
17
+ */
18
+ export const typedEntries = /** @type {TypedEntries} */ (Object.entries);
19
+
20
+ /**
21
+ * @typedef {<
22
+ * const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>,
23
+ * >(
24
+ * entries: Entries,
25
+ * ) => { [Entry in Entries[number] as Entry[0]]: Entry[1] }} FromTypedEntries
26
+ */
27
+ export const fromTypedEntries = /** @type {FromTypedEntries} */ (
28
+ Object.fromEntries
29
+ );
30
+
31
+ /**
32
+ * @typedef {<A extends unknown[], V>(
33
+ * arr: A,
34
+ * mapper: <K extends number>(el: A[K], idx: K, arr: A) => V,
35
+ * ) => V[]} TypedMap
36
+ */
37
+ export const typedMap = /** @type {TypedMap} */ (
38
+ Function.prototype.call.bind(Array.prototype.map)
39
+ );
40
+
8
41
  export const logLevels = /** @type {const} */ ([
9
42
  'debug',
10
43
  'log',
@@ -18,8 +51,6 @@ Object.freeze(logLevels);
18
51
 
19
52
  /** @typedef {Pick<Console, LogLevel>} LimitedConsole */
20
53
 
21
- const { entries, fromEntries } = Object;
22
-
23
54
  /**
24
55
  * Deep-copy a value by round-tripping it through JSON (which drops
25
56
  * function/symbol/undefined values and properties that are non-enumerable
@@ -32,11 +63,14 @@ const { entries, fromEntries } = Object;
32
63
  export const deepCopyJsonable = value => JSON.parse(JSON.stringify(value));
33
64
 
34
65
  /**
35
- * @param {any} value
36
- * @param {string | undefined} name
37
- * @param {object | undefined} container
38
- * @param {(value: any, name: string, record: object) => any} mapper
39
- * @returns {any}
66
+ * @template {Record<PropertyKey, unknown>} O
67
+ * @template {string & keyof O} K
68
+ * @template M
69
+ * @param {O[K]} value
70
+ * @param {K | undefined} name
71
+ * @param {O | undefined} container
72
+ * @param {(value: O[K], name: K, record: O) => O[K] | M} mapper
73
+ * @returns {O[K] | M | { [K2 in keyof O[K]]: O[K][K2] | M }}
40
74
  */
41
75
  const deepMapObjectInternal = (value, name, container, mapper) => {
42
76
  if (container && typeof name === 'string') {
@@ -51,18 +85,30 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
51
85
  }
52
86
 
53
87
  let wasMapped = false;
54
- const mappedEntries = Object.entries(value).map(([innerName, innerValue]) => {
88
+ const valueObj = /** @type {Record<string, unknown>} */ (value);
89
+ /**
90
+ * @type {<T extends typeof value, K2 extends string & keyof T>(
91
+ * entry: [K2, T[K2]],
92
+ * ) => [K2, T[K2] | M]}
93
+ */
94
+ const mapEntry = ([innerName, innerValue]) => {
55
95
  const mappedInnerValue = deepMapObjectInternal(
56
96
  innerValue,
57
97
  innerName,
58
- value,
98
+ valueObj,
59
99
  mapper,
60
100
  );
61
101
  wasMapped ||= mappedInnerValue !== innerValue;
62
- return [innerName, mappedInnerValue];
63
- });
102
+ return [innerName, /** @type {any} */ (mappedInnerValue)];
103
+ };
104
+ const mappedEntries = typedEntries(valueObj).map(mapEntry);
64
105
 
65
- return wasMapped ? Object.fromEntries(mappedEntries) : value;
106
+ if (!wasMapped) {
107
+ return value;
108
+ }
109
+
110
+ const mappedObj = fromTypedEntries(mappedEntries);
111
+ return /** @type {any} */ (mappedObj);
66
112
  };
67
113
 
68
114
  /**
@@ -74,23 +120,78 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
74
120
  * When the property value is an object, it is sent to the mapper like any other
75
121
  * value, and then recursively traversed unless replaced with a distinct value.
76
122
  *
77
- * @param {object} obj
78
- * @param {(value: any, name: string, record: object) => any} mapper
79
- * @returns {object}
123
+ * @template {Record<string, unknown>} O
124
+ * @template M
125
+ * @param {O} obj
126
+ * @param {<T extends Record<string, unknown>, K extends string & keyof T>(
127
+ * value: T[K],
128
+ * name: K,
129
+ * record: T,
130
+ * ) => T[K] | M} mapper
131
+ * @returns {O | { [K in keyof O]: K extends string ? O[K] | M : never }}
80
132
  */
81
133
  export const deepMapObject = (obj, mapper) =>
82
- deepMapObjectInternal(obj, undefined, undefined, mapper);
134
+ /** @type {any} */ (deepMapObjectInternal(obj, undefined, undefined, mapper));
83
135
 
84
136
  /**
85
- * @template {Record<PropertyKey, any>} O
86
- * @template V
137
+ * Explicitly set a function's name, supporting use of arrow functions for which
138
+ * source text doesn't include a name and no initial name is set by
139
+ * NamedEvaluation
140
+ * https://tc39.es/ecma262/multipage/syntax-directed-operations.html#sec-runtime-semantics-namedevaluation
141
+ *
142
+ * `name` is the first parameter for better readability at call sites (e.g.,
143
+ * `return defineName('foo', () => { ... })`).
144
+ *
145
+ * @template {Function} F
146
+ * @param {string} name
147
+ * @param {F} fn
148
+ * @returns {F}
149
+ */
150
+ export const defineName = (name, fn) =>
151
+ defineProperty(fn, 'name', { value: name });
152
+
153
+ /**
154
+ * By analogy with how `Array.prototype.map` will map the elements of an array
155
+ * to transformed elements of an array of the same shape, `objectMapMutable`
156
+ * will do likewise for the enumerable string-keyed properties of an object.
157
+ *
158
+ * Unlike endo's `objectMap`, this function returns a non-hardened object.
159
+ *
160
+ * @template {Record<string, unknown>} O
161
+ * @template M
87
162
  * @param {O} obj
88
- * @param {<K extends keyof O>(value: O[K], key: K) => V} mapFn
89
- * @returns {{ [K in keyof O]: V }}
163
+ * @param {<K extends keyof O>(value: O[K], key: K) => M} mapper
164
+ * @returns {{ [K in keyof O]: K extends string ? M : never }}
90
165
  */
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));
166
+ export const objectMapMutable = (obj, mapper) => {
167
+ const oldEntries = typedEntries(obj);
168
+ /** @type {<K extends keyof O>(entry: [K, O[K]]) => [K, M]} */
169
+ const mapEntry = ([k, v]) => [k, mapper(v, k)];
170
+ const newEntries = typedMap(oldEntries, mapEntry);
171
+ const newObj = fromTypedEntries(newEntries);
172
+ return /** @type {any} */ (newObj);
173
+ };
174
+
175
+ /**
176
+ * Return the value from `map` associated with `key`. If there is not yet such a
177
+ * value, get one from `makeValue(key)` and update `map` before returning the
178
+ * new value.
179
+ *
180
+ * @template K
181
+ * @template V
182
+ * @param {K extends WeakKey ? WeakMap<K, V> : Map<K, V>} map
183
+ * @param {K} key
184
+ * @param {(key: K) => V} makeValue
185
+ * @returns {V}
186
+ */
187
+ export const provideLazyMap = (map, key, makeValue) => {
188
+ const found = map.get(key);
189
+ if (found !== undefined || map.has(key)) {
190
+ return /** @type {V} */ (found);
191
+ }
192
+ const value = makeValue(key);
193
+ map.set(key, value);
194
+ return value;
94
195
  };
95
196
 
96
197
  /**
@@ -114,3 +215,23 @@ export const makeMeasureSeconds = currentTimeMillisec => {
114
215
  };
115
216
  return measureSeconds;
116
217
  };
218
+
219
+ /**
220
+ * Find all of an object's properties whose name starts with a prefix, and
221
+ * return a new object consisting of those properties without that prefix.
222
+ * Useful for filtering environment variables relevant to a particular purpose.
223
+ *
224
+ * @template {string} P
225
+ * @template {string} K
226
+ * @template V
227
+ * @param {Record<`${P}${K}`, V>} obj
228
+ * @param {P} prefix
229
+ */
230
+ export const unprefixedProperties = (obj, prefix) =>
231
+ /** @type {Record<K, V>} */ (
232
+ fromTypedEntries(
233
+ typedEntries(obj)
234
+ .filter(([key]) => key.startsWith(prefix))
235
+ .map(([key, value]) => [key.slice(prefix.length), value]),
236
+ )
237
+ );
@@ -31,8 +31,31 @@ export function makeChainStorageRoot(handleStorageMessage: (message: StorageMess
31
31
  * @returns {Promise<StorageNode>}
32
32
  */
33
33
  export function makeStorageNodeChild(storageNodeRef: ERef<StorageNode | null>, childName: string): Promise<StorageNode>;
34
+ /**
35
+ * @import {ERef} from '@endo/far';
36
+ * @import {PassableCap} from '@endo/marshal';
37
+ * @import {TypedPattern} from './types.js';
38
+ */
39
+ /** @typedef {ReturnType<typeof import('@endo/marshal').makeMarshal>} Marshaller */
40
+ /** @typedef {Pick<Marshaller, 'fromCapData'>} Unserializer */
41
+ /**
42
+ * Defined by vstorageStoreKey in vstorage.go
43
+ *
44
+ * @typedef VStorageKey
45
+ * @property {string} storeName
46
+ * @property {string} storeSubkey
47
+ * @property {string} dataPrefixBytes
48
+ * @property {string} [noDataValue]
49
+ */
50
+ /**
51
+ * @template [T=unknown]
52
+ * @typedef StreamCell
53
+ * @property {string} blockHeight decimal representation of a natural number
54
+ * @property {T[]} values
55
+ */
56
+ /** @type {TypedPattern<StreamCell>} */
57
+ export const StreamCellShape: TypedPattern<StreamCell>;
34
58
  export function isStreamCell(cell: any): cell is StreamCell;
35
- export function assertCapData(data: unknown): asserts data is import("@endo/marshal").CapData<string>;
36
59
  /** @type {(name: string) => void} */
37
60
  export const assertPathSegment: (name: string) => void;
38
61
  export function prepareChainStorageNode(zone: import("@agoric/base-zone").Zone): (messenger: import("./types.js").Callback<(message: StorageMessage) => any>, path: string, args_2?: {
@@ -143,5 +166,6 @@ export type StorageMessage = {
143
166
  args: StorageUpdateEntriesMessageArgs;
144
167
  };
145
168
  import type { ERef } from '@endo/far';
169
+ import type { TypedPattern } from './types.js';
146
170
  import type { PassableCap } from '@endo/marshal';
147
171
  //# sourceMappingURL=lib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AC;;;;;qBAC1B,MAAM,YAAY;;;;;4CAqBnB,KAAK,GACX,aAAa,GACb,KAAK,GACL,UAAU,GACV,SAAS,GACT,QAAQ,GACR,MAAM;;;;gDAGA,KAAK,GAAG,kBAAkB,GAAG,QAAQ;;;;mCAGrC,6BAA6B,GACnC,iCAAiC;;;;0CAG3B,CAAC,IAAI,EAAE,MAAM,CAAC;;;;2BAEd,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;;;;8CAErC,YAAY,EAAE;;;;6BAEd;IACJ,MAAM,EAAE,6BAA6B,CAAC;IACtC,IAAI,EAAE,2BAA2B,CAAC;CACnC,GACD;IACE,MAAM,EAAE,iCAAiC,CAAC;IAC1C,IAAI,EAAE,+BAA+B,CAAC;CACvC;0BApIe,WAAW;kCAEH,YAAY;iCADb,eAAe"}
@@ -9,6 +9,7 @@ import * as cb from './callback.js';
9
9
  /**
10
10
  * @import {ERef} from '@endo/far';
11
11
  * @import {PassableCap} from '@endo/marshal';
12
+ * @import {TypedPattern} from './types.js';
12
13
  */
13
14
 
14
15
  /** @typedef {ReturnType<typeof import('@endo/marshal').makeMarshal>} Marshaller */
@@ -31,6 +32,12 @@ import * as cb from './callback.js';
31
32
  * @property {T[]} values
32
33
  */
33
34
 
35
+ /** @type {TypedPattern<StreamCell>} */
36
+ export const StreamCellShape = harden({
37
+ blockHeight: M.string(),
38
+ values: M.array(),
39
+ });
40
+
34
41
  /**
35
42
  * This represents a node in an IAVL tree.
36
43
  *
@@ -77,21 +84,6 @@ export const isStreamCell = cell =>
77
84
  /^0$|^[1-9][0-9]*$/.test(cell.blockHeight);
78
85
  harden(isStreamCell);
79
86
 
80
- // TODO: Consolidate with `insistCapData` functions from swingset-liveslots,
81
- // swingset-xsnap-supervisor, etc.
82
- /**
83
- * @param {unknown} data
84
- * @returns {asserts data is import('@endo/marshal').CapData<string>}
85
- */
86
- export const assertCapData = data => {
87
- assert.typeof(data, 'object');
88
- assert(data);
89
- assert.typeof(data.body, 'string');
90
- assert(Array.isArray(data.slots));
91
- // XXX check that the .slots array elements are actually strings
92
- };
93
- harden(assertCapData);
94
-
95
87
  /**
96
88
  * @typedef {object} StoredFacet
97
89
  * @property {() => Promise<string>} getPath the chain storage path at which the