sasat 0.18.2 → 0.18.4
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.
|
@@ -12,20 +12,22 @@ export class RelationMapGenerator {
|
|
|
12
12
|
.export();
|
|
13
13
|
}
|
|
14
14
|
referencedRelationType(node) {
|
|
15
|
-
const type = tsg.
|
|
16
|
-
node.parent.entityName.
|
|
17
|
-
|
|
15
|
+
const type = tsg.typeRef('EntityResult', [
|
|
16
|
+
tsg.typeRef(node.parent.entityName.entityWithRelationTypeName()),
|
|
17
|
+
node.parent.entityName.identifiableTypeReference(Directory.paths.generated),
|
|
18
|
+
]).importFrom('sasat');
|
|
18
19
|
return tsg.propertySignature(node.referencedByPropertyName(), node.relation === 'Many' ? tsg.arrayType(type) : type);
|
|
19
20
|
}
|
|
20
21
|
entityRelationType(node) {
|
|
21
|
-
const importEntity = (entity) => Directory.entityPath(Directory.paths.generated, entity);
|
|
22
22
|
const typeProperties = [
|
|
23
|
-
...node.relations.map(it =>
|
|
24
|
-
tsg.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
...node.relations.map(it => {
|
|
24
|
+
const type = tsg.typeRef('EntityResult', [
|
|
25
|
+
tsg.typeRef(it.to.entityName.entityWithRelationTypeName()),
|
|
26
|
+
tsg.typeRef(it.to.entityName.relationTypeName()),
|
|
27
|
+
])
|
|
28
|
+
.importFrom('sasat');
|
|
29
|
+
return tsg.propertySignature(it.refPropertyName(), type);
|
|
30
|
+
}),
|
|
29
31
|
...node
|
|
30
32
|
.findReferencedRelations()
|
|
31
33
|
.map(it => this.referencedRelationType(it)),
|
|
@@ -69,7 +71,7 @@ export class RelationMapGenerator {
|
|
|
69
71
|
tableInfo(root) {
|
|
70
72
|
const columnMap = (entity) => tsg.propertyAssign('columnMap', tsg.object(...entity.fields.map(field => tsg.propertyAssign(field.fieldName, tsg.string(field.columnName)))));
|
|
71
73
|
return tsg
|
|
72
|
-
.variable('const', 'tableInfo', tsg.object(...root.repositories.map(repo => tsg.propertyAssign(repo.tableName, tsg.object(tsg.propertyAssign('identifiableKeys', tsg.array(repo.primaryKeys.map(tsg.string))), columnMap(repo.entity))))))
|
|
74
|
+
.variable('const', 'tableInfo', tsg.object(...root.repositories.map(repo => tsg.propertyAssign(repo.tableName, tsg.object(tsg.propertyAssign('identifiableKeys', tsg.array(repo.primaryKeys.map(tsg.string))), columnMap(repo.entity))))), tsg.typeRef('TableInfo').importFrom('sasat'))
|
|
73
75
|
.export();
|
|
74
76
|
}
|
|
75
77
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
export { BooleanValueExpression, Query, LockMode, } from './runtime/dsl/query/query.js';
|
|
2
|
-
export { Relation } from './migration/data/relation.js';
|
|
1
|
+
export type { BooleanValueExpression, Query, LockMode, } from './runtime/dsl/query/query.js';
|
|
2
|
+
export type { Relation } from './migration/data/relation.js';
|
|
3
|
+
export type { RelationMap } from './runtime/dsl/query/createQueryResolveInfo.js';
|
|
4
|
+
export type { TableInfo } from "./runtime/dsl/query/createQueryResolveInfo.js";
|
|
5
|
+
export type { Fields } from './runtime/field.js';
|
|
6
|
+
export type { ComparisonOperators } from './db/sql/expression/comparison.js';
|
|
7
|
+
export type { MigrationStore } from './migration/front/storeMigrator.js';
|
|
8
|
+
export type { SasatMigration } from './migration/front/migration.js';
|
|
9
|
+
export type { CommandResponse, QueryResponse } from './db/connectors/dbClient.js';
|
|
3
10
|
export { QExpr } from './runtime/dsl/factory.js';
|
|
4
|
-
export { RelationMap } from './runtime/dsl/query/createQueryResolveInfo.js';
|
|
5
|
-
export { Fields } from './runtime/field.js';
|
|
6
11
|
export { gqlResolveInfoToField } from './runtime/gqlResolveInfoToField.js';
|
|
7
|
-
export { ComparisonOperators } from './db/sql/expression/comparison.js';
|
|
8
|
-
export { MigrationStore } from './migration/front/storeMigrator.js';
|
|
9
|
-
export { SasatMigration } from './migration/front/migration.js';
|
|
10
12
|
export { SasatDBDatasource, EntityResult, EntityType, ListQueryOption, QueryOptions, } from './runtime/sasatDBDatasource.js';
|
|
11
13
|
export { getCurrentDateTimeString } from './util/dateUtil.js';
|
|
12
14
|
export { getDbClient } from './db/getDbClient.js';
|
|
13
15
|
export { assignDeep } from './util/assignDeep.js';
|
|
14
16
|
export { createTypeDef } from './runtime/createTypeDef.js';
|
|
15
17
|
export { CompositeCondition } from './db/sql/expression/compositeCondition.js';
|
|
16
|
-
export { CommandResponse, QueryResponse } from './db/connectors/dbClient.js';
|
|
17
18
|
export { pick } from './runtime/util.js';
|
package/lib/runtime/field.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { BooleanValueExpression } from "./dsl/query/query.js";
|
|
1
2
|
export declare type Fields<Entity, Relation = Record<string, unknown>> = {
|
|
2
3
|
fields: Array<keyof Entity & string>;
|
|
3
4
|
relations?: Relation;
|
|
4
5
|
tableAlias?: string;
|
|
6
|
+
where?: BooleanValueExpression;
|
|
5
7
|
};
|
|
@@ -7,6 +7,7 @@ const notTypeName = (fieldName) => fieldName !== '__typename';
|
|
|
7
7
|
export const createQuery = (baseTableName, fields, options, tableInfo, relationMap, context) => {
|
|
8
8
|
let tableCount = 0;
|
|
9
9
|
const select = [];
|
|
10
|
+
const where = [options?.where];
|
|
10
11
|
const resolveFields = (tableName, table) => {
|
|
11
12
|
const tableAlias = table.tableAlias || 't' + tableCount;
|
|
12
13
|
table.tableAlias = tableAlias;
|
|
@@ -19,6 +20,7 @@ export const createQuery = (baseTableName, fields, options, tableInfo, relationM
|
|
|
19
20
|
const realName = info.columnMap[it] || it;
|
|
20
21
|
return QExpr.field(tableAlias, realName, tableAlias + SELECT_ALIAS_SEPARATOR + it);
|
|
21
22
|
}));
|
|
23
|
+
where.push(table.where);
|
|
22
24
|
return QExpr.table(tableName, Object.entries(table.relations || {}).map(([relationName, table]) => {
|
|
23
25
|
const current = tableCount;
|
|
24
26
|
const rel = relationMap[tableName][relationName];
|
|
@@ -30,6 +32,7 @@ export const createQuery = (baseTableName, fields, options, tableInfo, relationM
|
|
|
30
32
|
select,
|
|
31
33
|
from,
|
|
32
34
|
...options,
|
|
35
|
+
where: where.filter(it => !it).length !== 0 ? QExpr.conditions.and(...where) : undefined,
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
38
|
export const createPagingInnerQuery = (tableName, tableAlias, fields, option, tableInfo) => {
|