@flusys/nestjs-shared 5.1.2 → 5.1.3

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.
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "RequestScopedApiService", {
6
- enumerable: true,
7
- get: function() {
8
- return RequestScopedApiService;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _apiserviceclass = require("./api-service.class");
13
- function _define_property(obj, key, value) {
14
- if (key in obj) {
15
- Object.defineProperty(obj, key, {
16
- value: value,
17
- enumerable: true,
18
- configurable: true,
19
- writable: true
20
- });
21
- } else {
22
- obj[key] = value;
23
- }
24
- return obj;
25
- }
26
- function _ts_decorate(decorators, target, key, desc) {
27
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29
- 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;
30
- return c > 3 && r && Object.defineProperty(target, key, r), r;
31
- }
32
- let RequestScopedApiService = class RequestScopedApiService extends _apiserviceclass.ApiService {
33
- async ensureRepositoryInitialized() {
34
- if (!this.repositoryInitialized) {
35
- const entity = this.resolveEntity();
36
- const provider = this.getDataSourceProvider();
37
- this.repository = await provider.getRepository(entity);
38
- this.repositoryInitialized = true;
39
- }
40
- }
41
- /** Initialize additional repositories beyond the primary entity */ async initializeAdditionalRepositories(entities) {
42
- const provider = this.getDataSourceProvider();
43
- const repositories = [];
44
- for (const entity of entities){
45
- repositories.push(await provider.getRepository(entity));
46
- }
47
- return repositories;
48
- }
49
- /** Get DataSource for direct access (transactions, custom queries) */ async getDataSourceForService() {
50
- const provider = this.getDataSourceProvider();
51
- return await provider.getDataSource();
52
- }
53
- constructor(...args){
54
- super(...args), _define_property(this, "repositoryInitialized", false);
55
- }
56
- };
57
- RequestScopedApiService = _ts_decorate([
58
- (0, _common.Injectable)({
59
- scope: _common.Scope.REQUEST
60
- })
61
- ], RequestScopedApiService);
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DataSourceModule", {
6
- enumerable: true,
7
- get: function() {
8
- return DataSourceModule;
9
- }
10
- });
11
- const _nestjscore = require("@flusys/nestjs-core");
12
- const _common = require("@nestjs/common");
13
- const _multitenantdatasourceservice = require("./multi-tenant-datasource.service");
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- 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;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- let DataSourceModule = class DataSourceModule {
21
- /**
22
- * Register with static options
23
- */ static forRoot(options) {
24
- const { global = false, ...moduleOptions } = options;
25
- return {
26
- module: DataSourceModule,
27
- global,
28
- providers: [
29
- {
30
- provide: _nestjscore.MODULE_OPTIONS,
31
- useValue: moduleOptions
32
- },
33
- _multitenantdatasourceservice.MultiTenantDataSourceService
34
- ],
35
- exports: [
36
- _nestjscore.MODULE_OPTIONS,
37
- _multitenantdatasourceservice.MultiTenantDataSourceService
38
- ]
39
- };
40
- }
41
- /**
42
- * Register with async options
43
- */ static forRootAsync(asyncOptions) {
44
- const { global = false, imports = [] } = asyncOptions;
45
- return {
46
- module: DataSourceModule,
47
- global,
48
- imports,
49
- providers: [
50
- ...this.createAsyncProviders(asyncOptions),
51
- _multitenantdatasourceservice.MultiTenantDataSourceService
52
- ],
53
- exports: [
54
- _nestjscore.MODULE_OPTIONS,
55
- _multitenantdatasourceservice.MultiTenantDataSourceService
56
- ]
57
- };
58
- }
59
- /**
60
- * Import for child modules (uses existing MODULE_OPTIONS)
61
- */ static forFeature() {
62
- return {
63
- module: DataSourceModule,
64
- providers: [
65
- _multitenantdatasourceservice.MultiTenantDataSourceService
66
- ],
67
- exports: [
68
- _multitenantdatasourceservice.MultiTenantDataSourceService
69
- ]
70
- };
71
- }
72
- /**
73
- * Create async providers based on options
74
- */ static createAsyncProviders(options) {
75
- if (options.useFactory) {
76
- return [
77
- {
78
- provide: _nestjscore.MODULE_OPTIONS,
79
- useFactory: options.useFactory,
80
- inject: options.inject || []
81
- }
82
- ];
83
- }
84
- if (options.useClass) {
85
- return [
86
- {
87
- provide: options.useClass,
88
- useClass: options.useClass
89
- },
90
- this.createFactoryProvider(options.useClass)
91
- ];
92
- }
93
- if (options.useExisting) {
94
- return [
95
- this.createFactoryProvider(options.useExisting)
96
- ];
97
- }
98
- return [
99
- {
100
- provide: _nestjscore.MODULE_OPTIONS,
101
- useValue: {}
102
- }
103
- ];
104
- }
105
- static createFactoryProvider(factoryClass) {
106
- return {
107
- provide: _nestjscore.MODULE_OPTIONS,
108
- useFactory: async (factory)=>factory.createOptions(),
109
- inject: [
110
- factoryClass
111
- ]
112
- };
113
- }
114
- };
115
- DataSourceModule = _ts_decorate([
116
- (0, _common.Module)({})
117
- ], DataSourceModule);
@@ -1,14 +0,0 @@
1
- import { DataSource, EntityTarget, Repository } from 'typeorm';
2
- import { Identity } from '../entities';
3
- import { IDataSourceProvider } from '../interfaces';
4
- import { ApiService } from './api-service.class';
5
- export declare abstract class RequestScopedApiService<CreateDtoT extends object, UpdateDtoT extends {
6
- id: string;
7
- }, InterfaceT extends Identity, EntityT extends Identity> extends ApiService<CreateDtoT, UpdateDtoT, InterfaceT, EntityT> {
8
- private repositoryInitialized;
9
- protected abstract resolveEntity(): EntityTarget<EntityT>;
10
- protected abstract getDataSourceProvider(): IDataSourceProvider;
11
- protected ensureRepositoryInitialized(): Promise<void>;
12
- protected initializeAdditionalRepositories(entities: EntityTarget<any>[]): Promise<Repository<any>[]>;
13
- protected getDataSourceForService(): Promise<DataSource>;
14
- }
@@ -1,51 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- 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;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- import { Injectable, Scope } from '@nestjs/common';
21
- import { ApiService } from './api-service.class';
22
- export class RequestScopedApiService extends ApiService {
23
- async ensureRepositoryInitialized() {
24
- if (!this.repositoryInitialized) {
25
- const entity = this.resolveEntity();
26
- const provider = this.getDataSourceProvider();
27
- this.repository = await provider.getRepository(entity);
28
- this.repositoryInitialized = true;
29
- }
30
- }
31
- /** Initialize additional repositories beyond the primary entity */ async initializeAdditionalRepositories(entities) {
32
- const provider = this.getDataSourceProvider();
33
- const repositories = [];
34
- for (const entity of entities){
35
- repositories.push(await provider.getRepository(entity));
36
- }
37
- return repositories;
38
- }
39
- /** Get DataSource for direct access (transactions, custom queries) */ async getDataSourceForService() {
40
- const provider = this.getDataSourceProvider();
41
- return await provider.getDataSource();
42
- }
43
- constructor(...args){
44
- super(...args), _define_property(this, "repositoryInitialized", false);
45
- }
46
- }
47
- RequestScopedApiService = _ts_decorate([
48
- Injectable({
49
- scope: Scope.REQUEST
50
- })
51
- ], RequestScopedApiService);
@@ -1,107 +0,0 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- }
7
- import { MODULE_OPTIONS } from '@flusys/nestjs-core';
8
- import { Module } from '@nestjs/common';
9
- import { MultiTenantDataSourceService } from './multi-tenant-datasource.service';
10
- export class DataSourceModule {
11
- /**
12
- * Register with static options
13
- */ static forRoot(options) {
14
- const { global = false, ...moduleOptions } = options;
15
- return {
16
- module: DataSourceModule,
17
- global,
18
- providers: [
19
- {
20
- provide: MODULE_OPTIONS,
21
- useValue: moduleOptions
22
- },
23
- MultiTenantDataSourceService
24
- ],
25
- exports: [
26
- MODULE_OPTIONS,
27
- MultiTenantDataSourceService
28
- ]
29
- };
30
- }
31
- /**
32
- * Register with async options
33
- */ static forRootAsync(asyncOptions) {
34
- const { global = false, imports = [] } = asyncOptions;
35
- return {
36
- module: DataSourceModule,
37
- global,
38
- imports,
39
- providers: [
40
- ...this.createAsyncProviders(asyncOptions),
41
- MultiTenantDataSourceService
42
- ],
43
- exports: [
44
- MODULE_OPTIONS,
45
- MultiTenantDataSourceService
46
- ]
47
- };
48
- }
49
- /**
50
- * Import for child modules (uses existing MODULE_OPTIONS)
51
- */ static forFeature() {
52
- return {
53
- module: DataSourceModule,
54
- providers: [
55
- MultiTenantDataSourceService
56
- ],
57
- exports: [
58
- MultiTenantDataSourceService
59
- ]
60
- };
61
- }
62
- /**
63
- * Create async providers based on options
64
- */ static createAsyncProviders(options) {
65
- if (options.useFactory) {
66
- return [
67
- {
68
- provide: MODULE_OPTIONS,
69
- useFactory: options.useFactory,
70
- inject: options.inject || []
71
- }
72
- ];
73
- }
74
- if (options.useClass) {
75
- return [
76
- {
77
- provide: options.useClass,
78
- useClass: options.useClass
79
- },
80
- this.createFactoryProvider(options.useClass)
81
- ];
82
- }
83
- if (options.useExisting) {
84
- return [
85
- this.createFactoryProvider(options.useExisting)
86
- ];
87
- }
88
- return [
89
- {
90
- provide: MODULE_OPTIONS,
91
- useValue: {}
92
- }
93
- ];
94
- }
95
- static createFactoryProvider(factoryClass) {
96
- return {
97
- provide: MODULE_OPTIONS,
98
- useFactory: async (factory)=>factory.createOptions(),
99
- inject: [
100
- factoryClass
101
- ]
102
- };
103
- }
104
- }
105
- DataSourceModule = _ts_decorate([
106
- Module({})
107
- ], DataSourceModule);
@@ -1,19 +0,0 @@
1
- import { IAsyncModuleOptions, IDataSourceServiceOptions, IModuleOptionsFactory } from '@flusys/nestjs-core';
2
- import { DynamicModule, Type } from '@nestjs/common';
3
- export interface DataSourceModuleOptions extends IDataSourceServiceOptions {
4
- global?: boolean;
5
- }
6
- export interface DataSourceOptionsFactory extends IModuleOptionsFactory<IDataSourceServiceOptions> {
7
- createOptions(): Promise<IDataSourceServiceOptions> | IDataSourceServiceOptions;
8
- }
9
- export interface DataSourceModuleAsyncOptions extends IAsyncModuleOptions<IDataSourceServiceOptions> {
10
- useClass?: Type<DataSourceOptionsFactory>;
11
- useExisting?: Type<DataSourceOptionsFactory>;
12
- }
13
- export declare class DataSourceModule {
14
- static forRoot(options: DataSourceModuleOptions): DynamicModule;
15
- static forRootAsync(asyncOptions: DataSourceModuleAsyncOptions): DynamicModule;
16
- static forFeature(): DynamicModule;
17
- private static createAsyncProviders;
18
- private static createFactoryProvider;
19
- }