@agoric/internal 0.3.3-dev-df9efa9.0.df9efa9 → 0.3.3-dev-1321e4f.0.1321e4f

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/internal",
3
- "version": "0.3.3-dev-df9efa9.0.df9efa9",
3
+ "version": "0.3.3-dev-1321e4f.0.1321e4f",
4
4
  "description": "Externally unsupported utilities internal to agoric-sdk",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -20,7 +20,7 @@
20
20
  "lint:types": "yarn run -T tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/base-zone": "0.1.1-dev-df9efa9.0.df9efa9",
23
+ "@agoric/base-zone": "0.1.1-dev-1321e4f.0.1321e4f",
24
24
  "@endo/cache-map": "^1.1.0",
25
25
  "@endo/common": "^1.2.13",
26
26
  "@endo/compartment-mapper": "^1.6.3",
@@ -38,7 +38,7 @@
38
38
  "jessie.js": "^0.3.4"
39
39
  },
40
40
  "devDependencies": {
41
- "@agoric/cosmic-proto": "0.4.1-dev-df9efa9.0.df9efa9",
41
+ "@agoric/cosmic-proto": "0.4.1-dev-1321e4f.0.1321e4f",
42
42
  "@endo/exo": "^1.5.12",
43
43
  "@endo/init": "^1.1.12",
44
44
  "@endo/ses-ava": "^1.3.2",
@@ -66,5 +66,5 @@
66
66
  "typeCoverage": {
67
67
  "atLeast": 93.22
68
68
  },
69
- "gitHead": "df9efa9cc6831e761d94e3cc74dfb7a9f886cdb1"
69
+ "gitHead": "1321e4f23e1d88f8f5b35ae00273a5ba6001e46b"
70
70
  }
@@ -14,7 +14,16 @@ export namespace defaultSerializer {
14
14
  let stringify: (obj: any) => string;
15
15
  }
16
16
  export const slotStringUnserialize: (capData: any) => any;
17
- export function makeFakeStorageKit(rootPath: string, rootOptions?: Parameters<typeof makeChainStorageRoot>[2]): {
17
+ export function makeAsyncQueue<T>(): {
18
+ enqueue: (data: T) => void;
19
+ iterable: {
20
+ [Symbol.asyncIterator](): AsyncGenerator<Awaited<T> | undefined, void, unknown>;
21
+ };
22
+ cancel: () => boolean;
23
+ };
24
+ export function makeFakeStorageKit(rootPath: string, rootOptions?: Parameters<typeof makeChainStorageRoot>[2], { eachMessage }?: {
25
+ eachMessage?: (m: StorageMessage) => void;
26
+ }): {
18
27
  rootNode: import("@endo/exo").Guarded<{
19
28
  getPath(): string;
20
29
  getStoreKey(): Promise<VStorageKey>;
@@ -60,7 +69,7 @@ export type MockChainStorageRootMethods = {
60
69
  };
61
70
  export type MockChainStorageRoot = StorageNode & MockChainStorageRootMethods;
62
71
  import { makeChainStorageRoot } from './lib-chainStorage.js';
63
- import type { StorageNode } from './lib-chainStorage.js';
64
72
  import type { StorageMessage } from './lib-chainStorage.js';
73
+ import type { StorageNode } from './lib-chainStorage.js';
65
74
  import type { Marshaller } from './lib-chainStorage.js';
66
75
  //# sourceMappingURL=storage-test-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAyBO,yCAHI,MAAM,UACN,MAAM,6GAGC;AAElB;;;GAGG;AACH;;;;;EAEG;;eAMU,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO;mBAEzB,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM;;AA8CjC,8CAtBuB,GAAG,KAAK,GAAG,CAsB+B;AAU1D,6CAHI,MAAM,gBACN,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC;;;;;oBAyFvC,CAAC;;;;UAsDM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;;sBAd3B,MAAM,KACJ,MAAM,EAAE;;0BA9FP,cAAc;;;8IAAd,cAAc;;;;EAiH7B;AAoBM,4CADO,oBAAoB,CA6BjC;AAUM,yCAPI,OAAO,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,WACvC,oBAAo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O,oBAAoB,CA6BjC;AAUM,yCAPI,OAAO,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,WACvC,oBAAoB,GAAG,cAAc,QACrC,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9D,CAAK;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,EAAE,CAAC,GAAG;IAChD,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,iBAkDL;6BAxGa,UAAU,CAAC,OAAO,kBAAkB,CAAC;;;;;;;;aAIrC,CACT,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,UAAU,EACvB,KAAK,CAAC,EAAE,MAAM,KACX,OAAO;UAKD,MAAM,MAAM,EAAE;;mCAEd,WAAW,GAAG,2BAA2B;qCAvTJ,uBAAuB;oCAOU,uBAAuB;iCAAvB,uBAAuB;gCAAvB,uBAAuB"}
@@ -88,6 +88,55 @@ const makeSlotStringUnserialize = () => {
88
88
  };
89
89
  export const slotStringUnserialize = makeSlotStringUnserialize();
90
90
 
91
+ /**
92
+ * @example to iterate over storage messages
93
+ *
94
+ * ```js
95
+ * const q = makeAsyncQueue<StorageMessage>();
96
+ * const storage = makeFakeStorageKit('published', undefined, { eachMessage: q.enqueue });
97
+ * for (const message of q.iterable) { ... }
98
+ * ```
99
+ *
100
+ * @template T
101
+ */
102
+ export const makeAsyncQueue = () => {
103
+ /** @type {T[]} */
104
+ const queue = [];
105
+ /** @type {null | ((r: undefined) => void)} */
106
+ let resolve = null;
107
+ let done = false;
108
+
109
+ /** @param {T} data */
110
+ const enqueue = data => {
111
+ queue.push(data);
112
+ if (resolve) {
113
+ resolve(undefined);
114
+ resolve = null;
115
+ }
116
+ };
117
+
118
+ let alreadyIterating = false;
119
+ const iterable = {
120
+ async *[Symbol.asyncIterator]() {
121
+ assert(!alreadyIterating, `AsyncQueue is already iterating`);
122
+ alreadyIterating = true;
123
+ await null;
124
+ while (!done) {
125
+ if (queue.length === 0) {
126
+ await new Promise(r => (resolve = r));
127
+ }
128
+
129
+ while (queue.length > 0) {
130
+ yield queue.shift();
131
+ }
132
+ }
133
+ },
134
+ };
135
+
136
+ const cancel = () => (done = true);
137
+ return harden({ enqueue, iterable, cancel });
138
+ };
139
+
91
140
  /**
92
141
  * For testing, creates a chainStorage root node over an in-memory map and
93
142
  * exposes both the map and the sequence of received messages. The `sequence`
@@ -95,8 +144,13 @@ export const slotStringUnserialize = makeSlotStringUnserialize();
95
144
  *
96
145
  * @param {string} rootPath
97
146
  * @param {Parameters<typeof makeChainStorageRoot>[2]} [rootOptions]
147
+ * @param {{ eachMessage?: (m: StorageMessage) => void }} [spyOpts]
98
148
  */
99
- export const makeFakeStorageKit = (rootPath, rootOptions) => {
149
+ export const makeFakeStorageKit = (
150
+ rootPath,
151
+ rootOptions,
152
+ { eachMessage } = {},
153
+ ) => {
100
154
  const resolvedOptions = { sequence: true, ...rootOptions };
101
155
  /** @type {TotalMap<string, string>} */
102
156
  const data = new Map();
@@ -133,6 +187,7 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
133
187
  /** @param {StorageMessage} message */
134
188
  message => {
135
189
  messages.push(message);
190
+ eachMessage?.(message);
136
191
  switch (message.method) {
137
192
  case 'getStoreKey': {
138
193
  const [key] = message.args;