@astrale-os/kernel-client 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 (257) hide show
  1. package/dist/client/batch.d.ts +26 -0
  2. package/dist/client/batch.d.ts.map +1 -0
  3. package/dist/client/batch.js +8 -0
  4. package/dist/client/batch.js.map +1 -0
  5. package/dist/client/bound.d.ts +27 -0
  6. package/dist/client/bound.d.ts.map +1 -0
  7. package/dist/client/bound.js +14 -0
  8. package/dist/client/bound.js.map +1 -0
  9. package/dist/client/client.d.ts +93 -0
  10. package/dist/client/client.d.ts.map +1 -0
  11. package/dist/client/client.js +393 -0
  12. package/dist/client/client.js.map +1 -0
  13. package/dist/client/config.d.ts +112 -0
  14. package/dist/client/config.d.ts.map +1 -0
  15. package/dist/client/config.js +10 -0
  16. package/dist/client/config.js.map +1 -0
  17. package/dist/client/fn-map.d.ts +61 -0
  18. package/dist/client/fn-map.d.ts.map +1 -0
  19. package/dist/client/fn-map.js +2 -0
  20. package/dist/client/fn-map.js.map +1 -0
  21. package/dist/client/freeze.d.ts +32 -0
  22. package/dist/client/freeze.d.ts.map +1 -0
  23. package/dist/client/freeze.js +42 -0
  24. package/dist/client/freeze.js.map +1 -0
  25. package/dist/client/hooks.d.ts +49 -0
  26. package/dist/client/hooks.d.ts.map +1 -0
  27. package/dist/client/hooks.js +2 -0
  28. package/dist/client/hooks.js.map +1 -0
  29. package/dist/client/index.d.ts +7 -0
  30. package/dist/client/index.d.ts.map +1 -0
  31. package/dist/client/index.js +2 -0
  32. package/dist/client/index.js.map +1 -0
  33. package/dist/delegation/cache.d.ts +133 -0
  34. package/dist/delegation/cache.d.ts.map +1 -0
  35. package/dist/delegation/cache.js +258 -0
  36. package/dist/delegation/cache.js.map +1 -0
  37. package/dist/delegation/errors.d.ts +44 -0
  38. package/dist/delegation/errors.d.ts.map +1 -0
  39. package/dist/delegation/errors.js +62 -0
  40. package/dist/delegation/errors.js.map +1 -0
  41. package/dist/delegation/index.d.ts +6 -0
  42. package/dist/delegation/index.d.ts.map +1 -0
  43. package/dist/delegation/index.js +4 -0
  44. package/dist/delegation/index.js.map +1 -0
  45. package/dist/delegation/policy.d.ts +175 -0
  46. package/dist/delegation/policy.d.ts.map +1 -0
  47. package/dist/delegation/policy.js +109 -0
  48. package/dist/delegation/policy.js.map +1 -0
  49. package/dist/errors/errors.d.ts +103 -0
  50. package/dist/errors/errors.d.ts.map +1 -0
  51. package/dist/errors/errors.js +170 -0
  52. package/dist/errors/errors.js.map +1 -0
  53. package/dist/errors/index.d.ts +4 -0
  54. package/dist/errors/index.d.ts.map +1 -0
  55. package/dist/errors/index.js +3 -0
  56. package/dist/errors/index.js.map +1 -0
  57. package/dist/errors/session-error.d.ts +21 -0
  58. package/dist/errors/session-error.d.ts.map +1 -0
  59. package/dist/errors/session-error.js +25 -0
  60. package/dist/errors/session-error.js.map +1 -0
  61. package/dist/index.d.ts +17 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +10 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/pacer/batcher.d.ts +11 -0
  66. package/dist/pacer/batcher.d.ts.map +1 -0
  67. package/dist/pacer/batcher.js +15 -0
  68. package/dist/pacer/batcher.js.map +1 -0
  69. package/dist/pacer/defaults.d.ts +18 -0
  70. package/dist/pacer/defaults.d.ts.map +1 -0
  71. package/dist/pacer/defaults.js +18 -0
  72. package/dist/pacer/defaults.js.map +1 -0
  73. package/dist/pacer/index.d.ts +10 -0
  74. package/dist/pacer/index.d.ts.map +1 -0
  75. package/dist/pacer/index.js +11 -0
  76. package/dist/pacer/index.js.map +1 -0
  77. package/dist/pacer/queue.d.ts +11 -0
  78. package/dist/pacer/queue.d.ts.map +1 -0
  79. package/dist/pacer/queue.js +15 -0
  80. package/dist/pacer/queue.js.map +1 -0
  81. package/dist/pacer/rate-limiter.d.ts +11 -0
  82. package/dist/pacer/rate-limiter.d.ts.map +1 -0
  83. package/dist/pacer/rate-limiter.js +15 -0
  84. package/dist/pacer/rate-limiter.js.map +1 -0
  85. package/dist/pacer/retry.d.ts +14 -0
  86. package/dist/pacer/retry.d.ts.map +1 -0
  87. package/dist/pacer/retry.js +50 -0
  88. package/dist/pacer/retry.js.map +1 -0
  89. package/dist/persistence/index.d.ts +3 -0
  90. package/dist/persistence/index.d.ts.map +1 -0
  91. package/dist/persistence/index.js +2 -0
  92. package/dist/persistence/index.js.map +1 -0
  93. package/dist/persistence/persistence.d.ts +52 -0
  94. package/dist/persistence/persistence.d.ts.map +1 -0
  95. package/dist/persistence/persistence.js +32 -0
  96. package/dist/persistence/persistence.js.map +1 -0
  97. package/dist/pool/errors.d.ts +13 -0
  98. package/dist/pool/errors.d.ts.map +1 -0
  99. package/dist/pool/errors.js +16 -0
  100. package/dist/pool/errors.js.map +1 -0
  101. package/dist/pool/index.d.ts +4 -0
  102. package/dist/pool/index.d.ts.map +1 -0
  103. package/dist/pool/index.js +3 -0
  104. package/dist/pool/index.js.map +1 -0
  105. package/dist/pool/pool.d.ts +63 -0
  106. package/dist/pool/pool.d.ts.map +1 -0
  107. package/dist/pool/pool.js +87 -0
  108. package/dist/pool/pool.js.map +1 -0
  109. package/dist/redirect/errors.d.ts +45 -0
  110. package/dist/redirect/errors.d.ts.map +1 -0
  111. package/dist/redirect/errors.js +52 -0
  112. package/dist/redirect/errors.js.map +1 -0
  113. package/dist/redirect/index.d.ts +4 -0
  114. package/dist/redirect/index.d.ts.map +1 -0
  115. package/dist/redirect/index.js +3 -0
  116. package/dist/redirect/index.js.map +1 -0
  117. package/dist/redirect/policy.d.ts +79 -0
  118. package/dist/redirect/policy.d.ts.map +1 -0
  119. package/dist/redirect/policy.js +69 -0
  120. package/dist/redirect/policy.js.map +1 -0
  121. package/dist/schema/call-args.d.ts +6 -0
  122. package/dist/schema/call-args.d.ts.map +1 -0
  123. package/dist/schema/call-args.js +21 -0
  124. package/dist/schema/call-args.js.map +1 -0
  125. package/dist/schema/class-proxy.d.ts +8 -0
  126. package/dist/schema/class-proxy.d.ts.map +1 -0
  127. package/dist/schema/class-proxy.js +38 -0
  128. package/dist/schema/class-proxy.js.map +1 -0
  129. package/dist/schema/extract.d.ts +9 -0
  130. package/dist/schema/extract.d.ts.map +1 -0
  131. package/dist/schema/extract.js +16 -0
  132. package/dist/schema/extract.js.map +1 -0
  133. package/dist/schema/from-entries.d.ts +12 -0
  134. package/dist/schema/from-entries.d.ts.map +1 -0
  135. package/dist/schema/from-entries.js +39 -0
  136. package/dist/schema/from-entries.js.map +1 -0
  137. package/dist/schema/index.d.ts +11 -0
  138. package/dist/schema/index.d.ts.map +1 -0
  139. package/dist/schema/index.js +9 -0
  140. package/dist/schema/index.js.map +1 -0
  141. package/dist/schema/node-proxy.d.ts +9 -0
  142. package/dist/schema/node-proxy.d.ts.map +1 -0
  143. package/dist/schema/node-proxy.js +32 -0
  144. package/dist/schema/node-proxy.js.map +1 -0
  145. package/dist/schema/proxy-types.d.ts +112 -0
  146. package/dist/schema/proxy-types.d.ts.map +1 -0
  147. package/dist/schema/proxy-types.js +2 -0
  148. package/dist/schema/proxy-types.js.map +1 -0
  149. package/dist/schema/registry.d.ts +51 -0
  150. package/dist/schema/registry.d.ts.map +1 -0
  151. package/dist/schema/registry.js +111 -0
  152. package/dist/schema/registry.js.map +1 -0
  153. package/dist/schema/resolve.d.ts +26 -0
  154. package/dist/schema/resolve.d.ts.map +1 -0
  155. package/dist/schema/resolve.js +27 -0
  156. package/dist/schema/resolve.js.map +1 -0
  157. package/dist/schema/typed-client.d.ts +10 -0
  158. package/dist/schema/typed-client.d.ts.map +1 -0
  159. package/dist/schema/typed-client.js +26 -0
  160. package/dist/schema/typed-client.js.map +1 -0
  161. package/dist/schema/types.d.ts +9 -0
  162. package/dist/schema/types.d.ts.map +1 -0
  163. package/dist/schema/types.js +2 -0
  164. package/dist/schema/types.js.map +1 -0
  165. package/dist/session/bound.d.ts +11 -0
  166. package/dist/session/bound.d.ts.map +1 -0
  167. package/dist/session/bound.js +24 -0
  168. package/dist/session/bound.js.map +1 -0
  169. package/dist/session/client-session.d.ts +61 -0
  170. package/dist/session/client-session.d.ts.map +1 -0
  171. package/dist/session/client-session.js +635 -0
  172. package/dist/session/client-session.js.map +1 -0
  173. package/dist/session/config.d.ts +157 -0
  174. package/dist/session/config.d.ts.map +1 -0
  175. package/dist/session/config.js +2 -0
  176. package/dist/session/config.js.map +1 -0
  177. package/dist/session/errors/index.d.ts +6 -0
  178. package/dist/session/errors/index.d.ts.map +1 -0
  179. package/dist/session/errors/index.js +8 -0
  180. package/dist/session/errors/index.js.map +1 -0
  181. package/dist/session/errors/session-errors.d.ts +52 -0
  182. package/dist/session/errors/session-errors.d.ts.map +1 -0
  183. package/dist/session/errors/session-errors.js +70 -0
  184. package/dist/session/errors/session-errors.js.map +1 -0
  185. package/dist/session/forward.d.ts +14 -0
  186. package/dist/session/forward.d.ts.map +1 -0
  187. package/dist/session/forward.js +44 -0
  188. package/dist/session/forward.js.map +1 -0
  189. package/dist/session/helpers.d.ts +23 -0
  190. package/dist/session/helpers.d.ts.map +1 -0
  191. package/dist/session/helpers.js +56 -0
  192. package/dist/session/helpers.js.map +1 -0
  193. package/dist/session/hooks.d.ts +140 -0
  194. package/dist/session/hooks.d.ts.map +1 -0
  195. package/dist/session/hooks.js +2 -0
  196. package/dist/session/hooks.js.map +1 -0
  197. package/dist/session/index.d.ts +6 -0
  198. package/dist/session/index.d.ts.map +1 -0
  199. package/dist/session/index.js +3 -0
  200. package/dist/session/index.js.map +1 -0
  201. package/dist/session/types.d.ts +38 -0
  202. package/dist/session/types.d.ts.map +1 -0
  203. package/dist/session/types.js +2 -0
  204. package/dist/session/types.js.map +1 -0
  205. package/dist/transport/binary.d.ts +15 -0
  206. package/dist/transport/binary.d.ts.map +1 -0
  207. package/dist/transport/binary.js +2 -0
  208. package/dist/transport/binary.js.map +1 -0
  209. package/dist/transport/contract.d.ts +58 -0
  210. package/dist/transport/contract.d.ts.map +1 -0
  211. package/dist/transport/contract.js +11 -0
  212. package/dist/transport/contract.js.map +1 -0
  213. package/dist/transport/fetch.d.ts +28 -0
  214. package/dist/transport/fetch.d.ts.map +1 -0
  215. package/dist/transport/fetch.js +74 -0
  216. package/dist/transport/fetch.js.map +1 -0
  217. package/dist/transport/http-envelope.d.ts +49 -0
  218. package/dist/transport/http-envelope.d.ts.map +1 -0
  219. package/dist/transport/http-envelope.js +405 -0
  220. package/dist/transport/http-envelope.js.map +1 -0
  221. package/dist/transport/http-routed.d.ts +61 -0
  222. package/dist/transport/http-routed.d.ts.map +1 -0
  223. package/dist/transport/http-routed.js +409 -0
  224. package/dist/transport/http-routed.js.map +1 -0
  225. package/dist/transport/index.d.ts +8 -0
  226. package/dist/transport/index.d.ts.map +1 -0
  227. package/dist/transport/index.js +6 -0
  228. package/dist/transport/index.js.map +1 -0
  229. package/dist/transport/request-id.d.ts +9 -0
  230. package/dist/transport/request-id.d.ts.map +1 -0
  231. package/dist/transport/request-id.js +12 -0
  232. package/dist/transport/request-id.js.map +1 -0
  233. package/dist/transport/ws-envelope.d.ts +74 -0
  234. package/dist/transport/ws-envelope.d.ts.map +1 -0
  235. package/dist/transport/ws-envelope.js +560 -0
  236. package/dist/transport/ws-envelope.js.map +1 -0
  237. package/dist/util/race-signal.d.ts +12 -0
  238. package/dist/util/race-signal.d.ts.map +1 -0
  239. package/dist/util/race-signal.js +34 -0
  240. package/dist/util/race-signal.js.map +1 -0
  241. package/dist/wire/controller.d.ts +38 -0
  242. package/dist/wire/controller.d.ts.map +1 -0
  243. package/dist/wire/controller.js +38 -0
  244. package/dist/wire/controller.js.map +1 -0
  245. package/dist/wire/index.d.ts +7 -0
  246. package/dist/wire/index.d.ts.map +1 -0
  247. package/dist/wire/index.js +4 -0
  248. package/dist/wire/index.js.map +1 -0
  249. package/dist/wire/meta.d.ts +81 -0
  250. package/dist/wire/meta.d.ts.map +1 -0
  251. package/dist/wire/meta.js +44 -0
  252. package/dist/wire/meta.js.map +1 -0
  253. package/dist/wire/sse.d.ts +67 -0
  254. package/dist/wire/sse.d.ts.map +1 -0
  255. package/dist/wire/sse.js +170 -0
  256. package/dist/wire/sse.js.map +1 -0
  257. package/package.json +104 -0
@@ -0,0 +1,11 @@
1
+ import { AsyncQueuer, type AsyncQueuerOptions } from '@tanstack/pacer';
2
+ export type KernelQueueOptions<TValue> = Omit<AsyncQueuerOptions<TValue>, 'concurrency'> & {
3
+ concurrency?: number;
4
+ };
5
+ /**
6
+ * Create an AsyncQueuer pre-configured with kernel defaults.
7
+ * The caller provides the processing function; concurrency defaults to
8
+ * `QUEUE_DEFAULTS.concurrency` (10).
9
+ */
10
+ export declare function createQueue<TValue>(fn: (item: TValue) => Promise<unknown>, opts?: KernelQueueOptions<TValue>): AsyncQueuer<TValue>;
11
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/pacer/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAItE,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG;IACzF,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAChC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EACtC,IAAI,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAChC,WAAW,CAAC,MAAM,CAAC,CAMrB"}
@@ -0,0 +1,15 @@
1
+ import { AsyncQueuer } from '@tanstack/pacer';
2
+ import { QUEUE_DEFAULTS } from './defaults';
3
+ /**
4
+ * Create an AsyncQueuer pre-configured with kernel defaults.
5
+ * The caller provides the processing function; concurrency defaults to
6
+ * `QUEUE_DEFAULTS.concurrency` (10).
7
+ */
8
+ export function createQueue(fn, opts) {
9
+ const { concurrency, ...rest } = opts ?? {};
10
+ return new AsyncQueuer(fn, {
11
+ ...rest,
12
+ concurrency: concurrency ?? QUEUE_DEFAULTS.concurrency,
13
+ });
14
+ }
15
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/pacer/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA2B,MAAM,iBAAiB,CAAA;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAM3C;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,EAAsC,EACtC,IAAiC;IAEjC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;IAC3C,OAAO,IAAI,WAAW,CAAC,EAAE,EAAE;QACzB,GAAG,IAAI;QACP,WAAW,EAAE,WAAW,IAAI,cAAc,CAAC,WAAW;KACvD,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { AsyncRateLimiter, type AnyAsyncFunction, type AsyncRateLimiterOptions } from '@tanstack/pacer';
2
+ export type KernelRateLimitOptions<TFn extends AnyAsyncFunction> = Omit<AsyncRateLimiterOptions<TFn>, 'limit' | 'window'> & {
3
+ limit?: number;
4
+ window?: number;
5
+ };
6
+ /**
7
+ * Create an AsyncRateLimiter pre-configured with kernel defaults.
8
+ * `limit` defaults to 300 calls per `window` (60 s).
9
+ */
10
+ export declare function createRateLimiter<TFn extends AnyAsyncFunction>(fn: TFn, opts?: KernelRateLimitOptions<TFn>): AsyncRateLimiter<TFn>;
11
+ //# sourceMappingURL=rate-limiter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../../src/pacer/rate-limiter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC7B,MAAM,iBAAiB,CAAA;AAIxB,MAAM,MAAM,sBAAsB,CAAC,GAAG,SAAS,gBAAgB,IAAI,IAAI,CACrE,uBAAuB,CAAC,GAAG,CAAC,EAC5B,OAAO,GAAG,QAAQ,CACnB,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,SAAS,gBAAgB,EAC5D,EAAE,EAAE,GAAG,EACP,IAAI,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC,GACjC,gBAAgB,CAAC,GAAG,CAAC,CAOvB"}
@@ -0,0 +1,15 @@
1
+ import { AsyncRateLimiter, } from '@tanstack/pacer';
2
+ import { RATE_LIMIT_DEFAULTS } from './defaults';
3
+ /**
4
+ * Create an AsyncRateLimiter pre-configured with kernel defaults.
5
+ * `limit` defaults to 300 calls per `window` (60 s).
6
+ */
7
+ export function createRateLimiter(fn, opts) {
8
+ const { limit, window, ...rest } = opts ?? {};
9
+ return new AsyncRateLimiter(fn, {
10
+ ...rest,
11
+ limit: limit ?? RATE_LIMIT_DEFAULTS.limit,
12
+ window: window ?? RATE_LIMIT_DEFAULTS.window,
13
+ });
14
+ }
15
+ //# sourceMappingURL=rate-limiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/pacer/rate-limiter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAGjB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAUhD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAO,EACP,IAAkC;IAElC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;IAC7C,OAAO,IAAI,gBAAgB,CAAC,EAAE,EAAE;QAC9B,GAAG,IAAI;QACP,KAAK,EAAE,KAAK,IAAI,mBAAmB,CAAC,KAAK;QACzC,MAAM,EAAE,MAAM,IAAI,mBAAmB,CAAC,MAAM;KAC7C,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export type KernelRetryOptions = {
2
+ maxAttempts?: number;
3
+ baseWait?: number;
4
+ maxWait?: number;
5
+ jitter?: number;
6
+ shouldRetry?: (error: Error, attempt: number) => boolean;
7
+ };
8
+ /**
9
+ * Retry an async function with kernel defaults (exponential backoff, jitter,
10
+ * capped delay). The optional `shouldRetry` predicate lets transports opt out
11
+ * of retrying non-transient errors (e.g. 4xx responses).
12
+ */
13
+ export declare function kernelRetry<T>(fn: () => Promise<T>, opts?: KernelRetryOptions): Promise<T>;
14
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/pacer/retry.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAA;CACzD,CAAA;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,CA0ChG"}
@@ -0,0 +1,50 @@
1
+ import { AsyncRetryer } from '@tanstack/pacer';
2
+ import { RETRY_DEFAULTS } from './defaults';
3
+ /**
4
+ * Retry an async function with kernel defaults (exponential backoff, jitter,
5
+ * capped delay). The optional `shouldRetry` predicate lets transports opt out
6
+ * of retrying non-transient errors (e.g. 4xx responses).
7
+ */
8
+ export async function kernelRetry(fn, opts) {
9
+ const { shouldRetry, ...rest } = opts ?? {};
10
+ // `AsyncRetryer.execute()` has silent-undefined paths the pacer library
11
+ // calls "cancellation outcomes": it catches `AbortError` (by name) and
12
+ // resolves with `undefined` without firing any hook, and `retryer.abort()`
13
+ // triggered from `onRetry` does the same. Both violate the kernelRetry
14
+ // contract — the caller expects "resolve with the value OR throw the
15
+ // last error", never silent undefined.
16
+ //
17
+ // Capture every failure in the inner wrapper itself (belt-and-braces:
18
+ // onError fires for non-abort, our wrapper covers everything). Rethrow
19
+ // on undefined when we saw an error.
20
+ let lastSeenError;
21
+ const wrapped = async () => {
22
+ try {
23
+ return await fn();
24
+ }
25
+ catch (err) {
26
+ lastSeenError = err instanceof Error ? err : new Error(String(err));
27
+ throw err;
28
+ }
29
+ };
30
+ const retryerOpts = {
31
+ maxAttempts: rest.maxAttempts ?? RETRY_DEFAULTS.maxAttempts,
32
+ baseWait: rest.baseWait ?? RETRY_DEFAULTS.baseWait,
33
+ maxWait: rest.maxWait ?? RETRY_DEFAULTS.maxWait,
34
+ jitter: rest.jitter ?? RETRY_DEFAULTS.jitter,
35
+ backoff: 'exponential',
36
+ throwOnError: 'last',
37
+ onRetry(attempt, error, retryer) {
38
+ if (shouldRetry && !shouldRetry(error, attempt)) {
39
+ retryer.abort();
40
+ }
41
+ },
42
+ };
43
+ // oxlint-disable-next-line @typescript-eslint/no-explicit-any
44
+ const retryer = new AsyncRetryer(wrapped, retryerOpts);
45
+ const result = await retryer.execute();
46
+ if (result === undefined && lastSeenError)
47
+ throw lastSeenError;
48
+ return result;
49
+ }
50
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/pacer/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;A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AAE,WAAkB,CAAC,CAAA;IAC7D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;IACtC,IAAI,MAAM,KAAK,SAAS,IAAI,aAAa;QAAE,MAAM,aAAa,CAAA;IAC9D,OAAO,MAAW,CAAA;AACpB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { SchemaPersistence } from './persistence';
2
+ export { MemorySchemaStore } from './persistence';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/persistence/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { MemorySchemaStore } from './persistence';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/persistence/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,52 @@
1
+ import type { FunctionSchema } from '../schema/types';
2
+ /**
3
+ * Storage adapter for learned schemas. Pure I/O — the `SchemaRegistry`
4
+ * handles dedupe and contract-drift detection internally; persistence
5
+ * just moves opaque `FunctionSchema` records between memory and a
6
+ * durable medium.
7
+ *
8
+ * Spec §9.5.
9
+ */
10
+ export interface SchemaPersistence {
11
+ /**
12
+ * Load every persisted schema. Called once at ClientSession construction
13
+ * (when `ClientSessionConfig.schemaStore` is configured). Throws wrap as
14
+ * `PersistenceLoadFailedError` at the ClientSession boundary.
15
+ */
16
+ load(): Promise<FunctionSchema[]>;
17
+ /**
18
+ * Persist one schema. Called from ClientSession's registry-save path after a
19
+ * redirect learns a new entry. The implementation decides durability
20
+ * (write-through, debounced, etc.); ClientSession awaits it only to surface
21
+ * errors through the hook surface.
22
+ */
23
+ save(schema: FunctionSchema): Promise<void>;
24
+ /**
25
+ * Drop every persisted schema. Rarely the right answer — provided
26
+ * for test fixtures and explicit "reset" flows. ClientSession's
27
+ * `disconnect()` does NOT call this (spec §13.6).
28
+ */
29
+ clear(): Promise<void>;
30
+ }
31
+ /**
32
+ * In-memory reference implementation. Useful for tests and for
33
+ * ephemeral orchestrators where "persistence" across ClientSession lifetimes
34
+ * inside one process is the goal.
35
+ *
36
+ * Not durable across process restarts. Consumers wanting filesystem /
37
+ * IndexedDB / remote-kv persistence implement `SchemaPersistence`
38
+ * against their own backing store.
39
+ */
40
+ export declare class MemorySchemaStore implements SchemaPersistence {
41
+ private readonly entries;
42
+ /**
43
+ * Optional preloaded entries. Useful for tests and for round-tripping
44
+ * a snapshot across ClientSession lifetimes in-process. `load()` returns these
45
+ * verbatim until the first `save()` mutates the map.
46
+ */
47
+ constructor(initial?: readonly FunctionSchema[]);
48
+ load(): Promise<FunctionSchema[]>;
49
+ save(schema: FunctionSchema): Promise<void>;
50
+ clear(): Promise<void>;
51
+ }
52
+ //# sourceMappingURL=persistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/persistence/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;IAEjC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3C;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,YAAW,iBAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAE5D;;;;OAIG;IACH,YAAY,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,EAE9C;IAEK,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAEtC;IAEK,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhD;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * In-memory reference implementation. Useful for tests and for
3
+ * ephemeral orchestrators where "persistence" across ClientSession lifetimes
4
+ * inside one process is the goal.
5
+ *
6
+ * Not durable across process restarts. Consumers wanting filesystem /
7
+ * IndexedDB / remote-kv persistence implement `SchemaPersistence`
8
+ * against their own backing store.
9
+ */
10
+ export class MemorySchemaStore {
11
+ entries = new Map();
12
+ /**
13
+ * Optional preloaded entries. Useful for tests and for round-tripping
14
+ * a snapshot across ClientSession lifetimes in-process. `load()` returns these
15
+ * verbatim until the first `save()` mutates the map.
16
+ */
17
+ constructor(initial) {
18
+ if (initial)
19
+ for (const schema of initial)
20
+ this.entries.set(schema.ref, schema);
21
+ }
22
+ async load() {
23
+ return Array.from(this.entries.values());
24
+ }
25
+ async save(schema) {
26
+ this.entries.set(schema.ref, schema);
27
+ }
28
+ async clear() {
29
+ this.entries.clear();
30
+ }
31
+ }
32
+ //# sourceMappingURL=persistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../src/persistence/persistence.ts"],"names":[],"mappings":"AAkCA;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAiB;IACX,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAA;IAE5D;;;;OAIG;IACH,YAAY,OAAmC;QAC7C,IAAI,OAAO;YAAE,KAAK,MAAM,MAAM,IAAI,OAAO;gBAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACjF,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAsB;QAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { WebOSError } from '../errors/errors';
2
+ /**
3
+ * Any `pool.clientFor(url)` call after `pool.disconnect()` (or any
4
+ * `session.call` after `session.disconnect()`).
5
+ *
6
+ * The pool is single-use post-disconnect — resurrection is a consumer
7
+ * responsibility (construct a new ClientSession / pool). Spec §10.3.6.
8
+ */
9
+ export declare class PoolClosedError extends WebOSError {
10
+ readonly kind: 'POOL_CLOSED';
11
+ constructor(message?: string);
12
+ }
13
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/pool/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,QAAQ,CAAC,IAAI,EAAG,aAAa,CAAS;IAEtC,YAAY,OAAO,SAA+B,EAGjD;CACF"}
@@ -0,0 +1,16 @@
1
+ import { WebOSError } from '../errors/errors';
2
+ /**
3
+ * Any `pool.clientFor(url)` call after `pool.disconnect()` (or any
4
+ * `session.call` after `session.disconnect()`).
5
+ *
6
+ * The pool is single-use post-disconnect — resurrection is a consumer
7
+ * responsibility (construct a new ClientSession / pool). Spec §10.3.6.
8
+ */
9
+ export class PoolClosedError extends WebOSError {
10
+ kind = 'POOL_CLOSED';
11
+ constructor(message = 'ClientPool is disconnected') {
12
+ super(message);
13
+ this.name = 'PoolClosedError';
14
+ }
15
+ }
16
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/pool/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;;;;GAMG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IACpC,IAAI,GAAG,aAAsB,CAAA;IAEtC,YAAY,OAAO,GAAG,4BAA4B;QAChD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export type { ClientFactory, ClientPoolConfig } from './pool';
2
+ export { ClientPool } from './pool';
3
+ export { PoolClosedError } from './errors';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pool/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { ClientPool } from './pool';
2
+ export { PoolClosedError } from './errors';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pool/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,63 @@
1
+ import type { KernelClient } from '../client/client';
2
+ import type { FnMap } from '../client/fn-map';
3
+ /**
4
+ * Factory for constructing a `KernelClient` bound to a given URL.
5
+ *
6
+ * The ClientSession's default factory wires `fetch`, `codec`, `requestTimeout`,
7
+ * `defaultTransport`, `defaultProtocol`, `schema`, `hooks`, `retry` from a single
8
+ * base config. Consumers who need custom wire-layer config replace the
9
+ * factory — it is the one wiring seam between ClientSession's config and the
10
+ * client's.
11
+ */
12
+ export type ClientFactory<M extends FnMap = FnMap> = (url: string) => KernelClient<M>;
13
+ /**
14
+ * `ClientPool` configuration. Spec §9.1.
15
+ */
16
+ export type ClientPoolConfig<M extends FnMap = FnMap> = {
17
+ /** How to build a `KernelClient` for a URL the pool hasn't seen. */
18
+ clientFactory: ClientFactory<M>;
19
+ /**
20
+ * Maximum cached clients. Least-recently-used is evicted when
21
+ * exceeded. Default: `32`.
22
+ */
23
+ maxSize?: number;
24
+ };
25
+ /**
26
+ * URL → `KernelClient` map with bounded LRU eviction. Spec §9.1.
27
+ *
28
+ * Invariants:
29
+ * - Idempotent `disconnect()` — subsequent calls are no-ops.
30
+ * - Post-disconnect `clientFor` throws `PoolClosedError`.
31
+ * - Eviction cascades `disconnect()` to the evicted client.
32
+ * - Calls to `clientFor(url)` return the same instance for the same
33
+ * URL (until eviction), so pooled-client hook registration is stable.
34
+ */
35
+ export declare class ClientPool<M extends FnMap = FnMap> {
36
+ private readonly entries;
37
+ private readonly factory;
38
+ private readonly maxSize;
39
+ private closed;
40
+ private clock;
41
+ constructor(config: ClientPoolConfig<M>);
42
+ /**
43
+ * Resolve or create a client for `url`. Throws `PoolClosedError` if
44
+ * the pool has been disconnected.
45
+ */
46
+ clientFor(url: string): KernelClient<M>;
47
+ /**
48
+ * Evict a specific URL and call its client's `disconnect()`.
49
+ * Idempotent — no-op for unknown URLs.
50
+ */
51
+ evict(url: string): void;
52
+ /**
53
+ * Tear down every cached client. Idempotent. After disconnect,
54
+ * `clientFor` throws `PoolClosedError`.
55
+ */
56
+ disconnect(): void;
57
+ /** Current number of cached clients — pool introspection helper. */
58
+ get size(): number;
59
+ /** Whether `disconnect()` has been called. */
60
+ get isClosed(): boolean;
61
+ private evictLeastRecentlyUsed;
62
+ }
63
+ //# sourceMappingURL=pool.d.ts.map
@@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 @@
1
+ import { PoolClosedError } from './errors';
2
+ /**
3
+ * URL → `KernelClient` map with bounded LRU eviction. Spec §9.1.
4
+ *
5
+ * Invariants:
6
+ * - Idempotent `disconnect()` — subsequent calls are no-ops.
7
+ * - Post-disconnect `clientFor` throws `PoolClosedError`.
8
+ * - Eviction cascades `disconnect()` to the evicted client.
9
+ * - Calls to `clientFor(url)` return the same instance for the same
10
+ * URL (until eviction), so pooled-client hook registration is stable.
11
+ */
12
+ export class ClientPool {
13
+ entries = new Map();
14
+ factory;
15
+ maxSize;
16
+ closed = false;
17
+ clock = 0;
18
+ constructor(config) {
19
+ this.factory = config.clientFactory;
20
+ this.maxSize = config.maxSize ?? 32;
21
+ if (this.maxSize < 1) {
22
+ throw new Error(`ClientPool.maxSize must be >= 1 (got ${this.maxSize})`);
23
+ }
24
+ }
25
+ /**
26
+ * Resolve or create a client for `url`. Throws `PoolClosedError` if
27
+ * the pool has been disconnected.
28
+ */
29
+ clientFor(url) {
30
+ if (this.closed)
31
+ throw new PoolClosedError();
32
+ const existing = this.entries.get(url);
33
+ if (existing) {
34
+ existing.lastUsed = ++this.clock;
35
+ return existing.client;
36
+ }
37
+ if (this.entries.size >= this.maxSize)
38
+ this.evictLeastRecentlyUsed();
39
+ const client = this.factory(url);
40
+ this.entries.set(url, { client, lastUsed: ++this.clock });
41
+ return client;
42
+ }
43
+ /**
44
+ * Evict a specific URL and call its client's `disconnect()`.
45
+ * Idempotent — no-op for unknown URLs.
46
+ */
47
+ evict(url) {
48
+ const entry = this.entries.get(url);
49
+ if (!entry)
50
+ return;
51
+ this.entries.delete(url);
52
+ entry.client.disconnect();
53
+ }
54
+ /**
55
+ * Tear down every cached client. Idempotent. After disconnect,
56
+ * `clientFor` throws `PoolClosedError`.
57
+ */
58
+ disconnect() {
59
+ if (this.closed)
60
+ return;
61
+ this.closed = true;
62
+ for (const { client } of this.entries.values())
63
+ client.disconnect();
64
+ this.entries.clear();
65
+ }
66
+ /** Current number of cached clients — pool introspection helper. */
67
+ get size() {
68
+ return this.entries.size;
69
+ }
70
+ /** Whether `disconnect()` has been called. */
71
+ get isClosed() {
72
+ return this.closed;
73
+ }
74
+ evictLeastRecentlyUsed() {
75
+ let oldestUrl;
76
+ let oldestTs = Number.POSITIVE_INFINITY;
77
+ for (const [url, entry] of this.entries) {
78
+ if (entry.lastUsed < oldestTs) {
79
+ oldestTs = entry.lastUsed;
80
+ oldestUrl = url;
81
+ }
82
+ }
83
+ if (oldestUrl !== undefined)
84
+ this.evict(oldestUrl);
85
+ }
86
+ }
87
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/pool/pool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAgC1C;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACJ,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAA;IACzC,OAAO,CAAkB;IACzB,OAAO,CAAQ;IACxB,MAAM,GAAG,KAAK,CAAA;IACd,KAAK,GAAG,CAAC,CAAA;IAEjB,YAAY,MAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,aAAa,CAAA;QACnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAA;QACnC,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;QAC1E,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,GAAW;QACnB,IAAI,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,eAAe,EAAE,CAAA;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACtC,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,QAAQ,GAAG,EAAE,IAA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AAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACxC,IAAI,KAAK,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC;gBAC9B,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;gBACzB,SAAS,GAAG,GAAG,CAAA;YACjB,CAAC;QACH,CAAC;QACD,IAAI,SAAS,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACpD,CAAC;CACF"}
@@ -0,0 +1,45 @@
1
+ import type { CallRedirection } from '@astrale-os/kernel-api';
2
+ import { ClientSessionError } from '../errors/session-error';
3
+ /**
4
+ * Redirect policy refused to follow a redirection.
5
+ *
6
+ * Thrown by ClientSession's dispatch loop after `RedirectPolicy.decide` returns
7
+ * `{ follow: false, reason }`. The refused `redirection` is preserved so
8
+ * consumers can surface the URL to the user or retry explicitly via
9
+ * `session.call(..., { url: e.redirection.url })`. Spec §10.3.
10
+ */
11
+ export declare class RedirectRefusedError extends ClientSessionError {
12
+ readonly redirection: CallRedirection;
13
+ readonly reason: string;
14
+ constructor(redirection: CallRedirection, reason: string, options?: ErrorOptions);
15
+ }
16
+ /**
17
+ * Redirect chain exceeded the configured `maxHops`.
18
+ *
19
+ * Thrown by ClientSession's dispatch loop before calling `RedirectPolicy.decide`
20
+ * on the would-be (N+1)-th hop. `hops` carries the full chain to that
21
+ * point — first element is the initial target, last is the hop that
22
+ * returned the cap-triggering redirect. Spec §10.3.
23
+ */
24
+ export declare class HopLimitExceededError extends ClientSessionError {
25
+ readonly method: string;
26
+ readonly hops: ReadonlyArray<{
27
+ url: string;
28
+ at: number;
29
+ }>;
30
+ constructor(method: string, hops: ReadonlyArray<{
31
+ url: string;
32
+ at: number;
33
+ }>);
34
+ }
35
+ /**
36
+ * A `RedirectPolicy.decide` implementation itself threw.
37
+ *
38
+ * Programmer error at the policy layer. The thrown error wraps as
39
+ * `cause`. Consumers treating this as "refused" is safe. Spec §10.3.
40
+ */
41
+ export declare class RedirectPolicyError extends ClientSessionError {
42
+ readonly redirection: CallRedirection;
43
+ constructor(redirection: CallRedirection, options?: ErrorOptions);
44
+ }
45
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/redirect/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;aAExC,WAAW,EAAE,eAAe;aAC5B,MAAM,EAAE,MAAM;IAFhC,YACkB,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,MAAM,EAC9B,OAAO,CAAC,EAAE,YAAY,EAIvB;CACF;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,kBAAkB;aAEzC,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,aAAa,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAFlE,YACkB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,aAAa,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,EAIjE;CACF;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,kBAAkB;aAEvC,WAAW,EAAE,eAAe;IAD9C,YACkB,WAAW,EAAE,eAAe,EAC5C,OAAO,CAAC,EAAE,YAAY,EAQvB;CACF"}
@@ -0,0 +1,52 @@
1
+ import { ClientSessionError } from '../errors/session-error';
2
+ /**
3
+ * Redirect policy refused to follow a redirection.
4
+ *
5
+ * Thrown by ClientSession's dispatch loop after `RedirectPolicy.decide` returns
6
+ * `{ follow: false, reason }`. The refused `redirection` is preserved so
7
+ * consumers can surface the URL to the user or retry explicitly via
8
+ * `session.call(..., { url: e.redirection.url })`. Spec §10.3.
9
+ */
10
+ export class RedirectRefusedError extends ClientSessionError {
11
+ redirection;
12
+ reason;
13
+ constructor(redirection, reason, options) {
14
+ super(`Redirect to ${redirection.url} refused: ${reason}`, 'REDIRECT_REFUSED', options);
15
+ this.redirection = redirection;
16
+ this.reason = reason;
17
+ this.name = 'RedirectRefusedError';
18
+ }
19
+ }
20
+ /**
21
+ * Redirect chain exceeded the configured `maxHops`.
22
+ *
23
+ * Thrown by ClientSession's dispatch loop before calling `RedirectPolicy.decide`
24
+ * on the would-be (N+1)-th hop. `hops` carries the full chain to that
25
+ * point — first element is the initial target, last is the hop that
26
+ * returned the cap-triggering redirect. Spec §10.3.
27
+ */
28
+ export class HopLimitExceededError extends ClientSessionError {
29
+ method;
30
+ hops;
31
+ constructor(method, hops) {
32
+ super(`Hop limit exceeded for "${method}": ${hops.length} hops`, 'HOP_LIMIT_EXCEEDED');
33
+ this.method = method;
34
+ this.hops = hops;
35
+ this.name = 'HopLimitExceededError';
36
+ }
37
+ }
38
+ /**
39
+ * A `RedirectPolicy.decide` implementation itself threw.
40
+ *
41
+ * Programmer error at the policy layer. The thrown error wraps as
42
+ * `cause`. Consumers treating this as "refused" is safe. Spec §10.3.
43
+ */
44
+ export class RedirectPolicyError extends ClientSessionError {
45
+ redirection;
46
+ constructor(redirection, options) {
47
+ super(`Redirect policy threw while deciding → ${redirection.url}`, 'REDIRECT_POLICY_THREW', options);
48
+ this.redirection = redirection;
49
+ this.name = 'RedirectPolicyError';
50
+ }
51
+ }
52
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/redirect/errors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAExC,WAAW;IACX,MAAM;IAFxB,YACkB,WAA4B,EAC5B,MAAc,EAC9B,OAAsB;QAEtB,KAAK,CAAC,eAAe,WAAW,CAAC,GAAG,aAAa,MAAM,EAAE,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAA;2BAJvE,WAAW;sBACX,MAAM;QAItB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,SAAQ,kBAAkB;IAEzC,MAAM;IACN,IAAI;IAFtB,YACkB,MAAc,EACd,IAAgD;QAEhE,KAAK,CAAC,2BAA2B,MAAM,MAAM,IAAI,CAAC,MAAM,OAAO,EAAE,oBAAoB,CAAC,CAAA;sBAHtE,MAAM;oBACN,IAAI;QAGpB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;IACrC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IAEvC,WAAW;IAD7B,YACkB,WAA4B,EAC5C,OAAsB;QAEtB,KAAK,CACH,0CAA0C,WAAW,CAAC,GAAG,EAAE,EAC3D,uBAAuB,EACvB,OAAO,CACR,CAAA;2BAPe,WAAW;QAQ3B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export type { RedirectDecision, RedirectHop, RedirectPolicy } from './policy';
2
+ export { allowAllPolicy, allowlistPolicy, promptPolicy, strictPolicy } from './policy';
3
+ export { HopLimitExceededError, RedirectPolicyError, RedirectRefusedError } from './errors';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redirect/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC7E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACtF,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { allowAllPolicy, allowlistPolicy, promptPolicy, strictPolicy } from './policy';
2
+ export { HopLimitExceededError, RedirectPolicyError, RedirectRefusedError } from './errors';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/redirect/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACtF,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA"}