@sdflc/backend-helpers 1.0.120 → 1.0.121
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/build/BaseGateway.d.ts
CHANGED
|
@@ -285,7 +285,7 @@ declare class BaseGateway {
|
|
|
285
285
|
* Returns the Database instance from config.
|
|
286
286
|
* All query builders are derived from this instance.
|
|
287
287
|
*/
|
|
288
|
-
getDb(): Database;
|
|
288
|
+
getDb(): Database | undefined;
|
|
289
289
|
/**
|
|
290
290
|
* Returns a Knex query builder scoped to this gateway's table.
|
|
291
291
|
* The builder is a fresh instance each time — it does not carry state
|
package/build/BaseGateway.js
CHANGED
|
@@ -482,10 +482,11 @@ class BaseGateway {
|
|
|
482
482
|
obj[constants_1.FIELDS.REMOVED_BY] = this.getContext()?.userId;
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
|
-
|
|
485
|
+
const db = this.getDb();
|
|
486
|
+
if (hasLang && localizationForField && db) {
|
|
486
487
|
// Append removal timestamp to the id to free the original localisation key
|
|
487
488
|
// for future re-use (e.g. if a new record with the same lang + slug is created).
|
|
488
|
-
obj[this.getIdField()] =
|
|
489
|
+
obj[this.getIdField()] = db.raw(`CONCAT(id, '-${removalTimeStr}')`);
|
|
489
490
|
}
|
|
490
491
|
return obj;
|
|
491
492
|
}
|
|
@@ -634,10 +635,11 @@ class BaseGateway {
|
|
|
634
635
|
*/
|
|
635
636
|
async list(args) {
|
|
636
637
|
const { filter, params, useCache } = args || {};
|
|
637
|
-
const
|
|
638
|
-
if (!this.config.table) {
|
|
638
|
+
const db = this.getDb();
|
|
639
|
+
if (!this.config.table || !db) {
|
|
639
640
|
return [];
|
|
640
641
|
}
|
|
642
|
+
const { limit, offset, sortBy } = db.createLimitOffsetSortBy(params, this.config.defaultSorting || []);
|
|
641
643
|
const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
|
|
642
644
|
const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
|
|
643
645
|
const { query } = await this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
|
|
@@ -285,7 +285,7 @@ declare class BaseGateway {
|
|
|
285
285
|
* Returns the Database instance from config.
|
|
286
286
|
* All query builders are derived from this instance.
|
|
287
287
|
*/
|
|
288
|
-
getDb(): Database;
|
|
288
|
+
getDb(): Database | undefined;
|
|
289
289
|
/**
|
|
290
290
|
* Returns a Knex query builder scoped to this gateway's table.
|
|
291
291
|
* The builder is a fresh instance each time — it does not carry state
|
package/build/esm/BaseGateway.js
CHANGED
|
@@ -476,10 +476,11 @@ class BaseGateway {
|
|
|
476
476
|
obj[FIELDS.REMOVED_BY] = this.getContext()?.userId;
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
-
|
|
479
|
+
const db = this.getDb();
|
|
480
|
+
if (hasLang && localizationForField && db) {
|
|
480
481
|
// Append removal timestamp to the id to free the original localisation key
|
|
481
482
|
// for future re-use (e.g. if a new record with the same lang + slug is created).
|
|
482
|
-
obj[this.getIdField()] =
|
|
483
|
+
obj[this.getIdField()] = db.raw(`CONCAT(id, '-${removalTimeStr}')`);
|
|
483
484
|
}
|
|
484
485
|
return obj;
|
|
485
486
|
}
|
|
@@ -628,10 +629,11 @@ class BaseGateway {
|
|
|
628
629
|
*/
|
|
629
630
|
async list(args) {
|
|
630
631
|
const { filter, params, useCache } = args || {};
|
|
631
|
-
const
|
|
632
|
-
if (!this.config.table) {
|
|
632
|
+
const db = this.getDb();
|
|
633
|
+
if (!this.config.table || !db) {
|
|
633
634
|
return [];
|
|
634
635
|
}
|
|
636
|
+
const { limit, offset, sortBy } = db.createLimitOffsetSortBy(params, this.config.defaultSorting || []);
|
|
635
637
|
const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
|
|
636
638
|
const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
|
|
637
639
|
const { query } = await this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Database } from '../Database';
|
|
2
2
|
export interface CacheInterface {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Database instance used by the default batch loader (batchLoaderDefault).
|
|
5
|
+
* Optional when a custom `loaderFn` is provided — in that case the loader
|
|
6
|
+
* function is responsible for its own data fetching and `db` is not used.
|
|
7
|
+
* Runtime safety is enforced in DataCache.batchLoaderDefault(), which throws
|
|
8
|
+
* if `db` is missing and no `loaderFn` was supplied.
|
|
9
|
+
*/
|
|
10
|
+
db?: Database;
|
|
4
11
|
/**
|
|
5
12
|
* Namespace prefix for DataLoader cache keys.
|
|
6
13
|
* Resolved in BaseGateway as: context.keyPrefix → config.keyPrefix → table name.
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Database } from '../Database';
|
|
2
2
|
export interface CacheInterface {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Database instance used by the default batch loader (batchLoaderDefault).
|
|
5
|
+
* Optional when a custom `loaderFn` is provided — in that case the loader
|
|
6
|
+
* function is responsible for its own data fetching and `db` is not used.
|
|
7
|
+
* Runtime safety is enforced in DataCache.batchLoaderDefault(), which throws
|
|
8
|
+
* if `db` is missing and no `loaderFn` was supplied.
|
|
9
|
+
*/
|
|
10
|
+
db?: Database;
|
|
4
11
|
/**
|
|
5
12
|
* Namespace prefix for DataLoader cache keys.
|
|
6
13
|
* Resolved in BaseGateway as: context.keyPrefix → config.keyPrefix → table name.
|