corebasic 1.0.148 → 1.0.149
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/libs/dip.js +14 -2
- package/package.json +1 -1
package/libs/dip.js
CHANGED
|
@@ -56,15 +56,27 @@ export const IdempotentDip = () => {
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
export const idip = async (message, callback, cleanup) => {
|
|
59
|
+
if (!callback)
|
|
60
|
+
throw {message: "Dip.idip() callback argument undefined"}
|
|
61
|
+
if (!cleanup)
|
|
62
|
+
throw {message: "Dip.idip() cleanup argument undefined"}
|
|
63
|
+
async function doCleanup(IDip) {
|
|
64
|
+
if (typeof cleanup === 'object') {
|
|
65
|
+
for (let collection in cleanup)
|
|
66
|
+
await IDip.cleanup(collection, { _id: {$in: cleanup[collection]} })
|
|
67
|
+
} else
|
|
68
|
+
await cleanup(IDip)
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
let IDip = await IdempotentDip().new(message.meta, message.txn)
|
|
60
72
|
if (!IDip) {
|
|
61
73
|
IDip = IdempotentDip().new(message.meta, message.txn, {blank: true})
|
|
62
|
-
await
|
|
74
|
+
await doCleanup(IDip)
|
|
63
75
|
return
|
|
64
76
|
}
|
|
65
77
|
await callback(IDip)
|
|
66
78
|
await IDip.finish()
|
|
67
|
-
await
|
|
79
|
+
await doCleanup(IDip)
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
|