File tree Expand file tree Collapse file tree 13 files changed +96
-67
lines changed Expand file tree Collapse file tree 13 files changed +96
-67
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " create-jd-app " : minor
3
+ ---
4
+
5
+ feat: use the builder$ api from prpc
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export default defineConfig({
19
19
external: ["@prisma/client"],
20
20
},`
21
21
: ""
22
- } ${ usePRPC ? `\n plugins: [prpcVite()],` : "" }
22
+ } ${ usePRPC ? `${ usePrisma ? "\n" : "" } plugins: [prpcVite()],` : "" }
23
23
},`
24
24
: ""
25
25
} ${
@@ -34,7 +34,11 @@ export default defineConfig({
34
34
} ;
35
35
36
36
export const modifyConfigIfNeeded = async ( ctx : ICtx ) => {
37
- if ( ctx . vercel || ctx . installers . includes ( "Prisma" ) ) {
37
+ if (
38
+ ctx . vercel ||
39
+ ctx . installers . includes ( "pRPC" ) ||
40
+ ctx . installers . includes ( "Prisma" )
41
+ ) {
38
42
await fs . writeFile (
39
43
path . join ( ctx . userDir , "app.config.ts" ) ,
40
44
getAppConfig ( ctx )
Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ const packages = {
12
12
"@prisma/client" : "^5.10.2" ,
13
13
// prpc
14
14
"@tanstack/solid-query" : "^5.28.6" ,
15
- "@solid-mediakit/prpc" : "^1.0.4 " ,
16
- "@solid-mediakit/prpc-plugin" : "^1.0.2 " ,
15
+ "@solid-mediakit/prpc" : "^1.2.1 " ,
16
+ "@solid-mediakit/prpc-plugin" : "^1.2.1 " ,
17
17
// next auth
18
18
"@solid-mediakit/auth" : "^2.0.7" ,
19
19
"@auth/core" : "^0.28.0" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { z } from "zod";
2
+ import { helloBuilder } from "../prpc";
3
+
4
+ export const helloQuery = helloBuilder
5
+ .input(
6
+ z.object({
7
+ hello: z.string(),
8
+ })
9
+ )
10
+ .query$(({ payload, ctx$ }) => {
11
+ if (payload.hello === "hello") {
12
+ return ctx$.hello;
13
+ }
14
+ return ctx$.world;
15
+ }, "myNewQuery");
Original file line number Diff line number Diff line change
1
+ import { z } from "zod";
2
+ import { userBuilder } from "../prpc";
3
+
4
+ export const protectedQuery = userBuilder
5
+ .input(
6
+ z.object({
7
+ hello: z.string(),
8
+ })
9
+ )
10
+ .query$(({ payload, ctx$ }) => {
11
+ return `this is top secret: ${payload.hello} ${ctx$.user?.name}`;
12
+ }, "myProtectedQuery");
Original file line number Diff line number Diff line change @@ -13,14 +13,18 @@ const config: IInstaller = (ctx) => {
13
13
} ) ,
14
14
files : [
15
15
{
16
- path : `${ __dirname } /utils/getQueries` ,
17
- to : `${ ctx . userDir } /src/server/queries.ts` ,
16
+ path : `${ __dirname } /files/hello.txt` ,
17
+ to : `${ ctx . userDir } /src/server/hello/hello.queries.ts` ,
18
+ } ,
19
+ {
20
+ path : `${ __dirname } /utils/getBuilder` ,
21
+ to : `${ ctx . userDir } /src/server/prpc.ts` ,
18
22
type : "exec" ,
19
23
} ,
20
24
useAuth
21
25
? {
22
- path : `${ __dirname } /files/authMw .txt` ,
23
- to : `${ ctx . userDir } /src/server/middleware .ts` ,
26
+ path : `${ __dirname } /files/user .txt` ,
27
+ to : `${ ctx . userDir } /src/server/user/user.queries .ts` ,
24
28
}
25
29
: undefined ,
26
30
] ,
Original file line number Diff line number Diff line change
1
+ import { IUtil } from "~types" ;
2
+
3
+ const getBuilder : IUtil = ( ctx ) => {
4
+ const useAuth = ctx . installers . includes ( "AuthJS" ) ;
5
+ return `import { builder$${
6
+ useAuth ? ", error$" : ""
7
+ } } from "@solid-mediakit/prpc";${
8
+ useAuth
9
+ ? `\nimport { authOptions } from "./auth";\nimport { getSession } from "@solid-mediakit/auth";`
10
+ : ""
11
+ }
12
+
13
+ export const helloBuilder = builder$()
14
+ .middleware$(() => {
15
+ return {
16
+ hello: 1,
17
+ };
18
+ })
19
+ .middleware$((ctx) => {
20
+ return {
21
+ ...ctx,
22
+ world: 2,
23
+ };
24
+ });${
25
+ useAuth
26
+ ? `\n\nexport const userBuilder = builder$().middleware$(async ({ event$ }) => {
27
+ const session = await getSession(event$.request, authOptions);
28
+ if (!session) {
29
+ return error$("Unauthorized", {
30
+ status: 401,
31
+ });
32
+ }
33
+ return session;
34
+ });`
35
+ : ""
36
+ }
37
+ ` ;
38
+ } ;
39
+
40
+ export default getBuilder ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import { type VoidComponent , Suspense , Show } from "solid-js" ;
2
2
import { A } from "@solidjs/router" ;
3
3
import { createSession , signOut , signIn } from "@solid-mediakit/auth/client" ;
4
- import { testQuery } from "~/server/queries" ;
4
+ import { helloQuery } from "~/server/hello/hello. queries" ;
5
5
6
6
const Home : VoidComponent = ( ) => {
7
- const hello = testQuery ( ( ) => ( { hello : "from pRPC" } ) ) ;
7
+ const hello = helloQuery ( ( ) => ( { hello : "from pRPC" } ) ) ;
8
8
return (
9
9
< main class = "flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#026d56] to-[#152a2c]" >
10
10
< div class = "container flex flex-col items-center justify-center gap-12 px-4 py-16 " >
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ import styles from "./index.module.css";
2
2
import { type VoidComponent , Suspense , Show } from "solid-js" ;
3
3
import { A } from "@solidjs/router" ;
4
4
import { createSession , signOut , signIn } from "@solid-mediakit/auth/client" ;
5
- import { testQuery } from "~/server/queries" ;
5
+ import { helloQuery } from "~/server/hello/hello. queries" ;
6
6
7
7
const Home : VoidComponent = ( ) => {
8
- const hello = testQuery ( ( ) => ( { hello : "from pRPC" } ) ) ;
8
+ const hello = helloQuery ( ( ) => ( { hello : "from pRPC" } ) ) ;
9
9
return (
10
10
< main >
11
11
< div class = { styles . container } >
Original file line number Diff line number Diff line change 1
1
import { type VoidComponent } from "solid-js" ;
2
2
import { A } from "@solidjs/router" ;
3
- import { testQuery } from "~/server/queries" ;
3
+ import { helloQuery } from "~/server/hello/hello. queries" ;
4
4
5
5
const Home : VoidComponent = ( ) => {
6
- const hello = testQuery ( ( ) => ( {
7
- hello : "from pRPC" ,
8
- } ) ) ;
6
+ const hello = helloQuery ( ( ) => ( { hello : "from pRPC" } ) ) ;
9
7
return (
10
8
< main class = "flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#026d56] to-[#152a2c]" >
11
9
< div class = "container flex flex-col items-center justify-center gap-12 px-4 py-16 " >
Original file line number Diff line number Diff line change 1
1
import { type VoidComponent } from "solid-js" ;
2
2
import { A } from "@solidjs/router" ;
3
3
import styles from "./index.module.css" ;
4
- import { testQuery } from "~/server/queries" ;
4
+ import { helloQuery } from "~/server/hello/hello. queries" ;
5
5
6
6
const Home : VoidComponent = ( ) => {
7
- const hello = testQuery ( ( ) => ( {
8
- hello : "from pRPC" ,
9
- } ) ) ;
7
+ const hello = helloQuery ( ( ) => ( { hello : "from pRPC" } ) ) ;
10
8
return (
11
9
< main >
12
10
< div class = { styles . container } >
You can’t perform that action at this time.
0 commit comments