@procedures/http 0.0.0-stage → 0.3.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 (80) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +118 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/address.d.ts +31 -0
  6. package/dist/address.d.ts.map +1 -0
  7. package/dist/address.js +214 -0
  8. package/dist/address.js.map +1 -0
  9. package/dist/errors.d.ts +39 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +18 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/exchange.d.ts +102 -0
  14. package/dist/exchange.d.ts.map +1 -0
  15. package/dist/exchange.js +322 -0
  16. package/dist/exchange.js.map +1 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +11 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/module.d.ts +41 -0
  22. package/dist/module.d.ts.map +1 -0
  23. package/dist/module.js +205 -0
  24. package/dist/module.js.map +1 -0
  25. package/dist/parsers.d.ts +37 -0
  26. package/dist/parsers.d.ts.map +1 -0
  27. package/dist/parsers.js +175 -0
  28. package/dist/parsers.js.map +1 -0
  29. package/dist/policy.d.ts +94 -0
  30. package/dist/policy.d.ts.map +1 -0
  31. package/dist/policy.js +140 -0
  32. package/dist/policy.js.map +1 -0
  33. package/dist/procedures/http/index.d.ts +5 -0
  34. package/dist/procedures/http/index.d.ts.map +1 -0
  35. package/dist/procedures/http/index.js +5 -0
  36. package/dist/procedures/http/index.js.map +1 -0
  37. package/dist/procedures/http/json.d.ts +14 -0
  38. package/dist/procedures/http/json.d.ts.map +1 -0
  39. package/dist/procedures/http/json.js +56 -0
  40. package/dist/procedures/http/json.js.map +1 -0
  41. package/dist/procedures/http/ndjson.d.ts +18 -0
  42. package/dist/procedures/http/ndjson.d.ts.map +1 -0
  43. package/dist/procedures/http/ndjson.js +65 -0
  44. package/dist/procedures/http/ndjson.js.map +1 -0
  45. package/dist/procedures/http/request.d.ts +14 -0
  46. package/dist/procedures/http/request.d.ts.map +1 -0
  47. package/dist/procedures/http/request.js +79 -0
  48. package/dist/procedures/http/request.js.map +1 -0
  49. package/dist/procedures/http/sse.d.ts +19 -0
  50. package/dist/procedures/http/sse.d.ts.map +1 -0
  51. package/dist/procedures/http/sse.js +66 -0
  52. package/dist/procedures/http/sse.js.map +1 -0
  53. package/dist/register.d.ts +6 -0
  54. package/dist/register.d.ts.map +1 -0
  55. package/dist/register.js +8 -0
  56. package/dist/register.js.map +1 -0
  57. package/dist/scope.d.ts +53 -0
  58. package/dist/scope.d.ts.map +1 -0
  59. package/dist/scope.js +107 -0
  60. package/dist/scope.js.map +1 -0
  61. package/dist/types.d.ts +102 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +8 -0
  64. package/dist/types.js.map +1 -0
  65. package/package.json +79 -3
  66. package/src/address.ts +206 -0
  67. package/src/errors.ts +44 -0
  68. package/src/exchange.ts +381 -0
  69. package/src/index.ts +11 -0
  70. package/src/module.ts +257 -0
  71. package/src/parsers.ts +184 -0
  72. package/src/policy.ts +192 -0
  73. package/src/procedures/http/index.ts +4 -0
  74. package/src/procedures/http/json.ts +52 -0
  75. package/src/procedures/http/ndjson.ts +64 -0
  76. package/src/procedures/http/request.ts +72 -0
  77. package/src/procedures/http/sse.ts +65 -0
  78. package/src/register.ts +10 -0
  79. package/src/scope.ts +129 -0
  80. package/src/types.ts +127 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * http.ndjson procedure
3
+ *
4
+ * Read an NDJSON response as a stream of parsed lines. The procedure sends a GET. Each line that
5
+ * is not blank is one item: its JSON value. The stream can run without an end, so the procedure
6
+ * declares an unbounded stream (roadmap R15). When the reader stops, the connection closes.
7
+ *
8
+ * The call waits for the status of the response. A refused host, a failed connection and a status
9
+ * outside 200 to 299 fail the call itself, before the first item.
10
+ */
11
+ import { HttpError } from "../../errors.js";
12
+ import { DEFAULT_ITEM_BYTES, DEFAULT_SETTINGS, excerpt, exchange, isOk, prepare, statusError, touching } from "../../exchange.js";
13
+ import { ndjsonLines } from "../../parsers.js";
14
+ import { CallScope } from "../../scope.js";
15
+ const PATH = ["http", "ndjson"];
16
+ /** The items of an open response. The end of the generator closes the connection. */
17
+ async function* items(opened, scope, maxLineBytes) {
18
+ try {
19
+ scope.touch();
20
+ for await (const line of ndjsonLines(touching(opened.body, scope), maxLineBytes, "http.ndjson")) {
21
+ let value;
22
+ try {
23
+ value = JSON.parse(line.text);
24
+ }
25
+ catch {
26
+ throw new HttpError("BAD_JSON", `http.ndjson: line ${line.line} is not JSON: ${excerpt(line.text, 80)}`, opened.response.statusCode);
27
+ }
28
+ // The idle time does not run while the reader holds the item
29
+ scope.pause();
30
+ yield value;
31
+ scope.touch();
32
+ }
33
+ }
34
+ catch (error) {
35
+ throw scope.translate(error);
36
+ }
37
+ finally {
38
+ opened.body.destroy();
39
+ opened.close();
40
+ scope.dispose();
41
+ }
42
+ }
43
+ /**
44
+ * Read an NDJSON response as a stream of parsed lines
45
+ */
46
+ export async function httpNdjson(input, ctx = {}, settings = DEFAULT_SETTINGS) {
47
+ const headers = { accept: "application/x-ndjson, application/jsonl;q=0.9, application/json;q=0.8" };
48
+ const prepared = prepare({ ...input, method: "GET" }, PATH, settings, { headers });
49
+ const scope = new CallScope(PATH, ctx, { timeoutMs: input.timeoutMs, idleTimeoutMs: input.idleTimeoutMs });
50
+ let opened;
51
+ try {
52
+ opened = await exchange(prepared, settings.policy, scope);
53
+ if (!isOk(opened.response.statusCode ?? 0))
54
+ throw await statusError(opened, scope);
55
+ }
56
+ catch (error) {
57
+ opened?.close();
58
+ scope.dispose();
59
+ throw scope.translate(error);
60
+ }
61
+ // The idle time starts again when the reader asks for the first item
62
+ scope.pause();
63
+ return items(opened, scope, input.maxLineBytes ?? DEFAULT_ITEM_BYTES);
64
+ }
65
+ //# sourceMappingURL=ndjson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AK,EAAE,CAAC;IACd,OAAO,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,IAAI,kBAAkB,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * http.request procedure
3
+ *
4
+ * Send an HTTP request and give the status, the headers and the body. The procedure gives each
5
+ * status: a status of 400 or more is not an error. The body of the response has a size limit.
6
+ */
7
+ import { type HttpSettings } from "../../exchange.js";
8
+ import { type ScopeContext } from "../../scope.js";
9
+ import type { HttpRequestInput, HttpRequestOutput } from "../../types.js";
10
+ /**
11
+ * Send an HTTP request and give the status, the headers and the body
12
+ */
13
+ export declare function httpRequest(input: HttpRequestInput, ctx?: ScopeContext, settings?: HttpSettings): Promise<HttpRequestOutput>;
14
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/procedures/http/request.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAA4F,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChJ,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AA2B1E;;GAEG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,GAAE,YAAiB,EAAE,QAAQ,GAAE,YAA+B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA+BxJ"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * http.request procedure
3
+ *
4
+ * Send an HTTP request and give the status, the headers and the body. The procedure gives each
5
+ * status: a status of 400 or more is not an error. The body of the response has a size limit.
6
+ */
7
+ import { HttpError } from "../../errors.js";
8
+ import { DEFAULT_SETTINGS, DEFAULT_TIMEOUT_MS, exchange, isOk, prepare, readBody, responseHeaders } from "../../exchange.js";
9
+ import { CallScope } from "../../scope.js";
10
+ const PATH = ["http", "request"];
11
+ /** The body of an input and its content type, or undefined. */
12
+ function bodyOf(input) {
13
+ const given = [input.body, input.json, input.bodyBase64].filter((value) => value !== undefined).length;
14
+ if (given > 1)
15
+ throw new Error("http.request: give only one of body, json and bodyBase64");
16
+ if (input.body !== undefined)
17
+ return { body: Buffer.from(input.body, "utf8"), type: "text/plain; charset=utf-8" };
18
+ if (input.json !== undefined)
19
+ return { body: Buffer.from(JSON.stringify(input.json), "utf8"), type: "application/json" };
20
+ if (input.bodyBase64 !== undefined)
21
+ return { body: Buffer.from(input.bodyBase64, "base64"), type: "application/octet-stream" };
22
+ return undefined;
23
+ }
24
+ /** The body of the response in the form of `responseType`. */
25
+ function decode(bytes, responseType, status) {
26
+ if (responseType === "bytes")
27
+ return bytes.toString("base64");
28
+ const text = bytes.toString("utf8");
29
+ if (responseType !== "json")
30
+ return text;
31
+ if (text.trim() === "")
32
+ return null;
33
+ try {
34
+ return JSON.parse(text);
35
+ }
36
+ catch {
37
+ throw new HttpError("BAD_JSON", `http.request: the body of the response is not JSON: ${text.slice(0, 200)}`, status);
38
+ }
39
+ }
40
+ /**
41
+ * Send an HTTP request and give the status, the headers and the body
42
+ */
43
+ export async function httpRequest(input, ctx = {}, settings = DEFAULT_SETTINGS) {
44
+ const method = input.method ?? "GET";
45
+ const body = bodyOf(input);
46
+ if (body !== undefined && (method === "GET" || method === "HEAD")) {
47
+ throw new Error(`http.request: a ${method} request has no body`);
48
+ }
49
+ const headers = {};
50
+ if (body !== undefined)
51
+ headers["content-type"] = body.type;
52
+ if (input.responseType === "json")
53
+ headers["accept"] = "application/json";
54
+ const prepared = prepare({ ...input, method }, PATH, settings, { headers, body: body?.body });
55
+ const scope = new CallScope(PATH, ctx, { timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS });
56
+ try {
57
+ const opened = await exchange(prepared, settings.policy, scope);
58
+ const limit = Math.min(input.maxResponseBytes ?? settings.maxResponseBytes, settings.maxResponseBytes);
59
+ const bytes = await readBody(opened.body, limit, scope, opened.response);
60
+ const status = opened.response.statusCode ?? 0;
61
+ return {
62
+ status,
63
+ statusText: opened.response.statusMessage ?? "",
64
+ ok: isOk(status),
65
+ url: opened.url,
66
+ redirected: opened.redirects.length > 0,
67
+ headers: responseHeaders(opened.response.headers),
68
+ body: decode(bytes, input.responseType, status),
69
+ bytes: bytes.length,
70
+ };
71
+ }
72
+ catch (error) {
73
+ throw scope.translate(error);
74
+ }
75
+ finally {
76
+ scope.dispose();
77
+ }
78
+ }
79
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/procedures/http/request.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAqB,MAAM,mBAAmB,CAAC;AAChJ,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAG9D,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEjC,+DAA+D;AAC/D,SAAS,MAAM,CAAC,KAAuB;IACrC,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC;IACvG,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC3F,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,2BA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AAM,CAAC,QAAQ,CAAC,aAAa,IAAI,EAAE;YAC/C,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC;YAChB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;YACvC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;YACjD,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC;YAC/C,KAAK,EAAE,KAAK,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * http.sse procedure
3
+ *
4
+ * Read a stream of server-sent events. The procedure sends a GET with
5
+ * `accept: text/event-stream`, and each event is one item: its type, its data and the last event
6
+ * ID. The procedure does not connect again after the end of the stream. To continue, a caller
7
+ * sends the last ID in `lastEventId`. The stream can run without an end (roadmap R15).
8
+ *
9
+ * The call waits for the status of the response. A refused host, a failed connection, a status
10
+ * outside 200 to 299 and another content type fail the call itself, before the first item.
11
+ */
12
+ import { type HttpSettings } from "../../exchange.js";
13
+ import { type ScopeContext } from "../../scope.js";
14
+ import type { HttpSseInput, HttpSseOutput } from "../../types.js";
15
+ /**
16
+ * Read a stream of server-sent events
17
+ */
18
+ export declare function httpSse(input: HttpSseInput, ctx?: ScopeContext, settings?: HttpSettings): Promise<AsyncGenerator<HttpSseOutput, void, undefined>>;
19
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/procedures/http/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAmH,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEvK,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAuBlE;;GAEG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,GAAE,YAAiB,EAAE,QAAQ,GAAE,YAA+B,GAAG,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAsB7K"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * http.sse procedure
3
+ *
4
+ * Read a stream of server-sent events. The procedure sends a GET with
5
+ * `accept: text/event-stream`, and each event is one item: its type, its data and the last event
6
+ * ID. The procedure does not connect again after the end of the stream. To continue, a caller
7
+ * sends the last ID in `lastEventId`. The stream can run without an end (roadmap R15).
8
+ *
9
+ * The call waits for the status of the response. A refused host, a failed connection, a status
10
+ * outside 200 to 299 and another content type fail the call itself, before the first item.
11
+ */
12
+ import { HttpError } from "../../errors.js";
13
+ import { DEFAULT_ITEM_BYTES, DEFAULT_SETTINGS, exchange, headerText, isOk, prepare, statusError, touching } from "../../exchange.js";
14
+ import { sseEvents } from "../../parsers.js";
15
+ import { CallScope } from "../../scope.js";
16
+ const PATH = ["http", "sse"];
17
+ /** The events of an open response. The end of the generator closes the connection. */
18
+ async function* events(opened, scope, maxEventBytes) {
19
+ try {
20
+ scope.touch();
21
+ for await (const event of sseEvents(touching(opened.body, scope), maxEventBytes, "http.sse")) {
22
+ // The idle time does not run while the reader holds the item
23
+ scope.pause();
24
+ yield event;
25
+ scope.touch();
26
+ }
27
+ }
28
+ catch (error) {
29
+ throw scope.translate(error);
30
+ }
31
+ finally {
32
+ opened.body.destroy();
33
+ opened.close();
34
+ scope.dispose();
35
+ }
36
+ }
37
+ /**
38
+ * Read a stream of server-sent events
39
+ */
40
+ export async function httpSse(input, ctx = {}, settings = DEFAULT_SETTINGS) {
41
+ const headers = { accept: "text/event-stream", "cache-control": "no-cache" };
42
+ if (input.lastEventId !== undefined)
43
+ headers["last-event-id"] = input.lastEventId;
44
+ const prepared = prepare({ ...input, method: "GET" }, PATH, settings, { headers });
45
+ const scope = new CallScope(PATH, ctx, { timeoutMs: input.timeoutMs, idleTimeoutMs: input.idleTimeoutMs });
46
+ let opened;
47
+ try {
48
+ opened = await exchange(prepared, settings.policy, scope);
49
+ const status = opened.response.statusCode ?? 0;
50
+ if (!isOk(status))
51
+ throw await statusError(opened, scope);
52
+ const type = headerText(opened.response.headers["content-type"]) ?? "";
53
+ if (!type.toLowerCase().startsWith("text/event-stream")) {
54
+ throw new HttpError("BAD_CONTENT_TYPE", `http.sse: the content type of the response is ${JSON.stringify(type)}, not text/event-stream`, status);
55
+ }
56
+ }
57
+ catch (error) {
58
+ opened?.close();
59
+ scope.dispose();
60
+ throw scope.translate(error);
61
+ }
62
+ // The idle time starts again when the reader asks for the first event
63
+ scope.pause();
64
+ return events(opened, scope, input.maxEventBytes ?? DEFAULT_ITEM_BYTES);
65
+ }
66
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/procedures/http/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAoC,MAAM,mBAAmB,CAAC;AACvK,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAG9D,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE7B,sFAAsF;AACtF,KAAK,SAAS,CAA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CAAC,CAAC;IAC3G,IAAI,MAA4B,CAAC;IACjC,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,MAAM,MAAM,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,SAAS,CAAC,kBAAkB,EAAE,iDAAiD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;QAClJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,MAAM,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,sEAAsE;IACtE,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,OAAO,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,IAAI,kBAAkB,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/http in the global registry:
3
+ * `import "@procedures/http/register"`. The package root registers nothing.
4
+ */
5
+ export * from "./module.js";
6
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,cAAc,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/http in the global registry:
3
+ * `import "@procedures/http/register"`. The package root registers nothing.
4
+ */
5
+ import { registerHttpProcedures } from "./module.js";
6
+ export * from "./module.js";
7
+ registerHttpProcedures();
8
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,cAAc,aAAa,CAAC;AAE5B,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The time limits and the stop of one call (roadmap R38).
3
+ *
4
+ * A call stops at the first of these events:
5
+ * - the signal of the call aborts (`ctx.signal`): the caller went away, or the server stops;
6
+ * - the deadline of the call passes (`ctx.capability.deadline`);
7
+ * - the time of the input passes (`timeoutMs`);
8
+ * - a stream gets no data for the idle time of the input (`idleTimeoutMs`).
9
+ *
10
+ * The earliest event wins. The stop aborts the request, and the call fails with `TIMEOUT` or
11
+ * `ABORTED`.
12
+ */
13
+ import { InvocationError, type ProcedurePath } from "@procedures/client";
14
+ /** The cause of a stop. */
15
+ export type StopReason = "timeout" | "idle" | "deadline" | "aborted";
16
+ /** The parts of the context of a handler that a scope reads. */
17
+ export interface ScopeContext {
18
+ readonly signal?: AbortSignal | undefined;
19
+ readonly capability?: {
20
+ readonly deadline?: number | undefined;
21
+ } | undefined;
22
+ }
23
+ /** The time limits of a scope, in milliseconds. */
24
+ export interface ScopeLimits {
25
+ /** The time of the whole call. */
26
+ readonly timeoutMs?: number | undefined;
27
+ /** The longest time without data. */
28
+ readonly idleTimeoutMs?: number | undefined;
29
+ }
30
+ /** The stop of one call: one abort signal for the request, and the error of the stop. */
31
+ export declare class CallScope {
32
+ #private;
33
+ readonly path: ProcedurePath;
34
+ readonly limits: ScopeLimits;
35
+ constructor(path: ProcedurePath, context: ScopeContext, limits?: ScopeLimits);
36
+ /** The signal that aborts the request at the stop. */
37
+ get signal(): AbortSignal;
38
+ /** The cause of the stop, or undefined while the call runs. */
39
+ get reason(): StopReason | undefined;
40
+ /** This function stops the call. The first cause wins. */
41
+ stop(reason: StopReason): void;
42
+ /** This function starts the idle time again: data arrived. */
43
+ touch(): void;
44
+ /** This function holds the idle time while the reader of a stream has an item and reads no data. */
45
+ pause(): void;
46
+ /** The error of the stop. Before a stop, an `ABORTED` error. */
47
+ error(): InvocationError;
48
+ /** The error to throw for a failure: the error of the stop after a stop, or the failure. */
49
+ translate(error: unknown): unknown;
50
+ /** This function removes the timers and the listener. */
51
+ dispose(): void;
52
+ }
53
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEzE,2BAA2B;AAC3B,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;AAKrE,gEAAgE;AAChE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CAC9E;AAED,mDAAmD;AACnD,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,qCAAqC;IACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C;AAED,yFAAyF;AACzF,qBAAa,SAAS;;IASlB,QAAQ,CAAC,IAAI,EAAE,aAAa;IAE5B,QAAQ,CAAC,MAAM,EAAE,WAAW;IAH9B,YACW,IAAI,EAAE,aAAa,EAC5B,OAAO,EAAE,YAAY,EACZ,MAAM,GAAE,WAAgB,EAYlC;IAMD,sDAAsD;IACtD,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,+DAA+D;IAC/D,IAAI,MAAM,IAAI,UAAU,GAAG,SAAS,CAEnC;IAED,0DAA0D;IAC1D,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAK7B;IAED,8DAA8D;IAC9D,KAAK,IAAI,IAAI,CAKZ;IAED,oGAAoG;IACpG,KAAK,IAAI,IAAI,CAEZ;IAOD,gEAAgE;IAChE,KAAK,IAAI,eAAe,CAYvB;IAED,4FAA4F;IAC5F,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEjC;IAED,yDAAyD;IACzD,OAAO,IAAI,IAAI,CAKd;CACF"}
package/dist/scope.js ADDED
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The time limits and the stop of one call (roadmap R38).
3
+ *
4
+ * A call stops at the first of these events:
5
+ * - the signal of the call aborts (`ctx.signal`): the caller went away, or the server stops;
6
+ * - the deadline of the call passes (`ctx.capability.deadline`);
7
+ * - the time of the input passes (`timeoutMs`);
8
+ * - a stream gets no data for the idle time of the input (`idleTimeoutMs`).
9
+ *
10
+ * The earliest event wins. The stop aborts the request, and the call fails with `TIMEOUT` or
11
+ * `ABORTED`.
12
+ */
13
+ import { InvocationError } from "@procedures/client";
14
+ /** The longest delay of `setTimeout`. A later time gets no timer: the call cannot last so long. */
15
+ const MAX_TIMER_MS = 2_147_483_647;
16
+ /** The stop of one call: one abort signal for the request, and the error of the stop. */
17
+ export class CallScope {
18
+ path;
19
+ limits;
20
+ #controller = new AbortController();
21
+ #timers = [];
22
+ #parent;
23
+ #onAbort = () => this.stop("aborted");
24
+ #idle;
25
+ #reason;
26
+ constructor(path, context, limits = {}) {
27
+ this.path = path;
28
+ this.limits = limits;
29
+ this.#parent = context.signal;
30
+ if (this.#parent?.aborted) {
31
+ this.stop("aborted");
32
+ return;
33
+ }
34
+ this.#parent?.addEventListener("abort", this.#onAbort, { once: true });
35
+ if (limits.timeoutMs !== undefined)
36
+ this.#later(limits.timeoutMs, () => this.stop("timeout"));
37
+ const deadline = context.capability?.deadline;
38
+ if (deadline !== undefined)
39
+ this.#later(Math.max(0, deadline - Date.now()), () => this.stop("deadline"));
40
+ this.touch();
41
+ }
42
+ #later(ms, stop) {
43
+ if (ms <= MAX_TIMER_MS)
44
+ this.#timers.push(setTimeout(stop, ms));
45
+ }
46
+ /** The signal that aborts the request at the stop. */
47
+ get signal() {
48
+ return this.#controller.signal;
49
+ }
50
+ /** The cause of the stop, or undefined while the call runs. */
51
+ get reason() {
52
+ return this.#reason;
53
+ }
54
+ /** This function stops the call. The first cause wins. */
55
+ stop(reason) {
56
+ if (this.#reason !== undefined)
57
+ return;
58
+ this.#reason = reason;
59
+ this.#clearIdle();
60
+ this.#controller.abort(this.error());
61
+ }
62
+ /** This function starts the idle time again: data arrived. */
63
+ touch() {
64
+ const idle = this.limits.idleTimeoutMs;
65
+ if (idle === undefined || this.#reason !== undefined)
66
+ return;
67
+ this.#clearIdle();
68
+ if (idle <= MAX_TIMER_MS)
69
+ this.#idle = setTimeout(() => this.stop("idle"), idle);
70
+ }
71
+ /** This function holds the idle time while the reader of a stream has an item and reads no data. */
72
+ pause() {
73
+ this.#clearIdle();
74
+ }
75
+ #clearIdle() {
76
+ if (this.#idle !== undefined)
77
+ clearTimeout(this.#idle);
78
+ this.#idle = undefined;
79
+ }
80
+ /** The error of the stop. Before a stop, an `ABORTED` error. */
81
+ error() {
82
+ const key = this.path.join(".");
83
+ switch (this.#reason) {
84
+ case "timeout":
85
+ return new InvocationError("TIMEOUT", `${key}: the call took more than ${this.limits.timeoutMs} ms (timeoutMs)`, this.path);
86
+ case "idle":
87
+ return new InvocationError("TIMEOUT", `${key}: no data arrived in ${this.limits.idleTimeoutMs} ms (idleTimeoutMs)`, this.path);
88
+ case "deadline":
89
+ return new InvocationError("TIMEOUT", `${key}: the deadline of the call passed`, this.path);
90
+ default:
91
+ return new InvocationError("ABORTED", `${key}: the caller aborted the call`, this.path);
92
+ }
93
+ }
94
+ /** The error to throw for a failure: the error of the stop after a stop, or the failure. */
95
+ translate(error) {
96
+ return this.#reason !== undefined ? this.error() : error;
97
+ }
98
+ /** This function removes the timers and the listener. */
99
+ dispose() {
100
+ for (const timer of this.#timers)
101
+ clearTimeout(timer);
102
+ this.#timers.length = 0;
103
+ this.#clearIdle();
104
+ this.#parent?.removeEventListener("abort", this.#onAbort);
105
+ }
106
+ }
107
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AAKzE,mGAAmG;AACnG,MAAM,YAAY,GAAG,aAAa,CAAC;AAgBnC,yFAAyF;AACzF,MAAM,OAAO,SAAS;IAST,IAAI;IAEJ,MAAM;IAVR,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,OAAO,GAAoC,EAAE,CAAC;IAC9C,OAAO,CAA0B;IACjC,QAAQ,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrD,KAAK,CAA4C;IACjD,OAAO,CAAyB;IAEhC,YACW,IAAmB,EAC5B,OAAqB,EACZ,MAAM,GAAgB,EAAE;oBAFxB,IAAI;sBAEJ,MAAM;QAEf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,EA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AAC;IACH,CAAC;IAED,4FAA4F;IAC5F,SAAS,CAAC,KAAc;QACtB,OAAO,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3D,CAAC;IAED,yDAAyD;IACzD,OAAO;QACL,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;CACF"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Type definitions of the procedures of this package
3
+ *
4
+ * mark procedure new adds the types of each new procedure here. The zod schemas are in
5
+ * `module.ts`: an exported schema needs a written type (isolatedDeclarations).
6
+ */
7
+ /** A JSON value. */
8
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
9
+ [key: string]: JsonValue;
10
+ };
11
+ /** The methods of `http.request`. */
12
+ export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
13
+ /** The fields of a request that each procedure has. */
14
+ export interface HttpTarget {
15
+ /** The URL: `http:` or `https:`. */
16
+ url: string;
17
+ /** The headers of the request. */
18
+ headers?: Record<string, string> | undefined;
19
+ /** More parameters for the query of the URL. A list gives the parameter more than one time. */
20
+ query?: Record<string, string | number | boolean | Array<string | number | boolean>> | undefined;
21
+ }
22
+ export interface HttpRequestInput extends HttpTarget {
23
+ method?: HttpMethod | undefined;
24
+ /** A body of text. */
25
+ body?: string | undefined;
26
+ /** A body of JSON: the procedure sets `content-type: application/json`. */
27
+ json?: unknown;
28
+ /** A body of bytes in base64. */
29
+ bodyBase64?: string | undefined;
30
+ /** The form of the body of the response: text (the default), parsed JSON, or bytes in base64. */
31
+ responseType?: "text" | "json" | "bytes" | undefined;
32
+ /** The time of the whole call, in milliseconds. The default is 30000. */
33
+ timeoutMs?: number | undefined;
34
+ /** The largest body of the response, in bytes. The limit of the module is the maximum. */
35
+ maxResponseBytes?: number | undefined;
36
+ /** What to do with a redirect: follow it (the default), give it (`manual`), or fail (`error`). */
37
+ redirect?: "follow" | "manual" | "error" | undefined;
38
+ /** The most redirects that the call follows. The default is 5. */
39
+ maxRedirects?: number | undefined;
40
+ }
41
+ export interface HttpRequestOutput {
42
+ status: number;
43
+ statusText: string;
44
+ /** True for a status in 200 to 299. */
45
+ ok: boolean;
46
+ /** The URL of the response: the last URL after the redirects. */
47
+ url: string;
48
+ /** True when the call followed one or more redirects. */
49
+ redirected: boolean;
50
+ /** The headers of the response, with names in lowercase. `set-cookie` is a list. */
51
+ headers: Record<string, string | string[]>;
52
+ /** The body: text, parsed JSON (null for an empty body), or bytes in base64. */
53
+ body: unknown;
54
+ /** The size of the body in bytes, after the content encoding. */
55
+ bytes: number;
56
+ }
57
+ export interface HttpJsonInput extends HttpTarget {
58
+ /** GET, or POST. The default is POST with `json`, and GET without it. */
59
+ method?: "GET" | "POST" | undefined;
60
+ /** The JSON body of a POST. */
61
+ json?: unknown;
62
+ /** The time of the whole call, in milliseconds. The default is 30000. */
63
+ timeoutMs?: number | undefined;
64
+ /** The largest body of the response, in bytes. The limit of the module is the maximum. */
65
+ maxResponseBytes?: number | undefined;
66
+ /** True (the default): a status outside 200 to 299 is an error. False: the output has it. */
67
+ failOnStatus?: boolean | undefined;
68
+ }
69
+ export interface HttpJsonOutput {
70
+ status: number;
71
+ ok: boolean;
72
+ url: string;
73
+ headers: Record<string, string | string[]>;
74
+ /** The parsed body. An empty body gives null. An error status with a body that is not JSON gives its text. */
75
+ data: unknown;
76
+ }
77
+ export interface HttpStreamInput extends HttpTarget {
78
+ /** The time of the whole stream, in milliseconds. The default is no limit. */
79
+ timeoutMs?: number | undefined;
80
+ /** The longest time without data, in milliseconds. The default is no limit. */
81
+ idleTimeoutMs?: number | undefined;
82
+ }
83
+ export interface HttpNdjsonInput extends HttpStreamInput {
84
+ /** The largest line, in bytes. The default is 1 MiB. */
85
+ maxLineBytes?: number | undefined;
86
+ }
87
+ /** One item of `http.ndjson`: the JSON value of one line. */
88
+ export type HttpNdjsonOutput = unknown;
89
+ export interface HttpSseInput extends HttpStreamInput {
90
+ /** The `Last-Event-ID` header: the server continues after this event. */
91
+ lastEventId?: string | undefined;
92
+ /** The largest event, in bytes. The default is 1 MiB. */
93
+ maxEventBytes?: number | undefined;
94
+ }
95
+ /** One item of `http.sse`: one event. */
96
+ export interface HttpSseOutput {
97
+ event: string;
98
+ data: string;
99
+ id?: string | undefined;
100
+ retry?: number | undefined;
101
+ }
102
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oBAAoB;AACpB,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,qCAAqC;AACrC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE1F,uDAAuD;AACvD,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC7C,+FAA+F;IAC/F,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAA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
3
+ *
4
+ * mark procedure new adds the types of each new procedure here. The zod schemas are in
5
+ * `module.ts`: an exported schema needs a written type (isolatedDeclarations).
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}