From ffe1804bc68847a28570dfe18fcc3c53bf8b0a0e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 5 Dec 2023 14:16:25 +0100 Subject: [PATCH] feat(mellow-react): add ts config --- templates/mellow-react/jsconfig.json | 20 ++- templates/mellow-react/types/index.d.ts | 173 ++++++++++++++++++++++++ 2 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 templates/mellow-react/types/index.d.ts diff --git a/templates/mellow-react/jsconfig.json b/templates/mellow-react/jsconfig.json index 08ac60b6..7301a42b 100644 --- a/templates/mellow-react/jsconfig.json +++ b/templates/mellow-react/jsconfig.json @@ -1,5 +1,23 @@ { + "include": ["api/**/*", "assets/js/**/*", "types/index.d.ts"], + "compilerOptions": { - "checkJs": true + "types": ["node"], + "typeRoots": ["./types", "./node_modules/@types"], + "lib": ["es2016"], + // silences wrong TS error, we don't compile, we only typecheck + "outDir": "./irrelevant/unused", + "allowJs": true, + "checkJs": true, + "jsx": "react-jsx", + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noEmitOnError": true, + "noErrorTruncation": true, + "baseUrl": ".", + "paths": { + "@/*": ["assets/js/*"] + } } } diff --git a/templates/mellow-react/types/index.d.ts b/templates/mellow-react/types/index.d.ts new file mode 100644 index 00000000..9168476c --- /dev/null +++ b/templates/mellow-react/types/index.d.ts @@ -0,0 +1,173 @@ +interface Sails { + log: LogMethod & LogObject + models: { [modelName: string]: Model } + helpers: Helper + on(event: string, listener: (...args: any[]) => void): void + off(event: string, listener: (...args: any[]) => void): void + emit(event: string, ...args: any[]): void + lift(cb?: (err: Error, sails: Sails) => void): Sails + lower(cb?: (err?: Error) => void): void + load(): Sails + getVersion(): string + inertia: Inertia + wish: Wish + hooks: Hook + config: Config + req: { + ip: string + } + renderView: ( + relPathToView: string, + _options: Dictionary, + optionalCb?: (err: Error | null, compiledHtml: string) => void + ) => Sails & Promise + intercept(callback: (err: Error) => Error): Sails & Promise +} + +interface Helper { + passwords: { + hashPassword: (password: string, strength?: number) => Promise + checkPassword: ( + passwordAttempt: string, + hashedPassword: string + ) => Promise + } + strings: { + random: (style?: 'url-friendly' | 'alphanumeric') => string + uuid: () => string + } + mail: { + send: { + with: (params: EmailParams) => Promise + } + } + getUserInitials: (fullName: string) => string + capitalize: (inputString: string) => string +} +interface EmailParams { + mailer?: string + to: string + cc?: string | array + bcc?: string | array + subject?: string + template?: string + templateData?: object + attachments?: EmailAttachment[] +} +interface EmailAttachment { + filename: string + content?: string | Buffer | NodeJS.ReadableStream + path?: string + href?: string + httpHeaders?: { [key: string]: string } + contentType?: string + contentDisposition?: string + cid?: string + encoding?: string + headers?: { [key: string]: string } + raw?: string +} + +interface Hook { + inertia: Inertia +} +interface LogMethod { + (...args: any[]): void +} + +interface LogObject { + info: LogMethod + warn: LogMethod + error: LogMethod + debug: LogMethod + silly: LogMethod + verbose: LogMethod +} + +interface Config { + smtp: { + transport?: 'smtp' + host?: string + port?: number + encryption?: 'tls' | 'ssl' + username: string + password: string + } + google: { + clientId: string + clientSecret: string + redirect: string + } + mail: { + default: string + mailers: { + log: object + smtp: { + transport: 'smtp' + host: string + port: number + encryption: 'tls' | 'ssl' + username?: string + password?: string + } + } + from: { + name: string + address: string + } + } + custom: Custom +} + +interface Custom { + baseUrl: string + passwordResetTokenTTL: number + emailProofTokenTTL: number + rememberMeCookieMaxAge: number + internalEmail: string + verifyEmail: boolean +} +interface Wish { + provider: (provider: string) => Wish + redirect: () => string + user: (code: string) => GoogleUser | GitHubUser +} +interface Inertia { + share: (key: string, value?: any) => void + render: ( + component: string, + props?: Record, + viewData?: Record + ) => any + flushShared: (key?: string) => void + viewData: (key: string, value: any) => void + getViewData: (key: string) => any + setRootView: (newRootView: string) => void + getRootView: () => string + location: (path: string) => void +} + +interface GoogleUser { + id: string + email: string + verified_email: boolean + name: string + given_name: string + family_name: string + picture: string + locale: string + accessToken: string + idToken: string +} + +interface LoggedInUser { + id: string + fullName: string + email: string + initials?: string + googleAvatarUrl?: string + value: LoggedInUser +} +declare const sails: Sails + +declare const User