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: OpaqueReference #42

Merged
merged 10 commits into from
Jul 14, 2024
Merged

feat: OpaqueReference #42

merged 10 commits into from
Jul 14, 2024

Conversation

lxsmnsyc
Copy link
Owner

@lxsmnsyc lxsmnsyc commented Jul 12, 2024

Fixes #41

This feature adds a very basic OpaqueReference class. The purpose of this class is to wrap user-specified values into "opaque references": references that are hidden from the serializer. An OpaqueReference contains two values: the original value it is trying to hide, and an optional replacement value, which is what the serializer "sees".

A replacement value can only be a value that seroval can serialize. By default, a replacement value is undefined.

Example:

import { serialize, deserialize, OpaqueReference } from 'seroval';

const example = {
  transparent: "This is a transparent value.",
  opaque: new OpaqueReference('This is an opaque value.'),
};

// You can still access the original value:
console.log(example.opaque.value);

// but now it's different
const deserialized = deserialize(serialize(example));
console.log(deserialized.opaque); // undefined

@lxsmnsyc lxsmnsyc merged commit 287ef25 into main Jul 14, 2024
1 check passed
@lxsmnsyc lxsmnsyc deleted the feature-opaque-ref branch July 14, 2024 06:06
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.

Allow opting out of serialization
1 participant