@verikit/react 0.23.1

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.
Files changed (104) hide show
  1. package/LICENSE.md +9 -0
  2. package/dist/client/index.d.ts +3 -0
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js +1 -0
  5. package/dist/client/use-verikit-client.d.ts +23 -0
  6. package/dist/client/use-verikit-client.d.ts.map +1 -0
  7. package/dist/client/use-verikit-client.js +22 -0
  8. package/dist/components/button.d.ts +11 -0
  9. package/dist/components/button.d.ts.map +1 -0
  10. package/dist/components/button.js +36 -0
  11. package/dist/components/checkbox.d.ts +5 -0
  12. package/dist/components/checkbox.d.ts.map +1 -0
  13. package/dist/components/checkbox.js +10 -0
  14. package/dist/components/dialog.d.ts +27 -0
  15. package/dist/components/dialog.d.ts.map +1 -0
  16. package/dist/components/dialog.js +40 -0
  17. package/dist/components/input.d.ts +5 -0
  18. package/dist/components/input.d.ts.map +1 -0
  19. package/dist/components/input.js +8 -0
  20. package/dist/components/label.d.ts +5 -0
  21. package/dist/components/label.d.ts.map +1 -0
  22. package/dist/components/label.js +7 -0
  23. package/dist/components/select.d.ts +26 -0
  24. package/dist/components/select.d.ts.map +1 -0
  25. package/dist/components/select.js +43 -0
  26. package/dist/components/textarea.d.ts +5 -0
  27. package/dist/components/textarea.d.ts.map +1 -0
  28. package/dist/components/textarea.js +7 -0
  29. package/dist/fields/field-shell.d.ts +28 -0
  30. package/dist/fields/field-shell.d.ts.map +1 -0
  31. package/dist/fields/field-shell.js +29 -0
  32. package/dist/fields/index.d.ts +7 -0
  33. package/dist/fields/index.d.ts.map +1 -0
  34. package/dist/fields/index.js +3 -0
  35. package/dist/fields/inputs.d.ts +22 -0
  36. package/dist/fields/inputs.d.ts.map +1 -0
  37. package/dist/fields/inputs.js +136 -0
  38. package/dist/fields/registry.d.ts +33 -0
  39. package/dist/fields/registry.d.ts.map +1 -0
  40. package/dist/fields/registry.js +31 -0
  41. package/dist/fields/types.d.ts +36 -0
  42. package/dist/fields/types.d.ts.map +1 -0
  43. package/dist/fields/types.js +1 -0
  44. package/dist/form/index.d.ts +11 -0
  45. package/dist/form/index.d.ts.map +1 -0
  46. package/dist/form/index.js +5 -0
  47. package/dist/form/use-verikit-form.d.ts +37 -0
  48. package/dist/form/use-verikit-form.d.ts.map +1 -0
  49. package/dist/form/use-verikit-form.js +66 -0
  50. package/dist/form/use-verikit-schema-tree-form.d.ts +46 -0
  51. package/dist/form/use-verikit-schema-tree-form.d.ts.map +1 -0
  52. package/dist/form/use-verikit-schema-tree-form.js +94 -0
  53. package/dist/index.d.ts +10 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +8 -0
  56. package/dist/layout/index.d.ts +5 -0
  57. package/dist/layout/index.d.ts.map +1 -0
  58. package/dist/layout/index.js +2 -0
  59. package/dist/layout/render-schema-node.d.ts +9 -0
  60. package/dist/layout/render-schema-node.d.ts.map +1 -0
  61. package/dist/layout/render-schema-node.js +143 -0
  62. package/dist/layout/types.d.ts +68 -0
  63. package/dist/layout/types.d.ts.map +1 -0
  64. package/dist/layout/types.js +1 -0
  65. package/dist/lib/utils.d.ts +4 -0
  66. package/dist/lib/utils.d.ts.map +1 -0
  67. package/dist/lib/utils.js +6 -0
  68. package/dist/query/index.d.ts +13 -0
  69. package/dist/query/index.d.ts.map +1 -0
  70. package/dist/query/index.js +6 -0
  71. package/dist/query/use-resource-form.d.ts +38 -0
  72. package/dist/query/use-resource-form.d.ts.map +1 -0
  73. package/dist/query/use-resource-form.js +31 -0
  74. package/dist/query/use-resource-mutations.d.ts +30 -0
  75. package/dist/query/use-resource-mutations.d.ts.map +1 -0
  76. package/dist/query/use-resource-mutations.js +107 -0
  77. package/dist/query/use-resource-queries.d.ts +15 -0
  78. package/dist/query/use-resource-queries.d.ts.map +1 -0
  79. package/dist/query/use-resource-queries.js +35 -0
  80. package/dist/query/use-resource-schema-tree-form.d.ts +35 -0
  81. package/dist/query/use-resource-schema-tree-form.d.ts.map +1 -0
  82. package/dist/query/use-resource-schema-tree-form.js +43 -0
  83. package/dist/query/use-resource-table.d.ts +46 -0
  84. package/dist/query/use-resource-table.d.ts.map +1 -0
  85. package/dist/query/use-resource-table.js +81 -0
  86. package/dist/relationships/belongs-to-field.d.ts +29 -0
  87. package/dist/relationships/belongs-to-field.d.ts.map +1 -0
  88. package/dist/relationships/belongs-to-field.js +28 -0
  89. package/dist/relationships/index.d.ts +3 -0
  90. package/dist/relationships/index.d.ts.map +1 -0
  91. package/dist/relationships/index.js +1 -0
  92. package/dist/resource/index.d.ts +5 -0
  93. package/dist/resource/index.d.ts.map +1 -0
  94. package/dist/resource/index.js +2 -0
  95. package/dist/resource/resource-form.d.ts +28 -0
  96. package/dist/resource/resource-form.d.ts.map +1 -0
  97. package/dist/resource/resource-form.js +25 -0
  98. package/dist/resource/resource-table-filters.d.ts +26 -0
  99. package/dist/resource/resource-table-filters.d.ts.map +1 -0
  100. package/dist/resource/resource-table-filters.js +151 -0
  101. package/dist/resource/resource-table.d.ts +45 -0
  102. package/dist/resource/resource-table.d.ts.map +1 -0
  103. package/dist/resource/resource-table.js +179 -0
  104. package/package.json +89 -0
@@ -0,0 +1,143 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { isFieldConditionMet, } from "@verikit/core";
3
+ import { Button } from "#components/button";
4
+ import { cn } from "#lib/utils";
5
+ import { RenderField } from "../fields/index.js";
6
+ import { BelongsToRelationshipField } from "../relationships/belongs-to-field.js";
7
+ import { getValueAtPath, pathKey, } from "@verikit/ui-core/layout/path";
8
+ function actionSchemaFor(node, props) {
9
+ const source = props.actions?.[node.name];
10
+ if (!source) {
11
+ return undefined;
12
+ }
13
+ return "toSchema" in source ? source.toSchema() : source;
14
+ }
15
+ function actionInputNodes(node, props) {
16
+ const actionSchema = actionSchemaFor(node, props);
17
+ if (actionSchema?.form) {
18
+ return Object.entries(actionSchema.form).map(([name, field]) => ({
19
+ ...field,
20
+ type: "field",
21
+ name,
22
+ }));
23
+ }
24
+ return node.input;
25
+ }
26
+ function schemaNodeKey(node, index) {
27
+ return "name" in node && typeof node.name === "string"
28
+ ? `${node.type}:${node.name}`
29
+ : `${node.type}:${index}`;
30
+ }
31
+ function clampIndex(index, length) {
32
+ if (length <= 0) {
33
+ return 0;
34
+ }
35
+ return Math.min(Math.max(index, 0), length - 1);
36
+ }
37
+ function schemaRenderProps(props) {
38
+ const { node: _node, className: _className, ...rest } = props;
39
+ return rest;
40
+ }
41
+ /** Sibling values at a node's own nesting level, for evaluating `condition`. */
42
+ function siblingValues(values, path) {
43
+ const container = getValueAtPath(values, path);
44
+ return typeof container === "object" &&
45
+ container !== null &&
46
+ !Array.isArray(container)
47
+ ? container
48
+ : {};
49
+ }
50
+ function renderFieldNode(node, props, path) {
51
+ if (!isFieldConditionMet(node.condition, siblingValues(props.values, path))) {
52
+ return null;
53
+ }
54
+ const fieldPath = [...path, node.name];
55
+ return (_jsx(RenderField, { field: node, registry: props.registry, className: props.className, value: getValueAtPath(props.values, fieldPath), error: props.errors?.[pathKey(fieldPath)], disabled: props.disabled, readOnly: props.readOnly, onValueChange: (value) => props.onFieldChange?.(fieldPath, value), onBlur: () => props.onFieldBlur?.(fieldPath) }));
56
+ }
57
+ /**
58
+ * Resolves relationships using a field reference from `.via()`.
59
+ * Adapter-specific references require a custom `renderRelationship`.
60
+ */
61
+ function resolveForeignKeyFieldName(foreignKey) {
62
+ return typeof foreignKey === "string" ? foreignKey : undefined;
63
+ }
64
+ /**
65
+ * Renders relationships using `renderRelationship` when provided.
66
+ * Otherwise, `belongsTo` uses the built-in picker when its foreign key
67
+ * is resolvable; collection relationships render nothing by default.
68
+ */
69
+ function renderRelationshipNode(node, props, path) {
70
+ if (props.renderRelationship) {
71
+ return props.renderRelationship(node, path);
72
+ }
73
+ if (node.relationshipType !== "belongsTo") {
74
+ return null;
75
+ }
76
+ const foreignKeyName = resolveForeignKeyFieldName(node.foreignKey);
77
+ if (!foreignKeyName) {
78
+ return null;
79
+ }
80
+ const foreignKeyPath = [...path, foreignKeyName];
81
+ return (_jsx(BelongsToRelationshipField, { relationship: node, className: props.className, value: getValueAtPath(props.values, foreignKeyPath), error: props.errors?.[pathKey(foreignKeyPath)], disabled: props.disabled, readOnly: props.readOnly, onValueChange: (value) => props.onFieldChange?.(foreignKeyPath, value), onBlur: () => props.onFieldBlur?.(foreignKeyPath) }));
82
+ }
83
+ function renderSectionNode(node, props, path) {
84
+ return (_jsxs("section", { className: cn("grid gap-4", props.className), children: [_jsx("h3", { className: "text-sm font-medium text-foreground", children: node.title }), _jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: node.children, path: path })] }));
85
+ }
86
+ function renderGridNode(node, props, path) {
87
+ return (_jsx("div", { className: cn("grid gap-4", props.className), style: { gridTemplateColumns: `repeat(${node.columns}, minmax(0, 1fr))` }, children: _jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: node.children, path: path }) }));
88
+ }
89
+ function renderTabsNode(node, props, path) {
90
+ const activeTab = clampIndex(props.activeTab ?? 0, node.tabs.length);
91
+ const activeTabEntry = node.tabs[activeTab];
92
+ return (_jsxs("div", { className: cn("grid gap-4", props.className), children: [_jsx("div", { role: "tablist", className: "flex flex-wrap gap-1 border-b border-border", children: node.tabs.map((tab, index) => (_jsx(Button, { type: "button", role: "tab", "aria-selected": index === activeTab, variant: index === activeTab ? "secondary" : "ghost", size: "sm", onClick: () => props.onActiveTabChange?.(index), children: tab.title }, tab.title))) }), activeTabEntry ? (_jsx("div", { role: "tabpanel", children: _jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: activeTabEntry.children, path: path }) })) : null] }));
93
+ }
94
+ function renderWizardNode(node, props, path) {
95
+ const stepCount = node.steps.length;
96
+ const activeStep = clampIndex(props.activeStep ?? 0, stepCount);
97
+ const activeStepEntry = node.steps[activeStep];
98
+ return (_jsxs("div", { className: cn("grid gap-4", props.className), children: [_jsx("ol", { className: "flex flex-wrap gap-3 text-sm text-muted-foreground", children: node.steps.map((step, index) => (_jsx("li", { "aria-current": index === activeStep ? "step" : undefined, className: cn(index === activeStep && "font-medium text-foreground"), children: step.title }, step.title))) }), activeStepEntry ? (_jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: activeStepEntry.children, path: path })) : null, _jsxs("div", { className: "flex justify-between gap-2", children: [_jsx(Button, { type: "button", variant: "outline", size: "sm", disabled: activeStep <= 0, onClick: () => props.onActiveStepChange?.(activeStep - 1), children: "Back" }), _jsx(Button, { type: "button", size: "sm", disabled: activeStep >= stepCount - 1, onClick: () => props.onActiveStepChange?.(activeStep + 1), children: "Next" })] })] }));
99
+ }
100
+ /**
101
+ * Renders a repeater's rows keyed by `getRepeaterRowKey` (when the caller supplies one, as `useVerikitSchemaTreeForm` does) instead of array index. Index-based keys make React reuse a removed row's DOM (and any focus or uncontrolled state inside it) for whatever row happens to shift into its position afterward. Falls back to `index` when no key source is given, so a caller wiring this tree up manually without the hook keeps the previous (imperfect, but no worse than before) behavior.
102
+ */
103
+ function renderRepeaterNode(node, props, path) {
104
+ const repeaterPath = [...path, node.name];
105
+ const items = getValueAtPath(props.values, repeaterPath);
106
+ const rows = Array.isArray(items) ? items : [];
107
+ return (_jsxs("div", { className: cn("grid gap-4", props.className), children: [rows.map((_, index) => (_jsxs("div", { className: "grid gap-3 rounded-lg border border-border p-3", children: [_jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: node.children, path: [...repeaterPath, index] }), _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "justify-self-start", onClick: () => props.onRepeaterRemove?.(repeaterPath, index), children: "Remove" })] }, props.getRepeaterRowKey?.(repeaterPath, index) ?? index))), _jsx(Button, { type: "button", variant: "outline", size: "sm", className: "justify-self-start", onClick: () => props.onRepeaterAdd?.(repeaterPath), children: "Add" })] }));
108
+ }
109
+ function renderActionNode(node, props, path) {
110
+ const actionPath = [...path, node.name];
111
+ const actionSchema = actionSchemaFor(node, props);
112
+ const input = actionInputNodes(node, props);
113
+ return (_jsxs("div", { className: cn("grid gap-4", props.className), children: [input ? (_jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: input, path: actionPath })) : null, _jsx(Button, { type: "button", className: "justify-self-start", onClick: () => props.onAction?.(node.name, actionPath), children: node.label ?? actionSchema?.label ?? node.name })] }));
114
+ }
115
+ /**
116
+ * Renders one Verikit schema node using the built-in React layout components.
117
+ */
118
+ export function RenderSchemaNode(props) {
119
+ const { node } = props;
120
+ const path = props.path ?? [];
121
+ switch (node.type) {
122
+ case "field":
123
+ return renderFieldNode(node, props, path);
124
+ case "relationship":
125
+ return renderRelationshipNode(node, props, path);
126
+ case "section":
127
+ return renderSectionNode(node, props, path);
128
+ case "grid":
129
+ return renderGridNode(node, props, path);
130
+ case "tabs":
131
+ return renderTabsNode(node, props, path);
132
+ case "wizard":
133
+ return renderWizardNode(node, props, path);
134
+ case "repeater":
135
+ return renderRepeaterNode(node, props, path);
136
+ case "action":
137
+ return renderActionNode(node, props, path);
138
+ }
139
+ }
140
+ /** Renders a list of Verikit schema nodes. */
141
+ export function RenderSchemaTree({ nodes, ...rest }) {
142
+ return (_jsx(_Fragment, { children: nodes.map((node, index) => (_jsx(RenderSchemaNode, { node: node, ...rest }, schemaNodeKey(node, index)))) }));
143
+ }
@@ -0,0 +1,68 @@
1
+ import type { RelationshipNode, SchemaNode } from "@verikit/core";
2
+ import type { ActionSchema } from "@verikit/runtime";
3
+ import type { ReactNode } from "react";
4
+ import type { VerikitFieldRegistry } from "../fields/index.js";
5
+ import type { SchemaPath } from "@verikit/ui-core/layout/path";
6
+ /**
7
+ * Runtime action builder or serialized action schema used by schema renderers.
8
+ */
9
+ export type SchemaActionSource = ActionSchema | {
10
+ readonly name: string;
11
+ toSchema(): ActionSchema;
12
+ };
13
+ /** Runtime actions keyed by action node name. */
14
+ export type SchemaActionRegistry = Partial<Record<string, SchemaActionSource>>;
15
+ /** Shared props used while rendering Verikit schema nodes. */
16
+ export interface SchemaRenderProps {
17
+ /** Current form values. */
18
+ values: Record<string, unknown>;
19
+ /** Path prefix for nested schema nodes. */
20
+ path?: SchemaPath;
21
+ /** Error content keyed by schema path. */
22
+ errors?: Record<string, ReactNode>;
23
+ /** Disables all rendered fields when supported. */
24
+ disabled?: boolean;
25
+ /** Marks all rendered fields as read-only when supported. */
26
+ readOnly?: boolean;
27
+ /** Optional field renderer overrides. */
28
+ registry?: Partial<VerikitFieldRegistry>;
29
+ /** Runtime actions whose forms should render for matching action nodes. */
30
+ actions?: SchemaActionRegistry;
31
+ /** Active tab index for tab nodes. */
32
+ activeTab?: number;
33
+ /** Called when a tab node changes active tab. */
34
+ onActiveTabChange?: (index: number) => void;
35
+ /** Active step index for wizard nodes. */
36
+ activeStep?: number;
37
+ /** Called when a wizard node changes active step. */
38
+ onActiveStepChange?: (index: number) => void;
39
+ /** Called when a field value changes. */
40
+ onFieldChange?: (path: SchemaPath, value: unknown) => void;
41
+ /** Called when a field loses focus. */
42
+ onFieldBlur?: (path: SchemaPath) => void;
43
+ /** Called when an action node is triggered. */
44
+ onAction?: (name: string, path: SchemaPath) => void;
45
+ /** Called when a repeater should append an item. */
46
+ onRepeaterAdd?: (path: SchemaPath) => void;
47
+ /** Called when a repeater should remove an item. */
48
+ onRepeaterRemove?: (path: SchemaPath, index: number) => void;
49
+ /**
50
+ * Returns a stable React key for a repeater row, given the repeater's own path and the row's current index. Falls back to `index` when omitted fine for a tree with no repeaters, but a caller that removes rows from the middle of one should supply this (`useVerikitSchemaTreeForm` does) so React doesn't reuse a removed row's DOM for whatever row shifts into its position.
51
+ */
52
+ getRepeaterRowKey?: (path: SchemaPath, index: number) => string;
53
+ /** Custom renderer for relationship nodes. */
54
+ renderRelationship?: (node: RelationshipNode, path: SchemaPath) => ReactNode;
55
+ }
56
+ /** Props for rendering a single schema node. */
57
+ export interface RenderSchemaNodeProps extends SchemaRenderProps {
58
+ /** Schema node to render. */
59
+ node: SchemaNode;
60
+ /** Class name applied to the node wrapper when supported. */
61
+ className?: string;
62
+ }
63
+ /** Props for rendering a list of schema nodes. */
64
+ export interface RenderSchemaTreeProps extends SchemaRenderProps {
65
+ /** Schema nodes to render in order. */
66
+ nodes: readonly SchemaNode[];
67
+ }
68
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/layout/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,IAAI,YAAY,CAAC;CAC1B,CAAC;AAEN,iDAAiD;AACjD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAE/E,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,2CAA2C;IAC3C,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,yCAAyC;IACzC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,uCAAuC;IACvC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACzC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpD,oDAAoD;IACpD,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAC3C,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAChE,8CAA8C;IAC9C,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK,SAAS,CAAC;CAC9E;AAED,gDAAgD;AAChD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,6BAA6B;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,uCAAuC;IACvC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { type ClassValue } from "clsx";
2
+ /** Merges conditional class names and resolves Tailwind conflicts. */
3
+ export declare function cn(...inputs: ClassValue[]): string;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7C,sEAAsE;AACtE,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAElD"}
@@ -0,0 +1,6 @@
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ /** Merges conditional class names and resolves Tailwind conflicts. */
4
+ export function cn(...inputs) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,13 @@
1
+ export { useListResource, useResourceFind, useResourceRelationship, } from "./use-resource-queries.js";
2
+ export type { UseListResourceOptions, UseFindResourceOptions, UseResourceRelationshipOptions, } from "./use-resource-queries.js";
3
+ export { useCreateResource, useUpdateResource, useDeleteResource, useActionResource, } from "./use-resource-mutations.js";
4
+ export type { UseCreateResourceOptions, UpdateResourceVariables, UseUpdateResourceOptions, UseDeleteResourceOptions, ActionResourceVariables, UseActionResourceOptions, } from "./use-resource-mutations.js";
5
+ export { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
6
+ export type { ResourceQueryKeys } from "@verikit/ui-core/query/query-keys";
7
+ export { useResourceForm } from "./use-resource-form.js";
8
+ export type { UseResourceFormOptions, UseResourceFormResult, UseResourceFormSource, } from "./use-resource-form.js";
9
+ export { useResourceSchemaTreeForm } from "./use-resource-schema-tree-form.js";
10
+ export type { UseResourceSchemaTreeFormOptions, UseResourceSchemaTreeFormResult, } from "./use-resource-schema-tree-form.js";
11
+ export { useResourceTable } from "./use-resource-table.js";
12
+ export type { UseResourceTableOptions, UseResourceTableResult, UseResourceTableSource, } from "./use-resource-table.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,YAAY,EACV,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { useListResource, useResourceFind, useResourceRelationship, } from "./use-resource-queries.js";
2
+ export { useCreateResource, useUpdateResource, useDeleteResource, useActionResource, } from "./use-resource-mutations.js";
3
+ export { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
4
+ export { useResourceForm } from "./use-resource-form.js";
5
+ export { useResourceSchemaTreeForm } from "./use-resource-schema-tree-form.js";
6
+ export { useResourceTable } from "./use-resource-table.js";
@@ -0,0 +1,38 @@
1
+ import type { Resource, ResourceSchema } from "@verikit/core";
2
+ import type { UseVerikitFormResult } from "../form/use-verikit-form.js";
3
+ import type { VerikitFormValues } from "@verikit/ui-core/form/submission";
4
+ /** A resource builder or its finalized schema either carries its own name. */
5
+ export type UseResourceFormSource = Resource | ResourceSchema;
6
+ /** Options for creating a resource-backed form that submits over `@verikit/client`. */
7
+ export interface UseResourceFormOptions<TRecord> {
8
+ /** Updates the record with this id instead of creating a new one. */
9
+ id?: string;
10
+ /** Initial values passed to TanStack Form. */
11
+ defaultValues?: VerikitFormValues;
12
+ /** Called with the created or updated record after a successful submit. */
13
+ onSuccess?: (record: TRecord) => void;
14
+ /**
15
+ * Called when the create/update mutation itself fails (e.g. a network error
16
+ * or a permission-denied response) — not for client-side field validation
17
+ * failures, which surface via `fieldErrors`/`submitError` instead.
18
+ */
19
+ onError?: (error: Error) => void;
20
+ }
21
+ /** State and helpers returned by {@link useResourceForm}. */
22
+ export interface UseResourceFormResult<TRecord = Record<string, unknown>> extends UseVerikitFormResult<TRecord> {
23
+ /** Whether the create/update mutation is currently in flight. */
24
+ isSubmitting: boolean;
25
+ /** Error from the most recent create/update mutation, if any. */
26
+ submitError: Error | null;
27
+ }
28
+ /**
29
+ * The single resource-backed form hook: takes a `Resource` (or its
30
+ * `ResourceSchema`) and wires `useVerikitForm` straight to its create/update
31
+ * mutation hooks its own name is the one source of truth for both the
32
+ * fields and which resource to submit to, so there's no separate `name`
33
+ * string or raw field map to keep in sync with it. Submitting infers,
34
+ * validates, and sends the request in one step. Creates when no `id` option
35
+ * is given, updates that record's id otherwise.
36
+ */
37
+ export declare function useResourceForm<TRecord = Record<string, unknown>>(resource: UseResourceFormSource, { id, defaultValues, onSuccess, onError, }?: UseResourceFormOptions<TRecord>): UseResourceFormResult<TRecord>;
38
+ //# sourceMappingURL=use-resource-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resource-form.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAM1E,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE9D,uFAAuF;AACvF,MAAM,WAAW,sBAAsB,CAAC,OAAO;IAC7C,qEAAqE;IACrE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,6DAA6D;AAC7D,MAAM,WAAW,qBAAqB,CACpC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjC,SAAQ,oBAAoB,CAAC,OAAO,CAAC;IACrC,iEAAiE;IACjE,YAAY,EAAE,OAAO,CAAC;IACtB,iEAAiE;IACjE,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,QAAQ,EAAE,qBAAqB,EAC/B,EACE,EAAE,EACF,aAAa,EACb,SAAS,EACT,OAAO,GACR,GAAE,sBAAsB,CAAC,OAAO,CAAM,GACtC,qBAAqB,CAAC,OAAO,CAAC,CAsBhC"}
@@ -0,0 +1,31 @@
1
+ import { useVerikitForm } from "../form/use-verikit-form.js";
2
+ import { useCreateResource, useUpdateResource, } from "./use-resource-mutations.js";
3
+ /**
4
+ * The single resource-backed form hook: takes a `Resource` (or its
5
+ * `ResourceSchema`) and wires `useVerikitForm` straight to its create/update
6
+ * mutation hooks its own name is the one source of truth for both the
7
+ * fields and which resource to submit to, so there's no separate `name`
8
+ * string or raw field map to keep in sync with it. Submitting infers,
9
+ * validates, and sends the request in one step. Creates when no `id` option
10
+ * is given, updates that record's id otherwise.
11
+ */
12
+ export function useResourceForm(resource, { id, defaultValues, onSuccess, onError, } = {}) {
13
+ const create = useCreateResource(resource.name, { onError });
14
+ const update = useUpdateResource(resource.name, { onError });
15
+ const form = useVerikitForm({
16
+ fields: resource,
17
+ defaultValues,
18
+ onSubmit: async (values) => {
19
+ const record = id
20
+ ? await update.mutateAsync({ id, input: values })
21
+ : await create.mutateAsync(values);
22
+ onSuccess?.(record);
23
+ return record;
24
+ },
25
+ });
26
+ return {
27
+ ...form,
28
+ isSubmitting: create.isPending || update.isPending,
29
+ submitError: create.error ?? update.error,
30
+ };
31
+ }
@@ -0,0 +1,30 @@
1
+ import type { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
2
+ import type { ActionOptions, ActionResult } from "@verikit/client";
3
+ export type UseCreateResourceOptions<TRecord> = Omit<UseMutationOptions<TRecord, Error, Record<string, unknown>>, "mutationFn">;
4
+ /**
5
+ * Creates a resource record, invalidating that resource's list/search queries on success.
6
+ */
7
+ export declare function useCreateResource<TRecord = Record<string, unknown>>(name: string, options?: UseCreateResourceOptions<TRecord>): UseMutationResult<TRecord, Error, Record<string, unknown>>;
8
+ export interface UpdateResourceVariables {
9
+ id: string;
10
+ input: Record<string, unknown>;
11
+ }
12
+ export type UseUpdateResourceOptions<TRecord> = Omit<UseMutationOptions<TRecord, Error, UpdateResourceVariables>, "mutationFn">;
13
+ /**
14
+ * Updates a resource record. Optimistically merges `input` into the cached `find(id)` record and any matching row in a cached list, rolling back to the pre-mutation snapshot on error; invalidates its list/search and find(id) queries on success (so any field the server computed, not just what was sent, ends up correct).
15
+ */
16
+ export declare function useUpdateResource<TRecord = Record<string, unknown>>(name: string, options?: UseUpdateResourceOptions<TRecord>): UseMutationResult<TRecord, Error, UpdateResourceVariables>;
17
+ export type UseDeleteResourceOptions = Omit<UseMutationOptions<void, Error, string>, "mutationFn">;
18
+ /**
19
+ * Deletes a resource record by id. Optimistically removes it from any cached list and evicts its `find(id)` cache entry outright. On error it restores only that record from its snapshot, preserving concurrent sibling deletes; on success, it invalidates list/search queries and (redundantly but harmlessly) re-evicts `find(id)`, since refetching a known-deleted record would just 404.
20
+ */
21
+ export declare function useDeleteResource(name: string, options?: UseDeleteResourceOptions): UseMutationResult<void, Error, string>;
22
+ export interface ActionResourceVariables extends ActionOptions {
23
+ input?: Record<string, unknown>;
24
+ }
25
+ export type UseActionResourceOptions<TResult> = Omit<UseMutationOptions<ActionResult<TResult>, Error, ActionResourceVariables>, "mutationFn">;
26
+ /**
27
+ * Runs a named runtime action, invalidating the resource's cached queries on success.
28
+ */
29
+ export declare function useActionResource<TResult = unknown>(name: string, actionName: string, options?: UseActionResourceOptions<TResult>): UseMutationResult<ActionResult<TResult>, Error, ActionResourceVariables>;
30
+ //# sourceMappingURL=use-resource-mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resource-mutations.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAYnE,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAAI,IAAI,CAClD,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC3D,YAAY,CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,GAC1C,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAa5D;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAAI,IAAI,CAClD,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,uBAAuB,CAAC,EAC3D,YAAY,CACb,CAAC;AAOF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,GAC1C,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAyD5D;AAED,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,EACvC,YAAY,CACb,CAAC;AAOF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB,GACjC,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CA6CxC;AAED,MAAM,WAAW,uBAAwB,SAAQ,aAAa;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAAI,IAAI,CAClD,kBAAkB,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,EACzE,YAAY,CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAG,OAAO,EACjD,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,GAC1C,iBAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAc1E"}
@@ -0,0 +1,107 @@
1
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
2
+ import { useVerikitClient } from "../client/use-verikit-client.js";
3
+ import { patchCachedListRecord, removeCachedListRecord, restoreDeletedRecord, restoreResourceQueries, snapshotResourceQueries, } from "@verikit/ui-core/query/optimistic";
4
+ import { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
5
+ /**
6
+ * Creates a resource record, invalidating that resource's list/search queries on success.
7
+ */
8
+ export function useCreateResource(name, options) {
9
+ const client = useVerikitClient();
10
+ const queryClient = useQueryClient();
11
+ const keys = resourceQueryKeys(name);
12
+ return useMutation({
13
+ ...options,
14
+ mutationFn: (input) => client.resource(name).create(input),
15
+ onSuccess: (...args) => {
16
+ void queryClient.invalidateQueries({ queryKey: keys.all });
17
+ return options?.onSuccess?.(...args);
18
+ },
19
+ });
20
+ }
21
+ /**
22
+ * Updates a resource record. Optimistically merges `input` into the cached `find(id)` record and any matching row in a cached list, rolling back to the pre-mutation snapshot on error; invalidates its list/search and find(id) queries on success (so any field the server computed, not just what was sent, ends up correct).
23
+ */
24
+ export function useUpdateResource(name, options) {
25
+ const client = useVerikitClient();
26
+ const queryClient = useQueryClient();
27
+ const keys = resourceQueryKeys(name);
28
+ return useMutation({
29
+ ...options,
30
+ mutationFn: ({ id, input }) => client.resource(name).update(id, input),
31
+ onMutate: async (variables, mutationContext) => {
32
+ await queryClient.cancelQueries({ queryKey: keys.all });
33
+ const snapshot = snapshotResourceQueries(queryClient, keys);
34
+ queryClient.setQueryData(keys.find(variables.id), (current) => current ? { ...current, ...variables.input } : current);
35
+ patchCachedListRecord(queryClient, keys, variables.id, (record) => ({ ...record, ...variables.input }));
36
+ const caller = await options?.onMutate?.(variables, mutationContext);
37
+ return { snapshot, caller };
38
+ },
39
+ onError: (error, variables, onMutateResult, mutationContext) => {
40
+ if (onMutateResult) {
41
+ restoreResourceQueries(queryClient, onMutateResult.snapshot);
42
+ }
43
+ return options?.onError?.(error, variables, onMutateResult?.caller, mutationContext);
44
+ },
45
+ // `keys.all` is a prefix of `keys.find(id)`, so this one call already
46
+ // invalidates both the resource's lists and that specific find(id) entry.
47
+ // Runs in onSettled (not onSuccess) so a failed mutation also forces a
48
+ // refetch: onError's rollback restores a pre-mutation snapshot, which can
49
+ // be stale if a background refetch wrote fresher data while this
50
+ // mutation was in flight.
51
+ onSettled: (data, error, variables, onMutateResult, mutationContext) => {
52
+ void queryClient.invalidateQueries({ queryKey: keys.all });
53
+ return options?.onSettled?.(data, error, variables, onMutateResult?.caller, mutationContext);
54
+ },
55
+ });
56
+ }
57
+ /**
58
+ * Deletes a resource record by id. Optimistically removes it from any cached list and evicts its `find(id)` cache entry outright. On error it restores only that record from its snapshot, preserving concurrent sibling deletes; on success, it invalidates list/search queries and (redundantly but harmlessly) re-evicts `find(id)`, since refetching a known-deleted record would just 404.
59
+ */
60
+ export function useDeleteResource(name, options) {
61
+ const client = useVerikitClient();
62
+ const queryClient = useQueryClient();
63
+ const keys = resourceQueryKeys(name);
64
+ return useMutation({
65
+ ...options,
66
+ mutationFn: (id) => client.resource(name).delete(id),
67
+ onMutate: async (id, mutationContext) => {
68
+ await queryClient.cancelQueries({ queryKey: keys.all });
69
+ const snapshot = snapshotResourceQueries(queryClient, keys);
70
+ queryClient.removeQueries({ queryKey: keys.find(id), exact: true });
71
+ removeCachedListRecord(queryClient, keys, id);
72
+ const caller = await options?.onMutate?.(id, mutationContext);
73
+ return { snapshot, caller };
74
+ },
75
+ onError: (error, id, onMutateResult, mutationContext) => {
76
+ if (onMutateResult) {
77
+ restoreDeletedRecord(queryClient, onMutateResult.snapshot, id);
78
+ }
79
+ return options?.onError?.(error, id, onMutateResult?.caller, mutationContext);
80
+ },
81
+ onSuccess: (data, id, ...rest) => {
82
+ queryClient.removeQueries({ queryKey: keys.find(id) });
83
+ return options?.onSuccess?.(data, id, ...rest);
84
+ },
85
+ // Always refetch after deletion to reconcile optimistic state with the server.
86
+ onSettled: (data, error, id, onMutateResult, mutationContext) => {
87
+ void queryClient.invalidateQueries({ queryKey: keys.all });
88
+ return options?.onSettled?.(data, error, id, onMutateResult?.caller, mutationContext);
89
+ },
90
+ });
91
+ }
92
+ /**
93
+ * Runs a named runtime action, invalidating the resource's cached queries on success.
94
+ */
95
+ export function useActionResource(name, actionName, options) {
96
+ const client = useVerikitClient();
97
+ const queryClient = useQueryClient();
98
+ const keys = resourceQueryKeys(name);
99
+ return useMutation({
100
+ ...options,
101
+ mutationFn: ({ input, ...actionOptions }) => client.resource(name).action(actionName, input, actionOptions),
102
+ onSuccess: (...args) => {
103
+ void queryClient.invalidateQueries({ queryKey: keys.all });
104
+ return options?.onSuccess?.(...args);
105
+ },
106
+ });
107
+ }
@@ -0,0 +1,15 @@
1
+ import type { UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
2
+ import type { ListParams, ListResponse } from "@verikit/client";
3
+ export type UseListResourceOptions<TRecord> = Omit<UseQueryOptions<ListResponse<TRecord>, Error>, "queryKey" | "queryFn">;
4
+ /** Lists a resource's records, cached per resource name + params. */
5
+ export declare function useListResource<TRecord = Record<string, unknown>>(name: string, params?: ListParams, options?: UseListResourceOptions<TRecord>): UseQueryResult<ListResponse<TRecord>, Error>;
6
+ export type UseFindResourceOptions<TRecord> = Omit<UseQueryOptions<TRecord, Error>, "queryKey" | "queryFn">;
7
+ /** Fetches a single resource record by id, cached per resource name + id. */
8
+ export declare function useResourceFind<TRecord = Record<string, unknown>>(name: string, id: string, options?: UseFindResourceOptions<TRecord>): UseQueryResult<TRecord, Error>;
9
+ export type UseResourceRelationshipOptions<TTarget> = Omit<UseQueryOptions<ListResponse<TTarget>, Error>, "queryKey" | "queryFn">;
10
+ /**
11
+ * Lists selectable records for a `belongsTo` relationship, cached by
12
+ * resource, relationship, and params. Server-side permissions and scopes apply.
13
+ */
14
+ export declare function useResourceRelationship<TTarget = Record<string, unknown>>(name: string, relationshipName: string, params?: ListParams, options?: UseResourceRelationshipOptions<TTarget>): UseQueryResult<ListResponse<TTarget>, Error>;
15
+ //# sourceMappingURL=use-resource-queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resource-queries.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE7E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIhE,MAAM,MAAM,sBAAsB,CAAC,OAAO,IAAI,IAAI,CAChD,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAC7C,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,UAAe,EACvB,OAAO,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACxC,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAS9C;AAED,MAAM,MAAM,sBAAsB,CAAC,OAAO,IAAI,IAAI,CAChD,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,EAC/B,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF,6EAA6E;AAC7E,wBAAgB,eAAe,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACxC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAShC;AAED,MAAM,MAAM,8BAA8B,CAAC,OAAO,IAAI,IAAI,CACxD,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAC7C,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvE,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,MAAM,EACxB,MAAM,GAAE,UAAe,EACvB,OAAO,CAAC,EAAE,8BAA8B,CAAC,OAAO,CAAC,GAChD,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAW9C"}
@@ -0,0 +1,35 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import { useVerikitClient } from "../client/use-verikit-client.js";
3
+ import { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
4
+ /** Lists a resource's records, cached per resource name + params. */
5
+ export function useListResource(name, params = {}, options) {
6
+ const client = useVerikitClient();
7
+ return useQuery({
8
+ queryKey: resourceQueryKeys(name).list(params),
9
+ queryFn: ({ signal }) => client.resource(name).list(params, { signal }),
10
+ ...options,
11
+ });
12
+ }
13
+ /** Fetches a single resource record by id, cached per resource name + id. */
14
+ export function useResourceFind(name, id, options) {
15
+ const client = useVerikitClient();
16
+ return useQuery({
17
+ queryKey: resourceQueryKeys(name).find(id),
18
+ queryFn: ({ signal }) => client.resource(name).find(id, { signal }),
19
+ ...options,
20
+ });
21
+ }
22
+ /**
23
+ * Lists selectable records for a `belongsTo` relationship, cached by
24
+ * resource, relationship, and params. Server-side permissions and scopes apply.
25
+ */
26
+ export function useResourceRelationship(name, relationshipName, params = {}, options) {
27
+ const client = useVerikitClient();
28
+ return useQuery({
29
+ queryKey: resourceQueryKeys(name).relationship(relationshipName, params),
30
+ queryFn: ({ signal }) => client
31
+ .resource(name)
32
+ .relationship(relationshipName, params, { signal }),
33
+ ...options,
34
+ });
35
+ }
@@ -0,0 +1,35 @@
1
+ import type { SchemaActionRegistry } from "../layout/types.js";
2
+ import { type UseVerikitSchemaTreeFormResult, type VerikitSchemaTreeSource } from "../form/use-verikit-schema-tree-form.js";
3
+ import { type VerikitFormValues } from "@verikit/ui-core/form/submission";
4
+ /** Options for creating a schema-tree resource form that submits over `@verikit/client`. */
5
+ export interface UseResourceSchemaTreeFormOptions<TRecord> {
6
+ /** Updates the record with this id instead of creating a new one. */
7
+ id?: string;
8
+ /** Runtime actions whose forms should render for matching action nodes. */
9
+ actions?: SchemaActionRegistry;
10
+ /** Initial values passed to TanStack Form. */
11
+ defaultValues?: VerikitFormValues;
12
+ /** Called with the created or updated record after a successful submit. */
13
+ onSuccess?: (record: TRecord) => void;
14
+ /**
15
+ * Called when the create/update mutation fails, excluding client-side
16
+ * validation errors surfaced through `fieldErrors` or `submitError`.
17
+ */
18
+ onError?: (error: Error) => void;
19
+ }
20
+ /** State and helpers returned by {@link useResourceSchemaTreeForm}. */
21
+ export interface UseResourceSchemaTreeFormResult<TRecord = Record<string, unknown>> extends UseVerikitSchemaTreeFormResult<TRecord> {
22
+ /** Whether the create/update mutation is currently in flight. */
23
+ isSubmitting: boolean;
24
+ /** Error from the most recent create/update mutation, if any. */
25
+ submitError: Error | null;
26
+ }
27
+ /**
28
+ * Schema-tree sibling of `useResourceForm`: same resource-backed
29
+ * create/update wiring, but built on `useVerikitSchemaTreeForm` so the
30
+ * rendered tree and therefore relationships and conditional fields is
31
+ * available to a tree-aware renderer like `ResourceForm`, instead of the
32
+ * flat field list `useResourceForm` exposes.
33
+ */
34
+ export declare function useResourceSchemaTreeForm<TRecord = Record<string, unknown>>(resource: VerikitSchemaTreeSource, { id, actions, defaultValues, onSuccess, onError, }?: UseResourceSchemaTreeFormOptions<TRecord>): UseResourceSchemaTreeFormResult<TRecord>;
35
+ //# sourceMappingURL=use-resource-schema-tree-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resource-schema-tree-form.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-schema-tree-form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG/D,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,uBAAuB,EAC7B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,kCAAkC,CAAC;AAM1C,4FAA4F;AAC5F,MAAM,WAAW,gCAAgC,CAAC,OAAO;IACvD,qEAAqE;IACrE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,8CAA8C;IAC9C,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,uEAAuE;AACvE,MAAM,WAAW,+BAA+B,CAC9C,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjC,SAAQ,8BAA8B,CAAC,OAAO,CAAC;IAC/C,iEAAiE;IACjE,YAAY,EAAE,OAAO,CAAC;IACtB,iEAAiE;IACjE,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,QAAQ,EAAE,uBAAuB,EACjC,EACE,EAAE,EACF,OAAO,EACP,aAAa,EACb,SAAS,EACT,OAAO,GACR,GAAE,gCAAgC,CAAC,OAAO,CAAM,GAChD,+BAA+B,CAAC,OAAO,CAAC,CAiC1C"}
@@ -0,0 +1,43 @@
1
+ import { VerikitClientError } from "@verikit/client";
2
+ import { useEffect, useRef } from "react";
3
+ import { useVerikitSchemaTreeForm, } from "../form/use-verikit-schema-tree-form.js";
4
+ import { validationIssuesToFieldErrors, } from "@verikit/ui-core/form/submission";
5
+ import { useCreateResource, useUpdateResource, } from "./use-resource-mutations.js";
6
+ /**
7
+ * Schema-tree sibling of `useResourceForm`: same resource-backed
8
+ * create/update wiring, but built on `useVerikitSchemaTreeForm` so the
9
+ * rendered tree and therefore relationships and conditional fields is
10
+ * available to a tree-aware renderer like `ResourceForm`, instead of the
11
+ * flat field list `useResourceForm` exposes.
12
+ */
13
+ export function useResourceSchemaTreeForm(resource, { id, actions, defaultValues, onSuccess, onError, } = {}) {
14
+ const create = useCreateResource(resource.name, { onError });
15
+ const update = useUpdateResource(resource.name, { onError });
16
+ const form = useVerikitSchemaTreeForm({
17
+ resource,
18
+ actions,
19
+ defaultValues,
20
+ onSubmit: async (values) => {
21
+ const record = id
22
+ ? await update.mutateAsync({ id, input: values })
23
+ : await create.mutateAsync(values);
24
+ onSuccess?.(record);
25
+ return record;
26
+ },
27
+ });
28
+ const handledMutationError = useRef(null);
29
+ const mutationError = id ? update.error : create.error;
30
+ useEffect(() => {
31
+ if (mutationError === handledMutationError.current)
32
+ return;
33
+ handledMutationError.current = mutationError;
34
+ if (mutationError instanceof VerikitClientError && mutationError.issues) {
35
+ form.setFieldErrors(validationIssuesToFieldErrors(mutationError.issues));
36
+ }
37
+ }, [mutationError, form.setFieldErrors]);
38
+ return {
39
+ ...form,
40
+ isSubmitting: create.isPending || update.isPending,
41
+ submitError: create.error ?? update.error,
42
+ };
43
+ }