Skip to content

feat: add experimental support for iterators and streams - #4911

Closed
KATT wants to merge 63 commits into
mainfrom
tuple-stream
Closed

KATT wants to merge 63 commits into
mainfrom
tuple-stream

Conversation

@KATT

@KATT KATT commented Oct 12, 2023 •

Copy link
Copy Markdown
Member

tl;dr is that queries and mutations can return generator functions, and you can "just" use them

test('async iterator', async () => {
const { proxy } = ctx;
const results = await proxy.iterator.query();
const resultsArray = [];
for await (const result of results) {
resultsArray.push(result);
}
expect(resultsArray).toMatchInlineSnapshot(`
Array [
1,
2,
3,
]
`);
});

🎯 Changes

Proof of concept of using tupleson to handle streaming data - tl;

  • Make new resolveHTTPResponse-function that returns a fetch Response
  • Use tupleson to serialize promises on the backend
  • Create a httpTuplesonLink that handles this type of response from the server
  • Make procedure as a generator function possible
  • Make tupleson configurable in initTRPC and figure out a way to reuse same configuration for both client and server (transformers will be unnecessary as we can configure them all in tson)

@vercel

vercel Bot commented Oct 12, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-prisma-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2023 8:41pm
og-image ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2023 8:41pm
trpc-next-app-dir ❌ Failed (Inspect) Nov 19, 2023 8:41pm
www ❌ Failed (Inspect) Nov 19, 2023 8:41pm

const ctx = konn()
.beforeEach(() => {
const t = initTRPC.create({
transformer: 'tupleson', // <------- help, idk if this is the right thing

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To me, it depends, if tupleson is the default anyway, the string is fine, if not I would opt for a reference from the tupleson package in order to make it tree shakable

The tree shake will, however, only fork if the default is different from tupleson, or if this is a required property and thus none is the default...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To me, it depends, if tupleson is the default anyway, the string is fine, if not I would opt for a reference from the tupleson package in order to make it tree shakable

The tree shake will, however, only fork if the default is different from tupleson, or if this is a required property and thus none is the default...

@Akxe
We've been leaning towards making Tupleson the transformer moving forward, deprecating the need for this field. It would make TSON a hard requirement for future implementations (but we maintain backward compat for a bit).

If users want to customize the transform logic, they do so by configuring TSON (which allows an alternative to the default JSON from stringifying/parsing).

Essentially, we would be moving the 'transformer' concept to be an implementation detail of Tupleson, instead of an implementation detail of tRPC.

That was an idea, at least. Thoughts?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I do like the idea of using TSON. My point was merely informative :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I do not want a string to be there. It means that even if you were to replace it, the TSON dependency is forced upon the consumer.

From my point of view; no choice or choice in the form of a function or a Class.

Why string? What would you put there otherwise?

KATT added 3 commits November 3, 2023 11:27
# Conflicts:
#	packages/tests/package.json
#	pnpm-lock.yaml
# Conflicts:
#	packages/client/package.json
#	pnpm-lock.yaml
@XantreDev

XantreDev commented Jan 2, 2024 •

Copy link
Copy Markdown

@KATT What is a progress on it? I think streaming is really useful

@KATT

KATT commented Jan 5, 2024

Copy link
Copy Markdown
Member Author

@KATT What is a progress on it? I think streaming is really useful

@XantreGodlike it's not high on the priority list for us right now as we don't need it ourselves. Our main priority at the moment is finishing the breaking changes we have for v11.

If you work for a company that would like to fund the development of this, we may reconsider, feel free to contact us if so.

@XantreDev

Copy link
Copy Markdown

@KATT What is a progress on it? I think streaming is really useful

@XantreGodlike it's not high on the priority list for us right now as we don't need it ourselves. Our main priority at the moment is finishing the breaking changes we have for v11.

If you work for a company that would like to fund the development of this, we may reconsider, feel free to contact us if so.

Nope, it's for hobby purposes

@JonathonRP

Copy link
Copy Markdown

@KATT any progress on this vs unstable_streamingLink?

@rdewolff

Copy link
Copy Markdown

Looking at the stream support 👀

@lacherogwu

Copy link
Copy Markdown

Looking forward for this as its very useful for download big files

@aayushpurplesectors

Copy link
Copy Markdown

Can't wait for it!!

@ghost

ghost commented Mar 26, 2024

Copy link
Copy Markdown

Looking forward to this for LLM applications so I can stream the LLM output without having to write a separate end-point through the framework I am using.

@Sid-Turner-Ellis

Copy link
Copy Markdown

@KATT For those that need this for personal projects, how can we help with getting this merged?

@lrwlf

lrwlf commented Apr 26, 2024

Copy link
Copy Markdown

Is there anything we can help? Looking forward to be merged soon

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

This branch had an error being deployed

2 failed and 3 active deployments
Preview – todomvc — 94057df3 Deployed Nov 19, 2023 by vercel[bot]
Preview – og-image — 94057df3 Deployed Nov 19, 2023 by vercel[bot]
Preview – next-prisma-starter — 94057df3 Deployed Nov 19, 2023 by vercel[bot]
Preview – www — 94057df3 Deployed Nov 19, 2023 by vercel[bot]
Preview – trpc-next-app-dir — 94057df3 Deployed Nov 19, 2023 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🙋‍♂️ help wanted Extra attention is needed @trpc/client @trpc/server 🕸 www Stuff to do with the website (`/www` folder)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Streaming Mutations / Queries update request handling in resolveHttpResponse to follow Fetch API