Skip to content

Commit 2d3c5ee

Browse files
chore: wip
1 parent 066e48e commit 2d3c5ee

File tree

11 files changed

+24
-74
lines changed

11 files changed

+24
-74
lines changed

storage/framework/core/database/src/drivers/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getTableName } from '@stacksjs/orm'
44
import { path } from '@stacksjs/path'
55
import { fs, globSync } from '@stacksjs/storage'
66
import { plural, snakeCase } from '@stacksjs/strings'
7-
import type { Attributes, Model, VineType } from '@stacksjs/types'
7+
import type { Attribute, Attributes, Model, VineType } from '@stacksjs/types'
88
export * from './mysql'
99
export * from './postgres'
1010
export * from './sqlite'
@@ -33,15 +33,15 @@ export async function modelTableName(model: Model | string): Promise<string> {
3333
return model.table ?? snakeCase(plural(model?.name || ''))
3434
}
3535

36-
export async function hasTableBeenMigrated(tableName: string) {
36+
export async function hasTableBeenMigrated(tableName: string): Promise<boolean> {
3737
log.debug(`hasTableBeenMigrated for table: ${tableName}`)
3838

3939
const results = await getExecutedMigrations()
4040

4141
return results.some((migration) => migration.name.includes(tableName))
4242
}
4343

44-
export async function getExecutedMigrations() {
44+
export async function getExecutedMigrations(): Promise<{ name: string }[]> {
4545
try {
4646
return await db.selectFrom('migrations').select('name').execute()
4747
} catch (error) {
@@ -175,7 +175,7 @@ export function pluckChanges(array1: string[], array2: string[]): { added: strin
175175
return { added, removed }
176176
}
177177

178-
export function arrangeColumns(attributes: Attributes | undefined) {
178+
export function arrangeColumns(attributes: Attributes | undefined): Attribute[] | string[] {
179179
if (!attributes) return []
180180

181181
const entries = Object.entries(attributes)
@@ -186,7 +186,7 @@ export function arrangeColumns(attributes: Attributes | undefined) {
186186
return orderA - orderB
187187
})
188188

189-
return entries
189+
return entries as Attribute[]
190190
}
191191

192192
export function isArrayEqual(arr1: (number | undefined)[], arr2: (number | undefined)[]): boolean {

storage/framework/core/database/src/drivers/mysql.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { italic, log } from '@stacksjs/cli'
22
import { db } from '@stacksjs/database'
3-
import { ok } from '@stacksjs/error-handling'
3+
import { type Ok, ok } from '@stacksjs/error-handling'
44
import { getModelName, getTableName } from '@stacksjs/orm'
55
import { fetchOtherModelRelations, getPivotTables } from '@stacksjs/orm'
66
import { path } from '@stacksjs/path'
7-
import { fs, glob, globSync } from '@stacksjs/storage'
7+
import { fs, globSync } from '@stacksjs/storage'
88

99
import { snakeCase } from '@stacksjs/strings'
1010
import type { Attribute, Attributes, Model } from '@stacksjs/types'
@@ -20,7 +20,7 @@ import {
2020
pluckChanges,
2121
} from '.'
2222

23-
export async function resetMysqlDatabase() {
23+
export async function resetMysqlDatabase(): Promise<Ok<string, any>> {
2424
const tables = await fetchTables()
2525

2626
for (const table of tables) await db.schema.dropTable(table).ifExists().execute()
@@ -62,7 +62,7 @@ export async function resetMysqlDatabase() {
6262
return ok('All tables dropped successfully!')
6363
}
6464

65-
export async function generateMysqlMigration(modelPath: string) {
65+
export async function generateMysqlMigration(modelPath: string): Promise<void> {
6666
// check if any files are in the database folder
6767
// const files = await fs.readdir(path.userMigrationsPath())
6868

@@ -123,7 +123,7 @@ export async function generateMysqlMigration(modelPath: string) {
123123
else await createTableMigration(modelPath)
124124
}
125125

126-
async function createTableMigration(modelPath: string) {
126+
async function createTableMigration(modelPath: string): Promise<void> {
127127
log.debug('createTableMigration modelPath:', modelPath)
128128

129129
const model = (await import(modelPath)).default as Model
@@ -197,7 +197,7 @@ async function createTableMigration(modelPath: string) {
197197
log.success(`Created migration: ${italic(migrationFileName)}`)
198198
}
199199

200-
async function createPivotTableMigration(model: Model, modelPath: string) {
200+
async function createPivotTableMigration(model: Model, modelPath: string): Promise<void> {
201201
const pivotTables = await getPivotTables(model, modelPath)
202202

203203
if (!pivotTables.length) return
@@ -228,7 +228,7 @@ async function createPivotTableMigration(model: Model, modelPath: string) {
228228
}
229229
}
230230

231-
export async function createAlterTableMigration(modelPath: string) {
231+
export async function createAlterTableMigration(modelPath: string): Promise<void> {
232232
console.log('createAlterTableMigration')
233233

234234
const model = (await import(modelPath)).default as Model

storage/framework/core/orm/src/drivers/dynamodb.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

storage/framework/core/orm/src/drivers/mysql.ts

Whitespace-only changes.

storage/framework/core/orm/src/drivers/postgres.ts

Whitespace-only changes.

storage/framework/core/orm/src/drivers/sqlite.ts

Whitespace-only changes.

storage/framework/core/orm/src/utils.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { generator, parser, traverse } from '@stacksjs/build'
21
import { italic, log } from '@stacksjs/cli'
32
import { path } from '@stacksjs/path'
43
import { fs, globSync } from '@stacksjs/storage'
@@ -38,40 +37,6 @@ export function getTableName(model: Model, modelPath: string): string {
3837
return snakeCase(plural(getModelName(model, modelPath)))
3938
}
4039

41-
export async function extractAttributesFromModel(filePath: string) {
42-
// Read the TypeScript file
43-
const content = fs.readFileSync(filePath, 'utf8')
44-
45-
// Parse the file content into an AST
46-
const ast = parser.parse(content, {
47-
sourceType: 'module',
48-
plugins: ['typescript', 'classProperties', 'decorators-legacy'],
49-
})
50-
51-
let fields: Attributes | undefined
52-
53-
// Traverse the AST to find the `fields` object
54-
traverse(ast, {
55-
ObjectExpression(path) {
56-
// Look for the `fields` key in the object
57-
const fieldsProperty = path.node.properties.find((property) => property.key?.name === 'attributes')
58-
59-
if (fieldsProperty?.value) {
60-
// Convert the AST back to code (stringify)
61-
const generated = generator(fieldsProperty.value, {}, content)
62-
fields = generated.code
63-
path.stop() // Stop traversing further once we found the fields
64-
}
65-
},
66-
})
67-
68-
return fields
69-
}
70-
71-
export function userModels() {
72-
return import.meta.glob<{ default: Model }>(path.userModelsPath('*.ts'))
73-
}
74-
7540
export function getPivotTableName(formattedModelName: string, modelRelationTable: string): string {
7641
// Create an array of the model names
7742
const models = [formattedModelName, modelRelationTable]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Middleware implements MiddlewareOptions {
1515

1616
// const readdir = promisify(fs.readdir)
1717

18-
async function importMiddlewares(directory: string) {
18+
async function importMiddlewares(directory: string): Promise<string[]> {
1919
// const middlewares = []
2020
// TODO: somehow this breaks ./buddy dev
2121
// const files = await readdir(directory)
@@ -30,6 +30,6 @@ async function importMiddlewares(directory: string) {
3030
return [directory] // fix this: return array of middlewares
3131
}
3232

33-
export const middlewares = async () => {
33+
export const middlewares = async (): Promise<string[]> => {
3434
return await importMiddlewares(userMiddlewarePath())
3535
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class Request<T extends RequestData = RequestData> implements RequestInst
7474
return this.headers.get(headerParam)
7575
}
7676

77-
public getHeaders() {
77+
public getHeaders(): any {
7878
return this.headers
7979
}
8080

@@ -106,4 +106,4 @@ export class Request<T extends RequestData = RequestData> implements RequestInst
106106
}
107107
}
108108

109-
export const request = new Request()
109+
export const request: Request = new Request()

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ function extractDynamicSegments(routePattern: string, path: string): RouteParam
122122

123123
const dynamicSegments: { [key: string]: string } = {}
124124
dynamicSegmentNames.forEach((name, index) => {
125-
dynamicSegments[name] = dynamicSegmentValues[index]
125+
if (name && dynamicSegmentValues[index] !== undefined) {
126+
dynamicSegments[name] = dynamicSegmentValues[index] // Ensure value is defined
127+
}
126128
})
127-
128129
return dynamicSegments
129130
}
130131

@@ -290,15 +291,15 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
290291
})
291292
}
292293

293-
function noCache(response: Response) {
294+
function noCache(response: Response): Response {
294295
response.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
295296
response.headers.set('Pragma', 'no-cache')
296297
response.headers.set('Expires', '0')
297298

298299
return response
299300
}
300301

301-
async function addRouteQuery(url: URL) {
302+
async function addRouteQuery(url: URL): Promise<void> {
302303
const modelFiles = globSync([path.userModelsPath('*.ts')], { absolute: true })
303304
for (const modelFile of modelFiles) {
304305
const model = (await import(modelFile)).default
@@ -315,7 +316,7 @@ async function addRouteQuery(url: URL) {
315316
RequestParam.addQuery(url)
316317
}
317318

318-
async function addBody(params: any) {
319+
async function addBody(params: any): Promise<void> {
319320
const modelFiles = globSync([path.userModelsPath('*.ts')], { absolute: true })
320321

321322
for (const modelFile of modelFiles) {

0 commit comments

Comments
 (0)