@milaboratories/pl-drivers 1.3.25 → 1.4.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 (78) hide show
  1. package/dist/clients/constructors.d.ts +14 -0
  2. package/dist/clients/constructors.d.ts.map +1 -0
  3. package/dist/clients/download.d.ts +19 -14
  4. package/dist/clients/download.d.ts.map +1 -1
  5. package/dist/clients/helpers.d.ts +4 -13
  6. package/dist/clients/helpers.d.ts.map +1 -1
  7. package/dist/clients/upload.d.ts +15 -13
  8. package/dist/clients/upload.d.ts.map +1 -1
  9. package/dist/drivers/{download_and_logs_blob.d.ts → download_blob.d.ts} +13 -40
  10. package/dist/drivers/download_blob.d.ts.map +1 -0
  11. package/dist/drivers/download_blob_task.d.ts +34 -0
  12. package/dist/drivers/download_blob_task.d.ts.map +1 -0
  13. package/dist/drivers/download_url.d.ts +11 -9
  14. package/dist/drivers/download_url.d.ts.map +1 -1
  15. package/dist/drivers/helpers/download_local_handle.d.ts +9 -0
  16. package/dist/drivers/helpers/download_local_handle.d.ts.map +1 -0
  17. package/dist/drivers/helpers/download_remote_handle.d.ts +8 -0
  18. package/dist/drivers/helpers/download_remote_handle.d.ts.map +1 -0
  19. package/dist/drivers/helpers/files_cache.d.ts +2 -1
  20. package/dist/drivers/helpers/files_cache.d.ts.map +1 -1
  21. package/dist/drivers/helpers/helpers.d.ts +2 -24
  22. package/dist/drivers/helpers/helpers.d.ts.map +1 -1
  23. package/dist/drivers/helpers/logs_handle.d.ts +13 -0
  24. package/dist/drivers/helpers/logs_handle.d.ts.map +1 -0
  25. package/dist/drivers/helpers/ls_remote_import_handle.d.ts +8 -0
  26. package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +1 -0
  27. package/dist/drivers/logs.d.ts +1 -5
  28. package/dist/drivers/logs.d.ts.map +1 -1
  29. package/dist/drivers/logs_stream.d.ts.map +1 -1
  30. package/dist/drivers/ls.d.ts.map +1 -1
  31. package/dist/drivers/types.d.ts +47 -4
  32. package/dist/drivers/types.d.ts.map +1 -1
  33. package/dist/drivers/upload.d.ts +2 -28
  34. package/dist/drivers/upload.d.ts.map +1 -1
  35. package/dist/drivers/upload_task.d.ts +41 -0
  36. package/dist/drivers/upload_task.d.ts.map +1 -0
  37. package/dist/helpers/download.d.ts +2 -2
  38. package/dist/helpers/download.d.ts.map +1 -1
  39. package/dist/index.d.ts +2 -2
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +2 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.mjs +1537 -1526
  44. package/dist/index.mjs.map +1 -1
  45. package/package.json +5 -5
  46. package/src/clients/constructors.ts +54 -0
  47. package/src/clients/download.test.ts +9 -6
  48. package/src/clients/download.ts +74 -64
  49. package/src/clients/helpers.ts +2 -53
  50. package/src/clients/upload.ts +136 -102
  51. package/src/drivers/download_blob.test.ts +12 -11
  52. package/src/drivers/{download_and_logs_blob.ts → download_blob.ts} +154 -290
  53. package/src/drivers/download_blob_task.ts +126 -0
  54. package/src/drivers/download_url.test.ts +1 -1
  55. package/src/drivers/download_url.ts +44 -37
  56. package/src/drivers/helpers/download_local_handle.ts +29 -0
  57. package/src/drivers/helpers/download_remote_handle.ts +40 -0
  58. package/src/drivers/helpers/files_cache.test.ts +7 -6
  59. package/src/drivers/helpers/files_cache.ts +6 -5
  60. package/src/drivers/helpers/helpers.ts +6 -100
  61. package/src/drivers/helpers/logs_handle.ts +52 -0
  62. package/src/drivers/helpers/ls_remote_import_handle.ts +43 -0
  63. package/src/drivers/logs.test.ts +14 -14
  64. package/src/drivers/logs.ts +3 -43
  65. package/src/drivers/logs_stream.ts +32 -6
  66. package/src/drivers/ls.test.ts +1 -2
  67. package/src/drivers/ls.ts +26 -28
  68. package/src/drivers/types.ts +48 -0
  69. package/src/drivers/upload.test.ts +8 -18
  70. package/src/drivers/upload.ts +38 -271
  71. package/src/drivers/upload_task.ts +251 -0
  72. package/src/helpers/download.ts +18 -15
  73. package/src/index.ts +2 -2
  74. package/dist/drivers/download_and_logs_blob.d.ts.map +0 -1
  75. package/dist/drivers/helpers/ls_list_entry.d.ts +0 -44
  76. package/dist/drivers/helpers/ls_list_entry.d.ts.map +0 -1
  77. package/src/drivers/helpers/ls_list_entry.test.ts +0 -55
  78. package/src/drivers/helpers/ls_list_entry.ts +0 -147
package/dist/index.mjs CHANGED
@@ -1,32 +1,34 @@
1
- var je = Object.defineProperty;
2
- var Ge = (s, e, t) => e in s ? je(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var d = (s, e, t) => Ge(s, typeof e != "symbol" ? e + "" : e, t);
1
+ var Ze = Object.defineProperty;
2
+ var Qe = (s, e, t) => e in s ? Ze(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var d = (s, e, t) => Qe(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { addRTypeToMetadata as T, bigintToResourceId as ee, stringifyWithResourceId as ye, resourceIdToString as Xe, isNotNullResourceId as Ye } from "@milaboratories/pl-client";
4
5
  import * as m from "node:fs/promises";
5
- import { addRTypeToMetadata as k, valErr as Ve, getField as qe, isNullResourceId as Je, bigintToResourceId as Y, stringifyWithResourceId as be, resourceIdToString as Ze, isNotNullResourceId as Qe } from "@milaboratories/pl-client";
6
+ import { request as be } from "undici";
6
7
  import { ServiceType as D, stackIntercept as y } from "@protobuf-ts/runtime-rpc";
7
- import { MessageType as g, reflectionMergePartial as f, UnknownFieldHandler as u, WireType as h, PbLong as I, typeofJsonValue as Te } from "@protobuf-ts/runtime";
8
- import { request as ke } from "undici";
9
- import { notEmpty as K, mapGet as ce, mapEntries as Xe, TaskProcessor as ee, CallersCounter as v, asyncPool as te, fileExists as Ye, assertNever as Ke } from "@milaboratories/ts-helpers";
10
- import { Readable as re, Writable as ne, Transform as et } from "node:stream";
11
- import * as O from "node:fs";
8
+ import { MessageType as g, reflectionMergePartial as f, UnknownFieldHandler as u, WireType as h, PbLong as P, typeofJsonValue as ke } from "@protobuf-ts/runtime";
9
+ import { notEmpty as te, CallersCounter as B, ensureDirExists as Te, fileExists as Le, createPathAtomically as Pe, mapGet as he, mapEntries as Ke, TaskProcessor as re, asyncPool as ne, assertNever as et } from "@milaboratories/ts-helpers";
10
+ import * as oe from "node:fs";
11
+ import tt from "node:fs";
12
12
  import * as w from "node:path";
13
- import Z from "node:path";
14
- import { text as tt, buffer as Le } from "node:stream/consumers";
15
- import { Computable as b, ChangeSource as N, PollingComputableHooks as Pe } from "@milaboratories/computable";
16
- import { scheduler as oe } from "node:timers/promises";
17
- import * as rt from "node:readline/promises";
18
- import nt from "denque";
19
- import * as de from "node:os";
20
- import ot from "node:os";
21
- import { randomUUID as L, createHash as st } from "node:crypto";
22
- import { rsSchema as se, treeEntryToResourceInfo as R, isPlTreeEntry as ie, makeResourceSnapshot as Q, isPlTreeEntryAccessor as it } from "@milaboratories/pl-tree";
23
- import { z as T } from "zod";
24
- import * as at from "node:zlib";
25
- import * as lt from "tar-fs";
26
- import { isImportFileHandleIndex as ct } from "@milaboratories/pl-model-common";
27
- import dt from "node:util";
28
- import { exec as ht } from "node:child_process";
29
- class ut extends g {
13
+ import Q from "node:path";
14
+ import { Readable as se, Writable as ie, Transform as rt } from "node:stream";
15
+ import { text as nt, buffer as Ie } from "node:stream/consumers";
16
+ import { ChangeSource as v, Computable as b, PollingComputableHooks as Re } from "@milaboratories/computable";
17
+ import { rsSchema as ae, treeEntryToResourceInfo as I, isPlTreeEntry as le, makeResourceSnapshot as X, isPlTreeEntryAccessor as ot } from "@milaboratories/pl-tree";
18
+ import st from "denque";
19
+ import { randomUUID as L, createHash as it } from "node:crypto";
20
+ import * as ue from "node:os";
21
+ import at from "node:os";
22
+ import * as lt from "node:readline/promises";
23
+ import { z as k } from "zod";
24
+ import { scheduler as Se } from "node:timers/promises";
25
+ import ct from "node:assert";
26
+ import * as dt from "node:zlib";
27
+ import * as ht from "tar-fs";
28
+ import { isImportFileHandleIndex as ut } from "@milaboratories/pl-model-common";
29
+ import pt from "node:util";
30
+ import { exec as gt } from "node:child_process";
31
+ class ft extends g {
30
32
  constructor() {
31
33
  super("MiLaboratories.Controller.Shared.uploadapi", []);
32
34
  }
@@ -34,20 +36,20 @@ class ut extends g {
34
36
  const t = globalThis.Object.create(this.messagePrototype);
35
37
  return e !== void 0 && f(this, t, e), t;
36
38
  }
37
- internalBinaryRead(e, t, n, r) {
38
- return r ?? this.create();
39
+ internalBinaryRead(e, t, r, n) {
40
+ return n ?? this.create();
39
41
  }
40
- internalBinaryWrite(e, t, n) {
41
- let r = n.writeUnknownFields;
42
- return r !== !1 && (r == !0 ? u.onWrite : r)(
42
+ internalBinaryWrite(e, t, r) {
43
+ let n = r.writeUnknownFields;
44
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
43
45
  this.typeName,
44
46
  e,
45
47
  t
46
48
  ), t;
47
49
  }
48
50
  }
49
- new ut();
50
- class pt extends g {
51
+ new ft();
52
+ class mt extends g {
51
53
  constructor() {
52
54
  super("MiLaboratories.Controller.Shared.uploadapi.Init", []);
53
55
  }
@@ -55,20 +57,20 @@ class pt extends g {
55
57
  const t = globalThis.Object.create(this.messagePrototype);
56
58
  return e !== void 0 && f(this, t, e), t;
57
59
  }
58
- internalBinaryRead(e, t, n, r) {
59
- return r ?? this.create();
60
+ internalBinaryRead(e, t, r, n) {
61
+ return n ?? this.create();
60
62
  }
61
- internalBinaryWrite(e, t, n) {
62
- let r = n.writeUnknownFields;
63
- return r !== !1 && (r == !0 ? u.onWrite : r)(
63
+ internalBinaryWrite(e, t, r) {
64
+ let n = r.writeUnknownFields;
65
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
64
66
  this.typeName,
65
67
  e,
66
68
  t
67
69
  ), t;
68
70
  }
69
71
  }
70
- new pt();
71
- class gt extends g {
72
+ new mt();
73
+ class wt extends g {
72
74
  constructor() {
73
75
  super("MiLaboratories.Controller.Shared.uploadapi.Init.Request", [
74
76
  {
@@ -85,9 +87,9 @@ class gt extends g {
85
87
  const t = globalThis.Object.create(this.messagePrototype);
86
88
  return t.resourceId = 0n, e !== void 0 && f(this, t, e), t;
87
89
  }
88
- internalBinaryRead(e, t, n, r) {
89
- let o = r ?? this.create(), a = e.pos + t;
90
- for (; e.pos < a; ) {
90
+ internalBinaryRead(e, t, r, n) {
91
+ let o = n ?? this.create(), l = e.pos + t;
92
+ for (; e.pos < l; ) {
91
93
  let [i, c] = e.tag();
92
94
  switch (i) {
93
95
  case /* uint64 resource_id */
@@ -95,13 +97,13 @@ class gt extends g {
95
97
  o.resourceId = e.uint64().toBigInt();
96
98
  break;
97
99
  default:
98
- let l = n.readUnknownField;
99
- if (l === "throw")
100
+ let a = r.readUnknownField;
101
+ if (a === "throw")
100
102
  throw new globalThis.Error(
101
103
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
102
104
  );
103
105
  let p = e.skip(c);
104
- l !== !1 && (l === !0 ? u.onRead : l)(
106
+ a !== !1 && (a === !0 ? u.onRead : a)(
105
107
  this.typeName,
106
108
  o,
107
109
  i,
@@ -112,18 +114,18 @@ class gt extends g {
112
114
  }
113
115
  return o;
114
116
  }
115
- internalBinaryWrite(e, t, n) {
117
+ internalBinaryWrite(e, t, r) {
116
118
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId);
117
- let r = n.writeUnknownFields;
118
- return r !== !1 && (r == !0 ? u.onWrite : r)(
119
+ let n = r.writeUnknownFields;
120
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
119
121
  this.typeName,
120
122
  e,
121
123
  t
122
124
  ), t;
123
125
  }
124
126
  }
125
- const ft = new gt();
126
- class mt extends g {
127
+ const yt = new wt();
128
+ class bt extends g {
127
129
  constructor() {
128
130
  super("MiLaboratories.Controller.Shared.uploadapi.Init.Response", [
129
131
  {
@@ -149,9 +151,9 @@ class mt extends g {
149
151
  const t = globalThis.Object.create(this.messagePrototype);
150
152
  return t.partsCount = 0n, t.uploadedParts = [], e !== void 0 && f(this, t, e), t;
151
153
  }
152
- internalBinaryRead(e, t, n, r) {
153
- let o = r ?? this.create(), a = e.pos + t;
154
- for (; e.pos < a; ) {
154
+ internalBinaryRead(e, t, r, n) {
155
+ let o = n ?? this.create(), l = e.pos + t;
156
+ for (; e.pos < l; ) {
155
157
  let [i, c] = e.tag();
156
158
  switch (i) {
157
159
  case /* uint64 parts_count */
@@ -161,18 +163,18 @@ class mt extends g {
161
163
  case /* repeated uint64 uploaded_parts */
162
164
  2:
163
165
  if (c === h.LengthDelimited)
164
- for (let P = e.int32() + e.pos; e.pos < P; )
166
+ for (let F = e.int32() + e.pos; e.pos < F; )
165
167
  o.uploadedParts.push(e.uint64().toBigInt());
166
168
  else o.uploadedParts.push(e.uint64().toBigInt());
167
169
  break;
168
170
  default:
169
- let l = n.readUnknownField;
170
- if (l === "throw")
171
+ let a = r.readUnknownField;
172
+ if (a === "throw")
171
173
  throw new globalThis.Error(
172
174
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
173
175
  );
174
176
  let p = e.skip(c);
175
- l !== !1 && (l === !0 ? u.onRead : l)(
177
+ a !== !1 && (a === !0 ? u.onRead : a)(
176
178
  this.typeName,
177
179
  o,
178
180
  i,
@@ -183,23 +185,23 @@ class mt extends g {
183
185
  }
184
186
  return o;
185
187
  }
186
- internalBinaryWrite(e, t, n) {
188
+ internalBinaryWrite(e, t, r) {
187
189
  if (e.partsCount !== 0n && t.tag(1, h.Varint).uint64(e.partsCount), e.uploadedParts.length) {
188
190
  t.tag(2, h.LengthDelimited).fork();
189
191
  for (let o = 0; o < e.uploadedParts.length; o++)
190
192
  t.uint64(e.uploadedParts[o]);
191
193
  t.join();
192
194
  }
193
- let r = n.writeUnknownFields;
194
- return r !== !1 && (r == !0 ? u.onWrite : r)(
195
+ let n = r.writeUnknownFields;
196
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
195
197
  this.typeName,
196
198
  e,
197
199
  t
198
200
  ), t;
199
201
  }
200
202
  }
201
- const wt = new mt();
202
- class yt extends g {
203
+ const kt = new bt();
204
+ class Tt extends g {
203
205
  constructor() {
204
206
  super("MiLaboratories.Controller.Shared.uploadapi.UpdateProgress", []);
205
207
  }
@@ -207,20 +209,20 @@ class yt extends g {
207
209
  const t = globalThis.Object.create(this.messagePrototype);
208
210
  return e !== void 0 && f(this, t, e), t;
209
211
  }
210
- internalBinaryRead(e, t, n, r) {
211
- return r ?? this.create();
212
+ internalBinaryRead(e, t, r, n) {
213
+ return n ?? this.create();
212
214
  }
213
- internalBinaryWrite(e, t, n) {
214
- let r = n.writeUnknownFields;
215
- return r !== !1 && (r == !0 ? u.onWrite : r)(
215
+ internalBinaryWrite(e, t, r) {
216
+ let n = r.writeUnknownFields;
217
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
216
218
  this.typeName,
217
219
  e,
218
220
  t
219
221
  ), t;
220
222
  }
221
223
  }
222
- new yt();
223
- class bt extends g {
224
+ new Tt();
225
+ class Lt extends g {
224
226
  constructor() {
225
227
  super("MiLaboratories.Controller.Shared.uploadapi.UpdateProgress.Request", [
226
228
  {
@@ -249,9 +251,9 @@ class bt extends g {
249
251
  e
250
252
  ), t;
251
253
  }
252
- internalBinaryRead(e, t, n, r) {
253
- let o = r ?? this.create(), a = e.pos + t;
254
- for (; e.pos < a; ) {
254
+ internalBinaryRead(e, t, r, n) {
255
+ let o = n ?? this.create(), l = e.pos + t;
256
+ for (; e.pos < l; ) {
255
257
  let [i, c] = e.tag();
256
258
  switch (i) {
257
259
  case /* uint64 resource_id */
@@ -263,13 +265,13 @@ class bt extends g {
263
265
  o.bytesProcessed = e.int64().toBigInt();
264
266
  break;
265
267
  default:
266
- let l = n.readUnknownField;
267
- if (l === "throw")
268
+ let a = r.readUnknownField;
269
+ if (a === "throw")
268
270
  throw new globalThis.Error(
269
271
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
270
272
  );
271
273
  let p = e.skip(c);
272
- l !== !1 && (l === !0 ? u.onRead : l)(
274
+ a !== !1 && (a === !0 ? u.onRead : a)(
273
275
  this.typeName,
274
276
  o,
275
277
  i,
@@ -280,18 +282,18 @@ class bt extends g {
280
282
  }
281
283
  return o;
282
284
  }
283
- internalBinaryWrite(e, t, n) {
285
+ internalBinaryWrite(e, t, r) {
284
286
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.bytesProcessed !== 0n && t.tag(2, h.Varint).int64(e.bytesProcessed);
285
- let r = n.writeUnknownFields;
286
- return r !== !1 && (r == !0 ? u.onWrite : r)(
287
+ let n = r.writeUnknownFields;
288
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
287
289
  this.typeName,
288
290
  e,
289
291
  t
290
292
  ), t;
291
293
  }
292
294
  }
293
- const Tt = new bt();
294
- class kt extends g {
295
+ const Pt = new Lt();
296
+ class It extends g {
295
297
  constructor() {
296
298
  super(
297
299
  "MiLaboratories.Controller.Shared.uploadapi.UpdateProgress.Response",
@@ -306,20 +308,20 @@ class kt extends g {
306
308
  e
307
309
  ), t;
308
310
  }
309
- internalBinaryRead(e, t, n, r) {
310
- return r ?? this.create();
311
+ internalBinaryRead(e, t, r, n) {
312
+ return n ?? this.create();
311
313
  }
312
- internalBinaryWrite(e, t, n) {
313
- let r = n.writeUnknownFields;
314
- return r !== !1 && (r == !0 ? u.onWrite : r)(
314
+ internalBinaryWrite(e, t, r) {
315
+ let n = r.writeUnknownFields;
316
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
315
317
  this.typeName,
316
318
  e,
317
319
  t
318
320
  ), t;
319
321
  }
320
322
  }
321
- const Lt = new kt();
322
- class Pt extends g {
323
+ const Rt = new It();
324
+ class St extends g {
323
325
  constructor() {
324
326
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL", []);
325
327
  }
@@ -327,20 +329,20 @@ class Pt extends g {
327
329
  const t = globalThis.Object.create(this.messagePrototype);
328
330
  return e !== void 0 && f(this, t, e), t;
329
331
  }
330
- internalBinaryRead(e, t, n, r) {
331
- return r ?? this.create();
332
+ internalBinaryRead(e, t, r, n) {
333
+ return n ?? this.create();
332
334
  }
333
- internalBinaryWrite(e, t, n) {
334
- let r = n.writeUnknownFields;
335
- return r !== !1 && (r == !0 ? u.onWrite : r)(
335
+ internalBinaryWrite(e, t, r) {
336
+ let n = r.writeUnknownFields;
337
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
336
338
  this.typeName,
337
339
  e,
338
340
  t
339
341
  ), t;
340
342
  }
341
343
  }
342
- new Pt();
343
- class It extends g {
344
+ new St();
345
+ class Ut extends g {
344
346
  constructor() {
345
347
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL.Request", [
346
348
  {
@@ -377,9 +379,9 @@ class It extends g {
377
379
  e
378
380
  ), t;
379
381
  }
380
- internalBinaryRead(e, t, n, r) {
381
- let o = r ?? this.create(), a = e.pos + t;
382
- for (; e.pos < a; ) {
382
+ internalBinaryRead(e, t, r, n) {
383
+ let o = n ?? this.create(), l = e.pos + t;
384
+ for (; e.pos < l; ) {
383
385
  let [i, c] = e.tag();
384
386
  switch (i) {
385
387
  case /* uint64 resource_id */
@@ -395,13 +397,13 @@ class It extends g {
395
397
  o.uploadedPartSize = e.uint64().toBigInt();
396
398
  break;
397
399
  default:
398
- let l = n.readUnknownField;
399
- if (l === "throw")
400
+ let a = r.readUnknownField;
401
+ if (a === "throw")
400
402
  throw new globalThis.Error(
401
403
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
402
404
  );
403
405
  let p = e.skip(c);
404
- l !== !1 && (l === !0 ? u.onRead : l)(
406
+ a !== !1 && (a === !0 ? u.onRead : a)(
405
407
  this.typeName,
406
408
  o,
407
409
  i,
@@ -412,18 +414,18 @@ class It extends g {
412
414
  }
413
415
  return o;
414
416
  }
415
- internalBinaryWrite(e, t, n) {
417
+ internalBinaryWrite(e, t, r) {
416
418
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.partNumber !== 0n && t.tag(2, h.Varint).uint64(e.partNumber), e.uploadedPartSize !== 0n && t.tag(3, h.Varint).uint64(e.uploadedPartSize);
417
- let r = n.writeUnknownFields;
418
- return r !== !1 && (r == !0 ? u.onWrite : r)(
419
+ let n = r.writeUnknownFields;
420
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
419
421
  this.typeName,
420
422
  e,
421
423
  t
422
424
  ), t;
423
425
  }
424
426
  }
425
- const Rt = new It();
426
- class St extends g {
427
+ const Nt = new Ut();
428
+ class Dt extends g {
427
429
  constructor() {
428
430
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL.HTTPHeader", [
429
431
  {
@@ -452,9 +454,9 @@ class St extends g {
452
454
  e
453
455
  ), t;
454
456
  }
455
- internalBinaryRead(e, t, n, r) {
456
- let o = r ?? this.create(), a = e.pos + t;
457
- for (; e.pos < a; ) {
457
+ internalBinaryRead(e, t, r, n) {
458
+ let o = n ?? this.create(), l = e.pos + t;
459
+ for (; e.pos < l; ) {
458
460
  let [i, c] = e.tag();
459
461
  switch (i) {
460
462
  case /* string Name = 1 [json_name = "Name"];*/
@@ -466,13 +468,13 @@ class St extends g {
466
468
  o.value = e.string();
467
469
  break;
468
470
  default:
469
- let l = n.readUnknownField;
470
- if (l === "throw")
471
+ let a = r.readUnknownField;
472
+ if (a === "throw")
471
473
  throw new globalThis.Error(
472
474
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
473
475
  );
474
476
  let p = e.skip(c);
475
- l !== !1 && (l === !0 ? u.onRead : l)(
477
+ a !== !1 && (a === !0 ? u.onRead : a)(
476
478
  this.typeName,
477
479
  o,
478
480
  i,
@@ -483,18 +485,18 @@ class St extends g {
483
485
  }
484
486
  return o;
485
487
  }
486
- internalBinaryWrite(e, t, n) {
488
+ internalBinaryWrite(e, t, r) {
487
489
  e.name !== "" && t.tag(1, h.LengthDelimited).string(e.name), e.value !== "" && t.tag(2, h.LengthDelimited).string(e.value);
488
- let r = n.writeUnknownFields;
489
- return r !== !1 && (r == !0 ? u.onWrite : r)(
490
+ let n = r.writeUnknownFields;
491
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
490
492
  this.typeName,
491
493
  e,
492
494
  t
493
495
  ), t;
494
496
  }
495
497
  }
496
- const E = new St();
497
- class Nt extends g {
498
+ const E = new Dt();
499
+ class Bt extends g {
498
500
  constructor() {
499
501
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL.Response", [
500
502
  {
@@ -544,9 +546,9 @@ class Nt extends g {
544
546
  e
545
547
  ), t;
546
548
  }
547
- internalBinaryRead(e, t, n, r) {
548
- let o = r ?? this.create(), a = e.pos + t;
549
- for (; e.pos < a; ) {
549
+ internalBinaryRead(e, t, r, n) {
550
+ let o = n ?? this.create(), l = e.pos + t;
551
+ for (; e.pos < l; ) {
550
552
  let [i, c] = e.tag();
551
553
  switch (i) {
552
554
  case /* string upload_url */
@@ -563,7 +565,7 @@ class Nt extends g {
563
565
  E.internalBinaryRead(
564
566
  e,
565
567
  e.uint32(),
566
- n
568
+ r
567
569
  )
568
570
  );
569
571
  break;
@@ -576,13 +578,13 @@ class Nt extends g {
576
578
  o.chunkEnd = e.uint64().toBigInt();
577
579
  break;
578
580
  default:
579
- let l = n.readUnknownField;
580
- if (l === "throw")
581
+ let a = r.readUnknownField;
582
+ if (a === "throw")
581
583
  throw new globalThis.Error(
582
584
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
583
585
  );
584
586
  let p = e.skip(c);
585
- l !== !1 && (l === !0 ? u.onRead : l)(
587
+ a !== !1 && (a === !0 ? u.onRead : a)(
586
588
  this.typeName,
587
589
  o,
588
590
  i,
@@ -593,25 +595,25 @@ class Nt extends g {
593
595
  }
594
596
  return o;
595
597
  }
596
- internalBinaryWrite(e, t, n) {
598
+ internalBinaryWrite(e, t, r) {
597
599
  e.uploadUrl !== "" && t.tag(1, h.LengthDelimited).string(e.uploadUrl), e.method !== "" && t.tag(2, h.LengthDelimited).string(e.method);
598
600
  for (let o = 0; o < e.headers.length; o++)
599
601
  E.internalBinaryWrite(
600
602
  e.headers[o],
601
603
  t.tag(3, h.LengthDelimited).fork(),
602
- n
604
+ r
603
605
  ).join();
604
606
  e.chunkStart !== 0n && t.tag(4, h.Varint).uint64(e.chunkStart), e.chunkEnd !== 0n && t.tag(5, h.Varint).uint64(e.chunkEnd);
605
- let r = n.writeUnknownFields;
606
- return r !== !1 && (r == !0 ? u.onWrite : r)(
607
+ let n = r.writeUnknownFields;
608
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
607
609
  this.typeName,
608
610
  e,
609
611
  t
610
612
  ), t;
611
613
  }
612
614
  }
613
- const Ut = new Nt();
614
- class Bt extends g {
615
+ const vt = new Bt();
616
+ class $t extends g {
615
617
  constructor() {
616
618
  super("MiLaboratories.Controller.Shared.uploadapi.Finalize", []);
617
619
  }
@@ -619,20 +621,20 @@ class Bt extends g {
619
621
  const t = globalThis.Object.create(this.messagePrototype);
620
622
  return e !== void 0 && f(this, t, e), t;
621
623
  }
622
- internalBinaryRead(e, t, n, r) {
623
- return r ?? this.create();
624
+ internalBinaryRead(e, t, r, n) {
625
+ return n ?? this.create();
624
626
  }
625
- internalBinaryWrite(e, t, n) {
626
- let r = n.writeUnknownFields;
627
- return r !== !1 && (r == !0 ? u.onWrite : r)(
627
+ internalBinaryWrite(e, t, r) {
628
+ let n = r.writeUnknownFields;
629
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
628
630
  this.typeName,
629
631
  e,
630
632
  t
631
633
  ), t;
632
634
  }
633
635
  }
634
- new Bt();
635
- class Dt extends g {
636
+ new $t();
637
+ class _t extends g {
636
638
  constructor() {
637
639
  super("MiLaboratories.Controller.Shared.uploadapi.Finalize.Request", [
638
640
  {
@@ -649,9 +651,9 @@ class Dt extends g {
649
651
  const t = globalThis.Object.create(this.messagePrototype);
650
652
  return t.resourceId = 0n, e !== void 0 && f(this, t, e), t;
651
653
  }
652
- internalBinaryRead(e, t, n, r) {
653
- let o = r ?? this.create(), a = e.pos + t;
654
- for (; e.pos < a; ) {
654
+ internalBinaryRead(e, t, r, n) {
655
+ let o = n ?? this.create(), l = e.pos + t;
656
+ for (; e.pos < l; ) {
655
657
  let [i, c] = e.tag();
656
658
  switch (i) {
657
659
  case /* uint64 resource_id */
@@ -659,13 +661,13 @@ class Dt extends g {
659
661
  o.resourceId = e.uint64().toBigInt();
660
662
  break;
661
663
  default:
662
- let l = n.readUnknownField;
663
- if (l === "throw")
664
+ let a = r.readUnknownField;
665
+ if (a === "throw")
664
666
  throw new globalThis.Error(
665
667
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
666
668
  );
667
669
  let p = e.skip(c);
668
- l !== !1 && (l === !0 ? u.onRead : l)(
670
+ a !== !1 && (a === !0 ? u.onRead : a)(
669
671
  this.typeName,
670
672
  o,
671
673
  i,
@@ -676,18 +678,18 @@ class Dt extends g {
676
678
  }
677
679
  return o;
678
680
  }
679
- internalBinaryWrite(e, t, n) {
681
+ internalBinaryWrite(e, t, r) {
680
682
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId);
681
- let r = n.writeUnknownFields;
682
- return r !== !1 && (r == !0 ? u.onWrite : r)(
683
+ let n = r.writeUnknownFields;
684
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
683
685
  this.typeName,
684
686
  e,
685
687
  t
686
688
  ), t;
687
689
  }
688
690
  }
689
- const vt = new Dt();
690
- class $t extends g {
691
+ const Ct = new _t();
692
+ class Ot extends g {
691
693
  constructor() {
692
694
  super("MiLaboratories.Controller.Shared.uploadapi.Finalize.Response", []);
693
695
  }
@@ -695,48 +697,48 @@ class $t extends g {
695
697
  const t = globalThis.Object.create(this.messagePrototype);
696
698
  return e !== void 0 && f(this, t, e), t;
697
699
  }
698
- internalBinaryRead(e, t, n, r) {
699
- return r ?? this.create();
700
+ internalBinaryRead(e, t, r, n) {
701
+ return n ?? this.create();
700
702
  }
701
- internalBinaryWrite(e, t, n) {
702
- let r = n.writeUnknownFields;
703
- return r !== !1 && (r == !0 ? u.onWrite : r)(
703
+ internalBinaryWrite(e, t, r) {
704
+ let n = r.writeUnknownFields;
705
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
704
706
  this.typeName,
705
707
  e,
706
708
  t
707
709
  ), t;
708
710
  }
709
711
  }
710
- const _t = new $t(), W = new D(
712
+ const Ft = new Ot(), W = new D(
711
713
  "MiLaboratories.Controller.Shared.Upload",
712
714
  [
713
715
  {
714
716
  name: "Init",
715
717
  options: {},
716
- I: ft,
717
- O: wt
718
+ I: yt,
719
+ O: kt
718
720
  },
719
721
  {
720
722
  name: "GetPartURL",
721
723
  options: {},
722
- I: Rt,
723
- O: Ut
724
+ I: Nt,
725
+ O: vt
724
726
  },
725
727
  {
726
728
  name: "UpdateProgress",
727
729
  options: {},
728
- I: Tt,
729
- O: Lt
730
+ I: Pt,
731
+ O: Rt
730
732
  },
731
733
  {
732
734
  name: "Finalize",
733
735
  options: {},
734
- I: vt,
735
- O: _t
736
+ I: Ct,
737
+ O: Ft
736
738
  }
737
739
  ]
738
740
  );
739
- class Ct {
741
+ class Et {
740
742
  constructor(e) {
741
743
  d(this, "typeName", W.typeName);
742
744
  d(this, "methods", W.methods);
@@ -751,12 +753,12 @@ class Ct {
751
753
  * @generated from protobuf rpc: Init(MiLaboratories.Controller.Shared.uploadapi.Init.Request) returns (MiLaboratories.Controller.Shared.uploadapi.Init.Response);
752
754
  */
753
755
  init(e, t) {
754
- const n = this.methods[0], r = this._transport.mergeOptions(t);
756
+ const r = this.methods[0], n = this._transport.mergeOptions(t);
755
757
  return y(
756
758
  "unary",
757
759
  this._transport,
758
- n,
759
760
  r,
761
+ n,
760
762
  e
761
763
  );
762
764
  }
@@ -769,8 +771,8 @@ class Ct {
769
771
  * @generated from protobuf rpc: GetPartURL(MiLaboratories.Controller.Shared.uploadapi.GetPartURL.Request) returns (MiLaboratories.Controller.Shared.uploadapi.GetPartURL.Response);
770
772
  */
771
773
  getPartURL(e, t) {
772
- const n = this.methods[1], r = this._transport.mergeOptions(t);
773
- return y("unary", this._transport, n, r, e);
774
+ const r = this.methods[1], n = this._transport.mergeOptions(t);
775
+ return y("unary", this._transport, r, n, e);
774
776
  }
775
777
  /**
776
778
  *
@@ -780,8 +782,8 @@ class Ct {
780
782
  * @generated from protobuf rpc: UpdateProgress(MiLaboratories.Controller.Shared.uploadapi.UpdateProgress.Request) returns (MiLaboratories.Controller.Shared.uploadapi.UpdateProgress.Response);
781
783
  */
782
784
  updateProgress(e, t) {
783
- const n = this.methods[2], r = this._transport.mergeOptions(t);
784
- return y("unary", this._transport, n, r, e);
785
+ const r = this.methods[2], n = this._transport.mergeOptions(t);
786
+ return y("unary", this._transport, r, n, e);
785
787
  }
786
788
  /**
787
789
  *
@@ -793,112 +795,128 @@ class Ct {
793
795
  * @generated from protobuf rpc: Finalize(MiLaboratories.Controller.Shared.uploadapi.Finalize.Request) returns (MiLaboratories.Controller.Shared.uploadapi.Finalize.Response);
794
796
  */
795
797
  finalize(e, t) {
796
- const n = this.methods[3], r = this._transport.mergeOptions(t);
797
- return y("unary", this._transport, n, r, e);
798
+ const r = this.methods[3], n = this._transport.mergeOptions(t);
799
+ return y("unary", this._transport, r, n, e);
798
800
  }
799
801
  }
800
- class Ie extends Error {
802
+ function Ue(s) {
803
+ return Object.fromEntries(s.map(({ name: e, value: t }) => [e, t]));
804
+ }
805
+ class Ne extends Error {
801
806
  }
802
- class Re extends Error {
807
+ class De extends Error {
803
808
  }
804
- class Ot extends Error {
809
+ class Wt extends Error {
805
810
  }
806
- class Se extends Error {
811
+ class Be extends Error {
807
812
  }
808
- class Ft {
809
- constructor(e, t, n, r) {
813
+ class At {
814
+ constructor(e, t, r, n) {
810
815
  d(this, "grpcClient");
811
- this.grpcTransport = e, this.httpClient = t, this.logger = r, this.grpcClient = new Ct(this.grpcTransport);
816
+ this.grpcTransport = e, this.httpClient = t, this.logger = n, this.grpcClient = new Et(this.grpcTransport);
812
817
  }
813
818
  close() {
814
819
  }
815
- async initUpload({ id: e, type: t }, n) {
816
- const r = await this.grpcClient.init({ resourceId: e }, k(t, n));
817
- return this.partsToUpload(r.response);
820
+ async initUpload({ id: e, type: t }, r) {
821
+ const n = await this.grpcInit(e, t, r);
822
+ return {
823
+ overall: n.partsCount,
824
+ toUpload: this.partsToUpload(n.partsCount, n.uploadedParts)
825
+ };
818
826
  }
819
- async partUpload({ id: e, type: t }, n, r, o, a, i) {
820
- const c = await this.grpcClient.getPartURL(
821
- {
822
- resourceId: e,
823
- partNumber: r,
824
- uploadedPartSize: 0n
825
- // we update progress as a separate call later.
826
- },
827
- k(t, i)
828
- ).response, { chunk: l, mTime: p } = await this.readChunk(n, c.chunkStart, c.chunkEnd);
829
- if (p > a)
830
- throw new Ie(
831
- "file was modified, expected mtime: " + a + ", got: " + p + "."
832
- );
833
- const P = await ke(c.uploadUrl, this.prepareUploadOpts(c, l)), le = await P.body.text();
834
- if (this.logger.info(
835
- `uploaded chunk ${r} from ${o} of resource: ${e}, response: '${le.toString()}', status code: ${P.statusCode}`
836
- ), P.statusCode != 200)
837
- throw new Ot(
838
- `response is not ok, status code: ${P.statusCode}, body: ${le}, headers: ${P.headers}, url: ${c.uploadUrl}`
839
- );
827
+ async partUpload({ id: e, type: t }, r, n, o, l) {
828
+ const i = await this.grpcGetPartUrl(
829
+ { id: e, type: t },
830
+ o,
831
+ 0n,
832
+ // we update progress as a separate call later.
833
+ l
834
+ ), c = await xt(r, i.chunkStart, i.chunkEnd);
835
+ await Mt(r, n);
836
+ const {
837
+ body: a,
838
+ statusCode: p,
839
+ headers: F
840
+ } = await be(i.uploadUrl, {
841
+ dispatcher: this.httpClient,
842
+ body: c,
843
+ headers: Ue(i.headers),
844
+ method: i.method.toUpperCase()
845
+ }), Je = await a.text();
846
+ Ht(p, Je, F, i), await this.grpcUpdateProgress({ id: e, type: t }, i.chunkEnd - i.chunkStart, l);
847
+ }
848
+ async finalize(e, t) {
849
+ return await this.grpcFinalize(e, t);
850
+ }
851
+ /** Calculates parts that need to be uploaded from the parts that were
852
+ * already uploaded. */
853
+ partsToUpload(e, t) {
854
+ const r = [], n = new Set(t);
855
+ for (let o = 1n; o <= e; o++)
856
+ n.has(o) || r.push(o);
857
+ return r;
858
+ }
859
+ async grpcInit(e, t, r) {
860
+ return await this.grpcClient.init({ resourceId: e }, T(t, r)).response;
861
+ }
862
+ async grpcGetPartUrl({ id: e, type: t }, r, n, o) {
863
+ return await this.grpcClient.getPartURL(
864
+ { resourceId: e, partNumber: r, uploadedPartSize: n },
865
+ T(t, o)
866
+ ).response;
867
+ }
868
+ async grpcUpdateProgress({ id: e, type: t }, r, n) {
840
869
  await this.grpcClient.updateProgress(
841
870
  {
842
871
  resourceId: e,
843
- bytesProcessed: c.chunkEnd - c.chunkStart
872
+ bytesProcessed: r
844
873
  },
845
- k(t, i)
846
- );
847
- }
848
- async finalizeUpload({ id: e, type: t }, n) {
849
- return await this.grpcClient.finalize({ resourceId: e }, k(t, n));
850
- }
851
- async readChunk(e, t, n) {
852
- let r;
853
- try {
854
- r = await m.open(e);
855
- const o = Number(n - t), a = Number(t), i = Buffer.alloc(o), c = await this.readBytesFromPosition(r, i, o, a), l = await m.stat(e);
856
- return {
857
- chunk: i.subarray(0, c),
858
- mTime: BigInt(Math.floor(l.mtimeMs / 1e3))
859
- };
860
- } catch (o) {
861
- throw o.code == "ENOENT" ? new Se(`there is no file ${e} for uploading`) : o;
862
- } finally {
863
- r == null || r.close();
864
- }
874
+ T(t, n)
875
+ ).response;
865
876
  }
866
- /** Read len bytes from a given position. The reason the method exists
867
- is that FileHandle.read can read less bytes than it's needed. */
868
- async readBytesFromPosition(e, t, n, r) {
869
- let o = 0;
870
- for (; o < n; ) {
871
- const { bytesRead: a } = await e.read(
872
- t,
873
- o,
874
- n - o,
875
- r + o
876
- );
877
- if (a === 0)
878
- throw new Re("file ended earlier than expected.");
879
- o += a;
880
- }
881
- return o;
877
+ async grpcFinalize({ id: e, type: t }, r) {
878
+ return await this.grpcClient.finalize({ resourceId: e }, T(t, r)).response;
882
879
  }
883
- /** Calculates parts that need to be uploaded from the parts that were
884
- * already uploaded. */
885
- partsToUpload(e) {
886
- const t = [], n = new Set(e.uploadedParts);
887
- for (let r = 1n; r <= e.partsCount; r++)
888
- n.has(r) || t.push(r);
889
- return t;
880
+ }
881
+ async function xt(s, e, t) {
882
+ let r;
883
+ try {
884
+ r = await m.open(s);
885
+ const n = Number(t - e), o = Number(e), l = Buffer.alloc(n), i = await zt(r, l, n, o);
886
+ return l.subarray(0, i);
887
+ } catch (n) {
888
+ throw n.code == "ENOENT" ? new Be(`there is no file ${s} for uploading`) : n;
889
+ } finally {
890
+ r == null || r.close();
890
891
  }
891
- prepareUploadOpts(e, t) {
892
- const n = e.headers.map(({ name: r, value: o }) => [r, o]);
893
- return {
894
- dispatcher: this.httpClient,
895
- body: t,
896
- headers: Object.fromEntries(n),
897
- method: e.method.toUpperCase()
898
- };
892
+ }
893
+ async function zt(s, e, t, r) {
894
+ let n = 0;
895
+ for (; n < t; ) {
896
+ const { bytesRead: o } = await s.read(
897
+ e,
898
+ n,
899
+ t - n,
900
+ r + n
901
+ );
902
+ if (o === 0)
903
+ throw new De("file ended earlier than expected.");
904
+ n += o;
899
905
  }
906
+ return n;
907
+ }
908
+ async function Mt(s, e) {
909
+ const t = BigInt(Math.floor((await m.stat(s)).mtimeMs / 1e3));
910
+ if (t > e)
911
+ throw new Ne(`file was modified, expected mtime: ${e}, got: ${t}.`);
900
912
  }
901
- class Et extends g {
913
+ function Ht(s, e, t, r) {
914
+ if (s != 200)
915
+ throw new Wt(
916
+ `response is not ok, status code: ${s}, body: ${e}, headers: ${t}, url: ${r.uploadUrl}`
917
+ );
918
+ }
919
+ class jt extends g {
902
920
  constructor() {
903
921
  super("google.protobuf.Duration", [
904
922
  {
@@ -922,48 +940,48 @@ class Et extends g {
922
940
  * Encode `Duration` to JSON string like "3.000001s".
923
941
  */
924
942
  internalJsonWrite(e, t) {
925
- let n = I.from(e.seconds).toNumber();
926
- if (n > 315576e6 || n < -315576e6)
943
+ let r = P.from(e.seconds).toNumber();
944
+ if (r > 315576e6 || r < -315576e6)
927
945
  throw new Error("Duration value out of range.");
928
- let r = e.seconds.toString();
929
- if (n === 0 && e.nanos < 0 && (r = "-" + r), e.nanos !== 0) {
946
+ let n = e.seconds.toString();
947
+ if (r === 0 && e.nanos < 0 && (n = "-" + n), e.nanos !== 0) {
930
948
  let o = Math.abs(e.nanos).toString();
931
- o = "0".repeat(9 - o.length) + o, o.substring(3) === "000000" ? o = o.substring(0, 3) : o.substring(6) === "000" && (o = o.substring(0, 6)), r += "." + o;
949
+ o = "0".repeat(9 - o.length) + o, o.substring(3) === "000000" ? o = o.substring(0, 3) : o.substring(6) === "000" && (o = o.substring(0, 6)), n += "." + o;
932
950
  }
933
- return r + "s";
951
+ return n + "s";
934
952
  }
935
953
  /**
936
954
  * Decode `Duration` from JSON string like "3.000001s"
937
955
  */
938
- internalJsonRead(e, t, n) {
956
+ internalJsonRead(e, t, r) {
939
957
  if (typeof e != "string")
940
958
  throw new Error(
941
- "Unable to parse Duration from JSON " + Te(e) + ". Expected string."
959
+ "Unable to parse Duration from JSON " + ke(e) + ". Expected string."
942
960
  );
943
- let r = e.match(/^(-?)([0-9]+)(?:\.([0-9]+))?s/);
944
- if (r === null)
961
+ let n = e.match(/^(-?)([0-9]+)(?:\.([0-9]+))?s/);
962
+ if (n === null)
945
963
  throw new Error(
946
964
  "Unable to parse Duration from JSON string. Invalid format."
947
965
  );
948
- n || (n = this.create());
949
- let [, o, a, i] = r, c = I.from(o + a);
966
+ r || (r = this.create());
967
+ let [, o, l, i] = n, c = P.from(o + l);
950
968
  if (c.toNumber() > 315576e6 || c.toNumber() < -315576e6)
951
969
  throw new Error(
952
970
  "Unable to parse Duration from JSON string. Value out of range."
953
971
  );
954
- if (n.seconds = c.toBigInt(), typeof i == "string") {
955
- let l = o + i + "0".repeat(9 - i.length);
956
- n.nanos = parseInt(l);
972
+ if (r.seconds = c.toBigInt(), typeof i == "string") {
973
+ let a = o + i + "0".repeat(9 - i.length);
974
+ r.nanos = parseInt(a);
957
975
  }
958
- return n;
976
+ return r;
959
977
  }
960
978
  create(e) {
961
979
  const t = globalThis.Object.create(this.messagePrototype);
962
980
  return t.seconds = 0n, t.nanos = 0, e !== void 0 && f(this, t, e), t;
963
981
  }
964
- internalBinaryRead(e, t, n, r) {
965
- let o = r ?? this.create(), a = e.pos + t;
966
- for (; e.pos < a; ) {
982
+ internalBinaryRead(e, t, r, n) {
983
+ let o = n ?? this.create(), l = e.pos + t;
984
+ for (; e.pos < l; ) {
967
985
  let [i, c] = e.tag();
968
986
  switch (i) {
969
987
  case /* int64 seconds */
@@ -975,13 +993,13 @@ class Et extends g {
975
993
  o.nanos = e.int32();
976
994
  break;
977
995
  default:
978
- let l = n.readUnknownField;
979
- if (l === "throw")
996
+ let a = r.readUnknownField;
997
+ if (a === "throw")
980
998
  throw new globalThis.Error(
981
999
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
982
1000
  );
983
1001
  let p = e.skip(c);
984
- l !== !1 && (l === !0 ? u.onRead : l)(
1002
+ a !== !1 && (a === !0 ? u.onRead : a)(
985
1003
  this.typeName,
986
1004
  o,
987
1005
  i,
@@ -992,18 +1010,18 @@ class Et extends g {
992
1010
  }
993
1011
  return o;
994
1012
  }
995
- internalBinaryWrite(e, t, n) {
1013
+ internalBinaryWrite(e, t, r) {
996
1014
  e.seconds !== 0n && t.tag(1, h.Varint).int64(e.seconds), e.nanos !== 0 && t.tag(2, h.Varint).int32(e.nanos);
997
- let r = n.writeUnknownFields;
998
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1015
+ let n = r.writeUnknownFields;
1016
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
999
1017
  this.typeName,
1000
1018
  e,
1001
1019
  t
1002
1020
  ), t;
1003
1021
  }
1004
1022
  }
1005
- const $ = new Et();
1006
- class Wt extends g {
1023
+ const $ = new jt();
1024
+ class Gt extends g {
1007
1025
  constructor() {
1008
1026
  super("MiLaboratories.Controller.Shared.ProgressAPI", []);
1009
1027
  }
@@ -1011,20 +1029,20 @@ class Wt extends g {
1011
1029
  const t = globalThis.Object.create(this.messagePrototype);
1012
1030
  return e !== void 0 && f(this, t, e), t;
1013
1031
  }
1014
- internalBinaryRead(e, t, n, r) {
1015
- return r ?? this.create();
1032
+ internalBinaryRead(e, t, r, n) {
1033
+ return n ?? this.create();
1016
1034
  }
1017
- internalBinaryWrite(e, t, n) {
1018
- let r = n.writeUnknownFields;
1019
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1035
+ internalBinaryWrite(e, t, r) {
1036
+ let n = r.writeUnknownFields;
1037
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1020
1038
  this.typeName,
1021
1039
  e,
1022
1040
  t
1023
1041
  ), t;
1024
1042
  }
1025
1043
  }
1026
- new Wt();
1027
- class At extends g {
1044
+ new Gt();
1045
+ class Vt extends g {
1028
1046
  constructor() {
1029
1047
  super("MiLaboratories.Controller.Shared.ProgressAPI.Report", [
1030
1048
  {
@@ -1070,9 +1088,9 @@ class At extends g {
1070
1088
  const t = globalThis.Object.create(this.messagePrototype);
1071
1089
  return t.progress = 0, t.bytesProcessed = 0n, t.bytesTotal = 0n, t.done = !1, t.name = "", e !== void 0 && f(this, t, e), t;
1072
1090
  }
1073
- internalBinaryRead(e, t, n, r) {
1074
- let o = r ?? this.create(), a = e.pos + t;
1075
- for (; e.pos < a; ) {
1091
+ internalBinaryRead(e, t, r, n) {
1092
+ let o = n ?? this.create(), l = e.pos + t;
1093
+ for (; e.pos < l; ) {
1076
1094
  let [i, c] = e.tag();
1077
1095
  switch (i) {
1078
1096
  case /* float progress */
@@ -1096,13 +1114,13 @@ class At extends g {
1096
1114
  o.name = e.string();
1097
1115
  break;
1098
1116
  default:
1099
- let l = n.readUnknownField;
1100
- if (l === "throw")
1117
+ let a = r.readUnknownField;
1118
+ if (a === "throw")
1101
1119
  throw new globalThis.Error(
1102
1120
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1103
1121
  );
1104
1122
  let p = e.skip(c);
1105
- l !== !1 && (l === !0 ? u.onRead : l)(
1123
+ a !== !1 && (a === !0 ? u.onRead : a)(
1106
1124
  this.typeName,
1107
1125
  o,
1108
1126
  i,
@@ -1113,18 +1131,18 @@ class At extends g {
1113
1131
  }
1114
1132
  return o;
1115
1133
  }
1116
- internalBinaryWrite(e, t, n) {
1134
+ internalBinaryWrite(e, t, r) {
1117
1135
  e.progress !== 0 && t.tag(1, h.Bit32).float(e.progress), e.bytesProcessed !== 0n && t.tag(2, h.Varint).uint64(e.bytesProcessed), e.bytesTotal !== 0n && t.tag(3, h.Varint).uint64(e.bytesTotal), e.done !== !1 && t.tag(4, h.Varint).bool(e.done), e.name !== "" && t.tag(5, h.LengthDelimited).string(e.name);
1118
- let r = n.writeUnknownFields;
1119
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1136
+ let n = r.writeUnknownFields;
1137
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1120
1138
  this.typeName,
1121
1139
  e,
1122
1140
  t
1123
1141
  ), t;
1124
1142
  }
1125
1143
  }
1126
- const S = new At();
1127
- class zt extends g {
1144
+ const R = new Vt();
1145
+ class qt extends g {
1128
1146
  constructor() {
1129
1147
  super("MiLaboratories.Controller.Shared.ProgressAPI.GetStatus", []);
1130
1148
  }
@@ -1132,20 +1150,20 @@ class zt extends g {
1132
1150
  const t = globalThis.Object.create(this.messagePrototype);
1133
1151
  return e !== void 0 && f(this, t, e), t;
1134
1152
  }
1135
- internalBinaryRead(e, t, n, r) {
1136
- return r ?? this.create();
1153
+ internalBinaryRead(e, t, r, n) {
1154
+ return n ?? this.create();
1137
1155
  }
1138
- internalBinaryWrite(e, t, n) {
1139
- let r = n.writeUnknownFields;
1140
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1156
+ internalBinaryWrite(e, t, r) {
1157
+ let n = r.writeUnknownFields;
1158
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1141
1159
  this.typeName,
1142
1160
  e,
1143
1161
  t
1144
1162
  ), t;
1145
1163
  }
1146
1164
  }
1147
- new zt();
1148
- class xt extends g {
1165
+ new qt();
1166
+ class Jt extends g {
1149
1167
  constructor() {
1150
1168
  super("MiLaboratories.Controller.Shared.ProgressAPI.GetStatus.Request", [
1151
1169
  {
@@ -1166,9 +1184,9 @@ class xt extends g {
1166
1184
  e
1167
1185
  ), t;
1168
1186
  }
1169
- internalBinaryRead(e, t, n, r) {
1170
- let o = r ?? this.create(), a = e.pos + t;
1171
- for (; e.pos < a; ) {
1187
+ internalBinaryRead(e, t, r, n) {
1188
+ let o = n ?? this.create(), l = e.pos + t;
1189
+ for (; e.pos < l; ) {
1172
1190
  let [i, c] = e.tag();
1173
1191
  switch (i) {
1174
1192
  case /* uint64 resource_id */
@@ -1176,13 +1194,13 @@ class xt extends g {
1176
1194
  o.resourceId = e.uint64().toBigInt();
1177
1195
  break;
1178
1196
  default:
1179
- let l = n.readUnknownField;
1180
- if (l === "throw")
1197
+ let a = r.readUnknownField;
1198
+ if (a === "throw")
1181
1199
  throw new globalThis.Error(
1182
1200
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1183
1201
  );
1184
1202
  let p = e.skip(c);
1185
- l !== !1 && (l === !0 ? u.onRead : l)(
1203
+ a !== !1 && (a === !0 ? u.onRead : a)(
1186
1204
  this.typeName,
1187
1205
  o,
1188
1206
  i,
@@ -1193,21 +1211,21 @@ class xt extends g {
1193
1211
  }
1194
1212
  return o;
1195
1213
  }
1196
- internalBinaryWrite(e, t, n) {
1214
+ internalBinaryWrite(e, t, r) {
1197
1215
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId);
1198
- let r = n.writeUnknownFields;
1199
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1216
+ let n = r.writeUnknownFields;
1217
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1200
1218
  this.typeName,
1201
1219
  e,
1202
1220
  t
1203
1221
  ), t;
1204
1222
  }
1205
1223
  }
1206
- const Mt = new xt();
1207
- class Ht extends g {
1224
+ const Zt = new Jt();
1225
+ class Qt extends g {
1208
1226
  constructor() {
1209
1227
  super("MiLaboratories.Controller.Shared.ProgressAPI.GetStatus.Response", [
1210
- { no: 1, name: "report", kind: "message", T: () => S }
1228
+ { no: 1, name: "report", kind: "message", T: () => R }
1211
1229
  ]);
1212
1230
  }
1213
1231
  create(e) {
@@ -1218,28 +1236,28 @@ class Ht extends g {
1218
1236
  e
1219
1237
  ), t;
1220
1238
  }
1221
- internalBinaryRead(e, t, n, r) {
1222
- let o = r ?? this.create(), a = e.pos + t;
1223
- for (; e.pos < a; ) {
1239
+ internalBinaryRead(e, t, r, n) {
1240
+ let o = n ?? this.create(), l = e.pos + t;
1241
+ for (; e.pos < l; ) {
1224
1242
  let [i, c] = e.tag();
1225
1243
  switch (i) {
1226
1244
  case /* MiLaboratories.Controller.Shared.ProgressAPI.Report report */
1227
1245
  1:
1228
- o.report = S.internalBinaryRead(
1246
+ o.report = R.internalBinaryRead(
1229
1247
  e,
1230
1248
  e.uint32(),
1231
- n,
1249
+ r,
1232
1250
  o.report
1233
1251
  );
1234
1252
  break;
1235
1253
  default:
1236
- let l = n.readUnknownField;
1237
- if (l === "throw")
1254
+ let a = r.readUnknownField;
1255
+ if (a === "throw")
1238
1256
  throw new globalThis.Error(
1239
1257
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1240
1258
  );
1241
1259
  let p = e.skip(c);
1242
- l !== !1 && (l === !0 ? u.onRead : l)(
1260
+ a !== !1 && (a === !0 ? u.onRead : a)(
1243
1261
  this.typeName,
1244
1262
  o,
1245
1263
  i,
@@ -1250,22 +1268,22 @@ class Ht extends g {
1250
1268
  }
1251
1269
  return o;
1252
1270
  }
1253
- internalBinaryWrite(e, t, n) {
1254
- e.report && S.internalBinaryWrite(
1271
+ internalBinaryWrite(e, t, r) {
1272
+ e.report && R.internalBinaryWrite(
1255
1273
  e.report,
1256
1274
  t.tag(1, h.LengthDelimited).fork(),
1257
- n
1275
+ r
1258
1276
  ).join();
1259
- let r = n.writeUnknownFields;
1260
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1277
+ let n = r.writeUnknownFields;
1278
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1261
1279
  this.typeName,
1262
1280
  e,
1263
1281
  t
1264
1282
  ), t;
1265
1283
  }
1266
1284
  }
1267
- const jt = new Ht();
1268
- class Gt extends g {
1285
+ const Xt = new Qt();
1286
+ class Yt extends g {
1269
1287
  constructor() {
1270
1288
  super("MiLaboratories.Controller.Shared.ProgressAPI.RealtimeStatus", []);
1271
1289
  }
@@ -1273,20 +1291,20 @@ class Gt extends g {
1273
1291
  const t = globalThis.Object.create(this.messagePrototype);
1274
1292
  return e !== void 0 && f(this, t, e), t;
1275
1293
  }
1276
- internalBinaryRead(e, t, n, r) {
1277
- return r ?? this.create();
1294
+ internalBinaryRead(e, t, r, n) {
1295
+ return n ?? this.create();
1278
1296
  }
1279
- internalBinaryWrite(e, t, n) {
1280
- let r = n.writeUnknownFields;
1281
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1297
+ internalBinaryWrite(e, t, r) {
1298
+ let n = r.writeUnknownFields;
1299
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1282
1300
  this.typeName,
1283
1301
  e,
1284
1302
  t
1285
1303
  ), t;
1286
1304
  }
1287
1305
  }
1288
- new Gt();
1289
- class Vt extends g {
1306
+ new Yt();
1307
+ class Kt extends g {
1290
1308
  constructor() {
1291
1309
  super(
1292
1310
  "MiLaboratories.Controller.Shared.ProgressAPI.RealtimeStatus.Request",
@@ -1311,9 +1329,9 @@ class Vt extends g {
1311
1329
  e
1312
1330
  ), t;
1313
1331
  }
1314
- internalBinaryRead(e, t, n, r) {
1315
- let o = r ?? this.create(), a = e.pos + t;
1316
- for (; e.pos < a; ) {
1332
+ internalBinaryRead(e, t, r, n) {
1333
+ let o = n ?? this.create(), l = e.pos + t;
1334
+ for (; e.pos < l; ) {
1317
1335
  let [i, c] = e.tag();
1318
1336
  switch (i) {
1319
1337
  case /* uint64 resource_id */
@@ -1325,18 +1343,18 @@ class Vt extends g {
1325
1343
  o.updateInterval = $.internalBinaryRead(
1326
1344
  e,
1327
1345
  e.uint32(),
1328
- n,
1346
+ r,
1329
1347
  o.updateInterval
1330
1348
  );
1331
1349
  break;
1332
1350
  default:
1333
- let l = n.readUnknownField;
1334
- if (l === "throw")
1351
+ let a = r.readUnknownField;
1352
+ if (a === "throw")
1335
1353
  throw new globalThis.Error(
1336
1354
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1337
1355
  );
1338
1356
  let p = e.skip(c);
1339
- l !== !1 && (l === !0 ? u.onRead : l)(
1357
+ a !== !1 && (a === !0 ? u.onRead : a)(
1340
1358
  this.typeName,
1341
1359
  o,
1342
1360
  i,
@@ -1347,26 +1365,26 @@ class Vt extends g {
1347
1365
  }
1348
1366
  return o;
1349
1367
  }
1350
- internalBinaryWrite(e, t, n) {
1368
+ internalBinaryWrite(e, t, r) {
1351
1369
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.updateInterval && $.internalBinaryWrite(
1352
1370
  e.updateInterval,
1353
1371
  t.tag(2, h.LengthDelimited).fork(),
1354
- n
1372
+ r
1355
1373
  ).join();
1356
- let r = n.writeUnknownFields;
1357
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1374
+ let n = r.writeUnknownFields;
1375
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1358
1376
  this.typeName,
1359
1377
  e,
1360
1378
  t
1361
1379
  ), t;
1362
1380
  }
1363
1381
  }
1364
- const qt = new Vt();
1365
- class Jt extends g {
1382
+ const er = new Kt();
1383
+ class tr extends g {
1366
1384
  constructor() {
1367
1385
  super(
1368
1386
  "MiLaboratories.Controller.Shared.ProgressAPI.RealtimeStatus.Response",
1369
- [{ no: 1, name: "report", kind: "message", T: () => S }]
1387
+ [{ no: 1, name: "report", kind: "message", T: () => R }]
1370
1388
  );
1371
1389
  }
1372
1390
  create(e) {
@@ -1377,28 +1395,28 @@ class Jt extends g {
1377
1395
  e
1378
1396
  ), t;
1379
1397
  }
1380
- internalBinaryRead(e, t, n, r) {
1381
- let o = r ?? this.create(), a = e.pos + t;
1382
- for (; e.pos < a; ) {
1398
+ internalBinaryRead(e, t, r, n) {
1399
+ let o = n ?? this.create(), l = e.pos + t;
1400
+ for (; e.pos < l; ) {
1383
1401
  let [i, c] = e.tag();
1384
1402
  switch (i) {
1385
1403
  case /* MiLaboratories.Controller.Shared.ProgressAPI.Report report */
1386
1404
  1:
1387
- o.report = S.internalBinaryRead(
1405
+ o.report = R.internalBinaryRead(
1388
1406
  e,
1389
1407
  e.uint32(),
1390
- n,
1408
+ r,
1391
1409
  o.report
1392
1410
  );
1393
1411
  break;
1394
1412
  default:
1395
- let l = n.readUnknownField;
1396
- if (l === "throw")
1413
+ let a = r.readUnknownField;
1414
+ if (a === "throw")
1397
1415
  throw new globalThis.Error(
1398
1416
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1399
1417
  );
1400
1418
  let p = e.skip(c);
1401
- l !== !1 && (l === !0 ? u.onRead : l)(
1419
+ a !== !1 && (a === !0 ? u.onRead : a)(
1402
1420
  this.typeName,
1403
1421
  o,
1404
1422
  i,
@@ -1409,21 +1427,21 @@ class Jt extends g {
1409
1427
  }
1410
1428
  return o;
1411
1429
  }
1412
- internalBinaryWrite(e, t, n) {
1413
- e.report && S.internalBinaryWrite(
1430
+ internalBinaryWrite(e, t, r) {
1431
+ e.report && R.internalBinaryWrite(
1414
1432
  e.report,
1415
1433
  t.tag(1, h.LengthDelimited).fork(),
1416
- n
1434
+ r
1417
1435
  ).join();
1418
- let r = n.writeUnknownFields;
1419
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1436
+ let n = r.writeUnknownFields;
1437
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1420
1438
  this.typeName,
1421
1439
  e,
1422
1440
  t
1423
1441
  ), t;
1424
1442
  }
1425
1443
  }
1426
- const Zt = new Jt(), A = new D(
1444
+ const rr = new tr(), A = new D(
1427
1445
  "MiLaboratories.Controller.Shared.Progress",
1428
1446
  [
1429
1447
  {
@@ -1431,19 +1449,19 @@ const Zt = new Jt(), A = new D(
1431
1449
  options: {
1432
1450
  "google.api.http": { get: "/resources/{resource_id}/get-progress" }
1433
1451
  },
1434
- I: Mt,
1435
- O: jt
1452
+ I: Zt,
1453
+ O: Xt
1436
1454
  },
1437
1455
  {
1438
1456
  name: "RealtimeStatus",
1439
1457
  serverStreaming: !0,
1440
1458
  options: {},
1441
- I: qt,
1442
- O: Zt
1459
+ I: er,
1460
+ O: rr
1443
1461
  }
1444
1462
  ]
1445
1463
  );
1446
- class Qt {
1464
+ class nr {
1447
1465
  constructor(e) {
1448
1466
  d(this, "typeName", A.typeName);
1449
1467
  d(this, "methods", A.methods);
@@ -1454,30 +1472,30 @@ class Qt {
1454
1472
  * @generated from protobuf rpc: GetStatus(MiLaboratories.Controller.Shared.ProgressAPI.GetStatus.Request) returns (MiLaboratories.Controller.Shared.ProgressAPI.GetStatus.Response);
1455
1473
  */
1456
1474
  getStatus(e, t) {
1457
- const n = this.methods[0], r = this._transport.mergeOptions(t);
1458
- return y("unary", this._transport, n, r, e);
1475
+ const r = this.methods[0], n = this._transport.mergeOptions(t);
1476
+ return y("unary", this._transport, r, n, e);
1459
1477
  }
1460
1478
  /**
1461
1479
  * @generated from protobuf rpc: RealtimeStatus(MiLaboratories.Controller.Shared.ProgressAPI.RealtimeStatus.Request) returns (stream MiLaboratories.Controller.Shared.ProgressAPI.RealtimeStatus.Response);
1462
1480
  */
1463
1481
  realtimeStatus(e, t) {
1464
- const n = this.methods[1], r = this._transport.mergeOptions(t);
1465
- return y("serverStreaming", this._transport, n, r, e);
1482
+ const r = this.methods[1], n = this._transport.mergeOptions(t);
1483
+ return y("serverStreaming", this._transport, r, n, e);
1466
1484
  }
1467
1485
  }
1468
- class Xt {
1469
- constructor(e, t, n, r) {
1486
+ class or {
1487
+ constructor(e, t, r, n) {
1470
1488
  d(this, "grpcClient");
1471
- this.grpcTransport = e, this.client = n, this.logger = r, this.grpcClient = new Qt(this.grpcTransport);
1489
+ this.grpcTransport = e, this.client = r, this.logger = n, this.grpcClient = new nr(this.grpcTransport);
1472
1490
  }
1473
1491
  close() {
1474
1492
  }
1475
1493
  /** getStatus gets a progress status by given rId and rType. */
1476
- async getStatus({ id: e, type: t }, n) {
1477
- const r = await this.grpcClient.getStatus(
1494
+ async getStatus({ id: e, type: t }, r) {
1495
+ const n = await this.grpcClient.getStatus(
1478
1496
  { resourceId: e },
1479
- k(t, n)
1480
- ), o = K(r.response.report);
1497
+ T(t, r)
1498
+ ), o = te(n.response.report);
1481
1499
  return {
1482
1500
  done: o.done,
1483
1501
  progress: o.progress,
@@ -1487,11 +1505,11 @@ class Xt {
1487
1505
  }
1488
1506
  // realtimeStatus returns a async generator that takes statuses from
1489
1507
  // GRPC stream every updateIntervalMs milliseconds.
1490
- async *realtimeStatus({ id: e, type: t }, n = 100, r) {
1491
- r = k(t, r);
1492
- const o = Math.floor(n / 1e3), a = (n - o * 1e3) * 1e6, i = $.create({
1508
+ async *realtimeStatus({ id: e, type: t }, r = 100, n) {
1509
+ n = T(t, n);
1510
+ const o = Math.floor(r / 1e3), l = (r - o * 1e3) * 1e6, i = $.create({
1493
1511
  seconds: BigInt(o),
1494
- nanos: a
1512
+ nanos: l
1495
1513
  });
1496
1514
  try {
1497
1515
  const { responses: c } = this.grpcClient.realtimeStatus(
@@ -1499,7 +1517,7 @@ class Xt {
1499
1517
  resourceId: e,
1500
1518
  updateInterval: i
1501
1519
  },
1502
- r
1520
+ n
1503
1521
  );
1504
1522
  yield* c;
1505
1523
  } catch (c) {
@@ -1507,7 +1525,37 @@ class Xt {
1507
1525
  }
1508
1526
  }
1509
1527
  }
1510
- class Yt extends g {
1528
+ class ce extends Error {
1529
+ }
1530
+ class ve {
1531
+ constructor(e) {
1532
+ this.httpClient = e;
1533
+ }
1534
+ async download(e, t, r) {
1535
+ const { statusCode: n, body: o, headers: l } = await be(e, {
1536
+ dispatcher: this.httpClient,
1537
+ headers: t,
1538
+ signal: r
1539
+ }), i = se.toWeb(o);
1540
+ return await sr(n, i, e), {
1541
+ content: i,
1542
+ size: Number(l["content-length"])
1543
+ };
1544
+ }
1545
+ }
1546
+ async function sr(s, e, t) {
1547
+ if (s != 200) {
1548
+ const r = (await nt(e)).substring(0, 1e3);
1549
+ throw 400 <= s && s < 500 ? new ce(
1550
+ `Http error: statusCode: ${s} url: ${t.toString()}, beginning of body: ${r}`
1551
+ ) : new Error(`Http error: statusCode: ${s} url: ${t.toString()}`);
1552
+ }
1553
+ }
1554
+ function N(s) {
1555
+ if (!Q.isAbsolute(s)) throw new Error(`Path ${s} is not absolute.`);
1556
+ return s;
1557
+ }
1558
+ class ir extends g {
1511
1559
  constructor() {
1512
1560
  super("MiLaboratories.Controller.Shared.DownloadAPI", []);
1513
1561
  }
@@ -1515,20 +1563,20 @@ class Yt extends g {
1515
1563
  const t = globalThis.Object.create(this.messagePrototype);
1516
1564
  return e !== void 0 && f(this, t, e), t;
1517
1565
  }
1518
- internalBinaryRead(e, t, n, r) {
1519
- return r ?? this.create();
1566
+ internalBinaryRead(e, t, r, n) {
1567
+ return n ?? this.create();
1520
1568
  }
1521
- internalBinaryWrite(e, t, n) {
1522
- let r = n.writeUnknownFields;
1523
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1569
+ internalBinaryWrite(e, t, r) {
1570
+ let n = r.writeUnknownFields;
1571
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1524
1572
  this.typeName,
1525
1573
  e,
1526
1574
  t
1527
1575
  ), t;
1528
1576
  }
1529
1577
  }
1530
- new Yt();
1531
- class Kt extends g {
1578
+ new ir();
1579
+ class ar extends g {
1532
1580
  constructor() {
1533
1581
  super("MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL", []);
1534
1582
  }
@@ -1536,20 +1584,20 @@ class Kt extends g {
1536
1584
  const t = globalThis.Object.create(this.messagePrototype);
1537
1585
  return e !== void 0 && f(this, t, e), t;
1538
1586
  }
1539
- internalBinaryRead(e, t, n, r) {
1540
- return r ?? this.create();
1587
+ internalBinaryRead(e, t, r, n) {
1588
+ return n ?? this.create();
1541
1589
  }
1542
- internalBinaryWrite(e, t, n) {
1543
- let r = n.writeUnknownFields;
1544
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1590
+ internalBinaryWrite(e, t, r) {
1591
+ let n = r.writeUnknownFields;
1592
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1545
1593
  this.typeName,
1546
1594
  e,
1547
1595
  t
1548
1596
  ), t;
1549
1597
  }
1550
1598
  }
1551
- new Kt();
1552
- class er extends g {
1599
+ new ar();
1600
+ class lr extends g {
1553
1601
  constructor() {
1554
1602
  super(
1555
1603
  "MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL.Request",
@@ -1573,9 +1621,9 @@ class er extends g {
1573
1621
  e
1574
1622
  ), t;
1575
1623
  }
1576
- internalBinaryRead(e, t, n, r) {
1577
- let o = r ?? this.create(), a = e.pos + t;
1578
- for (; e.pos < a; ) {
1624
+ internalBinaryRead(e, t, r, n) {
1625
+ let o = n ?? this.create(), l = e.pos + t;
1626
+ for (; e.pos < l; ) {
1579
1627
  let [i, c] = e.tag();
1580
1628
  switch (i) {
1581
1629
  case /* uint64 resource_id */
@@ -1583,13 +1631,13 @@ class er extends g {
1583
1631
  o.resourceId = e.uint64().toBigInt();
1584
1632
  break;
1585
1633
  default:
1586
- let l = n.readUnknownField;
1587
- if (l === "throw")
1634
+ let a = r.readUnknownField;
1635
+ if (a === "throw")
1588
1636
  throw new globalThis.Error(
1589
1637
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1590
1638
  );
1591
1639
  let p = e.skip(c);
1592
- l !== !1 && (l === !0 ? u.onRead : l)(
1640
+ a !== !1 && (a === !0 ? u.onRead : a)(
1593
1641
  this.typeName,
1594
1642
  o,
1595
1643
  i,
@@ -1600,18 +1648,18 @@ class er extends g {
1600
1648
  }
1601
1649
  return o;
1602
1650
  }
1603
- internalBinaryWrite(e, t, n) {
1651
+ internalBinaryWrite(e, t, r) {
1604
1652
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId);
1605
- let r = n.writeUnknownFields;
1606
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1653
+ let n = r.writeUnknownFields;
1654
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1607
1655
  this.typeName,
1608
1656
  e,
1609
1657
  t
1610
1658
  ), t;
1611
1659
  }
1612
1660
  }
1613
- const tr = new er();
1614
- class rr extends g {
1661
+ const cr = new lr();
1662
+ class dr extends g {
1615
1663
  constructor() {
1616
1664
  super(
1617
1665
  "MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL.HTTPHeader",
@@ -1643,9 +1691,9 @@ class rr extends g {
1643
1691
  e
1644
1692
  ), t;
1645
1693
  }
1646
- internalBinaryRead(e, t, n, r) {
1647
- let o = r ?? this.create(), a = e.pos + t;
1648
- for (; e.pos < a; ) {
1694
+ internalBinaryRead(e, t, r, n) {
1695
+ let o = n ?? this.create(), l = e.pos + t;
1696
+ for (; e.pos < l; ) {
1649
1697
  let [i, c] = e.tag();
1650
1698
  switch (i) {
1651
1699
  case /* string Name = 1 [json_name = "Name"];*/
@@ -1657,13 +1705,13 @@ class rr extends g {
1657
1705
  o.value = e.string();
1658
1706
  break;
1659
1707
  default:
1660
- let l = n.readUnknownField;
1661
- if (l === "throw")
1708
+ let a = r.readUnknownField;
1709
+ if (a === "throw")
1662
1710
  throw new globalThis.Error(
1663
1711
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1664
1712
  );
1665
1713
  let p = e.skip(c);
1666
- l !== !1 && (l === !0 ? u.onRead : l)(
1714
+ a !== !1 && (a === !0 ? u.onRead : a)(
1667
1715
  this.typeName,
1668
1716
  o,
1669
1717
  i,
@@ -1674,18 +1722,18 @@ class rr extends g {
1674
1722
  }
1675
1723
  return o;
1676
1724
  }
1677
- internalBinaryWrite(e, t, n) {
1725
+ internalBinaryWrite(e, t, r) {
1678
1726
  e.name !== "" && t.tag(1, h.LengthDelimited).string(e.name), e.value !== "" && t.tag(2, h.LengthDelimited).string(e.value);
1679
- let r = n.writeUnknownFields;
1680
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1727
+ let n = r.writeUnknownFields;
1728
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1681
1729
  this.typeName,
1682
1730
  e,
1683
1731
  t
1684
1732
  ), t;
1685
1733
  }
1686
1734
  }
1687
- const z = new rr();
1688
- class nr extends g {
1735
+ const x = new dr();
1736
+ class hr extends g {
1689
1737
  constructor() {
1690
1738
  super(
1691
1739
  "MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL.Response",
@@ -1702,7 +1750,7 @@ class nr extends g {
1702
1750
  name: "headers",
1703
1751
  kind: "message",
1704
1752
  repeat: 1,
1705
- T: () => z
1753
+ T: () => x
1706
1754
  }
1707
1755
  ]
1708
1756
  );
@@ -1715,9 +1763,9 @@ class nr extends g {
1715
1763
  e
1716
1764
  ), t;
1717
1765
  }
1718
- internalBinaryRead(e, t, n, r) {
1719
- let o = r ?? this.create(), a = e.pos + t;
1720
- for (; e.pos < a; ) {
1766
+ internalBinaryRead(e, t, r, n) {
1767
+ let o = n ?? this.create(), l = e.pos + t;
1768
+ for (; e.pos < l; ) {
1721
1769
  let [i, c] = e.tag();
1722
1770
  switch (i) {
1723
1771
  case /* string download_url */
@@ -1727,21 +1775,21 @@ class nr extends g {
1727
1775
  case /* repeated MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL.HTTPHeader headers */
1728
1776
  2:
1729
1777
  o.headers.push(
1730
- z.internalBinaryRead(
1778
+ x.internalBinaryRead(
1731
1779
  e,
1732
1780
  e.uint32(),
1733
- n
1781
+ r
1734
1782
  )
1735
1783
  );
1736
1784
  break;
1737
1785
  default:
1738
- let l = n.readUnknownField;
1739
- if (l === "throw")
1786
+ let a = r.readUnknownField;
1787
+ if (a === "throw")
1740
1788
  throw new globalThis.Error(
1741
1789
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1742
1790
  );
1743
1791
  let p = e.skip(c);
1744
- l !== !1 && (l === !0 ? u.onRead : l)(
1792
+ a !== !1 && (a === !0 ? u.onRead : a)(
1745
1793
  this.typeName,
1746
1794
  o,
1747
1795
  i,
@@ -1752,23 +1800,23 @@ class nr extends g {
1752
1800
  }
1753
1801
  return o;
1754
1802
  }
1755
- internalBinaryWrite(e, t, n) {
1803
+ internalBinaryWrite(e, t, r) {
1756
1804
  e.downloadUrl !== "" && t.tag(1, h.LengthDelimited).string(e.downloadUrl);
1757
1805
  for (let o = 0; o < e.headers.length; o++)
1758
- z.internalBinaryWrite(
1806
+ x.internalBinaryWrite(
1759
1807
  e.headers[o],
1760
1808
  t.tag(2, h.LengthDelimited).fork(),
1761
- n
1809
+ r
1762
1810
  ).join();
1763
- let r = n.writeUnknownFields;
1764
- return r !== !1 && (r == !0 ? u.onWrite : r)(
1811
+ let n = r.writeUnknownFields;
1812
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
1765
1813
  this.typeName,
1766
1814
  e,
1767
1815
  t
1768
1816
  ), t;
1769
1817
  }
1770
1818
  }
1771
- const or = new nr(), x = new D(
1819
+ const ur = new hr(), z = new D(
1772
1820
  "MiLaboratories.Controller.Shared.Download",
1773
1821
  [
1774
1822
  {
@@ -1776,110 +1824,84 @@ const or = new nr(), x = new D(
1776
1824
  options: {
1777
1825
  "google.api.http": { get: "/resources/{resource_id}/get-download-url" }
1778
1826
  },
1779
- I: tr,
1780
- O: or
1827
+ I: cr,
1828
+ O: ur
1781
1829
  }
1782
1830
  ]
1783
1831
  );
1784
- class sr {
1832
+ class pr {
1785
1833
  constructor(e) {
1786
- d(this, "typeName", x.typeName);
1787
- d(this, "methods", x.methods);
1788
- d(this, "options", x.options);
1834
+ d(this, "typeName", z.typeName);
1835
+ d(this, "methods", z.methods);
1836
+ d(this, "options", z.options);
1789
1837
  this._transport = e;
1790
1838
  }
1791
1839
  /**
1792
1840
  * @generated from protobuf rpc: GetDownloadURL(MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL.Request) returns (MiLaboratories.Controller.Shared.DownloadAPI.GetDownloadURL.Response);
1793
1841
  */
1794
1842
  getDownloadURL(e, t) {
1795
- const n = this.methods[0], r = this._transport.mergeOptions(t);
1796
- return y("unary", this._transport, n, r, e);
1797
- }
1798
- }
1799
- class ae extends Error {
1800
- }
1801
- class Ne {
1802
- constructor(e) {
1803
- this.httpClient = e;
1804
- }
1805
- async downloadRemoteFile(e, t, n) {
1806
- const { statusCode: r, body: o, headers: a } = await ke(e, {
1807
- dispatcher: this.httpClient,
1808
- headers: t,
1809
- signal: n
1810
- }), i = re.toWeb(o);
1811
- if (r != 200) {
1812
- const c = await tt(i), l = c.substring(0, Math.min(c.length, 1e3));
1813
- throw 400 <= r && r < 500 ? new ae(
1814
- `Http error: statusCode: ${r} url: ${e.toString()}, beginning of body: ${l}`
1815
- ) : new Error(`Http error: statusCode: ${r} url: ${e.toString()}`);
1816
- }
1817
- return {
1818
- content: i,
1819
- size: Number(a["content-length"])
1820
- };
1843
+ const r = this.methods[0], n = this._transport.mergeOptions(t);
1844
+ return y("unary", this._transport, r, n, e);
1821
1845
  }
1822
1846
  }
1823
- function B(s) {
1824
- if (!Z.isAbsolute(s)) throw new Error(`Path ${s} is not absolute.`);
1825
- return s;
1826
- }
1827
- const ir = "storage://";
1828
- class Ue extends Error {
1829
- }
1830
- class Be extends Error {
1831
- }
1832
- class ar {
1833
- constructor(e, t, n, r) {
1847
+ class gr {
1848
+ constructor(e, t, r, n) {
1834
1849
  d(this, "grpcClient");
1835
- d(this, "downloadHelper");
1850
+ d(this, "remoteFileDownloader");
1851
+ /** Helps to find a storage root directory by a storage id from URL scheme. */
1836
1852
  d(this, "localStorageIdsToRoot");
1837
- d(this, "isLocal", (e) => e.startsWith(ir));
1838
- this.grpcTransport = e, this.httpClient = t, this.logger = n;
1839
- for (const o of r) o.localPath !== "" && B(o.localPath);
1840
- this.grpcClient = new sr(this.grpcTransport), this.downloadHelper = new Ne(t), this.localStorageIdsToRoot = new Map(
1841
- r.map((o) => [o.storageId, o.localPath])
1842
- );
1853
+ this.grpcTransport = e, this.httpClient = t, this.logger = r, this.grpcClient = new pr(this.grpcTransport), this.remoteFileDownloader = new ve(t), this.localStorageIdsToRoot = br(n);
1843
1854
  }
1844
1855
  close() {
1845
1856
  }
1846
- async getUrl({ id: e, type: t }, n, r) {
1847
- const o = n ?? {};
1848
- return o.abort = r, await this.grpcClient.getDownloadURL(
1849
- { resourceId: e },
1850
- k(t, o)
1851
- ).response;
1852
- }
1853
- async downloadBlob(e, t, n) {
1854
- const { downloadUrl: r, headers: o } = await this.getUrl(e, t, n);
1855
- return this.logger.info(`download from url ${r}`), this.isLocal(r) ? await this.readLocalFile(r) : await this.downloadHelper.downloadRemoteFile(
1856
- r,
1857
- cr(o),
1858
- n
1859
- );
1857
+ async downloadBlob(e, t, r) {
1858
+ const { downloadUrl: n, headers: o } = await this.grpcGetDownloadUrl(e, t, r);
1859
+ return this.logger.info(`download blob from url ${n}`), yr(n) ? await this.readLocalFile(n) : await this.remoteFileDownloader.download(n, Ue(o), r);
1860
1860
  }
1861
1861
  async readLocalFile(e) {
1862
- const t = lr(e, this.localStorageIdsToRoot), r = (await m.stat(t)).size;
1862
+ const { storageId: t, relativePath: r } = fr(e), n = mr(t, this.localStorageIdsToRoot, r);
1863
1863
  return {
1864
- content: re.toWeb(O.createReadStream(t)),
1865
- size: r
1864
+ content: se.toWeb(oe.createReadStream(n)),
1865
+ size: (await m.stat(n)).size
1866
1866
  };
1867
1867
  }
1868
+ async grpcGetDownloadUrl({ id: e, type: t }, r, n) {
1869
+ const o = r ?? {};
1870
+ return o.abort = n, await this.grpcClient.getDownloadURL(
1871
+ { resourceId: e },
1872
+ T(t, o)
1873
+ ).response;
1874
+ }
1875
+ }
1876
+ function fr(s) {
1877
+ const e = new URL(s);
1878
+ if (e.pathname == "")
1879
+ throw new $e(`url for local filepath ${s} does not match url scheme`);
1880
+ return {
1881
+ storageId: e.host,
1882
+ relativePath: decodeURIComponent(e.pathname.slice(1))
1883
+ };
1868
1884
  }
1869
- function lr(s, e) {
1870
- const t = new URL(s);
1871
- if (t.pathname == "")
1872
- throw new Be(`url for local filepath ${s} does not match url scheme`);
1873
- const n = t.host, r = e.get(n);
1874
- if (r === void 0)
1875
- throw new Ue(`Unknown storage location: ${n}`);
1876
- const o = decodeURIComponent(t.pathname.slice(1));
1877
- return r === "" ? o : w.join(r, o);
1885
+ function mr(s, e, t) {
1886
+ const r = e.get(s);
1887
+ if (r === void 0) throw new _e(`Unknown storage location: ${s}`);
1888
+ return r === "" ? t : w.join(r, t);
1878
1889
  }
1879
- function cr(s) {
1880
- return Object.fromEntries(s.map(({ name: e, value: t }) => [e, t]));
1890
+ const wr = "storage://";
1891
+ function yr(s) {
1892
+ return s.startsWith(wr);
1881
1893
  }
1882
- class dr extends g {
1894
+ class $e extends Error {
1895
+ }
1896
+ class _e extends Error {
1897
+ }
1898
+ function br(s) {
1899
+ const e = /* @__PURE__ */ new Map();
1900
+ for (const t of s)
1901
+ t.localPath !== "" && N(t.localPath), e.set(t.storageId, t.localPath);
1902
+ return e;
1903
+ }
1904
+ class kr extends g {
1883
1905
  constructor() {
1884
1906
  super("google.protobuf.Timestamp", [
1885
1907
  {
@@ -1904,30 +1926,30 @@ class dr extends g {
1904
1926
  */
1905
1927
  now() {
1906
1928
  const e = this.create(), t = Date.now();
1907
- return e.seconds = I.from(Math.floor(t / 1e3)).toBigInt(), e.nanos = t % 1e3 * 1e6, e;
1929
+ return e.seconds = P.from(Math.floor(t / 1e3)).toBigInt(), e.nanos = t % 1e3 * 1e6, e;
1908
1930
  }
1909
1931
  /**
1910
1932
  * Converts a `Timestamp` to a JavaScript Date.
1911
1933
  */
1912
1934
  toDate(e) {
1913
1935
  return new Date(
1914
- I.from(e.seconds).toNumber() * 1e3 + Math.ceil(e.nanos / 1e6)
1936
+ P.from(e.seconds).toNumber() * 1e3 + Math.ceil(e.nanos / 1e6)
1915
1937
  );
1916
1938
  }
1917
1939
  /**
1918
1940
  * Converts a JavaScript Date to a `Timestamp`.
1919
1941
  */
1920
1942
  fromDate(e) {
1921
- const t = this.create(), n = e.getTime();
1922
- return t.seconds = I.from(Math.floor(n / 1e3)).toBigInt(), t.nanos = n % 1e3 * 1e6, t;
1943
+ const t = this.create(), r = e.getTime();
1944
+ return t.seconds = P.from(Math.floor(r / 1e3)).toBigInt(), t.nanos = r % 1e3 * 1e6, t;
1923
1945
  }
1924
1946
  /**
1925
1947
  * In JSON format, the `Timestamp` type is encoded as a string
1926
1948
  * in the RFC 3339 format.
1927
1949
  */
1928
1950
  internalJsonWrite(e, t) {
1929
- let n = I.from(e.seconds).toNumber() * 1e3;
1930
- if (n < Date.parse("0001-01-01T00:00:00Z") || n > Date.parse("9999-12-31T23:59:59Z"))
1951
+ let r = P.from(e.seconds).toNumber() * 1e3;
1952
+ if (r < Date.parse("0001-01-01T00:00:00Z") || r > Date.parse("9999-12-31T23:59:59Z"))
1931
1953
  throw new Error(
1932
1954
  "Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."
1933
1955
  );
@@ -1935,29 +1957,29 @@ class dr extends g {
1935
1957
  throw new Error(
1936
1958
  "Unable to encode invalid Timestamp to JSON. Nanos must not be negative."
1937
1959
  );
1938
- let r = "Z";
1960
+ let n = "Z";
1939
1961
  if (e.nanos > 0) {
1940
1962
  let o = (e.nanos + 1e9).toString().substring(1);
1941
- o.substring(3) === "000000" ? r = "." + o.substring(0, 3) + "Z" : o.substring(6) === "000" ? r = "." + o.substring(0, 6) + "Z" : r = "." + o + "Z";
1963
+ o.substring(3) === "000000" ? n = "." + o.substring(0, 3) + "Z" : o.substring(6) === "000" ? n = "." + o.substring(0, 6) + "Z" : n = "." + o + "Z";
1942
1964
  }
1943
- return new Date(n).toISOString().replace(".000Z", r);
1965
+ return new Date(r).toISOString().replace(".000Z", n);
1944
1966
  }
1945
1967
  /**
1946
1968
  * In JSON format, the `Timestamp` type is encoded as a string
1947
1969
  * in the RFC 3339 format.
1948
1970
  */
1949
- internalJsonRead(e, t, n) {
1971
+ internalJsonRead(e, t, r) {
1950
1972
  if (typeof e != "string")
1951
1973
  throw new Error(
1952
- "Unable to parse Timestamp from JSON " + Te(e) + "."
1974
+ "Unable to parse Timestamp from JSON " + ke(e) + "."
1953
1975
  );
1954
- let r = e.match(
1976
+ let n = e.match(
1955
1977
  /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/
1956
1978
  );
1957
- if (!r)
1979
+ if (!n)
1958
1980
  throw new Error("Unable to parse Timestamp from JSON. Invalid format.");
1959
1981
  let o = Date.parse(
1960
- r[1] + "-" + r[2] + "-" + r[3] + "T" + r[4] + ":" + r[5] + ":" + r[6] + (r[8] ? r[8] : "Z")
1982
+ n[1] + "-" + n[2] + "-" + n[3] + "T" + n[4] + ":" + n[5] + ":" + n[6] + (n[8] ? n[8] : "Z")
1961
1983
  );
1962
1984
  if (Number.isNaN(o))
1963
1985
  throw new Error("Unable to parse Timestamp from JSON. Invalid value.");
@@ -1965,15 +1987,15 @@ class dr extends g {
1965
1987
  throw new globalThis.Error(
1966
1988
  "Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."
1967
1989
  );
1968
- return n || (n = this.create()), n.seconds = I.from(o / 1e3).toBigInt(), n.nanos = 0, r[7] && (n.nanos = parseInt("1" + r[7] + "0".repeat(9 - r[7].length)) - 1e9), n;
1990
+ return r || (r = this.create()), r.seconds = P.from(o / 1e3).toBigInt(), r.nanos = 0, n[7] && (r.nanos = parseInt("1" + n[7] + "0".repeat(9 - n[7].length)) - 1e9), r;
1969
1991
  }
1970
1992
  create(e) {
1971
1993
  const t = globalThis.Object.create(this.messagePrototype);
1972
1994
  return t.seconds = 0n, t.nanos = 0, e !== void 0 && f(this, t, e), t;
1973
1995
  }
1974
- internalBinaryRead(e, t, n, r) {
1975
- let o = r ?? this.create(), a = e.pos + t;
1976
- for (; e.pos < a; ) {
1996
+ internalBinaryRead(e, t, r, n) {
1997
+ let o = n ?? this.create(), l = e.pos + t;
1998
+ for (; e.pos < l; ) {
1977
1999
  let [i, c] = e.tag();
1978
2000
  switch (i) {
1979
2001
  case /* int64 seconds */
@@ -1985,13 +2007,13 @@ class dr extends g {
1985
2007
  o.nanos = e.int32();
1986
2008
  break;
1987
2009
  default:
1988
- let l = n.readUnknownField;
1989
- if (l === "throw")
2010
+ let a = r.readUnknownField;
2011
+ if (a === "throw")
1990
2012
  throw new globalThis.Error(
1991
2013
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
1992
2014
  );
1993
2015
  let p = e.skip(c);
1994
- l !== !1 && (l === !0 ? u.onRead : l)(
2016
+ a !== !1 && (a === !0 ? u.onRead : a)(
1995
2017
  this.typeName,
1996
2018
  o,
1997
2019
  i,
@@ -2002,18 +2024,18 @@ class dr extends g {
2002
2024
  }
2003
2025
  return o;
2004
2026
  }
2005
- internalBinaryWrite(e, t, n) {
2027
+ internalBinaryWrite(e, t, r) {
2006
2028
  e.seconds !== 0n && t.tag(1, h.Varint).int64(e.seconds), e.nanos !== 0 && t.tag(2, h.Varint).int32(e.nanos);
2007
- let r = n.writeUnknownFields;
2008
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2029
+ let n = r.writeUnknownFields;
2030
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2009
2031
  this.typeName,
2010
2032
  e,
2011
2033
  t
2012
2034
  ), t;
2013
2035
  }
2014
2036
  }
2015
- const M = new dr();
2016
- class hr extends g {
2037
+ const M = new kr();
2038
+ class Tr extends g {
2017
2039
  constructor() {
2018
2040
  super("MiLaboratories.Controller.Shared.LsAPI", []);
2019
2041
  }
@@ -2021,20 +2043,20 @@ class hr extends g {
2021
2043
  const t = globalThis.Object.create(this.messagePrototype);
2022
2044
  return e !== void 0 && f(this, t, e), t;
2023
2045
  }
2024
- internalBinaryRead(e, t, n, r) {
2025
- return r ?? this.create();
2046
+ internalBinaryRead(e, t, r, n) {
2047
+ return n ?? this.create();
2026
2048
  }
2027
- internalBinaryWrite(e, t, n) {
2028
- let r = n.writeUnknownFields;
2029
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2049
+ internalBinaryWrite(e, t, r) {
2050
+ let n = r.writeUnknownFields;
2051
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2030
2052
  this.typeName,
2031
2053
  e,
2032
2054
  t
2033
2055
  ), t;
2034
2056
  }
2035
2057
  }
2036
- new hr();
2037
- class ur extends g {
2058
+ new Tr();
2059
+ class Lr extends g {
2038
2060
  constructor() {
2039
2061
  super("MiLaboratories.Controller.Shared.LsAPI.ListItem", [
2040
2062
  {
@@ -2087,9 +2109,9 @@ class ur extends g {
2087
2109
  const t = globalThis.Object.create(this.messagePrototype);
2088
2110
  return t.name = "", t.size = 0n, t.isDir = !1, t.fullName = "", t.directory = "", t.version = "", e !== void 0 && f(this, t, e), t;
2089
2111
  }
2090
- internalBinaryRead(e, t, n, r) {
2091
- let o = r ?? this.create(), a = e.pos + t;
2092
- for (; e.pos < a; ) {
2112
+ internalBinaryRead(e, t, r, n) {
2113
+ let o = n ?? this.create(), l = e.pos + t;
2114
+ for (; e.pos < l; ) {
2093
2115
  let [i, c] = e.tag();
2094
2116
  switch (i) {
2095
2117
  case /* string name */
@@ -2117,7 +2139,7 @@ class ur extends g {
2117
2139
  o.lastModified = M.internalBinaryRead(
2118
2140
  e,
2119
2141
  e.uint32(),
2120
- n,
2142
+ r,
2121
2143
  o.lastModified
2122
2144
  );
2123
2145
  break;
@@ -2126,13 +2148,13 @@ class ur extends g {
2126
2148
  o.version = e.string();
2127
2149
  break;
2128
2150
  default:
2129
- let l = n.readUnknownField;
2130
- if (l === "throw")
2151
+ let a = r.readUnknownField;
2152
+ if (a === "throw")
2131
2153
  throw new globalThis.Error(
2132
2154
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2133
2155
  );
2134
2156
  let p = e.skip(c);
2135
- l !== !1 && (l === !0 ? u.onRead : l)(
2157
+ a !== !1 && (a === !0 ? u.onRead : a)(
2136
2158
  this.typeName,
2137
2159
  o,
2138
2160
  i,
@@ -2143,22 +2165,22 @@ class ur extends g {
2143
2165
  }
2144
2166
  return o;
2145
2167
  }
2146
- internalBinaryWrite(e, t, n) {
2168
+ internalBinaryWrite(e, t, r) {
2147
2169
  e.name !== "" && t.tag(1, h.LengthDelimited).string(e.name), e.size !== 0n && t.tag(2, h.Varint).uint64(e.size), e.isDir !== !1 && t.tag(3, h.Varint).bool(e.isDir), e.fullName !== "" && t.tag(10, h.LengthDelimited).string(e.fullName), e.directory !== "" && t.tag(11, h.LengthDelimited).string(e.directory), e.lastModified && M.internalBinaryWrite(
2148
2170
  e.lastModified,
2149
2171
  t.tag(12, h.LengthDelimited).fork(),
2150
- n
2172
+ r
2151
2173
  ).join(), e.version !== "" && t.tag(13, h.LengthDelimited).string(e.version);
2152
- let r = n.writeUnknownFields;
2153
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2174
+ let n = r.writeUnknownFields;
2175
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2154
2176
  this.typeName,
2155
2177
  e,
2156
2178
  t
2157
2179
  ), t;
2158
2180
  }
2159
2181
  }
2160
- const H = new ur();
2161
- class pr extends g {
2182
+ const H = new Lr();
2183
+ class Pr extends g {
2162
2184
  constructor() {
2163
2185
  super("MiLaboratories.Controller.Shared.LsAPI.List", []);
2164
2186
  }
@@ -2166,20 +2188,20 @@ class pr extends g {
2166
2188
  const t = globalThis.Object.create(this.messagePrototype);
2167
2189
  return e !== void 0 && f(this, t, e), t;
2168
2190
  }
2169
- internalBinaryRead(e, t, n, r) {
2170
- return r ?? this.create();
2191
+ internalBinaryRead(e, t, r, n) {
2192
+ return n ?? this.create();
2171
2193
  }
2172
- internalBinaryWrite(e, t, n) {
2173
- let r = n.writeUnknownFields;
2174
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2194
+ internalBinaryWrite(e, t, r) {
2195
+ let n = r.writeUnknownFields;
2196
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2175
2197
  this.typeName,
2176
2198
  e,
2177
2199
  t
2178
2200
  ), t;
2179
2201
  }
2180
2202
  }
2181
- new pr();
2182
- class gr extends g {
2203
+ new Pr();
2204
+ class Ir extends g {
2183
2205
  constructor() {
2184
2206
  super("MiLaboratories.Controller.Shared.LsAPI.List.Request", [
2185
2207
  {
@@ -2203,9 +2225,9 @@ class gr extends g {
2203
2225
  const t = globalThis.Object.create(this.messagePrototype);
2204
2226
  return t.resourceId = 0n, t.location = "", e !== void 0 && f(this, t, e), t;
2205
2227
  }
2206
- internalBinaryRead(e, t, n, r) {
2207
- let o = r ?? this.create(), a = e.pos + t;
2208
- for (; e.pos < a; ) {
2228
+ internalBinaryRead(e, t, r, n) {
2229
+ let o = n ?? this.create(), l = e.pos + t;
2230
+ for (; e.pos < l; ) {
2209
2231
  let [i, c] = e.tag();
2210
2232
  switch (i) {
2211
2233
  case /* uint64 resource_id */
@@ -2217,13 +2239,13 @@ class gr extends g {
2217
2239
  o.location = e.string();
2218
2240
  break;
2219
2241
  default:
2220
- let l = n.readUnknownField;
2221
- if (l === "throw")
2242
+ let a = r.readUnknownField;
2243
+ if (a === "throw")
2222
2244
  throw new globalThis.Error(
2223
2245
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2224
2246
  );
2225
2247
  let p = e.skip(c);
2226
- l !== !1 && (l === !0 ? u.onRead : l)(
2248
+ a !== !1 && (a === !0 ? u.onRead : a)(
2227
2249
  this.typeName,
2228
2250
  o,
2229
2251
  i,
@@ -2234,18 +2256,18 @@ class gr extends g {
2234
2256
  }
2235
2257
  return o;
2236
2258
  }
2237
- internalBinaryWrite(e, t, n) {
2259
+ internalBinaryWrite(e, t, r) {
2238
2260
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.location !== "" && t.tag(2, h.LengthDelimited).string(e.location);
2239
- let r = n.writeUnknownFields;
2240
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2261
+ let n = r.writeUnknownFields;
2262
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2241
2263
  this.typeName,
2242
2264
  e,
2243
2265
  t
2244
2266
  ), t;
2245
2267
  }
2246
2268
  }
2247
- const fr = new gr();
2248
- class mr extends g {
2269
+ const Rr = new Ir();
2270
+ class Sr extends g {
2249
2271
  constructor() {
2250
2272
  super("MiLaboratories.Controller.Shared.LsAPI.List.Response", [
2251
2273
  {
@@ -2268,15 +2290,15 @@ class mr extends g {
2268
2290
  const t = globalThis.Object.create(this.messagePrototype);
2269
2291
  return t.items = [], t.delimiter = "", e !== void 0 && f(this, t, e), t;
2270
2292
  }
2271
- internalBinaryRead(e, t, n, r) {
2272
- let o = r ?? this.create(), a = e.pos + t;
2273
- for (; e.pos < a; ) {
2293
+ internalBinaryRead(e, t, r, n) {
2294
+ let o = n ?? this.create(), l = e.pos + t;
2295
+ for (; e.pos < l; ) {
2274
2296
  let [i, c] = e.tag();
2275
2297
  switch (i) {
2276
2298
  case /* repeated MiLaboratories.Controller.Shared.LsAPI.ListItem items */
2277
2299
  1:
2278
2300
  o.items.push(
2279
- H.internalBinaryRead(e, e.uint32(), n)
2301
+ H.internalBinaryRead(e, e.uint32(), r)
2280
2302
  );
2281
2303
  break;
2282
2304
  case /* string delimiter */
@@ -2284,13 +2306,13 @@ class mr extends g {
2284
2306
  o.delimiter = e.string();
2285
2307
  break;
2286
2308
  default:
2287
- let l = n.readUnknownField;
2288
- if (l === "throw")
2309
+ let a = r.readUnknownField;
2310
+ if (a === "throw")
2289
2311
  throw new globalThis.Error(
2290
2312
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2291
2313
  );
2292
2314
  let p = e.skip(c);
2293
- l !== !1 && (l === !0 ? u.onRead : l)(
2315
+ a !== !1 && (a === !0 ? u.onRead : a)(
2294
2316
  this.typeName,
2295
2317
  o,
2296
2318
  i,
@@ -2301,26 +2323,26 @@ class mr extends g {
2301
2323
  }
2302
2324
  return o;
2303
2325
  }
2304
- internalBinaryWrite(e, t, n) {
2326
+ internalBinaryWrite(e, t, r) {
2305
2327
  for (let o = 0; o < e.items.length; o++)
2306
2328
  H.internalBinaryWrite(
2307
2329
  e.items[o],
2308
2330
  t.tag(1, h.LengthDelimited).fork(),
2309
- n
2331
+ r
2310
2332
  ).join();
2311
2333
  e.delimiter !== "" && t.tag(2, h.LengthDelimited).string(e.delimiter);
2312
- let r = n.writeUnknownFields;
2313
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2334
+ let n = r.writeUnknownFields;
2335
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2314
2336
  this.typeName,
2315
2337
  e,
2316
2338
  t
2317
2339
  ), t;
2318
2340
  }
2319
2341
  }
2320
- const wr = new mr(), j = new D("MiLaboratories.Controller.Shared.LS", [
2321
- { name: "List", options: {}, I: fr, O: wr }
2342
+ const Ur = new Sr(), j = new D("MiLaboratories.Controller.Shared.LS", [
2343
+ { name: "List", options: {}, I: Rr, O: Ur }
2322
2344
  ]);
2323
- class yr {
2345
+ class Nr {
2324
2346
  constructor(e) {
2325
2347
  d(this, "typeName", j.typeName);
2326
2348
  d(this, "methods", j.methods);
@@ -2331,34 +2353,34 @@ class yr {
2331
2353
  * @generated from protobuf rpc: List(MiLaboratories.Controller.Shared.LsAPI.List.Request) returns (MiLaboratories.Controller.Shared.LsAPI.List.Response);
2332
2354
  */
2333
2355
  list(e, t) {
2334
- const n = this.methods[0], r = this._transport.mergeOptions(t);
2356
+ const r = this.methods[0], n = this._transport.mergeOptions(t);
2335
2357
  return y(
2336
2358
  "unary",
2337
2359
  this._transport,
2338
- n,
2339
2360
  r,
2361
+ n,
2340
2362
  e
2341
2363
  );
2342
2364
  }
2343
2365
  }
2344
- class br {
2366
+ class Dr {
2345
2367
  constructor(e, t) {
2346
2368
  d(this, "grpcClient");
2347
- this.logger = t, this.grpcClient = new yr(e);
2369
+ this.logger = t, this.grpcClient = new Nr(e);
2348
2370
  }
2349
2371
  close() {
2350
2372
  }
2351
- async list(e, t, n) {
2373
+ async list(e, t, r) {
2352
2374
  return await this.grpcClient.list(
2353
2375
  {
2354
2376
  resourceId: e.id,
2355
2377
  location: t
2356
2378
  },
2357
- k(e.type, n)
2379
+ T(e.type, r)
2358
2380
  ).response;
2359
2381
  }
2360
2382
  }
2361
- class Tr extends g {
2383
+ class Br extends g {
2362
2384
  constructor() {
2363
2385
  super("MiLaboratories.Controller.Shared.StreamingAPI", []);
2364
2386
  }
@@ -2366,20 +2388,20 @@ class Tr extends g {
2366
2388
  const t = globalThis.Object.create(this.messagePrototype);
2367
2389
  return e !== void 0 && f(this, t, e), t;
2368
2390
  }
2369
- internalBinaryRead(e, t, n, r) {
2370
- return r ?? this.create();
2391
+ internalBinaryRead(e, t, r, n) {
2392
+ return n ?? this.create();
2371
2393
  }
2372
- internalBinaryWrite(e, t, n) {
2373
- let r = n.writeUnknownFields;
2374
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2394
+ internalBinaryWrite(e, t, r) {
2395
+ let n = r.writeUnknownFields;
2396
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2375
2397
  this.typeName,
2376
2398
  e,
2377
2399
  t
2378
2400
  ), t;
2379
2401
  }
2380
2402
  }
2381
- new Tr();
2382
- class kr extends g {
2403
+ new Br();
2404
+ class vr extends g {
2383
2405
  constructor() {
2384
2406
  super("MiLaboratories.Controller.Shared.StreamingAPI.StreamBinary", [
2385
2407
  {
@@ -2421,9 +2443,9 @@ class kr extends g {
2421
2443
  const t = globalThis.Object.create(this.messagePrototype);
2422
2444
  return t.resourceId = 0n, t.offset = 0n, e !== void 0 && f(this, t, e), t;
2423
2445
  }
2424
- internalBinaryRead(e, t, n, r) {
2425
- let o = r ?? this.create(), a = e.pos + t;
2426
- for (; e.pos < a; ) {
2446
+ internalBinaryRead(e, t, r, n) {
2447
+ let o = n ?? this.create(), l = e.pos + t;
2448
+ for (; e.pos < l; ) {
2427
2449
  let [i, c] = e.tag();
2428
2450
  switch (i) {
2429
2451
  case /* uint64 resource_id */
@@ -2443,13 +2465,13 @@ class kr extends g {
2443
2465
  o.readLimit = e.int64().toBigInt();
2444
2466
  break;
2445
2467
  default:
2446
- let l = n.readUnknownField;
2447
- if (l === "throw")
2468
+ let a = r.readUnknownField;
2469
+ if (a === "throw")
2448
2470
  throw new globalThis.Error(
2449
2471
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2450
2472
  );
2451
2473
  let p = e.skip(c);
2452
- l !== !1 && (l === !0 ? u.onRead : l)(
2474
+ a !== !1 && (a === !0 ? u.onRead : a)(
2453
2475
  this.typeName,
2454
2476
  o,
2455
2477
  i,
@@ -2460,18 +2482,18 @@ class kr extends g {
2460
2482
  }
2461
2483
  return o;
2462
2484
  }
2463
- internalBinaryWrite(e, t, n) {
2485
+ internalBinaryWrite(e, t, r) {
2464
2486
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.offset !== 0n && t.tag(2, h.Varint).int64(e.offset), e.chunkSize !== void 0 && t.tag(11, h.Varint).uint32(e.chunkSize), e.readLimit !== void 0 && t.tag(20, h.Varint).int64(e.readLimit);
2465
- let r = n.writeUnknownFields;
2466
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2487
+ let n = r.writeUnknownFields;
2488
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2467
2489
  this.typeName,
2468
2490
  e,
2469
2491
  t
2470
2492
  ), t;
2471
2493
  }
2472
2494
  }
2473
- const Lr = new kr();
2474
- class Pr extends g {
2495
+ const $r = new vr();
2496
+ class _r extends g {
2475
2497
  constructor() {
2476
2498
  super("MiLaboratories.Controller.Shared.StreamingAPI.ReadBinary", [
2477
2499
  {
@@ -2504,9 +2526,9 @@ class Pr extends g {
2504
2526
  const t = globalThis.Object.create(this.messagePrototype);
2505
2527
  return t.resourceId = 0n, t.offset = 0n, e !== void 0 && f(this, t, e), t;
2506
2528
  }
2507
- internalBinaryRead(e, t, n, r) {
2508
- let o = r ?? this.create(), a = e.pos + t;
2509
- for (; e.pos < a; ) {
2529
+ internalBinaryRead(e, t, r, n) {
2530
+ let o = n ?? this.create(), l = e.pos + t;
2531
+ for (; e.pos < l; ) {
2510
2532
  let [i, c] = e.tag();
2511
2533
  switch (i) {
2512
2534
  case /* uint64 resource_id */
@@ -2522,13 +2544,13 @@ class Pr extends g {
2522
2544
  o.chunkSize = e.uint32();
2523
2545
  break;
2524
2546
  default:
2525
- let l = n.readUnknownField;
2526
- if (l === "throw")
2547
+ let a = r.readUnknownField;
2548
+ if (a === "throw")
2527
2549
  throw new globalThis.Error(
2528
2550
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2529
2551
  );
2530
2552
  let p = e.skip(c);
2531
- l !== !1 && (l === !0 ? u.onRead : l)(
2553
+ a !== !1 && (a === !0 ? u.onRead : a)(
2532
2554
  this.typeName,
2533
2555
  o,
2534
2556
  i,
@@ -2539,18 +2561,18 @@ class Pr extends g {
2539
2561
  }
2540
2562
  return o;
2541
2563
  }
2542
- internalBinaryWrite(e, t, n) {
2564
+ internalBinaryWrite(e, t, r) {
2543
2565
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.offset !== 0n && t.tag(2, h.Varint).int64(e.offset), e.chunkSize !== void 0 && t.tag(11, h.Varint).uint32(e.chunkSize);
2544
- let r = n.writeUnknownFields;
2545
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2566
+ let n = r.writeUnknownFields;
2567
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2546
2568
  this.typeName,
2547
2569
  e,
2548
2570
  t
2549
2571
  ), t;
2550
2572
  }
2551
2573
  }
2552
- const Ir = new Pr();
2553
- class Rr extends g {
2574
+ const Cr = new _r();
2575
+ class Or extends g {
2554
2576
  constructor() {
2555
2577
  super("MiLaboratories.Controller.Shared.StreamingAPI.StreamText", [
2556
2578
  {
@@ -2600,9 +2622,9 @@ class Rr extends g {
2600
2622
  const t = globalThis.Object.create(this.messagePrototype);
2601
2623
  return t.resourceId = 0n, t.offset = 0n, e !== void 0 && f(this, t, e), t;
2602
2624
  }
2603
- internalBinaryRead(e, t, n, r) {
2604
- let o = r ?? this.create(), a = e.pos + t;
2605
- for (; e.pos < a; ) {
2625
+ internalBinaryRead(e, t, r, n) {
2626
+ let o = n ?? this.create(), l = e.pos + t;
2627
+ for (; e.pos < l; ) {
2606
2628
  let [i, c] = e.tag();
2607
2629
  switch (i) {
2608
2630
  case /* uint64 resource_id */
@@ -2626,13 +2648,13 @@ class Rr extends g {
2626
2648
  o.searchRe = e.string();
2627
2649
  break;
2628
2650
  default:
2629
- let l = n.readUnknownField;
2630
- if (l === "throw")
2651
+ let a = r.readUnknownField;
2652
+ if (a === "throw")
2631
2653
  throw new globalThis.Error(
2632
2654
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2633
2655
  );
2634
2656
  let p = e.skip(c);
2635
- l !== !1 && (l === !0 ? u.onRead : l)(
2657
+ a !== !1 && (a === !0 ? u.onRead : a)(
2636
2658
  this.typeName,
2637
2659
  o,
2638
2660
  i,
@@ -2643,18 +2665,18 @@ class Rr extends g {
2643
2665
  }
2644
2666
  return o;
2645
2667
  }
2646
- internalBinaryWrite(e, t, n) {
2668
+ internalBinaryWrite(e, t, r) {
2647
2669
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.offset !== 0n && t.tag(2, h.Varint).int64(e.offset), e.readLimit !== void 0 && t.tag(20, h.Varint).int64(e.readLimit), e.search !== void 0 && t.tag(21, h.LengthDelimited).string(e.search), e.searchRe !== void 0 && t.tag(22, h.LengthDelimited).string(e.searchRe);
2648
- let r = n.writeUnknownFields;
2649
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2670
+ let n = r.writeUnknownFields;
2671
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2650
2672
  this.typeName,
2651
2673
  e,
2652
2674
  t
2653
2675
  ), t;
2654
2676
  }
2655
2677
  }
2656
- const Sr = new Rr();
2657
- class Nr extends g {
2678
+ const Fr = new Or();
2679
+ class Er extends g {
2658
2680
  constructor() {
2659
2681
  super("MiLaboratories.Controller.Shared.StreamingAPI.ReadText", [
2660
2682
  {
@@ -2704,9 +2726,9 @@ class Nr extends g {
2704
2726
  const t = globalThis.Object.create(this.messagePrototype);
2705
2727
  return t.resourceId = 0n, t.offset = 0n, e !== void 0 && f(this, t, e), t;
2706
2728
  }
2707
- internalBinaryRead(e, t, n, r) {
2708
- let o = r ?? this.create(), a = e.pos + t;
2709
- for (; e.pos < a; ) {
2729
+ internalBinaryRead(e, t, r, n) {
2730
+ let o = n ?? this.create(), l = e.pos + t;
2731
+ for (; e.pos < l; ) {
2710
2732
  let [i, c] = e.tag();
2711
2733
  switch (i) {
2712
2734
  case /* uint64 resource_id */
@@ -2730,13 +2752,13 @@ class Nr extends g {
2730
2752
  o.searchRe = e.string();
2731
2753
  break;
2732
2754
  default:
2733
- let l = n.readUnknownField;
2734
- if (l === "throw")
2755
+ let a = r.readUnknownField;
2756
+ if (a === "throw")
2735
2757
  throw new globalThis.Error(
2736
2758
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2737
2759
  );
2738
2760
  let p = e.skip(c);
2739
- l !== !1 && (l === !0 ? u.onRead : l)(
2761
+ a !== !1 && (a === !0 ? u.onRead : a)(
2740
2762
  this.typeName,
2741
2763
  o,
2742
2764
  i,
@@ -2747,18 +2769,18 @@ class Nr extends g {
2747
2769
  }
2748
2770
  return o;
2749
2771
  }
2750
- internalBinaryWrite(e, t, n) {
2772
+ internalBinaryWrite(e, t, r) {
2751
2773
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.offset !== 0n && t.tag(2, h.Varint).int64(e.offset), e.readLimit !== void 0 && t.tag(20, h.Varint).int64(e.readLimit), e.search !== void 0 && t.tag(21, h.LengthDelimited).string(e.search), e.searchRe !== void 0 && t.tag(22, h.LengthDelimited).string(e.searchRe);
2752
- let r = n.writeUnknownFields;
2753
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2774
+ let n = r.writeUnknownFields;
2775
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2754
2776
  this.typeName,
2755
2777
  e,
2756
2778
  t
2757
2779
  ), t;
2758
2780
  }
2759
2781
  }
2760
- const Ur = new Nr();
2761
- class Br extends g {
2782
+ const Wr = new Er();
2783
+ class Ar extends g {
2762
2784
  constructor() {
2763
2785
  super("MiLaboratories.Controller.Shared.StreamingAPI.LastLines", [
2764
2786
  {
@@ -2808,9 +2830,9 @@ class Br extends g {
2808
2830
  const t = globalThis.Object.create(this.messagePrototype);
2809
2831
  return t.resourceId = 0n, e !== void 0 && f(this, t, e), t;
2810
2832
  }
2811
- internalBinaryRead(e, t, n, r) {
2812
- let o = r ?? this.create(), a = e.pos + t;
2813
- for (; e.pos < a; ) {
2833
+ internalBinaryRead(e, t, r, n) {
2834
+ let o = n ?? this.create(), l = e.pos + t;
2835
+ for (; e.pos < l; ) {
2814
2836
  let [i, c] = e.tag();
2815
2837
  switch (i) {
2816
2838
  case /* uint64 resource_id */
@@ -2834,13 +2856,13 @@ class Br extends g {
2834
2856
  o.searchRe = e.string();
2835
2857
  break;
2836
2858
  default:
2837
- let l = n.readUnknownField;
2838
- if (l === "throw")
2859
+ let a = r.readUnknownField;
2860
+ if (a === "throw")
2839
2861
  throw new globalThis.Error(
2840
2862
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2841
2863
  );
2842
2864
  let p = e.skip(c);
2843
- l !== !1 && (l === !0 ? u.onRead : l)(
2865
+ a !== !1 && (a === !0 ? u.onRead : a)(
2844
2866
  this.typeName,
2845
2867
  o,
2846
2868
  i,
@@ -2851,18 +2873,18 @@ class Br extends g {
2851
2873
  }
2852
2874
  return o;
2853
2875
  }
2854
- internalBinaryWrite(e, t, n) {
2876
+ internalBinaryWrite(e, t, r) {
2855
2877
  e.resourceId !== 0n && t.tag(1, h.Varint).uint64(e.resourceId), e.offset !== void 0 && t.tag(2, h.Varint).int64(e.offset), e.lineCount !== void 0 && t.tag(3, h.Varint).int32(e.lineCount), e.search !== void 0 && t.tag(21, h.LengthDelimited).string(e.search), e.searchRe !== void 0 && t.tag(22, h.LengthDelimited).string(e.searchRe);
2856
- let r = n.writeUnknownFields;
2857
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2878
+ let n = r.writeUnknownFields;
2879
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2858
2880
  this.typeName,
2859
2881
  e,
2860
2882
  t
2861
2883
  ), t;
2862
2884
  }
2863
2885
  }
2864
- const Dr = new Br();
2865
- class vr extends g {
2886
+ const xr = new Ar();
2887
+ class zr extends g {
2866
2888
  constructor() {
2867
2889
  super("MiLaboratories.Controller.Shared.StreamingAPI.Response", [
2868
2890
  {
@@ -2894,9 +2916,9 @@ class vr extends g {
2894
2916
  const t = globalThis.Object.create(this.messagePrototype);
2895
2917
  return t.data = new Uint8Array(0), t.size = 0n, t.newOffset = 0n, e !== void 0 && f(this, t, e), t;
2896
2918
  }
2897
- internalBinaryRead(e, t, n, r) {
2898
- let o = r ?? this.create(), a = e.pos + t;
2899
- for (; e.pos < a; ) {
2919
+ internalBinaryRead(e, t, r, n) {
2920
+ let o = n ?? this.create(), l = e.pos + t;
2921
+ for (; e.pos < l; ) {
2900
2922
  let [i, c] = e.tag();
2901
2923
  switch (i) {
2902
2924
  case /* bytes data */
@@ -2912,13 +2934,13 @@ class vr extends g {
2912
2934
  o.newOffset = e.uint64().toBigInt();
2913
2935
  break;
2914
2936
  default:
2915
- let l = n.readUnknownField;
2916
- if (l === "throw")
2937
+ let a = r.readUnknownField;
2938
+ if (a === "throw")
2917
2939
  throw new globalThis.Error(
2918
2940
  `Unknown field ${i} (wire type ${c}) for ${this.typeName}`
2919
2941
  );
2920
2942
  let p = e.skip(c);
2921
- l !== !1 && (l === !0 ? u.onRead : l)(
2943
+ a !== !1 && (a === !0 ? u.onRead : a)(
2922
2944
  this.typeName,
2923
2945
  o,
2924
2946
  i,
@@ -2929,54 +2951,54 @@ class vr extends g {
2929
2951
  }
2930
2952
  return o;
2931
2953
  }
2932
- internalBinaryWrite(e, t, n) {
2954
+ internalBinaryWrite(e, t, r) {
2933
2955
  e.data.length && t.tag(1, h.LengthDelimited).bytes(e.data), e.size !== 0n && t.tag(2, h.Varint).uint64(e.size), e.newOffset !== 0n && t.tag(3, h.Varint).uint64(e.newOffset);
2934
- let r = n.writeUnknownFields;
2935
- return r !== !1 && (r == !0 ? u.onWrite : r)(
2956
+ let n = r.writeUnknownFields;
2957
+ return n !== !1 && (n == !0 ? u.onWrite : n)(
2936
2958
  this.typeName,
2937
2959
  e,
2938
2960
  t
2939
2961
  ), t;
2940
2962
  }
2941
2963
  }
2942
- const U = new vr(), G = new D(
2964
+ const S = new zr(), G = new D(
2943
2965
  "MiLaboratories.Controller.Shared.Streaming",
2944
2966
  [
2945
2967
  {
2946
2968
  name: "StreamBinary",
2947
2969
  serverStreaming: !0,
2948
2970
  options: {},
2949
- I: Lr,
2950
- O: U
2971
+ I: $r,
2972
+ O: S
2951
2973
  },
2952
2974
  {
2953
2975
  name: "ReadBinary",
2954
2976
  options: {},
2955
- I: Ir,
2956
- O: U
2977
+ I: Cr,
2978
+ O: S
2957
2979
  },
2958
2980
  {
2959
2981
  name: "StreamText",
2960
2982
  serverStreaming: !0,
2961
2983
  options: {},
2962
- I: Sr,
2963
- O: U
2984
+ I: Fr,
2985
+ O: S
2964
2986
  },
2965
2987
  {
2966
2988
  name: "ReadText",
2967
2989
  options: {},
2968
- I: Ur,
2969
- O: U
2990
+ I: Wr,
2991
+ O: S
2970
2992
  },
2971
2993
  {
2972
2994
  name: "LastLines",
2973
2995
  options: {},
2974
- I: Dr,
2975
- O: U
2996
+ I: xr,
2997
+ O: S
2976
2998
  }
2977
2999
  ]
2978
3000
  );
2979
- class $r {
3001
+ class Mr {
2980
3002
  constructor(e) {
2981
3003
  d(this, "typeName", G.typeName);
2982
3004
  d(this, "methods", G.methods);
@@ -2991,12 +3013,12 @@ class $r {
2991
3013
  * @generated from protobuf rpc: StreamBinary(MiLaboratories.Controller.Shared.StreamingAPI.StreamBinary) returns (stream MiLaboratories.Controller.Shared.StreamingAPI.Response);
2992
3014
  */
2993
3015
  streamBinary(e, t) {
2994
- const n = this.methods[0], r = this._transport.mergeOptions(t);
3016
+ const r = this.methods[0], n = this._transport.mergeOptions(t);
2995
3017
  return y(
2996
3018
  "serverStreaming",
2997
3019
  this._transport,
2998
- n,
2999
3020
  r,
3021
+ n,
3000
3022
  e
3001
3023
  );
3002
3024
  }
@@ -3009,12 +3031,12 @@ class $r {
3009
3031
  * @generated from protobuf rpc: ReadBinary(MiLaboratories.Controller.Shared.StreamingAPI.ReadBinary) returns (MiLaboratories.Controller.Shared.StreamingAPI.Response);
3010
3032
  */
3011
3033
  readBinary(e, t) {
3012
- const n = this.methods[1], r = this._transport.mergeOptions(t);
3034
+ const r = this.methods[1], n = this._transport.mergeOptions(t);
3013
3035
  return y(
3014
3036
  "unary",
3015
3037
  this._transport,
3016
- n,
3017
3038
  r,
3039
+ n,
3018
3040
  e
3019
3041
  );
3020
3042
  }
@@ -3025,12 +3047,12 @@ class $r {
3025
3047
  * @generated from protobuf rpc: StreamText(MiLaboratories.Controller.Shared.StreamingAPI.StreamText) returns (stream MiLaboratories.Controller.Shared.StreamingAPI.Response);
3026
3048
  */
3027
3049
  streamText(e, t) {
3028
- const n = this.methods[2], r = this._transport.mergeOptions(t);
3050
+ const r = this.methods[2], n = this._transport.mergeOptions(t);
3029
3051
  return y(
3030
3052
  "serverStreaming",
3031
3053
  this._transport,
3032
- n,
3033
3054
  r,
3055
+ n,
3034
3056
  e
3035
3057
  );
3036
3058
  }
@@ -3043,12 +3065,12 @@ class $r {
3043
3065
  * @generated from protobuf rpc: ReadText(MiLaboratories.Controller.Shared.StreamingAPI.ReadText) returns (MiLaboratories.Controller.Shared.StreamingAPI.Response);
3044
3066
  */
3045
3067
  readText(e, t) {
3046
- const n = this.methods[3], r = this._transport.mergeOptions(t);
3068
+ const r = this.methods[3], n = this._transport.mergeOptions(t);
3047
3069
  return y(
3048
3070
  "unary",
3049
3071
  this._transport,
3050
- n,
3051
3072
  r,
3073
+ n,
3052
3074
  e
3053
3075
  );
3054
3076
  }
@@ -3065,146 +3087,141 @@ class $r {
3065
3087
  * @generated from protobuf rpc: LastLines(MiLaboratories.Controller.Shared.StreamingAPI.LastLines) returns (MiLaboratories.Controller.Shared.StreamingAPI.Response);
3066
3088
  */
3067
3089
  lastLines(e, t) {
3068
- const n = this.methods[4], r = this._transport.mergeOptions(t);
3090
+ const r = this.methods[4], n = this._transport.mergeOptions(t);
3069
3091
  return y(
3070
3092
  "unary",
3071
3093
  this._transport,
3072
- n,
3073
3094
  r,
3095
+ n,
3074
3096
  e
3075
3097
  );
3076
3098
  }
3077
3099
  }
3078
- class _r {
3079
- constructor(e, t, n) {
3100
+ class Hr {
3101
+ constructor(e, t, r) {
3080
3102
  d(this, "grpcClient");
3081
- this.grpcTransport = e, this.httpClient = t, this.logger = n, this.grpcClient = new $r(this.grpcTransport);
3103
+ this.grpcTransport = e, this.httpClient = t, this.logger = r, this.grpcClient = new Mr(this.grpcTransport);
3082
3104
  }
3083
3105
  close() {
3084
3106
  }
3085
3107
  /** Reads text back and returns the text,
3086
3108
  * the new offset
3087
3109
  * and the total size of the (currently existing) file. */
3088
- async lastLines({ id: e, type: t }, n, r = 0n, o, a) {
3110
+ async lastLines({ id: e, type: t }, r, n = 0n, o, l) {
3089
3111
  return (await this.grpcClient.lastLines(
3090
3112
  {
3091
3113
  resourceId: e,
3092
- lineCount: n,
3093
- offset: r,
3114
+ lineCount: r,
3115
+ offset: n,
3094
3116
  search: o
3095
3117
  },
3096
- k(t, a)
3118
+ T(t, l)
3097
3119
  )).response;
3098
3120
  }
3099
3121
  /** Reads the file forward and returns the text,
3100
3122
  * the new offset
3101
3123
  * and the total size of the (currently existing) file. */
3102
- async readText({ id: e, type: t }, n, r = 0n, o, a) {
3124
+ async readText({ id: e, type: t }, r, n = 0n, o, l) {
3103
3125
  return (await this.grpcClient.readText(
3104
3126
  {
3105
- resourceId: K(e),
3106
- readLimit: BigInt(n),
3107
- offset: r,
3127
+ resourceId: te(e),
3128
+ readLimit: BigInt(r),
3129
+ offset: n,
3108
3130
  search: o
3109
3131
  },
3110
- k(t, a)
3132
+ T(t, l)
3111
3133
  )).response;
3112
3134
  }
3113
3135
  }
3114
- function On(s, e, t) {
3136
+ function Yn(s, e, t) {
3115
3137
  return e.getDriver({
3116
3138
  name: "DownloadBlob",
3117
- init: (n, r, o) => new ar(r, o, s, t)
3139
+ init: (r, n, o) => new gr(n, o, s, t)
3118
3140
  });
3119
3141
  }
3120
- function Fn(s, e) {
3142
+ function Kn(s, e) {
3121
3143
  return s.getDriver({
3122
3144
  name: "StreamLogs",
3123
- init: (t, n, r) => new _r(n, r, e)
3145
+ init: (t, r, n) => new Hr(r, n, e)
3124
3146
  });
3125
3147
  }
3126
- function En(s, e) {
3148
+ function eo(s, e) {
3127
3149
  return s.getDriver({
3128
3150
  name: "UploadProgress",
3129
- init: (t, n, r) => new Xt(n, r, s, e)
3151
+ init: (t, r, n) => new or(r, n, s, e)
3130
3152
  });
3131
3153
  }
3132
- function Wn(s, e) {
3154
+ function to(s, e) {
3133
3155
  return s.getDriver({
3134
3156
  name: "UploadBlob",
3135
- init: (t, n, r) => new Ft(n, r, s, e)
3157
+ init: (t, r, n) => new At(r, n, s, e)
3136
3158
  });
3137
3159
  }
3138
- function Cr(s, e) {
3160
+ function jr(s, e) {
3139
3161
  return s.getDriver({
3140
3162
  name: "LsFiles",
3141
- init: (t, n, r) => new br(n, e)
3163
+ init: (t, r, n) => new Dr(r, e)
3142
3164
  });
3143
3165
  }
3144
- class An {
3145
- constructor(e, t) {
3146
- d(this, "updater");
3147
- d(this, "schedule", () => this.updater.schedule());
3148
- this.onUpdate = e, this.sleepMs = t, this.updater = new De(async () => {
3149
- for (; ; ) {
3150
- if (await this.onUpdate()) return;
3151
- await oe.wait(this.sleepMs);
3152
- }
3153
- });
3166
+ class Gr {
3167
+ constructor(e, t, r, n, o) {
3168
+ d(this, "counter", new B());
3169
+ d(this, "change", new v());
3170
+ d(this, "signalCtl", new AbortController());
3171
+ d(this, "error");
3172
+ d(this, "done", !1);
3173
+ /** Represents a size in bytes of the downloaded blob. */
3174
+ d(this, "size", 0);
3175
+ this.logger = e, this.clientDownload = t, this.rInfo = r, this.path = n, this.handle = o;
3154
3176
  }
3155
- }
3156
- class De {
3157
- constructor(e) {
3158
- d(this, "updating");
3159
- this.onUpdate = e;
3177
+ attach(e, t) {
3178
+ this.counter.inc(t), this.done || this.change.attachWatcher(e);
3160
3179
  }
3161
- schedule() {
3162
- this.updating == null && (this.updating = (async () => {
3163
- try {
3164
- await this.onUpdate();
3165
- } catch (e) {
3166
- console.log(`error while updating in Updater: ${e}`);
3167
- } finally {
3168
- this.updating = void 0;
3180
+ async download() {
3181
+ try {
3182
+ await Te(w.dirname(this.path));
3183
+ const { content: e, size: t } = await this.clientDownload.downloadBlob(this.rInfo);
3184
+ await Le(this.path) ? await e.cancel("the file already exists.") : await Pe(this.logger, this.path, async (r) => {
3185
+ const n = ie.toWeb(tt.createWriteStream(r, { flags: "wx" }));
3186
+ await e.pipeTo(n);
3187
+ }), this.setDone(t), this.change.markChanged();
3188
+ } catch (e) {
3189
+ throw Ce(e) && (this.setError(e), this.change.markChanged(), await m.rm(this.path)), e;
3190
+ }
3191
+ }
3192
+ abort(e) {
3193
+ this.signalCtl.abort(new Oe(e));
3194
+ }
3195
+ getBlob() {
3196
+ return this.done ? this.error ? {
3197
+ done: !0,
3198
+ result: { ok: !1, error: this.error }
3199
+ } : {
3200
+ done: !0,
3201
+ result: {
3202
+ ok: !0,
3203
+ value: {
3204
+ handle: this.handle,
3205
+ size: this.size
3206
+ }
3169
3207
  }
3170
- })());
3208
+ } : { done: !1 };
3209
+ }
3210
+ setDone(e) {
3211
+ this.done = !0, this.size = e;
3212
+ }
3213
+ setError(e) {
3214
+ this.done = !0, this.error = e;
3171
3215
  }
3172
3216
  }
3173
- async function zn(s, e) {
3174
- return s.withReadTx("LogsDriverGetStream", async (t) => {
3175
- const n = await t.getResourceData(e, !0), r = await Ve(t, qe(n, "stream"));
3176
- if (r.error != "")
3177
- throw new Error(`while getting stream: ${r.error}`);
3178
- if (!Je(r.valueId))
3179
- return await t.getResourceData(r.valueId, !1);
3180
- });
3217
+ function Ce(s) {
3218
+ return s instanceof Oe || s instanceof ce || s instanceof _e || s instanceof $e || // file that we downloads from was moved or deleted.
3219
+ (s == null ? void 0 : s.code) == "ENOENT" || // A resource was deleted.
3220
+ s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED");
3181
3221
  }
3182
- const ve = "8C7#F1328%9E089B3D22", Or = /(?<stage>.*):\s*(?<progress>[\d.]+%)\s.*(?<eta>ETA:.*)/g;
3183
- function Fr(s) {
3184
- const t = s.replace(ve, "").match(Or);
3185
- if (t == null || t.length != 4)
3186
- return;
3187
- const [n, r, o, a] = t;
3188
- return {
3189
- stage: r,
3190
- // For example, 'Building pre-clones from tag groups'
3191
- progress: o,
3192
- // 35.3%
3193
- eta: a
3194
- // ETA: 00:00:07
3195
- };
3222
+ class Oe extends Error {
3196
3223
  }
3197
- async function xn(s, e, t) {
3198
- const n = await e.lastLines(s, 1, 0n, ve, t);
3199
- if (n.data == null || n.data.length == 0)
3200
- return { found: !1 };
3201
- const r = n.data.toString().split(/\r?\n/)[0];
3202
- if (r == null)
3203
- return { found: !1 };
3204
- const o = Fr(r);
3205
- return o === void 0 ? { found: !1 } : { found: !0, ...o };
3206
- }
3207
- class $e {
3224
+ class Fe {
3208
3225
  constructor(e) {
3209
3226
  d(this, "cache", /* @__PURE__ */ new Map());
3210
3227
  d(this, "totalSizeBytes", 0);
@@ -3214,132 +3231,148 @@ class $e {
3214
3231
  return this.cache.get(e) != null;
3215
3232
  }
3216
3233
  getFile(e, t) {
3217
- const n = this.cache.get(e);
3218
- return n != null && n.counter.inc(t), n;
3234
+ const r = this.cache.get(e);
3235
+ return r != null && r.counter.inc(t), r;
3219
3236
  }
3220
3237
  /** Decrements a counter in a cache and if we exceeds
3221
3238
  * a soft limit, removes files with zero counters. */
3222
3239
  removeFile(e, t) {
3223
- return ce(this.cache, e).counter.dec(t), this.toDelete();
3240
+ return he(this.cache, e).counter.dec(t), this.toDelete();
3224
3241
  }
3225
3242
  /** Returns what results should be deleted to comply with the soft limit. */
3226
3243
  toDelete() {
3227
3244
  if (this.totalSizeBytes <= this.softSizeBytes) return [];
3228
3245
  const e = [];
3229
3246
  let t = 0;
3230
- return Xe(this.cache).filter(([n, r]) => r.counter.isZero()).forEach(([n, r]) => {
3247
+ return Ke(this.cache).filter(([r, n]) => n.counter.isZero()).forEach(([r, n]) => {
3231
3248
  if (this.totalSizeBytes - t <= this.softSizeBytes) return;
3232
- const o = ce(this.cache, n);
3233
- t += o.sizeBytes, e.push(o);
3249
+ const o = he(this.cache, r);
3250
+ t += o.size, e.push(o);
3234
3251
  }), e;
3235
3252
  }
3236
3253
  addCache(e, t) {
3237
- const n = this.cache.get(e.path) == null;
3238
- if (this.cache.set(e.path, e), e.counter.inc(t), e.sizeBytes < 0) throw new Error(`empty sizeBytes: ${e}`);
3239
- n && (this.totalSizeBytes += e.sizeBytes);
3254
+ const r = this.cache.get(e.path) == null;
3255
+ if (this.cache.set(e.path, e), e.counter.inc(t), e.size < 0) throw new Error(`empty sizeBytes: ${e}`);
3256
+ r && (this.totalSizeBytes += e.size);
3240
3257
  }
3241
3258
  removeCache(e) {
3242
- this.cache.delete(e.path), this.totalSizeBytes -= e.sizeBytes;
3259
+ this.cache.delete(e.path), this.totalSizeBytes -= e.size;
3243
3260
  }
3244
3261
  }
3245
- class Mn {
3246
- constructor(e, t, n) {
3247
- this.logger = e, this.logsStreamDriver = t, this.downloadDriver = n;
3248
- }
3249
- getLastLogs(e, t, n) {
3250
- if (n === void 0) return b.make((o) => this.getLastLogs(e, t, o));
3251
- const r = q(n, e);
3252
- if (r === void 0) {
3253
- n.markUnstable("no stream in stream manager");
3254
- return;
3255
- }
3256
- if (V(r)) return this.downloadDriver.getLastLogs(r, t, n);
3257
- try {
3258
- return this.logsStreamDriver.getLastLogs(r, t, n);
3259
- } catch (o) {
3260
- if (o.name == "RpcError" && o.code == "NOT_FOUND") {
3261
- n.markUnstable(`NOT_FOUND in logs stream driver while getting last logs: ${o}`);
3262
- return;
3263
- }
3264
- throw o;
3265
- }
3266
- }
3267
- getProgressLog(e, t, n) {
3268
- if (n === void 0)
3269
- return b.make((o) => this.getProgressLog(e, t, o));
3270
- const r = q(n, e);
3271
- if (r === void 0) {
3272
- n.markUnstable("no stream in stream manager");
3273
- return;
3274
- }
3275
- if (V(r)) return this.downloadDriver.getProgressLog(r, t, n);
3276
- try {
3277
- return this.logsStreamDriver.getProgressLog(r, t, n);
3278
- } catch (o) {
3279
- if (o.name == "RpcError" && o.code == "NOT_FOUND") {
3280
- n.markUnstable(`NOT_FOUND in logs stream driver while getting a progress log: ${o}`);
3281
- return;
3282
- }
3283
- throw o;
3284
- }
3285
- }
3286
- getLogHandle(e, t) {
3287
- if (t === void 0) return b.make((r) => this.getLogHandle(e, r));
3288
- const n = q(t, e);
3289
- if (n === void 0) {
3290
- t.markUnstable("no stream in stream manager");
3291
- return;
3292
- }
3293
- return V(n) ? this.downloadDriver.getLogHandle(n, t) : this.logsStreamDriver.getLogHandle(n, t);
3294
- }
3295
- async lastLines(e, t, n, r) {
3296
- return C(e) ? await this.logsStreamDriver.lastLines(e, t, n, r) : await this.downloadDriver.lastLines(e, t, n, r);
3297
- }
3298
- async readText(e, t, n, r) {
3299
- return C(e) ? await this.logsStreamDriver.readText(e, t, n, r) : await this.downloadDriver.readText(e, t, n, r);
3300
- }
3262
+ const Ee = /^blob\+local:\/\/download\/(?<path>.*)#(?<signature>.*)$/;
3263
+ function Vr(s, e) {
3264
+ return `blob+local://download/${s}#${e.sign(s)}`;
3301
3265
  }
3302
- function V(s) {
3303
- return !s.type.name.startsWith("StreamWorkdir");
3266
+ function qr(s) {
3267
+ return !!s.match(Ee);
3304
3268
  }
3305
- function q(s, e) {
3306
- var t;
3307
- return (t = s.accessor(e).node().traverse("stream")) == null ? void 0 : t.resourceInfo;
3269
+ function V(s, e) {
3270
+ const t = s.match(Ee);
3271
+ if (t === null)
3272
+ throw new Error(`Local handle is malformed: ${s}, matches: ${t}`);
3273
+ const { path: r, signature: n } = t.groups;
3274
+ return e.verify(r, n, `Signature verification failed for: ${s}`), { path: r, signature: n };
3308
3275
  }
3276
+ const Jr = ae({
3277
+ kv: {
3278
+ "ctl/file/blobInfo": k.object({
3279
+ sizeBytes: k.coerce.number()
3280
+ })
3281
+ }
3282
+ });
3283
+ function Zr(s) {
3284
+ return s.kv["ctl/file/blobInfo"].sizeBytes;
3285
+ }
3286
+ const O = k.object({
3287
+ /** Local file path, to take data for upload */
3288
+ localPath: k.string(),
3289
+ /** Path signature, to check this data was generated by us */
3290
+ pathSignature: k.string(),
3291
+ /** File size in bytes */
3292
+ sizeBytes: k.string(),
3293
+ /** Modification time unix timestamp in seconds */
3294
+ modificationTime: k.string()
3295
+ }), We = k.object({
3296
+ /** Pl storage id */
3297
+ storageId: k.string(),
3298
+ /** Path inside storage */
3299
+ path: k.string()
3300
+ }), ro = k.union([
3301
+ O,
3302
+ We
3303
+ ]), Qr = ae({
3304
+ data: O,
3305
+ fields: {
3306
+ blob: !1
3307
+ }
3308
+ }), Xr = ae({
3309
+ fields: {
3310
+ incarnation: !1
3311
+ }
3312
+ }), Ae = /^blob\+remote:\/\/download\/(?<content>(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*))#(?<signature>.*)$/;
3313
+ function Yr(s, e) {
3314
+ const t = `${s.type.name}/${s.type.version}/${BigInt(s.id)}`;
3315
+ return `blob+remote://download/${t}#${e.sign(t)}`;
3316
+ }
3317
+ function Kr(s) {
3318
+ return !!s.match(Ae);
3319
+ }
3320
+ function en(s, e) {
3321
+ const t = s.match(Ae);
3322
+ if (t === null)
3323
+ throw new Error(`Remote handle is malformed: ${s}, matches: ${t}`);
3324
+ const { content: r, resourceType: n, resourceVersion: o, resourceId: l, signature: i } = t.groups;
3325
+ return e.verify(r, i, `Signature verification failed for ${s}`), {
3326
+ id: ee(BigInt(l)),
3327
+ type: { name: n, version: o }
3328
+ };
3329
+ }
3330
+ function xe(s, e) {
3331
+ return s ? `log+live://log/${e.type.name}/${e.type.version}/${BigInt(e.id)}` : `log+ready://log/${e.type.name}/${e.type.version}/${BigInt(e.id)}`;
3332
+ }
3333
+ const ze = /^log\+live:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3309
3334
  function _(s) {
3335
+ return ze.test(s);
3336
+ }
3337
+ const Me = /^log\+ready:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3338
+ function tn(s) {
3339
+ return Me.test(s);
3340
+ }
3341
+ function C(s) {
3310
3342
  let e;
3311
- if (C(s))
3312
- e = s.match(Ce);
3313
- else if (Er(s))
3314
- e = s.match(Oe);
3343
+ if (_(s))
3344
+ e = s.match(ze);
3345
+ else if (tn(s))
3346
+ e = s.match(Me);
3315
3347
  else throw new Error(`Log handle is malformed: ${s}`);
3316
3348
  if (e == null) throw new Error(`Log handle wasn't parsed: ${s}`);
3317
- const { resourceType: t, resourceVersion: n, resourceId: r } = e.groups;
3349
+ const { resourceType: t, resourceVersion: r, resourceId: n } = e.groups;
3318
3350
  return {
3319
- id: Y(BigInt(r)),
3320
- type: { name: t, version: n }
3351
+ id: ee(BigInt(n)),
3352
+ type: { name: t, version: r }
3321
3353
  };
3322
3354
  }
3323
- function _e(s, e) {
3324
- return s ? `log+live://log/${e.type.name}/${e.type.version}/${BigInt(e.id)}` : `log+ready://log/${e.type.name}/${e.type.version}/${BigInt(e.id)}`;
3355
+ class de extends Error {
3325
3356
  }
3326
- const Ce = /^log\+live:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3327
- function C(s) {
3328
- return Ce.test(s);
3329
- }
3330
- const Oe = /^log\+ready:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3331
- function Er(s) {
3332
- return Oe.test(s);
3333
- }
3334
- const Wr = se({
3335
- kv: {
3336
- "ctl/file/blobInfo": T.object({
3337
- sizeBytes: T.coerce.number()
3338
- })
3357
+ class rn {
3358
+ constructor(e) {
3359
+ d(this, "updating");
3360
+ this.onUpdate = e;
3339
3361
  }
3340
- });
3341
- class Hn {
3342
- constructor(e, t, n, r, o, a) {
3362
+ schedule() {
3363
+ this.updating == null && (this.updating = (async () => {
3364
+ try {
3365
+ await this.onUpdate();
3366
+ } catch (e) {
3367
+ console.log(`error while updating in Updater: ${e}`);
3368
+ } finally {
3369
+ this.updating = void 0;
3370
+ }
3371
+ })());
3372
+ }
3373
+ }
3374
+ class no {
3375
+ constructor(e, t, r, n, o, l) {
3343
3376
  /** Represents a Resource Id to the path of a blob as a map. */
3344
3377
  d(this, "idToDownload", /* @__PURE__ */ new Map());
3345
3378
  /** Writes and removes files to a hard drive and holds a counter for every
@@ -3351,125 +3384,134 @@ class Hn {
3351
3384
  d(this, "idToLastLines", /* @__PURE__ */ new Map());
3352
3385
  d(this, "idToProgressLog", /* @__PURE__ */ new Map());
3353
3386
  d(this, "saveDir");
3354
- this.logger = e, this.clientDownload = t, this.clientLogs = n, this.signer = o, this.cache = new $e(a.cacheSoftSizeBytes), this.downloadQueue = new ee(this.logger, a.nConcurrentDownloads), this.saveDir = w.resolve(r);
3387
+ this.logger = e, this.clientDownload = t, this.clientLogs = r, this.signer = o, this.cache = new Fe(l.cacheSoftSizeBytes), this.downloadQueue = new re(this.logger, l.nConcurrentDownloads), this.saveDir = w.resolve(n);
3355
3388
  }
3356
3389
  getDownloadedBlob(e, t) {
3357
- if (t === void 0) return b.make((a) => this.getDownloadedBlob(e, a));
3358
- const n = R(e, t), r = L();
3359
- t.addOnDestroy(() => this.releaseBlob(n.id, r));
3360
- const o = this.getDownloadedBlobNoCtx(t.watcher, n, r);
3390
+ if (t === void 0) return b.make((l) => this.getDownloadedBlob(e, l));
3391
+ const r = I(e, t), n = L();
3392
+ t.addOnDestroy(() => this.releaseBlob(r.id, n));
3393
+ const o = this.getDownloadedBlobNoCtx(t.watcher, r, n);
3361
3394
  return o == null && t.markUnstable("download blob is still undefined"), o;
3362
3395
  }
3363
- getOnDemandBlob(e, t) {
3364
- if (t === void 0) return b.make((a) => this.getOnDemandBlob(e, a));
3365
- const n = ie(e) ? Q(e, Wr, t) : e, r = L();
3366
- return t.addOnDestroy(() => this.releaseOnDemandBlob(n.id, r)), this.getOnDemandBlobNoCtx(t.watcher, n, r);
3367
- }
3368
- getLocalPath(e) {
3369
- return J(e, this.signer);
3370
- }
3371
- async getContent(e) {
3372
- if (Hr(e)) return await zr(this.getLocalPath(e));
3373
- if (!Gr(e)) throw new Error("Malformed remote handle");
3374
- const t = Vr(e, this.signer), { content: n } = await this.clientDownload.downloadBlob(t);
3375
- return await Le(n);
3376
- }
3377
- getDownloadedBlobNoCtx(e, t, n) {
3378
- let r = this.idToDownload.get(t.id);
3379
- if (r === void 0) {
3380
- const a = this.setNewDownloadTask(e, t, n);
3396
+ getDownloadedBlobNoCtx(e, t, r) {
3397
+ U("getDownloadedBlob", t.type);
3398
+ let n = this.idToDownload.get(t.id);
3399
+ if (n === void 0) {
3400
+ const l = this.setNewDownloadTask(t);
3381
3401
  this.downloadQueue.push({
3382
- fn: () => this.downloadBlob(a, n),
3383
- recoverableErrorPredicate: (i) => !0
3384
- }), r = a;
3402
+ fn: () => this.downloadBlob(l, r),
3403
+ recoverableErrorPredicate: (i) => !Ce(i)
3404
+ }), n = l;
3385
3405
  }
3386
- r.attach(e, n);
3387
- const o = r.getBlob();
3388
- if (o !== void 0) {
3389
- if (o.ok) return o.value;
3390
- throw o.error;
3406
+ n.attach(e, r);
3407
+ const o = n.getBlob();
3408
+ if (o.done) {
3409
+ if (o.result.ok) return o.result.value;
3410
+ throw o.result.error;
3391
3411
  }
3392
3412
  }
3393
- setNewDownloadTask(e, t, n) {
3394
- const r = this.getFilePath(t.id), o = new Mr(
3413
+ setNewDownloadTask(e) {
3414
+ const t = this.getFilePath(e.id), r = new Gr(
3415
+ this.logger,
3395
3416
  this.clientDownload,
3417
+ e,
3396
3418
  t,
3397
- r,
3398
- jr(r, this.signer)
3419
+ Vr(t, this.signer)
3399
3420
  );
3400
- return this.idToDownload.set(t.id, o), o;
3421
+ return this.idToDownload.set(e.id, r), r;
3401
3422
  }
3402
3423
  async downloadBlob(e, t) {
3403
- var n;
3404
- await e.download(), (n = e.getBlob()) != null && n.ok && this.cache.addCache(e, t);
3405
- }
3406
- getOnDemandBlobNoCtx(e, t, n) {
3407
- let r = this.idToOnDemand.get(t.id);
3408
- return r === void 0 && (r = new Ar(
3409
- t.kv["ctl/file/blobInfo"].sizeBytes,
3410
- qr(t, this.signer)
3411
- ), this.idToOnDemand.set(t.id, r)), r.attach(e, n), r.getHandle();
3412
- }
3413
- getLastLogs(e, t, n) {
3414
- if (n == null) return b.make((i) => this.getLastLogs(e, t, i));
3415
- const r = R(e, n), o = L();
3416
- n.addOnDestroy(() => this.releaseBlob(r.id, o));
3417
- const a = this.getLastLogsNoCtx(n.watcher, r, t, o);
3418
- return a == null && n.markUnstable("either a file was not downloaded or logs was not read"), a;
3419
- }
3420
- getLastLogsNoCtx(e, t, n, r) {
3421
- const o = this.getDownloadedBlobNoCtx(e, t, r);
3424
+ await e.download();
3425
+ const r = e.getBlob();
3426
+ r.done && r.result.ok && this.cache.addCache(e, t);
3427
+ }
3428
+ getOnDemandBlob(e, t) {
3429
+ if (t === void 0) return b.make((l) => this.getOnDemandBlob(e, l));
3430
+ const r = le(e) ? X(e, Jr, t) : e, n = L();
3431
+ return t.addOnDestroy(() => this.releaseOnDemandBlob(r.id, n)), this.getOnDemandBlobNoCtx(r, n);
3432
+ }
3433
+ getOnDemandBlobNoCtx(e, t) {
3434
+ U("getOnDemandBlob", e.type);
3435
+ let r = this.idToOnDemand.get(e.id);
3436
+ return r === void 0 && (r = new nn(Zr(e), Yr(e, this.signer)), this.idToOnDemand.set(e.id, r)), r.attach(t), r.getHandle();
3437
+ }
3438
+ /** Gets a path from a handle. */
3439
+ getLocalPath(e) {
3440
+ const { path: t } = V(e, this.signer);
3441
+ return t;
3442
+ }
3443
+ /** Gets a content of a blob by a handle. */
3444
+ async getContent(e) {
3445
+ if (qr(e))
3446
+ return await sn(this.getLocalPath(e));
3447
+ if (Kr(e)) {
3448
+ const t = en(e, this.signer), { content: r } = await this.clientDownload.downloadBlob(t);
3449
+ return await Ie(r);
3450
+ }
3451
+ throw new Error("Malformed remote handle");
3452
+ }
3453
+ getLastLogs(e, t, r) {
3454
+ if (r == null) return b.make((i) => this.getLastLogs(e, t, i));
3455
+ const n = I(e, r), o = L();
3456
+ r.addOnDestroy(() => this.releaseBlob(n.id, o));
3457
+ const l = this.getLastLogsNoCtx(r.watcher, n, t, o);
3458
+ return l == null && r.markUnstable("either a file was not downloaded or logs was not read"), l;
3459
+ }
3460
+ getLastLogsNoCtx(e, t, r, n) {
3461
+ U("getLastLogs", t.type);
3462
+ const o = this.getDownloadedBlobNoCtx(e, t, n);
3422
3463
  if (o == null) return;
3423
- const a = J(o.handle, this.signer);
3464
+ const { path: l } = V(o.handle, this.signer);
3424
3465
  let i = this.idToLastLines.get(t.id);
3425
3466
  if (i == null) {
3426
- const l = new he(a, n);
3427
- this.idToLastLines.set(t.id, l), i = l;
3467
+ const a = new pe(l, r);
3468
+ this.idToLastLines.set(t.id, a), i = a;
3428
3469
  }
3429
3470
  const c = i.getOrSchedule(e);
3430
3471
  if (c.error) throw c.error;
3431
3472
  return c.log;
3432
3473
  }
3433
- getProgressLog(e, t, n) {
3434
- if (n == null)
3474
+ getProgressLog(e, t, r) {
3475
+ if (r == null)
3435
3476
  return b.make((i) => this.getProgressLog(e, t, i));
3436
- const r = R(e, n), o = L();
3437
- n.addOnDestroy(() => this.releaseBlob(r.id, o));
3438
- const a = this.getProgressLogNoCtx(
3439
- n.watcher,
3440
- r,
3477
+ const n = I(e, r), o = L();
3478
+ r.addOnDestroy(() => this.releaseBlob(n.id, o));
3479
+ const l = this.getProgressLogNoCtx(
3480
+ r.watcher,
3481
+ n,
3441
3482
  t,
3442
3483
  o
3443
3484
  );
3444
- return a === void 0 && n.markUnstable("either a file was not downloaded or a progress log was not read"), a;
3485
+ return l === void 0 && r.markUnstable("either a file was not downloaded or a progress log was not read"), l;
3445
3486
  }
3446
- getProgressLogNoCtx(e, t, n, r) {
3447
- const o = this.getDownloadedBlobNoCtx(e, t, r);
3487
+ getProgressLogNoCtx(e, t, r, n) {
3488
+ U("getProgressLog", t.type);
3489
+ const o = this.getDownloadedBlobNoCtx(e, t, n);
3448
3490
  if (o == null) return;
3449
- const a = J(o.handle, this.signer);
3491
+ const { path: l } = V(o.handle, this.signer);
3450
3492
  let i = this.idToProgressLog.get(t.id);
3451
3493
  if (i == null) {
3452
- const l = new he(a, 1, n);
3453
- this.idToProgressLog.set(t.id, l), i = l;
3494
+ const a = new pe(l, 1, r);
3495
+ this.idToProgressLog.set(t.id, a), i = a;
3454
3496
  }
3455
3497
  const c = i.getOrSchedule(e);
3456
3498
  if (c.error) throw c.error;
3457
3499
  return c.log;
3458
3500
  }
3459
3501
  getLogHandle(e, t) {
3460
- if (t == null) return b.make((r) => this.getLogHandle(e, r));
3461
- const n = R(e, t);
3462
- return this.getLogHandleNoCtx(n);
3502
+ if (t == null) return b.make((n) => this.getLogHandle(e, n));
3503
+ const r = I(e, t);
3504
+ return this.getLogHandleNoCtx(r);
3463
3505
  }
3464
3506
  getLogHandleNoCtx(e) {
3465
- return _e(!1, e);
3507
+ return U("getLogHandle", e.type), xe(!1, e);
3466
3508
  }
3467
- async lastLines(e, t, n, r) {
3509
+ async lastLines(e, t, r, n) {
3468
3510
  const o = await this.clientLogs.lastLines(
3469
- _(e),
3511
+ C(e),
3470
3512
  t,
3471
- BigInt(n ?? 0),
3472
- r
3513
+ BigInt(r ?? 0),
3514
+ n
3473
3515
  );
3474
3516
  return {
3475
3517
  live: !1,
@@ -3479,12 +3521,12 @@ class Hn {
3479
3521
  newOffset: Number(o.newOffset)
3480
3522
  };
3481
3523
  }
3482
- async readText(e, t, n, r) {
3524
+ async readText(e, t, r, n) {
3483
3525
  const o = await this.clientLogs.readText(
3484
- _(e),
3526
+ C(e),
3485
3527
  t,
3486
- BigInt(n ?? 0),
3487
- r
3528
+ BigInt(r ?? 0),
3529
+ n
3488
3530
  );
3489
3531
  return {
3490
3532
  live: !1,
@@ -3495,27 +3537,27 @@ class Hn {
3495
3537
  };
3496
3538
  }
3497
3539
  async releaseBlob(e, t) {
3498
- const n = this.idToDownload.get(e);
3499
- if (n != null)
3500
- if (this.cache.existsFile(n.path)) {
3501
- const r = this.cache.removeFile(n.path, t);
3540
+ const r = this.idToDownload.get(e);
3541
+ if (r != null)
3542
+ if (this.cache.existsFile(r.path)) {
3543
+ const n = this.cache.removeFile(r.path, t);
3502
3544
  await Promise.all(
3503
- r.map(async (o) => {
3545
+ n.map(async (o) => {
3504
3546
  await m.rm(o.path), this.cache.removeCache(o), this.removeTask(
3505
3547
  o,
3506
- `the task ${o.path} was removedfrom cache along with ${r.map((a) => a.path)}`
3548
+ `the task ${o.path} was removedfrom cache along with ${n.map((l) => l.path)}`
3507
3549
  );
3508
3550
  })
3509
3551
  );
3510
3552
  } else
3511
- n.counter.dec(t) && this.removeTask(n, `the task ${n.path} was removed from cache`);
3553
+ r.counter.dec(t) && this.removeTask(r, `the task ${r.path} was removed from cache`);
3512
3554
  }
3513
3555
  removeTask(e, t) {
3514
3556
  e.abort(t), e.change.markChanged(), this.idToDownload.delete(e.rInfo.id), this.idToLastLines.delete(e.rInfo.id), this.idToProgressLog.delete(e.rInfo.id);
3515
3557
  }
3516
3558
  async releaseOnDemandBlob(e, t) {
3517
- var r;
3518
- (((r = this.idToOnDemand.get(e)) == null ? void 0 : r.release(t)) ?? !1) && this.idToOnDemand.delete(e);
3559
+ var n;
3560
+ (((n = this.idToOnDemand.get(e)) == null ? void 0 : n.release(t)) ?? !1) && this.idToOnDemand.delete(e);
3519
3561
  }
3520
3562
  /** Removes all files from a hard drive. */
3521
3563
  async releaseAll() {
@@ -3524,32 +3566,31 @@ class Hn {
3524
3566
  });
3525
3567
  }
3526
3568
  getFilePath(e) {
3527
- return w.resolve(w.join(this.saveDir, String(BigInt(e))));
3569
+ return w.resolve(this.saveDir, String(BigInt(e)));
3528
3570
  }
3529
3571
  }
3530
- class Ar {
3572
+ class nn {
3531
3573
  constructor(e, t) {
3532
- d(this, "change", new N());
3533
- d(this, "counter", new v());
3574
+ d(this, "counter", new B());
3534
3575
  this.size = e, this.handle = t;
3535
3576
  }
3536
3577
  getHandle() {
3537
3578
  return { handle: this.handle, size: this.size };
3538
3579
  }
3539
- attach(e, t) {
3540
- this.counter.inc(t), this.change.attachWatcher(e);
3580
+ attach(e) {
3581
+ this.counter.inc(e);
3541
3582
  }
3542
3583
  release(e) {
3543
3584
  return this.counter.dec(e);
3544
3585
  }
3545
3586
  }
3546
- class he {
3547
- constructor(e, t, n) {
3587
+ class pe {
3588
+ constructor(e, t, r) {
3548
3589
  d(this, "updater");
3549
3590
  d(this, "log");
3550
- d(this, "change", new N());
3591
+ d(this, "change", new v());
3551
3592
  d(this, "error");
3552
- this.path = e, this.lines = t, this.patternToSearch = n, this.updater = new De(async () => this.update());
3593
+ this.path = e, this.lines = t, this.patternToSearch = r, this.updater = new rn(async () => this.update());
3553
3594
  }
3554
3595
  getOrSchedule(e) {
3555
3596
  return this.change.attachWatcher(e), this.updater.schedule(), {
@@ -3559,7 +3600,7 @@ class he {
3559
3600
  }
3560
3601
  async update() {
3561
3602
  try {
3562
- const e = await xr(this.path, this.lines, this.patternToSearch);
3603
+ const e = await on(this.path, this.lines, this.patternToSearch);
3563
3604
  this.log != e && this.change.markChanged(), this.log = e;
3564
3605
  } catch (e) {
3565
3606
  if (e.name == "RpcError" && e.code == "NOT_FOUND") {
@@ -3570,148 +3611,168 @@ class he {
3570
3611
  }
3571
3612
  }
3572
3613
  }
3573
- async function ue(s) {
3574
- try {
3575
- return await m.access(s), !0;
3576
- } catch {
3577
- return !1;
3578
- }
3579
- }
3580
- async function zr(s) {
3581
- return await Le(re.toWeb(O.createReadStream(s)));
3582
- }
3583
- function xr(s, e, t) {
3584
- const n = O.createReadStream(s), r = new ne();
3585
- return new Promise((o, a) => {
3586
- const i = rt.createInterface(n, r), c = new nt();
3587
- i.on("line", function(l) {
3588
- t != null && !l.includes(t) || (c.push(l), c.length > e && c.shift());
3589
- }), i.on("error", a), i.on("close", function() {
3590
- o(c.toArray().join(de.EOL) + de.EOL);
3614
+ function on(s, e, t) {
3615
+ const r = oe.createReadStream(s), n = new ie();
3616
+ return new Promise((o, l) => {
3617
+ const i = lt.createInterface(r, n), c = new st();
3618
+ i.on("line", function(a) {
3619
+ t != null && !a.includes(t) || (c.push(a), c.length > e && c.shift());
3620
+ }), i.on("error", l), i.on("close", function() {
3621
+ o(c.toArray().join(ue.EOL) + ue.EOL);
3591
3622
  });
3592
3623
  });
3593
3624
  }
3594
- let Mr = class {
3595
- constructor(e, t, n, r) {
3596
- d(this, "counter", new v());
3597
- d(this, "change", new N());
3598
- d(this, "signalCtl", new AbortController());
3599
- d(this, "error");
3600
- d(this, "done", !1);
3601
- d(this, "sizeBytes", 0);
3602
- this.clientDownload = e, this.rInfo = t, this.path = n, this.handle = r;
3625
+ async function sn(s) {
3626
+ return await Ie(se.toWeb(oe.createReadStream(s)));
3627
+ }
3628
+ function U(s, e) {
3629
+ if (!e.name.startsWith("Blob/")) {
3630
+ let t = `${s}: wrong resource type: ${e.name}, expected: a resource of type that starts with 'Blob/'.`;
3631
+ throw e.name == "Blob" && (t += " If it's called from workflow, should a file be exported with 'file.exportFile' function?"), new de(t);
3603
3632
  }
3604
- attach(e, t) {
3605
- this.counter.inc(t), this.done || this.change.attachWatcher(e);
3633
+ }
3634
+ class an {
3635
+ constructor(e, t, r, n, o, l) {
3636
+ d(this, "change", new v());
3637
+ d(this, "counter", new B());
3638
+ /** If this is upload progress this field will be defined */
3639
+ d(this, "uploadData");
3640
+ d(this, "progress");
3641
+ /** If failed, then getting a progress is terminally failed. */
3642
+ d(this, "failed");
3643
+ this.logger = e, this.clientBlob = t, this.clientProgress = r, this.nConcurrentPartsUpload = n, this.res = l;
3644
+ const { uploadData: i, progress: c } = ln(l, o);
3645
+ this.uploadData = i, this.progress = c;
3646
+ }
3647
+ getProgress(e, t) {
3648
+ if (this.incCounter(e, t), this.failed)
3649
+ throw this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`), new Error(this.progress.lastError);
3650
+ return cn(this.progress);
3606
3651
  }
3607
- async download() {
3652
+ shouldScheduleUpload() {
3653
+ return this.progress.isUpload && this.progress.isUploadSignMatch;
3654
+ }
3655
+ /** Uploads a blob if it's not BlobIndex. */
3656
+ async uploadBlobTask() {
3657
+ ct(Y(this.res), "the upload operation can be done only for BlobUploads");
3608
3658
  try {
3609
- const { content: e, size: t } = await this.clientDownload.downloadBlob(this.rInfo);
3610
- if (await ue(w.dirname(this.path)) || await m.mkdir(w.dirname(this.path), { recursive: !0 }), await ue(this.path))
3611
- await e.cancel("the file already existed");
3612
- else {
3613
- const n = ne.toWeb(O.createWriteStream(this.path));
3614
- await e.pipeTo(n);
3615
- }
3616
- this.setDone(t);
3659
+ if (this.isComputableDone()) return;
3660
+ const e = await this.clientBlob.initUpload(this.res);
3661
+ this.logger.info(
3662
+ `started to upload blob ${this.res.id}, parts overall: ${e.overall}, parts remained: ${e.toUpload.length}`
3663
+ );
3664
+ const t = (r) => async () => {
3665
+ this.isComputableDone() || (await this.clientBlob.partUpload(
3666
+ this.res,
3667
+ this.uploadData.localPath,
3668
+ BigInt(this.uploadData.modificationTime),
3669
+ r
3670
+ ), this.logger.info(`uploaded chunk ${r}/${e.overall} of resource: ${this.res.id}`));
3671
+ };
3672
+ if (await ne(this.nConcurrentPartsUpload, e.toUpload.map(t)), this.isComputableDone()) return;
3673
+ await this.clientBlob.finalize(this.res), this.logger.info(`uploading of resource ${this.res.id} finished.`), this.change.markChanged();
3617
3674
  } catch (e) {
3618
- if (e instanceof pe || e instanceof ae || e instanceof Ue || e instanceof Be || e.code == "ENOENT") {
3619
- this.setError(e), await m.rm(this.path);
3675
+ if (this.setRetriableError(e), ge(e)) {
3676
+ this.logger.warn(`resource was deleted while uploading a blob: ${e}`), this.change.markChanged(), this.setDone(!0);
3677
+ return;
3678
+ }
3679
+ if (this.logger.error(`error while uploading a blob: ${e}`), this.change.markChanged(), He(e)) {
3680
+ this.setTerminalError(e);
3620
3681
  return;
3621
3682
  }
3622
3683
  throw e;
3623
3684
  }
3624
3685
  }
3625
- getBlob() {
3626
- if (this.done)
3627
- return {
3628
- ok: !0,
3629
- value: {
3630
- handle: this.handle,
3631
- size: this.sizeBytes
3632
- }
3633
- };
3634
- if (this.error)
3635
- return {
3636
- ok: !1,
3637
- error: this.error
3638
- };
3686
+ async updateStatus() {
3687
+ try {
3688
+ const e = await this.clientProgress.getStatus(this.res), t = this.progress.status;
3689
+ this.progress.status = un(e), this.setDone(e.done), (e.done || e.progress != (t == null ? void 0 : t.progress)) && this.change.markChanged();
3690
+ } catch (e) {
3691
+ if (this.setRetriableError(e), e.name == "RpcError" && e.code == "DEADLINE_EXCEEDED") {
3692
+ this.logger.warn("deadline exceeded while getting a status of BlobImport");
3693
+ return;
3694
+ }
3695
+ if (ge(e)) {
3696
+ this.logger.warn(
3697
+ `resource was not found while updating a status of BlobImport: ${e}, ${ye(this.res)}`
3698
+ ), this.change.markChanged(), this.setDone(!0);
3699
+ return;
3700
+ }
3701
+ this.logger.error(`error while updating a status of BlobImport: ${e}`), this.change.markChanged(), this.setTerminalError(e);
3702
+ }
3703
+ }
3704
+ /** Set non-terminal error, that task can be retried. */
3705
+ setRetriableError(e) {
3706
+ this.progress.lastError = String(e);
3707
+ }
3708
+ /** Set a terminal error, the task will throw a error instead of a progress. */
3709
+ setTerminalError(e) {
3710
+ this.progress.lastError = String(e), this.progress.done = !1, this.failed = !0;
3711
+ }
3712
+ setDoneIfOutputSet(e) {
3713
+ dn(e) && this.setDone(!0);
3639
3714
  }
3640
3715
  setDone(e) {
3641
- this.done = !0, this.sizeBytes = e, this.change.markChanged();
3716
+ this.progress.done = e, e && (this.progress.lastError = void 0);
3642
3717
  }
3643
- abort(e) {
3644
- this.signalCtl.abort(new pe(e));
3718
+ incCounter(e, t) {
3719
+ this.change.attachWatcher(e), this.counter.inc(t);
3645
3720
  }
3646
- setError(e) {
3647
- this.error = e, this.change.markChanged();
3721
+ decCounter(e) {
3722
+ return this.counter.dec(e);
3723
+ }
3724
+ isComputableDone() {
3725
+ return this.counter.isZero();
3648
3726
  }
3649
- };
3650
- class pe extends Error {
3651
3727
  }
3652
- const Fe = /^blob\+local:\/\/download\/(?<path>.*)#(?<signature>.*)$/;
3653
- function Hr(s) {
3654
- return !!s.match(Fe);
3728
+ function ln(s, e) {
3729
+ let t, r;
3730
+ return Y(s) && (r = O.parse(s.data), t = hn(e, r.localPath, r.pathSignature)), {
3731
+ uploadData: r,
3732
+ progress: {
3733
+ done: !1,
3734
+ status: void 0,
3735
+ isUpload: Y(s),
3736
+ isUploadSignMatch: t,
3737
+ lastError: void 0
3738
+ }
3739
+ };
3655
3740
  }
3656
- function J(s, e) {
3657
- const t = s.match(Fe);
3658
- if (t === null) throw new Error(`Local handle is malformed: ${s}, matches: ${t}`);
3659
- const { path: n, signature: r } = t.groups;
3660
- return e.verify(n, r, `Signature verification failed for: ${s}`), n;
3741
+ function cn(s) {
3742
+ return s.done, s.isUpload, s.isUploadSignMatch, s.lastError, s.status && (s.status.progress, s.status.bytesProcessed, s.status.bytesTotal), s;
3661
3743
  }
3662
- function jr(s, e) {
3663
- return `blob+local://download/${s}#${e.sign(s)}`;
3744
+ function dn(s) {
3745
+ return "blob" in s.fields ? s.fields.blob !== void 0 : s.fields.incarnation !== void 0;
3664
3746
  }
3665
- const Ee = /^blob\+remote:\/\/download\/(?<content>(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*))#(?<signature>.*)$/;
3666
- function Gr(s) {
3667
- return !!s.match(Ee);
3747
+ function Y(s) {
3748
+ return s.type.name.startsWith("BlobUpload");
3668
3749
  }
3669
- function Vr(s, e) {
3670
- const t = s.match(Ee);
3671
- if (t === null) throw new Error(`Remote handle is malformed: ${s}, matches: ${t}`);
3672
- const { content: n, resourceType: r, resourceVersion: o, resourceId: a, signature: i } = t.groups;
3673
- return e.verify(n, i, `Signature verification failed for ${s}`), {
3674
- id: Y(BigInt(a)),
3675
- type: { name: r, version: o }
3750
+ function hn(s, e, t) {
3751
+ try {
3752
+ return s.verify(e, t), !0;
3753
+ } catch {
3754
+ return !1;
3755
+ }
3756
+ }
3757
+ function un(s) {
3758
+ return {
3759
+ progress: s.progress ?? 0,
3760
+ bytesProcessed: Number(s.bytesProcessed),
3761
+ bytesTotal: Number(s.bytesTotal)
3676
3762
  };
3677
3763
  }
3678
- function qr(s, e) {
3679
- const t = `${s.type.name}/${s.type.version}/${BigInt(s.id)}`;
3680
- return `blob+remote://download/${t}#${e.sign(t)}`;
3764
+ function ge(s) {
3765
+ return s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED" || s.code == "ALREADY_EXISTS");
3681
3766
  }
3682
- const F = T.object({
3683
- /** Local file path, to take data for upload */
3684
- localPath: T.string(),
3685
- /** Path signature, to check this data was generated by us */
3686
- pathSignature: T.string(),
3687
- /** File size in bytes */
3688
- sizeBytes: T.string(),
3689
- /** Modification time unix timestamp in seconds */
3690
- modificationTime: T.string()
3691
- }), We = T.object({
3692
- /** Pl storage id */
3693
- storageId: T.string(),
3694
- /** Path inside storage */
3695
- path: T.string()
3696
- }), Gn = T.union([
3697
- F,
3698
- We
3699
- ]), Jr = se({
3700
- data: F,
3701
- fields: {
3702
- blob: !1
3703
- }
3704
- }), Zr = se({
3705
- fields: {
3706
- incarnation: !1
3707
- }
3708
- });
3709
- function Qr(s, e) {
3710
- const t = ie(s) ? e.accessor(s).node() : it(s) ? s.node() : s;
3711
- return t.resourceType.name.startsWith("BlobUpload") ? Q(t, Jr) : Q(t, Zr);
3767
+ function He(s) {
3768
+ return s instanceof Ne || s instanceof De || s instanceof Be;
3769
+ }
3770
+ function pn(s, e) {
3771
+ const t = le(s) ? e.accessor(s).node() : ot(s) ? s.node() : s;
3772
+ return t.resourceType.name.startsWith("BlobUpload") ? X(t, Qr) : X(t, Xr);
3712
3773
  }
3713
- class Vn {
3714
- constructor(e, t, n, r, o = {
3774
+ class oo {
3775
+ constructor(e, t, r, n, o = {
3715
3776
  nConcurrentPartUploads: 10,
3716
3777
  nConcurrentGetProgresses: 10,
3717
3778
  pollingInterval: 1e3,
@@ -3726,34 +3787,31 @@ class Vn {
3726
3787
  d(this, "keepRunning", !1);
3727
3788
  /** Actual state of main loop. */
3728
3789
  d(this, "currentLoop");
3729
- this.logger = e, this.signer = t, this.clientBlob = n, this.clientProgress = r, this.opts = o, this.uploadQueue = new ee(this.logger, 1, {
3790
+ this.logger = e, this.signer = t, this.clientBlob = r, this.clientProgress = n, this.opts = o, this.uploadQueue = new re(this.logger, 1, {
3730
3791
  type: "exponentialWithMaxDelayBackoff",
3731
3792
  initialDelay: 20,
3732
3793
  maxDelay: 15e3,
3733
3794
  // 15 seconds
3734
3795
  backoffMultiplier: 1.5,
3735
3796
  jitter: 0.5
3736
- }), this.hooks = new Pe(
3797
+ }), this.hooks = new Re(
3737
3798
  () => this.startUpdating(),
3738
3799
  () => this.stopUpdating(),
3739
3800
  { stopDebounce: o.stopPollingDelay },
3740
- (a, i) => this.scheduleOnNextState(a, i)
3801
+ (l, i) => this.scheduleOnNextState(l, i)
3741
3802
  );
3742
3803
  }
3743
3804
  getProgressId(e, t) {
3744
- if (t == null) return b.make((a) => this.getProgressId(e, a));
3745
- const n = ie(e) ? Qr(e, t) : e, r = L();
3746
- t.attacheHooks(this.hooks), t.addOnDestroy(() => this.release(n.id, r));
3747
- const o = this.getProgressIdNoCtx(t.watcher, n, r);
3748
- return ge(o) || t.markUnstable(
3749
- `upload/index progress was got, but it's not stable: ${JSON.stringify(o)}`
3750
- ), o;
3751
- }
3752
- getProgressIdNoCtx(e, t, n) {
3753
- const r = "blob" in t.fields ? t.fields.blob !== void 0 : t.fields.incarnation !== void 0, o = this.idToProgress.get(t.id);
3754
- if (o != null)
3755
- return o.attach(e, n), o.mustGetProgress(r);
3756
- const a = new Xr(
3805
+ if (t == null) return b.make((l) => this.getProgressId(e, l));
3806
+ const r = le(e) ? pn(e, t) : e, n = L();
3807
+ return t.attacheHooks(this.hooks), t.addOnDestroy(() => this.release(r.id, n)), this.getProgressIdNoCtx(t.watcher, r, n);
3808
+ }
3809
+ getProgressIdNoCtx(e, t, r) {
3810
+ fn("getProgressId", t.type);
3811
+ const n = this.idToProgress.get(t.id);
3812
+ if (n != null)
3813
+ return n.setDoneIfOutputSet(t), n.getProgress(e, r);
3814
+ const o = new an(
3757
3815
  this.logger,
3758
3816
  this.clientBlob,
3759
3817
  this.clientProgress,
@@ -3761,16 +3819,16 @@ class Vn {
3761
3819
  this.signer,
3762
3820
  t
3763
3821
  );
3764
- return this.idToProgress.set(t.id, a), a.attach(e, n), a.progress.isUpload && a.progress.isUploadSignMatch && this.uploadQueue.push({
3765
- fn: () => a.uploadBlobTask(),
3766
- recoverableErrorPredicate: (i) => !Ae(i)
3767
- }), a.mustGetProgress(r);
3822
+ return this.idToProgress.set(t.id, o), o.shouldScheduleUpload() && this.uploadQueue.push({
3823
+ fn: () => o.uploadBlobTask(),
3824
+ recoverableErrorPredicate: (l) => !He(l)
3825
+ }), o.setDoneIfOutputSet(t), o.getProgress(e, r);
3768
3826
  }
3769
3827
  /** Decrement counters for the file and remove an uploading if counter == 0. */
3770
3828
  async release(e, t) {
3771
- const n = this.idToProgress.get(e);
3772
- if (n === void 0) return;
3773
- n.decCounter(t) && this.idToProgress.delete(e);
3829
+ const r = this.idToProgress.get(e);
3830
+ if (r === void 0) return;
3831
+ r.decCounter(t) && this.idToProgress.delete(e);
3774
3832
  }
3775
3833
  /** Must be called when the driver is closing. */
3776
3834
  async releaseAll() {
@@ -3792,149 +3850,34 @@ class Vn {
3792
3850
  const e = this.scheduledOnNextState;
3793
3851
  this.scheduledOnNextState = [];
3794
3852
  try {
3795
- await te(
3853
+ await ne(
3796
3854
  this.opts.nConcurrentGetProgresses,
3797
3855
  this.getAllNotDoneProgresses().map((t) => async () => await t.updateStatus())
3798
3856
  ), e.forEach((t) => t.resolve());
3799
3857
  } catch (t) {
3800
- console.error(t), e.forEach((n) => n.reject(t));
3858
+ console.error(t), e.forEach((r) => r.reject(t));
3801
3859
  }
3802
3860
  if (!this.keepRunning) break;
3803
- await oe.wait(this.opts.pollingInterval);
3861
+ await Se.wait(this.opts.pollingInterval);
3804
3862
  }
3805
3863
  this.currentLoop = void 0;
3806
3864
  }
3807
3865
  getAllNotDoneProgresses() {
3808
- return Array.from(this.idToProgress.entries()).filter(([e, t]) => !ge(t.progress)).map(([e, t]) => t);
3809
- }
3810
- }
3811
- class Xr {
3812
- constructor(e, t, n, r, o, a) {
3813
- d(this, "change", new N());
3814
- d(this, "counter", new v());
3815
- d(this, "progress");
3816
- /** If this is upload progress this field will be defined */
3817
- d(this, "uploadData");
3818
- d(this, "uploadingTerminallyFailed");
3819
- this.logger = e, this.clientBlob = t, this.clientProgress = n, this.nConcurrentPartsUpload = r, this.res = a;
3820
- const i = a.type.name.startsWith("BlobUpload");
3821
- let c;
3822
- i && (this.uploadData = F.parse(a.data), c = Kr(
3823
- o,
3824
- this.uploadData.localPath,
3825
- this.uploadData.pathSignature
3826
- )), this.progress = {
3827
- done: !1,
3828
- status: void 0,
3829
- isUpload: i,
3830
- isUploadSignMatch: c,
3831
- lastError: void 0
3832
- };
3833
- }
3834
- mustGetProgress(e) {
3835
- const t = {
3836
- done: this.progress.done,
3837
- isUpload: this.progress.isUpload,
3838
- isUploadSignMatch: this.progress.isUploadSignMatch,
3839
- lastError: this.progress.lastError
3840
- };
3841
- if (this.progress.status && (t.status = {
3842
- progress: this.progress.status.progress,
3843
- bytesProcessed: this.progress.status.bytesProcessed,
3844
- bytesTotal: this.progress.status.bytesTotal
3845
- }), e)
3846
- return this.setDone(e), t;
3847
- if (this.uploadingTerminallyFailed)
3848
- throw this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`), new Error(this.progress.lastError);
3849
- return t;
3850
- }
3851
- attach(e, t) {
3852
- this.change.attachWatcher(e), this.counter.inc(t);
3853
- }
3854
- decCounter(e) {
3855
- return this.counter.dec(e);
3856
- }
3857
- /** Uploads a blob if it's not BlobIndex. */
3858
- async uploadBlobTask() {
3859
- try {
3860
- await this.uploadBlob();
3861
- } catch (e) {
3862
- if (this.setLastError(e), fe(e)) {
3863
- this.logger.warn(`resource was deleted while uploading a blob: ${e}`), this.change.markChanged(), this.setDone(!0);
3864
- return;
3865
- }
3866
- throw this.logger.error(`error while uploading a blob: ${e}`), this.change.markChanged(), Ae(e) && this.terminateWithError(e), e;
3867
- }
3868
- }
3869
- /** Uploads a blob using client. */
3870
- async uploadBlob() {
3871
- if (this.counter.isZero()) return;
3872
- const e = await this.clientBlob.initUpload(this.res);
3873
- this.logger.info(`start to upload blob ${this.res.id}, parts count: ${e.length}`);
3874
- const t = (n) => async () => {
3875
- this.counter.isZero() || await this.clientBlob.partUpload(
3876
- this.res,
3877
- this.uploadData.localPath,
3878
- n,
3879
- e.length,
3880
- BigInt(this.uploadData.modificationTime)
3881
- );
3882
- };
3883
- await te(this.nConcurrentPartsUpload, e.map(t)), !this.counter.isZero() && (await this.clientBlob.finalizeUpload(this.res), this.logger.info(`uploading of resource ${this.res.id} finished.`), this.change.markChanged());
3884
- }
3885
- terminateWithError(e) {
3886
- this.progress.lastError = String(e), this.progress.done = !1, this.uploadingTerminallyFailed = !0;
3887
- }
3888
- setLastError(e) {
3889
- this.progress.lastError = String(e);
3890
- }
3891
- setDone(e) {
3892
- this.progress.done = e, e && (this.progress.lastError = void 0);
3893
- }
3894
- async updateStatus() {
3895
- try {
3896
- const e = await this.clientProgress.getStatus(this.res), t = this.progress.status;
3897
- this.progress.status = Yr(e), this.setDone(e.done), (e.done || e.progress != (t == null ? void 0 : t.progress)) && this.change.markChanged();
3898
- } catch (e) {
3899
- if (this.setLastError(e), e.name == "RpcError" && e.code == "DEADLINE_EXCEEDED") {
3900
- this.logger.warn("deadline exceeded while getting a status of BlobImport");
3901
- return;
3902
- }
3903
- if (fe(e)) {
3904
- this.logger.warn(
3905
- `resource was not found while updating a status of BlobImport: ${e}, ${be(this.res)}`
3906
- ), this.change.markChanged(), this.setDone(!0);
3907
- return;
3908
- }
3909
- this.logger.error(`error while updating a status of BlobImport: ${e}`), this.change.markChanged(), this.terminateWithError(e);
3910
- }
3911
- }
3912
- }
3913
- function ge(s) {
3914
- return s.done && s.status !== void 0 && s.status !== null && s.status.progress >= 1;
3915
- }
3916
- function Yr(s) {
3917
- return {
3918
- progress: s.progress ?? 0,
3919
- bytesProcessed: Number(s.bytesProcessed),
3920
- bytesTotal: Number(s.bytesTotal)
3921
- };
3922
- }
3923
- function Kr(s, e, t) {
3924
- try {
3925
- return s.verify(e, t), !0;
3926
- } catch {
3927
- return !1;
3866
+ return Array.from(this.idToProgress.entries()).filter(([e, t]) => !gn(t.progress)).map(([e, t]) => t);
3928
3867
  }
3929
3868
  }
3930
- function Ae(s) {
3931
- return s instanceof Ie || s instanceof Re || s instanceof Se;
3869
+ function gn(s) {
3870
+ var e;
3871
+ return s.done && (((e = s.status) == null ? void 0 : e.progress) ?? 0) >= 1;
3932
3872
  }
3933
- function fe(s) {
3934
- return s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED" || s.code == "ALREADY_EXISTS");
3873
+ function fn(s, e) {
3874
+ if (!e.name.startsWith("BlobUpload") && !e.name.startsWith("BlobIndex"))
3875
+ throw new de(
3876
+ `${s}: wrong resource type: ${e.name}, expected: a resource of either type 'BlobUpload' or 'BlobIndex'.`
3877
+ );
3935
3878
  }
3936
- class qn {
3937
- constructor(e, t, n = {
3879
+ class so {
3880
+ constructor(e, t, r = {
3938
3881
  nConcurrentGetLogs: 10,
3939
3882
  pollingInterval: 1e3,
3940
3883
  stopPollingDelay: 1e3
@@ -3950,104 +3893,111 @@ class qn {
3950
3893
  d(this, "keepRunning", !1);
3951
3894
  /** Actual state of main loop. */
3952
3895
  d(this, "currentLoop");
3953
- this.logger = e, this.clientLogs = t, this.opts = n, this.hooks = new Pe(
3896
+ this.logger = e, this.clientLogs = t, this.opts = r, this.hooks = new Re(
3954
3897
  () => this.startUpdating(),
3955
3898
  () => this.stopUpdating(),
3956
- { stopDebounce: n.stopPollingDelay },
3957
- (r, o) => this.scheduleOnNextState(r, o)
3899
+ { stopDebounce: r.stopPollingDelay },
3900
+ (n, o) => this.scheduleOnNextState(n, o)
3958
3901
  );
3959
3902
  }
3960
- getLastLogs(e, t, n) {
3961
- if (n == null) return b.make((i) => this.getLastLogs(e, t, i));
3962
- const r = R(e, n), o = L();
3963
- n.attacheHooks(this.hooks), n.addOnDestroy(() => this.releaseLastLogs(r.id, o));
3964
- const a = this.getLastLogsNoCtx(n.watcher, r, t, o);
3965
- return n.markUnstable(
3903
+ getLastLogs(e, t, r) {
3904
+ if (r == null) return b.make((i) => this.getLastLogs(e, t, i));
3905
+ const n = I(e, r), o = L();
3906
+ r.attacheHooks(this.hooks), r.addOnDestroy(() => this.releaseLastLogs(n.id, o));
3907
+ const l = this.getLastLogsNoCtx(r.watcher, n, t, o);
3908
+ return r.markUnstable(
3966
3909
  "The logs are from stream, so we consider them unstable. Final values will be got from blobs."
3967
- ), a;
3910
+ ), l;
3968
3911
  }
3969
- getLastLogsNoCtx(e, t, n, r) {
3912
+ getLastLogsNoCtx(e, t, r, n) {
3913
+ q("getLastLogs", t.type);
3970
3914
  let o = this.idToLastLines.get(t.id);
3971
3915
  if (o == null) {
3972
- const i = new me(this.logger, this.clientLogs, t, n);
3916
+ const i = new fe(this.logger, this.clientLogs, t, r);
3973
3917
  this.idToLastLines.set(t.id, i), o = i;
3974
3918
  }
3975
- o.attach(e, r);
3976
- const a = o.getLog();
3977
- if (a.error != null) throw a.error;
3978
- return a.log;
3919
+ o.attach(e, n);
3920
+ const l = o.getLog();
3921
+ if (l.error != null) throw l.error;
3922
+ return l.log;
3979
3923
  }
3980
- getProgressLog(e, t, n) {
3981
- if (n == null)
3924
+ getProgressLog(e, t, r) {
3925
+ if (r == null)
3982
3926
  return b.make((i) => this.getProgressLog(e, t, i));
3983
- const r = R(e, n), o = L();
3984
- n.attacheHooks(this.hooks), n.addOnDestroy(() => this.releaseProgressLog(r.id, o));
3985
- const a = this.getProgressLogNoCtx(n.watcher, r, t, o);
3986
- return n.markUnstable(
3927
+ const n = I(e, r), o = L();
3928
+ r.attacheHooks(this.hooks), r.addOnDestroy(() => this.releaseProgressLog(n.id, o));
3929
+ const l = this.getProgressLogNoCtx(r.watcher, n, t, o);
3930
+ return r.markUnstable(
3987
3931
  "The progress log is from the stream, so we consider it unstable. Final value will be got from blobs."
3988
- ), a;
3932
+ ), l;
3989
3933
  }
3990
- getProgressLogNoCtx(e, t, n, r) {
3934
+ getProgressLogNoCtx(e, t, r, n) {
3935
+ q("getProgressLog", t.type);
3991
3936
  let o = this.idToProgressLog.get(t.id);
3992
3937
  if (o == null) {
3993
- const i = new me(this.logger, this.clientLogs, t, 1, n);
3938
+ const i = new fe(this.logger, this.clientLogs, t, 1, r);
3994
3939
  this.idToProgressLog.set(t.id, i), o = i;
3995
3940
  }
3996
- o.attach(e, r);
3997
- const a = o.getLog();
3998
- if (a.error) throw a.error;
3999
- return a.log;
3941
+ o.attach(e, n);
3942
+ const l = o.getLog();
3943
+ if (l.error) throw l.error;
3944
+ return l.log;
4000
3945
  }
4001
3946
  getLogHandle(e, t) {
4002
3947
  if (t == null) return b.make((o) => this.getLogHandle(e, o));
4003
- const n = R(e, t), r = this.getLogHandleNoCtx(n);
4004
- return t.markUnstable(`live_log:${Ze(n.id)}`), r;
3948
+ const r = I(e, t), n = this.getLogHandleNoCtx(r);
3949
+ return t.markUnstable(`live_log:${Xe(r.id)}`), n;
4005
3950
  }
4006
3951
  getLogHandleNoCtx(e) {
4007
- return _e(!0, e);
3952
+ return q("getLogHandle", e.type), xe(!0, e);
4008
3953
  }
4009
- async lastLines(e, t, n, r) {
3954
+ async lastLines(e, t, r, n) {
4010
3955
  return await this.tryWithNotFound(
4011
3956
  e,
4012
3957
  () => this.clientLogs.lastLines(
4013
- _(e),
3958
+ C(e),
4014
3959
  t,
4015
- BigInt(n ?? 0),
4016
- r
3960
+ BigInt(r ?? 0),
3961
+ n
4017
3962
  )
4018
3963
  );
4019
3964
  }
4020
- async readText(e, t, n, r) {
3965
+ async readText(e, t, r, n) {
4021
3966
  return await this.tryWithNotFound(
4022
3967
  e,
4023
- () => this.clientLogs.readText(_(e), t, BigInt(n ?? 0), r)
3968
+ () => this.clientLogs.readText(
3969
+ C(e),
3970
+ t,
3971
+ BigInt(r ?? 0),
3972
+ n
3973
+ )
4024
3974
  );
4025
3975
  }
4026
3976
  async tryWithNotFound(e, t) {
4027
- if (!C(e))
3977
+ if (!_(e))
4028
3978
  throw new Error(`Not live log handle was passed to live log driver, handle: ${e}`);
4029
3979
  try {
4030
- const n = await t();
3980
+ const r = await t();
4031
3981
  return {
4032
3982
  live: !0,
4033
3983
  shouldUpdateHandle: !1,
4034
- data: n.data,
4035
- size: Number(n.size),
4036
- newOffset: Number(n.newOffset)
3984
+ data: r.data,
3985
+ size: Number(r.size),
3986
+ newOffset: Number(r.newOffset)
4037
3987
  };
4038
- } catch (n) {
4039
- if (n.name == "RpcError" && n.code == "NOT_FOUND")
3988
+ } catch (r) {
3989
+ if (r.name == "RpcError" && r.code == "NOT_FOUND")
4040
3990
  return { shouldUpdateHandle: !0 };
4041
- throw n;
3991
+ throw r;
4042
3992
  }
4043
3993
  }
4044
3994
  async releaseLastLogs(e, t) {
4045
- var r;
4046
- ((r = this.idToLastLines.get(e)) == null ? void 0 : r.release(t)) && this.idToLastLines.delete(e);
3995
+ var n;
3996
+ ((n = this.idToLastLines.get(e)) == null ? void 0 : n.release(t)) && this.idToLastLines.delete(e);
4047
3997
  }
4048
3998
  async releaseProgressLog(e, t) {
4049
- var r;
4050
- ((r = this.idToProgressLog.get(e)) == null ? void 0 : r.release(t)) && this.idToProgressLog.delete(e);
3999
+ var n;
4000
+ ((n = this.idToProgressLog.get(e)) == null ? void 0 : n.release(t)) && this.idToProgressLog.delete(e);
4051
4001
  }
4052
4002
  async releaseAll() {
4053
4003
  }
@@ -4068,15 +4018,15 @@ class qn {
4068
4018
  this.scheduledOnNextState = [];
4069
4019
  try {
4070
4020
  const t = this.getAllLogs();
4071
- await te(
4021
+ await ne(
4072
4022
  this.opts.nConcurrentGetLogs,
4073
- t.map((n) => async () => await n.update())
4074
- ), e.forEach((n) => n.resolve());
4023
+ t.map((r) => async () => await r.update())
4024
+ ), e.forEach((r) => r.resolve());
4075
4025
  } catch (t) {
4076
- console.error(t), e.forEach((n) => n.reject(t));
4026
+ console.error(t), e.forEach((r) => r.reject(t));
4077
4027
  }
4078
4028
  if (!this.keepRunning) break;
4079
- await oe.wait(this.opts.pollingInterval);
4029
+ await Se.wait(this.opts.pollingInterval);
4080
4030
  }
4081
4031
  this.currentLoop = void 0;
4082
4032
  }
@@ -4084,13 +4034,13 @@ class qn {
4084
4034
  return Array.from(this.idToLastLines.entries()).concat(Array.from(this.idToProgressLog.entries())).map(([e, t]) => t);
4085
4035
  }
4086
4036
  }
4087
- class me {
4088
- constructor(e, t, n, r, o) {
4037
+ class fe {
4038
+ constructor(e, t, r, n, o) {
4089
4039
  d(this, "logs");
4090
4040
  d(this, "error");
4091
- d(this, "change", new N());
4092
- d(this, "counter", new v());
4093
- this.logger = e, this.clientLogs = t, this.rInfo = n, this.lines = r, this.patternToSearch = o;
4041
+ d(this, "change", new v());
4042
+ d(this, "counter", new B());
4043
+ this.logger = e, this.clientLogs = t, this.rInfo = r, this.lines = n, this.patternToSearch = o;
4094
4044
  }
4095
4045
  getLog() {
4096
4046
  return {
@@ -4120,13 +4070,83 @@ class me {
4120
4070
  return;
4121
4071
  }
4122
4072
  throw this.logger.error(
4123
- `Stream log lines for ${be(this.rInfo.id)} failed, reason: ${e}`
4073
+ `Stream log lines for ${ye(this.rInfo.id)} failed, reason: ${e}`
4124
4074
  ), e;
4125
4075
  }
4126
4076
  }
4127
4077
  }
4128
- class Jn {
4129
- constructor(e, t, n, r = {
4078
+ function q(s, e) {
4079
+ if (!e.name.startsWith("StreamWorkdir"))
4080
+ throw new de(
4081
+ `${s}: wrong resource type: ${e.name}, expected: a resource of type 'StreamWorkdir'.`
4082
+ );
4083
+ }
4084
+ class io {
4085
+ constructor(e, t, r) {
4086
+ this.logger = e, this.logsStreamDriver = t, this.downloadDriver = r;
4087
+ }
4088
+ getLastLogs(e, t, r) {
4089
+ if (r === void 0) return b.make((o) => this.getLastLogs(e, t, o));
4090
+ const n = Z(r, e);
4091
+ if (n === void 0) {
4092
+ r.markUnstable("no stream in stream manager");
4093
+ return;
4094
+ }
4095
+ if (J(n)) return this.downloadDriver.getLastLogs(n, t, r);
4096
+ try {
4097
+ return this.logsStreamDriver.getLastLogs(n, t, r);
4098
+ } catch (o) {
4099
+ if (o.name == "RpcError" && o.code == "NOT_FOUND") {
4100
+ r.markUnstable(`NOT_FOUND in logs stream driver while getting last logs: ${o}`);
4101
+ return;
4102
+ }
4103
+ throw o;
4104
+ }
4105
+ }
4106
+ getProgressLog(e, t, r) {
4107
+ if (r === void 0)
4108
+ return b.make((o) => this.getProgressLog(e, t, o));
4109
+ const n = Z(r, e);
4110
+ if (n === void 0) {
4111
+ r.markUnstable("no stream in stream manager");
4112
+ return;
4113
+ }
4114
+ if (J(n)) return this.downloadDriver.getProgressLog(n, t, r);
4115
+ try {
4116
+ return this.logsStreamDriver.getProgressLog(n, t, r);
4117
+ } catch (o) {
4118
+ if (o.name == "RpcError" && o.code == "NOT_FOUND") {
4119
+ r.markUnstable(`NOT_FOUND in logs stream driver while getting a progress log: ${o}`);
4120
+ return;
4121
+ }
4122
+ throw o;
4123
+ }
4124
+ }
4125
+ getLogHandle(e, t) {
4126
+ if (t === void 0) return b.make((n) => this.getLogHandle(e, n));
4127
+ const r = Z(t, e);
4128
+ if (r === void 0) {
4129
+ t.markUnstable("no stream in stream manager");
4130
+ return;
4131
+ }
4132
+ return J(r) ? this.downloadDriver.getLogHandle(r, t) : this.logsStreamDriver.getLogHandle(r, t);
4133
+ }
4134
+ async lastLines(e, t, r, n) {
4135
+ return _(e) ? await this.logsStreamDriver.lastLines(e, t, r, n) : await this.downloadDriver.lastLines(e, t, r, n);
4136
+ }
4137
+ async readText(e, t, r, n) {
4138
+ return _(e) ? await this.logsStreamDriver.readText(e, t, r, n) : await this.downloadDriver.readText(e, t, r, n);
4139
+ }
4140
+ }
4141
+ function J(s) {
4142
+ return !s.type.name.startsWith("StreamWorkdir");
4143
+ }
4144
+ function Z(s, e) {
4145
+ var t;
4146
+ return (t = s.accessor(e).node().traverse("stream")) == null ? void 0 : t.resourceInfo;
4147
+ }
4148
+ class ao {
4149
+ constructor(e, t, r, n = {
4130
4150
  cacheSoftSizeBytes: 50 * 1024 * 1024,
4131
4151
  withGunzip: !0,
4132
4152
  nConcurrentDownloads: 50
@@ -4137,212 +4157,211 @@ class Jn {
4137
4157
  /** Writes and removes files to a hard drive and holds a counter for every
4138
4158
  * file that should be kept. */
4139
4159
  d(this, "cache");
4140
- this.logger = e, this.saveDir = n, this.opts = r, this.downloadQueue = new ee(this.logger, this.opts.nConcurrentDownloads), this.cache = new $e(this.opts.cacheSoftSizeBytes), this.downloadHelper = new Ne(t);
4160
+ this.logger = e, this.saveDir = r, this.opts = n, this.downloadQueue = new re(this.logger, this.opts.nConcurrentDownloads), this.cache = new Fe(this.opts.cacheSoftSizeBytes), this.downloadHelper = new ve(t);
4141
4161
  }
4142
4162
  getPath(e, t) {
4143
4163
  if (t === void 0) return b.make((o) => this.getPath(e, o));
4144
- const n = L();
4145
- t.addOnDestroy(() => this.releasePath(e, n));
4146
- const r = this.getPathNoCtx(e, t.watcher, n);
4147
- return (r == null ? void 0 : r.path) === void 0 && t.markUnstable(
4148
- `a path to the downloaded and untared archive might be undefined. The current result: ${r}`
4149
- ), r;
4150
- }
4151
- getPathNoCtx(e, t, n) {
4152
- const r = e.toString(), o = this.urlToDownload.get(r);
4164
+ const r = L();
4165
+ t.addOnDestroy(() => this.releasePath(e, r));
4166
+ const n = this.getPathNoCtx(e, t.watcher, r);
4167
+ return (n == null ? void 0 : n.path) === void 0 && t.markUnstable(
4168
+ `a path to the downloaded and untared archive might be undefined. The current result: ${n}`
4169
+ ), n;
4170
+ }
4171
+ getPathNoCtx(e, t, r) {
4172
+ const n = e.toString(), o = this.urlToDownload.get(n);
4153
4173
  if (o != null)
4154
- return o.attach(t, n), o.getPath();
4155
- const a = this.setNewTask(t, e, n);
4174
+ return o.attach(t, r), o.getPath();
4175
+ const l = this.setNewTask(t, e, r);
4156
4176
  return this.downloadQueue.push({
4157
- fn: async () => this.downloadUrl(a, n),
4177
+ fn: async () => this.downloadUrl(l, r),
4158
4178
  recoverableErrorPredicate: (i) => !0
4159
- }), a.getPath();
4179
+ }), l.getPath();
4160
4180
  }
4161
4181
  /** Downloads and extracts a tar archive if it wasn't downloaded yet. */
4162
4182
  async downloadUrl(e, t) {
4163
- var n;
4164
- await e.download(this.downloadHelper, this.opts.withGunzip), ((n = e.getPath()) == null ? void 0 : n.path) != null && this.cache.addCache(e, t);
4183
+ var r;
4184
+ await e.download(this.downloadHelper, this.opts.withGunzip), ((r = e.getPath()) == null ? void 0 : r.path) != null && this.cache.addCache(e, t);
4165
4185
  }
4166
4186
  /** Removes a directory and aborts a downloading task when all callers
4167
4187
  * are not interested in it. */
4168
4188
  async releasePath(e, t) {
4169
- const n = e.toString(), r = this.urlToDownload.get(n);
4170
- if (r != null)
4171
- if (this.cache.existsFile(r.path)) {
4172
- const o = this.cache.removeFile(r.path, t);
4189
+ const r = e.toString(), n = this.urlToDownload.get(r);
4190
+ if (n != null)
4191
+ if (this.cache.existsFile(n.path)) {
4192
+ const o = this.cache.removeFile(n.path, t);
4173
4193
  await Promise.all(
4174
- o.map(async (a) => {
4175
- await X(a.path), this.cache.removeCache(a), this.removeTask(
4176
- a,
4177
- `the task ${JSON.stringify(a)} was removedfrom cache along with ${JSON.stringify(o)}`
4194
+ o.map(async (l) => {
4195
+ await K(l.path), this.cache.removeCache(l), this.removeTask(
4196
+ l,
4197
+ `the task ${JSON.stringify(l)} was removedfrom cache along with ${JSON.stringify(o)}`
4178
4198
  );
4179
4199
  })
4180
4200
  );
4181
4201
  } else
4182
- r.counter.dec(t) && this.removeTask(r, `the task ${JSON.stringify(r)} was removed from cache`);
4202
+ n.counter.dec(t) && this.removeTask(n, `the task ${JSON.stringify(n)} was removed from cache`);
4183
4203
  }
4184
4204
  /** Removes all files from a hard drive. */
4185
4205
  async releaseAll() {
4186
4206
  this.downloadQueue.stop(), await Promise.all(
4187
4207
  Array.from(this.urlToDownload.entries()).map(async ([e, t]) => {
4188
- await X(t.path), this.cache.removeCache(t), this.removeTask(t, `the task ${t} was released when the driver was closed`);
4208
+ await K(t.path), this.cache.removeCache(t), this.removeTask(t, `the task ${t} was released when the driver was closed`);
4189
4209
  })
4190
4210
  );
4191
4211
  }
4192
- setNewTask(e, t, n) {
4193
- const r = new en(this.getFilePath(t), t);
4194
- return r.attach(e, n), this.urlToDownload.set(t.toString(), r), r;
4212
+ setNewTask(e, t, r) {
4213
+ const n = new mn(this.logger, this.getFilePath(t), t);
4214
+ return n.attach(e, r), this.urlToDownload.set(t.toString(), n), n;
4195
4215
  }
4196
4216
  removeTask(e, t) {
4197
4217
  e.abort(t), e.change.markChanged(), this.urlToDownload.delete(e.url.toString());
4198
4218
  }
4199
4219
  getFilePath(e) {
4200
- const t = st("sha256").update(e.toString()).digest("hex");
4220
+ const t = it("sha256").update(e.toString()).digest("hex");
4201
4221
  return w.join(this.saveDir, t);
4202
4222
  }
4203
4223
  }
4204
- class en {
4205
- constructor(e, t) {
4206
- d(this, "counter", new v());
4207
- d(this, "change", new N());
4224
+ class mn {
4225
+ constructor(e, t, r) {
4226
+ d(this, "counter", new B());
4227
+ d(this, "change", new v());
4208
4228
  d(this, "signalCtl", new AbortController());
4209
4229
  d(this, "error");
4210
4230
  d(this, "done", !1);
4211
- d(this, "sizeBytes", 0);
4212
- this.path = e, this.url = t;
4231
+ d(this, "size", 0);
4232
+ this.logger = e, this.path = t, this.url = r;
4213
4233
  }
4214
4234
  attach(e, t) {
4215
4235
  this.counter.inc(t), this.done || this.change.attachWatcher(e);
4216
4236
  }
4217
4237
  async download(e, t) {
4218
4238
  try {
4219
- const n = await this.downloadAndUntar(
4220
- e,
4221
- t,
4222
- this.signalCtl.signal
4223
- );
4224
- this.setDone(n);
4225
- } catch (n) {
4226
- if (n instanceof we || n instanceof ae) {
4227
- this.setError(n), await X(this.path);
4239
+ const r = await this.downloadAndUntar(e, t, this.signalCtl.signal);
4240
+ this.setDone(r), this.change.markChanged();
4241
+ } catch (r) {
4242
+ if (r instanceof me || r instanceof ce) {
4243
+ this.setError(r), this.change.markChanged(), await K(this.path);
4228
4244
  return;
4229
4245
  }
4230
- throw n;
4246
+ throw r;
4231
4247
  }
4232
4248
  }
4233
- async downloadAndUntar(e, t, n) {
4234
- if (await Ye(this.path))
4235
- return await ze(this.path);
4236
- const r = await e.downloadRemoteFile(this.url.toString(), {}, n);
4237
- let o = r.content;
4249
+ async downloadAndUntar(e, t, r) {
4250
+ if (await Te(w.dirname(this.path)), await Le(this.path))
4251
+ return await je(this.path);
4252
+ const n = await e.download(this.url.toString(), {}, r);
4253
+ let o = n.content;
4238
4254
  if (t) {
4239
- const i = et.toWeb(at.createGunzip());
4240
- o = o.pipeThrough(i, { signal: n });
4255
+ const l = rt.toWeb(dt.createGunzip());
4256
+ o = o.pipeThrough(l, { signal: r });
4241
4257
  }
4242
- const a = ne.toWeb(lt.extract(this.path));
4243
- return await o.pipeTo(a, { signal: n }), r.size;
4258
+ return await Pe(this.logger, this.path, async (l) => {
4259
+ await m.mkdir(l);
4260
+ const i = ie.toWeb(ht.extract(l));
4261
+ await o.pipeTo(i, { signal: r });
4262
+ }), n.size;
4244
4263
  }
4245
4264
  getPath() {
4246
- if (this.done) return { path: K(this.path) };
4265
+ if (this.done) return { path: te(this.path) };
4247
4266
  if (this.error) return { error: this.error };
4248
4267
  }
4249
4268
  setDone(e) {
4250
- this.done = !0, this.sizeBytes = e, this.change.markChanged();
4251
- }
4252
- abort(e) {
4253
- this.signalCtl.abort(new we(e));
4269
+ this.done = !0, this.size = e;
4254
4270
  }
4255
4271
  setError(e) {
4256
- this.error = String(e), this.change.markChanged();
4272
+ this.error = String(e);
4273
+ }
4274
+ abort(e) {
4275
+ this.signalCtl.abort(new me(e));
4257
4276
  }
4258
4277
  }
4259
- class we extends Error {
4278
+ class me extends Error {
4260
4279
  }
4261
- async function ze(s) {
4280
+ async function je(s) {
4262
4281
  const e = await m.readdir(s, { withFileTypes: !0 });
4263
4282
  return (await Promise.all(
4264
- e.map(async (n) => {
4265
- const r = w.join(s, n.name);
4266
- return n.isDirectory() ? await ze(r) : (await m.stat(r)).size;
4283
+ e.map(async (r) => {
4284
+ const n = w.join(s, r.name);
4285
+ return r.isDirectory() ? await je(n) : (await m.stat(n)).size;
4267
4286
  })
4268
- )).reduce((n, r) => n + r, 0);
4287
+ )).reduce((r, n) => r + n, 0);
4269
4288
  }
4270
- async function X(s) {
4289
+ async function K(s) {
4271
4290
  await m.rm(s, { recursive: !0, force: !0 });
4272
4291
  }
4273
- function ye(s, e) {
4292
+ function we(s, e) {
4274
4293
  return `index://index/${encodeURIComponent(JSON.stringify({
4275
4294
  storageId: s,
4276
4295
  path: e
4277
4296
  }))}`;
4278
4297
  }
4279
- function tn(s, e, t, n) {
4280
- const r = {
4298
+ function wn(s, e, t, r) {
4299
+ const n = {
4281
4300
  localPath: s,
4282
4301
  pathSignature: e.sign(s),
4283
4302
  sizeBytes: String(t),
4284
- modificationTime: String(n)
4303
+ modificationTime: String(r)
4285
4304
  };
4286
- return `upload://upload/${encodeURIComponent(JSON.stringify(r))}`;
4305
+ return `upload://upload/${encodeURIComponent(JSON.stringify(n))}`;
4287
4306
  }
4288
- function rn(s) {
4307
+ function yn(s) {
4289
4308
  const e = new URL(s);
4290
- return F.parse(
4309
+ return O.parse(
4291
4310
  JSON.parse(decodeURIComponent(e.pathname.substring(1)))
4292
4311
  );
4293
4312
  }
4294
- function nn(s) {
4313
+ function bn(s) {
4295
4314
  const e = new URL(s);
4296
4315
  return We.parse(JSON.parse(decodeURIComponent(e.pathname.substring(1))));
4297
4316
  }
4298
- function on(s) {
4299
- if (cn(s))
4300
- return hn(s);
4301
- if (sn(s))
4302
- return ln(s);
4303
- Ke(s);
4317
+ function kn(s) {
4318
+ if (In(s))
4319
+ return Sn(s);
4320
+ if (Tn(s))
4321
+ return Pn(s);
4322
+ et(s);
4304
4323
  }
4305
- const xe = /^local:\/\/(?<name>.*)\/(?<path>.*)$/;
4306
- function sn(s) {
4307
- return xe.test(s);
4324
+ const Ge = /^local:\/\/(?<name>.*)\/(?<path>.*)$/;
4325
+ function Tn(s) {
4326
+ return Ge.test(s);
4308
4327
  }
4309
- function an(s, e) {
4328
+ function Ln(s, e) {
4310
4329
  return `local://${s}/${encodeURIComponent(e)}`;
4311
4330
  }
4312
- function ln(s) {
4313
- const e = s.match(xe);
4331
+ function Pn(s) {
4332
+ const e = s.match(Ge);
4314
4333
  if (e == null) throw new Error(`Local list handle wasn't parsed: ${s}`);
4315
- const { name: t, path: n } = e.groups;
4334
+ const { name: t, path: r } = e.groups;
4316
4335
  return {
4317
- rootPath: decodeURIComponent(n),
4336
+ rootPath: decodeURIComponent(r),
4318
4337
  name: t,
4319
4338
  isRemote: !1
4320
4339
  };
4321
4340
  }
4322
- const Me = /^remote:\/\/(?<name>.*)\/(?<resourceId>.*)$/;
4323
- function cn(s) {
4324
- return Me.test(s);
4341
+ const Ve = /^remote:\/\/(?<name>.*)\/(?<resourceId>.*)$/;
4342
+ function In(s) {
4343
+ return Ve.test(s);
4325
4344
  }
4326
- function dn(s, e) {
4345
+ function Rn(s, e) {
4327
4346
  return `remote://${s}/${BigInt(e)}`;
4328
4347
  }
4329
- function hn(s) {
4330
- const e = s.match(Me);
4348
+ function Sn(s) {
4349
+ const e = s.match(Ve);
4331
4350
  if (e == null) throw new Error(`Remote list handle wasn't parsed: ${s}`);
4332
- const { name: t, resourceId: n } = e.groups;
4351
+ const { name: t, resourceId: r } = e.groups;
4333
4352
  return {
4334
- id: Y(BigInt(n)),
4335
- type: un(t),
4353
+ id: ee(BigInt(r)),
4354
+ type: Un(t),
4336
4355
  name: t,
4337
4356
  isRemote: !0
4338
4357
  };
4339
4358
  }
4340
- function un(s) {
4359
+ function Un(s) {
4341
4360
  return { name: `LS/${s}`, version: "1" };
4342
4361
  }
4343
- async function pn() {
4344
- const s = ot.homedir();
4345
- if (Z.sep == "/")
4362
+ async function Nn() {
4363
+ const s = at.homedir();
4364
+ if (Q.sep == "/")
4346
4365
  return [
4347
4366
  {
4348
4367
  name: "local",
@@ -4351,15 +4370,15 @@ async function pn() {
4351
4370
  }
4352
4371
  ];
4353
4372
  {
4354
- const t = Z.parse(s).root.replaceAll(":\\", "");
4373
+ const t = Q.parse(s).root.replaceAll(":\\", "");
4355
4374
  try {
4356
- return (await dt.promisify(ht)("wmic logicaldisk get name")).stdout.split(`\r
4375
+ return (await pt.promisify(gt)("wmic logicaldisk get name")).stdout.split(`\r
4357
4376
  `).filter((o) => o.includes(":")).map((o) => o.trim().replaceAll(":", "")).map((o) => {
4358
- const a = o == t;
4377
+ const l = o == t;
4359
4378
  return {
4360
4379
  name: `local_disk_${o}`,
4361
4380
  root: `${o}:\\`,
4362
- initialPath: a ? s : `${o}:\\`
4381
+ initialPath: l ? s : `${o}:\\`
4363
4382
  };
4364
4383
  });
4365
4384
  } catch {
@@ -4373,14 +4392,14 @@ async function pn() {
4373
4392
  }
4374
4393
  }
4375
4394
  }
4376
- class He {
4377
- constructor(e, t, n, r, o, a, i) {
4378
- this.logger = e, this.lsClient = t, this.storageIdToResourceId = n, this.signer = r, this.virtualStoragesMap = o, this.localProjectionsMap = a, this.openFileDialogCallback = i;
4395
+ class qe {
4396
+ constructor(e, t, r, n, o, l, i) {
4397
+ this.logger = e, this.lsClient = t, this.storageIdToResourceId = r, this.signer = n, this.virtualStoragesMap = o, this.localProjectionsMap = l, this.openFileDialogCallback = i;
4379
4398
  }
4380
4399
  async getLocalFileContent(e, t) {
4381
- const n = await this.tryResolveLocalFileHandle(e);
4400
+ const r = await this.tryResolveLocalFileHandle(e);
4382
4401
  if (t) throw new Error("Range request not yet supported.");
4383
- return await m.readFile(n);
4402
+ return await m.readFile(r);
4384
4403
  }
4385
4404
  async getLocalFileSize(e) {
4386
4405
  const t = await this.tryResolveLocalFileHandle(e);
@@ -4389,7 +4408,7 @@ class He {
4389
4408
  async showOpenMultipleFilesDialog(e) {
4390
4409
  const t = await this.openFileDialogCallback(!0, e);
4391
4410
  return t === void 0 ? {} : {
4392
- files: await Promise.all(t.map((n) => this.getLocalFileHandle(n)))
4411
+ files: await Promise.all(t.map((r) => this.getLocalFileHandle(r)))
4393
4412
  };
4394
4413
  }
4395
4414
  async showOpenSingleFileDialog(e) {
@@ -4405,36 +4424,36 @@ class He {
4405
4424
  * @private
4406
4425
  */
4407
4426
  async tryResolveLocalFileHandle(e) {
4408
- if (ct(e)) {
4409
- const t = nn(e), n = this.localProjectionsMap.get(t.storageId);
4410
- if (!n)
4427
+ if (ut(e)) {
4428
+ const t = bn(e), r = this.localProjectionsMap.get(t.storageId);
4429
+ if (!r)
4411
4430
  throw new Error(`Storage ${t.storageId} is not mounted locally.`);
4412
- return w.join(n.localPath, t.path);
4431
+ return w.join(r.localPath, t.path);
4413
4432
  } else {
4414
- const t = rn(e);
4433
+ const t = yn(e);
4415
4434
  this.signer.verify(
4416
4435
  t.localPath,
4417
4436
  t.pathSignature,
4418
4437
  "Failed to validate local file handle signature."
4419
4438
  );
4420
- const n = t.localPath, r = await m.stat(n, { bigint: !0 });
4421
- if (String(r.mtimeMs / 1000n) !== t.modificationTime)
4439
+ const r = t.localPath, n = await m.stat(r, { bigint: !0 });
4440
+ if (String(n.mtimeMs / 1000n) !== t.modificationTime)
4422
4441
  throw new Error("File has changed since the handle was created.");
4423
- return n;
4442
+ return r;
4424
4443
  }
4425
4444
  }
4426
4445
  async getLocalFileHandle(e) {
4427
- B(e);
4428
- for (const n of this.localProjectionsMap.values())
4429
- if (e.startsWith(n.localPath)) {
4430
- const r = n.localPath === "" ? e : w.relative(n.localPath, e);
4431
- return ye(
4432
- n.storageId,
4433
- r
4446
+ N(e);
4447
+ for (const r of this.localProjectionsMap.values())
4448
+ if (e.startsWith(r.localPath)) {
4449
+ const n = r.localPath === "" ? e : w.relative(r.localPath, e);
4450
+ return we(
4451
+ r.storageId,
4452
+ n
4434
4453
  );
4435
4454
  }
4436
4455
  const t = await m.stat(e, { bigint: !0 });
4437
- return tn(
4456
+ return wn(
4438
4457
  e,
4439
4458
  this.signer,
4440
4459
  t.size,
@@ -4443,128 +4462,120 @@ class He {
4443
4462
  );
4444
4463
  }
4445
4464
  async getStorageList() {
4446
- const e = [...this.virtualStoragesMap.values()].map((r) => ({
4447
- name: r.name,
4448
- handle: an(r.name, r.root),
4449
- initialFullPath: r.initialPath
4450
- })), n = Object.entries(this.storageIdToResourceId).map(
4451
- ([r, o]) => ({
4452
- name: r,
4453
- handle: dn(r, o),
4465
+ const e = [...this.virtualStoragesMap.values()].map((n) => ({
4466
+ name: n.name,
4467
+ handle: Ln(n.name, n.root),
4468
+ initialFullPath: n.initialPath
4469
+ })), r = Object.entries(this.storageIdToResourceId).map(
4470
+ ([n, o]) => ({
4471
+ name: n,
4472
+ handle: Rn(n, o),
4454
4473
  initialFullPath: "",
4455
4474
  // we don't have any additional information from where to start browsing remote storages
4456
4475
  isInitialPathHome: !1
4457
4476
  })
4458
- ).filter((r) => r.name !== "root");
4459
- return [...e, ...n];
4477
+ ).filter((n) => n.name !== "root");
4478
+ return [...e, ...r];
4460
4479
  }
4461
4480
  async listFiles(e, t) {
4462
- const n = on(e);
4463
- if (n.isRemote)
4481
+ const r = kn(e);
4482
+ if (r.isRemote)
4464
4483
  return {
4465
- entries: (await this.lsClient.list(n, t)).items.map((o) => ({
4466
- type: o.isDir ? "dir" : "file",
4467
- name: o.name,
4468
- fullPath: o.fullName,
4469
- handle: ye(n.name, o.fullName)
4484
+ entries: (await this.lsClient.list(r, t)).items.map((i) => ({
4485
+ type: i.isDir ? "dir" : "file",
4486
+ name: i.name,
4487
+ fullPath: i.fullName,
4488
+ handle: we(r.name, i.fullName)
4470
4489
  }))
4471
4490
  };
4472
- {
4473
- w.sep === "/" && t === "" && (t = "/"), n.rootPath === "" && B(t);
4474
- const r = w.isAbsolute(t) ? t : w.join(n.rootPath, t), o = [];
4475
- for await (const a of await m.opendir(r)) {
4476
- if (!a.isFile() && !a.isDirectory()) continue;
4477
- const i = w.join(r, a.name);
4478
- o.push({
4479
- type: a.isFile() ? "file" : "dir",
4480
- name: a.name,
4481
- fullPath: i,
4482
- handle: await this.getLocalFileHandle(i)
4483
- });
4484
- }
4485
- return { entries: o };
4491
+ w.sep === "/" && t === "" && (t = "/"), r.rootPath === "" && N(t);
4492
+ const n = w.isAbsolute(t) ? t : w.join(r.rootPath, t), o = [];
4493
+ for await (const l of await m.opendir(n)) {
4494
+ if (!l.isFile() && !l.isDirectory()) continue;
4495
+ const i = w.join(n, l.name);
4496
+ o.push({
4497
+ type: l.isFile() ? "file" : "dir",
4498
+ name: l.name,
4499
+ fullPath: i,
4500
+ handle: await this.getLocalFileHandle(i)
4501
+ });
4486
4502
  }
4503
+ return { entries: o };
4487
4504
  }
4488
4505
  async fileToImportHandle(e) {
4489
4506
  throw new Error(
4490
4507
  "Not implemented. This method must be implemented and intercepted in desktop preload script."
4491
4508
  );
4492
4509
  }
4493
- static async init(e, t, n, r, o, a) {
4494
- const i = Cr(t, e);
4495
- a || (a = await pn());
4496
- for (const p of a) B(p.root);
4497
- for (const p of r) p.localPath !== "" && B(p.localPath);
4498
- const c = new Map(a.map((p) => [p.name, p])), l = new Map(r.map((p) => [p.storageId, p]));
4499
- if ((/* @__PURE__ */ new Set([...c.keys(), ...l.keys()])).size !== c.size + l.size)
4510
+ static async init(e, t, r, n, o, l) {
4511
+ const i = jr(t, e);
4512
+ l || (l = await Nn());
4513
+ for (const p of l) N(p.root);
4514
+ for (const p of n) p.localPath !== "" && N(p.localPath);
4515
+ const c = new Map(l.map((p) => [p.name, p])), a = new Map(n.map((p) => [p.storageId, p]));
4516
+ if ((/* @__PURE__ */ new Set([...c.keys(), ...a.keys()])).size !== c.size + a.size)
4500
4517
  throw new Error(
4501
4518
  "Intersection between local projection storage ids and virtual storages names detected."
4502
4519
  );
4503
- return new He(
4520
+ return new qe(
4504
4521
  e,
4505
4522
  i,
4506
- await gn(t),
4507
- n,
4523
+ await Dn(t),
4524
+ r,
4508
4525
  c,
4509
- l,
4526
+ a,
4510
4527
  o
4511
4528
  );
4512
4529
  }
4513
4530
  }
4514
- async function gn(s) {
4531
+ async function Dn(s) {
4515
4532
  return s.withReadTx("GetAvailableStorageIds", async (e) => {
4516
- const t = await e.getResourceByName("LSProvider"), n = await e.getResourceData(t, !0);
4517
- return fn(n);
4533
+ const t = await e.getResourceByName("LSProvider"), r = await e.getResourceData(t, !0);
4534
+ return Bn(r);
4518
4535
  });
4519
4536
  }
4520
- function fn(s) {
4537
+ function Bn(s) {
4521
4538
  return Object.fromEntries(
4522
- s.fields.filter((e) => e.type == "Dynamic" && Qe(e.value)).map((e) => [e.name.substring(8), e.value])
4539
+ s.fields.filter((e) => e.type == "Dynamic" && Ye(e.value)).map((e) => [e.name.substring(8), e.value])
4523
4540
  );
4524
4541
  }
4525
4542
  export {
4526
- ar as ClientDownload,
4527
- _r as ClientLogs,
4528
- br as ClientLs,
4529
- Xt as ClientProgress,
4530
- Ft as ClientUpload,
4531
- pn as DefaultVirtualLocalStorages,
4532
- Mr as Download,
4533
- Hn as DownloadDriver,
4534
- Jn as DownloadUrlDriver,
4535
- Gn as ImportFileHandleData,
4543
+ gr as ClientDownload,
4544
+ Hr as ClientLogs,
4545
+ Dr as ClientLs,
4546
+ or as ClientProgress,
4547
+ At as ClientUpload,
4548
+ Nn as DefaultVirtualLocalStorages,
4549
+ no as DownloadDriver,
4550
+ ao as DownloadUrlDriver,
4551
+ ro as ImportFileHandleData,
4536
4552
  We as ImportFileHandleIndexData,
4537
- F as ImportFileHandleUploadData,
4538
- Zr as IndexResourceSnapshot,
4539
- Mn as LogsDriver,
4540
- qn as LogsStreamDriver,
4541
- An as LongUpdater,
4542
- He as LsDriver,
4543
- Ie as MTimeError,
4544
- Ot as NetworkError,
4545
- Se as NoFileForUploading,
4546
- Wr as OnDemandBlobResourceSnapshot,
4547
- Re as UnexpectedEOF,
4548
- Ue as UnknownStorageError,
4549
- De as Updater,
4550
- Vn as UploadDriver,
4551
- Jr as UploadResourceSnapshot,
4552
- Be as WrongLocalFileUrl,
4553
- On as createDownloadClient,
4554
- Fn as createLogsClient,
4555
- Cr as createLsFilesClient,
4556
- Wn as createUploadBlobClient,
4557
- En as createUploadProgressClient,
4558
- _e as dataToHandle,
4559
- zn as getStream,
4560
- _ as handleToData,
4561
- cr as headersFromProto,
4562
- C as isLiveLogHandle,
4563
- Er as isReadyLogHandle,
4564
- Fr as lineToProgress,
4565
- Qr as makeBlobImportSnapshot,
4566
- xn as mixcrProgressFromLogs,
4567
- lr as parseLocalFileUrl,
4568
- B as validateAbsolute
4553
+ O as ImportFileHandleUploadData,
4554
+ Xr as IndexResourceSnapshot,
4555
+ io as LogsDriver,
4556
+ so as LogsStreamDriver,
4557
+ qe as LsDriver,
4558
+ Ne as MTimeError,
4559
+ Wt as NetworkError,
4560
+ Be as NoFileForUploading,
4561
+ Jr as OnDemandBlobResourceSnapshot,
4562
+ De as UnexpectedEOF,
4563
+ _e as UnknownStorageError,
4564
+ rn as Updater,
4565
+ oo as UploadDriver,
4566
+ Qr as UploadResourceSnapshot,
4567
+ $e as WrongLocalFileUrl,
4568
+ de as WrongResourceTypeError,
4569
+ Yn as createDownloadClient,
4570
+ Kn as createLogsClient,
4571
+ jr as createLsFilesClient,
4572
+ to as createUploadBlobClient,
4573
+ eo as createUploadProgressClient,
4574
+ mr as getFullPath,
4575
+ Zr as getSize,
4576
+ pn as makeBlobImportSnapshot,
4577
+ br as newLocalStorageIdsToRoot,
4578
+ fr as parseLocalUrl,
4579
+ N as validateAbsolute
4569
4580
  };
4570
4581
  //# sourceMappingURL=index.mjs.map