@agoric/internal 0.2.2-dev-4874362.0 → 0.2.2-dev-5933241.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-4874362.0+4874362",
3
+ "version": "0.2.2-dev-5933241.0+5933241",
4
4
  "description": "Externally unsupported utilities internal to agoric-sdk",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -20,7 +20,8 @@
20
20
  "lint:types": "tsc -p jsconfig.json"
21
21
  },
22
22
  "dependencies": {
23
- "@endo/eventual-send": "^0.16.8",
23
+ "@agoric/zone": "0.1.1-dev-5933241.0+5933241",
24
+ "@endo/far": "^0.2.14",
24
25
  "@endo/marshal": "^0.8.1",
25
26
  "@endo/promise-kit": "^0.2.52",
26
27
  "jessie.js": "^0.3.2"
@@ -37,5 +38,5 @@
37
38
  "publishConfig": {
38
39
  "access": "public"
39
40
  },
40
- "gitHead": "4874362b8f9aa4f7c9f67ef7761bd78df126f267"
41
+ "gitHead": "5933241100b910022eca47f872451a82207d0dfd"
41
42
  }
@@ -0,0 +1,9 @@
1
+ export function callSync<I extends (...args: unknown[]) => any>(callback: import("./types").SyncCallback<I>, ...args: Parameters<I>): ReturnType<I>;
2
+ export function callE<I extends (...args: unknown[]) => any>(callback: import("./types").Callback<I>, ...args: Parameters<I>): Promise<Awaited<ReturnType<I>>>;
3
+ export function makeSyncFunctionCallback<I extends (...args: unknown[]) => any, T extends (...args: [...B, ...Parameters<I>]) => ReturnType<I> = I, B extends unknown[] = []>(target: T, ...bound: B): import("./types").SyncCallback<I>;
4
+ export function makeFunctionCallback<I extends (...args: unknown[]) => any, T extends import("@endo/far").ERef<(...args: [...B, ...Parameters<I>]) => ReturnType<I>> = import("@endo/far").ERef<I>, B extends unknown[] = []>(target: T, ...bound: B): import("./types").Callback<I>;
5
+ export function makeSyncMethodCallback<I extends (...args: unknown[]) => any, P extends PropertyKey, T extends { [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>; } = { [x_1 in P]: I; }, B extends unknown[] = []>(target: T, methodName: P, ...bound: B): import("./types").SyncCallback<I>;
6
+ export function makeMethodCallback<I extends (...args: unknown[]) => any, P extends PropertyKey, T extends import("@endo/far").ERef<{ [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>; }> = import("@endo/far").ERef<{ [x_1 in P]: I; }>, B extends unknown[] = []>(target: T, methodName: P, ...bound: B): import("./types").Callback<I>;
7
+ export type Callback<I extends (...args: unknown[]) => any> = import('./types').Callback<I>;
8
+ export type SyncCallback<I extends (...args: unknown[]) => any> = import('./types').SyncCallback<I>;
9
+ //# sourceMappingURL=callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["callback.js"],"names":[],"mappings":"AAqBO,6CALiB,OAAO,EAAE,KAAK,GAAG,sFAWxC;AAUM,0CALiB,OAAO,EAAE,KAAK,GAAG,oGAWxC;AAYM,6DAPiB,OAAO,EAAE,KAAK,GAAG,2JAWxC;AAeM,yDATiB,OAAO,EAAE,KAAK,GAAG,2MAaxC;AAiBM,2DAXiB,OAAO,EAAE,KAAK,GAAG,iOAexC;AAiBM,uDAXiB,OAAO,EAAE,KAAK,GAAG,iRAexC;yCApHuB,OAAO,EAAE,KAAK,GAAG,IAC5B,OAAO,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;6CAIlB,OAAO,EAAE,KAAK,GAAG,IAC5B,OAAO,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC"}
@@ -0,0 +1,122 @@
1
+ // @ts-check
2
+ import { E } from '@endo/far';
3
+
4
+ /**
5
+ * @template {(...args: unknown[]) => any} I
6
+ * @typedef {import('./types').Callback<I>} Callback
7
+ */
8
+
9
+ /**
10
+ * @template {(...args: unknown[]) => any} I
11
+ * @typedef {import('./types').SyncCallback<I>} SyncCallback
12
+ */
13
+
14
+ /**
15
+ * Synchronously call a callback.
16
+ *
17
+ * @template {(...args: unknown[]) => any} I
18
+ * @param {SyncCallback<I>} callback
19
+ * @param {Parameters<I>} args
20
+ * @returns {ReturnType<I>}
21
+ */
22
+ export const callSync = (callback, ...args) => {
23
+ const { target, method, bound } = callback;
24
+ if (method === undefined) {
25
+ return target(...bound, ...args);
26
+ }
27
+ return target[method](...bound, ...args);
28
+ };
29
+
30
+ /**
31
+ * Eventual send to a callback.
32
+ *
33
+ * @template {(...args: unknown[]) => any} I
34
+ * @param {Callback<I>} callback
35
+ * @param {Parameters<I>} args
36
+ * @returns {Promise<Awaited<ReturnType<I>>>}
37
+ */
38
+ export const callE = (callback, ...args) => {
39
+ const { target, method, bound } = callback;
40
+ if (method === undefined) {
41
+ return E(target)(...bound, ...args);
42
+ }
43
+ return E(target)[method](...bound, ...args);
44
+ };
45
+
46
+ /**
47
+ * Create a callback from a near function.
48
+ *
49
+ * @template {(...args: unknown[]) => any} I
50
+ * @template {(...args: [...B, ...Parameters<I>]) => ReturnType<I>} [T=I]
51
+ * @template {unknown[]} [B=[]]
52
+ * @param {T} target
53
+ * @param {B} bound
54
+ * @returns {SyncCallback<I>}
55
+ */
56
+ export const makeSyncFunctionCallback = (target, ...bound) => {
57
+ /** @type {unknown} */
58
+ const cb = harden({ target, bound });
59
+ return /** @type {SyncCallback<I>} */ (cb);
60
+ };
61
+ harden(makeSyncFunctionCallback);
62
+
63
+ /**
64
+ * Create a callback from a potentially far function.
65
+ *
66
+ * @template {(...args: unknown[]) => any} I
67
+ * @template {import('@endo/far').ERef<
68
+ * (...args: [...B, ...Parameters<I>]) => ReturnType<I>
69
+ * >} [T=import('@endo/far').ERef<I>]
70
+ * @template {unknown[]} [B=[]]
71
+ * @param {T} target
72
+ * @param {B} bound
73
+ * @returns {Callback<I>}
74
+ */
75
+ export const makeFunctionCallback = (target, ...bound) => {
76
+ /** @type {unknown} */
77
+ const cb = harden({ target, bound });
78
+ return /** @type {Callback<I>} */ (cb);
79
+ };
80
+ harden(makeFunctionCallback);
81
+
82
+ /**
83
+ * Create a callback from a near method.
84
+ *
85
+ * @template {(...args: unknown[]) => any} I
86
+ * @template {PropertyKey} P
87
+ * @template {{
88
+ * [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>
89
+ * }} [T={ [x in P]: I }]
90
+ * @template {unknown[]} [B=[]]
91
+ * @param {T} target
92
+ * @param {P} methodName
93
+ * @param {B} bound
94
+ * @returns {SyncCallback<I>}
95
+ */
96
+ export const makeSyncMethodCallback = (target, methodName, ...bound) => {
97
+ /** @type {unknown} */
98
+ const cb = harden({ target, method: methodName, bound });
99
+ return /** @type {SyncCallback<I>} */ (cb);
100
+ };
101
+ harden(makeSyncMethodCallback);
102
+
103
+ /**
104
+ * Create a callback from a potentially far method.
105
+ *
106
+ * @template {(...args: unknown[]) => any} I
107
+ * @template {PropertyKey} P
108
+ * @template {import('@endo/far').ERef<{
109
+ * [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>
110
+ * }>} [T=import('@endo/far').ERef<{ [x in P]: I }>]
111
+ * @template {unknown[]} [B=[]]
112
+ * @param {T} target
113
+ * @param {P} methodName
114
+ * @param {B} bound
115
+ * @returns {Callback<I>}
116
+ */
117
+ export const makeMethodCallback = (target, methodName, ...bound) => {
118
+ /** @type {unknown} */
119
+ const cb = harden({ target, method: methodName, bound });
120
+ return /** @type {Callback<I>} */ (cb);
121
+ };
122
+ harden(makeMethodCallback);
@@ -1,31 +1,44 @@
1
1
  /**
2
- * Must match the switch in vstorage.go using `vstorageMessage` type
3
- *
4
- * @typedef { 'get' | 'getStoreKey' | 'has' | 'entries' | 'values' |'size' } StorageGetByPathMessageMethod
5
- * @typedef { 'set' | 'append' } StorageUpdateEntriesMessageMethod
6
- * @typedef {StorageGetByPathMessageMethod | StorageUpdateEntriesMessageMethod } StorageMessageMethod
7
- * @typedef { [path: string] } StorageGetByPathMessageArgs
8
- * @typedef { [path: string, value?: string | null] } StorageEntry
9
- * @typedef { StorageEntry[] } StorageUpdateEntriesMessageArgs
10
- * @typedef {{
11
- * method: StorageGetByPathMessageMethod;
12
- * args: StorageGetByPathMessageArgs;
13
- * } | {
14
- * method: StorageUpdateEntriesMessageMethod;
15
- * args: StorageUpdateEntriesMessageArgs;
16
- * }} StorageMessage
17
- */
18
- /**
19
- * Create a root storage node for a given backing function and root path.
2
+ * Create a heap-based root storage node for a given backing function and root path.
20
3
  *
21
- * @param {(message: StorageMessage) => any} handleStorageMessage a function for sending a storageMessage object to the storage implementation (cf. golang/cosmos/x/vstorage/vstorage.go)
4
+ * @param {(message: StorageMessage) => any} handleStorageMessage a function for
5
+ * sending a storageMessage object to the storage implementation
6
+ * (cf. golang/cosmos/x/vstorage/vstorage.go)
22
7
  * @param {string} rootPath
23
8
  * @param {object} [rootOptions]
24
- * @param {boolean} [rootOptions.sequence] employ a wrapping structure that preserves each value set within a single block, and default child nodes to do the same
9
+ * @param {boolean} [rootOptions.sequence] employ a wrapping structure that
10
+ * preserves each value set within a single block, and default child nodes
11
+ * to do the same
25
12
  */
26
13
  export function makeChainStorageRoot(handleStorageMessage: (message: StorageMessage) => any, rootPath: string, rootOptions?: {
27
14
  sequence?: boolean | undefined;
28
- } | undefined): StorageNode;
15
+ } | undefined): {
16
+ getPath(): string;
17
+ /**
18
+ * @deprecated use getPath
19
+ * @type {() => Promise<VStorageKey>}
20
+ */
21
+ getStoreKey(): Promise<VStorageKey>;
22
+ /** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
23
+ makeChildNode(name: string, childNodeOptions?: {
24
+ sequence?: boolean | undefined;
25
+ } | undefined): StorageNode;
26
+ /** @type {(value: string) => Promise<void>} */
27
+ setValue(value: string): Promise<void>;
28
+ } & import("@endo/eventual-send").RemotableBrand<{}, {
29
+ getPath(): string;
30
+ /**
31
+ * @deprecated use getPath
32
+ * @type {() => Promise<VStorageKey>}
33
+ */
34
+ getStoreKey(): Promise<VStorageKey>;
35
+ /** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
36
+ makeChildNode(name: string, childNodeOptions?: {
37
+ sequence?: boolean | undefined;
38
+ } | undefined): StorageNode;
39
+ /** @type {(value: string) => Promise<void>} */
40
+ setValue(value: string): Promise<void>;
41
+ }>;
29
42
  /**
30
43
  * Convenience function for returning a storage node at or under its input,
31
44
  * falling back to an inert object with the correct interface (but incomplete
@@ -38,41 +51,36 @@ export function makeChainStorageRoot(handleStorageMessage: (message: StorageMess
38
51
  export function makeStorageNodeChild(storageNodeRef: import('@endo/far').ERef<StorageNode | null>, childName: string): Promise<StorageNode>;
39
52
  /** @type {(name: string) => void} */
40
53
  export const assertPathSegment: (name: string) => void;
54
+ export function prepareChainStorageNode(zone: import('@agoric/zone').Zone): (args_0: import("./types.js").Callback<(message: StorageMessage) => any>, args_1: string, args_2?: {
55
+ sequence?: boolean | undefined;
56
+ } | undefined) => {
57
+ getPath(): string;
58
+ /**
59
+ * @deprecated use getPath
60
+ * @type {() => Promise<VStorageKey>}
61
+ */
62
+ getStoreKey(): Promise<VStorageKey>;
63
+ /** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
64
+ makeChildNode(name: string, childNodeOptions?: {
65
+ sequence?: boolean | undefined;
66
+ } | undefined): StorageNode;
67
+ /** @type {(value: string) => Promise<void>} */
68
+ setValue(value: string): Promise<void>;
69
+ } & import("@endo/eventual-send").RemotableBrand<{}, {
70
+ getPath(): string;
71
+ /**
72
+ * @deprecated use getPath
73
+ * @type {() => Promise<VStorageKey>}
74
+ */
75
+ getStoreKey(): Promise<VStorageKey>;
76
+ /** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
77
+ makeChildNode(name: string, childNodeOptions?: {
78
+ sequence?: boolean | undefined;
79
+ } | undefined): StorageNode;
80
+ /** @type {(value: string) => Promise<void>} */
81
+ setValue(value: string): Promise<void>;
82
+ }>;
41
83
  export function makeSerializeToStorage(storageNode: import('@endo/far').ERef<StorageNode>, marshaller: import('@endo/far').ERef<Marshaller>): (value: unknown) => Promise<void>;
42
- /**
43
- * Must match the switch in vstorage.go using `vstorageMessage` type
44
- */
45
- export type StorageGetByPathMessageMethod = 'get' | 'getStoreKey' | 'has' | 'entries' | 'values' | 'size';
46
- /**
47
- * Must match the switch in vstorage.go using `vstorageMessage` type
48
- */
49
- export type StorageUpdateEntriesMessageMethod = 'set' | 'append';
50
- /**
51
- * Must match the switch in vstorage.go using `vstorageMessage` type
52
- */
53
- export type StorageMessageMethod = StorageGetByPathMessageMethod | StorageUpdateEntriesMessageMethod;
54
- /**
55
- * Must match the switch in vstorage.go using `vstorageMessage` type
56
- */
57
- export type StorageGetByPathMessageArgs = [path: string];
58
- /**
59
- * Must match the switch in vstorage.go using `vstorageMessage` type
60
- */
61
- export type StorageEntry = [path: string, value?: string | null];
62
- /**
63
- * Must match the switch in vstorage.go using `vstorageMessage` type
64
- */
65
- export type StorageUpdateEntriesMessageArgs = [path: string, value?: string | null | undefined][];
66
- /**
67
- * Must match the switch in vstorage.go using `vstorageMessage` type
68
- */
69
- export type StorageMessage = {
70
- method: StorageGetByPathMessageMethod;
71
- args: [path: string];
72
- } | {
73
- method: StorageUpdateEntriesMessageMethod;
74
- args: StorageUpdateEntriesMessageArgs;
75
- };
76
84
  export type Marshaller = ReturnType<typeof import('@endo/marshal').makeMarshal>;
77
85
  export type Unserializer = Pick<Marshaller, 'unserialize'>;
78
86
  /**
@@ -124,4 +132,38 @@ export type StoredFacet = {
124
132
  */
125
133
  getUnserializer: () => Unserializer;
126
134
  };
135
+ /**
136
+ * Must match the switch in vstorage.go using `vstorageMessage` type
137
+ */
138
+ export type StorageGetByPathMessageMethod = 'get' | 'getStoreKey' | 'has' | 'entries' | 'values' | 'size';
139
+ /**
140
+ * Must match the switch in vstorage.go using `vstorageMessage` type
141
+ */
142
+ export type StorageUpdateEntriesMessageMethod = 'set' | 'append';
143
+ /**
144
+ * Must match the switch in vstorage.go using `vstorageMessage` type
145
+ */
146
+ export type StorageMessageMethod = StorageGetByPathMessageMethod | StorageUpdateEntriesMessageMethod;
147
+ /**
148
+ * Must match the switch in vstorage.go using `vstorageMessage` type
149
+ */
150
+ export type StorageGetByPathMessageArgs = [path: string];
151
+ /**
152
+ * Must match the switch in vstorage.go using `vstorageMessage` type
153
+ */
154
+ export type StorageEntry = [path: string, value?: string | null];
155
+ /**
156
+ * Must match the switch in vstorage.go using `vstorageMessage` type
157
+ */
158
+ export type StorageUpdateEntriesMessageArgs = [path: string, value?: string | null | undefined][];
159
+ /**
160
+ * Must match the switch in vstorage.go using `vstorageMessage` type
161
+ */
162
+ export type StorageMessage = {
163
+ method: StorageGetByPathMessageMethod;
164
+ args: [path: string];
165
+ } | {
166
+ method: StorageUpdateEntriesMessageMethod;
167
+ args: StorageUpdateEntriesMessageArgs;
168
+ };
127
169
  //# sourceMappingURL=lib-chainStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"AAwDA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;GAOG;AACH,qEALqB,cAAc,KAAK,GAAG,YAChC,MAAM;;4BAoEhB;AAUD;;;;;;;;GAQG;AACH,qDAJW,OAAO,WAAW,EAAE,IAAI,CAAC,WAAW,QAAE,aACtC,MAAM,GACJ,QAAQ,WAAW,CAAC,CAMhC;AAxHD,qCAAqC;AACrC,uCADkB,MAAM,KAAK,IAAI,CAI/B;AA8HK,oDAJI,OAAO,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,cACrC,OAAO,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,WAC1B,OAAO,KAAK,QAAQ,IAAI,CAAC,CAQ7C;;;;4CA9Ha,KAAK,GAAG,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAE,MAAM;;;;gDAC5D,KAAK,GAAG,QAAQ;;;;mCACjB,6BAA6B,GAAG,iCAAiC;;;;0CAChE,CAAC,IAAI,E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G,IAAI,CAAC;;;;8CACrC,mDAAc;;;;6BACf;IACZ,MAAU,EAAE,6BAA6B,CAAC;IAC1C,IAAQ,iBAA8B;CAClC,GAAG;IACP,MAAU,EAAE,iCAAiC,CAAC;IAC9C,IAAQ,kCAAkC;CACvC"}
@@ -1,7 +1,8 @@
1
1
  // @ts-check
2
2
 
3
- import { E } from '@endo/eventual-send';
4
- import { Far } from '@endo/marshal';
3
+ import { E } from '@endo/far';
4
+ import { M, heapZone } from '@agoric/zone';
5
+ import * as cb from './callback.js';
5
6
 
6
7
  const { Fail } = assert;
7
8
 
@@ -34,6 +35,15 @@ const { Fail } = assert;
34
35
  * @property {(subPath: string, options?: {sequence?: boolean}) => StorageNode} makeChildNode
35
36
  */
36
37
 
38
+ const ChainStorageNodeI = M.interface('StorageNode', {
39
+ setValue: M.callWhen(M.string()).returns(),
40
+ getPath: M.call().returns(M.string()),
41
+ getStoreKey: M.callWhen().returns(M.record()),
42
+ makeChildNode: M.call(M.string())
43
+ .optional(M.splitRecord({}, { sequence: M.boolean() }, {}))
44
+ .returns(M.remotable('StorageNode')),
45
+ });
46
+
37
47
  /**
38
48
  * @typedef {object} StoredFacet
39
49
  * @property {() => Promise<string>} getPath the chain storage path at which the node was constructed
@@ -73,51 +83,66 @@ harden(assertPathSegment);
73
83
  */
74
84
 
75
85
  /**
76
- * Create a root storage node for a given backing function and root path.
77
- *
78
- * @param {(message: StorageMessage) => any} handleStorageMessage a function for sending a storageMessage object to the storage implementation (cf. golang/cosmos/x/vstorage/vstorage.go)
79
- * @param {string} rootPath
80
- * @param {object} [rootOptions]
81
- * @param {boolean} [rootOptions.sequence] employ a wrapping structure that preserves each value set within a single block, and default child nodes to do the same
86
+ * @param {import('@agoric/zone').Zone} zone
82
87
  */
83
- export function makeChainStorageRoot(
84
- handleStorageMessage,
85
- rootPath,
86
- rootOptions = {},
87
- ) {
88
- assert.typeof(rootPath, 'string');
89
-
88
+ export const prepareChainStorageNode = zone => {
90
89
  /**
90
+ * Create a storage node for a given backing storage interface and path.
91
+ *
92
+ * @param {import('./callback').Callback<(message: StorageMessage) => any>} messenger a callback
93
+ * for sending a storageMessage object to the storage implementation
94
+ * (cf. golang/cosmos/x/vstorage/vstorage.go)
91
95
  * @param {string} path
92
96
  * @param {object} [options]
93
- * @param {boolean} [options.sequence]
97
+ * @param {boolean} [options.sequence] set values with `append` messages rather than `set` messages
98
+ * so the backing implementation employs a wrapping structure that
99
+ * preserves each value set within a single block.
100
+ * Child nodes default to inheriting this option from their parent.
94
101
  * @returns {StorageNode}
95
102
  */
96
- function makeChainStorageNode(path, options = {}) {
97
- const { sequence = false } = options;
98
- const node = {
103
+ const makeChainStorageNode = zone.exoClass(
104
+ 'ChainStorageNode',
105
+ ChainStorageNodeI,
106
+ /**
107
+ * @param {import('./callback').Callback<(message: StorageMessage) => any>} messenger
108
+ * @param {string} path
109
+ * @param {object} [options]
110
+ * @param {boolean} [options.sequence]
111
+ */
112
+ (messenger, path, { sequence = false } = {}) => {
113
+ assert.typeof(path, 'string');
114
+ assert.typeof(sequence, 'boolean');
115
+ return harden({ path, messenger, sequence });
116
+ },
117
+ {
99
118
  getPath() {
100
- return path;
119
+ return this.state.path;
101
120
  },
102
121
  /**
103
122
  * @deprecated use getPath
104
123
  * @type {() => Promise<VStorageKey>}
105
124
  */
106
125
  async getStoreKey() {
107
- return handleStorageMessage({
126
+ const { path, messenger } = this.state;
127
+ return cb.callE(messenger, {
108
128
  method: 'getStoreKey',
109
129
  args: [path],
110
130
  });
111
131
  },
112
132
  /** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
113
133
  makeChildNode(name, childNodeOptions = {}) {
114
- assert.typeof(name, 'string');
134
+ const { sequence, path, messenger } = this.state;
115
135
  assertPathSegment(name);
116
136
  const mergedOptions = { sequence, ...childNodeOptions };
117
- return makeChainStorageNode(`${path}.${name}`, mergedOptions);
137
+ return makeChainStorageNode(
138
+ messenger,
139
+ `${path}.${name}`,
140
+ mergedOptions,
141
+ );
118
142
  },
119
143
  /** @type {(value: string) => Promise<void>} */
120
144
  async setValue(value) {
145
+ const { sequence, path, messenger } = this.state;
121
146
  assert.typeof(value, 'string');
122
147
  /** @type {StorageEntry} */
123
148
  let entry;
@@ -126,7 +151,7 @@ export function makeChainStorageRoot(
126
151
  } else {
127
152
  entry = [path, value];
128
153
  }
129
- await handleStorageMessage({
154
+ await cb.callE(messenger, {
130
155
  method: sequence ? 'append' : 'set',
131
156
  args: [entry],
132
157
  });
@@ -138,11 +163,34 @@ export function makeChainStorageRoot(
138
163
  // * recursive delete
139
164
  // * batch operations
140
165
  // * local buffering (with end-of-block commit)
141
- };
142
- return Far('chainStorageNode', node);
143
- }
166
+ },
167
+ );
168
+ return makeChainStorageNode;
169
+ };
170
+
171
+ const makeHeapChainStorageNode = prepareChainStorageNode(heapZone);
172
+
173
+ /**
174
+ * Create a heap-based root storage node for a given backing function and root path.
175
+ *
176
+ * @param {(message: StorageMessage) => any} handleStorageMessage a function for
177
+ * sending a storageMessage object to the storage implementation
178
+ * (cf. golang/cosmos/x/vstorage/vstorage.go)
179
+ * @param {string} rootPath
180
+ * @param {object} [rootOptions]
181
+ * @param {boolean} [rootOptions.sequence] employ a wrapping structure that
182
+ * preserves each value set within a single block, and default child nodes
183
+ * to do the same
184
+ */
185
+ export function makeChainStorageRoot(
186
+ handleStorageMessage,
187
+ rootPath,
188
+ rootOptions = {},
189
+ ) {
190
+ const messenger = cb.makeFunctionCallback(handleStorageMessage);
144
191
 
145
- const rootNode = makeChainStorageNode(rootPath, rootOptions);
192
+ // Use the heapZone directly.
193
+ const rootNode = makeHeapChainStorageNode(messenger, rootPath, rootOptions);
146
194
  return rootNode;
147
195
  }
148
196
 
@@ -1,4 +1,3 @@
1
- export function getMethodNames(val: any): (string | symbol)[];
2
- export function bindAllMethods(obj: Remotable): Remotable;
3
- export type Remotable = import('@endo/marshal/src/types').Remotable;
1
+ export function getMethodNames<K extends PropertyKey>(val: Record<K, any>): K[];
2
+ export function bindAllMethods<T extends Record<PropertyKey, any>>(obj: T): T;
4
3
  //# sourceMappingURL=method-tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"method-tools.d.ts","sourceRoot":"","sources":["method-tools.js"],"names":[],"mappings":"AA0CO,oCAHI,GAAG,GACD,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,CAqB7B;AA+BM,oCAHI,SAAS,GACP,SAAS,CAiBnB;wBAhGW,OAAO,yBAAyB,EAAE,SAAS"}
1
+ {"version":3,"file":"method-tools.d.ts","sourceRoot":"","sources":["method-tools.js"],"names":[],"mappings":"AAyCO,gFAoBN;AAgCM,8EAeJ"}
@@ -9,8 +9,6 @@ const { getPrototypeOf, create, fromEntries, getOwnPropertyDescriptors } =
9
9
  Object;
10
10
  const { ownKeys, apply } = Reflect;
11
11
 
12
- /** @typedef {import('@endo/marshal/src/types').Remotable} Remotable */
13
-
14
12
  /**
15
13
  * Prioritize symbols as earlier than strings.
16
14
  *
@@ -37,8 +35,9 @@ const compareStringified = (a, b) => {
37
35
  /**
38
36
  * TODO Consolidate with the `getMethodNames` in `@endo/eventual-send`
39
37
  *
40
- * @param {any} val
41
- * @returns {(string|symbol)[]}
38
+ * @template {PropertyKey} K
39
+ * @param {Record<K, any>} val
40
+ * @returns {K[]}
42
41
  */
43
42
  export const getMethodNames = val => {
44
43
  let layer = val;
@@ -46,7 +45,8 @@ export const getMethodNames = val => {
46
45
  while (layer !== null && layer !== Object.prototype) {
47
46
  // be tolerant of non-objects
48
47
  const descs = getOwnPropertyDescriptors(layer);
49
- for (const name of ownKeys(descs)) {
48
+ const ownNames = /** @type {K[]} */ (ownKeys(descs));
49
+ for (const name of ownNames) {
50
50
  // In case a method is overridden by a non-method,
51
51
  // test `val[name]` rather than `layer[name]`
52
52
  if (typeof val[name] === 'function') {
@@ -87,8 +87,9 @@ harden(getMethodNames);
87
87
  * object has bound own methods overridding all the methods it would have
88
88
  * inherited from `obj`.
89
89
  *
90
- * @param {Remotable} obj
91
- * @returns {Remotable}
90
+ * @template {Record<PropertyKey, any>} T
91
+ * @param {T} obj
92
+ * @returns {T}
92
93
  */
93
94
  export const bindAllMethods = obj =>
94
95
  harden(
@@ -1,5 +1,19 @@
1
1
  export function makeFakeStorageKit(rootPath: string, rootOptions?: object | undefined): {
2
- rootNode: import("./lib-chainStorage.js").StorageNode;
2
+ rootNode: {
3
+ getPath(): string;
4
+ getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
5
+ makeChildNode(name: string, childNodeOptions?: {
6
+ sequence?: boolean | undefined;
7
+ } | undefined): import("./lib-chainStorage.js").StorageNode;
8
+ setValue(value: string): Promise<void>;
9
+ } & import("@endo/eventual-send").RemotableBrand<{}, {
10
+ getPath(): string;
11
+ getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
12
+ makeChildNode(name: string, childNodeOptions?: {
13
+ sequence?: boolean | undefined;
14
+ } | undefined): import("./lib-chainStorage.js").StorageNode;
15
+ setValue(value: string): Promise<void>;
16
+ }>;
3
17
  data: Map<string, any>;
4
18
  messages: import("./lib-chainStorage.js").StorageMessage[];
5
19
  toStorage: (message: import('../src/lib-chainStorage.js').StorageMessage) => Promise<number | {
@@ -18,21 +32,12 @@ export function makeMockChainStorageRoot(): {
18
32
  * @returns {unknown}
19
33
  */
20
34
  getBody: (path: string, marshaller?: import('./lib-chainStorage.js').Marshaller) => unknown;
21
- /**
22
- * publishes some data
23
- */
24
- setValue: (data: string) => Promise<void>;
25
- /**
26
- * the chain storage path at which the node was constructed
27
- */
28
- getPath: () => string;
29
- /**
30
- * DEPRECATED use getPath
31
- */
32
- getStoreKey: () => Promise<import("./lib-chainStorage.js").VStorageKey>;
33
- makeChildNode: (subPath: string, options?: {
35
+ getPath(): string;
36
+ getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
37
+ makeChildNode(name: string, childNodeOptions?: {
34
38
  sequence?: boolean | undefined;
35
- } | undefined) => import("./lib-chainStorage.js").StorageNode;
39
+ } | undefined): import("./lib-chainStorage.js").StorageNode;
40
+ setValue(value: string): Promise<void>;
36
41
  } & import("@endo/eventual-send").RemotableBrand<{}, {
37
42
  /**
38
43
  * Defaults to deserializing pass-by-presence objects into { iface } representations.
@@ -44,21 +49,12 @@ export function makeMockChainStorageRoot(): {
44
49
  * @returns {unknown}
45
50
  */
46
51
  getBody: (path: string, marshaller?: import('./lib-chainStorage.js').Marshaller) => unknown;
47
- /**
48
- * publishes some data
49
- */
50
- setValue: (data: string) => Promise<void>;
51
- /**
52
- * the chain storage path at which the node was constructed
53
- */
54
- getPath: () => string;
55
- /**
56
- * DEPRECATED use getPath
57
- */
58
- getStoreKey: () => Promise<import("./lib-chainStorage.js").VStorageKey>;
59
- makeChildNode: (subPath: string, options?: {
52
+ getPath(): string;
53
+ getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
54
+ makeChildNode(name: string, childNodeOptions?: {
60
55
  sequence?: boolean | undefined;
61
- } | undefined) => import("./lib-chainStorage.js").StorageNode;
56
+ } | undefined): import("./lib-chainStorage.js").StorageNode;
57
+ setValue(value: string): Promise<void>;
62
58
  }>;
63
59
  export type FakeStorageKit = ReturnType<typeof makeFakeStorageKit>;
64
60
  export type MockChainStorageRoot = ReturnType<typeof makeMockChainStorageRoot>;
@@ -1 +1 @@
1
- {"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAaO,6CAHI,MAAM;;;;yBAQH,OAAO,4BAA4B,EAAE,cAAc;;;;EAkDhE;AAIM;IASH;;;;;;;;OAQG;oBAHQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,KACxC,OAAO;;;;;;;;;;;;;;;;;IAPpB;;;;;;;;OAQG;oBAHQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,KACxC,OAAO;;;;;;;;;;;;;;;;GAcvB;6BAhCa,WAAY,yBAAyB,CAAC;mCAiCtC,WAAW,+BAA+B,CAAC"}
1
+ {"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAeO,6CAHI,MAAM;;;;;;;;;;;;;;;;;;yBAQH,OAAO,4BAA4B,EAAE,cAAc;;;;EAkDhE;AAIM;IASH;;;;;;;;OAQG;oBAHQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,KACxC,OAAO;;;;;;;;IAPpB;;;;;;;;OAQG;oBAHQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,KACxC,OAAO;;;;;;;GAcvB;6BAhCa,WAAY,yBAAyB,CAAC;mCAiCtC,WAAW,+BAA+B,CAAC"}
@@ -1,6 +1,8 @@
1
1
  // @ts-check
2
- import { Far, makeMarshal } from '@endo/marshal';
2
+ import { Far } from '@endo/far';
3
+ import { makeMarshal } from '@endo/marshal';
3
4
  import { makeChainStorageRoot } from './lib-chainStorage.js';
5
+ import { bindAllMethods } from './method-tools.js';
4
6
 
5
7
  const { Fail, quote: q } = assert;
6
8
 
@@ -78,7 +80,7 @@ export const makeMockChainStorageRoot = () => {
78
80
  }));
79
81
 
80
82
  return Far('mockChainStorage', {
81
- ...rootNode,
83
+ ...bindAllMethods(rootNode),
82
84
  /**
83
85
  * Defaults to deserializing pass-by-presence objects into { iface } representations.
84
86
  * Note that this is **not** a null transformation; capdata `@qclass` and `index` properties
package/src/types.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ export declare class Callback<I extends (...args: unknown[]) => any> {
3
+ private iface: I;
4
+
5
+ public target: any;
6
+
7
+ public method?: PropertyKey;
8
+
9
+ public bound: unknown[];
10
+ }
11
+
12
+ export declare class SyncCallback<
13
+ I extends (...args: unknown[]) => any,
14
+ > extends Callback<I> {
15
+ private syncIface: I;
16
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAYA,kCAAoC;AAa7B,0EAcN;AA0CM,gJAIN;AAQM,0CAHI,MAAM,MA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,EAAE,uCAcjB;AAOM,4FAeN;AAED;;;;;GAKG,CAAC,mFAFoB,OAAO,KAAK,QAAQ,IAAI,CAAC,gBAY7C;AAiBG,0GAUN;AAQD,+CAAoD;AAU7C,0EAUH;AAUG,0EAaH;AAEJ,oDAAoD;AACpD,uDAAqE;AAErE,2GAA2G;AAC3G,+GAIE;;;;sBA9UwB,OAAO,qBAAqB,EAAE,IAAI,CAAC,CAAC,CAAC;;;;;;iCAmJxC,GAAG,EAAE,KAAK,GAAG;;+BAUvB,CAAC,SAAS,YAAY,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC"}
package/src/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
  // @jessie-check
3
- import { E } from '@endo/eventual-send';
3
+ import { E } from '@endo/far';
4
4
  import { deeplyFulfilled, isObject } from '@endo/marshal';
5
5
  import { isPromise } from '@endo/promise-kit';
6
6
  import { asyncGenerate, makeSet } from 'jessie.js';
@@ -134,14 +134,17 @@ export const applyLabelingError = (func, args, label = undefined) => {
134
134
  throwLabeled(err, label);
135
135
  }
136
136
  if (isPromise(result)) {
137
- // @ts-expect-error If result is a rejected promise, this will
138
- // return a promise with a different rejection reason. But this
139
- // confuses TypeScript because it types that case as `Promise<never>`
140
- // which is cool for a promise that will never fulfll.
141
- // But TypeScript doesn't understand that this will only happen
142
- // when `result` was a rejected promise. In only this case `R`
143
- // should already allow `Promise<never>` as a subtype.
144
- return E.when(result, undefined, reason => throwLabeled(reason, label));
137
+ // If result is a rejected promise, this will return a promise with a
138
+ // different rejection reason. But this confuses TypeScript because it types
139
+ // that case as `Promise<never>` which is cool for a promise that will never
140
+ // fulfill. But TypeScript doesn't understand that this will only happen
141
+ // when `result` was a rejected promise. In only this case `R` should
142
+ // already allow `Promise<never>` as a subtype.
143
+ /** @type {unknown} */
144
+ const relabeled = E.when(result, undefined, reason =>
145
+ throwLabeled(reason, label),
146
+ );
147
+ return /** @type {R} */ (relabeled);
145
148
  } else {
146
149
  return result;
147
150
  }