Skip to content

Commit 6d24947

Browse files
authored
Merge pull request #12 from 188599/minification-support
provided a way to specify table name during mapping
2 parents 4cec5ba + 1c99220 commit 6d24947

21 files changed

Lines changed: 186 additions & 72 deletions

package-lock.json

Lines changed: 46 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77
"scripts": {
88
"test": "tsc & mocha src/test/**/*.spec.js",
99
"test-grep": "tsc & mocha src/test/**/*.spec.js --grep",
10-
"test-single": "tsc & mocha src/test/**/*.spec.js --grep Mapper --debug-brk",
10+
"test-single": "tsc && mocha --inspect src/test/**/*.spec.js --grep Mapper",
1111
"test-debug": "mocha -r ts-node/register src/test/**/*.spec.ts --debug-brk",
1212
"lint": "tslint -p tsconfig.json",
1313
"build": "tsc",
1414
"publish-npm": "tsc & npm publish",
1515
"publish-npm-alpha": "tsc && npm publish --tag alpha",
16-
"pack": "cd dist/ & npm pack ../"
16+
"pack": "cd dist/ & npm pack ../",
17+
"minify": "terser -o minification-test.spec.min.js -m -- minification-test.spec.js",
18+
"mapper-test-minified": "tsc && npm run minify && mocha --inspect minification-test.spec.min.js",
19+
"terser": "terser",
20+
"compile-watch": "tsc -w",
21+
"mocha": "mocha"
1722
},
1823
"dependencies": {
1924
"lambda-expression": ">=0.1.4",
2025
"lodash": "^4.17.15",
2126
"moment": "^2.22.0",
27+
"reflect-metadata": "^0.1.13",
2228
"rxjs": "^6.5.3",
2329
"uuid": "^3.3.2"
2430
},
@@ -35,9 +41,10 @@
3541
"mocha": "^6.2.2",
3642
"sinon": "^9.0.0",
3743
"sqlite3": "^4.1.1",
44+
"terser": "^5.10.0",
3845
"ts-node": "^8.5.4",
3946
"tslint": "^5.20.1",
40-
"typescript": "~3.2.2"
47+
"typescript": "^4.5.4"
4148
},
4249
"keywords": [
4350
"orm",

src/adapters/sqlite3-database-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class SQLite3DatabaseAdapter extends BaseDatabaseAdapter<SQLite3ObjectInt
3939
databaseNative: SQLite3ObjectInterface
4040
): (fn: (transaction: WebSqlTransactionInterface) => void) => Promise<any> {
4141
return (fn: (transaction: DatabaseBaseTransaction) => void): Promise<any> => {
42-
return new Promise<any>((resolve, reject) => {
42+
return new Promise<void>((resolve, reject) => {
4343
this.executeSql(databaseNative, "BEGIN TRANSACTION", [])
4444
.then(_ => {
4545
try {

src/core/row-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class RowResult<T> {
7070
ModelUtils.set(result, column.fieldReference, value);
7171
// TODO: essa associação será redundante para itens de primeiro nivel, mas será mantida para compatibilidade com itens de segundo nivel ou mais, pois há mapper que buscam a propriedade de sub nivel pelo nome da coluna por exemplo: 'cliente_cidade_uf_id'
7272
// BREAKING-CHANGE: Na proxima versão da aplicação essa compatibilidade deve ser removida, o que era causar quebra de versão, onde terá que ser alterada implementações que o "mapper" para obter valores de propriedades de sub nivel.
73-
result[column.column] = value;
73+
(result as any)[column.column] = value;
7474
}
7575
});
7676
return result;

src/core/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ export class Utils {
205205
return this.isQueryCompilable(value) || this.isQueryCompiledArray(value);
206206
}
207207

208-
public static databaseName<T>(tablename: TypeOrString<T>): string {
209-
return this.getValueByTypeOrString(tablename);
210-
}
211-
212208
public static getMapperTable<T>(
213209
typeT: (new () => T) | QueryBuilder<T> | { _builder: () => QueryBuilder<T> },
214210
getMapper: (tKey: (new () => any) | string) => MetadataTable<any>
@@ -244,10 +240,6 @@ export class Utils {
244240
: ExpressionOrValueEnum.Expression;
245241
}
246242

247-
public static getValueByTypeOrString<T>(param: TypeOrString<T>): string {
248-
return this.isString(param) ? param as string : (param as (new () => T)).name;
249-
}
250-
251243
public static getColumn<TReturn, T>(expression: ExpressionOrColumn<TReturn, T>, separator?: string): string {
252244
const type = this.expressionOrColumn(expression);
253245
switch (type) {

src/crud/crud.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Utils } from "../core/utils";
1010
import { KeyUtils } from "../core/key-utils";
1111
import { QueryBuilder } from "./query/query-builder";
1212
import { MetadataTableBase } from "../metadata-table-base";
13+
import { MapperUtils } from "../mapper/mapper-utils";
1314

1415
export class Crud {
1516
public enableLog: boolean;
@@ -137,16 +138,13 @@ export class Crud {
137138
}
138139

139140
private getDatabase() {
140-
// if (!this._database) {
141-
// throw new DatabaseBuilderError("Transaction ou Database not specified in query.");
142-
// }
143141
return this._database;
144142
}
145143

146144
private getMapper<T>(tKey: (new () => T) | string): MetadataTable<T> {
147145
const metadata = this._getMapper.get(tKey);
148146
if (Utils.isNull(metadata)) {
149-
throw new DatabaseBuilderError(`Mapper for "${Utils.isString(tKey) ? tKey : (tKey as new () => T).name}" not found!"`);
147+
throw new DatabaseBuilderError(`Mapper for "${MapperUtils.resolveKey(tKey)}" not found!"`);
150148
}
151149
return metadata;
152150
}

src/crud/delete/delete-columns-builder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ export class DeleteColumnsBuilder<T> extends ColumnsValuesBuilder<T, DeleteColum
1010

1111
protected columnFormat(column: Column): string {
1212
throw new DatabaseBuilderError(`Mapper '${this.mapperTable.tableName}', method not supported.`);
13-
// throw new DatabaseBuilderError(`Mapper '${this.metadata.newable.name}', method not supported.`);
1413
}
1514
}

src/crud/insert/insert-columns-builder.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export class InsertColumnsBuilder<T> extends ColumnsValuesBuilder<T, InsertColum
1212
return super.isAddColumn(column) && !(column.primaryKeyType === PrimaryKeyType.AutoIncrement);
1313
}
1414

15-
// protected columnFormat(column: Column): string {
16-
// // return column.primaryKeyType === PrimaryKeyType.AutoIncrement ? void 0 : column.name;
17-
// // return column.isAutoIncrement ? void 0 : column.name;
18-
// }
19-
2015
protected allowGenerateKey(): boolean {
2116
return true;
2217
}

src/crud/projection-builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DatabaseBuilderError } from "../core/errors";
1414
import { SqlCompilable } from "./sql-compilable";
1515
import { ProjectionModel } from "./projection-model";
1616
import { ProjectionCompile } from "./projection-compile";
17+
import { MapperUtils } from "../mapper/mapper-utils";
1718

1819
export class ProjectionBuilder<T> {
1920
private _projections: ProjectionModel[] = [];
@@ -47,7 +48,7 @@ export class ProjectionBuilder<T> {
4748

4849
public allByMap(metadata: MetadataTable<T>) {
4950
if (Utils.isNull(metadata)) {
50-
throw new DatabaseBuilderError(`Mapper not found for '${this._typeT.name}'`);
51+
throw new DatabaseBuilderError(`Mapper not found for '${MapperUtils.resolveKey(this._typeT)}'`);
5152
}
5253
this.selectAllColumns(metadata.mapperTable);
5354
}

src/crud/sql-base-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export abstract class SqlBaseBuilder<T> implements QueryCompilable {
2929
this._alias = this.createAlias(this._alias, this._tablename);
3030
}
3131

32-
protected createTablename<TTable>(currentTypeT: new () => TTable, currentMapper: MapperTable): string {
33-
return currentTypeT ? currentTypeT.name : currentMapper.tableName;
32+
protected createTablename<TTable>(_currentTypeT: new () => TTable, currentMapper: MapperTable): string {
33+
return currentMapper.tableName;
3434
}
3535

3636
protected createAlias(currentAlias: string, currentTablename: string): string {

0 commit comments

Comments
 (0)