@atlaspack/build-cache 2.13.4-typescript-e769947a5.0 → 2.13.4-typescript-08dcc1c9b.0
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/package.json +7 -3
- package/src/{buildCache.js → buildCache.ts} +0 -2
- package/src/{index.js → index.ts} +0 -2
- package/src/{serializer.js → serializer.ts} +14 -11
- package/src/serializerCore.ts +4 -0
- package/test/{serializer.test.js → serializer.test.ts} +6 -8
- package/tsconfig.json +4 -0
- package/src/serializerCore.js +0 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/build-cache",
|
|
3
3
|
"description": "Serialize and deserialize data structures to a build cache",
|
|
4
|
-
"version": "2.13.4-typescript-
|
|
4
|
+
"version": "2.13.4-typescript-08dcc1c9b.0",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"publishConfig": {
|
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
13
13
|
},
|
|
14
14
|
"main": "lib/index.js",
|
|
15
|
-
"source": "src/index.
|
|
15
|
+
"source": "src/index.ts",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">= 16.0.0"
|
|
18
18
|
},
|
|
19
|
-
"
|
|
19
|
+
"scripts": {
|
|
20
|
+
"check-ts": "tsc --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"types": "src/index.ts",
|
|
23
|
+
"gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
|
|
20
24
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import {Flow} from 'flow-to-typescript-codemod';
|
|
2
2
|
import {createBuildCache} from './buildCache';
|
|
3
3
|
import {serializeRaw, deserializeRaw} from './serializerCore';
|
|
4
4
|
|
|
5
5
|
export {serializeRaw, deserializeRaw} from './serializerCore';
|
|
6
6
|
|
|
7
|
-
const nameToCtor: Map<string, Class<any>> = new Map();
|
|
8
|
-
const ctorToName: Map<Class<any>, string> = new Map();
|
|
7
|
+
const nameToCtor: Map<string, Flow.Class<any>> = new Map();
|
|
8
|
+
const ctorToName: Map<Flow.Class<any>, string> = new Map();
|
|
9
9
|
|
|
10
|
-
export function registerSerializableClass(name: string, ctor: Class<any>) {
|
|
10
|
+
export function registerSerializableClass(name: string, ctor: Flow.Class<any>) {
|
|
11
11
|
if (ctorToName.has(ctor)) {
|
|
12
12
|
throw new Error('Class already registered with serializer');
|
|
13
13
|
}
|
|
@@ -16,7 +16,10 @@ export function registerSerializableClass(name: string, ctor: Class<any>) {
|
|
|
16
16
|
ctorToName.set(ctor, name);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function unregisterSerializableClass(
|
|
19
|
+
export function unregisterSerializableClass(
|
|
20
|
+
name: string,
|
|
21
|
+
ctor: Flow.Class<any>,
|
|
22
|
+
) {
|
|
20
23
|
if (nameToCtor.get(name) === ctor) {
|
|
21
24
|
nameToCtor.delete(name);
|
|
22
25
|
}
|
|
@@ -49,7 +52,7 @@ function shallowCopy(object: any) {
|
|
|
49
52
|
return object;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
function isBuffer(object) {
|
|
55
|
+
function isBuffer(object: any) {
|
|
53
56
|
return (
|
|
54
57
|
object.buffer instanceof ArrayBuffer ||
|
|
55
58
|
(typeof SharedArrayBuffer !== 'undefined' &&
|
|
@@ -57,11 +60,11 @@ function isBuffer(object) {
|
|
|
57
60
|
);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
function shouldContinueMapping(value) {
|
|
63
|
+
function shouldContinueMapping(value: any) {
|
|
61
64
|
return value && typeof value === 'object' && value.$$raw !== true;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
function mapObject(object: any, fn: (val
|
|
67
|
+
function mapObject(object: any, fn: (val?: any) => any, preOrder = false): any {
|
|
65
68
|
let cache = new Map();
|
|
66
69
|
let memo = new Map();
|
|
67
70
|
|
|
@@ -211,8 +214,8 @@ export function restoreDeserializedObject(object: any): any {
|
|
|
211
214
|
);
|
|
212
215
|
}
|
|
213
216
|
|
|
214
|
-
if (typeof ctor.deserialize === 'function') {
|
|
215
|
-
return ctor.deserialize(value.value);
|
|
217
|
+
if (typeof (ctor as any).deserialize === 'function') {
|
|
218
|
+
return (ctor as any).deserialize(value.value);
|
|
216
219
|
}
|
|
217
220
|
|
|
218
221
|
value = value.value;
|
|
@@ -223,7 +226,7 @@ export function restoreDeserializedObject(object: any): any {
|
|
|
223
226
|
});
|
|
224
227
|
}
|
|
225
228
|
|
|
226
|
-
const serializeCache = createBuildCache();
|
|
229
|
+
const serializeCache = createBuildCache<any, Buffer>();
|
|
227
230
|
|
|
228
231
|
export function serialize(object: any): Buffer {
|
|
229
232
|
let cached = serializeCache.get(object);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import sinon from 'sinon';
|
|
5
3
|
|
|
@@ -151,8 +149,8 @@ describe('serializer', () => {
|
|
|
151
149
|
|
|
152
150
|
it('should serialize a cyclic class', () => {
|
|
153
151
|
class Foo {
|
|
154
|
-
x:
|
|
155
|
-
constructor(x
|
|
152
|
+
x: Foo | null | undefined;
|
|
153
|
+
constructor(x?: Foo | null) {
|
|
156
154
|
this.x = x;
|
|
157
155
|
}
|
|
158
156
|
}
|
|
@@ -193,8 +191,8 @@ describe('serializer', () => {
|
|
|
193
191
|
|
|
194
192
|
it('should serialize a cyclic class and copy on write', () => {
|
|
195
193
|
class Foo {
|
|
196
|
-
x:
|
|
197
|
-
constructor(x
|
|
194
|
+
x: Foo | null | undefined;
|
|
195
|
+
constructor(x?: Foo | null) {
|
|
198
196
|
this.x = x;
|
|
199
197
|
}
|
|
200
198
|
}
|
|
@@ -257,7 +255,7 @@ describe('serializer', () => {
|
|
|
257
255
|
class Outer {
|
|
258
256
|
inner: Inner;
|
|
259
257
|
|
|
260
|
-
constructor(inner) {
|
|
258
|
+
constructor(inner: any) {
|
|
261
259
|
this.inner = inner;
|
|
262
260
|
}
|
|
263
261
|
|
|
@@ -272,7 +270,7 @@ describe('serializer', () => {
|
|
|
272
270
|
class Inner {
|
|
273
271
|
x: number;
|
|
274
272
|
|
|
275
|
-
constructor(x) {
|
|
273
|
+
constructor(x: any) {
|
|
276
274
|
this.x = x;
|
|
277
275
|
}
|
|
278
276
|
|
package/tsconfig.json
ADDED