Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate types.json #2127

Closed
wants to merge 7 commits into from
Closed

Conversation

shannonwells
Copy link
Collaborator

@shannonwells shannonwells commented Aug 15, 2024

Goal

The goal of this PR is to generate a types.json file to help with being on Subscan et al.

Closes #2062

Checklist

  • Updated js/api-augment for Custom RPC OR Runtime API?
  • Added types.json generation to release.yml
  • Added types.json generation to package.json (two scripts, but postbuild doesn't seem to be used anywhere).
  • Added types.json generation to generate_js_definitions.js script so it is triggered by make js

Verify

  1. Check out this branch and run make js, which replicates the two needed steps run in CI.
  2. if you cd js/api-augment/dist, this should exist: json/types.json
  3. The content of types.json should look like the following, so that it would be included in the tarball if you run npm pack:
{
    "RpcEvent": {
        "phase": "Option<u32>",
        "pallet": "u8",
        "event": "u8",
        "data": "Vec<u8>"
    },
    "HandleSuffix": "u16",
    "HandleResponse": {
        "base_handle": "String",
        "canonical_base": "String",
        "suffix": "u16"
    },
    "PresumptiveSuffixesResponse": {
        "suffixes": "Vec<HandleSuffix>",
        "base_handle": "String"
    },
    "BlockPaginationRequest": {
        "from_block": "BlockNumber",
        "from_index": "u32",
        "to_block": "BlockNumber",
        "page_size": "u32"
    },
    "MessageResponse": {
        "payload": "Option<Vec<u8>>",
        "cid": "Option<Vec<u8>>",
        "provider_msa_id": "MessageSourceId",
        "msa_id": "Option<MessageSourceId>",
        "index": "u16",
        "block_number": "BlockNumber",
        "payload_length": "Option<u32>"
    },
    "BlockPaginationResponseMessage": {
        "content": "Vec<MessageResponse>",
        "has_next": "bool",
        "next_block": "Option<BlockNumber>",
        "next_index": "Option<u32>"
    },
    "MessageSourceId": "u64",
    "DelegatorId": "MessageSourceId",
    "ProviderId": "MessageSourceId",
    "KeyInfoResponse": {
        "msa_keys": "Vec<AccountId>",
        "msa_id": "MessageSourceId"
    },
    "SchemaGrantResponse": {
        "schema_id": "SchemaId",
        "revoked_at": "BlockNumber"
    },
    "DelegationResponse": {
        "provider_id": "ProviderId",
        "permissions": "Vec<SchemaGrantResponse>"
    },
    "SchemaId": "u16",
    "SchemaModel": "Vec<u8>",
    "SchemaVersion": "u8",
    "SchemaResponse": {
        "schema_id": "SchemaId",
        "model": "SchemaModel",
        "model_type": "ModelType",
        "payload_location": "PayloadLocation",
        "settings": "Vec<SchemaSetting>"
    },
    "ModelType": {
        "_enum": [
            "AvroBinary",
            "Parquet"
        ]
    },
    "PayloadLocation": {
        "_enum": [
            "OnChain",
            "IPFS",
            "Itemized",
            "Paginated"
        ]
    },
    "SchemaSetting": {
        "_enum": [
            "AppendOnly",
            "SignatureRequired"
        ]
    },
    "SchemaVersionResponse": {
        "schema_name": "String",
        "schema_version": "SchemaVersion",
        "schema_id": "SchemaId"
    },
    "PageId": "u16",
    "PageHash": "u32",
    "PageNonce": "u16",
    "ItemizedStorageResponse": {
        "index": "u16",
        "payload": "Vec<u8>"
    },
    "PaginatedStorageResponse": {
        "page_id": "PageId",
        "msa_id": "MessageSourceId",
        "schema_id": "SchemaId",
        "content_hash": "PageHash",
        "nonce": "PageNonce",
        "payload": "Vec<u8>"
    },
    "ItemizedStoragePageResponse": {
        "msa_id": "MessageSourceId",
        "schema_id": "SchemaId",
        "content_hash": "PageHash",
        "nonce": "PageNonce",
        "items": "Vec<ItemizedStorageResponse>"
    }
}

@shannonwells shannonwells requested review from demisx, a team, wilwade, mattheworris, enddynayn, aramikm, claireolmstead and JoeCap08055 and removed request for a team October 1, 2024 01:13
import { dirname } from 'path';

// Get the filename from the URL
const __filename = fileURLToPath(import.meta.url);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I did not know one could do this.

Copy link
Collaborator

@enddynayn enddynayn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM!

@@ -41,6 +41,7 @@ else
npm install # in case things have changed
npm run fetch:local
npm run build
npm run build:types-json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant since build:types-json is now part of the postbuild script

Copy link
Collaborator Author

@shannonwells shannonwells Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it because I was unsure. I'm not seeing where postbuild gets called. Do you know what it's for?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way npm scripts work, any script that starts with "pre" or "post" runs before/after the main script of the same name. So "postbuild" automatically runs after "build".

Copy link
Collaborator

@wilwade wilwade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes about where the output publishes

@@ -21,7 +21,8 @@
"prepackage": "cp CONTRIBUTING.md README.md ../../LICENSE ./dist",
"prebuild": "npm run generate",
"build": "tsc -p ./tsconfig.types.json && tsc -p ./tsconfig.cjs.json && tsc -p ./tsconfig.esm.json",
"postbuild": "npm run package",
"build:types-json": "node scripts/generate.mjs",
"postbuild": "npm run package && npm run build:types-json",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to copy the file to the dist directory to make sure that it is published in the npm api-augment package

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate.mjs output goes to dist/json/types.json

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see it now. I misread the output and didn't see it when I built it locally. Sorry about that!

run: npm run build
run: |
npm run build
npm run build:types-json
working-directory: js/api-augment
- name: Upload Dist Dir
uses: actions/upload-artifact@v4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds it to the artifacts for the workflow, but if we want to include it as an artifact as part of the release, we need to update these two steps to include it:

  • Publish Release Candidate on GitHub
  • Publish Full Release on GitHub

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish types.json with releases
4 participants