@stacksjs/env 0.67.0 → 0.68.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -3
- package/dist/types.d.ts +80 -13
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Env } from './types';
|
|
2
|
+
import type { EnvKey } from '../../../env';
|
|
3
|
+
|
|
4
|
+
declare const handler: {
|
|
5
|
+
get: (target: Env, key: EnvKey) => unknown
|
|
6
|
+
};
|
|
3
7
|
export declare function process(): Env;
|
|
4
8
|
export declare const env: Env;
|
|
5
9
|
export declare function writeEnv(key: EnvKey, value: string, options?: { path: string }): void;
|
|
6
|
-
export * from
|
|
10
|
+
export * from './types'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +1,84 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { EnvKey } from '../../../env';
|
|
2
|
+
import type { VineBoolean, VineEnum, VineNumber, VineString } from '@stacksjs/validation';
|
|
3
|
+
|
|
4
|
+
declare interface EnumObject {
|
|
5
|
+
[key: string]: string[]
|
|
5
6
|
}
|
|
6
7
|
export declare const envEnum: EnumObject;
|
|
7
|
-
type EnvValue = string | boolean | number | readonly string[]
|
|
8
|
+
declare type EnvValue = string | boolean | number | readonly string[]
|
|
9
|
+
type EnvType = typeof env
|
|
10
|
+
type EnvKeys = keyof EnvType
|
|
11
|
+
type EnvMap = {
|
|
12
|
+
[K in EnvKeys]: EnvType[K] extends string
|
|
13
|
+
? VineString
|
|
14
|
+
: EnvType[K] extends number
|
|
15
|
+
? VineNumber
|
|
16
|
+
: EnvType[K] extends boolean
|
|
17
|
+
? VineBoolean
|
|
18
|
+
: EnvType[K] extends readonly string[]
|
|
19
|
+
? VineEnum<string[]>
|
|
20
|
+
: unknown
|
|
21
|
+
}
|
|
22
|
+
declare type ValidatorType = VineString | VineNumber | VineBoolean | VineEnum<string[]>
|
|
23
|
+
|
|
24
|
+
const envStructure = Object.entries(env).reduce((acc, [key, value]) => {
|
|
25
|
+
let validatorType: ValidatorType
|
|
26
|
+
switch (typeof value) {
|
|
27
|
+
case 'string':
|
|
28
|
+
validatorType = schema.string()
|
|
29
|
+
break
|
|
30
|
+
case 'number':
|
|
31
|
+
validatorType = schema.number()
|
|
32
|
+
break
|
|
33
|
+
case 'boolean':
|
|
34
|
+
validatorType = schema.boolean()
|
|
35
|
+
break
|
|
36
|
+
default:
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
validatorType = schema.enum(value as string[])
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof value === 'object') {
|
|
43
|
+
const schemaNameSymbol = Symbol.for('schema_name')
|
|
44
|
+
const schemaName = value[schemaNameSymbol]
|
|
45
|
+
|
|
46
|
+
if (schemaName === 'vine.string') {
|
|
47
|
+
validatorType = schema.string()
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (schemaName === 'vine.number') {
|
|
52
|
+
validatorType = schema.number()
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (schemaName === 'vine.boolean') {
|
|
57
|
+
validatorType = schema.boolean()
|
|
58
|
+
break
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if (!schemaName) {
|
|
63
|
+
validatorType = schema.enum(envEnum.APP_ENV)
|
|
64
|
+
break
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.error('Unknown env value type', typeof value)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
throw new Error(`Invalid env value for ${key}`)
|
|
71
|
+
}
|
|
72
|
+
const envKey = key as EnvKeys
|
|
73
|
+
|
|
74
|
+
acc[envKey] = validatorType as any
|
|
75
|
+
return acc
|
|
76
|
+
}, {} as EnvMap)
|
|
8
77
|
export declare const envSchema: unknown;
|
|
9
|
-
export type
|
|
10
|
-
export type
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
FRONTEND_APP_URL: string;
|
|
78
|
+
export declare type EnvOptions = Env
|
|
79
|
+
export type EnvConfig = Partial<Record<EnvKey, EnvValue>>
|
|
80
|
+
export declare interface FrontendEnv {
|
|
81
|
+
FRONTEND_APP_ENV: 'local' | 'development' | 'staging' | 'production'
|
|
82
|
+
FRONTEND_APP_URL: string
|
|
15
83
|
}
|
|
16
|
-
export type FrontendEnvKeys = keyof FrontendEnv
|
|
17
|
-
export {};
|
|
84
|
+
export declare type FrontendEnvKeys = keyof FrontendEnv
|
package/dist/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|