@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,112 @@
1
+ /**
2
+ * Client configuration and per-call options.
3
+ *
4
+ * Two orthogonal axes: `transport` (the pipe — http/ws/auto) × `protocol`
5
+ * (the message shape — envelope/auto). `route` is HTTP-only, so
6
+ * `protocol: 'auto'` degrades to envelope on WS. `binary` and `batch` are
7
+ * HTTP-only regardless of `transport`. Defaults: `'http'` + `'envelope'`.
8
+ */
9
+ import type { KernelRetryOptions } from '../pacer/retry';
10
+ import type { SchemaRegistry } from '../schema/registry';
11
+ import type { FunctionSchema } from '../schema/types';
12
+ import type { ClientHooks } from './hooks';
13
+ /** Minimal logger shape — a subset of `Console`. Defaults to `console`. */
14
+ export type ClientLogger = Pick<Console, 'error' | 'warn'>;
15
+ export type ClientConfig = {
16
+ /** Kernel URL. One client = one kernel — no pool. */
17
+ url: string;
18
+ /** Wire codec preference. Default `'json'`. */
19
+ codec?: 'json' | 'msgpack';
20
+ /**
21
+ * Default request timeout in ms. `0` or omitted = **no timeout** — the
22
+ * client never imposes one by default, so a CLI command against a
23
+ * dead server doesn't sit spinning for seconds the caller didn't ask
24
+ * for. Opt in explicitly per-client or per-call (`CallOptions.timeout`).
25
+ */
26
+ requestTimeout?: number;
27
+ /**
28
+ * Retry policy for transient wire failures (5xx, 429). **Default: no
29
+ * retry** — a failed call returns the failure immediately. Callers
30
+ * that want retries configure `kernelRetry` themselves or pass a
31
+ * policy here.
32
+ */
33
+ retry?: KernelRetryOptions;
34
+ /**
35
+ * Preloaded schemas or an external `SchemaRegistry`. Passing a registry
36
+ * lets multiple clients share one (saves / loads are visible across all).
37
+ * Passing an array loads an internal registry at construction.
38
+ */
39
+ schema?: FunctionSchema[] | SchemaRegistry;
40
+ /** Custom `fetch` (testing, environment shims). Default: global fetch. */
41
+ fetch?: typeof fetch;
42
+ /** Lifecycle hooks — pure observation (see `client/hooks.ts`). */
43
+ hooks?: ClientHooks;
44
+ /** Default transport (see `CallTransport`). Default `'http'`. */
45
+ defaultTransport?: CallTransport;
46
+ /**
47
+ * Default protocol. `'envelope'` always speaks the kernel envelope;
48
+ * `'auto'` prefers route if the schema has a `RouteBinding` and the
49
+ * transport is HTTP, else falls through to envelope. Default `'envelope'`.
50
+ */
51
+ defaultProtocol?: Protocol;
52
+ /**
53
+ * Logger used for hook-failure diagnostics. Only the error's name +
54
+ * message are surfaced — see `KernelClient.logHookError`. Default: `console`.
55
+ */
56
+ logger?: ClientLogger;
57
+ };
58
+ /**
59
+ * Transport the call rides over.
60
+ *
61
+ * - `'http'` — always HTTP.
62
+ * - `'ws'` — always WebSocket; connect failure throws `ConnectionError`.
63
+ * - `'auto'` — WS-first with HTTP fallback on initial connect failure.
64
+ * Once a frame round-trips, commits to WS (mid-session closures throw —
65
+ * no silent downgrade for long-running consumers). Signal stays on HTTP
66
+ * until WS is proven: fire-and-forget can't communicate fallback.
67
+ *
68
+ * **Caveat:** the browser `WebSocket` API reports all handshake failures
69
+ * (server doesn't speak WS, auth reject, WAF, origin mismatch) as the same
70
+ * error. `'auto'` treats every connect failure as WS-unsupported and sticks
71
+ * on HTTP for the client's lifetime — an auth-related failure gets masked.
72
+ * Consumers needing WS-specific errors should use `transport: 'ws'`.
73
+ */
74
+ export type CallTransport = 'http' | 'ws' | 'auto';
75
+ /**
76
+ * Message-shape preference. `envelope` forces the kernel envelope;
77
+ * `auto` uses the schema's `RouteBinding` when present and the
78
+ * transport is HTTP, else envelope.
79
+ */
80
+ export type Protocol = 'envelope' | 'auto';
81
+ export type CallOptions = {
82
+ /** Per-call timeout override (ms). */
83
+ timeout?: number;
84
+ /** Abort signal — propagates through the controller to the transport. */
85
+ signal?: AbortSignal;
86
+ /** Class context for instance-method schema resolution (e.g. `'Document'`). */
87
+ class?: string;
88
+ /**
89
+ * Override target URL. Used by an orchestrator (layer D) to retarget
90
+ * a call after a redirect. Supports `{placeholder}` substitution from
91
+ * params, same as `remoteUrl`.
92
+ */
93
+ url?: string;
94
+ /**
95
+ * Per-call transport override. Applies to hop-1 only — redirect follow-ups
96
+ * pick their transport from the schema of the new target.
97
+ */
98
+ transport?: CallTransport;
99
+ /**
100
+ * Per-call protocol override. `'auto'` resolves to route when the
101
+ * schema has a binding AND `transport === 'http'`; else envelope.
102
+ */
103
+ protocol?: Protocol;
104
+ /**
105
+ * Caller-provided correlation id — threaded into every `ClientHooks`
106
+ * context and onto any thrown error's `.details.correlationId`.
107
+ */
108
+ correlationId?: string;
109
+ /** Target-of-call for instance methods. Forwarded as `KernelRequest.self`. */
110
+ self?: string;
111
+ };
112
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/client/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAA;IAEX,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAE1B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAA;IAE1B;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,EAAE,GAAG,cAAc,CAAA;IAE1C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IAEpB,kEAAkE;IAClE,KAAK,CAAC,EAAE,WAAW,CAAA;IAEnB,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,aAAa,CAAA;IAEhC;;;;OAIG;IACH,eAAe,CAAC,EAAE,QAAQ,CAAA;IAE1B;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAA;AAElD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAA;AAE1C,MAAM,MAAM,WAAW,GAAG;IACxB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,yEAAyE;IACzE,MAAM,CAAC,EAAE,WAAW,CAAA;IAEpB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IAEzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Client configuration and per-call options.
3
+ *
4
+ * Two orthogonal axes: `transport` (the pipe — http/ws/auto) × `protocol`
5
+ * (the message shape — envelope/auto). `route` is HTTP-only, so
6
+ * `protocol: 'auto'` degrades to envelope on WS. `binary` and `batch` are
7
+ * HTTP-only regardless of `transport`. Defaults: `'http'` + `'envelope'`.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/client/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,61 @@
1
+ import type { CallRedirection } from '@astrale-os/kernel-api';
2
+ import type { BinaryResponse } from '../transport/binary';
3
+ import type { WireMeta } from '../wire/meta';
4
+ /**
5
+ * A single function entry in the type map. `TKind` is required — codegen
6
+ * always writes it; defaulting here would only obscure intent.
7
+ */
8
+ export type FnEntry<TParams, TResult, TKind extends 'call' | 'stream' | 'signal' | 'binary'> = {
9
+ params: TParams;
10
+ result: TResult;
11
+ kind: TKind;
12
+ };
13
+ /** Function map: method ref → FnEntry. Type parameter for `KernelClient<M>`. */
14
+ export type FnMap = Record<string, FnEntry<unknown, unknown, 'call' | 'stream' | 'signal' | 'binary'>>;
15
+ type FnsOfKind<M extends FnMap, K extends 'call' | 'stream' | 'signal' | 'binary'> = {
16
+ [Path in keyof M]: M[Path]['kind'] extends K ? Path : never;
17
+ }[keyof M] & string;
18
+ /**
19
+ * Wildcard-map detector. When `M` is the bare `FnMap` (no literal keys),
20
+ * `keyof M` is `string`, so `string extends keyof M` is `true` and the
21
+ * `*Fns<M>` aliases collapse to `string` — letting untyped consumers pass
22
+ * any method ref. For typed maps with literal keys, the conditional is
23
+ * `false` and the kind discrimination kicks in as before.
24
+ */
25
+ type IsWildcardMap<M extends FnMap> = string extends keyof M ? true : false;
26
+ export type CallFns<M extends FnMap> = IsWildcardMap<M> extends true ? string : FnsOfKind<M, 'call'>;
27
+ export type StreamFns<M extends FnMap> = IsWildcardMap<M> extends true ? string : FnsOfKind<M, 'stream'>;
28
+ export type SignalFns<M extends FnMap> = IsWildcardMap<M> extends true ? string : FnsOfKind<M, 'signal'>;
29
+ export type BinaryFns<M extends FnMap> = IsWildcardMap<M> extends true ? string : FnsOfKind<M, 'binary'>;
30
+ /** `client.send(...)` return — value or redirect. */
31
+ export type SendResult<T> = {
32
+ kind: 'value';
33
+ value: T;
34
+ meta: WireMeta;
35
+ } | {
36
+ kind: 'redirect';
37
+ redirection: CallRedirection;
38
+ meta: WireMeta;
39
+ };
40
+ /** `client.sendStream(...)` return — stream of chunks or on-open redirect. */
41
+ export type SendStreamResult<T> = {
42
+ kind: 'stream';
43
+ chunks: AsyncIterable<T>;
44
+ meta: WireMeta;
45
+ } | {
46
+ kind: 'redirect';
47
+ redirection: CallRedirection;
48
+ meta: WireMeta;
49
+ };
50
+ /** `client.sendBinary(...)` return — binary response or redirect. */
51
+ export type SendBinaryResult = {
52
+ kind: 'binary';
53
+ response: BinaryResponse;
54
+ meta: WireMeta;
55
+ } | {
56
+ kind: 'redirect';
57
+ redirection: CallRedirection;
58
+ meta: WireMeta;
59
+ };
60
+ export {};
61
+ //# sourceMappingURL=fn-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fn-map.d.ts","sourceRoot":"","sources":["../../src/client/fn-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI5C;;;GAGG;AACH,MAAM,MAAM,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,IAAI;IAC7F,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,KAAK,CAAA;CACZ,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,KAAK,GAAG,MAAM,CACxB,MAAM,EACN,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC,CACnE,CAAA;AAID,KAAK,SAAS,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,SAAS,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,IAAI;KAClF,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,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C;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAA;AAEtE,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fn-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fn-map.js","sourceRoot":"","sources":["../../src/client/fn-map.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import type { SendBinaryResult, SendResult, SendStreamResult } from './fn-map';
2
+ /**
3
+ * Freeze the envelope of a `Send*Result` so observers can't
4
+ * structurally rewrite it. Frozen:
5
+ *
6
+ * - the outer result (so `result.kind = 'redirect'` throws)
7
+ * - `result.meta` (so `meta.durationMs = 0` throws)
8
+ * - `result.meta.wire` and its `wire.headers` Record (HTTP variant)
9
+ *
10
+ * NOT frozen (by design — these are consumable / caller-owned):
11
+ *
12
+ * - `result.value` for `kind: 'value'` — payload data; caller may
13
+ * mutate it without affecting the client. Hooks that mutate this
14
+ * still see their changes in their own scope but do not retarget
15
+ * the client.
16
+ * - `result.redirection` for `kind: 'redirect'` — kept mutable for
17
+ * the same reason; an orchestrator may normalise the URL before
18
+ * retrying.
19
+ * - `result.chunks` for `kind: 'stream'` — the async iterable must
20
+ * stay live so the caller can consume it.
21
+ * - `result.response` for `kind: 'binary'` — body is a
22
+ * `ReadableStream` or `Uint8Array`; freezing the wrapper would not
23
+ * add safety and could surprise bindings that attach properties.
24
+ *
25
+ * The structural freeze closes spec §10's "observation, not
26
+ * transformation" guarantee: a hook that tries
27
+ * `ctx.result.kind = 'x'` or `ctx.result.meta.transport = 'y'` throws
28
+ * `TypeError` in strict mode instead of silently mutating the shape a
29
+ * subsequent hook or the caller depends on.
30
+ */
31
+ export declare function freezeResult<R extends SendResult<unknown> | SendStreamResult<unknown> | SendBinaryResult>(result: R): R;
32
+ //# sourceMappingURL=freeze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/client/freeze.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAC1B,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,gBAAgB,EAC5E,MAAM,EAAE,CAAC,GAAG,CAAC,CASd"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Freeze the envelope of a `Send*Result` so observers can't
3
+ * structurally rewrite it. Frozen:
4
+ *
5
+ * - the outer result (so `result.kind = 'redirect'` throws)
6
+ * - `result.meta` (so `meta.durationMs = 0` throws)
7
+ * - `result.meta.wire` and its `wire.headers` Record (HTTP variant)
8
+ *
9
+ * NOT frozen (by design — these are consumable / caller-owned):
10
+ *
11
+ * - `result.value` for `kind: 'value'` — payload data; caller may
12
+ * mutate it without affecting the client. Hooks that mutate this
13
+ * still see their changes in their own scope but do not retarget
14
+ * the client.
15
+ * - `result.redirection` for `kind: 'redirect'` — kept mutable for
16
+ * the same reason; an orchestrator may normalise the URL before
17
+ * retrying.
18
+ * - `result.chunks` for `kind: 'stream'` — the async iterable must
19
+ * stay live so the caller can consume it.
20
+ * - `result.response` for `kind: 'binary'` — body is a
21
+ * `ReadableStream` or `Uint8Array`; freezing the wrapper would not
22
+ * add safety and could surprise bindings that attach properties.
23
+ *
24
+ * The structural freeze closes spec §10's "observation, not
25
+ * transformation" guarantee: a hook that tries
26
+ * `ctx.result.kind = 'x'` or `ctx.result.meta.transport = 'y'` throws
27
+ * `TypeError` in strict mode instead of silently mutating the shape a
28
+ * subsequent hook or the caller depends on.
29
+ */
30
+ export function freezeResult(result) {
31
+ // Freeze the meta first so nested wire field is also frozen.
32
+ Object.freeze(result.meta);
33
+ if (result.meta.wire)
34
+ Object.freeze(result.meta.wire);
35
+ // Headers are already frozen by `headersToRecord`, but re-freezing a
36
+ // frozen object is a no-op and keeps the guarantee local.
37
+ const wire = result.meta.wire;
38
+ if (wire.kind === 'http')
39
+ Object.freeze(wire.headers);
40
+ return Object.freeze(result);
41
+ }
42
+ //# sourceMappingURL=freeze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freeze.js","sourceRoot":"","sources":["../../src/client/freeze.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,YAAY,CAE1B,MAAS;IACT,6DAA6D;IAC7D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI;QAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrD,qEAAqE;IACrE,0DAA0D;IAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAA;IAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { CredentialInput } from '@astrale-os/kernel-core';
2
+ import type { TransportName, WireMeta } from '../wire/meta';
3
+ import type { SendBinaryResult, SendResult, SendStreamResult } from './fn-map';
4
+ /**
5
+ * Lifecycle hooks — pure observation. Return values are ignored; throws
6
+ * are caught, logged, and the call proceeds unchanged. The result object
7
+ * handed to `onAfterReceive` is `Object.freeze`d, so hooks cannot mutate
8
+ * what the caller sees.
9
+ *
10
+ * Signals (fire-and-forget) flow through `onAfterSignal`, not
11
+ * `onAfterReceive` — signals have no response meta and a string-in-a-union
12
+ * would force every consumer to narrow away the non-object case.
13
+ */
14
+ export type ClientHooks = {
15
+ onBeforeSend?: (ctx: BeforeSendCtx) => void | Promise<void>;
16
+ onAfterReceive?: (ctx: AfterReceiveCtx) => void | Promise<void>;
17
+ onAfterSignal?: (ctx: AfterSignalCtx) => void | Promise<void>;
18
+ onError?: (ctx: ErrorCtx) => void | Promise<void>;
19
+ onStreamFrame?: (ctx: StreamFrameCtx) => void | Promise<void>;
20
+ };
21
+ export type BeforeSendCtx = {
22
+ method: string;
23
+ params: unknown;
24
+ credential: CredentialInput;
25
+ transport: TransportName;
26
+ url: string;
27
+ correlationId?: string;
28
+ };
29
+ export type AfterReceiveCtx = BeforeSendCtx & {
30
+ result: SendResult<unknown> | SendStreamResult<unknown> | SendBinaryResult;
31
+ meta: WireMeta;
32
+ };
33
+ export type AfterSignalCtx = BeforeSendCtx & {
34
+ /** Client-side timestamp when the signal was dispatched onto the wire. */
35
+ dispatchedAt: number;
36
+ };
37
+ export type ErrorCtx = BeforeSendCtx & {
38
+ error: Error;
39
+ /** Present when the error arose post-decode; absent on connect/timeout. */
40
+ meta?: WireMeta;
41
+ };
42
+ export type StreamFrameCtx = BeforeSendCtx & {
43
+ /** Zero-based index of the chunk in the stream. */
44
+ index: number;
45
+ data: unknown;
46
+ /** Stream-open meta — frozen from the opening `SendStreamResult.meta`. */
47
+ meta: WireMeta;
48
+ };
49
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/client/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAA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CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG;IACrC,KAAK,EAAE,KAAK,CAAA;IACZ,2EAA2E;IAC3E,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG;IAC3C,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,OAAO,CAAA;IACb,0EAA0E;IAC1E,IAAI,EAAE,QAAQ,CAAA;CACf,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/client/hooks.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export { KernelClient } from './client';
2
+ export type { BoundClientView } from './bound';
3
+ export type { CallOptions, ClientConfig, Protocol, CallTransport } from './config';
4
+ export type { AfterReceiveCtx, AfterSignalCtx, BeforeSendCtx, ClientHooks, ErrorCtx, StreamFrameCtx, } from './hooks';
5
+ export type { BinaryFns, CallFns, FnEntry, FnMap, SendBinaryResult, SendResult, SendStreamResult, SignalFns, StreamFns, } from './fn-map';
6
+ export type { BatchResults, TypedBatchRequest } from './batch';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClF,YAAY,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACb,WAAW,EACX,QAAQ,EACR,cAAc,GACf,MAAM,SAAS,CAAA;AAChB,YAAY,EACV,SAAS,EACT,OAAO,EACP,OAAO,EACP,KAAK,EACL,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,SAAS,GACV,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { KernelClient } from './client';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,133 @@
1
+ import type { CredentialInput } from '@astrale-os/kernel-core';
2
+ import type { SelfIdentityExpr, UnresolvedIdentityExpr } from '@astrale-os/kernel-core/expression';
3
+ /**
4
+ * Result a mint function returns. `credential` is what ClientSession hands to
5
+ * the wire; `ttl` (seconds) controls caching — omit to use
6
+ * `DelegationCacheConfig.ttl` (default 300), pass `0` to opt out of
7
+ * caching for this mint.
8
+ */
9
+ export type DelegationMintResult = {
10
+ credential: CredentialInput;
11
+ ttl?: number;
12
+ };
13
+ /**
14
+ * Mint function — resolves a delegated credential for
15
+ * `(audience, delegation, attestation)`. Matches the server-side
16
+ * `MintDelegationParams` triple in
17
+ * `kernel/ports/authentication/authentication.port.ts` — the cache
18
+ * forwards each field to the mint verbatim; no reduction, no flattening.
19
+ *
20
+ * ClientSession's default mint calls `identity.mintDelegation` through the
21
+ * default kernel; consumers can override (pre-shared tokens, HSM,
22
+ * offline signing). Must reject on failure — the cache treats rejection
23
+ * as "don't cache" and every waiter sees the error.
24
+ */
25
+ export type DelegationMintFn = (audience: string, delegation: UnresolvedIdentityExpr, attestation: SelfIdentityExpr | undefined) => Promise<DelegationMintResult>;
26
+ /**
27
+ * Config for `DelegationCache`. `mint` is required — without it, the
28
+ * cache cannot resolve misses.
29
+ */
30
+ export type DelegationCacheConfig = {
31
+ mint: DelegationMintFn;
32
+ /**
33
+ * Default TTL (seconds) applied when `mint` returns no explicit TTL.
34
+ * Default: `300`.
35
+ */
36
+ ttl?: number;
37
+ /**
38
+ * Maximum cached entries. LRU eviction when exceeded. Default: `64`.
39
+ */
40
+ maxSize?: number;
41
+ /**
42
+ * Clock source. Override for deterministic tests. Defaults to
43
+ * `() => Date.now() / 1000` — epoch seconds.
44
+ */
45
+ now?: () => number;
46
+ };
47
+ /**
48
+ * TTL-keyed credential cache with concurrent-mint deduplication. Spec §9.2.
49
+ *
50
+ * **Concurrent-mint invariant:** two concurrent `get(audience, delegation,
51
+ * attestation)` calls for the same structural triple share a single mint
52
+ * dispatch. On success, every waiter receives the same credential and the
53
+ * result is cached. On rejection, every waiter sees the rejection and the
54
+ * cache is NOT populated — subsequent calls re-attempt minting.
55
+ *
56
+ * **Structural key:** `delegation` and `attestation` are canonicalized
57
+ * by a deterministic JSON encoding (sorted keys; array order preserved —
58
+ * see `canonicalEncode` docstring). Policies returning fresh-but-equal
59
+ * objects on every call hit the same cache entry.
60
+ *
61
+ * **Attestation distinct from undefined:** `undefined` attestation and
62
+ * `{ kind: 'identity', self: true }` attestation are distinct keys (§9.2.1)
63
+ * even though the kernel adapter defaults the former to the latter at
64
+ * the wire — they produce distinguishable outer-envelope claims.
65
+ */
66
+ export declare class DelegationCache {
67
+ private readonly entries;
68
+ private readonly inFlight;
69
+ private readonly byAudience;
70
+ private readonly mint;
71
+ private readonly defaultTtl;
72
+ private readonly maxSize;
73
+ private readonly now;
74
+ private clock;
75
+ private clearEpoch;
76
+ constructor(config: DelegationCacheConfig);
77
+ /**
78
+ * Returns a delegated credential for `(audience, delegation, attestation)`.
79
+ * Cache hit returns synchronously-resolved; miss coalesces a single mint
80
+ * across concurrent callers on the same structural key.
81
+ *
82
+ * Throws `DelegationMintError` (wrapping the mint's cause) on mint
83
+ * failure. The failure is NOT cached.
84
+ */
85
+ get(audience: string, delegation: UnresolvedIdentityExpr, attestation?: SelfIdentityExpr): Promise<CredentialInput>;
86
+ /**
87
+ * Manually insert an entry. Used by consumers minting through a
88
+ * custom path outside `get`'s default mint flow.
89
+ */
90
+ set(audience: string, credential: CredentialInput, ttl: number, delegation: UnresolvedIdentityExpr, attestation?: SelfIdentityExpr): void;
91
+ /** Remove one entry. Idempotent — no-op for absent keys. */
92
+ evict(audience: string, delegation: UnresolvedIdentityExpr, attestation?: SelfIdentityExpr): void;
93
+ /**
94
+ * Remove every entry for `audience`, regardless of delegation /
95
+ * attestation shape. Returns the number of entries removed.
96
+ * Idempotent — returns `0` for unknown audiences.
97
+ *
98
+ * Bulk invalidation primitive: a host whose user revokes consent for
99
+ * an audience calls this without enumerating every
100
+ * `(delegation, attestation)` combination it minted.
101
+ */
102
+ evictAudience(audience: string): number;
103
+ /**
104
+ * Drop every cached entry. Does NOT abort in-flight mints — they
105
+ * resolve as usual but their results bypass the now-cleared cache.
106
+ */
107
+ clear(): void;
108
+ /** Entry count. Useful for tests; not a contract for production flow. */
109
+ get size(): number;
110
+ private insert;
111
+ private indexKey;
112
+ private deleteEntry;
113
+ private evictLeastRecentlyUsed;
114
+ }
115
+ /**
116
+ * Build a deterministic cache key from `(audience, delegation, attestation)`.
117
+ *
118
+ * The `delegation` and `attestation` trees are serialised through
119
+ * `canonicalEncode`, which:
120
+ * - Sorts object keys alphabetically at every node (so
121
+ * `{ kind, expr }` and `{ expr, kind }` collide).
122
+ * - Preserves array order (union/intersect/exclude operands are
123
+ * position-sensitive in the canonical form; `Scope[]` inside
124
+ * `{ kind: 'scope' }` is also position-preserving — scope sorting
125
+ * is the caller's choice, not the cache's, per spec §9.2.1).
126
+ * - Emits `#none` for absent attestation (distinct from any present
127
+ * `SelfIdentityExpr` including `{ kind: 'identity', self: true }`).
128
+ *
129
+ * Exported so ClientSession's `#pendingMints` table stays keyed identically
130
+ * without duplicating the key-shape logic.
131
+ */
132
+ export declare function delegationCacheKey(audience: string, delegation: UnresolvedIdentityExpr, attestation: SelfIdentityExpr | undefined): string;
133
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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