@mountaya/studio 0.1.0 → 0.2.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 (260) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/agent/index.cjs +2561 -2815
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +766 -786
  5. package/dist/agent/index.d.ts +766 -786
  6. package/dist/agent/index.js +2553 -2790
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/chunk-3Oi_Zrtm.js +9 -0
  9. package/dist/chunk-3Oi_Zrtm.js.map +1 -0
  10. package/dist/chunk-B18OPIu_.js +6 -0
  11. package/dist/chunk-B18OPIu_.js.map +1 -0
  12. package/dist/chunk-B5Uz3Qct.cjs +15 -0
  13. package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
  14. package/dist/chunk-BBEJwkd3.d.cts +839 -0
  15. package/dist/chunk-BIEc_SkR.cjs +29 -0
  16. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  17. package/dist/chunk-BKMFOe-N.js +171 -0
  18. package/dist/chunk-BKMFOe-N.js.map +1 -0
  19. package/dist/chunk-BP4uy7E1.d.ts +11583 -0
  20. package/dist/chunk-BSHTsFiB.js +1403 -0
  21. package/dist/chunk-BSHTsFiB.js.map +1 -0
  22. package/dist/chunk-BTUUABGI.js +17 -0
  23. package/dist/chunk-BTUUABGI.js.map +1 -0
  24. package/dist/chunk-BaPiaz5X.cjs +115 -0
  25. package/dist/chunk-BaPiaz5X.cjs.map +1 -0
  26. package/dist/chunk-BeCVpkYr.cjs +542 -0
  27. package/dist/chunk-BeCVpkYr.cjs.map +1 -0
  28. package/dist/chunk-BgngsvK8.cjs +6202 -0
  29. package/dist/chunk-BgngsvK8.cjs.map +1 -0
  30. package/dist/chunk-BhInd7CJ.d.cts +253 -0
  31. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  32. package/dist/chunk-By9ZnkVI.js +60 -0
  33. package/dist/chunk-By9ZnkVI.js.map +1 -0
  34. package/dist/chunk-BzqPhxsz.cjs +367 -0
  35. package/dist/chunk-BzqPhxsz.cjs.map +1 -0
  36. package/dist/chunk-C2mMX81q.d.ts +443 -0
  37. package/dist/chunk-C2rr9Q0V.cjs +1402 -0
  38. package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
  39. package/dist/{directorThreads-CqmvsV8b.d.cts → chunk-CDJCbwIQ.d.cts} +20 -22
  40. package/dist/chunk-CLGvBOVH.d.cts +1654 -0
  41. package/dist/chunk-COdw1dc6.d.ts +525 -0
  42. package/dist/chunk-CQCJnT2i.d.ts +511 -0
  43. package/dist/chunk-CSyHY67q.cjs +353 -0
  44. package/dist/chunk-CSyHY67q.cjs.map +1 -0
  45. package/dist/chunk-CiK1Iqrv.js +950 -0
  46. package/dist/chunk-CiK1Iqrv.js.map +1 -0
  47. package/dist/chunk-CmJBgSwZ.cjs +24 -0
  48. package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
  49. package/dist/chunk-CnrsRK2u.cjs +83 -0
  50. package/dist/chunk-CnrsRK2u.cjs.map +1 -0
  51. package/dist/chunk-Co782_9r.js +326 -0
  52. package/dist/chunk-Co782_9r.js.map +1 -0
  53. package/dist/chunk-Csr3KDpZ.cjs +32 -0
  54. package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
  55. package/dist/chunk-CwkmccXv.js +89 -0
  56. package/dist/chunk-CwkmccXv.js.map +1 -0
  57. package/dist/chunk-D0Q4iL9B.cjs +255 -0
  58. package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
  59. package/dist/chunk-DFwiSzUS.cjs +72 -0
  60. package/dist/chunk-DFwiSzUS.cjs.map +1 -0
  61. package/dist/chunk-DIFayl2P.d.cts +443 -0
  62. package/dist/chunk-DIGF58ux.d.cts +525 -0
  63. package/dist/chunk-DKuuuld5.js +101 -0
  64. package/dist/chunk-DKuuuld5.js.map +1 -0
  65. package/dist/chunk-DMePkFEo.js +5054 -0
  66. package/dist/chunk-DMePkFEo.js.map +1 -0
  67. package/dist/chunk-DO5SIBgu.js +305 -0
  68. package/dist/chunk-DO5SIBgu.js.map +1 -0
  69. package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
  70. package/dist/{tabs-B2nRO4p_.d.ts → chunk-DThaaNeb.d.cts} +2 -2
  71. package/dist/{tabs-B2nRO4p_.d.cts → chunk-DThaaNeb.d.ts} +2 -2
  72. package/dist/{directorThreads-CqmvsV8b.d.ts → chunk-DUQzjUJy.d.ts} +20 -22
  73. package/dist/chunk-DX37IPhV.cjs +1903 -0
  74. package/dist/chunk-DX37IPhV.cjs.map +1 -0
  75. package/dist/chunk-Damps5Tk.cjs +155 -0
  76. package/dist/chunk-Damps5Tk.cjs.map +1 -0
  77. package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
  78. package/dist/chunk-De0vAASv.d.ts +253 -0
  79. package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
  80. package/dist/chunk-DjEvqvPA.cjs +43 -0
  81. package/dist/chunk-DjEvqvPA.cjs.map +1 -0
  82. package/dist/{saveFile-j-1kkApx.d.cts → chunk-DkwDzwvu.d.cts} +7 -9
  83. package/dist/{saveFile-j-1kkApx.d.ts → chunk-DkwDzwvu.d.ts} +7 -9
  84. package/dist/chunk-Dmszv9If.js +71 -0
  85. package/dist/chunk-Dmszv9If.js.map +1 -0
  86. package/dist/chunk-Dp_ftNWY.d.cts +511 -0
  87. package/dist/chunk-DsHQySz0.js +31 -0
  88. package/dist/chunk-DsHQySz0.js.map +1 -0
  89. package/dist/chunk-DwoUyHHh.js +281 -0
  90. package/dist/chunk-DwoUyHHh.js.map +1 -0
  91. package/dist/chunk-IaIDQflj.d.cts +2315 -0
  92. package/dist/chunk-IaIDQflj.d.ts +2315 -0
  93. package/dist/chunk-cVXLsZfL.d.ts +839 -0
  94. package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
  95. package/dist/chunk-nJQxbOwQ.cjs +8962 -0
  96. package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
  97. package/dist/chunk-o9jaxhCO.js +8852 -0
  98. package/dist/chunk-o9jaxhCO.js.map +1 -0
  99. package/dist/chunk-p-Tt_Lwz.js +14 -0
  100. package/dist/chunk-p-Tt_Lwz.js.map +1 -0
  101. package/dist/engines/index.cjs +2046 -3401
  102. package/dist/engines/index.cjs.map +1 -1
  103. package/dist/engines/index.d.cts +1510 -1550
  104. package/dist/engines/index.d.ts +1510 -1550
  105. package/dist/engines/index.js +2039 -3380
  106. package/dist/engines/index.js.map +1 -1
  107. package/dist/handlers/index.cjs +47 -93
  108. package/dist/handlers/index.cjs.map +1 -1
  109. package/dist/handlers/index.d.cts +61 -103
  110. package/dist/handlers/index.d.ts +61 -103
  111. package/dist/handlers/index.js +27 -36
  112. package/dist/handlers/index.js.map +1 -1
  113. package/dist/index.cjs +3347 -4398
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.cts +8 -7297
  116. package/dist/index.d.ts +8 -7297
  117. package/dist/index.js +2997 -3187
  118. package/dist/index.js.map +1 -1
  119. package/dist/plugins/index.cjs +482 -949
  120. package/dist/plugins/index.cjs.map +1 -1
  121. package/dist/plugins/index.d.cts +44 -61
  122. package/dist/plugins/index.d.ts +44 -61
  123. package/dist/plugins/index.js +471 -915
  124. package/dist/plugins/index.js.map +1 -1
  125. package/dist/seams/index.cjs +77 -140
  126. package/dist/seams/index.cjs.map +1 -1
  127. package/dist/seams/index.d.cts +125 -158
  128. package/dist/seams/index.d.ts +125 -158
  129. package/dist/seams/index.js +41 -71
  130. package/dist/seams/index.js.map +1 -1
  131. package/dist/strings/fr/index.cjs +2130 -2116
  132. package/dist/strings/fr/index.cjs.map +1 -1
  133. package/dist/strings/fr/index.d.cts +3 -5
  134. package/dist/strings/fr/index.d.ts +3 -5
  135. package/dist/strings/fr/index.js +2125 -2114
  136. package/dist/strings/fr/index.js.map +1 -1
  137. package/dist/strings/index.cjs +2331 -2625
  138. package/dist/strings/index.cjs.map +1 -1
  139. package/dist/strings/index.d.cts +3 -731
  140. package/dist/strings/index.d.ts +3 -731
  141. package/dist/strings/index.js +2324 -2615
  142. package/dist/strings/index.js.map +1 -1
  143. package/dist/testing/index.cjs +214 -276
  144. package/dist/testing/index.cjs.map +1 -1
  145. package/dist/testing/index.d.cts +61 -121
  146. package/dist/testing/index.d.ts +61 -121
  147. package/dist/testing/index.js +208 -273
  148. package/dist/testing/index.js.map +1 -1
  149. package/dist/time/index.cjs +23 -23
  150. package/dist/time/index.cjs.map +1 -1
  151. package/dist/time/index.d.cts +5 -7
  152. package/dist/time/index.d.ts +5 -7
  153. package/dist/time/index.js +18 -21
  154. package/dist/time/index.js.map +1 -1
  155. package/package.json +14 -15
  156. package/src/agent/rules/stateDelta.ts +1 -0
  157. package/src/agent/stores/agentThreads.ts +1 -4
  158. package/src/bus/rules/bus.ts +1 -2
  159. package/src/bus/rules/defineRegistry.ts +3 -5
  160. package/src/bus/rules/types.ts +6 -7
  161. package/src/chrome/stores/uiStore.ts +4 -2
  162. package/src/embed/rules/fieldDependencies.ts +2 -0
  163. package/src/embed/rules/safetyRules.ts +2 -0
  164. package/src/embed/rules/tableCode.ts +4 -3
  165. package/src/index.ts +6 -27
  166. package/src/itinerary/rules/import.ts +6 -8
  167. package/src/plugins/contracts/plugin.ts +4 -2
  168. package/src/seams/rules/formatters.ts +5 -3
  169. package/src/testing/index.ts +1 -5
  170. package/src/viewer/rules/platformViewer.ts +1 -0
  171. package/dist/bus-BwiNiXdH.d.ts +0 -514
  172. package/dist/bus-DzmhPwdK.d.cts +0 -514
  173. package/dist/chainModel-B23pEP_1.d.cts +0 -127
  174. package/dist/chainModel-B23pEP_1.d.ts +0 -127
  175. package/dist/chunk-2HFY7ETU.js +0 -5721
  176. package/dist/chunk-2HFY7ETU.js.map +0 -1
  177. package/dist/chunk-355TOXSB.js +0 -72
  178. package/dist/chunk-355TOXSB.js.map +0 -1
  179. package/dist/chunk-4ZCUZVSV.js +0 -10275
  180. package/dist/chunk-4ZCUZVSV.js.map +0 -1
  181. package/dist/chunk-6HEKY3NF.js +0 -95
  182. package/dist/chunk-6HEKY3NF.js.map +0 -1
  183. package/dist/chunk-7GFLGGBX.cjs +0 -8
  184. package/dist/chunk-7GFLGGBX.cjs.map +0 -1
  185. package/dist/chunk-7NBRCENN.cjs +0 -19
  186. package/dist/chunk-7NBRCENN.cjs.map +0 -1
  187. package/dist/chunk-AF5GCXE3.js +0 -8
  188. package/dist/chunk-AF5GCXE3.js.map +0 -1
  189. package/dist/chunk-CJDIFRGZ.cjs +0 -2005
  190. package/dist/chunk-CJDIFRGZ.cjs.map +0 -1
  191. package/dist/chunk-CNPZY7N3.js +0 -349
  192. package/dist/chunk-CNPZY7N3.js.map +0 -1
  193. package/dist/chunk-DZJHTWSF.cjs +0 -45
  194. package/dist/chunk-DZJHTWSF.cjs.map +0 -1
  195. package/dist/chunk-EABIHHWA.js +0 -42
  196. package/dist/chunk-EABIHHWA.js.map +0 -1
  197. package/dist/chunk-EKZWV6RS.cjs +0 -415
  198. package/dist/chunk-EKZWV6RS.cjs.map +0 -1
  199. package/dist/chunk-EOKRXXAC.cjs +0 -24
  200. package/dist/chunk-EOKRXXAC.cjs.map +0 -1
  201. package/dist/chunk-F73W2ZTJ.js +0 -1126
  202. package/dist/chunk-F73W2ZTJ.js.map +0 -1
  203. package/dist/chunk-H4DVOZ5O.js +0 -1897
  204. package/dist/chunk-H4DVOZ5O.js.map +0 -1
  205. package/dist/chunk-HI52PBFT.cjs +0 -10314
  206. package/dist/chunk-HI52PBFT.cjs.map +0 -1
  207. package/dist/chunk-IDBXFBLG.cjs +0 -1225
  208. package/dist/chunk-IDBXFBLG.cjs.map +0 -1
  209. package/dist/chunk-LBWTJZUJ.js +0 -297
  210. package/dist/chunk-LBWTJZUJ.js.map +0 -1
  211. package/dist/chunk-NCLA6DKD.cjs +0 -310
  212. package/dist/chunk-NCLA6DKD.cjs.map +0 -1
  213. package/dist/chunk-O4MC5DPD.js +0 -19
  214. package/dist/chunk-O4MC5DPD.js.map +0 -1
  215. package/dist/chunk-OP37FKW6.cjs +0 -98
  216. package/dist/chunk-OP37FKW6.cjs.map +0 -1
  217. package/dist/chunk-OQSYFH3Z.cjs +0 -5945
  218. package/dist/chunk-OQSYFH3Z.cjs.map +0 -1
  219. package/dist/chunk-PACIO4NS.cjs +0 -26
  220. package/dist/chunk-PACIO4NS.cjs.map +0 -1
  221. package/dist/chunk-PSZ2R3TC.cjs +0 -75
  222. package/dist/chunk-PSZ2R3TC.cjs.map +0 -1
  223. package/dist/chunk-QFO5CZG2.cjs +0 -136
  224. package/dist/chunk-QFO5CZG2.cjs.map +0 -1
  225. package/dist/chunk-QL63MUEW.cjs +0 -140
  226. package/dist/chunk-QL63MUEW.cjs.map +0 -1
  227. package/dist/chunk-RFUPPVZO.js +0 -17
  228. package/dist/chunk-RFUPPVZO.js.map +0 -1
  229. package/dist/chunk-RPG2LWMP.js +0 -23
  230. package/dist/chunk-RPG2LWMP.js.map +0 -1
  231. package/dist/chunk-TIBXK6B7.cjs +0 -12
  232. package/dist/chunk-TIBXK6B7.cjs.map +0 -1
  233. package/dist/chunk-UU65VNEV.js +0 -381
  234. package/dist/chunk-UU65VNEV.js.map +0 -1
  235. package/dist/chunk-VGX6TR2I.js +0 -209
  236. package/dist/chunk-VGX6TR2I.js.map +0 -1
  237. package/dist/chunk-WUTDDBVP.js +0 -130
  238. package/dist/chunk-WUTDDBVP.js.map +0 -1
  239. package/dist/chunk-WVQQLKCI.cjs +0 -224
  240. package/dist/chunk-WVQQLKCI.cjs.map +0 -1
  241. package/dist/chunk-WZYXG3SE.js +0 -111
  242. package/dist/chunk-WZYXG3SE.js.map +0 -1
  243. package/dist/chunk-XDI2X3KE.js +0 -6
  244. package/dist/chunk-XDI2X3KE.js.map +0 -1
  245. package/dist/chunk-XKHLRIC7.cjs +0 -381
  246. package/dist/chunk-XKHLRIC7.cjs.map +0 -1
  247. package/dist/context-DNtd2WUv.d.cts +0 -11666
  248. package/dist/context-DgB72Bur.d.ts +0 -11666
  249. package/dist/en-Bu4Ti9Ev.d.cts +0 -2315
  250. package/dist/en-Bu4Ti9Ev.d.ts +0 -2315
  251. package/dist/shareLink-B6hlt942.d.ts +0 -144
  252. package/dist/shareLink-C7rIMb7x.d.ts +0 -527
  253. package/dist/shareLink-CnTxxXjp.d.cts +0 -144
  254. package/dist/shareLink-DyZVYH2V.d.cts +0 -527
  255. package/dist/studioPlugin-C3C7VjMy.d.ts +0 -847
  256. package/dist/studioPlugin-Cf3OBNUv.d.cts +0 -847
  257. package/dist/types-BzJRV6UI.d.cts +0 -845
  258. package/dist/types-BzJRV6UI.d.ts +0 -845
  259. package/dist/zoneForm-CdYNtnnA.d.cts +0 -320
  260. package/dist/zoneForm-mG85yt5e.d.ts +0 -320
@@ -0,0 +1,525 @@
1
+ import { a as StudioToolContext, io as StudioToolInputs, oo as StudioToolOutputs, yi as ShareLinkTarget } from "./chunk-mIaCX9EJ.cjs";
2
+ import { Jt as ToolFailure, Zt as ToolResultOf } from "./chunk-CLGvBOVH.cjs";
3
+ import { d as ShareLinkActions, p as ShareLinkScope } from "./chunk-DIFayl2P.cjs";
4
+ /** The tools a share link runs, by name. */
5
+ type ShareLinkTool = "studio.shareLink.disable" | "studio.shareLink.mint" | "studio.shareLink.rotate";
6
+ /**
7
+ * ShareLinkDispatch runs one of the tools a share link runs in the given context, and resolves
8
+ * with the tool's result.
9
+ *
10
+ * The result holds that tool's own data, as {@link StudioToolOutputs} states it: an `ok` answer
11
+ * of a mint and of a reset holds the share token, which is never empty. So the dispatch a host
12
+ * hands over is one typed by the studio's outputs: a bus built with `StudioToolInputs` and
13
+ * `StudioToolOutputs`, or a binding's own dispatch that answers each verb's data.
14
+ *
15
+ * The type is all that holds a host's own dispatch to that, and a bus parses no answer. So the
16
+ * engine reads the token through `mintedShareToken`, whose rule for a token is the contract's:
17
+ * an `ok` answer that holds none is no link. A mint answered so is the failure with nothing to
18
+ * word (see {@link ShareLinkFailure}), and a reset answered so resolves `"refused"` (see
19
+ * {@link ShareLinkEngine.rotate}).
20
+ *
21
+ * It takes the context because a reset and a disable run in one the engine layers its own
22
+ * confirm gate over (see {@link ShareLinkEngine.rotate}). A tool bus's dispatch never rejects: a
23
+ * refusal is a result whose `ok` is false. One that throws or rejects all the same is answered
24
+ * as a refusal the engine builds from what was thrown, and never reaches the engine's caller. A
25
+ * host holding a bus writes it as `(context, name, input) => bus.dispatch(context, name, input)`.
26
+ */
27
+ type ShareLinkDispatch = <TName extends ShareLinkTool>(context: StudioToolContext, name: TName, input: StudioToolInputs[TName]) => Promise<ToolResultOf<StudioToolOutputs, TName>>;
28
+ /**
29
+ * ShareLinkReadResult is what a read of a share link answers: the link's token, null where the
30
+ * resource has none set, or the refusal.
31
+ */
32
+ type ShareLinkReadResult = {
33
+ readonly ok: true;
34
+ /** The link's token, or null where no link is set. Never empty. */
35
+ readonly token: string | null;
36
+ } | ToolFailure;
37
+ /**
38
+ * ShareLinkRead reads a resource's share link without setting one, in the given context, and
39
+ * resolves with what it found.
40
+ *
41
+ * `readShareLink` of `@mountaya/studio/handlers` is the studio's own: it reads an itinerary's link
42
+ * through the context's persistence and a collection's through its client, and answers a
43
+ * refusal rather than throwing. A read of the host's own is held to the same answer by its type
44
+ * alone, so the engine holds an `ok` token to the contract's rule for one (a token that is empty
45
+ * is no link) and answers one that throws or rejects as the refusal it builds from what was
46
+ * thrown.
47
+ *
48
+ * A read and not a dispatch, because opening a share surface changes nothing: no verb runs, no
49
+ * confirmation is asked, and the token it finds enters no transcript.
50
+ */
51
+ type ShareLinkRead = (context: StudioToolContext, target: ShareLinkTarget) => Promise<ShareLinkReadResult>;
52
+ /**
53
+ * ShareLinkConfig is what a share link reads from its host, all of it replaceable mid-life
54
+ * through {@link ShareLinkEngine.configure}.
55
+ */
56
+ interface ShareLinkConfig {
57
+ /**
58
+ * Whether the viewer holds the edit grant on the resource, which reading, creating, resetting
59
+ * and disabling its link all need: a write role in the organization that owns it, or, for a
60
+ * personal resource, its authorship. False while the record that answers is loading. No read
61
+ * is sent without it, so a viewer whose role reads only is never handed a link, nor asked to
62
+ * meet the refusal the API would answer.
63
+ */
64
+ readonly canManage: boolean;
65
+ /**
66
+ * The tool context the link's tools and its read run in. Read when one is run, so the one
67
+ * configured last is the one used, and never copied: a reset and a disable run in a layer over
68
+ * it, which keeps its late-bound seams resolving when they are read.
69
+ */
70
+ readonly context: StudioToolContext;
71
+ /** Runs the link's tools. Read when a tool is run, so the one configured last is the one used. */
72
+ readonly dispatch: ShareLinkDispatch;
73
+ /**
74
+ * Reads the link without setting one. Read when the link is asked for, so the one configured
75
+ * last is the one used. `readShareLink` of `@mountaya/studio/handlers` is the studio's own.
76
+ */
77
+ readonly read: ShareLinkRead;
78
+ /**
79
+ * Whether the resource can hold a link at all. Only `"organization"` is ever sent a read or a
80
+ * create, and only for a viewer who holds `canManage`.
81
+ */
82
+ readonly scope: ShareLinkScope;
83
+ /**
84
+ * The resource the link is for. Compared by kind and id: one that differs is another question,
85
+ * so the engine drops what it held and reads again.
86
+ */
87
+ readonly target: ShareLinkTarget;
88
+ }
89
+ /**
90
+ * ShareLinkEngineOptions is the {@link ShareLinkConfig} an engine starts with, plus the one
91
+ * setting that is fixed for its life.
92
+ */
93
+ interface ShareLinkEngineOptions extends ShareLinkConfig {
94
+ /**
95
+ * The link's token when the host already holds it, so a surface shows the link from its first
96
+ * frame. The first subscriber still reads the link, which confirms the token, replaces one that
97
+ * was reset elsewhere, or drops one that was disabled elsewhere.
98
+ *
99
+ * @default null
100
+ */
101
+ readonly token?: string | null | undefined;
102
+ }
103
+ /**
104
+ * ShareLinkFailure is a read or a create that gave no answer, as a surface shows it: the refusal
105
+ * to word and whether offering a retry would be honest.
106
+ */
107
+ interface ShareLinkFailure {
108
+ /**
109
+ * The refusal, for a surface to word with its `detail` or with `mapToolError`. Null when the
110
+ * request gave nothing to word: a read or a dispatch that threw or rejected, or an `ok` answer
111
+ * that holds no token. A surface shows its own generic line for that one.
112
+ */
113
+ readonly failure: ToolFailure | null;
114
+ /**
115
+ * Whether asking again could answer, by `isRetryableShareLinkFailure`. Always true for a
116
+ * failure with nothing to word, since a second attempt there is as good as the first.
117
+ */
118
+ readonly retryable: boolean;
119
+ }
120
+ /**
121
+ * ShareLinkSnapshot is what a {@link ShareLinkEngine} answers: the link, and what the engine has
122
+ * decided about it.
123
+ *
124
+ * It names the target it answers for, so a reader holding one knows which resource the link
125
+ * opens and never takes one resource's link for another's.
126
+ */
127
+ interface ShareLinkSnapshot {
128
+ /**
129
+ * What Reset and Disable are worth offering, by `shareLinkActions` over the configured
130
+ * capability and scope and the token held. {@link ShareLinkEngine.rotate} and
131
+ * {@link ShareLinkEngine.disable} run only what reads `"ready"` here.
132
+ *
133
+ * While either is in flight, from its call to its answer and its confirmation being asked
134
+ * included, neither is offered: what would read `"ready"` reads `"waiting"`, since one link
135
+ * runs one action at a time. A refusal and an absence read as they do.
136
+ */
137
+ readonly actions: ShareLinkActions;
138
+ /**
139
+ * The management action whose request is running, or null. It is set when the confirmation is
140
+ * approved, never while it is asked, so a surface spins a control over the request alone. One
141
+ * link runs one action at a time, so it names the only one in flight.
142
+ */
143
+ readonly busy: keyof ShareLinkActions | null;
144
+ /**
145
+ * What last happened to the link through this engine, or null while nothing has: `"read"` once
146
+ * a read answered, the link or that none is set, `"minted"` once a create answered with a link,
147
+ * `"rotated"` and `"disabled"` once a reset and a disable settled. A surface with a live region
148
+ * announces it: the swap from a placeholder to a link, or from one link to another, is
149
+ * otherwise silent.
150
+ */
151
+ readonly change: "disabled" | "minted" | "read" | "rotated" | null;
152
+ /**
153
+ * Whether the engine knows if a link is set for the target: a read or a create answered, a
154
+ * reset or a disable settled, or the host handed a token over. While it is false a null `token`
155
+ * says nothing. Once it is true a null `token` is a resource with no link, which a surface
156
+ * offers to create through {@link ShareLinkEngine.mint}.
157
+ */
158
+ readonly known: boolean;
159
+ /**
160
+ * Why the latest create gave no link, or null. It leaves when a create is asked again, when a
161
+ * reset settles, when a disable sent after that create settles, and with the target it was
162
+ * about.
163
+ */
164
+ readonly mintFailure: ShareLinkFailure | null;
165
+ /** Whether a create is in flight. */
166
+ readonly minting: boolean;
167
+ /**
168
+ * Why the latest read gave no answer, or null. It leaves when the link is read again, when a
169
+ * create, a reset or a disable sent after that read settles, and with the target it was about.
170
+ *
171
+ * Until one of those it reads beside whatever token is held: a link the host handed over whose
172
+ * confirming read failed is still the link a surface shows, with the failure and its retry.
173
+ */
174
+ readonly readFailure: ShareLinkFailure | null;
175
+ /** Whether a read is in flight. */
176
+ readonly reading: boolean;
177
+ /** The resource the snapshot answers for. One object until the target changes by kind or id. */
178
+ readonly target: ShareLinkTarget;
179
+ /** The link's token, or null while there is no link, or none is known yet (see `known`). */
180
+ readonly token: string | null;
181
+ }
182
+ /**
183
+ * ShareLinkActionOutcome is what a reset or a disable came to, for the surface that asked:
184
+ *
185
+ * - `"settled"`: the link is as the reader asked. `linkWasActive` is false when a disable found
186
+ * no link to revoke (see `isShareLinkDisableSettled`), which a surface reports in other words.
187
+ * - `"refused"`: the verb failed. `failure` is the refusal to word. A dispatch that threw or
188
+ * rejected is one too, classified as the tool bus classifies a handler that throws: `internal`
189
+ * unless the thrown value carries a status the bus knows. So is a reset answered `ok` with no
190
+ * token, which is `internal`.
191
+ * - `"withheld"`: the confirmation was refused or left to expire, so no verb ran. There is
192
+ * nothing to report: the reader got what they chose.
193
+ * - `"skipped"`: the engine ran nothing, because the action was not `"ready"`, an action of
194
+ * this link was already in flight, or nobody was watching.
195
+ */
196
+ type ShareLinkActionOutcome = {
197
+ readonly failure: ToolFailure;
198
+ readonly status: "refused";
199
+ } | {
200
+ readonly linkWasActive: boolean;
201
+ readonly status: "settled";
202
+ } | {
203
+ readonly status: "skipped";
204
+ } | {
205
+ readonly status: "withheld";
206
+ };
207
+ /**
208
+ * ShareLinkEngine is the machine behind a resource's share link: it reads the link once somebody
209
+ * watches, keeps the token, that none is set, or the reason it could not tell, and creates,
210
+ * resets and disables the link through the tool bus when the reader asks.
211
+ *
212
+ * What it does, in the order a surface meets it:
213
+ *
214
+ * - **The read.** The first subscriber reads the link of an `"organization"` resource through
215
+ * `read`, which sets nothing, so opening a surface hands no link out. A `"pending"` scope holds
216
+ * the read until the record answers, and a `"personal"` one is never sent it: the API creates
217
+ * no link for one. Nor is a viewer without the edit grant (`canManage` false): the API answers
218
+ * their read 403, and the snapshot's `actions` already say they may not act on a link. A grant
219
+ * that lands later, once the roster that answers it has, sends the read then.
220
+ * - **No link.** A read that finds none leaves the snapshot `known` with no token, and
221
+ * {@link ShareLinkEngine.mint} creates one through `studio.shareLink.mint` when the reader asks.
222
+ * - **A refusal.** A read or a create that gave no answer is the snapshot's `readFailure` or
223
+ * `mintFailure`, with whether a retry is worth offering (`isRetryableShareLinkFailure`).
224
+ * Nothing retries by itself: {@link ShareLinkEngine.read} and {@link ShareLinkEngine.mint} ask
225
+ * again.
226
+ * - **Reset and Disable.** {@link ShareLinkEngine.rotate} and {@link ShareLinkEngine.disable}
227
+ * run what the snapshot's `actions` report `"ready"`, one at a time, and resolve with what
228
+ * each came to. The tool bus asks the confirmation. A withheld one leaves nothing to report:
229
+ * no verb ran, nothing spun, and the actions that waited while it was asked are offered again.
230
+ *
231
+ * Every write goes through `dispatch`, so a person pressing a control and an agent calling the
232
+ * same tools drive one link. Each write's answer is the link as it now stands, so the engine
233
+ * takes it from there and reads nothing again: a create, a reset and a disable each cost one
234
+ * request.
235
+ *
236
+ * The lifecycle is the listeners. Constructing one runs nothing; the first subscriber reads the
237
+ * link; the last unsubscribe parks. A parked engine runs no command and drops the answer of a
238
+ * read that lands on it, so the next subscriber reads again. React's StrictMode mounts,
239
+ * unmounts and mounts again before any answer can land, which parks and resumes around the one
240
+ * read in flight and reads once. A create, a reset or a disable in flight at a park is a write
241
+ * that happened, so its answer is kept. {@link ShareLinkEngine.dispose} is the latch, for an
242
+ * owner that is not a component.
243
+ *
244
+ * A read or a create and a reset or a disable can be in flight together, and their answers land
245
+ * in any order. Which answer the link stands on is decided by what each request does, and where
246
+ * that leaves a doubt, by the order the requests left in: a read and a create leave when they
247
+ * are sent, a reset or a disable when its confirmation is approved.
248
+ *
249
+ * - **A reset outranks every read and create in flight with it.** Neither issues another link
250
+ * where one is set, so the token a reset answers with is the newest whichever the server ran
251
+ * first. The reset's token stands whatever they answered before it, and one still in flight
252
+ * when the reset settles has its answer dropped: it may carry the token the reset retired. A
253
+ * reset answered `ok` with no token outranks them as well, since the server may have made it,
254
+ * and the engine then reads the link that stands.
255
+ * - **A disable outranks the requests sent before it, and yields to one sent after it.** A read
256
+ * or a create sent first may carry the token the disable revoked, so its answer is dropped. One
257
+ * sent after the disable left answers the link as it stands once the disable has run, so it is
258
+ * kept whichever answer lands first, and the disable's own outcome still says what the verb
259
+ * came to. The order the two left in is the order the engine takes the server to have run them
260
+ * in, which is the most a client can know of it.
261
+ * - **A later answer outranks an earlier one.** A read or a create whose answer lands after the
262
+ * answer of one sent later is dropped, so a read that set out before a create never takes back
263
+ * the link the create made.
264
+ *
265
+ * A request whose answer is dropped stops the snapshot reading `reading` or `minting`, unless one
266
+ * of its kind sent after it is still out, and leaves the token, the `change` and the absence of a
267
+ * failure the write left.
268
+ *
269
+ * A listener is told through `notifyListeners`: one that throws stops neither the engine nor the
270
+ * listeners after it, and its fault reaches the program as an uncaught error on a microtask.
271
+ *
272
+ * It keeps no time: nothing here is debounced, throttled or timed out, so the engine takes no
273
+ * `Clock` and arms no timer.
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * declare const context: StudioToolContext;
278
+ * declare const read: ShareLinkRead;
279
+ * declare function render(snapshot: ShareLinkSnapshot): void;
280
+ * declare function report(failure: ToolFailure): void;
281
+ *
282
+ * const link = new ShareLinkEngine({
283
+ * canManage: true,
284
+ * context,
285
+ * dispatch: (context, name, input) => bus.dispatch(context, name, input),
286
+ * read,
287
+ * scope: "organization",
288
+ * target: { id: "itin-1", kind: "itinerary" },
289
+ * });
290
+ * const release = link.subscribe(() => render(link.getSnapshot()));
291
+ *
292
+ * const outcome = await link.rotate();
293
+ * if (outcome.status === "refused") {
294
+ * report(outcome.failure);
295
+ * }
296
+ * release();
297
+ * ```
298
+ */
299
+ declare class ShareLinkEngine {
300
+ private config;
301
+ /** The target the state below answers for, replaced only by one that differs by kind or id. */
302
+ private target;
303
+ private token;
304
+ private known;
305
+ private readFailure;
306
+ private mintFailure;
307
+ private change;
308
+ private reading;
309
+ private minting;
310
+ /**
311
+ * Whether the link has been read under this target, so that no later subscriber reads again:
312
+ * its token, that none is set, its failure or its read in flight is what the engine holds. A
313
+ * settled disable raises it, since its reader asked for no link.
314
+ */
315
+ private asked;
316
+ /**
317
+ * The action called under this target and not yet answered, a confirmation being asked
318
+ * included, or null. One slot, because a link takes one management action at a time.
319
+ */
320
+ private acting;
321
+ /** Whether the confirmation of {@link acting} was approved, so its request is running. */
322
+ private running;
323
+ /** Counts the targets answered for: an answer sent under an earlier one is ignored. */
324
+ private epoch;
325
+ /**
326
+ * Counts the requests that left, a read and a create when they are sent and a reset or a
327
+ * disable at its approval, so each one holds its place in the order they were sent.
328
+ */
329
+ private sent;
330
+ /**
331
+ * The highest place a settled write outranks, or zero while none has settled: a read or a
332
+ * create sent at or before it has its answer dropped. A reset outranks every request sent by the
333
+ * time it settles, and a disable the ones sent before it.
334
+ */
335
+ private outranked;
336
+ /**
337
+ * The place of the read or the create whose answer the engine holds, or zero while it holds
338
+ * none of theirs.
339
+ */
340
+ private answeredAt;
341
+ /** The place of the latest read whose answer landed while nobody watched, or zero. */
342
+ private unheard;
343
+ /** The place of the read whose failure the engine holds, or zero while it holds none. */
344
+ private readFailedAt;
345
+ /** The place of the create whose failure the engine holds, or zero while it holds none. */
346
+ private mintFailedAt;
347
+ /** The place of the read sent last, or zero before any, which `reading` follows. */
348
+ private latestRead;
349
+ /** The place of the create sent last, or zero before any, which `minting` follows. */
350
+ private latestMint;
351
+ private snapshot;
352
+ private readonly subscriptions;
353
+ /** Whether nobody is watching. A parked engine asks for nothing and runs no command. */
354
+ private parked;
355
+ private disposed;
356
+ /**
357
+ * Constructing one holds the options and does nothing else: nothing is read and no tool is run.
358
+ * A React binding constructs during a render React is free to throw away, and a constructor
359
+ * with a side effect would leave the discarded copy reading.
360
+ */
361
+ constructor(options: ShareLinkEngineOptions);
362
+ /** getSnapshot returns the current answer, by reference and stable between changes. */
363
+ getSnapshot(): ShareLinkSnapshot;
364
+ /**
365
+ * subscribe registers a listener for every change of the snapshot, and returns its own
366
+ * unsubscribe, which is idempotent.
367
+ *
368
+ * The first listener resumes the engine, which reads the link unless it already has, and the
369
+ * last one leaving parks it. That is the whole lifecycle a component can express correctly:
370
+ * React tears an effect down and sets it up again with the same object under StrictMode, so a
371
+ * latch here would leave a live surface bound to a dead engine. Each call is its own
372
+ * subscription, so two owners subscribing one shared function each hold the engine until they
373
+ * release it.
374
+ */
375
+ subscribe(listener: () => void): () => void;
376
+ /**
377
+ * configure replaces the configuration, and tells its listeners only when the answer changed.
378
+ *
379
+ * A binding calls it on every render, so an unchanged configuration costs a comparison. A
380
+ * changed capability or scope moves the snapshot's `actions`, and a scope that turns
381
+ * `"organization"` sends the read a `"pending"` one held. A target that differs by kind or id
382
+ * is another question: the token, what the engine knew, the failures and the latest change are
383
+ * dropped, the answer of anything in flight for the previous target is ignored, an action still
384
+ * running for it holds back none of the new target's, and the link is read again. A parked
385
+ * engine keeps the configuration for its next subscriber.
386
+ */
387
+ configure(config: ShareLinkConfig): void;
388
+ /**
389
+ * dispose parks the engine and drops every listener, for good.
390
+ *
391
+ * Idempotent, and every call after it is a no-op rather than an error: an owner torn down
392
+ * mid-request should not have to guard the calls it already queued. A request in flight still
393
+ * reaches the tool it was sent to; its answer changes nothing here.
394
+ */
395
+ dispose(): void;
396
+ /**
397
+ * read reads the link again, and resolves once that read has answered.
398
+ *
399
+ * The first subscriber reads by itself. This is the retry a surface offers under a
400
+ * `readFailure` whose `retryable` is true. The previous failure leaves the snapshot while the
401
+ * read is in flight, so a surface shows its pending state.
402
+ *
403
+ * It does nothing, and resolves at once, while a read is in flight, while the scope is not
404
+ * `"organization"`, while the viewer does not hold `canManage`, while parked, and after
405
+ * {@link ShareLinkEngine.dispose}. It never rejects.
406
+ */
407
+ read(): Promise<void>;
408
+ /**
409
+ * mint creates the link through `studio.shareLink.mint`, and resolves once that create has
410
+ * answered: the reader's Create, which a surface offers once the snapshot is `known` with no
411
+ * token. The verb gets or creates, so a link made elsewhere in the meantime is the one it
412
+ * answers, and no URL already handed out is retired. A refusal is the snapshot's `mintFailure`,
413
+ * and asking again is its retry.
414
+ *
415
+ * It does nothing, and resolves at once, while a create is in flight, while a link is held,
416
+ * while a reset or a disable of this link is in flight, while the scope is not
417
+ * `"organization"`, while the viewer does not hold `canManage`, while parked, and after
418
+ * {@link ShareLinkEngine.dispose}. It never rejects.
419
+ */
420
+ mint(): Promise<void>;
421
+ /**
422
+ * rotate resets the link through `studio.shareLink.rotate`: the token held is retired, every
423
+ * URL carrying it stops working, and the snapshot takes the one issued in its place.
424
+ *
425
+ * The tool bus asks the confirmation inside the dispatch, so the tool runs in a context whose
426
+ * confirm gate the engine layers over the configured one: the snapshot's `busy` turns
427
+ * `"rotate"` when the gate approves, never while it is asked. A context with no confirm gate
428
+ * refuses, as the bus does for one.
429
+ *
430
+ * It runs only while the snapshot's `actions.rotate` is `"ready"`, which it is not while a
431
+ * reset or a disable of this target is in flight (one whose confirmation is still asked
432
+ * included), and while somebody is watching; otherwise it resolves `"skipped"`. One at a time,
433
+ * because two writes side by side would leave the token to whichever answer landed last. A
434
+ * refusal leaves the link, the latest change and a read's or a create's failure as they were.
435
+ * An answer that lands once the engine answers for another target, or after
436
+ * {@link ShareLinkEngine.dispose}, changes nothing either, and the outcome still says what the
437
+ * verb came to.
438
+ *
439
+ * It never rejects. A `dispatch` that throws or rejects resolves `"refused"` with the failure
440
+ * the tool bus builds for a handler that throws, and leaves the reset free to be asked again.
441
+ * So does an `ok` answer that holds no token, with the `internal` refusal the verb gives for a
442
+ * link that holds none: its sentence says the link held may no longer open. The engine then
443
+ * reads the link that stands, and drops the answer of a read or a create sent before the reset,
444
+ * which may carry the link it retired. That read is sent as the first one is, to a watched
445
+ * engine under the `"organization"` scope: a parked engine sends it for its next subscriber,
446
+ * and another scope once it turns `"organization"`.
447
+ */
448
+ rotate(): Promise<ShareLinkActionOutcome>;
449
+ /**
450
+ * disable revokes the link through `studio.shareLink.disable`: every URL carrying its token
451
+ * stops working, and the snapshot holds no token and knows that none is set. No later
452
+ * subscriber reads it again; {@link ShareLinkEngine.mint} creates another.
453
+ *
454
+ * On a `"personal"` resource a `not-found` answer settles it too, with `linkWasActive` false:
455
+ * no link was active, which is what the reader asked for (`isShareLinkDisableSettled`).
456
+ *
457
+ * The confirmation, the `busy` flag (`"disable"`) and the conditions it runs under are
458
+ * {@link ShareLinkEngine.rotate}'s, read off `actions.disable`.
459
+ */
460
+ disable(): Promise<ShareLinkActionOutcome>;
461
+ /** ask sends the first read of a target, once a scope that can hold a link is known. */
462
+ private ask;
463
+ /**
464
+ * mayAsk reports whether the link may be read or created as configured: the resource is an
465
+ * organization's, and the viewer holds the edit grant every request of its link needs.
466
+ */
467
+ private mayAsk;
468
+ /**
469
+ * runAsk sends one read or one create and keeps its answer, unless the engine has moved on by
470
+ * then or a write sent after it has settled.
471
+ */
472
+ private runAsk;
473
+ /** sendRead reads the link through the configured read, a throw answered as a refusal. */
474
+ private sendRead;
475
+ /** sendMint creates the link through the bus, a dispatch that throws answered as a refusal. */
476
+ private sendMint;
477
+ /** act runs one management action and settles the snapshot with its answer. */
478
+ private act;
479
+ /**
480
+ * settleRotate ends a reset with its answer. The token it issued is the newest whatever a read
481
+ * or a create answered or will answer, so every request sent by now is outranked.
482
+ *
483
+ * An `ok` answer that holds no token is refused as the verb refuses a link that holds none,
484
+ * and the engine was handed no link to show. The server answered `ok` all the same, so it may
485
+ * have retired the link held: every read and create sent by now is outranked, since its answer
486
+ * may carry that link, and the engine reads which link stands
487
+ * ({@link ShareLinkEngine.readStandingLink}). Until that read answers, the link and the latest
488
+ * change read as they did.
489
+ */
490
+ private settleRotate;
491
+ /**
492
+ * readStandingLink reads which link stands, once a reset answered `ok` with no token.
493
+ *
494
+ * It is sent while somebody watches a resource whose scope is `"organization"`, the one scope a
495
+ * read is sent under, for a viewer who holds the grant. On a parked engine, and under a scope or
496
+ * a grant that takes no read by now, the question is left open: the next subscriber asks it,
497
+ * or the configuration that takes one does. An engine that was disposed, or that answers for
498
+ * another target by now, asks nothing.
499
+ */
500
+ private readStandingLink;
501
+ /**
502
+ * settleDisable ends a disable with its answer, judged under the scope it was sent under and
503
+ * at the place it left in.
504
+ */
505
+ private settleDisable;
506
+ /**
507
+ * refuse ends an action whose verb did not run or failed, and answers what it came to:
508
+ * `"withheld"` for a confirmation nobody approved, `"refused"` with the failure otherwise.
509
+ * Nothing in the snapshot changes but the action in flight.
510
+ */
511
+ private refuse;
512
+ /**
513
+ * finish ends the action in flight: an action may be called again, and the snapshot stops
514
+ * spinning and takes what `apply` writes, in one change. An engine that was disposed, or that
515
+ * answers for another target by now, keeps everything as it is: the action it holds, if any,
516
+ * is the new target's.
517
+ */
518
+ private finish;
519
+ /** compose assembles the snapshot the engine's state stands for now. */
520
+ private compose;
521
+ /** publish replaces the snapshot when the state moved it, and tells every listener. */
522
+ private publish;
523
+ }
524
+ export { ShareLinkEngineOptions as a, ShareLinkReadResult as c, ShareLinkEngine as i, ShareLinkSnapshot as l, ShareLinkConfig as n, ShareLinkFailure as o, ShareLinkDispatch as r, ShareLinkRead as s, ShareLinkActionOutcome as t };
525
+ //# sourceMappingURL=chunk-DIGF58ux.d.cts.map
@@ -0,0 +1,101 @@
1
+ const restStatusCodes = {
2
+ 400: "invalid-input",
3
+ 402: "upgrade-required",
4
+ 403: "forbidden",
5
+ 404: "not-found",
6
+ 409: "conflict",
7
+ 412: "conflict",
8
+ 429: "rate-limited",
9
+ 504: "timeout"
10
+ };
11
+ const memberOf = (value, member) => {
12
+ if (typeof value !== "object" || value === null) return;
13
+ try {
14
+ return value[member];
15
+ } catch {
16
+ return;
17
+ }
18
+ };
19
+ const statusOf = (error) => {
20
+ const status = memberOf(error, "status");
21
+ return typeof status === "number" ? status : void 0;
22
+ };
23
+ const LIMIT_REACHED_CODE = "LIMIT_REACHED";
24
+ const carriesEntryCode = (error, code) => {
25
+ const entries = memberOf(error, "errors");
26
+ if (statusOf(error) === void 0 || !Array.isArray(entries)) return false;
27
+ try {
28
+ return entries.some((entry) => memberOf(memberOf(entry, "extensions"), "code") === code);
29
+ } catch {
30
+ return false;
31
+ }
32
+ };
33
+ const LONGEST_CLIENT_WAIT_SECONDS = 60;
34
+ const namesALongWait = (error) => {
35
+ if (statusOf(error) !== 429) return false;
36
+ const seconds = memberOf(error, "retryAfter");
37
+ return typeof seconds === "number" && seconds > LONGEST_CLIENT_WAIT_SECONDS;
38
+ };
39
+ const isLimitReached = (error) => carriesEntryCode(error, LIMIT_REACHED_CODE) || namesALongWait(error);
40
+ const lockHolderOf = (error) => {
41
+ if (statusOf(error) !== 409) return;
42
+ const id = memberOf(memberOf(memberOf(error, "metadata"), "holder"), "id");
43
+ return typeof id === "string" && id !== "" ? id : void 0;
44
+ };
45
+ const detailOf = (error) => {
46
+ const own = memberOf(error, "detail");
47
+ if (typeof own === "string") return own;
48
+ if (statusOf(error) === void 0) return;
49
+ const first = memberOf(memberOf(memberOf(error, "errors"), 0), "message");
50
+ return typeof first === "string" ? first : void 0;
51
+ };
52
+ const messageOf = (error) => {
53
+ try {
54
+ const message = error instanceof Error ? error.message : error;
55
+ return typeof message === "string" ? message : String(message);
56
+ } catch {
57
+ return "a value that cannot be printed";
58
+ }
59
+ };
60
+ const recognizedCode = (error, recognizers) => {
61
+ try {
62
+ for (const recognize of recognizers) {
63
+ const code = recognize(error);
64
+ if (code !== void 0) return code;
65
+ }
66
+ } catch {
67
+ return;
68
+ }
69
+ };
70
+ const codeForThrown = (error, recognizers = []) => {
71
+ const recognized = recognizedCode(error, recognizers);
72
+ if (recognized !== void 0) return recognized;
73
+ if (lockHolderOf(error) !== void 0) return "collab-locked";
74
+ if (isLimitReached(error)) return "limit-reached";
75
+ const status = statusOf(error);
76
+ return status === void 0 ? void 0 : restStatusCodes[status];
77
+ };
78
+ const WRITE_STILL_RUNNING = "write still running";
79
+ const WRITE_MADE = "write made";
80
+ const VERSION_MOVED = "version moved";
81
+ const keyedWriteOf = (error) => {
82
+ if (statusOf(error) !== 409) return;
83
+ const code = memberOf(memberOf(memberOf(memberOf(error, "errors"), 0), "extensions"), "code");
84
+ if (code === "IDEMPOTENCY_KEY_IN_USE") return WRITE_STILL_RUNNING;
85
+ return code === "IDEMPOTENCY_ANSWER_UNAVAILABLE" ? WRITE_MADE : void 0;
86
+ };
87
+ const conflictTagOf = (error) => keyedWriteOf(error) ?? (statusOf(error) === 412 ? "version moved" : void 0);
88
+ const failureFromThrown = (error, recognizers = []) => {
89
+ const code = codeForThrown(error, recognizers) ?? "internal";
90
+ const holderId = code === "collab-locked" ? lockHolderOf(error) : void 0;
91
+ const keyed = code === "conflict" ? conflictTagOf(error) : void 0;
92
+ return {
93
+ code,
94
+ detail: detailOf(error),
95
+ error: holderId !== void 0 ? `${code}: ${holderId}` : keyed !== void 0 ? `${keyed}: ${messageOf(error)}` : messageOf(error),
96
+ ok: false
97
+ };
98
+ };
99
+ export { failureFromThrown as a, messageOf as c, codeForThrown as i, restStatusCodes as l, WRITE_MADE as n, lockHolderOf as o, WRITE_STILL_RUNNING as r, memberOf as s, VERSION_MOVED as t };
100
+
101
+ //# sourceMappingURL=chunk-DKuuuld5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-DKuuuld5.js","names":[],"sources":["../src/bus/rules/errors.ts"],"mappings":"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"}