sasat 0.14.10 → 0.14.13
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/generator/ts/code/factory.d.ts +1 -1
- package/lib/generator/ts/code/factory.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/db/generatedRepositoryGenerator.js +3 -2
- package/lib/generator/ts/gql/mutationGenerator.js +2 -2
- package/lib/migration/creators/tableCreator.d.ts +2 -2
- package/lib/migration/creators/tableCreator.js +2 -2
- package/lib/migration/serializable/table.d.ts +1 -1
- package/lib/migration/serializable/table.js +3 -3
- package/lib/migration/serialized/serializedColumn.d.ts +1 -0
- package/lib/runtime/dsl/factory.d.ts +10 -8
- package/lib/runtime/dsl/factory.js +7 -0
- package/lib/runtime/dsl/query/query.d.ts +2 -1
- package/lib/runtime/sasatRepository.d.ts +11 -3
- package/lib/runtime/sasatRepository.js +11 -10
- package/package.json +6 -29
|
@@ -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';
|
|
@@ -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() {
|
|
@@ -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';
|
|
@@ -7,7 +7,7 @@ import { GqlOption } from '../data/gqlOption.js';
|
|
|
7
7
|
import { DataStore } from '../dataStore.js';
|
|
8
8
|
export interface TableBuilder {
|
|
9
9
|
column(columnName: string): ColumnCreator;
|
|
10
|
-
references(reference: Reference): TableBuilder;
|
|
10
|
+
references(reference: Reference, notNull: boolean): TableBuilder;
|
|
11
11
|
setPrimaryKey(...columnNames: string[]): TableBuilder;
|
|
12
12
|
addUniqueKey(...columnNames: string[]): TableBuilder;
|
|
13
13
|
createdAt(): TableBuilder;
|
|
@@ -23,7 +23,7 @@ export declare class TableCreator implements TableBuilder {
|
|
|
23
23
|
column(name: string): ColumnCreator;
|
|
24
24
|
addColumn(column: ColumnBuilder): void;
|
|
25
25
|
addUniqueKey(...columnNames: string[]): TableBuilder;
|
|
26
|
-
references(ref: Reference): TableBuilder;
|
|
26
|
+
references(ref: Reference, notNull?: boolean): TableBuilder;
|
|
27
27
|
setPrimaryKey(...columnNames: string[]): TableBuilder;
|
|
28
28
|
create(): TableHandler;
|
|
29
29
|
createdAt(): TableBuilder;
|
|
@@ -19,8 +19,8 @@ export class TableCreator {
|
|
|
19
19
|
this.table.addUniqueKey(...columnNames);
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
|
-
references(ref) {
|
|
23
|
-
this.table.addReferences(ref);
|
|
22
|
+
references(ref, notNull = true) {
|
|
23
|
+
this.table.addReferences(ref, undefined, notNull);
|
|
24
24
|
return this;
|
|
25
25
|
}
|
|
26
26
|
setPrimaryKey(...columnNames) {
|
|
@@ -29,7 +29,7 @@ export declare class TableHandler implements Table {
|
|
|
29
29
|
addColumn(column: BaseColumn, isPrimary?: boolean, isUnique?: boolean): void;
|
|
30
30
|
dropColumn(columnName: string): void;
|
|
31
31
|
serialize(): SerializedTable;
|
|
32
|
-
addReferences(ref: Reference, fieldName?: string): this;
|
|
32
|
+
addReferences(ref: Reference, fieldName?: string, notNull?: boolean): this;
|
|
33
33
|
private getIndexConstraintName;
|
|
34
34
|
addIndex(...columns: string[]): this;
|
|
35
35
|
removeIndex(...columns: string[]): this;
|
|
@@ -56,7 +56,7 @@ export class TableHandler {
|
|
|
56
56
|
gqlOption: this.gqlOption,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
addReferences(ref, fieldName) {
|
|
59
|
+
addReferences(ref, fieldName, notNull = true) {
|
|
60
60
|
const target = this.store.table(ref.targetTable).column(ref.targetColumn);
|
|
61
61
|
const targetData = target.serialize();
|
|
62
62
|
const data = {
|
|
@@ -64,7 +64,7 @@ export class TableHandler {
|
|
|
64
64
|
hasReference: true,
|
|
65
65
|
fieldName: fieldName || ref.columnName,
|
|
66
66
|
columnName: ref.columnName,
|
|
67
|
-
notNull
|
|
67
|
+
notNull,
|
|
68
68
|
default: undefined,
|
|
69
69
|
zerofill: false,
|
|
70
70
|
autoIncrement: false,
|
|
@@ -109,7 +109,7 @@ export class TableHandler {
|
|
|
109
109
|
rows.push(`UNIQUE KEY (${it.join(',')})`);
|
|
110
110
|
});
|
|
111
111
|
rows.push(...this._columns
|
|
112
|
-
.filter(it => it.isReference())
|
|
112
|
+
.filter(it => it.isReference() && it.data.reference.noFKey)
|
|
113
113
|
.map(it => {
|
|
114
114
|
const ref = it;
|
|
115
115
|
return referenceToSql(ref.getConstraintName(), ref.data.reference);
|
|
@@ -28,6 +28,7 @@ export interface Reference {
|
|
|
28
28
|
relationName?: string;
|
|
29
29
|
onUpdate?: ForeignKeyReferentialAction;
|
|
30
30
|
onDelete?: ForeignKeyReferentialAction;
|
|
31
|
+
noFKey?: boolean;
|
|
31
32
|
}
|
|
32
33
|
export declare const referenceToSql: (constraintName: string, ref: Reference) => string;
|
|
33
34
|
export interface SerializedReferenceColumn extends SerializedColumnBase {
|
|
@@ -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?: JoinType | undefined) => Join;
|
|
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
|
};
|
|
@@ -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 {};
|
|
@@ -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.13",
|
|
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",
|
|
@@ -37,9 +39,10 @@
|
|
|
37
39
|
"pluralize": "^8.0.0",
|
|
38
40
|
"prettier": "^2.0.0",
|
|
39
41
|
"sqlstring": "^2.3.1",
|
|
40
|
-
"typescript": "4.
|
|
42
|
+
"typescript": "4.7.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",
|
|
@@ -51,7 +54,7 @@
|
|
|
51
54
|
"@typescript-eslint/parser": "5.19.0",
|
|
52
55
|
"apollo-server": "3.6.7",
|
|
53
56
|
"env-cmd": "10.1.0",
|
|
54
|
-
"eslint": "8.
|
|
57
|
+
"eslint": "8.17.0",
|
|
55
58
|
"eslint-config-prettier": "8.5.0",
|
|
56
59
|
"eslint-plugin-prettier": "4.0.0",
|
|
57
60
|
"husky": "7.0.4",
|
|
@@ -75,31 +78,5 @@
|
|
|
75
78
|
"pre-commit": "lint-staged"
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
|
-
"jest": {
|
|
79
|
-
"moduleFileExtensions": [
|
|
80
|
-
"ts",
|
|
81
|
-
"js"
|
|
82
|
-
],
|
|
83
|
-
"moduleNameMapper": {
|
|
84
|
-
"^sasat": "<rootDir>/lib"
|
|
85
|
-
},
|
|
86
|
-
"coveragePathIgnorePatterns": [
|
|
87
|
-
"/node_modules/",
|
|
88
|
-
"<rootDir>/lib",
|
|
89
|
-
"<rootDir>/test"
|
|
90
|
-
],
|
|
91
|
-
"transform": {
|
|
92
|
-
"^.+\\.(ts|tsx)$": "ts-jest"
|
|
93
|
-
},
|
|
94
|
-
"globals": {
|
|
95
|
-
"ts-jest": {
|
|
96
|
-
"tsConfig": "tsconfig.json",
|
|
97
|
-
"diagnostics": true
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
"testMatch": [
|
|
101
|
-
"**/*.test.+(ts|tsx|js)"
|
|
102
|
-
]
|
|
103
|
-
},
|
|
104
81
|
"type": "module"
|
|
105
82
|
}
|