Skip to content

Commit e6bf297

Browse files
committed
chore: wip
1 parent 3e03a29 commit e6bf297

File tree

11 files changed

+26
-32
lines changed

11 files changed

+26
-32
lines changed

app/Listener.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { path as p } from '@stacksjs/path'
33
import events from './Events'
44

55
for (const key in events) {
6-
if (events.hasOwnProperty(key)) {
6+
if (Object.hasOwn(events, key)) {
77
const eventKey = key
88
const eventListeners = events[key]
99

@@ -20,13 +20,13 @@ for (const key in events) {
2020
listen(eventKey, e => actionModule.default.handle(e))
2121
}
2222
catch (error) {
23-
console.error('Module not found:', modulePath)
23+
handleError(`Module not found: ${modulePath}`, error)
2424
}
2525
}
2626
}
2727
}
2828
}
2929

30-
function isFunction(val: unknown): val is Function {
30+
function isFunction(val: unknown) {
3131
return typeof val === 'function'
3232
}

storage/framework/core/events/tests/events.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { all, dispatch, events, listen, mitt, off, useEvent, useEvents } from '.
55
describe('@stacksjs/events', () => {
66
test('mitt creates a functional event emitter', () => {
77
const emitter = mitt<{ test: string }>()
8-
const handler = mock((data: string) => {})
8+
const handler = mock(() => {})
99

1010
emitter.on('test', handler)
1111
emitter.emit('test', 'hello')
@@ -15,7 +15,7 @@ describe('@stacksjs/events', () => {
1515

1616
test('off removes event listeners', () => {
1717
const emitter = mitt<{ test: string }>()
18-
const handler = mock((data: string) => {})
18+
const handler = mock(() => {})
1919

2020
emitter.on('test', handler)
2121
emitter.off('test', handler)
@@ -26,7 +26,7 @@ describe('@stacksjs/events', () => {
2626

2727
test('wildcard listeners receive all events', () => {
2828
const emitter = mitt<{ test1: string, test2: number }>()
29-
const handler = mock((type: string, data: any) => {})
29+
const handler = mock(() => {})
3030

3131
emitter.on('*', handler)
3232
emitter.emit('test1', 'hello')
@@ -39,8 +39,8 @@ describe('@stacksjs/events', () => {
3939

4040
test('off removes all listeners of a given type when no handler is provided', () => {
4141
const emitter = mitt<{ test: string }>()
42-
const handler1 = mock((data: string) => {})
43-
const handler2 = mock((data: string) => {})
42+
const handler1 = mock(() => {})
43+
const handler2 = mock(() => {})
4444

4545
emitter.on('test', handler1)
4646
emitter.on('test', handler2)
@@ -52,28 +52,28 @@ describe('@stacksjs/events', () => {
5252
})
5353

5454
test('events creates a mitt instance with StacksEvents', () => {
55-
const emitter = events()
55+
const emitter = events
5656
expect(emitter).toHaveProperty('on')
5757
expect(emitter).toHaveProperty('off')
5858
expect(emitter).toHaveProperty('emit')
5959
})
6060

6161
test('listen is an alias for on', () => {
62-
const handler = mock((data: object) => {})
62+
const handler = mock(() => {})
6363
listen('user:registered', handler)
6464
dispatch('user:registered', { name: 'John Doe' })
6565
expect(handler).toHaveBeenCalledWith({ name: 'John Doe' })
6666
})
6767

6868
test('dispatch is an alias for emit', () => {
69-
const handler = mock((data: object) => {})
69+
const handler = mock(() => {})
7070
listen('user:logged-in', handler)
7171
dispatch('user:logged-in', { userId: 1 })
7272
expect(handler).toHaveBeenCalledWith({ userId: 1 })
7373
})
7474

7575
test('useEvent is an alias for emit', () => {
76-
const handler = mock((data: object) => {})
76+
const handler = mock(() => {})
7777
listen('user:logged-out', handler)
7878
useEvent('user:logged-out', { userId: 1 })
7979
expect(handler).toHaveBeenCalledWith({ userId: 1 })
@@ -86,22 +86,22 @@ describe('@stacksjs/events', () => {
8686
})
8787

8888
test('all provides access to the event handler map', () => {
89-
const handler = mock((data: Partial<UserModel>) => {})
89+
const handler = mock(() => {})
9090
listen('user:updated', handler)
9191
expect(all.get('user:updated')).toContain(handler)
9292
})
9393

9494
test('off removes a specific listener', () => {
95-
const handler = mock((data: object) => {})
95+
const handler = mock(() => {})
9696
listen('user:password-changed', handler)
9797
off('user:password-changed', handler)
9898
dispatch('user:password-changed', { userId: 1 })
9999
expect(handler).not.toHaveBeenCalled()
100100
})
101101

102102
test('multiple events can be handled', () => {
103-
const registeredHandler = mock((data: object) => {})
104-
const updatedHandler = mock((data: UserModel) => {})
103+
const registeredHandler = mock(() => {})
104+
const updatedHandler = mock(() => {})
105105

106106
listen('user:registered', registeredHandler)
107107
listen('user:updated', updatedHandler)

storage/framework/core/logging/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint no-console: 0 */
12
import process from 'node:process'
23
import { buddyOptions, stripAnsi } from '@stacksjs/cli'
34
import { handleError, writeToLogFile } from '@stacksjs/error-handling'

storage/framework/core/router/src/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Action } from '@stacksjs/actions'
22
import type { Job, RedirectCode, Route, RouteGroupOptions, RouterInterface, StatusCode } from '@stacksjs/types'
3+
import { handleError } from '@stacksjs/error-handling'
34
import { log } from '@stacksjs/logging'
45
import { path as p } from '@stacksjs/path'
56
import { kebabCase, pascalCase } from '@stacksjs/strings'
@@ -112,7 +113,7 @@ export class Router implements RouterInterface {
112113
return this.addRoute(action.method ?? 'GET', this.prepareUri(path), action.handle, 200)
113114
}
114115
catch (error) {
115-
log.error(`Could not find Action for path: ${path}`)
116+
handleError(`Could not find Action for path: ${path}`, error)
116117

117118
return this
118119
}

storage/framework/core/scheduler/src/schedule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class Schedule {
103103
}
104104

105105
start(): void {
106+
// eslint-disable-next-line no-new
106107
new CronJob(this.cronPattern, this.task, null, true, this.timezone)
107108
log.info(`Scheduled task with pattern: ${this.cronPattern} in timezone: ${this.timezone}`)
108109
}

storage/framework/core/search-engine/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function calculatePagination(): void {
4646
if (table.perPage)
4747
totalPages.value = Math.ceil(totalHits / table.perPage)
4848

49-
const hitPages = [...new Array(totalPages.value).keys()].map(i => i + 1)
49+
const hitPages = Array.from({ length: totalPages.value }, (_, i) => i + 1)
5050
const offset = 2
5151
const currentPage = table.currentPage ?? 1
5252
const lastPage = hitPages[hitPages.length - 1]

storage/framework/core/storage/src/files.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { JsonFile, PackageJson, TextFile } from '@stacksjs/types'
22
import { contains } from '@stacksjs/arrays'
3+
import { log } from '@stacksjs/logging'
34
import { dirname, join, path as p } from '@stacksjs/path'
45
import { detectIndent, detectNewline } from '@stacksjs/strings'
56
import { createFolder, isFolder } from './'
@@ -108,6 +109,7 @@ export function hasFiles(folder: string): boolean {
108109
return fs.readdirSync(folder).length > 0
109110
}
110111
catch (err) {
112+
log.debug(`Error reading folder: ${folder}`, err)
111113
return false
112114
}
113115
}

storage/framework/core/testing/src/dynamodb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import process from 'node:process'
12
import {
23
CreateTableCommand,
34
DeleteTableCommand,

storage/framework/core/tunnel/src/tunnel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export async function localTunnel(options?: { port: number }): Promise<LocalTunn
77
if (!options?.port)
88
options = { port }
99

10+
// eslint-disable-next-line no-console
1011
console.log('Creating local tunnel', options.port)
1112

1213
return 'localTunnel'

storage/framework/core/types/src/notifications.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ export interface NotificationOptions {
145145
secret: string
146146
}
147147

148-
discord?: {
149-
// appId: string
150-
// clientId: string
151-
// secret: string
152-
}
148+
// discord?: {}
153149
}
154150
}
155151
}

0 commit comments

Comments
 (0)