@sdflc/backend-helpers 1.0.127 → 1.0.128
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 +13 -8
- package/build/BaseGateway.js +25 -16
- package/build/esm/BaseGateway.d.ts +13 -8
- package/build/esm/BaseGateway.js +25 -16
- package/build/esm/interfaces/BaseGatewayPropsInterface.d.ts +8 -0
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +8 -0
- package/package.json +1 -1
package/build/BaseGateway.d.ts
CHANGED
|
@@ -134,6 +134,16 @@ declare class BaseGateway {
|
|
|
134
134
|
* while listing and loading still uses the primary key.
|
|
135
135
|
*/
|
|
136
136
|
getIdField(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Returns the column name used for the status field.
|
|
139
|
+
* Defaults to FIELDS.STATUS ('Status') for standard tables.
|
|
140
|
+
* Override via config.statusField for legacy tables that use a different
|
|
141
|
+
* column name (e.g. 'Status_ID').
|
|
142
|
+
*
|
|
143
|
+
* All status-related WHERE clauses and update patches use this value,
|
|
144
|
+
* so setting it once in the gateway constructor propagates everywhere.
|
|
145
|
+
*/
|
|
146
|
+
getStatusField(): string;
|
|
137
147
|
/**
|
|
138
148
|
* Returns the field name used to identify records in UPDATE and DELETE
|
|
139
149
|
* WHERE clauses. Falls back through idFieldUpdateRemove → idField → ID_FIELD.
|
|
@@ -462,14 +472,9 @@ declare class BaseGateway {
|
|
|
462
472
|
* Builds the patch object applied to a record when it is soft-deleted.
|
|
463
473
|
* Called by `remove()` when `hardRemove` is false and `hasRemovedAt` is true.
|
|
464
474
|
*
|
|
465
|
-
* Returns a new object
|
|
475
|
+
* Returns a new object with removal fields populated.
|
|
466
476
|
* Override in subclasses to add custom soft-delete fields.
|
|
467
|
-
* Always call `super.transformOnRemove(
|
|
468
|
-
*
|
|
469
|
-
* The `args` parameter is the original `where` filter passed to `remove()`.
|
|
470
|
-
* It is available so subclasses can derive removal values from the filter
|
|
471
|
-
* (e.g. storing which id was removed). In the base implementation it is
|
|
472
|
-
* spread into the patch object as-is.
|
|
477
|
+
* Always call `super.transformOnRemove()` first.
|
|
473
478
|
*
|
|
474
479
|
* Built-in transformations:
|
|
475
480
|
* - `hasRemovedAt` — sets removedAt to the current time (dayjs, not
|
|
@@ -488,7 +493,7 @@ declare class BaseGateway {
|
|
|
488
493
|
* (construction time). This is intentional — removal timestamps should be
|
|
489
494
|
* as accurate as possible and are not batch-grouped like create/update times.
|
|
490
495
|
*/
|
|
491
|
-
transformOnRemove(
|
|
496
|
+
transformOnRemove(): Promise<any>;
|
|
492
497
|
/**
|
|
493
498
|
* Transforms a record after it is read from the database, before it is
|
|
494
499
|
* returned to the caller.
|
package/build/BaseGateway.js
CHANGED
|
@@ -206,6 +206,18 @@ class BaseGateway {
|
|
|
206
206
|
getIdField() {
|
|
207
207
|
return this.config.idField || constants_1.ID_FIELD;
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns the column name used for the status field.
|
|
211
|
+
* Defaults to FIELDS.STATUS ('Status') for standard tables.
|
|
212
|
+
* Override via config.statusField for legacy tables that use a different
|
|
213
|
+
* column name (e.g. 'Status_ID').
|
|
214
|
+
*
|
|
215
|
+
* All status-related WHERE clauses and update patches use this value,
|
|
216
|
+
* so setting it once in the gateway constructor propagates everywhere.
|
|
217
|
+
*/
|
|
218
|
+
getStatusField() {
|
|
219
|
+
return this.config.statusField ?? constants_1.FIELDS.STATUS;
|
|
220
|
+
}
|
|
209
221
|
/**
|
|
210
222
|
* Returns the field name used to identify records in UPDATE and DELETE
|
|
211
223
|
* WHERE clauses. Falls back through idFieldUpdateRemove → idField → ID_FIELD.
|
|
@@ -603,7 +615,8 @@ class BaseGateway {
|
|
|
603
615
|
async onListFilter(query, filterParams) {
|
|
604
616
|
const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
|
|
605
617
|
if (hasStatus) {
|
|
606
|
-
|
|
618
|
+
const statusField = this.getStatusField();
|
|
619
|
+
query.whereIn(`${table}.${statusField}`, filterParams?.[statusField] != null ? (0, lodash_1.castArray)(filterParams?.[statusField]) : (0, lodash_1.castArray)(activeStatuses));
|
|
607
620
|
}
|
|
608
621
|
if (hasRemovedAt) {
|
|
609
622
|
query.whereNull(`${table}.${constants_1.FIELDS.REMOVED_AT}`);
|
|
@@ -664,12 +677,13 @@ class BaseGateway {
|
|
|
664
677
|
}
|
|
665
678
|
}
|
|
666
679
|
if (hasStatus) {
|
|
680
|
+
const statusField = this.getStatusField();
|
|
667
681
|
filtersAppliedQty++;
|
|
668
|
-
if (Array.isArray(filterParams?.[
|
|
669
|
-
query.whereIn(
|
|
682
|
+
if (Array.isArray(filterParams?.[statusField])) {
|
|
683
|
+
query.whereIn(statusField, filterParams?.[statusField]);
|
|
670
684
|
}
|
|
671
685
|
else {
|
|
672
|
-
query.where(
|
|
686
|
+
query.where(statusField, '!=', utils_1.STATUSES.REMOVED);
|
|
673
687
|
}
|
|
674
688
|
}
|
|
675
689
|
// Declarative update filter rules — applied after base logic.
|
|
@@ -711,7 +725,7 @@ class BaseGateway {
|
|
|
711
725
|
}
|
|
712
726
|
if (hasStatus === true) {
|
|
713
727
|
filtersAppliedQty++;
|
|
714
|
-
query.where(
|
|
728
|
+
query.where(this.getStatusField(), '!=', utils_1.STATUSES.REMOVED);
|
|
715
729
|
}
|
|
716
730
|
// Declarative remove filter rules — applied after base logic.
|
|
717
731
|
filtersAppliedQty += this.applyDeclarativeRemoveFilters(query, filterParams);
|
|
@@ -900,14 +914,9 @@ class BaseGateway {
|
|
|
900
914
|
* Builds the patch object applied to a record when it is soft-deleted.
|
|
901
915
|
* Called by `remove()` when `hardRemove` is false and `hasRemovedAt` is true.
|
|
902
916
|
*
|
|
903
|
-
* Returns a new object
|
|
917
|
+
* Returns a new object with removal fields populated.
|
|
904
918
|
* Override in subclasses to add custom soft-delete fields.
|
|
905
|
-
* Always call `super.transformOnRemove(
|
|
906
|
-
*
|
|
907
|
-
* The `args` parameter is the original `where` filter passed to `remove()`.
|
|
908
|
-
* It is available so subclasses can derive removal values from the filter
|
|
909
|
-
* (e.g. storing which id was removed). In the base implementation it is
|
|
910
|
-
* spread into the patch object as-is.
|
|
919
|
+
* Always call `super.transformOnRemove()` first.
|
|
911
920
|
*
|
|
912
921
|
* Built-in transformations:
|
|
913
922
|
* - `hasRemovedAt` — sets removedAt to the current time (dayjs, not
|
|
@@ -926,11 +935,11 @@ class BaseGateway {
|
|
|
926
935
|
* (construction time). This is intentional — removal timestamps should be
|
|
927
936
|
* as accurate as possible and are not batch-grouped like create/update times.
|
|
928
937
|
*/
|
|
929
|
-
async transformOnRemove(
|
|
938
|
+
async transformOnRemove() {
|
|
930
939
|
const { hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField } = this.config;
|
|
931
940
|
const removalTime = (0, dayjs_1.default)();
|
|
932
941
|
const removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
|
|
933
|
-
const obj = {
|
|
942
|
+
const obj = {};
|
|
934
943
|
if (hasRemovedAt) {
|
|
935
944
|
obj[constants_1.FIELDS.REMOVED_AT] = removalTime.toDate();
|
|
936
945
|
}
|
|
@@ -938,7 +947,7 @@ class BaseGateway {
|
|
|
938
947
|
obj[constants_1.FIELDS.REMOVED_AT_STR] = removalTimeStr;
|
|
939
948
|
}
|
|
940
949
|
if (hasStatus) {
|
|
941
|
-
obj[
|
|
950
|
+
obj[this.getStatusField()] = utils_1.STATUSES.REMOVED;
|
|
942
951
|
}
|
|
943
952
|
if (hasRemovedBy) {
|
|
944
953
|
if (obj[constants_1.FIELDS.REMOVED_BY] === undefined) {
|
|
@@ -1307,7 +1316,7 @@ class BaseGateway {
|
|
|
1307
1316
|
query.delete(this.config.returnFields);
|
|
1308
1317
|
}
|
|
1309
1318
|
else {
|
|
1310
|
-
const object = await this.transformOnRemove(
|
|
1319
|
+
const object = await this.transformOnRemove();
|
|
1311
1320
|
query.update(object).returning(this.config.returnFields);
|
|
1312
1321
|
}
|
|
1313
1322
|
const filtersAppliedQty = await this.onRemoveFilter(query, where);
|
|
@@ -134,6 +134,16 @@ declare class BaseGateway {
|
|
|
134
134
|
* while listing and loading still uses the primary key.
|
|
135
135
|
*/
|
|
136
136
|
getIdField(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Returns the column name used for the status field.
|
|
139
|
+
* Defaults to FIELDS.STATUS ('Status') for standard tables.
|
|
140
|
+
* Override via config.statusField for legacy tables that use a different
|
|
141
|
+
* column name (e.g. 'Status_ID').
|
|
142
|
+
*
|
|
143
|
+
* All status-related WHERE clauses and update patches use this value,
|
|
144
|
+
* so setting it once in the gateway constructor propagates everywhere.
|
|
145
|
+
*/
|
|
146
|
+
getStatusField(): string;
|
|
137
147
|
/**
|
|
138
148
|
* Returns the field name used to identify records in UPDATE and DELETE
|
|
139
149
|
* WHERE clauses. Falls back through idFieldUpdateRemove → idField → ID_FIELD.
|
|
@@ -462,14 +472,9 @@ declare class BaseGateway {
|
|
|
462
472
|
* Builds the patch object applied to a record when it is soft-deleted.
|
|
463
473
|
* Called by `remove()` when `hardRemove` is false and `hasRemovedAt` is true.
|
|
464
474
|
*
|
|
465
|
-
* Returns a new object
|
|
475
|
+
* Returns a new object with removal fields populated.
|
|
466
476
|
* Override in subclasses to add custom soft-delete fields.
|
|
467
|
-
* Always call `super.transformOnRemove(
|
|
468
|
-
*
|
|
469
|
-
* The `args` parameter is the original `where` filter passed to `remove()`.
|
|
470
|
-
* It is available so subclasses can derive removal values from the filter
|
|
471
|
-
* (e.g. storing which id was removed). In the base implementation it is
|
|
472
|
-
* spread into the patch object as-is.
|
|
477
|
+
* Always call `super.transformOnRemove()` first.
|
|
473
478
|
*
|
|
474
479
|
* Built-in transformations:
|
|
475
480
|
* - `hasRemovedAt` — sets removedAt to the current time (dayjs, not
|
|
@@ -488,7 +493,7 @@ declare class BaseGateway {
|
|
|
488
493
|
* (construction time). This is intentional — removal timestamps should be
|
|
489
494
|
* as accurate as possible and are not batch-grouped like create/update times.
|
|
490
495
|
*/
|
|
491
|
-
transformOnRemove(
|
|
496
|
+
transformOnRemove(): Promise<any>;
|
|
492
497
|
/**
|
|
493
498
|
* Transforms a record after it is read from the database, before it is
|
|
494
499
|
* returned to the caller.
|
package/build/esm/BaseGateway.js
CHANGED
|
@@ -200,6 +200,18 @@ class BaseGateway {
|
|
|
200
200
|
getIdField() {
|
|
201
201
|
return this.config.idField || ID_FIELD;
|
|
202
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Returns the column name used for the status field.
|
|
205
|
+
* Defaults to FIELDS.STATUS ('Status') for standard tables.
|
|
206
|
+
* Override via config.statusField for legacy tables that use a different
|
|
207
|
+
* column name (e.g. 'Status_ID').
|
|
208
|
+
*
|
|
209
|
+
* All status-related WHERE clauses and update patches use this value,
|
|
210
|
+
* so setting it once in the gateway constructor propagates everywhere.
|
|
211
|
+
*/
|
|
212
|
+
getStatusField() {
|
|
213
|
+
return this.config.statusField ?? FIELDS.STATUS;
|
|
214
|
+
}
|
|
203
215
|
/**
|
|
204
216
|
* Returns the field name used to identify records in UPDATE and DELETE
|
|
205
217
|
* WHERE clauses. Falls back through idFieldUpdateRemove → idField → ID_FIELD.
|
|
@@ -597,7 +609,8 @@ class BaseGateway {
|
|
|
597
609
|
async onListFilter(query, filterParams) {
|
|
598
610
|
const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
|
|
599
611
|
if (hasStatus) {
|
|
600
|
-
|
|
612
|
+
const statusField = this.getStatusField();
|
|
613
|
+
query.whereIn(`${table}.${statusField}`, filterParams?.[statusField] != null ? castArray(filterParams?.[statusField]) : castArray(activeStatuses));
|
|
601
614
|
}
|
|
602
615
|
if (hasRemovedAt) {
|
|
603
616
|
query.whereNull(`${table}.${FIELDS.REMOVED_AT}`);
|
|
@@ -658,12 +671,13 @@ class BaseGateway {
|
|
|
658
671
|
}
|
|
659
672
|
}
|
|
660
673
|
if (hasStatus) {
|
|
674
|
+
const statusField = this.getStatusField();
|
|
661
675
|
filtersAppliedQty++;
|
|
662
|
-
if (Array.isArray(filterParams?.[
|
|
663
|
-
query.whereIn(
|
|
676
|
+
if (Array.isArray(filterParams?.[statusField])) {
|
|
677
|
+
query.whereIn(statusField, filterParams?.[statusField]);
|
|
664
678
|
}
|
|
665
679
|
else {
|
|
666
|
-
query.where(
|
|
680
|
+
query.where(statusField, '!=', STATUSES.REMOVED);
|
|
667
681
|
}
|
|
668
682
|
}
|
|
669
683
|
// Declarative update filter rules — applied after base logic.
|
|
@@ -705,7 +719,7 @@ class BaseGateway {
|
|
|
705
719
|
}
|
|
706
720
|
if (hasStatus === true) {
|
|
707
721
|
filtersAppliedQty++;
|
|
708
|
-
query.where(
|
|
722
|
+
query.where(this.getStatusField(), '!=', STATUSES.REMOVED);
|
|
709
723
|
}
|
|
710
724
|
// Declarative remove filter rules — applied after base logic.
|
|
711
725
|
filtersAppliedQty += this.applyDeclarativeRemoveFilters(query, filterParams);
|
|
@@ -894,14 +908,9 @@ class BaseGateway {
|
|
|
894
908
|
* Builds the patch object applied to a record when it is soft-deleted.
|
|
895
909
|
* Called by `remove()` when `hardRemove` is false and `hasRemovedAt` is true.
|
|
896
910
|
*
|
|
897
|
-
* Returns a new object
|
|
911
|
+
* Returns a new object with removal fields populated.
|
|
898
912
|
* Override in subclasses to add custom soft-delete fields.
|
|
899
|
-
* Always call `super.transformOnRemove(
|
|
900
|
-
*
|
|
901
|
-
* The `args` parameter is the original `where` filter passed to `remove()`.
|
|
902
|
-
* It is available so subclasses can derive removal values from the filter
|
|
903
|
-
* (e.g. storing which id was removed). In the base implementation it is
|
|
904
|
-
* spread into the patch object as-is.
|
|
913
|
+
* Always call `super.transformOnRemove()` first.
|
|
905
914
|
*
|
|
906
915
|
* Built-in transformations:
|
|
907
916
|
* - `hasRemovedAt` — sets removedAt to the current time (dayjs, not
|
|
@@ -920,11 +929,11 @@ class BaseGateway {
|
|
|
920
929
|
* (construction time). This is intentional — removal timestamps should be
|
|
921
930
|
* as accurate as possible and are not batch-grouped like create/update times.
|
|
922
931
|
*/
|
|
923
|
-
async transformOnRemove(
|
|
932
|
+
async transformOnRemove() {
|
|
924
933
|
const { hasRemovedAt, hasRemovedAtStr, hasStatus, hasRemovedBy, hasLang, localizationForField } = this.config;
|
|
925
934
|
const removalTime = dayjs();
|
|
926
935
|
const removalTimeStr = removalTime.format('YYYYMMDDTHHmmssZ');
|
|
927
|
-
const obj = {
|
|
936
|
+
const obj = {};
|
|
928
937
|
if (hasRemovedAt) {
|
|
929
938
|
obj[FIELDS.REMOVED_AT] = removalTime.toDate();
|
|
930
939
|
}
|
|
@@ -932,7 +941,7 @@ class BaseGateway {
|
|
|
932
941
|
obj[FIELDS.REMOVED_AT_STR] = removalTimeStr;
|
|
933
942
|
}
|
|
934
943
|
if (hasStatus) {
|
|
935
|
-
obj[
|
|
944
|
+
obj[this.getStatusField()] = STATUSES.REMOVED;
|
|
936
945
|
}
|
|
937
946
|
if (hasRemovedBy) {
|
|
938
947
|
if (obj[FIELDS.REMOVED_BY] === undefined) {
|
|
@@ -1301,7 +1310,7 @@ class BaseGateway {
|
|
|
1301
1310
|
query.delete(this.config.returnFields);
|
|
1302
1311
|
}
|
|
1303
1312
|
else {
|
|
1304
|
-
const object = await this.transformOnRemove(
|
|
1313
|
+
const object = await this.transformOnRemove();
|
|
1305
1314
|
query.update(object).returning(this.config.returnFields);
|
|
1306
1315
|
}
|
|
1307
1316
|
const filtersAppliedQty = await this.onRemoveFilter(query, where);
|
|
@@ -16,6 +16,14 @@ export interface BaseGatewayPropsInterface extends CacheInterface {
|
|
|
16
16
|
* Defaults to the global ID_FIELD constant.
|
|
17
17
|
*/
|
|
18
18
|
idField?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Column name for the status field. Defaults to FIELDS.STATUS ('Status').
|
|
21
|
+
* Set to the actual column name on legacy tables that use a different name
|
|
22
|
+
* (e.g. statusField: 'Status_ID').
|
|
23
|
+
*
|
|
24
|
+
* All status-related WHERE clauses and soft-delete patches respect this value.
|
|
25
|
+
*/
|
|
26
|
+
statusField?: string;
|
|
19
27
|
/**
|
|
20
28
|
* Field name used in UPDATE/DELETE WHERE clauses.
|
|
21
29
|
* Separate from idField for tables where the write target differs
|
|
@@ -16,6 +16,14 @@ export interface BaseGatewayPropsInterface extends CacheInterface {
|
|
|
16
16
|
* Defaults to the global ID_FIELD constant.
|
|
17
17
|
*/
|
|
18
18
|
idField?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Column name for the status field. Defaults to FIELDS.STATUS ('Status').
|
|
21
|
+
* Set to the actual column name on legacy tables that use a different name
|
|
22
|
+
* (e.g. statusField: 'Status_ID').
|
|
23
|
+
*
|
|
24
|
+
* All status-related WHERE clauses and soft-delete patches respect this value.
|
|
25
|
+
*/
|
|
26
|
+
statusField?: string;
|
|
19
27
|
/**
|
|
20
28
|
* Field name used in UPDATE/DELETE WHERE clauses.
|
|
21
29
|
* Separate from idField for tables where the write target differs
|