@evjs/runtime 0.0.1-rc.6 → 0.0.1-rc.7
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 +267 -35
- package/esm/client/context.d.ts +1 -1
- package/esm/client/context.js +1 -1
- package/esm/client/create-app.d.ts +33 -11
- package/esm/client/create-app.d.ts.map +1 -1
- package/esm/client/create-app.js +12 -5
- package/esm/client/create-app.js.map +1 -1
- package/package.json +1 -1
package/AGENT.md
CHANGED
|
@@ -1,78 +1,310 @@
|
|
|
1
|
-
# @evjs/runtime
|
|
1
|
+
# @evjs/runtime — Agent Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> AI-agent reference for developing apps with the `@evjs/runtime` package.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Core runtime for evjs apps. Two entry points:
|
|
8
|
+
- `@evjs/runtime` + `@evjs/runtime/client` — client-side (React, TanStack)
|
|
9
|
+
- `@evjs/runtime/server` — server-side (Hono)
|
|
10
|
+
- `@evjs/runtime/server/ecma` — edge/serverless adapter
|
|
11
|
+
|
|
12
|
+
## Client API
|
|
6
13
|
|
|
7
14
|
### App Bootstrap
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { createApp, createAppRootRoute, createRoute } from "@evjs/runtime";
|
|
18
|
+
|
|
19
|
+
const rootRoute = createAppRootRoute({ component: RootLayout });
|
|
20
|
+
|
|
21
|
+
const homeRoute = createRoute({
|
|
22
|
+
getParentRoute: () => rootRoute,
|
|
23
|
+
path: "/",
|
|
24
|
+
component: HomePage,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const routeTree = rootRoute.addChildren([homeRoute]);
|
|
28
|
+
|
|
29
|
+
const app = createApp({ routeTree });
|
|
30
|
+
|
|
31
|
+
// REQUIRED for type-safe useParams, useSearch, Link, etc.
|
|
32
|
+
declare module "@tanstack/react-router" {
|
|
33
|
+
interface Register {
|
|
34
|
+
router: typeof app.router;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
app.render("#app");
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Key functions:**
|
|
42
|
+
| API | Import | Purpose |
|
|
43
|
+
|-----|--------|---------|
|
|
44
|
+
| `createApp` | `@evjs/runtime` | Bootstrap Router + QueryClient + render to DOM |
|
|
45
|
+
| `createAppRootRoute` | `@evjs/runtime` | Root route with typed `context.queryClient` |
|
|
46
|
+
| `createRoute` | `@evjs/runtime` | Define a route (re-export from TanStack Router) |
|
|
10
47
|
|
|
11
48
|
### Server Function Proxies
|
|
12
|
-
|
|
49
|
+
|
|
50
|
+
**Always use `query()` / `mutation()` wrappers.** Never call `useQuery` with manual fetch.
|
|
13
51
|
|
|
14
52
|
```tsx
|
|
15
|
-
import { query, mutation
|
|
53
|
+
import { query, mutation } from "@evjs/runtime/client";
|
|
16
54
|
import { getUsers, createUser } from "./api/users.server";
|
|
17
55
|
|
|
18
|
-
//
|
|
19
|
-
const { data } = query(getUsers).useQuery(
|
|
20
|
-
const { mutate } = mutation(createUser).useMutation();
|
|
56
|
+
// Data fetching
|
|
57
|
+
const { data, isLoading, error } = query(getUsers).useQuery();
|
|
21
58
|
|
|
22
|
-
//
|
|
23
|
-
const
|
|
24
|
-
api.query.getUsers.useQuery([]);
|
|
59
|
+
// With arguments (spread, not wrapped in array)
|
|
60
|
+
const { data } = query(getUser).useQuery(userId);
|
|
25
61
|
|
|
26
|
-
//
|
|
27
|
-
const
|
|
62
|
+
// Mutations
|
|
63
|
+
const { mutate, isPending } = mutation(createUser).useMutation();
|
|
64
|
+
mutate([{ name: "Alice", email: "alice@example.com" }]);
|
|
65
|
+
|
|
66
|
+
// queryOptions — for route loaders, prefetching, cache control
|
|
67
|
+
const opts = query(getUsers).queryOptions();
|
|
28
68
|
queryClient.ensureQueryData(opts);
|
|
69
|
+
queryClient.prefetchQuery(opts);
|
|
29
70
|
|
|
30
|
-
//
|
|
71
|
+
// Cache invalidation
|
|
31
72
|
queryClient.invalidateQueries({ queryKey: query(getUsers).queryKey() });
|
|
73
|
+
// or by evId
|
|
74
|
+
queryClient.invalidateQueries({ queryKey: [getUsers.evId] });
|
|
75
|
+
|
|
76
|
+
// Module proxy (for grouping)
|
|
77
|
+
import { createQueryProxy, createMutationProxy } from "@evjs/runtime/client";
|
|
78
|
+
const api = {
|
|
79
|
+
query: createQueryProxy({ getUsers, getUser }),
|
|
80
|
+
mutation: createMutationProxy({ createUser }),
|
|
81
|
+
};
|
|
82
|
+
api.query.getUsers.useQuery();
|
|
32
83
|
```
|
|
33
84
|
|
|
34
85
|
### Route Loader Pattern
|
|
86
|
+
|
|
87
|
+
Prefetch data before route renders — no loading spinners:
|
|
88
|
+
|
|
35
89
|
```tsx
|
|
36
|
-
const rootRoute = createAppRootRoute({ component: Root });
|
|
37
90
|
const usersRoute = createRoute({
|
|
38
91
|
getParentRoute: () => rootRoute,
|
|
39
92
|
path: "/users",
|
|
40
93
|
loader: ({ context }) =>
|
|
41
|
-
context.queryClient.ensureQueryData(query(getUsers).queryOptions(
|
|
94
|
+
context.queryClient.ensureQueryData(query(getUsers).queryOptions()),
|
|
42
95
|
component: UsersPage,
|
|
43
96
|
});
|
|
44
97
|
```
|
|
45
98
|
|
|
46
|
-
### Routing
|
|
47
|
-
`createRootRoute`, `createRoute`, `createRouter`, `Link`, `Outlet`, `Navigate`, `useParams`, `useSearch`, `useNavigate`, `useLocation`, `useMatch`, `useLoaderData`, `redirect`, `notFound`, `lazyRouteComponent`
|
|
99
|
+
### Routing
|
|
48
100
|
|
|
49
|
-
### Data (re-exports from @tanstack/react-query)
|
|
50
|
-
`useQuery`, `useMutation`, `useQueryClient`, `useSuspenseQuery`, `QueryClient`, `QueryClientProvider`
|
|
51
101
|
|
|
52
|
-
|
|
102
|
+
**Recommended structure:**
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
src/
|
|
106
|
+
├── main.tsx ← route tree wiring + type registration
|
|
107
|
+
├── api/*.server.ts ← server functions
|
|
108
|
+
└── pages/
|
|
109
|
+
├── __root.tsx ← root layout (nav + <Outlet />)
|
|
110
|
+
├── home.tsx ← static route
|
|
111
|
+
├── posts/index.tsx ← nested group (layout + index + $postId)
|
|
112
|
+
├── dashboard.tsx ← pathless layout + child route
|
|
113
|
+
├── search.tsx ← typed search params
|
|
114
|
+
└── catch.tsx ← redirect + 404
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Key patterns:**
|
|
118
|
+
|
|
119
|
+
| Pattern | Code | Notes |
|
|
120
|
+
|---------|------|-------|
|
|
121
|
+
| Dynamic slug | `path: "$postId"` | Access via `route.useParams()` → `{ postId: string }` |
|
|
122
|
+
| Pathless layout | `id: "dashboard-layout"` | Shared UI without URL segment, use `<Outlet />` |
|
|
123
|
+
| Index route | `path: "/"` inside a group | Shown when parent matches exactly |
|
|
124
|
+
| Catch-all / 404 | `path: "*"` | Matches unmatched URLs |
|
|
125
|
+
| Search params | `validateSearch: (s) => ({ q: s.q ?? "" })` | Access via `route.useSearch()` |
|
|
126
|
+
| Redirect | `beforeLoad: () => { throw redirect({ to: "/posts" }) }` | |
|
|
127
|
+
| Route nesting | `postsRoute.addChildren([indexRoute, detailRoute])` | |
|
|
128
|
+
| Loader prefetch | `loader: ({ params, context }) => context.queryClient.ensureQueryData(...)` | |
|
|
129
|
+
|
|
130
|
+
**Type-safe routing (CRITICAL):**
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
// main.tsx — ALWAYS register the router type
|
|
134
|
+
const app = createApp({ routeTree });
|
|
135
|
+
|
|
136
|
+
declare module "@tanstack/react-router" {
|
|
137
|
+
interface Register {
|
|
138
|
+
router: typeof app.router;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
app.render("#app");
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Without this declaration, `useParams()`, `useSearch()`, and `Link` all return `any`.
|
|
146
|
+
|
|
147
|
+
**Use route-scoped hooks** (not global):
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
// ✅ Type-safe — postId: string
|
|
151
|
+
const { postId } = postDetailRoute.useParams();
|
|
152
|
+
|
|
153
|
+
// ❌ Untyped — returns any
|
|
154
|
+
const params = useParams({ from: "/posts/$postId" });
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### Transport Configuration
|
|
159
|
+
|
|
53
160
|
```tsx
|
|
54
161
|
import { initTransport } from "@evjs/runtime/client";
|
|
55
162
|
|
|
56
|
-
//
|
|
163
|
+
// Default HTTP transport (usually no config needed)
|
|
164
|
+
initTransport({ endpoint: "/api/fn" });
|
|
165
|
+
|
|
166
|
+
// Custom API host (e.g., separate backend)
|
|
57
167
|
initTransport({
|
|
58
168
|
baseUrl: "https://api.example.com",
|
|
59
|
-
endpoint: "/
|
|
169
|
+
endpoint: "/api/fn",
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// WebSocket transport
|
|
173
|
+
initTransport({
|
|
174
|
+
transport: {
|
|
175
|
+
send: async (fnId, args) => {
|
|
176
|
+
// custom WebSocket implementation
|
|
177
|
+
},
|
|
178
|
+
},
|
|
60
179
|
});
|
|
61
180
|
|
|
62
|
-
//
|
|
63
|
-
initTransport({
|
|
181
|
+
// Custom codec (e.g., MessagePack)
|
|
182
|
+
initTransport({
|
|
183
|
+
codec: {
|
|
184
|
+
encode: (data) => msgpack.encode(data),
|
|
185
|
+
decode: (buffer) => msgpack.decode(buffer),
|
|
186
|
+
contentType: "application/msgpack",
|
|
187
|
+
},
|
|
188
|
+
});
|
|
64
189
|
```
|
|
65
190
|
|
|
66
|
-
|
|
191
|
+
### Routing Re-exports
|
|
67
192
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- `registerServerFn(fnId, fn)` — Register server function (called by build-tools).
|
|
71
|
-
- `createHandler()` — Standalone Hono server function handler.
|
|
193
|
+
From `@tanstack/react-router`:
|
|
194
|
+
`createRootRoute`, `createRoute`, `createRouter`, `Link`, `Outlet`, `Navigate`, `useParams`, `useSearch`, `useNavigate`, `useLocation`, `useMatch`, `useLoaderData`, `redirect`, `notFound`, `lazyRouteComponent`
|
|
72
195
|
|
|
73
|
-
|
|
196
|
+
### Data Re-exports
|
|
74
197
|
|
|
75
|
-
|
|
198
|
+
From `@tanstack/react-query`:
|
|
199
|
+
`useQuery`, `useMutation`, `useQueryClient`, `useSuspenseQuery`, `QueryClient`, `QueryClientProvider`
|
|
76
200
|
|
|
77
201
|
## Server Functions
|
|
78
|
-
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
// src/api/users.server.ts
|
|
205
|
+
"use server";
|
|
206
|
+
|
|
207
|
+
export async function getUsers() {
|
|
208
|
+
return await db.users.findMany();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export async function getUser(id: string) {
|
|
212
|
+
const user = await db.users.find(id);
|
|
213
|
+
if (!user) {
|
|
214
|
+
throw new ServerError("NOT_FOUND", { message: "User not found", id });
|
|
215
|
+
}
|
|
216
|
+
return user;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export async function createUser(name: string, email: string) {
|
|
220
|
+
return await db.users.create({ data: { name, email } });
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Rules:**
|
|
225
|
+
- File must start with `"use server";` directive
|
|
226
|
+
- Only **named async function exports** are supported
|
|
227
|
+
- No default exports, no arrow function exports
|
|
228
|
+
- Arguments are positional, transported as a tuple
|
|
229
|
+
- Use `.server.ts` extension or place in `src/api/`
|
|
230
|
+
- Build system auto-discovers — no manual registration
|
|
231
|
+
|
|
232
|
+
## Server API
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { createApp, serve, createHandler, registerMiddleware } from "@evjs/runtime/server";
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
| API | Purpose |
|
|
239
|
+
|-----|---------|
|
|
240
|
+
| `createApp({ endpoint? })` | Hono app with server function handler |
|
|
241
|
+
| `serve(app, { port?, host? })` | Node.js HTTP server with graceful shutdown |
|
|
242
|
+
| `createHandler()` | Standalone server function Hono handler |
|
|
243
|
+
| `registerServerFn(id, fn)` | Register a server function (used by build tools) |
|
|
244
|
+
| `registerMiddleware(fn)` | Register Hono middleware |
|
|
245
|
+
|
|
246
|
+
### ECMA Adapter (Edge / Serverless)
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import { createFetchHandler } from "@evjs/runtime/server/ecma";
|
|
250
|
+
|
|
251
|
+
const app = createApp({ endpoint: "/api/fn" });
|
|
252
|
+
const handler = createFetchHandler(app);
|
|
253
|
+
|
|
254
|
+
// Deno
|
|
255
|
+
Deno.serve(handler);
|
|
256
|
+
|
|
257
|
+
// Bun
|
|
258
|
+
export default { fetch: handler };
|
|
259
|
+
|
|
260
|
+
// Cloudflare Workers
|
|
261
|
+
export default { fetch: handler };
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Error Handling
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { ServerError } from "@evjs/runtime";
|
|
268
|
+
|
|
269
|
+
// Server — throw structured errors
|
|
270
|
+
export async function getUser(id: string) {
|
|
271
|
+
const user = await db.users.find(id);
|
|
272
|
+
if (!user) throw new ServerError("NOT_FOUND", { id });
|
|
273
|
+
return user;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Client — catch typed errors
|
|
277
|
+
import { ServerError } from "@evjs/runtime";
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
await getUser("123");
|
|
281
|
+
} catch (e) {
|
|
282
|
+
if (e instanceof ServerError) {
|
|
283
|
+
e.code; // "NOT_FOUND"
|
|
284
|
+
e.data; // { id: "123" }
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Middleware
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
// src/middleware/auth.ts
|
|
293
|
+
import { registerMiddleware } from "@evjs/runtime/server";
|
|
294
|
+
|
|
295
|
+
registerMiddleware(async (c, next) => {
|
|
296
|
+
const token = c.req.header("Authorization");
|
|
297
|
+
if (!token) return c.json({ error: "Unauthorized" }, 401);
|
|
298
|
+
await next();
|
|
299
|
+
});
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Common Mistakes
|
|
303
|
+
|
|
304
|
+
1. **Don't use raw `useQuery`** for server functions — use `query(fn).useQuery(args)`
|
|
305
|
+
2. **Arguments are spread, not wrapped** — `query(getUser).useQuery(id)` not `query(getUser).useQuery([id])`
|
|
306
|
+
3. **Don't call server functions directly in components** — wrap with `query()` or `mutation()`
|
|
307
|
+
4. **Don't forget `"use server";`** at the top of `.server.ts` files
|
|
308
|
+
5. **Import `ServerError` from `@evjs/runtime`** — not from `/server` or `/client`
|
|
309
|
+
6. **Always register the router type** — without `declare module "@tanstack/react-router" { interface Register { router: typeof app.router } }`, all route params/search will be `any`
|
|
310
|
+
7. **Use `route.useParams()`** not the global `useParams()` — the route-scoped version gives proper type inference
|
package/esm/client/context.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface AppRouteContext {
|
|
|
17
17
|
* getParentRoute: () => rootRoute,
|
|
18
18
|
* path: "/users",
|
|
19
19
|
* loader: ({ context }) =>
|
|
20
|
-
* context.queryClient.ensureQueryData(query(getUsers).queryOptions(
|
|
20
|
+
* context.queryClient.ensureQueryData(query(getUsers).queryOptions()),
|
|
21
21
|
* });
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
package/esm/client/context.js
CHANGED
|
@@ -13,7 +13,7 @@ import { createRootRouteWithContext } from "@tanstack/react-router";
|
|
|
13
13
|
* getParentRoute: () => rootRoute,
|
|
14
14
|
* path: "/users",
|
|
15
15
|
* loader: ({ context }) =>
|
|
16
|
-
* context.queryClient.ensureQueryData(query(getUsers).queryOptions(
|
|
16
|
+
* context.queryClient.ensureQueryData(query(getUsers).queryOptions()),
|
|
17
17
|
* });
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { QueryClient, type QueryClientConfig } from "@tanstack/react-query";
|
|
2
|
-
import type { AnyRoute
|
|
2
|
+
import type { AnyRoute } from "@tanstack/react-router";
|
|
3
3
|
/**
|
|
4
4
|
* Options for creating an ev application.
|
|
5
5
|
*/
|
|
6
6
|
export interface CreateAppOptions<TRouteTree extends AnyRoute> {
|
|
7
7
|
/** The root route tree produced by createRootRoute and addChildren. */
|
|
8
8
|
routeTree: TRouteTree;
|
|
9
|
-
/**
|
|
10
|
-
* Optional configuration for the TanStack Router.
|
|
11
|
-
*/
|
|
12
|
-
routerOptions?: Omit<Parameters<typeof import("@tanstack/react-router").createRouter>[0], "routeTree">;
|
|
13
9
|
/**
|
|
14
10
|
* Optional configuration for the TanStack Query Client.
|
|
15
11
|
*/
|
|
@@ -22,10 +18,25 @@ export interface CreateAppOptions<TRouteTree extends AnyRoute> {
|
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
20
|
* An initialized ev application instance.
|
|
21
|
+
*
|
|
22
|
+
* Register the router type for full IDE type safety on `useParams`,
|
|
23
|
+
* `useSearch`, `Link`, etc:
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const app = createApp({ routeTree });
|
|
27
|
+
*
|
|
28
|
+
* declare module "@tanstack/react-router" {
|
|
29
|
+
* interface Register {
|
|
30
|
+
* router: typeof app.router;
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* app.render("#app");
|
|
35
|
+
* ```
|
|
25
36
|
*/
|
|
26
|
-
export interface App {
|
|
27
|
-
/** The TanStack Router instance. */
|
|
28
|
-
router:
|
|
37
|
+
export interface App<TRouter> {
|
|
38
|
+
/** The TanStack Router instance (use `typeof app.router` for type registration). */
|
|
39
|
+
router: TRouter;
|
|
29
40
|
/** The TanStack Query Client instance. */
|
|
30
41
|
queryClient: QueryClient;
|
|
31
42
|
/**
|
|
@@ -40,14 +51,25 @@ export interface App {
|
|
|
40
51
|
* This function initializes the router and query client and returns
|
|
41
52
|
* an app object that can be mounted into the DOM.
|
|
42
53
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
54
|
+
* Register the router type globally for full IDE type-safety on
|
|
55
|
+
* `useParams`, `useSearch`, `Link`, etc:
|
|
45
56
|
*
|
|
46
57
|
* @example
|
|
47
58
|
* ```tsx
|
|
48
59
|
* const app = createApp({ routeTree });
|
|
60
|
+
*
|
|
61
|
+
* declare module "@tanstack/react-router" {
|
|
62
|
+
* interface Register {
|
|
63
|
+
* router: typeof app.router;
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
49
67
|
* app.render("#app");
|
|
50
68
|
* ```
|
|
51
69
|
*/
|
|
52
|
-
export declare function createApp<TRouteTree extends AnyRoute>(options: CreateAppOptions<TRouteTree>):
|
|
70
|
+
export declare function createApp<TRouteTree extends AnyRoute>(options: CreateAppOptions<TRouteTree>): {
|
|
71
|
+
router: import("@tanstack/router-core").RouterCore<TRouteTree, "never", false, import("@tanstack/history").RouterHistory, Record<string, any>>;
|
|
72
|
+
queryClient: QueryClient;
|
|
73
|
+
render: (container: string | HTMLElement) => void;
|
|
74
|
+
};
|
|
53
75
|
//# sourceMappingURL=create-app.d.ts.map
|
|
@@ -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,
|
|
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,MAAM,wBAAwB,CAAC;AAMvD;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,UAAU,SAAS,QAAQ;IAC3D,uEAAuE;IACvE,SAAS,EAAE,UAAU,CAAC;IACtB;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,GAAG,CAAC,OAAO;IAC1B,oFAAoF;IACpF,MAAM,EAAE,OAAO,CAAC;IAChB,0CAA0C;IAC1C,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,UAAU,SAAS,QAAQ,EACnD,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC;;;wBAgBV,MAAM,GAAG,WAAW,KAAG,IAAI;EAqBvD"}
|
package/esm/client/create-app.js
CHANGED
|
@@ -9,25 +9,32 @@ import { initTransport } from "./transport";
|
|
|
9
9
|
* This function initializes the router and query client and returns
|
|
10
10
|
* an app object that can be mounted into the DOM.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Register the router type globally for full IDE type-safety on
|
|
13
|
+
* `useParams`, `useSearch`, `Link`, etc:
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```tsx
|
|
17
17
|
* const app = createApp({ routeTree });
|
|
18
|
+
*
|
|
19
|
+
* declare module "@tanstack/react-router" {
|
|
20
|
+
* interface Register {
|
|
21
|
+
* router: typeof app.router;
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
18
25
|
* app.render("#app");
|
|
19
26
|
* ```
|
|
20
27
|
*/
|
|
21
28
|
export function createApp(options) {
|
|
22
|
-
const { routeTree,
|
|
29
|
+
const { routeTree, queryClientConfig, endpoint } = options;
|
|
23
30
|
if (endpoint) {
|
|
24
31
|
initTransport({ endpoint: endpoint });
|
|
25
32
|
}
|
|
26
33
|
const queryClient = new QueryClient(queryClientConfig);
|
|
27
34
|
const router = createRouter({
|
|
28
|
-
...routerOptions,
|
|
29
35
|
routeTree,
|
|
30
|
-
|
|
36
|
+
defaultPreload: "intent",
|
|
37
|
+
context: { queryClient },
|
|
31
38
|
});
|
|
32
39
|
function render(container) {
|
|
33
40
|
const el = typeof container === "string"
|
|
@@ -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,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAiD5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,SAAS,CACvB,OAAqC;IAErC,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE3D,IAAI,QAAQ,EAAE,CAAC;QACb,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,SAAS;QACT,cAAc,EAAE,QAAQ;QACxB,OAAO,EAAE,EAAE,WAAW,EAAqB;KAC5C,CAAC,CAAC;IAEH,SAAS,MAAM,CAAC,SAA+B;QAC7C,MAAM,EAAE,GACN,OAAO,SAAS,KAAK,QAAQ;YAC3B,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAc,SAAS,CAAC;YAChD,CAAC,CAAC,SAAS,CAAC;QAEhB,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,MAAM,IAAI,KAAK,CACb,0CAA0C,MAAM,CAAC,SAAS,CAAC,EAAE,CAC9D,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,CACT,KAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW,YACtC,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,GAAI,GACd,CACvB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC"}
|