@lotics/app-sdk 0.17.0 → 0.18.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.
@@ -25,9 +25,9 @@ interface QueryState<R> {
25
25
  * alias → input-type map. Result:
26
26
  * - Undeclared alias → compile-time error at the `useWorkflow("...")` site
27
27
  * - Declared with full `{workflow_id, inputs}` form → callable typed as
28
- * `(inputs: <DeclaredShape>) => Promise<unknown>`
28
+ * `(inputs: <DeclaredShape>) => Promise<WorkflowResult>`
29
29
  * - Declared with shorthand (bare workflow_id) → callable typed as
30
- * `(inputs?: Record<string, unknown>) => Promise<unknown>` (untyped)
30
+ * `(inputs?: Record<string, unknown>) => Promise<WorkflowResult>` (untyped inputs)
31
31
  *
32
32
  * ```tsx
33
33
  * const issue = useWorkflow("issueInvoiceStorageDrop");
@@ -35,8 +35,19 @@ interface QueryState<R> {
35
35
  * ```
36
36
  */
37
37
  export declare function useWorkflow<K extends keyof AppWorkflows & string>(alias: K): UseWorkflowFn<K>;
38
- export declare function useWorkflow(alias: string): (inputs?: Record<string, unknown>) => Promise<unknown>;
39
- type UseWorkflowFn<K extends keyof AppWorkflows & string> = AppWorkflows[K] extends Record<string, unknown> ? AppWorkflows[K] extends Record<string, never> ? (inputs?: Record<string, never>) => Promise<unknown> : (inputs: AppWorkflows[K]) => Promise<unknown> : (inputs?: Record<string, unknown>) => Promise<unknown>;
38
+ export declare function useWorkflow(alias: string): (inputs?: Record<string, unknown>) => Promise<WorkflowResult>;
39
+ type UseWorkflowFn<K extends keyof AppWorkflows & string> = AppWorkflows[K] extends Record<string, unknown> ? AppWorkflows[K] extends Record<string, never> ? (inputs?: Record<string, never>) => Promise<WorkflowResult> : (inputs: AppWorkflows[K]) => Promise<WorkflowResult> : (inputs?: Record<string, unknown>) => Promise<WorkflowResult>;
40
+ /**
41
+ * Result of an app-workflow run — the execute endpoint's response. `files` holds
42
+ * any document a workflow step generated (e.g. via a `generate_*_from_template`
43
+ * tool), resolved for download: read `files[0].url` and pass it to `openExternal`.
44
+ * A workflow that generates no file resolves with `files` absent.
45
+ */
46
+ export interface WorkflowResult {
47
+ status: "success" | "error";
48
+ message?: string;
49
+ files?: UploadedFile[];
50
+ }
40
51
  type UseQueryParams<K extends keyof AppQueries & string> = AppQueries[K] extends Record<string, never> ? [params?: Record<string, never>] : [params: AppQueries[K]];
41
52
  /**
42
53
  * Read rows from a query the app's author declared in `lotics.queries`.
@@ -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 } from "./hooks.js";
20
- export type { UploadedFile } from "./hooks.js";
20
+ export type { UploadedFile, WorkflowResult } 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";
@@ -27,6 +27,7 @@ export { readSelect } from "./select.js";
27
27
  export type { ResolvedOption } from "./select.js";
28
28
  export type { AppFixture } from "./mock.js";
29
29
  export type { AppWorkflows, AppQueries } from "./types.js";
30
- export { row } from "./row.js";
30
+ export { row, readLinks } from "./row.js";
31
+ export type { ResolvedLink } from "./row.js";
31
32
  export { useOptimistic } from "./use_optimistic.js";
32
33
  export type { OptimisticApi } from "./use_optimistic.js";
package/dist/src/index.js CHANGED
@@ -20,5 +20,5 @@ export { rpc } from "./rpc.js";
20
20
  export { openExternal } from "./open_external.js";
21
21
  export { readMembers } from "./members.js";
22
22
  export { readSelect } from "./select.js";
23
- export { row } from "./row.js";
23
+ export { row, readLinks } from "./row.js";
24
24
  export { useOptimistic } from "./use_optimistic.js";
package/dist/src/row.d.ts CHANGED
@@ -28,11 +28,28 @@ declare function bool(v: unknown): boolean;
28
28
  * fields are not handled here — they have no consumer yet.)
29
29
  */
30
30
  declare function date(v: unknown): Date | null;
31
+ /** A linked record cell entry — the target record's id + its display text. */
32
+ export interface ResolvedLink {
33
+ /** The linked record's id (e.g. "rec_…"). Use to correlate/filter. */
34
+ id: string;
35
+ /** The linked record's display text (its primary-field value). Use to render. */
36
+ display: string;
37
+ }
38
+ /**
39
+ * select_record_link → the FIRST linked record as `{ id, display }` (or null).
40
+ * The common single-link case: read `.display` to render the linked record's
41
+ * name, `.id` to correlate/filter (e.g. group rows by a parent record). Use
42
+ * `readLinks` for the full list on multi-link fields.
43
+ */
44
+ declare function link(v: unknown): ResolvedLink | null;
45
+ /** select_record_link → ALL linked records as `{ id, display }[]` (empty if none). */
46
+ export declare function readLinks(v: unknown): ResolvedLink[];
31
47
  export declare const row: {
32
48
  opt: typeof opt;
33
49
  text: typeof text;
34
50
  num: typeof num;
35
51
  bool: typeof bool;
36
52
  date: typeof date;
53
+ link: typeof link;
37
54
  };
38
55
  export {};
package/dist/src/row.js CHANGED
@@ -60,4 +60,33 @@ function date(v) {
60
60
  const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(text(v));
61
61
  return m ? new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : null;
62
62
  }
63
- export const row = { opt, text, num, bool, date };
63
+ /** One `{ id, display }` object → ResolvedLink, or null if absent/malformed. */
64
+ function asLink(v) {
65
+ if (!v || typeof v !== "object")
66
+ return null;
67
+ const id = v.id;
68
+ if (typeof id !== "string" || !id)
69
+ return null;
70
+ const display = v.display;
71
+ return { id, display: typeof display === "string" ? display : "" };
72
+ }
73
+ /**
74
+ * select_record_link → the FIRST linked record as `{ id, display }` (or null).
75
+ * The common single-link case: read `.display` to render the linked record's
76
+ * name, `.id` to correlate/filter (e.g. group rows by a parent record). Use
77
+ * `readLinks` for the full list on multi-link fields.
78
+ */
79
+ function link(v) {
80
+ if (Array.isArray(v))
81
+ return v.length ? asLink(v[0]) : null;
82
+ return asLink(v);
83
+ }
84
+ /** select_record_link → ALL linked records as `{ id, display }[]` (empty if none). */
85
+ export function readLinks(v) {
86
+ if (!Array.isArray(v)) {
87
+ const one = asLink(v);
88
+ return one ? [one] : [];
89
+ }
90
+ return v.map(asLink).filter((x) => x !== null);
91
+ }
92
+ export const row = { opt, text, num, bool, date, link };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.17.0",
3
+ "version": "0.18.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": {