Add asAsyncData
helper method for fluent Promises (e.g., Postgrest-js) integration
#443
Labels
enhancement
New feature or request
Is your feature request related to a problem? Please describe.
When using libraries like
postgrest-js
in a Nuxt project, the returned objects (e.g.,PostgrestBuilder
orPostgrestFilterBuilder
) implementPromiseLike
. While this allows resolving results withawait
or.then()
, the preferred Nuxt pattern for handling asynchronous data is through theuseAsyncData
composable.Currently, manually wrapping these fluent chains in
useAsyncData
can feel verbose and repetitive, reducing code clarity and developer experience.Describe the solution you'd like
It would be helpful to introduce a helper method like
asAsyncData()
directly onPromiseLike
objects (e.g.,PostgrestBuilder
in postgrest-js). This method would wrap the current fluent chain intouseAsyncData
, enabling a more concise and fluent syntax.Example:
Instead of:
You could write:
Describe alternatives you've considered
useAsyncData
. While functional, this approach leads to repetitive code and reduces readability.postgrest-js
.Additional context
The solution can leverage prototype chaining to extend the behavior of
PromiseLike
objects such asPostgrestBuilder
, and declaration merging to ensure proper TypeScript type support. This approach avoids modifying the original library code and provides a clean, composable integration into Nuxt.Related Nuxt documentation: useAsyncData.
The text was updated successfully, but these errors were encountered: