@balena/abstract-sql-to-typescript
Advanced tools
Comparing version 5.1.0-build-joshbwlng-replace-serials-9ffed15dc113018d9cf52543d7fe1ff41fa237ed-1 to 5.1.0-build-joshbwlng-replace-serials-cdf0e4e2fc7f91c3fcadbb32d476e3bb47557f24-1
@@ -57,4 +57,4 @@ { | ||
"versionist": { | ||
"publishedAt": "2024-12-10T23:34:29.144Z" | ||
"publishedAt": "2024-12-17T01:20:27.355Z" | ||
} | ||
} |
@@ -30,2 +30,8 @@ "use strict"; | ||
if (mode === 'Write') { | ||
if (f.references != null) { | ||
const referencedField = m.tables[f.references.resourceName].fields.find(({ fieldName }) => fieldName === f.references.fieldName); | ||
if (referencedField?.computed != null) { | ||
return `Types['${opts.convertSerialToInteger ? replaceSerial(referencedField.dataType) : referencedField.dataType}']['${mode}']`; | ||
} | ||
} | ||
return referencedFieldType; | ||
@@ -32,0 +38,0 @@ } |
{ | ||
"name": "@balena/abstract-sql-to-typescript", | ||
"version": "5.1.0-build-joshbwlng-replace-serials-9ffed15dc113018d9cf52543d7fe1ff41fa237ed-1", | ||
"version": "5.1.0-build-joshbwlng-replace-serials-cdf0e4e2fc7f91c3fcadbb32d476e3bb47557f24-1", | ||
"description": "A translator for abstract sql into typescript types.", | ||
@@ -57,4 +57,4 @@ "type": "commonjs", | ||
"versionist": { | ||
"publishedAt": "2024-12-10T23:34:29.144Z" | ||
"publishedAt": "2024-12-17T01:20:27.355Z" | ||
} | ||
} |
@@ -66,2 +66,14 @@ import type { | ||
if (mode === 'Write') { | ||
if (f.references != null) { | ||
const referencedField = m.tables[ | ||
f.references.resourceName | ||
].fields.find( | ||
({ fieldName }) => fieldName === f.references!.fieldName, | ||
); | ||
// If the referenced field is computed it won't generate a write typing | ||
// so we have to in-line it here as we cannot reference it | ||
if (referencedField?.computed != null) { | ||
return `Types['${opts.convertSerialToInteger ? replaceSerial(referencedField.dataType) : referencedField.dataType}']['${mode}']`; | ||
} | ||
} | ||
return referencedFieldType; | ||
@@ -68,0 +80,0 @@ } |
@@ -68,2 +68,3 @@ import type { AbstractSqlModel } from '@balena/abstract-sql-compiler'; | ||
index: 'PRIMARY KEY', | ||
computed: ['Field', 'id'], | ||
}, | ||
@@ -104,2 +105,3 @@ ], | ||
index: 'PRIMARY KEY', | ||
computed: ['Field', 'id'], | ||
}, | ||
@@ -140,2 +142,3 @@ ], | ||
index: 'PRIMARY KEY', | ||
computed: ['Field', 'id'], | ||
}, | ||
@@ -322,3 +325,2 @@ { | ||
modified_at: Types['Date Time']['Write']; | ||
id: Types['Serial']['Write']; | ||
}; | ||
@@ -337,3 +339,2 @@ } | ||
modified_at: Types['Date Time']['Write']; | ||
id: Types['Big Serial']['Write']; | ||
}; | ||
@@ -360,7 +361,6 @@ } | ||
modified_at: Types['Date Time']['Write']; | ||
id: Types['Serial']['Write']; | ||
a_date: Types['Date']['Write']; | ||
a_file: Types['WebResource']['Write']; | ||
parent: Parent['Write']['id']; | ||
references__other: Other['Write']['id']; | ||
parent: Types['Serial']['Write']; | ||
references__other: Types['Big Serial']['Write']; | ||
}; | ||
@@ -380,3 +380,3 @@ } | ||
modified_at: Types['Date Time']['Write']; | ||
test: Test['Write']['id']; | ||
test: Types['Serial']['Write']; | ||
tag_key: Types['Short Text']['Write']; | ||
@@ -411,3 +411,2 @@ id: Types['Serial']['Write']; | ||
modified_at: Types['Date Time']['Write']; | ||
id: Types['Integer']['Write']; | ||
}; | ||
@@ -426,3 +425,2 @@ } | ||
modified_at: Types['Date Time']['Write']; | ||
id: Types['Big Integer']['Write']; | ||
}; | ||
@@ -449,7 +447,6 @@ } | ||
modified_at: Types['Date Time']['Write']; | ||
id: Types['Integer']['Write']; | ||
a_date: Types['Date']['Write']; | ||
a_file: Types['WebResource']['Write']; | ||
parent: Parent['Write']['id']; | ||
references__other: Other['Write']['id']; | ||
parent: Types['Integer']['Write']; | ||
references__other: Types['Big Integer']['Write']; | ||
}; | ||
@@ -469,3 +466,3 @@ } | ||
modified_at: Types['Date Time']['Write']; | ||
test: Test['Write']['id']; | ||
test: Types['Integer']['Write']; | ||
tag_key: Types['Short Text']['Write']; | ||
@@ -472,0 +469,0 @@ id: Types['Integer']['Write']; |
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
464736
995