@evjs/runtime 0.0.1-rc.2 → 0.0.1-rc.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/AGENT.md +8 -8
- package/README.md +96 -40
- package/esm/client/create-app.d.ts +5 -0
- package/esm/client/create-app.d.ts.map +1 -1
- package/esm/client/create-app.js +5 -1
- package/esm/client/create-app.js.map +1 -1
- package/esm/client/index.d.ts +8 -3
- package/esm/client/index.d.ts.map +1 -1
- package/esm/client/index.js +5 -3
- package/esm/client/index.js.map +1 -1
- package/esm/client/query.d.ts +19 -5
- package/esm/client/query.d.ts.map +1 -1
- package/esm/client/query.js +52 -14
- package/esm/client/query.js.map +1 -1
- package/esm/client/transport.d.ts +11 -3
- package/esm/client/transport.d.ts.map +1 -1
- package/esm/client/transport.js +36 -12
- package/esm/client/transport.js.map +1 -1
- package/esm/codec.d.ts +31 -0
- package/esm/codec.d.ts.map +1 -0
- package/esm/codec.js +7 -0
- package/esm/codec.js.map +1 -0
- package/esm/constants.d.ts +6 -2
- package/esm/constants.d.ts.map +1 -1
- package/esm/constants.js +6 -2
- package/esm/constants.js.map +1 -1
- package/esm/errors.d.ts +37 -0
- package/esm/errors.d.ts.map +1 -0
- package/esm/errors.js +45 -0
- package/esm/errors.js.map +1 -0
- package/esm/serializer.d.ts +31 -0
- package/esm/serializer.d.ts.map +1 -0
- package/esm/serializer.js +7 -0
- package/esm/serializer.js.map +1 -0
- package/esm/server/app.d.ts +7 -5
- package/esm/server/app.d.ts.map +1 -1
- package/esm/server/app.js +7 -10
- package/esm/server/app.js.map +1 -1
- package/esm/server/dispatch.d.ts +71 -0
- package/esm/server/dispatch.d.ts.map +1 -0
- package/esm/server/dispatch.js +80 -0
- package/esm/server/dispatch.js.map +1 -0
- package/esm/server/environments/ecma.d.ts +2 -2
- package/esm/server/environments/ecma.d.ts.map +1 -1
- package/esm/server/environments/ecma.js +2 -2
- package/esm/server/environments/ecma.js.map +1 -1
- package/esm/server/environments/node.d.ts +2 -3
- package/esm/server/environments/node.d.ts.map +1 -1
- package/esm/server/environments/node.js +4 -5
- package/esm/server/environments/node.js.map +1 -1
- package/esm/server/handler.d.ts +12 -8
- package/esm/server/handler.d.ts.map +1 -1
- package/esm/server/handler.js +25 -28
- package/esm/server/handler.js.map +1 -1
- package/esm/server/index.d.ts +7 -1
- package/esm/server/index.d.ts.map +1 -1
- package/esm/server/index.js +4 -1
- package/esm/server/index.js.map +1 -1
- package/esm/server/register.d.ts +2 -2
- package/esm/server/register.js +2 -2
- package/package.json +1 -1
package/AGENT.md
CHANGED
|
@@ -51,28 +51,28 @@ const usersRoute = createRoute({
|
|
|
51
51
|
|
|
52
52
|
### Transport
|
|
53
53
|
```tsx
|
|
54
|
-
import {
|
|
54
|
+
import { initTransport } from "@evjs/runtime/client";
|
|
55
55
|
|
|
56
56
|
// Simple: custom base URL and endpoint path
|
|
57
|
-
|
|
57
|
+
initTransport({
|
|
58
58
|
baseUrl: "https://api.example.com",
|
|
59
|
-
endpoint: "/server-function", // default: "/api/
|
|
59
|
+
endpoint: "/server-function", // default: "/api/fn"
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// Advanced: fully custom transport
|
|
63
|
-
|
|
63
|
+
initTransport({ transport: { send: async (fnId, args) => { /* custom */ } } });
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
## Server API (`@evjs/runtime/server`)
|
|
67
67
|
|
|
68
|
-
- `createApp(options?)` — Create Hono app with
|
|
69
|
-
- `
|
|
68
|
+
- `createApp(options?)` — Create Hono app with server function handler. Options: `{ endpoint?: string, port?: number }`. Default endpoint path: `/api/fn`.
|
|
69
|
+
- `serve(app, { port?, host? })` — Start on Node.js (default port 3001).
|
|
70
70
|
- `registerServerFn(fnId, fn)` — Register server function (called by build-tools).
|
|
71
|
-
- `
|
|
71
|
+
- `createHandler()` — Standalone Hono server function handler.
|
|
72
72
|
|
|
73
73
|
## ECMA Adapter (`@evjs/runtime/server/ecma`)
|
|
74
74
|
|
|
75
|
-
- `
|
|
75
|
+
- `createFetchHandler(app)` — Wraps a Hono app for deployment to Deno, Bun, or any Fetch-compatible runtime.
|
|
76
76
|
|
|
77
77
|
## Server Functions
|
|
78
78
|
Files must start with `"use server";`, use named async exports, and end in `.server.ts`.
|
package/README.md
CHANGED
|
@@ -19,7 +19,9 @@ npm install @evjs/runtime
|
|
|
19
19
|
| `mutation(fn)` | Universal mutation proxy for server functions |
|
|
20
20
|
| `createQueryProxy(module)` | Module-level query proxy |
|
|
21
21
|
| `createMutationProxy(module)` | Module-level mutation proxy |
|
|
22
|
-
| `
|
|
22
|
+
| `initTransport` | One-time transport configuration (endpoint, custom transport, codec) |
|
|
23
|
+
| `ServerFunctionError` | Structured error class for server function failures |
|
|
24
|
+
| `jsonCodec` | Default JSON codec |
|
|
23
25
|
| `createRootRoute`, `createRoute`, `Link`, `Outlet`, ... | Re-exports from `@tanstack/react-router` |
|
|
24
26
|
| `useQuery`, `useMutation`, `useQueryClient`, ... | Re-exports from `@tanstack/react-query` |
|
|
25
27
|
|
|
@@ -27,16 +29,25 @@ npm install @evjs/runtime
|
|
|
27
29
|
|
|
28
30
|
| Export | Description |
|
|
29
31
|
|--------|-------------|
|
|
30
|
-
| `createApp` | Create a Hono app with
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
32
|
+
| `createApp` | Create a Hono app with server function handler |
|
|
33
|
+
| `createHandler` | Standalone Hono sub-app for server function dispatch |
|
|
34
|
+
| `dispatch` | Protocol-agnostic dispatcher for custom transports (WebSocket, IPC) |
|
|
35
|
+
| `registerMiddleware` | Register middleware for all server function calls |
|
|
36
|
+
| `registerServerFn` | Register a server function in the registry |
|
|
37
|
+
| `ServerError` | Throwable error with structured data and custom status |
|
|
38
|
+
| `jsonCodec` | Default JSON codec |
|
|
39
|
+
|
|
40
|
+
### `@evjs/runtime/server/node`
|
|
41
|
+
|
|
42
|
+
| Export | Description |
|
|
43
|
+
|--------|-------------|
|
|
44
|
+
| `serve` | Start the app on Node.js (default port 3001) |
|
|
34
45
|
|
|
35
46
|
### `@evjs/runtime/server/ecma`
|
|
36
47
|
|
|
37
48
|
| Export | Description |
|
|
38
49
|
|--------|-------------|
|
|
39
|
-
| `
|
|
50
|
+
| `createFetchHandler` | Wrap Hono app for Deno, Bun, or any Fetch-compatible runtime |
|
|
40
51
|
|
|
41
52
|
## Usage
|
|
42
53
|
|
|
@@ -47,8 +58,10 @@ import { createApp, createRootRoute, query, mutation } from "@evjs/runtime/clien
|
|
|
47
58
|
import { getUsers, createUser } from "./api/users.server";
|
|
48
59
|
|
|
49
60
|
function Users() {
|
|
50
|
-
const { data } = query(getUsers).useQuery(
|
|
51
|
-
const { mutate } = mutation(createUser).useMutation(
|
|
61
|
+
const { data } = query(getUsers).useQuery();
|
|
62
|
+
const { mutate } = mutation(createUser).useMutation({
|
|
63
|
+
invalidates: [getUsers], // auto-invalidate on success
|
|
64
|
+
});
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
const rootRoute = createRootRoute({ component: Root });
|
|
@@ -58,58 +71,101 @@ app.render("#app");
|
|
|
58
71
|
|
|
59
72
|
### Server
|
|
60
73
|
|
|
61
|
-
The server app is a runtime-agnostic Hono instance. Use a Runner to start it:
|
|
62
|
-
|
|
63
74
|
```ts
|
|
64
|
-
import { createApp
|
|
75
|
+
import { createApp } from "@evjs/runtime/server";
|
|
76
|
+
import { serve } from "@evjs/runtime/server/node";
|
|
65
77
|
|
|
66
78
|
const app = createApp();
|
|
67
|
-
|
|
79
|
+
serve(app, { port: 3001 });
|
|
68
80
|
```
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### Custom Endpoint
|
|
82
|
+
### Custom Transport
|
|
73
83
|
|
|
74
84
|
```ts
|
|
75
|
-
import {
|
|
85
|
+
import { initTransport } from "@evjs/runtime/client";
|
|
76
86
|
|
|
77
|
-
|
|
87
|
+
// Custom endpoint
|
|
88
|
+
initTransport({
|
|
78
89
|
baseUrl: "https://api.example.com",
|
|
79
|
-
endpoint: "/server-function", // default: "/api/
|
|
90
|
+
endpoint: "/server-function", // default: "/api/fn"
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Custom protocol (e.g. WebSocket)
|
|
94
|
+
initTransport({
|
|
95
|
+
transport: {
|
|
96
|
+
send: async (fnId, args) => { /* your protocol */ },
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Custom serialization
|
|
101
|
+
initTransport({
|
|
102
|
+
codec: { serialize: msgpack.encode, deserialize: msgpack.decode, contentType: "application/msgpack" },
|
|
80
103
|
});
|
|
81
104
|
```
|
|
82
105
|
|
|
83
|
-
###
|
|
106
|
+
### Server Middleware
|
|
84
107
|
|
|
85
108
|
```ts
|
|
86
|
-
import {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
109
|
+
import { registerMiddleware } from "@evjs/runtime/server";
|
|
110
|
+
|
|
111
|
+
registerMiddleware(async (ctx, next) => {
|
|
112
|
+
console.log(`Calling ${ctx.fnId}`);
|
|
113
|
+
const start = Date.now();
|
|
114
|
+
const result = await next();
|
|
115
|
+
console.log(`${ctx.fnId} took ${Date.now() - start}ms`);
|
|
116
|
+
return result;
|
|
95
117
|
});
|
|
96
118
|
```
|
|
97
119
|
|
|
120
|
+
### Typed Errors
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { ServerError } from "@evjs/runtime/server";
|
|
124
|
+
|
|
125
|
+
export async function getUser(id: string) {
|
|
126
|
+
const user = db.find(id);
|
|
127
|
+
if (!user) throw new ServerError("User not found", { status: 404, data: { id } });
|
|
128
|
+
return user;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
98
132
|
### Query Proxy Patterns
|
|
99
133
|
|
|
100
134
|
```tsx
|
|
101
|
-
//
|
|
102
|
-
const { data } = query(getUsers).useQuery(
|
|
135
|
+
// Direct wrapper
|
|
136
|
+
const { data } = query(getUsers).useQuery();
|
|
103
137
|
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// C. queryOptions (for prefetching, etc.)
|
|
113
|
-
const options = query(getUsers).queryOptions([id]);
|
|
138
|
+
// With args
|
|
139
|
+
const { data } = query(getUser).useQuery(userId);
|
|
140
|
+
|
|
141
|
+
// Query invalidation
|
|
142
|
+
query(getUsers).invalidate();
|
|
143
|
+
|
|
144
|
+
// queryOptions (for prefetching)
|
|
145
|
+
const options = query(getUsers).queryOptions();
|
|
114
146
|
queryClient.prefetchQuery(options);
|
|
147
|
+
|
|
148
|
+
// Module proxy
|
|
149
|
+
import * as UsersAPI from "./api/users.server";
|
|
150
|
+
const api = createQueryProxy(UsersAPI);
|
|
151
|
+
const { data } = api.getUsers.useQuery();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Custom Transport (WebSocket)
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { initTransport } from "@evjs/runtime/client";
|
|
158
|
+
|
|
159
|
+
initTransport({
|
|
160
|
+
transport: {
|
|
161
|
+
send: async (fnId, args) => {
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
ws.send(JSON.stringify({ id: ++reqId, fnId, args }));
|
|
164
|
+
pending.set(reqId, { resolve, reject });
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
115
169
|
```
|
|
170
|
+
|
|
171
|
+
See [`examples/websocket-fns`](../../examples/websocket-fns) for a full working example.
|
|
@@ -14,6 +14,11 @@ export interface CreateAppOptions<TRouteTree extends AnyRoute> {
|
|
|
14
14
|
* Optional configuration for the TanStack Query Client.
|
|
15
15
|
*/
|
|
16
16
|
queryClientConfig?: QueryClientConfig;
|
|
17
|
+
/**
|
|
18
|
+
* server function endpoint path. When provided, automatically configures the transport.
|
|
19
|
+
* Defaults to `/api/fn` if not specified.
|
|
20
|
+
*/
|
|
21
|
+
endpoint?: string;
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* An initialized ev application instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/client/create-app.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/client/create-app.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKlE;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,UAAU,SAAS,QAAQ;IAC3D,uEAAuE;IACvE,SAAS,EAAE,UAAU,CAAC;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,IAAI,CAClB,UAAU,CAAC,cAAc,wBAAwB,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EACnE,WAAW,CACZ,CAAC;IACF;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,oCAAoC;IACpC,MAAM,EAAE,SAAS,CAAC;IAClB,0CAA0C;IAC1C,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;CAC/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,UAAU,SAAS,QAAQ,EACnD,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC,GACpC,GAAG,CAoCL"}
|
package/esm/client/create-app.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { QueryClient, QueryClientProvider, } from "@tanstack/react-query";
|
|
3
3
|
import { createRouter, RouterProvider } from "@tanstack/react-router";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { initTransport } from "./transport";
|
|
5
6
|
/**
|
|
6
7
|
* Create a new ev application instance.
|
|
7
8
|
*
|
|
@@ -18,7 +19,10 @@ import { createRoot } from "react-dom/client";
|
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
export function createApp(options) {
|
|
21
|
-
const { routeTree, routerOptions, queryClientConfig } = options;
|
|
22
|
+
const { routeTree, routerOptions, queryClientConfig, endpoint } = options;
|
|
23
|
+
if (endpoint) {
|
|
24
|
+
initTransport({ endpoint: endpoint });
|
|
25
|
+
}
|
|
22
26
|
const queryClient = new QueryClient(queryClientConfig);
|
|
23
27
|
const router = createRouter({
|
|
24
28
|
...routerOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../../src/client/create-app.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EAEX,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../../src/client/create-app.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EAEX,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE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finiteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult, } from "@tanstack/react-query";
|
|
5
5
|
export { keepPreviousData, QueryClient, QueryClientProvider, useInfiniteQuery, useIsFetching, useMutation, usePrefetchQuery, useQuery, useQueryClient, useSuspenseQuery, } from "@tanstack/react-query";
|
|
6
|
+
export type { Codec } from "../codec";
|
|
7
|
+
export { jsonCodec } from "../codec";
|
|
8
|
+
export { ServerFunctionError } from "../errors";
|
|
6
9
|
export type { AppRouteContext } from "./context";
|
|
7
10
|
export { createAppRootRoute } from "./context";
|
|
8
11
|
export type { App, CreateAppOptions } from "./create-app";
|
|
9
12
|
export { createApp } from "./create-app";
|
|
10
|
-
export
|
|
11
|
-
export
|
|
13
|
+
export type { MutationProxy, MutationProxyHandler, QueryProxy, QueryProxyHandler, ServerFunction, } from "./query";
|
|
14
|
+
export { createMutationProxy, createQueryProxy, mutation, query, } from "./query";
|
|
15
|
+
export type { AnyRootRoute, AnyRoute, AnyRouteMatch, AnyRouter, ErrorComponentProps, ErrorRouteComponent, LinkOptions, LinkProps, NavigateOptions, NotFoundError, NotFoundRouteComponent, NotFoundRouteProps, RegisteredRouter, RouteComponent, RouteMatch, RouterOptions, RouterState, SearchSchemaInput, } from "./route";
|
|
16
|
+
export { CatchBoundary, CatchNotFound, createLink, createRootRoute, createRootRouteWithContext, createRoute, createRouteMask, createRouter, DefaultGlobalNotFound, ErrorComponent, getRouteApi, isNotFound, isRedirect, Link, lazyRouteComponent, linkOptions, Navigate, notFound, Outlet, RouterProvider, redirect, useBlocker, useCanGoBack, useLoaderData, useLoaderDeps, useLocation, useMatch, useMatchRoute, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch, } from "./route";
|
|
12
17
|
export type { RequestContext, ServerTransport, TransportOptions, } from "./transport";
|
|
13
|
-
export {
|
|
18
|
+
export { getFnName, initTransport } from "./transport";
|
|
14
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,iBAAiB,EACjB,QAAQ,EACR,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,YAAY,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,cAAc,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,iBAAiB,EACjB,QAAQ,EACR,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,mB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"}
|
package/esm/client/index.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Client-side runtime utilities.
|
|
3
3
|
*/
|
|
4
4
|
export { keepPreviousData, QueryClient, QueryClientProvider, useInfiniteQuery, useIsFetching, useMutation, usePrefetchQuery, useQuery, useQueryClient, useSuspenseQuery, } from "@tanstack/react-query";
|
|
5
|
+
export { jsonCodec } from "../codec";
|
|
6
|
+
export { ServerFunctionError } from "../errors";
|
|
5
7
|
export { createAppRootRoute } from "./context";
|
|
6
8
|
export { createApp } from "./create-app";
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
9
|
+
export { createMutationProxy, createQueryProxy, mutation, query, } from "./query";
|
|
10
|
+
export { CatchBoundary, CatchNotFound, createLink, createRootRoute, createRootRouteWithContext, createRoute, createRouteMask, createRouter, DefaultGlobalNotFound, ErrorComponent, getRouteApi, isNotFound, isRedirect, Link, lazyRouteComponent, linkOptions, Navigate, notFound, Outlet, RouterProvider, redirect, useBlocker, useCanGoBack, useLoaderData, useLoaderDeps, useLocation, useMatch, useMatchRoute, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch, } from "./route";
|
|
11
|
+
export { getFnName, initTransport } from "./transport";
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
package/esm/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQzC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,QAAQ,EACR,KAAK,GACN,MAAM,SAAS,CAAC;AAqBjB,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,eAAe,EACf,0BAA0B,EAC1B,WAAW,EACX,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,UAAU,EACV,UAAU,EACV,IAAI,EACJ,kBAAkB,EAClB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,cAAc,EACd,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,WAAW,EACX,QAAQ,EACR,aAAa,EACb,WAAW,EACX,SAAS,EACT,eAAe,EACf,SAAS,EACT,cAAc,EACd,SAAS,GACV,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/esm/client/query.d.ts
CHANGED
|
@@ -10,16 +10,27 @@ export interface QueryProxyHandler<TArgs extends unknown[], TResponse> {
|
|
|
10
10
|
/** Call the server function directly. */
|
|
11
11
|
(...args: TArgs): Promise<TResponse>;
|
|
12
12
|
/** Use as a standard TanStack Query. */
|
|
13
|
-
useQuery(args:
|
|
13
|
+
useQuery(...args: [
|
|
14
|
+
...args: TArgs,
|
|
15
|
+
options?: Omit<UseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">
|
|
16
|
+
]): UseQueryResult<TResponse, Error>;
|
|
14
17
|
/** Use as a TanStack Suspense Query. */
|
|
15
|
-
useSuspenseQuery(args:
|
|
18
|
+
useSuspenseQuery(...args: [
|
|
19
|
+
...args: TArgs,
|
|
20
|
+
options?: Omit<UseSuspenseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">
|
|
21
|
+
]): UseSuspenseQueryResult<TResponse, Error>;
|
|
16
22
|
/** Returns standard TanStack Query options. */
|
|
17
|
-
queryOptions(args:
|
|
23
|
+
queryOptions(...args: [
|
|
24
|
+
...args: TArgs,
|
|
25
|
+
options?: Omit<UseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">
|
|
26
|
+
]): UseQueryOptions<TResponse, Error> & {
|
|
18
27
|
queryKey: unknown[];
|
|
19
28
|
queryFn: () => Promise<TResponse>;
|
|
20
29
|
};
|
|
21
30
|
/** Returns the query key for this function and arguments. */
|
|
22
|
-
queryKey(args
|
|
31
|
+
queryKey(...args: TArgs): unknown[];
|
|
32
|
+
/** Invalidate cached queries for this function. */
|
|
33
|
+
invalidate(...args: TArgs): void;
|
|
23
34
|
}
|
|
24
35
|
/**
|
|
25
36
|
* The interface for a single server function's mutation proxy.
|
|
@@ -28,7 +39,10 @@ export interface MutationProxyHandler<TVariables, TResponse> {
|
|
|
28
39
|
/** Call the server function directly. */
|
|
29
40
|
(variables: TVariables): Promise<TResponse>;
|
|
30
41
|
/** Use as a TanStack Mutation. */
|
|
31
|
-
useMutation(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn">
|
|
42
|
+
useMutation(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn"> & {
|
|
43
|
+
/** Server functions whose queries should be invalidated on success. */
|
|
44
|
+
invalidates?: ((...args: unknown[]) => unknown)[];
|
|
45
|
+
}): UseMutationResult<TResponse, Error, TVariables>;
|
|
32
46
|
/** Returns standard TanStack Mutation options. */
|
|
33
47
|
mutationOptions(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn">): UseMutationOptions<TResponse, Error, TVariables> & {
|
|
34
48
|
mutationFn: (variables: TVariables) => Promise<TResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/client/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/client/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAK5B,MAAM,uBAAuB,CAAC;AAG/B;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,SAAS,IAAI,CAC/D,GAAG,IAAI,EAAE,KAAK,KACX,OAAO,CAAC,SAAS,CAAC,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,SAAS;IACnE,yCAAyC;IACzC,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAErC,wCAAwC;IACxC,QAAQ,CACN,GAAG,IAAI,EAAE;QACP,GAAG,IAAI,EAAE,KAAK;QACd,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;KAC1E,GACA,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAEpC,wCAAwC;IACxC,gBAAgB,CACd,GAAG,IAAI,EAAE;Q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C;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAA8B,CAAC,CAAC,UAAU,EAAE,SAAS,EACxE,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,SAAS,CAAC,KACzC,oBAAoB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,GAC/C,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC"}
|
package/esm/client/query.js
CHANGED
|
@@ -1,32 +1,64 @@
|
|
|
1
|
-
import { useMutation, useQuery, useSuspenseQuery, } from "@tanstack/react-query";
|
|
2
|
-
import { getFnId } from "./transport";
|
|
1
|
+
import { useMutation, useQuery, useQueryClient, useSuspenseQuery, } from "@tanstack/react-query";
|
|
2
|
+
import { __ev_call, getFnId } from "./transport";
|
|
3
|
+
function splitArgsAndOptions(rawArgs) {
|
|
4
|
+
const last = rawArgs[rawArgs.length - 1];
|
|
5
|
+
if (rawArgs.length > 0 &&
|
|
6
|
+
last != null &&
|
|
7
|
+
typeof last === "object" &&
|
|
8
|
+
!Array.isArray(last) &&
|
|
9
|
+
// Plain object check — rules out class instances, Dates, etc.
|
|
10
|
+
Object.getPrototypeOf(last) === Object.prototype) {
|
|
11
|
+
return {
|
|
12
|
+
args: rawArgs.slice(0, -1),
|
|
13
|
+
options: last,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return { args: rawArgs };
|
|
17
|
+
}
|
|
3
18
|
function createHandler(fn, path) {
|
|
19
|
+
const fnId = getFnId(fn);
|
|
4
20
|
return {
|
|
5
|
-
useQuery: (
|
|
21
|
+
useQuery: (...rawArgs) => {
|
|
22
|
+
const { args, options } = splitArgsAndOptions(rawArgs);
|
|
6
23
|
return useQuery({
|
|
7
24
|
...options,
|
|
8
|
-
queryKey: [
|
|
9
|
-
queryFn: () =>
|
|
25
|
+
queryKey: [fnId || path.join("."), ...args],
|
|
26
|
+
queryFn: ({ signal }) => __ev_call(fnId || path.join("."), args, { signal }),
|
|
10
27
|
});
|
|
11
28
|
},
|
|
12
|
-
useSuspenseQuery: (
|
|
29
|
+
useSuspenseQuery: (...rawArgs) => {
|
|
30
|
+
const { args, options } = splitArgsAndOptions(rawArgs);
|
|
13
31
|
return useSuspenseQuery({
|
|
14
32
|
...options,
|
|
15
|
-
queryKey: [
|
|
16
|
-
queryFn: () =>
|
|
33
|
+
queryKey: [fnId || path.join("."), ...args],
|
|
34
|
+
queryFn: ({ signal }) => __ev_call(fnId || path.join("."), args, { signal }),
|
|
17
35
|
});
|
|
18
36
|
},
|
|
19
37
|
useMutation: (options) => {
|
|
38
|
+
const queryClient = useQueryClient();
|
|
39
|
+
const { invalidates, ...restOptions } = options ?? {};
|
|
20
40
|
return useMutation({
|
|
21
|
-
...
|
|
41
|
+
...restOptions,
|
|
22
42
|
mutationFn: (variables) => fn(variables),
|
|
43
|
+
onSuccess: (...onSuccessArgs) => {
|
|
44
|
+
if (invalidates) {
|
|
45
|
+
for (const target of invalidates) {
|
|
46
|
+
const targetId = getFnId(target);
|
|
47
|
+
if (targetId) {
|
|
48
|
+
queryClient.invalidateQueries({ queryKey: [targetId] });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
restOptions?.onSuccess?.(...onSuccessArgs);
|
|
53
|
+
},
|
|
23
54
|
});
|
|
24
55
|
},
|
|
25
|
-
queryOptions: (
|
|
56
|
+
queryOptions: (...rawArgs) => {
|
|
57
|
+
const { args, options } = splitArgsAndOptions(rawArgs);
|
|
26
58
|
return {
|
|
27
59
|
...options,
|
|
28
|
-
queryKey: [
|
|
29
|
-
queryFn: () =>
|
|
60
|
+
queryKey: [fnId || path.join("."), ...args],
|
|
61
|
+
queryFn: ({ signal }) => __ev_call(fnId || path.join("."), args, { signal }),
|
|
30
62
|
};
|
|
31
63
|
},
|
|
32
64
|
mutationOptions: (options) => {
|
|
@@ -35,8 +67,14 @@ function createHandler(fn, path) {
|
|
|
35
67
|
mutationFn: (variables) => fn(variables),
|
|
36
68
|
};
|
|
37
69
|
},
|
|
38
|
-
queryKey: (args
|
|
39
|
-
return [
|
|
70
|
+
queryKey: (...args) => {
|
|
71
|
+
return [fnId || path.join("."), ...args];
|
|
72
|
+
},
|
|
73
|
+
invalidate: (...args) => {
|
|
74
|
+
const queryClient = useQueryClient();
|
|
75
|
+
queryClient.invalidateQueries({
|
|
76
|
+
queryKey: [fnId || path.join("."), ...args],
|
|
77
|
+
});
|
|
40
78
|
},
|
|
41
79
|
path: path.join("."),
|
|
42
80
|
};
|
package/esm/client/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/client/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,QAAQ,EACR,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/client/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAuGjD,SAAS,mBAAmB,CAAC,OAAkB;IAI7C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,IACE,OAAO,CAAC,MAAM,GAAG,CAAC;QAClB,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACpB,8DAA8D;QAC9D,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,SAAS,EAChD,CAAC;QACD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,OAAO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AAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC7B,OAAO,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACjC,CAAC;YACD,OAAO,EAAE,CAAC,CAAC,WAAW;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAI,MAAU;IAC5C,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,CAAkB,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAI,MAAU;IAC/C,OAAO,WAAW,CAAC,UAAU,EAAE,MAAM,CAAqB,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAMH,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAGN,CAAC"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* bundle, each exported function is replaced with a stub that calls
|
|
6
6
|
* `__ev_call(fnId, args)`. This module provides that helper.
|
|
7
7
|
*/
|
|
8
|
+
import { type Codec } from "../codec";
|
|
8
9
|
/**
|
|
9
10
|
* Request context passed through server calls.
|
|
10
11
|
* Used during SSR to forward headers/cookies, and in RSC for streaming.
|
|
@@ -35,18 +36,25 @@ export interface ServerTransport {
|
|
|
35
36
|
stream?(fnId: string, args: unknown[], context?: RequestContext): ReadableStream<Uint8Array>;
|
|
36
37
|
}
|
|
37
38
|
export interface TransportOptions {
|
|
38
|
-
/** Base URL for the
|
|
39
|
+
/** Base URL for the server function endpoint. Defaults to the current origin. */
|
|
39
40
|
baseUrl?: string;
|
|
40
|
-
/** Path prefix for the
|
|
41
|
+
/** Path prefix for the server function endpoint. Defaults to `/api/fn`. */
|
|
41
42
|
endpoint?: string;
|
|
42
43
|
/** Custom transport. When provided, `baseUrl` and `endpoint` are ignored. */
|
|
43
44
|
transport?: ServerTransport;
|
|
45
|
+
/** Custom codec. Defaults to JSON. */
|
|
46
|
+
codec?: Codec;
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* Configure the server transport. Call once at app startup if you need to
|
|
47
50
|
* customise the endpoint URL or provide a custom transport.
|
|
48
51
|
*/
|
|
49
|
-
export declare function
|
|
52
|
+
export declare function initTransport(options: TransportOptions): void;
|
|
53
|
+
/**
|
|
54
|
+
* Look up the human-readable export name for a function ID.
|
|
55
|
+
* Falls back to the fnId itself if no name is registered.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getFnName(fnId: string): string;
|
|
50
58
|
/**
|
|
51
59
|
* Look up the internal function ID for a server function stub.
|
|
52
60
|
* Returns undefined if the function is not a registered server function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/client/transport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/client/transport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAa,MAAM,UAAU,CAAC;AAQjD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,oGAAoG;IACpG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,uCAAuC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,IAAI,CACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EAAE,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,MAAM,CAAC,CACL,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EAAE,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,cAAc,CAAC,UAAU,CAA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