@flusys/nestjs-form-builder 7.1.0 → 8.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/config/index.d.ts +3 -3
- package/controllers/form-result.controller.d.ts +3 -3
- package/controllers/form.controller.d.ts +3 -3
- package/controllers/index.d.ts +2 -2
- package/docs/form-builder-swagger.config.d.ts +2 -2
- package/docs/index.d.ts +1 -1
- package/dtos/form.dto.d.ts +1 -1
- package/dtos/index.d.ts +2 -2
- package/entities/form-with-company.entity.d.ts +1 -1
- package/entities/form.entity.d.ts +1 -1
- package/entities/index.d.ts +7 -7
- package/enums/index.d.ts +1 -1
- package/fesm/262.js +1841 -0
- package/fesm/98.js +807 -0
- package/fesm/config/index.js +98 -3
- package/fesm/controllers/index.js +14 -2
- package/fesm/docs/index.js +171 -1
- package/fesm/dtos/index.js +571 -2
- package/fesm/entities/index.js +342 -10
- package/fesm/enums/index.js +38 -1
- package/fesm/index.js +482 -10
- package/fesm/interfaces/index.js +17 -3
- package/fesm/modules/index.js +178 -1
- package/fesm/runtime.js +85 -0
- package/fesm/services/index.js +35 -4
- package/index.d.ts +10 -10
- package/interfaces/form-builder-module.interface.d.ts +3 -3
- package/interfaces/form-result.interface.d.ts +1 -1
- package/interfaces/form.interface.d.ts +2 -2
- package/interfaces/index.d.ts +3 -3
- package/modules/form-builder.module.d.ts +2 -2
- package/modules/index.d.ts +1 -1
- package/package.json +26 -36
- package/services/form-builder-config.service.d.ts +4 -4
- package/services/form-builder-datasource.provider.d.ts +3 -3
- package/services/form-result.service.d.ts +6 -6
- package/services/form.service.d.ts +7 -7
- package/services/index.d.ts +4 -4
- package/utils/index.d.ts +2 -2
- package/utils/permission.utils.d.ts +1 -1
- package/cjs/config/event-actions.js +0 -33
- package/cjs/config/form-builder.constants.js +0 -13
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -38
- package/cjs/controllers/form-result.controller.js +0 -281
- package/cjs/controllers/form-result.controller.spec.js +0 -257
- package/cjs/controllers/form.controller.js +0 -231
- package/cjs/controllers/form.controller.spec.js +0 -212
- package/cjs/controllers/index.js +0 -19
- package/cjs/docs/form-builder-swagger.config.js +0 -150
- package/cjs/docs/form-builder-swagger.config.spec.js +0 -75
- package/cjs/docs/index.js +0 -11
- package/cjs/dtos/form-result.dto.js +0 -248
- package/cjs/dtos/form.dto.js +0 -270
- package/cjs/dtos/index.js +0 -19
- package/cjs/entities/form-result.entity.js +0 -100
- package/cjs/entities/form-with-company.entity.js +0 -65
- package/cjs/entities/form.entity.js +0 -127
- package/cjs/entities/index.js +0 -52
- package/cjs/entities/index.spec.js +0 -18
- package/cjs/enums/form-access-type.enum.js +0 -19
- package/cjs/enums/index.js +0 -18
- package/cjs/index.js +0 -28
- package/cjs/interfaces/form-builder-module.interface.js +0 -4
- package/cjs/interfaces/form-result.interface.js +0 -4
- package/cjs/interfaces/form.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -20
- package/cjs/modules/form-builder.module.js +0 -136
- package/cjs/modules/form-builder.module.spec.js +0 -133
- package/cjs/modules/index.js +0 -18
- package/cjs/services/form-builder-config.service.js +0 -69
- package/cjs/services/form-builder-config.service.spec.js +0 -121
- package/cjs/services/form-builder-datasource.provider.js +0 -125
- package/cjs/services/form-builder-datasource.provider.spec.js +0 -147
- package/cjs/services/form-result.service.js +0 -366
- package/cjs/services/form-result.service.spec.js +0 -823
- package/cjs/services/form.service.js +0 -341
- package/cjs/services/form.service.spec.js +0 -746
- package/cjs/services/index.js +0 -21
- package/cjs/utils/computed-field.utils.js +0 -199
- package/cjs/utils/computed-field.utils.spec.js +0 -1205
- package/cjs/utils/index.js +0 -19
- package/cjs/utils/permission.utils.js +0 -44
- package/cjs/utils/permission.utils.spec.js +0 -118
- package/fesm/config/event-actions.js +0 -12
- package/fesm/config/form-builder.constants.js +0 -3
- package/fesm/config/message-keys.js +0 -20
- package/fesm/controllers/form-result.controller.js +0 -271
- package/fesm/controllers/form-result.controller.spec.js +0 -253
- package/fesm/controllers/form.controller.js +0 -221
- package/fesm/controllers/form.controller.spec.js +0 -208
- package/fesm/docs/form-builder-swagger.config.js +0 -146
- package/fesm/docs/form-builder-swagger.config.spec.js +0 -71
- package/fesm/dtos/form-result.dto.js +0 -215
- package/fesm/dtos/form.dto.js +0 -243
- package/fesm/entities/form-result.entity.js +0 -90
- package/fesm/entities/form-with-company.entity.js +0 -55
- package/fesm/entities/form.entity.js +0 -117
- package/fesm/entities/index.spec.js +0 -14
- package/fesm/enums/form-access-type.enum.js +0 -9
- package/fesm/interfaces/form-builder-module.interface.js +0 -3
- package/fesm/interfaces/form-result.interface.js +0 -6
- package/fesm/interfaces/form.interface.js +0 -3
- package/fesm/modules/form-builder.module.js +0 -126
- package/fesm/modules/form-builder.module.spec.js +0 -129
- package/fesm/services/form-builder-config.service.js +0 -59
- package/fesm/services/form-builder-config.service.spec.js +0 -117
- package/fesm/services/form-builder-datasource.provider.js +0 -74
- package/fesm/services/form-builder-datasource.provider.spec.js +0 -143
- package/fesm/services/form-result.service.js +0 -356
- package/fesm/services/form-result.service.spec.js +0 -778
- package/fesm/services/form.service.js +0 -331
- package/fesm/services/form.service.spec.js +0 -701
- package/fesm/utils/computed-field.utils.js +0 -195
- package/fesm/utils/computed-field.utils.spec.js +0 -1201
- package/fesm/utils/index.js +0 -2
- package/fesm/utils/permission.utils.js +0 -42
- package/fesm/utils/permission.utils.spec.js +0 -114
|
@@ -1,90 +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
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { getJsonColumnType, Identity } from '@flusys/nestjs-shared';
|
|
24
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
25
|
-
export class FormResult extends Identity {
|
|
26
|
-
constructor(...args){
|
|
27
|
-
super(...args), _define_property(this, "formId", void 0), _define_property(this, "schemaVersionSnapshot", void 0), _define_property(this, "schemaVersion", void 0), _define_property(this, "data", void 0), _define_property(this, "submittedById", void 0), _define_property(this, "submittedAt", void 0), _define_property(this, "isDraft", void 0);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_ts_decorate([
|
|
31
|
-
Index(),
|
|
32
|
-
Column({
|
|
33
|
-
type: 'uuid',
|
|
34
|
-
nullable: false,
|
|
35
|
-
name: 'form_id'
|
|
36
|
-
}),
|
|
37
|
-
_ts_metadata("design:type", String)
|
|
38
|
-
], FormResult.prototype, "formId", void 0);
|
|
39
|
-
_ts_decorate([
|
|
40
|
-
Column({
|
|
41
|
-
type: getJsonColumnType(),
|
|
42
|
-
nullable: false,
|
|
43
|
-
name: 'schema_version_snapshot'
|
|
44
|
-
}),
|
|
45
|
-
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
46
|
-
], FormResult.prototype, "schemaVersionSnapshot", void 0);
|
|
47
|
-
_ts_decorate([
|
|
48
|
-
Column({
|
|
49
|
-
type: 'int',
|
|
50
|
-
nullable: false,
|
|
51
|
-
name: 'schema_version'
|
|
52
|
-
}),
|
|
53
|
-
_ts_metadata("design:type", Number)
|
|
54
|
-
], FormResult.prototype, "schemaVersion", void 0);
|
|
55
|
-
_ts_decorate([
|
|
56
|
-
Column({
|
|
57
|
-
type: getJsonColumnType(),
|
|
58
|
-
nullable: false
|
|
59
|
-
}),
|
|
60
|
-
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
61
|
-
], FormResult.prototype, "data", void 0);
|
|
62
|
-
_ts_decorate([
|
|
63
|
-
Column({
|
|
64
|
-
type: 'uuid',
|
|
65
|
-
nullable: true,
|
|
66
|
-
name: 'submitted_by_id'
|
|
67
|
-
}),
|
|
68
|
-
_ts_metadata("design:type", Object)
|
|
69
|
-
], FormResult.prototype, "submittedById", void 0);
|
|
70
|
-
_ts_decorate([
|
|
71
|
-
Column({
|
|
72
|
-
type: 'timestamp',
|
|
73
|
-
nullable: false,
|
|
74
|
-
name: 'submitted_at'
|
|
75
|
-
}),
|
|
76
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
77
|
-
], FormResult.prototype, "submittedAt", void 0);
|
|
78
|
-
_ts_decorate([
|
|
79
|
-
Column({
|
|
80
|
-
type: 'boolean',
|
|
81
|
-
default: false,
|
|
82
|
-
name: 'is_draft'
|
|
83
|
-
}),
|
|
84
|
-
_ts_metadata("design:type", Boolean)
|
|
85
|
-
], FormResult.prototype, "isDraft", void 0);
|
|
86
|
-
FormResult = _ts_decorate([
|
|
87
|
-
Entity({
|
|
88
|
-
name: 'form_result'
|
|
89
|
-
})
|
|
90
|
-
], FormResult);
|
|
@@ -1,55 +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
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
24
|
-
import { Form } from './form.entity';
|
|
25
|
-
export class FormWithCompany extends Form {
|
|
26
|
-
constructor(...args){
|
|
27
|
-
super(...args), _define_property(this, "companyId", void 0);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_ts_decorate([
|
|
31
|
-
Column({
|
|
32
|
-
type: 'uuid',
|
|
33
|
-
nullable: true,
|
|
34
|
-
name: 'company_id'
|
|
35
|
-
}),
|
|
36
|
-
_ts_metadata("design:type", Object)
|
|
37
|
-
], FormWithCompany.prototype, "companyId", void 0);
|
|
38
|
-
FormWithCompany = _ts_decorate([
|
|
39
|
-
Entity({
|
|
40
|
-
name: 'form'
|
|
41
|
-
}),
|
|
42
|
-
Index([
|
|
43
|
-
'companyId'
|
|
44
|
-
]),
|
|
45
|
-
Index([
|
|
46
|
-
'companyId',
|
|
47
|
-
'slug'
|
|
48
|
-
], {
|
|
49
|
-
unique: true
|
|
50
|
-
}),
|
|
51
|
-
Index([
|
|
52
|
-
'companyId',
|
|
53
|
-
'isActive'
|
|
54
|
-
])
|
|
55
|
-
], FormWithCompany);
|
|
@@ -1,117 +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
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { getJsonColumnType } from '@flusys/nestjs-shared';
|
|
24
|
-
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
25
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
26
|
-
import { FormAccessType } from '../enums/form-access-type.enum';
|
|
27
|
-
export class Form extends Identity {
|
|
28
|
-
constructor(...args){
|
|
29
|
-
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, "tags", void 0), _define_property(this, "isActive", void 0);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
_ts_decorate([
|
|
33
|
-
Column({
|
|
34
|
-
type: 'varchar',
|
|
35
|
-
length: 255,
|
|
36
|
-
nullable: false
|
|
37
|
-
}),
|
|
38
|
-
_ts_metadata("design:type", String)
|
|
39
|
-
], Form.prototype, "name", void 0);
|
|
40
|
-
_ts_decorate([
|
|
41
|
-
Column({
|
|
42
|
-
type: 'varchar',
|
|
43
|
-
length: 500,
|
|
44
|
-
nullable: true
|
|
45
|
-
}),
|
|
46
|
-
_ts_metadata("design:type", Object)
|
|
47
|
-
], Form.prototype, "description", void 0);
|
|
48
|
-
_ts_decorate([
|
|
49
|
-
Column({
|
|
50
|
-
type: 'varchar',
|
|
51
|
-
length: 255,
|
|
52
|
-
nullable: true
|
|
53
|
-
}),
|
|
54
|
-
_ts_metadata("design:type", Object)
|
|
55
|
-
], Form.prototype, "slug", void 0);
|
|
56
|
-
_ts_decorate([
|
|
57
|
-
Column({
|
|
58
|
-
type: getJsonColumnType(),
|
|
59
|
-
nullable: false
|
|
60
|
-
}),
|
|
61
|
-
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
62
|
-
], Form.prototype, "schema", void 0);
|
|
63
|
-
_ts_decorate([
|
|
64
|
-
Column({
|
|
65
|
-
type: 'int',
|
|
66
|
-
nullable: false,
|
|
67
|
-
default: 1,
|
|
68
|
-
name: 'schema_version'
|
|
69
|
-
}),
|
|
70
|
-
_ts_metadata("design:type", Number)
|
|
71
|
-
], Form.prototype, "schemaVersion", void 0);
|
|
72
|
-
_ts_decorate([
|
|
73
|
-
Column({
|
|
74
|
-
type: 'varchar',
|
|
75
|
-
length: 50,
|
|
76
|
-
default: 'AUTHENTICATED',
|
|
77
|
-
name: 'access_type'
|
|
78
|
-
}),
|
|
79
|
-
_ts_metadata("design:type", typeof FormAccessType === "undefined" ? Object : FormAccessType)
|
|
80
|
-
], Form.prototype, "accessType", void 0);
|
|
81
|
-
_ts_decorate([
|
|
82
|
-
Column({
|
|
83
|
-
type: getJsonColumnType(),
|
|
84
|
-
nullable: true,
|
|
85
|
-
name: 'action_groups'
|
|
86
|
-
}),
|
|
87
|
-
_ts_metadata("design:type", Object)
|
|
88
|
-
], Form.prototype, "actionGroups", void 0);
|
|
89
|
-
_ts_decorate([
|
|
90
|
-
Column({
|
|
91
|
-
type: getJsonColumnType(),
|
|
92
|
-
nullable: true
|
|
93
|
-
}),
|
|
94
|
-
_ts_metadata("design:type", Object)
|
|
95
|
-
], Form.prototype, "tags", void 0);
|
|
96
|
-
_ts_decorate([
|
|
97
|
-
Column({
|
|
98
|
-
type: 'boolean',
|
|
99
|
-
nullable: false,
|
|
100
|
-
default: true,
|
|
101
|
-
name: 'is_active'
|
|
102
|
-
}),
|
|
103
|
-
_ts_metadata("design:type", Boolean)
|
|
104
|
-
], Form.prototype, "isActive", void 0);
|
|
105
|
-
Form = _ts_decorate([
|
|
106
|
-
Entity({
|
|
107
|
-
name: 'form'
|
|
108
|
-
}),
|
|
109
|
-
Index([
|
|
110
|
-
'slug'
|
|
111
|
-
], {
|
|
112
|
-
unique: true
|
|
113
|
-
}),
|
|
114
|
-
Index([
|
|
115
|
-
'isActive'
|
|
116
|
-
])
|
|
117
|
-
], Form);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { getFormBuilderEntitiesByConfig, FormCoreEntities, FormCompanyEntities } from './index';
|
|
2
|
-
import { FormResult } from './form-result.entity';
|
|
3
|
-
describe('getFormBuilderEntitiesByConfig', ()=>{
|
|
4
|
-
it('returns the core entities when the company feature is disabled', ()=>{
|
|
5
|
-
expect(getFormBuilderEntitiesByConfig(false)).toBe(FormCoreEntities);
|
|
6
|
-
});
|
|
7
|
-
it('returns the company-scoped entities when the company feature is enabled', ()=>{
|
|
8
|
-
expect(getFormBuilderEntitiesByConfig(true)).toBe(FormCompanyEntities);
|
|
9
|
-
});
|
|
10
|
-
it('FormResult is shared between core and company entity sets (not company-scoped)', ()=>{
|
|
11
|
-
expect(getFormBuilderEntitiesByConfig(false)).toContain(FormResult);
|
|
12
|
-
expect(getFormBuilderEntitiesByConfig(true)).toContain(FormResult);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Form Access Type Enum
|
|
3
|
-
* Defines who can submit the form
|
|
4
|
-
*/ export var FormAccessType = /*#__PURE__*/ function(FormAccessType) {
|
|
5
|
-
/** No authentication required - anyone can submit */ FormAccessType["PUBLIC"] = "public";
|
|
6
|
-
/** Any authenticated user can submit */ FormAccessType["AUTHENTICATED"] = "authenticated";
|
|
7
|
-
/** Only users with specific action permissions can submit */ FormAccessType["ACTION_GROUP"] = "action_group";
|
|
8
|
-
return FormAccessType;
|
|
9
|
-
}({});
|
|
@@ -1,126 +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 { CacheModule, UtilsModule, createModuleEventsProvider } from '@flusys/nestjs-shared/modules';
|
|
21
|
-
import { Module } from '@nestjs/common';
|
|
22
|
-
import { FORM_BUILDER_MODULE_OPTIONS } from '../config/form-builder.constants';
|
|
23
|
-
import { FormController, FormResultController } from '../controllers';
|
|
24
|
-
import { FormBuilderConfigService, FormBuilderDataSourceProvider, FormService, FormResultService } from '../services';
|
|
25
|
-
export class FormBuilderModule {
|
|
26
|
-
/**
|
|
27
|
-
* Register FormBuilderModule synchronously
|
|
28
|
-
*/ static forRoot(options) {
|
|
29
|
-
return {
|
|
30
|
-
module: FormBuilderModule,
|
|
31
|
-
global: options.global ?? false,
|
|
32
|
-
imports: [
|
|
33
|
-
CacheModule,
|
|
34
|
-
UtilsModule
|
|
35
|
-
],
|
|
36
|
-
controllers: options.includeController !== false ? this.CONTROLLERS : [],
|
|
37
|
-
providers: this.buildProviders(options),
|
|
38
|
-
exports: this.EXPORTS
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Register FormBuilderModule asynchronously
|
|
43
|
-
*/ static forRootAsync(options) {
|
|
44
|
-
return {
|
|
45
|
-
module: FormBuilderModule,
|
|
46
|
-
global: options.global ?? false,
|
|
47
|
-
imports: [
|
|
48
|
-
...options.imports || [],
|
|
49
|
-
CacheModule,
|
|
50
|
-
UtilsModule
|
|
51
|
-
],
|
|
52
|
-
controllers: options.includeController !== false ? this.CONTROLLERS : [],
|
|
53
|
-
providers: [
|
|
54
|
-
...this.buildAsyncProviders(options),
|
|
55
|
-
...this.buildProviders()
|
|
56
|
-
],
|
|
57
|
-
exports: this.EXPORTS
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
static buildProviders(options) {
|
|
61
|
-
const providers = [
|
|
62
|
-
FormBuilderConfigService,
|
|
63
|
-
FormBuilderDataSourceProvider,
|
|
64
|
-
FormService,
|
|
65
|
-
FormResultService
|
|
66
|
-
];
|
|
67
|
-
if (options) {
|
|
68
|
-
providers.unshift({
|
|
69
|
-
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
70
|
-
useValue: options
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
providers.push(createModuleEventsProvider('form-builder', FORM_BUILDER_MODULE_OPTIONS));
|
|
74
|
-
return providers;
|
|
75
|
-
}
|
|
76
|
-
static buildAsyncProviders(options) {
|
|
77
|
-
if (options.useFactory) {
|
|
78
|
-
return [
|
|
79
|
-
{
|
|
80
|
-
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
81
|
-
useFactory: async (...args)=>({
|
|
82
|
-
...options,
|
|
83
|
-
config: await options.useFactory(...args)
|
|
84
|
-
}),
|
|
85
|
-
inject: options.inject || []
|
|
86
|
-
}
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
|
-
const factoryClass = options.useClass || options.useExisting;
|
|
90
|
-
if (!factoryClass) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
const providers = [
|
|
94
|
-
{
|
|
95
|
-
provide: FORM_BUILDER_MODULE_OPTIONS,
|
|
96
|
-
useFactory: async (factory)=>({
|
|
97
|
-
...options,
|
|
98
|
-
config: await factory.createFormBuilderOptions()
|
|
99
|
-
}),
|
|
100
|
-
inject: [
|
|
101
|
-
factoryClass
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
];
|
|
105
|
-
if (options.useClass) {
|
|
106
|
-
providers.push({
|
|
107
|
-
provide: options.useClass,
|
|
108
|
-
useClass: options.useClass
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return providers;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
_define_property(FormBuilderModule, "CONTROLLERS", [
|
|
115
|
-
FormController,
|
|
116
|
-
FormResultController
|
|
117
|
-
]);
|
|
118
|
-
_define_property(FormBuilderModule, "EXPORTS", [
|
|
119
|
-
FormBuilderConfigService,
|
|
120
|
-
FormBuilderDataSourceProvider,
|
|
121
|
-
FormService,
|
|
122
|
-
FormResultService
|
|
123
|
-
]);
|
|
124
|
-
FormBuilderModule = _ts_decorate([
|
|
125
|
-
Module({})
|
|
126
|
-
], FormBuilderModule);
|
|
@@ -1,129 +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
|
-
import { FormBuilderModule } from './form-builder.module';
|
|
15
|
-
import { FORM_BUILDER_MODULE_OPTIONS } from '../config/form-builder.constants';
|
|
16
|
-
import { FormController, FormResultController } from '../controllers';
|
|
17
|
-
function providerTokens(providers) {
|
|
18
|
-
return providers.map((p)=>typeof p === 'function' ? p : p.provide);
|
|
19
|
-
}
|
|
20
|
-
describe('FormBuilderModule', ()=>{
|
|
21
|
-
describe('forRoot', ()=>{
|
|
22
|
-
it('should default to a non-global module with all controllers registered', ()=>{
|
|
23
|
-
const dynamicModule = FormBuilderModule.forRoot({});
|
|
24
|
-
expect(dynamicModule.module).toBe(FormBuilderModule);
|
|
25
|
-
expect(dynamicModule.global).toBe(false);
|
|
26
|
-
expect(dynamicModule.controllers).toEqual([
|
|
27
|
-
FormController,
|
|
28
|
-
FormResultController
|
|
29
|
-
]);
|
|
30
|
-
});
|
|
31
|
-
it('should respect global: true', ()=>{
|
|
32
|
-
expect(FormBuilderModule.forRoot({
|
|
33
|
-
global: true
|
|
34
|
-
}).global).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
it('should register no controllers when includeController is false', ()=>{
|
|
37
|
-
expect(FormBuilderModule.forRoot({
|
|
38
|
-
includeController: false
|
|
39
|
-
}).controllers).toEqual([]);
|
|
40
|
-
});
|
|
41
|
-
it('should register a FORM_BUILDER_MODULE_OPTIONS provider carrying the given options', ()=>{
|
|
42
|
-
const options = {
|
|
43
|
-
bootstrapAppConfig: {
|
|
44
|
-
enableCompanyFeature: true
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const dynamicModule = FormBuilderModule.forRoot(options);
|
|
48
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === FORM_BUILDER_MODULE_OPTIONS);
|
|
49
|
-
expect(provider.useValue).toBe(options);
|
|
50
|
-
});
|
|
51
|
-
it('should always export the same fixed set of services', ()=>{
|
|
52
|
-
expect(FormBuilderModule.forRoot({}).exports).toHaveLength(4);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe('forRootAsync', ()=>{
|
|
56
|
-
it('should forward external imports alongside CacheModule/UtilsModule', ()=>{
|
|
57
|
-
let FakeImportedModule = class FakeImportedModule {
|
|
58
|
-
};
|
|
59
|
-
const dynamicModule = FormBuilderModule.forRootAsync({
|
|
60
|
-
imports: [
|
|
61
|
-
FakeImportedModule
|
|
62
|
-
]
|
|
63
|
-
});
|
|
64
|
-
expect(dynamicModule.imports).toEqual(expect.arrayContaining([
|
|
65
|
-
FakeImportedModule
|
|
66
|
-
]));
|
|
67
|
-
});
|
|
68
|
-
it('useFactory: builds a FORM_BUILDER_MODULE_OPTIONS provider merging resolved config', async ()=>{
|
|
69
|
-
const useFactory = jest.fn().mockResolvedValue({
|
|
70
|
-
foo: 'bar'
|
|
71
|
-
});
|
|
72
|
-
const dynamicModule = FormBuilderModule.forRootAsync({
|
|
73
|
-
useFactory,
|
|
74
|
-
inject: [
|
|
75
|
-
'SOME_TOKEN'
|
|
76
|
-
]
|
|
77
|
-
});
|
|
78
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === FORM_BUILDER_MODULE_OPTIONS);
|
|
79
|
-
expect(provider.inject).toEqual([
|
|
80
|
-
'SOME_TOKEN'
|
|
81
|
-
]);
|
|
82
|
-
const resolved = await provider.useFactory('injected');
|
|
83
|
-
expect(useFactory).toHaveBeenCalledWith('injected');
|
|
84
|
-
expect(resolved.config).toEqual({
|
|
85
|
-
foo: 'bar'
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
it('useClass: registers both the class provider and an options provider calling createFormBuilderOptions()', async ()=>{
|
|
89
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
90
|
-
constructor(){
|
|
91
|
-
_define_property(this, "createFormBuilderOptions", jest.fn().mockResolvedValue({
|
|
92
|
-
foo: 'from-class'
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const dynamicModule = FormBuilderModule.forRootAsync({
|
|
97
|
-
useClass: MyOptionsFactory
|
|
98
|
-
});
|
|
99
|
-
const classProvider = dynamicModule.providers.find((p)=>p.provide === MyOptionsFactory);
|
|
100
|
-
expect(classProvider.useClass).toBe(MyOptionsFactory);
|
|
101
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === FORM_BUILDER_MODULE_OPTIONS);
|
|
102
|
-
const instance = new MyOptionsFactory();
|
|
103
|
-
const resolved = await optionsProvider.useFactory(instance);
|
|
104
|
-
expect(instance.createFormBuilderOptions).toHaveBeenCalled();
|
|
105
|
-
expect(resolved.config).toEqual({
|
|
106
|
-
foo: 'from-class'
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
it('useExisting: registers a single options provider without a duplicate class registration', ()=>{
|
|
110
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
111
|
-
constructor(){
|
|
112
|
-
_define_property(this, "createFormBuilderOptions", jest.fn());
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
const dynamicModule = FormBuilderModule.forRootAsync({
|
|
116
|
-
useExisting: MyOptionsFactory
|
|
117
|
-
});
|
|
118
|
-
expect(dynamicModule.providers.filter((p)=>p.provide === MyOptionsFactory)).toHaveLength(0);
|
|
119
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === FORM_BUILDER_MODULE_OPTIONS);
|
|
120
|
-
expect(optionsProvider.inject).toEqual([
|
|
121
|
-
MyOptionsFactory
|
|
122
|
-
]);
|
|
123
|
-
});
|
|
124
|
-
it('should register no FORM_BUILDER_MODULE_OPTIONS provider when neither useFactory, useClass, nor useExisting is given', ()=>{
|
|
125
|
-
const dynamicModule = FormBuilderModule.forRootAsync({});
|
|
126
|
-
expect(providerTokens(dynamicModule.providers)).not.toContain(FORM_BUILDER_MODULE_OPTIONS);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,59 +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
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { Injectable, Inject } from '@nestjs/common';
|
|
29
|
-
import { FORM_BUILDER_MODULE_OPTIONS } from '../config/form-builder.constants';
|
|
30
|
-
import { FormBuilderModuleOptions } from '../interfaces/form-builder-module.interface';
|
|
31
|
-
export class FormBuilderConfigService {
|
|
32
|
-
isCompanyFeatureEnabled(tenant) {
|
|
33
|
-
return tenant?.enableCompanyFeature ?? this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
34
|
-
}
|
|
35
|
-
getDatabaseMode() {
|
|
36
|
-
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
37
|
-
}
|
|
38
|
-
isMultiTenant() {
|
|
39
|
-
return this.getDatabaseMode() === 'multi-tenant';
|
|
40
|
-
}
|
|
41
|
-
getOptions() {
|
|
42
|
-
return this.options;
|
|
43
|
-
}
|
|
44
|
-
getConfig() {
|
|
45
|
-
return this.options.config;
|
|
46
|
-
}
|
|
47
|
-
constructor(options){
|
|
48
|
-
_define_property(this, "options", void 0);
|
|
49
|
-
this.options = options;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
FormBuilderConfigService = _ts_decorate([
|
|
53
|
-
Injectable(),
|
|
54
|
-
_ts_param(0, Inject(FORM_BUILDER_MODULE_OPTIONS)),
|
|
55
|
-
_ts_metadata("design:type", Function),
|
|
56
|
-
_ts_metadata("design:paramtypes", [
|
|
57
|
-
typeof FormBuilderModuleOptions === "undefined" ? Object : FormBuilderModuleOptions
|
|
58
|
-
])
|
|
59
|
-
], FormBuilderConfigService);
|