@formio/appserver 2.0.0-dev.3 → 2.0.0-dev.30

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.
@@ -15,12 +15,12 @@ declare const _default: {
15
15
  method: boolean;
16
16
  };
17
17
  };
18
- mappingComponents(scope: import("../types/lib").ActionScope): Promise<any>;
19
- settingsForm(scope: import("../types/lib").ActionScope): Promise<any>;
20
- saveToForm(scope: import("../types/lib").ActionScope, resource: string): undefined;
21
- childSubmission(scope: import("../types/lib").ActionScope, req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, submission: any): any;
22
- childResponse(scope: import("../types/lib").ActionScope, req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse): void;
23
- executor(scope: import("../types/lib").ActionScope): Promise<(req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
18
+ mappingComponents(scope: import("src/types/lib").ActionScope): Promise<any>;
19
+ settingsForm(scope: import("src/types/lib").ActionScope): Promise<any>;
20
+ saveToForm(scope: import("src/types/lib").ActionScope, resource: string): undefined;
21
+ childSubmission(scope: import("src/types/lib").ActionScope, req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, submission: any): any;
22
+ childResponse(scope: import("src/types/lib").ActionScope, req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse): void;
23
+ executor(scope: import("src/types/lib").ActionScope): Promise<(req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
24
24
  };
25
25
  login: {
26
26
  readonly info: {
@@ -37,7 +37,7 @@ declare const _default: {
37
37
  method: boolean;
38
38
  };
39
39
  };
40
- settingsForm(scope: import("../types/lib").ActionScope): Promise<({
40
+ settingsForm(scope: import("src/types/lib").ActionScope): Promise<({
41
41
  type: string;
42
42
  label: string;
43
43
  key: string;
@@ -103,8 +103,8 @@ declare const _default: {
103
103
  validate?: undefined;
104
104
  })[]>;
105
105
  waitText(time: number): string;
106
- checkAttempts(scope: import("../types/lib").ActionScope, error: any, user: import("../types/lib").User): Promise<any>;
107
- executor(scope: import("../types/lib").ActionScope): Promise<(req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
106
+ checkAttempts(scope: import("src/types/lib").ActionScope, error: any, user: import("src/types/lib").User): Promise<any>;
107
+ executor(scope: import("src/types/lib").ActionScope): Promise<(req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void>>;
108
108
  };
109
109
  role: {
110
110
  readonly info: {
@@ -121,7 +121,7 @@ declare const _default: {
121
121
  method: boolean;
122
122
  };
123
123
  };
124
- settingsForm(scope: import("../types/lib").ActionScope): Promise<({
124
+ settingsForm(scope: import("src/types/lib").ActionScope): Promise<({
125
125
  type: string;
126
126
  input: boolean;
127
127
  label: string;
@@ -154,7 +154,7 @@ declare const _default: {
154
154
  required: boolean;
155
155
  };
156
156
  })[]>;
157
- executor(scope: import("../types/lib").ActionScope): Promise<(req: import("../types/lib").SubmissionRequest, res: import("../types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("../types/lib").SubmissionResponse>>;
157
+ executor(scope: import("src/types/lib").ActionScope): Promise<(req: import("src/types/lib").SubmissionRequest, res: import("src/types/lib").SubmissionResponse, next: import("express").NextFunction) => Promise<void | import("src/types/lib").SubmissionResponse>>;
158
158
  };
159
159
  };
160
160
  export default _default;
@@ -88,13 +88,13 @@ exports.SaveAction = {
88
88
  components: []
89
89
  };
90
90
  const toFields = [];
91
- yield scope.utils.eachComponent(form.components, (component) => {
91
+ yield scope.utils.eachComponentAsync(form.components, (component) => {
92
92
  if (['button'].indexOf(component.type) !== -1) {
93
93
  return;
94
94
  }
95
95
  toFields.push({ label: component.label || component.key, value: component.key });
96
96
  });
97
- yield scope.utils.eachComponent(scope.form.components, (component) => {
97
+ yield scope.utils.eachComponentAsync(scope.form.components, (component) => {
98
98
  if (['button'].indexOf(component.type) !== -1) {
99
99
  return;
100
100
  }
@@ -17,8 +17,8 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
17
  const debug = require('debug')('formio:auth');
18
18
  const error = require('debug')('formio:error');
19
19
  class Auth {
20
- token(user, secret, expire = 240) {
21
- return __awaiter(this, void 0, void 0, function* () {
20
+ token(user_1, secret_1) {
21
+ return __awaiter(this, arguments, void 0, function* (user, secret, expire = 240) {
22
22
  user = Object.assign({}, user);
23
23
  delete user.iat;
24
24
  delete user.exp;
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const find_1 = __importDefault(require("lodash/find"));
16
16
  const uniq_1 = __importDefault(require("lodash/uniq"));
17
17
  exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
18
- const { req, component } = scope;
18
+ const { component, submission } = scope;
19
19
  let { value } = scope;
20
20
  if (!value ||
21
21
  !component ||
@@ -43,7 +43,7 @@ exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
43
43
  value = (0, uniq_1.default)(value.map((val) => val._id ? val._id.toString() : val.toString()));
44
44
  // Iterate through each submissionAccess object and assign the appropriate access roles.
45
45
  component.submissionAccess.map((access) => {
46
- const perm = (0, find_1.default)(req.body.access, {
46
+ const perm = (0, find_1.default)(submission.access, {
47
47
  type: access.type,
48
48
  });
49
49
  if (perm) {
@@ -53,7 +53,7 @@ exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
53
53
  perm.resources = (0, uniq_1.default)(perm.resources.concat(value));
54
54
  }
55
55
  else {
56
- req.body.access.push({
56
+ submission.access.push({
57
57
  type: access.type,
58
58
  resources: value,
59
59
  });
@@ -5,5 +5,7 @@ export declare const Preppers: {
5
5
  persist: (scope: PrepScope) => Promise<void>;
6
6
  protect: (scope: PrepScope) => Promise<void>;
7
7
  password: (scope: PrepScope) => Promise<void>;
8
+ referenceLoad: (scope: PrepScope) => Promise<void>;
9
+ referenceSave: (scope: PrepScope) => Promise<void>;
8
10
  };
9
11
  export declare const Prepper: PrepperType;
@@ -19,19 +19,23 @@ const access_1 = __importDefault(require("./access"));
19
19
  const persist_1 = __importDefault(require("./persist"));
20
20
  const protect_1 = __importDefault(require("./protect"));
21
21
  const password_1 = __importDefault(require("./password"));
22
+ const reference_1 = require("./reference");
23
+ const core_1 = require("@formio/core");
22
24
  exports.Preppers = {
23
25
  bcrypt: bcrypt_1.default,
24
26
  access: access_1.default,
25
27
  persist: persist_1.default,
26
28
  protect: protect_1.default,
27
- password: password_1.default
29
+ password: password_1.default,
30
+ referenceLoad: reference_1.referenceLoad,
31
+ referenceSave: reference_1.referenceSave
28
32
  };
29
33
  const debug = require('debug')('formio:prepare');
30
34
  const error = require('debug')('formio:error');
31
35
  exports.Prepper = {
32
36
  preppers: {
33
- save: [exports.Preppers.persist, exports.Preppers.access, exports.Preppers.password, exports.Preppers.bcrypt],
34
- read: [exports.Preppers.protect]
37
+ save: [exports.Preppers.persist, exports.Preppers.access, exports.Preppers.password, exports.Preppers.bcrypt, exports.Preppers.referenceSave],
38
+ read: [exports.Preppers.protect, exports.Preppers.referenceLoad]
35
39
  },
36
40
  prepare(scope) {
37
41
  return __awaiter(this, void 0, void 0, function* () {
@@ -39,12 +43,10 @@ exports.Prepper = {
39
43
  const { type, form, submission } = scope;
40
44
  try {
41
45
  debug(`Preparing data for ${form.name}...`);
42
- yield scope.utils.eachComponentData(form.components, submission.data, (component, row, path) => __awaiter(this, void 0, void 0, function* () {
46
+ yield scope.utils.eachComponentDataAsync(form.components, submission.data, (component, compData, compRow, compPath) => __awaiter(this, void 0, void 0, function* () {
43
47
  if (exports.Prepper.preppers.hasOwnProperty(type)) {
44
48
  for (let i = 0; i < exports.Prepper.preppers[type].length; i++) {
45
- yield exports.Prepper.preppers[type][i](Object.assign(Object.assign({}, scope), { component,
46
- row,
47
- data, value: (0, get_1.default)(row, component.key), path }));
49
+ yield exports.Prepper.preppers[type][i](Object.assign(Object.assign({}, scope), { component, row: compRow, data, value: (0, get_1.default)(compData, compPath), path: core_1.Utils.getComponentAbsolutePath(component) }));
48
50
  }
49
51
  }
50
52
  }));
@@ -14,15 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const get_1 = __importDefault(require("lodash/get"));
16
16
  const set_1 = __importDefault(require("lodash/set"));
17
- const has_1 = __importDefault(require("lodash/has"));
18
17
  exports.default = (scope) => __awaiter(void 0, void 0, void 0, function* () {
19
18
  // Check if they do not provide a password in the save, but one exists in the current record.
20
19
  // Do not allow them to wipe out their password by saving data that does not include one.
21
20
  const { type, component, row, current, path, data } = scope;
22
- if (component.type === 'password' &&
23
- type === 'save' &&
24
- !(0, has_1.default)(row, component.key) &&
25
- (0, has_1.default)(current, `data.${path}`)) {
26
- (0, set_1.default)(data, path, (0, get_1.default)(current.data, path));
21
+ if (component.type === 'password' && type === 'save') {
22
+ const currentPass = (0, get_1.default)(current, `data.${path}`);
23
+ if (!(0, get_1.default)(row, component.key) && currentPass) {
24
+ (0, set_1.default)(data, path, currentPass);
25
+ }
27
26
  }
28
27
  });
@@ -0,0 +1,3 @@
1
+ import { PrepScope } from '@formio/appserver-types';
2
+ export declare const referenceLoad: (scope: PrepScope) => Promise<void>;
3
+ export declare const referenceSave: (scope: PrepScope) => Promise<void>;
@@ -0,0 +1,72 @@
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
+ exports.referenceSave = exports.referenceLoad = void 0;
16
+ const lodash_1 = require("lodash");
17
+ const protect_1 = __importDefault(require("./protect"));
18
+ const core_1 = require("@formio/core");
19
+ const getResource = (scope) => {
20
+ var _a, _b, _c, _d, _e;
21
+ const { component } = scope;
22
+ const resourceId = (_a = component.data) === null || _a === void 0 ? void 0 : _a.resource;
23
+ let resource = (_b = scope.server) === null || _b === void 0 ? void 0 : _b.project.forms[resourceId];
24
+ if (!resource) {
25
+ for (let name in (_c = scope.server) === null || _c === void 0 ? void 0 : _c.project.forms) {
26
+ const form = (_d = scope.server) === null || _d === void 0 ? void 0 : _d.project.forms[name].clientForm;
27
+ if (form._id.toString() === resourceId) {
28
+ resource = (_e = scope.server) === null || _e === void 0 ? void 0 : _e.project.forms[name];
29
+ break;
30
+ }
31
+ }
32
+ }
33
+ return resource;
34
+ };
35
+ const referenceLoad = (scope) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const { component, data, value, path } = scope;
37
+ if (!value) {
38
+ return;
39
+ }
40
+ if (component.reference) {
41
+ const resource = getResource(scope);
42
+ if (resource) {
43
+ const submission = yield resource.loadSubmission(value._id);
44
+ if (submission) {
45
+ // Make sure to protect this submission like any other submission output.
46
+ const context = Object.assign(Object.assign({}, scope), { data: {} });
47
+ yield scope.utils.eachComponentDataAsync(resource.clientForm.components, submission.data, (comp, compData, compRow, compPath) => __awaiter(void 0, void 0, void 0, function* () {
48
+ yield (0, protect_1.default)(Object.assign(Object.assign({}, context), { component: comp, row: compRow, data: context.data, value: (0, lodash_1.get)(compData, compPath), path: core_1.Utils.getComponentAbsolutePath(comp) }));
49
+ }));
50
+ submission.data = context.data;
51
+ (0, lodash_1.set)(data, path, submission);
52
+ }
53
+ }
54
+ }
55
+ });
56
+ exports.referenceLoad = referenceLoad;
57
+ const referenceSave = (scope) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const { component, data, value, path } = scope;
59
+ if (!value || !value._id) {
60
+ return;
61
+ }
62
+ if (component.reference && value._id) {
63
+ const resource = getResource(scope);
64
+ if (resource) {
65
+ (0, lodash_1.set)(data, path, {
66
+ _id: value._id,
67
+ form: resource.clientForm._id
68
+ });
69
+ }
70
+ }
71
+ });
72
+ exports.referenceSave = referenceSave;
package/lib/server.js CHANGED
@@ -7,13 +7,13 @@ exports.Actions = exports.Auth = exports.Database = exports.Prepper = exports.Se
7
7
  // Load the license key.
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const get_1 = __importDefault(require("lodash/get"));
10
- let licenseKey = (0, get_1.default)(process.env, 'LICENSE_KEY', '');
10
+ let licenseKey = (0, get_1.default)(process.env, 'APPSERVER_LICENSE', (0, get_1.default)(process.env, 'LICENSE_KEY', ''));
11
11
  if (!licenseKey) {
12
12
  try {
13
13
  licenseKey = fs_1.default.readFileSync(path_1.default.join((0, process_1.cwd)(), 'license.txt'), 'utf8');
14
14
  }
15
15
  catch (err) {
16
- console.log('No license key found. Please set the LICENSE_KEY environment variable or create a license.txt file in the root of the project.');
16
+ console.log('No license key found. Please set the APPSERVER_LICENSE environment variable or create a license.txt file in the root of the project.');
17
17
  }
18
18
  }
19
19
  const appserver_core_1 = require("@formio/appserver-core");
@@ -46,9 +46,10 @@ export interface DBConfig {
46
46
  export interface ServerDB {
47
47
  config: DBConfig;
48
48
  connect: (prefix?: string) => Promise<void>;
49
+ saveOne: (collection: string, doc: any) => Promise<any>;
49
50
  save: (collection: string, doc: any) => Promise<any>;
50
- load: (collection: string) => Promise<any>;
51
- remove: (collection: string) => Promise<any>;
51
+ load: (collection: string, query?: any) => Promise<any>;
52
+ remove: (collection: string, query?: any) => Promise<any>;
52
53
  index: (scope: FormScope, query: any) => Promise<any>;
53
54
  create: (scope: FormScope, doc: any, allowFields?: string[]) => Promise<any>;
54
55
  read: (scope: FormScope, id: string) => Promise<any>;
@@ -85,6 +86,7 @@ export interface ServerScope {
85
86
  template?: any;
86
87
  utils?: any;
87
88
  util?: any;
89
+ server?: any;
88
90
  hook?: (name: string, ...args: any[]) => void;
89
91
  licenseKey?: OfflineLicenseStruct;
90
92
  }
@@ -12,6 +12,7 @@ export interface SubmissionScope extends FormScope {
12
12
  export interface SubmissionRequest extends Request {
13
13
  user: any;
14
14
  token: any;
15
+ decoded: any;
15
16
  scope: any;
16
17
  admin: any;
17
18
  headers: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/appserver",
3
- "version": "2.0.0-dev.3",
3
+ "version": "2.0.0-dev.30",
4
4
  "description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
5
5
  "main": "server.js",
6
6
  "scripts": {
@@ -29,30 +29,32 @@
29
29
  ],
30
30
  "homepage": "https://github.com/formio/appserver#readme",
31
31
  "dependencies": {
32
- "@formio/appserver-auth-jwt": "^2.0.0-dev.1",
33
- "@formio/appserver-core": "^2.0.0-dev.4",
34
- "@formio/appserver-db-mongodb": "^2.0.0-dev.1",
35
- "@formio/appserver-types": "^2.0.0-dev.1",
36
- "@formio/core": "^2.0.0-dev.3",
37
- "async": "^3.2.4",
32
+ "@formio/appserver-auth-jwt": "^2.0.0-dev.9",
33
+ "@formio/appserver-core": "^2.0.0-dev.28",
34
+ "@formio/appserver-db-mongodb": "^2.0.0-dev.9",
35
+ "@formio/appserver-types": "^2.0.0-dev.10",
36
+ "@formio/core": "^2.1.0-dev.tt.7",
37
+ "@formio/license": "^2.0.0-dev.4",
38
+ "@formio/vm": "^0.1.0-dev.tt.1",
39
+ "async": "^3.2.5",
38
40
  "bcryptjs": "^2.4.3",
39
41
  "debug": "^4.3.4",
40
- "dotenv": "^16.0.3",
41
- "express": "^4.18.2",
42
- "jsonwebtoken": "^9.0.0",
42
+ "dotenv": "^16.4.5",
43
+ "express": "^4.19.2",
44
+ "jsonwebtoken": "^9.0.2",
43
45
  "lodash": "^4.17.21"
44
46
  },
45
47
  "devDependencies": {
46
- "@types/async": "^3.2.20",
47
- "@types/bcryptjs": "^2.4.2",
48
- "@types/express": "^4.17.17",
49
- "@types/jsonwebtoken": "^9.0.2",
50
- "@types/lodash": "^4.14.194",
51
- "@types/mocha": "^10.0.1",
52
- "@types/node": "^20.1.1",
53
- "mocha": "^10.2.0",
54
- "ts-node": "^10.9.1",
48
+ "@types/async": "^3.2.24",
49
+ "@types/bcryptjs": "^2.4.6",
50
+ "@types/express": "^4.17.21",
51
+ "@types/jsonwebtoken": "^9.0.6",
52
+ "@types/lodash": "^4.17.0",
53
+ "@types/mocha": "^10.0.6",
54
+ "@types/node": "^20.12.7",
55
+ "mocha": "^10.4.0",
56
+ "ts-node": "^10.9.2",
55
57
  "tsconfig-paths": "^4.2.0",
56
- "typescript": "^5.0.4"
58
+ "typescript": "^5.4.5"
57
59
  }
58
60
  }
package/lib/auth.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { AuthModule, AuthToken } from '@formio/appserver-types';
2
- export declare class Auth implements AuthModule {
3
- token(user: AuthToken, secret: string, expire?: number): Promise<string>;
4
- user(token: string, secret: string): Promise<AuthToken | null>;
5
- }
package/lib/auth.js DELETED
@@ -1,70 +0,0 @@
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
- exports.Auth = void 0;
16
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
- const debug = require('debug')('formio:auth');
18
- const error = require('debug')('formio:error');
19
- class Auth {
20
- token(user, secret, expire = 240) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- user = Object.assign({}, user);
23
- delete user.iat;
24
- delete user.exp;
25
- return new Promise((resolve, reject) => {
26
- if (!secret) {
27
- return reject(new Error('You cannot generate a token without a secret!'));
28
- }
29
- debug('auth.token()', user);
30
- jsonwebtoken_1.default.sign(user, secret, {
31
- expiresIn: expire * 60,
32
- }, (err, signed) => {
33
- if (err) {
34
- error(err);
35
- return reject(err);
36
- }
37
- resolve(signed || '');
38
- });
39
- });
40
- });
41
- }
42
- user(token, secret) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- if (!token) {
45
- return Promise.resolve(null);
46
- }
47
- return new Promise((resolve, reject) => {
48
- if (!secret) {
49
- return reject('You cannot authenticate without a JWT Secret!');
50
- }
51
- debug('auth.verify()', token);
52
- jsonwebtoken_1.default.verify(token, secret, (err, payload) => {
53
- if (err) {
54
- error(err);
55
- if (err.name === 'JsonWebTokenError') {
56
- return reject({ message: 'Bad Token' });
57
- }
58
- if (err.name === 'TokenExpiredError') {
59
- return reject({ message: 'Token Expired' });
60
- }
61
- return reject(err);
62
- }
63
- debug('auth.user()', payload);
64
- resolve(payload);
65
- });
66
- });
67
- });
68
- }
69
- }
70
- exports.Auth = Auth;
package/lib/db.d.ts DELETED
@@ -1,97 +0,0 @@
1
- import { Collection, Db } from 'mongodb';
2
- import { DBConfig, ServerDB, FormScope } from '@formio/appserver-types';
3
- export declare class Database implements ServerDB {
4
- config: DBConfig;
5
- db: Db | null;
6
- currentCollectionName: string;
7
- currentCollection: Collection<Document> | null;
8
- defaultCollection: Collection<Document> | null;
9
- prefix: string;
10
- constructor(config: DBConfig);
11
- ObjectId(id: any): any;
12
- collectionName(name: string): string;
13
- /**
14
- * Connect to the database.
15
- * @param {*} scope
16
- * @returns
17
- */
18
- connect(prefix?: string): Promise<void>;
19
- save(collectionName: string, item: any): Promise<import("mongodb").WithId<import("bson").Document> | null>;
20
- load(collectionName: string): Promise<import("mongodb").WithId<import("bson").Document> | null | undefined>;
21
- remove(collectionName: string): Promise<number | null>;
22
- /**
23
- * Ensures the form collection is created an returns it.
24
- * @param scope
25
- * @returns
26
- */
27
- formCollection(scope: FormScope): Promise<Collection<Document> | null>;
28
- /**
29
- * Setup indexes.
30
- */
31
- setupIndexes(collection: Collection<Document> | null, scope?: FormScope): Promise<void>;
32
- /**
33
- * Add a field index
34
- */
35
- addIndex(collection: Collection<Document>, path: string): Promise<void>;
36
- /**
37
- * Adds new indexes to the forms submission collection.
38
- * @param scope
39
- * @param indexes
40
- * @returns
41
- */
42
- addIndexes(scope: FormScope, indexes: string[]): Promise<void>;
43
- /**
44
- * Remove a field index.
45
- */
46
- removeIndex(collection: Collection<Document>, path: string): Promise<void>;
47
- /**
48
- * Removes indexes to the forms submission collection.
49
- * @param scope
50
- * @param indexes
51
- * @returns
52
- */
53
- removeIndexes(scope: FormScope, indexes: string[]): Promise<void>;
54
- /**
55
- * Fetch a list of submissions from a table/collection.
56
- * @param {*} table
57
- * @param {*} query
58
- */
59
- index(scope: FormScope, query?: {}): Promise<import("mongodb").WithId<Document>[] | undefined>;
60
- /**
61
- * Create a new record.
62
- */
63
- create(scope: FormScope, record: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null | undefined>;
64
- /**
65
- * Return a query for a single mongo record.
66
- * @param {*} form
67
- * @param {*} id
68
- * @returns
69
- */
70
- query(scope: FormScope, query?: any): any;
71
- /**
72
- * Find many records that match a query.
73
- */
74
- find(scope: FormScope, query?: any): Promise<import("mongodb").WithId<Document>[]>;
75
- /**
76
- * Find a record for a provided query.
77
- */
78
- findOne(scope: FormScope, query?: any): Promise<import("mongodb").WithId<Document> | null>;
79
- /**
80
- * Read a single submission from a form
81
- *
82
- * @param {*} table
83
- * @param {*} query
84
- */
85
- read(scope: FormScope, id: string): Promise<import("mongodb").WithId<Document> | null>;
86
- /**
87
- * Update a single submission of a form.
88
- *
89
- * @param {*} table
90
- * @param {*} query
91
- */
92
- update(scope: FormScope, id: string, update: any, allowFields?: string[]): Promise<import("mongodb").WithId<Document> | null>;
93
- /**
94
- * Delete a record from the database.
95
- */
96
- delete(scope: FormScope, id: string): Promise<boolean>;
97
- }