@ostanin/podman 0.1.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.
- package/README.md +432 -0
- package/esm/_dnt.polyfills.d.ts +7 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/api/artifacts.d.ts +25 -0
- package/esm/api/artifacts.d.ts.map +1 -0
- package/esm/api/artifacts.js +89 -0
- package/esm/api/containers.d.ts +71 -0
- package/esm/api/containers.d.ts.map +1 -0
- package/esm/api/containers.js +234 -0
- package/esm/api/exec.d.ts +15 -0
- package/esm/api/exec.d.ts.map +1 -0
- package/esm/api/exec.js +45 -0
- package/esm/api/generate.d.ts +11 -0
- package/esm/api/generate.d.ts.map +1 -0
- package/esm/api/generate.js +24 -0
- package/esm/api/images.d.ts +55 -0
- package/esm/api/images.d.ts.map +1 -0
- package/esm/api/images.js +212 -0
- package/esm/api/kube.d.ts +13 -0
- package/esm/api/kube.d.ts.map +1 -0
- package/esm/api/kube.js +38 -0
- package/esm/api/manifests.d.ts +19 -0
- package/esm/api/manifests.d.ts.map +1 -0
- package/esm/api/manifests.js +60 -0
- package/esm/api/networks.d.ts +25 -0
- package/esm/api/networks.d.ts.map +1 -0
- package/esm/api/networks.js +95 -0
- package/esm/api/pods.d.ts +35 -0
- package/esm/api/pods.d.ts.map +1 -0
- package/esm/api/pods.js +120 -0
- package/esm/api/quadlets.d.ts +23 -0
- package/esm/api/quadlets.d.ts.map +1 -0
- package/esm/api/quadlets.js +56 -0
- package/esm/api/secrets.d.ts +17 -0
- package/esm/api/secrets.d.ts.map +1 -0
- package/esm/api/secrets.js +49 -0
- package/esm/api/system.d.ts +23 -0
- package/esm/api/system.d.ts.map +1 -0
- package/esm/api/system.js +98 -0
- package/esm/api/volumes.d.ts +23 -0
- package/esm/api/volumes.d.ts.map +1 -0
- package/esm/api/volumes.js +69 -0
- package/esm/client.d.ts +56 -0
- package/esm/client.d.ts.map +1 -0
- package/esm/client.js +63 -0
- package/esm/internal/query.d.ts +2 -0
- package/esm/internal/query.d.ts.map +1 -0
- package/esm/internal/query.js +24 -0
- package/esm/mod.d.ts +22 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +18 -0
- package/esm/package.json +3 -0
- package/esm/ssh_transport.d.ts +14 -0
- package/esm/ssh_transport.d.ts.map +1 -0
- package/esm/ssh_transport.js +85 -0
- package/esm/transport.d.ts +23 -0
- package/esm/transport.d.ts.map +1 -0
- package/esm/transport.js +112 -0
- package/esm/transport_core.d.ts +31 -0
- package/esm/transport_core.d.ts.map +1 -0
- package/esm/transport_core.js +75 -0
- package/esm/types/api.d.ts +61 -0
- package/esm/types/api.d.ts.map +1 -0
- package/esm/types/api.js +5 -0
- package/esm/types/errors.d.ts +21 -0
- package/esm/types/errors.d.ts.map +1 -0
- package/esm/types/errors.js +47 -0
- package/esm/types/openapi.d.ts +19552 -0
- package/esm/types/openapi.d.ts.map +1 -0
- package/esm/types/openapi.js +5 -0
- package/package.json +36 -0
- package/script/_dnt.polyfills.d.ts +7 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +2 -0
- package/script/api/artifacts.d.ts +25 -0
- package/script/api/artifacts.d.ts.map +1 -0
- package/script/api/artifacts.js +93 -0
- package/script/api/containers.d.ts +71 -0
- package/script/api/containers.d.ts.map +1 -0
- package/script/api/containers.js +238 -0
- package/script/api/exec.d.ts +15 -0
- package/script/api/exec.d.ts.map +1 -0
- package/script/api/exec.js +49 -0
- package/script/api/generate.d.ts +11 -0
- package/script/api/generate.d.ts.map +1 -0
- package/script/api/generate.js +28 -0
- package/script/api/images.d.ts +55 -0
- package/script/api/images.d.ts.map +1 -0
- package/script/api/images.js +216 -0
- package/script/api/kube.d.ts +13 -0
- package/script/api/kube.d.ts.map +1 -0
- package/script/api/kube.js +42 -0
- package/script/api/manifests.d.ts +19 -0
- package/script/api/manifests.d.ts.map +1 -0
- package/script/api/manifests.js +64 -0
- package/script/api/networks.d.ts +25 -0
- package/script/api/networks.d.ts.map +1 -0
- package/script/api/networks.js +99 -0
- package/script/api/pods.d.ts +35 -0
- package/script/api/pods.d.ts.map +1 -0
- package/script/api/pods.js +124 -0
- package/script/api/quadlets.d.ts +23 -0
- package/script/api/quadlets.d.ts.map +1 -0
- package/script/api/quadlets.js +60 -0
- package/script/api/secrets.d.ts +17 -0
- package/script/api/secrets.d.ts.map +1 -0
- package/script/api/secrets.js +53 -0
- package/script/api/system.d.ts +23 -0
- package/script/api/system.d.ts.map +1 -0
- package/script/api/system.js +102 -0
- package/script/api/volumes.d.ts +23 -0
- package/script/api/volumes.d.ts.map +1 -0
- package/script/api/volumes.js +73 -0
- package/script/client.d.ts +56 -0
- package/script/client.d.ts.map +1 -0
- package/script/client.js +67 -0
- package/script/internal/query.d.ts +2 -0
- package/script/internal/query.d.ts.map +1 -0
- package/script/internal/query.js +27 -0
- package/script/mod.d.ts +22 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +42 -0
- package/script/package.json +3 -0
- package/script/ssh_transport.d.ts +14 -0
- package/script/ssh_transport.d.ts.map +1 -0
- package/script/ssh_transport.js +121 -0
- package/script/transport.d.ts +23 -0
- package/script/transport.d.ts.map +1 -0
- package/script/transport.js +149 -0
- package/script/transport_core.d.ts +31 -0
- package/script/transport_core.d.ts.map +1 -0
- package/script/transport_core.js +78 -0
- package/script/types/api.d.ts +61 -0
- package/script/types/api.d.ts.map +1 -0
- package/script/types/api.js +6 -0
- package/script/types/errors.d.ts +21 -0
- package/script/types/errors.d.ts.map +1 -0
- package/script/types/errors.js +54 -0
- package/script/types/openapi.d.ts +19552 -0
- package/script/types/openapi.d.ts.map +1 -0
- package/script/types/openapi.js +6 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared transport types and builder used by both Deno and Node transports.
|
|
3
|
+
*
|
|
4
|
+
* Runtime-specific code (Unix sockets, TLS clients) lives in
|
|
5
|
+
* `transport.ts` (Deno) or `_node/transport.ts` (Node).
|
|
6
|
+
*/
|
|
7
|
+
export interface TransportResponse {
|
|
8
|
+
status: number;
|
|
9
|
+
json: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface Transport {
|
|
12
|
+
request(method: string, path: string, body?: unknown): Promise<TransportResponse>;
|
|
13
|
+
requestRaw(method: string, path: string, body?: BodyInit, headers?: Record<string, string>): Promise<Response>;
|
|
14
|
+
requestStream(method: string, path: string): Promise<ReadableStream<Uint8Array>>;
|
|
15
|
+
getAuthHeader(): string | undefined;
|
|
16
|
+
close(): void;
|
|
17
|
+
}
|
|
18
|
+
export type AuthOption = {
|
|
19
|
+
username: string;
|
|
20
|
+
password: string;
|
|
21
|
+
} | {
|
|
22
|
+
identityToken: string;
|
|
23
|
+
};
|
|
24
|
+
export interface DoFetchInit {
|
|
25
|
+
body?: BodyInit;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
signal?: AbortSignal | null;
|
|
28
|
+
}
|
|
29
|
+
export type DoFetchFn = (method: string, path: string, init?: DoFetchInit) => Promise<Response>;
|
|
30
|
+
export declare function buildTransport(doFetch: DoFetchFn, authHeader: string | undefined, closeFn: () => void): Transport;
|
|
31
|
+
//# sourceMappingURL=transport_core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport_core.d.ts","sourceRoot":"","sources":["../src/transport_core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CACL,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9B,UAAU,CACR,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,QAAQ,CAAC,CAAC;IAErB,aAAa,CACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IAEvC,aAAa,IAAI,MAAM,GAAG,SAAS,CAAC;IACpC,KAAK,IAAI,IAAI,CAAC;CACf;AAID,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9B,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,MAAM,SAAS,GAAG,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAIvB,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,EAClB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,MAAM,IAAI,GAClB,SAAS,CAiFX"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared transport types and builder used by both Deno and Node transports.
|
|
3
|
+
*
|
|
4
|
+
* Runtime-specific code (Unix sockets, TLS clients) lives in
|
|
5
|
+
* `transport.ts` (Deno) or `_node/transport.ts` (Node).
|
|
6
|
+
*/
|
|
7
|
+
import { extractMessage, PodmanError } from "./types/errors.js";
|
|
8
|
+
// ─── Shared builder ──────────────────────────────────────────────────────────
|
|
9
|
+
export function buildTransport(doFetch, authHeader, closeFn) {
|
|
10
|
+
return {
|
|
11
|
+
async request(method, path, body) {
|
|
12
|
+
const headers = {
|
|
13
|
+
"Accept": "application/json",
|
|
14
|
+
};
|
|
15
|
+
if (body !== undefined) {
|
|
16
|
+
headers["Content-Type"] = "application/json";
|
|
17
|
+
}
|
|
18
|
+
const res = await doFetch(method, path, {
|
|
19
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
20
|
+
headers,
|
|
21
|
+
});
|
|
22
|
+
const text = await res.text();
|
|
23
|
+
let json = null;
|
|
24
|
+
if (text.trim()) {
|
|
25
|
+
try {
|
|
26
|
+
json = JSON.parse(text);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new PodmanError({
|
|
30
|
+
status: res.status,
|
|
31
|
+
message: `Invalid JSON response: ${text.slice(0, 200)}`,
|
|
32
|
+
method,
|
|
33
|
+
path,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { status: res.status, json };
|
|
38
|
+
},
|
|
39
|
+
async requestRaw(method, path, body, headers) {
|
|
40
|
+
return await doFetch(method, path, { body, headers });
|
|
41
|
+
},
|
|
42
|
+
async requestStream(method, path) {
|
|
43
|
+
const res = await doFetch(method, path, {
|
|
44
|
+
headers: { "Accept": "application/json" },
|
|
45
|
+
signal: null,
|
|
46
|
+
});
|
|
47
|
+
if (res.status >= 400) {
|
|
48
|
+
const text = await res.text();
|
|
49
|
+
let json = null;
|
|
50
|
+
try {
|
|
51
|
+
json = text.trim() ? JSON.parse(text) : null;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// use raw text as message if JSON parse fails
|
|
55
|
+
}
|
|
56
|
+
throw new PodmanError({
|
|
57
|
+
status: res.status,
|
|
58
|
+
message: json
|
|
59
|
+
? extractMessage(json)
|
|
60
|
+
: text || "Stream request failed",
|
|
61
|
+
method,
|
|
62
|
+
path,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (!res.body) {
|
|
66
|
+
throw new Error(`No response body for ${method} ${path}`);
|
|
67
|
+
}
|
|
68
|
+
return res.body;
|
|
69
|
+
},
|
|
70
|
+
close: closeFn,
|
|
71
|
+
getAuthHeader() {
|
|
72
|
+
return authHeader;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type * from "./openapi.js";
|
|
2
|
+
import type { components, Mount } from "./openapi.js";
|
|
3
|
+
export type ContainerTopResponse = components["schemas"]["ContainerTopOKBody"];
|
|
4
|
+
export type ContainersPruneReport = components["schemas"]["ContainersPruneReportLibpod"];
|
|
5
|
+
export type ImageSummary = components["schemas"]["LibpodImageSummary"];
|
|
6
|
+
export type ImageRemoveReport = components["schemas"]["LibpodImagesRemoveReport"];
|
|
7
|
+
export type ImageHistory = components["schemas"]["HistoryResponse"];
|
|
8
|
+
export type ImagePruneReport = components["schemas"]["PruneReport"];
|
|
9
|
+
export type NetworkCreateOptions = components["schemas"]["networkCreateLibpod"];
|
|
10
|
+
export type NetworkDisconnectOptions = components["schemas"]["DisconnectOptions"];
|
|
11
|
+
export type VolumePruneReport = components["schemas"]["PruneReport"];
|
|
12
|
+
export type OciMount = {
|
|
13
|
+
destination: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
source?: string;
|
|
16
|
+
options?: string[];
|
|
17
|
+
};
|
|
18
|
+
type _SpecGenerator = components["schemas"]["SpecGenerator"];
|
|
19
|
+
export type SpecGenerator = Omit<_SpecGenerator, "mounts"> & {
|
|
20
|
+
mounts?: (Mount | OciMount)[];
|
|
21
|
+
};
|
|
22
|
+
export type ImageSearchResult = NonNullable<components["responses"]["registrySearchResponse"]["content"]["application/json"]>;
|
|
23
|
+
/** Options for creating an exec session inside a container. */
|
|
24
|
+
export type ExecCreateConfig = {
|
|
25
|
+
/** Attach to stderr of the exec command. */
|
|
26
|
+
AttachStderr?: boolean;
|
|
27
|
+
/** Attach to stdin of the exec command. */
|
|
28
|
+
AttachStdin?: boolean;
|
|
29
|
+
/** Attach to stdout of the exec command. */
|
|
30
|
+
AttachStdout?: boolean;
|
|
31
|
+
/** Command to run, as a string or array of strings. */
|
|
32
|
+
Cmd?: string[];
|
|
33
|
+
/** Override the key sequence for detaching a container. */
|
|
34
|
+
DetachKeys?: string;
|
|
35
|
+
/** A list of environment variables in the form ["VAR=value", ...]. */
|
|
36
|
+
Env?: string[];
|
|
37
|
+
/** Runs the exec process with extended privileges. */
|
|
38
|
+
Privileged?: boolean;
|
|
39
|
+
/** Allocate a pseudo-TTY. */
|
|
40
|
+
Tty?: boolean;
|
|
41
|
+
/** The user, and optionally, group to run the exec process inside the container. */
|
|
42
|
+
User?: string;
|
|
43
|
+
/** The working directory for the exec process inside the container. */
|
|
44
|
+
WorkingDir?: string;
|
|
45
|
+
};
|
|
46
|
+
/** Options for starting an exec session. */
|
|
47
|
+
export type ExecStartConfig = {
|
|
48
|
+
/** Detach from the command. */
|
|
49
|
+
Detach?: boolean;
|
|
50
|
+
/** Allocate a pseudo-TTY. */
|
|
51
|
+
Tty?: boolean;
|
|
52
|
+
/** Height of the TTY session in characters. */
|
|
53
|
+
h?: number;
|
|
54
|
+
/** Width of the TTY session in characters. */
|
|
55
|
+
w?: number;
|
|
56
|
+
};
|
|
57
|
+
export interface ContainerChange {
|
|
58
|
+
Path: string;
|
|
59
|
+
Kind: number;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAOA,mBAAmB,cAAc,CAAC;AAElC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAItD,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC;AAC/E,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,6BAA6B,CAAC,CAAC;AACzF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAC;AAClF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC;AACpE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC;AACpE,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC;AAChF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,mBAAmB,CAAC,CAAC;AAClF,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC;AAOrE,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,KAAK,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC;AAC7D,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,GAAG;IAC3D,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC;CAC/B,CAAC;AAIF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CACzC,UAAU,CAAC,WAAW,CAAC,CAAC,wBAAwB,CAAC,CAAC,SAAS,CAAC,CAC1D,kBAAkB,CACnB,CACF,CAAC;AAIF,+DAA+D;AAC/D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,4CAA4C;IAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG;IAC5B,+BAA+B;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,+CAA+C;IAC/C,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,8CAA8C;IAC9C,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/esm/types/api.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Friendly aliases for awkwardly-named schemas, custom types not in the OpenAPI spec,
|
|
2
|
+
// and schema overrides. Query param types are auto-generated in openapi.ts.
|
|
3
|
+
//
|
|
4
|
+
// Run `deno task generate-types` to regenerate types/openapi.ts from Podman's swagger spec.
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Error thrown by the Podman client on non-404 API failures. Includes HTTP status, method, and path. */
|
|
2
|
+
export declare class PodmanError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly method: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
constructor(opts: {
|
|
7
|
+
status: number;
|
|
8
|
+
message: string;
|
|
9
|
+
method: string;
|
|
10
|
+
path: string;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export declare function extractMessage(json: unknown): string;
|
|
14
|
+
/** Create a PodmanError from a status code and raw JSON body. */
|
|
15
|
+
export declare function createPodmanError(status: number, json: unknown, method: string, path: string): PodmanError;
|
|
16
|
+
/**
|
|
17
|
+
* Read a raw Response body and throw a PodmanError.
|
|
18
|
+
* Use when a `requestRaw()` call returned a non-success status.
|
|
19
|
+
*/
|
|
20
|
+
export declare function throwRawError(res: Response, method: string, path: string): Promise<never>;
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd;CAOF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOpD;AAED,iEAAiE;AACjE,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,WAAW,CAOb;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,KAAK,CAAC,CAShB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Error thrown by the Podman client on non-404 API failures. Includes HTTP status, method, and path. */
|
|
2
|
+
export class PodmanError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
method;
|
|
5
|
+
path;
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
super(opts.message);
|
|
8
|
+
this.name = "PodmanError";
|
|
9
|
+
this.status = opts.status;
|
|
10
|
+
this.method = opts.method;
|
|
11
|
+
this.path = opts.path;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function extractMessage(json) {
|
|
15
|
+
if (json && typeof json === "object") {
|
|
16
|
+
const obj = json;
|
|
17
|
+
if (typeof obj.message === "string")
|
|
18
|
+
return obj.message;
|
|
19
|
+
if (typeof obj.cause === "string")
|
|
20
|
+
return obj.cause;
|
|
21
|
+
}
|
|
22
|
+
return "Unknown error";
|
|
23
|
+
}
|
|
24
|
+
/** Create a PodmanError from a status code and raw JSON body. */
|
|
25
|
+
export function createPodmanError(status, json, method, path) {
|
|
26
|
+
return new PodmanError({
|
|
27
|
+
status,
|
|
28
|
+
message: extractMessage(json),
|
|
29
|
+
method,
|
|
30
|
+
path,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read a raw Response body and throw a PodmanError.
|
|
35
|
+
* Use when a `requestRaw()` call returned a non-success status.
|
|
36
|
+
*/
|
|
37
|
+
export async function throwRawError(res, method, path) {
|
|
38
|
+
const text = await res.text();
|
|
39
|
+
let json = null;
|
|
40
|
+
try {
|
|
41
|
+
json = text.trim() ? JSON.parse(text) : null;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw createPodmanError(res.status, { message: text }, method, path);
|
|
45
|
+
}
|
|
46
|
+
throw createPodmanError(res.status, json, method, path);
|
|
47
|
+
}
|