@databricks/sdk-core 0.34.0 → 0.36.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/apierror/apierror.d.ts +52 -49
- package/dist/apierror/apierror.d.ts.map +1 -1
- package/dist/apierror/apierror.js +124 -172
- package/dist/apierror/apierror.js.map +1 -1
- package/dist/apierror/codes/codes.d.ts +113 -113
- package/dist/apierror/codes/codes.d.ts.map +1 -1
- package/dist/apierror/codes/codes.js +24 -115
- package/dist/apierror/codes/codes.js.map +1 -1
- package/dist/apierror/codes/index.d.ts +2 -7
- package/dist/apierror/codes/index.js +3 -7
- package/dist/apierror/details.d.ts +104 -101
- package/dist/apierror/details.d.ts.map +1 -1
- package/dist/apierror/details.js +151 -226
- package/dist/apierror/details.js.map +1 -1
- package/dist/apierror/index.d.ts +3 -8
- package/dist/apierror/index.js +3 -7
- package/dist/clientinfo/agent.d.ts +6 -3
- package/dist/clientinfo/agent.d.ts.map +1 -1
- package/dist/clientinfo/agent.js +134 -112
- package/dist/clientinfo/agent.js.map +1 -1
- package/dist/clientinfo/base.d.ts +13 -15
- package/dist/clientinfo/base.d.ts.map +1 -1
- package/dist/clientinfo/base.js +50 -50
- package/dist/clientinfo/base.js.map +1 -1
- package/dist/clientinfo/clientinfo.d.ts +40 -38
- package/dist/clientinfo/clientinfo.d.ts.map +1 -1
- package/dist/clientinfo/clientinfo.js +78 -88
- package/dist/clientinfo/clientinfo.js.map +1 -1
- package/dist/clientinfo/default.browser.d.ts +6 -10
- package/dist/clientinfo/default.browser.d.ts.map +1 -1
- package/dist/clientinfo/default.browser.js +24 -16
- package/dist/clientinfo/default.browser.js.map +1 -1
- package/dist/clientinfo/default.d.ts +8 -4
- package/dist/clientinfo/default.d.ts.map +1 -1
- package/dist/clientinfo/default.js +157 -102
- package/dist/clientinfo/default.js.map +1 -1
- package/dist/clientinfo/index.browser.d.ts +4 -5
- package/dist/clientinfo/index.browser.js +5 -4
- package/dist/clientinfo/index.d.ts +4 -5
- package/dist/clientinfo/index.js +5 -4
- package/dist/clientinfo/meta-harness.d.ts +6 -3
- package/dist/clientinfo/meta-harness.d.ts.map +1 -1
- package/dist/clientinfo/meta-harness.js +30 -46
- package/dist/clientinfo/meta-harness.js.map +1 -1
- package/dist/http/http.d.ts +25 -22
- package/dist/http/http.d.ts.map +1 -1
- package/dist/http/http.js +24 -34
- package/dist/http/http.js.map +1 -1
- package/dist/http/index.d.ts +2 -8
- package/dist/http/index.js +3 -7
- package/dist/index.d.ts +1 -6
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +2 -8
- package/dist/logger/index.js +3 -7
- package/dist/logger/logger.d.ts +26 -23
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +46 -60
- package/dist/logger/logger.js.map +1 -1
- package/dist/ops/execute.d.ts +7 -3
- package/dist/ops/execute.d.ts.map +1 -1
- package/dist/ops/execute.js +55 -67
- package/dist/ops/execute.js.map +1 -1
- package/dist/ops/index.d.ts +5 -12
- package/dist/ops/index.js +4 -9
- package/dist/ops/limiter.d.ts +5 -2
- package/dist/ops/limiter.d.ts.map +1 -1
- package/dist/ops/limiter.js +0 -2
- package/dist/ops/options.d.ts +23 -19
- package/dist/ops/options.d.ts.map +1 -1
- package/dist/ops/options.js +0 -2
- package/dist/ops/retrier.d.ts +34 -31
- package/dist/ops/retrier.d.ts.map +1 -1
- package/dist/ops/retrier.js +55 -66
- package/dist/ops/retrier.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/profiles/errors.d.ts +7 -4
- package/dist/profiles/errors.d.ts.map +1 -1
- package/dist/profiles/errors.js +16 -17
- package/dist/profiles/errors.js.map +1 -1
- package/dist/profiles/index.browser.d.ts +4 -10
- package/dist/profiles/index.browser.js +4 -8
- package/dist/profiles/index.d.ts +5 -15
- package/dist/profiles/index.js +5 -13
- package/dist/profiles/ini.d.ts +6 -3
- package/dist/profiles/ini.d.ts.map +1 -1
- package/dist/profiles/ini.js +60 -108
- package/dist/profiles/ini.js.map +1 -1
- package/dist/profiles/profile.d.ts +66 -67
- package/dist/profiles/profile.d.ts.map +1 -1
- package/dist/profiles/profile.js +89 -84
- package/dist/profiles/profile.js.map +1 -1
- package/dist/profiles/resolve.d.ts +8 -9
- package/dist/profiles/resolve.d.ts.map +1 -1
- package/dist/profiles/resolve.js +140 -185
- package/dist/profiles/resolve.js.map +1 -1
- package/dist/profiles/secret.d.ts +15 -12
- package/dist/profiles/secret.d.ts.map +1 -1
- package/dist/profiles/secret.js +38 -35
- package/dist/profiles/secret.js.map +1 -1
- package/dist/wkt/fieldmask.d.ts +23 -20
- package/dist/wkt/fieldmask.d.ts.map +1 -1
- package/dist/wkt/fieldmask.js +53 -62
- package/dist/wkt/fieldmask.js.map +1 -1
- package/dist/wkt/index.d.ts +3 -4
- package/dist/wkt/index.js +3 -2
- package/dist/wkt/value.d.ts +6 -3
- package/dist/wkt/value.d.ts.map +1 -1
- package/dist/wkt/value.js +0 -2
- package/package.json +2 -2
- package/dist/apierror/codes/index.d.ts.map +0 -1
- package/dist/apierror/codes/index.js.map +0 -1
- package/dist/apierror/index.d.ts.map +0 -1
- package/dist/apierror/index.js.map +0 -1
- package/dist/clientinfo/index.browser.d.ts.map +0 -1
- package/dist/clientinfo/index.browser.js.map +0 -1
- package/dist/clientinfo/index.d.ts.map +0 -1
- package/dist/clientinfo/index.js.map +0 -1
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/ops/index.d.ts.map +0 -1
- package/dist/ops/index.js.map +0 -1
- package/dist/ops/limiter.js.map +0 -1
- package/dist/ops/options.js.map +0 -1
- package/dist/profiles/index.browser.d.ts.map +0 -1
- package/dist/profiles/index.browser.js.map +0 -1
- package/dist/profiles/index.d.ts.map +0 -1
- package/dist/profiles/index.js.map +0 -1
- package/dist/wkt/index.d.ts.map +0 -1
- package/dist/wkt/index.js.map +0 -1
- package/dist/wkt/value.js.map +0 -1
package/dist/apierror/details.js
CHANGED
|
@@ -1,250 +1,175 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/apierror/details.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
// Zod schemas for the wire format (snake_case JSON from the API).
|
|
9
|
-
//
|
|
10
|
-
// Each schema validates the snake_case wire format from the API and transforms
|
|
11
|
-
// it into the camelCase TypeScript interface. Nullish fields default to their
|
|
12
|
-
// zero values (empty string, empty array, empty record) when absent or null.
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// Reusable schema fragments. Nullish fields default to their zero values
|
|
15
|
-
// (empty string, empty array, empty record) when absent or null.
|
|
16
|
-
const nullishString = z
|
|
17
|
-
.string()
|
|
18
|
-
.nullish()
|
|
19
|
-
.transform(v => v ?? '');
|
|
5
|
+
* Defines structured error detail types for API errors.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
const nullishString = z.string().nullish().transform((v) => v ?? "");
|
|
20
10
|
const errorInfoSchema = z.object({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.record(z.string(), z.string())
|
|
25
|
-
.nullish()
|
|
26
|
-
.transform(v => v ?? {}),
|
|
11
|
+
reason: nullishString,
|
|
12
|
+
domain: nullishString,
|
|
13
|
+
metadata: z.record(z.string(), z.string()).nullish().transform((v) => v ?? {})
|
|
27
14
|
});
|
|
28
|
-
const requestInfoSchema = z
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
requestId: d.request_id,
|
|
35
|
-
servingData: d.serving_data,
|
|
15
|
+
const requestInfoSchema = z.object({
|
|
16
|
+
request_id: nullishString,
|
|
17
|
+
serving_data: nullishString
|
|
18
|
+
}).transform((d) => ({
|
|
19
|
+
requestId: d.request_id,
|
|
20
|
+
servingData: d.serving_data
|
|
36
21
|
}));
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
ctx.addIssue({ code: 'custom', message: 'Invalid protobuf duration.' });
|
|
49
|
-
return z.NEVER;
|
|
50
|
-
}
|
|
51
|
-
return ms;
|
|
22
|
+
const nullishProtoDuration = z.string().nullish().transform((v, ctx) => {
|
|
23
|
+
if (v === null || v === void 0) return 0;
|
|
24
|
+
const ms = parseProtoDuration(v);
|
|
25
|
+
if (ms === void 0) {
|
|
26
|
+
ctx.addIssue({
|
|
27
|
+
code: "custom",
|
|
28
|
+
message: "Invalid protobuf duration."
|
|
29
|
+
});
|
|
30
|
+
return z.NEVER;
|
|
31
|
+
}
|
|
32
|
+
return ms;
|
|
52
33
|
});
|
|
53
|
-
const retryInfoSchema = z
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const debugInfoSchema = z
|
|
61
|
-
.object({
|
|
62
|
-
stack_entries: z
|
|
63
|
-
.array(z.string())
|
|
64
|
-
.nullish()
|
|
65
|
-
.transform(v => v ?? []),
|
|
66
|
-
detail: nullishString,
|
|
67
|
-
})
|
|
68
|
-
.transform(d => ({
|
|
69
|
-
stackEntries: d.stack_entries,
|
|
70
|
-
detail: d.detail,
|
|
34
|
+
const retryInfoSchema = z.object({ retry_delay: nullishProtoDuration }).transform((d) => ({ retryDelayMs: d.retry_delay }));
|
|
35
|
+
const debugInfoSchema = z.object({
|
|
36
|
+
stack_entries: z.array(z.string()).nullish().transform((v) => v ?? []),
|
|
37
|
+
detail: nullishString
|
|
38
|
+
}).transform((d) => ({
|
|
39
|
+
stackEntries: d.stack_entries,
|
|
40
|
+
detail: d.detail
|
|
71
41
|
}));
|
|
72
42
|
const quotaViolationSchema = z.object({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
const quotaFailureSchema = z.object({
|
|
77
|
-
violations: z
|
|
78
|
-
.array(quotaViolationSchema)
|
|
79
|
-
.nullish()
|
|
80
|
-
.transform(v => v ?? []),
|
|
43
|
+
subject: nullishString,
|
|
44
|
+
description: nullishString
|
|
81
45
|
});
|
|
46
|
+
const quotaFailureSchema = z.object({ violations: z.array(quotaViolationSchema).nullish().transform((v) => v ?? []) });
|
|
82
47
|
const preconditionViolationSchema = z.object({
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
const preconditionFailureSchema = z.object({
|
|
88
|
-
violations: z
|
|
89
|
-
.array(preconditionViolationSchema)
|
|
90
|
-
.nullish()
|
|
91
|
-
.transform(v => v ?? []),
|
|
48
|
+
type: nullishString,
|
|
49
|
+
subject: nullishString,
|
|
50
|
+
description: nullishString
|
|
92
51
|
});
|
|
52
|
+
const preconditionFailureSchema = z.object({ violations: z.array(preconditionViolationSchema).nullish().transform((v) => v ?? []) });
|
|
93
53
|
const fieldViolationSchema = z.object({
|
|
94
|
-
|
|
95
|
-
|
|
54
|
+
field: nullishString,
|
|
55
|
+
description: nullishString
|
|
96
56
|
});
|
|
97
|
-
const badRequestSchema = z
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.object({
|
|
109
|
-
resource_type: nullishString,
|
|
110
|
-
resource_name: nullishString,
|
|
111
|
-
owner: nullishString,
|
|
112
|
-
description: nullishString,
|
|
113
|
-
})
|
|
114
|
-
.transform(d => ({
|
|
115
|
-
resourceType: d.resource_type,
|
|
116
|
-
resourceName: d.resource_name,
|
|
117
|
-
owner: d.owner,
|
|
118
|
-
description: d.description,
|
|
57
|
+
const badRequestSchema = z.object({ field_violations: z.array(fieldViolationSchema).nullish().transform((v) => v ?? []) }).transform((d) => ({ fieldViolations: d.field_violations }));
|
|
58
|
+
const resourceInfoSchema = z.object({
|
|
59
|
+
resource_type: nullishString,
|
|
60
|
+
resource_name: nullishString,
|
|
61
|
+
owner: nullishString,
|
|
62
|
+
description: nullishString
|
|
63
|
+
}).transform((d) => ({
|
|
64
|
+
resourceType: d.resource_type,
|
|
65
|
+
resourceName: d.resource_name,
|
|
66
|
+
owner: d.owner,
|
|
67
|
+
description: d.description
|
|
119
68
|
}));
|
|
120
69
|
const helpLinkSchema = z.object({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
const helpSchema = z.object({
|
|
125
|
-
links: z
|
|
126
|
-
.array(helpLinkSchema)
|
|
127
|
-
.nullish()
|
|
128
|
-
.transform(v => v ?? []),
|
|
70
|
+
description: nullishString,
|
|
71
|
+
url: nullishString
|
|
129
72
|
});
|
|
130
|
-
|
|
131
|
-
const ERROR_INFO_TYPE =
|
|
132
|
-
const REQUEST_INFO_TYPE =
|
|
133
|
-
const RETRY_INFO_TYPE =
|
|
134
|
-
const DEBUG_INFO_TYPE =
|
|
135
|
-
const QUOTA_FAILURE_TYPE =
|
|
136
|
-
const PRECONDITION_FAILURE_TYPE =
|
|
137
|
-
const BAD_REQUEST_TYPE =
|
|
138
|
-
const RESOURCE_INFO_TYPE =
|
|
139
|
-
const HELP_TYPE =
|
|
140
|
-
// Checks whether a value is a plain object (not null, not an array).
|
|
73
|
+
const helpSchema = z.object({ links: z.array(helpLinkSchema).nullish().transform((v) => v ?? []) });
|
|
74
|
+
const ERROR_INFO_TYPE = "type.googleapis.com/google.rpc.ErrorInfo";
|
|
75
|
+
const REQUEST_INFO_TYPE = "type.googleapis.com/google.rpc.RequestInfo";
|
|
76
|
+
const RETRY_INFO_TYPE = "type.googleapis.com/google.rpc.RetryInfo";
|
|
77
|
+
const DEBUG_INFO_TYPE = "type.googleapis.com/google.rpc.DebugInfo";
|
|
78
|
+
const QUOTA_FAILURE_TYPE = "type.googleapis.com/google.rpc.QuotaFailure";
|
|
79
|
+
const PRECONDITION_FAILURE_TYPE = "type.googleapis.com/google.rpc.PreconditionFailure";
|
|
80
|
+
const BAD_REQUEST_TYPE = "type.googleapis.com/google.rpc.BadRequest";
|
|
81
|
+
const RESOURCE_INFO_TYPE = "type.googleapis.com/google.rpc.ResourceInfo";
|
|
82
|
+
const HELP_TYPE = "type.googleapis.com/google.rpc.Help";
|
|
141
83
|
function isRecord(value) {
|
|
142
|
-
|
|
84
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
143
85
|
}
|
|
144
|
-
// Parses a protobuf Duration string (e.g. "42.000000001s") into milliseconds.
|
|
145
|
-
// Returns undefined if the format is invalid.
|
|
146
86
|
function parseProtoDuration(s) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (Number.isNaN(seconds)) {
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
return seconds * 1000;
|
|
87
|
+
if (!s.endsWith("s")) return;
|
|
88
|
+
const seconds = Number(s.slice(0, -1));
|
|
89
|
+
if (Number.isNaN(seconds)) return;
|
|
90
|
+
return seconds * 1e3;
|
|
155
91
|
}
|
|
156
|
-
// Attempts to parse a single detail and assign it to the right ErrorDetails
|
|
157
|
-
// field. Returns true if the detail was recognized and valid, false otherwise.
|
|
158
92
|
function tryAssignDetail(ed, type, raw) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
case HELP_TYPE: {
|
|
217
|
-
const r = helpSchema.safeParse(raw);
|
|
218
|
-
if (!r.success)
|
|
219
|
-
return false;
|
|
220
|
-
ed.help = r.data;
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
default:
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
93
|
+
switch (type) {
|
|
94
|
+
case ERROR_INFO_TYPE: {
|
|
95
|
+
const r = errorInfoSchema.safeParse(raw);
|
|
96
|
+
if (!r.success) return false;
|
|
97
|
+
ed.errorInfo = r.data;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
case REQUEST_INFO_TYPE: {
|
|
101
|
+
const r = requestInfoSchema.safeParse(raw);
|
|
102
|
+
if (!r.success) return false;
|
|
103
|
+
ed.requestInfo = r.data;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
case RETRY_INFO_TYPE: {
|
|
107
|
+
const r = retryInfoSchema.safeParse(raw);
|
|
108
|
+
if (!r.success) return false;
|
|
109
|
+
ed.retryInfo = r.data;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
case DEBUG_INFO_TYPE: {
|
|
113
|
+
const r = debugInfoSchema.safeParse(raw);
|
|
114
|
+
if (!r.success) return false;
|
|
115
|
+
ed.debugInfo = r.data;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
case QUOTA_FAILURE_TYPE: {
|
|
119
|
+
const r = quotaFailureSchema.safeParse(raw);
|
|
120
|
+
if (!r.success) return false;
|
|
121
|
+
ed.quotaFailure = r.data;
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
case PRECONDITION_FAILURE_TYPE: {
|
|
125
|
+
const r = preconditionFailureSchema.safeParse(raw);
|
|
126
|
+
if (!r.success) return false;
|
|
127
|
+
ed.preconditionFailure = r.data;
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
case BAD_REQUEST_TYPE: {
|
|
131
|
+
const r = badRequestSchema.safeParse(raw);
|
|
132
|
+
if (!r.success) return false;
|
|
133
|
+
ed.badRequest = r.data;
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
case RESOURCE_INFO_TYPE: {
|
|
137
|
+
const r = resourceInfoSchema.safeParse(raw);
|
|
138
|
+
if (!r.success) return false;
|
|
139
|
+
ed.resourceInfo = r.data;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
case HELP_TYPE: {
|
|
143
|
+
const r = helpSchema.safeParse(raw);
|
|
144
|
+
if (!r.success) return false;
|
|
145
|
+
ed.help = r.data;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
default: return false;
|
|
149
|
+
}
|
|
226
150
|
}
|
|
227
151
|
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
return ed;
|
|
152
|
+
* Parses an array of raw error detail values into a structured ErrorDetails
|
|
153
|
+
* object. If multiple details of the same known type are present, the last
|
|
154
|
+
* one wins.
|
|
155
|
+
*/
|
|
156
|
+
function parseErrorDetails(rawDetails) {
|
|
157
|
+
const ed = { unknownDetails: [] };
|
|
158
|
+
for (const rd of rawDetails) {
|
|
159
|
+
if (!isRecord(rd)) {
|
|
160
|
+
ed.unknownDetails.push(rd);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const type = rd["@type"];
|
|
164
|
+
if (typeof type !== "string") {
|
|
165
|
+
ed.unknownDetails.push(rd);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (!tryAssignDetail(ed, type, rd)) ed.unknownDetails.push(rd);
|
|
169
|
+
}
|
|
170
|
+
return ed;
|
|
249
171
|
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { parseErrorDetails };
|
|
250
175
|
//# sourceMappingURL=details.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"details.js","sourceRoot":"","sources":["../../src/apierror/details.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAkMtB,8EAA8E;AAC9E,kEAAkE;AAClE,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAE9E,yEAAyE;AACzE,iEAAiE;AACjE,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,EAAE;KACR,OAAO,EAAE;KACT,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAE3B,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,aAAa;IACrB,QAAQ,EAAE,CAAC;SACR,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;SAC9B,OAAO,EAAE;SACT,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC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/apierror/details.ts"],"sourcesContent":["/**\n * Defines structured error detail types for API errors.\n *\n * @packageDocumentation\n */\n\nimport {z} from 'zod';\n\n/**\n * ErrorDetails contains the error details of an API error. It is the union of\n * known error details types and unknown details.\n */\nexport interface ErrorDetails {\n errorInfo?: ErrorInfo;\n requestInfo?: RequestInfo;\n retryInfo?: RetryInfo;\n debugInfo?: DebugInfo;\n quotaFailure?: QuotaFailure;\n preconditionFailure?: PreconditionFailure;\n badRequest?: BadRequest;\n resourceInfo?: ResourceInfo;\n help?: Help;\n\n /**\n * UnknownDetails contains error details that cannot be parsed into one of\n * the known types above.\n */\n unknownDetails: unknown[];\n}\n\n/** ErrorInfo describes the cause of the error with structured details. */\nexport interface ErrorInfo {\n /**\n * The reason of the error. This is a constant value that identifies the\n * proximate cause of the error.\n */\n reason: string;\n\n /** The logical grouping to which the \"reason\" belongs. */\n domain: string;\n\n /** Additional structured details about this error. */\n metadata: Record<string, string>;\n}\n\n/**\n * RequestInfo contains metadata about the request that clients can attach when\n * filing a bug or providing other forms of feedback.\n */\nexport interface RequestInfo {\n /**\n * An opaque string that should only be interpreted by the service that\n * generated it. For example, it can be used to identify requests in the\n * service's logs.\n */\n requestId: string;\n\n /**\n * Any data that was used to serve this request. For example, an encrypted\n * stack trace that can be sent back to the service provider for debugging.\n */\n servingData: string;\n}\n\n/**\n * RetryInfo describes when the clients can retry a failed request. Clients\n * could ignore the recommendation here or retry when this information is\n * missing from error responses.\n *\n * It's always recommended that clients should use exponential backoff when\n * retrying.\n *\n * Clients should wait until `retryDelayMs` amount of time has passed since\n * receiving the error response before retrying. If retrying requests also\n * fail, clients should use an exponential backoff scheme to gradually increase\n * the delay between retries based on `retryDelayMs`, until either a maximum\n * number of retries have been reached or a maximum retry delay cap has been\n * reached.\n */\nexport interface RetryInfo {\n /** Clients should wait at least this long between retrying the same request, in milliseconds. */\n retryDelayMs: number;\n}\n\n/** Describes additional debugging info. */\nexport interface DebugInfo {\n /** The stack trace entries indicating where the error occurred. */\n stackEntries: string[];\n\n /** Additional debugging information provided by the server. */\n detail: string;\n}\n\n/**\n * Describes how a quota check failed.\n *\n * For example if a daily limit was exceeded for the calling project,\n * a service could respond with a QuotaFailure detail containing the project\n * id and the description of the quota limit that was exceeded. If the\n * calling project hasn't enabled the service in the developer console, then\n * a service could respond with the project id and set `service_disabled`\n * to true.\n *\n * Also see RetryInfo and Help types for other details about handling a\n * quota failure.\n */\nexport interface QuotaFailure {\n /** Describes all quota violations. */\n violations: QuotaFailureViolation[];\n}\n\nexport interface QuotaFailureViolation {\n /** The subject on which the quota check failed. */\n subject: string;\n\n /**\n * A description of how the quota check failed. Clients can use this\n * description to find more about the quota configuration in the service's\n * public documentation, or find the relevant quota limit to adjust through\n * developer console.\n *\n * For example: \"Service disabled\" or \"Daily Limit for read operations\n * exceeded\".\n */\n description: string;\n}\n\n/** Describes what preconditions have failed. */\nexport interface PreconditionFailure {\n /** Describes all precondition violations. */\n violations: PreconditionFailureViolation[];\n}\n\nexport interface PreconditionFailureViolation {\n /** The type of PreconditionFailure. */\n type: string;\n\n /** The subject, relative to the type, that failed. */\n subject: string;\n\n /**\n * A description of how the precondition failed. Developers can use this\n * description to understand how to fix the failure.\n *\n * For example: \"Terms of service not accepted\".\n */\n description: string;\n}\n\n/**\n * Describes violations in a client request. This error type focuses on the\n * syntactic aspects of the request.\n */\nexport interface BadRequest {\n fieldViolations: BadRequestFieldViolation[];\n}\n\nexport interface BadRequestFieldViolation {\n /** A path leading to a field in the request body. */\n field: string;\n\n /** A description of why the request element is bad. */\n description: string;\n}\n\n/** Describes the resource that is being accessed. */\nexport interface ResourceInfo {\n /** A name for the type of resource being accessed. */\n resourceType: string;\n\n /** The name of the resource being accessed. */\n resourceName: string;\n\n /** The owner of the resource (optional). */\n owner: string;\n\n /** Describes what error is encountered when accessing this resource. */\n description: string;\n}\n\n/**\n * Provides links to documentation or for performing an out of band action.\n *\n * For example, if a quota check failed with an error indicating the calling\n * project hasn't enabled the accessed service, this can contain a URL pointing\n * directly to the right place in the developer console to flip the bit.\n */\nexport interface Help {\n /** URL(s) pointing to additional information on handling the current error. */\n links: HelpLink[];\n}\n\nexport interface HelpLink {\n /** Describes what the link offers. */\n description: string;\n\n /** The URL of the link. */\n url: string;\n}\n\n// ---------------------------------------------------------------------------\n// Zod schemas for the wire format (snake_case JSON from the API).\n//\n// Each schema validates the snake_case wire format from the API and transforms\n// it into the camelCase TypeScript interface. Nullish fields default to their\n// zero values (empty string, empty array, empty record) when absent or null.\n// ---------------------------------------------------------------------------\n\n// Reusable schema fragments. Nullish fields default to their zero values\n// (empty string, empty array, empty record) when absent or null.\nconst nullishString = z\n .string()\n .nullish()\n .transform(v => v ?? '');\n\nconst errorInfoSchema = z.object({\n reason: nullishString,\n domain: nullishString,\n metadata: z\n .record(z.string(), z.string())\n .nullish()\n .transform(v => v ?? {}),\n});\n\nconst requestInfoSchema = z\n .object({\n request_id: nullishString,\n serving_data: nullishString,\n })\n .transform(d => ({\n requestId: d.request_id,\n servingData: d.serving_data,\n }));\n\n// Parses a protobuf Duration string (e.g. \"42.000000001s\") into milliseconds.\n// Null/undefined defaults to 0. Invalid format causes a Zod validation failure.\nconst nullishProtoDuration = z\n .string()\n .nullish()\n .transform((v, ctx) => {\n if (v === null || v === undefined) {\n return 0;\n }\n const ms = parseProtoDuration(v);\n if (ms === undefined) {\n ctx.addIssue({code: 'custom', message: 'Invalid protobuf duration.'});\n return z.NEVER;\n }\n return ms;\n });\n\nconst retryInfoSchema = z\n .object({\n retry_delay: nullishProtoDuration,\n })\n .transform(d => ({\n retryDelayMs: d.retry_delay,\n }));\n\nconst debugInfoSchema = z\n .object({\n stack_entries: z\n .array(z.string())\n .nullish()\n .transform(v => v ?? []),\n detail: nullishString,\n })\n .transform(d => ({\n stackEntries: d.stack_entries,\n detail: d.detail,\n }));\n\nconst quotaViolationSchema = z.object({\n subject: nullishString,\n description: nullishString,\n});\n\nconst quotaFailureSchema = z.object({\n violations: z\n .array(quotaViolationSchema)\n .nullish()\n .transform(v => v ?? []),\n});\n\nconst preconditionViolationSchema = z.object({\n type: nullishString,\n subject: nullishString,\n description: nullishString,\n});\n\nconst preconditionFailureSchema = z.object({\n violations: z\n .array(preconditionViolationSchema)\n .nullish()\n .transform(v => v ?? []),\n});\n\nconst fieldViolationSchema = z.object({\n field: nullishString,\n description: nullishString,\n});\n\nconst badRequestSchema = z\n .object({\n field_violations: z\n .array(fieldViolationSchema)\n .nullish()\n .transform(v => v ?? []),\n })\n .transform(d => ({\n fieldViolations: d.field_violations,\n }));\n\nconst resourceInfoSchema = z\n .object({\n resource_type: nullishString,\n resource_name: nullishString,\n owner: nullishString,\n description: nullishString,\n })\n .transform(d => ({\n resourceType: d.resource_type,\n resourceName: d.resource_name,\n owner: d.owner,\n description: d.description,\n }));\n\nconst helpLinkSchema = z.object({\n description: nullishString,\n url: nullishString,\n});\n\nconst helpSchema = z.object({\n links: z\n .array(helpLinkSchema)\n .nullish()\n .transform(v => v ?? []),\n});\n\n// Google RPC type URLs used to identify error detail types in the wire format.\nconst ERROR_INFO_TYPE = 'type.googleapis.com/google.rpc.ErrorInfo';\nconst REQUEST_INFO_TYPE = 'type.googleapis.com/google.rpc.RequestInfo';\nconst RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.RetryInfo';\nconst DEBUG_INFO_TYPE = 'type.googleapis.com/google.rpc.DebugInfo';\nconst QUOTA_FAILURE_TYPE = 'type.googleapis.com/google.rpc.QuotaFailure';\nconst PRECONDITION_FAILURE_TYPE =\n 'type.googleapis.com/google.rpc.PreconditionFailure';\nconst BAD_REQUEST_TYPE = 'type.googleapis.com/google.rpc.BadRequest';\nconst RESOURCE_INFO_TYPE = 'type.googleapis.com/google.rpc.ResourceInfo';\nconst HELP_TYPE = 'type.googleapis.com/google.rpc.Help';\n\n// Checks whether a value is a plain object (not null, not an array).\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n// Parses a protobuf Duration string (e.g. \"42.000000001s\") into milliseconds.\n// Returns undefined if the format is invalid.\nfunction parseProtoDuration(s: string): number | undefined {\n if (!s.endsWith('s')) {\n return undefined;\n }\n const seconds = Number(s.slice(0, -1));\n if (Number.isNaN(seconds)) {\n return undefined;\n }\n return seconds * 1000;\n}\n\n// Attempts to parse a single detail and assign it to the right ErrorDetails\n// field. Returns true if the detail was recognized and valid, false otherwise.\nfunction tryAssignDetail(\n ed: ErrorDetails,\n type: string,\n raw: unknown\n): boolean {\n switch (type) {\n case ERROR_INFO_TYPE: {\n const r = errorInfoSchema.safeParse(raw);\n if (!r.success) return false;\n ed.errorInfo = r.data;\n return true;\n }\n case REQUEST_INFO_TYPE: {\n const r = requestInfoSchema.safeParse(raw);\n if (!r.success) return false;\n ed.requestInfo = r.data;\n return true;\n }\n case RETRY_INFO_TYPE: {\n const r = retryInfoSchema.safeParse(raw);\n if (!r.success) return false;\n ed.retryInfo = r.data;\n return true;\n }\n case DEBUG_INFO_TYPE: {\n const r = debugInfoSchema.safeParse(raw);\n if (!r.success) return false;\n ed.debugInfo = r.data;\n return true;\n }\n case QUOTA_FAILURE_TYPE: {\n const r = quotaFailureSchema.safeParse(raw);\n if (!r.success) return false;\n ed.quotaFailure = r.data;\n return true;\n }\n case PRECONDITION_FAILURE_TYPE: {\n const r = preconditionFailureSchema.safeParse(raw);\n if (!r.success) return false;\n ed.preconditionFailure = r.data;\n return true;\n }\n case BAD_REQUEST_TYPE: {\n const r = badRequestSchema.safeParse(raw);\n if (!r.success) return false;\n ed.badRequest = r.data;\n return true;\n }\n case RESOURCE_INFO_TYPE: {\n const r = resourceInfoSchema.safeParse(raw);\n if (!r.success) return false;\n ed.resourceInfo = r.data;\n return true;\n }\n case HELP_TYPE: {\n const r = helpSchema.safeParse(raw);\n if (!r.success) return false;\n ed.help = r.data;\n return true;\n }\n default:\n return false;\n }\n}\n\n/**\n * Parses an array of raw error detail values into a structured ErrorDetails\n * object. If multiple details of the same known type are present, the last\n * one wins.\n */\nexport function parseErrorDetails(rawDetails: unknown[]): ErrorDetails {\n const ed: ErrorDetails = {unknownDetails: []};\n for (const rd of rawDetails) {\n if (!isRecord(rd)) {\n ed.unknownDetails.push(rd);\n continue;\n }\n const type = rd['@type'];\n if (typeof type !== 'string') {\n ed.unknownDetails.push(rd);\n continue;\n }\n if (!tryAssignDetail(ed, type, rd)) {\n ed.unknownDetails.push(rd);\n }\n }\n return ed;\n}\n"],"mappings":";;;;;;;;AAkNA,MAAM,gBAAgB,EACnB,QAAQ,CACR,SAAS,CACT,WAAU,MAAK,KAAK,GAAG;AAE1B,MAAM,kBAAkB,EAAE,OAAO;CAC/B,QAAQ;CACR,QAAQ;CACR,UAAU,EACP,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAC9B,SAAS,CACT,WAAU,MAAK,KAAK,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,oBAAoB,EACvB,OAAO;CACN,YAAY;CACZ,cAAc;CACf,CAAC,CACD,WAAU,OAAM;CACf,WAAW,EAAE;CACb,aAAa,EAAE;CAChB,EAAE;AAIL,MAAM,uBAAuB,EAC1B,QAAQ,CACR,SAAS,CACT,WAAW,GAAG,QAAQ;AACrB,KAAI,MAAM,QAAQ,MAAM,OACtB,QAAO;CAET,MAAM,KAAK,mBAAmB,EAAE;AAChC,KAAI,OAAO,QAAW;AACpB,MAAI,SAAS;GAAC,MAAM;GAAU,SAAS;GAA6B,CAAC;AACrE,SAAO,EAAE;;AAEX,QAAO;EACP;AAEJ,MAAM,kBAAkB,EACrB,OAAO,EACN,aAAa,sBACd,CAAC,CACD,WAAU,OAAM,EACf,cAAc,EAAE,aACjB,EAAE;AAEL,MAAM,kBAAkB,EACrB,OAAO;CACN,eAAe,EACZ,MAAM,EAAE,QAAQ,CAAC,CACjB,SAAS,CACT,WAAU,MAAK,KAAK,EAAE,CAAC;CAC1B,QAAQ;CACT,CAAC,CACD,WAAU,OAAM;CACf,cAAc,EAAE;CAChB,QAAQ,EAAE;CACX,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oBAAoB;GACvB,MAAM,IAAI,mBAAmB,UAAU,IAAI;AAC3C,OAAI,CAAC,EAAE,QAAS,QAAO;AACvB,MAAG,eAAe,EAAE;AACpB,UAAO;;EAET,KAAK,WAAW;GACd,MAAM,IAAI,WAAW,UAAU,IAAI;AACnC,OAAI,CAAC,EAAE,QAAS,QAAO;AACvB,MAAG,OAAO,EAAE;AACZ,UAAO;;EAET,QACE,QAAO;;;;;;;;AASb,SAAgB,kBAAkB,YAAqC;CACrE,MAAM,KAAmB,EAAC,gBAAgB,EAAE,EAAC;AAC7C,MAAK,MAAM,MAAM,YAAY;AAC3B,MAAI,CAAC,SAAS,GAAG,EAAE;AACjB,MAAG,eAAe,KAAK,GAAG;AAC1B;;EAEF,MAAM,OAAO,GAAG;AAChB,MAAI,OAAO,SAAS,UAAU;AAC5B,MAAG,eAAe,KAAK,GAAG;AAC1B;;AAEF,MAAI,CAAC,gBAAgB,IAAI,MAAM,GAAG,CAChC,IAAG,eAAe,KAAK,GAAG;;AAG9B,QAAO"}
|
package/dist/apierror/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
export { ApiError } from './apierror';
|
|
7
|
-
export type { ErrorDetails, ErrorInfo, RequestInfo, RetryInfo, DebugInfo, QuotaFailure, QuotaFailureViolation, PreconditionFailure, PreconditionFailureViolation, BadRequest, BadRequestFieldViolation, ResourceInfo, Help, HelpLink, } from './details';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { BadRequest, BadRequestFieldViolation, DebugInfo, ErrorDetails, ErrorInfo, Help, HelpLink, PreconditionFailure, PreconditionFailureViolation, QuotaFailure, QuotaFailureViolation, RequestInfo, ResourceInfo, RetryInfo } from "./details.js";
|
|
2
|
+
import { ApiError } from "./apierror.js";
|
|
3
|
+
export { ApiError, type BadRequest, type BadRequestFieldViolation, type DebugInfo, type ErrorDetails, type ErrorInfo, type Help, type HelpLink, type PreconditionFailure, type PreconditionFailureViolation, type QuotaFailure, type QuotaFailureViolation, type RequestInfo, type ResourceInfo, type RetryInfo };
|
package/dist/apierror/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/clientinfo/agent.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Detects the AI coding agent (e.g. Claude Code, Cursor, Gemini CLI) that
|
|
3
4
|
* is running the current Node.js process. The detected product name is
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
* known env var is set (see {@link agentEnvFallback}).
|
|
30
31
|
* - `""` when nothing is set.
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
declare function lookupAgentProvider(): string;
|
|
33
34
|
/**
|
|
34
35
|
* Returns the detected AI agent name, cached for the process lifetime.
|
|
35
36
|
*
|
|
@@ -44,11 +45,13 @@ export declare function lookupAgentProvider(): string;
|
|
|
44
45
|
* explicit matcher fired (see {@link agentEnvFallback}).
|
|
45
46
|
* - `""` when no agent is detected.
|
|
46
47
|
*/
|
|
47
|
-
|
|
48
|
+
declare function agentProvider(): string;
|
|
48
49
|
/**
|
|
49
50
|
* Clears the cached agent detection result so that the next call to
|
|
50
51
|
* {@link agentProvider} re-evaluates the environment. Exported for
|
|
51
52
|
* testing only.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
declare function clearAgentCache(): void;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { agentProvider, clearAgentCache, lookupAgentProvider };
|
|
54
57
|
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","
|
|
1
|
+
{"version":3,"file":"agent.d.ts","names":[],"sources":["../../src/clientinfo/agent.ts"],"mappings":";;AAgGA;;;;;AAgCA;;;;;AAUA;;;;;;;;;;;;;;;;;;;;AAAA,iBA1CgB,mBAAA,CAAA;;;;;;;;;;;;;;;iBAgCA,aAAA,CAAA;;;;;;iBAUA,eAAA,CAAA"}
|