@agoric/internal 0.2.2-dev-2788f8d.0 → 0.2.2-dev-0ce9545.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-2788f8d.0+2788f8d",
3
+ "version": "0.2.2-dev-0ce9545.0+0ce9545",
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-2788f8d.0+2788f8d",
23
+ "@agoric/zone": "0.1.1-dev-0ce9545.0+0ce9545",
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": "2788f8d1343b7206b1b6322febdba52f3514e964"
45
+ "gitHead": "0ce9545041d41022e605b48da6d2561287591c54"
46
46
  }
package/src/callback.d.ts CHANGED
@@ -5,30 +5,26 @@ export function makeFunctionCallback<I extends (...args: unknown[]) => any, T ex
5
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
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
7
  export function isCallback(callback: any): callback is import("./types").Callback<any>;
8
- export function prepareAttenuator<M extends PropertyKey>(zone: import('@agoric/zone').Zone, methodNames: M[], { interfaceGuard, tag }?: {
8
+ export function prepareAttenuator<Methods extends {
9
+ [x: string]: (this: any, ...args: unknown[]) => any;
10
+ [x: number]: (this: any, ...args: unknown[]) => any;
11
+ [x: symbol]: (this: any, ...args: unknown[]) => any;
12
+ }>(zone: import('@agoric/zone').Zone, methodNames: (keyof Methods)[], { interfaceGuard, tag }?: {
9
13
  interfaceGuard?: InterfaceGuard | undefined;
10
14
  tag?: string | undefined;
11
15
  }): (args_0: {
12
16
  target?: any;
13
17
  isSync?: boolean | undefined;
14
- overrides?: { [K in M]?: import("./types").Callback<any> | null | undefined; } | undefined;
15
- }) => { [K_1 in M]: (this: any, ...args: unknown[]) => any; } & import("@endo/eventual-send").RemotableBrand<{}, { [K_1 in M]: (this: any, ...args: unknown[]) => any; }>;
16
- export function prepareGuardedAttenuator(zone: import('@agoric/zone').Zone, interfaceGuard: InterfaceGuard, opts?: {
17
- tag?: string | undefined;
18
- } | undefined): (args_0: {
19
- target?: any;
20
- isSync?: boolean | undefined;
21
- overrides?: {
22
- [x: string]: import("./types").Callback<any> | null | undefined;
23
- [x: symbol]: import("./types").Callback<any> | null | undefined;
24
- } | undefined;
25
- }) => {
26
- [x: string]: (this: any, ...args: unknown[]) => any;
27
- [x: symbol]: (this: any, ...args: unknown[]) => any;
28
- } & import("@endo/eventual-send").RemotableBrand<{}, {
18
+ overrides?: { [K in keyof Methods]?: import("./types").Callback<any> | null | undefined; } | undefined;
19
+ }) => Methods & import("@endo/eventual-send").RemotableBrand<{}, Methods>;
20
+ export function prepareGuardedAttenuator<Methods extends {
29
21
  [x: string]: (this: any, ...args: unknown[]) => any;
22
+ [x: number]: (this: any, ...args: unknown[]) => any;
30
23
  [x: symbol]: (this: any, ...args: unknown[]) => any;
31
- }>;
24
+ }>(zone: import('@agoric/zone').Zone, interfaceGuard: InterfaceGuard, opts?: {
25
+ tag?: string | undefined;
26
+ } | undefined): AttenuatorMaker<Methods>;
27
+ export type AttenuatorMaker<T> = AttenuatorMaker<T>;
32
28
  export type Callback<I extends (...args: unknown[]) => any> = import('./types').Callback<I>;
33
29
  export type SyncCallback<I extends (...args: unknown[]) => any> = import('./types').SyncCallback<I>;
34
30
  export type Farable<T> = import('@endo/eventual-send').RemotableBrand<{}, T> & T;
@@ -1 +1 @@
1
- {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["callback.js"],"names":[],"mappings":"AAkDO,6CALiB,OAAO,EAAE,KAAK,GAAG,sFAWxC;AAWM,0CALiB,OAAO,EAAE,KAAK,GAAG,oGAWxC;AAaM,6DAPiB,OAAO,EAAE,KAAK,GAAG,2JAaxC;AAeM,yDATiB,OAAO,EAAE,KAAK,GAAG,2MAexC;AAiBM,2DAXiB,OAAO,EAAE,KAAK,GAAG,iOAoBxC;AAiBM,uDAXiB,OAAO,EAAE,KAAK,GAAG,iRAmBxC;AAOM,qCAHI,GAAG,+CAeb;AAcM,+DAPI,OAAO,cAAc,EAAE,IAAI;IAGL,cAAc;IAEtB,GAAG;;aAkEb,GAAG;;;2BA1DI,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG,4EAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG,KA8FpD;AAWM,+CALI,OAAO,cAAc,EAAE,IAAI,kBAC3B,cAAc;;;aA3CV,GAAG;;;;;;;wBA1DI,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;GA6GpD;yCAzSuB,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;yBAGpB,OAAO,qBAAqB,EAAE,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC"}
1
+ {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["callback.js"],"names":[],"mappings":"AAuDO,6CALiB,OAAO,EAAE,KAAK,GAAG,sFAWxC;AAWM,0CALiB,OAAO,EAAE,KAAK,GAAG,oGAWxC;AAaM,6DAPiB,OAAO,EAAE,KAAK,GAAG,2JAaxC;AAeM,yDATiB,OAAO,EAAE,KAAK,GAAG,2MAexC;AAiBM,2DAXiB,OAAO,EAAE,KAAK,GAAG,iOAoBxC;AAiBM,uDAXiB,OAAO,EAAE,KAAK,GAAG,iRAmBxC;AAOM,qCAHI,GAAG,+CAeb;AAcM;wBARoC,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;SAC/D,OAAO,cAAc,EAAE,IAAI;IAGL,cAAc;IAEtB,GAAG;;aAmEb,GAAG;;;0EAoCjB;AAYM;wBANoC,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;wBAA/B,GAAG,WAAW,OAAO,EAAE,KAAK,GAAG;SAC/D,OAAO,cAAc,EAAE,IAAI,kBAC3B,cAAc;;yCAUxB;;yCA7SuB,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;yBAGpB,OAAO,qBAAqB,EAAE,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC"}
package/src/callback.js CHANGED
@@ -12,6 +12,11 @@ const ownKeys =
12
12
  rawOwnKeys
13
13
  );
14
14
 
15
+ /**
16
+ * @template T
17
+ * @typedef {(...args: Parameters<ReturnType<prepareAttenuator>>) => Farable<T>} AttenuatorMaker
18
+ */
19
+
15
20
  /**
16
21
  * @template {(...args: unknown[]) => any} I
17
22
  * @typedef {import('./types').Callback<I>} Callback
@@ -187,9 +192,9 @@ harden(isCallback);
187
192
  /**
188
193
  * Prepare an attenuator class whose methods can be redirected via callbacks.
189
194
  *
190
- * @template {PropertyKey} M
195
+ * @template {{ [K in PropertyKey]: (this: any, ...args: unknown[]) => any}} Methods
191
196
  * @param {import('@agoric/zone').Zone} zone The zone in which to allocate attenuators.
192
- * @param {M[]} methodNames Methods to forward.
197
+ * @param {(keyof Methods)[]} methodNames Methods to forward.
193
198
  * @param {object} opts
194
199
  * @param {InterfaceGuard} [opts.interfaceGuard] An interface guard for the
195
200
  * new attenuator.
@@ -202,43 +207,44 @@ export const prepareAttenuator = (
202
207
  ) => {
203
208
  /**
204
209
  * @typedef {(this: any, ...args: unknown[]) => any} Method
205
- * @typedef {{ [K in M]: Method }} Methods
206
- * @typedef {{ [K in M]?: Callback<any> | null}} Overrides
210
+ * @typedef {{ [K in keyof Methods]?: Callback<any> | null}} Overrides
207
211
  */
208
- const methods = fromEntries(
209
- methodNames.map(key => {
210
- // Only allow the `PropertyKey` type for the target method key.
211
- if (!isPropertyKey(key)) {
212
- throw Fail`key ${q(key)} is not a PropertyKey`;
213
- }
212
+ const methods = /** @type {Methods} */ (
213
+ fromEntries(
214
+ methodNames.map(key => {
215
+ // Only allow the `PropertyKey` type for the target method key.
216
+ if (!isPropertyKey(key)) {
217
+ throw Fail`key ${q(key)} is not a PropertyKey`;
218
+ }
214
219
 
215
- const m = /** @type {Methods} */ ({
216
- // Explicitly use concise method syntax to preserve `this` but prevent
217
- // constructor behavior.
218
- /** @type {Method} */
219
- [key](...args) {
220
- // Support both synchronous and async callbacks.
221
- const cb = this.state.cbs[key];
222
- if (!cb) {
223
- const err = assert.error(
224
- `unimplemented ${q(tag)} method ${q(key)}`,
225
- );
226
- if (this.state.isSync) {
227
- throw err;
220
+ const m = /** @type {Methods} */ ({
221
+ // Explicitly use concise method syntax to preserve `this` but prevent
222
+ // constructor behavior.
223
+ /** @type {Method} */
224
+ [key](...args) {
225
+ // Support both synchronous and async callbacks.
226
+ const cb = this.state.cbs[key];
227
+ if (!cb) {
228
+ const err = assert.error(
229
+ `unimplemented ${q(tag)} method ${q(key)}`,
230
+ );
231
+ if (this.state.isSync) {
232
+ throw err;
233
+ }
234
+ return Promise.reject(err);
235
+ }
236
+ if (cb.isSync) {
237
+ return callSync(cb, ...args);
228
238
  }
229
- return Promise.reject(err);
230
- }
231
- if (cb.isSync) {
232
- return callSync(cb, ...args);
233
- }
234
- return callE(cb, ...args);
235
- },
236
- })[key];
237
- return /** @type {const} */ ([key, m]);
238
- }),
239
+ return callE(cb, ...args);
240
+ },
241
+ })[key];
242
+ return /** @type {const} */ ([key, m]);
243
+ }),
244
+ )
239
245
  );
240
246
 
241
- const methodKeys = /** @type {M[]} */ (ownKeys(methods));
247
+ const methodKeys = /** @type {(keyof Methods)[]} */ (ownKeys(methods));
242
248
 
243
249
  /**
244
250
  * Create an exo object whose behavior is composed from a default target
@@ -301,6 +307,7 @@ harden(prepareAttenuator);
301
307
  /**
302
308
  * Prepare an attenuator whose methodNames are derived from the interfaceGuard.
303
309
  *
310
+ * @template {{ [K in PropertyKey]: (this: any, ...args: unknown[]) => any}} Methods
304
311
  * @param {import('@agoric/zone').Zone} zone
305
312
  * @param {InterfaceGuard} interfaceGuard
306
313
  * @param {object} [opts]
@@ -309,6 +316,8 @@ harden(prepareAttenuator);
309
316
  export const prepareGuardedAttenuator = (zone, interfaceGuard, opts = {}) => {
310
317
  const { methodGuards } = interfaceGuard;
311
318
  const methodNames = ownKeys(methodGuards);
312
- return prepareAttenuator(zone, methodNames, { ...opts, interfaceGuard });
319
+ return /** @type {AttenuatorMaker<Methods>} */ (
320
+ prepareAttenuator(zone, methodNames, { ...opts, interfaceGuard })
321
+ );
313
322
  };
314
323
  harden(prepareGuardedAttenuator);