-
Notifications
You must be signed in to change notification settings - Fork 583
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(encoding): add json/stream.ts #2231
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayame113 LGTM. Great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, besides two minor nitpicks
TBH, I think these combinators are too specific. A I think |
For concatenation, I think a stream combinator that has an API in the form |
IMO we should change this and the jsonc module to use |
This suggestion makes sense to me. You mean the users should be able to do: const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextDelimiterStream(separator))
.pipeThrough(new JSONParseStream()); instead of: const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new JSONLinesParseStream()); I also also agree with reducing
Is this suggestion about |
but we already have |
wait we also have |
Maybe the usage will be like this? // parses JSON lines, NDJSON and JSON Text Sequences
const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextDelimiterStream(separator)) // or TextLineStream
.pipeThrough(new JSONParseStream());
// parses Concatenated JSON
const readable = body!
.pipeThrough(new TextDecoderStream())
.pipeThrough(new ConcatenatedJSONParseStream());
// stringifies JSON lines, NDJSON, JSON Text Sequences and Concatenated JSON
readable
.pipeThrough(new JSONStringifyStream({ prefix, suffix })) // default of prefix is "", default of suffix is "\n"
.pipeThrough(new TextEncoderStream());
// or
// readable
// .pipeThrough(new JSONStringifyStream())
// .pipeThrough(new MappingStream((str) => `${prefix}${str}${suffix}`)) // The name is tentative
// .pipeThrough(new TextEncoderStream()); I don't have time this week, so I think I'll be working on the weekend. |
@ayame113 The interface looks cleaner to me. Let's switch to it |
The current interface looks like this:
What about |
I'm also in favor of keeping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM again.
I'm in favor of JSON
casing.
close #2208
JSONLinesParseStream
parses JSON lines, NDJSON and JSON Text Sequences.JSONLinesStringifyStream
stringifies JSON lines, NDJSON and JSON Text Sequences.ConcatenatedJSONParseStream
parses Concatenated JSON.ConcatenatedJSONStringifyStream
stringifies Concatenated JSON.Implementations have been ported from https://github.com/ayame113/jsonlines/tree/9e969323a0b09d573a4a35f0d466866bb62e1a67.
#2227 needs to be merged first. The CI should turn green when #2227 is merged into main.