@stonecrop/stonecrop 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,20 +16,47 @@ _This package is under active development / design._
16
16
  ```typescript
17
17
  import { createApp } from 'vue'
18
18
  import Stonecrop from '@stonecrop/stonecrop'
19
+ import router from './router'
19
20
 
20
21
  const app = createApp(App)
21
22
 
22
- // Build your Registry before installing the plugin
23
- const registry = new Registry(router, async ({ path, segments }) => {
24
- return await fetchDoctypeMeta(segments[0])
25
- })
26
-
27
23
  // Install the Stonecrop plugin
28
- app.use(Stonecrop, { registry })
24
+ app.use(Stonecrop, {
25
+ router,
26
+
27
+ // Lazy-load doctype metadata from your API given the current route context.
28
+ // routeContext = { path, segments } — adapt segments to your doctype naming.
29
+ getMeta: async ({ segments }) => {
30
+ return await fetchDoctypeMeta(segments[0])
31
+ },
32
+
33
+ // Optional: replace the default REST fetch() stub with your own transport.
34
+ // When provided, Stonecrop.getRecord() calls this instead of fetch(`/${slug}/${id}`).
35
+ fetchRecord: async (doctype, id) => {
36
+ return await myApiClient.getRecord(doctype, id)
37
+ },
38
+
39
+ // Optional: replace the default REST fetch() stub for lists.
40
+ fetchRecords: async (doctype) => {
41
+ return await myApiClient.getRecords(doctype)
42
+ },
43
+ })
29
44
 
30
45
  app.mount('#app')
31
46
  ```
32
47
 
48
+ ### Plugin Options
49
+
50
+ | Option | Type | Description |
51
+ |--------|------|-------------|
52
+ | `router` | `Router` | Vue Router instance. Required for route-based doctype resolution. |
53
+ | `getMeta` | `(ctx: RouteContext) => DoctypeMeta \| Promise<DoctypeMeta>` | Lazy-loads doctype metadata for the current route. `ctx` has `path` and `segments`. |
54
+ | `fetchRecord` | `(doctype, id) => Promise<Record \| null>` | Injectable replacement for `Stonecrop.getRecord()`'s default REST fetch. Use this to plug in GraphQL or any other transport. |
55
+ | `fetchRecords` | `(doctype) => Promise<Record[]>` | Injectable replacement for `Stonecrop.getRecords()`'s default REST fetch. |
56
+ | `components` | `Record<string, Component>` | Additional Vue components to register globally. |
57
+ | `autoInitializeRouter` | `boolean` | Call `onRouterInitialized` automatically after mount. Default: `false`. |
58
+ | `onRouterInitialized` | `(registry, stonecrop) => void` | Callback invoked after plugin install + mount. Receives the Registry and Stonecrop instances. |
59
+
33
60
  ### Available Imports
34
61
 
35
62
  ```typescript
@@ -54,16 +81,22 @@ import { useStonecrop } from '@stonecrop/stonecrop'
54
81
 
55
82
  export default {
56
83
  setup() {
57
- const { stonecrop } = useStonecrop()
84
+ // Base mode operation log only, no HST record loading
85
+ const { stonecrop, operationLog } = useStonecrop()
86
+
87
+ // HST mode — pass doctype and optional recordId for full integration
88
+ const { stonecrop, formData, provideHSTPath, handleHSTChange } = useStonecrop({
89
+ doctype: myDoctype,
90
+ recordId: 'record-123', // omit or pass undefined for new records
91
+ })
58
92
 
59
93
  // Access HST store
60
94
  const store = stonecrop.value?.getStore()
61
95
 
62
- // Work with records
63
- const records = stonecrop.value?.records('doctype')
96
+ // Work with records directly
64
97
  const record = stonecrop.value?.getRecordById('doctype', recordId)
65
98
 
66
- return { stonecrop, records, record }
99
+ return { stonecrop, formData }
67
100
  }
68
101
  }
69
102
  ```
@@ -1,6 +1,5 @@
1
- // src/composable.ts
2
1
  import { inject, onMounted, ref, watch, provide, computed } from 'vue';
3
- import { Stonecrop } from './stonecrop';
2
+ import { Stonecrop } from '../stonecrop';
4
3
  import { storeToRefs } from 'pinia';
5
4
  /**
6
5
  * @public
@@ -284,9 +283,9 @@ export function useStonecrop(options) {
284
283
  * Recursively save a record with all nested doctype fields
285
284
  * @param doctype - The doctype metadata
286
285
  * @param recordId - The record ID to save
287
- * @returns Promise resolving to the complete save payload
286
+ * @returns The complete save payload
288
287
  */
289
- const saveRecursive = async (doctype, recordId) => {
288
+ const saveRecursive = (doctype, recordId) => {
290
289
  if (!hstStore.value || !stonecrop.value) {
291
290
  throw new Error('HST store not initialized');
292
291
  }
package/dist/doctype.js CHANGED
@@ -9,6 +9,14 @@ export default class DoctypeMeta {
9
9
  * @readonly
10
10
  */
11
11
  doctype;
12
+ /**
13
+ * Alias for doctype (for DoctypeLike interface compatibility)
14
+ * @public
15
+ * @readonly
16
+ */
17
+ get name() {
18
+ return this.doctype;
19
+ }
12
20
  /**
13
21
  * The doctype schema
14
22
  * @public
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useStonecrop } from './composable';
1
+ import { useStonecrop } from './composables/stonecrop';
2
2
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
3
3
  import DoctypeMeta from './doctype';
4
4
  import { getGlobalTriggerEngine, markOperationIrreversible, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, } from './field-triggers';
@@ -24,14 +24,19 @@ async function setupAutoInitialization(registry, stonecrop, onRouterInitialized)
24
24
  * ```ts
25
25
  * import { createApp } from 'vue'
26
26
  * import Stonecrop from '@stonecrop/stonecrop'
27
+ * import { StonecropClient } from '@stonecrop/graphql-client'
27
28
  * import router from './router'
28
29
  *
30
+ * const client = new StonecropClient({ endpoint: '/graphql' })
31
+ *
29
32
  * const app = createApp(App)
30
33
  * app.use(Stonecrop, {
31
34
  * router,
35
+ * client,
32
36
  * getMeta: async (routeContext) => {
33
37
  * // routeContext contains: { path, segments }
34
- * // fetch doctype meta from your API using the route context
38
+ * // use the client to fetch doctype meta
39
+ * return client.getMeta({ doctype: routeContext.segments[0] })
35
40
  * },
36
41
  * autoInitializeRouter: true,
37
42
  * onRouterInitialized: async (registry, stonecrop) => {
@@ -56,7 +61,7 @@ const plugin = {
56
61
  app.provide('$registry', registry);
57
62
  app.config.globalProperties.$registry = registry;
58
63
  // Create and provide a global Stonecrop instance
59
- const stonecrop = new Stonecrop(registry);
64
+ const stonecrop = new Stonecrop(registry, undefined, options?.client ? { client: options.client } : undefined);
60
65
  app.provide('$stonecrop', stonecrop);
61
66
  app.config.globalProperties.$stonecrop = stonecrop;
62
67
  // Initialize operation log store if Pinia is available
@@ -73,6 +78,7 @@ const plugin = {
73
78
  }
74
79
  catch (error) {
75
80
  // Pinia not available - operation log won't work, but app should still function
81
+ // eslint-disable-next-line no-console
76
82
  console.warn('Pinia not available - operation log features will be disabled:', error);
77
83
  }
78
84
  // Register custom components
@@ -1,9 +1,9 @@
1
1
  import { Ref, ComputedRef } from 'vue';
2
- import Registry from './registry';
3
- import { Stonecrop } from './stonecrop';
4
- import DoctypeMeta from './doctype';
5
- import type { HSTNode } from './stores/hst';
6
- import type { HSTOperation, OperationLogConfig, OperationLogSnapshot } from './types/operation-log';
2
+ import Registry from '../registry';
3
+ import { Stonecrop } from '../stonecrop';
4
+ import DoctypeMeta from '../doctype';
5
+ import type { HSTNode } from '../stores/hst';
6
+ import type { HSTOperation, OperationLogConfig, OperationLogSnapshot } from '../types/operation-log';
7
7
  import { SchemaTypes } from '@stonecrop/aform';
8
8
  /**
9
9
  * Operation Log API - nested object containing all operation log functionality
@@ -90,4 +90,4 @@ export declare function useStonecrop(options: {
90
90
  doctype: DoctypeMeta;
91
91
  recordId?: string;
92
92
  }): HSTStonecropReturn;
93
- //# sourceMappingURL=composable.d.ts.map
93
+ //# sourceMappingURL=stonecrop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../../src/composables/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,GAAG,EAAiC,WAAW,EAAE,MAAM,KAAK,CAAA;AAExF,OAAO,QAAQ,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,WAAW,MAAM,YAAY,CAAA;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAG5C,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,EAAE,WAAW,EAAiB,MAAM,kBAAkB,CAAA;AA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G;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,mBAAmB,GAAG,kBAAkB,CAAA;AACxE;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACrC,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,OAAO,EAAE,WAAW,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,kBAAkB,CAAA"}
@@ -11,6 +11,12 @@ export default class DoctypeMeta {
11
11
  * @readonly
12
12
  */
13
13
  readonly doctype: string;
14
+ /**
15
+ * Alias for doctype (for DoctypeLike interface compatibility)
16
+ * @public
17
+ * @readonly
18
+ */
19
+ get name(): string;
14
20
  /**
15
21
  * The doctype schema
16
22
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../src/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAE/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAE3C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;IAE7C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;IAE9B;;;;;;;OAOG;gBAEF,O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AAC,EAAE,SAAS;IAStB;;;;;;;;;;;;;;OAcG;IACH,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAW3F;;;;;;;;;;;;;;;OAeG;IACH,IAAI,IAAI,WAKP;CACD"}
@@ -1,21 +1,21 @@
1
1
  export type * from '@stonecrop/aform/types';
2
2
  export type * from '@stonecrop/atable/types';
3
- import { useStonecrop } from './composable';
3
+ import { useStonecrop } from './composables/stonecrop';
4
4
  import { useOperationLog, useUndoRedoShortcuts, withBatch } from './composables/operation-log';
5
5
  import DoctypeMeta from './doctype';
6
6
  import { getGlobalTriggerEngine, markOperationIrreversible, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition } from './field-triggers';
7
7
  import plugin from './plugins';
8
8
  import Registry from './registry';
9
- import { Stonecrop } from './stonecrop';
9
+ import { type StonecropOptions, Stonecrop } from './stonecrop';
10
10
  import { HST, createHST, type HSTNode } from './stores/hst';
11
11
  import { useOperationLogStore } from './stores/operation-log';
12
12
  import { SchemaValidator, createValidator, validateSchema } from './schema-validator';
13
13
  export type * from './types';
14
- export type { BaseStonecropReturn, HSTChangeData, HSTStonecropReturn, OperationLogAPI } from './composable';
14
+ export type { BaseStonecropReturn, HSTChangeData, HSTStonecropReturn, OperationLogAPI } from './composables/stonecrop';
15
15
  export type { FieldTriggerEngine } from './field-triggers';
16
16
  export type { FieldChangeContext, TransitionChangeContext, FieldTriggerExecutionResult, ActionExecutionResult, TransitionExecutionResult, FieldActionFunction, TransitionActionFunction, } from './types/field-triggers';
17
17
  export type { ValidationIssue, ValidationResult, ValidatorOptions } from './schema-validator';
18
18
  export { ValidationSeverity } from './schema-validator';
19
- export { DoctypeMeta, Registry, Stonecrop, useStonecrop, HST, createHST, HSTNode, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, };
19
+ export { DoctypeMeta, Registry, Stonecrop, StonecropOptions, useStonecrop, HST, createHST, HSTNode, getGlobalTriggerEngine, registerGlobalAction, registerTransitionAction, setFieldRollback, triggerTransition, markOperationIrreversible, SchemaValidator, createValidator, validateSchema, useOperationLog, useOperationLogStore, useUndoRedoShortcuts, withBatch, };
20
20
  export default plugin;
21
21
  //# 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,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC9F,OAAO,WAAW,MAAM,WAAW,CAAA;AACnC,OAAO,EACN,sBAAsB,EACtB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACrF,mBAAmB,SAAS,CAAA;AAC5B,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3G,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;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AE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACrF,mBAAmB,SAAS,CAAA;AAC5B,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACtH,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,YAAY,EACX,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,GACxB,MAAM,wBAAwB,CAAA;AAE/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,EACN,WAAW,EACX,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,YAAY,EAEZ,GAAG,EACH,SAAS,EACT,OAAO,EAEP,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,GACT,CAAA;AAGD,eAAe,MAAM,CAAA"}
@@ -7,14 +7,19 @@ import { type Plugin } from 'vue';
7
7
  * ```ts
8
8
  * import { createApp } from 'vue'
9
9
  * import Stonecrop from '@stonecrop/stonecrop'
10
+ * import { StonecropClient } from '@stonecrop/graphql-client'
10
11
  * import router from './router'
11
12
  *
13
+ * const client = new StonecropClient({ endpoint: '/graphql' })
14
+ *
12
15
  * const app = createApp(App)
13
16
  * app.use(Stonecrop, {
14
17
  * router,
18
+ * client,
15
19
  * getMeta: async (routeContext) => {
16
20
  * // routeContext contains: { path, segments }
17
- * // fetch doctype meta from your API using the route context
21
+ * // use the client to fetch doctype meta
22
+ * return client.getMeta({ doctype: routeContext.segments[0] })
18
23
  * },
19
24
  * autoInitializeRouter: true,
20
25
  * onRouterInitialized: async (registry, stonecrop) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAY,MAAM,KAAK,CAAA;AA2BhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,MAAM,EAAE,MAiDb,CAAA;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAY,MAAM,KAAK,CAAA;AA2BhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,QAAA,MAAM,MAAM,EAAE,MAkDb,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -1,8 +1,24 @@
1
+ import type { DataClient } from '@stonecrop/schema';
1
2
  import DoctypeMeta from './doctype';
2
3
  import Registry from './registry';
3
4
  import { type HSTNode } from './stores/hst';
4
5
  import type { OperationLogConfig } from './types/operation-log';
5
6
  import type { RouteContext } from './types/registry';
7
+ /**
8
+ * Options for constructing a Stonecrop instance directly.
9
+ * When using the Vue plugin, pass these via `InstallOptions` instead.
10
+ * @public
11
+ */
12
+ export interface StonecropOptions {
13
+ /**
14
+ * Data client for fetching doctype metadata and records.
15
+ * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
16
+ * or implement DataClient for custom data sources.
17
+ *
18
+ * Can be set later via `setClient()` for deferred configuration.
19
+ */
20
+ client?: DataClient;
21
+ }
6
22
  /**
7
23
  * Main Stonecrop class with HST integration and built-in Operation Log
8
24
  * @public
@@ -11,14 +27,35 @@ export declare class Stonecrop {
11
27
  private hstStore;
12
28
  private _operationLogStore?;
13
29
  private _operationLogConfig?;
30
+ private _client?;
14
31
  /** The registry instance containing all doctype definitions */
15
32
  readonly registry: Registry;
16
33
  /**
17
34
  * Creates a new Stonecrop instance with HST integration
18
35
  * @param registry - The Registry instance containing doctype definitions
19
36
  * @param operationLogConfig - Optional configuration for the operation log
37
+ * @param options - Options including the data client (can be set later via setClient)
20
38
  */
21
- constructor(registry: Registry, operationLogConfig?: Partial<OperationLogConfig>);
39
+ constructor(registry: Registry, operationLogConfig?: Partial<OperationLogConfig>, options?: StonecropOptions);
40
+ /**
41
+ * Set the data client for fetching doctype metadata and records.
42
+ * Use this for deferred configuration in Nuxt/Vue plugin setups.
43
+ *
44
+ * @param client - DataClient implementation (e.g., StonecropClient from \@stonecrop/graphql-client)
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const { setClient } = useStonecropRegistry()
49
+ * const client = new StonecropClient({ endpoint: '/graphql' })
50
+ * setClient(client)
51
+ * ```
52
+ */
53
+ setClient(client: DataClient): void;
54
+ /**
55
+ * Get the current data client
56
+ * @returns The DataClient instance or undefined if not set
57
+ */
58
+ getClient(): DataClient | undefined;
22
59
  /**
23
60
  * Get the operation log store (lazy initialization)
24
61
  * @internal
@@ -109,7 +146,7 @@ export declare class Stonecrop {
109
146
  getSnapshot: () => import("./types").OperationLogSnapshot;
110
147
  markIrreversible: (operationId: string, reason: string) => void;
111
148
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
112
- }, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
149
+ }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
113
150
  operations: import("vue").Ref<{
114
151
  id: string;
115
152
  type: import("./types").HSTOperationType;
@@ -341,16 +378,33 @@ export declare class Stonecrop {
341
378
  */
342
379
  runAction(doctype: DoctypeMeta, action: string, args?: any[]): void;
343
380
  /**
344
- * Get records from server (maintains compatibility)
381
+ * Get records from server using the configured data client.
345
382
  * @param doctype - The doctype
383
+ * @throws Error if no data client has been configured
346
384
  */
347
385
  getRecords(doctype: DoctypeMeta): Promise<void>;
348
386
  /**
349
- * Get single record from server (maintains compatibility)
387
+ * Get single record from server using the configured data client.
350
388
  * @param doctype - The doctype
351
389
  * @param recordId - The record ID
390
+ * @throws Error if no data client has been configured
352
391
  */
353
392
  getRecord(doctype: DoctypeMeta, recordId: string): Promise<void>;
393
+ /**
394
+ * Dispatch an action to the server via the configured data client.
395
+ * All state changes flow through this single mutation endpoint.
396
+ *
397
+ * @param doctype - The doctype
398
+ * @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
399
+ * @param args - Action arguments (typically record ID and/or form data)
400
+ * @returns Action result with success status, response data, and any error
401
+ * @throws Error if no data client has been configured
402
+ */
403
+ dispatchAction(doctype: DoctypeMeta, action: string, args?: unknown[]): Promise<{
404
+ success: boolean;
405
+ data: unknown;
406
+ error: string | null;
407
+ }>;
354
408
  /**
355
409
  * Ensure doctype section exists in HST store
356
410
  * @param slug - The doctype slug
@@ -1 +1 @@
1
- {"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,WAAW,CAAA;AACnC,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;GAGG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAyC;IACpE,OAAO,CAAC,mBAAmB,CAAC,CAA6B;IAEzD,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAE3B;;;;OAIG;gBACS,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;IAWhF;;;O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AS,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI;IAkCnE;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBrD;;;;;OAKG;IACG,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAetE;;;;;;;;;OASG;IACG,cAAc,CACnB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EAAE,GACd,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAWrE;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAOlD;;;OAGG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;CAevE"}
@@ -92,7 +92,7 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
92
92
  getSnapshot: () => OperationLogSnapshot;
93
93
  markIrreversible: (operationId: string, reason: string) => void;
94
94
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
95
- }, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
95
+ }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
96
96
  operations: import("vue").Ref<{
97
97
  id: string;
98
98
  type: import("..").HSTOperationType;
@@ -1,3 +1,4 @@
1
+ import type { DataClient } from '@stonecrop/schema';
1
2
  import type { SchemaTypes } from '@stonecrop/aform';
2
3
  import { List, Map } from 'immutable';
3
4
  import type { Component } from 'vue';
@@ -42,6 +43,22 @@ export type InstallOptions = {
42
43
  router?: Router;
43
44
  components?: Record<string, Component>;
44
45
  getMeta?: (routeContext: RouteContext) => DoctypeMeta | Promise<DoctypeMeta>;
46
+ /**
47
+ * Data client for fetching doctype metadata and records.
48
+ * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
49
+ * or implement DataClient for custom data sources.
50
+ *
51
+ * Can be set later via `useStonecropRegistry().setClient()` for deferred configuration.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { StonecropClient } from '@stonecrop/graphql-client'
56
+ *
57
+ * const client = new StonecropClient({ endpoint: '/graphql' })
58
+ * app.use(StonecropPlugin, { client })
59
+ * ```
60
+ */
61
+ client?: DataClient;
45
62
  /** Automatically run initialization callback after app mounting (default: false) */
46
63
  autoInitializeRouter?: boolean;
47
64
  /** Callback function called after plugin is ready and mounted */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE,OAAO,KAAK,WAAW,MAAM,YAAY,CAAA;AACzC,OAAO,QAAQ,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAA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MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IACtC,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAC5E;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,oFAAoF;IACpF,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,iEAAiE;IACjE,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxF,CAAA;AAGD,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import type { AnyStateNodeConfig } from 'xstate';
2
2
  import { Component } from 'vue';
3
3
  import { ComputedRef } from 'vue';
4
+ import type { DataClient } from '@stonecrop/schema';
4
5
  import { List } from 'immutable';
5
6
  import { Map as Map_2 } from 'immutable';
6
7
  import { Plugin as Plugin_2 } from 'vue';
@@ -125,6 +126,12 @@ export declare class DoctypeMeta {
125
126
  * @readonly
126
127
  */
127
128
  readonly doctype: string;
129
+ /**
130
+ * Alias for doctype (for DoctypeLike interface compatibility)
131
+ * @public
132
+ * @readonly
133
+ */
134
+ get name(): string;
128
135
  /**
129
136
  * The doctype schema
130
137
  * @public
@@ -645,6 +652,22 @@ export declare type InstallOptions = {
645
652
  router?: Router;
646
653
  components?: Record<string, Component>;
647
654
  getMeta?: (routeContext: RouteContext) => DoctypeMeta | Promise<DoctypeMeta>;
655
+ /**
656
+ * Data client for fetching doctype metadata and records.
657
+ * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
658
+ * or implement DataClient for custom data sources.
659
+ *
660
+ * Can be set later via `useStonecropRegistry().setClient()` for deferred configuration.
661
+ *
662
+ * @example
663
+ * ```ts
664
+ * import { StonecropClient } from '@stonecrop/graphql-client'
665
+ *
666
+ * const client = new StonecropClient({ endpoint: '/graphql' })
667
+ * app.use(StonecropPlugin, { client })
668
+ * ```
669
+ */
670
+ client?: DataClient;
648
671
  /** Automatically run initialization callback after app mounting (default: false) */
649
672
  autoInitializeRouter?: boolean;
650
673
  /** Callback function called after plugin is ready and mounted */
@@ -769,14 +792,19 @@ export declare interface _PathMatchResult {
769
792
  * ```ts
770
793
  * import { createApp } from 'vue'
771
794
  * import Stonecrop from '@stonecrop/stonecrop'
795
+ * import { StonecropClient } from '@stonecrop/graphql-client'
772
796
  * import router from './router'
773
797
  *
798
+ * const client = new StonecropClient({ endpoint: '/graphql' })
799
+ *
774
800
  * const app = createApp(App)
775
801
  * app.use(Stonecrop, {
776
802
  * router,
803
+ * client,
777
804
  * getMeta: async (routeContext) => {
778
805
  * // routeContext contains: { path, segments }
779
- * // fetch doctype meta from your API using the route context
806
+ * // use the client to fetch doctype meta
807
+ * return client.getMeta({ doctype: routeContext.segments[0] })
780
808
  * },
781
809
  * autoInitializeRouter: true,
782
810
  * onRouterInitialized: async (registry, stonecrop) => {
@@ -995,14 +1023,35 @@ export declare class Stonecrop {
995
1023
  private hstStore;
996
1024
  private _operationLogStore?;
997
1025
  private _operationLogConfig?;
1026
+ private _client?;
998
1027
  /** The registry instance containing all doctype definitions */
999
1028
  readonly registry: Registry;
1000
1029
  /**
1001
1030
  * Creates a new Stonecrop instance with HST integration
1002
1031
  * @param registry - The Registry instance containing doctype definitions
1003
1032
  * @param operationLogConfig - Optional configuration for the operation log
1033
+ * @param options - Options including the data client (can be set later via setClient)
1034
+ */
1035
+ constructor(registry: Registry, operationLogConfig?: Partial<OperationLogConfig>, options?: StonecropOptions);
1036
+ /**
1037
+ * Set the data client for fetching doctype metadata and records.
1038
+ * Use this for deferred configuration in Nuxt/Vue plugin setups.
1039
+ *
1040
+ * @param client - DataClient implementation (e.g., StonecropClient from \@stonecrop/graphql-client)
1041
+ *
1042
+ * @example
1043
+ * ```ts
1044
+ * const { setClient } = useStonecropRegistry()
1045
+ * const client = new StonecropClient({ endpoint: '/graphql' })
1046
+ * setClient(client)
1047
+ * ```
1048
+ */
1049
+ setClient(client: DataClient): void;
1050
+ /**
1051
+ * Get the current data client
1052
+ * @returns The DataClient instance or undefined if not set
1004
1053
  */
1005
- constructor(registry: Registry, operationLogConfig?: Partial<OperationLogConfig>);
1054
+ getClient(): DataClient | undefined;
1006
1055
  /**
1007
1056
  * Get the operation log store (lazy initialization)
1008
1057
  * @internal
@@ -1093,7 +1142,7 @@ export declare class Stonecrop {
1093
1142
  getSnapshot: () => OperationLogSnapshot;
1094
1143
  markIrreversible: (operationId: string, reason: string) => void;
1095
1144
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
1096
- }, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
1145
+ }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
1097
1146
  operations: Ref< {
1098
1147
  id: string;
1099
1148
  type: HSTOperationType;
@@ -1325,16 +1374,33 @@ export declare class Stonecrop {
1325
1374
  */
1326
1375
  runAction(doctype: DoctypeMeta, action: string, args?: any[]): void;
1327
1376
  /**
1328
- * Get records from server (maintains compatibility)
1377
+ * Get records from server using the configured data client.
1329
1378
  * @param doctype - The doctype
1379
+ * @throws Error if no data client has been configured
1330
1380
  */
1331
1381
  getRecords(doctype: DoctypeMeta): Promise<void>;
1332
1382
  /**
1333
- * Get single record from server (maintains compatibility)
1383
+ * Get single record from server using the configured data client.
1334
1384
  * @param doctype - The doctype
1335
1385
  * @param recordId - The record ID
1386
+ * @throws Error if no data client has been configured
1336
1387
  */
1337
1388
  getRecord(doctype: DoctypeMeta, recordId: string): Promise<void>;
1389
+ /**
1390
+ * Dispatch an action to the server via the configured data client.
1391
+ * All state changes flow through this single mutation endpoint.
1392
+ *
1393
+ * @param doctype - The doctype
1394
+ * @param action - Action name to execute (e.g., 'SUBMIT', 'APPROVE', 'save')
1395
+ * @param args - Action arguments (typically record ID and/or form data)
1396
+ * @returns Action result with success status, response data, and any error
1397
+ * @throws Error if no data client has been configured
1398
+ */
1399
+ dispatchAction(doctype: DoctypeMeta, action: string, args?: unknown[]): Promise<{
1400
+ success: boolean;
1401
+ data: unknown;
1402
+ error: string | null;
1403
+ }>;
1338
1404
  /**
1339
1405
  * Ensure doctype section exists in HST store
1340
1406
  * @param slug - The doctype slug
@@ -1367,6 +1433,22 @@ export declare class Stonecrop {
1367
1433
  getRecordState(doctype: string | DoctypeMeta, recordId: string): string;
1368
1434
  }
1369
1435
 
1436
+ /**
1437
+ * Options for constructing a Stonecrop instance directly.
1438
+ * When using the Vue plugin, pass these via `InstallOptions` instead.
1439
+ * @public
1440
+ */
1441
+ export declare interface StonecropOptions {
1442
+ /**
1443
+ * Data client for fetching doctype metadata and records.
1444
+ * Use \@stonecrop/graphql-client's StonecropClient for GraphQL backends,
1445
+ * or implement DataClient for custom data sources.
1446
+ *
1447
+ * Can be set later via `setClient()` for deferred configuration.
1448
+ */
1449
+ client?: DataClient;
1450
+ }
1451
+
1370
1452
  /**
1371
1453
  * Supported action types for XState transitions
1372
1454
  * Can be either a transition-specific function or a string reference
@@ -1633,7 +1715,7 @@ getOperationsFor: (doctype: string, recordId?: string) => HSTOperation[];
1633
1715
  getSnapshot: () => OperationLogSnapshot;
1634
1716
  markIrreversible: (operationId: string, reason: string) => void;
1635
1717
  logAction: (doctype: string, actionName: string, recordIds?: string[], result?: "success" | "failure" | "pending", error?: string) => string;
1636
- }, "operations" | "clientId" | "currentIndex" | "config">, Pick<{
1718
+ }, "operations" | "currentIndex" | "config" | "clientId">, Pick<{
1637
1719
  operations: Ref< {
1638
1720
  id: string;
1639
1721
  type: HSTOperationType;