@delego/runner 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 +64 -0
- package/dist/client.d.ts +28 -0
- package/dist/client.js +242 -0
- package/dist/client.js.map +1 -0
- package/dist/connection.js +336 -0
- package/dist/connection.js.map +1 -0
- package/dist/generated-client.d.ts +397 -0
- package/dist/generated-client.js +667 -0
- package/dist/generated-client.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/runner-id.js +96 -0
- package/dist/runner-id.js.map +1 -0
- package/dist/types.d.ts +34 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
// Code generated by the Encore v1.52.5 client generator. DO NOT EDIT.
|
|
2
|
+
export const Local = "http://localhost:4000";
|
|
3
|
+
/**
|
|
4
|
+
* Environment returns a BaseURL for calling the cloud environment with the given name.
|
|
5
|
+
*/
|
|
6
|
+
export function Environment(name) {
|
|
7
|
+
return `https://${name}-delego-backend-trui.encr.app`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* PreviewEnv returns a BaseURL for calling the preview environment with the given PR number.
|
|
11
|
+
*/
|
|
12
|
+
export function PreviewEnv(pr) {
|
|
13
|
+
return Environment(`pr${pr}`);
|
|
14
|
+
}
|
|
15
|
+
const BROWSER = typeof globalThis === "object" && ("window" in globalThis);
|
|
16
|
+
/**
|
|
17
|
+
* Client is an API client for the delego-backend-trui Encore application.
|
|
18
|
+
*/
|
|
19
|
+
export default class Client {
|
|
20
|
+
core;
|
|
21
|
+
options;
|
|
22
|
+
target;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a Client for calling the public and authenticated APIs of your Encore application.
|
|
25
|
+
*
|
|
26
|
+
* @param target The target which the client should be configured to use. See Local and Environment for options.
|
|
27
|
+
* @param options Options for the client
|
|
28
|
+
*/
|
|
29
|
+
constructor(target, options) {
|
|
30
|
+
this.target = target;
|
|
31
|
+
this.options = options ?? {};
|
|
32
|
+
const base = new BaseClient(this.target, this.options);
|
|
33
|
+
this.core = new core.ServiceClient(base);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new Encore client with the given client options set.
|
|
37
|
+
*
|
|
38
|
+
* @param options Client options to set. They are merged with existing options.
|
|
39
|
+
**/
|
|
40
|
+
with(options) {
|
|
41
|
+
return new Client(this.target, {
|
|
42
|
+
...this.options,
|
|
43
|
+
...options,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export var core;
|
|
48
|
+
(function (core) {
|
|
49
|
+
class ServiceClient {
|
|
50
|
+
baseClient;
|
|
51
|
+
constructor(baseClient) {
|
|
52
|
+
this.baseClient = baseClient;
|
|
53
|
+
this.getOAuthUrl = this.getOAuthUrl.bind(this);
|
|
54
|
+
this.registerActions = this.registerActions.bind(this);
|
|
55
|
+
this.runnerConnection = this.runnerConnection.bind(this);
|
|
56
|
+
this.slackOAuthCallback = this.slackOAuthCallback.bind(this);
|
|
57
|
+
this.slackOAuthInitiate = this.slackOAuthInitiate.bind(this);
|
|
58
|
+
}
|
|
59
|
+
async getOAuthUrl() {
|
|
60
|
+
// Now make the actual call to the API
|
|
61
|
+
const resp = await this.baseClient.callTypedAPI("GET", `/core/slack/oauth/url`);
|
|
62
|
+
return await resp.json();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Registers or updates actions for a runner.
|
|
66
|
+
* Validates API key from X-API-Key header and upserts actions.
|
|
67
|
+
*/
|
|
68
|
+
async registerActions(params) {
|
|
69
|
+
// Convert our params into the objects we need for the request
|
|
70
|
+
const headers = makeRecord({
|
|
71
|
+
"x-api-key": params.apiKey,
|
|
72
|
+
});
|
|
73
|
+
// Construct the body with only the fields which we want encoded within the body (excluding query string or header fields)
|
|
74
|
+
const body = {
|
|
75
|
+
actions: params.actions,
|
|
76
|
+
emailRoles: params.emailRoles,
|
|
77
|
+
runnerId: params.runnerId,
|
|
78
|
+
};
|
|
79
|
+
// Now make the actual call to the API
|
|
80
|
+
const resp = await this.baseClient.callTypedAPI("POST", `/core/actions`, JSON.stringify(body), { headers });
|
|
81
|
+
return await resp.json();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* WebSocket streaming endpoint for SDK clients to connect and receive invocations
|
|
85
|
+
*/
|
|
86
|
+
async runnerConnection() {
|
|
87
|
+
return await this.baseClient.createStreamInOut(`/core/runners/connect`);
|
|
88
|
+
}
|
|
89
|
+
async slackOAuthCallback(method, body, options) {
|
|
90
|
+
return this.baseClient.callAPI(method, `/core/slack/oauth/callback`, body, options);
|
|
91
|
+
}
|
|
92
|
+
async slackOAuthInitiate(method, body, options) {
|
|
93
|
+
return this.baseClient.callAPI(method, `/core/slack/oauth/initiate`, body, options);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
core.ServiceClient = ServiceClient;
|
|
97
|
+
})(core || (core = {}));
|
|
98
|
+
function encodeQuery(parts) {
|
|
99
|
+
const pairs = [];
|
|
100
|
+
for (const key in parts) {
|
|
101
|
+
const val = (Array.isArray(parts[key]) ? parts[key] : [parts[key]]);
|
|
102
|
+
for (const v of val) {
|
|
103
|
+
pairs.push(`${key}=${encodeURIComponent(v)}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return pairs.join("&");
|
|
107
|
+
}
|
|
108
|
+
// makeRecord takes a record and strips any undefined values from it,
|
|
109
|
+
// and returns the same record with a narrower type.
|
|
110
|
+
// @ts-ignore - TS ignore because makeRecord is not always used
|
|
111
|
+
function makeRecord(record) {
|
|
112
|
+
for (const key in record) {
|
|
113
|
+
if (record[key] === undefined) {
|
|
114
|
+
delete record[key];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return record;
|
|
118
|
+
}
|
|
119
|
+
function encodeWebSocketHeaders(headers) {
|
|
120
|
+
// url safe, no pad
|
|
121
|
+
const base64encoded = btoa(JSON.stringify(headers))
|
|
122
|
+
.replaceAll("=", "")
|
|
123
|
+
.replaceAll("+", "-")
|
|
124
|
+
.replaceAll("/", "_");
|
|
125
|
+
return "encore.dev.headers." + base64encoded;
|
|
126
|
+
}
|
|
127
|
+
class WebSocketConnection {
|
|
128
|
+
ws;
|
|
129
|
+
hasUpdateHandlers = [];
|
|
130
|
+
constructor(url, headers) {
|
|
131
|
+
let protocols = ["encore-ws"];
|
|
132
|
+
if (headers) {
|
|
133
|
+
protocols.push(encodeWebSocketHeaders(headers));
|
|
134
|
+
}
|
|
135
|
+
this.ws = new WebSocket(url, protocols);
|
|
136
|
+
this.on("error", () => {
|
|
137
|
+
this.resolveHasUpdateHandlers();
|
|
138
|
+
});
|
|
139
|
+
this.on("close", () => {
|
|
140
|
+
this.resolveHasUpdateHandlers();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
resolveHasUpdateHandlers() {
|
|
144
|
+
const handlers = this.hasUpdateHandlers;
|
|
145
|
+
this.hasUpdateHandlers = [];
|
|
146
|
+
for (const handler of handlers) {
|
|
147
|
+
handler();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async hasUpdate() {
|
|
151
|
+
// await until a new message have been received, or the socket is closed
|
|
152
|
+
await new Promise((resolve) => {
|
|
153
|
+
this.hasUpdateHandlers.push(() => resolve(null));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
on(type, handler) {
|
|
157
|
+
this.ws.addEventListener(type, handler);
|
|
158
|
+
}
|
|
159
|
+
off(type, handler) {
|
|
160
|
+
this.ws.removeEventListener(type, handler);
|
|
161
|
+
}
|
|
162
|
+
close() {
|
|
163
|
+
this.ws.close();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export class StreamInOut {
|
|
167
|
+
socket;
|
|
168
|
+
buffer = [];
|
|
169
|
+
constructor(url, headers) {
|
|
170
|
+
this.socket = new WebSocketConnection(url, headers);
|
|
171
|
+
this.socket.on("message", (event) => {
|
|
172
|
+
this.buffer.push(JSON.parse(event.data));
|
|
173
|
+
this.socket.resolveHasUpdateHandlers();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
close() {
|
|
177
|
+
this.socket.close();
|
|
178
|
+
}
|
|
179
|
+
async send(msg) {
|
|
180
|
+
if (this.socket.ws.readyState === WebSocket.CONNECTING) {
|
|
181
|
+
// await that the socket is opened
|
|
182
|
+
await new Promise((resolve) => {
|
|
183
|
+
this.socket.ws.addEventListener("open", resolve, { once: true });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return this.socket.ws.send(JSON.stringify(msg));
|
|
187
|
+
}
|
|
188
|
+
async next() {
|
|
189
|
+
for await (const next of this)
|
|
190
|
+
return next;
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
async *[Symbol.asyncIterator]() {
|
|
194
|
+
while (true) {
|
|
195
|
+
if (this.buffer.length > 0) {
|
|
196
|
+
yield this.buffer.shift();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
if (this.socket.ws.readyState === WebSocket.CLOSED)
|
|
200
|
+
return;
|
|
201
|
+
await this.socket.hasUpdate();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export class StreamIn {
|
|
207
|
+
socket;
|
|
208
|
+
buffer = [];
|
|
209
|
+
constructor(url, headers) {
|
|
210
|
+
this.socket = new WebSocketConnection(url, headers);
|
|
211
|
+
this.socket.on("message", (event) => {
|
|
212
|
+
this.buffer.push(JSON.parse(event.data));
|
|
213
|
+
this.socket.resolveHasUpdateHandlers();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
close() {
|
|
217
|
+
this.socket.close();
|
|
218
|
+
}
|
|
219
|
+
async next() {
|
|
220
|
+
for await (const next of this)
|
|
221
|
+
return next;
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
async *[Symbol.asyncIterator]() {
|
|
225
|
+
while (true) {
|
|
226
|
+
if (this.buffer.length > 0) {
|
|
227
|
+
yield this.buffer.shift();
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
if (this.socket.ws.readyState === WebSocket.CLOSED)
|
|
231
|
+
return;
|
|
232
|
+
await this.socket.hasUpdate();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export class StreamOut {
|
|
238
|
+
socket;
|
|
239
|
+
responseValue;
|
|
240
|
+
constructor(url, headers) {
|
|
241
|
+
let responseResolver;
|
|
242
|
+
this.responseValue = new Promise((resolve) => responseResolver = resolve);
|
|
243
|
+
this.socket = new WebSocketConnection(url, headers);
|
|
244
|
+
this.socket.on("message", (event) => {
|
|
245
|
+
responseResolver(JSON.parse(event.data));
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
async response() {
|
|
249
|
+
return this.responseValue;
|
|
250
|
+
}
|
|
251
|
+
close() {
|
|
252
|
+
this.socket.close();
|
|
253
|
+
}
|
|
254
|
+
async send(msg) {
|
|
255
|
+
if (this.socket.ws.readyState === WebSocket.CONNECTING) {
|
|
256
|
+
// await that the socket is opened
|
|
257
|
+
await new Promise((resolve) => {
|
|
258
|
+
this.socket.ws.addEventListener("open", resolve, { once: true });
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return this.socket.ws.send(JSON.stringify(msg));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const boundFetch = fetch.bind(this);
|
|
265
|
+
class BaseClient {
|
|
266
|
+
baseURL;
|
|
267
|
+
fetcher;
|
|
268
|
+
headers;
|
|
269
|
+
requestInit;
|
|
270
|
+
authGenerator;
|
|
271
|
+
constructor(baseURL, options) {
|
|
272
|
+
this.baseURL = baseURL;
|
|
273
|
+
this.headers = {};
|
|
274
|
+
// Add User-Agent header if the script is running in the server
|
|
275
|
+
// because browsers do not allow setting User-Agent headers to requests
|
|
276
|
+
if (!BROWSER) {
|
|
277
|
+
this.headers["User-Agent"] = "delego-backend-trui-Generated-TS-Client (Encore/v1.52.5)";
|
|
278
|
+
}
|
|
279
|
+
this.requestInit = options.requestInit ?? {};
|
|
280
|
+
// Setup what fetch function we'll be using in the base client
|
|
281
|
+
if (options.fetcher !== undefined) {
|
|
282
|
+
this.fetcher = options.fetcher;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
this.fetcher = boundFetch;
|
|
286
|
+
}
|
|
287
|
+
// Setup an authentication data generator using the auth data token option
|
|
288
|
+
if (options.auth !== undefined) {
|
|
289
|
+
const auth = options.auth;
|
|
290
|
+
if (typeof auth === "function") {
|
|
291
|
+
this.authGenerator = auth;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
this.authGenerator = () => auth;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async getAuthData() {
|
|
299
|
+
let authData;
|
|
300
|
+
// If authorization data generator is present, call it and add the returned data to the request
|
|
301
|
+
if (this.authGenerator) {
|
|
302
|
+
const mayBePromise = this.authGenerator();
|
|
303
|
+
if (mayBePromise instanceof Promise) {
|
|
304
|
+
authData = await mayBePromise;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
authData = mayBePromise;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (authData) {
|
|
311
|
+
const data = {};
|
|
312
|
+
data.headers = makeRecord({
|
|
313
|
+
authorization: authData.authorization,
|
|
314
|
+
});
|
|
315
|
+
return data;
|
|
316
|
+
}
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
// createStreamInOut sets up a stream to a streaming API endpoint.
|
|
320
|
+
async createStreamInOut(path, params) {
|
|
321
|
+
let { query, headers } = params ?? {};
|
|
322
|
+
// Fetch auth data if there is any
|
|
323
|
+
const authData = await this.getAuthData();
|
|
324
|
+
// If we now have authentication data, add it to the request
|
|
325
|
+
if (authData) {
|
|
326
|
+
if (authData.query) {
|
|
327
|
+
query = { ...query, ...authData.query };
|
|
328
|
+
}
|
|
329
|
+
if (authData.headers) {
|
|
330
|
+
headers = { ...headers, ...authData.headers };
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const queryString = query ? '?' + encodeQuery(query) : '';
|
|
334
|
+
return new StreamInOut(this.baseURL + path + queryString, headers);
|
|
335
|
+
}
|
|
336
|
+
// createStreamIn sets up a stream to a streaming API endpoint.
|
|
337
|
+
async createStreamIn(path, params) {
|
|
338
|
+
let { query, headers } = params ?? {};
|
|
339
|
+
// Fetch auth data if there is any
|
|
340
|
+
const authData = await this.getAuthData();
|
|
341
|
+
// If we now have authentication data, add it to the request
|
|
342
|
+
if (authData) {
|
|
343
|
+
if (authData.query) {
|
|
344
|
+
query = { ...query, ...authData.query };
|
|
345
|
+
}
|
|
346
|
+
if (authData.headers) {
|
|
347
|
+
headers = { ...headers, ...authData.headers };
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const queryString = query ? '?' + encodeQuery(query) : '';
|
|
351
|
+
return new StreamIn(this.baseURL + path + queryString, headers);
|
|
352
|
+
}
|
|
353
|
+
// createStreamOut sets up a stream to a streaming API endpoint.
|
|
354
|
+
async createStreamOut(path, params) {
|
|
355
|
+
let { query, headers } = params ?? {};
|
|
356
|
+
// Fetch auth data if there is any
|
|
357
|
+
const authData = await this.getAuthData();
|
|
358
|
+
// If we now have authentication data, add it to the request
|
|
359
|
+
if (authData) {
|
|
360
|
+
if (authData.query) {
|
|
361
|
+
query = { ...query, ...authData.query };
|
|
362
|
+
}
|
|
363
|
+
if (authData.headers) {
|
|
364
|
+
headers = { ...headers, ...authData.headers };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const queryString = query ? '?' + encodeQuery(query) : '';
|
|
368
|
+
return new StreamOut(this.baseURL + path + queryString, headers);
|
|
369
|
+
}
|
|
370
|
+
// callTypedAPI makes an API call, defaulting content type to "application/json"
|
|
371
|
+
async callTypedAPI(method, path, body, params) {
|
|
372
|
+
return this.callAPI(method, path, body, {
|
|
373
|
+
...params,
|
|
374
|
+
headers: { "Content-Type": "application/json", ...params?.headers }
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
// callAPI is used by each generated API method to actually make the request
|
|
378
|
+
async callAPI(method, path, body, params) {
|
|
379
|
+
let { query, headers, ...rest } = params ?? {};
|
|
380
|
+
const init = {
|
|
381
|
+
...this.requestInit,
|
|
382
|
+
...rest,
|
|
383
|
+
method,
|
|
384
|
+
body: body ?? null,
|
|
385
|
+
};
|
|
386
|
+
// Merge our headers with any predefined headers
|
|
387
|
+
init.headers = { ...this.headers, ...init.headers, ...headers };
|
|
388
|
+
// Fetch auth data if there is any
|
|
389
|
+
const authData = await this.getAuthData();
|
|
390
|
+
// If we now have authentication data, add it to the request
|
|
391
|
+
if (authData) {
|
|
392
|
+
if (authData.query) {
|
|
393
|
+
query = { ...query, ...authData.query };
|
|
394
|
+
}
|
|
395
|
+
if (authData.headers) {
|
|
396
|
+
init.headers = { ...init.headers, ...authData.headers };
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
// Make the actual request
|
|
400
|
+
const queryString = query ? '?' + encodeQuery(query) : '';
|
|
401
|
+
const response = await this.fetcher(this.baseURL + path + queryString, init);
|
|
402
|
+
// handle any error responses
|
|
403
|
+
if (!response.ok) {
|
|
404
|
+
// try and get the error message from the response body
|
|
405
|
+
let body = { code: ErrCode.Unknown, message: `request failed: status ${response.status}` };
|
|
406
|
+
// if we can get the structured error we should, otherwise give a best effort
|
|
407
|
+
try {
|
|
408
|
+
const text = await response.text();
|
|
409
|
+
try {
|
|
410
|
+
const jsonBody = JSON.parse(text);
|
|
411
|
+
if (isAPIErrorResponse(jsonBody)) {
|
|
412
|
+
body = jsonBody;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
body.message += ": " + JSON.stringify(jsonBody);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
catch {
|
|
419
|
+
body.message += ": " + text;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
catch (e) {
|
|
423
|
+
// otherwise we just append the text to the error message
|
|
424
|
+
body.message += ": " + String(e);
|
|
425
|
+
}
|
|
426
|
+
throw new APIError(response.status, body);
|
|
427
|
+
}
|
|
428
|
+
return response;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function isAPIErrorResponse(err) {
|
|
432
|
+
return (err !== undefined && err !== null &&
|
|
433
|
+
isErrCode(err.code) &&
|
|
434
|
+
typeof (err.message) === "string" &&
|
|
435
|
+
(err.details === undefined || err.details === null || typeof (err.details) === "object"));
|
|
436
|
+
}
|
|
437
|
+
function isErrCode(code) {
|
|
438
|
+
return code !== undefined && Object.values(ErrCode).includes(code);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* APIError represents a structured error as returned from an Encore application.
|
|
442
|
+
*/
|
|
443
|
+
export class APIError extends Error {
|
|
444
|
+
/**
|
|
445
|
+
* The HTTP status code associated with the error.
|
|
446
|
+
*/
|
|
447
|
+
status;
|
|
448
|
+
/**
|
|
449
|
+
* The Encore error code
|
|
450
|
+
*/
|
|
451
|
+
code;
|
|
452
|
+
/**
|
|
453
|
+
* The error details
|
|
454
|
+
*/
|
|
455
|
+
details;
|
|
456
|
+
constructor(status, response) {
|
|
457
|
+
// extending errors causes issues after you construct them, unless you apply the following fixes
|
|
458
|
+
super(response.message);
|
|
459
|
+
// set error name as constructor name, make it not enumerable to keep native Error behavior
|
|
460
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target#new.target_in_constructors
|
|
461
|
+
Object.defineProperty(this, 'name', {
|
|
462
|
+
value: 'APIError',
|
|
463
|
+
enumerable: false,
|
|
464
|
+
configurable: true,
|
|
465
|
+
});
|
|
466
|
+
// fix the prototype chain
|
|
467
|
+
if (Object.setPrototypeOf == undefined) {
|
|
468
|
+
this.__proto__ = APIError.prototype;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
Object.setPrototypeOf(this, APIError.prototype);
|
|
472
|
+
}
|
|
473
|
+
// capture a stack trace
|
|
474
|
+
if (Error.captureStackTrace !== undefined) {
|
|
475
|
+
Error.captureStackTrace(this, this.constructor);
|
|
476
|
+
}
|
|
477
|
+
this.status = status;
|
|
478
|
+
this.code = response.code;
|
|
479
|
+
this.details = response.details;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Typeguard allowing use of an APIError's fields'
|
|
484
|
+
*/
|
|
485
|
+
export function isAPIError(err) {
|
|
486
|
+
return err instanceof APIError;
|
|
487
|
+
}
|
|
488
|
+
export var ErrCode;
|
|
489
|
+
(function (ErrCode) {
|
|
490
|
+
/**
|
|
491
|
+
* OK indicates the operation was successful.
|
|
492
|
+
*/
|
|
493
|
+
ErrCode["OK"] = "ok";
|
|
494
|
+
/**
|
|
495
|
+
* Canceled indicates the operation was canceled (typically by the caller).
|
|
496
|
+
*
|
|
497
|
+
* Encore will generate this error code when cancellation is requested.
|
|
498
|
+
*/
|
|
499
|
+
ErrCode["Canceled"] = "canceled";
|
|
500
|
+
/**
|
|
501
|
+
* Unknown error. An example of where this error may be returned is
|
|
502
|
+
* if a Status value received from another address space belongs to
|
|
503
|
+
* an error-space that is not known in this address space. Also
|
|
504
|
+
* errors raised by APIs that do not return enough error information
|
|
505
|
+
* may be converted to this error.
|
|
506
|
+
*
|
|
507
|
+
* Encore will generate this error code in the above two mentioned cases.
|
|
508
|
+
*/
|
|
509
|
+
ErrCode["Unknown"] = "unknown";
|
|
510
|
+
/**
|
|
511
|
+
* InvalidArgument indicates client specified an invalid argument.
|
|
512
|
+
* Note that this differs from FailedPrecondition. It indicates arguments
|
|
513
|
+
* that are problematic regardless of the state of the system
|
|
514
|
+
* (e.g., a malformed file name).
|
|
515
|
+
*
|
|
516
|
+
* This error code will not be generated by the gRPC framework.
|
|
517
|
+
*/
|
|
518
|
+
ErrCode["InvalidArgument"] = "invalid_argument";
|
|
519
|
+
/**
|
|
520
|
+
* DeadlineExceeded means operation expired before completion.
|
|
521
|
+
* For operations that change the state of the system, this error may be
|
|
522
|
+
* returned even if the operation has completed successfully. For
|
|
523
|
+
* example, a successful response from a server could have been delayed
|
|
524
|
+
* long enough for the deadline to expire.
|
|
525
|
+
*
|
|
526
|
+
* The gRPC framework will generate this error code when the deadline is
|
|
527
|
+
* exceeded.
|
|
528
|
+
*/
|
|
529
|
+
ErrCode["DeadlineExceeded"] = "deadline_exceeded";
|
|
530
|
+
/**
|
|
531
|
+
* NotFound means some requested entity (e.g., file or directory) was
|
|
532
|
+
* not found.
|
|
533
|
+
*
|
|
534
|
+
* This error code will not be generated by the gRPC framework.
|
|
535
|
+
*/
|
|
536
|
+
ErrCode["NotFound"] = "not_found";
|
|
537
|
+
/**
|
|
538
|
+
* AlreadyExists means an attempt to create an entity failed because one
|
|
539
|
+
* already exists.
|
|
540
|
+
*
|
|
541
|
+
* This error code will not be generated by the gRPC framework.
|
|
542
|
+
*/
|
|
543
|
+
ErrCode["AlreadyExists"] = "already_exists";
|
|
544
|
+
/**
|
|
545
|
+
* PermissionDenied indicates the caller does not have permission to
|
|
546
|
+
* execute the specified operation. It must not be used for rejections
|
|
547
|
+
* caused by exhausting some resource (use ResourceExhausted
|
|
548
|
+
* instead for those errors). It must not be
|
|
549
|
+
* used if the caller cannot be identified (use Unauthenticated
|
|
550
|
+
* instead for those errors).
|
|
551
|
+
*
|
|
552
|
+
* This error code will not be generated by the gRPC core framework,
|
|
553
|
+
* but expect authentication middleware to use it.
|
|
554
|
+
*/
|
|
555
|
+
ErrCode["PermissionDenied"] = "permission_denied";
|
|
556
|
+
/**
|
|
557
|
+
* ResourceExhausted indicates some resource has been exhausted, perhaps
|
|
558
|
+
* a per-user quota, or perhaps the entire file system is out of space.
|
|
559
|
+
*
|
|
560
|
+
* This error code will be generated by the gRPC framework in
|
|
561
|
+
* out-of-memory and server overload situations, or when a message is
|
|
562
|
+
* larger than the configured maximum size.
|
|
563
|
+
*/
|
|
564
|
+
ErrCode["ResourceExhausted"] = "resource_exhausted";
|
|
565
|
+
/**
|
|
566
|
+
* FailedPrecondition indicates operation was rejected because the
|
|
567
|
+
* system is not in a state required for the operation's execution.
|
|
568
|
+
* For example, directory to be deleted may be non-empty, an rmdir
|
|
569
|
+
* operation is applied to a non-directory, etc.
|
|
570
|
+
*
|
|
571
|
+
* A litmus test that may help a service implementor in deciding
|
|
572
|
+
* between FailedPrecondition, Aborted, and Unavailable:
|
|
573
|
+
* (a) Use Unavailable if the client can retry just the failing call.
|
|
574
|
+
* (b) Use Aborted if the client should retry at a higher-level
|
|
575
|
+
* (e.g., restarting a read-modify-write sequence).
|
|
576
|
+
* (c) Use FailedPrecondition if the client should not retry until
|
|
577
|
+
* the system state has been explicitly fixed. E.g., if an "rmdir"
|
|
578
|
+
* fails because the directory is non-empty, FailedPrecondition
|
|
579
|
+
* should be returned since the client should not retry unless
|
|
580
|
+
* they have first fixed up the directory by deleting files from it.
|
|
581
|
+
* (d) Use FailedPrecondition if the client performs conditional
|
|
582
|
+
* REST Get/Update/Delete on a resource and the resource on the
|
|
583
|
+
* server does not match the condition. E.g., conflicting
|
|
584
|
+
* read-modify-write on the same resource.
|
|
585
|
+
*
|
|
586
|
+
* This error code will not be generated by the gRPC framework.
|
|
587
|
+
*/
|
|
588
|
+
ErrCode["FailedPrecondition"] = "failed_precondition";
|
|
589
|
+
/**
|
|
590
|
+
* Aborted indicates the operation was aborted, typically due to a
|
|
591
|
+
* concurrency issue like sequencer check failures, transaction aborts,
|
|
592
|
+
* etc.
|
|
593
|
+
*
|
|
594
|
+
* See litmus test above for deciding between FailedPrecondition,
|
|
595
|
+
* Aborted, and Unavailable.
|
|
596
|
+
*/
|
|
597
|
+
ErrCode["Aborted"] = "aborted";
|
|
598
|
+
/**
|
|
599
|
+
* OutOfRange means operation was attempted past the valid range.
|
|
600
|
+
* E.g., seeking or reading past end of file.
|
|
601
|
+
*
|
|
602
|
+
* Unlike InvalidArgument, this error indicates a problem that may
|
|
603
|
+
* be fixed if the system state changes. For example, a 32-bit file
|
|
604
|
+
* system will generate InvalidArgument if asked to read at an
|
|
605
|
+
* offset that is not in the range [0,2^32-1], but it will generate
|
|
606
|
+
* OutOfRange if asked to read from an offset past the current
|
|
607
|
+
* file size.
|
|
608
|
+
*
|
|
609
|
+
* There is a fair bit of overlap between FailedPrecondition and
|
|
610
|
+
* OutOfRange. We recommend using OutOfRange (the more specific
|
|
611
|
+
* error) when it applies so that callers who are iterating through
|
|
612
|
+
* a space can easily look for an OutOfRange error to detect when
|
|
613
|
+
* they are done.
|
|
614
|
+
*
|
|
615
|
+
* This error code will not be generated by the gRPC framework.
|
|
616
|
+
*/
|
|
617
|
+
ErrCode["OutOfRange"] = "out_of_range";
|
|
618
|
+
/**
|
|
619
|
+
* Unimplemented indicates operation is not implemented or not
|
|
620
|
+
* supported/enabled in this service.
|
|
621
|
+
*
|
|
622
|
+
* This error code will be generated by the gRPC framework. Most
|
|
623
|
+
* commonly, you will see this error code when a method implementation
|
|
624
|
+
* is missing on the server. It can also be generated for unknown
|
|
625
|
+
* compression algorithms or a disagreement as to whether an RPC should
|
|
626
|
+
* be streaming.
|
|
627
|
+
*/
|
|
628
|
+
ErrCode["Unimplemented"] = "unimplemented";
|
|
629
|
+
/**
|
|
630
|
+
* Internal errors. Means some invariants expected by underlying
|
|
631
|
+
* system has been broken. If you see one of these errors,
|
|
632
|
+
* something is very broken.
|
|
633
|
+
*
|
|
634
|
+
* This error code will be generated by the gRPC framework in several
|
|
635
|
+
* internal error conditions.
|
|
636
|
+
*/
|
|
637
|
+
ErrCode["Internal"] = "internal";
|
|
638
|
+
/**
|
|
639
|
+
* Unavailable indicates the service is currently unavailable.
|
|
640
|
+
* This is a most likely a transient condition and may be corrected
|
|
641
|
+
* by retrying with a backoff. Note that it is not always safe to retry
|
|
642
|
+
* non-idempotent operations.
|
|
643
|
+
*
|
|
644
|
+
* See litmus test above for deciding between FailedPrecondition,
|
|
645
|
+
* Aborted, and Unavailable.
|
|
646
|
+
*
|
|
647
|
+
* This error code will be generated by the gRPC framework during
|
|
648
|
+
* abrupt shutdown of a server process or network connection.
|
|
649
|
+
*/
|
|
650
|
+
ErrCode["Unavailable"] = "unavailable";
|
|
651
|
+
/**
|
|
652
|
+
* DataLoss indicates unrecoverable data loss or corruption.
|
|
653
|
+
*
|
|
654
|
+
* This error code will not be generated by the gRPC framework.
|
|
655
|
+
*/
|
|
656
|
+
ErrCode["DataLoss"] = "data_loss";
|
|
657
|
+
/**
|
|
658
|
+
* Unauthenticated indicates the request does not have valid
|
|
659
|
+
* authentication credentials for the operation.
|
|
660
|
+
*
|
|
661
|
+
* The gRPC framework will generate this error code when the
|
|
662
|
+
* authentication metadata is invalid or a Credentials callback fails,
|
|
663
|
+
* but also expect authentication middleware to generate it.
|
|
664
|
+
*/
|
|
665
|
+
ErrCode["Unauthenticated"] = "unauthenticated";
|
|
666
|
+
})(ErrCode || (ErrCode = {}));
|
|
667
|
+
//# sourceMappingURL=generated-client.js.map
|