@platforma-sdk/bootstrap 3.1.3 → 3.1.4

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/README.md CHANGED
@@ -53,6 +53,29 @@ pl-dev svc up MyLocalPl
53
53
  The tool will download Platforma Backend archive for your OS and architecture, generate configuration file and all necessary directories.
54
54
  `up` command will make the service instance start.
55
55
 
56
+ ### How-To's
57
+
58
+ > NOTE: after creating instances with `svc create * <NAME>` command, start this instance with `svc up <NAME>`. Only one instance for user can be started at a time for now. When you call `up` for one instance, all other instances get stopped automatically.
59
+
60
+ - Docker-based:
61
+ - Create docker container, starting fake S3 service (minio) locally to use it as a primary storage:
62
+ ```bash
63
+ pl-dev svc create docker s3 MyInstance
64
+ ```
65
+ - Create docker container, connecting it to AWS S3 bucket `myAwesomeBucket` as a primary storage, keeping all the data under `some-prefix` prefix inside the bucket:
66
+ ```bash
67
+ pl-dev svc create docker MyInstance --storage-primary "s3://myAwesomeBucket/some-prefix?region=eu-central-1"
68
+ ```
69
+ - Mount custom directory with dev blocks from the host into docker container:
70
+ ```bash
71
+ pl-dev svc create docker MyInstance --mount /home/myusername/platforma-dev/blocks/
72
+ ```
73
+ - Local instances:
74
+ - Create service that starts locally on current host (no containers) and uses custom S3 service (not AWS) as library:
75
+ ```bash
76
+ pl-dev svc create local MyInstance --storage-library "s3es://my-corporate-s3.example.com/rawDataBucket/?region=company-internal-region"
77
+ ```
78
+
56
79
  ## Block skeleton generation
57
80
 
58
81
  To create new block skeleton, run
@@ -0,0 +1,38 @@
1
+ import { Command } from '@oclif/core';
2
+ import { OptionFlag, CustomOptions, BooleanFlag, Arg } from '@oclif/core/interfaces';
3
+ export default class Local extends Command {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ 'auth-ldap-default-dn': OptionFlag<string | undefined, CustomOptions>;
8
+ 'auth-ldap-server': OptionFlag<string | undefined, CustomOptions>;
9
+ 'auth-htpasswd-file': OptionFlag<string | undefined, CustomOptions>;
10
+ 'auth-enabled': BooleanFlag<boolean>;
11
+ "pl-workdir": OptionFlag<string | undefined, CustomOptions>;
12
+ "pl-log-file": OptionFlag<string | undefined, CustomOptions>;
13
+ 'storage-library': OptionFlag<string | undefined, CustomOptions>;
14
+ 'storage-work': OptionFlag<string | undefined, CustomOptions>;
15
+ 'storage-primary': OptionFlag<string | undefined, CustomOptions>;
16
+ storage: OptionFlag<string | undefined, CustomOptions>;
17
+ license: OptionFlag<string | undefined, CustomOptions>;
18
+ 'license-file': OptionFlag<string | undefined, CustomOptions>;
19
+ config: OptionFlag<string | undefined, CustomOptions>;
20
+ "pl-sources": OptionFlag<string | undefined, CustomOptions>;
21
+ "pl-binary": OptionFlag<string | undefined, CustomOptions>;
22
+ 'grpc-port': OptionFlag<number | undefined, CustomOptions>;
23
+ 'grpc-listen': OptionFlag<string | undefined, CustomOptions>;
24
+ 'monitoring-port': OptionFlag<number | undefined, CustomOptions>;
25
+ 'monitoring-listen': OptionFlag<string | undefined, CustomOptions>;
26
+ 'debug-port': OptionFlag<number | undefined, CustomOptions>;
27
+ 'debug-listen': OptionFlag<string | undefined, CustomOptions>;
28
+ 's3-port': OptionFlag<number, CustomOptions>;
29
+ 's3-console-port': OptionFlag<number, CustomOptions>;
30
+ version: OptionFlag<string | undefined, CustomOptions>;
31
+ 'log-level': OptionFlag<string, CustomOptions>;
32
+ };
33
+ static args: {
34
+ name: Arg<string, Record<string, unknown>>;
35
+ };
36
+ run(): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=s3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../../src/commands/svc/create/local/s3.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAS5C,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAA0F;IAErH,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;MAqBnB;IAEF,MAAM,CAAC,IAAI;;MAET;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA2ElC"}
@@ -25,14 +25,11 @@ export default class Local extends Command {
25
25
  'monitoring-listen': OptionFlag<string | undefined, CustomOptions>;
26
26
  'debug-port': OptionFlag<number | undefined, CustomOptions>;
27
27
  'debug-listen': OptionFlag<string | undefined, CustomOptions>;
28
- 's3-port': OptionFlag<number, CustomOptions>;
29
- 's3-console-port': OptionFlag<number, CustomOptions>;
30
28
  version: OptionFlag<string | undefined, CustomOptions>;
31
29
  'log-level': OptionFlag<string, CustomOptions>;
32
30
  };
33
31
  static args: {
34
32
  name: Arg<string, Record<string, unknown>>;
35
- mode: Arg<string | undefined, Record<string, unknown>>;
36
33
  };
37
34
  run(): Promise<void>;
38
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../../src/commands/svc/create/local.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAS5C,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAA0F;IAErH,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;MAqBnB;IAEF,MAAM,CAAC,IAAI;;;MAGT;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA8FlC"}
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../../src/commands/svc/create/local.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAS5C,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAA0F;IAErH,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;MAoBnB;IAEF,MAAM,CAAC,IAAI;;MAET;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAsElC"}
@@ -1 +1 @@
1
- {"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../../../src/commands/svc/up.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAM5C,MAAM,CAAC,OAAO,OAAO,EAAG,SAAQ,OAAO;IACrC,OAAgB,WAAW,SAA8B;IAEzD,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;MAEnB;IAEF,MAAM,CAAC,IAAI;;MAET;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAoBlC"}
1
+ {"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../../../src/commands/svc/up.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAM5C,MAAM,CAAC,OAAO,OAAO,EAAG,SAAQ,OAAO;IACrC,OAAgB,WAAW,SAA8B;IAEzD,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;MAEnB;IAEF,MAAM,CAAC,IAAI;;MAET;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAsClC"}
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ import { default as Cmd11 } from './commands/start/local/s3';
13
13
  import { default as Cmd12 } from './commands/svc/create/docker';
14
14
  import { default as Cmd13 } from './commands/svc/create/local';
15
15
  import { default as Cmd14 } from './commands/svc/create/docker/s3';
16
+ import { default as Cmd15 } from './commands/svc/create/local/s3';
16
17
  export declare const COMMANDS: {
17
18
  'create-block': typeof Cmd0;
18
19
  reset: typeof Cmd1;
@@ -29,5 +30,6 @@ export declare const COMMANDS: {
29
30
  'svc:create:docker': typeof Cmd12;
30
31
  'svc:create:local': typeof Cmd13;
31
32
  'svc:create:docker:s3': typeof Cmd14;
33
+ 'svc:create:local:s3': typeof Cmd15;
32
34
  };
33
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,IAAI,MAAM,uBAAuB,CAAC;AACzC,OAAO,IAAI,MAAM,qBAAqB,CAAC;AACvC,OAAO,IAAI,MAAM,qBAAqB,CAAC;AACvC,OAAO,IAAI,MAAM,mBAAmB,CAAC;AACrC,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAC/C,OAAO,KAAK,MAAM,2BAA2B,CAAC;AAC9C,OAAO,KAAK,MAAM,8BAA8B,CAAC;AACjD,OAAO,KAAK,MAAM,6BAA6B,CAAC;AAChD,OAAO,KAAK,MAAM,iCAAiC,CAAC;AAGpD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;CAgBpB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,IAAI,MAAM,uBAAuB,CAAC;AACzC,OAAO,IAAI,MAAM,qBAAqB,CAAC;AACvC,OAAO,IAAI,MAAM,qBAAqB,CAAC;AACvC,OAAO,IAAI,MAAM,mBAAmB,CAAC;AACrC,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAC/C,OAAO,KAAK,MAAM,2BAA2B,CAAC;AAC9C,OAAO,KAAK,MAAM,8BAA8B,CAAC;AACjD,OAAO,KAAK,MAAM,6BAA6B,CAAC;AAChD,OAAO,KAAK,MAAM,iCAAiC,CAAC;AACpD,OAAO,KAAK,MAAM,gCAAgC,CAAC;AAGnD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;CAiBpB,CAAC"}
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
- "use strict";var vr=Object.defineProperty;var Pr=(a,e,t)=>e in a?vr(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var l=(a,e,t)=>Pr(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@oclif/core"),T=require("node:os"),u=require("node:fs"),h=require("node:path"),ae=require("node:child_process"),le=require("winston"),kr=require("node:crypto"),K=require("readline-sync"),Sr=require("node:fs/promises"),$r=require("node:stream"),D=require("zod"),Ar=require("decompress"),ge=require("yaml"),ue=require("@milaboratories/pl-deployments"),Lr=require("node:https"),Ir=require("tar");function gr(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const x=gr(Sr),Or=gr(Ir),A={"log-level":d.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})};d.Flags.string({description:"name of instance",required:!1});const fe={image:d.Flags.string({description:"use custom docker image to run platforma"})},q={version:d.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},me={arch:d.Flags.string({description:"override architecture. You can start amd64 linux image on arm-based host (say, Apple M family processor). I.e. arm64, amd64, amd64/v2"})},J={license:d.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":d.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},H={"grpc-port":d.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":d.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":d.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":d.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":d.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":d.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},ur={"s3-port":d.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-port":d.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},W={storage:d.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},fr={"minio-presign-host":d.Flags.boolean({description:"use 'minio' host instead of 'localhost' in presign URLs"})},he={mount:d.Flags.string({multiple:!0,description:"things to be mounted into platforma docker container. Targets will appear inside the container under the same absolute paths"})},De={"pl-log-file":d.Flags.file({description:"specify path for Platforma Backend log file"})},xe={"pl-workdir":d.Flags.file({description:"specify working directory for Platforma Backend process"})},_e={"pl-binary":d.Flags.file({description:"start given Platforma Backend binary instead of automatically downloaded version"})},Ne={"pl-sources":d.Flags.file({description:"path to pl repository root: build Platforma Backend from sources and start the resulting binary"})},Ce={config:d.Flags.string({description:"use custom Platforma Backend config"})};d.Flags.file({description:"specify path on host to be used as 'primary' storage"});const ie={"storage-work":d.Flags.file({description:"specify path on host to be used as 'work' storage"})};d.Flags.file({description:"specify path on host to be used as 'library' storage"});const ce={"storage-primary":d.Flags.string({description:`specify 'primary' storage destination URL.
1
+ "use strict";var Pr=Object.defineProperty;var kr=(a,e,t)=>e in a?Pr(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var l=(a,e,t)=>kr(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@oclif/core"),D=require("node:os"),m=require("node:fs"),h=require("node:path"),ne=require("node:child_process"),de=require("winston"),Sr=require("node:crypto"),Q=require("readline-sync"),$r=require("node:fs/promises"),Lr=require("node:stream"),x=require("zod"),Ar=require("decompress"),ue=require("yaml"),fe=require("@milaboratories/pl-deployments"),Ir=require("node:https"),Or=require("tar");function ur(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const _=ur($r),Fr=ur(Or),L={"log-level":u.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})};u.Flags.string({description:"name of instance",required:!1});const me={image:u.Flags.string({description:"use custom docker image to run platforma"})},N={version:u.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},he={arch:u.Flags.string({description:"override architecture. You can start amd64 linux image on arm-based host (say, Apple M family processor). I.e. arm64, amd64, amd64/v2"})},C={license:u.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":u.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},M={"grpc-port":u.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":u.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":u.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":u.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":u.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":u.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},fr={"s3-port":u.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-port":u.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},j={storage:u.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},mr={"minio-presign-host":u.Flags.boolean({description:"use 'minio' host instead of 'localhost' in presign URLs"})},ye={mount:u.Flags.string({multiple:!0,description:"things to be mounted into platforma docker container. Targets will appear inside the container under the same absolute paths"})},pe={"pl-log-file":u.Flags.file({description:"specify path for Platforma Backend log file"})},be={"pl-workdir":u.Flags.file({description:"specify working directory for Platforma Backend process"})},we={"pl-binary":u.Flags.file({description:"start given Platforma Backend binary instead of automatically downloaded version"})},ve={"pl-sources":u.Flags.file({description:"path to pl repository root: build Platforma Backend from sources and start the resulting binary"})},Pe={config:u.Flags.string({description:"use custom Platforma Backend config"})};u.Flags.file({description:"specify path on host to be used as 'primary' storage"});const se={"storage-work":u.Flags.file({description:"specify path on host to be used as 'work' storage"})};u.Flags.file({description:"specify path on host to be used as 'library' storage"});const ie={"storage-primary":u.Flags.string({description:`specify 'primary' storage destination URL.
2
2
  file:/path/to/dir for directory on local FS
3
3
  s3://<bucket>/?region=<name> for real AWS bucket
4
4
  s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
5
- s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},oe={"storage-library":d.Flags.string({description:`specify 'library' storage destination URL.
5
+ s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},ce={"storage-library":u.Flags.string({description:`specify 'library' storage destination URL.
6
6
  file:/path/to/dir for directory on local FS
7
7
  s3://<bucket>/?region=<name> for real AWS bucket
8
8
  s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
9
- s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},Fr={"auth-enabled":d.Flags.boolean({description:"enable authorization"})},Er={"auth-htpasswd-file":d.Flags.file({description:"path to .htpasswd file with Platforma users (static user DB auth source)"})},Rr={"auth-ldap-server":d.Flags.string({description:"address of LDAP server to use for auth in Platforma (auth source)"})},Tr={"auth-ldap-default-dn":d.Flags.string({description:"DN to use when checking user with LDAP bind operation: e.g. cn=%u,ou=users,dc=example,dc=com"})},z={...Fr,...Er,...Rr,...Tr};function Dr(a){return K.question(`${a} [y/N] `).toLowerCase()==="y"}function _(a){throw new Error("this should never happen")}function L(a="debug"){return le.createLogger({level:a,format:le.format.printf(({level:e,message:t})=>{const r=" ".repeat(e.length+2);if(typeof t!="string"){const i=JSON.stringify(t);throw Error(`logger message ${i} is not a string`)}const n=t.split(`
9
+ s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},Rr={"auth-enabled":u.Flags.boolean({description:"enable authorization"})},Er={"auth-htpasswd-file":u.Flags.file({description:"path to .htpasswd file with Platforma users (static user DB auth source)"})},Tr={"auth-ldap-server":u.Flags.string({description:"address of LDAP server to use for auth in Platforma (auth source)"})},Dr={"auth-ldap-default-dn":u.Flags.string({description:"DN to use when checking user with LDAP bind operation: e.g. cn=%u,ou=users,dc=example,dc=com"})},B={...Rr,...Er,...Tr,...Dr};function xr(a){return Q.question(`${a} [y/N] `).toLowerCase()==="y"}function U(a){throw new Error("this should never happen")}function A(a="debug"){return de.createLogger({level:a,format:de.format.printf(({level:e,message:t})=>{const r=" ".repeat(e.length+2);if(typeof t!="string"){const i=JSON.stringify(t);throw Error(`logger message ${i} is not a string`)}const n=t.split(`
10
10
  `).map((i,c)=>c===0?i:r+i).join(`
11
- `);return`${(i=>le.format.colorize().colorize(i,i))(e)}: ${n}`}),transports:[new le.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function xr(a){return kr.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function _r(a){return a.startsWith("~")?h.join(T.homedir(),a.slice(1)):a}function ye(a,e){u.existsSync(a)||(u.mkdirSync(a,{recursive:!0}),e!=null&&e.mode&&u.chmodSync(a,e.mode))}function Nr(a){try{if(T.platform()!=="win32")return ae.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,t=ae.execSync(e,{encoding:"utf8"}).split(`
12
- `);return t.length<=1?"":t[1].trim()}catch{return""}}function Cr(a){const e=ae.execSync(`docker compose ls --filter name=${a} --format json`,{encoding:"utf8"}).trim(),t=JSON.parse(e);for(const r of t)if(r.Name===a)return r}const ve=["Python"],mr=["Tengo","Python"],Mr=D.z.union([D.z.literal("Tengo"),D.z.literal("Python")]),jr=D.z.object({npmOrgName:D.z.string().min(1),orgName:D.z.string().min(1),blockName:D.z.string().min(1),softwarePlatforms:D.z.array(Mr).refine(a=>new Set(a).size===a.length,{message:"Must be an array of unique software platforms"})});async function Br(a){const{npmOrgName:e,orgName:t,blockName:r,softwarePlatforms:n}=Gr(),s=h.join(process.cwd(),r);a.info("Downloading boilerplate code..."),await Ur("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",s);const i=mr.filter(o=>n.indexOf(o)<0),c=ve.length==i.length;a.info(`Keep platforms '${n}', remove: '${i}'. Will remove all platforms? ${c}`);for(const o of i)await qr(s,o);c&&await Jr(s),a.info("Replace everything in the template with provided options..."),Hr(s,[{from:/@platforma-open(?!.*runenv-python-3)/g,to:`@${e}`},{from:/my-org/g,to:t},{from:/block-boilerplate/g,to:r}])}function Gr(){let a=K.question('Write an organization name for npm. Default is "platforma-open": ');a===""&&(a="platforma-open");const e=K.question('Write an organization name, e.g. "my-org": '),t=K.question('Write a name of the block, e.g. "hello-world": '),r=K.keyInYN("Create package for block's software?");let n=["Tengo"];if(r)for(;n.length<mr.length;){const s=K.keyInSelect(ve,"Choose software platform:");if(s<0)break;n.push(ve[s])}return n=Array.from(new Set(n)).sort(),jr.parse({npmOrgName:a,orgName:e,blockName:t,softwarePlatforms:n})}async function Ur(a,e,t){const n=await(await fetch(a)).blob(),s=await x.mkdtemp(h.join(T.tmpdir(),"create-repo")),i=h.join(s,"packed-repo.zip"),c=$r.Writable.toWeb(u.createWriteStream(i));await n.stream().pipeTo(c);const o=h.join(s,"unpacked-repo");await x.mkdir(o),await Ar(i,o),await x.cp(h.join(o,e),t,{recursive:!0})}async function qr(a,e){const t=e.toLowerCase();await Q(h.join(a,"ui","src","pages","MainPage.vue"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await Q(h.join(a,"model","src","index.ts"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await Q(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}.*exec.builder.*[\\s\\S]*?\\n\\n`,"g")),await Q(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}Message.*\\n`,"g")),await Q(h.join(a,"workflow","src","wf.test.ts"),new RegExp(`.*${t}Message.*\\n.*expect.*\\n\\n`,"g")),await x.rm(h.join(a,"software",`src_${t}`),{recursive:!0}),await Me(h.join(a,"software","package.json"),r=>{const n=JSON.parse(r);return delete n["block-software"].artifacts[`hello-${t}-artifact`],delete n["block-software"].entrypoints[`hello-world-${t}`],JSON.stringify(n,null,2)})}async function Jr(a){await x.rm(h.join(a,"software"),{recursive:!0}),await Me(h.join(a,"workflow","package.json"),e=>{const t=JSON.parse(e);return delete t.dependencies["@platforma-open/my-org.block-boilerplate.software"],JSON.stringify(t,null,2)}),await Q(h.join(a,"pnpm-workspace.yaml"),/.*- software$\n/gm)}async function Hr(a,e){const t=await Wr(a);for(const{from:r,to:n}of e)for(const s of t)await hr(s,r,n)}async function Wr(a){return(await x.readdir(a,{withFileTypes:!0,recursive:!0})).filter(t=>t.isFile()).map(t=>h.join(t.parentPath,t.name))}async function Me(a,e){const t=await x.readFile(a),r=e(t.toString());await x.writeFile(a,r)}async function hr(a,e,t){return await Me(a,r=>r.replaceAll(e,t))}async function Q(a,e){return await hr(a,e,"")}const X=class X extends d.Command{async run(){const{flags:e}=await this.parse(X),t=L(e["log-level"]);await Br(t)}};l(X,"description","Helps to create a new block by downloading a block's template."),l(X,"examples",["<%= name %>"]),l(X,"flags",{...A});let Pe=X;function yr(...a){return h.resolve(__dirname,"..",...a)}function Y(...a){return yr("assets",...a)}function be(...a){return u.readFileSync(yr(...a))}function or(a){return a||(a=ue.getDefaultPlVersion()),`quay.io/milaboratories/platforma:${a}`}const N=class N{constructor(e){l(this,"state",{currentInstance:""});l(this,"filePath");l(this,"dirPath");e=e??h.resolve(T.homedir(),".config","pl-bootstrap");const t=h.join(e,"state.json");this.dirPath=e,this.filePath=t,u.existsSync(e)||u.mkdirSync(e,{recursive:!0}),u.existsSync(t)&&(this.state=JSON.parse(be(t).toString()))}static getStateInstance(){return N.instance||(N.instance=new N),N.instance}path(...e){return h.join(this.dirPath,...e)}instanceDir(e,...t){return e?this.path("data",e,...t):this.path("data")}binaries(...e){return this.path("binaries",...e)}writeState(){u.writeFileSync(this.filePath,JSON.stringify(this.state))}get instanceList(){return u.existsSync(this.instanceDir())?u.readdirSync(this.instanceDir()).filter(t=>this.instanceExists(t)):[]}instanceExists(e){return u.existsSync(this.instanceDir(e,"instance.json"))}getInstanceInfo(e){const t=this.instanceDir(e,"instance.json");if(!u.existsSync(t))throw new Error(`platforma backend instance '${e}' does not exist or is corrupted`);const r=JSON.parse(be(t).toString());return{name:e,...r}}setInstanceInfo(e,t){u.existsSync(this.instanceDir(e))||u.mkdirSync(this.instanceDir(e),{recursive:!0});const r=this.instanceDir(e,"instance.json");let n={};u.existsSync(r)&&(n=JSON.parse(be(r).toString())),u.writeFileSync(r,JSON.stringify({...n,...t}))}isInstanceActive(e){switch(e.type){case"docker":{const r=Cr(`pl-${e.name}`);return r?r.Status.trim().startsWith("running"):!1}case"process":return e.pid?lr(e.pid):!1;default:throw _(),new Error("cli logic error: unknown service type, cannot check its state")}}get isActive(){for(const e of this.instanceList){const t=this.getInstanceInfo(e);if(this.isInstanceActive(t))return!0}return!1}isValidPID(e){return lr(e)}get currentInstance(){const e=this.state.currentInstance;if(e&&this.instanceExists(e))return this.getInstanceInfo(e)}get currentInstanceName(){return this.state.currentInstance}set currentInstanceName(e){this.state.currentInstance=e,this.writeState()}selectInstance(e){if(!this.instanceExists(e))throw new Error(`instance '${e}' does not exist`);this.state.currentInstance=e,this.writeState()}};l(N,"instance");let ke=N;function lr(a){const e=Nr(a);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}const g=ke.getStateInstance();function pe(a,e,t){const r=[],n=[];for(const s of e)if(t={cwd:s.workdir,env:{...s.envs,...t==null?void 0:t.env},...s.runOpts,...t},s.async){const i=zr(a,s.cmd,s.args,t);n.push(i)}else{const i=Yr(a,s.cmd,s.args,t);if(r.push(i),i.error||i.status!==0)break}return{executed:r,spawned:n}}function zr(a,e,t,r){var c;a.debug(`Running:
11
+ `);return`${(i=>de.format.colorize().colorize(i,i))(e)}: ${n}`}),transports:[new de.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function _r(a){return Sr.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function Nr(a){return a.startsWith("~")?h.join(D.homedir(),a.slice(1)):a}function Se(a,e){m.existsSync(a)||(m.mkdirSync(a,{recursive:!0}),e!=null&&e.mode&&m.chmodSync(a,e.mode))}function Cr(a){try{if(D.platform()!=="win32")return ne.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,t=ne.execSync(e,{encoding:"utf8"}).split(`
12
+ `);return t.length<=1?"":t[1].trim()}catch{return""}}function Mr(a){const e=ne.execSync(`docker compose ls --filter name=${a} --format json`,{encoding:"utf8"}).trim(),t=JSON.parse(e);for(const r of t)if(r.Name===a)return r}const Ie=["Python"],hr=["Tengo","Python"],jr=x.z.union([x.z.literal("Tengo"),x.z.literal("Python")]),Br=x.z.object({npmOrgName:x.z.string().min(1),orgName:x.z.string().min(1),blockName:x.z.string().min(1),softwarePlatforms:x.z.array(jr).refine(a=>new Set(a).size===a.length,{message:"Must be an array of unique software platforms"})});async function Ur(a){const{npmOrgName:e,orgName:t,blockName:r,softwarePlatforms:n}=Gr(),s=h.join(process.cwd(),r);a.info("Downloading boilerplate code..."),await qr("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",s);const i=hr.filter(o=>n.indexOf(o)<0),c=Ie.length==i.length;a.info(`Keep platforms '${n}', remove: '${i}'. Will remove all platforms? ${c}`);for(const o of i)await Jr(s,o);c&&await Hr(s),a.info("Replace everything in the template with provided options..."),Wr(s,[{from:/@platforma-open(?!.*runenv-python-3)/g,to:`@${e}`},{from:/my-org/g,to:t},{from:/block-boilerplate/g,to:r}])}function Gr(){let a=Q.question('Write an organization name for npm. Default is "platforma-open": ');a===""&&(a="platforma-open");const e=Q.question('Write an organization name, e.g. "my-org": '),t=Q.question('Write a name of the block, e.g. "hello-world": '),r=Q.keyInYN("Create package for block's software?");let n=["Tengo"];if(r)for(;n.length<hr.length;){const s=Q.keyInSelect(Ie,"Choose software platform:");if(s<0)break;n.push(Ie[s])}return n=Array.from(new Set(n)).sort(),Br.parse({npmOrgName:a,orgName:e,blockName:t,softwarePlatforms:n})}async function qr(a,e,t){const n=await(await fetch(a)).blob(),s=await _.mkdtemp(h.join(D.tmpdir(),"create-repo")),i=h.join(s,"packed-repo.zip"),c=Lr.Writable.toWeb(m.createWriteStream(i));await n.stream().pipeTo(c);const o=h.join(s,"unpacked-repo");await _.mkdir(o),await Ar(i,o),await _.cp(h.join(o,e),t,{recursive:!0})}async function Jr(a,e){const t=e.toLowerCase();await X(h.join(a,"ui","src","pages","MainPage.vue"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await X(h.join(a,"model","src","index.ts"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await X(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}.*exec.builder.*[\\s\\S]*?\\n\\n`,"g")),await X(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}Message.*\\n`,"g")),await X(h.join(a,"workflow","src","wf.test.ts"),new RegExp(`.*${t}Message.*\\n.*expect.*\\n\\n`,"g")),await _.rm(h.join(a,"software",`src_${t}`),{recursive:!0}),await Be(h.join(a,"software","package.json"),r=>{const n=JSON.parse(r);return delete n["block-software"].artifacts[`hello-${t}-artifact`],delete n["block-software"].entrypoints[`hello-world-${t}`],JSON.stringify(n,null,2)})}async function Hr(a){await _.rm(h.join(a,"software"),{recursive:!0}),await Be(h.join(a,"workflow","package.json"),e=>{const t=JSON.parse(e);return delete t.dependencies["@platforma-open/my-org.block-boilerplate.software"],JSON.stringify(t,null,2)}),await X(h.join(a,"pnpm-workspace.yaml"),/.*- software$\n/gm)}async function Wr(a,e){const t=await zr(a);for(const{from:r,to:n}of e)for(const s of t)await yr(s,r,n)}async function zr(a){return(await _.readdir(a,{withFileTypes:!0,recursive:!0})).filter(t=>t.isFile()).map(t=>h.join(t.parentPath,t.name))}async function Be(a,e){const t=await _.readFile(a),r=e(t.toString());await _.writeFile(a,r)}async function yr(a,e,t){return await Be(a,r=>r.replaceAll(e,t))}async function X(a,e){return await yr(a,e,"")}const Z=class Z extends u.Command{async run(){const{flags:e}=await this.parse(Z),t=A(e["log-level"]);await Ur(t)}};l(Z,"description","Helps to create a new block by downloading a block's template."),l(Z,"examples",["<%= name %>"]),l(Z,"flags",{...L});let Oe=Z;function pr(...a){return h.resolve(__dirname,"..",...a)}function V(...a){return pr("assets",...a)}function $e(...a){return m.readFileSync(pr(...a))}function lr(a){return a||(a=fe.getDefaultPlVersion()),`quay.io/milaboratories/platforma:${a}`}const G=class G{constructor(e){l(this,"state",{currentInstance:""});l(this,"filePath");l(this,"dirPath");e=e??h.resolve(D.homedir(),".config","pl-bootstrap");const t=h.join(e,"state.json");this.dirPath=e,this.filePath=t,m.existsSync(e)||m.mkdirSync(e,{recursive:!0}),m.existsSync(t)&&(this.state=JSON.parse($e(t).toString()))}static getStateInstance(){return G.instance||(G.instance=new G),G.instance}path(...e){return h.join(this.dirPath,...e)}instanceDir(e,...t){return e?this.path("data",e,...t):this.path("data")}binaries(...e){return this.path("binaries",...e)}writeState(){m.writeFileSync(this.filePath,JSON.stringify(this.state))}get instanceList(){return m.existsSync(this.instanceDir())?m.readdirSync(this.instanceDir()).filter(t=>this.instanceExists(t)):[]}instanceExists(e){return m.existsSync(this.instanceDir(e,"instance.json"))}getInstanceInfo(e){const t=this.instanceDir(e,"instance.json");if(!m.existsSync(t))throw new Error(`platforma backend instance '${e}' does not exist or is corrupted`);const r=JSON.parse($e(t).toString());return{name:e,...r}}setInstanceInfo(e,t){m.existsSync(this.instanceDir(e))||m.mkdirSync(this.instanceDir(e),{recursive:!0});const r=this.instanceDir(e,"instance.json");let n={};m.existsSync(r)&&(n=JSON.parse($e(r).toString())),m.writeFileSync(r,JSON.stringify({...n,...t}))}isInstanceActive(e){switch(e.type){case"docker":{const r=Mr(`pl-${e.name}`);return r?r.Status.trim().startsWith("running"):!1}case"process":return e.pid?dr(e.pid):!1;default:throw U(),new Error("cli logic error: unknown service type, cannot check its state")}}get isActive(){for(const e of this.instanceList){const t=this.getInstanceInfo(e);if(this.isInstanceActive(t))return!0}return!1}isValidPID(e){return dr(e)}get currentInstance(){const e=this.state.currentInstance;if(e&&this.instanceExists(e))return this.getInstanceInfo(e)}get currentInstanceName(){return this.state.currentInstance}set currentInstanceName(e){this.state.currentInstance=e,this.writeState()}selectInstance(e){if(!this.instanceExists(e))throw new Error(`instance '${e}' does not exist`);this.state.currentInstance=e,this.writeState()}};l(G,"instance");let Fe=G;function dr(a){const e=Cr(a);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}const f=Fe.getStateInstance();function Le(a,e,t){const r=[],n=[];for(const s of e)if(t={cwd:s.workdir,env:{...s.envs,...t==null?void 0:t.env},...s.runOpts,...t},s.async){const i=Yr(a,s.cmd,s.args,t);n.push(i)}else{const i=Vr(a,s.cmd,s.args,t);if(r.push(i),i.error||i.status!==0)break}return{executed:r,spawned:n}}function Yr(a,e,t,r){var c;a.debug(`Running:
13
13
  env: ${JSON.stringify(r.env)}
14
14
  cmd: ${JSON.stringify([e,...t])}
15
- wd: ${(c=r.cwd)==null?void 0:c.toString()}`),r.env={...process.env,...r.env},a.debug(" spawning child process");const n=ae.spawn(e,t,r);let s=!1;const i=()=>{n.kill("SIGINT"),s=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",i),n.on("close",o=>{process.removeListener("SIGINT",i),s&&process.exit(o)}),n}function Yr(a,e,t,r){return a.debug(`Running:
15
+ wd: ${(c=r.cwd)==null?void 0:c.toString()}`),r.env={...process.env,...r.env},a.debug(" spawning child process");const n=ne.spawn(e,t,r);let s=!1;const i=()=>{n.kill("SIGINT"),s=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",i),n.on("close",o=>{process.removeListener("SIGINT",i),s&&process.exit(o)}),n}function Vr(a,e,t,r){return a.debug(`Running:
16
16
  cmd: ${JSON.stringify([e,...t])}
17
- opts: ${JSON.stringify(r)}`),r.env={...process.env,...r.env},ae.spawnSync(e,t,r)}function we(a,e,t,r,n){const s=u.readFileSync(a,{encoding:"utf-8"}),i=ge.parse(s.toString());if(!i.services)throw new Error(`file '${a}' seems to be not a docker-compose file or has unsupported version`);if(r)for(const c of Object.keys(i.services))r.has(c)||delete i.services[c];i.name=t;for(const[c,o]of(r==null?void 0:r.entries())??[]){const m=i.services[c];if(!m)throw new Error(`docker compose '${a}' has no declaration of service '${c}'`);if(o.platform&&(m.platform=o.platform),o.envs){m.environment||(m.environment=[]);for(let f=0;f<((m==null?void 0:m.environment.length)??0);){const w=m.environment[f].split("=")[0];if(o.envs[w]){const v=m.environment.pop();v&&m.environment.length!==f&&(m.environment[f]=v)}else f++}for(const[f,y]of Object.entries(o.envs))m.environment.push(`${f}=${y}`)}if(o.mounts){m.volumes||(m.volumes=[]);for(const f of o.mounts)m.volumes.push(`${f.hostPath}:${f.containerPath}`)}}n!=null&&n.dropVolumes&&delete i.volumes,u.writeFileSync(e,ge.stringify(i))}function Vr(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function br(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function V(a,e,t){a=_r(a);const r=new URL(a,`file:${e}`);switch(r.protocol){case"s3:":var i=r.hostname,n=r.searchParams.get("region");return{...t,type:"S3",bucketName:i,region:n};case"s3e:":var s=r.pathname.split("/").slice(1),i=s[0],c=s.length>1?s[1]:"";return{...t,type:"S3",endpoint:`http://${r.host}/`,bucketName:i,keyPrefix:c,region:r.searchParams.get("region"),key:r.username?`static:${r.username}`:"",secret:r.password?`static:${r.password}`:""};case"s3es:":var s=r.pathname.split("/").slice(1),i=s[0],c=s.length>1?s[1]:"";return{...t,type:"S3",endpoint:`https://${r.host}/`,bucketName:i,keyPrefix:c,region:r.searchParams.get("region"),key:r.username?`static:${r.username}`:"",secret:r.password?`static:${r.password}`:""};case"file:":return{type:"FS",rootPath:r.pathname};default:throw new Error(`storage protocol '${r.protocol}' is not supported`)}}function Kr(a,e){var v,b,P,S,k,p,$,ne,Be,Ge,Ue,qe,Je,He,We,ze,Ye,Ve,Ke,Qe,Xe,Ze,er,rr,tr,ar,nr,sr,ir,cr;const t=(e==null?void 0:e.localRoot)??g.instanceDir("default"),r={level:((v=e==null?void 0:e.log)==null?void 0:v.level)??"info",path:((b=e==null?void 0:e.log)==null?void 0:b.path)??`${t}/logs/platforma.log`},n={listen:((P=e==null?void 0:e.grpc)==null?void 0:P.listen)??"localhost:6345",tls:{enable:se((k=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:k.enable,!1),clientAuthMode:(($=(p=e==null?void 0:e.grpc)==null?void 0:p.tls)==null?void 0:$.clientAuthMode)??"NoAuth",certFile:((Be=(ne=e==null?void 0:e.grpc)==null?void 0:ne.tls)==null?void 0:Be.certFile)??`${t}/certs/tls.cert`,keyFile:((Ue=(Ge=e==null?void 0:e.grpc)==null?void 0:Ge.tls)==null?void 0:Ue.keyFile)??`${t}/certs/tls.key`,...(qe=e==null?void 0:e.grpc)==null?void 0:qe.tls}},s={auth:{enabled:((He=(Je=e==null?void 0:e.core)==null?void 0:Je.auth)==null?void 0:He.enabled)??!1,drivers:((ze=(We=e==null?void 0:e.core)==null?void 0:We.auth)==null?void 0:ze.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${t}/users.htpasswd`}]},db:{path:`${t}/db`}},i=dr("main",`${t}/storages/main`,"main-bucket",(Ye=e==null?void 0:e.storages)==null?void 0:Ye.primary);let c;switch((Ke=(Ve=e==null?void 0:e.storages)==null?void 0:Ve.work)==null?void 0:Ke.type){case void 0:case"FS":c=br("work"),c.rootPath=((Xe=(Qe=e==null?void 0:e.storages)==null?void 0:Qe.work)==null?void 0:Xe.rootPath)??`${t}/storages/work`,c.indexCachePeriod=((er=(Ze=e==null?void 0:e.storages)==null?void 0:Ze.work)==null?void 0:er.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const m=dr("library",`${t}/storages/library`,"library-bucket",(rr=e==null?void 0:e.storages)==null?void 0:rr.library),f={enabled:se((tr=e==null?void 0:e.monitoring)==null?void 0:tr.enabled,!0),listen:((ar=e==null?void 0:e.monitoring)==null?void 0:ar.listen)??"127.0.0.1:9090"},y={enabled:se((nr=e==null?void 0:e.debug)==null?void 0:nr.enabled,!0),listen:((sr=e==null?void 0:e.debug)==null?void 0:sr.listen)??"127.0.0.1:9091"},w={value:((ir=e==null?void 0:e.license)==null?void 0:ir.value)??"",file:((cr=e==null?void 0:e.license)==null?void 0:cr.file)??""};return{localRoot:t,license:w,log:r,grpc:n,core:s,monitoring:f,debug:y,storages:{primary:i,work:c,library:m},hacks:{libraryDownloadable:!0}}}function dr(a,e,t,r){let n;switch(r==null?void 0:r.type){case void 0:case"FS":n=br(a),n.rootPath=(r==null?void 0:r.rootPath)??e;break;case"S3":n=Vr(a),n.endpoint=(r==null?void 0:r.endpoint)??"http://localhost:9000",n.presignEndpoint=(r==null?void 0:r.presignEndpoint)??"http://localhost:9000",n.bucketName=(r==null?void 0:r.bucketName)??t,n.createBucket=se(r==null?void 0:r.createBucket,!0),n.forcePathStyle=se(r==null?void 0:r.forcePathStyle,!0),n.key=(r==null?void 0:r.key)??"",n.secret=(r==null?void 0:r.secret)??"",n.keyPrefix=(r==null?void 0:r.keyPrefix)??"",n.accessPrefixes=(r==null?void 0:r.accessPrefixes)??[""],n.uploadKeyPrefix=(r==null?void 0:r.uploadKeyPrefix)??"";break;default:throw _(),new Error("unknown storage type")}return n}function Qr(a){const e=a.monitoring.enabled?"":" disabled",t=a.debug.enabled?"":" disabled",r=a.hacks.libraryDownloadable?"true":"false";let n=a.license.value;return a.license.file!=""&&(n=u.readFileSync(a.license.file).toString().trimEnd()),`
17
+ opts: ${JSON.stringify(r)}`),r.env={...process.env,...r.env},ne.spawnSync(e,t,r)}function Ae(a,e,t,r,n){const s=m.readFileSync(a,{encoding:"utf-8"}),i=ue.parse(s.toString());if(!i.services)throw new Error(`file '${a}' seems to be not a docker-compose file or has unsupported version`);if(r)for(const c of Object.keys(i.services))r.has(c)||delete i.services[c];i.name=t;for(const[c,o]of(r==null?void 0:r.entries())??[]){const d=i.services[c];if(!d)throw new Error(`docker compose '${a}' has no declaration of service '${c}'`);if(o.platform&&(d.platform=o.platform),o.envs){d.environment||(d.environment=[]);for(let g=0;g<((d==null?void 0:d.environment.length)??0);){const w=d.environment[g].split("=")[0];if(o.envs[w]){const v=d.environment.pop();v&&d.environment.length!==g&&(d.environment[g]=v)}else g++}for(const[g,y]of Object.entries(o.envs))d.environment.push(`${g}=${y}`)}if(o.mounts){d.volumes||(d.volumes=[]);for(const g of o.mounts)d.volumes.push(`${g.hostPath}:${g.containerPath}`)}}n!=null&&n.dropVolumes&&delete i.volumes,m.writeFileSync(e,ue.stringify(i))}function Kr(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function br(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function K(a,e,t){a=Nr(a);const r=new URL(a,`file:${e}`);switch(r.protocol){case"s3:":var i=r.hostname,n=r.searchParams.get("region");return{...t,type:"S3",bucketName:i,region:n};case"s3e:":var s=r.pathname.split("/").slice(1),i=s[0],c=s.length>1?s[1]:"";return{...t,type:"S3",endpoint:`http://${r.host}/`,bucketName:i,keyPrefix:c,region:r.searchParams.get("region"),key:r.username?`static:${r.username}`:"",secret:r.password?`static:${r.password}`:""};case"s3es:":var s=r.pathname.split("/").slice(1),i=s[0],c=s.length>1?s[1]:"";return{...t,type:"S3",endpoint:`https://${r.host}/`,bucketName:i,keyPrefix:c,region:r.searchParams.get("region"),key:r.username?`static:${r.username}`:"",secret:r.password?`static:${r.password}`:""};case"file:":return{type:"FS",rootPath:r.pathname};default:throw new Error(`storage protocol '${r.protocol}' is not supported`)}}function Qr(a,e){var v,p,P,S,k,b,$,oe,Ue,Ge,qe,Je,He,We,ze,Ye,Ve,Ke,Qe,Xe,Ze,er,rr,tr,ar,nr,sr,ir,cr,or;const t=(e==null?void 0:e.localRoot)??f.instanceDir("default"),r={level:((v=e==null?void 0:e.log)==null?void 0:v.level)??"info",path:((p=e==null?void 0:e.log)==null?void 0:p.path)??`${t}/logs/platforma.log`},n={listen:((P=e==null?void 0:e.grpc)==null?void 0:P.listen)??"localhost:6345",tls:{enable:le((k=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:k.enable,!1),clientAuthMode:(($=(b=e==null?void 0:e.grpc)==null?void 0:b.tls)==null?void 0:$.clientAuthMode)??"NoAuth",certFile:((Ue=(oe=e==null?void 0:e.grpc)==null?void 0:oe.tls)==null?void 0:Ue.certFile)??`${t}/certs/tls.cert`,keyFile:((qe=(Ge=e==null?void 0:e.grpc)==null?void 0:Ge.tls)==null?void 0:qe.keyFile)??`${t}/certs/tls.key`,...(Je=e==null?void 0:e.grpc)==null?void 0:Je.tls}},s={auth:{enabled:((We=(He=e==null?void 0:e.core)==null?void 0:He.auth)==null?void 0:We.enabled)??!1,drivers:((Ye=(ze=e==null?void 0:e.core)==null?void 0:ze.auth)==null?void 0:Ye.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${t}/users.htpasswd`}]},db:{path:`${t}/db`}},i=gr("main",`${t}/storages/main`,"main-bucket",(Ve=e==null?void 0:e.storages)==null?void 0:Ve.primary);let c;switch((Qe=(Ke=e==null?void 0:e.storages)==null?void 0:Ke.work)==null?void 0:Qe.type){case void 0:case"FS":c=br("work"),c.rootPath=((Ze=(Xe=e==null?void 0:e.storages)==null?void 0:Xe.work)==null?void 0:Ze.rootPath)??`${t}/storages/work`,c.indexCachePeriod=((rr=(er=e==null?void 0:e.storages)==null?void 0:er.work)==null?void 0:rr.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const d=gr("library",`${t}/storages/library`,"library-bucket",(tr=e==null?void 0:e.storages)==null?void 0:tr.library),g={enabled:le((ar=e==null?void 0:e.monitoring)==null?void 0:ar.enabled,!0),listen:((nr=e==null?void 0:e.monitoring)==null?void 0:nr.listen)??"127.0.0.1:9090"},y={enabled:le((sr=e==null?void 0:e.debug)==null?void 0:sr.enabled,!0),listen:((ir=e==null?void 0:e.debug)==null?void 0:ir.listen)??"127.0.0.1:9091"},w={value:((cr=e==null?void 0:e.license)==null?void 0:cr.value)??"",file:((or=e==null?void 0:e.license)==null?void 0:or.file)??""};return{localRoot:t,license:w,log:r,grpc:n,core:s,monitoring:g,debug:y,storages:{primary:i,work:c,library:d},hacks:{libraryDownloadable:!0}}}function gr(a,e,t,r){let n;switch(r==null?void 0:r.type){case void 0:case"FS":n=br(a),n.rootPath=(r==null?void 0:r.rootPath)??e;break;case"S3":n=Kr(a),n.endpoint=(r==null?void 0:r.endpoint)??"http://localhost:9000",n.presignEndpoint=(r==null?void 0:r.presignEndpoint)??"http://localhost:9000",n.bucketName=(r==null?void 0:r.bucketName)??t,n.createBucket=le(r==null?void 0:r.createBucket,!0),n.forcePathStyle=le(r==null?void 0:r.forcePathStyle,!0),n.key=(r==null?void 0:r.key)??"",n.secret=(r==null?void 0:r.secret)??"",n.keyPrefix=(r==null?void 0:r.keyPrefix)??"",n.accessPrefixes=(r==null?void 0:r.accessPrefixes)??[""],n.uploadKeyPrefix=(r==null?void 0:r.uploadKeyPrefix)??"";break;default:throw U(),new Error("unknown storage type")}return n}function Xr(a){const e=a.monitoring.enabled?"":" disabled",t=a.debug.enabled?"":" disabled",r=a.hacks.libraryDownloadable?"true":"false";let n=a.license.value;return a.license.file!=""&&(n=m.readFileSync(a.license.file).toString().trimEnd()),`
18
18
  license:
19
19
  value: '${a.license.value}'
20
20
  file: '${a.license.file}'
@@ -88,22 +88,22 @@ controllers:
88
88
  packagesRoot: '${a.localRoot}/packages'
89
89
 
90
90
  workflows: {}
91
- `}function se(a,e){return a===void 0?e:a}const Xr=["linux","macos","windows"];function Zr(a){const e=T.platform();switch(e){case"darwin":return"macos";case"linux":return"linux";case"win32":return"windows";default:throw new Error(`operating system '${e}' is not currently supported by Platforma ecosystem. The list of OSes supported: `+JSON.stringify(Xr))}}const et=["amd64","arm64"];function pr(a){const e=T.arch();switch(e){case"arm64":return"arm64";case"x64":return"amd64";default:throw new Error(`processor architecture '${e}' is not currently supported by Platforma ecosystem. The list of architectures supported: `+JSON.stringify(et))}}function rt(a,e){const t=(e==null?void 0:e.version)??ue.getDefaultPlVersion(),r=(e==null?void 0:e.showProgress)??process.stdout.isTTY,n=`pl-${t}-${pr()}.tgz`,s=(e==null?void 0:e.downloadURL)??`https://cdn.platforma.bio/software/pl/${Zr()}/${n}`,i=(e==null?void 0:e.saveTo)??g.binaries(n);if(u.existsSync(i))return a.info(`Platforma Backend archive download skipped: '${i}' already exists`),Promise.resolve(i);u.mkdirSync(h.dirname(i),{recursive:!0}),a.info(`Downloading Platforma Backend archive:
91
+ `}function le(a,e){return a===void 0?e:a}const Zr=["linux","macos","windows"];function et(a){const e=D.platform();switch(e){case"darwin":return"macos";case"linux":return"linux";case"win32":return"windows";default:throw new Error(`operating system '${e}' is not currently supported by Platforma ecosystem. The list of OSes supported: `+JSON.stringify(Zr))}}const rt=["amd64","arm64"];function wr(a){const e=D.arch();switch(e){case"arm64":return"arm64";case"x64":return"amd64";default:throw new Error(`processor architecture '${e}' is not currently supported by Platforma ecosystem. The list of architectures supported: `+JSON.stringify(rt))}}function tt(a,e){const t=(e==null?void 0:e.version)??fe.getDefaultPlVersion(),r=(e==null?void 0:e.showProgress)??process.stdout.isTTY,n=`pl-${t}-${wr()}.tgz`,s=(e==null?void 0:e.downloadURL)??`https://cdn.platforma.bio/software/pl/${et()}/${n}`,i=(e==null?void 0:e.saveTo)??f.binaries(n);if(m.existsSync(i))return a.info(`Platforma Backend archive download skipped: '${i}' already exists`),Promise.resolve(i);m.mkdirSync(h.dirname(i),{recursive:!0}),a.info(`Downloading Platforma Backend archive:
92
92
  URL: ${s}
93
- Save to: ${i}`);const c=Lr.get(s);return new Promise((o,m)=>{c.on("response",f=>{if(!f.statusCode){const b=new Error("failed to download archive: no HTTP status code in response from server");c.destroy(),m(b);return}if(f.statusCode!==200){const b=new Error(`failed to download archive: ${f.statusCode} ${f.statusMessage}`);c.destroy(),m(b);return}const y=parseInt(f.headers["content-length"]||"0",10);let w=0;const v=u.createWriteStream(i);f.pipe(v),f.on("data",b=>{w+=b.length;const P=w/y*100;r&&process.stdout.write(` downloading: ${P.toFixed(2)}%\r`)}),f.on("error",b=>{u.unlinkSync(i),a.error(`Failed to download Platforma Binary: ${b.message}`),c.destroy(),m(b)}),v.on("finish",()=>{v.close(),a.info(" ... download done."),c.destroy(),o(i)})})})}function tt(a,e){a.debug("extracting archive...");const t=(e==null?void 0:e.version)??ue.getDefaultPlVersion();a.debug(` version: '${t}'`);const r=`${wr({version:t})}.tgz`,n=(e==null?void 0:e.archivePath)??g.binaries(r);a.debug(` archive path: '${n}'`);const s=(e==null?void 0:e.extractTo)??nt(n);if(a.debug(` target dir: '${s}'`),u.existsSync(s))return a.info(`Platforma Backend binaries unpack skipped: '${s}' exists`),s;if(!u.existsSync(n)){const i=`Platforma Backend binary archive not found at '${n}'`;throw a.error(i),new Error(i)}return u.existsSync(s)||(a.debug(` creating target dir '${s}'`),u.mkdirSync(s,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
93
+ Save to: ${i}`);const c=Ir.get(s);return new Promise((o,d)=>{c.on("response",g=>{if(!g.statusCode){const p=new Error("failed to download archive: no HTTP status code in response from server");c.destroy(),d(p);return}if(g.statusCode!==200){const p=new Error(`failed to download archive: ${g.statusCode} ${g.statusMessage}`);c.destroy(),d(p);return}const y=parseInt(g.headers["content-length"]||"0",10);let w=0;const v=m.createWriteStream(i);g.pipe(v),g.on("data",p=>{w+=p.length;const P=w/y*100;r&&process.stdout.write(` downloading: ${P.toFixed(2)}%\r`)}),g.on("error",p=>{m.unlinkSync(i),a.error(`Failed to download Platforma Binary: ${p.message}`),c.destroy(),d(p)}),v.on("finish",()=>{v.close(),a.info(" ... download done."),c.destroy(),o(i)})})})}function at(a,e){a.debug("extracting archive...");const t=(e==null?void 0:e.version)??fe.getDefaultPlVersion();a.debug(` version: '${t}'`);const r=`${vr({version:t})}.tgz`,n=(e==null?void 0:e.archivePath)??f.binaries(r);a.debug(` archive path: '${n}'`);const s=(e==null?void 0:e.extractTo)??st(n);if(a.debug(` target dir: '${s}'`),m.existsSync(s))return a.info(`Platforma Backend binaries unpack skipped: '${s}' exists`),s;if(!m.existsSync(n)){const i=`Platforma Backend binary archive not found at '${n}'`;throw a.error(i),new Error(i)}return m.existsSync(s)||(a.debug(` creating target dir '${s}'`),m.mkdirSync(s,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
94
94
  Archive: ${n}
95
- Target dir: ${s}`),Or.x({file:n,cwd:s,gzip:!0,sync:!0}),a.info(" ... unpack done."),s}function je(a,e){return rt(a,e).then(t=>tt(a,{archivePath:t}))}function wr(a){return`pl-${(a==null?void 0:a.version)??ue.getDefaultPlVersion()}-${pr()}`}function at(a,...e){return g.binaries(wr({version:a}),...e)}function nt(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class I{constructor(e){this.logger=e}startLast(){const e=g.currentInstance;if(!e)throw this.logger.error("failed to bring back Platforma Backend in the last started configuration: no last configuration found"),new Error("no previous run info found");return this.startInstance(e)}startInstance(e){if(e.runInfo){const r=this.renderRunInfo(e.runInfo);this.logger.info(`Starting platforma backend instance '${e.name}':
96
- ${r}`)}const t=pe(this.logger,e.upCommands);return de(t.executed),t.spawned.length>0&&e.type==="process"&&(e.pid=t.spawned[t.spawned.length-1].pid,g.setInstanceInfo(e.name,e),this.logger.info(`instance '${e.name}' started`)),g.currentInstanceName=e.name,t.spawned}stopInstance(e){if(!g.isInstanceActive(e)){this.logger.info(`instance '${e.name}' is not running`);return}this.logger.info(`stopping platforma backend instance '${e.name}'...`);const t=pe(this.logger,e.downCommands);switch(de(t.executed),e.type){case"docker":return;case"process":{e.pid&&g.isValidPID(e.pid)&&process.kill(e.pid);return}default:_()}}switchInstance(e){for(const t of g.instanceList)if(t!==e.name){const r=g.getInstanceInfo(t);g.isInstanceActive(r)&&this.stopInstance(r)}return this.startInstance(e)}createLocal(e,t){var o,m,f,y,w,v,b,P,S,k;const r=(t==null?void 0:t.binaryPath)??at(t==null?void 0:t.version,"binaries","platforma");let n=t==null?void 0:t.configPath;const s=(t==null?void 0:t.workdir)??(n?process.cwd():g.instanceDir(e));t!=null&&t.primaryURL&&(t.configOptions={...t.configOptions,storages:{...(o=t.configOptions)==null?void 0:o.storages,primary:V(t.primaryURL,s,(f=(m=t.configOptions)==null?void 0:m.storages)==null?void 0:f.primary)}}),t!=null&&t.libraryURL&&(t.configOptions={...t.configOptions,storages:{...(y=t.configOptions)==null?void 0:y.storages,library:V(t.libraryURL,s,(v=(w=t.configOptions)==null?void 0:w.storages)==null?void 0:v.library)}});const i=Kr(this.getLastJwt(),t==null?void 0:t.configOptions);this.logger.debug(" checking license..."),this.checkLicense((P=(b=t==null?void 0:t.configOptions)==null?void 0:b.license)==null?void 0:P.value,(k=(S=t==null?void 0:t.configOptions)==null?void 0:S.license)==null?void 0:k.file);const c=[`${i.localRoot}/packages`,`${i.localRoot}/packages-local`,`${i.localRoot}/blocks-local`];i.storages.primary.type==="FS"&&c.push(i.storages.primary.rootPath),i.storages.library.type==="FS"&&(c.push(i.storages.library.rootPath),i.hacks.libraryDownloadable=!1),i.storages.work.type==="FS"&&c.push(i.storages.work.rootPath),this.logger.debug(" creating pl state directories...");for(const p of c)u.existsSync(p)||(this.logger.debug(` '${p}'`),u.mkdirSync(p,{recursive:!0}));for(const p of i.core.auth.drivers)p.driver==="htpasswd"&&(u.existsSync(p.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${p.path}...`),u.copyFileSync(Y("users.htpasswd"),p.path)));return n||(n=h.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${n}'...`),u.writeFileSync(n,Qr(i))),g.setInstanceInfo(e,{type:"process",upCommands:[{async:!0,cmd:r,args:["-config",n],workdir:s,runOpts:{stdio:"inherit"}}],downCommands:[],cleanupCommands:[],runInfo:{configPath:n,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library}}),g.getInstanceInfo(e)}createLocalS3(e,t){var c;this.logger.debug("creating platforma instance in 'local s3' mode...");const r=(t==null?void 0:t.minioPort)??9e3,n=this.createLocal(e,{...t,primaryURL:(t==null?void 0:t.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(t==null?void 0:t.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`}),s=(c=t==null?void 0:t.configOptions)==null?void 0:c.localRoot,i=this.createMinio(e,{minioPort:r,minioConsolePort:t==null?void 0:t.minioConsolePort,storage:s?h.join(s,"minio"):void 0});return n.upCommands=[i.start,...n.upCommands],n.downCommands=[i.stop,...n.downCommands],n.cleanupCommands=[i.cleanup,...n.cleanupCommands],g.setInstanceInfo(e,n),n}createMinio(e,t){this.logger.debug(" creating docker compose for minio service...");const r=Y("compose-backend.yaml"),n=g.instanceDir(e,"compose-minio.yaml");we(r,n,`pl-${e}-minio`,new Map([["minio",{}]]),{dropVolumes:!0});const s=t!=null&&t.version?`:${t.version}`:"";this.logger.debug(` minio version: ${s}`);const i=(t==null?void 0:t.image)??`quay.io/minio/minio${s}`;this.logger.debug(` minio image: ${i}`);const c=(t==null?void 0:t.storage)??g.instanceDir(e,"minio");ye(c,{mode:"0775"});const o=(t==null?void 0:t.minioPort)??9e3,m=(t==null?void 0:t.minioConsolePort)??9001,f={MINIO_IMAGE:i,MINIO_STORAGE:h.resolve(c),MINIO_PORT:o.toString(),MINIO_CONSOLE_PORT:m.toString()};return{start:{cmd:"docker",args:["compose",`--file=${n}`,"up","--detach","--remove-orphans","--pull=missing"],envs:f,workdir:g.instanceDir(e),runOpts:{stdio:"inherit"}},stop:{cmd:"docker",args:["compose",`--file=${n}`,"down"],envs:f,workdir:g.instanceDir(e),runOpts:{stdio:"inherit"}},cleanup:{cmd:"docker",args:["compose",`--file=${n}`,"down","--volumes","--remove-orphans"],envs:f,workdir:g.instanceDir(e),runOpts:{stdio:"inherit"}}}}buildPlatforma(e){const t=h.resolve(e.repoRoot,"cmd","platforma"),r=e.binPath??h.join(T.tmpdir(),"platforma-local-build");this.logger.info("Building Platforma Backend binary from sources"),this.logger.info(` sources path: ${e.repoRoot}`),this.logger.info(` binary path: ${r}`);const n=ae.spawnSync("go",["build","-o",r,"."],{cwd:t,stdio:"inherit"});return de([n],"failed to build platforma binary from sources using 'go build' command"),r}createDockerS3(e,t,r){this.logger.debug("creating platforma instance in 'docker s3' mode...");const n=Y("compose-backend.yaml"),s=(r==null?void 0:r.image)??or(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...p)=>h.join(t,...p),c=p=>{const $=i(p);return ye($,{mode:"0775"}),$},o=i("logs","platforma.log");u.existsSync(o)||(u.mkdirSync(h.dirname(o),{recursive:!0}),u.writeFileSync(o,""));const m=(r==null?void 0:r.presignHost)??"localhost",f=V("s3e://testuser:testpassword@minio:9000/main-bucket");if(f.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");f.presignEndpoint=`http://${m}:9000`;const y=V("s3e://testuser:testpassword@minio:9000/library-bucket");if(y.type!=="S3")throw new Error(`${y.type} storage type is not supported for library storage`);y.presignEndpoint=`http://${m}:9000`;const w=c("db"),v=c("work"),b=i("users.htpasswd");u.existsSync(b)||u.copyFileSync(Y("users.htpasswd"),b);const P=i("compose.yaml");u.existsSync(P)&&this.logger.info(`replacing docker compose file ${P}`);const S=[];for(const p of(r==null?void 0:r.customMounts)??[])S.push({hostPath:p.hostPath,containerPath:p.containerPath??p.hostPath});we(n,P,`pl-${e}`,new Map([["minio",{}],["backend",{platform:r==null?void 0:r.platformOverride,mounts:S}]]));const k={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:b,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:w,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:v,...this.configureDockerStorage("primary",f),...this.configureDockerStorage("library",y)};if(r!=null&&r.grpcAddr&&(k.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(k.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(k.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(k.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(k.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(k.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(k.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const p of r.auth.drivers)p.driver==="htpasswd"&&(k.PL_AUTH_HTPASSWD_PATH=h.resolve(p.path),p.path="/etc/platforma/users.htpasswd");k.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return g.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"up","--detach","--remove-orphans","--pull=missing"],envs:k,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down"],envs:k,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down","--volumes","--remove-orphans"],envs:k,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:f,work:{type:"FS",rootPath:v},library:y,dbPath:w}}),g.getInstanceInfo(e)}createDocker(e,t,r){this.logger.debug("creating platforma instance in 'docker' mode...");const n=Y("compose-backend.yaml"),s=(r==null?void 0:r.image)??or(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...$)=>h.join(t,...$),c=$=>{const ne=i($);return ye(ne,{mode:"0775"}),ne},o=i("logs","platforma.log");u.existsSync(o)||(u.mkdirSync(h.dirname(o),{recursive:!0}),u.writeFileSync(o,""));const m=c("db"),f=c("primary"),y=c("library"),w=c("work"),v=i("users.htpasswd");u.existsSync(v)||u.copyFileSync(Y("users.htpasswd"),v);const b=i("compose.yaml");u.existsSync(b)&&this.logger.info(`replacing docker compose file ${b}`);const P=[];for(const $ of(r==null?void 0:r.customMounts)??[])P.push({hostPath:$.hostPath,containerPath:$.containerPath??$.hostPath});this.logger.debug(`Rendering docker compose file '${b}' using '${n}' as base template`),we(n,b,`pl-${e}`,new Map([["backend",{platform:r==null?void 0:r.platformOverride,mounts:P}]]));const S=V((r==null?void 0:r.primaryStorageURL)??`file:${f}`,"."),k=V((r==null?void 0:r.libraryStorageURL)??`file:${y}`,"."),p={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:v,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:m,PL_DATA_PRIMARY_ROOT:f,PL_DATA_LIBRARY_ROOT:y,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",S),...this.configureDockerStorage("library",k)};if(r!=null&&r.grpcAddr&&(p.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(p.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(p.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(p.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(p.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(p.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(p.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const $ of r.auth.drivers)$.driver==="htpasswd"&&(p.PL_AUTH_HTPASSWD_PATH=h.resolve($.path),$.path="/etc/platforma/users.htpasswd");p.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return g.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"up","--detach","--remove-orphans","--pull=missing"],envs:p,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down"],envs:p,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down","--volumes","--remove-orphans"],envs:p,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:S,work:{type:"FS",rootPath:w},library:k,dbPath:m}}),g.getInstanceInfo(e)}cleanupInstance(e){const t=[],r=new Map;let n="";if(e){const s=g.getInstanceInfo(e);switch(r.set(e,s),s.type){case"docker":{t.push(`docker service 'pl-${e}', including all its volumes and data in '${g.instanceDir(e)}' will be destroyed`);break}case"process":{t.push(`directory '${g.instanceDir(e)}' would be deleted`),s.downCommands&&t.push("associated docker service, including all volumes and data will be destroyed");break}default:_()}e===g.currentInstanceName&&t.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)"),n=`
95
+ Target dir: ${s}`),Fr.x({file:n,cwd:s,gzip:!0,sync:!0}),a.info(" ... unpack done."),s}function ke(a,e){return tt(a,e).then(t=>at(a,{archivePath:t}))}function vr(a){return`pl-${(a==null?void 0:a.version)??fe.getDefaultPlVersion()}-${wr()}`}function nt(a,...e){return f.binaries(vr({version:a}),...e)}function st(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class I{constructor(e){this.logger=e}startLast(){const e=f.currentInstance;if(!e)throw this.logger.error("failed to bring back Platforma Backend in the last started configuration: no last configuration found"),new Error("no previous run info found");return this.startInstance(e)}startInstance(e){if(e.runInfo){const r=this.renderRunInfo(e.runInfo);this.logger.info(`Starting platforma backend instance '${e.name}':
96
+ ${r}`)}const t=Le(this.logger,e.upCommands);return ge(t.executed),t.spawned.length>0&&e.type==="process"&&(e.pid=t.spawned[t.spawned.length-1].pid,f.setInstanceInfo(e.name,e),this.logger.info(`instance '${e.name}' started`)),f.currentInstanceName=e.name,t.spawned}stopInstance(e){if(!f.isInstanceActive(e)){this.logger.info(`instance '${e.name}' is not running`);return}this.logger.info(`stopping platforma backend instance '${e.name}'...`);const t=Le(this.logger,e.downCommands);switch(ge(t.executed),e.type){case"docker":return;case"process":{e.pid&&f.isValidPID(e.pid)&&process.kill(e.pid);return}default:U()}}switchInstance(e){for(const t of f.instanceList)if(t!==e.name){const r=f.getInstanceInfo(t);f.isInstanceActive(r)&&this.stopInstance(r)}return this.startInstance(e)}createLocal(e,t){var o,d,g,y,w,v,p,P,S,k;const r=(t==null?void 0:t.binaryPath)??nt(t==null?void 0:t.version,"binaries","platforma");let n=t==null?void 0:t.configPath;const s=(t==null?void 0:t.workdir)??(n?process.cwd():f.instanceDir(e));t!=null&&t.primaryURL&&(t.configOptions={...t.configOptions,storages:{...(o=t.configOptions)==null?void 0:o.storages,primary:K(t.primaryURL,s,(g=(d=t.configOptions)==null?void 0:d.storages)==null?void 0:g.primary)}}),t!=null&&t.libraryURL&&(t.configOptions={...t.configOptions,storages:{...(y=t.configOptions)==null?void 0:y.storages,library:K(t.libraryURL,s,(v=(w=t.configOptions)==null?void 0:w.storages)==null?void 0:v.library)}});const i=Qr(this.getLastJwt(),t==null?void 0:t.configOptions);this.logger.debug(" checking license..."),this.checkLicense((P=(p=t==null?void 0:t.configOptions)==null?void 0:p.license)==null?void 0:P.value,(k=(S=t==null?void 0:t.configOptions)==null?void 0:S.license)==null?void 0:k.file);const c=[`${i.localRoot}/packages`,`${i.localRoot}/packages-local`,`${i.localRoot}/blocks-local`];i.storages.primary.type==="FS"&&c.push(i.storages.primary.rootPath),i.storages.library.type==="FS"&&(c.push(i.storages.library.rootPath),i.hacks.libraryDownloadable=!1),i.storages.work.type==="FS"&&c.push(i.storages.work.rootPath),this.logger.debug(" creating pl state directories...");for(const b of c)m.existsSync(b)||(this.logger.debug(` '${b}'`),m.mkdirSync(b,{recursive:!0}));for(const b of i.core.auth.drivers)b.driver==="htpasswd"&&(m.existsSync(b.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${b.path}...`),m.copyFileSync(V("users.htpasswd"),b.path)));return n||(n=h.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${n}'...`),m.writeFileSync(n,Xr(i))),f.setInstanceInfo(e,{type:"process",upCommands:[{async:!0,cmd:r,args:["-config",n],workdir:s,runOpts:{stdio:"inherit"}}],downCommands:[],cleanupCommands:[],runInfo:{configPath:n,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library}}),f.getInstanceInfo(e)}createLocalS3(e,t){var c;this.logger.debug("creating platforma instance in 'local s3' mode...");const r=(t==null?void 0:t.minioPort)??9e3,n=this.createLocal(e,{...t,primaryURL:(t==null?void 0:t.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(t==null?void 0:t.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`}),s=(c=t==null?void 0:t.configOptions)==null?void 0:c.localRoot,i=this.createMinio(e,{minioPort:r,minioConsolePort:t==null?void 0:t.minioConsolePort,storage:s?h.join(s,"minio"):void 0});return n.upCommands=[i.start,...n.upCommands],n.downCommands=[i.stop,...n.downCommands],n.cleanupCommands=[i.cleanup,...n.cleanupCommands],f.setInstanceInfo(e,n),n}createMinio(e,t){this.logger.debug(" creating docker compose for minio service...");const r=V("compose-backend.yaml"),n=f.instanceDir(e,"compose-minio.yaml");Ae(r,n,`pl-${e}-minio`,new Map([["minio",{}]]),{dropVolumes:!0});const s=t!=null&&t.version?`:${t.version}`:"";this.logger.debug(` minio version: ${s}`);const i=(t==null?void 0:t.image)??`quay.io/minio/minio${s}`;this.logger.debug(` minio image: ${i}`);const c=(t==null?void 0:t.storage)??f.instanceDir(e,"minio");Se(c,{mode:"0775"});const o=(t==null?void 0:t.minioPort)??9e3,d=(t==null?void 0:t.minioConsolePort)??9001,g={MINIO_IMAGE:i,MINIO_STORAGE:h.resolve(c),MINIO_PORT:o.toString(),MINIO_CONSOLE_PORT:d.toString()};return{start:{cmd:"docker",args:["compose",`--file=${n}`,"up","--detach","--remove-orphans","--pull=missing"],envs:g,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}},stop:{cmd:"docker",args:["compose",`--file=${n}`,"down"],envs:g,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}},cleanup:{cmd:"docker",args:["compose",`--file=${n}`,"down","--volumes","--remove-orphans"],envs:g,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}}}}buildPlatforma(e){const t=h.resolve(e.repoRoot,"cmd","platforma"),r=e.binPath??h.join(D.tmpdir(),"platforma-local-build");this.logger.info("Building Platforma Backend binary from sources"),this.logger.info(` sources path: ${e.repoRoot}`),this.logger.info(` binary path: ${r}`);const n=ne.spawnSync("go",["build","-o",r,"."],{cwd:t,stdio:"inherit"});return ge([n],"failed to build platforma binary from sources using 'go build' command"),r}createDockerS3(e,t,r){this.logger.debug("creating platforma instance in 'docker s3' mode...");const n=V("compose-backend.yaml"),s=(r==null?void 0:r.image)??lr(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...b)=>h.join(t,...b),c=b=>{const $=i(b);return Se($,{mode:"0775"}),$},o=i("logs","platforma.log");m.existsSync(o)||(m.mkdirSync(h.dirname(o),{recursive:!0}),m.writeFileSync(o,""));const d=(r==null?void 0:r.presignHost)??"localhost",g=K("s3e://testuser:testpassword@minio:9000/main-bucket");if(g.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");g.presignEndpoint=`http://${d}:9000`;const y=K("s3e://testuser:testpassword@minio:9000/library-bucket");if(y.type!=="S3")throw new Error(`${y.type} storage type is not supported for library storage`);y.presignEndpoint=`http://${d}:9000`;const w=c("db"),v=c("work"),p=i("users.htpasswd");m.existsSync(p)||m.copyFileSync(V("users.htpasswd"),p);const P=i("compose.yaml");m.existsSync(P)&&this.logger.info(`replacing docker compose file ${P}`);const S=[];for(const b of(r==null?void 0:r.customMounts)??[])S.push({hostPath:b.hostPath,containerPath:b.containerPath??b.hostPath});Ae(n,P,`pl-${e}`,new Map([["minio",{}],["backend",{platform:r==null?void 0:r.platformOverride,mounts:S}]]));const k={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:p,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:w,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:v,...this.configureDockerStorage("primary",g),...this.configureDockerStorage("library",y)};if(r!=null&&r.grpcAddr&&(k.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(k.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(k.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(k.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(k.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(k.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(k.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const b of r.auth.drivers)b.driver==="htpasswd"&&(k.PL_AUTH_HTPASSWD_PATH=h.resolve(b.path),b.path="/etc/platforma/users.htpasswd");k.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return f.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"up","--detach","--remove-orphans","--pull=missing"],envs:k,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down"],envs:k,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down","--volumes","--remove-orphans"],envs:k,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:g,work:{type:"FS",rootPath:v},library:y,dbPath:w}}),f.getInstanceInfo(e)}createDocker(e,t,r){this.logger.debug("creating platforma instance in 'docker' mode...");const n=V("compose-backend.yaml"),s=(r==null?void 0:r.image)??lr(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...$)=>h.join(t,...$),c=$=>{const oe=i($);return Se(oe,{mode:"0775"}),oe},o=i("logs","platforma.log");m.existsSync(o)||(m.mkdirSync(h.dirname(o),{recursive:!0}),m.writeFileSync(o,""));const d=c("db"),g=c("primary"),y=c("library"),w=c("work"),v=i("users.htpasswd");m.existsSync(v)||m.copyFileSync(V("users.htpasswd"),v);const p=i("compose.yaml");m.existsSync(p)&&this.logger.info(`replacing docker compose file ${p}`);const P=[];for(const $ of(r==null?void 0:r.customMounts)??[])P.push({hostPath:$.hostPath,containerPath:$.containerPath??$.hostPath});this.logger.debug(`Rendering docker compose file '${p}' using '${n}' as base template`),Ae(n,p,`pl-${e}`,new Map([["backend",{platform:r==null?void 0:r.platformOverride,mounts:P}]]));const S=K((r==null?void 0:r.primaryStorageURL)??`file:${g}`,"."),k=K((r==null?void 0:r.libraryStorageURL)??`file:${y}`,"."),b={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:v,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:d,PL_DATA_PRIMARY_ROOT:g,PL_DATA_LIBRARY_ROOT:y,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",S),...this.configureDockerStorage("library",k)};if(r!=null&&r.grpcAddr&&(b.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(b.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(b.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(b.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(b.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(b.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(b.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const $ of r.auth.drivers)$.driver==="htpasswd"&&(b.PL_AUTH_HTPASSWD_PATH=h.resolve($.path),$.path="/etc/platforma/users.htpasswd");b.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return f.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${p}`,"up","--detach","--remove-orphans","--pull=missing"],envs:b,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${p}`,"down"],envs:b,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${p}`,"down","--volumes","--remove-orphans"],envs:b,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:S,work:{type:"FS",rootPath:w},library:k,dbPath:d}}),f.getInstanceInfo(e)}cleanupInstance(e){const t=[],r=new Map;let n="";if(e){const s=f.getInstanceInfo(e);switch(r.set(e,s),s.type){case"docker":{t.push(`docker service 'pl-${e}', including all its volumes and data in '${f.instanceDir(e)}' will be destroyed`);break}case"process":{t.push(`directory '${f.instanceDir(e)}' would be deleted`),s.downCommands&&t.push("associated docker service, including all volumes and data will be destroyed");break}default:U()}e===f.currentInstanceName&&t.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)"),n=`
97
97
  You are going to reset the state of platforma service '${e}':
98
98
  - ${t.join(`
99
99
  - `)}
100
- `}else{for(const s of g.instanceList)r.set(s,g.getInstanceInfo(s));t.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)",`all service configurations stored in: ${g.instanceDir()} (including all associated docker containers and volumes)`),n=`
100
+ `}else{for(const s of f.instanceList)r.set(s,f.getInstanceInfo(s));t.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)",`all service configurations stored in: ${f.instanceDir()} (including all associated docker containers and volumes)`),n=`
101
101
  You are going to reset the state of all platforma services configured with pl-bootstrap package.
102
102
  - ${t.join(`
103
103
  - `)}
104
- `}if(this.logger.warn(n),!Dr("Are you sure?")){this.logger.info("Reset action was canceled");return}for(const[s,i]of r.entries()){if(i.cleanupCommands.length){this.logger.info(`Wiping instance ${s} services`);const c=pe(this.logger,i.cleanupCommands);de(c.executed,`failed to wipe instance ${s} services`)}this.logger.info(`Destroying instance '${s}' data directory`),u.rmSync(g.instanceDir(s),{recursive:!0,force:!0})}e||(this.logger.info(`Destroying state dir '${g.path()}'`),u.rmSync(g.path(),{recursive:!0,force:!0})),this.logger.info(`
105
- If you want to remove all downloaded platforma binaries, delete '${g.binaries()}' dir manually
106
- `)}mergeLicenseEnvs(e){e.license===void 0&&((process.env.MI_LICENSE??"")!=""?e.license=process.env.MI_LICENSE:(process.env.PL_LICENSE??"")!=""&&(e.license=process.env.PL_LICENSE)),e["license-file"]===void 0&&e.license===void 0&&((process.env.MI_LICENSE_FILE??"")!=""?e["license-file"]=process.env.MI_LICENSE_FILE:(process.env.PL_LICENSE_FILE??"")!=""?e["license-file"]=process.env.PL_LICENSE_FILE:u.existsSync(h.resolve(T.homedir(),".pl.license"))&&(e["license-file"]=h.resolve(T.homedir(),".pl.license")))}initAuthDriversList(e,t){const r=[];if(e["auth-htpasswd-file"]&&r.push({driver:"htpasswd",path:h.resolve(t,e["auth-htpasswd-file"])}),!!e["auth-ldap-server"]!=!!e["auth-ldap-default-dn"])throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");if(e["auth-ldap-server"]&&r.push({driver:"ldap",serverUrl:e["auth-ldap-server"],defaultDN:e["auth-ldap-default-dn"]}),r.length!==0)return[{driver:"jwt",key:this.getLastJwt()},...r]}getLastJwt(){const e=g.path("auth.jwt"),t="utf-8";let r="";return u.existsSync(e)&&(r=u.readFileSync(e,{encoding:t})),r==""&&(r=xr(64),u.writeFileSync(e,r,{encoding:t})),r}checkLicense(e,t){if(!(e!==void 0&&e!="")&&!(t!==void 0&&t!=""))throw this.logger.error(`A license for Platforma Backend must be set.
104
+ `}if(this.logger.warn(n),!xr("Are you sure?")){this.logger.info("Reset action was canceled");return}for(const[s,i]of r.entries()){if(i.cleanupCommands.length){this.logger.info(`Wiping instance ${s} services`);const c=Le(this.logger,i.cleanupCommands);ge(c.executed,`failed to wipe instance ${s} services`)}this.logger.info(`Destroying instance '${s}' data directory`),m.rmSync(f.instanceDir(s),{recursive:!0,force:!0})}e||(this.logger.info(`Destroying state dir '${f.path()}'`),m.rmSync(f.path(),{recursive:!0,force:!0})),this.logger.info(`
105
+ If you want to remove all downloaded platforma binaries, delete '${f.binaries()}' dir manually
106
+ `)}mergeLicenseEnvs(e){e.license===void 0&&((process.env.MI_LICENSE??"")!=""?e.license=process.env.MI_LICENSE:(process.env.PL_LICENSE??"")!=""&&(e.license=process.env.PL_LICENSE)),e["license-file"]===void 0&&e.license===void 0&&((process.env.MI_LICENSE_FILE??"")!=""?e["license-file"]=process.env.MI_LICENSE_FILE:(process.env.PL_LICENSE_FILE??"")!=""?e["license-file"]=process.env.PL_LICENSE_FILE:m.existsSync(h.resolve(D.homedir(),".pl.license"))&&(e["license-file"]=h.resolve(D.homedir(),".pl.license")))}initAuthDriversList(e,t){const r=[];if(e["auth-htpasswd-file"]&&r.push({driver:"htpasswd",path:h.resolve(t,e["auth-htpasswd-file"])}),!!e["auth-ldap-server"]!=!!e["auth-ldap-default-dn"])throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");if(e["auth-ldap-server"]&&r.push({driver:"ldap",serverUrl:e["auth-ldap-server"],defaultDN:e["auth-ldap-default-dn"]}),r.length!==0)return[{driver:"jwt",key:this.getLastJwt()},...r]}getLastJwt(){const e=f.path("auth.jwt"),t="utf-8";let r="";return m.existsSync(e)&&(r=m.readFileSync(e,{encoding:t})),r==""&&(r=_r(64),m.writeFileSync(e,r,{encoding:t})),r}checkLicense(e,t){if(!(e!==void 0&&e!="")&&!(t!==void 0&&t!=""))throw this.logger.error(`A license for Platforma Backend must be set.
107
107
 
108
108
  You can provide the license directly using the '--license' flag
109
109
  or use the '--license-file' flag if the license is stored in a file.
@@ -113,6 +113,6 @@ Alternatively, you can set it via the environment variables 'MI_LICENSE' or 'PL_
113
113
  The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LICENSE_FILE',
114
114
  or stored in '$HOME/.pl.license'.
115
115
 
116
- You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,t){const r={},n=t.type;switch(e=e.toUpperCase(),n){case"S3":return r[`PL_DATA_${e}_TYPE`]="S3",r[`PL_DATA_${e}_S3_BUCKET`]=t.bucketName,t.endpoint&&(r[`PL_DATA_${e}_S3_ENDPOINT`]=t.endpoint),t.presignEndpoint&&(r[`PL_DATA_${e}_S3_PRESIGN_ENDPOINT`]=t.presignEndpoint),t.region&&(r[`PL_DATA_${e}_S3_REGION`]=t.region),t.key&&(r[`PL_DATA_${e}_S3_KEY`]=t.key),t.secret&&(r[`PL_DATA_${e}_S3_SECRET`]=t.secret),r;case"FS":return r[`PL_DATA_${e}_TYPE`]="FS",r;default:_()}return{}}renderRunInfo(e,t=10){var c,o;const r=[],n=m=>m.padStart(t," ");switch(e.configPath&&r.push(`${n("config")}: ${e.configPath}`),e.apiAddr?r.push(`${n("API")}: ${e.apiAddr}`):e.apiPort?r.push(`${n("API")}: 127.0.0.1:${e.apiPort.toString()}`):r.push(`${n("API")}: 127.0.0.1:6345`),e.logPath&&r.push(`${n("log")}: ${e.logPath}`),(c=e.primary)==null?void 0:c.type){case void 0:break;case"FS":r.push(`${n("primary")}: ${e.primary.rootPath}`);break;case"S3":r.push(`${n("primary")}: S3 at '${e.primary.endpoint??"AWS"}', bucket '${e.primary.bucketName}', prefix: '${e.primary.keyPrefix??""}'`);break;default:_()}switch((o=e.library)==null?void 0:o.type){case void 0:break;case"FS":r.push(`${n("library")}: ${e.library.rootPath}`);break;case"S3":r.push(`${n("library")}: S3 at '${e.library.endpoint??"AWS"}', bucket '${e.library.bucketName}', prefix: '${e.library.keyPrefix??""}'`);break;default:_()}return e.work&&r.push(`${n("workdirs")}: ${e.work.rootPath}`),e.dbPath&&r.push(`${n("db")}: ${e.dbPath}`),r.join(`
117
- `)}readComposeFile(e){const t=u.readFileSync(e);return ge.parse(t.toString())}writeComposeFile(e,t){u.writeFileSync(e,ge.stringify(t))}}function de(a,e){for(const t of a){if(t.error)throw t.error;const r=e??"failed to run command";if(t.status!==0)throw new Error(`${r}, process exited with code '${t.status}'`)}}const Z=class Z extends d.Command{async run(){const{flags:e}=await this.parse(Z),t=L(e["log-level"]);new I(t).cleanupInstance()}};l(Z,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),l(Z,"examples",["<%= config.bin %> <%= command.id %>"]),l(Z,"flags",{...A});let Se=Z;const ee=class ee extends d.Command{async run(){const{flags:e}=await this.parse(ee),t=L(e["log-level"]);new I(t).startLast()}};l(ee,"description","Start last run service configuraiton"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]),l(ee,"flags",{...A});let $e=ee;const re=class re extends d.Command{async run(){const{flags:e}=await this.parse(re),t=L(e["log-level"]),r=new I(t);g.currentInstance?r.stopInstance(g.currentInstance):t.warn("up/start command was not called for any instance, nothing to stop")}};l(re,"description","Stop platforma service"),l(re,"examples",["<%= config.bin %> <%= command.id %>"]),l(re,"flags",{...A});let Ae=re;var O;let st=(O=class extends d.Command{async run(){const{flags:e}=await this.parse(O),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):g.instanceDir(n),o=[];for(const y of e.mount??[])o.push({hostPath:y});const m=e.arch?`linux/${e.arch}`:void 0,f=r.createDocker(n,c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:m,customMounts:o,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]});r.switchInstance(f)}},l(O,"description","Run platforma backend service with 'FS' primary storage type"),l(O,"examples",["<%= config.bin %> <%= command.id %>"]),l(O,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...ce,...ie,...oe}),O);var F;let it=(F=class extends d.Command{async run(){const{flags:e}=await this.parse(F),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):g.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),m=e["auth-enabled"]??o!==void 0;let f=e["pl-binary"];e["pl-sources"]&&(f=r.buildPlatforma({repoRoot:e["pl-sources"]}));let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const b={binaryPath:f,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},P=r.createLocal(n,b);b.binaryPath?r.switchInstance(P):je(t,{version:e.version}).then(()=>{const S=r.switchInstance(P);setTimeout(()=>{for(const k of S)k.unref()},1e3)}).catch(function(S){t.error(S.message)})}},l(F,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(F,"examples",["<%= config.bin %> <%= command.id %>"]),l(F,"flags",{...A,...q,...H,..._e,...Ne,...Ce,...J,...W,...ce,...ie,...oe,...De,...xe,...z}),F);const C=class C extends d.Command{async run(){const{flags:e,args:t}=await this.parse(C),r=L(e["log-level"]),n=new I(r),s=t.name;e.all&&(n.cleanupInstance(),process.exit(0)),s||(r.error("Please, specify name of instance to be removed or set '--all' flag instead"),process.exit(1)),n.cleanupInstance(s)}};l(C,"description","List available instances"),l(C,"examples",["<%= config.bin %> <%= command.id %>"]),l(C,"flags",{...A,all:d.Flags.boolean({description:"remove all known instances",required:!1})}),l(C,"args",{name:d.Args.string({required:!1})});let Le=C;const M=class M extends d.Command{async run(){const{flags:e,args:t}=await this.parse(M),r=L(e["log-level"]),n=new I(r),s=t.name??g.currentInstanceName;s||(r.info("no pl service instance selected. No service was stopped"),process.exit(0)),n.stopInstance(g.getInstanceInfo(s))}};l(M,"description","List available instances"),l(M,"examples",["<%= config.bin %> <%= command.id %>"]),l(M,"flags",{...A}),l(M,"args",{name:d.Args.string({required:!1})});let Ie=M;const te=class te extends d.Command{async run(){await this.parse(te);const e=g.instanceList,t=g.currentInstanceName;for(const r of e){const n=[],s=g.getInstanceInfo(r);g.isInstanceActive(s)&&n.push("status:up"),n.push(`type:${s.type}`),console.log(r===t?` * ${r} (${n.join(", ")})`:` ${r} (${n.join(", ")})`)}}};l(te,"description","List available instances"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]),l(te,"flags",{});let Oe=te;const j=class j extends d.Command{async run(){const{flags:e,args:t}=await this.parse(j),r=L(e["log-level"]),n=new I(r),s=t.name??g.currentInstanceName;s||(r.error("no pl service instance is selected. Select instance with 'select' command or provide name to 'up'"),process.exit(1));const i=n.switchInstance(g.getInstanceInfo(s));setTimeout(()=>{for(const c of i)c.unref()},1e3)}};l(j,"description","List available instances"),l(j,"examples",["<%= config.bin %> <%= command.id %>"]),l(j,"flags",{...A}),l(j,"args",{name:d.Args.string({required:!1})});let Fe=j;var E;let ct=(E=class extends d.Command{async run(){const{flags:e}=await this.parse(E),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker-s3",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):g.instanceDir(n),o=[];for(const w of e.mount??[])o.push({hostPath:w});const m=e.arch?`linux/${e.arch}`:void 0,f=e["minio-presign-host"]?"minio":"localhost",y=r.createDockerS3(n,c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:m,customMounts:o,auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:f});r.switchInstance(y)}},l(E,"description","Run platforma backend service with 'S3' primary storage type"),l(E,"examples",["<%= config.bin %> <%= command.id %>"]),l(E,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...fr}),E);var R;let ot=(R=class extends d.Command{async run(){const{flags:e}=await this.parse(R),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local-s3",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):g.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),m=e["auth-enabled"]??o!==void 0;let f=e["pl-binary"];e["pl-sources"]&&(f=r.buildPlatforma({repoRoot:e["pl-sources"]}));let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const b={binaryPath:f,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},P=r.createLocalS3(n,b);b.binaryPath?r.switchInstance(P):je(t,{version:e.version}).then(()=>{const S=r.switchInstance(P);setTimeout(()=>{for(const k of S)k.unref()},1e3)}).catch(function(S){t.error(S.message)})}},l(R,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(R,"examples",["<%= config.bin %> <%= command.id %>"]),l(R,"flags",{...A,...q,...H,...ur,..._e,...Ne,...Ce,...J,...W,...ce,...ie,...oe,...De,...xe,...z}),R);const B=class B extends d.Command{async run(){const{flags:e,args:t}=await this.parse(B),r=L(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):g.instanceDir(s),m=[];for(const y of e.mount??[])m.push({hostPath:y});const f=e.arch?`linux/${e.arch}`:void 0;n.createDocker(s,o,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:f,customMounts:m,license:e.license,licenseFile:e["license-file"],auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]}),r.info(`Instance '${s}' was created. To start it run 'up' command`)}};l(B,"description","Run Platforma Backend service as docker container on current host"),l(B,"examples",["<%= config.bin %> <%= command.id %>"]),l(B,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...ce,...ie,...oe}),l(B,"args",{name:d.Args.string({required:!0})});let Ee=B;const G=class G extends d.Command{async run(){const{flags:e,args:t}=await this.parse(G),r=L(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):g.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,m=n.initAuthDriversList(e,i),f=e["auth-enabled"]??m!==void 0;let y=e["pl-binary"];e["pl-sources"]&&(y=n.buildPlatforma({repoRoot:e["pl-sources"]}));let w="127.0.0.1:6345";e["grpc-listen"]?w=e["grpc-listen"]:e["grpc-port"]&&(w=`127.0.0.1:${e["grpc-port"]}`);let v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);let b="127.0.0.1:9091";e["debug-listen"]?b=e["debug-listen"]:e["debug-port"]&&(b=`127.0.0.1:${e["debug-port"]}`);const P={binaryPath:y,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:w},monitoring:{listen:v},debug:{listen:b},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:f,drivers:m}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};switch(t.mode){case"s3":{r.info("Creating instance configuration, data directory and other stuff..."),n.createLocalS3(s,{...P,minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"]});break}case void 0:{e["s3-port"]&&r.warn("flag 's3-port' is only for 's3' mode"),e["s3-console-port"]&&r.warn("flag 's3-console-port' is only for 's3' mode"),n.createLocal(s,P);break}}if(P.binaryPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}je(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'pl up' command`)).catch(function(k){r.error(k.message)})}};l(G,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(G,"examples",["<%= config.bin %> <%= command.id %>"]),l(G,"flags",{...A,...q,...ur,...H,..._e,...Ne,...Ce,...J,...W,...ce,...ie,...oe,...De,...xe,...z}),l(G,"args",{name:d.Args.string({required:!0}),mode:d.Args.string({options:["s3"],required:!1})});let Re=G;const U=class U extends d.Command{async run(){const{flags:e,args:t}=await this.parse(U),r=L(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):g.instanceDir(s),m=[];for(const w of e.mount??[])m.push({hostPath:w});const f=e.arch?`linux/${e.arch}`:void 0,y=e["minio-presign-host"]?"minio":"localhost";n.createDockerS3(s,o,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:f,customMounts:m,auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:y}),r.info(`Instance '${s}' was created. To start it run 'up' command`),e["minio-presign-host"]&&r.info(" NOTE: make sure you have 'minio' host in your hosts file as 127.0.0.1 address")}};l(U,"description","Run Platforma Backend service as docker container on current host with MinIO as local S3 storage"),l(U,"examples",["<%= config.bin %> <%= command.id %>"]),l(U,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...fr}),l(U,"args",{name:d.Args.string({required:!0})});let Te=U;const lt={"create-block":Pe,reset:Se,start:$e,stop:Ae,"start:docker":st,"start:local":it,"svc:delete":Le,"svc:down":Ie,"svc:list":Oe,"svc:up":Fe,"start:docker:s3":ct,"start:local:s3":ot,"svc:create:docker":Ee,"svc:create:local":Re,"svc:create:docker:s3":Te};exports.COMMANDS=lt;
116
+ You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,t){const r={},n=t.type;switch(e=e.toUpperCase(),n){case"S3":return r[`PL_DATA_${e}_TYPE`]="S3",r[`PL_DATA_${e}_S3_BUCKET`]=t.bucketName,t.endpoint&&(r[`PL_DATA_${e}_S3_ENDPOINT`]=t.endpoint),t.presignEndpoint&&(r[`PL_DATA_${e}_S3_PRESIGN_ENDPOINT`]=t.presignEndpoint),t.region&&(r[`PL_DATA_${e}_S3_REGION`]=t.region),t.key&&(r[`PL_DATA_${e}_S3_KEY`]=t.key),t.secret&&(r[`PL_DATA_${e}_S3_SECRET`]=t.secret),r;case"FS":return r[`PL_DATA_${e}_TYPE`]="FS",r;default:U()}return{}}renderRunInfo(e,t=10){var c,o;const r=[],n=d=>d.padStart(t," ");switch(e.configPath&&r.push(`${n("config")}: ${e.configPath}`),e.apiAddr?r.push(`${n("API")}: ${e.apiAddr}`):e.apiPort?r.push(`${n("API")}: 127.0.0.1:${e.apiPort.toString()}`):r.push(`${n("API")}: 127.0.0.1:6345`),e.logPath&&r.push(`${n("log")}: ${e.logPath}`),(c=e.primary)==null?void 0:c.type){case void 0:break;case"FS":r.push(`${n("primary")}: ${e.primary.rootPath}`);break;case"S3":r.push(`${n("primary")}: S3 at '${e.primary.endpoint??"AWS"}', bucket '${e.primary.bucketName}', prefix: '${e.primary.keyPrefix??""}'`);break;default:U()}switch((o=e.library)==null?void 0:o.type){case void 0:break;case"FS":r.push(`${n("library")}: ${e.library.rootPath}`);break;case"S3":r.push(`${n("library")}: S3 at '${e.library.endpoint??"AWS"}', bucket '${e.library.bucketName}', prefix: '${e.library.keyPrefix??""}'`);break;default:U()}return e.work&&r.push(`${n("workdirs")}: ${e.work.rootPath}`),e.dbPath&&r.push(`${n("db")}: ${e.dbPath}`),r.join(`
117
+ `)}readComposeFile(e){const t=m.readFileSync(e);return ue.parse(t.toString())}writeComposeFile(e,t){m.writeFileSync(e,ue.stringify(t))}}function ge(a,e){for(const t of a){if(t.error)throw t.error;const r=e??"failed to run command";if(t.status!==0)throw new Error(`${r}, process exited with code '${t.status}'`)}}const ee=class ee extends u.Command{async run(){const{flags:e}=await this.parse(ee),t=A(e["log-level"]);new I(t).cleanupInstance()}};l(ee,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]),l(ee,"flags",{...L});let Re=ee;const re=class re extends u.Command{async run(){const{flags:e}=await this.parse(re),t=A(e["log-level"]);new I(t).startLast()}};l(re,"description","Start last run service configuraiton"),l(re,"examples",["<%= config.bin %> <%= command.id %>"]),l(re,"flags",{...L});let Ee=re;const te=class te extends u.Command{async run(){const{flags:e}=await this.parse(te),t=A(e["log-level"]),r=new I(t);f.currentInstance?r.stopInstance(f.currentInstance):t.warn("up/start command was not called for any instance, nothing to stop")}};l(te,"description","Stop platforma service"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]),l(te,"flags",{...L});let Te=te;var F;let it=(F=class extends u.Command{async run(){const{flags:e}=await this.parse(F),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):f.instanceDir(n),o=[];for(const y of e.mount??[])o.push({hostPath:y});const d=e.arch?`linux/${e.arch}`:void 0,g=r.createDocker(n,c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:d,customMounts:o,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]});r.switchInstance(g)}},l(F,"description","Run platforma backend service with 'FS' primary storage type"),l(F,"examples",["<%= config.bin %> <%= command.id %>"]),l(F,"flags",{...L,...M,...me,...N,...he,...B,...C,...ye,...j,...ie,...se,...ce}),F);var R;let ct=(R=class extends u.Command{async run(){const{flags:e}=await this.parse(R),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):f.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),d=e["auth-enabled"]??o!==void 0;let g=e["pl-binary"];e["pl-sources"]&&(g=r.buildPlatforma({repoRoot:e["pl-sources"]}));let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const p={binaryPath:g,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:d,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},P=r.createLocal(n,p);p.binaryPath?r.switchInstance(P):ke(t,{version:e.version}).then(()=>{const S=r.switchInstance(P);setTimeout(()=>{for(const k of S)k.unref()},1e3)}).catch(function(S){t.error(S.message)})}},l(R,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(R,"examples",["<%= config.bin %> <%= command.id %>"]),l(R,"flags",{...L,...N,...M,...we,...ve,...Pe,...C,...j,...ie,...se,...ce,...pe,...be,...B}),R);const q=class q extends u.Command{async run(){const{flags:e,args:t}=await this.parse(q),r=A(e["log-level"]),n=new I(r),s=t.name;e.all&&(n.cleanupInstance(),process.exit(0)),s||(r.error("Please, specify name of instance to be removed or set '--all' flag instead"),process.exit(1)),n.cleanupInstance(s)}};l(q,"description","List available instances"),l(q,"examples",["<%= config.bin %> <%= command.id %>"]),l(q,"flags",{...L,all:u.Flags.boolean({description:"remove all known instances",required:!1})}),l(q,"args",{name:u.Args.string({required:!1})});let De=q;const J=class J extends u.Command{async run(){const{flags:e,args:t}=await this.parse(J),r=A(e["log-level"]),n=new I(r),s=t.name??f.currentInstanceName;s||(r.info("no pl service instance selected. No service was stopped"),process.exit(0)),n.stopInstance(f.getInstanceInfo(s))}};l(J,"description","List available instances"),l(J,"examples",["<%= config.bin %> <%= command.id %>"]),l(J,"flags",{...L}),l(J,"args",{name:u.Args.string({required:!1})});let xe=J;const ae=class ae extends u.Command{async run(){await this.parse(ae);const e=f.instanceList,t=f.currentInstanceName;for(const r of e){const n=[],s=f.getInstanceInfo(r);f.isInstanceActive(s)&&n.push("status:up"),n.push(`type:${s.type}`),console.log(r===t?` * ${r} (${n.join(", ")})`:` ${r} (${n.join(", ")})`)}}};l(ae,"description","List available instances"),l(ae,"examples",["<%= config.bin %> <%= command.id %>"]),l(ae,"flags",{});let _e=ae;const H=class H extends u.Command{async run(){const{flags:e,args:t}=await this.parse(H),r=A(e["log-level"]),n=new I(r),s=t.name??f.currentInstanceName;s||(r.error("no pl service instance is selected. Select instance with 'select' command or provide name to 'up'"),process.exit(1));const i=n.switchInstance(f.getInstanceInfo(s)),c=[];for(const o of i)c.push(new Promise((d,g)=>{o.on("close",d),o.on("error",g)}));await Promise.all(c)}};l(H,"description","List available instances"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]),l(H,"flags",{...L}),l(H,"args",{name:u.Args.string({required:!1})});let Ne=H;var E;let ot=(E=class extends u.Command{async run(){const{flags:e}=await this.parse(E),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker-s3",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):f.instanceDir(n),o=[];for(const w of e.mount??[])o.push({hostPath:w});const d=e.arch?`linux/${e.arch}`:void 0,g=e["minio-presign-host"]?"minio":"localhost",y=r.createDockerS3(n,c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:d,customMounts:o,auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:g});r.switchInstance(y)}},l(E,"description","Run platforma backend service with 'S3' primary storage type"),l(E,"examples",["<%= config.bin %> <%= command.id %>"]),l(E,"flags",{...L,...M,...me,...N,...he,...B,...C,...ye,...j,...mr}),E);var T;let lt=(T=class extends u.Command{async run(){const{flags:e}=await this.parse(T),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local-s3",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):f.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),d=e["auth-enabled"]??o!==void 0;let g=e["pl-binary"];e["pl-sources"]&&(g=r.buildPlatforma({repoRoot:e["pl-sources"]}));let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const p={binaryPath:g,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:d,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},P=r.createLocalS3(n,p);p.binaryPath?r.switchInstance(P):ke(t,{version:e.version}).then(()=>{const S=r.switchInstance(P);setTimeout(()=>{for(const k of S)k.unref()},1e3)}).catch(function(S){t.error(S.message)})}},l(T,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(T,"examples",["<%= config.bin %> <%= command.id %>"]),l(T,"flags",{...L,...N,...M,...fr,...we,...ve,...Pe,...C,...j,...ie,...se,...ce,...pe,...be,...B}),T);const W=class W extends u.Command{async run(){const{flags:e,args:t}=await this.parse(W),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):f.instanceDir(s),d=[];for(const y of e.mount??[])d.push({hostPath:y});const g=e.arch?`linux/${e.arch}`:void 0;n.createDocker(s,o,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:g,customMounts:d,license:e.license,licenseFile:e["license-file"],auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]}),r.info(`Instance '${s}' was created. To start it run 'up' command`)}};l(W,"description","Run Platforma Backend service as docker container on current host"),l(W,"examples",["<%= config.bin %> <%= command.id %>"]),l(W,"flags",{...L,...M,...me,...N,...he,...B,...C,...ye,...j,...ie,...se,...ce}),l(W,"args",{name:u.Args.string({required:!0})});let Ce=W;var O;let dt=(O=class extends u.Command{async run(){const{flags:e,args:t}=await this.parse(O),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):f.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,d=n.initAuthDriversList(e,i),g=e["auth-enabled"]??d!==void 0;let y=e["pl-binary"];e["pl-sources"]&&(y=n.buildPlatforma({repoRoot:e["pl-sources"]}));let w="127.0.0.1:6345";e["grpc-listen"]?w=e["grpc-listen"]:e["grpc-port"]&&(w=`127.0.0.1:${e["grpc-port"]}`);let v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);let p="127.0.0.1:9091";e["debug-listen"]?p=e["debug-listen"]:e["debug-port"]&&(p=`127.0.0.1:${e["debug-port"]}`);const P={binaryPath:y,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:w},monitoring:{listen:v},debug:{listen:p},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:g,drivers:d}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};if(n.createLocal(s,P),P.binaryPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}ke(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'pl up' command`)).catch(function(S){r.error(S.message)})}},l(O,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(O,"examples",["<%= config.bin %> <%= command.id %>"]),l(O,"flags",{...L,...N,...M,...we,...ve,...Pe,...C,...j,...ie,...se,...ce,...pe,...be,...B}),l(O,"args",{name:u.Args.string({required:!0})}),O);const z=class z extends u.Command{async run(){const{flags:e,args:t}=await this.parse(z),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):f.instanceDir(s),d=[];for(const w of e.mount??[])d.push({hostPath:w});const g=e.arch?`linux/${e.arch}`:void 0,y=e["minio-presign-host"]?"minio":"localhost";n.createDockerS3(s,o,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:g,customMounts:d,auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:y}),r.info(`Instance '${s}' was created. To start it run 'up' command`),e["minio-presign-host"]&&r.info(" NOTE: make sure you have 'minio' host in your hosts file as 127.0.0.1 address")}};l(z,"description","Run Platforma Backend service as docker container on current host with MinIO as local S3 storage"),l(z,"examples",["<%= config.bin %> <%= command.id %>"]),l(z,"flags",{...L,...M,...me,...N,...he,...B,...C,...ye,...j,...mr}),l(z,"args",{name:u.Args.string({required:!0})});let Me=z;const Y=class Y extends u.Command{async run(){const{flags:e,args:t}=await this.parse(Y),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):f.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,d=n.initAuthDriversList(e,i),g=e["auth-enabled"]??d!==void 0;let y=e["pl-binary"];e["pl-sources"]&&(y=n.buildPlatforma({repoRoot:e["pl-sources"]}));let w="127.0.0.1:6345";e["grpc-listen"]?w=e["grpc-listen"]:e["grpc-port"]&&(w=`127.0.0.1:${e["grpc-port"]}`);let v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);let p="127.0.0.1:9091";e["debug-listen"]?p=e["debug-listen"]:e["debug-port"]&&(p=`127.0.0.1:${e["debug-port"]}`);const P={binaryPath:y,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:w},monitoring:{listen:v},debug:{listen:p},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:g,drivers:d}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};if(r.info("Creating instance configuration, data directory and other stuff..."),n.createLocalS3(s,P),P.binaryPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}ke(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'pl up' command`)).catch(function(S){r.error(S.message)})}};l(Y,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]),l(Y,"flags",{...L,...N,...fr,...M,...we,...ve,...Pe,...C,...j,...ie,...se,...ce,...pe,...be,...B}),l(Y,"args",{name:u.Args.string({required:!0})});let je=Y;const gt={"create-block":Oe,reset:Re,start:Ee,stop:Te,"start:docker":it,"start:local":ct,"svc:delete":De,"svc:down":xe,"svc:list":_e,"svc:up":Ne,"start:docker:s3":ot,"start:local:s3":lt,"svc:create:docker":Ce,"svc:create:local":dt,"svc:create:docker:s3":Me,"svc:create:local:s3":je};exports.COMMANDS=gt;
118
118
  //# sourceMappingURL=index.js.map