corebasic 1.0.57 → 1.0.59

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/elabase.js CHANGED
@@ -55,6 +55,34 @@ export function start(dbName) {
55
55
  }
56
56
 
57
57
 
58
+ let isTransaction = false
59
+ let transactions = []
60
+ let stats = false
61
+
62
+ export function transactionBegin() {
63
+ isTransaction = true
64
+ transactions = []
65
+ }
66
+ export function transactionAbort() {
67
+ isTransaction = false
68
+ transactions = []
69
+ }
70
+ export function transactionReset() {
71
+ transactionAbort()
72
+ }
73
+ export function transactionCommit(arg) {
74
+ let txns = transactions
75
+ let mode = transactions.some(txn => txn.insert || txn.update || txn.delete) ? "command" : "query"
76
+ isTransaction = false
77
+ transactions = []
78
+ return new Promise((resolve, reject) => resolve())
79
+ .then(() => execute({ "transaction": txns, mode, stats: arg?.stats ?? false, version: arg.version }))
80
+ .then (result => {
81
+ Events.send("Elabase.transactionCommit", { response: result })
82
+ return result
83
+ })
84
+ }
85
+
58
86
  export const insert = async (collection, value, _id) => {
59
87
  var arg = {
60
88
  collection: collection,
@@ -63,6 +91,11 @@ export const insert = async (collection, value, _id) => {
63
91
  if (_id)
64
92
  arg._id = _id
65
93
 
94
+ if (isTransaction) {
95
+ transactions.push(arg)
96
+ return
97
+ }
98
+ arg.mode = "command"
66
99
  return new Promise((resolve, reject) => resolve())
67
100
  .then(() => execute(arg))
68
101
  .then(result => {
@@ -77,6 +110,11 @@ export const query = async (collection, query, options) => {
77
110
  query: query,
78
111
  options: options ? options : {},
79
112
  }
113
+ if (isTransaction) {
114
+ transactions.push(arg)
115
+ return
116
+ }
117
+ arg.mode = "query"
80
118
  return new Promise((resolve, reject) => resolve())
81
119
  .then(() => execute(arg))
82
120
  }
@@ -106,6 +144,11 @@ export const update = async (collection, query, update, options) => {
106
144
  update: update,
107
145
  options: options ? options : {},
108
146
  }
147
+ if (isTransaction) {
148
+ transactions.push(arg)
149
+ return
150
+ }
151
+ arg.mode = "command"
109
152
  return new Promise((resolve, reject) => resolve())
110
153
  .then(() => execute(arg))
111
154
  .then (result => {
@@ -120,6 +163,11 @@ export const remove = async (collection, query) => {
120
163
  query: query,
121
164
  delete: true,
122
165
  }
166
+ if (isTransaction) {
167
+ transactions.push(arg)
168
+ return
169
+ }
170
+ arg.mode = "command"
123
171
  return new Promise((resolve, reject) => resolve())
124
172
  .then(() => execute(arg))
125
173
  .then(result => {
@@ -131,7 +179,7 @@ export const remove = async (collection, query) => {
131
179
  function execute(arg) {
132
180
  // arg example
133
181
  // {
134
- // db: "sled-sandhra",
182
+ // db: "middle-earth",
135
183
  // collection: "staff",
136
184
  // query: "[@][?name == 'Bilbo'] | [0]",
137
185
  // insert: { "name": "Bilbo" },
@@ -143,6 +191,8 @@ function execute(arg) {
143
191
  arg.db = arg.db ?? db
144
192
  arg.engine = arg.engine ?? internal.engineName
145
193
 
194
+ if (stats)
195
+ arg.stats = true
146
196
 
147
197
  return axios
148
198
  .post(fullurl, arg)
package/libs/session.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as jwt from 'jsonwebtoken'
1
+ import jwt from 'jsonwebtoken'
2
2
  let app
3
3
 
4
4
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.57",
4
+ "version": "1.0.59",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {