From 13e62a4a1a9671ded893cb7d7945d6fe55a2fa8c Mon Sep 17 00:00:00 2001 From: Josh Bowling Date: Tue, 17 Dec 2024 12:11:20 +0900 Subject: [PATCH] Add convert serial option to generate-types command Change-type: minor --- package.json | 2 +- src/bin/abstract-sql-compiler.ts | 22 ++++++++++++++++++---- src/migrator/migrations.ts | 2 +- src/sbvr-api/dev.ts | 2 +- src/sbvr-api/user.ts | 2 +- src/tasks/tasks.ts | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 627563270..444e70abc 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "dependencies": { "@balena/abstract-sql-compiler": "^10.1.0", - "@balena/abstract-sql-to-typescript": "^5.0.1", + "@balena/abstract-sql-to-typescript": "^5.1.0", "@balena/env-parsing": "^1.2.0", "@balena/lf-to-abstract-sql": "^5.0.3", "@balena/odata-parser": "^3.1.2", diff --git a/src/bin/abstract-sql-compiler.ts b/src/bin/abstract-sql-compiler.ts index b4d058517..6bc65575b 100644 --- a/src/bin/abstract-sql-compiler.ts +++ b/src/bin/abstract-sql-compiler.ts @@ -18,7 +18,13 @@ const runCompile = async (inputFile: string, outputFile?: string) => { writeSqlModel(sqlModel, outputFile); }; -const generateTypes = async (inputFile: string, outputFile?: string) => { +const generateTypes = async ( + inputFile: string, + options: { + outputFile?: string; + convertSerialToInteger?: boolean; + }, +) => { const { abstractSqlToTypescriptTypes } = await import( '@balena/abstract-sql-to-typescript/generate' ); @@ -26,9 +32,11 @@ const generateTypes = async (inputFile: string, outputFile?: string) => { inputFile, program.opts().model, ); - const types = abstractSqlToTypescriptTypes(abstractSql); + const types = abstractSqlToTypescriptTypes(abstractSql, { + convertSerialToInteger: options.convertSerialToInteger, + }); - writeAll(types, outputFile); + writeAll(types, options.outputFile); }; program @@ -57,7 +65,13 @@ program program .command('generate-types [output-file]') .description('generate typescript types from the input AbstractSql') - .action(generateTypes); + .option('--convert-serial-to-integer', 'Convert serials to integers') + .action(async (inputFile, outputFile, opts) => { + await generateTypes(inputFile, { + outputFile, + convertSerialToInteger: opts.convertSerialToInteger, + }); + }); program .command('help') diff --git a/src/migrator/migrations.ts b/src/migrator/migrations.ts index bfb6a043d..6620f9d47 100644 --- a/src/migrator/migrations.ts +++ b/src/migrator/migrations.ts @@ -1,4 +1,4 @@ -// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 +// These types were generated by @balena/abstract-sql-to-typescript v5.1.0 import type { Types } from '@balena/abstract-sql-to-typescript'; diff --git a/src/sbvr-api/dev.ts b/src/sbvr-api/dev.ts index 50ad54b90..d198605b6 100644 --- a/src/sbvr-api/dev.ts +++ b/src/sbvr-api/dev.ts @@ -1,4 +1,4 @@ -// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 +// These types were generated by @balena/abstract-sql-to-typescript v5.1.0 import type { Types } from '@balena/abstract-sql-to-typescript'; diff --git a/src/sbvr-api/user.ts b/src/sbvr-api/user.ts index 805cb9f00..c63f3f2ca 100644 --- a/src/sbvr-api/user.ts +++ b/src/sbvr-api/user.ts @@ -1,4 +1,4 @@ -// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 +// These types were generated by @balena/abstract-sql-to-typescript v5.1.0 import type { Types } from '@balena/abstract-sql-to-typescript'; diff --git a/src/tasks/tasks.ts b/src/tasks/tasks.ts index 8de74189d..d499ff4b8 100644 --- a/src/tasks/tasks.ts +++ b/src/tasks/tasks.ts @@ -1,4 +1,4 @@ -// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 +// These types were generated by @balena/abstract-sql-to-typescript v5.1.0 import type { Types } from '@balena/abstract-sql-to-typescript';