@indra.ai/deva 1.5.26 → 1.5.27
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/index.js +47 -51
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -781,18 +781,17 @@ class Deva {
|
|
|
781
781
|
function or running the enter function.
|
|
782
782
|
usage: this.start('msg')
|
|
783
783
|
***************/
|
|
784
|
-
start(
|
|
785
|
-
|
|
784
|
+
start(data, resolve) {
|
|
785
|
+
this.zone('start', data.id);
|
|
786
|
+
if (!this._active) return resolve(this._messages.offline);
|
|
787
|
+
this.action('start', data.id);
|
|
786
788
|
const id = this.lib.uid();
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
delete packet.hash;
|
|
791
|
-
packet.hash = this.lib.hash(packet);
|
|
789
|
+
delete data.hash;
|
|
790
|
+
data.value = 'start';
|
|
791
|
+
data.hash = this.lib.hash(data);
|
|
792
792
|
const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
|
|
793
|
-
this.state('start');
|
|
794
|
-
this.
|
|
795
|
-
return hasOnStart ? this.onStart(packet, resolve) : this.enter(packet, resolve)
|
|
793
|
+
this.state('start', data.id);
|
|
794
|
+
return hasOnStart ? this.onStart(data, resolve) : this.enter(data, resolve)
|
|
796
795
|
}
|
|
797
796
|
|
|
798
797
|
/**************
|
|
@@ -806,17 +805,16 @@ class Deva {
|
|
|
806
805
|
If the Deva is offline it will return the offline message.
|
|
807
806
|
usage: this.enter('msg')
|
|
808
807
|
***************/
|
|
809
|
-
enter(
|
|
810
|
-
|
|
808
|
+
enter(data, resolve) {
|
|
809
|
+
this.zone('enter', data.id);
|
|
810
|
+
if (!this._active) return resolve(this._messages.offline);
|
|
811
|
+
this.action('enter', data.id);
|
|
811
812
|
const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
this.
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
packet.hash = this.lib.hash(packet);
|
|
818
|
-
this.prompt(this._messages.enter);
|
|
819
|
-
return hasOnEnter ? this.onEnter(packet, resolve) : this.done(packet, resolve)
|
|
813
|
+
delete data.hash;
|
|
814
|
+
data.value = 'enter';
|
|
815
|
+
data.hash = this.lib.hash(data);
|
|
816
|
+
this.state('enter', data.id);
|
|
817
|
+
return hasOnEnter ? this.onEnter(data, resolve) : this.done(data, resolve)
|
|
820
818
|
}
|
|
821
819
|
|
|
822
820
|
/**************
|
|
@@ -830,17 +828,16 @@ class Deva {
|
|
|
830
828
|
If the deva is offline it will return the offline message.
|
|
831
829
|
usage: this.done('msg')
|
|
832
830
|
***************/
|
|
833
|
-
done(
|
|
834
|
-
|
|
831
|
+
done(data, resolve) {
|
|
832
|
+
this.zone('done', data.id);
|
|
833
|
+
if (!this._active) return resolve(this._messages.offline);
|
|
834
|
+
this.action('done', data.id);
|
|
835
835
|
const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
this.
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
packet.hash = this.lib.hash(packet);
|
|
842
|
-
this.prompt(this._messages.done);
|
|
843
|
-
return hasOnDone ? this.onDone(packet, resolve) : this.ready(packet, resolve);
|
|
836
|
+
delete data.hash;
|
|
837
|
+
data.value = 'done';
|
|
838
|
+
data.hash = this.lib.hash(data);
|
|
839
|
+
this.state('done', data.id);
|
|
840
|
+
return hasOnDone ? this.onDone(data, resolve) : this.ready(data, resolve);
|
|
844
841
|
}
|
|
845
842
|
|
|
846
843
|
/**************
|
|
@@ -851,17 +848,16 @@ class Deva {
|
|
|
851
848
|
describe: This function is use to relay the to the ready state.
|
|
852
849
|
usage: this.ready(data, resolve)
|
|
853
850
|
***************/
|
|
854
|
-
ready(
|
|
855
|
-
|
|
851
|
+
ready(data, resolve) {
|
|
852
|
+
this.zone('ready', data.id);
|
|
853
|
+
if (!this._active) return resolve(this._messages.offline);
|
|
854
|
+
this.action('ready', data.id);
|
|
856
855
|
const hasOnReady = this.onReady && typeof this.onReady === 'function';
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
this.
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
packet.hash = this.lib.hash(packet);// hash the entire packet before completeing.
|
|
863
|
-
this.prompt(this._messages.ready);
|
|
864
|
-
return hasOnReady ? this.onReady(packet, resolve) : resolve(packet);
|
|
856
|
+
delete data.hash;
|
|
857
|
+
data.value = 'ready';
|
|
858
|
+
data.hash = this.lib.hash(data);// hash the entire data before completeing.
|
|
859
|
+
this.state('ready', data.id);
|
|
860
|
+
return hasOnReady ? this.onReady(data, resolve) : resolve(data);
|
|
865
861
|
}
|
|
866
862
|
|
|
867
863
|
|
|
@@ -875,11 +871,14 @@ class Deva {
|
|
|
875
871
|
usage: this.finish(data, resolve)
|
|
876
872
|
***************/
|
|
877
873
|
finish(packet, resolve) {
|
|
878
|
-
|
|
874
|
+
this.zone('finish', packet.id); // enter finish zone
|
|
875
|
+
if (!this._active) return resolve(this._messages.offline); //
|
|
876
|
+
this.action('finish', packet.id); // start finish action
|
|
879
877
|
const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
this.
|
|
878
|
+
delete packet.hash; // delete packet hash to update for finish time
|
|
879
|
+
packet.finish = Date.now(); // set the finish timestamp
|
|
880
|
+
packet.hash = this.lib.hash(packet); // rehash the packet;
|
|
881
|
+
this.state('finish', packet.id); // set finish state
|
|
883
882
|
return hasOnFinish ? this.onFinish(packet, resolve) : this.complete(packet, resolve);
|
|
884
883
|
}
|
|
885
884
|
|
|
@@ -893,14 +892,14 @@ class Deva {
|
|
|
893
892
|
usage: this.complete(data, resolve)
|
|
894
893
|
***************/
|
|
895
894
|
complete(packet, resolve) {
|
|
896
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
897
|
-
const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
|
|
898
895
|
this.zone('complete', packet.id);
|
|
896
|
+
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
899
897
|
this.action('complete', packet.id);
|
|
900
|
-
this.
|
|
901
|
-
packet.created = Date.now();// set the complete date on the whole packet.
|
|
898
|
+
const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
|
|
902
899
|
delete packet.hash;
|
|
900
|
+
packet.complete = Date.now();// set the complete date on the whole packet.
|
|
903
901
|
packet.hash = this.lib.hash(packet);// hash the entire packet before complete.
|
|
902
|
+
this.state('complete', packet.id);
|
|
904
903
|
return hasOnComplete ? this.onComplete(packet, resolve) : resolve(packet);
|
|
905
904
|
}
|
|
906
905
|
|
|
@@ -936,7 +935,6 @@ class Deva {
|
|
|
936
935
|
data.hash = this.lib.hash(data);
|
|
937
936
|
// has stop function then set hasOnStop variable
|
|
938
937
|
// if: has on stop then run on stop function or return exit function.
|
|
939
|
-
this.prompt(this._messages.stop);
|
|
940
938
|
return hasOnStop ? this.onStop(data) : this.exit()
|
|
941
939
|
}
|
|
942
940
|
|
|
@@ -969,7 +967,6 @@ class Deva {
|
|
|
969
967
|
data.hash = this.lib.hash(data);
|
|
970
968
|
|
|
971
969
|
this.state('exit', id); // set the state to stop
|
|
972
|
-
this.prompt(this._messages.exit);
|
|
973
970
|
// clear memory
|
|
974
971
|
this._active = false;
|
|
975
972
|
this._client = false;
|
|
@@ -981,7 +978,6 @@ class Deva {
|
|
|
981
978
|
this._legal = false;
|
|
982
979
|
this._authority = false;
|
|
983
980
|
this._justice = false;
|
|
984
|
-
|
|
985
981
|
return hasOnExit ? this.onExit(data) : Promise.resolve(data)
|
|
986
982
|
}
|
|
987
983
|
|