@naturalcycles/db-lib 8.24.4 → 8.25.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.
|
@@ -56,7 +56,17 @@ class CommonDao {
|
|
|
56
56
|
const op = `getById(${id})`;
|
|
57
57
|
const table = opt.table || this.cfg.table;
|
|
58
58
|
const started = this.logStarted(op, table);
|
|
59
|
-
|
|
59
|
+
let dbm;
|
|
60
|
+
if (opt.timeout) {
|
|
61
|
+
// todo: possibly remove it after debugging is done
|
|
62
|
+
dbm = (await (0, js_lib_1.pTimeout)(this.cfg.db.getByIds(table, [id]), {
|
|
63
|
+
timeout: opt.timeout,
|
|
64
|
+
name: `getById(${table})`,
|
|
65
|
+
}))[0];
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
dbm = (await this.cfg.db.getByIds(table, [id]))[0];
|
|
69
|
+
}
|
|
60
70
|
const bm = opt.raw ? dbm : await this.dbmToBM(dbm, opt);
|
|
61
71
|
this.logResult(started, op, bm, table);
|
|
62
72
|
return bm || null;
|
|
@@ -135,6 +135,13 @@ export interface CommonDaoOptions extends CommonDBOptions {
|
|
|
135
135
|
* Useful e.g in AirtableDB where you can have one Dao to control multiple tables.
|
|
136
136
|
*/
|
|
137
137
|
table?: string;
|
|
138
|
+
/**
|
|
139
|
+
* If set - wraps the method in `pTimeout` with a timeout of given number of milliseconds.
|
|
140
|
+
* Currently, it is only used to debug an ongoing GCP infra issue.
|
|
141
|
+
*
|
|
142
|
+
* @experimental
|
|
143
|
+
*/
|
|
144
|
+
timeout?: number;
|
|
138
145
|
}
|
|
139
146
|
/**
|
|
140
147
|
* All properties default to undefined.
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@naturalcycles/bench-lib": "^1.0.0",
|
|
14
14
|
"@naturalcycles/dev-lib": "^12.0.1",
|
|
15
|
-
"@types/node": "^
|
|
15
|
+
"@types/node": "^17.0.0",
|
|
16
16
|
"jest": "^27.0.3"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=14.15"
|
|
44
44
|
},
|
|
45
|
-
"version": "8.
|
|
45
|
+
"version": "8.25.0",
|
|
46
46
|
"description": "Lowest Common Denominator API to supported Databases",
|
|
47
47
|
"keywords": [
|
|
48
48
|
"db",
|
|
@@ -168,6 +168,14 @@ export interface CommonDaoOptions extends CommonDBOptions {
|
|
|
168
168
|
* Useful e.g in AirtableDB where you can have one Dao to control multiple tables.
|
|
169
169
|
*/
|
|
170
170
|
table?: string
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* If set - wraps the method in `pTimeout` with a timeout of given number of milliseconds.
|
|
174
|
+
* Currently, it is only used to debug an ongoing GCP infra issue.
|
|
175
|
+
*
|
|
176
|
+
* @experimental
|
|
177
|
+
*/
|
|
178
|
+
timeout?: number
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
/**
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
JsonSchemaRootObject,
|
|
13
13
|
ObjectWithId,
|
|
14
14
|
pMap,
|
|
15
|
+
pTimeout,
|
|
15
16
|
Saved,
|
|
16
17
|
} from '@naturalcycles/js-lib'
|
|
17
18
|
import {
|
|
@@ -103,7 +104,21 @@ export class CommonDao<
|
|
|
103
104
|
const op = `getById(${id})`
|
|
104
105
|
const table = opt.table || this.cfg.table
|
|
105
106
|
const started = this.logStarted(op, table)
|
|
106
|
-
|
|
107
|
+
|
|
108
|
+
let dbm: DBM | undefined
|
|
109
|
+
|
|
110
|
+
if (opt.timeout) {
|
|
111
|
+
// todo: possibly remove it after debugging is done
|
|
112
|
+
dbm = (
|
|
113
|
+
await pTimeout(this.cfg.db.getByIds<DBM>(table, [id]), {
|
|
114
|
+
timeout: opt.timeout,
|
|
115
|
+
name: `getById(${table})`,
|
|
116
|
+
})
|
|
117
|
+
)[0]
|
|
118
|
+
} else {
|
|
119
|
+
dbm = (await this.cfg.db.getByIds<DBM>(table, [id]))[0]
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
const bm = opt.raw ? (dbm as any) : await this.dbmToBM(dbm, opt)
|
|
108
123
|
this.logResult(started, op, bm, table)
|
|
109
124
|
return bm || null
|