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

add Zod validation of state chain objects, infer types #1485

Merged
merged 19 commits into from
Mar 20, 2023
Merged

Conversation

mholtzman
Copy link
Collaborator

No description provided.

@mholtzman mholtzman marked this pull request as ready for review March 16, 2023 16:55

// Version number of latest known migration
const latest = Math.max(...Object.keys(migrations).map((n) => parseInt(n)))
const latest = migrations[migrations.length - 1].version
Copy link
Contributor

Choose a reason for hiding this comment

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

You might use dynamic import to avoid having to specify new migrations here each time, something like

  1. get array of dirNames in migrations dir
  2. map array to dynamic import of each migration index file
  3. sort as on line 9 above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought about this but deferred as it would make the migration process async and I thought it might be too much of a moving target to change the sync/async nature of the entire startup flow on top of all of these other changes. I do think this makes sense as a future optimization though as it will make it easier to manage migrations and not have to worry about adding them in two places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gonna just try a couple things though to see if there's something easy here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh yeah I think we'd need to use top-level await and that would require us changing our TS config, so at a minimum I think this is best left for another PR

export default {
version: 35,
migrate
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to use named exports and, e.g. import * as migration35 when exporting objects like this. If using the dynamic import I suggested above a named export will play nicer too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want to leave it as is, at least for now, as I don't want these modules exporting multiple different things (ie a field called version and function called migrate), I want them exporting just one thing: an object of type Migration

main/store/migrate/migrations/36/index.ts Show resolved Hide resolved
@mholtzman mholtzman merged commit 14b55a0 into canary Mar 20, 2023
@mholtzman mholtzman deleted the typed-state branch March 20, 2023 12:46
mholtzman added a commit that referenced this pull request Mar 22, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Apr 18, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Apr 18, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Apr 19, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Apr 19, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Apr 19, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Apr 20, 2023
* Integrate pylon evm (#1478)

* bump version

* remove infura and alchemy presets, use pylon

* update package lock

* remove gnosis chain preset

* fix chain name

* move migrations to separate files, use TS (#1482)

* add Zod validation of state chain objects, infer types (#1485)

* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing

* Choose summon keybinding (#1494)

Co-authored-by: goosewobbler <goosewobbler@pm.me>
Co-authored-by: goosewobbler <goosewobbler@protonmail.com>

* re-order migrations

* convert hot signers to TS, make tests run reliably

* more commits

* update comment

* remove unneeded assignment

* make worker interaction more typesafe

* remove unused code

* remove unused interface

* fix tests

* revert weird test change

* try revert file

* try move

* decouple worker controller and launch script, write controller tests

* fix worker exit in tests

* remove double cast

* rename some files

* remove ignore

* clean up worker interface

* last cleanup, fix typed data

* more type safety

* rebase, add bip39 type

* remove ts-ignores

* remove rebase artifact

* remove migration files

* update package lock

---------

Co-authored-by: goosewobbler <goosewobbler@pm.me>
Co-authored-by: goosewobbler <goosewobbler@protonmail.com>
mholtzman added a commit that referenced this pull request Jun 23, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
mholtzman added a commit that referenced this pull request Jun 23, 2023
* Integrate pylon evm (#1478)

* bump version

* remove infura and alchemy presets, use pylon

* update package lock

* remove gnosis chain preset

* fix chain name

* move migrations to separate files, use TS (#1482)

* add Zod validation of state chain objects, infer types (#1485)

* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing

* Choose summon keybinding (#1494)

Co-authored-by: goosewobbler <goosewobbler@pm.me>
Co-authored-by: goosewobbler <goosewobbler@protonmail.com>

* re-order migrations

* convert hot signers to TS, make tests run reliably

* more commits

* update comment

* remove unneeded assignment

* make worker interaction more typesafe

* remove unused code

* remove unused interface

* fix tests

* revert weird test change

* try revert file

* try move

* decouple worker controller and launch script, write controller tests

* fix worker exit in tests

* remove double cast

* rename some files

* remove ignore

* clean up worker interface

* last cleanup, fix typed data

* more type safety

* rebase, add bip39 type

* remove ts-ignores

* remove rebase artifact

* remove migration files

* update package lock

---------

Co-authored-by: goosewobbler <goosewobbler@pm.me>
Co-authored-by: goosewobbler <goosewobbler@protonmail.com>
mholtzman added a commit that referenced this pull request Jul 26, 2023
* add Zod validation of state chain objects, infer types

* move state files to TS, add more inferred types

* fix persist mock for tests

* add types to main state

* update test

* add mute notification schema

* move type export to state main

* move legacy file to TS

* try new migration format

* update legacy migrations and tests

* fix gas fees type

* fix gas type

* move legacy mapping

* final migration prototype

* finish migration poc

* finish cleaning up migrations

* test cleanup

* fix compilation error

* fix state parsing
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