@formio/appserver 2.0.0-rc.3 → 2.0.0-rc.31
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/actions/index.d.ts +3 -156
- package/lib/actions/login/LoginAction.d.ts +2 -109
- package/lib/actions/login/LoginAction.js +124 -213
- package/lib/actions/role/RoleAction.d.ts +2 -61
- package/lib/actions/role/RoleAction.js +13 -20
- package/lib/actions/save/SaveAction.d.ts +2 -28
- package/lib/actions/save/SaveAction.js +27 -45
- package/lib/modules/index.d.ts +1 -3
- package/lib/modules/index.js +2 -4
- package/lib/modules/mongodb/db.d.ts +31 -32
- package/lib/modules/mongodb/db.js +220 -94
- package/lib/server.d.ts +5 -171
- package/lib/server.js +59 -52
- package/package.json +20 -20
- package/lib/actions/login/LoginAction.spec.d.ts +0 -1
- package/lib/actions/login/LoginAction.spec.js +0 -15
- package/lib/actions/role/RoleAction.spec.d.ts +0 -1
- package/lib/actions/role/RoleAction.spec.js +0 -15
- package/lib/actions/save/SaveAction.spec.d.ts +0 -1
- package/lib/actions/save/SaveAction.spec.js +0 -15
- package/lib/modules/auth/auth.d.ts +0 -5
- package/lib/modules/auth/auth.js +0 -70
- package/lib/modules/auth/auth.spec.d.ts +0 -1
- package/lib/modules/auth/auth.spec.js +0 -93
- package/lib/modules/mongodb/db.spec.d.ts +0 -1
- package/lib/modules/mongodb/db.spec.js +0 -714
- package/server.js +0 -1
|
@@ -1,61 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const RoleAction: {
|
|
4
|
-
readonly info: {
|
|
5
|
-
name: string;
|
|
6
|
-
title: string;
|
|
7
|
-
description: string;
|
|
8
|
-
priority: number;
|
|
9
|
-
defaults: {
|
|
10
|
-
handler: string[];
|
|
11
|
-
method: string[];
|
|
12
|
-
};
|
|
13
|
-
access: {
|
|
14
|
-
handler: boolean;
|
|
15
|
-
method: boolean;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* The settings form for this action.
|
|
20
|
-
* @param {*} scope
|
|
21
|
-
*/
|
|
22
|
-
settingsForm(scope: ActionScope): Promise<({
|
|
23
|
-
type: string;
|
|
24
|
-
input: boolean;
|
|
25
|
-
label: string;
|
|
26
|
-
key: string;
|
|
27
|
-
placeholder: string;
|
|
28
|
-
template: string;
|
|
29
|
-
dataSrc: string;
|
|
30
|
-
data: {
|
|
31
|
-
json: string;
|
|
32
|
-
};
|
|
33
|
-
valueProperty: string;
|
|
34
|
-
multiple: boolean;
|
|
35
|
-
validate: {
|
|
36
|
-
required: boolean;
|
|
37
|
-
};
|
|
38
|
-
} | {
|
|
39
|
-
type: string;
|
|
40
|
-
input: boolean;
|
|
41
|
-
label: string;
|
|
42
|
-
key: string;
|
|
43
|
-
placeholder: string;
|
|
44
|
-
template: string;
|
|
45
|
-
dataSrc: string;
|
|
46
|
-
data: {
|
|
47
|
-
json: unknown[];
|
|
48
|
-
};
|
|
49
|
-
valueProperty: string;
|
|
50
|
-
multiple: boolean;
|
|
51
|
-
validate: {
|
|
52
|
-
required: boolean;
|
|
53
|
-
};
|
|
54
|
-
})[]>;
|
|
55
|
-
/**
|
|
56
|
-
* Returns the action middleware.
|
|
57
|
-
*
|
|
58
|
-
* @param {*} scope
|
|
59
|
-
*/
|
|
60
|
-
executor(scope: ActionScope): Promise<(req: SubmissionRequest, res: SubmissionResponse, next: NextFunction) => Promise<void | SubmissionResponse>>;
|
|
61
|
-
};
|
|
1
|
+
import { Action } from "@formio/appserver-core";
|
|
2
|
+
export declare const RoleAction: Action;
|
|
@@ -30,12 +30,9 @@ exports.RoleAction = {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
},
|
|
33
|
-
|
|
34
|
-
* The settings form for this action.
|
|
35
|
-
* @param {*} scope
|
|
36
|
-
*/
|
|
37
|
-
settingsForm(scope) {
|
|
33
|
+
settingsForm(form) {
|
|
38
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
39
36
|
return [
|
|
40
37
|
{
|
|
41
38
|
type: 'select',
|
|
@@ -97,7 +94,7 @@ exports.RoleAction = {
|
|
|
97
94
|
placeholder: 'Select the Role that this action will Add or Remove.',
|
|
98
95
|
template: '<span>{{ item.title }}</span>',
|
|
99
96
|
dataSrc: 'json',
|
|
100
|
-
data: { json: Object.values(
|
|
97
|
+
data: { json: Object.values(((_a = form.project.template) === null || _a === void 0 ? void 0 : _a.roles) || {}) },
|
|
101
98
|
valueProperty: '_id',
|
|
102
99
|
multiple: false,
|
|
103
100
|
validate: {
|
|
@@ -107,47 +104,43 @@ exports.RoleAction = {
|
|
|
107
104
|
];
|
|
108
105
|
});
|
|
109
106
|
},
|
|
110
|
-
|
|
111
|
-
* Returns the action middleware.
|
|
112
|
-
*
|
|
113
|
-
* @param {*} scope
|
|
114
|
-
*/
|
|
115
|
-
executor(scope) {
|
|
107
|
+
executor(form, action, handler, method) {
|
|
116
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
109
|
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
var _a, _b;
|
|
118
111
|
debug('Role Action');
|
|
119
112
|
// Check the submission for the submissionId.
|
|
120
|
-
if (
|
|
113
|
+
if (action.settings.association !== 'existing' && action.settings.association !== 'new') {
|
|
121
114
|
error('Invalid setting `association` for the RoleAction; expecting `new` or `existing`.');
|
|
122
115
|
return res.status(400).send('Invalid setting `association` for the RoleAction; expecting `new` or `existing`.');
|
|
123
116
|
}
|
|
124
117
|
// Error if operation type is not valid.
|
|
125
|
-
if (!
|
|
118
|
+
if (!action.settings.type || (action.settings.type !== 'add' && action.settings.type !== 'remove')) {
|
|
126
119
|
error('Invalid setting `type` for the RoleAction; expecting `add` or `remove`.');
|
|
127
120
|
return res.status(400).send('Invalid setting `type` for the RoleAction; expecting `add` or `remove`.');
|
|
128
121
|
}
|
|
129
122
|
// Error if no resource is being returned.
|
|
130
|
-
if (
|
|
123
|
+
if (action.settings.association === 'new' && res.hasOwnProperty('resource') && !((_a = res.resource) === null || _a === void 0 ? void 0 : _a.item) && action.settings.role) {
|
|
131
124
|
error('Invalid resource was provided for RoleAction association of `new`.');
|
|
132
125
|
return res.status(400).send('Invalid resource was provided for RoleAction association of `new`.');
|
|
133
126
|
}
|
|
134
127
|
// Error if association is existing and valid data was not provided.
|
|
135
|
-
if (
|
|
128
|
+
if (action.settings.association === 'existing' && !action.settings.role) {
|
|
136
129
|
error('Missing role for RoleAction association of "existing". Must specify role to assign in action settings or a form component named "role"');
|
|
137
130
|
return res.status(400).send('Missing role for RoleAction association of "existing". Must specify role to assign in action settings or a form component named "role"');
|
|
138
131
|
}
|
|
139
|
-
if (
|
|
132
|
+
if (action.settings.association === 'existing' && !((_b = res.resource) === null || _b === void 0 ? void 0 : _b.item)) {
|
|
140
133
|
error('Missing submission for RoleAction association of "existing:. Form must have a resource field named "submission".');
|
|
141
134
|
return res.status(400).send('Missing submission for RoleAction association of "existing:. Form must have a resource field named "submission".');
|
|
142
135
|
}
|
|
143
136
|
// Determine the resources based on the current request.
|
|
144
137
|
let resource = res.resource ? (res.resource.item || req.body) : req.body;
|
|
145
|
-
let role =
|
|
138
|
+
let role = form.project.roleId(action.settings.role);
|
|
146
139
|
if (!resource.roles) {
|
|
147
140
|
resource.roles = [];
|
|
148
141
|
}
|
|
149
142
|
const roleIndex = resource.roles.indexOf(role);
|
|
150
|
-
switch (
|
|
143
|
+
switch (action.settings.type) {
|
|
151
144
|
case 'add':
|
|
152
145
|
if (roleIndex !== -1) {
|
|
153
146
|
return next();
|
|
@@ -163,7 +156,7 @@ exports.RoleAction = {
|
|
|
163
156
|
}
|
|
164
157
|
debug('Updating user with roles', resource.roles);
|
|
165
158
|
// Update the user.
|
|
166
|
-
yield
|
|
159
|
+
yield form.saveSubmission(resource, ['roles']);
|
|
167
160
|
next();
|
|
168
161
|
});
|
|
169
162
|
});
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const SaveAction: {
|
|
4
|
-
readonly info: {
|
|
5
|
-
name: string;
|
|
6
|
-
title: string;
|
|
7
|
-
description: string;
|
|
8
|
-
priority: number;
|
|
9
|
-
defaults: {
|
|
10
|
-
handler: string[];
|
|
11
|
-
method: string[];
|
|
12
|
-
};
|
|
13
|
-
access: {
|
|
14
|
-
handler: boolean;
|
|
15
|
-
method: boolean;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
mappingComponents(scope: ActionScope): Promise<any>;
|
|
19
|
-
/**
|
|
20
|
-
* The settings form for this action.
|
|
21
|
-
* @param {*} scope
|
|
22
|
-
*/
|
|
23
|
-
settingsForm(scope: ActionScope): Promise<any>;
|
|
24
|
-
saveToForm(scope: ActionScope, resource: string): undefined;
|
|
25
|
-
childSubmission(scope: ActionScope, req: SubmissionRequest, res: SubmissionResponse, submission: any): any;
|
|
26
|
-
childResponse(scope: ActionScope, req: SubmissionRequest, res: SubmissionResponse): void;
|
|
27
|
-
executor(scope: ActionScope): Promise<(req: SubmissionRequest, res: SubmissionResponse, next: NextFunction) => Promise<void>>;
|
|
28
|
-
};
|
|
1
|
+
import { Action } from '@formio/appserver-core';
|
|
2
|
+
export declare const SaveAction: Action;
|
|
@@ -18,6 +18,7 @@ const set_1 = __importDefault(require("lodash/set"));
|
|
|
18
18
|
const has_1 = __importDefault(require("lodash/has"));
|
|
19
19
|
const get_1 = __importDefault(require("lodash/get"));
|
|
20
20
|
const async_1 = __importDefault(require("async"));
|
|
21
|
+
const appserver_core_1 = require("@formio/appserver-core");
|
|
21
22
|
const debug = require('debug')('formio:actions:save');
|
|
22
23
|
const error = require('debug')('formio:error');
|
|
23
24
|
exports.SaveAction = {
|
|
@@ -38,8 +39,9 @@ exports.SaveAction = {
|
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
41
|
},
|
|
41
|
-
mappingComponents(
|
|
42
|
+
mappingComponents(form) {
|
|
42
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
var _a;
|
|
43
45
|
const components = [
|
|
44
46
|
{
|
|
45
47
|
type: 'select',
|
|
@@ -76,8 +78,8 @@ exports.SaveAction = {
|
|
|
76
78
|
]
|
|
77
79
|
}
|
|
78
80
|
];
|
|
79
|
-
for (let key in
|
|
80
|
-
const
|
|
81
|
+
for (let key in (_a = form.project.template) === null || _a === void 0 ? void 0 : _a.resources) {
|
|
82
|
+
const resource = form.project.template.resources[key];
|
|
81
83
|
const mappings = {
|
|
82
84
|
title: 'Simple Mappings',
|
|
83
85
|
label: 'Simple Mappings',
|
|
@@ -88,13 +90,13 @@ exports.SaveAction = {
|
|
|
88
90
|
components: []
|
|
89
91
|
};
|
|
90
92
|
const toFields = [];
|
|
91
|
-
|
|
93
|
+
appserver_core_1.Utils.eachComponent(resource.components, (component) => {
|
|
92
94
|
if (['button'].indexOf(component.type) !== -1) {
|
|
93
95
|
return;
|
|
94
96
|
}
|
|
95
97
|
toFields.push({ label: component.label || component.key, value: component.key });
|
|
96
98
|
});
|
|
97
|
-
|
|
99
|
+
appserver_core_1.Utils.eachComponent(resource.components, (component) => {
|
|
98
100
|
if (['button'].indexOf(component.type) !== -1) {
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
@@ -112,16 +114,13 @@ exports.SaveAction = {
|
|
|
112
114
|
return components;
|
|
113
115
|
});
|
|
114
116
|
},
|
|
115
|
-
|
|
116
|
-
* The settings form for this action.
|
|
117
|
-
* @param {*} scope
|
|
118
|
-
*/
|
|
119
|
-
settingsForm(scope) {
|
|
117
|
+
settingsForm(form) {
|
|
120
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
var _a, _b;
|
|
121
120
|
const resources = [];
|
|
122
|
-
for (let name in
|
|
121
|
+
for (let name in (_a = form.project.template) === null || _a === void 0 ? void 0 : _a.resources) {
|
|
123
122
|
resources.push({
|
|
124
|
-
label:
|
|
123
|
+
label: (_b = form.project.template) === null || _b === void 0 ? void 0 : _b.resources[name].title,
|
|
125
124
|
value: name
|
|
126
125
|
});
|
|
127
126
|
}
|
|
@@ -168,7 +167,7 @@ exports.SaveAction = {
|
|
|
168
167
|
}
|
|
169
168
|
]
|
|
170
169
|
}
|
|
171
|
-
].concat(yield exports.SaveAction.mappingComponents(
|
|
170
|
+
].concat(yield exports.SaveAction.mappingComponents(form))
|
|
172
171
|
},
|
|
173
172
|
{
|
|
174
173
|
type: 'panel',
|
|
@@ -211,31 +210,12 @@ exports.SaveAction = {
|
|
|
211
210
|
];
|
|
212
211
|
});
|
|
213
212
|
},
|
|
214
|
-
saveToForm(scope, resource) {
|
|
215
|
-
let saveTo;
|
|
216
|
-
(0, each_1.default)(scope.template.resources, (form) => {
|
|
217
|
-
if (form.key === resource) {
|
|
218
|
-
saveTo = form;
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
if (!saveTo) {
|
|
223
|
-
(0, each_1.default)(scope.template.forms, (form) => {
|
|
224
|
-
if (form.key === resource) {
|
|
225
|
-
saveTo = form;
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return saveTo;
|
|
231
|
-
},
|
|
232
213
|
// Create a child submission.
|
|
233
|
-
childSubmission(
|
|
234
|
-
const { action } = scope;
|
|
214
|
+
childSubmission(action, req, res, form, submission) {
|
|
235
215
|
let childSub = { data: {} };
|
|
236
216
|
if (action.settings.mapping) {
|
|
237
217
|
try {
|
|
238
|
-
childSub =
|
|
218
|
+
childSub = appserver_core_1.Utils.evaluate(action.settings.mapping, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery), 'body');
|
|
239
219
|
}
|
|
240
220
|
catch (err) {
|
|
241
221
|
console.log(`Error in mapping transform: ${err.message}`);
|
|
@@ -254,7 +234,7 @@ exports.SaveAction = {
|
|
|
254
234
|
childSub.metadata = submission.metadata;
|
|
255
235
|
if (action.settings.transform) {
|
|
256
236
|
try {
|
|
257
|
-
childSub.data =
|
|
237
|
+
childSub.data = appserver_core_1.Utils.evaluate(action.settings.transform, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery), 'data');
|
|
258
238
|
}
|
|
259
239
|
catch (err) {
|
|
260
240
|
console.log(`Error in submission transform: ${err.message}`);
|
|
@@ -263,9 +243,8 @@ exports.SaveAction = {
|
|
|
263
243
|
return childSub;
|
|
264
244
|
},
|
|
265
245
|
// Set the child response
|
|
266
|
-
childResponse(
|
|
246
|
+
childResponse(action, req, res, form, submission) {
|
|
267
247
|
var _a, _b;
|
|
268
|
-
const { action } = scope;
|
|
269
248
|
if ((_a = res.resource) === null || _a === void 0 ? void 0 : _a.item) {
|
|
270
249
|
// Set the action in the property.
|
|
271
250
|
if ((_b = action.settings) === null || _b === void 0 ? void 0 : _b.property) {
|
|
@@ -284,7 +263,7 @@ exports.SaveAction = {
|
|
|
284
263
|
// Allow for a response mapping.
|
|
285
264
|
if (action.settings.response) {
|
|
286
265
|
try {
|
|
287
|
-
res.resource.item =
|
|
266
|
+
res.resource.item = appserver_core_1.Utils.evaluate(action.settings.response, Object.assign(Object.assign({}, appserver_core_1.Utils.evalContext(form, req.body, req.auth, req.headers, req.findQuery)), { response: res.resource.item }), 'response');
|
|
288
267
|
}
|
|
289
268
|
catch (err) {
|
|
290
269
|
console.log(`Error in mapping transform: ${err.message}`);
|
|
@@ -292,9 +271,8 @@ exports.SaveAction = {
|
|
|
292
271
|
}
|
|
293
272
|
}
|
|
294
273
|
},
|
|
295
|
-
executor(
|
|
274
|
+
executor(form, action, handler, method) {
|
|
296
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
-
const action = scope.action;
|
|
298
276
|
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
299
277
|
var _a;
|
|
300
278
|
debug('Save Action');
|
|
@@ -305,28 +283,32 @@ exports.SaveAction = {
|
|
|
305
283
|
// If this is saving to another resource, then we need to use those handlers instead.
|
|
306
284
|
if ((_a = action.settings) === null || _a === void 0 ? void 0 : _a.resource) {
|
|
307
285
|
debug('Saving to resource: ' + action.settings.resource);
|
|
308
|
-
const saveTo =
|
|
286
|
+
const saveTo = yield form.project.getForm(action.settings.resource);
|
|
309
287
|
if (saveTo) {
|
|
310
288
|
if (!saveTo.handlers) {
|
|
311
289
|
error('Cannot find resource handlers.');
|
|
312
290
|
return next('Cannot find resource handlers.');
|
|
313
291
|
}
|
|
314
292
|
const handlers = req.method === 'PUT' ? saveTo.handlers.update : saveTo.handlers.create;
|
|
315
|
-
const childReq =
|
|
316
|
-
|
|
293
|
+
const childReq = appserver_core_1.Utils.childRequest(req);
|
|
294
|
+
if (!childReq) {
|
|
295
|
+
error('Failed to create child request');
|
|
296
|
+
return next('Failed to create child request');
|
|
297
|
+
}
|
|
298
|
+
childReq.body = exports.SaveAction.childSubmission(action, req, res, saveTo, childReq.body);
|
|
317
299
|
return async_1.default.series(handlers.map((handler) => async_1.default.apply(handler, childReq, res)), (err) => {
|
|
318
300
|
if (err) {
|
|
319
301
|
error(err);
|
|
320
302
|
return next(err);
|
|
321
303
|
}
|
|
322
304
|
// Set the child response based on the response of the subform.
|
|
323
|
-
exports.SaveAction.childResponse(
|
|
305
|
+
exports.SaveAction.childResponse(action, req, res, saveTo, childReq.body);
|
|
324
306
|
next();
|
|
325
307
|
});
|
|
326
308
|
}
|
|
327
309
|
}
|
|
328
310
|
// Save the submission.
|
|
329
|
-
req.
|
|
311
|
+
req.saveSubmission = true;
|
|
330
312
|
debug('Saving submission');
|
|
331
313
|
return next();
|
|
332
314
|
});
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.Database = void 0;
|
|
4
|
+
var db_1 = require("./mongodb/db");
|
|
5
5
|
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return db_1.Database; } });
|
|
6
|
-
const appserver_auth_jwt_1 = require("@formio/appserver-auth-jwt");
|
|
7
|
-
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return appserver_auth_jwt_1.Auth; } });
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { Collection, Document, Db, FindOptions, MongoClient } from 'mongodb';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export type DatabaseIndexResponse = {
|
|
5
|
-
items: Document[];
|
|
6
|
-
count: number;
|
|
7
|
-
skip: number;
|
|
8
|
-
limit: number;
|
|
9
|
-
};
|
|
2
|
+
import { Component, Submission } from '@formio/core';
|
|
3
|
+
import { ServerDB, DBConfig, AppServerForm, DatabaseIndexResponse } from '@formio/appserver-core';
|
|
10
4
|
export declare class Database implements ServerDB {
|
|
11
5
|
config: DBConfig;
|
|
12
6
|
db: Db | null;
|
|
@@ -15,103 +9,108 @@ export declare class Database implements ServerDB {
|
|
|
15
9
|
currentCollection: Collection<Document> | null;
|
|
16
10
|
defaultCollection: Collection<Document> | null;
|
|
17
11
|
prefix: string;
|
|
12
|
+
authQuery: any;
|
|
18
13
|
constructor(config: DBConfig);
|
|
19
14
|
ObjectId(id: any): any;
|
|
20
15
|
collectionName(name: string): string;
|
|
21
16
|
/**
|
|
22
17
|
* Connect to the database.
|
|
23
|
-
* @param {*} scope
|
|
24
18
|
* @returns
|
|
25
19
|
*/
|
|
26
20
|
connect(prefix?: string): Promise<void>;
|
|
27
21
|
close(): Promise<void>;
|
|
28
22
|
collection(name: string): Collection<Document> | null;
|
|
29
|
-
save(collectionName: string, item: any): Promise<
|
|
30
|
-
saveOne(collectionName: string, item: any): Promise<
|
|
31
|
-
load(collectionName: string,
|
|
32
|
-
|
|
23
|
+
save(collectionName: string, item: any): Promise<any | null>;
|
|
24
|
+
saveOne(collectionName: string, item: any): Promise<any>;
|
|
25
|
+
load(collectionName: string, dbQuery?: {}): Promise<any | null>;
|
|
26
|
+
indexAuth(query: any): void;
|
|
27
|
+
getQueryValue(name: string, value: string, selector: string): string | boolean | Date | null;
|
|
28
|
+
/**
|
|
29
|
+
* Converts the url query to query parameters.
|
|
30
|
+
* @param query
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
dbQuery(query?: Record<string, string>): any;
|
|
34
|
+
remove(collectionName: string, dbQuery?: {}): Promise<number | null>;
|
|
33
35
|
/**
|
|
34
36
|
* Ensures the form collection is created an returns it.
|
|
35
|
-
* @param scope
|
|
36
37
|
* @returns
|
|
37
38
|
*/
|
|
38
|
-
formCollection(
|
|
39
|
+
formCollection(form: AppServerForm): Promise<Collection<Document> | null>;
|
|
39
40
|
/**
|
|
40
41
|
* Setup indexes.
|
|
41
42
|
*/
|
|
42
|
-
setupIndexes(collection: Collection<Document> | null,
|
|
43
|
+
setupIndexes(collection: Collection<Document> | null, form?: AppServerForm): Promise<void>;
|
|
43
44
|
/**
|
|
44
45
|
* Add a field index
|
|
45
46
|
*/
|
|
46
47
|
addIndex(collection: Collection<Document> | null, path: string): Promise<void>;
|
|
47
48
|
/**
|
|
48
49
|
* Adds new indexes to the forms submission collection.
|
|
49
|
-
* @param scope
|
|
50
50
|
* @param indexes
|
|
51
51
|
* @returns
|
|
52
52
|
*/
|
|
53
|
-
addIndexes(
|
|
53
|
+
addIndexes(form: AppServerForm, indexes: string[]): Promise<void>;
|
|
54
54
|
/**
|
|
55
55
|
* Remove a field index.
|
|
56
56
|
*/
|
|
57
57
|
removeIndex(collection: Collection<Document>, path: string): Promise<void>;
|
|
58
58
|
/**
|
|
59
59
|
* Removes indexes to the forms submission collection.
|
|
60
|
-
* @param scope
|
|
61
60
|
* @param indexes
|
|
62
61
|
* @returns
|
|
63
62
|
*/
|
|
64
|
-
removeIndexes(
|
|
63
|
+
removeIndexes(form: AppServerForm, indexes: string[]): Promise<void>;
|
|
65
64
|
/**
|
|
66
65
|
* Fetch a list of submissions from a table/collection.
|
|
67
66
|
* @param {*} table
|
|
68
67
|
* @param {*} query
|
|
69
68
|
*/
|
|
70
|
-
index(
|
|
69
|
+
index(form: AppServerForm, urlQuery?: any, collection?: Collection<Document> | null): Promise<DatabaseIndexResponse<Submission>>;
|
|
71
70
|
/**
|
|
72
71
|
* Perform a count of the amount of documents within a collection.
|
|
73
|
-
* @param
|
|
72
|
+
* @param form
|
|
74
73
|
* @param query
|
|
75
74
|
* @returns
|
|
76
75
|
*/
|
|
77
|
-
count(
|
|
76
|
+
count(form: AppServerForm, dbQuery?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<number>;
|
|
78
77
|
/**
|
|
79
78
|
* Create a new record.
|
|
80
79
|
*/
|
|
81
|
-
create(
|
|
80
|
+
create(form: AppServerForm, record: any, allowFields?: string[]): Promise<Submission | null>;
|
|
82
81
|
/**
|
|
83
82
|
* Return a query for a single mongo record.
|
|
84
83
|
* @param {*} form
|
|
85
84
|
* @param {*} id
|
|
86
85
|
* @returns
|
|
87
86
|
*/
|
|
88
|
-
query(
|
|
87
|
+
query(form: AppServerForm, query?: any, includeAll?: boolean): any;
|
|
89
88
|
/**
|
|
90
89
|
* Find many records that match a query.
|
|
91
90
|
*/
|
|
92
|
-
find(
|
|
91
|
+
find(form: AppServerForm, dbQuery?: any, limit?: number, skip?: number, sort?: any, select?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<any | null>;
|
|
93
92
|
/**
|
|
94
93
|
* Find a record for a provided query.
|
|
95
94
|
*/
|
|
96
|
-
findOne(
|
|
95
|
+
findOne(form: AppServerForm, dbQuery?: any, options?: FindOptions<Document>): Promise<Submission | null>;
|
|
97
96
|
/**
|
|
98
97
|
* Read a single submission from a form
|
|
99
98
|
*
|
|
100
99
|
* @param {*} table
|
|
101
100
|
* @param {*} query
|
|
102
101
|
*/
|
|
103
|
-
read(
|
|
102
|
+
read(form: AppServerForm, id: string | undefined): Promise<Submission | null>;
|
|
104
103
|
/**
|
|
105
104
|
* Update a single submission of a form.
|
|
106
105
|
*
|
|
107
106
|
* @param {*} table
|
|
108
107
|
* @param {*} query
|
|
109
108
|
*/
|
|
110
|
-
update(
|
|
109
|
+
update(form: AppServerForm, id: string | undefined, update: any, allowFields?: string[]): Promise<Submission | null>;
|
|
111
110
|
/**
|
|
112
111
|
* Delete a record from the database.
|
|
113
112
|
*/
|
|
114
|
-
delete(
|
|
113
|
+
delete(form: AppServerForm, id: string | undefined, hard?: boolean): Promise<boolean>;
|
|
115
114
|
addPathQueryParams(pathQueryParams: any, query: any, path: string): void;
|
|
116
115
|
/**
|
|
117
116
|
* Performs a unique query on the database to see if a value is unique.
|
|
@@ -119,10 +118,10 @@ export declare class Database implements ServerDB {
|
|
|
119
118
|
* - If the value is not unique, it returns the id of the non-unique submission.
|
|
120
119
|
* - If an error occurs, or uniqueness cannot be determined, it will throw an error.
|
|
121
120
|
*
|
|
122
|
-
* @param
|
|
121
|
+
* @param form
|
|
123
122
|
* @param context
|
|
124
123
|
* @param value
|
|
125
124
|
* @returns
|
|
126
125
|
*/
|
|
127
|
-
isUnique(
|
|
126
|
+
isUnique(form: AppServerForm, component: Component, submission: Submission, componentPath: string, value: any): Promise<boolean | string>;
|
|
128
127
|
}
|