@rivetkit/engine-api-full 2.0.38 → 2.0.39

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.
Files changed (51) hide show
  1. package/dist/browser/cjs/index.js +5 -130
  2. package/dist/browser/cjs/serialization.js +5 -130
  3. package/dist/browser/esm/index.js +5 -130
  4. package/dist/browser/esm/serialization.js +5 -130
  5. package/dist/node/{index.js → cjs/index.js} +5 -130
  6. package/dist/node/{serialization.js → cjs/serialization.js} +5 -147
  7. package/dist/node/esm/core.js +2317 -0
  8. package/dist/node/esm/index.js +4218 -0
  9. package/dist/node/esm/serialization.js +1925 -0
  10. package/package.json +13 -4
  11. package/types/api/types/Actor.d.ts +1 -1
  12. package/types/api/types/RunnerConfigResponse.d.ts +1 -1
  13. package/types/api/types/index.d.ts +0 -17
  14. package/types/serialization/types/Actor.d.ts +1 -2
  15. package/types/serialization/types/RunnerConfigResponse.d.ts +1 -2
  16. package/types/serialization/types/index.d.ts +0 -17
  17. package/types/api/types/ActorError.d.ts +0 -20
  18. package/types/api/types/ActorErrorCrashed.d.ts +0 -11
  19. package/types/api/types/ActorErrorCrashedCrashed.d.ts +0 -9
  20. package/types/api/types/ActorErrorRunnerConnectionLost.d.ts +0 -11
  21. package/types/api/types/ActorErrorRunnerConnectionLostRunnerConnectionLost.d.ts +0 -10
  22. package/types/api/types/ActorErrorRunnerDrainingTimeout.d.ts +0 -11
  23. package/types/api/types/ActorErrorRunnerDrainingTimeoutRunnerDrainingTimeout.d.ts +0 -10
  24. package/types/api/types/ActorErrorRunnerNoResponse.d.ts +0 -11
  25. package/types/api/types/ActorErrorRunnerNoResponseRunnerNoResponse.d.ts +0 -10
  26. package/types/api/types/ActorErrorRunnerPoolError.d.ts +0 -11
  27. package/types/api/types/RunnerPoolError.d.ts +0 -14
  28. package/types/api/types/RunnerPoolErrorServerlessConnectionError.d.ts +0 -11
  29. package/types/api/types/RunnerPoolErrorServerlessConnectionErrorServerlessConnectionError.d.ts +0 -9
  30. package/types/api/types/RunnerPoolErrorServerlessHttpError.d.ts +0 -11
  31. package/types/api/types/RunnerPoolErrorServerlessHttpErrorServerlessHttpError.d.ts +0 -10
  32. package/types/api/types/RunnerPoolErrorServerlessInvalidSsePayload.d.ts +0 -11
  33. package/types/api/types/RunnerPoolErrorServerlessInvalidSsePayloadServerlessInvalidSsePayload.d.ts +0 -10
  34. package/types/serialization/types/ActorError.d.ts +0 -15
  35. package/types/serialization/types/ActorErrorCrashed.d.ts +0 -13
  36. package/types/serialization/types/ActorErrorCrashedCrashed.d.ts +0 -12
  37. package/types/serialization/types/ActorErrorRunnerConnectionLost.d.ts +0 -13
  38. package/types/serialization/types/ActorErrorRunnerConnectionLostRunnerConnectionLost.d.ts +0 -13
  39. package/types/serialization/types/ActorErrorRunnerDrainingTimeout.d.ts +0 -13
  40. package/types/serialization/types/ActorErrorRunnerDrainingTimeoutRunnerDrainingTimeout.d.ts +0 -13
  41. package/types/serialization/types/ActorErrorRunnerNoResponse.d.ts +0 -13
  42. package/types/serialization/types/ActorErrorRunnerNoResponseRunnerNoResponse.d.ts +0 -13
  43. package/types/serialization/types/ActorErrorRunnerPoolError.d.ts +0 -13
  44. package/types/serialization/types/RunnerPoolError.d.ts +0 -13
  45. package/types/serialization/types/RunnerPoolErrorServerlessConnectionError.d.ts +0 -13
  46. package/types/serialization/types/RunnerPoolErrorServerlessConnectionErrorServerlessConnectionError.d.ts +0 -12
  47. package/types/serialization/types/RunnerPoolErrorServerlessHttpError.d.ts +0 -13
  48. package/types/serialization/types/RunnerPoolErrorServerlessHttpErrorServerlessHttpError.d.ts +0 -13
  49. package/types/serialization/types/RunnerPoolErrorServerlessInvalidSsePayload.d.ts +0 -13
  50. package/types/serialization/types/RunnerPoolErrorServerlessInvalidSsePayloadServerlessInvalidSsePayload.d.ts +0 -13
  51. /package/dist/node/{core.js → cjs/core.js} +0 -0
@@ -0,0 +1,4218 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts
12
+ var Node18UniversalStreamWrapper_exports = {};
13
+ __export(Node18UniversalStreamWrapper_exports, {
14
+ Node18UniversalStreamWrapper: () => Node18UniversalStreamWrapper
15
+ });
16
+ var Node18UniversalStreamWrapper;
17
+ var init_Node18UniversalStreamWrapper = __esm({
18
+ "src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts"() {
19
+ "use strict";
20
+ Node18UniversalStreamWrapper = class _Node18UniversalStreamWrapper {
21
+ readableStream;
22
+ reader;
23
+ events;
24
+ paused;
25
+ resumeCallback;
26
+ encoding;
27
+ constructor(readableStream) {
28
+ this.readableStream = readableStream;
29
+ this.reader = this.readableStream.getReader();
30
+ this.events = {
31
+ data: [],
32
+ end: [],
33
+ error: [],
34
+ readable: [],
35
+ close: [],
36
+ pause: [],
37
+ resume: []
38
+ };
39
+ this.paused = false;
40
+ this.resumeCallback = null;
41
+ this.encoding = null;
42
+ }
43
+ on(event, callback) {
44
+ var _a;
45
+ (_a = this.events[event]) == null ? void 0 : _a.push(callback);
46
+ }
47
+ off(event, callback) {
48
+ var _a;
49
+ this.events[event] = (_a = this.events[event]) == null ? void 0 : _a.filter((cb) => cb !== callback);
50
+ }
51
+ pipe(dest) {
52
+ this.on("data", async (chunk) => {
53
+ if (dest instanceof _Node18UniversalStreamWrapper) {
54
+ dest._write(chunk);
55
+ } else if (dest instanceof WritableStream) {
56
+ const writer = dest.getWriter();
57
+ writer.write(chunk).then(() => writer.releaseLock());
58
+ } else {
59
+ dest.write(chunk);
60
+ }
61
+ });
62
+ this.on("end", async () => {
63
+ if (dest instanceof _Node18UniversalStreamWrapper) {
64
+ dest._end();
65
+ } else if (dest instanceof WritableStream) {
66
+ const writer = dest.getWriter();
67
+ writer.close();
68
+ } else {
69
+ dest.end();
70
+ }
71
+ });
72
+ this.on("error", async (error) => {
73
+ if (dest instanceof _Node18UniversalStreamWrapper) {
74
+ dest._error(error);
75
+ } else if (dest instanceof WritableStream) {
76
+ const writer = dest.getWriter();
77
+ writer.abort(error);
78
+ } else {
79
+ dest.destroy(error);
80
+ }
81
+ });
82
+ this._startReading();
83
+ return dest;
84
+ }
85
+ pipeTo(dest) {
86
+ return this.pipe(dest);
87
+ }
88
+ unpipe(dest) {
89
+ this.off("data", async (chunk) => {
90
+ if (dest instanceof _Node18UniversalStreamWrapper) {
91
+ dest._write(chunk);
92
+ } else if (dest instanceof WritableStream) {
93
+ const writer = dest.getWriter();
94
+ writer.write(chunk).then(() => writer.releaseLock());
95
+ } else {
96
+ dest.write(chunk);
97
+ }
98
+ });
99
+ this.off("end", async () => {
100
+ if (dest instanceof _Node18UniversalStreamWrapper) {
101
+ dest._end();
102
+ } else if (dest instanceof WritableStream) {
103
+ const writer = dest.getWriter();
104
+ writer.close();
105
+ } else {
106
+ dest.end();
107
+ }
108
+ });
109
+ this.off("error", async (error) => {
110
+ if (dest instanceof _Node18UniversalStreamWrapper) {
111
+ dest._error(error);
112
+ } else if (dest instanceof WritableStream) {
113
+ const writer = dest.getWriter();
114
+ writer.abort(error);
115
+ } else {
116
+ dest.destroy(error);
117
+ }
118
+ });
119
+ }
120
+ destroy(error) {
121
+ this.reader.cancel(error).then(() => {
122
+ this._emit("close");
123
+ }).catch((err) => {
124
+ this._emit("error", err);
125
+ });
126
+ }
127
+ pause() {
128
+ this.paused = true;
129
+ this._emit("pause");
130
+ }
131
+ resume() {
132
+ if (this.paused) {
133
+ this.paused = false;
134
+ this._emit("resume");
135
+ if (this.resumeCallback) {
136
+ this.resumeCallback();
137
+ this.resumeCallback = null;
138
+ }
139
+ }
140
+ }
141
+ get isPaused() {
142
+ return this.paused;
143
+ }
144
+ async read() {
145
+ if (this.paused) {
146
+ await new Promise((resolve) => {
147
+ this.resumeCallback = resolve;
148
+ });
149
+ }
150
+ const { done, value } = await this.reader.read();
151
+ if (done) {
152
+ return void 0;
153
+ }
154
+ return value;
155
+ }
156
+ setEncoding(encoding) {
157
+ this.encoding = encoding;
158
+ }
159
+ async text() {
160
+ const chunks = [];
161
+ while (true) {
162
+ const { done, value } = await this.reader.read();
163
+ if (done) {
164
+ break;
165
+ }
166
+ if (value) {
167
+ chunks.push(value);
168
+ }
169
+ }
170
+ const decoder = new TextDecoder(this.encoding || "utf-8");
171
+ return decoder.decode(await new Blob(chunks).arrayBuffer());
172
+ }
173
+ async json() {
174
+ const text = await this.text();
175
+ return JSON.parse(text);
176
+ }
177
+ _write(chunk) {
178
+ this._emit("data", chunk);
179
+ }
180
+ _end() {
181
+ this._emit("end");
182
+ }
183
+ _error(error) {
184
+ this._emit("error", error);
185
+ }
186
+ _emit(event, data) {
187
+ if (this.events[event]) {
188
+ for (const callback of this.events[event] || []) {
189
+ callback(data);
190
+ }
191
+ }
192
+ }
193
+ async _startReading() {
194
+ try {
195
+ this._emit("readable");
196
+ while (true) {
197
+ if (this.paused) {
198
+ await new Promise((resolve) => {
199
+ this.resumeCallback = resolve;
200
+ });
201
+ }
202
+ const { done, value } = await this.reader.read();
203
+ if (done) {
204
+ this._emit("end");
205
+ this._emit("close");
206
+ break;
207
+ }
208
+ if (value) {
209
+ this._emit("data", value);
210
+ }
211
+ }
212
+ } catch (error) {
213
+ this._emit("error", error);
214
+ }
215
+ }
216
+ [Symbol.asyncIterator]() {
217
+ return {
218
+ next: async () => {
219
+ if (this.paused) {
220
+ await new Promise((resolve) => {
221
+ this.resumeCallback = resolve;
222
+ });
223
+ }
224
+ const { done, value } = await this.reader.read();
225
+ if (done) {
226
+ return { done: true, value: void 0 };
227
+ }
228
+ return { done: false, value };
229
+ },
230
+ [Symbol.asyncIterator]() {
231
+ return this;
232
+ }
233
+ };
234
+ }
235
+ };
236
+ }
237
+ });
238
+
239
+ // src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts
240
+ var UndiciStreamWrapper_exports = {};
241
+ __export(UndiciStreamWrapper_exports, {
242
+ UndiciStreamWrapper: () => UndiciStreamWrapper
243
+ });
244
+ var UndiciStreamWrapper;
245
+ var init_UndiciStreamWrapper = __esm({
246
+ "src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts"() {
247
+ "use strict";
248
+ UndiciStreamWrapper = class _UndiciStreamWrapper {
249
+ readableStream;
250
+ reader;
251
+ events;
252
+ paused;
253
+ resumeCallback;
254
+ encoding;
255
+ constructor(readableStream) {
256
+ this.readableStream = readableStream;
257
+ this.reader = this.readableStream.getReader();
258
+ this.events = {
259
+ data: [],
260
+ end: [],
261
+ error: [],
262
+ readable: [],
263
+ close: [],
264
+ pause: [],
265
+ resume: []
266
+ };
267
+ this.paused = false;
268
+ this.resumeCallback = null;
269
+ this.encoding = null;
270
+ }
271
+ on(event, callback) {
272
+ var _a;
273
+ (_a = this.events[event]) == null ? void 0 : _a.push(callback);
274
+ }
275
+ off(event, callback) {
276
+ var _a;
277
+ this.events[event] = (_a = this.events[event]) == null ? void 0 : _a.filter((cb) => cb !== callback);
278
+ }
279
+ pipe(dest) {
280
+ this.on("data", (chunk) => {
281
+ if (dest instanceof _UndiciStreamWrapper) {
282
+ dest._write(chunk);
283
+ } else {
284
+ const writer = dest.getWriter();
285
+ writer.write(chunk).then(() => writer.releaseLock());
286
+ }
287
+ });
288
+ this.on("end", () => {
289
+ if (dest instanceof _UndiciStreamWrapper) {
290
+ dest._end();
291
+ } else {
292
+ const writer = dest.getWriter();
293
+ writer.close();
294
+ }
295
+ });
296
+ this.on("error", (error) => {
297
+ if (dest instanceof _UndiciStreamWrapper) {
298
+ dest._error(error);
299
+ } else {
300
+ const writer = dest.getWriter();
301
+ writer.abort(error);
302
+ }
303
+ });
304
+ this._startReading();
305
+ return dest;
306
+ }
307
+ pipeTo(dest) {
308
+ return this.pipe(dest);
309
+ }
310
+ unpipe(dest) {
311
+ this.off("data", (chunk) => {
312
+ if (dest instanceof _UndiciStreamWrapper) {
313
+ dest._write(chunk);
314
+ } else {
315
+ const writer = dest.getWriter();
316
+ writer.write(chunk).then(() => writer.releaseLock());
317
+ }
318
+ });
319
+ this.off("end", () => {
320
+ if (dest instanceof _UndiciStreamWrapper) {
321
+ dest._end();
322
+ } else {
323
+ const writer = dest.getWriter();
324
+ writer.close();
325
+ }
326
+ });
327
+ this.off("error", (error) => {
328
+ if (dest instanceof _UndiciStreamWrapper) {
329
+ dest._error(error);
330
+ } else {
331
+ const writer = dest.getWriter();
332
+ writer.abort(error);
333
+ }
334
+ });
335
+ }
336
+ destroy(error) {
337
+ this.reader.cancel(error).then(() => {
338
+ this._emit("close");
339
+ }).catch((err) => {
340
+ this._emit("error", err);
341
+ });
342
+ }
343
+ pause() {
344
+ this.paused = true;
345
+ this._emit("pause");
346
+ }
347
+ resume() {
348
+ if (this.paused) {
349
+ this.paused = false;
350
+ this._emit("resume");
351
+ if (this.resumeCallback) {
352
+ this.resumeCallback();
353
+ this.resumeCallback = null;
354
+ }
355
+ }
356
+ }
357
+ get isPaused() {
358
+ return this.paused;
359
+ }
360
+ async read() {
361
+ if (this.paused) {
362
+ await new Promise((resolve) => {
363
+ this.resumeCallback = resolve;
364
+ });
365
+ }
366
+ const { done, value } = await this.reader.read();
367
+ if (done) {
368
+ return void 0;
369
+ }
370
+ return value;
371
+ }
372
+ setEncoding(encoding) {
373
+ this.encoding = encoding;
374
+ }
375
+ async text() {
376
+ const chunks = [];
377
+ while (true) {
378
+ const { done, value } = await this.reader.read();
379
+ if (done) {
380
+ break;
381
+ }
382
+ if (value) {
383
+ chunks.push(value);
384
+ }
385
+ }
386
+ const decoder = new TextDecoder(this.encoding || "utf-8");
387
+ return decoder.decode(await new Blob(chunks).arrayBuffer());
388
+ }
389
+ async json() {
390
+ const text = await this.text();
391
+ return JSON.parse(text);
392
+ }
393
+ _write(chunk) {
394
+ this._emit("data", chunk);
395
+ }
396
+ _end() {
397
+ this._emit("end");
398
+ }
399
+ _error(error) {
400
+ this._emit("error", error);
401
+ }
402
+ _emit(event, data) {
403
+ if (this.events[event]) {
404
+ for (const callback of this.events[event] || []) {
405
+ callback(data);
406
+ }
407
+ }
408
+ }
409
+ async _startReading() {
410
+ try {
411
+ this._emit("readable");
412
+ while (true) {
413
+ if (this.paused) {
414
+ await new Promise((resolve) => {
415
+ this.resumeCallback = resolve;
416
+ });
417
+ }
418
+ const { done, value } = await this.reader.read();
419
+ if (done) {
420
+ this._emit("end");
421
+ this._emit("close");
422
+ break;
423
+ }
424
+ if (value) {
425
+ this._emit("data", value);
426
+ }
427
+ }
428
+ } catch (error) {
429
+ this._emit("error", error);
430
+ }
431
+ }
432
+ [Symbol.asyncIterator]() {
433
+ return {
434
+ next: async () => {
435
+ if (this.paused) {
436
+ await new Promise((resolve) => {
437
+ this.resumeCallback = resolve;
438
+ });
439
+ }
440
+ const { done, value } = await this.reader.read();
441
+ if (done) {
442
+ return { done: true, value: void 0 };
443
+ }
444
+ return { done: false, value };
445
+ },
446
+ [Symbol.asyncIterator]() {
447
+ return this;
448
+ }
449
+ };
450
+ }
451
+ };
452
+ }
453
+ });
454
+
455
+ // src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts
456
+ var NodePre18StreamWrapper_exports = {};
457
+ __export(NodePre18StreamWrapper_exports, {
458
+ NodePre18StreamWrapper: () => NodePre18StreamWrapper
459
+ });
460
+ var NodePre18StreamWrapper;
461
+ var init_NodePre18StreamWrapper = __esm({
462
+ "src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts"() {
463
+ "use strict";
464
+ NodePre18StreamWrapper = class {
465
+ readableStream;
466
+ encoding;
467
+ constructor(readableStream) {
468
+ this.readableStream = readableStream;
469
+ }
470
+ on(event, callback) {
471
+ this.readableStream.on(event, callback);
472
+ }
473
+ off(event, callback) {
474
+ this.readableStream.off(event, callback);
475
+ }
476
+ pipe(dest) {
477
+ this.readableStream.pipe(dest);
478
+ return dest;
479
+ }
480
+ pipeTo(dest) {
481
+ return this.pipe(dest);
482
+ }
483
+ unpipe(dest) {
484
+ if (dest) {
485
+ this.readableStream.unpipe(dest);
486
+ } else {
487
+ this.readableStream.unpipe();
488
+ }
489
+ }
490
+ destroy(error) {
491
+ this.readableStream.destroy(error);
492
+ }
493
+ pause() {
494
+ this.readableStream.pause();
495
+ }
496
+ resume() {
497
+ this.readableStream.resume();
498
+ }
499
+ get isPaused() {
500
+ return this.readableStream.isPaused();
501
+ }
502
+ async read() {
503
+ return new Promise((resolve, reject) => {
504
+ const chunk = this.readableStream.read();
505
+ if (chunk) {
506
+ resolve(chunk);
507
+ } else {
508
+ this.readableStream.once("readable", () => {
509
+ const chunk2 = this.readableStream.read();
510
+ resolve(chunk2);
511
+ });
512
+ this.readableStream.once("error", reject);
513
+ }
514
+ });
515
+ }
516
+ setEncoding(encoding) {
517
+ this.readableStream.setEncoding(encoding);
518
+ this.encoding = encoding;
519
+ }
520
+ async text() {
521
+ const chunks = [];
522
+ const encoder = new TextEncoder();
523
+ this.readableStream.setEncoding(this.encoding || "utf-8");
524
+ for await (const chunk of this.readableStream) {
525
+ chunks.push(encoder.encode(chunk));
526
+ }
527
+ const decoder = new TextDecoder(this.encoding || "utf-8");
528
+ return decoder.decode(Buffer.concat(chunks));
529
+ }
530
+ async json() {
531
+ const text = await this.text();
532
+ return JSON.parse(text);
533
+ }
534
+ [Symbol.asyncIterator]() {
535
+ const readableStream = this.readableStream;
536
+ const iterator = readableStream[Symbol.asyncIterator]();
537
+ return {
538
+ async next() {
539
+ const { value, done } = await iterator.next();
540
+ return { value, done };
541
+ },
542
+ [Symbol.asyncIterator]() {
543
+ return this;
544
+ }
545
+ };
546
+ }
547
+ };
548
+ }
549
+ });
550
+
551
+ // src/api/index.ts
552
+ var api_exports = {};
553
+ __export(api_exports, {
554
+ CrashPolicy: () => CrashPolicy,
555
+ HealthStatus: () => HealthStatus,
556
+ RunnerConfigVariant: () => RunnerConfigVariant,
557
+ datacenters: () => datacenters_exports,
558
+ health: () => health_exports,
559
+ metadata: () => metadata_exports,
560
+ namespaces: () => namespaces_exports,
561
+ runners: () => runners_exports
562
+ });
563
+
564
+ // src/api/types/CrashPolicy.ts
565
+ var CrashPolicy = {
566
+ Restart: "restart",
567
+ Sleep: "sleep",
568
+ Destroy: "destroy"
569
+ };
570
+
571
+ // src/api/types/HealthStatus.ts
572
+ var HealthStatus = {
573
+ Ok: "ok",
574
+ Error: "error"
575
+ };
576
+
577
+ // src/api/types/RunnerConfigVariant.ts
578
+ var RunnerConfigVariant = {
579
+ Serverless: "serverless",
580
+ Normal: "normal"
581
+ };
582
+
583
+ // src/api/resources/datacenters/index.ts
584
+ var datacenters_exports = {};
585
+
586
+ // src/api/resources/health/index.ts
587
+ var health_exports = {};
588
+
589
+ // src/api/resources/metadata/index.ts
590
+ var metadata_exports = {};
591
+
592
+ // src/api/resources/namespaces/index.ts
593
+ var namespaces_exports = {};
594
+
595
+ // src/api/resources/runners/index.ts
596
+ var runners_exports = {};
597
+
598
+ // src/core/json.ts
599
+ var toJson = (value, replacer, space) => {
600
+ return JSON.stringify(value, replacer, space);
601
+ };
602
+
603
+ // src/core/fetcher/createRequestUrl.ts
604
+ import qs from "qs";
605
+ function createRequestUrl(baseUrl, queryParameters) {
606
+ return Object.keys(queryParameters ?? {}).length > 0 ? `${baseUrl}?${qs.stringify(queryParameters, { arrayFormat: "repeat" })}` : baseUrl;
607
+ }
608
+
609
+ // src/core/runtime/runtime.ts
610
+ var RUNTIME = evaluateRuntime();
611
+ function evaluateRuntime() {
612
+ var _a, _b, _c, _d, _e;
613
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
614
+ if (isBrowser) {
615
+ return {
616
+ type: "browser",
617
+ version: window.navigator.userAgent
618
+ };
619
+ }
620
+ const isCloudflare = typeof globalThis !== "undefined" && ((_a = globalThis == null ? void 0 : globalThis.navigator) == null ? void 0 : _a.userAgent) === "Cloudflare-Workers";
621
+ if (isCloudflare) {
622
+ return {
623
+ type: "workerd"
624
+ };
625
+ }
626
+ const isEdgeRuntime = typeof EdgeRuntime === "string";
627
+ if (isEdgeRuntime) {
628
+ return {
629
+ type: "edge-runtime"
630
+ };
631
+ }
632
+ const isWebWorker = typeof self === "object" && // @ts-ignore
633
+ typeof (self == null ? void 0 : self.importScripts) === "function" && (((_b = self.constructor) == null ? void 0 : _b.name) === "DedicatedWorkerGlobalScope" || ((_c = self.constructor) == null ? void 0 : _c.name) === "ServiceWorkerGlobalScope" || ((_d = self.constructor) == null ? void 0 : _d.name) === "SharedWorkerGlobalScope");
634
+ if (isWebWorker) {
635
+ return {
636
+ type: "web-worker"
637
+ };
638
+ }
639
+ const isDeno = typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
640
+ if (isDeno) {
641
+ return {
642
+ type: "deno",
643
+ version: Deno.version.deno
644
+ };
645
+ }
646
+ const isBun = typeof Bun !== "undefined" && typeof Bun.version !== "undefined";
647
+ if (isBun) {
648
+ return {
649
+ type: "bun",
650
+ version: Bun.version
651
+ };
652
+ }
653
+ const isNode = typeof process !== "undefined" && "version" in process && !!process.version && "versions" in process && !!((_e = process.versions) == null ? void 0 : _e.node);
654
+ if (isNode) {
655
+ return {
656
+ type: "node",
657
+ version: process.versions.node,
658
+ parsedVersion: Number(process.versions.node.split(".")[0])
659
+ };
660
+ }
661
+ const isReactNative = typeof navigator !== "undefined" && (navigator == null ? void 0 : navigator.product) === "ReactNative";
662
+ if (isReactNative) {
663
+ return {
664
+ type: "react-native"
665
+ };
666
+ }
667
+ return {
668
+ type: "unknown"
669
+ };
670
+ }
671
+
672
+ // src/core/fetcher/getFetchFn.ts
673
+ async function getFetchFn() {
674
+ if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) {
675
+ return fetch;
676
+ }
677
+ if (RUNTIME.type === "node") {
678
+ return (await import("node-fetch")).default;
679
+ }
680
+ if (typeof fetch == "function") {
681
+ return fetch;
682
+ }
683
+ return (await import("node-fetch")).default;
684
+ }
685
+
686
+ // src/core/fetcher/getRequestBody.ts
687
+ async function getRequestBody({ body, type }) {
688
+ if (type.includes("json")) {
689
+ return toJson(body);
690
+ } else {
691
+ return body;
692
+ }
693
+ }
694
+
695
+ // src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts
696
+ async function chooseStreamWrapper(responseBody) {
697
+ if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) {
698
+ return new (await Promise.resolve().then(() => (init_Node18UniversalStreamWrapper(), Node18UniversalStreamWrapper_exports))).Node18UniversalStreamWrapper(
699
+ responseBody
700
+ );
701
+ } else if (RUNTIME.type !== "node" && typeof fetch === "function") {
702
+ return new (await Promise.resolve().then(() => (init_UndiciStreamWrapper(), UndiciStreamWrapper_exports))).UndiciStreamWrapper(responseBody);
703
+ } else {
704
+ return new (await Promise.resolve().then(() => (init_NodePre18StreamWrapper(), NodePre18StreamWrapper_exports))).NodePre18StreamWrapper(responseBody);
705
+ }
706
+ }
707
+
708
+ // src/core/fetcher/getResponseBody.ts
709
+ async function getResponseBody(response, responseType) {
710
+ if (response.body != null && responseType === "blob") {
711
+ return await response.blob();
712
+ } else if (response.body != null && responseType === "arrayBuffer") {
713
+ return await response.arrayBuffer();
714
+ } else if (response.body != null && responseType === "sse") {
715
+ return response.body;
716
+ } else if (response.body != null && responseType === "streaming") {
717
+ return chooseStreamWrapper(response.body);
718
+ } else if (response.body != null && responseType === "text") {
719
+ return await response.text();
720
+ } else {
721
+ const text = await response.text();
722
+ if (text.length > 0) {
723
+ try {
724
+ let responseBody = JSON.parse(text);
725
+ return responseBody;
726
+ } catch (err) {
727
+ return {
728
+ ok: false,
729
+ error: {
730
+ reason: "non-json",
731
+ statusCode: response.status,
732
+ rawBody: text
733
+ }
734
+ };
735
+ }
736
+ } else {
737
+ return void 0;
738
+ }
739
+ }
740
+ }
741
+
742
+ // src/core/fetcher/signals.ts
743
+ var TIMEOUT = "timeout";
744
+ function getTimeoutSignal(timeoutMs) {
745
+ const controller = new AbortController();
746
+ const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
747
+ return { signal: controller.signal, abortId };
748
+ }
749
+ function anySignal(...args) {
750
+ const signals = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
751
+ const controller = new AbortController();
752
+ for (const signal of signals) {
753
+ if (signal.aborted) {
754
+ controller.abort(signal == null ? void 0 : signal.reason);
755
+ break;
756
+ }
757
+ signal.addEventListener("abort", () => controller.abort(signal == null ? void 0 : signal.reason), {
758
+ signal: controller.signal
759
+ });
760
+ }
761
+ return controller.signal;
762
+ }
763
+
764
+ // src/core/fetcher/makeRequest.ts
765
+ var makeRequest = async (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex) => {
766
+ const signals = [];
767
+ let timeoutAbortId = void 0;
768
+ if (timeoutMs != null) {
769
+ const { signal, abortId } = getTimeoutSignal(timeoutMs);
770
+ timeoutAbortId = abortId;
771
+ signals.push(signal);
772
+ }
773
+ if (abortSignal != null) {
774
+ signals.push(abortSignal);
775
+ }
776
+ let newSignals = anySignal(signals);
777
+ const response = await fetchFn(url, {
778
+ method,
779
+ headers,
780
+ body: requestBody,
781
+ signal: newSignals,
782
+ credentials: withCredentials ? "include" : void 0,
783
+ // @ts-ignore
784
+ duplex
785
+ });
786
+ if (timeoutAbortId != null) {
787
+ clearTimeout(timeoutAbortId);
788
+ }
789
+ return response;
790
+ };
791
+
792
+ // src/core/fetcher/requestWithRetries.ts
793
+ var INITIAL_RETRY_DELAY = 1e3;
794
+ var MAX_RETRY_DELAY = 6e4;
795
+ var DEFAULT_MAX_RETRIES = 2;
796
+ var JITTER_FACTOR = 0.2;
797
+ function addJitter(delay) {
798
+ const jitterMultiplier = 1 + (Math.random() * 2 - 1) * JITTER_FACTOR;
799
+ return delay * jitterMultiplier;
800
+ }
801
+ async function requestWithRetries(requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
802
+ let response = await requestFn();
803
+ for (let i = 0; i < maxRetries; ++i) {
804
+ if ([408, 429].includes(response.status) || response.status >= 500) {
805
+ const baseDelay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
806
+ const delayWithJitter = addJitter(baseDelay);
807
+ await new Promise((resolve) => setTimeout(resolve, delayWithJitter));
808
+ response = await requestFn();
809
+ } else {
810
+ break;
811
+ }
812
+ }
813
+ return response;
814
+ }
815
+
816
+ // src/core/fetcher/Fetcher.ts
817
+ async function fetcherImpl(args) {
818
+ const headers = {};
819
+ if (args.body !== void 0 && args.contentType != null) {
820
+ headers["Content-Type"] = args.contentType;
821
+ }
822
+ if (args.headers != null) {
823
+ for (const [key, value] of Object.entries(args.headers)) {
824
+ if (value != null) {
825
+ headers[key] = value;
826
+ }
827
+ }
828
+ }
829
+ const url = createRequestUrl(args.url, args.queryParameters);
830
+ const requestBody = await getRequestBody({
831
+ body: args.body,
832
+ type: args.requestType === "json" ? "json" : "other"
833
+ });
834
+ const fetchFn = await getFetchFn();
835
+ try {
836
+ const response = await requestWithRetries(
837
+ async () => makeRequest(
838
+ fetchFn,
839
+ url,
840
+ args.method,
841
+ headers,
842
+ requestBody,
843
+ args.timeoutMs,
844
+ args.abortSignal,
845
+ args.withCredentials,
846
+ args.duplex
847
+ ),
848
+ args.maxRetries
849
+ );
850
+ const responseBody = await getResponseBody(response, args.responseType);
851
+ if (response.status >= 200 && response.status < 400) {
852
+ return {
853
+ ok: true,
854
+ body: responseBody,
855
+ headers: response.headers
856
+ };
857
+ } else {
858
+ return {
859
+ ok: false,
860
+ error: {
861
+ reason: "status-code",
862
+ statusCode: response.status,
863
+ body: responseBody
864
+ }
865
+ };
866
+ }
867
+ } catch (error) {
868
+ if (args.abortSignal != null && args.abortSignal.aborted) {
869
+ return {
870
+ ok: false,
871
+ error: {
872
+ reason: "unknown",
873
+ errorMessage: "The user aborted a request"
874
+ }
875
+ };
876
+ } else if (error instanceof Error && error.name === "AbortError") {
877
+ return {
878
+ ok: false,
879
+ error: {
880
+ reason: "timeout"
881
+ }
882
+ };
883
+ } else if (error instanceof Error) {
884
+ return {
885
+ ok: false,
886
+ error: {
887
+ reason: "unknown",
888
+ errorMessage: error.message
889
+ }
890
+ };
891
+ }
892
+ return {
893
+ ok: false,
894
+ error: {
895
+ reason: "unknown",
896
+ errorMessage: toJson(error)
897
+ }
898
+ };
899
+ }
900
+ }
901
+ var fetcher = fetcherImpl;
902
+
903
+ // src/core/fetcher/Supplier.ts
904
+ var Supplier = {
905
+ get: async (supplier) => {
906
+ if (typeof supplier === "function") {
907
+ return supplier();
908
+ } else {
909
+ return supplier;
910
+ }
911
+ }
912
+ };
913
+
914
+ // src/core/auth/BasicAuth.ts
915
+ import { Base64 } from "js-base64";
916
+
917
+ // src/core/schemas/index.ts
918
+ var schemas_exports = {};
919
+ __export(schemas_exports, {
920
+ JsonError: () => JsonError,
921
+ ParseError: () => ParseError,
922
+ any: () => any,
923
+ bigint: () => bigint,
924
+ boolean: () => boolean,
925
+ booleanLiteral: () => booleanLiteral,
926
+ date: () => date,
927
+ discriminant: () => discriminant,
928
+ enum_: () => enum_,
929
+ getObjectLikeUtils: () => getObjectLikeUtils,
930
+ getObjectUtils: () => getObjectUtils,
931
+ getSchemaUtils: () => getSchemaUtils,
932
+ isProperty: () => isProperty,
933
+ lazy: () => lazy,
934
+ lazyObject: () => lazyObject,
935
+ list: () => list,
936
+ number: () => number,
937
+ object: () => object,
938
+ objectWithoutOptionalProperties: () => objectWithoutOptionalProperties,
939
+ optional: () => optional,
940
+ property: () => property,
941
+ record: () => record,
942
+ set: () => set,
943
+ string: () => string,
944
+ stringLiteral: () => stringLiteral,
945
+ transform: () => transform,
946
+ undiscriminatedUnion: () => undiscriminatedUnion,
947
+ union: () => union,
948
+ unknown: () => unknown,
949
+ withParsedProperties: () => withParsedProperties
950
+ });
951
+
952
+ // src/core/schemas/Schema.ts
953
+ var SchemaType = {
954
+ BIGINT: "bigint",
955
+ DATE: "date",
956
+ ENUM: "enum",
957
+ LIST: "list",
958
+ STRING_LITERAL: "stringLiteral",
959
+ BOOLEAN_LITERAL: "booleanLiteral",
960
+ OBJECT: "object",
961
+ ANY: "any",
962
+ BOOLEAN: "boolean",
963
+ NUMBER: "number",
964
+ STRING: "string",
965
+ UNKNOWN: "unknown",
966
+ RECORD: "record",
967
+ SET: "set",
968
+ UNION: "union",
969
+ UNDISCRIMINATED_UNION: "undiscriminatedUnion",
970
+ NULLABLE: "nullable",
971
+ OPTIONAL: "optional",
972
+ OPTIONAL_NULLABLE: "optionalNullable"
973
+ };
974
+
975
+ // src/core/schemas/utils/getErrorMessageForIncorrectType.ts
976
+ function getErrorMessageForIncorrectType(value, expectedType) {
977
+ return `Expected ${expectedType}. Received ${getTypeAsString(value)}.`;
978
+ }
979
+ function getTypeAsString(value) {
980
+ if (Array.isArray(value)) {
981
+ return "list";
982
+ }
983
+ if (value === null) {
984
+ return "null";
985
+ }
986
+ if (value instanceof BigInt) {
987
+ return "BigInt";
988
+ }
989
+ switch (typeof value) {
990
+ case "string":
991
+ return `"${value}"`;
992
+ case "bigint":
993
+ case "number":
994
+ case "boolean":
995
+ case "undefined":
996
+ return `${value}`;
997
+ }
998
+ return typeof value;
999
+ }
1000
+
1001
+ // src/core/schemas/utils/maybeSkipValidation.ts
1002
+ function maybeSkipValidation(schema) {
1003
+ return {
1004
+ ...schema,
1005
+ json: transformAndMaybeSkipValidation(schema.json),
1006
+ parse: transformAndMaybeSkipValidation(schema.parse)
1007
+ };
1008
+ }
1009
+ function transformAndMaybeSkipValidation(transform2) {
1010
+ return (value, opts) => {
1011
+ const transformed = transform2(value, opts);
1012
+ const { skipValidation = false } = opts ?? {};
1013
+ if (!transformed.ok && skipValidation) {
1014
+ console.warn(
1015
+ [
1016
+ "Failed to validate.",
1017
+ ...transformed.errors.map(
1018
+ (error) => " - " + (error.path.length > 0 ? `${error.path.join(".")}: ${error.message}` : error.message)
1019
+ )
1020
+ ].join("\n")
1021
+ );
1022
+ return {
1023
+ ok: true,
1024
+ value
1025
+ };
1026
+ } else {
1027
+ return transformed;
1028
+ }
1029
+ };
1030
+ }
1031
+
1032
+ // src/core/schemas/builders/schema-utils/stringifyValidationErrors.ts
1033
+ function stringifyValidationError(error) {
1034
+ if (error.path.length === 0) {
1035
+ return error.message;
1036
+ }
1037
+ return `${error.path.join(" -> ")}: ${error.message}`;
1038
+ }
1039
+
1040
+ // src/core/schemas/builders/schema-utils/JsonError.ts
1041
+ var JsonError = class _JsonError extends Error {
1042
+ constructor(errors) {
1043
+ super(errors.map(stringifyValidationError).join("; "));
1044
+ this.errors = errors;
1045
+ Object.setPrototypeOf(this, _JsonError.prototype);
1046
+ }
1047
+ };
1048
+
1049
+ // src/core/schemas/builders/schema-utils/ParseError.ts
1050
+ var ParseError = class _ParseError extends Error {
1051
+ constructor(errors) {
1052
+ super(errors.map(stringifyValidationError).join("; "));
1053
+ this.errors = errors;
1054
+ Object.setPrototypeOf(this, _ParseError.prototype);
1055
+ }
1056
+ };
1057
+
1058
+ // src/core/schemas/builders/schema-utils/getSchemaUtils.ts
1059
+ function getSchemaUtils(schema) {
1060
+ return {
1061
+ nullable: () => nullable(schema),
1062
+ optional: () => optional(schema),
1063
+ optionalNullable: () => optionalNullable(schema),
1064
+ transform: (transformer) => transform(schema, transformer),
1065
+ parseOrThrow: (raw, opts) => {
1066
+ const parsed = schema.parse(raw, opts);
1067
+ if (parsed.ok) {
1068
+ return parsed.value;
1069
+ }
1070
+ throw new ParseError(parsed.errors);
1071
+ },
1072
+ jsonOrThrow: (parsed, opts) => {
1073
+ const raw = schema.json(parsed, opts);
1074
+ if (raw.ok) {
1075
+ return raw.value;
1076
+ }
1077
+ throw new JsonError(raw.errors);
1078
+ }
1079
+ };
1080
+ }
1081
+ function nullable(schema) {
1082
+ const baseSchema = {
1083
+ parse: (raw, opts) => {
1084
+ if (raw == null) {
1085
+ return {
1086
+ ok: true,
1087
+ value: null
1088
+ };
1089
+ }
1090
+ return schema.parse(raw, opts);
1091
+ },
1092
+ json: (parsed, opts) => {
1093
+ if (parsed == null) {
1094
+ return {
1095
+ ok: true,
1096
+ value: null
1097
+ };
1098
+ }
1099
+ return schema.json(parsed, opts);
1100
+ },
1101
+ getType: () => SchemaType.NULLABLE
1102
+ };
1103
+ return {
1104
+ ...baseSchema,
1105
+ ...getSchemaUtils(baseSchema)
1106
+ };
1107
+ }
1108
+ function optional(schema) {
1109
+ const baseSchema = {
1110
+ parse: (raw, opts) => {
1111
+ if (raw == null) {
1112
+ return {
1113
+ ok: true,
1114
+ value: void 0
1115
+ };
1116
+ }
1117
+ return schema.parse(raw, opts);
1118
+ },
1119
+ json: (parsed, opts) => {
1120
+ if ((opts == null ? void 0 : opts.omitUndefined) && parsed === void 0) {
1121
+ return {
1122
+ ok: true,
1123
+ value: void 0
1124
+ };
1125
+ }
1126
+ if (parsed == null) {
1127
+ return {
1128
+ ok: true,
1129
+ value: null
1130
+ };
1131
+ }
1132
+ return schema.json(parsed, opts);
1133
+ },
1134
+ getType: () => SchemaType.OPTIONAL
1135
+ };
1136
+ return {
1137
+ ...baseSchema,
1138
+ ...getSchemaUtils(baseSchema)
1139
+ };
1140
+ }
1141
+ function optionalNullable(schema) {
1142
+ const baseSchema = {
1143
+ parse: (raw, opts) => {
1144
+ if (raw === void 0) {
1145
+ return {
1146
+ ok: true,
1147
+ value: void 0
1148
+ };
1149
+ }
1150
+ if (raw === null) {
1151
+ return {
1152
+ ok: true,
1153
+ value: null
1154
+ };
1155
+ }
1156
+ return schema.parse(raw, opts);
1157
+ },
1158
+ json: (parsed, opts) => {
1159
+ if (parsed === void 0) {
1160
+ return {
1161
+ ok: true,
1162
+ value: void 0
1163
+ };
1164
+ }
1165
+ if (parsed === null) {
1166
+ return {
1167
+ ok: true,
1168
+ value: null
1169
+ };
1170
+ }
1171
+ return schema.json(parsed, opts);
1172
+ },
1173
+ getType: () => SchemaType.OPTIONAL_NULLABLE
1174
+ };
1175
+ return {
1176
+ ...baseSchema,
1177
+ ...getSchemaUtils(baseSchema)
1178
+ };
1179
+ }
1180
+ function transform(schema, transformer) {
1181
+ const baseSchema = {
1182
+ parse: (raw, opts) => {
1183
+ const parsed = schema.parse(raw, opts);
1184
+ if (!parsed.ok) {
1185
+ return parsed;
1186
+ }
1187
+ return {
1188
+ ok: true,
1189
+ value: transformer.transform(parsed.value)
1190
+ };
1191
+ },
1192
+ json: (transformed, opts) => {
1193
+ const parsed = transformer.untransform(transformed);
1194
+ return schema.json(parsed, opts);
1195
+ },
1196
+ getType: () => schema.getType()
1197
+ };
1198
+ return {
1199
+ ...baseSchema,
1200
+ ...getSchemaUtils(baseSchema)
1201
+ };
1202
+ }
1203
+
1204
+ // src/core/schemas/builders/bigint/bigint.ts
1205
+ function bigint() {
1206
+ const baseSchema = {
1207
+ parse: (raw, { breadcrumbsPrefix = [] } = {}) => {
1208
+ if (typeof raw === "bigint") {
1209
+ return {
1210
+ ok: true,
1211
+ value: raw
1212
+ };
1213
+ }
1214
+ if (typeof raw === "number") {
1215
+ return {
1216
+ ok: true,
1217
+ value: BigInt(raw)
1218
+ };
1219
+ }
1220
+ return {
1221
+ ok: false,
1222
+ errors: [
1223
+ {
1224
+ path: breadcrumbsPrefix,
1225
+ message: getErrorMessageForIncorrectType(raw, "bigint | number")
1226
+ }
1227
+ ]
1228
+ };
1229
+ },
1230
+ json: (bigint2, { breadcrumbsPrefix = [] } = {}) => {
1231
+ if (typeof bigint2 !== "bigint") {
1232
+ return {
1233
+ ok: false,
1234
+ errors: [
1235
+ {
1236
+ path: breadcrumbsPrefix,
1237
+ message: getErrorMessageForIncorrectType(bigint2, "bigint")
1238
+ }
1239
+ ]
1240
+ };
1241
+ }
1242
+ return {
1243
+ ok: true,
1244
+ value: bigint2
1245
+ };
1246
+ },
1247
+ getType: () => SchemaType.BIGINT
1248
+ };
1249
+ return {
1250
+ ...maybeSkipValidation(baseSchema),
1251
+ ...getSchemaUtils(baseSchema)
1252
+ };
1253
+ }
1254
+
1255
+ // src/core/schemas/builders/date/date.ts
1256
+ var ISO_8601_REGEX = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
1257
+ function date() {
1258
+ const baseSchema = {
1259
+ parse: (raw, { breadcrumbsPrefix = [] } = {}) => {
1260
+ if (typeof raw !== "string") {
1261
+ return {
1262
+ ok: false,
1263
+ errors: [
1264
+ {
1265
+ path: breadcrumbsPrefix,
1266
+ message: getErrorMessageForIncorrectType(raw, "string")
1267
+ }
1268
+ ]
1269
+ };
1270
+ }
1271
+ if (!ISO_8601_REGEX.test(raw)) {
1272
+ return {
1273
+ ok: false,
1274
+ errors: [
1275
+ {
1276
+ path: breadcrumbsPrefix,
1277
+ message: getErrorMessageForIncorrectType(raw, "ISO 8601 date string")
1278
+ }
1279
+ ]
1280
+ };
1281
+ }
1282
+ return {
1283
+ ok: true,
1284
+ value: new Date(raw)
1285
+ };
1286
+ },
1287
+ json: (date2, { breadcrumbsPrefix = [] } = {}) => {
1288
+ if (date2 instanceof Date) {
1289
+ return {
1290
+ ok: true,
1291
+ value: date2.toISOString()
1292
+ };
1293
+ } else {
1294
+ return {
1295
+ ok: false,
1296
+ errors: [
1297
+ {
1298
+ path: breadcrumbsPrefix,
1299
+ message: getErrorMessageForIncorrectType(date2, "Date object")
1300
+ }
1301
+ ]
1302
+ };
1303
+ }
1304
+ },
1305
+ getType: () => SchemaType.DATE
1306
+ };
1307
+ return {
1308
+ ...maybeSkipValidation(baseSchema),
1309
+ ...getSchemaUtils(baseSchema)
1310
+ };
1311
+ }
1312
+
1313
+ // src/core/schemas/utils/createIdentitySchemaCreator.ts
1314
+ function createIdentitySchemaCreator(schemaType, validate) {
1315
+ return () => {
1316
+ const baseSchema = {
1317
+ parse: validate,
1318
+ json: validate,
1319
+ getType: () => schemaType
1320
+ };
1321
+ return {
1322
+ ...maybeSkipValidation(baseSchema),
1323
+ ...getSchemaUtils(baseSchema)
1324
+ };
1325
+ };
1326
+ }
1327
+
1328
+ // src/core/schemas/builders/enum/enum.ts
1329
+ function enum_(values) {
1330
+ const validValues = new Set(values);
1331
+ const schemaCreator = createIdentitySchemaCreator(
1332
+ SchemaType.ENUM,
1333
+ (value, { allowUnrecognizedEnumValues, breadcrumbsPrefix = [] } = {}) => {
1334
+ if (typeof value !== "string") {
1335
+ return {
1336
+ ok: false,
1337
+ errors: [
1338
+ {
1339
+ path: breadcrumbsPrefix,
1340
+ message: getErrorMessageForIncorrectType(value, "string")
1341
+ }
1342
+ ]
1343
+ };
1344
+ }
1345
+ if (!validValues.has(value) && !allowUnrecognizedEnumValues) {
1346
+ return {
1347
+ ok: false,
1348
+ errors: [
1349
+ {
1350
+ path: breadcrumbsPrefix,
1351
+ message: getErrorMessageForIncorrectType(value, "enum")
1352
+ }
1353
+ ]
1354
+ };
1355
+ }
1356
+ return {
1357
+ ok: true,
1358
+ value
1359
+ };
1360
+ }
1361
+ );
1362
+ return schemaCreator();
1363
+ }
1364
+
1365
+ // src/core/schemas/builders/lazy/lazy.ts
1366
+ function lazy(getter) {
1367
+ const baseSchema = constructLazyBaseSchema(getter);
1368
+ return {
1369
+ ...baseSchema,
1370
+ ...getSchemaUtils(baseSchema)
1371
+ };
1372
+ }
1373
+ function constructLazyBaseSchema(getter) {
1374
+ return {
1375
+ parse: (raw, opts) => getMemoizedSchema(getter).parse(raw, opts),
1376
+ json: (parsed, opts) => getMemoizedSchema(getter).json(parsed, opts),
1377
+ getType: () => getMemoizedSchema(getter).getType()
1378
+ };
1379
+ }
1380
+ function getMemoizedSchema(getter) {
1381
+ const castedGetter = getter;
1382
+ if (castedGetter.__zurg_memoized == null) {
1383
+ castedGetter.__zurg_memoized = getter();
1384
+ }
1385
+ return castedGetter.__zurg_memoized;
1386
+ }
1387
+
1388
+ // src/core/schemas/utils/entries.ts
1389
+ function entries(object2) {
1390
+ return Object.entries(object2);
1391
+ }
1392
+
1393
+ // src/core/schemas/utils/filterObject.ts
1394
+ function filterObject(obj, keysToInclude) {
1395
+ const keysToIncludeSet = new Set(keysToInclude);
1396
+ return Object.entries(obj).reduce(
1397
+ (acc, [key, value]) => {
1398
+ if (keysToIncludeSet.has(key)) {
1399
+ acc[key] = value;
1400
+ }
1401
+ return acc;
1402
+ },
1403
+ {}
1404
+ );
1405
+ }
1406
+
1407
+ // src/core/schemas/utils/isPlainObject.ts
1408
+ function isPlainObject(value) {
1409
+ if (typeof value !== "object" || value === null) {
1410
+ return false;
1411
+ }
1412
+ if (Object.getPrototypeOf(value) === null) {
1413
+ return true;
1414
+ }
1415
+ let proto = value;
1416
+ while (Object.getPrototypeOf(proto) !== null) {
1417
+ proto = Object.getPrototypeOf(proto);
1418
+ }
1419
+ return Object.getPrototypeOf(value) === proto;
1420
+ }
1421
+
1422
+ // src/core/schemas/utils/keys.ts
1423
+ function keys(object2) {
1424
+ return Object.keys(object2);
1425
+ }
1426
+
1427
+ // src/core/schemas/utils/partition.ts
1428
+ function partition(items, predicate) {
1429
+ const trueItems = [], falseItems = [];
1430
+ for (const item of items) {
1431
+ if (predicate(item)) {
1432
+ trueItems.push(item);
1433
+ } else {
1434
+ falseItems.push(item);
1435
+ }
1436
+ }
1437
+ return [trueItems, falseItems];
1438
+ }
1439
+
1440
+ // src/core/schemas/builders/object-like/getObjectLikeUtils.ts
1441
+ function getObjectLikeUtils(schema) {
1442
+ return {
1443
+ withParsedProperties: (properties) => withParsedProperties(schema, properties)
1444
+ };
1445
+ }
1446
+ function withParsedProperties(objectLike, properties) {
1447
+ const objectSchema = {
1448
+ parse: (raw, opts) => {
1449
+ const parsedObject = objectLike.parse(raw, opts);
1450
+ if (!parsedObject.ok) {
1451
+ return parsedObject;
1452
+ }
1453
+ const additionalProperties = Object.entries(properties).reduce(
1454
+ (processed, [key, value]) => {
1455
+ return {
1456
+ ...processed,
1457
+ [key]: typeof value === "function" ? value(parsedObject.value) : value
1458
+ };
1459
+ },
1460
+ {}
1461
+ );
1462
+ return {
1463
+ ok: true,
1464
+ value: {
1465
+ ...parsedObject.value,
1466
+ ...additionalProperties
1467
+ }
1468
+ };
1469
+ },
1470
+ json: (parsed, opts) => {
1471
+ if (!isPlainObject(parsed)) {
1472
+ return {
1473
+ ok: false,
1474
+ errors: [
1475
+ {
1476
+ path: (opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [],
1477
+ message: getErrorMessageForIncorrectType(parsed, "object")
1478
+ }
1479
+ ]
1480
+ };
1481
+ }
1482
+ const addedPropertyKeys = new Set(Object.keys(properties));
1483
+ const parsedWithoutAddedProperties = filterObject(
1484
+ parsed,
1485
+ Object.keys(parsed).filter((key) => !addedPropertyKeys.has(key))
1486
+ );
1487
+ return objectLike.json(parsedWithoutAddedProperties, opts);
1488
+ },
1489
+ getType: () => objectLike.getType()
1490
+ };
1491
+ return {
1492
+ ...objectSchema,
1493
+ ...getSchemaUtils(objectSchema),
1494
+ ...getObjectLikeUtils(objectSchema)
1495
+ };
1496
+ }
1497
+
1498
+ // src/core/schemas/builders/object/property.ts
1499
+ function property(rawKey, valueSchema) {
1500
+ return {
1501
+ rawKey,
1502
+ valueSchema,
1503
+ isProperty: true
1504
+ };
1505
+ }
1506
+ function isProperty(maybeProperty) {
1507
+ return maybeProperty.isProperty;
1508
+ }
1509
+
1510
+ // src/core/schemas/builders/object/object.ts
1511
+ function object(schemas) {
1512
+ const baseSchema = {
1513
+ _getRawProperties: () => Object.entries(schemas).map(
1514
+ ([parsedKey, propertySchema]) => isProperty(propertySchema) ? propertySchema.rawKey : parsedKey
1515
+ ),
1516
+ _getParsedProperties: () => keys(schemas),
1517
+ parse: (raw, opts) => {
1518
+ const rawKeyToProperty = {};
1519
+ const requiredKeys = [];
1520
+ for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
1521
+ const rawKey = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.rawKey : parsedKey;
1522
+ const valueSchema = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.valueSchema : schemaOrObjectProperty;
1523
+ const property2 = {
1524
+ rawKey,
1525
+ parsedKey,
1526
+ valueSchema
1527
+ };
1528
+ rawKeyToProperty[rawKey] = property2;
1529
+ if (isSchemaRequired(valueSchema)) {
1530
+ requiredKeys.push(rawKey);
1531
+ }
1532
+ }
1533
+ return validateAndTransformObject({
1534
+ value: raw,
1535
+ requiredKeys,
1536
+ getProperty: (rawKey) => {
1537
+ const property2 = rawKeyToProperty[rawKey];
1538
+ if (property2 == null) {
1539
+ return void 0;
1540
+ }
1541
+ return {
1542
+ transformedKey: property2.parsedKey,
1543
+ transform: (propertyValue) => property2.valueSchema.parse(propertyValue, {
1544
+ ...opts,
1545
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], rawKey]
1546
+ })
1547
+ };
1548
+ },
1549
+ unrecognizedObjectKeys: opts == null ? void 0 : opts.unrecognizedObjectKeys,
1550
+ skipValidation: opts == null ? void 0 : opts.skipValidation,
1551
+ breadcrumbsPrefix: opts == null ? void 0 : opts.breadcrumbsPrefix,
1552
+ omitUndefined: opts == null ? void 0 : opts.omitUndefined
1553
+ });
1554
+ },
1555
+ json: (parsed, opts) => {
1556
+ const requiredKeys = [];
1557
+ for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
1558
+ const valueSchema = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.valueSchema : schemaOrObjectProperty;
1559
+ if (isSchemaRequired(valueSchema)) {
1560
+ requiredKeys.push(parsedKey);
1561
+ }
1562
+ }
1563
+ return validateAndTransformObject({
1564
+ value: parsed,
1565
+ requiredKeys,
1566
+ getProperty: (parsedKey) => {
1567
+ const property2 = schemas[parsedKey];
1568
+ if (property2 == null) {
1569
+ return void 0;
1570
+ }
1571
+ if (isProperty(property2)) {
1572
+ return {
1573
+ transformedKey: property2.rawKey,
1574
+ transform: (propertyValue) => property2.valueSchema.json(propertyValue, {
1575
+ ...opts,
1576
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], parsedKey]
1577
+ })
1578
+ };
1579
+ } else {
1580
+ return {
1581
+ transformedKey: parsedKey,
1582
+ transform: (propertyValue) => property2.json(propertyValue, {
1583
+ ...opts,
1584
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], parsedKey]
1585
+ })
1586
+ };
1587
+ }
1588
+ },
1589
+ unrecognizedObjectKeys: opts == null ? void 0 : opts.unrecognizedObjectKeys,
1590
+ skipValidation: opts == null ? void 0 : opts.skipValidation,
1591
+ breadcrumbsPrefix: opts == null ? void 0 : opts.breadcrumbsPrefix,
1592
+ omitUndefined: opts == null ? void 0 : opts.omitUndefined
1593
+ });
1594
+ },
1595
+ getType: () => SchemaType.OBJECT
1596
+ };
1597
+ return {
1598
+ ...maybeSkipValidation(baseSchema),
1599
+ ...getSchemaUtils(baseSchema),
1600
+ ...getObjectLikeUtils(baseSchema),
1601
+ ...getObjectUtils(baseSchema)
1602
+ };
1603
+ }
1604
+ function validateAndTransformObject({
1605
+ value,
1606
+ requiredKeys,
1607
+ getProperty,
1608
+ unrecognizedObjectKeys = "fail",
1609
+ skipValidation = false,
1610
+ breadcrumbsPrefix = []
1611
+ }) {
1612
+ if (!isPlainObject(value)) {
1613
+ return {
1614
+ ok: false,
1615
+ errors: [
1616
+ {
1617
+ path: breadcrumbsPrefix,
1618
+ message: getErrorMessageForIncorrectType(value, "object")
1619
+ }
1620
+ ]
1621
+ };
1622
+ }
1623
+ const missingRequiredKeys = new Set(requiredKeys);
1624
+ const errors = [];
1625
+ const transformed = {};
1626
+ for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
1627
+ const property2 = getProperty(preTransformedKey);
1628
+ if (property2 != null) {
1629
+ missingRequiredKeys.delete(preTransformedKey);
1630
+ const value2 = property2.transform(preTransformedItemValue);
1631
+ if (value2.ok) {
1632
+ transformed[property2.transformedKey] = value2.value;
1633
+ } else {
1634
+ transformed[preTransformedKey] = preTransformedItemValue;
1635
+ errors.push(...value2.errors);
1636
+ }
1637
+ } else {
1638
+ switch (unrecognizedObjectKeys) {
1639
+ case "fail":
1640
+ errors.push({
1641
+ path: [...breadcrumbsPrefix, preTransformedKey],
1642
+ message: `Unexpected key "${preTransformedKey}"`
1643
+ });
1644
+ break;
1645
+ case "strip":
1646
+ break;
1647
+ case "passthrough":
1648
+ transformed[preTransformedKey] = preTransformedItemValue;
1649
+ break;
1650
+ }
1651
+ }
1652
+ }
1653
+ errors.push(
1654
+ ...requiredKeys.filter((key) => missingRequiredKeys.has(key)).map((key) => ({
1655
+ path: breadcrumbsPrefix,
1656
+ message: `Missing required key "${key}"`
1657
+ }))
1658
+ );
1659
+ if (errors.length === 0 || skipValidation) {
1660
+ return {
1661
+ ok: true,
1662
+ value: transformed
1663
+ };
1664
+ } else {
1665
+ return {
1666
+ ok: false,
1667
+ errors
1668
+ };
1669
+ }
1670
+ }
1671
+ function getObjectUtils(schema) {
1672
+ return {
1673
+ extend: (extension) => {
1674
+ const baseSchema = {
1675
+ _getParsedProperties: () => [...schema._getParsedProperties(), ...extension._getParsedProperties()],
1676
+ _getRawProperties: () => [...schema._getRawProperties(), ...extension._getRawProperties()],
1677
+ parse: (raw, opts) => {
1678
+ return validateAndTransformExtendedObject({
1679
+ extensionKeys: extension._getRawProperties(),
1680
+ value: raw,
1681
+ transformBase: (rawBase) => schema.parse(rawBase, opts),
1682
+ transformExtension: (rawExtension) => extension.parse(rawExtension, opts)
1683
+ });
1684
+ },
1685
+ json: (parsed, opts) => {
1686
+ return validateAndTransformExtendedObject({
1687
+ extensionKeys: extension._getParsedProperties(),
1688
+ value: parsed,
1689
+ transformBase: (parsedBase) => schema.json(parsedBase, opts),
1690
+ transformExtension: (parsedExtension) => extension.json(parsedExtension, opts)
1691
+ });
1692
+ },
1693
+ getType: () => SchemaType.OBJECT
1694
+ };
1695
+ return {
1696
+ ...baseSchema,
1697
+ ...getSchemaUtils(baseSchema),
1698
+ ...getObjectLikeUtils(baseSchema),
1699
+ ...getObjectUtils(baseSchema)
1700
+ };
1701
+ },
1702
+ passthrough: () => {
1703
+ const baseSchema = {
1704
+ _getParsedProperties: () => schema._getParsedProperties(),
1705
+ _getRawProperties: () => schema._getRawProperties(),
1706
+ parse: (raw, opts) => {
1707
+ const transformed = schema.parse(raw, { ...opts, unrecognizedObjectKeys: "passthrough" });
1708
+ if (!transformed.ok) {
1709
+ return transformed;
1710
+ }
1711
+ return {
1712
+ ok: true,
1713
+ value: {
1714
+ ...raw,
1715
+ ...transformed.value
1716
+ }
1717
+ };
1718
+ },
1719
+ json: (parsed, opts) => {
1720
+ const transformed = schema.json(parsed, { ...opts, unrecognizedObjectKeys: "passthrough" });
1721
+ if (!transformed.ok) {
1722
+ return transformed;
1723
+ }
1724
+ return {
1725
+ ok: true,
1726
+ value: {
1727
+ ...parsed,
1728
+ ...transformed.value
1729
+ }
1730
+ };
1731
+ },
1732
+ getType: () => SchemaType.OBJECT
1733
+ };
1734
+ return {
1735
+ ...baseSchema,
1736
+ ...getSchemaUtils(baseSchema),
1737
+ ...getObjectLikeUtils(baseSchema),
1738
+ ...getObjectUtils(baseSchema)
1739
+ };
1740
+ }
1741
+ };
1742
+ }
1743
+ function validateAndTransformExtendedObject({
1744
+ extensionKeys,
1745
+ value,
1746
+ transformBase,
1747
+ transformExtension
1748
+ }) {
1749
+ const extensionPropertiesSet = new Set(extensionKeys);
1750
+ const [extensionProperties, baseProperties] = partition(
1751
+ keys(value),
1752
+ (key) => extensionPropertiesSet.has(key)
1753
+ );
1754
+ const transformedBase = transformBase(filterObject(value, baseProperties));
1755
+ const transformedExtension = transformExtension(filterObject(value, extensionProperties));
1756
+ if (transformedBase.ok && transformedExtension.ok) {
1757
+ return {
1758
+ ok: true,
1759
+ value: {
1760
+ ...transformedBase.value,
1761
+ ...transformedExtension.value
1762
+ }
1763
+ };
1764
+ } else {
1765
+ return {
1766
+ ok: false,
1767
+ errors: [
1768
+ ...transformedBase.ok ? [] : transformedBase.errors,
1769
+ ...transformedExtension.ok ? [] : transformedExtension.errors
1770
+ ]
1771
+ };
1772
+ }
1773
+ }
1774
+ function isSchemaRequired(schema) {
1775
+ return !isSchemaOptional(schema);
1776
+ }
1777
+ function isSchemaOptional(schema) {
1778
+ switch (schema.getType()) {
1779
+ case SchemaType.ANY:
1780
+ case SchemaType.UNKNOWN:
1781
+ case SchemaType.OPTIONAL:
1782
+ case SchemaType.OPTIONAL_NULLABLE:
1783
+ return true;
1784
+ default:
1785
+ return false;
1786
+ }
1787
+ }
1788
+
1789
+ // src/core/schemas/builders/object/objectWithoutOptionalProperties.ts
1790
+ function objectWithoutOptionalProperties(schemas) {
1791
+ return object(schemas);
1792
+ }
1793
+
1794
+ // src/core/schemas/builders/lazy/lazyObject.ts
1795
+ function lazyObject(getter) {
1796
+ const baseSchema = {
1797
+ ...constructLazyBaseSchema(getter),
1798
+ _getRawProperties: () => getMemoizedSchema(getter)._getRawProperties(),
1799
+ _getParsedProperties: () => getMemoizedSchema(getter)._getParsedProperties()
1800
+ };
1801
+ return {
1802
+ ...baseSchema,
1803
+ ...getSchemaUtils(baseSchema),
1804
+ ...getObjectLikeUtils(baseSchema),
1805
+ ...getObjectUtils(baseSchema)
1806
+ };
1807
+ }
1808
+
1809
+ // src/core/schemas/builders/list/list.ts
1810
+ function list(schema) {
1811
+ const baseSchema = {
1812
+ parse: (raw, opts) => validateAndTransformArray(
1813
+ raw,
1814
+ (item, index) => schema.parse(item, {
1815
+ ...opts,
1816
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], `[${index}]`]
1817
+ })
1818
+ ),
1819
+ json: (parsed, opts) => validateAndTransformArray(
1820
+ parsed,
1821
+ (item, index) => schema.json(item, {
1822
+ ...opts,
1823
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], `[${index}]`]
1824
+ })
1825
+ ),
1826
+ getType: () => SchemaType.LIST
1827
+ };
1828
+ return {
1829
+ ...maybeSkipValidation(baseSchema),
1830
+ ...getSchemaUtils(baseSchema)
1831
+ };
1832
+ }
1833
+ function validateAndTransformArray(value, transformItem) {
1834
+ if (!Array.isArray(value)) {
1835
+ return {
1836
+ ok: false,
1837
+ errors: [
1838
+ {
1839
+ message: getErrorMessageForIncorrectType(value, "list"),
1840
+ path: []
1841
+ }
1842
+ ]
1843
+ };
1844
+ }
1845
+ const maybeValidItems = value.map((item, index) => transformItem(item, index));
1846
+ return maybeValidItems.reduce(
1847
+ (acc, item) => {
1848
+ if (acc.ok && item.ok) {
1849
+ return {
1850
+ ok: true,
1851
+ value: [...acc.value, item.value]
1852
+ };
1853
+ }
1854
+ const errors = [];
1855
+ if (!acc.ok) {
1856
+ errors.push(...acc.errors);
1857
+ }
1858
+ if (!item.ok) {
1859
+ errors.push(...item.errors);
1860
+ }
1861
+ return {
1862
+ ok: false,
1863
+ errors
1864
+ };
1865
+ },
1866
+ { ok: true, value: [] }
1867
+ );
1868
+ }
1869
+
1870
+ // src/core/schemas/builders/literals/stringLiteral.ts
1871
+ function stringLiteral(literal) {
1872
+ const schemaCreator = createIdentitySchemaCreator(
1873
+ SchemaType.STRING_LITERAL,
1874
+ (value, { breadcrumbsPrefix = [] } = {}) => {
1875
+ if (value === literal) {
1876
+ return {
1877
+ ok: true,
1878
+ value: literal
1879
+ };
1880
+ } else {
1881
+ return {
1882
+ ok: false,
1883
+ errors: [
1884
+ {
1885
+ path: breadcrumbsPrefix,
1886
+ message: getErrorMessageForIncorrectType(value, `"${literal}"`)
1887
+ }
1888
+ ]
1889
+ };
1890
+ }
1891
+ }
1892
+ );
1893
+ return schemaCreator();
1894
+ }
1895
+
1896
+ // src/core/schemas/builders/literals/booleanLiteral.ts
1897
+ function booleanLiteral(literal) {
1898
+ const schemaCreator = createIdentitySchemaCreator(
1899
+ SchemaType.BOOLEAN_LITERAL,
1900
+ (value, { breadcrumbsPrefix = [] } = {}) => {
1901
+ if (value === literal) {
1902
+ return {
1903
+ ok: true,
1904
+ value: literal
1905
+ };
1906
+ } else {
1907
+ return {
1908
+ ok: false,
1909
+ errors: [
1910
+ {
1911
+ path: breadcrumbsPrefix,
1912
+ message: getErrorMessageForIncorrectType(value, `${literal.toString()}`)
1913
+ }
1914
+ ]
1915
+ };
1916
+ }
1917
+ }
1918
+ );
1919
+ return schemaCreator();
1920
+ }
1921
+
1922
+ // src/core/schemas/builders/primitives/any.ts
1923
+ var any = createIdentitySchemaCreator(SchemaType.ANY, (value) => ({ ok: true, value }));
1924
+
1925
+ // src/core/schemas/builders/primitives/boolean.ts
1926
+ var boolean = createIdentitySchemaCreator(
1927
+ SchemaType.BOOLEAN,
1928
+ (value, { breadcrumbsPrefix = [] } = {}) => {
1929
+ if (typeof value === "boolean") {
1930
+ return {
1931
+ ok: true,
1932
+ value
1933
+ };
1934
+ } else {
1935
+ return {
1936
+ ok: false,
1937
+ errors: [
1938
+ {
1939
+ path: breadcrumbsPrefix,
1940
+ message: getErrorMessageForIncorrectType(value, "boolean")
1941
+ }
1942
+ ]
1943
+ };
1944
+ }
1945
+ }
1946
+ );
1947
+
1948
+ // src/core/schemas/builders/primitives/number.ts
1949
+ var number = createIdentitySchemaCreator(
1950
+ SchemaType.NUMBER,
1951
+ (value, { breadcrumbsPrefix = [] } = {}) => {
1952
+ if (typeof value === "number") {
1953
+ return {
1954
+ ok: true,
1955
+ value
1956
+ };
1957
+ } else {
1958
+ return {
1959
+ ok: false,
1960
+ errors: [
1961
+ {
1962
+ path: breadcrumbsPrefix,
1963
+ message: getErrorMessageForIncorrectType(value, "number")
1964
+ }
1965
+ ]
1966
+ };
1967
+ }
1968
+ }
1969
+ );
1970
+
1971
+ // src/core/schemas/builders/primitives/string.ts
1972
+ var string = createIdentitySchemaCreator(
1973
+ SchemaType.STRING,
1974
+ (value, { breadcrumbsPrefix = [] } = {}) => {
1975
+ if (typeof value === "string") {
1976
+ return {
1977
+ ok: true,
1978
+ value
1979
+ };
1980
+ } else {
1981
+ return {
1982
+ ok: false,
1983
+ errors: [
1984
+ {
1985
+ path: breadcrumbsPrefix,
1986
+ message: getErrorMessageForIncorrectType(value, "string")
1987
+ }
1988
+ ]
1989
+ };
1990
+ }
1991
+ }
1992
+ );
1993
+
1994
+ // src/core/schemas/builders/primitives/unknown.ts
1995
+ var unknown = createIdentitySchemaCreator(SchemaType.UNKNOWN, (value) => ({ ok: true, value }));
1996
+
1997
+ // src/core/schemas/builders/record/record.ts
1998
+ function record(keySchema, valueSchema) {
1999
+ const baseSchema = {
2000
+ parse: (raw, opts) => {
2001
+ return validateAndTransformRecord({
2002
+ value: raw,
2003
+ isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
2004
+ transformKey: (key) => keySchema.parse(key, {
2005
+ ...opts,
2006
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], `${key} (key)`]
2007
+ }),
2008
+ transformValue: (value, key) => valueSchema.parse(value, {
2009
+ ...opts,
2010
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], `${key}`]
2011
+ }),
2012
+ breadcrumbsPrefix: opts == null ? void 0 : opts.breadcrumbsPrefix
2013
+ });
2014
+ },
2015
+ json: (parsed, opts) => {
2016
+ return validateAndTransformRecord({
2017
+ value: parsed,
2018
+ isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
2019
+ transformKey: (key) => keySchema.json(key, {
2020
+ ...opts,
2021
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], `${key} (key)`]
2022
+ }),
2023
+ transformValue: (value, key) => valueSchema.json(value, {
2024
+ ...opts,
2025
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], `${key}`]
2026
+ }),
2027
+ breadcrumbsPrefix: opts == null ? void 0 : opts.breadcrumbsPrefix
2028
+ });
2029
+ },
2030
+ getType: () => SchemaType.RECORD
2031
+ };
2032
+ return {
2033
+ ...maybeSkipValidation(baseSchema),
2034
+ ...getSchemaUtils(baseSchema)
2035
+ };
2036
+ }
2037
+ function validateAndTransformRecord({
2038
+ value,
2039
+ isKeyNumeric,
2040
+ transformKey,
2041
+ transformValue,
2042
+ breadcrumbsPrefix = []
2043
+ }) {
2044
+ if (!isPlainObject(value)) {
2045
+ return {
2046
+ ok: false,
2047
+ errors: [
2048
+ {
2049
+ path: breadcrumbsPrefix,
2050
+ message: getErrorMessageForIncorrectType(value, "object")
2051
+ }
2052
+ ]
2053
+ };
2054
+ }
2055
+ return entries(value).reduce(
2056
+ (accPromise, [stringKey, value2]) => {
2057
+ if (value2 === void 0) {
2058
+ return accPromise;
2059
+ }
2060
+ const acc = accPromise;
2061
+ let key = stringKey;
2062
+ if (isKeyNumeric) {
2063
+ const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
2064
+ if (!isNaN(numberKey)) {
2065
+ key = numberKey;
2066
+ }
2067
+ }
2068
+ const transformedKey = transformKey(key);
2069
+ const transformedValue = transformValue(value2, key);
2070
+ if (acc.ok && transformedKey.ok && transformedValue.ok) {
2071
+ return {
2072
+ ok: true,
2073
+ value: {
2074
+ ...acc.value,
2075
+ [transformedKey.value]: transformedValue.value
2076
+ }
2077
+ };
2078
+ }
2079
+ const errors = [];
2080
+ if (!acc.ok) {
2081
+ errors.push(...acc.errors);
2082
+ }
2083
+ if (!transformedKey.ok) {
2084
+ errors.push(...transformedKey.errors);
2085
+ }
2086
+ if (!transformedValue.ok) {
2087
+ errors.push(...transformedValue.errors);
2088
+ }
2089
+ return {
2090
+ ok: false,
2091
+ errors
2092
+ };
2093
+ },
2094
+ { ok: true, value: {} }
2095
+ );
2096
+ }
2097
+
2098
+ // src/core/schemas/builders/set/set.ts
2099
+ function set(schema) {
2100
+ const listSchema = list(schema);
2101
+ const baseSchema = {
2102
+ parse: (raw, opts) => {
2103
+ const parsedList = listSchema.parse(raw, opts);
2104
+ if (parsedList.ok) {
2105
+ return {
2106
+ ok: true,
2107
+ value: new Set(parsedList.value)
2108
+ };
2109
+ } else {
2110
+ return parsedList;
2111
+ }
2112
+ },
2113
+ json: (parsed, opts) => {
2114
+ if (!(parsed instanceof Set)) {
2115
+ return {
2116
+ ok: false,
2117
+ errors: [
2118
+ {
2119
+ path: (opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [],
2120
+ message: getErrorMessageForIncorrectType(parsed, "Set")
2121
+ }
2122
+ ]
2123
+ };
2124
+ }
2125
+ const jsonList = listSchema.json([...parsed], opts);
2126
+ return jsonList;
2127
+ },
2128
+ getType: () => SchemaType.SET
2129
+ };
2130
+ return {
2131
+ ...maybeSkipValidation(baseSchema),
2132
+ ...getSchemaUtils(baseSchema)
2133
+ };
2134
+ }
2135
+
2136
+ // src/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts
2137
+ function undiscriminatedUnion(schemas) {
2138
+ const baseSchema = {
2139
+ parse: (raw, opts) => {
2140
+ return validateAndTransformUndiscriminatedUnion(
2141
+ (schema, opts2) => schema.parse(raw, opts2),
2142
+ schemas,
2143
+ opts
2144
+ );
2145
+ },
2146
+ json: (parsed, opts) => {
2147
+ return validateAndTransformUndiscriminatedUnion(
2148
+ (schema, opts2) => schema.json(parsed, opts2),
2149
+ schemas,
2150
+ opts
2151
+ );
2152
+ },
2153
+ getType: () => SchemaType.UNDISCRIMINATED_UNION
2154
+ };
2155
+ return {
2156
+ ...maybeSkipValidation(baseSchema),
2157
+ ...getSchemaUtils(baseSchema)
2158
+ };
2159
+ }
2160
+ function validateAndTransformUndiscriminatedUnion(transform2, schemas, opts) {
2161
+ const errors = [];
2162
+ for (const [index, schema] of schemas.entries()) {
2163
+ const transformed = transform2(schema, { ...opts, skipValidation: false });
2164
+ if (transformed.ok) {
2165
+ return transformed;
2166
+ } else {
2167
+ for (const error of transformed.errors) {
2168
+ errors.push({
2169
+ path: error.path,
2170
+ message: `[Variant ${index}] ${error.message}`
2171
+ });
2172
+ }
2173
+ }
2174
+ }
2175
+ return {
2176
+ ok: false,
2177
+ errors
2178
+ };
2179
+ }
2180
+
2181
+ // src/core/schemas/builders/union/discriminant.ts
2182
+ function discriminant(parsedDiscriminant, rawDiscriminant) {
2183
+ return {
2184
+ parsedDiscriminant,
2185
+ rawDiscriminant
2186
+ };
2187
+ }
2188
+
2189
+ // src/core/schemas/builders/union/union.ts
2190
+ function union(discriminant2, union2) {
2191
+ const rawDiscriminant = typeof discriminant2 === "string" ? discriminant2 : discriminant2.rawDiscriminant;
2192
+ const parsedDiscriminant = typeof discriminant2 === "string" ? discriminant2 : discriminant2.parsedDiscriminant;
2193
+ const discriminantValueSchema = enum_(keys(union2));
2194
+ const baseSchema = {
2195
+ parse: (raw, opts) => {
2196
+ return transformAndValidateUnion({
2197
+ value: raw,
2198
+ discriminant: rawDiscriminant,
2199
+ transformedDiscriminant: parsedDiscriminant,
2200
+ transformDiscriminantValue: (discriminantValue) => discriminantValueSchema.parse(discriminantValue, {
2201
+ allowUnrecognizedEnumValues: opts == null ? void 0 : opts.allowUnrecognizedUnionMembers,
2202
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], rawDiscriminant]
2203
+ }),
2204
+ getAdditionalPropertiesSchema: (discriminantValue) => union2[discriminantValue],
2205
+ allowUnrecognizedUnionMembers: opts == null ? void 0 : opts.allowUnrecognizedUnionMembers,
2206
+ transformAdditionalProperties: (additionalProperties, additionalPropertiesSchema) => additionalPropertiesSchema.parse(additionalProperties, opts),
2207
+ breadcrumbsPrefix: opts == null ? void 0 : opts.breadcrumbsPrefix
2208
+ });
2209
+ },
2210
+ json: (parsed, opts) => {
2211
+ return transformAndValidateUnion({
2212
+ value: parsed,
2213
+ discriminant: parsedDiscriminant,
2214
+ transformedDiscriminant: rawDiscriminant,
2215
+ transformDiscriminantValue: (discriminantValue) => discriminantValueSchema.json(discriminantValue, {
2216
+ allowUnrecognizedEnumValues: opts == null ? void 0 : opts.allowUnrecognizedUnionMembers,
2217
+ breadcrumbsPrefix: [...(opts == null ? void 0 : opts.breadcrumbsPrefix) ?? [], parsedDiscriminant]
2218
+ }),
2219
+ getAdditionalPropertiesSchema: (discriminantValue) => union2[discriminantValue],
2220
+ allowUnrecognizedUnionMembers: opts == null ? void 0 : opts.allowUnrecognizedUnionMembers,
2221
+ transformAdditionalProperties: (additionalProperties, additionalPropertiesSchema) => additionalPropertiesSchema.json(additionalProperties, opts),
2222
+ breadcrumbsPrefix: opts == null ? void 0 : opts.breadcrumbsPrefix
2223
+ });
2224
+ },
2225
+ getType: () => SchemaType.UNION
2226
+ };
2227
+ return {
2228
+ ...maybeSkipValidation(baseSchema),
2229
+ ...getSchemaUtils(baseSchema),
2230
+ ...getObjectLikeUtils(baseSchema)
2231
+ };
2232
+ }
2233
+ function transformAndValidateUnion({
2234
+ value,
2235
+ discriminant: discriminant2,
2236
+ transformedDiscriminant,
2237
+ transformDiscriminantValue,
2238
+ getAdditionalPropertiesSchema,
2239
+ allowUnrecognizedUnionMembers = false,
2240
+ transformAdditionalProperties,
2241
+ breadcrumbsPrefix = []
2242
+ }) {
2243
+ if (!isPlainObject(value)) {
2244
+ return {
2245
+ ok: false,
2246
+ errors: [
2247
+ {
2248
+ path: breadcrumbsPrefix,
2249
+ message: getErrorMessageForIncorrectType(value, "object")
2250
+ }
2251
+ ]
2252
+ };
2253
+ }
2254
+ const { [discriminant2]: discriminantValue, ...additionalProperties } = value;
2255
+ if (discriminantValue == null) {
2256
+ return {
2257
+ ok: false,
2258
+ errors: [
2259
+ {
2260
+ path: breadcrumbsPrefix,
2261
+ message: `Missing discriminant ("${discriminant2}")`
2262
+ }
2263
+ ]
2264
+ };
2265
+ }
2266
+ const transformedDiscriminantValue = transformDiscriminantValue(discriminantValue);
2267
+ if (!transformedDiscriminantValue.ok) {
2268
+ return {
2269
+ ok: false,
2270
+ errors: transformedDiscriminantValue.errors
2271
+ };
2272
+ }
2273
+ const additionalPropertiesSchema = getAdditionalPropertiesSchema(transformedDiscriminantValue.value);
2274
+ if (additionalPropertiesSchema == null) {
2275
+ if (allowUnrecognizedUnionMembers) {
2276
+ return {
2277
+ ok: true,
2278
+ value: {
2279
+ [transformedDiscriminant]: transformedDiscriminantValue.value,
2280
+ ...additionalProperties
2281
+ }
2282
+ };
2283
+ } else {
2284
+ return {
2285
+ ok: false,
2286
+ errors: [
2287
+ {
2288
+ path: [...breadcrumbsPrefix, discriminant2],
2289
+ message: "Unexpected discriminant value"
2290
+ }
2291
+ ]
2292
+ };
2293
+ }
2294
+ }
2295
+ const transformedAdditionalProperties = transformAdditionalProperties(
2296
+ additionalProperties,
2297
+ additionalPropertiesSchema
2298
+ );
2299
+ if (!transformedAdditionalProperties.ok) {
2300
+ return transformedAdditionalProperties;
2301
+ }
2302
+ return {
2303
+ ok: true,
2304
+ value: {
2305
+ [transformedDiscriminant]: discriminantValue,
2306
+ ...transformedAdditionalProperties.value
2307
+ }
2308
+ };
2309
+ }
2310
+
2311
+ // src/serialization/index.ts
2312
+ var serialization_exports = {};
2313
+ __export(serialization_exports, {
2314
+ Actor: () => Actor,
2315
+ ActorName: () => ActorName,
2316
+ ActorsCreateRequest: () => ActorsCreateRequest,
2317
+ ActorsCreateResponse: () => ActorsCreateResponse,
2318
+ ActorsDeleteResponse: () => ActorsDeleteResponse,
2319
+ ActorsGetOrCreateRequest: () => ActorsGetOrCreateRequest,
2320
+ ActorsGetOrCreateResponse: () => ActorsGetOrCreateResponse,
2321
+ ActorsKvGetResponse: () => ActorsKvGetResponse,
2322
+ ActorsListNamesResponse: () => ActorsListNamesResponse,
2323
+ ActorsListResponse: () => ActorsListResponse,
2324
+ CrashPolicy: () => CrashPolicy2,
2325
+ Datacenter: () => Datacenter,
2326
+ DatacenterHealth: () => DatacenterHealth,
2327
+ DatacentersListResponse: () => DatacentersListResponse,
2328
+ HealthFanoutResponse: () => HealthFanoutResponse,
2329
+ HealthResponse: () => HealthResponse,
2330
+ HealthStatus: () => HealthStatus2,
2331
+ MetadataGetResponse: () => MetadataGetResponse,
2332
+ Namespace: () => Namespace,
2333
+ NamespaceListResponse: () => NamespaceListResponse,
2334
+ NamespacesCreateRequest: () => NamespacesCreateRequest,
2335
+ NamespacesCreateResponse: () => NamespacesCreateResponse,
2336
+ Pagination: () => Pagination,
2337
+ RivetId: () => RivetId,
2338
+ Runner: () => Runner,
2339
+ RunnerConfig: () => RunnerConfig,
2340
+ RunnerConfigKind: () => RunnerConfigKind,
2341
+ RunnerConfigKindNormal: () => RunnerConfigKindNormal,
2342
+ RunnerConfigKindServerless: () => RunnerConfigKindServerless,
2343
+ RunnerConfigKindServerlessServerless: () => RunnerConfigKindServerlessServerless,
2344
+ RunnerConfigResponse: () => RunnerConfigResponse,
2345
+ RunnerConfigServerless: () => RunnerConfigServerless,
2346
+ RunnerConfigVariant: () => RunnerConfigVariant2,
2347
+ RunnerConfigsDeleteResponse: () => RunnerConfigsDeleteResponse,
2348
+ RunnerConfigsListResponse: () => RunnerConfigsListResponse,
2349
+ RunnerConfigsListResponseRunnerConfigsValue: () => RunnerConfigsListResponseRunnerConfigsValue,
2350
+ RunnerConfigsRefreshMetadataRequestBody: () => RunnerConfigsRefreshMetadataRequestBody,
2351
+ RunnerConfigsRefreshMetadataResponse: () => RunnerConfigsRefreshMetadataResponse,
2352
+ RunnerConfigsServerlessHealthCheckRequest: () => RunnerConfigsServerlessHealthCheckRequest,
2353
+ RunnerConfigsServerlessHealthCheckResponse: () => RunnerConfigsServerlessHealthCheckResponse,
2354
+ RunnerConfigsServerlessHealthCheckResponseFailure: () => RunnerConfigsServerlessHealthCheckResponseFailure,
2355
+ RunnerConfigsServerlessHealthCheckResponseFailureFailure: () => RunnerConfigsServerlessHealthCheckResponseFailureFailure,
2356
+ RunnerConfigsServerlessHealthCheckResponseSuccess: () => RunnerConfigsServerlessHealthCheckResponseSuccess,
2357
+ RunnerConfigsServerlessHealthCheckResponseSuccessSuccess: () => RunnerConfigsServerlessHealthCheckResponseSuccessSuccess,
2358
+ RunnerConfigsServerlessMetadataError: () => RunnerConfigsServerlessMetadataError,
2359
+ RunnerConfigsServerlessMetadataErrorInvalidRequest: () => RunnerConfigsServerlessMetadataErrorInvalidRequest,
2360
+ RunnerConfigsServerlessMetadataErrorInvalidResponseJson: () => RunnerConfigsServerlessMetadataErrorInvalidResponseJson,
2361
+ RunnerConfigsServerlessMetadataErrorInvalidResponseJsonInvalidResponseJson: () => RunnerConfigsServerlessMetadataErrorInvalidResponseJsonInvalidResponseJson,
2362
+ RunnerConfigsServerlessMetadataErrorInvalidResponseSchema: () => RunnerConfigsServerlessMetadataErrorInvalidResponseSchema,
2363
+ RunnerConfigsServerlessMetadataErrorInvalidResponseSchemaInvalidResponseSchema: () => RunnerConfigsServerlessMetadataErrorInvalidResponseSchemaInvalidResponseSchema,
2364
+ RunnerConfigsServerlessMetadataErrorNonSuccessStatus: () => RunnerConfigsServerlessMetadataErrorNonSuccessStatus,
2365
+ RunnerConfigsServerlessMetadataErrorNonSuccessStatusNonSuccessStatus: () => RunnerConfigsServerlessMetadataErrorNonSuccessStatusNonSuccessStatus,
2366
+ RunnerConfigsServerlessMetadataErrorRequestFailed: () => RunnerConfigsServerlessMetadataErrorRequestFailed,
2367
+ RunnerConfigsServerlessMetadataErrorRequestTimedOut: () => RunnerConfigsServerlessMetadataErrorRequestTimedOut,
2368
+ RunnerConfigsUpsertRequestBody: () => RunnerConfigsUpsertRequestBody,
2369
+ RunnerConfigsUpsertResponse: () => RunnerConfigsUpsertResponse,
2370
+ RunnersListNamesResponse: () => RunnersListNamesResponse,
2371
+ RunnersListResponse: () => RunnersListResponse,
2372
+ namespaces: () => namespaces_exports2
2373
+ });
2374
+
2375
+ // src/serialization/types/RivetId.ts
2376
+ var RivetId = schemas_exports.string();
2377
+
2378
+ // src/serialization/types/CrashPolicy.ts
2379
+ var CrashPolicy2 = schemas_exports.enum_(["restart", "sleep", "destroy"]);
2380
+
2381
+ // src/serialization/types/Actor.ts
2382
+ var Actor = schemas_exports.object({
2383
+ actorId: schemas_exports.property("actor_id", RivetId),
2384
+ connectableTs: schemas_exports.property("connectable_ts", schemas_exports.number().optional()),
2385
+ crashPolicy: schemas_exports.property("crash_policy", CrashPolicy2),
2386
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2387
+ datacenter: schemas_exports.string(),
2388
+ destroyTs: schemas_exports.property("destroy_ts", schemas_exports.number().optional()),
2389
+ error: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional(),
2390
+ key: schemas_exports.string().optional(),
2391
+ name: schemas_exports.string(),
2392
+ namespaceId: schemas_exports.property("namespace_id", RivetId),
2393
+ pendingAllocationTs: schemas_exports.property("pending_allocation_ts", schemas_exports.number().optional()),
2394
+ rescheduleTs: schemas_exports.property("reschedule_ts", schemas_exports.number().optional()),
2395
+ runnerNameSelector: schemas_exports.property("runner_name_selector", schemas_exports.string()),
2396
+ sleepTs: schemas_exports.property("sleep_ts", schemas_exports.number().optional()),
2397
+ startTs: schemas_exports.property("start_ts", schemas_exports.number().optional())
2398
+ });
2399
+
2400
+ // src/serialization/types/ActorName.ts
2401
+ var ActorName = schemas_exports.object({
2402
+ metadata: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown())
2403
+ });
2404
+
2405
+ // src/serialization/types/ActorsCreateResponse.ts
2406
+ var ActorsCreateResponse = schemas_exports.object({
2407
+ actor: Actor
2408
+ });
2409
+
2410
+ // src/serialization/types/ActorsDeleteResponse.ts
2411
+ var ActorsDeleteResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2412
+
2413
+ // src/serialization/types/ActorsGetOrCreateResponse.ts
2414
+ var ActorsGetOrCreateResponse = schemas_exports.object({
2415
+ actor: Actor,
2416
+ created: schemas_exports.boolean()
2417
+ });
2418
+
2419
+ // src/serialization/types/ActorsKvGetResponse.ts
2420
+ var ActorsKvGetResponse = schemas_exports.object({
2421
+ updateTs: schemas_exports.property("update_ts", schemas_exports.number()),
2422
+ value: schemas_exports.string()
2423
+ });
2424
+
2425
+ // src/serialization/types/Pagination.ts
2426
+ var Pagination = schemas_exports.object({
2427
+ cursor: schemas_exports.string().optional()
2428
+ });
2429
+
2430
+ // src/serialization/types/ActorsListNamesResponse.ts
2431
+ var ActorsListNamesResponse = schemas_exports.object({
2432
+ names: schemas_exports.record(schemas_exports.string(), ActorName),
2433
+ pagination: Pagination
2434
+ });
2435
+
2436
+ // src/serialization/types/ActorsListResponse.ts
2437
+ var ActorsListResponse = schemas_exports.object({
2438
+ actors: schemas_exports.list(Actor),
2439
+ pagination: Pagination
2440
+ });
2441
+
2442
+ // src/serialization/types/Datacenter.ts
2443
+ var Datacenter = schemas_exports.object({
2444
+ label: schemas_exports.number(),
2445
+ name: schemas_exports.string(),
2446
+ url: schemas_exports.string()
2447
+ });
2448
+
2449
+ // src/serialization/types/HealthResponse.ts
2450
+ var HealthResponse = schemas_exports.object({
2451
+ runtime: schemas_exports.string(),
2452
+ status: schemas_exports.string(),
2453
+ version: schemas_exports.string()
2454
+ });
2455
+
2456
+ // src/serialization/types/HealthStatus.ts
2457
+ var HealthStatus2 = schemas_exports.enum_(["ok", "error"]);
2458
+
2459
+ // src/serialization/types/DatacenterHealth.ts
2460
+ var DatacenterHealth = schemas_exports.object({
2461
+ datacenterLabel: schemas_exports.property("datacenter_label", schemas_exports.number()),
2462
+ datacenterName: schemas_exports.property("datacenter_name", schemas_exports.string()),
2463
+ error: schemas_exports.string().optional(),
2464
+ response: HealthResponse.optional(),
2465
+ rttMs: schemas_exports.property("rtt_ms", schemas_exports.number().optional()),
2466
+ status: HealthStatus2
2467
+ });
2468
+
2469
+ // src/serialization/types/DatacentersListResponse.ts
2470
+ var DatacentersListResponse = schemas_exports.object({
2471
+ datacenters: schemas_exports.list(Datacenter),
2472
+ pagination: Pagination
2473
+ });
2474
+
2475
+ // src/serialization/types/HealthFanoutResponse.ts
2476
+ var HealthFanoutResponse = schemas_exports.object({
2477
+ datacenters: schemas_exports.list(DatacenterHealth)
2478
+ });
2479
+
2480
+ // src/serialization/types/MetadataGetResponse.ts
2481
+ var MetadataGetResponse = schemas_exports.object({
2482
+ buildTimestamp: schemas_exports.property("build_timestamp", schemas_exports.string()),
2483
+ cargoProfile: schemas_exports.property("cargo_profile", schemas_exports.string()),
2484
+ cargoTarget: schemas_exports.property("cargo_target", schemas_exports.string()),
2485
+ gitSha: schemas_exports.property("git_sha", schemas_exports.string()),
2486
+ runtime: schemas_exports.string(),
2487
+ rustcHost: schemas_exports.property("rustc_host", schemas_exports.string()),
2488
+ rustcVersion: schemas_exports.property("rustc_version", schemas_exports.string()),
2489
+ version: schemas_exports.string()
2490
+ });
2491
+
2492
+ // src/serialization/types/Namespace.ts
2493
+ var Namespace = schemas_exports.object({
2494
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2495
+ displayName: schemas_exports.property("display_name", schemas_exports.string()),
2496
+ name: schemas_exports.string(),
2497
+ namespaceId: schemas_exports.property("namespace_id", RivetId)
2498
+ });
2499
+
2500
+ // src/serialization/types/NamespaceListResponse.ts
2501
+ var NamespaceListResponse = schemas_exports.object({
2502
+ namespaces: schemas_exports.list(Namespace),
2503
+ pagination: Pagination
2504
+ });
2505
+
2506
+ // src/serialization/types/NamespacesCreateResponse.ts
2507
+ var NamespacesCreateResponse = schemas_exports.object({
2508
+ namespace: Namespace
2509
+ });
2510
+
2511
+ // src/serialization/types/Runner.ts
2512
+ var Runner = schemas_exports.object({
2513
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2514
+ datacenter: schemas_exports.string(),
2515
+ drainTs: schemas_exports.property("drain_ts", schemas_exports.number().optional()),
2516
+ key: schemas_exports.string(),
2517
+ lastConnectedTs: schemas_exports.property("last_connected_ts", schemas_exports.number().optional()),
2518
+ lastPingTs: schemas_exports.property("last_ping_ts", schemas_exports.number()),
2519
+ lastRtt: schemas_exports.property("last_rtt", schemas_exports.number()),
2520
+ metadata: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional(),
2521
+ name: schemas_exports.string(),
2522
+ namespaceId: schemas_exports.property("namespace_id", RivetId),
2523
+ remainingSlots: schemas_exports.property("remaining_slots", schemas_exports.number()),
2524
+ runnerId: schemas_exports.property("runner_id", RivetId),
2525
+ stopTs: schemas_exports.property("stop_ts", schemas_exports.number().optional()),
2526
+ totalSlots: schemas_exports.property("total_slots", schemas_exports.number()),
2527
+ version: schemas_exports.number()
2528
+ });
2529
+
2530
+ // src/serialization/types/RunnerConfigServerless.ts
2531
+ var RunnerConfigServerless = schemas_exports.object({
2532
+ headers: schemas_exports.record(schemas_exports.string(), schemas_exports.string()).optional(),
2533
+ maxRunners: schemas_exports.property("max_runners", schemas_exports.number()),
2534
+ minRunners: schemas_exports.property("min_runners", schemas_exports.number().optional()),
2535
+ requestLifespan: schemas_exports.property("request_lifespan", schemas_exports.number()),
2536
+ runnersMargin: schemas_exports.property("runners_margin", schemas_exports.number().optional()),
2537
+ slotsPerRunner: schemas_exports.property("slots_per_runner", schemas_exports.number()),
2538
+ url: schemas_exports.string()
2539
+ });
2540
+
2541
+ // src/serialization/types/RunnerConfig.ts
2542
+ var RunnerConfig = schemas_exports.object({
2543
+ normal: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional(),
2544
+ serverless: RunnerConfigServerless.optional(),
2545
+ drainOnVersionUpgrade: schemas_exports.property(
2546
+ "drain_on_version_upgrade",
2547
+ schemas_exports.boolean().optional()
2548
+ ),
2549
+ metadata: schemas_exports.unknown().optional()
2550
+ });
2551
+
2552
+ // src/serialization/types/RunnerConfigKindNormal.ts
2553
+ var RunnerConfigKindNormal = schemas_exports.object({
2554
+ normal: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown())
2555
+ });
2556
+
2557
+ // src/serialization/types/RunnerConfigKindServerlessServerless.ts
2558
+ var RunnerConfigKindServerlessServerless = schemas_exports.object({
2559
+ headers: schemas_exports.record(schemas_exports.string(), schemas_exports.string()).optional(),
2560
+ maxRunners: schemas_exports.property("max_runners", schemas_exports.number()),
2561
+ minRunners: schemas_exports.property("min_runners", schemas_exports.number().optional()),
2562
+ requestLifespan: schemas_exports.property("request_lifespan", schemas_exports.number()),
2563
+ runnersMargin: schemas_exports.property("runners_margin", schemas_exports.number().optional()),
2564
+ slotsPerRunner: schemas_exports.property("slots_per_runner", schemas_exports.number()),
2565
+ url: schemas_exports.string()
2566
+ });
2567
+
2568
+ // src/serialization/types/RunnerConfigKindServerless.ts
2569
+ var RunnerConfigKindServerless = schemas_exports.object({
2570
+ serverless: RunnerConfigKindServerlessServerless
2571
+ });
2572
+
2573
+ // src/serialization/types/RunnerConfigKind.ts
2574
+ var RunnerConfigKind = schemas_exports.undiscriminatedUnion([RunnerConfigKindNormal, RunnerConfigKindServerless]);
2575
+
2576
+ // src/serialization/types/RunnerConfigResponse.ts
2577
+ var RunnerConfigResponse = schemas_exports.object({
2578
+ runnerPoolError: schemas_exports.property(
2579
+ "runner_pool_error",
2580
+ schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional()
2581
+ )
2582
+ }).extend(RunnerConfig);
2583
+
2584
+ // src/serialization/types/RunnerConfigVariant.ts
2585
+ var RunnerConfigVariant2 = schemas_exports.enum_(["serverless", "normal"]);
2586
+
2587
+ // src/serialization/types/RunnerConfigsDeleteResponse.ts
2588
+ var RunnerConfigsDeleteResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2589
+
2590
+ // src/serialization/types/RunnerConfigsListResponseRunnerConfigsValue.ts
2591
+ var RunnerConfigsListResponseRunnerConfigsValue = schemas_exports.object({
2592
+ datacenters: schemas_exports.record(schemas_exports.string(), RunnerConfigResponse)
2593
+ });
2594
+
2595
+ // src/serialization/types/RunnerConfigsListResponse.ts
2596
+ var RunnerConfigsListResponse = schemas_exports.object({
2597
+ pagination: Pagination,
2598
+ runnerConfigs: schemas_exports.property(
2599
+ "runner_configs",
2600
+ schemas_exports.record(schemas_exports.string(), RunnerConfigsListResponseRunnerConfigsValue)
2601
+ )
2602
+ });
2603
+
2604
+ // src/serialization/types/RunnerConfigsRefreshMetadataRequestBody.ts
2605
+ var RunnerConfigsRefreshMetadataRequestBody = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2606
+
2607
+ // src/serialization/types/RunnerConfigsRefreshMetadataResponse.ts
2608
+ var RunnerConfigsRefreshMetadataResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2609
+
2610
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseSuccessSuccess.ts
2611
+ var RunnerConfigsServerlessHealthCheckResponseSuccessSuccess = schemas_exports.object({
2612
+ version: schemas_exports.string()
2613
+ });
2614
+
2615
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseSuccess.ts
2616
+ var RunnerConfigsServerlessHealthCheckResponseSuccess = schemas_exports.object({
2617
+ success: RunnerConfigsServerlessHealthCheckResponseSuccessSuccess
2618
+ });
2619
+
2620
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorInvalidRequest.ts
2621
+ var RunnerConfigsServerlessMetadataErrorInvalidRequest = schemas_exports.object({
2622
+ invalidRequest: schemas_exports.property(
2623
+ "invalid_request",
2624
+ schemas_exports.record(schemas_exports.string(), schemas_exports.unknown())
2625
+ )
2626
+ });
2627
+
2628
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorRequestFailed.ts
2629
+ var RunnerConfigsServerlessMetadataErrorRequestFailed = schemas_exports.object({
2630
+ requestFailed: schemas_exports.property(
2631
+ "request_failed",
2632
+ schemas_exports.record(schemas_exports.string(), schemas_exports.unknown())
2633
+ )
2634
+ });
2635
+
2636
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorRequestTimedOut.ts
2637
+ var RunnerConfigsServerlessMetadataErrorRequestTimedOut = schemas_exports.object({
2638
+ requestTimedOut: schemas_exports.property(
2639
+ "request_timed_out",
2640
+ schemas_exports.record(schemas_exports.string(), schemas_exports.unknown())
2641
+ )
2642
+ });
2643
+
2644
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorNonSuccessStatusNonSuccessStatus.ts
2645
+ var RunnerConfigsServerlessMetadataErrorNonSuccessStatusNonSuccessStatus = schemas_exports.object({
2646
+ body: schemas_exports.string(),
2647
+ statusCode: schemas_exports.property("status_code", schemas_exports.number())
2648
+ });
2649
+
2650
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorNonSuccessStatus.ts
2651
+ var RunnerConfigsServerlessMetadataErrorNonSuccessStatus = schemas_exports.object({
2652
+ nonSuccessStatus: schemas_exports.property(
2653
+ "non_success_status",
2654
+ RunnerConfigsServerlessMetadataErrorNonSuccessStatusNonSuccessStatus
2655
+ )
2656
+ });
2657
+
2658
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorInvalidResponseJsonInvalidResponseJson.ts
2659
+ var RunnerConfigsServerlessMetadataErrorInvalidResponseJsonInvalidResponseJson = schemas_exports.object({
2660
+ body: schemas_exports.string()
2661
+ });
2662
+
2663
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorInvalidResponseJson.ts
2664
+ var RunnerConfigsServerlessMetadataErrorInvalidResponseJson = schemas_exports.object({
2665
+ invalidResponseJson: schemas_exports.property(
2666
+ "invalid_response_json",
2667
+ RunnerConfigsServerlessMetadataErrorInvalidResponseJsonInvalidResponseJson
2668
+ )
2669
+ });
2670
+
2671
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorInvalidResponseSchemaInvalidResponseSchema.ts
2672
+ var RunnerConfigsServerlessMetadataErrorInvalidResponseSchemaInvalidResponseSchema = schemas_exports.object({
2673
+ runtime: schemas_exports.string(),
2674
+ version: schemas_exports.string()
2675
+ });
2676
+
2677
+ // src/serialization/types/RunnerConfigsServerlessMetadataErrorInvalidResponseSchema.ts
2678
+ var RunnerConfigsServerlessMetadataErrorInvalidResponseSchema = schemas_exports.object({
2679
+ invalidResponseSchema: schemas_exports.property(
2680
+ "invalid_response_schema",
2681
+ RunnerConfigsServerlessMetadataErrorInvalidResponseSchemaInvalidResponseSchema
2682
+ )
2683
+ });
2684
+
2685
+ // src/serialization/types/RunnerConfigsServerlessMetadataError.ts
2686
+ var RunnerConfigsServerlessMetadataError = schemas_exports.undiscriminatedUnion([
2687
+ RunnerConfigsServerlessMetadataErrorInvalidRequest,
2688
+ RunnerConfigsServerlessMetadataErrorRequestFailed,
2689
+ RunnerConfigsServerlessMetadataErrorRequestTimedOut,
2690
+ RunnerConfigsServerlessMetadataErrorNonSuccessStatus,
2691
+ RunnerConfigsServerlessMetadataErrorInvalidResponseJson,
2692
+ RunnerConfigsServerlessMetadataErrorInvalidResponseSchema
2693
+ ]);
2694
+
2695
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseFailureFailure.ts
2696
+ var RunnerConfigsServerlessHealthCheckResponseFailureFailure = schemas_exports.object({
2697
+ error: RunnerConfigsServerlessMetadataError
2698
+ });
2699
+
2700
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseFailure.ts
2701
+ var RunnerConfigsServerlessHealthCheckResponseFailure = schemas_exports.object({
2702
+ failure: RunnerConfigsServerlessHealthCheckResponseFailureFailure
2703
+ });
2704
+
2705
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponse.ts
2706
+ var RunnerConfigsServerlessHealthCheckResponse = schemas_exports.undiscriminatedUnion([
2707
+ RunnerConfigsServerlessHealthCheckResponseSuccess,
2708
+ RunnerConfigsServerlessHealthCheckResponseFailure
2709
+ ]);
2710
+
2711
+ // src/serialization/types/RunnerConfigsUpsertResponse.ts
2712
+ var RunnerConfigsUpsertResponse = schemas_exports.object({
2713
+ endpointConfigChanged: schemas_exports.property("endpoint_config_changed", schemas_exports.boolean())
2714
+ });
2715
+
2716
+ // src/serialization/types/RunnersListNamesResponse.ts
2717
+ var RunnersListNamesResponse = schemas_exports.object({
2718
+ names: schemas_exports.list(schemas_exports.string()),
2719
+ pagination: Pagination
2720
+ });
2721
+
2722
+ // src/serialization/types/RunnersListResponse.ts
2723
+ var RunnersListResponse = schemas_exports.object({
2724
+ pagination: Pagination,
2725
+ runners: schemas_exports.list(Runner)
2726
+ });
2727
+
2728
+ // src/serialization/client/requests/ActorsCreateRequest.ts
2729
+ var ActorsCreateRequest = schemas_exports.object({
2730
+ crashPolicy: schemas_exports.property("crash_policy", CrashPolicy2),
2731
+ datacenter: schemas_exports.string().optional(),
2732
+ input: schemas_exports.string().optional(),
2733
+ key: schemas_exports.string().optional(),
2734
+ name: schemas_exports.string(),
2735
+ runnerNameSelector: schemas_exports.property("runner_name_selector", schemas_exports.string())
2736
+ });
2737
+
2738
+ // src/serialization/client/requests/ActorsGetOrCreateRequest.ts
2739
+ var ActorsGetOrCreateRequest = schemas_exports.object({
2740
+ crashPolicy: schemas_exports.property("crash_policy", CrashPolicy2),
2741
+ datacenter: schemas_exports.string().optional(),
2742
+ input: schemas_exports.string().optional(),
2743
+ key: schemas_exports.string(),
2744
+ name: schemas_exports.string(),
2745
+ runnerNameSelector: schemas_exports.property("runner_name_selector", schemas_exports.string())
2746
+ });
2747
+
2748
+ // src/serialization/client/requests/RunnerConfigsServerlessHealthCheckRequest.ts
2749
+ var RunnerConfigsServerlessHealthCheckRequest = schemas_exports.object({
2750
+ headers: schemas_exports.record(schemas_exports.string(), schemas_exports.string()).optional(),
2751
+ url: schemas_exports.string()
2752
+ });
2753
+
2754
+ // src/serialization/client/requests/RunnerConfigsUpsertRequestBody.ts
2755
+ var RunnerConfigsUpsertRequestBody = schemas_exports.object({
2756
+ datacenters: schemas_exports.record(schemas_exports.string(), RunnerConfig)
2757
+ });
2758
+
2759
+ // src/serialization/resources/namespaces/index.ts
2760
+ var namespaces_exports2 = {};
2761
+ __export(namespaces_exports2, {
2762
+ NamespacesCreateRequest: () => NamespacesCreateRequest
2763
+ });
2764
+
2765
+ // src/serialization/resources/namespaces/client/requests/NamespacesCreateRequest.ts
2766
+ var NamespacesCreateRequest = schemas_exports.object({
2767
+ displayName: schemas_exports.property("display_name", schemas_exports.string()),
2768
+ name: schemas_exports.string()
2769
+ });
2770
+
2771
+ // src/Client.ts
2772
+ import urlJoin6 from "url-join";
2773
+
2774
+ // src/errors/RivetError.ts
2775
+ var RivetError = class _RivetError extends Error {
2776
+ statusCode;
2777
+ body;
2778
+ constructor({ message, statusCode, body }) {
2779
+ super(buildMessage({ message, statusCode, body }));
2780
+ Object.setPrototypeOf(this, _RivetError.prototype);
2781
+ if (statusCode != null) {
2782
+ this.statusCode = statusCode;
2783
+ }
2784
+ if (body !== void 0) {
2785
+ this.body = body;
2786
+ }
2787
+ }
2788
+ };
2789
+ function buildMessage({
2790
+ message,
2791
+ statusCode,
2792
+ body
2793
+ }) {
2794
+ let lines = [];
2795
+ if (message != null) {
2796
+ lines.push(message);
2797
+ }
2798
+ if (statusCode != null) {
2799
+ lines.push(`Status code: ${statusCode.toString()}`);
2800
+ }
2801
+ if (body != null) {
2802
+ lines.push(`Body: ${toJson(body, void 0, 2)}`);
2803
+ }
2804
+ return lines.join("\n");
2805
+ }
2806
+
2807
+ // src/errors/RivetTimeoutError.ts
2808
+ var RivetTimeoutError = class _RivetTimeoutError extends Error {
2809
+ constructor(message) {
2810
+ super(message);
2811
+ Object.setPrototypeOf(this, _RivetTimeoutError.prototype);
2812
+ }
2813
+ };
2814
+
2815
+ // src/api/resources/datacenters/client/Client.ts
2816
+ import urlJoin from "url-join";
2817
+ var Datacenters = class {
2818
+ constructor(_options) {
2819
+ this._options = _options;
2820
+ }
2821
+ /**
2822
+ * @param {Datacenters.RequestOptions} requestOptions - Request-specific configuration.
2823
+ *
2824
+ * @example
2825
+ * await client.datacenters.list()
2826
+ */
2827
+ async list(requestOptions) {
2828
+ const _response = await (this._options.fetcher ?? fetcher)({
2829
+ url: urlJoin(
2830
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
2831
+ "datacenters"
2832
+ ),
2833
+ method: "GET",
2834
+ headers: {
2835
+ Authorization: await this._getAuthorizationHeader(),
2836
+ "X-Fern-Language": "JavaScript",
2837
+ "X-Fern-Runtime": RUNTIME.type,
2838
+ "X-Fern-Runtime-Version": RUNTIME.version,
2839
+ ...requestOptions == null ? void 0 : requestOptions.headers
2840
+ },
2841
+ contentType: "application/json",
2842
+ requestType: "json",
2843
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
2844
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
2845
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
2846
+ });
2847
+ if (_response.ok) {
2848
+ return DatacentersListResponse.parseOrThrow(_response.body, {
2849
+ unrecognizedObjectKeys: "passthrough",
2850
+ allowUnrecognizedUnionMembers: true,
2851
+ allowUnrecognizedEnumValues: true,
2852
+ skipValidation: true,
2853
+ breadcrumbsPrefix: ["response"]
2854
+ });
2855
+ }
2856
+ if (_response.error.reason === "status-code") {
2857
+ throw new RivetError({
2858
+ statusCode: _response.error.statusCode,
2859
+ body: _response.error.body
2860
+ });
2861
+ }
2862
+ switch (_response.error.reason) {
2863
+ case "non-json":
2864
+ throw new RivetError({
2865
+ statusCode: _response.error.statusCode,
2866
+ body: _response.error.rawBody
2867
+ });
2868
+ case "timeout":
2869
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /datacenters.");
2870
+ case "unknown":
2871
+ throw new RivetError({
2872
+ message: _response.error.errorMessage
2873
+ });
2874
+ }
2875
+ }
2876
+ async _getAuthorizationHeader() {
2877
+ return `Bearer ${await Supplier.get(this._options.token)}`;
2878
+ }
2879
+ };
2880
+
2881
+ // src/api/resources/health/client/Client.ts
2882
+ import urlJoin2 from "url-join";
2883
+ var Health = class {
2884
+ constructor(_options) {
2885
+ this._options = _options;
2886
+ }
2887
+ /**
2888
+ * @param {Health.RequestOptions} requestOptions - Request-specific configuration.
2889
+ *
2890
+ * @example
2891
+ * await client.health.fanout()
2892
+ */
2893
+ async fanout(requestOptions) {
2894
+ const _response = await (this._options.fetcher ?? fetcher)({
2895
+ url: urlJoin2(
2896
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
2897
+ "health/fanout"
2898
+ ),
2899
+ method: "GET",
2900
+ headers: {
2901
+ Authorization: await this._getAuthorizationHeader(),
2902
+ "X-Fern-Language": "JavaScript",
2903
+ "X-Fern-Runtime": RUNTIME.type,
2904
+ "X-Fern-Runtime-Version": RUNTIME.version,
2905
+ ...requestOptions == null ? void 0 : requestOptions.headers
2906
+ },
2907
+ contentType: "application/json",
2908
+ requestType: "json",
2909
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
2910
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
2911
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
2912
+ });
2913
+ if (_response.ok) {
2914
+ return HealthFanoutResponse.parseOrThrow(_response.body, {
2915
+ unrecognizedObjectKeys: "passthrough",
2916
+ allowUnrecognizedUnionMembers: true,
2917
+ allowUnrecognizedEnumValues: true,
2918
+ skipValidation: true,
2919
+ breadcrumbsPrefix: ["response"]
2920
+ });
2921
+ }
2922
+ if (_response.error.reason === "status-code") {
2923
+ throw new RivetError({
2924
+ statusCode: _response.error.statusCode,
2925
+ body: _response.error.body
2926
+ });
2927
+ }
2928
+ switch (_response.error.reason) {
2929
+ case "non-json":
2930
+ throw new RivetError({
2931
+ statusCode: _response.error.statusCode,
2932
+ body: _response.error.rawBody
2933
+ });
2934
+ case "timeout":
2935
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /health/fanout.");
2936
+ case "unknown":
2937
+ throw new RivetError({
2938
+ message: _response.error.errorMessage
2939
+ });
2940
+ }
2941
+ }
2942
+ async _getAuthorizationHeader() {
2943
+ return `Bearer ${await Supplier.get(this._options.token)}`;
2944
+ }
2945
+ };
2946
+
2947
+ // src/api/resources/metadata/client/Client.ts
2948
+ import urlJoin3 from "url-join";
2949
+ var Metadata = class {
2950
+ constructor(_options) {
2951
+ this._options = _options;
2952
+ }
2953
+ /**
2954
+ * @param {Metadata.RequestOptions} requestOptions - Request-specific configuration.
2955
+ *
2956
+ * @example
2957
+ * await client.metadata.get()
2958
+ */
2959
+ async get(requestOptions) {
2960
+ const _response = await (this._options.fetcher ?? fetcher)({
2961
+ url: urlJoin3(
2962
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
2963
+ "metadata"
2964
+ ),
2965
+ method: "GET",
2966
+ headers: {
2967
+ Authorization: await this._getAuthorizationHeader(),
2968
+ "X-Fern-Language": "JavaScript",
2969
+ "X-Fern-Runtime": RUNTIME.type,
2970
+ "X-Fern-Runtime-Version": RUNTIME.version,
2971
+ ...requestOptions == null ? void 0 : requestOptions.headers
2972
+ },
2973
+ contentType: "application/json",
2974
+ requestType: "json",
2975
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
2976
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
2977
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
2978
+ });
2979
+ if (_response.ok) {
2980
+ return MetadataGetResponse.parseOrThrow(_response.body, {
2981
+ unrecognizedObjectKeys: "passthrough",
2982
+ allowUnrecognizedUnionMembers: true,
2983
+ allowUnrecognizedEnumValues: true,
2984
+ skipValidation: true,
2985
+ breadcrumbsPrefix: ["response"]
2986
+ });
2987
+ }
2988
+ if (_response.error.reason === "status-code") {
2989
+ throw new RivetError({
2990
+ statusCode: _response.error.statusCode,
2991
+ body: _response.error.body
2992
+ });
2993
+ }
2994
+ switch (_response.error.reason) {
2995
+ case "non-json":
2996
+ throw new RivetError({
2997
+ statusCode: _response.error.statusCode,
2998
+ body: _response.error.rawBody
2999
+ });
3000
+ case "timeout":
3001
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /metadata.");
3002
+ case "unknown":
3003
+ throw new RivetError({
3004
+ message: _response.error.errorMessage
3005
+ });
3006
+ }
3007
+ }
3008
+ async _getAuthorizationHeader() {
3009
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3010
+ }
3011
+ };
3012
+
3013
+ // src/api/resources/namespaces/client/Client.ts
3014
+ import urlJoin4 from "url-join";
3015
+ var Namespaces = class {
3016
+ constructor(_options) {
3017
+ this._options = _options;
3018
+ }
3019
+ /**
3020
+ * @param {Rivet.NamespacesListRequest} request
3021
+ * @param {Namespaces.RequestOptions} requestOptions - Request-specific configuration.
3022
+ *
3023
+ * @example
3024
+ * await client.namespaces.list()
3025
+ */
3026
+ async list(request = {}, requestOptions) {
3027
+ const { limit, cursor, name, namespaceIds, namespaceId } = request;
3028
+ const _queryParams = {};
3029
+ if (limit != null) {
3030
+ _queryParams["limit"] = limit.toString();
3031
+ }
3032
+ if (cursor != null) {
3033
+ _queryParams["cursor"] = cursor;
3034
+ }
3035
+ if (name != null) {
3036
+ _queryParams["name"] = name;
3037
+ }
3038
+ if (namespaceIds != null) {
3039
+ _queryParams["namespace_ids"] = namespaceIds;
3040
+ }
3041
+ if (namespaceId != null) {
3042
+ if (Array.isArray(namespaceId)) {
3043
+ _queryParams["namespace_id"] = namespaceId.map(
3044
+ (item) => RivetId.jsonOrThrow(item, { unrecognizedObjectKeys: "strip" })
3045
+ );
3046
+ } else {
3047
+ _queryParams["namespace_id"] = namespaceId;
3048
+ }
3049
+ }
3050
+ const _response = await (this._options.fetcher ?? fetcher)({
3051
+ url: urlJoin4(
3052
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3053
+ "namespaces"
3054
+ ),
3055
+ method: "GET",
3056
+ headers: {
3057
+ Authorization: await this._getAuthorizationHeader(),
3058
+ "X-Fern-Language": "JavaScript",
3059
+ "X-Fern-Runtime": RUNTIME.type,
3060
+ "X-Fern-Runtime-Version": RUNTIME.version,
3061
+ ...requestOptions == null ? void 0 : requestOptions.headers
3062
+ },
3063
+ contentType: "application/json",
3064
+ queryParameters: _queryParams,
3065
+ requestType: "json",
3066
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3067
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3068
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3069
+ });
3070
+ if (_response.ok) {
3071
+ return NamespaceListResponse.parseOrThrow(_response.body, {
3072
+ unrecognizedObjectKeys: "passthrough",
3073
+ allowUnrecognizedUnionMembers: true,
3074
+ allowUnrecognizedEnumValues: true,
3075
+ skipValidation: true,
3076
+ breadcrumbsPrefix: ["response"]
3077
+ });
3078
+ }
3079
+ if (_response.error.reason === "status-code") {
3080
+ throw new RivetError({
3081
+ statusCode: _response.error.statusCode,
3082
+ body: _response.error.body
3083
+ });
3084
+ }
3085
+ switch (_response.error.reason) {
3086
+ case "non-json":
3087
+ throw new RivetError({
3088
+ statusCode: _response.error.statusCode,
3089
+ body: _response.error.rawBody
3090
+ });
3091
+ case "timeout":
3092
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /namespaces.");
3093
+ case "unknown":
3094
+ throw new RivetError({
3095
+ message: _response.error.errorMessage
3096
+ });
3097
+ }
3098
+ }
3099
+ /**
3100
+ * @param {Rivet.NamespacesCreateRequest} request
3101
+ * @param {Namespaces.RequestOptions} requestOptions - Request-specific configuration.
3102
+ *
3103
+ * @example
3104
+ * await client.namespaces.create({
3105
+ * displayName: "display_name",
3106
+ * name: "name"
3107
+ * })
3108
+ */
3109
+ async create(request, requestOptions) {
3110
+ const _response = await (this._options.fetcher ?? fetcher)({
3111
+ url: urlJoin4(
3112
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3113
+ "namespaces"
3114
+ ),
3115
+ method: "POST",
3116
+ headers: {
3117
+ Authorization: await this._getAuthorizationHeader(),
3118
+ "X-Fern-Language": "JavaScript",
3119
+ "X-Fern-Runtime": RUNTIME.type,
3120
+ "X-Fern-Runtime-Version": RUNTIME.version,
3121
+ ...requestOptions == null ? void 0 : requestOptions.headers
3122
+ },
3123
+ contentType: "application/json",
3124
+ requestType: "json",
3125
+ body: NamespacesCreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
3126
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3127
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3128
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3129
+ });
3130
+ if (_response.ok) {
3131
+ return NamespacesCreateResponse.parseOrThrow(_response.body, {
3132
+ unrecognizedObjectKeys: "passthrough",
3133
+ allowUnrecognizedUnionMembers: true,
3134
+ allowUnrecognizedEnumValues: true,
3135
+ skipValidation: true,
3136
+ breadcrumbsPrefix: ["response"]
3137
+ });
3138
+ }
3139
+ if (_response.error.reason === "status-code") {
3140
+ throw new RivetError({
3141
+ statusCode: _response.error.statusCode,
3142
+ body: _response.error.body
3143
+ });
3144
+ }
3145
+ switch (_response.error.reason) {
3146
+ case "non-json":
3147
+ throw new RivetError({
3148
+ statusCode: _response.error.statusCode,
3149
+ body: _response.error.rawBody
3150
+ });
3151
+ case "timeout":
3152
+ throw new RivetTimeoutError("Timeout exceeded when calling POST /namespaces.");
3153
+ case "unknown":
3154
+ throw new RivetError({
3155
+ message: _response.error.errorMessage
3156
+ });
3157
+ }
3158
+ }
3159
+ async _getAuthorizationHeader() {
3160
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3161
+ }
3162
+ };
3163
+
3164
+ // src/api/resources/runners/client/Client.ts
3165
+ import urlJoin5 from "url-join";
3166
+ var Runners = class {
3167
+ constructor(_options) {
3168
+ this._options = _options;
3169
+ }
3170
+ /**
3171
+ * @param {Rivet.RunnersListRequest} request
3172
+ * @param {Runners.RequestOptions} requestOptions - Request-specific configuration.
3173
+ *
3174
+ * @example
3175
+ * await client.runners.list({
3176
+ * namespace: "namespace"
3177
+ * })
3178
+ */
3179
+ async list(request, requestOptions) {
3180
+ const { namespace, name, runnerIds, runnerId, includeStopped, limit, cursor } = request;
3181
+ const _queryParams = {};
3182
+ _queryParams["namespace"] = namespace;
3183
+ if (name != null) {
3184
+ _queryParams["name"] = name;
3185
+ }
3186
+ if (runnerIds != null) {
3187
+ _queryParams["runner_ids"] = runnerIds;
3188
+ }
3189
+ if (runnerId != null) {
3190
+ if (Array.isArray(runnerId)) {
3191
+ _queryParams["runner_id"] = runnerId.map(
3192
+ (item) => RivetId.jsonOrThrow(item, { unrecognizedObjectKeys: "strip" })
3193
+ );
3194
+ } else {
3195
+ _queryParams["runner_id"] = runnerId;
3196
+ }
3197
+ }
3198
+ if (includeStopped != null) {
3199
+ _queryParams["include_stopped"] = includeStopped.toString();
3200
+ }
3201
+ if (limit != null) {
3202
+ _queryParams["limit"] = limit.toString();
3203
+ }
3204
+ if (cursor != null) {
3205
+ _queryParams["cursor"] = cursor;
3206
+ }
3207
+ const _response = await (this._options.fetcher ?? fetcher)({
3208
+ url: urlJoin5(
3209
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3210
+ "runners"
3211
+ ),
3212
+ method: "GET",
3213
+ headers: {
3214
+ Authorization: await this._getAuthorizationHeader(),
3215
+ "X-Fern-Language": "JavaScript",
3216
+ "X-Fern-Runtime": RUNTIME.type,
3217
+ "X-Fern-Runtime-Version": RUNTIME.version,
3218
+ ...requestOptions == null ? void 0 : requestOptions.headers
3219
+ },
3220
+ contentType: "application/json",
3221
+ queryParameters: _queryParams,
3222
+ requestType: "json",
3223
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3224
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3225
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3226
+ });
3227
+ if (_response.ok) {
3228
+ return RunnersListResponse.parseOrThrow(_response.body, {
3229
+ unrecognizedObjectKeys: "passthrough",
3230
+ allowUnrecognizedUnionMembers: true,
3231
+ allowUnrecognizedEnumValues: true,
3232
+ skipValidation: true,
3233
+ breadcrumbsPrefix: ["response"]
3234
+ });
3235
+ }
3236
+ if (_response.error.reason === "status-code") {
3237
+ throw new RivetError({
3238
+ statusCode: _response.error.statusCode,
3239
+ body: _response.error.body
3240
+ });
3241
+ }
3242
+ switch (_response.error.reason) {
3243
+ case "non-json":
3244
+ throw new RivetError({
3245
+ statusCode: _response.error.statusCode,
3246
+ body: _response.error.rawBody
3247
+ });
3248
+ case "timeout":
3249
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /runners.");
3250
+ case "unknown":
3251
+ throw new RivetError({
3252
+ message: _response.error.errorMessage
3253
+ });
3254
+ }
3255
+ }
3256
+ /**
3257
+ * 2 round trips:
3258
+ *
3259
+ * - GET /runners/names (fanout)
3260
+ * - [api-peer] namespace::ops::resolve_for_name_global
3261
+ *
3262
+ * @param {Rivet.RunnersListNamesRequest} request
3263
+ * @param {Runners.RequestOptions} requestOptions - Request-specific configuration.
3264
+ *
3265
+ * @example
3266
+ * await client.runners.listNames({
3267
+ * namespace: "namespace"
3268
+ * })
3269
+ */
3270
+ async listNames(request, requestOptions) {
3271
+ const { namespace, limit, cursor } = request;
3272
+ const _queryParams = {};
3273
+ _queryParams["namespace"] = namespace;
3274
+ if (limit != null) {
3275
+ _queryParams["limit"] = limit.toString();
3276
+ }
3277
+ if (cursor != null) {
3278
+ _queryParams["cursor"] = cursor;
3279
+ }
3280
+ const _response = await (this._options.fetcher ?? fetcher)({
3281
+ url: urlJoin5(
3282
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3283
+ "runners/names"
3284
+ ),
3285
+ method: "GET",
3286
+ headers: {
3287
+ Authorization: await this._getAuthorizationHeader(),
3288
+ "X-Fern-Language": "JavaScript",
3289
+ "X-Fern-Runtime": RUNTIME.type,
3290
+ "X-Fern-Runtime-Version": RUNTIME.version,
3291
+ ...requestOptions == null ? void 0 : requestOptions.headers
3292
+ },
3293
+ contentType: "application/json",
3294
+ queryParameters: _queryParams,
3295
+ requestType: "json",
3296
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3297
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3298
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3299
+ });
3300
+ if (_response.ok) {
3301
+ return RunnersListNamesResponse.parseOrThrow(_response.body, {
3302
+ unrecognizedObjectKeys: "passthrough",
3303
+ allowUnrecognizedUnionMembers: true,
3304
+ allowUnrecognizedEnumValues: true,
3305
+ skipValidation: true,
3306
+ breadcrumbsPrefix: ["response"]
3307
+ });
3308
+ }
3309
+ if (_response.error.reason === "status-code") {
3310
+ throw new RivetError({
3311
+ statusCode: _response.error.statusCode,
3312
+ body: _response.error.body
3313
+ });
3314
+ }
3315
+ switch (_response.error.reason) {
3316
+ case "non-json":
3317
+ throw new RivetError({
3318
+ statusCode: _response.error.statusCode,
3319
+ body: _response.error.rawBody
3320
+ });
3321
+ case "timeout":
3322
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /runners/names.");
3323
+ case "unknown":
3324
+ throw new RivetError({
3325
+ message: _response.error.errorMessage
3326
+ });
3327
+ }
3328
+ }
3329
+ async _getAuthorizationHeader() {
3330
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3331
+ }
3332
+ };
3333
+
3334
+ // src/Client.ts
3335
+ var RivetClient = class {
3336
+ constructor(_options) {
3337
+ this._options = _options;
3338
+ }
3339
+ _datacenters;
3340
+ _health;
3341
+ _metadata;
3342
+ _namespaces;
3343
+ _runners;
3344
+ get datacenters() {
3345
+ return this._datacenters ?? (this._datacenters = new Datacenters(this._options));
3346
+ }
3347
+ get health() {
3348
+ return this._health ?? (this._health = new Health(this._options));
3349
+ }
3350
+ get metadata() {
3351
+ return this._metadata ?? (this._metadata = new Metadata(this._options));
3352
+ }
3353
+ get namespaces() {
3354
+ return this._namespaces ?? (this._namespaces = new Namespaces(this._options));
3355
+ }
3356
+ get runners() {
3357
+ return this._runners ?? (this._runners = new Runners(this._options));
3358
+ }
3359
+ /**
3360
+ * **If key is some & `include_destroyed` is false**
3361
+ *
3362
+ * 2 round trips:
3363
+ *
3364
+ * - namespace::ops::resolve_for_name_global
3365
+ * - GET /actors (multiple DCs based on actor IDs)
3366
+ *
3367
+ * This path is optimized because we can read the actor IDs fro the key directly from Epoxy with
3368
+ * stale consistency to determine which datacenter the actor lives in. Under most circumstances,
3369
+ * this means we don't need to fan out to all datacenters (like normal list does).
3370
+ *
3371
+ * The reason `include_destroyed` has to be false is Epoxy only stores currently active actors. If
3372
+ * `include_destroyed` is true, we show all previous iterations of actors with the same key.
3373
+ *
3374
+ * **Otherwise**
3375
+ *
3376
+ * 2 round trips:
3377
+ *
3378
+ * - namespace::ops::resolve_for_name_global
3379
+ * - GET /actors (fanout)
3380
+ *
3381
+ * ## Optimized Alternative Routes
3382
+ *
3383
+ * @param {Rivet.ActorsListRequest} request
3384
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3385
+ *
3386
+ * @example
3387
+ * await client.actorsList({
3388
+ * namespace: "namespace"
3389
+ * })
3390
+ */
3391
+ async actorsList(request, requestOptions) {
3392
+ const { namespace, name, key, actorIds, actorId, includeDestroyed, limit, cursor } = request;
3393
+ const _queryParams = {};
3394
+ _queryParams["namespace"] = namespace;
3395
+ if (name != null) {
3396
+ _queryParams["name"] = name;
3397
+ }
3398
+ if (key != null) {
3399
+ _queryParams["key"] = key;
3400
+ }
3401
+ if (actorIds != null) {
3402
+ _queryParams["actor_ids"] = actorIds;
3403
+ }
3404
+ if (actorId != null) {
3405
+ if (Array.isArray(actorId)) {
3406
+ _queryParams["actor_id"] = actorId.map(
3407
+ (item) => RivetId.jsonOrThrow(item, { unrecognizedObjectKeys: "strip" })
3408
+ );
3409
+ } else {
3410
+ _queryParams["actor_id"] = actorId;
3411
+ }
3412
+ }
3413
+ if (includeDestroyed != null) {
3414
+ _queryParams["include_destroyed"] = includeDestroyed.toString();
3415
+ }
3416
+ if (limit != null) {
3417
+ _queryParams["limit"] = limit.toString();
3418
+ }
3419
+ if (cursor != null) {
3420
+ _queryParams["cursor"] = cursor;
3421
+ }
3422
+ const _response = await (this._options.fetcher ?? fetcher)({
3423
+ url: urlJoin6(
3424
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3425
+ "actors"
3426
+ ),
3427
+ method: "GET",
3428
+ headers: {
3429
+ Authorization: await this._getAuthorizationHeader(),
3430
+ "X-Fern-Language": "JavaScript",
3431
+ "X-Fern-Runtime": RUNTIME.type,
3432
+ "X-Fern-Runtime-Version": RUNTIME.version,
3433
+ ...requestOptions == null ? void 0 : requestOptions.headers
3434
+ },
3435
+ contentType: "application/json",
3436
+ queryParameters: _queryParams,
3437
+ requestType: "json",
3438
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3439
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3440
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3441
+ });
3442
+ if (_response.ok) {
3443
+ return ActorsListResponse.parseOrThrow(_response.body, {
3444
+ unrecognizedObjectKeys: "passthrough",
3445
+ allowUnrecognizedUnionMembers: true,
3446
+ allowUnrecognizedEnumValues: true,
3447
+ skipValidation: true,
3448
+ breadcrumbsPrefix: ["response"]
3449
+ });
3450
+ }
3451
+ if (_response.error.reason === "status-code") {
3452
+ throw new RivetError({
3453
+ statusCode: _response.error.statusCode,
3454
+ body: _response.error.body
3455
+ });
3456
+ }
3457
+ switch (_response.error.reason) {
3458
+ case "non-json":
3459
+ throw new RivetError({
3460
+ statusCode: _response.error.statusCode,
3461
+ body: _response.error.rawBody
3462
+ });
3463
+ case "timeout":
3464
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /actors.");
3465
+ case "unknown":
3466
+ throw new RivetError({
3467
+ message: _response.error.errorMessage
3468
+ });
3469
+ }
3470
+ }
3471
+ /**
3472
+ * **If actor is created in the current datacenter:**
3473
+ *
3474
+ * 2 round trips:
3475
+ *
3476
+ * - namespace::ops::resolve_for_name_global
3477
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3478
+ *
3479
+ * **If actor is created in a different datacenter:**
3480
+ *
3481
+ * 3 round trips:
3482
+ *
3483
+ * - namespace::ops::resolve_for_name_global
3484
+ * - POST /actors to remote datacenter
3485
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3486
+ *
3487
+ * actor::get will always be in the same datacenter.
3488
+ *
3489
+ * @param {Rivet.ActorsCreateRequest} request
3490
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3491
+ *
3492
+ * @example
3493
+ * await client.actorsCreate({
3494
+ * namespace: "namespace",
3495
+ * crashPolicy: "restart",
3496
+ * name: "name",
3497
+ * runnerNameSelector: "runner_name_selector"
3498
+ * })
3499
+ */
3500
+ async actorsCreate(request, requestOptions) {
3501
+ const { namespace, ..._body } = request;
3502
+ const _queryParams = {};
3503
+ _queryParams["namespace"] = namespace;
3504
+ const _response = await (this._options.fetcher ?? fetcher)({
3505
+ url: urlJoin6(
3506
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3507
+ "actors"
3508
+ ),
3509
+ method: "POST",
3510
+ headers: {
3511
+ Authorization: await this._getAuthorizationHeader(),
3512
+ "X-Fern-Language": "JavaScript",
3513
+ "X-Fern-Runtime": RUNTIME.type,
3514
+ "X-Fern-Runtime-Version": RUNTIME.version,
3515
+ ...requestOptions == null ? void 0 : requestOptions.headers
3516
+ },
3517
+ contentType: "application/json",
3518
+ queryParameters: _queryParams,
3519
+ requestType: "json",
3520
+ body: ActorsCreateRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
3521
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3522
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3523
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3524
+ });
3525
+ if (_response.ok) {
3526
+ return ActorsCreateResponse.parseOrThrow(_response.body, {
3527
+ unrecognizedObjectKeys: "passthrough",
3528
+ allowUnrecognizedUnionMembers: true,
3529
+ allowUnrecognizedEnumValues: true,
3530
+ skipValidation: true,
3531
+ breadcrumbsPrefix: ["response"]
3532
+ });
3533
+ }
3534
+ if (_response.error.reason === "status-code") {
3535
+ throw new RivetError({
3536
+ statusCode: _response.error.statusCode,
3537
+ body: _response.error.body
3538
+ });
3539
+ }
3540
+ switch (_response.error.reason) {
3541
+ case "non-json":
3542
+ throw new RivetError({
3543
+ statusCode: _response.error.statusCode,
3544
+ body: _response.error.rawBody
3545
+ });
3546
+ case "timeout":
3547
+ throw new RivetTimeoutError("Timeout exceeded when calling POST /actors.");
3548
+ case "unknown":
3549
+ throw new RivetError({
3550
+ message: _response.error.errorMessage
3551
+ });
3552
+ }
3553
+ }
3554
+ /**
3555
+ * **If actor exists**
3556
+ *
3557
+ * 2 round trips:
3558
+ *
3559
+ * - namespace::ops::resolve_for_name_global
3560
+ * - GET /actors/{}
3561
+ *
3562
+ * **If actor does not exist and is created in the current datacenter:**
3563
+ *
3564
+ * 2 round trips:
3565
+ *
3566
+ * - namespace::ops::resolve_for_name_global
3567
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3568
+ *
3569
+ * **If actor does not exist and is created in a different datacenter:**
3570
+ *
3571
+ * 3 round trips:
3572
+ *
3573
+ * - namespace::ops::resolve_for_name_global
3574
+ * - POST /actors to remote datacenter
3575
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3576
+ *
3577
+ * actor::get will always be in the same datacenter.
3578
+ *
3579
+ * ## Optimized Alternative Routes
3580
+ *
3581
+ * @param {Rivet.ActorsGetOrCreateRequest} request
3582
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3583
+ *
3584
+ * @example
3585
+ * await client.actorsGetOrCreate({
3586
+ * namespace: "namespace",
3587
+ * crashPolicy: "restart",
3588
+ * key: "key",
3589
+ * name: "name",
3590
+ * runnerNameSelector: "runner_name_selector"
3591
+ * })
3592
+ */
3593
+ async actorsGetOrCreate(request, requestOptions) {
3594
+ const { namespace, ..._body } = request;
3595
+ const _queryParams = {};
3596
+ _queryParams["namespace"] = namespace;
3597
+ const _response = await (this._options.fetcher ?? fetcher)({
3598
+ url: urlJoin6(
3599
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3600
+ "actors"
3601
+ ),
3602
+ method: "PUT",
3603
+ headers: {
3604
+ Authorization: await this._getAuthorizationHeader(),
3605
+ "X-Fern-Language": "JavaScript",
3606
+ "X-Fern-Runtime": RUNTIME.type,
3607
+ "X-Fern-Runtime-Version": RUNTIME.version,
3608
+ ...requestOptions == null ? void 0 : requestOptions.headers
3609
+ },
3610
+ contentType: "application/json",
3611
+ queryParameters: _queryParams,
3612
+ requestType: "json",
3613
+ body: ActorsGetOrCreateRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
3614
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3615
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3616
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3617
+ });
3618
+ if (_response.ok) {
3619
+ return ActorsGetOrCreateResponse.parseOrThrow(_response.body, {
3620
+ unrecognizedObjectKeys: "passthrough",
3621
+ allowUnrecognizedUnionMembers: true,
3622
+ allowUnrecognizedEnumValues: true,
3623
+ skipValidation: true,
3624
+ breadcrumbsPrefix: ["response"]
3625
+ });
3626
+ }
3627
+ if (_response.error.reason === "status-code") {
3628
+ throw new RivetError({
3629
+ statusCode: _response.error.statusCode,
3630
+ body: _response.error.body
3631
+ });
3632
+ }
3633
+ switch (_response.error.reason) {
3634
+ case "non-json":
3635
+ throw new RivetError({
3636
+ statusCode: _response.error.statusCode,
3637
+ body: _response.error.rawBody
3638
+ });
3639
+ case "timeout":
3640
+ throw new RivetTimeoutError("Timeout exceeded when calling PUT /actors.");
3641
+ case "unknown":
3642
+ throw new RivetError({
3643
+ message: _response.error.errorMessage
3644
+ });
3645
+ }
3646
+ }
3647
+ /**
3648
+ * 2 round trips:
3649
+ *
3650
+ * - GET /actors/names (fanout)
3651
+ * - [api-peer] namespace::ops::resolve_for_name_global
3652
+ *
3653
+ * @param {Rivet.ActorsListNamesRequest} request
3654
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3655
+ *
3656
+ * @example
3657
+ * await client.actorsListNames({
3658
+ * namespace: "namespace"
3659
+ * })
3660
+ */
3661
+ async actorsListNames(request, requestOptions) {
3662
+ const { namespace, limit, cursor } = request;
3663
+ const _queryParams = {};
3664
+ _queryParams["namespace"] = namespace;
3665
+ if (limit != null) {
3666
+ _queryParams["limit"] = limit.toString();
3667
+ }
3668
+ if (cursor != null) {
3669
+ _queryParams["cursor"] = cursor;
3670
+ }
3671
+ const _response = await (this._options.fetcher ?? fetcher)({
3672
+ url: urlJoin6(
3673
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3674
+ "actors/names"
3675
+ ),
3676
+ method: "GET",
3677
+ headers: {
3678
+ Authorization: await this._getAuthorizationHeader(),
3679
+ "X-Fern-Language": "JavaScript",
3680
+ "X-Fern-Runtime": RUNTIME.type,
3681
+ "X-Fern-Runtime-Version": RUNTIME.version,
3682
+ ...requestOptions == null ? void 0 : requestOptions.headers
3683
+ },
3684
+ contentType: "application/json",
3685
+ queryParameters: _queryParams,
3686
+ requestType: "json",
3687
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3688
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3689
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3690
+ });
3691
+ if (_response.ok) {
3692
+ return ActorsListNamesResponse.parseOrThrow(_response.body, {
3693
+ unrecognizedObjectKeys: "passthrough",
3694
+ allowUnrecognizedUnionMembers: true,
3695
+ allowUnrecognizedEnumValues: true,
3696
+ skipValidation: true,
3697
+ breadcrumbsPrefix: ["response"]
3698
+ });
3699
+ }
3700
+ if (_response.error.reason === "status-code") {
3701
+ throw new RivetError({
3702
+ statusCode: _response.error.statusCode,
3703
+ body: _response.error.body
3704
+ });
3705
+ }
3706
+ switch (_response.error.reason) {
3707
+ case "non-json":
3708
+ throw new RivetError({
3709
+ statusCode: _response.error.statusCode,
3710
+ body: _response.error.rawBody
3711
+ });
3712
+ case "timeout":
3713
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /actors/names.");
3714
+ case "unknown":
3715
+ throw new RivetError({
3716
+ message: _response.error.errorMessage
3717
+ });
3718
+ }
3719
+ }
3720
+ /**
3721
+ * 2 round trip:
3722
+ *
3723
+ * - DELETE /actors/{}
3724
+ * - [api-peer] namespace::ops::resolve_for_name_global
3725
+ *
3726
+ * @param {Rivet.RivetId} actorId
3727
+ * @param {Rivet.ActorsDeleteRequest} request
3728
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3729
+ *
3730
+ * @example
3731
+ * await client.actorsDelete("actor_id", {
3732
+ * namespace: "namespace"
3733
+ * })
3734
+ */
3735
+ async actorsDelete(actorId, request, requestOptions) {
3736
+ const { namespace } = request;
3737
+ const _queryParams = {};
3738
+ _queryParams["namespace"] = namespace;
3739
+ const _response = await (this._options.fetcher ?? fetcher)({
3740
+ url: urlJoin6(
3741
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3742
+ `actors/${encodeURIComponent(RivetId.jsonOrThrow(actorId))}`
3743
+ ),
3744
+ method: "DELETE",
3745
+ headers: {
3746
+ Authorization: await this._getAuthorizationHeader(),
3747
+ "X-Fern-Language": "JavaScript",
3748
+ "X-Fern-Runtime": RUNTIME.type,
3749
+ "X-Fern-Runtime-Version": RUNTIME.version,
3750
+ ...requestOptions == null ? void 0 : requestOptions.headers
3751
+ },
3752
+ contentType: "application/json",
3753
+ queryParameters: _queryParams,
3754
+ requestType: "json",
3755
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3756
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3757
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3758
+ });
3759
+ if (_response.ok) {
3760
+ return ActorsDeleteResponse.parseOrThrow(_response.body, {
3761
+ unrecognizedObjectKeys: "passthrough",
3762
+ allowUnrecognizedUnionMembers: true,
3763
+ allowUnrecognizedEnumValues: true,
3764
+ skipValidation: true,
3765
+ breadcrumbsPrefix: ["response"]
3766
+ });
3767
+ }
3768
+ if (_response.error.reason === "status-code") {
3769
+ throw new RivetError({
3770
+ statusCode: _response.error.statusCode,
3771
+ body: _response.error.body
3772
+ });
3773
+ }
3774
+ switch (_response.error.reason) {
3775
+ case "non-json":
3776
+ throw new RivetError({
3777
+ statusCode: _response.error.statusCode,
3778
+ body: _response.error.rawBody
3779
+ });
3780
+ case "timeout":
3781
+ throw new RivetTimeoutError("Timeout exceeded when calling DELETE /actors/{actor_id}.");
3782
+ case "unknown":
3783
+ throw new RivetError({
3784
+ message: _response.error.errorMessage
3785
+ });
3786
+ }
3787
+ }
3788
+ /**
3789
+ * @param {Rivet.RivetId} actorId
3790
+ * @param {string} key
3791
+ * @param {Rivet.ActorsKvGetRequest} request
3792
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3793
+ *
3794
+ * @example
3795
+ * await client.actorsKvGet("actor_id", "key", {
3796
+ * namespace: "namespace"
3797
+ * })
3798
+ */
3799
+ async actorsKvGet(actorId, key, request, requestOptions) {
3800
+ const { namespace } = request;
3801
+ const _queryParams = {};
3802
+ _queryParams["namespace"] = namespace;
3803
+ const _response = await (this._options.fetcher ?? fetcher)({
3804
+ url: urlJoin6(
3805
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3806
+ `actors/${encodeURIComponent(RivetId.jsonOrThrow(actorId))}/kv/keys/${encodeURIComponent(key)}`
3807
+ ),
3808
+ method: "GET",
3809
+ headers: {
3810
+ Authorization: await this._getAuthorizationHeader(),
3811
+ "X-Fern-Language": "JavaScript",
3812
+ "X-Fern-Runtime": RUNTIME.type,
3813
+ "X-Fern-Runtime-Version": RUNTIME.version,
3814
+ ...requestOptions == null ? void 0 : requestOptions.headers
3815
+ },
3816
+ contentType: "application/json",
3817
+ queryParameters: _queryParams,
3818
+ requestType: "json",
3819
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3820
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3821
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3822
+ });
3823
+ if (_response.ok) {
3824
+ return ActorsKvGetResponse.parseOrThrow(_response.body, {
3825
+ unrecognizedObjectKeys: "passthrough",
3826
+ allowUnrecognizedUnionMembers: true,
3827
+ allowUnrecognizedEnumValues: true,
3828
+ skipValidation: true,
3829
+ breadcrumbsPrefix: ["response"]
3830
+ });
3831
+ }
3832
+ if (_response.error.reason === "status-code") {
3833
+ throw new RivetError({
3834
+ statusCode: _response.error.statusCode,
3835
+ body: _response.error.body
3836
+ });
3837
+ }
3838
+ switch (_response.error.reason) {
3839
+ case "non-json":
3840
+ throw new RivetError({
3841
+ statusCode: _response.error.statusCode,
3842
+ body: _response.error.rawBody
3843
+ });
3844
+ case "timeout":
3845
+ throw new RivetTimeoutError(
3846
+ "Timeout exceeded when calling GET /actors/{actor_id}/kv/keys/{key}."
3847
+ );
3848
+ case "unknown":
3849
+ throw new RivetError({
3850
+ message: _response.error.errorMessage
3851
+ });
3852
+ }
3853
+ }
3854
+ /**
3855
+ * @param {Rivet.RunnerConfigsListRequest} request
3856
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3857
+ *
3858
+ * @example
3859
+ * await client.runnerConfigsList({
3860
+ * namespace: "namespace"
3861
+ * })
3862
+ */
3863
+ async runnerConfigsList(request, requestOptions) {
3864
+ const { namespace, limit, cursor, variant, runnerNames, runnerName } = request;
3865
+ const _queryParams = {};
3866
+ _queryParams["namespace"] = namespace;
3867
+ if (limit != null) {
3868
+ _queryParams["limit"] = limit.toString();
3869
+ }
3870
+ if (cursor != null) {
3871
+ _queryParams["cursor"] = cursor;
3872
+ }
3873
+ if (variant != null) {
3874
+ _queryParams["variant"] = RunnerConfigVariant2.jsonOrThrow(variant, {
3875
+ unrecognizedObjectKeys: "strip"
3876
+ });
3877
+ }
3878
+ if (runnerNames != null) {
3879
+ _queryParams["runner_names"] = runnerNames;
3880
+ }
3881
+ if (runnerName != null) {
3882
+ if (Array.isArray(runnerName)) {
3883
+ _queryParams["runner_name"] = runnerName.map((item) => item);
3884
+ } else {
3885
+ _queryParams["runner_name"] = runnerName;
3886
+ }
3887
+ }
3888
+ const _response = await (this._options.fetcher ?? fetcher)({
3889
+ url: urlJoin6(
3890
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3891
+ "runner-configs"
3892
+ ),
3893
+ method: "GET",
3894
+ headers: {
3895
+ Authorization: await this._getAuthorizationHeader(),
3896
+ "X-Fern-Language": "JavaScript",
3897
+ "X-Fern-Runtime": RUNTIME.type,
3898
+ "X-Fern-Runtime-Version": RUNTIME.version,
3899
+ ...requestOptions == null ? void 0 : requestOptions.headers
3900
+ },
3901
+ contentType: "application/json",
3902
+ queryParameters: _queryParams,
3903
+ requestType: "json",
3904
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3905
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3906
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3907
+ });
3908
+ if (_response.ok) {
3909
+ return RunnerConfigsListResponse.parseOrThrow(_response.body, {
3910
+ unrecognizedObjectKeys: "passthrough",
3911
+ allowUnrecognizedUnionMembers: true,
3912
+ allowUnrecognizedEnumValues: true,
3913
+ skipValidation: true,
3914
+ breadcrumbsPrefix: ["response"]
3915
+ });
3916
+ }
3917
+ if (_response.error.reason === "status-code") {
3918
+ throw new RivetError({
3919
+ statusCode: _response.error.statusCode,
3920
+ body: _response.error.body
3921
+ });
3922
+ }
3923
+ switch (_response.error.reason) {
3924
+ case "non-json":
3925
+ throw new RivetError({
3926
+ statusCode: _response.error.statusCode,
3927
+ body: _response.error.rawBody
3928
+ });
3929
+ case "timeout":
3930
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /runner-configs.");
3931
+ case "unknown":
3932
+ throw new RivetError({
3933
+ message: _response.error.errorMessage
3934
+ });
3935
+ }
3936
+ }
3937
+ /**
3938
+ * @param {Rivet.RunnerConfigsServerlessHealthCheckRequest} request
3939
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3940
+ *
3941
+ * @example
3942
+ * await client.runnerConfigsServerlessHealthCheck({
3943
+ * namespace: "namespace",
3944
+ * url: "url"
3945
+ * })
3946
+ */
3947
+ async runnerConfigsServerlessHealthCheck(request, requestOptions) {
3948
+ const { namespace, ..._body } = request;
3949
+ const _queryParams = {};
3950
+ _queryParams["namespace"] = namespace;
3951
+ const _response = await (this._options.fetcher ?? fetcher)({
3952
+ url: urlJoin6(
3953
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3954
+ "runner-configs/serverless-health-check"
3955
+ ),
3956
+ method: "POST",
3957
+ headers: {
3958
+ Authorization: await this._getAuthorizationHeader(),
3959
+ "X-Fern-Language": "JavaScript",
3960
+ "X-Fern-Runtime": RUNTIME.type,
3961
+ "X-Fern-Runtime-Version": RUNTIME.version,
3962
+ ...requestOptions == null ? void 0 : requestOptions.headers
3963
+ },
3964
+ contentType: "application/json",
3965
+ queryParameters: _queryParams,
3966
+ requestType: "json",
3967
+ body: RunnerConfigsServerlessHealthCheckRequest.jsonOrThrow(_body, {
3968
+ unrecognizedObjectKeys: "strip"
3969
+ }),
3970
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3971
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3972
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3973
+ });
3974
+ if (_response.ok) {
3975
+ return RunnerConfigsServerlessHealthCheckResponse.parseOrThrow(_response.body, {
3976
+ unrecognizedObjectKeys: "passthrough",
3977
+ allowUnrecognizedUnionMembers: true,
3978
+ allowUnrecognizedEnumValues: true,
3979
+ skipValidation: true,
3980
+ breadcrumbsPrefix: ["response"]
3981
+ });
3982
+ }
3983
+ if (_response.error.reason === "status-code") {
3984
+ throw new RivetError({
3985
+ statusCode: _response.error.statusCode,
3986
+ body: _response.error.body
3987
+ });
3988
+ }
3989
+ switch (_response.error.reason) {
3990
+ case "non-json":
3991
+ throw new RivetError({
3992
+ statusCode: _response.error.statusCode,
3993
+ body: _response.error.rawBody
3994
+ });
3995
+ case "timeout":
3996
+ throw new RivetTimeoutError(
3997
+ "Timeout exceeded when calling POST /runner-configs/serverless-health-check."
3998
+ );
3999
+ case "unknown":
4000
+ throw new RivetError({
4001
+ message: _response.error.errorMessage
4002
+ });
4003
+ }
4004
+ }
4005
+ /**
4006
+ * @param {string} runnerName
4007
+ * @param {Rivet.RunnerConfigsUpsertRequestBody} request
4008
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4009
+ *
4010
+ * @example
4011
+ * await client.runnerConfigsUpsert("runner_name", {
4012
+ * namespace: "namespace",
4013
+ * datacenters: {
4014
+ * "key": {}
4015
+ * }
4016
+ * })
4017
+ */
4018
+ async runnerConfigsUpsert(runnerName, request, requestOptions) {
4019
+ const { namespace, ..._body } = request;
4020
+ const _queryParams = {};
4021
+ _queryParams["namespace"] = namespace;
4022
+ const _response = await (this._options.fetcher ?? fetcher)({
4023
+ url: urlJoin6(
4024
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4025
+ `runner-configs/${encodeURIComponent(runnerName)}`
4026
+ ),
4027
+ method: "PUT",
4028
+ headers: {
4029
+ Authorization: await this._getAuthorizationHeader(),
4030
+ "X-Fern-Language": "JavaScript",
4031
+ "X-Fern-Runtime": RUNTIME.type,
4032
+ "X-Fern-Runtime-Version": RUNTIME.version,
4033
+ ...requestOptions == null ? void 0 : requestOptions.headers
4034
+ },
4035
+ contentType: "application/json",
4036
+ queryParameters: _queryParams,
4037
+ requestType: "json",
4038
+ body: RunnerConfigsUpsertRequestBody.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
4039
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4040
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4041
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4042
+ });
4043
+ if (_response.ok) {
4044
+ return RunnerConfigsUpsertResponse.parseOrThrow(_response.body, {
4045
+ unrecognizedObjectKeys: "passthrough",
4046
+ allowUnrecognizedUnionMembers: true,
4047
+ allowUnrecognizedEnumValues: true,
4048
+ skipValidation: true,
4049
+ breadcrumbsPrefix: ["response"]
4050
+ });
4051
+ }
4052
+ if (_response.error.reason === "status-code") {
4053
+ throw new RivetError({
4054
+ statusCode: _response.error.statusCode,
4055
+ body: _response.error.body
4056
+ });
4057
+ }
4058
+ switch (_response.error.reason) {
4059
+ case "non-json":
4060
+ throw new RivetError({
4061
+ statusCode: _response.error.statusCode,
4062
+ body: _response.error.rawBody
4063
+ });
4064
+ case "timeout":
4065
+ throw new RivetTimeoutError("Timeout exceeded when calling PUT /runner-configs/{runner_name}.");
4066
+ case "unknown":
4067
+ throw new RivetError({
4068
+ message: _response.error.errorMessage
4069
+ });
4070
+ }
4071
+ }
4072
+ /**
4073
+ * @param {string} runnerName
4074
+ * @param {Rivet.RunnerConfigsDeleteRequest} request
4075
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4076
+ *
4077
+ * @example
4078
+ * await client.runnerConfigsDelete("runner_name", {
4079
+ * namespace: "namespace"
4080
+ * })
4081
+ */
4082
+ async runnerConfigsDelete(runnerName, request, requestOptions) {
4083
+ const { namespace } = request;
4084
+ const _queryParams = {};
4085
+ _queryParams["namespace"] = namespace;
4086
+ const _response = await (this._options.fetcher ?? fetcher)({
4087
+ url: urlJoin6(
4088
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4089
+ `runner-configs/${encodeURIComponent(runnerName)}`
4090
+ ),
4091
+ method: "DELETE",
4092
+ headers: {
4093
+ Authorization: await this._getAuthorizationHeader(),
4094
+ "X-Fern-Language": "JavaScript",
4095
+ "X-Fern-Runtime": RUNTIME.type,
4096
+ "X-Fern-Runtime-Version": RUNTIME.version,
4097
+ ...requestOptions == null ? void 0 : requestOptions.headers
4098
+ },
4099
+ contentType: "application/json",
4100
+ queryParameters: _queryParams,
4101
+ requestType: "json",
4102
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4103
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4104
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4105
+ });
4106
+ if (_response.ok) {
4107
+ return RunnerConfigsDeleteResponse.parseOrThrow(_response.body, {
4108
+ unrecognizedObjectKeys: "passthrough",
4109
+ allowUnrecognizedUnionMembers: true,
4110
+ allowUnrecognizedEnumValues: true,
4111
+ skipValidation: true,
4112
+ breadcrumbsPrefix: ["response"]
4113
+ });
4114
+ }
4115
+ if (_response.error.reason === "status-code") {
4116
+ throw new RivetError({
4117
+ statusCode: _response.error.statusCode,
4118
+ body: _response.error.body
4119
+ });
4120
+ }
4121
+ switch (_response.error.reason) {
4122
+ case "non-json":
4123
+ throw new RivetError({
4124
+ statusCode: _response.error.statusCode,
4125
+ body: _response.error.rawBody
4126
+ });
4127
+ case "timeout":
4128
+ throw new RivetTimeoutError(
4129
+ "Timeout exceeded when calling DELETE /runner-configs/{runner_name}."
4130
+ );
4131
+ case "unknown":
4132
+ throw new RivetError({
4133
+ message: _response.error.errorMessage
4134
+ });
4135
+ }
4136
+ }
4137
+ /**
4138
+ * @param {string} runnerName
4139
+ * @param {Rivet.RunnerConfigsRefreshMetadataRequest} request
4140
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4141
+ *
4142
+ * @example
4143
+ * await client.runnerConfigsRefreshMetadata("runner_name", {
4144
+ * namespace: "namespace",
4145
+ * body: {
4146
+ * "key": "value"
4147
+ * }
4148
+ * })
4149
+ */
4150
+ async runnerConfigsRefreshMetadata(runnerName, request, requestOptions) {
4151
+ const { namespace, body: _body } = request;
4152
+ const _queryParams = {};
4153
+ _queryParams["namespace"] = namespace;
4154
+ const _response = await (this._options.fetcher ?? fetcher)({
4155
+ url: urlJoin6(
4156
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4157
+ `runner-configs/${encodeURIComponent(runnerName)}/refresh-metadata`
4158
+ ),
4159
+ method: "POST",
4160
+ headers: {
4161
+ Authorization: await this._getAuthorizationHeader(),
4162
+ "X-Fern-Language": "JavaScript",
4163
+ "X-Fern-Runtime": RUNTIME.type,
4164
+ "X-Fern-Runtime-Version": RUNTIME.version,
4165
+ ...requestOptions == null ? void 0 : requestOptions.headers
4166
+ },
4167
+ contentType: "application/json",
4168
+ queryParameters: _queryParams,
4169
+ requestType: "json",
4170
+ body: RunnerConfigsRefreshMetadataRequestBody.jsonOrThrow(_body, {
4171
+ unrecognizedObjectKeys: "strip"
4172
+ }),
4173
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4174
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4175
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4176
+ });
4177
+ if (_response.ok) {
4178
+ return RunnerConfigsRefreshMetadataResponse.parseOrThrow(_response.body, {
4179
+ unrecognizedObjectKeys: "passthrough",
4180
+ allowUnrecognizedUnionMembers: true,
4181
+ allowUnrecognizedEnumValues: true,
4182
+ skipValidation: true,
4183
+ breadcrumbsPrefix: ["response"]
4184
+ });
4185
+ }
4186
+ if (_response.error.reason === "status-code") {
4187
+ throw new RivetError({
4188
+ statusCode: _response.error.statusCode,
4189
+ body: _response.error.body
4190
+ });
4191
+ }
4192
+ switch (_response.error.reason) {
4193
+ case "non-json":
4194
+ throw new RivetError({
4195
+ statusCode: _response.error.statusCode,
4196
+ body: _response.error.rawBody
4197
+ });
4198
+ case "timeout":
4199
+ throw new RivetTimeoutError(
4200
+ "Timeout exceeded when calling POST /runner-configs/{runner_name}/refresh-metadata."
4201
+ );
4202
+ case "unknown":
4203
+ throw new RivetError({
4204
+ message: _response.error.errorMessage
4205
+ });
4206
+ }
4207
+ }
4208
+ async _getAuthorizationHeader() {
4209
+ return `Bearer ${await Supplier.get(this._options.token)}`;
4210
+ }
4211
+ };
4212
+ export {
4213
+ api_exports as Rivet,
4214
+ RivetClient,
4215
+ RivetError,
4216
+ RivetTimeoutError,
4217
+ serialization_exports as serialization
4218
+ };