@pylonsync/functions 0.3.10 → 0.3.12
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/package.json +1 -1
- package/src/runtime.ts +8 -0
- package/src/types.ts +36 -0
package/package.json
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -316,6 +316,14 @@ function buildDbReader(callId: string): DbReader {
|
|
|
316
316
|
limit: numItems,
|
|
317
317
|
})) as any;
|
|
318
318
|
},
|
|
319
|
+
async search(entity, query) {
|
|
320
|
+
return (await rpcDb(callId, {
|
|
321
|
+
type: "db",
|
|
322
|
+
op: "search",
|
|
323
|
+
entity,
|
|
324
|
+
data: query,
|
|
325
|
+
})) as any;
|
|
326
|
+
},
|
|
319
327
|
};
|
|
320
328
|
}
|
|
321
329
|
|
package/src/types.ts
CHANGED
|
@@ -43,6 +43,29 @@ export interface DbReader {
|
|
|
43
43
|
query: Record<string, unknown>
|
|
44
44
|
): Promise<Record<string, unknown>>;
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Faceted full-text search against an entity that declares a
|
|
48
|
+
* `search:` config. Mirrors the typed-client `client.search()` /
|
|
49
|
+
* the HTTP `/api/search/<entity>` shape.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const result = await ctx.db.search("Product", {
|
|
53
|
+
* query: "rust async",
|
|
54
|
+
* filters: { brand: "Atlas" },
|
|
55
|
+
* facets: ["category"],
|
|
56
|
+
* page: 0,
|
|
57
|
+
* pageSize: 20,
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Returns `{ hits, facetCounts, total, tookMs }`. Throws on
|
|
62
|
+
* entities without a `search:` config (`SEARCH_NOT_CONFIGURED`).
|
|
63
|
+
*/
|
|
64
|
+
search(
|
|
65
|
+
entity: string,
|
|
66
|
+
query: Record<string, unknown>
|
|
67
|
+
): Promise<SearchResult>;
|
|
68
|
+
|
|
46
69
|
/**
|
|
47
70
|
* Cursor-paginated list. Pass `cursor` from a previous page's `nextCursor`
|
|
48
71
|
* to continue; pass `null` for the first page.
|
|
@@ -70,6 +93,19 @@ export interface PaginationResult<T = Record<string, unknown>> {
|
|
|
70
93
|
isDone: boolean;
|
|
71
94
|
}
|
|
72
95
|
|
|
96
|
+
/** Result shape for [`DbReader.search`]. */
|
|
97
|
+
export interface SearchResult<T = Record<string, unknown>> {
|
|
98
|
+
/** Ranked (or sorted) hit rows. */
|
|
99
|
+
hits: T[];
|
|
100
|
+
/** `{facet_name: {value: count}}` — counts excluded for the
|
|
101
|
+
* active filter on the same facet (standard exclusion pattern). */
|
|
102
|
+
facetCounts: Record<string, Record<string, number>>;
|
|
103
|
+
/** Total hit count before pagination. */
|
|
104
|
+
total: number;
|
|
105
|
+
/** Milliseconds spent in the search engine. */
|
|
106
|
+
tookMs: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
73
109
|
// ---------------------------------------------------------------------------
|
|
74
110
|
// Database — write operations (extends read)
|
|
75
111
|
// ---------------------------------------------------------------------------
|