@srpc.org/core 0.20.3 → 0.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/dist/shared.d.ts +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @srpc/core
|
|
1
|
+
# @srpc.org/core
|
|
2
2
|
|
|
3
3
|
A lightweight, type-safe RPC framework for TypeScript with automatic type inference, multiple runtime support, and zero dependencies.
|
|
4
4
|
|
|
@@ -6,11 +6,11 @@ A lightweight, type-safe RPC framework for TypeScript with automatic type infere
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
# Using JSR (recommended)
|
|
9
|
-
deno add @srpc/core
|
|
10
|
-
npx jsr add @srpc/core
|
|
11
|
-
yarn dlx jsr add @srpc/core
|
|
12
|
-
pnpm dlx jsr add @srpc/core
|
|
13
|
-
bunx jsr add @srpc/core
|
|
9
|
+
deno add @srpc.org/core
|
|
10
|
+
npx jsr add @srpc.org/core
|
|
11
|
+
yarn dlx jsr add @srpc.org/core
|
|
12
|
+
pnpm dlx jsr add @srpc.org/core
|
|
13
|
+
bunx jsr add @srpc.org/core
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Features
|
|
@@ -30,7 +30,7 @@ bunx jsr add @srpc/core
|
|
|
30
30
|
#### Using Fetch API (Recommended for Edge Runtimes)
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
|
-
import { initSRPC, srpcFetchApi } from "@srpc/core/server";
|
|
33
|
+
import { initSRPC, srpcFetchApi } from "@srpc.org/core/server";
|
|
34
34
|
|
|
35
35
|
// Initialize SRPC
|
|
36
36
|
const s = initSRPC();
|
|
@@ -63,8 +63,8 @@ export default {
|
|
|
63
63
|
#### Using Node.js HTTP Server
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
|
-
import { initSRPC } from "@srpc/core/server";
|
|
67
|
-
import { createSrpcServer } from "@srpc/core/server";
|
|
66
|
+
import { initSRPC } from "@srpc.org/core/server";
|
|
67
|
+
import { createSrpcServer } from "@srpc.org/core/server";
|
|
68
68
|
|
|
69
69
|
const s = initSRPC();
|
|
70
70
|
|
|
@@ -90,7 +90,7 @@ server.listen(3000, () => {
|
|
|
90
90
|
### Client Setup
|
|
91
91
|
|
|
92
92
|
```typescript
|
|
93
|
-
import { createSRPCClient } from "@srpc/core/client";
|
|
93
|
+
import { createSRPCClient } from "@srpc.org/core/client";
|
|
94
94
|
import type { AppRouter } from "./server";
|
|
95
95
|
|
|
96
96
|
// Create type-safe client
|
|
@@ -110,7 +110,7 @@ const user = await client.getUser(1); // Type: { id: number, name: string, email
|
|
|
110
110
|
Organize your procedures into logical groups:
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
import { initSRPC } from "@srpc/core/server";
|
|
113
|
+
import { initSRPC } from "@srpc.org/core/server";
|
|
114
114
|
|
|
115
115
|
const s = initSRPC();
|
|
116
116
|
|
|
@@ -151,7 +151,7 @@ const appRouter = s.router({
|
|
|
151
151
|
Add context (authentication, database connections, etc.) to your procedures:
|
|
152
152
|
|
|
153
153
|
```typescript
|
|
154
|
-
import { initSRPC, srpcFetchApi } from "@srpc/core/server";
|
|
154
|
+
import { initSRPC, srpcFetchApi } from "@srpc.org/core/server";
|
|
155
155
|
|
|
156
156
|
// Define your context type
|
|
157
157
|
type Context = {
|
|
@@ -189,7 +189,7 @@ const { fetch: handleRequest } = srpcFetchApi({
|
|
|
189
189
|
Use `SRPCError` for proper HTTP status code mapping:
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
|
-
import { initSRPC } from "@srpc/core/server";
|
|
192
|
+
import { initSRPC } from "@srpc.org/core/server";
|
|
193
193
|
import { SRPCError } from "@srpc.org/core";
|
|
194
194
|
|
|
195
195
|
const s = initSRPC();
|
|
@@ -227,8 +227,8 @@ try {
|
|
|
227
227
|
Use custom serializers for complex data types:
|
|
228
228
|
|
|
229
229
|
```typescript
|
|
230
|
-
import { createSRPCClient } from "@srpc/core/client";
|
|
231
|
-
import type { Serializer } from "@srpc/core/shared";
|
|
230
|
+
import { createSRPCClient } from "@srpc.org/core/client";
|
|
231
|
+
import type { Serializer } from "@srpc.org/core/shared";
|
|
232
232
|
|
|
233
233
|
// Example: Using superjson for Date, Map, Set support
|
|
234
234
|
import superjson from "superjson";
|
|
@@ -273,7 +273,7 @@ type GetUserOutput = RouterOutputs["getUser"]; // { id: number, name: string, em
|
|
|
273
273
|
Call procedures directly on the server without HTTP:
|
|
274
274
|
|
|
275
275
|
```typescript
|
|
276
|
-
import { createSRPCCaller } from "@srpc/core/server";
|
|
276
|
+
import { createSRPCCaller } from "@srpc.org/core/server";
|
|
277
277
|
import { appRouter } from "./router";
|
|
278
278
|
|
|
279
279
|
const caller = createSRPCCaller({
|
package/dist/client.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ declare class SRPC<TContext, TRoutes extends Routes<TContext> = {}> {
|
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```typescript
|
|
31
|
-
* import { createSRPCClient } from "@srpc/core/client";
|
|
31
|
+
* import { createSRPCClient } from "@srpc.org/core/client";
|
|
32
32
|
* import type { AppRouter } from "./server";
|
|
33
33
|
*
|
|
34
34
|
* const client = createSRPCClient<AppRouter>({
|
|
@@ -91,7 +91,7 @@ type SRPCClientOptions = {
|
|
|
91
91
|
*
|
|
92
92
|
* @example Basic usage
|
|
93
93
|
* ```typescript
|
|
94
|
-
* import { createSRPCClient } from "@srpc/core/client";
|
|
94
|
+
* import { createSRPCClient } from "@srpc.org/core/client";
|
|
95
95
|
* import type { AppRouter } from "./server";
|
|
96
96
|
*
|
|
97
97
|
* const client = createSRPCClient<AppRouter>({
|
package/dist/client.js
CHANGED
|
@@ -82,7 +82,7 @@ function createInnerProxy(callback, path, memo) {
|
|
|
82
82
|
*
|
|
83
83
|
* @example Basic usage
|
|
84
84
|
* ```typescript
|
|
85
|
-
* import { createSRPCClient } from "@srpc/core/client";
|
|
85
|
+
* import { createSRPCClient } from "@srpc.org/core/client";
|
|
86
86
|
* import type { AppRouter } from "./server";
|
|
87
87
|
*
|
|
88
88
|
* const client = createSRPCClient<AppRouter>({
|
package/dist/server.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare const srpcFetchApi: <TRouter extends AnySRPC>({ router, endpoint, create
|
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
44
|
-
* import { initSRPC, srpcFetchApi } from "@srpc/core/server";
|
|
44
|
+
* import { initSRPC, srpcFetchApi } from "@srpc.org/core/server";
|
|
45
45
|
*
|
|
46
46
|
* // Initialize and create router
|
|
47
47
|
* const s = initSRPC();
|
|
@@ -76,7 +76,7 @@ declare const srpcFetchApi: <TRouter extends AnySRPC>({ router, endpoint, create
|
|
|
76
76
|
*
|
|
77
77
|
* @example Basic usage
|
|
78
78
|
* ```typescript
|
|
79
|
-
* import { createSRPCCaller, initSRPC } from "@srpc/core/server";
|
|
79
|
+
* import { createSRPCCaller, initSRPC } from "@srpc.org/core/server";
|
|
80
80
|
*
|
|
81
81
|
* const s = initSRPC();
|
|
82
82
|
* const appRouter = s.router({
|
package/dist/server.js
CHANGED
|
@@ -189,7 +189,7 @@ const srpcFetchApi = ({ router, endpoint, createContext, transformer: serializer
|
|
|
189
189
|
*
|
|
190
190
|
* @example Basic usage
|
|
191
191
|
* ```typescript
|
|
192
|
-
* import { createSRPCCaller, initSRPC } from "@srpc/core/server";
|
|
192
|
+
* import { createSRPCCaller, initSRPC } from "@srpc.org/core/server";
|
|
193
193
|
*
|
|
194
194
|
* const s = initSRPC();
|
|
195
195
|
* const appRouter = s.router({
|
package/dist/shared.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ declare const createFlatProxy: <TFaux>(callback: (path: string & keyof TFaux) =>
|
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
54
|
* ```typescript
|
|
55
|
-
* import { SRPCError, type InferRouterInputs, type InferRouterOutputs } from "@srpc/core/shared";
|
|
55
|
+
* import { SRPCError, type InferRouterInputs, type InferRouterOutputs } from "@srpc.org/core/shared";
|
|
56
56
|
*
|
|
57
57
|
* // Throw typed errors
|
|
58
58
|
* throw new SRPCError("Not found", "NOT_FOUND");
|
|
@@ -72,7 +72,7 @@ declare const createFlatProxy: <TFaux>(callback: (path: string & keyof TFaux) =>
|
|
|
72
72
|
* @example Using superjson for Date, Map, Set support
|
|
73
73
|
* ```typescript
|
|
74
74
|
* import superjson from "superjson";
|
|
75
|
-
* import type { Serializer } from "@srpc/core/shared";
|
|
75
|
+
* import type { Serializer } from "@srpc.org/core/shared";
|
|
76
76
|
*
|
|
77
77
|
* const customSerializer: Serializer = {
|
|
78
78
|
* serialize: (value) => superjson.stringify(value),
|
|
@@ -203,7 +203,7 @@ declare class SRPCError extends Error {
|
|
|
203
203
|
*
|
|
204
204
|
* @example
|
|
205
205
|
* ```typescript
|
|
206
|
-
* import type { InferProcedureInput } from "@srpc/core/shared";
|
|
206
|
+
* import type { InferProcedureInput } from "@srpc.org/core/shared";
|
|
207
207
|
*
|
|
208
208
|
* type GetUserProcedure = (ctx: Context, id: number) => Promise<User>;
|
|
209
209
|
* type GetUserInput = InferProcedureInput<GetUserProcedure>; // [id: number]
|
|
@@ -222,7 +222,7 @@ type InferProcedureInput<T extends AnyProcedure> = T extends (_ctx: any, ...args
|
|
|
222
222
|
*
|
|
223
223
|
* @example
|
|
224
224
|
* ```typescript
|
|
225
|
-
* import type { ClientProcedure } from "@srpc/core/shared";
|
|
225
|
+
* import type { ClientProcedure } from "@srpc.org/core/shared";
|
|
226
226
|
*
|
|
227
227
|
* // Server procedure
|
|
228
228
|
* type ServerProc = (ctx: Context, id: number) => Promise<User>;
|
|
@@ -242,7 +242,7 @@ type ClientProcedure<T extends AnyProcedure> = (...args: InferProcedureInput<T>)
|
|
|
242
242
|
*
|
|
243
243
|
* @example
|
|
244
244
|
* ```typescript
|
|
245
|
-
* import type { DecoratedProcedureRecord } from "@srpc/core/shared";
|
|
245
|
+
* import type { DecoratedProcedureRecord } from "@srpc.org/core/shared";
|
|
246
246
|
*
|
|
247
247
|
* // Server router
|
|
248
248
|
* const appRouter = s.router({
|
|
@@ -287,7 +287,7 @@ type InferRPCFromRouter<TRouter extends AnySRPC> = DecoratedProcedureRecord<TRou
|
|
|
287
287
|
*
|
|
288
288
|
* @example
|
|
289
289
|
* ```typescript
|
|
290
|
-
* import type { DecoratedProcedureOutputs } from "@srpc/core/shared";
|
|
290
|
+
* import type { DecoratedProcedureOutputs } from "@srpc.org/core/shared";
|
|
291
291
|
*
|
|
292
292
|
* const appRouter = s.router({
|
|
293
293
|
* getUser: async (ctx, id: number) => ({ id, name: "John" }),
|
|
@@ -340,7 +340,7 @@ type InferRouterOutputs<TRouter extends AnySRPC> = DecoratedProcedureOutputs<TRo
|
|
|
340
340
|
*
|
|
341
341
|
* @example
|
|
342
342
|
* ```typescript
|
|
343
|
-
* import type { DecoratedProcedureInputs } from "@srpc/core/shared";
|
|
343
|
+
* import type { DecoratedProcedureInputs } from "@srpc.org/core/shared";
|
|
344
344
|
*
|
|
345
345
|
* const appRouter = s.router({
|
|
346
346
|
* getUser: async (ctx, id: number) => ({ id, name: "John" }),
|