@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
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import "../components/AlterAudit.js";
|
|
2
|
-
|
|
3
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
4
|
-
|
|
5
|
-
import {AlterAudit} from "../components/AlterAudit.js";
|
|
6
|
-
import {FormioHooksService} from "./FormioHooksService.js";
|
|
7
|
-
import {FormioService} from "./FormioService.js";
|
|
8
|
-
|
|
9
|
-
async function createFormioFixture(routerOpts: any = {}) {
|
|
10
|
-
const service = await PlatformTest.invoke<FormioService>(FormioService, []);
|
|
11
|
-
const router = {
|
|
12
|
-
init: vi.fn().mockReturnThis(),
|
|
13
|
-
...routerOpts,
|
|
14
|
-
formio: {
|
|
15
|
-
...(routerOpts.formio || {}),
|
|
16
|
-
util: {
|
|
17
|
-
log: vi.fn(),
|
|
18
|
-
error: vi.fn()
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const config: any = {
|
|
23
|
-
baseUrl: "/projects",
|
|
24
|
-
jwt: {
|
|
25
|
-
secret: "secret"
|
|
26
|
-
},
|
|
27
|
-
root: {
|
|
28
|
-
email: "email@email.com",
|
|
29
|
-
password: "password"
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
PlatformTest.injector.settings.set("mongoose", [
|
|
34
|
-
{
|
|
35
|
-
id: "default",
|
|
36
|
-
url: "mongoose://url",
|
|
37
|
-
connectionOptions: {
|
|
38
|
-
useNewUrlParser: true
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
vi.spyOn(service, "createRouter").mockReturnValue(router);
|
|
44
|
-
|
|
45
|
-
return {router, config, service};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
describe("FormioService", () => {
|
|
49
|
-
beforeEach(() => PlatformTest.create());
|
|
50
|
-
afterEach(PlatformTest.reset);
|
|
51
|
-
|
|
52
|
-
it("should create the new service", async () => {
|
|
53
|
-
const {router, service, config} = await createFormioFixture();
|
|
54
|
-
|
|
55
|
-
const result = await service.init(config);
|
|
56
|
-
|
|
57
|
-
expect(service.createRouter).toHaveBeenCalledWith(config);
|
|
58
|
-
expect(result).toEqual(router);
|
|
59
|
-
expect(config.mongo).toEqual("mongoose://url");
|
|
60
|
-
expect(config.mongoConfig).toEqual('{"useNewUrlParser":true}');
|
|
61
|
-
});
|
|
62
|
-
it("should call hook", async () => {
|
|
63
|
-
const {router, service, config} = await createFormioFixture();
|
|
64
|
-
|
|
65
|
-
await service.init(config, PlatformTest.get<FormioHooksService>(FormioHooksService).getHooks());
|
|
66
|
-
|
|
67
|
-
// hooks
|
|
68
|
-
const ctx = PlatformTest.createRequestContext();
|
|
69
|
-
const hooks = router.init.mock.calls[0][0];
|
|
70
|
-
|
|
71
|
-
vi.spyOn(AlterAudit.prototype, "transform").mockReturnValue(false);
|
|
72
|
-
|
|
73
|
-
hooks.alter.audit({$ctx: ctx}, "test");
|
|
74
|
-
|
|
75
|
-
expect(AlterAudit.prototype.transform).toHaveBeenCalledWith(ctx, "test");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("isInit()", () => {
|
|
79
|
-
it("should return true", async () => {
|
|
80
|
-
const {service, config} = await createFormioFixture();
|
|
81
|
-
|
|
82
|
-
await service.init(config);
|
|
83
|
-
expect(service.isInit()).toEqual(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("should return false", async () => {
|
|
87
|
-
const {service} = await createFormioFixture();
|
|
88
|
-
|
|
89
|
-
await service.init({} as any);
|
|
90
|
-
|
|
91
|
-
expect(service.isInit()).toEqual(false);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe("encrypt()", () => {
|
|
95
|
-
it("should encrypt password", async () => {
|
|
96
|
-
const routeOpts = {
|
|
97
|
-
formio: {
|
|
98
|
-
encrypt: vi.fn().mockImplementation((text, cb) => {
|
|
99
|
-
cb(null, "hash");
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
104
|
-
|
|
105
|
-
await service.init(config);
|
|
106
|
-
|
|
107
|
-
const result = await service.encrypt("text");
|
|
108
|
-
|
|
109
|
-
expect(result).toEqual("hash");
|
|
110
|
-
});
|
|
111
|
-
it("should throw error", async () => {
|
|
112
|
-
const routeOpts = {
|
|
113
|
-
formio: {
|
|
114
|
-
encrypt: vi.fn().mockImplementation((text, cb) => {
|
|
115
|
-
cb(new Error("error"));
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
120
|
-
|
|
121
|
-
await service.init(config);
|
|
122
|
-
|
|
123
|
-
let actualError: any;
|
|
124
|
-
try {
|
|
125
|
-
await service.encrypt("text");
|
|
126
|
-
} catch (er) {
|
|
127
|
-
actualError = er;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
expect(actualError.message).toEqual("error");
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe("Action", () => {
|
|
134
|
-
it("should return Action", async () => {
|
|
135
|
-
const routeOpts = {
|
|
136
|
-
formio: {
|
|
137
|
-
Action: class {}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
141
|
-
|
|
142
|
-
await service.init(config);
|
|
143
|
-
|
|
144
|
-
expect(service.Action).toEqual(routeOpts.formio.Action);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe("util", () => {
|
|
148
|
-
it("should return util", async () => {
|
|
149
|
-
const routeOpts = {
|
|
150
|
-
formio: {
|
|
151
|
-
util: {}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const {service, config, router} = await createFormioFixture(routeOpts);
|
|
155
|
-
|
|
156
|
-
await service.init(config);
|
|
157
|
-
|
|
158
|
-
expect(service.util).toEqual(router.formio.util);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe("hook", () => {
|
|
162
|
-
it("should return hook", async () => {
|
|
163
|
-
const routeOpts = {
|
|
164
|
-
formio: {
|
|
165
|
-
hook: {}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
169
|
-
|
|
170
|
-
await service.init(config);
|
|
171
|
-
|
|
172
|
-
expect(service.hook).toEqual(routeOpts.formio.hook);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
describe("auth", () => {
|
|
176
|
-
it("should return auth", async () => {
|
|
177
|
-
const routeOpts = {
|
|
178
|
-
formio: {
|
|
179
|
-
auth: {}
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
183
|
-
|
|
184
|
-
await service.init(config);
|
|
185
|
-
|
|
186
|
-
expect(service.auth).toEqual(routeOpts.formio.auth);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe("audit", () => {
|
|
190
|
-
it("should return audit", async () => {
|
|
191
|
-
const routeOpts = {
|
|
192
|
-
formio: {
|
|
193
|
-
audit: {}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
197
|
-
|
|
198
|
-
await service.init(config);
|
|
199
|
-
|
|
200
|
-
expect(service.audit).toEqual(routeOpts.formio.audit);
|
|
201
|
-
});
|
|
202
|
-
it("should return empty fn", async () => {
|
|
203
|
-
const routeOpts = {
|
|
204
|
-
formio: {}
|
|
205
|
-
};
|
|
206
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
207
|
-
|
|
208
|
-
await service.init(config);
|
|
209
|
-
|
|
210
|
-
expect(typeof service.audit).toEqual("function");
|
|
211
|
-
expect(service.audit("test")).toEqual(undefined);
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
describe("formio", () => {
|
|
215
|
-
it("should return formio", async () => {
|
|
216
|
-
const routeOpts = {
|
|
217
|
-
formio: {
|
|
218
|
-
hook: {}
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
const {service, config, router} = await createFormioFixture(routeOpts);
|
|
222
|
-
|
|
223
|
-
await service.init(config);
|
|
224
|
-
|
|
225
|
-
expect(service.formio).toEqual(router.formio);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe("schemas", () => {
|
|
229
|
-
it("should return schemas", async () => {
|
|
230
|
-
const routeOpts = {
|
|
231
|
-
formio: {
|
|
232
|
-
schemas: {}
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
236
|
-
|
|
237
|
-
await service.init(config);
|
|
238
|
-
|
|
239
|
-
expect(service.schemas).toEqual(routeOpts.formio.schemas);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
describe("middleware", () => {
|
|
243
|
-
it("should return middleware", async () => {
|
|
244
|
-
const routeOpts = {
|
|
245
|
-
formio: {
|
|
246
|
-
middleware: {}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
250
|
-
|
|
251
|
-
await service.init(config);
|
|
252
|
-
|
|
253
|
-
expect(service.middleware).toEqual(routeOpts.formio.middleware);
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
describe("mongoose", () => {
|
|
257
|
-
it("should return mongoose", async () => {
|
|
258
|
-
const routeOpts = {
|
|
259
|
-
formio: {
|
|
260
|
-
mongoose: {}
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
264
|
-
|
|
265
|
-
await service.init(config);
|
|
266
|
-
|
|
267
|
-
expect(service.mongoose).toEqual(routeOpts.formio.mongoose);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
describe("resources", () => {
|
|
271
|
-
it("should return resources", async () => {
|
|
272
|
-
const routeOpts = {
|
|
273
|
-
formio: {
|
|
274
|
-
resources: {}
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
278
|
-
|
|
279
|
-
await service.init(config);
|
|
280
|
-
|
|
281
|
-
expect(service.resources).toEqual(routeOpts.formio.resources);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
describe("db", () => {
|
|
285
|
-
it("should return db", async () => {
|
|
286
|
-
const routeOpts = {
|
|
287
|
-
formio: {
|
|
288
|
-
db: {}
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
292
|
-
|
|
293
|
-
await service.init(config);
|
|
294
|
-
|
|
295
|
-
expect(service.db).toEqual(routeOpts.formio.db);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
describe("config", () => {
|
|
299
|
-
it("should return config", async () => {
|
|
300
|
-
const routeOpts = {
|
|
301
|
-
formio: {
|
|
302
|
-
config: {}
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
306
|
-
|
|
307
|
-
await service.init(config);
|
|
308
|
-
|
|
309
|
-
expect(service.config).toEqual(routeOpts.formio.config);
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
describe("exportTemplate()", () => {
|
|
313
|
-
it("should return template", async () => {
|
|
314
|
-
const routeOpts = {
|
|
315
|
-
formio: {
|
|
316
|
-
template: {
|
|
317
|
-
export(_: any, cb: any) {
|
|
318
|
-
cb(null, "ok");
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
324
|
-
|
|
325
|
-
await service.init(config);
|
|
326
|
-
|
|
327
|
-
const result = await service.exportTemplate(config);
|
|
328
|
-
|
|
329
|
-
expect(result).toEqual("ok");
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
describe("importTemplate()", () => {
|
|
333
|
-
it("should return template", async () => {
|
|
334
|
-
const routeOpts = {
|
|
335
|
-
formio: {
|
|
336
|
-
template: {
|
|
337
|
-
import: {
|
|
338
|
-
template(_: any, cb: any) {
|
|
339
|
-
cb(null, "ok");
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
346
|
-
|
|
347
|
-
await service.init(config);
|
|
348
|
-
|
|
349
|
-
const result = await service.importTemplate(config);
|
|
350
|
-
|
|
351
|
-
expect(result).toEqual("ok");
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
describe("template", () => {
|
|
355
|
-
it("should return template", async () => {
|
|
356
|
-
const routeOpts = {
|
|
357
|
-
formio: {
|
|
358
|
-
template: {}
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
const {service, config} = await createFormioFixture(routeOpts);
|
|
362
|
-
|
|
363
|
-
await service.init(config);
|
|
364
|
-
|
|
365
|
-
expect(service.template).toEqual(routeOpts.formio.template);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
});
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {promisify} from "node:util";
|
|
2
|
-
|
|
3
|
-
import {Inject, Injectable, InjectorService} from "@tsed/di";
|
|
4
|
-
import {MongooseConnectionOptions} from "@tsed/mongoose";
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import createRouter from "formio";
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import swagger from "formio/src/util/swagger.js";
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import util from "formio/src/util/util.js";
|
|
11
|
-
import {Db} from "mongodb";
|
|
12
|
-
import {Mongoose} from "mongoose";
|
|
13
|
-
|
|
14
|
-
import {Formio} from "../domain/Formio.js";
|
|
15
|
-
import {FormioConfig} from "../domain/FormioConfig.js";
|
|
16
|
-
import {FormioHook, FormioHooks} from "../domain/FormioHooks.js";
|
|
17
|
-
import {FormioSchemas} from "../domain/FormioModels.js";
|
|
18
|
-
import {FormioRouter} from "../domain/FormioRouter.js";
|
|
19
|
-
import {FormioTemplate} from "../domain/FormioTemplate.js";
|
|
20
|
-
import {FormioExportOptions} from "../domain/FormioTemplateUtil.js";
|
|
21
|
-
|
|
22
|
-
@Injectable()
|
|
23
|
-
export class FormioService {
|
|
24
|
-
router: FormioRouter;
|
|
25
|
-
|
|
26
|
-
@Inject()
|
|
27
|
-
protected injector: InjectorService;
|
|
28
|
-
|
|
29
|
-
get audit(): Function {
|
|
30
|
-
return this.formio.audit || (() => {});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get auth() {
|
|
34
|
-
return this.formio.auth;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// istanbul ignore next
|
|
38
|
-
get swagger() {
|
|
39
|
-
return (...args: any[]) => new Promise((resolve) => swagger(...args, resolve));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get config(): FormioConfig {
|
|
43
|
-
return this.formio.config;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get db(): Db {
|
|
47
|
-
return this.formio.db;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get resources() {
|
|
51
|
-
return this.formio.resources;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get mongoose(): Mongoose {
|
|
55
|
-
return this.formio.mongoose;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get middleware() {
|
|
59
|
-
return this.formio.middleware;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get schemas(): FormioSchemas {
|
|
63
|
-
return this.formio.schemas;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get formio(): Formio {
|
|
67
|
-
return this.router.formio as Formio;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get hook(): FormioHook {
|
|
71
|
-
return this.formio.hook;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get util() {
|
|
75
|
-
return this.formio.util;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get template() {
|
|
79
|
-
return this.formio.template;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
get Action() {
|
|
83
|
-
return this.formio.Action;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
exportTemplate(options: Partial<FormioExportOptions> = {}): Promise<FormioTemplate> {
|
|
87
|
-
return promisify(this.formio.template.export)(options);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
importTemplate(template: FormioTemplate): Promise<FormioTemplate> {
|
|
91
|
-
return promisify(this.formio.template.import.template)(template);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
encrypt(text: string) {
|
|
95
|
-
return promisify(this.formio.encrypt)(text);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
isInit() {
|
|
99
|
-
return !!this.router;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// istanbul ignore next
|
|
103
|
-
public createRouter(options: FormioConfig) {
|
|
104
|
-
return createRouter(options);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public init(options: FormioConfig, hooks: FormioHooks = {}) {
|
|
108
|
-
if (options && Object.keys(options).length) {
|
|
109
|
-
this.router = this.createRouter(this.mapConfiguration(options));
|
|
110
|
-
this.bindLogger();
|
|
111
|
-
|
|
112
|
-
return this.router.init(hooks);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
protected mapConfiguration(options: FormioConfig) {
|
|
117
|
-
const {injector} = this;
|
|
118
|
-
const mongooseSettings = injector.settings.get<MongooseConnectionOptions>("mongoose.0");
|
|
119
|
-
|
|
120
|
-
if (mongooseSettings) {
|
|
121
|
-
options.mongo = options.mongo || mongooseSettings.url;
|
|
122
|
-
options.mongoConfig = options.mongoConfig || JSON.stringify(mongooseSettings.connectionOptions);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return options;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
protected bindLogger() {
|
|
129
|
-
const {injector} = this;
|
|
130
|
-
|
|
131
|
-
util.log = injector.logger.info.bind(injector.logger);
|
|
132
|
-
util.error = injector.logger.error.bind(injector.logger);
|
|
133
|
-
}
|
|
134
|
-
}
|
package/src/utils/isMongoId.ts
DELETED
package/vitest.config.mts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import {presets} from "@tsed/vitest/presets";
|
|
3
|
-
import {defineConfig} from "vitest/config";
|
|
4
|
-
|
|
5
|
-
export default defineConfig(
|
|
6
|
-
{
|
|
7
|
-
...presets,
|
|
8
|
-
test: {
|
|
9
|
-
...presets.test,
|
|
10
|
-
coverage: {
|
|
11
|
-
...presets.test.coverage,
|
|
12
|
-
thresholds: {
|
|
13
|
-
statements: 0,
|
|
14
|
-
branches: 0,
|
|
15
|
-
functions: 0,
|
|
16
|
-
lines: 0
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
);
|