@naturalcycles/datastore-lib 3.35.1 → 3.36.0
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/DatastoreStreamReadable.js +4 -1
- package/dist/query.util.js +16 -7
- package/package.json +10 -5
- package/src/DatastoreStreamReadable.ts +4 -1
- package/src/query.util.ts +14 -10
|
@@ -132,7 +132,10 @@ class DatastoreStreamReadable extends node_stream_1.Readable {
|
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
if (!this.running) {
|
|
135
|
-
void this.runNextQuery()
|
|
135
|
+
void this.runNextQuery().catch(err => {
|
|
136
|
+
console.log('error in runNextQuery', err);
|
|
137
|
+
this.emit('error', err);
|
|
138
|
+
});
|
|
136
139
|
}
|
|
137
140
|
else {
|
|
138
141
|
this.logger.log(`_read ${this.count}, wasRunning: true`);
|
package/dist/query.util.js
CHANGED
|
@@ -13,16 +13,25 @@ const OP_MAP = {
|
|
|
13
13
|
function dbQueryToDatastoreQuery(dbQuery, emptyQuery) {
|
|
14
14
|
let q = emptyQuery;
|
|
15
15
|
// filter
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
for (const f of dbQuery._filters) {
|
|
17
|
+
// keeping "previous syntax" commented out
|
|
18
|
+
// (q, f) => q.filter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val),
|
|
19
|
+
// Datastore doesn't allow `undefined` as filter value.
|
|
20
|
+
// We don't want to throw on it, so instead we'll replace it with valid value of `null`.
|
|
21
|
+
// `a > null` will return anything that's indexed
|
|
22
|
+
// `a < null` should return nothing
|
|
23
|
+
// `a == null` will return just that - rows with null values
|
|
24
|
+
let { op, val } = f;
|
|
25
|
+
if (val === undefined)
|
|
26
|
+
val = null;
|
|
27
|
+
q = q.filter(new datastore_1.PropertyFilter(f.name, OP_MAP[op] || op, val));
|
|
28
|
+
}
|
|
21
29
|
// limit
|
|
22
30
|
q = q.limit(dbQuery._limitValue || 0);
|
|
23
31
|
// order
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
for (const ord of dbQuery._orders) {
|
|
33
|
+
q = q.order(ord.name, { descending: ord.descending });
|
|
34
|
+
}
|
|
26
35
|
// select
|
|
27
36
|
if (dbQuery._selectedFieldNames) {
|
|
28
37
|
const fields = dbQuery._selectedFieldNames.map(f => FNAME_MAP[f] || f);
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/datastore-lib",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.36.0",
|
|
4
4
|
"description": "Opinionated library to work with Google Datastore",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"prepare": "husky"
|
|
6
|
+
"prepare": "husky",
|
|
7
|
+
"build": "dev-lib build",
|
|
8
|
+
"test": "dev-lib test",
|
|
9
|
+
"lint": "dev-lib lint",
|
|
10
|
+
"bt": "dev-lib bt",
|
|
11
|
+
"lbt": "dev-lib lbt"
|
|
7
12
|
},
|
|
8
13
|
"dependencies": {
|
|
9
14
|
"@google-cloud/datastore": "^9.0.0",
|
|
@@ -12,8 +17,8 @@
|
|
|
12
17
|
"@naturalcycles/nodejs-lib": "^13.1.0"
|
|
13
18
|
},
|
|
14
19
|
"devDependencies": {
|
|
15
|
-
"@naturalcycles/dev-lib": "^
|
|
16
|
-
"@types/node": "^
|
|
20
|
+
"@naturalcycles/dev-lib": "^15.2.0",
|
|
21
|
+
"@types/node": "^22.0.0",
|
|
17
22
|
"jest": "^29.0.3"
|
|
18
23
|
},
|
|
19
24
|
"files": [
|
|
@@ -27,7 +32,7 @@
|
|
|
27
32
|
"main": "dist/index.js",
|
|
28
33
|
"types": "dist/index.d.ts",
|
|
29
34
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
35
|
+
"node": ">=20.13.0"
|
|
31
36
|
},
|
|
32
37
|
"publishConfig": {
|
|
33
38
|
"access": "public"
|
|
@@ -192,7 +192,10 @@ export class DatastoreStreamReadable<T = any> extends Readable implements Readab
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
if (!this.running) {
|
|
195
|
-
void this.runNextQuery()
|
|
195
|
+
void this.runNextQuery().catch(err => {
|
|
196
|
+
console.log('error in runNextQuery', err)
|
|
197
|
+
this.emit('error', err)
|
|
198
|
+
})
|
|
196
199
|
} else {
|
|
197
200
|
this.logger.log(`_read ${this.count}, wasRunning: true`)
|
|
198
201
|
}
|
package/src/query.util.ts
CHANGED
|
@@ -19,23 +19,27 @@ export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
|
|
|
19
19
|
let q = emptyQuery
|
|
20
20
|
|
|
21
21
|
// filter
|
|
22
|
-
|
|
23
|
-
q = dbQuery._filters.reduce(
|
|
22
|
+
for (const f of dbQuery._filters) {
|
|
24
23
|
// keeping "previous syntax" commented out
|
|
25
24
|
// (q, f) => q.filter(f.name as string, OP_MAP[f.op] || (f.op as any), f.val),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
|
|
26
|
+
// Datastore doesn't allow `undefined` as filter value.
|
|
27
|
+
// We don't want to throw on it, so instead we'll replace it with valid value of `null`.
|
|
28
|
+
// `a > null` will return anything that's indexed
|
|
29
|
+
// `a < null` should return nothing
|
|
30
|
+
// `a == null` will return just that - rows with null values
|
|
31
|
+
let { op, val } = f
|
|
32
|
+
if (val === undefined) val = null
|
|
33
|
+
q = q.filter(new PropertyFilter(f.name as string, OP_MAP[op] || (op as any), val))
|
|
34
|
+
}
|
|
29
35
|
|
|
30
36
|
// limit
|
|
31
37
|
q = q.limit(dbQuery._limitValue || 0)
|
|
32
38
|
|
|
33
39
|
// order
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
q,
|
|
38
|
-
)
|
|
40
|
+
for (const ord of dbQuery._orders) {
|
|
41
|
+
q = q.order(ord.name as string, { descending: ord.descending })
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
// select
|
|
41
45
|
if (dbQuery._selectedFieldNames) {
|