-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
2a46f4c
commit 7427ac6
Showing
24 changed files
with
415 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,4 @@ shrinkwrap.yaml | |
package-lock.json | ||
todo.md | ||
.adonisjs | ||
playground/public/assets | ||
public/assets | ||
**/*/public/assets |
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
Empty file.
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,12 +1,66 @@ | ||
{ | ||
"name": "inertia", | ||
"name": "@tuyau/inertia", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"description": "", | ||
"author": "Julien Ripouteau <[email protected]>", | ||
"license": "ISC", | ||
"keywords": [], | ||
"exports": { | ||
".": "./build/index.js", | ||
"./react": "./build/react/index.js", | ||
"./types": "./build/types.js" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "eslint .", | ||
"typecheck": "tsc --noEmit", | ||
"build": "tsup-node && tsc --emitDeclarationOnly --declaration", | ||
"test": "c8 node --enable-source-maps --loader ts-node/esm bin/test.ts", | ||
"quick:test": "node --enable-source-maps --loader ts-node/esm bin/test.ts", | ||
"checks": "pnpm lint && pnpm typecheck" | ||
}, | ||
"peerDependencies": { | ||
"@inertiajs/react": "^1.0.16", | ||
"@inertiajs/vue3": "^1.0.16", | ||
"@tuyau/client": "workspace:*", | ||
"react": "^18.3.1", | ||
"solid-js": "^1.8.17", | ||
"vue": "^3.4.27" | ||
}, | ||
"peerDependenciesMeta": { | ||
"react": { | ||
"optional": true | ||
}, | ||
"vue": { | ||
"optional": true | ||
}, | ||
"@inertiajs/react": { | ||
"optional": true | ||
}, | ||
"@inertiajs/vue3": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"@inertiajs/react": "^1.0.16", | ||
"@inertiajs/vue3": "^1.0.16", | ||
"@tuyau/client": "workspace:*", | ||
"@types/react": "^18.3.1", | ||
"react": "^18.3.1", | ||
"solid-js": "^1.8.17", | ||
"vue": "^3.4.27" | ||
}, | ||
"tsup": { | ||
"entry": [ | ||
"./src/index.ts", | ||
"./src/react/index.tsx", | ||
"./src/types.ts" | ||
], | ||
"outDir": "./build", | ||
"clean": true, | ||
"format": "esm", | ||
"dts": false, | ||
"target": "esnext" | ||
} | ||
} |
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 @@ | ||
console.log('hey') |
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,42 @@ | ||
import React from 'react' | ||
import { Link as InertiaLink } from '@inertiajs/react' | ||
import type { TuyauClient, RouteName, RoutesNameParams } from '@tuyau/client' | ||
|
||
import type { AssertedApi } from '../types.js' | ||
|
||
const TuyauContext = React.createContext<TuyauClient<any, any> | null>(null) | ||
|
||
export const TuyauProvider = (props: { | ||
children: React.ReactNode | ||
client: TuyauClient<any, any> | ||
}) => <TuyauContext.Provider value={props.client}>{props.children}</TuyauContext.Provider> | ||
|
||
export const useTuyau = () => React.useContext(TuyauContext) | ||
|
||
type LinkProps<Route extends RouteName<AssertedApi['routes']>> = Omit< | ||
React.ComponentPropsWithoutRef<typeof InertiaLink>, | ||
'href' | 'method' | ||
> & { | ||
route: Route | ||
params: RoutesNameParams<AssertedApi['routes'], Route> | ||
} | ||
|
||
function LinkInner<Route extends RouteName<AssertedApi['routes']>>( | ||
props: LinkProps<Route>, | ||
ref?: React.ForwardedRef<React.ElementRef<typeof InertiaLink>>, | ||
) { | ||
const tuyau = useTuyau() | ||
if (!tuyau) throw new Error('You must wrap your app in a TuyauProvider') | ||
|
||
const result = tuyau.$route(props.route, props.params as any) | ||
|
||
console.log(result) | ||
|
||
return <InertiaLink {...props} href={result.path} method={result.method[0]} ref={ref} /> | ||
} | ||
|
||
export const Link: <Route extends RouteName<AssertedApi['routes']>>( | ||
props: LinkProps<Route> & { | ||
ref?: React.Ref<React.ElementRef<typeof InertiaLink>> | ||
}, | ||
) => ReturnType<typeof LinkInner> = React.forwardRef(LinkInner) as any |
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,13 @@ | ||
import type { GeneratedRoutes } from '@tuyau/client' | ||
|
||
/** | ||
* To be extended user-side with module augmentation | ||
*/ | ||
export interface Api {} | ||
|
||
export type AssertedApi = Api extends { | ||
routes: GeneratedRoutes | ||
definition: Record<string, any> | ||
} | ||
? Api | ||
: never |
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
49 changes: 49 additions & 0 deletions
49
playgrounds/inertia-react/app/controllers/comments_controller.ts
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,49 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
export default class CommentsController { | ||
/** | ||
* Display a list of resource | ||
*/ | ||
async index({}: HttpContext) {} | ||
|
||
/** | ||
* Display form to create a new record | ||
*/ | ||
async create({}: HttpContext) {} | ||
|
||
/** | ||
* Handle form submission for the create action | ||
*/ | ||
async store({}: HttpContext) {} | ||
|
||
/** | ||
* Show individual record | ||
*/ | ||
async show({}: HttpContext) {} | ||
|
||
/** | ||
* Edit individual record | ||
*/ | ||
async edit({}: HttpContext) { | ||
return [ | ||
{ | ||
id: 1, | ||
body: 'Hello world', | ||
user: { | ||
id: 1, | ||
email: '[email protected]', | ||
}, | ||
}, | ||
] | ||
} | ||
|
||
/** | ||
* Handle form submission for the edit action | ||
*/ | ||
async update({}: HttpContext) {} | ||
|
||
/** | ||
* Delete record | ||
*/ | ||
async destroy({}: HttpContext) {} | ||
} |
11 changes: 11 additions & 0 deletions
11
playgrounds/inertia-react/app/controllers/inertia_controller.ts
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,11 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
export default class InertiaController { | ||
async index({ inertia }: HttpContext) { | ||
return inertia.render('home', { version: '6.0' }) | ||
} | ||
|
||
async backoffice({ inertia }: HttpContext) { | ||
return inertia.render('backoffice', { version: '6.0' }) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
playgrounds/inertia-react/app/controllers/posts_controller.ts
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,40 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
export default class PostsController { | ||
/** | ||
* Display a list of resource | ||
*/ | ||
async index({}: HttpContext) {} | ||
|
||
/** | ||
* Display form to create a new record | ||
*/ | ||
async create({ request, inertia }: HttpContext) { | ||
return inertia.render('posts/create') | ||
} | ||
|
||
/** | ||
* Handle form submission for the create action | ||
*/ | ||
async store({}: HttpContext) {} | ||
|
||
/** | ||
* Show individual record | ||
*/ | ||
async show({}: HttpContext) {} | ||
|
||
/** | ||
* Edit individual record | ||
*/ | ||
async edit({}: HttpContext) {} | ||
|
||
/** | ||
* Handle form submission for the edit action | ||
*/ | ||
async update({}: HttpContext) {} | ||
|
||
/** | ||
* Delete record | ||
*/ | ||
async destroy({}: HttpContext) {} | ||
} |
35 changes: 35 additions & 0 deletions
35
playgrounds/inertia-react/app/controllers/users_controller.ts
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,35 @@ | ||
import app from '@adonisjs/core/services/app' | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
import { getUsersValidator, uploadFileValidator } from '../validators/main.js' | ||
|
||
export default class UsersController { | ||
async index({ response, request }: HttpContext) { | ||
await request.validateUsing(getUsersValidator) | ||
|
||
if (Math.random() > 0.5) { | ||
return response.badGateway('Something went wrong' as const) | ||
} | ||
|
||
if (Math.random() > 0.5) { | ||
return response.badRequest({ message: 'Invalid request' as const }) | ||
} | ||
|
||
return { | ||
users: [ | ||
{ id: 1, name: 'John Doe' }, | ||
{ id: 2, name: 'Jane Doe' }, | ||
], | ||
} | ||
} | ||
|
||
async simpleText() { | ||
return 'foo' as const | ||
} | ||
|
||
async fileUpload({ request }: HttpContext) { | ||
const payload = await request.validateUsing(uploadFileValidator) | ||
await payload.file.move(app.makePath('uploads')) | ||
return { message: 'File uploaded' as const } | ||
} | ||
} |
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,17 @@ | ||
import { defineConfig } from '@tuyau/core' | ||
|
||
const tuyauConfig = defineConfig({ | ||
codegen: { | ||
/** | ||
* Filters the definitions and named routes to be generated | ||
*/ | ||
// definitions: { | ||
// only: [], | ||
// } | ||
// routes: { | ||
// only: [], | ||
// } | ||
} | ||
}) | ||
|
||
export default tuyauConfig | ||
Oops, something went wrong.