@kikiutils/shared 18.3.0 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +0 -7
  2. package/dist/buffer.d.ts +0 -2
  3. package/dist/buffer.d.ts.map +1 -1
  4. package/dist/buffer.js +1 -2
  5. package/dist/classes/enhanced-date.d.ts +0 -2
  6. package/dist/classes/enhanced-date.d.ts.map +1 -1
  7. package/dist/classes/enhanced-date.js +1 -2
  8. package/dist/classes/path.d.ts +1 -3
  9. package/dist/classes/path.d.ts.map +1 -1
  10. package/dist/classes/path.js +1 -2
  11. package/dist/classes/precision-number.d.ts +0 -2
  12. package/dist/classes/precision-number.d.ts.map +1 -1
  13. package/dist/classes/precision-number.js +1 -2
  14. package/dist/clipboard.d.ts +0 -2
  15. package/dist/clipboard.d.ts.map +1 -1
  16. package/dist/clipboard.js +1 -2
  17. package/dist/crypto-hash.d.ts +0 -2
  18. package/dist/crypto-hash.d.ts.map +1 -1
  19. package/dist/crypto-hash.js +1 -2
  20. package/dist/datetime.d.ts +0 -2
  21. package/dist/datetime.d.ts.map +1 -1
  22. package/dist/datetime.js +1 -2
  23. package/dist/element-plus.d.ts +0 -2
  24. package/dist/element-plus.d.ts.map +1 -1
  25. package/dist/element-plus.js +1 -2
  26. package/dist/enum.d.ts +0 -2
  27. package/dist/enum.d.ts.map +1 -1
  28. package/dist/enum.js +1 -2
  29. package/dist/env.d.ts +0 -2
  30. package/dist/env.d.ts.map +1 -1
  31. package/dist/env.js +1 -2
  32. package/dist/event-awaiter.d.ts +0 -2
  33. package/dist/event-awaiter.d.ts.map +1 -1
  34. package/dist/event-awaiter.js +1 -2
  35. package/dist/file.d.ts +0 -2
  36. package/dist/file.d.ts.map +1 -1
  37. package/dist/file.js +1 -2
  38. package/dist/general.d.ts +0 -2
  39. package/dist/general.d.ts.map +1 -1
  40. package/dist/general.js +1 -2
  41. package/dist/hash.d.ts +0 -2
  42. package/dist/hash.d.ts.map +1 -1
  43. package/dist/hash.js +1 -2
  44. package/dist/logger/_internals/formatter.d.ts +13 -0
  45. package/dist/logger/_internals/formatter.d.ts.map +1 -0
  46. package/dist/logger/_internals/formatter.js +57 -0
  47. package/dist/logger/_internals/formatter.js.map +1 -0
  48. package/dist/logger/_internals/levels.d.ts +54 -0
  49. package/dist/logger/_internals/levels.d.ts.map +1 -0
  50. package/dist/logger/_internals/levels.js +59 -0
  51. package/dist/logger/_internals/levels.js.map +1 -0
  52. package/dist/logger/_internals/logger.d.ts +12 -0
  53. package/dist/logger/_internals/logger.d.ts.map +1 -0
  54. package/dist/logger/_internals/logger.js +147 -0
  55. package/dist/logger/_internals/logger.js.map +1 -0
  56. package/dist/logger/_internals/types.d.ts +12 -0
  57. package/dist/logger/_internals/types.d.ts.map +1 -0
  58. package/dist/logger/_internals/types.js +1 -0
  59. package/dist/logger/index.d.ts +10 -0
  60. package/dist/logger/index.d.ts.map +1 -0
  61. package/dist/logger/index.js +25 -0
  62. package/dist/logger/index.js.map +1 -0
  63. package/dist/logger/node/_internals/file-writer.d.ts +11 -0
  64. package/dist/logger/node/_internals/file-writer.d.ts.map +1 -0
  65. package/dist/logger/node/_internals/file-writer.js +188 -0
  66. package/dist/logger/node/_internals/file-writer.js.map +1 -0
  67. package/dist/logger/node/_internals/formatter.d.ts +4 -0
  68. package/dist/logger/node/_internals/formatter.d.ts.map +1 -0
  69. package/dist/logger/node/_internals/formatter.js +21 -0
  70. package/dist/logger/node/_internals/formatter.js.map +1 -0
  71. package/dist/logger/node/index.d.ts +10 -0
  72. package/dist/logger/node/index.d.ts.map +1 -0
  73. package/dist/logger/node/index.js +123 -0
  74. package/dist/logger/node/index.js.map +1 -0
  75. package/dist/logger/node/types.d.ts +43 -0
  76. package/dist/logger/node/types.d.ts.map +1 -0
  77. package/dist/logger/node/types.js +1 -0
  78. package/dist/logger/types.d.ts +50 -0
  79. package/dist/logger/types.d.ts.map +1 -0
  80. package/dist/logger/types.js +1 -0
  81. package/dist/math.d.ts +0 -2
  82. package/dist/math.d.ts.map +1 -1
  83. package/dist/math.js +1 -2
  84. package/dist/number.d.ts +0 -2
  85. package/dist/number.d.ts.map +1 -1
  86. package/dist/number.js +1 -2
  87. package/dist/random.d.ts +0 -2
  88. package/dist/random.d.ts.map +1 -1
  89. package/dist/random.js +1 -2
  90. package/dist/redis/script-runner.d.ts +0 -2
  91. package/dist/redis/script-runner.d.ts.map +1 -1
  92. package/dist/redis/script-runner.js +1 -2
  93. package/dist/storages/lru/keyed-store.d.ts +0 -2
  94. package/dist/storages/lru/keyed-store.d.ts.map +1 -1
  95. package/dist/storages/lru/keyed-store.js +1 -2
  96. package/dist/storages/redis/keyed-store.d.ts +4 -4
  97. package/dist/storages/redis/keyed-store.d.ts.map +1 -1
  98. package/dist/storages/redis/keyed-store.js +7 -4
  99. package/dist/storages/redis/keyed-store.js.map +1 -1
  100. package/dist/storages/redis/msgpack.d.ts +10 -3
  101. package/dist/storages/redis/msgpack.d.ts.map +1 -1
  102. package/dist/storages/redis/msgpack.js +18 -3
  103. package/dist/storages/redis/msgpack.js.map +1 -1
  104. package/dist/storages/redis/types.d.ts +30 -2
  105. package/dist/storages/redis/types.d.ts.map +1 -1
  106. package/dist/string.d.ts +0 -2
  107. package/dist/string.d.ts.map +1 -1
  108. package/dist/string.js +1 -2
  109. package/dist/time.d.ts +0 -2
  110. package/dist/time.d.ts.map +1 -1
  111. package/dist/time.js +1 -2
  112. package/dist/types/filtered-key-path.d.ts +0 -2
  113. package/dist/types/filtered-key-path.d.ts.map +1 -1
  114. package/dist/types/index.d.ts +0 -10
  115. package/dist/types/index.d.ts.map +1 -1
  116. package/dist/types/vue.d.ts +0 -2
  117. package/dist/types/vue.d.ts.map +1 -1
  118. package/dist/url.d.ts +0 -2
  119. package/dist/url.d.ts.map +1 -1
  120. package/dist/url.js +1 -2
  121. package/dist/vue.d.ts +0 -2
  122. package/dist/vue.d.ts.map +1 -1
  123. package/dist/vue.js +1 -2
  124. package/dist/web.d.ts +0 -2
  125. package/dist/web.d.ts.map +1 -1
  126. package/dist/web.js +1 -2
  127. package/package.json +73 -45
  128. package/src/logger/_internals/formatter.ts +80 -0
  129. package/src/logger/_internals/levels.ts +60 -0
  130. package/src/logger/_internals/logger.ts +224 -0
  131. package/src/logger/_internals/types.ts +12 -0
  132. package/src/logger/index.ts +34 -0
  133. package/src/logger/node/_internals/file-writer.ts +298 -0
  134. package/src/logger/node/_internals/formatter.ts +33 -0
  135. package/src/logger/node/index.ts +173 -0
  136. package/src/logger/node/types.ts +58 -0
  137. package/src/logger/types.ts +60 -0
  138. package/src/storages/redis/keyed-store.ts +6 -2
  139. package/src/storages/redis/msgpack.ts +17 -1
  140. package/src/storages/redis/types.ts +34 -0
  141. package/src/types/index.ts +0 -10
  142. package/dist/classes/ssh-client.d.ts +0 -40
  143. package/dist/classes/ssh-client.d.ts.map +0 -1
  144. package/dist/classes/ssh-client.js +0 -130
  145. package/dist/classes/ssh-client.js.map +0 -1
  146. package/dist/consola.d.ts +0 -24
  147. package/dist/consola.d.ts.map +0 -1
  148. package/dist/consola.js +0 -29
  149. package/dist/consola.js.map +0 -1
  150. package/dist/object.d.ts +0 -44
  151. package/dist/object.d.ts.map +0 -1
  152. package/dist/object.js +0 -59
  153. package/dist/object.js.map +0 -1
  154. package/dist/pino.d.ts +0 -25
  155. package/dist/pino.d.ts.map +0 -1
  156. package/dist/pino.js +0 -34
  157. package/dist/pino.js.map +0 -1
  158. package/src/classes/ssh-client.ts +0 -175
  159. package/src/consola.ts +0 -25
  160. package/src/object.ts +0 -78
  161. package/src/pino.ts +0 -33
package/dist/consola.js DELETED
@@ -1,29 +0,0 @@
1
- import { createConsola } from "consola";
2
- //#region src/consola.ts
3
- /**
4
- * A consola logger with environment-controlled verbosity.
5
- *
6
- * @remarks
7
- * `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;
8
- * otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.
9
- * Assign `logger.level` to change verbosity after initialization.
10
- *
11
- * @example
12
- *
13
- * ```ts
14
- * import { logger } from '@kikiutils/shared/consola';
15
- *
16
- * logger.level = 3;
17
- * logger.info('Application started');
18
- * ```
19
- *
20
- * @see {@link https://github.com/unjs/consola#log-level | Consola log levels}
21
- */
22
- const consolaLogger = createConsola();
23
- const logger = consolaLogger;
24
- if (process.env.CONSOLA_LOGGER_LEVEL !== void 0) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;
25
- else consolaLogger.level = process.env.NODE_ENV === "production" ? 0 : consolaLogger.level;
26
- //#endregion
27
- export { consolaLogger, logger };
28
-
29
- //# sourceMappingURL=consola.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"consola.js","names":[],"sources":["../src/consola.ts"],"sourcesContent":["import { createConsola } from 'consola';\n\n/**\n * A consola logger with environment-controlled verbosity.\n *\n * @remarks\n * `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;\n * otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.\n * Assign `logger.level` to change verbosity after initialization.\n *\n * @example\n *\n * ```ts\n * import { logger } from '@kikiutils/shared/consola';\n *\n * logger.level = 3;\n * logger.info('Application started');\n * ```\n *\n * @see {@link https://github.com/unjs/consola#log-level | Consola log levels}\n */\nexport const consolaLogger = createConsola();\nexport const logger = consolaLogger;\nif (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;\nelse consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,gBAAgB,cAAc;AAC3C,MAAa,SAAS;AACtB,IAAI,QAAQ,IAAI,yBAAyB,KAAA,GAAW,cAAc,QAAQ,CAAC,QAAQ,IAAI;KAClF,cAAc,QAAQ,QAAQ,IAAI,aAAa,eAAe,IAAI,cAAc"}
package/dist/object.d.ts DELETED
@@ -1,44 +0,0 @@
1
- //#region src/object.d.ts
2
- /**
3
- * Serializes a nested object into a deterministic, flat string format.
4
- *
5
- * @remarks
6
- * This function recursively traverses the input object (including nested objects and arrays),
7
- * flattens it into key paths using dot notation (e.g. "a.b.0.c"), sorts all keys,
8
- * and joins each key-value pair into a string with customizable separators.
9
- *
10
- * It is designed for use cases such as signature generation, cache key construction,
11
- * or any context requiring consistent and predictable object serialization.
12
- *
13
- * Note: Empty objects and arrays produce an empty string, which is useful for
14
- * generating deterministic signature payloads.
15
- *
16
- * @param input - The object to serialize. Can contain nested objects and arrays.
17
- * @param kvSeparator - The string used to separate each key from its value (default: '=').
18
- * @param pairSeparator - The string used to separate each key-value pair (default: '&').
19
- *
20
- * @returns A deterministic string representation of the input object.
21
- *
22
- * @example
23
- *
24
- * ```ts
25
- * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';
26
- *
27
- * console.log(stringifyObjectDeterministically({
28
- * b: 2,
29
- * a: {
30
- * x: 1,
31
- * y: [
32
- * 3,
33
- * 4,
34
- * ],
35
- * },
36
- * })); // => a.x=1&a.y.0=3&a.y.1=4&b=2
37
- *
38
- * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // => foo:bar
39
- * console.log(stringifyObjectDeterministically({})); // => ''
40
- * ```
41
- */
42
- export declare function stringifyObjectDeterministically(input: Record<string, any>, kvSeparator?: string, pairSeparator?: string): string;
43
- //#endregion
44
- //# sourceMappingURL=object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.d.ts","names":[],"sources":["../src/object.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwCgB,iCACZ,OAAO,qBACP,sBACA"}
package/dist/object.js DELETED
@@ -1,59 +0,0 @@
1
- //#region src/object.ts
2
- /**
3
- * Serializes a nested object into a deterministic, flat string format.
4
- *
5
- * @remarks
6
- * This function recursively traverses the input object (including nested objects and arrays),
7
- * flattens it into key paths using dot notation (e.g. "a.b.0.c"), sorts all keys,
8
- * and joins each key-value pair into a string with customizable separators.
9
- *
10
- * It is designed for use cases such as signature generation, cache key construction,
11
- * or any context requiring consistent and predictable object serialization.
12
- *
13
- * Note: Empty objects and arrays produce an empty string, which is useful for
14
- * generating deterministic signature payloads.
15
- *
16
- * @param input - The object to serialize. Can contain nested objects and arrays.
17
- * @param kvSeparator - The string used to separate each key from its value (default: '=').
18
- * @param pairSeparator - The string used to separate each key-value pair (default: '&').
19
- *
20
- * @returns A deterministic string representation of the input object.
21
- *
22
- * @example
23
- *
24
- * ```ts
25
- * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';
26
- *
27
- * console.log(stringifyObjectDeterministically({
28
- * b: 2,
29
- * a: {
30
- * x: 1,
31
- * y: [
32
- * 3,
33
- * 4,
34
- * ],
35
- * },
36
- * })); // => a.x=1&a.y.0=3&a.y.1=4&b=2
37
- *
38
- * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // => foo:bar
39
- * console.log(stringifyObjectDeterministically({})); // => ''
40
- * ```
41
- */
42
- function stringifyObjectDeterministically(input, kvSeparator = "=", pairSeparator = "&") {
43
- const entries = [];
44
- function walk(object, path = []) {
45
- if (Array.isArray(object)) object.forEach((value, i) => {
46
- walk(value, [...path, i.toString()]);
47
- });
48
- else if (object !== null && typeof object === "object" && Object.prototype.toString.call(object) === "[object Object]") Object.keys(object).sort().forEach((key) => {
49
- walk(object[key], [...path, key]);
50
- });
51
- else entries.push(`${path.join(".")}${kvSeparator}${String(object)}`);
52
- }
53
- walk(input);
54
- return entries.sort().join(pairSeparator);
55
- }
56
- //#endregion
57
- export { stringifyObjectDeterministically };
58
-
59
- //# sourceMappingURL=object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.js","names":[],"sources":["../src/object.ts"],"sourcesContent":["/**\n * Serializes a nested object into a deterministic, flat string format.\n *\n * @remarks\n * This function recursively traverses the input object (including nested objects and arrays),\n * flattens it into key paths using dot notation (e.g. \"a.b.0.c\"), sorts all keys,\n * and joins each key-value pair into a string with customizable separators.\n *\n * It is designed for use cases such as signature generation, cache key construction,\n * or any context requiring consistent and predictable object serialization.\n *\n * Note: Empty objects and arrays produce an empty string, which is useful for\n * generating deterministic signature payloads.\n *\n * @param input - The object to serialize. Can contain nested objects and arrays.\n * @param kvSeparator - The string used to separate each key from its value (default: '=').\n * @param pairSeparator - The string used to separate each key-value pair (default: '&').\n *\n * @returns A deterministic string representation of the input object.\n *\n * @example\n *\n * ```ts\n * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';\n *\n * console.log(stringifyObjectDeterministically({\n * b: 2,\n * a: {\n * x: 1,\n * y: [\n * 3,\n * 4,\n * ],\n * },\n * })); // => a.x=1&a.y.0=3&a.y.1=4&b=2\n *\n * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // => foo:bar\n * console.log(stringifyObjectDeterministically({})); // => ''\n * ```\n */\nexport function stringifyObjectDeterministically(\n input: Record<string, any>,\n kvSeparator: string = '=',\n pairSeparator: string = '&',\n) {\n const entries: string[] = [];\n\n function walk(object: any, path: string[] = []) {\n if (Array.isArray(object)) {\n object.forEach((value, i) => {\n walk(\n value,\n [\n ...path,\n i.toString(),\n ],\n );\n });\n } else if (\n object !== null\n && typeof object === 'object'\n && Object.prototype.toString.call(object) === '[object Object]'\n ) {\n Object.keys(object).sort().forEach((key) => {\n walk(\n object[key],\n [\n ...path,\n key,\n ],\n );\n });\n } else entries.push(`${path.join('.')}${kvSeparator}${String(object)}`);\n }\n\n walk(input);\n return entries.sort().join(pairSeparator);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,iCACZ,OACA,cAAsB,KACtB,gBAAwB,KAC1B;CACE,MAAM,UAAoB,CAAC;CAE3B,SAAS,KAAK,QAAa,OAAiB,CAAC,GAAG;EAC5C,IAAI,MAAM,QAAQ,MAAM,GACpB,OAAO,SAAS,OAAO,MAAM;GACzB,KACI,OACA,CACI,GAAG,MACH,EAAE,SAAS,CACf,CACJ;EACJ,CAAC;OACE,IACH,WAAW,QACR,OAAO,WAAW,YAClB,OAAO,UAAU,SAAS,KAAK,MAAM,MAAM,mBAE9C,OAAO,KAAK,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,QAAQ;GACxC,KACI,OAAO,MACP,CACI,GAAG,MACH,GACJ,CACJ;EACJ,CAAC;OACE,QAAQ,KAAK,GAAG,KAAK,KAAK,GAAG,IAAI,cAAc,OAAO,MAAM,GAAG;CAC1E;CAEA,KAAK,KAAK;CACV,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,aAAa;AAC5C"}
package/dist/pino.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { pino } from "pino";
2
- //#region src/pino.d.ts
3
- /**
4
- * A pino logger with environment-controlled verbosity.
5
- *
6
- * @remarks
7
- * `PINO_LOGGER_LEVEL` sets the log level when nonempty at module initialization;
8
- * otherwise, `NODE_ENV=production` selects `error`, and other environments retain the logger's default level.
9
- * Assign `logger.level` to change verbosity after initialization.
10
- *
11
- * @example
12
- *
13
- * ```ts
14
- * import { logger } from '@kikiutils/shared/pino';
15
- *
16
- * logger.level = 'info';
17
- * logger.info('Application started');
18
- * ```
19
- *
20
- * @see {@link https://getpino.io/#/docs/api?id=level-string | Pino log levels}
21
- */
22
- export declare const pinoLogger: pino.Logger<never, boolean>;
23
- export declare const logger: pino.Logger<never, boolean>;
24
- //#endregion
25
- //# sourceMappingURL=pino.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pino.d.ts","names":[],"sources":["../src/pino.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;qBA6Ba,YAAU,KAAA;qBACV,QAAM,KAAA"}
package/dist/pino.js DELETED
@@ -1,34 +0,0 @@
1
- import { pino } from "pino";
2
- import { PinoPretty } from "pino-pretty";
3
- //#region src/pino.ts
4
- const stream = PinoPretty({
5
- colorize: true,
6
- ignore: "hostname,pid",
7
- translateTime: "SYS:yyyy-mm-dd HH:MM:ss.l"
8
- });
9
- /**
10
- * A pino logger with environment-controlled verbosity.
11
- *
12
- * @remarks
13
- * `PINO_LOGGER_LEVEL` sets the log level when nonempty at module initialization;
14
- * otherwise, `NODE_ENV=production` selects `error`, and other environments retain the logger's default level.
15
- * Assign `logger.level` to change verbosity after initialization.
16
- *
17
- * @example
18
- *
19
- * ```ts
20
- * import { logger } from '@kikiutils/shared/pino';
21
- *
22
- * logger.level = 'info';
23
- * logger.info('Application started');
24
- * ```
25
- *
26
- * @see {@link https://getpino.io/#/docs/api?id=level-string | Pino log levels}
27
- */
28
- const pinoLogger = pino({}, stream);
29
- const logger = pinoLogger;
30
- pinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "error" : pinoLogger.level);
31
- //#endregion
32
- export { logger, pinoLogger };
33
-
34
- //# sourceMappingURL=pino.js.map
package/dist/pino.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"pino.js","names":[],"sources":["../src/pino.ts"],"sourcesContent":["import { pino } from 'pino';\nimport { PinoPretty } from 'pino-pretty';\n\n// Configure pretty-printed log output.\nconst stream = PinoPretty({\n colorize: true, // Enable colored output for better readability\n ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs\n translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format\n});\n\n/**\n * A pino logger with environment-controlled verbosity.\n *\n * @remarks\n * `PINO_LOGGER_LEVEL` sets the log level when nonempty at module initialization;\n * otherwise, `NODE_ENV=production` selects `error`, and other environments retain the logger's default level.\n * Assign `logger.level` to change verbosity after initialization.\n *\n * @example\n *\n * ```ts\n * import { logger } from '@kikiutils/shared/pino';\n *\n * logger.level = 'info';\n * logger.info('Application started');\n * ```\n *\n * @see {@link https://getpino.io/#/docs/api?id=level-string | Pino log levels}\n */\nexport const pinoLogger = pino({}, stream);\nexport const logger = pinoLogger;\n// eslint-disable-next-line style/max-len\npinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);\n"],"mappings":";;;AAIA,MAAM,SAAS,WAAW;CACtB,UAAU;CACV,QAAQ;CACR,eAAe;AACnB,CAAC;;;;;;;;;;;;;;;;;;;;AAqBD,MAAa,aAAa,KAAK,CAAC,GAAG,MAAM;AACzC,MAAa,SAAS;AAEtB,WAAW,QAAQ,QAAQ,IAAI,sBAAsB,QAAQ,IAAI,aAAa,eAAe,UAAU,WAAW"}
@@ -1,175 +0,0 @@
1
- import { createConsola } from 'consola';
2
- import type { ConsolaInstance } from 'consola';
3
- import { NodeSSH } from 'node-ssh';
4
- import type {
5
- Config,
6
- SSHExecCommandOptions,
7
- SSHGetPutDirectoryOptions,
8
- SSHPutFilesOptions,
9
- } from 'node-ssh';
10
- import type {
11
- SFTPWrapper,
12
- TransferOptions,
13
- } from 'ssh2';
14
-
15
- import type { PathLike } from './path';
16
-
17
- const loggerLevelStringToConsolaLogLevelMap = {
18
- debug: 4,
19
- error: 0,
20
- fatal: 0,
21
- info: 3,
22
- normal: 2,
23
- silent: -999,
24
- trace: 5,
25
- verbose: 999,
26
- warn: 1,
27
- } as const;
28
-
29
- export class SshClient {
30
- // Private instance properties
31
- readonly #connectConfig: Config;
32
- readonly #logger: ConsolaInstance;
33
- #nodeSsh: NodeSSH;
34
-
35
- // Public instance properties
36
- getDir = this.getDirectory;
37
- putDir = this.putDirectory;
38
-
39
- // Constructor
40
- constructor(host: string, username: string, password: string, port: number = 22, connectConfig?: Config) {
41
- this.#connectConfig = {
42
- ...connectConfig,
43
- host,
44
- password,
45
- port,
46
- username,
47
- };
48
-
49
- this.#logger = createConsola();
50
- this.#nodeSsh = new NodeSSH();
51
- if (process.env.NODE_ENV === 'production') this.setLoggerLevel('error');
52
- }
53
-
54
- // Public instance accessors
55
- get nodeSsh() {
56
- return this.#nodeSsh;
57
- }
58
-
59
- // Public instance methods
60
- async connect() {
61
- try {
62
- this.#nodeSsh = await this.#nodeSsh.connect(this.#connectConfig);
63
- return true;
64
- } catch (error) {
65
- this.#logger.error(error);
66
- return false;
67
- }
68
- }
69
-
70
- disconnect() {
71
- try {
72
- this.#nodeSsh.dispose();
73
- return true;
74
- } catch (error) {
75
- this.#logger.error(error);
76
- return false;
77
- }
78
- }
79
-
80
- execCommand(command: string, options?: SSHExecCommandOptions) {
81
- return this.#nodeSsh.execCommand(command, options).catch(() => {});
82
- }
83
-
84
- execCommandWithIo(command: string, options?: SSHExecCommandOptions) {
85
- return this.execCommand(
86
- command,
87
- {
88
- ...options,
89
- onStderr: (data) => process.stderr.write(data.toString()),
90
- onStdout: (data) => process.stdout.write(data.toString()),
91
- },
92
- );
93
- }
94
-
95
- async getDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {
96
- try {
97
- return await this.#nodeSsh.getDirectory(localDirectory.toString(), remoteDirectory.toString(), options);
98
- } catch (error) {
99
- this.#logger.error(error);
100
- return false;
101
- }
102
- }
103
-
104
- async getFile(
105
- localFile: PathLike,
106
- remoteFile: PathLike,
107
- givenSftp?: null | SFTPWrapper,
108
- transferOptions?: null | TransferOptions,
109
- ) {
110
- try {
111
- await this.#nodeSsh.getFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
112
- return true;
113
- } catch (error) {
114
- this.#logger.error(error);
115
- return false;
116
- }
117
- }
118
-
119
- isConnected() {
120
- return this.#nodeSsh.isConnected();
121
- }
122
-
123
- async mkdir(path: PathLike) {
124
- try {
125
- await this.#nodeSsh.mkdir(path.toString());
126
- return true;
127
- } catch (error) {
128
- this.#logger.error(error);
129
- return false;
130
- }
131
- }
132
-
133
- async putDirectory(localDirectory: PathLike, remoteDirectory: PathLike, options?: SSHGetPutDirectoryOptions) {
134
- try {
135
- return await this.#nodeSsh.putDirectory(localDirectory.toString(), remoteDirectory.toString(), options);
136
- } catch (error) {
137
- this.#logger.error(error);
138
- return false;
139
- }
140
- }
141
-
142
- async putFile(
143
- localFile: PathLike,
144
- remoteFile: PathLike,
145
- givenSftp?: null | SFTPWrapper,
146
- transferOptions?: null | TransferOptions,
147
- ) {
148
- try {
149
- await this.#nodeSsh.putFile(localFile.toString(), remoteFile.toString(), givenSftp, transferOptions);
150
- return true;
151
- } catch (error) {
152
- this.#logger.error(error);
153
- return false;
154
- }
155
- }
156
-
157
- async putFiles(files: { local: PathLike; remote: PathLike }[], options?: SSHPutFilesOptions) {
158
- try {
159
- const convertedFiles = files.map(({ local, remote }) => ({
160
- local: local.toString(),
161
- remote: remote.toString(),
162
- }));
163
-
164
- await this.#nodeSsh.putFiles(convertedFiles, options);
165
- return true;
166
- } catch (error) {
167
- this.#logger.error(error);
168
- return false;
169
- }
170
- }
171
-
172
- setLoggerLevel(level: keyof typeof loggerLevelStringToConsolaLogLevelMap) {
173
- this.#logger.level = loggerLevelStringToConsolaLogLevelMap[level];
174
- }
175
- }
package/src/consola.ts DELETED
@@ -1,25 +0,0 @@
1
- import { createConsola } from 'consola';
2
-
3
- /**
4
- * A consola logger with environment-controlled verbosity.
5
- *
6
- * @remarks
7
- * `CONSOLA_LOGGER_LEVEL` sets the log level when defined at module initialization;
8
- * otherwise, `NODE_ENV=production` selects `0`, and other environments retain the logger's default level.
9
- * Assign `logger.level` to change verbosity after initialization.
10
- *
11
- * @example
12
- *
13
- * ```ts
14
- * import { logger } from '@kikiutils/shared/consola';
15
- *
16
- * logger.level = 3;
17
- * logger.info('Application started');
18
- * ```
19
- *
20
- * @see {@link https://github.com/unjs/consola#log-level | Consola log levels}
21
- */
22
- export const consolaLogger = createConsola();
23
- export const logger = consolaLogger;
24
- if (process.env.CONSOLA_LOGGER_LEVEL !== undefined) consolaLogger.level = +process.env.CONSOLA_LOGGER_LEVEL;
25
- else consolaLogger.level = process.env.NODE_ENV === 'production' ? 0 : consolaLogger.level;
package/src/object.ts DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * Serializes a nested object into a deterministic, flat string format.
3
- *
4
- * @remarks
5
- * This function recursively traverses the input object (including nested objects and arrays),
6
- * flattens it into key paths using dot notation (e.g. "a.b.0.c"), sorts all keys,
7
- * and joins each key-value pair into a string with customizable separators.
8
- *
9
- * It is designed for use cases such as signature generation, cache key construction,
10
- * or any context requiring consistent and predictable object serialization.
11
- *
12
- * Note: Empty objects and arrays produce an empty string, which is useful for
13
- * generating deterministic signature payloads.
14
- *
15
- * @param input - The object to serialize. Can contain nested objects and arrays.
16
- * @param kvSeparator - The string used to separate each key from its value (default: '=').
17
- * @param pairSeparator - The string used to separate each key-value pair (default: '&').
18
- *
19
- * @returns A deterministic string representation of the input object.
20
- *
21
- * @example
22
- *
23
- * ```ts
24
- * import { stringifyObjectDeterministically } from '@kikiutils/shared/object';
25
- *
26
- * console.log(stringifyObjectDeterministically({
27
- * b: 2,
28
- * a: {
29
- * x: 1,
30
- * y: [
31
- * 3,
32
- * 4,
33
- * ],
34
- * },
35
- * })); // => a.x=1&a.y.0=3&a.y.1=4&b=2
36
- *
37
- * console.log(stringifyObjectDeterministically({ foo: 'bar' }, ':', '|')); // => foo:bar
38
- * console.log(stringifyObjectDeterministically({})); // => ''
39
- * ```
40
- */
41
- export function stringifyObjectDeterministically(
42
- input: Record<string, any>,
43
- kvSeparator: string = '=',
44
- pairSeparator: string = '&',
45
- ) {
46
- const entries: string[] = [];
47
-
48
- function walk(object: any, path: string[] = []) {
49
- if (Array.isArray(object)) {
50
- object.forEach((value, i) => {
51
- walk(
52
- value,
53
- [
54
- ...path,
55
- i.toString(),
56
- ],
57
- );
58
- });
59
- } else if (
60
- object !== null
61
- && typeof object === 'object'
62
- && Object.prototype.toString.call(object) === '[object Object]'
63
- ) {
64
- Object.keys(object).sort().forEach((key) => {
65
- walk(
66
- object[key],
67
- [
68
- ...path,
69
- key,
70
- ],
71
- );
72
- });
73
- } else entries.push(`${path.join('.')}${kvSeparator}${String(object)}`);
74
- }
75
-
76
- walk(input);
77
- return entries.sort().join(pairSeparator);
78
- }
package/src/pino.ts DELETED
@@ -1,33 +0,0 @@
1
- import { pino } from 'pino';
2
- import { PinoPretty } from 'pino-pretty';
3
-
4
- // Configure pretty-printed log output.
5
- const stream = PinoPretty({
6
- colorize: true, // Enable colored output for better readability
7
- ignore: 'hostname,pid', // Exclude 'hostname' and 'pid' fields from the logs
8
- translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l', // Format the timestamp in 'yyyy-mm-dd HH:MM:ss.l' format
9
- });
10
-
11
- /**
12
- * A pino logger with environment-controlled verbosity.
13
- *
14
- * @remarks
15
- * `PINO_LOGGER_LEVEL` sets the log level when nonempty at module initialization;
16
- * otherwise, `NODE_ENV=production` selects `error`, and other environments retain the logger's default level.
17
- * Assign `logger.level` to change verbosity after initialization.
18
- *
19
- * @example
20
- *
21
- * ```ts
22
- * import { logger } from '@kikiutils/shared/pino';
23
- *
24
- * logger.level = 'info';
25
- * logger.info('Application started');
26
- * ```
27
- *
28
- * @see {@link https://getpino.io/#/docs/api?id=level-string | Pino log levels}
29
- */
30
- export const pinoLogger = pino({}, stream);
31
- export const logger = pinoLogger;
32
- // eslint-disable-next-line style/max-len
33
- pinoLogger.level = process.env.PINO_LOGGER_LEVEL || (process.env.NODE_ENV === 'production' ? 'error' : pinoLogger.level);