@calvear/env 3.0.1 โ 3.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 +14 -0
- package/README.md +603 -515
- package/arguments.js +1 -1
- package/arguments.js.map +1 -1
- package/assets/logo.svg +30 -30
- package/commands/export.command.js +1 -1
- package/commands/export.command.js.map +1 -1
- package/commands/pull.command.js.map +1 -1
- package/commands/push.command.js.map +1 -1
- package/commands/schema.command.js.map +1 -1
- package/main.js.map +1 -1
- package/package.json +2 -1
- package/providers/index.js.map +1 -1
- package/providers/secrets.provider.js.map +1 -1
- package/schemas/settings.schema.json +2 -2
- package/utils/argv.util.js.map +1 -1
- package/utils/logger.d.ts.map +1 -1
- package/utils/logger.js +14 -9
- package/utils/logger.js.map +1 -1
- package/utils/normalize.util.d.ts +4 -0
- package/utils/normalize.util.d.ts.map +1 -1
- package/utils/normalize.util.js +1 -1
- package/utils/normalize.util.js.map +1 -1
- package/utils/schema.util.d.ts.map +1 -1
- package/utils/schema.util.js +2 -2
- package/utils/schema.util.js.map +1 -1
- package/utils/ui.d.ts.map +1 -1
- package/utils/ui.js +54 -31
- package/utils/ui.js.map +1 -1
package/arguments.js
CHANGED
package/arguments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.js","names":[],"sources":["../src/arguments.ts"],"sourcesContent":["import type { JSONSchemaType } from 'ajv';\r\nimport ci from 'ci-info';\r\nimport type { Arguments, Options } from 'yargs';\r\nimport type { EnvProviderConfig } from './interfaces/index.js';\r\nimport { IntegratedProviderConfig } from './providers/index.js';\r\n\r\nconst GROUPS = {\r\n\tCORE: 'Core Options',\r\n\tGROUP_WORKSPACE: 'Workspace Options',\r\n\tJSON_SCHEMA_WORKSPACE: 'JSON Schema Options',\r\n\tLOG_WORKSPACE: 'Logger Options',\r\n};\r\n\r\nexport interface CommandArguments extends Arguments {\r\n\tarrayDescomposition: boolean;\r\n\tci: boolean;\r\n\tconfigFile: string;\r\n\tdetectFormat: boolean;\r\n\tenv: string;\r\n\texpand: boolean;\r\n\tnestingDelimiter: string;\r\n\tnullable: boolean;\r\n\tpackageJson: string;\r\n\tprojectInfo: Record<string, string>;\r\n\tproviders: EnvProviderConfig[];\r\n\tresolve: 'merge' | 'override';\r\n\troot: string;\r\n\tschemaFile: string;\r\n\texportIgnoreKeys?: string[];\r\n\tlogLevel?: 'debug' | 'error' | 'info' | 'silly' | 'trace' | 'warn';\r\n\tlogMaskAnyRegEx?: string[];\r\n\tlogMaskValuesOfKeys?: string[];\r\n\tmodes?: string[];\r\n\tschema?: Record<string, JSONSchemaType<object>>;\r\n}\r\n\r\n// common CLI arguments\r\nexport const args: Record<keyof CommandArguments, Options> = {\r\n\tarrayDescomposition: {\r\n\t\talias: 'arrDesc',\r\n\t\tdefault: false,\r\n\t\tdescribe: 'Whether serialize or break down arrays',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\tci: {\r\n\t\tdefault: ci.isCI,\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'boolean',\r\n\t\tdescribe:\r\n\t\t\t'Run providers in continuous-integration mode (skips local files)',\r\n\t},\r\n\tconfigFile: {\r\n\t\talias: 'c',\r\n\t\tdefault: '[[root]]/settings/settings.json',\r\n\t\tdescribe: 'Config JSON file path',\r\n\t\tgroup: GROUPS.GROUP_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\tdetectFormat: {\r\n\t\talias: 'df',\r\n\t\tdefault: false,\r\n\t\tdescribe: 'Whether format of strings variables are included in schema',\r\n\t\tgroup: GROUPS.JSON_SCHEMA_WORKSPACE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\tenv: {\r\n\t\talias: 'e',\r\n\t\tdescribe: 'Environment to load, i.e. dev, prod',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'string',\r\n\t},\r\n\texpand: {\r\n\t\talias: 'x',\r\n\t\tdefault: false,\r\n\t\tdescribe: 'Interpolate environment variables using themselves',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\texportIgnoreKeys: {\r\n\t\talias: 'iek',\r\n\t\tdefault: [],\r\n\t\tgroup: GROUPS.JSON_SCHEMA_WORKSPACE,\r\n\t\thidden: true,\r\n\t\ttype: 'array',\r\n\t},\r\n\tlogLevel: {\r\n\t\talias: 'log',\r\n\t\tchoices: ['silly', 'trace', 'debug', 'info', 'warn', 'error'],\r\n\t\tdefault: 'info',\r\n\t\tdescribe: 'Log verbosity level',\r\n\t\tgroup: GROUPS.LOG_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\tlogMaskAnyRegEx: {\r\n\t\talias: 'mrx',\r\n\t\tdefault: [],\r\n\t\tdescribe: 'Mask log values matching these regular expressions',\r\n\t\tgroup: GROUPS.LOG_WORKSPACE,\r\n\t\ttype: 'array',\r\n\t},\r\n\tlogMaskValuesOfKeys: {\r\n\t\talias: 'mvk',\r\n\t\tdefault: [],\r\n\t\tdescribe: 'Mask
|
|
1
|
+
{"version":3,"file":"arguments.js","names":[],"sources":["../src/arguments.ts"],"sourcesContent":["import type { JSONSchemaType } from 'ajv';\r\nimport ci from 'ci-info';\r\nimport type { Arguments, Options } from 'yargs';\r\nimport type { EnvProviderConfig } from './interfaces/index.js';\r\nimport { IntegratedProviderConfig } from './providers/index.js';\r\n\r\nconst GROUPS = {\r\n\tCORE: 'Core Options',\r\n\tGROUP_WORKSPACE: 'Workspace Options',\r\n\tJSON_SCHEMA_WORKSPACE: 'JSON Schema Options',\r\n\tLOG_WORKSPACE: 'Logger Options',\r\n};\r\n\r\nexport interface CommandArguments extends Arguments {\r\n\tarrayDescomposition: boolean;\r\n\tci: boolean;\r\n\tconfigFile: string;\r\n\tdetectFormat: boolean;\r\n\tenv: string;\r\n\texpand: boolean;\r\n\tnestingDelimiter: string;\r\n\tnullable: boolean;\r\n\tpackageJson: string;\r\n\tprojectInfo: Record<string, string>;\r\n\tproviders: EnvProviderConfig[];\r\n\tresolve: 'merge' | 'override';\r\n\troot: string;\r\n\tschemaFile: string;\r\n\texportIgnoreKeys?: string[];\r\n\tlogLevel?: 'debug' | 'error' | 'info' | 'silly' | 'trace' | 'warn';\r\n\tlogMaskAnyRegEx?: string[];\r\n\tlogMaskValuesOfKeys?: string[];\r\n\tmodes?: string[];\r\n\tschema?: Record<string, JSONSchemaType<object>>;\r\n}\r\n\r\n// common CLI arguments\r\nexport const args: Record<keyof CommandArguments, Options> = {\r\n\tarrayDescomposition: {\r\n\t\talias: 'arrDesc',\r\n\t\tdefault: false,\r\n\t\tdescribe: 'Whether serialize or break down arrays',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\tci: {\r\n\t\tdefault: ci.isCI,\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'boolean',\r\n\t\tdescribe:\r\n\t\t\t'Run providers in continuous-integration mode (skips local files)',\r\n\t},\r\n\tconfigFile: {\r\n\t\talias: 'c',\r\n\t\tdefault: '[[root]]/settings/settings.json',\r\n\t\tdescribe: 'Config JSON file path',\r\n\t\tgroup: GROUPS.GROUP_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\tdetectFormat: {\r\n\t\talias: 'df',\r\n\t\tdefault: false,\r\n\t\tdescribe: 'Whether format of strings variables are included in schema',\r\n\t\tgroup: GROUPS.JSON_SCHEMA_WORKSPACE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\tenv: {\r\n\t\talias: 'e',\r\n\t\tdescribe: 'Environment to load, i.e. dev, prod',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'string',\r\n\t},\r\n\texpand: {\r\n\t\talias: 'x',\r\n\t\tdefault: false,\r\n\t\tdescribe: 'Interpolate environment variables using themselves',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\texportIgnoreKeys: {\r\n\t\talias: 'iek',\r\n\t\tdefault: [],\r\n\t\tgroup: GROUPS.JSON_SCHEMA_WORKSPACE,\r\n\t\thidden: true,\r\n\t\ttype: 'array',\r\n\t},\r\n\tlogLevel: {\r\n\t\talias: 'log',\r\n\t\tchoices: ['silly', 'trace', 'debug', 'info', 'warn', 'error'],\r\n\t\tdefault: 'info',\r\n\t\tdescribe: 'Log verbosity level',\r\n\t\tgroup: GROUPS.LOG_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\tlogMaskAnyRegEx: {\r\n\t\talias: 'mrx',\r\n\t\tdefault: [],\r\n\t\tdescribe: 'Mask log values matching these regular expressions',\r\n\t\tgroup: GROUPS.LOG_WORKSPACE,\r\n\t\ttype: 'array',\r\n\t},\r\n\tlogMaskValuesOfKeys: {\r\n\t\talias: 'mvk',\r\n\t\tdefault: [],\r\n\t\tdescribe: 'Mask a value when its key matches (exact or /regex/)',\r\n\t\tgroup: GROUPS.LOG_WORKSPACE,\r\n\t\ttype: 'array',\r\n\t},\r\n\tmodes: {\r\n\t\talias: 'm',\r\n\t\tdescribe: 'Execution modes, i.e. debug, test',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'array',\r\n\t},\r\n\tnestingDelimiter: {\r\n\t\talias: 'nd',\r\n\t\tdefault: '__',\r\n\t\tgroup: GROUPS.CORE,\r\n\t\ttype: 'string',\r\n\t\tdescribe:\r\n\t\t\t'Nesting level delimiter for flatten, i.e. { l1: { l2: \"value\" } } turns into { l1__l2: \"value\" }',\r\n\t},\r\n\tnullable: {\r\n\t\talias: 'null',\r\n\t\tdefault: true,\r\n\t\tdescribe: 'Whether variables are nullable',\r\n\t\tgroup: GROUPS.JSON_SCHEMA_WORKSPACE,\r\n\t\ttype: 'boolean',\r\n\t},\r\n\tpackageJson: {\r\n\t\talias: ['pkg'],\r\n\t\tdefault: '',\r\n\t\tdescribe: 'package.json path',\r\n\t\tgroup: GROUPS.GROUP_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\tproviders: {\r\n\t\tdefault: IntegratedProviderConfig,\r\n\t\tdescribe: 'Providers handling variables loading',\r\n\t\thidden: true,\r\n\t\ttype: 'array',\r\n\t},\r\n\tresolve: {\r\n\t\talias: 'r',\r\n\t\tchoices: ['merge', 'override'],\r\n\t\tdefault: 'merge',\r\n\t\tdescribe: 'Whether merges new schema or override',\r\n\t\tgroup: GROUPS.JSON_SCHEMA_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\troot: {\r\n\t\tdefault: 'env',\r\n\t\tdescribe: 'Default environment folder path',\r\n\t\tgroup: GROUPS.GROUP_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n\tschemaFile: {\r\n\t\talias: ['s', 'schema'],\r\n\t\tdefault: '[[root]]/settings/schema.json',\r\n\t\tdescribe: 'Environment Schema JSON file path',\r\n\t\tgroup: GROUPS.GROUP_WORKSPACE,\r\n\t\ttype: 'string',\r\n\t},\r\n};\r\n"],"mappings":";;;AAMA,IAAM,IAAS;CACd,MAAM;CACN,iBAAiB;CACjB,uBAAuB;CACvB,eAAe;AAChB,GA0Ba,IAAgD;CAC5D,qBAAqB;EACpB,OAAO;EACP,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,IAAI;EACH,SAAS,EAAG;EACZ,OAAO,EAAO;EACd,MAAM;EACN,UACC;CACF;CACA,YAAY;EACX,OAAO;EACP,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,cAAc;EACb,OAAO;EACP,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,KAAK;EACJ,OAAO;EACP,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,QAAQ;EACP,OAAO;EACP,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,kBAAkB;EACjB,OAAO;EACP,SAAS,CAAC;EACV,OAAO,EAAO;EACd,QAAQ;EACR,MAAM;CACP;CACA,UAAU;EACT,OAAO;EACP,SAAS;GAAC;GAAS;GAAS;GAAS;GAAQ;GAAQ;EAAO;EAC5D,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,iBAAiB;EAChB,OAAO;EACP,SAAS,CAAC;EACV,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,qBAAqB;EACpB,OAAO;EACP,SAAS,CAAC;EACV,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,OAAO;EACN,OAAO;EACP,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,kBAAkB;EACjB,OAAO;EACP,SAAS;EACT,OAAO,EAAO;EACd,MAAM;EACN,UACC;CACF;CACA,UAAU;EACT,OAAO;EACP,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,aAAa;EACZ,OAAO,CAAC,KAAK;EACb,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,WAAW;EACV,SAAS;EACT,UAAU;EACV,QAAQ;EACR,MAAM;CACP;CACA,SAAS;EACR,OAAO;EACP,SAAS,CAAC,SAAS,UAAU;EAC7B,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,MAAM;EACL,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;CACA,YAAY;EACX,OAAO,CAAC,KAAK,QAAQ;EACrB,SAAS;EACT,UAAU;EACV,OAAO,EAAO;EACd,MAAM;CACP;AACD"}
|
package/assets/logo.svg
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
<svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="env">
|
|
2
|
-
<defs>
|
|
3
|
-
<linearGradient id="card" x1="32" y1="24" x2="224" y2="232" gradientUnits="userSpaceOnUse">
|
|
4
|
-
<stop stop-color="#101A2E"/>
|
|
5
|
-
<stop offset="1" stop-color="#0A1120"/>
|
|
6
|
-
</linearGradient>
|
|
7
|
-
<linearGradient id="accent" x1="72" y1="104" x2="184" y2="168" gradientUnits="userSpaceOnUse">
|
|
8
|
-
<stop stop-color="#34D399"/>
|
|
9
|
-
<stop offset="1" stop-color="#22D3EE"/>
|
|
10
|
-
</linearGradient>
|
|
11
|
-
</defs>
|
|
12
|
-
|
|
13
|
-
<!-- terminal card -->
|
|
14
|
-
<rect x="20" y="20" width="216" height="216" rx="46" fill="url(#card)"/>
|
|
15
|
-
<rect x="21" y="21" width="214" height="214" rx="45" fill="none" stroke="#22D3EE" stroke-opacity="0.18" stroke-width="2"/>
|
|
16
|
-
|
|
17
|
-
<!-- title bar dots -->
|
|
18
|
-
<circle cx="58" cy="62" r="7" fill="#F87171"/>
|
|
19
|
-
<circle cx="82" cy="62" r="7" fill="#FBBF24"/>
|
|
20
|
-
<circle cx="106" cy="62" r="7" fill="#34D399"/>
|
|
21
|
-
|
|
22
|
-
<!-- separator -->
|
|
23
|
-
<line x1="40" y1="86" x2="216" y2="86" stroke="#22D3EE" stroke-opacity="0.12" stroke-width="2"/>
|
|
24
|
-
|
|
25
|
-
<!-- [ > _ ] : env brackets + CLI prompt -->
|
|
26
|
-
<path d="M104 108 H82 V184 H104" stroke="url(#accent)" stroke-width="14" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
27
|
-
<path d="M152 108 H174 V184 H152" stroke="url(#accent)" stroke-width="14" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
28
|
-
<path d="M110 128 L132 146 L110 164" stroke="#E2F7F2" stroke-width="13" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
29
|
-
<rect x="128" y="158" width="22" height="11" rx="3" fill="#34D399"/>
|
|
30
|
-
</svg>
|
|
1
|
+
<svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="env">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="card" x1="32" y1="24" x2="224" y2="232" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#101A2E"/>
|
|
5
|
+
<stop offset="1" stop-color="#0A1120"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="accent" x1="72" y1="104" x2="184" y2="168" gradientUnits="userSpaceOnUse">
|
|
8
|
+
<stop stop-color="#34D399"/>
|
|
9
|
+
<stop offset="1" stop-color="#22D3EE"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
|
|
13
|
+
<!-- terminal card -->
|
|
14
|
+
<rect x="20" y="20" width="216" height="216" rx="46" fill="url(#card)"/>
|
|
15
|
+
<rect x="21" y="21" width="214" height="214" rx="45" fill="none" stroke="#22D3EE" stroke-opacity="0.18" stroke-width="2"/>
|
|
16
|
+
|
|
17
|
+
<!-- title bar dots -->
|
|
18
|
+
<circle cx="58" cy="62" r="7" fill="#F87171"/>
|
|
19
|
+
<circle cx="82" cy="62" r="7" fill="#FBBF24"/>
|
|
20
|
+
<circle cx="106" cy="62" r="7" fill="#34D399"/>
|
|
21
|
+
|
|
22
|
+
<!-- separator -->
|
|
23
|
+
<line x1="40" y1="86" x2="216" y2="86" stroke="#22D3EE" stroke-opacity="0.12" stroke-width="2"/>
|
|
24
|
+
|
|
25
|
+
<!-- [ > _ ] : env brackets + CLI prompt -->
|
|
26
|
+
<path d="M104 108 H82 V184 H104" stroke="url(#accent)" stroke-width="14" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
27
|
+
<path d="M152 108 H174 V184 H152" stroke="url(#accent)" stroke-width="14" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
28
|
+
<path d="M110 128 L132 146 L110 164" stroke="#E2F7F2" stroke-width="13" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
29
|
+
<rect x="128" y="158" width="22" height="11" rx="3" fill="#34D399"/>
|
|
30
|
+
</svg>
|
|
@@ -37,7 +37,7 @@ var l = {
|
|
|
37
37
|
}).example("env export -e dev -m build", "Exports \"dev\" variables to a dotenv file at root as \".env\"").example("env export -e prod -m build -f json --uri [[env]].env.json", "Exports \"prod\" variables to a json file at root as \"prod.env.json\""), e),
|
|
38
38
|
handler: async ({ expand: l, exportIgnoreKeys: u, exportQuotes: d, providers: f, ...p }) => {
|
|
39
39
|
let m = c({ NODE_ENV: "development" }, ...await e(await t(f, p), p));
|
|
40
|
-
m = o(m, p.nestingDelimiter, p.arrayDescomposition), l && (m = n(m, m)), u && (a.silly("ignoring:", u), m = Object.fromEntries(Object.entries(m).filter(([e]) => !u.includes(e)))),
|
|
40
|
+
m = o(m, p.nestingDelimiter, p.arrayDescomposition), l && (m = n(m, m)), u && (a.silly("ignoring:", u), m = Object.fromEntries(Object.entries(m).filter(([e]) => !u.includes(e)))), s.variables(m);
|
|
41
41
|
let { format: h, uri: g } = p;
|
|
42
42
|
switch (h) {
|
|
43
43
|
case "dotenv":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.command.js","names":[],"sources":["../../src/commands/export.command.ts"],"sourcesContent":["import merge from 'merge-deep';\r\nimport type { CommandModule } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport {\r\n\tflatAndValidateResults,\r\n\tinterpolate,\r\n\tloadVariablesFromProviders,\r\n\tlogger,\r\n\tnormalize,\r\n\tui,\r\n\twriteEnvFromJson,\r\n\twriteJson,\r\n} from '../utils/index.js';\r\n\r\nexport interface ExportCommandArguments extends CommandArguments {\r\n\tformat: 'dotenv' | 'json';\r\n\r\n\turi: string;\r\n\r\n\texportQuotes: boolean;\r\n}\r\n\r\n/**\r\n * Export command.\r\n * Export environment variables to a file.\r\n *\r\n * @example [>_]: env export -e dev -m build\r\n */\r\nexport const exportCommand: CommandModule<any, ExportCommandArguments> = {\r\n\tcommand: 'export [options..]',\r\n\tdescribe: 'Export unified environment variables to a file from providers',\r\n\tbuilder: (builder) => {\r\n\t\tbuilder\r\n\t\t\t.options({\r\n\t\t\t\texportQuotes: {\r\n\t\t\t\t\talias: ['quotes', 'q'],\r\n\t\t\t\t\tdefault: false,\r\n\t\t\t\t\tdescribe: 'Wraps values in quotes',\r\n\t\t\t\t\ttype: 'boolean',\r\n\t\t\t\t},\r\n\t\t\t\tformat: {\r\n\t\t\t\t\talias: 'f',\r\n\t\t\t\t\tchoices: ['json', 'dotenv'],\r\n\t\t\t\t\tdefault: 'dotenv',\r\n\t\t\t\t\tdescribe: 'Format for export variables',\r\n\t\t\t\t\ttype: 'string',\r\n\t\t\t\t},\r\n\t\t\t\turi: {\r\n\t\t\t\t\talias: ['u', 'p', 'path'],\r\n\t\t\t\t\tdefault: '.env',\r\n\t\t\t\t\tdescribe: 'Uri for export file with variables',\r\n\t\t\t\t\ttype: 'string',\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t\t.example(\r\n\t\t\t\t'env export -e dev -m build',\r\n\t\t\t\t'Exports \"dev\" variables to a dotenv file at root as \".env\"',\r\n\t\t\t)\r\n\t\t\t.example(\r\n\t\t\t\t'env export -e prod -m build -f json --uri [[env]].env.json',\r\n\t\t\t\t'Exports \"prod\" variables to a json file at root as \"prod.env.json\"',\r\n\t\t\t);\r\n\r\n\t\treturn builder;\r\n\t},\r\n\thandler: async ({\r\n\t\texpand,\r\n\t\texportIgnoreKeys,\r\n\t\texportQuotes,\r\n\t\tproviders,\r\n\t\t...argv\r\n\t}) => {\r\n\t\tconst results = await loadVariablesFromProviders(providers, argv);\r\n\r\n\t\tlet env = merge(\r\n\t\t\t{ NODE_ENV: 'development' },\r\n\t\t\t...(await flatAndValidateResults(results, argv)),\r\n\t\t);\r\n\r\n\t\tenv = normalize(env, argv.nestingDelimiter, argv.arrayDescomposition);\r\n\t\tif (expand) env = interpolate(env, env);\r\n\t\tif (exportIgnoreKeys) {\r\n\t\t\tlogger.silly('ignoring:', exportIgnoreKeys);\r\n\t\t\tenv = Object.fromEntries(\r\n\t\t\t\tObject.entries(env).filter(\r\n\t\t\t\t\t([k]) => !exportIgnoreKeys.includes(k),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\
|
|
1
|
+
{"version":3,"file":"export.command.js","names":[],"sources":["../../src/commands/export.command.ts"],"sourcesContent":["import merge from 'merge-deep';\r\nimport type { CommandModule } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport {\r\n\tflatAndValidateResults,\r\n\tinterpolate,\r\n\tloadVariablesFromProviders,\r\n\tlogger,\r\n\tnormalize,\r\n\tui,\r\n\twriteEnvFromJson,\r\n\twriteJson,\r\n} from '../utils/index.js';\r\n\r\nexport interface ExportCommandArguments extends CommandArguments {\r\n\tformat: 'dotenv' | 'json';\r\n\r\n\turi: string;\r\n\r\n\texportQuotes: boolean;\r\n}\r\n\r\n/**\r\n * Export command.\r\n * Export environment variables to a file.\r\n *\r\n * @example [>_]: env export -e dev -m build\r\n */\r\nexport const exportCommand: CommandModule<any, ExportCommandArguments> = {\r\n\tcommand: 'export [options..]',\r\n\tdescribe: 'Export unified environment variables to a file from providers',\r\n\tbuilder: (builder) => {\r\n\t\tbuilder\r\n\t\t\t.options({\r\n\t\t\t\texportQuotes: {\r\n\t\t\t\t\talias: ['quotes', 'q'],\r\n\t\t\t\t\tdefault: false,\r\n\t\t\t\t\tdescribe: 'Wraps values in quotes',\r\n\t\t\t\t\ttype: 'boolean',\r\n\t\t\t\t},\r\n\t\t\t\tformat: {\r\n\t\t\t\t\talias: 'f',\r\n\t\t\t\t\tchoices: ['json', 'dotenv'],\r\n\t\t\t\t\tdefault: 'dotenv',\r\n\t\t\t\t\tdescribe: 'Format for export variables',\r\n\t\t\t\t\ttype: 'string',\r\n\t\t\t\t},\r\n\t\t\t\turi: {\r\n\t\t\t\t\talias: ['u', 'p', 'path'],\r\n\t\t\t\t\tdefault: '.env',\r\n\t\t\t\t\tdescribe: 'Uri for export file with variables',\r\n\t\t\t\t\ttype: 'string',\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t\t.example(\r\n\t\t\t\t'env export -e dev -m build',\r\n\t\t\t\t'Exports \"dev\" variables to a dotenv file at root as \".env\"',\r\n\t\t\t)\r\n\t\t\t.example(\r\n\t\t\t\t'env export -e prod -m build -f json --uri [[env]].env.json',\r\n\t\t\t\t'Exports \"prod\" variables to a json file at root as \"prod.env.json\"',\r\n\t\t\t);\r\n\r\n\t\treturn builder;\r\n\t},\r\n\thandler: async ({\r\n\t\texpand,\r\n\t\texportIgnoreKeys,\r\n\t\texportQuotes,\r\n\t\tproviders,\r\n\t\t...argv\r\n\t}) => {\r\n\t\tconst results = await loadVariablesFromProviders(providers, argv);\r\n\r\n\t\tlet env = merge(\r\n\t\t\t{ NODE_ENV: 'development' },\r\n\t\t\t...(await flatAndValidateResults(results, argv)),\r\n\t\t);\r\n\r\n\t\tenv = normalize(env, argv.nestingDelimiter, argv.arrayDescomposition);\r\n\t\tif (expand) env = interpolate(env, env);\r\n\t\tif (exportIgnoreKeys) {\r\n\t\t\tlogger.silly('ignoring:', exportIgnoreKeys);\r\n\t\t\tenv = Object.fromEntries(\r\n\t\t\t\tObject.entries(env).filter(\r\n\t\t\t\t\t([k]) => !exportIgnoreKeys.includes(k),\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tui.variables(env);\r\n\r\n\t\tconst { format, uri } = argv;\r\n\r\n\t\tswitch (format) {\r\n\t\t\tcase 'dotenv': {\r\n\t\t\t\tawait writeEnvFromJson(uri, env, true, exportQuotes);\r\n\t\t\t\tui.action(\r\n\t\t\t\t\t'๐ค',\r\n\t\t\t\t\t`exported ${Object.keys(env).length} variables โ ${uri} (${format})`,\r\n\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tcase 'json': {\r\n\t\t\t\tawait writeJson(uri, env, true);\r\n\t\t\t\tui.action(\r\n\t\t\t\t\t'๐ค',\r\n\t\t\t\t\t`exported ${Object.keys(env).length} variables โ ${uri} (${format})`,\r\n\t\t\t\t);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tdefault: {\r\n\t\t\t\tlogger.error(`format ${format} not recognized`);\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n};\r\n"],"mappings":";;;;;;;;;AA4BA,IAAa,IAA4D;CACxE,SAAS;CACT,UAAU;CACV,UAAU,OACT,EACE,QAAQ;EACR,cAAc;GACb,OAAO,CAAC,UAAU,GAAG;GACrB,SAAS;GACT,UAAU;GACV,MAAM;EACP;EACA,QAAQ;GACP,OAAO;GACP,SAAS,CAAC,QAAQ,QAAQ;GAC1B,SAAS;GACT,UAAU;GACV,MAAM;EACP;EACA,KAAK;GACJ,OAAO;IAAC;IAAK;IAAK;GAAM;GACxB,SAAS;GACT,UAAU;GACV,MAAM;EACP;CACD,CAAC,EACA,QACA,8BACA,gEACD,EACC,QACA,8DACA,wEACD,GAEM;CAER,SAAS,OAAO,EACf,WACA,qBACA,iBACA,cACA,GAAG,QACE;EAGL,IAAI,IAAM,EACT,EAAE,UAAU,cAAc,GAC1B,GAAI,MAAM,EAAuB,MAJZ,EAA2B,GAAW,CAAI,GAIrB,CAAI,CAC/C;EAaA,AAXA,IAAM,EAAU,GAAK,EAAK,kBAAkB,EAAK,mBAAmB,GAChE,MAAQ,IAAM,EAAY,GAAK,CAAG,IAClC,MACH,EAAO,MAAM,aAAa,CAAgB,GAC1C,IAAM,OAAO,YACZ,OAAO,QAAQ,CAAG,EAAE,QAClB,CAAC,OAAO,CAAC,EAAiB,SAAS,CAAC,CACtC,CACD,IAGD,EAAG,UAAU,CAAG;EAEhB,IAAM,EAAE,WAAQ,WAAQ;EAExB,QAAQ,GAAR;GACC,KAAK;IAEJ,AADA,MAAM,EAAiB,GAAK,GAAK,IAAM,CAAY,GACnD,EAAG,OACF,MACA,YAAY,OAAO,KAAK,CAAG,EAAE,OAAO,eAAe,EAAI,IAAI,EAAO,EACnE;IACA;GAGD,KAAK;IAEJ,AADA,MAAM,EAAU,GAAK,GAAK,EAAI,GAC9B,EAAG,OACF,MACA,YAAY,OAAO,KAAK,CAAG,EAAE,OAAO,eAAe,EAAI,IAAI,EAAO,EACnE;IACA;GAGD,SACC,EAAO,MAAM,UAAU,EAAO,gBAAgB;EAEhD;CACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull.command.js","names":[],"sources":["../../src/commands/pull.command.ts"],"sourcesContent":["import pc from 'picocolors';\nimport type { CommandModule } from 'yargs';\nimport type { CommandArguments } from '../arguments.js';\nimport { logger, ui } from '../utils/index.js';\n\nexport interface PullCommandArguments extends CommandArguments {\n\t// whether variables should be overwritten in already exists\n\toverwrite: boolean;\n}\n\n/**\n * Pulls environment variables from providers.\n *\n * @example [>_]: env pull -e dev\n */\nexport const pullCommand: CommandModule<any, PullCommandArguments> = {\n\tcommand: 'pull [options..]',\n\tdescribe: 'Pull environment variables from provider stores',\n\tbuilder: (builder) => {\n\t\tbuilder\n\t\t\t.options({\n\t\t\t\toverwrite: {\n\t\t\t\t\talias: 'o',\n\t\t\t\t\tdefault: false,\n\t\t\t\t\tdescribe: 'Overwrite local variables',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t},\n\t\t\t})\n\t\t\t.example('env pull -e dev', 'Download \"dev\" environment secrets')\n\t\t\t.example(\n\t\t\t\t'env pull -e dev -o',\n\t\t\t\t'Download and overwrite (if any exists) \"dev\" environment secrets',\n\t\t\t);\n\n\t\treturn builder;\n\t},\n\thandler: async ({ providers, ...argv }) => {\n\t\tconst pullProviders = providers.filter(\n\t\t\t({ handler: { pull } }) => !!pull,\n\t\t);\n\t\tconst promises = await Promise.all(\n\t\t\tpullProviders.map(({ config, handler: { key, pull } }) => {\n\t\t\t\tlogger.silly(`pulling from ${pc.yellow(key)} provider`);\n\n\t\t\t\treturn pull!(argv, config);\n\t\t\t}),\n\t\t);\n\n\t\tif (promises.length > 0)\n\t\t\tui.action('โฌ๏ธ', `pulled from ${promises.length} provider(s)`);\n\t\telse logger.warn('no providers for pull variables');\n\t},\n};\n"],"mappings":";;;;;AAeA,IAAa,IAAwD;CACpE,SAAS;CACT,UAAU;CACV,UAAU,OACT,EACE,QAAQ,EACR,WAAW;EACV,OAAO;EACP,SAAS;EACT,UAAU;EACV,MAAM;CACP,EACD,CAAC,EACA,QAAQ,mBAAmB,sCAAoC,EAC/D,QACA,sBACA,oEACD,GAEM;CAER,SAAS,OAAO,EAAE,cAAW,GAAG,QAAW;EAC1C,IAAM,IAAgB,EAAU,QAC9B,EAAE,SAAS,EAAE,gBAAa,CAAC,CAAC,CAC9B,GACM,IAAW,MAAM,QAAQ,IAC9B,EAAc,KAAK,EAAE,WAAQ,SAAS,EAAE,QAAK,iBAC5C,EAAO,MAAM,gBAAgB,EAAG,OAAO,CAAG,EAAE,UAAU,GAE/C,EAAM,GAAM,CAAM,EACzB,CACF;EAEA,AAAI,EAAS,SAAS,IACrB,EAAG,OAAO,MAAM,eAAe,EAAS,OAAO,aAAa,IACxD,EAAO,KAAK,iCAAiC;CACnD;AACD"}
|
|
1
|
+
{"version":3,"file":"pull.command.js","names":[],"sources":["../../src/commands/pull.command.ts"],"sourcesContent":["import pc from 'picocolors';\r\nimport type { CommandModule } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport { logger, ui } from '../utils/index.js';\r\n\r\nexport interface PullCommandArguments extends CommandArguments {\r\n\t// whether variables should be overwritten in already exists\r\n\toverwrite: boolean;\r\n}\r\n\r\n/**\r\n * Pulls environment variables from providers.\r\n *\r\n * @example [>_]: env pull -e dev\r\n */\r\nexport const pullCommand: CommandModule<any, PullCommandArguments> = {\r\n\tcommand: 'pull [options..]',\r\n\tdescribe: 'Pull environment variables from provider stores',\r\n\tbuilder: (builder) => {\r\n\t\tbuilder\r\n\t\t\t.options({\r\n\t\t\t\toverwrite: {\r\n\t\t\t\t\talias: 'o',\r\n\t\t\t\t\tdefault: false,\r\n\t\t\t\t\tdescribe: 'Overwrite local variables',\r\n\t\t\t\t\ttype: 'boolean',\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t\t.example('env pull -e dev', 'Download \"dev\" environment secrets')\r\n\t\t\t.example(\r\n\t\t\t\t'env pull -e dev -o',\r\n\t\t\t\t'Download and overwrite (if any exists) \"dev\" environment secrets',\r\n\t\t\t);\r\n\r\n\t\treturn builder;\r\n\t},\r\n\thandler: async ({ providers, ...argv }) => {\r\n\t\tconst pullProviders = providers.filter(\r\n\t\t\t({ handler: { pull } }) => !!pull,\r\n\t\t);\r\n\t\tconst promises = await Promise.all(\r\n\t\t\tpullProviders.map(({ config, handler: { key, pull } }) => {\r\n\t\t\t\tlogger.silly(`pulling from ${pc.yellow(key)} provider`);\r\n\r\n\t\t\t\treturn pull!(argv, config);\r\n\t\t\t}),\r\n\t\t);\r\n\r\n\t\tif (promises.length > 0)\r\n\t\t\tui.action('โฌ๏ธ', `pulled from ${promises.length} provider(s)`);\r\n\t\telse logger.warn('no providers for pull variables');\r\n\t},\r\n};\r\n"],"mappings":";;;;;AAeA,IAAa,IAAwD;CACpE,SAAS;CACT,UAAU;CACV,UAAU,OACT,EACE,QAAQ,EACR,WAAW;EACV,OAAO;EACP,SAAS;EACT,UAAU;EACV,MAAM;CACP,EACD,CAAC,EACA,QAAQ,mBAAmB,sCAAoC,EAC/D,QACA,sBACA,oEACD,GAEM;CAER,SAAS,OAAO,EAAE,cAAW,GAAG,QAAW;EAC1C,IAAM,IAAgB,EAAU,QAC9B,EAAE,SAAS,EAAE,gBAAa,CAAC,CAAC,CAC9B,GACM,IAAW,MAAM,QAAQ,IAC9B,EAAc,KAAK,EAAE,WAAQ,SAAS,EAAE,QAAK,iBAC5C,EAAO,MAAM,gBAAgB,EAAG,OAAO,CAAG,EAAE,UAAU,GAE/C,EAAM,GAAM,CAAM,EACzB,CACF;EAEA,AAAI,EAAS,SAAS,IACrB,EAAG,OAAO,MAAM,eAAe,EAAS,OAAO,aAAa,IACxD,EAAO,KAAK,iCAAiC;CACnD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.command.js","names":[],"sources":["../../src/commands/push.command.ts"],"sourcesContent":["import pc from 'picocolors';\nimport type { CommandModule } from 'yargs';\nimport type { CommandArguments } from '../arguments.js';\nimport { logger, ui } from '../utils/index.js';\n\nexport interface PushCommandArguments extends CommandArguments {\n\t// forces to push in case of conflict\n\tforce: boolean;\n}\n\n/**\n * Pushes environment variables to providers store.\n *\n * @example [>_]: env push -e dev\n */\nexport const pushCommand: CommandModule<any, PushCommandArguments> = {\n\tcommand: 'push [options..]',\n\tdescribe: 'Push environment variables to provider stores',\n\tbuilder: (builder) => {\n\t\tbuilder\n\t\t\t.options({\n\t\t\t\tforce: {\n\t\t\t\t\talias: 'f',\n\t\t\t\t\tdefault: false,\n\t\t\t\t\tdescribe: 'Force push for secrets',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t},\n\t\t\t})\n\t\t\t.example('env push -e dev', 'Download \"dev\" environment secrets');\n\n\t\treturn builder;\n\t},\n\thandler: async ({ providers, ...argv }) => {\n\t\tconst pushProviders = providers.filter(\n\t\t\t({ handler: { push } }) => !!push,\n\t\t);\n\t\tconst promises = await Promise.all(\n\t\t\tpushProviders.map(({ config, handler: { key, push } }) => {\n\t\t\t\tlogger.debug(`pushing to ${pc.yellow(key)} provider`);\n\n\t\t\t\treturn push!(argv, config);\n\t\t\t}),\n\t\t);\n\n\t\tif (promises.length > 0)\n\t\t\tui.action('โฌ๏ธ', `pushed to ${promises.length} provider(s)`);\n\t\telse logger.warn('no providers for push variables');\n\t},\n};\n"],"mappings":";;;;;AAeA,IAAa,IAAwD;CACpE,SAAS;CACT,UAAU;CACV,UAAU,OACT,EACE,QAAQ,EACR,OAAO;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,MAAM;CACP,EACD,CAAC,EACA,QAAQ,mBAAmB,sCAAoC,GAE1D;CAER,SAAS,OAAO,EAAE,cAAW,GAAG,QAAW;EAC1C,IAAM,IAAgB,EAAU,QAC9B,EAAE,SAAS,EAAE,gBAAa,CAAC,CAAC,CAC9B,GACM,IAAW,MAAM,QAAQ,IAC9B,EAAc,KAAK,EAAE,WAAQ,SAAS,EAAE,QAAK,iBAC5C,EAAO,MAAM,cAAc,EAAG,OAAO,CAAG,EAAE,UAAU,GAE7C,EAAM,GAAM,CAAM,EACzB,CACF;EAEA,AAAI,EAAS,SAAS,IACrB,EAAG,OAAO,MAAM,aAAa,EAAS,OAAO,aAAa,IACtD,EAAO,KAAK,iCAAiC;CACnD;AACD"}
|
|
1
|
+
{"version":3,"file":"push.command.js","names":[],"sources":["../../src/commands/push.command.ts"],"sourcesContent":["import pc from 'picocolors';\r\nimport type { CommandModule } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport { logger, ui } from '../utils/index.js';\r\n\r\nexport interface PushCommandArguments extends CommandArguments {\r\n\t// forces to push in case of conflict\r\n\tforce: boolean;\r\n}\r\n\r\n/**\r\n * Pushes environment variables to providers store.\r\n *\r\n * @example [>_]: env push -e dev\r\n */\r\nexport const pushCommand: CommandModule<any, PushCommandArguments> = {\r\n\tcommand: 'push [options..]',\r\n\tdescribe: 'Push environment variables to provider stores',\r\n\tbuilder: (builder) => {\r\n\t\tbuilder\r\n\t\t\t.options({\r\n\t\t\t\tforce: {\r\n\t\t\t\t\talias: 'f',\r\n\t\t\t\t\tdefault: false,\r\n\t\t\t\t\tdescribe: 'Force push for secrets',\r\n\t\t\t\t\ttype: 'boolean',\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t\t.example('env push -e dev', 'Download \"dev\" environment secrets');\r\n\r\n\t\treturn builder;\r\n\t},\r\n\thandler: async ({ providers, ...argv }) => {\r\n\t\tconst pushProviders = providers.filter(\r\n\t\t\t({ handler: { push } }) => !!push,\r\n\t\t);\r\n\t\tconst promises = await Promise.all(\r\n\t\t\tpushProviders.map(({ config, handler: { key, push } }) => {\r\n\t\t\t\tlogger.debug(`pushing to ${pc.yellow(key)} provider`);\r\n\r\n\t\t\t\treturn push!(argv, config);\r\n\t\t\t}),\r\n\t\t);\r\n\r\n\t\tif (promises.length > 0)\r\n\t\t\tui.action('โฌ๏ธ', `pushed to ${promises.length} provider(s)`);\r\n\t\telse logger.warn('no providers for push variables');\r\n\t},\r\n};\r\n"],"mappings":";;;;;AAeA,IAAa,IAAwD;CACpE,SAAS;CACT,UAAU;CACV,UAAU,OACT,EACE,QAAQ,EACR,OAAO;EACN,OAAO;EACP,SAAS;EACT,UAAU;EACV,MAAM;CACP,EACD,CAAC,EACA,QAAQ,mBAAmB,sCAAoC,GAE1D;CAER,SAAS,OAAO,EAAE,cAAW,GAAG,QAAW;EAC1C,IAAM,IAAgB,EAAU,QAC9B,EAAE,SAAS,EAAE,gBAAa,CAAC,CAAC,CAC9B,GACM,IAAW,MAAM,QAAQ,IAC9B,EAAc,KAAK,EAAE,WAAQ,SAAS,EAAE,QAAK,iBAC5C,EAAO,MAAM,cAAc,EAAG,OAAO,CAAG,EAAE,UAAU,GAE7C,EAAM,GAAM,CAAM,EACzB,CACF;EAEA,AAAI,EAAS,SAAS,IACrB,EAAG,OAAO,MAAM,aAAa,EAAS,OAAO,aAAa,IACtD,EAAO,KAAK,iCAAiC;CACnD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.command.js","names":[],"sources":["../../src/commands/schema.command.ts"],"sourcesContent":["import type { CommandModule } from 'yargs';\nimport type { CommandArguments } from '../arguments.js';\nimport {\n\tgenerateSchemaFrom,\n\tloadVariablesFromProviders,\n\tlogger,\n\tui,\n} from '../utils/index.js';\n\n/**\n * Generates validation schema from providers environment variables.\n *\n * @example [>_]: env schema -e dev -m build\n */\nexport const schemaCommand: CommandModule<any, CommandArguments> = {\n\tcommand: 'schema [options..]',\n\tdescribe: 'Generate the JSON validation schema from providers',\n\tbuilder: (builder) => {\n\t\treturn builder.example(\n\t\t\t'env schema --generate -e dev -m debug unit',\n\t\t\t'Updates JSON schema',\n\t\t);\n\t},\n\thandler: async (argv) => {\n\t\targv.ci = true;\n\n\t\tconst results = await loadVariablesFromProviders(argv.providers, argv);\n\n\t\tconst schema = await generateSchemaFrom(results, argv);\n\n\t\tlogger.silly('schema:', schema);\n\t\tui.action('๐', `schema updated โ ${argv.schemaFile}`);\n\t},\n};\n"],"mappings":";;;;;AAcA,IAAa,IAAsD;CAClE,SAAS;CACT,UAAU;CACV,UAAU,MACF,EAAQ,QACd,8CACA,qBACD;CAED,SAAS,OAAO,MAAS;EACxB,EAAK,KAAK;EAIV,IAAM,IAAS,MAAM,EAAmB,MAFlB,EAA2B,EAAK,WAAW,CAAI,GAEpB,CAAI;EAGrD,AADA,EAAO,MAAM,WAAW,CAAM,GAC9B,EAAG,OAAO,MAAM,oBAAoB,EAAK,YAAY;CACtD;AACD"}
|
|
1
|
+
{"version":3,"file":"schema.command.js","names":[],"sources":["../../src/commands/schema.command.ts"],"sourcesContent":["import type { CommandModule } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport {\r\n\tgenerateSchemaFrom,\r\n\tloadVariablesFromProviders,\r\n\tlogger,\r\n\tui,\r\n} from '../utils/index.js';\r\n\r\n/**\r\n * Generates validation schema from providers environment variables.\r\n *\r\n * @example [>_]: env schema -e dev -m build\r\n */\r\nexport const schemaCommand: CommandModule<any, CommandArguments> = {\r\n\tcommand: 'schema [options..]',\r\n\tdescribe: 'Generate the JSON validation schema from providers',\r\n\tbuilder: (builder) => {\r\n\t\treturn builder.example(\r\n\t\t\t'env schema --generate -e dev -m debug unit',\r\n\t\t\t'Updates JSON schema',\r\n\t\t);\r\n\t},\r\n\thandler: async (argv) => {\r\n\t\targv.ci = true;\r\n\r\n\t\tconst results = await loadVariablesFromProviders(argv.providers, argv);\r\n\r\n\t\tconst schema = await generateSchemaFrom(results, argv);\r\n\r\n\t\tlogger.silly('schema:', schema);\r\n\t\tui.action('๐', `schema updated โ ${argv.schemaFile}`);\r\n\t},\r\n};\r\n"],"mappings":";;;;;AAcA,IAAa,IAAsD;CAClE,SAAS;CACT,UAAU;CACV,UAAU,MACF,EAAQ,QACd,8CACA,qBACD;CAED,SAAS,OAAO,MAAS;EACxB,EAAK,KAAK;EAIV,IAAM,IAAS,MAAM,EAAmB,MAFlB,EAA2B,EAAK,WAAW,CAAI,GAEpB,CAAI;EAGrD,AADA,EAAO,MAAM,WAAW,CAAM,GAC9B,EAAG,OAAO,MAAM,oBAAoB,EAAK,YAAY;CACtD;AACD"}
|
package/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","names":[],"sources":["../src/main.ts"],"sourcesContent":["import { exec } from './exec.js';\nimport { normalizeRawArgv } from './utils/index.js';\n\nvoid exec(normalizeRawArgv(process.argv));\n"],"mappings":";;;;;AAGK,EAAK,EAAiB,QAAQ,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.js","names":[],"sources":["../src/main.ts"],"sourcesContent":["import { exec } from './exec.js';\r\nimport { normalizeRawArgv } from './utils/index.js';\r\n\r\nvoid exec(normalizeRawArgv(process.argv));\r\n"],"mappings":";;;;;AAGK,EAAK,EAAiB,QAAQ,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0
|
|
2
|
+
"version": "3.1.0",
|
|
3
3
|
"project": "common",
|
|
4
4
|
"name": "@calvear/env",
|
|
5
5
|
"type": "module",
|
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
"test:watch": "vitest --project unit",
|
|
97
97
|
"test:cov": "vitest run --project unit --coverage",
|
|
98
98
|
"test:int": "vitest run --project integration",
|
|
99
|
+
"run:test": "node dist/main.js --root tests/env --log debug -e dev : node tests/run.js",
|
|
99
100
|
"typecheck": "tsc --noEmit",
|
|
100
101
|
"lint": "eslint --cache --cache-location node_modules/.cache/eslint/ .",
|
|
101
102
|
"lint:fix": "eslint --fix --cache --cache-location node_modules/.cache/eslint/ .",
|
package/providers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/providers/index.ts"],"sourcesContent":["import type { EnvProvider } from '../interfaces/index.js';\nimport { AppSettingsProvider } from './app-settings.provider.js';\nimport { LocalProvider } from './local.provider.js';\nimport { PackageJsonProvider } from './package-json.provider.js';\nimport { SecretsProvider } from './secrets.provider.js';\n\nconst IntegratedProviders: Record<string, EnvProvider<any, any>> = {\n\t[AppSettingsProvider.key]: AppSettingsProvider,\n\t[LocalProvider.key]: LocalProvider,\n\t[PackageJsonProvider.key]: PackageJsonProvider,\n\t[SecretsProvider.key]: SecretsProvider,\n};\n\n// order defines provider load + merge precedence (later entries win):\n// package-json (base info) < app-settings < secrets < local (highest).\n// Do NOT alphabetize this array โ the sequence is semantic.\nconst IntegratedProviderConfig = [\n\t{\n\t\tpath: PackageJsonProvider.key,\n\t},\n\t{\n\t\tpath: AppSettingsProvider.key,\n\t},\n\t{\n\t\tpath: SecretsProvider.key,\n\t},\n\t{\n\t\tpath: LocalProvider.key,\n\t},\n];\n\nexport { IntegratedProviderConfig, IntegratedProviders };\n"],"mappings":";;;;;AAMA,IAAM,IAA6D;EACjE,EAAoB,MAAM;EAC1B,EAAc,MAAM;EACpB,EAAoB,MAAM;EAC1B,EAAgB,MAAM;AACxB,GAKM,IAA2B;CAChC,EACC,MAAM,EAAoB,IAC3B;CACA,EACC,MAAM,EAAoB,IAC3B;CACA,EACC,MAAM,EAAgB,IACvB;CACA,EACC,MAAM,EAAc,IACrB;AACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/providers/index.ts"],"sourcesContent":["import type { EnvProvider } from '../interfaces/index.js';\r\nimport { AppSettingsProvider } from './app-settings.provider.js';\r\nimport { LocalProvider } from './local.provider.js';\r\nimport { PackageJsonProvider } from './package-json.provider.js';\r\nimport { SecretsProvider } from './secrets.provider.js';\r\n\r\nconst IntegratedProviders: Record<string, EnvProvider<any, any>> = {\r\n\t[AppSettingsProvider.key]: AppSettingsProvider,\r\n\t[LocalProvider.key]: LocalProvider,\r\n\t[PackageJsonProvider.key]: PackageJsonProvider,\r\n\t[SecretsProvider.key]: SecretsProvider,\r\n};\r\n\r\n// order defines provider load + merge precedence (later entries win):\r\n// package-json (base info) < app-settings < secrets < local (highest).\r\n// Do NOT alphabetize this array โ the sequence is semantic.\r\nconst IntegratedProviderConfig = [\r\n\t{\r\n\t\tpath: PackageJsonProvider.key,\r\n\t},\r\n\t{\r\n\t\tpath: AppSettingsProvider.key,\r\n\t},\r\n\t{\r\n\t\tpath: SecretsProvider.key,\r\n\t},\r\n\t{\r\n\t\tpath: LocalProvider.key,\r\n\t},\r\n];\r\n\r\nexport { IntegratedProviderConfig, IntegratedProviders };\r\n"],"mappings":";;;;;AAMA,IAAM,IAA6D;EACjE,EAAoB,MAAM;EAC1B,EAAc,MAAM;EACpB,EAAoB,MAAM;EAC1B,EAAgB,MAAM;AACxB,GAKM,IAA2B;CAChC,EACC,MAAM,EAAoB,IAC3B;CACA,EACC,MAAM,EAAoB,IAC3B;CACA,EACC,MAAM,EAAgB,IACvB;CACA,EACC,MAAM,EAAc,IACrB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.provider.js","names":[],"sources":["../../src/providers/secrets.provider.ts"],"sourcesContent":["import pc from 'picocolors';\nimport type { CommandArguments } from '../arguments.js';\nimport type { EnvProvider } from '../interfaces/index.js';\nimport { logger as globalLogger, readJson } from '../utils/index.js';\n\nconst KEY = 'secrets';\n\nconst logger = globalLogger.getSubLogger({\n\tprefix: [pc.bold(pc.blue(`[${KEY}]`))],\n});\n\ninterface SecretsCommandArguments extends CommandArguments {\n\tsecretsFile: string;\n}\n\n/**\n * Loads secrets from env files in env folder.\n */\nexport const SecretsProvider: EnvProvider<SecretsCommandArguments> = {\n\tkey: KEY,\n\n\tbuilder: (builder) => {\n\t\tbuilder.options({\n\t\t\tsecretsFile: {\n\t\t\t\talias: 'sf',\n\t\t\t\tdefault: '[[root]]/[[env]].env.json',\n\t\t\t\tdescribe: 'Secret variables file path',\n\t\t\t\tgroup: KEY,\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t});\n\t},\n\n\tload: async ({ env, secretsFile }) => {\n\t\tif (!env) {\n\t\t\tlogger.silly('no env, provider skipped');\n\n\t\t\treturn [];\n\t\t}\n\n\t\tconst [secrets] = await readJson(secretsFile);\n\n\t\treturn [secrets];\n\t},\n};\n"],"mappings":";;;;;AAKA,IAAM,IAAM,WAEN,IAAS,EAAa,aAAa,EACxC,QAAQ,CAAC,EAAG,KAAK,EAAG,KAAK,IAAI,EAAI,EAAE,CAAC,CAAC,EACtC,CAAC,GASY,IAAwD;CACpE,KAAK;CAEL,UAAU,MAAY;EACrB,EAAQ,QAAQ,EACf,aAAa;GACZ,OAAO;GACP,SAAS;GACT,UAAU;GACV,OAAO;GACP,MAAM;EACP,EACD,CAAC;CACF;CAEA,MAAM,OAAO,EAAE,QAAK,qBAAkB;EACrC,IAAI,CAAC,GAGJ,OAFA,EAAO,MAAM,0BAA0B,GAEhC,CAAC;EAGT,IAAM,CAAC,KAAW,MAAM,EAAS,CAAW;EAE5C,OAAO,CAAC,CAAO;CAChB;AACD"}
|
|
1
|
+
{"version":3,"file":"secrets.provider.js","names":[],"sources":["../../src/providers/secrets.provider.ts"],"sourcesContent":["import pc from 'picocolors';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport type { EnvProvider } from '../interfaces/index.js';\r\nimport { logger as globalLogger, readJson } from '../utils/index.js';\r\n\r\nconst KEY = 'secrets';\r\n\r\nconst logger = globalLogger.getSubLogger({\r\n\tprefix: [pc.bold(pc.blue(`[${KEY}]`))],\r\n});\r\n\r\ninterface SecretsCommandArguments extends CommandArguments {\r\n\tsecretsFile: string;\r\n}\r\n\r\n/**\r\n * Loads secrets from env files in env folder.\r\n */\r\nexport const SecretsProvider: EnvProvider<SecretsCommandArguments> = {\r\n\tkey: KEY,\r\n\r\n\tbuilder: (builder) => {\r\n\t\tbuilder.options({\r\n\t\t\tsecretsFile: {\r\n\t\t\t\talias: 'sf',\r\n\t\t\t\tdefault: '[[root]]/[[env]].env.json',\r\n\t\t\t\tdescribe: 'Secret variables file path',\r\n\t\t\t\tgroup: KEY,\r\n\t\t\t\ttype: 'string',\r\n\t\t\t},\r\n\t\t});\r\n\t},\r\n\r\n\tload: async ({ env, secretsFile }) => {\r\n\t\tif (!env) {\r\n\t\t\tlogger.silly('no env, provider skipped');\r\n\r\n\t\t\treturn [];\r\n\t\t}\r\n\r\n\t\tconst [secrets] = await readJson(secretsFile);\r\n\r\n\t\treturn [secrets];\r\n\t},\r\n};\r\n"],"mappings":";;;;;AAKA,IAAM,IAAM,WAEN,IAAS,EAAa,aAAa,EACxC,QAAQ,CAAC,EAAG,KAAK,EAAG,KAAK,IAAI,EAAI,EAAE,CAAC,CAAC,EACtC,CAAC,GASY,IAAwD;CACpE,KAAK;CAEL,UAAU,MAAY;EACrB,EAAQ,QAAQ,EACf,aAAa;GACZ,OAAO;GACP,SAAS;GACT,UAAU;GACV,OAAO;GACP,MAAM;EACP,EACD,CAAC;CACF;CAEA,MAAM,OAAO,EAAE,QAAK,qBAAkB;EACrC,IAAI,CAAC,GAGJ,OAFA,EAAO,MAAM,0BAA0B,GAEhC,CAAC;EAGT,IAAM,CAAC,KAAW,MAAM,EAAS,CAAW;EAE5C,OAAO,CAAC,CAAO;CAChB;AACD"}
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"default": "info"
|
|
91
91
|
},
|
|
92
92
|
"logMaskAnyRegEx": {
|
|
93
|
-
"description": "
|
|
93
|
+
"description": "Regexes that mask matching content inside any string value (global, every occurrence).",
|
|
94
94
|
"type": "array",
|
|
95
95
|
"items": {
|
|
96
96
|
"type": "string"
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"default": []
|
|
99
99
|
},
|
|
100
100
|
"logMaskValuesOfKeys": {
|
|
101
|
-
"description": "
|
|
101
|
+
"description": "Mask a variable's whole value when its key matches: an exact key name (case-insensitive) or a /source/flags regex on the key name, e.g. \"/token/i\".",
|
|
102
102
|
"type": "array",
|
|
103
103
|
"items": {
|
|
104
104
|
"type": "string"
|
package/utils/argv.util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argv.util.js","names":[],"sources":["../../src/utils/argv.util.ts"],"sourcesContent":["/**\n * Recombines argv tokens so single-quoted, space-containing argument values\n * survive shell splitting. Mirrors the original main.ts pre-processing as a\n * pure, testable function.\n *\n * @param argv raw process.argv\n * @returns normalized argv (already sliced past node + script path)\n */\nexport function normalizeRawArgv(argv: string[]): string[] {\n\tconst cmdArgs: string[] = [];\n\tlet composite = '';\n\n\tfor (let arg of argv) {\n\t\tif (arg.includes(' ')) arg = `\"${arg}\"`;\n\n\t\tif (arg.at(-1) === \"'\") {\n\t\t\tcmdArgs.push(`${composite} ${arg}`.replaceAll(\"'\", '\"'));\n\t\t\tcomposite = '';\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg[0] === \"'\") {\n\t\t\tcomposite += arg;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (composite) {\n\t\t\tcomposite += ` ${arg}`;\n\t\t\tcontinue;\n\t\t}\n\n\t\tcmdArgs.push(arg);\n\t}\n\n\treturn cmdArgs.slice(2);\n}\n"],"mappings":";AAQA,SAAgB,EAAiB,GAA0B;CAC1D,IAAM,IAAoB,CAAC,GACvB,IAAY;CAEhB,KAAK,IAAI,KAAO,GAAM;EAGrB,IAFI,EAAI,SAAS,GAAG,MAAG,IAAM,IAAI,EAAI,KAEjC,EAAI,GAAG,EAAE,MAAM,KAAK;GAEvB,AADA,EAAQ,KAAK,GAAG,EAAU,GAAG,IAAM,WAAW,KAAK,IAAG,CAAC,GACvD,IAAY;GACZ;EACD;EAEA,IAAI,EAAI,OAAO,KAAK;GACnB,KAAa;GACb;EACD;EAEA,IAAI,GAAW;GACd,KAAa,IAAI;GACjB;EACD;EAEA,EAAQ,KAAK,CAAG;CACjB;CAEA,OAAO,EAAQ,MAAM,CAAC;AACvB"}
|
|
1
|
+
{"version":3,"file":"argv.util.js","names":[],"sources":["../../src/utils/argv.util.ts"],"sourcesContent":["/**\r\n * Recombines argv tokens so single-quoted, space-containing argument values\r\n * survive shell splitting. Mirrors the original main.ts pre-processing as a\r\n * pure, testable function.\r\n *\r\n * @param argv raw process.argv\r\n * @returns normalized argv (already sliced past node + script path)\r\n */\r\nexport function normalizeRawArgv(argv: string[]): string[] {\r\n\tconst cmdArgs: string[] = [];\r\n\tlet composite = '';\r\n\r\n\tfor (let arg of argv) {\r\n\t\tif (arg.includes(' ')) arg = `\"${arg}\"`;\r\n\r\n\t\tif (arg.at(-1) === \"'\") {\r\n\t\t\tcmdArgs.push(`${composite} ${arg}`.replaceAll(\"'\", '\"'));\r\n\t\t\tcomposite = '';\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (arg[0] === \"'\") {\r\n\t\t\tcomposite += arg;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (composite) {\r\n\t\t\tcomposite += ` ${arg}`;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tcmdArgs.push(arg);\r\n\t}\r\n\r\n\treturn cmdArgs.slice(2);\r\n}\r\n"],"mappings":";AAQA,SAAgB,EAAiB,GAA0B;CAC1D,IAAM,IAAoB,CAAC,GACvB,IAAY;CAEhB,KAAK,IAAI,KAAO,GAAM;EAGrB,IAFI,EAAI,SAAS,GAAG,MAAG,IAAM,IAAI,EAAI,KAEjC,EAAI,GAAG,EAAE,MAAM,KAAK;GAEvB,AADA,EAAQ,KAAK,GAAG,EAAU,GAAG,IAAM,WAAW,KAAK,IAAG,CAAC,GACvD,IAAY;GACZ;EACD;EAEA,IAAI,EAAI,OAAO,KAAK;GACnB,KAAa;GACb;EACD;EAEA,IAAI,GAAW;GACd,KAAa,IAAI;GACjB;EACD;EAEA,EAAQ,KAAK,CAAG;CACjB;CAEA,OAAO,EAAQ,MAAM,CAAC;AACvB"}
|
package/utils/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,OAAO,GACP,MAAM,GACN,OAAO,GACP,OAAO,GACP,MAAM,CAAC;AAEV,+CAA+C;AAC/C,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAOnD,CAAC;AAEF,MAAM,WAAW,cAAc;IAC9B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,OAAO,GACP,MAAM,GACN,OAAO,GACP,OAAO,GACP,MAAM,CAAC;AAEV,+CAA+C;AAC/C,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAOnD,CAAC;AAEF,MAAM,WAAW,cAAc;IAC9B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC;CACxB;AA8BD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,GAAE,cAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,CAO3E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EACvB,QAAQ,EAAE,cAAc,GACtB,IAAI,CAUN;AAED,4BAA4B;AAC5B,eAAO,MAAM,MAAM,iBAAiB,CAAC"}
|
package/utils/logger.js
CHANGED
|
@@ -9,24 +9,29 @@ var t = {
|
|
|
9
9
|
warn: 4
|
|
10
10
|
}, n = {
|
|
11
11
|
hideLogPositionForProduction: !0,
|
|
12
|
-
maskPlaceholder: "
|
|
12
|
+
maskPlaceholder: "*****",
|
|
13
|
+
maskValuesOfKeysCaseInsensitive: !0,
|
|
13
14
|
prettyLogTemplate: "{{hh}}:{{MM}}:{{ss}}.{{ms}} {{logLevelName}} ",
|
|
14
15
|
prettyLogTimeZone: "local",
|
|
15
16
|
type: "pretty"
|
|
16
17
|
};
|
|
17
|
-
function r(
|
|
18
|
+
function r(e) {
|
|
19
|
+
let t = /^\/(.*)\/([a-z]*)$/s.exec(e), n = t ? t[1] : e, r = t ? t[2] : "";
|
|
20
|
+
return new RegExp(n, r.includes("g") ? r : `${r}g`);
|
|
21
|
+
}
|
|
22
|
+
function i(i = {}) {
|
|
18
23
|
return new e({
|
|
19
24
|
...n,
|
|
20
|
-
maskValuesOfKeys:
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
maskValuesOfKeys: i.maskValuesOfKeys ?? [],
|
|
26
|
+
maskValuesRegEx: (i.maskAnyRegEx ?? []).map(r),
|
|
27
|
+
minLevel: t[i.minLevel ?? "info"]
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
|
-
function
|
|
26
|
-
n.minLevel && (e.settings.minLevel = t[n.minLevel]), n.maskValuesOfKeys && (e.settings.maskValuesOfKeys = n.maskValuesOfKeys), n.maskAnyRegEx && (e.settings.maskValuesRegEx = n.maskAnyRegEx.map(
|
|
30
|
+
function a(e, n) {
|
|
31
|
+
n.minLevel && (e.settings.minLevel = t[n.minLevel]), n.maskValuesOfKeys && (e.settings.maskValuesOfKeys = n.maskValuesOfKeys), n.maskAnyRegEx && (e.settings.maskValuesRegEx = n.maskAnyRegEx.map(r));
|
|
27
32
|
}
|
|
28
|
-
var
|
|
33
|
+
var o = i();
|
|
29
34
|
//#endregion
|
|
30
|
-
export { t as LOG_LEVELS,
|
|
35
|
+
export { t as LOG_LEVELS, a as configureLogger, i as createLogger, o as logger };
|
|
31
36
|
|
|
32
37
|
//# sourceMappingURL=logger.js.map
|
package/utils/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { Logger } from 'tslog';\r\nimport type { ISettingsParam } from 'tslog';\r\n\r\nexport type LogLevelName =\r\n\t| 'debug'\r\n\t| 'error'\r\n\t| 'info'\r\n\t| 'silly'\r\n\t| 'trace'\r\n\t| 'warn';\r\n\r\n/** tslog v4 numeric minLevel by level name. */\r\nexport const LOG_LEVELS: Record<LogLevelName, number> = {\r\n\tdebug: 2,\r\n\terror: 5,\r\n\tinfo: 3,\r\n\tsilly: 0,\r\n\ttrace: 1,\r\n\twarn: 4,\r\n};\r\n\r\nexport interface LoggerSettings {\r\n\tmaskAnyRegEx?: string[];\r\n\tmaskValuesOfKeys?: string[];\r\n\tminLevel?: LogLevelName;\r\n}\r\n\r\nconst BASE_SETTINGS: ISettingsParam<unknown> = {\r\n\thideLogPositionForProduction: true,\r\n\tmaskPlaceholder: '
|
|
1
|
+
{"version":3,"file":"logger.js","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { Logger } from 'tslog';\r\nimport type { ISettingsParam } from 'tslog';\r\n\r\nexport type LogLevelName =\r\n\t| 'debug'\r\n\t| 'error'\r\n\t| 'info'\r\n\t| 'silly'\r\n\t| 'trace'\r\n\t| 'warn';\r\n\r\n/** tslog v4 numeric minLevel by level name. */\r\nexport const LOG_LEVELS: Record<LogLevelName, number> = {\r\n\tdebug: 2,\r\n\terror: 5,\r\n\tinfo: 3,\r\n\tsilly: 0,\r\n\ttrace: 1,\r\n\twarn: 4,\r\n};\r\n\r\nexport interface LoggerSettings {\r\n\tmaskAnyRegEx?: string[];\r\n\tmaskValuesOfKeys?: string[];\r\n\tminLevel?: LogLevelName;\r\n}\r\n\r\nconst BASE_SETTINGS: ISettingsParam<unknown> = {\r\n\thideLogPositionForProduction: true,\r\n\tmaskPlaceholder: '*****',\r\n\t// key masking matches regardless of case, so PASSWORD/Password/password\r\n\t// are all masked and the pretty env render stays consistent with tslog\r\n\tmaskValuesOfKeysCaseInsensitive: true,\r\n\tprettyLogTemplate: '{{hh}}:{{MM}}:{{ss}}.{{ms}}\\t{{logLevelName}}\\t',\r\n\tprettyLogTimeZone: 'local',\r\n\ttype: 'pretty',\r\n};\r\n\r\n/**\r\n * Compiles a user-supplied mask pattern into a RegExp.\r\n *\r\n * Accepts either a bare source (`secret\\\\d+`) or the `/source/flags` form\r\n * (`/secret/i`) so callers can opt into case-insensitive or other flags. The\r\n * global flag is always forced: tslog masks via `String.replace`, which only\r\n * replaces the first match otherwise, so a secret repeated in one string would\r\n * leak its later occurrences.\r\n */\r\nfunction compileMaskRegEx(pattern: string): RegExp {\r\n\tconst delimited = /^\\/(.*)\\/([a-z]*)$/s.exec(pattern);\r\n\tconst source = delimited ? delimited[1] : pattern;\r\n\tconst flags = delimited ? delimited[2] : '';\r\n\r\n\treturn new RegExp(source, flags.includes('g') ? flags : `${flags}g`);\r\n}\r\n\r\n/**\r\n * Builds a configured tslog logger. Extracted as a factory so settings logic\r\n * is unit-testable and reused by sub-loggers.\r\n */\r\nexport function createLogger(settings: LoggerSettings = {}): Logger<unknown> {\r\n\treturn new Logger({\r\n\t\t...BASE_SETTINGS,\r\n\t\tmaskValuesOfKeys: settings.maskValuesOfKeys ?? [],\r\n\t\tmaskValuesRegEx: (settings.maskAnyRegEx ?? []).map(compileMaskRegEx),\r\n\t\tminLevel: LOG_LEVELS[settings.minLevel ?? 'info'],\r\n\t});\r\n}\r\n\r\n/**\r\n * Applies runtime settings to an existing logger by mutating `logger.settings`\r\n * (tslog v4 has no `setSettings`).\r\n */\r\nexport function configureLogger(\r\n\tlogger: Logger<unknown>,\r\n\tsettings: LoggerSettings,\r\n): void {\r\n\tif (settings.minLevel)\r\n\t\tlogger.settings.minLevel = LOG_LEVELS[settings.minLevel];\r\n\r\n\tif (settings.maskValuesOfKeys)\r\n\t\tlogger.settings.maskValuesOfKeys = settings.maskValuesOfKeys;\r\n\r\n\tif (settings.maskAnyRegEx)\r\n\t\tlogger.settings.maskValuesRegEx =\r\n\t\t\tsettings.maskAnyRegEx.map(compileMaskRegEx);\r\n}\r\n\r\n/** Global stdout logger. */\r\nexport const logger = createLogger();\r\n"],"mappings":";;AAYA,IAAa,IAA2C;CACvD,OAAO;CACP,OAAO;CACP,MAAM;CACN,OAAO;CACP,OAAO;CACP,MAAM;AACP,GAQM,IAAyC;CAC9C,8BAA8B;CAC9B,iBAAiB;CAGjB,iCAAiC;CACjC,mBAAmB;CACnB,mBAAmB;CACnB,MAAM;AACP;AAWA,SAAS,EAAiB,GAAyB;CAClD,IAAM,IAAY,sBAAsB,KAAK,CAAO,GAC9C,IAAS,IAAY,EAAU,KAAK,GACpC,IAAQ,IAAY,EAAU,KAAK;CAEzC,OAAO,IAAI,OAAO,GAAQ,EAAM,SAAS,GAAG,IAAI,IAAQ,GAAG,EAAM,EAAE;AACpE;AAMA,SAAgB,EAAa,IAA2B,CAAC,GAAoB;CAC5E,OAAO,IAAI,EAAO;EACjB,GAAG;EACH,kBAAkB,EAAS,oBAAoB,CAAC;EAChD,kBAAkB,EAAS,gBAAgB,CAAC,GAAG,IAAI,CAAgB;EACnE,UAAU,EAAW,EAAS,YAAY;CAC3C,CAAC;AACF;AAMA,SAAgB,EACf,GACA,GACO;CAOP,AANI,EAAS,aACZ,EAAO,SAAS,WAAW,EAAW,EAAS,YAE5C,EAAS,qBACZ,EAAO,SAAS,mBAAmB,EAAS,mBAEzC,EAAS,iBACZ,EAAO,SAAS,kBACf,EAAS,aAAa,IAAI,CAAgB;AAC7C;AAGA,IAAa,IAAS,EAAa"}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Flatten a object keeping depth path
|
|
3
3
|
* in key using __ as level separator.
|
|
4
4
|
*
|
|
5
|
+
* Keys prefixed with `#` are skipped, and the `$` global marker is stripped
|
|
6
|
+
* per segment so nested globals (e.g. `GROUP.$VAR1`) flatten to `GROUP__VAR1`
|
|
7
|
+
* instead of leaving the `$` embedded mid-key.
|
|
8
|
+
*
|
|
5
9
|
* @param {Record<string, any>} obj
|
|
6
10
|
* @param {string} nestingDelimiter char for delimit nesting levels
|
|
7
11
|
* @param {string} pkey first level key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.util.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.util.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"normalize.util.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CACtB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,gBAAgB,SAAO,EACvB,IAAI,SAAK,GACP,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACxB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,gBAAgB,SAAO,EACvB,mBAAmB,UAAQ,EAC3B,IAAI,SAAK,GACP,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyCzB"}
|
package/utils/normalize.util.js
CHANGED
|
@@ -4,7 +4,7 @@ function e(t, n = "__", r = "") {
|
|
|
4
4
|
for (let a in t) {
|
|
5
5
|
let o = t[a], s = typeof o;
|
|
6
6
|
if (!(o === void 0 || s === "function") && a[0] !== "#") {
|
|
7
|
-
if (a = r + a, o === null || s !== "object" || Array.isArray(o)) {
|
|
7
|
+
if (a = r + (a[0] === "$" ? a.slice(1) : a), o === null || s !== "object" || Array.isArray(o)) {
|
|
8
8
|
i[a] = o;
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.util.js","names":[],"sources":["../../src/utils/normalize.util.ts"],"sourcesContent":["/**\r\n * Flatten a object keeping depth path\r\n * in key using __ as level separator.\r\n *\r\n * @param {Record<string, any>} obj\r\n * @param {string} nestingDelimiter char for delimit nesting levels\r\n * @param {string} pkey first level key\r\n *\r\n * @returns {Record<string, unknown>} flattened object\r\n */\r\nexport function flatten(\r\n\tobj: Record<string, any>,\r\n\tnestingDelimiter = '__',\r\n\tpkey = '',\r\n): Record<string, unknown> {\r\n\tconst flattened: Record<string, unknown> = {};\r\n\r\n\tfor (let key in obj) {\r\n\t\tconst value = obj[key];\r\n\t\tconst type = typeof value;\r\n\r\n\t\tif (value === undefined || type === 'function') continue;\r\n\r\n\t\t// skipped property\r\n\t\tif (key[0] === '#') continue;\r\n\t\tkey = pkey + key;\r\n\r\n\t\tif (value === null || type !== 'object' || Array.isArray(value)) {\r\n\t\t\tflattened[key] = value;\r\n\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tObject.assign(\r\n\t\t\tflattened,\r\n\t\t\tflatten(value, nestingDelimiter, `${key}${nestingDelimiter}`),\r\n\t\t);\r\n\t}\r\n\r\n\treturn flattened;\r\n}\r\n\r\n/**\r\n * Normalizes env object, converts arrays in list strings,\r\n * only primitives types array,\r\n * and removes $ global character from keys.\r\n *\r\n * @param {Record<string, any>} obj\r\n * @param {string} nestingDelimiter char for delimit nesting levels\r\n * @param {boolean} arrayDescomposition serialize or break down arrays\r\n * @param {string} pkey first level key\r\n *\r\n * @returns {Record<string, unknown>} normalized object\r\n */\r\nexport function normalize(\r\n\tobj: Record<string, any>,\r\n\tnestingDelimiter = '__',\r\n\tarrayDescomposition = false,\r\n\tpkey = '',\r\n): Record<string, unknown> {\r\n\tconst flattened: Record<string, unknown> = {};\r\n\r\n\tfor (let key in obj) {\r\n\t\tconst value = obj[key];\r\n\t\tconst type = typeof value;\r\n\r\n\t\tif (value === null || value === undefined || type === 'function')\r\n\t\t\tcontinue;\r\n\r\n\t\t// shared/global keys are prefixed with `$`; strip it for injection\r\n\t\tkey = pkey + (key[0] === '$' ? key.slice(1) : key);\r\n\r\n\t\tif (type !== 'object') {\r\n\t\t\tflattened[key] = value;\r\n\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (Array.isArray(value)) {\r\n\t\t\tnormalizeArray(\r\n\t\t\t\tflattened,\r\n\t\t\t\tkey,\r\n\t\t\t\tvalue,\r\n\t\t\t\tnestingDelimiter,\r\n\t\t\t\tarrayDescomposition,\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tObject.assign(\r\n\t\t\t\tflattened,\r\n\t\t\t\tnormalize(\r\n\t\t\t\t\tvalue,\r\n\t\t\t\t\tnestingDelimiter,\r\n\t\t\t\t\tarrayDescomposition,\r\n\t\t\t\t\t`${key}${nestingDelimiter}`,\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\treturn flattened;\r\n}\r\n\r\n/**\r\n * Flatten and normalizes an array.\r\n *\r\n * @param {Record<string, unknown>} flattened\r\n * @param {string} key\r\n * @param {any[]} value\r\n * @param {string} [nestingDelimiter='__']\r\n * @param {boolean} [arrayDescomposition=false]\r\n */\r\nfunction normalizeArray(\r\n\tflattened: Record<string, unknown>,\r\n\tkey: string,\r\n\tvalue: any[],\r\n\tnestingDelimiter = '__',\r\n\tarrayDescomposition = false,\r\n): void {\r\n\tif (arrayDescomposition) {\r\n\t\tkey = `${key}${nestingDelimiter}`;\r\n\r\n\t\tfor (const [i, item] of value.entries()) {\r\n\t\t\tif (typeof item === 'object') {\r\n\t\t\t\tObject.assign(\r\n\t\t\t\t\tflattened,\r\n\t\t\t\t\tnormalize(\r\n\t\t\t\t\t\titem,\r\n\t\t\t\t\t\tnestingDelimiter,\r\n\t\t\t\t\t\tarrayDescomposition,\r\n\t\t\t\t\t\t`${key}${i}${nestingDelimiter}`,\r\n\t\t\t\t\t),\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tflattened[`${key}${i}`] = item;\r\n\t\t\t}\r\n\t\t}\r\n\t} else {\r\n\t\tflattened[key] = value.filter((v) => typeof v !== 'object').join(',');\r\n\t}\r\n}\r\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"normalize.util.js","names":[],"sources":["../../src/utils/normalize.util.ts"],"sourcesContent":["/**\r\n * Flatten a object keeping depth path\r\n * in key using __ as level separator.\r\n *\r\n * Keys prefixed with `#` are skipped, and the `$` global marker is stripped\r\n * per segment so nested globals (e.g. `GROUP.$VAR1`) flatten to `GROUP__VAR1`\r\n * instead of leaving the `$` embedded mid-key.\r\n *\r\n * @param {Record<string, any>} obj\r\n * @param {string} nestingDelimiter char for delimit nesting levels\r\n * @param {string} pkey first level key\r\n *\r\n * @returns {Record<string, unknown>} flattened object\r\n */\r\nexport function flatten(\r\n\tobj: Record<string, any>,\r\n\tnestingDelimiter = '__',\r\n\tpkey = '',\r\n): Record<string, unknown> {\r\n\tconst flattened: Record<string, unknown> = {};\r\n\r\n\tfor (let key in obj) {\r\n\t\tconst value = obj[key];\r\n\t\tconst type = typeof value;\r\n\r\n\t\tif (value === undefined || type === 'function') continue;\r\n\r\n\t\t// skipped property\r\n\t\tif (key[0] === '#') continue;\r\n\t\t// shared/global keys are prefixed with `$`; strip the marker per segment\r\n\t\tkey = pkey + (key[0] === '$' ? key.slice(1) : key);\r\n\r\n\t\tif (value === null || type !== 'object' || Array.isArray(value)) {\r\n\t\t\tflattened[key] = value;\r\n\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tObject.assign(\r\n\t\t\tflattened,\r\n\t\t\tflatten(value, nestingDelimiter, `${key}${nestingDelimiter}`),\r\n\t\t);\r\n\t}\r\n\r\n\treturn flattened;\r\n}\r\n\r\n/**\r\n * Normalizes env object, converts arrays in list strings,\r\n * only primitives types array,\r\n * and removes $ global character from keys.\r\n *\r\n * @param {Record<string, any>} obj\r\n * @param {string} nestingDelimiter char for delimit nesting levels\r\n * @param {boolean} arrayDescomposition serialize or break down arrays\r\n * @param {string} pkey first level key\r\n *\r\n * @returns {Record<string, unknown>} normalized object\r\n */\r\nexport function normalize(\r\n\tobj: Record<string, any>,\r\n\tnestingDelimiter = '__',\r\n\tarrayDescomposition = false,\r\n\tpkey = '',\r\n): Record<string, unknown> {\r\n\tconst flattened: Record<string, unknown> = {};\r\n\r\n\tfor (let key in obj) {\r\n\t\tconst value = obj[key];\r\n\t\tconst type = typeof value;\r\n\r\n\t\tif (value === null || value === undefined || type === 'function')\r\n\t\t\tcontinue;\r\n\r\n\t\t// shared/global keys are prefixed with `$`; strip it for injection\r\n\t\tkey = pkey + (key[0] === '$' ? key.slice(1) : key);\r\n\r\n\t\tif (type !== 'object') {\r\n\t\t\tflattened[key] = value;\r\n\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (Array.isArray(value)) {\r\n\t\t\tnormalizeArray(\r\n\t\t\t\tflattened,\r\n\t\t\t\tkey,\r\n\t\t\t\tvalue,\r\n\t\t\t\tnestingDelimiter,\r\n\t\t\t\tarrayDescomposition,\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tObject.assign(\r\n\t\t\t\tflattened,\r\n\t\t\t\tnormalize(\r\n\t\t\t\t\tvalue,\r\n\t\t\t\t\tnestingDelimiter,\r\n\t\t\t\t\tarrayDescomposition,\r\n\t\t\t\t\t`${key}${nestingDelimiter}`,\r\n\t\t\t\t),\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\treturn flattened;\r\n}\r\n\r\n/**\r\n * Flatten and normalizes an array.\r\n *\r\n * @param {Record<string, unknown>} flattened\r\n * @param {string} key\r\n * @param {any[]} value\r\n * @param {string} [nestingDelimiter='__']\r\n * @param {boolean} [arrayDescomposition=false]\r\n */\r\nfunction normalizeArray(\r\n\tflattened: Record<string, unknown>,\r\n\tkey: string,\r\n\tvalue: any[],\r\n\tnestingDelimiter = '__',\r\n\tarrayDescomposition = false,\r\n): void {\r\n\tif (arrayDescomposition) {\r\n\t\tkey = `${key}${nestingDelimiter}`;\r\n\r\n\t\tfor (const [i, item] of value.entries()) {\r\n\t\t\tif (typeof item === 'object') {\r\n\t\t\t\tObject.assign(\r\n\t\t\t\t\tflattened,\r\n\t\t\t\t\tnormalize(\r\n\t\t\t\t\t\titem,\r\n\t\t\t\t\t\tnestingDelimiter,\r\n\t\t\t\t\t\tarrayDescomposition,\r\n\t\t\t\t\t\t`${key}${i}${nestingDelimiter}`,\r\n\t\t\t\t\t),\r\n\t\t\t\t);\r\n\t\t\t} else {\r\n\t\t\t\tflattened[`${key}${i}`] = item;\r\n\t\t\t}\r\n\t\t}\r\n\t} else {\r\n\t\tflattened[key] = value.filter((v) => typeof v !== 'object').join(',');\r\n\t}\r\n}\r\n"],"mappings":";AAcA,SAAgB,EACf,GACA,IAAmB,MACnB,IAAO,IACmB;CAC1B,IAAM,IAAqC,CAAC;CAE5C,KAAK,IAAI,KAAO,GAAK;EACpB,IAAM,IAAQ,EAAI,IACZ,IAAO,OAAO;EAEhB,YAAU,KAAA,KAAa,MAAS,eAGhC,EAAI,OAAO,KAIf;OAFA,IAAM,KAAQ,EAAI,OAAO,MAAM,EAAI,MAAM,CAAC,IAAI,IAE1C,MAAU,QAAQ,MAAS,YAAY,MAAM,QAAQ,CAAK,GAAG;IAChE,EAAU,KAAO;IAEjB;GACD;GAEA,OAAO,OACN,GACA,EAAQ,GAAO,GAAkB,GAAG,IAAM,GAAkB,CAC7D;EALA;CAMD;CAEA,OAAO;AACR;AAcA,SAAgB,EACf,GACA,IAAmB,MACnB,IAAsB,IACtB,IAAO,IACmB;CAC1B,IAAM,IAAqC,CAAC;CAE5C,KAAK,IAAI,KAAO,GAAK;EACpB,IAAM,IAAQ,EAAI,IACZ,IAAO,OAAO;EAEhB,WAAU,QAA+B,MAAS,aAMtD;OAFA,IAAM,KAAQ,EAAI,OAAO,MAAM,EAAI,MAAM,CAAC,IAAI,IAE1C,MAAS,UAAU;IACtB,EAAU,KAAO;IAEjB;GACD;GAEA,AAAI,MAAM,QAAQ,CAAK,IACtB,EACC,GACA,GACA,GACA,GACA,CACD,IAEA,OAAO,OACN,GACA,EACC,GACA,GACA,GACA,GAAG,IAAM,GACV,CACD;EAnBD;CAqBD;CAEA,OAAO;AACR;AAWA,SAAS,EACR,GACA,GACA,GACA,IAAmB,MACnB,IAAsB,IACf;CACP,IAAI,GAAqB;EACxB,IAAM,GAAG,IAAM;EAEf,KAAK,IAAM,CAAC,GAAG,MAAS,EAAM,QAAQ,GACrC,AAAI,OAAO,KAAS,WACnB,OAAO,OACN,GACA,EACC,GACA,GACA,GACA,GAAG,IAAM,IAAI,GACd,CACD,IAEA,EAAU,GAAG,IAAM,OAAO;CAG7B,OACC,EAAU,KAAO,EAAM,QAAQ,MAAM,OAAO,KAAM,QAAQ,EAAE,KAAK,GAAG;AAEtE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.util.d.ts","sourceRoot":"","sources":["../../src/utils/schema.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,cAAc,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAiC9C;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAyBlC;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,CAOlC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GACjC,OAAO,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,SAAK,EACd,gBAAgB,SAAO,EACvB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GACjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"schema.util.d.ts","sourceRoot":"","sources":["../../src/utils/schema.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,cAAc,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAiC9C;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAyBlC;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,CAOlC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GACjC,OAAO,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,SAAK,EACd,gBAAgB,SAAO,EACvB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GACjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqBzB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,aAAa,UAAO,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAI3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,aAAa,UAAO,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAS3C"}
|
package/utils/schema.util.js
CHANGED
|
@@ -29,10 +29,10 @@ function l(e, t = "", n = "__", r = {}) {
|
|
|
29
29
|
if (s(e)) {
|
|
30
30
|
for (let i in e.properties) {
|
|
31
31
|
if (i[0] === "#") continue;
|
|
32
|
-
let a = t + (t ? n : "") +
|
|
32
|
+
let a = i[0] === "$" ? i.slice(1) : i, o = t + (t ? n : "") + a;
|
|
33
33
|
r = {
|
|
34
34
|
...r,
|
|
35
|
-
...l(e.properties[i],
|
|
35
|
+
...l(e.properties[i], o, n)
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
return r;
|
package/utils/schema.util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.util.js","names":[],"sources":["../../src/utils/schema.util.ts"],"sourcesContent":["import type { Format, JSONSchemaType, ValidateFunction } from 'ajv';\r\nimport type { Options } from 'to-json-schema';\r\n\r\n// cached AJV instances (with and without formats)\r\nlet _ajv: any;\r\nlet _ajvWithFormats: any;\r\n\r\n// cached module references\r\nlet _AjvClass: any;\r\nlet _addFormats: any;\r\nlet _toJsonSchema: any;\r\n\r\n/* eslint-disable regexp/no-useless-assertions, regexp/no-super-linear-backtracking -- domain validation regexes from JSON Schema spec; modifying these patterns would change format validation behavior */\r\nconst FORMAT_REGEXPS: Record<string, Format> = {\r\n\t'ip-address':\r\n\t\t/^(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})$/,\r\n\r\n\tcolor: /^(#?([\\dA-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\b\\s*,\\s*\\b(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\b\\s*,\\s*\\b(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/,\r\n\r\n\thostname:\r\n\t\t/^(?=.{1,255}$)[\\da-z](?:[\\da-z-]{0,61}[\\da-z])?(?:\\.[\\da-z](?:[\\da-z-]{0,61}[\\da-z])?)*\\.?$/i,\r\n\r\n\talphanumeric: /^[\\da-z]+$/i,\r\n\r\n\t'utc-millisec': (input: string) => !Number.isNaN(+input),\r\n\r\n\talpha: /^[a-z]+$/i,\r\n\r\n\tstyle: /\\s*(.+?):\\s*([^;]+);?/g,\r\n\r\n\tphone: /^\\+(?:\\d ?){6,14}\\d$/,\r\n};\r\n/* eslint-enable regexp/no-useless-assertions, regexp/no-super-linear-backtracking */\r\n\r\n/**\r\n * Generates JSON schema from JSON template/object.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} json json object\r\n * @param {Options} [options]\r\n *\r\n * @returns {*} {Promise<Record<string, unknown>>}\r\n */\r\nexport async function schemaFrom(\r\n\tjson: Record<string, unknown>,\r\n\toptions?: Options & { nullable?: boolean },\r\n): Promise<Record<string, unknown>> {\r\n\tif (!_toJsonSchema) {\r\n\t\tconst mod = await import('to-json-schema');\r\n\t\t_toJsonSchema = mod.default;\r\n\t}\r\n\r\n\treturn _toJsonSchema(json, {\r\n\t\trequired: false,\r\n\t\t...options,\r\n\t\tpostProcessFnc: (\r\n\t\t\ttype: string,\r\n\t\t\tschema: any,\r\n\t\t\tvalue: unknown,\r\n\t\t\tdefaultFunc: any,\r\n\t\t) => {\r\n\t\t\tif (value !== json) {\r\n\t\t\t\tschema.type = [type];\r\n\t\t\t\tschema.nullable = options?.nullable ?? false;\r\n\t\t\t}\r\n\r\n\t\t\tif (value === null || value === undefined) schema.nullable = true;\r\n\r\n\t\t\treturn defaultFunc(type, schema, value);\r\n\t\t},\r\n\t});\r\n}\r\n\r\n/**\r\n * Validates if a object is a JSON schema.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} schema\r\n *\r\n * @returns {boolean} if is a JSON schema\r\n */\r\nexport function isJsonSchemaObject(\r\n\tschema: Record<string, unknown>,\r\n): schema is JSONSchemaType<object> {\r\n\tif (schema.type === 'object') return true;\r\n\r\n\treturn (\r\n\t\tArray.isArray(schema.type) &&\r\n\t\t(schema.type as string[]).includes('object')\r\n\t);\r\n}\r\n\r\n/**\r\n * Converts a JSON schema to JSON template.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} schema JSON schema\r\n * @param {Record<string, any>} [container] template container\r\n *\r\n * @returns {unknown} object or default value\r\n */\r\nexport function schemaToJson(\r\n\tschema: Record<string, unknown>,\r\n\tcontainer: Record<string, any> = {},\r\n): unknown {\r\n\tif (isJsonSchemaObject(schema)) {\r\n\t\tfor (const key in schema.properties)\r\n\t\t\tcontainer[key] = schemaToJson(schema.properties[key]);\r\n\r\n\t\treturn container;\r\n\t} else {\r\n\t\treturn schema.default ?? (schema.nullable ? null : undefined);\r\n\t}\r\n}\r\n\r\n/**\r\n * Flatten a JSON schema.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} schema JSON schema\r\n * @param {string} [parentKey] previous level key\r\n * @param {string} [nestingDelimiter] char for delimit nesting levels\r\n * @param {Record<string, any>} [container] result container\r\n *\r\n * @returns {Record<string, unknown>} flattened schema\r\n */\r\nexport function flatSchema(\r\n\tschema: Record<string, unknown>,\r\n\tparentKey = '',\r\n\tnestingDelimiter = '__',\r\n\tcontainer: Record<string, any> = {},\r\n): Record<string, unknown> {\r\n\tif (isJsonSchemaObject(schema)) {\r\n\t\tfor (const key in schema.properties) {\r\n\t\t\tif (key[0] === '#') continue;\r\n\r\n\t\t\t// global property
|
|
1
|
+
{"version":3,"file":"schema.util.js","names":[],"sources":["../../src/utils/schema.util.ts"],"sourcesContent":["import type { Format, JSONSchemaType, ValidateFunction } from 'ajv';\r\nimport type { Options } from 'to-json-schema';\r\n\r\n// cached AJV instances (with and without formats)\r\nlet _ajv: any;\r\nlet _ajvWithFormats: any;\r\n\r\n// cached module references\r\nlet _AjvClass: any;\r\nlet _addFormats: any;\r\nlet _toJsonSchema: any;\r\n\r\n/* eslint-disable regexp/no-useless-assertions, regexp/no-super-linear-backtracking -- domain validation regexes from JSON Schema spec; modifying these patterns would change format validation behavior */\r\nconst FORMAT_REGEXPS: Record<string, Format> = {\r\n\t'ip-address':\r\n\t\t/^(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d{1,2})$/,\r\n\r\n\tcolor: /^(#?([\\dA-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\b\\s*,\\s*\\b(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\b\\s*,\\s*\\b(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/,\r\n\r\n\thostname:\r\n\t\t/^(?=.{1,255}$)[\\da-z](?:[\\da-z-]{0,61}[\\da-z])?(?:\\.[\\da-z](?:[\\da-z-]{0,61}[\\da-z])?)*\\.?$/i,\r\n\r\n\talphanumeric: /^[\\da-z]+$/i,\r\n\r\n\t'utc-millisec': (input: string) => !Number.isNaN(+input),\r\n\r\n\talpha: /^[a-z]+$/i,\r\n\r\n\tstyle: /\\s*(.+?):\\s*([^;]+);?/g,\r\n\r\n\tphone: /^\\+(?:\\d ?){6,14}\\d$/,\r\n};\r\n/* eslint-enable regexp/no-useless-assertions, regexp/no-super-linear-backtracking */\r\n\r\n/**\r\n * Generates JSON schema from JSON template/object.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} json json object\r\n * @param {Options} [options]\r\n *\r\n * @returns {*} {Promise<Record<string, unknown>>}\r\n */\r\nexport async function schemaFrom(\r\n\tjson: Record<string, unknown>,\r\n\toptions?: Options & { nullable?: boolean },\r\n): Promise<Record<string, unknown>> {\r\n\tif (!_toJsonSchema) {\r\n\t\tconst mod = await import('to-json-schema');\r\n\t\t_toJsonSchema = mod.default;\r\n\t}\r\n\r\n\treturn _toJsonSchema(json, {\r\n\t\trequired: false,\r\n\t\t...options,\r\n\t\tpostProcessFnc: (\r\n\t\t\ttype: string,\r\n\t\t\tschema: any,\r\n\t\t\tvalue: unknown,\r\n\t\t\tdefaultFunc: any,\r\n\t\t) => {\r\n\t\t\tif (value !== json) {\r\n\t\t\t\tschema.type = [type];\r\n\t\t\t\tschema.nullable = options?.nullable ?? false;\r\n\t\t\t}\r\n\r\n\t\t\tif (value === null || value === undefined) schema.nullable = true;\r\n\r\n\t\t\treturn defaultFunc(type, schema, value);\r\n\t\t},\r\n\t});\r\n}\r\n\r\n/**\r\n * Validates if a object is a JSON schema.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} schema\r\n *\r\n * @returns {boolean} if is a JSON schema\r\n */\r\nexport function isJsonSchemaObject(\r\n\tschema: Record<string, unknown>,\r\n): schema is JSONSchemaType<object> {\r\n\tif (schema.type === 'object') return true;\r\n\r\n\treturn (\r\n\t\tArray.isArray(schema.type) &&\r\n\t\t(schema.type as string[]).includes('object')\r\n\t);\r\n}\r\n\r\n/**\r\n * Converts a JSON schema to JSON template.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} schema JSON schema\r\n * @param {Record<string, any>} [container] template container\r\n *\r\n * @returns {unknown} object or default value\r\n */\r\nexport function schemaToJson(\r\n\tschema: Record<string, unknown>,\r\n\tcontainer: Record<string, any> = {},\r\n): unknown {\r\n\tif (isJsonSchemaObject(schema)) {\r\n\t\tfor (const key in schema.properties)\r\n\t\t\tcontainer[key] = schemaToJson(schema.properties[key]);\r\n\r\n\t\treturn container;\r\n\t} else {\r\n\t\treturn schema.default ?? (schema.nullable ? null : undefined);\r\n\t}\r\n}\r\n\r\n/**\r\n * Flatten a JSON schema.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} schema JSON schema\r\n * @param {string} [parentKey] previous level key\r\n * @param {string} [nestingDelimiter] char for delimit nesting levels\r\n * @param {Record<string, any>} [container] result container\r\n *\r\n * @returns {Record<string, unknown>} flattened schema\r\n */\r\nexport function flatSchema(\r\n\tschema: Record<string, unknown>,\r\n\tparentKey = '',\r\n\tnestingDelimiter = '__',\r\n\tcontainer: Record<string, any> = {},\r\n): Record<string, unknown> {\r\n\tif (isJsonSchemaObject(schema)) {\r\n\t\tfor (const key in schema.properties) {\r\n\t\t\tif (key[0] === '#') continue;\r\n\r\n\t\t\t// global property: strip the `$` marker so the flat schema key\r\n\t\t\t// matches the injected env key (which flatten/normalize also strip)\r\n\t\t\tconst cleanKey = key[0] === '$' ? key.slice(1) : key;\r\n\t\t\tconst subKey =\r\n\t\t\t\tparentKey + (parentKey ? nestingDelimiter : '') + cleanKey;\r\n\r\n\t\t\tcontainer = {\r\n\t\t\t\t...container,\r\n\t\t\t\t...flatSchema(schema.properties[key], subKey, nestingDelimiter),\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\treturn container;\r\n\t} else {\r\n\t\treturn { [parentKey]: schema };\r\n\t}\r\n}\r\n\r\n/**\r\n * Creates a JSON schema validator using AJV.\r\n *\r\n * @see https://ajv.js.org/\r\n *\r\n * @export\r\n * @param {Record<string, object>} schema json schema by provider\r\n * @param {boolean} enableFormats whether formats are enabled\r\n *\r\n * @returns {Promise<ValidateFunction>} validators\r\n */\r\nexport async function createValidator(\r\n\tschema: Record<string, unknown>,\r\n\tenableFormats = true,\r\n): Promise<ValidateFunction> {\r\n\tconst ajv = await getAjv(enableFormats);\r\n\r\n\treturn ajv.compile(schema);\r\n}\r\n\r\n/**\r\n * Creates a JSON schema validator lookup using AJV.\r\n *\r\n * @see https://ajv.js.org/\r\n *\r\n * @export\r\n * @param {Record<string, object>} schemaLookup json schema by provider\r\n * @param {boolean} enableFormats whether formats are enabled\r\n *\r\n * @returns {Promise<Record<string, ValidateFunction>>} validators lookup\r\n */\r\nexport async function createValidators(\r\n\tschemaLookup: Record<string, object>,\r\n\tenableFormats = true,\r\n): Promise<Record<string, ValidateFunction>> {\r\n\tconst ajv = await getAjv(enableFormats);\r\n\r\n\tconst validators: Record<string, ValidateFunction> = {};\r\n\r\n\tfor (const key in schemaLookup)\r\n\t\tvalidators[key] = ajv.compile(schemaLookup[key]);\r\n\r\n\treturn validators;\r\n}\r\n\r\n/**\r\n * Returns a cached AJV instance (lazy-loads ajv and ajv-formats on first call).\r\n *\r\n * @param {boolean} withFormats whether to include format validators\r\n * @returns {Promise<any>} cached AJV instance\r\n */\r\nasync function getAjv(withFormats: boolean): Promise<any> {\r\n\tif (!_AjvClass) {\r\n\t\tconst [ajvMod, formatsMod] = await Promise.all([\r\n\t\t\timport('ajv'),\r\n\t\t\timport('ajv-formats'),\r\n\t\t]);\r\n\t\t_AjvClass = ajvMod.Ajv;\r\n\t\t_addFormats = formatsMod.default;\r\n\t}\r\n\r\n\tif (withFormats) {\r\n\t\tif (!_ajvWithFormats) {\r\n\t\t\t_ajvWithFormats = new _AjvClass({\r\n\t\t\t\tallErrors: true,\r\n\t\t\t\tallowUnionTypes: true,\r\n\t\t\t});\r\n\r\n\t\t\t(\r\n\t\t\t\t_addFormats as unknown as (\r\n\t\t\t\t\tajv: any,\r\n\t\t\t\t\toptions?: { mode?: string },\r\n\t\t\t\t) => void\r\n\t\t\t)(_ajvWithFormats, { mode: 'fast' });\r\n\r\n\t\t\tfor (const key in FORMAT_REGEXPS)\r\n\t\t\t\t_ajvWithFormats.addFormat(key, FORMAT_REGEXPS[key]);\r\n\t\t}\r\n\r\n\t\treturn _ajvWithFormats;\r\n\t}\r\n\r\n\tif (!_ajv) {\r\n\t\t_ajv = new _AjvClass({\r\n\t\t\tallErrors: true,\r\n\t\t\tallowUnionTypes: true,\r\n\t\t});\r\n\t}\r\n\r\n\treturn _ajv;\r\n}\r\n"],"mappings":";AAIA,IAAI,GACA,GAGA,GACA,GACA,GAGE,IAAyC;CAC9C,cACC;CAED,OAAO;CAEP,UACC;CAED,cAAc;CAEd,iBAAiB,MAAkB,CAAC,OAAO,MAAM,CAAC,CAAK;CAEvD,OAAO;CAEP,OAAO;CAEP,OAAO;AACR;AAYA,eAAsB,EACrB,GACA,GACmC;CAMnC,OALA,AAEC,OAAgB,MADE,OAAO,mBACL,SAGd,EAAc,GAAM;EAC1B,UAAU;EACV,GAAG;EACH,iBACC,GACA,GACA,GACA,OAEI,MAAU,MACb,EAAO,OAAO,CAAC,CAAI,GACnB,EAAO,WAAW,GAAS,YAAY,KAGpC,MAAuC,EAAO,WAAW,KAEtD,EAAY,GAAM,GAAQ,CAAK;CAExC,CAAC;AACF;AAUA,SAAgB,EACf,GACmC;CAGnC,OAFI,EAAO,SAAS,WAAiB,KAGpC,MAAM,QAAQ,EAAO,IAAI,KACxB,EAAO,KAAkB,SAAS,QAAQ;AAE7C;AAWA,SAAgB,EACf,GACA,IAAiC,CAAC,GACxB;CACV,IAAI,EAAmB,CAAM,GAAG;EAC/B,KAAK,IAAM,KAAO,EAAO,YACxB,EAAU,KAAO,EAAa,EAAO,WAAW,EAAI;EAErD,OAAO;CACR,OACC,OAAO,EAAO,YAAY,EAAO,WAAW,OAAO,KAAA;AAErD;AAaA,SAAgB,EACf,GACA,IAAY,IACZ,IAAmB,MACnB,IAAiC,CAAC,GACR;CAC1B,IAAI,EAAmB,CAAM,GAAG;EAC/B,KAAK,IAAM,KAAO,EAAO,YAAY;GACpC,IAAI,EAAI,OAAO,KAAK;GAIpB,IAAM,IAAW,EAAI,OAAO,MAAM,EAAI,MAAM,CAAC,IAAI,GAC3C,IACL,KAAa,IAAY,IAAmB,MAAM;GAEnD,IAAY;IACX,GAAG;IACH,GAAG,EAAW,EAAO,WAAW,IAAM,GAAQ,CAAgB;GAC/D;EACD;EAEA,OAAO;CACR,OACC,OAAO,GAAG,IAAY,EAAO;AAE/B;AAaA,eAAsB,EACrB,GACA,IAAgB,IACY;CAG5B,QAAO,MAFW,EAAO,CAAa,GAE3B,QAAQ,CAAM;AAC1B;AAaA,eAAsB,EACrB,GACA,IAAgB,IAC4B;CAC5C,IAAM,IAAM,MAAM,EAAO,CAAa,GAEhC,IAA+C,CAAC;CAEtD,KAAK,IAAM,KAAO,GACjB,EAAW,KAAO,EAAI,QAAQ,EAAa,EAAI;CAEhD,OAAO;AACR;AAQA,eAAe,EAAO,GAAoC;CACzD,IAAI,CAAC,GAAW;EACf,IAAM,CAAC,GAAQ,KAAc,MAAM,QAAQ,IAAI,CAC9C,OAAO,QACP,OAAO,cACR,CAAC;EAED,AADA,IAAY,EAAO,KACnB,IAAc,EAAW;CAC1B;CAEA,IAAI,GAAa;EAChB,IAAI,CAAC,GAAiB;GAMrB,AALA,IAAkB,IAAI,EAAU;IAC/B,WAAW;IACX,iBAAiB;GAClB,CAAC,GAED,EAKE,GAAiB,EAAE,MAAM,OAAO,CAAC;GAEnC,KAAK,IAAM,KAAO,GACjB,EAAgB,UAAU,GAAK,EAAe,EAAI;EACpD;EAEA,OAAO;CACR;CASA,OAPA,AACC,MAAO,IAAI,EAAU;EACpB,WAAW;EACX,iBAAiB;CAClB,CAAC,GAGK;AACR"}
|
package/utils/ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../src/utils/ui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../src/utils/ui.ts"],"names":[],"mappings":"AA8GA,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,eAAO,MAAM,EAAE;oBACE,MAAM,QAAQ,MAAM,UAAU,MAAM,EAAE,GAAG,IAAI;kBAY/C,MAAM,SAAS,MAAM,GAAG,IAAI;IAS1C,6EAA6E;mBAC9D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;mBAqC9B,MAAM,MAAM,MAAM,GAAG,IAAI;qBAQvB,MAAM,GAAG,IAAI;iBAMjB,MAAM,GAAG,IAAI;iBAKb,MAAM,GAAG,IAAI;kBAKZ,MAAM,WAAW,MAAM,GAAG,IAAI;CAG5C,CAAC"}
|
package/utils/ui.js
CHANGED
|
@@ -6,70 +6,93 @@ var r = {
|
|
|
6
6
|
local: "๐",
|
|
7
7
|
"package-json": "๐ฆ",
|
|
8
8
|
secrets: "๐"
|
|
9
|
-
};
|
|
10
|
-
function
|
|
9
|
+
}, i = String.fromCodePoint(27);
|
|
10
|
+
function a(n) {
|
|
11
11
|
return (t.settings.minLevel ?? e.info) <= n;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
13
|
+
function o(t = "", n = e.info) {
|
|
14
|
+
a(n) && process.stdout.write(`${t}\n`);
|
|
15
|
+
}
|
|
16
|
+
function s(e) {
|
|
17
|
+
let t = /* @__PURE__ */ new Set(), n = [];
|
|
18
|
+
for (let r of e) {
|
|
19
|
+
let e = /^\/(.*)\/([a-z]*)$/s.exec(r);
|
|
20
|
+
e ? n.push(new RegExp(e[1], e[2])) : t.add(r.toLowerCase());
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
exact: t,
|
|
24
|
+
patterns: n
|
|
25
|
+
};
|
|
15
26
|
}
|
|
16
|
-
function
|
|
17
|
-
let { maskPlaceholder:
|
|
18
|
-
if (
|
|
27
|
+
function c(e, n, r) {
|
|
28
|
+
let { maskPlaceholder: i = "***", maskValuesRegEx: a = [] } = t.settings;
|
|
29
|
+
if (r.exact.has(e.toLowerCase()) || r.patterns.some((t) => t.test(e))) return {
|
|
19
30
|
masked: !0,
|
|
20
|
-
value:
|
|
31
|
+
value: i
|
|
21
32
|
};
|
|
22
33
|
let o = !1, s = n;
|
|
23
34
|
for (let e of a) {
|
|
24
|
-
let t = s.
|
|
25
|
-
|
|
35
|
+
let t = e.flags.includes("g") ? e.flags : `${e.flags}g`, n = s.replace(new RegExp(e.source, t), i);
|
|
36
|
+
n !== s && (o = !0), s = n;
|
|
26
37
|
}
|
|
27
38
|
return {
|
|
28
39
|
masked: o,
|
|
29
40
|
value: s
|
|
30
41
|
};
|
|
31
42
|
}
|
|
32
|
-
function
|
|
43
|
+
function l(e) {
|
|
44
|
+
return n.isColorSupported ? `${i}[38;5;208m${e}${i}[39m` : e;
|
|
45
|
+
}
|
|
46
|
+
function u(e, t) {
|
|
47
|
+
switch (typeof e) {
|
|
48
|
+
case "bigint":
|
|
49
|
+
case "number": return l(t);
|
|
50
|
+
case "boolean": return e ? n.green(t) : n.red(t);
|
|
51
|
+
case "string": return n.gray(t);
|
|
52
|
+
default: return n.dim(t);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function d(e) {
|
|
33
56
|
return e < 1e3 ? `${Math.round(e)}ms` : `${(e / 1e3).toFixed(1)}s`;
|
|
34
57
|
}
|
|
35
|
-
var
|
|
58
|
+
var f = {
|
|
36
59
|
header(e, t, r) {
|
|
37
60
|
let i = [n.bold("โก env") + n.dim(` v${e}`)];
|
|
38
|
-
t && i.push(`๐ ${n.bold(n.green(t))}`), r && r.length > 0 && i.push(`๐งฉ ${n.magenta(r.join("+"))}`),
|
|
61
|
+
t && i.push(`๐ ${n.bold(n.green(t))}`), r && r.length > 0 && i.push(`๐งฉ ${n.magenta(r.join("+"))}`), o(), o(i.join(n.dim(" ยท "))), o();
|
|
39
62
|
},
|
|
40
63
|
provider(e, t) {
|
|
41
|
-
let i = r[e] ?? "๐งฉ",
|
|
42
|
-
|
|
64
|
+
let i = r[e] ?? "๐งฉ", a = e === "secrets" ? "secrets" : "vars";
|
|
65
|
+
o(` ${i} ${n.cyan(e.padEnd(16))} ${n.bold(String(t))} ${n.dim(a)}`);
|
|
43
66
|
},
|
|
44
|
-
variables(
|
|
45
|
-
if (!
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
for (let [t,
|
|
49
|
-
let { masked:
|
|
50
|
-
|
|
67
|
+
variables(r) {
|
|
68
|
+
if (!a(e.debug)) return;
|
|
69
|
+
let i = Object.entries(r).sort(([e], [t]) => e.localeCompare(t)), l = i.reduce((e, [t]) => Math.max(e, t.length), 0), d = n.dim(`environment (${i.length} variables)`), f = s(t.settings.maskValuesOfKeys ?? []);
|
|
70
|
+
o(` ${d}`, e.debug);
|
|
71
|
+
for (let [t, r] of i) {
|
|
72
|
+
let { masked: i, value: a } = c(t, String(r), f), s = i ? n.yellow(a) : u(r, a);
|
|
73
|
+
o(` ${n.cyan(t.padEnd(l))} ${n.dim("=")} ${s}`, e.debug);
|
|
51
74
|
}
|
|
52
|
-
|
|
75
|
+
o("", e.debug);
|
|
53
76
|
},
|
|
54
77
|
summary(e, t) {
|
|
55
|
-
let r = n.dim(`in ${
|
|
56
|
-
|
|
78
|
+
let r = n.dim(`in ${d(t)}`);
|
|
79
|
+
o(), o(` ${n.green("โ")} ${n.bold(String(e))} variables loaded ${r}`);
|
|
57
80
|
},
|
|
58
81
|
running(e) {
|
|
59
|
-
|
|
82
|
+
o(), o(` ${n.yellow("โถ")} ${n.bold(e)}`), o();
|
|
60
83
|
},
|
|
61
84
|
finished(e) {
|
|
62
|
-
let t = n.dim(`finished in ${
|
|
63
|
-
|
|
85
|
+
let t = n.dim(`finished in ${d(e)}`);
|
|
86
|
+
o(` ${n.green("โ")} ${t}`);
|
|
64
87
|
},
|
|
65
88
|
failed(e) {
|
|
66
|
-
|
|
89
|
+
o(` ${n.red(`โ exited with code ${e}`)}`);
|
|
67
90
|
},
|
|
68
91
|
action(e, t) {
|
|
69
|
-
|
|
92
|
+
o(` ${e} ${t}`);
|
|
70
93
|
}
|
|
71
94
|
};
|
|
72
95
|
//#endregion
|
|
73
|
-
export {
|
|
96
|
+
export { d as formatDuration, f as ui };
|
|
74
97
|
|
|
75
98
|
//# sourceMappingURL=ui.js.map
|