@calvear/env 2.10.6 โ†’ 3.0.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +515 -677
  3. package/arguments.d.ts +15 -15
  4. package/arguments.d.ts.map +1 -1
  5. package/arguments.js +142 -131
  6. package/arguments.js.map +1 -1
  7. package/assets/logo.svg +30 -0
  8. package/commands/env.command.d.ts +8 -2
  9. package/commands/env.command.d.ts.map +1 -1
  10. package/commands/env.command.js +65 -81
  11. package/commands/env.command.js.map +1 -1
  12. package/commands/export.command.d.ts +9 -2
  13. package/commands/export.command.d.ts.map +1 -1
  14. package/commands/export.command.js +54 -56
  15. package/commands/export.command.js.map +1 -1
  16. package/commands/index.d.ts +5 -5
  17. package/commands/index.d.ts.map +1 -1
  18. package/commands/index.js +5 -14
  19. package/commands/pull.command.d.ts +6 -1
  20. package/commands/pull.command.d.ts.map +1 -1
  21. package/commands/pull.command.js +21 -37
  22. package/commands/pull.command.js.map +1 -1
  23. package/commands/push.command.d.ts +6 -1
  24. package/commands/push.command.d.ts.map +1 -1
  25. package/commands/push.command.js +21 -36
  26. package/commands/push.command.js.map +1 -1
  27. package/commands/schema.command.d.ts +6 -1
  28. package/commands/schema.command.d.ts.map +1 -1
  29. package/commands/schema.command.js +17 -17
  30. package/commands/schema.command.js.map +1 -1
  31. package/exec.d.ts +7 -1
  32. package/exec.d.ts.map +1 -1
  33. package/exec.js +88 -147
  34. package/exec.js.map +1 -1
  35. package/index.d.ts +3 -3
  36. package/index.d.ts.map +1 -1
  37. package/index.js +3 -20
  38. package/interfaces/index.d.ts +1 -1
  39. package/interfaces/index.d.ts.map +1 -1
  40. package/interfaces/loader.interface.d.ts +29 -3
  41. package/interfaces/loader.interface.d.ts.map +1 -1
  42. package/main.d.ts +0 -1
  43. package/main.js +7 -26
  44. package/main.js.map +1 -1
  45. package/package.json +53 -33
  46. package/providers/app-settings.provider.d.ts +5 -3
  47. package/providers/app-settings.provider.d.ts.map +1 -1
  48. package/providers/app-settings.provider.js +36 -51
  49. package/providers/app-settings.provider.js.map +1 -1
  50. package/providers/index.d.ts +2 -2
  51. package/providers/index.d.ts.map +1 -1
  52. package/providers/index.js +18 -28
  53. package/providers/index.js.map +1 -1
  54. package/providers/local.provider.d.ts +5 -2
  55. package/providers/local.provider.d.ts.map +1 -1
  56. package/providers/local.provider.js +27 -40
  57. package/providers/local.provider.js.map +1 -1
  58. package/providers/package-json.provider.d.ts +5 -2
  59. package/providers/package-json.provider.d.ts.map +1 -1
  60. package/providers/package-json.provider.js +26 -28
  61. package/providers/package-json.provider.js.map +1 -1
  62. package/providers/secrets.provider.d.ts +5 -2
  63. package/providers/secrets.provider.d.ts.map +1 -1
  64. package/providers/secrets.provider.js +24 -33
  65. package/providers/secrets.provider.js.map +1 -1
  66. package/utils/argv.util.d.ts +10 -0
  67. package/utils/argv.util.d.ts.map +1 -0
  68. package/utils/argv.util.js +24 -0
  69. package/utils/argv.util.js.map +1 -0
  70. package/utils/command.util.d.ts +71 -4
  71. package/utils/command.util.d.ts.map +1 -1
  72. package/utils/command.util.js +60 -135
  73. package/utils/command.util.js.map +1 -1
  74. package/utils/index.d.ts +8 -6
  75. package/utils/index.d.ts.map +1 -1
  76. package/utils/index.js +9 -23
  77. package/utils/interpolate.util.d.ts +29 -1
  78. package/utils/interpolate.util.d.ts.map +1 -1
  79. package/utils/interpolate.util.js +12 -29
  80. package/utils/interpolate.util.js.map +1 -1
  81. package/utils/json.util.d.ts +41 -3
  82. package/utils/json.util.d.ts.map +1 -1
  83. package/utils/json.util.js +29 -41
  84. package/utils/json.util.js.map +1 -1
  85. package/utils/logger.d.ts +21 -2
  86. package/utils/logger.d.ts.map +1 -1
  87. package/utils/logger.js +31 -17
  88. package/utils/logger.js.map +1 -1
  89. package/utils/normalize.util.d.ts +24 -2
  90. package/utils/normalize.util.d.ts.map +1 -1
  91. package/utils/normalize.util.js +35 -57
  92. package/utils/normalize.util.js.map +1 -1
  93. package/utils/schema.util.d.ts +62 -3
  94. package/utils/schema.util.d.ts.map +1 -1
  95. package/utils/schema.util.js +64 -92
  96. package/utils/schema.util.js.map +1 -1
  97. package/utils/ui.d.ts +14 -0
  98. package/utils/ui.d.ts.map +1 -0
  99. package/utils/ui.js +75 -0
  100. package/utils/ui.js.map +1 -0
  101. package/commands/index.js.map +0 -1
  102. package/index.js.map +0 -1
  103. package/interfaces/index.js +0 -18
  104. package/interfaces/index.js.map +0 -1
  105. package/interfaces/loader.interface.js +0 -3
  106. package/interfaces/loader.interface.js.map +0 -1
  107. package/tsconfig.build.tsbuildinfo +0 -1
  108. package/utils/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,MAAM,OAAO,CAAC;AAKxD,eAAO,MAAM,MAAM,QAYjB,CAAC"}
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;AAUD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,GAAE,cAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,CAS3E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EACvB,QAAQ,EAAE,cAAc,GACtB,IAAI,CAWN;AAED,4BAA4B;AAC5B,eAAO,MAAM,MAAM,iBAAiB,CAAC"}
package/utils/logger.js CHANGED
@@ -1,18 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = void 0;
4
- const tslog_1 = require("tslog");
5
- exports.logger = new tslog_1.LoggerWithoutCallSite({
6
- displayDateTime: true,
7
- displayLoggerName: false,
8
- displayInstanceName: false,
9
- displayFunctionName: false,
10
- prettyInspectHighlightStyles: {
11
- regexp: 'green',
12
- number: 'cyan'
13
- },
14
- displayFilePath: 'hidden',
15
- dateTimePattern: 'hour:minute:second.millisecond',
16
- maskPlaceholder: '***'
17
- });
1
+ import { Logger as e } from "tslog";
2
+ //#region src/utils/logger.ts
3
+ var t = {
4
+ debug: 2,
5
+ error: 5,
6
+ info: 3,
7
+ silly: 0,
8
+ trace: 1,
9
+ warn: 4
10
+ }, n = {
11
+ hideLogPositionForProduction: !0,
12
+ maskPlaceholder: "***",
13
+ prettyLogTemplate: "{{hh}}:{{MM}}:{{ss}}.{{ms}} {{logLevelName}} ",
14
+ prettyLogTimeZone: "local",
15
+ type: "pretty"
16
+ };
17
+ function r(r = {}) {
18
+ return new e({
19
+ ...n,
20
+ maskValuesOfKeys: r.maskValuesOfKeys ?? [],
21
+ minLevel: t[r.minLevel ?? "info"],
22
+ maskValuesRegEx: (r.maskAnyRegEx ?? []).map((e) => new RegExp(e))
23
+ });
24
+ }
25
+ function i(e, n) {
26
+ n.minLevel && (e.settings.minLevel = t[n.minLevel]), n.maskValuesOfKeys && (e.settings.maskValuesOfKeys = n.maskValuesOfKeys), n.maskAnyRegEx && (e.settings.maskValuesRegEx = n.maskAnyRegEx.map((e) => new RegExp(e)));
27
+ }
28
+ var a = r();
29
+ //#endregion
30
+ export { t as LOG_LEVELS, i as configureLogger, r as createLogger, a as logger };
31
+
18
32
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;AAAA,iCAAwD;AAK3C,QAAA,MAAM,GAAG,IAAI,6BAAM,CAAC;IAChC,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,KAAK;IACxB,mBAAmB,EAAE,KAAK;IAC1B,mBAAmB,EAAE,KAAK;IAC1B,4BAA4B,EAAE;QAC7B,MAAM,EAAE,OAAO;QACf,MAAM,EAAE,MAAM;KACd;IACD,eAAe,EAAE,QAAQ;IACzB,eAAe,EAAE,gCAAgC;IACjD,eAAe,EAAE,KAAK;CACtB,CAAC,CAAC"}
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\tprettyLogTemplate: '{{hh}}:{{MM}}:{{ss}}.{{ms}}\\t{{logLevelName}}\\t',\r\n\tprettyLogTimeZone: 'local',\r\n\ttype: 'pretty',\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\tminLevel: LOG_LEVELS[settings.minLevel ?? 'info'],\r\n\t\tmaskValuesRegEx: (settings.maskAnyRegEx ?? []).map(\r\n\t\t\t(pattern) => new RegExp(pattern),\r\n\t\t),\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 = settings.maskAnyRegEx.map(\r\n\t\t\t(pattern) => new RegExp(pattern),\r\n\t\t);\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;CACjB,mBAAmB;CACnB,mBAAmB;CACnB,MAAM;AACP;AAMA,SAAgB,EAAa,IAA2B,CAAC,GAAoB;CAC5E,OAAO,IAAI,EAAO;EACjB,GAAG;EACH,kBAAkB,EAAS,oBAAoB,CAAC;EAChD,UAAU,EAAW,EAAS,YAAY;EAC1C,kBAAkB,EAAS,gBAAgB,CAAC,GAAG,KAC7C,MAAY,IAAI,OAAO,CAAO,CAChC;CACD,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,kBAAkB,EAAS,aAAa,KACtD,MAAY,IAAI,OAAO,CAAO,CAChC;AACF;AAGA,IAAa,IAAS,EAAa"}
@@ -1,3 +1,25 @@
1
- export declare function flatten(obj: Record<string, any>, nestingDelimiter?: string, pkey?: string): Record<string, string>;
2
- export declare function normalize(obj: Record<string, any>, nestingDelimiter?: string, arrayDescomposition?: boolean, pkey?: string): Record<string, string>;
1
+ /**
2
+ * Flatten a object keeping depth path
3
+ * in key using __ as level separator.
4
+ *
5
+ * @param {Record<string, any>} obj
6
+ * @param {string} nestingDelimiter char for delimit nesting levels
7
+ * @param {string} pkey first level key
8
+ *
9
+ * @returns {Record<string, unknown>} flattened object
10
+ */
11
+ export declare function flatten(obj: Record<string, any>, nestingDelimiter?: string, pkey?: string): Record<string, unknown>;
12
+ /**
13
+ * Normalizes env object, converts arrays in list strings,
14
+ * only primitives types array,
15
+ * and removes $ global character from keys.
16
+ *
17
+ * @param {Record<string, any>} obj
18
+ * @param {string} nestingDelimiter char for delimit nesting levels
19
+ * @param {boolean} arrayDescomposition serialize or break down arrays
20
+ * @param {string} pkey first level key
21
+ *
22
+ * @returns {Record<string, unknown>} normalized object
23
+ */
24
+ export declare function normalize(obj: Record<string, any>, nestingDelimiter?: string, arrayDescomposition?: boolean, pkey?: string): Record<string, unknown>;
3
25
  //# sourceMappingURL=normalize.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.util.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.util.ts"],"names":[],"mappings":"AAYA,wBAAgB,OAAO,CACtB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,gBAAgB,SAAO,EACvB,IAAI,SAAK,GACP,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0BxB;AAcD,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,MAAM,CAAC,CAyCxB"}
1
+ {"version":3,"file":"normalize.util.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;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,CA0BzB;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"}
@@ -1,61 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalize = exports.flatten = void 0;
4
- function flatten(obj, nestingDelimiter = '__', pkey = '') {
5
- const flattened = {};
6
- for (let key in obj) {
7
- const value = obj[key];
8
- const type = typeof value;
9
- if (value === undefined || type === 'function')
10
- continue;
11
- if (key[0] === '#')
12
- continue;
13
- key = pkey + key;
14
- if (value === null || type !== 'object' || Array.isArray(value)) {
15
- flattened[key] = value;
16
- continue;
17
- }
18
- Object.assign(flattened, flatten(value, nestingDelimiter, `${key}${nestingDelimiter}`));
19
- }
20
- return flattened;
1
+ //#region src/utils/normalize.util.ts
2
+ function e(t, n = "__", r = "") {
3
+ let i = {};
4
+ for (let a in t) {
5
+ let o = t[a], s = typeof o;
6
+ if (!(o === void 0 || s === "function") && a[0] !== "#") {
7
+ if (a = r + a, o === null || s !== "object" || Array.isArray(o)) {
8
+ i[a] = o;
9
+ continue;
10
+ }
11
+ Object.assign(i, e(o, n, `${a}${n}`));
12
+ }
13
+ }
14
+ return i;
21
15
  }
22
- exports.flatten = flatten;
23
- function normalize(obj, nestingDelimiter = '__', arrayDescomposition = false, pkey = '') {
24
- const flattened = {};
25
- for (let key in obj) {
26
- const value = obj[key];
27
- const type = typeof value;
28
- if (value === null || value === undefined || type === 'function')
29
- continue;
30
- key = pkey + key.replace('$', '');
31
- if (type !== 'object') {
32
- flattened[key] = value;
33
- continue;
34
- }
35
- if (Array.isArray(value)) {
36
- normalizeArray(flattened, key, value, nestingDelimiter, arrayDescomposition);
37
- }
38
- else {
39
- Object.assign(flattened, normalize(value, nestingDelimiter, arrayDescomposition, `${key}${nestingDelimiter}`));
40
- }
41
- }
42
- return flattened;
16
+ function t(e, r = "__", i = !1, a = "") {
17
+ let o = {};
18
+ for (let s in e) {
19
+ let c = e[s], l = typeof c;
20
+ if (!(c == null || l === "function")) {
21
+ if (s = a + (s[0] === "$" ? s.slice(1) : s), l !== "object") {
22
+ o[s] = c;
23
+ continue;
24
+ }
25
+ Array.isArray(c) ? n(o, s, c, r, i) : Object.assign(o, t(c, r, i, `${s}${r}`));
26
+ }
27
+ }
28
+ return o;
43
29
  }
44
- exports.normalize = normalize;
45
- function normalizeArray(flattened, key, value, nestingDelimiter = '__', arrayDescomposition = false) {
46
- if (arrayDescomposition) {
47
- key = `${key}${nestingDelimiter}`;
48
- for (let i = 0; i < value.length; i++) {
49
- if (typeof value[i] === 'object') {
50
- Object.assign(flattened, normalize(value[i], nestingDelimiter, arrayDescomposition, `${key}${i}${nestingDelimiter}`));
51
- }
52
- else {
53
- flattened[`${key}${i}`] = value[i];
54
- }
55
- }
56
- }
57
- else {
58
- flattened[key] = value.filter((v) => typeof v !== 'object').join(',');
59
- }
30
+ function n(e, n, r, i = "__", a = !1) {
31
+ if (a) {
32
+ n = `${n}${i}`;
33
+ for (let [o, s] of r.entries()) typeof s == "object" ? Object.assign(e, t(s, i, a, `${n}${o}${i}`)) : e[`${n}${o}`] = s;
34
+ } else e[n] = r.filter((e) => typeof e != "object").join(",");
60
35
  }
36
+ //#endregion
37
+ export { e as flatten, t as normalize };
38
+
61
39
  //# sourceMappingURL=normalize.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.util.js","sourceRoot":"","sources":["../../src/utils/normalize.util.ts"],"names":[],"mappings":";;;AAYA,SAAgB,OAAO,CACtB,GAAwB,EACxB,gBAAgB,GAAG,IAAI,EACvB,IAAI,GAAG,EAAE;IAET,MAAM,SAAS,GAA2B,EAAE,CAAC;IAE7C,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;QAE1B,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU;YAAE,SAAS;QAGzD,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,SAAS;QAC7B,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;QAEjB,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjE,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAEvB,SAAS;QACV,CAAC;QAED,MAAM,CAAC,MAAM,CACZ,SAAS,EACT,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,GAAG,GAAG,gBAAgB,EAAE,CAAC,CAC7D,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AA9BD,0BA8BC;AAcD,SAAgB,SAAS,CACxB,GAAwB,EACxB,gBAAgB,GAAG,IAAI,EACvB,mBAAmB,GAAG,KAAK,EAC3B,IAAI,GAAG,EAAE;IAET,MAAM,SAAS,GAA2B,EAAE,CAAC;IAE7C,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,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AgB,EAAE,CAC/B,CACD,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;IACF,CAAC;SAAM,CAAC;QACP,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvE,CAAC;AACF,CAAC"}
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":";AAUA,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,KAGf;OAFA,IAAM,IAAO,GAET,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,11 +1,70 @@
1
1
  import { JSONSchemaType, ValidateFunction } from 'ajv';
2
2
  import { Options } from 'to-json-schema';
3
+ /**
4
+ * Generates JSON schema from JSON template/object.
5
+ *
6
+ * @export
7
+ * @param {Record<string, unknown>} json json object
8
+ * @param {Options} [options]
9
+ *
10
+ * @returns {*} {Promise<Record<string, unknown>>}
11
+ */
3
12
  export declare function schemaFrom(json: Record<string, unknown>, options?: Options & {
4
13
  nullable?: boolean;
5
- }): Record<string, unknown>;
14
+ }): Promise<Record<string, unknown>>;
15
+ /**
16
+ * Validates if a object is a JSON schema.
17
+ *
18
+ * @export
19
+ * @param {Record<string, unknown>} schema
20
+ *
21
+ * @returns {boolean} if is a JSON schema
22
+ */
6
23
  export declare function isJsonSchemaObject(schema: Record<string, unknown>): schema is JSONSchemaType<object>;
24
+ /**
25
+ * Converts a JSON schema to JSON template.
26
+ *
27
+ * @export
28
+ * @param {Record<string, unknown>} schema JSON schema
29
+ * @param {Record<string, any>} [container] template container
30
+ *
31
+ * @returns {unknown} object or default value
32
+ */
7
33
  export declare function schemaToJson(schema: Record<string, unknown>, container?: Record<string, any>): unknown;
34
+ /**
35
+ * Flatten a JSON schema.
36
+ *
37
+ * @export
38
+ * @param {Record<string, unknown>} schema JSON schema
39
+ * @param {string} [parentKey] previous level key
40
+ * @param {string} [nestingDelimiter] char for delimit nesting levels
41
+ * @param {Record<string, any>} [container] result container
42
+ *
43
+ * @returns {Record<string, unknown>} flattened schema
44
+ */
8
45
  export declare function flatSchema(schema: Record<string, unknown>, parentKey?: string, nestingDelimiter?: string, container?: Record<string, any>): Record<string, unknown>;
9
- export declare function createValidator(schema: Record<string, unknown>, enableFormats?: boolean): ValidateFunction;
10
- export declare function createValidators(schemaLookup: Record<string, object>, enableFormats?: boolean): Record<string, ValidateFunction>;
46
+ /**
47
+ * Creates a JSON schema validator using AJV.
48
+ *
49
+ * @see https://ajv.js.org/
50
+ *
51
+ * @export
52
+ * @param {Record<string, object>} schema json schema by provider
53
+ * @param {boolean} enableFormats whether formats are enabled
54
+ *
55
+ * @returns {Promise<ValidateFunction>} validators
56
+ */
57
+ export declare function createValidator(schema: Record<string, unknown>, enableFormats?: boolean): Promise<ValidateFunction>;
58
+ /**
59
+ * Creates a JSON schema validator lookup using AJV.
60
+ *
61
+ * @see https://ajv.js.org/
62
+ *
63
+ * @export
64
+ * @param {Record<string, object>} schemaLookup json schema by provider
65
+ * @param {boolean} enableFormats whether formats are enabled
66
+ *
67
+ * @returns {Promise<Record<string, ValidateFunction>>} validators lookup
68
+ */
69
+ export declare function createValidators(schemaLookup: Record<string, object>, enableFormats?: boolean): Promise<Record<string, ValidateFunction>>;
11
70
  //# sourceMappingURL=schema.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.util.d.ts","sourceRoot":"","sources":["../../src/utils/schema.util.ts"],"names":[],"mappings":"AAAA,OAAY,EAAU,cAAc,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAEpE,OAAqB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA+BvD,wBAAgB,UAAU,CACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,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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,CAmBzB;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"}
@@ -1,100 +1,72 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ //#region src/utils/schema.util.ts
2
+ var e, t, n, r, i, a = {
3
+ "ip-address": /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})$/,
4
+ color: /^(#?([\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*\)))$/,
5
+ hostname: /^(?=.{1,255}$)[\da-z](?:[\da-z-]{0,61}[\da-z])?(?:\.[\da-z](?:[\da-z-]{0,61}[\da-z])?)*\.?$/i,
6
+ alphanumeric: /^[\da-z]+$/i,
7
+ "utc-millisec": (e) => !Number.isNaN(+e),
8
+ alpha: /^[a-z]+$/i,
9
+ style: /\s*(.+?):\s*([^;]+);?/g,
10
+ phone: /^\+(?:\d ?){6,14}\d$/
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createValidators = exports.createValidator = exports.flatSchema = exports.schemaToJson = exports.isJsonSchemaObject = exports.schemaFrom = void 0;
7
- const ajv_1 = __importDefault(require("ajv"));
8
- const ajv_formats_1 = __importDefault(require("ajv-formats"));
9
- const to_json_schema_1 = __importDefault(require("to-json-schema"));
10
- const FORMAT_REGEXPS = {
11
- 'ip-address': /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})$/,
12
- color: /^(#?([\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*\)))$/,
13
- hostname: /^(?=.{1,255}$)[\dA-Za-z](?:(?:[\dA-Za-z]|-){0,61}[\dA-Za-z])?(?:\.[\dA-Za-z](?:(?:[\dA-Za-z]|-){0,61}[\dA-Za-z])?)*\.?$/,
14
- alphanumeric: /^[\dA-Za-z]+$/,
15
- 'utc-millisec': (input) => !Number.isNaN(+input),
16
- alpha: /^[A-Za-z]+$/,
17
- style: /\s*(.+?):\s*([^;]+);?/g,
18
- phone: /^\+(?:\d ?){6,14}\d$/
19
- };
20
- function schemaFrom(json, options) {
21
- return (0, to_json_schema_1.default)(json, {
22
- required: false,
23
- ...options,
24
- postProcessFnc: (type, schema, value, defaultFunc) => {
25
- if (value !== json) {
26
- schema.type = [type];
27
- schema.nullable = options?.nullable ?? false;
28
- }
29
- if (value === null || value === undefined)
30
- schema.nullable = true;
31
- return defaultFunc(type, schema, value);
32
- }
33
- });
12
+ async function o(e, t) {
13
+ return i ||= (await import("to-json-schema")).default, i(e, {
14
+ required: !1,
15
+ ...t,
16
+ postProcessFnc: (n, r, i, a) => (i !== e && (r.type = [n], r.nullable = t?.nullable ?? !1), i ?? (r.nullable = !0), a(n, r, i))
17
+ });
18
+ }
19
+ function s(e) {
20
+ return e.type === "object" ? !0 : Array.isArray(e.type) && e.type.includes("object");
34
21
  }
35
- exports.schemaFrom = schemaFrom;
36
- function isJsonSchemaObject(schema) {
37
- if (schema.type === 'object')
38
- return true;
39
- return Array.isArray(schema.type) && schema.type.includes('object');
22
+ function c(e, t = {}) {
23
+ if (s(e)) {
24
+ for (let n in e.properties) t[n] = c(e.properties[n]);
25
+ return t;
26
+ } else return e.default ?? (e.nullable ? null : void 0);
40
27
  }
41
- exports.isJsonSchemaObject = isJsonSchemaObject;
42
- function schemaToJson(schema, container = {}) {
43
- if (isJsonSchemaObject(schema)) {
44
- for (const key in schema.properties)
45
- container[key] = schemaToJson(schema.properties[key]);
46
- return container;
47
- }
48
- else {
49
- return schema.default ?? (schema.nullable ? null : undefined);
50
- }
28
+ function l(e, t = "", n = "__", r = {}) {
29
+ if (s(e)) {
30
+ for (let i in e.properties) {
31
+ if (i[0] === "#") continue;
32
+ let a = t + (t ? n : "") + i;
33
+ r = {
34
+ ...r,
35
+ ...l(e.properties[i], a, n)
36
+ };
37
+ }
38
+ return r;
39
+ } else return { [t]: e };
51
40
  }
52
- exports.schemaToJson = schemaToJson;
53
- function flatSchema(schema, parentKey = '', nestingDelimiter = '__', container = {}) {
54
- if (isJsonSchemaObject(schema)) {
55
- for (const key in schema.properties) {
56
- if (key[0] === '#')
57
- continue;
58
- const subKey = parentKey + (parentKey ? nestingDelimiter : '') + key;
59
- container = {
60
- ...container,
61
- ...flatSchema(schema.properties[key], subKey, nestingDelimiter)
62
- };
63
- }
64
- return container;
65
- }
66
- else {
67
- return { [parentKey]: schema };
68
- }
41
+ async function u(e, t = !0) {
42
+ return (await f(t)).compile(e);
69
43
  }
70
- exports.flatSchema = flatSchema;
71
- function createValidator(schema, enableFormats = true) {
72
- const ajv = new ajv_1.default({
73
- allErrors: true,
74
- allowUnionTypes: true
75
- });
76
- if (enableFormats) {
77
- (0, ajv_formats_1.default)(ajv, { mode: 'fast' });
78
- for (const key in FORMAT_REGEXPS)
79
- ajv.addFormat(key, FORMAT_REGEXPS[key]);
80
- }
81
- return ajv.compile(schema);
44
+ async function d(e, t = !0) {
45
+ let n = await f(t), r = {};
46
+ for (let t in e) r[t] = n.compile(e[t]);
47
+ return r;
82
48
  }
83
- exports.createValidator = createValidator;
84
- function createValidators(schemaLookup, enableFormats = true) {
85
- const ajv = new ajv_1.default({
86
- allErrors: true,
87
- allowUnionTypes: true
88
- });
89
- if (enableFormats) {
90
- (0, ajv_formats_1.default)(ajv, { mode: 'fast' });
91
- for (const key in FORMAT_REGEXPS)
92
- ajv.addFormat(key, FORMAT_REGEXPS[key]);
93
- }
94
- const validators = {};
95
- for (const key in schemaLookup)
96
- validators[key] = ajv.compile(schemaLookup[key]);
97
- return validators;
49
+ async function f(i) {
50
+ if (!n) {
51
+ let [e, t] = await Promise.all([import("ajv"), import("ajv-formats")]);
52
+ n = e.Ajv, r = t.default;
53
+ }
54
+ if (i) {
55
+ if (!t) {
56
+ t = new n({
57
+ allErrors: !0,
58
+ allowUnionTypes: !0
59
+ }), r(t, { mode: "fast" });
60
+ for (let e in a) t.addFormat(e, a[e]);
61
+ }
62
+ return t;
63
+ }
64
+ return e ||= new n({
65
+ allErrors: !0,
66
+ allowUnionTypes: !0
67
+ }), e;
98
68
  }
99
- exports.createValidators = createValidators;
69
+ //#endregion
70
+ export { u as createValidator, d as createValidators, l as flatSchema, s as isJsonSchemaObject, o as schemaFrom, c as schemaToJson };
71
+
100
72
  //# sourceMappingURL=schema.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.util.js","sourceRoot":"","sources":["../../src/utils/schema.util.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoE;AACpE,8DAAqC;AACrC,oEAAuD;AAEvD,MAAM,cAAc,GAA2B;IAC9C,YAAY,EACX,+EAA+E;IAEhF,KAAK,EAAE,8VAA8V;IAErW,QAAQ,EACP,yHAAyH;IAE1H,YAAY,EAAE,eAAe;IAE7B,cAAc,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;IAExD,KAAK,EAAE,aAAa;IAEpB,KAAK,EAAE,wBAAwB;IAE/B,KAAK,EAAE,sBAAsB;CAC7B,CAAC;AAWF,SAAgB,UAAU,CACzB,IAA6B,EAC7B,OAA0C;IAE1C,OAAO,IAAA,wBAAY,EAAC,IAAI,EAAE;QACzB,QAAQ,EAAE,KAAK;QACf,GAAG,OAAO;QACV,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;YACpD,IAAI,KAAK,K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AE,CAAC;QACnB,IAAA,qBAAU,EAAC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAElC,KAAK,MAAM,GAAG,IAAI,cAAc;YAC/B,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,UAAU,GAAqC,EAAE,CAAC;IAExD,KAAK,MAAM,GAAG,IAAI,YAAY;QAC7B,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAElD,OAAO,UAAU,CAAC;AACnB,CAAC;AAtBD,4CAsBC"}
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, but prefix removed for injection\r\n\t\t\tconst subKey =\r\n\t\t\t\tparentKey + (parentKey ? nestingDelimiter : '') + key;\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,EAAm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EAAU;EACpB,WAAW;EACX,iBAAiB;CAClB,CAAC,GAGK;AACR"}
package/utils/ui.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /** Formats a duration in ms as "142ms" or "1.4s". */
2
+ export declare function formatDuration(ms: number): string;
3
+ export declare const ui: {
4
+ header(version: string, env?: string, modes?: string[]): void;
5
+ provider(key: string, count: number): void;
6
+ /** Pretty, sorted, masked dump of the resolved environment (debug level). */
7
+ variables(env: Record<string, unknown>): void;
8
+ summary(total: number, ms: number): void;
9
+ running(command: string): void;
10
+ finished(ms: number): void;
11
+ failed(code: number): void;
12
+ action(emoji: string, message: string): void;
13
+ };
14
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../src/utils/ui.ts"],"names":[],"mappings":"AAqDA,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;mBA2B9B,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 ADDED
@@ -0,0 +1,75 @@
1
+ import { LOG_LEVELS as e, logger as t } from "./logger.js";
2
+ import n from "picocolors";
3
+ //#region src/utils/ui.ts
4
+ var r = {
5
+ "app-settings": "๐Ÿ—‚๏ธ",
6
+ local: "๐Ÿ“‚",
7
+ "package-json": "๐Ÿ“ฆ",
8
+ secrets: "๐Ÿ”"
9
+ };
10
+ function i(n) {
11
+ return (t.settings.minLevel ?? e.info) <= n;
12
+ }
13
+ function a(t = "", n = e.info) {
14
+ i(n) && process.stdout.write(`${t}\n`);
15
+ }
16
+ function o(e, n) {
17
+ let { maskPlaceholder: r = "***", maskValuesOfKeys: i = [], maskValuesRegEx: a = [] } = t.settings;
18
+ if (i.some((t) => t.toLowerCase() === e.toLowerCase())) return {
19
+ masked: !0,
20
+ value: r
21
+ };
22
+ let o = !1, s = n;
23
+ for (let e of a) {
24
+ let t = s.replaceAll(new RegExp(e.source, "g"), r);
25
+ t !== s && (o = !0), s = t;
26
+ }
27
+ return {
28
+ masked: o,
29
+ value: s
30
+ };
31
+ }
32
+ function s(e) {
33
+ return e < 1e3 ? `${Math.round(e)}ms` : `${(e / 1e3).toFixed(1)}s`;
34
+ }
35
+ var c = {
36
+ header(e, t, r) {
37
+ 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("+"))}`), a(), a(i.join(n.dim(" ยท "))), a();
39
+ },
40
+ provider(e, t) {
41
+ let i = r[e] ?? "๐Ÿงฉ", o = e === "secrets" ? "secrets" : "vars";
42
+ a(` ${i} ${n.cyan(e.padEnd(16))} ${n.bold(String(t))} ${n.dim(o)}`);
43
+ },
44
+ variables(t) {
45
+ if (!i(e.debug)) return;
46
+ let r = Object.entries(t).sort(([e], [t]) => e.localeCompare(t)), s = r.reduce((e, [t]) => Math.max(e, t.length), 0);
47
+ a(` ${n.dim(`environment (${r.length} variables)`)}`, e.debug);
48
+ for (let [t, i] of r) {
49
+ let { masked: r, value: c } = o(t, String(i)), l = r ? n.yellow(c) : n.green(c);
50
+ a(` ${n.cyan(t.padEnd(s))} ${n.dim("=")} ${l}`, e.debug);
51
+ }
52
+ a("", e.debug);
53
+ },
54
+ summary(e, t) {
55
+ let r = n.dim(`in ${s(t)}`);
56
+ a(), a(` ${n.green("โœ“")} ${n.bold(String(e))} variables loaded ${r}`);
57
+ },
58
+ running(e) {
59
+ a(), a(` ${n.yellow("โ–ถ")} ${n.bold(e)}`), a();
60
+ },
61
+ finished(e) {
62
+ let t = n.dim(`finished in ${s(e)}`);
63
+ a(` ${n.green("โœ“")} ${t}`);
64
+ },
65
+ failed(e) {
66
+ a(` ${n.red(`โœ— exited with code ${e}`)}`);
67
+ },
68
+ action(e, t) {
69
+ a(` ${e} ${t}`);
70
+ }
71
+ };
72
+ //#endregion
73
+ export { s as formatDuration, c as ui };
74
+
75
+ //# sourceMappingURL=ui.js.map