@milaboratories/pl-drivers 1.5.16 → 1.5.18

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.
package/dist/index.mjs CHANGED
@@ -1,35 +1,35 @@
1
- var rt = Object.defineProperty;
2
- var st = (s, e, t) => e in s ? rt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var d = (s, e, t) => st(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { addRTypeToMetadata as P, bigintToResourceId as he, stringifyWithResourceId as y, resourceIdToString as it, isNotNullResourceId as at } from "@milaboratories/pl-client";
1
+ var st = Object.defineProperty;
2
+ var it = (s, e, t) => e in s ? st(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var d = (s, e, t) => it(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { addRTypeToMetadata as P, bigintToResourceId as he, stringifyWithResourceId as y, resourceIdToString as at, isNotNullResourceId as lt } from "@milaboratories/pl-client";
5
5
  import * as m from "node:fs/promises";
6
6
  import { request as Ne } from "undici";
7
- import { ServiceType as C, stackIntercept as T } from "@protobuf-ts/runtime-rpc";
8
- import { MessageType as g, reflectionMergePartial as f, UnknownFieldHandler as u, WireType as h, PbLong as R, typeofJsonValue as Be, assertNever as lt } from "@protobuf-ts/runtime";
9
- import { notEmpty as H, CallersCounter as S, ensureDirExists as ue, fileExists as pe, createPathAtomically as ge, mapGet as Pe, mapEntries as ct, TaskProcessor as j, asyncPool as fe, assertNever as dt } from "@milaboratories/ts-helpers";
7
+ import { ServiceType as _, stackIntercept as T } from "@protobuf-ts/runtime-rpc";
8
+ import { MessageType as g, reflectionMergePartial as f, UnknownFieldHandler as u, WireType as h, PbLong as U, typeofJsonValue as Be, assertNever as ct } from "@protobuf-ts/runtime";
9
+ import { notEmpty as H, CallersCounter as v, ensureDirExists as ue, fileExists as pe, createPathAtomically as ge, mapGet as Pe, mapEntries as dt, TaskProcessor as j, asyncPool as fe, assertNever as ht } from "@milaboratories/ts-helpers";
10
10
  import * as me from "node:fs";
11
11
  import ie from "node:fs";
12
12
  import * as b from "node:path";
13
13
  import L from "node:path";
14
- import { Readable as we, Writable as U, Transform as $e } from "node:stream";
15
- import { text as ht, buffer as _e } from "node:stream/consumers";
16
- import { ChangeSource as N, Computable as w, PollingComputableHooks as Ce } from "@milaboratories/computable";
17
- import { rsSchema as G, treeEntryToResourceInfo as I, isPlTreeEntry as F, makeResourceSnapshot as A, isPlTreeEntryAccessor as Fe } from "@milaboratories/pl-tree";
18
- import ut from "denque";
19
- import { randomUUID as D, createHash as pt } from "node:crypto";
14
+ import { Readable as we, Writable as I, Transform as $e } from "node:stream";
15
+ import { text as ut, buffer as Ce } from "node:stream/consumers";
16
+ import { ChangeSource as N, Computable as w, PollingComputableHooks as _e } from "@milaboratories/computable";
17
+ import { rsSchema as G, treeEntryToResourceInfo as R, isPlTreeEntry as E, makeResourceSnapshot as x, isPlTreeEntryAccessor as Ee } from "@milaboratories/pl-tree";
18
+ import pt from "denque";
19
+ import { randomUUID as D, createHash as gt } from "node:crypto";
20
20
  import * as De from "node:os";
21
- import gt from "node:os";
22
- import * as ft from "node:readline/promises";
21
+ import ft from "node:os";
22
+ import * as mt from "node:readline/promises";
23
23
  import { z as k } from "zod";
24
24
  import * as Oe from "node:zlib";
25
25
  import * as ae from "tar-fs";
26
- import mt from "decompress";
27
- import { scheduler as Ee } from "node:timers/promises";
28
- import wt from "node:assert";
29
- import { isImportFileHandleIndex as yt } from "@milaboratories/pl-model-common";
30
- import bt from "node:util";
31
- import { exec as Tt } from "node:child_process";
32
- class kt extends g {
26
+ import wt from "decompress";
27
+ import { scheduler as Fe } from "node:timers/promises";
28
+ import yt from "node:assert";
29
+ import { isImportFileHandleIndex as bt } from "@milaboratories/pl-model-common";
30
+ import Tt from "node:util";
31
+ import { exec as kt } from "node:child_process";
32
+ class Lt extends g {
33
33
  constructor() {
34
34
  super("MiLaboratories.Controller.Shared.uploadapi", []);
35
35
  }
@@ -49,8 +49,8 @@ class kt extends g {
49
49
  ), t;
50
50
  }
51
51
  }
52
- new kt();
53
- class Lt extends g {
52
+ new Lt();
53
+ class Pt extends g {
54
54
  constructor() {
55
55
  super("MiLaboratories.Controller.Shared.uploadapi.Init", []);
56
56
  }
@@ -70,8 +70,8 @@ class Lt extends g {
70
70
  ), t;
71
71
  }
72
72
  }
73
- new Lt();
74
- class Pt extends g {
73
+ new Pt();
74
+ class Dt extends g {
75
75
  constructor() {
76
76
  super("MiLaboratories.Controller.Shared.uploadapi.Init.Request", [
77
77
  {
@@ -125,7 +125,7 @@ class Pt extends g {
125
125
  ), t;
126
126
  }
127
127
  }
128
- const Dt = new Pt();
128
+ const Ut = new Dt();
129
129
  class Rt extends g {
130
130
  constructor() {
131
131
  super("MiLaboratories.Controller.Shared.uploadapi.Init.Response", [
@@ -202,7 +202,7 @@ class Rt extends g {
202
202
  }
203
203
  }
204
204
  const It = new Rt();
205
- class Ut extends g {
205
+ class St extends g {
206
206
  constructor() {
207
207
  super("MiLaboratories.Controller.Shared.uploadapi.UpdateProgress", []);
208
208
  }
@@ -222,7 +222,7 @@ class Ut extends g {
222
222
  ), t;
223
223
  }
224
224
  }
225
- new Ut();
225
+ new St();
226
226
  class vt extends g {
227
227
  constructor() {
228
228
  super("MiLaboratories.Controller.Shared.uploadapi.UpdateProgress.Request", [
@@ -293,8 +293,8 @@ class vt extends g {
293
293
  ), t;
294
294
  }
295
295
  }
296
- const St = new vt();
297
- class Nt extends g {
296
+ const Nt = new vt();
297
+ class Bt extends g {
298
298
  constructor() {
299
299
  super(
300
300
  "MiLaboratories.Controller.Shared.uploadapi.UpdateProgress.Response",
@@ -321,8 +321,8 @@ class Nt extends g {
321
321
  ), t;
322
322
  }
323
323
  }
324
- const Bt = new Nt();
325
- class $t extends g {
324
+ const $t = new Bt();
325
+ class Ct extends g {
326
326
  constructor() {
327
327
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL", []);
328
328
  }
@@ -342,7 +342,7 @@ class $t extends g {
342
342
  ), t;
343
343
  }
344
344
  }
345
- new $t();
345
+ new Ct();
346
346
  class _t extends g {
347
347
  constructor() {
348
348
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL.Request", [
@@ -425,8 +425,8 @@ class _t extends g {
425
425
  ), t;
426
426
  }
427
427
  }
428
- const Ct = new _t();
429
- class Ft extends g {
428
+ const Et = new _t();
429
+ class Ot extends g {
430
430
  constructor() {
431
431
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL.HTTPHeader", [
432
432
  {
@@ -496,8 +496,8 @@ class Ft extends g {
496
496
  ), t;
497
497
  }
498
498
  }
499
- const Z = new Ft();
500
- class Ot extends g {
499
+ const Z = new Ot();
500
+ class Ft extends g {
501
501
  constructor() {
502
502
  super("MiLaboratories.Controller.Shared.uploadapi.GetPartURL.Response", [
503
503
  {
@@ -613,8 +613,8 @@ class Ot extends g {
613
613
  ), t;
614
614
  }
615
615
  }
616
- const Et = new Ot();
617
- class Wt extends g {
616
+ const Wt = new Ft();
617
+ class zt extends g {
618
618
  constructor() {
619
619
  super("MiLaboratories.Controller.Shared.uploadapi.Finalize", []);
620
620
  }
@@ -634,8 +634,8 @@ class Wt extends g {
634
634
  ), t;
635
635
  }
636
636
  }
637
- new Wt();
638
- class zt extends g {
637
+ new zt();
638
+ class xt extends g {
639
639
  constructor() {
640
640
  super("MiLaboratories.Controller.Shared.uploadapi.Finalize.Request", [
641
641
  {
@@ -689,8 +689,8 @@ class zt extends g {
689
689
  ), t;
690
690
  }
691
691
  }
692
- const At = new zt();
693
- class xt extends g {
692
+ const At = new xt();
693
+ class Mt extends g {
694
694
  constructor() {
695
695
  super("MiLaboratories.Controller.Shared.uploadapi.Finalize.Response", []);
696
696
  }
@@ -710,36 +710,36 @@ class xt extends g {
710
710
  ), t;
711
711
  }
712
712
  }
713
- const Mt = new xt(), Q = new C(
713
+ const Ht = new Mt(), Q = new _(
714
714
  "MiLaboratories.Controller.Shared.Upload",
715
715
  [
716
716
  {
717
717
  name: "Init",
718
718
  options: {},
719
- I: Dt,
719
+ I: Ut,
720
720
  O: It
721
721
  },
722
722
  {
723
723
  name: "GetPartURL",
724
724
  options: {},
725
- I: Ct,
726
- O: Et
725
+ I: Et,
726
+ O: Wt
727
727
  },
728
728
  {
729
729
  name: "UpdateProgress",
730
730
  options: {},
731
- I: St,
732
- O: Bt
731
+ I: Nt,
732
+ O: $t
733
733
  },
734
734
  {
735
735
  name: "Finalize",
736
736
  options: {},
737
737
  I: At,
738
- O: Mt
738
+ O: Ht
739
739
  }
740
740
  ]
741
741
  );
742
- class Ht {
742
+ class jt {
743
743
  constructor(e) {
744
744
  d(this, "typeName", Q.typeName);
745
745
  d(this, "methods", Q.methods);
@@ -805,16 +805,16 @@ function We(s) {
805
805
  }
806
806
  class ze extends Error {
807
807
  }
808
- class Ae extends Error {
808
+ class xe extends Error {
809
809
  }
810
- class jt extends Error {
810
+ class Ae extends Error {
811
811
  }
812
- class xe extends Error {
812
+ class Me extends Error {
813
813
  }
814
814
  class Gt {
815
815
  constructor(e, t, o, n) {
816
816
  d(this, "grpcClient");
817
- this.grpcTransport = e, this.httpClient = t, this.logger = n, this.grpcClient = new Ht(this.grpcTransport);
817
+ this.grpcTransport = e, this.httpClient = t, this.logger = n, this.grpcClient = new jt(this.grpcTransport);
818
818
  }
819
819
  close() {
820
820
  }
@@ -842,14 +842,20 @@ class Gt {
842
842
  } = await Ne(i.uploadUrl, {
843
843
  dispatcher: this.httpClient,
844
844
  body: c,
845
+ // We got headers only after we send
846
+ // the whole body (in case of S3 PUT requests it's 5 MB).
847
+ // It might be slow with a slow connection (or with SSH),
848
+ // that's why we got big timeout here.
849
+ headersTimeout: 6e4,
850
+ bodyTimeout: 6e4,
845
851
  headers: We(i.headers),
846
852
  method: i.method.toUpperCase()
847
- }), nt = await l.text();
848
- Zt(p, nt, J, i);
853
+ }), rt = await l.text();
854
+ Zt(p, rt, J, i);
849
855
  } catch (l) {
850
- throw new Error(`partUpload: error ${JSON.stringify(l)} happened while trying to do part upload to the url ${i.uploadUrl}, headers: ${JSON.stringify(i.headers)}`);
856
+ throw l instanceof Ae ? l : new Error(`partUpload: error ${JSON.stringify(l)} happened while trying to do part upload to the url ${i.uploadUrl}, headers: ${JSON.stringify(i.headers)}`);
851
857
  }
852
- await this.grpcUpdateProgress({ id: e, type: t }, i.chunkEnd - i.chunkStart, a);
858
+ await this.grpcUpdateProgress({ id: e, type: t }, BigInt(i.chunkEnd - i.chunkStart), a);
853
859
  }
854
860
  async finalize(e, t) {
855
861
  return await this.grpcFinalize(e, t);
@@ -891,7 +897,7 @@ async function Vt(s, e, t) {
891
897
  const n = Number(t - e), r = Number(e), a = Buffer.alloc(n), i = await qt(o, a, n, r);
892
898
  return a.subarray(0, i);
893
899
  } catch (n) {
894
- throw n && typeof n == "object" && "code" in n && n.code == "ENOENT" ? new xe(`there is no file ${s} for uploading`) : n;
900
+ throw n && typeof n == "object" && "code" in n && n.code == "ENOENT" ? new Me(`there is no file ${s} for uploading`) : n;
895
901
  } finally {
896
902
  await (o == null ? void 0 : o.close());
897
903
  }
@@ -906,7 +912,7 @@ async function qt(s, e, t, o) {
906
912
  o + n
907
913
  );
908
914
  if (r === 0)
909
- throw new Ae("file ended earlier than expected.");
915
+ throw new xe("file ended earlier than expected.");
910
916
  n += r;
911
917
  }
912
918
  return n;
@@ -918,7 +924,7 @@ async function Jt(s, e) {
918
924
  }
919
925
  function Zt(s, e, t, o) {
920
926
  if (s != 200)
921
- throw new jt(
927
+ throw new Ae(
922
928
  `response is not ok, status code: ${s}, body: ${e}, headers: ${JSON.stringify(t)}, url: ${o.uploadUrl}`
923
929
  );
924
930
  }
@@ -946,7 +952,7 @@ class Qt extends g {
946
952
  * Encode `Duration` to JSON string like "3.000001s".
947
953
  */
948
954
  internalJsonWrite(e, t) {
949
- const o = R.from(e.seconds).toNumber();
955
+ const o = U.from(e.seconds).toNumber();
950
956
  if (o > 315576e6 || o < -315576e6)
951
957
  throw new Error("Duration value out of range.");
952
958
  let n = e.seconds.toString();
@@ -970,7 +976,7 @@ class Qt extends g {
970
976
  "Unable to parse Duration from JSON string. Invalid format."
971
977
  );
972
978
  o || (o = this.create());
973
- const [, r, a, i] = n, c = R.from(r + a);
979
+ const [, r, a, i] = n, c = U.from(r + a);
974
980
  if (c.toNumber() > 315576e6 || c.toNumber() < -315576e6)
975
981
  throw new Error(
976
982
  "Unable to parse Duration from JSON string. Value out of range."
@@ -1147,7 +1153,7 @@ class Kt extends g {
1147
1153
  ), t;
1148
1154
  }
1149
1155
  }
1150
- const v = new Kt();
1156
+ const S = new Kt();
1151
1157
  class Yt extends g {
1152
1158
  constructor() {
1153
1159
  super("MiLaboratories.Controller.Shared.ProgressAPI.GetStatus", []);
@@ -1231,7 +1237,7 @@ const to = new eo();
1231
1237
  class oo extends g {
1232
1238
  constructor() {
1233
1239
  super("MiLaboratories.Controller.Shared.ProgressAPI.GetStatus.Response", [
1234
- { no: 1, name: "report", kind: "message", T: () => v }
1240
+ { no: 1, name: "report", kind: "message", T: () => S }
1235
1241
  ]);
1236
1242
  }
1237
1243
  create(e) {
@@ -1249,7 +1255,7 @@ class oo extends g {
1249
1255
  switch (i) {
1250
1256
  case /* MiLaboratories.Controller.Shared.ProgressAPI.Report report */
1251
1257
  1:
1252
- r.report = v.internalBinaryRead(
1258
+ r.report = S.internalBinaryRead(
1253
1259
  e,
1254
1260
  e.uint32(),
1255
1261
  o,
@@ -1275,7 +1281,7 @@ class oo extends g {
1275
1281
  return r;
1276
1282
  }
1277
1283
  internalBinaryWrite(e, t, o) {
1278
- e.report && v.internalBinaryWrite(
1284
+ e.report && S.internalBinaryWrite(
1279
1285
  e.report,
1280
1286
  t.tag(1, h.LengthDelimited).fork(),
1281
1287
  o
@@ -1390,7 +1396,7 @@ class ao extends g {
1390
1396
  constructor() {
1391
1397
  super(
1392
1398
  "MiLaboratories.Controller.Shared.ProgressAPI.RealtimeStatus.Response",
1393
- [{ no: 1, name: "report", kind: "message", T: () => v }]
1399
+ [{ no: 1, name: "report", kind: "message", T: () => S }]
1394
1400
  );
1395
1401
  }
1396
1402
  create(e) {
@@ -1408,7 +1414,7 @@ class ao extends g {
1408
1414
  switch (i) {
1409
1415
  case /* MiLaboratories.Controller.Shared.ProgressAPI.Report report */
1410
1416
  1:
1411
- r.report = v.internalBinaryRead(
1417
+ r.report = S.internalBinaryRead(
1412
1418
  e,
1413
1419
  e.uint32(),
1414
1420
  o,
@@ -1434,7 +1440,7 @@ class ao extends g {
1434
1440
  return r;
1435
1441
  }
1436
1442
  internalBinaryWrite(e, t, o) {
1437
- e.report && v.internalBinaryWrite(
1443
+ e.report && S.internalBinaryWrite(
1438
1444
  e.report,
1439
1445
  t.tag(1, h.LengthDelimited).fork(),
1440
1446
  o
@@ -1447,7 +1453,7 @@ class ao extends g {
1447
1453
  ), t;
1448
1454
  }
1449
1455
  }
1450
- const lo = new ao(), X = new C(
1456
+ const lo = new ao(), X = new _(
1451
1457
  "MiLaboratories.Controller.Shared.Progress",
1452
1458
  [
1453
1459
  {
@@ -1533,7 +1539,7 @@ class ho {
1533
1539
  }
1534
1540
  class V extends Error {
1535
1541
  }
1536
- class Me {
1542
+ class He {
1537
1543
  constructor(e) {
1538
1544
  this.httpClient = e;
1539
1545
  }
@@ -1551,13 +1557,13 @@ class Me {
1551
1557
  }
1552
1558
  async function uo(s, e, t) {
1553
1559
  if (s != 200) {
1554
- const o = (await ht(e)).substring(0, 1e3);
1560
+ const o = (await ut(e)).substring(0, 1e3);
1555
1561
  throw 400 <= s && s < 500 ? new V(
1556
1562
  `Http error: statusCode: ${s} url: ${t.toString()}, beginning of body: ${o}`
1557
1563
  ) : new Error(`Http error: statusCode: ${s} url: ${t.toString()}`);
1558
1564
  }
1559
1565
  }
1560
- function _(s) {
1566
+ function C(s) {
1561
1567
  if (!L.isAbsolute(s)) throw new Error(`Path ${s} is not absolute.`);
1562
1568
  return s;
1563
1569
  }
@@ -1822,7 +1828,7 @@ class yo extends g {
1822
1828
  ), t;
1823
1829
  }
1824
1830
  }
1825
- const bo = new yo(), Y = new C(
1831
+ const bo = new yo(), Y = new _(
1826
1832
  "MiLaboratories.Controller.Shared.Download",
1827
1833
  [
1828
1834
  {
@@ -1856,13 +1862,13 @@ class ko {
1856
1862
  d(this, "remoteFileDownloader");
1857
1863
  /** Helps to find a storage root directory by a storage id from URL scheme. */
1858
1864
  d(this, "localStorageIdsToRoot");
1859
- this.grpcTransport = e, this.httpClient = t, this.logger = o, this.grpcClient = new To(this.grpcTransport), this.remoteFileDownloader = new Me(t), this.localStorageIdsToRoot = Io(n);
1865
+ this.grpcTransport = e, this.httpClient = t, this.logger = o, this.grpcClient = new To(this.grpcTransport), this.remoteFileDownloader = new He(t), this.localStorageIdsToRoot = Ro(n);
1860
1866
  }
1861
1867
  close() {
1862
1868
  }
1863
1869
  async downloadBlob(e, t, o) {
1864
1870
  const { downloadUrl: n, headers: r } = await this.grpcGetDownloadUrl(e, t, o);
1865
- return this.logger.info(`download blob from url ${n}`), Ro(n) ? await this.readLocalFile(n) : await this.remoteFileDownloader.download(n, We(r), o);
1871
+ return this.logger.info(`download blob from url ${n}`), Uo(n) ? await this.readLocalFile(n) : await this.remoteFileDownloader.download(n, We(r), o);
1866
1872
  }
1867
1873
  async readLocalFile(e) {
1868
1874
  const { storageId: t, relativePath: o } = Lo(e), n = Po(t, this.localStorageIdsToRoot, o);
@@ -1894,20 +1900,20 @@ function Po(s, e, t) {
1894
1900
  return o === "" ? t : b.join(o, t);
1895
1901
  }
1896
1902
  const Do = "storage://";
1897
- function Ro(s) {
1903
+ function Uo(s) {
1898
1904
  return s.startsWith(Do);
1899
1905
  }
1900
1906
  class ye extends Error {
1901
1907
  }
1902
1908
  class be extends Error {
1903
1909
  }
1904
- function Io(s) {
1910
+ function Ro(s) {
1905
1911
  const e = /* @__PURE__ */ new Map();
1906
1912
  for (const t of s)
1907
- t.localPath !== "" && _(t.localPath), e.set(t.storageId, t.localPath);
1913
+ t.localPath !== "" && C(t.localPath), e.set(t.storageId, t.localPath);
1908
1914
  return e;
1909
1915
  }
1910
- class Uo extends g {
1916
+ class Io extends g {
1911
1917
  constructor() {
1912
1918
  super("google.protobuf.Timestamp", [
1913
1919
  {
@@ -1932,14 +1938,14 @@ class Uo extends g {
1932
1938
  */
1933
1939
  now() {
1934
1940
  const e = this.create(), t = Date.now();
1935
- return e.seconds = R.from(Math.floor(t / 1e3)).toBigInt(), e.nanos = t % 1e3 * 1e6, e;
1941
+ return e.seconds = U.from(Math.floor(t / 1e3)).toBigInt(), e.nanos = t % 1e3 * 1e6, e;
1936
1942
  }
1937
1943
  /**
1938
1944
  * Converts a `Timestamp` to a JavaScript Date.
1939
1945
  */
1940
1946
  toDate(e) {
1941
1947
  return new Date(
1942
- R.from(e.seconds).toNumber() * 1e3 + Math.ceil(e.nanos / 1e6)
1948
+ U.from(e.seconds).toNumber() * 1e3 + Math.ceil(e.nanos / 1e6)
1943
1949
  );
1944
1950
  }
1945
1951
  /**
@@ -1947,14 +1953,14 @@ class Uo extends g {
1947
1953
  */
1948
1954
  fromDate(e) {
1949
1955
  const t = this.create(), o = e.getTime();
1950
- return t.seconds = R.from(Math.floor(o / 1e3)).toBigInt(), t.nanos = o % 1e3 * 1e6, t;
1956
+ return t.seconds = U.from(Math.floor(o / 1e3)).toBigInt(), t.nanos = o % 1e3 * 1e6, t;
1951
1957
  }
1952
1958
  /**
1953
1959
  * In JSON format, the `Timestamp` type is encoded as a string
1954
1960
  * in the RFC 3339 format.
1955
1961
  */
1956
1962
  internalJsonWrite(e, t) {
1957
- const o = R.from(e.seconds).toNumber() * 1e3;
1963
+ const o = U.from(e.seconds).toNumber() * 1e3;
1958
1964
  if (o < Date.parse("0001-01-01T00:00:00Z") || o > Date.parse("9999-12-31T23:59:59Z"))
1959
1965
  throw new Error(
1960
1966
  "Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."
@@ -1993,7 +1999,7 @@ class Uo extends g {
1993
1999
  throw new globalThis.Error(
1994
2000
  "Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."
1995
2001
  );
1996
- return o || (o = this.create()), o.seconds = R.from(r / 1e3).toBigInt(), o.nanos = 0, n[7] && (o.nanos = parseInt("1" + n[7] + "0".repeat(9 - n[7].length)) - 1e9), o;
2002
+ return o || (o = this.create()), o.seconds = U.from(r / 1e3).toBigInt(), o.nanos = 0, n[7] && (o.nanos = parseInt("1" + n[7] + "0".repeat(9 - n[7].length)) - 1e9), o;
1997
2003
  }
1998
2004
  create(e) {
1999
2005
  const t = globalThis.Object.create(this.messagePrototype);
@@ -2040,8 +2046,8 @@ class Uo extends g {
2040
2046
  ), t;
2041
2047
  }
2042
2048
  }
2043
- const ee = new Uo();
2044
- class vo extends g {
2049
+ const ee = new Io();
2050
+ class So extends g {
2045
2051
  constructor() {
2046
2052
  super("MiLaboratories.Controller.Shared.LsAPI", []);
2047
2053
  }
@@ -2061,8 +2067,8 @@ class vo extends g {
2061
2067
  ), t;
2062
2068
  }
2063
2069
  }
2064
- new vo();
2065
- class So extends g {
2070
+ new So();
2071
+ class vo extends g {
2066
2072
  constructor() {
2067
2073
  super("MiLaboratories.Controller.Shared.LsAPI.ListItem", [
2068
2074
  {
@@ -2185,7 +2191,7 @@ class So extends g {
2185
2191
  ), t;
2186
2192
  }
2187
2193
  }
2188
- const te = new So();
2194
+ const te = new vo();
2189
2195
  class No extends g {
2190
2196
  constructor() {
2191
2197
  super("MiLaboratories.Controller.Shared.LsAPI.List", []);
@@ -2273,7 +2279,7 @@ class Bo extends g {
2273
2279
  }
2274
2280
  }
2275
2281
  const $o = new Bo();
2276
- class _o extends g {
2282
+ class Co extends g {
2277
2283
  constructor() {
2278
2284
  super("MiLaboratories.Controller.Shared.LsAPI.List.Response", [
2279
2285
  {
@@ -2345,10 +2351,10 @@ class _o extends g {
2345
2351
  ), t;
2346
2352
  }
2347
2353
  }
2348
- const Co = new _o(), oe = new C("MiLaboratories.Controller.Shared.LS", [
2349
- { name: "List", options: {}, I: $o, O: Co }
2354
+ const _o = new Co(), oe = new _("MiLaboratories.Controller.Shared.LS", [
2355
+ { name: "List", options: {}, I: $o, O: _o }
2350
2356
  ]);
2351
- class Fo {
2357
+ class Eo {
2352
2358
  constructor(e) {
2353
2359
  d(this, "typeName", oe.typeName);
2354
2360
  d(this, "methods", oe.methods);
@@ -2372,7 +2378,7 @@ class Fo {
2372
2378
  class Oo {
2373
2379
  constructor(e, t) {
2374
2380
  d(this, "grpcClient");
2375
- this.logger = t, this.grpcClient = new Fo(e);
2381
+ this.logger = t, this.grpcClient = new Eo(e);
2376
2382
  }
2377
2383
  close() {
2378
2384
  }
@@ -2386,7 +2392,7 @@ class Oo {
2386
2392
  ).response;
2387
2393
  }
2388
2394
  }
2389
- class Eo extends g {
2395
+ class Fo extends g {
2390
2396
  constructor() {
2391
2397
  super("MiLaboratories.Controller.Shared.StreamingAPI", []);
2392
2398
  }
@@ -2406,7 +2412,7 @@ class Eo extends g {
2406
2412
  ), t;
2407
2413
  }
2408
2414
  }
2409
- new Eo();
2415
+ new Fo();
2410
2416
  class Wo extends g {
2411
2417
  constructor() {
2412
2418
  super("MiLaboratories.Controller.Shared.StreamingAPI.StreamBinary", [
@@ -2499,7 +2505,7 @@ class Wo extends g {
2499
2505
  }
2500
2506
  }
2501
2507
  const zo = new Wo();
2502
- class Ao extends g {
2508
+ class xo extends g {
2503
2509
  constructor() {
2504
2510
  super("MiLaboratories.Controller.Shared.StreamingAPI.ReadBinary", [
2505
2511
  {
@@ -2577,7 +2583,7 @@ class Ao extends g {
2577
2583
  ), t;
2578
2584
  }
2579
2585
  }
2580
- const xo = new Ao();
2586
+ const Ao = new xo();
2581
2587
  class Mo extends g {
2582
2588
  constructor() {
2583
2589
  super("MiLaboratories.Controller.Shared.StreamingAPI.StreamText", [
@@ -2967,7 +2973,7 @@ class Jo extends g {
2967
2973
  ), t;
2968
2974
  }
2969
2975
  }
2970
- const B = new Jo(), ne = new C(
2976
+ const B = new Jo(), ne = new _(
2971
2977
  "MiLaboratories.Controller.Shared.Streaming",
2972
2978
  [
2973
2979
  {
@@ -2980,7 +2986,7 @@ const B = new Jo(), ne = new C(
2980
2986
  {
2981
2987
  name: "ReadBinary",
2982
2988
  options: {},
2983
- I: xo,
2989
+ I: Ao,
2984
2990
  O: B
2985
2991
  },
2986
2992
  {
@@ -3139,25 +3145,25 @@ class Qo {
3139
3145
  )).response;
3140
3146
  }
3141
3147
  }
3142
- function fr(s, e, t) {
3148
+ function yr(s, e, t) {
3143
3149
  return e.getDriver({
3144
3150
  name: "DownloadBlob",
3145
3151
  init: (o, n, r) => new ko(n, r, s, t)
3146
3152
  });
3147
3153
  }
3148
- function mr(s, e) {
3154
+ function br(s, e) {
3149
3155
  return s.getDriver({
3150
3156
  name: "StreamLogs",
3151
3157
  init: (t, o, n) => new Qo(o, n, e)
3152
3158
  });
3153
3159
  }
3154
- function wr(s, e) {
3160
+ function Tr(s, e) {
3155
3161
  return s.getDriver({
3156
3162
  name: "UploadProgress",
3157
3163
  init: (t, o, n) => new ho(o, n, s, e)
3158
3164
  });
3159
3165
  }
3160
- function yr(s, e) {
3166
+ function kr(s, e) {
3161
3167
  return s.getDriver({
3162
3168
  name: "UploadBlob",
3163
3169
  init: (t, o, n) => new Gt(o, n, s, e)
@@ -3171,7 +3177,7 @@ function Xo(s, e) {
3171
3177
  }
3172
3178
  class Ko {
3173
3179
  constructor(e, t, o, n, r) {
3174
- d(this, "counter", new S());
3180
+ d(this, "counter", new v());
3175
3181
  d(this, "change", new N());
3176
3182
  d(this, "signalCtl", new AbortController());
3177
3183
  d(this, "error");
@@ -3206,12 +3212,12 @@ class Ko {
3206
3212
  return this.logger.info(`a blob was already downloaded: ${this.path}`), (await m.stat(this.path)).size;
3207
3213
  const { content: e, size: t } = await this.clientDownload.downloadBlob(this.rInfo);
3208
3214
  return await ge(this.logger, this.path, async (o) => {
3209
- const n = U.toWeb(ie.createWriteStream(o, { flags: "wx" }));
3215
+ const n = I.toWeb(ie.createWriteStream(o, { flags: "wx" }));
3210
3216
  await e.pipeTo(n);
3211
3217
  }), t;
3212
3218
  }
3213
3219
  abort(e) {
3214
- this.signalCtl.abort(new He(e));
3220
+ this.signalCtl.abort(new je(e));
3215
3221
  }
3216
3222
  getBlob() {
3217
3223
  return this.done ? this.error ? {
@@ -3236,9 +3242,9 @@ class Ko {
3236
3242
  }
3237
3243
  }
3238
3244
  function Te(s) {
3239
- return s instanceof He || s instanceof V || s instanceof be || s instanceof ye || (s == null ? void 0 : s.code) == "ENOENT" || s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED");
3245
+ return s instanceof je || s instanceof V || s instanceof be || s instanceof ye || (s == null ? void 0 : s.code) == "ENOENT" || s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED");
3240
3246
  }
3241
- class He extends Error {
3247
+ class je extends Error {
3242
3248
  }
3243
3249
  class ke {
3244
3250
  constructor(e) {
@@ -3263,7 +3269,7 @@ class ke {
3263
3269
  if (this.totalSizeBytes <= this.softSizeBytes) return [];
3264
3270
  const e = [];
3265
3271
  let t = 0;
3266
- return ct(this.cache).filter(([o, n]) => n.counter.isZero()).forEach(([o, n]) => {
3272
+ return dt(this.cache).filter(([o, n]) => n.counter.isZero()).forEach(([o, n]) => {
3267
3273
  if (this.totalSizeBytes - t <= this.softSizeBytes) return;
3268
3274
  const r = Pe(this.cache, o);
3269
3275
  t += r.size, e.push(r);
@@ -3278,15 +3284,15 @@ class ke {
3278
3284
  this.cache.delete(e.path), this.totalSizeBytes -= e.size;
3279
3285
  }
3280
3286
  }
3281
- const je = /^blob\+local:\/\/download\/(?<path>.*)#(?<signature>.*)$/;
3287
+ const Ge = /^blob\+local:\/\/download\/(?<path>.*)#(?<signature>.*)$/;
3282
3288
  function Yo(s, e) {
3283
3289
  return `blob+local://download/${s}#${e.sign(s)}`;
3284
3290
  }
3285
3291
  function en(s) {
3286
- return !!s.match(je);
3292
+ return !!s.match(Ge);
3287
3293
  }
3288
3294
  function re(s, e) {
3289
- const t = s.match(je);
3295
+ const t = s.match(Ge);
3290
3296
  if (t === null)
3291
3297
  throw new Error(`Local handle is malformed: ${s}, matches: ${t}`);
3292
3298
  const { path: o, signature: n } = t.groups;
@@ -3311,14 +3317,14 @@ const q = k.object({
3311
3317
  sizeBytes: k.string(),
3312
3318
  /** Modification time unix timestamp in seconds */
3313
3319
  modificationTime: k.string()
3314
- }), Ge = k.object({
3320
+ }), Ve = k.object({
3315
3321
  /** Pl storage id */
3316
3322
  storageId: k.string(),
3317
3323
  /** Path inside storage */
3318
3324
  path: k.string()
3319
- }), br = k.union([
3325
+ }), Lr = k.union([
3320
3326
  q,
3321
- Ge
3327
+ Ve
3322
3328
  ]), nn = G({
3323
3329
  data: q,
3324
3330
  fields: {
@@ -3328,16 +3334,16 @@ const q = k.object({
3328
3334
  fields: {
3329
3335
  incarnation: !1
3330
3336
  }
3331
- }), Ve = /^blob\+remote:\/\/download\/(?<content>(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*))#(?<signature>.*)$/;
3337
+ }), qe = /^blob\+remote:\/\/download\/(?<content>(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*))#(?<signature>.*)$/;
3332
3338
  function sn(s, e) {
3333
3339
  const t = `${s.type.name}/${s.type.version}/${BigInt(s.id)}`;
3334
3340
  return `blob+remote://download/${t}#${e.sign(t)}`;
3335
3341
  }
3336
3342
  function an(s) {
3337
- return !!s.match(Ve);
3343
+ return !!s.match(qe);
3338
3344
  }
3339
3345
  function ln(s, e) {
3340
- const t = s.match(Ve);
3346
+ const t = s.match(qe);
3341
3347
  if (t === null)
3342
3348
  throw new Error(`Remote handle is malformed: ${s}, matches: ${t}`);
3343
3349
  const { content: o, resourceType: n, resourceVersion: r, resourceId: a, signature: i } = t.groups;
@@ -3346,23 +3352,23 @@ function ln(s, e) {
3346
3352
  type: { name: n, version: r }
3347
3353
  };
3348
3354
  }
3349
- function qe(s, e) {
3355
+ function Je(s, e) {
3350
3356
  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)}`;
3351
3357
  }
3352
- const Je = /^log\+live:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3353
- function x(s) {
3354
- return Je.test(s);
3358
+ const Ze = /^log\+live:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3359
+ function A(s) {
3360
+ return Ze.test(s);
3355
3361
  }
3356
- const Ze = /^log\+ready:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3362
+ const Qe = /^log\+ready:\/\/log\/(?<resourceType>.*)\/(?<resourceVersion>.*)\/(?<resourceId>.*)$/;
3357
3363
  function cn(s) {
3358
- return Ze.test(s);
3364
+ return Qe.test(s);
3359
3365
  }
3360
3366
  function M(s) {
3361
3367
  let e;
3362
- if (x(s))
3363
- e = s.match(Je);
3364
- else if (cn(s))
3368
+ if (A(s))
3365
3369
  e = s.match(Ze);
3370
+ else if (cn(s))
3371
+ e = s.match(Qe);
3366
3372
  else throw new Error(`Log handle is malformed: ${s}`);
3367
3373
  if (e == null) throw new Error(`Log handle wasn't parsed: ${s}`);
3368
3374
  const { resourceType: t, resourceVersion: o, resourceId: n } = e.groups;
@@ -3390,7 +3396,7 @@ class dn {
3390
3396
  })());
3391
3397
  }
3392
3398
  }
3393
- class Tr {
3399
+ class Pr {
3394
3400
  constructor(e, t, o, n, r, a) {
3395
3401
  /** Represents a Resource Id to the path of a blob as a map. */
3396
3402
  d(this, "idToDownload", /* @__PURE__ */ new Map());
@@ -3407,7 +3413,7 @@ class Tr {
3407
3413
  }
3408
3414
  getDownloadedBlob(e, t) {
3409
3415
  if (t === void 0) return w.make((a) => this.getDownloadedBlob(e, a));
3410
- const o = I(e, t), n = D();
3416
+ const o = R(e, t), n = D();
3411
3417
  t.addOnDestroy(() => this.releaseBlob(o.id, n));
3412
3418
  const r = this.getDownloadedBlobNoCtx(t.watcher, o, n);
3413
3419
  return r == null && t.markUnstable("download blob is still undefined"), r;
@@ -3446,7 +3452,7 @@ class Tr {
3446
3452
  }
3447
3453
  getOnDemandBlob(e, t) {
3448
3454
  if (t === void 0) return w.make((a) => this.getOnDemandBlob(e, a));
3449
- const o = F(e) ? A(e, tn, t) : e, n = D();
3455
+ const o = E(e) ? x(e, tn, t) : e, n = D();
3450
3456
  return t.addOnDestroy(() => this.releaseOnDemandBlob(o.id, n)), this.getOnDemandBlobNoCtx(o, n);
3451
3457
  }
3452
3458
  getOnDemandBlobNoCtx(e, t) {
@@ -3465,13 +3471,25 @@ class Tr {
3465
3471
  return await pn(this.getLocalPath(e));
3466
3472
  if (an(e)) {
3467
3473
  const t = ln(e, this.signer), { content: o } = await this.clientDownload.downloadBlob(t);
3468
- return await _e(o);
3474
+ return await Ce(o);
3469
3475
  }
3470
3476
  throw new Error("Malformed remote handle");
3471
3477
  }
3478
+ /**
3479
+ * Creates computable that will return blob content once it is downloaded.
3480
+ * Uses downloaded blob handle under the hood, so stores corresponding blob in file system.
3481
+ */
3482
+ getComputableContent(e) {
3483
+ return w.make(
3484
+ (t) => this.getDownloadedBlob(e, t),
3485
+ {
3486
+ postprocessValue: (t) => t ? this.getContent(t.handle) : void 0
3487
+ }
3488
+ ).withStableType();
3489
+ }
3472
3490
  getLastLogs(e, t, o) {
3473
3491
  if (o == null) return w.make((i) => this.getLastLogs(e, t, i));
3474
- const n = I(e, o), r = D();
3492
+ const n = R(e, o), r = D();
3475
3493
  o.addOnDestroy(() => this.releaseBlob(n.id, r));
3476
3494
  const a = this.getLastLogsNoCtx(o.watcher, n, t, r);
3477
3495
  return a == null && o.markUnstable("either a file was not downloaded or logs was not read"), a;
@@ -3483,7 +3501,7 @@ class Tr {
3483
3501
  const { path: a } = re(r.handle, this.signer);
3484
3502
  let i = this.idToLastLines.get(t.id);
3485
3503
  if (i == null) {
3486
- const l = new Re(a, o);
3504
+ const l = new Ue(a, o);
3487
3505
  this.idToLastLines.set(t.id, l), i = l;
3488
3506
  }
3489
3507
  const c = i.getOrSchedule(e);
@@ -3493,7 +3511,7 @@ class Tr {
3493
3511
  getProgressLog(e, t, o) {
3494
3512
  if (o == null)
3495
3513
  return w.make((i) => this.getProgressLog(e, t, i));
3496
- const n = I(e, o), r = D();
3514
+ const n = R(e, o), r = D();
3497
3515
  o.addOnDestroy(() => this.releaseBlob(n.id, r));
3498
3516
  const a = this.getProgressLogNoCtx(
3499
3517
  o.watcher,
@@ -3510,7 +3528,7 @@ class Tr {
3510
3528
  const { path: a } = re(r.handle, this.signer);
3511
3529
  let i = this.idToProgressLog.get(t.id);
3512
3530
  if (i == null) {
3513
- const l = new Re(a, 1, o);
3531
+ const l = new Ue(a, 1, o);
3514
3532
  this.idToProgressLog.set(t.id, l), i = l;
3515
3533
  }
3516
3534
  const c = i.getOrSchedule(e);
@@ -3519,11 +3537,11 @@ class Tr {
3519
3537
  }
3520
3538
  getLogHandle(e, t) {
3521
3539
  if (t == null) return w.make((n) => this.getLogHandle(e, n));
3522
- const o = I(e, t);
3540
+ const o = R(e, t);
3523
3541
  return this.getLogHandleNoCtx(o);
3524
3542
  }
3525
3543
  getLogHandleNoCtx(e) {
3526
- return $("getLogHandle", e.type), qe(!1, e);
3544
+ return $("getLogHandle", e.type), Je(!1, e);
3527
3545
  }
3528
3546
  async lastLines(e, t, o, n) {
3529
3547
  const r = await this.clientLogs.lastLines(
@@ -3593,7 +3611,7 @@ class Tr {
3593
3611
  }
3594
3612
  class hn {
3595
3613
  constructor(e, t) {
3596
- d(this, "counter", new S());
3614
+ d(this, "counter", new v());
3597
3615
  this.size = e, this.handle = t;
3598
3616
  }
3599
3617
  getHandle() {
@@ -3606,7 +3624,7 @@ class hn {
3606
3624
  return this.counter.dec(e);
3607
3625
  }
3608
3626
  }
3609
- class Re {
3627
+ class Ue {
3610
3628
  constructor(e, t, o) {
3611
3629
  d(this, "updater");
3612
3630
  d(this, "log");
@@ -3634,9 +3652,9 @@ class Re {
3634
3652
  }
3635
3653
  }
3636
3654
  function un(s, e, t) {
3637
- const o = me.createReadStream(s), n = new U();
3655
+ const o = me.createReadStream(s), n = new I();
3638
3656
  return new Promise((r, a) => {
3639
- const i = ft.createInterface(o, n), c = new ut();
3657
+ const i = mt.createInterface(o, n), c = new pt();
3640
3658
  i.on("line", function(l) {
3641
3659
  t != null && !l.includes(t) || (c.push(l), c.length > e && c.shift());
3642
3660
  }), i.on("error", a), i.on("close", function() {
@@ -3645,7 +3663,7 @@ function un(s, e, t) {
3645
3663
  });
3646
3664
  }
3647
3665
  async function pn(s) {
3648
- return await _e(we.toWeb(me.createReadStream(s)));
3666
+ return await Ce(we.toWeb(me.createReadStream(s)));
3649
3667
  }
3650
3668
  function $(s, e) {
3651
3669
  if (!e.name.startsWith("Blob/")) {
@@ -3655,8 +3673,8 @@ function $(s, e) {
3655
3673
  }
3656
3674
  const gn = G({});
3657
3675
  function fn(s, e) {
3658
- const t = F(s) ? e.accessor(s).node() : Fe(s) ? s.node() : s;
3659
- return A(t, gn);
3676
+ const t = E(s) ? e.accessor(s).node() : Ee(s) ? s.node() : s;
3677
+ return x(t, gn);
3660
3678
  }
3661
3679
  function mn(s, e, t) {
3662
3680
  const o = L.relative(e, t);
@@ -3679,7 +3697,7 @@ function bn(s, e) {
3679
3697
  }
3680
3698
  class Tn {
3681
3699
  constructor(e, t, o, n, r, a, i) {
3682
- d(this, "counter", new S());
3700
+ d(this, "counter", new v());
3683
3701
  d(this, "change", new N());
3684
3702
  d(this, "signalCtl", new AbortController());
3685
3703
  d(this, "error");
@@ -3719,7 +3737,7 @@ class Tn {
3719
3737
  /** Does the download part and keeps a state of the process. */
3720
3738
  async downloadAndDecompress(e) {
3721
3739
  if (this.state = {}, this.state.parentDir = L.dirname(this.path), await ue(this.state.parentDir), this.state.fileExisted = await pe(this.path), this.state.fileExisted)
3722
- return await Qe(this.path);
3740
+ return await Xe(this.path);
3723
3741
  const { content: t, size: o } = await this.clientDownload.downloadBlob(
3724
3742
  this.rInfo,
3725
3743
  {},
@@ -3729,23 +3747,23 @@ class Tn {
3729
3747
  switch (this.state.tempPath = n, this.state.archiveFormat = this.format, this.format) {
3730
3748
  case "tar":
3731
3749
  await m.mkdir(n);
3732
- const r = U.toWeb(ae.extract(n));
3750
+ const r = I.toWeb(ae.extract(n));
3733
3751
  await t.pipeTo(r, { signal: e });
3734
3752
  return;
3735
3753
  case "tgz":
3736
3754
  await m.mkdir(n);
3737
- const a = $e.toWeb(Oe.createGunzip()), i = U.toWeb(ae.extract(n));
3755
+ const a = $e.toWeb(Oe.createGunzip()), i = I.toWeb(ae.extract(n));
3738
3756
  await t.pipeThrough(a, { signal: e }).pipeTo(i, { signal: e });
3739
3757
  return;
3740
3758
  case "zip":
3741
3759
  this.state.zipPath = this.path + ".zip";
3742
- const c = U.toWeb(ie.createWriteStream(this.state.zipPath));
3743
- await t.pipeTo(c, { signal: e }), this.state.zipPathCreated = !0, await mt(this.state.zipPath, n, {
3760
+ const c = I.toWeb(ie.createWriteStream(this.state.zipPath));
3761
+ await t.pipeTo(c, { signal: e }), this.state.zipPathCreated = !0, await wt(this.state.zipPath, n, {
3744
3762
  filter: (l) => !l.path.endsWith("/")
3745
3763
  }), this.state.zipDecompressed = !0, await ie.promises.rm(this.state.zipPath), this.state.zipPathDeleted = !0;
3746
3764
  return;
3747
3765
  default:
3748
- lt(this.format);
3766
+ ct(this.format);
3749
3767
  }
3750
3768
  }), this.state.pathCreated = !0, o;
3751
3769
  }
@@ -3760,30 +3778,30 @@ class Tn {
3760
3778
  this.error = String(e);
3761
3779
  }
3762
3780
  abort(e) {
3763
- this.signalCtl.abort(new Xe(e));
3781
+ this.signalCtl.abort(new Ke(e));
3764
3782
  }
3765
3783
  }
3766
- async function Qe(s) {
3784
+ async function Xe(s) {
3767
3785
  const e = await m.readdir(s, { withFileTypes: !0 });
3768
3786
  return (await Promise.all(
3769
3787
  e.map(async (o) => {
3770
3788
  const n = L.join(s, o.name);
3771
- return o.isDirectory() ? await Qe(n) : (await m.stat(n)).size;
3789
+ return o.isDirectory() ? await Xe(n) : (await m.stat(n)).size;
3772
3790
  })
3773
3791
  )).reduce((o, n) => o + n, 0);
3774
3792
  }
3775
3793
  async function le(s) {
3776
3794
  await m.rm(s, { recursive: !0, force: !0 });
3777
3795
  }
3778
- let Xe = class extends Error {
3796
+ let Ke = class extends Error {
3779
3797
  };
3780
3798
  function kn(s) {
3781
- return s instanceof Xe || s instanceof V || s instanceof be || s instanceof ye || (s == null ? void 0 : s.code) == "ENOENT" || s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED") || String(s).includes("incorrect header check");
3799
+ return s instanceof Ke || s instanceof V || s instanceof be || s instanceof ye || (s == null ? void 0 : s.code) == "ENOENT" || s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED") || String(s).includes("incorrect header check");
3782
3800
  }
3783
3801
  function O(s, e) {
3784
3802
  return `id:${String(BigInt(s))}-${e}`;
3785
3803
  }
3786
- class Lr {
3804
+ class Ur {
3787
3805
  constructor(e, t, o, n, r = {
3788
3806
  cacheSoftSizeBytes: 50 * 1024 * 1024,
3789
3807
  nConcurrentDownloads: 50
@@ -3821,7 +3839,7 @@ class Lr {
3821
3839
  extractArchiveAndGetURL(e, t, o) {
3822
3840
  if (o === void 0)
3823
3841
  return w.make((i) => this.extractArchiveAndGetURL(e, t, i));
3824
- const n = F(e) ? fn(e, o) : e, r = D();
3842
+ const n = E(e) ? fn(e, o) : e, r = D();
3825
3843
  o.addOnDestroy(() => this.releasePath(n.id, t, r));
3826
3844
  const a = this.extractArchiveAndGetURLNoCtx(n, t, o.watcher, r);
3827
3845
  if ((a == null ? void 0 : a.url) === void 0 && o.markUnstable(
@@ -3899,7 +3917,11 @@ class Lr {
3899
3917
  class Ln {
3900
3918
  constructor(e, t, o, n, r, a) {
3901
3919
  d(this, "change", new N());
3902
- d(this, "counter", new S());
3920
+ d(this, "counter", new v());
3921
+ d(this, "nMaxUploads");
3922
+ d(this, "nPartsWithThisUploadSpeed", 0);
3923
+ d(this, "nPartsToIncreaseUpload", 10);
3924
+ // how many parts we have to wait to increase concurrency, 50 mb, 10 parts by 5 mb each.
3903
3925
  /** If this is upload progress this field will be defined */
3904
3926
  d(this, "uploadData");
3905
3927
  d(this, "progress");
@@ -3908,7 +3930,7 @@ class Ln {
3908
3930
  /** True if the blob was existed.
3909
3931
  * At this case, the task will show progress == 1.0. */
3910
3932
  d(this, "alreadyExisted", !1);
3911
- this.logger = e, this.clientBlob = t, this.clientProgress = o, this.nConcurrentPartsUpload = n, this.res = a;
3933
+ this.logger = e, this.clientBlob = t, this.clientProgress = o, this.maxNConcurrentPartsUpload = n, this.res = a, this.nMaxUploads = this.maxNConcurrentPartsUpload;
3912
3934
  const { uploadData: i, progress: c } = Pn(a, r);
3913
3935
  this.uploadData = i, this.progress = c;
3914
3936
  }
@@ -3922,51 +3944,54 @@ class Ln {
3922
3944
  }
3923
3945
  /** Uploads a blob if it's not BlobIndex. */
3924
3946
  async uploadBlobTask() {
3925
- wt(ce(this.res), "the upload operation can be done only for BlobUploads");
3947
+ yt(ce(this.res), "the upload operation can be done only for BlobUploads");
3948
+ const e = 1e4;
3926
3949
  try {
3927
3950
  if (this.isComputableDone()) return;
3928
- const e = await this.clientBlob.initUpload(this.res);
3951
+ const t = await this.clientBlob.initUpload(this.res, { timeout: e });
3929
3952
  this.logger.info(
3930
- `started to upload blob ${this.res.id}, parts overall: ${e.overall}, parts remained: ${e.toUpload.length}`
3953
+ `started to upload blob ${this.res.id}, parts overall: ${t.overall}, parts remained: ${t.toUpload.length}, number of concurrent uploads: ${this.nMaxUploads}`
3931
3954
  );
3932
- const t = (o) => async () => {
3955
+ const o = (n) => async (r) => {
3933
3956
  this.isComputableDone() || (await this.clientBlob.partUpload(
3934
3957
  this.res,
3935
3958
  this.uploadData.localPath,
3936
3959
  BigInt(this.uploadData.modificationTime),
3937
- o
3938
- ), this.logger.info(`uploaded chunk ${o}/${e.overall} of resource: ${this.res.id}`));
3960
+ n,
3961
+ { timeout: e }
3962
+ ), this.logger.info(`uploaded chunk ${n}/${t.overall} of resource: ${this.res.id}`), this.nPartsWithThisUploadSpeed++, this.nPartsWithThisUploadSpeed >= this.nPartsToIncreaseUpload && (this.nPartsWithThisUploadSpeed = 0, this.nMaxUploads = Nn(this.logger, this.nMaxUploads, this.maxNConcurrentPartsUpload), r.setConcurrency(this.nMaxUploads)));
3939
3963
  };
3940
- if (await fe(this.nConcurrentPartsUpload, e.toUpload.map(t)), this.isComputableDone()) return;
3941
- await this.clientBlob.finalize(this.res), this.logger.info(`uploading of resource ${this.res.id} finished.`), this.change.markChanged();
3942
- } catch (e) {
3943
- if (this.setRetriableError(e), Ie(e)) {
3944
- this.logger.warn(`resource was deleted while uploading a blob: ${e}`), this.change.markChanged(), this.setDone(!0);
3964
+ if (await fe(this.nMaxUploads, t.toUpload.map(o)), this.isComputableDone()) return;
3965
+ await this.clientBlob.finalize(this.res, { timeout: e }), this.logger.info(`uploading of resource ${this.res.id} finished.`), this.change.markChanged();
3966
+ } catch (t) {
3967
+ if (this.setRetriableError(t), Re(t)) {
3968
+ this.logger.warn(`resource was deleted while uploading a blob: ${t}`), this.change.markChanged(), this.setDone(!0);
3945
3969
  return;
3946
3970
  }
3947
- if (this.logger.error(`error while uploading a blob: ${e}`), this.change.markChanged(), Ke(e)) {
3948
- this.setTerminalError(e);
3971
+ if (this.logger.error(`error while uploading a blob: ${t}`), this.change.markChanged(), Ye(t)) {
3972
+ this.setTerminalError(t);
3949
3973
  return;
3950
3974
  }
3951
- throw e;
3975
+ throw vn(t) && (this.nMaxUploads = Bn(this.logger, this.nMaxUploads, 1)), t;
3952
3976
  }
3953
3977
  }
3954
3978
  async updateStatus() {
3979
+ var e;
3955
3980
  try {
3956
- const e = await this.clientProgress.getStatus(this.res), t = this.progress.status, o = vn(this.alreadyExisted, Un(e));
3957
- this.progress.status = o, this.setDone(e.done), (e.done || this.progress.status.progress != (t == null ? void 0 : t.progress)) && this.change.markChanged();
3958
- } catch (e) {
3959
- if (this.setRetriableError(e), e.name == "RpcError" && e.code == "DEADLINE_EXCEEDED") {
3981
+ const t = await this.clientProgress.getStatus(this.res, { timeout: 1e4 }), o = this.progress.status, n = Sn(this.alreadyExisted, In(t));
3982
+ this.progress.status = n, this.setDone(t.done), (t.done || this.progress.status.progress != (o == null ? void 0 : o.progress)) && this.change.markChanged();
3983
+ } catch (t) {
3984
+ if (this.setRetriableError(t), t.name == "RpcError" && t.code == "DEADLINE_EXCEEDED" || (e = t == null ? void 0 : t.message) != null && e.includes("DEADLINE_EXCEEDED")) {
3960
3985
  this.logger.warn("deadline exceeded while getting a status of BlobImport");
3961
3986
  return;
3962
3987
  }
3963
- if (Ie(e)) {
3988
+ if (Re(t)) {
3964
3989
  this.logger.warn(
3965
- `resource was not found while updating a status of BlobImport: ${e}, ${y(this.res)}`
3990
+ `resource was not found while updating a status of BlobImport: ${t}, ${y(this.res)}`
3966
3991
  ), this.change.markChanged(), this.setDone(!0);
3967
3992
  return;
3968
3993
  }
3969
- this.logger.error(`error while updating a status of BlobImport: ${e}`), this.change.markChanged(), this.setTerminalError(e);
3994
+ this.logger.error(`retryable error while updating a status of BlobImport: ${t}`);
3970
3995
  }
3971
3996
  }
3972
3997
  /** Set non-terminal error, that task can be retried. */
@@ -3978,7 +4003,7 @@ class Ln {
3978
4003
  this.progress.lastError = String(e), this.progress.done = !1, this.failed = !0;
3979
4004
  }
3980
4005
  setDoneIfOutputSet(e) {
3981
- Rn(e) && (this.setDone(!0), this.alreadyExisted = !0);
4006
+ Un(e) && (this.setDone(!0), this.alreadyExisted = !0);
3982
4007
  }
3983
4008
  setDone(e) {
3984
4009
  this.progress.done = e, e && (this.progress.lastError = void 0);
@@ -3995,7 +4020,7 @@ class Ln {
3995
4020
  }
3996
4021
  function Pn(s, e) {
3997
4022
  let t, o;
3998
- return ce(s) && (o = q.parse(s.data), t = In(e, o.localPath, o.pathSignature)), {
4023
+ return ce(s) && (o = q.parse(s.data), t = Rn(e, o.localPath, o.pathSignature)), {
3999
4024
  uploadData: o,
4000
4025
  progress: {
4001
4026
  done: !1,
@@ -4009,44 +4034,55 @@ function Pn(s, e) {
4009
4034
  function Dn(s) {
4010
4035
  return s.done, s.isUpload, s.isUploadSignMatch, s.lastError, s.status && (s.status.progress, s.status.bytesProcessed, s.status.bytesTotal), s;
4011
4036
  }
4012
- function Rn(s) {
4037
+ function Un(s) {
4013
4038
  return "blob" in s.fields ? s.fields.blob !== void 0 : s.fields.incarnation !== void 0;
4014
4039
  }
4015
4040
  function ce(s) {
4016
4041
  return s.type.name.startsWith("BlobUpload");
4017
4042
  }
4018
- function In(s, e, t) {
4043
+ function Rn(s, e, t) {
4019
4044
  try {
4020
4045
  return s.verify(e, t), !0;
4021
4046
  } catch {
4022
4047
  return !1;
4023
4048
  }
4024
4049
  }
4025
- function Un(s) {
4050
+ function In(s) {
4026
4051
  return {
4027
4052
  progress: s.progress ?? 0,
4028
4053
  bytesProcessed: Number(s.bytesProcessed),
4029
4054
  bytesTotal: Number(s.bytesTotal)
4030
4055
  };
4031
4056
  }
4032
- function vn(s, e) {
4057
+ function Sn(s, e) {
4033
4058
  return s && e.bytesTotal != 0 && e.bytesProcessed == 0 ? {
4034
4059
  progress: 1,
4035
4060
  bytesProcessed: Number(e.bytesTotal),
4036
4061
  bytesTotal: Number(e.bytesTotal)
4037
4062
  } : e;
4038
4063
  }
4039
- function Ie(s) {
4064
+ function Re(s) {
4040
4065
  return s.name == "RpcError" && (s.code == "NOT_FOUND" || s.code == "ABORTED" || s.code == "ALREADY_EXISTS");
4041
4066
  }
4042
- function Ke(s) {
4043
- return s instanceof ze || s instanceof Ae || s instanceof xe;
4067
+ function Ye(s) {
4068
+ return s instanceof ze || s instanceof xe || s instanceof Me;
4044
4069
  }
4045
- function Sn(s, e) {
4046
- const t = F(s) ? e.accessor(s).node() : Fe(s) ? s.node() : s;
4047
- return t.resourceType.name.startsWith("BlobUpload") ? A(t, nn) : A(t, rn);
4070
+ function vn(s) {
4071
+ return s == null ? void 0 : s.message.includes("UND_ERR_HEADERS_TIMEOUT");
4048
4072
  }
4049
- class Pr {
4073
+ function Nn(s, e, t) {
4074
+ const o = Math.min(e + 2, t);
4075
+ return o != e && s.info(`uploadTask.increaseConcurrency: increased from ${e} to ${o}`), o;
4076
+ }
4077
+ function Bn(s, e, t) {
4078
+ const o = Math.max(Math.round(e / 2), t);
4079
+ return o != e && s.info(`uploadTask.decreaseConcurrency: decreased from ${e} to ${o}`), o;
4080
+ }
4081
+ function $n(s, e) {
4082
+ const t = E(s) ? e.accessor(s).node() : Ee(s) ? s.node() : s;
4083
+ return t.resourceType.name.startsWith("BlobUpload") ? x(t, nn) : x(t, rn);
4084
+ }
4085
+ class Rr {
4050
4086
  constructor(e, t, o, n, r = {
4051
4087
  nConcurrentPartUploads: 10,
4052
4088
  nConcurrentGetProgresses: 10,
@@ -4069,7 +4105,7 @@ class Pr {
4069
4105
  // 15 seconds
4070
4106
  backoffMultiplier: 1.5,
4071
4107
  jitter: 0.5
4072
- }), this.hooks = new Ce(
4108
+ }), this.hooks = new _e(
4073
4109
  () => this.startUpdating(),
4074
4110
  () => this.stopUpdating(),
4075
4111
  { stopDebounce: r.stopPollingDelay },
@@ -4078,11 +4114,11 @@ class Pr {
4078
4114
  }
4079
4115
  getProgressId(e, t) {
4080
4116
  if (t == null) return w.make((a) => this.getProgressId(e, a));
4081
- const o = F(e) ? Sn(e, t) : e, n = D();
4117
+ const o = E(e) ? $n(e, t) : e, n = D();
4082
4118
  return t.attacheHooks(this.hooks), t.addOnDestroy(() => this.release(o.id, n)), this.getProgressIdNoCtx(t.watcher, o, n);
4083
4119
  }
4084
4120
  getProgressIdNoCtx(e, t, o) {
4085
- Bn("getProgressId", t.type);
4121
+ _n("getProgressId", t.type);
4086
4122
  const n = this.idToProgress.get(t.id);
4087
4123
  if (n != null)
4088
4124
  return n.setDoneIfOutputSet(t), n.getProgress(e, o);
@@ -4096,7 +4132,7 @@ class Pr {
4096
4132
  );
4097
4133
  return this.idToProgress.set(t.id, r), r.shouldScheduleUpload() && this.uploadQueue.push({
4098
4134
  fn: () => r.uploadBlobTask(),
4099
- recoverableErrorPredicate: (a) => !Ke(a)
4135
+ recoverableErrorPredicate: (a) => !Ye(a)
4100
4136
  }), r.setDoneIfOutputSet(t), r.getProgress(e, o);
4101
4137
  }
4102
4138
  /** Decrement counters for the file and remove an uploading if counter == 0. */
@@ -4133,25 +4169,25 @@ class Pr {
4133
4169
  console.error(t), e.forEach((o) => o.reject(t));
4134
4170
  }
4135
4171
  if (!this.keepRunning) break;
4136
- await Ee.wait(this.opts.pollingInterval);
4172
+ await Fe.wait(this.opts.pollingInterval);
4137
4173
  }
4138
4174
  this.currentLoop = void 0;
4139
4175
  }
4140
4176
  getAllNotDoneProgresses() {
4141
- return Array.from(this.idToProgress.entries()).filter(([e, t]) => !Nn(t.progress)).map(([e, t]) => t);
4177
+ return Array.from(this.idToProgress.entries()).filter(([e, t]) => !Cn(t.progress)).map(([e, t]) => t);
4142
4178
  }
4143
4179
  }
4144
- function Nn(s) {
4180
+ function Cn(s) {
4145
4181
  var e;
4146
4182
  return s.done && (((e = s.status) == null ? void 0 : e.progress) ?? 0) >= 1;
4147
4183
  }
4148
- function Bn(s, e) {
4184
+ function _n(s, e) {
4149
4185
  if (!e.name.startsWith("BlobUpload") && !e.name.startsWith("BlobIndex"))
4150
4186
  throw new Le(
4151
4187
  `${s}: wrong resource type: ${e.name}, expected: a resource of either type 'BlobUpload' or 'BlobIndex'.`
4152
4188
  );
4153
4189
  }
4154
- class Dr {
4190
+ class Ir {
4155
4191
  constructor(e, t, o = {
4156
4192
  nConcurrentGetLogs: 10,
4157
4193
  pollingInterval: 1e3,
@@ -4168,7 +4204,7 @@ class Dr {
4168
4204
  d(this, "keepRunning", !1);
4169
4205
  /** Actual state of main loop. */
4170
4206
  d(this, "currentLoop");
4171
- this.logger = e, this.clientLogs = t, this.opts = o, this.hooks = new Ce(
4207
+ this.logger = e, this.clientLogs = t, this.opts = o, this.hooks = new _e(
4172
4208
  () => this.startUpdating(),
4173
4209
  () => this.stopUpdating(),
4174
4210
  { stopDebounce: o.stopPollingDelay },
@@ -4177,7 +4213,7 @@ class Dr {
4177
4213
  }
4178
4214
  getLastLogs(e, t, o) {
4179
4215
  if (o == null) return w.make((i) => this.getLastLogs(e, t, i));
4180
- const n = I(e, o), r = D();
4216
+ const n = R(e, o), r = D();
4181
4217
  o.attacheHooks(this.hooks), o.addOnDestroy(() => this.releaseLastLogs(n.id, r));
4182
4218
  const a = this.getLastLogsNoCtx(o.watcher, n, t, r);
4183
4219
  return o.markUnstable(
@@ -4188,7 +4224,7 @@ class Dr {
4188
4224
  se("getLastLogs", t.type);
4189
4225
  let r = this.idToLastLines.get(t.id);
4190
4226
  if (r == null) {
4191
- const i = new Ue(this.logger, this.clientLogs, t, o);
4227
+ const i = new Ie(this.logger, this.clientLogs, t, o);
4192
4228
  this.idToLastLines.set(t.id, i), r = i;
4193
4229
  }
4194
4230
  r.attach(e, n);
@@ -4199,7 +4235,7 @@ class Dr {
4199
4235
  getProgressLog(e, t, o) {
4200
4236
  if (o == null)
4201
4237
  return w.make((i) => this.getProgressLog(e, t, i));
4202
- const n = I(e, o), r = D();
4238
+ const n = R(e, o), r = D();
4203
4239
  o.attacheHooks(this.hooks), o.addOnDestroy(() => this.releaseProgressLog(n.id, r));
4204
4240
  const a = this.getProgressLogNoCtx(o.watcher, n, t, r);
4205
4241
  return o.markUnstable(
@@ -4210,7 +4246,7 @@ class Dr {
4210
4246
  se("getProgressLog", t.type);
4211
4247
  let r = this.idToProgressLog.get(t.id);
4212
4248
  if (r == null) {
4213
- const i = new Ue(this.logger, this.clientLogs, t, 1, o);
4249
+ const i = new Ie(this.logger, this.clientLogs, t, 1, o);
4214
4250
  this.idToProgressLog.set(t.id, i), r = i;
4215
4251
  }
4216
4252
  r.attach(e, n);
@@ -4220,11 +4256,11 @@ class Dr {
4220
4256
  }
4221
4257
  getLogHandle(e, t) {
4222
4258
  if (t == null) return w.make((r) => this.getLogHandle(e, r));
4223
- const o = I(e, t), n = this.getLogHandleNoCtx(o);
4224
- return t.markUnstable(`live_log:${it(o.id)}`), n;
4259
+ const o = R(e, t), n = this.getLogHandleNoCtx(o);
4260
+ return t.markUnstable(`live_log:${at(o.id)}`), n;
4225
4261
  }
4226
4262
  getLogHandleNoCtx(e) {
4227
- return se("getLogHandle", e.type), qe(!0, e);
4263
+ return se("getLogHandle", e.type), Je(!0, e);
4228
4264
  }
4229
4265
  async lastLines(e, t, o, n) {
4230
4266
  return await this.tryWithNotFound(
@@ -4249,7 +4285,7 @@ class Dr {
4249
4285
  );
4250
4286
  }
4251
4287
  async tryWithNotFound(e, t) {
4252
- if (!x(e))
4288
+ if (!A(e))
4253
4289
  throw new Error(`Not live log handle was passed to live log driver, handle: ${e}`);
4254
4290
  try {
4255
4291
  const o = await t();
@@ -4301,7 +4337,7 @@ class Dr {
4301
4337
  console.error(t), e.forEach((o) => o.reject(t));
4302
4338
  }
4303
4339
  if (!this.keepRunning) break;
4304
- await Ee.wait(this.opts.pollingInterval);
4340
+ await Fe.wait(this.opts.pollingInterval);
4305
4341
  }
4306
4342
  this.currentLoop = void 0;
4307
4343
  }
@@ -4309,12 +4345,12 @@ class Dr {
4309
4345
  return Array.from(this.idToLastLines.entries()).concat(Array.from(this.idToProgressLog.entries())).map(([e, t]) => t);
4310
4346
  }
4311
4347
  }
4312
- class Ue {
4348
+ class Ie {
4313
4349
  constructor(e, t, o, n, r) {
4314
4350
  d(this, "logs");
4315
4351
  d(this, "error");
4316
4352
  d(this, "change", new N());
4317
- d(this, "counter", new S());
4353
+ d(this, "counter", new v());
4318
4354
  this.logger = e, this.clientLogs = t, this.rInfo = o, this.lines = n, this.patternToSearch = r;
4319
4355
  }
4320
4356
  getLog() {
@@ -4356,7 +4392,7 @@ function se(s, e) {
4356
4392
  `${s}: wrong resource type: ${e.name}, expected: a resource of type 'StreamWorkdir'.`
4357
4393
  );
4358
4394
  }
4359
- class Rr {
4395
+ class Sr {
4360
4396
  constructor(e, t, o) {
4361
4397
  this.logger = e, this.logsStreamDriver = t, this.downloadDriver = o;
4362
4398
  }
@@ -4367,7 +4403,7 @@ class Rr {
4367
4403
  o.markUnstable("no stream in stream manager");
4368
4404
  return;
4369
4405
  }
4370
- if (E(n)) return this.downloadDriver.getLastLogs(n, t, o);
4406
+ if (F(n)) return this.downloadDriver.getLastLogs(n, t, o);
4371
4407
  try {
4372
4408
  return this.logsStreamDriver.getLastLogs(n, t, o);
4373
4409
  } catch (r) {
@@ -4386,7 +4422,7 @@ class Rr {
4386
4422
  o.markUnstable("no stream in stream manager");
4387
4423
  return;
4388
4424
  }
4389
- if (E(n)) return this.downloadDriver.getProgressLog(n, t, o);
4425
+ if (F(n)) return this.downloadDriver.getProgressLog(n, t, o);
4390
4426
  try {
4391
4427
  return this.logsStreamDriver.getProgressLog(n, t, o);
4392
4428
  } catch (r) {
@@ -4405,7 +4441,7 @@ class Rr {
4405
4441
  o.markUnstable("no stream in stream manager");
4406
4442
  return;
4407
4443
  }
4408
- if (E(n))
4444
+ if (F(n))
4409
4445
  return {
4410
4446
  progressLine: this.downloadDriver.getProgressLog(n, t, o),
4411
4447
  live: !1
@@ -4430,23 +4466,23 @@ class Rr {
4430
4466
  t.markUnstable("no stream in stream manager");
4431
4467
  return;
4432
4468
  }
4433
- return E(o) ? this.downloadDriver.getLogHandle(o, t) : this.logsStreamDriver.getLogHandle(o, t);
4469
+ return F(o) ? this.downloadDriver.getLogHandle(o, t) : this.logsStreamDriver.getLogHandle(o, t);
4434
4470
  }
4435
4471
  async lastLines(e, t, o, n) {
4436
- return x(e) ? await this.logsStreamDriver.lastLines(e, t, o, n) : await this.downloadDriver.lastLines(e, t, o, n);
4472
+ return A(e) ? await this.logsStreamDriver.lastLines(e, t, o, n) : await this.downloadDriver.lastLines(e, t, o, n);
4437
4473
  }
4438
4474
  async readText(e, t, o, n) {
4439
- return x(e) ? await this.logsStreamDriver.readText(e, t, o, n) : await this.downloadDriver.readText(e, t, o, n);
4475
+ return A(e) ? await this.logsStreamDriver.readText(e, t, o, n) : await this.downloadDriver.readText(e, t, o, n);
4440
4476
  }
4441
4477
  }
4442
- function E(s) {
4478
+ function F(s) {
4443
4479
  return !s.type.name.startsWith("StreamWorkdir");
4444
4480
  }
4445
4481
  function W(s, e) {
4446
4482
  var t;
4447
4483
  return (t = s.accessor(e).node().traverse("stream")) == null ? void 0 : t.resourceInfo;
4448
4484
  }
4449
- class Ir {
4485
+ class vr {
4450
4486
  constructor(e, t, o, n = {
4451
4487
  cacheSoftSizeBytes: 50 * 1024 * 1024,
4452
4488
  withGunzip: !0,
@@ -4458,7 +4494,7 @@ class Ir {
4458
4494
  /** Writes and removes files to a hard drive and holds a counter for every
4459
4495
  * file that should be kept. */
4460
4496
  d(this, "cache");
4461
- this.logger = e, this.saveDir = o, this.opts = n, this.downloadQueue = new j(this.logger, this.opts.nConcurrentDownloads), this.cache = new ke(this.opts.cacheSoftSizeBytes), this.downloadHelper = new Me(t);
4497
+ this.logger = e, this.saveDir = o, this.opts = n, this.downloadQueue = new j(this.logger, this.opts.nConcurrentDownloads), this.cache = new ke(this.opts.cacheSoftSizeBytes), this.downloadHelper = new He(t);
4462
4498
  }
4463
4499
  getPath(e, t) {
4464
4500
  if (t === void 0) return w.make((r) => this.getPath(e, r));
@@ -4517,20 +4553,20 @@ class Ir {
4517
4553
  );
4518
4554
  }
4519
4555
  setNewTask(e, t, o) {
4520
- const n = new $n(this.logger, this.getFilePath(t), t);
4556
+ const n = new En(this.logger, this.getFilePath(t), t);
4521
4557
  return n.attach(e, o), this.urlToDownload.set(t.toString(), n), n;
4522
4558
  }
4523
4559
  removeTask(e, t) {
4524
4560
  e.abort(t), e.change.markChanged(), this.urlToDownload.delete(e.url.toString());
4525
4561
  }
4526
4562
  getFilePath(e) {
4527
- const t = pt("sha256").update(e.toString()).digest("hex");
4563
+ const t = gt("sha256").update(e.toString()).digest("hex");
4528
4564
  return b.join(this.saveDir, t);
4529
4565
  }
4530
4566
  }
4531
- class $n {
4567
+ class En {
4532
4568
  constructor(e, t, o) {
4533
- d(this, "counter", new S());
4569
+ d(this, "counter", new v());
4534
4570
  d(this, "change", new N());
4535
4571
  d(this, "signalCtl", new AbortController());
4536
4572
  d(this, "error");
@@ -4555,7 +4591,7 @@ class $n {
4555
4591
  const o = await this.downloadAndUntar(e, t, this.signalCtl.signal);
4556
4592
  this.setDone(o), this.change.markChanged();
4557
4593
  } catch (o) {
4558
- if (o instanceof ve || o instanceof V) {
4594
+ if (o instanceof Se || o instanceof V) {
4559
4595
  this.setError(o), this.change.markChanged(), await de(this.path);
4560
4596
  return;
4561
4597
  }
@@ -4564,7 +4600,7 @@ class $n {
4564
4600
  }
4565
4601
  async downloadAndUntar(e, t, o) {
4566
4602
  if (await ue(b.dirname(this.path)), await pe(this.path))
4567
- return await Ye(this.path);
4603
+ return await et(this.path);
4568
4604
  const n = await e.download(this.url.toString(), {}, o);
4569
4605
  let r = n.content;
4570
4606
  if (t) {
@@ -4573,7 +4609,7 @@ class $n {
4573
4609
  }
4574
4610
  return await ge(this.logger, this.path, async (a) => {
4575
4611
  await m.mkdir(a);
4576
- const i = U.toWeb(ae.extract(a));
4612
+ const i = I.toWeb(ae.extract(a));
4577
4613
  await r.pipeTo(i, { signal: o });
4578
4614
  }), n.size;
4579
4615
  }
@@ -4588,30 +4624,30 @@ class $n {
4588
4624
  this.error = String(e);
4589
4625
  }
4590
4626
  abort(e) {
4591
- this.signalCtl.abort(new ve(e));
4627
+ this.signalCtl.abort(new Se(e));
4592
4628
  }
4593
4629
  }
4594
- class ve extends Error {
4630
+ class Se extends Error {
4595
4631
  }
4596
- async function Ye(s) {
4632
+ async function et(s) {
4597
4633
  const e = await m.readdir(s, { withFileTypes: !0 });
4598
4634
  return (await Promise.all(
4599
4635
  e.map(async (o) => {
4600
4636
  const n = b.join(s, o.name);
4601
- return o.isDirectory() ? await Ye(n) : (await m.stat(n)).size;
4637
+ return o.isDirectory() ? await et(n) : (await m.stat(n)).size;
4602
4638
  })
4603
4639
  )).reduce((o, n) => o + n, 0);
4604
4640
  }
4605
4641
  async function de(s) {
4606
4642
  await m.rm(s, { recursive: !0, force: !0 });
4607
4643
  }
4608
- function Se(s, e) {
4644
+ function ve(s, e) {
4609
4645
  return `index://index/${encodeURIComponent(JSON.stringify({
4610
4646
  storageId: s,
4611
4647
  path: e
4612
4648
  }))}`;
4613
4649
  }
4614
- function _n(s, e, t, o) {
4650
+ function On(s, e, t, o) {
4615
4651
  const n = {
4616
4652
  localPath: s,
4617
4653
  pathSignature: e.sign(s),
@@ -4620,32 +4656,32 @@ function _n(s, e, t, o) {
4620
4656
  };
4621
4657
  return `upload://upload/${encodeURIComponent(JSON.stringify(n))}`;
4622
4658
  }
4623
- function Cn(s) {
4659
+ function Fn(s) {
4624
4660
  const e = new URL(s);
4625
4661
  return q.parse(
4626
4662
  JSON.parse(decodeURIComponent(e.pathname.substring(1)))
4627
4663
  );
4628
4664
  }
4629
- function Fn(s) {
4665
+ function Wn(s) {
4630
4666
  const e = new URL(s);
4631
- return Ge.parse(JSON.parse(decodeURIComponent(e.pathname.substring(1))));
4667
+ return Ve.parse(JSON.parse(decodeURIComponent(e.pathname.substring(1))));
4632
4668
  }
4633
- function On(s) {
4634
- if (An(s))
4669
+ function zn(s) {
4670
+ if (Hn(s))
4671
+ return Gn(s);
4672
+ if (xn(s))
4635
4673
  return Mn(s);
4636
- if (En(s))
4637
- return zn(s);
4638
- dt(s);
4674
+ ht(s);
4639
4675
  }
4640
- const et = /^local:\/\/(?<name>.*)\/(?<path>.*)$/;
4641
- function En(s) {
4642
- return et.test(s);
4676
+ const tt = /^local:\/\/(?<name>.*)\/(?<path>.*)$/;
4677
+ function xn(s) {
4678
+ return tt.test(s);
4643
4679
  }
4644
- function Wn(s, e) {
4680
+ function An(s, e) {
4645
4681
  return `local://${s}/${encodeURIComponent(e)}`;
4646
4682
  }
4647
- function zn(s) {
4648
- const e = s.match(et);
4683
+ function Mn(s) {
4684
+ const e = s.match(tt);
4649
4685
  if (e == null) throw new Error(`Local list handle wasn't parsed: ${s}`);
4650
4686
  const { name: t, path: o } = e.groups;
4651
4687
  return {
@@ -4654,29 +4690,29 @@ function zn(s) {
4654
4690
  isRemote: !1
4655
4691
  };
4656
4692
  }
4657
- const tt = /^remote:\/\/(?<name>.*)\/(?<resourceId>.*)$/;
4658
- function An(s) {
4659
- return tt.test(s);
4693
+ const ot = /^remote:\/\/(?<name>.*)\/(?<resourceId>.*)$/;
4694
+ function Hn(s) {
4695
+ return ot.test(s);
4660
4696
  }
4661
- function xn(s, e) {
4697
+ function jn(s, e) {
4662
4698
  return `remote://${s}/${BigInt(e)}`;
4663
4699
  }
4664
- function Mn(s) {
4665
- const e = s.match(tt);
4700
+ function Gn(s) {
4701
+ const e = s.match(ot);
4666
4702
  if (e == null) throw new Error(`Remote list handle wasn't parsed: ${s}`);
4667
4703
  const { name: t, resourceId: o } = e.groups;
4668
4704
  return {
4669
4705
  id: he(BigInt(o)),
4670
- type: Hn(t),
4706
+ type: Vn(t),
4671
4707
  name: t,
4672
4708
  isRemote: !0
4673
4709
  };
4674
4710
  }
4675
- function Hn(s) {
4711
+ function Vn(s) {
4676
4712
  return { name: `LS/${s}`, version: "1" };
4677
4713
  }
4678
- async function jn() {
4679
- const s = gt.homedir();
4714
+ async function qn() {
4715
+ const s = ft.homedir();
4680
4716
  if (L.sep == "/")
4681
4717
  return [
4682
4718
  {
@@ -4688,7 +4724,7 @@ async function jn() {
4688
4724
  {
4689
4725
  const t = L.parse(s).root.replaceAll(":\\", "");
4690
4726
  try {
4691
- return (await bt.promisify(Tt)("wmic logicaldisk get name")).stdout.split(`\r
4727
+ return (await Tt.promisify(kt)("wmic logicaldisk get name")).stdout.split(`\r
4692
4728
  `).filter((r) => r.includes(":")).map((r) => r.trim().replaceAll(":", "")).map((r) => {
4693
4729
  const a = r == t;
4694
4730
  return {
@@ -4708,7 +4744,7 @@ async function jn() {
4708
4744
  }
4709
4745
  }
4710
4746
  }
4711
- class ot {
4747
+ class nt {
4712
4748
  constructor(e, t, o, n, r, a, i) {
4713
4749
  this.logger = e, this.lsClient = t, this.storageIdToResourceId = o, this.signer = n, this.virtualStoragesMap = r, this.localProjectionsMap = a, this.openFileDialogCallback = i;
4714
4750
  }
@@ -4740,13 +4776,13 @@ class ot {
4740
4776
  * @private
4741
4777
  */
4742
4778
  async tryResolveLocalFileHandle(e) {
4743
- if (yt(e)) {
4744
- const t = Fn(e), o = this.localProjectionsMap.get(t.storageId);
4779
+ if (bt(e)) {
4780
+ const t = Wn(e), o = this.localProjectionsMap.get(t.storageId);
4745
4781
  if (!o)
4746
4782
  throw new Error(`Storage ${t.storageId} is not mounted locally.`);
4747
4783
  return b.join(o.localPath, t.path);
4748
4784
  } else {
4749
- const t = Cn(e);
4785
+ const t = Fn(e);
4750
4786
  this.signer.verify(
4751
4787
  t.localPath,
4752
4788
  t.pathSignature,
@@ -4759,17 +4795,17 @@ class ot {
4759
4795
  }
4760
4796
  }
4761
4797
  async getLocalFileHandle(e) {
4762
- _(e);
4798
+ C(e);
4763
4799
  for (const o of this.localProjectionsMap.values())
4764
4800
  if (e.startsWith(o.localPath)) {
4765
4801
  const n = o.localPath === "" ? e : b.relative(o.localPath, e);
4766
- return Se(
4802
+ return ve(
4767
4803
  o.storageId,
4768
4804
  n
4769
4805
  );
4770
4806
  }
4771
4807
  const t = await m.stat(e, { bigint: !0 });
4772
- return _n(
4808
+ return On(
4773
4809
  e,
4774
4810
  this.signer,
4775
4811
  t.size,
@@ -4780,12 +4816,12 @@ class ot {
4780
4816
  async getStorageList() {
4781
4817
  const e = [...this.virtualStoragesMap.values()].map((n) => ({
4782
4818
  name: n.name,
4783
- handle: Wn(n.name, n.root),
4819
+ handle: An(n.name, n.root),
4784
4820
  initialFullPath: n.initialPath
4785
4821
  })), o = Object.entries(this.storageIdToResourceId).map(
4786
4822
  ([n, r]) => ({
4787
4823
  name: n,
4788
- handle: xn(n, r),
4824
+ handle: jn(n, r),
4789
4825
  initialFullPath: "",
4790
4826
  // we don't have any additional information from where to start browsing remote storages
4791
4827
  isInitialPathHome: !1
@@ -4794,17 +4830,17 @@ class ot {
4794
4830
  return [...e, ...o];
4795
4831
  }
4796
4832
  async listFiles(e, t) {
4797
- const o = On(e);
4833
+ const o = zn(e);
4798
4834
  if (o.isRemote)
4799
4835
  return {
4800
4836
  entries: (await this.lsClient.list(o, t)).items.map((i) => ({
4801
4837
  type: i.isDir ? "dir" : "file",
4802
4838
  name: i.name,
4803
4839
  fullPath: i.fullName,
4804
- handle: Se(o.name, i.fullName)
4840
+ handle: ve(o.name, i.fullName)
4805
4841
  }))
4806
4842
  };
4807
- b.sep === "/" && t === "" && (t = "/"), o.rootPath === "" && _(t);
4843
+ b.sep === "/" && t === "" && (t = "/"), o.rootPath === "" && C(t);
4808
4844
  const n = b.isAbsolute(t) ? t : b.join(o.rootPath, t), r = [];
4809
4845
  for await (const a of await m.opendir(n)) {
4810
4846
  if (!a.isFile() && !a.isDirectory()) continue;
@@ -4825,18 +4861,18 @@ class ot {
4825
4861
  }
4826
4862
  static async init(e, t, o, n, r, a) {
4827
4863
  const i = Xo(t, e);
4828
- a || (a = await jn());
4829
- for (const p of a) _(p.root);
4830
- for (const p of n) p.localPath !== "" && _(p.localPath);
4864
+ a || (a = await qn());
4865
+ for (const p of a) C(p.root);
4866
+ for (const p of n) p.localPath !== "" && C(p.localPath);
4831
4867
  const c = new Map(a.map((p) => [p.name, p])), l = new Map(n.map((p) => [p.storageId, p]));
4832
4868
  if ((/* @__PURE__ */ new Set([...c.keys(), ...l.keys()])).size !== c.size + l.size)
4833
4869
  throw new Error(
4834
4870
  "Intersection between local projection storage ids and virtual storages names detected."
4835
4871
  );
4836
- return new ot(
4872
+ return new nt(
4837
4873
  e,
4838
4874
  i,
4839
- await Gn(t),
4875
+ await Jn(t),
4840
4876
  o,
4841
4877
  c,
4842
4878
  l,
@@ -4844,15 +4880,15 @@ class ot {
4844
4880
  );
4845
4881
  }
4846
4882
  }
4847
- async function Gn(s) {
4883
+ async function Jn(s) {
4848
4884
  return s.withReadTx("GetAvailableStorageIds", async (e) => {
4849
4885
  const t = await e.getResourceByName("LSProvider"), o = await e.getResourceData(t, !0);
4850
- return Vn(o);
4886
+ return Zn(o);
4851
4887
  });
4852
4888
  }
4853
- function Vn(s) {
4889
+ function Zn(s) {
4854
4890
  return Object.fromEntries(
4855
- s.fields.filter((e) => e.type == "Dynamic" && at(e.value)).map((e) => [e.name.substring(8), e.value])
4891
+ s.fields.filter((e) => e.type == "Dynamic" && lt(e.value)).map((e) => [e.name.substring(8), e.value])
4856
4892
  );
4857
4893
  }
4858
4894
  export {
@@ -4861,40 +4897,40 @@ export {
4861
4897
  Oo as ClientLs,
4862
4898
  ho as ClientProgress,
4863
4899
  Gt as ClientUpload,
4864
- jn as DefaultVirtualLocalStorages,
4865
- Lr as DownloadBlobToURLDriver,
4866
- Tr as DownloadDriver,
4867
- Ir as DownloadUrlDriver,
4900
+ qn as DefaultVirtualLocalStorages,
4901
+ Ur as DownloadBlobToURLDriver,
4902
+ Pr as DownloadDriver,
4903
+ vr as DownloadUrlDriver,
4868
4904
  gn as DownloadableBlobSnapshot,
4869
- br as ImportFileHandleData,
4870
- Ge as ImportFileHandleIndexData,
4905
+ Lr as ImportFileHandleData,
4906
+ Ve as ImportFileHandleIndexData,
4871
4907
  q as ImportFileHandleUploadData,
4872
4908
  rn as IndexResourceSnapshot,
4873
- Rr as LogsDriver,
4874
- Dr as LogsStreamDriver,
4875
- ot as LsDriver,
4909
+ Sr as LogsDriver,
4910
+ Ir as LogsStreamDriver,
4911
+ nt as LsDriver,
4876
4912
  ze as MTimeError,
4877
- jt as NetworkError,
4878
- xe as NoFileForUploading,
4913
+ Ae as NetworkError,
4914
+ Me as NoFileForUploading,
4879
4915
  tn as OnDemandBlobResourceSnapshot,
4880
- Ae as UnexpectedEOF,
4916
+ xe as UnexpectedEOF,
4881
4917
  be as UnknownStorageError,
4882
4918
  dn as Updater,
4883
- Pr as UploadDriver,
4919
+ Rr as UploadDriver,
4884
4920
  nn as UploadResourceSnapshot,
4885
4921
  ye as WrongLocalFileUrl,
4886
4922
  Le as WrongResourceTypeError,
4887
- fr as createDownloadClient,
4888
- mr as createLogsClient,
4923
+ yr as createDownloadClient,
4924
+ br as createLogsClient,
4889
4925
  Xo as createLsFilesClient,
4890
- yr as createUploadBlobClient,
4891
- wr as createUploadProgressClient,
4926
+ kr as createUploadBlobClient,
4927
+ Tr as createUploadProgressClient,
4892
4928
  Po as getFullPath,
4893
4929
  on as getSize,
4894
- Sn as makeBlobImportSnapshot,
4930
+ $n as makeBlobImportSnapshot,
4895
4931
  fn as makeDownloadableBlobSnapshot,
4896
- Io as newLocalStorageIdsToRoot,
4932
+ Ro as newLocalStorageIdsToRoot,
4897
4933
  Lo as parseLocalUrl,
4898
- _ as validateAbsolute
4934
+ C as validateAbsolute
4899
4935
  };
4900
4936
  //# sourceMappingURL=index.mjs.map