@distilled.cloud/core 1.0.0-rc.16 → 1.0.0-rc.18

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 (306) hide show
  1. package/lib/_bundle/aws.js +2 -0
  2. package/lib/_bundle/aws.js.map +1 -0
  3. package/lib/_bundle/base.js +5 -0
  4. package/lib/_bundle/base.js.map +1 -0
  5. package/lib/_bundle/graphql.js +3 -0
  6. package/lib/_bundle/graphql.js.map +1 -0
  7. package/lib/_bundle/rest.js +2 -0
  8. package/lib/_bundle/rest.js.map +1 -0
  9. package/lib/_bundle/xml.js +4 -0
  10. package/lib/_bundle/xml.js.map +1 -0
  11. package/lib/annotations.d.ts +15 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +15 -0
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -796
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/category.js +1 -278
  20. package/lib/chunks.js +1 -11
  21. package/lib/config.d.ts +54 -13
  22. package/lib/config.d.ts.map +1 -1
  23. package/lib/config.js +1 -161
  24. package/lib/crypto.js +1 -130
  25. package/lib/debug.d.ts.map +1 -1
  26. package/lib/debug.js +1 -8
  27. package/lib/error-category.d.ts.map +1 -1
  28. package/lib/error-category.js +1 -47
  29. package/lib/errors.d.ts +2 -13
  30. package/lib/errors.d.ts.map +1 -1
  31. package/lib/errors.js +1 -198
  32. package/lib/graphql.d.ts +14 -0
  33. package/lib/graphql.d.ts.map +1 -1
  34. package/lib/graphql.js +1 -1058
  35. package/lib/graphql.types.js +1 -6
  36. package/lib/index.d.ts +3 -2
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +1 -15
  39. package/lib/pagination.d.ts +34 -2
  40. package/lib/pagination.d.ts.map +1 -1
  41. package/lib/pagination.js +1 -271
  42. package/lib/plain-values.js +1 -39
  43. package/lib/plain-values.js.map +1 -1
  44. package/lib/protocol-http.d.ts +30 -6
  45. package/lib/protocol-http.d.ts.map +1 -1
  46. package/lib/protocol-http.js +1 -812
  47. package/lib/protocol-rest.d.ts +53 -39
  48. package/lib/protocol-rest.d.ts.map +1 -1
  49. package/lib/protocol-rest.js +1 -375
  50. package/lib/query.js +1 -27
  51. package/lib/response-validation-strict.js +1 -284
  52. package/lib/response-validation.d.ts +4 -3
  53. package/lib/response-validation.d.ts.map +1 -1
  54. package/lib/response-validation.js +1 -118
  55. package/lib/retry-after.js +1 -112
  56. package/lib/retry.js +1 -197
  57. package/lib/schema-lite-impl.js +1 -341
  58. package/lib/schema-lite-typed.js +1 -27
  59. package/lib/schema-lite.js +1 -31
  60. package/lib/schema.js +1 -220
  61. package/lib/telemetry-debug.d.ts +14 -0
  62. package/lib/telemetry-debug.d.ts.map +1 -0
  63. package/lib/telemetry-debug.js +2 -0
  64. package/lib/telemetry-debug.js.map +1 -0
  65. package/lib/telemetry-hooks.d.ts +32 -0
  66. package/lib/telemetry-hooks.d.ts.map +1 -0
  67. package/lib/telemetry-hooks.js +2 -0
  68. package/lib/telemetry-hooks.js.map +1 -0
  69. package/lib/telemetry-host-rules.d.ts +23 -0
  70. package/lib/telemetry-host-rules.d.ts.map +1 -0
  71. package/lib/telemetry-host-rules.js +2 -0
  72. package/lib/telemetry-host-rules.js.map +1 -0
  73. package/lib/telemetry-lambda-context.d.ts +17 -0
  74. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  75. package/lib/telemetry-lambda-context.js +2 -0
  76. package/lib/telemetry-lambda-context.js.map +1 -0
  77. package/lib/telemetry-message-context.d.ts +52 -0
  78. package/lib/telemetry-message-context.d.ts.map +1 -0
  79. package/lib/telemetry-message-context.js +2 -0
  80. package/lib/telemetry-message-context.js.map +1 -0
  81. package/lib/telemetry-metrics.d.ts +6 -0
  82. package/lib/telemetry-metrics.d.ts.map +1 -0
  83. package/lib/telemetry-metrics.js +2 -0
  84. package/lib/telemetry-metrics.js.map +1 -0
  85. package/lib/telemetry-name-template.d.ts +13 -0
  86. package/lib/telemetry-name-template.d.ts.map +1 -0
  87. package/lib/telemetry-name-template.js +2 -0
  88. package/lib/telemetry-name-template.js.map +1 -0
  89. package/lib/telemetry-stream.d.ts +9 -0
  90. package/lib/telemetry-stream.d.ts.map +1 -0
  91. package/lib/telemetry-stream.js +2 -0
  92. package/lib/telemetry-stream.js.map +1 -0
  93. package/lib/telemetry-xray.d.ts +28 -0
  94. package/lib/telemetry-xray.d.ts.map +1 -0
  95. package/lib/telemetry-xray.js +2 -0
  96. package/lib/telemetry-xray.js.map +1 -0
  97. package/lib/telemetry.d.ts +269 -0
  98. package/lib/telemetry.d.ts.map +1 -0
  99. package/lib/telemetry.js +3 -0
  100. package/lib/telemetry.js.map +1 -0
  101. package/lib/trait.js +1 -131
  102. package/lib/xml.js +1 -323
  103. package/package.json +1 -3
  104. package/src/annotations.ts +37 -0
  105. package/src/api.ts +130 -30
  106. package/src/category.ts +21 -22
  107. package/src/config.ts +58 -29
  108. package/src/debug.ts +9 -6
  109. package/src/error-category.ts +12 -14
  110. package/src/errors.ts +7 -7
  111. package/src/graphql.ts +123 -18
  112. package/src/index.ts +3 -2
  113. package/src/pagination.ts +119 -6
  114. package/src/protocol-http.ts +63 -43
  115. package/src/protocol-rest.ts +201 -140
  116. package/src/response-validation.ts +4 -3
  117. package/src/telemetry-debug.ts +135 -0
  118. package/src/telemetry-hooks.ts +33 -0
  119. package/src/telemetry-host-rules.ts +39 -0
  120. package/src/telemetry-lambda-context.ts +46 -0
  121. package/src/telemetry-message-context.ts +170 -0
  122. package/src/telemetry-metrics.ts +69 -0
  123. package/src/telemetry-name-template.ts +26 -0
  124. package/src/telemetry-stream.ts +91 -0
  125. package/src/telemetry-xray.ts +66 -0
  126. package/src/telemetry.ts +768 -0
  127. package/lib/api.js.map +0 -1
  128. package/lib/category.js.map +0 -1
  129. package/lib/chunks.js.map +0 -1
  130. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  131. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  132. package/lib/codegen/boolean-string-enums.js +0 -147
  133. package/lib/codegen/boolean-string-enums.js.map +0 -1
  134. package/lib/codegen/chunk.d.ts +0 -7
  135. package/lib/codegen/chunk.d.ts.map +0 -1
  136. package/lib/codegen/chunk.js +0 -139
  137. package/lib/codegen/chunk.js.map +0 -1
  138. package/lib/codegen/cli.d.ts +0 -80
  139. package/lib/codegen/cli.d.ts.map +0 -1
  140. package/lib/codegen/cli.js +0 -166
  141. package/lib/codegen/cli.js.map +0 -1
  142. package/lib/codegen/datafy.d.ts +0 -14
  143. package/lib/codegen/datafy.d.ts.map +0 -1
  144. package/lib/codegen/datafy.js +0 -853
  145. package/lib/codegen/datafy.js.map +0 -1
  146. package/lib/codegen/dedupe.d.ts +0 -5
  147. package/lib/codegen/dedupe.d.ts.map +0 -1
  148. package/lib/codegen/dedupe.js +0 -153
  149. package/lib/codegen/dedupe.js.map +0 -1
  150. package/lib/codegen/emit.d.ts +0 -125
  151. package/lib/codegen/emit.d.ts.map +0 -1
  152. package/lib/codegen/emit.js +0 -99
  153. package/lib/codegen/emit.js.map +0 -1
  154. package/lib/codegen/format.d.ts +0 -11
  155. package/lib/codegen/format.d.ts.map +0 -1
  156. package/lib/codegen/format.js +0 -32
  157. package/lib/codegen/format.js.map +0 -1
  158. package/lib/codegen/generated-at.d.ts +0 -29
  159. package/lib/codegen/generated-at.d.ts.map +0 -1
  160. package/lib/codegen/generated-at.js +0 -78
  161. package/lib/codegen/generated-at.js.map +0 -1
  162. package/lib/codegen/generator.d.ts +0 -353
  163. package/lib/codegen/generator.d.ts.map +0 -1
  164. package/lib/codegen/generator.js +0 -810
  165. package/lib/codegen/generator.js.map +0 -1
  166. package/lib/codegen/graph.d.ts +0 -36
  167. package/lib/codegen/graph.d.ts.map +0 -1
  168. package/lib/codegen/graph.js +0 -136
  169. package/lib/codegen/graph.js.map +0 -1
  170. package/lib/codegen/graphql-client.d.ts +0 -70
  171. package/lib/codegen/graphql-client.d.ts.map +0 -1
  172. package/lib/codegen/graphql-client.js +0 -439
  173. package/lib/codegen/graphql-client.js.map +0 -1
  174. package/lib/codegen/graphql.d.ts +0 -207
  175. package/lib/codegen/graphql.d.ts.map +0 -1
  176. package/lib/codegen/graphql.js +0 -786
  177. package/lib/codegen/graphql.js.map +0 -1
  178. package/lib/codegen/latin1.d.ts +0 -3
  179. package/lib/codegen/latin1.d.ts.map +0 -1
  180. package/lib/codegen/latin1.js +0 -126
  181. package/lib/codegen/latin1.js.map +0 -1
  182. package/lib/codegen/members.d.ts +0 -32
  183. package/lib/codegen/members.d.ts.map +0 -1
  184. package/lib/codegen/members.js +0 -62
  185. package/lib/codegen/members.js.map +0 -1
  186. package/lib/codegen/model-diff.d.ts +0 -10
  187. package/lib/codegen/model-diff.d.ts.map +0 -1
  188. package/lib/codegen/model-diff.js +0 -67
  189. package/lib/codegen/model-diff.js.map +0 -1
  190. package/lib/codegen/naming.d.ts +0 -29
  191. package/lib/codegen/naming.d.ts.map +0 -1
  192. package/lib/codegen/naming.js +0 -74
  193. package/lib/codegen/naming.js.map +0 -1
  194. package/lib/codegen/openapi-cli.d.ts +0 -52
  195. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  196. package/lib/codegen/openapi-cli.js +0 -84
  197. package/lib/codegen/openapi-cli.js.map +0 -1
  198. package/lib/codegen/openapi.d.ts +0 -209
  199. package/lib/codegen/openapi.d.ts.map +0 -1
  200. package/lib/codegen/openapi.js +0 -1548
  201. package/lib/codegen/openapi.js.map +0 -1
  202. package/lib/codegen/operations.d.ts +0 -24
  203. package/lib/codegen/operations.d.ts.map +0 -1
  204. package/lib/codegen/operations.js +0 -56
  205. package/lib/codegen/operations.js.map +0 -1
  206. package/lib/codegen/pagination.d.ts +0 -39
  207. package/lib/codegen/pagination.d.ts.map +0 -1
  208. package/lib/codegen/pagination.js +0 -31
  209. package/lib/codegen/pagination.js.map +0 -1
  210. package/lib/codegen/patch-audit.d.ts +0 -84
  211. package/lib/codegen/patch-audit.d.ts.map +0 -1
  212. package/lib/codegen/patch-audit.js +0 -366
  213. package/lib/codegen/patch-audit.js.map +0 -1
  214. package/lib/codegen/patches.d.ts +0 -129
  215. package/lib/codegen/patches.d.ts.map +0 -1
  216. package/lib/codegen/patches.js +0 -472
  217. package/lib/codegen/patches.js.map +0 -1
  218. package/lib/codegen/prelude.d.ts +0 -15
  219. package/lib/codegen/prelude.d.ts.map +0 -1
  220. package/lib/codegen/prelude.js +0 -60
  221. package/lib/codegen/prelude.js.map +0 -1
  222. package/lib/codegen/privatize.d.ts +0 -21
  223. package/lib/codegen/privatize.d.ts.map +0 -1
  224. package/lib/codegen/privatize.js +0 -176
  225. package/lib/codegen/privatize.js.map +0 -1
  226. package/lib/codegen/proto.d.ts +0 -121
  227. package/lib/codegen/proto.d.ts.map +0 -1
  228. package/lib/codegen/proto.js +0 -960
  229. package/lib/codegen/proto.js.map +0 -1
  230. package/lib/codegen/pure.d.ts +0 -6
  231. package/lib/codegen/pure.d.ts.map +0 -1
  232. package/lib/codegen/pure.js +0 -91
  233. package/lib/codegen/pure.js.map +0 -1
  234. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  235. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  236. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  237. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  238. package/lib/codegen/spec-path.d.ts +0 -16
  239. package/lib/codegen/spec-path.d.ts.map +0 -1
  240. package/lib/codegen/spec-path.js +0 -101
  241. package/lib/codegen/spec-path.js.map +0 -1
  242. package/lib/codegen/table.d.ts +0 -5
  243. package/lib/codegen/table.d.ts.map +0 -1
  244. package/lib/codegen/table.js +0 -249
  245. package/lib/codegen/table.js.map +0 -1
  246. package/lib/config.js.map +0 -1
  247. package/lib/crypto.js.map +0 -1
  248. package/lib/debug.js.map +0 -1
  249. package/lib/error-category.js.map +0 -1
  250. package/lib/errors.js.map +0 -1
  251. package/lib/graphql.js.map +0 -1
  252. package/lib/graphql.types.js.map +0 -1
  253. package/lib/index.js.map +0 -1
  254. package/lib/json-patch.d.ts +0 -58
  255. package/lib/json-patch.d.ts.map +0 -1
  256. package/lib/json-patch.js +0 -227
  257. package/lib/json-patch.js.map +0 -1
  258. package/lib/pagination.js.map +0 -1
  259. package/lib/protocol-http.js.map +0 -1
  260. package/lib/protocol-rest.js.map +0 -1
  261. package/lib/query.js.map +0 -1
  262. package/lib/response-validation-strict.js.map +0 -1
  263. package/lib/response-validation.js.map +0 -1
  264. package/lib/retry-after.js.map +0 -1
  265. package/lib/retry.js.map +0 -1
  266. package/lib/schema-lite-impl.js.map +0 -1
  267. package/lib/schema-lite-typed.js.map +0 -1
  268. package/lib/schema-lite.js.map +0 -1
  269. package/lib/schema.js.map +0 -1
  270. package/lib/testing.d.ts +0 -40
  271. package/lib/testing.d.ts.map +0 -1
  272. package/lib/testing.js +0 -42
  273. package/lib/testing.js.map +0 -1
  274. package/lib/trait.js.map +0 -1
  275. package/lib/xml.js.map +0 -1
  276. package/src/codegen/boolean-string-enums.ts +0 -155
  277. package/src/codegen/chunk.ts +0 -147
  278. package/src/codegen/cli.ts +0 -293
  279. package/src/codegen/datafy.ts +0 -874
  280. package/src/codegen/dedupe.ts +0 -173
  281. package/src/codegen/emit.ts +0 -200
  282. package/src/codegen/format.ts +0 -49
  283. package/src/codegen/generated-at.ts +0 -88
  284. package/src/codegen/generator.ts +0 -1229
  285. package/src/codegen/graph.ts +0 -151
  286. package/src/codegen/graphql-client.ts +0 -545
  287. package/src/codegen/graphql.ts +0 -1145
  288. package/src/codegen/latin1.ts +0 -131
  289. package/src/codegen/members.ts +0 -79
  290. package/src/codegen/model-diff.ts +0 -67
  291. package/src/codegen/naming.ts +0 -85
  292. package/src/codegen/openapi-cli.ts +0 -141
  293. package/src/codegen/openapi.ts +0 -1845
  294. package/src/codegen/operations.ts +0 -73
  295. package/src/codegen/pagination.ts +0 -64
  296. package/src/codegen/patch-audit.ts +0 -480
  297. package/src/codegen/patches.ts +0 -581
  298. package/src/codegen/prelude.ts +0 -70
  299. package/src/codegen/privatize.ts +0 -200
  300. package/src/codegen/proto.ts +0 -1092
  301. package/src/codegen/pure.ts +0 -94
  302. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  303. package/src/codegen/spec-path.ts +0 -112
  304. package/src/codegen/table.ts +0 -254
  305. package/src/json-patch.ts +0 -273
  306. package/src/testing.ts +0 -74
@@ -0,0 +1,269 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import type * as Exit from "effect/Exit";
4
+ import * as Fiber from "effect/Fiber";
5
+ import * as HttpClient from "effect/http/HttpClient";
6
+ import type * as HttpClientError from "effect/http/HttpClientError";
7
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
8
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse";
9
+ import type * as AST from "effect/SchemaAST";
10
+ import type * as Stream from "effect/Stream";
11
+ import * as Tracer from "effect/Tracer";
12
+ /**
13
+ * Debug mode's implementation, provided by `TelemetryDebug.layer`
14
+ * (`./telemetry-debug.ts`); undefined, the default, is operation spans only.
15
+ * The per-call path only checks whether it is set.
16
+ */
17
+ export interface DebugHooks {
18
+ /** An INTERNAL span around one of distilled's steps. */
19
+ readonly phase: <A, E, R>(name: string, effect: Effect.Effect<A, E, R>, attributes?: Record<string, unknown>) => Effect.Effect<A, E, R>;
20
+ /** Try `n` (1-based) as its own `Attempt` span. */
21
+ readonly attempt: <A, E, R>(base: Effect.Effect<A, E, R>, n: number) => Effect.Effect<A, E, R>;
22
+ /** The caller's read of a streamed output member, as a span under `parent`. */
23
+ readonly readStream: <A, E, R>(stream: Stream.Stream<A, E, R>, parent: Tracer.Span, member: string) => Stream.Stream<A, E, R>;
24
+ /** Log each request and response line to stderr (`./debug.ts`). */
25
+ readonly logRequests: boolean;
26
+ /** OTel `code.*` attributes for the caller's line. */
27
+ readonly callSite: (callSite: (() => string | undefined) | undefined) => Record<string, unknown> | undefined;
28
+ }
29
+ export declare const Debug: Context.Reference<DebugHooks | undefined>;
30
+ /**
31
+ * The traced call running on this fiber: its operation span, the debug-mode
32
+ * attempt span of the current try, and the retry history so far. Protocols
33
+ * write through {@link annotate} synchronously, without an extra effect.
34
+ */
35
+ export interface Call {
36
+ readonly span: Tracer.Span;
37
+ readonly info: OperationInfo;
38
+ attempt: Tracer.Span | undefined;
39
+ readonly retryErrors: Array<string>;
40
+ retryDelayMs: number;
41
+ }
42
+ export declare const OperationSpan: Context.Reference<Call | undefined>;
43
+ /**
44
+ * How a value becomes an attribute value (`com.distilled.telemetry`
45
+ * transforms; see `packages/dev/src/codegen/telemetry-traits.md`).
46
+ */
47
+ export type Transform = "list" | "keys" | "count" | "lastPathSegment" | "arnResource" | "arn" | "jsonList" | "nonZero";
48
+ export interface AttributeRule {
49
+ readonly name: string;
50
+ /** Dotted path into the member's value, read before the transform. */
51
+ readonly field?: string;
52
+ readonly transform?: Transform;
53
+ }
54
+ /**
55
+ * Extra facts for a request, by host (`hostRules` in
56
+ * `./telemetry-host-rules.ts`): `set` records an attribute on the span.
57
+ */
58
+ export type RequestHook = (host: string, span: Tracer.Span, set: (key: string, value: unknown) => void) => void;
59
+ /** The `com.distilled.telemetry#service` trait, as generated code carries it. */
60
+ export interface ServiceTelemetry {
61
+ readonly system: string;
62
+ readonly attributes?: Readonly<Record<string, string | number | boolean>>;
63
+ readonly responseHeaders?: ReadonlyArray<AttributeRule & {
64
+ readonly header: string;
65
+ }>;
66
+ /** From the trait's `hosts`. */
67
+ readonly onRequest?: RequestHook;
68
+ /**
69
+ * The rules every operation of this module follows, so its generated
70
+ * `span` holds only what differs (see {@link operationInfo}): span name
71
+ * `<prefix>.<op>`, `rpc.method` `<service>/<op>`, and each path label
72
+ * recorded as `<labels>.<label in snake_case>`.
73
+ */
74
+ readonly prefix?: string;
75
+ readonly service?: string;
76
+ readonly labels?: string;
77
+ /** Path labels named another way than `<labels>.<snake_case>`, by property. */
78
+ readonly labelNames?: Readonly<Record<string, string>>;
79
+ /** `false`: operations do not derive `url.template` (RPC protocols). */
80
+ readonly templates?: false;
81
+ /**
82
+ * How requests carry the span's trace context, from the trait's
83
+ * `propagation`: `"w3c"`, a `traceparent` header; or a function returning
84
+ * the header to set (X-Ray, `./telemetry-xray.ts`).
85
+ */
86
+ readonly propagate?: "w3c" | ((span: Tracer.AnySpan) => readonly [header: string, value: string]);
87
+ }
88
+ /** A span name for one call from its input attributes; undefined keeps the trait's `name`. */
89
+ export type SpanRename = (attributes: Readonly<Record<string, unknown>>) => string | undefined;
90
+ /**
91
+ * Runs an operation call in its span and keeps the span open after the call
92
+ * returns, until the caller has read a streamed output member (the trait's
93
+ * `stream`; built by `./telemetry-stream.ts`). Every other operation uses
94
+ * `Effect.useSpan`, which ends the span on return.
95
+ */
96
+ export type SpanHold = <A, E, R>(fiber: Fiber.Fiber<unknown, unknown>, name: string, options: Tracer.SpanOptionsNoTrace, debug: DebugHooks | undefined, inSpan: (span: Tracer.Span) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
97
+ /** Read trace context back from an operation's messages (the trait's `extract`). */
98
+ export interface MessageExtract {
99
+ /** The input asking the service to return the trace context. */
100
+ readonly request: (input: unknown) => unknown;
101
+ /** Links to the spans the output's messages name. */
102
+ readonly links: (output: unknown) => ReadonlyArray<Tracer.SpanLink>;
103
+ }
104
+ /**
105
+ * The `com.distilled.telemetry#operation` trait plus its input members'
106
+ * rules. The trait's `nameTemplate`, `inject` and `extract` arrive as the
107
+ * functions `./telemetry-name-template.ts` and
108
+ * `./telemetry-message-context.ts` build from them.
109
+ */
110
+ export interface SpanConfig {
111
+ /**
112
+ * The operation's model name. With it, whatever this config leaves out
113
+ * follows the service's rules and the input schema's annotations.
114
+ */
115
+ readonly op?: string;
116
+ /** `false`: no `url.template`, whatever the service's rule. */
117
+ readonly template?: false;
118
+ readonly name?: string;
119
+ readonly method?: string;
120
+ readonly kind?: "client" | "producer" | "consumer";
121
+ /** Fixed attributes; `null` drops one the service sets. */
122
+ readonly attributes?: Readonly<Record<string, string | number | boolean | null>>;
123
+ /** `com.distilled.telemetry#attributes` of the input members, by property name. */
124
+ readonly input?: Readonly<Record<string, ReadonlyArray<AttributeRule>>>;
125
+ /**
126
+ * Attributes recorded under a second name once the request is built:
127
+ * `{ "cloud.region": "faas.invoked_region" }`.
128
+ */
129
+ readonly copy?: Readonly<Record<string, string>>;
130
+ /** The same, for output members: recorded when the call succeeds. */
131
+ readonly output?: Readonly<Record<string, ReadonlyArray<AttributeRule>>>;
132
+ readonly rename?: SpanRename;
133
+ /** Write the span's trace context into the request's messages. */
134
+ readonly inject?: (span: Tracer.Span, input: unknown) => unknown;
135
+ readonly extract?: MessageExtract;
136
+ /** Keep the span open until the caller has read a streamed output member. */
137
+ readonly hold?: SpanHold;
138
+ }
139
+ /** One operation's span facts, built once per operation. */
140
+ export interface OperationInfo {
141
+ /** Span name, e.g. `S3.GetObject`. */
142
+ readonly name: string;
143
+ readonly kind: "client" | "producer" | "consumer";
144
+ /** Fixed attributes: rpc.system.name, rpc.method, service and operation attributes. */
145
+ readonly attributes: Readonly<Record<string, unknown>>;
146
+ /** Input property and rule pairs, flattened. */
147
+ readonly input: ReadonlyArray<readonly [property: string, rule: AttributeRule]>;
148
+ readonly output: ReadonlyArray<readonly [property: string, rule: AttributeRule]>;
149
+ readonly responseHeaders: ReadonlyArray<AttributeRule & {
150
+ readonly header: string;
151
+ }>;
152
+ readonly onRequest: RequestHook | undefined;
153
+ readonly propagate: ServiceTelemetry["propagate"];
154
+ readonly copy: SpanConfig["copy"];
155
+ readonly rename: SpanRename | undefined;
156
+ readonly inject: SpanConfig["inject"];
157
+ readonly extract: MessageExtract | undefined;
158
+ readonly hold: SpanHold | undefined;
159
+ }
160
+ /**
161
+ * The span facts of an operation from its generated `telemetry` and `span`
162
+ * config. A `span` naming its `op` (a string is just the op) derives what it
163
+ * leaves out, from the service's rules and the input schema:
164
+ *
165
+ * name `<service.prefix>.<op>`
166
+ * rpc.method `<service.service>/<op>`
167
+ * url.template the path of the input's `T.Http` uri, unless the service
168
+ * or the span says `false`
169
+ * input each `T.Label` property as `<service.labels>.<snake_case>`;
170
+ * an explicit entry replaces it (`[]` records nothing)
171
+ *
172
+ * The generator emits only what differs from these rules, so the result is
173
+ * exactly the model's `com.distilled.telemetry` traits. An operation
174
+ * generated without traits gets its operation name, or
175
+ * `distilled.operation`.
176
+ */
177
+ export declare const operationInfo: (service: ServiceTelemetry | undefined, config: SpanConfig | string | undefined, operationName: string | undefined, inputAst?: AST.AST) => OperationInfo;
178
+ /**
179
+ * An opt-in observer of every operation call (`./telemetry-metrics.ts`):
180
+ * wraps the call, whether or not a span is recorded.
181
+ */
182
+ export type Measure = <A, E, R>(info: OperationInfo, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
183
+ export declare const Metrics: Context.Reference<Measure | undefined>;
184
+ /** App callbacks on each recorded operation span (`./telemetry-hooks.ts`). */
185
+ export interface SpanHooks {
186
+ readonly onStart?: (span: Tracer.Span, call: {
187
+ readonly name: string;
188
+ readonly method: unknown;
189
+ readonly input: unknown;
190
+ }) => void;
191
+ readonly onEnd?: (span: Tracer.Span, exit: Exit.Exit<unknown, unknown>) => void;
192
+ }
193
+ export declare const Hooks: Context.Reference<SpanHooks | undefined>;
194
+ export declare const isDebug: (context: Context.Context<any>) => boolean;
195
+ /**
196
+ * Record a fact about the current try (status, request id, host): on the
197
+ * operation span, where the last try wins, and on the debug attempt span.
198
+ */
199
+ export declare const annotate: (context: Context.Context<any>, key: string, value: unknown) => void;
200
+ /**
201
+ * The request facts, recorded when it is sent (so a call that never gets a
202
+ * response still has them): method, host and port. Host only: the full URL
203
+ * can carry a presigned signature.
204
+ */
205
+ export declare const annotateRequest: (context: Context.Context<any>, method: string, url: string) => void;
206
+ /**
207
+ * The response facts, for every protocol: status, and the response
208
+ * headers the service trait lists (request ids).
209
+ */
210
+ export declare const annotateResponse: (context: Context.Context<any>, status: number, headers: Readonly<Record<string, string | undefined>>) => void;
211
+ /**
212
+ * `client.execute(request)` for the traced call on this fiber: the
213
+ * request facts before it is sent, the response facts when it returns.
214
+ * Untraced calls pay one context read.
215
+ */
216
+ export declare const execute: (context: Context.Context<any>, client: HttpClient.HttpClient, request: HttpClientRequest.HttpClientRequest) => Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError>;
217
+ export declare const tagOf: (error: unknown) => string;
218
+ /**
219
+ * Try `n` failed with `error` and the call retries after `delayMs`. The
220
+ * operation span carries the history, so a slow call shows why:
221
+ *
222
+ * distilled.attempts 5 (tries so far, including the next one)
223
+ * distilled.retry.errors ["SlowDown", "SlowDown", "SlowDown", "SlowDown"]
224
+ * distilled.retry.delay_ms 4087 (total backoff)
225
+ *
226
+ * A call that succeeds first time has none of them.
227
+ */
228
+ export declare const retried: (context: Context.Context<any>, n: number, error: unknown, delayMs: number) => void;
229
+ /** Debug-only internal span around `effect`; `effect` itself otherwise. */
230
+ export declare const phase: <A, E, R>(context: Context.Context<any>, name: string, effect: Effect.Effect<A, E, R>, attributes?: Record<string, unknown>) => Effect.Effect<A, E, R>;
231
+ /**
232
+ * Capture the caller of an operation, cheaply: `Error.captureStackTrace`
233
+ * drops `entry` (the operation function the user called) and every frame
234
+ * above it, so 2 frames are enough. V8 records them now and formats them
235
+ * only if someone reads `.stack` (an error rendered with `Cause.pretty`, or
236
+ * a debug span exporting `code.*`). Skipped when `Error.stackTraceLimit`
237
+ * is 0, the rule Effect's own spans follow.
238
+ */
239
+ export declare const captureCallSite: (entry: Function) => (() => string | undefined) | undefined;
240
+ /**
241
+ * Build typed errors without a JS stack: their own
242
+ * frames all point into distilled's response decoder (noise), and the
243
+ * failure frame supplies the caller's line instead. Saves the frame capture
244
+ * on every error. Defects keep their stacks. Use inline:
245
+ *
246
+ * const saved = suppressStack();
247
+ * try { error = new Cls(...) } finally { restoreStack(saved) }
248
+ */
249
+ export declare const suppressStack: () => number | undefined;
250
+ export declare const restoreStack: (saved: number | undefined) => void;
251
+ /**
252
+ * One operation call (every attempt), with or without debug hooks.
253
+ *
254
+ * no exporter: no span. Effect's HTTP span is switched off too (nobody
255
+ * would see it); the failure frame still names the call.
256
+ * operation: one CLIENT span. Effect's HTTP span is switched off and
257
+ * protocols copy its facts (status, host, request id) onto
258
+ * this span, so one span per call.
259
+ * debug: the span is the parent of Effect's HTTP span (one per
260
+ * attempt) and of distilled's internal spans.
261
+ *
262
+ * Failures set `error.type` to the error's tag; Effect sets the status.
263
+ * An operation whose trait names a streamed output member (`stream`:
264
+ * Bedrock ConverseStream) keeps the span open until the caller has read
265
+ * that stream (`./telemetry-stream.ts`); every other span ends when the
266
+ * call returns, after the response headers.
267
+ */
268
+ export declare const operationSpan: <A, E, R>(fiber: Fiber.Fiber<unknown, unknown>, debug: DebugHooks | undefined, info: OperationInfo, callSite: (() => string | undefined) | undefined, input: unknown, run: (input: unknown) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
269
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,IAAI,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AAG1E,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe,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AAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,SAC7B,UAAU,GAAG,SAAS,QACvB,aAAa,YACT,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,SACzC,OAAO,OACT,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAIvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import{getAnn as e,getProps as t}from"./annotations.js";import*as n from"effect/Context";import*as r from"effect/Effect";import*as i from"effect/http/HttpClient";import*as a from"effect/Cause";import"effect/Fiber";import*as o from"effect/http/HttpClientRequest";import*as s from"effect/Redacted";import*as c from"effect/References";import*as l from"effect/Tracer";const u=/*@__PURE__*/ n.Reference(`@distilled.cloud/core/Telemetry/Debug`,{defaultValue:()=>void 0});const d=/*@__PURE__*/ n.Reference(`@distilled.cloud/core/Telemetry/OperationSpan`,{defaultValue:()=>void 0});const isScalar=e=>typeof e===`string`||typeof e===`number`||typeof e===`boolean`;const fieldOf=(e,t)=>{let n=e;for(const e of t.split(`.`)){if(n===null||typeof n!==`object`)return void 0;n=n[e]}return n};const transform=(e,t)=>{const n=e.field===void 0?t:fieldOf(t,e.field);if(n===void 0||n===null||s.isRedacted(n))return void 0;switch(e.transform){case void 0:return isScalar(n)||Array.isArray(n)&&n.length>0&&n.every(isScalar)?n:void 0;case`nonZero`:return typeof n===`number`&&n!==0?n:void 0;case`list`:return typeof n===`string`?[n]:void 0;case`keys`:return n!==null&&typeof n===`object`?Object.keys(n):void 0;case`count`:return Array.isArray(n)?n.length:void 0;case`lastPathSegment`:return typeof n===`string`?n.slice(n.lastIndexOf(`/`)+1):void 0;case`arnResource`:return typeof n===`string`?n.slice(n.lastIndexOf(`:`)+1):void 0;case`arn`:return typeof n===`string`&&n.startsWith(`arn:`)?n:void 0;case`jsonList`:return Array.isArray(n)?n.map(e=>JSON.stringify(e)):typeof n===`object`?[JSON.stringify(n)]:void 0}};const f=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http`);const p=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/label`);const snakeCase=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1_$2`).replace(/[^A-Za-z0-9]+/g,`_`).toLowerCase();const operationInfo=(n,r,i,a)=>{const o=typeof r===`string`?{op:r}:r;const s=o?.op;let c=o?.input;let l;if(s!==void 0&&a!==void 0){if(n?.templates!==false&&o?.template!==false)l=e(a,f)?.uri?.split(`?`)[0];if(n?.labels!==void 0){const r={};for(const i of t(a)){if(e(i.type,p)===void 0)continue;const t=String(i.name);r[t]=[{name:n.labelNames?.[t]??`${n.labels}.${snakeCase(t)}`}]}c={...r,...c}}}const u=flatten(c);const d={...n?{"rpc.system.name":n.system}:{},...n?.attributes,...l!==void 0?{"url.template":l}:{},...o?.attributes};for(const e in o?.attributes)if(d[e]===null)delete d[e];const m=o?.method??(s!==void 0&&n?.service!==void 0?`${n.service}/${s}`:void 0);return{name:o?.name??(s!==void 0&&n?.prefix!==void 0?`${n.prefix}.${s}`:void 0)??i??`distilled.operation`,kind:o?.kind??`client`,attributes:m===void 0?d:{"rpc.method":m,...d},input:u,output:flatten(o?.output),responseHeaders:n?.responseHeaders??[],onRequest:n?.onRequest,propagate:n?.propagate,copy:o?.copy,rename:o?.rename,inject:o?.inject,extract:o?.extract,hold:o?.hold}};const flatten=e=>{const t=[];for(const n in e)for(const r of e[n])t.push([n,r]);return t};const readRules=(e,t,n)=>{if(e.length===0||t===null||typeof t!==`object`)return;for(const[r,i]of e){const e=transform(i,t[r]);if(e!==void 0)n(i.name,e)}};const m=/*@__PURE__*/ n.Reference(`@distilled.cloud/core/Telemetry/Metrics`,{defaultValue:()=>void 0});const h=/*@__PURE__*/ n.Reference(`@distilled.cloud/core/Telemetry/Hooks`,{defaultValue:()=>void 0});const isDebug=e=>n.get(e,u)!==void 0;const annotate=(e,t,r)=>{const i=n.get(e,d);if(i===void 0)return;i.span.attribute(t,r);i.attempt?.attribute(t,r)};const annotateRequest=(e,t,r)=>{if(n.get(e,d)===void 0)return;const i=r.indexOf(`://`)+3;let a=i;while(a<r.length&&!`/?#`.includes(r[a]))a++;const o=r.slice(i,a);const s=o.lastIndexOf(`:`);const c=s!==-1&&!o.endsWith(`]`);const l=c?o.slice(0,s):o;annotate(e,`http.request.method`,t);annotate(e,`server.address`,l);annotate(e,`server.port`,c?Number(o.slice(s+1)):r.startsWith(`https`)?443:80);const u=n.get(e,d);u.info.onRequest?.(l,u.span,(t,n)=>annotate(e,t,n));for(const t in u.info.copy){const n=u.span.attributes.get(t);if(n!==void 0)annotate(e,u.info.copy[t],n)}};const annotateResponse=(e,t,r)=>{const i=n.get(e,d);if(i===void 0)return;annotate(e,`http.response.status_code`,t);for(const t of i.info.responseHeaders){const n=r[t.header];if(n!==void 0)annotate(e,t.name,transform(t,n))}};const execute=(e,t,i)=>{const a=n.get(e,d);if(a===void 0)return t.execute(i);annotateRequest(e,i.method,i.url);const s=a.info.propagate;if(s!==void 0){const e=a.attempt??a.span;i=s===`w3c`?o.setHeader(i,`traceparent`,`00-${e.traceId}-${e.spanId}-${e.sampled?`01`:`00`}`):o.setHeader(i,...s(e))}return r.map(t.execute(i),t=>{annotateResponse(e,t.status,t.headers);return t})};const tagOf=e=>e?._tag??`_OTHER`;const retried=(e,t,r,i)=>{const a=n.get(e,d);if(a===void 0)return;a.retryErrors.push(tagOf(r));a.retryDelayMs+=i;a.span.attribute(`distilled.attempts`,t+1);a.span.attribute(`distilled.retry.errors`,a.retryErrors.slice());a.span.attribute(`distilled.retry.delay_ms`,Math.round(a.retryDelayMs))};const phase=(e,t,r,i)=>{const a=n.get(e,u);return a===void 0?r:a.phase(t,r,i)};const g=/[\\/](?:packages[\\/][^\\/]+[\\/](?:src|lib)[\\/]|@distilled\.cloud[\\/])|node:internal/;const captureCallSite=e=>{const t=Error.stackTraceLimit;if(t===0)return void 0;const n={};Error.stackTraceLimit=2;if(typeof Error.captureStackTrace===`function`)Error.captureStackTrace(n,e);else n.stack=(/* @__PURE__ */ new Error()).stack;Error.stackTraceLimit=t;let r=null;return()=>{if(r!==null)return r;r=(n.stack?.split(`
2
+ `)??[]).slice(1).find(e=>!g.test(e))?.trim();return r}};const suppressStack=()=>{const e=Error.stackTraceLimit;if(e===0)return void 0;Error.stackTraceLimit=0;return e};const restoreStack=e=>{if(e!==void 0)Error.stackTraceLimit=e};const always=()=>true;const exporting=e=>{const t=e.cache.tracer;return t!==void 0&&t!==l.nativeTracer};const withFailureFrame=(e,t,i)=>i===void 0?e:r.catchCause(e,e=>r.withFiber(o=>r.failCause(a.annotate(e,n.make(a.StackTrace,{name:t,stack:i,parent:n.getOrUndefined(a.annotations(e),a.StackTrace)??o.getRef(c.CurrentStackFrame)}),{overwrite:true}))));const operationSpan=(e,t,n,r,i,a)=>{const o=e.getRef(m);const s=traceCall(e,t,n,r,i,a);return o===void 0?s:o(n,s)};const traceCall=(e,t,a,o,s,c)=>{if(!exporting(e)){const e=c(s);return withFailureFrame(t!==void 0?e:r.provideService(e,i.TracerDisabledWhen,always),a.name,o)}const u=t!==void 0?{...a.attributes,...t.callSite(o)}:{...a.attributes};readRules(a.input,s,(e,t)=>u[e]=t);const f=e.getRef(h);const inSpan=e=>{const o=a.extract;let u=a.inject===void 0?s:a.inject(e,s);if(o!==void 0)u=o.request(u);let p=r.tapError(c(u),t=>r.sync(()=>e.attribute(`error.type`,tagOf(t))));if(o!==void 0||a.output.length>0)p=r.tap(p,t=>r.sync(()=>{readRules(a.output,t,(t,n)=>e.attribute(t,n));if(o!==void 0){const n=o.links(t);if(n.length>0)e.addLinks(n)}}));if(f!==void 0){f.onStart?.(e,{name:a.name,method:a.attributes[`rpc.method`],input:s});const t=f.onEnd;if(t!==void 0)p=r.onExit(p,n=>r.sync(()=>t(e,n)))}const m={span:e,info:a,attempt:void 0,retryErrors:[],retryDelayMs:0};if(t!==void 0)return r.updateContext(p,t=>n.add(n.add(t,d,m),l.ParentSpan,e));return r.updateContext(p,e=>n.add(n.add(e,d,m),i.TracerDisabledWhen,always))};const p=a.rename?.(u)??a.name;const m={kind:a.kind,attributes:u};const g=a.hold===void 0?r.useSpan(p,m,inSpan):a.hold(e,p,m,t,inSpan);return withFailureFrame(g,a.name,o)};export{u as Debug,h as Hooks,m as Metrics,d as OperationSpan,annotate,annotateRequest,annotateResponse,captureCallSite,execute,isDebug,operationInfo,operationSpan,phase,restoreStack,retried,suppressStack,tagOf};
3
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.js","names":["Context","Effect","HttpClient","Cause","HttpClientRequest","Redacted","References","Tracer","Debug","OperationSpan","value","at","key","path","rule","raw","v","HTTP","LABEL","name","span","config","op","rules","template","inputAst","service","getAnn","derived","prop","getProps","property","input","attributes","method","operationName","out","read","set","Metrics","Hooks","context","call","hostStart","url","hostEnd","authority","colon","hasPort","host","from","status","headers","client","request","propagate","response","error","delayMs","n","debug","effect","CORE_FRAME","limit","holder","entry","cache","line","saved","tracer","fiber","callSite","body","cause","measure","traced","info","run","hooks","extract","sent","output","links","onEnd","exit","options"],"sources":["../src/telemetry.ts"],"mappings":"4WAuEA,MAAaQ,EAAsB,gBAAQ,UACzC,wCACA,CAAE,iBAAoB,IAAA,EAAU,CAClC,EAeA,MAAaC,EAA8B,gBAAQ,UACjD,gDACA,CAAE,iBAAoB,IAAA,EAAU,CAClC,EAgJA,MAAM,SAAY,GAChB,OAAOC,IAAU,UAAY,OAAOA,IAAU,UAAY,OAAOA,IAAU,UAE7E,MAAM,SAAW,EAAgB,IAA0B,CACzD,IAAIC,EAAKD,EACT,IAAK,MAAME,KAAOC,EAAK,MAAM,GAAG,EAAG,CACjC,GAAIF,IAAO,MAAQ,OAAOA,IAAO,SAAU,OAAO,IAAA,GAClD,EAAMA,EAA+BC,EACvC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/lib/trait.js CHANGED
@@ -1,131 +1 @@
1
- export const annotationMetaSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/annotation-meta");
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
- export function makeAnnotation(sym, value) {
10
- const fn = (schema) => schema.annotate({ [sym]: value });
11
- fn[annotationMetaSymbol] = [{ symbol: sym, value }];
12
- fn[sym] = value;
13
- return fn;
14
- }
15
-
16
-
17
-
18
-
19
-
20
- export function all(...annotations) {
21
- const entries = [];
22
- const raw = {};
23
- for (const a of annotations) {
24
- for (const entry of a[annotationMetaSymbol]) {
25
- entries.push(entry);
26
- raw[entry.symbol] = entry.value;
27
- }
28
- }
29
- const fn = (schema) => schema.annotate(raw);
30
- fn[annotationMetaSymbol] = entries;
31
- for (const { symbol: sym, value } of entries) {
32
- fn[sym] = value;
33
- }
34
- return fn;
35
- }
36
- export const httpSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http");
37
-
38
-
39
-
40
-
41
-
42
- export const Http = (trait) => makeAnnotation(httpSymbol, trait);
43
- export const labelSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/label");
44
-
45
- export const Label = (name) => makeAnnotation(labelSymbol, name ?? true);
46
- export const labelEncodingSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/label-encoding");
47
-
48
- export const LabelEncoding = (options) => {
49
- if (!/^[!$&'()*+,;=:@]*$/.test(options.preserve)) {
50
- throw new TypeError("LabelEncoding can preserve only URI path-segment delimiters");
51
- }
52
- return makeAnnotation(labelEncodingSymbol, options.preserve);
53
- };
54
- export const responseCodeSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/response-code");
55
- export const ResponseCode = () => makeAnnotation(responseCodeSymbol, true);
56
- export const headerSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/header");
57
- export const Header = (name) => makeAnnotation(headerSymbol, name ?? true);
58
- export const bodySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/body");
59
- export const Body = (name) => makeAnnotation(bodySymbol, name ?? true);
60
- export const querySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/query");
61
- export const Query = (name) => makeAnnotation(querySymbol, name ?? true);
62
- export const deepQuerySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/deep-query");
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
- export const DeepQuery = (name) => makeAnnotation(deepQuerySymbol, name ?? true);
72
- export const httpBodySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http-body");
73
-
74
-
75
-
76
-
77
-
78
- export const HttpBody = () => makeAnnotation(httpBodySymbol, true);
79
- export const stringEncodedSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/string-encoded");
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
- export const StringEncoded = () => makeAnnotation(stringEncodedSymbol, true);
90
- export const formDataFileSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/form-data-file");
91
-
92
-
93
-
94
-
95
-
96
- export const FormDataFile = () => makeAnnotation(formDataFileSymbol, true);
97
- //#endregion
98
- //#region Generic JSON traits
99
- export const keyDictionarySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/key-dictionary");
100
- export const KeyDictionary = (dict) => makeAnnotation(keyDictionarySymbol, dict);
101
- export const unionCasesSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/union-cases");
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
- export const UnionCases = (cases, discriminator) => makeAnnotation(unionCasesSymbol, discriminator ? { cases, discriminator } : { cases });
115
- //#endregion
116
- //#region Error matcher traits
117
- export const errorMatchersSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/error-matchers");
118
-
119
-
120
-
121
-
122
-
123
-
124
- export const applyErrorMatchers = (cls, matchers) => {
125
- cls[errorMatchersSymbol] = matchers;
126
- return cls;
127
- };
128
-
129
- export const getErrorMatchers = (cls) => cls?.[errorMatchersSymbol];
130
- //#endregion
131
- //# sourceMappingURL=trait.js.map
1
+ export { trait$Body as Body, trait$DeepQuery as DeepQuery, trait$FormDataFile as FormDataFile, trait$Header as Header, trait$Http as Http, trait$HttpBody as HttpBody, trait$KeyDictionary as KeyDictionary, trait$Label as Label, trait$LabelEncoding as LabelEncoding, trait$Query as Query, trait$ResponseCode as ResponseCode, trait$StringEncoded as StringEncoded, trait$UnionCases as UnionCases, trait$all as all, trait$annotationMetaSymbol as annotationMetaSymbol, trait$applyErrorMatchers as applyErrorMatchers, trait$bodySymbol as bodySymbol, trait$deepQuerySymbol as deepQuerySymbol, trait$errorMatchersSymbol as errorMatchersSymbol, trait$formDataFileSymbol as formDataFileSymbol, trait$getErrorMatchers as getErrorMatchers, trait$headerSymbol as headerSymbol, trait$httpBodySymbol as httpBodySymbol, trait$httpSymbol as httpSymbol, trait$keyDictionarySymbol as keyDictionarySymbol, trait$labelEncodingSymbol as labelEncodingSymbol, trait$labelSymbol as labelSymbol, trait$makeAnnotation as makeAnnotation, trait$querySymbol as querySymbol, trait$responseCodeSymbol as responseCodeSymbol, trait$stringEncodedSymbol as stringEncodedSymbol, trait$unionCasesSymbol as unionCasesSymbol } from "./_bundle/base.js";