Skip to content

Commit 063ca15

Browse files
chore: wip
1 parent 0e8538c commit 063ca15

File tree

13 files changed

+201
-151
lines changed

13 files changed

+201
-151
lines changed

storage/framework/.biomelintrc-auto-import.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,4 @@
418418
"wordChar"
419419
]
420420
}
421-
}
421+
}

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,12 @@ export async function generateModelString(
969969
}
970970
971971
verifyTwoFactorCode(code: string): boolean {
972-
if (! this.${formattedModelName}) return false
972+
const modelTwoFactorSecret = this.two_factor_secret
973+
let isValid = false
973974
974-
const modelTwoFactorSecret = this.${formattedModelName}.two_factor_secret
975-
const isValid = verifyTwoFactorCode(code, modelTwoFactorSecret)
975+
if (typeof modelTwoFactorSecret === 'string') {
976+
isValid = verifyTwoFactorCode(code, modelTwoFactorSecret)
977+
}
976978
977979
return isValid
978980
}
@@ -988,16 +990,16 @@ export async function generateModelString(
988990
constructorFields += `this.${snakeCase(attribute.field)} = ${formattedModelName}?.${snakeCase(attribute.field)}\n `
989991
jsonFields += `${snakeCase(attribute.field)}: this.${snakeCase(attribute.field)},\n `
990992

991-
whereStatements += `static where${pascalCase(attribute.field)}(value: string | number | boolean | undefined | null): ${modelName}Model {
993+
whereStatements += `static where${pascalCase(attribute.field)}(value: string): ${modelName}Model {
992994
const instance = new this(null)
993995
994996
instance.query = instance.query.where('${attribute.field}', '=', value)
995997
996998
return instance
997999
} \n\n`
9981000

999-
whereFunctionStatements += `export async function where${pascalCase(attribute.field)}(value: string | number | boolean | undefined | null): Promise<${modelName}Model[]> {
1000-
const query = db.selectFrom('${tableName}').where('${attribute.field}', '=', value)
1001+
whereFunctionStatements += `export async function where${pascalCase(attribute.field)}(value: ${entity}): Promise<${modelName}Model[]> {
1002+
const query = db.selectFrom('${tableName}').where('${snakeCase(attribute.field)}', '=', value)
10011003
const results = await query.execute()
10021004
10031005
return results.map(modelItem => new ${modelName}Model(modelItem))
@@ -1056,11 +1058,9 @@ export async function generateModelString(
10561058
`
10571059
}
10581060

1059-
if (useSoftDeletes) {
1060-
fieldString += `
1061-
deleted_at?: Date
1062-
`
1063-
}
1061+
fieldString += `
1062+
deleted_at?: Date
1063+
`
10641064

10651065
const hidden = JSON.stringify(getHiddenAttributes(model.attributes))
10661066
const fillable = JSON.stringify(getFillableAttributes(model.attributes))
@@ -1533,7 +1533,7 @@ export async function generateModelString(
15331533
throw new Error('${modelName} data is undefined')
15341534
15351535
if (this.id === undefined) {
1536-
const newModel = await db.insertInto('${tableName}')
1536+
await db.insertInto('${tableName}')
15371537
.values(this as New${modelName})
15381538
.executeTakeFirstOrThrow()
15391539
}
@@ -1547,7 +1547,7 @@ export async function generateModelString(
15471547
if (this.id === undefined)
15481548
throw new Error('${modelName} ID is undefined');
15491549
1550-
const model = this.find(this.id)
1550+
const model = await this.find(this.id)
15511551
15521552
// Check if soft deletes are enabled
15531553
if (this.softDeletes) {
@@ -1610,9 +1610,8 @@ export async function generateModelString(
16101610
toJSON() {
16111611
const output: Partial<${modelName}Type> = ${jsonFields}
16121612
1613-
this.hidden.forEach((attr) => {
1614-
if (attr in output)
1615-
delete output[attr as keyof Partial<${modelName}Type>]
1613+
this.hidden.forEach((attr: string) => {
1614+
if (attr in output) delete (output as Record<string, any>)[attr]
16161615
})
16171616
16181617
type ${modelName} = Omit<${modelName}Type, 'password'>

storage/framework/core/strings/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { intro, outro } from '../build/src'
21
import { dts } from 'bun-plugin-dts-auto'
2+
import { intro, outro } from '../build/src'
33

44
const { startTime } = await intro({
55
dir: import.meta.dir,

storage/framework/env.d.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
1-
export declare const envKeys: readonly ["APP_NAME", "APP_ENV", "APP_KEY", "APP_URL", "PORT", "PORT_BACKEND", "PORT_ADMIN", "PORT_LIBRARY", "PORT_DESKTOP", "PORT_EMAIL", "PORT_DOCS", "PORT_INSPECT", "PORT_API", "PORT_SYSTEM_TRAY", "APP_MAINTENANCE", "API_PREFIX", "DOCS_PREFIX", "DEBUG", "DB_CONNECTION", "DB_HOST", "DB_PORT", "DB_DATABASE", "DB_USERNAME", "DB_PASSWORD", "AWS_ACCOUNT_ID", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_DEFAULT_REGION", "AWS_DEFAULT_PASSWORD", "MAIL_MAILER", "MAIL_HOST", "MAIL_PORT", "MAIL_USERNAME", "MAIL_PASSWORD", "MAIL_ENCRYPTION", "MAIL_FROM_NAME", "MAIL_FROM_ADDRESS", "SEARCH_ENGINE_DRIVER", "MEILISEARCH_HOST", "MEILISEARCH_KEY", "FRONTEND_APP_ENV", "FRONTEND_APP_URL"];
2-
export type EnvKey = (typeof envKeys)[number];
1+
export declare const envKeys: readonly [
2+
'APP_NAME',
3+
'APP_ENV',
4+
'APP_KEY',
5+
'APP_URL',
6+
'PORT',
7+
'PORT_BACKEND',
8+
'PORT_ADMIN',
9+
'PORT_LIBRARY',
10+
'PORT_DESKTOP',
11+
'PORT_EMAIL',
12+
'PORT_DOCS',
13+
'PORT_INSPECT',
14+
'PORT_API',
15+
'PORT_SYSTEM_TRAY',
16+
'APP_MAINTENANCE',
17+
'API_PREFIX',
18+
'DOCS_PREFIX',
19+
'DEBUG',
20+
'DB_CONNECTION',
21+
'DB_HOST',
22+
'DB_PORT',
23+
'DB_DATABASE',
24+
'DB_USERNAME',
25+
'DB_PASSWORD',
26+
'AWS_ACCOUNT_ID',
27+
'AWS_ACCESS_KEY_ID',
28+
'AWS_SECRET_ACCESS_KEY',
29+
'AWS_DEFAULT_REGION',
30+
'AWS_DEFAULT_PASSWORD',
31+
'MAIL_MAILER',
32+
'MAIL_HOST',
33+
'MAIL_PORT',
34+
'MAIL_USERNAME',
35+
'MAIL_PASSWORD',
36+
'MAIL_ENCRYPTION',
37+
'MAIL_FROM_NAME',
38+
'MAIL_FROM_ADDRESS',
39+
'SEARCH_ENGINE_DRIVER',
40+
'MEILISEARCH_HOST',
41+
'MEILISEARCH_KEY',
42+
'FRONTEND_APP_ENV',
43+
'FRONTEND_APP_URL',
44+
]
45+
export type EnvKey = (typeof envKeys)[number]

storage/framework/orm/src/models/AccessToken.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface PersonalAccessTokensTable {
2222
created_at?: Date
2323

2424
updated_at?: Date
25+
26+
deleted_at?: Date
2527
}
2628

2729
interface AccessTokenResponse {
@@ -352,31 +354,31 @@ export class AccessTokenModel {
352354
return instance
353355
}
354356

355-
static whereName(value: string | number | boolean | undefined | null): AccessTokenModel {
357+
static whereName(value: string): AccessTokenModel {
356358
const instance = new this(null)
357359

358360
instance.query = instance.query.where('name', '=', value)
359361

360362
return instance
361363
}
362364

363-
static whereToken(value: string | number | boolean | undefined | null): AccessTokenModel {
365+
static whereToken(value: string): AccessTokenModel {
364366
const instance = new this(null)
365367

366368
instance.query = instance.query.where('token', '=', value)
367369

368370
return instance
369371
}
370372

371-
static wherePlainTextToken(value: string | number | boolean | undefined | null): AccessTokenModel {
373+
static wherePlainTextToken(value: string): AccessTokenModel {
372374
const instance = new this(null)
373375

374376
instance.query = instance.query.where('plainTextToken', '=', value)
375377

376378
return instance
377379
}
378380

379-
static whereAbilities(value: string | number | boolean | undefined | null): AccessTokenModel {
381+
static whereAbilities(value: string): AccessTokenModel {
380382
const instance = new this(null)
381383

382384
instance.query = instance.query.where('abilities', '=', value)
@@ -490,7 +492,7 @@ export class AccessTokenModel {
490492
if (!this) throw new Error('AccessToken data is undefined')
491493

492494
if (this.id === undefined) {
493-
const newModel = await db
495+
await db
494496
.insertInto('personal_access_tokens')
495497
.values(this as NewAccessToken)
496498
.executeTakeFirstOrThrow()
@@ -503,7 +505,7 @@ export class AccessTokenModel {
503505
async delete(): Promise<void> {
504506
if (this.id === undefined) throw new Error('AccessToken ID is undefined')
505507

506-
const model = this.find(this.id)
508+
const model = await this.find(this.id)
507509

508510
// Check if soft deletes are enabled
509511
if (this.softDeletes) {
@@ -580,8 +582,8 @@ export class AccessTokenModel {
580582
updated_at: this.updated_at,
581583
}
582584

583-
this.hidden.forEach((attr) => {
584-
if (attr in output) delete output[attr as keyof Partial<AccessTokenType>]
585+
this.hidden.forEach((attr: string) => {
586+
if (attr in output) delete (output as Record<string, any>)[attr]
585587
})
586588

587589
type AccessToken = Omit<AccessTokenType, 'password'>
@@ -628,30 +630,28 @@ export async function remove(id: number): Promise<void> {
628630
await db.deleteFrom('personal_access_tokens').where('id', '=', id).execute()
629631
}
630632

631-
export async function whereName(value: string | number | boolean | undefined | null): Promise<AccessTokenModel[]> {
633+
export async function whereName(value: string): Promise<AccessTokenModel[]> {
632634
const query = db.selectFrom('personal_access_tokens').where('name', '=', value)
633635
const results = await query.execute()
634636

635637
return results.map((modelItem) => new AccessTokenModel(modelItem))
636638
}
637639

638-
export async function whereToken(value: string | number | boolean | undefined | null): Promise<AccessTokenModel[]> {
640+
export async function whereToken(value: string): Promise<AccessTokenModel[]> {
639641
const query = db.selectFrom('personal_access_tokens').where('token', '=', value)
640642
const results = await query.execute()
641643

642644
return results.map((modelItem) => new AccessTokenModel(modelItem))
643645
}
644646

645-
export async function wherePlainTextToken(
646-
value: string | number | boolean | undefined | null,
647-
): Promise<AccessTokenModel[]> {
648-
const query = db.selectFrom('personal_access_tokens').where('plainTextToken', '=', value)
647+
export async function wherePlainTextToken(value: string): Promise<AccessTokenModel[]> {
648+
const query = db.selectFrom('personal_access_tokens').where('plain_text_token', '=', value)
649649
const results = await query.execute()
650650

651651
return results.map((modelItem) => new AccessTokenModel(modelItem))
652652
}
653653

654-
export async function whereAbilities(value: string | number | boolean | undefined | null): Promise<AccessTokenModel[]> {
654+
export async function whereAbilities(value: string[]): Promise<AccessTokenModel[]> {
655655
const query = db.selectFrom('personal_access_tokens').where('abilities', '=', value)
656656
const results = await query.execute()
657657

0 commit comments

Comments
 (0)