@stonecrop/stonecrop 0.16.5 → 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,35 @@
1
+ /**
2
+ * The route identity of a record the user is composing that does not exist on the server yet.
3
+ *
4
+ * Rejected: minting `new-<timestamp>` so a draft had a store key too. Nothing ever created that
5
+ * HST node, so every write to `doctype.<draftId>.<field>` threw on the missing ancestor, and the
6
+ * form's data survived only because Vue cached the empty object the getter returned and the form
7
+ * mutated it in place — any invalidation discarded the edits silently. Seeding the node instead
8
+ * makes the draft a phantom row, because `getRecords` lists every key under the doctype.
9
+ *
10
+ * So a draft is held off-HST by whoever renders the form, and reaches the server as an action
11
+ * carrying no record id, which the write path already reads as "create".
12
+ */
13
+ /**
14
+ * The record-id segment a draft route carries: `/{doctype}/new`.
15
+ *
16
+ * Route only — never a store key, and never sent: an action dispatched for a draft omits the id
17
+ * rather than sending this.
18
+ *
19
+ * @public
20
+ */
21
+ export declare const DRAFT_RECORD_ID = "new";
22
+ /**
23
+ * Whether a record id refers to a record that has not been saved yet.
24
+ *
25
+ * Guard anything that assumes the record exists — fetching it, resolving its links, judging
26
+ * workflow readiness — with this rather than the literal. The shell and this package once spelled
27
+ * the rule differently, which left every guard here dead.
28
+ *
29
+ * @param recordId - The record id to test
30
+ * @returns `true` when the id is the draft segment, `false` for a real identity or no id at all
31
+ *
32
+ * @public
33
+ */
34
+ export declare function isDraftRecordId(recordId: string | null | undefined): boolean;
35
+ //# sourceMappingURL=draft.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAQ,CAAA;AAEpC;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The route identity of a record the user is composing that does not exist on the server yet.
3
+ *
4
+ * Rejected: minting `new-<timestamp>` so a draft had a store key too. Nothing ever created that
5
+ * HST node, so every write to `doctype.<draftId>.<field>` threw on the missing ancestor, and the
6
+ * form's data survived only because Vue cached the empty object the getter returned and the form
7
+ * mutated it in place — any invalidation discarded the edits silently. Seeding the node instead
8
+ * makes the draft a phantom row, because `getRecords` lists every key under the doctype.
9
+ *
10
+ * So a draft is held off-HST by whoever renders the form, and reaches the server as an action
11
+ * carrying no record id, which the write path already reads as "create".
12
+ */
13
+ /**
14
+ * The record-id segment a draft route carries: `/{doctype}/new`.
15
+ *
16
+ * Route only — never a store key, and never sent: an action dispatched for a draft omits the id
17
+ * rather than sending this.
18
+ *
19
+ * @public
20
+ */
21
+ export const DRAFT_RECORD_ID = 'new';
22
+ /**
23
+ * Whether a record id refers to a record that has not been saved yet.
24
+ *
25
+ * Guard anything that assumes the record exists — fetching it, resolving its links, judging
26
+ * workflow readiness — with this rather than the literal. The shell and this package once spelled
27
+ * the rule differently, which left every guard here dead.
28
+ *
29
+ * @param recordId - The record id to test
30
+ * @returns `true` when the id is the draft segment, `false` for a real identity or no id at all
31
+ *
32
+ * @public
33
+ */
34
+ export function isDraftRecordId(recordId) {
35
+ return recordId === DRAFT_RECORD_ID;
36
+ }
@@ -1,14 +1,16 @@
1
1
  export type * from '@stonecrop/aform/types';
2
2
  export type * from '@stonecrop/atable/types';
3
+ import { useClientAction } from './client-action';
3
4
  import { executeClientHandler } from './client-handler';
4
5
  import { useLazyLink } from './composables/lazy-link';
5
6
  import { useStonecrop } from './composables/stonecrop';
6
7
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
7
8
  import Doctype from './doctype';
9
+ import { DRAFT_RECORD_ID, isDraftRecordId } from './draft';
8
10
  import { FieldTriggerEngine, getGlobalTriggerEngine, markOperationIrreversible, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition } from './field-triggers';
9
11
  import plugin from './plugins';
10
12
  import Registry from './registry';
11
- import { Stonecrop, getStonecrop } from './stonecrop';
13
+ import { Stonecrop } from './stonecrop';
12
14
  import { HST, createHST, type HSTNode } from './stores/hst';
13
15
  import { useOperationLogStore } from './stores/operation-log';
14
16
  import { useValidationStore } from './stores/validation';
@@ -18,6 +20,6 @@ export type * from './types';
18
20
  export type { ClientHandlerApi } from './client-handler';
19
21
  export type { ValidationError } from './stores/validation';
20
22
  export { ValidationSeverity };
21
- export { Doctype, Registry, Stonecrop, useLazyLink, useStonecrop, executeClientHandler, HST, createHST, HSTNode, FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, useValidationStore, getStonecrop, };
23
+ export { Doctype, Registry, Stonecrop, DRAFT_RECORD_ID, isDraftRecordId, useLazyLink, useStonecrop, executeClientHandler, useClientAction, HST, createHST, HSTNode, FieldTriggerEngine, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, useValidationStore, };
22
24
  export default plugin;
23
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,wBAAwB,CAAA;AAC3C,mBAAmB,yBAAyB,CAAA;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC9F,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,EAET,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,EAEZ,oBAAoB,EAEpB,eAAe,EAEf,GAAG,EACH,SAAS,EACT,OAAO,EAEP,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EAEzB,eAAe,EACf,eAAe,EACf,cAAc,EAEd,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,EAET,kBAAkB,GAElB,CAAA;AAGD,eAAe,MAAM,CAAA"}
package/dist/src/index.js CHANGED
@@ -1,12 +1,14 @@
1
+ import { useClientAction } from './client-action';
1
2
  import { executeClientHandler } from './client-handler';
2
3
  import { useLazyLink } from './composables/lazy-link';
3
4
  import { useStonecrop } from './composables/stonecrop';
4
5
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
5
6
  import Doctype from './doctype';
7
+ import { DRAFT_RECORD_ID, isDraftRecordId } from './draft';
6
8
  import { FieldTriggerEngine, getGlobalTriggerEngine, markOperationIrreversible, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, } from './field-triggers';
7
9
  import plugin from './plugins';
8
10
  import Registry from './registry';
9
- import { Stonecrop, getStonecrop } from './stonecrop';
11
+ import { Stonecrop } from './stonecrop';
10
12
  import { HST, createHST } from './stores/hst';
11
13
  import { useOperationLogStore } from './stores/operation-log';
12
14
  import { useValidationStore } from './stores/validation';
@@ -14,9 +16,13 @@ import { SchemaValidator, createValidator, validateSchema } from './schema-valid
14
16
  import { ValidationSeverity } from './types/schema-validator';
15
17
  // Export enum as value (enums need runtime export, not just type)
16
18
  export { ValidationSeverity };
17
- export { Doctype, Registry, Stonecrop, useLazyLink, useStonecrop,
19
+ export { Doctype, Registry, Stonecrop,
20
+ // Unsaved-record identity, shared with the desktop shell
21
+ DRAFT_RECORD_ID, isDraftRecordId, useLazyLink, useStonecrop,
18
22
  // clientHandler executor
19
23
  executeClientHandler,
24
+ // The one blessed write path, shared by every Vue host
25
+ useClientAction,
20
26
  // HST exports for advanced usage
21
27
  HST, createHST,
22
28
  // Field trigger system exports
@@ -26,8 +32,8 @@ SchemaValidator, createValidator, validateSchema,
26
32
  // Operation log exports
27
33
  useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch,
28
34
  // Field-validation store
29
- useValidationStore,
35
+ useValidationStore,
30
36
  // Utility functions
31
- getStonecrop, };
37
+ };
32
38
  // Default export is the Vue plugin
33
39
  export default plugin;
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAiE,MAAM,kBAAkB,CAAA;AACpH,OAAO,KAAK,EAA8B,eAAe,EAA+B,MAAM,mBAAmB,CAAA;AAEjH,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAA;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAa;IAElC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAK;IAE/C;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc,CAAqE;IAE3F;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB,CAAgB;IAE3C;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IAExB;;;;OAIG;gBACS,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAUjG;;;OAGG;IACH,OAAO,CAA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S,EAAE,MAAM,CAAA;KAAE,CAAC;IAWvF;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,eAAe,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAwBtG;;;OAGG;IACH,OAAO,CAAC,oBAAoB;CAgC5B"}
@@ -1,5 +1,4 @@
1
1
  import { componentCategory, componentLinkExpansion, resolveLinkRenderMode } from '@stonecrop/schema';
2
- import { getGlobalTriggerEngine } from './field-triggers';
3
2
  /**
4
3
  * Stonecrop Registry class
5
4
  * @public
@@ -73,13 +72,12 @@ export default class Registry {
73
72
  this.registry[doctype.slug] = doctype;
74
73
  this._ancestorIndexDirty = true;
75
74
  }
76
- // Register actions (including field triggers) with the field trigger engine
77
- const triggerEngine = getGlobalTriggerEngine();
78
- // Register under both doctype name and slug to handle different lookup patterns
79
- triggerEngine.registerDoctypeActions(doctype.doctype, doctype.actions);
80
- if (doctype.slug !== doctype.doctype) {
81
- triggerEngine.registerDoctypeActions(doctype.slug, doctype.actions);
82
- }
75
+ // Field triggers are registered imperatively, by the app, via the FieldTriggerEngine's own
76
+ // `registerDoctypeActions`. A doctype used to be able to declare them too, but that path
77
+ // could not survive the wire — neither the Zod gate nor the SDL carries such a map — so it
78
+ // only ever worked for a host bypassing both, and it left two public `runAction` methods
79
+ // meaning opposite things. Registering here would also overwrite an app's imperative
80
+ // registration, since `registerDoctypeActions` sets the maps even when handed nothing.
83
81
  if (doctype.component && this.router && !this.router.hasRoute(doctype.doctype)) {
84
82
  this.router.addRoute({
85
83
  path: `/${doctype.slug}`,
@@ -1,4 +1,4 @@
1
- import type { DataClient } from '@stonecrop/schema';
1
+ import type { DataClient, GetRecordOptions, GetRecordsOptions, GetRecordsResult } from '@stonecrop/schema';
2
2
  import Doctype from './doctype';
3
3
  import Registry from './registry';
4
4
  import { type HSTNode } from './stores/hst';
@@ -22,6 +22,11 @@ export declare class Stonecrop {
22
22
  private _operationLogStore?;
23
23
  private _operationLogConfig?;
24
24
  private _client?;
25
+ /**
26
+ * Per-doctype page info from the last list read, keyed by slug. Reactive so views tracking
27
+ * it update on fetch. Deliberately not in HST — see {@link Stonecrop.getRecords}.
28
+ */
29
+ private pageInfo;
25
30
  /** The registry instance containing all doctype definitions */
26
31
  readonly registry: Registry;
27
32
  /**
@@ -138,7 +143,7 @@ export declare class Stonecrop {
138
143
  getSnapshot: () => import("./types").OperationLogSnapshot;
139
144
  markIrreversible: (operationId: string, reason: string) => void;
140
145
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
141
- }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
146
+ }, "config" | "operations" | "clientId" | "currentIndex">, Pick<{
142
147
  operations: import("vue").Ref<{
143
148
  id: string;
144
149
  type: import("./types").HSTOperationType;
@@ -357,14 +362,6 @@ export declare class Stonecrop {
357
362
  * @param doctype - The doctype to setup
358
363
  */
359
364
  setup(doctype: Doctype): void;
360
- /**
361
- * Run action on doctype
362
- * Executes the action and logs it to the operation log for audit tracking
363
- * @param doctype - The doctype
364
- * @param action - The action to run
365
- * @param args - Action arguments (typically record IDs)
366
- */
367
- runAction(doctype: Doctype, action: string, args?: string[]): void;
368
365
  /**
369
366
  * Get the effective blockWorkflows value for a link.
370
367
  * Returns true if blockWorkflows is explicitly true, or if it's absent and fetch method is 'sync'.
@@ -384,22 +381,76 @@ export declare class Stonecrop {
384
381
  blockedLinks?: string[];
385
382
  };
386
383
  /**
387
- * Get records from server using the configured data client.
384
+ * Fetch a doctype's records from the server and store them in HST.
385
+ *
386
+ * This is the one read path for a list. Every caller shares its keying rule, so a row is
387
+ * always stored under the identity its Edit link will later ask for.
388
+ *
389
+ * Deliberately unguarded, unlike {@link Stonecrop.getRecord}: a list is a view of data that
390
+ * changes, so revisiting one must re-read it rather than serve whatever HST happens to hold.
391
+ *
392
+ * `options` is forwarded to the client untouched — no row limit is invented here, because
393
+ * nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
394
+ * passes none gets whatever the server considers a reasonable page.
395
+ *
388
396
  * @param doctype - The doctype
397
+ * @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
389
398
  * @throws Error if no data client has been configured
399
+ * @public
400
+ */
401
+ getRecords(doctype: Doctype, options?: GetRecordsOptions): Promise<GetRecordsResult>;
402
+ /**
403
+ * What the last {@link Stonecrop.getRecords} for this doctype returned about the wider set.
404
+ *
405
+ * Answers the question HST cannot: HST holds what was fetched, so counting its keys reports
406
+ * how much has been seen, never how much exists. Reactive, so a view reading it re-renders
407
+ * when a fetch lands.
408
+ *
409
+ * @param doctype - The doctype slug string or Doctype object
410
+ * @returns Page info, or undefined if this doctype's records have not been fetched
411
+ * @public
390
412
  */
391
- getRecords(doctype: Doctype): Promise<void>;
413
+ getPageInfo(doctype: string | Doctype): {
414
+ hasMore: boolean;
415
+ count?: number;
416
+ } | undefined;
392
417
  /**
393
- * Get single record from server using the configured data client.
418
+ * Fetch a single record from the server and store it in HST.
419
+ *
420
+ * This is the one read path for a record, and it owns the whole job: deciding whether a fetch
421
+ * is warranted, performing it, and writing the result back under the doctype's declared
422
+ * identity. Callers ask for a record and get one; they do not re-derive when to ask.
423
+ *
424
+ * Two cases return without touching the network, because in both the answer is already known:
425
+ * a draft does not exist on the server yet, and a record already in HST has been read.
426
+ * Refetching the latter would also discard unsaved edits sitting in the store.
427
+ *
394
428
  * @param doctype - The doctype slug string or Doctype object
395
429
  * @param recordId - The record ID
430
+ * @param options - Query options (includeNested, maxDepth), forwarded to the client
396
431
  * @throws Error if no data client has been configured
397
432
  * @throws Error if a slug string is given and no matching doctype is found in the registry
433
+ * @public
398
434
  */
399
- getRecord(doctype: string | Doctype, recordId: string): Promise<void>;
435
+ getRecord(doctype: string | Doctype, recordId: string, options?: GetRecordOptions): Promise<void>;
400
436
  /**
401
- * Dispatch an action to the server via the configured data client.
402
- * All state changes flow through this single mutation endpoint.
437
+ * Dispatch an action to the server via the configured data client, and file the record it
438
+ * returns into HST under the identity the *server* settled on.
439
+ *
440
+ * The write is the point. For a created record the settled identity is never the one that was
441
+ * dispatched, so a caller that stores the result under the id it sent files the record under a
442
+ * key nothing can fetch and leaves the next save creating a second one. Every host that
443
+ * hand-rolled this got it wrong the same way, so it stops being the caller's job — this is the
444
+ * write-side twin of {@link Stonecrop.getRecords}, which keys reads by the same rule.
445
+ *
446
+ * Two things are deliberately NOT done here, because both need the id that was dispatched and
447
+ * that lives inside `args` — an opaque array whose shape is a convention between a host's
448
+ * client and its server handlers, not something this layer may parse. Dropping the stale key
449
+ * and moving the route therefore stay with `useClientAction`, which knows both ids.
450
+ *
451
+ * A result that states no identity of its own — a `{ state: 'APPROVED' }` outcome — is left
452
+ * alone rather than guessed at, for the same reason `settledRecordId` is strict: a partial
453
+ * record must not be able to look like a rename.
403
454
  *
404
455
  * @param doctype - The doctype
405
456
  * @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
@@ -486,15 +537,4 @@ export declare class Stonecrop {
486
537
  */
487
538
  private collectNestedData;
488
539
  }
489
- /**
490
- * Returns the global Stonecrop singleton instance, or `undefined` if no
491
- * instance has been created yet.
492
- *
493
- * Use this when you need the Stonecrop instance outside a Vue component
494
- * context (e.g., in workflow action handlers, plugin setup code, or
495
- * non-component utilities). Inside a component, prefer `useStonecrop()`.
496
- *
497
- * @public
498
- */
499
- export declare function getStonecrop(): Stonecrop | undefined;
500
540
  //# sourceMappingURL=stonecrop.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtD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
  import { createHST } from './stores/hst';
4
4
  import { useOperationLogStore } from './stores/operation-log';
5
5
  /**
@@ -19,6 +19,11 @@ export class Stonecrop {
19
19
  _operationLogStore;
20
20
  _operationLogConfig;
21
21
  _client;
22
+ /**
23
+ * Per-doctype page info from the last list read, keyed by slug. Reactive so views tracking
24
+ * it update on fetch. Deliberately not in HST — see {@link Stonecrop.getRecords}.
25
+ */
26
+ pageInfo = reactive({});
22
27
  /** The registry instance containing all doctype definitions */
23
28
  registry;
24
29
  /**
@@ -198,66 +203,6 @@ export class Stonecrop {
198
203
  // Ensure doctype exists in store
199
204
  this.ensureDoctypeExists(doctype.slug);
200
205
  }
201
- /**
202
- * Run action on doctype
203
- * Executes the action and logs it to the operation log for audit tracking
204
- * @param doctype - The doctype
205
- * @param action - The action to run
206
- * @param args - Action arguments (typically record IDs)
207
- */
208
- runAction(doctype, action, args) {
209
- const registry = this.registry.registry[doctype.slug];
210
- const actions = registry?.actions?.get(action);
211
- const recordIds = Array.isArray(args) ? args.filter((arg) => typeof arg === 'string') : undefined;
212
- const recordId = recordIds?.[0];
213
- // Check if workflow is ready (all blocked links have data)
214
- const workflowStatus = recordId ? this.isWorkflowReady(doctype, recordId) : { ready: true };
215
- if (!workflowStatus.ready) {
216
- const opLogStore = this.getOperationLogStore();
217
- opLogStore.logAction(doctype.doctype, action, recordIds, 'failure', `BLOCKED: missing data for links: ${workflowStatus.blockedLinks?.join(', ')}`);
218
- throw new Error(`Workflow blocked: missing data for links: ${workflowStatus.blockedLinks?.join(', ')}`);
219
- }
220
- // Log action execution start
221
- const opLogStore = this.getOperationLogStore();
222
- let actionResult = 'success';
223
- let actionError;
224
- try {
225
- // Execute action functions
226
- if (actions && actions.length > 0) {
227
- const engine = getGlobalTriggerEngine();
228
- actions.forEach(actionStr => {
229
- try {
230
- const actionFn = engine.getAction(actionStr);
231
- if (!actionFn)
232
- throw new Error(`Action "${actionStr}" is not registered in FieldTriggerEngine`);
233
- const context = {
234
- path: `${doctype.slug}.${recordIds?.[0] ?? ''}`,
235
- fieldname: action,
236
- beforeValue: undefined,
237
- afterValue: args,
238
- operation: 'set',
239
- doctype: doctype.doctype,
240
- recordId: recordId,
241
- timestamp: new Date(),
242
- };
243
- void actionFn(context);
244
- }
245
- catch (error) {
246
- actionResult = 'failure';
247
- actionError = error instanceof Error ? error.message : 'Unknown error';
248
- throw error;
249
- }
250
- });
251
- }
252
- }
253
- catch {
254
- // Error already set in inner catch
255
- }
256
- finally {
257
- // Log the action execution to operation log
258
- opLogStore.logAction(doctype.doctype, action, recordIds, actionResult, actionError);
259
- }
260
- }
261
206
  /**
262
207
  * Get the effective blockWorkflows value for a link.
263
208
  * Returns true if blockWorkflows is explicitly true, or if it's absent and fetch method is 'sync'.
@@ -282,7 +227,7 @@ export class Stonecrop {
282
227
  */
283
228
  isWorkflowReady(doctype, recordId) {
284
229
  // New records don't block workflows - they haven't been saved yet
285
- if (recordId === 'new') {
230
+ if (isDraftRecordId(recordId)) {
286
231
  return { ready: true };
287
232
  }
288
233
  const links = this.registry.getDescendantLinks(doctype.slug);
@@ -301,16 +246,34 @@ export class Stonecrop {
301
246
  return { ready: true };
302
247
  }
303
248
  /**
304
- * Get records from server using the configured data client.
249
+ * Fetch a doctype's records from the server and store them in HST.
250
+ *
251
+ * This is the one read path for a list. Every caller shares its keying rule, so a row is
252
+ * always stored under the identity its Edit link will later ask for.
253
+ *
254
+ * Deliberately unguarded, unlike {@link Stonecrop.getRecord}: a list is a view of data that
255
+ * changes, so revisiting one must re-read it rather than serve whatever HST happens to hold.
256
+ *
257
+ * `options` is forwarded to the client untouched — no row limit is invented here, because
258
+ * nothing on this side of the wire knows what is safe for an arbitrary backend. A caller that
259
+ * passes none gets whatever the server considers a reasonable page.
260
+ *
305
261
  * @param doctype - The doctype
262
+ * @param options - Query options (filters, orderBy, limit, offset), forwarded to the client
306
263
  * @throws Error if no data client has been configured
264
+ * @public
307
265
  */
308
- async getRecords(doctype) {
266
+ async getRecords(doctype, options) {
309
267
  if (!this._client) {
310
268
  throw new Error('No data client configured. Call setClient() with a DataClient implementation ' +
311
269
  '(e.g., StonecropClient from @stonecrop/graphql-client) before fetching records.');
312
270
  }
313
- const records = await this._client.getRecords(doctype);
271
+ const result = await this._client.getRecords(doctype, options);
272
+ const records = result.data;
273
+ // Page info is kept beside HST, not in it. `getRecordIds` reads the raw keys under a
274
+ // doctype node, so anything filed there becomes a phantom record — the same hazard that
275
+ // ruled out seeding a draft node.
276
+ this.pageInfo[doctype.slug] = { hasMore: result.hasMore, count: result.count };
314
277
  // Key each record by its declared primary key, falling back to `id`. This used to read
315
278
  // `record.id` only, which silently dropped every row of a natural-keyed doctype (no `id`
316
279
  // column at all) — the records never entered HST, so the list rendered empty and no
@@ -321,15 +284,42 @@ export class Stonecrop {
321
284
  this.addRecord(doctype, recordId, record);
322
285
  }
323
286
  });
287
+ return result;
288
+ }
289
+ /**
290
+ * What the last {@link Stonecrop.getRecords} for this doctype returned about the wider set.
291
+ *
292
+ * Answers the question HST cannot: HST holds what was fetched, so counting its keys reports
293
+ * how much has been seen, never how much exists. Reactive, so a view reading it re-renders
294
+ * when a fetch lands.
295
+ *
296
+ * @param doctype - The doctype slug string or Doctype object
297
+ * @returns Page info, or undefined if this doctype's records have not been fetched
298
+ * @public
299
+ */
300
+ getPageInfo(doctype) {
301
+ const slug = typeof doctype === 'string' ? doctype : doctype.slug;
302
+ return this.pageInfo[slug];
324
303
  }
325
304
  /**
326
- * Get single record from server using the configured data client.
305
+ * Fetch a single record from the server and store it in HST.
306
+ *
307
+ * This is the one read path for a record, and it owns the whole job: deciding whether a fetch
308
+ * is warranted, performing it, and writing the result back under the doctype's declared
309
+ * identity. Callers ask for a record and get one; they do not re-derive when to ask.
310
+ *
311
+ * Two cases return without touching the network, because in both the answer is already known:
312
+ * a draft does not exist on the server yet, and a record already in HST has been read.
313
+ * Refetching the latter would also discard unsaved edits sitting in the store.
314
+ *
327
315
  * @param doctype - The doctype slug string or Doctype object
328
316
  * @param recordId - The record ID
317
+ * @param options - Query options (includeNested, maxDepth), forwarded to the client
329
318
  * @throws Error if no data client has been configured
330
319
  * @throws Error if a slug string is given and no matching doctype is found in the registry
320
+ * @public
331
321
  */
332
- async getRecord(doctype, recordId) {
322
+ async getRecord(doctype, recordId, options) {
333
323
  if (!this._client) {
334
324
  throw new Error('No data client configured. Call setClient() with a DataClient implementation ' +
335
325
  '(e.g., StonecropClient from @stonecrop/graphql-client) before fetching records.');
@@ -338,14 +328,37 @@ export class Stonecrop {
338
328
  if (!resolved) {
339
329
  throw new Error(`Doctype not found: ${typeof doctype === 'string' ? doctype : doctype.slug}`);
340
330
  }
341
- const result = await this._client.getRecord(resolved, recordId);
331
+ // An unsaved draft has no server record, so a fetch could only ever miss. This guard used
332
+ // to live in every host, which is how the private draft-id scheme leaked into all of them.
333
+ if (isDraftRecordId(recordId)) {
334
+ return;
335
+ }
336
+ if (this.getRecordById(resolved.slug, recordId)) {
337
+ return;
338
+ }
339
+ const result = await this._client.getRecord(resolved, recordId, options);
342
340
  if (result?.record) {
343
341
  this.addRecord(resolved, recordId, result.record);
344
342
  }
345
343
  }
346
344
  /**
347
- * Dispatch an action to the server via the configured data client.
348
- * All state changes flow through this single mutation endpoint.
345
+ * Dispatch an action to the server via the configured data client, and file the record it
346
+ * returns into HST under the identity the *server* settled on.
347
+ *
348
+ * The write is the point. For a created record the settled identity is never the one that was
349
+ * dispatched, so a caller that stores the result under the id it sent files the record under a
350
+ * key nothing can fetch and leaves the next save creating a second one. Every host that
351
+ * hand-rolled this got it wrong the same way, so it stops being the caller's job — this is the
352
+ * write-side twin of {@link Stonecrop.getRecords}, which keys reads by the same rule.
353
+ *
354
+ * Two things are deliberately NOT done here, because both need the id that was dispatched and
355
+ * that lives inside `args` — an opaque array whose shape is a convention between a host's
356
+ * client and its server handlers, not something this layer may parse. Dropping the stale key
357
+ * and moving the route therefore stay with `useClientAction`, which knows both ids.
358
+ *
359
+ * A result that states no identity of its own — a `{ state: 'APPROVED' }` outcome — is left
360
+ * alone rather than guessed at, for the same reason `settledRecordId` is strict: a partial
361
+ * record must not be able to look like a rename.
349
362
  *
350
363
  * @param doctype - The doctype
351
364
  * @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
@@ -358,7 +371,21 @@ export class Stonecrop {
358
371
  throw new Error('No data client configured. Call setClient() with a DataClient implementation ' +
359
372
  '(e.g., StonecropClient from @stonecrop/graphql-client) before dispatching actions.');
360
373
  }
361
- return this._client.runAction(doctype, action, args);
374
+ const result = await this._client.runAction(doctype, action, args);
375
+ if (result.success && result.data && typeof result.data === 'object' && !Array.isArray(result.data)) {
376
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the guard above confirms a non-null, non-array object; the action result payload is an opaque JSON scalar
377
+ const record = result.data;
378
+ // Require the declared key to be *present* before trusting `getRecordId`, which falls
379
+ // back to `id`. Without that, a handler returning `{ id, total }` for a natural-keyed
380
+ // doctype would relocate the record to a key the adapter cannot look up.
381
+ if (record[doctype.recordIdField] !== undefined) {
382
+ const settledId = doctype.getRecordId(record);
383
+ if (settledId !== undefined) {
384
+ this.addRecord(doctype, settledId, record);
385
+ }
386
+ }
387
+ }
388
+ return result;
362
389
  }
363
390
  /**
364
391
  * Ensure doctype section exists in HST store
@@ -557,19 +584,6 @@ export class Stonecrop {
557
584
  return payload;
558
585
  }
559
586
  }
560
- /**
561
- * Returns the global Stonecrop singleton instance, or `undefined` if no
562
- * instance has been created yet.
563
- *
564
- * Use this when you need the Stonecrop instance outside a Vue component
565
- * context (e.g., in workflow action handlers, plugin setup code, or
566
- * non-component utilities). Inside a component, prefer `useStonecrop()`.
567
- *
568
- * @public
569
- */
570
- export function getStonecrop() {
571
- return Stonecrop._root;
572
- }
573
587
  function createCodedError(message, code) {
574
588
  // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- extending Error with code property; CodedError cast is the standard pattern for typed error objects
575
589
  const error = new Error(message);
@@ -90,7 +90,7 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
90
90
  getSnapshot: () => OperationLogSnapshot;
91
91
  markIrreversible: (operationId: string, reason: string) => void;
92
92
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
93
- }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
93
+ }, "config" | "operations" | "clientId" | "currentIndex">, Pick<{
94
94
  operations: import("vue").Ref<{
95
95
  id: string;
96
96
  type: import("..").HSTOperationType;