@zlink-systems/stream-connector 0.30.3 → 0.32.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.
@@ -794,20 +794,22 @@ var ZlinkStreamConnectorBundle = (() => {
794
794
  if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
795
795
  throw new TypeError("framework-json-v1 payload is not a JSON value.");
796
796
  }
797
- const encoded = JSON.stringify(
798
- value,
799
- replacer === void 0 ? frameworkJsonV1Replacer : function(key, item) {
800
- const transformed = replacer.call(this, key, item);
801
- return frameworkJsonV1Replacer.call({ [key]: transformed }, key, transformed);
802
- }
803
- );
797
+ const encoded = replacer === void 0 ? JSON.stringify(value, frameworkJsonV1Replacer) : stringifyWithReplacer(value, replacer);
804
798
  if (schema !== void 0) {
805
799
  validateFrameworkJsonV1Value(JSON.parse(encoded), schema, "$", false);
806
800
  }
807
801
  return encoded;
808
802
  }
803
+ function stringifyWithReplacer(value, replacer) {
804
+ return JSON.stringify(value, function(key, item) {
805
+ const transformed = replacer.call(this, key, item);
806
+ return frameworkJsonV1Value(transformed, transformed);
807
+ });
808
+ }
809
809
  function frameworkJsonV1Replacer(key, item) {
810
- const source = this[key];
810
+ return frameworkJsonV1Value(this[key], item);
811
+ }
812
+ function frameworkJsonV1Value(source, item) {
811
813
  if (typeof source === "number" && !Number.isFinite(source)) {
812
814
  throw new TypeError("framework-json-v1 only accepts finite JSON numbers.");
813
815
  }
@@ -948,18 +950,21 @@ var ZlinkStreamConnectorBundle = (() => {
948
950
  this.text = text;
949
951
  this.options = options;
950
952
  __publicField(this, "index", 0);
953
+ __publicField(this, "firstEscape");
954
+ const escape = text.indexOf("\\");
955
+ this.firstEscape = escape === -1 ? text.length : escape;
951
956
  }
952
957
  scan() {
953
958
  this.skipWhitespace();
954
- this.scanValue();
959
+ this.scanValue([]);
955
960
  this.skipWhitespace();
956
961
  if (this.index !== this.text.length) this.fail("trailing data");
957
962
  }
958
- scanValue() {
963
+ scanValue(path) {
959
964
  this.skipWhitespace();
960
965
  const token = this.text[this.index];
961
- if (token === "{") return this.scanObject();
962
- if (token === "[") return this.scanArray();
966
+ if (token === "{") return this.scanObject(path);
967
+ if (token === "[") return this.scanArray(path);
963
968
  if (token === '"') {
964
969
  this.scanString();
965
970
  return;
@@ -969,7 +974,7 @@ var ZlinkStreamConnectorBundle = (() => {
969
974
  if (token === "n") return this.scanLiteral("null");
970
975
  this.scanNumber();
971
976
  }
972
- scanObject() {
977
+ scanObject(path) {
973
978
  var _a, _b;
974
979
  this.index++;
975
980
  this.skipWhitespace();
@@ -983,7 +988,11 @@ var ZlinkStreamConnectorBundle = (() => {
983
988
  if (this.text[this.index] !== '"') this.fail("object property name");
984
989
  const property = this.scanString();
985
990
  if (properties.has(property)) {
986
- throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
991
+ if (this.options.onDuplicateProperty !== void 0) {
992
+ this.options.onDuplicateProperty(property, path);
993
+ } else {
994
+ throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
995
+ }
987
996
  }
988
997
  properties.add(property);
989
998
  if (((_b = (_a = this.options).rejectPropertyName) == null ? void 0 : _b.call(_a, property)) === true) {
@@ -992,14 +1001,14 @@ var ZlinkStreamConnectorBundle = (() => {
992
1001
  this.skipWhitespace();
993
1002
  if (this.text[this.index] !== ":") this.fail("':' after object property");
994
1003
  this.index++;
995
- this.scanValue();
1004
+ this.scanValue(this.options.onDuplicateProperty === void 0 ? path : [...path, property]);
996
1005
  this.skipWhitespace();
997
1006
  const delimiter = this.text[this.index++];
998
1007
  if (delimiter === "}") return;
999
1008
  if (delimiter !== ",") this.fail("',' or '}' after object property");
1000
1009
  }
1001
1010
  }
1002
- scanArray() {
1011
+ scanArray(path) {
1003
1012
  this.index++;
1004
1013
  this.skipWhitespace();
1005
1014
  if (this.text[this.index] === "]") {
@@ -1007,7 +1016,7 @@ var ZlinkStreamConnectorBundle = (() => {
1007
1016
  return;
1008
1017
  }
1009
1018
  for (; ; ) {
1010
- this.scanValue();
1019
+ this.scanValue(this.options.onDuplicateProperty === void 0 ? path : [...path, "[]"]);
1011
1020
  this.skipWhitespace();
1012
1021
  const delimiter = this.text[this.index++];
1013
1022
  if (delimiter === "]") return;
@@ -1015,19 +1024,32 @@ var ZlinkStreamConnectorBundle = (() => {
1015
1024
  }
1016
1025
  }
1017
1026
  scanString() {
1018
- const start = this.index++;
1027
+ const text = this.text;
1028
+ const start = this.index;
1029
+ let index = start + 1;
1030
+ const end = text.indexOf('"', index);
1031
+ if (end !== -1 && end < this.firstEscape) {
1032
+ this.index = end + 1;
1033
+ return text.slice(index, end);
1034
+ }
1019
1035
  let sawEscape = false;
1020
1036
  for (; ; ) {
1021
- if (this.index >= this.text.length) this.fail("unterminated string");
1022
- const character = this.text[this.index++];
1037
+ if (index >= text.length) {
1038
+ this.index = index;
1039
+ this.fail("unterminated string");
1040
+ }
1041
+ const character = text[index++];
1023
1042
  if (character === '"') {
1024
- return sawEscape ? JSON.parse(this.text.slice(start, this.index)) : this.text.slice(start + 1, this.index - 1);
1043
+ this.index = index;
1044
+ return sawEscape ? JSON.parse(text.slice(start, index)) : text.slice(start + 1, index - 1);
1025
1045
  }
1026
1046
  if (character === "\\") {
1027
1047
  sawEscape = true;
1028
- if (this.index >= this.text.length) this.fail("unterminated escape");
1029
- const escaped = this.text[this.index++];
1030
- if (escaped === "u") this.index += 4;
1048
+ if (index >= text.length) {
1049
+ this.index = index;
1050
+ this.fail("unterminated escape");
1051
+ }
1052
+ if (text[index++] === "u") index += 4;
1031
1053
  }
1032
1054
  }
1033
1055
  }
@@ -2921,6 +2943,10 @@ var ZlinkStreamConnectorBundle = (() => {
2921
2943
  }
2922
2944
  }
2923
2945
  async dispatch(connection, header, payload, signal) {
2946
+ if (header.kind === 5 /* Control */) {
2947
+ await this.dispatchControl(connection, header, payload, signal);
2948
+ return;
2949
+ }
2924
2950
  const actor = header.actorSlot === void 0 ? void 0 : this.actors.resolve(header.actorSlot);
2925
2951
  if (header.kind === 3 /* Response */ && header.requestSeq !== void 0) {
2926
2952
  try {
@@ -2962,10 +2988,6 @@ var ZlinkStreamConnectorBundle = (() => {
2962
2988
  }
2963
2989
  return;
2964
2990
  }
2965
- if (header.kind === 5 /* Control */) {
2966
- await this.dispatchControl(connection, header, payload, signal);
2967
- return;
2968
- }
2969
2991
  if (header.kind === 1 /* Send */) {
2970
2992
  this.receivedMessages.enqueue(
2971
2993
  {
@@ -2989,16 +3011,16 @@ var ZlinkStreamConnectorBundle = (() => {
2989
3011
  await ((_a = this.serverClosing) == null ? void 0 : _a.call(this, closing.closeReason));
2990
3012
  return;
2991
3013
  }
2992
- if (payload.length !== 0) {
2993
- throw connectorError(
2994
- "frameDecodeFailed" /* FrameDecodeFailed */,
2995
- "Control packet payload must be empty."
2996
- );
2997
- }
2998
3014
  if (header.name === ZLINK_STREAM_HEARTBEAT_PING) {
2999
3015
  await this.frameSender.sendControl(connection, ZLINK_STREAM_HEARTBEAT_PONG);
3000
3016
  return;
3001
3017
  }
3018
+ if (header.name === ZLINK_STREAM_HEARTBEAT_PONG) {
3019
+ return;
3020
+ }
3021
+ if (header.name.startsWith("$zlink.")) {
3022
+ return;
3023
+ }
3002
3024
  if (header.name !== ZLINK_STREAM_HEARTBEAT_PONG) {
3003
3025
  throw connectorError("frameDecodeFailed" /* FrameDecodeFailed */, "Unknown control packet.");
3004
3026
  }
@@ -749,20 +749,22 @@ function stringifyFrameworkJsonV1(value, schema, replacer) {
749
749
  if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
750
750
  throw new TypeError("framework-json-v1 payload is not a JSON value.");
751
751
  }
752
- const encoded = JSON.stringify(
753
- value,
754
- replacer === void 0 ? frameworkJsonV1Replacer : function(key, item) {
755
- const transformed = replacer.call(this, key, item);
756
- return frameworkJsonV1Replacer.call({ [key]: transformed }, key, transformed);
757
- }
758
- );
752
+ const encoded = replacer === void 0 ? JSON.stringify(value, frameworkJsonV1Replacer) : stringifyWithReplacer(value, replacer);
759
753
  if (schema !== void 0) {
760
754
  validateFrameworkJsonV1Value(JSON.parse(encoded), schema, "$", false);
761
755
  }
762
756
  return encoded;
763
757
  }
758
+ function stringifyWithReplacer(value, replacer) {
759
+ return JSON.stringify(value, function(key, item) {
760
+ const transformed = replacer.call(this, key, item);
761
+ return frameworkJsonV1Value(transformed, transformed);
762
+ });
763
+ }
764
764
  function frameworkJsonV1Replacer(key, item) {
765
- const source = this[key];
765
+ return frameworkJsonV1Value(this[key], item);
766
+ }
767
+ function frameworkJsonV1Value(source, item) {
766
768
  if (typeof source === "number" && !Number.isFinite(source)) {
767
769
  throw new TypeError("framework-json-v1 only accepts finite JSON numbers.");
768
770
  }
@@ -902,19 +904,22 @@ var JsonPropertyScanner = class {
902
904
  constructor(text, options) {
903
905
  this.text = text;
904
906
  this.options = options;
907
+ const escape = text.indexOf("\\");
908
+ this.firstEscape = escape === -1 ? text.length : escape;
905
909
  }
906
910
  index = 0;
911
+ firstEscape;
907
912
  scan() {
908
913
  this.skipWhitespace();
909
- this.scanValue();
914
+ this.scanValue([]);
910
915
  this.skipWhitespace();
911
916
  if (this.index !== this.text.length) this.fail("trailing data");
912
917
  }
913
- scanValue() {
918
+ scanValue(path) {
914
919
  this.skipWhitespace();
915
920
  const token = this.text[this.index];
916
- if (token === "{") return this.scanObject();
917
- if (token === "[") return this.scanArray();
921
+ if (token === "{") return this.scanObject(path);
922
+ if (token === "[") return this.scanArray(path);
918
923
  if (token === '"') {
919
924
  this.scanString();
920
925
  return;
@@ -924,7 +929,7 @@ var JsonPropertyScanner = class {
924
929
  if (token === "n") return this.scanLiteral("null");
925
930
  this.scanNumber();
926
931
  }
927
- scanObject() {
932
+ scanObject(path) {
928
933
  this.index++;
929
934
  this.skipWhitespace();
930
935
  if (this.text[this.index] === "}") {
@@ -937,7 +942,11 @@ var JsonPropertyScanner = class {
937
942
  if (this.text[this.index] !== '"') this.fail("object property name");
938
943
  const property = this.scanString();
939
944
  if (properties.has(property)) {
940
- throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
945
+ if (this.options.onDuplicateProperty !== void 0) {
946
+ this.options.onDuplicateProperty(property, path);
947
+ } else {
948
+ throw new SyntaxError(`framework-json-v1 duplicate property '${property}'.`);
949
+ }
941
950
  }
942
951
  properties.add(property);
943
952
  if (this.options.rejectPropertyName?.(property) === true) {
@@ -946,14 +955,14 @@ var JsonPropertyScanner = class {
946
955
  this.skipWhitespace();
947
956
  if (this.text[this.index] !== ":") this.fail("':' after object property");
948
957
  this.index++;
949
- this.scanValue();
958
+ this.scanValue(this.options.onDuplicateProperty === void 0 ? path : [...path, property]);
950
959
  this.skipWhitespace();
951
960
  const delimiter = this.text[this.index++];
952
961
  if (delimiter === "}") return;
953
962
  if (delimiter !== ",") this.fail("',' or '}' after object property");
954
963
  }
955
964
  }
956
- scanArray() {
965
+ scanArray(path) {
957
966
  this.index++;
958
967
  this.skipWhitespace();
959
968
  if (this.text[this.index] === "]") {
@@ -961,7 +970,7 @@ var JsonPropertyScanner = class {
961
970
  return;
962
971
  }
963
972
  for (; ; ) {
964
- this.scanValue();
973
+ this.scanValue(this.options.onDuplicateProperty === void 0 ? path : [...path, "[]"]);
965
974
  this.skipWhitespace();
966
975
  const delimiter = this.text[this.index++];
967
976
  if (delimiter === "]") return;
@@ -969,19 +978,32 @@ var JsonPropertyScanner = class {
969
978
  }
970
979
  }
971
980
  scanString() {
972
- const start = this.index++;
981
+ const text = this.text;
982
+ const start = this.index;
983
+ let index = start + 1;
984
+ const end = text.indexOf('"', index);
985
+ if (end !== -1 && end < this.firstEscape) {
986
+ this.index = end + 1;
987
+ return text.slice(index, end);
988
+ }
973
989
  let sawEscape = false;
974
990
  for (; ; ) {
975
- if (this.index >= this.text.length) this.fail("unterminated string");
976
- const character = this.text[this.index++];
991
+ if (index >= text.length) {
992
+ this.index = index;
993
+ this.fail("unterminated string");
994
+ }
995
+ const character = text[index++];
977
996
  if (character === '"') {
978
- return sawEscape ? JSON.parse(this.text.slice(start, this.index)) : this.text.slice(start + 1, this.index - 1);
997
+ this.index = index;
998
+ return sawEscape ? JSON.parse(text.slice(start, index)) : text.slice(start + 1, index - 1);
979
999
  }
980
1000
  if (character === "\\") {
981
1001
  sawEscape = true;
982
- if (this.index >= this.text.length) this.fail("unterminated escape");
983
- const escaped = this.text[this.index++];
984
- if (escaped === "u") this.index += 4;
1002
+ if (index >= text.length) {
1003
+ this.index = index;
1004
+ this.fail("unterminated escape");
1005
+ }
1006
+ if (text[index++] === "u") index += 4;
985
1007
  }
986
1008
  }
987
1009
  }
@@ -2859,6 +2881,10 @@ var ZlinkStreamReceiveDispatcher = class {
2859
2881
  }
2860
2882
  }
2861
2883
  async dispatch(connection, header, payload, signal) {
2884
+ if (header.kind === 5 /* Control */) {
2885
+ await this.dispatchControl(connection, header, payload, signal);
2886
+ return;
2887
+ }
2862
2888
  const actor = header.actorSlot === void 0 ? void 0 : this.actors.resolve(header.actorSlot);
2863
2889
  if (header.kind === 3 /* Response */ && header.requestSeq !== void 0) {
2864
2890
  try {
@@ -2900,10 +2926,6 @@ var ZlinkStreamReceiveDispatcher = class {
2900
2926
  }
2901
2927
  return;
2902
2928
  }
2903
- if (header.kind === 5 /* Control */) {
2904
- await this.dispatchControl(connection, header, payload, signal);
2905
- return;
2906
- }
2907
2929
  if (header.kind === 1 /* Send */) {
2908
2930
  this.receivedMessages.enqueue(
2909
2931
  {
@@ -2926,16 +2948,16 @@ var ZlinkStreamReceiveDispatcher = class {
2926
2948
  await this.serverClosing?.(closing.closeReason);
2927
2949
  return;
2928
2950
  }
2929
- if (payload.length !== 0) {
2930
- throw connectorError(
2931
- "frameDecodeFailed" /* FrameDecodeFailed */,
2932
- "Control packet payload must be empty."
2933
- );
2934
- }
2935
2951
  if (header.name === ZLINK_STREAM_HEARTBEAT_PING) {
2936
2952
  await this.frameSender.sendControl(connection, ZLINK_STREAM_HEARTBEAT_PONG);
2937
2953
  return;
2938
2954
  }
2955
+ if (header.name === ZLINK_STREAM_HEARTBEAT_PONG) {
2956
+ return;
2957
+ }
2958
+ if (header.name.startsWith("$zlink.")) {
2959
+ return;
2960
+ }
2939
2961
  if (header.name !== ZLINK_STREAM_HEARTBEAT_PONG) {
2940
2962
  throw connectorError("frameDecodeFailed" /* FrameDecodeFailed */, "Unknown control packet.");
2941
2963
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zlink-systems/stream-connector",
3
- "version": "0.30.3",
3
+ "version": "0.32.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,6 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@zlink-systems/stream-wire": "0.30.3"
25
+ "@zlink-systems/stream-wire": "0.32.0"
26
26
  }
27
27
  }