@milaboratories/pl-drivers 1.5.17 → 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
@@ -5,7 +5,7 @@ import { addRTypeToMetadata as P, bigintToResourceId as he, stringifyWithResourc
5
5
  import * as m from "node:fs/promises";
6
6
  import { request as Ne } from "undici";
7
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 D, typeofJsonValue as Be, assertNever as ct } from "@protobuf-ts/runtime";
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
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";
@@ -16,8 +16,8 @@ import { text as ut, buffer as Ce } from "node:stream/consumers";
16
16
  import { ChangeSource as N, Computable as w, PollingComputableHooks as _e } from "@milaboratories/computable";
17
17
  import { rsSchema as G, treeEntryToResourceInfo as R, isPlTreeEntry as E, makeResourceSnapshot as x, isPlTreeEntryAccessor as Ee } from "@milaboratories/pl-tree";
18
18
  import pt from "denque";
19
- import { randomUUID as U, createHash as gt } from "node:crypto";
20
- import * as Ue from "node:os";
19
+ import { randomUUID as D, createHash as gt } from "node:crypto";
20
+ import * as De from "node:os";
21
21
  import ft from "node:os";
22
22
  import * as mt from "node:readline/promises";
23
23
  import { z as k } from "zod";
@@ -71,7 +71,7 @@ class Pt extends g {
71
71
  }
72
72
  }
73
73
  new Pt();
74
- class Ut extends g {
74
+ class Dt extends g {
75
75
  constructor() {
76
76
  super("MiLaboratories.Controller.Shared.uploadapi.Init.Request", [
77
77
  {
@@ -125,7 +125,7 @@ class Ut extends g {
125
125
  ), t;
126
126
  }
127
127
  }
128
- const Dt = new Ut();
128
+ const Ut = new Dt();
129
129
  class Rt extends g {
130
130
  constructor() {
131
131
  super("MiLaboratories.Controller.Shared.uploadapi.Init.Response", [
@@ -716,7 +716,7 @@ const Ht = new Mt(), Q = new _(
716
716
  {
717
717
  name: "Init",
718
718
  options: {},
719
- I: Dt,
719
+ I: Ut,
720
720
  O: It
721
721
  },
722
722
  {
@@ -952,7 +952,7 @@ class Qt extends g {
952
952
  * Encode `Duration` to JSON string like "3.000001s".
953
953
  */
954
954
  internalJsonWrite(e, t) {
955
- const o = D.from(e.seconds).toNumber();
955
+ const o = U.from(e.seconds).toNumber();
956
956
  if (o > 315576e6 || o < -315576e6)
957
957
  throw new Error("Duration value out of range.");
958
958
  let n = e.seconds.toString();
@@ -976,7 +976,7 @@ class Qt extends g {
976
976
  "Unable to parse Duration from JSON string. Invalid format."
977
977
  );
978
978
  o || (o = this.create());
979
- const [, r, a, i] = n, c = D.from(r + a);
979
+ const [, r, a, i] = n, c = U.from(r + a);
980
980
  if (c.toNumber() > 315576e6 || c.toNumber() < -315576e6)
981
981
  throw new Error(
982
982
  "Unable to parse Duration from JSON string. Value out of range."
@@ -1868,7 +1868,7 @@ class ko {
1868
1868
  }
1869
1869
  async downloadBlob(e, t, o) {
1870
1870
  const { downloadUrl: n, headers: r } = await this.grpcGetDownloadUrl(e, t, o);
1871
- return this.logger.info(`download blob from url ${n}`), Do(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);
1872
1872
  }
1873
1873
  async readLocalFile(e) {
1874
1874
  const { storageId: t, relativePath: o } = Lo(e), n = Po(t, this.localStorageIdsToRoot, o);
@@ -1899,9 +1899,9 @@ function Po(s, e, t) {
1899
1899
  if (o === void 0) throw new be(`Unknown storage location: ${s}`);
1900
1900
  return o === "" ? t : b.join(o, t);
1901
1901
  }
1902
- const Uo = "storage://";
1903
- function Do(s) {
1904
- return s.startsWith(Uo);
1902
+ const Do = "storage://";
1903
+ function Uo(s) {
1904
+ return s.startsWith(Do);
1905
1905
  }
1906
1906
  class ye extends Error {
1907
1907
  }
@@ -1938,14 +1938,14 @@ class Io extends g {
1938
1938
  */
1939
1939
  now() {
1940
1940
  const e = this.create(), t = Date.now();
1941
- return e.seconds = D.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;
1942
1942
  }
1943
1943
  /**
1944
1944
  * Converts a `Timestamp` to a JavaScript Date.
1945
1945
  */
1946
1946
  toDate(e) {
1947
1947
  return new Date(
1948
- D.from(e.seconds).toNumber() * 1e3 + Math.ceil(e.nanos / 1e6)
1948
+ U.from(e.seconds).toNumber() * 1e3 + Math.ceil(e.nanos / 1e6)
1949
1949
  );
1950
1950
  }
1951
1951
  /**
@@ -1953,14 +1953,14 @@ class Io extends g {
1953
1953
  */
1954
1954
  fromDate(e) {
1955
1955
  const t = this.create(), o = e.getTime();
1956
- return t.seconds = D.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;
1957
1957
  }
1958
1958
  /**
1959
1959
  * In JSON format, the `Timestamp` type is encoded as a string
1960
1960
  * in the RFC 3339 format.
1961
1961
  */
1962
1962
  internalJsonWrite(e, t) {
1963
- const o = D.from(e.seconds).toNumber() * 1e3;
1963
+ const o = U.from(e.seconds).toNumber() * 1e3;
1964
1964
  if (o < Date.parse("0001-01-01T00:00:00Z") || o > Date.parse("9999-12-31T23:59:59Z"))
1965
1965
  throw new Error(
1966
1966
  "Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."
@@ -1999,7 +1999,7 @@ class Io extends g {
1999
1999
  throw new globalThis.Error(
2000
2000
  "Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."
2001
2001
  );
2002
- return o || (o = this.create()), o.seconds = D.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;
2003
2003
  }
2004
2004
  create(e) {
2005
2005
  const t = globalThis.Object.create(this.messagePrototype);
@@ -3413,7 +3413,7 @@ class Pr {
3413
3413
  }
3414
3414
  getDownloadedBlob(e, t) {
3415
3415
  if (t === void 0) return w.make((a) => this.getDownloadedBlob(e, a));
3416
- const o = R(e, t), n = U();
3416
+ const o = R(e, t), n = D();
3417
3417
  t.addOnDestroy(() => this.releaseBlob(o.id, n));
3418
3418
  const r = this.getDownloadedBlobNoCtx(t.watcher, o, n);
3419
3419
  return r == null && t.markUnstable("download blob is still undefined"), r;
@@ -3452,7 +3452,7 @@ class Pr {
3452
3452
  }
3453
3453
  getOnDemandBlob(e, t) {
3454
3454
  if (t === void 0) return w.make((a) => this.getOnDemandBlob(e, a));
3455
- const o = E(e) ? x(e, tn, t) : e, n = U();
3455
+ const o = E(e) ? x(e, tn, t) : e, n = D();
3456
3456
  return t.addOnDestroy(() => this.releaseOnDemandBlob(o.id, n)), this.getOnDemandBlobNoCtx(o, n);
3457
3457
  }
3458
3458
  getOnDemandBlobNoCtx(e, t) {
@@ -3475,9 +3475,21 @@ class Pr {
3475
3475
  }
3476
3476
  throw new Error("Malformed remote handle");
3477
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
+ }
3478
3490
  getLastLogs(e, t, o) {
3479
3491
  if (o == null) return w.make((i) => this.getLastLogs(e, t, i));
3480
- const n = R(e, o), r = U();
3492
+ const n = R(e, o), r = D();
3481
3493
  o.addOnDestroy(() => this.releaseBlob(n.id, r));
3482
3494
  const a = this.getLastLogsNoCtx(o.watcher, n, t, r);
3483
3495
  return a == null && o.markUnstable("either a file was not downloaded or logs was not read"), a;
@@ -3489,7 +3501,7 @@ class Pr {
3489
3501
  const { path: a } = re(r.handle, this.signer);
3490
3502
  let i = this.idToLastLines.get(t.id);
3491
3503
  if (i == null) {
3492
- const l = new De(a, o);
3504
+ const l = new Ue(a, o);
3493
3505
  this.idToLastLines.set(t.id, l), i = l;
3494
3506
  }
3495
3507
  const c = i.getOrSchedule(e);
@@ -3499,7 +3511,7 @@ class Pr {
3499
3511
  getProgressLog(e, t, o) {
3500
3512
  if (o == null)
3501
3513
  return w.make((i) => this.getProgressLog(e, t, i));
3502
- const n = R(e, o), r = U();
3514
+ const n = R(e, o), r = D();
3503
3515
  o.addOnDestroy(() => this.releaseBlob(n.id, r));
3504
3516
  const a = this.getProgressLogNoCtx(
3505
3517
  o.watcher,
@@ -3516,7 +3528,7 @@ class Pr {
3516
3528
  const { path: a } = re(r.handle, this.signer);
3517
3529
  let i = this.idToProgressLog.get(t.id);
3518
3530
  if (i == null) {
3519
- const l = new De(a, 1, o);
3531
+ const l = new Ue(a, 1, o);
3520
3532
  this.idToProgressLog.set(t.id, l), i = l;
3521
3533
  }
3522
3534
  const c = i.getOrSchedule(e);
@@ -3612,7 +3624,7 @@ class hn {
3612
3624
  return this.counter.dec(e);
3613
3625
  }
3614
3626
  }
3615
- class De {
3627
+ class Ue {
3616
3628
  constructor(e, t, o) {
3617
3629
  d(this, "updater");
3618
3630
  d(this, "log");
@@ -3646,7 +3658,7 @@ function un(s, e, t) {
3646
3658
  i.on("line", function(l) {
3647
3659
  t != null && !l.includes(t) || (c.push(l), c.length > e && c.shift());
3648
3660
  }), i.on("error", a), i.on("close", function() {
3649
- r(c.toArray().join(Ue.EOL) + Ue.EOL);
3661
+ r(c.toArray().join(De.EOL) + De.EOL);
3650
3662
  });
3651
3663
  });
3652
3664
  }
@@ -3789,7 +3801,7 @@ function kn(s) {
3789
3801
  function O(s, e) {
3790
3802
  return `id:${String(BigInt(s))}-${e}`;
3791
3803
  }
3792
- class Dr {
3804
+ class Ur {
3793
3805
  constructor(e, t, o, n, r = {
3794
3806
  cacheSoftSizeBytes: 50 * 1024 * 1024,
3795
3807
  nConcurrentDownloads: 50
@@ -3827,7 +3839,7 @@ class Dr {
3827
3839
  extractArchiveAndGetURL(e, t, o) {
3828
3840
  if (o === void 0)
3829
3841
  return w.make((i) => this.extractArchiveAndGetURL(e, t, i));
3830
- const n = E(e) ? fn(e, o) : e, r = U();
3842
+ const n = E(e) ? fn(e, o) : e, r = D();
3831
3843
  o.addOnDestroy(() => this.releasePath(n.id, t, r));
3832
3844
  const a = this.extractArchiveAndGetURLNoCtx(n, t, o.watcher, r);
3833
3845
  if ((a == null ? void 0 : a.url) === void 0 && o.markUnstable(
@@ -3925,7 +3937,7 @@ class Ln {
3925
3937
  getProgress(e, t) {
3926
3938
  if (this.incCounter(e, t), this.failed)
3927
3939
  throw this.logger.error(`Uploading terminally failed: ${this.progress.lastError}`), new Error(this.progress.lastError);
3928
- return Un(this.progress);
3940
+ return Dn(this.progress);
3929
3941
  }
3930
3942
  shouldScheduleUpload() {
3931
3943
  return this.progress.isUpload && this.progress.isUploadSignMatch;
@@ -3991,7 +4003,7 @@ class Ln {
3991
4003
  this.progress.lastError = String(e), this.progress.done = !1, this.failed = !0;
3992
4004
  }
3993
4005
  setDoneIfOutputSet(e) {
3994
- Dn(e) && (this.setDone(!0), this.alreadyExisted = !0);
4006
+ Un(e) && (this.setDone(!0), this.alreadyExisted = !0);
3995
4007
  }
3996
4008
  setDone(e) {
3997
4009
  this.progress.done = e, e && (this.progress.lastError = void 0);
@@ -4019,10 +4031,10 @@ function Pn(s, e) {
4019
4031
  }
4020
4032
  };
4021
4033
  }
4022
- function Un(s) {
4034
+ function Dn(s) {
4023
4035
  return s.done, s.isUpload, s.isUploadSignMatch, s.lastError, s.status && (s.status.progress, s.status.bytesProcessed, s.status.bytesTotal), s;
4024
4036
  }
4025
- function Dn(s) {
4037
+ function Un(s) {
4026
4038
  return "blob" in s.fields ? s.fields.blob !== void 0 : s.fields.incarnation !== void 0;
4027
4039
  }
4028
4040
  function ce(s) {
@@ -4102,7 +4114,7 @@ class Rr {
4102
4114
  }
4103
4115
  getProgressId(e, t) {
4104
4116
  if (t == null) return w.make((a) => this.getProgressId(e, a));
4105
- const o = E(e) ? $n(e, t) : e, n = U();
4117
+ const o = E(e) ? $n(e, t) : e, n = D();
4106
4118
  return t.attacheHooks(this.hooks), t.addOnDestroy(() => this.release(o.id, n)), this.getProgressIdNoCtx(t.watcher, o, n);
4107
4119
  }
4108
4120
  getProgressIdNoCtx(e, t, o) {
@@ -4201,7 +4213,7 @@ class Ir {
4201
4213
  }
4202
4214
  getLastLogs(e, t, o) {
4203
4215
  if (o == null) return w.make((i) => this.getLastLogs(e, t, i));
4204
- const n = R(e, o), r = U();
4216
+ const n = R(e, o), r = D();
4205
4217
  o.attacheHooks(this.hooks), o.addOnDestroy(() => this.releaseLastLogs(n.id, r));
4206
4218
  const a = this.getLastLogsNoCtx(o.watcher, n, t, r);
4207
4219
  return o.markUnstable(
@@ -4223,7 +4235,7 @@ class Ir {
4223
4235
  getProgressLog(e, t, o) {
4224
4236
  if (o == null)
4225
4237
  return w.make((i) => this.getProgressLog(e, t, i));
4226
- const n = R(e, o), r = U();
4238
+ const n = R(e, o), r = D();
4227
4239
  o.attacheHooks(this.hooks), o.addOnDestroy(() => this.releaseProgressLog(n.id, r));
4228
4240
  const a = this.getProgressLogNoCtx(o.watcher, n, t, r);
4229
4241
  return o.markUnstable(
@@ -4486,7 +4498,7 @@ class vr {
4486
4498
  }
4487
4499
  getPath(e, t) {
4488
4500
  if (t === void 0) return w.make((r) => this.getPath(e, r));
4489
- const o = U();
4501
+ const o = D();
4490
4502
  t.addOnDestroy(() => this.releasePath(e, o));
4491
4503
  const n = this.getPathNoCtx(e, t.watcher, o);
4492
4504
  return (n == null ? void 0 : n.path) === void 0 && t.markUnstable(
@@ -4886,7 +4898,7 @@ export {
4886
4898
  ho as ClientProgress,
4887
4899
  Gt as ClientUpload,
4888
4900
  qn as DefaultVirtualLocalStorages,
4889
- Dr as DownloadBlobToURLDriver,
4901
+ Ur as DownloadBlobToURLDriver,
4890
4902
  Pr as DownloadDriver,
4891
4903
  vr as DownloadUrlDriver,
4892
4904
  gn as DownloadableBlobSnapshot,