@evjs/runtime 0.0.1-alpha.5 → 0.0.1-alpha.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/README.md +72 -13
- package/esm/client/index.d.ts +4 -2
- package/esm/client/index.d.ts.map +1 -1
- package/esm/client/index.js +3 -1
- package/esm/client/index.js.map +1 -1
- package/esm/client/query.d.ts +74 -0
- package/esm/client/query.d.ts.map +1 -0
- package/esm/client/query.js +96 -0
- package/esm/client/query.js.map +1 -0
- package/esm/client/transport.d.ts +50 -0
- package/esm/client/transport.d.ts.map +1 -0
- package/esm/client/transport.js +71 -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/server/app.d.ts +9 -9
- package/esm/server/app.d.ts.map +1 -1
- package/esm/server/app.js +9 -12
- package/esm/server/app.js.map +1 -1
- package/esm/server/environments/node.d.ts +11 -0
- package/esm/server/environments/node.d.ts.map +1 -0
- package/esm/server/environments/node.js +19 -0
- package/esm/server/environments/node.js.map +1 -0
- package/esm/server/index.d.ts +4 -2
- package/esm/server/index.d.ts.map +1 -1
- package/esm/server/index.js +2 -1
- package/esm/server/index.js.map +1 -1
- package/package.json +6 -1
- 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/esm/version.d.ts +0 -2
- package/esm/version.d.ts.map +0 -1
- package/esm/version.js +0 -2
- package/esm/version.js.map +0 -1
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
|
+
```
|
package/esm/client/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
+
export * from "@tanstack/react-query";
|
|
4
5
|
export type { App, CreateAppOptions } from "./create-app";
|
|
5
6
|
export { createApp } from "./create-app";
|
|
7
|
+
export * from "./query";
|
|
6
8
|
export * from "./route";
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
+
export type { RequestContext, ServerTransport, TransportOptions, } from "./transport";
|
|
10
|
+
export { configureTransport } from "./transport";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,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,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
+
export * from "@tanstack/react-query";
|
|
4
5
|
export { createApp } from "./create-app";
|
|
6
|
+
export * from "./query";
|
|
5
7
|
export * from "./route";
|
|
6
|
-
export {
|
|
8
|
+
export { configureTransport } from "./transport";
|
|
7
9
|
//# 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,cAAc,uBAAuB,CAAC;AAEtC,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,74 @@
|
|
|
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 evjs webpack loader.
|
|
4
|
+
*/
|
|
5
|
+
export type ServerFunction<TArgs extends unknown[], TResponse> = ((...args: TArgs) => Promise<TResponse>) & {
|
|
6
|
+
_evId?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The interface for a single server function's query proxy.
|
|
10
|
+
*/
|
|
11
|
+
export interface QueryProxyHandler<TArgs extends unknown[], TResponse> {
|
|
12
|
+
/** Call the server function directly. */
|
|
13
|
+
(...args: TArgs): Promise<TResponse>;
|
|
14
|
+
/** Use as a standard TanStack Query. */
|
|
15
|
+
useQuery(args: TArgs, options?: Omit<UseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">): UseQueryResult<TResponse, Error>;
|
|
16
|
+
/** Use as a TanStack Suspense Query. */
|
|
17
|
+
useSuspenseQuery(args: TArgs, options?: Omit<UseSuspenseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">): UseSuspenseQueryResult<TResponse, Error>;
|
|
18
|
+
/** Returns standard TanStack Query options. */
|
|
19
|
+
queryOptions(args: TArgs, options?: Omit<UseQueryOptions<TResponse, Error>, "queryKey" | "queryFn">): UseQueryOptions<TResponse, Error> & {
|
|
20
|
+
queryKey: unknown[];
|
|
21
|
+
queryFn: () => Promise<TResponse>;
|
|
22
|
+
};
|
|
23
|
+
/** Returns the query key for this function and arguments. */
|
|
24
|
+
queryKey(args?: TArgs): unknown[];
|
|
25
|
+
/** The stable function ID (internal). */
|
|
26
|
+
_evId: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The interface for a single server function's mutation proxy.
|
|
30
|
+
*/
|
|
31
|
+
export interface MutationProxyHandler<TVariables, TResponse> {
|
|
32
|
+
/** Call the server function directly. */
|
|
33
|
+
(variables: TVariables): Promise<TResponse>;
|
|
34
|
+
/** Use as a TanStack Mutation. */
|
|
35
|
+
useMutation(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn">): UseMutationResult<TResponse, Error, TVariables>;
|
|
36
|
+
/** Returns standard TanStack Mutation options. */
|
|
37
|
+
mutationOptions(options?: Omit<UseMutationOptions<TResponse, Error, TVariables>, "mutationFn">): UseMutationOptions<TResponse, Error, TVariables> & {
|
|
38
|
+
mutationFn: (variables: TVariables) => Promise<TResponse>;
|
|
39
|
+
};
|
|
40
|
+
/** The stable function ID (internal). */
|
|
41
|
+
_evId: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A recursive proxy that maps property access to server function stubs.
|
|
45
|
+
*/
|
|
46
|
+
export type QueryProxy<TModule> = {
|
|
47
|
+
[K in keyof TModule]: TModule[K] extends ServerFunction<infer TArgs, infer TResponse> ? QueryProxyHandler<TArgs, TResponse> : QueryProxy<TModule[K]>;
|
|
48
|
+
};
|
|
49
|
+
export type MutationProxy<TModule> = {
|
|
50
|
+
[K in keyof TModule]: TModule[K] extends ServerFunction<infer TVars, infer TResponse> ? MutationProxyHandler<TVars, TResponse> : MutationProxy<TModule[K]>;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Create a type-safe query proxy for a module or object.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createQueryProxy<T>(source?: T): QueryProxy<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Create a type-safe mutation proxy for a module or object.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createMutationProxy<T>(source?: T): MutationProxy<T>;
|
|
60
|
+
/**
|
|
61
|
+
* The global query proxy/wrapper.
|
|
62
|
+
* @example
|
|
63
|
+
* const { data } = query(getUsers).useQuery();
|
|
64
|
+
* // or with a typed proxy:
|
|
65
|
+
* const api = createQueryProxy(getUsersModule);
|
|
66
|
+
* const { data } = api.getUsers.useQuery();
|
|
67
|
+
*/
|
|
68
|
+
export declare const query: (<TArgs extends unknown[], TResponse>(fn: ServerFunction<TArgs, TResponse>) => QueryProxyHandler<TArgs, TResponse>) & QueryProxy<Record<string, unknown>>;
|
|
69
|
+
/**
|
|
70
|
+
* The global mutation proxy/wrapper.
|
|
71
|
+
* @example const { mutate } = mutation(createUser).useMutation();
|
|
72
|
+
*/
|
|
73
|
+
export declare const mutation: (<TVariables, TResponse>(fn: (args: TVariables) => Promise<TResponse>) => MutationProxyHandler<TVariables, TResponse>) & MutationProxy<Record<string, unknown>>;
|
|
74
|
+
//# 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,EA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AAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAE7D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAEnE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAA2B,CAAC,CAC5C,KAAK,SAAS,OAAO,EAAE,EACvB,SAAS,EAET,EAAE,EAAE,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,KACjC,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,GACvC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEtC;;;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"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useMutation, useQuery, useSuspenseQuery, } from "@tanstack/react-query";
|
|
2
|
+
function createHandler(fn, path) {
|
|
3
|
+
return {
|
|
4
|
+
useQuery: (args = [], options) => {
|
|
5
|
+
return useQuery({
|
|
6
|
+
...options,
|
|
7
|
+
queryKey: [fn._evId || path.join("."), ...args],
|
|
8
|
+
queryFn: () => fn(...args),
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
useSuspenseQuery: (args = [], options) => {
|
|
12
|
+
return useSuspenseQuery({
|
|
13
|
+
...options,
|
|
14
|
+
queryKey: [fn._evId || path.join("."), ...args],
|
|
15
|
+
queryFn: () => fn(...args),
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
useMutation: (options) => {
|
|
19
|
+
return useMutation({
|
|
20
|
+
...options,
|
|
21
|
+
mutationFn: (variables) => fn(variables),
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
queryOptions: (args = [], options) => {
|
|
25
|
+
return {
|
|
26
|
+
...options,
|
|
27
|
+
queryKey: [fn._evId || path.join("."), ...args],
|
|
28
|
+
queryFn: () => fn(...args),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
mutationOptions: (options) => {
|
|
32
|
+
return {
|
|
33
|
+
...options,
|
|
34
|
+
mutationFn: (variables) => fn(variables),
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
queryKey: (args = []) => {
|
|
38
|
+
return [fn._evId || path.join("."), ...args];
|
|
39
|
+
},
|
|
40
|
+
_evId: fn._evId,
|
|
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
|
+
if (prop === "_evId")
|
|
49
|
+
return _target._evId;
|
|
50
|
+
const newPath = [...path, prop];
|
|
51
|
+
const val = source
|
|
52
|
+
? source[prop]
|
|
53
|
+
: undefined;
|
|
54
|
+
// If we have a source and this is a function, return the handler
|
|
55
|
+
if (typeof val === "function") {
|
|
56
|
+
return createHandler(val, newPath);
|
|
57
|
+
}
|
|
58
|
+
// Otherwise return a nested proxy
|
|
59
|
+
return createProxy(type, val, newPath);
|
|
60
|
+
},
|
|
61
|
+
apply(_target, _thisArg, args) {
|
|
62
|
+
const fn = args[0];
|
|
63
|
+
if (typeof fn === "function") {
|
|
64
|
+
return createHandler(fn, path);
|
|
65
|
+
}
|
|
66
|
+
return fn; // Fallback
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a type-safe query proxy for a module or object.
|
|
72
|
+
*/
|
|
73
|
+
export function createQueryProxy(source) {
|
|
74
|
+
return createProxy("query", source);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a type-safe mutation proxy for a module or object.
|
|
78
|
+
*/
|
|
79
|
+
export function createMutationProxy(source) {
|
|
80
|
+
return createProxy("mutation", source);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The global query proxy/wrapper.
|
|
84
|
+
* @example
|
|
85
|
+
* const { data } = query(getUsers).useQuery();
|
|
86
|
+
* // or with a typed proxy:
|
|
87
|
+
* const api = createQueryProxy(getUsersModule);
|
|
88
|
+
* const { data } = api.getUsers.useQuery();
|
|
89
|
+
*/
|
|
90
|
+
export const query = createProxy("query");
|
|
91
|
+
/**
|
|
92
|
+
* The global mutation proxy/wrapper.
|
|
93
|
+
* @example const { mutate } = mutation(createUser).useMutation();
|
|
94
|
+
*/
|
|
95
|
+
export const mutation = createProxy("mutation");
|
|
96
|
+
//# 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;AAmG/B,SAAS,aAAa,CAAC,EAAsC,EAAE,IAAc;IAC3E,OAAO;QACL,QAAQ,EAAE,CACR,OAAkB,EAAE,EACpB,OAAuE,EACvE,EAAE;YACF,OAAO,QAAQ,CAAC;gBACd,GAAG,OAAO;gBACV,QAAQ,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;gBAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;aAC3B,CAAC,CAAC;QACL,CAAC;QACD,gBAAgB,EAAE,CAChB,OAAkB,EAAE,EACpB,OAGC,EACD,EAAE;YACF,OAAO,gBAAgB,CAAC;gBACtB,GAA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G;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAGN,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
//# 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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
* @param fnId - The unique identifier assigned to the server function by the
|
|
63
|
+
* Webpack loader (e.g. `"user_server_getUser"`).
|
|
64
|
+
* @param args - The arguments to pass to the server function. Must be
|
|
65
|
+
* JSON-serializable.
|
|
66
|
+
* @returns A promise that resolves with the server function's return value.
|
|
67
|
+
*/
|
|
68
|
+
export async function __ev_call(fnId, args, context) {
|
|
69
|
+
return getTransport().send(fnId, args, context);
|
|
70
|
+
}
|
|
71
|
+
//# 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,I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B,IAAY,EACZ,IAAe,EACf,OAAwB;IAExB,OAAO,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,aAAa,CAAC"}
|
package/esm/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC"}
|
package/esm/server/app.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Server application factory.
|
|
3
3
|
*
|
|
4
|
-
* Creates a Hono app with RPC middleware
|
|
5
|
-
*
|
|
4
|
+
* Creates a Hono app with RPC middleware.
|
|
5
|
+
* This app is runtime-agnostic and can be mounted in Node, Edge, or Bun.
|
|
6
6
|
*/
|
|
7
7
|
import { Hono } from "hono";
|
|
8
|
-
/** Options for
|
|
9
|
-
export interface
|
|
8
|
+
/** Options for createApp. */
|
|
9
|
+
export interface CreateAppOptions {
|
|
10
10
|
/** Port to listen on. Defaults to 3001. */
|
|
11
11
|
port?: number;
|
|
12
12
|
/** RPC endpoint path. Defaults to "/api/rpc". */
|
|
13
13
|
rpcEndpoint?: string;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Create
|
|
16
|
+
* Create an ev API server application.
|
|
17
17
|
*
|
|
18
|
-
* Mounts the RPC middleware at `/api/rpc
|
|
18
|
+
* Mounts the RPC middleware at `/api/rpc`.
|
|
19
19
|
* In Stage 3, this will be extended with SSR middleware.
|
|
20
20
|
*
|
|
21
|
-
* @param options -
|
|
22
|
-
* @returns
|
|
21
|
+
* @param options - Application configuration.
|
|
22
|
+
* @returns A runtime-agnostic Hono app instance.
|
|
23
23
|
*/
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function createApp(options?: CreateAppOptions): Hono;
|
|
25
25
|
//# sourceMappingURL=app.d.ts.map
|
package/esm/server/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,6BAA6B;AAC7B,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAS1D"}
|
package/esm/server/app.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Server application factory.
|
|
3
3
|
*
|
|
4
|
-
* Creates a Hono app with RPC middleware
|
|
5
|
-
*
|
|
4
|
+
* Creates a Hono app with RPC middleware.
|
|
5
|
+
* This app is runtime-agnostic and can be mounted in Node, Edge, or Bun.
|
|
6
6
|
*/
|
|
7
7
|
import { Hono } from "hono";
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_RPC_ENDPOINT } from "../constants";
|
|
9
9
|
import { createRpcMiddleware } from "./handler";
|
|
10
10
|
/**
|
|
11
|
-
* Create
|
|
11
|
+
* Create an ev API server application.
|
|
12
12
|
*
|
|
13
|
-
* Mounts the RPC middleware at `/api/rpc
|
|
13
|
+
* Mounts the RPC middleware at `/api/rpc`.
|
|
14
14
|
* In Stage 3, this will be extended with SSR middleware.
|
|
15
15
|
*
|
|
16
|
-
* @param options -
|
|
17
|
-
* @returns
|
|
16
|
+
* @param options - Application configuration.
|
|
17
|
+
* @returns A runtime-agnostic Hono app instance.
|
|
18
18
|
*/
|
|
19
|
-
export function
|
|
20
|
-
const {
|
|
19
|
+
export function createApp(options) {
|
|
20
|
+
const { rpcEndpoint = DEFAULT_RPC_ENDPOINT } = options ?? {};
|
|
21
21
|
const app = new Hono();
|
|
22
22
|
// Mount RPC endpoint
|
|
23
23
|
app.route(rpcEndpoint, createRpcMiddleware());
|
|
24
|
-
serve({ fetch: app.fetch, port }, (info) => {
|
|
25
|
-
console.log(`ev server running at http://localhost:${info.port}`);
|
|
26
|
-
});
|
|
27
24
|
return app;
|
|
28
25
|
}
|
|
29
26
|
//# sourceMappingURL=app.js.map
|
package/esm/server/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/server/app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAUhD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,OAA0B;IAClD,MAAM,EAAE,WAAW,GAAG,oBAAoB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAE7D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,qBAAqB;IACrB,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAE9C,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
export interface NodeRunnerOptions {
|
|
3
|
+
port?: number;
|
|
4
|
+
host?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Runner plugin for Node.js environments.
|
|
8
|
+
* Takes a compiled Hono app and starts a native Node HTTP server.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runNodeServer(app: Hono, options?: NodeRunnerOptions): import("@hono/node-server").ServerType;
|
|
11
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/server/environments/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAIjC,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,0CAYnE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { serve } from "@hono/node-server";
|
|
2
|
+
import { getLogger } from "@logtape/logtape";
|
|
3
|
+
const logger = getLogger(["evjs", "server"]);
|
|
4
|
+
/**
|
|
5
|
+
* Runner plugin for Node.js environments.
|
|
6
|
+
* Takes a compiled Hono app and starts a native Node HTTP server.
|
|
7
|
+
*/
|
|
8
|
+
export function runNodeServer(app, options) {
|
|
9
|
+
const port = options?.port || 3001;
|
|
10
|
+
const hostname = options?.host;
|
|
11
|
+
const server = serve({ fetch: app.fetch, port, hostname }, (info) => {
|
|
12
|
+
const address = info.address === "0.0.0.0" || info.address === "::"
|
|
13
|
+
? "localhost"
|
|
14
|
+
: info.address;
|
|
15
|
+
logger.info `Server API ready at http://${address}:${info.port}`;
|
|
16
|
+
});
|
|
17
|
+
return server;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/server/environments/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAO7C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAS,EAAE,OAA2B;IAClE,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC;IACnC,MAAM,QAAQ,GAAG,OAAO,EAAE,IAAI,CAAC;IAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;QAClE,MAAM,OAAO,GACX,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;YACjD,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QACnB,MAAM,CAAC,IAAI,CAAA,8BAA8B,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/esm/server/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Server-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
4
|
+
export type { CreateAppOptions } from "./app";
|
|
5
|
+
export { createApp } from "./app";
|
|
6
|
+
export type { NodeRunnerOptions } from "./environments/node";
|
|
7
|
+
export { runNodeServer } from "./environments/node";
|
|
6
8
|
export { createRpcMiddleware, registerServerFn } from "./handler";
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/esm/server/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Server-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
-
export {
|
|
4
|
+
export { createApp } from "./app";
|
|
5
|
+
export { runNodeServer } from "./environments/node";
|
|
5
6
|
export { createRpcMiddleware, registerServerFn } from "./handler";
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/esm/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evjs/runtime",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hono/node-server": "^1.19.11",
|
|
7
|
+
"@logtape/logtape": "^2.0.4",
|
|
7
8
|
"@tanstack/react-query": "^5.90.21",
|
|
8
9
|
"@tanstack/react-router": "^1.163.3",
|
|
9
10
|
"hono": "^4.12.5"
|
|
@@ -38,6 +39,10 @@
|
|
|
38
39
|
"types": "./esm/client/index.d.ts",
|
|
39
40
|
"import": "./esm/client/index.js"
|
|
40
41
|
},
|
|
42
|
+
"./client/transport": {
|
|
43
|
+
"types": "./esm/client/transport.d.ts",
|
|
44
|
+
"import": "./esm/client/transport.js"
|
|
45
|
+
},
|
|
41
46
|
"./server": {
|
|
42
47
|
"types": "./esm/server/index.d.ts",
|
|
43
48
|
"import": "./esm/server/index.js"
|
package/esm/client/rpc.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side RPC helper 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_rpc(fnId, args)`. This module provides that helper.
|
|
7
|
-
*/
|
|
8
|
-
export interface RpcOptions {
|
|
9
|
-
/** Base URL for the RPC endpoint. Defaults to the current origin. */
|
|
10
|
-
baseUrl?: string;
|
|
11
|
-
/** Path prefix for the RPC endpoint. Defaults to `/api/rpc`. */
|
|
12
|
-
endpoint?: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Configure the RPC client. Call once at app startup if you need to
|
|
16
|
-
* customise the endpoint URL.
|
|
17
|
-
*/
|
|
18
|
-
export declare function configureRpc(options: RpcOptions): void;
|
|
19
|
-
/**
|
|
20
|
-
* Call a server function by its unique ID.
|
|
21
|
-
*
|
|
22
|
-
* @param fnId - The unique identifier assigned to the server function by the
|
|
23
|
-
* Webpack loader (e.g. `"user_server_getUser"`).
|
|
24
|
-
* @param args - The arguments to pass to the server function. Must be
|
|
25
|
-
* JSON-serializable.
|
|
26
|
-
* @returns A promise that resolves with the server function's return value.
|
|
27
|
-
*/
|
|
28
|
-
export declare function __ev_rpc(fnId: string, args: unknown[]): Promise<unknown>;
|
|
29
|
-
//# sourceMappingURL=rpc.d.ts.map
|
package/esm/client/rpc.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../src/client/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAOD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAEtD;AAED;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB9E"}
|
package/esm/client/rpc.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side RPC helper 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_rpc(fnId, args)`. This module provides that helper.
|
|
7
|
-
*/
|
|
8
|
-
let _options = {
|
|
9
|
-
baseUrl: "",
|
|
10
|
-
endpoint: "/api/rpc",
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Configure the RPC client. Call once at app startup if you need to
|
|
14
|
-
* customise the endpoint URL.
|
|
15
|
-
*/
|
|
16
|
-
export function configureRpc(options) {
|
|
17
|
-
_options = { ..._options, ...options };
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Call a server function by its unique ID.
|
|
21
|
-
*
|
|
22
|
-
* @param fnId - The unique identifier assigned to the server function by the
|
|
23
|
-
* Webpack loader (e.g. `"user_server_getUser"`).
|
|
24
|
-
* @param args - The arguments to pass to the server function. Must be
|
|
25
|
-
* JSON-serializable.
|
|
26
|
-
* @returns A promise that resolves with the server function's return value.
|
|
27
|
-
*/
|
|
28
|
-
export async function __ev_rpc(fnId, args) {
|
|
29
|
-
const url = `${_options.baseUrl}${_options.endpoint}`;
|
|
30
|
-
const res = await fetch(url, {
|
|
31
|
-
method: "POST",
|
|
32
|
-
headers: { "Content-Type": "application/json" },
|
|
33
|
-
body: JSON.stringify({ fnId, args }),
|
|
34
|
-
});
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
const text = await res.text().catch(() => res.statusText);
|
|
37
|
-
throw new Error(`[ev/rpc] Server function "${fnId}" failed (${res.status}): ${text}`);
|
|
38
|
-
}
|
|
39
|
-
const payload = await res.json();
|
|
40
|
-
if (payload.error) {
|
|
41
|
-
throw new Error(`[ev/rpc] Server function "${fnId}" threw: ${payload.error}`);
|
|
42
|
-
}
|
|
43
|
-
return payload.result;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=rpc.js.map
|
package/esm/client/rpc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/client/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,IAAI,QAAQ,GAAyB;IACnC,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAmB;IAC9C,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,IAAe;IAC1D,MAAM,GAAG,GAAG,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAEtD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;KACrC,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,aAAa,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;IACxF,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAEjC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,YAAY,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}
|
package/esm/version.d.ts
DELETED
package/esm/version.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,kBAAkB,CAAC"}
|
package/esm/version.js
DELETED
package/esm/version.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC"}
|