Skip to content

Commit

Permalink
chore(types): improve deeplyFulfilledObject return type
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 11, 2023
1 parent 31d8b10 commit 9d03e4c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 35 deletions.
3 changes: 2 additions & 1 deletion packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"devDependencies": {
"@endo/init": "^0.5.52",
"ava": "^5.1.0"
"ava": "^5.1.0",
"type-fest": "^3.5.7"
},
"author": "Agoric",
"license": "Apache-2.0",
Expand Down
8 changes: 2 additions & 6 deletions packages/internal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,12 @@ harden(bindAllMethods);

/**
* @template {{}} T
* @typedef {{ [K in keyof T]: DeeplyAwaited<T[K]> }} DeeplyAwaitedObject
* @typedef {{ [K in keyof T]: T[K] extends Function ? T[K] : DeeplyAwaited<T[K]> }} DeeplyAwaitedObject
*/

/**
* Caveats:
* - doesn't recur within Promise results
* - resulting type has wrapper in its name
*
* @template T
* @typedef {T extends PromiseLike<any> ? Awaited<T> : T extends {} ? DeeplyAwaitedObject<T> : Awaited<T>} DeeplyAwaited
* @typedef {T extends PromiseLike<any> ? Awaited<T> : T extends {} ? import('type-fest').Simplify<DeeplyAwaitedObject<T>> : Awaited<T>} DeeplyAwaited
*/

/**
Expand Down
20 changes: 20 additions & 0 deletions packages/internal/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import test from 'ava';
import '@endo/init';

import { Far } from '@endo/marshal';
import {
fromUniqueEntries,
objectMap,
Expand All @@ -10,6 +11,7 @@ import {
whileTrue,
untilTrue,
forever,
deeplyFulfilledObject,
} from '../src/utils.js';

test('fromUniqueEntries', t => {
Expand Down Expand Up @@ -57,6 +59,24 @@ test('objectMap', t => {
);
});

test('deeplyFulfilledObject', async t => {
const someFar = Far('somefar', { getAsync: () => Promise.resolve('async') });
const unfulfilled = harden({
obj1: {
obj2a: {
stringP: Promise.resolve('foo'),
},
obj2b: someFar,
},
});
const fulfilled = await deeplyFulfilledObject(unfulfilled);
// JS check that it's a now string
fulfilled.obj1.obj2a.stringP.length;
t.deepEqual(fulfilled, {
obj1: { obj2a: { stringP: 'foo' }, obj2b: someFar },
});
});

test('makeMeasureSeconds', async t => {
const times = [1000.25, 2000.75, NaN];
/** @type {() => number} */
Expand Down
68 changes: 40 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3302,13 +3302,13 @@
"@typescript-eslint/types" "5.33.0"
"@typescript-eslint/visitor-keys" "5.33.0"

"@typescript-eslint/scope-manager@5.49.0":
version "5.49.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.49.0.tgz#81b5d899cdae446c26ddf18bd47a2f5484a8af3e"
integrity sha512-clpROBOiMIzpbWNxCe1xDK14uPZh35u4QaZO1GddilEzoCLAEz4szb51rBpdgurs5k2YzPtJeTEN3qVbG+LRUQ==
"@typescript-eslint/scope-manager@5.51.0":
version "5.51.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.51.0.tgz#ad3e3c2ecf762d9a4196c0fbfe19b142ac498990"
integrity sha512-gNpxRdlx5qw3yaHA0SFuTjW4rxeYhpHxt491PEcKF8Z6zpq0kMhe0Tolxt0qjlojS+/wArSDlj/LtE69xUJphQ==
dependencies:
"@typescript-eslint/types" "5.49.0"
"@typescript-eslint/visitor-keys" "5.49.0"
"@typescript-eslint/types" "5.51.0"
"@typescript-eslint/visitor-keys" "5.51.0"

"@typescript-eslint/[email protected]":
version "5.33.0"
Expand All @@ -3324,10 +3324,10 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.33.0.tgz#d41c584831805554b063791338b0220b613a275b"
integrity sha512-nIMt96JngB4MYFYXpZ/3ZNU4GWPNdBbcB5w2rDOCpXOVUkhtNlG2mmm8uXhubhidRZdwMaMBap7Uk8SZMU/ppw==

"@typescript-eslint/types@5.49.0":
version "5.49.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.49.0.tgz#ad66766cb36ca1c89fcb6ac8b87ec2e6dac435c3"
integrity sha512-7If46kusG+sSnEpu0yOz2xFv5nRz158nzEXnJFCGVEHWnuzolXKwrH5Bsf9zsNlOQkyZuk0BZKKoJQI+1JPBBg==
"@typescript-eslint/types@5.51.0":
version "5.51.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.51.0.tgz#e7c1622f46c7eea7e12bbf1edfb496d4dec37c90"
integrity sha512-SqOn0ANn/v6hFn0kjvLwiDi4AzR++CBZz0NV5AnusT2/3y32jdc0G4woXPWHCumWtUXZKPAS27/9vziSsC9jnw==

"@typescript-eslint/[email protected]":
version "5.33.0"
Expand All @@ -3342,13 +3342,13 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/typescript-estree@5.49.0":
version "5.49.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.49.0.tgz#ebd6294c0ea97891fce6af536048181e23d729c8"
integrity sha512-PBdx+V7deZT/3GjNYPVQv1Nc0U46dAHbIuOG8AZ3on3vuEKiPDwFE/lG1snN2eUB9IhF7EyF7K1hmTcLztNIsA==
"@typescript-eslint/typescript-estree@5.51.0":
version "5.51.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.51.0.tgz#0ec8170d7247a892c2b21845b06c11eb0718f8de"
integrity sha512-TSkNupHvNRkoH9FMA3w7TazVFcBPveAAmb7Sz+kArY6sLT86PA5Vx80cKlYmd8m3Ha2SwofM1KwraF24lM9FvA==
dependencies:
"@typescript-eslint/types" "5.49.0"
"@typescript-eslint/visitor-keys" "5.49.0"
"@typescript-eslint/types" "5.51.0"
"@typescript-eslint/visitor-keys" "5.51.0"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
Expand All @@ -3368,15 +3368,15 @@
eslint-utils "^3.0.0"

"@typescript-eslint/utils@^5.10.0", "@typescript-eslint/utils@^5.10.2":
version "5.49.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.49.0.tgz#1c07923bc55ff7834dfcde487fff8d8624a87b32"
integrity sha512-cPJue/4Si25FViIb74sHCLtM4nTSBXtLx1d3/QT6mirQ/c65bV8arBEebBJJizfq8W2YyMoPI/WWPFWitmNqnQ==
version "5.51.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.51.0.tgz#074f4fabd5b12afe9c8aa6fdee881c050f8b4d47"
integrity sha512-76qs+5KWcaatmwtwsDJvBk4H76RJQBFe+Gext0EfJdC3Vd2kpY2Pf//OHHzHp84Ciw0/rYoGTDnIAr3uWhhJYw==
dependencies:
"@types/json-schema" "^7.0.9"
"@types/semver" "^7.3.12"
"@typescript-eslint/scope-manager" "5.49.0"
"@typescript-eslint/types" "5.49.0"
"@typescript-eslint/typescript-estree" "5.49.0"
"@typescript-eslint/scope-manager" "5.51.0"
"@typescript-eslint/types" "5.51.0"
"@typescript-eslint/typescript-estree" "5.51.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
semver "^7.3.7"
Expand All @@ -3389,12 +3389,12 @@
"@typescript-eslint/types" "5.33.0"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/visitor-keys@5.49.0":
version "5.49.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.49.0.tgz#2561c4da3f235f5c852759bf6c5faec7524f90fe"
integrity sha512-v9jBMjpNWyn8B6k/Mjt6VbUS4J1GvUlR4x3Y+ibnP1z7y7V4n0WRz+50DY6+Myj0UaXVSuUlHohO+eZ8IJEnkg==
"@typescript-eslint/visitor-keys@5.51.0":
version "5.51.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.51.0.tgz#c0147dd9a36c0de758aaebd5b48cae1ec59eba87"
integrity sha512-Oh2+eTdjHjOFjKA27sxESlA87YPSOJafGCR0md5oeMdh1ZcCfAGCIOL216uTBAkAIptvLIfKQhl7lHxMJet4GQ==
dependencies:
"@typescript-eslint/types" "5.49.0"
"@typescript-eslint/types" "5.51.0"
eslint-visitor-keys "^3.3.0"

"@web/browser-logs@^0.2.1", "@web/browser-logs@^0.2.2":
Expand Down Expand Up @@ -9674,7 +9674,14 @@ node-fetch-npm@^2.0.2:
json-parse-better-errors "^1.0.0"
safe-buffer "^5.1.1"

[email protected], node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.5:
[email protected], node-fetch@^2.6.5:
version "2.6.9"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.9.tgz#7c7f744b5cc6eb5fd404e0c7a9fec630a55657e6"
integrity sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1:
version "2.6.8"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.8.tgz#a68d30b162bc1d8fd71a367e81b997e1f4d4937e"
integrity sha512-RZ6dBYuj8dRSfxpUSu+NsdF1dpPpluJxwOp+6IoDp/sH2QNDSvurYsAa+F1WxY2RjA1iP93xhcsUoYbF2XBqVg==
Expand Down Expand Up @@ -12658,6 +12665,11 @@ type-fest@^0.8.1:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==

type-fest@^3.5.7:
version "3.5.7"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-3.5.7.tgz#1ee9efc9a172f4002c40b896689928a7bba537f2"
integrity sha512-6J4bYzb4sdkcLBty4XW7F18VPI66M4boXNE+CY40532oq2OJe6AVMB5NmjOp6skt/jw5mRjz/hLRpuglz0U+FA==

type-is@^1.6.16, type-is@~1.6.18:
version "1.6.18"
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131"
Expand Down

0 comments on commit 9d03e4c

Please sign in to comment.