feat(pinia-colada): define base options and interceptors via contract meta - #1718
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/json-schema
@orpc/nest
@orpc/next
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Important
isProcedureUtilsOptions incorrectly rejects function modifiers in scoped options — see inline comment. Otherwise looks solid.
Reviewed changes — ports the contract-options-via-meta pattern to @orpc/pinia-colada, allowing base options and interceptors to be defined on procedure contracts via piniaColada() and applied automatically through ContractOptionsUtilsPlugin.
- New
meta.ts—piniaColada()stores procedure utils options in contract meta under~pinia-colada, with merge-on-repeat semantics;getPiniaColadaMeta()reads stored options;ContractOptionsUtilsPluginimplementsRouterUtilsPlugin.initProcedureOptionsto apply meta as the base layer mergeProcedureUtilsOptionsandmergeProcedureUtilsModifier— centralized option merging that concatenates interceptors (meta → global → scoped) and composes modifier functions (base applied first), replacing the ad-hoc inline spread-merging increateRouterUtilsInternal- Enhanced
isProcedureUtilsOptions— moved fromrouter-utils.tstoprocedure-utils.tswith stricter validation (interceptor-element function checks, modifier-key plain-object checks) and constant key arrays - Router utils refactor —
createRouterUtilsInternalnow usesmergeProcedureUtilsOptionsfor global→scoped composition, deduplicating the merging logic - Docs — new contract options plugin section in
pinia-colada.mdwith a warning about contract types being reference-only
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ocument optimistic updates via contract meta
There was a problem hiding this comment.
Reviewed changes — adds UseMutationGlobalContext to UseMutationFnContext so augmented global values are typed inside mutation interceptors, and documents the optimistic-update pattern via contract meta and global onMutate.
UseMutationFnContextincludesUseMutationGlobalContext— switched the source type fromUseMutationOptions['mutation']'s context (which only carries localonMutatecontext, effectivelyanywith the<any, any>generics) toUseMutationOptionsGlobal['onSuccess']'s context (which intersectsUseMutationContextCommon & UseMutationGlobalContext). Module augmentations onUseMutationGlobalContextnow flow through to mutation interceptorfnContext.- Docs: optimistic updates via contract meta — new collapsible section in
pinia-colada.mdshowing how to augmentUseMutationGlobalContext, provide runtime values (router utils, query cache) through a globalonMutatehook, and use them in contract-meta mutation interceptors for optimistic updates with rollback.
ℹ️ No new issues from the incremental changes. The prior finding about
isProcedureUtilsOptionsrejecting function modifiers is still unaddressed — see the open thread for details.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
6960752 to
6ab745e
Compare
There was a problem hiding this comment.
Reviewed changes — added a runtime test validating the optimistic-update-through-contract-meta pattern from the docs.
- New
meta.test.tsx— end-to-end test mount using Vue, Pinia Colada,ContractOptionsUtilsPlugin, and a globalonMutatethat injects router utils and a query cache intoUseMutationGlobalContext. Verifies optimistic update, rollback on error,invalidateQueriesrefetch, and a successful mutation sequence.
ℹ️ No new issues from the incremental changes. The test is thorough and passes. The prior finding about
isProcedureUtilsOptionsrejecting function modifiers is still unaddressed — see the open thread.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — adds undefined reset semantics to mergeProcedureUtilsOptions, tightens the merger API, and moves composition tests to the right module.
mergeProcedureUtilsOptionssupports explicitundefinedreset — a key set toundefinedin the override clears the base value instead of merging. The implementation handles this cleanly by relying on the initial{ ...base, ...override }spread and only applying interceptor concatenation or modifier composition when both sides have truthy values.mergeProcedureUtilsModifiersignature tightened — both parameters are now required (not| undefined), matching the caller which only invokes when both are defined.- Composition tests moved from
meta.test.tstoprocedure-utils.test.ts— tests now exercisemergeProcedureUtilsOptionsdirectly rather than going through the meta layer, which is the right home. emptyInterceptorsremoved from router-utils tests — the new merge doesn't carry forward empty interceptor arrays, so test expectations no longer include them.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Summary
Port of #1705 to
@orpc/pinia-colada. Define base Pinia Colada options and interceptors directly on a procedure contract viapiniaColada, and apply them automatically with the newContractOptionsUtilsPlugin.piniaColadainfers input, output, and error types from the contract, supports all procedure utils options (keys, options, interceptors), and merges when applied multiple timesContractOptionsUtilsPluginapplies meta options as the base layer: utils level options override them and utils interceptors run after meta interceptorsundefinedresets the value from lower layersgetPiniaColadaMetareads the stored options for custom integrationsUseMutationFnContextnow matches the runtime merged mutation context, so values provided by a globalonMutateare typed inside mutation interceptors viaUseMutationContextCommonaugmentationonMutatehook for optimistic updates