@naturalcycles/datastore-lib 3.18.0 → 3.18.1
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/datastore.db.js +10 -1
- package/dist/datastore.model.d.ts +7 -0
- package/package.json +1 -1
- package/src/datastore.db.ts +10 -1
- package/src/datastore.model.ts +8 -0
package/dist/datastore.db.js
CHANGED
|
@@ -57,7 +57,16 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
57
57
|
const keys = ids.map(id => this.key(table, id));
|
|
58
58
|
let rows;
|
|
59
59
|
try {
|
|
60
|
-
|
|
60
|
+
if (this.cfg.timeout) {
|
|
61
|
+
const r = await (0, js_lib_1.pTimeout)(this.ds().get(keys), {
|
|
62
|
+
timeout: this.cfg.timeout,
|
|
63
|
+
name: `datastore.getByIds(${table})`,
|
|
64
|
+
});
|
|
65
|
+
rows = r[0];
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
rows = (await this.ds().get(keys))[0];
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
catch (err) {
|
|
63
72
|
this.cfg.logger.log('datastore recreated on error');
|
|
@@ -34,6 +34,13 @@ export interface DatastoreDBCfg extends DatastoreOptions {
|
|
|
34
34
|
* Default to `console`
|
|
35
35
|
*/
|
|
36
36
|
logger?: CommonLogger;
|
|
37
|
+
/**
|
|
38
|
+
* Experimental option, currently only applies to `getByIds`.
|
|
39
|
+
* Applies pTimeout to Datastore operation, re-creates Datastore on any error.
|
|
40
|
+
*
|
|
41
|
+
* @experimental
|
|
42
|
+
*/
|
|
43
|
+
timeout?: number;
|
|
37
44
|
}
|
|
38
45
|
export interface DatastoreCredentials {
|
|
39
46
|
type?: string;
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
JsonSchemaRootObject,
|
|
25
25
|
CommonLogger,
|
|
26
26
|
commonLoggerMinLevel,
|
|
27
|
+
pTimeout,
|
|
27
28
|
} from '@naturalcycles/js-lib'
|
|
28
29
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
29
30
|
import { boldWhite } from '@naturalcycles/nodejs-lib/dist/colors'
|
|
@@ -116,7 +117,15 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
116
117
|
let rows: any[]
|
|
117
118
|
|
|
118
119
|
try {
|
|
119
|
-
|
|
120
|
+
if (this.cfg.timeout) {
|
|
121
|
+
const r = await pTimeout(this.ds().get(keys), {
|
|
122
|
+
timeout: this.cfg.timeout,
|
|
123
|
+
name: `datastore.getByIds(${table})`,
|
|
124
|
+
})
|
|
125
|
+
rows = r[0]
|
|
126
|
+
} else {
|
|
127
|
+
rows = (await this.ds().get(keys))[0]
|
|
128
|
+
}
|
|
120
129
|
} catch (err) {
|
|
121
130
|
this.cfg.logger.log('datastore recreated on error')
|
|
122
131
|
|
package/src/datastore.model.ts
CHANGED
|
@@ -41,6 +41,14 @@ export interface DatastoreDBCfg extends DatastoreOptions {
|
|
|
41
41
|
* Default to `console`
|
|
42
42
|
*/
|
|
43
43
|
logger?: CommonLogger
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Experimental option, currently only applies to `getByIds`.
|
|
47
|
+
* Applies pTimeout to Datastore operation, re-creates Datastore on any error.
|
|
48
|
+
*
|
|
49
|
+
* @experimental
|
|
50
|
+
*/
|
|
51
|
+
timeout?: number
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export interface DatastoreCredentials {
|