ethdebug / format

Smart contract debugging data format – Standards development working group
https://ethdebug.github.io/format/
43 stars 4 forks source link

Export schemas at type-level and improve a few other things slightly #78

Closed gnidan closed 7 months ago

gnidan commented 7 months ago

This PR adds a Schema<Id> helper type as an export of @ethdebug/format. This provides all the schemas at the type-level (e.g., Schema<"schema:ethdebug/format/type"> equals { readonly $schema: string; readonly $id: string; /* ... */ }).

This sort of thing is necessary because TypeScript is not capable of inferring const types except for value literals... so this PR modifies the existing schema-to-module codegen process to stringify each schema as an object literal (in addition to the existing output of all the YAMLs as string literals). This new object dump is initialized with our friend as const.

Anyway, this sort of thing is a bit extraneous, but I figured it couldn't hurt. Having these raw schema const types is necessary for certain general-purpose solutions like json-schema-to-ts, although I was unable to get that package working with these schemas (it seems like a lot of people are having trouble with their recent releases).

In addition, this PR has a few other code improvements that have been polluting my draft pointer-schema branch, so I'm including them here.