nest-knexjs 0.0.7 → 0.0.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/common/index.d.ts +2 -0
- package/dist/common/index.js +14 -0
- package/dist/common/knex.decorators.d.ts +3 -0
- package/dist/common/knex.decorators.js +11 -0
- package/dist/common/knex.utils.d.ts +20 -0
- package/dist/common/knex.utils.js +62 -0
- package/dist/entities-metadata.storage.d.ts +8 -0
- package/dist/entities-metadata.storage.js +31 -0
- package/dist/exceptions/circular-dependency.exception.d.ts +3 -0
- package/dist/exceptions/circular-dependency.exception.js +10 -0
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +15 -0
- package/dist/interfaces/knex-module-async-options.interface.d.ts +10 -0
- package/dist/interfaces/knex-module-async-options.interface.js +2 -0
- package/dist/interfaces/knex-options-factory.interface.d.ts +4 -0
- package/dist/interfaces/knex-options-factory.interface.js +2 -0
- package/dist/interfaces/knex-options.interface.d.ts +7 -0
- package/dist/interfaces/knex-options.interface.js +2 -0
- package/dist/knex-core.module.d.ts +14 -0
- package/dist/knex-core.module.js +107 -0
- package/dist/knex.constants.d.ts +3 -0
- package/dist/knex.constants.js +6 -0
- package/dist/knex.module.d.ts +6 -0
- package/dist/knex.module.js +30 -0
- package/package.json +13 -13
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./knex.decorators"), exports);
|
|
14
|
+
__exportStar(require("./knex.utils"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { KnexModuleOptions } from '../interfaces/knex-options.interface';
|
|
2
|
+
export declare const InjectModel: (connection?: string) => (target: object, key: string | symbol, index?: number) => void;
|
|
3
|
+
export declare const InjectConnection: (connection?: KnexModuleOptions | string) => ParameterDecorator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectConnection = exports.InjectModel = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const knex_utils_1 = require("./knex.utils");
|
|
6
|
+
const InjectModel = (connection) => {
|
|
7
|
+
return (0, common_1.Inject)((0, knex_utils_1.getConnectionToken)(connection));
|
|
8
|
+
};
|
|
9
|
+
exports.InjectModel = InjectModel;
|
|
10
|
+
const InjectConnection = (connection) => (0, common_1.Inject)((0, knex_utils_1.getConnectionToken)(connection));
|
|
11
|
+
exports.InjectConnection = InjectConnection;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KnexModuleOptions } from '../interfaces';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* This function generates an injection token for an Model
|
|
5
|
+
* @param {Function} This parameter can either be a Model
|
|
6
|
+
* @param {string} [connection='default'] Connection name
|
|
7
|
+
* @returns {string} The Entity injection token
|
|
8
|
+
*/
|
|
9
|
+
export declare function getModelToken(model: Function, connection?: KnexModuleOptions | string): string;
|
|
10
|
+
export declare function getConnectionToken(connection?: KnexModuleOptions | any): string | Function;
|
|
11
|
+
/**
|
|
12
|
+
* This function returns a Connection prefix based on the connection name
|
|
13
|
+
* @param {KnexModuleOptions | string} [connection='default'] This optional parameter is either
|
|
14
|
+
* a KnexModuleOptions or a string.
|
|
15
|
+
* @returns {string | Function} The Connection injection token.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getConnectionPrefix(connection?: KnexModuleOptions | string): string;
|
|
18
|
+
export declare function handleRetry(retryAttempts?: number, retryDelay?: number): <T>(source: Observable<T>) => Observable<T>;
|
|
19
|
+
export declare function getConnectionName(options: KnexModuleOptions): string;
|
|
20
|
+
export declare const generateString: () => any;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateString = exports.getConnectionName = exports.handleRetry = exports.getConnectionPrefix = exports.getConnectionToken = exports.getModelToken = void 0;
|
|
4
|
+
const knex_constants_1 = require("../knex.constants");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const circular_dependency_exception_1 = require("../exceptions/circular-dependency.exception");
|
|
9
|
+
const logger = new common_1.Logger('KnexModule');
|
|
10
|
+
/**
|
|
11
|
+
* This function generates an injection token for an Model
|
|
12
|
+
* @param {Function} This parameter can either be a Model
|
|
13
|
+
* @param {string} [connection='default'] Connection name
|
|
14
|
+
* @returns {string} The Entity injection token
|
|
15
|
+
*/
|
|
16
|
+
function getModelToken(model, connection = knex_constants_1.DEFAULT_CONNECTION_NAME) {
|
|
17
|
+
if (model === null || model === undefined) {
|
|
18
|
+
throw new circular_dependency_exception_1.CircularDependencyException('@InjectModel()');
|
|
19
|
+
}
|
|
20
|
+
const connectionPrefix = getConnectionPrefix(connection);
|
|
21
|
+
return `${connectionPrefix}${model.name}`;
|
|
22
|
+
}
|
|
23
|
+
exports.getModelToken = getModelToken;
|
|
24
|
+
function getConnectionToken(connection = knex_constants_1.DEFAULT_CONNECTION_NAME) {
|
|
25
|
+
return `${connection.name || knex_constants_1.DEFAULT_CONNECTION_NAME}`;
|
|
26
|
+
}
|
|
27
|
+
exports.getConnectionToken = getConnectionToken;
|
|
28
|
+
/**
|
|
29
|
+
* This function returns a Connection prefix based on the connection name
|
|
30
|
+
* @param {KnexModuleOptions | string} [connection='default'] This optional parameter is either
|
|
31
|
+
* a KnexModuleOptions or a string.
|
|
32
|
+
* @returns {string | Function} The Connection injection token.
|
|
33
|
+
*/
|
|
34
|
+
function getConnectionPrefix(connection = knex_constants_1.DEFAULT_CONNECTION_NAME) {
|
|
35
|
+
if (connection === knex_constants_1.DEFAULT_CONNECTION_NAME) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
if (typeof connection === 'string') {
|
|
39
|
+
return connection + '_';
|
|
40
|
+
}
|
|
41
|
+
if (connection.name === knex_constants_1.DEFAULT_CONNECTION_NAME || !connection.name) {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
return connection.name + '_';
|
|
45
|
+
}
|
|
46
|
+
exports.getConnectionPrefix = getConnectionPrefix;
|
|
47
|
+
function handleRetry(retryAttempts = 9, retryDelay = 3000) {
|
|
48
|
+
return (source) => source.pipe((0, operators_1.retryWhen)((e) => e.pipe((0, operators_1.scan)((errorCount, error) => {
|
|
49
|
+
logger.error(`Unable to connect to the database. Retrying (${errorCount + 1})...`, error.stack);
|
|
50
|
+
if (errorCount + 1 >= retryAttempts) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
return errorCount + 1;
|
|
54
|
+
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
55
|
+
}
|
|
56
|
+
exports.handleRetry = handleRetry;
|
|
57
|
+
function getConnectionName(options) {
|
|
58
|
+
return options && options.name ? options.name : knex_constants_1.DEFAULT_CONNECTION_NAME;
|
|
59
|
+
}
|
|
60
|
+
exports.getConnectionName = getConnectionName;
|
|
61
|
+
const generateString = () => (0, uuid_1.v4)();
|
|
62
|
+
exports.generateString = generateString;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KnexModuleOptions } from './interfaces';
|
|
2
|
+
declare type ConnectionToken = KnexModuleOptions | string;
|
|
3
|
+
export declare class EntitiesMetadataStorage {
|
|
4
|
+
private static readonly storage;
|
|
5
|
+
static addEntitiesByConnection(connection: ConnectionToken, entities: Function[]): void;
|
|
6
|
+
static getEntitiesByConnection(connection: ConnectionToken): Function[];
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntitiesMetadataStorage = void 0;
|
|
4
|
+
class EntitiesMetadataStorage {
|
|
5
|
+
static addEntitiesByConnection(connection, entities) {
|
|
6
|
+
const connectionToken = typeof connection === 'string' ? connection : connection.name;
|
|
7
|
+
if (!connectionToken) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let collection = this.storage.get(connectionToken);
|
|
11
|
+
if (!collection) {
|
|
12
|
+
collection = [];
|
|
13
|
+
this.storage.set(connectionToken, collection);
|
|
14
|
+
}
|
|
15
|
+
entities.forEach(entity => {
|
|
16
|
+
if (collection.includes(entity)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
collection.push(entity);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
static getEntitiesByConnection(connection) {
|
|
23
|
+
const connectionToken = typeof connection === 'string' ? connection : connection.name;
|
|
24
|
+
if (!connectionToken) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
return this.storage.get(connectionToken) || [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.EntitiesMetadataStorage = EntitiesMetadataStorage;
|
|
31
|
+
EntitiesMetadataStorage.storage = new Map();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CircularDependencyException = void 0;
|
|
4
|
+
class CircularDependencyException extends Error {
|
|
5
|
+
constructor(context) {
|
|
6
|
+
const ctx = context ? ` inside ${context}` : ``;
|
|
7
|
+
super(`A circular dependency has been detected${ctx}. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()". Also, try to eliminate barrel files because they can lead to an unexpected behavior too.`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CircularDependencyException = CircularDependencyException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './circular-dependency.exception';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./circular-dependency.exception"), exports);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./common"), exports);
|
|
14
|
+
__exportStar(require("./interfaces"), exports);
|
|
15
|
+
__exportStar(require("./knex.module"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./knex-options.interface"), exports);
|
|
14
|
+
__exportStar(require("./knex-options-factory.interface"), exports);
|
|
15
|
+
__exportStar(require("./knex-module-async-options.interface"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from "@nestjs/common/interfaces";
|
|
2
|
+
import { KnexModuleOptions } from './knex-options.interface';
|
|
3
|
+
import { KnexOptionsFactory } from './knex-options-factory.interface';
|
|
4
|
+
export interface KnexModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
5
|
+
name?: string;
|
|
6
|
+
inject?: any[];
|
|
7
|
+
useClass?: Type<KnexOptionsFactory>;
|
|
8
|
+
useExisting?: Type<KnexOptionsFactory>;
|
|
9
|
+
useFactory?: (...args: any[]) => Promise<KnexModuleOptions> | KnexModuleOptions;
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DynamicModule, Provider, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { KnexModuleAsyncOptions, KnexModuleOptions } from './interfaces';
|
|
3
|
+
import { ModuleRef } from '@nestjs/core';
|
|
4
|
+
export declare class KnexCoreModule implements OnApplicationShutdown {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly moduleRef;
|
|
7
|
+
constructor(options: KnexModuleOptions, moduleRef: ModuleRef);
|
|
8
|
+
static forRoot(options: KnexModuleOptions, connection?: string): DynamicModule;
|
|
9
|
+
static forRootAsync(options: KnexModuleAsyncOptions, connection: string): DynamicModule;
|
|
10
|
+
onApplicationShutdown(): Promise<any>;
|
|
11
|
+
static createAsyncProviders(options: KnexModuleAsyncOptions): Provider[];
|
|
12
|
+
static createAsyncOptionsProvider(options: KnexModuleAsyncOptions): Provider;
|
|
13
|
+
private static createConnectionFactory;
|
|
14
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var KnexCoreModule_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.KnexCoreModule = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const knex_utils_1 = require("./common/knex.utils");
|
|
19
|
+
const knex_constants_1 = require("./knex.constants");
|
|
20
|
+
const knex_1 = require("knex");
|
|
21
|
+
const core_1 = require("@nestjs/core");
|
|
22
|
+
const rxjs_1 = require("rxjs");
|
|
23
|
+
let KnexCoreModule = KnexCoreModule_1 = class KnexCoreModule {
|
|
24
|
+
constructor(options, moduleRef) {
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.moduleRef = moduleRef;
|
|
27
|
+
}
|
|
28
|
+
static forRoot(options, connection) {
|
|
29
|
+
const knexModuleOptions = {
|
|
30
|
+
provide: knex_constants_1.KNEX_MODULE_OPTIONS,
|
|
31
|
+
useValue: options,
|
|
32
|
+
};
|
|
33
|
+
const connectionProvider = {
|
|
34
|
+
provide: (0, knex_utils_1.getConnectionToken)(connection),
|
|
35
|
+
useFactory: async () => await this.createConnectionFactory(options),
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
module: KnexCoreModule_1,
|
|
39
|
+
providers: [connectionProvider, knexModuleOptions],
|
|
40
|
+
exports: [connectionProvider],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
static forRootAsync(options, connection) {
|
|
44
|
+
const connectionProvider = {
|
|
45
|
+
provide: (0, knex_utils_1.getConnectionToken)(connection),
|
|
46
|
+
useFactory: async (options) => {
|
|
47
|
+
return await this.createConnectionFactory(options);
|
|
48
|
+
},
|
|
49
|
+
inject: [knex_constants_1.KNEX_MODULE_OPTIONS],
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
module: KnexCoreModule_1,
|
|
53
|
+
imports: options.imports,
|
|
54
|
+
providers: [...this.createAsyncProviders(options), connectionProvider],
|
|
55
|
+
exports: [connectionProvider],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async onApplicationShutdown() {
|
|
59
|
+
const connection = this.moduleRef.get((0, knex_utils_1.getConnectionToken)(this.options));
|
|
60
|
+
connection && (await connection.destroy());
|
|
61
|
+
}
|
|
62
|
+
static createAsyncProviders(options) {
|
|
63
|
+
if (options.useExisting || options.useFactory) {
|
|
64
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
65
|
+
}
|
|
66
|
+
const useClass = options.useClass;
|
|
67
|
+
return [
|
|
68
|
+
this.createAsyncOptionsProvider(options),
|
|
69
|
+
{
|
|
70
|
+
provide: useClass,
|
|
71
|
+
useClass,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
static createAsyncOptionsProvider(options) {
|
|
76
|
+
if (options.useFactory) {
|
|
77
|
+
return {
|
|
78
|
+
provide: knex_constants_1.KNEX_MODULE_OPTIONS,
|
|
79
|
+
useFactory: options.useFactory,
|
|
80
|
+
inject: options.inject || [],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// `as Type<KnexOptionsFactory>` is a workaround for microsoft/TypeScript#31603
|
|
84
|
+
const inject = [
|
|
85
|
+
(options.useClass || options.useExisting),
|
|
86
|
+
];
|
|
87
|
+
return {
|
|
88
|
+
provide: knex_constants_1.KNEX_MODULE_OPTIONS,
|
|
89
|
+
useFactory: async (optionsFactory) => {
|
|
90
|
+
return await optionsFactory.createKnexOptions();
|
|
91
|
+
},
|
|
92
|
+
inject
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
static async createConnectionFactory(options) {
|
|
96
|
+
return (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(async () => {
|
|
97
|
+
return (0, knex_1.knex)(options.config);
|
|
98
|
+
}).pipe((0, knex_utils_1.handleRetry)(options.retryAttempts, options.retryDelay)));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
KnexCoreModule = KnexCoreModule_1 = __decorate([
|
|
102
|
+
(0, common_1.Global)(),
|
|
103
|
+
(0, common_1.Module)({}),
|
|
104
|
+
__param(0, (0, common_1.Inject)(knex_constants_1.KNEX_MODULE_OPTIONS)),
|
|
105
|
+
__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
106
|
+
], KnexCoreModule);
|
|
107
|
+
exports.KnexCoreModule = KnexCoreModule;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONNECTION_NAME = exports.KNEX_MODULE_ID = exports.KNEX_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.KNEX_MODULE_OPTIONS = 'KnexModuleOptions';
|
|
5
|
+
exports.KNEX_MODULE_ID = 'KnexModuleId';
|
|
6
|
+
exports.DEFAULT_CONNECTION_NAME = 'default';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { KnexModuleAsyncOptions, KnexModuleOptions } from './interfaces';
|
|
3
|
+
export declare class KnexModule {
|
|
4
|
+
static forRoot(options: KnexModuleOptions, connection?: string): DynamicModule;
|
|
5
|
+
static forRootAsync(options: KnexModuleAsyncOptions, connection?: string): DynamicModule;
|
|
6
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var KnexModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.KnexModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const knex_core_module_1 = require("./knex-core.module");
|
|
13
|
+
let KnexModule = KnexModule_1 = class KnexModule {
|
|
14
|
+
static forRoot(options, connection) {
|
|
15
|
+
return {
|
|
16
|
+
module: KnexModule_1,
|
|
17
|
+
imports: [knex_core_module_1.KnexCoreModule.forRoot(options, connection)],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
static forRootAsync(options, connection) {
|
|
21
|
+
return {
|
|
22
|
+
module: KnexModule_1,
|
|
23
|
+
imports: [knex_core_module_1.KnexCoreModule.forRootAsync(options, connection)],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
KnexModule = KnexModule_1 = __decorate([
|
|
28
|
+
(0, common_1.Module)({})
|
|
29
|
+
], KnexModule);
|
|
30
|
+
exports.KnexModule = KnexModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-knexjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Knexjs module for Nest framework (node.js) 😻",
|
|
5
5
|
"author": "Tony133",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
"release": "release-it"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@commitlint/cli": "16.0
|
|
21
|
+
"@commitlint/cli": "16.1.0",
|
|
22
22
|
"@commitlint/config-angular": "16.0.0",
|
|
23
|
-
"@nestjs/common": "8.2.
|
|
24
|
-
"@nestjs/core": "8.2.
|
|
25
|
-
"@nestjs/platform-express": "8.2.
|
|
26
|
-
"@nestjs/testing": "8.2.
|
|
23
|
+
"@nestjs/common": "8.2.6",
|
|
24
|
+
"@nestjs/core": "8.2.6",
|
|
25
|
+
"@nestjs/platform-express": "8.2.6",
|
|
26
|
+
"@nestjs/testing": "8.2.6",
|
|
27
27
|
"@types/express": "4.17.13",
|
|
28
|
-
"@types/node": "16.11.
|
|
28
|
+
"@types/node": "16.11.21",
|
|
29
29
|
"@types/jest": "27.4.0",
|
|
30
30
|
"@types/supertest": "2.0.11",
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
32
|
-
"@typescript-eslint/parser": "5.
|
|
33
|
-
"eslint": "8.
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "5.10.1",
|
|
32
|
+
"@typescript-eslint/parser": "5.10.1",
|
|
33
|
+
"eslint": "8.8.0",
|
|
34
34
|
"eslint-config-prettier": "8.3.0",
|
|
35
35
|
"eslint-plugin-import": "2.25.4",
|
|
36
36
|
"knex": "1.0.1",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"prettier": "2.5.1",
|
|
40
40
|
"jest": "27.4.7",
|
|
41
41
|
"reflect-metadata": "0.1.13",
|
|
42
|
-
"release-it": "14.12.
|
|
43
|
-
"supertest": "6.2.
|
|
42
|
+
"release-it": "14.12.4",
|
|
43
|
+
"supertest": "6.2.2",
|
|
44
44
|
"ts-node": "10.4.0",
|
|
45
45
|
"rxjs": "7.5.2",
|
|
46
46
|
"ts-jest": "27.1.3",
|
|
47
47
|
"tsconfig-paths": "3.12.0",
|
|
48
|
-
"typescript": "4.5.
|
|
48
|
+
"typescript": "4.5.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@nestjs/common": "^7.0.0 || ^8.0.0",
|