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