@rivetkit/engine-api-full 25.5.3

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