@evjs/runtime 0.0.1-alpha.1 → 0.0.1-alpha.10
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 +66 -0
- package/README.md +72 -13
- package/esm/client/context.d.ts +25 -0
- package/esm/client/context.d.ts.map +1 -0
- package/esm/client/context.js +21 -0
- package/esm/client/context.js.map +1 -0
- package/esm/client/create-app.d.ts.map +1 -1
- package/esm/client/create-app.js +1 -0
- package/esm/client/create-app.js.map +1 -1
- package/esm/client/index.d.ts +7 -2
- package/esm/client/index.d.ts.map +1 -1
- package/esm/client/index.js +4 -1
- package/esm/client/index.js.map +1 -1
- package/esm/client/query.d.ts +68 -0
- package/esm/client/query.d.ts.map +1 -0
- package/esm/client/query.js +94 -0
- package/esm/client/query.js.map +1 -0
- package/esm/client/transport.d.ts +55 -0
- package/esm/client/transport.d.ts.map +1 -0
- package/esm/client/transport.js +88 -0
- package/esm/client/transport.js.map +1 -0
- package/esm/constants.d.ts +6 -0
- package/esm/constants.d.ts.map +1 -0
- package/esm/constants.js +6 -0
- package/esm/constants.js.map +1 -0
- package/esm/index.d.ts +3 -4
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +6 -4
- package/esm/index.js.map +1 -1
- package/esm/server/app.d.ts +9 -9
- package/esm/server/app.d.ts.map +1 -1
- package/esm/server/app.js +11 -12
- package/esm/server/app.js.map +1 -1
- package/esm/server/environments/ecma.d.ts +19 -0
- package/esm/server/environments/ecma.d.ts.map +1 -0
- package/esm/server/environments/ecma.js +20 -0
- package/esm/server/environments/ecma.js.map +1 -0
- package/esm/server/environments/node.d.ts +14 -0
- package/esm/server/environments/node.d.ts.map +1 -0
- package/esm/server/environments/node.js +31 -0
- package/esm/server/environments/node.js.map +1 -0
- package/esm/server/handler.d.ts +0 -11
- package/esm/server/handler.d.ts.map +1 -1
- package/esm/server/handler.js +1 -12
- package/esm/server/handler.js.map +1 -1
- package/esm/server/index.d.ts +13 -4
- package/esm/server/index.d.ts.map +1 -1
- package/esm/server/index.js +11 -3
- package/esm/server/index.js.map +1 -1
- package/esm/server/register.d.ts +22 -0
- package/esm/server/register.d.ts.map +1 -0
- package/esm/server/register.js +22 -0
- package/esm/server/register.js.map +1 -0
- package/package.json +33 -5
- package/esm/client/rpc.d.ts +0 -29
- package/esm/client/rpc.d.ts.map +0 -1
- package/esm/client/rpc.js +0 -45
- package/esm/client/rpc.js.map +0 -1
package/AGENT.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @evjs/runtime
|
|
2
|
+
|
|
3
|
+
Core runtime for the ev React framework. Provides client-side routing, data fetching, and server-side handling.
|
|
4
|
+
|
|
5
|
+
## Client API (`@evjs/runtime/client`)
|
|
6
|
+
|
|
7
|
+
### App Bootstrap
|
|
8
|
+
- `createApp({ routeTree, routerOptions?, queryClientConfig? })` — Bootstrap Router + Query + DOM. Injects `queryClient` into router context.
|
|
9
|
+
- `createAppRootRoute(options)` — Create root route with typed `context.queryClient` for route loaders.
|
|
10
|
+
|
|
11
|
+
### Server Function Proxies
|
|
12
|
+
Always use these instead of raw `useQuery`/`useMutation` for server functions:
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { query, mutation, createQueryProxy, createMutationProxy } from "@evjs/runtime/client";
|
|
16
|
+
import { getUsers, createUser } from "./api/users.server";
|
|
17
|
+
|
|
18
|
+
// Direct wrapper
|
|
19
|
+
const { data } = query(getUsers).useQuery([]);
|
|
20
|
+
const { mutate } = mutation(createUser).useMutation();
|
|
21
|
+
|
|
22
|
+
// Module proxy
|
|
23
|
+
const api = { query: createQueryProxy({ getUsers }), mutation: createMutationProxy({ createUser }) };
|
|
24
|
+
api.query.getUsers.useQuery([]);
|
|
25
|
+
|
|
26
|
+
// queryOptions (for loaders, prefetch)
|
|
27
|
+
const opts = query(getUsers).queryOptions([]);
|
|
28
|
+
queryClient.ensureQueryData(opts);
|
|
29
|
+
|
|
30
|
+
// Query key (for invalidation)
|
|
31
|
+
queryClient.invalidateQueries({ queryKey: query(getUsers).queryKey() });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Route Loader Pattern
|
|
35
|
+
```tsx
|
|
36
|
+
const rootRoute = createAppRootRoute({ component: Root });
|
|
37
|
+
const usersRoute = createRoute({
|
|
38
|
+
getParentRoute: () => rootRoute,
|
|
39
|
+
path: "/users",
|
|
40
|
+
loader: ({ context }) =>
|
|
41
|
+
context.queryClient.ensureQueryData(query(getUsers).queryOptions([])),
|
|
42
|
+
component: UsersPage,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Routing (re-exports from @tanstack/react-router)
|
|
47
|
+
`createRootRoute`, `createRoute`, `createRouter`, `Link`, `Outlet`, `Navigate`, `useParams`, `useSearch`, `useNavigate`, `useLocation`, `useMatch`, `useLoaderData`, `redirect`, `notFound`, `lazyRouteComponent`
|
|
48
|
+
|
|
49
|
+
### Data (re-exports from @tanstack/react-query)
|
|
50
|
+
`useQuery`, `useMutation`, `useQueryClient`, `useSuspenseQuery`, `QueryClient`, `QueryClientProvider`
|
|
51
|
+
|
|
52
|
+
### Transport
|
|
53
|
+
```tsx
|
|
54
|
+
import { configureTransport } from "@evjs/runtime/client";
|
|
55
|
+
configureTransport({ transport: { send: async (fnId, args) => { /* custom */ } } });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Server API (`@evjs/runtime/server`)
|
|
59
|
+
|
|
60
|
+
- `createApp(options?)` — Create Hono app with RPC middleware.
|
|
61
|
+
- `runNodeServer(app, { port?, host? })` — Start on Node.js (default port 3001).
|
|
62
|
+
- `registerServerFn(fnId, fn)` — Register server function (called by build-tools).
|
|
63
|
+
- `createRpcMiddleware()` — Standalone Hono RPC sub-app.
|
|
64
|
+
|
|
65
|
+
## Server Functions
|
|
66
|
+
Files must start with `"use server";`, use named async exports, and end in `.server.ts`.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @evjs/runtime
|
|
2
2
|
|
|
3
|
-
Core runtime for the **ev** framework.
|
|
3
|
+
Core runtime for the **ev** framework. Provides client-side routing, data fetching, and server-side handling via Hono.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,32 +8,91 @@ Core runtime for the **ev** framework. It provides isomorphic utilities for clie
|
|
|
8
8
|
npm install @evjs/runtime
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Exports
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
### `@evjs/runtime/client`
|
|
14
|
+
|
|
15
|
+
| Export | Description |
|
|
16
|
+
|--------|-------------|
|
|
17
|
+
| `createApp` | Bootstrap TanStack Router + Query + DOM |
|
|
18
|
+
| `query(fn)` | Universal query proxy for server functions |
|
|
19
|
+
| `mutation(fn)` | Universal mutation proxy for server functions |
|
|
20
|
+
| `createQueryProxy(module)` | Module-level query proxy |
|
|
21
|
+
| `createMutationProxy(module)` | Module-level mutation proxy |
|
|
22
|
+
| `configureTransport` | Set custom transport (fetch, axios, WebSocket) |
|
|
23
|
+
| `createRootRoute`, `createRoute`, `Link`, `Outlet`, ... | Re-exports from `@tanstack/react-router` |
|
|
24
|
+
| `useQuery`, `useMutation`, `useQueryClient`, ... | Re-exports from `@tanstack/react-query` |
|
|
25
|
+
|
|
26
|
+
### `@evjs/runtime/server`
|
|
27
|
+
|
|
28
|
+
| Export | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `createApp` | Create a Hono app with RPC middleware |
|
|
31
|
+
| `runNodeServer` | Start the app on Node.js (default port 3001) |
|
|
32
|
+
| `registerServerFn` | Register a server function in the RPC registry |
|
|
33
|
+
| `createRpcMiddleware` | Standalone Hono sub-app for RPC dispatch |
|
|
17
34
|
|
|
18
35
|
## Usage
|
|
19
36
|
|
|
20
|
-
### Client
|
|
37
|
+
### Client
|
|
21
38
|
|
|
22
39
|
```tsx
|
|
23
|
-
import { createApp, createRootRoute } from "@evjs/runtime";
|
|
40
|
+
import { createApp, createRootRoute, query, mutation } from "@evjs/runtime/client";
|
|
41
|
+
import { getUsers, createUser } from "./api/users.server";
|
|
42
|
+
|
|
43
|
+
function Users() {
|
|
44
|
+
const { data } = query(getUsers).useQuery([]);
|
|
45
|
+
const { mutate } = mutation(createUser).useMutation();
|
|
46
|
+
}
|
|
24
47
|
|
|
25
48
|
const rootRoute = createRootRoute({ component: Root });
|
|
26
49
|
const app = createApp({ routeTree: rootRoute });
|
|
27
|
-
|
|
28
50
|
app.render("#app");
|
|
29
51
|
```
|
|
30
52
|
|
|
31
|
-
### Server
|
|
53
|
+
### Server
|
|
54
|
+
|
|
55
|
+
The server app is a runtime-agnostic Hono instance. Use a Runner to start it:
|
|
32
56
|
|
|
33
57
|
```ts
|
|
34
|
-
import {
|
|
58
|
+
import { createApp, runNodeServer } from "@evjs/runtime/server";
|
|
35
59
|
|
|
36
|
-
|
|
60
|
+
const app = createApp();
|
|
61
|
+
runNodeServer(app, { port: 3001 });
|
|
37
62
|
```
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
In development, `ev dev` with `runner` configured in `EvWebpackPlugin` handles this automatically.
|
|
65
|
+
|
|
66
|
+
### Custom Transport
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { configureTransport } from "@evjs/runtime/client";
|
|
70
|
+
|
|
71
|
+
configureTransport({
|
|
72
|
+
transport: {
|
|
73
|
+
send: async (fnId, args) => {
|
|
74
|
+
const { data } = await axios.post("/api/rpc", { fnId, args });
|
|
75
|
+
return data.result;
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Query Proxy Patterns
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
// A. Direct wrapper (single function)
|
|
85
|
+
const { data } = query(getUsers).useQuery([]);
|
|
86
|
+
|
|
87
|
+
// B. Module proxy (feature-based API)
|
|
88
|
+
import * as UsersAPI from "./api/users.server";
|
|
89
|
+
const users = {
|
|
90
|
+
query: createQueryProxy(UsersAPI),
|
|
91
|
+
mutation: createMutationProxy(UsersAPI),
|
|
92
|
+
};
|
|
93
|
+
users.query.getUsers.useQuery([]);
|
|
94
|
+
|
|
95
|
+
// C. queryOptions (for prefetching, etc.)
|
|
96
|
+
const options = query(getUsers).queryOptions([id]);
|
|
97
|
+
queryClient.prefetchQuery(options);
|
|
98
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { QueryClient } from "@tanstack/react-query";
|
|
2
|
+
/** Default context available in route loaders. */
|
|
3
|
+
export interface AppRouteContext {
|
|
4
|
+
queryClient: QueryClient;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a root route with the app's default context (queryClient).
|
|
8
|
+
*
|
|
9
|
+
* Use this instead of `createRootRoute` when you want typed access
|
|
10
|
+
* to `context.queryClient` in `loader` / `beforeLoad`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const rootRoute = createAppRootRoute({ component: Root });
|
|
15
|
+
*
|
|
16
|
+
* const usersRoute = createRoute({
|
|
17
|
+
* getParentRoute: () => rootRoute,
|
|
18
|
+
* path: "/users",
|
|
19
|
+
* loader: ({ context }) =>
|
|
20
|
+
* context.queryClient.ensureQueryData(query(getUsers).queryOptions([])),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const createAppRootRoute: <TRegister = import("@tanstack/router-core").Register, TRouteContextFn = import("@tanstack/router-core").AnyContext, TBeforeLoadFn = import("@tanstack/router-core").AnyContext, TSearchValidator = undefined, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TSSR = unknown, TServerMiddlewares = unknown>(options?: import("@tanstack/router-core").RootRouteOptions<TRegister, TSearchValidator, AppRouteContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TSSR, TServerMiddlewares, undefined> | undefined) => import("@tanstack/react-router").RootRoute<TRegister, TSearchValidator, AppRouteContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, unknown, unknown, TSSR, TServerMiddlewares, undefined>;
|
|
25
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/client/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,iuBAAgD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRootRouteWithContext } from "@tanstack/react-router";
|
|
2
|
+
/**
|
|
3
|
+
* Create a root route with the app's default context (queryClient).
|
|
4
|
+
*
|
|
5
|
+
* Use this instead of `createRootRoute` when you want typed access
|
|
6
|
+
* to `context.queryClient` in `loader` / `beforeLoad`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const rootRoute = createAppRootRoute({ component: Root });
|
|
11
|
+
*
|
|
12
|
+
* const usersRoute = createRoute({
|
|
13
|
+
* getParentRoute: () => rootRoute,
|
|
14
|
+
* path: "/users",
|
|
15
|
+
* loader: ({ context }) =>
|
|
16
|
+
* context.queryClient.ensureQueryData(query(getUsers).queryOptions([])),
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const createAppRootRoute = createRootRouteWithContext();
|
|
21
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/client/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAOpE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,0BAA0B,EAAmB,CAAC"}
|
|
@@ -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;AAIlE;;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;CACvC;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,
|
|
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;AAIlE;;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;CACvC;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,CAgCL"}
|
package/esm/client/create-app.js
CHANGED
|
@@ -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;AAoC9C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CACvB,OAAqC;IAErC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IAEhE,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,GAAG,aAAa;QAChB,SAAS;
|
|
1
|
+
{"version":3,"file":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
|
* Client-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
+
export type { QueryClientConfig, QueryKey, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult, } from "@tanstack/react-query";
|
|
5
|
+
export { keepPreviousData, QueryClient, QueryClientProvider, useInfiniteQuery, useIsFetching, useMutation, usePrefetchQuery, useQuery, useQueryClient, useSuspenseQuery, } from "@tanstack/react-query";
|
|
6
|
+
export type { AppRouteContext } from "./context";
|
|
7
|
+
export { createAppRootRoute } from "./context";
|
|
4
8
|
export type { App, CreateAppOptions } from "./create-app";
|
|
5
9
|
export { createApp } from "./create-app";
|
|
10
|
+
export * from "./query";
|
|
6
11
|
export * from "./route";
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
12
|
+
export type { RequestContext, ServerTransport, TransportOptions, } from "./transport";
|
|
13
|
+
export { configureTransport } from "./transport";
|
|
9
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
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;AACxB,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/esm/client/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
+
export { keepPreviousData, QueryClient, QueryClientProvider, useInfiniteQuery, useIsFetching, useMutation, usePrefetchQuery, useQuery, useQueryClient, useSuspenseQuery, } from "@tanstack/react-query";
|
|
5
|
+
export { createAppRootRoute } from "./context";
|
|
4
6
|
export { createApp } from "./create-app";
|
|
7
|
+
export * from "./query";
|
|
5
8
|
export * from "./route";
|
|
6
|
-
export {
|
|
9
|
+
export { configureTransport } from "./transport";
|
|
7
10
|
//# 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;
|
|
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;AACzC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAMxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSuspenseQueryOptions, type UseSuspenseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
/**
|
|
3
|
+
* A server function stub as generated by the build-tools loader.
|
|
4
|
+
*/
|
|
5
|
+
export type ServerFunction<TArgs extends unknown[], TResponse> = (...args: TArgs) => Promise<TResponse>;
|
|
6
|
+
/**
|
|
7
|
+
* The interface for a single server function's query proxy.
|
|
8
|
+
*/
|
|
9
|
+
export interface QueryProxyHandler<TArgs extends unknown[], TResponse> {
|
|
10
|
+
/** Call the server function directly. */
|
|
11
|
+
(...args: TArgs): Promise<TResponse>;
|
|
12
|
+
/** Use as a standard TanStack Query. */
|
|
13
|
+
useQuery(args: TArgs, options?: Omit<UseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">): UseQueryResult<TResponse, Error>;
|
|
14
|
+
/** Use as a TanStack Suspense Query. */
|
|
15
|
+
useSuspenseQuery(args: TArgs, options?: Omit<UseSuspenseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">): UseSuspenseQueryResult<TResponse, Error>;
|
|
16
|
+
/** Returns standard TanStack Query options. */
|
|
17
|
+
queryOptions(args: TArgs, options?: Omit<UseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">): UseQueryOptions<TResponse, Error> & {
|
|
18
|
+
queryKey: unknown[];
|
|
19
|
+
queryFn: () => Promise<TResponse>;
|
|
20
|
+
};
|
|
21
|
+
/** Returns the query key for this function and arguments. */
|
|
22
|
+
queryKey(args?: TArgs): unknown[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The interface for a single server function's mutation proxy.
|
|
26
|
+
*/
|
|
27
|
+
export interface MutationProxyHandler<TVariables, TResponse> {
|
|
28
|
+
/** Call the server function directly. */
|
|
29
|
+
(variables: TVariables): Promise<TResponse>;
|
|
30
|
+
/** Use as a TanStack Mutation. */
|
|
31
|
+
useMutation(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn">): UseMutationResult<TResponse, Error, TVariables>;
|
|
32
|
+
/** Returns standard TanStack Mutation options. */
|
|
33
|
+
mutationOptions(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn">): UseMutationOptions<TResponse, Error, TVariables> & {
|
|
34
|
+
mutationFn: (variables: TVariables) => Promise<TResponse>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A recursive proxy that maps property access to server function stubs.
|
|
39
|
+
*/
|
|
40
|
+
export type QueryProxy<TModule> = {
|
|
41
|
+
[K in keyof TModule]: TModule[K] extends ServerFunction<infer TArgs, infer TResponse> ? QueryProxyHandler<TArgs, TResponse> : QueryProxy<TModule[K]>;
|
|
42
|
+
};
|
|
43
|
+
export type MutationProxy<TModule> = {
|
|
44
|
+
[K in keyof TModule]: TModule[K] extends ServerFunction<infer TVars, infer TResponse> ? MutationProxyHandler<TVars, TResponse> : MutationProxy<TModule[K]>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Create a type-safe query proxy for a module or object.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createQueryProxy<T>(source?: T): QueryProxy<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a type-safe mutation proxy for a module or object.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createMutationProxy<T>(source?: T): MutationProxy<T>;
|
|
54
|
+
/**
|
|
55
|
+
* The global query proxy/wrapper.
|
|
56
|
+
* @example
|
|
57
|
+
* const { data } = query(getUsers).useQuery();
|
|
58
|
+
* // or with a typed proxy:
|
|
59
|
+
* const api = createQueryProxy(getUsersModule);
|
|
60
|
+
* const { data } = api.getUsers.useQuery();
|
|
61
|
+
*/
|
|
62
|
+
export declare const query: (<TArgs extends unknown[], TResponse>(fn: ServerFunction<TArgs, TResponse>) => QueryProxyHandler<TArgs, TResponse>) & QueryProxy<Record<string, unknown>>;
|
|
63
|
+
/**
|
|
64
|
+
* The global mutation proxy/wrapper.
|
|
65
|
+
* @example const { mutate } = mutation(createUser).useMutation();
|
|
66
|
+
*/
|
|
67
|
+
export declare const mutation: (<TVariables, TResponse>(fn: (args: TVariables) => Promise<TResponse>) => MutationProxyHandler<TVariables, TResponse>) & MutationProxy<Record<string, unknown>>;
|
|
68
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +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,EAI5B,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,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,GACxE,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAEpC,wCAAwC;IACxC,gBAAgB,CACd,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,IAAI,CACZ,uBAAuB,CAAC,SAAS,EAAE,KAAK,CAAC,EACzC,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";
|
|
2
|
+
import { getFnId } from "./transport";
|
|
3
|
+
function createHandler(fn, path) {
|
|
4
|
+
return {
|
|
5
|
+
useQuery: (args = [], options) => {
|
|
6
|
+
return useQuery({
|
|
7
|
+
...options,
|
|
8
|
+
queryKey: [getFnId(fn) || path.join("."), ...args],
|
|
9
|
+
queryFn: () => fn(...args),
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
useSuspenseQuery: (args = [], options) => {
|
|
13
|
+
return useSuspenseQuery({
|
|
14
|
+
...options,
|
|
15
|
+
queryKey: [getFnId(fn) || path.join("."), ...args],
|
|
16
|
+
queryFn: () => fn(...args),
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
useMutation: (options) => {
|
|
20
|
+
return useMutation({
|
|
21
|
+
...options,
|
|
22
|
+
mutationFn: (variables) => fn(variables),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
queryOptions: (args = [], options) => {
|
|
26
|
+
return {
|
|
27
|
+
...options,
|
|
28
|
+
queryKey: [getFnId(fn) || path.join("."), ...args],
|
|
29
|
+
queryFn: () => fn(...args),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
mutationOptions: (options) => {
|
|
33
|
+
return {
|
|
34
|
+
...options,
|
|
35
|
+
mutationFn: (variables) => fn(variables),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
queryKey: (args = []) => {
|
|
39
|
+
return [getFnId(fn) || path.join("."), ...args];
|
|
40
|
+
},
|
|
41
|
+
path: path.join("."),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createProxy(type, source, path = []) {
|
|
45
|
+
const target = source ?? (() => { });
|
|
46
|
+
return new Proxy(target, {
|
|
47
|
+
get(_target, prop) {
|
|
48
|
+
const newPath = [...path, prop];
|
|
49
|
+
const val = source
|
|
50
|
+
? source[prop]
|
|
51
|
+
: undefined;
|
|
52
|
+
// If we have a source and this is a function, return the handler
|
|
53
|
+
if (typeof val === "function") {
|
|
54
|
+
return createHandler(val, newPath);
|
|
55
|
+
}
|
|
56
|
+
// Otherwise return a nested proxy
|
|
57
|
+
return createProxy(type, val, newPath);
|
|
58
|
+
},
|
|
59
|
+
apply(_target, _thisArg, args) {
|
|
60
|
+
const fn = args[0];
|
|
61
|
+
if (typeof fn === "function") {
|
|
62
|
+
return createHandler(fn, path);
|
|
63
|
+
}
|
|
64
|
+
return fn; // Fallback
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a type-safe query proxy for a module or object.
|
|
70
|
+
*/
|
|
71
|
+
export function createQueryProxy(source) {
|
|
72
|
+
return createProxy("query", source);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a type-safe mutation proxy for a module or object.
|
|
76
|
+
*/
|
|
77
|
+
export function createMutationProxy(source) {
|
|
78
|
+
return createProxy("mutation", source);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The global query proxy/wrapper.
|
|
82
|
+
* @example
|
|
83
|
+
* const { data } = query(getUsers).useQuery();
|
|
84
|
+
* // or with a typed proxy:
|
|
85
|
+
* const api = createQueryProxy(getUsersModule);
|
|
86
|
+
* const { data } = api.getUsers.useQuery();
|
|
87
|
+
*/
|
|
88
|
+
export const query = createProxy("query");
|
|
89
|
+
/**
|
|
90
|
+
* The global mutation proxy/wrapper.
|
|
91
|
+
* @example const { mutate } = mutation(createUser).useMutation();
|
|
92
|
+
*/
|
|
93
|
+
export const mutation = createProxy("mutation");
|
|
94
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +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;AA2FtC,SAAS,aAAa,CAAC,EAAsC,EAAE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ACL,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"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side transport for calling server functions.
|
|
3
|
+
*
|
|
4
|
+
* When the Webpack loader transforms a `"use server"` module for the client
|
|
5
|
+
* bundle, each exported function is replaced with a stub that calls
|
|
6
|
+
* `__ev_call(fnId, args)`. This module provides that helper.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Request context passed through server calls.
|
|
10
|
+
* Used during SSR to forward headers/cookies, and in RSC for streaming.
|
|
11
|
+
*
|
|
12
|
+
* @experimental This interface is reserved for future SSR/RSC support.
|
|
13
|
+
* Do not rely on it in production — the shape may change.
|
|
14
|
+
*/
|
|
15
|
+
export interface RequestContext {
|
|
16
|
+
/** @experimental Request headers to forward (e.g. cookies during SSR). SSR is not yet supported. */
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
/** Signal for aborting the request. */
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Transport interface for client-server communication.
|
|
23
|
+
* Implement this to use a custom request library or protocol.
|
|
24
|
+
*/
|
|
25
|
+
export interface ServerTransport {
|
|
26
|
+
/** Standard request-response call for server functions. */
|
|
27
|
+
send(fnId: string, args: unknown[], context?: RequestContext): Promise<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Streaming call for RSC Flight protocol.
|
|
30
|
+
* Returns a ReadableStream of serialized React elements.
|
|
31
|
+
*
|
|
32
|
+
* @experimental Not yet implemented. Reserved for future RSC support.
|
|
33
|
+
* Do not use — this method signature may change.
|
|
34
|
+
*/
|
|
35
|
+
stream?(fnId: string, args: unknown[], context?: RequestContext): ReadableStream<Uint8Array>;
|
|
36
|
+
}
|
|
37
|
+
export interface TransportOptions {
|
|
38
|
+
/** Base URL for the RPC endpoint. Defaults to the current origin. */
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
/** Path prefix for the RPC endpoint. Defaults to `/api/rpc`. */
|
|
41
|
+
endpoint?: string;
|
|
42
|
+
/** Custom transport. When provided, `baseUrl` and `endpoint` are ignored. */
|
|
43
|
+
transport?: ServerTransport;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configure the server transport. Call once at app startup if you need to
|
|
47
|
+
* customise the endpoint URL or provide a custom transport.
|
|
48
|
+
*/
|
|
49
|
+
export declare function configureTransport(options: TransportOptions): void;
|
|
50
|
+
/**
|
|
51
|
+
* Look up the internal function ID for a server function stub.
|
|
52
|
+
* Returns undefined if the function is not a registered server function.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getFnId(fn: (...args: any[]) => any): string | undefined;
|
|
55
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/client/transport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;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,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAwDD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CASlE;AAiCD;;;GAGG;AAEH,wBAAgB,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,MAAM,GAAG,SAAS,CAEvE"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side transport for calling server functions.
|
|
3
|
+
*
|
|
4
|
+
* When the Webpack loader transforms a `"use server"` module for the client
|
|
5
|
+
* bundle, each exported function is replaced with a stub that calls
|
|
6
|
+
* `__ev_call(fnId, args)`. This module provides that helper.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_RPC_ENDPOINT } from "../constants";
|
|
9
|
+
/**
|
|
10
|
+
* Default fetch-based transport.
|
|
11
|
+
*/
|
|
12
|
+
function createFetchTransport(baseUrl, endpoint) {
|
|
13
|
+
return {
|
|
14
|
+
async send(fnId, args, context) {
|
|
15
|
+
const url = `${baseUrl}${endpoint}`;
|
|
16
|
+
const res = await fetch(url, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
...context?.headers,
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({ fnId, args }),
|
|
23
|
+
signal: context?.signal,
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const text = await res.text().catch(() => res.statusText);
|
|
27
|
+
throw new Error(`[ev] Server function "${fnId}" failed (${res.status}): ${text}`);
|
|
28
|
+
}
|
|
29
|
+
const payload = await res.json();
|
|
30
|
+
if (payload.error) {
|
|
31
|
+
throw new Error(`[ev] Server function "${fnId}" threw: ${payload.error}`);
|
|
32
|
+
}
|
|
33
|
+
return payload.result;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
let _transport = null;
|
|
38
|
+
function getTransport() {
|
|
39
|
+
if (!_transport) {
|
|
40
|
+
_transport = createFetchTransport("", DEFAULT_RPC_ENDPOINT);
|
|
41
|
+
}
|
|
42
|
+
return _transport;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Configure the server transport. Call once at app startup if you need to
|
|
46
|
+
* customise the endpoint URL or provide a custom transport.
|
|
47
|
+
*/
|
|
48
|
+
export function configureTransport(options) {
|
|
49
|
+
if (options.transport) {
|
|
50
|
+
_transport = options.transport;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
_transport = createFetchTransport(options.baseUrl ?? "", options.endpoint ?? DEFAULT_RPC_ENDPOINT);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Call a server function by its unique ID.
|
|
58
|
+
*
|
|
59
|
+
* @internal This function is auto-injected by the Webpack loader.
|
|
60
|
+
* Do not call directly — use server functions as normal imports instead.
|
|
61
|
+
*/
|
|
62
|
+
export async function __ev_call(fnId, args, context) {
|
|
63
|
+
return getTransport().send(fnId, args, context);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Internal registry mapping server function references to their IDs.
|
|
67
|
+
* Uses WeakMap so function stubs can be garbage collected.
|
|
68
|
+
*/
|
|
69
|
+
// biome-ignore lint/suspicious/noExplicitAny: must accept any function shape
|
|
70
|
+
const fnIdRegistry = new WeakMap();
|
|
71
|
+
/**
|
|
72
|
+
* Register a server function stub with its ID.
|
|
73
|
+
*
|
|
74
|
+
* @internal Called by build-tools codegen. Do not use directly.
|
|
75
|
+
*/
|
|
76
|
+
// biome-ignore lint/suspicious/noExplicitAny: must accept any function shape
|
|
77
|
+
export function __ev_register(fn, fnId) {
|
|
78
|
+
fnIdRegistry.set(fn, fnId);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Look up the internal function ID for a server function stub.
|
|
82
|
+
* Returns undefined if the function is not a registered server function.
|
|
83
|
+
*/
|
|
84
|
+
// biome-ignore lint/suspicious/noExplicitAny: must accept any function shape
|
|
85
|
+
export function getFnId(fn) {
|
|
86
|
+
return fnIdRegistry.get(fn);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/client/transport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAmDpD;;GAEG;AACH,SAAS,oBAAoB,CAC3B,OAAe,EACf,QAAgB;IAEhB,OAAO;QACL,KAAK,CAAC,IAAI,CACR,IAAY,EACZ,IAAe,EACf,OAAwB;YAExB,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;YAEpC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC3B,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,GAAG,OAAO,EAAE,OAAO;iBACpB;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;gBACpC,MAAM,EAAE,OAAO,EAAE,MAAM;aACxB,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,E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