@formio/appserver 2.0.0-dev.9 → 2.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -16
- package/lib/actions/index.d.ts +11 -12
- package/lib/actions/login/LoginAction.d.ts +3 -2
- package/lib/actions/login/LoginAction.spec.d.ts +1 -0
- package/lib/actions/login/LoginAction.spec.js +15 -0
- package/lib/actions/role/RoleAction.spec.d.ts +1 -0
- package/lib/actions/role/RoleAction.spec.js +15 -0
- package/lib/actions/save/SaveAction.spec.d.ts +1 -0
- package/lib/actions/save/SaveAction.spec.js +15 -0
- package/lib/modules/auth/auth.spec.d.ts +1 -0
- package/lib/modules/auth/auth.spec.js +93 -0
- package/lib/modules/index.d.ts +1 -1
- package/lib/modules/index.js +2 -2
- package/lib/modules/mongodb/db.d.ts +128 -0
- package/lib/modules/mongodb/db.js +706 -0
- package/lib/modules/mongodb/db.spec.d.ts +1 -0
- package/lib/modules/mongodb/db.spec.js +714 -0
- package/lib/server.d.ts +3 -7
- package/lib/server.js +8 -12
- package/package.json +26 -25
- package/lib/prepare/access.d.ts +0 -3
- package/lib/prepare/access.js +0 -62
- package/lib/prepare/bcrypt.d.ts +0 -3
- package/lib/prepare/bcrypt.js +0 -25
- package/lib/prepare/index.d.ts +0 -11
- package/lib/prepare/index.js +0 -61
- package/lib/prepare/password.d.ts +0 -3
- package/lib/prepare/password.js +0 -27
- package/lib/prepare/persist.d.ts +0 -3
- package/lib/prepare/persist.js +0 -24
- package/lib/prepare/protect.d.ts +0 -3
- package/lib/prepare/protect.js +0 -28
- package/lib/prepare/reference.d.ts +0 -3
- package/lib/prepare/reference.js +0 -71
- package/lib/types/action.d.ts +0 -7
- package/lib/types/action.js +0 -2
- package/lib/types/form.d.ts +0 -4
- package/lib/types/form.js +0 -2
- package/lib/types/index.d.ts +0 -5
- package/lib/types/index.js +0 -21
- package/lib/types/project.d.ts +0 -4
- package/lib/types/project.js +0 -2
- package/lib/types/server.d.ts +0 -101
- package/lib/types/server.js +0 -2
- package/lib/types/submission.d.ts +0 -44
- package/lib/types/submission.js +0 -2
package/README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
## Form.io
|
|
2
|
-
The Form.io
|
|
1
|
+
## Form.io App Server
|
|
2
|
+
The Form.io App Server is a performant run-time application server used to serve single project templates (including forms, resources, roles, etc) at a single deployed endpoint.
|
|
3
|
+
|
|
4
|
+
It's goals are as follows:
|
|
5
|
+
- Provide a single project runtime server where non-submission resources are cached in memory.
|
|
6
|
+
- Enable multi-tenant / multi-database deployments.
|
|
7
|
+
- Provide extensible server-side functionality
|
|
8
|
+
- Support other databases besides MongoDB compliant databases for submission data.
|
|
3
9
|
|
|
4
10
|
### Installation
|
|
5
11
|
To use this library, you must mount it within an Express.js application. As an example, you can create a simple Express.js application with this library by first creating a new [Express.js application](https://expressjs.com/en/starter/installing.html) and then install and use the Server as follows.
|
|
6
12
|
|
|
7
13
|
```
|
|
8
|
-
npm install --save @formio/appserver
|
|
14
|
+
npm install --save @formio/appserver@rc
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
Then within your server.js file, you would add the following.
|
|
@@ -31,6 +37,9 @@ const { Server } = require('@formio/appserver');
|
|
|
31
37
|
})();
|
|
32
38
|
```
|
|
33
39
|
|
|
40
|
+
### License
|
|
41
|
+
The Form.io App Server does require a license to run. If you are interested in trying out this technology, please contact us @ https://form.io/contact-us
|
|
42
|
+
|
|
34
43
|
### Running Locally
|
|
35
44
|
To run this library locally, you can clone the repository, and then npm install.
|
|
36
45
|
|
|
@@ -58,27 +67,27 @@ This library uses environment variables to configure the configurations required
|
|
|
58
67
|
| MONGO | yes | Your MongoDB Connection string to use the default DB. | mongodb://localhost:27017/appserver |
|
|
59
68
|
| PROJECT_ENDPOINT | yes | The endpoint for your deployed Form.io Enterprise project. | https://mydeployment.com/myproject |
|
|
60
69
|
| PROJECT_KEY | yes | The API Key for your deployed Form.io Enterprise Project. | abc123 |
|
|
61
|
-
| LICENSE_KEY | yes | Your License Key for this
|
|
70
|
+
| LICENSE_KEY | yes | Your License Key for this App Server deployment. | <LONG LICENSE KEY> |
|
|
62
71
|
| PORT | no | The port that your server will run on. Default 3005 | 3005 |
|
|
63
72
|
| JWT_SECRET | yes | The key used to protect your JWT authentication tokens. | YOUR_SECRET_KEY |
|
|
64
73
|
| JWT_EXPIRE_TIME | no | The number of minutes to expire your JWT token. | 240 |
|
|
65
|
-
| PORTAL_SECRET | no | Provides the ability to connect to the
|
|
74
|
+
| PORTAL_SECRET | no | Provides the ability to connect to the App Server via the Remote Environment Connection within your Developer Portal. | YOUR_SECRET_KEY |
|
|
66
75
|
| PROJECT_CACHE | no | Disables the cache for project resources (such as Project template, Project Settings, and Access Settings). Default "true" | true |
|
|
67
76
|
| MONGO_CONFIG | no | Additional configurations to add to the DB connection string | {} |
|
|
68
77
|
|
|
69
78
|
### Developer Portal Connection
|
|
70
|
-
Once you have the
|
|
79
|
+
Once you have the App Server running within your own environment, and connected to your own database, you can now deploy your new changes to your forms, resources, project settings, etc. To accomplish this, you must first run the App Server using the ```PORTAL_SECRET``` described above.
|
|
71
80
|
|
|
72
81
|
Once you have this set, you can then log into your Developer Portal, and then navigate to your Project.
|
|
73
82
|
|
|
74
|
-
Once there, you will then go to your **Staging | Connect Environment**. Here you will put your
|
|
83
|
+
Once there, you will then go to your **Staging | Connect Environment**. Here you will put your App Server endpoint and the PORTAL_SECRET value. You will then want to set the **Project Path Type** to use **Subdirectory**. Then click **Continue**.
|
|
75
84
|
|
|
76
|
-
You will then see the next page, where you will select your Stage in the dropdown. You should see it since the
|
|
85
|
+
You will then see the next page, where you will select your Stage in the dropdown. You should see it since the App Server connects to the project on bootup.
|
|
77
86
|
|
|
78
|
-
Once you are connected, any changes you make within the Developer portal will now be directly reflected within your
|
|
87
|
+
Once you are connected, any changes you make within the Developer portal will now be directly reflected within your App Server deployment.
|
|
79
88
|
|
|
80
89
|
### Custom Configuration
|
|
81
|
-
The
|
|
90
|
+
The App Server is very extensible, and many things can be altered and modified as well as custom implementations of different components are possible using configurations.
|
|
82
91
|
|
|
83
92
|
The following configurations can be provided to the Server instance. Here are some configurations that are supported.
|
|
84
93
|
|
|
@@ -161,12 +170,18 @@ const { CustomAction } = require('./actions/custom');
|
|
|
161
170
|
*
|
|
162
171
|
* The "scope" argument is a ProcessScope type. See https://github.com/formio/appserver/blob/main/src/types/submission.ts
|
|
163
172
|
*/
|
|
164
|
-
processors:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
processors: {
|
|
174
|
+
submission: [
|
|
175
|
+
(scope) => {},
|
|
176
|
+
(scope) => {}
|
|
177
|
+
],
|
|
178
|
+
evaluator: [
|
|
179
|
+
(scope) => {}
|
|
180
|
+
],
|
|
181
|
+
prepare: [
|
|
182
|
+
(scope) => {}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
170
185
|
});
|
|
171
186
|
|
|
172
187
|
// Initialize the server.
|
package/lib/actions/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="express" />
|
|
2
1
|
declare const _default: {
|
|
3
2
|
save: {
|
|
4
3
|
readonly info: {
|
|
@@ -15,12 +14,12 @@ declare const _default: {
|
|
|
15
14
|
method: boolean;
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
|
-
mappingComponents(scope: import("
|
|
19
|
-
settingsForm(scope: import("
|
|
20
|
-
saveToForm(scope: import("
|
|
21
|
-
childSubmission(scope: import("
|
|
22
|
-
childResponse(scope: import("
|
|
23
|
-
executor(scope: import("
|
|
17
|
+
mappingComponents(scope: import("@formio/appserver-types").ActionScope): Promise<any>;
|
|
18
|
+
settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<any>;
|
|
19
|
+
saveToForm(scope: import("@formio/appserver-types").ActionScope, resource: string): undefined;
|
|
20
|
+
childSubmission(scope: import("@formio/appserver-types").ActionScope, req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, submission: any): any;
|
|
21
|
+
childResponse(scope: import("@formio/appserver-types").ActionScope, req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse): void;
|
|
22
|
+
executor(scope: import("@formio/appserver-types").ActionScope): Promise<(req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
|
|
24
23
|
};
|
|
25
24
|
login: {
|
|
26
25
|
readonly info: {
|
|
@@ -37,7 +36,7 @@ declare const _default: {
|
|
|
37
36
|
method: boolean;
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
|
-
settingsForm(scope: import("
|
|
39
|
+
settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<({
|
|
41
40
|
type: string;
|
|
42
41
|
label: string;
|
|
43
42
|
key: string;
|
|
@@ -103,8 +102,8 @@ declare const _default: {
|
|
|
103
102
|
validate?: undefined;
|
|
104
103
|
})[]>;
|
|
105
104
|
waitText(time: number): string;
|
|
106
|
-
checkAttempts(scope: import("
|
|
107
|
-
executor(scope: import("
|
|
105
|
+
checkAttempts(scope: import("@formio/appserver-types").ActionScope, error: any, user: import("@formio/core").Submission): Promise<any>;
|
|
106
|
+
executor(scope: import("@formio/appserver-types").ActionScope): Promise<(req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
|
|
108
107
|
};
|
|
109
108
|
role: {
|
|
110
109
|
readonly info: {
|
|
@@ -121,7 +120,7 @@ declare const _default: {
|
|
|
121
120
|
method: boolean;
|
|
122
121
|
};
|
|
123
122
|
};
|
|
124
|
-
settingsForm(scope: import("
|
|
123
|
+
settingsForm(scope: import("@formio/appserver-types").ActionScope): Promise<({
|
|
125
124
|
type: string;
|
|
126
125
|
input: boolean;
|
|
127
126
|
label: string;
|
|
@@ -154,7 +153,7 @@ declare const _default: {
|
|
|
154
153
|
required: boolean;
|
|
155
154
|
};
|
|
156
155
|
})[]>;
|
|
157
|
-
executor(scope: import("
|
|
156
|
+
executor(scope: import("@formio/appserver-types").ActionScope): Promise<(req: import("@formio/appserver-types").SubmissionRequest, res: import("@formio/appserver-types").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("@formio/appserver-types").SubmissionResponse>>;
|
|
158
157
|
};
|
|
159
158
|
};
|
|
160
159
|
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextFunction } from 'express';
|
|
2
|
-
import { ActionScope,
|
|
2
|
+
import { ActionScope, SubmissionRequest, SubmissionResponse } from '@formio/appserver-types';
|
|
3
|
+
import { Submission } from '@formio/core/types';
|
|
3
4
|
export declare const LoginAction: {
|
|
4
5
|
readonly info: {
|
|
5
6
|
name: string;
|
|
@@ -98,7 +99,7 @@ export declare const LoginAction: {
|
|
|
98
99
|
* @param next
|
|
99
100
|
* @returns {*}
|
|
100
101
|
*/
|
|
101
|
-
checkAttempts(scope: ActionScope, error: any, user:
|
|
102
|
+
checkAttempts(scope: ActionScope, error: any, user: Submission): Promise<any>;
|
|
102
103
|
/**
|
|
103
104
|
* Returns the action middleware.
|
|
104
105
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const LoginAction_1 = require("./LoginAction");
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
describe('LoginAction', () => {
|
|
9
|
+
it('Validate the LoginAction information', () => {
|
|
10
|
+
const info = LoginAction_1.LoginAction.info;
|
|
11
|
+
assert_1.default.equal(info.name, 'login');
|
|
12
|
+
assert_1.default.equal(info.title, 'Login');
|
|
13
|
+
});
|
|
14
|
+
it('TO-DO: Write tests for LoginAction');
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const RoleAction_1 = require("./RoleAction");
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
describe('RoleAction', () => {
|
|
9
|
+
it('Validate the RoleAction information', () => {
|
|
10
|
+
const info = RoleAction_1.RoleAction.info;
|
|
11
|
+
assert_1.default.equal(info.name, 'role');
|
|
12
|
+
assert_1.default.equal(info.title, 'Role Assignment');
|
|
13
|
+
});
|
|
14
|
+
it('TO-DO: Write tests for RoleAction');
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const SaveAction_1 = require("./SaveAction");
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
describe('SaveAction', () => {
|
|
9
|
+
it('Validate the SaveAction information', () => {
|
|
10
|
+
const info = SaveAction_1.SaveAction.info;
|
|
11
|
+
assert_1.default.equal(info.name, 'save');
|
|
12
|
+
assert_1.default.equal(info.title, 'Save Submission');
|
|
13
|
+
});
|
|
14
|
+
it('TO-DO: Write tests for SaveAction');
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const auth_1 = require("./auth");
|
|
16
|
+
const assert_1 = __importDefault(require("assert"));
|
|
17
|
+
describe('Auth', () => {
|
|
18
|
+
const user = {
|
|
19
|
+
user: {
|
|
20
|
+
_id: 'test',
|
|
21
|
+
data: {
|
|
22
|
+
firstName: 'Joe',
|
|
23
|
+
lastName: 'Smith',
|
|
24
|
+
email: 'joe@example.com'
|
|
25
|
+
},
|
|
26
|
+
roles: [
|
|
27
|
+
'1234',
|
|
28
|
+
'2468'
|
|
29
|
+
],
|
|
30
|
+
form: '234234243234234234',
|
|
31
|
+
project: '213312131213212334'
|
|
32
|
+
},
|
|
33
|
+
form: {
|
|
34
|
+
_id: '234234243234234234'
|
|
35
|
+
},
|
|
36
|
+
project: {
|
|
37
|
+
_id: '213312131213212334'
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
let token = '';
|
|
41
|
+
it('Should return a valid auth token for a valid user', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const auth = new auth_1.Auth();
|
|
43
|
+
token = yield auth.token(user, 'test', 240);
|
|
44
|
+
(0, assert_1.default)(token, 'It must generate a valid token');
|
|
45
|
+
}));
|
|
46
|
+
it('Should validate that the token is valid', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const auth = new auth_1.Auth();
|
|
48
|
+
const tokenUser = yield auth.user(token, 'test');
|
|
49
|
+
(0, assert_1.default)(tokenUser === null || tokenUser === void 0 ? void 0 : tokenUser.iat, 'It must have an iat');
|
|
50
|
+
(0, assert_1.default)(tokenUser === null || tokenUser === void 0 ? void 0 : tokenUser.exp, 'It must have an exp');
|
|
51
|
+
tokenUser === null || tokenUser === void 0 ? true : delete tokenUser.iat;
|
|
52
|
+
tokenUser === null || tokenUser === void 0 ? true : delete tokenUser.exp;
|
|
53
|
+
assert_1.default.deepEqual(tokenUser, user);
|
|
54
|
+
}));
|
|
55
|
+
it('Should throw an error with "Bad Token" for an invalid token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const auth = new auth_1.Auth();
|
|
57
|
+
try {
|
|
58
|
+
yield auth.user('invalid', 'test');
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
assert_1.default.equal(err.message, 'Bad Token');
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
it('Should throw an error with "Token Expired" for an expired token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const auth = new auth_1.Auth();
|
|
66
|
+
token = yield auth.token(user, 'test', 0);
|
|
67
|
+
try {
|
|
68
|
+
yield auth.user(token, 'test');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
assert_1.default.equal(err.message, 'Token Expired');
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
it('Should throw an error for a token without a secret', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const auth = new auth_1.Auth();
|
|
76
|
+
try {
|
|
77
|
+
yield auth.token(user, '');
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
assert_1.default.equal(err.message, 'You cannot generate a token without a secret!');
|
|
81
|
+
}
|
|
82
|
+
}));
|
|
83
|
+
it('Should throw an error for a token with the wrong secret', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const auth = new auth_1.Auth();
|
|
85
|
+
token = yield auth.token(user, 'test', 0);
|
|
86
|
+
try {
|
|
87
|
+
yield auth.user(token, '1234');
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
assert_1.default.equal(err.message, 'Bad Token');
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
});
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Auth = exports.Database = void 0;
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return
|
|
4
|
+
const db_1 = require("./mongodb/db");
|
|
5
|
+
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return db_1.Database; } });
|
|
6
6
|
const appserver_auth_jwt_1 = require("@formio/appserver-auth-jwt");
|
|
7
7
|
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return appserver_auth_jwt_1.Auth; } });
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Collection, Document, Db, FindOptions, MongoClient } from 'mongodb';
|
|
2
|
+
import { DBConfig, ServerDB, FormScope } from '@formio/appserver-types';
|
|
3
|
+
import { ValidationContext } from '@formio/core/types';
|
|
4
|
+
export type DatabaseIndexResponse = {
|
|
5
|
+
items: Document[];
|
|
6
|
+
count: number;
|
|
7
|
+
skip: number;
|
|
8
|
+
limit: number;
|
|
9
|
+
};
|
|
10
|
+
export declare class Database implements ServerDB {
|
|
11
|
+
config: DBConfig;
|
|
12
|
+
db: Db | null;
|
|
13
|
+
client: MongoClient | null;
|
|
14
|
+
currentCollectionName: string;
|
|
15
|
+
currentCollection: Collection<Document> | null;
|
|
16
|
+
defaultCollection: Collection<Document> | null;
|
|
17
|
+
prefix: string;
|
|
18
|
+
constructor(config: DBConfig);
|
|
19
|
+
ObjectId(id: any): any;
|
|
20
|
+
collectionName(name: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Connect to the database.
|
|
23
|
+
* @param {*} scope
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
connect(prefix?: string): Promise<void>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
collection(name: string): Collection<Document> | null;
|
|
29
|
+
save(collectionName: string, item: any): Promise<import("mongodb").WithId<Document> | null>;
|
|
30
|
+
saveOne(collectionName: string, item: any): Promise<import("mongodb").WithId<Document> | null>;
|
|
31
|
+
load(collectionName: string, query?: {}): Promise<import("mongodb").WithId<Document> | null | undefined>;
|
|
32
|
+
remove(collectionName: string, query?: {}): Promise<number | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Ensures the form collection is created an returns it.
|
|
35
|
+
* @param scope
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
formCollection(scope: FormScope): Promise<Collection<Document> | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Setup indexes.
|
|
41
|
+
*/
|
|
42
|
+
setupIndexes(collection: Collection<Document> | null, scope?: FormScope): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Add a field index
|
|
45
|
+
*/
|
|
46
|
+
addIndex(collection: Collection<Document> | null, path: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Adds new indexes to the forms submission collection.
|
|
49
|
+
* @param scope
|
|
50
|
+
* @param indexes
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
addIndexes(scope: FormScope, indexes: string[]): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Remove a field index.
|
|
56
|
+
*/
|
|
57
|
+
removeIndex(collection: Collection<Document>, path: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Removes indexes to the forms submission collection.
|
|
60
|
+
* @param scope
|
|
61
|
+
* @param indexes
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
removeIndexes(scope: FormScope, indexes: string[]): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Fetch a list of submissions from a table/collection.
|
|
67
|
+
* @param {*} table
|
|
68
|
+
* @param {*} query
|
|
69
|
+
*/
|
|
70
|
+
index(scope: FormScope, query?: any, collection?: Collection<Document> | null): Promise<DatabaseIndexResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* Perform a count of the amount of documents within a collection.
|
|
73
|
+
* @param scope
|
|
74
|
+
* @param query
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
count(scope: FormScope, query?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<number>;
|
|
78
|
+
/**
|
|
79
|
+
* Create a new record.
|
|
80
|
+
*/
|
|
81
|
+
create(scope: FormScope, record: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* Return a query for a single mongo record.
|
|
84
|
+
* @param {*} form
|
|
85
|
+
* @param {*} id
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
query(scope: FormScope, query?: any, includeAll?: boolean): any;
|
|
89
|
+
/**
|
|
90
|
+
* Find many records that match a query.
|
|
91
|
+
*/
|
|
92
|
+
find(scope: FormScope, query?: any, limit?: number, skip?: number, sort?: any, select?: any, inCollection?: Collection<Document> | null, includeDeleted?: boolean): Promise<Document[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Find a record for a provided query.
|
|
95
|
+
*/
|
|
96
|
+
findOne(scope: FormScope, query?: any, options?: FindOptions<Document>): Promise<import("mongodb").WithId<Document> | null>;
|
|
97
|
+
/**
|
|
98
|
+
* Read a single submission from a form
|
|
99
|
+
*
|
|
100
|
+
* @param {*} table
|
|
101
|
+
* @param {*} query
|
|
102
|
+
*/
|
|
103
|
+
read(scope: FormScope, id: string | undefined): Promise<import("mongodb").WithId<Document> | null>;
|
|
104
|
+
/**
|
|
105
|
+
* Update a single submission of a form.
|
|
106
|
+
*
|
|
107
|
+
* @param {*} table
|
|
108
|
+
* @param {*} query
|
|
109
|
+
*/
|
|
110
|
+
update(scope: FormScope, id: string | undefined, update: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Delete a record from the database.
|
|
113
|
+
*/
|
|
114
|
+
delete(scope: FormScope, id: string | undefined, hard?: boolean): Promise<boolean>;
|
|
115
|
+
addPathQueryParams(pathQueryParams: any, query: any, path: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Performs a unique query on the database to see if a value is unique.
|
|
118
|
+
* - If the value is unique, it returns true.
|
|
119
|
+
* - If the value is not unique, it returns the id of the non-unique submission.
|
|
120
|
+
* - If an error occurs, or uniqueness cannot be determined, it will throw an error.
|
|
121
|
+
*
|
|
122
|
+
* @param scope
|
|
123
|
+
* @param context
|
|
124
|
+
* @param value
|
|
125
|
+
* @returns
|
|
126
|
+
*/
|
|
127
|
+
isUnique(scope: FormScope, context: ValidationContext, value: any): Promise<boolean | string>;
|
|
128
|
+
}
|