{"id":23701255,"url":"https://github.com/sinclairnick/schema-shift","last_synced_at":"2026-02-21T17:01:21.696Z","repository":{"id":269354492,"uuid":"907149157","full_name":"sinclairnick/schema-shift","owner":"sinclairnick","description":"Utilities for converting and modifying validation schema","archived":false,"fork":false,"pushed_at":"2024-12-23T01:28:43.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T00:11:30.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinclairnick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-23T00:00:55.000Z","updated_at":"2025-01-30T01:22:40.000Z","dependencies_parsed_at":"2024-12-23T01:20:24.156Z","dependency_job_id":"95f74c6e-a556-48c0-afb8-b13166dc4315","html_url":"https://github.com/sinclairnick/schema-shift","commit_stats":null,"previous_names":["sinclairnick/schema-shift"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sinclairnick/schema-shift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairnick%2Fschema-shift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairnick%2Fschema-shift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairnick%2Fschema-shift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairnick%2Fschema-shift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinclairnick","download_url":"https://codeload.github.com/sinclairnick/schema-shift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairnick%2Fschema-shift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29688216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T15:51:39.154Z","status":"ssl_error","status_checked_at":"2026-02-21T15:49:03.425Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-12-30T09:35:15.766Z","updated_at":"2026-02-21T17:01:21.678Z","avatar_url":"https://github.com/sinclairnick.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schema Shift\n\nSchema shift provides a unified API for interacting with schema libraries programmatically and converting between schema libraries and formats. Modify, introspect and convert schemas defined using most popular validation libraries.\n\n```sh\nnpm i schema-shift\n```\n\n## Features\n\n-   [x] Generate JSON Schema definitions\n-   [x] Convert schema between various libraries\n-   [x] Universal interface for parsing values and inferring types\n-   [x] Traverse, introspect and transform schemas\n\n## Example Usage\n\n```ts\n// Define a schema\nconst MyZodSchema = z.object({ foo: z.string() });\n\n// Generate intermediate representation of the schema\nconst mySchemaDef = ZodShift.toDef(MyZodSchema);\n\n// Convert that into a different schema library...\nconst MyJoiSchema = JoiShift.fromDef(mySchemaDef);\n\n// ...or into JSON Schema\nconst jsonSchema = JoiShift.toJsonSchema(MyJoiSchema);\n```\n\n## Table of Contents\n\n-   [Why?](#why)\n-   [How?](#how)\n-   [API Reference](#api-reference)\n    -   [Core Functionality](#core-functionality)\n    -   [Utilities](#utilities)\n        -   [`Infer\u003cT\u003e`](#infer)\n        -   [`parse`](#parsevalue)\n        -   [`getParseFn`](#getparsefnschema)\n\n## Why?\n\nThe JS ecosystem boasts countless schema validation libraries. While this offers the benefit of choice, it also leads to fragmentation of the ecosystem and makes it harder for libraries to integrate with one another.\n\nSchema Shift unifies the ecosystem of validation libraries by making it trivial to manage, modify and transform schema between different forms. For library authors, this makes it easy to support many different validation/schema libraries without explicitly hand-rolling code for each.\n\n## How?\n\nSchema Shift transforms a given schema, defined using one of the many supported schema libraries, into an intermediate JSON Schema-like representation. In turn, this can be used to produce the equivalent schema in another library, modify the schema shape without touching any internals, or generate a JSON schema definition.\n\n```\n{Schema A} --[.toDef()]--\u003e {Abstract Definition} --[.fromDef()]--\u003e {Schema B}\n```\n\n## API Reference\n\nSchema Shift currently supports the following libraries.\n\n|             | import                                                        |\n| ----------- | ------------------------------------------------------------- |\n| Zod         | `import { ZodShift } from \"schema-shift/zod\"`                 |\n| Yup         | `import { YupShift } from \"schema-shift/yup\"`                 |\n| Joi         | `import { JoiShift } from \"schema-shift/joi\"`                 |\n| Valibot     | `import { ValibotShift } from \"schema-shift/valibot\"`         |\n| TypeBox     | `import { TypeBoxShift } from \"schema-shift/typebox\"`         |\n| Superstruct | `import { SuperstructShift } from \"schema-shift/superstruct\"` |\n| Runtypes    | `import { RuntypesShift } from \"schema-shift/runtypes\"`       |\n\n### Core Functionality\n\nSchema Shift exports library-specific namespaces which expose the functions listed below.\n\n#### `\u003cnamespace\u003e.toDef(schema)`\n\n\u003e Creates a definition (internal representation) for the given schema.\n\n```ts\nconst def = ZodShift.toDef(MyZodSchema);\n```\n\nWe can supply this `def`inition to one of the various formatter functions below. Modifying the `def` allows us to produces changes in any schema produced by the formatting functions which accept a `def` as input, listed below.\n\n#### `\u003cnamespace\u003e.fromDef(def)`\n\n\u003e Creates a schema from the given definition.\n\n```ts\nconst MyZodSchema = ZodShift.fromDef(def);\n```\n\nBy providing a `def` to a `.fromDef` function, we instantiate a schema corresponding to the namespace. In other words, `ZodShift.fromDef` creates a `zod` schema, and so forth.\n\nBecause `.fromDef` handles schema definitions programmatically, type information is _not_ preserved as if you were describing a schema explicitly. Therefore, this process is intended for runtime-specific use-cases, like validating values conform to a specific shape.\n\n#### `\u003cnamespace\u003e.toJsonSchema(schema)`\n\n\u003e Convert a schema to JSON Schema form.\n\n```ts\nconst jsonSchema = ZodShift.toJsonSchema(MyZodSchema);\n```\n\nWe can transform a schema into it's JSON Schema equivalent via `.toJsonSchema`, which can be used with OpenAPI specs, for example.\n\nThis function will require installing `@sinclair/typebox`.\n\n_Under the hood, this function is really just sugar for creating a `def` and passing it to `TypeBoxShift.fromDef`, which provides a JSON Schema representation._\n\n#### `\u003cnamespace\u003e.isSchema(value)`\n\n\u003e Determine if an unknown value is a schema object.\n\n```ts\nconst isZodSchema = ZodShift.isSchema(maybeZodSchema);\n```\n\nWe might not always have control over or knowledge of certain values in our programs. We can verify whether an unknown value is in fact a schema or not using `.isSchema`.\n\n_Note that `.isSchema` is only a heuristic, and determining schema type is not an exact science._\n\n### Utilities\n\nThese utilities are not library-specific, and can be imported via the root package.\n\n```ts\nimport { ... } from \"schema-shift\";\n```\n\n#### Infer\u003cT\u003e\n\nThe `Infer` type utility enables inferring the output type of any supported schema. Additionally, the `InferIn` utility can be used to infer the \"input\" type, meaning the expected type _before the schema performs any transformations_.\n\n```ts\nimport { Infer, InferIn } from \"schema-shift\";\n\nconst User = z.object({\n    id: z.number().transform(String),\n});\n\ntype User = Infer\u003ctypeof User\u003e;\n// { id: string }\n\ntype UserIn = InferIn\u003ctypeof User\u003e;\n// { id: number }\n```\n\n#### parse(value)\n\nThe `parse` function enables parsing any supported schema by providing the schema and value.\n\n```ts\nimport { parse, Parser } from \"schema-shift\";\n\nconst FooZod = z.object({ foo: z.boolean() });\nconst BarJoi = J.object({ bar: J.boolean() });\n\nparse(FooZod, { foo: true });\n// { foo: boolean }\n\nparse(BarJoi, { bar: true });\n// { bar: boolean }\n\n// Use the `Parser` type for custom functionality\nconst customParser = (parser: Parser, value: unknown) =\u003e {\n    return parse(parser, value);\n};\n```\n\n#### getParseFn(schema)\n\nGiven an unknown schema, returns a function that can parse values.\n\n```ts\nimport { getParseFn } from \"schema-shift\";\n\nconst FooZod = z.object({ foo: z.boolean() });\n\nconst parser = getParseFn(FooZod);\n\nparser({ foo: true });\n// { foo: boolean }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairnick%2Fschema-shift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinclairnick%2Fschema-shift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairnick%2Fschema-shift/lists"}