ueberdb2 4.1.37 → 4.1.38
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/dist/index.js +25 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -738,7 +738,7 @@ const nullLogger = normalizeLogger(null);
|
|
|
738
738
|
// Format: All characters match themselves except * matches any zero or more characters. No
|
|
739
739
|
// backslash escaping is supported, so it is impossible to create a pattern that matches only the
|
|
740
740
|
// '*' character.
|
|
741
|
-
const simpleGlobToRegExp
|
|
741
|
+
const simpleGlobToRegExp = (s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
742
742
|
class AbstractDatabase {
|
|
743
743
|
logger;
|
|
744
744
|
// @ts-ignore
|
|
@@ -758,9 +758,9 @@ class AbstractDatabase {
|
|
|
758
758
|
* For findKey regex. Used by document dbs like mongodb or dirty.
|
|
759
759
|
*/
|
|
760
760
|
createFindRegex(key, notKey) {
|
|
761
|
-
let regex = `^(?=${simpleGlobToRegExp
|
|
761
|
+
let regex = `^(?=${simpleGlobToRegExp(key)}$)`;
|
|
762
762
|
if (notKey != null)
|
|
763
|
-
regex += `(?!${simpleGlobToRegExp
|
|
763
|
+
regex += `(?!${simpleGlobToRegExp(notKey)}$)`;
|
|
764
764
|
return new RegExp(regex);
|
|
765
765
|
}
|
|
766
766
|
doBulk(operations, cb) {
|
|
@@ -102627,7 +102627,6 @@ const Database$b = class Database extends require$$0$7.EventEmitter {
|
|
|
102627
102627
|
};
|
|
102628
102628
|
settings.mock = this;
|
|
102629
102629
|
this.settings = settings;
|
|
102630
|
-
console.log("Initialized");
|
|
102631
102630
|
}
|
|
102632
102631
|
close(cb) {
|
|
102633
102632
|
this.emit('close', cb);
|
|
@@ -347100,7 +347099,9 @@ const DATABASE = 'ueberdb';
|
|
|
347100
347099
|
const STORE_WITH_DOT = 'store:';
|
|
347101
347100
|
const STORE = 'store';
|
|
347102
347101
|
const WILDCARD = '*';
|
|
347103
|
-
const
|
|
347102
|
+
const escapeId = (id) => {
|
|
347103
|
+
return id.replace(/[\W_]+/g, "_");
|
|
347104
|
+
};
|
|
347104
347105
|
const Database$1 = class SurrealDB extends AbstractDatabase {
|
|
347105
347106
|
_client;
|
|
347106
347107
|
constructor(settings) {
|
|
@@ -347127,9 +347128,14 @@ const Database$1 = class SurrealDB extends AbstractDatabase {
|
|
|
347127
347128
|
async get(key) {
|
|
347128
347129
|
if (this._client == null)
|
|
347129
347130
|
return null;
|
|
347130
|
-
const
|
|
347131
|
+
const keyEscaped = escapeId(key);
|
|
347132
|
+
const res = await this._client.select(STORE_WITH_DOT + keyEscaped);
|
|
347131
347133
|
if (res.length > 0) {
|
|
347132
|
-
|
|
347134
|
+
console.log("Get: ", res[0].key, key);
|
|
347135
|
+
if (res[0].key === key) {
|
|
347136
|
+
return res[0].value;
|
|
347137
|
+
}
|
|
347138
|
+
return null;
|
|
347133
347139
|
}
|
|
347134
347140
|
else {
|
|
347135
347141
|
return null;
|
|
@@ -347141,8 +347147,9 @@ const Database$1 = class SurrealDB extends AbstractDatabase {
|
|
|
347141
347147
|
if (notKey != null) {
|
|
347142
347148
|
const query = `SELECT key FROM store WHERE ${this.transformWildcard(key, 'key')} AND ${this.transformWildcardNegative(notKey, 'notKey')}`;
|
|
347143
347149
|
key = key.replace(WILDCARD, '');
|
|
347150
|
+
key = escapeId(key);
|
|
347144
347151
|
notKey = notKey.replace(WILDCARD, '');
|
|
347145
|
-
|
|
347152
|
+
notKey = escapeId(notKey);
|
|
347146
347153
|
const res = await this._client.query(query, { key: key, notKey: notKey });
|
|
347147
347154
|
// @ts-ignore
|
|
347148
347155
|
return this.transformResult(res);
|
|
@@ -347150,6 +347157,7 @@ const Database$1 = class SurrealDB extends AbstractDatabase {
|
|
|
347150
347157
|
else {
|
|
347151
347158
|
const query = `SELECT key FROM store WHERE ${this.transformWildcard(key, 'key')}`;
|
|
347152
347159
|
key = key.replace(WILDCARD, '');
|
|
347160
|
+
key = escapeId(key);
|
|
347153
347161
|
const res = await this._client.query(query, { key });
|
|
347154
347162
|
// @ts-ignore
|
|
347155
347163
|
return this.transformResult(res);
|
|
@@ -347185,57 +347193,47 @@ const Database$1 = class SurrealDB extends AbstractDatabase {
|
|
|
347185
347193
|
}
|
|
347186
347194
|
transformResult(res) {
|
|
347187
347195
|
const value = [];
|
|
347188
|
-
console.log("Outer result ", res);
|
|
347189
347196
|
res[0].result.forEach(k => {
|
|
347190
|
-
console.log("Resultat ", k);
|
|
347191
347197
|
value.push(k.key);
|
|
347192
347198
|
});
|
|
347193
347199
|
return value;
|
|
347194
347200
|
}
|
|
347195
|
-
/**
|
|
347196
|
-
* For findKey regex. Used by document dbs like mongodb or dirty.
|
|
347197
|
-
*/
|
|
347198
|
-
createFindRegex(key, notKey) {
|
|
347199
|
-
let regex = `^(?=${simpleGlobToRegExp(key)}$)`;
|
|
347200
|
-
if (notKey != null)
|
|
347201
|
-
regex += `(?!${simpleGlobToRegExp(notKey)}$)`;
|
|
347202
|
-
return new RegExp(regex);
|
|
347203
|
-
}
|
|
347204
347201
|
async set(key, value) {
|
|
347205
347202
|
if (this._client == null)
|
|
347206
347203
|
return null;
|
|
347204
|
+
const keyEscaped = escapeId(key);
|
|
347207
347205
|
const exists = await this.get(key);
|
|
347208
347206
|
if (exists) {
|
|
347209
|
-
|
|
347210
|
-
id:
|
|
347207
|
+
await this._client.update(STORE, {
|
|
347208
|
+
id: keyEscaped,
|
|
347211
347209
|
key: key,
|
|
347212
347210
|
value: value
|
|
347213
347211
|
});
|
|
347214
|
-
console.log("Update ", updatE);
|
|
347215
347212
|
}
|
|
347216
347213
|
else {
|
|
347217
|
-
|
|
347218
|
-
id:
|
|
347214
|
+
await this._client.create(STORE, {
|
|
347215
|
+
id: keyEscaped,
|
|
347219
347216
|
key: key,
|
|
347220
347217
|
value: value
|
|
347221
347218
|
});
|
|
347222
|
-
console.log("Created ", created);
|
|
347223
347219
|
}
|
|
347224
347220
|
}
|
|
347225
347221
|
async remove(key) {
|
|
347226
347222
|
if (this._client == null)
|
|
347227
347223
|
return null;
|
|
347224
|
+
key = escapeId(key);
|
|
347228
347225
|
return await this._client.delete(STORE_WITH_DOT + key);
|
|
347229
347226
|
}
|
|
347230
347227
|
async doBulk(bulk) {
|
|
347231
347228
|
if (this._client == null)
|
|
347232
347229
|
return null;
|
|
347233
347230
|
bulk.forEach(b => {
|
|
347231
|
+
const key = escapeId(b.key);
|
|
347234
347232
|
if (b.type === 'set') {
|
|
347235
|
-
this._client.update(STORE +
|
|
347233
|
+
this._client.update(STORE + key, { key: key, value: b.value });
|
|
347236
347234
|
}
|
|
347237
347235
|
else if (b.type === 'remove') {
|
|
347238
|
-
this._client.delete(STORE +
|
|
347236
|
+
this._client.delete(STORE + key);
|
|
347239
347237
|
}
|
|
347240
347238
|
});
|
|
347241
347239
|
}
|