bdy 1.16.28-stage → 1.16.30-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +32 -31
  3. package/distTs/src/command/package/create.js +10 -2
  4. package/distTs/src/command/package/delete.js +3 -1
  5. package/distTs/src/command/package/download.js +3 -120
  6. package/distTs/src/command/package/get.js +1 -1
  7. package/distTs/src/command/package/list.js +1 -1
  8. package/distTs/src/command/package/publish.js +4 -3
  9. package/distTs/src/command/package/version/delete.js +1 -0
  10. package/distTs/src/command/package/version/get.js +1 -0
  11. package/distTs/src/command/package/version/list.js +1 -0
  12. package/distTs/src/command/pipeline/run.js +1 -0
  13. package/distTs/src/command/sandbox/cp.js +79 -17
  14. package/distTs/src/command/sandbox/create.js +2 -15
  15. package/distTs/src/command/sandbox/endpoint/add.js +1 -0
  16. package/distTs/src/command/sandbox/endpoint/delete.js +1 -0
  17. package/distTs/src/command/sandbox/endpoint/get.js +1 -0
  18. package/distTs/src/command/sandbox/endpoint/list.js +1 -0
  19. package/distTs/src/command/sandbox/endpoint.js +4 -0
  20. package/distTs/src/command/sandbox/exec/command.js +1 -0
  21. package/distTs/src/command/sandbox/exec/kill.js +1 -0
  22. package/distTs/src/command/sandbox/exec/list.js +1 -0
  23. package/distTs/src/command/sandbox/exec/logs.js +1 -0
  24. package/distTs/src/command/sandbox/exec/status.js +1 -0
  25. package/distTs/src/command/sandbox/exec.js +5 -0
  26. package/distTs/src/command/sandbox/get.js +0 -1
  27. package/distTs/src/command/sandbox/snapshot/create.js +1 -0
  28. package/distTs/src/command/sandbox/snapshot/delete.js +1 -0
  29. package/distTs/src/command/sandbox/snapshot/get.js +1 -0
  30. package/distTs/src/command/sandbox/snapshot/list.js +2 -1
  31. package/distTs/src/command/sandbox/snapshot.js +4 -0
  32. package/distTs/src/command/sandbox/status.js +0 -1
  33. package/distTs/src/input.js +72 -2
  34. package/distTs/src/texts.js +234 -16
  35. package/distTs/src/utils.js +279 -3
  36. package/package.json +1 -1
@@ -43,16 +43,20 @@ exports.isFile = isFile;
43
43
  exports.getAppWorkspaceUrl = getAppWorkspaceUrl;
44
44
  exports.getAppWorkspaceSettingsUrl = getAppWorkspaceSettingsUrl;
45
45
  exports.getAppUrl = getAppUrl;
46
+ exports.untarGz = untarGz;
47
+ exports.unzipFile = unzipFile;
46
48
  exports.getDockerRegistryHostByApiBaseUrl = getDockerRegistryHostByApiBaseUrl;
47
49
  exports.getAppHostByApiBaseUrl = getAppHostByApiBaseUrl;
48
- const node_path_1 = __importStar(require("node:path"));
49
- const node_fs_1 = require("node:fs");
50
+ const node_path_1 = __importDefault(require("node:path"));
51
+ const node_fs_1 = __importStar(require("node:fs"));
50
52
  const texts_1 = require("./texts");
51
53
  const ssh2_1 = __importDefault(require("ssh2"));
52
54
  const node_sea_1 = require("node:sea");
53
55
  const commander_1 = require("commander");
54
56
  const node_os_1 = __importStar(require("node:os"));
55
57
  const node_child_process_1 = require("node:child_process");
58
+ const fflate_1 = require("fflate");
59
+ const tar_stream_1 = __importDefault(require("tar-stream"));
56
60
  exports.TUNNEL_HTTP_RATE_LIMIT = 2000;
57
61
  exports.TUNNEL_HTTP_RATE_WINDOW = 60000;
58
62
  exports.TUNNEL_HTTP_LOG_MAX_BODY = 5242880; // 5MB
@@ -388,7 +392,7 @@ const getVersion = () => {
388
392
  }
389
393
  else {
390
394
  const root = (0, exports.getRootDir)();
391
- packageJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(root, 'package.json'), 'utf8'));
395
+ packageJson = JSON.parse((0, node_fs_1.readFileSync)(node_path_1.default.resolve(root, 'package.json'), 'utf8'));
392
396
  }
393
397
  cachedVersion = packageJson.version;
394
398
  }
@@ -577,6 +581,278 @@ function getAppWorkspaceSettingsUrl(baseUrl, workspace) {
577
581
  function getAppUrl(baseUrl, path) {
578
582
  return `https://${getAppHostByApiBaseUrl(baseUrl)}${path}`;
579
583
  }
584
+ function untarGz(dirPath, tarGzPath, onFile) {
585
+ return new Promise((resolve, reject) => {
586
+ let _startedFiles = 0;
587
+ let _finishedFiles = 0;
588
+ let _finishedStream = false;
589
+ let _finishedError = null;
590
+ let _calledResolve = false;
591
+ const rs = node_fs_1.default.createReadStream(tarGzPath);
592
+ const extract = tar_stream_1.default.extract();
593
+ const _finish = () => {
594
+ if (_finishedError || _finishedStream) {
595
+ try {
596
+ rs.removeAllListeners();
597
+ rs.close();
598
+ }
599
+ catch {
600
+ // do nothing
601
+ }
602
+ }
603
+ if (_calledResolve)
604
+ return;
605
+ if (_finishedError) {
606
+ _calledResolve = true;
607
+ reject(_finishedError);
608
+ return;
609
+ }
610
+ if (_finishedStream && _startedFiles === _finishedFiles) {
611
+ _calledResolve = true;
612
+ resolve();
613
+ }
614
+ };
615
+ const finishFile = (err, fws) => {
616
+ if (!_finishedError && err)
617
+ _finishedError = err;
618
+ const complete = () => {
619
+ _finishedFiles += 1;
620
+ onFile();
621
+ _finish();
622
+ };
623
+ if (fws) {
624
+ fws.once('finish', () => {
625
+ fws.removeAllListeners();
626
+ complete();
627
+ });
628
+ fws.end();
629
+ }
630
+ else {
631
+ complete();
632
+ }
633
+ };
634
+ const finishStream = (err) => {
635
+ if (!_finishedError && err)
636
+ _finishedError = err;
637
+ _finishedStream = true;
638
+ _finish();
639
+ };
640
+ extract.on('entry', async (header, stream, next) => {
641
+ if (_finishedError) {
642
+ stream.resume();
643
+ next();
644
+ return;
645
+ }
646
+ _startedFiles += 1;
647
+ const fullPath = node_path_1.default.join(dirPath, header.name);
648
+ const parentPath = node_path_1.default.dirname(fullPath);
649
+ let fws;
650
+ try {
651
+ await node_fs_1.default.promises.rm(fullPath, {
652
+ recursive: true,
653
+ force: true,
654
+ });
655
+ }
656
+ catch {
657
+ // do nothing
658
+ }
659
+ try {
660
+ if (header.type === 'directory') {
661
+ await node_fs_1.default.promises.mkdir(fullPath, {
662
+ recursive: true,
663
+ });
664
+ stream.resume();
665
+ finishFile();
666
+ next();
667
+ return;
668
+ }
669
+ await node_fs_1.default.promises.mkdir(parentPath, {
670
+ recursive: true,
671
+ });
672
+ fws = node_fs_1.default.createWriteStream(fullPath, {
673
+ flags: 'w',
674
+ });
675
+ fws.on('error', (err) => {
676
+ finishFile(err, fws);
677
+ });
678
+ }
679
+ catch (err) {
680
+ stream.resume();
681
+ finishFile(err, fws);
682
+ next();
683
+ return;
684
+ }
685
+ stream.on('data', (chunk) => {
686
+ if (_finishedError)
687
+ return;
688
+ if (fws) {
689
+ fws.write(chunk);
690
+ }
691
+ });
692
+ stream.on('end', () => {
693
+ finishFile(null, fws);
694
+ next();
695
+ });
696
+ stream.on('error', (err) => {
697
+ finishFile(err, fws);
698
+ next();
699
+ });
700
+ });
701
+ extract.on('finish', () => {
702
+ finishStream();
703
+ });
704
+ extract.on('error', (err) => {
705
+ finishStream(err);
706
+ });
707
+ const gunzip = new fflate_1.Gunzip((data, final) => {
708
+ if (_finishedError)
709
+ return;
710
+ extract.write(Buffer.from(data));
711
+ if (final) {
712
+ extract.end();
713
+ }
714
+ });
715
+ rs.on('data', (chunk) => {
716
+ try {
717
+ gunzip.push(chunk, false);
718
+ }
719
+ catch (err) {
720
+ finishStream(err);
721
+ }
722
+ });
723
+ rs.on('error', (err) => {
724
+ finishStream(err);
725
+ });
726
+ rs.on('end', () => {
727
+ try {
728
+ gunzip.push(new Uint8Array(0), true);
729
+ }
730
+ catch (err) {
731
+ finishStream(err);
732
+ }
733
+ });
734
+ });
735
+ }
736
+ function unzipFile(dirPath, zipPath, onFile) {
737
+ return new Promise((resolve, reject) => {
738
+ let _startedFiles = 0;
739
+ let _finishedFiles = 0;
740
+ let _finishedStream = false;
741
+ let _finishedError = null;
742
+ let _calledResolve = false;
743
+ const rs = node_fs_1.default.createReadStream(zipPath);
744
+ const _finish = () => {
745
+ if (_finishedError || _finishedStream) {
746
+ try {
747
+ rs.removeAllListeners();
748
+ rs.close();
749
+ }
750
+ catch {
751
+ // do nothing
752
+ }
753
+ }
754
+ if (_calledResolve)
755
+ return;
756
+ if (_finishedError) {
757
+ _calledResolve = true;
758
+ reject(_finishedError);
759
+ return;
760
+ }
761
+ if (_finishedStream && _startedFiles === _finishedFiles) {
762
+ _calledResolve = true;
763
+ resolve();
764
+ }
765
+ };
766
+ const finishFile = (err, fws) => {
767
+ if (!_finishedError && err)
768
+ _finishedError = err;
769
+ const complete = () => {
770
+ _finishedFiles += 1;
771
+ onFile();
772
+ _finish();
773
+ };
774
+ if (fws) {
775
+ fws.once('finish', () => {
776
+ fws.removeAllListeners();
777
+ complete();
778
+ });
779
+ fws.end();
780
+ }
781
+ else {
782
+ complete();
783
+ }
784
+ };
785
+ const finishStream = (err) => {
786
+ if (!_finishedError && err)
787
+ _finishedError = err;
788
+ _finishedStream = true;
789
+ _finish();
790
+ };
791
+ const unzip = new fflate_1.Unzip(async (file) => {
792
+ if (_finishedError)
793
+ return;
794
+ _startedFiles += 1;
795
+ const fullPath = node_path_1.default.join(dirPath, file.name);
796
+ const parentPath = node_path_1.default.dirname(fullPath);
797
+ let fws;
798
+ try {
799
+ await node_fs_1.default.promises.rm(fullPath, {
800
+ recursive: true,
801
+ force: true,
802
+ });
803
+ }
804
+ catch {
805
+ // do nothing
806
+ }
807
+ try {
808
+ if (fullPath.endsWith('/')) {
809
+ await node_fs_1.default.promises.mkdir(fullPath, {
810
+ recursive: true,
811
+ });
812
+ finishFile();
813
+ return;
814
+ }
815
+ await node_fs_1.default.promises.mkdir(parentPath, {
816
+ recursive: true,
817
+ });
818
+ fws = node_fs_1.default.createWriteStream(fullPath, {
819
+ flags: 'w',
820
+ });
821
+ fws.on('error', (err) => {
822
+ finishFile(err, fws);
823
+ });
824
+ }
825
+ catch (err) {
826
+ finishFile(err, fws);
827
+ return;
828
+ }
829
+ file.ondata = (err, data, final) => {
830
+ if (_finishedError)
831
+ return;
832
+ if (err)
833
+ finishFile(err, fws);
834
+ else {
835
+ if (fws)
836
+ fws.write(data);
837
+ if (final)
838
+ finishFile(null, fws);
839
+ }
840
+ };
841
+ file.start();
842
+ });
843
+ unzip.register(fflate_1.AsyncUnzipInflate);
844
+ rs.on('data', (chunk) => {
845
+ unzip.push(chunk, false);
846
+ });
847
+ rs.on('error', (err) => {
848
+ finishStream(err);
849
+ });
850
+ rs.on('end', () => {
851
+ unzip.push(new Uint8Array(0), true);
852
+ finishStream();
853
+ });
854
+ });
855
+ }
580
856
  function getDockerRegistryHostByApiBaseUrl(baseUrl) {
581
857
  if (baseUrl.hostname.includes('api.buddy.works')) {
582
858
  return 'container-pkg.buddy.works';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.16.28-stage",
4
+ "version": "1.16.30-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {