@eggjs/dal-runtime 4.0.0-beta.7 → 4.0.0-beta.8

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/dist/index.d.ts CHANGED
@@ -1,15 +1,244 @@
1
- import { BaseSqlMapGenerator } from "./BaseSqlMap.js";
2
- import { CodeGenerator } from "./CodeGenerator.js";
3
- import { DaoLoader } from "./DaoLoader.js";
4
- import { DataSourceOptions, MysqlDataSource } from "./MySqlDataSource.js";
5
- import { DatabaseForker } from "./DatabaseForker.js";
6
- import { TableSqlMap } from "./TableSqlMap.js";
7
- import { DataSource, ExecuteSql } from "./DataSource.js";
8
- import { NunjucksConverter } from "./NunjucksConverter.js";
9
- import { NunjucksUtils } from "./NunjucksUtil.js";
10
- import { SqlGenerator } from "./SqlGenerator.js";
11
- import { SqlMapLoader } from "./SqlMapLoader.js";
12
- import { SqlUtil } from "./SqlUtil.js";
13
- import { TableModelInstanceBuilder } from "./TableModelInstanceBuilder.js";
14
- import { TemplateUtil } from "./TemplateUtil.js";
1
+ import { BaseDaoType, ColumnModel, TableModel } from "@eggjs/dal-decorator";
2
+ import { CodeGeneratorOptions, ColumnType, DataSource as DataSource$1, GenerateSqlMap, Geometry, GeometryCollection, Line, Logger, MultiLine, MultiPoint, MultiPolygon, PaginateData, Point, Polygon, SqlMap, SqlType, Templates } from "@eggjs/tegg-types";
3
+ import nunjucks, { Template } from "nunjucks";
4
+ import { BaseDaoType as BaseDaoType$1 } from "@eggjs/tegg-types/dal";
5
+ import { RDSClientOptions } from "@eggjs/rds";
6
+ import { Base } from "sdk-base";
7
+
8
+ //#region src/BaseSqlMap.d.ts
9
+ declare class BaseSqlMapGenerator {
10
+ private readonly tableModel;
11
+ private readonly logger;
12
+ constructor(tableModel: TableModel, logger: Logger);
13
+ generateAllColumns(countIf: boolean): string;
14
+ generateFindByPrimary(): Array<GenerateSqlMap>;
15
+ generateFindByIndexes(): GenerateSqlMap[];
16
+ generateInsert(): string;
17
+ generateUpdate(): string;
18
+ generateDelete(): string;
19
+ load(): Record<string, SqlMap>;
20
+ }
21
+ //#endregion
22
+ //#region src/CodeGenerator.d.ts
23
+ declare class CodeGenerator {
24
+ private readonly moduleDir;
25
+ private readonly moduleName;
26
+ private readonly teggPkg;
27
+ private readonly dalPkg;
28
+ constructor(options: CodeGeneratorOptions);
29
+ private njkEnv;
30
+ createNunjucksEnv(): void;
31
+ genCode(tplName: Templates, filePath: string, tableModel: TableModel): string;
32
+ generate(tableModel: TableModel): Promise<void>;
33
+ }
34
+ //#endregion
35
+ //#region src/DaoLoader.d.ts
36
+ declare class DaoLoader {
37
+ static loadDaos(moduleDir: string): Promise<Array<BaseDaoType$1>>;
38
+ }
39
+ //#endregion
40
+ //#region src/MySqlDataSource.d.ts
41
+ interface DataSourceOptions extends RDSClientOptions {
42
+ name: string;
43
+ initSql?: string;
44
+ forkDb?: boolean;
45
+ initRetryTimes?: number;
46
+ logger?: Logger;
47
+ }
48
+ declare class MysqlDataSource extends Base {
49
+ #private;
50
+ private client;
51
+ private readonly initSql;
52
+ readonly name: string;
53
+ readonly timezone?: string;
54
+ readonly rdsOptions: RDSClientOptions;
55
+ readonly forkDb?: boolean;
56
+ constructor(options: DataSourceOptions);
57
+ protected _init(): Promise<void>;
58
+ query<T = any>(sql: string): Promise<T>;
59
+ beginTransactionScope<T>(scope: () => Promise<T>): Promise<T>;
60
+ }
61
+ //#endregion
62
+ //#region src/DatabaseForker.d.ts
63
+ declare class DatabaseForker {
64
+ private readonly env;
65
+ private readonly options;
66
+ constructor(env: string, options: DataSourceOptions);
67
+ shouldFork(): boolean;
68
+ forkDb(moduleDir: string): Promise<void>;
69
+ private forkTables;
70
+ private doForkTable;
71
+ private doCreateUtDb;
72
+ destroy(): Promise<void>;
73
+ }
74
+ //#endregion
75
+ //#region src/TableSqlMap.d.ts
76
+ declare class TableSqlMap {
77
+ #private;
78
+ readonly name: string;
79
+ private readonly map;
80
+ private readonly blocks;
81
+ private readonly sqlGenerator;
82
+ constructor(name: string, map: Record<string, SqlMap>);
83
+ generate(name: string, data: object, timezone: string): string;
84
+ getType(name: string): SqlType;
85
+ getTemplateString(name: string): string;
86
+ }
87
+ //#endregion
88
+ //#region src/DataSource.d.ts
89
+ interface ExecuteSql {
90
+ sql: string;
91
+ template: string;
92
+ sqlType: SqlType;
93
+ }
94
+ declare class DataSource<T> implements DataSource$1<T> {
95
+ #private;
96
+ private readonly tableModel;
97
+ private readonly mysqlDataSource;
98
+ private readonly sqlMap;
99
+ constructor(tableModel: TableModel<T>, mysqlDataSource: MysqlDataSource, sqlMap: TableSqlMap);
100
+ /**
101
+ * public for aop execute to implement sql hint append
102
+ * @param sqlName - sql name
103
+ * @param data - sql data
104
+ */
105
+ generateSql(sqlName: string, data: object): Promise<ExecuteSql>;
106
+ count(sqlName: string, data?: any): Promise<number>;
107
+ execute(sqlName: string, data?: any): Promise<Array<T>>;
108
+ executeRaw(sqlName: string, data?: any): Promise<Array<any>>;
109
+ executeScalar(sqlName: string, data?: any): Promise<T | null>;
110
+ executeRawScalar(sqlName: string, data?: any): Promise<any | null>;
111
+ paginate(sqlName: string, data: any, currentPage: number, perPageCount: number): Promise<PaginateData<T>>;
112
+ }
113
+ //#endregion
114
+ //#region src/NunjucksConverter.d.ts
115
+ declare class NunjucksConverter {
116
+ /**
117
+ * 将变量 HTML 转义的逻辑改为 MySQL 防注入转义
118
+ *
119
+ * eg:
120
+ *
121
+ * output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "allColumns")
122
+ *
123
+ * 转换为
124
+ *
125
+ * output += runtime.escapeSQL.call(this, "allColumns", runtime.contextOrFrameLookup(context, frame, "allColumns")
126
+ *
127
+ * @param {String} code 转换前的代码
128
+ * @return {String} 转换后的代码
129
+ */
130
+ static convertNormalVariableCode(code: string): string;
131
+ /**
132
+ * 三目运算的 MySQL 防注入转义
133
+ *
134
+ * eg:
135
+ *
136
+ * output += runtime.suppressValue((runtime.contextOrFrameLookup(context, frame, "$gmtCreate") !== \
137
+ * runtime.contextOrFrameLookup(context, frame, "undefined")?runtime.contextOrFrameLookup(context,\
138
+ * frame, "$gmtCreate"):"NOW()"), env.opts.autoescape);
139
+ *
140
+ * 转换为
141
+ *
142
+ * output += runtime.suppressValue((runtime.contextOrFrameLookup(...) != ...) ?
143
+ * runtime.escapeSQL.call(this, "...", runtime.contextOrFrameLookup(...)) :
144
+ * ...)
145
+ *
146
+ * @param {String} code 转换前的代码
147
+ * @return {String} 转换后的代码
148
+ */
149
+ static convertTernaryCode(code: string): string;
150
+ /**
151
+ * 对象的属性,如 `user.id` 防注入转义
152
+ *
153
+ * eg:
154
+ * output += runtime.suppressValue(runtime.memberLookup(\
155
+ * (runtime.contextOrFrameLookup(context, frame, "user")),"id"), env.opts.autoescape);
156
+ *
157
+ * 转换为
158
+ *
159
+ * output += runtime.escapeSQL.call(this, "<...>", runtime.memberLookup(...), env.opts.autoescape);
160
+ *
161
+ * 由于 escapeSQL 中是根据 key 与预定义 block 匹配决定是否转义,而 memberLookup 的状态下总的 key 肯定不会匹配,
162
+ * 所以找一个绝对不会匹配的 "<...>" 传入。事实上它可以是任意一个不会被匹配的字符串,比如说 ">_<" 等。
163
+ *
164
+ * @param {String} code 转换前的代码
165
+ * @return {String} 转换后的代码
166
+ */
167
+ static convertNestedObjectCode(code: string): string;
168
+ /**
169
+ * For 中的 `t_xxx` 要被转义:
170
+ *
171
+ * eg:
172
+ * frame.set("...", t_...);
173
+ * ...
174
+ * output += runtime.suppressValue(t_.., env.opts.autoscape);
175
+ *
176
+ * 转换为
177
+ *
178
+ * output += runtime.escapeSQL.call(this, "for.t_...", t_..., env.opts.autoescape);
179
+ *
180
+ * 由于 escapeSQL 中是根据 key 与预定义 block 匹配决定是否转义,而 memberLookup 的状态下总的 key 肯定不会匹配,
181
+ * 所以找一个绝对不会匹配的 "for.t_..." 传入。事实上它可以是任意一个不会被匹配的字符串,比如说 ">_<" 等。
182
+ *
183
+ * @param {String} code 转换前的代码
184
+ * @return {String} 转换后的代码
185
+ */
186
+ static convertValueInsideFor(code: string): string;
187
+ }
188
+ //#endregion
189
+ //#region src/NunjucksUtil.d.ts
190
+ declare class NunjucksUtils {
191
+ static createEnv(modelName: string): nunjucks.Environment;
192
+ static compile(modelName: string, sqlName: string, sql: string): nunjucks.Template;
193
+ }
194
+ //#endregion
195
+ //#region src/SqlGenerator.d.ts
196
+ declare class SqlGenerator {
197
+ private formatComment;
198
+ private generateColumn;
199
+ private generateColumnType;
200
+ private generateIndex;
201
+ private generateTableOptions;
202
+ generate(tableModel: TableModel): string;
203
+ }
204
+ //#endregion
205
+ //#region src/SqlMapLoader.d.ts
206
+ declare class SqlMapLoader {
207
+ private readonly logger;
208
+ private readonly tableModel;
209
+ private readonly clazzExtension;
210
+ constructor(tableModel: TableModel, baseDaoClazz: BaseDaoType, logger: Logger);
211
+ load(): TableSqlMap;
212
+ }
213
+ //#endregion
214
+ //#region src/SqlUtil.d.ts
215
+ declare class SqlUtil {
216
+ static minify(sql: string): string;
217
+ }
218
+ //#endregion
219
+ //#region src/TableModelInstanceBuilder.d.ts
220
+ declare class TableModelInstanceBuilder {
221
+ constructor(tableModel: TableModel, row: Record<string, any>);
222
+ static buildInstance<T>(tableModel: TableModel<T>, row: Record<string, any>): any;
223
+ static buildRow<T extends object>(instance: T, tableModel: TableModel<T>): any;
224
+ }
225
+ //#endregion
226
+ //#region src/TemplateUtil.d.ts
227
+ declare class TemplateUtil {
228
+ static isSpatialType(columnModel: ColumnModel): boolean;
229
+ static importPath(tableModelPath: string, currentPath: string): string;
230
+ static dbTypeToTsType(columnType: ColumnType): string;
231
+ static toJson(value: any): string;
232
+ static toPoint(point: Point): string;
233
+ static toLine(val: Line): string;
234
+ static toPolygon(val: Polygon): string;
235
+ static toGeometry(val: Geometry): string;
236
+ static toMultiPoint(val: MultiPoint): string;
237
+ static toMultiLine(val: MultiLine): string;
238
+ static toMultiPolygon(val: MultiPolygon): string;
239
+ static toGeometryCollection(val: GeometryCollection): string;
240
+ static spatialFilter: Record<ColumnType, string>;
241
+ static getSpatialFilter(columnType: ColumnType): string;
242
+ }
243
+ //#endregion
15
244
  export { BaseSqlMapGenerator, CodeGenerator, DaoLoader, DataSource, DataSourceOptions, DatabaseForker, ExecuteSql, MysqlDataSource, NunjucksConverter, NunjucksUtils, SqlGenerator, SqlMapLoader, SqlUtil, TableModelInstanceBuilder, TableSqlMap, TemplateUtil };