@onivoro/server-typeorm-mysql 0.1.32
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/cjs/index.d.ts +19 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/lib/classes/type-orm-paging-repository.class.d.ts +14 -0
- package/dist/cjs/lib/classes/type-orm-paging-repository.class.js +16 -0
- package/dist/cjs/lib/classes/type-orm-repository.class.d.ts +21 -0
- package/dist/cjs/lib/classes/type-orm-repository.class.js +62 -0
- package/dist/cjs/lib/constants/many-to-one-relation-options.constant.d.ts +2 -0
- package/dist/cjs/lib/constants/many-to-one-relation-options.constant.js +4 -0
- package/dist/cjs/lib/decorators/nullable-table-column.decorator.d.ts +2 -0
- package/dist/cjs/lib/decorators/nullable-table-column.decorator.js +12 -0
- package/dist/cjs/lib/decorators/primary-table-column.decorator.d.ts +2 -0
- package/dist/cjs/lib/decorators/primary-table-column.decorator.js +12 -0
- package/dist/cjs/lib/decorators/table-column.decorator.d.ts +2 -0
- package/dist/cjs/lib/decorators/table-column.decorator.js +12 -0
- package/dist/cjs/lib/decorators/table.decorator.d.ts +3 -0
- package/dist/cjs/lib/decorators/table.decorator.js +11 -0
- package/dist/cjs/lib/functions/data-source-config-factory.function.d.ts +3 -0
- package/dist/cjs/lib/functions/data-source-config-factory.function.js +25 -0
- package/dist/cjs/lib/functions/data-source-factory.function.d.ts +3 -0
- package/dist/cjs/lib/functions/data-source-factory.function.js +7 -0
- package/dist/cjs/lib/functions/generate-date-query.function.d.ts +2 -0
- package/dist/cjs/lib/functions/generate-date-query.function.js +17 -0
- package/dist/cjs/lib/functions/get-api-type-from-column.function.d.ts +2 -0
- package/dist/cjs/lib/functions/get-api-type-from-column.function.js +15 -0
- package/dist/cjs/lib/functions/get-paging-key.function.d.ts +1 -0
- package/dist/cjs/lib/functions/get-paging-key.function.js +7 -0
- package/dist/cjs/lib/functions/get-skip.function.d.ts +1 -0
- package/dist/cjs/lib/functions/get-skip.function.js +7 -0
- package/dist/cjs/lib/functions/remove-falsey-keys.function.d.ts +1 -0
- package/dist/cjs/lib/functions/remove-falsey-keys.function.js +12 -0
- package/dist/cjs/lib/server-typeorm-mysql.module.d.ts +5 -0
- package/dist/cjs/lib/server-typeorm-mysql.module.js +49 -0
- package/dist/cjs/lib/types/data-source-options.interface.d.ts +10 -0
- package/dist/cjs/lib/types/data-source-options.interface.js +2 -0
- package/dist/cjs/lib/types/entity-provider.interface.d.ts +9 -0
- package/dist/cjs/lib/types/entity-provider.interface.js +2 -0
- package/dist/cjs/lib/types/page-params.interface.d.ts +4 -0
- package/dist/cjs/lib/types/page-params.interface.js +2 -0
- package/dist/cjs/lib/types/paged-data.interface.d.ts +6 -0
- package/dist/cjs/lib/types/paged-data.interface.js +2 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +35 -0
- package/dist/esm/lib/classes/type-orm-paging-repository.class.d.ts +14 -0
- package/dist/esm/lib/classes/type-orm-paging-repository.class.js +16 -0
- package/dist/esm/lib/classes/type-orm-repository.class.d.ts +21 -0
- package/dist/esm/lib/classes/type-orm-repository.class.js +62 -0
- package/dist/esm/lib/constants/many-to-one-relation-options.constant.d.ts +2 -0
- package/dist/esm/lib/constants/many-to-one-relation-options.constant.js +4 -0
- package/dist/esm/lib/decorators/nullable-table-column.decorator.d.ts +2 -0
- package/dist/esm/lib/decorators/nullable-table-column.decorator.js +12 -0
- package/dist/esm/lib/decorators/primary-table-column.decorator.d.ts +2 -0
- package/dist/esm/lib/decorators/primary-table-column.decorator.js +12 -0
- package/dist/esm/lib/decorators/table-column.decorator.d.ts +2 -0
- package/dist/esm/lib/decorators/table-column.decorator.js +12 -0
- package/dist/esm/lib/decorators/table.decorator.d.ts +3 -0
- package/dist/esm/lib/decorators/table.decorator.js +11 -0
- package/dist/esm/lib/functions/data-source-config-factory.function.d.ts +3 -0
- package/dist/esm/lib/functions/data-source-config-factory.function.js +25 -0
- package/dist/esm/lib/functions/data-source-factory.function.d.ts +3 -0
- package/dist/esm/lib/functions/data-source-factory.function.js +7 -0
- package/dist/esm/lib/functions/generate-date-query.function.d.ts +2 -0
- package/dist/esm/lib/functions/generate-date-query.function.js +17 -0
- package/dist/esm/lib/functions/get-api-type-from-column.function.d.ts +2 -0
- package/dist/esm/lib/functions/get-api-type-from-column.function.js +15 -0
- package/dist/esm/lib/functions/get-paging-key.function.d.ts +1 -0
- package/dist/esm/lib/functions/get-paging-key.function.js +7 -0
- package/dist/esm/lib/functions/get-skip.function.d.ts +1 -0
- package/dist/esm/lib/functions/get-skip.function.js +7 -0
- package/dist/esm/lib/functions/remove-falsey-keys.function.d.ts +1 -0
- package/dist/esm/lib/functions/remove-falsey-keys.function.js +12 -0
- package/dist/esm/lib/server-typeorm-mysql.module.d.ts +5 -0
- package/dist/esm/lib/server-typeorm-mysql.module.js +49 -0
- package/dist/esm/lib/types/data-source-options.interface.d.ts +10 -0
- package/dist/esm/lib/types/data-source-options.interface.js +2 -0
- package/dist/esm/lib/types/entity-provider.interface.d.ts +9 -0
- package/dist/esm/lib/types/entity-provider.interface.js +2 -0
- package/dist/esm/lib/types/page-params.interface.d.ts +4 -0
- package/dist/esm/lib/types/page-params.interface.js +2 -0
- package/dist/esm/lib/types/paged-data.interface.d.ts +6 -0
- package/dist/esm/lib/types/paged-data.interface.js +2 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/lib/classes/type-orm-paging-repository.class.d.ts +14 -0
- package/dist/types/lib/classes/type-orm-repository.class.d.ts +21 -0
- package/dist/types/lib/constants/many-to-one-relation-options.constant.d.ts +2 -0
- package/dist/types/lib/decorators/nullable-table-column.decorator.d.ts +2 -0
- package/dist/types/lib/decorators/primary-table-column.decorator.d.ts +2 -0
- package/dist/types/lib/decorators/table-column.decorator.d.ts +2 -0
- package/dist/types/lib/decorators/table.decorator.d.ts +3 -0
- package/dist/types/lib/functions/data-source-config-factory.function.d.ts +3 -0
- package/dist/types/lib/functions/data-source-factory.function.d.ts +3 -0
- package/dist/types/lib/functions/generate-date-query.function.d.ts +2 -0
- package/dist/types/lib/functions/get-api-type-from-column.function.d.ts +2 -0
- package/dist/types/lib/functions/get-paging-key.function.d.ts +1 -0
- package/dist/types/lib/functions/get-skip.function.d.ts +1 -0
- package/dist/types/lib/functions/remove-falsey-keys.function.d.ts +1 -0
- package/dist/types/lib/server-typeorm-mysql.module.d.ts +5 -0
- package/dist/types/lib/types/data-source-options.interface.d.ts +10 -0
- package/dist/types/lib/types/entity-provider.interface.d.ts +9 -0
- package/dist/types/lib/types/page-params.interface.d.ts +4 -0
- package/dist/types/lib/types/paged-data.interface.d.ts +6 -0
- package/package.json +49 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOrmRepository = void 0;
|
|
4
|
+
class TypeOrmRepository {
|
|
5
|
+
entityType;
|
|
6
|
+
entityManager;
|
|
7
|
+
constructor(entityType, entityManager) {
|
|
8
|
+
this.entityType = entityType;
|
|
9
|
+
this.entityManager = entityManager;
|
|
10
|
+
}
|
|
11
|
+
forTransaction(entityManager) {
|
|
12
|
+
return { ...this, entityManager };
|
|
13
|
+
}
|
|
14
|
+
async getMany(options) {
|
|
15
|
+
return await this.repo.find(options);
|
|
16
|
+
}
|
|
17
|
+
async getManyAndCount(options) {
|
|
18
|
+
return await this.repo.findAndCount(options);
|
|
19
|
+
}
|
|
20
|
+
async getOne(options) {
|
|
21
|
+
const results = await this.getMany(options);
|
|
22
|
+
if (results?.length > 1) {
|
|
23
|
+
throw new Error(`${TypeOrmRepository.prototype.getOne.name} expects only 1 result but found ${results.length} results of entity type "${this.entityType}" for criteria ${JSON.stringify(options, null, 2)}`);
|
|
24
|
+
}
|
|
25
|
+
return results[0];
|
|
26
|
+
}
|
|
27
|
+
async postOne(body) {
|
|
28
|
+
return await this.insertAndReturn(body);
|
|
29
|
+
}
|
|
30
|
+
async postMany(body) {
|
|
31
|
+
return await this.insertAndReturnMany(body);
|
|
32
|
+
}
|
|
33
|
+
async delete(options) {
|
|
34
|
+
return await this.repo.delete(options);
|
|
35
|
+
}
|
|
36
|
+
async softDelete(options) {
|
|
37
|
+
return await this.repo.softDelete(options);
|
|
38
|
+
}
|
|
39
|
+
async put(options, body) {
|
|
40
|
+
await this.repo.save(options, body);
|
|
41
|
+
}
|
|
42
|
+
async patch(options, body) {
|
|
43
|
+
await this.repo.update(options, body);
|
|
44
|
+
}
|
|
45
|
+
get repo() {
|
|
46
|
+
return this.entityManager.getRepository(this.entityType);
|
|
47
|
+
}
|
|
48
|
+
async insertAndReturn(entityToInsert) {
|
|
49
|
+
return (await this.insertAndReturnMany([entityToInsert]))[0];
|
|
50
|
+
}
|
|
51
|
+
async insertAndReturnMany(entitiesToInsert) {
|
|
52
|
+
const insertionResult = await this.repo
|
|
53
|
+
.createQueryBuilder()
|
|
54
|
+
.insert()
|
|
55
|
+
.values(entitiesToInsert)
|
|
56
|
+
.returning('*')
|
|
57
|
+
.execute();
|
|
58
|
+
const insertedEntity = insertionResult.generatedMaps;
|
|
59
|
+
return insertedEntity;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.TypeOrmRepository = TypeOrmRepository;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullableTableColumn = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
const get_api_type_from_column_function_1 = require("../functions/get-api-type-from-column.function");
|
|
8
|
+
const NullableTableColumn = (options) => {
|
|
9
|
+
const apiType = (0, get_api_type_from_column_function_1.getApiTypeFromColumn)(options?.type);
|
|
10
|
+
return (0, common_1.applyDecorators)((0, typeorm_1.Column)({ type: options?.type, nullable: true }), (0, swagger_1.ApiPropertyOptional)({ type: apiType }));
|
|
11
|
+
};
|
|
12
|
+
exports.NullableTableColumn = NullableTableColumn;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrimaryTableColumn = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
const get_api_type_from_column_function_1 = require("../functions/get-api-type-from-column.function");
|
|
8
|
+
const PrimaryTableColumn = (options) => {
|
|
9
|
+
const apiType = (0, get_api_type_from_column_function_1.getApiTypeFromColumn)(options?.type);
|
|
10
|
+
return (0, common_1.applyDecorators)((0, typeorm_1.Column)({ type: options?.type, nullable: false }), (0, swagger_1.ApiProperty)({ type: apiType }));
|
|
11
|
+
};
|
|
12
|
+
exports.PrimaryTableColumn = PrimaryTableColumn;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableColumn = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
const get_api_type_from_column_function_1 = require("../functions/get-api-type-from-column.function");
|
|
8
|
+
const TableColumn = (options) => {
|
|
9
|
+
const apiType = (0, get_api_type_from_column_function_1.getApiTypeFromColumn)(options?.type);
|
|
10
|
+
return (0, common_1.applyDecorators)((0, typeorm_1.Column)({ type: options?.type, nullable: false }), (0, swagger_1.ApiProperty)({ type: apiType }));
|
|
11
|
+
};
|
|
12
|
+
exports.TableColumn = TableColumn;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const isomorphic_common_1 = require("@onivoro/isomorphic-common");
|
|
7
|
+
const Table = (EntityClass) => {
|
|
8
|
+
const tableName = (0, isomorphic_common_1.snakeCase)(EntityClass.name);
|
|
9
|
+
return (0, common_1.applyDecorators)((0, typeorm_1.Entity)(tableName));
|
|
10
|
+
};
|
|
11
|
+
exports.Table = Table;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions';
|
|
2
|
+
import { IDataSourceOptions } from '../types/data-source-options.interface';
|
|
3
|
+
export declare function dataSourceConfigFactory(name: string, options: IDataSourceOptions, entities: any[]): MysqlConnectionOptions;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dataSourceConfigFactory = void 0;
|
|
4
|
+
const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
|
|
5
|
+
function dataSourceConfigFactory(name, options, entities) {
|
|
6
|
+
const { ca, database, host, password, port, username, synchronize = false, logging = false } = options;
|
|
7
|
+
const config = {
|
|
8
|
+
name,
|
|
9
|
+
type: 'mysql',
|
|
10
|
+
host,
|
|
11
|
+
port: port,
|
|
12
|
+
username,
|
|
13
|
+
password,
|
|
14
|
+
ssl: ca ? { ca } : undefined,
|
|
15
|
+
database,
|
|
16
|
+
synchronize,
|
|
17
|
+
logging,
|
|
18
|
+
entities,
|
|
19
|
+
subscribers: [],
|
|
20
|
+
migrations: [],
|
|
21
|
+
namingStrategy: new typeorm_naming_strategies_1.SnakeNamingStrategy(),
|
|
22
|
+
};
|
|
23
|
+
return config;
|
|
24
|
+
}
|
|
25
|
+
exports.dataSourceConfigFactory = dataSourceConfigFactory;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dataSourceFactory = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const data_source_config_factory_function_1 = require("./data-source-config-factory.function");
|
|
6
|
+
const dataSourceFactory = (name, options, entities) => new typeorm_1.DataSource((0, data_source_config_factory_function_1.dataSourceConfigFactory)(name, options, entities));
|
|
7
|
+
exports.dataSourceFactory = dataSourceFactory;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateDateQuery = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
function generateDateQuery(minDueDate, maxDueDate) {
|
|
6
|
+
if (minDueDate && maxDueDate) {
|
|
7
|
+
return (0, typeorm_1.Between)(minDueDate, maxDueDate);
|
|
8
|
+
}
|
|
9
|
+
if (maxDueDate) {
|
|
10
|
+
return (0, typeorm_1.LessThanOrEqual)(new Date(maxDueDate));
|
|
11
|
+
}
|
|
12
|
+
if (minDueDate) {
|
|
13
|
+
return (0, typeorm_1.MoreThanOrEqual)(new Date(minDueDate));
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
exports.generateDateQuery = generateDateQuery;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getApiTypeFromColumn = void 0;
|
|
4
|
+
function getApiTypeFromColumn(columnType) {
|
|
5
|
+
if (!columnType) {
|
|
6
|
+
return 'string';
|
|
7
|
+
}
|
|
8
|
+
switch (columnType) {
|
|
9
|
+
case 'boolean':
|
|
10
|
+
return columnType;
|
|
11
|
+
default:
|
|
12
|
+
return 'string';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.getApiTypeFromColumn = getApiTypeFromColumn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPagingKey(pageSize: number, skip: number, total: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSkip(pagingKey: number | string, pageSize: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeFalseyKeys<T>(obj: T): T;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeFalseyKeys = void 0;
|
|
4
|
+
function removeFalseyKeys(obj) {
|
|
5
|
+
return Object.entries(obj)
|
|
6
|
+
.filter(([k, v]) => typeof v !== 'undefined')
|
|
7
|
+
.reduce((acc, [k, v]) => {
|
|
8
|
+
acc[k] = v;
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
}
|
|
12
|
+
exports.removeFalseyKeys = removeFalseyKeys;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { IDataSourceOptions } from './types/data-source-options.interface';
|
|
3
|
+
export declare class ServerTypeormMysqlModule {
|
|
4
|
+
static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
|
|
5
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 ServerTypeormMysqlModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ServerTypeormMysqlModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const typeorm_1 = require("typeorm");
|
|
13
|
+
const data_source_factory_function_1 = require("./functions/data-source-factory.function");
|
|
14
|
+
const dataSourceMap = new Map();
|
|
15
|
+
let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormMysqlModule {
|
|
16
|
+
static configure(injectables, entities, options, name = 'default') {
|
|
17
|
+
const providers = [
|
|
18
|
+
{
|
|
19
|
+
provide: typeorm_1.DataSource,
|
|
20
|
+
useFactory: async () => {
|
|
21
|
+
const cachedDataSource = dataSourceMap.get(name);
|
|
22
|
+
if (!cachedDataSource) {
|
|
23
|
+
const dataSource = (0, data_source_factory_function_1.dataSourceFactory)(name, options, entities);
|
|
24
|
+
await dataSource.initialize();
|
|
25
|
+
dataSourceMap.set(name, dataSource);
|
|
26
|
+
}
|
|
27
|
+
return dataSourceMap.get(name);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
provide: typeorm_1.EntityManager,
|
|
32
|
+
useFactory: (dataSource) => {
|
|
33
|
+
return dataSource.manager;
|
|
34
|
+
},
|
|
35
|
+
inject: [typeorm_1.DataSource]
|
|
36
|
+
},
|
|
37
|
+
...injectables,
|
|
38
|
+
];
|
|
39
|
+
return {
|
|
40
|
+
module: ServerTypeormMysqlModule_1,
|
|
41
|
+
exports: providers,
|
|
42
|
+
providers,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.ServerTypeormMysqlModule = ServerTypeormMysqlModule;
|
|
47
|
+
exports.ServerTypeormMysqlModule = ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = __decorate([
|
|
48
|
+
(0, common_1.Module)({})
|
|
49
|
+
], ServerTypeormMysqlModule);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IEntityProvider<TEntity, TFindOneOptions, TFindManyOptions, TFindOptionsWhere, TQueryDeepPartialEntity> {
|
|
2
|
+
getOne: (options: TFindOneOptions) => Promise<TEntity>;
|
|
3
|
+
getMany: (options: TFindManyOptions) => Promise<TEntity[]>;
|
|
4
|
+
postOne: (body: Partial<TEntity>) => Promise<TEntity>;
|
|
5
|
+
postMany: (body: Partial<TEntity[]>) => Promise<TEntity[]>;
|
|
6
|
+
delete: (options: TFindOptionsWhere) => Promise<void>;
|
|
7
|
+
put: (options: TFindOptionsWhere, body: TQueryDeepPartialEntity) => Promise<void>;
|
|
8
|
+
patch: (options: TFindOptionsWhere, body: TQueryDeepPartialEntity) => Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './lib/classes/type-orm-paging-repository.class';
|
|
2
|
+
export * from './lib/classes/type-orm-repository.class';
|
|
3
|
+
export * from './lib/constants/many-to-one-relation-options.constant';
|
|
4
|
+
export * from './lib/decorators/nullable-table-column.decorator';
|
|
5
|
+
export * from './lib/decorators/primary-table-column.decorator';
|
|
6
|
+
export * from './lib/decorators/table-column.decorator';
|
|
7
|
+
export * from './lib/decorators/table.decorator';
|
|
8
|
+
export * from './lib/functions/data-source-config-factory.function';
|
|
9
|
+
export * from './lib/functions/data-source-factory.function';
|
|
10
|
+
export * from './lib/functions/generate-date-query.function';
|
|
11
|
+
export * from './lib/functions/get-api-type-from-column.function';
|
|
12
|
+
export * from './lib/functions/get-paging-key.function';
|
|
13
|
+
export * from './lib/functions/get-skip.function';
|
|
14
|
+
export * from './lib/functions/remove-falsey-keys.function';
|
|
15
|
+
export * from './lib/types/data-source-options.interface';
|
|
16
|
+
export * from './lib/types/entity-provider.interface';
|
|
17
|
+
export * from './lib/types/page-params.interface';
|
|
18
|
+
export * from './lib/types/paged-data.interface';
|
|
19
|
+
export * from './lib/server-typeorm-mysql.module';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { TypeOrmRepository } from './type-orm-repository.class';
|
|
3
|
+
import { IPagedData } from '../types/paged-data.interface';
|
|
4
|
+
import { getSkip } from '../functions/get-skip.function';
|
|
5
|
+
import { removeFalseyKeys } from '../functions/remove-falsey-keys.function';
|
|
6
|
+
import { getPagingKey } from '../functions/get-paging-key.function';
|
|
7
|
+
import { IPageParams } from '../types/page-params.interface';
|
|
8
|
+
export declare abstract class TypeOrmPagingRepository<TEntity, TEntityParams> extends TypeOrmRepository<TEntity> {
|
|
9
|
+
protected getPagingKey: typeof getPagingKey;
|
|
10
|
+
protected getSkip: typeof getSkip;
|
|
11
|
+
protected removeFalseyKeys: typeof removeFalseyKeys;
|
|
12
|
+
constructor(entityType: any, entityManager: EntityManager);
|
|
13
|
+
abstract getPage(pageParams: IPageParams, params: TEntityParams): Promise<IPagedData<TEntity>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
|
2
|
+
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
3
|
+
import { IEntityProvider } from '../types/entity-provider.interface';
|
|
4
|
+
export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEntity, FindOneOptions<TEntity>, FindManyOptions<TEntity>, FindOptionsWhere<TEntity>, QueryDeepPartialEntity<TEntity>> {
|
|
5
|
+
private entityType;
|
|
6
|
+
entityManager: EntityManager;
|
|
7
|
+
constructor(entityType: any, entityManager: EntityManager);
|
|
8
|
+
forTransaction(entityManager: EntityManager): TypeOrmRepository<TEntity>;
|
|
9
|
+
getMany(options: FindManyOptions<TEntity>): Promise<TEntity[]>;
|
|
10
|
+
getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
|
|
11
|
+
getOne(options: FindOneOptions<TEntity>): Promise<TEntity>;
|
|
12
|
+
postOne(body: Partial<TEntity>): Promise<TEntity>;
|
|
13
|
+
postMany(body: Partial<TEntity>[]): Promise<TEntity[]>;
|
|
14
|
+
delete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
15
|
+
softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
|
|
16
|
+
put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
17
|
+
patch(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
|
|
18
|
+
get repo(): import("typeorm").Repository<import("typeorm").ObjectLiteral>;
|
|
19
|
+
protected insertAndReturn(entityToInsert: TEntity): Promise<TEntity>;
|
|
20
|
+
protected insertAndReturnMany(entitiesToInsert: TEntity[]): Promise<TEntity[]>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions';
|
|
2
|
+
import { IDataSourceOptions } from '../types/data-source-options.interface';
|
|
3
|
+
export declare function dataSourceConfigFactory(name: string, options: IDataSourceOptions, entities: any[]): MysqlConnectionOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPagingKey(pageSize: number, skip: number, total: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSkip(pagingKey: number | string, pageSize: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeFalseyKeys<T>(obj: T): T;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { IDataSourceOptions } from './types/data-source-options.interface';
|
|
3
|
+
export declare class ServerTypeormMysqlModule {
|
|
4
|
+
static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
|
|
5
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IEntityProvider<TEntity, TFindOneOptions, TFindManyOptions, TFindOptionsWhere, TQueryDeepPartialEntity> {
|
|
2
|
+
getOne: (options: TFindOneOptions) => Promise<TEntity>;
|
|
3
|
+
getMany: (options: TFindManyOptions) => Promise<TEntity[]>;
|
|
4
|
+
postOne: (body: Partial<TEntity>) => Promise<TEntity>;
|
|
5
|
+
postMany: (body: Partial<TEntity[]>) => Promise<TEntity[]>;
|
|
6
|
+
delete: (options: TFindOptionsWhere) => Promise<void>;
|
|
7
|
+
put: (options: TFindOptionsWhere, body: TQueryDeepPartialEntity) => Promise<void>;
|
|
8
|
+
patch: (options: TFindOptionsWhere, body: TQueryDeepPartialEntity) => Promise<void>;
|
|
9
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onivoro/server-typeorm-mysql",
|
|
3
|
+
"version": "0.1.32",
|
|
4
|
+
"repository": {
|
|
5
|
+
"url": "git+https://github.com/onivoro/server-typeorm-mysql.git"
|
|
6
|
+
},
|
|
7
|
+
"main": "dist/cjs/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"types": "dist/types/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/*"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"onx": "onx",
|
|
15
|
+
"build": "onx Build",
|
|
16
|
+
"deploy": "onx Publish",
|
|
17
|
+
"test": "onx Test",
|
|
18
|
+
"update": "onx Update"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/types/index.d.ts",
|
|
23
|
+
"require": "./dist/cjs/index.js",
|
|
24
|
+
"import": "./dist/esm/index.js",
|
|
25
|
+
"default": "./dist/esm/lib.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"onx": {
|
|
29
|
+
"platform": "server",
|
|
30
|
+
"module": ""
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@onivoro/cli": "*",
|
|
34
|
+
"@types/jest": "*",
|
|
35
|
+
"@types/node": "18.19.1",
|
|
36
|
+
"typescript": "*"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": "18.19.1",
|
|
40
|
+
"npm": "10.2.4"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@nestjs/common": "^10.4.4",
|
|
44
|
+
"@nestjs/swagger": "^7.4.2",
|
|
45
|
+
"@onivoro/isomorphic-common": "^0.4.0",
|
|
46
|
+
"typeorm": "^0.3.20",
|
|
47
|
+
"typeorm-naming-strategies": "^4.1.0"
|
|
48
|
+
}
|
|
49
|
+
}
|