@naturalcycles/datastore-lib 3.25.4 → 3.26.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/datastore.db.d.ts +1 -1
- package/dist/datastore.db.js +13 -11
- package/package.json +1 -1
- package/src/datastore.db.ts +14 -12
package/dist/datastore.db.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
48
48
|
getStats(table: string): Promise<DatastoreStats | undefined>;
|
|
49
49
|
getStatsCount(table: string): Promise<number | undefined>;
|
|
50
50
|
getTableProperties(table: string): Promise<DatastorePropertyStats[]>;
|
|
51
|
-
mapId<T
|
|
51
|
+
mapId<T extends ObjectWithId>(o: any, preserveKey?: boolean): T;
|
|
52
52
|
toDatastoreEntity<T = any>(kind: string, o: T & {
|
|
53
53
|
id?: string | number;
|
|
54
54
|
}, excludeFromIndexes?: string[]): DatastorePayload<T>;
|
package/dist/datastore.db.js
CHANGED
|
@@ -80,9 +80,10 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
80
80
|
const DS = datastoreLib.Datastore;
|
|
81
81
|
this.cachedDatastore = new DS(this.cfg);
|
|
82
82
|
// Second try (will throw)
|
|
83
|
-
const r = await (0, js_lib_1.
|
|
83
|
+
const r = await (0, js_lib_1.pRetry)(() => this.ds().get(keys), {
|
|
84
|
+
...this.getPRetryOptions(`datastore.getByIds(${table}) second try`),
|
|
85
|
+
maxAttempts: 3,
|
|
84
86
|
timeout: this.cfg.timeout,
|
|
85
|
-
name: `datastore.getByIds(${table}) second try`,
|
|
86
87
|
errorData: {
|
|
87
88
|
// This error will be grouped ACROSS all endpoints and usages
|
|
88
89
|
fingerprint: ['DATASTORE_TIMEOUT'],
|
|
@@ -92,7 +93,9 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
|
-
rows =
|
|
96
|
+
rows = await (0, js_lib_1.pRetry)(async () => {
|
|
97
|
+
return (await this.ds().get(keys))[0];
|
|
98
|
+
}, this.getPRetryOptions(`datastore.getByIds(${table})`));
|
|
96
99
|
}
|
|
97
100
|
return (rows
|
|
98
101
|
.map(r => this.mapId(r))
|
|
@@ -101,7 +104,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
101
104
|
.sort((a, b) => (a.id > b.id ? 1 : -1)));
|
|
102
105
|
}
|
|
103
106
|
getQueryKind(q) {
|
|
104
|
-
if (!q
|
|
107
|
+
if (!q?.kinds?.length)
|
|
105
108
|
return ''; // should never be the case, but
|
|
106
109
|
return q.kinds[0];
|
|
107
110
|
}
|
|
@@ -246,7 +249,7 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
246
249
|
}
|
|
247
250
|
async getStatsCount(table) {
|
|
248
251
|
const stats = await this.getStats(table);
|
|
249
|
-
return stats
|
|
252
|
+
return stats?.count;
|
|
250
253
|
}
|
|
251
254
|
async getTableProperties(table) {
|
|
252
255
|
const q = this.ds()
|
|
@@ -350,11 +353,9 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
350
353
|
}
|
|
351
354
|
else if (dtype === datastore_model_1.DatastoreType.NULL) {
|
|
352
355
|
// check, maybe we can just skip this type and do nothing?
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
};
|
|
357
|
-
}
|
|
356
|
+
s.properties[name] ||= {
|
|
357
|
+
type: 'null',
|
|
358
|
+
};
|
|
358
359
|
}
|
|
359
360
|
else {
|
|
360
361
|
throw new Error(`Unknown Datastore Type '${stats.property_type}' for ${table}.${name}`);
|
|
@@ -366,9 +367,10 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
366
367
|
return {
|
|
367
368
|
predicate: err => RETRY_ON.some(s => err?.message?.includes(s)),
|
|
368
369
|
name,
|
|
370
|
+
timeout: 10000,
|
|
369
371
|
maxAttempts: 5,
|
|
370
372
|
delay: 5000,
|
|
371
|
-
delayMultiplier:
|
|
373
|
+
delayMultiplier: 1.5,
|
|
372
374
|
logFirstAttempt: false,
|
|
373
375
|
logFailures: true,
|
|
374
376
|
// logAll: true,
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -144,9 +144,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
144
144
|
this.cachedDatastore = new DS(this.cfg)
|
|
145
145
|
|
|
146
146
|
// Second try (will throw)
|
|
147
|
-
const r = await
|
|
147
|
+
const r = await pRetry(() => this.ds().get(keys), {
|
|
148
|
+
...this.getPRetryOptions(`datastore.getByIds(${table}) second try`),
|
|
149
|
+
maxAttempts: 3,
|
|
148
150
|
timeout: this.cfg.timeout,
|
|
149
|
-
name: `datastore.getByIds(${table}) second try`,
|
|
150
151
|
errorData: {
|
|
151
152
|
// This error will be grouped ACROSS all endpoints and usages
|
|
152
153
|
fingerprint: ['DATASTORE_TIMEOUT'],
|
|
@@ -155,7 +156,9 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
155
156
|
rows = r[0]
|
|
156
157
|
}
|
|
157
158
|
} else {
|
|
158
|
-
rows =
|
|
159
|
+
rows = await pRetry(async () => {
|
|
160
|
+
return (await this.ds().get(keys))[0]
|
|
161
|
+
}, this.getPRetryOptions(`datastore.getByIds(${table})`))
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
return (
|
|
@@ -168,7 +171,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
getQueryKind(q: Query): string {
|
|
171
|
-
if (!q
|
|
174
|
+
if (!q?.kinds?.length) return '' // should never be the case, but
|
|
172
175
|
return q.kinds[0]!
|
|
173
176
|
}
|
|
174
177
|
|
|
@@ -380,7 +383,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
380
383
|
|
|
381
384
|
async getStatsCount(table: string): Promise<number | undefined> {
|
|
382
385
|
const stats = await this.getStats(table)
|
|
383
|
-
return stats
|
|
386
|
+
return stats?.count
|
|
384
387
|
}
|
|
385
388
|
|
|
386
389
|
async getTableProperties(table: string): Promise<DatastorePropertyStats[]> {
|
|
@@ -391,7 +394,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
391
394
|
return stats
|
|
392
395
|
}
|
|
393
396
|
|
|
394
|
-
mapId<T
|
|
397
|
+
mapId<T extends ObjectWithId>(o: any, preserveKey = false): T {
|
|
395
398
|
if (!o) return o
|
|
396
399
|
const r = {
|
|
397
400
|
...o,
|
|
@@ -497,11 +500,9 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
497
500
|
s.properties[name] = {} as JsonSchemaAny
|
|
498
501
|
} else if (dtype === DatastoreType.NULL) {
|
|
499
502
|
// check, maybe we can just skip this type and do nothing?
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
} as JsonSchemaNull
|
|
504
|
-
}
|
|
503
|
+
s.properties[name] ||= {
|
|
504
|
+
type: 'null',
|
|
505
|
+
} as JsonSchemaNull
|
|
505
506
|
} else {
|
|
506
507
|
throw new Error(
|
|
507
508
|
`Unknown Datastore Type '${stats.property_type}' for ${table}.${name as string}`,
|
|
@@ -516,9 +517,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
516
517
|
return {
|
|
517
518
|
predicate: err => RETRY_ON.some(s => err?.message?.includes(s)),
|
|
518
519
|
name,
|
|
520
|
+
timeout: 10_000,
|
|
519
521
|
maxAttempts: 5,
|
|
520
522
|
delay: 5000,
|
|
521
|
-
delayMultiplier:
|
|
523
|
+
delayMultiplier: 1.5,
|
|
522
524
|
logFirstAttempt: false,
|
|
523
525
|
logFailures: true,
|
|
524
526
|
// logAll: true,
|