Comparing version 1.13.2 to 1.13.3
@@ -59,3 +59,3 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
var equalityAnnotations = generateReferentialEqualityAnnotations(identities); | ||
var equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe); | ||
if (equalityAnnotations) { | ||
@@ -62,0 +62,0 @@ res.meta = __assign(__assign({}, res.meta), { referentialEqualities: equalityAnnotations }); |
@@ -14,4 +14,4 @@ import { TypeAnnotation } from './transformer'; | ||
export declare type ReferentialEqualityAnnotations = Record<string, string[]> | [string[]] | [string[], Record<string, string[]>]; | ||
export declare function generateReferentialEqualityAnnotations(identitites: Map<any, any[][]>): ReferentialEqualityAnnotations | undefined; | ||
export declare function generateReferentialEqualityAnnotations(identitites: Map<any, any[][]>, dedupe: boolean): ReferentialEqualityAnnotations | undefined; | ||
export declare const walker: (object: any, identities: Map<any, any[][]>, superJson: SuperJSON, dedupe: boolean, path?: any[], objectsInThisPath?: any[], seenObjects?: Map<unknown, Result>) => Result; | ||
export {}; |
@@ -90,3 +90,3 @@ var __read = (this && this.__read) || function (o, n) { | ||
} | ||
export function generateReferentialEqualityAnnotations(identitites) { | ||
export function generateReferentialEqualityAnnotations(identitites, dedupe) { | ||
var result = {}; | ||
@@ -98,10 +98,16 @@ var rootEqualityPaths = undefined; | ||
} | ||
var _a = __read(paths | ||
.map(function (path) { return path.map(String); }) | ||
.sort(function (a, b) { return a.length - b.length; })), shortestPath = _a[0], identicalPaths = _a.slice(1); | ||
if (shortestPath.length === 0) { | ||
// if we're not deduping, all of these objects continue existing. | ||
// putting the shortest path first makes it easier to parse for humans | ||
// if we're deduping though, only the first entry will still exist, so we can't do this optimisation. | ||
if (!dedupe) { | ||
paths = paths | ||
.map(function (path) { return path.map(String); }) | ||
.sort(function (a, b) { return a.length - b.length; }); | ||
} | ||
var _a = __read(paths), representativePath = _a[0], identicalPaths = _a.slice(1); | ||
if (representativePath.length === 0) { | ||
rootEqualityPaths = identicalPaths.map(stringifyPath); | ||
} | ||
else { | ||
result[stringifyPath(shortestPath)] = identicalPaths.map(stringifyPath); | ||
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath); | ||
} | ||
@@ -108,0 +114,0 @@ }); |
@@ -62,3 +62,3 @@ "use strict"; | ||
} | ||
var equalityAnnotations = plainer_1.generateReferentialEqualityAnnotations(identities); | ||
var equalityAnnotations = plainer_1.generateReferentialEqualityAnnotations(identities, this.dedupe); | ||
if (equalityAnnotations) { | ||
@@ -65,0 +65,0 @@ res.meta = __assign(__assign({}, res.meta), { referentialEqualities: equalityAnnotations }); |
@@ -14,4 +14,4 @@ import { TypeAnnotation } from './transformer'; | ||
export declare type ReferentialEqualityAnnotations = Record<string, string[]> | [string[]] | [string[], Record<string, string[]>]; | ||
export declare function generateReferentialEqualityAnnotations(identitites: Map<any, any[][]>): ReferentialEqualityAnnotations | undefined; | ||
export declare function generateReferentialEqualityAnnotations(identitites: Map<any, any[][]>, dedupe: boolean): ReferentialEqualityAnnotations | undefined; | ||
export declare const walker: (object: any, identities: Map<any, any[][]>, superJson: SuperJSON, dedupe: boolean, path?: any[], objectsInThisPath?: any[], seenObjects?: Map<unknown, Result>) => Result; | ||
export {}; |
@@ -95,3 +95,3 @@ "use strict"; | ||
} | ||
function generateReferentialEqualityAnnotations(identitites) { | ||
function generateReferentialEqualityAnnotations(identitites, dedupe) { | ||
var result = {}; | ||
@@ -103,10 +103,16 @@ var rootEqualityPaths = undefined; | ||
} | ||
var _a = __read(paths | ||
.map(function (path) { return path.map(String); }) | ||
.sort(function (a, b) { return a.length - b.length; })), shortestPath = _a[0], identicalPaths = _a.slice(1); | ||
if (shortestPath.length === 0) { | ||
// if we're not deduping, all of these objects continue existing. | ||
// putting the shortest path first makes it easier to parse for humans | ||
// if we're deduping though, only the first entry will still exist, so we can't do this optimisation. | ||
if (!dedupe) { | ||
paths = paths | ||
.map(function (path) { return path.map(String); }) | ||
.sort(function (a, b) { return a.length - b.length; }); | ||
} | ||
var _a = __read(paths), representativePath = _a[0], identicalPaths = _a.slice(1); | ||
if (representativePath.length === 0) { | ||
rootEqualityPaths = identicalPaths.map(pathstringifier_1.stringifyPath); | ||
} | ||
else { | ||
result[pathstringifier_1.stringifyPath(shortestPath)] = identicalPaths.map(pathstringifier_1.stringifyPath); | ||
result[pathstringifier_1.stringifyPath(representativePath)] = identicalPaths.map(pathstringifier_1.stringifyPath); | ||
} | ||
@@ -113,0 +119,0 @@ }); |
{ | ||
"version": "1.13.2", | ||
"version": "1.13.3", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -46,3 +46,3 @@ <p align="center"> | ||
## Sponsors | ||
[<img src="https://user-images.githubusercontent.com/3496193/206313745-11f25f7b-2540-4a4c-86c0-d085e38b0b45.png" alt="Flightcontrol Logo" style="width: 400px;"/>](https://www.flightcontrol.dev/?ref=superjson) | ||
[<img src="https://raw.githubusercontent.com/blitz-js/blitz/main/assets/flightcontrol.png" alt="Flightcontrol Logo" style="width: 400px;"/>](https://www.flightcontrol.dev/?ref=superjson) | ||
@@ -49,0 +49,0 @@ |
/* eslint-disable es5/no-for-of */ | ||
/* eslint-disable es5/no-es6-methods */ | ||
import * as fs from 'fs'; | ||
import SuperJSON from './'; | ||
@@ -1196,1 +1198,22 @@ import { JSONValue, SuperJSONResult, SuperJSONValue } from './types'; | ||
}); | ||
test('dedupe=true on a large complicated schema', () => { | ||
const content = fs.readFileSync(__dirname + '/non-deduped-cal.json', 'utf-8'); | ||
const parsed = JSON.parse(content); | ||
const deserialized = SuperJSON.deserialize(parsed); | ||
const nondeduped = new SuperJSON({}); | ||
const deduped = new SuperJSON({ | ||
dedupe: true, | ||
}); | ||
const nondedupedOut = nondeduped.deserialize( | ||
nondeduped.serialize(deserialized) | ||
); | ||
const dedupedOut = deduped.deserialize(deduped.serialize(deserialized)); | ||
expect(nondedupedOut).toEqual(deserialized); | ||
expect(dedupedOut).toEqual(deserialized); | ||
}); |
@@ -48,3 +48,4 @@ import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types'; | ||
const equalityAnnotations = generateReferentialEqualityAnnotations( | ||
identities | ||
identities, | ||
this.dedupe | ||
); | ||
@@ -51,0 +52,0 @@ if (equalityAnnotations) { |
@@ -121,3 +121,4 @@ import { | ||
export function generateReferentialEqualityAnnotations( | ||
identitites: Map<any, any[][]> | ||
identitites: Map<any, any[][]>, | ||
dedupe: boolean | ||
): ReferentialEqualityAnnotations | undefined { | ||
@@ -132,10 +133,19 @@ const result: Record<string, string[]> = {}; | ||
const [shortestPath, ...identicalPaths] = paths | ||
.map(path => path.map(String)) | ||
.sort((a, b) => a.length - b.length); | ||
// if we're not deduping, all of these objects continue existing. | ||
// putting the shortest path first makes it easier to parse for humans | ||
// if we're deduping though, only the first entry will still exist, so we can't do this optimisation. | ||
if (!dedupe) { | ||
paths = paths | ||
.map(path => path.map(String)) | ||
.sort((a, b) => a.length - b.length); | ||
} | ||
if (shortestPath.length === 0) { | ||
const [representativePath, ...identicalPaths] = paths; | ||
if (representativePath.length === 0) { | ||
rootEqualityPaths = identicalPaths.map(stringifyPath); | ||
} else { | ||
result[stringifyPath(shortestPath)] = identicalPaths.map(stringifyPath); | ||
result[stringifyPath(representativePath)] = identicalPaths.map( | ||
stringifyPath | ||
); | ||
} | ||
@@ -142,0 +152,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6996358
106
5713
1