@xata.io/pgroll
Advanced tools
Comparing version 0.0.0-alpha.vf0d55c85ef5c649e4f49105bc342dc7e70d49ca9 to 0.0.0-alpha.vf58a3c229cee57bd4c4c22a72c3826618cdc9b94
# @xata.io/pgroll | ||
## 0.0.0-alpha.vf0d55c85ef5c649e4f49105bc342dc7e70d49ca9 | ||
## 0.0.0-alpha.vf58a3c229cee57bd4c4c22a72c3826618cdc9b94 | ||
### Minor Changes | ||
### Patch Changes | ||
- [#1250](https://github.com/xataio/client-ts/pull/1250) [`5c7f7ec`](https://github.com/xataio/client-ts/commit/5c7f7ec8f85428c8c5de3cc6e49d95d261b340f0) Thanks [@SferaDev](https://github.com/SferaDev)! - Initial release | ||
- Force canary build | ||
## 0.4.4 | ||
### Patch Changes | ||
- [#1250](https://github.com/xataio/client-ts/pull/1250) [`9a6af72`](https://github.com/xataio/client-ts/commit/9a6af72ba4dd7880e8196a0a57d4133930957add) Thanks [@SferaDev](https://github.com/SferaDev)! - Add new package for pgroll migrations |
{ | ||
"name": "@xata.io/pgroll", | ||
"version": "0.0.0-alpha.vf0d55c85ef5c649e4f49105bc342dc7e70d49ca9", | ||
"version": "0.0.0-alpha.vf58a3c229cee57bd4c4c22a72c3826618cdc9b94", | ||
"description": "Migration tool for PostgreSQL", | ||
@@ -29,7 +29,7 @@ "type": "module", | ||
"zod": "^3.22.4", | ||
"zod-to-json-schema": "^3.21.4" | ||
"zod-to-json-schema": "^3.22.4" | ||
}, | ||
"devDependencies": { | ||
"ts-morph": "^21.0.1", | ||
"tsx": "^4.1.2" | ||
"tsx": "^4.7.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "scripts": { |
@@ -13,2 +13,3 @@ import fs from 'fs/promises'; | ||
properties: Record<string, Definition>; | ||
oneOf?: unknown[]; | ||
required?: string[]; | ||
@@ -34,2 +35,4 @@ description?: string; | ||
properties: z.record(DefinitionSchema), | ||
// TODO: Add full support for oneOf | ||
oneOf: z.array(z.any()).optional(), | ||
required: z.array(z.string()).optional(), | ||
@@ -151,3 +154,4 @@ description: z.string().optional(), | ||
async function main() { | ||
const response = await fetch(PGROLL_JSON_SCHEMA_URL).then((response) => response.json()); | ||
const url = process.env.PGROLL_JSON_SCHEMA_URL ?? PGROLL_JSON_SCHEMA_URL; | ||
const response = await fetch(url).then((response) => response.json()); | ||
const schema = JSONSchema.parse(response); | ||
@@ -157,6 +161,10 @@ | ||
const project = new Project({ compilerOptions: { target: ScriptTarget.ESNext } }); | ||
const file = project.createSourceFile('types.ts', '', { overwrite: true }); | ||
const schemaFile = project.createSourceFile('schema.ts', '', { overwrite: true }); | ||
const typesFile = project.createSourceFile('types.ts', '', { overwrite: true }); | ||
// Write the JSON schema to a file | ||
schemaFile.addStatements(`export const schema = ${JSON.stringify(response, null, 2)} as const;`); | ||
// Add import statements | ||
file.addImportDeclaration({ moduleSpecifier: 'zod', namedImports: ['z'] }); | ||
typesFile.addImportDeclaration({ moduleSpecifier: 'zod', namedImports: ['z'] }); | ||
@@ -172,5 +180,5 @@ // Topologically sort the schema definitions | ||
// Add a type alias for the Zod type | ||
file.addTypeAlias({ name, type: `z.infer<typeof ${name}Definition>`, isExported: true }); | ||
typesFile.addTypeAlias({ name, type: `z.infer<typeof ${name}Definition>`, isExported: true }); | ||
// Add a variable statement for the Zod schema | ||
file.addVariableStatement({ | ||
typesFile.addVariableStatement({ | ||
declarationKind: VariableDeclarationKind.Const, | ||
@@ -183,3 +191,3 @@ declarations: [{ name: `${name}Definition`, initializer: statement }], | ||
// Add a type alias for the OperationType | ||
file.addTypeAlias({ | ||
typesFile.addTypeAlias({ | ||
name: 'OperationType', | ||
@@ -192,3 +200,3 @@ type: `(typeof operationTypes)[number]`, | ||
const operationTypes = (schema.$defs['PgRollOperation'] as any).anyOf.flatMap((def) => Object.keys(def.properties)); | ||
file.addVariableStatement({ | ||
typesFile.addVariableStatement({ | ||
declarationKind: VariableDeclarationKind.Const, | ||
@@ -205,5 +213,6 @@ declarations: [ | ||
// Write the generated TypeScript code to a file | ||
await fs.writeFile('src/types.ts', prettier.format(file.getFullText(), { parser: 'typescript' })); | ||
await fs.writeFile('src/schema.ts', prettier.format(schemaFile.getFullText(), { parser: 'typescript' })); | ||
await fs.writeFile('src/types.ts', prettier.format(typesFile.getFullText(), { parser: 'typescript' })); | ||
} | ||
main(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
228616
4784
4
Updatedzod-to-json-schema@^3.22.4