@adobe/spacecat-shared-data-access 4.19.0 → 4.20.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/CHANGELOG.md +6 -0
- package/CLAUDE.md +1 -1
- package/package.json +1 -1
- package/src/models/base/base.collection.js +19 -2
- package/src/models/base/index.d.ts +1 -0
- package/src/util/postgrest.utils.js +37 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [@adobe/spacecat-shared-data-access-v4.20.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.19.0...@adobe/spacecat-shared-data-access-v4.20.0) (2026-08-12)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **data-access:** compound AND filter and orderBy column for postgrest queries ([#1874](https://github.com/adobe/spacecat-shared/issues/1874)) ([620b37e](https://github.com/adobe/spacecat-shared/commit/620b37eb1bc252c9bdd01661037de6fd7e0bfe35))
|
|
6
|
+
|
|
1
7
|
## [@adobe/spacecat-shared-data-access-v4.19.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v4.18.0...@adobe/spacecat-shared-data-access-v4.19.0) (2026-08-11)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/CLAUDE.md
CHANGED
|
@@ -178,7 +178,7 @@ This is the same client instance used internally by entity collections — same
|
|
|
178
178
|
async findByStatus(status) {
|
|
179
179
|
return this.all(
|
|
180
180
|
(attrs, op) => op.eq(attrs.status, status),
|
|
181
|
-
{ limit: 100,
|
|
181
|
+
{ limit: 100, orderBy: { attribute: 'createdAt', direction: 'desc' } }
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
```
|
package/package.json
CHANGED
|
@@ -428,8 +428,25 @@ class BaseCollection {
|
|
|
428
428
|
this.#logAndThrowError(`Failed to query [${this.entityName}]: query proxy [${options.index}] not found`);
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
const
|
|
432
|
-
|
|
431
|
+
const hasExplicitOrderBy = isObject(options.orderBy) && hasText(options.orderBy.attribute);
|
|
432
|
+
let explicitAscending;
|
|
433
|
+
if (hasExplicitOrderBy) {
|
|
434
|
+
const { toDbMap } = this.fieldMaps;
|
|
435
|
+
if (!Object.prototype.hasOwnProperty.call(toDbMap, options.orderBy.attribute)) {
|
|
436
|
+
this.#logAndThrowError(`Failed to query [${this.entityName}]: unknown orderBy attribute [${options.orderBy.attribute}]`);
|
|
437
|
+
}
|
|
438
|
+
const direction = options.orderBy.direction === undefined
|
|
439
|
+
? 'asc'
|
|
440
|
+
: String(options.orderBy.direction).toLowerCase();
|
|
441
|
+
if (direction !== 'asc' && direction !== 'desc') {
|
|
442
|
+
this.#logAndThrowError(`Failed to query [${this.entityName}]: invalid orderBy direction [${options.orderBy.direction}]`);
|
|
443
|
+
}
|
|
444
|
+
explicitAscending = direction === 'asc';
|
|
445
|
+
}
|
|
446
|
+
const orderFields = hasExplicitOrderBy
|
|
447
|
+
? [this.#toDbField(options.orderBy.attribute)]
|
|
448
|
+
: this.#getOrderFields(indexName, keys);
|
|
449
|
+
const ascending = hasExplicitOrderBy ? explicitAscending : options.order === 'asc';
|
|
433
450
|
let query = this.postgrestService
|
|
434
451
|
.from(this.tableName)
|
|
435
452
|
.select(select);
|
|
@@ -152,6 +152,7 @@ const applyWhere = (query, whereFn, toDbMap) => {
|
|
|
152
152
|
like: (field, value) => ({ type: 'like', field, value }),
|
|
153
153
|
ilike: (field, value) => ({ type: 'ilike', field, value }),
|
|
154
154
|
contains: (field, value) => ({ type: 'contains', field, value }),
|
|
155
|
+
and: (...conditions) => ({ type: 'and', conditions: conditions.filter(Boolean) }),
|
|
155
156
|
};
|
|
156
157
|
|
|
157
158
|
const expression = whereFn(attrs, op);
|
|
@@ -159,37 +160,43 @@ const applyWhere = (query, whereFn, toDbMap) => {
|
|
|
159
160
|
return query;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
163
|
+
const applyExpr = (q, expr) => {
|
|
164
|
+
switch (expr.type) {
|
|
165
|
+
case 'and':
|
|
166
|
+
return (expr.conditions || []).reduce((acc, cond) => applyExpr(acc, cond), q);
|
|
167
|
+
case 'eq':
|
|
168
|
+
return q.eq(expr.field, expr.value);
|
|
169
|
+
case 'ne':
|
|
170
|
+
return q.neq(expr.field, expr.value);
|
|
171
|
+
case 'gt':
|
|
172
|
+
return q.gt(expr.field, expr.value);
|
|
173
|
+
case 'gte':
|
|
174
|
+
return q.gte(expr.field, expr.value);
|
|
175
|
+
case 'lt':
|
|
176
|
+
return q.lt(expr.field, expr.value);
|
|
177
|
+
case 'lte':
|
|
178
|
+
return q.lte(expr.field, expr.value);
|
|
179
|
+
case 'in':
|
|
180
|
+
return q.in(
|
|
181
|
+
expr.field,
|
|
182
|
+
Array.isArray(expr.value) ? expr.value : [expr.value],
|
|
183
|
+
);
|
|
184
|
+
case 'is':
|
|
185
|
+
return q.is(expr.field, expr.value);
|
|
186
|
+
case 'like':
|
|
187
|
+
return q.like(expr.field, expr.value);
|
|
188
|
+
case 'ilike':
|
|
189
|
+
return q.ilike(expr.field, expr.value);
|
|
190
|
+
case 'contains': {
|
|
191
|
+
const value = Array.isArray(expr.value) ? expr.value : [expr.value];
|
|
192
|
+
return q.contains(expr.field, value);
|
|
193
|
+
}
|
|
194
|
+
default:
|
|
195
|
+
throw new Error(`Unsupported where operator: ${expr.type}`);
|
|
189
196
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return applyExpr(query, expression);
|
|
193
200
|
};
|
|
194
201
|
|
|
195
202
|
export {
|