@atlaspack/core 2.12.1-dev.3460 → 2.12.1-dev.3466
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/lib/CommittedAsset.js +11 -5
- package/lib/PackagerRunner.js +8 -2
- package/lib/RequestTracker.js +10 -4
- package/lib/UncommittedAsset.js +8 -2
- package/lib/assetUtils.js +8 -2
- package/lib/index.js +0 -43
- package/lib/registerCoreWithSerializer.js +11 -5
- package/lib/requests/AtlaspackConfigRequest.js +8 -2
- package/lib/requests/ConfigRequest.js +9 -4
- package/lib/requests/DevDepRequest.js +9 -3
- package/lib/requests/PathRequest.js +8 -2
- package/lib/worker.js +8 -2
- package/package.json +17 -16
- package/src/CommittedAsset.js +4 -2
- package/src/PackagerRunner.js +1 -1
- package/src/RequestTracker.js +1 -1
- package/src/UncommittedAsset.js +1 -1
- package/src/assetUtils.js +1 -1
- package/src/index.js +0 -10
- package/src/registerCoreWithSerializer.js +7 -4
- package/src/requests/AtlaspackConfigRequest.js +1 -1
- package/src/requests/ConfigRequest.js +1 -2
- package/src/requests/DevDepRequest.js +1 -1
- package/src/requests/PathRequest.js +1 -1
- package/src/worker.js +1 -1
- package/lib/buildCache.js +0 -18
- package/lib/serializer.js +0 -216
- package/lib/serializerCore.js +0 -16
- package/src/buildCache.js +0 -15
- package/src/serializer.js +0 -255
- package/src/serializerCore.js +0 -5
- package/test/serializer.test.js +0 -302
package/lib/serializer.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.cacheSerializedObject = cacheSerializedObject;
|
|
7
|
-
exports.deserialize = deserialize;
|
|
8
|
-
Object.defineProperty(exports, "deserializeRaw", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _serializerCore.deserializeRaw;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.deserializeToCache = deserializeToCache;
|
|
15
|
-
exports.prepareForSerialization = prepareForSerialization;
|
|
16
|
-
exports.registerSerializableClass = registerSerializableClass;
|
|
17
|
-
exports.removeSerializedObjectFromCache = removeSerializedObjectFromCache;
|
|
18
|
-
exports.restoreDeserializedObject = restoreDeserializedObject;
|
|
19
|
-
exports.serialize = serialize;
|
|
20
|
-
Object.defineProperty(exports, "serializeRaw", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return _serializerCore.serializeRaw;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
exports.unregisterSerializableClass = unregisterSerializableClass;
|
|
27
|
-
var _buildCache = require("./buildCache");
|
|
28
|
-
var _serializerCore = require("./serializerCore");
|
|
29
|
-
const nameToCtor = new Map();
|
|
30
|
-
const ctorToName = new Map();
|
|
31
|
-
function registerSerializableClass(name, ctor) {
|
|
32
|
-
if (ctorToName.has(ctor)) {
|
|
33
|
-
throw new Error('Class already registered with serializer');
|
|
34
|
-
}
|
|
35
|
-
nameToCtor.set(name, ctor);
|
|
36
|
-
ctorToName.set(ctor, name);
|
|
37
|
-
}
|
|
38
|
-
function unregisterSerializableClass(name, ctor) {
|
|
39
|
-
if (nameToCtor.get(name) === ctor) {
|
|
40
|
-
nameToCtor.delete(name);
|
|
41
|
-
}
|
|
42
|
-
if (ctorToName.get(ctor) === name) {
|
|
43
|
-
ctorToName.delete(ctor);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function shallowCopy(object) {
|
|
47
|
-
if (object && typeof object === 'object') {
|
|
48
|
-
if (Array.isArray(object)) {
|
|
49
|
-
return [...object];
|
|
50
|
-
}
|
|
51
|
-
if (object instanceof Map) {
|
|
52
|
-
return new Map(object);
|
|
53
|
-
}
|
|
54
|
-
if (object instanceof Set) {
|
|
55
|
-
return new Set(object);
|
|
56
|
-
}
|
|
57
|
-
return Object.create(Object.getPrototypeOf(object), Object.getOwnPropertyDescriptors(object));
|
|
58
|
-
}
|
|
59
|
-
return object;
|
|
60
|
-
}
|
|
61
|
-
function isBuffer(object) {
|
|
62
|
-
return object.buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== 'undefined' && object.buffer instanceof SharedArrayBuffer;
|
|
63
|
-
}
|
|
64
|
-
function shouldContinueMapping(value) {
|
|
65
|
-
return value && typeof value === 'object' && value.$$raw !== true;
|
|
66
|
-
}
|
|
67
|
-
function mapObject(object, fn, preOrder = false) {
|
|
68
|
-
let cache = new Map();
|
|
69
|
-
let memo = new Map();
|
|
70
|
-
|
|
71
|
-
// Memoize the passed function to ensure it always returns the exact same
|
|
72
|
-
// output by reference for the same input. This is important to maintain
|
|
73
|
-
// reference integrity when deserializing rather than cloning.
|
|
74
|
-
let memoizedFn = val => {
|
|
75
|
-
let res = memo.get(val);
|
|
76
|
-
if (res == null) {
|
|
77
|
-
res = fn(val);
|
|
78
|
-
memo.set(val, res);
|
|
79
|
-
}
|
|
80
|
-
return res;
|
|
81
|
-
};
|
|
82
|
-
let walk = (object, shouldCopy = false) => {
|
|
83
|
-
// Check the cache first, both for performance and cycle detection.
|
|
84
|
-
if (cache.has(object)) {
|
|
85
|
-
return cache.get(object);
|
|
86
|
-
}
|
|
87
|
-
let result = object;
|
|
88
|
-
cache.set(object, result);
|
|
89
|
-
let processKey = (key, value) => {
|
|
90
|
-
let newValue = value;
|
|
91
|
-
if (preOrder && value && typeof value === 'object') {
|
|
92
|
-
newValue = memoizedFn(value);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Recursively walk the children
|
|
96
|
-
if (preOrder ? shouldContinueMapping(newValue) : newValue && typeof newValue === 'object' && shouldContinueMapping(object)) {
|
|
97
|
-
newValue = walk(newValue, newValue === value);
|
|
98
|
-
}
|
|
99
|
-
if (!preOrder && newValue && typeof newValue === 'object') {
|
|
100
|
-
newValue = memoizedFn(newValue);
|
|
101
|
-
}
|
|
102
|
-
if (newValue !== value) {
|
|
103
|
-
// Copy on write. We only need to do this when serializing, not deserializing.
|
|
104
|
-
if (object === result && preOrder && shouldCopy) {
|
|
105
|
-
result = shallowCopy(object);
|
|
106
|
-
cache.set(object, result);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Replace the key with the new value
|
|
110
|
-
if (result instanceof Map) {
|
|
111
|
-
result.set(key, newValue);
|
|
112
|
-
} else if (result instanceof Set) {
|
|
113
|
-
let _result = result; // For Flow
|
|
114
|
-
// TODO: do we care about iteration order??
|
|
115
|
-
_result.delete(value);
|
|
116
|
-
_result.add(newValue);
|
|
117
|
-
} else {
|
|
118
|
-
result[key] = newValue;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Iterate in various ways depending on type.
|
|
124
|
-
if (Array.isArray(object)) {
|
|
125
|
-
for (let i = 0; i < object.length; i++) {
|
|
126
|
-
processKey(i, object[i]);
|
|
127
|
-
}
|
|
128
|
-
} else if (object instanceof Map || object instanceof Set) {
|
|
129
|
-
for (let [key, val] of object.entries()) {
|
|
130
|
-
processKey(key, val);
|
|
131
|
-
}
|
|
132
|
-
} else if (!isBuffer(object)) {
|
|
133
|
-
for (let key in object) {
|
|
134
|
-
processKey(key, object[key]);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return result;
|
|
138
|
-
};
|
|
139
|
-
let mapped = memoizedFn(object);
|
|
140
|
-
if (preOrder ? shouldContinueMapping(mapped) : mapped && typeof mapped === 'object' && shouldContinueMapping(object)) {
|
|
141
|
-
return walk(mapped, mapped === object);
|
|
142
|
-
}
|
|
143
|
-
return mapped;
|
|
144
|
-
}
|
|
145
|
-
function prepareForSerialization(object) {
|
|
146
|
-
if (object !== null && object !== void 0 && object.$$raw) {
|
|
147
|
-
return object;
|
|
148
|
-
}
|
|
149
|
-
return mapObject(object, value => {
|
|
150
|
-
// Add a $$type property with the name of this class, if any is registered.
|
|
151
|
-
if (value && typeof value === 'object' && typeof value.constructor === 'function') {
|
|
152
|
-
let type = ctorToName.get(value.constructor);
|
|
153
|
-
if (type != null) {
|
|
154
|
-
let serialized = value;
|
|
155
|
-
let raw = false;
|
|
156
|
-
if (value && typeof value.serialize === 'function') {
|
|
157
|
-
// If the object has a serialize method, call it
|
|
158
|
-
serialized = value.serialize();
|
|
159
|
-
raw = (serialized && serialized.$$raw) ?? true;
|
|
160
|
-
if (serialized) {
|
|
161
|
-
delete serialized.$$raw;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
$$type: type,
|
|
166
|
-
$$raw: raw,
|
|
167
|
-
value: {
|
|
168
|
-
...serialized
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return value;
|
|
174
|
-
}, true);
|
|
175
|
-
}
|
|
176
|
-
function restoreDeserializedObject(object) {
|
|
177
|
-
return mapObject(object, value => {
|
|
178
|
-
// If the value has a $$type property, use it to restore the object type
|
|
179
|
-
if (value && value.$$type) {
|
|
180
|
-
let ctor = nameToCtor.get(value.$$type);
|
|
181
|
-
if (ctor == null) {
|
|
182
|
-
throw new Error(`Expected constructor ${value.$$type} to be registered with serializer to deserialize`);
|
|
183
|
-
}
|
|
184
|
-
if (typeof ctor.deserialize === 'function') {
|
|
185
|
-
return ctor.deserialize(value.value);
|
|
186
|
-
}
|
|
187
|
-
value = value.value;
|
|
188
|
-
Object.setPrototypeOf(value, ctor.prototype);
|
|
189
|
-
}
|
|
190
|
-
return value;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
const serializeCache = (0, _buildCache.createBuildCache)();
|
|
194
|
-
function serialize(object) {
|
|
195
|
-
let cached = serializeCache.get(object);
|
|
196
|
-
if (cached) {
|
|
197
|
-
return cached;
|
|
198
|
-
}
|
|
199
|
-
let mapped = prepareForSerialization(object);
|
|
200
|
-
return (0, _serializerCore.serializeRaw)(mapped);
|
|
201
|
-
}
|
|
202
|
-
function deserialize(buffer) {
|
|
203
|
-
let obj = (0, _serializerCore.deserializeRaw)(buffer);
|
|
204
|
-
return restoreDeserializedObject(obj);
|
|
205
|
-
}
|
|
206
|
-
function cacheSerializedObject(object, buffer) {
|
|
207
|
-
serializeCache.set(object, buffer || serialize(object));
|
|
208
|
-
}
|
|
209
|
-
function deserializeToCache(buffer) {
|
|
210
|
-
let deserialized = deserialize(buffer);
|
|
211
|
-
serializeCache.set(deserialized, buffer);
|
|
212
|
-
return deserialized;
|
|
213
|
-
}
|
|
214
|
-
function removeSerializedObjectFromCache(object) {
|
|
215
|
-
serializeCache.delete(object);
|
|
216
|
-
}
|
package/lib/serializerCore.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.serializeRaw = exports.deserializeRaw = void 0;
|
|
7
|
-
function _v() {
|
|
8
|
-
const data = _interopRequireDefault(require("v8"));
|
|
9
|
-
_v = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
let serializeRaw = exports.serializeRaw = _v().default.serialize;
|
|
16
|
-
let deserializeRaw = exports.deserializeRaw = _v().default.deserialize;
|
package/src/buildCache.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
const buildCaches: Array<Map<any, any>> = [];
|
|
4
|
-
|
|
5
|
-
export function createBuildCache<K, V>(): Map<K, V> {
|
|
6
|
-
let cache = new Map<K, V>();
|
|
7
|
-
buildCaches.push(cache);
|
|
8
|
-
return cache;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function clearBuildCaches() {
|
|
12
|
-
for (let cache of buildCaches) {
|
|
13
|
-
cache.clear();
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/serializer.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import {createBuildCache} from './buildCache';
|
|
3
|
-
import {serializeRaw, deserializeRaw} from './serializerCore';
|
|
4
|
-
|
|
5
|
-
export {serializeRaw, deserializeRaw} from './serializerCore';
|
|
6
|
-
|
|
7
|
-
const nameToCtor: Map<string, Class<any>> = new Map();
|
|
8
|
-
const ctorToName: Map<Class<any>, string> = new Map();
|
|
9
|
-
|
|
10
|
-
export function registerSerializableClass(name: string, ctor: Class<any>) {
|
|
11
|
-
if (ctorToName.has(ctor)) {
|
|
12
|
-
throw new Error('Class already registered with serializer');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
nameToCtor.set(name, ctor);
|
|
16
|
-
ctorToName.set(ctor, name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function unregisterSerializableClass(name: string, ctor: Class<any>) {
|
|
20
|
-
if (nameToCtor.get(name) === ctor) {
|
|
21
|
-
nameToCtor.delete(name);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (ctorToName.get(ctor) === name) {
|
|
25
|
-
ctorToName.delete(ctor);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function shallowCopy(object: any) {
|
|
30
|
-
if (object && typeof object === 'object') {
|
|
31
|
-
if (Array.isArray(object)) {
|
|
32
|
-
return [...object];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (object instanceof Map) {
|
|
36
|
-
return new Map(object);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (object instanceof Set) {
|
|
40
|
-
return new Set(object);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return Object.create(
|
|
44
|
-
Object.getPrototypeOf(object),
|
|
45
|
-
Object.getOwnPropertyDescriptors(object),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return object;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isBuffer(object) {
|
|
53
|
-
return (
|
|
54
|
-
object.buffer instanceof ArrayBuffer ||
|
|
55
|
-
(typeof SharedArrayBuffer !== 'undefined' &&
|
|
56
|
-
object.buffer instanceof SharedArrayBuffer)
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function shouldContinueMapping(value) {
|
|
61
|
-
return value && typeof value === 'object' && value.$$raw !== true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function mapObject(object: any, fn: (val: any) => any, preOrder = false): any {
|
|
65
|
-
let cache = new Map();
|
|
66
|
-
let memo = new Map();
|
|
67
|
-
|
|
68
|
-
// Memoize the passed function to ensure it always returns the exact same
|
|
69
|
-
// output by reference for the same input. This is important to maintain
|
|
70
|
-
// reference integrity when deserializing rather than cloning.
|
|
71
|
-
let memoizedFn = (val: any) => {
|
|
72
|
-
let res = memo.get(val);
|
|
73
|
-
if (res == null) {
|
|
74
|
-
res = fn(val);
|
|
75
|
-
memo.set(val, res);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return res;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
let walk = (object: any, shouldCopy = false) => {
|
|
82
|
-
// Check the cache first, both for performance and cycle detection.
|
|
83
|
-
if (cache.has(object)) {
|
|
84
|
-
return cache.get(object);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let result = object;
|
|
88
|
-
cache.set(object, result);
|
|
89
|
-
|
|
90
|
-
let processKey = (key: any, value: any) => {
|
|
91
|
-
let newValue = value;
|
|
92
|
-
if (preOrder && value && typeof value === 'object') {
|
|
93
|
-
newValue = memoizedFn(value);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Recursively walk the children
|
|
97
|
-
if (
|
|
98
|
-
preOrder
|
|
99
|
-
? shouldContinueMapping(newValue)
|
|
100
|
-
: newValue &&
|
|
101
|
-
typeof newValue === 'object' &&
|
|
102
|
-
shouldContinueMapping(object)
|
|
103
|
-
) {
|
|
104
|
-
newValue = walk(newValue, newValue === value);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!preOrder && newValue && typeof newValue === 'object') {
|
|
108
|
-
newValue = memoizedFn(newValue);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (newValue !== value) {
|
|
112
|
-
// Copy on write. We only need to do this when serializing, not deserializing.
|
|
113
|
-
if (object === result && preOrder && shouldCopy) {
|
|
114
|
-
result = shallowCopy(object);
|
|
115
|
-
cache.set(object, result);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Replace the key with the new value
|
|
119
|
-
if (result instanceof Map) {
|
|
120
|
-
result.set(key, newValue);
|
|
121
|
-
} else if (result instanceof Set) {
|
|
122
|
-
let _result = result; // For Flow
|
|
123
|
-
// TODO: do we care about iteration order??
|
|
124
|
-
_result.delete(value);
|
|
125
|
-
_result.add(newValue);
|
|
126
|
-
} else {
|
|
127
|
-
result[key] = newValue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// Iterate in various ways depending on type.
|
|
133
|
-
if (Array.isArray(object)) {
|
|
134
|
-
for (let i = 0; i < object.length; i++) {
|
|
135
|
-
processKey(i, object[i]);
|
|
136
|
-
}
|
|
137
|
-
} else if (object instanceof Map || object instanceof Set) {
|
|
138
|
-
for (let [key, val] of object.entries()) {
|
|
139
|
-
processKey(key, val);
|
|
140
|
-
}
|
|
141
|
-
} else if (!isBuffer(object)) {
|
|
142
|
-
for (let key in object) {
|
|
143
|
-
processKey(key, object[key]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return result;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
let mapped = memoizedFn(object);
|
|
151
|
-
if (
|
|
152
|
-
preOrder
|
|
153
|
-
? shouldContinueMapping(mapped)
|
|
154
|
-
: mapped && typeof mapped === 'object' && shouldContinueMapping(object)
|
|
155
|
-
) {
|
|
156
|
-
return walk(mapped, mapped === object);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return mapped;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function prepareForSerialization(object: any): any {
|
|
163
|
-
if (object?.$$raw) {
|
|
164
|
-
return object;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return mapObject(
|
|
168
|
-
object,
|
|
169
|
-
(value) => {
|
|
170
|
-
// Add a $$type property with the name of this class, if any is registered.
|
|
171
|
-
if (
|
|
172
|
-
value &&
|
|
173
|
-
typeof value === 'object' &&
|
|
174
|
-
typeof value.constructor === 'function'
|
|
175
|
-
) {
|
|
176
|
-
let type = ctorToName.get(value.constructor);
|
|
177
|
-
if (type != null) {
|
|
178
|
-
let serialized = value;
|
|
179
|
-
let raw = false;
|
|
180
|
-
if (value && typeof value.serialize === 'function') {
|
|
181
|
-
// If the object has a serialize method, call it
|
|
182
|
-
serialized = value.serialize();
|
|
183
|
-
raw = (serialized && serialized.$$raw) ?? true;
|
|
184
|
-
if (serialized) {
|
|
185
|
-
delete serialized.$$raw;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
$$type: type,
|
|
191
|
-
$$raw: raw,
|
|
192
|
-
value: {...serialized},
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return value;
|
|
198
|
-
},
|
|
199
|
-
true,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function restoreDeserializedObject(object: any): any {
|
|
204
|
-
return mapObject(object, (value) => {
|
|
205
|
-
// If the value has a $$type property, use it to restore the object type
|
|
206
|
-
if (value && value.$$type) {
|
|
207
|
-
let ctor = nameToCtor.get(value.$$type);
|
|
208
|
-
if (ctor == null) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
`Expected constructor ${value.$$type} to be registered with serializer to deserialize`,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (typeof ctor.deserialize === 'function') {
|
|
215
|
-
return ctor.deserialize(value.value);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
value = value.value;
|
|
219
|
-
Object.setPrototypeOf(value, ctor.prototype);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return value;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const serializeCache = createBuildCache();
|
|
227
|
-
|
|
228
|
-
export function serialize(object: any): Buffer {
|
|
229
|
-
let cached = serializeCache.get(object);
|
|
230
|
-
if (cached) {
|
|
231
|
-
return cached;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
let mapped = prepareForSerialization(object);
|
|
235
|
-
return serializeRaw(mapped);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export function deserialize(buffer: Buffer): any {
|
|
239
|
-
let obj = deserializeRaw(buffer);
|
|
240
|
-
return restoreDeserializedObject(obj);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function cacheSerializedObject(object: any, buffer?: Buffer): void {
|
|
244
|
-
serializeCache.set(object, buffer || serialize(object));
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export function deserializeToCache(buffer: Buffer): any {
|
|
248
|
-
let deserialized = deserialize(buffer);
|
|
249
|
-
serializeCache.set(deserialized, buffer);
|
|
250
|
-
return deserialized;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export function removeSerializedObjectFromCache(object: any) {
|
|
254
|
-
serializeCache.delete(object);
|
|
255
|
-
}
|