@zthun/romulator-client 1.18.4 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -18,7 +18,7 @@ class ZRomulatorConfigGamesMetadata {
18
18
  }
19
19
  }
20
20
 
21
- function _define_property$5(obj, key, value) {
21
+ function _define_property$6(obj, key, value) {
22
22
  if (key in obj) {
23
23
  Object.defineProperty(obj, key, {
24
24
  value: value,
@@ -51,11 +51,11 @@ class ZRomulatorConfigGamesBuilder {
51
51
  return structuredClone(this._config);
52
52
  }
53
53
  constructor(){
54
- _define_property$5(this, "_config", {});
54
+ _define_property$6(this, "_config", {});
55
55
  }
56
56
  }
57
57
 
58
- function _define_property$4(obj, key, value) {
58
+ function _define_property$5(obj, key, value) {
59
59
  if (key in obj) {
60
60
  Object.defineProperty(obj, key, {
61
61
  value: value,
@@ -117,7 +117,7 @@ class ZRomulatorConfigBuilder {
117
117
  return structuredClone(this._config);
118
118
  }
119
119
  constructor(){
120
- _define_property$4(this, "_config", {
120
+ _define_property$5(this, "_config", {
121
121
  id: "games",
122
122
  name: "",
123
123
  file: ""
@@ -125,7 +125,7 @@ class ZRomulatorConfigBuilder {
125
125
  }
126
126
  }
127
127
 
128
- function _define_property$3(obj, key, value) {
128
+ function _define_property$4(obj, key, value) {
129
129
  if (key in obj) {
130
130
  Object.defineProperty(obj, key, {
131
131
  value: value,
@@ -211,7 +211,7 @@ function _define_property$3(obj, key, value) {
211
211
  return structuredClone(this._players);
212
212
  }
213
213
  constructor(){
214
- _define_property$3(this, "_players", {
214
+ _define_property$4(this, "_players", {
215
215
  min: 1,
216
216
  max: 1
217
217
  });
@@ -220,25 +220,25 @@ function _define_property$3(obj, key, value) {
220
220
  *
221
221
  * @returns
222
222
  * This object.
223
- */ _define_property$3(this, "singlePlayer", this.range.bind(this, 1, 1));
223
+ */ _define_property$4(this, "singlePlayer", this.range.bind(this, 1, 1));
224
224
  /**
225
225
  * Sets the player count to 2 for max and 1 for min.
226
226
  *
227
227
  * @returns
228
228
  * This object.
229
- */ _define_property$3(this, "twoPlayer", this.range.bind(this, 1, 2));
229
+ */ _define_property$4(this, "twoPlayer", this.range.bind(this, 1, 2));
230
230
  /**
231
231
  * Sets the player count to 4 for max and 1 for min.
232
232
  *
233
233
  * @returns
234
234
  * This object.
235
- */ _define_property$3(this, "fourPlayer", this.range.bind(this, 1, 4));
235
+ */ _define_property$4(this, "fourPlayer", this.range.bind(this, 1, 4));
236
236
  /**
237
237
  * Sets the player count to 8 for max and 1 for min.
238
238
  *
239
239
  * @returns
240
240
  * This object.
241
- */ _define_property$3(this, "eightPlayer", this.range.bind(this, 1, 8));
241
+ */ _define_property$4(this, "eightPlayer", this.range.bind(this, 1, 8));
242
242
  }
243
243
  }
244
244
 
@@ -425,7 +425,7 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
425
425
  return typeof candidate === "string" && Object.prototype.hasOwnProperty.call(ZRomulatorSystemIdMap, candidate);
426
426
  }
427
427
 
428
- function _define_property$2(obj, key, value) {
428
+ function _define_property$3(obj, key, value) {
429
429
  if (key in obj) {
430
430
  Object.defineProperty(obj, key, {
431
431
  value: value,
@@ -600,7 +600,7 @@ function _define_property$2(obj, key, value) {
600
600
  return lodashEs.omitBy(clone, lodashEs.isUndefined);
601
601
  }
602
602
  constructor(){
603
- _define_property$2(this, "_game", {
603
+ _define_property$3(this, "_game", {
604
604
  id: "",
605
605
  name: "",
606
606
  file: "",
@@ -614,6 +614,261 @@ function _define_property$2(obj, key, value) {
614
614
  }
615
615
  }
616
616
 
617
+ /**
618
+ * The status of a job.
619
+ */ var ZJobStatus = /*#__PURE__*/ function(ZJobStatus) {
620
+ /**
621
+ * Idle, job is not running yet.
622
+ *
623
+ * This is the default state.
624
+ */ ZJobStatus["Idle"] = "idle";
625
+ /**
626
+ * Job is running.
627
+ */ ZJobStatus["Running"] = "running";
628
+ /**
629
+ * Job was canceled.
630
+ *
631
+ * Jobs that were in a running state when the application
632
+ * shuts down will reboot with this status.
633
+ */ ZJobStatus["Canceled"] = "canceled";
634
+ /**
635
+ * Job failed.
636
+ *
637
+ * Try again.
638
+ */ ZJobStatus["Failed"] = "failed";
639
+ /**
640
+ * Job completed successfully.
641
+ */ ZJobStatus["Success"] = "success";
642
+ return ZJobStatus;
643
+ }({});
644
+
645
+ /**
646
+ * Represents the supported job types.
647
+ */ var ZJobType = /*#__PURE__*/ function(ZJobType) {
648
+ /**
649
+ * Unknown job type.
650
+ *
651
+ * You can use this as the null object for a job.
652
+ */ ZJobType["Unknown"] = "unknown";
653
+ /**
654
+ * A quick hello world style job.
655
+ *
656
+ * Will always succeed. This is
657
+ * just to validate that the job
658
+ * engine is working.
659
+ *
660
+ * Ping has no context and no parameters.
661
+ */ ZJobType["Ping"] = "ping";
662
+ /**
663
+ * A scrape job.
664
+ *
665
+ * A scrape job downloads media from
666
+ * a scraper and saves it to the
667
+ * media folder.
668
+ *
669
+ * A scrape job with no context scrapes
670
+ * all systems and games.
671
+ */ ZJobType["Scrape"] = "scrape";
672
+ return ZJobType;
673
+ }({});
674
+
675
+ function _define_property$2(obj, key, value) {
676
+ if (key in obj) {
677
+ Object.defineProperty(obj, key, {
678
+ value: value,
679
+ enumerable: true,
680
+ configurable: true,
681
+ writable: true
682
+ });
683
+ } else {
684
+ obj[key] = value;
685
+ }
686
+ return obj;
687
+ }
688
+ /**
689
+ * A builder that constructs IZJob instances.
690
+ */ class ZJobBuilder {
691
+ /**
692
+ * Sets the unique identifier for the job.
693
+ *
694
+ * @param val -
695
+ * Job id. If this is falsy, then the id
696
+ * is cleared.
697
+ * @returns
698
+ * This builder.
699
+ */ id(val) {
700
+ this._job.id = val;
701
+ return this;
702
+ }
703
+ /**
704
+ * Sets the id to a new generated guid if the id is not set.
705
+ *
706
+ * @returns
707
+ * This object.
708
+ */ guid() {
709
+ return this._job.id ? this : this.id(helpfulFn.createGuid());
710
+ }
711
+ /**
712
+ * Sets the job type.
713
+ *
714
+ * @param val -
715
+ * The job type.
716
+ * @returns
717
+ * This builder.
718
+ */ type(val) {
719
+ this._job.type = val;
720
+ return this;
721
+ }
722
+ /**
723
+ * Sets the state of the job.
724
+ *
725
+ * @param status -
726
+ * The status of the job.
727
+ *
728
+ * @returns
729
+ * This object.
730
+ */ status(status) {
731
+ this._job.status = status;
732
+ return this;
733
+ }
734
+ /**
735
+ * Sets the percent value.
736
+ *
737
+ * @param val -
738
+ * The percentage of the job complete
739
+ *
740
+ * @returns
741
+ * This object.
742
+ */ percent(val) {
743
+ this._job.percent = val;
744
+ if (this._job.percent != null) {
745
+ this._job.percent = Math.min(100, Math.max(0, this._job.percent));
746
+ this._job.percent = Math.round(this._job.percent);
747
+ }
748
+ return this;
749
+ }
750
+ /**
751
+ * Sets the job context or parameters.
752
+ *
753
+ * @param val -
754
+ * Context to attach to the job.
755
+ * @returns
756
+ * This builder.
757
+ */ context(val) {
758
+ this._job.context = val;
759
+ return this;
760
+ }
761
+ /**
762
+ * Sets the date and time when the job was created.
763
+ *
764
+ * @param val -
765
+ * The iso string representation of the job creation date.
766
+ *
767
+ * @returns
768
+ * This object.
769
+ */ createdAt(val) {
770
+ this._job.createdAt = val;
771
+ return this;
772
+ }
773
+ /**
774
+ * Removes information about the job that does not need to be written
775
+ * to a job file.
776
+ *
777
+ * This removes any created and updated date as the file's audit
778
+ * information is source of truth for these. The id is also removed
779
+ * as the file name serves as an id.
780
+ *
781
+ * @returns
782
+ * This object.
783
+ */ redact() {
784
+ delete this._job.id;
785
+ delete this._job.createdAt;
786
+ return this;
787
+ }
788
+ /**
789
+ * Attempts to parse a job from a candidate job file.
790
+ */ parse(candidate) {
791
+ const type = lodashEs.get(candidate, "type");
792
+ const context = lodashEs.get(candidate, "context");
793
+ const status = lodashEs.get(candidate, "status");
794
+ const percent = lodashEs.get(candidate, "percent");
795
+ return this.type(helpfulFn.castEnum(ZJobType, type)).status(helpfulFn.castEnum(ZJobStatus, status)).percent(helpfulFn.castNumber(percent, 0)).context(context);
796
+ }
797
+ /**
798
+ * Copies the values from another job into this builder.
799
+ *
800
+ * @param other -
801
+ * The job to duplicate.
802
+ * @returns
803
+ * This builder.
804
+ */ copy(other) {
805
+ this._job = structuredClone(other);
806
+ return this;
807
+ }
808
+ /**
809
+ * Builds a clean IZJob instance with undefined values removed.
810
+ *
811
+ * @returns
812
+ * The constructed job.
813
+ */ build() {
814
+ const clone = structuredClone(this._job);
815
+ return lodashEs.omitBy(clone, lodashEs.isUndefined);
816
+ }
817
+ constructor(){
818
+ _define_property$2(this, "_job", {
819
+ type: ZJobType.Ping
820
+ });
821
+ /**
822
+ * Sets the job type to ping.
823
+ *
824
+ * @returns
825
+ * This object.
826
+ */ _define_property$2(this, "ping", this.type.bind(this, ZJobType.Ping));
827
+ /**
828
+ * Sets the job type to scrape.
829
+ *
830
+ * @returns
831
+ * This object.
832
+ */ _define_property$2(this, "scrape", this.type.bind(this, ZJobType.Scrape));
833
+ /**
834
+ * Sets the state status to idle and the percent to 0.
835
+ *
836
+ * @returns
837
+ * This object.
838
+ */ _define_property$2(this, "idle", this.status.bind(this, ZJobStatus.Idle));
839
+ /**
840
+ * Sets the state status to running.
841
+ *
842
+ * @returns
843
+ * This object.
844
+ */ _define_property$2(this, "running", this.status.bind(this, ZJobStatus.Running));
845
+ /**
846
+ * Sets the state status to canceled.
847
+ *
848
+ * @returns
849
+ * This object.
850
+ */ _define_property$2(this, "canceled", this.status.bind(this, ZJobStatus.Canceled));
851
+ /**
852
+ * Sets the state status to failed.
853
+ *
854
+ * @returns
855
+ * This object.
856
+ */ _define_property$2(this, "failed", this.status.bind(this, ZJobStatus.Failed));
857
+ /**
858
+ * Sets the state status to success and the percent to 100.
859
+ *
860
+ * @returns
861
+ * This object.
862
+ */ _define_property$2(this, "success", this.status.bind(this, ZJobStatus.Success));
863
+ /**
864
+ * Sets the percentage to 0.
865
+ */ _define_property$2(this, "start", this.percent.bind(this, 0));
866
+ /**
867
+ * Sets the percentage to 100.
868
+ */ _define_property$2(this, "complete", this.percent.bind(this, 100));
869
+ }
870
+ }
871
+
617
872
  var ZRomulatorGameMediaType = /*#__PURE__*/ function(ZRomulatorGameMediaType) {
618
873
  /**
619
874
  * A 3d representation of the box art.
@@ -1129,6 +1384,9 @@ function _define_property(obj, key, value) {
1129
1384
  }
1130
1385
  }
1131
1386
 
1387
+ exports.ZJobBuilder = ZJobBuilder;
1388
+ exports.ZJobStatus = ZJobStatus;
1389
+ exports.ZJobType = ZJobType;
1132
1390
  exports.ZRomulatorConfigBuilder = ZRomulatorConfigBuilder;
1133
1391
  exports.ZRomulatorConfigGamesBuilder = ZRomulatorConfigGamesBuilder;
1134
1392
  exports.ZRomulatorConfigGamesMetadata = ZRomulatorConfigGamesMetadata;