@devhelm/sdk 0.1.4 → 0.2.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/dist/errors.d.ts +98 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +171 -27
- package/dist/errors.js.map +1 -1
- package/dist/generated/api.d.ts +16484 -3199
- package/dist/generated/api.d.ts.map +1 -1
- package/dist/generated/schemas.d.ts +9495 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +3547 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/http.d.ts +33 -19
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +120 -50
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/alert-channels.d.ts +2 -4
- package/dist/resources/alert-channels.d.ts.map +1 -1
- package/dist/resources/alert-channels.js +12 -12
- package/dist/resources/alert-channels.js.map +1 -1
- package/dist/resources/api-keys.d.ts.map +1 -1
- package/dist/resources/api-keys.js +8 -6
- package/dist/resources/api-keys.js.map +1 -1
- package/dist/resources/dependencies.d.ts +7 -1
- package/dist/resources/dependencies.d.ts.map +1 -1
- package/dist/resources/dependencies.js +14 -9
- package/dist/resources/dependencies.js.map +1 -1
- package/dist/resources/deploy-lock.d.ts +9 -1
- package/dist/resources/deploy-lock.d.ts.map +1 -1
- package/dist/resources/deploy-lock.js +21 -8
- package/dist/resources/deploy-lock.js.map +1 -1
- package/dist/resources/environments.d.ts.map +1 -1
- package/dist/resources/environments.js +11 -10
- package/dist/resources/environments.js.map +1 -1
- package/dist/resources/incidents.d.ts +3 -5
- package/dist/resources/incidents.d.ts.map +1 -1
- package/dist/resources/incidents.js +12 -15
- package/dist/resources/incidents.js.map +1 -1
- package/dist/resources/monitors.d.ts +2 -2
- package/dist/resources/monitors.d.ts.map +1 -1
- package/dist/resources/monitors.js +16 -18
- package/dist/resources/monitors.js.map +1 -1
- package/dist/resources/notification-policies.d.ts.map +1 -1
- package/dist/resources/notification-policies.js +11 -10
- package/dist/resources/notification-policies.js.map +1 -1
- package/dist/resources/resource-groups.d.ts +2 -2
- package/dist/resources/resource-groups.d.ts.map +1 -1
- package/dist/resources/resource-groups.js +15 -13
- package/dist/resources/resource-groups.js.map +1 -1
- package/dist/resources/secrets.d.ts.map +1 -1
- package/dist/resources/secrets.js +10 -8
- package/dist/resources/secrets.js.map +1 -1
- package/dist/resources/status-pages.d.ts +12 -24
- package/dist/resources/status-pages.d.ts.map +1 -1
- package/dist/resources/status-pages.js +54 -44
- package/dist/resources/status-pages.js.map +1 -1
- package/dist/resources/status.d.ts.map +1 -1
- package/dist/resources/status.js +3 -3
- package/dist/resources/status.js.map +1 -1
- package/dist/resources/tags.d.ts.map +1 -1
- package/dist/resources/tags.js +11 -10
- package/dist/resources/tags.js.map +1 -1
- package/dist/resources/webhooks.d.ts +2 -4
- package/dist/resources/webhooks.d.ts.map +1 -1
- package/dist/resources/webhooks.js +12 -12
- package/dist/resources/webhooks.js.map +1 -1
- package/dist/schemas.d.ts +5159 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +160 -0
- package/dist/schemas.js.map +1 -0
- package/dist/types.d.ts +72 -58
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +44 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +71 -0
- package/dist/validation.js.map +1 -0
- package/package.json +10 -5
package/dist/errors.d.ts
CHANGED
|
@@ -1,12 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ErrorResponse } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Error taxonomy for the DevHelm SDK (P4 — see
|
|
5
|
+
* `mono/cowork/design/040-codegen-policies.md`):
|
|
6
|
+
*
|
|
7
|
+
* DevhelmValidationError — local request/response shape validation failed
|
|
8
|
+
* DevhelmApiError — API returned a non-2xx (with status + body)
|
|
9
|
+
* DevhelmTransportError — request never reached the server
|
|
10
|
+
*
|
|
11
|
+
* All three inherit from `DevhelmError` for catch-all sites.
|
|
12
|
+
*/
|
|
2
13
|
export declare class DevhelmError extends Error {
|
|
3
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Coarse machine-readable category for switching on error class without
|
|
16
|
+
* `instanceof` chains. Standardised across every {@link DevhelmError}
|
|
17
|
+
* subclass so `err.code` is always populated:
|
|
18
|
+
* - {@link DevhelmValidationError} → `"VALIDATION"`
|
|
19
|
+
* - {@link DevhelmTransportError} → `"TRANSPORT"`
|
|
20
|
+
* - {@link DevhelmApiError} → server-supplied (e.g. `"NOT_FOUND"`)
|
|
21
|
+
*/
|
|
22
|
+
readonly code: string;
|
|
23
|
+
constructor(message: string, code?: string);
|
|
24
|
+
}
|
|
25
|
+
export interface ValidationIssue {
|
|
26
|
+
readonly path: ReadonlyArray<string | number>;
|
|
27
|
+
readonly message: string;
|
|
28
|
+
readonly code: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class DevhelmValidationError extends DevhelmError {
|
|
31
|
+
readonly issues: ReadonlyArray<ValidationIssue>;
|
|
32
|
+
constructor(message: string, issues?: ReadonlyArray<ValidationIssue>);
|
|
33
|
+
static fromZodError(error: z.ZodError, prefix: string): DevhelmValidationError;
|
|
34
|
+
}
|
|
35
|
+
export interface DevhelmApiErrorOptions {
|
|
36
|
+
/** Human-readable detail extracted from the response body, if any. */
|
|
37
|
+
detail?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Coarse machine-readable category from `ErrorResponse.code`
|
|
40
|
+
* (e.g. `NOT_FOUND`, `RATE_LIMITED`). Switch on this — never on
|
|
41
|
+
* `message` — when adapting behaviour to specific error classes.
|
|
42
|
+
*/
|
|
43
|
+
code?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Per-request id from the API's `X-Request-Id` response header
|
|
46
|
+
* (and mirrored in `ErrorResponse.requestId`). Always include it
|
|
47
|
+
* when filing a support ticket.
|
|
48
|
+
*/
|
|
49
|
+
requestId?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Parsed canonical error envelope (`ErrorResponse` from the OpenAPI
|
|
52
|
+
* spec) when the response matched the contract. `undefined` for
|
|
53
|
+
* non-conforming bodies (e.g. proxy 502 HTML, plain text, or JSON
|
|
54
|
+
* shapes that predate the canonical envelope).
|
|
55
|
+
*/
|
|
56
|
+
body?: ErrorResponse;
|
|
57
|
+
/**
|
|
58
|
+
* Raw response body — the unparsed JSON value or response text.
|
|
59
|
+
* Always populated when there was a body. Useful for debugging
|
|
60
|
+
* non-conforming responses without losing the original shape.
|
|
61
|
+
*/
|
|
62
|
+
rawBody?: unknown;
|
|
63
|
+
}
|
|
64
|
+
export declare class DevhelmApiError extends DevhelmError {
|
|
4
65
|
readonly status: number;
|
|
5
66
|
readonly detail: string | undefined;
|
|
6
|
-
|
|
67
|
+
readonly requestId: string | undefined;
|
|
68
|
+
readonly body: ErrorResponse | undefined;
|
|
69
|
+
readonly rawBody: unknown;
|
|
70
|
+
constructor(message: string, status: number, options?: DevhelmApiErrorOptions);
|
|
71
|
+
}
|
|
72
|
+
export declare class DevhelmAuthError extends DevhelmApiError {
|
|
73
|
+
constructor(message: string, status: number, options?: DevhelmApiErrorOptions);
|
|
74
|
+
}
|
|
75
|
+
export declare class DevhelmNotFoundError extends DevhelmApiError {
|
|
76
|
+
constructor(message: string, status: number, options?: DevhelmApiErrorOptions);
|
|
77
|
+
}
|
|
78
|
+
export declare class DevhelmConflictError extends DevhelmApiError {
|
|
79
|
+
constructor(message: string, status: number, options?: DevhelmApiErrorOptions);
|
|
80
|
+
}
|
|
81
|
+
export declare class DevhelmRateLimitError extends DevhelmApiError {
|
|
82
|
+
constructor(message: string, status: number, options?: DevhelmApiErrorOptions);
|
|
83
|
+
}
|
|
84
|
+
export declare class DevhelmServerError extends DevhelmApiError {
|
|
85
|
+
constructor(message: string, status: number, options?: DevhelmApiErrorOptions);
|
|
7
86
|
}
|
|
8
|
-
export declare class
|
|
9
|
-
constructor(message: string,
|
|
87
|
+
export declare class DevhelmTransportError extends DevhelmError {
|
|
88
|
+
constructor(message: string, options?: {
|
|
89
|
+
cause?: unknown;
|
|
90
|
+
});
|
|
10
91
|
}
|
|
11
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Map an HTTP error response to a typed {@link DevhelmApiError} subclass.
|
|
94
|
+
*
|
|
95
|
+
* `requestId` is the value of the `X-Request-Id` response header. Pass it
|
|
96
|
+
* in from the call site so the SDK still surfaces the id even when the
|
|
97
|
+
* server returned a non-JSON body (e.g. an HTML error page from a
|
|
98
|
+
* misconfigured proxy). The header takes precedence over any value found
|
|
99
|
+
* in the body.
|
|
100
|
+
*/
|
|
101
|
+
export declare function errorFromResponse(status: number, body: string, options?: {
|
|
102
|
+
requestId?: string;
|
|
103
|
+
}): DevhelmApiError;
|
|
12
104
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAA;AAErB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AAE7C;;;;;;;;;GASG;AAEH,qBAAa,YAAa,SAAQ,KAAK;IACrC;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBAET,OAAO,EAAE,MAAM,EAAE,IAAI,SAAU;CAK5C;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,E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;gBAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;CAI9E;AAED,qBAAa,qBAAsB,SAAQ,eAAe;gBAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;CAI9E;AAED,qBAAa,kBAAmB,SAAQ,eAAe;gBACzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;CAI9E;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAC;CASzD;AAiBD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAC7B,eAAe,CAmDjB"}
|
package/dist/errors.js
CHANGED
|
@@ -1,45 +1,189 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ErrorResponseSchema } from './schemas.js';
|
|
3
|
+
/**
|
|
4
|
+
* Error taxonomy for the DevHelm SDK (P4 — see
|
|
5
|
+
* `mono/cowork/design/040-codegen-policies.md`):
|
|
6
|
+
*
|
|
7
|
+
* DevhelmValidationError — local request/response shape validation failed
|
|
8
|
+
* DevhelmApiError — API returned a non-2xx (with status + body)
|
|
9
|
+
* DevhelmTransportError — request never reached the server
|
|
10
|
+
*
|
|
11
|
+
* All three inherit from `DevhelmError` for catch-all sites.
|
|
12
|
+
*/
|
|
1
13
|
export class DevhelmError extends Error {
|
|
14
|
+
/**
|
|
15
|
+
* Coarse machine-readable category for switching on error class without
|
|
16
|
+
* `instanceof` chains. Standardised across every {@link DevhelmError}
|
|
17
|
+
* subclass so `err.code` is always populated:
|
|
18
|
+
* - {@link DevhelmValidationError} → `"VALIDATION"`
|
|
19
|
+
* - {@link DevhelmTransportError} → `"TRANSPORT"`
|
|
20
|
+
* - {@link DevhelmApiError} → server-supplied (e.g. `"NOT_FOUND"`)
|
|
21
|
+
*/
|
|
2
22
|
code;
|
|
3
|
-
|
|
4
|
-
detail;
|
|
5
|
-
constructor(code, message, status, detail) {
|
|
23
|
+
constructor(message, code = 'ERROR') {
|
|
6
24
|
super(message);
|
|
7
25
|
this.name = 'DevhelmError';
|
|
8
26
|
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class DevhelmValidationError extends DevhelmError {
|
|
30
|
+
issues;
|
|
31
|
+
constructor(message, issues = []) {
|
|
32
|
+
super(message, 'VALIDATION');
|
|
33
|
+
this.name = 'DevhelmValidationError';
|
|
34
|
+
this.issues = issues;
|
|
35
|
+
}
|
|
36
|
+
static fromZodError(error, prefix) {
|
|
37
|
+
const issues = error.issues.map((i) => ({
|
|
38
|
+
path: [...i.path],
|
|
39
|
+
message: i.message,
|
|
40
|
+
code: i.code,
|
|
41
|
+
}));
|
|
42
|
+
const summary = issues
|
|
43
|
+
.slice(0, 5)
|
|
44
|
+
.map((i) => `${i.path.join('.') || '<root>'}: ${i.message}`)
|
|
45
|
+
.join('; ');
|
|
46
|
+
return new DevhelmValidationError(`${prefix}: ${summary}`, issues);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class DevhelmApiError extends DevhelmError {
|
|
50
|
+
status;
|
|
51
|
+
detail;
|
|
52
|
+
requestId;
|
|
53
|
+
body;
|
|
54
|
+
rawBody;
|
|
55
|
+
constructor(message, status, options) {
|
|
56
|
+
// Server-supplied code wins; fall back to a generic API-error label so
|
|
57
|
+
// `err.code` is never undefined for catch sites switching on category.
|
|
58
|
+
super(message, options?.code ?? 'API_ERROR');
|
|
59
|
+
this.name = 'DevhelmApiError';
|
|
9
60
|
this.status = status;
|
|
10
|
-
this.detail = detail;
|
|
61
|
+
this.detail = options?.detail;
|
|
62
|
+
this.requestId = options?.requestId;
|
|
63
|
+
this.body = options?.body;
|
|
64
|
+
this.rawBody = options?.rawBody;
|
|
11
65
|
}
|
|
12
66
|
}
|
|
13
|
-
export class
|
|
14
|
-
constructor(message, status) {
|
|
15
|
-
super(
|
|
16
|
-
this.name = '
|
|
67
|
+
export class DevhelmAuthError extends DevhelmApiError {
|
|
68
|
+
constructor(message, status, options) {
|
|
69
|
+
super(message, status, options);
|
|
70
|
+
this.name = 'DevhelmAuthError';
|
|
17
71
|
}
|
|
18
72
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const parsed = JSON.parse(body);
|
|
24
|
-
message = String(parsed['message'] ?? parsed['error'] ?? message);
|
|
25
|
-
detail = parsed['detail'] ? String(parsed['detail']) : undefined;
|
|
73
|
+
export class DevhelmNotFoundError extends DevhelmApiError {
|
|
74
|
+
constructor(message, status, options) {
|
|
75
|
+
super(message, status, options);
|
|
76
|
+
this.name = 'DevhelmNotFoundError';
|
|
26
77
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
78
|
+
}
|
|
79
|
+
export class DevhelmConflictError extends DevhelmApiError {
|
|
80
|
+
constructor(message, status, options) {
|
|
81
|
+
super(message, status, options);
|
|
82
|
+
this.name = 'DevhelmConflictError';
|
|
30
83
|
}
|
|
31
|
-
|
|
32
|
-
|
|
84
|
+
}
|
|
85
|
+
export class DevhelmRateLimitError extends DevhelmApiError {
|
|
86
|
+
constructor(message, status, options) {
|
|
87
|
+
super(message, status, options);
|
|
88
|
+
this.name = 'DevhelmRateLimitError';
|
|
33
89
|
}
|
|
34
|
-
|
|
35
|
-
|
|
90
|
+
}
|
|
91
|
+
export class DevhelmServerError extends DevhelmApiError {
|
|
92
|
+
constructor(message, status, options) {
|
|
93
|
+
super(message, status, options);
|
|
94
|
+
this.name = 'DevhelmServerError';
|
|
36
95
|
}
|
|
37
|
-
|
|
38
|
-
|
|
96
|
+
}
|
|
97
|
+
export class DevhelmTransportError extends DevhelmError {
|
|
98
|
+
constructor(message, options) {
|
|
99
|
+
super(message, 'TRANSPORT');
|
|
100
|
+
this.name = 'DevhelmTransportError';
|
|
101
|
+
if (options?.cause !== undefined) {
|
|
102
|
+
// Node 16+ supports the standard cause chain; we set it explicitly so
|
|
103
|
+
// the instance shape stays consistent across runtimes.
|
|
104
|
+
;
|
|
105
|
+
this.cause = options.cause;
|
|
106
|
+
}
|
|
39
107
|
}
|
|
40
|
-
|
|
41
|
-
|
|
108
|
+
}
|
|
109
|
+
// Lenient shape used to extract a human-readable message + detail from
|
|
110
|
+
// non-conforming error bodies (e.g. older deployments that emit
|
|
111
|
+
// `{message, error, detail}` instead of the canonical `ErrorResponse`,
|
|
112
|
+
// or proxies that include their own shape).
|
|
113
|
+
const FallbackErrorShape = z
|
|
114
|
+
.object({
|
|
115
|
+
message: z.string().optional(),
|
|
116
|
+
error: z.string().optional(),
|
|
117
|
+
detail: z.string().optional(),
|
|
118
|
+
code: z.string().optional(),
|
|
119
|
+
requestId: z.string().optional(),
|
|
120
|
+
request_id: z.string().optional(),
|
|
121
|
+
})
|
|
122
|
+
.passthrough();
|
|
123
|
+
/**
|
|
124
|
+
* Map an HTTP error response to a typed {@link DevhelmApiError} subclass.
|
|
125
|
+
*
|
|
126
|
+
* `requestId` is the value of the `X-Request-Id` response header. Pass it
|
|
127
|
+
* in from the call site so the SDK still surfaces the id even when the
|
|
128
|
+
* server returned a non-JSON body (e.g. an HTML error page from a
|
|
129
|
+
* misconfigured proxy). The header takes precedence over any value found
|
|
130
|
+
* in the body.
|
|
131
|
+
*/
|
|
132
|
+
export function errorFromResponse(status, body, options) {
|
|
133
|
+
let message = `HTTP ${status}`;
|
|
134
|
+
let detail;
|
|
135
|
+
let code;
|
|
136
|
+
let bodyRequestId;
|
|
137
|
+
let parsed;
|
|
138
|
+
let rawBody = body || undefined;
|
|
139
|
+
if (body) {
|
|
140
|
+
try {
|
|
141
|
+
const json = JSON.parse(body);
|
|
142
|
+
rawBody = json;
|
|
143
|
+
const canonical = ErrorResponseSchema.safeParse(json);
|
|
144
|
+
if (canonical.success) {
|
|
145
|
+
parsed = canonical.data;
|
|
146
|
+
message = parsed.message;
|
|
147
|
+
code = parsed.code;
|
|
148
|
+
bodyRequestId = parsed.requestId ?? undefined;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const fallback = FallbackErrorShape.safeParse(json);
|
|
152
|
+
if (fallback.success) {
|
|
153
|
+
message = fallback.data.message ?? fallback.data.error ?? message;
|
|
154
|
+
detail = fallback.data.detail;
|
|
155
|
+
code = fallback.data.code;
|
|
156
|
+
bodyRequestId = fallback.data.requestId ?? fallback.data.request_id;
|
|
157
|
+
if (message === `HTTP ${status}` && !fallback.data.message && !fallback.data.error) {
|
|
158
|
+
message = body;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
message = body;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
message = body;
|
|
168
|
+
}
|
|
42
169
|
}
|
|
43
|
-
|
|
170
|
+
const opts = {
|
|
171
|
+
detail,
|
|
172
|
+
code,
|
|
173
|
+
requestId: options?.requestId ?? bodyRequestId,
|
|
174
|
+
body: parsed,
|
|
175
|
+
rawBody,
|
|
176
|
+
};
|
|
177
|
+
if (status === 401 || status === 403)
|
|
178
|
+
return new DevhelmAuthError(message, status, opts);
|
|
179
|
+
if (status === 404)
|
|
180
|
+
return new DevhelmNotFoundError(message, status, opts);
|
|
181
|
+
if (status === 409)
|
|
182
|
+
return new DevhelmConflictError(message, status, opts);
|
|
183
|
+
if (status === 429)
|
|
184
|
+
return new DevhelmRateLimitError(message, status, opts);
|
|
185
|
+
if (status >= 500)
|
|
186
|
+
return new DevhelmServerError(message, status, opts);
|
|
187
|
+
return new DevhelmApiError(message, status, opts);
|
|
44
188
|
}
|
|
45
189
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAA;AACrB,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAA;AAGhD;;;;;;;;;GASG;AAEH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC;;;;;;;OAOG;IACM,IAAI,CAAQ;IAErB,YAAY,OAAe,EAAE,IAAI,GAAG,OAAO;QACzC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAQD,MAAM,OAAO,sBAAuB,SAAQ,YAAY;IAC7C,MAAM,CAAgC;IAE/C,YAAY,OAAe,EAAE,SAAyC,EAAE;QACtE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,KAAiB,EAAE,MAAc;QACnD,MAAM,MAAM,GAAsB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACzD,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAA2B;YAC3C,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,IAAI,EAAE,CAAC,CAAC,IAAI;SACb,CAAC,CAAC,CAAA;QACH,MAAM,OAAO,GAAG,MAAM;aACnB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IA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