Skip to content

Conversation

@SebastienGllmt
Copy link
Contributor

This is a port of Emurgo/cardano-serialization-lib#345

This one has some merge conflicts though. I did some cleanup so hopefully it shouldn't be too bad

so that we can get better type information than simply `any` in the
.ts/flow type annotations.

This is a multi-phase process:
1) Generate (using `schemars` traits) .json schemas for all types. This
is done by running the program in rust/json-gen which will export these
to rust/json-gen/schemas
2) Running scripts/run-json2ts.js to convert these to .ts files
3) We will need to convert the names to add in the JSON suffix to these
(not implemented yet)
4) Running scripts/json-ts-types.js to replace any `any` return types
with the correct *JSON type generated above

some files are hardcoded so they don't line up right now and some steps
aren't working as the schemas generated in 1) inline ALL referenced
schemas within a single schema so in step 2) we end up with a lot of
duplicate type definitions. We might be able to just have a stage to
remove duplicates from the schemas, or maybe there's a way to change the
json to ts tool to not do that.

Some types also throw runtime errors when serializing e.g. non-string
keys despite compiling fine since serde != serde_json
-get rid of [k: string]: unknown in structs
-add js:ts-json-gen command that runs all stages of rust->schemas->ts
gen
-fixes for some runtime errors (maps)
-adding some missing json impls
All definitions are wiped from schemas now and all references to those
local definitions are transformed into external definitions which we
pass in a param to the schema compiler to not generate definitions for.
Fixes for:
-Strings/empty MapOf_ defs
-to_js_value() to actually be a JsValue instead of to_json()
-swap out type defs in .ts with the JSON ones
-get rid of infinite recursion in certain types (no longer using
external $refs)
-finalize npm build commands
-probably some other fixes
Copy link
Contributor

@rooooooooob rooooooooob left a comment

Choose a reason for hiding this comment

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

I fixed some issues where scripts/files were still referring to cardano-serialization-lib + removed some unneeded build dependencies I forgot to remove before from the main Cargo.toml.

@SebastienGllmt SebastienGllmt merged commit 4591f86 into develop Mar 31, 2022
@SebastienGllmt SebastienGllmt deleted the dcspark/auto-json-to-ts branch March 31, 2022 22:00
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.

3 participants