@stonecrop/stonecrop 0.16.6 → 0.17.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.
Files changed (44) hide show
  1. package/README.md +16 -8
  2. package/dist/src/client-action.d.ts +31 -0
  3. package/dist/src/client-action.d.ts.map +1 -0
  4. package/dist/src/client-action.js +169 -0
  5. package/dist/src/composables/stonecrop.d.ts +9 -6
  6. package/dist/src/composables/stonecrop.d.ts.map +1 -1
  7. package/dist/src/composables/stonecrop.js +19 -90
  8. package/dist/src/doctype.d.ts +15 -12
  9. package/dist/src/doctype.d.ts.map +1 -1
  10. package/dist/src/doctype.js +19 -20
  11. package/dist/src/draft.d.ts +35 -0
  12. package/dist/src/draft.d.ts.map +1 -0
  13. package/dist/src/draft.js +36 -0
  14. package/dist/src/index.d.ts +4 -2
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +10 -4
  17. package/dist/src/registry.d.ts.map +1 -1
  18. package/dist/src/registry.js +6 -8
  19. package/dist/src/stonecrop.d.ts +67 -27
  20. package/dist/src/stonecrop.d.ts.map +1 -1
  21. package/dist/src/stonecrop.js +98 -84
  22. package/dist/src/stores/operation-log.d.ts +1 -1
  23. package/dist/src/types/client-action.d.ts +121 -0
  24. package/dist/src/types/client-action.d.ts.map +1 -0
  25. package/dist/src/types/client-action.js +0 -0
  26. package/dist/src/types/doctype.d.ts +1 -4
  27. package/dist/src/types/doctype.d.ts.map +1 -1
  28. package/dist/src/types/index.d.ts +1 -0
  29. package/dist/src/types/index.d.ts.map +1 -1
  30. package/dist/src/types/index.js +1 -0
  31. package/dist/stonecrop.d.ts +274 -49
  32. package/dist/stonecrop.js +662 -617
  33. package/dist/stonecrop.js.map +1 -1
  34. package/package.json +4 -4
  35. package/src/client-action.ts +207 -0
  36. package/src/composables/stonecrop.ts +28 -102
  37. package/src/doctype.ts +18 -20
  38. package/src/draft.ts +38 -0
  39. package/src/index.ts +8 -2
  40. package/src/registry.ts +6 -8
  41. package/src/stonecrop.ts +107 -93
  42. package/src/types/client-action.ts +121 -0
  43. package/src/types/doctype.ts +1 -4
  44. package/src/types/index.ts +1 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Payload emitted with the 'action' event when the user triggers a declared action —
3
+ * an FSM transition or a stateless Command.
4
+ *
5
+ * Defined here rather than in `@stonecrop/desktop` because the shell that *emits* it and the
6
+ * runner that *consumes* it now live in different packages, and desktop already depends on this
7
+ * one. `@stonecrop/desktop` re-exports it, so a host importing it from there is unaffected.
8
+ *
9
+ * @public
10
+ */
11
+ export type ActionEventPayload = {
12
+ /** The declared action name (e.g. 'SAVE', 'SUBMIT', 'APPROVE') */
13
+ name: string;
14
+ doctype: string;
15
+ recordId: string;
16
+ /** Snapshot of the form data at the time the action was triggered */
17
+ data: Record<string, any>;
18
+ };
19
+ /**
20
+ * Result of dispatching an action to its server handler.
21
+ * @public
22
+ */
23
+ export type ActionDispatchResult = {
24
+ success: boolean;
25
+ data: unknown;
26
+ error: string | null;
27
+ };
28
+ /**
29
+ * An action that did not complete, described well enough for a host to render it.
30
+ *
31
+ * An object rather than a bare message on purpose: a notification says *what* failed, and the
32
+ * action, doctype and record are all known at the point of failure. It is also the shape that can
33
+ * gain a field later without breaking a host that already destructures it.
34
+ *
35
+ * @public
36
+ */
37
+ export interface ActionFailure {
38
+ /** Human-readable reason — the server's own message where there is one. */
39
+ message: string;
40
+ /** The action that was clicked, not necessarily the one a `clientHandler` dispatched. */
41
+ action: string;
42
+ /** Slug of the doctype the action was raised on. */
43
+ doctype: string;
44
+ /** Record the action was raised against; the `new` route segment for an unsaved record. */
45
+ recordId: string;
46
+ /** The thrown value, present only when the failure was a throw rather than a refused dispatch. */
47
+ cause?: unknown;
48
+ }
49
+ /**
50
+ * Everything known about a dispatch at the point the argument array is built.
51
+ * @public
52
+ */
53
+ export interface ActionArgsContext {
54
+ /** Slug of the doctype the action was raised on. */
55
+ doctype: string;
56
+ /** The action being dispatched. */
57
+ action: string;
58
+ /** The route's record segment — {@link DRAFT_RECORD_ID} for an unsaved record. */
59
+ recordId: string;
60
+ /** Whether `recordId` is the draft segment rather than a real identity. */
61
+ isDraft: boolean;
62
+ /** The form snapshot being sent. */
63
+ data: Record<string, unknown>;
64
+ /** Extra fields a `clientHandler` passed to `runAction`. */
65
+ extra?: Record<string, unknown>;
66
+ }
67
+ /**
68
+ * Where a record ended up after the server settled its identity.
69
+ * @public
70
+ */
71
+ export interface FollowRecordContext {
72
+ /** Slug of the doctype the action was raised on. */
73
+ doctype: string;
74
+ /** The identity the server settled on — where the record now lives. */
75
+ recordId: string;
76
+ /** The identity that was dispatched, which is no longer valid. */
77
+ previousRecordId: string;
78
+ }
79
+ /**
80
+ * Host overrides for `useClientAction`.
81
+ *
82
+ * These are the three things that legitimately differ between applications: how your backend wants
83
+ * an action's arguments shaped, where the user should end up after a create, and how a failure is
84
+ * shown. Everything else is framework behaviour and is deliberately not configurable — in
85
+ * particular, resolving a record's identity and keying it into HST stay sealed, because that is
86
+ * the rule the adapter re-derives server-side, and every host that re-derived it got it wrong.
87
+ *
88
+ * @public
89
+ */
90
+ export interface UseClientActionOptions {
91
+ /**
92
+ * Called instead of the built-in alert when an action fails. Supply this to route failures into
93
+ * the host's own notification system, or pass a no-op to suppress them entirely.
94
+ *
95
+ * It fully replaces the default, console log included — a host that wants one writes it.
96
+ */
97
+ onError?: (failure: ActionFailure) => void;
98
+ /**
99
+ * Build the opaque argument array handed to `DataClient.runAction`.
100
+ *
101
+ * The default is `[{ id, data }]`, omitting `id` entirely for a draft — the envelope every
102
+ * in-repo server handler destructures. Supply this when your backend expects another shape;
103
+ * `examples/desktop` uses positional `[recordId, data]`, for instance. Nothing validates the
104
+ * array, so both ends of your own stack have to agree on it.
105
+ *
106
+ * Whatever you return is sent verbatim. It does not affect how the *result* is stored — that
107
+ * is keyed off the returned record's declared identity, not off what was sent.
108
+ */
109
+ buildArgs?: (context: ActionArgsContext) => unknown[];
110
+ /**
111
+ * Move the user to where a record ended up when the server settled on a different identity —
112
+ * the create case, and any action that rewrites a natural key.
113
+ *
114
+ * The default is `router.replace('/{doctype}/{recordId}')`. `replace`, not `push`: the route
115
+ * being left behind was never a record, so going Back to `/{doctype}/new` would show an empty
116
+ * form that creates yet another record. Supply this for a locale prefix, a nested path, or to
117
+ * stay put; the store has already been updated either way.
118
+ */
119
+ followRecord?: (context: FollowRecordContext) => void | Promise<void>;
120
+ }
121
+ //# sourceMappingURL=client-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-action.d.ts","sourceRoot":"","sources":["../../../src/types/client-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACzB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAE5F;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC7B,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAA;IACf,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAA;IACd,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,2FAA2F;IAC3F,QAAQ,EAAE,MAAM,CAAA;IAChB,kGAAkG;IAClG,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,kFAAkF;IAClF,QAAQ,EAAE,MAAM,CAAA;IAChB,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAA;IAChB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAA;IAChB,kEAAkE;IAClE,gBAAgB,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAA;IAC1C;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,EAAE,CAAA;IACrD;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrE"}
File without changes
@@ -1,5 +1,5 @@
1
1
  import type { DoctypeField, LinkDeclaration, WorkflowMeta } from '@stonecrop/schema';
2
- import { List, Map } from 'immutable';
2
+ import { List } from 'immutable';
3
3
  import type { AnyStateNodeConfig, UnknownMachineConfig } from 'xstate';
4
4
  /**
5
5
  * Immutable Doctype type for Stonecrop instances. App authors should use
@@ -9,7 +9,6 @@ import type { AnyStateNodeConfig, UnknownMachineConfig } from 'xstate';
9
9
  export type ImmutableDoctype = {
10
10
  readonly schema?: List<DoctypeField>;
11
11
  readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
12
- readonly actions?: Map<string, string[]>;
13
12
  };
14
13
  /**
15
14
  * Plain object representation of doctype configuration for serialization/API responses.
@@ -27,8 +26,6 @@ export type DoctypeConfig = {
27
26
  links?: Record<string, LinkDeclaration>;
28
27
  /** Workflow configuration (XState format or simple WorkflowMeta) */
29
28
  workflow?: UnknownMachineConfig | WorkflowMeta;
30
- /** Actions and their field triggers */
31
- actions?: Record<string, string[]>;
32
29
  /** Ancestor doctype for inheritance */
33
30
  inherits?: string;
34
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/types/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,YAAY,CAAA;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CACxC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iEAAiE;IACjE,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACvC,oEAAoE;IACpE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,YAAY,CAAA;IAC9C,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAClC,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
1
+ {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/types/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,YAAY,CAAA;CAC5E,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iEAAiE;IACjE,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACvC,oEAAoE;IACpE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,YAAY,CAAA;IAC9C,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
@@ -1,3 +1,4 @@
1
+ export * from './client-action';
1
2
  export * from './composable';
2
3
  export * from './doctype';
3
4
  export * from './field-triggers';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,OAAO,CAAA;AACrB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,OAAO,CAAA;AACrB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA"}
@@ -1,4 +1,5 @@
1
1
  // Re-export all type files
2
+ export * from './client-action';
2
3
  export * from './composable';
3
4
  export * from './doctype';
4
5
  export * from './field-triggers';
@@ -3,9 +3,12 @@ import { Component } from 'vue';
3
3
  import { ComputedRef } from 'vue';
4
4
  import type { DataClient } from '@stonecrop/schema';
5
5
  import type { DoctypeField } from '@stonecrop/schema';
6
+ import type { GetRecordOptions } from '@stonecrop/schema';
7
+ import type { GetRecordsOptions } from '@stonecrop/schema';
8
+ import type { GetRecordsResult } from '@stonecrop/schema';
6
9
  import type { LinkDeclaration } from '@stonecrop/schema';
7
10
  import { List } from 'immutable';
8
- import { Map as Map_2 } from 'immutable';
11
+ import type { Map as Map_2 } from 'immutable';
9
12
  import { Plugin as Plugin_2 } from 'vue';
10
13
  import { Ref } from 'vue';
11
14
  import type { ResolvedField } from '@stonecrop/aform';
@@ -16,6 +19,54 @@ import type { TriggerDefinition } from '@stonecrop/schema';
16
19
  import type { UnknownMachineConfig } from 'xstate';
17
20
  import type { WorkflowMeta } from '@stonecrop/schema';
18
21
 
22
+ /**
23
+ * Everything known about a dispatch at the point the argument array is built.
24
+ * @public
25
+ */
26
+ export declare interface ActionArgsContext {
27
+ /** Slug of the doctype the action was raised on. */
28
+ doctype: string;
29
+ /** The action being dispatched. */
30
+ action: string;
31
+ /** The route's record segment — {@link DRAFT_RECORD_ID} for an unsaved record. */
32
+ recordId: string;
33
+ /** Whether `recordId` is the draft segment rather than a real identity. */
34
+ isDraft: boolean;
35
+ /** The form snapshot being sent. */
36
+ data: Record<string, unknown>;
37
+ /** Extra fields a `clientHandler` passed to `runAction`. */
38
+ extra?: Record<string, unknown>;
39
+ }
40
+
41
+ /**
42
+ * Result of dispatching an action to its server handler.
43
+ * @public
44
+ */
45
+ export declare type ActionDispatchResult = {
46
+ success: boolean;
47
+ data: unknown;
48
+ error: string | null;
49
+ };
50
+
51
+ /**
52
+ * Payload emitted with the 'action' event when the user triggers a declared action —
53
+ * an FSM transition or a stateless Command.
54
+ *
55
+ * Defined here rather than in `@stonecrop/desktop` because the shell that *emits* it and the
56
+ * runner that *consumes* it now live in different packages, and desktop already depends on this
57
+ * one. `@stonecrop/desktop` re-exports it, so a host importing it from there is unaffected.
58
+ *
59
+ * @public
60
+ */
61
+ export declare type ActionEventPayload = {
62
+ /** The declared action name (e.g. 'SAVE', 'SUBMIT', 'APPROVE') */
63
+ name: string;
64
+ doctype: string;
65
+ recordId: string;
66
+ /** Snapshot of the form data at the time the action was triggered */
67
+ data: Record<string, any>;
68
+ };
69
+
19
70
  /**
20
71
  * Result of executing a field action
21
72
  * @public
@@ -31,6 +82,28 @@ export declare interface ActionExecutionResult {
31
82
  action: FieldAction;
32
83
  }
33
84
 
85
+ /**
86
+ * An action that did not complete, described well enough for a host to render it.
87
+ *
88
+ * An object rather than a bare message on purpose: a notification says *what* failed, and the
89
+ * action, doctype and record are all known at the point of failure. It is also the shape that can
90
+ * gain a field later without breaking a host that already destructures it.
91
+ *
92
+ * @public
93
+ */
94
+ export declare interface ActionFailure {
95
+ /** Human-readable reason — the server's own message where there is one. */
96
+ message: string;
97
+ /** The action that was clicked, not necessarily the one a `clientHandler` dispatched. */
98
+ action: string;
99
+ /** Slug of the doctype the action was raised on. */
100
+ doctype: string;
101
+ /** Record the action was raised against; the `new` route segment for an unsaved record. */
102
+ recordId: string;
103
+ /** The thrown value, present only when the failure was a throw rather than a refused dispatch. */
104
+ cause?: unknown;
105
+ }
106
+
34
107
  /**
35
108
  * Registry for storing global action functions
36
109
  * @public
@@ -165,12 +238,6 @@ export declare class Doctype {
165
238
  * @readonly
166
239
  */
167
240
  readonly workflow: ImmutableDoctype['workflow'];
168
- /**
169
- * The doctype actions and field triggers
170
- * @public
171
- * @readonly
172
- */
173
- readonly actions: ImmutableDoctype['actions'];
174
241
  /**
175
242
  * The doctype component
176
243
  * @public
@@ -188,11 +255,10 @@ export declare class Doctype {
188
255
  * @param doctype - The doctype name
189
256
  * @param schema - The doctype schema definition
190
257
  * @param workflow - The doctype workflow configuration (XState machine)
191
- * @param actions - The doctype actions and field triggers
192
258
  * @param component - Optional Vue component for rendering the doctype
193
259
  * @param links - Optional relationship links to other doctypes
194
260
  */
195
- constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], actions: ImmutableDoctype['actions'], component?: Component, links?: Record<string, LinkDeclaration>);
261
+ constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], component?: Component, links?: Record<string, LinkDeclaration>);
196
262
  /**
197
263
  * Creates a Doctype instance from a plain configuration object.
198
264
  * Handles conversion of arrays to Immutable.js collections internally.
@@ -262,14 +328,24 @@ export declare class Doctype {
262
328
  */
263
329
  getRecordId(record: Record<string, unknown>): string | undefined;
264
330
  /**
265
- * Returns the actions as a plain object for use with components that expect
266
- * plain JavaScript objects.
331
+ * The field a record of this doctype is identified by: the declared `primaryKey`, or `id`
332
+ * when nothing is declared.
333
+ *
334
+ * The client-side twin of the adapters' `recordLookupField`. Both are the same call to
335
+ * `@stonecrop/schema`'s `getRecordIdField`, so the field a caller reads an identity out of is
336
+ * the same field the adapter builds its lookup predicate on.
267
337
  *
268
- * @returns Object mapping action names to field trigger arrays
338
+ * Use this to ask whether a record *states* its own identity. `getRecordId` deliberately
339
+ * falls back to `id` when the declared key is missing, which is right for resolving a link
340
+ * from a record already in hand and wrong for deciding whether a server response settled on
341
+ * a new identity: a response that omits a natural key would resolve through that fallback to
342
+ * a surrogate the adapter cannot look up.
343
+ *
344
+ * @returns The identifying fieldname
269
345
  *
270
346
  * @public
271
347
  */
272
- getActionsObject(): Record<string, string[]>;
348
+ get recordIdField(): string;
273
349
  /**
274
350
  * Returns the transitions available from a given workflow state, derived from the
275
351
  * doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
@@ -382,12 +458,20 @@ export declare type DoctypeConfig = {
382
458
  links?: Record<string, LinkDeclaration>;
383
459
  /** Workflow configuration (XState format or simple WorkflowMeta) */
384
460
  workflow?: UnknownMachineConfig | WorkflowMeta;
385
- /** Actions and their field triggers */
386
- actions?: Record<string, string[]>;
387
461
  /** Ancestor doctype for inheritance */
388
462
  inherits?: string;
389
463
  };
390
464
 
465
+ /**
466
+ * The record-id segment a draft route carries: `/{doctype}/new`.
467
+ *
468
+ * Route only — never a store key, and never sent: an action dispatched for a draft omits the id
469
+ * rather than sending this.
470
+ *
471
+ * @public
472
+ */
473
+ export declare const DRAFT_RECORD_ID = "new";
474
+
391
475
  /**
392
476
  * Execute a docbuilder-authored `clientHandler` body against an injected API map.
393
477
  *
@@ -655,23 +739,24 @@ export declare interface FieldTriggerOptions {
655
739
  }
656
740
 
657
741
  /**
658
- * Get or create the global field trigger engine singleton
659
- * @param options - Optional configuration for the field trigger engine
742
+ * Where a record ended up after the server settled its identity.
660
743
  * @public
661
744
  */
662
- export declare function getGlobalTriggerEngine(options?: FieldTriggerOptions): FieldTriggerEngine;
745
+ export declare interface FollowRecordContext {
746
+ /** Slug of the doctype the action was raised on. */
747
+ doctype: string;
748
+ /** The identity the server settled on — where the record now lives. */
749
+ recordId: string;
750
+ /** The identity that was dispatched, which is no longer valid. */
751
+ previousRecordId: string;
752
+ }
663
753
 
664
754
  /**
665
- * Returns the global Stonecrop singleton instance, or `undefined` if no
666
- * instance has been created yet.
667
- *
668
- * Use this when you need the Stonecrop instance outside a Vue component
669
- * context (e.g., in workflow action handlers, plugin setup code, or
670
- * non-component utilities). Inside a component, prefer `useStonecrop()`.
671
- *
755
+ * Get or create the global field trigger engine singleton
756
+ * @param options - Optional configuration for the field trigger engine
672
757
  * @public
673
758
  */
674
- export declare function getStonecrop(): Stonecrop | undefined;
759
+ export declare function getGlobalTriggerEngine(options?: FieldTriggerOptions): FieldTriggerEngine;
675
760
 
676
761
  /**
677
762
  * Global HST Manager (Singleton)
@@ -961,7 +1046,6 @@ export declare type HSTStonecropReturn = BaseStonecropReturn & {
961
1046
  export declare type ImmutableDoctype = {
962
1047
  readonly schema?: List<DoctypeField>;
963
1048
  readonly workflow?: UnknownMachineConfig | AnyStateNodeConfig | WorkflowMeta;
964
- readonly actions?: Map_2<string, string[]>;
965
1049
  };
966
1050
 
967
1051
  /**
@@ -994,6 +1078,20 @@ export declare type InstallOptions = {
994
1078
  onRouterInitialized?: (registry: Registry, stonecrop: Stonecrop) => void | Promise<void>;
995
1079
  };
996
1080
 
1081
+ /**
1082
+ * Whether a record id refers to a record that has not been saved yet.
1083
+ *
1084
+ * Guard anything that assumes the record exists — fetching it, resolving its links, judging
1085
+ * workflow readiness — with this rather than the literal. The shell and this package once spelled
1086
+ * the rule differently, which left every guard here dead.
1087
+ *
1088
+ * @param recordId - The record id to test
1089
+ * @returns `true` when the id is the draft segment, `false` for a real identity or no id at all
1090
+ *
1091
+ * @public
1092
+ */
1093
+ export declare function isDraftRecordId(recordId: string | null | undefined): boolean;
1094
+
997
1095
  /**
998
1096
  * Lazy link state for a single link field.
999
1097
  * Provides reactive state and reload capability for lazy-loaded links.
@@ -1483,6 +1581,11 @@ export declare class Stonecrop {
1483
1581
  private _operationLogStore?;
1484
1582
  private _operationLogConfig?;
1485
1583
  private _client?;
1584
+ /**
1585
+ * Per-doctype page info from the last list read, keyed by slug. Reactive so views tracking
1586
+ * it update on fetch. Deliberately not in HST — see {@link Stonecrop.getRecords}.
1587
+ */
1588
+ private pageInfo;
1486
1589
  /** The registry instance containing all doctype definitions */
1487
1590
  readonly registry: Registry;
1488
1591
  /**
@@ -1599,7 +1702,7 @@ export declare class Stonecrop {
1599
1702
  getSnapshot: () => OperationLogSnapshot;
1600
1703
  markIrreversible: (operationId: string, reason: string) => void;
1601
1704
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
1602
- }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
1705
+ }, "config" | "operations" | "clientId" | "currentIndex">, Pick<{
1603
1706
  operations: Ref< {
1604
1707
  id: string;
1605
1708
  type: HSTOperationType;
@@ -1818,14 +1921,6 @@ export declare class Stonecrop {
1818
1921
  * @param doctype - The doctype to setup
1819
1922
  */
1820
1923
  setup(doctype: Doctype): void;
1821
- /**
1822
- * Run action on doctype
1823
- * Executes the action and logs it to the operation log for audit tracking
1824
- * @param doctype - The doctype
1825
- * @param action - The action to run
1826
- * @param args - Action arguments (typically record IDs)
1827
- */
1828
- runAction(doctype: Doctype, action: string, args?: string[]): void;
1829
1924
  /**
1830
1925
  * Get the effective blockWorkflows value for a link.
1831
1926
  * Returns true if blockWorkflows is explicitly true, or if it's absent and fetch method is 'sync'.
@@ -1845,22 +1940,76 @@ export declare class Stonecrop {
1845
1940
  blockedLinks?: string[];
1846
1941
  };
1847
1942
  /**
1848
- * Get records from server using the configured data client.
1943
+ * Fetch a doctype's records from the server and store them in HST.
1944
+ *
1945
+ * This is the one read path for a list. Every caller shares its keying rule, so a row is
1946
+ * always stored under the identity its Edit link will later ask for.
1947
+ *
1948
+ * Deliberately unguarded, unlike {@link Stonecrop.getRecord}: a list is a view of data that
1949
+ * changes, so revisiting one must re-read it rather than serve whatever HST happens to hold.
1950
+ *
1951
+ * `options` is forwarded to the client untouched — no row limit is invented here, because
1952
+ * nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
1953
+ * passes none gets whatever the server considers a reasonable page.
1954
+ *
1849
1955
  * @param doctype - The doctype
1956
+ * @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
1850
1957
  * @throws Error if no data client has been configured
1958
+ * @public
1959
+ */
1960
+ getRecords(doctype: Doctype, options?: GetRecordsOptions): Promise<GetRecordsResult>;
1961
+ /**
1962
+ * What the last {@link Stonecrop.getRecords} for this doctype returned about the wider set.
1963
+ *
1964
+ * Answers the question HST cannot: HST holds what was fetched, so counting its keys reports
1965
+ * how much has been seen, never how much exists. Reactive, so a view reading it re-renders
1966
+ * when a fetch lands.
1967
+ *
1968
+ * @param doctype - The doctype slug string or Doctype object
1969
+ * @returns Page info, or undefined if this doctype's records have not been fetched
1970
+ * @public
1851
1971
  */
1852
- getRecords(doctype: Doctype): Promise<void>;
1972
+ getPageInfo(doctype: string | Doctype): {
1973
+ hasMore: boolean;
1974
+ count?: number;
1975
+ } | undefined;
1853
1976
  /**
1854
- * Get single record from server using the configured data client.
1977
+ * Fetch a single record from the server and store it in HST.
1978
+ *
1979
+ * This is the one read path for a record, and it owns the whole job: deciding whether a fetch
1980
+ * is warranted, performing it, and writing the result back under the doctype's declared
1981
+ * identity. Callers ask for a record and get one; they do not re-derive when to ask.
1982
+ *
1983
+ * Two cases return without touching the network, because in both the answer is already known:
1984
+ * a draft does not exist on the server yet, and a record already in HST has been read.
1985
+ * Refetching the latter would also discard unsaved edits sitting in the store.
1986
+ *
1855
1987
  * @param doctype - The doctype slug string or Doctype object
1856
1988
  * @param recordId - The record ID
1989
+ * @param options - Query options (includeNested, maxDepth), forwarded to the client
1857
1990
  * @throws Error if no data client has been configured
1858
1991
  * @throws Error if a slug string is given and no matching doctype is found in the registry
1992
+ * @public
1859
1993
  */
1860
- getRecord(doctype: string | Doctype, recordId: string): Promise<void>;
1994
+ getRecord(doctype: string | Doctype, recordId: string, options?: GetRecordOptions): Promise<void>;
1861
1995
  /**
1862
- * Dispatch an action to the server via the configured data client.
1863
- * All state changes flow through this single mutation endpoint.
1996
+ * Dispatch an action to the server via the configured data client, and file the record it
1997
+ * returns into HST under the identity the *server* settled on.
1998
+ *
1999
+ * The write is the point. For a created record the settled identity is never the one that was
2000
+ * dispatched, so a caller that stores the result under the id it sent files the record under a
2001
+ * key nothing can fetch and leaves the next save creating a second one. Every host that
2002
+ * hand-rolled this got it wrong the same way, so it stops being the caller's job — this is the
2003
+ * write-side twin of {@link Stonecrop.getRecords}, which keys reads by the same rule.
2004
+ *
2005
+ * Two things are deliberately NOT done here, because both need the id that was dispatched and
2006
+ * that lives inside `args` — an opaque array whose shape is a convention between a host's
2007
+ * client and its server handlers, not something this layer may parse. Dropping the stale key
2008
+ * and moving the route therefore stay with `useClientAction`, which knows both ids.
2009
+ *
2010
+ * A result that states no identity of its own — a `{ state: 'APPROVED' }` outcome — is left
2011
+ * alone rather than guessed at, for the same reason `settledRecordId` is strict: a partial
2012
+ * record must not be able to look like a rename.
1864
2013
  *
1865
2014
  * @param doctype - The doctype
1866
2015
  * @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
@@ -2044,6 +2193,79 @@ export declare interface UndoRedoState {
2044
2193
  currentIndex: number;
2045
2194
  }
2046
2195
 
2196
+ /**
2197
+ * Shared executor for doctype action clicks. A host's Desktop `@action` handler delegates
2198
+ * here so every host runs the same logic from one definition:
2199
+ *
2200
+ * - If the clicked action carries a `clientHandler`, run it. The handler **owns
2201
+ * orchestration** — it calls `runAction` itself when it needs the server, navigates via
2202
+ * `router`, reads `record`, or queries `graphql`. It supersedes the default dispatch.
2203
+ * - Otherwise dispatch the action to its server `handler` (the pre-existing behavior),
2204
+ * so actions without a `clientHandler` are unchanged.
2205
+ *
2206
+ * `runAction` is the only blessed write: it dispatches **and** leaves the store consistent,
2207
+ * filing the returned record under the identity the *server* settled on and following the route
2208
+ * there when that differs from the one dispatched. For a created record those are never the same,
2209
+ * which is what makes hand-rolling this reliably wrong.
2210
+ *
2211
+ * The store write itself lives one layer down, in {@link Stonecrop.dispatchAction}, so a host that
2212
+ * never adopts this composable still cannot file a record under the wrong key. What stays here is
2213
+ * only what needs the *dispatched* id: dropping the stale key, and moving the route.
2214
+ *
2215
+ * Pass `buildArgs` to change the argument envelope your backend receives, `followRecord` to change
2216
+ * where a created record sends the user, and `onError` to route failures into your own
2217
+ * notification system. Identity resolution and HST keying are deliberately not configurable — see
2218
+ * {@link UseClientActionOptions}.
2219
+ *
2220
+ * @public
2221
+ */
2222
+ export declare function useClientAction(options?: UseClientActionOptions): {
2223
+ run: (payload: ActionEventPayload) => Promise<void>;
2224
+ };
2225
+
2226
+ /**
2227
+ * Host overrides for `useClientAction`.
2228
+ *
2229
+ * These are the three things that legitimately differ between applications: how your backend wants
2230
+ * an action's arguments shaped, where the user should end up after a create, and how a failure is
2231
+ * shown. Everything else is framework behaviour and is deliberately not configurable — in
2232
+ * particular, resolving a record's identity and keying it into HST stay sealed, because that is
2233
+ * the rule the adapter re-derives server-side, and every host that re-derived it got it wrong.
2234
+ *
2235
+ * @public
2236
+ */
2237
+ export declare interface UseClientActionOptions {
2238
+ /**
2239
+ * Called instead of the built-in alert when an action fails. Supply this to route failures into
2240
+ * the host's own notification system, or pass a no-op to suppress them entirely.
2241
+ *
2242
+ * It fully replaces the default, console log included — a host that wants one writes it.
2243
+ */
2244
+ onError?: (failure: ActionFailure) => void;
2245
+ /**
2246
+ * Build the opaque argument array handed to `DataClient.runAction`.
2247
+ *
2248
+ * The default is `[{ id, data }]`, omitting `id` entirely for a draft — the envelope every
2249
+ * in-repo server handler destructures. Supply this when your backend expects another shape;
2250
+ * `examples/desktop` uses positional `[recordId, data]`, for instance. Nothing validates the
2251
+ * array, so both ends of your own stack have to agree on it.
2252
+ *
2253
+ * Whatever you return is sent verbatim. It does not affect how the *result* is stored — that
2254
+ * is keyed off the returned record's declared identity, not off what was sent.
2255
+ */
2256
+ buildArgs?: (context: ActionArgsContext) => unknown[];
2257
+ /**
2258
+ * Move the user to where a record ended up when the server settled on a different identity —
2259
+ * the create case, and any action that rewrites a natural key.
2260
+ *
2261
+ * The default is `router.replace('/{doctype}/{recordId}')`. `replace`, not `push`: the route
2262
+ * being left behind was never a record, so going Back to `/{doctype}/new` would show an empty
2263
+ * form that creates yet another record. Supply this for a locale prefix, a nested path, or to
2264
+ * stay put; the store has already been updated either way.
2265
+ */
2266
+ followRecord?: (context: FollowRecordContext) => void | Promise<void>;
2267
+ }
2268
+
2047
2269
  /**
2048
2270
  * Get the lazy link state for a specific link field on a doctype record.
2049
2271
  *
@@ -2251,7 +2473,7 @@ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
2251
2473
  getSnapshot: () => OperationLogSnapshot;
2252
2474
  markIrreversible: (operationId: string, reason: string) => void;
2253
2475
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
2254
- }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
2476
+ }, "config" | "operations" | "clientId" | "currentIndex">, Pick<{
2255
2477
  operations: Ref< {
2256
2478
  id: string;
2257
2479
  type: HSTOperationType;
@@ -2422,13 +2644,15 @@ logAction: (doctype: string, actionName: string, recordIds?: string[], result?:
2422
2644
  }, "clear" | "undo" | "redo" | "configure" | "addOperation" | "startBatch" | "commitBatch" | "cancelBatch" | "getOperationsFor" | "getSnapshot" | "markIrreversible" | "logAction">>;
2423
2645
 
2424
2646
  /**
2425
- * Unified Stonecrop composable - handles both general operations and HST reactive integration
2647
+ * Unified Stonecrop composable - handles both general operations and HST reactive integration.
2648
+ *
2649
+ * Called with no doctype, it returns the Stonecrop instance and the operation log, and touches
2650
+ * the network not at all. Name a doctype to get the HST surface.
2426
2651
  *
2427
- * @param options - Configuration options for the composable
2428
- * @returns Stonecrop instance and optional HST integration utilities
2652
+ * @returns The Stonecrop instance and the operation log
2429
2653
  * @public
2430
2654
  */
2431
- export declare function useStonecrop(): BaseStonecropReturn | HSTStonecropReturn;
2655
+ export declare function useStonecrop(): BaseStonecropReturn;
2432
2656
 
2433
2657
  /**
2434
2658
  * Unified Stonecrop composable with HST integration for a specific doctype and record.
@@ -2440,8 +2664,9 @@ export declare function useStonecrop(): BaseStonecropReturn | HSTStonecropReturn
2440
2664
  * immediately after calling this composable; no `nextTick`, `flushPromises`, or
2441
2665
  * `setTimeout` is required.
2442
2666
  *
2443
- * The only remaining async work in `onMounted` is fetching an existing record from the
2444
- * server when `recordId` is not `'new'`, and lazy-loading a doctype by slug string.
2667
+ * The only async work in `onMounted` is fetching an existing record from the server when
2668
+ * `recordId` is not a draft, and lazy-loading a doctype by slug string. Both need a doctype
2669
+ * named here — nothing is inferred from the route.
2445
2670
  *
2446
2671
  * @param options - Configuration with doctype (string slug or Doctype instance) and optional recordId
2447
2672
  * @returns Stonecrop instance with full HST integration utilities