@nathapp/nestjs-data 1.0.0-rc.6 → 1.0.0-rc.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 +0 -1
- package/dist/index.js +0 -1
- package/dist/typeorm/base-typeorm-options-factory.d.ts +12 -0
- package/dist/typeorm/base-typeorm-options-factory.js +34 -0
- package/dist/typeorm/constants.d.ts +16 -0
- package/dist/typeorm/constants.js +19 -0
- package/dist/typeorm/index.d.ts +5 -2
- package/dist/typeorm/index.js +9 -1
- package/dist/typeorm/typeorm-ex.module.d.ts +5 -0
- package/dist/typeorm/typeorm-ex.module.js +27 -0
- package/dist/typeorm/typeorm-utils.d.ts +26 -0
- package/dist/typeorm/typeorm-utils.js +15 -0
- package/package.json +10 -5
- package/dist/connection/connection-factory.d.ts +0 -14
- package/dist/connection/connection-factory.js +0 -61
- package/dist/connection/index.d.ts +0 -2
- package/dist/connection/index.js +0 -5
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./connection"), exports);
|
|
18
17
|
__exportStar(require("./decorator"), exports);
|
|
19
18
|
__exportStar(require("./entities"), exports);
|
|
20
19
|
__exportStar(require("./pagination"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from "@nestjs/typeorm";
|
|
2
|
+
import { EntitySchema, MixedList } from "typeorm";
|
|
3
|
+
import { BaseDataSourceOptions } from "typeorm/data-source/BaseDataSourceOptions";
|
|
4
|
+
export type OptionWithoutEntities = Omit<Partial<BaseDataSourceOptions>, "entities" | "type">;
|
|
5
|
+
export declare class BaseTypeOrmModuleOptionFactory implements TypeOrmOptionsFactory {
|
|
6
|
+
private readonly connectionString;
|
|
7
|
+
private readonly entities;
|
|
8
|
+
private readonly options?;
|
|
9
|
+
private connectionType;
|
|
10
|
+
constructor(connectionString: string, entities: MixedList<Function | string | EntitySchema>, options?: OptionWithoutEntities);
|
|
11
|
+
createTypeOrmOptions(connectionName?: string): TypeOrmModuleOptions | Promise<TypeOrmModuleOptions>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseTypeOrmModuleOptionFactory = void 0;
|
|
4
|
+
const typeorm_utils_1 = require("./typeorm-utils");
|
|
5
|
+
class BaseTypeOrmModuleOptionFactory {
|
|
6
|
+
constructor(connectionString, entities, options) {
|
|
7
|
+
this.connectionString = connectionString;
|
|
8
|
+
this.entities = entities;
|
|
9
|
+
this.options = options;
|
|
10
|
+
if (!connectionString || connectionString == "") {
|
|
11
|
+
throw new Error("connectionString is missing");
|
|
12
|
+
}
|
|
13
|
+
const isPresent = connectionString && connectionString != "";
|
|
14
|
+
this.connectionType = (isPresent ? this.connectionString.split(":").shift() : null);
|
|
15
|
+
}
|
|
16
|
+
createTypeOrmOptions(connectionName) {
|
|
17
|
+
const options = (0, typeorm_utils_1.sanatizeTypeOrmOptions)(this.connectionType, this.options);
|
|
18
|
+
switch (this.connectionType) {
|
|
19
|
+
case "mysql":
|
|
20
|
+
case "mariadb":
|
|
21
|
+
case "mongodb":
|
|
22
|
+
return {
|
|
23
|
+
name: connectionName,
|
|
24
|
+
type: this.connectionType,
|
|
25
|
+
url: this.connectionString,
|
|
26
|
+
entities: this.entities || [],
|
|
27
|
+
...options,
|
|
28
|
+
};
|
|
29
|
+
default:
|
|
30
|
+
throw new Error("Connection Not Supported");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.BaseTypeOrmModuleOptionFactory = BaseTypeOrmModuleOptionFactory;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SnakeNamingStrategy } from "typeorm-naming-strategies";
|
|
2
|
+
export declare const defaultExtraOptions: {
|
|
3
|
+
entities: any[];
|
|
4
|
+
logging: boolean;
|
|
5
|
+
synchronize: boolean;
|
|
6
|
+
autoLoadEntities: boolean;
|
|
7
|
+
namingStrategy: SnakeNamingStrategy;
|
|
8
|
+
};
|
|
9
|
+
export declare const defaultMysqlExtraOptions: {
|
|
10
|
+
supportBigNumbers: boolean;
|
|
11
|
+
bigNumberStrings: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const defaultMongoExtraOptions: {
|
|
14
|
+
useNewUrlParser: boolean;
|
|
15
|
+
useUnifiedTopology: boolean;
|
|
16
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultMongoExtraOptions = exports.defaultMysqlExtraOptions = exports.defaultExtraOptions = void 0;
|
|
4
|
+
const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
|
|
5
|
+
exports.defaultExtraOptions = {
|
|
6
|
+
entities: [],
|
|
7
|
+
logging: false,
|
|
8
|
+
synchronize: false,
|
|
9
|
+
autoLoadEntities: true,
|
|
10
|
+
namingStrategy: new typeorm_naming_strategies_1.SnakeNamingStrategy(),
|
|
11
|
+
};
|
|
12
|
+
exports.defaultMysqlExtraOptions = {
|
|
13
|
+
supportBigNumbers: true,
|
|
14
|
+
bigNumberStrings: true,
|
|
15
|
+
};
|
|
16
|
+
exports.defaultMongoExtraOptions = {
|
|
17
|
+
useNewUrlParser: true,
|
|
18
|
+
useUnifiedTopology: true,
|
|
19
|
+
};
|
package/dist/typeorm/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BaseTypeOrmModuleOptionFactory, OptionWithoutEntities } from "./base-typeorm-options-factory";
|
|
2
|
+
import { defaultExtraOptions, defaultMongoExtraOptions, defaultMysqlExtraOptions } from "./constants";
|
|
3
|
+
import { DEFAULT_DATA_SOURCE_NAME, SupportedConnectionType, TypeOrmExModule } from "./typeorm-ex.module";
|
|
4
|
+
import { sanatizeTypeOrmOptions } from "./typeorm-utils";
|
|
5
|
+
export { TypeOrmExModule, DEFAULT_DATA_SOURCE_NAME, defaultExtraOptions, defaultMysqlExtraOptions, defaultMongoExtraOptions, SupportedConnectionType, sanatizeTypeOrmOptions, BaseTypeOrmModuleOptionFactory, OptionWithoutEntities, };
|
package/dist/typeorm/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_DATA_SOURCE_NAME = exports.TypeOrmExModule = void 0;
|
|
3
|
+
exports.BaseTypeOrmModuleOptionFactory = exports.sanatizeTypeOrmOptions = exports.defaultMongoExtraOptions = exports.defaultMysqlExtraOptions = exports.defaultExtraOptions = exports.DEFAULT_DATA_SOURCE_NAME = exports.TypeOrmExModule = void 0;
|
|
4
|
+
const base_typeorm_options_factory_1 = require("./base-typeorm-options-factory");
|
|
5
|
+
Object.defineProperty(exports, "BaseTypeOrmModuleOptionFactory", { enumerable: true, get: function () { return base_typeorm_options_factory_1.BaseTypeOrmModuleOptionFactory; } });
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
Object.defineProperty(exports, "defaultExtraOptions", { enumerable: true, get: function () { return constants_1.defaultExtraOptions; } });
|
|
8
|
+
Object.defineProperty(exports, "defaultMongoExtraOptions", { enumerable: true, get: function () { return constants_1.defaultMongoExtraOptions; } });
|
|
9
|
+
Object.defineProperty(exports, "defaultMysqlExtraOptions", { enumerable: true, get: function () { return constants_1.defaultMysqlExtraOptions; } });
|
|
4
10
|
const typeorm_ex_module_1 = require("./typeorm-ex.module");
|
|
5
11
|
Object.defineProperty(exports, "DEFAULT_DATA_SOURCE_NAME", { enumerable: true, get: function () { return typeorm_ex_module_1.DEFAULT_DATA_SOURCE_NAME; } });
|
|
6
12
|
Object.defineProperty(exports, "TypeOrmExModule", { enumerable: true, get: function () { return typeorm_ex_module_1.TypeOrmExModule; } });
|
|
13
|
+
const typeorm_utils_1 = require("./typeorm-utils");
|
|
14
|
+
Object.defineProperty(exports, "sanatizeTypeOrmOptions", { enumerable: true, get: function () { return typeorm_utils_1.sanatizeTypeOrmOptions; } });
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { TypeOrmModuleAsyncOptions, TypeOrmModuleOptions } from "@nestjs/typeorm";
|
|
2
3
|
import { DataSource, DataSourceOptions } from "typeorm";
|
|
3
4
|
export declare const DEFAULT_DATA_SOURCE_NAME = "default";
|
|
5
|
+
export type SupportedConnectionType = "mysql" | "mariadb" | "mongodb";
|
|
4
6
|
export declare class TypeOrmExModule {
|
|
7
|
+
static forRoot(options?: TypeOrmModuleOptions): DynamicModule;
|
|
8
|
+
static forRootAsync(options?: TypeOrmModuleAsyncOptions): DynamicModule;
|
|
5
9
|
static forCustomRepository<T extends new (...args: any[]) => any>(repositories: T[], dataSource?: DataSource | DataSourceOptions | string): DynamicModule;
|
|
10
|
+
private static sanitizeOptions;
|
|
6
11
|
}
|
|
@@ -3,8 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TypeOrmExModule = exports.DEFAULT_DATA_SOURCE_NAME = void 0;
|
|
4
4
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
5
5
|
const decorator_1 = require("../decorator");
|
|
6
|
+
const typeorm_utils_1 = require("./typeorm-utils");
|
|
6
7
|
exports.DEFAULT_DATA_SOURCE_NAME = 'default';
|
|
7
8
|
class TypeOrmExModule {
|
|
9
|
+
static forRoot(options) {
|
|
10
|
+
options = this.sanitizeOptions(options);
|
|
11
|
+
return {
|
|
12
|
+
module: TypeOrmExModule,
|
|
13
|
+
imports: [typeorm_1.TypeOrmModule.forRoot(options)],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
static forRootAsync(options) {
|
|
17
|
+
return {
|
|
18
|
+
module: TypeOrmExModule,
|
|
19
|
+
imports: [typeorm_1.TypeOrmModule.forRootAsync(options)],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
8
22
|
static forCustomRepository(repositories, dataSource = exports.DEFAULT_DATA_SOURCE_NAME) {
|
|
9
23
|
const providers = [];
|
|
10
24
|
for (const repository of repositories) {
|
|
@@ -33,5 +47,18 @@ class TypeOrmExModule {
|
|
|
33
47
|
providers,
|
|
34
48
|
};
|
|
35
49
|
}
|
|
50
|
+
static sanitizeOptions(options) {
|
|
51
|
+
let connectionType;
|
|
52
|
+
if (options.type) {
|
|
53
|
+
connectionType = options.type;
|
|
54
|
+
}
|
|
55
|
+
else if (options["url"]) {
|
|
56
|
+
connectionType = options["url"].split(":").shift();
|
|
57
|
+
}
|
|
58
|
+
if (!connectionType) {
|
|
59
|
+
throw new Error("Connection Not Supported");
|
|
60
|
+
}
|
|
61
|
+
return (0, typeorm_utils_1.sanatizeTypeOrmOptions)(connectionType, options);
|
|
62
|
+
}
|
|
36
63
|
}
|
|
37
64
|
exports.TypeOrmExModule = TypeOrmExModule;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TypeOrmModuleOptions } from "@nestjs/typeorm";
|
|
2
|
+
import { SupportedConnectionType } from "./typeorm-ex.module";
|
|
3
|
+
import { OptionWithoutEntities } from "./base-typeorm-options-factory";
|
|
4
|
+
export declare const sanatizeTypeOrmOptions: (connectionType: SupportedConnectionType, options: TypeOrmModuleOptions | OptionWithoutEntities) => ({
|
|
5
|
+
entities: any[];
|
|
6
|
+
logging: boolean;
|
|
7
|
+
synchronize: boolean;
|
|
8
|
+
autoLoadEntities: boolean;
|
|
9
|
+
namingStrategy: import("typeorm-naming-strategies").SnakeNamingStrategy;
|
|
10
|
+
} & {
|
|
11
|
+
supportBigNumbers: boolean;
|
|
12
|
+
bigNumberStrings: boolean;
|
|
13
|
+
} & {
|
|
14
|
+
type: SupportedConnectionType;
|
|
15
|
+
} & OptionWithoutEntities) | ({
|
|
16
|
+
entities: any[];
|
|
17
|
+
logging: boolean;
|
|
18
|
+
synchronize: boolean;
|
|
19
|
+
autoLoadEntities: boolean;
|
|
20
|
+
namingStrategy: import("typeorm-naming-strategies").SnakeNamingStrategy;
|
|
21
|
+
} & {
|
|
22
|
+
useNewUrlParser: boolean;
|
|
23
|
+
useUnifiedTopology: boolean;
|
|
24
|
+
} & {
|
|
25
|
+
type: SupportedConnectionType;
|
|
26
|
+
} & OptionWithoutEntities);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanatizeTypeOrmOptions = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const sanatizeTypeOrmOptions = (connectionType, options) => {
|
|
6
|
+
const dbType = { type: connectionType };
|
|
7
|
+
switch (connectionType) {
|
|
8
|
+
case "mysql":
|
|
9
|
+
case "mariadb":
|
|
10
|
+
return Object.assign(constants_1.defaultExtraOptions, constants_1.defaultMysqlExtraOptions, dbType, options);
|
|
11
|
+
case "mongodb":
|
|
12
|
+
return Object.assign(constants_1.defaultExtraOptions, constants_1.defaultMongoExtraOptions, dbType, options);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.sanatizeTypeOrmOptions = sanatizeTypeOrmOptions;
|
package/package.json
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-data",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
4
4
|
"description": "@nathapp/nestjs-data",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
7
7
|
"precommit": "lint-staged",
|
|
8
|
-
"test": "jest",
|
|
9
|
-
"test:
|
|
10
|
-
"test:
|
|
11
|
-
"test:e2e": "jest --config ./test/jest-e2e.json",
|
|
8
|
+
"test": "jest --config ./test/jest-test.json",
|
|
9
|
+
"test:cov": "jest --config ./test/jest-test.json --coverage",
|
|
10
|
+
"test:watch": "jest --config ./test/jest-test.json --watch",
|
|
12
11
|
"lint": "eslint -c .eslintrc.js"
|
|
13
12
|
},
|
|
14
13
|
"author": "",
|
|
15
14
|
"license": "ISC",
|
|
16
15
|
"devDependencies": {
|
|
16
|
+
"@golevelup/ts-jest": "^0.3.7",
|
|
17
17
|
"@nestjs/platform-express": "^9.0.0",
|
|
18
18
|
"@nestjs/platform-fastify": "^9.0.0",
|
|
19
|
+
"@nestjs/testing": "^9.4.3",
|
|
20
|
+
"@types/jest": "^29.5.2",
|
|
19
21
|
"@types/node": "^17.0.22",
|
|
20
22
|
"@typescript-eslint/eslint-plugin": "^4",
|
|
21
23
|
"@typescript-eslint/parser": "^4",
|
|
22
24
|
"eslint": "*",
|
|
23
25
|
"eslint-config-prettier": "^6",
|
|
24
26
|
"eslint-plugin-prettier": "^3",
|
|
27
|
+
"jest": "^29.5.0",
|
|
25
28
|
"prettier": "^2",
|
|
29
|
+
"supertest": "^6.3.3",
|
|
30
|
+
"ts-jest": "^29.1.0",
|
|
26
31
|
"typescript": "^4"
|
|
27
32
|
},
|
|
28
33
|
"types": "./index.d.ts",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TypeOrmModuleOptions } from "@nestjs/typeorm";
|
|
2
|
-
export interface TypeOrmConnectionFactory {
|
|
3
|
-
createModuleOptions(): Promise<TypeOrmModuleOptions> | TypeOrmModuleOptions;
|
|
4
|
-
}
|
|
5
|
-
export declare class DefaultTypeOrmConnectionFactory implements TypeOrmConnectionFactory {
|
|
6
|
-
private connectionString;
|
|
7
|
-
private connectionName;
|
|
8
|
-
private connectionType;
|
|
9
|
-
private extraOptions;
|
|
10
|
-
constructor(connectionString: String, connectionName?: String, extraOptions?: any);
|
|
11
|
-
private createExtraOptions;
|
|
12
|
-
createModuleOptions(): TypeOrmModuleOptions | Promise<TypeOrmModuleOptions>;
|
|
13
|
-
static createModuleOptions(connectionString: String, connectionName?: String, extraOptions?: any): TypeOrmModuleOptions | Promise<TypeOrmModuleOptions>;
|
|
14
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultTypeOrmConnectionFactory = void 0;
|
|
4
|
-
const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
|
|
5
|
-
const defaultExtraOptions = {
|
|
6
|
-
entities: [],
|
|
7
|
-
logging: false,
|
|
8
|
-
synchronize: false,
|
|
9
|
-
autoLoadEntities: true,
|
|
10
|
-
namingStrategy: new typeorm_naming_strategies_1.SnakeNamingStrategy(),
|
|
11
|
-
};
|
|
12
|
-
const defaultMysqlExtraOptions = {
|
|
13
|
-
supportBigNumbers: true,
|
|
14
|
-
bigNumberStrings: true,
|
|
15
|
-
};
|
|
16
|
-
const defaultMongoExtraOptions = {
|
|
17
|
-
useNewUrlParser: true,
|
|
18
|
-
useUnifiedTopology: true,
|
|
19
|
-
};
|
|
20
|
-
class DefaultTypeOrmConnectionFactory {
|
|
21
|
-
constructor(connectionString, connectionName, extraOptions) {
|
|
22
|
-
this.connectionString = connectionString;
|
|
23
|
-
if (!connectionString || connectionString == "") {
|
|
24
|
-
throw new Error("connectionString is missing");
|
|
25
|
-
}
|
|
26
|
-
this.connectionName = connectionName || "default";
|
|
27
|
-
const isPresent = connectionString && connectionString != "";
|
|
28
|
-
this.connectionType = (isPresent ? this.connectionString.split(":").shift() : null);
|
|
29
|
-
this.extraOptions = extraOptions || {};
|
|
30
|
-
}
|
|
31
|
-
createExtraOptions() {
|
|
32
|
-
switch (this.connectionType) {
|
|
33
|
-
case "mysql":
|
|
34
|
-
case "mariadb":
|
|
35
|
-
return Object.assign(defaultExtraOptions, defaultMysqlExtraOptions, this.extraOptions);
|
|
36
|
-
case "mongodb":
|
|
37
|
-
return Object.assign(defaultExtraOptions, defaultMongoExtraOptions, this.extraOptions);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
createModuleOptions() {
|
|
41
|
-
const options = this.createExtraOptions();
|
|
42
|
-
switch (this.connectionType) {
|
|
43
|
-
case "mysql":
|
|
44
|
-
case "mariadb":
|
|
45
|
-
case "mongodb":
|
|
46
|
-
return {
|
|
47
|
-
...options,
|
|
48
|
-
type: this.connectionType,
|
|
49
|
-
name: this.connectionName,
|
|
50
|
-
url: this.connectionString,
|
|
51
|
-
};
|
|
52
|
-
default:
|
|
53
|
-
throw new Error("Connection Not Supported");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
static createModuleOptions(connectionString, connectionName, extraOptions) {
|
|
57
|
-
const factory = new DefaultTypeOrmConnectionFactory(connectionString, connectionName, extraOptions);
|
|
58
|
-
return factory.createModuleOptions();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.DefaultTypeOrmConnectionFactory = DefaultTypeOrmConnectionFactory;
|
package/dist/connection/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultTypeOrmConnectionFactory = void 0;
|
|
4
|
-
const connection_factory_1 = require("./connection-factory");
|
|
5
|
-
Object.defineProperty(exports, "DefaultTypeOrmConnectionFactory", { enumerable: true, get: function () { return connection_factory_1.DefaultTypeOrmConnectionFactory; } });
|