Skip to content

Commit

Permalink
feat(mellow-svelte): add ts configs
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Dec 5, 2023
1 parent 0bf6aa4 commit 96e795a
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 1 deletion.
1 change: 1 addition & 0 deletions templates/mellow-svelte/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createInertiaApp } from '@inertiajs/svelte'
import '~/css/main.css'

// @ts-ignore
createInertiaApp({
resolve: (name) => require(`./pages/${name}`),
setup({ el, App, props }) {
Expand Down
19 changes: 18 additions & 1 deletion templates/mellow-svelte/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"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,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmitOnError": true,
"noErrorTruncation": true,
"baseUrl": ".",
"paths": {
"@/*": ["assets/js/*"]
}
}
}
173 changes: 173 additions & 0 deletions templates/mellow-svelte/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<string>
intercept(callback: (err: Error) => Error): Sails & Promise<string>
}

interface Helper {
passwords: {
hashPassword: (password: string, strength?: number) => Promise<string>
checkPassword: (
passwordAttempt: string,
hashedPassword: string
) => Promise<Sails>
}
strings: {
random: (style?: 'url-friendly' | 'alphanumeric') => string
uuid: () => string
}
mail: {
send: {
with: (params: EmailParams) => Promise<string>
}
}
getUserInitials: (fullName: string) => string
capitalize: (inputString: string) => string
}
interface EmailParams {
mailer?: string
to: string
cc?: string | array<string>
bcc?: string | array<string>
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<string, any>,
viewData?: Record<string, any>
) => 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

0 comments on commit 96e795a

Please sign in to comment.