@evjs/runtime 0.0.1-alpha.6 → 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 +65 -14
- package/esm/client/index.d.ts +2 -2
- package/esm/client/index.d.ts.map +1 -1
- package/esm/client/index.js +1 -2
- package/esm/client/index.js.map +1 -1
- package/esm/client/query.d.ts +0 -4
- package/esm/client/query.d.ts.map +1 -1
- package/esm/client/query.js +0 -18
- package/esm/client/query.js.map +1 -1
- 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,40 +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
40
|
import { createApp, createRootRoute, query, mutation } from "@evjs/runtime/client";
|
|
24
41
|
import { getUsers, createUser } from "./api/users.server";
|
|
25
42
|
|
|
26
|
-
// Using the Query Proxy
|
|
27
43
|
function Users() {
|
|
28
44
|
const { data } = query(getUsers).useQuery([]);
|
|
29
45
|
const { mutate } = mutation(createUser).useMutation();
|
|
30
|
-
// ...
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
const rootRoute = createRootRoute({ component: Root });
|
|
34
49
|
const app = createApp({ routeTree: rootRoute });
|
|
35
|
-
|
|
36
50
|
app.render("#app");
|
|
37
51
|
```
|
|
38
52
|
|
|
39
|
-
### Server
|
|
53
|
+
### Server
|
|
54
|
+
|
|
55
|
+
The server app is a runtime-agnostic Hono instance. Use a Runner to start it:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { createApp, runNodeServer } from "@evjs/runtime/server";
|
|
59
|
+
|
|
60
|
+
const app = createApp();
|
|
61
|
+
runNodeServer(app, { port: 3001 });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In development, `ev dev` with `runner` configured in `EvWebpackPlugin` handles this automatically.
|
|
65
|
+
|
|
66
|
+
### Custom Transport
|
|
40
67
|
|
|
41
68
|
```ts
|
|
42
|
-
import {
|
|
69
|
+
import { configureTransport } from "@evjs/runtime/client";
|
|
43
70
|
|
|
44
|
-
|
|
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
|
+
});
|
|
45
79
|
```
|
|
46
80
|
|
|
47
|
-
|
|
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
|
@@ -6,6 +6,6 @@ export type { App, CreateAppOptions } from "./create-app";
|
|
|
6
6
|
export { createApp } from "./create-app";
|
|
7
7
|
export * from "./query";
|
|
8
8
|
export * from "./route";
|
|
9
|
-
export type {
|
|
10
|
-
export {
|
|
9
|
+
export type { RequestContext, ServerTransport, TransportOptions, } from "./transport";
|
|
10
|
+
export { configureTransport } from "./transport";
|
|
11
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;
|
|
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,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-side runtime utilities.
|
|
3
3
|
*/
|
|
4
|
-
// ── TanStack Query Integration ──
|
|
5
4
|
export * from "@tanstack/react-query";
|
|
6
5
|
export { createApp } from "./create-app";
|
|
7
6
|
export * from "./query";
|
|
8
7
|
export * from "./route";
|
|
9
|
-
export {
|
|
8
|
+
export { configureTransport } from "./transport";
|
|
10
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;AAEH,
|
|
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"}
|
package/esm/client/query.d.ts
CHANGED
|
@@ -71,8 +71,4 @@ export declare const query: (<TArgs extends unknown[], TResponse>(fn: ServerFunc
|
|
|
71
71
|
* @example const { mutate } = mutation(createUser).useMutation();
|
|
72
72
|
*/
|
|
73
73
|
export declare const mutation: (<TVariables, TResponse>(fn: (args: TVariables) => Promise<TResponse>) => MutationProxyHandler<TVariables, TResponse>) & MutationProxy<Record<string, unknown>>;
|
|
74
|
-
/** @deprecated Use query.fnName.useQuery() */
|
|
75
|
-
export declare function useServerQuery<TArgs extends unknown[], TResponse, TError = Error>(serverFn: ServerFunction<TArgs, TResponse>, args: TArgs, options?: Omit<UseQueryOptions<TResponse, TError>, "queryKey" | "queryFn">): UseQueryResult<TResponse, TError>;
|
|
76
|
-
/** @deprecated Use mutation.fnName.useMutation() */
|
|
77
|
-
export declare function useServerMutation<TVariables, TResponse, TError = Error>(serverFn: (args: TVariables) => Promise<TResponse>, options?: Omit<UseMutationOptions<TResponse, TError, TVariables>, "mutationFn">): UseMutationResult<TResponse, TError, TVariables>;
|
|
78
74
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/client/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kB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,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC"}
|
package/esm/client/query.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useMutation, useQuery, useSuspenseQuery, } from "@tanstack/react-query";
|
|
2
|
-
// ── Implementation ───────────────────────────────────────
|
|
3
2
|
function createHandler(fn, path) {
|
|
4
3
|
return {
|
|
5
4
|
useQuery: (args = [], options) => {
|
|
@@ -94,21 +93,4 @@ export const query = createProxy("query");
|
|
|
94
93
|
* @example const { mutate } = mutation(createUser).useMutation();
|
|
95
94
|
*/
|
|
96
95
|
export const mutation = createProxy("mutation");
|
|
97
|
-
// ── Legacy Hooks (deprecated) ──────────────────────────
|
|
98
|
-
/** @deprecated Use query.fnName.useQuery() */
|
|
99
|
-
export function useServerQuery(serverFn, args, options) {
|
|
100
|
-
const queryKey = [serverFn._evId || serverFn.name, ...args];
|
|
101
|
-
return useQuery({
|
|
102
|
-
...options,
|
|
103
|
-
queryKey,
|
|
104
|
-
queryFn: () => serverFn(...args),
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/** @deprecated Use mutation.fnName.useMutation() */
|
|
108
|
-
export function useServerMutation(serverFn, options) {
|
|
109
|
-
return useMutation({
|
|
110
|
-
...options,
|
|
111
|
-
mutationFn: (variables) => serverFn(variables),
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
96
|
//# sourceMappingURL=query.js.map
|
package/esm/client/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/client/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,QAAQ,EACR,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;
|
|
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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,OAAO,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACjC,CAAC;YACD,OAAO,EAAE,CAAC,CAAC,WAAW;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAI,MAAU;IAC5C,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,CAAkB,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAI,MAAU;IAC/C,OAAO,WAAW,CAAC,UAAU,EAAE,MAAM,CAAqB,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAMH,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAGN,CAAC"}
|
|
@@ -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/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,UAAU,GAAG,oBAAoB,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAyB;IAC1D,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IACjC,CAAC;SAAM,CAAC;QACN,UAAU,GAAG,oBAAoB,CAC/B,OAAO,CAAC,OAAO,IAAI,EAAE,EACrB,OAAO,CAAC,QAAQ,IAAI,oBAAoB,CACzC,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,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;
|
|
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
|
-
import { serve } from "@hono/node-server";
|
|
8
7
|
import { Hono } from "hono";
|
|
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,
|
|
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 type {
|
|
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,YAAY,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;AAGH,OAAO,EAAE,
|
|
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,CAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EAAE,GACd,OAAO,CAAC,OAAO,CAAC,CAyBlB"}
|
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,CAC5B,IAAY,EACZ,IAAe;IAEf,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,CACb,6BAA6B,IAAI,aAAa,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CACrE,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAEjC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,YAAY,OAAO,CAAC,KAAK,EAAE,CAC7D,CAAC;IACJ,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"}
|