corebasic 1.0.60 → 1.0.62

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.
Files changed (3) hide show
  1. package/index.js +2 -0
  2. package/libs/dip.js +43 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
 
3
3
  import * as Elabase from './libs/elabase.js'
4
+ import * as Dip from './libs/dip.js'
4
5
  import * as Kafka from './libs/kafka.js'
5
6
  import * as Utils from './libs/utils.js'
6
7
  import * as Session from './libs/session.js'
@@ -9,6 +10,7 @@ import * as Features from './libs/features.js'
9
10
 
10
11
  export {
11
12
  Elabase,
13
+ Dip,
12
14
  Kafka,
13
15
  Utils,
14
16
  Session,
package/libs/dip.js ADDED
@@ -0,0 +1,43 @@
1
+ import * as Elabase from './elabase.js'
2
+
3
+ export const start = Elabase.start
4
+
5
+ export const insert = Elabase.insert
6
+ export const query = Elabase.query
7
+ export const update = Elabase.update
8
+ export const remove = Elabase.remove
9
+
10
+ export const transactionBegin = Elabase.transactionBegin
11
+ export const transactionAbort = Elabase.transactionAbort
12
+ export const transactionReset = Elabase.transactionReset
13
+ export const transactionCommit = Elabase.transactionCommit
14
+
15
+
16
+ export const IdempotentDip = () => {
17
+ return {
18
+ txn: '',
19
+ new: (async function (txn) {
20
+ this.txn = txn
21
+ return await Elabase.query("txns",{_id: this.txn}).length ? false : this
22
+ }),
23
+ insert: (async function (collection, query, data) {
24
+ await Elabase.update(collection, query, { $setOnInsert: data }, {upsert: true})
25
+ }),
26
+ update: (async function (collection, query, data, rollback) {
27
+ let token = { [this.txn]: true }
28
+ let idempotent = { [this.txn]: { $exists: rollback ?? false } }
29
+ await Elabase.update(collection, {...query, ...idempotent}, {...data, $setOnInsert: undefined, $set: {...(data.$set ?? {}), ...token} })
30
+ return await Elabase.query(collection, {...query, ...idempotent}).length
31
+ }),
32
+ upsert: (async function (collection, query, data, rollback) {
33
+ await this.idempotentInsert(collection, query, data.$setOnInsert)
34
+ return await this.update(collection, query, data, rollback)
35
+ }),
36
+ cleanup: (async function (collection, query) {
37
+ await Elabase.update(collection, query, { $unset: { [this.txn]: true } })
38
+ }),
39
+ finish: (async function () {
40
+ return await Elabase.upsert("txns",{_id: this.txn}, {}, {upsert: true})
41
+ })
42
+ }
43
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.60",
4
+ "version": "1.0.62",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {