@platforma-sdk/bootstrap 2.7.2 → 2.8.1

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,8 +5,8 @@ import { Flags as y, Command as E } from "@oclif/core";
5
5
  import L from "node:os";
6
6
  import d, { createWriteStream as cr } from "node:fs";
7
7
  import o, { resolve as nr } from "node:path";
8
- import { execSync as Ge, spawn as lr, spawnSync as q } from "node:child_process";
9
- import z from "winston";
8
+ import { execSync as Ge, spawn as lr, spawnSync as K } from "node:child_process";
9
+ import Q from "winston";
10
10
  import { randomBytes as or } from "node:crypto";
11
11
  import M from "readline-sync";
12
12
  import * as T from "node:fs/promises";
@@ -153,22 +153,25 @@ const ye = {
153
153
  function wr(a) {
154
154
  return M.question(`${a} [y/N] `).toLowerCase() === "y";
155
155
  }
156
- function V(a) {
156
+ function q(a) {
157
157
  throw new Error("this should never happen");
158
158
  }
159
159
  function F(a = "debug") {
160
- return z.createLogger({
160
+ return Q.createLogger({
161
161
  level: a,
162
- format: z.format.combine(
163
- z.format.printf(({ level: e, message: r }) => {
164
- const t = " ".repeat(e.length + 2), i = r.split(`
162
+ format: Q.format.printf(({ level: e, message: r }) => {
163
+ const t = " ".repeat(e.length + 2);
164
+ if (typeof r != "string") {
165
+ const c = JSON.stringify(r);
166
+ throw Error(`logger message ${c} is not a string`);
167
+ }
168
+ const i = r.split(`
165
169
  `).map((c, n) => n === 0 ? c : t + c).join(`
166
170
  `);
167
- return `${((c) => z.format.colorize().colorize(c, c))(e)}: ${i}`;
168
- })
169
- ),
171
+ return `${((c) => Q.format.colorize().colorize(c, c))(e)}: ${i}`;
172
+ }),
170
173
  transports: [
171
- new z.transports.Console({
174
+ new Q.transports.Console({
172
175
  stderrLevels: ["error", "warn", "info", "debug"],
173
176
  handleExceptions: !0
174
177
  })
@@ -195,7 +198,7 @@ function Sr(a) {
195
198
  return "";
196
199
  }
197
200
  }
198
- const ce = ["Python"], Ve = ["Tengo", "Python"], Ar = O.union([O.literal("Tengo"), O.literal("Python")]), Rr = O.object({
201
+ const ce = ["Python"], Ve = ["Tengo", "Python"], Ar = O.union([O.literal("Tengo"), O.literal("Python")]), pr = O.object({
199
202
  npmOrgName: O.string().min(1),
200
203
  orgName: O.string().min(1),
201
204
  blockName: O.string().min(1),
@@ -203,7 +206,7 @@ const ce = ["Python"], Ve = ["Tengo", "Python"], Ar = O.union([O.literal("Tengo"
203
206
  message: "Must be an array of unique software platforms"
204
207
  })
205
208
  });
206
- async function pr(a) {
209
+ async function Rr(a) {
207
210
  const { npmOrgName: e, orgName: r, blockName: t, softwarePlatforms: i } = Lr(), s = o.join(process.cwd(), t);
208
211
  a.info("Downloading boilerplate code..."), await _r(
209
212
  // 'https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/software_platforms.zip',
@@ -238,7 +241,7 @@ function Lr() {
238
241
  if (s < 0) break;
239
242
  i.push(ce[s]);
240
243
  }
241
- return i = Array.from(new Set(i)).sort(), Rr.parse({ npmOrgName: a, orgName: e, blockName: r, softwarePlatforms: i });
244
+ return i = Array.from(new Set(i)).sort(), pr.parse({ npmOrgName: a, orgName: e, blockName: r, softwarePlatforms: i });
242
245
  }
243
246
  async function _r(a, e, r) {
244
247
  const i = await (await fetch(a)).blob(), s = await T.mkdtemp(o.join(L.tmpdir(), "create-repo")), c = o.join(s, "packed-repo.zip"), n = dr.toWeb(cr(c));
@@ -308,7 +311,7 @@ async function C(a, e) {
308
311
  const B = class B extends E {
309
312
  async run() {
310
313
  const { flags: e } = await this.parse(B), r = F(e["log-level"]);
311
- await pr(r);
314
+ await Rr(r);
312
315
  }
313
316
  };
314
317
  h(B, "description", "Helps to create a new block by downloading a block's template."), h(B, "examples", ["<%= name %>"]), h(B, "flags", {
@@ -450,7 +453,7 @@ function Ze(a, e, r, t) {
450
453
  env: ${JSON.stringify(t.env)}
451
454
  cmd: ${JSON.stringify([e, ...r])}
452
455
  wd: ${t.cwd}`
453
- ), t.env = { ...process.env, ...t.env }, q(e, r, t);
456
+ ), t.env = { ...process.env, ...t.env }, K(e, r, t);
454
457
  }
455
458
  function Mr(a) {
456
459
  return {
@@ -524,14 +527,14 @@ function x(a, e, r) {
524
527
  }
525
528
  }
526
529
  function Cr(a, e) {
527
- var g, b, v, S, R, k, _, Y, A, we, ve, ke, Se, Ae, Re, pe, Le, _e, $e, Oe, Te, Ee, De, Fe, Ne, Ie, xe, Me, Ce, Be;
530
+ var g, b, v, S, p, k, _, Y, A, we, ve, ke, Se, Ae, pe, Re, Le, _e, $e, Oe, Te, Ee, De, Fe, Ne, Ie, xe, Me, Ce, Be;
528
531
  const r = (e == null ? void 0 : e.localRoot) ?? l.data("local-custom"), t = {
529
532
  level: ((g = e == null ? void 0 : e.log) == null ? void 0 : g.level) ?? "info",
530
533
  path: ((b = e == null ? void 0 : e.log) == null ? void 0 : b.path) ?? `${r}/logs/platforma.log`
531
534
  }, i = {
532
535
  listen: ((v = e == null ? void 0 : e.grpc) == null ? void 0 : v.listen) ?? "localhost:6345",
533
536
  tls: {
534
- enable: Q((R = (S = e == null ? void 0 : e.grpc) == null ? void 0 : S.tls) == null ? void 0 : R.enable, !1),
537
+ enable: V((p = (S = e == null ? void 0 : e.grpc) == null ? void 0 : S.tls) == null ? void 0 : p.enable, !1),
535
538
  clientAuthMode: ((_ = (k = e == null ? void 0 : e.grpc) == null ? void 0 : k.tls) == null ? void 0 : _.clientAuthMode) ?? "NoAuth",
536
539
  certFile: ((A = (Y = e == null ? void 0 : e.grpc) == null ? void 0 : Y.tls) == null ? void 0 : A.certFile) ?? `${r}/certs/tls.cert`,
537
540
  keyFile: ((ve = (we = e == null ? void 0 : e.grpc) == null ? void 0 : we.tls) == null ? void 0 : ve.keyFile) ?? `${r}/certs/tls.key`,
@@ -540,7 +543,7 @@ function Cr(a, e) {
540
543
  }, s = {
541
544
  auth: {
542
545
  enabled: ((Ae = (Se = e == null ? void 0 : e.core) == null ? void 0 : Se.auth) == null ? void 0 : Ae.enabled) ?? !1,
543
- drivers: ((pe = (Re = e == null ? void 0 : e.core) == null ? void 0 : Re.auth) == null ? void 0 : pe.drivers) ?? [
546
+ drivers: ((Re = (pe = e == null ? void 0 : e.core) == null ? void 0 : pe.auth) == null ? void 0 : Re.drivers) ?? [
544
547
  { driver: "jwt", key: a },
545
548
  { driver: "htpasswd", path: `${r}/users.htpasswd` }
546
549
  ]
@@ -569,10 +572,10 @@ function Cr(a, e) {
569
572
  "library-bucket",
570
573
  (Fe = e == null ? void 0 : e.storages) == null ? void 0 : Fe.library
571
574
  ), f = {
572
- enabled: Q((Ne = e == null ? void 0 : e.monitoring) == null ? void 0 : Ne.enabled, !0),
575
+ enabled: V((Ne = e == null ? void 0 : e.monitoring) == null ? void 0 : Ne.enabled, !0),
573
576
  listen: ((Ie = e == null ? void 0 : e.monitoring) == null ? void 0 : Ie.listen) ?? "127.0.0.1:9090"
574
577
  }, w = {
575
- enabled: Q((xe = e == null ? void 0 : e.debug) == null ? void 0 : xe.enabled, !0),
578
+ enabled: V((xe = e == null ? void 0 : e.debug) == null ? void 0 : xe.enabled, !0),
576
579
  listen: ((Me = e == null ? void 0 : e.debug) == null ? void 0 : Me.listen) ?? "127.0.0.1:9091"
577
580
  }, P = {
578
581
  value: ((Ce = e == null ? void 0 : e.license) == null ? void 0 : Ce.value) ?? "",
@@ -598,10 +601,10 @@ function We(a, e, r, t) {
598
601
  i = er(a), i.rootPath = (t == null ? void 0 : t.rootPath) ?? e;
599
602
  break;
600
603
  case "S3":
601
- i = Mr(a), i.endpoint = (t == null ? void 0 : t.endpoint) ?? "http://localhost:9000", i.presignEndpoint = (t == null ? void 0 : t.presignEndpoint) ?? "http://localhost:9000", i.bucketName = (t == null ? void 0 : t.bucketName) ?? r, i.createBucket = Q(t == null ? void 0 : t.createBucket, !0), i.forcePathStyle = Q(t == null ? void 0 : t.forcePathStyle, !0), i.key = (t == null ? void 0 : t.key) ?? "", i.secret = (t == null ? void 0 : t.secret) ?? "", i.keyPrefix = (t == null ? void 0 : t.keyPrefix) ?? "", i.accessPrefixes = (t == null ? void 0 : t.accessPrefixes) ?? [""], i.uploadKeyPrefix = (t == null ? void 0 : t.uploadKeyPrefix) ?? "";
604
+ i = Mr(a), i.endpoint = (t == null ? void 0 : t.endpoint) ?? "http://localhost:9000", i.presignEndpoint = (t == null ? void 0 : t.presignEndpoint) ?? "http://localhost:9000", i.bucketName = (t == null ? void 0 : t.bucketName) ?? r, i.createBucket = V(t == null ? void 0 : t.createBucket, !0), i.forcePathStyle = V(t == null ? void 0 : t.forcePathStyle, !0), i.key = (t == null ? void 0 : t.key) ?? "", i.secret = (t == null ? void 0 : t.secret) ?? "", i.keyPrefix = (t == null ? void 0 : t.keyPrefix) ?? "", i.accessPrefixes = (t == null ? void 0 : t.accessPrefixes) ?? [""], i.uploadKeyPrefix = (t == null ? void 0 : t.uploadKeyPrefix) ?? "";
602
605
  break;
603
606
  default:
604
- throw V(), new Error("unknown storage type");
607
+ throw q(), new Error("unknown storage type");
605
608
  }
606
609
  return i;
607
610
  }
@@ -684,7 +687,7 @@ controllers:
684
687
  workflows: {}
685
688
  `;
686
689
  }
687
- function Q(a, e) {
690
+ function V(a, e) {
688
691
  return a === void 0 ? e : a;
689
692
  }
690
693
  const Gr = ["linux", "macos", "windows"];
@@ -793,10 +796,10 @@ class I {
793
796
  }
794
797
  startLast() {
795
798
  const e = Ir(this.logger, { stdio: "inherit" });
796
- K(e, "failed to bring back Platforma Backend in the last started configuration");
799
+ z(e, "failed to bring back Platforma Backend in the last started configuration");
797
800
  }
798
801
  startLocal(e) {
799
- var u, m, f, w, P, g, b, v, S, R;
802
+ var u, m, f, w, P, g, b, v, S, p;
800
803
  const r = (e == null ? void 0 : e.binaryPath) ?? Hr(e == null ? void 0 : e.version, "binaries", "platforma");
801
804
  var t = e == null ? void 0 : e.configPath;
802
805
  const i = (e == null ? void 0 : e.workdir) ?? (t ? process.cwd() : l.path());
@@ -814,7 +817,7 @@ class I {
814
817
  }
815
818
  });
816
819
  const s = Cr(this.getLastJwt(), e == null ? void 0 : e.configOptions);
817
- this.logger.debug(" checking license..."), this.checkLicense((v = (b = e == null ? void 0 : e.configOptions) == null ? void 0 : b.license) == null ? void 0 : v.value, (R = (S = e == null ? void 0 : e.configOptions) == null ? void 0 : S.license) == null ? void 0 : R.file);
820
+ this.logger.debug(" checking license..."), this.checkLicense((v = (b = e == null ? void 0 : e.configOptions) == null ? void 0 : b.license) == null ? void 0 : v.value, (p = (S = e == null ? void 0 : e.configOptions) == null ? void 0 : S.license) == null ? void 0 : p.file);
818
821
  const c = [
819
822
  `${s.localRoot}/packages`,
820
823
  `${s.localRoot}/packages-local`,
@@ -887,7 +890,7 @@ ${n}`), Nr(
887
890
  PL_IMAGE: "scratch"
888
891
  };
889
892
  this.logger.debug(" spawning child 'docker' process...");
890
- const f = q(
893
+ const f = K(
891
894
  "docker",
892
895
  ["compose", `--file=${r}`, "up", "--detach", "--remove-orphans", "--pull=missing", "minio"],
893
896
  {
@@ -898,23 +901,23 @@ ${n}`), Nr(
898
901
  stdio: "inherit"
899
902
  }
900
903
  );
901
- K(f, "failed to start MinIO service in docker");
904
+ z(f, "failed to start MinIO service in docker");
902
905
  }
903
906
  buildPlatforma(e) {
904
907
  const r = o.resolve(e.repoRoot, "cmd", "platforma"), t = e.binPath ?? o.join(L.tmpdir(), "platforma-local-build");
905
908
  this.logger.info("Building Platforma Backend binary from sources"), this.logger.info(` sources path: ${e.repoRoot}`), this.logger.info(` binary path: ${t}`);
906
- const i = q("go", ["build", "-o", t, "."], {
909
+ const i = K("go", ["build", "-o", t, "."], {
907
910
  cwd: r,
908
911
  stdio: "inherit"
909
912
  });
910
- return K(i, "failed to build platforma binary from sources using 'go build' command"), t;
913
+ return z(i, "failed to build platforma binary from sources using 'go build' command"), t;
911
914
  }
912
915
  startDockerS3(e, r) {
913
916
  const t = $("compose-backend.yaml"), i = (r == null ? void 0 : r.image) ?? se(r == null ? void 0 : r.version);
914
917
  this.checkLicense(r == null ? void 0 : r.license, r == null ? void 0 : r.licenseFile);
915
918
  const s = (...S) => o.join(e, ...S), c = (S) => {
916
- const R = s(S);
917
- return X(R, { mode: "0775" }), R;
919
+ const p = s(S);
920
+ return X(p, { mode: "0775" }), p;
918
921
  }, n = s("logs", "platforma.log");
919
922
  d.existsSync(n) || (d.mkdirSync(o.dirname(n), { recursive: !0 }), d.writeFileSync(n, ""));
920
923
  const u = x("s3e://testuser:testpassword@minio:9000/main-bucket");
@@ -971,7 +974,7 @@ ${n}`), Nr(
971
974
  composePath: t
972
975
  }
973
976
  );
974
- K(b, "failed to start Platforma Backend in Docker"), l.isActive = !0;
977
+ z(b, "failed to start Platforma Backend in Docker"), l.isActive = !0;
975
978
  const v = this.renderRunInfo({
976
979
  apiPort: r == null ? void 0 : r.grpcPort,
977
980
  apiAddr: r == null ? void 0 : r.grpcAddr,
@@ -1033,8 +1036,8 @@ ${v}`);
1033
1036
  libraryPath: f
1034
1037
  }
1035
1038
  );
1036
- K(S, "failed to start Platforma Backend in Docker"), l.isActive = !0;
1037
- const R = this.renderRunInfo({
1039
+ z(S, "failed to start Platforma Backend in Docker"), l.isActive = !0;
1040
+ const p = this.renderRunInfo({
1038
1041
  apiPort: r == null ? void 0 : r.grpcPort,
1039
1042
  apiAddr: r == null ? void 0 : r.grpcAddr,
1040
1043
  logPath: n,
@@ -1044,7 +1047,7 @@ ${v}`);
1044
1047
  dbPath: u
1045
1048
  });
1046
1049
  this.logger.info(`Started platforma:
1047
- ${R}`);
1050
+ ${p}`);
1048
1051
  }
1049
1052
  stop() {
1050
1053
  if (!l.isActive) {
@@ -1054,7 +1057,7 @@ ${R}`);
1054
1057
  const e = l.lastRun;
1055
1058
  switch (e.mode) {
1056
1059
  case "docker":
1057
- const r = q("docker", ["compose", "--file", e.docker.composePath, "down"], {
1060
+ const r = K("docker", ["compose", "--file", e.docker.composePath, "down"], {
1058
1061
  env: {
1059
1062
  ...process.env,
1060
1063
  ...e.envs
@@ -1067,11 +1070,11 @@ ${R}`);
1067
1070
  l.isValidPID && process.kill(e.process.pid), l.isActive = !1;
1068
1071
  return;
1069
1072
  default:
1070
- V(e.mode);
1073
+ q(e.mode);
1071
1074
  }
1072
1075
  }
1073
1076
  cleanup() {
1074
- var n, u, m, f, w, P, g, b, v, S, R, k, _, Y;
1077
+ var n, u, m, f, w, P, g, b, v, S, p, k, _, Y;
1075
1078
  const e = [
1076
1079
  "last command run cache ('pl-service start' shorthand will stop working until next full start command call)",
1077
1080
  "'platforma' docker compose service containers and volumes"
@@ -1085,7 +1088,7 @@ ${R}`);
1085
1088
  A.startsWith(r) || t.push(A);
1086
1089
  }
1087
1090
  if ((S = (v = l.lastRun) == null ? void 0 : v.process) != null && S.storagePath) {
1088
- const A = (k = (R = l.lastRun) == null ? void 0 : R.process) == null ? void 0 : k.storagePath;
1091
+ const A = (k = (p = l.lastRun) == null ? void 0 : p.process) == null ? void 0 : k.storagePath;
1089
1092
  A.startsWith(r) || t.push(A);
1090
1093
  }
1091
1094
  const i = t.length > 0 ? ` - storages (you'll loose all projects and calculation results stored in service instances):
@@ -1142,7 +1145,7 @@ If you want to remove all downloaded platforma binaries, delete '${l.binaries()}
1142
1145
  return t == "" && (t = vr(64), d.writeFileSync(e, t, { encoding: r })), t;
1143
1146
  }
1144
1147
  destroyDocker(e, r) {
1145
- const t = l.data("stub"), i = q("docker", ["compose", "--file", e, "down", "--volumes", "--remove-orphans"], {
1148
+ const t = l.data("stub"), i = K("docker", ["compose", "--file", e, "down", "--volumes", "--remove-orphans"], {
1146
1149
  env: {
1147
1150
  ...process.env,
1148
1151
  PL_IMAGE: "scratch",
@@ -1180,7 +1183,7 @@ You can obtain the license from "https://licensing.milaboratories.com".`), new E
1180
1183
  case "FS":
1181
1184
  return t[`PL_DATA_${e}_TYPE`] = "FS", t;
1182
1185
  default:
1183
- V();
1186
+ q();
1184
1187
  }
1185
1188
  return {};
1186
1189
  }
@@ -1199,7 +1202,7 @@ You can obtain the license from "https://licensing.milaboratories.com".`), new E
1199
1202
  );
1200
1203
  break;
1201
1204
  default:
1202
- V();
1205
+ q();
1203
1206
  }
1204
1207
  switch ((u = e.library) == null ? void 0 : u.type) {
1205
1208
  case void 0:
@@ -1213,7 +1216,7 @@ You can obtain the license from "https://licensing.milaboratories.com".`), new E
1213
1216
  );
1214
1217
  break;
1215
1218
  default:
1216
- V();
1219
+ q();
1217
1220
  }
1218
1221
  return e.work && t.push(`${i("workdirs")}: ${e.work.rootPath}`), e.dbPath && t.push(`${i("db")}: ${e.dbPath}`), t.join(`
1219
1222
  `);
@@ -1226,7 +1229,7 @@ You can obtain the license from "https://licensing.milaboratories.com".`), new E
1226
1229
  d.writeFileSync(e, je.stringify(r));
1227
1230
  }
1228
1231
  }
1229
- function K(a, e) {
1232
+ function z(a, e) {
1230
1233
  if (a.error)
1231
1234
  throw a.error;
1232
1235
  const r = e ?? "failed to run command";
@@ -1357,10 +1360,10 @@ h(J, "description", "Run Platforma Backend service as local process on current h
1357
1360
  ...ie
1358
1361
  });
1359
1362
  let fe = J;
1360
- var p;
1361
- let zr = (p = class extends E {
1363
+ var R;
1364
+ let zr = (R = class extends E {
1362
1365
  async run() {
1363
- const { flags: e } = await this.parse(p), r = F(e["log-level"]), t = new I(r);
1366
+ const { flags: e } = await this.parse(R), r = F(e["log-level"]), t = new I(r);
1364
1367
  t.mergeLicenseEnvs(e);
1365
1368
  const i = e["auth-enabled"], s = i ? {
1366
1369
  enabled: i,
@@ -1380,7 +1383,7 @@ let zr = (p = class extends E {
1380
1383
  debugPort: e["debug-port"]
1381
1384
  });
1382
1385
  }
1383
- }, h(p, "description", "Run platforma backend service with 'S3' primary storage type"), h(p, "examples", ["<%= config.bin %> <%= command.id %>"]), h(p, "flags", {
1386
+ }, h(R, "description", "Run platforma backend service with 'S3' primary storage type"), h(R, "examples", ["<%= config.bin %> <%= command.id %>"]), h(R, "flags", {
1384
1387
  ...D,
1385
1388
  ...te,
1386
1389
  ...Je,
@@ -1388,7 +1391,7 @@ let zr = (p = class extends E {
1388
1391
  ...ae,
1389
1392
  ...re,
1390
1393
  ...ie
1391
- }), p);
1394
+ }), R);
1392
1395
  const H = class H extends E {
1393
1396
  async run() {
1394
1397
  const { flags: e } = await this.parse(H), r = F(e["log-level"]), t = new I(r);