@encore.dev/sdk 2.0.0-beta.8 → 2.0.0-beta.9

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 (186) hide show
  1. package/README.md +54 -0
  2. package/app_meta.test.ts +25 -5
  3. package/app_meta.ts +43 -12
  4. package/config/config.test.ts +8 -12
  5. package/config/config.ts +16 -12
  6. package/config/secrets.ts +19 -10
  7. package/config/value.ts +13 -17
  8. package/cron/mod.test.ts +52 -0
  9. package/cron/mod.ts +9 -2
  10. package/dist/app_meta.d.ts +37 -12
  11. package/dist/app_meta.d.ts.map +1 -1
  12. package/dist/app_meta.js +1 -0
  13. package/dist/app_meta.js.map +1 -1
  14. package/dist/config/config.d.ts +16 -12
  15. package/dist/config/config.d.ts.map +1 -1
  16. package/dist/config/config.js +5 -2
  17. package/dist/config/config.js.map +1 -1
  18. package/dist/config/secrets.d.ts +19 -10
  19. package/dist/config/secrets.d.ts.map +1 -1
  20. package/dist/config/secrets.js +19 -10
  21. package/dist/config/secrets.js.map +1 -1
  22. package/dist/config/value.d.ts +7 -5
  23. package/dist/config/value.d.ts.map +1 -1
  24. package/dist/config/value.js +10 -7
  25. package/dist/config/value.js.map +1 -1
  26. package/dist/cron/mod.d.ts +5 -1
  27. package/dist/cron/mod.d.ts.map +1 -1
  28. package/dist/cron/mod.js +8 -1
  29. package/dist/cron/mod.js.map +1 -1
  30. package/dist/frontends/mod.d.ts +39 -0
  31. package/dist/frontends/mod.d.ts.map +1 -0
  32. package/dist/frontends/mod.js +47 -0
  33. package/dist/frontends/mod.js.map +1 -0
  34. package/dist/gateway/mod.d.ts +3 -2
  35. package/dist/gateway/mod.d.ts.map +1 -1
  36. package/dist/gateway/mod.js +3 -2
  37. package/dist/gateway/mod.js.map +1 -1
  38. package/dist/gateways/mod.d.ts +42 -0
  39. package/dist/gateways/mod.d.ts.map +1 -0
  40. package/dist/gateways/mod.js +55 -0
  41. package/dist/gateways/mod.js.map +1 -0
  42. package/dist/internal/fetch.d.ts +4 -0
  43. package/dist/internal/fetch.d.ts.map +1 -1
  44. package/dist/internal/fetch.js +12 -1
  45. package/dist/internal/fetch.js.map +1 -1
  46. package/dist/internal/otel/http.d.ts +11 -0
  47. package/dist/internal/otel/http.d.ts.map +1 -0
  48. package/dist/internal/otel/http.js +64 -0
  49. package/dist/internal/otel/http.js.map +1 -0
  50. package/dist/internal/otel/index.d.ts +1 -1
  51. package/dist/internal/otel/index.d.ts.map +1 -1
  52. package/dist/internal/otel/index.js +1 -1
  53. package/dist/internal/otel/index.js.map +1 -1
  54. package/dist/internal/otel/provider.d.ts +3 -0
  55. package/dist/internal/otel/provider.d.ts.map +1 -1
  56. package/dist/internal/otel/provider.js +3 -0
  57. package/dist/internal/otel/provider.js.map +1 -1
  58. package/dist/internal/otel/span.d.ts +11 -1
  59. package/dist/internal/otel/span.d.ts.map +1 -1
  60. package/dist/internal/otel/span.js +25 -2
  61. package/dist/internal/otel/span.js.map +1 -1
  62. package/dist/internal/reqfields.d.ts +26 -6
  63. package/dist/internal/reqfields.d.ts.map +1 -1
  64. package/dist/internal/reqfields.js +44 -7
  65. package/dist/internal/reqfields.js.map +1 -1
  66. package/dist/internal/runtime/napi/napi.cjs +36 -4
  67. package/dist/internal/runtime/napi/napi.d.cts +99 -4
  68. package/dist/internal/testing/carry.d.ts +49 -0
  69. package/dist/internal/testing/carry.d.ts.map +1 -0
  70. package/dist/internal/testing/carry.js +77 -0
  71. package/dist/internal/testing/carry.js.map +1 -0
  72. package/dist/internal/testing/scope.d.ts +34 -6
  73. package/dist/internal/testing/scope.d.ts.map +1 -1
  74. package/dist/internal/testing/scope.js +103 -5
  75. package/dist/internal/testing/scope.js.map +1 -1
  76. package/dist/internal/testing/steps.d.ts +55 -0
  77. package/dist/internal/testing/steps.d.ts.map +1 -0
  78. package/dist/internal/testing/steps.js +295 -0
  79. package/dist/internal/testing/steps.js.map +1 -0
  80. package/dist/internal/testing/telemetry.d.ts +305 -0
  81. package/dist/internal/testing/telemetry.d.ts.map +1 -0
  82. package/dist/internal/testing/telemetry.js +188 -0
  83. package/dist/internal/testing/telemetry.js.map +1 -0
  84. package/dist/mod.d.ts +1 -1
  85. package/dist/mod.d.ts.map +1 -1
  86. package/dist/mod.js.map +1 -1
  87. package/dist/pubsub/mod.d.ts +1 -1
  88. package/dist/pubsub/mod.d.ts.map +1 -1
  89. package/dist/pubsub/subscription.d.ts +6 -5
  90. package/dist/pubsub/subscription.d.ts.map +1 -1
  91. package/dist/pubsub/subscription.js.map +1 -1
  92. package/dist/pubsub/topic.d.ts +14 -8
  93. package/dist/pubsub/topic.d.ts.map +1 -1
  94. package/dist/pubsub/topic.js +36 -22
  95. package/dist/pubsub/topic.js.map +1 -1
  96. package/dist/reqctx/mod.d.ts +1 -18
  97. package/dist/reqctx/mod.d.ts.map +1 -1
  98. package/dist/reqctx/mod.js +1 -17
  99. package/dist/reqctx/mod.js.map +1 -1
  100. package/dist/services/index.d.ts +2 -1
  101. package/dist/services/index.d.ts.map +1 -1
  102. package/dist/services/index.js +2 -1
  103. package/dist/services/index.js.map +1 -1
  104. package/dist/storage/objects/bucket.d.ts +2 -1
  105. package/dist/storage/objects/bucket.d.ts.map +1 -1
  106. package/dist/storage/objects/bucket.js +2 -1
  107. package/dist/storage/objects/bucket.js.map +1 -1
  108. package/dist/storage/postgres/database.d.ts +5 -1
  109. package/dist/storage/postgres/database.d.ts.map +1 -1
  110. package/dist/storage/postgres/database.js +7 -3
  111. package/dist/storage/postgres/database.js.map +1 -1
  112. package/dist/storage/redis/commands.d.ts +5 -5
  113. package/dist/storage/redis/commands.d.ts.map +1 -1
  114. package/dist/storage/redis/commands.js +5 -5
  115. package/dist/storage/redis/commands.js.map +1 -1
  116. package/dist/testing/mod.d.ts +28 -5
  117. package/dist/testing/mod.d.ts.map +1 -1
  118. package/dist/testing/mod.js +52 -8
  119. package/dist/testing/mod.js.map +1 -1
  120. package/dist/testing/playwright.d.ts +93 -0
  121. package/dist/testing/playwright.d.ts.map +1 -0
  122. package/dist/testing/playwright.js +164 -0
  123. package/dist/testing/playwright.js.map +1 -0
  124. package/dist/testing/puppeteer.d.ts +36 -0
  125. package/dist/testing/puppeteer.d.ts.map +1 -0
  126. package/dist/testing/puppeteer.js +70 -0
  127. package/dist/testing/puppeteer.js.map +1 -0
  128. package/dist/testing/system.d.ts +181 -0
  129. package/dist/testing/system.d.ts.map +1 -0
  130. package/dist/testing/system.js +255 -0
  131. package/dist/testing/system.js.map +1 -0
  132. package/dist/tracing/http.d.ts +11 -0
  133. package/dist/tracing/http.d.ts.map +1 -0
  134. package/dist/tracing/http.js +34 -0
  135. package/dist/tracing/http.js.map +1 -0
  136. package/dist/tracing/mod.d.ts +1 -0
  137. package/dist/tracing/mod.d.ts.map +1 -1
  138. package/dist/tracing/mod.js +1 -0
  139. package/dist/tracing/mod.js.map +1 -1
  140. package/dist/tracing/node.d.ts +10 -0
  141. package/dist/tracing/node.d.ts.map +1 -0
  142. package/dist/tracing/node.js +142 -0
  143. package/dist/tracing/node.js.map +1 -0
  144. package/dist/tsconfig.build.tsbuildinfo +1 -1
  145. package/frontends/mod.test.ts +51 -0
  146. package/frontends/mod.ts +50 -0
  147. package/gateway/mod.ts +3 -2
  148. package/gateways/mod.ts +60 -0
  149. package/internal/fetch.ts +12 -1
  150. package/internal/otel/http.ts +91 -0
  151. package/internal/otel/index.ts +1 -1
  152. package/internal/otel/provider.ts +3 -0
  153. package/internal/otel/span.ts +25 -2
  154. package/internal/reqfields.ts +43 -10
  155. package/internal/runtime/napi/napi.cjs +36 -4
  156. package/internal/runtime/napi/napi.d.cts +99 -4
  157. package/internal/testing/carry.test.ts +242 -0
  158. package/internal/testing/carry.ts +101 -0
  159. package/internal/testing/scope.ts +106 -7
  160. package/internal/testing/steps.test.ts +152 -0
  161. package/internal/testing/steps.ts +342 -0
  162. package/internal/testing/telemetry.test.ts +210 -0
  163. package/internal/testing/telemetry.ts +466 -0
  164. package/mod.ts +1 -0
  165. package/package.json +26 -1
  166. package/pubsub/mod.ts +6 -1
  167. package/pubsub/pubsub.test.ts +1 -0
  168. package/pubsub/subscription.ts +6 -5
  169. package/pubsub/topic.ts +45 -21
  170. package/reqctx/mod.ts +1 -18
  171. package/reqctx/reqctx.test.ts +23 -0
  172. package/scripts/postprocess-docs.test.ts +11 -1
  173. package/services/index.ts +2 -1
  174. package/storage/objects/bucket.ts +2 -1
  175. package/storage/postgres/database.ts +7 -3
  176. package/storage/redis/commands.ts +5 -5
  177. package/testing/mod.ts +63 -7
  178. package/testing/playwright.ts +247 -0
  179. package/testing/puppeteer.ts +101 -0
  180. package/testing/system.test.ts +108 -0
  181. package/testing/system.ts +373 -0
  182. package/tracing/http.ts +49 -0
  183. package/tracing/mod.ts +1 -0
  184. package/tracing/native.test.ts +101 -4
  185. package/tracing/node.ts +176 -0
  186. package/tracing/tracing.test.ts +660 -24
@@ -0,0 +1,466 @@
1
+ /**
2
+ * What a test session recorded for one system test, as the core read it
3
+ * (`encore_sdk_core::system_test::telemetry`): the spans and the lines logged
4
+ * in them, each span said to be what it is of. The core hands it over as
5
+ * JSON, with the tree and the errors worked out; this gives it types.
6
+ *
7
+ * @internal
8
+ */
9
+
10
+ /** A span's kind. */
11
+ export type SpanKind =
12
+ 'internal' | 'server' | 'client' | 'producer' | 'consumer';
13
+
14
+ /** A span's status. */
15
+ export type SpanStatus = 'unset' | 'ok' | 'error';
16
+
17
+ /** The test itself: the root of its trace. */
18
+ export interface TestWhat {
19
+ type: 'test';
20
+ name: string;
21
+ }
22
+
23
+ /**
24
+ * A request Encore handed a service, or took at a gateway: recorded by
25
+ * Encore where it hands the request over, whether or not the service records
26
+ * a span of its own.
27
+ */
28
+ export interface RequestWhat {
29
+ type: 'request';
30
+ /** The service it was handed to, or the gateway that took it. */
31
+ service: string;
32
+ method: string;
33
+ path: string;
34
+ /** The route it matched, when the service's API spec says. */
35
+ route?: string;
36
+ /** The endpoint it matched, by name, when known. */
37
+ endpoint?: string;
38
+ /** The response's status; 0 when none was sent. */
39
+ status: number;
40
+ /** Who made it: the service whose span it is under, `test` for the test
41
+ * itself, none when its parent is not among the spans. */
42
+ caller?: string;
43
+ /** How long it was held for its service to start, if it was, in
44
+ * nanoseconds. */
45
+ coldStartNanos?: number;
46
+ /** Whether a call between services carried its request's context
47
+ * (`propagated`), as Encore judged it, when it did. */
48
+ propagation?: string;
49
+ }
50
+
51
+ /** A query a service, or the test, ran on a database. */
52
+ export interface QueryWhat {
53
+ type: 'query';
54
+ database: string;
55
+ /** What it does to what (`INSERT charges`). */
56
+ summary: string;
57
+ statement: string;
58
+ }
59
+
60
+ /** A message published to a topic. */
61
+ export interface PublishWhat {
62
+ type: 'publish';
63
+ topic: string;
64
+ messageId: string;
65
+ }
66
+
67
+ /** A message delivered to a subscription: one attempt. */
68
+ export interface DeliveryWhat {
69
+ type: 'delivery';
70
+ topic: string;
71
+ subscription: string;
72
+ messageId: string;
73
+ /** Which delivery of the message it is: 1 the first. */
74
+ attempt: number;
75
+ /** Whether the handler handled it. */
76
+ handled: boolean;
77
+ }
78
+
79
+ /** Encore's own doing on a request's way: sending it on, or holding it
80
+ * while its service starts. Part of the request. */
81
+ export interface HopWhat {
82
+ type: 'hop';
83
+ }
84
+
85
+ /** Anything else: a span of the app's own, a cache command, a connect. */
86
+ export interface OtherWhat {
87
+ type: 'other';
88
+ }
89
+
90
+ /** What a span is of, with what a test asks of one. */
91
+ export type What =
92
+ | TestWhat
93
+ | RequestWhat
94
+ | QueryWhat
95
+ | PublishWhat
96
+ | DeliveryWhat
97
+ | HopWhat
98
+ | OtherWhat;
99
+
100
+ /** An event of a span. */
101
+ export interface SpanEvent {
102
+ name: string;
103
+ timeUnixNanos: bigint;
104
+ attributes: Record<string, unknown>;
105
+ }
106
+
107
+ /** A link to another span. */
108
+ export interface SpanLink {
109
+ traceId: string;
110
+ spanId: string;
111
+ }
112
+
113
+ /** One span. */
114
+ export interface Span<W extends What = What> {
115
+ traceId: string;
116
+ spanId: string;
117
+ /** None for the root of a trace. */
118
+ parentSpanId?: string;
119
+ name: string;
120
+ kind: SpanKind;
121
+ /** The service that recorded it: the app's name for the test's own
122
+ * spans. */
123
+ service: string;
124
+ /** The instrumentation scope that recorded it. */
125
+ scope: string;
126
+ startUnixNanos: bigint;
127
+ endUnixNanos: bigint;
128
+ status: SpanStatus;
129
+ /** Empty unless the status says. */
130
+ statusMessage: string;
131
+ attributes: Record<string, unknown>;
132
+ events: SpanEvent[];
133
+ /** The spans it is linked to: a delivery's, to the publish of its
134
+ * message. */
135
+ links: SpanLink[];
136
+ /** What the span is of. */
137
+ what: W;
138
+ }
139
+
140
+ /** A line a service logged, or something Encore captured of a request. */
141
+ export interface Log {
142
+ timeUnixNanos: bigint;
143
+ /** `error`, `warn`, `info`, `debug` or `trace`; empty when unknown. */
144
+ level: string;
145
+ body: string;
146
+ service: string;
147
+ /** Empty for a line logged outside any span. */
148
+ traceId: string;
149
+ spanId: string;
150
+ /** The name of the event it is, for one that is no line; empty for a
151
+ * line. */
152
+ eventName: string;
153
+ attributes: Record<string, unknown>;
154
+ }
155
+
156
+ /**
157
+ * Which spans of a kind to list: those whose {@link Span.what} has each
158
+ * value given. `{service: "orders", status: 200}` matches the requests the
159
+ * `orders` service answered with a 200.
160
+ */
161
+ export type Filter<W extends What> = Partial<Omit<W, 'type'>>;
162
+
163
+ /** What a test session recorded for one test. */
164
+ export class Telemetry {
165
+ /** The test's id. */
166
+ readonly testId: string;
167
+ /** Every span of every trace the test caused, by start: the test's own
168
+ * trace, and that of each delivery of a message published for it. */
169
+ readonly spans: readonly Span[];
170
+ /** The lines the services logged in those traces, and what Encore
171
+ * captured of their requests, by time. */
172
+ readonly logs: readonly Log[];
173
+ private readonly rendered: string;
174
+ private readonly shaped: string;
175
+ private readonly wrong: readonly string[];
176
+ private readonly lost: readonly LostContext[];
177
+
178
+ /** @internal */
179
+ constructor(wire: Wire) {
180
+ this.testId = wire.test_id ?? '';
181
+ this.spans = (wire.spans ?? []).map(span);
182
+ this.logs = (wire.logs ?? []).map(log);
183
+ this.rendered = wire.rendered ?? '';
184
+ this.shaped = wire.shape ?? '';
185
+ this.wrong = wire.errors ?? [];
186
+ this.lost = (wire.lost_context ?? []).map(lost => ({
187
+ caller: lost.caller,
188
+ service: lost.service,
189
+ method: lost.method,
190
+ path: lost.path,
191
+ verdict: lost.verdict,
192
+ ofTest: lost.of_test,
193
+ }));
194
+ }
195
+
196
+ /**
197
+ * Reads the core's JSON (`Telemetry::to_json`). The times in it are
198
+ * nanoseconds since the Unix epoch, past what a JavaScript number holds
199
+ * exactly, so they are read as bigints.
200
+ *
201
+ * @internal
202
+ */
203
+ static parse(json: string): Telemetry {
204
+ // A key is the only place a string is followed by a colon, so this
205
+ // quotes the values of those keys and nothing in a string.
206
+ const quoted = json.replace(
207
+ /"((?:start|end|time)_unix_nanos)"\s*:\s*(\d+)/g,
208
+ '"$1":"$2"',
209
+ );
210
+ return new Telemetry(JSON.parse(quoted) as Wire);
211
+ }
212
+
213
+ /** The requests services were handed, and gateways took, in order. */
214
+ requests(filter?: Filter<RequestWhat>): Span<RequestWhat>[] {
215
+ return this.of('request', filter);
216
+ }
217
+
218
+ /** The queries run on the app's databases, in order. */
219
+ queries(filter?: Filter<QueryWhat>): Span<QueryWhat>[] {
220
+ return this.of('query', filter);
221
+ }
222
+
223
+ /** The messages published, in order. */
224
+ publishes(filter?: Filter<PublishWhat>): Span<PublishWhat>[] {
225
+ return this.of('publish', filter);
226
+ }
227
+
228
+ /** The deliveries of messages to subscriptions, an attempt each, in
229
+ * order. */
230
+ deliveries(filter?: Filter<DeliveryWhat>): Span<DeliveryWhat>[] {
231
+ return this.of('delivery', filter);
232
+ }
233
+
234
+ private of<W extends What>(type: W['type'], filter?: Filter<W>): Span<W>[] {
235
+ const wanted = Object.entries(filter ?? {}).filter(
236
+ ([, value]) => value !== undefined,
237
+ );
238
+ return this.spans.filter(
239
+ (span): span is Span<W> =>
240
+ span.what.type === type &&
241
+ wanted.every(
242
+ ([key, value]) =>
243
+ (span.what as unknown as Record<string, unknown>)[key] === value,
244
+ ),
245
+ );
246
+ }
247
+
248
+ /**
249
+ * What went wrong in what the test caused, a line each: requests answered
250
+ * with a server error, spans that failed, deliveries the handler did not
251
+ * handle, calls between services that lost their request's context, and
252
+ * lines logged as errors.
253
+ */
254
+ errors(): string[] {
255
+ return [...this.wrong];
256
+ }
257
+
258
+ /**
259
+ * The calls between services that lost their request's context, and with
260
+ * it the test: those a service made for the test, then those only known
261
+ * to have been made while it ran, each kind of call once. A test that
262
+ * finds its own data without what it expected finds why here. The tree
263
+ * (`toString`) lists them under it.
264
+ */
265
+ lostContext(): LostContext[] {
266
+ return [...this.lost];
267
+ }
268
+
269
+ /**
270
+ * The tree without what differs between runs — ids, times, how long
271
+ * anything took, cold starts — for a snapshot of which services a flow
272
+ * touches, and in what order. Spans beside each other that overlap in
273
+ * time are listed by name, so concurrent calls give one shape.
274
+ */
275
+ shape(): string {
276
+ return this.shaped;
277
+ }
278
+
279
+ /**
280
+ * What the test caused, as a tree: each request and what the service did
281
+ * for it, then each delivery, with statuses and how long each took. What
282
+ * a failed test prints.
283
+ */
284
+ toString(): string {
285
+ return this.rendered;
286
+ }
287
+ }
288
+
289
+ /**
290
+ * What a failed system test prints of what its session recorded for it: the
291
+ * tree of what it caused in the app, under a line saying so. Empty for a
292
+ * test that caused nothing there.
293
+ */
294
+ export function causedBy(recorded: Telemetry): string {
295
+ // The test's own span alone: it reached nothing.
296
+ if (recorded.spans.length <= 1) return '';
297
+ const tree = recorded.toString().trimEnd();
298
+ if (tree === '') return '';
299
+ const lines = tree.split('\n').map(line => ` ${line}`);
300
+ return ['', 'What this test caused in the app:', ...lines].join('\n');
301
+ }
302
+
303
+ /** The core's JSON: its `Serialize` derives, with a nanosecond time quoted
304
+ * by {@link Telemetry.parse}. */
305
+ interface Wire {
306
+ test_id?: string;
307
+ spans?: WireSpan[];
308
+ logs?: WireLog[];
309
+ rendered?: string;
310
+ shape?: string;
311
+ errors?: string[];
312
+ lost_context?: {
313
+ caller?: string;
314
+ service: string;
315
+ method: string;
316
+ path: string;
317
+ verdict: string;
318
+ of_test: boolean;
319
+ }[];
320
+ }
321
+
322
+ /**
323
+ * A call between services that did not carry its request's context, and so
324
+ * not the test: what the service called did for it, it did on the data the
325
+ * services share, not on the test's.
326
+ */
327
+ export interface LostContext {
328
+ /** The service that made the call, when it is known. */
329
+ readonly caller?: string;
330
+ /** The service called. */
331
+ readonly service: string;
332
+ readonly method: string;
333
+ readonly path: string;
334
+ /** How it was lost: `context_dropped` for a call in its request's trace
335
+ * without its Request Context, `detached` for one in a trace of its own,
336
+ * `untraced` for one with no trace. */
337
+ readonly verdict: string;
338
+ /** Whether the call is known to be the test's: one in its trace. Not one
339
+ * only known to have been made while it ran, which may be another
340
+ * test's running beside it. */
341
+ readonly ofTest: boolean;
342
+ }
343
+
344
+ interface WireSpan {
345
+ trace_id: string;
346
+ span_id: string;
347
+ parent_span_id?: string;
348
+ name: string;
349
+ kind: SpanKind;
350
+ service: string;
351
+ scope: string;
352
+ start_unix_nanos: string | number;
353
+ end_unix_nanos: string | number;
354
+ status: SpanStatus;
355
+ status_message?: string;
356
+ attributes?: Record<string, unknown>;
357
+ events?: {
358
+ name: string;
359
+ time_unix_nanos: string | number;
360
+ attributes?: Record<string, unknown>;
361
+ }[];
362
+ links?: {trace_id: string; span_id: string}[];
363
+ what: WireWhat;
364
+ }
365
+
366
+ type WireWhat =
367
+ | TestWhat
368
+ | {
369
+ type: 'request';
370
+ service: string;
371
+ method: string;
372
+ path: string;
373
+ route?: string;
374
+ endpoint?: string;
375
+ status: number;
376
+ caller?: string;
377
+ cold_start_nanos?: number;
378
+ propagation?: string;
379
+ }
380
+ | QueryWhat
381
+ | {type: 'publish'; topic: string; message_id: string}
382
+ | {
383
+ type: 'delivery';
384
+ topic: string;
385
+ subscription: string;
386
+ message_id: string;
387
+ attempt: number;
388
+ handled: boolean;
389
+ }
390
+ | HopWhat
391
+ | OtherWhat;
392
+
393
+ interface WireLog {
394
+ time_unix_nanos: string | number;
395
+ level: string;
396
+ body: string;
397
+ service: string;
398
+ trace_id?: string;
399
+ span_id?: string;
400
+ event_name?: string;
401
+ attributes?: Record<string, unknown>;
402
+ }
403
+
404
+ function span(wire: WireSpan): Span {
405
+ return {
406
+ traceId: wire.trace_id,
407
+ spanId: wire.span_id,
408
+ ...(wire.parent_span_id === undefined
409
+ ? {}
410
+ : {parentSpanId: wire.parent_span_id}),
411
+ name: wire.name,
412
+ kind: wire.kind,
413
+ service: wire.service,
414
+ scope: wire.scope,
415
+ startUnixNanos: BigInt(wire.start_unix_nanos),
416
+ endUnixNanos: BigInt(wire.end_unix_nanos),
417
+ status: wire.status,
418
+ statusMessage: wire.status_message ?? '',
419
+ attributes: wire.attributes ?? {},
420
+ events: (wire.events ?? []).map(event => ({
421
+ name: event.name,
422
+ timeUnixNanos: BigInt(event.time_unix_nanos),
423
+ attributes: event.attributes ?? {},
424
+ })),
425
+ links: (wire.links ?? []).map(link => ({
426
+ traceId: link.trace_id,
427
+ spanId: link.span_id,
428
+ })),
429
+ what: what(wire.what),
430
+ };
431
+ }
432
+
433
+ function what(wire: WireWhat): What {
434
+ switch (wire.type) {
435
+ case 'request': {
436
+ const {cold_start_nanos: coldStartNanos, ...rest} = wire;
437
+ return coldStartNanos === undefined ? rest : {...rest, coldStartNanos};
438
+ }
439
+ case 'publish':
440
+ return {type: wire.type, topic: wire.topic, messageId: wire.message_id};
441
+ case 'delivery':
442
+ return {
443
+ type: wire.type,
444
+ topic: wire.topic,
445
+ subscription: wire.subscription,
446
+ messageId: wire.message_id,
447
+ attempt: wire.attempt,
448
+ handled: wire.handled,
449
+ };
450
+ default:
451
+ return wire;
452
+ }
453
+ }
454
+
455
+ function log(wire: WireLog): Log {
456
+ return {
457
+ timeUnixNanos: BigInt(wire.time_unix_nanos),
458
+ level: wire.level,
459
+ body: wire.body,
460
+ service: wire.service,
461
+ traceId: wire.trace_id ?? '',
462
+ spanId: wire.span_id ?? '',
463
+ eventName: wire.event_name ?? '',
464
+ attributes: wire.attributes ?? {},
465
+ };
466
+ }
package/mod.ts CHANGED
@@ -6,6 +6,7 @@ export type {
6
6
  DeployMeta,
7
7
  EnvironmentMeta,
8
8
  EnvironmentType,
9
+ FrontendMeta,
9
10
  GatewayMeta,
10
11
  HostedService,
11
12
  } from './app_meta';
package/package.json CHANGED
@@ -39,11 +39,21 @@
39
39
  "default": "./dist/cron/mod.js",
40
40
  "types": "./dist/cron/mod.d.ts"
41
41
  },
42
+ "./frontends": {
43
+ "bun": "./frontends/mod.ts",
44
+ "default": "./dist/frontends/mod.js",
45
+ "types": "./dist/frontends/mod.d.ts"
46
+ },
42
47
  "./gateway": {
43
48
  "bun": "./gateway/mod.ts",
44
49
  "default": "./dist/gateway/mod.js",
45
50
  "types": "./dist/gateway/mod.d.ts"
46
51
  },
52
+ "./gateways": {
53
+ "bun": "./gateways/mod.ts",
54
+ "default": "./dist/gateways/mod.js",
55
+ "types": "./dist/gateways/mod.d.ts"
56
+ },
47
57
  "./internal/*": {
48
58
  "bun": "./internal/*.ts",
49
59
  "default": "./dist/internal/*.js",
@@ -114,6 +124,16 @@
114
124
  "default": "./dist/testing/node.js",
115
125
  "types": "./dist/testing/node.d.ts"
116
126
  },
127
+ "./testing/playwright": {
128
+ "bun": "./testing/playwright.ts",
129
+ "default": "./dist/testing/playwright.js",
130
+ "types": "./dist/testing/playwright.d.ts"
131
+ },
132
+ "./testing/puppeteer": {
133
+ "bun": "./testing/puppeteer.ts",
134
+ "default": "./dist/testing/puppeteer.js",
135
+ "types": "./dist/testing/puppeteer.d.ts"
136
+ },
117
137
  "./testing/vitest": {
118
138
  "bun": "./testing/vitest.ts",
119
139
  "default": "./dist/testing/vitest.js",
@@ -124,6 +144,11 @@
124
144
  "default": "./dist/tracing/mod.js",
125
145
  "types": "./dist/tracing/mod.d.ts"
126
146
  },
147
+ "./tracing/node": {
148
+ "bun": "./tracing/node.ts",
149
+ "default": "./dist/tracing/node.js",
150
+ "types": "./dist/tracing/node.d.ts"
151
+ },
127
152
  "./types": {
128
153
  "bun": "./types/mod.ts",
129
154
  "default": "./dist/types/mod.js",
@@ -171,5 +196,5 @@
171
196
  },
172
197
  "sideEffects": false,
173
198
  "type": "module",
174
- "version": "2.0.0-beta.8"
199
+ "version": "2.0.0-beta.9"
175
200
  }
package/pubsub/mod.ts CHANGED
@@ -9,7 +9,12 @@ export type {
9
9
  } from './topic';
10
10
 
11
11
  export {Subscription, NoRetries, InfiniteRetries} from './subscription';
12
- export type {SubscriptionConfig, RetryPolicy, Message} from './subscription';
12
+ export type {
13
+ SubscriptionConfig,
14
+ SubscriptionOptions,
15
+ RetryPolicy,
16
+ Message,
17
+ } from './subscription';
13
18
 
14
19
  export type {
15
20
  TopicPerms,
@@ -22,6 +22,7 @@ mock.module('../internal/runtime/mod', () => ({
22
22
  }));
23
23
  mock.module('../internal/otel/index', () => ({
24
24
  activeCtxBytes: () => undefined,
25
+ contextCtxBytes: () => undefined,
25
26
  }));
26
27
  mock.module('../log/index', () => ({default: {error: errors}}));
27
28
  const {Topic, OrderedTopic, PublishBatchError, MaxBatchSize} =
@@ -184,22 +184,23 @@ function handlerContext(
184
184
  }
185
185
 
186
186
  /**
187
- * SubscriptionConfig is used when creating a subscription
187
+ * SubscriptionConfig is used when creating a subscription: its
188
+ * {@link SubscriptionOptions}, and how its messages are decoded.
189
+ *
190
+ * Decode JSON by default; byte subscriptions must select `encoding: "raw"`.
191
+ * `decode` optionally validates/transforms JSON, or decodes a custom raw format.
188
192
  *
189
193
  * The values given here may be clamped to the supported values by
190
194
  * the target cloud. (i.e. ack deadline may be brought within the supported range
191
195
  * by the target cloud pubsub implementation).
192
196
  */
193
- /**
194
- * Decode JSON by default; byte subscriptions must select `encoding: "raw"`.
195
- * `decode` optionally validates/transforms JSON, or decodes a custom raw format.
196
- */
197
197
  export type SubscriptionConfig<Msg> = SubscriptionOptions<Msg> &
198
198
  ([Msg] extends [Uint8Array]
199
199
  ? {encoding: 'raw'; decode?: never}
200
200
  : | {encoding?: 'json'; decode?: (data: unknown) => Msg}
201
201
  | {encoding: 'raw'; decode: (data: unknown) => Msg});
202
202
 
203
+ /** A subscription's options, other than how its messages are decoded. */
203
204
  export interface SubscriptionOptions<Msg> {
204
205
  /**
205
206
  * Handler is the function which will be called to process a message