Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convert serial option to generate-types command #847

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading