seroval 1.4.0 → 1.4.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 (68) hide show
  1. package/dist/cjs/development/index.cjs +524 -364
  2. package/dist/cjs/development/index.cjs.map +3 -3
  3. package/dist/cjs/production/index.cjs +3 -3
  4. package/dist/esm/development/index.mjs +524 -364
  5. package/dist/esm/development/index.mjs.map +3 -3
  6. package/dist/esm/production/index.mjs +3 -3
  7. package/dist/types/core/base-primitives.d.ts +2 -2
  8. package/dist/types/core/base-primitives.d.ts.map +1 -1
  9. package/dist/types/core/compat.d.ts +2 -1
  10. package/dist/types/core/compat.d.ts.map +1 -1
  11. package/dist/types/core/constants.d.ts +2 -2
  12. package/dist/types/core/constants.d.ts.map +1 -1
  13. package/dist/types/core/constructors.d.ts +1 -1
  14. package/dist/types/core/constructors.d.ts.map +1 -1
  15. package/dist/types/core/context/async-parser.d.ts +5 -4
  16. package/dist/types/core/context/async-parser.d.ts.map +1 -1
  17. package/dist/types/core/context/deserializer.d.ts +7 -2
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser.d.ts +3 -1
  20. package/dist/types/core/context/parser.d.ts.map +1 -1
  21. package/dist/types/core/context/serializer.d.ts.map +1 -1
  22. package/dist/types/core/context/sync-parser.d.ts +5 -5
  23. package/dist/types/core/context/sync-parser.d.ts.map +1 -1
  24. package/dist/types/core/cross/index.d.ts.map +1 -1
  25. package/dist/types/core/errors.d.ts +9 -0
  26. package/dist/types/core/errors.d.ts.map +1 -1
  27. package/dist/types/core/literals.d.ts.map +1 -1
  28. package/dist/types/core/node.d.ts +1 -1
  29. package/dist/types/core/node.d.ts.map +1 -1
  30. package/dist/types/core/string.d.ts.map +1 -1
  31. package/dist/types/core/tree/index.d.ts +4 -1
  32. package/dist/types/core/tree/index.d.ts.map +1 -1
  33. package/dist/types/core/types.d.ts +2 -11
  34. package/dist/types/core/types.d.ts.map +1 -1
  35. package/package.json +2 -3
  36. package/src/core/Serializer.ts +0 -119
  37. package/src/core/base-primitives.ts +0 -515
  38. package/src/core/compat.ts +0 -21
  39. package/src/core/constants.ts +0 -187
  40. package/src/core/constructors.ts +0 -269
  41. package/src/core/context/async-parser.ts +0 -586
  42. package/src/core/context/deserializer.ts +0 -646
  43. package/src/core/context/parser.ts +0 -333
  44. package/src/core/context/serializer.ts +0 -1411
  45. package/src/core/context/sync-parser.ts +0 -833
  46. package/src/core/cross/index.ts +0 -186
  47. package/src/core/errors.ts +0 -163
  48. package/src/core/function-string.ts +0 -32
  49. package/src/core/keys.ts +0 -17
  50. package/src/core/literals.ts +0 -43
  51. package/src/core/node.ts +0 -40
  52. package/src/core/opaque-reference.ts +0 -9
  53. package/src/core/plugin.ts +0 -100
  54. package/src/core/reference.ts +0 -66
  55. package/src/core/special-reference.ts +0 -42
  56. package/src/core/stream.ts +0 -71
  57. package/src/core/string.ts +0 -84
  58. package/src/core/symbols.ts +0 -18
  59. package/src/core/tree/index.ts +0 -125
  60. package/src/core/types.ts +0 -375
  61. package/src/core/utils/error.ts +0 -73
  62. package/src/core/utils/get-identifier.ts +0 -18
  63. package/src/core/utils/get-object-flag.ts +0 -14
  64. package/src/core/utils/is-valid-identifier.ts +0 -12
  65. package/src/core/utils/iterator-to-sequence.ts +0 -44
  66. package/src/core/utils/promise-to-result.ts +0 -9
  67. package/src/core/utils/typed-array.ts +0 -56
  68. package/src/index.ts +0 -36
@@ -1,73 +0,0 @@
1
- import { Feature } from '../compat';
2
- import { ERROR_CONSTRUCTOR_STRING, ErrorConstructorTag } from '../constants';
3
-
4
- type ErrorValue =
5
- | Error
6
- | AggregateError
7
- | EvalError
8
- | RangeError
9
- | ReferenceError
10
- | TypeError
11
- | SyntaxError
12
- | URIError;
13
-
14
- export function getErrorConstructor(error: ErrorValue): ErrorConstructorTag {
15
- if (error instanceof EvalError) {
16
- return ErrorConstructorTag.EvalError;
17
- }
18
- if (error instanceof RangeError) {
19
- return ErrorConstructorTag.RangeError;
20
- }
21
- if (error instanceof ReferenceError) {
22
- return ErrorConstructorTag.ReferenceError;
23
- }
24
- if (error instanceof SyntaxError) {
25
- return ErrorConstructorTag.SyntaxError;
26
- }
27
- if (error instanceof TypeError) {
28
- return ErrorConstructorTag.TypeError;
29
- }
30
- if (error instanceof URIError) {
31
- return ErrorConstructorTag.URIError;
32
- }
33
- return ErrorConstructorTag.Error;
34
- }
35
-
36
- function getInitialErrorOptions(
37
- error: Error,
38
- ): Record<string, unknown> | undefined {
39
- const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
40
- // Name has been modified
41
- if (error.name !== construct) {
42
- return { name: error.name };
43
- }
44
- if (error.constructor.name !== construct) {
45
- // Otherwise, name is overriden because
46
- // the Error class is extended
47
- return { name: error.constructor.name };
48
- }
49
- return {};
50
- }
51
-
52
- export function getErrorOptions(
53
- error: Error,
54
- features: number,
55
- ): Record<string, unknown> | undefined {
56
- let options = getInitialErrorOptions(error);
57
- const names = Object.getOwnPropertyNames(error);
58
- for (let i = 0, len = names.length, name: string; i < len; i++) {
59
- name = names[i];
60
- if (name !== 'name' && name !== 'message') {
61
- if (name === 'stack') {
62
- if (features & Feature.ErrorPrototypeStack) {
63
- options = options || {};
64
- options[name] = error[name as keyof Error];
65
- }
66
- } else {
67
- options = options || {};
68
- options[name] = error[name as keyof Error];
69
- }
70
- }
71
- }
72
- return options;
73
- }
@@ -1,18 +0,0 @@
1
- // Written by https://github.com/DylanPiercey and is distributed under the MIT license.
2
- const REF_START_CHARS = /* @__PURE__ */ 'hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_'; // Avoids chars that could evaluate to a reserved word.
3
- const REF_START_CHARS_LEN = /* @__PURE__ */ REF_START_CHARS.length;
4
- const REF_CHARS =
5
- /* @__PURE__ */ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_';
6
- const REF_CHARS_LEN = /* @__PURE__ */ REF_CHARS.length;
7
-
8
- export default function getIdentifier(index: number): string {
9
- let mod = index % REF_START_CHARS_LEN;
10
- let ref = REF_START_CHARS[mod];
11
- index = (index - mod) / REF_START_CHARS_LEN;
12
- while (index > 0) {
13
- mod = index % REF_CHARS_LEN;
14
- ref += REF_CHARS[mod];
15
- index = (index - mod) / REF_CHARS_LEN;
16
- }
17
- return ref;
18
- }
@@ -1,14 +0,0 @@
1
- import { SerovalObjectFlags } from '../constants';
2
-
3
- export function getObjectFlag(obj: unknown): SerovalObjectFlags {
4
- if (Object.isFrozen(obj)) {
5
- return SerovalObjectFlags.Frozen;
6
- }
7
- if (Object.isSealed(obj)) {
8
- return SerovalObjectFlags.Sealed;
9
- }
10
- if (Object.isExtensible(obj)) {
11
- return SerovalObjectFlags.None;
12
- }
13
- return SerovalObjectFlags.NonExtensible;
14
- }
@@ -1,12 +0,0 @@
1
- const IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
2
-
3
- export function isValidIdentifier(name: string): boolean {
4
- const char = name[0];
5
- return (
6
- (char === '$' ||
7
- char === '_' ||
8
- (char >= 'A' && char <= 'Z') ||
9
- (char >= 'a' && char <= 'z')) &&
10
- IDENTIFIER_CHECK.test(name)
11
- );
12
- }
@@ -1,44 +0,0 @@
1
- import { ITERATOR_CONSTRUCTOR } from '../constructors';
2
- import { SYM_ITERATOR } from '../symbols';
3
-
4
- export interface Sequence {
5
- v: unknown[];
6
- t: number;
7
- d: number;
8
- }
9
-
10
- export function iteratorToSequence<T>(source: Iterable<T>): Sequence {
11
- const values: unknown[] = [];
12
- let throwsAt = -1;
13
- let doneAt = -1;
14
-
15
- const iterator = source[SYM_ITERATOR]();
16
-
17
- while (true) {
18
- try {
19
- const value = iterator.next();
20
- values.push(value.value);
21
- if (value.done) {
22
- doneAt = values.length - 1;
23
- break;
24
- }
25
- } catch (error) {
26
- throwsAt = values.length;
27
- values.push(error);
28
- }
29
- }
30
-
31
- return {
32
- v: values,
33
- t: throwsAt,
34
- d: doneAt,
35
- };
36
- }
37
-
38
- const createIterator = ITERATOR_CONSTRUCTOR(SYM_ITERATOR);
39
-
40
- export function sequenceToIterator<T>(
41
- sequence: Sequence,
42
- ): () => IterableIterator<T> {
43
- return createIterator(sequence) as unknown as () => IterableIterator<T>;
44
- }
@@ -1,9 +0,0 @@
1
- export default async function promiseToResult(
2
- current: Promise<unknown>,
3
- ): Promise<[0 | 1, unknown]> {
4
- try {
5
- return [1, await current];
6
- } catch (e) {
7
- return [0, e];
8
- }
9
- }
@@ -1,56 +0,0 @@
1
- import { SerovalUnknownTypedArrayError } from '../errors';
2
-
3
- type TypedArrayConstructor =
4
- | Int8ArrayConstructor
5
- | Int16ArrayConstructor
6
- | Int32ArrayConstructor
7
- | Uint8ArrayConstructor
8
- | Uint16ArrayConstructor
9
- | Uint32ArrayConstructor
10
- | Uint8ClampedArrayConstructor
11
- | Float32ArrayConstructor
12
- | Float64ArrayConstructor
13
- | BigInt64ArrayConstructor
14
- | BigUint64ArrayConstructor;
15
-
16
- export type TypedArrayValue =
17
- | Int8Array
18
- | Int16Array
19
- | Int32Array
20
- | Uint8Array
21
- | Uint16Array
22
- | Uint32Array
23
- | Uint8ClampedArray
24
- | Float32Array
25
- | Float64Array;
26
-
27
- export type BigIntTypedArrayValue = BigInt64Array | BigUint64Array;
28
-
29
- export function getTypedArrayConstructor(name: string): TypedArrayConstructor {
30
- switch (name) {
31
- case 'Int8Array':
32
- return Int8Array;
33
- case 'Int16Array':
34
- return Int16Array;
35
- case 'Int32Array':
36
- return Int32Array;
37
- case 'Uint8Array':
38
- return Uint8Array;
39
- case 'Uint16Array':
40
- return Uint16Array;
41
- case 'Uint32Array':
42
- return Uint32Array;
43
- case 'Uint8ClampedArray':
44
- return Uint8ClampedArray;
45
- case 'Float32Array':
46
- return Float32Array;
47
- case 'Float64Array':
48
- return Float64Array;
49
- case 'BigInt64Array':
50
- return BigInt64Array;
51
- case 'BigUint64Array':
52
- return BigUint64Array;
53
- default:
54
- throw new SerovalUnknownTypedArrayError(name);
55
- }
56
- }
package/src/index.ts DELETED
@@ -1,36 +0,0 @@
1
- export { Feature } from './core/compat';
2
- export type {
3
- AsyncParsePluginContext,
4
- AsyncParserContextOptions,
5
- } from './core/context/async-parser';
6
- export type {
7
- BaseDeserializerContextOptions,
8
- CrossDeserializerContextOptions,
9
- DeserializePluginContext,
10
- VanillaDeserializerContextOptions,
11
- } from './core/context/deserializer';
12
- export type { BaseParserContextOptions } from './core/context/parser';
13
- export type {
14
- BaseSerializerContextOptions,
15
- CrossContextOptions,
16
- CrossSerializerContextOptions,
17
- SerializePluginContext,
18
- VanillaSerializerContextOptions,
19
- } from './core/context/serializer';
20
- export type {
21
- StreamParsePluginContext,
22
- StreamParserContextOptions,
23
- SyncParsePluginContext,
24
- SyncParserContextOptions,
25
- } from './core/context/sync-parser';
26
- export * from './core/cross';
27
- export * from './core/errors';
28
- export { getCrossReferenceHeader } from './core/keys';
29
- export { OpaqueReference } from './core/opaque-reference';
30
- export * from './core/plugin';
31
- export { createReference } from './core/reference';
32
- export { default as Serializer } from './core/Serializer';
33
- export { createStream } from './core/stream';
34
- export type { Stream, StreamListener } from './core/stream';
35
- export * from './core/tree';
36
- export type { SerovalNode } from './core/types';