corebasic 1.0.182 → 1.0.183
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 +4 -4
- package/libs/elabase.js +29 -20
- package/package.json +1 -1
package/libs/dip.js
CHANGED
|
@@ -8,10 +8,10 @@ export const query = Elabase.query
|
|
|
8
8
|
export const update = Elabase.update
|
|
9
9
|
export const remove = Elabase.remove
|
|
10
10
|
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
export const
|
|
11
|
+
export const batchBegin = Elabase.batchBegin
|
|
12
|
+
export const batchAbort = Elabase.batchAbort
|
|
13
|
+
export const batchReset = Elabase.batchReset
|
|
14
|
+
export const batchSubmit = Elabase.batchSubmit
|
|
15
15
|
|
|
16
16
|
export const shard_stats = Elabase.shard_stats
|
|
17
17
|
export let config = Elabase.config
|
package/libs/elabase.js
CHANGED
|
@@ -112,25 +112,26 @@ function generate_suffix(meta) {
|
|
|
112
112
|
return suffixes
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
let
|
|
116
|
-
let batches =
|
|
115
|
+
let BATCH_COUNTER = 0n;
|
|
116
|
+
let batches = {}
|
|
117
117
|
|
|
118
118
|
export function batchBegin() {
|
|
119
|
-
|
|
120
|
-
batches = []
|
|
119
|
+
const uid = ++BATCH_COUNTER; // Safe. No skew in async ++BATCH_COUNTER as single thread and ++COUNTER is atomic in event loop sense. ⚠️ Only breaks on worker_threads or cluster (multi-process)
|
|
120
|
+
batches[uid] = []
|
|
121
|
+
return uid
|
|
121
122
|
}
|
|
122
|
-
export function batchAbort() {
|
|
123
|
-
|
|
124
|
-
batches = []
|
|
123
|
+
export function batchAbort(batch_id) {
|
|
124
|
+
delete batches[batch_id]
|
|
125
125
|
}
|
|
126
126
|
export function batchReset() {
|
|
127
127
|
batchAbort()
|
|
128
128
|
}
|
|
129
|
-
export function batchSubmit(arg) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
export function batchSubmit(batch_id, arg) {
|
|
130
|
+
if (!batch_id || !batches[batch_id] || !batches[batch_id].length)
|
|
131
|
+
throw {message: `Error: Invalid batch in Dip.batchSubmit()`}
|
|
132
|
+
let txns = batches[batch_id]
|
|
133
|
+
let mode = batches[batch_id].some(txn => txn.insert || txn.update || txn.delete) ? "command" : "query"
|
|
134
|
+
delete batches[batch_id]
|
|
134
135
|
return new Promise((resolve, reject) => resolve())
|
|
135
136
|
.then(() => execute({ "batch": txns, mode, version: arg?.version, compression: arg?.compression }))
|
|
136
137
|
.then (result => {
|
|
@@ -167,8 +168,10 @@ export const insert = async (meta, collection, value, _id, extras) => {
|
|
|
167
168
|
throw {message: "Error: invalid _id in Dip.insert()"}
|
|
168
169
|
|
|
169
170
|
|
|
170
|
-
if (
|
|
171
|
-
batches.
|
|
171
|
+
if (meta.batch) {
|
|
172
|
+
if (!batches[meta.batch])
|
|
173
|
+
throw {message: 'Error: Invalid batch in Dip.insert()'}
|
|
174
|
+
batches[meta.batch].push(arg)
|
|
172
175
|
return
|
|
173
176
|
}
|
|
174
177
|
arg.mode = "command"
|
|
@@ -195,8 +198,10 @@ export const query = async (meta, collection, query, options, extras) => {
|
|
|
195
198
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
196
199
|
}
|
|
197
200
|
arg = Object.assign(arg, extras)
|
|
198
|
-
if (
|
|
199
|
-
batches.
|
|
201
|
+
if (meta.batch) {
|
|
202
|
+
if (!batches[meta.batch])
|
|
203
|
+
throw {message: 'Error: Invalid batch in Dip.query()'}
|
|
204
|
+
batches[meta.batch].push(arg)
|
|
200
205
|
return
|
|
201
206
|
}
|
|
202
207
|
arg.mode = "query"
|
|
@@ -238,8 +243,10 @@ export const update = async (meta, collection, query, update, options, extras) =
|
|
|
238
243
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
239
244
|
}
|
|
240
245
|
arg = Object.assign(arg, extras)
|
|
241
|
-
if (
|
|
242
|
-
batches.
|
|
246
|
+
if (meta.batch) {
|
|
247
|
+
if (!batches[meta.batch])
|
|
248
|
+
throw {message: 'Error: Invalid batch in Dip.update()'}
|
|
249
|
+
batches[meta.batch].push(arg)
|
|
243
250
|
return
|
|
244
251
|
}
|
|
245
252
|
arg.mode = "command"
|
|
@@ -270,8 +277,10 @@ export const remove = async (meta, collection, query, options, extras) => {
|
|
|
270
277
|
...(meta.DIP_DB ? {db: meta.DIP_DB} : {}),
|
|
271
278
|
}
|
|
272
279
|
arg = Object.assign(arg, extras)
|
|
273
|
-
if (
|
|
274
|
-
batches.
|
|
280
|
+
if (meta.batch) {
|
|
281
|
+
if (!batches[meta.batch])
|
|
282
|
+
throw {message: 'Error: Invalid batch in Dip.query()'}
|
|
283
|
+
batches[meta.batch].push(arg)
|
|
275
284
|
return
|
|
276
285
|
}
|
|
277
286
|
arg.mode = "command"
|