-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
153 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as trpcCli from 'trpc-cli' | ||
import {router} from './router' | ||
|
||
export const cli = trpcCli.createCli({router}) | ||
|
||
void cli.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {Client, createClient} from '@pgkit/client' | ||
import {Migrator, createMigratorRouter} from '@pgkit/migrator' | ||
import {confirm} from '@pgkit/migrator/dist/cli' | ||
import {router as typegenRouter} from '@pgkit/typegen' | ||
import express from 'express' | ||
import * as trpcCli from 'trpc-cli' | ||
import {z} from 'trpc-cli' | ||
import {loadConfig} from './config' | ||
|
||
const t = trpcCli.trpcServer.initTRPC.meta<trpcCli.TrpcCliMeta>().create() | ||
|
||
const procedureWithClient = t.procedure.use(async ({ctx, next}) => { | ||
const config = await loadConfig() | ||
const client = (clientSingleton.client ||= createClient(config.client.connectionString)) | ||
const migrator = (clientSingleton.migrator ||= new Migrator({ | ||
client, | ||
migrationsPath: config.migrator?.migrationsPath, | ||
migrationTableName: config.migrator?.migrationTableName, | ||
})) | ||
return next({ | ||
ctx: {...ctx, client, migrator}, | ||
}) | ||
}) | ||
|
||
const clientSingleton = { | ||
client: null as null | Client, | ||
migrator: null as null | Migrator, | ||
} | ||
|
||
export const router = t.router({ | ||
migrate: createMigratorRouter( | ||
procedureWithClient.use(async ({ctx, next}) => { | ||
return next({ctx: {...ctx, confirm}}) | ||
}), | ||
), | ||
...typegenRouter._def.procedures, | ||
admin: procedureWithClient | ||
.input( | ||
z.object({ | ||
port: z.number().default(7002), | ||
}), | ||
) | ||
.mutation(async ({input, ctx}) => { | ||
const {getExpressRouter} = await import('@pgkit/admin') | ||
const app = express() | ||
app.use(getExpressRouter(ctx.client)) | ||
app.listen(input.port, () => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Admin UI listening on http://localhost:${input.port}`) | ||
}) | ||
return new Promise(_r => {}) | ||
}), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
{ | ||
"extends": [ | ||
"./tsconfig.json" | ||
], | ||
"include": [ | ||
"src" | ||
], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"noEmit": false, | ||
"module": "Node16" | ||
} | ||
"extends": ["./tsconfig.json"], | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"noEmit": false, | ||
"skipLibCheck": true, | ||
"module": "Node16" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.