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