From e139744278d04c4c6a5f3128f9e37bc26b3f8ddf Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Mon, 6 May 2024 17:41:09 +0200 Subject: [PATCH] Bundle registry in npm package --- npm/CHANGELOG.md | 6 ++ npm/package.json | 10 +-- npm/pnpm-lock.yaml | 149 +++++++++++++++++++++------------------ npm/src/client.test.ts | 23 ++++++ npm/src/client.ts | 30 ++++---- npm/src/github.ts | 40 ----------- npm/src/json.ts | 42 +++++++++++ npm/src/registry.test.ts | 4 +- npm/src/registry.ts | 19 ++--- npm/src/utils.ts | 6 -- 10 files changed, 184 insertions(+), 145 deletions(-) create mode 100644 npm/src/client.test.ts delete mode 100644 npm/src/github.ts create mode 100644 npm/src/json.ts diff --git a/npm/CHANGELOG.md b/npm/CHANGELOG.md index 1a7ddf4..52badb1 100644 --- a/npm/CHANGELOG.md +++ b/npm/CHANGELOG.md @@ -1,5 +1,11 @@ # @penumbra-labs/registry +## 7.0.0 + +### Major Changes + +- Bundle registry in dist + ## 6.0.0 ### Major Changes diff --git a/npm/package.json b/npm/package.json index 8289b53..2857f24 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@penumbra-labs/registry", - "version": "6.0.0", + "version": "7.0.0", "description": "Chain and asset registry for Penumbra", "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -15,17 +15,17 @@ "test": "vitest run" }, "devDependencies": { - "@buf/penumbra-zone_penumbra.bufbuild_es": "1.9.0-20240501193854-ea3cc743390d.1", + "@buf/penumbra-zone_penumbra.bufbuild_es": "1.9.0-20240505174225-78be1d64b1cb.1", "@bufbuild/protobuf": "^1.9.0", "@changesets/cli": "^2.27.1", "@eslint/eslintrc": "^3.0.2", - "@eslint/js": "^9.1.1", - "eslint": "^9.1.1", + "@eslint/js": "^9.2.0", + "eslint": "^9.2.0", "prettier": "^3.2.5", "tsup": "^8.0.2", "typescript": "^5.4.5", "typescript-eslint": "^7.8.0", - "vitest": "^1.5.3" + "vitest": "^1.6.0" }, "files": [ "dist", diff --git a/npm/pnpm-lock.yaml b/npm/pnpm-lock.yaml index a4da558..2e352ee 100644 --- a/npm/pnpm-lock.yaml +++ b/npm/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: devDependencies: '@buf/penumbra-zone_penumbra.bufbuild_es': - specifier: 1.9.0-20240501193854-ea3cc743390d.1 - version: 1.9.0-20240501193854-ea3cc743390d.1(@bufbuild/protobuf@1.9.0) + specifier: 1.9.0-20240505174225-78be1d64b1cb.1 + version: 1.9.0-20240505174225-78be1d64b1cb.1(@bufbuild/protobuf@1.9.0) '@bufbuild/protobuf': specifier: ^1.9.0 version: 1.9.0 @@ -18,11 +18,11 @@ devDependencies: specifier: ^3.0.2 version: 3.0.2 '@eslint/js': - specifier: ^9.1.1 - version: 9.1.1 + specifier: ^9.2.0 + version: 9.2.0 eslint: - specifier: ^9.1.1 - version: 9.1.1 + specifier: ^9.2.0 + version: 9.2.0 prettier: specifier: ^3.2.5 version: 3.2.5 @@ -34,10 +34,10 @@ devDependencies: version: 5.4.5 typescript-eslint: specifier: ^7.8.0 - version: 7.8.0(eslint@9.1.1)(typescript@5.4.5) + version: 7.8.0(eslint@9.2.0)(typescript@5.4.5) vitest: - specifier: ^1.5.3 - version: 1.5.3 + specifier: ^1.6.0 + version: 1.6.0 packages: /@babel/code-frame@7.24.2: @@ -85,6 +85,7 @@ packages: /@buf/cosmos_cosmos-proto.bufbuild_es@1.9.0-20211202220400-1935555c206d.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-proto.bufbuild_es/-/cosmos_cosmos-proto.bufbuild_es-1.9.0-20211202220400-1935555c206d.1.tgz, } peerDependencies: @@ -96,6 +97,7 @@ packages: /@buf/cosmos_cosmos-sdk.bufbuild_es@1.9.0-20230522115704-e7a85cef453e.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-sdk.bufbuild_es/-/cosmos_cosmos-sdk.bufbuild_es-1.9.0-20230522115704-e7a85cef453e.1.tgz, } peerDependencies: @@ -110,6 +112,7 @@ packages: /@buf/cosmos_cosmos-sdk.bufbuild_es@1.9.0-20230719110346-aa25660f4ff7.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-sdk.bufbuild_es/-/cosmos_cosmos-sdk.bufbuild_es-1.9.0-20230719110346-aa25660f4ff7.1.tgz, } peerDependencies: @@ -124,6 +127,7 @@ packages: /@buf/cosmos_gogo-proto.bufbuild_es@1.9.0-20221020125208-34d970b699f8.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.9.0-20221020125208-34d970b699f8.1.tgz, } peerDependencies: @@ -135,6 +139,7 @@ packages: /@buf/cosmos_gogo-proto.bufbuild_es@1.9.0-20230509103710-5e5b9fdd0180.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.9.0-20230509103710-5e5b9fdd0180.1.tgz, } peerDependencies: @@ -146,6 +151,7 @@ packages: /@buf/cosmos_ibc.bufbuild_es@1.9.0-20230913112312-7ab44ae956a0.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_ibc.bufbuild_es/-/cosmos_ibc.bufbuild_es-1.9.0-20230913112312-7ab44ae956a0.1.tgz, } peerDependencies: @@ -162,6 +168,7 @@ packages: /@buf/cosmos_ics23.bufbuild_es@1.9.0-20221207100654-55085f7c710a.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/cosmos_ics23.bufbuild_es/-/cosmos_ics23.bufbuild_es-1.9.0-20221207100654-55085f7c710a.1.tgz, } peerDependencies: @@ -173,6 +180,7 @@ packages: /@buf/googleapis_googleapis.bufbuild_es@1.9.0-20220908150232-8d7204855ec1.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.9.0-20220908150232-8d7204855ec1.1.tgz, } peerDependencies: @@ -184,6 +192,7 @@ packages: /@buf/googleapis_googleapis.bufbuild_es@1.9.0-20221214150216-75b4300737fb.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.9.0-20221214150216-75b4300737fb.1.tgz, } peerDependencies: @@ -195,6 +204,7 @@ packages: /@buf/googleapis_googleapis.bufbuild_es@1.9.0-20230502210827-cc916c318597.1(@bufbuild/protobuf@1.9.0): resolution: { + registry: https://buf.build/gen/npm/v1/, tarball: https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.9.0-20230502210827-cc916c318597.1.tgz, } peerDependencies: @@ -203,10 +213,11 @@ packages: '@bufbuild/protobuf': 1.9.0 dev: true - /@buf/penumbra-zone_penumbra.bufbuild_es@1.9.0-20240501193854-ea3cc743390d.1(@bufbuild/protobuf@1.9.0): + /@buf/penumbra-zone_penumbra.bufbuild_es@1.9.0-20240505174225-78be1d64b1cb.1(@bufbuild/protobuf@1.9.0): resolution: { - tarball: https://buf.build/gen/npm/v1/@buf/penumbra-zone_penumbra.bufbuild_es/-/penumbra-zone_penumbra.bufbuild_es-1.9.0-20240501193854-ea3cc743390d.1.tgz, + registry: https://buf.build/gen/npm/v1/, + tarball: https://buf.build/gen/npm/v1/@buf/penumbra-zone_penumbra.bufbuild_es/-/penumbra-zone_penumbra.bufbuild_es-1.9.0-20240505174225-78be1d64b1cb.1.tgz, } peerDependencies: '@bufbuild/protobuf': ^1.9.0 @@ -1013,7 +1024,7 @@ packages: dev: true optional: true - /@eslint-community/eslint-utils@4.4.0(eslint@9.1.1): + /@eslint-community/eslint-utils@4.4.0(eslint@9.2.0): resolution: { integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==, @@ -1022,7 +1033,7 @@ packages: peerDependencies: eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 dependencies: - eslint: 9.1.1 + eslint: 9.2.0 eslint-visitor-keys: 3.4.3 dev: true @@ -1054,10 +1065,10 @@ packages: - supports-color dev: true - /@eslint/js@9.1.1: + /@eslint/js@9.2.0: resolution: { - integrity: sha512-5WoDz3Y19Bg2BnErkZTp0en+c/i9PvgFS7MBe1+m60HjFr0hrphlAGp4yzI7pxpt4xShln4ZyYp4neJm8hmOkQ==, + integrity: sha512-ESiIudvhoYni+MdsI8oD7skpprZ89qKocwRM2KEvhhBJ9nl5MRh7BXU5GTod7Mdygq+AUl+QzId6iWJKR/wABA==, } engines: { node: ^18.18.0 || ^20.9.0 || >=21.1.0 } dev: true @@ -1091,10 +1102,10 @@ packages: } dev: true - /@humanwhocodes/retry@0.2.3: + /@humanwhocodes/retry@0.2.4: resolution: { - integrity: sha512-X38nUbachlb01YMlvPFojKoiXq+LzZvuSce70KPMPdeM1Rj03k4dR7lDslhbqXn3Ang4EU3+EAmwEAsbrjHW3g==, + integrity: sha512-Ttl/jHpxfS3st5sxwICYfk4pOH0WrLI1SpW283GgQL7sCWU7EHIOhX4b4fkIxr3tkfzwg8+FNojtzsIEE7Ecgg==, } engines: { node: '>=18.18' } dev: true @@ -1460,7 +1471,7 @@ packages: } dev: true - /@typescript-eslint/eslint-plugin@7.8.0(@typescript-eslint/parser@7.8.0)(eslint@9.1.1)(typescript@5.4.5): + /@typescript-eslint/eslint-plugin@7.8.0(@typescript-eslint/parser@7.8.0)(eslint@9.2.0)(typescript@5.4.5): resolution: { integrity: sha512-gFTT+ezJmkwutUPmB0skOj3GZJtlEGnlssems4AjkVweUPGj7jRwwqg0Hhg7++kPGJqKtTYx+R05Ftww372aIg==, @@ -1475,13 +1486,13 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 7.8.0(eslint@9.1.1)(typescript@5.4.5) + '@typescript-eslint/parser': 7.8.0(eslint@9.2.0)(typescript@5.4.5) '@typescript-eslint/scope-manager': 7.8.0 - '@typescript-eslint/type-utils': 7.8.0(eslint@9.1.1)(typescript@5.4.5) - '@typescript-eslint/utils': 7.8.0(eslint@9.1.1)(typescript@5.4.5) + '@typescript-eslint/type-utils': 7.8.0(eslint@9.2.0)(typescript@5.4.5) + '@typescript-eslint/utils': 7.8.0(eslint@9.2.0)(typescript@5.4.5) '@typescript-eslint/visitor-keys': 7.8.0 debug: 4.3.4 - eslint: 9.1.1 + eslint: 9.2.0 graphemer: 1.4.0 ignore: 5.3.1 natural-compare: 1.4.0 @@ -1492,7 +1503,7 @@ packages: - supports-color dev: true - /@typescript-eslint/parser@7.8.0(eslint@9.1.1)(typescript@5.4.5): + /@typescript-eslint/parser@7.8.0(eslint@9.2.0)(typescript@5.4.5): resolution: { integrity: sha512-KgKQly1pv0l4ltcftP59uQZCi4HUYswCLbTqVZEJu7uLX8CTLyswqMLqLN+2QFz4jCptqWVV4SB7vdxcH2+0kQ==, @@ -1510,7 +1521,7 @@ packages: '@typescript-eslint/typescript-estree': 7.8.0(typescript@5.4.5) '@typescript-eslint/visitor-keys': 7.8.0 debug: 4.3.4 - eslint: 9.1.1 + eslint: 9.2.0 typescript: 5.4.5 transitivePeerDependencies: - supports-color @@ -1527,7 +1538,7 @@ packages: '@typescript-eslint/visitor-keys': 7.8.0 dev: true - /@typescript-eslint/type-utils@7.8.0(eslint@9.1.1)(typescript@5.4.5): + /@typescript-eslint/type-utils@7.8.0(eslint@9.2.0)(typescript@5.4.5): resolution: { integrity: sha512-H70R3AefQDQpz9mGv13Uhi121FNMh+WEaRqcXTX09YEDky21km4dV1ZXJIp8QjXc4ZaVkXVdohvWDzbnbHDS+A==, @@ -1541,9 +1552,9 @@ packages: optional: true dependencies: '@typescript-eslint/typescript-estree': 7.8.0(typescript@5.4.5) - '@typescript-eslint/utils': 7.8.0(eslint@9.1.1)(typescript@5.4.5) + '@typescript-eslint/utils': 7.8.0(eslint@9.2.0)(typescript@5.4.5) debug: 4.3.4 - eslint: 9.1.1 + eslint: 9.2.0 ts-api-utils: 1.3.0(typescript@5.4.5) typescript: 5.4.5 transitivePeerDependencies: @@ -1583,7 +1594,7 @@ packages: - supports-color dev: true - /@typescript-eslint/utils@7.8.0(eslint@9.1.1)(typescript@5.4.5): + /@typescript-eslint/utils@7.8.0(eslint@9.2.0)(typescript@5.4.5): resolution: { integrity: sha512-L0yFqOCflVqXxiZyXrDr80lnahQfSOfc9ELAAZ75sqicqp2i36kEZZGuUymHNFoYOqxRT05up760b4iGsl02nQ==, @@ -1592,13 +1603,13 @@ packages: peerDependencies: eslint: ^8.56.0 dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@9.1.1) + '@eslint-community/eslint-utils': 4.4.0(eslint@9.2.0) '@types/json-schema': 7.0.15 '@types/semver': 7.5.8 '@typescript-eslint/scope-manager': 7.8.0 '@typescript-eslint/types': 7.8.0 '@typescript-eslint/typescript-estree': 7.8.0(typescript@5.4.5) - eslint: 9.1.1 + eslint: 9.2.0 semver: 7.6.0 transitivePeerDependencies: - supports-color @@ -1616,32 +1627,32 @@ packages: eslint-visitor-keys: 3.4.3 dev: true - /@vitest/expect@1.5.3: + /@vitest/expect@1.6.0: resolution: { - integrity: sha512-y+waPz31pOFr3rD7vWTbwiLe5+MgsMm40jTZbQE8p8/qXyBX3CQsIXRx9XK12IbY7q/t5a5aM/ckt33b4PxK2g==, + integrity: sha512-ixEvFVQjycy/oNgHjqsL6AZCDduC+tflRluaHIzKIsdbzkLn2U/iBnVeJwB6HsIjQBdfMR8Z0tRxKUsvFJEeWQ==, } dependencies: - '@vitest/spy': 1.5.3 - '@vitest/utils': 1.5.3 + '@vitest/spy': 1.6.0 + '@vitest/utils': 1.6.0 chai: 4.4.1 dev: true - /@vitest/runner@1.5.3: + /@vitest/runner@1.6.0: resolution: { - integrity: sha512-7PlfuReN8692IKQIdCxwir1AOaP5THfNkp0Uc4BKr2na+9lALNit7ub9l3/R7MP8aV61+mHKRGiqEKRIwu6iiQ==, + integrity: sha512-P4xgwPjwesuBiHisAVz/LSSZtDjOTPYZVmNAnpHHSR6ONrf8eCJOFRvUwdHn30F5M1fxhqtl7QZQUk2dprIXAg==, } dependencies: - '@vitest/utils': 1.5.3 + '@vitest/utils': 1.6.0 p-limit: 5.0.0 pathe: 1.1.2 dev: true - /@vitest/snapshot@1.5.3: + /@vitest/snapshot@1.6.0: resolution: { - integrity: sha512-K3mvIsjyKYBhNIDujMD2gfQEzddLe51nNOAf45yKRt/QFJcUIeTQd2trRvv6M6oCBHNVnZwFWbQ4yj96ibiDsA==, + integrity: sha512-+Hx43f8Chus+DCmygqqfetcAZrDJwvTj0ymqjQq4CvmpKFSTVteEOBzCusu1x2tt4OJcvBflyHUE0DZSLgEMtQ==, } dependencies: magic-string: 0.30.10 @@ -1649,19 +1660,19 @@ packages: pretty-format: 29.7.0 dev: true - /@vitest/spy@1.5.3: + /@vitest/spy@1.6.0: resolution: { - integrity: sha512-Llj7Jgs6lbnL55WoshJUUacdJfjU2honvGcAJBxhra5TPEzTJH8ZuhI3p/JwqqfnTr4PmP7nDmOXP53MS7GJlg==, + integrity: sha512-leUTap6B/cqi/bQkXUu6bQV5TZPx7pmMBKBQiI0rJA8c3pB56ZsaTbREnF7CJfmvAS4V2cXIBAh/3rVwrrCYgw==, } dependencies: tinyspy: 2.2.1 dev: true - /@vitest/utils@1.5.3: + /@vitest/utils@1.6.0: resolution: { - integrity: sha512-rE9DTN1BRhzkzqNQO+kw8ZgfeEBCLXiHJwetk668shmNBpSagQxneT5eSqEBLP+cqSiAeecvQmbpFfdMyLcIQA==, + integrity: sha512-21cPiuGMoMZwiOHa2i4LXkMkMkCGzA+MVFV70jRwHo95dL4x/ts5GZhML1QWuy7yfp3WzK3lRvZi3JnXTYqrBw==, } dependencies: diff-sequences: 29.6.3 @@ -2650,21 +2661,21 @@ packages: engines: { node: ^18.18.0 || ^20.9.0 || >=21.1.0 } dev: true - /eslint@9.1.1: + /eslint@9.2.0: resolution: { - integrity: sha512-b4cRQ0BeZcSEzPpY2PjFY70VbO32K7BStTGtBsnIGdTSEEQzBi8hPBcGQmTG2zUvFr9uLe0TK42bw8YszuHEqg==, + integrity: sha512-0n/I88vZpCOzO+PQpt0lbsqmn9AsnsJAQseIqhZFI8ibQT0U1AkEKRxA3EVMos0BoHSXDQvCXY25TUjB5tr8Og==, } engines: { node: ^18.18.0 || ^20.9.0 || >=21.1.0 } hasBin: true dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@9.1.1) + '@eslint-community/eslint-utils': 4.4.0(eslint@9.2.0) '@eslint-community/regexpp': 4.10.0 '@eslint/eslintrc': 3.0.2 - '@eslint/js': 9.1.1 + '@eslint/js': 9.2.0 '@humanwhocodes/config-array': 0.13.0 '@humanwhocodes/module-importer': 1.0.1 - '@humanwhocodes/retry': 0.2.3 + '@humanwhocodes/retry': 0.2.4 '@nodelib/fs.walk': 1.2.8 ajv: 6.12.6 chalk: 4.1.2 @@ -3101,7 +3112,7 @@ packages: foreground-child: 3.1.1 jackspeak: 2.3.6 minimatch: 9.0.4 - minipass: 7.0.4 + minipass: 7.1.0 path-scurry: 1.10.2 dev: true @@ -3972,10 +3983,10 @@ packages: kind-of: 6.0.3 dev: true - /minipass@7.0.4: + /minipass@7.1.0: resolution: { - integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==, + integrity: sha512-oGZRv2OT1lO2UF1zUcwdTb3wqUwI0kBGTgt/T7OdSj6M6N5m3o5uPf0AIW6lVxGGoiWUR7e2AwTE+xiwK8WQig==, } engines: { node: '>=16 || 14 >=14.17' } dev: true @@ -4298,7 +4309,7 @@ packages: engines: { node: '>=16 || 14 >=14.17' } dependencies: lru-cache: 10.2.2 - minipass: 7.0.4 + minipass: 7.1.0 dev: true /path-type@4.0.0: @@ -5397,7 +5408,7 @@ packages: possible-typed-array-names: 1.0.0 dev: true - /typescript-eslint@7.8.0(eslint@9.1.1)(typescript@5.4.5): + /typescript-eslint@7.8.0(eslint@9.2.0)(typescript@5.4.5): resolution: { integrity: sha512-sheFG+/D8N/L7gC3WT0Q8sB97Nm573Yfr+vZFzl/4nBdYcmviBPtwGSX9TJ7wpVg28ocerKVOt+k2eGmHzcgVA==, @@ -5410,10 +5421,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 7.8.0(@typescript-eslint/parser@7.8.0)(eslint@9.1.1)(typescript@5.4.5) - '@typescript-eslint/parser': 7.8.0(eslint@9.1.1)(typescript@5.4.5) - '@typescript-eslint/utils': 7.8.0(eslint@9.1.1)(typescript@5.4.5) - eslint: 9.1.1 + '@typescript-eslint/eslint-plugin': 7.8.0(@typescript-eslint/parser@7.8.0)(eslint@9.2.0)(typescript@5.4.5) + '@typescript-eslint/parser': 7.8.0(eslint@9.2.0)(typescript@5.4.5) + '@typescript-eslint/utils': 7.8.0(eslint@9.2.0)(typescript@5.4.5) + eslint: 9.2.0 typescript: 5.4.5 transitivePeerDependencies: - supports-color @@ -5474,10 +5485,10 @@ packages: spdx-expression-parse: 3.0.1 dev: true - /vite-node@1.5.3: + /vite-node@1.6.0: resolution: { - integrity: sha512-axFo00qiCpU/JLd8N1gu9iEYL3xTbMbMrbe5nDp9GL0nb6gurIdZLkkFogZXWnE8Oyy5kfSLwNVIcVsnhE7lgQ==, + integrity: sha512-de6HJgzC+TFzOu0NTC4RAIsyf/DY/ibWDYQUcuEA84EMHhcefTUGkjFHKKEJhQN4A+6I0u++kr3l36ZF2d7XRw==, } engines: { node: ^18.0.0 || >=20.0.0 } hasBin: true @@ -5536,18 +5547,18 @@ packages: fsevents: 2.3.3 dev: true - /vitest@1.5.3: + /vitest@1.6.0: resolution: { - integrity: sha512-2oM7nLXylw3mQlW6GXnRriw+7YvZFk/YNV8AxIC3Z3MfFbuziLGWP9GPxxu/7nRlXhqyxBikpamr+lEEj1sUEw==, + integrity: sha512-H5r/dN06swuFnzNFhq/dnz37bPXnq8xB2xB5JOVk8K09rUtoeNN+LHWkoQ0A/i3hvbUKKcCei9KpbxqHMLhLLA==, } engines: { node: ^18.0.0 || >=20.0.0 } hasBin: true peerDependencies: '@edge-runtime/vm': '*' '@types/node': ^18.0.0 || >=20.0.0 - '@vitest/browser': 1.5.3 - '@vitest/ui': 1.5.3 + '@vitest/browser': 1.6.0 + '@vitest/ui': 1.6.0 happy-dom: '*' jsdom: '*' peerDependenciesMeta: @@ -5564,11 +5575,11 @@ packages: jsdom: optional: true dependencies: - '@vitest/expect': 1.5.3 - '@vitest/runner': 1.5.3 - '@vitest/snapshot': 1.5.3 - '@vitest/spy': 1.5.3 - '@vitest/utils': 1.5.3 + '@vitest/expect': 1.6.0 + '@vitest/runner': 1.6.0 + '@vitest/snapshot': 1.6.0 + '@vitest/spy': 1.6.0 + '@vitest/utils': 1.6.0 acorn-walk: 8.3.2 chai: 4.4.1 debug: 4.3.4 @@ -5582,7 +5593,7 @@ packages: tinybench: 2.8.0 tinypool: 0.8.4 vite: 5.2.11 - vite-node: 1.5.3 + vite-node: 1.6.0 why-is-node-running: 2.2.2 transitivePeerDependencies: - less diff --git a/npm/src/client.test.ts b/npm/src/client.test.ts new file mode 100644 index 0000000..a413446 --- /dev/null +++ b/npm/src/client.test.ts @@ -0,0 +1,23 @@ +import { describe, it, expect } from 'vitest'; +import { ChainRegistryClient } from './client'; +import { Registry } from './registry'; + +describe('ChainRegistryClient', () => { + const client = new ChainRegistryClient(); + + it('returns a Registry object for valid chain IDs', () => { + const registry = client.get('penumbra-testnet-deimos-7'); + expect(registry).toBeInstanceOf(Registry); + expect(registry.chainId).toEqual('penumbra-testnet-deimos-7'); + }); + + it('throws an error when no registry is found', () => { + expect(() => client.get('unknown')).toThrow('Registry not found for unknown'); + }); + + it('handles preview chain IDs by swapping them', () => { + const registry = client.get('penumbra-testnet-deimos-7-711be12a'); + expect(registry).toBeInstanceOf(Registry); + expect(registry.chainId).toEqual('penumbra-testnet-deimos-7'); + }); +}); diff --git a/npm/src/client.ts b/npm/src/client.ts index 7e0f45d..d413b0e 100644 --- a/npm/src/client.ts +++ b/npm/src/client.ts @@ -1,25 +1,25 @@ -import { GithubFetcher } from './github'; import { deriveTestnetChainIdFromPreview, isTestnetPreviewChainId } from './utils'; import { Registry } from './registry'; +import { allJsonRegistries } from './json'; export class ChainRegistryClient { - private readonly github: GithubFetcher; + get(chainId: string): Registry { + const chainIdToIndex = this.swapIfPreviewChain(chainId); + const jsonRegistry = allJsonRegistries[chainIdToIndex]; + if (!jsonRegistry) { + throw new Error(`Registry not found for ${chainIdToIndex}`); + } - constructor() { - this.github = new GithubFetcher(); + return new Registry(jsonRegistry); } - async get(chainId: string): Promise { - if (isTestnetPreviewChainId(chainId)) { - const derivedChainId = deriveTestnetChainIdFromPreview(chainId); - if (derivedChainId) { - return this.github.fetchRegistryData(derivedChainId); - } - } - return this.github.fetchRegistryData(chainId); - } + private swapIfPreviewChain(chainId: string): string { + if (!isTestnetPreviewChainId(chainId)) return chainId; - clearCache() { - this.github.clearCache(); + const derivedChainId = deriveTestnetChainIdFromPreview(chainId); + if (!derivedChainId) { + throw new Error(`Chain id could not be derived from testnet preview chain: ${chainId}`); + } + return derivedChainId; } } diff --git a/npm/src/github.ts b/npm/src/github.ts deleted file mode 100644 index 8b5005f..0000000 --- a/npm/src/github.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; -import { Jsonified } from './utils'; -import { Base64AssetId, Chain, Registry, Rpc } from './registry'; - -export interface GithubRegistryResponse { - chainId: string; - ibcConnections: Chain[]; - rpcs: Rpc[]; - assetById: Record>; - stakingAssetId: Base64AssetId; - numeraires: Base64AssetId[]; -} - -const REGISTRY_BASE_URL = 'https://raw.githubusercontent.com/prax-wallet/registry/main/registry'; - -type ChainId = string; - -export class GithubFetcher { - private cache: Record = {}; - - async fetchRegistryData(chainId: ChainId): Promise { - if (this.cache[chainId]) return this.cache[chainId]!; - const response = await this.typedFetcher( - `${REGISTRY_BASE_URL}/${chainId}.json`, - ); - return new Registry(response); - } - - clearCache(): void { - this.cache = {}; - } - - private async typedFetcher(url: string): Promise { - const response = await fetch(url); - if (!response.ok) { - throw new Error(`Failed to fetch from: ${url}`); - } - return (await response.json()) as T; - } -} diff --git a/npm/src/json.ts b/npm/src/json.ts new file mode 100644 index 0000000..4d9f6c6 --- /dev/null +++ b/npm/src/json.ts @@ -0,0 +1,42 @@ +import * as Deimos6 from '../../registry/penumbra-testnet-deimos-6.json'; +import * as Deimos7 from '../../registry/penumbra-testnet-deimos-7.json'; +import { Base64AssetId, Chain, Rpc } from './registry'; + +export interface JsonRegistry { + chainId: string; + ibcConnections: Chain[]; + rpcs: Rpc[]; + assetById: Record; + stakingAssetId: Base64AssetId; + numeraires: Base64AssetId[]; +} + +interface JsonMetadata { + description?: string; + denomUnits: DenomUnit[]; + base: string; + display: string; + name?: string; + symbol: string; + penumbraAssetId: PenumbraAssetId; + images?: Image[]; +} + +interface DenomUnit { + denom: string; + exponent?: number; +} + +interface PenumbraAssetId { + inner: string; +} + +interface Image { + png?: string; + svg?: string; +} + +export const allJsonRegistries: Record = { + 'penumbra-testnet-deimos-6': Deimos6, + 'penumbra-testnet-deimos-7': Deimos7, +}; diff --git a/npm/src/registry.test.ts b/npm/src/registry.test.ts index a047c1c..fe89119 100644 --- a/npm/src/registry.test.ts +++ b/npm/src/registry.test.ts @@ -1,10 +1,10 @@ import { describe, expect, it } from 'vitest'; import { base64ToUint8Array } from './utils'; import { Registry } from './registry'; -import { GithubRegistryResponse } from './github'; import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; +import { JsonRegistry } from './json'; -const testRegistry: GithubRegistryResponse = { +const testRegistry: JsonRegistry = { chainId: 'penumbra-testnet-deimos-6', ibcConnections: [ { diff --git a/npm/src/registry.ts b/npm/src/registry.ts index 19f5475..4908826 100644 --- a/npm/src/registry.ts +++ b/npm/src/registry.ts @@ -3,7 +3,8 @@ import { Metadata, } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; import { base64ToUint8Array, mapObjectValues, Stringified, uint8ArrayToBase64 } from './utils'; -import { GithubRegistryResponse } from './github'; +import { JsonRegistry } from './json'; +import { JsonValue } from '@bufbuild/protobuf'; export type Base64AssetId = Stringified; @@ -36,13 +37,15 @@ export class Registry { private readonly assetById: Record; - constructor(response: GithubRegistryResponse) { - this.chainId = response.chainId; - this.ibcConnections = response.ibcConnections; - this.rpcs = response.rpcs; - this.assetById = mapObjectValues(response.assetById, id => Metadata.fromJson(id)); - this.stakingAssetId = new AssetId({ inner: base64ToUint8Array(response.stakingAssetId) }); - this.numeraires = response.numeraires.map(a => new AssetId({ inner: base64ToUint8Array(a) })); + constructor(r: JsonRegistry) { + this.chainId = r.chainId; + this.ibcConnections = r.ibcConnections; + this.rpcs = r.rpcs; + this.assetById = mapObjectValues(r.assetById, jsonMetadata => + Metadata.fromJson(jsonMetadata as unknown as JsonValue), + ); + this.stakingAssetId = new AssetId({ inner: base64ToUint8Array(r.stakingAssetId) }); + this.numeraires = r.numeraires.map(a => new AssetId({ inner: base64ToUint8Array(a) })); } getMetadata(id: AssetId): Metadata { diff --git a/npm/src/utils.ts b/npm/src/utils.ts index 25cfb83..e675e7b 100644 --- a/npm/src/utils.ts +++ b/npm/src/utils.ts @@ -1,9 +1,3 @@ -import { JsonValue } from '@bufbuild/protobuf'; - -// @ts-expect-error alias for dev only -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export type Jsonified = JsonValue; - // @ts-expect-error alias for dev only // eslint-disable-next-line @typescript-eslint/no-unused-vars export type Stringified = string;