silgi 0.1.0-beta.6 → 0.1.0-beta.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/dist/adapters/astro.d.mts +2 -2
- package/dist/adapters/astro.mjs +4 -4
- package/dist/adapters/aws-lambda.d.mts +2 -2
- package/dist/adapters/aws-lambda.mjs +4 -4
- package/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.mjs +4 -4
- package/dist/adapters/message-port.d.mts +2 -2
- package/dist/adapters/message-port.mjs +4 -4
- package/dist/adapters/nestjs.d.mts +3 -3
- package/dist/adapters/nestjs.mjs +6 -6
- package/dist/adapters/nextjs.d.mts +2 -2
- package/dist/adapters/nextjs.mjs +4 -4
- package/dist/adapters/peer.mjs +2 -2
- package/dist/adapters/remix.d.mts +2 -2
- package/dist/adapters/remix.mjs +4 -4
- package/dist/adapters/solidstart.d.mts +2 -2
- package/dist/adapters/solidstart.mjs +4 -4
- package/dist/adapters/sveltekit.d.mts +2 -2
- package/dist/adapters/sveltekit.mjs +4 -4
- package/dist/broker/index.d.mts +2 -2
- package/dist/broker/index.mjs +4 -4
- package/dist/client/adapters/ofetch/index.d.mts +3 -3
- package/dist/integrations/better-auth/index.d.mts +9 -9
- package/dist/integrations/better-auth/index.mjs +8 -8
- package/dist/integrations/drizzle/index.d.mts +2 -2
- package/dist/integrations/drizzle/index.mjs +4 -4
- package/dist/integrations/hey-api/index.d.mts +2 -0
- package/dist/integrations/hey-api/index.mjs +2 -0
- package/dist/integrations/hey-api/to-client.d.mts +20 -0
- package/dist/integrations/hey-api/to-client.mjs +39 -0
- package/dist/integrations/pinia-colada/general-utils.d.mts +13 -0
- package/dist/integrations/pinia-colada/general-utils.mjs +9 -0
- package/dist/integrations/pinia-colada/index.d.mts +6 -0
- package/dist/integrations/pinia-colada/index.mjs +5 -0
- package/dist/integrations/pinia-colada/key.d.mts +11 -0
- package/dist/integrations/pinia-colada/key.mjs +11 -0
- package/dist/integrations/pinia-colada/procedure-utils.d.mts +25 -0
- package/dist/integrations/pinia-colada/procedure-utils.mjs +33 -0
- package/dist/integrations/pinia-colada/router-utils.d.mts +17 -0
- package/dist/integrations/pinia-colada/router-utils.mjs +30 -0
- package/dist/integrations/pinia-colada/types.d.mts +26 -0
- package/package.json +21 -2
|
@@ -7,9 +7,9 @@ interface AstroAdapterOptions<TCtx extends Record<string, unknown>> extends Fetc
|
|
|
7
7
|
* Create an Astro API route handler.
|
|
8
8
|
* Astro passes { request, params } — we extract request and delegate.
|
|
9
9
|
*/
|
|
10
|
-
declare function
|
|
10
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: AstroAdapterOptions<TCtx>): (ctx: {
|
|
11
11
|
request: Request;
|
|
12
12
|
params: Record<string, string>;
|
|
13
13
|
}) => Response | Promise<Response>;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { AstroAdapterOptions,
|
|
15
|
+
export { AstroAdapterOptions, createHandler };
|
package/dist/adapters/astro.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import { createFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
8
|
* // src/pages/api/rpc/[...path].ts
|
|
9
|
-
* import {
|
|
9
|
+
* import { createHandler } from "silgi/astro"
|
|
10
10
|
* import { appRouter } from "~/server/rpc"
|
|
11
11
|
*
|
|
12
|
-
* const handler =
|
|
12
|
+
* const handler = createHandler(appRouter, {
|
|
13
13
|
* prefix: "/api/rpc",
|
|
14
14
|
* context: (req) => ({ db: getDB() }),
|
|
15
15
|
* })
|
|
@@ -23,9 +23,9 @@ import { createFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
23
23
|
* Create an Astro API route handler.
|
|
24
24
|
* Astro passes { request, params } — we extract request and delegate.
|
|
25
25
|
*/
|
|
26
|
-
function
|
|
26
|
+
function createHandler(router, options = {}) {
|
|
27
27
|
const handler = createFetchAdapter(router, options, "/api/rpc");
|
|
28
28
|
return ({ request }) => handler(request);
|
|
29
29
|
}
|
|
30
30
|
//#endregion
|
|
31
|
-
export {
|
|
31
|
+
export { createHandler };
|
|
@@ -37,6 +37,6 @@ interface LambdaResponse {
|
|
|
37
37
|
*
|
|
38
38
|
* Supports API Gateway v1 (REST) and v2 (HTTP) event formats.
|
|
39
39
|
*/
|
|
40
|
-
declare function
|
|
40
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: LambdaAdapterOptions<TCtx>): (event: LambdaEvent, context?: LambdaContext) => Promise<LambdaResponse>;
|
|
41
41
|
//#endregion
|
|
42
|
-
export { LambdaAdapterOptions,
|
|
42
|
+
export { LambdaAdapterOptions, createHandler };
|
|
@@ -6,9 +6,9 @@ import { buildContext, isMethodAllowed, parseQueryData, serializeError } from ".
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
* import {
|
|
9
|
+
* import { createHandler } from "silgi/aws-lambda"
|
|
10
10
|
*
|
|
11
|
-
* export const handler =
|
|
11
|
+
* export const handler = createHandler(appRouter, {
|
|
12
12
|
* context: (event) => ({ db: getDB(), userId: event.requestContext?.authorizer?.userId }),
|
|
13
13
|
* })
|
|
14
14
|
* ```
|
|
@@ -18,7 +18,7 @@ import { buildContext, isMethodAllowed, parseQueryData, serializeError } from ".
|
|
|
18
18
|
*
|
|
19
19
|
* Supports API Gateway v1 (REST) and v2 (HTTP) event formats.
|
|
20
20
|
*/
|
|
21
|
-
function
|
|
21
|
+
function createHandler(router, options = {}) {
|
|
22
22
|
const flatRouter = compileRouter(router);
|
|
23
23
|
const prefix = options.prefix ?? "";
|
|
24
24
|
const JSON_HDR = { "content-type": "application/json" };
|
|
@@ -89,4 +89,4 @@ function silgiLambda(router, options = {}) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
//#endregion
|
|
92
|
-
export {
|
|
92
|
+
export { createHandler };
|
|
@@ -11,6 +11,6 @@ interface ExpressAdapterOptions<TCtx extends Record<string, unknown>> {
|
|
|
11
11
|
* Mount at a prefix — the remainder of the path is the procedure name.
|
|
12
12
|
* Requires `express.json()` middleware for POST body parsing.
|
|
13
13
|
*/
|
|
14
|
-
declare function
|
|
14
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: ExpressAdapterOptions<TCtx>): (req: any, res: any, next: any) => void;
|
|
15
15
|
//#endregion
|
|
16
|
-
export { ExpressAdapterOptions,
|
|
16
|
+
export { ExpressAdapterOptions, createHandler };
|
|
@@ -8,10 +8,10 @@ import { iteratorToEventStream } from "../core/sse.mjs";
|
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
10
|
* import express from "express"
|
|
11
|
-
* import {
|
|
11
|
+
* import { createHandler } from "silgi/express"
|
|
12
12
|
*
|
|
13
13
|
* const app = express()
|
|
14
|
-
* app.use("/rpc",
|
|
14
|
+
* app.use("/rpc", createHandler(appRouter, {
|
|
15
15
|
* context: (req) => ({ db: getDB(), user: req.user }),
|
|
16
16
|
* }))
|
|
17
17
|
* app.listen(3000)
|
|
@@ -23,7 +23,7 @@ import { iteratorToEventStream } from "../core/sse.mjs";
|
|
|
23
23
|
* Mount at a prefix — the remainder of the path is the procedure name.
|
|
24
24
|
* Requires `express.json()` middleware for POST body parsing.
|
|
25
25
|
*/
|
|
26
|
-
function
|
|
26
|
+
function createHandler(router, options = {}) {
|
|
27
27
|
const flatRouter = compileRouter(router);
|
|
28
28
|
return (req, res, next) => {
|
|
29
29
|
let pathname = req.path ?? req.url ?? "";
|
|
@@ -117,4 +117,4 @@ function silgiExpress(router, options = {}) {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
//#endregion
|
|
120
|
-
export {
|
|
120
|
+
export { createHandler };
|
|
@@ -10,7 +10,7 @@ interface MessagePortAdapterOptions<TCtx extends Record<string, unknown>> {
|
|
|
10
10
|
* Listens for RPC messages and responds with results.
|
|
11
11
|
* Returns a dispose function to stop listening.
|
|
12
12
|
*/
|
|
13
|
-
declare function
|
|
13
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, port: {
|
|
14
14
|
postMessage(msg: unknown): void;
|
|
15
15
|
addEventListener(type: 'message', handler: (event: {
|
|
16
16
|
data: unknown;
|
|
@@ -39,4 +39,4 @@ declare class MessagePortLink<TCtx extends ClientContext = ClientContext> implem
|
|
|
39
39
|
dispose(): void;
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
|
-
export { MessagePortAdapterOptions, MessagePortLink,
|
|
42
|
+
export { MessagePortAdapterOptions, MessagePortLink, createHandler };
|
|
@@ -11,9 +11,9 @@ import { buildContext, serializeError } from "../core/dispatch.mjs";
|
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
13
|
* // Worker / Electron main
|
|
14
|
-
* import {
|
|
14
|
+
* import { createHandler } from "silgi/message-port"
|
|
15
15
|
*
|
|
16
|
-
* const dispose =
|
|
16
|
+
* const dispose = createHandler(appRouter, port, {
|
|
17
17
|
* context: () => ({ db: getDB() }),
|
|
18
18
|
* })
|
|
19
19
|
*
|
|
@@ -30,7 +30,7 @@ import { buildContext, serializeError } from "../core/dispatch.mjs";
|
|
|
30
30
|
* Listens for RPC messages and responds with results.
|
|
31
31
|
* Returns a dispose function to stop listening.
|
|
32
32
|
*/
|
|
33
|
-
function
|
|
33
|
+
function createHandler(router, port, options = {}) {
|
|
34
34
|
const flatRouter = compileRouter(router);
|
|
35
35
|
const handler = async (event) => {
|
|
36
36
|
const msg = event.data;
|
|
@@ -129,4 +129,4 @@ var MessagePortLink = class {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
//#endregion
|
|
132
|
-
export { MessagePortLink,
|
|
132
|
+
export { MessagePortLink, createHandler };
|
|
@@ -11,15 +11,15 @@ interface NestAdapterOptions<TCtx extends Record<string, unknown>> {
|
|
|
11
11
|
* Use inside a `@Controller` with `@All("*")`.
|
|
12
12
|
* Handles routing internally — NestJS only needs to mount the prefix.
|
|
13
13
|
*/
|
|
14
|
-
declare function
|
|
14
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: NestAdapterOptions<TCtx>): (req: any, res: any) => Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Create a NestJS module configuration for Silgi.
|
|
17
17
|
*
|
|
18
18
|
* Returns an object that can be used with NestJS's dynamic module pattern.
|
|
19
19
|
*/
|
|
20
|
-
declare function
|
|
20
|
+
declare function createModule(router: RouterDef, options?: NestAdapterOptions<any>): {
|
|
21
21
|
handler: (req: any, res: any) => Promise<void>;
|
|
22
22
|
router: RouterDef;
|
|
23
23
|
};
|
|
24
24
|
//#endregion
|
|
25
|
-
export { NestAdapterOptions,
|
|
25
|
+
export { NestAdapterOptions, createHandler, createModule };
|
package/dist/adapters/nestjs.mjs
CHANGED
|
@@ -8,10 +8,10 @@ import { buildContext, parseQueryData, serializeError } from "../core/dispatch.m
|
|
|
8
8
|
* ```ts
|
|
9
9
|
* // rpc.controller.ts
|
|
10
10
|
* import { Controller, All, Req, Res } from "@nestjs/common"
|
|
11
|
-
* import {
|
|
11
|
+
* import { createHandler } from "silgi/nestjs"
|
|
12
12
|
* import { appRouter } from "./rpc"
|
|
13
13
|
*
|
|
14
|
-
* const rpcHandler =
|
|
14
|
+
* const rpcHandler = createHandler(appRouter, {
|
|
15
15
|
* context: (req) => ({ db: getDB(), user: req.user }),
|
|
16
16
|
* })
|
|
17
17
|
*
|
|
@@ -30,7 +30,7 @@ import { buildContext, parseQueryData, serializeError } from "../core/dispatch.m
|
|
|
30
30
|
* Use inside a `@Controller` with `@All("*")`.
|
|
31
31
|
* Handles routing internally — NestJS only needs to mount the prefix.
|
|
32
32
|
*/
|
|
33
|
-
function
|
|
33
|
+
function createHandler(router, options = {}) {
|
|
34
34
|
const flatRouter = compileRouter(router);
|
|
35
35
|
return async (req, res) => {
|
|
36
36
|
let pathname = req.params?.[0] ?? req.path ?? req.url ?? "";
|
|
@@ -65,11 +65,11 @@ function silgiNestHandler(router, options = {}) {
|
|
|
65
65
|
*
|
|
66
66
|
* Returns an object that can be used with NestJS's dynamic module pattern.
|
|
67
67
|
*/
|
|
68
|
-
function
|
|
68
|
+
function createModule(router, options = {}) {
|
|
69
69
|
return {
|
|
70
|
-
handler:
|
|
70
|
+
handler: createHandler(router, options),
|
|
71
71
|
router
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
//#endregion
|
|
75
|
-
export {
|
|
75
|
+
export { createHandler, createModule };
|
|
@@ -9,6 +9,6 @@ interface NextjsAdapterOptions<TCtx extends Record<string, unknown>> extends Fet
|
|
|
9
9
|
* Uses Silgi's handler() internally — full Fetch API support
|
|
10
10
|
* including content negotiation (JSON, MessagePack, devalue).
|
|
11
11
|
*/
|
|
12
|
-
declare function
|
|
12
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: NextjsAdapterOptions<TCtx>): (req: Request) => Response | Promise<Response>;
|
|
13
13
|
//#endregion
|
|
14
|
-
export { NextjsAdapterOptions,
|
|
14
|
+
export { NextjsAdapterOptions, createHandler };
|
package/dist/adapters/nextjs.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import { createFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
8
|
* // app/api/rpc/[...path]/route.ts
|
|
9
|
-
* import {
|
|
9
|
+
* import { createHandler } from "silgi/nextjs"
|
|
10
10
|
* import { appRouter } from "~/server/rpc"
|
|
11
11
|
*
|
|
12
|
-
* const handler =
|
|
12
|
+
* const handler = createHandler(appRouter, {
|
|
13
13
|
* context: (req) => ({ db: getDB() }),
|
|
14
14
|
* })
|
|
15
15
|
*
|
|
@@ -22,8 +22,8 @@ import { createFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
22
22
|
* Uses Silgi's handler() internally — full Fetch API support
|
|
23
23
|
* including content negotiation (JSON, MessagePack, devalue).
|
|
24
24
|
*/
|
|
25
|
-
function
|
|
25
|
+
function createHandler(router, options = {}) {
|
|
26
26
|
return createFetchAdapter(router, options, "/api/rpc");
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
|
-
export {
|
|
29
|
+
export { createHandler };
|
package/dist/adapters/peer.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClient } from "../client/client.mjs";
|
|
2
|
-
import { MessagePortLink,
|
|
2
|
+
import { MessagePortLink, createHandler } from "./message-port.mjs";
|
|
3
3
|
//#region src/adapters/peer.ts
|
|
4
4
|
/**
|
|
5
5
|
* Peer-to-peer adapter — bidirectional RPC between two Silgi instances.
|
|
@@ -26,7 +26,7 @@ import { MessagePortLink, silgiMessagePort } from "./message-port.mjs";
|
|
|
26
26
|
* for the remote peer's router.
|
|
27
27
|
*/
|
|
28
28
|
function createPeer(localRouter, port, options = {}) {
|
|
29
|
-
const dispose =
|
|
29
|
+
const dispose = createHandler(localRouter, port, options);
|
|
30
30
|
return {
|
|
31
31
|
client: createClient(new MessagePortLink(port)),
|
|
32
32
|
dispose
|
|
@@ -7,9 +7,9 @@ interface RemixAdapterOptions<TCtx extends Record<string, unknown>> extends Fetc
|
|
|
7
7
|
* Create a Remix action/loader handler.
|
|
8
8
|
* Remix passes { request, params } — we extract request and delegate.
|
|
9
9
|
*/
|
|
10
|
-
declare function
|
|
10
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: RemixAdapterOptions<TCtx>): (args: {
|
|
11
11
|
request: Request;
|
|
12
12
|
params: Record<string, string>;
|
|
13
13
|
}) => Response | Promise<Response>;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { RemixAdapterOptions,
|
|
15
|
+
export { RemixAdapterOptions, createHandler };
|
package/dist/adapters/remix.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import { createFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
8
|
* // app/routes/rpc.$.tsx
|
|
9
|
-
* import {
|
|
9
|
+
* import { createHandler } from "silgi/remix"
|
|
10
10
|
* import { appRouter } from "~/server/rpc"
|
|
11
11
|
*
|
|
12
|
-
* const handler =
|
|
12
|
+
* const handler = createHandler(appRouter, {
|
|
13
13
|
* prefix: "/rpc",
|
|
14
14
|
* context: (req) => ({ db: getDB() }),
|
|
15
15
|
* })
|
|
@@ -22,9 +22,9 @@ import { createFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
22
22
|
* Create a Remix action/loader handler.
|
|
23
23
|
* Remix passes { request, params } — we extract request and delegate.
|
|
24
24
|
*/
|
|
25
|
-
function
|
|
25
|
+
function createHandler(router, options = {}) {
|
|
26
26
|
const handler = createFetchAdapter(router, options, "/rpc");
|
|
27
27
|
return ({ request }) => handler(request);
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
|
-
export {
|
|
30
|
+
export { createHandler };
|
|
@@ -7,6 +7,6 @@ interface SolidStartAdapterOptions<TCtx extends Record<string, unknown>> extends
|
|
|
7
7
|
* Create a SolidStart API route handler.
|
|
8
8
|
* SolidStart uses Fetch API events — uses Silgi's handler().
|
|
9
9
|
*/
|
|
10
|
-
declare function
|
|
10
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: SolidStartAdapterOptions<TCtx>): (event: any) => Response | Promise<Response>;
|
|
11
11
|
//#endregion
|
|
12
|
-
export { SolidStartAdapterOptions,
|
|
12
|
+
export { SolidStartAdapterOptions, createHandler };
|
|
@@ -6,10 +6,10 @@ import { createEventFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
8
|
* // src/routes/api/rpc/[...path].ts
|
|
9
|
-
* import {
|
|
9
|
+
* import { createHandler } from "silgi/solidstart"
|
|
10
10
|
* import { appRouter } from "~/server/rpc"
|
|
11
11
|
*
|
|
12
|
-
* const handler =
|
|
12
|
+
* const handler = createHandler(appRouter, {
|
|
13
13
|
* prefix: "/api/rpc",
|
|
14
14
|
* context: (event) => ({ db: getDB() }),
|
|
15
15
|
* })
|
|
@@ -22,8 +22,8 @@ import { createEventFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
22
22
|
* Create a SolidStart API route handler.
|
|
23
23
|
* SolidStart uses Fetch API events — uses Silgi's handler().
|
|
24
24
|
*/
|
|
25
|
-
function
|
|
25
|
+
function createHandler(router, options = {}) {
|
|
26
26
|
return createEventFetchAdapter(router, options, "/api/rpc", (event) => event.request ?? event);
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
|
-
export {
|
|
29
|
+
export { createHandler };
|
|
@@ -9,6 +9,6 @@ interface SvelteKitAdapterOptions<TCtx extends Record<string, unknown>> extends
|
|
|
9
9
|
* SvelteKit passes a RequestEvent with `.request` (standard Request).
|
|
10
10
|
* The handler uses Silgi's handler() for full protocol support.
|
|
11
11
|
*/
|
|
12
|
-
declare function
|
|
12
|
+
declare function createHandler<TCtx extends Record<string, unknown>>(router: RouterDef, options?: SvelteKitAdapterOptions<TCtx>): (event: any) => Response | Promise<Response>;
|
|
13
13
|
//#endregion
|
|
14
|
-
export { SvelteKitAdapterOptions,
|
|
14
|
+
export { SvelteKitAdapterOptions, createHandler };
|
|
@@ -6,10 +6,10 @@ import { createEventFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
8
|
* // src/routes/api/rpc/[...path]/+server.ts
|
|
9
|
-
* import {
|
|
9
|
+
* import { createHandler } from "silgi/sveltekit"
|
|
10
10
|
* import { appRouter } from "$lib/server/rpc"
|
|
11
11
|
*
|
|
12
|
-
* const handler =
|
|
12
|
+
* const handler = createHandler(appRouter, {
|
|
13
13
|
* context: (event) => ({ db: getDB(), user: event.locals.user }),
|
|
14
14
|
* })
|
|
15
15
|
*
|
|
@@ -23,8 +23,8 @@ import { createEventFetchAdapter } from "./_fetch-adapter.mjs";
|
|
|
23
23
|
* SvelteKit passes a RequestEvent with `.request` (standard Request).
|
|
24
24
|
* The handler uses Silgi's handler() for full protocol support.
|
|
25
25
|
*/
|
|
26
|
-
function
|
|
26
|
+
function createHandler(router, options = {}) {
|
|
27
27
|
return createEventFetchAdapter(router, options, "/api/rpc", (event) => event.request);
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
|
-
export {
|
|
30
|
+
export { createHandler };
|
package/dist/broker/index.d.mts
CHANGED
|
@@ -38,7 +38,7 @@ interface BrokerOptions<TCtx extends Record<string, unknown>> {
|
|
|
38
38
|
*
|
|
39
39
|
* Returns a cleanup function to stop listening.
|
|
40
40
|
*/
|
|
41
|
-
declare function
|
|
41
|
+
declare function createBroker<TCtx extends Record<string, unknown>>(router: RouterDef, driver: BrokerDriver, options?: BrokerOptions<TCtx>): Promise<() => void>;
|
|
42
42
|
interface BrokerLinkOptions {
|
|
43
43
|
/** Subject/topic to send requests to. Default: `"silgi"` */
|
|
44
44
|
subject?: string;
|
|
@@ -59,4 +59,4 @@ declare class BrokerLink<TCtx extends ClientContext = ClientContext> implements
|
|
|
59
59
|
*/
|
|
60
60
|
declare function memoryBroker(): BrokerDriver;
|
|
61
61
|
//#endregion
|
|
62
|
-
export { BrokerDriver, BrokerLink, BrokerLinkOptions, BrokerOptions,
|
|
62
|
+
export { BrokerDriver, BrokerLink, BrokerLinkOptions, BrokerOptions, createBroker, memoryBroker };
|
package/dist/broker/index.mjs
CHANGED
|
@@ -11,10 +11,10 @@ import { compileRouter } from "../compile.mjs";
|
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
13
|
* // Server
|
|
14
|
-
* import {
|
|
14
|
+
* import { createBroker, memoryBroker } from "silgi/broker"
|
|
15
15
|
*
|
|
16
16
|
* const driver = memoryBroker()
|
|
17
|
-
* const dispose = await
|
|
17
|
+
* const dispose = await createBroker(appRouter, driver, {
|
|
18
18
|
* subject: "myapp.rpc",
|
|
19
19
|
* context: () => ({ db: getDB() }),
|
|
20
20
|
* })
|
|
@@ -35,7 +35,7 @@ import { compileRouter } from "../compile.mjs";
|
|
|
35
35
|
*
|
|
36
36
|
* Returns a cleanup function to stop listening.
|
|
37
37
|
*/
|
|
38
|
-
async function
|
|
38
|
+
async function createBroker(router, driver, options = {}) {
|
|
39
39
|
const compiledRouter = compileRouter(router);
|
|
40
40
|
const subject = options.subject ?? "silgi";
|
|
41
41
|
const unsubscribe = await driver.subscribe(subject, (payload, reply) => {
|
|
@@ -150,4 +150,4 @@ function memoryBroker() {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
//#endregion
|
|
153
|
-
export { BrokerLink,
|
|
153
|
+
export { BrokerLink, createBroker, memoryBroker };
|
|
@@ -2,7 +2,7 @@ import { ClientContext, ClientLink, ClientOptions } from "../../types.mjs";
|
|
|
2
2
|
import { FetchContext, FetchOptions } from "ofetch";
|
|
3
3
|
|
|
4
4
|
//#region src/client/adapters/ofetch/index.d.ts
|
|
5
|
-
interface
|
|
5
|
+
interface LinkOptions<TClientContext extends ClientContext = ClientContext> {
|
|
6
6
|
/** Server base URL (e.g. "http://localhost:3000") */
|
|
7
7
|
url: string;
|
|
8
8
|
/** Static headers or dynamic header factory */
|
|
@@ -50,6 +50,6 @@ interface SilgiLinkOptions<TClientContext extends ClientContext = ClientContext>
|
|
|
50
50
|
* const users = await client.users.list({ limit: 10 })
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
declare function createLink<TClientContext extends ClientContext = ClientContext>(options:
|
|
53
|
+
declare function createLink<TClientContext extends ClientContext = ClientContext>(options: LinkOptions<TClientContext>): ClientLink<TClientContext>;
|
|
54
54
|
//#endregion
|
|
55
|
-
export {
|
|
55
|
+
export { LinkOptions, createLink };
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
|
-
* import {
|
|
13
|
+
* import { tracing } from 'silgi/better-auth'
|
|
14
14
|
*
|
|
15
15
|
* const auth = betterAuth({
|
|
16
16
|
* plugins: [
|
|
17
|
-
*
|
|
17
|
+
* tracing(), // auto-traces all auth operations
|
|
18
18
|
* ],
|
|
19
19
|
* })
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
interface
|
|
22
|
+
interface TracingConfig {
|
|
23
23
|
/** Capture request body as span input (default: true) */
|
|
24
24
|
captureInput?: boolean;
|
|
25
25
|
/** Capture response data as span output (default: true) */
|
|
@@ -34,21 +34,21 @@ interface SilgiTracingConfig {
|
|
|
34
34
|
* @param config - Optional configuration
|
|
35
35
|
* @returns A Better Auth plugin (typed as `any` to avoid requiring better-auth types at build time)
|
|
36
36
|
*/
|
|
37
|
-
declare function
|
|
37
|
+
declare function tracing(config?: TracingConfig): any;
|
|
38
38
|
/**
|
|
39
39
|
* Instrument a Better Auth instance to trace all `auth.api.*` method calls.
|
|
40
|
-
* Works with `
|
|
40
|
+
* Works with `withCtx` — programmatic calls from background jobs,
|
|
41
41
|
* server-side session fetches etc. are traced when context is available.
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
45
|
-
* import { instrumentBetterAuth,
|
|
45
|
+
* import { instrumentBetterAuth, withCtx } from 'silgi/better-auth'
|
|
46
46
|
*
|
|
47
47
|
* const auth = instrumentBetterAuth(betterAuth({ ... }))
|
|
48
48
|
*
|
|
49
49
|
* // In a silgi procedure:
|
|
50
50
|
* const me = s.$resolve(async ({ ctx }) => {
|
|
51
|
-
* return
|
|
51
|
+
* return withCtx(ctx, () => auth.api.getSession({ headers: ctx.headers }))
|
|
52
52
|
* })
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
@@ -56,6 +56,6 @@ declare function instrumentBetterAuth<T extends Record<string, any>>(auth: T): T
|
|
|
56
56
|
/**
|
|
57
57
|
* Run a function with silgi context available to instrumented Better Auth API calls.
|
|
58
58
|
*/
|
|
59
|
-
declare function
|
|
59
|
+
declare function withCtx<T>(ctx: Record<string, unknown>, fn: () => T): T;
|
|
60
60
|
//#endregion
|
|
61
|
-
export {
|
|
61
|
+
export { TracingConfig, instrumentBetterAuth, tracing, withCtx };
|
|
@@ -11,11 +11,11 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
-
* import {
|
|
14
|
+
* import { tracing } from 'silgi/better-auth'
|
|
15
15
|
*
|
|
16
16
|
* const auth = betterAuth({
|
|
17
17
|
* plugins: [
|
|
18
|
-
*
|
|
18
|
+
* tracing(), // auto-traces all auth operations
|
|
19
19
|
* ],
|
|
20
20
|
* })
|
|
21
21
|
* ```
|
|
@@ -127,7 +127,7 @@ const requestMetas = /* @__PURE__ */ new WeakMap();
|
|
|
127
127
|
* @param config - Optional configuration
|
|
128
128
|
* @returns A Better Auth plugin (typed as `any` to avoid requiring better-auth types at build time)
|
|
129
129
|
*/
|
|
130
|
-
function
|
|
130
|
+
function tracing(config) {
|
|
131
131
|
const captureInput = config?.captureInput ?? true;
|
|
132
132
|
const captureOutput = config?.captureOutput ?? true;
|
|
133
133
|
return {
|
|
@@ -245,18 +245,18 @@ const API_METHOD_METADATA = {
|
|
|
245
245
|
const AUTH_INSTRUMENTED = "__silgiBetterAuthInstrumented";
|
|
246
246
|
/**
|
|
247
247
|
* Instrument a Better Auth instance to trace all `auth.api.*` method calls.
|
|
248
|
-
* Works with `
|
|
248
|
+
* Works with `withCtx` — programmatic calls from background jobs,
|
|
249
249
|
* server-side session fetches etc. are traced when context is available.
|
|
250
250
|
*
|
|
251
251
|
* @example
|
|
252
252
|
* ```ts
|
|
253
|
-
* import { instrumentBetterAuth,
|
|
253
|
+
* import { instrumentBetterAuth, withCtx } from 'silgi/better-auth'
|
|
254
254
|
*
|
|
255
255
|
* const auth = instrumentBetterAuth(betterAuth({ ... }))
|
|
256
256
|
*
|
|
257
257
|
* // In a silgi procedure:
|
|
258
258
|
* const me = s.$resolve(async ({ ctx }) => {
|
|
259
|
-
* return
|
|
259
|
+
* return withCtx(ctx, () => auth.api.getSession({ headers: ctx.headers }))
|
|
260
260
|
* })
|
|
261
261
|
* ```
|
|
262
262
|
*/
|
|
@@ -280,7 +280,7 @@ function instrumentBetterAuth(auth) {
|
|
|
280
280
|
/**
|
|
281
281
|
* Run a function with silgi context available to instrumented Better Auth API calls.
|
|
282
282
|
*/
|
|
283
|
-
function
|
|
283
|
+
function withCtx(ctx, fn) {
|
|
284
284
|
return ctxStorage.run(ctx, fn);
|
|
285
285
|
}
|
|
286
286
|
function wrapApiMethod(originalFn, operation, method) {
|
|
@@ -329,4 +329,4 @@ function wrapApiMethod(originalFn, operation, method) {
|
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
331
|
//#endregion
|
|
332
|
-
export { instrumentBetterAuth,
|
|
332
|
+
export { instrumentBetterAuth, tracing, withCtx };
|
|
@@ -22,6 +22,6 @@ declare function instrumentDrizzle<T extends Record<string, any>>(db: T, config?
|
|
|
22
22
|
* Run a function with silgi context available to instrumented Drizzle instances.
|
|
23
23
|
* All Drizzle queries inside `fn` will be recorded as trace spans.
|
|
24
24
|
*/
|
|
25
|
-
declare function
|
|
25
|
+
declare function withCtx<T>(ctx: Record<string, unknown>, fn: () => T): T;
|
|
26
26
|
//#endregion
|
|
27
|
-
export { InstrumentDrizzleConfig, instrumentDrizzle,
|
|
27
|
+
export { InstrumentDrizzleConfig, instrumentDrizzle, withCtx };
|
|
@@ -18,7 +18,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* import { instrumentDrizzle,
|
|
21
|
+
* import { instrumentDrizzle, withCtx } from 'silgi/drizzle'
|
|
22
22
|
*
|
|
23
23
|
* const db = instrumentDrizzle(drizzle(url, { schema }), {
|
|
24
24
|
* dbName: 'ecommerce',
|
|
@@ -27,7 +27,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
27
27
|
* })
|
|
28
28
|
*
|
|
29
29
|
* const listUsers = s.$resolve(async ({ ctx }) => {
|
|
30
|
-
* return
|
|
30
|
+
* return withCtx(ctx, () => db.select().from(users))
|
|
31
31
|
* })
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
@@ -58,7 +58,7 @@ function instrumentDrizzle(db, config) {
|
|
|
58
58
|
* Run a function with silgi context available to instrumented Drizzle instances.
|
|
59
59
|
* All Drizzle queries inside `fn` will be recorded as trace spans.
|
|
60
60
|
*/
|
|
61
|
-
function
|
|
61
|
+
function withCtx(ctx, fn) {
|
|
62
62
|
return ctxStorage.run(ctx, fn);
|
|
63
63
|
}
|
|
64
64
|
function resolveConfig(config) {
|
|
@@ -283,4 +283,4 @@ function round(n) {
|
|
|
283
283
|
return Math.round(n * 100) / 100;
|
|
284
284
|
}
|
|
285
285
|
//#endregion
|
|
286
|
-
export { instrumentDrizzle,
|
|
286
|
+
export { instrumentDrizzle, withCtx };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SilgiError } from "../../core/error.mjs";
|
|
2
|
+
import { Client } from "../../client/types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/hey-api/to-client.d.ts
|
|
5
|
+
type ToClientResult<T extends Record<string, any>> = { [K in keyof T]: T[K] extends ((options: infer UInput) => Promise<infer UResult>) ? Client<Record<never, never>, UInput, {
|
|
6
|
+
body: UResult extends {
|
|
7
|
+
data: infer USuccess;
|
|
8
|
+
} ? Exclude<USuccess, undefined> : never;
|
|
9
|
+
request: Request;
|
|
10
|
+
response: Response;
|
|
11
|
+
}, SilgiError> : T[K] extends Record<string, any> ? ToClientResult<T[K]> : never };
|
|
12
|
+
/**
|
|
13
|
+
* Convert a Hey API SDK to a Silgi client.
|
|
14
|
+
*
|
|
15
|
+
* This allows you to use any Hey API generated client with the Silgi
|
|
16
|
+
* ecosystem — including TanStack Query, Pinia Colada, and other integrations.
|
|
17
|
+
*/
|
|
18
|
+
declare function toClient<T extends Record<string, any>>(sdk: T): ToClientResult<T>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ToClientResult, toClient };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/integrations/hey-api/to-client.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert a Hey API SDK to a Silgi client.
|
|
4
|
+
*
|
|
5
|
+
* This allows you to use any Hey API generated client with the Silgi
|
|
6
|
+
* ecosystem — including TanStack Query, Pinia Colada, and other integrations.
|
|
7
|
+
*/
|
|
8
|
+
function toClient(sdk) {
|
|
9
|
+
const client = {};
|
|
10
|
+
for (const key in sdk) {
|
|
11
|
+
const fn = sdk[key];
|
|
12
|
+
if (!fn || typeof fn !== "function") continue;
|
|
13
|
+
client[key] = async (input, options) => {
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
if (input?.signal?.aborted || options?.signal?.aborted) controller.abort();
|
|
16
|
+
else {
|
|
17
|
+
input?.signal?.addEventListener("abort", () => controller.abort());
|
|
18
|
+
options?.signal?.addEventListener("abort", () => controller.abort());
|
|
19
|
+
}
|
|
20
|
+
const result = await fn({
|
|
21
|
+
...input,
|
|
22
|
+
signal: controller.signal,
|
|
23
|
+
headers: {
|
|
24
|
+
...input?.headers,
|
|
25
|
+
...typeof options?.lastEventId === "string" ? { "last-event-id": options.lastEventId } : {}
|
|
26
|
+
},
|
|
27
|
+
throwOnError: true
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
body: result.data,
|
|
31
|
+
request: result.request,
|
|
32
|
+
response: result.response
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return client;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { toClient };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BuildKeyOptions } from "./key.mjs";
|
|
2
|
+
import { EntryKey } from "@pinia/colada";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/pinia-colada/general-utils.d.ts
|
|
5
|
+
interface GeneralUtils<TInput> {
|
|
6
|
+
/**
|
|
7
|
+
* Generate a query/mutation key for checking status, invalidate, set, get, etc.
|
|
8
|
+
*/
|
|
9
|
+
key(options?: BuildKeyOptions<TInput>): EntryKey;
|
|
10
|
+
}
|
|
11
|
+
declare function createGeneralUtils<TInput>(path: string[]): GeneralUtils<TInput>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { GeneralUtils, createGeneralUtils };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BuildKeyOptions, PartialDeep, buildKey } from "./key.mjs";
|
|
2
|
+
import { GeneralUtils, createGeneralUtils } from "./general-utils.mjs";
|
|
3
|
+
import { MaybeOptionalOptions, MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn, SetOptional, UseQueryFnContext } from "./types.mjs";
|
|
4
|
+
import { CreateProcedureUtilsOptions, ProcedureUtils, createProcedureUtils } from "./procedure-utils.mjs";
|
|
5
|
+
import { CreateRouterUtilsOptions, RouterUtils, createRouterUtils } from "./router-utils.mjs";
|
|
6
|
+
export { BuildKeyOptions, CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, MaybeOptionalOptions, MutationOptions, MutationOptionsIn, PartialDeep, ProcedureUtils, QueryOptions, QueryOptionsIn, RouterUtils, SetOptional, UseQueryFnContext, buildKey, createRouterUtils as createColadaUtils, createGeneralUtils, createProcedureUtils, createRouterUtils };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { buildKey } from "./key.mjs";
|
|
2
|
+
import { createGeneralUtils } from "./general-utils.mjs";
|
|
3
|
+
import { createProcedureUtils } from "./procedure-utils.mjs";
|
|
4
|
+
import { createRouterUtils } from "./router-utils.mjs";
|
|
5
|
+
export { buildKey, createRouterUtils as createColadaUtils, createGeneralUtils, createProcedureUtils, createRouterUtils };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntryKey } from "@pinia/colada";
|
|
2
|
+
|
|
3
|
+
//#region src/integrations/pinia-colada/key.d.ts
|
|
4
|
+
type PartialDeep<T> = T extends object ? { [K in keyof T]?: PartialDeep<T[K]> } : T;
|
|
5
|
+
interface BuildKeyOptions<TInput> {
|
|
6
|
+
type?: 'query' | 'mutation';
|
|
7
|
+
input?: PartialDeep<TInput>;
|
|
8
|
+
}
|
|
9
|
+
declare function buildKey<TInput>(path: string[], options?: BuildKeyOptions<TInput>): EntryKey;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { BuildKeyOptions, PartialDeep, buildKey };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/integrations/pinia-colada/key.ts
|
|
2
|
+
function buildKey(path, options = {}) {
|
|
3
|
+
const withInput = options.input !== void 0 ? { input: options.input } : {};
|
|
4
|
+
const withType = options.type !== void 0 ? { type: options.type } : {};
|
|
5
|
+
return [path, {
|
|
6
|
+
...withInput,
|
|
7
|
+
...withType
|
|
8
|
+
}];
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { buildKey };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Client, ClientContext } from "../../client/types.mjs";
|
|
2
|
+
import { MaybeOptionalOptions, MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn } from "./types.mjs";
|
|
3
|
+
import { _EmptyObject } from "@pinia/colada";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/pinia-colada/procedure-utils.d.ts
|
|
6
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
7
|
+
/**
|
|
8
|
+
* Calling corresponding procedure client
|
|
9
|
+
*/
|
|
10
|
+
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
11
|
+
/**
|
|
12
|
+
* Generate options used for useQuery
|
|
13
|
+
*/
|
|
14
|
+
queryOptions<UInitialData extends TOutput | undefined = TOutput | undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, UInitialData>>): NoInfer<QueryOptions<TOutput, TError, UInitialData>>;
|
|
15
|
+
/**
|
|
16
|
+
* Generate options used for useMutation
|
|
17
|
+
*/
|
|
18
|
+
mutationOptions<UMutationContext extends Record<any, any> = _EmptyObject>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
19
|
+
}
|
|
20
|
+
interface CreateProcedureUtilsOptions {
|
|
21
|
+
path: string[];
|
|
22
|
+
}
|
|
23
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { CreateProcedureUtilsOptions, ProcedureUtils, createProcedureUtils };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { buildKey } from "./key.mjs";
|
|
2
|
+
import { computed, toValue } from "vue";
|
|
3
|
+
//#region src/integrations/pinia-colada/procedure-utils.ts
|
|
4
|
+
function createProcedureUtils(client, options) {
|
|
5
|
+
return {
|
|
6
|
+
call: client,
|
|
7
|
+
queryOptions(...[{ input, context, ...rest } = {}]) {
|
|
8
|
+
return {
|
|
9
|
+
key: computed(() => buildKey(options.path, {
|
|
10
|
+
type: "query",
|
|
11
|
+
input: toValue(input)
|
|
12
|
+
})),
|
|
13
|
+
query: ({ signal }) => client(toValue(input), {
|
|
14
|
+
signal,
|
|
15
|
+
context: toValue(context)
|
|
16
|
+
}),
|
|
17
|
+
...rest
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
mutationOptions(...[{ context, ...rest } = {}]) {
|
|
21
|
+
return {
|
|
22
|
+
key: (input) => buildKey(options.path, {
|
|
23
|
+
type: "mutation",
|
|
24
|
+
input
|
|
25
|
+
}),
|
|
26
|
+
mutation: (input) => client(input, { context: toValue(context) }),
|
|
27
|
+
...rest
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createProcedureUtils };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Client, NestedClient } from "../../client/types.mjs";
|
|
2
|
+
import { GeneralUtils } from "./general-utils.mjs";
|
|
3
|
+
import { ProcedureUtils } from "./procedure-utils.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/pinia-colada/router-utils.d.ts
|
|
6
|
+
type RouterUtils<T extends NestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : { [K in keyof T]: T[K] extends NestedClient ? RouterUtils<T[K]> : never } & GeneralUtils<unknown>;
|
|
7
|
+
interface CreateRouterUtilsOptions {
|
|
8
|
+
path?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create Pinia Colada utilities from a Silgi client.
|
|
12
|
+
*
|
|
13
|
+
* Both client-side and server-side clients are supported.
|
|
14
|
+
*/
|
|
15
|
+
declare function createRouterUtils<T extends NestedClient>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { CreateRouterUtilsOptions, RouterUtils, createRouterUtils };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createGeneralUtils } from "./general-utils.mjs";
|
|
2
|
+
import { createProcedureUtils } from "./procedure-utils.mjs";
|
|
3
|
+
//#region src/integrations/pinia-colada/router-utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create Pinia Colada utilities from a Silgi client.
|
|
6
|
+
*
|
|
7
|
+
* Both client-side and server-side clients are supported.
|
|
8
|
+
*/
|
|
9
|
+
function createRouterUtils(client, options = {}) {
|
|
10
|
+
const path = options.path ?? [];
|
|
11
|
+
const generalUtils = createGeneralUtils(path);
|
|
12
|
+
const procedureUtils = createProcedureUtils(client, { path });
|
|
13
|
+
return new Proxy({
|
|
14
|
+
...generalUtils,
|
|
15
|
+
...procedureUtils
|
|
16
|
+
}, { get(target, prop) {
|
|
17
|
+
const value = Reflect.get(target, prop);
|
|
18
|
+
if (typeof prop !== "string") return value;
|
|
19
|
+
const nextUtils = createRouterUtils(client[prop], {
|
|
20
|
+
...options,
|
|
21
|
+
path: [...path, prop]
|
|
22
|
+
});
|
|
23
|
+
if (typeof value !== "function") return nextUtils;
|
|
24
|
+
return new Proxy(value, { get(_, prop) {
|
|
25
|
+
return Reflect.get(nextUtils, prop);
|
|
26
|
+
} });
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createRouterUtils };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ClientContext } from "../../client/types.mjs";
|
|
2
|
+
import { MaybeRefOrGetter } from "vue";
|
|
3
|
+
import { UseMutationOptions, UseQueryOptions } from "@pinia/colada";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/pinia-colada/types.d.ts
|
|
6
|
+
type SetOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
7
|
+
type MaybeOptionalOptions<T> = Partial<T> extends T ? [options?: T] : [options: T];
|
|
8
|
+
type UseQueryFnContext = Parameters<UseQueryOptions<any>['query']>[0];
|
|
9
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TInitialData extends TOutput | undefined> = (undefined extends TInput ? {
|
|
10
|
+
input?: MaybeRefOrGetter<TInput>;
|
|
11
|
+
} : {
|
|
12
|
+
input: MaybeRefOrGetter<TInput>;
|
|
13
|
+
}) & (Record<never, never> extends TClientContext ? {
|
|
14
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
|
15
|
+
} : {
|
|
16
|
+
context: MaybeRefOrGetter<TClientContext>;
|
|
17
|
+
}) & SetOptional<QueryOptions<TOutput, TError, TInitialData>, 'key' | 'query'>;
|
|
18
|
+
type QueryOptions<TOutput, TError, TInitialData extends TOutput | undefined> = UseQueryOptions<TOutput, TError, TInitialData>;
|
|
19
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext extends Record<any, any>> = (Record<never, never> extends TClientContext ? {
|
|
20
|
+
context?: MaybeRefOrGetter<TClientContext>;
|
|
21
|
+
} : {
|
|
22
|
+
context: MaybeRefOrGetter<TClientContext>;
|
|
23
|
+
}) & SetOptional<UseMutationOptions<TOutput, TInput, TError, TMutationContext>, 'mutation'>;
|
|
24
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext extends Record<any, any>> = UseMutationOptions<TOutput, TInput, TError, TMutationContext>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { MaybeOptionalOptions, MutationOptions, MutationOptionsIn, QueryOptions, QueryOptionsIn, SetOptional, UseQueryFnContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The fastest end-to-end type-safe RPC framework for TypeScript — compiled pipelines, single package, every runtime",
|
|
6
6
|
"keywords": [
|
|
@@ -83,6 +83,14 @@
|
|
|
83
83
|
"import": "./dist/integrations/tanstack-query/index.mjs",
|
|
84
84
|
"types": "./dist/integrations/tanstack-query/index.d.mts"
|
|
85
85
|
},
|
|
86
|
+
"./pinia-colada": {
|
|
87
|
+
"import": "./dist/integrations/pinia-colada/index.mjs",
|
|
88
|
+
"types": "./dist/integrations/pinia-colada/index.d.mts"
|
|
89
|
+
},
|
|
90
|
+
"./hey-api": {
|
|
91
|
+
"import": "./dist/integrations/hey-api/index.mjs",
|
|
92
|
+
"types": "./dist/integrations/hey-api/index.d.mts"
|
|
93
|
+
},
|
|
86
94
|
"./drizzle": {
|
|
87
95
|
"import": "./dist/integrations/drizzle/index.mjs",
|
|
88
96
|
"types": "./dist/integrations/drizzle/index.d.mts"
|
|
@@ -261,6 +269,7 @@
|
|
|
261
269
|
"@orpc/client": "^1.13.9",
|
|
262
270
|
"@orpc/contract": "^1.13.9",
|
|
263
271
|
"@orpc/server": "^1.13.9",
|
|
272
|
+
"@pinia/colada": "^1.0.0",
|
|
264
273
|
"@trpc/client": "^11.14.1",
|
|
265
274
|
"@trpc/server": "^11.14.1",
|
|
266
275
|
"@types/express": "^5.0.6",
|
|
@@ -281,19 +290,29 @@
|
|
|
281
290
|
"obuild": "^0.4.32",
|
|
282
291
|
"oxfmt": "^0.41.0",
|
|
283
292
|
"oxlint": "^1.56.0",
|
|
293
|
+
"pinia": "^3.0.4",
|
|
284
294
|
"rou3": "^0.8.1",
|
|
285
295
|
"tsdown": "^0.21.4",
|
|
286
296
|
"typescript": "^6.0.2",
|
|
287
297
|
"vitest": "^4.1.0",
|
|
298
|
+
"vue": "^3.5.31",
|
|
288
299
|
"ws": "^8.19.0",
|
|
289
300
|
"zod": "^4.3.6"
|
|
290
301
|
},
|
|
291
302
|
"peerDependencies": {
|
|
292
|
-
"@
|
|
303
|
+
"@pinia/colada": ">=0.16.0",
|
|
304
|
+
"@scalar/api-reference": ">=1.0.0",
|
|
305
|
+
"vue": ">=3.3.0"
|
|
293
306
|
},
|
|
294
307
|
"peerDependenciesMeta": {
|
|
295
308
|
"@scalar/api-reference": {
|
|
296
309
|
"optional": true
|
|
310
|
+
},
|
|
311
|
+
"@pinia/colada": {
|
|
312
|
+
"optional": true
|
|
313
|
+
},
|
|
314
|
+
"vue": {
|
|
315
|
+
"optional": true
|
|
297
316
|
}
|
|
298
317
|
},
|
|
299
318
|
"engines": {
|