sasat 0.14.8 → 0.14.11
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.
- package/lib/cli/commands/dumpDb.js +1 -1
- package/lib/cli/commands/migrate.js +1 -1
- package/lib/db/connectors/mockClient.d.ts +1 -1
- package/lib/db/connectors/mockClient.js +1 -1
- package/lib/db/connectors/mysql/client.js +1 -1
- package/lib/db/connectors/mysql/transaction.d.ts +1 -1
- package/lib/db/formatQuery.js +1 -1
- package/lib/db/sql/createTable/createTableParser.js +1 -1
- package/lib/db/sql/createTable/createTableSerializer.js +1 -1
- package/lib/generator/ts/code/factory.d.ts +5 -5
- package/lib/generator/ts/code/factory.js +1 -1
- package/lib/generator/ts/code/importDeclaration.js +1 -1
- package/lib/generator/ts/code/node/{ExpressionStatement.d.ts → expressionStatement.d.ts} +0 -0
- package/lib/generator/ts/code/node/{ExpressionStatement.js → expressionStatement.js} +0 -0
- package/lib/generator/ts/code/node/expressions.d.ts +1 -1
- package/lib/generator/ts/code/node/expressions.js +1 -1
- package/lib/generator/ts/code/node/parameter.d.ts +2 -1
- package/lib/generator/ts/code/node/variableDeclaration.d.ts +2 -1
- package/lib/generator/ts/db/generatedRepositoryGenerator.js +3 -2
- package/lib/generator/ts/gql/mutationGenerator.js +2 -2
- package/lib/generator/ts/staticFiles.js +1 -1
- package/lib/migration/front/tableMigrator.d.ts +1 -1
- package/lib/migration/front/tableMigrator.js +1 -1
- package/lib/migration/migrationReader.js +3 -3
- package/lib/migration/migrationTargetResolver.js +1 -1
- package/lib/migration/serialized/serializedColumn.d.ts +1 -1
- package/lib/parser/node/relationNode.d.ts +1 -1
- package/lib/parser/node/repositoryNode.js +1 -1
- package/lib/runtime/dsl/factory.d.ts +10 -8
- package/lib/runtime/dsl/factory.js +7 -0
- package/lib/runtime/dsl/mutation/mutation.d.ts +1 -1
- package/lib/runtime/dsl/query/createQueryResolveInfo.d.ts +1 -1
- package/lib/runtime/dsl/query/fieldToQuery.d.ts +1 -1
- package/lib/runtime/dsl/query/query.d.ts +3 -2
- package/lib/runtime/dsl/replaceAliases.js +1 -1
- package/lib/runtime/sasatRepository.d.ts +11 -3
- package/lib/runtime/sasatRepository.js +11 -10
- package/package.json +7 -31
|
@@ -4,7 +4,7 @@ import { SqlString } from '../../runtime/sql/sqlString.js';
|
|
|
4
4
|
import { writeYmlFile } from '../../util/fsUtil.js';
|
|
5
5
|
import { DBColumnTypes } from '../../migration/column/columnTypes.js';
|
|
6
6
|
import { config } from '../../config/config.js';
|
|
7
|
-
import { getDbClient } from
|
|
7
|
+
import { getDbClient } from '../../db/getDbClient.js';
|
|
8
8
|
export const dumpDB = async () => {
|
|
9
9
|
const con = getDbClient();
|
|
10
10
|
try {
|
|
@@ -4,7 +4,7 @@ import { Parser } from '../../parser/parser.js';
|
|
|
4
4
|
import { CodeGenerateController } from '../../generator/controller.js';
|
|
5
5
|
import { DataStoreHandler } from '../../migration/dataStore.js';
|
|
6
6
|
import { writeCurrentSchema } from '../../util/fsUtil.js';
|
|
7
|
-
import { getDbClient } from
|
|
7
|
+
import { getDbClient } from '../../db/getDbClient.js';
|
|
8
8
|
export const migrate = async (options) => {
|
|
9
9
|
let current;
|
|
10
10
|
try {
|
package/lib/db/formatQuery.js
CHANGED
|
@@ -205,7 +205,7 @@ export class CreateTableParser {
|
|
|
205
205
|
targetTable,
|
|
206
206
|
targetColumn,
|
|
207
207
|
columnName,
|
|
208
|
-
relation: isColumnUnique ?
|
|
208
|
+
relation: isColumnUnique ? 'OneOrZero' : 'Many',
|
|
209
209
|
relationName: sameTableRefs.length !== 0 ? targetTable + sameTableRefs.length : undefined,
|
|
210
210
|
onUpdate,
|
|
211
211
|
onDelete,
|
|
@@ -65,7 +65,7 @@ const startStrMap = [
|
|
|
65
65
|
targetTable,
|
|
66
66
|
targetColumn,
|
|
67
67
|
columnName,
|
|
68
|
-
relation: isColumnUnique ?
|
|
68
|
+
relation: isColumnUnique ? 'OneOrZero' : 'Many',
|
|
69
69
|
relationName: sameTableRefs.length !== 0 ? targetTable + sameTableRefs.length : undefined,
|
|
70
70
|
onUpdate: onUpdate !== -1 ? tokens[onUpdate + 1].value : undefined,
|
|
71
71
|
onDelete: onDelete !== -1 ? tokens[onDelete + 1].value : undefined,
|
|
@@ -4,7 +4,7 @@ import { Block } from './node/block.js';
|
|
|
4
4
|
import { Class } from './node/class.js';
|
|
5
5
|
import { EnumDeclaration } from './node/enumDeclaration.js';
|
|
6
6
|
import { EnumMember } from './node/enumMember.js';
|
|
7
|
-
import { ExpressionStatement } from './node/
|
|
7
|
+
import { ExpressionStatement } from './node/expressionStatement.js';
|
|
8
8
|
import { ExtendsClause } from './node/extendsClause.js';
|
|
9
9
|
import { IfStatement } from './node/ifStatement.js';
|
|
10
10
|
import { ImplementsClause } from './node/implementsClause.js';
|
|
@@ -35,13 +35,13 @@ export declare const tsg: {
|
|
|
35
35
|
implements: (...args: TypeReference[]) => ImplementsClause;
|
|
36
36
|
interface: (name: string) => TsInterface;
|
|
37
37
|
method: (methodName: string, params: Parameter[], returnType: import("./node/type/type.js").TsType, body: import("./abstruct/statement.js").TsStatement[]) => MethodDeclaration;
|
|
38
|
-
parameter: (paramName: string, type?:
|
|
38
|
+
parameter: (paramName: string, type?: import("./node/type/type.js").TsType | undefined) => Parameter;
|
|
39
39
|
propertyAssign: (key: string, value?: Exp.Identifier | Exp.Literal | undefined) => PropertyAssignment;
|
|
40
40
|
propertyDeclaration: (propertyName: string, type: import("./node/type/type.js").TsType, optional?: boolean | undefined) => PropertyDeclaration;
|
|
41
41
|
propertySignature: (propertyName: string, type: import("./node/type/type.js").TsType, isOptional?: boolean | undefined, isReadOnly?: boolean | undefined) => PropertySignature;
|
|
42
42
|
return: (expression: Exp.TsExpression) => ReturnStatement;
|
|
43
43
|
spreadAssign: (identifier: Exp.Identifier | Exp.ObjectLiteral | Exp.ArrayLiteral) => SpreadAssignment;
|
|
44
|
-
variable: (flag: "const" | "let", variableName: string | Exp.Identifier, expression: Exp.TsExpression | Exp.Identifier, type?:
|
|
44
|
+
variable: (flag: "const" | "let", variableName: string | Exp.Identifier, expression: Exp.TsExpression | Exp.Identifier, type?: import("./node/type/type.js").TsType | undefined) => VariableDeclaration;
|
|
45
45
|
methodModifiers: () => MethodModifiers;
|
|
46
46
|
propertyModifiers: () => PropertyModifiers;
|
|
47
47
|
arrayType: (type: import("./node/type/type.js").TsType) => ArrayType;
|
|
@@ -49,8 +49,8 @@ export declare const tsg: {
|
|
|
49
49
|
unionType: (types: import("./node/type/type.js").TsType[]) => UnionType;
|
|
50
50
|
typeAlias: (alias: string, type: import("./node/type/type.js").TsType) => TypeAliasDeclaration;
|
|
51
51
|
typeLiteral: (properties?: PropertySignature[] | undefined) => TypeLiteral;
|
|
52
|
-
typeRef: (typeName: string, typeArguments?: (Exp.Identifier |
|
|
53
|
-
arrowFunc: (params: Parameter[], returnType:
|
|
52
|
+
typeRef: (typeName: string, typeArguments?: (Exp.Identifier | import("./node/type/type.js").TsType)[] | undefined) => TypeReference;
|
|
53
|
+
arrowFunc: (params: Parameter[], returnType: import("./node/type/type.js").TsType | undefined, body: Exp.TsExpression | Block) => Exp.ArrowFunction;
|
|
54
54
|
async: (expression: Exp.ArrowFunction) => Exp.AsyncExpression;
|
|
55
55
|
await: (expression: Exp.TsExpression) => Exp.AwaitExpression;
|
|
56
56
|
binary: (left: Exp.TsExpression, operator: Exp.BinaryExpressionToken, right: Exp.TsExpression) => Exp.BinaryExpression;
|
|
@@ -4,7 +4,7 @@ import { Block } from './node/block.js';
|
|
|
4
4
|
import { Class } from './node/class.js';
|
|
5
5
|
import { EnumDeclaration } from './node/enumDeclaration.js';
|
|
6
6
|
import { EnumMember } from './node/enumMember.js';
|
|
7
|
-
import { ExpressionStatement } from './node/
|
|
7
|
+
import { ExpressionStatement } from './node/expressionStatement.js';
|
|
8
8
|
import { ExtendsClause } from './node/extendsClause.js';
|
|
9
9
|
import { IfStatement } from './node/ifStatement.js';
|
|
10
10
|
import { ImplementsClause } from './node/implementsClause.js';
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TsCode } from '../abstruct/tsCode.js';
|
|
2
|
-
import { ExpressionStatement } from './
|
|
2
|
+
import { ExpressionStatement } from './expressionStatement.js';
|
|
3
3
|
import { SpreadAssignment } from './spreadAssignment.js';
|
|
4
4
|
import { PropertyAssignment } from './propertyAssignment.js';
|
|
5
5
|
import { Parameter } from './parameter.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TsCode } from '../abstruct/tsCode.js';
|
|
2
|
-
import { ExpressionStatement } from './
|
|
2
|
+
import { ExpressionStatement } from './expressionStatement.js';
|
|
3
3
|
import { Parameter } from './parameter.js';
|
|
4
4
|
export class TsExpression extends TsCode {
|
|
5
5
|
constructor() {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TsType } from './type/type.js';
|
|
1
2
|
import { TsCode } from '../abstruct/tsCode.js';
|
|
2
3
|
export declare class Parameter extends TsCode {
|
|
3
4
|
private paramName;
|
|
4
5
|
private type?;
|
|
5
|
-
constructor(paramName: string, type?:
|
|
6
|
+
constructor(paramName: string, type?: TsType | undefined);
|
|
6
7
|
protected toTsString(): string;
|
|
7
8
|
static arrayToString(params: Parameter[]): string;
|
|
8
9
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ExportableDeclaration } from '../abstruct/exportableDeclaration.js';
|
|
2
2
|
import { Identifier, TsExpression } from './expressions.js';
|
|
3
|
+
import { TsType } from './type/type.js';
|
|
3
4
|
declare type VariableType = 'const' | 'let';
|
|
4
5
|
export declare class VariableDeclaration extends ExportableDeclaration {
|
|
5
6
|
private readonly flag;
|
|
6
7
|
private readonly expression;
|
|
7
8
|
private readonly type?;
|
|
8
9
|
private readonly variableName;
|
|
9
|
-
constructor(flag: VariableType, variableName: Identifier | string, expression: TsExpression | Identifier, type?:
|
|
10
|
+
constructor(flag: VariableType, variableName: Identifier | string, expression: TsExpression | Identifier, type?: TsType | undefined);
|
|
10
11
|
protected toTsString(): string;
|
|
11
12
|
}
|
|
12
13
|
export {};
|
|
@@ -84,12 +84,13 @@ export class GeneratedRepositoryGenerator {
|
|
|
84
84
|
.call(qExpr.property('field').call(tsg.identifier('tableName'), tsg.string(it.name)), qExpr.property('value').call(tsg.identifier(it.name))));
|
|
85
85
|
const body = [
|
|
86
86
|
tsg.variable('const', 'tableName', tsg.identifier('fields?.tableAlias || this.tableName')),
|
|
87
|
-
tsg.return(tsg.identifier(it.returnType.isArray ? 'this.find' : 'this.first').call(tsg.identifier('fields'),
|
|
87
|
+
tsg.return(tsg.identifier(it.returnType.isArray ? 'this.find' : 'this.first').call(tsg.identifier('fields'), tsg.object()
|
|
88
|
+
.addProperties(tsg.propertyAssign('where', exps.length === 1
|
|
88
89
|
? exps[0]
|
|
89
90
|
: qExpr
|
|
90
91
|
.property('conditions')
|
|
91
92
|
.property('and')
|
|
92
|
-
.call(...exps))),
|
|
93
|
+
.call(...exps))))),
|
|
93
94
|
];
|
|
94
95
|
const returnType = tsg
|
|
95
96
|
.typeRef('EntityResult', [
|
|
@@ -3,10 +3,10 @@ import { VariableDeclaration } from '../code/node/variableDeclaration.js';
|
|
|
3
3
|
import { PropertyAssignment } from '../code/node/propertyAssignment.js';
|
|
4
4
|
import { TypeReference } from '../code/node/type/typeReference.js';
|
|
5
5
|
import { Parameter } from '../code/node/parameter.js';
|
|
6
|
-
import { Block } from '../code/node/
|
|
6
|
+
import { Block } from '../code/node/block.js';
|
|
7
7
|
import { ReturnStatement } from '../code/node/returnStatement.js';
|
|
8
8
|
import { SpreadAssignment } from '../code/node/spreadAssignment.js';
|
|
9
|
-
import { ExpressionStatement } from '../code/node/
|
|
9
|
+
import { ExpressionStatement } from '../code/node/expressionStatement.js';
|
|
10
10
|
import { IntersectionType } from '../code/node/type/intersectionType.js';
|
|
11
11
|
import { KeywordTypeNode } from '../code/node/type/typeKeyword.js';
|
|
12
12
|
import { IfStatement } from '../code/node/ifStatement.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImportDeclaration } from
|
|
1
|
+
import { ImportDeclaration } from './code/importDeclaration.js';
|
|
2
2
|
const contextFile = `\
|
|
3
3
|
${new ImportDeclaration(['BaseGqlContext'], './__generated__/context').toString()}
|
|
4
4
|
export interface GqlContext extends BaseGqlContext {}
|
|
@@ -6,7 +6,7 @@ import { GqlOption } from '../data/gqlOption.js';
|
|
|
6
6
|
import { Column } from '../serializable/column.js';
|
|
7
7
|
import { SerializedTable } from '../serialized/serializedStore.js';
|
|
8
8
|
import { DBType } from '../column/columnTypes.js';
|
|
9
|
-
import { DBIndex } from
|
|
9
|
+
import { DBIndex } from '../data/index.js';
|
|
10
10
|
export interface MigrationTable extends Table {
|
|
11
11
|
addIndex(...columns: string[]): MigrationTable;
|
|
12
12
|
removeIndex(...columns: string[]): MigrationTable;
|
|
@@ -2,7 +2,7 @@ import { TableHandler } from '../serializable/table.js';
|
|
|
2
2
|
import { NormalColumn } from '../serializable/column.js';
|
|
3
3
|
import { SqlCreator } from '../../db/sql/sqlCreater.js';
|
|
4
4
|
import { SqlString } from '../../runtime/sql/sqlString.js';
|
|
5
|
-
import { DBIndex } from
|
|
5
|
+
import { DBIndex } from '../data/index.js';
|
|
6
6
|
export class TableMigrator {
|
|
7
7
|
constructor(table, store) {
|
|
8
8
|
this.table = table;
|
|
@@ -4,7 +4,7 @@ import * as fs from 'fs';
|
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import ts from 'typescript';
|
|
6
6
|
import { readInitialSchema } from '../util/fsUtil.js';
|
|
7
|
-
import { config } from
|
|
7
|
+
import { config } from '../config/config.js';
|
|
8
8
|
export class MigrationReader {
|
|
9
9
|
read(onMigrate) {
|
|
10
10
|
const files = fs.readdirSync(MigrationTargetResolver.getMigrationDir());
|
|
@@ -21,11 +21,11 @@ export class MigrationReader {
|
|
|
21
21
|
return store;
|
|
22
22
|
}
|
|
23
23
|
static getTsConfig() {
|
|
24
|
-
const configFileName = ts.findConfigFile(
|
|
24
|
+
const configFileName = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json');
|
|
25
25
|
if (!configFileName)
|
|
26
26
|
return undefined;
|
|
27
27
|
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
28
|
-
return ts.parseJsonConfigFileContent(configFile.config, ts.sys,
|
|
28
|
+
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, './').options;
|
|
29
29
|
}
|
|
30
30
|
static readMigration(store, fileName, direction) {
|
|
31
31
|
const file = fs.readFileSync(path.join(MigrationTargetResolver.getMigrationDir(), fileName)).toString();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { config } from '../config/config.js';
|
|
4
|
-
import { getDbClient } from
|
|
4
|
+
import { getDbClient } from '../db/getDbClient.js';
|
|
5
5
|
export var Direction;
|
|
6
6
|
(function (Direction) {
|
|
7
7
|
Direction["Up"] = "up";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DBColumnTypes } from '../column/columnTypes.js';
|
|
2
2
|
import { SqlValueType } from '../../db/connectors/dbClient.js';
|
|
3
3
|
import { ForeignKeyReferentialAction } from '../data/foreignKey.js';
|
|
4
|
-
import { Relation } from
|
|
4
|
+
import { Relation } from '../data/relation.js';
|
|
5
5
|
interface SerializedColumnBase {
|
|
6
6
|
hasReference: boolean;
|
|
7
7
|
fieldName: string;
|
|
@@ -2,7 +2,7 @@ import { TypeNode } from './typeNode.js';
|
|
|
2
2
|
import { EntityNode } from './entityNode.js';
|
|
3
3
|
import { ReferenceColumn } from '../../migration/serializable/column.js';
|
|
4
4
|
import { EntityName } from './entityName.js';
|
|
5
|
-
import { Relation } from
|
|
5
|
+
import { Relation } from '../../migration/data/relation.js';
|
|
6
6
|
export declare class RelationNode {
|
|
7
7
|
readonly parent: EntityNode;
|
|
8
8
|
readonly relationName: string | undefined;
|
|
@@ -36,7 +36,7 @@ export class RepositoryNode {
|
|
|
36
36
|
const refMethods = (relation) => {
|
|
37
37
|
return new FindMethodNode([
|
|
38
38
|
new ParameterNode(relation.fromField, new TypeNode(relation.parent.field(relation.fromField).dbType, false, false)),
|
|
39
|
-
], new TypeNode(EntityName.fromTableName(relation.parent.repository.tableName), relation.relation ===
|
|
39
|
+
], new TypeNode(EntityName.fromTableName(relation.parent.repository.tableName), relation.relation === 'Many', false), false);
|
|
40
40
|
};
|
|
41
41
|
const referencedByMethod = (relation) => {
|
|
42
42
|
const to = relation.parent.repository.root.findRepository(relation.toEntityName);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BooleanValueExpression,
|
|
1
|
+
import { BetweenExpression, BooleanValueExpression, ComparisonExpression, Field, Fn, InExpression, IsNullExpression, Join, JoinType, Literal, ParenthesisExpression, QueryTable, Sort, SortDirection, Value } from './query/query.js';
|
|
2
2
|
export declare const QExpr: {
|
|
3
|
-
conditions: {
|
|
3
|
+
readonly conditions: {
|
|
4
4
|
and: (...expr: BooleanValueExpression[]) => BooleanValueExpression;
|
|
5
5
|
or: (...expr: BooleanValueExpression[]) => BooleanValueExpression;
|
|
6
6
|
eq: (left: Value, right: Value) => ComparisonExpression;
|
|
@@ -21,10 +21,12 @@ export declare const QExpr: {
|
|
|
21
21
|
isNull: (expr: Value) => IsNullExpression;
|
|
22
22
|
isNotNull: (expr: Value) => IsNullExpression;
|
|
23
23
|
};
|
|
24
|
-
field: (table: string, name: string, alias?: string | undefined) => Field;
|
|
25
|
-
fn: (fnName: string, args: Value[]) => Fn;
|
|
26
|
-
paren: (expression: BooleanValueExpression) => ParenthesisExpression;
|
|
27
|
-
table: (name: string, joins: Join[], alias?: string | undefined) => QueryTable;
|
|
28
|
-
join: (table: QueryTable, conditions: BooleanValueExpression, type?:
|
|
29
|
-
value: (value: string | boolean | number | null) => Literal;
|
|
24
|
+
readonly field: (table: string, name: string, alias?: string | undefined) => Field;
|
|
25
|
+
readonly fn: (fnName: string, args: Value[]) => Fn;
|
|
26
|
+
readonly paren: (expression: BooleanValueExpression) => ParenthesisExpression;
|
|
27
|
+
readonly table: (name: string, joins: Join[], alias?: string | undefined) => QueryTable;
|
|
28
|
+
readonly join: (table: QueryTable, conditions: BooleanValueExpression, type?: JoinType | undefined) => Join;
|
|
29
|
+
readonly value: (value: string | boolean | number | null) => Literal;
|
|
30
|
+
readonly sort: (field: Field, direction: SortDirection) => Sort;
|
|
31
|
+
readonly order: (field: Field, direction: SortDirection) => Sort;
|
|
30
32
|
};
|
|
@@ -97,6 +97,11 @@ const literal = (value) => ({
|
|
|
97
97
|
kind: QueryNodeKind.Literal,
|
|
98
98
|
value,
|
|
99
99
|
});
|
|
100
|
+
const sort = (field, direction) => ({
|
|
101
|
+
kind: QueryNodeKind.Sort,
|
|
102
|
+
field,
|
|
103
|
+
direction,
|
|
104
|
+
});
|
|
100
105
|
export const QExpr = {
|
|
101
106
|
conditions,
|
|
102
107
|
field,
|
|
@@ -105,4 +110,6 @@ export const QExpr = {
|
|
|
105
110
|
table,
|
|
106
111
|
join,
|
|
107
112
|
value: literal,
|
|
113
|
+
sort,
|
|
114
|
+
order: sort,
|
|
108
115
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SqlValueType } from '../../../db/connectors/dbClient.js';
|
|
2
2
|
import { TableInfo } from '../query/createQueryResolveInfo.js';
|
|
3
|
-
import { BooleanValueExpression } from
|
|
3
|
+
import { BooleanValueExpression } from '../query/query.js';
|
|
4
4
|
declare type ValueSet = {
|
|
5
5
|
field: string;
|
|
6
6
|
value: SqlValueType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BooleanValueExpression } from './query.js';
|
|
2
2
|
import { QueryResolveInfo } from './sql/hydrate.js';
|
|
3
|
-
import { Fields } from
|
|
3
|
+
import { Fields } from '../../field.js';
|
|
4
4
|
export declare type RelationInfo = {
|
|
5
5
|
table: string;
|
|
6
6
|
on: (parentTableAlias: string, childTableAlias: string) => BooleanValueExpression;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Query } from './query.js';
|
|
2
2
|
import { RelationMap } from './createQueryResolveInfo.js';
|
|
3
|
-
import { Fields } from
|
|
3
|
+
import { Fields } from '../../field.js';
|
|
4
4
|
export declare const fieldToQuery: (tableName: string, fields: Fields, map: RelationMap) => Query;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComparisonOperators } from
|
|
1
|
+
import { ComparisonOperators } from '../../../db/sql/expression/comparison.js';
|
|
2
2
|
export declare enum QueryNodeKind {
|
|
3
3
|
Field = 0,
|
|
4
4
|
Function = 1,
|
|
@@ -97,10 +97,11 @@ export declare type Literal = {
|
|
|
97
97
|
kind: QueryNodeKind.Literal;
|
|
98
98
|
value: string | boolean | number | null;
|
|
99
99
|
};
|
|
100
|
+
export declare type SortDirection = 'ASC' | 'DESC';
|
|
100
101
|
export declare type Sort = {
|
|
101
102
|
kind: QueryNodeKind.Sort;
|
|
102
103
|
field: Field;
|
|
103
|
-
direction:
|
|
104
|
+
direction: SortDirection;
|
|
104
105
|
};
|
|
105
106
|
export declare type QueryNode = Field | Fn | QueryTable | Literal | BooleanValueExpression | Join | Sort;
|
|
106
107
|
export {};
|
|
@@ -56,7 +56,7 @@ export const replaceAliases = (query, tableInfo) => {
|
|
|
56
56
|
addAlias(query.from);
|
|
57
57
|
const replaceAlias = createAliasReplacer(tableInfo, tableAliases);
|
|
58
58
|
return {
|
|
59
|
-
select: query.select.map(replaceAlias),
|
|
59
|
+
select: query.select.map(replaceAlias).filter(it => it.kind !== QueryNodeKind.Field || it.name),
|
|
60
60
|
from: replaceAlias(query.from),
|
|
61
61
|
where: query.where ? replaceAlias(query.where) : undefined,
|
|
62
62
|
sort: query.sort ? query.sort.map(replaceAlias) : undefined,
|
|
@@ -2,7 +2,7 @@ import { CommandResponse, DataStoreInfo } from '../index.js';
|
|
|
2
2
|
import { Fields } from './field.js';
|
|
3
3
|
import { ResultRow } from './dsl/query/sql/hydrate.js';
|
|
4
4
|
import { SQLExecutor } from '../db/connectors/dbClient.js';
|
|
5
|
-
import { BooleanValueExpression, Query } from './dsl/query/query.js';
|
|
5
|
+
import { BooleanValueExpression, Query, Sort } from './dsl/query/query.js';
|
|
6
6
|
export declare type EntityResult<Entity, Identifiable> = Identifiable & Partial<Entity>;
|
|
7
7
|
interface Repository<Entity, Creatable, Identifiable> {
|
|
8
8
|
create(entity: Creatable): Promise<Entity>;
|
|
@@ -24,8 +24,16 @@ export declare abstract class SasatRepository<Entity, Creatable, Identifiable, E
|
|
|
24
24
|
create(entity: Creatable): Promise<Entity>;
|
|
25
25
|
update(entity: Identifiable & Partial<Entity>): Promise<CommandResponse>;
|
|
26
26
|
delete(entity: Identifiable): Promise<CommandResponse>;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
first(fields?: EntityFields, option?: {
|
|
28
|
+
where?: BooleanValueExpression;
|
|
29
|
+
sort?: Sort[];
|
|
30
|
+
}): Promise<EntityResult<Entity, Identifiable> | null>;
|
|
31
|
+
find(fields?: EntityFields, options?: {
|
|
32
|
+
where?: BooleanValueExpression;
|
|
33
|
+
sort?: Sort[];
|
|
34
|
+
limit?: number;
|
|
35
|
+
offset?: number;
|
|
36
|
+
}): Promise<EntityResult<Entity, Identifiable>[]>;
|
|
29
37
|
private createIdentifiableExpression;
|
|
30
38
|
}
|
|
31
39
|
export {};
|
|
@@ -45,24 +45,25 @@ export class SasatRepository {
|
|
|
45
45
|
};
|
|
46
46
|
return this.client.rawCommand(deleteToSql(dsl, this.maps.tableInfo));
|
|
47
47
|
}
|
|
48
|
-
async
|
|
48
|
+
async first(fields, option) {
|
|
49
|
+
const result = await this.find(fields, option);
|
|
50
|
+
if (result.length !== 0)
|
|
51
|
+
return result[0];
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
async find(fields, options) {
|
|
49
55
|
const field = fields || { fields: this.fields };
|
|
50
56
|
const query = {
|
|
51
57
|
...fieldToQuery(this.tableName, field, this.maps.relationMap),
|
|
52
|
-
where,
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
where: options?.where,
|
|
59
|
+
sort: options?.sort,
|
|
60
|
+
limit: options?.limit,
|
|
61
|
+
offset: options?.offset,
|
|
55
62
|
};
|
|
56
63
|
const info = createQueryResolveInfo(this.tableName, field, this.maps.relationMap, this.maps.tableInfo);
|
|
57
64
|
const result = await this.query(appendKeysToQuery(query, this.maps.tableInfo));
|
|
58
65
|
return hydrate(result, info);
|
|
59
66
|
}
|
|
60
|
-
async first(fields, where) {
|
|
61
|
-
const result = await this.find(fields, where);
|
|
62
|
-
if (result.length !== 0)
|
|
63
|
-
return result[0];
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
67
|
createIdentifiableExpression(entity) {
|
|
67
68
|
const expr = this.primaryKeys.map(it => {
|
|
68
69
|
const value = entity[it];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sasat",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.11",
|
|
4
4
|
"repository": "https://github.com/yanokunpei/sasat.git",
|
|
5
5
|
"author": "yanokunpei <ninian138@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"prettier": "prettier --write './**/*.ts'",
|
|
21
21
|
"pretest": "yarn resetdb && yarn sasat migrate",
|
|
22
22
|
"test": "env-cmd jest --coverage --silent=false --verbose false",
|
|
23
|
+
"test:single": "env-cmd jest --silent=false --verbose false",
|
|
24
|
+
"test:base": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
23
25
|
"resetdb": "docker-compose exec db sh -c \"mysql -u root < /docker-entrypoint-initdb.d/temp.sql\"",
|
|
24
26
|
"prepare": "yarn build",
|
|
25
27
|
"sasat": "yarn env-cmd ts-node-esm ./src/cli/cli.ts",
|
|
@@ -29,21 +31,21 @@
|
|
|
29
31
|
"cac": "6.7.12",
|
|
30
32
|
"chalk": "5.0.1",
|
|
31
33
|
"fs-extra": "^10.0.0",
|
|
34
|
+
"graphql": "^16.3.0",
|
|
32
35
|
"graphql-subscriptions": "^2.0.0",
|
|
33
36
|
"js-yaml": "^4.0.0",
|
|
34
37
|
"mariadb": "^2.1.5",
|
|
35
|
-
"
|
|
38
|
+
"mysql2": "^2.3.3",
|
|
36
39
|
"pluralize": "^8.0.0",
|
|
37
40
|
"prettier": "^2.0.0",
|
|
38
41
|
"sqlstring": "^2.3.1",
|
|
39
|
-
"typescript": "4.6.3"
|
|
40
|
-
"graphql": "^16.3.0"
|
|
42
|
+
"typescript": "4.6.3"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
45
|
+
"sasat": "link:./src",
|
|
43
46
|
"@types/fs-extra": "9.0.13",
|
|
44
47
|
"@types/jest": "27.4.1",
|
|
45
48
|
"@types/js-yaml": "4.0.5",
|
|
46
|
-
"@types/mysql": "2.15.21",
|
|
47
49
|
"@types/node": "16.11.26",
|
|
48
50
|
"@types/pluralize": "0.0.29",
|
|
49
51
|
"@types/prettier": "2.6.0",
|
|
@@ -76,31 +78,5 @@
|
|
|
76
78
|
"pre-commit": "lint-staged"
|
|
77
79
|
}
|
|
78
80
|
},
|
|
79
|
-
"jest": {
|
|
80
|
-
"moduleFileExtensions": [
|
|
81
|
-
"ts",
|
|
82
|
-
"js"
|
|
83
|
-
],
|
|
84
|
-
"moduleNameMapper": {
|
|
85
|
-
"^sasat": "<rootDir>/lib"
|
|
86
|
-
},
|
|
87
|
-
"coveragePathIgnorePatterns": [
|
|
88
|
-
"/node_modules/",
|
|
89
|
-
"<rootDir>/lib",
|
|
90
|
-
"<rootDir>/test"
|
|
91
|
-
],
|
|
92
|
-
"transform": {
|
|
93
|
-
"^.+\\.(ts|tsx)$": "ts-jest"
|
|
94
|
-
},
|
|
95
|
-
"globals": {
|
|
96
|
-
"ts-jest": {
|
|
97
|
-
"tsConfig": "tsconfig.json",
|
|
98
|
-
"diagnostics": true
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
"testMatch": [
|
|
102
|
-
"**/*.test.+(ts|tsx|js)"
|
|
103
|
-
]
|
|
104
|
-
},
|
|
105
81
|
"type": "module"
|
|
106
82
|
}
|