Skip to content

Feat/services api#27

Open
codewizdave wants to merge 13 commits into
mainfrom
feat/services-api
Open

Feat/services api#27
codewizdave wants to merge 13 commits into
mainfrom
feat/services-api

Conversation

@codewizdave
Copy link
Copy Markdown
Member

No description provided.

codewizdave and others added 3 commits April 27, 2026 11:34
The manual installation guide was removed as it's no longer needed
or has been superseded by other documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Removes the old router-based API (createAPI, createPublicAPI, d.router)
and replaces it with a simpler services-based approach using query(),
mutation(), bind(), and defineServices().

This is a complete rewrite of the server package's public API:
- query() and mutation() create typed service handlers
- bind() attaches context to a service
- defineServices() creates a local API proxy with bound services
- Services are composable and simpler than the router model

Old files removed: api factory, router builder, all procedures,
middleware, hooks, events system, and associated tests.

New files added: services module (query, mutation, bind, api),
new types, and services test.

BREAKING CHANGE: The router-based API is removed. Migrate to
services-based approach using defineServices().

Co-Authored-By: martyy-code <nesalia.inc@gmail.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drpc-basic-next Error Error May 7, 2026 2:31pm
drpc-web Error Error May 7, 2026 2:31pm

When a service has no args (TArgs = {}), allow calling it without
passing {}. Previously required api.service({}), now works with
api.service().

The fix is in api.ts where the proxy handler checks if args is
undefined or empty object and conditionally calls bound.call()
with or without args.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Service types (ServiceConfig, ServiceInternal, BoundService, etc.)
are now in src/services/types.ts. Root types.ts re-exports them
for backward compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use inline type specifiers in imports
- Remove unused TCtx type parameter from LocalAPI
- Add targeted eslint-disable for {} in conditional types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This avoids the @typescript-eslint/no-empty-object-type lint warning
while maintaining the same semantics for detecting empty args.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1. Add validation using StandardSchemaV1's validate method
2. Unify query/mutation via createProcedure (DRY)
3. Memoize bound services in defineServices proxy
4. Store _args explicitly in ServiceInternal to avoid Parameters extraction
5. Remove redundant bind.ts (now in createProcedure)
6. Export ProcedureKind type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1. Handle async validation (StandardSchemaV1 allows Promise)
2. Return validation issues instead of full error object
3. Extract issues array properly from validation result

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tput directly

Handler now returns Promise<TOutput> - user is free to use Result,
Maybe, or direct values. Validation errors are thrown (not wrapped).

Tests updated to:
- Test validation failures (rejects.toThrow())
- Test handler errors propagation
- Test async validation
- Test edge cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Core changes:
- Handler returns TOutput directly (no Result wrapper) - user is free
- Validation errors throw ValidationError (not returned in Result)
- Support async validation (await StandardSchemaV1 validate)
- Support sync handlers (TOutput | Promise<TOutput>)
- ValidationError class with issues array for better error handling
- Use transformed value from schema if available

Types:
- BoundService now returns Promise<Awaited<TOutput>>
- LocalAPI uses ReturnType properly for sync/async handlers
- ValidationError exported for user consumption

Tests (20 total):
- Validation errors with ValidationError checks
- Async validation with Valibot pipeAsync
- Sync handler support
- ValidationError.issues array verification
- Handler error propagation

Examples:
- 01-basic-services: CRUD with query/mutation
- 02-validation: Zod, Valibot, async validation
- 03-no-args-services: services without arguments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
services: { getTime, getDateInfo, createSession },
context: {
getTime: () => new Date(),
sessionId: 'sess_' + Math.random().toString(36).substring(2),
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