Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lewis-wow/tsrex
https://github.com/lewis-wow/tsrex
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/lewis-wow/tsrex
- Owner: lewis-wow
- License: mit
- Created: 2024-10-15T11:37:39.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-10-17T19:41:57.000Z (2 months ago)
- Last Synced: 2024-10-20T05:52:40.807Z (2 months ago)
- Language: MDX
- Size: 38.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ptsq
Public type-safe query
[![codecov](https://codecov.io/gh/lewis-wow/ptsq/graph/badge.svg?token=18BSO2G62X)](https://codecov.io/gh/lewis-wow/ptsq)
## Installation
```bash
npm i @ptsq/server
``````bash
npm i @ptsq/client
``````bash
npm i -D @ptsq/introspection-cli
``````ts title="server.ts"
import { ptsq } from '@ptsq/server';
import { Type } from '@sinclair/typebox';
import express, { Request, Response } from 'express';const app = express();
const createContext = ({ req, res }: { req: Request; res: Response }) => ({
req,
res,
});const { resolver, router, serve } = ptsq({
ctx: createContext,
}).create();const testQuery = resolver
.args(Type.Object({ name: Type.String() }))
.output(Type.String())
.query(
async ({
ctx /* { req: express.Request, res: express.Response } */,
input /* { name: string } */,
}) => {
return `Hello, ${input.name}`;
},
);const baseRouter = router({
test: testQuery,
});app.use((req, res) => serve(baseRouter)(req, res));
app.listen(4000);
``````ts title="client.ts"
import { createProxyClient } from '@ptsq/client';
import type { BaseRouter } from './server';const client = createProxyClient({
url: 'http://localhost:4000/ptsq/',
});const result /* string */ = await client.test.query({
name: /* string */ 'John',
});
``````ts title="remote-client.ts"
import { createProxyClient } from '@ptsq/client';
import type { BaseRouter } from './introspected-schema';const client = createProxyClient({
url: 'http://localhost:4000/ptsq/',
});const result /* string */ = await client.test.query({
name: /* string */ 'John',
});
```