Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed May 18, 2024
1 parent a9a650d commit 05ae57a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
1 change: 0 additions & 1 deletion storage/framework/core/database/src/drivers/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ok } from '@stacksjs/error-handling'
import { modelTableName } from '@stacksjs/orm'
import { path } from '@stacksjs/path'
import { fs, glob } from '@stacksjs/storage'
import { pluralize, snakeCase } from '@stacksjs/strings'
import type { Attribute, Attributes, Model } from '@stacksjs/types'
import { checkPivotMigration, fetchOtherModelRelations, getLastMigrationFields, hasTableBeenMigrated, mapFieldTypeToColumnType } from '.'

Expand Down
13 changes: 13 additions & 0 deletions storage/framework/core/orm/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { generator, parser, traverse } from '@stacksjs/build'
import { fs } from '@stacksjs/storage'
import { plural, snakeCase } from '@stacksjs/strings'
import type { Attributes } from '@stacksjs/types'
import type { Model } from '@stacksjs/types'

type ModelPath = string

export async function modelTableName(model: Model | ModelPath): Promise<string> {
if (typeof model === 'string') {
const modelPath = model
model = (await import(model)).default as Model
}

return model.table ?? snakeCase(plural(model.name ?? modelPath.replace(/.*\/(.*)\.ts$/, '$1')))
}

export async function extractFieldsFromModel(filePath: string) {
// Read the TypeScript file
Expand Down
11 changes: 10 additions & 1 deletion storage/framework/database/models/AccessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ export default {
'`abilities` must be string of either `read`, `write`, `admin`, `read|write`, `read|admin`, `write|admin`, or `read|write|admin`',
},

factory: () => collect(['read', 'write', 'admin', 'read|write', 'read|admin', 'write|admin', 'read|write|admin']).random(),
factory: () =>
collect([
'read',
'write',
'admin',
'read|write',
'read|admin',
'write|admin',
'read|write|admin',
]).random(),
},
},
} satisfies Model
4 changes: 2 additions & 2 deletions storage/framework/database/models/Project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { collect } from '@stacksjs/collections'
import { faker } from '@stacksjs/faker'
import type { Model } from '@stacksjs/types'
import { schema } from '@stacksjs/validation'
import { collect } from '@stacksjs/collections'

export default {
name: 'Project', // defaults to the sanitized file name
Expand Down Expand Up @@ -33,7 +33,7 @@ export default {
message: '`description` must be a string',
},

factory: () => faker.lorem.sentence({ min: 10, max: 10 }),
factory: () => faker.lorem.sentence({ min: 10, max: 25 }),
},

url: {
Expand Down
2 changes: 0 additions & 2 deletions storage/framework/orm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './Subscriber.ts'

export * from './utils'
12 changes: 0 additions & 12 deletions storage/framework/orm/src/utils.ts

This file was deleted.

0 comments on commit 05ae57a

Please sign in to comment.