@agoric/internal 0.3.3-other-dev-3eb1a1d.0 → 0.3.3-other-dev-d15096d.0.d15096d

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.
Files changed (111) hide show
  1. package/README.md +1 -4
  2. package/package.json +29 -23
  3. package/src/action-types.d.ts +2 -1
  4. package/src/action-types.d.ts.map +1 -1
  5. package/src/action-types.js +4 -4
  6. package/src/batched-deliver.d.ts +6 -2
  7. package/src/batched-deliver.d.ts.map +1 -1
  8. package/src/batched-deliver.js +7 -2
  9. package/src/callback.d.ts +10 -12
  10. package/src/callback.d.ts.map +1 -1
  11. package/src/callback.js +23 -16
  12. package/src/chain-storage-paths.d.ts.map +1 -1
  13. package/src/chain-utils.d.ts +3 -1
  14. package/src/chain-utils.d.ts.map +1 -1
  15. package/src/chain-utils.js +6 -1
  16. package/src/cli-utils.d.ts +2 -0
  17. package/src/cli-utils.d.ts.map +1 -0
  18. package/src/cli-utils.js +21 -0
  19. package/src/config.d.ts +21 -4
  20. package/src/config.d.ts.map +1 -1
  21. package/src/config.js +25 -2
  22. package/src/debug.d.ts +4 -1
  23. package/src/debug.d.ts.map +1 -1
  24. package/src/debug.js +26 -13
  25. package/src/errors.d.ts +1 -1
  26. package/src/errors.d.ts.map +1 -1
  27. package/src/hex.d.ts +15 -0
  28. package/src/hex.d.ts.map +1 -0
  29. package/src/hex.js +105 -0
  30. package/src/index.d.ts +5 -3
  31. package/src/index.js +13 -4
  32. package/src/js-utils.d.ts +38 -1
  33. package/src/js-utils.d.ts.map +1 -1
  34. package/src/js-utils.js +184 -14
  35. package/src/lib-chainStorage.d.ts +45 -32
  36. package/src/lib-chainStorage.d.ts.map +1 -1
  37. package/src/lib-chainStorage.js +24 -32
  38. package/src/lib-nodejs/ava-unhandled-rejection.d.ts +13 -0
  39. package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -0
  40. package/src/lib-nodejs/ava-unhandled-rejection.js +66 -0
  41. package/src/lib-nodejs/spawnSubprocessWorker.d.ts +0 -2
  42. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
  43. package/src/lib-nodejs/spawnSubprocessWorker.js +5 -3
  44. package/src/lib-nodejs/waitUntilQuiescent.d.ts +3 -0
  45. package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -1
  46. package/src/lib-nodejs/waitUntilQuiescent.js +5 -1
  47. package/src/marshal/board-client-utils.d.ts +19 -0
  48. package/src/marshal/board-client-utils.d.ts.map +1 -0
  49. package/src/{marshal.js → marshal/board-client-utils.js} +30 -36
  50. package/src/marshal/cap-data.d.ts +3 -0
  51. package/src/marshal/cap-data.d.ts.map +1 -0
  52. package/src/marshal/cap-data.js +20 -0
  53. package/src/marshal/inaccessible-val.d.ts +2 -0
  54. package/src/marshal/inaccessible-val.d.ts.map +1 -0
  55. package/src/marshal/inaccessible-val.js +15 -0
  56. package/src/marshal/pure-data.d.ts +8 -0
  57. package/src/marshal/pure-data.d.ts.map +1 -0
  58. package/src/marshal/pure-data.js +14 -0
  59. package/src/marshal/wrap-marshaller.d.ts +33 -0
  60. package/src/marshal/wrap-marshaller.d.ts.map +1 -0
  61. package/src/marshal/wrap-marshaller.js +439 -0
  62. package/src/method-tools.d.ts.map +1 -1
  63. package/src/method-tools.js +8 -50
  64. package/src/metrics.d.ts +183 -0
  65. package/src/metrics.d.ts.map +1 -0
  66. package/src/metrics.js +476 -0
  67. package/src/module-utils.d.ts +2 -0
  68. package/src/module-utils.d.ts.map +1 -0
  69. package/src/module-utils.js +27 -0
  70. package/src/natural-sort.d.ts +2 -0
  71. package/src/natural-sort.d.ts.map +1 -0
  72. package/src/natural-sort.js +83 -0
  73. package/src/netstring.d.ts +2 -2
  74. package/src/netstring.d.ts.map +1 -1
  75. package/src/netstring.js +1 -0
  76. package/src/node/buffer-line-transform.d.ts +12 -7
  77. package/src/node/buffer-line-transform.d.ts.map +1 -1
  78. package/src/node/buffer-line-transform.js +8 -4
  79. package/src/node/fs-stream.d.ts +4 -1
  80. package/src/node/fs-stream.d.ts.map +1 -1
  81. package/src/node/fs-stream.js +28 -27
  82. package/src/node/shutdown.d.ts.map +1 -1
  83. package/src/node/shutdown.js +2 -0
  84. package/src/priority-senders.d.ts +3 -1
  85. package/src/priority-senders.d.ts.map +1 -1
  86. package/src/priority-senders.js +7 -2
  87. package/src/queue.d.ts +1 -1
  88. package/src/queue.d.ts.map +1 -1
  89. package/src/ses-utils.d.ts +24 -5
  90. package/src/ses-utils.d.ts.map +1 -1
  91. package/src/ses-utils.js +189 -15
  92. package/src/storage-test-utils.d.ts +25 -7
  93. package/src/storage-test-utils.d.ts.map +1 -1
  94. package/src/storage-test-utils.js +141 -22
  95. package/src/tagged.d.ts +4 -1
  96. package/src/testing-utils.js +1 -1
  97. package/src/tmpDir.d.ts +2 -0
  98. package/src/tmpDir.d.ts.map +1 -0
  99. package/src/tmpDir.js +17 -0
  100. package/src/tokens.d.ts.map +1 -1
  101. package/src/typeGuards.d.ts +19 -0
  102. package/src/typeGuards.d.ts.map +1 -1
  103. package/src/typeGuards.js +16 -0
  104. package/src/types.d.ts +30 -17
  105. package/src/types.d.ts.map +1 -1
  106. package/src/types.ts +43 -18
  107. package/src/work-pool.d.ts +13 -0
  108. package/src/work-pool.d.ts.map +1 -0
  109. package/src/work-pool.js +233 -0
  110. package/src/marshal.d.ts +0 -20
  111. package/src/marshal.d.ts.map +0 -1
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
@@ -1,13 +1,15 @@
1
+ export * from "./cli-utils.js";
1
2
  export * from "./config.js";
2
3
  export * from "./debug.js";
3
4
  export * from "./errors.js";
4
5
  export * from "./js-utils.js";
5
6
  export * from "./method-tools.js";
7
+ export * from "./metrics.js";
8
+ export * from "./natural-sort.js";
6
9
  export * from "./ses-utils.js";
10
+ export * from "./tmpDir.js";
7
11
  export * from "./typeCheck.js";
8
12
  export * from "./typeGuards.js";
9
13
  export * from "./types-index.js";
10
- export { objectMap } from "@endo/common/object-map.js";
11
- export { objectMetaMap } from "@endo/common/object-meta-map.js";
12
- export { fromUniqueEntries } from "@endo/common/from-unique-entries.js";
14
+ export { pureDataMarshaller } from "./marshal/pure-data.js";
13
15
  //# sourceMappingURL=index.d.ts.map
package/src/index.js CHANGED
@@ -2,18 +2,27 @@
2
2
 
3
3
  /// <reference types="ses" />
4
4
 
5
+ // NOTE: Because @endo/bundle-source does not do tree-shaking (at least as of
6
+ // September 2025), bundles for sources that import from '@agoric/internal' will
7
+ // include each of these files even if none of their own exports are used.
8
+ // To keep the size of bundles down, deep imports from @agoric/internal are
9
+ // preferred.
10
+ // HOWEVER, there are still occasional imports of '@agoric/internal', so be
11
+ // judicious about what to include here!
12
+
13
+ export * from './cli-utils.js';
5
14
  export * from './config.js';
6
15
  export * from './debug.js';
7
16
  export * from './errors.js';
8
17
  export * from './js-utils.js';
18
+ export { pureDataMarshaller } from './marshal/pure-data.js';
9
19
  export * from './method-tools.js';
20
+ export * from './metrics.js';
21
+ export * from './natural-sort.js';
10
22
  export * from './ses-utils.js';
23
+ export * from './tmpDir.js';
11
24
  export * from './typeCheck.js';
12
25
  export * from './typeGuards.js';
13
26
 
14
27
  // eslint-disable-next-line import/export -- just types
15
28
  export * from './types-index.js';
16
-
17
- export { objectMap } from '@endo/common/object-map.js';
18
- export { objectMetaMap } from '@endo/common/object-meta-map.js';
19
- export { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
package/src/js-utils.d.ts CHANGED
@@ -1,7 +1,44 @@
1
+ /** For overriding TypeScript inferring the type of `true` as boolean. */
2
+ export const TRUE: true;
3
+ /**
4
+ * @typedef {<O extends Record<string, unknown>>(
5
+ * obj: O,
6
+ * ) => Exclude<
7
+ * { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O],
8
+ * undefined
9
+ * >[]} TypedEntries
10
+ */
11
+ export const typedEntries: TypedEntries;
12
+ /**
13
+ * @typedef {<
14
+ * const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>,
15
+ * >(
16
+ * entries: Entries,
17
+ * ) => { [Entry in Entries[number] as Entry[0]]: Entry[1] }} FromTypedEntries
18
+ */
19
+ export const fromTypedEntries: FromTypedEntries;
20
+ /**
21
+ * @typedef {<A extends unknown[], V>(
22
+ * arr: A,
23
+ * mapper: <K extends number>(el: A[K], idx: K, arr: A) => V,
24
+ * ) => V[]} TypedMap
25
+ */
26
+ export const typedMap: TypedMap;
27
+ export const logLevels: readonly ["debug", "log", "info", "warn", "error"];
1
28
  export function deepCopyJsonable<T>(value: T): T;
2
- export function deepMapObject(obj: object, mapper: (value: any, name: string, record: object) => any): object;
29
+ 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
+ export function defineName<F extends Function>(name: string, fn: F): F;
31
+ 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
+ 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;
3
34
  export function makeMeasureSeconds(currentTimeMillisec: () => number): <T>(fn: () => Promise<T>) => Promise<{
4
35
  result: T;
5
36
  duration: number;
6
37
  }>;
38
+ export function unprefixedProperties<P extends string, K extends string, V>(obj: Record<`${P}${K}`, V>, prefix: P): Record<K, V>;
39
+ 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
+ export type FromTypedEntries = <const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>>(entries: Entries) => { [Entry in Entries[number] as Entry[0]]: Entry[1]; };
41
+ 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 readonly ["debug", "log", "info", "warn", "error"] & number];
43
+ export type LimitedConsole = Pick<Console, LogLevel>;
7
44
  //# sourceMappingURL=js-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"js-utils.d.ts","sourceRoot":"","sources":["js-utils.js"],"names":[],"mappings":"AAgBO,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,M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AAO,KACb,GAAG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,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,55 @@
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
+ * ) => Exclude<
17
+ * { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O],
18
+ * undefined
19
+ * >[]} TypedEntries
20
+ */
21
+ export const typedEntries = /** @type {TypedEntries} */ (Object.entries);
22
+
23
+ /**
24
+ * @typedef {<
25
+ * const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>,
26
+ * >(
27
+ * entries: Entries,
28
+ * ) => { [Entry in Entries[number] as Entry[0]]: Entry[1] }} FromTypedEntries
29
+ */
30
+ export const fromTypedEntries = /** @type {FromTypedEntries} */ (
31
+ Object.fromEntries
32
+ );
33
+
34
+ /**
35
+ * @typedef {<A extends unknown[], V>(
36
+ * arr: A,
37
+ * mapper: <K extends number>(el: A[K], idx: K, arr: A) => V,
38
+ * ) => V[]} TypedMap
39
+ */
40
+ export const typedMap = /** @type {TypedMap} */ (
41
+ Function.prototype.call.bind(Array.prototype.map)
42
+ );
43
+
44
+ export const logLevels = /** @type {const} */ ([
45
+ 'debug',
46
+ 'log',
47
+ 'info',
48
+ 'warn',
49
+ 'error',
50
+ ]);
51
+ Object.freeze(logLevels);
52
+
53
+ /** @typedef {(typeof logLevels)[keyof logLevels & number]} LogLevel */
54
+
55
+ /** @typedef {Pick<Console, LogLevel>} LimitedConsole */
56
+
8
57
  /**
9
58
  * Deep-copy a value by round-tripping it through JSON (which drops
10
59
  * function/symbol/undefined values and properties that are non-enumerable
@@ -17,11 +66,14 @@
17
66
  export const deepCopyJsonable = value => JSON.parse(JSON.stringify(value));
18
67
 
19
68
  /**
20
- * @param {any} value
21
- * @param {string | undefined} name
22
- * @param {object | undefined} container
23
- * @param {(value: any, name: string, record: object) => any} mapper
24
- * @returns {any}
69
+ * @template {Record<PropertyKey, unknown>} O
70
+ * @template {string & keyof O} K
71
+ * @template M
72
+ * @param {O[K]} value
73
+ * @param {K | undefined} name
74
+ * @param {O | undefined} container
75
+ * @param {(value: O[K], name: string, record: O) => O[K] | M} mapper
76
+ * @returns {O[K] | M | { [K2 in keyof O[K]]: O[K][K2] | M }}
25
77
  */
26
78
  const deepMapObjectInternal = (value, name, container, mapper) => {
27
79
  if (container && typeof name === 'string') {
@@ -36,18 +88,30 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
36
88
  }
37
89
 
38
90
  let wasMapped = false;
39
- const mappedEntries = Object.entries(value).map(([innerName, innerValue]) => {
91
+ const valueObj = /** @type {Record<string, unknown>} */ (value);
92
+ /**
93
+ * @type {<T extends typeof value, K2 extends string & keyof T>(
94
+ * entry: [K2, T[K2]],
95
+ * ) => [K2, T[K2] | M]}
96
+ */
97
+ const mapEntry = ([innerName, innerValue]) => {
40
98
  const mappedInnerValue = deepMapObjectInternal(
41
99
  innerValue,
42
100
  innerName,
43
- value,
101
+ valueObj,
44
102
  mapper,
45
103
  );
46
104
  wasMapped ||= mappedInnerValue !== innerValue;
47
- return [innerName, mappedInnerValue];
48
- });
105
+ return [innerName, /** @type {any} */ (mappedInnerValue)];
106
+ };
107
+ const mappedEntries = typedEntries(valueObj).map(mapEntry);
108
+
109
+ if (!wasMapped) {
110
+ return value;
111
+ }
49
112
 
50
- return wasMapped ? Object.fromEntries(mappedEntries) : value;
113
+ const mappedObj = fromTypedEntries(mappedEntries);
114
+ return /** @type {any} */ (mappedObj);
51
115
  };
52
116
 
53
117
  /**
@@ -59,12 +123,98 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
59
123
  * When the property value is an object, it is sent to the mapper like any other
60
124
  * value, and then recursively traversed unless replaced with a distinct value.
61
125
  *
62
- * @param {object} obj
63
- * @param {(value: any, name: string, record: object) => any} mapper
64
- * @returns {object}
126
+ * @template {Record<string, unknown>} O
127
+ * @template M
128
+ * @param {O} obj
129
+ * @param {<T extends Record<string, unknown>, K extends string & keyof T>(
130
+ * value: T[K],
131
+ * name: K,
132
+ * record: T,
133
+ * ) => T[K] | M} mapper
134
+ * @returns {O | { [K in keyof O]: K extends string ? O[K] | M : never }}
65
135
  */
66
136
  export const deepMapObject = (obj, mapper) =>
67
- deepMapObjectInternal(obj, undefined, undefined, mapper);
137
+ /** @type {any} */ (deepMapObjectInternal(obj, undefined, undefined, mapper));
138
+
139
+ /**
140
+ * Explicitly set a function's name, supporting use of arrow functions for which
141
+ * source text doesn't include a name and no initial name is set by
142
+ * NamedEvaluation
143
+ * https://tc39.es/ecma262/multipage/syntax-directed-operations.html#sec-runtime-semantics-namedevaluation
144
+ *
145
+ * `name` is the first parameter for better readability at call sites (e.g.,
146
+ * `return defineName('foo', () => { ... })`).
147
+ *
148
+ * @template {Function} F
149
+ * @param {string} name
150
+ * @param {F} fn
151
+ * @returns {F}
152
+ */
153
+ export const defineName = (name, fn) =>
154
+ defineProperty(fn, 'name', { value: name });
155
+
156
+ /**
157
+ * By analogy with how `Array.prototype.map` will map the elements of an array
158
+ * to transformed elements of an array of the same shape, `objectMapMutable`
159
+ * will do likewise for the enumerable string-keyed properties of an object.
160
+ *
161
+ * Unlike endo's `objectMap`, this function returns a non-hardened object.
162
+ *
163
+ * @template {Record<string, unknown>} O
164
+ * @template M
165
+ * @param {O} obj
166
+ * @param {<K extends keyof O>(value: O[K], key: K) => M} mapper
167
+ * @returns {{ [K in keyof O]: K extends string ? M : never }}
168
+ */
169
+ export const objectMapMutable = (obj, mapper) => {
170
+ const oldEntries = typedEntries(obj);
171
+ /** @type {<K extends keyof O>(entry: [K, O[K]]) => [K, M]} */
172
+ const mapEntry = ([k, v]) => [k, mapper(v, k)];
173
+ const newEntries = typedMap(oldEntries, mapEntry);
174
+ const newObj = fromTypedEntries(newEntries);
175
+ return /** @type {any} */ (newObj);
176
+ };
177
+
178
+ /**
179
+ * Map the elements of an array to new values, skipping elements for which the
180
+ * mapping results in either `undefined` or `false`.
181
+ *
182
+ * @template T
183
+ * @template U
184
+ * @param {T[]} arr
185
+ * @param {(value: T, index: number, arr: T[]) => U | undefined | false} mapOrDrop
186
+ * @returns {U[]}
187
+ */
188
+ export const partialMap = (arr, mapOrDrop) =>
189
+ arr.reduce((results, el, i, arrArg) => {
190
+ const result = mapOrDrop(el, i, arrArg);
191
+ if (result !== undefined && result !== false) {
192
+ results.push(result);
193
+ }
194
+ return results;
195
+ }, /** @type {U[]} */ ([]));
196
+
197
+ /**
198
+ * Return the value from `map` associated with `key`. If there is not yet such a
199
+ * value, get one from `makeValue(key)` and update `map` before returning the
200
+ * new value.
201
+ *
202
+ * @template K
203
+ * @template V
204
+ * @param {K extends WeakKey ? WeakMap<K, V> : Map<K, V>} map
205
+ * @param {K} key
206
+ * @param {(key: K) => V} makeValue
207
+ * @returns {V}
208
+ */
209
+ export const provideLazyMap = (map, key, makeValue) => {
210
+ const found = map.get(key);
211
+ if (found !== undefined || map.has(key)) {
212
+ return /** @type {V} */ (found);
213
+ }
214
+ const value = makeValue(key);
215
+ map.set(key, value);
216
+ return value;
217
+ };
68
218
 
69
219
  /**
70
220
  * Returns a function that uses a millisecond-based current-time capability
@@ -87,3 +237,23 @@ export const makeMeasureSeconds = currentTimeMillisec => {
87
237
  };
88
238
  return measureSeconds;
89
239
  };
240
+
241
+ /**
242
+ * Find all of an object's properties whose name starts with a prefix, and
243
+ * return a new object consisting of those properties without that prefix.
244
+ * Useful for filtering environment variables relevant to a particular purpose.
245
+ *
246
+ * @template {string} P
247
+ * @template {string} K
248
+ * @template V
249
+ * @param {Record<`${P}${K}`, V>} obj
250
+ * @param {P} prefix
251
+ */
252
+ export const unprefixedProperties = (obj, prefix) =>
253
+ /** @type {Record<K, V>} */ (
254
+ fromTypedEntries(
255
+ typedEntries(obj)
256
+ .filter(([key]) => key.startsWith(prefix))
257
+ .map(([key, value]) => [key.slice(prefix.length), value]),
258
+ )
259
+ );
@@ -13,23 +13,12 @@
13
13
  */
14
14
  export function makeChainStorageRoot(handleStorageMessage: (message: StorageMessage) => any, rootPath: string, rootOptions?: {
15
15
  sequence?: boolean | undefined;
16
- } | undefined): import("@endo/exo").Guarded<{
16
+ }): import("@endo/exo").Guarded<{
17
17
  getPath(): string;
18
- /**
19
- * @deprecated use getPath
20
- * @type {() => Promise<VStorageKey>}
21
- */
22
18
  getStoreKey(): Promise<VStorageKey>;
23
- /**
24
- * @type {(
25
- * name: string,
26
- * childNodeOptions?: { sequence?: boolean },
27
- * ) => StorageNode}
28
- */
29
19
  makeChildNode(name: string, childNodeOptions?: {
30
20
  sequence?: boolean;
31
21
  }): StorageNode;
32
- /** @type {(value: string) => Promise<void>} */
33
22
  setValue(value: string): Promise<void>;
34
23
  }>;
35
24
  /**
@@ -37,38 +26,54 @@ export function makeChainStorageRoot(handleStorageMessage: (message: StorageMess
37
26
  * falling back to an inert object with the correct interface (but incomplete
38
27
  * behavior) when that is unavailable.
39
28
  *
40
- * @param {ERef<StorageNode?>} storageNodeRef
29
+ * @param {ERef<Remote<StorageNode> | null>} storageNodeRef
41
30
  * @param {string} childName
42
- * @returns {Promise<StorageNode>}
31
+ * @returns {Promise<Remote<StorageNode>>}
32
+ */
33
+ export function makeStorageNodeChild(storageNodeRef: ERef<Remote<StorageNode> | null>, childName: string): Promise<Remote<StorageNode>>;
34
+ /**
35
+ * @import {ERef} from '@endo/far';
36
+ * @import {Marshal, Passable} from '@endo/marshal';
37
+ * @import {Remote, ERemote, TypedPattern} from './types.js';
38
+ * @import {EMarshaller} from './marshal/wrap-marshaller.js';
39
+ * @import {Zone} from '@agoric/base-zone';
40
+ * @import {Callback} from './types.js';
41
+ */
42
+ /** @typedef {Marshal<unknown>} Marshaller */
43
+ /** @typedef {Pick<Marshaller, 'fromCapData'>} Unserializer */
44
+ /**
45
+ * Defined by vstorageStoreKey in vstorage.go
46
+ *
47
+ * @typedef VStorageKey
48
+ * @property {string} storeName
49
+ * @property {string} storeSubkey
50
+ * @property {string} dataPrefixBytes
51
+ * @property {string} [noDataValue]
52
+ */
53
+ /**
54
+ * @template [T=unknown]
55
+ * @typedef StreamCell
56
+ * @property {string} blockHeight corresponding with the write of `values`
57
+ * (decimal representation of a natural number)
58
+ * @property {T[]} values
43
59
  */
44
- export function makeStorageNodeChild(storageNodeRef: ERef<StorageNode | null>, childName: string): Promise<StorageNode>;
60
+ /** @type {TypedPattern<StreamCell>} */
61
+ export const StreamCellShape: TypedPattern<StreamCell>;
45
62
  export function isStreamCell(cell: any): cell is StreamCell;
46
- export function assertCapData(data: unknown): asserts data is import("@endo/marshal").CapData<string>;
47
63
  /** @type {(name: string) => void} */
48
64
  export const assertPathSegment: (name: string) => void;
49
- export function prepareChainStorageNode(zone: import("@agoric/base-zone").Zone): (messenger: import("./types.js").Callback<(message: StorageMessage) => any>, path: string, args_2?: {
65
+ export function prepareChainStorageNode(zone: Zone): (messenger: Callback<(message: StorageMessage) => any>, path: string, args_2?: {
50
66
  sequence?: boolean | undefined;
51
67
  } | undefined) => import("@endo/exo").Guarded<{
52
68
  getPath(): string;
53
- /**
54
- * @deprecated use getPath
55
- * @type {() => Promise<VStorageKey>}
56
- */
57
69
  getStoreKey(): Promise<VStorageKey>;
58
- /**
59
- * @type {(
60
- * name: string,
61
- * childNodeOptions?: { sequence?: boolean },
62
- * ) => StorageNode}
63
- */
64
70
  makeChildNode(name: string, childNodeOptions?: {
65
71
  sequence?: boolean;
66
72
  }): StorageNode;
67
- /** @type {(value: string) => Promise<void>} */
68
73
  setValue(value: string): Promise<void>;
69
74
  }>;
70
- export function makeSerializeToStorage(storageNode: ERef<StorageNode>, marshaller: ERef<Marshaller>): (value: PassableCap) => Promise<void>;
71
- export type Marshaller = ReturnType<typeof import("@endo/marshal").makeMarshal>;
75
+ export function makeSerializeToStorage(storageNode: ERemote<StorageNode>, marshaller: ERemote<EMarshaller>): (value: Passable) => Promise<void>;
76
+ export type Marshaller = Marshal<unknown>;
72
77
  export type Unserializer = Pick<Marshaller, "fromCapData">;
73
78
  /**
74
79
  * Defined by vstorageStoreKey in vstorage.go
@@ -81,7 +86,8 @@ export type VStorageKey = {
81
86
  };
82
87
  export type StreamCell<T = unknown> = {
83
88
  /**
84
- * decimal representation of a natural number
89
+ * corresponding with the write of `values`
90
+ * (decimal representation of a natural number)
85
91
  */
86
92
  blockHeight: string;
87
93
  values: T[];
@@ -164,6 +170,13 @@ export type StorageMessage = {
164
170
  method: StorageUpdateEntriesMessageMethod;
165
171
  args: StorageUpdateEntriesMessageArgs;
166
172
  };
173
+ import type { Remote } from './types.js';
167
174
  import type { ERef } from '@endo/far';
168
- import type { PassableCap } from '@endo/marshal';
175
+ import type { TypedPattern } from './types.js';
176
+ import type { Zone } from '@agoric/base-zone';
177
+ import type { Callback } from './types.js';
178
+ import type { ERemote } from './types.js';
179
+ import type { EMarshaller } from './marshal/wrap-marshaller.js';
180
+ import type { Passable } from '@endo/marshal';
181
+ import type { Marshal } from '@endo/marshal';
169
182
  //# sourceMappingURL=lib-chainStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"AAyPA;;;;;;;;;;;;GAYG;AACH,2DATW,CAA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