@stonecrop/stonecrop 0.10.1 → 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.
Files changed (39) hide show
  1. package/README.md +60 -72
  2. package/dist/composables/operation-log.js +7 -4
  3. package/dist/{composable.js → composables/stonecrop.js} +3 -4
  4. package/dist/doctype.js +35 -0
  5. package/dist/index.js +1 -1
  6. package/dist/plugins/index.js +8 -2
  7. package/dist/registry.js +9 -0
  8. package/dist/src/composables/operation-log.d.ts.map +1 -1
  9. package/dist/src/{composable.d.ts → composables/stonecrop.d.ts} +6 -6
  10. package/dist/src/composables/stonecrop.d.ts.map +1 -0
  11. package/dist/src/doctype.d.ts +25 -0
  12. package/dist/src/doctype.d.ts.map +1 -1
  13. package/dist/src/index.d.ts +4 -4
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/plugins/index.d.ts +6 -1
  16. package/dist/src/plugins/index.d.ts.map +1 -1
  17. package/dist/src/registry.d.ts +7 -0
  18. package/dist/src/registry.d.ts.map +1 -1
  19. package/dist/src/stonecrop.d.ts +72 -4
  20. package/dist/src/stonecrop.d.ts.map +1 -1
  21. package/dist/src/stores/operation-log.d.ts +1 -1
  22. package/dist/src/stores/operation-log.d.ts.map +1 -1
  23. package/dist/src/types/index.d.ts +17 -0
  24. package/dist/src/types/index.d.ts.map +1 -1
  25. package/dist/stonecrop.d.ts +128 -6
  26. package/dist/stonecrop.js +449 -337
  27. package/dist/stonecrop.js.map +1 -1
  28. package/dist/stores/operation-log.js +0 -3
  29. package/package.json +5 -4
  30. package/src/composables/operation-log.ts +7 -4
  31. package/src/{composable.ts → composables/stonecrop.ts} +8 -9
  32. package/src/doctype.ts +35 -0
  33. package/src/index.ts +4 -3
  34. package/src/plugins/index.ts +8 -2
  35. package/src/registry.ts +10 -0
  36. package/src/stonecrop.ts +127 -10
  37. package/src/stores/operation-log.ts +0 -3
  38. package/src/types/index.ts +17 -0
  39. package/dist/src/composable.d.ts.map +0 -1
package/README.md CHANGED
@@ -16,120 +16,108 @@ _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
23
  // Install the Stonecrop plugin
23
24
  app.use(Stonecrop, {
24
25
  router,
25
- components: {
26
- // Register custom components
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)
27
42
  },
28
- getMeta: async (doctype: string) => {
29
- // Fetch doctype metadata from your API
30
- return await fetchDoctypeMeta(doctype)
31
- }
32
43
  })
33
44
 
34
45
  app.mount('#app')
35
46
  ```
36
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
+
37
60
  ### Available Imports
38
61
 
39
62
  ```typescript
40
- // Default export - Vue plugin
41
- import Stonecrop from '@stonecrop/stonecrop'
63
+ // Default export - Vue plugin (install with app.use)
64
+ import StonecropPlugin from '@stonecrop/stonecrop'
42
65
 
43
66
  // Named exports - utilities and classes
44
67
  import {
45
- Stonecrop as StonecropClass, // Core class
46
- Registry, // Doctype registry
47
- useStonecrop, // Vue composable
48
- HST, // Hierarchical State Tree
49
- createHST, // HST factory
50
- DoctypeMeta // Doctype metadata class
68
+ Stonecrop, // Core orchestration class
69
+ Registry, // Doctype registry (singleton)
70
+ DoctypeMeta, // Doctype definition class
71
+ useStonecrop, // Vue composable — primary integration point
72
+ HST, // HST store class
73
+ createHST, // HST factory function
51
74
  } from '@stonecrop/stonecrop'
52
- ```### Using the Composable
75
+ ```
76
+
77
+ ### Using the Composable
53
78
 
54
79
  ```typescript
55
80
  import { useStonecrop } from '@stonecrop/stonecrop'
56
81
 
57
82
  export default {
58
83
  setup() {
59
- 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
+ })
60
92
 
61
93
  // Access HST store
62
94
  const store = stonecrop.value?.getStore()
63
95
 
64
- // Work with records
65
- const records = stonecrop.value?.records('doctype')
96
+ // Work with records directly
66
97
  const record = stonecrop.value?.getRecordById('doctype', recordId)
67
98
 
68
- return { stonecrop, records, record }
99
+ return { stonecrop, formData }
69
100
  }
70
101
  }
71
102
  ```
72
103
 
73
104
  ## Design
74
- A context will define schema, workflow and actions.
75
- - Schema describes the data model and layout of the document.
76
- - Workflows are the events that are registered on it and will specific to the context. An application might have 'login', 'onAppLoad', 'beforeRouteChange' and 'logout' events. A form/document context might define CRUD events. A table component, nested inside the form component might define its own events. I think we want Events to be FSM
77
- - Actions are an ordered set of functions, called by Workflow
78
- - [Router integration](https://pinia.vuejs.org/core-concepts/plugins.html#adding-new-external-properties). Stonecrop setup should expect a router or provide a default implementation
105
+ A Doctype defines schema, workflow, and actions.
106
+ - **Schema** describes the data model and field layout used by AForm for rendering.
107
+ - **Workflow** is an XState machine config expressing the states and transitions a record can go through.
108
+ - **Actions** are an ordered map of named functions, triggered by field changes (lowercase keys) or FSM transitions (UPPERCASE keys).
109
+ - **Registry** is the singleton catalog — all doctypes live here. Optional Vue Router integration allows automatic route creation per doctype.
110
+ - **Stem/`useStonecrop()`** is the Vue composable that wires components to HST and provides `formData`, `provideHSTPath`, `handleHSTChange`, and the operation log API.
79
111
 
80
- The context will be tree-shaped with a single root. Adding more nodes at the root level isn't a problem, but multiple roots would be disallowed.
112
+ The data model is **two operations**: get data and run actions. There is no CRUD. Records change state through FSM transitions; those transitions have side effects (persistence, notifications, etc.) defined in action handlers registered by the application. The framework provides the pipeline; applications define what actions exist and what they do.
81
113
 
82
- Example APIs and paths
114
+ HST path structure:
83
115
 
84
116
  ```
85
- app.schema <Record> // immutable
86
- app.workflow <FSM> // immutable
87
- app.actions <OrderedSet> // immutable
88
- app.value <Store> // mutable
89
- app.user // "tyler@agritheory.com"
90
- app.name // "My First Application"
91
- app.doctype.schema <Record> // `app.doctype` lazy loaded by Event in router?
92
- app.doctype.workflow <FSM>
93
- app.doctype.actions <OrderedSet>
94
- app.doctype.actions.value <Store>
95
- app.doctype.schema.field.workflow <FSM>
96
- app.doctype.schema.field.actions <OrderedSet>
97
- app.doctype.schema.field.value <Store>
98
- app.doctype.schema.field.value.field.value <Store> // a "sub-form"
99
- app.doctype.schema.field.value.field['a:1'].value <Store> // also a "sub-form", representing a table
117
+ doctype.recordId.fieldname // e.g. plan.abc-123.title
118
+ doctype.recordId.nested.field // deep nesting supported
100
119
  ```
101
120
 
102
- ## Base Classes
103
- The Doctype aligns with a row, record or object in a database. It is required to specify its schema, a Finite State Machine that informs its workflow and a set of functions that are triggered by that FSM's state transitions.
104
-
105
- Registry is a map of all Doctypes, lazy loaded and is responsible for routing within the application
106
-
107
- Stem is a composable singleton that wraps Registry and provides application level state management
108
-
109
-
110
- ## Story / Network diagram
111
- #### **Doctype | Record Story**
112
-
113
- - User is redirected after successful login
114
- - Base URL is configured at app level to serve a navigation page
115
- - User navigates to list view of `doctype`
116
- - Table component loads existing records of `doctype` from schema; record-level schema is added to registry with web worker
117
- - User navigates to specific record of `doctype`: schema is loaded from registry, data is loaded from server
118
- - User mutates data, changes are persisted to server / DB per FSM
119
-
120
- #### **App Level**
121
- - User is redirected after successful login
122
- - Base URL is configured at app level to serve a navigation page
123
- - User opens command palette from lower-right-docked tab interface
124
- - User can search for `doctype` by name or other server-enabled capabilities
125
-
126
- #### **Low Code**
127
- - User can define `doctype` and schema from UI
128
- - Fields are shown as rows in a table
129
- - FSM is shown as an editable diagram that validates itself
130
-
131
- ___
132
-
133
121
  # Hierarchical State Tree (HST) Interface Requirements
134
122
 
135
123
  ## Core Requirements
@@ -1,6 +1,6 @@
1
1
  import { useMagicKeys, whenever } from '@vueuse/core';
2
2
  import { storeToRefs } from 'pinia';
3
- import { inject } from 'vue';
3
+ import { getCurrentInstance, inject } from 'vue';
4
4
  import { useOperationLogStore } from '../stores/operation-log';
5
5
  /**
6
6
  * Composable for operation log management
@@ -28,9 +28,12 @@ import { useOperationLogStore } from '../stores/operation-log';
28
28
  * @public
29
29
  */
30
30
  export function useOperationLog(config) {
31
- // Try to use the injected store from the Stonecrop plugin first
32
- // This ensures we use the same Pinia instance as the app
33
- const injectedStore = inject('$operationLogStore', undefined);
31
+ // inject() is only valid inside a component setup() context. When this
32
+ // composable is called outside one (e.g. directly in test bodies or plain
33
+ // scripts) skip the injection entirely and fall back to the Pinia store.
34
+ const injectedStore = getCurrentInstance()
35
+ ? inject('$operationLogStore', undefined)
36
+ : undefined;
34
37
  const store = injectedStore || useOperationLogStore();
35
38
  // Apply configuration if provided
36
39
  if (config) {
@@ -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
@@ -48,6 +56,33 @@ export default class DoctypeMeta {
48
56
  this.actions = actions;
49
57
  this.component = component;
50
58
  }
59
+ /**
60
+ * Returns the transitions available from a given workflow state, derived from the
61
+ * doctype's XState workflow configuration.
62
+ *
63
+ * @param currentState - The state name to read transitions from
64
+ * @returns Array of transition descriptors with `name` and `targetState`
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const transitions = doctype.getAvailableTransitions('draft')
69
+ * // [{ name: 'SUBMIT', targetState: 'submitted' }]
70
+ * ```
71
+ *
72
+ * @public
73
+ */
74
+ getAvailableTransitions(currentState) {
75
+ const states = this.workflow?.states;
76
+ if (!states)
77
+ return [];
78
+ const stateConfig = states[currentState];
79
+ if (!stateConfig?.on)
80
+ return [];
81
+ return Object.entries(stateConfig.on).map(([name, target]) => ({
82
+ name,
83
+ targetState: typeof target === 'string' ? target : 'unknown',
84
+ }));
85
+ }
51
86
  /**
52
87
  * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
53
88
  * - It replaces camelCase and PascalCase with kebab-case strings
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
package/dist/registry.js CHANGED
@@ -235,4 +235,13 @@ export default class Registry {
235
235
  });
236
236
  return record;
237
237
  }
238
+ /**
239
+ * Get a registered doctype by slug
240
+ * @param slug - The doctype slug to look up
241
+ * @returns The DoctypeMeta instance if found, or undefined
242
+ * @public
243
+ */
244
+ getDoctype(slug) {
245
+ return this.registry[slug];
246
+ }
238
247
  }
@@ -1 +1 @@
1
- {"version":3,"file":"operation-log.d.ts","sourceRoot":"","sources":["../../../src/composables/operation-log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiB3C,OAAO,KAAG,OAAO;qBAOjB,OAAO,KAAG,OAAO;;gCAcN,MAAM,KAAG,MAAM,GAAG,IAAI;;;gCAqBtB,MAAM,aAAa,MAAM;;oCAgBrB,MAAM,UAAU,MAAM;yBAcnD,MAAM,cACH,MAAM,cACN,MAAM,EAAE,WACZ,SAAS,GAAG,SAAS,GAAG,SAAS,UACjC,MAAM,KACZ,MAAM;yBAQmB,OAAO,CAAC,kBAAkB,CAAC;EA2BvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,UAAO,QAqCrE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYzG"}
1
+ {"version":3,"file":"operation-log.d.ts","sourceRoot":"","sources":["../../../src/composables/operation-log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAoB3C,OAAO,KAAG,OAAO;qBAOjB,OAAO,KAAG,OAAO;;gCAcN,MAAM,KAAG,MAAM,GAAG,IAAI;;;gCAqBtB,MAAM,aAAa,MAAM;;oCAgBrB,MAAM,UAAU,MAAM;yBAcnD,MAAM,cACH,MAAM,cACN,MAAM,EAAE,WACZ,SAAS,GAAG,SAAS,GAAG,SAAS,UACjC,MAAM,KACZ,MAAM;yBAQmB,OAAO,CAAC,kBAAkB,CAAC;EA2BvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,UAAO,QAqCrE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYzG"}
@@ -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;AAE7D;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAA;IAC/B,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACzB,aAAa,EAAE,WAAW,CAAC;QAC1B,OAAO,EAAE,OAAO,CAAA;QAChB,OAAO,EAAE,OAAO,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,SAAS,EAAE,MAAM,CAAA;Q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,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
@@ -44,6 +50,25 @@ export default class DoctypeMeta {
44
50
  * @param component - Optional Vue component for rendering the doctype
45
51
  */
46
52
  constructor(doctype: string, schema: ImmutableDoctype['schema'], workflow: ImmutableDoctype['workflow'], actions: ImmutableDoctype['actions'], component?: Component);
53
+ /**
54
+ * Returns the transitions available from a given workflow state, derived from the
55
+ * doctype's XState workflow configuration.
56
+ *
57
+ * @param currentState - The state name to read transitions from
58
+ * @returns Array of transition descriptors with `name` and `targetState`
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const transitions = doctype.getAvailableTransitions('draft')
63
+ * // [{ name: 'SUBMIT', targetState: 'submitted' }]
64
+ * ```
65
+ *
66
+ * @public
67
+ */
68
+ getAvailableTransitions(currentState: string): Array<{
69
+ name: string;
70
+ targetState: string;
71
+ }>;
47
72
  /**
48
73
  * Converts the registered doctype string to a slug (kebab-case). The following conversions are made:
49
74
  * - It replaces camelCase and PascalCase with kebab-case strings
@@ -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,gBAA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gB,CAAC,QAAQ,CAAC,EAClC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,EACtC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,EACpC,SAAS,CAAC,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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,SAAS,EAAE,MAAM,aAAa,CAAA;AAC9D,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,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"}
@@ -103,5 +103,12 @@ export default class Registry {
103
103
  * @public
104
104
  */
105
105
  initializeRecord(schema: SchemaTypes[]): Record<string, any>;
106
+ /**
107
+ * Get a registered doctype by slug
108
+ * @param slug - The doctype slug to look up
109
+ * @returns The DoctypeMeta instance if found, or undefined
110
+ * @public
111
+ */
112
+ getDoctype(slug: string): DoctypeMeta | undefined;
106
113
  }
107
114
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,OAAO,WAAW,MAAM,WAAW,CA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;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;IAErB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAE9C;;;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,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAWzG;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAE5E;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE,WAAW;IAsB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,WAAW,EAAE;IAwF1E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IA4C5D;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;CAgBjD"}
@@ -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)
38
+ */
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
+ * ```
20
52
  */
21
- constructor(registry: Registry, operationLogConfig?: Partial<OperationLogConfig>);
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
@@ -367,5 +421,19 @@ export declare class Stonecrop {
367
421
  * @returns Root HST node
368
422
  */
369
423
  getStore(): HSTNode;
424
+ /**
425
+ * Determine the current workflow state for a record.
426
+ *
427
+ * Reads the record's `status` field from the HST store. If the field is absent or
428
+ * empty the doctype's declared `workflow.initial` state is used as the fallback,
429
+ * giving callers a reliable state name without having to duplicate that logic.
430
+ *
431
+ * @param doctype - The doctype slug or DoctypeMeta instance
432
+ * @param recordId - The record identifier
433
+ * @returns The current state name, or an empty string if the doctype has no workflow
434
+ *
435
+ * @public
436
+ */
437
+ getRecordState(doctype: string | DoctypeMeta, recordId: string): string;
370
438
  }
371
439
  //# sourceMappingURL=stonecrop.d.ts.map