{"id":14987576,"url":"https://github.com/tone-row/future-proof","last_synced_at":"2025-04-12T00:16:02.400Z","repository":{"id":195431275,"uuid":"692902711","full_name":"tone-row/future-proof","owner":"tone-row","description":"Write data migration logic in code so you can change the shape of your data confidently as your app evolves","archived":false,"fork":false,"pushed_at":"2023-09-29T18:45:23.000Z","size":289,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T11:32:40.907Z","etag":null,"topics":["context","data","localstorage","migration-tool","zustand"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tone-row.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-17T23:25:56.000Z","updated_at":"2024-06-05T20:28:01.000Z","dependencies_parsed_at":"2023-09-29T21:17:07.114Z","dependency_job_id":null,"html_url":"https://github.com/tone-row/future-proof","commit_stats":{"total_commits":29,"total_committers":1,"mean_commits":29.0,"dds":0.0,"last_synced_commit":"e6df5b98dd4666074e6c006ae08f1d86d7909e52"},"previous_names":["tone-row/object.upkeep"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tone-row%2Ffuture-proof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tone-row%2Ffuture-proof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tone-row%2Ffuture-proof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tone-row%2Ffuture-proof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tone-row","download_url":"https://codeload.github.com/tone-row/future-proof/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247856554,"owners_count":21007623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context","data","localstorage","migration-tool","zustand"],"created_at":"2024-09-24T14:14:57.525Z","updated_at":"2025-04-12T00:16:02.374Z","avatar_url":"https://github.com/tone-row.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# future-proof\n\nDealing with changes in the shape of your application's data over time can be a challenging task. The conventional methods often result in a complicated mess, making it hard to ensure that your data is always up-to-date. This is where [future-proof](https://github.com/tone-row/future-proof) comes into play.\n\nHere's how you can define migration steps using Future-proof:\n\n```typescript\n// In the beginning\nconst initialState = { x: 0, y: 0 };\nconst { version, migrate } = from({ x: 0, y: 0 }).init(initialState);\n```\nAs your data evolves, you can add migration steps:\n\n```typescript\n// Later on\nconst initialState = { x: 0, y: 0, z: 0 };\nconst { version, migrate } = from({ x: 0, y: 0 })\n  .to((state) =\u003e ({ ...state, z: 0 }))\n  .init(initialState);\n```\nEach to function takes a callback that receives the current state object and returns a new state object with the desired changes.\n\nApplying migrations is as simple as calling the migrate function with your data object and its version:\n\n```typescript\nconst data = migrate(\n  {\n    x: 200,\n    y: 200,\n  },\n  0\n);\n```\nFuture-proof has been designed with Zustand persisted stores in mind, making it a seamless integration:\n\n```typescript\nimport { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport { from } from \"future-proof\";\n\ntype State = { x: number; y: number; z: number; θ: number };\nconst initialState: State = {\n  x: 100,\n  y: 100,\n  z: 100,\n  θ: 0,\n};\n\nconst { version, migrate } = from({\n  x: 100,\n  y: 100,\n})\n  .to((data) =\u003e ({ ...data, z: 100 }))\n  .to((data) =\u003e ({ ...data, θ: 0 }))\n  .init(initialState);\n\nconst useStore = create\u003cState\u003e()(\n  persist((set) =\u003e initialState, {\n    name: \"my-persisted-store\",\n    version,\n    migrate,\n  })\n);\n```\n\nBy using Future-proof, you can confidently change the shape of your data as your app evolves, keeping your data migration logic clean and easy to read.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftone-row%2Ffuture-proof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftone-row%2Ffuture-proof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftone-row%2Ffuture-proof/lists"}