@lambdot/env 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0](https://github.com/Embers-of-the-Fire/lambdot/compare/env-v0.0.1...env-v0.1.0) (2026-08-29)
4
+
5
+
6
+ ### Features
7
+
8
+ * **protocol-qq:** qq protocol with gateway and webhook infras ([d41936b](https://github.com/Embers-of-the-Fire/lambdot/commit/d41936be964e620c6da5641aecfe5f370c2e541c))
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@lambdot/env",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.ts"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "dependencies": {
12
+ "@lambdot/core": "workspace:*"
13
+ }
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,50 @@
1
+ import type { Disposer, FeaturePlugin } from "@lambdot/core";
2
+
3
+ /**
4
+ * The typed capability contract shared by an environment provider and its
5
+ * consumers, parameterized by capability name: the provider declares it as
6
+ * `TProvides`, consumers as `TInjects`. The value is a snapshot of the
7
+ * requested variables, keyed by variable name. Distinct names fold side by
8
+ * side (`EnvCapability<"qq-env"> & EnvCapability<"discord-env">`), exactly
9
+ * like `WsCapability` in `@lambdot/websocket`.
10
+ */
11
+ export type EnvCapability<TCap extends string, TKey extends string> = {
12
+ readonly [K in TCap]: Readonly<Record<TKey, string>>;
13
+ };
14
+
15
+ /**
16
+ * Read variables from `process.env` and provide them as a typed capability.
17
+ * A missing or empty variable fails activation loudly at kernel start, so a
18
+ * misconfigured deployment surfaces before any consumer activates.
19
+ *
20
+ * ```ts
21
+ * createKernel().use(envVars("qq-env", ["QQ_BOT_APP_ID", "QQ_BOT_APP_SECRET"]));
22
+ * // ctx["qq-env"].QQ_BOT_APP_ID: string
23
+ * ```
24
+ */
25
+ export function envVars<TCap extends string, TKey extends string>(
26
+ capability: TCap,
27
+ keys: readonly TKey[],
28
+ ): FeaturePlugin<{}, {}, undefined, void, `env:${TCap}`, EnvCapability<TCap, TKey>> {
29
+ return {
30
+ name: `env:${capability}`,
31
+ apply(ctx) {
32
+ const values: Record<string, string> = {};
33
+ for (const key of keys) {
34
+ const value = process.env[key];
35
+ if (value === undefined || value === "")
36
+ throw new Error(
37
+ `env:${capability}: required environment variable "${key}" is not set`,
38
+ );
39
+ values[key] = value;
40
+ }
41
+ // The kernel's `provide` keeps its value parameter behind a
42
+ // conditional type that stays deferred for a generic capability
43
+ // name; `EnvCapability<TCap, TKey>` already ties this name to the
44
+ // record, so pin the call down here (same trick as `wsTransport`).
45
+ return (
46
+ ctx.provide as (name: TCap, value: Readonly<Record<TKey, string>>) => Disposer
47
+ ).call(ctx, capability, values as Readonly<Record<TKey, string>>);
48
+ },
49
+ };
50
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"]
4
+ }