seroval 1.3.2 → 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 (125) hide show
  1. package/dist/cjs/development/index.cjs +2817 -2700
  2. package/dist/cjs/development/index.cjs.map +4 -4
  3. package/dist/cjs/production/index.cjs +3 -17
  4. package/dist/esm/development/index.mjs +2817 -2700
  5. package/dist/esm/development/index.mjs.map +4 -4
  6. package/dist/esm/production/index.mjs +3 -17
  7. package/dist/types/core/base-primitives.d.ts +3 -4
  8. package/dist/types/core/base-primitives.d.ts.map +1 -1
  9. package/dist/types/core/compat.d.ts +3 -2
  10. package/dist/types/core/compat.d.ts.map +1 -1
  11. package/dist/types/core/constants.d.ts +2 -1
  12. package/dist/types/core/constants.d.ts.map +1 -1
  13. package/dist/types/core/constructors.d.ts +54 -0
  14. package/dist/types/core/constructors.d.ts.map +1 -0
  15. package/dist/types/core/context/async-parser.d.ts +20 -0
  16. package/dist/types/core/context/async-parser.d.ts.map +1 -0
  17. package/dist/types/core/context/deserializer.d.ts +40 -38
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser.d.ts +34 -19
  20. package/dist/types/core/context/parser.d.ts.map +1 -1
  21. package/dist/types/core/context/serializer.d.ts +38 -99
  22. package/dist/types/core/context/serializer.d.ts.map +1 -1
  23. package/dist/types/core/context/sync-parser.d.ts +59 -0
  24. package/dist/types/core/context/sync-parser.d.ts.map +1 -0
  25. package/dist/types/core/cross/index.d.ts +12 -13
  26. package/dist/types/core/cross/index.d.ts.map +1 -1
  27. package/dist/types/core/errors.d.ts +9 -0
  28. package/dist/types/core/errors.d.ts.map +1 -1
  29. package/dist/types/core/function-string.d.ts +2 -2
  30. package/dist/types/core/function-string.d.ts.map +1 -1
  31. package/dist/types/core/literals.d.ts.map +1 -1
  32. package/dist/types/core/node.d.ts +1 -1
  33. package/dist/types/core/node.d.ts.map +1 -1
  34. package/dist/types/core/plugin.d.ts +13 -11
  35. package/dist/types/core/plugin.d.ts.map +1 -1
  36. package/dist/types/core/reference.d.ts.map +1 -1
  37. package/dist/types/core/special-reference.d.ts +3 -2
  38. package/dist/types/core/special-reference.d.ts.map +1 -1
  39. package/dist/types/core/stream.d.ts +1 -2
  40. package/dist/types/core/stream.d.ts.map +1 -1
  41. package/dist/types/core/string.d.ts.map +1 -1
  42. package/dist/types/core/symbols.d.ts +14 -0
  43. package/dist/types/core/symbols.d.ts.map +1 -0
  44. package/dist/types/core/tree/index.d.ts +7 -3
  45. package/dist/types/core/tree/index.d.ts.map +1 -1
  46. package/dist/types/core/types.d.ts +4 -11
  47. package/dist/types/core/types.d.ts.map +1 -1
  48. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
  49. package/dist/types/index.d.ts +10 -5
  50. package/dist/types/index.d.ts.map +1 -1
  51. package/package.json +18 -21
  52. package/dist/types/core/context/parser/async.d.ts +0 -24
  53. package/dist/types/core/context/parser/async.d.ts.map +0 -1
  54. package/dist/types/core/context/parser/stream.d.ts +0 -43
  55. package/dist/types/core/context/parser/stream.d.ts.map +0 -1
  56. package/dist/types/core/context/parser/sync.d.ts +0 -30
  57. package/dist/types/core/context/parser/sync.d.ts.map +0 -1
  58. package/dist/types/core/cross/async.d.ts +0 -8
  59. package/dist/types/core/cross/async.d.ts.map +0 -1
  60. package/dist/types/core/cross/deserializer.d.ts +0 -9
  61. package/dist/types/core/cross/deserializer.d.ts.map +0 -1
  62. package/dist/types/core/cross/parser.d.ts +0 -6
  63. package/dist/types/core/cross/parser.d.ts.map +0 -1
  64. package/dist/types/core/cross/serializer.d.ts +0 -16
  65. package/dist/types/core/cross/serializer.d.ts.map +0 -1
  66. package/dist/types/core/cross/stream.d.ts +0 -8
  67. package/dist/types/core/cross/stream.d.ts.map +0 -1
  68. package/dist/types/core/cross/sync.d.ts +0 -8
  69. package/dist/types/core/cross/sync.d.ts.map +0 -1
  70. package/dist/types/core/tree/async.d.ts +0 -8
  71. package/dist/types/core/tree/async.d.ts.map +0 -1
  72. package/dist/types/core/tree/deserializer.d.ts +0 -13
  73. package/dist/types/core/tree/deserializer.d.ts.map +0 -1
  74. package/dist/types/core/tree/serializer.d.ts +0 -29
  75. package/dist/types/core/tree/serializer.d.ts.map +0 -1
  76. package/dist/types/core/tree/sync.d.ts +0 -8
  77. package/dist/types/core/tree/sync.d.ts.map +0 -1
  78. package/dist/types/core/utils/assert.d.ts +0 -2
  79. package/dist/types/core/utils/assert.d.ts.map +0 -1
  80. package/dist/types/core/utils/deferred.d.ts +0 -7
  81. package/dist/types/core/utils/deferred.d.ts.map +0 -1
  82. package/src/core/Serializer.ts +0 -119
  83. package/src/core/base-primitives.ts +0 -542
  84. package/src/core/compat.ts +0 -20
  85. package/src/core/constants.ts +0 -185
  86. package/src/core/context/deserializer.ts +0 -456
  87. package/src/core/context/parser/async.ts +0 -495
  88. package/src/core/context/parser/stream.ts +0 -323
  89. package/src/core/context/parser/sync.ts +0 -404
  90. package/src/core/context/parser.ts +0 -270
  91. package/src/core/context/serializer.ts +0 -1180
  92. package/src/core/cross/async.ts +0 -9
  93. package/src/core/cross/deserializer.ts +0 -16
  94. package/src/core/cross/index.ts +0 -170
  95. package/src/core/cross/parser.ts +0 -7
  96. package/src/core/cross/serializer.ts +0 -72
  97. package/src/core/cross/stream.ts +0 -9
  98. package/src/core/cross/sync.ts +0 -9
  99. package/src/core/errors.ts +0 -102
  100. package/src/core/function-string.ts +0 -31
  101. package/src/core/keys.ts +0 -17
  102. package/src/core/literals.ts +0 -43
  103. package/src/core/node.ts +0 -40
  104. package/src/core/opaque-reference.ts +0 -9
  105. package/src/core/plugin.ts +0 -91
  106. package/src/core/reference.ts +0 -63
  107. package/src/core/special-reference.ts +0 -114
  108. package/src/core/stream.ts +0 -205
  109. package/src/core/string.ts +0 -84
  110. package/src/core/tree/async.ts +0 -9
  111. package/src/core/tree/deserializer.ts +0 -26
  112. package/src/core/tree/index.ts +0 -111
  113. package/src/core/tree/serializer.ts +0 -98
  114. package/src/core/tree/sync.ts +0 -9
  115. package/src/core/types.ts +0 -370
  116. package/src/core/utils/assert.ts +0 -5
  117. package/src/core/utils/deferred.ts +0 -22
  118. package/src/core/utils/error.ts +0 -73
  119. package/src/core/utils/get-identifier.ts +0 -18
  120. package/src/core/utils/get-object-flag.ts +0 -14
  121. package/src/core/utils/is-valid-identifier.ts +0 -12
  122. package/src/core/utils/iterator-to-sequence.ts +0 -66
  123. package/src/core/utils/promise-to-result.ts +0 -9
  124. package/src/core/utils/typed-array.ts +0 -56
  125. package/src/index.ts +0 -18
@@ -1,9 +0,0 @@
1
- import BaseAsyncParserContext from '../context/parser/async';
2
- import type { SerovalMode } from '../plugin';
3
- import type { CrossParserContextOptions } from './parser';
4
-
5
- export type CrossAsyncParserContextOptions = CrossParserContextOptions;
6
-
7
- export default class CrossAsyncParserContext extends BaseAsyncParserContext {
8
- readonly mode: SerovalMode = 'cross';
9
- }
@@ -1,16 +0,0 @@
1
- import type { BaseDeserializerOptions } from '../context/deserializer';
2
- import BaseDeserializerContext from '../context/deserializer';
3
- import type { SerovalMode } from '../plugin';
4
-
5
- export type CrossDeserializerContextOptions = BaseDeserializerOptions;
6
-
7
- export default class CrossDeserializerContext extends BaseDeserializerContext {
8
- readonly mode: SerovalMode = 'cross';
9
-
10
- assignIndexedValue<T>(index: number, value: T): T {
11
- if (!this.refs.has(index)) {
12
- this.refs.set(index, value);
13
- }
14
- return value;
15
- }
16
- }
@@ -1,170 +0,0 @@
1
- import { resolvePlugins } from '../plugin';
2
- import type { SerovalNode } from '../types';
3
- import type { CrossAsyncParserContextOptions } from './async';
4
- import AsyncCrossParserContext from './async';
5
- import type { CrossDeserializerContextOptions } from './deserializer';
6
- import CrossDeserializerContext from './deserializer';
7
- import type { CrossContextOptions, CrossParserContextOptions } from './parser';
8
- import CrossSerializerContext from './serializer';
9
- import type { CrossStreamParserContextOptions } from './stream';
10
- import StreamCrossParserContext from './stream';
11
- import type { CrossSyncParserContextOptions } from './sync';
12
- import SyncCrossParserContext from './sync';
13
-
14
- export interface CrossSerializeOptions
15
- extends CrossSyncParserContextOptions,
16
- CrossContextOptions {}
17
-
18
- export function crossSerialize<T>(
19
- source: T,
20
- options: CrossSerializeOptions = {},
21
- ): string {
22
- const plugins = resolvePlugins(options.plugins);
23
- const ctx = new SyncCrossParserContext({
24
- plugins,
25
- disabledFeatures: options.disabledFeatures,
26
- refs: options.refs,
27
- });
28
- const tree = ctx.parseTop(source);
29
- const serial = new CrossSerializerContext({
30
- plugins,
31
- features: ctx.features,
32
- scopeId: options.scopeId,
33
- markedRefs: ctx.marked,
34
- });
35
- return serial.serializeTop(tree);
36
- }
37
-
38
- export interface CrossSerializeAsyncOptions
39
- extends CrossAsyncParserContextOptions,
40
- CrossContextOptions {}
41
-
42
- export async function crossSerializeAsync<T>(
43
- source: T,
44
- options: CrossSerializeAsyncOptions = {},
45
- ): Promise<string> {
46
- const plugins = resolvePlugins(options.plugins);
47
- const ctx = new AsyncCrossParserContext({
48
- plugins,
49
- disabledFeatures: options.disabledFeatures,
50
- refs: options.refs,
51
- });
52
- const tree = await ctx.parseTop(source);
53
- const serial = new CrossSerializerContext({
54
- plugins,
55
- features: ctx.features,
56
- scopeId: options.scopeId,
57
- markedRefs: ctx.marked,
58
- });
59
- return serial.serializeTop(tree);
60
- }
61
-
62
- export type ToCrossJSONOptions = CrossParserContextOptions;
63
-
64
- export function toCrossJSON<T>(
65
- source: T,
66
- options: CrossParserContextOptions = {},
67
- ): SerovalNode {
68
- const plugins = resolvePlugins(options.plugins);
69
- const ctx = new SyncCrossParserContext({
70
- plugins,
71
- disabledFeatures: options.disabledFeatures,
72
- refs: options.refs,
73
- });
74
- return ctx.parseTop(source);
75
- }
76
-
77
- export type ToCrossJSONAsyncOptions = CrossParserContextOptions;
78
-
79
- export async function toCrossJSONAsync<T>(
80
- source: T,
81
- options: CrossParserContextOptions = {},
82
- ): Promise<SerovalNode> {
83
- const plugins = resolvePlugins(options.plugins);
84
- const ctx = new AsyncCrossParserContext({
85
- plugins,
86
- disabledFeatures: options.disabledFeatures,
87
- refs: options.refs,
88
- });
89
- return await ctx.parseTop(source);
90
- }
91
-
92
- export interface CrossSerializeStreamOptions
93
- extends Omit<CrossStreamParserContextOptions, 'onParse'>,
94
- CrossContextOptions {
95
- onSerialize: (data: string, initial: boolean) => void;
96
- }
97
-
98
- export function crossSerializeStream<T>(
99
- source: T,
100
- options: CrossSerializeStreamOptions,
101
- ): () => void {
102
- const plugins = resolvePlugins(options.plugins);
103
- const ctx = new StreamCrossParserContext({
104
- plugins,
105
- refs: options.refs,
106
- disabledFeatures: options.disabledFeatures,
107
- onParse(node, initial): void {
108
- const serial = new CrossSerializerContext({
109
- plugins,
110
- features: ctx.features,
111
- scopeId: options.scopeId,
112
- markedRefs: ctx.marked,
113
- });
114
-
115
- let serialized: string;
116
-
117
- try {
118
- serialized = serial.serializeTop(node);
119
- } catch (err) {
120
- if (options.onError) {
121
- options.onError(err);
122
- }
123
- return;
124
- }
125
-
126
- options.onSerialize(serialized, initial);
127
- },
128
- onError: options.onError,
129
- onDone: options.onDone,
130
- });
131
-
132
- ctx.start(source);
133
-
134
- return ctx.destroy.bind(ctx);
135
- }
136
-
137
- export type ToCrossJSONStreamOptions = CrossStreamParserContextOptions;
138
-
139
- export function toCrossJSONStream<T>(
140
- source: T,
141
- options: ToCrossJSONStreamOptions,
142
- ): () => void {
143
- const plugins = resolvePlugins(options.plugins);
144
- const ctx = new StreamCrossParserContext({
145
- plugins,
146
- refs: options.refs,
147
- disabledFeatures: options.disabledFeatures,
148
- onParse: options.onParse,
149
- onError: options.onError,
150
- onDone: options.onDone,
151
- });
152
-
153
- ctx.start(source);
154
-
155
- return ctx.destroy.bind(ctx);
156
- }
157
-
158
- export type FromCrossJSONOptions = CrossDeserializerContextOptions;
159
-
160
- export function fromCrossJSON<T>(
161
- source: SerovalNode,
162
- options: FromCrossJSONOptions,
163
- ): T {
164
- const plugins = resolvePlugins(options.plugins);
165
- const ctx = new CrossDeserializerContext({
166
- plugins,
167
- refs: options.refs,
168
- });
169
- return ctx.deserializeTop(source) as T;
170
- }
@@ -1,7 +0,0 @@
1
- import type { BaseParserContextOptions } from '../context/parser';
2
-
3
- export type CrossParserContextOptions = BaseParserContextOptions;
4
-
5
- export interface CrossContextOptions {
6
- scopeId?: string;
7
- }
@@ -1,72 +0,0 @@
1
- import { SerovalNodeType } from '../constants';
2
- import type { BaseSerializerContextOptions } from '../context/serializer';
3
- import BaseSerializerContext from '../context/serializer';
4
- import { GLOBAL_CONTEXT_REFERENCES } from '../keys';
5
- import type { SerovalMode } from '../plugin';
6
- import { serializeString } from '../string';
7
- import type { SerovalNode } from '../types';
8
- import type { CrossContextOptions } from './parser';
9
-
10
- export interface CrossSerializerContextOptions
11
- extends BaseSerializerContextOptions,
12
- CrossContextOptions {}
13
-
14
- export default class CrossSerializerContext extends BaseSerializerContext {
15
- readonly mode: SerovalMode = 'cross';
16
-
17
- scopeId?: string;
18
-
19
- constructor(options: CrossSerializerContextOptions) {
20
- super(options);
21
- this.scopeId = options.scopeId;
22
- }
23
-
24
- getRefParam(id: number): string {
25
- return GLOBAL_CONTEXT_REFERENCES + '[' + id + ']';
26
- }
27
-
28
- protected assignIndexedValue(index: number, value: string): string {
29
- // In cross-reference, we have to assume that
30
- // every reference are going to be referenced
31
- // in the future, and so we need to store
32
- // all of it into the reference array.
33
- return this.getRefParam(index) + '=' + value;
34
- }
35
-
36
- serializeTop(tree: SerovalNode): string {
37
- // Get the serialized result
38
- const result = this.serialize(tree);
39
- // If the node is a non-reference, return
40
- // the result immediately
41
- const id = tree.i;
42
- if (id == null) {
43
- return result;
44
- }
45
- // Get the patches
46
- const patches = this.resolvePatches();
47
- // Get the variable that represents the root
48
- const ref = this.getRefParam(id);
49
- // Parameters needed for scoping
50
- const params = this.scopeId == null ? '' : GLOBAL_CONTEXT_REFERENCES;
51
- // If there are patches, append it after the result
52
- const body = patches ? '(' + result + ',' + patches + ref + ')' : result;
53
- // If there are no params, there's no need to generate a function
54
- if (params === '') {
55
- if (tree.t === SerovalNodeType.Object && !patches) {
56
- return '(' + body + ')';
57
- }
58
- return body;
59
- }
60
- // Get the arguments for the IIFE
61
- const args =
62
- this.scopeId == null
63
- ? '()'
64
- : '(' +
65
- GLOBAL_CONTEXT_REFERENCES +
66
- '["' +
67
- serializeString(this.scopeId) +
68
- '"])';
69
- // Create the IIFE
70
- return '(' + this.createFunction([params], body) + ')' + args;
71
- }
72
- }
@@ -1,9 +0,0 @@
1
- import type { BaseStreamParserContextOptions } from '../context/parser/stream';
2
- import BaseStreamParserContext from '../context/parser/stream';
3
- import type { SerovalMode } from '../plugin';
4
-
5
- export type CrossStreamParserContextOptions = BaseStreamParserContextOptions;
6
-
7
- export default class CrossStreamParserContext extends BaseStreamParserContext {
8
- readonly mode: SerovalMode = 'cross';
9
- }
@@ -1,9 +0,0 @@
1
- import BaseSyncParserContext from '../context/parser/sync';
2
- import type { SerovalMode } from '../plugin';
3
- import type { CrossParserContextOptions } from './parser';
4
-
5
- export type CrossSyncParserContextOptions = CrossParserContextOptions;
6
-
7
- export default class CrossSyncParserContext extends BaseSyncParserContext {
8
- readonly mode: SerovalMode = 'cross';
9
- }
@@ -1,102 +0,0 @@
1
- import { serializeString } from './string';
2
- import type { SerovalNode } from './types';
3
-
4
- const { toString: objectToString } = /* @__PURE__ */ Object.prototype;
5
-
6
- function getErrorMessage(type: string, cause: any): string {
7
- if (cause instanceof Error) {
8
- return `Seroval caught an error during the ${type} process.
9
-
10
- ${cause.name}
11
- ${cause.message}
12
-
13
- - For more information, please check the "cause" property of this error.
14
- - If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new`;
15
- }
16
- return `Seroval caught an error during the ${type} process.
17
-
18
- "${objectToString.call(cause)}"
19
-
20
- For more information, please check the "cause" property of this error.`;
21
- }
22
-
23
- export class SerovalError extends Error {
24
- constructor(
25
- type: string,
26
- public cause: any,
27
- ) {
28
- super(getErrorMessage(type, cause));
29
- }
30
- }
31
-
32
- export class SerovalParserError extends SerovalError {
33
- constructor(cause: any) {
34
- super('parsing', cause);
35
- }
36
- }
37
-
38
- export class SerovalSerializationError extends SerovalError {
39
- constructor(cause: any) {
40
- super('serialization', cause);
41
- }
42
- }
43
-
44
- export class SerovalDeserializationError extends SerovalError {
45
- constructor(cause: any) {
46
- super('deserialization', cause);
47
- }
48
- }
49
-
50
- export class SerovalUnsupportedTypeError extends Error {
51
- constructor(public value: unknown) {
52
- super(
53
- `The value ${objectToString.call(value)} of type "${typeof value}" cannot be parsed/serialized.
54
-
55
- There are few workarounds for this problem:
56
- - Transform the value in a way that it can be serialized.
57
- - If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.`,
58
- );
59
- }
60
- }
61
-
62
- export class SerovalUnsupportedNodeError extends Error {
63
- constructor(node: SerovalNode) {
64
- super('Unsupported node type "' + node.t + '".');
65
- }
66
- }
67
-
68
- export class SerovalMissingPluginError extends Error {
69
- constructor(tag: string) {
70
- super('Missing plugin for tag "' + tag + '".');
71
- }
72
- }
73
-
74
- export class SerovalMissingInstanceError extends Error {
75
- constructor(tag: string) {
76
- super('Missing "' + tag + '" instance.');
77
- }
78
- }
79
-
80
- export class SerovalMissingReferenceError extends Error {
81
- constructor(public value: unknown) {
82
- super(
83
- 'Missing reference for the value "' +
84
- objectToString.call(value) +
85
- '" of type "' +
86
- typeof value +
87
- '"',
88
- );
89
- }
90
- }
91
-
92
- export class SerovalMissingReferenceForIdError extends Error {
93
- constructor(id: string) {
94
- super('Missing reference for id "' + serializeString(id) + '"');
95
- }
96
- }
97
-
98
- export class SerovalUnknownTypedArrayError extends Error {
99
- constructor(name: string) {
100
- super('Unknown TypedArray "' + name + '"');
101
- }
102
- }
@@ -1,31 +0,0 @@
1
- import { Feature } from './compat';
2
-
3
- export function createFunction(
4
- features: number,
5
- parameters: string[],
6
- body: string,
7
- ): string {
8
- if (features & Feature.ArrowFunction) {
9
- const joined =
10
- parameters.length === 1
11
- ? parameters[0]
12
- : '(' + parameters.join(',') + ')';
13
- return joined + '=>' + (body.startsWith('{') ? '(' + body + ')' : body);
14
- }
15
- return 'function(' + parameters.join(',') + '){return ' + body + '}';
16
- }
17
-
18
- export function createEffectfulFunction(
19
- features: number,
20
- parameters: string[],
21
- body: string,
22
- ): string {
23
- if (features & Feature.ArrowFunction) {
24
- const joined =
25
- parameters.length === 1
26
- ? parameters[0]
27
- : '(' + parameters.join(',') + ')';
28
- return joined + '=>{' + body + '}';
29
- }
30
- return 'function(' + parameters.join(',') + '){' + body + '}';
31
- }
package/src/core/keys.ts DELETED
@@ -1,17 +0,0 @@
1
- import { serializeString } from './string';
2
-
3
- // Used for mapping isomorphic references
4
- export const REFERENCES_KEY = '__SEROVAL_REFS__';
5
-
6
- export const GLOBAL_CONTEXT_REFERENCES = '$R';
7
-
8
- const GLOBAL_CONTEXT_R = `self.${GLOBAL_CONTEXT_REFERENCES}`;
9
-
10
- export function getCrossReferenceHeader(id?: string): string {
11
- if (id == null) {
12
- return `${GLOBAL_CONTEXT_R}=${GLOBAL_CONTEXT_R}||[]`;
13
- }
14
- return `(${GLOBAL_CONTEXT_R}=${GLOBAL_CONTEXT_R}||{})["${serializeString(
15
- id,
16
- )}"]=[]`;
17
- }
@@ -1,43 +0,0 @@
1
- import { NIL, SerovalConstant, SerovalNodeType } from './constants';
2
- import { createSerovalNode } from './node';
3
- import type { SerovalConstantNode } from './types';
4
-
5
- function createConstantNode(value: SerovalConstant): SerovalConstantNode {
6
- return createSerovalNode(
7
- SerovalNodeType.Constant,
8
- NIL,
9
- value,
10
- NIL,
11
- NIL,
12
- NIL,
13
- NIL,
14
- NIL,
15
- NIL,
16
- NIL,
17
- NIL,
18
- NIL,
19
- );
20
- }
21
-
22
- export const TRUE_NODE = /* @__PURE__ */ createConstantNode(
23
- SerovalConstant.True,
24
- );
25
- export const FALSE_NODE = /* @__PURE__ */ createConstantNode(
26
- SerovalConstant.False,
27
- );
28
- export const UNDEFINED_NODE = /* @__PURE__ */ createConstantNode(
29
- SerovalConstant.Undefined,
30
- );
31
- export const NULL_NODE = /* @__PURE__ */ createConstantNode(
32
- SerovalConstant.Null,
33
- );
34
- export const NEG_ZERO_NODE = /* @__PURE__ */ createConstantNode(
35
- SerovalConstant.NegZero,
36
- );
37
- export const INFINITY_NODE = /* @__PURE__ */ createConstantNode(
38
- SerovalConstant.Inf,
39
- );
40
- export const NEG_INFINITY_NODE = /* @__PURE__ */ createConstantNode(
41
- SerovalConstant.NegInf,
42
- );
43
- export const NAN_NODE = /* @__PURE__ */ createConstantNode(SerovalConstant.Nan);
package/src/core/node.ts DELETED
@@ -1,40 +0,0 @@
1
- import type { SerovalNodeType } from './constants';
2
- import type { SerovalNode } from './types';
3
-
4
- type ExtractedNodeType<T extends SerovalNodeType> = Extract<
5
- SerovalNode,
6
- { t: T }
7
- >;
8
-
9
- export function createSerovalNode<
10
- T extends SerovalNodeType,
11
- N extends ExtractedNodeType<T>,
12
- >(
13
- t: T,
14
- i: N['i'],
15
- s: N['s'],
16
- l: N['l'],
17
- c: N['c'],
18
- m: N['m'],
19
- p: N['p'],
20
- e: N['e'],
21
- a: N['a'],
22
- f: N['f'],
23
- b: N['b'],
24
- o: N['o'],
25
- ): N {
26
- return {
27
- t,
28
- i,
29
- s,
30
- l,
31
- c,
32
- m,
33
- p,
34
- e,
35
- a,
36
- f,
37
- b,
38
- o,
39
- } as N;
40
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * An opaque reference allows hiding values from the serializer.
3
- */
4
- export class OpaqueReference<V, R = undefined> {
5
- constructor(
6
- public readonly value: V,
7
- public readonly replacement?: R,
8
- ) {}
9
- }
@@ -1,91 +0,0 @@
1
- import type BaseDeserializerContext from './context/deserializer';
2
- import type BaseAsyncParserContext from './context/parser/async';
3
- import type BaseStreamParserContext from './context/parser/stream';
4
- import type BaseSyncParserContext from './context/parser/sync';
5
- import type BaseSerializerContext from './context/serializer';
6
-
7
- export type SerovalMode = 'vanilla' | 'cross';
8
-
9
- export interface PluginData {
10
- id: number;
11
- }
12
-
13
- export interface Plugin<Value, Node> {
14
- /**
15
- * A unique string that helps idenfity the plugin
16
- */
17
- tag: string;
18
- /**
19
- * List of dependency plugins
20
- */
21
- extends?: Plugin<any, any>[];
22
- /**
23
- * Method to test if a value is an expected value of the plugin
24
- * @param value
25
- */
26
- test(value: unknown): boolean;
27
- /**
28
- * Parsing modes
29
- */
30
- parse: {
31
- sync?: (value: Value, ctx: BaseSyncParserContext, data: PluginData) => Node;
32
- async?: (
33
- value: Value,
34
- ctx: BaseAsyncParserContext,
35
- data: PluginData,
36
- ) => Promise<Node>;
37
- stream?: (
38
- value: Value,
39
- ctx: BaseStreamParserContext,
40
- data: PluginData,
41
- ) => Node;
42
- };
43
- /**
44
- * Convert the parsed node into a JS string
45
- */
46
- serialize(node: Node, ctx: BaseSerializerContext, data: PluginData): string;
47
- /**
48
- * Convert the parsed node into its runtime equivalent.
49
- */
50
- deserialize(
51
- node: Node,
52
- ctx: BaseDeserializerContext,
53
- data: PluginData,
54
- ): Value;
55
- }
56
-
57
- export function createPlugin<Value, Node>(
58
- plugin: Plugin<Value, Node>,
59
- ): Plugin<Value, Node> {
60
- return plugin;
61
- }
62
-
63
- export interface PluginAccessOptions {
64
- plugins?: Plugin<any, any>[];
65
- }
66
-
67
- function dedupePlugins(
68
- deduped: Set<Plugin<any, any>>,
69
- plugins: Plugin<any, any>[],
70
- ): void {
71
- for (let i = 0, len = plugins.length; i < len; i++) {
72
- const current = plugins[i];
73
- if (!deduped.has(current)) {
74
- deduped.add(current);
75
- if (current.extends) {
76
- dedupePlugins(deduped, current.extends);
77
- }
78
- }
79
- }
80
- }
81
-
82
- export function resolvePlugins(
83
- plugins?: Plugin<any, any>[],
84
- ): Plugin<any, any>[] | undefined {
85
- if (plugins) {
86
- const deduped = new Set<Plugin<any, any>>();
87
- dedupePlugins(deduped, plugins);
88
- return [...deduped];
89
- }
90
- return undefined;
91
- }