@nextclaw/app-runtime 0.14.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/index.d.ts +5 -4
  2. package/dist/index.js +2 -1
  3. package/dist/package.js +1 -1
  4. package/dist/services/app-build.service.d.ts +1 -0
  5. package/dist/services/app-build.service.d.ts.map +1 -1
  6. package/dist/services/app-build.service.js +37 -2
  7. package/dist/services/app-build.service.js.map +1 -1
  8. package/dist/services/app-grant.service.d.ts.map +1 -1
  9. package/dist/services/app-grant.service.js +1 -4
  10. package/dist/services/app-grant.service.js.map +1 -1
  11. package/dist/services/app-installation-lifecycle.service.js +29 -2
  12. package/dist/services/app-installation-lifecycle.service.js.map +1 -1
  13. package/dist/services/app-manifest.service.d.ts +1 -0
  14. package/dist/services/app-manifest.service.d.ts.map +1 -1
  15. package/dist/services/app-manifest.service.js +27 -0
  16. package/dist/services/app-manifest.service.js.map +1 -1
  17. package/dist/services/app-permissions.service.d.ts.map +1 -1
  18. package/dist/services/app-permissions.service.js +0 -3
  19. package/dist/services/app-permissions.service.js.map +1 -1
  20. package/dist/services/app-registry-parser.service.js +200 -0
  21. package/dist/services/app-registry-parser.service.js.map +1 -0
  22. package/dist/services/app-registry.service.d.ts +4 -9
  23. package/dist/services/app-registry.service.d.ts.map +1 -1
  24. package/dist/services/app-registry.service.js +40 -164
  25. package/dist/services/app-registry.service.js.map +1 -1
  26. package/dist/services/app-runtime-cli.service.js +1 -1
  27. package/dist/services/app-runtime-cli.service.js.map +1 -1
  28. package/dist/services/app-runtime-options.service.d.ts.map +1 -1
  29. package/dist/services/app-runtime-options.service.js +2 -2
  30. package/dist/services/app-runtime-options.service.js.map +1 -1
  31. package/dist/services/app-runtime-toolchain.service.d.ts +5 -2
  32. package/dist/services/app-runtime-toolchain.service.d.ts.map +1 -1
  33. package/dist/services/app-runtime-toolchain.service.js +36 -4
  34. package/dist/services/app-runtime-toolchain.service.js.map +1 -1
  35. package/dist/services/app-rust-wasi-scaffold-template.service.d.ts +24 -0
  36. package/dist/services/app-rust-wasi-scaffold-template.service.d.ts.map +1 -0
  37. package/dist/services/app-rust-wasi-scaffold-template.service.js +394 -0
  38. package/dist/services/app-rust-wasi-scaffold-template.service.js.map +1 -0
  39. package/dist/services/app-scaffold.service.d.ts +4 -2
  40. package/dist/services/app-scaffold.service.d.ts.map +1 -1
  41. package/dist/services/app-scaffold.service.js +20 -4
  42. package/dist/services/app-scaffold.service.js.map +1 -1
  43. package/dist/services/platform-auth-state.service.js +1 -1
  44. package/dist/types/app-manifest.types.d.ts +8 -1
  45. package/dist/types/app-manifest.types.d.ts.map +1 -1
  46. package/dist/types/app-manifest.types.js.map +1 -1
  47. package/dist/types/app-registry.types.d.ts +8 -1
  48. package/dist/types/app-registry.types.d.ts.map +1 -1
  49. package/package.json +2 -1
  50. package/resources/rust-wasi/Cargo.lock +454 -0
  51. package/resources/wit/deps/clocks@0.2.6/monotonic-clock.wit +50 -0
  52. package/resources/wit/deps/clocks@0.2.6/timezone.wit +55 -0
  53. package/resources/wit/deps/clocks@0.2.6/wall-clock.wit +46 -0
  54. package/resources/wit/deps/clocks@0.2.6/world.wit +11 -0
  55. package/resources/wit/deps/config@0.2.0-draft-2024-09-27/package.wit +1 -0
  56. package/resources/wit/deps/config@0.2.0-draft-2024-09-27/store.wit +9 -0
  57. package/resources/wit/deps/http@0.2.6/handler.wit +49 -0
  58. package/resources/wit/deps/http@0.2.6/package.wit +1 -0
  59. package/resources/wit/deps/http@0.2.6/types.wit +688 -0
  60. package/resources/wit/deps/io@0.2.6/error.wit +34 -0
  61. package/resources/wit/deps/io@0.2.6/poll.wit +47 -0
  62. package/resources/wit/deps/io@0.2.6/streams.wit +290 -0
  63. package/resources/wit/deps/io@0.2.6/world.wit +10 -0
  64. package/resources/wit/deps/spin@2.0.0/package.wit +1 -0
  65. package/resources/wit/deps/spin@2.0.0/sqlite.wit +50 -0
  66. package/resources/wit/portable-service.wit +120 -0
@@ -0,0 +1,688 @@
1
+ /// This interface defines all of the types and methods for implementing
2
+ /// HTTP Requests and Responses, both incoming and outgoing, as well as
3
+ /// their headers, trailers, and bodies.
4
+ @since(version = 0.2.0)
5
+ interface types {
6
+ @since(version = 0.2.0)
7
+ use wasi:clocks/monotonic-clock@0.2.6.{duration};
8
+ @since(version = 0.2.0)
9
+ use wasi:io/streams@0.2.6.{input-stream, output-stream};
10
+ @since(version = 0.2.0)
11
+ use wasi:io/error@0.2.6.{error as io-error};
12
+ @since(version = 0.2.0)
13
+ use wasi:io/poll@0.2.6.{pollable};
14
+
15
+ /// This type corresponds to HTTP standard Methods.
16
+ @since(version = 0.2.0)
17
+ variant method {
18
+ get,
19
+ head,
20
+ post,
21
+ put,
22
+ delete,
23
+ connect,
24
+ options,
25
+ trace,
26
+ patch,
27
+ other(string)
28
+ }
29
+
30
+ /// This type corresponds to HTTP standard Related Schemes.
31
+ @since(version = 0.2.0)
32
+ variant scheme {
33
+ HTTP,
34
+ HTTPS,
35
+ other(string)
36
+ }
37
+
38
+ /// These cases are inspired by the IANA HTTP Proxy Error Types:
39
+ /// <https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types>
40
+ @since(version = 0.2.0)
41
+ variant error-code {
42
+ DNS-timeout,
43
+ DNS-error(DNS-error-payload),
44
+ destination-not-found,
45
+ destination-unavailable,
46
+ destination-IP-prohibited,
47
+ destination-IP-unroutable,
48
+ connection-refused,
49
+ connection-terminated,
50
+ connection-timeout,
51
+ connection-read-timeout,
52
+ connection-write-timeout,
53
+ connection-limit-reached,
54
+ TLS-protocol-error,
55
+ TLS-certificate-error,
56
+ TLS-alert-received(TLS-alert-received-payload),
57
+ HTTP-request-denied,
58
+ HTTP-request-length-required,
59
+ HTTP-request-body-size(option<u64>),
60
+ HTTP-request-method-invalid,
61
+ HTTP-request-URI-invalid,
62
+ HTTP-request-URI-too-long,
63
+ HTTP-request-header-section-size(option<u32>),
64
+ HTTP-request-header-size(option<field-size-payload>),
65
+ HTTP-request-trailer-section-size(option<u32>),
66
+ HTTP-request-trailer-size(field-size-payload),
67
+ HTTP-response-incomplete,
68
+ HTTP-response-header-section-size(option<u32>),
69
+ HTTP-response-header-size(field-size-payload),
70
+ HTTP-response-body-size(option<u64>),
71
+ HTTP-response-trailer-section-size(option<u32>),
72
+ HTTP-response-trailer-size(field-size-payload),
73
+ HTTP-response-transfer-coding(option<string>),
74
+ HTTP-response-content-coding(option<string>),
75
+ HTTP-response-timeout,
76
+ HTTP-upgrade-failed,
77
+ HTTP-protocol-error,
78
+ loop-detected,
79
+ configuration-error,
80
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
81
+ /// more specific case. It also includes an optional string for an
82
+ /// unstructured description of the error. Users should not depend on the
83
+ /// string for diagnosing errors, as it's not required to be consistent
84
+ /// between implementations.
85
+ internal-error(option<string>)
86
+ }
87
+
88
+ /// Defines the case payload type for `DNS-error` above:
89
+ @since(version = 0.2.0)
90
+ record DNS-error-payload {
91
+ rcode: option<string>,
92
+ info-code: option<u16>
93
+ }
94
+
95
+ /// Defines the case payload type for `TLS-alert-received` above:
96
+ @since(version = 0.2.0)
97
+ record TLS-alert-received-payload {
98
+ alert-id: option<u8>,
99
+ alert-message: option<string>
100
+ }
101
+
102
+ /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
103
+ @since(version = 0.2.0)
104
+ record field-size-payload {
105
+ field-name: option<string>,
106
+ field-size: option<u32>
107
+ }
108
+
109
+ /// Attempts to extract a http-related `error` from the wasi:io `error`
110
+ /// provided.
111
+ ///
112
+ /// Stream operations which return
113
+ /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of
114
+ /// type `wasi:io/error/error` with more information about the operation
115
+ /// that failed. This payload can be passed through to this function to see
116
+ /// if there's http-related information about the error to return.
117
+ ///
118
+ /// Note that this function is fallible because not all io-errors are
119
+ /// http-related errors.
120
+ @since(version = 0.2.0)
121
+ http-error-code: func(err: borrow<io-error>) -> option<error-code>;
122
+
123
+ /// This type enumerates the different kinds of errors that may occur when
124
+ /// setting or appending to a `fields` resource.
125
+ @since(version = 0.2.0)
126
+ variant header-error {
127
+ /// This error indicates that a `field-name` or `field-value` was
128
+ /// syntactically invalid when used with an operation that sets headers in a
129
+ /// `fields`.
130
+ invalid-syntax,
131
+
132
+ /// This error indicates that a forbidden `field-name` was used when trying
133
+ /// to set a header in a `fields`.
134
+ forbidden,
135
+
136
+ /// This error indicates that the operation on the `fields` was not
137
+ /// permitted because the fields are immutable.
138
+ immutable,
139
+ }
140
+
141
+ /// Field names are always strings.
142
+ ///
143
+ /// Field names should always be treated as case insensitive by the `fields`
144
+ /// resource for the purposes of equality checking.
145
+ @since(version = 0.2.1)
146
+ type field-name = field-key;
147
+
148
+ /// Field keys are always strings.
149
+ ///
150
+ /// Field keys should always be treated as case insensitive by the `fields`
151
+ /// resource for the purposes of equality checking.
152
+ ///
153
+ /// # Deprecation
154
+ ///
155
+ /// This type has been deprecated in favor of the `field-name` type.
156
+ @since(version = 0.2.0)
157
+ @deprecated(version = 0.2.2)
158
+ type field-key = string;
159
+
160
+ /// Field values should always be ASCII strings. However, in
161
+ /// reality, HTTP implementations often have to interpret malformed values,
162
+ /// so they are provided as a list of bytes.
163
+ @since(version = 0.2.0)
164
+ type field-value = list<u8>;
165
+
166
+ /// This following block defines the `fields` resource which corresponds to
167
+ /// HTTP standard Fields. Fields are a common representation used for both
168
+ /// Headers and Trailers.
169
+ ///
170
+ /// A `fields` may be mutable or immutable. A `fields` created using the
171
+ /// constructor, `from-list`, or `clone` will be mutable, but a `fields`
172
+ /// resource given by other means (including, but not limited to,
173
+ /// `incoming-request.headers`, `outgoing-request.headers`) might be
174
+ /// immutable. In an immutable fields, the `set`, `append`, and `delete`
175
+ /// operations will fail with `header-error.immutable`.
176
+ @since(version = 0.2.0)
177
+ resource fields {
178
+
179
+ /// Construct an empty HTTP Fields.
180
+ ///
181
+ /// The resulting `fields` is mutable.
182
+ @since(version = 0.2.0)
183
+ constructor();
184
+
185
+ /// Construct an HTTP Fields.
186
+ ///
187
+ /// The resulting `fields` is mutable.
188
+ ///
189
+ /// The list represents each name-value pair in the Fields. Names
190
+ /// which have multiple values are represented by multiple entries in this
191
+ /// list with the same name.
192
+ ///
193
+ /// The tuple is a pair of the field name, represented as a string, and
194
+ /// Value, represented as a list of bytes.
195
+ ///
196
+ /// An error result will be returned if any `field-name` or `field-value` is
197
+ /// syntactically invalid, or if a field is forbidden.
198
+ @since(version = 0.2.0)
199
+ from-list: static func(
200
+ entries: list<tuple<field-name,field-value>>
201
+ ) -> result<fields, header-error>;
202
+
203
+ /// Get all of the values corresponding to a name. If the name is not present
204
+ /// in this `fields` or is syntactically invalid, an empty list is returned.
205
+ /// However, if the name is present but empty, this is represented by a list
206
+ /// with one or more empty field-values present.
207
+ @since(version = 0.2.0)
208
+ get: func(name: field-name) -> list<field-value>;
209
+
210
+ /// Returns `true` when the name is present in this `fields`. If the name is
211
+ /// syntactically invalid, `false` is returned.
212
+ @since(version = 0.2.0)
213
+ has: func(name: field-name) -> bool;
214
+
215
+ /// Set all of the values for a name. Clears any existing values for that
216
+ /// name, if they have been set.
217
+ ///
218
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
219
+ ///
220
+ /// Fails with `header-error.invalid-syntax` if the `field-name` or any of
221
+ /// the `field-value`s are syntactically invalid.
222
+ @since(version = 0.2.0)
223
+ set: func(name: field-name, value: list<field-value>) -> result<_, header-error>;
224
+
225
+ /// Delete all values for a name. Does nothing if no values for the name
226
+ /// exist.
227
+ ///
228
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
229
+ ///
230
+ /// Fails with `header-error.invalid-syntax` if the `field-name` is
231
+ /// syntactically invalid.
232
+ @since(version = 0.2.0)
233
+ delete: func(name: field-name) -> result<_, header-error>;
234
+
235
+ /// Append a value for a name. Does not change or delete any existing
236
+ /// values for that name.
237
+ ///
238
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
239
+ ///
240
+ /// Fails with `header-error.invalid-syntax` if the `field-name` or
241
+ /// `field-value` are syntactically invalid.
242
+ @since(version = 0.2.0)
243
+ append: func(name: field-name, value: field-value) -> result<_, header-error>;
244
+
245
+ /// Retrieve the full set of names and values in the Fields. Like the
246
+ /// constructor, the list represents each name-value pair.
247
+ ///
248
+ /// The outer list represents each name-value pair in the Fields. Names
249
+ /// which have multiple values are represented by multiple entries in this
250
+ /// list with the same name.
251
+ ///
252
+ /// The names and values are always returned in the original casing and in
253
+ /// the order in which they will be serialized for transport.
254
+ @since(version = 0.2.0)
255
+ entries: func() -> list<tuple<field-name,field-value>>;
256
+
257
+ /// Make a deep copy of the Fields. Equivalent in behavior to calling the
258
+ /// `fields` constructor on the return value of `entries`. The resulting
259
+ /// `fields` is mutable.
260
+ @since(version = 0.2.0)
261
+ clone: func() -> fields;
262
+ }
263
+
264
+ /// Headers is an alias for Fields.
265
+ @since(version = 0.2.0)
266
+ type headers = fields;
267
+
268
+ /// Trailers is an alias for Fields.
269
+ @since(version = 0.2.0)
270
+ type trailers = fields;
271
+
272
+ /// Represents an incoming HTTP Request.
273
+ @since(version = 0.2.0)
274
+ resource incoming-request {
275
+
276
+ /// Returns the method of the incoming request.
277
+ @since(version = 0.2.0)
278
+ method: func() -> method;
279
+
280
+ /// Returns the path with query parameters from the request, as a string.
281
+ @since(version = 0.2.0)
282
+ path-with-query: func() -> option<string>;
283
+
284
+ /// Returns the protocol scheme from the request.
285
+ @since(version = 0.2.0)
286
+ scheme: func() -> option<scheme>;
287
+
288
+ /// Returns the authority of the Request's target URI, if present.
289
+ @since(version = 0.2.0)
290
+ authority: func() -> option<string>;
291
+
292
+ /// Get the `headers` associated with the request.
293
+ ///
294
+ /// The returned `headers` resource is immutable: `set`, `append`, and
295
+ /// `delete` operations will fail with `header-error.immutable`.
296
+ ///
297
+ /// The `headers` returned are a child resource: it must be dropped before
298
+ /// the parent `incoming-request` is dropped. Dropping this
299
+ /// `incoming-request` before all children are dropped will trap.
300
+ @since(version = 0.2.0)
301
+ headers: func() -> headers;
302
+
303
+ /// Gives the `incoming-body` associated with this request. Will only
304
+ /// return success at most once, and subsequent calls will return error.
305
+ @since(version = 0.2.0)
306
+ consume: func() -> result<incoming-body>;
307
+ }
308
+
309
+ /// Represents an outgoing HTTP Request.
310
+ @since(version = 0.2.0)
311
+ resource outgoing-request {
312
+
313
+ /// Construct a new `outgoing-request` with a default `method` of `GET`, and
314
+ /// `none` values for `path-with-query`, `scheme`, and `authority`.
315
+ ///
316
+ /// * `headers` is the HTTP Headers for the Request.
317
+ ///
318
+ /// It is possible to construct, or manipulate with the accessor functions
319
+ /// below, an `outgoing-request` with an invalid combination of `scheme`
320
+ /// and `authority`, or `headers` which are not permitted to be sent.
321
+ /// It is the obligation of the `outgoing-handler.handle` implementation
322
+ /// to reject invalid constructions of `outgoing-request`.
323
+ @since(version = 0.2.0)
324
+ constructor(
325
+ headers: headers
326
+ );
327
+
328
+ /// Returns the resource corresponding to the outgoing Body for this
329
+ /// Request.
330
+ ///
331
+ /// Returns success on the first call: the `outgoing-body` resource for
332
+ /// this `outgoing-request` can be retrieved at most once. Subsequent
333
+ /// calls will return error.
334
+ @since(version = 0.2.0)
335
+ body: func() -> result<outgoing-body>;
336
+
337
+ /// Get the Method for the Request.
338
+ @since(version = 0.2.0)
339
+ method: func() -> method;
340
+ /// Set the Method for the Request. Fails if the string present in a
341
+ /// `method.other` argument is not a syntactically valid method.
342
+ @since(version = 0.2.0)
343
+ set-method: func(method: method) -> result;
344
+
345
+ /// Get the combination of the HTTP Path and Query for the Request.
346
+ /// When `none`, this represents an empty Path and empty Query.
347
+ @since(version = 0.2.0)
348
+ path-with-query: func() -> option<string>;
349
+ /// Set the combination of the HTTP Path and Query for the Request.
350
+ /// When `none`, this represents an empty Path and empty Query. Fails is the
351
+ /// string given is not a syntactically valid path and query uri component.
352
+ @since(version = 0.2.0)
353
+ set-path-with-query: func(path-with-query: option<string>) -> result;
354
+
355
+ /// Get the HTTP Related Scheme for the Request. When `none`, the
356
+ /// implementation may choose an appropriate default scheme.
357
+ @since(version = 0.2.0)
358
+ scheme: func() -> option<scheme>;
359
+ /// Set the HTTP Related Scheme for the Request. When `none`, the
360
+ /// implementation may choose an appropriate default scheme. Fails if the
361
+ /// string given is not a syntactically valid uri scheme.
362
+ @since(version = 0.2.0)
363
+ set-scheme: func(scheme: option<scheme>) -> result;
364
+
365
+ /// Get the authority of the Request's target URI. A value of `none` may be used
366
+ /// with Related Schemes which do not require an authority. The HTTP and
367
+ /// HTTPS schemes always require an authority.
368
+ @since(version = 0.2.0)
369
+ authority: func() -> option<string>;
370
+ /// Set the authority of the Request's target URI. A value of `none` may be used
371
+ /// with Related Schemes which do not require an authority. The HTTP and
372
+ /// HTTPS schemes always require an authority. Fails if the string given is
373
+ /// not a syntactically valid URI authority.
374
+ @since(version = 0.2.0)
375
+ set-authority: func(authority: option<string>) -> result;
376
+
377
+ /// Get the headers associated with the Request.
378
+ ///
379
+ /// The returned `headers` resource is immutable: `set`, `append`, and
380
+ /// `delete` operations will fail with `header-error.immutable`.
381
+ ///
382
+ /// This headers resource is a child: it must be dropped before the parent
383
+ /// `outgoing-request` is dropped, or its ownership is transferred to
384
+ /// another component by e.g. `outgoing-handler.handle`.
385
+ @since(version = 0.2.0)
386
+ headers: func() -> headers;
387
+ }
388
+
389
+ /// Parameters for making an HTTP Request. Each of these parameters is
390
+ /// currently an optional timeout applicable to the transport layer of the
391
+ /// HTTP protocol.
392
+ ///
393
+ /// These timeouts are separate from any the user may use to bound a
394
+ /// blocking call to `wasi:io/poll.poll`.
395
+ @since(version = 0.2.0)
396
+ resource request-options {
397
+ /// Construct a default `request-options` value.
398
+ @since(version = 0.2.0)
399
+ constructor();
400
+
401
+ /// The timeout for the initial connect to the HTTP Server.
402
+ @since(version = 0.2.0)
403
+ connect-timeout: func() -> option<duration>;
404
+
405
+ /// Set the timeout for the initial connect to the HTTP Server. An error
406
+ /// return value indicates that this timeout is not supported.
407
+ @since(version = 0.2.0)
408
+ set-connect-timeout: func(duration: option<duration>) -> result;
409
+
410
+ /// The timeout for receiving the first byte of the Response body.
411
+ @since(version = 0.2.0)
412
+ first-byte-timeout: func() -> option<duration>;
413
+
414
+ /// Set the timeout for receiving the first byte of the Response body. An
415
+ /// error return value indicates that this timeout is not supported.
416
+ @since(version = 0.2.0)
417
+ set-first-byte-timeout: func(duration: option<duration>) -> result;
418
+
419
+ /// The timeout for receiving subsequent chunks of bytes in the Response
420
+ /// body stream.
421
+ @since(version = 0.2.0)
422
+ between-bytes-timeout: func() -> option<duration>;
423
+
424
+ /// Set the timeout for receiving subsequent chunks of bytes in the Response
425
+ /// body stream. An error return value indicates that this timeout is not
426
+ /// supported.
427
+ @since(version = 0.2.0)
428
+ set-between-bytes-timeout: func(duration: option<duration>) -> result;
429
+ }
430
+
431
+ /// Represents the ability to send an HTTP Response.
432
+ ///
433
+ /// This resource is used by the `wasi:http/incoming-handler` interface to
434
+ /// allow a Response to be sent corresponding to the Request provided as the
435
+ /// other argument to `incoming-handler.handle`.
436
+ @since(version = 0.2.0)
437
+ resource response-outparam {
438
+ /// Send an HTTP 1xx response.
439
+ ///
440
+ /// Unlike `response-outparam.set`, this does not consume the
441
+ /// `response-outparam`, allowing the guest to send an arbitrary number of
442
+ /// informational responses before sending the final response using
443
+ /// `response-outparam.set`.
444
+ ///
445
+ /// This will return an `HTTP-protocol-error` if `status` is not in the
446
+ /// range [100-199], or an `internal-error` if the implementation does not
447
+ /// support informational responses.
448
+ @unstable(feature = informational-outbound-responses)
449
+ send-informational: func(
450
+ status: u16,
451
+ headers: headers
452
+ ) -> result<_, error-code>;
453
+
454
+ /// Set the value of the `response-outparam` to either send a response,
455
+ /// or indicate an error.
456
+ ///
457
+ /// This method consumes the `response-outparam` to ensure that it is
458
+ /// called at most once. If it is never called, the implementation
459
+ /// will respond with an error.
460
+ ///
461
+ /// The user may provide an `error` to `response` to allow the
462
+ /// implementation determine how to respond with an HTTP error response.
463
+ @since(version = 0.2.0)
464
+ set: static func(
465
+ param: response-outparam,
466
+ response: result<outgoing-response, error-code>,
467
+ );
468
+ }
469
+
470
+ /// This type corresponds to the HTTP standard Status Code.
471
+ @since(version = 0.2.0)
472
+ type status-code = u16;
473
+
474
+ /// Represents an incoming HTTP Response.
475
+ @since(version = 0.2.0)
476
+ resource incoming-response {
477
+
478
+ /// Returns the status code from the incoming response.
479
+ @since(version = 0.2.0)
480
+ status: func() -> status-code;
481
+
482
+ /// Returns the headers from the incoming response.
483
+ ///
484
+ /// The returned `headers` resource is immutable: `set`, `append`, and
485
+ /// `delete` operations will fail with `header-error.immutable`.
486
+ ///
487
+ /// This headers resource is a child: it must be dropped before the parent
488
+ /// `incoming-response` is dropped.
489
+ @since(version = 0.2.0)
490
+ headers: func() -> headers;
491
+
492
+ /// Returns the incoming body. May be called at most once. Returns error
493
+ /// if called additional times.
494
+ @since(version = 0.2.0)
495
+ consume: func() -> result<incoming-body>;
496
+ }
497
+
498
+ /// Represents an incoming HTTP Request or Response's Body.
499
+ ///
500
+ /// A body has both its contents - a stream of bytes - and a (possibly
501
+ /// empty) set of trailers, indicating that the full contents of the
502
+ /// body have been received. This resource represents the contents as
503
+ /// an `input-stream` and the delivery of trailers as a `future-trailers`,
504
+ /// and ensures that the user of this interface may only be consuming either
505
+ /// the body contents or waiting on trailers at any given time.
506
+ @since(version = 0.2.0)
507
+ resource incoming-body {
508
+
509
+ /// Returns the contents of the body, as a stream of bytes.
510
+ ///
511
+ /// Returns success on first call: the stream representing the contents
512
+ /// can be retrieved at most once. Subsequent calls will return error.
513
+ ///
514
+ /// The returned `input-stream` resource is a child: it must be dropped
515
+ /// before the parent `incoming-body` is dropped, or consumed by
516
+ /// `incoming-body.finish`.
517
+ ///
518
+ /// This invariant ensures that the implementation can determine whether
519
+ /// the user is consuming the contents of the body, waiting on the
520
+ /// `future-trailers` to be ready, or neither. This allows for network
521
+ /// backpressure is to be applied when the user is consuming the body,
522
+ /// and for that backpressure to not inhibit delivery of the trailers if
523
+ /// the user does not read the entire body.
524
+ @since(version = 0.2.0)
525
+ %stream: func() -> result<input-stream>;
526
+
527
+ /// Takes ownership of `incoming-body`, and returns a `future-trailers`.
528
+ /// This function will trap if the `input-stream` child is still alive.
529
+ @since(version = 0.2.0)
530
+ finish: static func(this: incoming-body) -> future-trailers;
531
+ }
532
+
533
+ /// Represents a future which may eventually return trailers, or an error.
534
+ ///
535
+ /// In the case that the incoming HTTP Request or Response did not have any
536
+ /// trailers, this future will resolve to the empty set of trailers once the
537
+ /// complete Request or Response body has been received.
538
+ @since(version = 0.2.0)
539
+ resource future-trailers {
540
+
541
+ /// Returns a pollable which becomes ready when either the trailers have
542
+ /// been received, or an error has occurred. When this pollable is ready,
543
+ /// the `get` method will return `some`.
544
+ @since(version = 0.2.0)
545
+ subscribe: func() -> pollable;
546
+
547
+ /// Returns the contents of the trailers, or an error which occurred,
548
+ /// once the future is ready.
549
+ ///
550
+ /// The outer `option` represents future readiness. Users can wait on this
551
+ /// `option` to become `some` using the `subscribe` method.
552
+ ///
553
+ /// The outer `result` is used to retrieve the trailers or error at most
554
+ /// once. It will be success on the first call in which the outer option
555
+ /// is `some`, and error on subsequent calls.
556
+ ///
557
+ /// The inner `result` represents that either the HTTP Request or Response
558
+ /// body, as well as any trailers, were received successfully, or that an
559
+ /// error occurred receiving them. The optional `trailers` indicates whether
560
+ /// or not trailers were present in the body.
561
+ ///
562
+ /// When some `trailers` are returned by this method, the `trailers`
563
+ /// resource is immutable, and a child. Use of the `set`, `append`, or
564
+ /// `delete` methods will return an error, and the resource must be
565
+ /// dropped before the parent `future-trailers` is dropped.
566
+ @since(version = 0.2.0)
567
+ get: func() -> option<result<result<option<trailers>, error-code>>>;
568
+ }
569
+
570
+ /// Represents an outgoing HTTP Response.
571
+ @since(version = 0.2.0)
572
+ resource outgoing-response {
573
+
574
+ /// Construct an `outgoing-response`, with a default `status-code` of `200`.
575
+ /// If a different `status-code` is needed, it must be set via the
576
+ /// `set-status-code` method.
577
+ ///
578
+ /// * `headers` is the HTTP Headers for the Response.
579
+ @since(version = 0.2.0)
580
+ constructor(headers: headers);
581
+
582
+ /// Get the HTTP Status Code for the Response.
583
+ @since(version = 0.2.0)
584
+ status-code: func() -> status-code;
585
+
586
+ /// Set the HTTP Status Code for the Response. Fails if the status-code
587
+ /// given is not a valid http status code.
588
+ @since(version = 0.2.0)
589
+ set-status-code: func(status-code: status-code) -> result;
590
+
591
+ /// Get the headers associated with the Request.
592
+ ///
593
+ /// The returned `headers` resource is immutable: `set`, `append`, and
594
+ /// `delete` operations will fail with `header-error.immutable`.
595
+ ///
596
+ /// This headers resource is a child: it must be dropped before the parent
597
+ /// `outgoing-request` is dropped, or its ownership is transferred to
598
+ /// another component by e.g. `outgoing-handler.handle`.
599
+ @since(version = 0.2.0)
600
+ headers: func() -> headers;
601
+
602
+ /// Returns the resource corresponding to the outgoing Body for this Response.
603
+ ///
604
+ /// Returns success on the first call: the `outgoing-body` resource for
605
+ /// this `outgoing-response` can be retrieved at most once. Subsequent
606
+ /// calls will return error.
607
+ @since(version = 0.2.0)
608
+ body: func() -> result<outgoing-body>;
609
+ }
610
+
611
+ /// Represents an outgoing HTTP Request or Response's Body.
612
+ ///
613
+ /// A body has both its contents - a stream of bytes - and a (possibly
614
+ /// empty) set of trailers, inducating the full contents of the body
615
+ /// have been sent. This resource represents the contents as an
616
+ /// `output-stream` child resource, and the completion of the body (with
617
+ /// optional trailers) with a static function that consumes the
618
+ /// `outgoing-body` resource, and ensures that the user of this interface
619
+ /// may not write to the body contents after the body has been finished.
620
+ ///
621
+ /// If the user code drops this resource, as opposed to calling the static
622
+ /// method `finish`, the implementation should treat the body as incomplete,
623
+ /// and that an error has occurred. The implementation should propagate this
624
+ /// error to the HTTP protocol by whatever means it has available,
625
+ /// including: corrupting the body on the wire, aborting the associated
626
+ /// Request, or sending a late status code for the Response.
627
+ @since(version = 0.2.0)
628
+ resource outgoing-body {
629
+
630
+ /// Returns a stream for writing the body contents.
631
+ ///
632
+ /// The returned `output-stream` is a child resource: it must be dropped
633
+ /// before the parent `outgoing-body` resource is dropped (or finished),
634
+ /// otherwise the `outgoing-body` drop or `finish` will trap.
635
+ ///
636
+ /// Returns success on the first call: the `output-stream` resource for
637
+ /// this `outgoing-body` may be retrieved at most once. Subsequent calls
638
+ /// will return error.
639
+ @since(version = 0.2.0)
640
+ write: func() -> result<output-stream>;
641
+
642
+ /// Finalize an outgoing body, optionally providing trailers. This must be
643
+ /// called to signal that the response is complete. If the `outgoing-body`
644
+ /// is dropped without calling `outgoing-body.finalize`, the implementation
645
+ /// should treat the body as corrupted.
646
+ ///
647
+ /// Fails if the body's `outgoing-request` or `outgoing-response` was
648
+ /// constructed with a Content-Length header, and the contents written
649
+ /// to the body (via `write`) does not match the value given in the
650
+ /// Content-Length.
651
+ @since(version = 0.2.0)
652
+ finish: static func(
653
+ this: outgoing-body,
654
+ trailers: option<trailers>
655
+ ) -> result<_, error-code>;
656
+ }
657
+
658
+ /// Represents a future which may eventually return an incoming HTTP
659
+ /// Response, or an error.
660
+ ///
661
+ /// This resource is returned by the `wasi:http/outgoing-handler` interface to
662
+ /// provide the HTTP Response corresponding to the sent Request.
663
+ @since(version = 0.2.0)
664
+ resource future-incoming-response {
665
+ /// Returns a pollable which becomes ready when either the Response has
666
+ /// been received, or an error has occurred. When this pollable is ready,
667
+ /// the `get` method will return `some`.
668
+ @since(version = 0.2.0)
669
+ subscribe: func() -> pollable;
670
+
671
+ /// Returns the incoming HTTP Response, or an error, once one is ready.
672
+ ///
673
+ /// The outer `option` represents future readiness. Users can wait on this
674
+ /// `option` to become `some` using the `subscribe` method.
675
+ ///
676
+ /// The outer `result` is used to retrieve the response or error at most
677
+ /// once. It will be success on the first call in which the outer option
678
+ /// is `some`, and error on subsequent calls.
679
+ ///
680
+ /// The inner `result` represents that either the incoming HTTP Response
681
+ /// status and headers have received successfully, or that an error
682
+ /// occurred. Errors may also occur while consuming the response body,
683
+ /// but those will be reported by the `incoming-body` and its
684
+ /// `output-stream` child.
685
+ @since(version = 0.2.0)
686
+ get: func() -> option<result<result<incoming-response, error-code>>>;
687
+ }
688
+ }