@kasoa/env 0.0.7 → 0.0.9

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.
@@ -0,0 +1,2 @@
1
+ export { node as default } from "@kasoa/eslint-config/node";
2
+ //# sourceMappingURL=eslint.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1 @@
1
+ export { node as default } from "@kasoa/eslint-config/node";
@@ -0,0 +1,2 @@
1
+ export { base as default } from "@kasoa/prettier-config/base";
2
+ //# sourceMappingURL=prettier.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prettier.config.d.ts","sourceRoot":"","sources":["../prettier.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1 @@
1
+ export { base as default } from "@kasoa/prettier-config/base";
@@ -1 +1 @@
1
- {"version":3,"file":"define-env.test.d.ts","sourceRoot":"","sources":["../src/define-env.test.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"define-env.test.d.ts","sourceRoot":"","sources":["../../src/define-env.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,gBAAgB,IAC7C,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AAElC,wBAAgB,SAAS,CAAC,CAAC,SAAS,gBAAgB,EAClD,MAAM,EAAE,CAAC,EACT,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,QAAQ,CAAC,CAAC,CAAC,CAab"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kasoa/env",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Type-safe environment variable validation using Standard Schema",
@@ -26,11 +26,10 @@
26
26
  "url": "https://github.com/emmanuelchucks/kasoa/issues"
27
27
  },
28
28
  "files": [
29
- "src",
30
29
  "dist"
31
30
  ],
32
31
  "exports": {
33
- ".": "./dist/index.js"
32
+ ".": "./dist/src/index.js"
34
33
  },
35
34
  "publishConfig": {
36
35
  "access": "public"
@@ -39,14 +38,15 @@
39
38
  "@standard-schema/spec": "^1.1.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@types/node": "^25.0.9",
43
- "@typescript/native-preview": "^7.0.0-dev.20260120.1",
41
+ "@types/node": "^25.2.3",
42
+ "@typescript/native-preview": "^7.0.0-dev.20260211.1",
44
43
  "eslint": "^9.39.2",
45
- "prettier": "^3.8.0",
44
+ "prettier": "^3.8.1",
46
45
  "valibot": "^1.2.0",
47
- "vitest": "^4.0.17",
48
- "@kasoa/tsconfig": "0.0.0",
49
- "@kasoa/eslint-config": "0.0.18"
46
+ "vitest": "^4.0.18",
47
+ "@kasoa/eslint-config": "0.0.26",
48
+ "@kasoa/prettier-config": "0.0.11",
49
+ "@kasoa/tsconfig": "0.0.0"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=24"
@@ -55,7 +55,7 @@
55
55
  "dev": "tsgo --watch",
56
56
  "build": "tsgo",
57
57
  "lint": "eslint --fix --cache .",
58
- "format": "prettier --write --cache .",
58
+ "format": "prettier --write --cache --experimental-cli .",
59
59
  "typecheck": "tsgo --noEmit",
60
60
  "test": "vitest run"
61
61
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,gBAAgB,IAC7C,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AAElC,wBAAgB,SAAS,CAAC,CAAC,SAAS,gBAAgB,EAClD,MAAM,EAAE,CAAC,EACT,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,QAAQ,CAAC,CAAC,CAAC,CAab"}
@@ -1,113 +0,0 @@
1
- import * as v from "valibot";
2
- import { describe, expect, it } from "vitest";
3
- import { defineEnv } from "./index.js";
4
-
5
- describe("defineEnv()", () => {
6
- it("returns validated env object", () => {
7
- expect.assertions(1);
8
-
9
- const schema = v.object({
10
- DATABASE_URL: v.string(),
11
- PORT: v.pipe(v.string(), v.toNumber()),
12
- });
13
-
14
- const env = defineEnv(schema, {
15
- DATABASE_URL: "postgres://localhost",
16
- PORT: "3000",
17
- });
18
-
19
- expect(env).toStrictEqual({
20
- DATABASE_URL: "postgres://localhost",
21
- PORT: 3000,
22
- });
23
- });
24
-
25
- it("throws on missing required variable", () => {
26
- expect.assertions(2);
27
-
28
- const schema = v.object({
29
- DATABASE_URL: v.string(),
30
- });
31
-
32
- expect(() => defineEnv(schema, {})).toThrowError(
33
- "Environment validation failed",
34
- );
35
- expect(() => defineEnv(schema, {})).toThrowError("DATABASE_URL");
36
- });
37
-
38
- it("treats empty string as undefined", () => {
39
- expect.assertions(1);
40
-
41
- const schema = v.object({
42
- API_KEY: v.string(),
43
- });
44
-
45
- expect(() => defineEnv(schema, { API_KEY: "" })).toThrowError(
46
- "Environment validation failed",
47
- );
48
- });
49
-
50
- it("supports optional variables with defaults", () => {
51
- expect.assertions(1);
52
-
53
- const schema = v.object({
54
- PORT: v.optional(v.string(), "3000"),
55
- });
56
-
57
- const env = defineEnv(schema, {});
58
-
59
- expect(env.PORT).toBe("3000");
60
- });
61
-
62
- it("validates nested paths correctly", () => {
63
- expect.assertions(1);
64
-
65
- const schema = v.object({
66
- DATABASE_URL: v.pipe(v.string(), v.url()),
67
- });
68
-
69
- expect(() => defineEnv(schema, { DATABASE_URL: "not-a-url" })).toThrowError(
70
- "DATABASE_URL",
71
- );
72
- });
73
-
74
- it("throws TypeError for async schemas", () => {
75
- expect.assertions(2);
76
-
77
- const asyncSchema = {
78
- "~standard": {
79
- vendor: "test",
80
- version: 1 as const,
81
- validate: () => Promise.resolve({ value: {} }),
82
- },
83
- };
84
-
85
- expect(() => defineEnv(asyncSchema, {})).toThrowError(TypeError);
86
- expect(() => defineEnv(asyncSchema, {})).toThrowError(
87
- "Async schema validation is not supported",
88
- );
89
- });
90
-
91
- it("uses process.env by default", () => {
92
- expect.assertions(1);
93
-
94
- const originalEnv = process.env.TEST_VAR;
95
- process.env.TEST_VAR = "test-value";
96
-
97
- try {
98
- const schema = v.object({
99
- TEST_VAR: v.string(),
100
- });
101
-
102
- const env = defineEnv(schema);
103
-
104
- expect(env.TEST_VAR).toBe("test-value");
105
- } finally {
106
- if (originalEnv === undefined) {
107
- delete process.env.TEST_VAR;
108
- } else {
109
- process.env.TEST_VAR = originalEnv;
110
- }
111
- }
112
- });
113
- });
package/src/index.ts DELETED
@@ -1,50 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
-
3
- export type InferEnv<T extends StandardSchemaV1> =
4
- StandardSchemaV1.InferOutput<T>;
5
-
6
- export function defineEnv<T extends StandardSchemaV1>(
7
- schema: T,
8
- env: Record<string, string | undefined> = process.env,
9
- ): InferEnv<T> {
10
- const normalizedEnv = normalizeEnv(env);
11
- const result = schema["~standard"].validate(normalizedEnv);
12
-
13
- if (result instanceof Promise) {
14
- throw new TypeError("Async schema validation is not supported");
15
- }
16
-
17
- if (result.issues) {
18
- throw new Error(formatIssues(result.issues));
19
- }
20
-
21
- return result.value as InferEnv<T>;
22
- }
23
-
24
- function normalizeEnv(
25
- env: Record<string, string | undefined>,
26
- ): Record<string, string | undefined> {
27
- const normalizedEnv: Record<string, string | undefined> = {};
28
- for (const key of Object.keys(env)) {
29
- const value = env[key];
30
- normalizedEnv[key] = value === "" ? undefined : value;
31
- }
32
- return normalizedEnv;
33
- }
34
-
35
- function formatIssues(issues: readonly StandardSchemaV1.Issue[]): string {
36
- const lines = issues.map((issue) => {
37
- const key = issue.path ? getPathString(issue.path) : "root";
38
- return ` ${key}: ${issue.message}`;
39
- });
40
-
41
- return `Environment validation failed:\n\n${lines.join("\n")}`;
42
- }
43
-
44
- function getPathString(
45
- path: readonly (PropertyKey | StandardSchemaV1.PathSegment)[],
46
- ): string {
47
- return path
48
- .map((segment) => (typeof segment === "object" ? segment.key : segment))
49
- .join(".");
50
- }
File without changes
File without changes