@navette-js/database 1.0.0-beta.3 → 1.0.0-beta.4

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/lib/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export type ListQuery = {
7
7
  /** Global search: every word must appear in at least one of the searchable columns. */
8
8
  search?: string | null;
9
9
  searchColumns?: string[];
10
+ /** `false`: the search term is matched as a whole, instead of word by word. */
11
+ splitSearchTerms?: boolean;
10
12
  /** Per-column search: all conditions must match. */
11
13
  columnSearches?: Record<string, string>;
12
14
  /** Soft-deleted records: excluded by default, included, or only those. */
@@ -16,10 +18,14 @@ export type ListQuery = {
16
18
  direction: SortDirection;
17
19
  } | null;
18
20
  /** Table grouping: this sort is applied before `sort`. */
21
+ /** Rows are first ordered by their group: by `column`, or by `modify` (a custom order). */
19
22
  groupSort?: {
20
23
  column: string;
21
24
  direction: SortDirection;
25
+ modify?: (query: any, direction: SortDirection) => void;
22
26
  } | null;
27
+ /** Only these records (keys), e.g. the rows of the displayed page. */
28
+ keys?: string[];
23
29
  /** Extra server-side conditions (list tab, custom filter); never built from unvalidated browser input. */
24
30
  modifiers?: ((query: any) => void)[];
25
31
  page: number;
package/lib/index.js CHANGED
@@ -136,9 +136,12 @@ export class ObjectionAdapter {
136
136
  /** Base query with modifiers, global search and per-column searches applied. */
137
137
  filtered(query) {
138
138
  const q = this.base(query.trashed ?? 'without');
139
+ if (query.keys)
140
+ q.whereIn(`${this.model.tableName}.${this.keyColumn}`, query.keys.map(String).slice(0, 10000));
139
141
  for (const modifier of query.modifiers ?? [])
140
142
  modifier(q);
141
- const words = (query.search ?? '').trim().split(/\s+/).filter(Boolean);
143
+ const term = (query.search ?? '').trim();
144
+ const words = query.splitSearchTerms === false ? (term ? [term] : []) : term.split(/\s+/).filter(Boolean);
142
145
  const columns = query.searchColumns ?? [];
143
146
  if (words.length && columns.length) {
144
147
  // Each word must match at least one column, case-insensitively; LIKE wildcards in the input are escaped.
@@ -157,7 +160,9 @@ export class ObjectionAdapter {
157
160
  }
158
161
  async finishPagination(q, query) {
159
162
  const total = await q.clone().resultSize();
160
- if (query.groupSort)
163
+ if (query.groupSort?.modify)
164
+ query.groupSort.modify(q, query.groupSort.direction);
165
+ else if (query.groupSort)
161
166
  q.orderBy(query.groupSort.column, query.groupSort.direction);
162
167
  if (query.sort)
163
168
  q.orderBy(query.sort.column, query.sort.direction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navette-js/database",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "Data adapters (Objection/Knex) for Navette panels.",
5
5
  "license": "MIT",
6
6
  "type": "module",