@qlever-llc/trellis 0.5.1 → 0.6.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 (490) hide show
  1. package/README.md +16 -2
  2. package/esm/_dnt.polyfills.d.ts +11 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -1
  4. package/esm/_dnt.polyfills.js +14 -0
  5. package/esm/_dnt.shims.d.ts +6 -0
  6. package/esm/_dnt.shims.d.ts.map +1 -0
  7. package/esm/_dnt.shims.js +61 -0
  8. package/esm/auth/browser/login.d.ts +27 -0
  9. package/esm/auth/browser/login.d.ts.map +1 -0
  10. package/esm/auth/browser/login.js +94 -0
  11. package/esm/auth/browser/portal.d.ts +11 -0
  12. package/esm/auth/browser/portal.d.ts.map +1 -0
  13. package/esm/auth/browser/portal.js +33 -0
  14. package/esm/auth/browser/session.d.ts +19 -0
  15. package/esm/auth/browser/session.d.ts.map +1 -0
  16. package/esm/auth/browser/session.js +65 -0
  17. package/esm/auth/browser/storage.d.ts +12 -0
  18. package/esm/auth/browser/storage.d.ts.map +1 -0
  19. package/esm/auth/browser/storage.js +61 -0
  20. package/esm/auth/browser.d.ts +13 -0
  21. package/esm/auth/browser.d.ts.map +1 -0
  22. package/esm/auth/browser.js +11 -0
  23. package/esm/auth/keys.d.ts +5 -0
  24. package/esm/auth/keys.d.ts.map +1 -0
  25. package/esm/auth/keys.js +50 -0
  26. package/esm/auth/mod.d.ts +18 -0
  27. package/esm/auth/mod.d.ts.map +1 -0
  28. package/esm/auth/mod.js +17 -0
  29. package/esm/auth/proof.d.ts +9 -0
  30. package/esm/auth/proof.d.ts.map +1 -0
  31. package/esm/auth/proof.js +43 -0
  32. package/esm/auth/protocol.d.ts +1212 -0
  33. package/esm/auth/protocol.d.ts.map +1 -0
  34. package/esm/auth/protocol.js +682 -0
  35. package/esm/auth/schemas.d.ts +93 -0
  36. package/esm/auth/schemas.d.ts.map +1 -0
  37. package/esm/auth/schemas.js +64 -0
  38. package/esm/auth/session_auth.d.ts +20 -0
  39. package/esm/auth/session_auth.d.ts.map +1 -0
  40. package/esm/auth/session_auth.js +42 -0
  41. package/esm/auth/trellis_id.d.ts +2 -0
  42. package/esm/auth/trellis_id.d.ts.map +1 -0
  43. package/esm/auth/trellis_id.js +5 -0
  44. package/esm/auth/types.d.ts +8 -0
  45. package/esm/auth/types.d.ts.map +1 -0
  46. package/esm/auth/types.js +1 -0
  47. package/esm/auth/utils.d.ts +11 -0
  48. package/esm/auth/utils.d.ts.map +1 -0
  49. package/esm/auth/utils.js +68 -0
  50. package/esm/auth/workload_activation.d.ts +192 -0
  51. package/esm/auth/workload_activation.d.ts.map +1 -0
  52. package/esm/auth/workload_activation.js +290 -0
  53. package/esm/contracts/canonical.d.ts +14 -0
  54. package/esm/contracts/canonical.d.ts.map +1 -0
  55. package/esm/contracts/canonical.js +135 -0
  56. package/esm/contracts/mod.d.ts +462 -0
  57. package/esm/contracts/mod.d.ts.map +1 -0
  58. package/esm/contracts/mod.js +532 -0
  59. package/esm/contracts/protocol.d.ts +301 -0
  60. package/esm/contracts/protocol.d.ts.map +1 -0
  61. package/esm/contracts/protocol.js +130 -0
  62. package/esm/contracts/runtime.d.ts +48 -0
  63. package/esm/contracts/runtime.d.ts.map +1 -0
  64. package/esm/contracts/runtime.js +9 -0
  65. package/esm/contracts/schema_pointers.d.ts +18 -0
  66. package/esm/contracts/schema_pointers.d.ts.map +1 -0
  67. package/esm/contracts/schema_pointers.js +59 -0
  68. package/esm/server/deno.d.ts +7 -0
  69. package/esm/server/deno.d.ts.map +1 -0
  70. package/esm/server/deno.js +16 -0
  71. package/esm/server/health.d.ts +92 -0
  72. package/esm/server/health.d.ts.map +1 -0
  73. package/esm/server/health.js +74 -0
  74. package/esm/server/health_rpc.d.ts +16 -0
  75. package/esm/server/health_rpc.d.ts.map +1 -0
  76. package/esm/server/health_rpc.js +23 -0
  77. package/esm/server/health_schemas.d.ts +20 -0
  78. package/esm/server/health_schemas.d.ts.map +1 -0
  79. package/esm/server/health_schemas.js +18 -0
  80. package/esm/server/mod.d.ts +17 -0
  81. package/esm/server/mod.d.ts.map +1 -0
  82. package/esm/server/mod.js +17 -0
  83. package/esm/server/node.d.ts +7 -0
  84. package/esm/server/node.d.ts.map +1 -0
  85. package/esm/server/node.js +16 -0
  86. package/esm/server/runtime.d.ts +16 -0
  87. package/esm/server/runtime.d.ts.map +1 -0
  88. package/esm/server/runtime.js +1 -0
  89. package/esm/server/service.d.ts +121 -0
  90. package/esm/server/service.d.ts.map +1 -0
  91. package/esm/server/service.js +256 -0
  92. package/esm/server/subscription.d.ts +99 -0
  93. package/esm/server/subscription.d.ts.map +1 -0
  94. package/esm/server/subscription.js +25 -0
  95. package/esm/telemetry/carrier.d.ts +9 -0
  96. package/esm/telemetry/carrier.d.ts.map +1 -0
  97. package/esm/telemetry/carrier.js +20 -0
  98. package/esm/telemetry/core.d.ts +8 -0
  99. package/esm/telemetry/core.d.ts.map +1 -0
  100. package/esm/telemetry/core.js +14 -0
  101. package/esm/telemetry/env.d.ts +2 -0
  102. package/esm/telemetry/env.d.ts.map +1 -0
  103. package/esm/telemetry/env.js +10 -0
  104. package/esm/telemetry/mod.d.ts +11 -0
  105. package/esm/telemetry/mod.d.ts.map +1 -0
  106. package/esm/telemetry/mod.js +7 -0
  107. package/esm/telemetry/nats.d.ts +7 -0
  108. package/esm/telemetry/nats.d.ts.map +1 -0
  109. package/esm/telemetry/nats.js +6 -0
  110. package/esm/telemetry/result.d.ts +2 -0
  111. package/esm/telemetry/result.d.ts.map +1 -0
  112. package/esm/telemetry/result.js +18 -0
  113. package/esm/telemetry/runtime.d.ts +2 -0
  114. package/esm/telemetry/runtime.d.ts.map +1 -0
  115. package/esm/telemetry/runtime.js +53 -0
  116. package/esm/telemetry/trace.d.ts +5 -0
  117. package/esm/telemetry/trace.d.ts.map +1 -0
  118. package/esm/telemetry/trace.js +26 -0
  119. package/esm/telemetry/trellis.d.ts +3 -0
  120. package/esm/telemetry/trellis.d.ts.map +1 -0
  121. package/esm/telemetry/trellis.js +7 -0
  122. package/esm/trellis/_sdk/activity/_dnt.polyfills.d.ts +12 -0
  123. package/esm/trellis/_sdk/activity/_dnt.polyfills.d.ts.map +1 -0
  124. package/esm/trellis/_sdk/activity/_dnt.polyfills.js +15 -0
  125. package/esm/trellis/_sdk/activity/api.d.ts +10 -0
  126. package/esm/trellis/_sdk/activity/api.d.ts.map +1 -0
  127. package/esm/trellis/_sdk/activity/api.js +43 -0
  128. package/esm/trellis/_sdk/activity/contract.d.ts +8 -0
  129. package/esm/trellis/_sdk/activity/contract.d.ts.map +1 -0
  130. package/esm/trellis/_sdk/activity/contract.js +59 -0
  131. package/esm/trellis/_sdk/activity/mod.d.ts +7 -0
  132. package/esm/trellis/_sdk/activity/mod.d.ts.map +1 -0
  133. package/esm/trellis/_sdk/activity/mod.js +5 -0
  134. package/esm/trellis/_sdk/activity/package.json +3 -0
  135. package/esm/trellis/_sdk/activity/schemas.d.ts +607 -0
  136. package/esm/trellis/_sdk/activity/schemas.d.ts.map +1 -0
  137. package/esm/trellis/_sdk/activity/schemas.js +33 -0
  138. package/esm/trellis/_sdk/activity/types.d.ts +96 -0
  139. package/esm/trellis/_sdk/activity/types.d.ts.map +1 -0
  140. package/esm/trellis/_sdk/activity/types.js +3 -0
  141. package/esm/trellis/_sdk/auth/_dnt.polyfills.d.ts +12 -0
  142. package/esm/trellis/_sdk/auth/_dnt.polyfills.d.ts.map +1 -0
  143. package/esm/trellis/_sdk/auth/_dnt.polyfills.js +15 -0
  144. package/esm/trellis/_sdk/auth/api.d.ts +10 -0
  145. package/esm/trellis/_sdk/auth/api.d.ts.map +1 -0
  146. package/esm/trellis/_sdk/auth/api.js +354 -0
  147. package/esm/trellis/_sdk/auth/contract.d.ts +28 -0
  148. package/esm/trellis/_sdk/auth/contract.d.ts.map +1 -0
  149. package/esm/trellis/_sdk/auth/contract.js +83 -0
  150. package/esm/trellis/_sdk/auth/mod.d.ts +7 -0
  151. package/esm/trellis/_sdk/auth/mod.d.ts.map +1 -0
  152. package/esm/trellis/_sdk/auth/mod.js +5 -0
  153. package/esm/trellis/_sdk/auth/package.json +3 -0
  154. package/esm/trellis/_sdk/auth/schemas.d.ts +8967 -0
  155. package/esm/trellis/_sdk/auth/schemas.d.ts.map +1 -0
  156. package/esm/trellis/_sdk/auth/schemas.js +306 -0
  157. package/esm/trellis/_sdk/auth/types.d.ts +1232 -0
  158. package/esm/trellis/_sdk/auth/types.d.ts.map +1 -0
  159. package/esm/trellis/_sdk/auth/types.js +3 -0
  160. package/esm/trellis/_sdk/core/_dnt.polyfills.d.ts +12 -0
  161. package/esm/trellis/_sdk/core/_dnt.polyfills.d.ts.map +1 -0
  162. package/esm/trellis/_sdk/core/_dnt.polyfills.js +15 -0
  163. package/esm/trellis/_sdk/core/api.d.ts +10 -0
  164. package/esm/trellis/_sdk/core/api.d.ts.map +1 -0
  165. package/esm/trellis/_sdk/core/api.js +36 -0
  166. package/esm/trellis/_sdk/core/contract.d.ts +8 -0
  167. package/esm/trellis/_sdk/core/contract.d.ts.map +1 -0
  168. package/esm/trellis/_sdk/core/contract.js +59 -0
  169. package/esm/trellis/_sdk/core/mod.d.ts +7 -0
  170. package/esm/trellis/_sdk/core/mod.d.ts.map +1 -0
  171. package/esm/trellis/_sdk/core/mod.js +5 -0
  172. package/esm/trellis/_sdk/core/package.json +3 -0
  173. package/esm/trellis/_sdk/core/schemas.d.ts +1144 -0
  174. package/esm/trellis/_sdk/core/schemas.d.ts.map +1 -0
  175. package/esm/trellis/_sdk/core/schemas.js +28 -0
  176. package/esm/trellis/_sdk/core/types.d.ts +176 -0
  177. package/esm/trellis/_sdk/core/types.d.ts.map +1 -0
  178. package/esm/trellis/_sdk/core/types.js +3 -0
  179. package/esm/trellis/auth/browser.d.ts +3 -0
  180. package/esm/trellis/auth/browser.d.ts.map +1 -0
  181. package/esm/trellis/auth/browser.js +2 -0
  182. package/esm/trellis/auth.d.ts +3 -0
  183. package/esm/trellis/auth.d.ts.map +1 -0
  184. package/esm/trellis/auth.js +2 -0
  185. package/esm/trellis/browser.d.ts +2 -7
  186. package/esm/trellis/browser.d.ts.map +1 -1
  187. package/esm/trellis/browser.js +2 -7
  188. package/esm/trellis/client.d.ts +6 -4
  189. package/esm/trellis/client.d.ts.map +1 -1
  190. package/esm/trellis/client.js +28 -1
  191. package/esm/trellis/codec.d.ts +4 -3
  192. package/esm/trellis/codec.d.ts.map +1 -1
  193. package/esm/trellis/codec.js +15 -2
  194. package/esm/trellis/contract.d.ts +11 -0
  195. package/esm/trellis/contract.d.ts.map +1 -0
  196. package/esm/trellis/contract.js +15 -0
  197. package/esm/trellis/contracts.d.ts +5 -0
  198. package/esm/trellis/contracts.d.ts.map +1 -0
  199. package/esm/trellis/contracts.js +3 -0
  200. package/esm/trellis/env.d.ts +1 -1
  201. package/esm/trellis/env.d.ts.map +1 -1
  202. package/esm/trellis/env.js +1 -1
  203. package/esm/trellis/errors/AuthError.d.ts +1 -1
  204. package/esm/trellis/errors/AuthError.d.ts.map +1 -1
  205. package/esm/trellis/errors/AuthError.js +11 -0
  206. package/esm/trellis/errors/RemoteError.d.ts +3 -3
  207. package/esm/trellis/errors/RemoteError.d.ts.map +1 -1
  208. package/esm/trellis/errors/RemoteError.js +3 -3
  209. package/esm/trellis/errors/TrellisError.d.ts +1 -1
  210. package/esm/trellis/errors/TrellisError.js +1 -1
  211. package/esm/trellis/errors/index.d.ts +2 -1
  212. package/esm/trellis/errors/index.d.ts.map +1 -1
  213. package/esm/trellis/errors/index.js +3 -2
  214. package/esm/trellis/globals.d.ts +9 -1
  215. package/esm/trellis/globals.d.ts.map +1 -1
  216. package/esm/trellis/globals.js +16 -8
  217. package/esm/trellis/helpers.d.ts +2 -1
  218. package/esm/trellis/helpers.d.ts.map +1 -1
  219. package/esm/trellis/helpers.js +1 -0
  220. package/esm/trellis/index.d.ts +13 -5
  221. package/esm/trellis/index.d.ts.map +1 -1
  222. package/esm/trellis/index.js +8 -3
  223. package/esm/trellis/kv.d.ts +10 -7
  224. package/esm/trellis/kv.d.ts.map +1 -1
  225. package/esm/trellis/kv.js +57 -34
  226. package/esm/trellis/models/trellis/TrellisError.d.ts +1 -1
  227. package/esm/trellis/models/trellis/TrellisError.js +1 -1
  228. package/esm/trellis/operations.d.ts +81 -0
  229. package/esm/trellis/operations.d.ts.map +1 -0
  230. package/esm/trellis/operations.js +206 -0
  231. package/esm/trellis/sdk/activity.d.ts +3 -0
  232. package/esm/trellis/sdk/activity.d.ts.map +1 -0
  233. package/esm/trellis/sdk/activity.js +2 -0
  234. package/esm/trellis/sdk/auth.d.ts +4 -0
  235. package/esm/trellis/sdk/auth.d.ts.map +1 -0
  236. package/esm/trellis/sdk/auth.js +3 -0
  237. package/esm/trellis/sdk/core.d.ts +4 -0
  238. package/esm/trellis/sdk/core.d.ts.map +1 -0
  239. package/esm/trellis/sdk/core.js +3 -0
  240. package/esm/trellis/server/deno.d.ts +3 -0
  241. package/esm/trellis/server/deno.d.ts.map +1 -0
  242. package/esm/trellis/server/deno.js +2 -0
  243. package/esm/trellis/server/health.d.ts +5 -0
  244. package/esm/trellis/server/health.d.ts.map +1 -0
  245. package/esm/trellis/server/health.js +3 -0
  246. package/esm/trellis/server/mod.d.ts +3 -0
  247. package/esm/trellis/server/mod.d.ts.map +1 -0
  248. package/esm/trellis/server/mod.js +2 -0
  249. package/esm/trellis/server/node.d.ts +3 -0
  250. package/esm/trellis/server/node.d.ts.map +1 -0
  251. package/esm/trellis/server/node.js +2 -0
  252. package/esm/trellis/server/runtime.d.ts +4 -0
  253. package/esm/trellis/server/runtime.d.ts.map +1 -0
  254. package/esm/trellis/server/runtime.js +2 -0
  255. package/esm/trellis/server.d.ts +21 -0
  256. package/esm/trellis/server.d.ts.map +1 -0
  257. package/esm/trellis/server.js +536 -0
  258. package/esm/trellis/server_logger.d.ts +3 -0
  259. package/esm/trellis/server_logger.d.ts.map +1 -0
  260. package/esm/trellis/server_logger.js +7 -0
  261. package/esm/trellis/tasks.d.ts +3 -3
  262. package/esm/trellis/tasks.d.ts.map +1 -1
  263. package/esm/trellis/tasks.js +1 -1
  264. package/esm/trellis/tracing.d.ts +2 -2
  265. package/esm/trellis/tracing.d.ts.map +1 -1
  266. package/esm/trellis/tracing.js +2 -2
  267. package/esm/trellis/trellis.d.ts +167 -78
  268. package/esm/trellis/trellis.d.ts.map +1 -1
  269. package/esm/trellis/trellis.js +281 -87
  270. package/esm/trellis/workload.d.ts +45 -0
  271. package/esm/trellis/workload.d.ts.map +1 -0
  272. package/esm/trellis/workload.js +144 -0
  273. package/package.json +63 -4
  274. package/script/auth/browser/login.d.ts +27 -0
  275. package/script/auth/browser/login.d.ts.map +1 -0
  276. package/script/auth/browser/login.js +100 -0
  277. package/script/auth/browser/portal.d.ts +11 -0
  278. package/script/auth/browser/portal.d.ts.map +1 -0
  279. package/script/auth/browser/portal.js +40 -0
  280. package/script/auth/browser/session.d.ts +19 -0
  281. package/script/auth/browser/session.d.ts.map +1 -0
  282. package/script/auth/browser/session.js +79 -0
  283. package/script/auth/browser/storage.d.ts +12 -0
  284. package/script/auth/browser/storage.d.ts.map +1 -0
  285. package/script/auth/browser/storage.js +67 -0
  286. package/script/auth/browser.d.ts +13 -0
  287. package/script/auth/browser.d.ts.map +1 -0
  288. package/script/auth/browser.js +46 -0
  289. package/script/auth/keys.d.ts +5 -0
  290. package/script/auth/keys.d.ts.map +1 -0
  291. package/script/auth/keys.js +56 -0
  292. package/script/auth/mod.d.ts +18 -0
  293. package/script/auth/mod.d.ts.map +1 -0
  294. package/script/auth/mod.js +172 -0
  295. package/script/auth/proof.d.ts +9 -0
  296. package/script/auth/proof.d.ts.map +1 -0
  297. package/script/auth/proof.js +48 -0
  298. package/script/auth/protocol.d.ts +1212 -0
  299. package/script/auth/protocol.d.ts.map +1 -0
  300. package/script/auth/protocol.js +687 -0
  301. package/script/auth/schemas.d.ts +93 -0
  302. package/script/auth/schemas.d.ts.map +1 -0
  303. package/script/auth/schemas.js +67 -0
  304. package/script/auth/session_auth.d.ts +20 -0
  305. package/script/auth/session_auth.d.ts.map +1 -0
  306. package/script/auth/session_auth.js +45 -0
  307. package/script/auth/trellis_id.d.ts +2 -0
  308. package/script/auth/trellis_id.d.ts.map +1 -0
  309. package/script/auth/trellis_id.js +8 -0
  310. package/script/auth/types.d.ts +8 -0
  311. package/script/auth/types.d.ts.map +1 -0
  312. package/script/auth/utils.d.ts +11 -0
  313. package/script/auth/utils.d.ts.map +1 -0
  314. package/script/auth/utils.js +77 -0
  315. package/script/auth/workload_activation.d.ts +192 -0
  316. package/script/auth/workload_activation.d.ts.map +1 -0
  317. package/script/auth/workload_activation.js +308 -0
  318. package/script/contracts/canonical.d.ts +14 -0
  319. package/script/contracts/canonical.d.ts.map +1 -0
  320. package/script/contracts/canonical.js +144 -0
  321. package/script/contracts/mod.d.ts +462 -0
  322. package/script/contracts/mod.d.ts.map +1 -0
  323. package/script/contracts/mod.js +555 -0
  324. package/script/contracts/protocol.d.ts +301 -0
  325. package/script/contracts/protocol.d.ts.map +1 -0
  326. package/script/contracts/protocol.js +136 -0
  327. package/script/contracts/runtime.d.ts +48 -0
  328. package/script/contracts/runtime.d.ts.map +1 -0
  329. package/script/contracts/runtime.js +13 -0
  330. package/script/contracts/schema_pointers.d.ts +18 -0
  331. package/script/contracts/schema_pointers.d.ts.map +1 -0
  332. package/script/contracts/schema_pointers.js +63 -0
  333. package/script/telemetry/carrier.d.ts +9 -0
  334. package/script/telemetry/carrier.d.ts.map +1 -0
  335. package/script/telemetry/carrier.js +25 -0
  336. package/script/telemetry/core.d.ts +8 -0
  337. package/script/telemetry/core.d.ts.map +1 -0
  338. package/script/telemetry/core.js +24 -0
  339. package/script/telemetry/env.d.ts +2 -0
  340. package/script/telemetry/env.d.ts.map +1 -0
  341. package/script/telemetry/env.js +12 -0
  342. package/script/telemetry/mod.d.ts +11 -0
  343. package/script/telemetry/mod.d.ts.map +1 -0
  344. package/script/telemetry/mod.js +29 -0
  345. package/script/telemetry/nats.d.ts +7 -0
  346. package/script/telemetry/nats.d.ts.map +1 -0
  347. package/script/telemetry/nats.js +9 -0
  348. package/script/telemetry/result.d.ts +2 -0
  349. package/script/telemetry/result.d.ts.map +1 -0
  350. package/script/telemetry/result.js +21 -0
  351. package/script/telemetry/runtime.d.ts +2 -0
  352. package/script/telemetry/runtime.d.ts.map +1 -0
  353. package/script/telemetry/runtime.js +79 -0
  354. package/script/telemetry/trace.d.ts +5 -0
  355. package/script/telemetry/trace.d.ts.map +1 -0
  356. package/script/telemetry/trace.js +31 -0
  357. package/script/telemetry/trellis.d.ts +3 -0
  358. package/script/telemetry/trellis.d.ts.map +1 -0
  359. package/script/telemetry/trellis.js +14 -0
  360. package/script/trellis/_sdk/activity/_dnt.polyfills.d.ts +12 -0
  361. package/script/trellis/_sdk/activity/_dnt.polyfills.d.ts.map +1 -0
  362. package/script/trellis/_sdk/activity/_dnt.polyfills.js +16 -0
  363. package/script/trellis/_sdk/activity/api.d.ts +10 -0
  364. package/script/trellis/_sdk/activity/api.d.ts.map +1 -0
  365. package/script/trellis/_sdk/activity/api.js +46 -0
  366. package/script/trellis/_sdk/activity/contract.d.ts +8 -0
  367. package/script/trellis/_sdk/activity/contract.d.ts.map +1 -0
  368. package/script/trellis/_sdk/activity/contract.js +62 -0
  369. package/script/trellis/_sdk/activity/mod.d.ts +7 -0
  370. package/script/trellis/_sdk/activity/mod.d.ts.map +1 -0
  371. package/script/trellis/_sdk/activity/mod.js +30 -0
  372. package/script/trellis/_sdk/activity/package.json +3 -0
  373. package/script/trellis/_sdk/activity/schemas.d.ts +607 -0
  374. package/script/trellis/_sdk/activity/schemas.d.ts.map +1 -0
  375. package/script/trellis/_sdk/activity/schemas.js +36 -0
  376. package/script/trellis/_sdk/activity/types.d.ts +96 -0
  377. package/script/trellis/_sdk/activity/types.d.ts.map +1 -0
  378. package/script/trellis/_sdk/activity/types.js +6 -0
  379. package/script/trellis/_sdk/auth/_dnt.polyfills.d.ts +12 -0
  380. package/script/trellis/_sdk/auth/_dnt.polyfills.d.ts.map +1 -0
  381. package/script/trellis/_sdk/auth/_dnt.polyfills.js +16 -0
  382. package/script/trellis/_sdk/auth/api.d.ts +10 -0
  383. package/script/trellis/_sdk/auth/api.d.ts.map +1 -0
  384. package/script/trellis/_sdk/auth/api.js +357 -0
  385. package/script/trellis/_sdk/auth/contract.d.ts +28 -0
  386. package/script/trellis/_sdk/auth/contract.d.ts.map +1 -0
  387. package/script/trellis/_sdk/auth/contract.js +86 -0
  388. package/script/trellis/_sdk/auth/mod.d.ts +7 -0
  389. package/script/trellis/_sdk/auth/mod.d.ts.map +1 -0
  390. package/script/trellis/_sdk/auth/mod.js +31 -0
  391. package/script/trellis/_sdk/auth/package.json +3 -0
  392. package/script/trellis/_sdk/auth/schemas.d.ts +8967 -0
  393. package/script/trellis/_sdk/auth/schemas.d.ts.map +1 -0
  394. package/script/trellis/_sdk/auth/schemas.js +309 -0
  395. package/script/trellis/_sdk/auth/types.d.ts +1232 -0
  396. package/script/trellis/_sdk/auth/types.d.ts.map +1 -0
  397. package/script/trellis/_sdk/auth/types.js +6 -0
  398. package/script/trellis/_sdk/core/_dnt.polyfills.d.ts +12 -0
  399. package/script/trellis/_sdk/core/_dnt.polyfills.d.ts.map +1 -0
  400. package/script/trellis/_sdk/core/_dnt.polyfills.js +16 -0
  401. package/script/trellis/_sdk/core/api.d.ts +10 -0
  402. package/script/trellis/_sdk/core/api.d.ts.map +1 -0
  403. package/script/trellis/_sdk/core/api.js +39 -0
  404. package/script/trellis/_sdk/core/contract.d.ts +8 -0
  405. package/script/trellis/_sdk/core/contract.d.ts.map +1 -0
  406. package/script/trellis/_sdk/core/contract.js +62 -0
  407. package/script/trellis/_sdk/core/mod.d.ts +7 -0
  408. package/script/trellis/_sdk/core/mod.d.ts.map +1 -0
  409. package/script/trellis/_sdk/core/mod.js +30 -0
  410. package/script/trellis/_sdk/core/package.json +3 -0
  411. package/script/trellis/_sdk/core/schemas.d.ts +1144 -0
  412. package/script/trellis/_sdk/core/schemas.d.ts.map +1 -0
  413. package/script/trellis/_sdk/core/schemas.js +31 -0
  414. package/script/trellis/_sdk/core/types.d.ts +176 -0
  415. package/script/trellis/_sdk/core/types.d.ts.map +1 -0
  416. package/script/trellis/_sdk/core/types.js +6 -0
  417. package/script/trellis/auth.d.ts +2 -0
  418. package/script/trellis/auth.d.ts.map +1 -0
  419. package/script/trellis/auth.js +17 -0
  420. package/script/trellis/client.d.ts +8 -6
  421. package/script/trellis/client.d.ts.map +1 -1
  422. package/script/trellis/client.js +54 -3
  423. package/script/trellis/codec.d.ts +5 -4
  424. package/script/trellis/codec.d.ts.map +1 -1
  425. package/script/trellis/codec.js +31 -17
  426. package/script/trellis/contract.d.ts +11 -0
  427. package/script/trellis/contract.d.ts.map +1 -0
  428. package/script/trellis/contract.js +18 -0
  429. package/script/trellis/contracts.d.ts +4 -0
  430. package/script/trellis/contracts.d.ts.map +1 -0
  431. package/script/trellis/contracts.js +20 -0
  432. package/script/trellis/errors/AuthError.d.ts +2 -2
  433. package/script/trellis/errors/AuthError.d.ts.map +1 -1
  434. package/script/trellis/errors/AuthError.js +13 -2
  435. package/script/trellis/errors/KVError.d.ts +1 -1
  436. package/script/trellis/errors/KVError.d.ts.map +1 -1
  437. package/script/trellis/errors/KVError.js +2 -2
  438. package/script/trellis/errors/RemoteError.d.ts +4 -4
  439. package/script/trellis/errors/RemoteError.d.ts.map +1 -1
  440. package/script/trellis/errors/RemoteError.js +11 -11
  441. package/script/trellis/errors/TrellisError.d.ts +1 -1
  442. package/script/trellis/errors/TrellisError.d.ts.map +1 -1
  443. package/script/trellis/errors/TrellisError.js +2 -2
  444. package/script/trellis/errors/ValidationError.d.ts +1 -1
  445. package/script/trellis/errors/ValidationError.d.ts.map +1 -1
  446. package/script/trellis/errors/ValidationError.js +2 -2
  447. package/script/trellis/errors/index.d.ts +14 -14
  448. package/script/trellis/errors/index.d.ts.map +1 -1
  449. package/script/trellis/errors/index.js +31 -31
  450. package/script/trellis/globals.d.ts +9 -1
  451. package/script/trellis/globals.d.ts.map +1 -1
  452. package/script/trellis/globals.js +16 -8
  453. package/script/trellis/helpers.d.ts +1 -1
  454. package/script/trellis/helpers.d.ts.map +1 -1
  455. package/script/trellis/index.d.ts +17 -10
  456. package/script/trellis/index.d.ts.map +1 -1
  457. package/script/trellis/index.js +57 -22
  458. package/script/trellis/kv.d.ts +11 -8
  459. package/script/trellis/kv.d.ts.map +1 -1
  460. package/script/trellis/kv.js +91 -68
  461. package/script/trellis/models/trellis/TrellisError.d.ts +1 -1
  462. package/script/trellis/models/trellis/TrellisError.d.ts.map +1 -1
  463. package/script/trellis/models/trellis/TrellisError.js +8 -8
  464. package/script/trellis/operations.d.ts +81 -0
  465. package/script/trellis/operations.d.ts.map +1 -0
  466. package/script/trellis/operations.js +212 -0
  467. package/script/trellis/sdk/core.d.ts +3 -0
  468. package/script/trellis/sdk/core.d.ts.map +1 -0
  469. package/script/trellis/sdk/core.js +20 -0
  470. package/script/trellis/tasks.d.ts +3 -3
  471. package/script/trellis/tasks.d.ts.map +1 -1
  472. package/script/trellis/tasks.js +5 -5
  473. package/script/trellis/tracing.d.ts +2 -3
  474. package/script/trellis/tracing.d.ts.map +1 -1
  475. package/script/trellis/tracing.js +17 -20
  476. package/script/trellis/trellis.d.ts +169 -80
  477. package/script/trellis/trellis.d.ts.map +1 -1
  478. package/script/trellis/trellis.js +379 -177
  479. package/script/trellis/workload.d.ts +45 -0
  480. package/script/trellis/workload.d.ts.map +1 -0
  481. package/script/trellis/workload.js +172 -0
  482. package/script/_dnt.polyfills.d.ts +0 -7
  483. package/script/_dnt.polyfills.d.ts.map +0 -1
  484. package/script/trellis/browser.d.ts +0 -11
  485. package/script/trellis/browser.d.ts.map +0 -1
  486. package/script/trellis/browser.js +0 -21
  487. package/script/trellis/env.d.ts +0 -2
  488. package/script/trellis/env.d.ts.map +0 -1
  489. package/script/trellis/env.js +0 -5
  490. /package/script/{_dnt.polyfills.js → auth/types.js} +0 -0
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
4
3
  if (kind === "m") throw new TypeError("Private method is not writable");
5
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -11,28 +10,45 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
12
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
13
12
  };
14
- var _Trellis_instances, _Trellis_log, _Trellis_tasks, _Trellis_noResponderMaxRetries, _Trellis_noResponderRetryMs, _Trellis_authBypassMethods, _Trellis_handleRPC, _Trellis_processRPCMessage, _Trellis_respondWithError, _Trellis_handleEvent, _Trellis_escapeSubjectToken, _Trellis_createProof, _TrellisServer_version, _TrellisServer_log;
13
+ var _Trellis_instances, _Trellis_log, _Trellis_tasks, _Trellis_hasExplicitApi, _Trellis_noResponderMaxRetries, _Trellis_noResponderRetryMs, _Trellis_authBypassMethods, _Trellis_operationStore, _Trellis_unknownApiError, _Trellis_handleRPC, _Trellis_processRPCMessage, _Trellis_respondWithError, _Trellis_handleEvent, _Trellis_escapeSubjectToken, _Trellis_createProof, _Trellis_requestJson, _Trellis_watchJson;
15
14
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.TrellisServer = exports.Trellis = void 0;
15
+ exports.Trellis = exports.DurableOperationRecordSchema = void 0;
16
+ exports.safeJson = safeJson;
17
+ exports.base64urlEncode = base64urlEncode;
18
+ exports.base64urlDecode = base64urlDecode;
19
+ exports.toArrayBuffer = toArrayBuffer;
20
+ exports.sha256 = sha256;
21
+ exports.buildProofInput = buildProofInput;
22
+ exports.isResultLike = isResultLike;
23
+ exports.buildRuntimeOperationSnapshot = buildRuntimeOperationSnapshot;
24
+ exports.isTerminalRuntimeOperationSnapshot = isTerminalRuntimeOperationSnapshot;
17
25
  const jetstream_1 = require("@nats-io/jetstream");
18
26
  const nats_core_1 = require("@nats-io/nats-core");
19
- const trellis_result_1 = require("@qlever-llc/trellis-result");
20
- const trellis_sdk_core_1 = require("@qlever-llc/trellis-sdk-core");
21
- const trellis_telemetry_1 = require("@qlever-llc/trellis-telemetry");
27
+ const result_1 = require("@qlever-llc/result");
28
+ const tracing_ts_1 = require("./tracing.ts");
29
+ const typebox_1 = require("typebox");
22
30
  const value_1 = require("typebox/value");
23
31
  const ulid_1 = require("ulid");
24
- const codec_js_1 = require("./codec.js");
25
- const index_js_1 = require("./errors/index.js");
26
- const RemoteError_js_1 = require("./errors/RemoteError.js");
27
- const globals_js_1 = require("./globals.js");
28
- const TrellisError_js_1 = require("./models/trellis/TrellisError.js");
29
- const tasks_js_1 = require("./tasks.js");
32
+ const codec_ts_1 = require("./codec.ts");
33
+ const index_ts_1 = require("./errors/index.ts");
34
+ const RemoteError_ts_1 = require("./errors/RemoteError.ts");
35
+ const globals_ts_1 = require("./globals.ts");
36
+ const kv_ts_1 = require("./kv.ts");
37
+ const TrellisError_ts_1 = require("./models/trellis/TrellisError.ts");
38
+ const operations_ts_1 = require("./operations.ts");
39
+ const tasks_ts_1 = require("./tasks.ts");
30
40
  /**
31
41
  * Safely extract JSON from a NATS message.
32
42
  * The .json() method can throw if the message data is not valid JSON.
33
43
  */
34
44
  function safeJson(msg) {
35
- return trellis_result_1.Result.try(() => msg.json());
45
+ return result_1.Result.try(() => msg.json());
46
+ }
47
+ function encodeRuntimeSchema(schema, data) {
48
+ return (0, codec_ts_1.encodeSchema)(schema, data);
49
+ }
50
+ function parseRuntimeSchema(schema, data) {
51
+ return (0, codec_ts_1.parseUnknownSchema)(schema, data);
36
52
  }
37
53
  function base64urlEncode(data) {
38
54
  const b64 = btoa(String.fromCharCode(...data));
@@ -86,9 +102,90 @@ function buildProofInput(sessionKey, subject, payloadHash) {
86
102
  buf.set(payloadHash, offset);
87
103
  return buf;
88
104
  }
105
+ function isResultLike(value) {
106
+ return value instanceof result_1.Result;
107
+ }
108
+ const DurableOperationSnapshotSchema = typebox_1.Type.Object({
109
+ id: typebox_1.Type.String(),
110
+ service: typebox_1.Type.String(),
111
+ operation: typebox_1.Type.String(),
112
+ revision: typebox_1.Type.Number(),
113
+ state: typebox_1.Type.Union([
114
+ typebox_1.Type.Literal("pending"),
115
+ typebox_1.Type.Literal("running"),
116
+ typebox_1.Type.Literal("completed"),
117
+ typebox_1.Type.Literal("failed"),
118
+ typebox_1.Type.Literal("cancelled"),
119
+ ]),
120
+ createdAt: typebox_1.Type.String(),
121
+ updatedAt: typebox_1.Type.String(),
122
+ completedAt: typebox_1.Type.Optional(typebox_1.Type.String()),
123
+ progress: typebox_1.Type.Optional(typebox_1.Type.Any()),
124
+ output: typebox_1.Type.Optional(typebox_1.Type.Any()),
125
+ error: typebox_1.Type.Optional(typebox_1.Type.Object({
126
+ type: typebox_1.Type.String(),
127
+ message: typebox_1.Type.String(),
128
+ })),
129
+ });
130
+ exports.DurableOperationRecordSchema = typebox_1.Type.Object({
131
+ ownerSessionKey: typebox_1.Type.String(),
132
+ sequence: typebox_1.Type.Number(),
133
+ snapshot: DurableOperationSnapshotSchema,
134
+ });
135
+ function buildRuntimeOperationSnapshot(runtime, state, patch) {
136
+ const updatedAt = new Date().toISOString();
137
+ const completedAt = state === "completed" || state === "failed" || state === "cancelled"
138
+ ? (patch?.completedAt ?? updatedAt)
139
+ : patch?.completedAt;
140
+ return {
141
+ id: runtime.id,
142
+ service: runtime.service,
143
+ operation: runtime.operation,
144
+ revision: patch?.revision ?? runtime.snapshot.revision + 1,
145
+ state,
146
+ createdAt: patch?.createdAt ?? runtime.snapshot.createdAt,
147
+ updatedAt,
148
+ ...(completedAt ? { completedAt } : {}),
149
+ ...(patch?.progress !== undefined
150
+ ? { progress: patch.progress }
151
+ : runtime.snapshot.progress !== undefined
152
+ ? { progress: runtime.snapshot.progress }
153
+ : {}),
154
+ ...(patch?.output !== undefined
155
+ ? { output: patch.output }
156
+ : runtime.snapshot.output !== undefined
157
+ ? { output: runtime.snapshot.output }
158
+ : {}),
159
+ ...(patch?.error
160
+ ? { error: patch.error }
161
+ : runtime.snapshot.error
162
+ ? { error: runtime.snapshot.error }
163
+ : {}),
164
+ };
165
+ }
166
+ function isRuntimeOperationSnapshot(value) {
167
+ return !!value && typeof value === "object" &&
168
+ typeof value.id === "string" &&
169
+ typeof value.service === "string" &&
170
+ typeof value.operation === "string" &&
171
+ typeof value.revision === "number" &&
172
+ typeof value.state === "string" &&
173
+ typeof value.createdAt === "string" &&
174
+ typeof value.updatedAt === "string";
175
+ }
176
+ function isTerminalRuntimeOperationSnapshot(value) {
177
+ return isRuntimeOperationSnapshot(value) && (value.state === "completed" || value.state === "failed" ||
178
+ value.state === "cancelled");
179
+ }
89
180
  const NATS_SUBJECT_TOKEN_FORBIDDEN = /[\u0000\s.*>~]/gu;
90
181
  const DEFAULT_NO_RESPONDER_MAX_RETRIES = 2;
91
182
  const DEFAULT_NO_RESPONDER_RETRY_MS = 200;
183
+ const EMPTY_TRELLIS_API = {
184
+ rpc: {},
185
+ operations: {},
186
+ events: {},
187
+ subjects: {},
188
+ };
92
189
  class Trellis {
93
190
  constructor(name, // Must be unique for a service
94
191
  nats, auth, opts) {
@@ -137,23 +234,27 @@ class Trellis {
137
234
  });
138
235
  _Trellis_log.set(this, void 0);
139
236
  _Trellis_tasks.set(this, void 0);
237
+ _Trellis_hasExplicitApi.set(this, void 0);
140
238
  _Trellis_noResponderMaxRetries.set(this, void 0);
141
239
  _Trellis_noResponderRetryMs.set(this, void 0);
142
240
  _Trellis_authBypassMethods.set(this, void 0);
241
+ _Trellis_operationStore.set(this, void 0);
242
+ const api = opts?.api;
143
243
  this.name = name;
144
244
  this.nats = nats;
145
245
  this.js = (0, jetstream_1.jetstream)(this.nats);
146
246
  this.auth = auth;
147
- this.api = (opts?.api ?? trellis_sdk_core_1.API);
148
- __classPrivateFieldSet(this, _Trellis_log, (opts?.log ?? globals_js_1.logger).child({ lib: "trellis" }), "f");
247
+ this.api = (api ?? EMPTY_TRELLIS_API);
248
+ __classPrivateFieldSet(this, _Trellis_log, (opts?.log ?? globals_ts_1.logger).child({ lib: "trellis" }), "f");
149
249
  this.timeout = opts?.timeout ?? 3000;
150
250
  this.stream = opts?.stream ?? "trellis";
251
+ __classPrivateFieldSet(this, _Trellis_hasExplicitApi, api !== undefined, "f");
151
252
  __classPrivateFieldSet(this, _Trellis_noResponderMaxRetries, opts?.noResponderRetry?.maxAttempts ??
152
253
  DEFAULT_NO_RESPONDER_MAX_RETRIES, "f");
153
254
  __classPrivateFieldSet(this, _Trellis_noResponderRetryMs, opts?.noResponderRetry?.baseDelayMs ??
154
255
  DEFAULT_NO_RESPONDER_RETRY_MS, "f");
155
256
  __classPrivateFieldSet(this, _Trellis_authBypassMethods, new Set(opts?.authBypassMethods ?? []), "f");
156
- __classPrivateFieldSet(this, _Trellis_tasks, new tasks_js_1.TrellisTasks({ log: __classPrivateFieldGet(this, _Trellis_log, "f") }), "f");
257
+ __classPrivateFieldSet(this, _Trellis_tasks, new tasks_ts_1.TrellisTasks({ log: __classPrivateFieldGet(this, _Trellis_log, "f") }), "f");
157
258
  }
158
259
  /**
159
260
  * Returns the underlying NATS connection.
@@ -161,6 +262,41 @@ class Trellis {
161
262
  get natsConnection() {
162
263
  return this.nats;
163
264
  }
265
+ async operationStoreHandle() {
266
+ if (!__classPrivateFieldGet(this, _Trellis_operationStore, "f")) {
267
+ const bucket = `trellis_operations_${this.name.replace(/[^A-Za-z0-9_-]/g, "_")}`;
268
+ __classPrivateFieldSet(this, _Trellis_operationStore, (async () => {
269
+ const result = await kv_ts_1.TypedKV.open(this.nats, bucket, exports.DurableOperationRecordSchema, {
270
+ history: 5,
271
+ ttl: 0,
272
+ });
273
+ const value = result.take();
274
+ if ((0, result_1.isErr)(value)) {
275
+ throw value.error;
276
+ }
277
+ return value;
278
+ })(), "f");
279
+ }
280
+ return __classPrivateFieldGet(this, _Trellis_operationStore, "f");
281
+ }
282
+ async loadOperationRecord(operationId) {
283
+ const store = await this.operationStoreHandle();
284
+ const entry = await store.get(operationId);
285
+ const value = entry.take();
286
+ if ((0, result_1.isErr)(value)) {
287
+ return null;
288
+ }
289
+ return value.value;
290
+ }
291
+ async saveOperationRecord(runtime) {
292
+ const store = await this.operationStoreHandle();
293
+ const record = {
294
+ ownerSessionKey: runtime.ownerSessionKey,
295
+ sequence: runtime.sequence,
296
+ snapshot: runtime.snapshot,
297
+ };
298
+ await store.put(runtime.id, record);
299
+ }
164
300
  /**
165
301
  * Makes an authenticated request to a Trellis RPC method.
166
302
  *
@@ -174,44 +310,42 @@ class Trellis {
174
310
  * ok: A validated reponse of method M
175
311
  * err: RemoteError | ValidationError | UnexpectedError
176
312
  */
177
- // TypeScript hits recursion limits on this generic surface under the app's Svelte check.
178
- // The implementation still builds and is exercised by runtime validation below.
179
- // @ts-expect-error
180
313
  async request(method, input, opts) {
181
- __classPrivateFieldGet(this, _Trellis_log, "f").trace({ method: String(method), input: input }, `Calling ${method.toString()}.`);
182
- const ctx = this.api["rpc"][method];
314
+ __classPrivateFieldGet(this, _Trellis_log, "f").trace({ method: String(method) }, `Calling ${method.toString()}.`);
315
+ const methodName = method;
316
+ const ctx = this.api["rpc"][methodName];
183
317
  if (!ctx) {
184
- return (0, trellis_result_1.err)(new index_js_1.UnexpectedError({
185
- cause: new Error(`Unknown RPC method '${method.toString()}'. Did you forget to include its API module?`),
318
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({
319
+ cause: __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "RPC method", method.toString()),
186
320
  context: { method: method.toString() },
187
321
  }));
188
322
  }
189
- const msg = (0, codec_js_1.encodeSchema)(ctx.input, input).take();
190
- if ((0, trellis_result_1.isErr)(msg)) {
323
+ const msg = encodeRuntimeSchema(ctx.input, input).take();
324
+ if ((0, result_1.isErr)(msg)) {
191
325
  return msg;
192
326
  }
193
327
  const subject = this.template(ctx.subject, input).take();
194
- if ((0, trellis_result_1.isErr)(subject)) {
328
+ if ((0, result_1.isErr)(subject)) {
195
329
  return subject;
196
330
  }
197
331
  // Start a client span for this RPC request
198
- const span = (0, trellis_telemetry_1.startClientSpan)(method, subject);
332
+ const span = (0, tracing_ts_1.startClientSpan)(method, subject);
199
333
  const attempt = async () => {
200
334
  const proof = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_createProof).call(this, subject, msg);
201
335
  const headers = (0, nats_core_1.headers)();
202
336
  headers.set("session-key", this.auth.sessionKey);
203
337
  headers.set("proof", proof);
204
338
  // Inject trace context into NATS headers for propagation
205
- (0, trellis_telemetry_1.injectTraceContext)((0, trellis_telemetry_1.createNatsHeaderCarrier)(headers), span);
339
+ (0, tracing_ts_1.injectTraceContext)((0, tracing_ts_1.createNatsHeaderCarrier)(headers), span);
206
340
  // Attempt request with retry for transient "no responders" errors
207
341
  const requestWithRetry = async () => {
208
342
  for (let retry = 0; retry <= __classPrivateFieldGet(this, _Trellis_noResponderMaxRetries, "f"); retry++) {
209
- const result = await trellis_result_1.AsyncResult.try(() => this.nats.request(subject, msg, {
343
+ const result = await result_1.AsyncResult.try(() => this.nats.request(subject, msg, {
210
344
  headers,
211
345
  timeout: opts?.timeout ?? this.timeout,
212
346
  }));
213
347
  if (result.isOk()) {
214
- return (0, trellis_result_1.ok)((await result).take());
348
+ return (0, result_1.ok)((await result).take());
215
349
  }
216
350
  const cause = result.error.cause;
217
351
  const message = cause instanceof Error
@@ -230,7 +364,7 @@ class Trellis {
230
364
  const reason = isNatsPermission
231
365
  ? `Permission denied. You need one of these capabilities: ${ctx.callerCapabilities.join(", ")}`
232
366
  : message;
233
- return (0, trellis_result_1.err)(new index_js_1.UnexpectedError({
367
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({
234
368
  cause,
235
369
  context: {
236
370
  method,
@@ -242,114 +376,144 @@ class Trellis {
242
376
  }));
243
377
  }
244
378
  // Should be unreachable, but TypeScript needs explicit return
245
- return (0, trellis_result_1.err)(new index_js_1.UnexpectedError({
379
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({
246
380
  context: { method, subject, reason: "retry loop exhausted" },
247
381
  }));
248
382
  };
249
383
  const msgResult = await requestWithRetry();
250
384
  const m = msgResult.take();
251
- if ((0, trellis_result_1.isErr)(m)) {
385
+ if ((0, result_1.isErr)(m)) {
252
386
  return m;
253
387
  }
254
388
  if (m.headers?.get("status") === "error") {
255
389
  const json = safeJson(m).take();
256
- if ((0, trellis_result_1.isErr)(json)) {
390
+ if ((0, result_1.isErr)(json)) {
257
391
  return json;
258
392
  }
259
- const error = (0, codec_js_1.parse)(TrellisError_js_1.TrellisErrorDataSchema, json).take();
260
- if ((0, trellis_result_1.isErr)(error)) {
393
+ const error = (0, codec_ts_1.parse)(TrellisError_ts_1.TrellisErrorDataSchema, json).take();
394
+ if ((0, result_1.isErr)(error)) {
261
395
  return error;
262
396
  }
263
- return (0, trellis_result_1.err)(new RemoteError_js_1.RemoteError({ error }));
397
+ return (0, result_1.err)(new RemoteError_ts_1.RemoteError({ error }));
264
398
  }
265
399
  const json = safeJson(m).take();
266
- if ((0, trellis_result_1.isErr)(json)) {
400
+ if ((0, result_1.isErr)(json)) {
267
401
  return json;
268
402
  }
269
- const outputResult = (0, codec_js_1.parseSchema)(ctx.output, json);
270
- if (outputResult.isErr()) {
271
- return outputResult;
403
+ const outputResult = parseRuntimeSchema(ctx.output, json).take();
404
+ if ((0, result_1.isErr)(outputResult)) {
405
+ return (0, result_1.err)(outputResult.error);
272
406
  }
273
- const output = outputResult.take();
274
- return (0, trellis_result_1.ok)(output);
407
+ return (0, result_1.ok)(outputResult);
275
408
  };
276
- return (0, trellis_telemetry_1.withSpanAsync)(span, async () => {
409
+ return (0, tracing_ts_1.withSpanAsync)(span, async () => {
277
410
  try {
278
411
  const result = await attempt();
279
412
  const value = result.take();
280
- if ((0, trellis_result_1.isErr)(value)) {
413
+ if ((0, result_1.isErr)(value)) {
281
414
  span.setStatus({
282
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
415
+ code: tracing_ts_1.SpanStatusCode.ERROR,
283
416
  message: value.error.message,
284
417
  });
285
418
  }
286
419
  else {
287
- span.setStatus({ code: trellis_telemetry_1.SpanStatusCode.OK });
420
+ span.setStatus({ code: tracing_ts_1.SpanStatusCode.OK });
288
421
  }
289
422
  return result;
290
423
  }
291
424
  catch (cause) {
292
- const unexpected = new index_js_1.UnexpectedError({ cause });
425
+ const unexpected = new index_ts_1.UnexpectedError({ cause });
293
426
  span.setStatus({
294
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
427
+ code: tracing_ts_1.SpanStatusCode.ERROR,
295
428
  message: unexpected.message,
296
429
  });
297
430
  span.recordException(unexpected);
298
- return (0, trellis_result_1.err)(unexpected);
431
+ return (0, result_1.err)(unexpected);
299
432
  }
300
433
  finally {
301
434
  span.end();
302
435
  }
303
436
  });
304
437
  }
438
+ async requestOrThrow(method, input, opts) {
439
+ const result = await this.request(method, input, opts);
440
+ const value = result.take();
441
+ if ((0, result_1.isErr)(value)) {
442
+ throw value.error;
443
+ }
444
+ return value;
445
+ }
446
+ operation(operation) {
447
+ const descriptor = this.api["operations"]?.[operation];
448
+ if (!descriptor) {
449
+ throw __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "operation", operation.toString());
450
+ }
451
+ const transport = {
452
+ requestJson: (subject, body) => __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_requestJson).call(this, subject, body),
453
+ watchJson: (subject, body) => __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_watchJson).call(this, subject, body),
454
+ };
455
+ return new operations_ts_1.OperationInvoker(transport, descriptor);
456
+ }
305
457
  /*
306
458
  * Mount a handler to process requests made to a specific Trellis API
307
459
  */
308
460
  async mount(method, fn) {
309
- __classPrivateFieldGet(this, _Trellis_tasks, "f").add(method, __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_handleRPC).call(this, method, fn));
461
+ const methodName = method;
462
+ const ctx = this.api["rpc"][methodName];
463
+ if (!ctx) {
464
+ throw __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "RPC method", method.toString());
465
+ }
466
+ const task = __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_handleRPC).call(this, methodName, fn);
467
+ __classPrivateFieldGet(this, _Trellis_tasks, "f").add(methodName, task);
468
+ }
469
+ respondWithError(msg, error) {
470
+ __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_respondWithError).call(this, msg, error);
310
471
  }
311
472
  async publish(event, data) {
312
- const ctx = this.api["events"][event];
473
+ const eventName = event;
474
+ const ctx = this.api["events"][eventName];
313
475
  if (!ctx) {
314
- return (0, trellis_result_1.err)(new index_js_1.UnexpectedError({
315
- cause: new Error(`Unknown event '${event.toString()}'. Did you forget to include its API module?`),
476
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({
477
+ cause: __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "event", event.toString()),
316
478
  context: { event: event.toString() },
317
479
  }));
318
480
  }
319
481
  const subject = this.template(ctx.subject, data).take();
320
- if ((0, trellis_result_1.isErr)(subject)) {
321
- globals_js_1.logger.error({ err: subject.error }, "Failed to template event.");
482
+ if ((0, result_1.isErr)(subject)) {
483
+ globals_ts_1.logger.error({ err: subject.error }, "Failed to template event.");
322
484
  return subject;
323
485
  }
324
- const msg = (0, codec_js_1.encodeSchema)(ctx.event, {
486
+ const payload = {
325
487
  ...data,
326
488
  header: {
327
489
  id: (0, ulid_1.ulid)(),
328
490
  time: new Date().toISOString(),
329
491
  },
330
- }).take();
331
- if ((0, trellis_result_1.isErr)(msg)) {
332
- globals_js_1.logger.error({ err: msg.error }, "Failed to encode event.");
333
- return msg;
492
+ };
493
+ const msg = (0, codec_ts_1.encodeSchema)(ctx.event, payload).take();
494
+ if ((0, result_1.isErr)(msg)) {
495
+ globals_ts_1.logger.error({ err: msg.error }, "Failed to encode event.");
496
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({ cause: msg.error }));
334
497
  }
335
- globals_js_1.logger.trace({ subject }, `Publishing ${event.toString()} event.`);
498
+ globals_ts_1.logger.trace({ subject }, `Publishing ${event.toString()} event.`);
336
499
  await this.js.publish(subject, msg);
337
- return (0, trellis_result_1.ok)(undefined);
500
+ return (0, result_1.ok)(undefined);
338
501
  }
339
502
  async event(event, subjectData, fn) {
340
- const ctx = this.api["events"][event];
503
+ const eventName = event;
504
+ const ctx = this.api["events"][eventName];
341
505
  if (!ctx) {
342
- return (0, trellis_result_1.err)(new index_js_1.UnexpectedError({
343
- cause: new Error(`Unknown event '${event.toString()}'. Did you forget to include its API module?`),
506
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({
507
+ cause: __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_unknownApiError).call(this, "event", event.toString()),
344
508
  context: { event: event.toString() },
345
509
  }));
346
510
  }
347
511
  const jsm = await (0, jetstream_1.jetstreamManager)(this.nats);
348
512
  const subject = this.template(ctx.subject, subjectData, true).take();
349
- if ((0, trellis_result_1.isErr)(subject))
513
+ if ((0, result_1.isErr)(subject))
350
514
  return subject;
351
515
  const consumerName = `${this.name}-${event.replaceAll(".", "_")}`;
352
- const addResult = await trellis_result_1.AsyncResult.try(() => jsm.consumers.add(this.stream, {
516
+ const addResult = await result_1.AsyncResult.try(() => jsm.consumers.add(this.stream, {
353
517
  durable_name: consumerName,
354
518
  ack_policy: "explicit",
355
519
  deliver_policy: "all",
@@ -358,13 +522,13 @@ class Trellis {
358
522
  // If add failed (consumer already exists), try to get existing consumer info
359
523
  const consumerInfoResult = addResult.isOk()
360
524
  ? addResult
361
- : await trellis_result_1.AsyncResult.try(() => jsm.consumers.info(this.stream, consumerName));
525
+ : await result_1.AsyncResult.try(() => jsm.consumers.info(this.stream, consumerName));
362
526
  const info = consumerInfoResult.take();
363
- if ((0, trellis_result_1.isErr)(info))
527
+ if ((0, result_1.isErr)(info))
364
528
  return info;
365
529
  const consumer = this.js.consumers.getConsumerFromInfo(info);
366
- __classPrivateFieldGet(this, _Trellis_tasks, "f").add(event, __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_handleEvent).call(this, event, consumer, fn));
367
- return (0, trellis_result_1.ok)(undefined);
530
+ __classPrivateFieldGet(this, _Trellis_tasks, "f").add(eventName, __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_handleEvent).call(this, eventName, consumer, fn));
531
+ return (0, result_1.ok)(undefined);
368
532
  }
369
533
  wait() {
370
534
  return __classPrivateFieldGet(this, _Trellis_tasks, "f").wait();
@@ -377,7 +541,7 @@ class Trellis {
377
541
  const key = placeholder.slice(1, -1); // Remove { and }
378
542
  const value = value_1.Pointer.Get(data, key);
379
543
  if ((value === undefined || value === null) && !allowWildcards) {
380
- return (0, trellis_result_1.err)(new index_js_1.ValidationError({
544
+ return (0, result_1.err)(new index_ts_1.ValidationError({
381
545
  errors: [
382
546
  {
383
547
  path: key,
@@ -398,24 +562,35 @@ class Trellis {
398
562
  }
399
563
  return __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_escapeSubjectToken).call(this, `${value}`);
400
564
  });
401
- return (0, trellis_result_1.ok)(result);
565
+ return (0, result_1.ok)(result);
566
+ }
567
+ async requestAuthValidate(input) {
568
+ const request = this.request.bind(this);
569
+ const result = await request("Auth.ValidateRequest", input);
570
+ return result;
402
571
  }
403
572
  }
404
573
  exports.Trellis = Trellis;
405
- _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noResponderMaxRetries = new WeakMap(), _Trellis_noResponderRetryMs = new WeakMap(), _Trellis_authBypassMethods = new WeakMap(), _Trellis_instances = new WeakSet(), _Trellis_handleRPC = function _Trellis_handleRPC(method, fn, subjectData = {}) {
574
+ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_hasExplicitApi = new WeakMap(), _Trellis_noResponderMaxRetries = new WeakMap(), _Trellis_noResponderRetryMs = new WeakMap(), _Trellis_authBypassMethods = new WeakMap(), _Trellis_operationStore = new WeakMap(), _Trellis_instances = new WeakSet(), _Trellis_unknownApiError = function _Trellis_unknownApiError(kind, name) {
575
+ const base = `Unknown ${kind} '${name}'.`;
576
+ if (__classPrivateFieldGet(this, _Trellis_hasExplicitApi, "f")) {
577
+ return new Error(`${base} Did you forget to include its API module?`);
578
+ }
579
+ return new Error(`${base} No API surface was provided. Pass opts.api, use createClient(contract, ...), or await createCoreClient(...) instead.`);
580
+ }, _Trellis_handleRPC = function _Trellis_handleRPC(method, fn, subjectData = {}) {
406
581
  // Get API details
407
582
  const ctx = this.api["rpc"][method];
408
583
  const subject = this.template(ctx.subject, subjectData, true).take();
409
- if ((0, trellis_result_1.isErr)(subject)) {
410
- return trellis_result_1.AsyncResult.lift(subject);
584
+ if ((0, result_1.isErr)(subject)) {
585
+ return result_1.AsyncResult.lift(subject);
411
586
  }
412
587
  __classPrivateFieldGet(this, _Trellis_log, "f").info({ method: String(method) }, `Mounting ${method.toString()} RPC handler`);
413
588
  const sub = this.nats.subscribe(subject);
414
- return trellis_result_1.AsyncResult.try(async () => {
589
+ return result_1.AsyncResult.try(async () => {
415
590
  for await (const msg of sub) {
416
591
  const resultPromise = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_processRPCMessage).call(this, method, ctx, msg, fn);
417
592
  const result = resultPromise.take();
418
- if ((0, trellis_result_1.isErr)(result)) {
593
+ if ((0, result_1.isErr)(result)) {
419
594
  __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_respondWithError).call(this, msg, result.error);
420
595
  continue;
421
596
  }
@@ -425,42 +600,41 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
425
600
  }, _Trellis_processRPCMessage = async function _Trellis_processRPCMessage(method, ctx, msg, fn) {
426
601
  __classPrivateFieldGet(this, _Trellis_log, "f").debug({ method: String(method), subject: msg.subject }, "Processing RPC message");
427
602
  // Extract trace context from incoming NATS headers
428
- const parentContext = (0, trellis_telemetry_1.extractTraceContext)((0, trellis_telemetry_1.createNatsHeaderCarrier)({
603
+ const parentContext = (0, tracing_ts_1.extractTraceContext)((0, tracing_ts_1.createNatsHeaderCarrier)({
429
604
  get: (k) => msg.headers?.get(k) ?? undefined,
430
605
  set: () => { }, // Server doesn't need to set headers on incoming messages
431
606
  }));
432
607
  // Start a server span for this RPC handler
433
- const span = (0, trellis_telemetry_1.startServerSpan)(method, msg.subject, parentContext);
608
+ const span = (0, tracing_ts_1.startServerSpan)(method, msg.subject, parentContext);
434
609
  // Execute the handler within the span's context
435
- return (0, trellis_telemetry_1.withSpanAsync)(span, async () => {
610
+ return (0, tracing_ts_1.withSpanAsync)(span, async () => {
436
611
  const execute = async () => {
437
612
  const jsonData = safeJson(msg).take();
438
- if ((0, trellis_result_1.isErr)(jsonData)) {
613
+ if ((0, result_1.isErr)(jsonData)) {
439
614
  __classPrivateFieldGet(this, _Trellis_log, "f").warn({ method, error: jsonData.error.message }, "Failed to parse JSON");
440
615
  span.setStatus({
441
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
616
+ code: tracing_ts_1.SpanStatusCode.ERROR,
442
617
  message: "Failed to parse JSON",
443
618
  });
444
619
  return jsonData;
445
620
  }
446
- const parsedInput = (0, codec_js_1.parseSchema)(ctx.input, jsonData).take();
447
- if ((0, trellis_result_1.isErr)(parsedInput)) {
621
+ const parsedInput = parseRuntimeSchema(ctx.input, jsonData).take();
622
+ if ((0, result_1.isErr)(parsedInput)) {
448
623
  span.setStatus({
449
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
624
+ code: tracing_ts_1.SpanStatusCode.ERROR,
450
625
  message: "Input validation failed",
451
626
  });
452
627
  return parsedInput;
453
628
  }
454
- let user;
629
+ let caller;
455
630
  const callerSessionKey = msg.headers?.get("session-key") ?? "";
456
631
  const authRequired = ctx.authRequired ?? true;
457
632
  if (!authRequired || __classPrivateFieldGet(this, _Trellis_authBypassMethods, "f").has(method)) {
458
- user = {
633
+ caller = {
634
+ type: "service",
459
635
  id: "system",
460
- origin: "trellis",
461
636
  active: true,
462
637
  name: "System",
463
- email: "system@trellis.internal",
464
638
  capabilities: ["service"],
465
639
  };
466
640
  }
@@ -470,25 +644,25 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
470
644
  if (!sessionKey) {
471
645
  __classPrivateFieldGet(this, _Trellis_log, "f").warn({ method }, "Missing session-key header");
472
646
  span.setStatus({
473
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
647
+ code: tracing_ts_1.SpanStatusCode.ERROR,
474
648
  message: "Missing session-key",
475
649
  });
476
- return (0, trellis_result_1.err)(new index_js_1.AuthError({ reason: "missing_session_key" }));
650
+ return (0, result_1.err)(new index_ts_1.AuthError({ reason: "missing_session_key" }));
477
651
  }
478
652
  if (!proof) {
479
653
  __classPrivateFieldGet(this, _Trellis_log, "f").warn({ method }, "Missing proof in request");
480
654
  span.setStatus({
481
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
655
+ code: tracing_ts_1.SpanStatusCode.ERROR,
482
656
  message: "Missing proof",
483
657
  });
484
- return (0, trellis_result_1.err)(new index_js_1.AuthError({ reason: "missing_proof" }));
658
+ return (0, result_1.err)(new index_ts_1.AuthError({ reason: "missing_proof" }));
485
659
  }
486
660
  // Verify proof signature locally using the raw request bytes we received.
487
661
  const payloadBytes = msg.data ?? new Uint8Array();
488
662
  const payloadHash = await sha256(payloadBytes);
489
663
  const proofInput = buildProofInput(sessionKey, msg.subject, payloadHash);
490
664
  const digest = await sha256(proofInput);
491
- const verifyResult = await trellis_result_1.AsyncResult.try(async () => {
665
+ const verifyResult = await result_1.AsyncResult.try(async () => {
492
666
  const publicKeyRaw = base64urlDecode(sessionKey);
493
667
  const pub = await crypto.subtle.importKey("raw", toArrayBuffer(publicKeyRaw), { name: "Ed25519" }, true, ["verify"]);
494
668
  return crypto.subtle.verify({ name: "Ed25519" }, pub, toArrayBuffer(base64urlDecode(proof)), toArrayBuffer(digest));
@@ -497,15 +671,15 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
497
671
  (await verifyResult).take() === true;
498
672
  if (!signatureOk) {
499
673
  span.setStatus({
500
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
674
+ code: tracing_ts_1.SpanStatusCode.ERROR,
501
675
  message: "Invalid signature",
502
676
  });
503
- return (0, trellis_result_1.err)(new index_js_1.AuthError({
677
+ return (0, result_1.err)(new index_ts_1.AuthError({
504
678
  reason: "invalid_signature",
505
679
  context: { sessionKey },
506
680
  }));
507
681
  }
508
- const authResult = await this.request("Auth.ValidateRequest", {
682
+ const authResult = await this.requestAuthValidate({
509
683
  sessionKey,
510
684
  proof,
511
685
  subject: msg.subject,
@@ -513,52 +687,61 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
513
687
  capabilities: ctx.callerCapabilities,
514
688
  });
515
689
  const auth = authResult.take();
516
- if ((0, trellis_result_1.isErr)(auth)) {
690
+ if ((0, result_1.isErr)(auth)) {
517
691
  __classPrivateFieldGet(this, _Trellis_log, "f").warn({
518
692
  method,
519
693
  error: auth.error.message,
520
694
  errorType: auth.error.name,
521
- remoteError: auth.error instanceof RemoteError_js_1.RemoteError
695
+ remoteError: auth.error instanceof RemoteError_ts_1.RemoteError
522
696
  ? auth.error.toSerializable()
523
697
  : undefined,
524
698
  }, "Auth.ValidateRequest failed");
525
699
  span.setStatus({
526
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
700
+ code: tracing_ts_1.SpanStatusCode.ERROR,
527
701
  message: "Auth.ValidateRequest failed",
528
702
  });
529
- return auth;
703
+ return (0, result_1.err)(auth.error);
530
704
  }
531
705
  if (!auth.allowed) {
532
706
  span.setStatus({
533
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
707
+ code: tracing_ts_1.SpanStatusCode.ERROR,
534
708
  message: "Insufficient permissions",
535
709
  });
536
- return (0, trellis_result_1.err)(new index_js_1.AuthError({
710
+ return (0, result_1.err)(new index_ts_1.AuthError({
537
711
  reason: "insufficient_permissions",
538
712
  context: {
539
713
  requiredCapabilities: ctx.callerCapabilities,
540
- userCapabilities: auth.user.capabilities,
714
+ userCapabilities: auth.caller.capabilities,
541
715
  },
542
716
  }));
543
717
  }
544
718
  if (typeof msg.reply !== "string" ||
545
719
  !msg.reply.startsWith(`${auth.inboxPrefix}.`)) {
546
720
  span.setStatus({
547
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
721
+ code: tracing_ts_1.SpanStatusCode.ERROR,
548
722
  message: "Reply subject mismatch",
549
723
  });
550
- return (0, trellis_result_1.err)(new index_js_1.AuthError({
724
+ return (0, result_1.err)(new index_ts_1.AuthError({
551
725
  reason: "reply_subject_mismatch",
552
726
  context: { expected: auth.inboxPrefix, actual: msg.reply },
553
727
  }));
554
728
  }
555
- user = auth.user;
729
+ caller = auth.caller;
730
+ }
731
+ span.setAttribute("auth.caller.type", caller.type);
732
+ if (caller.type === "user") {
733
+ span.setAttribute("user.id", caller.id);
734
+ span.setAttribute("user.origin", caller.origin);
556
735
  }
557
- // Add user info to span attributes
558
- span.setAttribute("user.id", user.id);
559
- span.setAttribute("user.origin", user.origin);
560
- const handlerResultWrapped = await trellis_result_1.AsyncResult.try(() => fn(parsedInput, {
561
- user,
736
+ if (caller.type === "service") {
737
+ span.setAttribute("service.id", caller.id);
738
+ }
739
+ if (caller.type === "workload") {
740
+ span.setAttribute("workload.instance_id", caller.instanceId);
741
+ span.setAttribute("workload.profile_id", caller.profileId);
742
+ }
743
+ const handlerResultWrapped = await result_1.AsyncResult.try(() => fn(parsedInput, {
744
+ caller,
562
745
  sessionKey: callerSessionKey,
563
746
  }));
564
747
  if (handlerResultWrapped.isErr()) {
@@ -571,21 +754,21 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
571
754
  : error.cause,
572
755
  }, "Handler threw unexpectedly.");
573
756
  span.setStatus({
574
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
757
+ code: tracing_ts_1.SpanStatusCode.ERROR,
575
758
  message: error.message,
576
759
  });
577
760
  span.recordException(error);
578
- return (0, trellis_result_1.err)(error);
761
+ return (0, result_1.err)(error);
579
762
  }
580
763
  const handlerResult = (await handlerResultWrapped).take();
581
764
  const handlerOutcome = handlerResult.take();
582
- if ((0, trellis_result_1.isErr)(handlerOutcome)) {
765
+ if ((0, result_1.isErr)(handlerOutcome)) {
583
766
  const handlerError = handlerOutcome.error;
584
- const error = handlerError instanceof index_js_1.UnexpectedError ||
585
- handlerError instanceof index_js_1.AuthError ||
586
- handlerError instanceof index_js_1.ValidationError
767
+ const error = handlerError instanceof index_ts_1.UnexpectedError ||
768
+ handlerError instanceof index_ts_1.AuthError ||
769
+ handlerError instanceof index_ts_1.ValidationError
587
770
  ? handlerError
588
- : new index_js_1.UnexpectedError({ cause: handlerError });
771
+ : new index_ts_1.UnexpectedError({ cause: handlerError });
589
772
  __classPrivateFieldGet(this, _Trellis_log, "f").error({
590
773
  method,
591
774
  error: error.message,
@@ -595,38 +778,38 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
595
778
  : error.cause,
596
779
  }, "Handler returned error.");
597
780
  span.setStatus({
598
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
781
+ code: tracing_ts_1.SpanStatusCode.ERROR,
599
782
  message: error.message,
600
783
  });
601
- return (0, trellis_result_1.err)(error);
784
+ return (0, result_1.err)(error);
602
785
  }
603
- const encoded = (0, codec_js_1.encodeSchema)(ctx.output, handlerOutcome).take();
604
- if ((0, trellis_result_1.isErr)(encoded)) {
786
+ const encoded = (0, codec_ts_1.encodeSchema)(ctx.output, handlerOutcome).take();
787
+ if ((0, result_1.isErr)(encoded)) {
605
788
  span.setStatus({
606
- code: trellis_telemetry_1.SpanStatusCode.ERROR,
789
+ code: tracing_ts_1.SpanStatusCode.ERROR,
607
790
  message: "Output encoding failed",
608
791
  });
609
792
  return encoded;
610
793
  }
611
- span.setStatus({ code: trellis_telemetry_1.SpanStatusCode.OK });
612
- return (0, trellis_result_1.ok)(encoded);
794
+ span.setStatus({ code: tracing_ts_1.SpanStatusCode.OK });
795
+ return (0, result_1.ok)(encoded);
613
796
  };
614
797
  const result = await execute();
615
798
  span.end();
616
799
  return result;
617
800
  });
618
801
  }, _Trellis_respondWithError = function _Trellis_respondWithError(msg, error) {
619
- const trellisError = error instanceof index_js_1.UnexpectedError ||
620
- error instanceof index_js_1.AuthError ||
621
- error instanceof index_js_1.ValidationError ||
622
- error instanceof RemoteError_js_1.RemoteError
802
+ const trellisError = error instanceof index_ts_1.UnexpectedError ||
803
+ error instanceof index_ts_1.AuthError ||
804
+ error instanceof index_ts_1.ValidationError ||
805
+ error instanceof RemoteError_ts_1.RemoteError
623
806
  ? error
624
- : new index_js_1.UnexpectedError({ cause: error });
807
+ : new index_ts_1.UnexpectedError({ cause: error });
625
808
  __classPrivateFieldGet(this, _Trellis_log, "f").error({ error: trellisError.toSerializable() }, "RPC error");
626
809
  const errorData = trellisError.toSerializable();
627
810
  const hdrs = (0, nats_core_1.headers)();
628
811
  hdrs.set("status", "error");
629
- const serialized = trellis_result_1.Result.try(() => JSON.stringify(errorData));
812
+ const serialized = result_1.Result.try(() => JSON.stringify(errorData));
630
813
  if (serialized.isErr()) {
631
814
  __classPrivateFieldGet(this, _Trellis_log, "f").error({ error: serialized.error }, "Failed to serialize error response");
632
815
  msg.respond('{"type":"UnexpectedError","message":"Failed to serialize error"}', { headers: hdrs });
@@ -635,24 +818,35 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
635
818
  msg.respond(serialized.take(), { headers: hdrs });
636
819
  }, _Trellis_handleEvent = function _Trellis_handleEvent(event, consumer, fn) {
637
820
  const ctx = this.api["events"][event];
638
- return trellis_result_1.AsyncResult.try(async () => {
821
+ return result_1.AsyncResult.try(async () => {
639
822
  const msgs = await consumer.consume();
640
823
  for await (const msg of msgs) {
641
- const jsonData = trellis_result_1.Result.try(() => msg.json());
824
+ const jsonData = result_1.Result.try(() => msg.json());
642
825
  if (jsonData.isErr()) {
643
826
  __classPrivateFieldGet(this, _Trellis_log, "f").error({ error: jsonData.error }, "Event parse failed");
644
827
  msg.term();
645
828
  continue;
646
829
  }
647
- const m = (0, codec_js_1.parseSchema)(ctx.event, jsonData.take()).take();
648
- if ((0, trellis_result_1.isErr)(m)) {
830
+ const json = jsonData.take();
831
+ if ((0, result_1.isErr)(json)) {
832
+ __classPrivateFieldGet(this, _Trellis_log, "f").error({ error: json.error }, "Event parse failed");
833
+ msg.term();
834
+ continue;
835
+ }
836
+ const parsedEvent = parseRuntimeSchema(ctx.event, json);
837
+ const m = parsedEvent.take();
838
+ if ((0, result_1.isErr)(m)) {
649
839
  __classPrivateFieldGet(this, _Trellis_log, "f").error({ error: m.error }, "Event validation failed");
650
840
  msg.term();
651
841
  continue;
652
842
  }
653
- const handlerResult = await trellis_result_1.AsyncResult.lift(fn(m));
843
+ const handlerResult = await result_1.AsyncResult.lift(fn(m));
654
844
  if (handlerResult.isErr()) {
655
- __classPrivateFieldGet(this, _Trellis_log, "f").error({ error: handlerResult.error.toSerializable(), event, subject: msg.subject }, "Event handler failed");
845
+ __classPrivateFieldGet(this, _Trellis_log, "f").error({
846
+ error: handlerResult.error.toSerializable(),
847
+ event,
848
+ subject: msg.subject,
849
+ }, "Event handler failed");
656
850
  msg.nak();
657
851
  continue;
658
852
  }
@@ -673,43 +867,51 @@ _Trellis_log = new WeakMap(), _Trellis_tasks = new WeakMap(), _Trellis_noRespond
673
867
  const digest = await sha256(input);
674
868
  const sigBytes = await this.auth.sign(digest);
675
869
  return base64urlEncode(sigBytes);
676
- };
677
- class TrellisServer extends Trellis {
678
- constructor(name, nats, auth, opts) {
679
- super(name, nats, auth, opts);
680
- _TrellisServer_version.set(this, void 0);
681
- _TrellisServer_log.set(this, void 0);
682
- __classPrivateFieldSet(this, _TrellisServer_version, opts?.version, "f");
683
- __classPrivateFieldSet(this, _TrellisServer_log, (opts?.log ?? globals_js_1.logger).child({ lib: "trellis-server" }), "f");
870
+ }, _Trellis_requestJson = async function _Trellis_requestJson(subject, body) {
871
+ const payload = JSON.stringify(body);
872
+ const proof = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_createProof).call(this, subject, payload);
873
+ const headers = (0, nats_core_1.headers)();
874
+ headers.set("session-key", this.auth.sessionKey);
875
+ headers.set("proof", proof);
876
+ const response = await result_1.AsyncResult.try(() => this.nats.request(subject, payload, {
877
+ timeout: this.timeout,
878
+ headers,
879
+ })).take();
880
+ if ((0, result_1.isErr)(response)) {
881
+ return response;
684
882
  }
685
- /**
686
- * Creates an authenticated TrellisServer instance.
687
- *
688
- * Services connect to NATS using the session-key auth flow (see ADR):
689
- * - NATS `auth_token` (aka `token`) is a JSON string `{ v: 1, sessionKey, iat, sig }`
690
- * - `sig` signs SHA-256(`nats-connect:${iat}`) with the session key
691
- * - `inboxPrefix` MUST be `_INBOX.${sessionKey.slice(0, 16)}`
692
- *
693
- * @param name Unique name for this service
694
- * @param nats Existing NATS connection (already authenticated)
695
- * @param auth Service session-key credentials
696
- * @param opts Optional server options
697
- * @returns An authenticated TrellisServer instance
698
- */
699
- static create(name, nats, auth, opts) {
700
- return new TrellisServer(name, nats, auth, opts);
883
+ return safeJson(response);
884
+ }, _Trellis_watchJson = async function _Trellis_watchJson(subject, body) {
885
+ const payload = JSON.stringify(body);
886
+ const proof = await __classPrivateFieldGet(this, _Trellis_instances, "m", _Trellis_createProof).call(this, subject, payload);
887
+ const headers = (0, nats_core_1.headers)();
888
+ headers.set("session-key", this.auth.sessionKey);
889
+ headers.set("proof", proof);
890
+ const inbox = (0, nats_core_1.createInbox)(`_INBOX.${this.auth.sessionKey.slice(0, 16)}`);
891
+ const sub = this.nats.subscribe(inbox);
892
+ try {
893
+ this.nats.publish(subject, payload, {
894
+ headers,
895
+ reply: inbox,
896
+ });
897
+ await this.nats.flush();
701
898
  }
702
- /**
703
- * Stops the server by clearing refresh timers and draining the NATS connection.
704
- * Draining allows in-flight messages to complete before closing the connection.
705
- * This method is idempotent and can be called multiple times safely.
706
- */
707
- async stop() {
708
- // Only drain if the connection is not already closed
709
- if (!this.natsConnection.isClosed()) {
710
- await this.natsConnection.drain();
711
- }
899
+ catch (cause) {
900
+ sub.unsubscribe();
901
+ return (0, result_1.err)(new index_ts_1.UnexpectedError({ cause }));
712
902
  }
713
- }
714
- exports.TrellisServer = TrellisServer;
715
- _TrellisServer_version = new WeakMap(), _TrellisServer_log = new WeakMap();
903
+ return (0, result_1.ok)((async function* () {
904
+ try {
905
+ for await (const msg of sub) {
906
+ if (msg.headers?.get("status") === "error") {
907
+ yield (0, result_1.err)(new index_ts_1.UnexpectedError({ cause: new Error(msg.string()) }));
908
+ continue;
909
+ }
910
+ yield safeJson(msg);
911
+ }
912
+ }
913
+ finally {
914
+ sub.unsubscribe();
915
+ }
916
+ })());
917
+ };