@lotics/app-sdk 0.24.0 → 0.25.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.
@@ -28,6 +28,36 @@ interface QueryState<R> {
28
28
  /** True while a `loadMore` request is in flight. */
29
29
  loadingMore: boolean;
30
30
  }
31
+ /**
32
+ * One sort key — the wire shape of the query RPC's `sort`. The server applies
33
+ * these AFTER the named query, bounded to the query's output columns (an
34
+ * un-projected `field_key` is rejected), so an app can sort by any column it
35
+ * actually selects without the query template declaring it.
36
+ */
37
+ export interface QuerySortKey {
38
+ field_key: string;
39
+ order: "asc" | "desc";
40
+ }
41
+ /** A filter condition over one output column (wire shape of a filter node). */
42
+ export interface QueryFilterCondition {
43
+ node_type: "condition";
44
+ field_key: string;
45
+ type?: string;
46
+ operator: string;
47
+ value?: unknown;
48
+ }
49
+ /** A boolean group of filter nodes (wire shape — recursive). */
50
+ export interface QueryFilterGroup {
51
+ node_type: "group";
52
+ logic: "and" | "or";
53
+ children: Array<QueryFilterCondition | QueryFilterGroup>;
54
+ }
55
+ /**
56
+ * Runtime filter applied AFTER the named query, bounded to its output columns
57
+ * (same exposure invariant as `sort`). Build a group from per-column filters
58
+ * with `columnFilterToConditions` (`@lotics/ui/grid/column_filter`).
59
+ */
60
+ export type QueryFilter = QueryFilterCondition | QueryFilterGroup;
31
61
  /** Options for `useQuery`. */
32
62
  export interface QueryOptions {
33
63
  /**
@@ -53,6 +83,16 @@ export interface QueryOptions {
53
83
  * re-run is wasted work and a visible reload.
54
84
  */
55
85
  revalidateOnFocus?: boolean;
86
+ /**
87
+ * Sort the result by output columns at runtime. Changing it re-queries (it is
88
+ * part of the cache key). Empty/omitted leaves the query's own order intact.
89
+ */
90
+ sort?: QuerySortKey[];
91
+ /**
92
+ * Filter the result by output columns at runtime. Changing it re-queries.
93
+ * Compose from per-column UI filters via `columnFilterToConditions`.
94
+ */
95
+ filter?: QueryFilter;
56
96
  }
57
97
  /**
58
98
  * Trigger a workflow by alias from the app's manifest.
package/dist/src/hooks.js CHANGED
@@ -36,6 +36,8 @@ export function useQuery(alias, params, opts) {
36
36
  const pageSize = opts?.pageSize;
37
37
  const enabled = opts?.enabled ?? true;
38
38
  const revalidateOnFocus = opts?.revalidateOnFocus ?? true;
39
+ const sort = opts?.sort && opts.sort.length > 0 ? opts.sort : undefined;
40
+ const filter = opts?.filter;
39
41
  // A registered fixture short-circuits the network in mock / dev mode.
40
42
  const mockRows = getMockRows(alias);
41
43
  // The cache key is (alias, params, pageSize, pageIndex), built HERE so an app
@@ -52,15 +54,19 @@ export function useQuery(alias, params, opts) {
52
54
  if (index > 0 && (pageSize == null || prev == null || prev.rows.length < pageSize)) {
53
55
  return null;
54
56
  }
55
- return ["app-query", alias, params ?? {}, pageSize ?? null, index];
57
+ // sort/filter join the key so a re-sort or re-filter is a distinct cache
58
+ // entry — SWR refetches instead of serving the previous order/subset.
59
+ return ["app-query", alias, params ?? {}, pageSize ?? null, sort ?? null, filter ?? null, index];
56
60
  };
57
61
  const swr = useSWRInfinite(getKey, (key) => {
58
- const index = Number(key[4]);
62
+ const index = Number(key[6]);
59
63
  return rpc("query", {
60
64
  alias,
61
65
  params: params ?? {},
62
66
  limit: pageSize,
63
67
  offset: pageSize != null ? index * pageSize : 0,
68
+ sort,
69
+ filter,
64
70
  });
65
71
  }, {
66
72
  // loadMore appends pages — don't re-fetch earlier pages when `size` grows.
@@ -17,7 +17,7 @@
17
17
  export { mount } from "./mount.js";
18
18
  export type { MountOptions } from "./mount.js";
19
19
  export { useWorkflow, useQuery, useFileUpload, useMembers } from "./hooks.js";
20
- export type { UploadedFile, QueryOptions, WorkflowResult, MembersOptions } from "./hooks.js";
20
+ export type { UploadedFile, QueryOptions, QuerySortKey, QueryFilter, QueryFilterCondition, QueryFilterGroup, WorkflowResult, MembersOptions, } from "./hooks.js";
21
21
  export { rpc } from "./rpc.js";
22
22
  export type { RpcOp } from "./rpc.js";
23
23
  export { openExternal } from "./open_external.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Runtime SDK for Lotics custom-code apps — typed hooks, postMessage bridge, mount entry point",
5
5
  "type": "module",
6
6
  "exports": {