@raymanselltickets/common 1.0.12 → 1.0.14
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/build/events/order-cancelled-event.d.ts +1 -0
- package/build/events/order-created-event.d.ts +1 -0
- package/build/events/ticket-created-event.d.ts +1 -0
- package/build/events/ticket-updated-event.d.ts +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/util/occ.d.ts +7 -0
- package/build/util/occ.js +21 -0
- package/package.json +3 -2
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
/**
|
|
3
|
+
* Implement optimistic concurrency control using a schema's version key.
|
|
4
|
+
*
|
|
5
|
+
* @param {mongoose.Schema} schema - A Mongoose schema to be plugged into.
|
|
6
|
+
*/
|
|
7
|
+
export function versionOCCPlugin(schema) {
|
|
8
|
+
// Get version key name
|
|
9
|
+
const versionKey = schema.get('versionKey');
|
|
10
|
+
assert(versionKey, 'document schema must have a version key');
|
|
11
|
+
// Add pre-save hook to check version
|
|
12
|
+
schema.pre('save', function () {
|
|
13
|
+
// Condition the save on the versions matching
|
|
14
|
+
this.$where = {
|
|
15
|
+
...this.$where,
|
|
16
|
+
[versionKey]: this.get(versionKey),
|
|
17
|
+
};
|
|
18
|
+
// Increment the version atomically
|
|
19
|
+
this.increment();
|
|
20
|
+
});
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raymanselltickets/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"cookie-session": "^2.1.1",
|
|
32
32
|
"express": "^5.2.1",
|
|
33
33
|
"express-validator": "^7.3.1",
|
|
34
|
-
"jsonwebtoken": "^9.0.3"
|
|
34
|
+
"jsonwebtoken": "^9.0.3",
|
|
35
|
+
"mongoose": "^9.1.2"
|
|
35
36
|
}
|
|
36
37
|
}
|