rastack 0.0.49 → 0.0.51

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 (68) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/components/auto-form/AutoForm.tsx +13 -0
  3. package/components/auto-form/use-auto-form.ts +28 -0
  4. package/components/types.ts +8 -0
  5. package/dist/admin.js +13 -13
  6. package/dist/compile/analyze.d.ts +20 -0
  7. package/dist/compile/analyze.js +60 -49
  8. package/dist/compile/entities.d.ts +19 -0
  9. package/dist/compile/entities.js +87 -13
  10. package/dist/compile/index.d.ts +23 -4
  11. package/dist/compile/index.js +86 -7
  12. package/dist/compile/model.d.ts +38 -0
  13. package/dist/compile/openapi.d.ts +9 -0
  14. package/dist/compile/openapi.js +14 -0
  15. package/dist/define/index.d.ts +162 -21
  16. package/dist/define/index.js +28 -22
  17. package/dist/define/manifest.d.ts +64 -0
  18. package/dist/define/manifest.js +250 -0
  19. package/dist/import/tabular.d.ts +8 -2
  20. package/dist/import/tabular.js +1 -1
  21. package/dist/plugin/core.d.ts +108 -0
  22. package/dist/plugin/core.js +198 -0
  23. package/dist/plugin/index.d.ts +112 -0
  24. package/dist/plugin/index.js +203 -0
  25. package/dist/rastack-import.js +4 -1
  26. package/dist/validate/adapters.js +2 -0
  27. package/dist/validate/index.d.ts +1 -0
  28. package/dist/validate/index.js +1 -0
  29. package/dist/validate/machine.d.ts +23 -2
  30. package/dist/validate/machine.js +35 -2
  31. package/dist/validate/transitions.d.ts +86 -0
  32. package/dist/validate/transitions.js +199 -0
  33. package/dist/wasm/rastack_wasm.js +1 -1
  34. package/dist/wasm/rastack_wasm_bg.wasm +0 -0
  35. package/hooks/data.ts +221 -0
  36. package/hooks/entity.ts +228 -0
  37. package/hooks/form/entity-form.ts +358 -0
  38. package/hooks/form/form.ts +8 -1
  39. package/hooks/form/index.ts +7 -1
  40. package/hooks/index.ts +4 -0
  41. package/hooks/manifest.ts +77 -0
  42. package/hooks/registry.ts +56 -0
  43. package/package.json +1 -1
  44. package/plugin.ts +8 -0
  45. package/provider/provider.tsx +26 -5
  46. package/provider/types.ts +15 -3
  47. package/src/compile/analyze.ts +74 -45
  48. package/src/compile/entities.ts +111 -11
  49. package/src/compile/index.ts +108 -11
  50. package/src/compile/model.ts +40 -0
  51. package/src/compile/openapi.ts +13 -1
  52. package/src/define/index.ts +233 -29
  53. package/src/define/manifest.ts +278 -0
  54. package/src/import/tabular.ts +9 -2
  55. package/src/plugin/core.ts +236 -0
  56. package/src/plugin/index.ts +243 -0
  57. package/src/rastack-import.ts +4 -1
  58. package/src/validate/adapters.ts +1 -0
  59. package/src/validate/index.ts +1 -0
  60. package/src/validate/machine.ts +55 -3
  61. package/src/validate/transitions.ts +232 -0
  62. package/test/components.spec.ts +22 -0
  63. package/test/plugin.spec.ts +315 -0
  64. package/test/runtime-manifest.spec.ts +309 -0
  65. package/test/transitions.spec.ts +372 -0
  66. package/test/typed-hooks.spec.ts +412 -0
  67. package/wasm/rastack_wasm.js +1 -1
  68. package/wasm/rastack_wasm_bg.wasm +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.51](https://github.com/theserverkid/reactapistack/compare/v0.0.50...v0.0.51) (2026-07-16)
6
+
7
+ ### [0.0.50](https://github.com/theserverkid/reactapistack/compare/v0.0.49...v0.0.50) (2026-07-15)
8
+
5
9
  ### [0.0.49](https://github.com/theserverkid/reactapistack/compare/v0.0.48...v0.0.49) (2026-07-14)
6
10
 
7
11
  ### [0.0.48](https://github.com/theserverkid/reactapistack/compare/v0.0.47...v0.0.48) (2026-07-13)
@@ -229,6 +229,19 @@ export function AutoForm(props: AutoFormProps): React.JSX.Element {
229
229
  justifyContent: "flex-end",
230
230
  }}
231
231
  >
232
+ {/* State-machine actions: one button per transition available from
233
+ the record's current state (feature-detected off the form). */}
234
+ {model.transitions.map((t) => (
235
+ <Button
236
+ key={t.name}
237
+ type="button"
238
+ variant="outline"
239
+ disabled={model.isSubmitting}
240
+ onClick={() => t.fire()}
241
+ >
242
+ {t.label}
243
+ </Button>
244
+ ))}
232
245
  {onCancel ? (
233
246
  <Button
234
247
  type="button"
@@ -37,6 +37,15 @@ export interface AutoFormFieldModel {
37
37
  ) => React.ReactNode;
38
38
  }
39
39
 
40
+ /** One state-machine action the form can fire from the record's current state. */
41
+ export interface AutoFormTransitionModel {
42
+ name: string;
43
+ label: React.ReactNode;
44
+ /** The state the record enters when the action fires. */
45
+ to: string;
46
+ fire: () => void;
47
+ }
48
+
40
49
  export interface AutoFormModel {
41
50
  fields: AutoFormFieldModel[];
42
51
  submit: () => void;
@@ -45,6 +54,11 @@ export interface AutoFormModel {
45
54
  /** `true` when the form is valid and not mid-submit. */
46
55
  canSubmit: boolean;
47
56
  errors: Record<string, unknown>;
57
+ /**
58
+ * State-machine actions — feature-detected from `useForm(Entity)` results
59
+ * whose resource declares `transitions`. Empty on forms without one.
60
+ */
61
+ transitions: AutoFormTransitionModel[];
48
62
  }
49
63
 
50
64
  /** Pure model assembly — see {@link useAutoForm}. Testable with a mock form. */
@@ -70,6 +84,19 @@ export function buildAutoFormModel(
70
84
  };
71
85
  });
72
86
 
87
+ // Feature-detect the state machine: `useForm(Entity)` exposes the declared
88
+ // transitions available from the record's current state; anything else
89
+ // (legacy hooks, hand-rolled forms) simply renders no actions.
90
+ const transitions: AutoFormTransitionModel[] =
91
+ Array.isArray(form.transitions) && typeof form.transition === "function"
92
+ ? form.transitions.map((t) => ({
93
+ name: t.name,
94
+ label: t.label ?? humanizeKey(t.name),
95
+ to: t.to,
96
+ fire: () => form.transition!(t.name),
97
+ }))
98
+ : [];
99
+
73
100
  return {
74
101
  fields,
75
102
  submit: () => form.onSubmit(),
@@ -77,6 +104,7 @@ export function buildAutoFormModel(
77
104
  isSubmitting: form.isSubmitting,
78
105
  canSubmit: !form.isSubmitDisabled && !form.isSubmitting,
79
106
  errors: (form.errors as Record<string, unknown>) ?? {},
107
+ transitions,
80
108
  };
81
109
  }
82
110
 
@@ -95,4 +95,12 @@ export interface AutoFormLike {
95
95
  isSubmitting: boolean;
96
96
  /** Formik's error bag, keyed by field name. */
97
97
  errors?: Record<string, unknown> | unknown;
98
+ /**
99
+ * State-machine actions, feature-detected like everything else: when
100
+ * `useForm(Entity)` exposes the resource's declared transitions, the
101
+ * auto-form renders one action button per available edge.
102
+ */
103
+ transitions?: Array<{ name: string; label?: string; to: string }>;
104
+ /** Fire a declared transition (stage the edge's patch and save). */
105
+ transition?(name: string): void;
98
106
  }