@encore.dev/sdk 0.0.0 → 2.0.0-beta.5

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 (250) hide show
  1. package/LICENSE +362 -0
  2. package/README.md +122 -2
  3. package/app_meta.test.ts +134 -0
  4. package/app_meta.ts +186 -0
  5. package/config/config.test.ts +381 -0
  6. package/config/config.ts +178 -0
  7. package/config/mod.ts +14 -0
  8. package/config/secrets.ts +147 -0
  9. package/config/value.ts +243 -0
  10. package/cron/mod.ts +23 -0
  11. package/dist/app_meta.d.ts +93 -0
  12. package/dist/app_meta.js +65 -0
  13. package/dist/app_meta.js.map +1 -0
  14. package/dist/config/config.d.ts +105 -0
  15. package/dist/config/config.js +87 -0
  16. package/dist/config/config.js.map +1 -0
  17. package/dist/config/mod.d.ts +4 -0
  18. package/dist/config/mod.js +3 -0
  19. package/dist/config/mod.js.map +1 -0
  20. package/dist/config/secrets.d.ts +92 -0
  21. package/dist/config/secrets.js +80 -0
  22. package/dist/config/secrets.js.map +1 -0
  23. package/dist/config/value.d.ts +51 -0
  24. package/dist/config/value.js +178 -0
  25. package/dist/config/value.js.map +1 -0
  26. package/dist/cron/mod.d.ts +22 -0
  27. package/dist/cron/mod.js +9 -0
  28. package/dist/cron/mod.js.map +1 -0
  29. package/dist/internal/otel/backend.d.ts +50 -0
  30. package/dist/internal/otel/backend.js +2 -0
  31. package/dist/internal/otel/backend.js.map +1 -0
  32. package/dist/internal/otel/context.d.ts +10 -0
  33. package/dist/internal/otel/context.js +34 -0
  34. package/dist/internal/otel/context.js.map +1 -0
  35. package/dist/internal/otel/context_manager.d.ts +22 -0
  36. package/dist/internal/otel/context_manager.js +120 -0
  37. package/dist/internal/otel/context_manager.js.map +1 -0
  38. package/dist/internal/otel/encode.d.ts +112 -0
  39. package/dist/internal/otel/encode.js +290 -0
  40. package/dist/internal/otel/encode.js.map +1 -0
  41. package/dist/internal/otel/index.d.ts +9 -0
  42. package/dist/internal/otel/index.js +9 -0
  43. package/dist/internal/otel/index.js.map +1 -0
  44. package/dist/internal/otel/meter.d.ts +73 -0
  45. package/dist/internal/otel/meter.js +265 -0
  46. package/dist/internal/otel/meter.js.map +1 -0
  47. package/dist/internal/otel/propagator.d.ts +14 -0
  48. package/dist/internal/otel/propagator.js +61 -0
  49. package/dist/internal/otel/propagator.js.map +1 -0
  50. package/dist/internal/otel/provider.d.ts +9 -0
  51. package/dist/internal/otel/provider.js +19 -0
  52. package/dist/internal/otel/provider.js.map +1 -0
  53. package/dist/internal/otel/request_context.d.ts +11 -0
  54. package/dist/internal/otel/request_context.js +20 -0
  55. package/dist/internal/otel/request_context.js.map +1 -0
  56. package/dist/internal/otel/span.d.ts +61 -0
  57. package/dist/internal/otel/span.js +206 -0
  58. package/dist/internal/otel/span.js.map +1 -0
  59. package/dist/internal/otel/tracer.d.ts +15 -0
  60. package/dist/internal/otel/tracer.js +65 -0
  61. package/dist/internal/otel/tracer.js.map +1 -0
  62. package/dist/internal/reqtrack/mod.d.ts +6 -0
  63. package/dist/internal/reqtrack/mod.js +28 -0
  64. package/dist/internal/reqtrack/mod.js.map +1 -0
  65. package/dist/internal/runtime/meter.d.ts +11 -0
  66. package/dist/internal/runtime/meter.js +22 -0
  67. package/dist/internal/runtime/meter.js.map +1 -0
  68. package/dist/internal/runtime/mod.d.ts +12 -0
  69. package/dist/internal/runtime/mod.js +28 -0
  70. package/dist/internal/runtime/mod.js.map +1 -0
  71. package/dist/internal/runtime/napi/napi.cjs +122 -0
  72. package/dist/internal/runtime/napi/napi.d.cts +601 -0
  73. package/dist/internal/runtime/shutdown.d.ts +13 -0
  74. package/dist/internal/runtime/shutdown.js +56 -0
  75. package/dist/internal/runtime/shutdown.js.map +1 -0
  76. package/dist/internal/utils/constraints.d.ts +9 -0
  77. package/dist/internal/utils/constraints.js +2 -0
  78. package/dist/internal/utils/constraints.js.map +1 -0
  79. package/dist/log/index.d.ts +39 -0
  80. package/dist/log/index.js +44 -0
  81. package/dist/log/index.js.map +1 -0
  82. package/dist/log/logger.d.ts +123 -0
  83. package/dist/log/logger.js +203 -0
  84. package/dist/log/logger.js.map +1 -0
  85. package/dist/log/runtime.d.ts +19 -0
  86. package/dist/log/runtime.js +22 -0
  87. package/dist/log/runtime.js.map +1 -0
  88. package/dist/log/stderr.d.ts +9 -0
  89. package/dist/log/stderr.js +25 -0
  90. package/dist/log/stderr.js.map +1 -0
  91. package/dist/metrics/mod.d.ts +315 -0
  92. package/dist/metrics/mod.js +488 -0
  93. package/dist/metrics/mod.js.map +1 -0
  94. package/dist/mod.d.ts +6 -0
  95. package/dist/mod.js +4 -0
  96. package/dist/mod.js.map +1 -0
  97. package/dist/otel.d.ts +9 -0
  98. package/dist/otel.js +13 -0
  99. package/dist/otel.js.map +1 -0
  100. package/dist/pubsub/encoding.d.ts +3 -0
  101. package/dist/pubsub/encoding.js +10 -0
  102. package/dist/pubsub/encoding.js.map +1 -0
  103. package/dist/pubsub/mod.d.ts +6 -0
  104. package/dist/pubsub/mod.js +3 -0
  105. package/dist/pubsub/mod.js.map +1 -0
  106. package/dist/pubsub/refs.d.ts +12 -0
  107. package/dist/pubsub/refs.js +11 -0
  108. package/dist/pubsub/refs.js.map +1 -0
  109. package/dist/pubsub/subscription.d.ts +128 -0
  110. package/dist/pubsub/subscription.js +39 -0
  111. package/dist/pubsub/subscription.js.map +1 -0
  112. package/dist/pubsub/topic.d.ts +148 -0
  113. package/dist/pubsub/topic.js +164 -0
  114. package/dist/pubsub/topic.js.map +1 -0
  115. package/dist/req_meta.d.ts +47 -0
  116. package/dist/req_meta.js +26 -0
  117. package/dist/req_meta.js.map +1 -0
  118. package/dist/services/index.d.ts +12 -0
  119. package/dist/services/index.js +22 -0
  120. package/dist/services/index.js.map +1 -0
  121. package/dist/shutdown/mod.d.ts +23 -0
  122. package/dist/shutdown/mod.js +24 -0
  123. package/dist/shutdown/mod.js.map +1 -0
  124. package/dist/storage/objects/bucket.d.ts +216 -0
  125. package/dist/storage/objects/bucket.js +123 -0
  126. package/dist/storage/objects/bucket.js.map +1 -0
  127. package/dist/storage/objects/error.d.ts +14 -0
  128. package/dist/storage/objects/error.js +81 -0
  129. package/dist/storage/objects/error.js.map +1 -0
  130. package/dist/storage/objects/mod.d.ts +4 -0
  131. package/dist/storage/objects/mod.js +3 -0
  132. package/dist/storage/objects/mod.js.map +1 -0
  133. package/dist/storage/objects/refs.d.ts +31 -0
  134. package/dist/storage/objects/refs.js +20 -0
  135. package/dist/storage/objects/refs.js.map +1 -0
  136. package/dist/storage/postgres/database.d.ts +295 -0
  137. package/dist/storage/postgres/database.js +378 -0
  138. package/dist/storage/postgres/database.js.map +1 -0
  139. package/dist/storage/postgres/mod.d.ts +2 -0
  140. package/dist/storage/postgres/mod.js +2 -0
  141. package/dist/storage/postgres/mod.js.map +1 -0
  142. package/dist/storage/redis/commands.d.ts +573 -0
  143. package/dist/storage/redis/commands.js +637 -0
  144. package/dist/storage/redis/commands.js.map +1 -0
  145. package/dist/storage/redis/database.d.ts +302 -0
  146. package/dist/storage/redis/database.js +336 -0
  147. package/dist/storage/redis/database.js.map +1 -0
  148. package/dist/storage/redis/mod.d.ts +88 -0
  149. package/dist/storage/redis/mod.js +84 -0
  150. package/dist/storage/redis/mod.js.map +1 -0
  151. package/dist/storage/redis/native.d.ts +8 -0
  152. package/dist/storage/redis/native.js +11 -0
  153. package/dist/storage/redis/native.js.map +1 -0
  154. package/dist/storage/redis/options.d.ts +89 -0
  155. package/dist/storage/redis/options.js +53 -0
  156. package/dist/storage/redis/options.js.map +1 -0
  157. package/dist/storage/redis/pubsub.d.ts +53 -0
  158. package/dist/storage/redis/pubsub.js +88 -0
  159. package/dist/storage/redis/pubsub.js.map +1 -0
  160. package/dist/storage/redis/reply.d.ts +256 -0
  161. package/dist/storage/redis/reply.js +572 -0
  162. package/dist/storage/redis/reply.js.map +1 -0
  163. package/dist/storage/redis/scan.d.ts +11 -0
  164. package/dist/storage/redis/scan.js +76 -0
  165. package/dist/storage/redis/scan.js.map +1 -0
  166. package/dist/storage/redis/script.d.ts +91 -0
  167. package/dist/storage/redis/script.js +143 -0
  168. package/dist/storage/redis/script.js.map +1 -0
  169. package/dist/storage/redis/target.d.ts +47 -0
  170. package/dist/storage/redis/target.js +82 -0
  171. package/dist/storage/redis/target.js.map +1 -0
  172. package/dist/storage/redis/wire.d.ts +105 -0
  173. package/dist/storage/redis/wire.js +333 -0
  174. package/dist/storage/redis/wire.js.map +1 -0
  175. package/dist/tsconfig.build.tsbuildinfo +1 -0
  176. package/dist/types/mod.d.ts +42 -0
  177. package/dist/types/mod.js +65 -0
  178. package/dist/types/mod.js.map +1 -0
  179. package/internal/otel/backend.ts +60 -0
  180. package/internal/otel/context.test.ts +70 -0
  181. package/internal/otel/context.ts +48 -0
  182. package/internal/otel/context_manager.test.ts +154 -0
  183. package/internal/otel/context_manager.ts +141 -0
  184. package/internal/otel/encode.test.ts +266 -0
  185. package/internal/otel/encode.ts +408 -0
  186. package/internal/otel/index.ts +20 -0
  187. package/internal/otel/meter.test.ts +231 -0
  188. package/internal/otel/meter.ts +332 -0
  189. package/internal/otel/propagator.test.ts +105 -0
  190. package/internal/otel/propagator.ts +68 -0
  191. package/internal/otel/provider.ts +23 -0
  192. package/internal/otel/request_context.ts +32 -0
  193. package/internal/otel/span.ts +252 -0
  194. package/internal/otel/tracer.test.ts +352 -0
  195. package/internal/otel/tracer.ts +104 -0
  196. package/internal/reqtrack/mod.ts +39 -0
  197. package/internal/runtime/meter.ts +26 -0
  198. package/internal/runtime/mod.ts +41 -0
  199. package/internal/runtime/napi/napi.cjs +122 -0
  200. package/internal/runtime/napi/napi.d.cts +601 -0
  201. package/internal/runtime/shutdown.test.ts +248 -0
  202. package/internal/runtime/shutdown.ts +64 -0
  203. package/internal/utils/constraints.ts +12 -0
  204. package/log/index.ts +107 -0
  205. package/log/logger.test.ts +194 -0
  206. package/log/logger.ts +308 -0
  207. package/log/runtime.test.ts +65 -0
  208. package/log/runtime.ts +40 -0
  209. package/log/stderr.test.ts +23 -0
  210. package/log/stderr.ts +24 -0
  211. package/metrics/export.test.ts +337 -0
  212. package/metrics/mod.test.ts +180 -0
  213. package/metrics/mod.ts +619 -0
  214. package/mod.ts +22 -0
  215. package/otel.test.ts +84 -0
  216. package/otel.ts +17 -0
  217. package/package.json +121 -5
  218. package/pubsub/encoding.ts +8 -0
  219. package/pubsub/mod.ts +14 -0
  220. package/pubsub/pubsub.test.ts +186 -0
  221. package/pubsub/refs.ts +22 -0
  222. package/pubsub/subscription.ts +180 -0
  223. package/pubsub/topic.test.ts +121 -0
  224. package/pubsub/topic.ts +212 -0
  225. package/req_meta.ts +75 -0
  226. package/services/index.test.ts +30 -0
  227. package/services/index.ts +21 -0
  228. package/shutdown/mod.ts +24 -0
  229. package/storage/objects/bucket.ts +338 -0
  230. package/storage/objects/error.ts +94 -0
  231. package/storage/objects/mod.ts +35 -0
  232. package/storage/objects/refs.ts +69 -0
  233. package/storage/postgres/database.integration.test.ts +175 -0
  234. package/storage/postgres/database.test.ts +241 -0
  235. package/storage/postgres/database.ts +497 -0
  236. package/storage/postgres/mod.ts +15 -0
  237. package/storage/redis/commands.ts +1221 -0
  238. package/storage/redis/database.ts +466 -0
  239. package/storage/redis/mod.ts +135 -0
  240. package/storage/redis/native.ts +11 -0
  241. package/storage/redis/options.ts +119 -0
  242. package/storage/redis/pubsub.ts +92 -0
  243. package/storage/redis/redis.test.ts +706 -0
  244. package/storage/redis/reply.ts +705 -0
  245. package/storage/redis/runtime.test.ts +233 -0
  246. package/storage/redis/scan.ts +125 -0
  247. package/storage/redis/script.ts +162 -0
  248. package/storage/redis/target.ts +131 -0
  249. package/storage/redis/wire.ts +369 -0
  250. package/types/mod.ts +92 -0
@@ -0,0 +1,601 @@
1
+ /* tslint:disable */
2
+ /* eslint:disable */
3
+ // Automatically generated by gen_type_defs. Do not edit.
4
+
5
+ export interface AppMeta {
6
+ appId: string
7
+ appSlug: string
8
+ /** The API gateways serving the application, keyed by gateway name. */
9
+ gateways: Record<string, GatewayMeta>
10
+ environment: EnvironmentMeta
11
+ build: BuildMeta
12
+ deploy: DeployMeta
13
+ }
14
+
15
+ export interface AttrsOptions {
16
+ version?: string
17
+ }
18
+
19
+ export class Bucket {
20
+ object(name: string): BucketObject
21
+ list(options?: ListOptions | undefined | null, source?: Buffer | undefined | null): Promise<ListIterator | TypedObjectError>
22
+ }
23
+
24
+ export class BucketObject {
25
+ attrs(options?: AttrsOptions | undefined | null, source?: Buffer | undefined | null): Promise<ObjectAttrs | TypedObjectError>
26
+ exists(options?: ExistsOptions | undefined | null, source?: Buffer | undefined | null): Promise<boolean | TypedObjectError>
27
+ upload(data: Buffer, opts?: UploadOptions | undefined | null, source?: Buffer | undefined | null): Promise<ObjectAttrs | TypedObjectError>
28
+ signedUploadUrl(options?: UploadUrlOptions | undefined | null, source?: Buffer | undefined | null): Promise<SignedUploadUrl | TypedObjectError>
29
+ signedDownloadUrl(options?: DownloadUrlOptions | undefined | null, source?: Buffer | undefined | null): Promise<SignedDownloadUrl | TypedObjectError>
30
+ downloadAll(options?: DownloadOptions | undefined | null, source?: Buffer | undefined | null): Promise<Buffer | TypedObjectError>
31
+ delete(options?: DeleteOptions | undefined | null, source?: Buffer | undefined | null): Promise<TypedObjectError | null>
32
+ publicUrl(): string
33
+ }
34
+
35
+ export interface BuildMeta {
36
+ revision: string
37
+ }
38
+
39
+ export interface ByteRange {
40
+ offset: number
41
+ length?: number
42
+ }
43
+
44
+ export enum CloudProvider {
45
+ AWS = 0,
46
+ GCP = 1,
47
+ Azure = 2,
48
+ Encore = 3,
49
+ Local = 4
50
+ }
51
+
52
+ /** What a JS thread's collector replies with, once. */
53
+ export class CollectReply {
54
+ /**
55
+ * The milliseconds left to send in: the collection goes on without
56
+ * what is sent later.
57
+ */
58
+ get timeout(): number
59
+ /**
60
+ * Sends the thread's observations: the `i`th is `values[i]` for the
61
+ * observable instrument `ids[i]`, with the attributes `attrs[i]`, a
62
+ * JSON object's text. Later calls do nothing.
63
+ */
64
+ send(ids: Array<number>, values: Array<number>, attrs: Array<string>): void
65
+ }
66
+
67
+ export class Config {
68
+ /** The value now. */
69
+ current(): ConfigRevision
70
+ /**
71
+ * The revision number now, cheaper than [`Config::current`] for telling
72
+ * whether a cached value is still current.
73
+ */
74
+ revision(): number
75
+ /** The config's JSON Schema, as JSON text. */
76
+ schema(): string
77
+ /**
78
+ * Calls `handler` on the event loop with each revision the value gets
79
+ * from now on, the revision's own value with it: the value now may be a
80
+ * later one by the time the handler runs. Revisions that come faster
81
+ * than the watch sees them are coalesced to the latest; each is passed
82
+ * once, in order. Does not keep the process alive. Stop it with the
83
+ * returned watch's `stop`.
84
+ */
85
+ onChange(handler: (revision: ConfigRevision) => void): ConfigWatch
86
+ }
87
+
88
+ /** A config's value at one point. */
89
+ export interface ConfigRevision {
90
+ /** Counts up from 0, the value the process started with. */
91
+ number: number
92
+ /**
93
+ * The value, as JSON text, with a placeholder
94
+ * (`{"$encore_secret": {"name", "scope"}}`) for each secret field.
95
+ */
96
+ value: string
97
+ }
98
+
99
+ /** Being told of a config's changes, until stopped. */
100
+ export class ConfigWatch {
101
+ /** Stops the calls. */
102
+ stop(): void
103
+ }
104
+
105
+ export class Cursor {
106
+ next(): Promise<Row | null>
107
+ rowsAffected(): Promise<bigint>
108
+ close(): Promise<void>
109
+ }
110
+
111
+ export class Decimal {
112
+ constructor(value: string)
113
+ toString(): string
114
+ add(other: Decimal): Decimal
115
+ sub(other: Decimal): Decimal
116
+ mul(other: Decimal): Decimal
117
+ div(other: Decimal): Decimal
118
+ }
119
+
120
+ export interface DeleteOptions {
121
+ version?: string
122
+ }
123
+
124
+ export interface DeployMeta {
125
+ id: string
126
+ deployTime: string
127
+ hostedServices: Record<string, HostedService>
128
+ }
129
+
130
+ export interface DownloadOptions {
131
+ version?: string
132
+ range?: ByteRange
133
+ }
134
+
135
+ export interface DownloadUrlOptions {
136
+ ttl?: number
137
+ }
138
+
139
+ export interface EnvironmentMeta {
140
+ name: string
141
+ type: EnvironmentType
142
+ cloud: CloudProvider
143
+ }
144
+
145
+ export enum EnvironmentType {
146
+ Production = 0,
147
+ Development = 1,
148
+ Ephemeral = 2,
149
+ Test = 3
150
+ }
151
+
152
+ export interface ExistsOptions {
153
+ version?: string
154
+ }
155
+
156
+ export interface GatewayMeta {
157
+ name: string
158
+ baseUrl: string
159
+ }
160
+
161
+ export interface HostedService {
162
+ name: string
163
+ }
164
+
165
+ /** A registered instrument. */
166
+ export class Instrument {
167
+ /** Identifies an observable instrument's observations. */
168
+ get id(): number
169
+ /**
170
+ * Records `value` with `attrs`, a JSON object's text, taken in the
171
+ * span `span` (a 25-byte context). A measurement the instrument cannot
172
+ * take is dropped.
173
+ */
174
+ record(value: number, attrs?: string, span?: Buffer): void
175
+ }
176
+
177
+ /** An instrument to register, in its meter's instrumentation scope. */
178
+ export interface InstrumentOptions {
179
+ scopeName: string
180
+ scopeVersion?: string
181
+ scopeSchemaUrl?: string
182
+ /**
183
+ * 0 counter, 1 up-down counter, 2 histogram, 3 gauge, 4 observable
184
+ * counter, 5 observable up-down counter, 6 observable gauge.
185
+ */
186
+ kind: number
187
+ /** 0 `i64`, 1 `u64`, 2 `f64`. */
188
+ number: number
189
+ name: string
190
+ unit?: string
191
+ description?: string
192
+ /** A histogram's advisory explicit bucket boundaries. */
193
+ boundaries?: Array<number>
194
+ }
195
+
196
+ export class ListEntry {
197
+ name: string
198
+ size: number
199
+ etag: string
200
+ }
201
+
202
+ export class ListIterator {
203
+ next(): Promise<ListEntry | null>
204
+ markDone(): void
205
+ }
206
+
207
+ export interface ListOptions {
208
+ prefix?: string
209
+ limit?: number
210
+ }
211
+
212
+ /** The meter provider, as JS registers instruments with it. */
213
+ export class Meters {
214
+ /**
215
+ * Registers an instrument. One identical to another shares its
216
+ * aggregation; every instrument records nothing when metrics are not
217
+ * exported.
218
+ */
219
+ instrument(opts: InstrumentOptions): Instrument
220
+ /**
221
+ * Adds this JS thread's collector, which a collection calls on the
222
+ * thread's event loop with a [`CollectReply`] to send every
223
+ * observation of the thread's observable instruments with. Does not
224
+ * keep the thread alive.
225
+ */
226
+ addCollector(collect: (reply: CollectReply) => void): void
227
+ }
228
+
229
+ export class ObjectAttrs {
230
+ name: string
231
+ version?: string
232
+ size: number
233
+ contentType?: string
234
+ etag: string
235
+ }
236
+
237
+ export enum ObjectErrorKind {
238
+ NotFound = 0,
239
+ PreconditionFailed = 1,
240
+ InvalidArgument = 2,
241
+ Other = 3,
242
+ Internal = 4
243
+ }
244
+
245
+ /** Span lifecycle calls into the telemetry pipeline. */
246
+ export class Pipeline {
247
+ /**
248
+ * Starts a span. `parent`: 25-byte context, with `tracestate`.
249
+ * `packed`: start scope, attributes, and links in the packed layout.
250
+ */
251
+ startSpan(name: string, kind: number, parent: Buffer | undefined | null, tracestate: string | undefined | null, startUnixNanos: bigint | undefined | null, packed: Buffer): SpanStartResult
252
+ /** Ends a span. `packed`: the finished span in the packed layout. */
253
+ endSpan(packed: Buffer): void
254
+ /** The number of telemetry items dropped because the queue was full. */
255
+ dropped(): bigint
256
+ }
257
+
258
+ /**
259
+ * A PubSub message delivered to a subscription handler.
260
+ *
261
+ * Carries the core message attributes. The payload is exposed as raw bytes
262
+ * via `data`; callers are responsible for deserializing it themselves.
263
+ */
264
+ export class PubSubMessage {
265
+ /** The unique message id assigned by the cloud provider. */
266
+ get id(): string
267
+ /** The raw message payload bytes. */
268
+ get data(): Buffer
269
+ /** The message attributes set when publishing. */
270
+ get attributes(): Record<string, string>
271
+ /** The key it was published with, on an ordered topic. */
272
+ get orderingKey(): string | null
273
+ /** The delivery attempt for this message, starting at 1. */
274
+ get deliveryAttempt(): number
275
+ /** The time the message was published. */
276
+ get publishTime(): Date
277
+ }
278
+
279
+ export interface PubSubMessageData {
280
+ service: string
281
+ topic: string
282
+ subscription: string
283
+ id: string
284
+ deliveryAttempt: number
285
+ }
286
+
287
+ export class PubSubSubscription {
288
+ subscribe(): Promise<void>
289
+ }
290
+
291
+ export interface PubSubSubscriptionConfig {
292
+ topicName: string
293
+ subscriptionName: string
294
+ handler: (...args: any[]) => any
295
+ }
296
+
297
+ export class PubSubTopic {
298
+ /**
299
+ * Publish a message. `data` is the raw payload, delivered to subscribers
300
+ * verbatim, with its `attributes`. `orderingKey` is the message's ordering
301
+ * key, which an ordered topic's message needs and an unordered topic's
302
+ * cannot have.
303
+ */
304
+ publish(data: Buffer, attributes?: Record<string, string> | undefined | null, source?: Buffer | undefined | null, orderingKey?: string | undefined | null): Promise<string>
305
+ }
306
+
307
+ export class QueryArgs {
308
+ constructor(params: Array<unknown>)
309
+ }
310
+
311
+ /**
312
+ * A connection taken out of a database's pool, until it is released. Its
313
+ * commands run one at a time.
314
+ */
315
+ export class RedisConnection {
316
+ /** [`RedisDatabase::execute`], on this connection. */
317
+ execute(cmd: Buffer, source?: Buffer | undefined | null): Promise<Buffer>
318
+ /**
319
+ * [`RedisDatabase::execute_each`], on this connection. `null` for a
320
+ * transaction that did not run because a watched key changed.
321
+ */
322
+ executeEach(batch: Buffer, atomic: boolean, source?: Buffer | undefined | null): Promise<Buffer | null>
323
+ /** Watches the encoded list of `keys`. */
324
+ watch(keys: Buffer, source?: Buffer | undefined | null): Promise<void>
325
+ /** Stops watching every key. */
326
+ unwatch(source?: Buffer | undefined | null): Promise<void>
327
+ /**
328
+ * Returns the connection to its pool. Keys it still watches are unwatched
329
+ * first, which is why it is dropped here, on the runtime, rather than
330
+ * whenever JavaScript collects it.
331
+ */
332
+ release(): Promise<void>
333
+ }
334
+
335
+ /** A Redis database, its client opened on first use. */
336
+ export class RedisDatabase {
337
+ /** The prefix every key of the database is stored under, if it has one. */
338
+ keyPrefix(): string | null
339
+ /**
340
+ * The URL a client other than this one connects to the database with,
341
+ * past its key prefix.
342
+ */
343
+ connectionUrl(): string
344
+ /** Runs an encoded command, resolving to its encoded reply. */
345
+ execute(cmd: Buffer, source?: Buffer | undefined | null): Promise<Buffer>
346
+ /**
347
+ * Runs an encoded batch in one round trip, as a transaction if `atomic`,
348
+ * resolving to the replies as one encoded array. A command the server
349
+ * rejects fails alone: its reply is the error.
350
+ */
351
+ executeEach(batch: Buffer, atomic: boolean, source?: Buffer | undefined | null): Promise<Buffer>
352
+ /** Takes a connection out of the pool. */
353
+ acquire(source?: Buffer | undefined | null): Promise<RedisConnection>
354
+ /**
355
+ * Subscribes to the encoded lists of `channels` and `patterns`, on a
356
+ * connection of its own.
357
+ */
358
+ subscribe(channels: Buffer, patterns: Buffer, source?: Buffer | undefined | null): Promise<RedisSubscription>
359
+ }
360
+
361
+ /** A message published to a channel. */
362
+ export interface RedisMessage {
363
+ /** The channel, without the database's prefix. */
364
+ channel: Buffer
365
+ payload: Buffer
366
+ }
367
+
368
+ /** An open subscription, on a connection of its own. */
369
+ export class RedisSubscription {
370
+ /** The next message, or `null` once the subscription is closed. */
371
+ next(): Promise<RedisMessage | null>
372
+ /**
373
+ * Closes the subscription and its connection, which unsubscribes: a
374
+ * waiting `next`, and any later one, returns `null`.
375
+ */
376
+ close(): Promise<void>
377
+ }
378
+
379
+ export class Request {
380
+ meta(): RequestMeta
381
+ /** The request's span context; null if the request arrived without one. */
382
+ spanContext(): SpanContextData | null
383
+ }
384
+
385
+ export interface RequestMeta {
386
+ trace?: TraceData
387
+ pubsubMessage: PubSubMessageData
388
+ }
389
+
390
+ export class Row {
391
+ values(): Record<string, unknown>
392
+ }
393
+
394
+ export class Runtime {
395
+ constructor(options: RuntimeOptions)
396
+ /**
397
+ * Runs until shutdown completes, returning the process exit code: waits
398
+ * for a shutdown signal, then drains the infrastructure integrations. A
399
+ * `cooperative` shutdown cleans up once the app has drained its own work
400
+ * too ([`Runtime::mark_application_drained`]), or the deadline passed.
401
+ * The JS caller exits the process from Node's main thread with the
402
+ * returned code.
403
+ */
404
+ runForever(cooperative?: boolean | undefined | null): Promise<number>
405
+ /**
406
+ * Starts the shutdown once; the first call chooses the mode. A
407
+ * cooperative shutdown waits for [`Runtime::mark_application_drained`]
408
+ * (or the deadline) before cleanup.
409
+ */
410
+ beginShutdown(cooperative: boolean): void
411
+ /** Tells the runtime the application has drained its work. */
412
+ markApplicationDrained(): void
413
+ /**
414
+ * Waits for cleanup to complete after [`Runtime::begin_shutdown`],
415
+ * returning the process exit code: 0 when it finished within the
416
+ * deadline, else 1.
417
+ */
418
+ shutdownCompleted(): Promise<number>
419
+ sqlDatabase(encoreName: string): SqlDatabase
420
+ pubsubTopic(encoreName: string): PubSubTopic
421
+ bucket(encoreName: string): Bucket
422
+ redisDatabase(encoreName: string): RedisDatabase
423
+ pubsubSubscription(cfg: PubSubSubscriptionConfig): PubSubSubscription
424
+ /**
425
+ * A config belonging to the service this process hosts, if the runtime
426
+ * config has one of the name. An app-wide config of the same name is
427
+ * deliberately not consulted: the namespaces are separate.
428
+ */
429
+ config(encoreName: string): Config | null
430
+ /** A shared or global config, if the runtime config has one of the name. */
431
+ sharedConfig(encoreName: string): Config | null
432
+ /**
433
+ * The secret given to the service this process hosts, whatever its scope:
434
+ * a name has one scope across the app.
435
+ */
436
+ secret(encoreName: string): Secret | null
437
+ /** The telemetry pipeline's span lifecycle calls. */
438
+ telemetry(): Pipeline
439
+ /** The meter provider's instrument calls. */
440
+ meters(): Meters
441
+ /** Returns the version of the Encore runtime being used */
442
+ static version(): string
443
+ /** Returns the git commit hash used to build the Encore runtime */
444
+ static buildCommit(): string
445
+ appMeta(): AppMeta
446
+ runtimeConfig(): RuntimeConfig
447
+ }
448
+
449
+ export interface RuntimeConfig {
450
+ /** The service hosted by this process, if any. */
451
+ currentService?: string
452
+ /**
453
+ * Base URLs of the services this process can reach, keyed by service
454
+ * name.
455
+ */
456
+ services: Record<string, string>
457
+ }
458
+
459
+ /** One runtime log line. */
460
+ export interface RuntimeLogLine {
461
+ /** 1 ERROR, 2 WARN, 3 INFO, 4 DEBUG, 5 TRACE. */
462
+ level: number
463
+ /** The module path, or `file:line`, the line comes from. */
464
+ target: string
465
+ message: string
466
+ /** A JSON object of key-values, `exception.*` included. */
467
+ fields: string
468
+ /** The current span's 25-byte context when the line was logged. */
469
+ spanCtx?: Buffer
470
+ }
471
+
472
+ export interface RuntimeOptions {
473
+ testMode?: boolean
474
+ typeConstructors: RuntimeTypeConstructors
475
+ }
476
+
477
+ export interface RuntimeTypeConstructors {
478
+ decimal: (...args: any[]) => any
479
+ }
480
+
481
+ /**
482
+ * What a database handle may do, which decides the connections its statements
483
+ * run on. See [`postgres::Access`].
484
+ */
485
+ export enum SQLAccess {
486
+ /** Read and write, on the primary: a write or admin handle. */
487
+ ReadWrite = 0,
488
+ /** Read only, from a read replica if the database has a read-only pool on one. */
489
+ Read = 1,
490
+ /** Read only, from the primary. */
491
+ ReadPrimary = 2
492
+ }
493
+
494
+ export class Secret {
495
+ /** Returns the cached value of the secret. */
496
+ cached(): string
497
+ }
498
+
499
+ export interface SignedDownloadUrl {
500
+ url: string
501
+ }
502
+
503
+ export interface SignedUploadUrl {
504
+ url: string
505
+ }
506
+
507
+ export interface SpanContextData {
508
+ /** 25-byte context: trace id, span id, trace flags. */
509
+ ctx: Buffer
510
+ tracestate: string
511
+ }
512
+
513
+ export interface SpanStartResult {
514
+ /** The span's 25-byte context. */
515
+ ctx: Buffer
516
+ tracestate: string
517
+ startUnixNanos: bigint
518
+ startMonoNanos: bigint
519
+ }
520
+
521
+ export class SqlConn {
522
+ close(): Promise<void>
523
+ begin(source?: Buffer | undefined | null): Promise<Transaction>
524
+ query(query: string, args: QueryArgs, source?: Buffer | undefined | null): Promise<Cursor>
525
+ }
526
+ export type SQLConn = SqlConn
527
+
528
+ /** A handle to a database for one access level: see [`SQLDatabase::with_access`]. */
529
+ export class SqlDatabase {
530
+ /**
531
+ * A handle to the database for `access`, sharing this one's pool. A read
532
+ * handle runs on read-only connections: a statement that writes fails
533
+ * with SQLSTATE 25006, and the transactions it begins are read-only. See
534
+ * [`postgres::Pool::with_access`].
535
+ */
536
+ withAccess(access: SQLAccess): SqlDatabase
537
+ /**
538
+ * Reports the connection string to connect to this database with the
539
+ * handle's access. A read handle's connects as its statements run, its
540
+ * session read-only: see [`postgres::Database::proxy_conn_string`].
541
+ */
542
+ connString(): string
543
+ /** Begins a transaction */
544
+ begin(source?: Buffer | undefined | null): Promise<Transaction>
545
+ query(query: string, args: QueryArgs, source?: Buffer | undefined | null): Promise<Cursor>
546
+ acquire(): Promise<SQLConn>
547
+ }
548
+ export type SQLDatabase = SqlDatabase
549
+
550
+ export interface TraceData {
551
+ traceId: string
552
+ spanId: string
553
+ }
554
+
555
+ export class Transaction {
556
+ isClosed(): boolean
557
+ commit(): Promise<void>
558
+ rollback(): Promise<void>
559
+ query(query: string, args: QueryArgs, source?: Buffer | undefined | null): Promise<Cursor>
560
+ }
561
+
562
+ export class TypedObjectError {
563
+ kind: ObjectErrorKind
564
+ message: string
565
+ }
566
+
567
+ export interface UploadOptions {
568
+ contentType?: string
569
+ preconditions?: UploadPreconditions
570
+ }
571
+
572
+ export interface UploadPreconditions {
573
+ notExists?: boolean
574
+ }
575
+
576
+ export interface UploadUrlOptions {
577
+ ttl?: number
578
+ }
579
+
580
+ /**
581
+ * One log record in the Encore log format, newline included, for the
582
+ * logger to print. Absent, empty, and 0 are none. `level` is the
583
+ * OpenTelemetry severity number, 1–24; `time_unix_millis` absent is now;
584
+ * `span_ctx` is the span's 25-byte context: trace id, span id, flags;
585
+ * `exception_stacktrace` is in JavaScript's format; `code_*` are the
586
+ * caller's function, source file, line, and column; `runtime_target` is
587
+ * the runtime module a line of the runtime's own comes from, logged under
588
+ * the runtime's logger in place of `logger`; `attrs_json` is a JSON object
589
+ * of the user's attributes. An attribute named like a reserved key is that
590
+ * field when valid, `raw.<key>` otherwise; one named like a key of the
591
+ * record's own fields is `raw.<key>`. Needs no runtime.
592
+ */
593
+ export declare function encodeLog(level: number, timeUnixMillis: number | undefined | null, message: string, logger?: string | undefined | null, spanCtx?: Buffer | undefined | null, exceptionType?: string | undefined | null, exceptionMessage?: string | undefined | null, exceptionStacktrace?: string | undefined | null, codeFunction?: string | undefined | null, codeFile?: string | undefined | null, codeLine?: number | undefined | null, codeColumn?: number | undefined | null, runtimeTarget?: string | undefined | null, attrsJson?: string | undefined | null): Buffer
594
+
595
+ /**
596
+ * Hands the runtime's own log lines to `handler` on the event loop, or
597
+ * drops them for `null`. Lines logged before the first call are handed
598
+ * over first. Does not keep the process alive.
599
+ */
600
+ export declare function setRuntimeLogHandler(handler: ((line: RuntimeLogLine) => void) | null): void
601
+