@flusys/nestjs-form-builder 1.0.0-beta → 1.0.0
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/README.md +722 -0
- package/cjs/controllers/form-result.controller.js +67 -5
- package/cjs/controllers/form.controller.js +48 -15
- package/cjs/docs/form-builder-swagger.config.js +6 -100
- package/cjs/dtos/form-result.dto.js +6 -93
- package/cjs/dtos/form.dto.js +21 -163
- package/cjs/entities/form-with-company.entity.js +12 -2
- package/cjs/entities/form.entity.js +103 -3
- package/cjs/entities/index.js +28 -16
- package/cjs/index.js +1 -0
- package/cjs/interfaces/form-result.interface.js +1 -6
- package/cjs/modules/form-builder.module.js +57 -83
- package/cjs/services/form-builder-config.service.js +6 -16
- package/cjs/services/form-builder-datasource.provider.js +19 -59
- package/cjs/services/form-result.service.js +107 -181
- package/cjs/services/form.service.js +56 -72
- package/cjs/utils/computed-field.utils.js +17 -29
- package/cjs/utils/permission.utils.js +11 -16
- package/controllers/form-result.controller.d.ts +10 -12
- package/dtos/form-result.dto.d.ts +2 -19
- package/dtos/form.dto.d.ts +6 -32
- package/entities/form-with-company.entity.d.ts +2 -2
- package/entities/form.entity.d.ts +12 -2
- package/entities/index.d.ts +7 -2
- package/fesm/controllers/form-result.controller.js +69 -7
- package/fesm/controllers/form.controller.js +50 -17
- package/fesm/docs/form-builder-swagger.config.js +6 -100
- package/fesm/dtos/form-result.dto.js +9 -99
- package/fesm/dtos/form.dto.js +22 -165
- package/fesm/entities/form-with-company.entity.js +12 -2
- package/fesm/entities/form.entity.js +104 -4
- package/fesm/entities/index.js +18 -24
- package/fesm/index.js +2 -0
- package/fesm/modules/form-builder.module.js +57 -83
- package/fesm/services/form-builder-config.service.js +6 -16
- package/fesm/services/form-builder-datasource.provider.js +19 -59
- package/fesm/services/form-result.service.js +107 -181
- package/fesm/services/form.service.js +56 -72
- package/fesm/utils/computed-field.utils.js +17 -29
- package/fesm/utils/permission.utils.js +2 -9
- package/index.d.ts +1 -0
- package/interfaces/form-builder-module.interface.d.ts +4 -7
- package/interfaces/form-result.interface.d.ts +2 -9
- package/interfaces/form.interface.d.ts +2 -10
- package/modules/form-builder.module.d.ts +4 -3
- package/package.json +3 -3
- package/services/form-builder-config.service.d.ts +5 -3
- package/services/form-builder-datasource.provider.d.ts +3 -6
- package/services/form-result.service.d.ts +5 -0
- package/services/form.service.d.ts +13 -10
- package/utils/permission.utils.d.ts +0 -2
- package/cjs/entities/form-base.entity.js +0 -113
- package/entities/form-base.entity.d.ts +0 -13
- package/fesm/entities/form-base.entity.js +0 -106
|
@@ -1,15 +1,115 @@
|
|
|
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
|
+
}
|
|
1
14
|
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
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;
|
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
19
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
+
}
|
|
23
|
+
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
24
|
+
import { Column, Entity, Index } from 'typeorm';
|
|
25
|
+
import { FormAccessType } from '../enums/form-access-type.enum';
|
|
26
|
+
export class Form extends Identity {
|
|
27
|
+
constructor(...args){
|
|
28
|
+
super(...args), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "slug", void 0), _define_property(this, "schema", void 0), _define_property(this, "schemaVersion", void 0), _define_property(this, "accessType", void 0), _define_property(this, "actionGroups", void 0), _define_property(this, "isActive", void 0), _define_property(this, "metadata", void 0);
|
|
29
|
+
}
|
|
10
30
|
}
|
|
31
|
+
_ts_decorate([
|
|
32
|
+
Column({
|
|
33
|
+
type: 'varchar',
|
|
34
|
+
length: 255,
|
|
35
|
+
nullable: false
|
|
36
|
+
}),
|
|
37
|
+
_ts_metadata("design:type", String)
|
|
38
|
+
], Form.prototype, "name", void 0);
|
|
39
|
+
_ts_decorate([
|
|
40
|
+
Column({
|
|
41
|
+
type: 'varchar',
|
|
42
|
+
length: 500,
|
|
43
|
+
nullable: true
|
|
44
|
+
}),
|
|
45
|
+
_ts_metadata("design:type", Object)
|
|
46
|
+
], Form.prototype, "description", void 0);
|
|
47
|
+
_ts_decorate([
|
|
48
|
+
Column({
|
|
49
|
+
type: 'varchar',
|
|
50
|
+
length: 255,
|
|
51
|
+
nullable: true
|
|
52
|
+
}),
|
|
53
|
+
_ts_metadata("design:type", Object)
|
|
54
|
+
], Form.prototype, "slug", void 0);
|
|
55
|
+
_ts_decorate([
|
|
56
|
+
Column({
|
|
57
|
+
type: 'json',
|
|
58
|
+
nullable: false
|
|
59
|
+
}),
|
|
60
|
+
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
61
|
+
], Form.prototype, "schema", void 0);
|
|
62
|
+
_ts_decorate([
|
|
63
|
+
Column({
|
|
64
|
+
type: 'int',
|
|
65
|
+
nullable: false,
|
|
66
|
+
default: 1,
|
|
67
|
+
name: 'schema_version'
|
|
68
|
+
}),
|
|
69
|
+
_ts_metadata("design:type", Number)
|
|
70
|
+
], Form.prototype, "schemaVersion", void 0);
|
|
71
|
+
_ts_decorate([
|
|
72
|
+
Column({
|
|
73
|
+
type: 'varchar',
|
|
74
|
+
length: 50,
|
|
75
|
+
default: 'AUTHENTICATED',
|
|
76
|
+
name: 'access_type'
|
|
77
|
+
}),
|
|
78
|
+
_ts_metadata("design:type", typeof FormAccessType === "undefined" ? Object : FormAccessType)
|
|
79
|
+
], Form.prototype, "accessType", void 0);
|
|
80
|
+
_ts_decorate([
|
|
81
|
+
Column({
|
|
82
|
+
type: 'simple-array',
|
|
83
|
+
nullable: true,
|
|
84
|
+
name: 'action_groups'
|
|
85
|
+
}),
|
|
86
|
+
_ts_metadata("design:type", Object)
|
|
87
|
+
], Form.prototype, "actionGroups", void 0);
|
|
88
|
+
_ts_decorate([
|
|
89
|
+
Column({
|
|
90
|
+
type: 'boolean',
|
|
91
|
+
nullable: false,
|
|
92
|
+
default: true,
|
|
93
|
+
name: 'is_active'
|
|
94
|
+
}),
|
|
95
|
+
_ts_metadata("design:type", Boolean)
|
|
96
|
+
], Form.prototype, "isActive", void 0);
|
|
97
|
+
_ts_decorate([
|
|
98
|
+
Column('simple-json', {
|
|
99
|
+
nullable: true
|
|
100
|
+
}),
|
|
101
|
+
_ts_metadata("design:type", Object)
|
|
102
|
+
], Form.prototype, "metadata", void 0);
|
|
11
103
|
Form = _ts_decorate([
|
|
12
104
|
Entity({
|
|
13
105
|
name: 'form'
|
|
14
|
-
})
|
|
106
|
+
}),
|
|
107
|
+
Index([
|
|
108
|
+
'slug'
|
|
109
|
+
], {
|
|
110
|
+
unique: true
|
|
111
|
+
}),
|
|
112
|
+
Index([
|
|
113
|
+
'isActive'
|
|
114
|
+
])
|
|
15
115
|
], Form);
|
package/fesm/entities/index.js
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
//
|
|
2
|
-
export * from './form-base.entity';
|
|
1
|
+
// Entities without company feature
|
|
3
2
|
export * from './form.entity';
|
|
4
|
-
export * from './form-with-company.entity';
|
|
5
|
-
// Form Result Entity (single - no company variant needed)
|
|
6
3
|
export * from './form-result.entity';
|
|
7
|
-
//
|
|
4
|
+
// Entities with company feature
|
|
5
|
+
export * from './form-with-company.entity';
|
|
8
6
|
import { Form } from './form.entity';
|
|
9
|
-
import { FormWithCompany } from './form-with-company.entity';
|
|
10
7
|
import { FormResult } from './form-result.entity';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
return [
|
|
26
|
-
Form,
|
|
27
|
-
FormResult
|
|
28
|
-
];
|
|
8
|
+
import { FormWithCompany } from './form-with-company.entity';
|
|
9
|
+
// Core entities (no company feature)
|
|
10
|
+
export const FormCoreEntities = [
|
|
11
|
+
Form,
|
|
12
|
+
FormResult
|
|
13
|
+
];
|
|
14
|
+
// Company-specific entities
|
|
15
|
+
export const FormCompanyEntities = [
|
|
16
|
+
FormWithCompany,
|
|
17
|
+
FormResult
|
|
18
|
+
];
|
|
19
|
+
export function getFormBuilderEntitiesByConfig(enableCompanyFeature) {
|
|
20
|
+
return enableCompanyFeature ? FormCompanyEntities : FormCoreEntities;
|
|
29
21
|
}
|
|
22
|
+
// Base type aliases for backwards compatibility with services
|
|
23
|
+
export { Form as FormBase } from './form.entity';
|
package/fesm/index.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
+
}
|
|
1
14
|
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -13,8 +26,6 @@ export class FormBuilderModule {
|
|
|
13
26
|
/**
|
|
14
27
|
* Register FormBuilderModule synchronously
|
|
15
28
|
*/ static forRoot(options) {
|
|
16
|
-
const controllers = this.getControllers(options);
|
|
17
|
-
const providers = this.getProviders(options);
|
|
18
29
|
return {
|
|
19
30
|
module: FormBuilderModule,
|
|
20
31
|
global: options.global ?? false,
|
|
@@ -22,21 +33,14 @@ export class FormBuilderModule {
|
|
|
22
33
|
CacheModule,
|
|
23
34
|
UtilsModule
|
|
24
35
|
],
|
|
25
|
-
controllers: options.includeController !== false ?
|
|
26
|
-
providers,
|
|
27
|
-
exports:
|
|
28
|
-
FormBuilderConfigService,
|
|
29
|
-
FormBuilderDataSourceProvider,
|
|
30
|
-
FormService,
|
|
31
|
-
FormResultService
|
|
32
|
-
]
|
|
36
|
+
controllers: options.includeController !== false ? this.CONTROLLERS : [],
|
|
37
|
+
providers: this.buildProviders(options),
|
|
38
|
+
exports: this.EXPORTS
|
|
33
39
|
};
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
42
|
* Register FormBuilderModule asynchronously
|
|
37
43
|
*/ static forRootAsync(options) {
|
|
38
|
-
const controllers = this.getControllers(options);
|
|
39
|
-
const asyncProviders = this.createAsyncProviders(options);
|
|
40
44
|
return {
|
|
41
45
|
module: FormBuilderModule,
|
|
42
46
|
global: options.global ?? false,
|
|
@@ -45,41 +49,22 @@ export class FormBuilderModule {
|
|
|
45
49
|
CacheModule,
|
|
46
50
|
UtilsModule
|
|
47
51
|
],
|
|
48
|
-
controllers: options.includeController !== false ?
|
|
52
|
+
controllers: options.includeController !== false ? this.CONTROLLERS : [],
|
|
49
53
|
providers: [
|
|
50
|
-
...
|
|
51
|
-
...this.
|
|
54
|
+
...this.buildAsyncProviders(options),
|
|
55
|
+
...this.buildProviders()
|
|
52
56
|
],
|
|
53
|
-
exports:
|
|
54
|
-
FormBuilderConfigService,
|
|
55
|
-
FormBuilderDataSourceProvider,
|
|
56
|
-
FormService,
|
|
57
|
-
FormResultService
|
|
58
|
-
]
|
|
57
|
+
exports: this.EXPORTS
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get controllers
|
|
64
|
-
*/ static getControllers(options) {
|
|
65
|
-
return [
|
|
66
|
-
FormController,
|
|
67
|
-
FormResultController
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get providers
|
|
72
|
-
* @param options Module options
|
|
73
|
-
* @param includeOptionsProvider Whether to include the FORM_BUILDER_MODULE_OPTIONS provider
|
|
74
|
-
*/ static getProviders(options, includeOptionsProvider = true) {
|
|
60
|
+
static buildProviders(options) {
|
|
75
61
|
const providers = [
|
|
76
62
|
FormBuilderConfigService,
|
|
77
63
|
FormBuilderDataSourceProvider,
|
|
78
64
|
FormService,
|
|
79
65
|
FormResultService
|
|
80
66
|
];
|
|
81
|
-
|
|
82
|
-
if (includeOptionsProvider) {
|
|
67
|
+
if (options) {
|
|
83
68
|
providers.unshift({
|
|
84
69
|
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
85
70
|
useValue: options
|
|
@@ -87,65 +72,54 @@ export class FormBuilderModule {
|
|
|
87
72
|
}
|
|
88
73
|
return providers;
|
|
89
74
|
}
|
|
90
|
-
|
|
91
|
-
* Create async providers for forRootAsync
|
|
92
|
-
*/ static createAsyncProviders(options) {
|
|
75
|
+
static buildAsyncProviders(options) {
|
|
93
76
|
if (options.useFactory) {
|
|
94
77
|
return [
|
|
95
78
|
{
|
|
96
79
|
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
97
|
-
useFactory: async (...args)=>{
|
|
98
|
-
const config = await options.useFactory(...args);
|
|
99
|
-
return {
|
|
80
|
+
useFactory: async (...args)=>({
|
|
100
81
|
...options,
|
|
101
|
-
config
|
|
102
|
-
}
|
|
103
|
-
},
|
|
82
|
+
config: await options.useFactory(...args)
|
|
83
|
+
}),
|
|
104
84
|
inject: options.inject || []
|
|
105
85
|
}
|
|
106
86
|
];
|
|
107
87
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
112
|
-
useFactory: async (optionsFactory)=>{
|
|
113
|
-
const config = await optionsFactory.createFormBuilderOptions();
|
|
114
|
-
return {
|
|
115
|
-
...options,
|
|
116
|
-
config
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
inject: [
|
|
120
|
-
options.useClass
|
|
121
|
-
]
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
provide: options.useClass,
|
|
125
|
-
useClass: options.useClass
|
|
126
|
-
}
|
|
127
|
-
];
|
|
88
|
+
const factoryClass = options.useClass || options.useExisting;
|
|
89
|
+
if (!factoryClass) {
|
|
90
|
+
return [];
|
|
128
91
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
92
|
+
const providers = [
|
|
93
|
+
{
|
|
94
|
+
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
95
|
+
useFactory: async (factory)=>({
|
|
96
|
+
...options,
|
|
97
|
+
config: await factory.createFormBuilderOptions()
|
|
98
|
+
}),
|
|
99
|
+
inject: [
|
|
100
|
+
factoryClass
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
if (options.useClass) {
|
|
105
|
+
providers.push({
|
|
106
|
+
provide: options.useClass,
|
|
107
|
+
useClass: options.useClass
|
|
108
|
+
});
|
|
145
109
|
}
|
|
146
|
-
return
|
|
110
|
+
return providers;
|
|
147
111
|
}
|
|
148
112
|
}
|
|
113
|
+
_define_property(FormBuilderModule, "CONTROLLERS", [
|
|
114
|
+
FormController,
|
|
115
|
+
FormResultController
|
|
116
|
+
]);
|
|
117
|
+
_define_property(FormBuilderModule, "EXPORTS", [
|
|
118
|
+
FormBuilderConfigService,
|
|
119
|
+
FormBuilderDataSourceProvider,
|
|
120
|
+
FormService,
|
|
121
|
+
FormResultService
|
|
122
|
+
]);
|
|
149
123
|
FormBuilderModule = _ts_decorate([
|
|
150
124
|
Module({})
|
|
151
125
|
], FormBuilderModule);
|
|
@@ -29,29 +29,19 @@ import { Injectable, Inject } from '@nestjs/common';
|
|
|
29
29
|
import { FORM_BUILDER_MODULE_OPTIONS } from '../config/form-builder.constants';
|
|
30
30
|
import { FormBuilderModuleOptions } from '../interfaces/form-builder-module.interface';
|
|
31
31
|
export class FormBuilderConfigService {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/ isCompanyFeatureEnabled() {
|
|
35
|
-
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
32
|
+
isCompanyFeatureEnabled(tenant) {
|
|
33
|
+
return tenant?.enableCompanyFeature ?? this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
* Get database mode
|
|
39
|
-
*/ getDatabaseMode() {
|
|
35
|
+
getDatabaseMode() {
|
|
40
36
|
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
41
37
|
}
|
|
42
|
-
|
|
43
|
-
* Check if multi-tenant mode is enabled
|
|
44
|
-
*/ isMultiTenant() {
|
|
38
|
+
isMultiTenant() {
|
|
45
39
|
return this.getDatabaseMode() === 'multi-tenant';
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
* Get module options
|
|
49
|
-
*/ getOptions() {
|
|
41
|
+
getOptions() {
|
|
50
42
|
return this.options;
|
|
51
43
|
}
|
|
52
|
-
|
|
53
|
-
* Get form builder configuration
|
|
54
|
-
*/ getConfig() {
|
|
44
|
+
getConfig() {
|
|
55
45
|
return this.options.config;
|
|
56
46
|
}
|
|
57
47
|
constructor(options){
|
|
@@ -29,69 +29,36 @@ import { MultiTenantDataSourceService } from '@flusys/nestjs-shared/modules';
|
|
|
29
29
|
import { Inject, Injectable, Logger, Optional, Scope } from '@nestjs/common';
|
|
30
30
|
import { REQUEST } from '@nestjs/core';
|
|
31
31
|
import { Request } from 'express';
|
|
32
|
-
import {
|
|
33
|
-
import { FORM_BUILDER_MODULE_OPTIONS } from '../config/form-builder.constants';
|
|
32
|
+
import { FormBuilderConfigService } from './form-builder-config.service';
|
|
34
33
|
export class FormBuilderDataSourceProvider extends MultiTenantDataSourceService {
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Build parent options from FormBuilderModuleOptions
|
|
38
|
-
*/ static buildParentOptions(options) {
|
|
34
|
+
static buildParentOptions(options) {
|
|
39
35
|
return {
|
|
40
36
|
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
41
|
-
defaultDatabaseConfig: options.config?.defaultDatabaseConfig
|
|
37
|
+
defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
|
|
38
|
+
tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
|
|
39
|
+
tenants: options.config?.tenants
|
|
42
40
|
};
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Get global enable company feature flag
|
|
47
|
-
*/ getEnableCompanyFeature() {
|
|
48
|
-
return this.formBuilderOptions.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Get enable company feature for specific tenant
|
|
52
|
-
* Falls back to global setting if not specified per-tenant
|
|
53
|
-
*/ getEnableCompanyFeatureForTenant(tenant) {
|
|
54
|
-
return tenant?.enableCompanyFeature ?? this.getEnableCompanyFeature();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get enable company feature for current request context
|
|
58
|
-
*/ getEnableCompanyFeatureForCurrentTenant() {
|
|
59
|
-
return this.getEnableCompanyFeatureForTenant(this.getCurrentTenant() ?? undefined);
|
|
60
|
-
}
|
|
61
|
-
// Entity Management
|
|
62
|
-
/**
|
|
63
|
-
* Get form builder entities based on company feature flag
|
|
64
|
-
*/ async getFormBuilderEntities(enableCompanyFeature) {
|
|
65
|
-
const enable = enableCompanyFeature ?? this.getEnableCompanyFeature();
|
|
42
|
+
async getFormBuilderEntities(enableCompanyFeature) {
|
|
43
|
+
const enable = enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
66
44
|
const { Form, FormResult, FormWithCompany } = await import('../entities');
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
return [
|
|
45
|
+
return enable ? [
|
|
46
|
+
FormWithCompany,
|
|
47
|
+
FormResult
|
|
48
|
+
] : [
|
|
74
49
|
Form,
|
|
75
50
|
FormResult
|
|
76
51
|
];
|
|
77
52
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* Override to dynamically set entities based on tenant config
|
|
81
|
-
*/ async createDataSourceFromConfig(config) {
|
|
82
|
-
const currentTenant = this.getCurrentTenant();
|
|
83
|
-
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
53
|
+
async createDataSourceFromConfig(config) {
|
|
54
|
+
const enableCompanyFeature = this.configService.isCompanyFeatureEnabled(this.getCurrentTenant() ?? undefined);
|
|
84
55
|
const entities = await this.getFormBuilderEntities(enableCompanyFeature);
|
|
85
56
|
return super.createDataSourceFromConfig(config, entities);
|
|
86
57
|
}
|
|
87
|
-
|
|
88
|
-
* Override to use FormBuilder-specific static cache
|
|
89
|
-
*/ async getSingleDataSource() {
|
|
90
|
-
// Return existing initialized connection from FormBuilder-specific cache
|
|
58
|
+
async getSingleDataSource() {
|
|
91
59
|
if (FormBuilderDataSourceProvider.singleDataSource?.isInitialized) {
|
|
92
60
|
return FormBuilderDataSourceProvider.singleDataSource;
|
|
93
61
|
}
|
|
94
|
-
// If another request is creating the connection, wait for it
|
|
95
62
|
if (FormBuilderDataSourceProvider.singleConnectionLock) {
|
|
96
63
|
return FormBuilderDataSourceProvider.singleConnectionLock;
|
|
97
64
|
}
|
|
@@ -99,7 +66,6 @@ export class FormBuilderDataSourceProvider extends MultiTenantDataSourceService
|
|
|
99
66
|
if (!config) {
|
|
100
67
|
throw new Error('No database config available. Provide defaultDatabaseConfig in FormBuilderModule options.');
|
|
101
68
|
}
|
|
102
|
-
// Create connection with lock to prevent race conditions
|
|
103
69
|
const connectionPromise = this.createDataSourceFromConfig(config);
|
|
104
70
|
FormBuilderDataSourceProvider.singleConnectionLock = connectionPromise;
|
|
105
71
|
try {
|
|
@@ -110,20 +76,15 @@ export class FormBuilderDataSourceProvider extends MultiTenantDataSourceService
|
|
|
110
76
|
FormBuilderDataSourceProvider.singleConnectionLock = null;
|
|
111
77
|
}
|
|
112
78
|
}
|
|
113
|
-
|
|
114
|
-
* Override to use FormBuilder-specific static cache for tenant connections
|
|
115
|
-
*/ async getOrCreateTenantConnection(tenant) {
|
|
116
|
-
// Return existing initialized connection from FormBuilder-specific cache
|
|
79
|
+
async getOrCreateTenantConnection(tenant) {
|
|
117
80
|
const existing = FormBuilderDataSourceProvider.tenantConnections.get(tenant.id);
|
|
118
81
|
if (existing?.isInitialized) {
|
|
119
82
|
return existing;
|
|
120
83
|
}
|
|
121
|
-
// If another request is creating this tenant's connection, wait for it
|
|
122
84
|
const pendingConnection = FormBuilderDataSourceProvider.connectionLocks.get(tenant.id);
|
|
123
85
|
if (pendingConnection) {
|
|
124
86
|
return pendingConnection;
|
|
125
87
|
}
|
|
126
|
-
// Create connection with lock to prevent race conditions
|
|
127
88
|
const config = this.buildTenantDatabaseConfig(tenant);
|
|
128
89
|
const connectionPromise = this.createDataSourceFromConfig(config);
|
|
129
90
|
FormBuilderDataSourceProvider.connectionLocks.set(tenant.id, connectionPromise);
|
|
@@ -135,11 +96,10 @@ export class FormBuilderDataSourceProvider extends MultiTenantDataSourceService
|
|
|
135
96
|
FormBuilderDataSourceProvider.connectionLocks.delete(tenant.id);
|
|
136
97
|
}
|
|
137
98
|
}
|
|
138
|
-
constructor(
|
|
139
|
-
super(FormBuilderDataSourceProvider.buildParentOptions(
|
|
99
|
+
constructor(configService, request){
|
|
100
|
+
super(FormBuilderDataSourceProvider.buildParentOptions(configService.getOptions()), request), _define_property(this, "configService", void 0), _define_property(this, "logger", void 0), this.configService = configService, this.logger = new Logger(FormBuilderDataSourceProvider.name);
|
|
140
101
|
}
|
|
141
102
|
}
|
|
142
|
-
// Override parent's static properties to have FormBuilder-specific cache
|
|
143
103
|
_define_property(FormBuilderDataSourceProvider, "tenantConnections", new Map());
|
|
144
104
|
_define_property(FormBuilderDataSourceProvider, "singleDataSource", null);
|
|
145
105
|
_define_property(FormBuilderDataSourceProvider, "tenantsRegistry", new Map());
|
|
@@ -150,12 +110,12 @@ FormBuilderDataSourceProvider = _ts_decorate([
|
|
|
150
110
|
Injectable({
|
|
151
111
|
scope: Scope.REQUEST
|
|
152
112
|
}),
|
|
153
|
-
_ts_param(0, Inject(
|
|
113
|
+
_ts_param(0, Inject(FormBuilderConfigService)),
|
|
154
114
|
_ts_param(1, Optional()),
|
|
155
115
|
_ts_param(1, Inject(REQUEST)),
|
|
156
116
|
_ts_metadata("design:type", Function),
|
|
157
117
|
_ts_metadata("design:paramtypes", [
|
|
158
|
-
typeof
|
|
118
|
+
typeof FormBuilderConfigService === "undefined" ? Object : FormBuilderConfigService,
|
|
159
119
|
typeof Request === "undefined" ? Object : Request
|
|
160
120
|
])
|
|
161
121
|
], FormBuilderDataSourceProvider);
|