@rivetkit/engine-api-full 0.0.0-main.d6a0ba8

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