@arki/env 0.0.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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/contracts/common.d.ts +24 -0
- package/dist/contracts/common.d.ts.map +1 -0
- package/dist/contracts/common.js +23 -0
- package/dist/contracts/common.js.map +1 -0
- package/dist/contracts/index.d.ts +32 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +14 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/parsing.d.ts +7 -0
- package/dist/contracts/parsing.d.ts.map +1 -0
- package/dist/contracts/parsing.js +18 -0
- package/dist/contracts/parsing.js.map +1 -0
- package/dist/contracts/urls.d.ts +7 -0
- package/dist/contracts/urls.d.ts.map +1 -0
- package/dist/contracts/urls.js +14 -0
- package/dist/contracts/urls.js.map +1 -0
- package/dist/core/define-env.d.ts +13 -0
- package/dist/core/define-env.d.ts.map +1 -0
- package/dist/core/define-env.js +18 -0
- package/dist/core/define-env.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/dot.d.ts +69 -0
- package/dist/dot.d.ts.map +1 -0
- package/dist/dot.js +59 -0
- package/dist/dot.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ARKI Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @arki/env
|
|
2
|
+
|
|
3
|
+
Type-safe environment variable parsing for ARKI. `defineEnv()` is a thin wrapper around [`@t3-oss/env-core`](https://env.t3.gg/) with Zod contracts for common variable shapes — ports, URLs, comma-separated lists, JSON, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @arki/env
|
|
9
|
+
# or
|
|
10
|
+
bun add @arki/env
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @arki/env
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### `defineEnv`
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineEnv } from '@arki/env/core';
|
|
21
|
+
import { contracts } from '@arki/env/contracts';
|
|
22
|
+
|
|
23
|
+
export const env = defineEnv({
|
|
24
|
+
server: {
|
|
25
|
+
NODE_ENV: contracts.nodeEnv(),
|
|
26
|
+
PORT: contracts.port(3000),
|
|
27
|
+
DATABASE_URL: contracts.url(),
|
|
28
|
+
LOG_LEVEL: contracts.string('info'),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(env.PORT); // number
|
|
33
|
+
console.log(env.DATABASE_URL); // string (validated URL)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`defineEnv` reads from `process.env`, validates against the Zod schemas in `server`, and returns a fully typed object. It skips validation when `CI` is set or `NODE_ENV !== 'development'` unless you override via `options.skipValidation`.
|
|
37
|
+
|
|
38
|
+
### Contracts
|
|
39
|
+
|
|
40
|
+
The `contracts` namespace bundles common variable shapes so you do not have to assemble them by hand. The categories:
|
|
41
|
+
|
|
42
|
+
- **Common**: `string`, `number`, `boolean`, `port`, `nodeEnv`.
|
|
43
|
+
- **URLs**: `url`, `httpsUrl`, `postgresUrl`, `redisUrl`.
|
|
44
|
+
- **Parsing**: `csv`, `json`, `keyValue`.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { contracts } from '@arki/env/contracts';
|
|
48
|
+
|
|
49
|
+
const env = defineEnv({
|
|
50
|
+
server: {
|
|
51
|
+
ALLOWED_ORIGINS: contracts.csv(), // 'a,b,c' → ['a', 'b', 'c']
|
|
52
|
+
FEATURE_FLAGS: contracts.json(), // JSON-parsed
|
|
53
|
+
SERVICE_TAGS: contracts.keyValue(), // 'a=1,b=2' → { a: '1', b: '2' }
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
- `@arki/env/core`
|
|
61
|
+
- `defineEnv(config)` — validate `process.env` and return a typed object.
|
|
62
|
+
- `@arki/env/contracts`
|
|
63
|
+
- `contracts` — flattened namespace of all built-in Zod contracts.
|
|
64
|
+
- `commonContracts`, `urlContracts`, `parseContracts` — per-category namespaces.
|
|
65
|
+
- `@arki/env`
|
|
66
|
+
- Re-exports `contracts` from `@arki/env/contracts`.
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
`@arki/env` ships an optional `@arki/env/dot` adapter for the
|
|
71
|
+
[`@arki/dot`](https://www.npmjs.com/package/@arki/dot) framework.
|
|
72
|
+
|
|
73
|
+
- See `packages/dot/docs/` in the [`@arki/dot`](https://www.npmjs.com/package/@arki/dot)
|
|
74
|
+
package for plugin authoring, lifecycle, diagnostics, and the
|
|
75
|
+
[adapter authoring guide](https://github.com/arkijs/arki/blob/main/packages/dot/docs/adapter-authoring.md).
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const commonContracts: {
|
|
3
|
+
string: (defaultValue?: string) => z.ZodString | z.ZodDefault<z.ZodString>;
|
|
4
|
+
number: (defaultValue?: number) => z.ZodCoercedNumber<unknown> | z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
5
|
+
port: (defaultValue?: number) => z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
6
|
+
nodeEnv: () => z.ZodDefault<z.ZodEnum<{
|
|
7
|
+
development: "development";
|
|
8
|
+
production: "production";
|
|
9
|
+
test: "test";
|
|
10
|
+
}>>;
|
|
11
|
+
boolean: (defaultValue?: boolean) => z.ZodPipe<z.ZodDefault<z.ZodEnum<{
|
|
12
|
+
0: "0";
|
|
13
|
+
1: "1";
|
|
14
|
+
true: "true";
|
|
15
|
+
false: "false";
|
|
16
|
+
}>>, z.ZodTransform<boolean, "0" | "1" | "true" | "false">>;
|
|
17
|
+
logLevel: (defaultValue?: "debug" | "info" | "warn" | "error") => z.ZodDefault<z.ZodEnum<{
|
|
18
|
+
debug: "debug";
|
|
19
|
+
info: "info";
|
|
20
|
+
warn: "warn";
|
|
21
|
+
error: "error";
|
|
22
|
+
}>>;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/contracts/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;4BACF,MAAM;4BAKN,MAAM;;;;;;;;;;;;;8BAoBL,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;;;;;;CAE7D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const commonContracts = {
|
|
3
|
+
string: (defaultValue) => {
|
|
4
|
+
const schema = z.string();
|
|
5
|
+
return defaultValue ? schema.default(defaultValue) : schema;
|
|
6
|
+
},
|
|
7
|
+
number: (defaultValue) => {
|
|
8
|
+
const schema = z.coerce.number();
|
|
9
|
+
return defaultValue ? schema.default(defaultValue) : schema;
|
|
10
|
+
},
|
|
11
|
+
port: (defaultValue = 3000) => z
|
|
12
|
+
.coerce.number()
|
|
13
|
+
.min(1, 'Port must be at least 1')
|
|
14
|
+
.max(65_535, 'Port must be at most 65535')
|
|
15
|
+
.default(defaultValue),
|
|
16
|
+
nodeEnv: () => z.enum(['development', 'production', 'test']).default('development'),
|
|
17
|
+
boolean: (defaultValue = false) => z
|
|
18
|
+
.enum(['true', 'false', '1', '0'])
|
|
19
|
+
.default(defaultValue ? 'true' : 'false')
|
|
20
|
+
.transform(val => val === 'true' || val === '1'),
|
|
21
|
+
logLevel: (defaultValue = 'info') => z.enum(['debug', 'info', 'warn', 'error']).default(defaultValue),
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/contracts/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,CAAC,YAAqB,EAAE,EAAE;QAChC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAED,MAAM,EAAE,CAAC,YAAqB,EAAE,EAAE;QAChC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAED,IAAI,EAAE,CAAC,YAAY,GAAG,IAAI,EAAE,EAAE,CAC5B,CAAC;SACE,MAAM,CAAC,MAAM,EAAE;SACf,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC;SACjC,GAAG,CAAC,MAAM,EAAE,4BAA4B,CAAC;SACzC,OAAO,CAAC,YAAY,CAAC;IAE1B,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAEnF,OAAO,EAAE,CAAC,YAAY,GAAG,KAAK,EAAE,EAAE,CAChC,CAAC;SACE,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;SACjC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;SACxC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC;IAEpD,QAAQ,EAAE,CAAC,eAAoD,MAAM,EAAE,EAAE,CACvE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;CACnE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const contracts: {
|
|
2
|
+
json: <T extends import("zod").ZodType>(schema: T) => import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<Awaited<import("zod").infer<T>>, string>>;
|
|
3
|
+
csvArray: <T extends import("zod").ZodType>(itemSchema: T) => import("zod").ZodPipe<import("zod").ZodTransform<unknown, unknown>, import("zod").ZodArray<T>>;
|
|
4
|
+
csvSet: <T extends import("zod").ZodType>(itemSchema: T) => import("zod").ZodPipe<import("zod").ZodTransform<unknown, unknown>, import("zod").ZodArray<T>>;
|
|
5
|
+
url: (defaultValue?: string) => import("zod").ZodString | import("zod").ZodDefault<import("zod").ZodString>;
|
|
6
|
+
databaseUrl: () => import("zod").ZodURL;
|
|
7
|
+
redisUrl: () => import("zod").ZodURL;
|
|
8
|
+
string: (defaultValue?: string) => import("zod").ZodString | import("zod").ZodDefault<import("zod").ZodString>;
|
|
9
|
+
number: (defaultValue?: number) => import("zod").ZodCoercedNumber<unknown> | import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
|
|
10
|
+
port: (defaultValue?: number) => import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
|
|
11
|
+
nodeEnv: () => import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
12
|
+
development: "development";
|
|
13
|
+
production: "production";
|
|
14
|
+
test: "test";
|
|
15
|
+
}>>;
|
|
16
|
+
boolean: (defaultValue?: boolean) => import("zod").ZodPipe<import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
17
|
+
0: "0";
|
|
18
|
+
1: "1";
|
|
19
|
+
true: "true";
|
|
20
|
+
false: "false";
|
|
21
|
+
}>>, import("zod").ZodTransform<boolean, "0" | "1" | "true" | "false">>;
|
|
22
|
+
logLevel: (defaultValue?: "debug" | "info" | "warn" | "error") => import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
23
|
+
debug: "debug";
|
|
24
|
+
info: "info";
|
|
25
|
+
warn: "warn";
|
|
26
|
+
error: "error";
|
|
27
|
+
}>>;
|
|
28
|
+
};
|
|
29
|
+
export { commonContracts } from './common.js';
|
|
30
|
+
export { urlContracts } from './urls.js';
|
|
31
|
+
export { parseContracts } from './parsing.js';
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIrB,CAAC;AAKF,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { commonContracts } from './common.js';
|
|
2
|
+
import { parseContracts } from './parsing.js';
|
|
3
|
+
import { urlContracts } from './urls.js';
|
|
4
|
+
// Unified contracts export
|
|
5
|
+
export const contracts = {
|
|
6
|
+
...commonContracts,
|
|
7
|
+
...urlContracts,
|
|
8
|
+
...parseContracts,
|
|
9
|
+
};
|
|
10
|
+
// Individual category exports
|
|
11
|
+
export { commonContracts } from './common.js';
|
|
12
|
+
export { urlContracts } from './urls.js';
|
|
13
|
+
export { parseContracts } from './parsing.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,GAAG,eAAe;IAClB,GAAG,YAAY;IACf,GAAG,cAAc;CAClB,CAAC;AAEF,8BAA8B;AAG9B,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const parseContracts: {
|
|
3
|
+
json: <T extends z.ZodType>(schema: T) => z.ZodPipe<z.ZodString, z.ZodTransform<Awaited<z.core.output<T>>, string>>;
|
|
4
|
+
csvArray: <T extends z.ZodType>(itemSchema: T) => z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodArray<T>>;
|
|
5
|
+
csvSet: <T extends z.ZodType>(itemSchema: T) => z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodArray<T>>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=parsing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/contracts/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc;WAClB,CAAC,SAAS,CAAC,CAAC,OAAO,UAAU,CAAC;eAM1B,CAAC,SAAS,CAAC,CAAC,OAAO,cAAc,CAAC;aASpC,CAAC,SAAS,CAAC,CAAC,OAAO,cAAc,CAAC;CAQ5C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const parseContracts = {
|
|
3
|
+
json: (schema) => z.string().transform((str) => {
|
|
4
|
+
const parsed = JSON.parse(str);
|
|
5
|
+
return schema.parse(parsed);
|
|
6
|
+
}),
|
|
7
|
+
csvArray: (itemSchema) => z.preprocess((val) => {
|
|
8
|
+
if (typeof val !== 'string')
|
|
9
|
+
return val;
|
|
10
|
+
return val.split(',').map((s) => s.trim());
|
|
11
|
+
}, z.array(itemSchema)),
|
|
12
|
+
csvSet: (itemSchema) => z.preprocess((val) => {
|
|
13
|
+
if (typeof val !== 'string')
|
|
14
|
+
return val;
|
|
15
|
+
return [...new Set(val.split(',').map((s) => s.trim()))];
|
|
16
|
+
}, z.array(itemSchema)),
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=parsing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.js","sourceRoot":"","sources":["../../src/contracts/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,CAAsB,MAAS,EAAE,EAAE,CACvC,CAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAe,CAAC;IAC5C,CAAC,CAAC;IAEJ,QAAQ,EAAE,CAAsB,UAAa,EAAE,EAAE,CAC/C,CAAC,CAAC,UAAU,CACV,CAAC,GAAG,EAAE,EAAE;QACN,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAC;QACxC,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC,EACD,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CACpB;IAEH,MAAM,EAAE,CAAsB,UAAa,EAAE,EAAE,CAC7C,CAAC,CAAC,UAAU,CACV,CAAC,GAAG,EAAE,EAAE;QACN,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAC;QACxC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC,EACD,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CACpB;CACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/contracts/urls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,YAAY;yBACF,MAAM;;;CAiB5B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const urlContracts = {
|
|
3
|
+
url: (defaultValue) => {
|
|
4
|
+
const schema = z.string().url();
|
|
5
|
+
return defaultValue ? schema.default(defaultValue) : schema;
|
|
6
|
+
},
|
|
7
|
+
databaseUrl: () => z
|
|
8
|
+
.url()
|
|
9
|
+
.refine(url => url.startsWith('postgres://') || url.startsWith('postgresql://'), 'Database URL must start with postgres:// or postgresql://'),
|
|
10
|
+
redisUrl: () => z
|
|
11
|
+
.url()
|
|
12
|
+
.refine(url => url.startsWith('redis://') || url.startsWith('rediss://'), 'Redis URL must start with redis:// or rediss://'),
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=urls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../../src/contracts/urls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,GAAG,EAAE,CAAC,YAAqB,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC;IAED,WAAW,EAAE,GAAG,EAAE,CAChB,CAAC;SACE,GAAG,EAAE;SACL,MAAM,CACL,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC,EACvE,2DAA2D,CAC5D;IAEL,QAAQ,EAAE,GAAG,EAAE,CACb,CAAC;SACE,GAAG,EAAE;SACL,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,iDAAiD,CAAC;CACjI,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
type CoreEnvConfig = {
|
|
3
|
+
server: Record<string, ZodType>;
|
|
4
|
+
options?: {
|
|
5
|
+
skipValidation?: boolean;
|
|
6
|
+
onValidationError?: (issues: any) => never;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare function defineEnv(config: CoreEnvConfig): Readonly<{
|
|
10
|
+
[x: string]: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=define-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-env.d.ts","sourceRoot":"","sources":["../../src/core/define-env.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,aAAa,GAAG;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE;QACR,cAAc,CAAC,EAAE,OAAO,CAAC;QAEzB,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,KAAK,CAAC;KAC5C,CAAC;CACH,CAAC;AAEF,wBAAgB,SAAS,CAAC,MAAM,EAAE,aAAa;;GAiB9C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createEnv } from '@t3-oss/env-core';
|
|
2
|
+
export function defineEnv(config) {
|
|
3
|
+
const skipValidation = config.options?.skipValidation ?? (!!process.env.CI || process.env.NODE_ENV !== 'development');
|
|
4
|
+
// Auto-generate runtimeEnv (no Next.js bundler constraints)
|
|
5
|
+
const runtimeEnv = {};
|
|
6
|
+
for (const key of Object.keys(config.server)) {
|
|
7
|
+
runtimeEnv[key] = process.env[key];
|
|
8
|
+
}
|
|
9
|
+
return createEnv({
|
|
10
|
+
server: config.server,
|
|
11
|
+
client: {},
|
|
12
|
+
clientPrefix: '',
|
|
13
|
+
runtimeEnv,
|
|
14
|
+
skipValidation,
|
|
15
|
+
onValidationError: config.options?.onValidationError,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=define-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-env.js","sourceRoot":"","sources":["../../src/core/define-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAY7C,MAAM,UAAU,SAAS,CAAC,MAAqB;IAC7C,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,EAAE,cAAc,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC;IAEtH,4DAA4D;IAC5D,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7C,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,SAAS,CAAC;QACf,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,EAAE;QAChB,UAAU;QACV,cAAc;QACd,iBAAiB,EAAE,MAAM,CAAC,OAAO,EAAE,iBAAiB;KACrD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/dot.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOT adapter for `@arki/env`.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `defineEnv()` as a `DotPip` so a DOT app can validate its
|
|
5
|
+
* environment alongside any other services. The pip is sync (env
|
|
6
|
+
* validation is sync), so the `boot` hook returns the validated env
|
|
7
|
+
* object synchronously through the standard `services` channel.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { defineApp } from '@arki/dot';
|
|
12
|
+
* import { env } from '@arki/env/dot';
|
|
13
|
+
* import { z } from 'zod';
|
|
14
|
+
*
|
|
15
|
+
* const app = await defineApp('my-app')
|
|
16
|
+
* .use(env({ schema: { PORT: z.coerce.number().default(3000) } }))
|
|
17
|
+
* .boot();
|
|
18
|
+
*
|
|
19
|
+
* console.log(app.services.env.PORT); // number, typed.
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The `@arki/dot` package is an OPTIONAL peer of `@arki/env`. Importing
|
|
23
|
+
* this adapter without `@arki/dot` installed will fail at module load —
|
|
24
|
+
* that is intentional: the adapter only makes sense in a DOT app.
|
|
25
|
+
*/
|
|
26
|
+
import { type DotPip } from '@arki/dot/pip';
|
|
27
|
+
import type { ZodType } from 'zod';
|
|
28
|
+
/**
|
|
29
|
+
* Options for the env DOT adapter.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam TSchema - The shape of the `server` schema record. The
|
|
32
|
+
* resulting `app.services.env` is typed from this.
|
|
33
|
+
*/
|
|
34
|
+
export type EnvDotOptions<TSchema extends Record<string, ZodType>> = {
|
|
35
|
+
/** Zod schemas for each env var the pip validates. */
|
|
36
|
+
readonly schema: TSchema;
|
|
37
|
+
/**
|
|
38
|
+
* Pip name override. Defaults to `'env'`. Use this only when
|
|
39
|
+
* composing multiple env scopes inside the same app (rare).
|
|
40
|
+
*/
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Forwarded to `defineEnv`. If `true`, the validator is skipped
|
|
44
|
+
* entirely. By default, validation is skipped when `CI` is set or
|
|
45
|
+
* `NODE_ENV !== 'development'`.
|
|
46
|
+
*/
|
|
47
|
+
readonly skipValidation?: boolean;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The shape of services published by the env adapter.
|
|
51
|
+
*
|
|
52
|
+
* The key is configurable via `options.name` (defaults to `'env'`) so
|
|
53
|
+
* downstream pips can pick the right env when multiple env scopes
|
|
54
|
+
* exist. For the default single-env case, `app.services.env` is the
|
|
55
|
+
* validated record.
|
|
56
|
+
*/
|
|
57
|
+
export type EnvServices<TSchema extends Record<string, ZodType>> = {
|
|
58
|
+
readonly env: {
|
|
59
|
+
readonly [K in keyof TSchema]: TSchema[K] extends ZodType<infer U> ? U : never;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Build a DOT pip that validates and publishes a typed `env` service.
|
|
64
|
+
*
|
|
65
|
+
* @param options - Schema + optional config.
|
|
66
|
+
* @returns A `DotPip` that registers an `env`-kind service.
|
|
67
|
+
*/
|
|
68
|
+
export declare function env<TSchema extends Record<string, ZodType>>(options: EnvDotOptions<TSchema>): DotPip<EnvServices<TSchema>>;
|
|
69
|
+
//# sourceMappingURL=dot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dot.d.ts","sourceRoot":"","sources":["../src/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAInC;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACnE,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACjE,QAAQ,CAAC,GAAG,EAAE;QAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;KAAE,CAAC;CAClG,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,GAC9B,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAyB9B"}
|
package/dist/dot.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOT adapter for `@arki/env`.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `defineEnv()` as a `DotPip` so a DOT app can validate its
|
|
5
|
+
* environment alongside any other services. The pip is sync (env
|
|
6
|
+
* validation is sync), so the `boot` hook returns the validated env
|
|
7
|
+
* object synchronously through the standard `services` channel.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { defineApp } from '@arki/dot';
|
|
12
|
+
* import { env } from '@arki/env/dot';
|
|
13
|
+
* import { z } from 'zod';
|
|
14
|
+
*
|
|
15
|
+
* const app = await defineApp('my-app')
|
|
16
|
+
* .use(env({ schema: { PORT: z.coerce.number().default(3000) } }))
|
|
17
|
+
* .boot();
|
|
18
|
+
*
|
|
19
|
+
* console.log(app.services.env.PORT); // number, typed.
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The `@arki/dot` package is an OPTIONAL peer of `@arki/env`. Importing
|
|
23
|
+
* this adapter without `@arki/dot` installed will fail at module load —
|
|
24
|
+
* that is intentional: the adapter only makes sense in a DOT app.
|
|
25
|
+
*/
|
|
26
|
+
import { defineDotPip } from '@arki/dot/pip';
|
|
27
|
+
import { defineEnv } from './core/define-env.js';
|
|
28
|
+
/**
|
|
29
|
+
* Build a DOT pip that validates and publishes a typed `env` service.
|
|
30
|
+
*
|
|
31
|
+
* @param options - Schema + optional config.
|
|
32
|
+
* @returns A `DotPip` that registers an `env`-kind service.
|
|
33
|
+
*/
|
|
34
|
+
export function env(options) {
|
|
35
|
+
const name = options.name ?? 'env';
|
|
36
|
+
return defineDotPip({
|
|
37
|
+
name,
|
|
38
|
+
version: '0.1.0',
|
|
39
|
+
provides: ['env'],
|
|
40
|
+
configure(ctx) {
|
|
41
|
+
ctx.registerService('env', 'env');
|
|
42
|
+
},
|
|
43
|
+
boot() {
|
|
44
|
+
const validated = defineEnv({
|
|
45
|
+
server: options.schema,
|
|
46
|
+
options: options.skipValidation !== undefined
|
|
47
|
+
? { skipValidation: options.skipValidation }
|
|
48
|
+
: undefined,
|
|
49
|
+
});
|
|
50
|
+
// `defineEnv` returns a Proxy from `@t3-oss/env-core`; we narrow it
|
|
51
|
+
// to the schema-derived shape so downstream typing flows through.
|
|
52
|
+
// The runtime guarantee comes from Zod-side validation inside
|
|
53
|
+
// `defineEnv`. No `any` involved — the cast is type-only.
|
|
54
|
+
const envObject = validated;
|
|
55
|
+
return { services: { env: envObject } };
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=dot.js.map
|
package/dist/dot.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dot.js","sourceRoot":"","sources":["../src/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAoCjD;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CACjB,OAA+B;IAE/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC;IACnC,OAAO,YAAY,CAAuB;QACxC,IAAI;QACJ,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,CAAC,KAAK,CAAC;QACjB,SAAS,CAAC,GAAG;YACX,GAAG,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC;QACD,IAAI;YACF,MAAM,SAAS,GAAG,SAAS,CAAC;gBAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EACL,OAAO,CAAC,cAAc,KAAK,SAAS;oBAClC,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE;oBAC5C,CAAC,CAAC,SAAS;aAChB,CAAC,CAAC;YACH,oEAAoE;YACpE,kEAAkE;YAClE,8DAA8D;YAC9D,0DAA0D;YAC1D,MAAM,SAAS,GAAG,SAAmD,CAAC;YACtE,OAAO,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC;QAC1C,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arki/env",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Type-safe environment variable parsing for ARKI — defineEnv() built on @t3-oss/env-core with Zod contracts for common variable shapes.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/arki-labs/arki.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://arki.dev",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/arki-labs/arki/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"arki",
|
|
16
|
+
"typescript",
|
|
17
|
+
"env",
|
|
18
|
+
"environment",
|
|
19
|
+
"zod",
|
|
20
|
+
"t3-env",
|
|
21
|
+
"config"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./core": {
|
|
32
|
+
"types": "./dist/core/index.d.ts",
|
|
33
|
+
"import": "./dist/core/index.js",
|
|
34
|
+
"default": "./dist/core/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./contracts": {
|
|
37
|
+
"types": "./dist/contracts/index.d.ts",
|
|
38
|
+
"import": "./dist/contracts/index.js",
|
|
39
|
+
"default": "./dist/contracts/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./dot": {
|
|
42
|
+
"types": "./dist/dot.d.ts",
|
|
43
|
+
"import": "./dist/dot.js",
|
|
44
|
+
"default": "./dist/dot.js"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist/**",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE",
|
|
52
|
+
"package.json"
|
|
53
|
+
],
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@t3-oss/env-core": "^0.13.10",
|
|
56
|
+
"zod": "4.3.5"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@arki/dot": "^0.1.1"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"@arki/dot": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
}
|
|
69
|
+
}
|