Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dedupe flag #247

Merged
merged 15 commits into from
Jul 17, 2023
Merged

feat: add dedupe flag #247

merged 15 commits into from
Jul 17, 2023

Conversation

KATT
Copy link
Contributor

@KATT KATT commented Jul 14, 2023

add dedupe flag that will make sure that complex objects only appear once in the output

@KATT KATT requested a review from Skn0tt as a code owner July 14, 2023 14:24
Comment on lines +170 to +172
? {
transformedValue: null,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice with some symbol here (and for circular references fwiw) to show in the JSON that we have replaced it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I wonder if there's some other implementation that we can draw inspiration from 🤔

Apparently Node.js prints [Circular *1]:
Screenshot 2023-07-14 at 16 34 28

Same with Deno. This might even be a v8 thing.

Screenshot 2023-07-14 at 16 44 50

What if we did [Circular] and [Pruned]?

Copy link
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks solid, i'd like to pause a moment to think about the name + location of that flag.

src/index.test.ts Outdated Show resolved Hide resolved
Comment on lines +170 to +172
? {
transformedValue: null,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I wonder if there's some other implementation that we can draw inspiration from 🤔

Apparently Node.js prints [Circular *1]:
Screenshot 2023-07-14 at 16 34 28

Same with Deno. This might even be a v8 thing.

Screenshot 2023-07-14 at 16 44 50

What if we did [Circular] and [Pruned]?

src/index.ts Outdated
/**
* If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
*/
public dedupe = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut instinct was to put this as an optional parameter to serialize, and call it something like pruneReferentialEqualities, in reference to meta.referentialEqualities. I'd also be fine with dedupeReferentialEqualities. It's a lot longer of a name, but more descriptive I guess? But also harder to parse, so i'm torn between the two. Any strong feelings from your end on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an optional argument to serialize could be seen as a breaking change in cases like items.map(superjson.serialize.bind(superjson) 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where you're coming from, but I don't necessarily agree with that strict of a definition of "breaking change" 😅

@KATT
Copy link
Contributor Author

KATT commented Jul 14, 2023

You decide everything and me / @juliusmarminge will just follow suit. :)

Feel free to just push to my PR or make another stab at it, I gotta go for today now!

@KATT
Copy link
Contributor Author

KATT commented Jul 14, 2023

FWIW, changing the circular to anything else but null could be seen as a breaking change - so maybe it's better to have both as null for now

@Skn0tt Skn0tt merged commit dd3aeb5 into blitz-js:main Jul 17, 2023
3 checks passed
@Skn0tt
Copy link
Member

Skn0tt commented Jul 17, 2023

@juliusmarminge
Copy link
Contributor

Published as part of https://github.com/blitz-js/superjson/releases/tag/v1.13.0

Awesome. Unfortunately, for some reason I get an error when running the compiled version yelling that SuperJSON isn't a constructor 🤔

CleanShot 2023-07-17 at 10 47 44@2x

@Skn0tt
Copy link
Member

Skn0tt commented Jul 17, 2023

Can reproduce locally, let's see what's causing it 🤔

@Skn0tt
Copy link
Member

Skn0tt commented Jul 17, 2023

It looks like it's related to how TypeScript emits the export default class. Seems like that bug has existed before this PR, but nobody tried doing new SuperJSON until now!

@juliusmarminge
Copy link
Contributor

juliusmarminge commented Jul 17, 2023

It looks like it's related to how TypeScript emits the export default class

Bundling javascript....

Seems like that bug has existed before this PR, but nobody tried doing new SuperJSON until now!

Seems reasonable. Nothing in this PR should cause difference in behavior in that regard

@Skn0tt
Copy link
Member

Skn0tt commented Jul 17, 2023

As a workaround, could you try const SuperJSON = require(".").default? That fixed it for me locally.

@juliusmarminge
Copy link
Contributor

juliusmarminge commented Jul 17, 2023

As a workaround, could you try const SuperJSON = require(".").default? That fixed it for me locally.

How do you mean? The relative require('.') won't work outside of the local repo. I tried this without success though:

import type SuperJSON from 'superjson'

// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
export const superjson: SuperJSON = require('superjson').default({
	dedupe: true,
})
CleanShot 2023-07-17 at 11 12 04@2x

@Skn0tt
Copy link
Member

Skn0tt commented Jul 17, 2023

Oops, meant to replace the . with superjson. But you guessed right, that's what I was referring to - doesn't seem to work, though. I'll see what I can do to fix the import ...

@juliusmarminge
Copy link
Contributor

Oops, meant to replace the . with superjson. But you guessed right, that's what I was referring to - doesn't seem to work, though. I'll see what I can do to fix the import ...

Made a temporary workaround that works if you use a named import instead of the default one in #250 🤷🏼‍♂️

@KATT KATT deleted the compression branch July 17, 2023 14:22
Chia1104 added a commit to Chia1104/chia1104.dev that referenced this pull request Jul 21, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [superjson](https://togithub.com/blitz-js/superjson) | [`1.12.4` ->
`1.13.1`](https://renovatebot.com/diffs/npm/superjson/1.12.4/1.13.1) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/superjson/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/superjson/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/superjson/1.12.4/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/superjson/1.12.4/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>blitz-js/superjson (superjson)</summary>

###
[`v1.13.1`](https://togithub.com/blitz-js/superjson/releases/tag/v1.13.1)

[Compare
Source](https://togithub.com/blitz-js/superjson/compare/v1.13.0...v1.13.1)

#### What's Changed

- Bump json5 from 1.0.1 to 1.0.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#218
- Bump minimatch from 3.0.4 to 3.1.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#213
- Bump decode-uri-component from 0.2.0 to 0.2.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#212
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#248
- fix: TypeError: SuperJSON is not a constructor by
[@&#8203;juliusmarminge](https://togithub.com/juliusmarminge) in
[blitz-js/superjson#250

#### New Contributors

- [@&#8203;juliusmarminge](https://togithub.com/juliusmarminge) made
their first contribution in
[blitz-js/superjson#250

**Full Changelog**:
blitz-js/superjson@v1.13.0...v1.13.1

###
[`v1.13.0`](https://togithub.com/blitz-js/superjson/releases/tag/v1.13.0)

[Compare
Source](https://togithub.com/blitz-js/superjson/compare/v1.12.4...v1.13.0)

#### What's Changed

- fix: referential equalities should ignore child nodes by
[@&#8203;KATT](https://togithub.com/KATT) in
[blitz-js/superjson#244
- feat: add `dedupe` flag by [@&#8203;KATT](https://togithub.com/KATT)
in
[blitz-js/superjson#247

**Full Changelog**:
blitz-js/superjson@v1.12.4...v1.13.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/Chia1104/chia1104.dev).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi44LjExIiwidXBkYXRlZEluVmVyIjoiMzYuOC4xMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
Chia1104 added a commit to Chia1104/chia-stack that referenced this pull request Jul 25, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [superjson](https://togithub.com/blitz-js/superjson) | [`1.12.4` ->
`1.13.1`](https://renovatebot.com/diffs/npm/superjson/1.12.4/1.13.1) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/superjson/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/superjson/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/superjson/1.12.4/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/superjson/1.12.4/1.13.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>blitz-js/superjson (superjson)</summary>

###
[`v1.13.1`](https://togithub.com/blitz-js/superjson/releases/tag/v1.13.1)

[Compare
Source](https://togithub.com/blitz-js/superjson/compare/v1.13.0...v1.13.1)

#### What's Changed

- Bump json5 from 1.0.1 to 1.0.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#218
- Bump minimatch from 3.0.4 to 3.1.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#213
- Bump decode-uri-component from 0.2.0 to 0.2.2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#212
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[blitz-js/superjson#248
- fix: TypeError: SuperJSON is not a constructor by
[@&#8203;juliusmarminge](https://togithub.com/juliusmarminge) in
[blitz-js/superjson#250

#### New Contributors

- [@&#8203;juliusmarminge](https://togithub.com/juliusmarminge) made
their first contribution in
[blitz-js/superjson#250

**Full Changelog**:
blitz-js/superjson@v1.13.0...v1.13.1

###
[`v1.13.0`](https://togithub.com/blitz-js/superjson/releases/tag/v1.13.0)

[Compare
Source](https://togithub.com/blitz-js/superjson/compare/v1.12.4...v1.13.0)

#### What's Changed

- fix: referential equalities should ignore child nodes by
[@&#8203;KATT](https://togithub.com/KATT) in
[blitz-js/superjson#244
- feat: add `dedupe` flag by [@&#8203;KATT](https://togithub.com/KATT)
in
[blitz-js/superjson#247

**Full Changelog**:
blitz-js/superjson@v1.12.4...v1.13.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/Chia1104/chia-stack).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMS4wIiwidXBkYXRlZEluVmVyIjoiMzYuMTEuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants