@wishknish/knishio-client-ts 0.9.3 → 0.9.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/dist/index.d.cts CHANGED
@@ -807,6 +807,10 @@ declare class CheckMolecule {
807
807
  isotopeC(): boolean;
808
808
  isotopeT(): boolean;
809
809
  isotopeR(): boolean;
810
+ isotopeP(): boolean;
811
+ isotopeA(): boolean;
812
+ isotopeB(): boolean;
813
+ isotopeF(): boolean;
810
814
  isotopeV(senderWallet?: Wallet | null): boolean;
811
815
  molecularHash(): boolean;
812
816
  ots(): boolean;
package/dist/index.d.ts CHANGED
@@ -807,6 +807,10 @@ declare class CheckMolecule {
807
807
  isotopeC(): boolean;
808
808
  isotopeT(): boolean;
809
809
  isotopeR(): boolean;
810
+ isotopeP(): boolean;
811
+ isotopeA(): boolean;
812
+ isotopeB(): boolean;
813
+ isotopeF(): boolean;
810
814
  isotopeV(senderWallet?: Wallet | null): boolean;
811
815
  molecularHash(): boolean;
812
816
  ots(): boolean;
@@ -5746,7 +5746,10 @@ var KnishIO = (function (exports) {
5746
5746
  const l3 = listeners[event];
5747
5747
  l3.push(listener);
5748
5748
  return () => {
5749
- l3.splice(l3.indexOf(listener), 1);
5749
+ const i4 = l3.indexOf(listener);
5750
+ if (i4 > -1) {
5751
+ l3.splice(i4, 1);
5752
+ }
5750
5753
  };
5751
5754
  },
5752
5755
  emit(event, ...args) {
@@ -22745,9 +22748,9 @@ ${operationTypes.join("\n")}
22745
22748
  }
22746
22749
  });
22747
22750
 
22748
- // node_modules/graphql-ws/dist/server-CYkRkF1s.cjs
22749
- var require_server_CYkRkF1s = __commonJS({
22750
- "node_modules/graphql-ws/dist/server-CYkRkF1s.cjs"(exports) {
22751
+ // node_modules/graphql-ws/dist/server-DN5-9C2B.cjs
22752
+ var require_server_DN5_9C2B = __commonJS({
22753
+ "node_modules/graphql-ws/dist/server-DN5-9C2B.cjs"(exports) {
22751
22754
  var graphql2 = (init_graphql2(), __toCommonJS(graphql_exports));
22752
22755
  var common = require_common_DqFHi7oM();
22753
22756
  function makeServer(options) {
@@ -22755,6 +22758,7 @@ ${operationTypes.join("\n")}
22755
22758
  schema,
22756
22759
  context,
22757
22760
  roots,
22761
+ parse: parse3,
22758
22762
  validate: validate2,
22759
22763
  execute: execute2,
22760
22764
  subscribe: subscribe3,
@@ -22927,7 +22931,7 @@ ${operationTypes.join("\n")}
22927
22931
  throw new Error("The GraphQL schema is not provided");
22928
22932
  const args = {
22929
22933
  operationName: payload.operationName,
22930
- document: graphql2.parse(payload.query),
22934
+ document: (parse3 ?? graphql2.parse)(payload.query),
22931
22935
  variableValues: payload.variables
22932
22936
  };
22933
22937
  execArgs = {
@@ -23071,7 +23075,7 @@ ${operationTypes.join("\n")}
23071
23075
  var require_dist = __commonJS({
23072
23076
  "node_modules/graphql-ws/dist/index.cjs"(exports) {
23073
23077
  var client = require_client();
23074
- var server = require_server_CYkRkF1s();
23078
+ var server = require_server_DN5_9C2B();
23075
23079
  var common = require_common_DqFHi7oM();
23076
23080
  init_graphql2();
23077
23081
  exports.TerminatedCloseEvent = client.TerminatedCloseEvent;
@@ -27686,7 +27690,7 @@ ${operationTypes.join("\n")}
27686
27690
  * @return True if all validations pass
27687
27691
  */
27688
27692
  verify(senderWallet) {
27689
- return this.molecularHash() && this.ots() && this.batchId() && this.continuId() && this.isotopeM() && this.isotopeT() && this.isotopeC() && this.isotopeU() && this.isotopeI() && this.isotopeR() && this.isotopeV(senderWallet || null);
27693
+ return this.molecularHash() && this.ots() && this.batchId() && this.continuId() && this.isotopeM() && this.isotopeT() && this.isotopeC() && this.isotopeU() && this.isotopeI() && this.isotopeR() && this.isotopeP() && this.isotopeA() && this.isotopeB() && this.isotopeF() && this.isotopeV(senderWallet || null);
27690
27694
  }
27691
27695
  /**
27692
27696
  * Validate ContinuID requirement
@@ -27874,6 +27878,141 @@ ${operationTypes.join("\n")}
27874
27878
  }
27875
27879
  return true;
27876
27880
  }
27881
+ /**
27882
+ * Validate isotope P atoms (peering)
27883
+ * @return True if valid
27884
+ * @throws WrongTokenTypeException if the token slug is not USER
27885
+ * @throws MetaMissingException if the required peerHost meta field is absent
27886
+ */
27887
+ isotopeP() {
27888
+ for (const atom of this.molecule.getIsotopes("P")) {
27889
+ if (atom.token !== "USER") {
27890
+ throw new WrongTokenTypeException(`Check::isotopeP() - "${atom.token}" is not a valid Token slug for "${atom.isotope}" isotope Atoms!`);
27891
+ }
27892
+ const metas = atom.aggregatedMeta();
27893
+ if (!Object.prototype.hasOwnProperty.call(metas, "peerHost") || !metas.peerHost) {
27894
+ throw new MetaMissingException('Check::isotopeP() - Required meta field "peerHost" is missing!');
27895
+ }
27896
+ }
27897
+ return true;
27898
+ }
27899
+ /**
27900
+ * Validate isotope A atoms (append request)
27901
+ * @return True if valid
27902
+ * @throws WrongTokenTypeException if the token slug is not USER
27903
+ * @throws MetaMissingException if metaType, metaId or the action meta field is absent
27904
+ */
27905
+ isotopeA() {
27906
+ for (const atom of this.molecule.getIsotopes("A")) {
27907
+ if (atom.token !== "USER") {
27908
+ throw new WrongTokenTypeException(`Check::isotopeA() - "${atom.token}" is not a valid Token slug for "${atom.isotope}" isotope Atoms!`);
27909
+ }
27910
+ if (!atom.metaType) {
27911
+ throw new MetaMissingException('Check::isotopeA() - Required field "metaType" is missing!');
27912
+ }
27913
+ if (!atom.metaId) {
27914
+ throw new MetaMissingException('Check::isotopeA() - Required field "metaId" is missing!');
27915
+ }
27916
+ const metas = atom.aggregatedMeta();
27917
+ if (!Object.prototype.hasOwnProperty.call(metas, "action") || !metas.action) {
27918
+ throw new MetaMissingException('Check::isotopeA() - Required meta field "action" is missing!');
27919
+ }
27920
+ }
27921
+ return true;
27922
+ }
27923
+ /**
27924
+ * Validate isotope B atoms (buffer/exchange)
27925
+ *
27926
+ * Buffer molecules are cross-isotope: their V atoms do not balance on their own
27927
+ * because a B atom absorbs the difference. isotopeV() therefore skips its V-only
27928
+ * conservation checks whenever B (or F) atoms are present, and conservation is
27929
+ * enforced here instead over the combined V+B set.
27930
+ *
27931
+ * @return True if valid
27932
+ * @throws MetaMissingException if metaType is not walletBundle, or metaId is absent
27933
+ * @throws TransferMalformedException if a B atom value is not a number
27934
+ * @throws TransferUnbalancedException if V+B atom values do not sum to zero
27935
+ */
27936
+ isotopeB() {
27937
+ const isotopeB = this.molecule.getIsotopes("B");
27938
+ if (isotopeB.length === 0) {
27939
+ return true;
27940
+ }
27941
+ for (const atom of isotopeB) {
27942
+ if (!atom.metaType || atom.metaType !== "walletBundle") {
27943
+ throw new MetaMissingException('Check::isotopeB() - B-isotope atoms must have metaType "walletBundle"!');
27944
+ }
27945
+ if (!atom.metaId) {
27946
+ throw new MetaMissingException("Check::isotopeB() - B-isotope atoms must have a metaId!");
27947
+ }
27948
+ const value2 = atom.value !== null ? Number(atom.value) : Number.NaN;
27949
+ if (Number.isNaN(value2)) {
27950
+ throw new TransferMalformedException("Check::isotopeB() - B-isotope atom value is not a valid number!");
27951
+ }
27952
+ }
27953
+ const vAtoms = this.molecule.getIsotopes("V");
27954
+ if (vAtoms.length > 0) {
27955
+ let sum = 0;
27956
+ for (const atom of [...vAtoms, ...isotopeB]) {
27957
+ const value2 = atom.value !== null ? Number(atom.value) : Number.NaN;
27958
+ if (!Number.isNaN(value2)) {
27959
+ sum += value2;
27960
+ }
27961
+ }
27962
+ if (sum !== 0) {
27963
+ throw new TransferUnbalancedException("Check::isotopeB() - V+B atom values do not balance to zero!");
27964
+ }
27965
+ }
27966
+ return true;
27967
+ }
27968
+ /**
27969
+ * Validate isotope F atoms (fusion/NFT)
27970
+ *
27971
+ * Mirrors isotopeB() and additionally forbids negative values. Must stay paired
27972
+ * with the hasCrossIsotope gate in isotopeV(), which is keyed on B *or* F: without
27973
+ * this check an F-isotope molecule would skip V-only conservation with nothing
27974
+ * validating V+F conservation in its place.
27975
+ *
27976
+ * @return True if valid
27977
+ * @throws MetaMissingException if metaType is not walletBundle, or metaId is absent
27978
+ * @throws TransferMalformedException if an F atom value is not a number, or is negative
27979
+ * @throws TransferUnbalancedException if V+F atom values do not sum to zero
27980
+ */
27981
+ isotopeF() {
27982
+ const isotopeF = this.molecule.getIsotopes("F");
27983
+ if (isotopeF.length === 0) {
27984
+ return true;
27985
+ }
27986
+ for (const atom of isotopeF) {
27987
+ if (!atom.metaType || atom.metaType !== "walletBundle") {
27988
+ throw new MetaMissingException('Check::isotopeF() - F-isotope atoms must have metaType "walletBundle"!');
27989
+ }
27990
+ if (!atom.metaId) {
27991
+ throw new MetaMissingException("Check::isotopeF() - F-isotope atoms must have a metaId!");
27992
+ }
27993
+ const value2 = atom.value !== null ? Number(atom.value) : Number.NaN;
27994
+ if (Number.isNaN(value2)) {
27995
+ throw new TransferMalformedException("Check::isotopeF() - F-isotope atom value is not a valid number!");
27996
+ }
27997
+ if (value2 < 0) {
27998
+ throw new TransferMalformedException("Check::isotopeF() - F-isotope atom value must not be negative!");
27999
+ }
28000
+ }
28001
+ const vAtoms = this.molecule.getIsotopes("V");
28002
+ if (vAtoms.length > 0) {
28003
+ let sum = 0;
28004
+ for (const atom of [...vAtoms, ...isotopeF]) {
28005
+ const value2 = atom.value !== null ? Number(atom.value) : Number.NaN;
28006
+ if (!Number.isNaN(value2)) {
28007
+ sum += value2;
28008
+ }
28009
+ }
28010
+ if (sum !== 0) {
28011
+ throw new TransferUnbalancedException("Check::isotopeF() - V+F atom values do not balance to zero!");
28012
+ }
28013
+ }
28014
+ return true;
28015
+ }
27877
28016
  /**
27878
28017
  * Validate isotope V atoms (value transfers)
27879
28018
  * @param senderWallet - Optional wallet for balance validation
@@ -27885,11 +28024,12 @@ ${operationTypes.join("\n")}
27885
28024
  if (isotopeV.length === 0) {
27886
28025
  return true;
27887
28026
  }
28027
+ const hasCrossIsotope = this.molecule.getIsotopes("B").length > 0 || this.molecule.getIsotopes("F").length > 0;
27888
28028
  const firstAtom = this.molecule.atoms[0];
27889
28029
  if (!firstAtom) {
27890
28030
  throw new exports.AtomsMissingException("Check::isotopeV() - Missing first atom");
27891
28031
  }
27892
- if (firstAtom.isotope === "V" && isotopeV.length === 2) {
28032
+ if (!hasCrossIsotope && firstAtom.isotope === "V" && isotopeV.length === 2) {
27893
28033
  const endAtom = isotopeV[isotopeV.length - 1];
27894
28034
  if (!endAtom) {
27895
28035
  throw new exports.AtomsMissingException("Check::isotopeV() - Missing end atom");
@@ -27901,6 +28041,10 @@ ${operationTypes.join("\n")}
27901
28041
  if (endValue < 0) {
27902
28042
  throw new TransferMalformedException();
27903
28043
  }
28044
+ const firstValueForPair = firstAtom.value !== null ? Number(firstAtom.value) : 0;
28045
+ if (firstValueForPair + endValue !== 0) {
28046
+ throw new TransferUnbalancedException();
28047
+ }
27904
28048
  return true;
27905
28049
  }
27906
28050
  let sum = 0;
@@ -27929,7 +28073,7 @@ ${operationTypes.join("\n")}
27929
28073
  sum += value2;
27930
28074
  }
27931
28075
  }
27932
- if (sum !== 0) {
28076
+ if (!hasCrossIsotope && sum !== 0) {
27933
28077
  throw new TransferUnbalancedException();
27934
28078
  }
27935
28079
  if (senderWallet) {
@@ -27941,7 +28085,7 @@ ${operationTypes.join("\n")}
27941
28085
  if (remainder < 0) {
27942
28086
  throw new exports.TransferBalanceException();
27943
28087
  }
27944
- if (remainder !== sum) {
28088
+ if (!hasCrossIsotope && remainder !== sum) {
27945
28089
  throw new TransferRemainderException();
27946
28090
  }
27947
28091
  } else if (sum !== 0) {