@dlenroc/typed-client 0.3.0 → 0.3.1
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.
- package/README.md +5 -0
- package/dist/{codec-DpNVlh9j.js → codec-CaVxvHce.js} +1 -1
- package/dist/{errors-Dcje8BxZ.js → errors-25xWqgvt.js} +46 -3
- package/dist/fetch.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/k6.js +2 -2
- package/dist/playwright.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -295,6 +295,11 @@ available. `schema` names the schema that failed: `path`, `query`, `headers`,
|
|
|
295
295
|
or `body`. That schema either reported `issues` or threw `cause`. A `response`
|
|
296
296
|
error without `schema` means the body could not be decoded.
|
|
297
297
|
|
|
298
|
+
The message names the method and the URL when the URL is known. It lists up to
|
|
299
|
+
10 issues, one per line, or gives the first line of the cause and of its cause.
|
|
300
|
+
It leaves out URL credentials. The `url` and `cause` fields keep the full
|
|
301
|
+
values.
|
|
302
|
+
|
|
298
303
|
If cleanup fails as well, `cleanupError` holds the secondary failure.
|
|
299
304
|
Reporters that serialize errors can read `code`, `meta`, and the other
|
|
300
305
|
enumerable fields. Read `message` and `cause` explicitly when building a
|
|
@@ -56,9 +56,51 @@ function createUrlResolver(baseUrl) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
// src/core/errors.ts
|
|
59
|
+
function withoutCredentials(url) {
|
|
60
|
+
return url.replace(/^((?:[a-z][a-z\d+.-]*:)?\/\/)[^/?#]*@/i, "$1");
|
|
61
|
+
}
|
|
62
|
+
function pathText(path = []) {
|
|
63
|
+
let text = "";
|
|
64
|
+
for (let i = 0; i < path.length; i++) {
|
|
65
|
+
const segment = path[i];
|
|
66
|
+
const key = typeof segment === "object" ? segment.key : segment;
|
|
67
|
+
text += typeof key === "number" ? `[${key}]` : (i === 0 ? "" : ".") + String(key);
|
|
68
|
+
}
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
function issueText(issue) {
|
|
72
|
+
const path = pathText(issue.path);
|
|
73
|
+
if (path === "" || issue.message.startsWith(`${path} `)) return issue.message;
|
|
74
|
+
return issue.message === "" ? path : `${path}: ${issue.message}`;
|
|
75
|
+
}
|
|
76
|
+
const shownIssues = 10;
|
|
77
|
+
function issuesText(issues) {
|
|
78
|
+
const shown = Math.min(issues.length, shownIssues);
|
|
79
|
+
let text = "";
|
|
80
|
+
for (let i = 0; i < shown; i++) text += `\n - ${issueText(issues[i])}`;
|
|
81
|
+
if (issues.length > shown) text += `\n - … ${issues.length - shown} more`;
|
|
82
|
+
return text;
|
|
83
|
+
}
|
|
84
|
+
function firstLine(error) {
|
|
85
|
+
const line = (typeof error === "string" ? error : error instanceof Error ? error.message : "").split("\n", 1)[0];
|
|
86
|
+
const code = error?.code;
|
|
87
|
+
return line === "" && typeof code === "string" ? code : line;
|
|
88
|
+
}
|
|
89
|
+
function causeText(cause) {
|
|
90
|
+
const outer = firstLine(cause);
|
|
91
|
+
if (outer === "") return "";
|
|
92
|
+
const inner = firstLine(cause.cause);
|
|
93
|
+
return inner === "" ? `: ${outer}` : `: ${outer} (${inner})`;
|
|
94
|
+
}
|
|
95
|
+
function describe(summary, method, url, issues, cause) {
|
|
96
|
+
const detail = issues !== void 0 && issues.length > 0 ? issuesText(issues) : causeText(cause);
|
|
97
|
+
if (!url) return summary + detail;
|
|
98
|
+
const requestUrl = withoutCredentials(url);
|
|
99
|
+
return `${summary} for ${method} ${requestUrl}${detail.replaceAll(url, () => requestUrl)}`;
|
|
100
|
+
}
|
|
59
101
|
var ClientErrorInstance = class extends Error {
|
|
60
|
-
constructor(code,
|
|
61
|
-
super(
|
|
102
|
+
constructor(code, summary, method, url, meta, status, schema, issues, cause) {
|
|
103
|
+
super(describe(summary, method, url, issues, cause));
|
|
62
104
|
this.code = code;
|
|
63
105
|
this.method = method;
|
|
64
106
|
this.url = url;
|
|
@@ -69,6 +111,7 @@ var ClientErrorInstance = class extends Error {
|
|
|
69
111
|
this.cause = cause;
|
|
70
112
|
}
|
|
71
113
|
};
|
|
114
|
+
Object.defineProperty(ClientErrorInstance, "name", { value: "ClientError" });
|
|
72
115
|
ClientErrorInstance.prototype.name = "ClientError";
|
|
73
116
|
const ClientError = ClientErrorInstance;
|
|
74
117
|
var ResponseCleanupError = class extends Error {
|
|
@@ -90,6 +133,6 @@ function preserveCleanupError(error, failure) {
|
|
|
90
133
|
return error;
|
|
91
134
|
}
|
|
92
135
|
function transportError(prepared, method, url, meta, failure) {
|
|
93
|
-
return preserveCleanupError(new ClientError(prepared ? "transport" : "request", prepared ? "
|
|
136
|
+
return preserveCleanupError(new ClientError(prepared ? "transport" : "request", prepared ? "Cannot get response" : "Cannot prepare request", method, url, meta, void 0, void 0, void 0, failure instanceof FailureWithCleanupError ? failure.cause : failure), failure);
|
|
94
137
|
}
|
|
95
138
|
export { transportError as a, asSearchParams as c, preserveCleanupError as i, encodeFields as l, FailureWithCleanupError as n, appendQuery as o, ResponseCleanupError as r, createUrlResolver as s, ClientError as t, forEachField as u };
|
package/dist/fetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as transportError, c as asSearchParams, s as createUrlResolver } from "./errors-
|
|
2
|
-
import { a as appendResponseHeader, c as encodeJson, i as encodeUtf8, n as decodeUrlEncoded, o as prepareHeaders, s as asFormData } from "./codec-
|
|
1
|
+
import { a as transportError, c as asSearchParams, s as createUrlResolver } from "./errors-25xWqgvt.js";
|
|
2
|
+
import { a as appendResponseHeader, c as encodeJson, i as encodeUtf8, n as decodeUrlEncoded, o as prepareHeaders, s as asFormData } from "./codec-CaVxvHce.js";
|
|
3
3
|
// src/transports/fetch.ts
|
|
4
4
|
async function decodeFormData(form) {
|
|
5
5
|
const target = Object.create(null);
|
package/dist/index.d.ts
CHANGED
|
@@ -437,7 +437,7 @@ declare class ClientErrorInstance extends Error {
|
|
|
437
437
|
readonly schema: string | undefined;
|
|
438
438
|
readonly issues: readonly StandardIssue[] | undefined;
|
|
439
439
|
cleanupError?: unknown;
|
|
440
|
-
constructor(code: ClientError["code"],
|
|
440
|
+
constructor(code: ClientError["code"], summary: string, method: string, url: string | undefined, meta: Meta, status: number | undefined, schema: SchemaPart | undefined, issues: readonly StandardIssue[] | undefined, cause: unknown);
|
|
441
441
|
}
|
|
442
442
|
export declare const ClientError: {
|
|
443
443
|
/** @internal */
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as transportError, i as preserveCleanupError, n as FailureWithCleanupError, o as appendQuery, r as ResponseCleanupError, t as ClientError } from "./errors-
|
|
1
|
+
import { a as transportError, i as preserveCleanupError, n as FailureWithCleanupError, o as appendQuery, r as ResponseCleanupError, t as ClientError } from "./errors-25xWqgvt.js";
|
|
2
2
|
// src/core/endpoint.ts
|
|
3
3
|
function compilePath(url) {
|
|
4
4
|
const suffixStart = url.search(/[?#]/);
|
|
@@ -41,7 +41,7 @@ function type() {
|
|
|
41
41
|
return typeMarker;
|
|
42
42
|
}
|
|
43
43
|
function executableSchema(input) {
|
|
44
|
-
return input
|
|
44
|
+
return input?.["~standard"] === void 0 ? void 0 : input;
|
|
45
45
|
}
|
|
46
46
|
function normalizeBody(input) {
|
|
47
47
|
if (typeof input === "string") return {
|
|
@@ -69,7 +69,7 @@ function endpoint(url, definition = {}) {
|
|
|
69
69
|
const kinds = /* @__PURE__ */ new Set();
|
|
70
70
|
for (const status in declaredResponses) {
|
|
71
71
|
const declared = declaredResponses[status];
|
|
72
|
-
const descriptor = declared !== null && typeof declared === "object" && declared !== typeMarker &&
|
|
72
|
+
const descriptor = declared !== null && typeof declared === "object" && declared !== typeMarker && executableSchema(declared) === void 0 && "body" in declared ? declared : void 0;
|
|
73
73
|
const body = normalizeBody(descriptor ? descriptor.body : declared);
|
|
74
74
|
responses[status] = {
|
|
75
75
|
kind: body.kind,
|
|
@@ -179,7 +179,7 @@ async function invoke(endpoint, transport, input) {
|
|
|
179
179
|
try {
|
|
180
180
|
url = appendQuery(unchecked && typeof path === "string" ? path : renderPath(endpoint.path, path), query);
|
|
181
181
|
} catch (cause) {
|
|
182
|
-
throw new ClientError("request", "
|
|
182
|
+
throw new ClientError("request", "Cannot build request URL", method, void 0, meta, void 0, void 0, void 0, cause);
|
|
183
183
|
}
|
|
184
184
|
const bodyKind = unchecked ? input?.bodyKind ?? endpoint.body.kind : endpoint.body.kind;
|
|
185
185
|
const responseKinds = selectResponseKinds(endpoint, expectedStatus, discard);
|
|
@@ -226,7 +226,7 @@ async function invoke(endpoint, transport, input) {
|
|
|
226
226
|
} catch (failure) {
|
|
227
227
|
const cause = failure instanceof FailureWithCleanupError ? failure.cause : failure;
|
|
228
228
|
const cleanupFailed = cause instanceof ResponseCleanupError;
|
|
229
|
-
const wrapped = kind === "none" || cleanupFailed ? new ClientError("transport", `
|
|
229
|
+
const wrapped = kind === "none" || cleanupFailed ? new ClientError("transport", `Cannot release response (status ${status})`, method, responseUrl, meta, status, void 0, void 0, cleanupFailed ? cause.cause : cause) : new ClientError("response", `Cannot decode ${kind} response (status ${status})`, method, responseUrl, meta, status, void 0, void 0, cause);
|
|
230
230
|
throw preserveCleanupError(wrapped, failure);
|
|
231
231
|
}
|
|
232
232
|
if (!discard && responseSpec?.bodySchema !== void 0) {
|
package/dist/k6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as transportError, l as encodeFields, s as createUrlResolver, u as forEachField } from "./errors-
|
|
2
|
-
import { c as encodeJson, i as encodeUtf8, n as decodeUrlEncoded, o as prepareHeaders, r as decodeUtf8, t as decodeMultipart } from "./codec-
|
|
1
|
+
import { a as transportError, l as encodeFields, s as createUrlResolver, u as forEachField } from "./errors-25xWqgvt.js";
|
|
2
|
+
import { c as encodeJson, i as encodeUtf8, n as decodeUrlEncoded, o as prepareHeaders, r as decodeUtf8, t as decodeMultipart } from "./codec-CaVxvHce.js";
|
|
3
3
|
import http from "k6/http";
|
|
4
4
|
// src/transports/k6.ts
|
|
5
5
|
function binaryView(input) {
|
package/dist/playwright.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as transportError, l as encodeFields, n as FailureWithCleanupError, r as ResponseCleanupError, s as createUrlResolver } from "./errors-
|
|
2
|
-
import { a as appendResponseHeader, c as encodeJson, n as decodeUrlEncoded, o as prepareHeaders, s as asFormData, t as decodeMultipart } from "./codec-
|
|
1
|
+
import { a as transportError, l as encodeFields, n as FailureWithCleanupError, r as ResponseCleanupError, s as createUrlResolver } from "./errors-25xWqgvt.js";
|
|
2
|
+
import { a as appendResponseHeader, c as encodeJson, n as decodeUrlEncoded, o as prepareHeaders, s as asFormData, t as decodeMultipart } from "./codec-CaVxvHce.js";
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
4
|
// src/transports/playwright.ts
|
|
5
5
|
async function disposeAfterFailure(response, cause) {
|