seroval 0.4.0-alpha.7 → 0.4.0-alpha.8
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.
- package/dist/cjs/development/index.cjs +14 -13
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +14 -13
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/context.d.ts +5 -4
- package/package.json +2 -2
- package/src/context.ts +16 -14
- package/src/index.ts +3 -3
- package/src/tree/serialize.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seroval",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.0-alpha.
|
|
4
|
+
"version": "0.4.0-alpha.8",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"src"
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"typesVersions": {
|
|
65
65
|
"*": {}
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "e965d1992af3e9a86a8919de6204fe4edb7b21a2"
|
|
68
68
|
}
|
package/src/context.ts
CHANGED
|
@@ -28,16 +28,17 @@ export type Assignment =
|
|
|
28
28
|
|
|
29
29
|
export interface ParserContext {
|
|
30
30
|
refs: Map<unknown, number>;
|
|
31
|
-
markedRefs:
|
|
31
|
+
markedRefs: Record<number, number>;
|
|
32
32
|
features: number;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export interface SerializationContext {
|
|
36
36
|
stack: number[];
|
|
37
37
|
// Map tree refs to actual refs
|
|
38
|
-
validRefs:
|
|
38
|
+
validRefs: number[];
|
|
39
|
+
refSize: number;
|
|
39
40
|
// Refs that are...referenced
|
|
40
|
-
markedRefs:
|
|
41
|
+
markedRefs: Record<number, number>;
|
|
41
42
|
// Variables
|
|
42
43
|
vars: string[];
|
|
43
44
|
// Array of assignments to be done (used for recursion)
|
|
@@ -58,14 +59,14 @@ export function createParserContext(options: Partial<Options> = {}): ParserConte
|
|
|
58
59
|
// eslint-disable-next-line prefer-object-spread
|
|
59
60
|
const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
|
|
60
61
|
return {
|
|
61
|
-
markedRefs:
|
|
62
|
+
markedRefs: {},
|
|
62
63
|
refs: new Map(),
|
|
63
64
|
features: parseTargets(result.target),
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
export interface SerializationOptions {
|
|
68
|
-
markedRefs: number
|
|
69
|
+
markedRefs: Record<number, number>;
|
|
69
70
|
features: number;
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -74,9 +75,10 @@ export function createSerializationContext(options: SerializationOptions): Seria
|
|
|
74
75
|
stack: [],
|
|
75
76
|
vars: [],
|
|
76
77
|
assignments: [],
|
|
77
|
-
validRefs:
|
|
78
|
+
validRefs: [],
|
|
79
|
+
refSize: 0,
|
|
78
80
|
features: options.features,
|
|
79
|
-
markedRefs:
|
|
81
|
+
markedRefs: options.markedRefs,
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
@@ -84,7 +86,7 @@ export function createSerializationContext(options: SerializationOptions): Seria
|
|
|
84
86
|
* Increments the number of references the referenced value has
|
|
85
87
|
*/
|
|
86
88
|
export function markRef(ctx: ParserContext | SerializationContext, current: number) {
|
|
87
|
-
ctx.markedRefs
|
|
89
|
+
ctx.markedRefs[current] = 1;
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
/**
|
|
@@ -97,13 +99,13 @@ function createValidRef(
|
|
|
97
99
|
ctx: SerializationContext,
|
|
98
100
|
index: number,
|
|
99
101
|
) {
|
|
100
|
-
const current = ctx.validRefs
|
|
101
|
-
if (current
|
|
102
|
-
|
|
102
|
+
const current = ctx.validRefs[index];
|
|
103
|
+
if (current == null) {
|
|
104
|
+
const value = ctx.refSize++;
|
|
105
|
+
ctx.validRefs[index] = value;
|
|
106
|
+
return value;
|
|
103
107
|
}
|
|
104
|
-
|
|
105
|
-
ctx.validRefs.set(index, id);
|
|
106
|
-
return id;
|
|
108
|
+
return current;
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
/**
|
package/src/index.ts
CHANGED
|
@@ -106,7 +106,7 @@ type SerovalJSON = [
|
|
|
106
106
|
root: number,
|
|
107
107
|
isObject: boolean,
|
|
108
108
|
feature: number,
|
|
109
|
-
markedRefs: number
|
|
109
|
+
markedRefs: Record<number, number>,
|
|
110
110
|
];
|
|
111
111
|
|
|
112
112
|
export function toJSON<T extends ServerValue>(
|
|
@@ -120,7 +120,7 @@ export function toJSON<T extends ServerValue>(
|
|
|
120
120
|
root,
|
|
121
121
|
isObject,
|
|
122
122
|
ctx.features,
|
|
123
|
-
|
|
123
|
+
ctx.markedRefs,
|
|
124
124
|
]);
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -135,7 +135,7 @@ export async function toJSONAsync<T extends AsyncServerValue>(
|
|
|
135
135
|
root,
|
|
136
136
|
isObject,
|
|
137
137
|
ctx.features,
|
|
138
|
-
|
|
138
|
+
ctx.markedRefs,
|
|
139
139
|
]);
|
|
140
140
|
}
|
|
141
141
|
|