diff --git a/src/migrator/migrations.ts b/src/migrator/migrations.ts index a316bd043..bfb6a043d 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.1 +// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 import type { Types } from '@balena/abstract-sql-to-typescript'; diff --git a/src/sbvr-api/dev.ts b/src/sbvr-api/dev.ts index 7691f0a84..50ad54b90 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.1 +// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 import type { Types } from '@balena/abstract-sql-to-typescript'; diff --git a/src/sbvr-api/translations.ts b/src/sbvr-api/translations.ts index a82be05bb..44aa6470b 100644 --- a/src/sbvr-api/translations.ts +++ b/src/sbvr-api/translations.ts @@ -24,13 +24,12 @@ export type AliasValidNodeType = | UnknownTypeNodes | NullNode; const aliasFields = ( - fromAbstractSqlModel: AbstractSqlModel, - toAbstractSqlModel: AbstractSqlModel, + translationAbstractSqlModel: AbstractSqlModel, fromResourceName: string, toResource: string, aliases: Dictionary, ): SelectNode[1] => { - const fromFieldNames = fromAbstractSqlModel.tables[ + const fromFieldNames = translationAbstractSqlModel.tables[ fromResourceName ].fields.map(({ fieldName }) => fieldName); const nonexistentFields = _.difference(Object.keys(aliases), fromFieldNames); @@ -39,9 +38,9 @@ const aliasFields = ( `Tried to alias non-existent fields: '${nonexistentFields.join(', ')}'`, ); } - const toFieldNames = toAbstractSqlModel.tables[toResource].fields.map( - ({ fieldName }) => fieldName, - ); + const toFieldNames = translationAbstractSqlModel.tables[ + toResource + ].fields.map(({ fieldName }) => fieldName); const checkToFieldExists = (fromFieldName: string, toFieldName: string) => { if (!toFieldNames.includes(toFieldName)) { throw new Error( @@ -70,13 +69,12 @@ const aliasFields = ( }; const aliasResource = ( - fromAbstractSqlModel: AbstractSqlModel, - toAbstractSqlModel: AbstractSqlModel, + translationAbstractSqlModel: AbstractSqlModel, fromResourceName: string, toResource: string, aliases: Dictionary, ): Definition => { - if (!toAbstractSqlModel.tables[toResource]) { + if (!translationAbstractSqlModel.tables[toResource]) { throw new Error(`Tried to alias to a non-existent resource: ${toResource}`); } return { @@ -85,8 +83,7 @@ const aliasResource = ( [ 'Select', aliasFields( - fromAbstractSqlModel, - toAbstractSqlModel, + translationAbstractSqlModel, fromResourceName, toResource, aliases, @@ -247,8 +244,9 @@ export const translateAbstractSqlModel = ( table.definition = definition; } else { table.definition = aliasResource( + // fromAbstractSqlModel is the translation model as it contains + // both the unaliased fromResource and the aliased toResource fromAbstractSqlModel, - toAbstractSqlModel, key, aliasedToResource, definition, diff --git a/src/sbvr-api/user.ts b/src/sbvr-api/user.ts index 1d1e970d5..805cb9f00 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.1 +// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 import type { Types } from '@balena/abstract-sql-to-typescript'; diff --git a/src/tasks/tasks.ts b/src/tasks/tasks.ts index 6b98ab4b6..8de74189d 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.1 +// These types were generated by @balena/abstract-sql-to-typescript v5.0.2 import type { Types } from '@balena/abstract-sql-to-typescript';