@calvear/env 3.0.1 โ 3.1.1
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/env.command.js.map +1 -1
- 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/exec.js.map +1 -1
- package/main.js.map +1 -1
- package/package.json +109 -108
- package/providers/app-settings.provider.js.map +1 -1
- package/providers/index.js.map +1 -1
- package/providers/secrets.provider.js.map +1 -1
- package/schemas/env.schema.json +40 -36
- package/schemas/settings.schema.json +2 -2
- package/utils/argv.util.js.map +1 -1
- package/utils/command.util.js.map +1 -1
- package/utils/interpolate.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/schemas/env.schema.json
CHANGED
|
@@ -4,16 +4,11 @@
|
|
|
4
4
|
"description": "appsettings.json schema definition.",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"additionalProperties": false,
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"description": "
|
|
10
|
-
"type": "string"
|
|
11
|
-
},
|
|
12
|
-
"|DEFAULT|": {
|
|
13
|
-
"description": "Default basis environment variables.",
|
|
14
|
-
"title": "AppSettings Default Environment",
|
|
15
|
-
"additionalProperties": false,
|
|
7
|
+
"definitions": {
|
|
8
|
+
"flatVariables": {
|
|
9
|
+
"description": "Flat set of environment variables.",
|
|
16
10
|
"type": "object",
|
|
11
|
+
"additionalProperties": false,
|
|
17
12
|
"default": {},
|
|
18
13
|
"patternProperties": {
|
|
19
14
|
"^.*$": {
|
|
@@ -21,91 +16,100 @@
|
|
|
21
16
|
{ "type": "array" },
|
|
22
17
|
{ "type": "object" },
|
|
23
18
|
{ "type": "string" },
|
|
19
|
+
{ "type": "number" },
|
|
24
20
|
{ "type": "boolean" },
|
|
25
21
|
{ "type": "null" }
|
|
26
22
|
]
|
|
27
23
|
}
|
|
28
24
|
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"properties": {
|
|
28
|
+
"$schema": {
|
|
29
|
+
"description": "Environment appsettings schema definition.",
|
|
30
|
+
"type": "string"
|
|
31
|
+
},
|
|
32
|
+
"|DEFAULT|": {
|
|
33
|
+
"description": "Default basis environment variables.",
|
|
34
|
+
"title": "AppSettings Default Env",
|
|
35
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
29
36
|
},
|
|
30
37
|
"|MODE|": {
|
|
31
38
|
"description": "Environment variables loaded by mode argument (-m or --mode). Used for execution modes, like 'debug', 'test', 'build', 'packing', or any you need.",
|
|
32
39
|
"title": "AppSettings Modes",
|
|
33
|
-
"additionalProperties": true,
|
|
34
40
|
"type": "object",
|
|
35
41
|
"default": {},
|
|
42
|
+
"additionalProperties": { "$ref": "#/definitions/flatVariables" },
|
|
36
43
|
"properties": {
|
|
37
44
|
"debug": {
|
|
38
45
|
"description": "Variables used for 'debug' local execution.",
|
|
39
|
-
"
|
|
40
|
-
"default": {}
|
|
46
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
41
47
|
},
|
|
42
48
|
"build": {
|
|
43
49
|
"description": "Variables used for 'build' operation.",
|
|
44
|
-
"
|
|
45
|
-
"default": {}
|
|
50
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
46
51
|
},
|
|
47
52
|
"test": {
|
|
48
53
|
"description": "Variables used for 'test' execution.",
|
|
49
|
-
"
|
|
50
|
-
"default": {}
|
|
54
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
},
|
|
54
58
|
"|ENV|": {
|
|
55
59
|
"description": "Environment variables loaded by environment argument (-e or --env). Used for environment selected, like 'dev', 'qa', 'stg', 'prod', or any you need.",
|
|
56
|
-
"title": "AppSettings
|
|
57
|
-
"additionalProperties": true,
|
|
60
|
+
"title": "AppSettings Env",
|
|
58
61
|
"type": "object",
|
|
59
62
|
"default": {},
|
|
63
|
+
"additionalProperties": { "$ref": "#/definitions/flatVariables" },
|
|
60
64
|
"properties": {
|
|
65
|
+
"local": {
|
|
66
|
+
"description": "Variables for 'local' environment.",
|
|
67
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
68
|
+
},
|
|
61
69
|
"dev": {
|
|
62
70
|
"description": "Variables for 'development' environment.",
|
|
63
|
-
"
|
|
64
|
-
"default": {}
|
|
71
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
65
72
|
},
|
|
66
73
|
"qa": {
|
|
67
74
|
"description": "Variables for 'quality assurance' environment.",
|
|
68
|
-
"
|
|
69
|
-
"default": {}
|
|
75
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
70
76
|
},
|
|
71
77
|
"stg": {
|
|
72
78
|
"description": "Variables for 'staging' environment.",
|
|
73
|
-
"
|
|
74
|
-
"default": {}
|
|
79
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
75
80
|
},
|
|
76
81
|
"prod": {
|
|
77
82
|
"description": "Variables for 'production' environment.",
|
|
78
|
-
"
|
|
79
|
-
"default": {}
|
|
83
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
},
|
|
83
87
|
"|LOCAL|": {
|
|
84
88
|
"description": "Environment variables loaded by environment argument (-e or --env) but locally only. Used for local environment needs",
|
|
85
|
-
"title": "AppSettings Local
|
|
86
|
-
"additionalProperties": true,
|
|
89
|
+
"title": "AppSettings Local Env",
|
|
87
90
|
"type": "object",
|
|
88
91
|
"default": {},
|
|
92
|
+
"additionalProperties": { "$ref": "#/definitions/flatVariables" },
|
|
89
93
|
"properties": {
|
|
94
|
+
"local": {
|
|
95
|
+
"description": "Variables for 'local' environment.",
|
|
96
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
97
|
+
},
|
|
90
98
|
"dev": {
|
|
91
99
|
"description": "Variables for 'development' environment in local execution.",
|
|
92
|
-
"
|
|
93
|
-
"default": {}
|
|
100
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
94
101
|
},
|
|
95
102
|
"qa": {
|
|
96
103
|
"description": "Variables for 'quality assurance' environment in local execution.",
|
|
97
|
-
"
|
|
98
|
-
"default": {}
|
|
104
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
99
105
|
},
|
|
100
106
|
"stg": {
|
|
101
107
|
"description": "Variables for 'staging' environment in local execution.",
|
|
102
|
-
"
|
|
103
|
-
"default": {}
|
|
108
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
104
109
|
},
|
|
105
110
|
"prod": {
|
|
106
111
|
"description": "Variables for 'production' environment in local execution.",
|
|
107
|
-
"
|
|
108
|
-
"default": {}
|
|
112
|
+
"allOf": [{ "$ref": "#/definitions/flatVariables" }]
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
}
|
|
@@ -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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.util.js","names":[],"sources":["../../src/utils/command.util.ts"],"sourcesContent":["import merge from 'merge-deep';\r\nimport { readFileSync } from 'node:fs';\r\nimport Path from 'node:path';\r\nimport pc from 'picocolors';\r\nimport type { Arguments } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport type { EnvCommandArguments } from '../commands/env.command.js';\r\nimport type {\r\n\tEnvProviderConfig,\r\n\tEnvProviderResult,\r\n} from '../interfaces/index.js';\r\nimport {\r\n\tcreateValidators,\r\n\tflatten,\r\n\tinterpolate,\r\n\tlogger,\r\n\treadJson,\r\n\tschemaFrom,\r\n\twriteJson,\r\n} from './index.js';\r\n\r\n/**\r\n * Injects config to command arguments from file.\r\n *\r\n * @param {Record<string, unknown>} argv\r\n * @param {[string, string]} delimiters\r\n */\r\nexport async function loadConfigFile(\r\n\targv: Record<string, unknown>,\r\n\tdelimiters: [string, string],\r\n): Promise<void> {\r\n\tif (typeof argv.configFile === 'string') {\r\n\t\tconst path = interpolate(argv.configFile, argv, delimiters);\r\n\t\tconst [config, success] = await readJson(path);\r\n\r\n\t\tif (success) for (const key in config) argv[key] ??= config[key];\r\n\t}\r\n}\r\n\r\n/**\r\n * Extracts subcommand from command line parameters.\r\n *\r\n * @export\r\n * @param {string[]} rawArgv process.argv.slice(2)\r\n * @param {[string, string]} delimiters\r\n *\r\n * @returns {string[]} subcommand for wrap if exists\r\n */\r\nexport function getSubcommand(rawArgv: string[], delimiters: [string, string]) {\r\n\tlet subcommand: string[] = [];\r\n\r\n\t// subcommand delimiter indexes\r\n\r\n\tconst begin = rawArgv.indexOf(delimiters[0]);\r\n\r\n\tconst count = rawArgv.lastIndexOf(delimiters[1]) - begin;\r\n\r\n\t// calculates subcommand surrounded by delimiters\r\n\tif (begin > 0) {\r\n\t\tsubcommand =\r\n\t\t\tcount > 0\r\n\t\t\t\t? rawArgv.splice(begin, count + 1).slice(1, -1)\r\n\t\t\t\t: rawArgv.splice(begin).slice(1);\r\n\t}\r\n\r\n\treturn subcommand;\r\n}\r\n\r\n/**\r\n * Loads providers JSON schema from file.\r\n *\r\n * @param {Record<string, unknown>} argv\r\n * @param {[string, string]} delimiters\r\n *\r\n * @returns {Promise<Record<string, unknown>>}\r\n */\r\nexport async function loadSchemaFile(\r\n\targv: Record<string, unknown>,\r\n\tdelimiters: [string, string],\r\n): Promise<Record<string, unknown> | undefined> {\r\n\tif (typeof argv.schemaFile === 'string') {\r\n\t\tconst path = interpolate(argv.schemaFile, argv, delimiters);\r\n\t\tconst [schema, success] = await readJson(path);\r\n\r\n\t\treturn success ? schema : undefined;\r\n\t}\r\n\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Reads project package.json.\r\n *\r\n * @export\r\n * @returns {Promise<Record<string, unknown>> | never}\r\n */\r\nexport function loadProjectInfo(\r\n\trelativePath = '',\r\n): Promise<Record<string, unknown>> {\r\n\ttry {\r\n\t\tconst filePath = Path.join(process.cwd(), relativePath, 'package.json');\r\n\r\n\t\treturn Promise.resolve(\r\n\t\t\tJSON.parse(readFileSync(filePath, 'utf8')) as Record<\r\n\t\t\t\tstring,\r\n\t\t\t\tunknown\r\n\t\t\t>,\r\n\t\t);\r\n\t} catch {\r\n\t\tlogger.warn(\r\n\t\t\t`project file ${pc.underline(pc.yellow('package.json'))} not found`,\r\n\t\t);\r\n\r\n\t\treturn Promise.resolve({});\r\n\t}\r\n}\r\n\r\n/**\r\n * Executes load functions from provider handlers.\r\n *\r\n * @param {EnvProviderConfig[]} providers\r\n * @param {Partial<Arguments<EnvCommandArguments>>} argv\r\n *\r\n * @returns {EnvProviderResult[]}\r\n */\r\nexport function loadVariablesFromProviders(\r\n\tproviders: EnvProviderConfig[],\r\n\targv: Partial<Arguments<EnvCommandArguments>>,\r\n): Promise<EnvProviderResult[]> {\r\n\tif (!providers) return Promise.resolve([]) as Promise<EnvProviderResult[]>;\r\n\r\n\treturn Promise.all(\r\n\t\tproviders.map(async ({ config, handler: { key, load } }) => {\r\n\t\t\tlogger.silly(`executing ${pc.yellow(key)} provider`);\r\n\r\n\t\t\tconst value = await load(argv, config);\r\n\r\n\t\t\treturn { config, key, value };\r\n\t\t}),\r\n\t);\r\n}\r\n\r\n/**\r\n * Flattern environment provider results.\r\n *\r\n * @param {EnvProviderResult[]} results\r\n * @param {Partial<Arguments<EnvCommandArguments>>} argv\r\n *\r\n * @throws {Error} on schema validation failed\r\n *\r\n * @returns {EnvProviderResult[]} flatten results\r\n */\r\nexport function flatResults(\r\n\tresults: EnvProviderResult[],\r\n\tnestingDelimiter = '__',\r\n): EnvProviderResult[] | never {\r\n\treturn results.flatMap(({ value }) => {\r\n\t\tif (Array.isArray(value))\r\n\t\t\treturn merge({}, ...value.map((v) => flatten(v, nestingDelimiter)));\r\n\r\n\t\treturn flatten(value, nestingDelimiter);\r\n\t});\r\n}\r\n\r\n/**\r\n * Flattern and validates environment provider results.\r\n *\r\n * @param {EnvProviderResult[]} results\r\n * @param {Partial<Arguments<EnvCommandArguments>>} argv\r\n *\r\n * @throws {Error} on schema validation failed\r\n *\r\n * @returns {EnvProviderResult[]}\r\n */\r\nexport async function flatAndValidateResults(\r\n\tresults: EnvProviderResult[],\r\n\targv: Partial<Arguments<EnvCommandArguments>>,\r\n): Promise<EnvProviderResult[]> {\r\n\tif (!argv.schemaValidate)\r\n\t\treturn flatResults(results, argv.nestingDelimiter);\r\n\r\n\tconst validators = await createValidators(argv.schema!, argv.detectFormat);\r\n\r\n\treturn results.flatMap(({ key, value }) => {\r\n\t\tlet baseValue = value;\r\n\t\tif (Array.isArray(value)) {\r\n\t\t\tvalue = merge({}, ...value);\r\n\t\t\tbaseValue = merge(\r\n\t\t\t\t{},\r\n\t\t\t\t...baseValue.map((v: any) => flatten(v, argv.nestingDelimiter)),\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tbaseValue = flatten(value, argv.nestingDelimiter);\r\n\t\t}\r\n\r\n\t\tconst validator = validators![key];\r\n\r\n\t\tif (!validator || validator?.(value)) return baseValue;\r\n\r\n\t\tlogger.error(\r\n\t\t\t`schema validation failed for ${pc.yellow(key)}`,\r\n\t\t\tvalidator?.errors,\r\n\t\t);\r\n\r\n\t\tthrow new Error(`schema validation failed for ${key}`);\r\n\t});\r\n}\r\n\r\n/**\r\n * Creates or updates JSON schema from\r\n * environment variables grouped by provider key.\r\n *\r\n * @export\r\n * @param {EnvProviderResult[]} env\r\n * @param {Arguments<EnvCommandArguments>} argv\r\n *\r\n * @returns {Promise<object>} JSON schema grouped by provider key.\r\n */\r\nexport async function generateSchemaFrom(\r\n\tenv: EnvProviderResult[],\r\n\targv: Arguments<CommandArguments>,\r\n): Promise<object> {\r\n\tconst { detectFormat, nullable, resolve, schemaFile } = argv;\r\n\r\n\t// generates schemas from providers results\r\n\tconst schemaEntries: Record<string, unknown> = {};\r\n\tfor (const { key, value } of env) {\r\n\t\tconst merged = Array.isArray(value) ? merge({}, ...value) : value;\r\n\r\n\t\tschemaEntries[key] = await schemaFrom(merged, {\r\n\t\t\tnullable,\r\n\t\t\tstrings: { detectFormat },\r\n\t\t});\r\n\t}\r\n\r\n\tlet schema: Record<string, unknown> = schemaEntries;\r\n\r\n\tif (resolve === 'merge') schema = merge(argv.schema, schema);\r\n\r\n\tawait writeJson(schemaFile, schema, true);\r\n\r\n\treturn schema;\r\n}\r\n"],"mappings":";;;;;;;;;;;AA2BA,eAAsB,EACrB,GACA,GACgB;CAChB,IAAI,OAAO,EAAK,cAAe,UAAU;EAExC,IAAM,CAAC,GAAQ,KAAW,MAAM,EADnB,EAAY,EAAK,YAAY,GAAM,CACP,CAAI;EAE7C,IAAI,GAAS,KAAK,IAAM,KAAO,GAAQ,EAAK,OAAS,EAAO;CAC7D;AACD;AAWA,SAAgB,EAAc,GAAmB,GAA8B;CAC9E,IAAI,IAAuB,CAAC,GAItB,IAAQ,EAAQ,QAAQ,EAAW,EAAE,GAErC,IAAQ,EAAQ,YAAY,EAAW,EAAE,IAAI;CAUnD,OAPI,IAAQ,MACX,IACC,IAAQ,IACL,EAAQ,OAAO,GAAO,IAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"command.util.js","names":[],"sources":["../../src/utils/command.util.ts"],"sourcesContent":["import merge from 'merge-deep';\r\nimport { readFileSync } from 'node:fs';\r\nimport Path from 'node:path';\r\nimport pc from 'picocolors';\r\nimport type { Arguments } from 'yargs';\r\nimport type { CommandArguments } from '../arguments.js';\r\nimport type { EnvCommandArguments } from '../commands/env.command.js';\r\nimport type {\r\n\tEnvProviderConfig,\r\n\tEnvProviderResult,\r\n} from '../interfaces/index.js';\r\nimport {\r\n\tcreateValidators,\r\n\tflatten,\r\n\tinterpolate,\r\n\tlogger,\r\n\treadJson,\r\n\tschemaFrom,\r\n\twriteJson,\r\n} from './index.js';\r\n\r\n/**\r\n * Injects config to command arguments from file.\r\n *\r\n * @param {Record<string, unknown>} argv\r\n * @param {[string, string]} delimiters\r\n */\r\nexport async function loadConfigFile(\r\n\targv: Record<string, unknown>,\r\n\tdelimiters: [string, string],\r\n): Promise<void> {\r\n\tif (typeof argv.configFile === 'string') {\r\n\t\tconst path = interpolate(argv.configFile, argv, delimiters);\r\n\t\tconst [config, success] = await readJson(path);\r\n\r\n\t\tif (success) for (const key in config) argv[key] ??= config[key];\r\n\t}\r\n}\r\n\r\n/**\r\n * Extracts subcommand from command line parameters.\r\n *\r\n * @export\r\n * @param {string[]} rawArgv process.argv.slice(2)\r\n * @param {[string, string]} delimiters\r\n *\r\n * @returns {string[]} subcommand for wrap if exists\r\n */\r\nexport function getSubcommand(rawArgv: string[], delimiters: [string, string]) {\r\n\tlet subcommand: string[] = [];\r\n\r\n\t// subcommand delimiter indexes\r\n\r\n\tconst begin = rawArgv.indexOf(delimiters[0]);\r\n\r\n\tconst count = rawArgv.lastIndexOf(delimiters[1]) - begin;\r\n\r\n\t// calculates subcommand surrounded by delimiters\r\n\tif (begin > 0) {\r\n\t\tsubcommand =\r\n\t\t\tcount > 0\r\n\t\t\t\t? rawArgv.splice(begin, count + 1).slice(1, -1)\r\n\t\t\t\t: rawArgv.splice(begin).slice(1);\r\n\t}\r\n\r\n\treturn subcommand;\r\n}\r\n\r\n/**\r\n * Loads providers JSON schema from file.\r\n *\r\n * @param {Record<string, unknown>} argv\r\n * @param {[string, string]} delimiters\r\n *\r\n * @returns {Promise<Record<string, unknown>>}\r\n */\r\nexport async function loadSchemaFile(\r\n\targv: Record<string, unknown>,\r\n\tdelimiters: [string, string],\r\n): Promise<Record<string, unknown> | undefined> {\r\n\tif (typeof argv.schemaFile === 'string') {\r\n\t\tconst path = interpolate(argv.schemaFile, argv, delimiters);\r\n\t\tconst [schema, success] = await readJson(path);\r\n\r\n\t\treturn success ? schema : undefined;\r\n\t}\r\n\r\n\treturn undefined;\r\n}\r\n\r\n/**\r\n * Reads project package.json.\r\n *\r\n * @export\r\n * @returns {Promise<Record<string, unknown>> | never}\r\n */\r\nexport function loadProjectInfo(\r\n\trelativePath = '',\r\n): Promise<Record<string, unknown>> {\r\n\ttry {\r\n\t\tconst filePath = Path.join(process.cwd(), relativePath, 'package.json');\r\n\r\n\t\treturn Promise.resolve(\r\n\t\t\tJSON.parse(readFileSync(filePath, 'utf8')) as Record<\r\n\t\t\t\tstring,\r\n\t\t\t\tunknown\r\n\t\t\t>,\r\n\t\t);\r\n\t} catch {\r\n\t\tlogger.warn(\r\n\t\t\t`project file ${pc.underline(pc.yellow('package.json'))} not found`,\r\n\t\t);\r\n\r\n\t\treturn Promise.resolve({});\r\n\t}\r\n}\r\n\r\n/**\r\n * Executes load functions from provider handlers.\r\n *\r\n * @param {EnvProviderConfig[]} providers\r\n * @param {Partial<Arguments<EnvCommandArguments>>} argv\r\n *\r\n * @returns {EnvProviderResult[]}\r\n */\r\nexport function loadVariablesFromProviders(\r\n\tproviders: EnvProviderConfig[],\r\n\targv: Partial<Arguments<EnvCommandArguments>>,\r\n): Promise<EnvProviderResult[]> {\r\n\tif (!providers) return Promise.resolve([]) as Promise<EnvProviderResult[]>;\r\n\r\n\treturn Promise.all(\r\n\t\tproviders.map(async ({ config, handler: { key, load } }) => {\r\n\t\t\tlogger.silly(`executing ${pc.yellow(key)} provider`);\r\n\r\n\t\t\tconst value = await load(argv, config);\r\n\r\n\t\t\treturn { config, key, value };\r\n\t\t}),\r\n\t);\r\n}\r\n\r\n/**\r\n * Flattern environment provider results.\r\n *\r\n * @param {EnvProviderResult[]} results\r\n * @param {Partial<Arguments<EnvCommandArguments>>} argv\r\n *\r\n * @throws {Error} on schema validation failed\r\n *\r\n * @returns {EnvProviderResult[]} flatten results\r\n */\r\nexport function flatResults(\r\n\tresults: EnvProviderResult[],\r\n\tnestingDelimiter = '__',\r\n): EnvProviderResult[] | never {\r\n\treturn results.flatMap(({ value }) => {\r\n\t\tif (Array.isArray(value))\r\n\t\t\treturn merge({}, ...value.map((v) => flatten(v, nestingDelimiter)));\r\n\r\n\t\treturn flatten(value, nestingDelimiter);\r\n\t});\r\n}\r\n\r\n/**\r\n * Flattern and validates environment provider results.\r\n *\r\n * @param {EnvProviderResult[]} results\r\n * @param {Partial<Arguments<EnvCommandArguments>>} argv\r\n *\r\n * @throws {Error} on schema validation failed\r\n *\r\n * @returns {EnvProviderResult[]}\r\n */\r\nexport async function flatAndValidateResults(\r\n\tresults: EnvProviderResult[],\r\n\targv: Partial<Arguments<EnvCommandArguments>>,\r\n): Promise<EnvProviderResult[]> {\r\n\tif (!argv.schemaValidate)\r\n\t\treturn flatResults(results, argv.nestingDelimiter);\r\n\r\n\tconst validators = await createValidators(argv.schema!, argv.detectFormat);\r\n\r\n\treturn results.flatMap(({ key, value }) => {\r\n\t\tlet baseValue = value;\r\n\t\tif (Array.isArray(value)) {\r\n\t\t\tvalue = merge({}, ...value);\r\n\t\t\tbaseValue = merge(\r\n\t\t\t\t{},\r\n\t\t\t\t...baseValue.map((v: any) => flatten(v, argv.nestingDelimiter)),\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tbaseValue = flatten(value, argv.nestingDelimiter);\r\n\t\t}\r\n\r\n\t\tconst validator = validators![key];\r\n\r\n\t\tif (!validator || validator?.(value)) return baseValue;\r\n\r\n\t\tlogger.error(\r\n\t\t\t`schema validation failed for ${pc.yellow(key)}`,\r\n\t\t\tvalidator?.errors,\r\n\t\t);\r\n\r\n\t\tthrow new Error(`schema validation failed for ${key}`);\r\n\t});\r\n}\r\n\r\n/**\r\n * Creates or updates JSON schema from\r\n * environment variables grouped by provider key.\r\n *\r\n * @export\r\n * @param {EnvProviderResult[]} env\r\n * @param {Arguments<EnvCommandArguments>} argv\r\n *\r\n * @returns {Promise<object>} JSON schema grouped by provider key.\r\n */\r\nexport async function generateSchemaFrom(\r\n\tenv: EnvProviderResult[],\r\n\targv: Arguments<CommandArguments>,\r\n): Promise<object> {\r\n\tconst { detectFormat, nullable, resolve, schemaFile } = argv;\r\n\r\n\t// generates schemas from providers results\r\n\tconst schemaEntries: Record<string, unknown> = {};\r\n\tfor (const { key, value } of env) {\r\n\t\tconst merged = Array.isArray(value) ? merge({}, ...value) : value;\r\n\r\n\t\tschemaEntries[key] = await schemaFrom(merged, {\r\n\t\t\tnullable,\r\n\t\t\tstrings: { detectFormat },\r\n\t\t});\r\n\t}\r\n\r\n\tlet schema: Record<string, unknown> = schemaEntries;\r\n\r\n\tif (resolve === 'merge') schema = merge(argv.schema, schema);\r\n\r\n\tawait writeJson(schemaFile, schema, true);\r\n\r\n\treturn schema;\r\n}\r\n"],"mappings":";;;;;;;;;;;AA2BA,eAAsB,EACrB,GACA,GACgB;CAChB,IAAI,OAAO,EAAK,cAAe,UAAU;EAExC,IAAM,CAAC,GAAQ,KAAW,MAAM,EADnB,EAAY,EAAK,YAAY,GAAM,CACP,CAAI;EAE7C,IAAI,GAAS,KAAK,IAAM,KAAO,GAAQ,EAAK,OA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n * Validates value must be a record.\r\n *\r\n * @export\r\n * @param {unknown} obj\r\n * @returns {*} {obj is Record<string, unknown>}\r\n */\r\nexport function isRecord(obj: unknown): obj is Record<string, unknown> {\r\n\tif (!obj || typeof obj !== 'object') return false;\r\n\r\n\treturn Object.keys(obj).length > 0;\r\n}\r\n\r\n/**\r\n * Replaces string arguments with regex interpolation.\r\n *\r\n * @export\r\n * @template T\r\n * @param {T} value\r\n * @param {Record<string, unknown>} args\r\n * @param {[string, string]} [delimiters=['[[', ']]']]\r\n *\r\n * @returns {T} mutated value\r\n */\r\nexport function interpolate<T>(\r\n\tvalue: T,\r\n\targs: Record<string, unknown>,\r\n\tdelimiters: [string, string] = ['[[', ']]'],\r\n): T {\r\n\tif (typeof value === 'string') {\r\n\t\tif (!value.includes(delimiters[0])) return value as T;\r\n\r\n\t\treturn subslate(value, args, {\r\n\t\t\tstartStopPairs: delimiters,\r\n\t\t}) as T;\r\n\t}\r\n\r\n\tif (Array.isArray(value))\r\n\t\treturn value.map((a) => interpolate(a, args, delimiters)) as T;\r\n\r\n\tif (isRecord(value)) return interpolateJson(value, args, delimiters) as T;\r\n\r\n\treturn value;\r\n}\r\n\r\n/**\r\n * Replaces JSON string arguments with regex interpolation.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} args\r\n * @param {Record<string, unknown>} values\r\n * @param {[string, string]} [delimiters=['[[', ']]']]\r\n *\r\n * @returns {Record<string, unknown>} mutated args\r\n */\r\nexport function interpolateJson(\r\n\tvalues: Record<string, unknown>,\r\n\targs: Record<string, unknown>,\r\n\tdelimiters: [string, string] = ['[[', ']]'],\r\n): Record<string, unknown> {\r\n\tfor (const key in values)\r\n\t\tvalues[key] = interpolate(values[key], args, delimiters);\r\n\r\n\treturn values;\r\n}\r\n"],"mappings":";;AASA,SAAgB,EAAS,GAA8C;CAGtE,OAFI,CAAC,KAAO,OAAO,KAAQ,WAAiB,KAErC,OAAO,KAAK,CAAG,
|
|
1
|
+
{"version":3,"file":"interpolate.util.js","names":[],"sources":["../../src/utils/interpolate.util.ts"],"sourcesContent":["import subslate from 'subslate';\r\n\r\n/**\r\n * Validates value must be a record.\r\n *\r\n * @export\r\n * @param {unknown} obj\r\n * @returns {*} {obj is Record<string, unknown>}\r\n */\r\nexport function isRecord(obj: unknown): obj is Record<string, unknown> {\r\n\tif (!obj || typeof obj !== 'object') return false;\r\n\r\n\treturn Object.keys(obj).length > 0;\r\n}\r\n\r\n/**\r\n * Replaces string arguments with regex interpolation.\r\n *\r\n * @export\r\n * @template T\r\n * @param {T} value\r\n * @param {Record<string, unknown>} args\r\n * @param {[string, string]} [delimiters=['[[', ']]']]\r\n *\r\n * @returns {T} mutated value\r\n */\r\nexport function interpolate<T>(\r\n\tvalue: T,\r\n\targs: Record<string, unknown>,\r\n\tdelimiters: [string, string] = ['[[', ']]'],\r\n): T {\r\n\tif (typeof value === 'string') {\r\n\t\tif (!value.includes(delimiters[0])) return value as T;\r\n\r\n\t\treturn subslate(value, args, {\r\n\t\t\tstartStopPairs: delimiters,\r\n\t\t}) as T;\r\n\t}\r\n\r\n\tif (Array.isArray(value))\r\n\t\treturn value.map((a) => interpolate(a, args, delimiters)) as T;\r\n\r\n\tif (isRecord(value)) return interpolateJson(value, args, delimiters) as T;\r\n\r\n\treturn value;\r\n}\r\n\r\n/**\r\n * Replaces JSON string arguments with regex interpolation.\r\n *\r\n * @export\r\n * @param {Record<string, unknown>} args\r\n * @param {Record<string, unknown>} values\r\n * @param {[string, string]} [delimiters=['[[', ']]']]\r\n *\r\n * @returns {Record<string, unknown>} mutated args\r\n */\r\nexport function interpolateJson(\r\n\tvalues: Record<string, unknown>,\r\n\targs: Record<string, unknown>,\r\n\tdelimiters: [string, string] = ['[[', ']]'],\r\n): Record<string, unknown> {\r\n\tfor (const key in values)\r\n\t\tvalues[key] = interpolate(values[key], args, delimiters);\r\n\r\n\treturn values;\r\n}\r\n"],"mappings":";;AASA,SAAgB,EAAS,GAA8C;CAGtE,OAFI,CAAC,KAAO,OAAO,KAAQ,WAAiB,KAErC,OAAO,KAAK,CAAG,CAAC,CAAC,SAAS;AAClC;AAaA,SAAgB,EACf,GACA,GACA,IAA+B,CAAC,MAAM,IAAI,GACtC;CAcJ,OAbI,OAAO,KAAU,WACf,EAAM,SAAS,EAAW,EAAE,IAE1B,EAAS,GAAO,GAAM,EAC5B,gBAAgB,EACjB,CAAC,IAJ0C,IAOxC,MAAM,QAAQ,CAAK,IACf,EAAM,KAAK,MAAM,EAAY,GAAG,GAAM,CAAU,CAAC,IAErD,EAAS,CAAK,IAAU,EAAgB,GAAO,GAAM,CAAU,IAE5D;AACR;AAYA,SAAgB,EACf,GACA,GACA,IAA+B,CAAC,MAAM,IAAI,GAChB;CAC1B,KAAK,IAAM,KAAO,GACjB,EAAO,KAAO,EAAY,EAAO,IAAM,GAAM,CAAU;CAExD,OAAO;AACR"}
|
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,EAAA,CAAG,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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AAE,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,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C,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
|