scenv 0.1.1 → 0.2.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/dist/index.cjs CHANGED
@@ -25,24 +25,24 @@ __export(index_exports, {
25
25
  getCallbacks: () => getCallbacks,
26
26
  getContextValues: () => getContextValues,
27
27
  loadConfig: () => loadConfig,
28
- parseSenvArgs: () => parseSenvArgs,
28
+ parseScenvArgs: () => parseScenvArgs,
29
29
  resetConfig: () => resetConfig,
30
- senv: () => senv
30
+ scenv: () => scenv
31
31
  });
32
32
  module.exports = __toCommonJS(index_exports);
33
33
 
34
34
  // src/config.ts
35
35
  var import_node_fs = require("fs");
36
36
  var import_node_path = require("path");
37
- var CONFIG_FILENAME = "senv.config.json";
37
+ var CONFIG_FILENAME = "scenv.config.json";
38
38
  var envKeyMap = {
39
- SENV_CONTEXT: "contexts",
40
- SENV_ADD_CONTEXTS: "addContexts",
41
- SENV_PROMPT: "prompt",
42
- SENV_IGNORE_ENV: "ignoreEnv",
43
- SENV_IGNORE_CONTEXT: "ignoreContext",
44
- SENV_SAVE_PROMPT: "savePrompt",
45
- SENV_SAVE_CONTEXT_TO: "saveContextTo"
39
+ SCENV_CONTEXT: "contexts",
40
+ SCENV_ADD_CONTEXTS: "addContexts",
41
+ SCENV_PROMPT: "prompt",
42
+ SCENV_IGNORE_ENV: "ignoreEnv",
43
+ SCENV_IGNORE_CONTEXT: "ignoreContext",
44
+ SCENV_SAVE_PROMPT: "savePrompt",
45
+ SCENV_SAVE_CONTEXT_TO: "saveContextTo"
46
46
  };
47
47
  var programmaticConfig = {};
48
48
  var programmaticCallbacks = {};
@@ -269,7 +269,7 @@ function normalizeValidatorResult(result) {
269
269
  if (result.success === true) return result;
270
270
  return result;
271
271
  }
272
- function senv(name, options = {}) {
272
+ function scenv(name, options = {}) {
273
273
  const key = options.key ?? defaultKeyFromName(name);
274
274
  const envKey = options.env ?? defaultEnvFromKey(key);
275
275
  const validator = options.validator;
@@ -391,7 +391,7 @@ function senv(name, options = {}) {
391
391
  }
392
392
 
393
393
  // src/cli-args.ts
394
- function parseSenvArgs(argv) {
394
+ function parseScenvArgs(argv) {
395
395
  const config = {};
396
396
  let i = 0;
397
397
  while (i < argv.length) {
@@ -442,7 +442,7 @@ function parseSenvArgs(argv) {
442
442
  getCallbacks,
443
443
  getContextValues,
444
444
  loadConfig,
445
- parseSenvArgs,
445
+ parseScenvArgs,
446
446
  resetConfig,
447
- senv
447
+ scenv
448
448
  });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  type PromptMode = "always" | "never" | "fallback" | "no-env";
2
2
  type SavePromptMode = "always" | "never" | "ask";
3
- interface SenvConfig {
3
+ interface ScenvConfig {
4
4
  /** Replace all contexts with this list (CLI: --context a,b,c) */
5
5
  contexts?: string[];
6
6
  /** Merge these contexts with existing (CLI: --add-context a,b,c) */
@@ -20,22 +20,22 @@ interface SenvConfig {
20
20
  /** Root directory for config/context search (default: cwd) */
21
21
  root?: string;
22
22
  }
23
- interface SenvCallbacks {
23
+ interface ScenvCallbacks {
24
24
  /** When user was just prompted for a value and savePrompt is ask/always: (variableName, value, contextNames) => context name to save to, or null to skip */
25
25
  onAskSaveAfterPrompt?: (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
26
26
  /** When saveContextTo is "ask": (variableName, contextNames) => context name to save to */
27
27
  onAskContext?: (name: string, contextNames: string[]) => Promise<string>;
28
28
  }
29
- declare function getCallbacks(): SenvCallbacks;
29
+ declare function getCallbacks(): ScenvCallbacks;
30
30
  /**
31
31
  * Load full config: file (from root or cwd) <- env <- programmatic. Precedence: programmatic > env > file.
32
32
  */
33
- declare function loadConfig(root?: string): SenvConfig;
33
+ declare function loadConfig(root?: string): ScenvConfig;
34
34
  /**
35
35
  * Set programmatic config (e.g. from CLI flags). Merged on top of env and file in loadConfig().
36
36
  */
37
- declare function configure(partial: Partial<SenvConfig> & {
38
- callbacks?: SenvCallbacks;
37
+ declare function configure(partial: Partial<ScenvConfig> & {
38
+ callbacks?: ScenvCallbacks;
39
39
  }): void;
40
40
  /**
41
41
  * Reset programmatic config (mainly for tests).
@@ -59,14 +59,14 @@ type ValidatorResult<T> = boolean | {
59
59
  error?: unknown;
60
60
  };
61
61
  type PromptFn<T> = (name: string, defaultValue: T) => T | Promise<T>;
62
- interface SenvVariableOptions<T> {
62
+ interface ScenvVariableOptions<T> {
63
63
  key?: string;
64
64
  env?: string;
65
65
  default?: T;
66
66
  validator?: (val: T) => ValidatorResult<T>;
67
67
  prompt?: PromptFn<T>;
68
68
  }
69
- interface SenvVariable<T> {
69
+ interface ScenvVariable<T> {
70
70
  get(): Promise<T>;
71
71
  safeGet(): Promise<{
72
72
  success: true;
@@ -77,13 +77,13 @@ interface SenvVariable<T> {
77
77
  }>;
78
78
  save(value?: T): Promise<void>;
79
79
  }
80
- declare function senv<T>(name: string, options?: SenvVariableOptions<T>): SenvVariable<T>;
80
+ declare function scenv<T>(name: string, options?: ScenvVariableOptions<T>): ScenvVariable<T>;
81
81
 
82
82
  /**
83
- * Parse argv (e.g. process.argv.slice(2)) into SenvConfig for configure().
83
+ * Parse argv (e.g. process.argv.slice(2)) into ScenvConfig for configure().
84
84
  * Supports: --context a,b,c --add-context x,y --prompt fallback --ignore-env --ignore-context
85
85
  * --set key=value --save-prompt ask --save-context-to prod
86
86
  */
87
- declare function parseSenvArgs(argv: string[]): Partial<SenvConfig>;
87
+ declare function parseScenvArgs(argv: string[]): Partial<ScenvConfig>;
88
88
 
89
- export { type PromptMode, type SavePromptMode, type SenvCallbacks, type SenvConfig, type SenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseSenvArgs, resetConfig, senv };
89
+ export { type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  type PromptMode = "always" | "never" | "fallback" | "no-env";
2
2
  type SavePromptMode = "always" | "never" | "ask";
3
- interface SenvConfig {
3
+ interface ScenvConfig {
4
4
  /** Replace all contexts with this list (CLI: --context a,b,c) */
5
5
  contexts?: string[];
6
6
  /** Merge these contexts with existing (CLI: --add-context a,b,c) */
@@ -20,22 +20,22 @@ interface SenvConfig {
20
20
  /** Root directory for config/context search (default: cwd) */
21
21
  root?: string;
22
22
  }
23
- interface SenvCallbacks {
23
+ interface ScenvCallbacks {
24
24
  /** When user was just prompted for a value and savePrompt is ask/always: (variableName, value, contextNames) => context name to save to, or null to skip */
25
25
  onAskSaveAfterPrompt?: (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
26
26
  /** When saveContextTo is "ask": (variableName, contextNames) => context name to save to */
27
27
  onAskContext?: (name: string, contextNames: string[]) => Promise<string>;
28
28
  }
29
- declare function getCallbacks(): SenvCallbacks;
29
+ declare function getCallbacks(): ScenvCallbacks;
30
30
  /**
31
31
  * Load full config: file (from root or cwd) <- env <- programmatic. Precedence: programmatic > env > file.
32
32
  */
33
- declare function loadConfig(root?: string): SenvConfig;
33
+ declare function loadConfig(root?: string): ScenvConfig;
34
34
  /**
35
35
  * Set programmatic config (e.g. from CLI flags). Merged on top of env and file in loadConfig().
36
36
  */
37
- declare function configure(partial: Partial<SenvConfig> & {
38
- callbacks?: SenvCallbacks;
37
+ declare function configure(partial: Partial<ScenvConfig> & {
38
+ callbacks?: ScenvCallbacks;
39
39
  }): void;
40
40
  /**
41
41
  * Reset programmatic config (mainly for tests).
@@ -59,14 +59,14 @@ type ValidatorResult<T> = boolean | {
59
59
  error?: unknown;
60
60
  };
61
61
  type PromptFn<T> = (name: string, defaultValue: T) => T | Promise<T>;
62
- interface SenvVariableOptions<T> {
62
+ interface ScenvVariableOptions<T> {
63
63
  key?: string;
64
64
  env?: string;
65
65
  default?: T;
66
66
  validator?: (val: T) => ValidatorResult<T>;
67
67
  prompt?: PromptFn<T>;
68
68
  }
69
- interface SenvVariable<T> {
69
+ interface ScenvVariable<T> {
70
70
  get(): Promise<T>;
71
71
  safeGet(): Promise<{
72
72
  success: true;
@@ -77,13 +77,13 @@ interface SenvVariable<T> {
77
77
  }>;
78
78
  save(value?: T): Promise<void>;
79
79
  }
80
- declare function senv<T>(name: string, options?: SenvVariableOptions<T>): SenvVariable<T>;
80
+ declare function scenv<T>(name: string, options?: ScenvVariableOptions<T>): ScenvVariable<T>;
81
81
 
82
82
  /**
83
- * Parse argv (e.g. process.argv.slice(2)) into SenvConfig for configure().
83
+ * Parse argv (e.g. process.argv.slice(2)) into ScenvConfig for configure().
84
84
  * Supports: --context a,b,c --add-context x,y --prompt fallback --ignore-env --ignore-context
85
85
  * --set key=value --save-prompt ask --save-context-to prod
86
86
  */
87
- declare function parseSenvArgs(argv: string[]): Partial<SenvConfig>;
87
+ declare function parseScenvArgs(argv: string[]): Partial<ScenvConfig>;
88
88
 
89
- export { type PromptMode, type SavePromptMode, type SenvCallbacks, type SenvConfig, type SenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseSenvArgs, resetConfig, senv };
89
+ export { type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  // src/config.ts
2
2
  import { readFileSync, existsSync } from "fs";
3
3
  import { dirname, join } from "path";
4
- var CONFIG_FILENAME = "senv.config.json";
4
+ var CONFIG_FILENAME = "scenv.config.json";
5
5
  var envKeyMap = {
6
- SENV_CONTEXT: "contexts",
7
- SENV_ADD_CONTEXTS: "addContexts",
8
- SENV_PROMPT: "prompt",
9
- SENV_IGNORE_ENV: "ignoreEnv",
10
- SENV_IGNORE_CONTEXT: "ignoreContext",
11
- SENV_SAVE_PROMPT: "savePrompt",
12
- SENV_SAVE_CONTEXT_TO: "saveContextTo"
6
+ SCENV_CONTEXT: "contexts",
7
+ SCENV_ADD_CONTEXTS: "addContexts",
8
+ SCENV_PROMPT: "prompt",
9
+ SCENV_IGNORE_ENV: "ignoreEnv",
10
+ SCENV_IGNORE_CONTEXT: "ignoreContext",
11
+ SCENV_SAVE_PROMPT: "savePrompt",
12
+ SCENV_SAVE_CONTEXT_TO: "saveContextTo"
13
13
  };
14
14
  var programmaticConfig = {};
15
15
  var programmaticCallbacks = {};
@@ -242,7 +242,7 @@ function normalizeValidatorResult(result) {
242
242
  if (result.success === true) return result;
243
243
  return result;
244
244
  }
245
- function senv(name, options = {}) {
245
+ function scenv(name, options = {}) {
246
246
  const key = options.key ?? defaultKeyFromName(name);
247
247
  const envKey = options.env ?? defaultEnvFromKey(key);
248
248
  const validator = options.validator;
@@ -364,7 +364,7 @@ function senv(name, options = {}) {
364
364
  }
365
365
 
366
366
  // src/cli-args.ts
367
- function parseSenvArgs(argv) {
367
+ function parseScenvArgs(argv) {
368
368
  const config = {};
369
369
  let i = 0;
370
370
  while (i < argv.length) {
@@ -414,7 +414,7 @@ export {
414
414
  getCallbacks,
415
415
  getContextValues,
416
416
  loadConfig,
417
- parseSenvArgs,
417
+ parseScenvArgs,
418
418
  resetConfig,
419
- senv
419
+ scenv
420
420
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scenv",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Environment and context variables with runtime-configurable resolution",
5
5
  "repository": {
6
6
  "type": "git",