seroval 1.0.4 → 1.0.5

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 (62) hide show
  1. package/dist/cjs/development/index.cjs +267 -267
  2. package/dist/cjs/development/index.cjs.map +3 -3
  3. package/dist/cjs/production/index.cjs +4 -4
  4. package/dist/esm/development/index.mjs +267 -267
  5. package/dist/esm/development/index.mjs.map +3 -3
  6. package/dist/esm/production/index.mjs +5 -5
  7. package/dist/types/core/Serializer.d.ts.map +1 -1
  8. package/dist/types/core/base-primitives.d.ts.map +1 -1
  9. package/dist/types/core/constants.d.ts +4 -4
  10. package/dist/types/core/constants.d.ts.map +1 -1
  11. package/dist/types/core/context/deserializer.d.ts +1 -1
  12. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  13. package/dist/types/core/context/parser/async.d.ts +1 -1
  14. package/dist/types/core/context/parser/async.d.ts.map +1 -1
  15. package/dist/types/core/context/parser/stream.d.ts +2 -2
  16. package/dist/types/core/context/parser/stream.d.ts.map +1 -1
  17. package/dist/types/core/context/parser/sync.d.ts +3 -3
  18. package/dist/types/core/context/parser/sync.d.ts.map +1 -1
  19. package/dist/types/core/context/parser.d.ts.map +1 -1
  20. package/dist/types/core/context/serializer.d.ts +1 -1
  21. package/dist/types/core/context/serializer.d.ts.map +1 -1
  22. package/dist/types/core/cross/async.d.ts +1 -1
  23. package/dist/types/core/cross/async.d.ts.map +1 -1
  24. package/dist/types/core/cross/deserializer.d.ts +1 -1
  25. package/dist/types/core/cross/deserializer.d.ts.map +1 -1
  26. package/dist/types/core/cross/serializer.d.ts +1 -1
  27. package/dist/types/core/cross/serializer.d.ts.map +1 -1
  28. package/dist/types/core/errors.d.ts +1 -1
  29. package/dist/types/core/errors.d.ts.map +1 -1
  30. package/dist/types/core/plugin.d.ts +1 -1
  31. package/dist/types/core/plugin.d.ts.map +1 -1
  32. package/dist/types/core/tree/async.d.ts +1 -1
  33. package/dist/types/core/tree/async.d.ts.map +1 -1
  34. package/dist/types/core/tree/deserializer.d.ts +1 -1
  35. package/dist/types/core/tree/deserializer.d.ts.map +1 -1
  36. package/dist/types/core/tree/index.d.ts.map +1 -1
  37. package/dist/types/core/tree/serializer.d.ts +1 -1
  38. package/dist/types/core/tree/serializer.d.ts.map +1 -1
  39. package/dist/types/core/types.d.ts +1 -1
  40. package/dist/types/core/types.d.ts.map +1 -1
  41. package/package.json +4 -5
  42. package/src/core/Serializer.ts +5 -5
  43. package/src/core/base-primitives.ts +4 -4
  44. package/src/core/constants.ts +12 -12
  45. package/src/core/context/deserializer.ts +20 -20
  46. package/src/core/context/parser/async.ts +27 -27
  47. package/src/core/context/parser/stream.ts +5 -5
  48. package/src/core/context/parser/sync.ts +16 -16
  49. package/src/core/context/parser.ts +3 -3
  50. package/src/core/context/serializer.ts +23 -23
  51. package/src/core/cross/async.ts +1 -1
  52. package/src/core/cross/deserializer.ts +1 -1
  53. package/src/core/cross/serializer.ts +2 -2
  54. package/src/core/errors.ts +5 -2
  55. package/src/core/literals.ts +4 -4
  56. package/src/core/plugin.ts +1 -1
  57. package/src/core/reference.ts +2 -2
  58. package/src/core/tree/async.ts +1 -1
  59. package/src/core/tree/deserializer.ts +1 -1
  60. package/src/core/tree/index.ts +8 -2
  61. package/src/core/tree/serializer.ts +5 -5
  62. package/src/core/types.ts +2 -2
@@ -9,13 +9,6 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
9
9
  })(Feature || {});
10
10
  var ALL_ENABLED = 31;
11
11
 
12
- // src/core/utils/assert.ts
13
- function assert(cond, error) {
14
- if (!cond) {
15
- throw error;
16
- }
17
- }
18
-
19
12
  // src/core/string.ts
20
13
  function serializeChar(str) {
21
14
  switch (str) {
@@ -107,6 +100,13 @@ function getCrossReferenceHeader(id) {
107
100
  )}"]=[]`;
108
101
  }
109
102
 
103
+ // src/core/utils/assert.ts
104
+ function assert(cond, error) {
105
+ if (!cond) {
106
+ throw error;
107
+ }
108
+ }
109
+
110
110
  // src/core/reference.ts
111
111
  var REFERENCE = /* @__PURE__ */ new Map();
112
112
  var INV_REFERENCE = /* @__PURE__ */ new Map();
@@ -234,20 +234,20 @@ var CONSTANT_STRING = {
234
234
  [3 /* False */]: "!1",
235
235
  [1 /* Undefined */]: "void 0",
236
236
  [0 /* Null */]: "null",
237
- [4 /* NegativeZero */]: "-0",
238
- [5 /* Infinity */]: "1/0",
239
- [6 /* NegativeInfinity */]: "-1/0",
240
- [7 /* NaN */]: "0/0"
237
+ [4 /* NegZero */]: "-0",
238
+ [5 /* Inf */]: "1/0",
239
+ [6 /* NegInf */]: "-1/0",
240
+ [7 /* Nan */]: "0/0"
241
241
  };
242
242
  var CONSTANT_VAL = {
243
243
  [2 /* True */]: true,
244
244
  [3 /* False */]: false,
245
245
  [1 /* Undefined */]: void 0,
246
246
  [0 /* Null */]: null,
247
- [4 /* NegativeZero */]: -0,
248
- [5 /* Infinity */]: Infinity,
249
- [6 /* NegativeInfinity */]: -Infinity,
250
- [7 /* NaN */]: NaN
247
+ [4 /* NegZero */]: -0,
248
+ [5 /* Inf */]: Number.POSITIVE_INFINITY,
249
+ [6 /* NegInf */]: Number.NEGATIVE_INFINITY,
250
+ [7 /* Nan */]: Number.NaN
251
251
  };
252
252
  var ERROR_CONSTRUCTOR_STRING = {
253
253
  [0 /* Error */]: "Error",
@@ -298,15 +298,15 @@ var NULL_NODE = /* @__PURE__ */ createConstantNode(
298
298
  0 /* Null */
299
299
  );
300
300
  var NEG_ZERO_NODE = /* @__PURE__ */ createConstantNode(
301
- 4 /* NegativeZero */
301
+ 4 /* NegZero */
302
302
  );
303
303
  var INFINITY_NODE = /* @__PURE__ */ createConstantNode(
304
- 5 /* Infinity */
304
+ 5 /* Inf */
305
305
  );
306
306
  var NEG_INFINITY_NODE = /* @__PURE__ */ createConstantNode(
307
- 6 /* NegativeInfinity */
307
+ 6 /* NegInf */
308
308
  );
309
- var NAN_NODE = /* @__PURE__ */ createConstantNode(7 /* NaN */);
309
+ var NAN_NODE = /* @__PURE__ */ createConstantNode(7 /* Nan */);
310
310
 
311
311
  // src/core/utils/error.ts
312
312
  function getErrorConstructor(error) {
@@ -377,9 +377,9 @@ function getObjectFlag(obj) {
377
377
  // src/core/base-primitives.ts
378
378
  function createNumberNode(value) {
379
379
  switch (value) {
380
- case Infinity:
380
+ case Number.POSITIVE_INFINITY:
381
381
  return INFINITY_NODE;
382
- case -Infinity:
382
+ case Number.NEGATIVE_INFINITY:
383
383
  return NEG_INFINITY_NODE;
384
384
  }
385
385
  if (value !== value) {
@@ -778,70 +778,6 @@ function createStreamReturnNode(id, parsed) {
778
778
  };
779
779
  }
780
780
 
781
- // src/core/utils/iterator-to-sequence.ts
782
- function iteratorToSequence(source) {
783
- const values = [];
784
- let throwsAt = -1;
785
- let doneAt = -1;
786
- const iterator = source[Symbol.iterator]();
787
- while (true) {
788
- try {
789
- const value = iterator.next();
790
- values.push(value.value);
791
- if (value.done) {
792
- doneAt = values.length - 1;
793
- break;
794
- }
795
- } catch (error) {
796
- throwsAt = values.length;
797
- values.push(error);
798
- }
799
- }
800
- return {
801
- v: values,
802
- t: throwsAt,
803
- d: doneAt
804
- };
805
- }
806
- function sequenceToIterator(sequence) {
807
- return () => {
808
- let index = 0;
809
- return {
810
- [Symbol.iterator]() {
811
- return this;
812
- },
813
- next() {
814
- if (index > sequence.d) {
815
- return {
816
- done: true,
817
- value: void 0
818
- };
819
- }
820
- const currentIndex = index++;
821
- const currentItem = sequence.v[currentIndex];
822
- if (currentIndex === sequence.t) {
823
- throw currentItem;
824
- }
825
- return {
826
- done: currentIndex === sequence.d,
827
- value: currentItem
828
- };
829
- }
830
- };
831
- };
832
- }
833
-
834
- // src/core/special-reference.ts
835
- var ITERATOR = {};
836
- var ASYNC_ITERATOR = {};
837
- var SPECIAL_REFS = {
838
- [0 /* MapSentinel */]: {},
839
- [1 /* PromiseConstructor */]: {},
840
- [2 /* PromiseResolve */]: {},
841
- [3 /* PromiseReject */]: {},
842
- [4 /* StreamConstructor */]: {}
843
- };
844
-
845
781
  // src/core/errors.ts
846
782
  var { toString: objectToString } = Object.prototype;
847
783
  function getErrorMessage(type, cause) {
@@ -927,190 +863,17 @@ var SerovalUnknownTypedArrayError = class extends Error {
927
863
  }
928
864
  };
929
865
 
930
- // src/core/context/parser.ts
931
- var BaseParserContext = class {
932
- constructor(options) {
933
- this.marked = /* @__PURE__ */ new Set();
934
- this.plugins = options.plugins;
935
- this.features = ALL_ENABLED ^ (options.disabledFeatures || 0);
936
- this.refs = options.refs || /* @__PURE__ */ new Map();
937
- }
938
- markRef(id) {
939
- this.marked.add(id);
940
- }
941
- isMarked(id) {
942
- return this.marked.has(id);
943
- }
944
- getIndexedValue(current) {
945
- const registeredId = this.refs.get(current);
946
- if (registeredId != null) {
947
- this.markRef(registeredId);
948
- return {
949
- type: 1 /* Indexed */,
950
- value: createIndexedValueNode(registeredId)
951
- };
952
- }
953
- const id = this.refs.size;
954
- this.refs.set(current, id);
955
- return {
956
- type: 0 /* Fresh */,
957
- value: id
958
- };
959
- }
960
- getReference(current) {
961
- const indexed = this.getIndexedValue(current);
962
- if (indexed.type === 1 /* Indexed */) {
963
- return indexed;
964
- }
965
- if (hasReferenceID(current)) {
966
- return {
967
- type: 2 /* Referenced */,
968
- value: createReferenceNode(indexed.value, current)
969
- };
970
- }
971
- return indexed;
972
- }
973
- getStrictReference(current) {
974
- assert(hasReferenceID(current), new SerovalUnsupportedTypeError(current));
975
- const result = this.getIndexedValue(current);
976
- if (result.type === 1 /* Indexed */) {
977
- return result.value;
978
- }
979
- return createReferenceNode(result.value, current);
980
- }
981
- parseFunction(current) {
982
- return this.getStrictReference(current);
983
- }
984
- parseWellKnownSymbol(current) {
985
- const ref = this.getReference(current);
986
- if (ref.type !== 0 /* Fresh */) {
987
- return ref.value;
988
- }
989
- assert(current in INV_SYMBOL_REF, new SerovalUnsupportedTypeError(current));
990
- return createWKSymbolNode(ref.value, current);
991
- }
992
- parseSpecialReference(ref) {
993
- const result = this.getIndexedValue(SPECIAL_REFS[ref]);
994
- if (result.type === 1 /* Indexed */) {
995
- return result.value;
996
- }
997
- return {
998
- t: 26 /* SpecialReference */,
999
- i: result.value,
1000
- s: ref,
1001
- l: void 0,
1002
- c: void 0,
1003
- m: void 0,
1004
- p: void 0,
1005
- e: void 0,
1006
- a: void 0,
1007
- f: void 0,
1008
- b: void 0,
1009
- o: void 0
1010
- };
1011
- }
1012
- parseIteratorFactory() {
1013
- const result = this.getIndexedValue(ITERATOR);
1014
- if (result.type === 1 /* Indexed */) {
1015
- return result.value;
1016
- }
1017
- return {
1018
- t: 27 /* IteratorFactory */,
1019
- i: result.value,
1020
- s: void 0,
1021
- l: void 0,
1022
- c: void 0,
1023
- m: void 0,
1024
- p: void 0,
1025
- e: void 0,
1026
- a: void 0,
1027
- f: this.parseWellKnownSymbol(Symbol.iterator),
1028
- b: void 0,
1029
- o: void 0
1030
- };
1031
- }
1032
- parseAsyncIteratorFactory() {
1033
- const result = this.getIndexedValue(ASYNC_ITERATOR);
1034
- if (result.type === 1 /* Indexed */) {
1035
- return result.value;
1036
- }
1037
- return {
1038
- t: 29 /* AsyncIteratorFactory */,
1039
- i: result.value,
1040
- s: void 0,
1041
- l: void 0,
1042
- c: void 0,
1043
- m: void 0,
1044
- p: void 0,
1045
- e: void 0,
1046
- a: [
1047
- this.parseSpecialReference(1 /* PromiseConstructor */),
1048
- this.parseWellKnownSymbol(Symbol.asyncIterator)
1049
- ],
1050
- f: void 0,
1051
- b: void 0,
1052
- o: void 0
1053
- };
1054
- }
1055
- createObjectNode(id, current, empty, record) {
1056
- return {
1057
- t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
1058
- i: id,
1059
- s: void 0,
1060
- l: void 0,
1061
- c: void 0,
1062
- m: void 0,
1063
- p: record,
1064
- e: void 0,
1065
- a: void 0,
1066
- f: void 0,
1067
- b: void 0,
1068
- o: getObjectFlag(current)
1069
- };
1070
- }
1071
- createMapNode(id, k, v, s) {
1072
- return {
1073
- t: 8 /* Map */,
1074
- i: id,
1075
- s: void 0,
1076
- l: void 0,
1077
- c: void 0,
1078
- m: void 0,
1079
- p: void 0,
1080
- e: { k, v, s },
1081
- a: void 0,
1082
- f: this.parseSpecialReference(0 /* MapSentinel */),
1083
- b: void 0,
1084
- o: void 0
1085
- };
1086
- }
1087
- createPromiseConstructorNode(id) {
1088
- return {
1089
- t: 22 /* PromiseConstructor */,
1090
- i: id,
1091
- s: void 0,
1092
- l: void 0,
1093
- c: void 0,
1094
- m: void 0,
1095
- p: void 0,
1096
- e: void 0,
1097
- a: void 0,
1098
- f: this.parseSpecialReference(1 /* PromiseConstructor */),
1099
- b: void 0,
1100
- o: void 0
1101
- };
1102
- }
866
+ // src/core/special-reference.ts
867
+ var ITERATOR = {};
868
+ var ASYNC_ITERATOR = {};
869
+ var SPECIAL_REFS = {
870
+ [0 /* MapSentinel */]: {},
871
+ [1 /* PromiseConstructor */]: {},
872
+ [2 /* PromiseResolve */]: {},
873
+ [3 /* PromiseReject */]: {},
874
+ [4 /* StreamConstructor */]: {}
1103
875
  };
1104
876
 
1105
- // src/core/utils/promise-to-result.ts
1106
- async function promiseToResult(current) {
1107
- try {
1108
- return [1, await current];
1109
- } catch (e) {
1110
- return [0, e];
1111
- }
1112
- }
1113
-
1114
877
  // src/core/utils/deferred.ts
1115
878
  function createDeferred() {
1116
879
  let resolve;
@@ -1297,6 +1060,243 @@ function streamToAsyncIterable(stream) {
1297
1060
  };
1298
1061
  }
1299
1062
 
1063
+ // src/core/utils/iterator-to-sequence.ts
1064
+ function iteratorToSequence(source) {
1065
+ const values = [];
1066
+ let throwsAt = -1;
1067
+ let doneAt = -1;
1068
+ const iterator = source[Symbol.iterator]();
1069
+ while (true) {
1070
+ try {
1071
+ const value = iterator.next();
1072
+ values.push(value.value);
1073
+ if (value.done) {
1074
+ doneAt = values.length - 1;
1075
+ break;
1076
+ }
1077
+ } catch (error) {
1078
+ throwsAt = values.length;
1079
+ values.push(error);
1080
+ }
1081
+ }
1082
+ return {
1083
+ v: values,
1084
+ t: throwsAt,
1085
+ d: doneAt
1086
+ };
1087
+ }
1088
+ function sequenceToIterator(sequence) {
1089
+ return () => {
1090
+ let index = 0;
1091
+ return {
1092
+ [Symbol.iterator]() {
1093
+ return this;
1094
+ },
1095
+ next() {
1096
+ if (index > sequence.d) {
1097
+ return {
1098
+ done: true,
1099
+ value: void 0
1100
+ };
1101
+ }
1102
+ const currentIndex = index++;
1103
+ const currentItem = sequence.v[currentIndex];
1104
+ if (currentIndex === sequence.t) {
1105
+ throw currentItem;
1106
+ }
1107
+ return {
1108
+ done: currentIndex === sequence.d,
1109
+ value: currentItem
1110
+ };
1111
+ }
1112
+ };
1113
+ };
1114
+ }
1115
+
1116
+ // src/core/utils/promise-to-result.ts
1117
+ async function promiseToResult(current) {
1118
+ try {
1119
+ return [1, await current];
1120
+ } catch (e) {
1121
+ return [0, e];
1122
+ }
1123
+ }
1124
+
1125
+ // src/core/context/parser.ts
1126
+ var BaseParserContext = class {
1127
+ constructor(options) {
1128
+ this.marked = /* @__PURE__ */ new Set();
1129
+ this.plugins = options.plugins;
1130
+ this.features = ALL_ENABLED ^ (options.disabledFeatures || 0);
1131
+ this.refs = options.refs || /* @__PURE__ */ new Map();
1132
+ }
1133
+ markRef(id) {
1134
+ this.marked.add(id);
1135
+ }
1136
+ isMarked(id) {
1137
+ return this.marked.has(id);
1138
+ }
1139
+ getIndexedValue(current) {
1140
+ const registeredId = this.refs.get(current);
1141
+ if (registeredId != null) {
1142
+ this.markRef(registeredId);
1143
+ return {
1144
+ type: 1 /* Indexed */,
1145
+ value: createIndexedValueNode(registeredId)
1146
+ };
1147
+ }
1148
+ const id = this.refs.size;
1149
+ this.refs.set(current, id);
1150
+ return {
1151
+ type: 0 /* Fresh */,
1152
+ value: id
1153
+ };
1154
+ }
1155
+ getReference(current) {
1156
+ const indexed = this.getIndexedValue(current);
1157
+ if (indexed.type === 1 /* Indexed */) {
1158
+ return indexed;
1159
+ }
1160
+ if (hasReferenceID(current)) {
1161
+ return {
1162
+ type: 2 /* Referenced */,
1163
+ value: createReferenceNode(indexed.value, current)
1164
+ };
1165
+ }
1166
+ return indexed;
1167
+ }
1168
+ getStrictReference(current) {
1169
+ assert(hasReferenceID(current), new SerovalUnsupportedTypeError(current));
1170
+ const result = this.getIndexedValue(current);
1171
+ if (result.type === 1 /* Indexed */) {
1172
+ return result.value;
1173
+ }
1174
+ return createReferenceNode(result.value, current);
1175
+ }
1176
+ parseFunction(current) {
1177
+ return this.getStrictReference(current);
1178
+ }
1179
+ parseWellKnownSymbol(current) {
1180
+ const ref = this.getReference(current);
1181
+ if (ref.type !== 0 /* Fresh */) {
1182
+ return ref.value;
1183
+ }
1184
+ assert(current in INV_SYMBOL_REF, new SerovalUnsupportedTypeError(current));
1185
+ return createWKSymbolNode(ref.value, current);
1186
+ }
1187
+ parseSpecialReference(ref) {
1188
+ const result = this.getIndexedValue(SPECIAL_REFS[ref]);
1189
+ if (result.type === 1 /* Indexed */) {
1190
+ return result.value;
1191
+ }
1192
+ return {
1193
+ t: 26 /* SpecialReference */,
1194
+ i: result.value,
1195
+ s: ref,
1196
+ l: void 0,
1197
+ c: void 0,
1198
+ m: void 0,
1199
+ p: void 0,
1200
+ e: void 0,
1201
+ a: void 0,
1202
+ f: void 0,
1203
+ b: void 0,
1204
+ o: void 0
1205
+ };
1206
+ }
1207
+ parseIteratorFactory() {
1208
+ const result = this.getIndexedValue(ITERATOR);
1209
+ if (result.type === 1 /* Indexed */) {
1210
+ return result.value;
1211
+ }
1212
+ return {
1213
+ t: 27 /* IteratorFactory */,
1214
+ i: result.value,
1215
+ s: void 0,
1216
+ l: void 0,
1217
+ c: void 0,
1218
+ m: void 0,
1219
+ p: void 0,
1220
+ e: void 0,
1221
+ a: void 0,
1222
+ f: this.parseWellKnownSymbol(Symbol.iterator),
1223
+ b: void 0,
1224
+ o: void 0
1225
+ };
1226
+ }
1227
+ parseAsyncIteratorFactory() {
1228
+ const result = this.getIndexedValue(ASYNC_ITERATOR);
1229
+ if (result.type === 1 /* Indexed */) {
1230
+ return result.value;
1231
+ }
1232
+ return {
1233
+ t: 29 /* AsyncIteratorFactory */,
1234
+ i: result.value,
1235
+ s: void 0,
1236
+ l: void 0,
1237
+ c: void 0,
1238
+ m: void 0,
1239
+ p: void 0,
1240
+ e: void 0,
1241
+ a: [
1242
+ this.parseSpecialReference(1 /* PromiseConstructor */),
1243
+ this.parseWellKnownSymbol(Symbol.asyncIterator)
1244
+ ],
1245
+ f: void 0,
1246
+ b: void 0,
1247
+ o: void 0
1248
+ };
1249
+ }
1250
+ createObjectNode(id, current, empty, record) {
1251
+ return {
1252
+ t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
1253
+ i: id,
1254
+ s: void 0,
1255
+ l: void 0,
1256
+ c: void 0,
1257
+ m: void 0,
1258
+ p: record,
1259
+ e: void 0,
1260
+ a: void 0,
1261
+ f: void 0,
1262
+ b: void 0,
1263
+ o: getObjectFlag(current)
1264
+ };
1265
+ }
1266
+ createMapNode(id, k, v, s) {
1267
+ return {
1268
+ t: 8 /* Map */,
1269
+ i: id,
1270
+ s: void 0,
1271
+ l: void 0,
1272
+ c: void 0,
1273
+ m: void 0,
1274
+ p: void 0,
1275
+ e: { k, v, s },
1276
+ a: void 0,
1277
+ f: this.parseSpecialReference(0 /* MapSentinel */),
1278
+ b: void 0,
1279
+ o: void 0
1280
+ };
1281
+ }
1282
+ createPromiseConstructorNode(id) {
1283
+ return {
1284
+ t: 22 /* PromiseConstructor */,
1285
+ i: id,
1286
+ s: void 0,
1287
+ l: void 0,
1288
+ c: void 0,
1289
+ m: void 0,
1290
+ p: void 0,
1291
+ e: void 0,
1292
+ a: void 0,
1293
+ f: this.parseSpecialReference(1 /* PromiseConstructor */),
1294
+ b: void 0,
1295
+ o: void 0
1296
+ };
1297
+ }
1298
+ };
1299
+
1300
1300
  // src/core/context/parser/async.ts
1301
1301
  var BaseAsyncParserContext = class extends BaseParserContext {
1302
1302
  async parseItems(current) {