@limrun/api 0.82.0 → 0.84.0

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 (282) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +4 -6
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts.map +1 -1
  5. package/client.js.map +1 -1
  6. package/client.mjs.map +1 -1
  7. package/core/api-promise.d.mts.map +1 -1
  8. package/core/api-promise.d.ts.map +1 -1
  9. package/core/api-promise.js +0 -1
  10. package/core/api-promise.js.map +1 -1
  11. package/core/api-promise.mjs +0 -1
  12. package/core/api-promise.mjs.map +1 -1
  13. package/core/error.d.mts.map +1 -1
  14. package/core/error.d.ts.map +1 -1
  15. package/core/error.js +0 -1
  16. package/core/error.js.map +1 -1
  17. package/core/error.mjs +0 -1
  18. package/core/error.mjs.map +1 -1
  19. package/core/pagination.d.mts.map +1 -1
  20. package/core/pagination.d.ts.map +1 -1
  21. package/core/pagination.js +0 -1
  22. package/core/pagination.js.map +1 -1
  23. package/core/pagination.mjs +0 -1
  24. package/core/pagination.mjs.map +1 -1
  25. package/core/resource.d.mts.map +1 -1
  26. package/core/resource.d.ts.map +1 -1
  27. package/core/resource.js +0 -1
  28. package/core/resource.js.map +1 -1
  29. package/core/resource.mjs +0 -1
  30. package/core/resource.mjs.map +1 -1
  31. package/exec-client.d.mts +3 -3
  32. package/exec-client.d.ts +3 -3
  33. package/gradle-snapshot.d.mts +9 -1
  34. package/gradle-snapshot.d.mts.map +1 -1
  35. package/gradle-snapshot.d.ts +9 -1
  36. package/gradle-snapshot.d.ts.map +1 -1
  37. package/gradle-snapshot.js.map +1 -1
  38. package/gradle-snapshot.mjs.map +1 -1
  39. package/index.d.mts +1 -1
  40. package/index.d.mts.map +1 -1
  41. package/index.d.ts +1 -1
  42. package/index.d.ts.map +1 -1
  43. package/index.js +4 -3
  44. package/index.js.map +1 -1
  45. package/index.mjs +1 -1
  46. package/index.mjs.map +1 -1
  47. package/internal/builtin-types.d.mts.map +1 -1
  48. package/internal/builtin-types.d.ts.map +1 -1
  49. package/internal/builtin-types.js +0 -1
  50. package/internal/builtin-types.js.map +1 -1
  51. package/internal/builtin-types.mjs +0 -1
  52. package/internal/builtin-types.mjs.map +1 -1
  53. package/internal/daemon-snapshot.d.mts +29 -0
  54. package/internal/daemon-snapshot.d.mts.map +1 -0
  55. package/internal/daemon-snapshot.d.ts +29 -0
  56. package/internal/daemon-snapshot.d.ts.map +1 -0
  57. package/internal/daemon-snapshot.js +137 -0
  58. package/internal/daemon-snapshot.js.map +1 -0
  59. package/internal/daemon-snapshot.mjs +134 -0
  60. package/internal/daemon-snapshot.mjs.map +1 -0
  61. package/internal/detect-platform.d.mts.map +1 -1
  62. package/internal/detect-platform.d.ts.map +1 -1
  63. package/internal/detect-platform.js +0 -1
  64. package/internal/detect-platform.js.map +1 -1
  65. package/internal/detect-platform.mjs +0 -1
  66. package/internal/detect-platform.mjs.map +1 -1
  67. package/internal/errors.d.mts.map +1 -1
  68. package/internal/errors.d.ts.map +1 -1
  69. package/internal/errors.js +0 -1
  70. package/internal/errors.js.map +1 -1
  71. package/internal/errors.mjs +0 -1
  72. package/internal/errors.mjs.map +1 -1
  73. package/internal/headers.d.mts.map +1 -1
  74. package/internal/headers.d.ts.map +1 -1
  75. package/internal/headers.js +0 -1
  76. package/internal/headers.js.map +1 -1
  77. package/internal/headers.mjs +0 -1
  78. package/internal/headers.mjs.map +1 -1
  79. package/internal/parse.d.mts.map +1 -1
  80. package/internal/parse.d.ts.map +1 -1
  81. package/internal/parse.js +0 -1
  82. package/internal/parse.js.map +1 -1
  83. package/internal/parse.mjs +0 -1
  84. package/internal/parse.mjs.map +1 -1
  85. package/internal/request-options.d.mts.map +1 -1
  86. package/internal/request-options.d.ts.map +1 -1
  87. package/internal/request-options.js +0 -1
  88. package/internal/request-options.js.map +1 -1
  89. package/internal/request-options.mjs +0 -1
  90. package/internal/request-options.mjs.map +1 -1
  91. package/internal/shim-types.d.mts.map +1 -1
  92. package/internal/shim-types.d.ts.map +1 -1
  93. package/internal/shim-types.js +6 -1
  94. package/internal/shim-types.js.map +1 -1
  95. package/internal/shim-types.mjs +6 -1
  96. package/internal/shim-types.mjs.map +1 -1
  97. package/internal/shims.d.mts.map +1 -1
  98. package/internal/shims.d.ts.map +1 -1
  99. package/internal/shims.js +6 -1
  100. package/internal/shims.js.map +1 -1
  101. package/internal/shims.mjs +6 -1
  102. package/internal/shims.mjs.map +1 -1
  103. package/internal/types.d.mts.map +1 -1
  104. package/internal/types.d.ts.map +1 -1
  105. package/internal/types.js +0 -1
  106. package/internal/types.js.map +1 -1
  107. package/internal/types.mjs +0 -1
  108. package/internal/types.mjs.map +1 -1
  109. package/internal/utils/base64.d.mts.map +1 -1
  110. package/internal/utils/base64.d.ts.map +1 -1
  111. package/internal/utils/base64.js +0 -1
  112. package/internal/utils/base64.js.map +1 -1
  113. package/internal/utils/base64.mjs +0 -1
  114. package/internal/utils/base64.mjs.map +1 -1
  115. package/internal/utils/env.d.mts.map +1 -1
  116. package/internal/utils/env.d.ts.map +1 -1
  117. package/internal/utils/env.js +0 -1
  118. package/internal/utils/env.js.map +1 -1
  119. package/internal/utils/env.mjs +0 -1
  120. package/internal/utils/env.mjs.map +1 -1
  121. package/internal/utils/log.d.mts.map +1 -1
  122. package/internal/utils/log.d.ts.map +1 -1
  123. package/internal/utils/log.js +0 -1
  124. package/internal/utils/log.js.map +1 -1
  125. package/internal/utils/log.mjs +0 -1
  126. package/internal/utils/log.mjs.map +1 -1
  127. package/internal/utils/query.d.mts.map +1 -1
  128. package/internal/utils/query.d.ts.map +1 -1
  129. package/internal/utils/query.js +0 -1
  130. package/internal/utils/query.js.map +1 -1
  131. package/internal/utils/query.mjs +0 -1
  132. package/internal/utils/query.mjs.map +1 -1
  133. package/internal/utils/sleep.d.mts.map +1 -1
  134. package/internal/utils/sleep.d.ts.map +1 -1
  135. package/internal/utils/sleep.js +0 -1
  136. package/internal/utils/sleep.js.map +1 -1
  137. package/internal/utils/sleep.mjs +0 -1
  138. package/internal/utils/sleep.mjs.map +1 -1
  139. package/internal/utils/uuid.d.mts.map +1 -1
  140. package/internal/utils/uuid.d.ts.map +1 -1
  141. package/internal/utils/uuid.js +0 -1
  142. package/internal/utils/uuid.js.map +1 -1
  143. package/internal/utils/uuid.mjs +0 -1
  144. package/internal/utils/uuid.mjs.map +1 -1
  145. package/internal/utils/values.d.mts.map +1 -1
  146. package/internal/utils/values.d.ts.map +1 -1
  147. package/internal/utils/values.js +0 -1
  148. package/internal/utils/values.js.map +1 -1
  149. package/internal/utils/values.mjs +0 -1
  150. package/internal/utils/values.mjs.map +1 -1
  151. package/internal/utils.d.mts.map +1 -1
  152. package/internal/utils.d.ts.map +1 -1
  153. package/internal/utils.js +0 -1
  154. package/internal/utils.js.map +1 -1
  155. package/internal/utils.mjs +0 -1
  156. package/internal/utils.mjs.map +1 -1
  157. package/package.json +2 -2
  158. package/resources/analytics.d.mts.map +1 -1
  159. package/resources/analytics.d.ts.map +1 -1
  160. package/resources/analytics.js +0 -1
  161. package/resources/analytics.js.map +1 -1
  162. package/resources/analytics.mjs +0 -1
  163. package/resources/analytics.mjs.map +1 -1
  164. package/resources/android-instances.d.mts.map +1 -1
  165. package/resources/android-instances.d.ts.map +1 -1
  166. package/resources/android-instances.js +0 -1
  167. package/resources/android-instances.js.map +1 -1
  168. package/resources/android-instances.mjs +0 -1
  169. package/resources/android-instances.mjs.map +1 -1
  170. package/resources/assets.d.mts.map +1 -1
  171. package/resources/assets.d.ts.map +1 -1
  172. package/resources/assets.js +0 -1
  173. package/resources/assets.js.map +1 -1
  174. package/resources/assets.mjs +0 -1
  175. package/resources/assets.mjs.map +1 -1
  176. package/resources/daemon-client-shared.d.mts.map +1 -1
  177. package/resources/daemon-client-shared.d.ts.map +1 -1
  178. package/resources/daemon-client-shared.js.map +1 -1
  179. package/resources/daemon-client-shared.mjs.map +1 -1
  180. package/resources/gradle-instances-helpers.d.mts.map +1 -1
  181. package/resources/gradle-instances-helpers.d.ts.map +1 -1
  182. package/resources/gradle-instances-helpers.js +25 -37
  183. package/resources/gradle-instances-helpers.js.map +1 -1
  184. package/resources/gradle-instances-helpers.mjs +25 -37
  185. package/resources/gradle-instances-helpers.mjs.map +1 -1
  186. package/resources/gradle-instances.d.mts.map +1 -1
  187. package/resources/gradle-instances.d.ts.map +1 -1
  188. package/resources/gradle-instances.js +0 -2
  189. package/resources/gradle-instances.js.map +1 -1
  190. package/resources/gradle-instances.mjs +0 -2
  191. package/resources/gradle-instances.mjs.map +1 -1
  192. package/resources/index.d.mts +1 -1
  193. package/resources/index.d.mts.map +1 -1
  194. package/resources/index.d.ts +1 -1
  195. package/resources/index.d.ts.map +1 -1
  196. package/resources/index.js +3 -2
  197. package/resources/index.js.map +1 -1
  198. package/resources/index.mjs +1 -1
  199. package/resources/index.mjs.map +1 -1
  200. package/resources/ios-instances.d.mts.map +1 -1
  201. package/resources/ios-instances.d.ts.map +1 -1
  202. package/resources/ios-instances.js +0 -1
  203. package/resources/ios-instances.js.map +1 -1
  204. package/resources/ios-instances.mjs +0 -1
  205. package/resources/ios-instances.mjs.map +1 -1
  206. package/resources/macos-instances-helpers.d.mts +34 -3
  207. package/resources/macos-instances-helpers.d.mts.map +1 -1
  208. package/resources/macos-instances-helpers.d.ts +34 -3
  209. package/resources/macos-instances-helpers.d.ts.map +1 -1
  210. package/resources/macos-instances-helpers.js +112 -25
  211. package/resources/macos-instances-helpers.js.map +1 -1
  212. package/resources/macos-instances-helpers.mjs +110 -25
  213. package/resources/macos-instances-helpers.mjs.map +1 -1
  214. package/resources/macos-instances.d.mts.map +1 -1
  215. package/resources/macos-instances.d.ts.map +1 -1
  216. package/resources/macos-instances.js +0 -2
  217. package/resources/macos-instances.js.map +1 -1
  218. package/resources/macos-instances.mjs +0 -2
  219. package/resources/macos-instances.mjs.map +1 -1
  220. package/resources/scoped-tokens.d.mts.map +1 -1
  221. package/resources/scoped-tokens.d.ts.map +1 -1
  222. package/resources/scoped-tokens.js +0 -1
  223. package/resources/scoped-tokens.js.map +1 -1
  224. package/resources/scoped-tokens.mjs +0 -1
  225. package/resources/scoped-tokens.mjs.map +1 -1
  226. package/resources/xcode-instances-helpers.d.mts +3 -4
  227. package/resources/xcode-instances-helpers.d.mts.map +1 -1
  228. package/resources/xcode-instances-helpers.d.ts +3 -4
  229. package/resources/xcode-instances-helpers.d.ts.map +1 -1
  230. package/resources/xcode-instances-helpers.js.map +1 -1
  231. package/resources/xcode-instances-helpers.mjs.map +1 -1
  232. package/resources/xcode-instances.d.mts.map +1 -1
  233. package/resources/xcode-instances.d.ts.map +1 -1
  234. package/resources/xcode-instances.js +0 -1
  235. package/resources/xcode-instances.js.map +1 -1
  236. package/resources/xcode-instances.mjs +0 -1
  237. package/resources/xcode-instances.mjs.map +1 -1
  238. package/src/client.ts +0 -2
  239. package/src/core/api-promise.ts +0 -2
  240. package/src/core/error.ts +0 -2
  241. package/src/core/pagination.ts +0 -2
  242. package/src/core/resource.ts +0 -2
  243. package/src/exec-client.ts +3 -3
  244. package/src/gradle-snapshot.ts +9 -1
  245. package/src/index.ts +1 -2
  246. package/src/internal/builtin-types.ts +0 -2
  247. package/src/internal/daemon-snapshot.ts +144 -0
  248. package/src/internal/detect-platform.ts +0 -2
  249. package/src/internal/errors.ts +0 -2
  250. package/src/internal/headers.ts +0 -2
  251. package/src/internal/parse.ts +0 -2
  252. package/src/internal/request-options.ts +0 -2
  253. package/src/internal/shim-types.ts +0 -2
  254. package/src/internal/shims.ts +0 -2
  255. package/src/internal/types.ts +0 -2
  256. package/src/internal/utils/base64.ts +0 -2
  257. package/src/internal/utils/env.ts +0 -2
  258. package/src/internal/utils/log.ts +0 -2
  259. package/src/internal/utils/query.ts +0 -2
  260. package/src/internal/utils/sleep.ts +0 -2
  261. package/src/internal/utils/uuid.ts +0 -2
  262. package/src/internal/utils/values.ts +0 -2
  263. package/src/internal/utils.ts +0 -2
  264. package/src/resources/analytics.ts +0 -2
  265. package/src/resources/android-instances.ts +0 -2
  266. package/src/resources/assets.ts +0 -2
  267. package/src/resources/daemon-client-shared.ts +2 -4
  268. package/src/resources/gradle-instances-helpers.ts +27 -41
  269. package/src/resources/gradle-instances.ts +0 -3
  270. package/src/resources/index.ts +1 -2
  271. package/src/resources/ios-instances.ts +0 -2
  272. package/src/resources/macos-instances-helpers.ts +169 -29
  273. package/src/resources/macos-instances.ts +0 -3
  274. package/src/resources/scoped-tokens.ts +0 -2
  275. package/src/resources/xcode-instances-helpers.ts +3 -4
  276. package/src/resources/xcode-instances.ts +0 -2
  277. package/src/version.ts +1 -1
  278. package/version.d.mts +1 -1
  279. package/version.d.ts +1 -1
  280. package/version.js +1 -1
  281. package/version.mjs +1 -1
  282. package/src/lib/.keep +0 -4
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
2
 
5
3
  /**
@@ -0,0 +1,144 @@
1
+ import { directInstanceHttpError } from './direct-instance-errors';
2
+ import { nodeProxyTransport } from './proxy-transport';
3
+ import { sleep } from './utils/sleep';
4
+
5
+ /**
6
+ * How to ask an instance's own daemon for its disk snapshot and follow the restore. gradlebuild,
7
+ * limulator and limacvm serve the same pair: POST /snapshot takes the request and answers with
8
+ * the status at once, and GET /snapshot answers with the status.
9
+ */
10
+ export type DaemonSnapshotOptions<T> = {
11
+ apiUrl: string;
12
+ token: string;
13
+ /** The body of POST /snapshot. It may hold the encryption key, so no error repeats it. */
14
+ request: Record<string, unknown>;
15
+ timeoutMs: number;
16
+ /** Takes one status as the daemon reports it, and returns true once it is the last one needed. */
17
+ onStatus: (status: T) => boolean;
18
+ /**
19
+ * The error for a 404 on POST /snapshot, which an image without snapshot requests answers. A 404
20
+ * on the status that follows is the daemon's error instead, since the request was taken and a
21
+ * caller must not send it again another way.
22
+ */
23
+ unavailableError: () => Error;
24
+ timeoutError: (last: T | undefined) => Error;
25
+ };
26
+
27
+ /** How long to wait between reads of a daemon that answers JSON, and before reconnecting. */
28
+ const RETRY_MS = 1000;
29
+
30
+ /**
31
+ * Sends the snapshot request, then follows the status until `onStatus` says it is done. A daemon
32
+ * that streams answers GET /snapshot with `snapshot` events, one per change, as director's
33
+ * snapshot stream does. One from before the stream answers a single JSON status, and is then
34
+ * read again every second.
35
+ */
36
+ export async function followDaemonSnapshot<T>(options: DaemonSnapshotOptions<T>): Promise<T> {
37
+ const url = `${options.apiUrl}/snapshot`;
38
+ const deadline = Date.now() + options.timeoutMs;
39
+ let last: T | undefined;
40
+ const take = (status: T): boolean => {
41
+ last = status;
42
+ return options.onStatus(status);
43
+ };
44
+ const failed = async (response: Response, request: boolean): Promise<Error> => {
45
+ if (request && response.status === 404) {
46
+ await response.text().catch(() => undefined);
47
+ return options.unavailableError();
48
+ }
49
+ // The body is the daemon's reason, which never repeats the encryption key.
50
+ const text = (await response.text()).trim();
51
+ if (response.status === 404) {
52
+ // Not a NotFoundError: the instance took the request, so a caller must not take it for a gone
53
+ // one and replace it.
54
+ return Object.assign(new Error(`Disk snapshot status failed: 404${text ? ` ${text}` : ''}`), {
55
+ status: 404,
56
+ body: text,
57
+ });
58
+ }
59
+ return directInstanceHttpError('Disk snapshot request', response.status, text, response.headers);
60
+ };
61
+
62
+ const answer = await nodeProxyTransport.fetch(url, {
63
+ method: 'POST',
64
+ headers: { Authorization: `Bearer ${options.token}`, 'Content-Type': 'application/json' },
65
+ body: JSON.stringify(options.request),
66
+ });
67
+ if (!answer.ok) throw await failed(answer, true);
68
+ if (take((await answer.json()) as T)) return last as T;
69
+
70
+ for (;;) {
71
+ const remaining = deadline - Date.now();
72
+ if (remaining <= 0) throw options.timeoutError(last);
73
+ const abort = new AbortController();
74
+ const timer = setTimeout(() => abort.abort(), remaining);
75
+ try {
76
+ // A restore runs for up to fifteen minutes, longer than fetch's default five-minute bound on a
77
+ // body; the deadline bounds the stream instead.
78
+ const response = await nodeProxyTransport.fetchLongRequest(url, {
79
+ headers: { Authorization: `Bearer ${options.token}`, Accept: 'text/event-stream' },
80
+ signal: abort.signal,
81
+ });
82
+ if (!response.ok) throw await failed(response, false);
83
+ if (!(response.headers.get('content-type') ?? '').includes('text/event-stream')) {
84
+ if (take((await response.json()) as T)) return last as T;
85
+ } else if (await readEvents(response, (data) => take(JSON.parse(data) as T))) {
86
+ abort.abort();
87
+ return last as T;
88
+ }
89
+ } catch (error) {
90
+ // The deadline cut the request or the stream; anything else is the daemon's answer.
91
+ if (!abort.signal.aborted) throw error;
92
+ throw options.timeoutError(last);
93
+ } finally {
94
+ clearTimeout(timer);
95
+ }
96
+ // A daemon that answered JSON is read again; a stream that ended is opened again.
97
+ await sleep(Math.min(RETRY_MS, Math.max(deadline - Date.now(), 0)));
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Reads `snapshot` events from a stream and hands each one's data to `onData` until it returns
103
+ * true, which this returns too. It returns false when the stream ends or breaks first, so the
104
+ * caller opens it again; an error from `onData` is the daemon's answer and is thrown.
105
+ */
106
+ async function readEvents(response: Response, onData: (data: string) => boolean): Promise<boolean> {
107
+ if (!response.body) return false;
108
+ const reader = response.body.getReader();
109
+ const decoder = new TextDecoder();
110
+ let buffered = '';
111
+ let event = '';
112
+ let data: string[] = [];
113
+ try {
114
+ for (;;) {
115
+ let chunk: Awaited<ReturnType<typeof reader.read>>;
116
+ try {
117
+ chunk = await reader.read();
118
+ } catch {
119
+ return false;
120
+ }
121
+ const { done, value } = chunk;
122
+ if (done) return false;
123
+ buffered += decoder.decode(value, { stream: true });
124
+ const lines = buffered.split(/\r\n|\r|\n/);
125
+ // The last piece may be half a line; it waits for the rest.
126
+ buffered = lines.pop() ?? '';
127
+ for (const line of lines) {
128
+ if (line === '') {
129
+ const dispatched = event === 'snapshot' && data.length > 0 && onData(data.join('\n'));
130
+ event = '';
131
+ data = [];
132
+ if (dispatched) return true;
133
+ } else if (line.startsWith('event:')) {
134
+ event = line.slice(6).trim();
135
+ } else if (line.startsWith('data:')) {
136
+ const value = line.slice(5);
137
+ data.push(value.startsWith(' ') ? value.slice(1) : value);
138
+ }
139
+ }
140
+ }
141
+ } finally {
142
+ reader.cancel().catch(() => undefined);
143
+ }
144
+ }
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { VERSION } from '../version';
4
2
 
5
3
  export const isRunningInBrowser = () => {
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export function isAbortError(err: unknown) {
4
2
  return (
5
3
  typeof err === 'object' &&
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { isReadonlyArray } from './utils/values';
4
2
 
5
3
  type HeaderValue = string | undefined | null;
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import type { FinalRequestOptions } from './request-options';
4
2
  import { type Limrun } from '../client';
5
3
  import { formatRequestDetails, loggerFor } from './utils/log';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { NullableHeaders } from './headers';
4
2
 
5
3
  import type { BodyInit } from './builtin-types';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * Shims for types that we can't always rely on being available globally.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export type PromiseOrValue<T> = T | Promise<T>;
4
2
  export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
5
3
 
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { LimrunError } from '../../core/error';
4
2
  import { encodeUTF8 } from './bytes';
5
3
 
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * Read an environment variable.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { hasOwn } from './values';
4
2
  import { type Limrun } from '../../client';
5
3
  import { RequestOptions } from '../request-options';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { LimrunError } from '../../core/error';
4
2
 
5
3
  /**
@@ -1,3 +1 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * https://stackoverflow.com/a/2117523
5
3
  */
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { LimrunError } from '../../core/error';
4
2
 
5
3
  // https://url.spec.whatwg.org/#url-scheme-string
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export * from './utils/values';
4
2
  export * from './utils/base64';
5
3
  export * from './utils/env';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { RequestOptions } from '../internal/request-options';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { buildHeaders } from '../internal/headers';
@@ -13,10 +13,8 @@ export type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
13
13
  // gradle responses share this exact shape (their OpenAPI schemas are
14
14
  // structurally identical), so it is defined once here and aliased per
15
15
  // resource; a platform gaining a field of its own is the signal to split the
16
- // aliases back into real interfaces. Hand-written against
17
- // api/public/director/openapiv3.yaml; if a Stainless regeneration ever picks
18
- // those paths up, reconcile with the generated surface instead of
19
- // duplicating it.
16
+ // aliases back into real interfaces. Written against
17
+ // api/public/director/openapiv3.yaml.
20
18
  export interface BuildLog {
21
19
  /** Exec ID assigned by the build daemon, e.g. build-1776140344112378000. */
22
20
  id: string;
@@ -1,15 +1,13 @@
1
1
  import { DeviceDetachUnavailableError } from '../device-detach';
2
- import { directInstanceHttpError } from '../internal/direct-instance-errors';
2
+ import { followDaemonSnapshot } from '../internal/daemon-snapshot';
3
3
  import { nodeProxyTransport } from '../internal/proxy-transport';
4
4
  import {
5
5
  GradleSnapshotRequestUnavailableError,
6
6
  GradleSnapshotTimeoutError,
7
7
  isGradleRestoreTerminal,
8
8
  type GradleInstanceSnapshot,
9
- type GradleSnapshotRequest,
10
9
  type GradleSnapshotRestoreOptions,
11
10
  } from '../gradle-snapshot';
12
- import { sleep } from '../internal/utils/sleep';
13
11
  import type { AndroidInstance } from './android-instances';
14
12
  import { pullBuildFile } from '../internal/build-pull-file';
15
13
  import { normalizeAssetUpload, type BuildUpload } from '../lib/asset-permissions';
@@ -315,45 +313,33 @@ class GradleInstancesHelpers extends GradleInstances {
315
313
  },
316
314
 
317
315
  async restoreSnapshot({ onUpdate, timeoutMs = RESTORE_TIMEOUT_MS, key, restoreKeys, encryptionKey }) {
318
- const snapshotRequest = async (body?: GradleSnapshotRequest): Promise<GradleInstanceSnapshot> => {
319
- const response = await nodeProxyTransport.fetch(`${apiUrl}/snapshot`, {
320
- method: body ? 'POST' : 'GET',
321
- headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
322
- ...(body ? { body: JSON.stringify(body) } : {}),
323
- });
324
- if (response.status === 404) {
325
- await response.text().catch(() => undefined);
326
- throw new GradleSnapshotRequestUnavailableError();
327
- }
328
- if (!response.ok) {
329
- // The body is the daemon's reason, which never repeats the encryption key.
330
- throw directInstanceHttpError(
331
- 'Disk snapshot request',
332
- response.status,
333
- (await response.text()).trim(),
334
- response.headers,
335
- );
336
- }
337
- return instanceSnapshot((await response.json()) as InstanceSnapshotReport);
338
- };
339
- const deadline = Date.now() + timeoutMs;
340
- let state = await snapshotRequest({
341
- ...(key !== undefined && { key }),
342
- ...(restoreKeys !== undefined && { restoreKeys }),
343
- ...(encryptionKey !== undefined && { encryptionKey }),
344
- });
345
316
  let reported = '';
346
- for (;;) {
347
- const seen = `${state.restore.phase}/${state.restore.reason ?? ''}`;
348
- if (seen !== reported) {
349
- reported = seen;
350
- onUpdate?.(state);
351
- }
352
- if (isGradleRestoreTerminal(state.restore.phase)) return state;
353
- if (Date.now() >= deadline) throw new GradleSnapshotTimeoutError('restore', timeoutMs, state);
354
- await sleep(1000);
355
- state = await snapshotRequest();
356
- }
317
+ let state: GradleInstanceSnapshot | undefined;
318
+ await followDaemonSnapshot<InstanceSnapshotReport>({
319
+ apiUrl,
320
+ token,
321
+ request: {
322
+ ...(key !== undefined && { key }),
323
+ ...(restoreKeys !== undefined && { restoreKeys }),
324
+ ...(encryptionKey !== undefined && { encryptionKey }),
325
+ },
326
+ timeoutMs,
327
+ onStatus: (report) => {
328
+ const current = instanceSnapshot(report);
329
+ state = current;
330
+ const seen = `${current.restore.phase}/${current.restore.reason ?? ''}/${
331
+ current.restore.doneBytes ?? ''
332
+ }`;
333
+ if (seen !== reported) {
334
+ reported = seen;
335
+ onUpdate?.(current);
336
+ }
337
+ return isGradleRestoreTerminal(current.restore.phase);
338
+ },
339
+ unavailableError: () => new GradleSnapshotRequestUnavailableError(),
340
+ timeoutError: () => new GradleSnapshotTimeoutError('restore', timeoutMs, state),
341
+ });
342
+ return state!;
357
343
  },
358
344
  };
359
345
  }
@@ -1,6 +1,3 @@
1
- // Hand-written following the Stainless resource pattern; a future generation
2
- // from the OpenAPI spec reconciles with this file.
3
-
4
1
  import { APIResource } from '../core/resource';
5
2
  import { APIPromise } from '../core/api-promise';
6
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export {
4
2
  XcodeSnapshots,
5
3
  IOSSnapshots,
@@ -140,6 +138,7 @@ export {
140
138
  type MacosSyncResult,
141
139
  type MacosFileEntry,
142
140
  type PullResult,
141
+ MacosSnapshotEncryptionUnsupportedError,
143
142
  } from './macos-instances-helpers';
144
143
 
145
144
  export {
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';