From c9684e831ec5a7f7e8159879e907e8fef97cdc09 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 2 Jun 2022 12:09:59 -0700 Subject: [PATCH 1/5] chore: bump typescript --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4e93306..2f58f31 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@agoric/babel-parser": "^7.6.4", "babel-eslint": ">=11.0.0-beta.2", "eslint-plugin-eslint-comments": "^3.1.2", - "typescript": "^4.0.3" + "typescript": "^4.7.2" }, "engines": { "node": ">=14.15.0" diff --git a/yarn.lock b/yarn.lock index ee790b1..f402769 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17029,10 +17029,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.0.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3" - integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw== +typescript@^4.7.2: + version "4.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4" + integrity sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A== uglify-js@^3.1.4: version "3.13.1" From 6b30c21626f2b8f091f17bdab63fcfa0e30d7f17 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 2 Jun 2022 12:22:09 -0700 Subject: [PATCH 2/5] chore: bump @endo deps --- package.json | 1 - ui/package.json | 8 ++++---- yarn.lock | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2f58f31..14995e5 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "_agstate/agoric-servers" ], "devDependencies": { - "@endo/init": "^0.5.33", "ses": "^0.15.7", "@typescript-eslint/parser": "^4.19.0", "ava": "^3.12.1", diff --git a/ui/package.json b/ui/package.json index 4831533..7df0e15 100644 --- a/ui/package.json +++ b/ui/package.json @@ -32,16 +32,16 @@ ] }, "dependencies": { - "@endo/captp": "^1.10.12", "@agoric/ertp": "dev", - "@endo/eventual-send": "^0.14.4", - "@endo/nat": "^4.1.4", "@agoric/notifier": "dev", + "@agoric/run-protocol": "dev", "@agoric/same-structure": "dev", "@agoric/ui-components": "dev", "@agoric/wallet-connection": "dev", "@agoric/zoe": "dev", - "@agoric/run-protocol": "dev", + "@endo/captp": "^2.0.7", + "@endo/eventual-send": "^0.15.3", + "@endo/nat": "^4.1.12", "@material-ui/core": "^4.11.3", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.57", diff --git a/yarn.lock b/yarn.lock index f402769..b296164 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2060,6 +2060,16 @@ "@endo/nat" "^4.1.8" "@endo/promise-kit" "^0.2.37" +"@endo/captp@^2.0.7": + version "2.0.7" + resolved "https://registry.yarnpkg.com/@endo/captp/-/captp-2.0.7.tgz#ec17c397a8c9f579771a2301ce8aa4ff9492e3f1" + integrity sha512-gMQe96BfSRUpCBDZtUJiX2ptpL1L91tmd23ooTupRp5L3M1aFO3u0juRO5dGImoTZa8+4iixn43YLxLRa8QRyA== + dependencies: + "@endo/eventual-send" "^0.15.3" + "@endo/marshal" "^0.6.7" + "@endo/nat" "^4.1.12" + "@endo/promise-kit" "^0.2.41" + "@endo/check-bundle@^0.1.2": version "0.1.2" resolved "https://registry.yarnpkg.com/@endo/check-bundle/-/check-bundle-0.1.2.tgz#0cdaf1436f858d08ea597081755602df2cdacfdc" @@ -2115,6 +2125,11 @@ resolved "https://registry.yarnpkg.com/@endo/eventual-send/-/eventual-send-0.14.8.tgz#0d95b5cd7e420219cdd84c43683bfbd0b6cd2ff6" integrity sha512-JIbzzIk1/Z+44O7+IuF5HfMzGu1txOvW5IJKu91syk//MIWU1+XQyPhwQKuWiZ2KX+ADdSPyNZTZjAN2IAE8gQ== +"@endo/eventual-send@^0.15.3": + version "0.15.3" + resolved "https://registry.yarnpkg.com/@endo/eventual-send/-/eventual-send-0.15.3.tgz#b6673c0953fca06941b2d06d49aafec6d012af04" + integrity sha512-RAV7Jup9YnFQWD9Po4T8t93eK6qTdvT0evu7j/BD9BfOthhuM18DYtd9j8oz/8qix59KuRKricf+c8WaHNiaog== + "@endo/far@^0.1.5": version "0.1.5" resolved "https://registry.yarnpkg.com/@endo/far/-/far-0.1.5.tgz#af2640dffba5cbb326af8ccf9c42831fa9a175f8" @@ -2196,6 +2211,20 @@ "@endo/nat" "^4.1.8" "@endo/promise-kit" "^0.2.37" +"@endo/marshal@^0.6.7": + version "0.6.7" + resolved "https://registry.yarnpkg.com/@endo/marshal/-/marshal-0.6.7.tgz#395366e346a7405ec57cc9057b9f211db54a9409" + integrity sha512-13mFxlWeSI0oOPaVfMNQ2UnNlwHtNf9Jg1Znez7A2o9bDZda0E/CoFyWfQMYbS2o2SWbn8CAjwTBUsjrSJWF7g== + dependencies: + "@endo/eventual-send" "^0.15.3" + "@endo/nat" "^4.1.12" + "@endo/promise-kit" "^0.2.41" + +"@endo/nat@^4.1.12": + version "4.1.12" + resolved "https://registry.yarnpkg.com/@endo/nat/-/nat-4.1.12.tgz#172b9552048349ed8a125344fdc72f14e7a30bd0" + integrity sha512-aDVsQK8jaq5WmKPp6CLuKKHPd4bMyX0+p0ZUuvUVnJ7v6OB6VesHF+1v7ss2Rx6XEv8FYuP1OdjJrsI/nQYkVw== + "@endo/nat@^4.1.4": version "4.1.4" resolved "https://registry.yarnpkg.com/@endo/nat/-/nat-4.1.4.tgz#7e9c45817b6ddb0332a115600b6e52d500efe9c7" @@ -2238,6 +2267,13 @@ dependencies: ses "^0.15.11" +"@endo/promise-kit@^0.2.41": + version "0.2.41" + resolved "https://registry.yarnpkg.com/@endo/promise-kit/-/promise-kit-0.2.41.tgz#aa8d9f1fafaedf7805fff05432e80d05b582fd57" + integrity sha512-VY3Ov/Ro0r05v8sUGRQnHhuwfwQvtecB3Uhntj2m5ClMeaSFj3hn8XIeWBDRK7jd+/gkCOBtTa67qnrC6ALg4w== + dependencies: + ses "^0.15.15" + "@endo/static-module-record@^0.6.12": version "0.6.12" resolved "https://registry.yarnpkg.com/@endo/static-module-record/-/static-module-record-0.6.12.tgz#5b65f89b449ef72fbb985d6beaee4dbc99579844" @@ -15737,6 +15773,11 @@ ses@^0.15.11: resolved "https://registry.yarnpkg.com/ses/-/ses-0.15.11.tgz#851cb6a20d8967537075d25bb0185051c28c23db" integrity sha512-lQg6q8/PVf+n18EjP+5Uv1tN9oVQ3br5QxJzPXoAVQleSYnlf20JY9coe7n1B9A6CtIKIHyr6m/TfskcRCufgA== +ses@^0.15.15: + version "0.15.15" + resolved "https://registry.yarnpkg.com/ses/-/ses-0.15.15.tgz#082923a1cabeac3151f9b3867e325fe447ce037d" + integrity sha512-sJM4HRlM3VouA3RhRmS7wG5MRQPqZZnc6O4BvAefU7yeM+qp8EUfGAWQ9iB/X5cNh3+m5N9lC7DEpyxQ+E4D+w== + ses@^0.15.7: version "0.15.7" resolved "https://registry.yarnpkg.com/ses/-/ses-0.15.7.tgz#53da049638bb34941befd1eccf34647c950f91a2" From 84449777919a6ae5b5e04d4f34f60853f16bb00a Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 2 Jun 2022 15:06:04 -0700 Subject: [PATCH 3/5] refactor: typecheck passing --- tsconfig.json | 18 +++++++++ ui/jsconfig.json | 11 ------ ui/src/types/types.js | 86 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 tsconfig.json delete mode 100644 ui/jsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8bc76d6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "es2020", + "noEmit": true, + "downlevelIteration": true, + "strictNullChecks": true, + "moduleResolution": "node", + "allowJs": true, + // Enable this to check .js files that don't have @ts-check + // "checkJs": true, + // for React + "allowSyntheticDefaultImports": true, + "jsx": "preserve" + }, + "include": ["ui/"], + "exclude": ["**/build", "**/public"] + } + \ No newline at end of file diff --git a/ui/jsconfig.json b/ui/jsconfig.json deleted file mode 100644 index 24769ca..0000000 --- a/ui/jsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "target": "es2020", - "noEmit": true, - "downlevelIteration": true, - "strictNullChecks": true, - "moduleResolution": "node", - "jsx": "preserve" - }, - "include": ["src/**/*.js", "src/**/*.jsx", "tools/**/*.js", "exports.js"] -} diff --git a/ui/src/types/types.js b/ui/src/types/types.js index c163650..3fcbef9 100644 --- a/ui/src/types/types.js +++ b/ui/src/types/types.js @@ -1,3 +1,83 @@ +// @ts-check +/** + * FIXME + * + * @typedef {any} Terms + * @typedef {'instance'} Instance + */ +/** + * @typedef {PromiseLike} ERef + * @template T + */ + +/** + * @template {AssetKind} [K=AssetKind] + * @typedef {object} Issuer + * + * The issuer cannot mint a new amount, but it can create empty purses + * and payments. The issuer can also transform payments (splitting + * payments, combining payments, burning payments, and claiming + * payments exclusively). The issuer should be gotten from a trusted + * source and then relied upon as the decider of whether an untrusted + * payment is valid. + * + * @property {() => Brand} getBrand Get the Brand for this Issuer. The + * Brand indicates the type of digital asset and is shared by the + * mint, the issuer, and any purses and payments of this particular + * kind. The brand is not closely held, so this function should not be + * trusted to identify an issuer alone. Fake digital assets and amount + * can use another issuer's brand. + * + * @property {() => string} getAllegedName Get the allegedName for + * this mint/issuer + * @property {() => AssetKind} getAssetKind Get the kind of + * MathHelpers used by this Issuer. + * @property {() => any} getDisplayInfo Give information to UI + * on how to display amounts for this issuer. + * @property {() => any} makeEmptyPurse Make an empty purse of this + * brand. + * @property {any} isLive + * @property {any} getAmountOf + * @property {any} burn + * @property {any} claim + * @property {any} combine + * @property {any} split + * @property {any} splitMany + */ +/** + * @typedef {'nat' | 'set' | 'copySet' | 'copyBag' } AssetKind + */ +/** + * @template {AssetKind} [K=AssetKind] + * @typedef {object} Brand + * @property {(allegedIssuer: ERef) => Promise} isMyIssuer + * Should be used with `issuer.getBrand` to ensure an issuer and brand match. + * @property {() => string} getAllegedName + * @property {() => any} getDisplayInfo + */ + +/** + * @template {AssetKind} [K=AssetKind] + * @typedef {object} Amount + * Amounts are descriptions of digital assets, answering the questions + * "how much" and "of what kind". Amounts are values labeled with a brand. + * AmountMath executes the logic of how amounts are changed when digital + * assets are merged, separated, or otherwise manipulated. For + * example, a deposit of 2 bucks into a purse that already has 3 bucks + * gives a new purse balance of 5 bucks. An empty purse has 0 bucks. AmountMath + * relies heavily on polymorphic MathHelpers, which manipulate the unbranded + * portion. + * + * @property {Brand} brand + * @property {any} value + */ + +/** + * @typedef {object} Ratio + * @property {Amount<'nat'>} numerator + * @property {Amount<'nat'>} denominator + */ + /** * @typedef {object} CollateralInfo * @@ -40,7 +120,7 @@ * this purse * @property {Petname} brandPetname the petname for this purse's brand * @property {Petname} pursePetname the petname for this purse - * @property {any} displayInfo the brand's displayInfo + * @property {import('@agoric/ertp/exported.js').DisplayInfo} displayInfo the brand's displayInfo * @property {any} value the purse's current balance * @property {any} currentAmountSlots * @property {any} currentAmount @@ -69,7 +149,7 @@ /** * @typedef {{ * instance?: Instance, - * ammAPI?: ERef, + * ammAPI?: ERef, * centralBrand?: Brand, * otherBrands?: Record, * }} AutoswapState @@ -103,7 +183,7 @@ * treasuryAPI: unknown, * runIssuer: Issuer, * runBrand: Brand, - * priceAuthority: ERef, + * priceAuthority: ERef, * minInitialDebt: Amount<'nat'>, * debtLimit: Amount<'nat'>, * }} VaultState From 22c6ede82ad5828577741dcded3445dad28c5f5b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 2 Jun 2022 15:08:16 -0700 Subject: [PATCH 4/5] ci: run typecheck --- .github/workflows/lint-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 7c80265..43840e4 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -71,5 +71,6 @@ jobs: - name: yarn build run: yarn build - run: yarn lint + - run: yarn tsc - name: yarn test (everything) run: yarn test From 2f02253466aa46c201c31de3bc01e3b8bea32dae Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 2 Jun 2022 15:36:20 -0700 Subject: [PATCH 5/5] ci: use typescript mode in jsdoc lint --- ui/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/package.json b/ui/package.json index 7df0e15..31ad10a 100644 --- a/ui/package.json +++ b/ui/package.json @@ -112,6 +112,9 @@ ] } }, + "jsdoc": { + "mode": "typescript" + }, "react": { "version": "detect" }