Skip to content

Commit bb1858a

Browse files
committed
chore: wip
1 parent da1c0b1 commit bb1858a

File tree

6 files changed

+67
-29
lines changed

6 files changed

+67
-29
lines changed

bun.lockb

24 Bytes
Binary file not shown.

storage/framework/core/env/src/types.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { log } from '@stacksjs/logging'
12
import { schema } from '@stacksjs/validation'
23
import type { Infer, VineBoolean, VineEnum, VineNumber, VineString } from '@stacksjs/validation'
34
import env from '~/config/env'
@@ -38,6 +39,43 @@ const envStructure = Object.entries(env).reduce((acc, [key, value]) => {
3839
validatorType = schema.enum(value as string[])
3940
break
4041
}
42+
43+
// check if is on object
44+
if (typeof value === 'object') {
45+
const schemaNameSymbol = Symbol.for('schema_name')
46+
const schemaName = value[schemaNameSymbol]
47+
log.debug('value', value)
48+
log.debug('schemaName', schemaName)
49+
50+
if (schemaName === 'vine.string') {
51+
validatorType = schema.string()
52+
break
53+
}
54+
55+
if (schemaName === 'vine.number') {
56+
validatorType = schema.number()
57+
break
58+
}
59+
60+
if (schemaName === 'vine.boolean') {
61+
validatorType = schema.boolean()
62+
break
63+
}
64+
65+
// if (schemaName === 'vine.enum') {
66+
// validatorType = schema.enum(value as string[])
67+
// break
68+
// }
69+
70+
// oddly, enums don't trigger schemaName === 'vine.enum'
71+
if (!schemaName) {
72+
validatorType = schema.enum(value as string[])
73+
break
74+
}
75+
76+
console.error('Unknown env value type', typeof value)
77+
}
78+
4179
throw new Error(`Invalid env value for ${key}`)
4280
}
4381
const envKey = key as EnvKeys
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './is'
22
export * from './rules'
3-
export * from './validate'
3+
export * from './schema'
44
export * from './types'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { USD } from '@dinero.js/currencies'
22
import { dinero as currency } from 'dinero.js'
3-
import { schema } from './validate'
3+
import { schema } from './schema'
44

55
/**
66
* Thanks to VineJS for the following types:

storage/framework/core/validation/src/validate.ts renamed to storage/framework/core/validation/src/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type SchemaEnum = string[]
1414

1515
export type SchemaType = SchemaString | SchemaNumber | SchemaBoolean | SchemaEnum
1616

17+
export type { Infer } from '@vinejs/vine/types'
18+
export { VineString, VineBoolean, VineEnum, VineNumber, VineDate } from '@vinejs/vine'
19+
1720
export const validate = {
1821
string: (defaultValue = ''): SchemaString => defaultValue,
1922
number: (defaultValue = 1): SchemaNumber => defaultValue,
2023
boolean: (defaultValue = true): SchemaBoolean => defaultValue,
2124
enum: (values: string[]): SchemaEnum => values,
2225
}
23-
24-
export type { Infer } from '@vinejs/vine/types'
25-
export { VineString, VineBoolean, VineEnum, VineNumber, VineDate } from '@vinejs/vine'

storage/framework/types/auto-imports.d.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ declare global {
9090
const ValidationEnum: typeof import('../core/validation/src/types/index')['ValidationEnum']
9191
const ValidationNumber: typeof import('../core/validation/src/types/index')['ValidationNumber']
9292
const ValidationString: typeof import('../core/validation/src/types/index')['ValidationString']
93-
const VineBoolean: typeof import('../core/validation/src/validate')['VineBoolean']
94-
const VineDate: typeof import('../core/validation/src/validate')['VineDate']
95-
const VineEnum: typeof import('../core/validation/src/validate')['VineEnum']
96-
const VineNumber: typeof import('../core/validation/src/validate')['VineNumber']
97-
const VineString: typeof import('../core/validation/src/validate')['VineString']
93+
const VineBoolean: typeof import('../core/validation/src/schema')['VineBoolean']
94+
const VineDate: typeof import('../core/validation/src/schema')['VineDate']
95+
const VineEnum: typeof import('../core/validation/src/schema')['VineEnum']
96+
const VineNumber: typeof import('../core/validation/src/schema')['VineNumber']
97+
const VineString: typeof import('../core/validation/src/schema')['VineString']
9898
const _dirname: typeof import('../core/storage/src/helpers')['_dirname']
9999
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
100100
const actionsPath: typeof import('../core/path/src/paths')['actionsPath']
@@ -670,7 +670,7 @@ declare global {
670670
const route: typeof import('../core/router/src/router')['route']
671671
const routerPath: typeof import('../core/path/src/paths')['routerPath']
672672
const routesPath: typeof import('../core/path/src/paths')['routesPath']
673-
const rule: typeof import('../core/validation/src/validate')['rule']
673+
const rule: typeof import('../core/validation/src/schema')['rule']
674674
const runAction: typeof import('../core/actions/src/helpers/utils')['runAction']
675675
const runActions: typeof import('../core/actions/src/helpers/utils')['runActions']
676676
const runAdd: typeof import('../core/actions/src/index')['runAdd']
@@ -694,7 +694,7 @@ declare global {
694694
const runtimePath: typeof import('../core/path/src/paths')['runtimePath']
695695
const schedule: typeof import('../core/scheduler/src/schedule')['default']
696696
const schedulerPath: typeof import('../core/path/src/paths')['schedulerPath']
697-
const schema: typeof import('../core/validation/src/validate')['schema']
697+
const schema: typeof import('../core/validation/src/schema')['schema']
698698
const scriptsPath: typeof import('../core/path/src/paths')['scriptsPath']
699699
const searchEnginePath: typeof import('../core/path/src/paths')['searchEnginePath']
700700
const searchFilters: typeof import('../core/search-engine/src/index')['searchFilters']
@@ -1001,7 +1001,7 @@ declare global {
10011001
const userModelsPath: typeof import('../core/path/src/paths')['userModelsPath']
10021002
const userNotificationsPath: typeof import('../core/path/src/paths')['userNotificationsPath']
10031003
const utilsPath: typeof import('../core/path/src/paths')['utilsPath']
1004-
const validate: typeof import('../core/validation/src/validate')['validate']
1004+
const validate: typeof import('../core/validation/src/schema')['validate']
10051005
const validationPath: typeof import('../core/path/src/paths')['validationPath']
10061006
const validator: typeof import('../core/validation/src/validate')['validator']
10071007
const verifyHash: typeof import('../core/security/src/hash')['verifyHash']
@@ -1105,11 +1105,11 @@ declare module 'vue' {
11051105
readonly ValidationEnum: UnwrapRef<typeof import('../core/validation/src/types/index')['ValidationEnum']>
11061106
readonly ValidationNumber: UnwrapRef<typeof import('../core/validation/src/types/index')['ValidationNumber']>
11071107
readonly ValidationString: UnwrapRef<typeof import('../core/validation/src/types/index')['ValidationString']>
1108-
readonly VineBoolean: UnwrapRef<typeof import('../core/validation/src/validate')['VineBoolean']>
1109-
readonly VineDate: UnwrapRef<typeof import('../core/validation/src/validate')['VineDate']>
1110-
readonly VineEnum: UnwrapRef<typeof import('../core/validation/src/validate')['VineEnum']>
1111-
readonly VineNumber: UnwrapRef<typeof import('../core/validation/src/validate')['VineNumber']>
1112-
readonly VineString: UnwrapRef<typeof import('../core/validation/src/validate')['VineString']>
1108+
readonly VineBoolean: UnwrapRef<typeof import('../core/validation/src/schema')['VineBoolean']>
1109+
readonly VineDate: UnwrapRef<typeof import('../core/validation/src/schema')['VineDate']>
1110+
readonly VineEnum: UnwrapRef<typeof import('../core/validation/src/schema')['VineEnum']>
1111+
readonly VineNumber: UnwrapRef<typeof import('../core/validation/src/schema')['VineNumber']>
1112+
readonly VineString: UnwrapRef<typeof import('../core/validation/src/schema')['VineString']>
11131113
readonly _dirname: UnwrapRef<typeof import('../core/storage/src/helpers')['_dirname']>
11141114
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
11151115
readonly actionsPath: UnwrapRef<typeof import('../core/path/src/paths')['actionsPath']>
@@ -1648,7 +1648,7 @@ declare module 'vue' {
16481648
readonly route: UnwrapRef<typeof import('../core/router/src/router')['route']>
16491649
readonly routerPath: UnwrapRef<typeof import('../core/path/src/paths')['routerPath']>
16501650
readonly routesPath: UnwrapRef<typeof import('../core/path/src/paths')['routesPath']>
1651-
readonly rule: UnwrapRef<typeof import('../core/validation/src/validate')['rule']>
1651+
readonly rule: UnwrapRef<typeof import('../core/validation/src/schema')['rule']>
16521652
readonly runAction: UnwrapRef<typeof import('../core/actions/src/helpers/utils')['runAction']>
16531653
readonly runActions: UnwrapRef<typeof import('../core/actions/src/helpers/utils')['runActions']>
16541654
readonly runAdd: UnwrapRef<typeof import('../core/actions/src/index')['runAdd']>
@@ -1668,7 +1668,7 @@ declare module 'vue' {
16681668
readonly runtimePath: UnwrapRef<typeof import('../core/path/src/paths')['runtimePath']>
16691669
readonly schedule: UnwrapRef<typeof import('../core/scheduler/src/schedule')['default']>
16701670
readonly schedulerPath: UnwrapRef<typeof import('../core/path/src/paths')['schedulerPath']>
1671-
readonly schema: UnwrapRef<typeof import('../core/validation/src/validate')['schema']>
1671+
readonly schema: UnwrapRef<typeof import('../core/validation/src/schema')['schema']>
16721672
readonly scriptsPath: UnwrapRef<typeof import('../core/path/src/paths')['scriptsPath']>
16731673
readonly searchEnginePath: UnwrapRef<typeof import('../core/path/src/paths')['searchEnginePath']>
16741674
readonly searchFilters: UnwrapRef<typeof import('../core/search-engine/src/index')['searchFilters']>
@@ -1961,7 +1961,7 @@ declare module 'vue' {
19611961
readonly userModelsPath: UnwrapRef<typeof import('../core/path/src/paths')['userModelsPath']>
19621962
readonly userNotificationsPath: UnwrapRef<typeof import('../core/path/src/paths')['userNotificationsPath']>
19631963
readonly utilsPath: UnwrapRef<typeof import('../core/path/src/paths')['utilsPath']>
1964-
readonly validate: UnwrapRef<typeof import('../core/validation/src/validate')['validate']>
1964+
readonly validate: UnwrapRef<typeof import('../core/validation/src/schema')['validate']>
19651965
readonly validationPath: UnwrapRef<typeof import('../core/path/src/paths')['validationPath']>
19661966
readonly verifyHash: UnwrapRef<typeof import('../core/security/src/hash')['verifyHash']>
19671967
readonly version: UnwrapRef<typeof import('../core/utils/src/versions')['version']>
@@ -2048,11 +2048,11 @@ declare module '@vue/runtime-core' {
20482048
readonly ValidationEnum: UnwrapRef<typeof import('../core/validation/src/types/index')['ValidationEnum']>
20492049
readonly ValidationNumber: UnwrapRef<typeof import('../core/validation/src/types/index')['ValidationNumber']>
20502050
readonly ValidationString: UnwrapRef<typeof import('../core/validation/src/types/index')['ValidationString']>
2051-
readonly VineBoolean: UnwrapRef<typeof import('../core/validation/src/validate')['VineBoolean']>
2052-
readonly VineDate: UnwrapRef<typeof import('../core/validation/src/validate')['VineDate']>
2053-
readonly VineEnum: UnwrapRef<typeof import('../core/validation/src/validate')['VineEnum']>
2054-
readonly VineNumber: UnwrapRef<typeof import('../core/validation/src/validate')['VineNumber']>
2055-
readonly VineString: UnwrapRef<typeof import('../core/validation/src/validate')['VineString']>
2051+
readonly VineBoolean: UnwrapRef<typeof import('../core/validation/src/schema')['VineBoolean']>
2052+
readonly VineDate: UnwrapRef<typeof import('../core/validation/src/schema')['VineDate']>
2053+
readonly VineEnum: UnwrapRef<typeof import('../core/validation/src/schema')['VineEnum']>
2054+
readonly VineNumber: UnwrapRef<typeof import('../core/validation/src/schema')['VineNumber']>
2055+
readonly VineString: UnwrapRef<typeof import('../core/validation/src/schema')['VineString']>
20562056
readonly _dirname: UnwrapRef<typeof import('../core/storage/src/helpers')['_dirname']>
20572057
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
20582058
readonly actionsPath: UnwrapRef<typeof import('../core/path/src/paths')['actionsPath']>
@@ -2591,7 +2591,7 @@ declare module '@vue/runtime-core' {
25912591
readonly route: UnwrapRef<typeof import('../core/router/src/router')['route']>
25922592
readonly routerPath: UnwrapRef<typeof import('../core/path/src/paths')['routerPath']>
25932593
readonly routesPath: UnwrapRef<typeof import('../core/path/src/paths')['routesPath']>
2594-
readonly rule: UnwrapRef<typeof import('../core/validation/src/validate')['rule']>
2594+
readonly rule: UnwrapRef<typeof import('../core/validation/src/schema')['rule']>
25952595
readonly runAction: UnwrapRef<typeof import('../core/actions/src/helpers/utils')['runAction']>
25962596
readonly runActions: UnwrapRef<typeof import('../core/actions/src/helpers/utils')['runActions']>
25972597
readonly runAdd: UnwrapRef<typeof import('../core/actions/src/index')['runAdd']>
@@ -2611,7 +2611,7 @@ declare module '@vue/runtime-core' {
26112611
readonly runtimePath: UnwrapRef<typeof import('../core/path/src/paths')['runtimePath']>
26122612
readonly schedule: UnwrapRef<typeof import('../core/scheduler/src/schedule')['default']>
26132613
readonly schedulerPath: UnwrapRef<typeof import('../core/path/src/paths')['schedulerPath']>
2614-
readonly schema: UnwrapRef<typeof import('../core/validation/src/validate')['schema']>
2614+
readonly schema: UnwrapRef<typeof import('../core/validation/src/schema')['schema']>
26152615
readonly scriptsPath: UnwrapRef<typeof import('../core/path/src/paths')['scriptsPath']>
26162616
readonly searchEnginePath: UnwrapRef<typeof import('../core/path/src/paths')['searchEnginePath']>
26172617
readonly searchFilters: UnwrapRef<typeof import('../core/search-engine/src/index')['searchFilters']>
@@ -2904,7 +2904,7 @@ declare module '@vue/runtime-core' {
29042904
readonly userModelsPath: UnwrapRef<typeof import('../core/path/src/paths')['userModelsPath']>
29052905
readonly userNotificationsPath: UnwrapRef<typeof import('../core/path/src/paths')['userNotificationsPath']>
29062906
readonly utilsPath: UnwrapRef<typeof import('../core/path/src/paths')['utilsPath']>
2907-
readonly validate: UnwrapRef<typeof import('../core/validation/src/validate')['validate']>
2907+
readonly validate: UnwrapRef<typeof import('../core/validation/src/schema')['validate']>
29082908
readonly validationPath: UnwrapRef<typeof import('../core/path/src/paths')['validationPath']>
29092909
readonly verifyHash: UnwrapRef<typeof import('../core/security/src/hash')['verifyHash']>
29102910
readonly version: UnwrapRef<typeof import('../core/utils/src/versions')['version']>

0 commit comments

Comments
 (0)