pasika 0.10.3 → 0.10.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.
@@ -3398,6 +3398,7 @@ var FETCHED = `fetch must not be called; make the request through ${HELPER3} fro
3398
3398
  var DECLARED3 = `A file must not declare its own ${HELPER3}; import it from ${ENTRY3}. See ${DOC4}`;
3399
3399
  var IMPORTED3 = `${HELPER3} must be imported from ${ENTRY3}. See ${DOC4}`;
3400
3400
  var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["globalThis", "window", "self", "global"]);
3401
+ var TEST_FILE = /(?:^|[\\/])(?:__tests__|tests)[\\/]|[.](?:test|spec)[.][cm]?[jt]sx?$/;
3401
3402
  function isNamed3(node, name) {
3402
3403
  return node?.type === "Identifier" && node.name === name;
3403
3404
  }
@@ -3414,6 +3415,7 @@ var zodFetchHelperRule = {
3414
3415
  }
3415
3416
  },
3416
3417
  create(context) {
3418
+ if (TEST_FILE.test(context.filename)) return {};
3417
3419
  const checkSource = (node) => {
3418
3420
  if (!node.source || node.source.value === ENTRY3) return;
3419
3421
  for (const specifier of node.specifiers) {
@@ -16,6 +16,10 @@ interface ZodFetchRelayedResponse {
16
16
  * data the response schema accepted, and a failure back as an `HttpError` carrying
17
17
  * the status the upstream reported, the message for a client, and what the upstream
18
18
  * answered with. A call that names no response schema gets the response itself.
19
+ *
20
+ * A success that carries no body is the schema's call: one that allows its data to
21
+ * be absent, such as `z.undefined()` for an endpoint answering `204`, accepts it, and
22
+ * one that does not makes it a failure of this gateway's own, a 502.
19
23
  */
20
24
  declare function zodFetch<TSchema extends ZodType>(options: ZodFetchOptions<TSchema> & {
21
25
  responseSchema: TSchema;
@@ -5,6 +5,7 @@ import {
5
5
  // helpers/zod-fetch.ts
6
6
  import { z } from "zod";
7
7
  var streamBody = z.custom((value) => value instanceof ReadableStream);
8
+ var BAD_GATEWAY = 502;
8
9
  function decodeFailureBody(body) {
9
10
  try {
10
11
  const parsed = JSON.parse(body);
@@ -27,13 +28,15 @@ async function zodFetch(options) {
27
28
  if (options.responseSchema === void 0) {
28
29
  const streamed = streamBody.safeParse(response.body);
29
30
  if (!streamed.success) {
30
- throw new HttpError("The upstream answered without a body to relay.", response.status);
31
+ throw new HttpError("The upstream answered without a body to relay.", BAD_GATEWAY);
31
32
  }
32
33
  return { body: streamed.data, status: response.status, headers: response.headers };
33
34
  }
34
35
  const body = await response.text();
35
36
  if (body === "") {
36
- throw new HttpError("The upstream answered without a body to decode.", response.status);
37
+ const absent = options.responseSchema.safeParse(void 0);
38
+ if (absent.success) return absent.data;
39
+ throw new HttpError("The upstream answered without a body to decode.", BAD_GATEWAY);
37
40
  }
38
41
  const decoded = JSON.parse(body);
39
42
  return options.responseSchema.parse(decoded);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pasika",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "description": "Reusable agent setup package",
5
5
  "repository": {
6
6
  "type": "git",