Skip to content

Commit 58fbe3b

Browse files
chore: wip
1 parent 391daa8 commit 58fbe3b

File tree

4 files changed

+83
-80
lines changed

4 files changed

+83
-80
lines changed

storage/framework/core/database/src/seeder.ts

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { Model, RelationConfig } from '@stacksjs/types'
1+
import type { Model } from '@stacksjs/types'
22
import { italic, log } from '@stacksjs/cli'
33
import { db } from '@stacksjs/database'
44
import { faker } from '@stacksjs/faker'
5-
import { fetchOtherModelRelations, findCoreModel, getModelName, getTableName } from '@stacksjs/orm'
5+
import { findCoreModel, getModelName, getTableName } from '@stacksjs/orm'
66
import { path } from '@stacksjs/path'
77
import { makeHash } from '@stacksjs/security'
88
import { fs } from '@stacksjs/storage'
@@ -80,66 +80,66 @@ async function seedModel(name: string, modelPath: string, model: Model) {
8080
log.info(`Successfully seeded ${italic(tableName)}`)
8181
}
8282

83-
async function seedPivotRelation(relation: RelationConfig): Promise<any> {
84-
const record: Record<string, any> = {}
85-
const record2: Record<string, any> = {}
86-
const pivotRecord: Record<string, any> = {}
87-
const modelInstance = await getModelInstance(relation?.model)
83+
// async function seedPivotRelation(relation: RelationConfig): Promise<any> {
84+
// const record: Record<string, any> = {}
85+
// const record2: Record<string, any> = {}
86+
// const pivotRecord: Record<string, any> = {}
87+
// const modelInstance = await getModelInstance(relation?.model)
8888

89-
const relationModelInstance = (await import(path.userModelsPath(`${relation?.relationModel}.ts`))).default
89+
// const relationModelInstance = (await import(path.userModelsPath(`${relation?.relationModel}.ts`))).default
9090

91-
const useUuid = modelInstance?.traits?.useUuid || false
91+
// const useUuid = modelInstance?.traits?.useUuid || false
9292

93-
if (!relationModelInstance)
94-
return 1
95-
96-
const relationModelTable = relationModelInstance.table
97-
const relationalModelUuid = relationModelInstance.traits?.useUuid || false
98-
const relationTable = relation.table
99-
const pivotTable = relation.pivotTable
100-
const modelKey = relation.pivotForeign || ''
101-
const foreignKey = relation.pivotKey || ''
102-
103-
for (const fieldName in relationModelInstance.attributes) {
104-
const formattedFieldName = snakeCase(fieldName)
105-
const field = relationModelInstance.attributes[fieldName]
106-
// Pass faker to the factory function
107-
if (formattedFieldName === 'password')
108-
record[formattedFieldName] = field?.factory ? await makeHash(field.factory(faker), { algorithm: 'bcrypt' }) : undefined
109-
else
110-
record[formattedFieldName] = field?.factory ? field.factory(faker) : undefined
111-
}
93+
// if (!relationModelInstance)
94+
// return 1
11295

113-
for (const fieldName in modelInstance.attributes) {
114-
const formattedFieldName = snakeCase(fieldName)
115-
const field = modelInstance.attributes[fieldName]
116-
// Pass faker to the factory function
117-
if (formattedFieldName === 'password')
118-
record2[formattedFieldName] = field?.factory ? await makeHash(field.factory(faker), { algorithm: 'bcrypt' }) : undefined
119-
else record2[formattedFieldName] = field?.factory ? field.factory(faker) : undefined
120-
}
96+
// const relationModelTable = relationModelInstance.table
97+
// const relationalModelUuid = relationModelInstance.traits?.useUuid || false
98+
// const relationTable = relation.table
99+
// const pivotTable = relation.pivotTable
100+
// const modelKey = relation.pivotForeign || ''
101+
// const foreignKey = relation.pivotKey || ''
121102

122-
if (relationalModelUuid)
123-
record.uuid = Bun.randomUUIDv7()
103+
// for (const fieldName in relationModelInstance.attributes) {
104+
// const formattedFieldName = snakeCase(fieldName)
105+
// const field = relationModelInstance.attributes[fieldName]
106+
// // Pass faker to the factory function
107+
// if (formattedFieldName === 'password')
108+
// record[formattedFieldName] = field?.factory ? await makeHash(field.factory(faker), { algorithm: 'bcrypt' }) : undefined
109+
// else
110+
// record[formattedFieldName] = field?.factory ? field.factory(faker) : undefined
111+
// }
124112

125-
const data = await db.insertInto(relationModelTable).values(record).executeTakeFirstOrThrow()
113+
// for (const fieldName in modelInstance.attributes) {
114+
// const formattedFieldName = snakeCase(fieldName)
115+
// const field = modelInstance.attributes[fieldName]
116+
// // Pass faker to the factory function
117+
// if (formattedFieldName === 'password')
118+
// record2[formattedFieldName] = field?.factory ? await makeHash(field.factory(faker), { algorithm: 'bcrypt' }) : undefined
119+
// else record2[formattedFieldName] = field?.factory ? field.factory(faker) : undefined
120+
// }
126121

127-
if (useUuid)
128-
record2.uuid = Bun.randomUUIDv7()
122+
// if (relationalModelUuid)
123+
// record.uuid = Bun.randomUUIDv7()
129124

130-
const data2 = await db.insertInto(relationTable).values(record2).executeTakeFirstOrThrow()
131-
const relationData = data.insertId || 1
132-
const modelData = data2.insertId || 1
125+
// const data = await db.insertInto(relationModelTable).values(record).executeTakeFirstOrThrow()
133126

134-
pivotRecord[foreignKey] = relationData
135-
pivotRecord[modelKey] = modelData
127+
// if (useUuid)
128+
// record2.uuid = Bun.randomUUIDv7()
136129

137-
if (useUuid)
138-
pivotRecord.uuid = Bun.randomUUIDv7()
130+
// const data2 = await db.insertInto(relationTable).values(record2).executeTakeFirstOrThrow()
131+
// const relationData = data.insertId || 1
132+
// const modelData = data2.insertId || 1
139133

140-
if (pivotTable)
141-
await db.insertInto(pivotTable).values(pivotRecord).executeTakeFirstOrThrow()
142-
}
134+
// pivotRecord[foreignKey] = relationData
135+
// pivotRecord[modelKey] = modelData
136+
137+
// if (useUuid)
138+
// pivotRecord.uuid = Bun.randomUUIDv7()
139+
140+
// if (pivotTable)
141+
// await db.insertInto(pivotTable).values(pivotRecord).executeTakeFirstOrThrow()
142+
// }
143143

144144
async function getModelInstance(modelName: string): Promise<Model> {
145145
let modelInstance: Model
@@ -157,42 +157,42 @@ async function getModelInstance(modelName: string): Promise<Model> {
157157
return modelInstance
158158
}
159159

160-
async function seedModelRelation(modelName: string): Promise<bigint | number> {
161-
let modelInstance: Model
162-
let currentPath = path.userModelsPath(`${modelName}.ts`)
160+
// async function seedModelRelation(modelName: string): Promise<bigint | number> {
161+
// let modelInstance: Model
162+
// let currentPath = path.userModelsPath(`${modelName}.ts`)
163163

164-
if (fs.existsSync(currentPath)) {
165-
modelInstance = (await import(path.userModelsPath(`${modelName}.ts`))).default as Model
166-
}
167-
else {
168-
currentPath = findCoreModel(`${modelName}.ts`)
169-
modelInstance = (await import(currentPath)).default as Model
170-
}
164+
// if (fs.existsSync(currentPath)) {
165+
// modelInstance = (await import(path.userModelsPath(`${modelName}.ts`))).default as Model
166+
// }
167+
// else {
168+
// currentPath = findCoreModel(`${modelName}.ts`)
169+
// modelInstance = (await import(currentPath)).default as Model
170+
// }
171171

172-
if (modelInstance === null || modelInstance === undefined)
173-
return 1
172+
// if (modelInstance === null || modelInstance === undefined)
173+
// return 1
174174

175-
const record: any = {}
176-
const tableName = getTableName(modelInstance, currentPath)
175+
// const record: any = {}
176+
// const tableName = getTableName(modelInstance, currentPath)
177177

178-
const useUuid = modelInstance.traits?.useUuid || false
178+
// const useUuid = modelInstance.traits?.useUuid || false
179179

180-
for (const fieldName in modelInstance.attributes) {
181-
const formattedFieldName = snakeCase(fieldName)
182-
const field = modelInstance.attributes[fieldName]
183-
// Pass faker to the factory function
184-
if (formattedFieldName === 'password')
185-
record[formattedFieldName] = field?.factory ? await makeHash(field.factory(faker), { algorithm: 'bcrypt' }) : undefined
186-
else record[formattedFieldName] = field?.factory ? field.factory(faker) : undefined
187-
}
180+
// for (const fieldName in modelInstance.attributes) {
181+
// const formattedFieldName = snakeCase(fieldName)
182+
// const field = modelInstance.attributes[fieldName]
183+
// // Pass faker to the factory function
184+
// if (formattedFieldName === 'password')
185+
// record[formattedFieldName] = field?.factory ? await makeHash(field.factory(faker), { algorithm: 'bcrypt' }) : undefined
186+
// else record[formattedFieldName] = field?.factory ? field.factory(faker) : undefined
187+
// }
188188

189-
if (useUuid)
190-
record.uuid = Bun.randomUUIDv7()
189+
// if (useUuid)
190+
// record.uuid = Bun.randomUUIDv7()
191191

192-
const data = await db.insertInto(tableName).values(record).executeTakeFirstOrThrow()
192+
// const data = await db.insertInto(tableName).values(record).executeTakeFirstOrThrow()
193193

194-
return (Number(data.insertId) || Number(data.numInsertedOrUpdatedRows)) || 1
195-
}
194+
// return (Number(data.insertId) || Number(data.numInsertedOrUpdatedRows)) || 1
195+
// }
196196

197197
export async function seed(): Promise<void> {
198198
// if a custom seeder exists, use it instead

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,7 @@ export function generateTraitBasedTables(): string {
12621262
text += ' commentables: CommentablesTable\n'
12631263
text += ' comments: CommentsTable\n'
12641264
text += ' tags: TagsTable\n'
1265+
text += ' taggables: TaggableTable\n'
12651266
text += ' commentable_upvotes: CommentableUpvotesTable\n'
12661267
text += ' categorizables: CategorizableTable\n'
12671268
text += ' categorizable_models: CategorizableModelsTable\n'

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, RequestInstance, Route, RouteGroupOptions, RouterInterface, StatusCode } from '@stacksjs/types'
3+
import process from 'node:process'
34
import { handleError } from '@stacksjs/error-handling'
45
import { log } from '@stacksjs/logging'
56
import { path as p } from '@stacksjs/path'
@@ -9,12 +10,12 @@ import { customValidate, isObject, isObjectNotEmpty } from '@stacksjs/validation
910
import { staticRoute } from './'
1011
import { response } from './response'
1112
import { extractDefaultRequest, findRequestInstanceFromAction } from './utils'
12-
import process from 'process'
1313

1414
type ActionPath = string
1515

1616
// Global cache busting timestamp for development mode
1717
declare global {
18+
// eslint-disable-next-line vars-on-top
1819
var __cacheBuster: number
1920
}
2021

storage/framework/orm/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export interface Database {
220220
commentables: CommentablesTable
221221
comments: CommentsTable
222222
tags: TagsTable
223+
taggables: TaggableTable
223224
commentable_upvotes: CommentableUpvotesTable
224225
categorizables: CategorizableTable
225226
categorizable_models: CategorizableModelsTable

0 commit comments

Comments
 (0)