Skip to content

Commit e4612b4

Browse files
committed
chore: wip
1 parent 4fe1098 commit e4612b4

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

storage/framework/core/actions/src/helpers/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import { Glob } from 'bun'
1717
export async function runAction(action: string, options?: ActionOptions) {
1818
// check if action is a file anywhere in ./app/Actions/**/*.ts
1919
// if it is, return and await the action
20-
console.log('action', action)
2120
const glob = new Glob('**/*.ts')
2221
const scanOptions = { cwd: p.userActionsPath(), onlyFiles: true }
2322

2423
for await (const file of glob.scan(scanOptions)) {
25-
console.log('file', file)
24+
log.debug('file', file)
2625
if (file === `${action}.ts` || file.endsWith(`${action}.ts`))
2726
return ((await import(p.userActionsPath(file))).default as Action).handle()
2827

storage/framework/core/validation/src/rules.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { USD } from '@dinero.js/currencies'
2-
import vine from '@vinejs/vine'
32
import { dinero as currency } from 'dinero.js'
3+
import { schema } from './validate'
44

55
/**
66
* Thanks to VineJS for the following types:
@@ -95,23 +95,22 @@ export interface ErrorReporterContract {
9595
report: (message: string, rule: string, field: FieldContext, args?: Record<string, any>) => any
9696
}
9797

98-
export const isMoney = vine.createRule((value: unknown, _, field: FieldContext) => {
98+
export const isMoney = schema.createRule((value: unknown, _, field: FieldContext) => {
9999
/**
100100
* Convert string representation of a number to a JavaScript
101101
* Number data type.
102102
*/
103-
const asNumber = (value: unknown): number => {
104-
const result = Number(value)
105-
return Number.isNaN(result) ? 0 : result
106-
}
107-
108-
const numericValue = asNumber(value)
103+
const numericValue = schema.helpers.asNumber(value)
109104

110105
/**
111106
* Report error, if the value is NaN post-conversion
112107
*/
113108
if (Number.isNaN(numericValue)) {
114-
field.report('The {{ field }} field value must be a number', 'money', field)
109+
field.report(
110+
'The {{ field }} field value must be a number',
111+
'money',
112+
field
113+
)
115114
return
116115
}
117116

@@ -124,4 +123,4 @@ export const isMoney = vine.createRule((value: unknown, _, field: FieldContext)
124123
* Mutate the field's value
125124
*/
126125
field.mutate(amount, field)
127-
}) as any
126+
})

storage/framework/core/validation/src/types/money.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { BaseLiteralType } from '@vinejs/vine'
33
import type { FieldOptions, Validation } from '@vinejs/vine/types'
44
import { isMoney } from '../rules'
55

6-
export class MoneyValidator extends BaseLiteralType<Money, Money> {
6+
export class MoneyValidator extends BaseLiteralType<string, Money, Money> {
77
constructor(options?: FieldOptions, validations?: Validation<any>[]) {
88
super(options, validations || [isMoney()])
99
}
1010

1111
clone() {
12-
return new MoneyValidator(this.cloneOptions(), this.cloneValidations()) as this
12+
return new MoneyValidator(
13+
this.cloneOptions(),
14+
this.cloneValidations()
15+
) as this
1316
}
1417
}

storage/framework/core/validation/src/validate.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { MoneyValidator } from './types/money'
55
export { schema, rule }
66

77
// @ts-expect-error - investigate why this is not working
8-
Vine.macro('money', () => {
9-
return new MoneyValidator()
10-
})
8+
Vine.macro('money', () => new MoneyValidator())
119

1210
type SchemaString = string
1311
type SchemaNumber = number
@@ -24,4 +22,4 @@ export const validate = {
2422
}
2523

2624
export type { Infer } from '@vinejs/vine/types'
27-
export { VineString, VineBoolean, VineEnum, VineNumber } from '@vinejs/vine'
25+
export { VineString, VineBoolean, VineEnum, VineNumber, VineDate } from '@vinejs/vine'

0 commit comments

Comments
 (0)