Skip to content

Commit

Permalink
feat: playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Apr 14, 2024
1 parent d9be656 commit 25c0159
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 116 deletions.
5 changes: 3 additions & 2 deletions packages/client/src/errors.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
16 changes: 15 additions & 1 deletion packages/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:*",
Expand Down Expand Up @@ -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"
}
}
25 changes: 0 additions & 25 deletions playground/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions playground/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/**
Expand Down
22 changes: 13 additions & 9 deletions playground/adonisrc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { relative } from 'node:path'
import { defineConfig } from '@adonisjs/core/app'
import { relative } from 'path';

export default defineConfig({
/*
Expand All @@ -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'),
],

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -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'),
],

/*
Expand Down Expand Up @@ -71,7 +75,7 @@ export default defineConfig({
{
files: ['tests/functional/**/*.spec(.ts|.js)'],
name: 'functional',
timeout: 30000,
timeout: 30_000,
},
],
forceExit: false,
Expand Down Expand Up @@ -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)}`)
}
},
}),
Expand Down
4 changes: 2 additions & 2 deletions playground/app/controllers/users_controller.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion playground/app/exceptions/handler.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions playground/app/middleware/auth_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
2 changes: 1 addition & 1 deletion playground/app/middleware/container_bindings_middleware.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion playground/app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export default class User extends compose(BaseModel, AuthFinder) {
declare updatedAt: DateTime | null

static accessTokens = DbAccessTokensProvider.forModel(User)
}
}
1 change: 1 addition & 0 deletions playground/bin/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import 'reflect-metadata'

import { Ignitor, prettyPrintError } from '@adonisjs/core'

/**
Expand Down
1 change: 1 addition & 0 deletions playground/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import 'reflect-metadata'

import { Ignitor, prettyPrintError } from '@adonisjs/core'

/**
Expand Down
12 changes: 6 additions & 6 deletions playground/bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion playground/config/app.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions playground/config/auth.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -8,7 +8,7 @@ const authConfig = defineConfig({
api: tokensGuard({
provider: tokensUserProvider({
tokens: 'accessTokens',
model: () => import('#models/user')
model: () => import('#models/user'),
}),
}),
},
Expand All @@ -25,4 +25,4 @@ declare module '@adonisjs/auth/types' {
}
declare module '@adonisjs/core/types' {
interface EventsList extends InferAuthEvents<Authenticators> {}
}
}
4 changes: 2 additions & 2 deletions playground/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -18,4 +18,4 @@ const dbConfig = defineConfig({
},
})

export default dbConfig
export default dbConfig
4 changes: 2 additions & 2 deletions playground/config/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
},
})
Expand Down
4 changes: 2 additions & 2 deletions playground/config/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export default defineConfig({
*/
ssr: {
enabled: false,
entrypoint: 'inertia/app/ssr.tsx'
}
entrypoint: 'inertia/app/ssr.tsx',
},
})
3 changes: 2 additions & 1 deletion playground/config/logger.ts
Original file line number Diff line number Diff line change
@@ -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',

Expand Down
3 changes: 2 additions & 1 deletion playground/config/session.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export default class extends BaseSchema {
async down() {
this.schema.dropTable(this.tableName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export default class extends BaseSchema {
async down() {
this.schema.dropTable(this.tableName)
}
}
}
10 changes: 4 additions & 6 deletions playground/inertia/app/app.tsx
Original file line number Diff line number Diff line change
@@ -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(() => <App {...props} />, el)
render(() => <App {...props} />, el)
},
})
10 changes: 2 additions & 8 deletions playground/inertia/app/tuyau.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/// <reference path="../../adonisrc.ts" />
/// <reference types="hot-hook/import-meta" />

import { AdonisApi } from '../../.adonisjs/types/api'
import { createTuyau } from '@tuyau/client'

export const tuyau = createTuyau<AdonisApi>('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<AdonisApi>('http://localhost:3333')
2 changes: 1 addition & 1 deletion playground/inertia/pages/errors/not_found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default function NotFound() {
</div>
</>
)
}
}
2 changes: 1 addition & 1 deletion playground/inertia/pages/errors/server_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default function ServerError(props: { error: any }) {
</div>
</>
)
}
}
Loading

0 comments on commit 25c0159

Please sign in to comment.