@stonecrop/stonecrop 0.30.0 → 0.32.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 (121) hide show
  1. package/dist/stonecrop.js +3548 -2740
  2. package/dist/stonecrop.js.map +1 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/package.json +33 -27
  5. package/dist/src/client-action.d.ts +0 -31
  6. package/dist/src/client-action.d.ts.map +0 -1
  7. package/dist/src/client-action.js +0 -169
  8. package/dist/src/client-handler.d.ts +0 -43
  9. package/dist/src/client-handler.d.ts.map +0 -1
  10. package/dist/src/client-handler.js +0 -42
  11. package/dist/src/composables/lazy-link.d.ts +0 -25
  12. package/dist/src/composables/lazy-link.d.ts.map +0 -1
  13. package/dist/src/composables/lazy-link.js +0 -124
  14. package/dist/src/composables/operation-log.d.ts +0 -136
  15. package/dist/src/composables/operation-log.d.ts.map +0 -1
  16. package/dist/src/composables/operation-log.js +0 -224
  17. package/dist/src/composables/stonecrop.d.ts +0 -37
  18. package/dist/src/composables/stonecrop.d.ts.map +0 -1
  19. package/dist/src/composables/stonecrop.js +0 -433
  20. package/dist/src/doctype.d.ts +0 -243
  21. package/dist/src/doctype.d.ts.map +0 -1
  22. package/dist/src/doctype.js +0 -325
  23. package/dist/src/draft.d.ts +0 -35
  24. package/dist/src/draft.d.ts.map +0 -1
  25. package/dist/src/draft.js +0 -36
  26. package/dist/src/exceptions.d.ts +0 -14
  27. package/dist/src/exceptions.d.ts.map +0 -1
  28. package/dist/src/exceptions.js +0 -16
  29. package/dist/src/field-triggers.d.ts +0 -184
  30. package/dist/src/field-triggers.d.ts.map +0 -1
  31. package/dist/src/field-triggers.js +0 -577
  32. package/dist/src/index.d.ts +0 -25
  33. package/dist/src/index.d.ts.map +0 -1
  34. package/dist/src/index.js +0 -39
  35. package/dist/src/plugins/index.d.ts +0 -35
  36. package/dist/src/plugins/index.d.ts.map +0 -1
  37. package/dist/src/plugins/index.js +0 -98
  38. package/dist/src/registry.d.ts +0 -161
  39. package/dist/src/registry.d.ts.map +0 -1
  40. package/dist/src/registry.js +0 -384
  41. package/dist/src/schema-validator.d.ts +0 -78
  42. package/dist/src/schema-validator.d.ts.map +0 -1
  43. package/dist/src/schema-validator.js +0 -398
  44. package/dist/src/stonecrop.d.ts +0 -539
  45. package/dist/src/stonecrop.d.ts.map +0 -1
  46. package/dist/src/stonecrop.js +0 -610
  47. package/dist/src/stores/hst.d.ts +0 -92
  48. package/dist/src/stores/hst.d.ts.map +0 -1
  49. package/dist/src/stores/hst.js +0 -487
  50. package/dist/src/stores/index.d.ts +0 -9
  51. package/dist/src/stores/index.d.ts.map +0 -1
  52. package/dist/src/stores/index.js +0 -13
  53. package/dist/src/stores/operation-log.d.ts +0 -262
  54. package/dist/src/stores/operation-log.d.ts.map +0 -1
  55. package/dist/src/stores/operation-log.js +0 -571
  56. package/dist/src/stores/validation.d.ts +0 -83
  57. package/dist/src/stores/validation.d.ts.map +0 -1
  58. package/dist/src/stores/validation.js +0 -104
  59. package/dist/src/types/client-action.d.ts +0 -121
  60. package/dist/src/types/client-action.d.ts.map +0 -1
  61. package/dist/src/types/client-action.js +0 -0
  62. package/dist/src/types/composable.d.ts +0 -268
  63. package/dist/src/types/composable.d.ts.map +0 -1
  64. package/dist/src/types/composable.js +0 -0
  65. package/dist/src/types/doctype.d.ts +0 -34
  66. package/dist/src/types/doctype.d.ts.map +0 -1
  67. package/dist/src/types/doctype.js +0 -0
  68. package/dist/src/types/field-triggers.d.ts +0 -186
  69. package/dist/src/types/field-triggers.d.ts.map +0 -1
  70. package/dist/src/types/field-triggers.js +0 -4
  71. package/dist/src/types/hst.d.ts +0 -70
  72. package/dist/src/types/hst.d.ts.map +0 -1
  73. package/dist/src/types/hst.js +0 -0
  74. package/dist/src/types/index.d.ts +0 -11
  75. package/dist/src/types/index.d.ts.map +0 -1
  76. package/dist/src/types/index.js +0 -11
  77. package/dist/src/types/operation-log.d.ts +0 -163
  78. package/dist/src/types/operation-log.d.ts.map +0 -1
  79. package/dist/src/types/operation-log.js +0 -0
  80. package/dist/src/types/plugin.d.ts +0 -37
  81. package/dist/src/types/plugin.d.ts.map +0 -1
  82. package/dist/src/types/plugin.js +0 -0
  83. package/dist/src/types/registry.d.ts +0 -11
  84. package/dist/src/types/registry.d.ts.map +0 -1
  85. package/dist/src/types/registry.js +0 -0
  86. package/dist/src/types/schema-validator.d.ts +0 -66
  87. package/dist/src/types/schema-validator.d.ts.map +0 -1
  88. package/dist/src/types/schema-validator.js +0 -13
  89. package/dist/src/types/stonecrop.d.ts +0 -32
  90. package/dist/src/types/stonecrop.d.ts.map +0 -1
  91. package/dist/src/types/stonecrop.js +0 -0
  92. package/dist/stonecrop.tsbuildinfo +0 -1
  93. package/src/client-action.ts +0 -207
  94. package/src/client-handler.ts +0 -55
  95. package/src/composables/lazy-link.ts +0 -145
  96. package/src/composables/operation-log.ts +0 -257
  97. package/src/composables/stonecrop.ts +0 -556
  98. package/src/doctype.ts +0 -360
  99. package/src/draft.ts +0 -38
  100. package/src/exceptions.ts +0 -16
  101. package/src/field-triggers.ts +0 -686
  102. package/src/index.ts +0 -81
  103. package/src/plugins/index.ts +0 -113
  104. package/src/registry.ts +0 -433
  105. package/src/schema-validator.ts +0 -476
  106. package/src/stonecrop.ts +0 -721
  107. package/src/stores/hst.ts +0 -626
  108. package/src/stores/index.ts +0 -21
  109. package/src/stores/operation-log.ts +0 -675
  110. package/src/stores/validation.ts +0 -138
  111. package/src/types/client-action.ts +0 -121
  112. package/src/types/composable.ts +0 -288
  113. package/src/types/doctype.ts +0 -35
  114. package/src/types/field-triggers.ts +0 -201
  115. package/src/types/hst.ts +0 -77
  116. package/src/types/index.ts +0 -11
  117. package/src/types/operation-log.ts +0 -202
  118. package/src/types/plugin.ts +0 -38
  119. package/src/types/registry.ts +0 -10
  120. package/src/types/schema-validator.ts +0 -69
  121. package/src/types/stonecrop.ts +0 -33
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.11"
8
+ "packageVersion": "7.59.0"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,46 +1,57 @@
1
1
  {
2
2
  "name": "@stonecrop/stonecrop",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "description": "Schema-driven framework with XState workflows and HST state management",
5
+ "keywords": [
6
+ "framework",
7
+ "schema-driven",
8
+ "stonecrop",
9
+ "ui",
10
+ "vue"
11
+ ],
12
+ "homepage": "https://github.com/agritheory/stonecrop#readme",
5
13
  "bugs": {
6
14
  "url": "https://github.com/agritheory/stonecrop/issues"
7
15
  },
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/agritheory/stonecrop",
11
- "directory": "stonecrop"
12
- },
13
16
  "license": "MIT",
14
17
  "author": {
15
18
  "name": "Tyler Matteson",
16
19
  "email": "tyler@agritheory.com"
17
20
  },
18
- "sideEffects": false,
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/agritheory/stonecrop",
24
+ "directory": "stonecrop"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "!dist/src"
29
+ ],
19
30
  "type": "module",
31
+ "sideEffects": false,
32
+ "types": "./dist/stonecrop.d.ts",
20
33
  "exports": {
21
34
  ".": {
22
35
  "types": "./dist/stonecrop.d.ts",
23
36
  "import": "./dist/stonecrop.js"
24
37
  },
25
- "./types": "./dist/src/types/index.d.ts"
38
+ "./types": "./dist/stonecrop.d.ts",
39
+ "./package.json": "./package.json"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
26
43
  },
27
- "types": "./dist/stonecrop.d.ts",
28
- "files": [
29
- "dist/*",
30
- "src/*"
31
- ],
32
44
  "dependencies": {
33
45
  "@vueuse/core": "^14.2.1",
34
46
  "immutable": "^5.1.4",
35
47
  "pinia-shared-state": "^1.0.1",
36
48
  "xstate": "^5.25.0",
37
- "@stonecrop/aform": "0.30.0",
38
- "@stonecrop/atable": "0.30.0",
39
- "@stonecrop/schema": "0.30.0"
49
+ "@stonecrop/aform": "0.32.0",
50
+ "@stonecrop/atable": "0.32.0",
51
+ "@stonecrop/schema": "0.32.0"
40
52
  },
41
53
  "devDependencies": {
42
- "@microsoft/api-documenter": "^7.30.5",
43
- "@rushstack/heft": "^1.2.17",
54
+ "@microsoft/api-extractor": "^7.58.7",
44
55
  "@vitejs/plugin-vue": "^6.0.6",
45
56
  "@vitest/coverage-istanbul": "^4.1.5",
46
57
  "@vue/test-utils": "^2.4.10",
@@ -49,11 +60,10 @@
49
60
  "oxlint-tsgolint": "0.23.0",
50
61
  "pinia": "^3.0.4",
51
62
  "typescript": "^6.0.3",
52
- "vite": "^7.3.2",
63
+ "vite": "^8.2.2",
53
64
  "vitest": "^4.1.5",
54
65
  "vue": "^3.5.33",
55
- "vue-router": "^5.0.6",
56
- "stonecrop-rig": "0.7.0"
66
+ "vue-router": "^5.0.6"
57
67
  },
58
68
  "peerDependencies": {
59
69
  "pinia": "^3.0.4",
@@ -63,13 +73,9 @@
63
73
  "engines": {
64
74
  "node": ">=24.0.0"
65
75
  },
66
- "publishConfig": {
67
- "access": "public"
68
- },
69
76
  "scripts": {
70
- "_phase:build": "heft build --clean && vite build && rushx docs",
71
- "build": "heft build --clean && vite build && rushx docs",
72
- "docs": "bash ../common/scripts/run-docs.sh stonecrop",
77
+ "dev": "vite build --watch",
78
+ "docs": "bash ../tools/scripts/run-docs.sh stonecrop",
73
79
  "lint": "oxlint",
74
80
  "lint:fix": "oxlint --fix",
75
81
  "preview": "vite preview",
@@ -1,31 +0,0 @@
1
- import type { ActionEventPayload, UseClientActionOptions } from './types/client-action';
2
- /**
3
- * Shared executor for doctype action clicks. A host's Desktop `@action` handler delegates
4
- * here so every host runs the same logic from one definition:
5
- *
6
- * - If the clicked action carries a `clientHandler`, run it. The handler **owns
7
- * orchestration** — it calls `runAction` itself when it needs the server, navigates via
8
- * `router`, reads `record`, or queries `graphql`. It supersedes the default dispatch.
9
- * - Otherwise dispatch the action to its server `handler` (the pre-existing behavior),
10
- * so actions without a `clientHandler` are unchanged.
11
- *
12
- * `runAction` is the only blessed write: it dispatches **and** leaves the store consistent,
13
- * filing the returned record under the identity the *server* settled on and following the route
14
- * there when that differs from the one dispatched. For a created record those are never the same,
15
- * which is what makes hand-rolling this reliably wrong.
16
- *
17
- * The store write itself lives one layer down, in {@link Stonecrop.dispatchAction}, so a host that
18
- * never adopts this composable still cannot file a record under the wrong key. What stays here is
19
- * only what needs the *dispatched* id: dropping the stale key, and moving the route.
20
- *
21
- * Pass `buildArgs` to change the argument envelope your backend receives, `followRecord` to change
22
- * where a created record sends the user, and `onError` to route failures into your own
23
- * notification system. Identity resolution and HST keying are deliberately not configurable — see
24
- * {@link UseClientActionOptions}.
25
- *
26
- * @public
27
- */
28
- export declare function useClientAction(options?: UseClientActionOptions): {
29
- run: (payload: ActionEventPayload) => Promise<void>;
30
- };
31
- //# sourceMappingURL=client-action.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-action.d.ts","sourceRoot":"","sources":["../../src/client-action.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEX,kBAAkB,EAGlB,sBAAsB,EACtB,MAAM,uBAAuB,CAAA;AA0B9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B;mBA2EvC,kBAAkB,KAAG,OAAO,CAAC,IAAI,CAAC;EAkE9D"}
@@ -1,169 +0,0 @@
1
- import { useRouter } from 'vue-router';
2
- import { executeClientHandler } from './client-handler';
3
- import { useStonecrop } from './composables/stonecrop';
4
- import { isDraftRecordId } from './draft';
5
- /**
6
- * The identity a server response settled on, or `undefined` when it did not state one.
7
- *
8
- * Deliberately stricter than `getRecordId`: that falls back to `id` when the declared key is
9
- * absent, which here would let a handler returning a partial record (say `{ id, total }` for a
10
- * natural-keyed doctype) look like a rename and relocate the record to a key the adapter cannot
11
- * look up. An action whose result carries no identity at all — a `{ state }` outcome — leaves the
12
- * record exactly where it is.
13
- */
14
- function settledRecordId(doctype, record) {
15
- if (record[doctype.recordIdField] === undefined)
16
- return undefined;
17
- return doctype.getRecordId(record);
18
- }
19
- /**
20
- * Default failure surface: a blocking alert beats a silent `console.error` for a failed action
21
- * (e.g. a Save that the server refused), and there is no notification system in the framework to
22
- * route it into. A host with one passes `onError` and this is never called.
23
- */
24
- function notifyActionError(failure) {
25
- console.error('Action failed:', failure.message);
26
- if (typeof window !== 'undefined')
27
- window.alert(failure.message);
28
- }
29
- /**
30
- * Shared executor for doctype action clicks. A host's Desktop `@action` handler delegates
31
- * here so every host runs the same logic from one definition:
32
- *
33
- * - If the clicked action carries a `clientHandler`, run it. The handler **owns
34
- * orchestration** — it calls `runAction` itself when it needs the server, navigates via
35
- * `router`, reads `record`, or queries `graphql`. It supersedes the default dispatch.
36
- * - Otherwise dispatch the action to its server `handler` (the pre-existing behavior),
37
- * so actions without a `clientHandler` are unchanged.
38
- *
39
- * `runAction` is the only blessed write: it dispatches **and** leaves the store consistent,
40
- * filing the returned record under the identity the *server* settled on and following the route
41
- * there when that differs from the one dispatched. For a created record those are never the same,
42
- * which is what makes hand-rolling this reliably wrong.
43
- *
44
- * The store write itself lives one layer down, in {@link Stonecrop.dispatchAction}, so a host that
45
- * never adopts this composable still cannot file a record under the wrong key. What stays here is
46
- * only what needs the *dispatched* id: dropping the stale key, and moving the route.
47
- *
48
- * Pass `buildArgs` to change the argument envelope your backend receives, `followRecord` to change
49
- * where a created record sends the user, and `onError` to route failures into your own
50
- * notification system. Identity resolution and HST keying are deliberately not configurable — see
51
- * {@link UseClientActionOptions}.
52
- *
53
- * @public
54
- */
55
- export function useClientAction(options = {}) {
56
- const { stonecrop } = useStonecrop();
57
- // Called during setup so the injection is available; the registry fallback below covers a
58
- // caller outside an injection context, and a host that installed the plugin with `{ router }`.
59
- const injectedRouter = useRouter();
60
- const onError = options.onError ?? notifyActionError;
61
- const resolveRouter = () => injectedRouter ?? stonecrop.value?.registry.router;
62
- const buildArgs = options.buildArgs ??
63
- // Spreading `undefined` in an object literal adds nothing, so `extra` needs no fallback.
64
- (({ recordId, isDraft, data, extra }) => [{ ...(isDraft ? {} : { id: recordId }), data, ...extra }]);
65
- const followRecord = options.followRecord ??
66
- (async ({ doctype, recordId }) => {
67
- await resolveRouter()?.replace(`/${doctype}/${recordId}`);
68
- });
69
- /**
70
- * Dispatch `action` for the record and reconcile the store and the route with whichever
71
- * identity the result carries.
72
- */
73
- async function dispatchAndWriteback(doctypeSlug, recordId, data, action, extra) {
74
- const sc = stonecrop.value;
75
- if (!sc)
76
- return { success: false, data: null, error: 'Stonecrop is not initialized' };
77
- const doctype = sc.registry.getDoctype(doctypeSlug);
78
- if (!doctype)
79
- return { success: false, data: null, error: `Unknown doctype: ${doctypeSlug}` };
80
- // A draft omits the id, which the write path reads as "create". Sending the route segment
81
- // instead reaches the same branch by accident — via a lookup for a record named `new`.
82
- const isDraft = isDraftRecordId(recordId);
83
- const result = await sc.dispatchAction(doctype, action, buildArgs({ doctype: doctypeSlug, action, recordId, isDraft, data, extra }));
84
- if (result.success && result.data) {
85
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the action result payload is an opaque JSON scalar; every adapter returns the record as an object
86
- const record = result.data;
87
- const settledId = settledRecordId(doctype, record);
88
- if (settledId === undefined) {
89
- // The result states no identity of its own — a `{ state }` outcome. `dispatchAction`
90
- // could not file it, because only this layer knows which record was dispatched. A
91
- // draft has nowhere to put it: filing it under the route segment would leave a
92
- // record named `new` in the list view.
93
- if (!isDraft)
94
- sc.addRecord(doctypeSlug, recordId, record);
95
- return result;
96
- }
97
- // `dispatchAction` has already filed the record under `settledId`. Only the two steps
98
- // that need the dispatched id are left.
99
- if (recordId !== settledId) {
100
- // No-op for a draft, which was never in the store — `removeRecord` checks first.
101
- sc.removeRecord(doctypeSlug, recordId);
102
- await followRecord({ doctype: doctypeSlug, recordId: settledId, previousRecordId: recordId });
103
- }
104
- }
105
- return result;
106
- }
107
- /**
108
- * Handle a Desktop `@action` event: run the action's `clientHandler` if present,
109
- * else dispatch to the server handler.
110
- */
111
- async function run(payload) {
112
- const sc = stonecrop.value;
113
- if (!sc)
114
- return;
115
- const { name, doctype: doctypeSlug, recordId, data } = payload;
116
- const doctype = sc.registry.getDoctype(doctypeSlug);
117
- // `workflow` is a union (XState | WorkflowMeta); only WorkflowMeta carries an
118
- // `actions` map with `clientHandler`. An XState workflow has no `actions`, so the
119
- // lookup is undefined and we fall through to the server dispatch.
120
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- narrowing the workflow union to read the optional actions map
121
- const workflow = doctype?.workflow;
122
- const clientHandler = workflow?.actions?.[name]?.clientHandler;
123
- try {
124
- if (!clientHandler) {
125
- // No client handler — preserve the existing server-dispatch behavior.
126
- const result = await dispatchAndWriteback(doctypeSlug, recordId, data, name);
127
- if (!result.success) {
128
- onError({
129
- message: result.error ?? `Action "${name}" failed`,
130
- action: name,
131
- doctype: doctypeSlug,
132
- recordId,
133
- });
134
- }
135
- return;
136
- }
137
- // Client handler present — it owns orchestration. Assemble the capability map.
138
- // Prefer the live HST record; fall back to the form snapshot in the payload.
139
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- HSTNode.get returns any; a record node is always an object of field values
140
- const record = sc.getRecordById(doctypeSlug, recordId)?.get('') ?? data;
141
- const runAction = (action, extra) => dispatchAndWriteback(doctypeSlug, recordId, data, action, extra);
142
- // Read-only GraphQL escape hatch — no mutation is injected (a raw mutation would
143
- // bypass the dispatch and leave HST stale). `query` is the GraphQL transport's
144
- // method, not part of the abstract DataClient interface (a non-GraphQL client may
145
- // not support it), so probe for it structurally and reject if unsupported.
146
- const graphql = {
147
- query(query, variables) {
148
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- probing DataClient for the GraphQL transport's `query`, which the abstract interface deliberately does not declare
149
- const client = sc.getClient();
150
- if (!client?.query) {
151
- return Promise.reject(new Error('The configured data client does not support graphql.query'));
152
- }
153
- return client.query(query, variables);
154
- },
155
- };
156
- await executeClientHandler(clientHandler, { router: resolveRouter(), record, runAction, graphql });
157
- }
158
- catch (error) {
159
- onError({
160
- message: error instanceof Error ? error.message : String(error),
161
- action: name,
162
- doctype: doctypeSlug,
163
- recordId,
164
- cause: error,
165
- });
166
- }
167
- }
168
- return { run };
169
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * clientHandler execution
3
- * Pure executor for docbuilder-authored client handlers.
4
- * @packageDocumentation
5
- */
6
- /**
7
- * Named capabilities injected into a clientHandler body as function parameters.
8
- * The caller (the assembly composable) owns what each name resolves to — typically
9
- * `router`, `record`, `runAction`, and a read-only `graphql`.
10
- *
11
- * @public
12
- */
13
- export type ClientHandlerApi = Record<string, unknown>;
14
- /**
15
- * Execute a docbuilder-authored `clientHandler` body against an injected API map.
16
- *
17
- * `code` is a function *body* (statements), not a full function — authored in the
18
- * docbuilder code editor and stored on `ActionDefinition.clientHandler`. It is compiled
19
- * with the AsyncFunction constructor, so `await` works directly. Each key of `api`
20
- * becomes a parameter name bound to its value, so a handler can reference `router`,
21
- * `record`, `runAction`, etc. by name.
22
- *
23
- * This executor is deliberately concern-free: it performs no routing, dispatch, or HST
24
- * writes itself — the caller assembles `api`. The injected set is an *intent* contract,
25
- * not a sandbox (an AsyncFunction body can still reach `fetch`/`window`); enforcement of
26
- * what a handler may actually do lives server-side, not here.
27
- *
28
- * Errors are propagated to the caller as a rejected promise — syntax errors at compile
29
- * time and thrown errors / rejections at run time — so callers handle both uniformly.
30
- *
31
- * @param code - the clientHandler body, e.g. `"router.push('/users')"`
32
- * @param api - named capabilities injected as parameters (default: none)
33
- * @returns whatever the body returns (typically `void`)
34
- *
35
- * @example
36
- * ```ts
37
- * await executeClientHandler("await runAction('Assign', [record.id])", { runAction, record })
38
- * ```
39
- *
40
- * @public
41
- */
42
- export declare function executeClientHandler(code: string, api?: ClientHandlerApi): Promise<unknown>;
43
- //# sourceMappingURL=client-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-handler.d.ts","sourceRoot":"","sources":["../../src/client-handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAStD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,gBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC,CAIrG"}
@@ -1,42 +0,0 @@
1
- /**
2
- * clientHandler execution
3
- * Pure executor for docbuilder-authored client handlers.
4
- * @packageDocumentation
5
- */
6
- // AsyncFunction is not a global; reach it via an async function's constructor so authored
7
- // bodies can use top-level `await` without writing an async wrapper.
8
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- an async function's constructor is always the AsyncFunction constructor
9
- const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
10
- /**
11
- * Execute a docbuilder-authored `clientHandler` body against an injected API map.
12
- *
13
- * `code` is a function *body* (statements), not a full function — authored in the
14
- * docbuilder code editor and stored on `ActionDefinition.clientHandler`. It is compiled
15
- * with the AsyncFunction constructor, so `await` works directly. Each key of `api`
16
- * becomes a parameter name bound to its value, so a handler can reference `router`,
17
- * `record`, `runAction`, etc. by name.
18
- *
19
- * This executor is deliberately concern-free: it performs no routing, dispatch, or HST
20
- * writes itself — the caller assembles `api`. The injected set is an *intent* contract,
21
- * not a sandbox (an AsyncFunction body can still reach `fetch`/`window`); enforcement of
22
- * what a handler may actually do lives server-side, not here.
23
- *
24
- * Errors are propagated to the caller as a rejected promise — syntax errors at compile
25
- * time and thrown errors / rejections at run time — so callers handle both uniformly.
26
- *
27
- * @param code - the clientHandler body, e.g. `"router.push('/users')"`
28
- * @param api - named capabilities injected as parameters (default: none)
29
- * @returns whatever the body returns (typically `void`)
30
- *
31
- * @example
32
- * ```ts
33
- * await executeClientHandler("await runAction('Assign', [record.id])", { runAction, record })
34
- * ```
35
- *
36
- * @public
37
- */
38
- export async function executeClientHandler(code, api = {}) {
39
- const names = Object.keys(api);
40
- const fn = new AsyncFunction(...names, code);
41
- return fn(...names.map(name => api[name]));
42
- }
@@ -1,25 +0,0 @@
1
- import Doctype from '../doctype';
2
- import type { LazyLink } from '../types/composable';
3
- /**
4
- * Get the lazy link state for a specific link field on a doctype record.
5
- *
6
- * This composable provides reactive state for lazy-loaded links:
7
- * - `loading`: true while fetching
8
- * - `loaded`: true after successful fetch (permanent until reload)
9
- * - `error`: error state if any
10
- * - `reload()`: explicitly trigger a fetch
11
- * - `data`: computed from HST, or undefined if not loaded
12
- *
13
- * The reload() function respects the link's fetch strategy:
14
- * - `sync`: fetches via GraphQL query through fetchNestedData
15
- * - `lazy`: fetches via GraphQL query through fetchNestedData
16
- * - `custom`: invokes the serialized handler function directly
17
- *
18
- * @param doctype - The doctype instance
19
- * @param recordId - The record ID
20
- * @param linkFieldname - The link fieldname to load
21
- * @returns LazyLink with loading, loaded, error, reload, and data
22
- * @public
23
- */
24
- export declare function useLazyLink(doctype: Doctype, recordId: string, linkFieldname: string): LazyLink;
25
- //# sourceMappingURL=lazy-link.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lazy-link.d.ts","sourceRoot":"","sources":["../../../src/composables/lazy-link.ts"],"names":[],"mappings":"AAGA,OAAO,OAAO,MAAM,YAAY,CAAA;AAEhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,QAAQ,CAoH/F"}
@@ -1,124 +0,0 @@
1
- import { computed, inject, ref } from 'vue';
2
- import { Stonecrop } from '../stonecrop';
3
- /**
4
- * Get the lazy link state for a specific link field on a doctype record.
5
- *
6
- * This composable provides reactive state for lazy-loaded links:
7
- * - `loading`: true while fetching
8
- * - `loaded`: true after successful fetch (permanent until reload)
9
- * - `error`: error state if any
10
- * - `reload()`: explicitly trigger a fetch
11
- * - `data`: computed from HST, or undefined if not loaded
12
- *
13
- * The reload() function respects the link's fetch strategy:
14
- * - `sync`: fetches via GraphQL query through fetchNestedData
15
- * - `lazy`: fetches via GraphQL query through fetchNestedData
16
- * - `custom`: invokes the serialized handler function directly
17
- *
18
- * @param doctype - The doctype instance
19
- * @param recordId - The record ID
20
- * @param linkFieldname - The link fieldname to load
21
- * @returns LazyLink with loading, loaded, error, reload, and data
22
- * @public
23
- */
24
- export function useLazyLink(doctype, recordId, linkFieldname) {
25
- const stonecropInstance = inject('$stonecrop') || Stonecrop._root;
26
- if (!stonecropInstance) {
27
- throw new Error('Stonecrop instance not available. Ensure useStonecrop() has been called first.');
28
- }
29
- const loading = ref(false);
30
- const loaded = ref(false);
31
- const error = ref(null);
32
- const hstStore = stonecropInstance.getStore();
33
- /**
34
- * Build the HST path for a lazy link field
35
- */
36
- const getLinkPath = () => {
37
- const slug = doctype.slug || doctype.doctype;
38
- return `${slug}.${recordId}.${linkFieldname}`;
39
- };
40
- /**
41
- * Get the link declaration from the doctype schema
42
- */
43
- const getLinkDeclaration = () => {
44
- return doctype.links?.[linkFieldname]?.fetch;
45
- };
46
- /**
47
- * Invoke a custom fetch handler
48
- * The handler is a serialized function string that we execute via new Function()
49
- */
50
- const invokeCustomHandler = async (handler) => {
51
- try {
52
- // Create function from serialized string and invoke it
53
- // The function receives the stonecrop instance and path as parameters
54
- // oxlint-disable-next-line @typescript-eslint/no-implied-eval
55
- const fn = new Function('stonecrop', 'path', 'hst', `
56
- return (${handler})(stonecrop, path, hst)
57
- `);
58
- return await fn(stonecropInstance, getLinkPath(), hstStore);
59
- }
60
- catch (err) {
61
- throw new Error(`Custom handler failed: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
62
- }
63
- };
64
- /**
65
- * Fetch the link data using the appropriate strategy
66
- */
67
- const fetchLinkData = async () => {
68
- const linkFetch = getLinkDeclaration();
69
- const ancestorPath = `${doctype.slug || doctype.doctype}.${recordId}`;
70
- if (linkFetch?.method === 'custom') {
71
- // Ensure ancestor path exists before invoking custom handler
72
- if (!hstStore.has(ancestorPath)) {
73
- hstStore.set(ancestorPath, {}, 'system');
74
- }
75
- // Custom handler - invoke directly
76
- const result = await invokeCustomHandler(linkFetch.handler);
77
- // Store result in HST at the link path
78
- hstStore.set(getLinkPath(), result, 'system');
79
- }
80
- else {
81
- // sync or lazy (both use fetchNestedData but with different includeNested)
82
- // For lazy links, we still use fetchNestedData but only for this specific link
83
- await stonecropInstance.fetchNestedData(ancestorPath, doctype, recordId, { includeNested: [linkFieldname] });
84
- }
85
- };
86
- /**
87
- * Explicitly reload the lazy link data
88
- */
89
- const reload = async () => {
90
- if (loading.value)
91
- return;
92
- loading.value = true;
93
- error.value = null;
94
- try {
95
- await fetchLinkData();
96
- loaded.value = true;
97
- }
98
- catch (err) {
99
- error.value = err instanceof Error ? err : new Error(String(err));
100
- throw err;
101
- }
102
- finally {
103
- loading.value = false;
104
- }
105
- };
106
- /**
107
- * Computed property that returns the loaded data from HST
108
- */
109
- const data = computed(() => {
110
- if (!loaded.value)
111
- return undefined;
112
- return hstStore.get(getLinkPath());
113
- });
114
- return {
115
- // State
116
- loading,
117
- loaded,
118
- error,
119
- // Computed
120
- data,
121
- // Actions
122
- reload,
123
- };
124
- }