@formio/appserver 2.12.1 → 2.13.0

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.
@@ -171,7 +171,7 @@ exports.LoginAction = {
171
171
  }
172
172
  return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
173
173
  debug('Login Action');
174
- const result = yield (loginProvider === null || loginProvider === void 0 ? void 0 : loginProvider.login(req.auth, req.body, actionForm));
174
+ const result = yield loginProvider === null || loginProvider === void 0 ? void 0 : loginProvider.login(req.auth, req.body, actionForm);
175
175
  if (!result) {
176
176
  return next('Unable to login');
177
177
  }
@@ -20,7 +20,7 @@ export declare class Database implements ServerDB {
20
20
  close(): Promise<void>;
21
21
  collection(name: string): Collection<Document> | null;
22
22
  save(collectionName: string, item: any): Promise<any | null>;
23
- saveOne(collectionName: string, item: any): Promise<any>;
23
+ saveOne<T>(collectionName: string, item: T): Promise<T | null>;
24
24
  load(collectionName: string, dbQuery?: {}): Promise<any | null>;
25
25
  getQueryValue(name: string, value: string, selector: string): string | boolean | Date | null;
26
26
  /**
@@ -130,17 +130,18 @@ class Database {
130
130
  if (!collection) {
131
131
  return null;
132
132
  }
133
- if (!item._id) {
134
- // Try to load an existing record if one exists.
135
- let existing = yield this.load(collectionName);
136
- if (existing && !existing._id) {
137
- existing._id = new mongodb_1.ObjectId();
138
- const result = yield collection.insertOne(existing);
139
- existing = yield collection.findOne({ _id: this.ObjectId(result.insertedId) });
140
- }
141
- item._id = existing === null || existing === void 0 ? void 0 : existing._id;
133
+ try {
134
+ debug('db.saveOne()', collectionName);
135
+ // Use an atomic findOneAndReplace with upsert to ensure only a single record exists.
136
+ // Find any existing record and replace it, or insert if none exists.
137
+ const filter = item._id ? { _id: this.ObjectId(item._id) } : {};
138
+ const result = yield collection.findOneAndReplace(filter, (0, lodash_1.omit)(item, '_id'), { upsert: true, returnDocument: 'after' });
139
+ return result;
140
+ }
141
+ catch (err) {
142
+ error(err.message);
142
143
  }
143
- return yield this.save(collectionName, item);
144
+ return null;
144
145
  });
145
146
  }
146
147
  // Generic load record method.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/appserver",
3
- "version": "2.12.1",
3
+ "version": "2.13.0",
4
4
  "description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
5
5
  "main": "lib/server.js",
6
6
  "types": "lib/server.d.ts",
@@ -33,16 +33,16 @@
33
33
  ],
34
34
  "homepage": "https://github.com/formio/appserver#readme",
35
35
  "dependencies": {
36
- "@formio/appserver-core": "^2.12.1",
37
- "@formio/core": "2.5.1-dev.291.6557e4e",
36
+ "@formio/appserver-core": "^2.13.0",
37
+ "@formio/core": "2.8.0",
38
38
  "async": "^3.2.6",
39
39
  "bcryptjs": "^3.0.3",
40
40
  "debug": "^4.4.3",
41
- "dotenv": "^17.3.1",
41
+ "dotenv": "^17.4.2",
42
42
  "express": "^5.2.1",
43
43
  "jsonwebtoken": "^9.0.3",
44
- "lodash": "^4.17.23",
45
- "mongodb": "^7.1.0"
44
+ "lodash": "^4.18.1",
45
+ "mongodb": "^7.5.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/async": "^3.2.25",
@@ -50,15 +50,16 @@
50
50
  "@types/chai": "^5.2.3",
51
51
  "@types/express": "^5.0.6",
52
52
  "@types/jsonwebtoken": "^9.0.10",
53
- "@types/lodash": "^4.17.23",
53
+ "@types/lodash": "^4.17.24",
54
54
  "@types/mocha": "^10.0.10",
55
- "@types/node": "^25.3.0",
55
+ "@types/node": "^26.1.2",
56
56
  "chai": "^6.2.2",
57
57
  "cross-env": "^10.1.0",
58
- "mocha": "^11.7.5",
59
- "mongodb-memory-server": "^11.0.1",
58
+ "mocha": "^11.7.6",
59
+ "mongodb-memory-server": "^11.2.0",
60
60
  "ts-node": "^10.9.2",
61
61
  "tsconfig-paths": "^4.2.0",
62
- "typescript": "^5.9.3"
62
+ "tsx": "^4.23.1",
63
+ "typescript": "^7.0.2"
63
64
  }
64
65
  }