@w6w/embed 0.2.1 → 0.2.19

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 (185) hide show
  1. package/README.md +22 -5
  2. package/dist/ConfirmModal-Pv2-A_3U.js +186 -0
  3. package/dist/ConfirmModal-Pv2-A_3U.js.map +1 -0
  4. package/dist/{CreateFunctionModal-DRsFx-FB.js → CreateFunctionModal-DScxp_LN.js} +25 -25
  5. package/dist/{CreateFunctionModal-DRsFx-FB.js.map → CreateFunctionModal-DScxp_LN.js.map} +1 -1
  6. package/dist/{DocumentFormModal-BExK1V-B.js → DocumentFormModal-Br4s8wmi.js} +5 -5
  7. package/dist/{DocumentFormModal-BExK1V-B.js.map → DocumentFormModal-Br4s8wmi.js.map} +1 -1
  8. package/dist/ImportSpecModal-Cpzp8ndt.js +251 -0
  9. package/dist/ImportSpecModal-Cpzp8ndt.js.map +1 -0
  10. package/dist/ModelRoutesManager-1Ac5wcas.js +345 -0
  11. package/dist/ModelRoutesManager-1Ac5wcas.js.map +1 -0
  12. package/dist/WorkflowEditor-CmhXHRxi.js +1109 -0
  13. package/dist/WorkflowEditor-CmhXHRxi.js.map +1 -0
  14. package/dist/apps-ItBvnWX3.js +92 -0
  15. package/dist/apps-ItBvnWX3.js.map +1 -0
  16. package/dist/{callables-3mFrMVG_.js → callables-tOlflvbl.js} +11 -11
  17. package/dist/{callables-3mFrMVG_.js.map → callables-tOlflvbl.js.map} +1 -1
  18. package/dist/chrome/ConfirmModal.d.ts +4 -1
  19. package/dist/chrome/DangerZone.d.ts +4 -3
  20. package/dist/chrome/ExecutionProfileHeader.d.ts +3 -3
  21. package/dist/chrome/JsonToggle.d.ts +29 -20
  22. package/dist/chrome/Modal.d.ts +3 -1
  23. package/dist/chrome/RightRail.d.ts +6 -1
  24. package/dist/chrome/VersionHistoryModal.d.ts +2 -0
  25. package/dist/chrome/index.d.ts +1 -0
  26. package/dist/chrome/workspace.d.ts +36 -1
  27. package/dist/coerce-input-DFJ4n_wc.js +150 -0
  28. package/dist/coerce-input-DFJ4n_wc.js.map +1 -0
  29. package/dist/connections-CzsCyIxY.js +119 -0
  30. package/dist/connections-CzsCyIxY.js.map +1 -0
  31. package/dist/credentials-Cn92LGhJ.js +171 -0
  32. package/dist/credentials-Cn92LGhJ.js.map +1 -0
  33. package/dist/data-stores-UeQvwVCa.js +170 -0
  34. package/dist/data-stores-UeQvwVCa.js.map +1 -0
  35. package/dist/document-sources-DNmBojx6.js +169 -0
  36. package/dist/document-sources-DNmBojx6.js.map +1 -0
  37. package/dist/draft/use-workflow-draft.d.ts +2 -0
  38. package/dist/draft.mjs +2 -2
  39. package/dist/editor/BindingBanner.d.ts +13 -0
  40. package/dist/editor/CallableEditorFrame.d.ts +7 -0
  41. package/dist/editor/EndpointCards.d.ts +4 -1
  42. package/dist/editor/PublishControl.d.ts +19 -0
  43. package/dist/editor/PublishTooltip.d.ts +7 -0
  44. package/dist/editor/SetupIncompleteBanner.d.ts +12 -0
  45. package/dist/editor/StartingStateModal.d.ts +14 -0
  46. package/dist/editor/TargetSelector.d.ts +15 -0
  47. package/dist/editor/TargetSelector.types.d.ts +2 -0
  48. package/dist/editor/WorkflowSettingsModal.d.ts +6 -1
  49. package/dist/editor/WorkflowVariablesEditor.d.ts +6 -0
  50. package/dist/editor/definition.d.ts +6 -0
  51. package/dist/editor/json-apply.d.ts +29 -0
  52. package/dist/editor/step-problems-feed.d.ts +5 -0
  53. package/dist/editor/types.d.ts +2 -2
  54. package/dist/editor-apps-DkkC7wOQ.js +152 -0
  55. package/dist/editor-apps-DkkC7wOQ.js.map +1 -0
  56. package/dist/editor-tools-BR27RGto.js +1683 -0
  57. package/dist/editor-tools-BR27RGto.js.map +1 -0
  58. package/dist/editor.mjs +1 -1
  59. package/dist/editors.mjs +855 -650
  60. package/dist/editors.mjs.map +1 -1
  61. package/dist/{endpoints-B2ynbZo-.js → endpoints-DSRo1Lc5.js} +113 -107
  62. package/dist/endpoints-DSRo1Lc5.js.map +1 -0
  63. package/dist/fields-DvS8XZFc.js +21 -0
  64. package/dist/fields-DvS8XZFc.js.map +1 -0
  65. package/dist/forms/ModelBudgetsManager.d.ts +9 -0
  66. package/dist/forms/ModelRoutesManager.d.ts +14 -0
  67. package/dist/forms.d.ts +4 -0
  68. package/dist/forms.mjs +611 -212
  69. package/dist/forms.mjs.map +1 -1
  70. package/dist/{rail-settings-XYGToh00.js → import-bindings-EUtxZ9Ti.js} +90 -24
  71. package/dist/import-bindings-EUtxZ9Ti.js.map +1 -0
  72. package/dist/index.mjs +154 -117
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/lib/binding-problems.d.ts +42 -0
  75. package/dist/lib/code-rail.d.ts +4 -2
  76. package/dist/lib/history-query.d.ts +45 -0
  77. package/dist/lib/import-bindings.d.ts +89 -0
  78. package/dist/lib/index.d.ts +4 -0
  79. package/dist/lib/invoke-error.d.ts +1 -0
  80. package/dist/lib/rail-settings.d.ts +1 -1
  81. package/dist/lib/sdk-snippets.d.ts +1 -1
  82. package/dist/lib/setup-incomplete.d.ts +22 -0
  83. package/dist/lib/starting-data.d.ts +31 -0
  84. package/dist/lib/state-panel.d.ts +29 -0
  85. package/dist/lib/target-fields.d.ts +11 -15
  86. package/dist/lib/trigger-preview.d.ts +1 -0
  87. package/dist/lib/workflow-live-run.d.ts +93 -8
  88. package/dist/lib/workflow-nodes.d.ts +5 -0
  89. package/dist/lib/workflow-validity.d.ts +65 -16
  90. package/dist/lib/workflow-variables.d.ts +1 -1
  91. package/dist/lib/workflow-version.d.ts +2 -0
  92. package/dist/lib.mjs +86 -69
  93. package/dist/lists/ConnectionDependents.d.ts +31 -0
  94. package/dist/lists/ConnectionDetail.d.ts +4 -1
  95. package/dist/lists/ConnectionList.d.ts +4 -1
  96. package/dist/lists/CredentialDetail.d.ts +15 -0
  97. package/dist/lists/CredentialList.d.ts +14 -0
  98. package/dist/lists/DataStoreList.d.ts +17 -0
  99. package/dist/lists/DataStoreView.d.ts +19 -0
  100. package/dist/lists/Logs.d.ts +19 -0
  101. package/dist/lists/ModelCatalog.d.ts +12 -0
  102. package/dist/lists/ModelUsage.d.ts +12 -0
  103. package/dist/lists.d.ts +14 -0
  104. package/dist/lists.mjs +1766 -609
  105. package/dist/lists.mjs.map +1 -1
  106. package/dist/models-bAayQPJ_.js +270 -0
  107. package/dist/models-bAayQPJ_.js.map +1 -0
  108. package/dist/{project-context-BiCjv_E3.js → project-context-Tvp-La7A.js} +3 -3
  109. package/dist/{project-context-BiCjv_E3.js.map → project-context-Tvp-La7A.js.map} +1 -1
  110. package/dist/rail/ConnectionsTool.d.ts +2 -0
  111. package/dist/rail/HistoryTool.d.ts +2 -0
  112. package/dist/rail/StartingStateTool.d.ts +2 -0
  113. package/dist/rail/settings-sections.d.ts +4 -1
  114. package/dist/rail.mjs +4 -4
  115. package/dist/repos/agents-studio-agents.d.ts +52 -0
  116. package/dist/repos/agents-studio-assets.d.ts +68 -0
  117. package/dist/repos/connections.d.ts +30 -12
  118. package/dist/repos/constants.d.ts +12 -0
  119. package/dist/repos/credentials.d.ts +83 -0
  120. package/dist/repos/data-stores.d.ts +84 -0
  121. package/dist/repos/endpoints.d.ts +9 -3
  122. package/dist/repos/fields.d.ts +34 -0
  123. package/dist/repos/functions.d.ts +7 -5
  124. package/dist/repos/history.d.ts +9 -0
  125. package/dist/repos/index.d.ts +7 -0
  126. package/dist/repos/models.d.ts +289 -0
  127. package/dist/repos/spec-export.d.ts +3 -3
  128. package/dist/repos/spec-import.d.ts +30 -1
  129. package/dist/repos/step-tests.d.ts +2 -0
  130. package/dist/repos/webhook-listen.d.ts +35 -0
  131. package/dist/repos/workflows.d.ts +105 -2
  132. package/dist/repos.mjs +655 -176
  133. package/dist/repos.mjs.map +1 -1
  134. package/dist/setup-incomplete-BHs3Lpfy.js +199 -0
  135. package/dist/setup-incomplete-BHs3Lpfy.js.map +1 -0
  136. package/dist/{slug-C4ktDPdy.js → slug-BVdgiP_L.js} +64 -60
  137. package/dist/slug-BVdgiP_L.js.map +1 -0
  138. package/dist/{spec-export-Cf3VQSQS.js → spec-export-DGy5ijps.js} +73 -60
  139. package/dist/spec-export-DGy5ijps.js.map +1 -0
  140. package/dist/spec-import-SWOonsNr.js +116 -0
  141. package/dist/spec-import-SWOonsNr.js.map +1 -0
  142. package/dist/{step-tests-CivICmTq.js → step-tests-B4E4W3ly.js} +8 -7
  143. package/dist/step-tests-B4E4W3ly.js.map +1 -0
  144. package/dist/theme-context-E2ZhlXDX.js +6 -0
  145. package/dist/theme-context-E2ZhlXDX.js.map +1 -0
  146. package/dist/theme-context.d.ts +2 -0
  147. package/dist/{use-callable-draft-zHLpcr-b.js → use-callable-draft-DCauHt5o.js} +23 -23
  148. package/dist/{use-callable-draft-zHLpcr-b.js.map → use-callable-draft-DCauHt5o.js.map} +1 -1
  149. package/dist/use-workflow-draft-l3P5KZzw.js +338 -0
  150. package/dist/use-workflow-draft-l3P5KZzw.js.map +1 -0
  151. package/dist/{workflow-blank-DyL3_RUA.js → workflow-blank-DFpGObrn.js} +6 -6
  152. package/dist/{workflow-blank-DyL3_RUA.js.map → workflow-blank-DFpGObrn.js.map} +1 -1
  153. package/dist/workflows-BZN4Hyz1.js +623 -0
  154. package/dist/workflows-BZN4Hyz1.js.map +1 -0
  155. package/package.json +3 -2
  156. package/src/styles.css +155 -7
  157. package/dist/ConfirmModal-RLbZT5_k.js +0 -181
  158. package/dist/ConfirmModal-RLbZT5_k.js.map +0 -1
  159. package/dist/ImportSpecModal-BDQIf6rg.js +0 -136
  160. package/dist/ImportSpecModal-BDQIf6rg.js.map +0 -1
  161. package/dist/WorkflowEditor-DlbVv6Fs.js +0 -854
  162. package/dist/WorkflowEditor-DlbVv6Fs.js.map +0 -1
  163. package/dist/apps-1FNUwbGv.js +0 -77
  164. package/dist/apps-1FNUwbGv.js.map +0 -1
  165. package/dist/coerce-input-BicYr7nc.js +0 -139
  166. package/dist/coerce-input-BicYr7nc.js.map +0 -1
  167. package/dist/connections-CjjYeRqb.js +0 -78
  168. package/dist/connections-CjjYeRqb.js.map +0 -1
  169. package/dist/document-sources-C0grrtdq.js +0 -86
  170. package/dist/document-sources-C0grrtdq.js.map +0 -1
  171. package/dist/editor-apps-BdenSV1o.js +0 -95
  172. package/dist/editor-apps-BdenSV1o.js.map +0 -1
  173. package/dist/editor-tools-RxmY5iyi.js +0 -1279
  174. package/dist/editor-tools-RxmY5iyi.js.map +0 -1
  175. package/dist/endpoints-B2ynbZo-.js.map +0 -1
  176. package/dist/rail-settings-XYGToh00.js.map +0 -1
  177. package/dist/slug-C4ktDPdy.js.map +0 -1
  178. package/dist/spec-export-Cf3VQSQS.js.map +0 -1
  179. package/dist/spec-import-CjmxyZDR.js +0 -465
  180. package/dist/spec-import-CjmxyZDR.js.map +0 -1
  181. package/dist/step-tests-CivICmTq.js.map +0 -1
  182. package/dist/trigger-preview-VPkrryDl.js +0 -120
  183. package/dist/trigger-preview-VPkrryDl.js.map +0 -1
  184. package/dist/use-workflow-draft-DzAyUeA6.js +0 -316
  185. package/dist/use-workflow-draft-DzAyUeA6.js.map +0 -1
@@ -0,0 +1,171 @@
1
+ import { useQueryClient as c, useMutation as i, useQuery as l } from "@tanstack/react-query";
2
+ import { u as a } from "./client-context-CX61Bgw-.js";
3
+ import { c as w } from "./connections-CzsCyIxY.js";
4
+ const u = ["credentials"], d = (e) => ["credential", e], S = (e) => ["credential-dependents", e];
5
+ function y(e, t) {
6
+ e.invalidateQueries({ queryKey: u }), e.invalidateQueries({ queryKey: d(t) }), e.invalidateQueries({ queryKey: w }), e.invalidateQueries({ queryKey: ["connection"] }), e.invalidateQueries({ queryKey: ["app-connections"] });
7
+ }
8
+ function C(e, t) {
9
+ return e.console.credentials.list(t);
10
+ }
11
+ function f(e, t) {
12
+ return e.console.credentials.get(t);
13
+ }
14
+ function p(e, t) {
15
+ return e.console.credentials.create(t);
16
+ }
17
+ function v(e, t, n) {
18
+ return e.console.credentials.update(t, n);
19
+ }
20
+ function q(e, t, n) {
21
+ return e.console.credentials.rotate(t, n);
22
+ }
23
+ function m(e, t, n) {
24
+ return n === "disabled" ? e.console.credentials.disable(t) : e.console.credentials.enable(t);
25
+ }
26
+ function K(e, t) {
27
+ return e.console.credentials.test(t);
28
+ }
29
+ function Q(e, t) {
30
+ return e.console.credentials.dependents(t);
31
+ }
32
+ async function M(e, t) {
33
+ var n, r;
34
+ try {
35
+ return await e.console.credentials.delete(t), { ok: !0 };
36
+ } catch (s) {
37
+ const o = s;
38
+ if ((o == null ? void 0 : o.status) === 409 && o.code === "credential_in_use")
39
+ return {
40
+ ok: !1,
41
+ dependents: { connections: ((r = (n = (o.raw ?? {}).error) == null ? void 0 : n.dependents) == null ? void 0 : r.connections) ?? [] }
42
+ };
43
+ throw s;
44
+ }
45
+ }
46
+ function E(e) {
47
+ const t = a();
48
+ return l({
49
+ queryKey: e ? [...u, e] : u,
50
+ queryFn: () => C(t, e)
51
+ });
52
+ }
53
+ function T(e) {
54
+ const t = a();
55
+ return l({ queryKey: d(e), queryFn: () => f(t, e) });
56
+ }
57
+ function _(e, t = !0) {
58
+ const n = a();
59
+ return l({
60
+ queryKey: S(e),
61
+ queryFn: () => Q(n, e),
62
+ enabled: t,
63
+ retry: !1
64
+ });
65
+ }
66
+ function j() {
67
+ const e = a(), t = c();
68
+ return i({
69
+ mutationFn: (n) => p(e, n),
70
+ onSuccess: () => t.invalidateQueries({ queryKey: u })
71
+ });
72
+ }
73
+ function x(e) {
74
+ const t = a(), n = c();
75
+ return i({
76
+ mutationFn: (r) => v(t, e, r),
77
+ onSuccess: () => {
78
+ n.invalidateQueries({ queryKey: u }), n.invalidateQueries({ queryKey: d(e) });
79
+ }
80
+ });
81
+ }
82
+ function A(e) {
83
+ const t = a(), n = c();
84
+ return i({
85
+ mutationFn: (r) => q(t, e, r),
86
+ onSuccess: () => y(n, e)
87
+ });
88
+ }
89
+ function R(e) {
90
+ const t = a(), n = c();
91
+ return i({
92
+ mutationFn: (r) => m(t, e, r),
93
+ onSuccess: () => y(n, e)
94
+ });
95
+ }
96
+ function U(e) {
97
+ const t = a();
98
+ return i({
99
+ mutationFn: () => K(t, e)
100
+ });
101
+ }
102
+ function H() {
103
+ const e = a(), t = c();
104
+ return i({
105
+ mutationFn: (n) => M(e, n),
106
+ onSuccess: (n, r) => {
107
+ n.ok && y(t, r);
108
+ }
109
+ });
110
+ }
111
+ const F = [
112
+ "listCredentials",
113
+ "createCredential",
114
+ "getCredential",
115
+ "rotateCredential",
116
+ "setCredentialStatus",
117
+ "testCredential",
118
+ "credentialDependents",
119
+ "deleteCredential"
120
+ ];
121
+ function h(e) {
122
+ return {
123
+ listCredentials: (t) => C(e, t),
124
+ createCredential: (t) => p(e, t),
125
+ getCredential: (t) => f(e, t),
126
+ rotateCredential: (t, n) => q(e, t, n),
127
+ setCredentialStatus: (t, n) => m(e, t, n),
128
+ testCredential: (t) => K(e, t),
129
+ credentialDependents: (t) => Q(e, t),
130
+ deleteCredential: async (t) => {
131
+ try {
132
+ await e.console.credentials.delete(t);
133
+ } catch (n) {
134
+ throw n && typeof n == "object" && "raw" in n && (n.body = n.raw), n;
135
+ }
136
+ }
137
+ };
138
+ }
139
+ function I(e, t) {
140
+ const n = h(t), r = e;
141
+ for (const s of F)
142
+ typeof r[s] != "function" && (r[s] = n[s]);
143
+ return e;
144
+ }
145
+ export {
146
+ S as a,
147
+ d as b,
148
+ p as c,
149
+ h as d,
150
+ u as e,
151
+ M as f,
152
+ f as g,
153
+ Q as h,
154
+ y as i,
155
+ j,
156
+ _ as k,
157
+ C as l,
158
+ T as m,
159
+ E as n,
160
+ H as o,
161
+ A as p,
162
+ R as q,
163
+ q as r,
164
+ m as s,
165
+ K as t,
166
+ v as u,
167
+ U as v,
168
+ x as w,
169
+ I as x
170
+ };
171
+ //# sourceMappingURL=credentials-Cn92LGhJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials-Cn92LGhJ.js","sources":["../src/repos/credentials.ts"],"sourcesContent":["/**\n * The stored-credentials repo — list, single, create, rename, rotate, enable/disable, test,\n * dependents and delete, over `client.console.credentials.*`. Mirrors `connections.ts`.\n *\n * `invalidateAfterCredentialWrite` is the one place that knows a credential write can change what\n * a connection shows (its status, its untested flag), so it also stales every cached connection.\n * `credentialUiMethods` / `withCredentialMethods` are how both hosts (`W6WEmbedProvider` and\n * Studio's facade) supply the eight optional `W6WApi` credential methods from one implementation.\n */\nimport { type QueryClient, useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type { W6WClient } from \"@w6w/sdk\";\nimport type {\n CredentialDependents,\n CredentialListFilter,\n CredentialSummary,\n CredentialTestResult,\n} from \"@w6w/sdk/console\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\nimport { connectionsKey } from \"./connections.ts\";\n\nexport type {\n CredentialDependents,\n CredentialListFilter,\n CredentialSummary,\n CredentialTestResult,\n} from \"@w6w/sdk/console\";\n\n// ── keys ──────────────────────────────────────────────────────────────\n\nexport const credentialsKey = [\"credentials\"] as const;\nexport const credentialKey = (id: string) => [\"credential\", id] as const;\nexport const credentialDependentsKey = (id: string) => [\"credential-dependents\", id] as const;\n\n/**\n * A credential write (rotate, enable/disable, delete) changes what every connection on it\n * reports, so the credential keys AND every cached connection (single and per-app) go stale.\n */\nexport function invalidateAfterCredentialWrite(qc: QueryClient, id: string): void {\n qc.invalidateQueries({ queryKey: credentialsKey });\n qc.invalidateQueries({ queryKey: credentialKey(id) });\n qc.invalidateQueries({ queryKey: connectionsKey });\n qc.invalidateQueries({ queryKey: [\"connection\"] });\n qc.invalidateQueries({ queryKey: [\"app-connections\"] });\n}\n\n// ── fetchers ──────────────────────────────────────────────────────────\n\nexport function listCredentials(\n client: W6WClient,\n filter?: CredentialListFilter,\n): Promise<CredentialSummary[]> {\n return client.console.credentials.list(filter);\n}\n\nexport function getCredential(client: W6WClient, id: string): Promise<CredentialSummary> {\n return client.console.credentials.get(id);\n}\n\nexport function createCredential(\n client: W6WClient,\n body: { name: string; contract: string; source: Record<string, unknown> },\n): Promise<CredentialSummary> {\n return client.console.credentials.create(body);\n}\n\n/** Rename. */\nexport function updateCredential(\n client: W6WClient,\n id: string,\n body: { name: string },\n): Promise<CredentialSummary> {\n return client.console.credentials.update(id, body);\n}\n\nexport function rotateCredential(\n client: W6WClient,\n id: string,\n body: { source: Record<string, unknown> },\n): Promise<CredentialSummary> {\n return client.console.credentials.rotate(id, body);\n}\n\nexport function setCredentialStatus(\n client: W6WClient,\n id: string,\n status: \"active\" | \"disabled\",\n): Promise<CredentialSummary> {\n return status === \"disabled\"\n ? client.console.credentials.disable(id)\n : client.console.credentials.enable(id);\n}\n\nexport function testCredential(client: W6WClient, id: string): Promise<CredentialTestResult> {\n return client.console.credentials.test(id);\n}\n\nexport function getCredentialDependents(\n client: W6WClient,\n id: string,\n): Promise<CredentialDependents> {\n return client.console.credentials.dependents(id);\n}\n\nexport type DeleteCredentialResult = { ok: true } | { ok: false; dependents: CredentialDependents };\n\n/**\n * Delete. A 409 `credential_in_use` is data — `{ ok: false, dependents }` — not a thrown error;\n * every other failure rejects. There is no `force`: a credential in use is never deleted.\n * Wire (RECONCILE R-11): `{ error: { code, message, dependents: { connections } } }`.\n */\nexport async function deleteCredential(\n client: W6WClient,\n id: string,\n): Promise<DeleteCredentialResult> {\n try {\n await client.console.credentials.delete(id);\n return { ok: true };\n } catch (e) {\n const err = e as { status?: unknown; code?: unknown; raw?: unknown };\n if (err?.status === 409 && err.code === \"credential_in_use\") {\n const raw = (err.raw ?? {}) as {\n error?: { dependents?: Partial<CredentialDependents> };\n };\n return {\n ok: false,\n dependents: { connections: raw.error?.dependents?.connections ?? [] },\n };\n }\n throw e;\n }\n}\n\n// ── hooks ─────────────────────────────────────────────────────────────\n\nexport function useCredentialsQuery(filter?: CredentialListFilter) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: filter ? [...credentialsKey, filter] : credentialsKey,\n queryFn: () => listCredentials(client, filter),\n });\n}\n\nexport function useCredentialQuery(id: string) {\n const client = useEmbedClient();\n return useQuery({ queryKey: credentialKey(id), queryFn: () => getCredential(client, id) });\n}\n\nexport function useCredentialDependentsQuery(id: string, enabled = true) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: credentialDependentsKey(id),\n queryFn: () => getCredentialDependents(client, id),\n enabled,\n retry: false,\n });\n}\n\nexport function useCreateCredentialMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (body: { name: string; contract: string; source: Record<string, unknown> }) =>\n createCredential(client, body),\n onSuccess: () => qc.invalidateQueries({ queryKey: credentialsKey }),\n });\n}\n\n/** Rename touches only the credential keys: no connection's state changes. */\nexport function useUpdateCredentialMutation(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (body: { name: string }) => updateCredential(client, id, body),\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: credentialsKey });\n qc.invalidateQueries({ queryKey: credentialKey(id) });\n },\n });\n}\n\nexport function useRotateCredentialMutation(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (body: { source: Record<string, unknown> }) => rotateCredential(client, id, body),\n onSuccess: () => invalidateAfterCredentialWrite(qc, id),\n });\n}\n\nexport function useSetCredentialStatusMutation(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (status: \"active\" | \"disabled\") => setCredentialStatus(client, id, status),\n onSuccess: () => invalidateAfterCredentialWrite(qc, id),\n });\n}\n\nexport function useTestCredentialMutation(id: string) {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (): Promise<CredentialTestResult> => testCredential(client, id),\n });\n}\n\nexport function useDeleteCredentialMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => deleteCredential(client, id),\n onSuccess: (r, id) => {\n if (r.ok) invalidateAfterCredentialWrite(qc, id);\n },\n });\n}\n\n// ── W6WApi bridge ─────────────────────────────────────────────────────\n\ntype CredentialMethodName =\n | \"listCredentials\"\n | \"createCredential\"\n | \"getCredential\"\n | \"rotateCredential\"\n | \"setCredentialStatus\"\n | \"testCredential\"\n | \"credentialDependents\"\n | \"deleteCredential\";\n\nconst CREDENTIAL_METHODS: readonly CredentialMethodName[] = [\n \"listCredentials\",\n \"createCredential\",\n \"getCredential\",\n \"rotateCredential\",\n \"setCredentialStatus\",\n \"testCredential\",\n \"credentialDependents\",\n \"deleteCredential\",\n];\n\n/**\n * The eight optional `W6WApi` credential methods over `client` (this module may not import\n * `@w6w/ui`, so the signatures are checked where they are spread into a `W6WApi`: Studio's\n * facade, and `W6WEmbedProvider`'s bridge). `deleteCredential` rejects on a\n * 409 with the response body attached as `.body` (as `withApiErrorBody` does in the react adapter).\n */\nexport function credentialUiMethods(client: W6WClient) {\n return {\n listCredentials: (filter?: CredentialListFilter) => listCredentials(client, filter),\n createCredential: (body: { name: string; contract: string; source: Record<string, unknown> }) =>\n createCredential(client, body),\n getCredential: (id: string) => getCredential(client, id),\n rotateCredential: (id: string, body: { source: Record<string, unknown> }) =>\n rotateCredential(client, id, body),\n setCredentialStatus: (id: string, status: \"active\" | \"disabled\") =>\n setCredentialStatus(client, id, status),\n testCredential: (id: string) => testCredential(client, id),\n credentialDependents: (id: string) => getCredentialDependents(client, id),\n deleteCredential: async (id: string) => {\n try {\n await client.console.credentials.delete(id);\n } catch (e) {\n if (e && typeof e === \"object\" && \"raw\" in e) {\n (e as { body?: unknown }).body = (e as { raw?: unknown }).raw;\n }\n throw e;\n }\n },\n };\n}\n\n/** Fills ONLY the credential methods that are not functions on `adapter`; keeps the rest. */\nexport function withCredentialMethods<T extends object>(adapter: T, client: W6WClient): T {\n const ours = credentialUiMethods(client);\n const target = adapter as Record<string, unknown>;\n for (const name of CREDENTIAL_METHODS) {\n if (typeof target[name] !== \"function\") target[name] = ours[name];\n }\n return adapter;\n}\n"],"names":["credentialsKey","credentialKey","id","credentialDependentsKey","invalidateAfterCredentialWrite","qc","connectionsKey","listCredentials","client","filter","getCredential","createCredential","body","updateCredential","rotateCredential","setCredentialStatus","status","testCredential","getCredentialDependents","deleteCredential","e","err","_b","_a","useCredentialsQuery","useEmbedClient","useQuery","useCredentialQuery","useCredentialDependentsQuery","enabled","useCreateCredentialMutation","useQueryClient","useMutation","useUpdateCredentialMutation","useRotateCredentialMutation","useSetCredentialStatusMutation","useTestCredentialMutation","useDeleteCredentialMutation","r","CREDENTIAL_METHODS","credentialUiMethods","withCredentialMethods","adapter","ours","target","name"],"mappings":";;;AA6BO,MAAMA,IAAiB,CAAC,aAAa,GAC/BC,IAAgB,CAACC,MAAe,CAAC,cAAcA,CAAE,GACjDC,IAA0B,CAACD,MAAe,CAAC,yBAAyBA,CAAE;AAM5E,SAASE,EAA+BC,GAAiBH,GAAkB;AAChF,EAAAG,EAAG,kBAAkB,EAAE,UAAUL,EAAA,CAAgB,GACjDK,EAAG,kBAAkB,EAAE,UAAUJ,EAAcC,CAAE,GAAG,GACpDG,EAAG,kBAAkB,EAAE,UAAUC,EAAA,CAAgB,GACjDD,EAAG,kBAAkB,EAAE,UAAU,CAAC,YAAY,GAAG,GACjDA,EAAG,kBAAkB,EAAE,UAAU,CAAC,iBAAiB,GAAG;AACxD;AAIO,SAASE,EACdC,GACAC,GAC8B;AAC9B,SAAOD,EAAO,QAAQ,YAAY,KAAKC,CAAM;AAC/C;AAEO,SAASC,EAAcF,GAAmBN,GAAwC;AACvF,SAAOM,EAAO,QAAQ,YAAY,IAAIN,CAAE;AAC1C;AAEO,SAASS,EACdH,GACAI,GAC4B;AAC5B,SAAOJ,EAAO,QAAQ,YAAY,OAAOI,CAAI;AAC/C;AAGO,SAASC,EACdL,GACAN,GACAU,GAC4B;AAC5B,SAAOJ,EAAO,QAAQ,YAAY,OAAON,GAAIU,CAAI;AACnD;AAEO,SAASE,EACdN,GACAN,GACAU,GAC4B;AAC5B,SAAOJ,EAAO,QAAQ,YAAY,OAAON,GAAIU,CAAI;AACnD;AAEO,SAASG,EACdP,GACAN,GACAc,GAC4B;AAC5B,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E,CAAI;AAElE,SAAOH;AACT;"}
@@ -0,0 +1,170 @@
1
+ import { useQueryClient as l, useMutation as u, useQuery as m, useInfiniteQuery as C } from "@tanstack/react-query";
2
+ import { u as i } from "./client-context-CX61Bgw-.js";
3
+ const f = 10, p = 200;
4
+ function K(e) {
5
+ return ["data-stores", e, "list"];
6
+ }
7
+ function Q(e, n) {
8
+ return ["data-stores", n, "detail", e];
9
+ }
10
+ function x(e, n, t) {
11
+ return ["data-stores", n, "entries", e, t];
12
+ }
13
+ async function q(e, n) {
14
+ const t = [];
15
+ let s;
16
+ for (let r = 0; r < f; r++) {
17
+ const a = await e.dataStores.list({ project: n, cursor: s, limit: p });
18
+ if (t.push(...a.items), a.nextCursor === void 0) break;
19
+ s = a.nextCursor;
20
+ }
21
+ return t;
22
+ }
23
+ async function v(e, n) {
24
+ return (await q(e, n)).map((t) => ({ name: t.name, kind: t.kind }));
25
+ }
26
+ const y = /* @__PURE__ */ new Map();
27
+ async function D(e, n, t, s = {}) {
28
+ var S;
29
+ const r = `${n}\0${t}`;
30
+ let a = y.get(r);
31
+ if (a === void 0) {
32
+ let o;
33
+ for (let c = 0; c < f && a === void 0; c++) {
34
+ const d = await e.dataStores.list({
35
+ project: n,
36
+ cursor: o,
37
+ limit: p,
38
+ signal: s.signal
39
+ });
40
+ if (a = (S = d.items.find((g) => g.name === t)) == null ? void 0 : S.id, d.nextCursor === void 0) break;
41
+ o = d.nextCursor;
42
+ }
43
+ if (a === void 0) return { items: [], more: !1 };
44
+ y.set(r, a);
45
+ }
46
+ try {
47
+ const o = await e.dataStores.entries.list(a, {
48
+ project: n,
49
+ prefix: s.prefix,
50
+ limit: s.limit,
51
+ signal: s.signal
52
+ });
53
+ return {
54
+ items: o.items.map((c) => ({ key: c.key, value: c.value, updatedAt: c.updatedAt })),
55
+ more: o.nextCursor !== void 0
56
+ };
57
+ } catch (o) {
58
+ throw y.delete(r), o;
59
+ }
60
+ }
61
+ function F(e) {
62
+ const n = i();
63
+ return m({
64
+ queryKey: K(e),
65
+ queryFn: () => q(n, e),
66
+ enabled: e != null
67
+ });
68
+ }
69
+ function j(e, n) {
70
+ const t = i();
71
+ return m({
72
+ queryKey: Q(e, n),
73
+ queryFn: () => t.dataStores.get(e, { project: n }),
74
+ enabled: n != null
75
+ });
76
+ }
77
+ function k(e, n, t) {
78
+ const s = i();
79
+ return C({
80
+ queryKey: x(e, n, t),
81
+ queryFn: ({ pageParam: r }) => s.dataStores.entries.list(e, {
82
+ project: n,
83
+ prefix: t === "" ? void 0 : t,
84
+ cursor: r
85
+ }),
86
+ initialPageParam: void 0,
87
+ getNextPageParam: (r) => r.nextCursor,
88
+ enabled: n != null
89
+ });
90
+ }
91
+ function A(e, n, t, s) {
92
+ return e.dataStores.entries.get(n, t, { project: s });
93
+ }
94
+ function w() {
95
+ const e = i(), n = l();
96
+ return u({
97
+ mutationFn: (t) => e.dataStores.create(t.input, { project: t.project }),
98
+ onSuccess: () => n.invalidateQueries({ queryKey: ["data-stores"] })
99
+ });
100
+ }
101
+ function b() {
102
+ const e = i(), n = l();
103
+ return u({
104
+ mutationFn: (t) => e.dataStores.archive(t.id, { project: t.project }),
105
+ onSuccess: () => n.invalidateQueries({ queryKey: ["data-stores"] })
106
+ });
107
+ }
108
+ function h() {
109
+ const e = i(), n = l();
110
+ return u({
111
+ mutationFn: (t) => e.dataStores.entries.set(
112
+ t.id,
113
+ t.key,
114
+ { value: t.value, ifVersion: t.ifVersion, ttlSeconds: t.ttlSeconds },
115
+ { project: t.project }
116
+ ),
117
+ onSuccess: () => n.invalidateQueries({ queryKey: ["data-stores"] })
118
+ });
119
+ }
120
+ function P() {
121
+ const e = i(), n = l();
122
+ return u({
123
+ mutationFn: (t) => e.dataStores.entries.insert(t.id, t.row, {
124
+ project: t.project,
125
+ ttlSeconds: t.ttlSeconds
126
+ }),
127
+ onSuccess: () => n.invalidateQueries({ queryKey: ["data-stores"] })
128
+ });
129
+ }
130
+ function _() {
131
+ const e = i(), n = l();
132
+ return u({
133
+ mutationFn: (t) => e.dataStores.entries.delete(t.id, t.key, { project: t.project }),
134
+ onSuccess: () => n.invalidateQueries({ queryKey: ["data-stores"] })
135
+ });
136
+ }
137
+ function T() {
138
+ const e = i(), n = l();
139
+ return u({
140
+ mutationFn: (t) => e.dataStores.importCsv(t.id, t.csv, { project: t.project }),
141
+ onSuccess: () => n.invalidateQueries({ queryKey: ["data-stores"] })
142
+ });
143
+ }
144
+ function G() {
145
+ const e = i();
146
+ return u({
147
+ mutationFn: (n) => e.dataStores.exportCsv(n.id, { project: n.project })
148
+ });
149
+ }
150
+ export {
151
+ f as D,
152
+ Q as a,
153
+ K as b,
154
+ D as c,
155
+ x as d,
156
+ v as e,
157
+ w as f,
158
+ A as g,
159
+ j as h,
160
+ F as i,
161
+ _ as j,
162
+ k,
163
+ q as l,
164
+ G as m,
165
+ T as n,
166
+ P as o,
167
+ h as p,
168
+ b as u
169
+ };
170
+ //# sourceMappingURL=data-stores-UeQvwVCa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-stores-UeQvwVCa.js","sources":["../src/repos/data-stores.ts"],"sourcesContent":["/**\n * The `data-stores` domain repo — wraps `@w6w/sdk`'s `client.dataStores.*` in react-query. The\n * repo never builds a request itself (no `client.request`, no `fetch`): every call is one SDK op,\n * and `project` is passed on every one of them (an omitted project would silently fall to the\n * account's default project).\n *\n * Every key starts with the bare `[\"data-stores\"]` prefix and every mutation invalidates that\n * prefix, so a write refreshes the list and any open store in whatever project it was cached\n * under. Reads are `enabled: projectId != null` and carry `projectId` in the key, so a render\n * before the project resolves never queries (or caches) the wrong project.\n *\n * Parsing, row building and conflict logic are `@w6w/ui`'s data-store util (E-2); this file only\n * moves data.\n */\nimport { useInfiniteQuery, useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n DataStore,\n DataStoreCreateInput,\n DataStoreEntry,\n DataStoreEntryPage,\n DataStoreKind,\n W6WClient,\n} from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\n\n/** The most requests one \"walk every page\" read makes (200 stores a page). */\nexport const DATA_STORE_MAX_PAGES = 10;\nconst PAGE_LIMIT = 200;\n\n/** Query key for a project's store list. */\nexport function dataStoresKey(projectId?: string) {\n return [\"data-stores\", projectId, \"list\"] as const;\n}\n\n/** Query key for one store. */\nexport function dataStoreKey(id: string, projectId?: string) {\n return [\"data-stores\", projectId, \"detail\", id] as const;\n}\n\n/** Query key for one store's entries under a key prefix (`\"\"` = no filter). */\nexport function dataStoreEntriesKey(id: string, projectId: string | undefined, prefix: string) {\n return [\"data-stores\", projectId, \"entries\", id, prefix] as const;\n}\n\n/**\n * The project's stores, walked page by page (at most {@link DATA_STORE_MAX_PAGES} requests),\n * server order kept. Hook-less so the ui picker's `listDataStores` seam can call it too.\n */\nexport async function listAllDataStores(client: W6WClient, project: string): Promise<DataStore[]> {\n const out: DataStore[] = [];\n let cursor: string | undefined;\n for (let i = 0; i < DATA_STORE_MAX_PAGES; i++) {\n const page = await client.dataStores.list({ project, cursor, limit: PAGE_LIMIT });\n out.push(...page.items);\n if (page.nextCursor === undefined) break;\n cursor = page.nextCursor;\n }\n return out;\n}\n\n/** The picker's shape: store names and kinds only. */\nexport async function listDataStores(\n client: W6WClient,\n project: string,\n): Promise<{ name: string; kind: DataStoreKind }[]> {\n return (await listAllDataStores(client, project)).map((s) => ({ name: s.name, kind: s.kind }));\n}\n\n/** Store id by `project \\0 name`: a key picker's every keystroke must not re-walk the list. */\nconst storeIds = new Map<string, string>();\n\n/**\n * ONE page of the entries of the project's store named `store`, for the ui's `data-store-key`\n * picker (`W6WApi.listDataStoreEntries`): the name is resolved to its id (remembered), then\n * `prefix` is the host's server-side key search and `limit` caps the page. An unknown name is an\n * empty page; a failed entries read forgets the id (renamed or archived) and rethrows.\n */\nexport async function listDataStoreEntries(\n client: W6WClient,\n project: string,\n store: string,\n opts: { prefix?: string; limit?: number; signal?: AbortSignal } = {},\n): Promise<{ items: { key: string; value: unknown; updatedAt: string }[]; more: boolean }> {\n const memo = `${project}\\0${store}`;\n let id = storeIds.get(memo);\n if (id === undefined) {\n let cursor: string | undefined;\n for (let i = 0; i < DATA_STORE_MAX_PAGES && id === undefined; i++) {\n const page = await client.dataStores.list({\n project,\n cursor,\n limit: PAGE_LIMIT,\n signal: opts.signal,\n });\n id = page.items.find((s) => s.name === store)?.id;\n if (page.nextCursor === undefined) break;\n cursor = page.nextCursor;\n }\n if (id === undefined) return { items: [], more: false };\n storeIds.set(memo, id);\n }\n try {\n const page = await client.dataStores.entries.list(id, {\n project,\n prefix: opts.prefix,\n limit: opts.limit,\n signal: opts.signal,\n });\n return {\n items: page.items.map((e) => ({ key: e.key, value: e.value, updatedAt: e.updatedAt })),\n more: page.nextCursor !== undefined,\n };\n } catch (e) {\n storeIds.delete(memo);\n throw e;\n }\n}\n\nexport function useDataStoresQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: dataStoresKey(projectId),\n queryFn: () => listAllDataStores(client, projectId as string),\n enabled: projectId != null,\n });\n}\n\nexport function useDataStoreQuery(id: string, projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: dataStoreKey(id, projectId),\n queryFn: () => client.dataStores.get(id, { project: projectId }),\n enabled: projectId != null,\n });\n}\n\nexport function useEntriesQuery(id: string, projectId: string | undefined, prefix: string) {\n const client = useEmbedClient();\n return useInfiniteQuery({\n queryKey: dataStoreEntriesKey(id, projectId, prefix),\n queryFn: ({ pageParam }): Promise<DataStoreEntryPage> =>\n client.dataStores.entries.list(id, {\n project: projectId,\n prefix: prefix === \"\" ? undefined : prefix,\n cursor: pageParam,\n }),\n initialPageParam: undefined as string | undefined,\n getNextPageParam: (last) => last.nextCursor,\n enabled: projectId != null,\n });\n}\n\n/** One entry by key, read fresh (the conflict prompt's Reload). */\nexport function getEntry(\n client: W6WClient,\n id: string,\n key: string,\n project: string,\n): Promise<DataStoreEntry> {\n return client.dataStores.entries.get(id, key, { project });\n}\n\nexport function useCreateDataStoreMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (vars: { input: DataStoreCreateInput; project: string }) =>\n client.dataStores.create(vars.input, { project: vars.project }),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"data-stores\"] }),\n });\n}\n\nexport function useArchiveDataStoreMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (vars: { id: string; project: string }) =>\n client.dataStores.archive(vars.id, { project: vars.project }),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"data-stores\"] }),\n });\n}\n\n/** `PUT` one entry. `ifVersion` is the optimistic-concurrency guard; `ttlSeconds` keeps an expiry. */\nexport function useSetEntryMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (vars: {\n id: string;\n key: string;\n value: unknown;\n ifVersion?: number;\n ttlSeconds?: number;\n project: string;\n }) =>\n client.dataStores.entries.set(\n vars.id,\n vars.key,\n { value: vars.value, ifVersion: vars.ifVersion, ttlSeconds: vars.ttlSeconds },\n { project: vars.project },\n ),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"data-stores\"] }),\n });\n}\n\n/** `POST` one table row; the server generates the key. */\nexport function useInsertRowMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (vars: {\n id: string;\n row: Record<string, unknown>;\n ttlSeconds?: number;\n project: string;\n }) =>\n client.dataStores.entries.insert(vars.id, vars.row, {\n project: vars.project,\n ttlSeconds: vars.ttlSeconds,\n }),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"data-stores\"] }),\n });\n}\n\nexport function useDeleteEntryMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (vars: { id: string; key: string; project: string }) =>\n client.dataStores.entries.delete(vars.id, vars.key, { project: vars.project }),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"data-stores\"] }),\n });\n}\n\n/** Import CSV text verbatim (`text/csv`). Resolves `{imported}`; a refusal throws an `ApiError`. */\nexport function useImportCsvMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (vars: { id: string; csv: string; project: string }) =>\n client.dataStores.importCsv(vars.id, vars.csv, { project: vars.project }),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"data-stores\"] }),\n });\n}\n\n/** Export a table store as CSV text. Read-only: nothing is invalidated. */\nexport function useExportCsvMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (vars: { id: string; project: string }) =>\n client.dataStores.exportCsv(vars.id, { project: vars.project }),\n });\n}\n"],"names":["DATA_STORE_MAX_PAGES","PAGE_LIMIT","dataStoresKey","projectId","dataStoreKey","id","dataStoreEntriesKey","prefix","listAllDataStores","client","project","out","cursor","i","page","listDataStores","s","storeIds","listDataStoreEntries","store","opts","memo","_a","e","useDataStoresQuery","useEmbedClient","useQuery","useDataStoreQuery","useEntriesQuery","useInfiniteQuery","pageParam","last","getEntry","key","useCreateDataStoreMutation","qc","useQueryClient","useMutation","vars","useArchiveDataStoreMutation","useSetEntryMutation","useInsertRowMutation","useDeleteEntryMutation","useImportCsvMutation","useExportCsvMutation"],"mappings":";;AA0BO,MAAMA,IAAuB,IAC9BC,IAAa;AAGZ,SAASC,EAAcC,GAAoB;AAChD,SAAO,CAAC,eAAeA,GAAW,MAAM;AAC1C;AAGO,SAASC,EAAaC,GAAYF,GAAoB;AAC3D,SAAO,CAAC,eAAeA,GAAW,UAAUE,CAAE;AAChD;AAGO,SAASC,EAAoBD,GAAYF,GAA+BI,GAAgB;AAC7F,SAAO,CAAC,eAAeJ,GAAW,WAAWE,GAAIE,CAAM;AACzD;AAMA,eAAsBC,EAAkBC,GAAmBC,GAAuC;AAChG,QAAMC,IAAmB,CAAA;AACzB,MAAIC;AACJ,WAASC,IAAI,GAAGA,IAAIb,GAAsBa,KAAK;AAC7C,UAAMC,IAAO,MAAML,EAAO,WAAW,KAAK,EAAE,SAAAC,GAAS,QAAAE,GAAQ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SAASO,IAAyB;AACvC,QAAMjC,IAASgB,EAAA,GACTU,IAAKC,EAAA;AACX,SAAOC,EAAY;AAAA,IACjB,YAAY,CAACC,MACX7B,EAAO,WAAW,QAAQ,OAAO6B,EAAK,IAAIA,EAAK,KAAK,EAAE,SAASA,EAAK,SAAS;AAAA,IAC/E,WAAW,MAAMH,EAAG,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAA,CAAG;AAAA,EAAA,CACpE;AACH;AAGO,SAASQ,IAAuB;AACrC,QAAMlC,IAASgB,EAAA,GACTU,IAAKC,EAAA;AACX,SAAOC,EAAY;AAAA,IACjB,YAAY,CAACC,MACX7B,EAAO,WAAW,UAAU6B,EAAK,IAAIA,EAAK,KAAK,EAAE,SAASA,EAAK,SAAS;AAAA,IAC1E,WAAW,MAAMH,EAAG,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAA,CAAG;AAAA,EAAA,CACpE;AACH;AAGO,SAASS,IAAuB;AACrC,QAAMnC,IAASgB,EAAA;AACf,SAAOY,EAAY;AAAA,IACjB,YAAY,CAACC,MACX7B,EAAO,WAAW,UAAU6B,EAAK,IAAI,EAAE,SAASA,EAAK,QAAA,CAAS;AAAA,EAAA,CACjE;AACH;"}
@@ -0,0 +1,169 @@
1
+ import { STATE_LIMITS as l } from "@w6w/expr";
2
+ import { parse as f } from "yaml";
3
+ const y = /* @__PURE__ */ new Set(["string", "number", "boolean", "object", "array"]);
4
+ function p(e) {
5
+ if (!Array.isArray(e)) return [];
6
+ const n = [];
7
+ for (const t of e) {
8
+ if (typeof t != "object" || t === null || Array.isArray(t)) continue;
9
+ const r = t, o = { key: typeof r.key == "string" ? r.key : "" };
10
+ typeof r.type == "string" && y.has(r.type) && (o.type = r.type), typeof r.required == "boolean" && (o.required = r.required), r.default !== void 0 && (o.default = r.default), n.push(o);
11
+ }
12
+ return n;
13
+ }
14
+ function m(e) {
15
+ if (e.length !== 0)
16
+ return e.map((n) => {
17
+ const t = { key: n.key };
18
+ return n.type !== void 0 && (t.type = n.type), n.required && (t.required = !0), n.default !== void 0 && (t.default = n.default), t;
19
+ });
20
+ }
21
+ function h(e) {
22
+ const n = /* @__PURE__ */ new Set(), t = [];
23
+ return e.forEach((r, o) => {
24
+ n.has(r.key) ? t.push(o) : n.add(r.key);
25
+ }), t;
26
+ }
27
+ function b(e, n, t) {
28
+ const r = /* @__PURE__ */ new Set(), o = [];
29
+ for (const i of [...e.slice(0, n).map((s) => s.key), ...t])
30
+ i === "" || r.has(i) || (r.add(i), o.push(i));
31
+ return o;
32
+ }
33
+ function c(e) {
34
+ return typeof e == "object" && e !== null && !Array.isArray(e) && e.type === "expr" && Array.isArray(e.parts);
35
+ }
36
+ function v(e) {
37
+ const n = [], t = [];
38
+ for (const r of e)
39
+ if (r.key.trim() !== "") {
40
+ if (c(r.default)) {
41
+ n.push({ key: r.key, type: r.type, required: !1 }), t.push(r.key);
42
+ continue;
43
+ }
44
+ n.push({ key: r.key, type: r.type, default: r.default, required: r.required });
45
+ }
46
+ return { fields: n, computed: t };
47
+ }
48
+ function a(e) {
49
+ return e !== null && typeof e == "object" && !Array.isArray(e);
50
+ }
51
+ function A(e) {
52
+ return a(e) ? e : void 0;
53
+ }
54
+ function S(e) {
55
+ if (e.trim() === "") return { ok: !0, value: void 0 };
56
+ let n;
57
+ try {
58
+ n = JSON.parse(e);
59
+ } catch {
60
+ return { ok: !1, reason: "invalid_json" };
61
+ }
62
+ return a(n) ? JSON.stringify(n).length > l.initialChars ? { ok: !1, reason: "too_large" } : Object.keys(n).length === 0 ? { ok: !0, value: void 0 } : { ok: !0, value: n } : { ok: !1, reason: "not_object" };
63
+ }
64
+ function j(e, n) {
65
+ if (!e) return [];
66
+ const t = [];
67
+ for (const r of n)
68
+ r.key === "" || t.includes(r.key) || Object.hasOwn(e, r.key) && t.push(r.key);
69
+ return t;
70
+ }
71
+ function w(e) {
72
+ if (!e) return !1;
73
+ switch (e.kind) {
74
+ case "function":
75
+ case "endpoint":
76
+ case "workflow":
77
+ return !0;
78
+ // A bare connection has no snippet; only the action page (which names one) does.
79
+ case "connection":
80
+ return !!e.action;
81
+ default:
82
+ return !1;
83
+ }
84
+ }
85
+ function g(e) {
86
+ if (!e) return null;
87
+ switch (e.kind) {
88
+ case "function":
89
+ return { kind: "function", id: e.id, key: e.key, inputs: e.inputs, alias: e.alias };
90
+ case "endpoint":
91
+ return {
92
+ kind: "endpoint",
93
+ id: e.id,
94
+ key: e.key,
95
+ invokeUrl: e.invokeUrl,
96
+ invokeUrlByKey: e.invokeUrlByKey,
97
+ urlForm: e.urlForm,
98
+ alias: e.alias,
99
+ inputs: e.inputs
100
+ };
101
+ case "workflow":
102
+ return { kind: "workflow", id: e.id, displayName: e.label, key: e.key };
103
+ case "connection":
104
+ return e.action ? { kind: "connection", id: e.id, action: e.action, params: e.params } : null;
105
+ default:
106
+ return null;
107
+ }
108
+ }
109
+ function O({
110
+ resource: e,
111
+ target: n,
112
+ hasAdapter: t
113
+ }) {
114
+ return (n.kind === "function" || n.kind === "workflow") && n.kind === e.kind && n.id === e.id ? t ? "warn" : "block" : "allow";
115
+ }
116
+ function u(e) {
117
+ let n;
118
+ if (e.format === "json")
119
+ try {
120
+ n = JSON.parse(e.content);
121
+ } catch {
122
+ return null;
123
+ }
124
+ else if (e.format === "yaml")
125
+ try {
126
+ n = f(e.content);
127
+ } catch {
128
+ return null;
129
+ }
130
+ else
131
+ return null;
132
+ return typeof n != "object" || n === null || Array.isArray(n) ? null : n;
133
+ }
134
+ function q(e) {
135
+ return e.map((n) => {
136
+ const t = u(n);
137
+ if (!t) return { key: n.key };
138
+ const r = Object.keys(t);
139
+ return r.length > 0 ? { key: n.key, fields: r.map((o) => ({ key: o })) } : { key: n.key };
140
+ });
141
+ }
142
+ function F(e) {
143
+ const n = {};
144
+ for (const t of e) {
145
+ n[`documents.${t.key}`] = t.content;
146
+ const r = u(t);
147
+ if (r)
148
+ for (const [o, i] of Object.entries(r))
149
+ n[`documents.${t.key}.${o}`] = i;
150
+ }
151
+ return n;
152
+ }
153
+ export {
154
+ h as a,
155
+ c as b,
156
+ p as c,
157
+ F as d,
158
+ O as e,
159
+ v as f,
160
+ S as g,
161
+ b as h,
162
+ w as i,
163
+ q as p,
164
+ A as r,
165
+ j as s,
166
+ g as t,
167
+ m as v
168
+ };
169
+ //# sourceMappingURL=document-sources-DNmBojx6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-sources-DNmBojx6.js","sources":["../src/lib/workflow-variables.ts","../src/lib/starting-data.ts","../src/lib/code-rail.ts","../src/lib/error-handler-self.ts","../src/lib/document-sources.ts"],"sourcesContent":["/**\n * The pure decisions behind a workflow's `variables` list (T1.1.5) — the\n * Variables tab's authoring surface and the run page's generated-form\n * projection. `variables` rides inside the workflow **definition**\n * (`w6w-workflow/packages/types/mod.ts:170`), the same JSON document that\n * already carries `steps`, so there is no column, no migration and no server\n * change behind it.\n *\n * Pure, React-free, `.ts`, **no value import of `@w6w/ui`** — studio's\n * `test:unit` is a bare `node --test` with no jsx loader\n * (`studio/package.json:17`), so a value import of the barrel (which\n * re-exports `.tsx`) kills the test. Same shape as `workflow-settings.ts`'s\n * reader/writer discipline and `input-seeding.ts`'s pure-module docstring\n * rule.\n *\n * The row type is defined **locally**, structurally identical to\n * `WorkflowVariable` (`w6w-workflow/packages/types/mod.ts:40-45`: `key`,\n * `type?`, `required?`, `default?`), so no cast is needed at the `.tsx`\n * boundary in either direction.\n */\n\n/** One row of a workflow's declared `variables` list. */\nexport interface WorkflowVariableRow {\n key: string;\n type?: \"string\" | \"number\" | \"boolean\" | \"object\" | \"array\";\n required?: boolean;\n default?: unknown;\n}\n\n/** The declared type union `WorkflowVariable.type` accepts. */\nconst VARIABLE_TYPES = new Set([\"string\", \"number\", \"boolean\", \"object\", \"array\"]);\n\n/**\n * Read a workflow definition's `variables` field as an array of rows.\n *\n * Takes `unknown` because the source is `JSON.parse`d and the `</>` editor\n * lets an author type anything: a non-array reads as no variables, and a\n * non-object array entry is dropped rather than crashing the tab. **Never\n * sorts, never de-dups, never re-orders** — declaration order *is*\n * resolution order (D-5) and `resolveVariables` iterates the array in order\n * (`w6w-workflow/packages/engine/src/run.ts:70-83`), so two rows sharing a\n * key both survive, in the order they were declared.\n */\nexport function readVariables(raw: unknown): WorkflowVariableRow[] {\n if (!Array.isArray(raw)) return [];\n const out: WorkflowVariableRow[] = [];\n for (const entry of raw) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) continue;\n const e = entry as Record<string, unknown>;\n const row: WorkflowVariableRow = { key: typeof e.key === \"string\" ? e.key : \"\" };\n if (typeof e.type === \"string\" && VARIABLE_TYPES.has(e.type)) {\n row.type = e.type as WorkflowVariableRow[\"type\"];\n }\n if (typeof e.required === \"boolean\") row.required = e.required;\n if (e.default !== undefined) row.default = e.default;\n out.push(row);\n }\n return out;\n}\n\n/**\n * The rows ready to write back into the definition's `variables` field.\n *\n * Mirrors `workflow-settings.ts`'s \"default written as absent\" rule, but here\n * it applies to a row's **optional flags, not the value**: `required` is\n * omitted when `false` and `type` is omitted when unset, so opening the tab\n * and touching nothing does not rewrite a legacy definition into\n * `{required:false,type:undefined}` rows. `default` is user data and is kept\n * **verbatim** — including `false`, `0`, `\"\"` and `null` — never dropped as\n * an optimisation (a \"drop falsy\" implementation would lose a `false`\n * default, which is exactly the case the tests pin).\n *\n * Returns `undefined` for an empty array (never `[]`) so the caller\n * (`patchMeta`, via `JSON.stringify`) drops the key entirely — which matters\n * beyond hygiene here: `draftFromWorkflowVariables`\n * (`server/packages/api/mcp/tool-schema.ts:310-326`) treats `undefined` and\n * `length === 0` identically (pass-through), so `[]` and absent already agree\n * on the wire; this just keeps the definition itself from growing an empty\n * `\"variables\": []` on the first open of the tab.\n */\nexport function variablesForSave(rows: WorkflowVariableRow[]): WorkflowVariableRow[] | undefined {\n if (rows.length === 0) return undefined;\n return rows.map((r) => {\n const out: WorkflowVariableRow = { key: r.key };\n if (r.type !== undefined) out.type = r.type;\n if (r.required) out.required = true;\n if (r.default !== undefined) out.default = r.default;\n return out;\n });\n}\n\n/**\n * Every index whose `key` repeats an earlier row's key. `resolveVariables`\n * writes `vars[v.key]` in a loop with no duplicate check (`run.ts:74-80`), so\n * a later row silently wins — this is informational only (the tab marks the\n * row; nothing here blocks a save), never de-duping or rejecting.\n */\nexport function duplicateKeyIndexes(rows: WorkflowVariableRow[]): number[] {\n const seen = new Set<string>();\n const out: number[] = [];\n rows.forEach((r, i) => {\n if (seen.has(r.key)) out.push(i);\n else seen.add(r.key);\n });\n return out;\n}\n\n/**\n * The `var.*` names to offer row `index`'s expression rail: the keys of\n * rows **strictly above** it, then `projectVars`, deduped, with blanks\n * dropped. Declaration order is resolution order (D-5), so a row can only\n * reference a variable declared earlier than itself — offering a row at or\n * below `index` would suggest a forward reference the engine rejects\n * (T2.1.1). This is the offered rail only; it is not validation.\n */\nexport function varsRailFor(\n rows: WorkflowVariableRow[],\n index: number,\n projectVars: string[],\n): string[] {\n const seen = new Set<string>();\n const out: string[] = [];\n for (const k of [...rows.slice(0, index).map((r) => r.key), ...projectVars]) {\n if (k === \"\" || seen.has(k)) continue;\n seen.add(k);\n out.push(k);\n }\n return out;\n}\n\n/** `true` if `v` is an `ExprValue` envelope — the two-key check `@w6w/ui`'s\n * `isExprValue` (`ui/src/types.ts:301-309`) makes, re-implemented locally\n * because this module cannot import `@w6w/ui` at value level (see the\n * module docstring). Mirrors `trigger-preview.ts:102-119`'s sanctioned\n * pattern for the same constraint — this is not duplication. */\nexport function isExprDefault(v: unknown): boolean {\n return (\n typeof v === \"object\" &&\n v !== null &&\n !Array.isArray(v) &&\n (v as { type?: unknown }).type === \"expr\" &&\n Array.isArray((v as { parts?: unknown }).parts)\n );\n}\n\n/** One field the run page's generated form fills — structurally assignable\n * to `@w6w/ui/flow`'s `TriggerFieldDef` (all fields optional) with no cast. */\nexport interface RunFormField {\n key: string;\n type?: WorkflowVariableRow[\"type\"];\n default?: unknown;\n required?: boolean;\n}\n\n/**\n * Project a workflow's declared variables into the run page's form fields.\n *\n * A row whose `default` is an `ExprValue` envelope is a server-side\n * computation (its value is resolved at run time, not authored on the\n * client), so it is emitted with **`default` dropped and `required: false`**\n * — never as a value `ui`'s `seedValues` would `String(...)` the envelope\n * into — and its key is listed in `computed` so the host can label the field\n * \"computed at run time\" and post nothing for it. A row with a blank/missing\n * key is dropped, mirroring `@w6w/ui`'s `fieldsToParams`, which does the same\n * before turning field definitions into a fillable form.\n */\nexport function runFormFields(rows: WorkflowVariableRow[]): {\n fields: RunFormField[];\n computed: string[];\n} {\n const fields: RunFormField[] = [];\n const computed: string[] = [];\n for (const r of rows) {\n if (r.key.trim() === \"\") continue;\n if (isExprDefault(r.default)) {\n fields.push({ key: r.key, type: r.type, required: false });\n computed.push(r.key);\n continue;\n }\n fields.push({ key: r.key, type: r.type, default: r.default, required: r.required });\n }\n return { fields, computed };\n}\n","/**\n * The pure decisions behind a workflow's **Starting data** (`Workflow.initialState`,\n * core/rfcs/workflow.md; ruling R8): a literal JSON object that seeds the run's\n * state tree. It rides inside the workflow definition as a top-level key, the\n * same way `variables` does, so the Settings tab only reads and writes that key.\n *\n * Seed layering (R2', later wins): project variables → starting data → the\n * workflow's own / the caller's variables.\n *\n * Pure, React-free, `.ts`, **no value import of `@w6w/ui`** — the same header\n * rule as `workflow-variables.ts` (studio's `test:unit` has no jsx loader).\n */\nimport { STATE_LIMITS } from \"@w6w/expr\";\nimport type { WorkflowVariableRow } from \"./workflow-variables.ts\";\n\n/** Why a Starting data draft cannot be saved. */\nexport type StartingDataProblem = \"invalid_json\" | \"not_object\" | \"too_large\";\n\n/** The outcome of reading a Starting data draft for save. `value: undefined` drops the key. */\nexport type StartingDataForSave =\n | { ok: true; value: Record<string, unknown> | undefined }\n | { ok: false; reason: StartingDataProblem };\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === \"object\" && !Array.isArray(v);\n}\n\n/**\n * Read a definition's `initialState` field. Takes `unknown` because the source is\n * `JSON.parse`d and the `</>` editor lets an author type anything: only a plain\n * object counts; anything else reads as \"no starting data\".\n */\nexport function readStartingData(raw: unknown): Record<string, unknown> | undefined {\n return isPlainObject(raw) ? raw : undefined;\n}\n\n/**\n * Turn the tab's JSON text into the value `patchMeta({ initialState })` saves.\n * Blank text and `{}` both mean \"no starting data\" (`value: undefined`, so the\n * key is dropped from the definition). Anything but a plain object is refused,\n * as is an object whose serialised form exceeds `STATE_LIMITS.initialChars`\n * (measured exactly as the server measures it: `JSON.stringify(v).length`).\n */\nexport function startingDataForSave(text: string): StartingDataForSave {\n if (text.trim() === \"\") return { ok: true, value: undefined };\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return { ok: false, reason: \"invalid_json\" };\n }\n if (!isPlainObject(parsed)) return { ok: false, reason: \"not_object\" };\n if (JSON.stringify(parsed).length > STATE_LIMITS.initialChars) {\n return { ok: false, reason: \"too_large\" };\n }\n if (Object.keys(parsed).length === 0) return { ok: true, value: undefined };\n return { ok: true, value: parsed };\n}\n\n/**\n * The declared variable keys that are also top-level keys of the starting data —\n * on those keys the variable's value wins (R2'). Variable declaration order, no\n * duplicates, no empty keys.\n */\nexport function startingDataCollisions(\n initial: Record<string, unknown> | undefined,\n variables: readonly WorkflowVariableRow[],\n): string[] {\n if (!initial) return [];\n const out: string[] = [];\n for (const v of variables) {\n if (v.key === \"\" || out.includes(v.key)) continue;\n if (Object.hasOwn(initial, v.key)) out.push(v.key);\n }\n return out;\n}\n","/**\n * Pure decisions behind the right rail's Code tool (`src/ui/rail/CodeTool.tsx`).\n * Split out so `node --test` can gate them directly — mirrors\n * `src/lib/alias-rail.ts`'s own reason for existing: `node --test` throws\n * `ERR_UNKNOWN_FILE_EXTENSION` on any `@w6w/ui`-adjacent import, and\n * `src/ui/workspace.tsx` sits one hop from that barrel through `Layout.tsx`'s\n * import graph. So this module declares its own structural mirror of\n * `WorkspaceCallable` instead of importing it.\n */\nimport type { SnippetCallable, SnippetInput } from \"./sdk-snippets.ts\";\n\n/** Structural mirror of T2.1.2's widened `WorkspaceCallable` (`src/ui/workspace.tsx`). */\nexport type RailCallable =\n | { kind: \"function\"; id: string; key?: string; inputs?: readonly SnippetInput[]; alias?: string }\n | {\n kind: \"endpoint\";\n id: string;\n key?: string;\n invokeUrl?: string;\n invokeUrlByKey?: string;\n urlForm?: \"id\" | \"key\";\n alias?: string;\n inputs?: readonly SnippetInput[];\n }\n | { kind: \"workflow\"; id: string; label?: string; key?: string }\n | { kind: \"connection\"; id: string; action?: string; params?: readonly SnippetInput[] }\n | null;\n\n/**\n * Is a \"Call from code\" panel meaningful for this context? Mirrors\n * `alias-rail.ts`'s `targetForCallable` fail-closed shape exactly (its own\n * comment: *\"'connection' and no resource at all both fail closed to null —\n * house style\"*) — a bare `\"connection\"` (no `action`) and `null` both answer `false`.\n */\nexport function isAvailable(ctx: RailCallable): boolean {\n if (!ctx) return false;\n switch (ctx.kind) {\n case \"function\":\n case \"endpoint\":\n case \"workflow\":\n return true;\n // A bare connection has no snippet; only the action page (which names one) does.\n case \"connection\":\n return !!ctx.action;\n default:\n return false;\n }\n}\n\n/**\n * The widened-union -> `SnippetCallable` conversion `CodeTool.Panel` hands to\n * `CallFromCodeBody`. `null` for a context this tool has no snippet for\n * (a connection without an `action`, or no resource at all) — defensive, since `isAvailable`\n * already keeps the tool off the strip for those.\n *\n * The one easy-to-miss field: `WorkspaceCallable`'s `label` maps to\n * `SnippetCallable`'s `workflow` arm's `displayName` — NOT the same field\n * name. A naive `{...ctx}` spread compiles (both optional) but silently\n * drops the label everywhere it matters, never caught by `tsc`.\n */\nexport function toSnippetCallable(ctx: RailCallable): SnippetCallable | null {\n if (!ctx) return null;\n switch (ctx.kind) {\n case \"function\":\n return { kind: \"function\", id: ctx.id, key: ctx.key, inputs: ctx.inputs, alias: ctx.alias };\n case \"endpoint\":\n return {\n kind: \"endpoint\",\n id: ctx.id,\n key: ctx.key,\n invokeUrl: ctx.invokeUrl,\n invokeUrlByKey: ctx.invokeUrlByKey,\n urlForm: ctx.urlForm,\n alias: ctx.alias,\n inputs: ctx.inputs,\n };\n case \"workflow\":\n return { kind: \"workflow\", id: ctx.id, displayName: ctx.label, key: ctx.key };\n case \"connection\":\n return ctx.action\n ? { kind: \"connection\", id: ctx.id, action: ctx.action, params: ctx.params }\n : null;\n default:\n return null;\n }\n}\n","/**\n * The authoring-time half of the error-handler recursion guard. The server\n * compares resolved values at dispatch time; this small, pure decision keeps\n * the rail from creating the known-identical no-adapter case in the first\n * place without losing an adapter imported or authored elsewhere.\n */\nexport type ErrorHandlerSelfDecision = \"allow\" | \"warn\" | \"block\";\n\nexport interface ErrorHandlerSelfInput {\n resource: { kind: string; id: string };\n target: { kind: string; id: string };\n hasAdapter: boolean;\n}\n\n/**\n * Only Function and Workflow targets can re-enter the currently edited\n * resource. Actions are always allowed. A self-target with no adapter passes\n * the failed input through unchanged, so it is refused; an adapter is kept\n * and called out because only the runtime can determine its resolved values.\n */\nexport function errorHandlerSelfDecision({\n resource,\n target,\n hasAdapter,\n}: ErrorHandlerSelfInput): ErrorHandlerSelfDecision {\n const selfTarget =\n (target.kind === \"function\" || target.kind === \"workflow\") &&\n target.kind === resource.kind &&\n target.id === resource.id;\n if (!selfTarget) return \"allow\";\n return hasAdapter ? \"warn\" : \"block\";\n}\n","/**\n * Pure `Doc[]` → `ExpressionOptions` projections for the ƒx picker's\n * Documents group — extracted out of `ExpressionScope.tsx` so studio's\n * Node-native `test:unit` runner (globbed to `src/lib/__tests__/`,\n * `src/api/__tests__/` and `src/repos/__tests__/` only — `.ai/PLANNER.md`\n * fact 10) can reach it. No React, no import from `src/ui/` — `@w6w/ui`'s\n * `ExpressionDocumentSource` interface is not imported either (it is not\n * exported from `@w6w/ui`'s barrel, D-P3): the object literals returned below\n * are structurally identical to it, so TypeScript carries the shape without a\n * type import.\n *\n * ## The gate — mirrors the engine's own, bit-for-bit\n *\n * A document contributes field data **iff**: `doc.format === \"json\"` AND\n * `JSON.parse(doc.content)` succeeds into a plain object, OR\n * `doc.format === \"yaml\"` AND npm `yaml`'s `parse(doc.content)` succeeds into\n * a plain object — where *plain object* means\n * `typeof v === \"object\" && v !== null && !Array.isArray(v)`. This mirrors\n * the engine's own gate (`documentsSeed` /\n * `packages/server/packages/api/run-seed.ts`, read-only, out of scope)\n * bit-for-bit for each format: `format === \"json\"` or `format === \"yaml\"`,\n * then a `try/catch` parse, falling back to the raw content string on either\n * a non-matching format or a throw. Reproduced here so the picker never\n * offers a ref the run scope itself would refuse to resolve\n * (`render_ref_unresolved`) — `text`/`markdown`/`html` documents, and a\n * `json`/`yaml` document whose parse throws or yields a non-plain-object, are\n * excluded.\n *\n * The two parsers are not identical for every input — `@std/yaml` (server,\n * `{ schema: \"core\" }`) and npm `yaml` (here) diverge on tab-indented content\n * and on an unresolvable custom tag (`!!js/function`), both accepted, tested\n * debt (D-3). Every other input, including a plain JSON object (JSON is a\n * subset of YAML), agrees between the two.\n *\n * Field keys are enumerated RAW and UNFILTERED by {@link projectDocumentSources}\n * — arbitrary user-authored JSON keys (which can contain `.`/`{`/`}`/\n * whitespace) reach the modal; `isRefSafeKey` filters them exactly once, at\n * the modal's render site (`ExpressionEditorModal.tsx`), never here\n * (`building-blocks.md`: \"enumerate raw at the source, filter once at the\n * single render site\").\n */\nimport type { Doc } from \"@w6w/sdk\";\nimport { parse as parseYaml } from \"yaml\";\n\n/** One document's contribution to `ExpressionOptions.documents` — structurally\n * identical to `@w6w/ui`'s (unexported) `ExpressionDocumentSource`. */\nexport interface DocumentSource {\n key: string;\n fields?: { key: string }[];\n}\n\n/**\n * `doc`'s parsed content when the gate holds, else `null`. The one place both\n * functions below apply the gate, so they cannot silently disagree on it.\n */\nfunction gatedFields(doc: Doc): Record<string, unknown> | null {\n let parsed: unknown;\n if (doc.format === \"json\") {\n try {\n parsed = JSON.parse(doc.content);\n } catch {\n return null;\n }\n } else if (doc.format === \"yaml\") {\n try {\n parsed = parseYaml(doc.content);\n } catch {\n return null;\n }\n } else {\n return null;\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) return null;\n return parsed as Record<string, unknown>;\n}\n\n/**\n * The `ExpressionOptions.documents` array: `{ key }` for every document, plus\n * `fields` (raw, unfiltered top-level keys) when the gate holds AND the\n * parsed object has at least one key. `fields` is OMITTED (not `[]`) both\n * when the gate fails and when it holds but yields zero keys — a consumer\n * must be able to tell \"nothing declared\" from \"declared none\".\n */\nexport function projectDocumentSources(docs: Doc[]): DocumentSource[] {\n return docs.map((d) => {\n const parsed = gatedFields(d);\n if (!parsed) return { key: d.key };\n const keys = Object.keys(parsed);\n return keys.length > 0 ? { key: d.key, fields: keys.map((key) => ({ key })) } : { key: d.key };\n });\n}\n\n/**\n * The `sampleValues` entries the ƒx Result preview substitutes for document\n * refs: `documents.<key>` → the document's raw content, for every document\n * (unconditional, exactly as before this project), PLUS `documents.<key>.<field>`\n * → the field's own parsed value, for the gated set only. Without the second\n * half, every field ref this project newly makes pickable would preview as\n * the empty string (`renderResult` does an exact flat-key lookup).\n */\nexport function documentSampleValues(docs: Doc[]): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const d of docs) {\n out[`documents.${d.key}`] = d.content;\n const parsed = gatedFields(d);\n if (!parsed) continue;\n for (const [key, value] of Object.entries(parsed)) {\n out[`documents.${d.key}.${key}`] = value;\n }\n }\n return out;\n}\n"],"names":["VARIABLE_TYPES","readVariables","raw","out","entry","e","row","variablesForSave","rows","r","duplicateKeyIndexes","seen","i","varsRailFor","index","projectVars","k","isExprDefault","v","runFormFields","fields","computed","isPlainObject","readStartingData","startingDataForSave","text","parsed","STATE_LIMITS","startingDataCollisions","initial","variables","isAvailable","ctx","toSnippetCallable","errorHandlerSelfDecision","resource","target","hasAdapter","gatedFields","doc","parseYaml","projectDocumentSources","docs","d","keys","key","documentSampleValues","value"],"mappings":";;AA8BA,MAAMA,wBAAqB,IAAI,CAAC,UAAU,UAAU,WAAW,UAAU,OAAO,CAAC;AAa1E,SAASC,EAAcC,GAAqC;AACjE,MAAI,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AAE,IAAIA,EAAE;AAC9B,UAAMjB,IAASY,EAAYK,CAAC;AAC5B,QAAKjB;AACL,iBAAW,CAACmB,GAAKE,CAAK,KAAK,OAAO,QAAQrB,CAAM;AAC9C,QAAAvB,EAAI,aAAawC,EAAE,GAAG,IAAIE,CAAG,EAAE,IAAIE;AAAA,EAEvC;AACA,SAAO5C;AACT;"}
@@ -63,5 +63,7 @@ export interface WorkflowDraft {
63
63
  commit(next: string): Promise<FlushOutcome>;
64
64
  /** 409 recovery: GET, replace the buffer and token, clear `stale`. */
65
65
  reload(): Promise<void>;
66
+ /** Stop pending saves, drain an in-flight save, replace the server draft, then reload. */
67
+ discardThen(action: () => Promise<unknown>): Promise<void>;
66
68
  }
67
69
  export declare function useWorkflowDraft(o: UseWorkflowDraftOptions): WorkflowDraft;
package/dist/draft.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
- import { A as a, c as s, i as t, n as o, r as i, u } from "./use-workflow-draft-DzAyUeA6.js";
2
+ import { A as a, c as s, i as t, n as o, r as i, u } from "./use-workflow-draft-l3P5KZzw.js";
3
3
  import { E as n, u as l } from "./client-context-CX61Bgw-.js";
4
4
  import { D as E, c, u as d } from "./draft-registry-YF0tqNN0.js";
5
- import { u as p, a as x, b as S } from "./use-callable-draft-zHLpcr-b.js";
5
+ import { u as p, a as x, b as S } from "./use-callable-draft-DCauHt5o.js";
6
6
  export {
7
7
  a as AUTOSAVE_DEBOUNCE_MS,
8
8
  E as DraftRegistryProvider,