@agoric/internal 0.4.0 → 0.4.1-upgrade-23-dev-bd79330.0.bd79330

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 (131) hide show
  1. package/README.md +1 -4
  2. package/package.json +13 -11
  3. package/src/action-types.d.ts +47 -20
  4. package/src/action-types.d.ts.map +1 -1
  5. package/src/action-types.js +19 -19
  6. package/src/ava-force-exit.d.mts +2 -0
  7. package/src/ava-force-exit.d.mts.map +1 -0
  8. package/src/ava-force-exit.mjs +6 -0
  9. package/src/batched-deliver.d.ts +6 -2
  10. package/src/batched-deliver.d.ts.map +1 -1
  11. package/src/batched-deliver.js +7 -3
  12. package/src/build-cache-types.d.ts +33 -0
  13. package/src/build-cache-types.d.ts.map +1 -0
  14. package/src/build-cache-types.js +42 -0
  15. package/src/build-cache.d.ts +12 -0
  16. package/src/build-cache.d.ts.map +1 -0
  17. package/src/build-cache.js +184 -0
  18. package/src/callback.d.ts +9 -11
  19. package/src/callback.d.ts.map +1 -1
  20. package/src/callback.js +16 -10
  21. package/src/chain-storage-paths.d.ts.map +1 -1
  22. package/src/chain-storage-paths.js +0 -2
  23. package/src/chain-utils.d.ts +3 -1
  24. package/src/chain-utils.d.ts.map +1 -1
  25. package/src/chain-utils.js +6 -1
  26. package/src/config.d.ts +22 -3
  27. package/src/config.d.ts.map +1 -1
  28. package/src/config.js +25 -3
  29. package/src/debug.d.ts +4 -1
  30. package/src/debug.d.ts.map +1 -1
  31. package/src/debug.js +26 -15
  32. package/src/index.d.ts +2 -1
  33. package/src/index.js +10 -3
  34. package/src/js-utils.d.ts +7 -3
  35. package/src/js-utils.d.ts.map +1 -1
  36. package/src/js-utils.js +24 -3
  37. package/src/keyMirror.d.ts +3 -0
  38. package/src/keyMirror.d.ts.map +1 -0
  39. package/src/keyMirror.js +45 -0
  40. package/src/kv-store.d.ts +33 -0
  41. package/src/kv-store.d.ts.map +1 -0
  42. package/src/kv-store.js +257 -0
  43. package/src/lib-chainStorage.d.ts +23 -12
  44. package/src/lib-chainStorage.d.ts.map +1 -1
  45. package/src/lib-chainStorage.js +18 -18
  46. package/src/lib-nodejs/ava-unhandled-rejection.d.ts +18 -3
  47. package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -1
  48. package/src/lib-nodejs/ava-unhandled-rejection.js +211 -20
  49. package/src/lib-nodejs/engine-gc.js +2 -2
  50. package/src/lib-nodejs/spawnSubprocessWorker.d.ts +0 -2
  51. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
  52. package/src/lib-nodejs/spawnSubprocessWorker.js +8 -7
  53. package/src/lib-nodejs/waitUntilQuiescent.d.ts +3 -0
  54. package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -1
  55. package/src/lib-nodejs/waitUntilQuiescent.js +5 -1
  56. package/src/lib-nodejs/worker-protocol.d.ts +1 -1
  57. package/src/lib-nodejs/worker-protocol.d.ts.map +1 -1
  58. package/src/lib-nodejs/worker-protocol.js +5 -5
  59. package/src/magic-cookie-test-only.d.ts.map +1 -1
  60. package/src/magic-cookie-test-only.js +0 -2
  61. package/src/marshal/board-client-utils.d.ts +19 -0
  62. package/src/marshal/board-client-utils.d.ts.map +1 -0
  63. package/src/{marshal.js → marshal/board-client-utils.js} +27 -52
  64. package/src/marshal/cap-data.d.ts +11 -0
  65. package/src/marshal/cap-data.d.ts.map +1 -0
  66. package/src/marshal/cap-data.js +19 -0
  67. package/src/marshal/inaccessible-val.d.ts +2 -0
  68. package/src/marshal/inaccessible-val.d.ts.map +1 -0
  69. package/src/marshal/inaccessible-val.js +15 -0
  70. package/src/marshal/pure-data.d.ts +8 -0
  71. package/src/marshal/pure-data.d.ts.map +1 -0
  72. package/src/marshal/pure-data.js +14 -0
  73. package/src/marshal/wrap-marshaller.d.ts +60 -0
  74. package/src/marshal/wrap-marshaller.d.ts.map +1 -0
  75. package/src/marshal/wrap-marshaller.js +432 -0
  76. package/src/module-utils.d.ts +1 -0
  77. package/src/module-utils.d.ts.map +1 -1
  78. package/src/module-utils.js +16 -0
  79. package/src/natural-sort.d.ts.map +1 -1
  80. package/src/natural-sort.js +48 -13
  81. package/src/netstring.d.ts +1 -1
  82. package/src/netstring.d.ts.map +1 -1
  83. package/src/netstring.js +5 -5
  84. package/src/node/buffer-line-transform.d.ts +10 -5
  85. package/src/node/buffer-line-transform.d.ts.map +1 -1
  86. package/src/node/buffer-line-transform.js +8 -4
  87. package/src/node/createBundles.d.ts.map +1 -1
  88. package/src/node/createBundles.js +3 -5
  89. package/src/node/fs-stream.d.ts +4 -1
  90. package/src/node/fs-stream.d.ts.map +1 -1
  91. package/src/node/fs-stream.js +58 -9
  92. package/src/node/read-json.d.ts +2 -0
  93. package/src/node/read-json.d.ts.map +1 -0
  94. package/src/node/read-json.js +18 -0
  95. package/src/node/shutdown.js +1 -1
  96. package/src/priority-senders.d.ts +2 -1
  97. package/src/priority-senders.d.ts.map +1 -1
  98. package/src/priority-senders.js +6 -4
  99. package/src/queue.d.ts.map +1 -1
  100. package/src/queue.js +0 -2
  101. package/src/ses-utils.d.ts +27 -5
  102. package/src/ses-utils.d.ts.map +1 -1
  103. package/src/ses-utils.js +115 -20
  104. package/src/storage-test-utils.d.ts +15 -5
  105. package/src/storage-test-utils.d.ts.map +1 -1
  106. package/src/storage-test-utils.js +62 -8
  107. package/src/tagged.d.ts +18 -1
  108. package/src/testing-utils.d.ts +4 -0
  109. package/src/testing-utils.d.ts.map +1 -1
  110. package/src/testing-utils.js +88 -2
  111. package/src/typeGuards.d.ts +6 -2
  112. package/src/typeGuards.d.ts.map +1 -1
  113. package/src/typeGuards.js +7 -4
  114. package/src/types-index.d.ts +1 -0
  115. package/src/types.d.ts +34 -19
  116. package/src/types.d.ts.map +1 -1
  117. package/src/types.js +173 -0
  118. package/src/upgrade-api.d.ts.map +1 -1
  119. package/src/upgrade-api.js +4 -3
  120. package/src/work-pool.d.ts +13 -0
  121. package/src/work-pool.d.ts.map +1 -0
  122. package/src/work-pool.js +233 -0
  123. package/vendor/anylogger.d.ts +98 -0
  124. package/vendor/anylogger.d.ts.map +1 -0
  125. package/vendor/anylogger.js +60 -0
  126. package/vendor/anylogger.ts +160 -0
  127. package/vendor/tsconfig.anylogger.json +15 -0
  128. package/exported.js +0 -2
  129. package/src/marshal.d.ts +0 -33
  130. package/src/marshal.d.ts.map +0 -1
  131. package/src/types.ts +0 -129
package/src/callback.js CHANGED
@@ -4,7 +4,14 @@ import { E } from '@endo/far';
4
4
  import { isPrimitive, isPassableSymbol } from '@endo/pass-style';
5
5
  import { getInterfaceMethodKeys } from '@endo/patterns';
6
6
 
7
- /** @import {ERef} from '@endo/far' */
7
+ /**
8
+ * @import {ERef} from '@endo/far'
9
+ * @import {Methods} from '@endo/exo';
10
+ * @import {Farable} from '@endo/exo';
11
+ * @import {Zone} from '@agoric/base-zone';
12
+ * @import {InterfaceGuard} from '@endo/patterns';
13
+ * @import {MethodGuard} from '@endo/patterns';
14
+ */
8
15
  /** @import {Callback, SyncCallback} from './types.js' */
9
16
 
10
17
  const { fromEntries } = Object;
@@ -16,10 +23,10 @@ const ownKeys =
16
23
  );
17
24
 
18
25
  /**
19
- * @template {import('@endo/exo').Methods} T
26
+ * @template {Methods} T
20
27
  * @typedef {(
21
- * ...args: Parameters<ReturnType<prepareAttenuator>>
22
- * ) => import('@endo/exo').Farable<T>} MakeAttenuator
28
+ * ...args: Parameters<ReturnType<typeof prepareAttenuator>>
29
+ * ) => Farable<T>} MakeAttenuator
23
30
  */
24
31
 
25
32
  /**
@@ -185,12 +192,11 @@ harden(isCallback);
185
192
  * Prepare an attenuator class whose methods can be redirected via callbacks.
186
193
  *
187
194
  * @template {PropertyKey} M
188
- * @param {import('@agoric/base-zone').Zone} zone The zone in which to allocate
189
- * attenuators.
195
+ * @param {Zone} zone The zone in which to allocate attenuators.
190
196
  * @param {M[]} methodNames Methods to forward.
191
197
  * @param {object} opts
192
- * @param {import('@endo/patterns').InterfaceGuard<{
193
- * [K in M]: import('@endo/patterns').MethodGuard;
198
+ * @param {InterfaceGuard<{
199
+ * [K in M]: MethodGuard;
194
200
  * }>} [opts.interfaceGuard]
195
201
  * An interface guard for the new attenuator.
196
202
  * @param {string} [opts.tag] A tag for the new attenuator exoClass.
@@ -299,8 +305,8 @@ harden(prepareAttenuator);
299
305
  /**
300
306
  * Prepare an attenuator whose methodNames are derived from the interfaceGuard.
301
307
  *
302
- * @template {import('@endo/patterns').InterfaceGuard} G
303
- * @param {import('@agoric/base-zone').Zone} zone
308
+ * @template {InterfaceGuard} G
309
+ * @param {Zone} zone
304
310
  * @param {G} interfaceGuard
305
311
  * @param {object} [opts]
306
312
  * @param {string} [opts.tag]
@@ -1 +1 @@
1
- {"version":3,"file":"chain-storage-paths.d.ts","sourceRoot":"","sources":["chain-storage-paths.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,2BAA4B,aAAa,CAAC;AAC1C,kCAAmC,mBAAmB,CAAC;AACvD,oCAAqC,qBAAqB,CAAC;AAC3D,yBAA0B,YAAY,CAAC;AACvC,qBAAsB,QAAQ,CAAC;AAC/B,sBAAuB,SAAS,CAAC;AACjC,sBAAuB,SAAS,CAAC;AACjC,qBAAsB,WAAW,CAAC;AAClC,0BAA2B,YAAY,CAAC"}
1
+ {"version":3,"file":"chain-storage-paths.d.ts","sourceRoot":"","sources":["chain-storage-paths.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,2BAA4B,aAAa,CAAC;AAC1C,kCAAmC,mBAAmB,CAAC;AACvD,oCAAqC,qBAAqB,CAAC;AAC3D,yBAA0B,YAAY,CAAC;AACvC,qBAAsB,QAAQ,CAAC;AAC/B,sBAAuB,SAAS,CAAC;AACjC,sBAAuB,SAAS,CAAC;AACjC,qBAAsB,WAAW,CAAC;AAClC,0BAA2B,YAAY,CAAC"}
@@ -1,5 +1,3 @@
1
- // @jessie-check
2
-
3
1
  /**
4
2
  * These identify top-level paths for SwingSet chain storage (and serve as
5
3
  * prefixes). To avoid collisions, they should remain synchronized with
@@ -6,7 +6,7 @@ export type BlockInfo = {
6
6
  * POSIX Seconds Since the Epoch
7
7
  */
8
8
  blockTime: number;
9
- params: import("@agoric/cosmic-proto/swingset/swingset.js").ParamsSDKType;
9
+ params: JsonSafe<ParamsSDKType>;
10
10
  };
11
11
  /**
12
12
  * cosmosInitAction fields that are subject to consensus. See cosmosInitAction
@@ -21,5 +21,7 @@ export type InitMsg = BlockInfo & {
21
21
  amount: NatString;
22
22
  }[];
23
23
  };
24
+ import type { ParamsSDKType } from '@agoric/cosmic-proto/swingset/swingset.js';
25
+ import type { JsonSafe } from '@agoric/cosmic-proto/json-safe';
24
26
  import * as _ActionType from './action-types.js';
25
27
  //# sourceMappingURL=chain-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain-utils.d.ts","sourceRoot":"","sources":["chain-utils.js"],"names":[],"mappings":"AAsCO,wCAHI,GAAG,GACD,OAAO,CAoBnB;wBA1Ca,GAAG,MAAM,EAAE;;iBAIX,MAAM;;;;eACN,MAAM;YACN,OAAO,2CAA2C,EAAE,aAAa;;;;;;sBAIlE,SAAS,GAAG;IACpB,IAAI,EAAE,OAAO,WAAW,CAAC,cAAc,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACrD;6BAjByB,mBAAmB"}
1
+ {"version":3,"file":"chain-utils.d.ts","sourceRoot":"","sources":["chain-utils.js"],"names":[],"mappings":"AA2CO,wCAHI,GAAG,GACD,OAAO,CAoBnB;wBA/Ca,GAAG,MAAM,EAAE;;iBASX,MAAM;;;;eACN,MAAM;YACN,SAAS,aAAa,CAAC;;;;;;sBAIxB,SAAS,GAAG;IACpB,IAAI,EAAE,OAAO,WAAW,CAAC,cAAc,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACrD;mCAjB4B,2CAA2C;8BAChD,gCAAgC;6BAN9B,mBAAmB"}
@@ -14,11 +14,16 @@ import * as _ActionType from './action-types.js';
14
14
 
15
15
  /** @typedef {`${bigint}`} NatString */
16
16
 
17
+ /**
18
+ * @import {ParamsSDKType} from '@agoric/cosmic-proto/swingset/swingset.js'
19
+ * @import {JsonSafe} from '@agoric/cosmic-proto/json-safe'
20
+ */
21
+
17
22
  /**
18
23
  * @typedef {object} BlockInfo
19
24
  * @property {number} blockHeight
20
25
  * @property {number} blockTime POSIX Seconds Since the Epoch
21
- * @property {import('@agoric/cosmic-proto/swingset/swingset.js').ParamsSDKType} params
26
+ * @property {JsonSafe<ParamsSDKType>} params
22
27
  */
23
28
 
24
29
  /**
package/src/config.d.ts CHANGED
@@ -17,9 +17,9 @@ export namespace CosmosInitKeyToBridgeId {
17
17
  let vbankPort: "bank";
18
18
  let vibcPort: "dibc";
19
19
  }
20
- export namespace WalletName {
21
- let depositFacet: "depositFacet";
22
- }
20
+ export const WalletName: import("./keyMirror.js").KeyMirrorResult<{
21
+ depositFacet: null;
22
+ }>;
23
23
  export namespace VBankAccount {
24
24
  namespace reserve {
25
25
  let module: "vbank/reserve";
@@ -32,4 +32,23 @@ export namespace VBankAccount {
32
32
  export { address_1 as address };
33
33
  }
34
34
  }
35
+ /**
36
+ * ClusterName specifies a collection of networks. The specific networks
37
+ * associated with a particular name may vary from context to context, and may
38
+ * also overlap (e.g. a "local" cluster may connect to the same remote networks
39
+ * as a "testnet" cluster), but this type nevertheless supports cross-package
40
+ * coordination where the values associated with static labels are subject to
41
+ * choice of cluster. Some examples:
42
+ *
43
+ * - the chain ID for a static label like "Agoric" or "Ethereum"
44
+ * - the cryptographic hash for a static label like "BLD" or "USDC"
45
+ * - the URL for a service like "Agoric RPC" or "Axelar" or "Spectrum"
46
+ *
47
+ * "mainnet" should always include the Agoric network described by
48
+ * https://main.agoric.net/network-config rather than some other alternative.
49
+ *
50
+ * XXX This actually belongs somewhere else, possibly with refactoring.
51
+ * https://github.com/Agoric/agoric-sdk/pull/12185#discussion_r2500123226
52
+ */
53
+ export type ClusterName = "local" | "testnet" | "mainnet";
35
54
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":";;;uBAkBU,CAAC,OAAO,QAAQ,EAAE,MAAM,OAAO,QAAQ,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":";;;uBAwCU,CAAC,OAAO,QAAQ,EAAE,MAAM,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;AAsBlD;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA9BU,OAAO,GAAG,SAAS,GAAG,SAAS"}
package/src/config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // @ts-check
2
- // @jessie-check
2
+
3
+ import { keyMirror } from './keyMirror.js';
3
4
 
4
5
  /**
5
6
  * @file
@@ -13,6 +14,27 @@
13
14
  * package are placed here.
14
15
  */
15
16
 
17
+ /**
18
+ * ClusterName specifies a collection of networks. The specific networks
19
+ * associated with a particular name may vary from context to context, and may
20
+ * also overlap (e.g. a "local" cluster may connect to the same remote networks
21
+ * as a "testnet" cluster), but this type nevertheless supports cross-package
22
+ * coordination where the values associated with static labels are subject to
23
+ * choice of cluster. Some examples:
24
+ *
25
+ * - the chain ID for a static label like "Agoric" or "Ethereum"
26
+ * - the cryptographic hash for a static label like "BLD" or "USDC"
27
+ * - the URL for a service like "Agoric RPC" or "Axelar" or "Spectrum"
28
+ *
29
+ * "mainnet" should always include the Agoric network described by
30
+ * https://main.agoric.net/network-config rather than some other alternative.
31
+ *
32
+ * XXX This actually belongs somewhere else, possibly with refactoring.
33
+ * https://github.com/Agoric/agoric-sdk/pull/12185#discussion_r2500123226
34
+ *
35
+ * @typedef {'local' | 'testnet' | 'mainnet'} ClusterName
36
+ */
37
+
16
38
  /**
17
39
  * Event source ids used by the bridge device.
18
40
  *
@@ -38,8 +60,8 @@ export const CosmosInitKeyToBridgeId = {
38
60
  };
39
61
  harden(CosmosInitKeyToBridgeId);
40
62
 
41
- export const WalletName = /** @type {const} */ ({
42
- depositFacet: 'depositFacet',
63
+ export const WalletName = keyMirror({
64
+ depositFacet: null,
43
65
  });
44
66
  harden(WalletName);
45
67
 
package/src/debug.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export function makeTracer(name: string, enable?: boolean | "verbose"): (..._args: any[]) => void;
1
+ export function makeTracer(label: string, enable?: boolean | "verbose"): ((..._args: any[]) => void) & {
2
+ sub: (subLabel: any, subEnable?: boolean | "verbose") => ((..._args: any[]) => void) & /*elided*/ any;
3
+ };
4
+ export type TraceLogger = ReturnType<typeof makeTracer>;
2
5
  //# sourceMappingURL=debug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.js"],"names":[],"mappings":"AAQO,iCAHI,MAAM,WACN,OAAO,GAAG,SAAS,6BAiC7B"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.js"],"names":[],"mappings":"AAQO,kCAHI,MAAM,WACN,OAAO,GAAG,SAAS;;EAwC7B;0BAIY,UAAU,CAAC,OAAO,UAAU,CAAC"}
package/src/debug.js CHANGED
@@ -1,41 +1,52 @@
1
- // @jessie-check
2
-
1
+ // See https://github.com/Agoric/agoric-sdk/issues/11844
2
+ // See https://github.com/Agoric/agoric-sdk/issues/11845
3
3
  let debugInstance = 1;
4
4
 
5
5
  /**
6
- * @param {string} name
6
+ * @param {string} label
7
7
  * @param {boolean | 'verbose'} enable
8
8
  */
9
- export const makeTracer = (name, enable = true) => {
9
+ export const makeTracer = (label, enable = true) => {
10
+ const sub = (subLabel, subEnable = enable) =>
11
+ makeTracer(`${label}.${subLabel}`, subEnable);
12
+ const key = `----- ${label},${debugInstance} `;
10
13
  debugInstance += 1;
11
- let debugCount = 1;
12
- const key = `----- ${name}.${debugInstance} `;
13
14
  // the cases below define a named variable to provide better debug info
14
15
  switch (enable) {
15
16
  case false: {
16
17
  const logDisabled = (..._args) => {};
17
- return logDisabled;
18
+ return harden(Object.assign(logDisabled, { sub }));
18
19
  }
19
20
  case 'verbose': {
20
21
  const infoTick = (optLog, ...args) => {
21
- if (optLog.log) {
22
- console.info(key, (debugCount += 1), ...args);
22
+ // XXX Sniff tests such as this are inherently unreliable and smell bad.
23
+ // Even aside from the security hazard of
24
+ // https://github.com/Agoric/agoric-sdk/issues/11845
25
+ // an object intended as a normal logging argument may accidentally
26
+ // pass this sniff test, causing confusion.
27
+ if (typeof optLog?.log === 'function') {
28
+ console.info(key, ...args);
23
29
  } else {
24
- console.info(key, (debugCount += 1), optLog, ...args);
30
+ console.info(key, optLog, ...args);
25
31
  }
26
32
  };
27
- return infoTick;
33
+ return harden(Object.assign(infoTick, { sub }));
28
34
  }
29
35
  default: {
30
36
  const debugTick = (optLog, ...args) => {
31
- if (optLog.log) {
32
- optLog.log(key, (debugCount += 1), ...args);
37
+ // Another unreliable sniff test like the one above
38
+ if (typeof optLog?.log === 'function') {
39
+ optLog.log(key, ...args);
33
40
  } else {
34
- console.info(key, (debugCount += 1), optLog, ...args);
41
+ console.info(key, optLog, ...args);
35
42
  }
36
43
  };
37
- return debugTick;
44
+ return harden(Object.assign(debugTick, { sub }));
38
45
  }
39
46
  }
40
47
  };
41
48
  harden(makeTracer);
49
+
50
+ /**
51
+ * @typedef {ReturnType<typeof makeTracer>} TraceLogger
52
+ */
package/src/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./config.js";
3
3
  export * from "./debug.js";
4
4
  export * from "./errors.js";
5
5
  export * from "./js-utils.js";
6
+ export * from "./keyMirror.js";
6
7
  export * from "./method-tools.js";
7
8
  export * from "./metrics.js";
8
9
  export * from "./natural-sort.js";
@@ -11,5 +12,5 @@ export * from "./tmpDir.js";
11
12
  export * from "./typeCheck.js";
12
13
  export * from "./typeGuards.js";
13
14
  export * from "./types-index.js";
14
- export { pureDataMarshaller } from "./marshal.js";
15
+ export { pureDataMarshaller } from "./marshal/pure-data.js";
15
16
  //# sourceMappingURL=index.d.ts.map
package/src/index.js CHANGED
@@ -1,13 +1,20 @@
1
- // @jessie-check
2
-
3
1
  /// <reference types="ses" />
4
2
 
3
+ // NOTE: Because @endo/bundle-source does not do tree-shaking (at least as of
4
+ // September 2025), bundles for sources that import from '@agoric/internal' will
5
+ // include each of these files even if none of their own exports are used.
6
+ // To keep the size of bundles down, deep imports from @agoric/internal are
7
+ // preferred.
8
+ // HOWEVER, there are still occasional imports of '@agoric/internal', so be
9
+ // judicious about what to include here!
10
+
5
11
  export * from './cli-utils.js';
6
12
  export * from './config.js';
7
13
  export * from './debug.js';
8
14
  export * from './errors.js';
9
15
  export * from './js-utils.js';
10
- export { pureDataMarshaller } from './marshal.js';
16
+ export * from './keyMirror.js';
17
+ export { pureDataMarshaller } from './marshal/pure-data.js';
11
18
  export * from './method-tools.js';
12
19
  export * from './metrics.js';
13
20
  export * from './natural-sort.js';
package/src/js-utils.d.ts CHANGED
@@ -3,7 +3,10 @@ export const TRUE: true;
3
3
  /**
4
4
  * @typedef {<O extends Record<string, unknown>>(
5
5
  * obj: O,
6
- * ) => { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O][]} TypedEntries
6
+ * ) => Exclude<
7
+ * { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O],
8
+ * undefined
9
+ * >[]} TypedEntries
7
10
  */
8
11
  export const typedEntries: TypedEntries;
9
12
  /**
@@ -26,13 +29,14 @@ export function deepCopyJsonable<T>(value: T): T;
26
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; };
27
30
  export function defineName<F extends Function>(name: string, fn: F): F;
28
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; };
29
- export function provideLazyMap<K, V>(map: K extends WeakKey ? WeakMap<K, V> : Map<K, V>, key: K, makeValue: (key: K) => V): V;
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;
30
34
  export function makeMeasureSeconds(currentTimeMillisec: () => number): <T>(fn: () => Promise<T>) => Promise<{
31
35
  result: T;
32
36
  duration: number;
33
37
  }>;
34
38
  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][];
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>[];
36
40
  export type FromTypedEntries = <const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>>(entries: Entries) => { [Entry in Entries[number] as Entry[0]]: Entry[1]; };
37
41
  export type TypedMap = <A extends unknown[], V>(arr: A, mapper: <K extends number>(el: A[K], idx: K, arr: A) => V) => V[];
38
42
  export type LogLevel = (typeof logLevels)[keyof readonly ["debug", "log", "info", "warn", "error"] & number];
@@ -1 +1 @@
1
- {"version":3,"file":"js-utils.d.ts","sourceRoot":"","sources":["js-utils.js"],"names":[],"mappings":"AASA,yEAAyE;AACzE,mBAA0C,IAAI,CAAE;AAEhD;;;;GAIG;AACH,2BAAuC,YAAY,CAAsB;AAEzE;;;;;;GAMG;AACH,+BAA2C,gBAAgB,CAEzD;AAEF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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
@@ -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.
@@ -13,7 +12,10 @@ export const TRUE = /** @type {const} */ (true);
13
12
  /**
14
13
  * @typedef {<O extends Record<string, unknown>>(
15
14
  * obj: O,
16
- * ) => { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O][]} TypedEntries
15
+ * ) => Exclude<
16
+ * { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O],
17
+ * undefined
18
+ * >[]} TypedEntries
17
19
  */
18
20
  export const typedEntries = /** @type {TypedEntries} */ (Object.entries);
19
21
 
@@ -172,6 +174,25 @@ export const objectMapMutable = (obj, mapper) => {
172
174
  return /** @type {any} */ (newObj);
173
175
  };
174
176
 
177
+ /**
178
+ * Map the elements of an array to new values, skipping elements for which the
179
+ * mapping results in either `undefined` or `false`.
180
+ *
181
+ * @template T
182
+ * @template U
183
+ * @param {T[]} arr
184
+ * @param {(value: T, index: number, arr: T[]) => U | undefined | false} mapOrDrop
185
+ * @returns {U[]}
186
+ */
187
+ export const partialMap = (arr, mapOrDrop) =>
188
+ arr.reduce((results, el, i, arrArg) => {
189
+ const result = mapOrDrop(el, i, arrArg);
190
+ if (result !== undefined && result !== false) {
191
+ results.push(result);
192
+ }
193
+ return results;
194
+ }, /** @type {U[]} */ ([]));
195
+
175
196
  /**
176
197
  * Return the value from `map` associated with `key`. If there is not yet such a
177
198
  * value, get one from `makeValue(key)` and update `map` before returning the
@@ -179,7 +200,7 @@ export const objectMapMutable = (obj, mapper) => {
179
200
  *
180
201
  * @template K
181
202
  * @template V
182
- * @param {K extends WeakKey ? WeakMap<K, V> : Map<K, V>} map
203
+ * @param {[K] extends [WeakKey] ? WeakMap<K, V> : Map<K, V>} map
183
204
  * @param {K} key
184
205
  * @param {(key: K) => V} makeValue
185
206
  * @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":"AAuBO,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,CAqBjC;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"}
@@ -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
+ *
14
+ * `@enum {(typeof MyEnum)[keyof typeof MyEnum]}`
15
+ *
16
+ * The provided record must only map property names to either `null` or the
17
+ * property name itself. The returned object has identical keys whose values are
18
+ * the string form of the key.
19
+ *
20
+ * @template {Record<string, string | null> & Record<Exclude<PropertyKey, string>, never>} Init
21
+ * @param {Init & { readonly [K in keyof Init]: Init[K] extends null ? null : K }} record
22
+ * @returns {KeyMirrorResult<Init>}
23
+ */
24
+ export const keyMirror = record => {
25
+ if (record === null || typeof record !== 'object') {
26
+ throw TypeError('keyMirror expects a record of string keys.');
27
+ }
28
+
29
+ /** @type {Record<string, string>} */
30
+ const mirrored = {
31
+ // @ts-expect-error Record confused by null prototype
32
+ __proto__: null,
33
+ };
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: any, right: any): 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;AAOM,uEAoBN;AAOM,mCAJO,CAAC,iBACJ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GACZ,OAAO,CAAC,CAAC,CAAC,CA8DtB;oBAxPa,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"}