@lotics/app-sdk 0.1.0 → 0.2.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/dist/src/hooks.d.ts +19 -1
- package/dist/src/hooks.js +3 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/rpc.d.ts +1 -1
- package/dist/src/types.d.ts +26 -0
- package/package.json +1 -1
package/dist/src/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QueryAst, TableRow, WorkspaceTables } from "./types.js";
|
|
1
|
+
import type { AppWorkflows, QueryAst, TableRow, WorkspaceTables } from "./types.js";
|
|
2
2
|
interface QueryState<R> {
|
|
3
3
|
rows: R[];
|
|
4
4
|
loading: boolean;
|
|
@@ -30,6 +30,24 @@ export declare function useMutate(table_id: string): {
|
|
|
30
30
|
type RowFor<K extends keyof WorkspaceTables & string> = WorkspaceTables[K];
|
|
31
31
|
/** Trigger a workflow by action_id. Returns a callable that runs it. */
|
|
32
32
|
export declare function useAction(action_id: string): (inputs?: Record<string, unknown>) => Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Trigger a workflow by alias from the app's manifest.
|
|
35
|
+
*
|
|
36
|
+
* The alias must be declared in `package.json` "lotics.workflows" and synced
|
|
37
|
+
* to `apps.workflows` on the last deploy. Returns a callable; pass whatever
|
|
38
|
+
* inputs the workflow expects (the workflow's own trigger schema gates them
|
|
39
|
+
* server-side).
|
|
40
|
+
*
|
|
41
|
+
* Per-app `lotics types` codegen augments `AppWorkflows` with the declared
|
|
42
|
+
* alias keys — passing an undeclared alias is a compile-time error.
|
|
43
|
+
*
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const issue = useWorkflow("issueInvoiceStorageDrop");
|
|
46
|
+
* await issue({ record_id: row.__source_record_id });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function useWorkflow<K extends keyof AppWorkflows & string>(alias: K): (inputs?: Record<string, unknown>) => Promise<unknown>;
|
|
50
|
+
export declare function useWorkflow(alias: string): (inputs?: Record<string, unknown>) => Promise<unknown>;
|
|
33
51
|
/**
|
|
34
52
|
* Escape hatch — pass a raw query AST. Same shape the server validates via
|
|
35
53
|
* `parseQueryNode`. Use for joins, group-by, projections, and other shapes
|
package/dist/src/hooks.js
CHANGED
|
@@ -56,6 +56,9 @@ export function useMutate(table_id) {
|
|
|
56
56
|
export function useAction(action_id) {
|
|
57
57
|
return useCallback((inputs) => rpc("action", { action_id, inputs: inputs ?? {} }), [action_id]);
|
|
58
58
|
}
|
|
59
|
+
export function useWorkflow(alias) {
|
|
60
|
+
return useCallback((inputs) => rpc("workflow", { alias, inputs: inputs ?? {} }), [alias]);
|
|
61
|
+
}
|
|
59
62
|
/**
|
|
60
63
|
* Escape hatch — pass a raw query AST. Same shape the server validates via
|
|
61
64
|
* `parseQueryNode`. Use for joins, group-by, projections, and other shapes
|
package/dist/src/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* depending on packages/ui's React Native Web setup.
|
|
11
11
|
*/
|
|
12
12
|
export { mount } from "./mount.js";
|
|
13
|
-
export { useTable, useMutate, useAction, useQuery } from "./hooks.js";
|
|
13
|
+
export { useTable, useMutate, useAction, useWorkflow, useQuery } from "./hooks.js";
|
|
14
14
|
export { rpc } from "./rpc.js";
|
|
15
15
|
export type { RpcOp } from "./rpc.js";
|
|
16
|
-
export type { WorkspaceTables, RowOf, TableRow, SourceAddressing, QueryAst } from "./types.js";
|
|
16
|
+
export type { WorkspaceTables, AppWorkflows, RowOf, TableRow, SourceAddressing, QueryAst, } from "./types.js";
|
package/dist/src/index.js
CHANGED
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
* depending on packages/ui's React Native Web setup.
|
|
11
11
|
*/
|
|
12
12
|
export { mount } from "./mount.js";
|
|
13
|
-
export { useTable, useMutate, useAction, useQuery } from "./hooks.js";
|
|
13
|
+
export { useTable, useMutate, useAction, useWorkflow, useQuery } from "./hooks.js";
|
|
14
14
|
export { rpc } from "./rpc.js";
|
package/dist/src/rpc.d.ts
CHANGED
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* old bundles must keep working forever, since we can't force users to
|
|
15
15
|
* redeploy. Add new ops alongside existing ones; never repurpose them.
|
|
16
16
|
*/
|
|
17
|
-
export type RpcOp = "query" | "mutate" | "action" | "filter";
|
|
17
|
+
export type RpcOp = "query" | "mutate" | "action" | "workflow" | "filter";
|
|
18
18
|
export declare function rpc<T = unknown>(op: RpcOp, payload: unknown): Promise<T>;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -22,6 +22,32 @@
|
|
|
22
22
|
*/
|
|
23
23
|
export interface WorkspaceTables {
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* App-specific workflow augmentation point. Same pattern as WorkspaceTables.
|
|
27
|
+
*
|
|
28
|
+
* The base SDK ships `AppWorkflows` empty — `useWorkflow(alias)` accepts any
|
|
29
|
+
* string at runtime. Per-app codegen (folded into `lotics app pull`) emits a
|
|
30
|
+
* file that augments this interface with the aliases declared in the app's
|
|
31
|
+
* `package.json` lotics.workflows, giving compile-time autocomplete +
|
|
32
|
+
* "undeclared alias" errors:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* // .lotics/types.ts (generated)
|
|
36
|
+
* import "@lotics/app-sdk";
|
|
37
|
+
* declare module "@lotics/app-sdk" {
|
|
38
|
+
* interface AppWorkflows {
|
|
39
|
+
* "issueInvoiceStorageDrop": never;
|
|
40
|
+
* "issueInvoiceReuseLift": never;
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* The `never` value is a placeholder for v2 input/output typing — when the
|
|
46
|
+
* codegen learns to extract workflow trigger schemas, the value becomes the
|
|
47
|
+
* input type. For now the hook's runtime signature is unaffected.
|
|
48
|
+
*/
|
|
49
|
+
export interface AppWorkflows {
|
|
50
|
+
}
|
|
25
51
|
/**
|
|
26
52
|
* Helper: row type for a known table id, or fallback for unknown ones.
|
|
27
53
|
* Currently unused by exported hooks (useRecord deferred to v2) but kept
|