Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
types(server)!: move base manager class type to dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 12, 2022
1 parent e6d91cb commit 8d2134c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
24 changes: 16 additions & 8 deletions server/types/dependent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import type {
} from "express"
import type { ExpressPeerServer } from "peer"
import type { Session } from "express-session"

import type { Serializable } from "$/types/general"
import CacheClient from "$!/helpers/cache_client"
import type { SharedManagerState } from "$!/types/dependent"

import BaseManager from "%/managers/base"
import TransactionManager from "%/managers/helpers/transaction_manager"

// @ts-ignore
export interface Request extends BaseRequest {
export interface Request extends BaseRequest, SharedManagerState<TransactionManager> {
// Added due to `express-session` package
session: Session & {
token?: string
Expand All @@ -27,12 +30,6 @@ export interface Request extends BaseRequest {
user: Serializable|undefined
isAuthenticated: () => boolean
logout: () => void

// Added to manage the transactions
transaction: TransactionManager

// Added to manage the cache
cache: CacheClient
}

export interface AuthenticatedRequest extends Request {
Expand Down Expand Up @@ -68,3 +65,14 @@ export interface AuthenticatedIDRequest extends AuthenticatedRequest {
}

export type PeerServer = ReturnType<typeof ExpressPeerServer>

/**
* Useful when passing a base manager to other functions/methods
*/
export type BaseManagerClass<T extends SharedManagerState = SharedManagerState>
= new(state?: Partial<T>) => BaseManager<
any,
any,
any,
any
>
11 changes: 0 additions & 11 deletions server/types/independent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import type { UserKind } from "$/types/database"
import type Middleware from "!/bases/middleware"
import BaseManager from "%/managers/base"
import CacheClient from "$!/helpers/cache_client"
import TransactionManager from "%/managers/helpers/transaction_manager"

/**
* Used to indicate which middlewares to use in a route.
Expand Down Expand Up @@ -45,14 +42,6 @@ export interface PasswordResetArguments {
}
}

/**
* Useful when passing a base manager to other functions/methods
*/
export type BaseManagerClass = new(
transaction?: TransactionManager,
cache?: CacheClient
) => BaseManager<any, any, any, any>

/**
* Shape of validation error
*/
Expand Down
2 changes: 1 addition & 1 deletion server/types/rule_set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseManagerClass } from "!/types/independent"
import type { BaseManagerClass } from "!/types/dependent"
import type { FieldRules, Rules, Pipe } from "!/types/validation"

export type IdentifierDocumentOptions = Partial<{
Expand Down
2 changes: 1 addition & 1 deletion server/types/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Pipe as BasePipe } from "$/types/database"
import type BasePermissionGroup from "$/permissions/base"
import type { BaseManagerClass } from "!/types/independent"
import type { BaseManagerClass } from "!/types/dependent"

export interface NullableConstraints { nullable?: { defaultValue: any } }

Expand Down

0 comments on commit 8d2134c

Please sign in to comment.