@rivetkit/engine-api-full 0.0.0-main.31c444e

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