@tsed/formio 8.11.1 → 8.12.0-rc.1
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/lib/esm/FormioModule.js +0 -1
- package/lib/esm/builder/FormioMapper.js +0 -1
- package/lib/esm/components/AlterActions.js +0 -1
- package/lib/esm/components/AlterAudit.js +0 -1
- package/lib/esm/components/AlterHost.js +0 -1
- package/lib/esm/components/AlterLog.js +0 -1
- package/lib/esm/components/AlterSkip.js +0 -1
- package/lib/esm/components/AlterTemplateExportSteps.js +0 -1
- package/lib/esm/components/AlterTemplateImportSteps.js +0 -1
- package/lib/esm/decorators/action.js +0 -1
- package/lib/esm/decorators/actionCtx.js +0 -1
- package/lib/esm/decorators/alter.js +0 -1
- package/lib/esm/decorators/on.js +0 -1
- package/lib/esm/decorators/useFormioAuth.js +0 -1
- package/lib/esm/domain/AlterHook.js +0 -1
- package/lib/esm/domain/Formio.js +0 -1
- package/lib/esm/domain/FormioAction.js +0 -1
- package/lib/esm/domain/FormioActionsIndex.js +0 -1
- package/lib/esm/domain/FormioAuth.js +0 -1
- package/lib/esm/domain/FormioBaseModel.js +0 -1
- package/lib/esm/domain/FormioConfig.js +0 -1
- package/lib/esm/domain/FormioCtxMapper.js +0 -1
- package/lib/esm/domain/FormioDecodedToken.js +0 -1
- package/lib/esm/domain/FormioErrors.js +0 -1
- package/lib/esm/domain/FormioHooks.js +0 -1
- package/lib/esm/domain/FormioJs.js +0 -1
- package/lib/esm/domain/FormioModels.js +0 -1
- package/lib/esm/domain/FormioRouter.js +0 -1
- package/lib/esm/domain/FormioSettings.js +0 -1
- package/lib/esm/domain/FormioTemplate.js +0 -1
- package/lib/esm/domain/FormioTemplateUtil.js +0 -1
- package/lib/esm/domain/FormioUpdate.js +0 -1
- package/lib/esm/domain/FormioUtils.js +0 -1
- package/lib/esm/domain/OnHook.js +0 -1
- package/lib/esm/domain/Resource.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js +0 -1
- package/lib/esm/services/FormioAuthService.js +0 -1
- package/lib/esm/services/FormioDatabase.js +0 -1
- package/lib/esm/services/FormioHooksService.js +0 -1
- package/lib/esm/services/FormioInstaller.js +0 -1
- package/lib/esm/services/FormioRepository.js +0 -1
- package/lib/esm/services/FormioService.js +0 -1
- package/lib/esm/utils/isMongoId.js +0 -1
- package/package.json +13 -10
- package/lib/esm/FormioModule.js.map +0 -1
- package/lib/esm/builder/FormioMapper.js.map +0 -1
- package/lib/esm/components/AlterActions.js.map +0 -1
- package/lib/esm/components/AlterAudit.js.map +0 -1
- package/lib/esm/components/AlterHost.js.map +0 -1
- package/lib/esm/components/AlterLog.js.map +0 -1
- package/lib/esm/components/AlterSkip.js.map +0 -1
- package/lib/esm/components/AlterTemplateExportSteps.js.map +0 -1
- package/lib/esm/components/AlterTemplateImportSteps.js.map +0 -1
- package/lib/esm/decorators/action.js.map +0 -1
- package/lib/esm/decorators/actionCtx.js.map +0 -1
- package/lib/esm/decorators/alter.js.map +0 -1
- package/lib/esm/decorators/on.js.map +0 -1
- package/lib/esm/decorators/useFormioAuth.js.map +0 -1
- package/lib/esm/domain/AlterHook.js.map +0 -1
- package/lib/esm/domain/Formio.js.map +0 -1
- package/lib/esm/domain/FormioAction.js.map +0 -1
- package/lib/esm/domain/FormioActionsIndex.js.map +0 -1
- package/lib/esm/domain/FormioAuth.js.map +0 -1
- package/lib/esm/domain/FormioBaseModel.js.map +0 -1
- package/lib/esm/domain/FormioConfig.js.map +0 -1
- package/lib/esm/domain/FormioCtxMapper.js.map +0 -1
- package/lib/esm/domain/FormioDecodedToken.js.map +0 -1
- package/lib/esm/domain/FormioErrors.js.map +0 -1
- package/lib/esm/domain/FormioHooks.js.map +0 -1
- package/lib/esm/domain/FormioJs.js.map +0 -1
- package/lib/esm/domain/FormioModels.js.map +0 -1
- package/lib/esm/domain/FormioRouter.js.map +0 -1
- package/lib/esm/domain/FormioSettings.js.map +0 -1
- package/lib/esm/domain/FormioTemplate.js.map +0 -1
- package/lib/esm/domain/FormioTemplateUtil.js.map +0 -1
- package/lib/esm/domain/FormioUpdate.js.map +0 -1
- package/lib/esm/domain/FormioUtils.js.map +0 -1
- package/lib/esm/domain/OnHook.js.map +0 -1
- package/lib/esm/domain/Resource.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js.map +0 -1
- package/lib/esm/services/FormioAuthService.js.map +0 -1
- package/lib/esm/services/FormioDatabase.js.map +0 -1
- package/lib/esm/services/FormioHooksService.js.map +0 -1
- package/lib/esm/services/FormioInstaller.js.map +0 -1
- package/lib/esm/services/FormioRepository.js.map +0 -1
- package/lib/esm/services/FormioService.js.map +0 -1
- package/lib/esm/utils/isMongoId.js.map +0 -1
- package/src/FormioModule.spec.ts +0 -113
- package/src/FormioModule.ts +0 -130
- package/src/builder/FormioMapper.spec.ts +0 -93
- package/src/builder/FormioMapper.ts +0 -71
- package/src/components/AlterActions.spec.ts +0 -376
- package/src/components/AlterActions.ts +0 -136
- package/src/components/AlterAudit.spec.ts +0 -19
- package/src/components/AlterAudit.ts +0 -12
- package/src/components/AlterHost.spec.ts +0 -20
- package/src/components/AlterHost.ts +0 -11
- package/src/components/AlterLog.spec.ts +0 -19
- package/src/components/AlterLog.ts +0 -12
- package/src/components/AlterSkip.spec.ts +0 -44
- package/src/components/AlterSkip.ts +0 -28
- package/src/components/AlterTemplateExportSteps.spec.ts +0 -99
- package/src/components/AlterTemplateExportSteps.ts +0 -58
- package/src/components/AlterTemplateImportSteps.spec.ts +0 -70
- package/src/components/AlterTemplateImportSteps.ts +0 -50
- package/src/decorators/action.ts +0 -20
- package/src/decorators/actionCtx.spec.ts +0 -25
- package/src/decorators/actionCtx.ts +0 -29
- package/src/decorators/alter.spec.ts +0 -16
- package/src/decorators/alter.ts +0 -19
- package/src/decorators/on.spec.ts +0 -16
- package/src/decorators/on.ts +0 -19
- package/src/decorators/useFormioAuth.spec.ts +0 -15
- package/src/decorators/useFormioAuth.ts +0 -12
- package/src/domain/AlterHook.ts +0 -3
- package/src/domain/Formio.ts +0 -122
- package/src/domain/FormioAction.ts +0 -30
- package/src/domain/FormioActionsIndex.ts +0 -19
- package/src/domain/FormioAuth.ts +0 -83
- package/src/domain/FormioBaseModel.ts +0 -14
- package/src/domain/FormioConfig.ts +0 -63
- package/src/domain/FormioCtxMapper.ts +0 -8
- package/src/domain/FormioDecodedToken.ts +0 -13
- package/src/domain/FormioErrors.ts +0 -53
- package/src/domain/FormioHooks.ts +0 -207
- package/src/domain/FormioJs.ts +0 -18
- package/src/domain/FormioModels.ts +0 -48
- package/src/domain/FormioRouter.ts +0 -10
- package/src/domain/FormioSettings.ts +0 -61
- package/src/domain/FormioTemplate.ts +0 -9
- package/src/domain/FormioTemplateUtil.ts +0 -15
- package/src/domain/FormioUpdate.ts +0 -23
- package/src/domain/FormioUtils.ts +0 -331
- package/src/domain/OnHook.ts +0 -3
- package/src/domain/Resource.ts +0 -21
- package/src/index.ts +0 -46
- package/src/middlewares/FormioAuthMiddleware.spec.ts +0 -61
- package/src/middlewares/FormioAuthMiddleware.ts +0 -34
- package/src/services/FormioAuthService.spec.ts +0 -396
- package/src/services/FormioAuthService.ts +0 -228
- package/src/services/FormioDatabase.spec.ts +0 -326
- package/src/services/FormioDatabase.ts +0 -165
- package/src/services/FormioHooksService.spec.ts +0 -156
- package/src/services/FormioHooksService.ts +0 -92
- package/src/services/FormioInstaller.spec.ts +0 -146
- package/src/services/FormioInstaller.ts +0 -46
- package/src/services/FormioRepository.spec.ts +0 -114
- package/src/services/FormioRepository.ts +0 -49
- package/src/services/FormioService.spec.ts +0 -368
- package/src/services/FormioService.ts +0 -134
- package/src/utils/isMongoId.ts +0 -3
- package/vitest.config.mts +0 -21
package/src/FormioModule.spec.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {faker} from "@faker-js/faker";
|
|
2
|
-
import {PlatformApplication, PlatformRouteDetails} from "@tsed/platform-http";
|
|
3
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
4
|
-
|
|
5
|
-
import {FormioModule} from "./FormioModule.js";
|
|
6
|
-
import {FormioInstaller} from "./services/FormioInstaller.js";
|
|
7
|
-
import {FormioService} from "./services/FormioService.js";
|
|
8
|
-
|
|
9
|
-
async function createFormioModuleFixture() {
|
|
10
|
-
const formio = {
|
|
11
|
-
swagger: vi.fn(),
|
|
12
|
-
router: vi.fn(),
|
|
13
|
-
middleware: {
|
|
14
|
-
restrictRequestTypes: vi.fn()
|
|
15
|
-
},
|
|
16
|
-
isInit: vi.fn().mockReturnValue(true),
|
|
17
|
-
init: vi.fn()
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const installer = {
|
|
21
|
-
hasForms: vi.fn().mockReturnValue(false),
|
|
22
|
-
install: vi.fn()
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const app = {
|
|
26
|
-
use: vi.fn(),
|
|
27
|
-
getRouter: vi.fn().mockReturnThis()
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const service = await PlatformTest.invoke<FormioModule>(FormioModule, [
|
|
31
|
-
{
|
|
32
|
-
token: FormioInstaller,
|
|
33
|
-
use: installer
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
token: FormioService,
|
|
37
|
-
use: formio
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
token: PlatformApplication,
|
|
41
|
-
use: app
|
|
42
|
-
}
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
return {service, app, installer, formio};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
describe("FormioModule", () => {
|
|
49
|
-
beforeEach(() => PlatformTest.create());
|
|
50
|
-
afterEach(PlatformTest.reset);
|
|
51
|
-
|
|
52
|
-
describe("$onRoutesInit()", () => {
|
|
53
|
-
it("should run install template", async () => {
|
|
54
|
-
const {service, app, installer, formio} = await createFormioModuleFixture();
|
|
55
|
-
|
|
56
|
-
const template = {
|
|
57
|
-
forms: {}
|
|
58
|
-
};
|
|
59
|
-
const root = {
|
|
60
|
-
email: faker.internet.email()
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
PlatformTest.injector.settings.set("formio.template", template);
|
|
64
|
-
PlatformTest.injector.settings.set("formio.root", root);
|
|
65
|
-
|
|
66
|
-
installer.install.mockResolvedValue((service as any).template);
|
|
67
|
-
|
|
68
|
-
await service.$onRoutesInit();
|
|
69
|
-
|
|
70
|
-
expect(app.use).toHaveBeenCalledWith("/", formio.middleware.restrictRequestTypes, formio.router);
|
|
71
|
-
expect(installer.install).toHaveBeenCalledWith(template, root);
|
|
72
|
-
});
|
|
73
|
-
it("should skip install", async () => {
|
|
74
|
-
const {service, installer} = await createFormioModuleFixture();
|
|
75
|
-
PlatformTest.injector.settings.set("formio.template", {});
|
|
76
|
-
|
|
77
|
-
await service.$onRoutesInit();
|
|
78
|
-
|
|
79
|
-
expect(installer.install).toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe("$logRoutes()", () => {
|
|
83
|
-
it("should add formio routes", async () => {
|
|
84
|
-
const {service, formio} = await createFormioModuleFixture();
|
|
85
|
-
const routes: PlatformRouteDetails[] = [];
|
|
86
|
-
|
|
87
|
-
PlatformTest.injector.settings.set("formio.baseUrl", "/projects");
|
|
88
|
-
PlatformTest.injector.settings.set("formio.root");
|
|
89
|
-
|
|
90
|
-
formio.swagger.mockReturnValue({
|
|
91
|
-
paths: {
|
|
92
|
-
"/path/to": {
|
|
93
|
-
get: {
|
|
94
|
-
operationId: "operationId"
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const results = await service.$logRoutes(routes);
|
|
101
|
-
|
|
102
|
-
expect(results).toEqual([
|
|
103
|
-
{
|
|
104
|
-
className: "formio",
|
|
105
|
-
method: "get",
|
|
106
|
-
methodClassName: "operationId",
|
|
107
|
-
name: "operationId",
|
|
108
|
-
url: "/projects/path/to"
|
|
109
|
-
}
|
|
110
|
-
]);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
package/src/FormioModule.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {deepClone} from "@tsed/core";
|
|
2
|
-
import {Constant, Inject, InjectorService, Module} from "@tsed/di";
|
|
3
|
-
import {normalizePath} from "@tsed/normalize-path";
|
|
4
|
-
import {OnReady, OnRoutesInit, PlatformApplication, PlatformRouteDetails} from "@tsed/platform-http";
|
|
5
|
-
|
|
6
|
-
import {AlterActions} from "./components/AlterActions.js";
|
|
7
|
-
import {AlterAudit} from "./components/AlterAudit.js";
|
|
8
|
-
import {AlterHost} from "./components/AlterHost.js";
|
|
9
|
-
import {AlterLog} from "./components/AlterLog.js";
|
|
10
|
-
import {AlterSkip} from "./components/AlterSkip.js";
|
|
11
|
-
import {AlterTemplateExportSteps} from "./components/AlterTemplateExportSteps.js";
|
|
12
|
-
import {AlterTemplateImportSteps} from "./components/AlterTemplateImportSteps.js";
|
|
13
|
-
import {FormioConfig} from "./domain/FormioConfig.js";
|
|
14
|
-
import {FormioTemplate} from "./domain/FormioTemplate.js";
|
|
15
|
-
import {FormioAuthService} from "./services/FormioAuthService.js";
|
|
16
|
-
import {FormioHooksService} from "./services/FormioHooksService.js";
|
|
17
|
-
import {FormioInstaller} from "./services/FormioInstaller.js";
|
|
18
|
-
import {FormioService} from "./services/FormioService.js";
|
|
19
|
-
|
|
20
|
-
@Module({
|
|
21
|
-
imports: [
|
|
22
|
-
FormioService,
|
|
23
|
-
FormioHooksService,
|
|
24
|
-
FormioAuthService,
|
|
25
|
-
AlterActions,
|
|
26
|
-
AlterHost,
|
|
27
|
-
AlterAudit,
|
|
28
|
-
AlterLog,
|
|
29
|
-
AlterSkip,
|
|
30
|
-
AlterTemplateImportSteps,
|
|
31
|
-
AlterTemplateExportSteps
|
|
32
|
-
]
|
|
33
|
-
})
|
|
34
|
-
export class FormioModule implements OnRoutesInit, OnReady {
|
|
35
|
-
@Inject()
|
|
36
|
-
protected formio: FormioService;
|
|
37
|
-
|
|
38
|
-
@Inject()
|
|
39
|
-
protected hooks: FormioHooksService;
|
|
40
|
-
|
|
41
|
-
@Inject()
|
|
42
|
-
protected installer: FormioInstaller;
|
|
43
|
-
|
|
44
|
-
@Inject()
|
|
45
|
-
protected app: PlatformApplication;
|
|
46
|
-
|
|
47
|
-
@Inject()
|
|
48
|
-
protected injector: InjectorService;
|
|
49
|
-
|
|
50
|
-
@Constant("formio", {})
|
|
51
|
-
protected settings: FormioConfig;
|
|
52
|
-
|
|
53
|
-
@Constant("formio.baseUrl", "/")
|
|
54
|
-
protected baseUrl: string;
|
|
55
|
-
|
|
56
|
-
@Constant("formio.skipInstall", false)
|
|
57
|
-
protected skipInstall: boolean;
|
|
58
|
-
|
|
59
|
-
@Constant("formio.template")
|
|
60
|
-
protected template?: FormioTemplate;
|
|
61
|
-
|
|
62
|
-
@Constant("formio.root")
|
|
63
|
-
protected root?: any;
|
|
64
|
-
|
|
65
|
-
$onInit() {
|
|
66
|
-
return this.init(deepClone(this.settings));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
init(options: FormioConfig) {
|
|
70
|
-
return this.formio.init(options, this.hooks.getHooks());
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async $onRoutesInit() {
|
|
74
|
-
if (this.formio.isInit()) {
|
|
75
|
-
this.app.use(this.baseUrl, this.formio.middleware.restrictRequestTypes, this.formio.router);
|
|
76
|
-
|
|
77
|
-
if (await this.shouldInstall()) {
|
|
78
|
-
await this.installer.install(this.template!, this.root);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async $logRoutes(routes: PlatformRouteDetails[]): Promise<PlatformRouteDetails[]> {
|
|
84
|
-
if (this.formio.isInit()) {
|
|
85
|
-
const spec = (await this.formio.swagger(
|
|
86
|
-
{
|
|
87
|
-
$ctx: {
|
|
88
|
-
request: {
|
|
89
|
-
protocol: "http",
|
|
90
|
-
host: "localhost"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
this.formio.router
|
|
95
|
-
)) as any;
|
|
96
|
-
const {baseUrl} = this;
|
|
97
|
-
|
|
98
|
-
Object.entries(spec.paths).forEach(([path, methods]: [string, any]) => {
|
|
99
|
-
Object.entries(methods).forEach(([method, operation]: [string, any]) => {
|
|
100
|
-
routes.push({
|
|
101
|
-
method,
|
|
102
|
-
name: operation.operationId,
|
|
103
|
-
url: normalizePath(baseUrl, path.replace(/\/{(.*)}/gi, "/:$1")),
|
|
104
|
-
className: "formio",
|
|
105
|
-
methodClassName: operation.operationId
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return routes;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// istanbul ignore next
|
|
115
|
-
$onReady() {
|
|
116
|
-
if (this.formio.isInit() && "getBestHost" in this.injector.settings) {
|
|
117
|
-
const {injector} = this;
|
|
118
|
-
// @ts-ignore
|
|
119
|
-
const host = injector.settings.getBestHost();
|
|
120
|
-
const url = host.toString();
|
|
121
|
-
|
|
122
|
-
injector.logger.info(`Form.io API is available on ${url}${this.baseUrl || "/"}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
protected async shouldInstall() {
|
|
127
|
-
const hasForms = await this.installer.hasForms();
|
|
128
|
-
return this.template && !(hasForms || this.skipInstall);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {toMap as tMap} from "@tsed/core";
|
|
2
|
-
import {MongooseDocument} from "@tsed/mongoose";
|
|
3
|
-
|
|
4
|
-
import {FormioMapper} from "./FormioMapper.js";
|
|
5
|
-
|
|
6
|
-
function toMap<T>(list: any[]) {
|
|
7
|
-
return tMap<string, MongooseDocument<T>>(list, (o: any) => [o._id.toString(), `$machineName:${o.machineName}`]);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe("FormioMapper", () => {
|
|
11
|
-
it("should map data to import (obj)", () => {
|
|
12
|
-
const mapper = new FormioMapper({
|
|
13
|
-
forms: toMap([{_id: "form_id", machineName: "form_machine"}]),
|
|
14
|
-
actions: toMap([{_id: "action_id", machineName: "action_machine"}]),
|
|
15
|
-
roles: toMap([{_id: "role_id", machineName: "role_machine"}])
|
|
16
|
-
});
|
|
17
|
-
const data = {
|
|
18
|
-
form: "form_machine",
|
|
19
|
-
value: 0,
|
|
20
|
-
notAnId: "id",
|
|
21
|
-
date: new Date()
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const result = mapper.mapToImport(data);
|
|
25
|
-
|
|
26
|
-
expect(result).toEqual({
|
|
27
|
-
...data,
|
|
28
|
-
form: "form_id"
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
it("should map data to import (array)", () => {
|
|
32
|
-
const mapper = new FormioMapper({
|
|
33
|
-
forms: toMap([{_id: "form_id", machineName: "form_machine"}]),
|
|
34
|
-
actions: toMap([{_id: "action_id", machineName: "action_machine"}]),
|
|
35
|
-
roles: toMap([{_id: "role_id", machineName: "role_machine"}])
|
|
36
|
-
});
|
|
37
|
-
const data = {
|
|
38
|
-
form: "form_machine",
|
|
39
|
-
value: 0,
|
|
40
|
-
notAnId: "id",
|
|
41
|
-
date: new Date()
|
|
42
|
-
};
|
|
43
|
-
const result = mapper.mapToImport([data]);
|
|
44
|
-
|
|
45
|
-
expect(result).toEqual([
|
|
46
|
-
{
|
|
47
|
-
...data,
|
|
48
|
-
form: "form_id"
|
|
49
|
-
}
|
|
50
|
-
]);
|
|
51
|
-
});
|
|
52
|
-
it("should map data to export (obj)", () => {
|
|
53
|
-
const mapper = new FormioMapper({
|
|
54
|
-
forms: toMap([{_id: "form_id", machineName: "form_machine"}]),
|
|
55
|
-
actions: toMap([{_id: "action_id", machineName: "action_machine"}]),
|
|
56
|
-
roles: toMap([{_id: "role_id", machineName: "role_machine"}])
|
|
57
|
-
});
|
|
58
|
-
const data = {
|
|
59
|
-
form: "form_id",
|
|
60
|
-
value: 0,
|
|
61
|
-
notAnId: "id",
|
|
62
|
-
date: new Date()
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const result = mapper.mapToExport(data);
|
|
66
|
-
|
|
67
|
-
expect(result).toEqual({
|
|
68
|
-
...data,
|
|
69
|
-
form: "$machineName:form_machine"
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
it("should map data to export (array)", () => {
|
|
73
|
-
const mapper = new FormioMapper({
|
|
74
|
-
forms: toMap([{_id: "form_id", machineName: "form_machine"}]),
|
|
75
|
-
actions: toMap([{_id: "action_id", machineName: "action_machine"}]),
|
|
76
|
-
roles: toMap([{_id: "role_id", machineName: "role_machine"}])
|
|
77
|
-
});
|
|
78
|
-
const data = {
|
|
79
|
-
form: "form_id",
|
|
80
|
-
value: 0,
|
|
81
|
-
notAnId: "id",
|
|
82
|
-
date: new Date()
|
|
83
|
-
};
|
|
84
|
-
const result = mapper.mapToExport([data]);
|
|
85
|
-
|
|
86
|
-
expect(result).toEqual([
|
|
87
|
-
{
|
|
88
|
-
...data,
|
|
89
|
-
form: "$machineName:form_machine"
|
|
90
|
-
}
|
|
91
|
-
]);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {FormioCtxMapper} from "../domain/FormioCtxMapper.js";
|
|
2
|
-
|
|
3
|
-
export class FormioMapper {
|
|
4
|
-
constructor(readonly ctxData: FormioCtxMapper) {}
|
|
5
|
-
|
|
6
|
-
find(key: string) {
|
|
7
|
-
const store = Object.values(this.ctxData).find((store) => store.get(key));
|
|
8
|
-
|
|
9
|
-
return store?.get(key);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
findId(data: string) {
|
|
13
|
-
const key = String(data).startsWith("$machineName:") ? String(data) : `$machineName:${String(data)}`;
|
|
14
|
-
const item = this.find(key);
|
|
15
|
-
|
|
16
|
-
return item ? item._id : undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
findMachineName(data: any) {
|
|
20
|
-
const key = String(data);
|
|
21
|
-
const item: any = this.find(key);
|
|
22
|
-
|
|
23
|
-
return item ? `$machineName:${item.name || item.machineName}` : undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
mapToExport(data: any) {
|
|
27
|
-
return this.mapData(data, this.findMachineName.bind(this));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
mapToImport(data: any) {
|
|
31
|
-
return this.mapData(data, this.findId.bind(this));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
mapData(data: any, resolver: any): any {
|
|
35
|
-
if (!data) {
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (Array.isArray(data)) {
|
|
40
|
-
return data.map((item) => {
|
|
41
|
-
return this.mapData(item, resolver);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const key = resolver(data, this.ctxData);
|
|
46
|
-
|
|
47
|
-
if (key) {
|
|
48
|
-
return key;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (typeof data === "object" && !("_bsontype" in data) && !(data instanceof Date)) {
|
|
52
|
-
const isForm = data.path && data.type;
|
|
53
|
-
const mapped = Object.entries(data).reduce((obj, [key, value]) => {
|
|
54
|
-
return {
|
|
55
|
-
...obj,
|
|
56
|
-
[key]: this.mapData(value, resolver)
|
|
57
|
-
};
|
|
58
|
-
}, {});
|
|
59
|
-
|
|
60
|
-
return isForm
|
|
61
|
-
? {
|
|
62
|
-
...mapped,
|
|
63
|
-
name: data.name,
|
|
64
|
-
machineName: data.machineName || data.name
|
|
65
|
-
}
|
|
66
|
-
: mapped;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return data;
|
|
70
|
-
}
|
|
71
|
-
}
|