From 7584d2d7a7110aef0331ebfa178b2295842c59fa Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:19:14 -0700 Subject: refactor: project maintenance - work in progress --- types/auth.ts | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ types/drive.ts | 13 +++++++ types/events.ts | 33 ++++++++++++++++++ types/tests.ts | 19 +++++++++++ 4 files changed, 168 insertions(+) create mode 100644 types/auth.ts create mode 100644 types/drive.ts create mode 100644 types/events.ts create mode 100644 types/tests.ts (limited to 'types') diff --git a/types/auth.ts b/types/auth.ts new file mode 100644 index 0000000..9761ea5 --- /dev/null +++ b/types/auth.ts @@ -0,0 +1,103 @@ +/** + * Contract source: https://git.io/JOdz5 + * + * Feel free to let us know via PR, if you find something broken in this + * file. + */ + +import User from '#app/Models/User' +import { JWTGuardConfig, JWTGuardContract } from '@ioc:Adonis/Addons/Jwt' + +declare module '@ioc:Adonis/Addons/Auth' { + /* + |-------------------------------------------------------------------------- + | Providers + |-------------------------------------------------------------------------- + | + | The providers are used to fetch users. The Auth module comes pre-bundled + | with two providers that are `Lucid` and `Database`. Both uses database + | to fetch user details. + | + | You can also create and register your own custom providers. + | + */ + interface ProvidersList { + /* + |-------------------------------------------------------------------------- + | User Provider + |-------------------------------------------------------------------------- + | + | The following provider uses Lucid models as a driver for fetching user + | details from the database for authentication. + | + | You can create multiple providers using the same underlying driver with + | different Lucid models. + | + */ + user: { + implementation: LucidProviderContract + config: LucidProviderConfig + } + } + + /* + |-------------------------------------------------------------------------- + | Guards + |-------------------------------------------------------------------------- + | + | The guards are used for authenticating users using different drivers. + | The auth module comes with 3 different guards. + | + | - SessionGuardContract + | - BasicAuthGuardContract + | - OATGuardContract ( Opaque access token ) + | + | Every guard needs a provider for looking up users from the database. + | + */ + interface GuardsList { + /* + |-------------------------------------------------------------------------- + | Web Guard + |-------------------------------------------------------------------------- + | + | The web guard uses sessions for maintaining user login state. It uses + | the `user` provider for fetching user details. + | + */ + web: { + implementation: SessionGuardContract<'user', 'web'> + config: SessionGuardConfig<'user'> + } + /* + |-------------------------------------------------------------------------- + | OAT Guard + |-------------------------------------------------------------------------- + | + | OAT, stands for (Opaque access tokens) guard uses database backed tokens + | to authenticate requests. + | + */ + api: { + implementation: OATGuardContract<'user', 'api'> + config: OATGuardConfig<'user'> + } + /* + |-------------------------------------------------------------------------- + | Basic Auth Guard + |-------------------------------------------------------------------------- + | + | The basic guard uses basic auth for maintaining user login state. It uses + | the `user` provider for fetching user details. + | + */ + basic: { + implementation: BasicAuthGuardContract<'user', 'basic'> + config: BasicAuthGuardConfig<'user'> + } + jwt: { + implementation: JWTGuardContract<'user', 'api'> + config: JWTGuardConfig<'user'> + } + } +} diff --git a/types/drive.ts b/types/drive.ts new file mode 100644 index 0000000..0ad668e --- /dev/null +++ b/types/drive.ts @@ -0,0 +1,13 @@ +/** + * Contract source: https://git.io/JBt3I + * + * Feel free to let us know via PR, if you find something broken in this contract + * file. + */ + +import { InferDisksFromConfig } from '@adonisjs/core/build/config' +import driveConfig from '../config/drive.js' + +declare module '@ioc:Adonis/Core/Drive' { + interface DisksList extends InferDisksFromConfig {} +} diff --git a/types/events.ts b/types/events.ts new file mode 100644 index 0000000..91be5b4 --- /dev/null +++ b/types/events.ts @@ -0,0 +1,33 @@ +/** + * Contract source: https://git.io/JfefG + * + * Feel free to let us know via PR, if you find something broken in this contract + * file. + */ + +import User from '#app/Models/User' + +declare module '@ioc:Adonis/Core/Event' { + /* + |-------------------------------------------------------------------------- + | Define typed events + |-------------------------------------------------------------------------- + | + | You can define types for events inside the following interface and + | AdonisJS will make sure that all listeners and emit calls adheres + | to the defined types. + | + | For example: + | + | interface EventsList { + | 'new:user': UserModel + | } + | + | Now calling `Event.emit('new:user')` will statically ensure that passed value is + | an instance of the the UserModel only. + | + */ + interface EventsList { + 'forgot:password': { user: User; token: string } + } +} diff --git a/types/tests.ts b/types/tests.ts new file mode 100644 index 0000000..9be30fc --- /dev/null +++ b/types/tests.ts @@ -0,0 +1,19 @@ +/** + * Contract source: https://bit.ly/3DP1ypf + * + * Feel free to let us know via PR, if you find something broken in this contract + * file. + */ + +import '@japa/runner' + +declare module '@japa/runner' { + interface TestContext { + // Extend context + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Test { + // Extend test + } +} -- cgit v1.2.3-70-g09d2