@adamhl8/configs 0.24.13 → 0.25.0

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.
@@ -6,7 +6,7 @@ declare const knipConfig: OptionalMergeConfigFn<KnipConfig, {
6
6
  readonly project: ["**"];
7
7
  readonly entry: ["./src/index.ts", "**/*.test.ts", "./tsdown.config.ts"];
8
8
  readonly ignoreBinaries: ["lefthook", "gh"];
9
- readonly ignoreDependencies: ("@adamhl8/eslint-plugin-clean-modules" | "@commitlint/cli")[];
9
+ readonly ignoreDependencies: ("@commitlint/cli" | "@adamhl8/eslint-plugin-clean-modules")[];
10
10
  readonly tsdown: false;
11
11
  }>;
12
12
  //#endregion
@@ -0,0 +1,9 @@
1
+ import { requireWhen } from "./utils.js";
2
+ import arkenv from "arkenv";
3
+
4
+ //#region src/env/index.d.ts
5
+ type ArkEnv = typeof arkenv;
6
+ declare const parseEnv: ArkEnv;
7
+ //#endregion
8
+ export { parseEnv, requireWhen };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/env/index.ts"],"mappings":";;;;KAKK,MAAA,UAAgB,MAAM;AAAA,cAEd,QAAA,EAOP,MAAM"}
@@ -0,0 +1,17 @@
1
+ import { requireWhen } from "./utils.js";
2
+ import process from "node:process";
3
+ import arkenv from "arkenv";
4
+ import { attempt, isErr } from "ts-explicit-errors";
5
+ //#region src/env/index.ts
6
+ const parseEnv = ((...args) => {
7
+ const env = attempt(() => arkenv(...args));
8
+ if (isErr(env)) {
9
+ console.error(env.message);
10
+ process.exit(1);
11
+ }
12
+ return env;
13
+ });
14
+ //#endregion
15
+ export { parseEnv, requireWhen };
16
+
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/env/index.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport arkenv from \"arkenv\"\nimport { attempt, isErr } from \"ts-explicit-errors\"\n\ntype ArkEnv = typeof arkenv\n\nexport const parseEnv = ((...args: Parameters<ArkEnv>) => {\n const env = attempt(() => arkenv(...args))\n if (isErr(env)) {\n console.error(env.message)\n process.exit(1)\n }\n return env\n}) as ArkEnv\n\nexport { requireWhen } from \"#/env/utils.ts\"\n"],"mappings":";;;;;AAOA,MAAa,aAAa,GAAG,SAA6B;CACxD,MAAM,MAAM,cAAc,OAAO,GAAG,IAAI,CAAC;CACzC,IAAI,MAAM,GAAG,GAAG;EACd,QAAQ,MAAM,IAAI,OAAO;EACzB,QAAQ,KAAK,CAAC;CAChB;CACA,OAAO;AACT"}
@@ -0,0 +1,14 @@
1
+ import { type } from "arktype";
2
+
3
+ //#region src/env/utils.d.ts
4
+ /**
5
+ * Makes an env var required while `when` is true, otherwise optional.
6
+ *
7
+ * A set value must always satisfy `def`. An unset var takes `fallback` (exempt from `def` validation), or the key is
8
+ * omitted entirely if no fallback is given.
9
+ */
10
+ declare function requireWhen<const type$1>(when: boolean, type: type.validate<type$1>): ReturnType<type.instantiate<type$1>["optional"]>;
11
+ declare function requireWhen<const type$2>(when: boolean, type: type.validate<type$2>, fallback: type.infer<type$2>): type.instantiate<type$2>;
12
+ //#endregion
13
+ export { requireWhen };
14
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/env/utils.ts"],"mappings":";;;;;AASA;;;;iBAAgB,WAAA,eACd,IAAA,WACA,IAAA,EAAM,IAAA,CAAQ,QAAA,CAAS,MAAA,IACtB,UAAA,CAAW,IAAA,CAAQ,WAAA,CAAY,MAAA;AAAA,iBAClB,WAAA,eACd,IAAA,WACA,IAAA,EAAM,IAAA,CAAQ,QAAA,CAAS,MAAA,GACvB,QAAA,EAAU,IAAA,CAAQ,KAAA,CAAM,MAAA,IACvB,IAAA,CAAQ,WAAA,CAAY,MAAA"}
@@ -0,0 +1,14 @@
1
+ import { type } from "arkenv";
2
+ //#region src/env/utils.ts
3
+ function requireWhen(when, type$1, ...rest) {
4
+ const t = type.raw(type$1);
5
+ if (when) return t;
6
+ if (rest.length === 0) return t.optional();
7
+ const [fallback] = rest;
8
+ const unset = Symbol("unset");
9
+ return t.or(type.unit(unset)).pipe((v) => v === unset ? fallback : v).default(unset);
10
+ }
11
+ //#endregion
12
+ export { requireWhen };
13
+
14
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["arkenvType","type"],"sources":["../../src/env/utils.ts"],"sourcesContent":["import { type as arkenvType } from \"arkenv\"\nimport type { type as arktype } from \"arktype\"\n\n/**\n * Makes an env var required while `when` is true, otherwise optional.\n *\n * A set value must always satisfy `def`. An unset var takes `fallback` (exempt from `def` validation), or the key is\n * omitted entirely if no fallback is given.\n */\nexport function requireWhen<const type>(\n when: boolean,\n type: arktype.validate<type>,\n): ReturnType<arktype.instantiate<type>[\"optional\"]>\nexport function requireWhen<const type>(\n when: boolean,\n type: arktype.validate<type>,\n fallback: arktype.infer<type>,\n): arktype.instantiate<type>\n/* oxlint-disable typescript/no-unsafe-type-assertion */\nexport function requireWhen(when: boolean, type: unknown, ...rest: [unknown?]): never {\n const t = arkenvType.raw(type)\n if (when) return t as never\n if (rest.length === 0) return t.optional() as never\n const [fallback] = rest\n // defaulting to a sentinel keeps the fallback exempt from def validation without\n // letting an explicitly set value bypass it (env values can never be a symbol)\n const unset = Symbol(\"unset\")\n return t\n .or(arkenvType.unit(unset))\n .pipe((v: unknown) => (v === unset ? fallback : v))\n .default(unset as never) as never\n}\n"],"mappings":";;AAmBA,SAAgB,YAAY,MAAe,QAAe,GAAG,MAAyB;CACpF,MAAM,IAAIA,KAAW,IAAIC,MAAI;CAC7B,IAAI,MAAM,OAAO;CACjB,IAAI,KAAK,WAAW,GAAG,OAAO,EAAE,SAAS;CACzC,MAAM,CAAC,YAAY;CAGnB,MAAM,QAAQ,OAAO,OAAO;CAC5B,OAAO,EACJ,GAAGD,KAAW,KAAK,KAAK,CAAC,CAAC,CAC1B,MAAM,MAAgB,MAAM,QAAQ,WAAW,CAAE,CAAC,CAClD,QAAQ,KAAc;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamhl8/configs",
3
- "version": "0.24.13",
3
+ "version": "0.25.0",
4
4
  "homepage": "https://github.com/adamhl8/configs",
5
5
  "bugs": {
6
6
  "url": "https://github.com/adamhl8/configs/issues"
@@ -31,6 +31,10 @@
31
31
  ".": {
32
32
  "types": "./dist/index.d.ts",
33
33
  "import": "./dist/index.js"
34
+ },
35
+ "./env": {
36
+ "types": "./dist/env/index.d.ts",
37
+ "import": "./dist/env/index.js"
34
38
  }
35
39
  },
36
40
  "publishConfig": {
@@ -48,7 +52,10 @@
48
52
  "@adamhl8/eslint-plugin-clean-modules": "^0.1.3",
49
53
  "@commitlint/config-conventional": "^21.2.0",
50
54
  "@commitlint/types": "^21.2.0",
55
+ "arkenv": "^0.12.2",
56
+ "arktype": "^2.2.2",
51
57
  "es-toolkit": "^1.49.0",
58
+ "ts-explicit-errors": "^4.1.2",
52
59
  "type-fest": "^5.7.0"
53
60
  },
54
61
  "devDependencies": {