@gobing-ai/ts-utils 0.4.63 → 0.4.67
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/env.d.ts +42 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +52 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/env.ts +59 -0
- package/src/index.ts +1 -0
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-variable gateway — the sanctioned funnel for `process.env` access
|
|
3
|
+
* (mirrors `packages/config` in gobing-ai/spur; enforced by the
|
|
4
|
+
* `boundary/env-var-hygiene` rule). Direct `process.env`/`Bun.env` access is
|
|
5
|
+
* banned outside this module so the set of env consumers stays greppable.
|
|
6
|
+
*
|
|
7
|
+
* These accessors are node-bun only: on `cloudflare-workers` there is no
|
|
8
|
+
* `process`; inject config explicitly rather than calling them (ADR-008).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Read one environment variable. Only an unset variable yields `fallback`;
|
|
12
|
+
* an empty string is a set value and is returned as-is.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getEnvVar(name: string, fallback?: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Read the live environment as a record. The returned object IS `process.env`
|
|
17
|
+
* (not a copy): whole-record operations (`{ ...getEnvVars(), ...vars }`,
|
|
18
|
+
* `Object.entries(getEnvVars())`) see later mutations, which child-spawn
|
|
19
|
+
* composition relies on. For single variables prefer {@link getEnvVar},
|
|
20
|
+
* {@link setEnvVar}, or {@link removeEnvVar}.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getEnvVars(): Record<string, string | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Set one environment variable through the sanctioned gateway. Passing
|
|
25
|
+
* `undefined` removes the key, so the save/restore idiom
|
|
26
|
+
* (`const prev = getEnvVar(k); … setEnvVar(k, prev)`) restores absence exactly.
|
|
27
|
+
*/
|
|
28
|
+
export declare function setEnvVar(name: string, value: string | undefined): void;
|
|
29
|
+
/** Remove one environment variable; a no-op when the key is absent. */
|
|
30
|
+
export declare function removeEnvVar(name: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Read a runtime option from a `bootstrap.options`-style option bag, returning
|
|
33
|
+
* `fallback` when the config, section, or key is absent (or null). The typed
|
|
34
|
+
* replacement surface for config-carrying environment variables — call sites
|
|
35
|
+
* own key naming and value coercion.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getAppOptions<T>(config: {
|
|
38
|
+
bootstrap?: {
|
|
39
|
+
options?: Record<string, unknown> | null;
|
|
40
|
+
} | null;
|
|
41
|
+
} | null | undefined, key: string, fallback: T): T;
|
|
42
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG7E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAGvE;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC3B,MAAM,EAAE;IAAE,SAAS,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EAC9F,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,GACZ,CAAC,CAGH"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-variable gateway — the sanctioned funnel for `process.env` access
|
|
3
|
+
* (mirrors `packages/config` in gobing-ai/spur; enforced by the
|
|
4
|
+
* `boundary/env-var-hygiene` rule). Direct `process.env`/`Bun.env` access is
|
|
5
|
+
* banned outside this module so the set of env consumers stays greppable.
|
|
6
|
+
*
|
|
7
|
+
* These accessors are node-bun only: on `cloudflare-workers` there is no
|
|
8
|
+
* `process`; inject config explicitly rather than calling them (ADR-008).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Read one environment variable. Only an unset variable yields `fallback`;
|
|
12
|
+
* an empty string is a set value and is returned as-is.
|
|
13
|
+
*/
|
|
14
|
+
export function getEnvVar(name, fallback) {
|
|
15
|
+
const raw = process.env[name];
|
|
16
|
+
return raw === undefined ? fallback : raw;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read the live environment as a record. The returned object IS `process.env`
|
|
20
|
+
* (not a copy): whole-record operations (`{ ...getEnvVars(), ...vars }`,
|
|
21
|
+
* `Object.entries(getEnvVars())`) see later mutations, which child-spawn
|
|
22
|
+
* composition relies on. For single variables prefer {@link getEnvVar},
|
|
23
|
+
* {@link setEnvVar}, or {@link removeEnvVar}.
|
|
24
|
+
*/
|
|
25
|
+
export function getEnvVars() {
|
|
26
|
+
return process.env;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set one environment variable through the sanctioned gateway. Passing
|
|
30
|
+
* `undefined` removes the key, so the save/restore idiom
|
|
31
|
+
* (`const prev = getEnvVar(k); … setEnvVar(k, prev)`) restores absence exactly.
|
|
32
|
+
*/
|
|
33
|
+
export function setEnvVar(name, value) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
delete process.env[name];
|
|
36
|
+
else
|
|
37
|
+
process.env[name] = value;
|
|
38
|
+
}
|
|
39
|
+
/** Remove one environment variable; a no-op when the key is absent. */
|
|
40
|
+
export function removeEnvVar(name) {
|
|
41
|
+
delete process.env[name];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Read a runtime option from a `bootstrap.options`-style option bag, returning
|
|
45
|
+
* `fallback` when the config, section, or key is absent (or null). The typed
|
|
46
|
+
* replacement surface for config-carrying environment variables — call sites
|
|
47
|
+
* own key naming and value coercion.
|
|
48
|
+
*/
|
|
49
|
+
export function getAppOptions(config, key, fallback) {
|
|
50
|
+
const value = config?.bootstrap?.options?.[key];
|
|
51
|
+
return value === undefined || value === null ? fallback : value;
|
|
52
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/src/env.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-variable gateway — the sanctioned funnel for `process.env` access
|
|
3
|
+
* (mirrors `packages/config` in gobing-ai/spur; enforced by the
|
|
4
|
+
* `boundary/env-var-hygiene` rule). Direct `process.env`/`Bun.env` access is
|
|
5
|
+
* banned outside this module so the set of env consumers stays greppable.
|
|
6
|
+
*
|
|
7
|
+
* These accessors are node-bun only: on `cloudflare-workers` there is no
|
|
8
|
+
* `process`; inject config explicitly rather than calling them (ADR-008).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Read one environment variable. Only an unset variable yields `fallback`;
|
|
13
|
+
* an empty string is a set value and is returned as-is.
|
|
14
|
+
*/
|
|
15
|
+
export function getEnvVar(name: string, fallback?: string): string | undefined {
|
|
16
|
+
const raw = process.env[name];
|
|
17
|
+
return raw === undefined ? fallback : raw;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Read the live environment as a record. The returned object IS `process.env`
|
|
22
|
+
* (not a copy): whole-record operations (`{ ...getEnvVars(), ...vars }`,
|
|
23
|
+
* `Object.entries(getEnvVars())`) see later mutations, which child-spawn
|
|
24
|
+
* composition relies on. For single variables prefer {@link getEnvVar},
|
|
25
|
+
* {@link setEnvVar}, or {@link removeEnvVar}.
|
|
26
|
+
*/
|
|
27
|
+
export function getEnvVars(): Record<string, string | undefined> {
|
|
28
|
+
return process.env;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Set one environment variable through the sanctioned gateway. Passing
|
|
33
|
+
* `undefined` removes the key, so the save/restore idiom
|
|
34
|
+
* (`const prev = getEnvVar(k); … setEnvVar(k, prev)`) restores absence exactly.
|
|
35
|
+
*/
|
|
36
|
+
export function setEnvVar(name: string, value: string | undefined): void {
|
|
37
|
+
if (value === undefined) delete process.env[name];
|
|
38
|
+
else process.env[name] = value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Remove one environment variable; a no-op when the key is absent. */
|
|
42
|
+
export function removeEnvVar(name: string): void {
|
|
43
|
+
delete process.env[name];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Read a runtime option from a `bootstrap.options`-style option bag, returning
|
|
48
|
+
* `fallback` when the config, section, or key is absent (or null). The typed
|
|
49
|
+
* replacement surface for config-carrying environment variables — call sites
|
|
50
|
+
* own key naming and value coercion.
|
|
51
|
+
*/
|
|
52
|
+
export function getAppOptions<T>(
|
|
53
|
+
config: { bootstrap?: { options?: Record<string, unknown> | null } | null } | null | undefined,
|
|
54
|
+
key: string,
|
|
55
|
+
fallback: T,
|
|
56
|
+
): T {
|
|
57
|
+
const value = config?.bootstrap?.options?.[key];
|
|
58
|
+
return value === undefined || value === null ? fallback : (value as T);
|
|
59
|
+
}
|