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

implement and use DBOSJSON instead of JSON #490

Merged
merged 6 commits into from
Jun 7, 2024

Conversation

demetris-manikas
Copy link
Contributor

This PR address #450

I chose the getTime() over toUTCString() since it consumes less space.

@demetris-manikas demetris-manikas force-pushed the 450-dbos-reviver-replacer branch 4 times, most recently from c4f423e to eb5f871 Compare June 6, 2024 06:35
src/utils.ts Outdated
return value;
}

const JSON_DATE_VALUE_PREFIX = 'date:'
Copy link
Member

Choose a reason for hiding this comment

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

I think the prefix could be more unique so we don't mistakenly deserialize other strings. For example, DBOSJsonDate or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!
I was waiting for this.
Just name it!
Maybe add some of $%^@ as well.

@demetris-manikas
Copy link
Contributor Author

What about using a library?
This one looks alive and kicking https://github.com/yahoo/serialize-javascript

@qianl15
Copy link
Member

qianl15 commented Jun 6, 2024

What about using a library? This one looks alive and kicking https://github.com/yahoo/serialize-javascript

Looks like this package doesn't support Buffer and:

For some use cases you might also need to deserialize the string. This is explicitly not part of this module.

We might find some better suited package later.

@demetris-manikas
Copy link
Contributor Author

Updated to use DBOSJsonDate as prefix

qianl15
qianl15 previously approved these changes Jun 6, 2024
Copy link
Member

@qianl15 qianl15 left a comment

Choose a reason for hiding this comment

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

After discussing with the team, we're reconsidering this PR -- we think a safer way is to parse into an object (similar to the way we implemented Buffer replacer and reviver). Because the string with a prefix is still unsafe and will do a string matching for every single string.

@qianl15 qianl15 dismissed their stale review June 6, 2024 20:17

After discussing with the team, we're reconsidering this PR

Copy link
Member

@qianl15 qianl15 left a comment

Choose a reason for hiding this comment

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

Hi @demetris-manikas Thanks again for your contribution! We'd like to have two changes on this PR:

  1. Instead of prefixing a string, we think a safer way is to use an object, similar to the way we implemented Buffer support. For example:
interface SerializedDate {
  dbos_type: 'dbos_Date';
  dbos_data: string;
}
  1. Could you also replace JSON in all other places under src/? There are still some JSON in dbos-executor.ts, config.ts, fdb_system_database.ts, server.ts, and logs.ts.

@demetris-manikas
Copy link
Contributor Author

Sure.
are you sure about the data being a string instead of a number?
and if so you want the toUTCString() to be used?

@qianl15
Copy link
Member

qianl15 commented Jun 6, 2024

Sure. are you sure about the data being a string instead of a number? and if so you want the toUTCString() to be used?

Let's use toISOString() as this is the default format used by JSON.

@demetris-manikas
Copy link
Contributor Author

Applied all recommendations

src/utils.ts Outdated Show resolved Hide resolved
@qianl15 qianl15 merged commit c677c7f into dbos-inc:main Jun 7, 2024
2 checks passed
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.

2 participants