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