itd-api 0.11.0 → 0.12.1

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 (71) hide show
  1. package/dist/events/index.cjs +3 -3
  2. package/dist/events/index.d.cts +2 -2
  3. package/dist/events/index.d.ts +2 -2
  4. package/dist/events/index.js +3 -3
  5. package/dist/index.cjs +28 -48
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +23 -19
  8. package/dist/index.d.ts +23 -19
  9. package/dist/index.js +26 -49
  10. package/dist/index.js.map +1 -1
  11. package/dist/node/index.cjs +2 -2
  12. package/dist/node/index.cjs.map +1 -1
  13. package/dist/node/index.d.cts +7 -8
  14. package/dist/node/index.d.ts +7 -8
  15. package/dist/node/index.js +2 -2
  16. package/dist/node/index.js.map +1 -1
  17. package/dist/rest/index.cjs +7 -4
  18. package/dist/rest/index.cjs.map +1 -1
  19. package/dist/rest/index.d.cts +5 -5
  20. package/dist/rest/index.d.ts +5 -5
  21. package/dist/rest/index.js +5 -5
  22. package/dist/rest/index.js.map +1 -1
  23. package/dist/shared/{events-CAb9G7Sf.d.ts → events-9215JDDd.d.ts} +2 -2
  24. package/dist/shared/{events-C6tmj8aW.cjs → events-BKyxZQNw.cjs} +246 -56
  25. package/dist/shared/events-BKyxZQNw.cjs.map +1 -0
  26. package/dist/shared/{events-Sc75x6rT.d.cts → events-FaXfdle0.d.cts} +2 -2
  27. package/dist/shared/{events-MWNcnfrq.js → events-_iYo8EP5.js} +246 -56
  28. package/dist/shared/events-_iYo8EP5.js.map +1 -0
  29. package/dist/shared/key-value-store-DYSPsqwq.cjs.map +1 -1
  30. package/dist/shared/key-value-store-w1Dn5Pjb.js.map +1 -1
  31. package/dist/shared/{multi-storage-C7-Gz6Z7.cjs → multi-storage-7Y3KCseI.cjs} +2 -2
  32. package/dist/shared/multi-storage-7Y3KCseI.cjs.map +1 -0
  33. package/dist/shared/{multi-storage-BLBrGN9Q.js → multi-storage-DiBSx64p.js} +2 -2
  34. package/dist/shared/multi-storage-DiBSx64p.js.map +1 -0
  35. package/dist/shared/{options-5tywTYId.cjs → options-D5ttspWk.cjs} +2 -2
  36. package/dist/shared/{options-5tywTYId.cjs.map → options-D5ttspWk.cjs.map} +1 -1
  37. package/dist/shared/{options-BerKicCs.js → options-DLlaETn_.js} +2 -2
  38. package/dist/shared/{options-BerKicCs.js.map → options-DLlaETn_.js.map} +1 -1
  39. package/dist/shared/{redact-DoC7lSsp.cjs → redact-BbhtA9o-.cjs} +13 -3
  40. package/dist/shared/redact-BbhtA9o-.cjs.map +1 -0
  41. package/dist/shared/{redact-C5oxIvcc.js → redact-DSfdmeY7.js} +13 -3
  42. package/dist/shared/redact-DSfdmeY7.js.map +1 -0
  43. package/dist/shared/{render-Dnc84B4M.cjs → render-BQvC5UxF.cjs} +134 -49
  44. package/dist/shared/render-BQvC5UxF.cjs.map +1 -0
  45. package/dist/shared/{render-CBroJPcV.d.ts → render-BS09ygcy.d.ts} +84 -70
  46. package/dist/shared/{render-DRh5_aRe.js → render-CFoF2WaH.js} +134 -49
  47. package/dist/shared/render-CFoF2WaH.js.map +1 -0
  48. package/dist/shared/{render-DM7AhTZW.d.cts → render-X2JCo1JS.d.cts} +84 -70
  49. package/dist/shared/storage-86wiHeXD.js.map +1 -1
  50. package/dist/shared/storage-CIjejZDt.cjs.map +1 -1
  51. package/dist/shared/{url-Bg61sk_Y.js → url-CdT4lMxQ.js} +25 -12
  52. package/dist/shared/url-CdT4lMxQ.js.map +1 -0
  53. package/dist/shared/{url-BOi-_mJT.d.ts → url-_R0oJ7gE.d.cts} +102 -53
  54. package/dist/shared/{url-BOi-_mJT.d.cts → url-_R0oJ7gE.d.ts} +102 -53
  55. package/dist/shared/{url-DTgkCWv5.cjs → url-ioIaywDi.cjs} +42 -11
  56. package/dist/shared/url-ioIaywDi.cjs.map +1 -0
  57. package/dist/web/index.cjs.map +1 -1
  58. package/dist/web/index.d.cts +4 -5
  59. package/dist/web/index.d.ts +4 -5
  60. package/dist/web/index.js.map +1 -1
  61. package/package.json +11 -11
  62. package/dist/shared/events-C6tmj8aW.cjs.map +0 -1
  63. package/dist/shared/events-MWNcnfrq.js.map +0 -1
  64. package/dist/shared/multi-storage-BLBrGN9Q.js.map +0 -1
  65. package/dist/shared/multi-storage-C7-Gz6Z7.cjs.map +0 -1
  66. package/dist/shared/redact-C5oxIvcc.js.map +0 -1
  67. package/dist/shared/redact-DoC7lSsp.cjs.map +0 -1
  68. package/dist/shared/render-DRh5_aRe.js.map +0 -1
  69. package/dist/shared/render-Dnc84B4M.cjs.map +0 -1
  70. package/dist/shared/url-Bg61sk_Y.js.map +0 -1
  71. package/dist/shared/url-DTgkCWv5.cjs.map +0 -1
@@ -1,6 +1,6 @@
1
- const require_url = require("./url-DTgkCWv5.cjs");
1
+ const require_url = require("./url-ioIaywDi.cjs");
2
2
  const require_validate = require("./validate-CFx2dISs.cjs");
3
- const require_redact = require("./redact-DoC7lSsp.cjs");
3
+ const require_redact = require("./redact-BbhtA9o-.cjs");
4
4
  //#region src/core/emitter.ts
5
5
  /**
6
6
  * Минимальный типизированный источник событий.
@@ -912,82 +912,228 @@ var PollTransport = class {
912
912
  }
913
913
  };
914
914
  //#endregion
915
- //#region node_modules/eventsource-parser/dist/index.js
915
+ //#region node_modules/eventsource-parser/dist/errors.js
916
+ /**
917
+ * Error thrown when encountering an issue during parsing.
918
+ *
919
+ * @public
920
+ */
916
921
  var ParseError = class extends Error {
917
922
  constructor(message, options) {
918
- super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
923
+ super(message);
924
+ this.name = "ParseError";
925
+ this.type = options.type;
926
+ this.field = options.field;
927
+ this.value = options.value;
928
+ this.line = options.line;
919
929
  }
920
930
  };
931
+ //#endregion
932
+ //#region node_modules/eventsource-parser/dist/parse.js
933
+ /**
934
+ * EventSource/Server-Sent Events parser
935
+ * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
936
+ */
921
937
  const LF = 10;
922
938
  const CR = 13;
923
939
  const SPACE = 32;
924
- function noop(_arg) {}
940
+ const MAX_FIELD_PREFIX_LENGTH = 6;
941
+ /**
942
+ * Creates a new EventSource parser.
943
+ *
944
+ * @param config - Parser configuration. Accepts callbacks (see {@link ParserCallbacks})
945
+ * and options like `maxBufferSize` (see {@link ParserConfig}).
946
+ *
947
+ * @returns A new EventSource parser, with `feed` and `reset` methods.
948
+ * @public
949
+ */
925
950
  function createParser(config) {
926
- if (typeof config == "function") throw new TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");
927
- const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
928
- let pendingFragmentsLength = 0, isFirstChunk = !0, id, data = "", dataLines = 0, eventType, terminated = !1;
951
+ if (typeof config === "function") throw new TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");
952
+ const { maxBufferSize, onComment, onError, onEvent, onId, onRetry } = config;
953
+ const pendingFragments = [];
954
+ let pendingFragmentsLength = 0;
955
+ let bomPrefix = "";
956
+ let id;
957
+ let data = "";
958
+ let dataLines = 0;
959
+ let eventType;
960
+ let terminated = false;
961
+ let skippingLine = false;
962
+ let skipNextLineFeed = false;
963
+ /**
964
+ * Feeds a chunk of the SSE stream to the parser. Any trailing bytes that do
965
+ * not yet form a complete line are held back and prepended to the next chunk,
966
+ * so callers can pass arbitrary slices of the stream without worrying about
967
+ * line boundaries.
968
+ *
969
+ * Per the SSE spec, one leading UTF-8 BOM is stripped before parsing,
970
+ * even when split across chunks. This handles both the raw 3-byte form (0xEF 0xBB
971
+ * 0xBF) and a single decoded U+FEFF, so a leading BOM is ignored regardless of
972
+ * how the caller decoded the bytes.
973
+ *
974
+ * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream
975
+ */
929
976
  function feed(chunk) {
930
977
  if (terminated) throw new Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");
931
- if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
932
- const trailing2 = processLines(chunk);
933
- trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
978
+ if (bomPrefix !== void 0) {
979
+ chunk = bomPrefix + chunk;
980
+ if (chunk === "" || chunk === "ï" || chunk === "ï»") {
981
+ bomPrefix = chunk;
982
+ return;
983
+ }
984
+ bomPrefix = void 0;
985
+ chunk = chunk.replace(/^(?:\uFEFF|\xEF\xBB\xBF)/, "");
986
+ }
987
+ if (skippingLine || skipNextLineFeed) {
988
+ chunk = resumeAfterSkip(chunk);
989
+ if (!chunk) return;
990
+ }
991
+ if (!pendingFragments.length) {
992
+ const trailing = processLines(chunk);
993
+ if (trailing !== "") storeTrailing(trailing);
994
+ checkBufferSize();
934
995
  return;
935
996
  }
936
- if (chunk.indexOf(`
937
- `) === -1 && chunk.indexOf("\r") === -1) {
938
- pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
997
+ if (chunk.indexOf("\n") === -1 && chunk.indexOf("\r") === -1) {
998
+ if (pendingFragmentsLength < MAX_FIELD_PREFIX_LENGTH) {
999
+ if (!shouldBufferTrailing(pendingFragments.join("") + chunk.slice(0, MAX_FIELD_PREFIX_LENGTH - pendingFragmentsLength))) {
1000
+ pendingFragments.length = 0;
1001
+ pendingFragmentsLength = 0;
1002
+ skippingLine = true;
1003
+ return;
1004
+ }
1005
+ }
1006
+ pendingFragments.push(chunk);
1007
+ pendingFragmentsLength += chunk.length;
1008
+ checkBufferSize();
939
1009
  return;
940
1010
  }
941
1011
  pendingFragments.push(chunk);
942
1012
  const input = pendingFragments.join("");
943
- pendingFragments.length = 0, pendingFragmentsLength = 0;
944
- const trailing = processLines(input);
945
- trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
1013
+ pendingFragments.length = 0;
1014
+ pendingFragmentsLength = 0;
1015
+ storeTrailing(processLines(input));
1016
+ checkBufferSize();
1017
+ }
1018
+ function resumeAfterSkip(chunk) {
1019
+ if (chunk.length === 0) return chunk;
1020
+ if (skipNextLineFeed) {
1021
+ skipNextLineFeed = false;
1022
+ return chunk.charCodeAt(0) === LF ? chunk.slice(1) : chunk;
1023
+ }
1024
+ const crIndex = chunk.indexOf("\r");
1025
+ const lfIndex = chunk.indexOf("\n");
1026
+ const lineEnd = crIndex === -1 ? lfIndex : lfIndex === -1 ? crIndex : crIndex < lfIndex ? crIndex : lfIndex;
1027
+ if (lineEnd === -1) return "";
1028
+ if (lineEnd === chunk.length - 1 && chunk.charCodeAt(lineEnd) === CR) {
1029
+ skippingLine = false;
1030
+ skipNextLineFeed = true;
1031
+ return "";
1032
+ }
1033
+ skippingLine = false;
1034
+ return chunk.slice(lineEnd + (chunk.charCodeAt(lineEnd) === CR && chunk.charCodeAt(lineEnd + 1) === LF ? 2 : 1));
1035
+ }
1036
+ function storeTrailing(trailing) {
1037
+ if (!trailing) return;
1038
+ if (trailing.charCodeAt(trailing.length - 1) === CR) {
1039
+ parseLine(trailing, 0, trailing.length - 1);
1040
+ skipNextLineFeed = true;
1041
+ return;
1042
+ }
1043
+ if (shouldBufferTrailing(trailing)) {
1044
+ pendingFragments.push(trailing);
1045
+ pendingFragmentsLength = trailing.length;
1046
+ return;
1047
+ }
1048
+ skippingLine = true;
1049
+ }
1050
+ function shouldBufferTrailing(trailing) {
1051
+ const firstCharCode = trailing.charCodeAt(0);
1052
+ return firstCharCode === 58 && !!onComment || firstCharCode === 100 && isPotentialField(trailing, "data") || firstCharCode === 101 && isPotentialField(trailing, "event") || firstCharCode === 105 && isPotentialField(trailing, "id") || firstCharCode === 114 && isPotentialField(trailing, "retry");
946
1053
  }
947
1054
  function checkBufferSize() {
948
- maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = !0, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, { type: "max-buffer-size-exceeded" }))));
1055
+ if (maxBufferSize === void 0) return;
1056
+ if (pendingFragmentsLength + data.length <= maxBufferSize) return;
1057
+ terminated = true;
1058
+ pendingFragments.length = 0;
1059
+ pendingFragmentsLength = 0;
1060
+ id = void 0;
1061
+ data = "";
1062
+ dataLines = 0;
1063
+ eventType = void 0;
1064
+ skippingLine = false;
1065
+ skipNextLineFeed = false;
1066
+ onError === null || onError === void 0 || onError(new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, { type: "max-buffer-size-exceeded" }));
949
1067
  }
1068
+ /**
1069
+ * Splits `chunk` into SSE lines and dispatches each to the appropriate handler.
1070
+ * Returns any trailing bytes that did not terminate with a line break, so the
1071
+ * caller can prepend them to the next chunk.
1072
+ *
1073
+ * The SSE spec permits three line terminators: `\n`, `\r`, and `\r\n`. Real-world
1074
+ * streams almost always use plain `\n`, so we take a fast path when no `\r` is
1075
+ * present in the chunk. The slow path is spec-correct but does more work per line.
1076
+ */
950
1077
  function processLines(chunk) {
951
1078
  let searchIndex = 0;
952
1079
  if (chunk.indexOf("\r") === -1) {
953
- let lfIndex = chunk.indexOf(`
954
- `, searchIndex);
955
- for (; lfIndex !== -1;) {
1080
+ let lfIndex = chunk.indexOf("\n", searchIndex);
1081
+ while (lfIndex !== -1) {
956
1082
  if (searchIndex === lfIndex) {
957
- dataLines > 0 && onEvent({
1083
+ if (id !== void 0) onId === null || onId === void 0 || onId(id);
1084
+ if (dataLines > 0) onEvent === null || onEvent === void 0 || onEvent({
958
1085
  id,
959
1086
  event: eventType,
960
1087
  data
961
- }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
962
- `, searchIndex);
1088
+ });
1089
+ id = void 0;
1090
+ data = "";
1091
+ dataLines = 0;
1092
+ eventType = void 0;
1093
+ searchIndex = lfIndex + 1;
1094
+ lfIndex = chunk.indexOf("\n", searchIndex);
963
1095
  continue;
964
1096
  }
965
1097
  const firstCharCode = chunk.charCodeAt(searchIndex);
966
1098
  if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
967
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
1099
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5;
1100
+ const value = chunk.slice(valueStart, lfIndex);
968
1101
  if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
969
- onEvent({
1102
+ if (id !== void 0) onId === null || onId === void 0 || onId(id);
1103
+ onEvent === null || onEvent === void 0 || onEvent({
970
1104
  id,
971
1105
  event: eventType,
972
1106
  data: value
973
- }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
974
- `, searchIndex);
1107
+ });
1108
+ id = void 0;
1109
+ data = "";
1110
+ eventType = void 0;
1111
+ searchIndex = lfIndex + 2;
1112
+ lfIndex = chunk.indexOf("\n", searchIndex);
975
1113
  continue;
976
1114
  }
977
- data = dataLines === 0 ? value : `${data}
978
- ${value}`, dataLines++;
979
- } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6, lfIndex) || void 0 : parseLine(chunk, searchIndex, lfIndex);
980
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
981
- `, searchIndex);
1115
+ data = dataLines === 0 ? value : `${data}\n${value}`;
1116
+ dataLines++;
1117
+ } else if (isEventPrefix(chunk, searchIndex, firstCharCode)) eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6, lfIndex) || void 0;
1118
+ else parseLine(chunk, searchIndex, lfIndex);
1119
+ searchIndex = lfIndex + 1;
1120
+ lfIndex = chunk.indexOf("\n", searchIndex);
982
1121
  }
983
1122
  return chunk.slice(searchIndex);
984
1123
  }
985
- for (; searchIndex < chunk.length;) {
986
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
987
- `, searchIndex);
1124
+ while (searchIndex < chunk.length) {
1125
+ const crIndex = chunk.indexOf("\r", searchIndex);
1126
+ const lfIndex = chunk.indexOf("\n", searchIndex);
988
1127
  let lineEnd = -1;
989
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) break;
990
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
1128
+ if (crIndex !== -1 && lfIndex !== -1) lineEnd = crIndex < lfIndex ? crIndex : lfIndex;
1129
+ else if (crIndex !== -1) {
1130
+ if (crIndex === chunk.length - 1) lineEnd = -1;
1131
+ else lineEnd = crIndex;
1132
+ } else if (lfIndex !== -1) lineEnd = lfIndex;
1133
+ if (lineEnd === -1) break;
1134
+ parseLine(chunk, searchIndex, lineEnd);
1135
+ searchIndex = lineEnd + 1;
1136
+ if (chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF) searchIndex++;
991
1137
  }
992
1138
  return chunk.slice(searchIndex);
993
1139
  }
@@ -998,9 +1144,10 @@ ${value}`, dataLines++;
998
1144
  }
999
1145
  const firstCharCode = chunk.charCodeAt(start);
1000
1146
  if (isDataPrefix(chunk, start, firstCharCode)) {
1001
- const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
1002
- data = dataLines === 0 ? value2 : `${data}
1003
- ${value2}`, dataLines++;
1147
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5;
1148
+ const value = chunk.slice(valueStart, end);
1149
+ data = dataLines === 0 ? value : `${data}\n${value}`;
1150
+ dataLines++;
1004
1151
  return;
1005
1152
  }
1006
1153
  if (isEventPrefix(chunk, start, firstCharCode)) {
@@ -1008,23 +1155,25 @@ ${value2}`, dataLines++;
1008
1155
  return;
1009
1156
  }
1010
1157
  if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
1011
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
1012
- value2.includes("\0") || (id = value2);
1158
+ const value = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
1159
+ if (!value.includes("\0")) id = value;
1013
1160
  return;
1014
1161
  }
1015
1162
  if (firstCharCode === 58) {
1016
1163
  if (onComment) {
1017
- const line2 = chunk.slice(start, end);
1018
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
1164
+ const line = chunk.slice(start, end);
1165
+ onComment(line.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
1019
1166
  }
1020
1167
  return;
1021
1168
  }
1022
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
1169
+ const line = chunk.slice(start, end);
1170
+ const fieldSeparatorIndex = line.indexOf(":");
1023
1171
  if (fieldSeparatorIndex === -1) {
1024
1172
  processField(line, "", line);
1025
1173
  return;
1026
1174
  }
1027
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1;
1175
+ const field = line.slice(0, fieldSeparatorIndex);
1176
+ const offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1;
1028
1177
  processField(field, line.slice(fieldSeparatorIndex + offset), line);
1029
1178
  }
1030
1179
  function processField(field, value, line) {
@@ -1033,20 +1182,21 @@ ${value2}`, dataLines++;
1033
1182
  eventType = value || void 0;
1034
1183
  break;
1035
1184
  case "data":
1036
- data = dataLines === 0 ? value : `${data}
1037
- ${value}`, dataLines++;
1185
+ data = dataLines === 0 ? value : `${data}\n${value}`;
1186
+ dataLines++;
1038
1187
  break;
1039
1188
  case "id":
1040
- value.includes("\0") || (id = value);
1189
+ if (!value.includes("\0")) id = value;
1041
1190
  break;
1042
1191
  case "retry":
1043
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(new ParseError(`Invalid \`retry\` value: "${value}"`, {
1192
+ if (/^\d+$/.test(value)) onRetry === null || onRetry === void 0 || onRetry(parseInt(value, 10));
1193
+ else onError === null || onError === void 0 || onError(new ParseError(`Invalid \`retry\` value: "${value}"`, {
1044
1194
  type: "invalid-retry",
1045
1195
  value,
1046
1196
  line
1047
1197
  }));
1048
1198
  break;
1049
- default: onError(new ParseError(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`, {
1199
+ default: onError === null || onError === void 0 || onError(new ParseError(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}…` : field}"`, {
1050
1200
  type: "unknown-field",
1051
1201
  field,
1052
1202
  value,
@@ -1055,30 +1205,70 @@ ${value}`, dataLines++;
1055
1205
  }
1056
1206
  }
1057
1207
  function dispatchEvent() {
1058
- dataLines > 0 && onEvent({
1208
+ if (id !== void 0) onId === null || onId === void 0 || onId(id);
1209
+ if (dataLines > 0) onEvent === null || onEvent === void 0 || onEvent({
1059
1210
  id,
1060
1211
  event: eventType,
1061
1212
  data
1062
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
1213
+ });
1214
+ id = void 0;
1215
+ data = "";
1216
+ dataLines = 0;
1217
+ eventType = void 0;
1063
1218
  }
1064
1219
  function reset(options = {}) {
1065
1220
  if (options.consume && pendingFragments.length > 0) {
1066
1221
  const incompleteLine = pendingFragments.join("");
1067
1222
  parseLine(incompleteLine, 0, incompleteLine.length);
1068
1223
  }
1069
- isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = !1;
1224
+ bomPrefix = "";
1225
+ id = void 0;
1226
+ data = "";
1227
+ dataLines = 0;
1228
+ eventType = void 0;
1229
+ pendingFragments.length = 0;
1230
+ pendingFragmentsLength = 0;
1231
+ terminated = false;
1232
+ skippingLine = false;
1233
+ skipNextLineFeed = false;
1070
1234
  }
1071
1235
  return {
1072
1236
  feed,
1073
1237
  reset
1074
1238
  };
1075
1239
  }
1240
+ /**
1241
+ * Checks if `chunk` starts with the literal `data:` at index `i`.
1242
+ *
1243
+ * Equivalent to `chunk.startsWith('data:', i)`, but benchmarks show this
1244
+ * hand-unrolled char-code comparison is ~20% faster on common event types.
1245
+ * The caller passes `firstCharCode` (the code at `i`) so it can be reused
1246
+ * across prefix checks.
1247
+ *
1248
+ * ASCII: 'd' = 100, 'a' = 97, 't' = 116, 'a' = 97, ':' = 58
1249
+ */
1076
1250
  function isDataPrefix(chunk, i, firstCharCode) {
1077
1251
  return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
1078
1252
  }
1253
+ /**
1254
+ * Checks if `chunk` starts with the literal `event:` at index `i`.
1255
+ *
1256
+ * See {@link isDataPrefix} for why this is hand-unrolled rather than using
1257
+ * `String.prototype.startsWith`.
1258
+ *
1259
+ * ASCII: 'e' = 101, 'v' = 118, 'e' = 101, 'n' = 110, 't' = 116, ':' = 58
1260
+ */
1079
1261
  function isEventPrefix(chunk, i, firstCharCode) {
1080
1262
  return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
1081
1263
  }
1264
+ function isPotentialField(line, field) {
1265
+ let i = 1;
1266
+ while (i < line.length && i < field.length) {
1267
+ if (line.charCodeAt(i) !== field.charCodeAt(i)) return false;
1268
+ i++;
1269
+ }
1270
+ return line.length <= field.length || line.charCodeAt(field.length) === 58;
1271
+ }
1082
1272
  //#endregion
1083
1273
  //#region src/events/transports/sse.ts
1084
1274
  /** Путь потока уведомлений. */
@@ -2262,4 +2452,4 @@ Object.defineProperty(exports, "setNotificationEventsConnectGuard", {
2262
2452
  }
2263
2453
  });
2264
2454
 
2265
- //# sourceMappingURL=events-C6tmj8aW.cjs.map
2455
+ //# sourceMappingURL=events-BKyxZQNw.cjs.map