lazypock 0.14.0 → 0.15.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/README.md +9 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -5
- package/dist/index.d.ts +32 -5
- package/dist/index.global.js +19 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/collection.ts +29 -2
- package/src/index.ts +2 -0
- package/src/lazypock.ts +4 -0
- package/src/types.ts +32 -4
package/README.md
CHANGED
|
@@ -352,6 +352,15 @@ per-field type. An empty `in([])` / `notIn([])` throws. A built expression
|
|
|
352
352
|
can be passed anywhere a `filter` string is accepted — including
|
|
353
353
|
`getFirstListItem(q('slug').eq('hello-world'))`.
|
|
354
354
|
|
|
355
|
+
For a one-off filter, build inline with a callback — it receives the same
|
|
356
|
+
typed `where` helper, so field names are still suggested and checked:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
await postsSvc.getFullList({
|
|
360
|
+
filter: (w) => w('title').contains('x').and(w('published').eq(true)),
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
355
364
|
#### Expanding relations
|
|
356
365
|
|
|
357
366
|
`expand` attaches the related record(s) under `record.expand`; the relation
|
package/dist/index.cjs
CHANGED
|
@@ -990,6 +990,17 @@ var CollectionService = class _CollectionService {
|
|
|
990
990
|
where(field) {
|
|
991
991
|
return new FilterBuilder(field);
|
|
992
992
|
}
|
|
993
|
+
/**
|
|
994
|
+
* Resolve a `filter` callback into a concrete string / {@link FilterExpr}.
|
|
995
|
+
* The callback receives this collection's typed `where` helper, so
|
|
996
|
+
* `filter: (w) => w("title").contains("x")` type-checks field names inline.
|
|
997
|
+
*/
|
|
998
|
+
resolveFilter(filter) {
|
|
999
|
+
if (typeof filter !== "function") {
|
|
1000
|
+
return filter;
|
|
1001
|
+
}
|
|
1002
|
+
return filter((field) => this.where(field));
|
|
1003
|
+
}
|
|
993
1004
|
/**
|
|
994
1005
|
* Resolve the leading relation chain of an expand token against the
|
|
995
1006
|
* (optionally schema-aware) collection graph.
|
|
@@ -1239,6 +1250,11 @@ var CollectionService = class _CollectionService {
|
|
|
1239
1250
|
if (Array.isArray(queryParams.expand)) {
|
|
1240
1251
|
queryParams.expand = queryParams.expand.join(",");
|
|
1241
1252
|
}
|
|
1253
|
+
if (typeof queryParams.filter === "function") {
|
|
1254
|
+
queryParams.filter = this.resolveFilter(
|
|
1255
|
+
queryParams.filter
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1242
1258
|
const expandInfo = this.normalizeExpand(
|
|
1243
1259
|
typeof queryParams.expand === "string" ? queryParams.expand : void 0
|
|
1244
1260
|
);
|
|
@@ -1286,6 +1302,9 @@ var CollectionService = class _CollectionService {
|
|
|
1286
1302
|
*/
|
|
1287
1303
|
async getFullList(options) {
|
|
1288
1304
|
const { batch = 1e3, ...rest } = options ?? {};
|
|
1305
|
+
if (typeof rest.filter === "function") {
|
|
1306
|
+
rest.filter = this.resolveFilter(rest.filter);
|
|
1307
|
+
}
|
|
1289
1308
|
const effectiveKey = typeof rest.requestKey === "string" ? rest.requestKey : `getFullList:${this.collectionName}:${stableStringify(rest)}`;
|
|
1290
1309
|
const items = [];
|
|
1291
1310
|
let page = 1;
|