@nathapp/nestjs-data 1.0.0-rc.12 → 1.0.0-rc.14
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/repository/base.repository.d.ts +1 -0
- package/dist/repository/base.repository.js +39 -37
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/testing-utils.d.ts +53 -0
- package/dist/testing/testing-utils.js +23 -0
- package/dist/typeorm/base-typeorm-options-factory.d.ts +2 -1
- package/dist/typeorm/base-typeorm-options-factory.js +1 -1
- package/dist/typeorm/typeorm-utils.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./decorator"), exports);
|
|
|
18
18
|
__exportStar(require("./entities"), exports);
|
|
19
19
|
__exportStar(require("./repository"), exports);
|
|
20
20
|
__exportStar(require("./pagination"), exports);
|
|
21
|
+
__exportStar(require("./testing"), exports);
|
|
21
22
|
__exportStar(require("./typeorm"), exports);
|
|
@@ -11,6 +11,7 @@ export declare abstract class BaseSpRepository extends BaseRepository {
|
|
|
11
11
|
readonly executeCommand: string;
|
|
12
12
|
constructor(dataSource: DataSource, executeCommand?: string);
|
|
13
13
|
callQuery(spName: string, formatOrValue?: any, params?: any, rename?: (key: string, depth: number, object: any) => string, objectifyForSignleRecord?: boolean): Promise<any>;
|
|
14
|
+
private resolveRecordsets;
|
|
14
15
|
private prepare;
|
|
15
16
|
private renameKey;
|
|
16
17
|
private changeKey;
|
|
@@ -15,50 +15,52 @@ class BaseSpRepository extends BaseRepository {
|
|
|
15
15
|
}
|
|
16
16
|
async callQuery(spName, formatOrValue, params, rename, objectifyForSignleRecord = false) {
|
|
17
17
|
const { formattedSP, paramaters } = await this.prepare(spName, formatOrValue, params);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const results = await this.dataSource.query(formattedSP, paramaters);
|
|
19
|
+
return this.resolveRecordsets(results, rename, objectifyForSignleRecord);
|
|
20
|
+
}
|
|
21
|
+
resolveRecordsets(results, rename, objectifyForSignleRecord = false) {
|
|
22
|
+
if (!Array.isArray(results)) {
|
|
23
|
+
if (objectifyForSignleRecord) {
|
|
24
|
+
return {};
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const result = [];
|
|
35
|
-
for (let i = 0; recordset.length > i; i++) {
|
|
36
|
-
const record = recordset[i];
|
|
37
|
-
result.push(this.renameKey(record, rename));
|
|
38
|
-
}
|
|
39
|
-
recordsets.push(result);
|
|
40
|
-
}
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const status = results.pop();
|
|
29
|
+
if (1 < results.length) {
|
|
30
|
+
const recordsets = [];
|
|
31
|
+
for (let i = 0; results.length > i; i++) {
|
|
32
|
+
const recordset = results[i];
|
|
33
|
+
if (!rename) {
|
|
34
|
+
recordsets.push(recordset);
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (rename) {
|
|
48
|
-
return this.renameKey(recordset[0], rename);
|
|
36
|
+
else {
|
|
37
|
+
const result = [];
|
|
38
|
+
for (let i = 0; recordset.length > i; i++) {
|
|
39
|
+
const record = recordset[i];
|
|
40
|
+
result.push(this.renameKey(record, rename));
|
|
49
41
|
}
|
|
50
|
-
|
|
42
|
+
recordsets.push(result);
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
return recordsets;
|
|
46
|
+
}
|
|
47
|
+
const recordset = results[0];
|
|
48
|
+
if (objectifyForSignleRecord) {
|
|
49
|
+
if (1 == recordset.length) {
|
|
50
|
+
if (rename) {
|
|
51
|
+
return this.renameKey(recordset[0], rename);
|
|
57
52
|
}
|
|
58
|
-
return
|
|
53
|
+
return recordset[0];
|
|
59
54
|
}
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
}
|
|
56
|
+
if (rename) {
|
|
57
|
+
const result = [];
|
|
58
|
+
for (let i = 0; recordset.length > i; i++) {
|
|
59
|
+
result.push(this.renameKey(recordset[i], rename));
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
return recordset;
|
|
62
64
|
}
|
|
63
65
|
async prepare(spName, formatOrValue, params) {
|
|
64
66
|
let paramaters = [];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEmptySingleResult = exports.resolveQueryArrayResult = exports.resolveQuerySingleResult = exports.sqlQueryResult = void 0;
|
|
4
|
+
const testing_utils_1 = require("./testing-utils");
|
|
5
|
+
Object.defineProperty(exports, "sqlQueryResult", { enumerable: true, get: function () { return testing_utils_1.sqlQueryResult; } });
|
|
6
|
+
Object.defineProperty(exports, "resolveQuerySingleResult", { enumerable: true, get: function () { return testing_utils_1.resolveQuerySingleResult; } });
|
|
7
|
+
Object.defineProperty(exports, "resolveQueryArrayResult", { enumerable: true, get: function () { return testing_utils_1.resolveQueryArrayResult; } });
|
|
8
|
+
Object.defineProperty(exports, "resolveEmptySingleResult", { enumerable: true, get: function () { return testing_utils_1.resolveEmptySingleResult; } });
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const sqlQueryResult: {
|
|
2
|
+
fieldCount: number;
|
|
3
|
+
affectedRows: number;
|
|
4
|
+
insertId: number;
|
|
5
|
+
info: string;
|
|
6
|
+
serverStatus: number;
|
|
7
|
+
warningStatus: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const resolveQuerySingleResult: (result: any, statusQueryResult?: {
|
|
10
|
+
fieldCount: number;
|
|
11
|
+
affectedRows: number;
|
|
12
|
+
insertId: number;
|
|
13
|
+
info: string;
|
|
14
|
+
serverStatus: number;
|
|
15
|
+
warningStatus: number;
|
|
16
|
+
}) => (any[] | {
|
|
17
|
+
fieldCount: number;
|
|
18
|
+
affectedRows: number;
|
|
19
|
+
insertId: number;
|
|
20
|
+
info: string;
|
|
21
|
+
serverStatus: number;
|
|
22
|
+
warningStatus: number;
|
|
23
|
+
})[];
|
|
24
|
+
export declare const resolveQueryArrayResult: (results: any[], statusQueryResult?: {
|
|
25
|
+
fieldCount: number;
|
|
26
|
+
affectedRows: number;
|
|
27
|
+
insertId: number;
|
|
28
|
+
info: string;
|
|
29
|
+
serverStatus: number;
|
|
30
|
+
warningStatus: number;
|
|
31
|
+
}) => (any[] | {
|
|
32
|
+
fieldCount: number;
|
|
33
|
+
affectedRows: number;
|
|
34
|
+
insertId: number;
|
|
35
|
+
info: string;
|
|
36
|
+
serverStatus: number;
|
|
37
|
+
warningStatus: number;
|
|
38
|
+
})[];
|
|
39
|
+
export declare const resolveEmptySingleResult: (statusQueryResult?: {
|
|
40
|
+
fieldCount: number;
|
|
41
|
+
affectedRows: number;
|
|
42
|
+
insertId: number;
|
|
43
|
+
info: string;
|
|
44
|
+
serverStatus: number;
|
|
45
|
+
warningStatus: number;
|
|
46
|
+
}) => (any[] | {
|
|
47
|
+
fieldCount: number;
|
|
48
|
+
affectedRows: number;
|
|
49
|
+
insertId: number;
|
|
50
|
+
info: string;
|
|
51
|
+
serverStatus: number;
|
|
52
|
+
warningStatus: number;
|
|
53
|
+
})[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEmptySingleResult = exports.resolveQueryArrayResult = exports.resolveQuerySingleResult = exports.sqlQueryResult = void 0;
|
|
4
|
+
exports.sqlQueryResult = {
|
|
5
|
+
fieldCount: 0,
|
|
6
|
+
affectedRows: 0,
|
|
7
|
+
insertId: 0,
|
|
8
|
+
info: '',
|
|
9
|
+
serverStatus: 34,
|
|
10
|
+
warningStatus: 0,
|
|
11
|
+
};
|
|
12
|
+
const resolveQuerySingleResult = (result, statusQueryResult = exports.sqlQueryResult) => {
|
|
13
|
+
return [[result], statusQueryResult];
|
|
14
|
+
};
|
|
15
|
+
exports.resolveQuerySingleResult = resolveQuerySingleResult;
|
|
16
|
+
const resolveQueryArrayResult = (results, statusQueryResult = exports.sqlQueryResult) => {
|
|
17
|
+
return [results, statusQueryResult];
|
|
18
|
+
};
|
|
19
|
+
exports.resolveQueryArrayResult = resolveQueryArrayResult;
|
|
20
|
+
const resolveEmptySingleResult = (statusQueryResult = exports.sqlQueryResult) => {
|
|
21
|
+
return [[], statusQueryResult];
|
|
22
|
+
};
|
|
23
|
+
exports.resolveEmptySingleResult = resolveEmptySingleResult;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from "@nestjs/typeorm";
|
|
2
2
|
import { EntitySchema, MixedList } from "typeorm";
|
|
3
3
|
import { BaseDataSourceOptions } from "typeorm/data-source/BaseDataSourceOptions";
|
|
4
|
-
|
|
4
|
+
import { MysqlConnectionOptions } from "typeorm/driver/mysql/MysqlConnectionOptions";
|
|
5
|
+
export type OptionWithoutEntities = Omit<Partial<BaseDataSourceOptions>, "entities" | "type"> | Omit<Partial<MysqlConnectionOptions>, "entities" | "type">;
|
|
5
6
|
export declare class BaseTypeOrmModuleOptionFactory implements TypeOrmOptionsFactory {
|
|
6
7
|
private readonly connectionString;
|
|
7
8
|
private readonly entities?;
|
|
@@ -34,7 +34,7 @@ class BaseTypeOrmModuleOptionFactory {
|
|
|
34
34
|
exports.BaseTypeOrmModuleOptionFactory = BaseTypeOrmModuleOptionFactory;
|
|
35
35
|
class DefaultTypeOrmModuleOptionFactory extends BaseTypeOrmModuleOptionFactory {
|
|
36
36
|
constructor(entities, options) {
|
|
37
|
-
super(process.env.
|
|
37
|
+
super(process.env.MYSQL_URL, entities, options);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.DefaultTypeOrmModuleOptionFactory = DefaultTypeOrmModuleOptionFactory;
|
|
@@ -12,7 +12,7 @@ export declare const sanatizeTypeOrmOptions: (connectionType: SupportedConnectio
|
|
|
12
12
|
bigNumberStrings: boolean;
|
|
13
13
|
} & {
|
|
14
14
|
type: SupportedConnectionType;
|
|
15
|
-
} &
|
|
15
|
+
} & Omit<Partial<import("typeorm/data-source/BaseDataSourceOptions").BaseDataSourceOptions>, "type" | "entities">) | ({
|
|
16
16
|
entities: any[];
|
|
17
17
|
logging: boolean;
|
|
18
18
|
synchronize: boolean;
|
|
@@ -23,4 +23,4 @@ export declare const sanatizeTypeOrmOptions: (connectionType: SupportedConnectio
|
|
|
23
23
|
useUnifiedTopology: boolean;
|
|
24
24
|
} & {
|
|
25
25
|
type: SupportedConnectionType;
|
|
26
|
-
} &
|
|
26
|
+
} & Omit<Partial<import("typeorm/data-source/BaseDataSourceOptions").BaseDataSourceOptions>, "type" | "entities">);
|