sasat 0.19.2 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -82,28 +82,31 @@ const makeTableInfo = (root) => {
|
|
|
82
82
|
.variable('const', 'tableInfo', tsg.object(...root.entities.map(entity => tsg.propertyAssign(entity.tableName, tsg.object(tsg.propertyAssign('identifiableKeys', tsg.array(entity.identifyKeys.map(tsg.string))), columnMap(entity))))), tsg.typeRef('TableInfo').importFrom('sasat'))
|
|
83
83
|
.export();
|
|
84
84
|
};
|
|
85
|
+
const referenceRelationType = (ref) => {
|
|
86
|
+
const parentEntityName = EntityName.fromTableName(ref.parentTableName);
|
|
87
|
+
console.log(ref.entity.name.name, parentEntityName.name);
|
|
88
|
+
const type = tsg
|
|
89
|
+
.typeRef('EntityResult', [
|
|
90
|
+
tsg.typeRef(parentEntityName.entityWithRelationTypeName()),
|
|
91
|
+
tsg.typeRef(parentEntityName.relationTypeName()),
|
|
92
|
+
])
|
|
93
|
+
.importFrom('sasat');
|
|
94
|
+
return tsg.propertySignature(ref.fieldName, type);
|
|
95
|
+
};
|
|
85
96
|
const referencedRelationType = (node) => {
|
|
97
|
+
const child = EntityName.fromTableName(node.childTable);
|
|
86
98
|
const type = tsg
|
|
87
99
|
.typeRef('EntityResult', [
|
|
88
|
-
tsg.typeRef(
|
|
89
|
-
makeTypeRef(
|
|
100
|
+
tsg.typeRef(child.entityWithRelationTypeName()),
|
|
101
|
+
makeTypeRef(child, 'identifiable', 'GENERATED'),
|
|
90
102
|
])
|
|
91
103
|
.importFrom('sasat');
|
|
92
104
|
return tsg.propertySignature(node.fieldName, node.relation === 'Many' ? tsg.arrayType(type) : type);
|
|
93
105
|
};
|
|
94
106
|
const entityRelationType = (node) => {
|
|
95
107
|
const typeProperties = [
|
|
96
|
-
...node.references.map(
|
|
97
|
-
|
|
98
|
-
const type = tsg
|
|
99
|
-
.typeRef('EntityResult', [
|
|
100
|
-
tsg.typeRef(parentEntityName.entityWithRelationTypeName()),
|
|
101
|
-
tsg.typeRef(parentEntityName.relationTypeName()),
|
|
102
|
-
])
|
|
103
|
-
.importFrom('sasat');
|
|
104
|
-
return tsg.propertySignature(it.fieldName, type);
|
|
105
|
-
}),
|
|
106
|
-
...node.referencedBy.map(it => referencedRelationType(it)),
|
|
108
|
+
...node.references.map(referenceRelationType),
|
|
109
|
+
...node.referencedBy.map(referencedRelationType),
|
|
107
110
|
];
|
|
108
111
|
return [
|
|
109
112
|
tsg
|
|
@@ -2,5 +2,5 @@ import { KeywordTypeNode, tsg, } from '../../../../tsg/index.js';
|
|
|
2
2
|
import { columnTypeToTsType } from '../../../../migration/column/columnTypes.js';
|
|
3
3
|
export const fieldToPropertySignature = (field) => {
|
|
4
4
|
const type = tsg.typeRef(columnTypeToTsType(field.dbType));
|
|
5
|
-
return tsg.propertySignature(field.fieldName, field.isNullable ? tsg.unionType(type, KeywordTypeNode.null) : type,
|
|
5
|
+
return tsg.propertySignature(field.fieldName, field.isNullable ? tsg.unionType(type, KeywordTypeNode.null) : type, field.isNullable, true);
|
|
6
6
|
};
|