@agoric/internal 0.2.2-dev-317cfb6.0 → 0.2.2-dev-ab38bde.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/internal",
3
- "version": "0.2.2-dev-317cfb6.0+317cfb6",
3
+ "version": "0.2.2-dev-ab38bde.0+ab38bde",
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": "tsc -p jsconfig.json"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/zone": "0.1.1-dev-317cfb6.0+317cfb6",
23
+ "@agoric/zone": "0.1.1-dev-ab38bde.0+ab38bde",
24
24
  "@endo/far": "^0.2.18",
25
25
  "@endo/marshal": "^0.8.5",
26
26
  "@endo/patterns": "^0.2.2",
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "317cfb6a5030a8129a527e4cc6e2865f864c4ed7"
45
+ "gitHead": "ab38bdefa7fec337f897de122041bd5b79ea0196"
46
46
  }
@@ -0,0 +1,19 @@
1
+ export default function makeScratchPad(): {
2
+ delete: (keyP: any) => Promise<void>;
3
+ get: (keyP: any) => Promise<any>;
4
+ lookup: (...path: any[]) => any;
5
+ init: (keyP: any, objP: any) => Promise<any>;
6
+ keys: () => Promise<any[]>;
7
+ list: () => Promise<any[]>;
8
+ set: (keyP: any, objP: any) => Promise<any>;
9
+ } & import("@endo/eventual-send").RemotableBrand<{}, {
10
+ delete: (keyP: any) => Promise<void>;
11
+ get: (keyP: any) => Promise<any>;
12
+ lookup: (...path: any[]) => any;
13
+ init: (keyP: any, objP: any) => Promise<any>;
14
+ keys: () => Promise<any[]>;
15
+ list: () => Promise<any[]>;
16
+ set: (keyP: any, objP: any) => Promise<any>;
17
+ }>;
18
+ export type ScratchPad = ReturnType<typeof makeScratchPad>;
19
+ //# sourceMappingURL=scratch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratch.d.ts","sourceRoot":"","sources":["scratch.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgDC;yBACa,WAAW,qBAAqB,CAAC"}
package/src/scratch.js ADDED
@@ -0,0 +1,52 @@
1
+ import { E, Far } from '@endo/far';
2
+
3
+ export default function makeScratchPad() {
4
+ const map = new Map();
5
+
6
+ const keys = async () => {
7
+ const keyList = [...map.keys()];
8
+ return harden(keyList.sort());
9
+ };
10
+
11
+ const scratch = Far('scratchPad', {
12
+ delete: async keyP => {
13
+ const key = await keyP;
14
+ map.delete(key);
15
+ },
16
+ get: async keyP => {
17
+ const key = await keyP;
18
+ return map.get(key);
19
+ },
20
+ lookup: (...path) => {
21
+ if (path.length === 0) {
22
+ return scratch;
23
+ }
24
+ const [first, ...rest] = path;
25
+ const firstValue = E(scratch).get(first);
26
+ if (rest.length === 0) {
27
+ return firstValue;
28
+ }
29
+ return E(firstValue).lookup(...rest);
30
+ },
31
+ // Initialize a key only if it doesn't already exist. Needed for atomicity
32
+ // between multiple invocations.
33
+ init: async (keyP, objP) => {
34
+ const [key, obj] = await Promise.all([keyP, objP]);
35
+ if (map.has(key)) {
36
+ throw Error(`Scratchpad already has key ${key}`);
37
+ }
38
+ map.set(key, obj);
39
+ return key;
40
+ },
41
+ keys,
42
+ // Legacy alias for `keys`.
43
+ list: keys,
44
+ set: async (keyP, objP) => {
45
+ const [key, obj] = await Promise.all([keyP, objP]);
46
+ map.set(key, obj);
47
+ return key;
48
+ },
49
+ });
50
+ return scratch;
51
+ }
52
+ /** @typedef {ReturnType<typeof makeScratchPad>} ScratchPad */