Skip to content

Commit

Permalink
Add convert serial option to generate-types command
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
joshbwlng committed Dec 17, 2024
1 parent bf2e8cb commit 13e62a4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 18 additions & 4 deletions src/bin/abstract-sql-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,25 @@ 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'
);
const abstractSql = getAbstractSqlModelFromFile(
inputFile,
program.opts().model,
);
const types = abstractSqlToTypescriptTypes(abstractSql);
const types = abstractSqlToTypescriptTypes(abstractSql, {
convertSerialToInteger: options.convertSerialToInteger,
});

writeAll(types, outputFile);
writeAll(types, options.outputFile);
};

program
Expand Down Expand Up @@ -57,7 +65,13 @@ program
program
.command('generate-types <input-file> [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')
Expand Down
2 changes: 1 addition & 1 deletion src/migrator/migrations.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/sbvr-api/dev.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/sbvr-api/user.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/tasks/tasks.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 13e62a4

Please sign in to comment.