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