@rivetkit/engine-api-full 0.0.0-0-0-0-preview-guard-stops.9d82529

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 (264) hide show
  1. package/dist/browser/cjs/core.js +2338 -0
  2. package/dist/browser/cjs/index.js +4480 -0
  3. package/dist/browser/cjs/package.json +3 -0
  4. package/dist/browser/cjs/serialization.js +1961 -0
  5. package/dist/browser/esm/core.js +2312 -0
  6. package/dist/browser/esm/index.js +4454 -0
  7. package/dist/browser/esm/package.json +3 -0
  8. package/dist/browser/esm/serialization.js +1934 -0
  9. package/dist/node/cjs/core.js +2353 -0
  10. package/dist/node/cjs/index.js +4493 -0
  11. package/dist/node/cjs/package.json +3 -0
  12. package/dist/node/cjs/serialization.js +2023 -0
  13. package/dist/node/esm/core.js +2317 -0
  14. package/dist/node/esm/index.js +4459 -0
  15. package/dist/node/esm/package.json +3 -0
  16. package/dist/node/esm/serialization.js +1935 -0
  17. package/package.json +72 -0
  18. package/types/Client.d.ts +281 -0
  19. package/types/api/client/index.d.ts +1 -0
  20. package/types/api/client/requests/ActorsCreateRequest.d.ts +23 -0
  21. package/types/api/client/requests/ActorsDeleteRequest.d.ts +12 -0
  22. package/types/api/client/requests/ActorsGetOrCreateRequest.d.ts +23 -0
  23. package/types/api/client/requests/ActorsKvGetRequest.d.ts +12 -0
  24. package/types/api/client/requests/ActorsListNamesRequest.d.ts +14 -0
  25. package/types/api/client/requests/ActorsListRequest.d.ts +23 -0
  26. package/types/api/client/requests/ActorsRescheduleRequest.d.ts +17 -0
  27. package/types/api/client/requests/ActorsSleepRequest.d.ts +17 -0
  28. package/types/api/client/requests/RunnerConfigsDeleteRequest.d.ts +12 -0
  29. package/types/api/client/requests/RunnerConfigsListRequest.d.ts +21 -0
  30. package/types/api/client/requests/RunnerConfigsRefreshMetadataRequest.d.ts +17 -0
  31. package/types/api/client/requests/RunnerConfigsServerlessHealthCheckRequest.d.ts +15 -0
  32. package/types/api/client/requests/RunnerConfigsUpsertRequestBody.d.ts +17 -0
  33. package/types/api/client/requests/index.d.ts +13 -0
  34. package/types/api/index.d.ts +3 -0
  35. package/types/api/resources/datacenters/client/Client.d.ts +36 -0
  36. package/types/api/resources/datacenters/client/index.d.ts +1 -0
  37. package/types/api/resources/datacenters/index.d.ts +1 -0
  38. package/types/api/resources/envoys/client/Client.d.ts +39 -0
  39. package/types/api/resources/envoys/client/index.d.ts +1 -0
  40. package/types/api/resources/envoys/client/requests/EnvoysListRequest.d.ts +16 -0
  41. package/types/api/resources/envoys/client/requests/index.d.ts +1 -0
  42. package/types/api/resources/envoys/index.d.ts +1 -0
  43. package/types/api/resources/health/client/Client.d.ts +36 -0
  44. package/types/api/resources/health/client/index.d.ts +1 -0
  45. package/types/api/resources/health/index.d.ts +1 -0
  46. package/types/api/resources/index.d.ts +9 -0
  47. package/types/api/resources/metadata/client/Client.d.ts +36 -0
  48. package/types/api/resources/metadata/client/index.d.ts +1 -0
  49. package/types/api/resources/metadata/index.d.ts +1 -0
  50. package/types/api/resources/namespaces/client/Client.d.ts +48 -0
  51. package/types/api/resources/namespaces/client/index.d.ts +1 -0
  52. package/types/api/resources/namespaces/client/requests/NamespacesCreateRequest.d.ts +14 -0
  53. package/types/api/resources/namespaces/client/requests/NamespacesListRequest.d.ts +18 -0
  54. package/types/api/resources/namespaces/client/requests/index.d.ts +2 -0
  55. package/types/api/resources/namespaces/index.d.ts +1 -0
  56. package/types/api/resources/runners/client/Client.d.ts +54 -0
  57. package/types/api/resources/runners/client/index.d.ts +1 -0
  58. package/types/api/resources/runners/client/requests/RunnersListNamesRequest.d.ts +14 -0
  59. package/types/api/resources/runners/client/requests/RunnersListRequest.d.ts +22 -0
  60. package/types/api/resources/runners/client/requests/index.d.ts +2 -0
  61. package/types/api/resources/runners/index.d.ts +1 -0
  62. package/types/api/types/Actor.d.ts +32 -0
  63. package/types/api/types/ActorName.d.ts +6 -0
  64. package/types/api/types/ActorsCreateResponse.d.ts +7 -0
  65. package/types/api/types/ActorsDeleteResponse.d.ts +4 -0
  66. package/types/api/types/ActorsGetOrCreateResponse.d.ts +8 -0
  67. package/types/api/types/ActorsKvGetResponse.d.ts +7 -0
  68. package/types/api/types/ActorsListNamesResponse.d.ts +8 -0
  69. package/types/api/types/ActorsListResponse.d.ts +8 -0
  70. package/types/api/types/ActorsRescheduleRequestBody.d.ts +4 -0
  71. package/types/api/types/ActorsRescheduleResponse.d.ts +4 -0
  72. package/types/api/types/ActorsSleepRequestBody.d.ts +4 -0
  73. package/types/api/types/ActorsSleepResponse.d.ts +4 -0
  74. package/types/api/types/CrashPolicy.d.ts +9 -0
  75. package/types/api/types/Datacenter.d.ts +8 -0
  76. package/types/api/types/DatacenterHealth.d.ts +12 -0
  77. package/types/api/types/DatacentersListResponse.d.ts +8 -0
  78. package/types/api/types/Envoy.d.ts +18 -0
  79. package/types/api/types/EnvoysListResponse.d.ts +8 -0
  80. package/types/api/types/HealthFanoutResponse.d.ts +7 -0
  81. package/types/api/types/HealthResponse.d.ts +8 -0
  82. package/types/api/types/HealthStatus.d.ts +8 -0
  83. package/types/api/types/MetadataGetResponse.d.ts +15 -0
  84. package/types/api/types/Namespace.d.ts +10 -0
  85. package/types/api/types/NamespaceListResponse.d.ts +8 -0
  86. package/types/api/types/NamespacesCreateResponse.d.ts +7 -0
  87. package/types/api/types/Pagination.d.ts +6 -0
  88. package/types/api/types/RivetId.d.ts +4 -0
  89. package/types/api/types/Runner.d.ts +21 -0
  90. package/types/api/types/RunnerConfig.d.ts +11 -0
  91. package/types/api/types/RunnerConfigKind.d.ts +5 -0
  92. package/types/api/types/RunnerConfigKindNormal.d.ts +7 -0
  93. package/types/api/types/RunnerConfigKindNormalNormal.d.ts +12 -0
  94. package/types/api/types/RunnerConfigKindServerless.d.ts +7 -0
  95. package/types/api/types/RunnerConfigKindServerlessServerless.d.ts +29 -0
  96. package/types/api/types/RunnerConfigNormal.d.ts +12 -0
  97. package/types/api/types/RunnerConfigResponse.d.ts +8 -0
  98. package/types/api/types/RunnerConfigServerless.d.ts +29 -0
  99. package/types/api/types/RunnerConfigVariant.d.ts +8 -0
  100. package/types/api/types/RunnerConfigsDeleteResponse.d.ts +4 -0
  101. package/types/api/types/RunnerConfigsListResponse.d.ts +8 -0
  102. package/types/api/types/RunnerConfigsListResponseRunnerConfigsValue.d.ts +7 -0
  103. package/types/api/types/RunnerConfigsRefreshMetadataRequestBody.d.ts +4 -0
  104. package/types/api/types/RunnerConfigsRefreshMetadataResponse.d.ts +4 -0
  105. package/types/api/types/RunnerConfigsServerlessHealthCheckResponse.d.ts +5 -0
  106. package/types/api/types/RunnerConfigsServerlessHealthCheckResponseFailure.d.ts +7 -0
  107. package/types/api/types/RunnerConfigsServerlessHealthCheckResponseFailureFailure.d.ts +7 -0
  108. package/types/api/types/RunnerConfigsServerlessHealthCheckResponseSuccess.d.ts +7 -0
  109. package/types/api/types/RunnerConfigsServerlessHealthCheckResponseSuccessSuccess.d.ts +6 -0
  110. package/types/api/types/RunnerConfigsServerlessMetadataError.d.ts +16 -0
  111. package/types/api/types/RunnerConfigsUpsertResponse.d.ts +6 -0
  112. package/types/api/types/RunnersListNamesResponse.d.ts +8 -0
  113. package/types/api/types/RunnersListResponse.d.ts +8 -0
  114. package/types/api/types/index.d.ts +52 -0
  115. package/types/core/auth/BasicAuth.d.ts +8 -0
  116. package/types/core/auth/BearerToken.d.ts +5 -0
  117. package/types/core/auth/index.d.ts +2 -0
  118. package/types/core/fetcher/APIResponse.d.ts +10 -0
  119. package/types/core/fetcher/Fetcher.d.ts +39 -0
  120. package/types/core/fetcher/Supplier.d.ts +4 -0
  121. package/types/core/fetcher/createRequestUrl.d.ts +1 -0
  122. package/types/core/fetcher/getFetchFn.d.ts +4 -0
  123. package/types/core/fetcher/getHeader.d.ts +1 -0
  124. package/types/core/fetcher/getRequestBody.d.ts +7 -0
  125. package/types/core/fetcher/getResponseBody.d.ts +1 -0
  126. package/types/core/fetcher/index.d.ts +5 -0
  127. package/types/core/fetcher/makeRequest.d.ts +1 -0
  128. package/types/core/fetcher/requestWithRetries.d.ts +1 -0
  129. package/types/core/fetcher/signals.d.ts +11 -0
  130. package/types/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +30 -0
  131. package/types/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +21 -0
  132. package/types/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +31 -0
  133. package/types/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +18 -0
  134. package/types/core/index.d.ts +4 -0
  135. package/types/core/json.d.ts +15 -0
  136. package/types/core/runtime/index.d.ts +1 -0
  137. package/types/core/runtime/runtime.d.ts +9 -0
  138. package/types/core/schemas/Schema.d.ts +87 -0
  139. package/types/core/schemas/builders/bigint/bigint.d.ts +2 -0
  140. package/types/core/schemas/builders/bigint/index.d.ts +1 -0
  141. package/types/core/schemas/builders/date/date.d.ts +2 -0
  142. package/types/core/schemas/builders/date/index.d.ts +1 -0
  143. package/types/core/schemas/builders/enum/enum.d.ts +2 -0
  144. package/types/core/schemas/builders/enum/index.d.ts +1 -0
  145. package/types/core/schemas/builders/index.d.ts +14 -0
  146. package/types/core/schemas/builders/lazy/index.d.ts +3 -0
  147. package/types/core/schemas/builders/lazy/lazy.d.ts +5 -0
  148. package/types/core/schemas/builders/lazy/lazyObject.d.ts +3 -0
  149. package/types/core/schemas/builders/list/index.d.ts +1 -0
  150. package/types/core/schemas/builders/list/list.d.ts +2 -0
  151. package/types/core/schemas/builders/literals/booleanLiteral.d.ts +2 -0
  152. package/types/core/schemas/builders/literals/index.d.ts +2 -0
  153. package/types/core/schemas/builders/literals/stringLiteral.d.ts +2 -0
  154. package/types/core/schemas/builders/object/index.d.ts +6 -0
  155. package/types/core/schemas/builders/object/object.d.ts +3 -0
  156. package/types/core/schemas/builders/object/objectWithoutOptionalProperties.d.ts +6 -0
  157. package/types/core/schemas/builders/object/property.d.ts +8 -0
  158. package/types/core/schemas/builders/object/types.d.ts +31 -0
  159. package/types/core/schemas/builders/object-like/getObjectLikeUtils.d.ts +9 -0
  160. package/types/core/schemas/builders/object-like/index.d.ts +2 -0
  161. package/types/core/schemas/builders/object-like/types.d.ts +7 -0
  162. package/types/core/schemas/builders/primitives/any.d.ts +1 -0
  163. package/types/core/schemas/builders/primitives/boolean.d.ts +1 -0
  164. package/types/core/schemas/builders/primitives/index.d.ts +5 -0
  165. package/types/core/schemas/builders/primitives/number.d.ts +1 -0
  166. package/types/core/schemas/builders/primitives/string.d.ts +1 -0
  167. package/types/core/schemas/builders/primitives/unknown.d.ts +1 -0
  168. package/types/core/schemas/builders/record/index.d.ts +2 -0
  169. package/types/core/schemas/builders/record/record.d.ts +3 -0
  170. package/types/core/schemas/builders/record/types.d.ts +4 -0
  171. package/types/core/schemas/builders/schema-utils/JsonError.d.ts +5 -0
  172. package/types/core/schemas/builders/schema-utils/ParseError.d.ts +5 -0
  173. package/types/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +21 -0
  174. package/types/core/schemas/builders/schema-utils/index.d.ts +4 -0
  175. package/types/core/schemas/builders/schema-utils/stringifyValidationErrors.d.ts +2 -0
  176. package/types/core/schemas/builders/set/index.d.ts +1 -0
  177. package/types/core/schemas/builders/set/set.d.ts +2 -0
  178. package/types/core/schemas/builders/undiscriminated-union/index.d.ts +2 -0
  179. package/types/core/schemas/builders/undiscriminated-union/types.d.ts +4 -0
  180. package/types/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.d.ts +3 -0
  181. package/types/core/schemas/builders/union/discriminant.d.ts +5 -0
  182. package/types/core/schemas/builders/union/index.d.ts +4 -0
  183. package/types/core/schemas/builders/union/types.d.ts +13 -0
  184. package/types/core/schemas/builders/union/union.d.ts +4 -0
  185. package/types/core/schemas/index.d.ts +2 -0
  186. package/types/core/schemas/utils/MaybePromise.d.ts +1 -0
  187. package/types/core/schemas/utils/addQuestionMarksToNullableProperties.d.ts +7 -0
  188. package/types/core/schemas/utils/createIdentitySchemaCreator.d.ts +2 -0
  189. package/types/core/schemas/utils/entries.d.ts +1 -0
  190. package/types/core/schemas/utils/filterObject.d.ts +1 -0
  191. package/types/core/schemas/utils/getErrorMessageForIncorrectType.d.ts +1 -0
  192. package/types/core/schemas/utils/isPlainObject.d.ts +1 -0
  193. package/types/core/schemas/utils/keys.d.ts +1 -0
  194. package/types/core/schemas/utils/maybeSkipValidation.d.ts +2 -0
  195. package/types/core/schemas/utils/partition.d.ts +1 -0
  196. package/types/errors/RivetError.d.ts +12 -0
  197. package/types/errors/RivetTimeoutError.d.ts +6 -0
  198. package/types/errors/index.d.ts +2 -0
  199. package/types/index.d.ts +4 -0
  200. package/types/serialization/client/index.d.ts +1 -0
  201. package/types/serialization/client/requests/ActorsCreateRequest.d.ts +18 -0
  202. package/types/serialization/client/requests/ActorsGetOrCreateRequest.d.ts +18 -0
  203. package/types/serialization/client/requests/RunnerConfigsServerlessHealthCheckRequest.d.ts +13 -0
  204. package/types/serialization/client/requests/RunnerConfigsUpsertRequestBody.d.ts +13 -0
  205. package/types/serialization/client/requests/index.d.ts +4 -0
  206. package/types/serialization/index.d.ts +3 -0
  207. package/types/serialization/resources/index.d.ts +2 -0
  208. package/types/serialization/resources/namespaces/client/index.d.ts +1 -0
  209. package/types/serialization/resources/namespaces/client/requests/NamespacesCreateRequest.d.ts +13 -0
  210. package/types/serialization/resources/namespaces/client/requests/index.d.ts +1 -0
  211. package/types/serialization/resources/namespaces/index.d.ts +1 -0
  212. package/types/serialization/types/Actor.d.ts +28 -0
  213. package/types/serialization/types/ActorName.d.ts +12 -0
  214. package/types/serialization/types/ActorsCreateResponse.d.ts +13 -0
  215. package/types/serialization/types/ActorsDeleteResponse.d.ts +10 -0
  216. package/types/serialization/types/ActorsGetOrCreateResponse.d.ts +14 -0
  217. package/types/serialization/types/ActorsKvGetResponse.d.ts +13 -0
  218. package/types/serialization/types/ActorsListNamesResponse.d.ts +15 -0
  219. package/types/serialization/types/ActorsListResponse.d.ts +15 -0
  220. package/types/serialization/types/ActorsRescheduleRequestBody.d.ts +10 -0
  221. package/types/serialization/types/ActorsRescheduleResponse.d.ts +10 -0
  222. package/types/serialization/types/ActorsSleepRequestBody.d.ts +10 -0
  223. package/types/serialization/types/ActorsSleepResponse.d.ts +10 -0
  224. package/types/serialization/types/CrashPolicy.d.ts +10 -0
  225. package/types/serialization/types/Datacenter.d.ts +14 -0
  226. package/types/serialization/types/DatacenterHealth.d.ts +19 -0
  227. package/types/serialization/types/DatacentersListResponse.d.ts +15 -0
  228. package/types/serialization/types/Envoy.d.ts +24 -0
  229. package/types/serialization/types/EnvoysListResponse.d.ts +15 -0
  230. package/types/serialization/types/HealthFanoutResponse.d.ts +13 -0
  231. package/types/serialization/types/HealthResponse.d.ts +14 -0
  232. package/types/serialization/types/HealthStatus.d.ts +10 -0
  233. package/types/serialization/types/MetadataGetResponse.d.ts +21 -0
  234. package/types/serialization/types/Namespace.d.ts +16 -0
  235. package/types/serialization/types/NamespaceListResponse.d.ts +15 -0
  236. package/types/serialization/types/NamespacesCreateResponse.d.ts +13 -0
  237. package/types/serialization/types/Pagination.d.ts +12 -0
  238. package/types/serialization/types/RivetId.d.ts +10 -0
  239. package/types/serialization/types/Runner.d.ts +27 -0
  240. package/types/serialization/types/RunnerConfig.d.ts +17 -0
  241. package/types/serialization/types/RunnerConfigKind.d.ts +12 -0
  242. package/types/serialization/types/RunnerConfigKindNormal.d.ts +13 -0
  243. package/types/serialization/types/RunnerConfigKindNormalNormal.d.ts +15 -0
  244. package/types/serialization/types/RunnerConfigKindServerless.d.ts +13 -0
  245. package/types/serialization/types/RunnerConfigKindServerlessServerless.d.ts +25 -0
  246. package/types/serialization/types/RunnerConfigNormal.d.ts +15 -0
  247. package/types/serialization/types/RunnerConfigResponse.d.ts +14 -0
  248. package/types/serialization/types/RunnerConfigServerless.d.ts +25 -0
  249. package/types/serialization/types/RunnerConfigVariant.d.ts +10 -0
  250. package/types/serialization/types/RunnerConfigsDeleteResponse.d.ts +10 -0
  251. package/types/serialization/types/RunnerConfigsListResponse.d.ts +15 -0
  252. package/types/serialization/types/RunnerConfigsListResponseRunnerConfigsValue.d.ts +13 -0
  253. package/types/serialization/types/RunnerConfigsRefreshMetadataRequestBody.d.ts +10 -0
  254. package/types/serialization/types/RunnerConfigsRefreshMetadataResponse.d.ts +10 -0
  255. package/types/serialization/types/RunnerConfigsServerlessHealthCheckResponse.d.ts +12 -0
  256. package/types/serialization/types/RunnerConfigsServerlessHealthCheckResponseFailure.d.ts +13 -0
  257. package/types/serialization/types/RunnerConfigsServerlessHealthCheckResponseFailureFailure.d.ts +13 -0
  258. package/types/serialization/types/RunnerConfigsServerlessHealthCheckResponseSuccess.d.ts +13 -0
  259. package/types/serialization/types/RunnerConfigsServerlessHealthCheckResponseSuccessSuccess.d.ts +12 -0
  260. package/types/serialization/types/RunnerConfigsServerlessMetadataError.d.ts +14 -0
  261. package/types/serialization/types/RunnerConfigsUpsertResponse.d.ts +12 -0
  262. package/types/serialization/types/RunnersListNamesResponse.d.ts +14 -0
  263. package/types/serialization/types/RunnersListResponse.d.ts +15 -0
  264. package/types/serialization/types/index.d.ts +52 -0
@@ -0,0 +1,4493 @@
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
+ RunnerConfigKindNormalNormal: () => RunnerConfigKindNormalNormal,
2386
+ RunnerConfigKindServerless: () => RunnerConfigKindServerless,
2387
+ RunnerConfigKindServerlessServerless: () => RunnerConfigKindServerlessServerless,
2388
+ RunnerConfigNormal: () => RunnerConfigNormal,
2389
+ RunnerConfigResponse: () => RunnerConfigResponse,
2390
+ RunnerConfigServerless: () => RunnerConfigServerless,
2391
+ RunnerConfigVariant: () => RunnerConfigVariant2,
2392
+ RunnerConfigsDeleteResponse: () => RunnerConfigsDeleteResponse,
2393
+ RunnerConfigsListResponse: () => RunnerConfigsListResponse,
2394
+ RunnerConfigsListResponseRunnerConfigsValue: () => RunnerConfigsListResponseRunnerConfigsValue,
2395
+ RunnerConfigsRefreshMetadataRequestBody: () => RunnerConfigsRefreshMetadataRequestBody,
2396
+ RunnerConfigsRefreshMetadataResponse: () => RunnerConfigsRefreshMetadataResponse,
2397
+ RunnerConfigsServerlessHealthCheckRequest: () => RunnerConfigsServerlessHealthCheckRequest,
2398
+ RunnerConfigsServerlessHealthCheckResponse: () => RunnerConfigsServerlessHealthCheckResponse,
2399
+ RunnerConfigsServerlessHealthCheckResponseFailure: () => RunnerConfigsServerlessHealthCheckResponseFailure,
2400
+ RunnerConfigsServerlessHealthCheckResponseFailureFailure: () => RunnerConfigsServerlessHealthCheckResponseFailureFailure,
2401
+ RunnerConfigsServerlessHealthCheckResponseSuccess: () => RunnerConfigsServerlessHealthCheckResponseSuccess,
2402
+ RunnerConfigsServerlessHealthCheckResponseSuccessSuccess: () => RunnerConfigsServerlessHealthCheckResponseSuccessSuccess,
2403
+ RunnerConfigsServerlessMetadataError: () => RunnerConfigsServerlessMetadataError,
2404
+ RunnerConfigsUpsertRequestBody: () => RunnerConfigsUpsertRequestBody,
2405
+ RunnerConfigsUpsertResponse: () => RunnerConfigsUpsertResponse,
2406
+ RunnersListNamesResponse: () => RunnersListNamesResponse,
2407
+ RunnersListResponse: () => RunnersListResponse,
2408
+ namespaces: () => namespaces_exports2
2409
+ });
2410
+
2411
+ // src/serialization/types/RivetId.ts
2412
+ var RivetId = schemas_exports.string();
2413
+
2414
+ // src/serialization/types/CrashPolicy.ts
2415
+ var CrashPolicy2 = schemas_exports.enum_(["restart", "sleep", "destroy"]);
2416
+
2417
+ // src/serialization/types/Actor.ts
2418
+ var Actor = schemas_exports.object({
2419
+ actorId: schemas_exports.property("actor_id", RivetId),
2420
+ connectableTs: schemas_exports.property("connectable_ts", schemas_exports.number().optional()),
2421
+ crashPolicy: schemas_exports.property("crash_policy", CrashPolicy2),
2422
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2423
+ datacenter: schemas_exports.string(),
2424
+ destroyTs: schemas_exports.property("destroy_ts", schemas_exports.number().optional()),
2425
+ error: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional(),
2426
+ key: schemas_exports.string().optional(),
2427
+ name: schemas_exports.string(),
2428
+ namespaceId: schemas_exports.property("namespace_id", RivetId),
2429
+ pendingAllocationTs: schemas_exports.property("pending_allocation_ts", schemas_exports.number().optional()),
2430
+ rescheduleTs: schemas_exports.property("reschedule_ts", schemas_exports.number().optional()),
2431
+ runnerNameSelector: schemas_exports.property("runner_name_selector", schemas_exports.string()),
2432
+ sleepTs: schemas_exports.property("sleep_ts", schemas_exports.number().optional()),
2433
+ startTs: schemas_exports.property("start_ts", schemas_exports.number().optional())
2434
+ });
2435
+
2436
+ // src/serialization/types/ActorName.ts
2437
+ var ActorName = schemas_exports.object({
2438
+ metadata: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown())
2439
+ });
2440
+
2441
+ // src/serialization/types/ActorsCreateResponse.ts
2442
+ var ActorsCreateResponse = schemas_exports.object({
2443
+ actor: Actor
2444
+ });
2445
+
2446
+ // src/serialization/types/ActorsDeleteResponse.ts
2447
+ var ActorsDeleteResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2448
+
2449
+ // src/serialization/types/ActorsGetOrCreateResponse.ts
2450
+ var ActorsGetOrCreateResponse = schemas_exports.object({
2451
+ actor: Actor,
2452
+ created: schemas_exports.boolean()
2453
+ });
2454
+
2455
+ // src/serialization/types/ActorsKvGetResponse.ts
2456
+ var ActorsKvGetResponse = schemas_exports.object({
2457
+ updateTs: schemas_exports.property("update_ts", schemas_exports.number()),
2458
+ value: schemas_exports.string()
2459
+ });
2460
+
2461
+ // src/serialization/types/Pagination.ts
2462
+ var Pagination = schemas_exports.object({
2463
+ cursor: schemas_exports.string().optional()
2464
+ });
2465
+
2466
+ // src/serialization/types/ActorsListNamesResponse.ts
2467
+ var ActorsListNamesResponse = schemas_exports.object({
2468
+ names: schemas_exports.record(schemas_exports.string(), ActorName),
2469
+ pagination: Pagination
2470
+ });
2471
+
2472
+ // src/serialization/types/ActorsListResponse.ts
2473
+ var ActorsListResponse = schemas_exports.object({
2474
+ actors: schemas_exports.list(Actor),
2475
+ pagination: Pagination
2476
+ });
2477
+
2478
+ // src/serialization/types/ActorsRescheduleRequestBody.ts
2479
+ var ActorsRescheduleRequestBody = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2480
+
2481
+ // src/serialization/types/ActorsRescheduleResponse.ts
2482
+ var ActorsRescheduleResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2483
+
2484
+ // src/serialization/types/ActorsSleepRequestBody.ts
2485
+ var ActorsSleepRequestBody = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2486
+
2487
+ // src/serialization/types/ActorsSleepResponse.ts
2488
+ var ActorsSleepResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2489
+
2490
+ // src/serialization/types/Datacenter.ts
2491
+ var Datacenter = schemas_exports.object({
2492
+ label: schemas_exports.number(),
2493
+ name: schemas_exports.string(),
2494
+ url: schemas_exports.string()
2495
+ });
2496
+
2497
+ // src/serialization/types/HealthResponse.ts
2498
+ var HealthResponse = schemas_exports.object({
2499
+ runtime: schemas_exports.string(),
2500
+ status: schemas_exports.string(),
2501
+ version: schemas_exports.string()
2502
+ });
2503
+
2504
+ // src/serialization/types/HealthStatus.ts
2505
+ var HealthStatus2 = schemas_exports.enum_(["ok", "error"]);
2506
+
2507
+ // src/serialization/types/DatacenterHealth.ts
2508
+ var DatacenterHealth = schemas_exports.object({
2509
+ datacenterLabel: schemas_exports.property("datacenter_label", schemas_exports.number()),
2510
+ datacenterName: schemas_exports.property("datacenter_name", schemas_exports.string()),
2511
+ error: schemas_exports.string().optional(),
2512
+ response: HealthResponse.optional(),
2513
+ rttMs: schemas_exports.property("rtt_ms", schemas_exports.number().optional()),
2514
+ status: HealthStatus2
2515
+ });
2516
+
2517
+ // src/serialization/types/DatacentersListResponse.ts
2518
+ var DatacentersListResponse = schemas_exports.object({
2519
+ datacenters: schemas_exports.list(Datacenter),
2520
+ pagination: Pagination
2521
+ });
2522
+
2523
+ // src/serialization/types/Envoy.ts
2524
+ var Envoy = schemas_exports.object({
2525
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2526
+ datacenter: schemas_exports.string(),
2527
+ envoyKey: schemas_exports.property("envoy_key", schemas_exports.string()),
2528
+ lastConnectedTs: schemas_exports.property("last_connected_ts", schemas_exports.number().optional()),
2529
+ lastPingTs: schemas_exports.property("last_ping_ts", schemas_exports.number()),
2530
+ lastRtt: schemas_exports.property("last_rtt", schemas_exports.number()),
2531
+ metadata: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional(),
2532
+ namespaceId: schemas_exports.property("namespace_id", RivetId),
2533
+ poolName: schemas_exports.property("pool_name", schemas_exports.string()),
2534
+ slots: schemas_exports.number(),
2535
+ stopTs: schemas_exports.property("stop_ts", schemas_exports.number().optional()),
2536
+ version: schemas_exports.number()
2537
+ });
2538
+
2539
+ // src/serialization/types/EnvoysListResponse.ts
2540
+ var EnvoysListResponse = schemas_exports.object({
2541
+ envoys: schemas_exports.list(Envoy),
2542
+ pagination: Pagination
2543
+ });
2544
+
2545
+ // src/serialization/types/HealthFanoutResponse.ts
2546
+ var HealthFanoutResponse = schemas_exports.object({
2547
+ datacenters: schemas_exports.list(DatacenterHealth)
2548
+ });
2549
+
2550
+ // src/serialization/types/MetadataGetResponse.ts
2551
+ var MetadataGetResponse = schemas_exports.object({
2552
+ buildTimestamp: schemas_exports.property("build_timestamp", schemas_exports.string()),
2553
+ cargoProfile: schemas_exports.property("cargo_profile", schemas_exports.string()),
2554
+ cargoTarget: schemas_exports.property("cargo_target", schemas_exports.string()),
2555
+ envoyProtocolVersion: schemas_exports.property("envoy_protocol_version", schemas_exports.number()),
2556
+ epoxyProtocolVersion: schemas_exports.property("epoxy_protocol_version", schemas_exports.number()),
2557
+ gitSha: schemas_exports.property("git_sha", schemas_exports.string()),
2558
+ runtime: schemas_exports.string(),
2559
+ rustcHost: schemas_exports.property("rustc_host", schemas_exports.string()),
2560
+ rustcVersion: schemas_exports.property("rustc_version", schemas_exports.string()),
2561
+ version: schemas_exports.string()
2562
+ });
2563
+
2564
+ // src/serialization/types/Namespace.ts
2565
+ var Namespace = schemas_exports.object({
2566
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2567
+ displayName: schemas_exports.property("display_name", schemas_exports.string()),
2568
+ name: schemas_exports.string(),
2569
+ namespaceId: schemas_exports.property("namespace_id", RivetId)
2570
+ });
2571
+
2572
+ // src/serialization/types/NamespaceListResponse.ts
2573
+ var NamespaceListResponse = schemas_exports.object({
2574
+ namespaces: schemas_exports.list(Namespace),
2575
+ pagination: Pagination
2576
+ });
2577
+
2578
+ // src/serialization/types/NamespacesCreateResponse.ts
2579
+ var NamespacesCreateResponse = schemas_exports.object({
2580
+ namespace: Namespace
2581
+ });
2582
+
2583
+ // src/serialization/types/Runner.ts
2584
+ var Runner = schemas_exports.object({
2585
+ createTs: schemas_exports.property("create_ts", schemas_exports.number()),
2586
+ datacenter: schemas_exports.string(),
2587
+ drainTs: schemas_exports.property("drain_ts", schemas_exports.number().optional()),
2588
+ key: schemas_exports.string(),
2589
+ lastConnectedTs: schemas_exports.property("last_connected_ts", schemas_exports.number().optional()),
2590
+ lastPingTs: schemas_exports.property("last_ping_ts", schemas_exports.number()),
2591
+ lastRtt: schemas_exports.property("last_rtt", schemas_exports.number()),
2592
+ metadata: schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional(),
2593
+ name: schemas_exports.string(),
2594
+ namespaceId: schemas_exports.property("namespace_id", RivetId),
2595
+ remainingSlots: schemas_exports.property("remaining_slots", schemas_exports.number()),
2596
+ runnerId: schemas_exports.property("runner_id", RivetId),
2597
+ stopTs: schemas_exports.property("stop_ts", schemas_exports.number().optional()),
2598
+ totalSlots: schemas_exports.property("total_slots", schemas_exports.number()),
2599
+ version: schemas_exports.number()
2600
+ });
2601
+
2602
+ // src/serialization/types/RunnerConfigNormal.ts
2603
+ var RunnerConfigNormal = schemas_exports.object({
2604
+ actorEvictionDelay: schemas_exports.property("actor_eviction_delay", schemas_exports.number().optional()),
2605
+ actorEvictionPeriod: schemas_exports.property("actor_eviction_period", schemas_exports.number().optional()),
2606
+ actorEvictionRate: schemas_exports.property("actor_eviction_rate", schemas_exports.number().optional()),
2607
+ drainOnVersionUpgrade: schemas_exports.property(
2608
+ "drain_on_version_upgrade",
2609
+ schemas_exports.boolean().optional()
2610
+ )
2611
+ });
2612
+
2613
+ // src/serialization/types/RunnerConfigServerless.ts
2614
+ var RunnerConfigServerless = schemas_exports.object({
2615
+ actorEvictionDelay: schemas_exports.property("actor_eviction_delay", schemas_exports.number().optional()),
2616
+ actorEvictionPeriod: schemas_exports.property("actor_eviction_period", schemas_exports.number().optional()),
2617
+ actorEvictionRate: schemas_exports.property("actor_eviction_rate", schemas_exports.number().optional()),
2618
+ drainGracePeriod: schemas_exports.property("drain_grace_period", schemas_exports.number().optional()),
2619
+ drainOnVersionUpgrade: schemas_exports.property(
2620
+ "drain_on_version_upgrade",
2621
+ schemas_exports.boolean().optional()
2622
+ ),
2623
+ headers: schemas_exports.record(schemas_exports.string(), schemas_exports.string()).optional(),
2624
+ maxConcurrentActors: schemas_exports.property("max_concurrent_actors", schemas_exports.number().optional()),
2625
+ maxRunners: schemas_exports.property("max_runners", schemas_exports.number().optional()),
2626
+ metadataPollInterval: schemas_exports.property("metadata_poll_interval", schemas_exports.number().optional()),
2627
+ minRunners: schemas_exports.property("min_runners", schemas_exports.number().optional()),
2628
+ requestLifespan: schemas_exports.property("request_lifespan", schemas_exports.number()),
2629
+ runnersMargin: schemas_exports.property("runners_margin", schemas_exports.number().optional()),
2630
+ slotsPerRunner: schemas_exports.property("slots_per_runner", schemas_exports.number().optional()),
2631
+ url: schemas_exports.string()
2632
+ });
2633
+
2634
+ // src/serialization/types/RunnerConfig.ts
2635
+ var RunnerConfig = schemas_exports.object({
2636
+ normal: RunnerConfigNormal.optional(),
2637
+ serverless: RunnerConfigServerless.optional(),
2638
+ drainOnVersionUpgrade: schemas_exports.property(
2639
+ "drain_on_version_upgrade",
2640
+ schemas_exports.boolean().optional()
2641
+ ),
2642
+ metadata: schemas_exports.unknown().optional()
2643
+ });
2644
+
2645
+ // src/serialization/types/RunnerConfigKindNormalNormal.ts
2646
+ var RunnerConfigKindNormalNormal = schemas_exports.object({
2647
+ actorEvictionDelay: schemas_exports.property("actor_eviction_delay", schemas_exports.number().optional()),
2648
+ actorEvictionPeriod: schemas_exports.property("actor_eviction_period", schemas_exports.number().optional()),
2649
+ actorEvictionRate: schemas_exports.property("actor_eviction_rate", schemas_exports.number().optional()),
2650
+ drainOnVersionUpgrade: schemas_exports.property(
2651
+ "drain_on_version_upgrade",
2652
+ schemas_exports.boolean().optional()
2653
+ )
2654
+ });
2655
+
2656
+ // src/serialization/types/RunnerConfigKindNormal.ts
2657
+ var RunnerConfigKindNormal = schemas_exports.object({
2658
+ normal: RunnerConfigKindNormalNormal
2659
+ });
2660
+
2661
+ // src/serialization/types/RunnerConfigKindServerlessServerless.ts
2662
+ var RunnerConfigKindServerlessServerless = schemas_exports.object({
2663
+ actorEvictionDelay: schemas_exports.property("actor_eviction_delay", schemas_exports.number().optional()),
2664
+ actorEvictionPeriod: schemas_exports.property("actor_eviction_period", schemas_exports.number().optional()),
2665
+ actorEvictionRate: schemas_exports.property("actor_eviction_rate", schemas_exports.number().optional()),
2666
+ drainGracePeriod: schemas_exports.property("drain_grace_period", schemas_exports.number().optional()),
2667
+ drainOnVersionUpgrade: schemas_exports.property(
2668
+ "drain_on_version_upgrade",
2669
+ schemas_exports.boolean().optional()
2670
+ ),
2671
+ headers: schemas_exports.record(schemas_exports.string(), schemas_exports.string()).optional(),
2672
+ maxConcurrentActors: schemas_exports.property("max_concurrent_actors", schemas_exports.number().optional()),
2673
+ maxRunners: schemas_exports.property("max_runners", schemas_exports.number().optional()),
2674
+ metadataPollInterval: schemas_exports.property("metadata_poll_interval", schemas_exports.number().optional()),
2675
+ minRunners: schemas_exports.property("min_runners", schemas_exports.number().optional()),
2676
+ requestLifespan: schemas_exports.property("request_lifespan", schemas_exports.number()),
2677
+ runnersMargin: schemas_exports.property("runners_margin", schemas_exports.number().optional()),
2678
+ slotsPerRunner: schemas_exports.property("slots_per_runner", schemas_exports.number().optional()),
2679
+ url: schemas_exports.string()
2680
+ });
2681
+
2682
+ // src/serialization/types/RunnerConfigKindServerless.ts
2683
+ var RunnerConfigKindServerless = schemas_exports.object({
2684
+ serverless: RunnerConfigKindServerlessServerless
2685
+ });
2686
+
2687
+ // src/serialization/types/RunnerConfigKind.ts
2688
+ var RunnerConfigKind = schemas_exports.undiscriminatedUnion([RunnerConfigKindNormal, RunnerConfigKindServerless]);
2689
+
2690
+ // src/serialization/types/RunnerConfigResponse.ts
2691
+ var RunnerConfigResponse = schemas_exports.object({
2692
+ protocolVersion: schemas_exports.property("protocol_version", schemas_exports.number().optional()),
2693
+ runnerPoolError: schemas_exports.property(
2694
+ "runner_pool_error",
2695
+ schemas_exports.record(schemas_exports.string(), schemas_exports.unknown()).optional()
2696
+ )
2697
+ }).extend(RunnerConfig);
2698
+
2699
+ // src/serialization/types/RunnerConfigVariant.ts
2700
+ var RunnerConfigVariant2 = schemas_exports.enum_(["serverless", "normal"]);
2701
+
2702
+ // src/serialization/types/RunnerConfigsDeleteResponse.ts
2703
+ var RunnerConfigsDeleteResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2704
+
2705
+ // src/serialization/types/RunnerConfigsListResponseRunnerConfigsValue.ts
2706
+ var RunnerConfigsListResponseRunnerConfigsValue = schemas_exports.object({
2707
+ datacenters: schemas_exports.record(schemas_exports.string(), RunnerConfigResponse)
2708
+ });
2709
+
2710
+ // src/serialization/types/RunnerConfigsListResponse.ts
2711
+ var RunnerConfigsListResponse = schemas_exports.object({
2712
+ pagination: Pagination,
2713
+ runnerConfigs: schemas_exports.property(
2714
+ "runner_configs",
2715
+ schemas_exports.record(schemas_exports.string(), RunnerConfigsListResponseRunnerConfigsValue)
2716
+ )
2717
+ });
2718
+
2719
+ // src/serialization/types/RunnerConfigsRefreshMetadataRequestBody.ts
2720
+ var RunnerConfigsRefreshMetadataRequestBody = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2721
+
2722
+ // src/serialization/types/RunnerConfigsRefreshMetadataResponse.ts
2723
+ var RunnerConfigsRefreshMetadataResponse = schemas_exports.record(schemas_exports.string(), schemas_exports.unknown());
2724
+
2725
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseSuccessSuccess.ts
2726
+ var RunnerConfigsServerlessHealthCheckResponseSuccessSuccess = schemas_exports.object({
2727
+ version: schemas_exports.string()
2728
+ });
2729
+
2730
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseSuccess.ts
2731
+ var RunnerConfigsServerlessHealthCheckResponseSuccess = schemas_exports.object({
2732
+ success: RunnerConfigsServerlessHealthCheckResponseSuccessSuccess
2733
+ });
2734
+
2735
+ // src/serialization/types/RunnerConfigsServerlessMetadataError.ts
2736
+ var RunnerConfigsServerlessMetadataError = schemas_exports.object({
2737
+ details: schemas_exports.string().optional(),
2738
+ message: schemas_exports.string(),
2739
+ metadata: schemas_exports.unknown().optional()
2740
+ });
2741
+
2742
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseFailureFailure.ts
2743
+ var RunnerConfigsServerlessHealthCheckResponseFailureFailure = schemas_exports.object({
2744
+ error: RunnerConfigsServerlessMetadataError
2745
+ });
2746
+
2747
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponseFailure.ts
2748
+ var RunnerConfigsServerlessHealthCheckResponseFailure = schemas_exports.object({
2749
+ failure: RunnerConfigsServerlessHealthCheckResponseFailureFailure
2750
+ });
2751
+
2752
+ // src/serialization/types/RunnerConfigsServerlessHealthCheckResponse.ts
2753
+ var RunnerConfigsServerlessHealthCheckResponse = schemas_exports.undiscriminatedUnion([
2754
+ RunnerConfigsServerlessHealthCheckResponseSuccess,
2755
+ RunnerConfigsServerlessHealthCheckResponseFailure
2756
+ ]);
2757
+
2758
+ // src/serialization/types/RunnerConfigsUpsertResponse.ts
2759
+ var RunnerConfigsUpsertResponse = schemas_exports.object({
2760
+ endpointConfigChanged: schemas_exports.property("endpoint_config_changed", schemas_exports.boolean())
2761
+ });
2762
+
2763
+ // src/serialization/types/RunnersListNamesResponse.ts
2764
+ var RunnersListNamesResponse = schemas_exports.object({
2765
+ names: schemas_exports.list(schemas_exports.string()),
2766
+ pagination: Pagination
2767
+ });
2768
+
2769
+ // src/serialization/types/RunnersListResponse.ts
2770
+ var RunnersListResponse = schemas_exports.object({
2771
+ pagination: Pagination,
2772
+ runners: schemas_exports.list(Runner)
2773
+ });
2774
+
2775
+ // src/serialization/client/requests/ActorsCreateRequest.ts
2776
+ var ActorsCreateRequest = schemas_exports.object({
2777
+ crashPolicy: schemas_exports.property("crash_policy", CrashPolicy2),
2778
+ datacenter: schemas_exports.string().optional(),
2779
+ input: schemas_exports.string().optional(),
2780
+ key: schemas_exports.string().optional(),
2781
+ name: schemas_exports.string(),
2782
+ runnerNameSelector: schemas_exports.property("runner_name_selector", schemas_exports.string())
2783
+ });
2784
+
2785
+ // src/serialization/client/requests/ActorsGetOrCreateRequest.ts
2786
+ var ActorsGetOrCreateRequest = schemas_exports.object({
2787
+ crashPolicy: schemas_exports.property("crash_policy", CrashPolicy2),
2788
+ datacenter: schemas_exports.string().optional(),
2789
+ input: schemas_exports.string().optional(),
2790
+ key: schemas_exports.string(),
2791
+ name: schemas_exports.string(),
2792
+ runnerNameSelector: schemas_exports.property("runner_name_selector", schemas_exports.string())
2793
+ });
2794
+
2795
+ // src/serialization/client/requests/RunnerConfigsServerlessHealthCheckRequest.ts
2796
+ var RunnerConfigsServerlessHealthCheckRequest = schemas_exports.object({
2797
+ headers: schemas_exports.record(schemas_exports.string(), schemas_exports.string()).optional(),
2798
+ url: schemas_exports.string()
2799
+ });
2800
+
2801
+ // src/serialization/client/requests/RunnerConfigsUpsertRequestBody.ts
2802
+ var RunnerConfigsUpsertRequestBody = schemas_exports.object({
2803
+ datacenters: schemas_exports.record(schemas_exports.string(), RunnerConfig)
2804
+ });
2805
+
2806
+ // src/serialization/resources/namespaces/index.ts
2807
+ var namespaces_exports2 = {};
2808
+ __export(namespaces_exports2, {
2809
+ NamespacesCreateRequest: () => NamespacesCreateRequest
2810
+ });
2811
+
2812
+ // src/serialization/resources/namespaces/client/requests/NamespacesCreateRequest.ts
2813
+ var NamespacesCreateRequest = schemas_exports.object({
2814
+ displayName: schemas_exports.property("display_name", schemas_exports.string()),
2815
+ name: schemas_exports.string()
2816
+ });
2817
+
2818
+ // src/Client.ts
2819
+ var import_url_join7 = __toESM(require("url-join"));
2820
+
2821
+ // src/errors/RivetError.ts
2822
+ var RivetError = class _RivetError extends Error {
2823
+ statusCode;
2824
+ body;
2825
+ constructor({ message, statusCode, body }) {
2826
+ super(buildMessage({ message, statusCode, body }));
2827
+ Object.setPrototypeOf(this, _RivetError.prototype);
2828
+ if (statusCode != null) {
2829
+ this.statusCode = statusCode;
2830
+ }
2831
+ if (body !== void 0) {
2832
+ this.body = body;
2833
+ }
2834
+ }
2835
+ };
2836
+ function buildMessage({
2837
+ message,
2838
+ statusCode,
2839
+ body
2840
+ }) {
2841
+ let lines = [];
2842
+ if (message != null) {
2843
+ lines.push(message);
2844
+ }
2845
+ if (statusCode != null) {
2846
+ lines.push(`Status code: ${statusCode.toString()}`);
2847
+ }
2848
+ if (body != null) {
2849
+ lines.push(`Body: ${toJson(body, void 0, 2)}`);
2850
+ }
2851
+ return lines.join("\n");
2852
+ }
2853
+
2854
+ // src/errors/RivetTimeoutError.ts
2855
+ var RivetTimeoutError = class _RivetTimeoutError extends Error {
2856
+ constructor(message) {
2857
+ super(message);
2858
+ Object.setPrototypeOf(this, _RivetTimeoutError.prototype);
2859
+ }
2860
+ };
2861
+
2862
+ // src/api/resources/datacenters/client/Client.ts
2863
+ var import_url_join = __toESM(require("url-join"));
2864
+ var Datacenters = class {
2865
+ constructor(_options) {
2866
+ this._options = _options;
2867
+ }
2868
+ /**
2869
+ * @param {Datacenters.RequestOptions} requestOptions - Request-specific configuration.
2870
+ *
2871
+ * @example
2872
+ * await client.datacenters.list()
2873
+ */
2874
+ async list(requestOptions) {
2875
+ const _response = await (this._options.fetcher ?? fetcher)({
2876
+ url: (0, import_url_join.default)(
2877
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
2878
+ "datacenters"
2879
+ ),
2880
+ method: "GET",
2881
+ headers: {
2882
+ Authorization: await this._getAuthorizationHeader(),
2883
+ "X-Fern-Language": "JavaScript",
2884
+ "X-Fern-Runtime": RUNTIME.type,
2885
+ "X-Fern-Runtime-Version": RUNTIME.version,
2886
+ ...requestOptions == null ? void 0 : requestOptions.headers
2887
+ },
2888
+ contentType: "application/json",
2889
+ requestType: "json",
2890
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
2891
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
2892
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
2893
+ });
2894
+ if (_response.ok) {
2895
+ return DatacentersListResponse.parseOrThrow(_response.body, {
2896
+ unrecognizedObjectKeys: "passthrough",
2897
+ allowUnrecognizedUnionMembers: true,
2898
+ allowUnrecognizedEnumValues: true,
2899
+ skipValidation: true,
2900
+ breadcrumbsPrefix: ["response"]
2901
+ });
2902
+ }
2903
+ if (_response.error.reason === "status-code") {
2904
+ throw new RivetError({
2905
+ statusCode: _response.error.statusCode,
2906
+ body: _response.error.body
2907
+ });
2908
+ }
2909
+ switch (_response.error.reason) {
2910
+ case "non-json":
2911
+ throw new RivetError({
2912
+ statusCode: _response.error.statusCode,
2913
+ body: _response.error.rawBody
2914
+ });
2915
+ case "timeout":
2916
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /datacenters.");
2917
+ case "unknown":
2918
+ throw new RivetError({
2919
+ message: _response.error.errorMessage
2920
+ });
2921
+ }
2922
+ }
2923
+ async _getAuthorizationHeader() {
2924
+ return `Bearer ${await Supplier.get(this._options.token)}`;
2925
+ }
2926
+ };
2927
+
2928
+ // src/api/resources/envoys/client/Client.ts
2929
+ var import_url_join2 = __toESM(require("url-join"));
2930
+ var Envoys = class {
2931
+ constructor(_options) {
2932
+ this._options = _options;
2933
+ }
2934
+ /**
2935
+ * @param {Rivet.EnvoysListRequest} request
2936
+ * @param {Envoys.RequestOptions} requestOptions - Request-specific configuration.
2937
+ *
2938
+ * @example
2939
+ * await client.envoys.list({
2940
+ * namespace: "namespace"
2941
+ * })
2942
+ */
2943
+ async list(request, requestOptions) {
2944
+ const { namespace, name, envoyKey, limit, cursor } = request;
2945
+ const _queryParams = {};
2946
+ _queryParams["namespace"] = namespace;
2947
+ if (name != null) {
2948
+ _queryParams["name"] = name;
2949
+ }
2950
+ if (envoyKey != null) {
2951
+ if (Array.isArray(envoyKey)) {
2952
+ _queryParams["envoy_key"] = envoyKey.map((item) => item);
2953
+ } else {
2954
+ _queryParams["envoy_key"] = envoyKey;
2955
+ }
2956
+ }
2957
+ if (limit != null) {
2958
+ _queryParams["limit"] = limit.toString();
2959
+ }
2960
+ if (cursor != null) {
2961
+ _queryParams["cursor"] = cursor;
2962
+ }
2963
+ const _response = await (this._options.fetcher ?? fetcher)({
2964
+ url: (0, import_url_join2.default)(
2965
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
2966
+ "envoys"
2967
+ ),
2968
+ method: "GET",
2969
+ headers: {
2970
+ Authorization: await this._getAuthorizationHeader(),
2971
+ "X-Fern-Language": "JavaScript",
2972
+ "X-Fern-Runtime": RUNTIME.type,
2973
+ "X-Fern-Runtime-Version": RUNTIME.version,
2974
+ ...requestOptions == null ? void 0 : requestOptions.headers
2975
+ },
2976
+ contentType: "application/json",
2977
+ queryParameters: _queryParams,
2978
+ requestType: "json",
2979
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
2980
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
2981
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
2982
+ });
2983
+ if (_response.ok) {
2984
+ return EnvoysListResponse.parseOrThrow(_response.body, {
2985
+ unrecognizedObjectKeys: "passthrough",
2986
+ allowUnrecognizedUnionMembers: true,
2987
+ allowUnrecognizedEnumValues: true,
2988
+ skipValidation: true,
2989
+ breadcrumbsPrefix: ["response"]
2990
+ });
2991
+ }
2992
+ if (_response.error.reason === "status-code") {
2993
+ throw new RivetError({
2994
+ statusCode: _response.error.statusCode,
2995
+ body: _response.error.body
2996
+ });
2997
+ }
2998
+ switch (_response.error.reason) {
2999
+ case "non-json":
3000
+ throw new RivetError({
3001
+ statusCode: _response.error.statusCode,
3002
+ body: _response.error.rawBody
3003
+ });
3004
+ case "timeout":
3005
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /envoys.");
3006
+ case "unknown":
3007
+ throw new RivetError({
3008
+ message: _response.error.errorMessage
3009
+ });
3010
+ }
3011
+ }
3012
+ async _getAuthorizationHeader() {
3013
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3014
+ }
3015
+ };
3016
+
3017
+ // src/api/resources/health/client/Client.ts
3018
+ var import_url_join3 = __toESM(require("url-join"));
3019
+ var Health = class {
3020
+ constructor(_options) {
3021
+ this._options = _options;
3022
+ }
3023
+ /**
3024
+ * @param {Health.RequestOptions} requestOptions - Request-specific configuration.
3025
+ *
3026
+ * @example
3027
+ * await client.health.fanout()
3028
+ */
3029
+ async fanout(requestOptions) {
3030
+ const _response = await (this._options.fetcher ?? fetcher)({
3031
+ url: (0, import_url_join3.default)(
3032
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3033
+ "health/fanout"
3034
+ ),
3035
+ method: "GET",
3036
+ headers: {
3037
+ Authorization: await this._getAuthorizationHeader(),
3038
+ "X-Fern-Language": "JavaScript",
3039
+ "X-Fern-Runtime": RUNTIME.type,
3040
+ "X-Fern-Runtime-Version": RUNTIME.version,
3041
+ ...requestOptions == null ? void 0 : requestOptions.headers
3042
+ },
3043
+ contentType: "application/json",
3044
+ requestType: "json",
3045
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3046
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3047
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3048
+ });
3049
+ if (_response.ok) {
3050
+ return HealthFanoutResponse.parseOrThrow(_response.body, {
3051
+ unrecognizedObjectKeys: "passthrough",
3052
+ allowUnrecognizedUnionMembers: true,
3053
+ allowUnrecognizedEnumValues: true,
3054
+ skipValidation: true,
3055
+ breadcrumbsPrefix: ["response"]
3056
+ });
3057
+ }
3058
+ if (_response.error.reason === "status-code") {
3059
+ throw new RivetError({
3060
+ statusCode: _response.error.statusCode,
3061
+ body: _response.error.body
3062
+ });
3063
+ }
3064
+ switch (_response.error.reason) {
3065
+ case "non-json":
3066
+ throw new RivetError({
3067
+ statusCode: _response.error.statusCode,
3068
+ body: _response.error.rawBody
3069
+ });
3070
+ case "timeout":
3071
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /health/fanout.");
3072
+ case "unknown":
3073
+ throw new RivetError({
3074
+ message: _response.error.errorMessage
3075
+ });
3076
+ }
3077
+ }
3078
+ async _getAuthorizationHeader() {
3079
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3080
+ }
3081
+ };
3082
+
3083
+ // src/api/resources/metadata/client/Client.ts
3084
+ var import_url_join4 = __toESM(require("url-join"));
3085
+ var Metadata = class {
3086
+ constructor(_options) {
3087
+ this._options = _options;
3088
+ }
3089
+ /**
3090
+ * @param {Metadata.RequestOptions} requestOptions - Request-specific configuration.
3091
+ *
3092
+ * @example
3093
+ * await client.metadata.get()
3094
+ */
3095
+ async get(requestOptions) {
3096
+ const _response = await (this._options.fetcher ?? fetcher)({
3097
+ url: (0, import_url_join4.default)(
3098
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3099
+ "metadata"
3100
+ ),
3101
+ method: "GET",
3102
+ headers: {
3103
+ Authorization: await this._getAuthorizationHeader(),
3104
+ "X-Fern-Language": "JavaScript",
3105
+ "X-Fern-Runtime": RUNTIME.type,
3106
+ "X-Fern-Runtime-Version": RUNTIME.version,
3107
+ ...requestOptions == null ? void 0 : requestOptions.headers
3108
+ },
3109
+ contentType: "application/json",
3110
+ requestType: "json",
3111
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3112
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3113
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3114
+ });
3115
+ if (_response.ok) {
3116
+ return MetadataGetResponse.parseOrThrow(_response.body, {
3117
+ unrecognizedObjectKeys: "passthrough",
3118
+ allowUnrecognizedUnionMembers: true,
3119
+ allowUnrecognizedEnumValues: true,
3120
+ skipValidation: true,
3121
+ breadcrumbsPrefix: ["response"]
3122
+ });
3123
+ }
3124
+ if (_response.error.reason === "status-code") {
3125
+ throw new RivetError({
3126
+ statusCode: _response.error.statusCode,
3127
+ body: _response.error.body
3128
+ });
3129
+ }
3130
+ switch (_response.error.reason) {
3131
+ case "non-json":
3132
+ throw new RivetError({
3133
+ statusCode: _response.error.statusCode,
3134
+ body: _response.error.rawBody
3135
+ });
3136
+ case "timeout":
3137
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /metadata.");
3138
+ case "unknown":
3139
+ throw new RivetError({
3140
+ message: _response.error.errorMessage
3141
+ });
3142
+ }
3143
+ }
3144
+ async _getAuthorizationHeader() {
3145
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3146
+ }
3147
+ };
3148
+
3149
+ // src/api/resources/namespaces/client/Client.ts
3150
+ var import_url_join5 = __toESM(require("url-join"));
3151
+ var Namespaces = class {
3152
+ constructor(_options) {
3153
+ this._options = _options;
3154
+ }
3155
+ /**
3156
+ * @param {Rivet.NamespacesListRequest} request
3157
+ * @param {Namespaces.RequestOptions} requestOptions - Request-specific configuration.
3158
+ *
3159
+ * @example
3160
+ * await client.namespaces.list()
3161
+ */
3162
+ async list(request = {}, requestOptions) {
3163
+ const { limit, cursor, name, namespaceIds, namespaceId } = request;
3164
+ const _queryParams = {};
3165
+ if (limit != null) {
3166
+ _queryParams["limit"] = limit.toString();
3167
+ }
3168
+ if (cursor != null) {
3169
+ _queryParams["cursor"] = cursor;
3170
+ }
3171
+ if (name != null) {
3172
+ _queryParams["name"] = name;
3173
+ }
3174
+ if (namespaceIds != null) {
3175
+ _queryParams["namespace_ids"] = namespaceIds;
3176
+ }
3177
+ if (namespaceId != null) {
3178
+ if (Array.isArray(namespaceId)) {
3179
+ _queryParams["namespace_id"] = namespaceId.map(
3180
+ (item) => RivetId.jsonOrThrow(item, { unrecognizedObjectKeys: "strip" })
3181
+ );
3182
+ } else {
3183
+ _queryParams["namespace_id"] = namespaceId;
3184
+ }
3185
+ }
3186
+ const _response = await (this._options.fetcher ?? fetcher)({
3187
+ url: (0, import_url_join5.default)(
3188
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3189
+ "namespaces"
3190
+ ),
3191
+ method: "GET",
3192
+ headers: {
3193
+ Authorization: await this._getAuthorizationHeader(),
3194
+ "X-Fern-Language": "JavaScript",
3195
+ "X-Fern-Runtime": RUNTIME.type,
3196
+ "X-Fern-Runtime-Version": RUNTIME.version,
3197
+ ...requestOptions == null ? void 0 : requestOptions.headers
3198
+ },
3199
+ contentType: "application/json",
3200
+ queryParameters: _queryParams,
3201
+ requestType: "json",
3202
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3203
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3204
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3205
+ });
3206
+ if (_response.ok) {
3207
+ return NamespaceListResponse.parseOrThrow(_response.body, {
3208
+ unrecognizedObjectKeys: "passthrough",
3209
+ allowUnrecognizedUnionMembers: true,
3210
+ allowUnrecognizedEnumValues: true,
3211
+ skipValidation: true,
3212
+ breadcrumbsPrefix: ["response"]
3213
+ });
3214
+ }
3215
+ if (_response.error.reason === "status-code") {
3216
+ throw new RivetError({
3217
+ statusCode: _response.error.statusCode,
3218
+ body: _response.error.body
3219
+ });
3220
+ }
3221
+ switch (_response.error.reason) {
3222
+ case "non-json":
3223
+ throw new RivetError({
3224
+ statusCode: _response.error.statusCode,
3225
+ body: _response.error.rawBody
3226
+ });
3227
+ case "timeout":
3228
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /namespaces.");
3229
+ case "unknown":
3230
+ throw new RivetError({
3231
+ message: _response.error.errorMessage
3232
+ });
3233
+ }
3234
+ }
3235
+ /**
3236
+ * @param {Rivet.NamespacesCreateRequest} request
3237
+ * @param {Namespaces.RequestOptions} requestOptions - Request-specific configuration.
3238
+ *
3239
+ * @example
3240
+ * await client.namespaces.create({
3241
+ * displayName: "display_name",
3242
+ * name: "name"
3243
+ * })
3244
+ */
3245
+ async create(request, requestOptions) {
3246
+ const _response = await (this._options.fetcher ?? fetcher)({
3247
+ url: (0, import_url_join5.default)(
3248
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3249
+ "namespaces"
3250
+ ),
3251
+ method: "POST",
3252
+ headers: {
3253
+ Authorization: await this._getAuthorizationHeader(),
3254
+ "X-Fern-Language": "JavaScript",
3255
+ "X-Fern-Runtime": RUNTIME.type,
3256
+ "X-Fern-Runtime-Version": RUNTIME.version,
3257
+ ...requestOptions == null ? void 0 : requestOptions.headers
3258
+ },
3259
+ contentType: "application/json",
3260
+ requestType: "json",
3261
+ body: NamespacesCreateRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
3262
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3263
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3264
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3265
+ });
3266
+ if (_response.ok) {
3267
+ return NamespacesCreateResponse.parseOrThrow(_response.body, {
3268
+ unrecognizedObjectKeys: "passthrough",
3269
+ allowUnrecognizedUnionMembers: true,
3270
+ allowUnrecognizedEnumValues: true,
3271
+ skipValidation: true,
3272
+ breadcrumbsPrefix: ["response"]
3273
+ });
3274
+ }
3275
+ if (_response.error.reason === "status-code") {
3276
+ throw new RivetError({
3277
+ statusCode: _response.error.statusCode,
3278
+ body: _response.error.body
3279
+ });
3280
+ }
3281
+ switch (_response.error.reason) {
3282
+ case "non-json":
3283
+ throw new RivetError({
3284
+ statusCode: _response.error.statusCode,
3285
+ body: _response.error.rawBody
3286
+ });
3287
+ case "timeout":
3288
+ throw new RivetTimeoutError("Timeout exceeded when calling POST /namespaces.");
3289
+ case "unknown":
3290
+ throw new RivetError({
3291
+ message: _response.error.errorMessage
3292
+ });
3293
+ }
3294
+ }
3295
+ async _getAuthorizationHeader() {
3296
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3297
+ }
3298
+ };
3299
+
3300
+ // src/api/resources/runners/client/Client.ts
3301
+ var import_url_join6 = __toESM(require("url-join"));
3302
+ var Runners = class {
3303
+ constructor(_options) {
3304
+ this._options = _options;
3305
+ }
3306
+ /**
3307
+ * @param {Rivet.RunnersListRequest} request
3308
+ * @param {Runners.RequestOptions} requestOptions - Request-specific configuration.
3309
+ *
3310
+ * @example
3311
+ * await client.runners.list({
3312
+ * namespace: "namespace"
3313
+ * })
3314
+ */
3315
+ async list(request, requestOptions) {
3316
+ const { namespace, name, runnerIds, runnerId, includeStopped, limit, cursor } = request;
3317
+ const _queryParams = {};
3318
+ _queryParams["namespace"] = namespace;
3319
+ if (name != null) {
3320
+ _queryParams["name"] = name;
3321
+ }
3322
+ if (runnerIds != null) {
3323
+ _queryParams["runner_ids"] = runnerIds;
3324
+ }
3325
+ if (runnerId != null) {
3326
+ if (Array.isArray(runnerId)) {
3327
+ _queryParams["runner_id"] = runnerId.map(
3328
+ (item) => RivetId.jsonOrThrow(item, { unrecognizedObjectKeys: "strip" })
3329
+ );
3330
+ } else {
3331
+ _queryParams["runner_id"] = runnerId;
3332
+ }
3333
+ }
3334
+ if (includeStopped != null) {
3335
+ _queryParams["include_stopped"] = includeStopped.toString();
3336
+ }
3337
+ if (limit != null) {
3338
+ _queryParams["limit"] = limit.toString();
3339
+ }
3340
+ if (cursor != null) {
3341
+ _queryParams["cursor"] = cursor;
3342
+ }
3343
+ const _response = await (this._options.fetcher ?? fetcher)({
3344
+ url: (0, import_url_join6.default)(
3345
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3346
+ "runners"
3347
+ ),
3348
+ method: "GET",
3349
+ headers: {
3350
+ Authorization: await this._getAuthorizationHeader(),
3351
+ "X-Fern-Language": "JavaScript",
3352
+ "X-Fern-Runtime": RUNTIME.type,
3353
+ "X-Fern-Runtime-Version": RUNTIME.version,
3354
+ ...requestOptions == null ? void 0 : requestOptions.headers
3355
+ },
3356
+ contentType: "application/json",
3357
+ queryParameters: _queryParams,
3358
+ requestType: "json",
3359
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3360
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3361
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3362
+ });
3363
+ if (_response.ok) {
3364
+ return RunnersListResponse.parseOrThrow(_response.body, {
3365
+ unrecognizedObjectKeys: "passthrough",
3366
+ allowUnrecognizedUnionMembers: true,
3367
+ allowUnrecognizedEnumValues: true,
3368
+ skipValidation: true,
3369
+ breadcrumbsPrefix: ["response"]
3370
+ });
3371
+ }
3372
+ if (_response.error.reason === "status-code") {
3373
+ throw new RivetError({
3374
+ statusCode: _response.error.statusCode,
3375
+ body: _response.error.body
3376
+ });
3377
+ }
3378
+ switch (_response.error.reason) {
3379
+ case "non-json":
3380
+ throw new RivetError({
3381
+ statusCode: _response.error.statusCode,
3382
+ body: _response.error.rawBody
3383
+ });
3384
+ case "timeout":
3385
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /runners.");
3386
+ case "unknown":
3387
+ throw new RivetError({
3388
+ message: _response.error.errorMessage
3389
+ });
3390
+ }
3391
+ }
3392
+ /**
3393
+ * 2 round trips:
3394
+ *
3395
+ * - GET /runners/names (fanout)
3396
+ * - [api-peer] namespace::ops::resolve_for_name_global
3397
+ *
3398
+ * @param {Rivet.RunnersListNamesRequest} request
3399
+ * @param {Runners.RequestOptions} requestOptions - Request-specific configuration.
3400
+ *
3401
+ * @example
3402
+ * await client.runners.listNames({
3403
+ * namespace: "namespace"
3404
+ * })
3405
+ */
3406
+ async listNames(request, requestOptions) {
3407
+ const { namespace, limit, cursor } = request;
3408
+ const _queryParams = {};
3409
+ _queryParams["namespace"] = namespace;
3410
+ if (limit != null) {
3411
+ _queryParams["limit"] = limit.toString();
3412
+ }
3413
+ if (cursor != null) {
3414
+ _queryParams["cursor"] = cursor;
3415
+ }
3416
+ const _response = await (this._options.fetcher ?? fetcher)({
3417
+ url: (0, import_url_join6.default)(
3418
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3419
+ "runners/names"
3420
+ ),
3421
+ method: "GET",
3422
+ headers: {
3423
+ Authorization: await this._getAuthorizationHeader(),
3424
+ "X-Fern-Language": "JavaScript",
3425
+ "X-Fern-Runtime": RUNTIME.type,
3426
+ "X-Fern-Runtime-Version": RUNTIME.version,
3427
+ ...requestOptions == null ? void 0 : requestOptions.headers
3428
+ },
3429
+ contentType: "application/json",
3430
+ queryParameters: _queryParams,
3431
+ requestType: "json",
3432
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3433
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3434
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3435
+ });
3436
+ if (_response.ok) {
3437
+ return RunnersListNamesResponse.parseOrThrow(_response.body, {
3438
+ unrecognizedObjectKeys: "passthrough",
3439
+ allowUnrecognizedUnionMembers: true,
3440
+ allowUnrecognizedEnumValues: true,
3441
+ skipValidation: true,
3442
+ breadcrumbsPrefix: ["response"]
3443
+ });
3444
+ }
3445
+ if (_response.error.reason === "status-code") {
3446
+ throw new RivetError({
3447
+ statusCode: _response.error.statusCode,
3448
+ body: _response.error.body
3449
+ });
3450
+ }
3451
+ switch (_response.error.reason) {
3452
+ case "non-json":
3453
+ throw new RivetError({
3454
+ statusCode: _response.error.statusCode,
3455
+ body: _response.error.rawBody
3456
+ });
3457
+ case "timeout":
3458
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /runners/names.");
3459
+ case "unknown":
3460
+ throw new RivetError({
3461
+ message: _response.error.errorMessage
3462
+ });
3463
+ }
3464
+ }
3465
+ async _getAuthorizationHeader() {
3466
+ return `Bearer ${await Supplier.get(this._options.token)}`;
3467
+ }
3468
+ };
3469
+
3470
+ // src/Client.ts
3471
+ var RivetClient = class {
3472
+ constructor(_options) {
3473
+ this._options = _options;
3474
+ }
3475
+ _datacenters;
3476
+ _envoys;
3477
+ _health;
3478
+ _metadata;
3479
+ _namespaces;
3480
+ _runners;
3481
+ get datacenters() {
3482
+ return this._datacenters ?? (this._datacenters = new Datacenters(this._options));
3483
+ }
3484
+ get envoys() {
3485
+ return this._envoys ?? (this._envoys = new Envoys(this._options));
3486
+ }
3487
+ get health() {
3488
+ return this._health ?? (this._health = new Health(this._options));
3489
+ }
3490
+ get metadata() {
3491
+ return this._metadata ?? (this._metadata = new Metadata(this._options));
3492
+ }
3493
+ get namespaces() {
3494
+ return this._namespaces ?? (this._namespaces = new Namespaces(this._options));
3495
+ }
3496
+ get runners() {
3497
+ return this._runners ?? (this._runners = new Runners(this._options));
3498
+ }
3499
+ /**
3500
+ * **If key is some & `include_destroyed` is false**
3501
+ *
3502
+ * 2 round trips:
3503
+ *
3504
+ * - namespace::ops::resolve_for_name_global
3505
+ * - GET /actors (multiple DCs based on actor IDs)
3506
+ *
3507
+ * This path is optimized because we can read the actor IDs fro the key directly from Epoxy with
3508
+ * stale consistency to determine which datacenter the actor lives in. Under most circumstances,
3509
+ * this means we don't need to fan out to all datacenters (like normal list does).
3510
+ *
3511
+ * The reason `include_destroyed` has to be false is Epoxy only stores currently active actors. If
3512
+ * `include_destroyed` is true, we show all previous iterations of actors with the same key.
3513
+ *
3514
+ * **Otherwise**
3515
+ *
3516
+ * 2 round trips:
3517
+ *
3518
+ * - namespace::ops::resolve_for_name_global
3519
+ * - GET /actors (fanout)
3520
+ *
3521
+ * ## Optimized Alternative Routes
3522
+ *
3523
+ * @param {Rivet.ActorsListRequest} request
3524
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3525
+ *
3526
+ * @example
3527
+ * await client.actorsList({
3528
+ * namespace: "namespace"
3529
+ * })
3530
+ */
3531
+ async actorsList(request, requestOptions) {
3532
+ const { namespace, name, key, actorIds, actorId, includeDestroyed, limit, cursor } = request;
3533
+ const _queryParams = {};
3534
+ _queryParams["namespace"] = namespace;
3535
+ if (name != null) {
3536
+ _queryParams["name"] = name;
3537
+ }
3538
+ if (key != null) {
3539
+ _queryParams["key"] = key;
3540
+ }
3541
+ if (actorIds != null) {
3542
+ _queryParams["actor_ids"] = actorIds;
3543
+ }
3544
+ if (actorId != null) {
3545
+ if (Array.isArray(actorId)) {
3546
+ _queryParams["actor_id"] = actorId.map(
3547
+ (item) => RivetId.jsonOrThrow(item, { unrecognizedObjectKeys: "strip" })
3548
+ );
3549
+ } else {
3550
+ _queryParams["actor_id"] = actorId;
3551
+ }
3552
+ }
3553
+ if (includeDestroyed != null) {
3554
+ _queryParams["include_destroyed"] = includeDestroyed.toString();
3555
+ }
3556
+ if (limit != null) {
3557
+ _queryParams["limit"] = limit.toString();
3558
+ }
3559
+ if (cursor != null) {
3560
+ _queryParams["cursor"] = cursor;
3561
+ }
3562
+ const _response = await (this._options.fetcher ?? fetcher)({
3563
+ url: (0, import_url_join7.default)(
3564
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3565
+ "actors"
3566
+ ),
3567
+ method: "GET",
3568
+ headers: {
3569
+ Authorization: await this._getAuthorizationHeader(),
3570
+ "X-Fern-Language": "JavaScript",
3571
+ "X-Fern-Runtime": RUNTIME.type,
3572
+ "X-Fern-Runtime-Version": RUNTIME.version,
3573
+ ...requestOptions == null ? void 0 : requestOptions.headers
3574
+ },
3575
+ contentType: "application/json",
3576
+ queryParameters: _queryParams,
3577
+ requestType: "json",
3578
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3579
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3580
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3581
+ });
3582
+ if (_response.ok) {
3583
+ return ActorsListResponse.parseOrThrow(_response.body, {
3584
+ unrecognizedObjectKeys: "passthrough",
3585
+ allowUnrecognizedUnionMembers: true,
3586
+ allowUnrecognizedEnumValues: true,
3587
+ skipValidation: true,
3588
+ breadcrumbsPrefix: ["response"]
3589
+ });
3590
+ }
3591
+ if (_response.error.reason === "status-code") {
3592
+ throw new RivetError({
3593
+ statusCode: _response.error.statusCode,
3594
+ body: _response.error.body
3595
+ });
3596
+ }
3597
+ switch (_response.error.reason) {
3598
+ case "non-json":
3599
+ throw new RivetError({
3600
+ statusCode: _response.error.statusCode,
3601
+ body: _response.error.rawBody
3602
+ });
3603
+ case "timeout":
3604
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /actors.");
3605
+ case "unknown":
3606
+ throw new RivetError({
3607
+ message: _response.error.errorMessage
3608
+ });
3609
+ }
3610
+ }
3611
+ /**
3612
+ * **If actor is created in the current datacenter:**
3613
+ *
3614
+ * 2 round trips:
3615
+ *
3616
+ * - namespace::ops::resolve_for_name_global
3617
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3618
+ *
3619
+ * **If actor is created in a different datacenter:**
3620
+ *
3621
+ * 3 round trips:
3622
+ *
3623
+ * - namespace::ops::resolve_for_name_global
3624
+ * - POST /actors to remote datacenter
3625
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3626
+ *
3627
+ * actor::get will always be in the same datacenter.
3628
+ *
3629
+ * @param {Rivet.ActorsCreateRequest} request
3630
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3631
+ *
3632
+ * @example
3633
+ * await client.actorsCreate({
3634
+ * namespace: "namespace",
3635
+ * crashPolicy: "restart",
3636
+ * name: "name",
3637
+ * runnerNameSelector: "runner_name_selector"
3638
+ * })
3639
+ */
3640
+ async actorsCreate(request, requestOptions) {
3641
+ const { namespace, ..._body } = request;
3642
+ const _queryParams = {};
3643
+ _queryParams["namespace"] = namespace;
3644
+ const _response = await (this._options.fetcher ?? fetcher)({
3645
+ url: (0, import_url_join7.default)(
3646
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3647
+ "actors"
3648
+ ),
3649
+ method: "POST",
3650
+ headers: {
3651
+ Authorization: await this._getAuthorizationHeader(),
3652
+ "X-Fern-Language": "JavaScript",
3653
+ "X-Fern-Runtime": RUNTIME.type,
3654
+ "X-Fern-Runtime-Version": RUNTIME.version,
3655
+ ...requestOptions == null ? void 0 : requestOptions.headers
3656
+ },
3657
+ contentType: "application/json",
3658
+ queryParameters: _queryParams,
3659
+ requestType: "json",
3660
+ body: ActorsCreateRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
3661
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3662
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3663
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3664
+ });
3665
+ if (_response.ok) {
3666
+ return ActorsCreateResponse.parseOrThrow(_response.body, {
3667
+ unrecognizedObjectKeys: "passthrough",
3668
+ allowUnrecognizedUnionMembers: true,
3669
+ allowUnrecognizedEnumValues: true,
3670
+ skipValidation: true,
3671
+ breadcrumbsPrefix: ["response"]
3672
+ });
3673
+ }
3674
+ if (_response.error.reason === "status-code") {
3675
+ throw new RivetError({
3676
+ statusCode: _response.error.statusCode,
3677
+ body: _response.error.body
3678
+ });
3679
+ }
3680
+ switch (_response.error.reason) {
3681
+ case "non-json":
3682
+ throw new RivetError({
3683
+ statusCode: _response.error.statusCode,
3684
+ body: _response.error.rawBody
3685
+ });
3686
+ case "timeout":
3687
+ throw new RivetTimeoutError("Timeout exceeded when calling POST /actors.");
3688
+ case "unknown":
3689
+ throw new RivetError({
3690
+ message: _response.error.errorMessage
3691
+ });
3692
+ }
3693
+ }
3694
+ /**
3695
+ * **If actor exists**
3696
+ *
3697
+ * 2 round trips:
3698
+ *
3699
+ * - namespace::ops::resolve_for_name_global
3700
+ * - GET /actors/{}
3701
+ *
3702
+ * **If actor does not exist and is created in the current datacenter:**
3703
+ *
3704
+ * 2 round trips:
3705
+ *
3706
+ * - namespace::ops::resolve_for_name_global
3707
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3708
+ *
3709
+ * **If actor does not exist and is created in a different datacenter:**
3710
+ *
3711
+ * 3 round trips:
3712
+ *
3713
+ * - namespace::ops::resolve_for_name_global
3714
+ * - POST /actors to remote datacenter
3715
+ * - [pegboard::workflows::actor] Create actor workflow (includes Epoxy key allocation)
3716
+ *
3717
+ * actor::get will always be in the same datacenter.
3718
+ *
3719
+ * ## Optimized Alternative Routes
3720
+ *
3721
+ * @param {Rivet.ActorsGetOrCreateRequest} request
3722
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3723
+ *
3724
+ * @example
3725
+ * await client.actorsGetOrCreate({
3726
+ * namespace: "namespace",
3727
+ * crashPolicy: "restart",
3728
+ * key: "key",
3729
+ * name: "name",
3730
+ * runnerNameSelector: "runner_name_selector"
3731
+ * })
3732
+ */
3733
+ async actorsGetOrCreate(request, requestOptions) {
3734
+ const { namespace, ..._body } = request;
3735
+ const _queryParams = {};
3736
+ _queryParams["namespace"] = namespace;
3737
+ const _response = await (this._options.fetcher ?? fetcher)({
3738
+ url: (0, import_url_join7.default)(
3739
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3740
+ "actors"
3741
+ ),
3742
+ method: "PUT",
3743
+ headers: {
3744
+ Authorization: await this._getAuthorizationHeader(),
3745
+ "X-Fern-Language": "JavaScript",
3746
+ "X-Fern-Runtime": RUNTIME.type,
3747
+ "X-Fern-Runtime-Version": RUNTIME.version,
3748
+ ...requestOptions == null ? void 0 : requestOptions.headers
3749
+ },
3750
+ contentType: "application/json",
3751
+ queryParameters: _queryParams,
3752
+ requestType: "json",
3753
+ body: ActorsGetOrCreateRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
3754
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3755
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3756
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3757
+ });
3758
+ if (_response.ok) {
3759
+ return ActorsGetOrCreateResponse.parseOrThrow(_response.body, {
3760
+ unrecognizedObjectKeys: "passthrough",
3761
+ allowUnrecognizedUnionMembers: true,
3762
+ allowUnrecognizedEnumValues: true,
3763
+ skipValidation: true,
3764
+ breadcrumbsPrefix: ["response"]
3765
+ });
3766
+ }
3767
+ if (_response.error.reason === "status-code") {
3768
+ throw new RivetError({
3769
+ statusCode: _response.error.statusCode,
3770
+ body: _response.error.body
3771
+ });
3772
+ }
3773
+ switch (_response.error.reason) {
3774
+ case "non-json":
3775
+ throw new RivetError({
3776
+ statusCode: _response.error.statusCode,
3777
+ body: _response.error.rawBody
3778
+ });
3779
+ case "timeout":
3780
+ throw new RivetTimeoutError("Timeout exceeded when calling PUT /actors.");
3781
+ case "unknown":
3782
+ throw new RivetError({
3783
+ message: _response.error.errorMessage
3784
+ });
3785
+ }
3786
+ }
3787
+ /**
3788
+ * 2 round trips:
3789
+ *
3790
+ * - GET /actors/names (fanout)
3791
+ * - [api-peer] namespace::ops::resolve_for_name_global
3792
+ *
3793
+ * @param {Rivet.ActorsListNamesRequest} request
3794
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3795
+ *
3796
+ * @example
3797
+ * await client.actorsListNames({
3798
+ * namespace: "namespace"
3799
+ * })
3800
+ */
3801
+ async actorsListNames(request, requestOptions) {
3802
+ const { namespace, limit, cursor } = request;
3803
+ const _queryParams = {};
3804
+ _queryParams["namespace"] = namespace;
3805
+ if (limit != null) {
3806
+ _queryParams["limit"] = limit.toString();
3807
+ }
3808
+ if (cursor != null) {
3809
+ _queryParams["cursor"] = cursor;
3810
+ }
3811
+ const _response = await (this._options.fetcher ?? fetcher)({
3812
+ url: (0, import_url_join7.default)(
3813
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3814
+ "actors/names"
3815
+ ),
3816
+ method: "GET",
3817
+ headers: {
3818
+ Authorization: await this._getAuthorizationHeader(),
3819
+ "X-Fern-Language": "JavaScript",
3820
+ "X-Fern-Runtime": RUNTIME.type,
3821
+ "X-Fern-Runtime-Version": RUNTIME.version,
3822
+ ...requestOptions == null ? void 0 : requestOptions.headers
3823
+ },
3824
+ contentType: "application/json",
3825
+ queryParameters: _queryParams,
3826
+ requestType: "json",
3827
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3828
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3829
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3830
+ });
3831
+ if (_response.ok) {
3832
+ return ActorsListNamesResponse.parseOrThrow(_response.body, {
3833
+ unrecognizedObjectKeys: "passthrough",
3834
+ allowUnrecognizedUnionMembers: true,
3835
+ allowUnrecognizedEnumValues: true,
3836
+ skipValidation: true,
3837
+ breadcrumbsPrefix: ["response"]
3838
+ });
3839
+ }
3840
+ if (_response.error.reason === "status-code") {
3841
+ throw new RivetError({
3842
+ statusCode: _response.error.statusCode,
3843
+ body: _response.error.body
3844
+ });
3845
+ }
3846
+ switch (_response.error.reason) {
3847
+ case "non-json":
3848
+ throw new RivetError({
3849
+ statusCode: _response.error.statusCode,
3850
+ body: _response.error.rawBody
3851
+ });
3852
+ case "timeout":
3853
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /actors/names.");
3854
+ case "unknown":
3855
+ throw new RivetError({
3856
+ message: _response.error.errorMessage
3857
+ });
3858
+ }
3859
+ }
3860
+ /**
3861
+ * 2 round trip:
3862
+ *
3863
+ * - DELETE /actors/{}
3864
+ * - [api-peer] namespace::ops::resolve_for_name_global
3865
+ *
3866
+ * @param {Rivet.RivetId} actorId
3867
+ * @param {Rivet.ActorsDeleteRequest} request
3868
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3869
+ *
3870
+ * @example
3871
+ * await client.actorsDelete("actor_id", {
3872
+ * namespace: "namespace"
3873
+ * })
3874
+ */
3875
+ async actorsDelete(actorId, request, requestOptions) {
3876
+ const { namespace } = request;
3877
+ const _queryParams = {};
3878
+ _queryParams["namespace"] = namespace;
3879
+ const _response = await (this._options.fetcher ?? fetcher)({
3880
+ url: (0, import_url_join7.default)(
3881
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3882
+ `actors/${encodeURIComponent(RivetId.jsonOrThrow(actorId))}`
3883
+ ),
3884
+ method: "DELETE",
3885
+ headers: {
3886
+ Authorization: await this._getAuthorizationHeader(),
3887
+ "X-Fern-Language": "JavaScript",
3888
+ "X-Fern-Runtime": RUNTIME.type,
3889
+ "X-Fern-Runtime-Version": RUNTIME.version,
3890
+ ...requestOptions == null ? void 0 : requestOptions.headers
3891
+ },
3892
+ contentType: "application/json",
3893
+ queryParameters: _queryParams,
3894
+ requestType: "json",
3895
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3896
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3897
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3898
+ });
3899
+ if (_response.ok) {
3900
+ return ActorsDeleteResponse.parseOrThrow(_response.body, {
3901
+ unrecognizedObjectKeys: "passthrough",
3902
+ allowUnrecognizedUnionMembers: true,
3903
+ allowUnrecognizedEnumValues: true,
3904
+ skipValidation: true,
3905
+ breadcrumbsPrefix: ["response"]
3906
+ });
3907
+ }
3908
+ if (_response.error.reason === "status-code") {
3909
+ throw new RivetError({
3910
+ statusCode: _response.error.statusCode,
3911
+ body: _response.error.body
3912
+ });
3913
+ }
3914
+ switch (_response.error.reason) {
3915
+ case "non-json":
3916
+ throw new RivetError({
3917
+ statusCode: _response.error.statusCode,
3918
+ body: _response.error.rawBody
3919
+ });
3920
+ case "timeout":
3921
+ throw new RivetTimeoutError("Timeout exceeded when calling DELETE /actors/{actor_id}.");
3922
+ case "unknown":
3923
+ throw new RivetError({
3924
+ message: _response.error.errorMessage
3925
+ });
3926
+ }
3927
+ }
3928
+ /**
3929
+ * @param {Rivet.RivetId} actorId
3930
+ * @param {string} key
3931
+ * @param {Rivet.ActorsKvGetRequest} request
3932
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3933
+ *
3934
+ * @example
3935
+ * await client.actorsKvGet("actor_id", "key", {
3936
+ * namespace: "namespace"
3937
+ * })
3938
+ */
3939
+ async actorsKvGet(actorId, key, request, requestOptions) {
3940
+ const { namespace } = request;
3941
+ const _queryParams = {};
3942
+ _queryParams["namespace"] = namespace;
3943
+ const _response = await (this._options.fetcher ?? fetcher)({
3944
+ url: (0, import_url_join7.default)(
3945
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
3946
+ `actors/${encodeURIComponent(RivetId.jsonOrThrow(actorId))}/kv/keys/${encodeURIComponent(key)}`
3947
+ ),
3948
+ method: "GET",
3949
+ headers: {
3950
+ Authorization: await this._getAuthorizationHeader(),
3951
+ "X-Fern-Language": "JavaScript",
3952
+ "X-Fern-Runtime": RUNTIME.type,
3953
+ "X-Fern-Runtime-Version": RUNTIME.version,
3954
+ ...requestOptions == null ? void 0 : requestOptions.headers
3955
+ },
3956
+ contentType: "application/json",
3957
+ queryParameters: _queryParams,
3958
+ requestType: "json",
3959
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
3960
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
3961
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
3962
+ });
3963
+ if (_response.ok) {
3964
+ return ActorsKvGetResponse.parseOrThrow(_response.body, {
3965
+ unrecognizedObjectKeys: "passthrough",
3966
+ allowUnrecognizedUnionMembers: true,
3967
+ allowUnrecognizedEnumValues: true,
3968
+ skipValidation: true,
3969
+ breadcrumbsPrefix: ["response"]
3970
+ });
3971
+ }
3972
+ if (_response.error.reason === "status-code") {
3973
+ throw new RivetError({
3974
+ statusCode: _response.error.statusCode,
3975
+ body: _response.error.body
3976
+ });
3977
+ }
3978
+ switch (_response.error.reason) {
3979
+ case "non-json":
3980
+ throw new RivetError({
3981
+ statusCode: _response.error.statusCode,
3982
+ body: _response.error.rawBody
3983
+ });
3984
+ case "timeout":
3985
+ throw new RivetTimeoutError(
3986
+ "Timeout exceeded when calling GET /actors/{actor_id}/kv/keys/{key}."
3987
+ );
3988
+ case "unknown":
3989
+ throw new RivetError({
3990
+ message: _response.error.errorMessage
3991
+ });
3992
+ }
3993
+ }
3994
+ /**
3995
+ * @param {Rivet.RivetId} actorId
3996
+ * @param {Rivet.ActorsRescheduleRequest} request
3997
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
3998
+ *
3999
+ * @example
4000
+ * await client.actorsReschedule("actor_id", {
4001
+ * namespace: "namespace",
4002
+ * body: {
4003
+ * "key": "value"
4004
+ * }
4005
+ * })
4006
+ */
4007
+ async actorsReschedule(actorId, request, requestOptions) {
4008
+ const { namespace, body: _body } = request;
4009
+ const _queryParams = {};
4010
+ _queryParams["namespace"] = namespace;
4011
+ const _response = await (this._options.fetcher ?? fetcher)({
4012
+ url: (0, import_url_join7.default)(
4013
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4014
+ `actors/${encodeURIComponent(RivetId.jsonOrThrow(actorId))}/reschedule`
4015
+ ),
4016
+ method: "POST",
4017
+ headers: {
4018
+ Authorization: await this._getAuthorizationHeader(),
4019
+ "X-Fern-Language": "JavaScript",
4020
+ "X-Fern-Runtime": RUNTIME.type,
4021
+ "X-Fern-Runtime-Version": RUNTIME.version,
4022
+ ...requestOptions == null ? void 0 : requestOptions.headers
4023
+ },
4024
+ contentType: "application/json",
4025
+ queryParameters: _queryParams,
4026
+ requestType: "json",
4027
+ body: ActorsRescheduleRequestBody.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
4028
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4029
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4030
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4031
+ });
4032
+ if (_response.ok) {
4033
+ return ActorsRescheduleResponse.parseOrThrow(_response.body, {
4034
+ unrecognizedObjectKeys: "passthrough",
4035
+ allowUnrecognizedUnionMembers: true,
4036
+ allowUnrecognizedEnumValues: true,
4037
+ skipValidation: true,
4038
+ breadcrumbsPrefix: ["response"]
4039
+ });
4040
+ }
4041
+ if (_response.error.reason === "status-code") {
4042
+ throw new RivetError({
4043
+ statusCode: _response.error.statusCode,
4044
+ body: _response.error.body
4045
+ });
4046
+ }
4047
+ switch (_response.error.reason) {
4048
+ case "non-json":
4049
+ throw new RivetError({
4050
+ statusCode: _response.error.statusCode,
4051
+ body: _response.error.rawBody
4052
+ });
4053
+ case "timeout":
4054
+ throw new RivetTimeoutError("Timeout exceeded when calling POST /actors/{actor_id}/reschedule.");
4055
+ case "unknown":
4056
+ throw new RivetError({
4057
+ message: _response.error.errorMessage
4058
+ });
4059
+ }
4060
+ }
4061
+ /**
4062
+ * @param {Rivet.RivetId} actorId
4063
+ * @param {Rivet.ActorsSleepRequest} request
4064
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4065
+ *
4066
+ * @example
4067
+ * await client.actorsSleep("actor_id", {
4068
+ * namespace: "namespace",
4069
+ * body: {
4070
+ * "key": "value"
4071
+ * }
4072
+ * })
4073
+ */
4074
+ async actorsSleep(actorId, request, requestOptions) {
4075
+ const { namespace, body: _body } = request;
4076
+ const _queryParams = {};
4077
+ _queryParams["namespace"] = namespace;
4078
+ const _response = await (this._options.fetcher ?? fetcher)({
4079
+ url: (0, import_url_join7.default)(
4080
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4081
+ `actors/${encodeURIComponent(RivetId.jsonOrThrow(actorId))}/sleep`
4082
+ ),
4083
+ method: "POST",
4084
+ headers: {
4085
+ Authorization: await this._getAuthorizationHeader(),
4086
+ "X-Fern-Language": "JavaScript",
4087
+ "X-Fern-Runtime": RUNTIME.type,
4088
+ "X-Fern-Runtime-Version": RUNTIME.version,
4089
+ ...requestOptions == null ? void 0 : requestOptions.headers
4090
+ },
4091
+ contentType: "application/json",
4092
+ queryParameters: _queryParams,
4093
+ requestType: "json",
4094
+ body: ActorsSleepRequestBody.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
4095
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4096
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4097
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4098
+ });
4099
+ if (_response.ok) {
4100
+ return ActorsSleepResponse.parseOrThrow(_response.body, {
4101
+ unrecognizedObjectKeys: "passthrough",
4102
+ allowUnrecognizedUnionMembers: true,
4103
+ allowUnrecognizedEnumValues: true,
4104
+ skipValidation: true,
4105
+ breadcrumbsPrefix: ["response"]
4106
+ });
4107
+ }
4108
+ if (_response.error.reason === "status-code") {
4109
+ throw new RivetError({
4110
+ statusCode: _response.error.statusCode,
4111
+ body: _response.error.body
4112
+ });
4113
+ }
4114
+ switch (_response.error.reason) {
4115
+ case "non-json":
4116
+ throw new RivetError({
4117
+ statusCode: _response.error.statusCode,
4118
+ body: _response.error.rawBody
4119
+ });
4120
+ case "timeout":
4121
+ throw new RivetTimeoutError("Timeout exceeded when calling POST /actors/{actor_id}/sleep.");
4122
+ case "unknown":
4123
+ throw new RivetError({
4124
+ message: _response.error.errorMessage
4125
+ });
4126
+ }
4127
+ }
4128
+ /**
4129
+ * @param {Rivet.RunnerConfigsListRequest} request
4130
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4131
+ *
4132
+ * @example
4133
+ * await client.runnerConfigsList({
4134
+ * namespace: "namespace"
4135
+ * })
4136
+ */
4137
+ async runnerConfigsList(request, requestOptions) {
4138
+ const { namespace, limit, cursor, variant, runnerNames, runnerName } = request;
4139
+ const _queryParams = {};
4140
+ _queryParams["namespace"] = namespace;
4141
+ if (limit != null) {
4142
+ _queryParams["limit"] = limit.toString();
4143
+ }
4144
+ if (cursor != null) {
4145
+ _queryParams["cursor"] = cursor;
4146
+ }
4147
+ if (variant != null) {
4148
+ _queryParams["variant"] = RunnerConfigVariant2.jsonOrThrow(variant, {
4149
+ unrecognizedObjectKeys: "strip"
4150
+ });
4151
+ }
4152
+ if (runnerNames != null) {
4153
+ _queryParams["runner_names"] = runnerNames;
4154
+ }
4155
+ if (runnerName != null) {
4156
+ if (Array.isArray(runnerName)) {
4157
+ _queryParams["runner_name"] = runnerName.map((item) => item);
4158
+ } else {
4159
+ _queryParams["runner_name"] = runnerName;
4160
+ }
4161
+ }
4162
+ const _response = await (this._options.fetcher ?? fetcher)({
4163
+ url: (0, import_url_join7.default)(
4164
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4165
+ "runner-configs"
4166
+ ),
4167
+ method: "GET",
4168
+ headers: {
4169
+ Authorization: await this._getAuthorizationHeader(),
4170
+ "X-Fern-Language": "JavaScript",
4171
+ "X-Fern-Runtime": RUNTIME.type,
4172
+ "X-Fern-Runtime-Version": RUNTIME.version,
4173
+ ...requestOptions == null ? void 0 : requestOptions.headers
4174
+ },
4175
+ contentType: "application/json",
4176
+ queryParameters: _queryParams,
4177
+ requestType: "json",
4178
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4179
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4180
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4181
+ });
4182
+ if (_response.ok) {
4183
+ return RunnerConfigsListResponse.parseOrThrow(_response.body, {
4184
+ unrecognizedObjectKeys: "passthrough",
4185
+ allowUnrecognizedUnionMembers: true,
4186
+ allowUnrecognizedEnumValues: true,
4187
+ skipValidation: true,
4188
+ breadcrumbsPrefix: ["response"]
4189
+ });
4190
+ }
4191
+ if (_response.error.reason === "status-code") {
4192
+ throw new RivetError({
4193
+ statusCode: _response.error.statusCode,
4194
+ body: _response.error.body
4195
+ });
4196
+ }
4197
+ switch (_response.error.reason) {
4198
+ case "non-json":
4199
+ throw new RivetError({
4200
+ statusCode: _response.error.statusCode,
4201
+ body: _response.error.rawBody
4202
+ });
4203
+ case "timeout":
4204
+ throw new RivetTimeoutError("Timeout exceeded when calling GET /runner-configs.");
4205
+ case "unknown":
4206
+ throw new RivetError({
4207
+ message: _response.error.errorMessage
4208
+ });
4209
+ }
4210
+ }
4211
+ /**
4212
+ * @param {Rivet.RunnerConfigsServerlessHealthCheckRequest} request
4213
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4214
+ *
4215
+ * @example
4216
+ * await client.runnerConfigsServerlessHealthCheck({
4217
+ * namespace: "namespace",
4218
+ * url: "url"
4219
+ * })
4220
+ */
4221
+ async runnerConfigsServerlessHealthCheck(request, requestOptions) {
4222
+ const { namespace, ..._body } = request;
4223
+ const _queryParams = {};
4224
+ _queryParams["namespace"] = namespace;
4225
+ const _response = await (this._options.fetcher ?? fetcher)({
4226
+ url: (0, import_url_join7.default)(
4227
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4228
+ "runner-configs/serverless-health-check"
4229
+ ),
4230
+ method: "POST",
4231
+ headers: {
4232
+ Authorization: await this._getAuthorizationHeader(),
4233
+ "X-Fern-Language": "JavaScript",
4234
+ "X-Fern-Runtime": RUNTIME.type,
4235
+ "X-Fern-Runtime-Version": RUNTIME.version,
4236
+ ...requestOptions == null ? void 0 : requestOptions.headers
4237
+ },
4238
+ contentType: "application/json",
4239
+ queryParameters: _queryParams,
4240
+ requestType: "json",
4241
+ body: RunnerConfigsServerlessHealthCheckRequest.jsonOrThrow(_body, {
4242
+ unrecognizedObjectKeys: "strip"
4243
+ }),
4244
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4245
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4246
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4247
+ });
4248
+ if (_response.ok) {
4249
+ return RunnerConfigsServerlessHealthCheckResponse.parseOrThrow(_response.body, {
4250
+ unrecognizedObjectKeys: "passthrough",
4251
+ allowUnrecognizedUnionMembers: true,
4252
+ allowUnrecognizedEnumValues: true,
4253
+ skipValidation: true,
4254
+ breadcrumbsPrefix: ["response"]
4255
+ });
4256
+ }
4257
+ if (_response.error.reason === "status-code") {
4258
+ throw new RivetError({
4259
+ statusCode: _response.error.statusCode,
4260
+ body: _response.error.body
4261
+ });
4262
+ }
4263
+ switch (_response.error.reason) {
4264
+ case "non-json":
4265
+ throw new RivetError({
4266
+ statusCode: _response.error.statusCode,
4267
+ body: _response.error.rawBody
4268
+ });
4269
+ case "timeout":
4270
+ throw new RivetTimeoutError(
4271
+ "Timeout exceeded when calling POST /runner-configs/serverless-health-check."
4272
+ );
4273
+ case "unknown":
4274
+ throw new RivetError({
4275
+ message: _response.error.errorMessage
4276
+ });
4277
+ }
4278
+ }
4279
+ /**
4280
+ * @param {string} runnerName
4281
+ * @param {Rivet.RunnerConfigsUpsertRequestBody} request
4282
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4283
+ *
4284
+ * @example
4285
+ * await client.runnerConfigsUpsert("runner_name", {
4286
+ * namespace: "namespace",
4287
+ * datacenters: {
4288
+ * "key": {}
4289
+ * }
4290
+ * })
4291
+ */
4292
+ async runnerConfigsUpsert(runnerName, request, requestOptions) {
4293
+ const { namespace, ..._body } = request;
4294
+ const _queryParams = {};
4295
+ _queryParams["namespace"] = namespace;
4296
+ const _response = await (this._options.fetcher ?? fetcher)({
4297
+ url: (0, import_url_join7.default)(
4298
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4299
+ `runner-configs/${encodeURIComponent(runnerName)}`
4300
+ ),
4301
+ method: "PUT",
4302
+ headers: {
4303
+ Authorization: await this._getAuthorizationHeader(),
4304
+ "X-Fern-Language": "JavaScript",
4305
+ "X-Fern-Runtime": RUNTIME.type,
4306
+ "X-Fern-Runtime-Version": RUNTIME.version,
4307
+ ...requestOptions == null ? void 0 : requestOptions.headers
4308
+ },
4309
+ contentType: "application/json",
4310
+ queryParameters: _queryParams,
4311
+ requestType: "json",
4312
+ body: RunnerConfigsUpsertRequestBody.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
4313
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4314
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4315
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4316
+ });
4317
+ if (_response.ok) {
4318
+ return RunnerConfigsUpsertResponse.parseOrThrow(_response.body, {
4319
+ unrecognizedObjectKeys: "passthrough",
4320
+ allowUnrecognizedUnionMembers: true,
4321
+ allowUnrecognizedEnumValues: true,
4322
+ skipValidation: true,
4323
+ breadcrumbsPrefix: ["response"]
4324
+ });
4325
+ }
4326
+ if (_response.error.reason === "status-code") {
4327
+ throw new RivetError({
4328
+ statusCode: _response.error.statusCode,
4329
+ body: _response.error.body
4330
+ });
4331
+ }
4332
+ switch (_response.error.reason) {
4333
+ case "non-json":
4334
+ throw new RivetError({
4335
+ statusCode: _response.error.statusCode,
4336
+ body: _response.error.rawBody
4337
+ });
4338
+ case "timeout":
4339
+ throw new RivetTimeoutError("Timeout exceeded when calling PUT /runner-configs/{runner_name}.");
4340
+ case "unknown":
4341
+ throw new RivetError({
4342
+ message: _response.error.errorMessage
4343
+ });
4344
+ }
4345
+ }
4346
+ /**
4347
+ * @param {string} runnerName
4348
+ * @param {Rivet.RunnerConfigsDeleteRequest} request
4349
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4350
+ *
4351
+ * @example
4352
+ * await client.runnerConfigsDelete("runner_name", {
4353
+ * namespace: "namespace"
4354
+ * })
4355
+ */
4356
+ async runnerConfigsDelete(runnerName, request, requestOptions) {
4357
+ const { namespace } = request;
4358
+ const _queryParams = {};
4359
+ _queryParams["namespace"] = namespace;
4360
+ const _response = await (this._options.fetcher ?? fetcher)({
4361
+ url: (0, import_url_join7.default)(
4362
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4363
+ `runner-configs/${encodeURIComponent(runnerName)}`
4364
+ ),
4365
+ method: "DELETE",
4366
+ headers: {
4367
+ Authorization: await this._getAuthorizationHeader(),
4368
+ "X-Fern-Language": "JavaScript",
4369
+ "X-Fern-Runtime": RUNTIME.type,
4370
+ "X-Fern-Runtime-Version": RUNTIME.version,
4371
+ ...requestOptions == null ? void 0 : requestOptions.headers
4372
+ },
4373
+ contentType: "application/json",
4374
+ queryParameters: _queryParams,
4375
+ requestType: "json",
4376
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4377
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4378
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4379
+ });
4380
+ if (_response.ok) {
4381
+ return RunnerConfigsDeleteResponse.parseOrThrow(_response.body, {
4382
+ unrecognizedObjectKeys: "passthrough",
4383
+ allowUnrecognizedUnionMembers: true,
4384
+ allowUnrecognizedEnumValues: true,
4385
+ skipValidation: true,
4386
+ breadcrumbsPrefix: ["response"]
4387
+ });
4388
+ }
4389
+ if (_response.error.reason === "status-code") {
4390
+ throw new RivetError({
4391
+ statusCode: _response.error.statusCode,
4392
+ body: _response.error.body
4393
+ });
4394
+ }
4395
+ switch (_response.error.reason) {
4396
+ case "non-json":
4397
+ throw new RivetError({
4398
+ statusCode: _response.error.statusCode,
4399
+ body: _response.error.rawBody
4400
+ });
4401
+ case "timeout":
4402
+ throw new RivetTimeoutError(
4403
+ "Timeout exceeded when calling DELETE /runner-configs/{runner_name}."
4404
+ );
4405
+ case "unknown":
4406
+ throw new RivetError({
4407
+ message: _response.error.errorMessage
4408
+ });
4409
+ }
4410
+ }
4411
+ /**
4412
+ * @param {string} runnerName
4413
+ * @param {Rivet.RunnerConfigsRefreshMetadataRequest} request
4414
+ * @param {RivetClient.RequestOptions} requestOptions - Request-specific configuration.
4415
+ *
4416
+ * @example
4417
+ * await client.runnerConfigsRefreshMetadata("runner_name", {
4418
+ * namespace: "namespace",
4419
+ * body: {
4420
+ * "key": "value"
4421
+ * }
4422
+ * })
4423
+ */
4424
+ async runnerConfigsRefreshMetadata(runnerName, request, requestOptions) {
4425
+ const { namespace, body: _body } = request;
4426
+ const _queryParams = {};
4427
+ _queryParams["namespace"] = namespace;
4428
+ const _response = await (this._options.fetcher ?? fetcher)({
4429
+ url: (0, import_url_join7.default)(
4430
+ await Supplier.get(this._options.baseUrl) ?? await Supplier.get(this._options.environment),
4431
+ `runner-configs/${encodeURIComponent(runnerName)}/refresh-metadata`
4432
+ ),
4433
+ method: "POST",
4434
+ headers: {
4435
+ Authorization: await this._getAuthorizationHeader(),
4436
+ "X-Fern-Language": "JavaScript",
4437
+ "X-Fern-Runtime": RUNTIME.type,
4438
+ "X-Fern-Runtime-Version": RUNTIME.version,
4439
+ ...requestOptions == null ? void 0 : requestOptions.headers
4440
+ },
4441
+ contentType: "application/json",
4442
+ queryParameters: _queryParams,
4443
+ requestType: "json",
4444
+ body: RunnerConfigsRefreshMetadataRequestBody.jsonOrThrow(_body, {
4445
+ unrecognizedObjectKeys: "strip"
4446
+ }),
4447
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 18e4,
4448
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
4449
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
4450
+ });
4451
+ if (_response.ok) {
4452
+ return RunnerConfigsRefreshMetadataResponse.parseOrThrow(_response.body, {
4453
+ unrecognizedObjectKeys: "passthrough",
4454
+ allowUnrecognizedUnionMembers: true,
4455
+ allowUnrecognizedEnumValues: true,
4456
+ skipValidation: true,
4457
+ breadcrumbsPrefix: ["response"]
4458
+ });
4459
+ }
4460
+ if (_response.error.reason === "status-code") {
4461
+ throw new RivetError({
4462
+ statusCode: _response.error.statusCode,
4463
+ body: _response.error.body
4464
+ });
4465
+ }
4466
+ switch (_response.error.reason) {
4467
+ case "non-json":
4468
+ throw new RivetError({
4469
+ statusCode: _response.error.statusCode,
4470
+ body: _response.error.rawBody
4471
+ });
4472
+ case "timeout":
4473
+ throw new RivetTimeoutError(
4474
+ "Timeout exceeded when calling POST /runner-configs/{runner_name}/refresh-metadata."
4475
+ );
4476
+ case "unknown":
4477
+ throw new RivetError({
4478
+ message: _response.error.errorMessage
4479
+ });
4480
+ }
4481
+ }
4482
+ async _getAuthorizationHeader() {
4483
+ return `Bearer ${await Supplier.get(this._options.token)}`;
4484
+ }
4485
+ };
4486
+ // Annotate the CommonJS export names for ESM import in node:
4487
+ 0 && (module.exports = {
4488
+ Rivet,
4489
+ RivetClient,
4490
+ RivetError,
4491
+ RivetTimeoutError,
4492
+ serialization
4493
+ });