diff --git a/packages/client/src/errors.ts b/packages/client/src/errors.ts index ffbe8bd..b5e2df8 100644 --- a/packages/client/src/errors.ts +++ b/packages/client/src/errors.ts @@ -1,9 +1,10 @@ export class TuyauHTTPError extends Error { constructor( public status: number, - public data: unknown, + public value: unknown, ) { - super(data + '') + super(value + '') this.name = 'TuyauHTTPError' + this.value = value } } diff --git a/packages/codegen/package.json b/packages/codegen/package.json index 81442f2..b818cd9 100644 --- a/packages/codegen/package.json +++ b/packages/codegen/package.json @@ -29,7 +29,7 @@ "test": "c8 npm run quick:test", "index:commands": "adonis-kit index build/commands", "prebuild": "npm run lint && npm run clean", - "build": "pnpm clean && tsc && pnpm copy:templates && pnpm index:commands", + "build": "pnpm clean && tsup-node && pnpm copy:templates && pnpm index:commands", "release": "pnpm build && pnpm release-it", "version": "npm run build", "prepublishOnly": "npm run build" @@ -43,6 +43,7 @@ "devDependencies": { "@adonisjs/assembler": "^7.4.0", "@adonisjs/core": "^6.5.0", + "@julr/tooling-configs": "^2.2.0", "@poppinss/matchit": "^3.1.2", "@tuyau/client": "workspace:*", "@tuyau/utils": "workspace:*", @@ -72,5 +73,18 @@ "releaseName": "@tuyau/codegen@${version}", "web": true } + }, + "tsup": { + "entry": [ + "./index.ts", + "./src/types.ts", + "./commands/main.ts", + "./providers/tuyau_provider.ts" + ], + "outDir": "./build", + "clean": true, + "format": "esm", + "dts": true, + "target": "esnext" } } diff --git a/playground/.gitignore b/playground/.gitignore deleted file mode 100644 index 4e9b445..0000000 --- a/playground/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# Dependencies and AdonisJS build -node_modules -build -tmp - -# Secrets -.env -.env.local -.env.production.local -.env.development.local - -# Frontend assets compiled code -public/assets - -# Build tools specific -npm-debug.log -yarn-error.log - -# Editors specific -.fleet -.idea -.vscode - -# Platform specific -.DS_Store diff --git a/playground/ace.js b/playground/ace.js index d47f53a..dbf9003 100644 --- a/playground/ace.js +++ b/playground/ace.js @@ -20,6 +20,7 @@ * Register hook to process TypeScript files using ts-node */ import { register } from 'node:module' + register('ts-node/esm', import.meta.url) /** diff --git a/playground/adonisrc.ts b/playground/adonisrc.ts index 5abbd4b..e7e0cb1 100644 --- a/playground/adonisrc.ts +++ b/playground/adonisrc.ts @@ -1,5 +1,5 @@ +import { relative } from 'node:path' import { defineConfig } from '@adonisjs/core/app' -import { relative } from 'path'; export default defineConfig({ /* @@ -11,7 +11,11 @@ export default defineConfig({ | will be scanned automatically from the "./commands" directory. | */ - commands: [() => import('@adonisjs/core/commands'), () => import('@adonisjs/lucid/commands'), () => import('@tuyau/codegen/commands')], + commands: [ + () => import('@adonisjs/core/commands'), + () => import('@adonisjs/lucid/commands'), + () => import('@tuyau/codegen/commands'), + ], /* |-------------------------------------------------------------------------- @@ -39,7 +43,7 @@ export default defineConfig({ () => import('@adonisjs/lucid/database_provider'), () => import('@adonisjs/auth/auth_provider'), () => import('@adonisjs/inertia/inertia_provider'), - () => import('@tuyau/codegen/tuyau_provider') + () => import('@tuyau/codegen/tuyau_provider'), ], /* @@ -71,7 +75,7 @@ export default defineConfig({ { files: ['tests/functional/**/*.spec(.ts|.js)'], name: 'functional', - timeout: 30000, + timeout: 30_000, }, ], forceExit: false, @@ -108,16 +112,16 @@ export default defineConfig({ async () => ({ default: (ui, message, actions) => { if (message.type === 'hot-hook:full-reload') { - const path = relative(import.meta.dirname, message.path || message.paths[0]); + const path = relative(import.meta.dirname, message.path || message.paths[0]) - ui.logger.log(`${ui.colors.green('full-reload')} due to ${ui.colors.cyan(path)}`); - actions.restartServer(); + ui.logger.log(`${ui.colors.green('full-reload')} due to ${ui.colors.cyan(path)}`) + actions.restartServer() } if (message.type === 'hot-hook:invalidated') { - const path = relative(import.meta.dirname, message.path || message.paths[0]); + const path = relative(import.meta.dirname, message.path || message.paths[0]) - ui.logger.log(`${ui.colors.yellow('invalidated')} ${ui.colors.cyan(path)}`); + ui.logger.log(`${ui.colors.yellow('invalidated')} ${ui.colors.cyan(path)}`) } }, }), diff --git a/playground/app/controllers/users_controller.ts b/playground/app/controllers/users_controller.ts index b80019a..c8291d3 100644 --- a/playground/app/controllers/users_controller.ts +++ b/playground/app/controllers/users_controller.ts @@ -1,9 +1,9 @@ import type { HttpContext } from '@adonisjs/core/http' -\ + export default class UsersController { index({ response }: HttpContext) { if (Math.random() > 0.5) { - return response.badGateway('Somethisdng went wrong' as const) + return response.badGateway('Something went wrong' as const) } if (Math.random() > 0.5) { diff --git a/playground/app/exceptions/handler.ts b/playground/app/exceptions/handler.ts index 0ab9d3b..9e205cf 100644 --- a/playground/app/exceptions/handler.ts +++ b/playground/app/exceptions/handler.ts @@ -1,5 +1,6 @@ import app from '@adonisjs/core/services/app' -import { HttpContext, ExceptionHandler } from '@adonisjs/core/http' +import type { HttpContext } from '@adonisjs/core/http' +import { ExceptionHandler } from '@adonisjs/core/http' import type { StatusPageRange, StatusPageRenderer } from '@adonisjs/core/types/http' export default class HttpExceptionHandler extends ExceptionHandler { diff --git a/playground/app/middleware/auth_middleware.ts b/playground/app/middleware/auth_middleware.ts index 6e07003..40f9bbb 100644 --- a/playground/app/middleware/auth_middleware.ts +++ b/playground/app/middleware/auth_middleware.ts @@ -17,9 +17,9 @@ export default class AuthMiddleware { next: NextFn, options: { guards?: (keyof Authenticators)[] - } = {} + } = {}, ) { await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo }) return next() } -} \ No newline at end of file +} diff --git a/playground/app/middleware/container_bindings_middleware.ts b/playground/app/middleware/container_bindings_middleware.ts index 48e6d09..97abc83 100644 --- a/playground/app/middleware/container_bindings_middleware.ts +++ b/playground/app/middleware/container_bindings_middleware.ts @@ -1,6 +1,6 @@ import { Logger } from '@adonisjs/core/logger' import { HttpContext } from '@adonisjs/core/http' -import { NextFn } from '@adonisjs/core/types/http' +import type { NextFn } from '@adonisjs/core/types/http' /** * The container bindings middleware binds classes to their request diff --git a/playground/app/models/user.ts b/playground/app/models/user.ts index 631827f..d87197f 100644 --- a/playground/app/models/user.ts +++ b/playground/app/models/user.ts @@ -30,4 +30,4 @@ export default class User extends compose(BaseModel, AuthFinder) { declare updatedAt: DateTime | null static accessTokens = DbAccessTokensProvider.forModel(User) -} \ No newline at end of file +} diff --git a/playground/bin/console.ts b/playground/bin/console.ts index 4b102ee..71c6b86 100644 --- a/playground/bin/console.ts +++ b/playground/bin/console.ts @@ -12,6 +12,7 @@ */ import 'reflect-metadata' + import { Ignitor, prettyPrintError } from '@adonisjs/core' /** diff --git a/playground/bin/server.ts b/playground/bin/server.ts index fe0fefb..60b62f5 100644 --- a/playground/bin/server.ts +++ b/playground/bin/server.ts @@ -10,6 +10,7 @@ */ import 'reflect-metadata' + import { Ignitor, prettyPrintError } from '@adonisjs/core' /** diff --git a/playground/bin/test.ts b/playground/bin/test.ts index d759efe..5659ee7 100644 --- a/playground/bin/test.ts +++ b/playground/bin/test.ts @@ -10,12 +10,13 @@ | */ -process.env.NODE_ENV = 'test' - import 'reflect-metadata' + import { Ignitor, prettyPrintError } from '@adonisjs/core' import { configure, processCLIArgs, run } from '@japa/runner' +process.env.NODE_ENV = 'test' + /** * URL to the application root. AdonisJS need it to resolve * paths to file and directories for scaffolding commands @@ -49,10 +50,9 @@ new Ignitor(APP_ROOT, { importer: IMPORTER }) configure({ ...app.rcFile.tests, ...config, - ...{ - setup: runnerHooks.setup, - teardown: runnerHooks.teardown.concat([() => app.terminate()]), - }, + + setup: runnerHooks.setup, + teardown: runnerHooks.teardown.concat([() => app.terminate()]), }) }) .run(() => run()) diff --git a/playground/config/app.ts b/playground/config/app.ts index 1292af7..797be00 100644 --- a/playground/config/app.ts +++ b/playground/config/app.ts @@ -1,8 +1,9 @@ -import env from '#start/env' import app from '@adonisjs/core/services/app' import { Secret } from '@adonisjs/core/helpers' import { defineConfig } from '@adonisjs/core/http' +import env from '#start/env' + /** * The app key is used for encrypting cookies, generating signed URLs, * and by the "encryption" module. diff --git a/playground/config/auth.ts b/playground/config/auth.ts index a03af35..350dbc0 100644 --- a/playground/config/auth.ts +++ b/playground/config/auth.ts @@ -1,5 +1,5 @@ import { defineConfig } from '@adonisjs/auth' -import { InferAuthEvents, Authenticators } from '@adonisjs/auth/types' +import type { InferAuthEvents, Authenticators } from '@adonisjs/auth/types' import { tokensGuard, tokensUserProvider } from '@adonisjs/auth/access_tokens' const authConfig = defineConfig({ @@ -8,7 +8,7 @@ const authConfig = defineConfig({ api: tokensGuard({ provider: tokensUserProvider({ tokens: 'accessTokens', - model: () => import('#models/user') + model: () => import('#models/user'), }), }), }, @@ -25,4 +25,4 @@ declare module '@adonisjs/auth/types' { } declare module '@adonisjs/core/types' { interface EventsList extends InferAuthEvents {} -} \ No newline at end of file +} diff --git a/playground/config/database.ts b/playground/config/database.ts index ed32052..4281077 100644 --- a/playground/config/database.ts +++ b/playground/config/database.ts @@ -7,7 +7,7 @@ const dbConfig = defineConfig({ sqlite: { client: 'better-sqlite3', connection: { - filename: app.tmpPath('db.sqlite3') + filename: app.tmpPath('db.sqlite3'), }, useNullAsDefault: true, migrations: { @@ -18,4 +18,4 @@ const dbConfig = defineConfig({ }, }) -export default dbConfig \ No newline at end of file +export default dbConfig diff --git a/playground/config/hash.ts b/playground/config/hash.ts index ab10300..1f2d57e 100644 --- a/playground/config/hash.ts +++ b/playground/config/hash.ts @@ -5,10 +5,10 @@ const hashConfig = defineConfig({ list: { scrypt: drivers.scrypt({ - cost: 16384, + cost: 16_384, blockSize: 8, parallelization: 1, - maxMemory: 33554432, + maxMemory: 33_554_432, }), }, }) diff --git a/playground/config/inertia.ts b/playground/config/inertia.ts index 1e33d59..c94e891 100644 --- a/playground/config/inertia.ts +++ b/playground/config/inertia.ts @@ -18,6 +18,6 @@ export default defineConfig({ */ ssr: { enabled: false, - entrypoint: 'inertia/app/ssr.tsx' - } + entrypoint: 'inertia/app/ssr.tsx', + }, }) diff --git a/playground/config/logger.ts b/playground/config/logger.ts index b961300..3b88614 100644 --- a/playground/config/logger.ts +++ b/playground/config/logger.ts @@ -1,7 +1,8 @@ -import env from '#start/env' import app from '@adonisjs/core/services/app' import { defineConfig, targets } from '@adonisjs/core/logger' +import env from '#start/env' + const loggerConfig = defineConfig({ default: 'app', diff --git a/playground/config/session.ts b/playground/config/session.ts index 6a143aa..71ee3e6 100644 --- a/playground/config/session.ts +++ b/playground/config/session.ts @@ -1,7 +1,8 @@ -import env from '#start/env' import app from '@adonisjs/core/services/app' import { defineConfig, stores } from '@adonisjs/session' +import env from '#start/env' + const sessionConfig = defineConfig({ enabled: true, cookieName: 'adonis-session', diff --git a/playground/database/migrations/1713101984460_create_users_table.ts b/playground/database/migrations/1713101984460_create_users_table.ts index d6a6798..dbca083 100644 --- a/playground/database/migrations/1713101984460_create_users_table.ts +++ b/playground/database/migrations/1713101984460_create_users_table.ts @@ -18,4 +18,4 @@ export default class extends BaseSchema { async down() { this.schema.dropTable(this.tableName) } -} \ No newline at end of file +} diff --git a/playground/database/migrations/1713101984462_create_access_tokens_table.ts b/playground/database/migrations/1713101984462_create_access_tokens_table.ts index d0f711f..a3ce197 100644 --- a/playground/database/migrations/1713101984462_create_access_tokens_table.ts +++ b/playground/database/migrations/1713101984462_create_access_tokens_table.ts @@ -28,4 +28,4 @@ export default class extends BaseSchema { async down() { this.schema.dropTable(this.tableName) } -} \ No newline at end of file +} diff --git a/playground/inertia/app/app.tsx b/playground/inertia/app/app.tsx index 6e4842c..3e747db 100644 --- a/playground/inertia/app/app.tsx +++ b/playground/inertia/app/app.tsx @@ -1,18 +1,16 @@ import '../css/app.css' -import { hydrate } from 'solid-js/web'; + +import { render } from 'solid-js/web' import { createInertiaApp } from 'inertia-adapter-solid' import { resolvePageComponent } from '@adonisjs/inertia/helpers' createInertiaApp({ progress: { color: '#5468FF' }, resolve: (name) => { - return resolvePageComponent( - `../pages/${name}.tsx`, - import.meta.glob('../pages/**/*.tsx'), - ) + return resolvePageComponent(`../pages/${name}.tsx`, import.meta.glob('../pages/**/*.tsx')) }, setup({ el, App, props }) { - hydrate(() => , el) + render(() => , el) }, }) diff --git a/playground/inertia/app/tuyau.tsx b/playground/inertia/app/tuyau.tsx index 6d50e91..57efe7e 100644 --- a/playground/inertia/app/tuyau.tsx +++ b/playground/inertia/app/tuyau.tsx @@ -1,14 +1,8 @@ /// /// -import { AdonisApi } from '../../.adonisjs/types/api' import { createTuyau } from '@tuyau/client' -export const tuyau = createTuyau('http://localhost:3333') +import type { AdonisApi } from '../../.adonisjs/types/api' -const result = await tuyau.users.get({ - query: { - email: 'foo', - password: 'bar', - } -}) +export const tuyau = createTuyau('http://localhost:3333') diff --git a/playground/inertia/pages/errors/not_found.tsx b/playground/inertia/pages/errors/not_found.tsx index 6b0427d..b74feba 100644 --- a/playground/inertia/pages/errors/not_found.tsx +++ b/playground/inertia/pages/errors/not_found.tsx @@ -8,4 +8,4 @@ export default function NotFound() { ) -} \ No newline at end of file +} diff --git a/playground/inertia/pages/errors/server_error.tsx b/playground/inertia/pages/errors/server_error.tsx index 45da445..49fbeae 100644 --- a/playground/inertia/pages/errors/server_error.tsx +++ b/playground/inertia/pages/errors/server_error.tsx @@ -8,4 +8,4 @@ export default function ServerError(props: { error: any }) { ) -} \ No newline at end of file +} diff --git a/playground/inertia/pages/home.tsx b/playground/inertia/pages/home.tsx index 178688f..eb6f5e4 100644 --- a/playground/inertia/pages/home.tsx +++ b/playground/inertia/pages/home.tsx @@ -1,15 +1,46 @@ +import { tuyau } from '~/app/tuyau' +import { Match, Switch, createResource } from 'solid-js' +import type { InferPageProps } from '@adonisjs/inertia/types' + +import type InertiaController from '../../app/controllers/inertia_controller' + +type InferErrorType any> = Awaited>['error'] + +export default function Home(props: InferPageProps) { + const [data] = createResource(async () => { + const result = await tuyau.users.get() + if (result.error) throw result.error + + return result.data + }) + + const errorMessage = () => { + const error = data.error as InferErrorType + + if (error?.status === 400) { + return error.value.message + } + + if (error?.status === 502) { + return error.value + } + + return 'Unknown error' + } -export default function Home(props: { version: number }) { return ( <>
AdonisJS {props.version} x Inertia x Solid.js
- - Learn more about AdonisJS and Inertia.js by visiting the{' '} - AdonisJS documentation. - + + Loading... + {errorMessage()} + + {(users) =>
    {users()?.users.map((user) =>
  • {user.name}
  • )}
} +
+
) -} \ No newline at end of file +} diff --git a/playground/inertia/tsconfig.json b/playground/inertia/tsconfig.json index fb6ba12..4c48bf9 100644 --- a/playground/inertia/tsconfig.json +++ b/playground/inertia/tsconfig.json @@ -1,13 +1,13 @@ { "extends": "@adonisjs/tsconfig/tsconfig.client.json", "compilerOptions": { - "baseUrl": ".", "jsx": "preserve", - "module": "ESNext", "jsxImportSource": "solid-js", + "baseUrl": ".", + "module": "ESNext", "paths": { - "~/*": ["./*"], - }, + "~/*": ["./*"] + } }, - "include": ["./**/*.ts", "./**/*.tsx"], -} \ No newline at end of file + "include": ["./**/*.ts", "./**/*.tsx"] +} diff --git a/playground/package.json b/playground/package.json index f044c4f..de091ec 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,8 +1,8 @@ { "name": "playground", + "type": "module", "version": "0.0.0", "private": true, - "type": "module", "license": "UNLICENSED", "scripts": { "start": "node bin/server.js", @@ -31,19 +31,6 @@ "#start/*": "./start/*.js", "#config/*": "./config/*.js" }, - "devDependencies": { - "@adonisjs/assembler": "^7.4.0", - "@adonisjs/tsconfig": "^1.3.0", - "@japa/plugin-adonisjs": "^3.0.1", - "@tuyau/utils": "workspace:*", - "@types/luxon": "^3.4.2", - "@types/node": "^20.12.7", - "eslint": "^8.57.0", - "hot-hook": "^0.1.9", - "pino-pretty": "^11.0.0", - "vite": "^5.2.8", - "vite-plugin-solid": "^2.10.2" - }, "dependencies": { "@adonisjs/auth": "^9.2.0", "@adonisjs/core": "^6.5.0", @@ -65,6 +52,19 @@ "reflect-metadata": "^0.2.2", "solid-js": "^1.8.16" }, + "devDependencies": { + "@adonisjs/assembler": "^7.4.0", + "@adonisjs/tsconfig": "^1.3.0", + "@japa/plugin-adonisjs": "^3.0.1", + "@tuyau/utils": "workspace:*", + "@types/luxon": "^3.4.2", + "@types/node": "^20.12.7", + "eslint": "^8.57.0", + "hot-hook": "^0.1.10", + "pino-pretty": "^11.0.0", + "vite": "^5.2.8", + "vite-plugin-solid": "^2.10.2" + }, "hotHook": { "boundaries": [ "../app/controllers/*.ts", diff --git a/playground/start/kernel.ts b/playground/start/kernel.ts index 96c619e..fbe6762 100644 --- a/playground/start/kernel.ts +++ b/playground/start/kernel.ts @@ -27,7 +27,7 @@ server.use([ () => import('@adonisjs/static/static_middleware'), () => import('@adonisjs/cors/cors_middleware'), () => import('@adonisjs/vite/vite_middleware'), - () => import('@adonisjs/inertia/inertia_middleware') + () => import('@adonisjs/inertia/inertia_middleware'), ]) /** @@ -38,7 +38,7 @@ router.use([ () => import('@adonisjs/core/bodyparser_middleware'), () => import('@adonisjs/session/session_middleware'), () => import('@adonisjs/shield/shield_middleware'), - () => import('@adonisjs/auth/initialize_auth_middleware') + () => import('@adonisjs/auth/initialize_auth_middleware'), ]) /** @@ -46,5 +46,5 @@ router.use([ * the routes or the routes group. */ export const middleware = router.named({ - auth: () => import('#middleware/auth_middleware') + auth: () => import('#middleware/auth_middleware'), }) diff --git a/playground/start/routes.ts b/playground/start/routes.ts index 96e2478..6f0a304 100644 --- a/playground/start/routes.ts +++ b/playground/start/routes.ts @@ -8,7 +8,10 @@ */ import router from '@adonisjs/core/services/router' + const UsersController = () => import('#controllers/users_controller') +const InertiaController = () => import('#controllers/inertia_controller') router.resource('users', UsersController) +router.get('/', [InertiaController, 'index']) diff --git a/playground/vite.config.ts b/playground/vite.config.ts index f2e3638..09411df 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.ts @@ -1,11 +1,15 @@ import { defineConfig } from 'vite' -import { getDirname } from '@adonisjs/core/helpers' -import inertia from '@adonisjs/inertia/client' import solid from 'vite-plugin-solid' import adonisjs from '@adonisjs/vite/client' +import inertia from '@adonisjs/inertia/client' +import { getDirname } from '@adonisjs/core/helpers' export default defineConfig({ - plugins: [inertia({ ssr: { enabled: true, entrypoint: 'inertia/app/ssr.tsx' } }), solid({ ssr: true }), adonisjs({ entrypoints: ['inertia/app/app.tsx'], reload: ['resources/views/**/*.edge'] })], + plugins: [ + inertia({ ssr: { enabled: true, entrypoint: 'inertia/app/ssr.tsx' } }), + solid({ ssr: true }), + adonisjs({ entrypoints: ['inertia/app/app.tsx'], reload: ['resources/views/**/*.edge'] }), + ], /** * Define aliases for importing modules from diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0886e7d..78f0596 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,6 +82,9 @@ importers: '@adonisjs/core': specifier: ^6.5.0 version: 6.5.0(@adonisjs/assembler@7.4.0)(@vinejs/vine@1.8.0)(edge.js@6.0.2) + '@julr/tooling-configs': + specifier: ^2.2.0 + version: 2.2.0(eslint@8.57.0)(prettier@3.2.5)(typescript@5.4.5) '@poppinss/matchit': specifier: ^3.1.2 version: 3.1.2 @@ -179,8 +182,8 @@ importers: specifier: ^8.57.0 version: 8.57.0 hot-hook: - specifier: ^0.1.9 - version: 0.1.9 + specifier: ^0.1.10 + version: 0.1.10 pino-pretty: specifier: ^11.0.0 version: 11.0.0 @@ -4949,8 +4952,8 @@ packages: lru-cache: 10.2.0 dev: true - /hot-hook@0.1.9: - resolution: {integrity: sha512-6tjuUSFpg0dy88Yhf7H/XMNv9y2Lc+fefx91FQKxUVXeSdOw8F9WOArbqMrNbP/trNBQBTmwY9HthSs640cJkA==} + /hot-hook@0.1.10: + resolution: {integrity: sha512-ilWzR35L2yGjk2N70lSq8/xG2vcafhu32TeDU0iY0mJZF9O6l/62ur866xzvPDNq6uC8PWLwCqAPswFMxvdRmQ==} dependencies: chokidar: 3.6.0 fast-glob: 3.3.2