@cyberskill/shared 3.2.0 → 3.3.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 (237) hide show
  1. package/dist/config/commitlint/index.js +8 -9
  2. package/dist/config/commitlint/index.js.map +1 -1
  3. package/dist/config/config.type.js +8 -5
  4. package/dist/config/config.type.js.map +1 -1
  5. package/dist/config/config.util.js +33 -42
  6. package/dist/config/config.util.js.map +1 -1
  7. package/dist/config/env/env.constant.js +6 -5
  8. package/dist/config/env/env.constant.js.map +1 -1
  9. package/dist/config/env/env.util.js +26 -27
  10. package/dist/config/env/env.util.js.map +1 -1
  11. package/dist/config/env/index.js +2 -7
  12. package/dist/config/eslint/index.js +23 -19
  13. package/dist/config/eslint/index.js.map +1 -1
  14. package/dist/config/graphql-codegen/graphql-codegen.util.js +30 -38
  15. package/dist/config/graphql-codegen/graphql-codegen.util.js.map +1 -1
  16. package/dist/config/graphql-codegen/index.js +2 -5
  17. package/dist/config/index.js +3 -7
  18. package/dist/config/lint-staged/index.js +8 -7
  19. package/dist/config/lint-staged/index.js.map +1 -1
  20. package/dist/config/storybook/index.js +2 -6
  21. package/dist/config/storybook/storybook.main.js +19 -18
  22. package/dist/config/storybook/storybook.main.js.map +1 -1
  23. package/dist/config/storybook/storybook.preview.js +31 -37
  24. package/dist/config/storybook/storybook.preview.js.map +1 -1
  25. package/dist/config/vitest/index.js +3 -7
  26. package/dist/config/vitest/vitest.e2e.js +14 -17
  27. package/dist/config/vitest/vitest.e2e.js.map +1 -1
  28. package/dist/config/vitest/vitest.unit.js +31 -32
  29. package/dist/config/vitest/vitest.unit.js.map +1 -1
  30. package/dist/constant/common.js +6 -5
  31. package/dist/constant/common.js.map +1 -1
  32. package/dist/constant/index.js +3 -7
  33. package/dist/constant/response-status.d.ts +186 -186
  34. package/dist/constant/response-status.js +254 -253
  35. package/dist/constant/response-status.js.map +1 -1
  36. package/dist/node/apollo-server/apollo-server.util.js +27 -29
  37. package/dist/node/apollo-server/apollo-server.util.js.map +1 -1
  38. package/dist/node/apollo-server/index.js +2 -7
  39. package/dist/node/cli/index.js +112 -113
  40. package/dist/node/cli/index.js.map +1 -1
  41. package/dist/node/command/command.type.js +8 -5
  42. package/dist/node/command/command.type.js.map +1 -1
  43. package/dist/node/command/command.util.js +136 -149
  44. package/dist/node/command/command.util.js.map +1 -1
  45. package/dist/node/command/index.js +3 -12
  46. package/dist/node/express/express.type.d.ts +11 -0
  47. package/dist/node/express/express.type.js +2 -0
  48. package/dist/node/express/express.util.js +74 -65
  49. package/dist/node/express/express.util.js.map +1 -1
  50. package/dist/node/express/index.js +3 -14
  51. package/dist/node/fs/fs.util.js +27 -51
  52. package/dist/node/fs/fs.util.js.map +1 -1
  53. package/dist/node/fs/index.js +2 -19
  54. package/dist/node/log/index.js +2 -8
  55. package/dist/node/log/log.type.js +8 -5
  56. package/dist/node/log/log.type.js.map +1 -1
  57. package/dist/node/log/log.util.js +51 -68
  58. package/dist/node/log/log.util.js.map +1 -1
  59. package/dist/node/mongo/index.js +8 -26
  60. package/dist/node/mongo/mongo.constant.js +6 -6
  61. package/dist/node/mongo/mongo.constant.js.map +1 -1
  62. package/dist/node/mongo/mongo.controller.mongoose.d.ts +6 -1
  63. package/dist/node/mongo/mongo.controller.mongoose.js +333 -467
  64. package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
  65. package/dist/node/mongo/mongo.controller.native.js +153 -212
  66. package/dist/node/mongo/mongo.controller.native.js.map +1 -1
  67. package/dist/node/mongo/mongo.dynamic-populate.js +164 -192
  68. package/dist/node/mongo/mongo.dynamic-populate.js.map +1 -1
  69. package/dist/node/mongo/mongo.populate.js +229 -262
  70. package/dist/node/mongo/mongo.populate.js.map +1 -1
  71. package/dist/node/mongo/mongo.type.js +8 -17
  72. package/dist/node/mongo/mongo.type.js.map +1 -1
  73. package/dist/node/mongo/mongo.util.js +134 -293
  74. package/dist/node/mongo/mongo.util.js.map +1 -1
  75. package/dist/node/package/index.js +3 -11
  76. package/dist/node/package/package.type.js +8 -5
  77. package/dist/node/package/package.type.js.map +1 -1
  78. package/dist/node/package/package.util.js +216 -225
  79. package/dist/node/package/package.util.js.map +1 -1
  80. package/dist/node/path/index.js +3 -58
  81. package/dist/node/path/path.constant.js +211 -298
  82. package/dist/node/path/path.constant.js.map +1 -1
  83. package/dist/node/path/path.util.js +13 -16
  84. package/dist/node/path/path.util.js.map +1 -1
  85. package/dist/node/storage/index.js +3 -10
  86. package/dist/node/storage/storage.constant.js +6 -8
  87. package/dist/node/storage/storage.constant.js.map +1 -1
  88. package/dist/node/storage/storage.util.js +127 -178
  89. package/dist/node/storage/storage.util.js.map +1 -1
  90. package/dist/node/upload/index.js +4 -16
  91. package/dist/node/upload/upload.constant.js +58 -32
  92. package/dist/node/upload/upload.constant.js.map +1 -1
  93. package/dist/node/upload/upload.type.js +8 -5
  94. package/dist/node/upload/upload.type.js.map +1 -1
  95. package/dist/node/upload/upload.util.js +125 -137
  96. package/dist/node/upload/upload.util.js.map +1 -1
  97. package/dist/node/ws/index.js +2 -6
  98. package/dist/node/ws/ws.type.d.ts +7 -8
  99. package/dist/node/ws/ws.util.js +46 -44
  100. package/dist/node/ws/ws.util.js.map +1 -1
  101. package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js +8 -0
  102. package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js.map +1 -0
  103. package/dist/react/apollo-client/apollo-client.component.js +16 -18
  104. package/dist/react/apollo-client/apollo-client.component.js.map +1 -1
  105. package/dist/react/apollo-client/apollo-client.constant.js +6 -5
  106. package/dist/react/apollo-client/apollo-client.constant.js.map +1 -1
  107. package/dist/react/apollo-client/apollo-client.context.js +10 -13
  108. package/dist/react/apollo-client/apollo-client.context.js.map +1 -1
  109. package/dist/react/apollo-client/apollo-client.module.scss.js +8 -7
  110. package/dist/react/apollo-client/apollo-client.module.scss.js.map +1 -1
  111. package/dist/react/apollo-client/apollo-client.util.js +57 -75
  112. package/dist/react/apollo-client/apollo-client.util.js.map +1 -1
  113. package/dist/react/apollo-client/index.js +7 -30
  114. package/dist/react/apollo-client/links/index.js +2 -5
  115. package/dist/react/apollo-client/links/upload.js +63 -107
  116. package/dist/react/apollo-client/links/upload.js.map +1 -1
  117. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +14 -16
  118. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js.map +1 -1
  119. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js +8 -7
  120. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js.map +1 -1
  121. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +14 -14
  122. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js.map +1 -1
  123. package/dist/react/apollo-client-nextjs/index.js +3 -7
  124. package/dist/react/apollo-error/apollo-error.component.js +57 -69
  125. package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
  126. package/dist/react/apollo-error/apollo-error.context.js +7 -6
  127. package/dist/react/apollo-error/apollo-error.context.js.map +1 -1
  128. package/dist/react/apollo-error/apollo-error.hook.js +10 -10
  129. package/dist/react/apollo-error/apollo-error.hook.js.map +1 -1
  130. package/dist/react/apollo-error/apollo-error.module.scss.js +15 -11
  131. package/dist/react/apollo-error/apollo-error.module.scss.js.map +1 -1
  132. package/dist/react/apollo-error/apollo-error.provider.js +31 -25
  133. package/dist/react/apollo-error/apollo-error.provider.js.map +1 -1
  134. package/dist/react/apollo-error/apollo-error.util.js +14 -16
  135. package/dist/react/apollo-error/apollo-error.util.js.map +1 -1
  136. package/dist/react/apollo-error/index.js +5 -15
  137. package/dist/react/i18next/i18next.hook.js +7 -6
  138. package/dist/react/i18next/i18next.hook.js.map +1 -1
  139. package/dist/react/i18next/i18next.util.js +9 -8
  140. package/dist/react/i18next/i18next.util.js.map +1 -1
  141. package/dist/react/i18next/index.js +3 -7
  142. package/dist/react/loading/index.js +3 -9
  143. package/dist/react/loading/loading.component.js +47 -48
  144. package/dist/react/loading/loading.component.js.map +1 -1
  145. package/dist/react/loading/loading.context.js +7 -6
  146. package/dist/react/loading/loading.context.js.map +1 -1
  147. package/dist/react/loading/loading.hook.js +11 -11
  148. package/dist/react/loading/loading.hook.js.map +1 -1
  149. package/dist/react/loading/loading.module.scss.js +18 -15
  150. package/dist/react/loading/loading.module.scss.js.map +1 -1
  151. package/dist/react/loading/loading.provider.js +26 -18
  152. package/dist/react/loading/loading.provider.js.map +1 -1
  153. package/dist/react/log/index.js +2 -6
  154. package/dist/react/log/log.util.d.ts +8 -0
  155. package/dist/react/log/log.util.js +33 -29
  156. package/dist/react/log/log.util.js.map +1 -1
  157. package/dist/react/next-intl/index.js +6 -14
  158. package/dist/react/next-intl/next-intl.constant.js +16 -15
  159. package/dist/react/next-intl/next-intl.constant.js.map +1 -1
  160. package/dist/react/next-intl/next-intl.context.js +7 -6
  161. package/dist/react/next-intl/next-intl.context.js.map +1 -1
  162. package/dist/react/next-intl/next-intl.hoc.js +20 -23
  163. package/dist/react/next-intl/next-intl.hoc.js.map +1 -1
  164. package/dist/react/next-intl/next-intl.hook.js +13 -14
  165. package/dist/react/next-intl/next-intl.hook.js.map +1 -1
  166. package/dist/react/next-intl/next-intl.provider.js +28 -23
  167. package/dist/react/next-intl/next-intl.provider.js.map +1 -1
  168. package/dist/react/storage/index.js +3 -7
  169. package/dist/react/storage/storage.hook.js +61 -58
  170. package/dist/react/storage/storage.hook.js.map +1 -1
  171. package/dist/react/storage/storage.util.js +36 -68
  172. package/dist/react/storage/storage.util.js.map +1 -1
  173. package/dist/react/toast/index.js +2 -6
  174. package/dist/react/userback/index.js +2 -5
  175. package/dist/react/userback/userback.component.js +27 -27
  176. package/dist/react/userback/userback.component.js.map +1 -1
  177. package/dist/style.css +2 -1
  178. package/dist/typescript/common.type.js +8 -5
  179. package/dist/typescript/common.type.js.map +1 -1
  180. package/dist/typescript/index.js +2 -5
  181. package/dist/util/common/common.util.js +119 -48
  182. package/dist/util/common/common.util.js.map +1 -1
  183. package/dist/util/common/index.js +2 -9
  184. package/dist/util/index.js +6 -27
  185. package/dist/util/object/index.d.ts +3 -0
  186. package/dist/util/object/index.js +2 -10
  187. package/dist/util/object/object.util.js +94 -128
  188. package/dist/util/object/object.util.js.map +1 -1
  189. package/dist/util/serializer/index.js +2 -5
  190. package/dist/util/serializer/serializer.util.js +73 -78
  191. package/dist/util/serializer/serializer.util.js.map +1 -1
  192. package/dist/util/string/index.d.ts +3 -0
  193. package/dist/util/string/index.js +2 -10
  194. package/dist/util/string/string.util.js +59 -71
  195. package/dist/util/string/string.util.js.map +1 -1
  196. package/dist/util/validate/index.d.ts +3 -0
  197. package/dist/util/validate/index.js +2 -5
  198. package/dist/util/validate/validate.util.js +13 -39
  199. package/dist/util/validate/validate.util.js.map +1 -1
  200. package/package.json +29 -27
  201. package/dist/config/env/index.js.map +0 -1
  202. package/dist/config/graphql-codegen/index.js.map +0 -1
  203. package/dist/config/index.js.map +0 -1
  204. package/dist/config/storybook/index.js.map +0 -1
  205. package/dist/config/vitest/index.js.map +0 -1
  206. package/dist/constant/index.js.map +0 -1
  207. package/dist/node/apollo-server/index.js.map +0 -1
  208. package/dist/node/command/index.js.map +0 -1
  209. package/dist/node/express/index.js.map +0 -1
  210. package/dist/node/fs/index.js.map +0 -1
  211. package/dist/node/log/index.js.map +0 -1
  212. package/dist/node/mongo/index.js.map +0 -1
  213. package/dist/node/package/index.js.map +0 -1
  214. package/dist/node/path/index.js.map +0 -1
  215. package/dist/node/storage/index.js.map +0 -1
  216. package/dist/node/upload/index.js.map +0 -1
  217. package/dist/node/ws/index.js.map +0 -1
  218. package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js +0 -7
  219. package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js.map +0 -1
  220. package/dist/react/apollo-client/index.js.map +0 -1
  221. package/dist/react/apollo-client/links/index.js.map +0 -1
  222. package/dist/react/apollo-client-nextjs/index.js.map +0 -1
  223. package/dist/react/apollo-error/index.js.map +0 -1
  224. package/dist/react/i18next/index.js.map +0 -1
  225. package/dist/react/loading/index.js.map +0 -1
  226. package/dist/react/log/index.js.map +0 -1
  227. package/dist/react/next-intl/index.js.map +0 -1
  228. package/dist/react/storage/index.js.map +0 -1
  229. package/dist/react/toast/index.js.map +0 -1
  230. package/dist/react/userback/index.js.map +0 -1
  231. package/dist/typescript/index.js.map +0 -1
  232. package/dist/util/common/index.js.map +0 -1
  233. package/dist/util/index.js.map +0 -1
  234. package/dist/util/object/index.js.map +0 -1
  235. package/dist/util/serializer/index.js.map +0 -1
  236. package/dist/util/string/index.js.map +0 -1
  237. package/dist/util/validate/index.js.map +0 -1
@@ -1,20 +1,17 @@
1
- import r from "node:path";
2
1
  import { getEnv as e } from "../../config/env/env.util.js";
3
- const t = e(), o = r, c = o.dirname;
4
- function m(...n) {
5
- return o.resolve(t.CWD, ...n);
2
+ import t from "node:path";
3
+ //#region src/node/path/path.util.ts
4
+ var n = e(), r = t, i = r.dirname;
5
+ function a(...e) {
6
+ return r.resolve(n.CWD, ...e);
6
7
  }
7
- function u(...n) {
8
- return o.resolve(...n);
8
+ function o(...e) {
9
+ return r.resolve(...e);
9
10
  }
10
- function v(...n) {
11
- return o.join(...n);
11
+ function s(...e) {
12
+ return r.join(...e);
12
13
  }
13
- export {
14
- c as dirname,
15
- v as join,
16
- o as path,
17
- u as resolve,
18
- m as resolveWorkingPath
19
- };
20
- //# sourceMappingURL=path.util.js.map
14
+ //#endregion
15
+ export { i as dirname, s as join, r as path, o as resolve, a as resolveWorkingPath };
16
+
17
+ //# sourceMappingURL=path.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"path.util.js","sources":["../../../src/node/path/path.util.ts"],"sourcesContent":["import pathNode from 'node:path';\n\nimport { getEnv } from '#config/env/index.js';\n\nconst env = getEnv();\n\nexport const path = pathNode;\n\nexport const dirname = path.dirname;\n\n/**\n * Resolves a path relative to the current working directory.\n * This function creates an absolute path by combining the current working directory\n * with the provided path segments, ensuring consistent path resolution across the application.\n *\n * @param urls - Path segments to resolve relative to the current working directory.\n * @returns An absolute path string resolved from the current working directory.\n */\nexport function resolveWorkingPath(...urls: string[]): string {\n return path.resolve(env.CWD, ...urls);\n}\n\n/**\n * Resolves an absolute path from the provided path segments.\n * This function creates an absolute path by combining the provided path segments,\n * similar to Node.js path.resolve but without using the current working directory as base.\n *\n * @param urls - Path segments to resolve into an absolute path.\n * @returns An absolute path string resolved from the provided segments.\n */\nexport function resolve(...urls: string[]): string {\n return path.resolve(...urls);\n}\n\n/**\n * Joins path segments into a single path string.\n * This function combines multiple path segments using the appropriate path separator\n * for the current operating system, similar to Node.js path.join.\n *\n * @param urls - Path segments to join together.\n * @returns A joined path string with appropriate separators.\n */\nexport function join(...urls: string[]): string {\n return path.join(...urls);\n}\n"],"names":["env","getEnv","path","pathNode","dirname","resolveWorkingPath","urls","resolve","join"],"mappings":";;AAIA,MAAMA,IAAMC,EAAA,GAECC,IAAOC,GAEPC,IAAUF,EAAK;AAUrB,SAASG,KAAsBC,GAAwB;AAC1D,SAAOJ,EAAK,QAAQF,EAAI,KAAK,GAAGM,CAAI;AACxC;AAUO,SAASC,KAAWD,GAAwB;AAC/C,SAAOJ,EAAK,QAAQ,GAAGI,CAAI;AAC/B;AAUO,SAASE,KAAQF,GAAwB;AAC5C,SAAOJ,EAAK,KAAK,GAAGI,CAAI;AAC5B;"}
1
+ {"version":3,"file":"path.util.js","names":[],"sources":["../../../src/node/path/path.util.ts"],"sourcesContent":["import pathNode from 'node:path';\n\nimport { getEnv } from '#config/env/index.js';\n\nconst env = getEnv();\n\nexport const path = pathNode;\n\nexport const dirname = path.dirname;\n\n/**\n * Resolves a path relative to the current working directory.\n * This function creates an absolute path by combining the current working directory\n * with the provided path segments, ensuring consistent path resolution across the application.\n *\n * @param urls - Path segments to resolve relative to the current working directory.\n * @returns An absolute path string resolved from the current working directory.\n */\nexport function resolveWorkingPath(...urls: string[]): string {\n return path.resolve(env.CWD, ...urls);\n}\n\n/**\n * Resolves an absolute path from the provided path segments.\n * This function creates an absolute path by combining the provided path segments,\n * similar to Node.js path.resolve but without using the current working directory as base.\n *\n * @param urls - Path segments to resolve into an absolute path.\n * @returns An absolute path string resolved from the provided segments.\n */\nexport function resolve(...urls: string[]): string {\n return path.resolve(...urls);\n}\n\n/**\n * Joins path segments into a single path string.\n * This function combines multiple path segments using the appropriate path separator\n * for the current operating system, similar to Node.js path.join.\n *\n * @param urls - Path segments to join together.\n * @returns A joined path string with appropriate separators.\n */\nexport function join(...urls: string[]): string {\n return path.join(...urls);\n}\n"],"mappings":";;;AAIA,IAAM,IAAM,GAAQ,EAEP,IAAO,GAEP,IAAU,EAAK;AAU5B,SAAgB,EAAmB,GAAG,GAAwB;AAC1D,QAAO,EAAK,QAAQ,EAAI,KAAK,GAAG,EAAK;;AAWzC,SAAgB,EAAQ,GAAG,GAAwB;AAC/C,QAAO,EAAK,QAAQ,GAAG,EAAK;;AAWhC,SAAgB,EAAK,GAAG,GAAwB;AAC5C,QAAO,EAAK,KAAK,GAAG,EAAK"}
@@ -1,10 +1,3 @@
1
- import { NODE_FS_DRIVER_NAME as N, STORAGE_INSTANCE_NAME as A, STORAGE_KEY_EXTENSION as S, STORAGE_STORE_NAME as O } from "./storage.constant.js";
2
- import { storage as T } from "./storage.util.js";
3
- export {
4
- N as NODE_FS_DRIVER_NAME,
5
- A as STORAGE_INSTANCE_NAME,
6
- S as STORAGE_KEY_EXTENSION,
7
- O as STORAGE_STORE_NAME,
8
- T as storage
9
- };
10
- //# sourceMappingURL=index.js.map
1
+ import { NODE_FS_DRIVER_NAME as e, STORAGE_INSTANCE_NAME as t, STORAGE_KEY_EXTENSION as n, STORAGE_STORE_NAME as r } from "./storage.constant.js";
2
+ import { storage as i } from "./storage.util.js";
3
+ export { e as NODE_FS_DRIVER_NAME, t as STORAGE_INSTANCE_NAME, n as STORAGE_KEY_EXTENSION, r as STORAGE_STORE_NAME, i as storage };
@@ -1,8 +1,6 @@
1
- const E = "localforage-node-fs", o = ".json", _ = "cyberskill", s = "node-storage";
2
- export {
3
- E as NODE_FS_DRIVER_NAME,
4
- _ as STORAGE_INSTANCE_NAME,
5
- o as STORAGE_KEY_EXTENSION,
6
- s as STORAGE_STORE_NAME
7
- };
8
- //# sourceMappingURL=storage.constant.js.map
1
+ //#region src/node/storage/storage.constant.ts
2
+ var e = "localforage-node-fs", t = ".json", n = "cyberskill", r = "node-storage";
3
+ //#endregion
4
+ export { e as NODE_FS_DRIVER_NAME, n as STORAGE_INSTANCE_NAME, t as STORAGE_KEY_EXTENSION, r as STORAGE_STORE_NAME };
5
+
6
+ //# sourceMappingURL=storage.constant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.constant.js","sources":["../../../src/node/storage/storage.constant.ts"],"sourcesContent":["export const NODE_FS_DRIVER_NAME = 'localforage-node-fs';\nexport const STORAGE_KEY_EXTENSION = '.json';\nexport const STORAGE_INSTANCE_NAME = 'cyberskill';\nexport const STORAGE_STORE_NAME = 'node-storage';\n"],"names":["NODE_FS_DRIVER_NAME","STORAGE_KEY_EXTENSION","STORAGE_INSTANCE_NAME","STORAGE_STORE_NAME"],"mappings":"AAAO,MAAMA,IAAsB,uBACtBC,IAAwB,SACxBC,IAAwB,cACxBC,IAAqB;"}
1
+ {"version":3,"file":"storage.constant.js","names":[],"sources":["../../../src/node/storage/storage.constant.ts"],"sourcesContent":["export const NODE_FS_DRIVER_NAME = 'localforage-node-fs';\nexport const STORAGE_KEY_EXTENSION = '.json';\nexport const STORAGE_INSTANCE_NAME = 'cyberskill';\nexport const STORAGE_STORE_NAME = 'node-storage';\n"],"mappings":";AAAA,IAAa,IAAsB,uBACtB,IAAwB,SACxB,IAAwB,cACxB,IAAqB"}
@@ -1,183 +1,132 @@
1
- import w from "localforage";
2
- import i from "node:fs/promises";
3
- import E from "node:path";
4
- import { STORAGE_KEY_EXTENSION as d, NODE_FS_DRIVER_NAME as v, STORAGE_STORE_NAME as R, STORAGE_INSTANCE_NAME as I } from "./storage.constant.js";
5
- import { catchError as s, log as h } from "../log/log.util.js";
6
- import { getEnv as S } from "../../config/env/env.util.js";
7
- const l = S(), a = {
8
- baseDir: l.CYBERSKILL_STORAGE_DIRECTORY
9
- };
10
- function g(r) {
11
- return `${encodeURIComponent(r)}${d}`;
1
+ import { getEnv as e } from "../../config/env/env.util.js";
2
+ import { catchError as t, log as n } from "../log/log.util.js";
3
+ import { NODE_FS_DRIVER_NAME as r, STORAGE_INSTANCE_NAME as i, STORAGE_KEY_EXTENSION as a, STORAGE_STORE_NAME as o } from "./storage.constant.js";
4
+ import s from "localforage";
5
+ import c from "node:path";
6
+ import l from "node:fs/promises";
7
+ //#region src/node/storage/storage.util.ts
8
+ var u = { baseDir: "" };
9
+ function d(e) {
10
+ return `${encodeURIComponent(e)}${a}`;
12
11
  }
13
- function _(r) {
14
- return decodeURIComponent(r.slice(0, -d.length));
12
+ function f(e) {
13
+ return decodeURIComponent(e.slice(0, -a.length));
15
14
  }
16
- function y(r, e) {
17
- return E.join(e, g(r));
15
+ function p(e, t) {
16
+ return c.join(t, d(e));
18
17
  }
19
- const c = {
20
- _driver: v,
21
- _support: !0,
22
- /** Ensures the storage directory exists and respects custom baseDir overrides. */
23
- async _initStorage(r) {
24
- try {
25
- const e = typeof r == "object" && r !== null && "baseDir" in r ? r.baseDir : void 0;
26
- typeof e == "string" && e.length > 0 ? a.baseDir = e : a.baseDir = l.CYBERSKILL_STORAGE_DIRECTORY, await i.mkdir(a.baseDir, { recursive: !0 });
27
- } catch (e) {
28
- throw h.error("[Storage:init]", e), e;
29
- }
30
- },
31
- /** Deletes all stored entries by recreating the directory. */
32
- async clear() {
33
- const { baseDir: r } = a;
34
- await i.rm(r, { recursive: !0, force: !0 }), await i.mkdir(r, { recursive: !0 });
35
- },
36
- /** Reads and parses a stored value; returns null when the file is missing. */
37
- async getItem(r) {
38
- const { baseDir: e } = a, t = y(r, e);
39
- try {
40
- const n = await i.readFile(t, "utf8");
41
- return JSON.parse(n);
42
- } catch (n) {
43
- if (n.code === "ENOENT")
44
- return null;
45
- throw n;
46
- }
47
- },
48
- /** Iterates through all keys, invoking the iterator until it returns a value. */
49
- async iterate(r) {
50
- const e = await c.keys();
51
- let t = 1;
52
- for (const n of e) {
53
- const D = await c.getItem(n), f = r(D, n, t);
54
- if (f !== void 0)
55
- return f;
56
- t += 1;
57
- }
58
- },
59
- /** Returns the key name at the given index or null when out of bounds. */
60
- async key(r) {
61
- return (await c.keys())[r] ?? null;
62
- },
63
- /** Lists all stored keys. */
64
- async keys() {
65
- const { baseDir: r } = a;
66
- try {
67
- return (await i.readdir(r)).filter((t) => t.endsWith(d)).map(_);
68
- } catch (e) {
69
- if (e.code === "ENOENT")
70
- return [];
71
- throw e;
72
- }
73
- },
74
- /** Returns the count of stored keys. */
75
- async length() {
76
- return (await c.keys()).length;
77
- },
78
- /** Removes a stored value for the given key. */
79
- async removeItem(r) {
80
- const { baseDir: e } = a, t = y(r, e);
81
- await i.rm(t, { force: !0 });
82
- },
83
- /** Stores a value as JSON on disk. */
84
- async setItem(r, e) {
85
- const { baseDir: t } = a, n = y(r, t);
86
- return await i.mkdir(t, { recursive: !0 }), await i.writeFile(n, JSON.stringify(e), "utf8"), e;
87
- }
88
- };
89
- let o = null, m = null;
90
- async function u() {
91
- return o ? (await o, m) : (o = (async () => {
92
- await w.defineDriver(c), a.baseDir = l.CYBERSKILL_STORAGE_DIRECTORY;
93
- const r = await w.getDriver(v), e = {
94
- baseDir: a.baseDir,
95
- name: I,
96
- storeName: R
97
- };
98
- await r._initStorage(e), m = r;
99
- })().catch((r) => {
100
- throw o = null, r;
101
- }), await o, m);
18
+ var m = {
19
+ _driver: r,
20
+ _support: !0,
21
+ async _initStorage(t) {
22
+ try {
23
+ let n = typeof t == "object" && t && "baseDir" in t ? t.baseDir : void 0;
24
+ typeof n == "string" && n.length > 0 ? u.baseDir = n : u.baseDir = e().CYBERSKILL_STORAGE_DIRECTORY, await l.mkdir(u.baseDir, { recursive: !0 });
25
+ } catch (e) {
26
+ throw n.error("[Storage:init]", e), e;
27
+ }
28
+ },
29
+ async clear() {
30
+ let { baseDir: e } = u;
31
+ e && (await l.rm(e, {
32
+ recursive: !0,
33
+ force: !0
34
+ }), await l.mkdir(e, { recursive: !0 }));
35
+ },
36
+ async getItem(e) {
37
+ let { baseDir: t } = u, n = p(e, t);
38
+ try {
39
+ let e = await l.readFile(n, "utf8");
40
+ return JSON.parse(e);
41
+ } catch (e) {
42
+ if (e.code === "ENOENT") return null;
43
+ throw e;
44
+ }
45
+ },
46
+ async iterate(e) {
47
+ let t = await m.keys(), n = 1;
48
+ for (let r of t) {
49
+ let t = e(await m.getItem(r), r, n);
50
+ if (t !== void 0) return t;
51
+ n += 1;
52
+ }
53
+ },
54
+ async key(e) {
55
+ return (await m.keys())[e] ?? null;
56
+ },
57
+ async keys() {
58
+ let { baseDir: e } = u;
59
+ try {
60
+ return (await l.readdir(e)).filter((e) => e.endsWith(a)).map(f);
61
+ } catch (e) {
62
+ if (e.code === "ENOENT") return [];
63
+ throw e;
64
+ }
65
+ },
66
+ async length() {
67
+ return (await m.keys()).length;
68
+ },
69
+ async removeItem(e) {
70
+ let { baseDir: t } = u, n = p(e, t);
71
+ await l.rm(n, { force: !0 });
72
+ },
73
+ async setItem(e, t) {
74
+ let { baseDir: n } = u, r = p(e, n);
75
+ return await l.mkdir(n, { recursive: !0 }), await l.writeFile(r, JSON.stringify(t), "utf8"), t;
76
+ }
77
+ }, h = null, g = null;
78
+ async function _() {
79
+ return h ? (await h, g) : (h = (async () => {
80
+ await s.defineDriver(m), u.baseDir = e().CYBERSKILL_STORAGE_DIRECTORY;
81
+ let t = await s.getDriver(r);
82
+ await t._initStorage({
83
+ baseDir: u.baseDir,
84
+ name: i,
85
+ storeName: o
86
+ }), g = t;
87
+ })().catch((e) => {
88
+ throw h = null, e;
89
+ }), await h, g);
102
90
  }
103
- const A = {
104
- /**
105
- * Retrieves a value from persistent storage by key.
106
- * This method fetches data that was previously stored using the set method.
107
- * Returns null if the key doesn't exist or if an error occurs.
108
- *
109
- * @param key - The unique identifier for the stored value.
110
- * @returns A promise that resolves to the stored value or null if not found.
111
- */
112
- async get(r) {
113
- try {
114
- return await (await u()).getItem(r) ?? null;
115
- } catch (e) {
116
- return s(e, { returnValue: null });
117
- }
118
- },
119
- /**
120
- * Stores a value in persistent storage with a unique key.
121
- * This method saves data that can be retrieved later using the get method.
122
- * The data is automatically serialized and stored in the configured storage directory.
123
- *
124
- * @param key - The unique identifier for the value to store.
125
- * @param value - The data to store (will be automatically serialized).
126
- * @returns A promise that resolves when the storage operation is complete.
127
- */
128
- async set(r, e) {
129
- try {
130
- await (await u()).setItem(r, e);
131
- } catch (t) {
132
- s(t);
133
- }
134
- },
135
- /**
136
- * Removes a value from persistent storage by key.
137
- * This method permanently deletes the stored data associated with the specified key.
138
- *
139
- * @param key - The unique identifier of the value to remove.
140
- * @returns A promise that resolves when the removal operation is complete.
141
- */
142
- async remove(r) {
143
- try {
144
- await (await u()).removeItem(r);
145
- } catch (e) {
146
- s(e);
147
- }
148
- },
149
- /**
150
- * Retrieves all storage keys.
151
- * This method returns an array of all keys that currently have stored values.
152
- * Returns an empty array if no keys exist or if an error occurs.
153
- *
154
- * @returns A promise that resolves to an array of storage keys.
155
- */
156
- async keys() {
157
- try {
158
- const e = await (await u()).keys();
159
- return Array.isArray(e) ? e : (h.warn("[Storage:keys] Invalid keys response:", e), []);
160
- } catch (r) {
161
- return s(r, { returnValue: [] });
162
- }
163
- },
164
- /**
165
- * Gets a human-readable log link for a storage key.
166
- * This method provides a formatted string that shows the storage directory path
167
- * and the key name for debugging and manual inspection purposes.
168
- *
169
- * @param key - The storage key to generate a log link for.
170
- * @returns A promise that resolves to a formatted log link string or null if an error occurs.
171
- */
172
- async getLogLink(r) {
173
- try {
174
- return `${E.join(l.CYBERSKILL_STORAGE_DIRECTORY, g(r))} (key: ${r})`;
175
- } catch (e) {
176
- return s(e, { returnValue: null });
177
- }
178
- }
179
- };
180
- export {
181
- A as storage
91
+ var v = {
92
+ async get(e) {
93
+ try {
94
+ return await (await _()).getItem(e) ?? null;
95
+ } catch (e) {
96
+ return t(e, { returnValue: null });
97
+ }
98
+ },
99
+ async set(e, n) {
100
+ try {
101
+ await (await _()).setItem(e, n);
102
+ } catch (e) {
103
+ t(e);
104
+ }
105
+ },
106
+ async remove(e) {
107
+ try {
108
+ await (await _()).removeItem(e);
109
+ } catch (e) {
110
+ t(e);
111
+ }
112
+ },
113
+ async keys() {
114
+ try {
115
+ let e = await (await _()).keys();
116
+ return Array.isArray(e) ? e : (n.warn("[Storage:keys] Invalid keys response:", e), []);
117
+ } catch (e) {
118
+ return t(e, { returnValue: [] });
119
+ }
120
+ },
121
+ async getLogLink(n) {
122
+ try {
123
+ return `${c.join(e().CYBERSKILL_STORAGE_DIRECTORY, d(n))} (key: ${n})`;
124
+ } catch (e) {
125
+ return t(e, { returnValue: null });
126
+ }
127
+ }
182
128
  };
183
- //# sourceMappingURL=storage.util.js.map
129
+ //#endregion
130
+ export { v as storage };
131
+
132
+ //# sourceMappingURL=storage.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.util.js","sources":["../../../src/node/storage/storage.util.ts"],"sourcesContent":["import localForage from 'localforage';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { getEnv } from '#config/env/index.js';\n\nimport type { LocalForageDriver, NodeFsDriverState, NodeLocalForageOptions } from './storage.type.js';\n\nimport { catchError, log } from '../log/index.js';\nimport { NODE_FS_DRIVER_NAME, STORAGE_INSTANCE_NAME, STORAGE_KEY_EXTENSION, STORAGE_STORE_NAME } from './storage.constant.js';\n\nconst env = getEnv();\n\nconst nodeFsDriverState: NodeFsDriverState = {\n baseDir: env.CYBERSKILL_STORAGE_DIRECTORY,\n};\n\n/**\n * Encodes a storage key into a filename-safe string.\n */\nfunction encodeKey(key: string): string {\n return `${encodeURIComponent(key)}${STORAGE_KEY_EXTENSION}`;\n}\n\n/**\n * Decodes a filename-safe key back to the original storage key.\n */\nfunction decodeKey(fileName: string): string {\n return decodeURIComponent(fileName.slice(0, -STORAGE_KEY_EXTENSION.length));\n}\n\n/**\n * Maps a storage key to an absolute file path inside the storage directory.\n */\nfunction getFilePath(key: string, baseDir: string): string {\n return path.join(baseDir, encodeKey(key));\n}\n\n/**\n * Custom localForage driver that stores JSON-encoded values on the filesystem.\n */\nconst nodeFsDriver: LocalForageDriver = {\n _driver: NODE_FS_DRIVER_NAME,\n _support: true,\n /** Ensures the storage directory exists and respects custom baseDir overrides. */\n async _initStorage(options: unknown) {\n try {\n const baseDirFromOptions = typeof options === 'object' && options !== null && 'baseDir' in options\n ? (options as { baseDir?: unknown }).baseDir\n : undefined;\n\n if (typeof baseDirFromOptions === 'string' && baseDirFromOptions.length > 0) {\n nodeFsDriverState.baseDir = baseDirFromOptions;\n }\n else {\n nodeFsDriverState.baseDir = env.CYBERSKILL_STORAGE_DIRECTORY;\n }\n\n await fs.mkdir(nodeFsDriverState.baseDir, { recursive: true });\n }\n catch (error) {\n log.error('[Storage:init]', error);\n throw error;\n }\n },\n /** Deletes all stored entries by recreating the directory. */\n async clear() {\n const { baseDir } = nodeFsDriverState;\n\n await fs.rm(baseDir, { recursive: true, force: true });\n await fs.mkdir(baseDir, { recursive: true });\n },\n /** Reads and parses a stored value; returns null when the file is missing. */\n async getItem<T>(key: string): Promise<T | null> {\n const { baseDir } = nodeFsDriverState;\n const filePath = getFilePath(key, baseDir);\n\n try {\n const content = await fs.readFile(filePath, 'utf8');\n\n return JSON.parse(content) as T;\n }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n throw error;\n }\n },\n /** Iterates through all keys, invoking the iterator until it returns a value. */\n async iterate<T, U>(iterator: (value: T, key: string, iterationNumber: number) => U): Promise<U> {\n const keys = await nodeFsDriver.keys();\n let iterationNumber = 1;\n\n for (const key of keys) {\n const value = await nodeFsDriver.getItem<T>(key);\n\n const result = iterator(value as T, key, iterationNumber);\n\n if (result !== undefined) {\n return result;\n }\n iterationNumber += 1;\n }\n\n return undefined as unknown as U;\n },\n /** Returns the key name at the given index or null when out of bounds. */\n async key(keyIndex: number): Promise<string> {\n const keys = await nodeFsDriver.keys();\n\n return keys[keyIndex] ?? null as unknown as string;\n },\n /** Lists all stored keys. */\n async keys(): Promise<string[]> {\n const { baseDir } = nodeFsDriverState;\n\n try {\n const files = await fs.readdir(baseDir);\n\n return files\n .filter(file => file.endsWith(STORAGE_KEY_EXTENSION))\n .map(decodeKey);\n }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return [];\n }\n throw error;\n }\n },\n /** Returns the count of stored keys. */\n async length(): Promise<number> {\n const keys = await nodeFsDriver.keys();\n\n return keys.length;\n },\n /** Removes a stored value for the given key. */\n async removeItem(key: string): Promise<void> {\n const { baseDir } = nodeFsDriverState;\n const filePath = getFilePath(key, baseDir);\n\n await fs.rm(filePath, { force: true });\n },\n /** Stores a value as JSON on disk. */\n async setItem<T>(key: string, value: T): Promise<T> {\n const { baseDir } = nodeFsDriverState;\n const filePath = getFilePath(key, baseDir);\n\n await fs.mkdir(baseDir, { recursive: true });\n await fs.writeFile(filePath, JSON.stringify(value), 'utf8');\n\n return value;\n },\n};\n\nlet initPromise: Promise<void> | null = null;\nlet driverInstance: LocalForageDriver | null = null;\n\n/**\n * Prepares and returns the filesystem-backed localForage driver.\n * We bypass localForage's default driver selection and explicitly initialize\n * our custom driver to ensure Node compatibility.\n */\nasync function ensureLocalForageReady(): Promise<LocalForageDriver> {\n if (initPromise) {\n await initPromise;\n return driverInstance as LocalForageDriver;\n }\n\n initPromise = (async () => {\n await localForage.defineDriver(nodeFsDriver);\n nodeFsDriverState.baseDir = env.CYBERSKILL_STORAGE_DIRECTORY;\n const driver = await localForage.getDriver(NODE_FS_DRIVER_NAME);\n\n const initOptions = {\n baseDir: nodeFsDriverState.baseDir,\n name: STORAGE_INSTANCE_NAME,\n storeName: STORAGE_STORE_NAME,\n } satisfies NodeLocalForageOptions;\n\n await driver._initStorage(initOptions as unknown as Parameters<typeof driver._initStorage>[0]);\n driverInstance = driver;\n })().catch((error) => {\n initPromise = null;\n throw error;\n });\n\n await initPromise;\n\n return driverInstance as LocalForageDriver;\n}\n\n/**\n * Persistent storage utility object for data persistence across application sessions.\n * This object provides methods for storing, retrieving, and managing data using localForage,\n * with automatic initialization and error handling.\n */\nexport const storage = {\n /**\n * Retrieves a value from persistent storage by key.\n * This method fetches data that was previously stored using the set method.\n * Returns null if the key doesn't exist or if an error occurs.\n *\n * @param key - The unique identifier for the stored value.\n * @returns A promise that resolves to the stored value or null if not found.\n */\n async get<T = unknown>(key: string): Promise<T | null> {\n try {\n const driver = await ensureLocalForageReady();\n const result = await driver.getItem<T>(key);\n\n return result ?? null;\n }\n catch (error) {\n return catchError(error, { returnValue: null });\n }\n },\n /**\n * Stores a value in persistent storage with a unique key.\n * This method saves data that can be retrieved later using the get method.\n * The data is automatically serialized and stored in the configured storage directory.\n *\n * @param key - The unique identifier for the value to store.\n * @param value - The data to store (will be automatically serialized).\n * @returns A promise that resolves when the storage operation is complete.\n */\n async set<T = unknown>(key: string, value: T): Promise<void> {\n try {\n const driver = await ensureLocalForageReady();\n\n await driver.setItem(key, value);\n }\n catch (error) {\n catchError(error);\n }\n },\n /**\n * Removes a value from persistent storage by key.\n * This method permanently deletes the stored data associated with the specified key.\n *\n * @param key - The unique identifier of the value to remove.\n * @returns A promise that resolves when the removal operation is complete.\n */\n async remove(key: string): Promise<void> {\n try {\n const driver = await ensureLocalForageReady();\n\n await driver.removeItem(key);\n }\n catch (error) {\n catchError(error);\n }\n },\n /**\n * Retrieves all storage keys.\n * This method returns an array of all keys that currently have stored values.\n * Returns an empty array if no keys exist or if an error occurs.\n *\n * @returns A promise that resolves to an array of storage keys.\n */\n async keys(): Promise<string[]> {\n try {\n const driver = await ensureLocalForageReady();\n const keys = await driver.keys();\n\n if (!Array.isArray(keys)) {\n log.warn(`[Storage:keys] Invalid keys response:`, keys);\n return [];\n }\n\n return keys;\n }\n catch (error) {\n return catchError(error, { returnValue: [] });\n }\n },\n /**\n * Gets a human-readable log link for a storage key.\n * This method provides a formatted string that shows the storage directory path\n * and the key name for debugging and manual inspection purposes.\n *\n * @param key - The storage key to generate a log link for.\n * @returns A promise that resolves to a formatted log link string or null if an error occurs.\n */\n async getLogLink(key: string): Promise<string | null> {\n try {\n const storagePath = path.join(env.CYBERSKILL_STORAGE_DIRECTORY, encodeKey(key));\n\n return `${storagePath} (key: ${key})`;\n }\n catch (error) {\n return catchError(error, { returnValue: null });\n }\n },\n\n};\n"],"names":["env","getEnv","nodeFsDriverState","encodeKey","key","STORAGE_KEY_EXTENSION","decodeKey","fileName","getFilePath","baseDir","path","nodeFsDriver","NODE_FS_DRIVER_NAME","options","baseDirFromOptions","fs","error","log","filePath","content","iterator","keys","iterationNumber","value","result","keyIndex","file","initPromise","driverInstance","ensureLocalForageReady","localForage","driver","initOptions","STORAGE_INSTANCE_NAME","STORAGE_STORE_NAME","storage","catchError"],"mappings":";;;;;;AAWA,MAAMA,IAAMC,EAAA,GAENC,IAAuC;AAAA,EACzC,SAASF,EAAI;AACjB;AAKA,SAASG,EAAUC,GAAqB;AACpC,SAAO,GAAG,mBAAmBA,CAAG,CAAC,GAAGC,CAAqB;AAC7D;AAKA,SAASC,EAAUC,GAA0B;AACzC,SAAO,mBAA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A;AAAA,IAIf,SACOL,GAAO;AACV,aAAOoB,EAAWpB,GAAO,EAAE,aAAa,CAAA,GAAI;AAAA,IAChD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAWZ,GAAqC;AAClD,QAAI;AAGA,aAAO,GAFaM,EAAK,KAAKV,EAAI,8BAA8BG,EAAUC,CAAG,CAAC,CAEzD,UAAUA,CAAG;AAAA,IACtC,SACOY,GAAO;AACV,aAAOoB,EAAWpB,GAAO,EAAE,aAAa,MAAM;AAAA,IAClD;AAAA,EACJ;AAEJ;"}
1
+ {"version":3,"file":"storage.util.js","names":[],"sources":["../../../src/node/storage/storage.util.ts"],"sourcesContent":["import localForage from 'localforage';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { getEnv } from '#config/env/index.js';\n\nimport type { LocalForageDriver, NodeFsDriverState, NodeLocalForageOptions } from './storage.type.js';\n\nimport { catchError, log } from '../log/index.js';\nimport { NODE_FS_DRIVER_NAME, STORAGE_INSTANCE_NAME, STORAGE_KEY_EXTENSION, STORAGE_STORE_NAME } from './storage.constant.js';\n\nconst nodeFsDriverState: NodeFsDriverState = {\n baseDir: '',\n};\n\n/**\n * Encodes a storage key into a filename-safe string.\n */\nfunction encodeKey(key: string): string {\n return `${encodeURIComponent(key)}${STORAGE_KEY_EXTENSION}`;\n}\n\n/**\n * Decodes a filename-safe key back to the original storage key.\n */\nfunction decodeKey(fileName: string): string {\n return decodeURIComponent(fileName.slice(0, -STORAGE_KEY_EXTENSION.length));\n}\n\n/**\n * Maps a storage key to an absolute file path inside the storage directory.\n */\nfunction getFilePath(key: string, baseDir: string): string {\n return path.join(baseDir, encodeKey(key));\n}\n\n/**\n * Custom localForage driver that stores JSON-encoded values on the filesystem.\n */\nconst nodeFsDriver: LocalForageDriver = {\n _driver: NODE_FS_DRIVER_NAME,\n _support: true,\n /** Ensures the storage directory exists and respects custom baseDir overrides. */\n async _initStorage(options: unknown) {\n try {\n const baseDirFromOptions = typeof options === 'object' && options !== null && 'baseDir' in options\n ? (options as { baseDir?: unknown }).baseDir\n : undefined;\n\n if (typeof baseDirFromOptions === 'string' && baseDirFromOptions.length > 0) {\n nodeFsDriverState.baseDir = baseDirFromOptions;\n }\n else {\n nodeFsDriverState.baseDir = getEnv().CYBERSKILL_STORAGE_DIRECTORY;\n }\n\n await fs.mkdir(nodeFsDriverState.baseDir, { recursive: true });\n }\n catch (error) {\n log.error('[Storage:init]', error);\n throw error;\n }\n },\n /** Deletes all stored entries by recreating the directory. Callers must ensure no concurrent operations. */\n async clear() {\n const { baseDir } = nodeFsDriverState;\n\n if (!baseDir) {\n return;\n }\n\n await fs.rm(baseDir, { recursive: true, force: true });\n await fs.mkdir(baseDir, { recursive: true });\n },\n /** Reads and parses a stored value; returns null when the file is missing. */\n async getItem<T>(key: string): Promise<T | null> {\n const { baseDir } = nodeFsDriverState;\n const filePath = getFilePath(key, baseDir);\n\n try {\n const content = await fs.readFile(filePath, 'utf8');\n\n return JSON.parse(content) as T;\n }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n throw error;\n }\n },\n /** Iterates through all keys, invoking the iterator until it returns a value. */\n async iterate<T, U>(iterator: (value: T, key: string, iterationNumber: number) => U): Promise<U> {\n const keys = await nodeFsDriver.keys();\n let iterationNumber = 1;\n\n for (const key of keys) {\n const value = await nodeFsDriver.getItem<T>(key);\n\n const result = iterator(value as T, key, iterationNumber);\n\n if (result !== undefined) {\n return result;\n }\n iterationNumber += 1;\n }\n\n return undefined as unknown as U;\n },\n /** Returns the key name at the given index or null when out of bounds. */\n async key(keyIndex: number): Promise<string> {\n const keys = await nodeFsDriver.keys();\n\n return keys[keyIndex] ?? null as unknown as string;\n },\n /** Lists all stored keys. */\n async keys(): Promise<string[]> {\n const { baseDir } = nodeFsDriverState;\n\n try {\n const files = await fs.readdir(baseDir);\n\n return files\n .filter(file => file.endsWith(STORAGE_KEY_EXTENSION))\n .map(decodeKey);\n }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return [];\n }\n throw error;\n }\n },\n /** Returns the count of stored keys. */\n async length(): Promise<number> {\n const keys = await nodeFsDriver.keys();\n\n return keys.length;\n },\n /** Removes a stored value for the given key. */\n async removeItem(key: string): Promise<void> {\n const { baseDir } = nodeFsDriverState;\n const filePath = getFilePath(key, baseDir);\n\n await fs.rm(filePath, { force: true });\n },\n /** Stores a value as JSON on disk. */\n async setItem<T>(key: string, value: T): Promise<T> {\n const { baseDir } = nodeFsDriverState;\n const filePath = getFilePath(key, baseDir);\n\n await fs.mkdir(baseDir, { recursive: true });\n await fs.writeFile(filePath, JSON.stringify(value), 'utf8');\n\n return value;\n },\n};\n\nlet initPromise: Promise<void> | null = null;\nlet driverInstance: LocalForageDriver | null = null;\n\n/**\n * Prepares and returns the filesystem-backed localForage driver.\n * We bypass localForage's default driver selection and explicitly initialize\n * our custom driver to ensure Node compatibility.\n */\nasync function ensureLocalForageReady(): Promise<LocalForageDriver> {\n if (initPromise) {\n await initPromise;\n return driverInstance as LocalForageDriver;\n }\n\n initPromise = (async () => {\n await localForage.defineDriver(nodeFsDriver);\n nodeFsDriverState.baseDir = getEnv().CYBERSKILL_STORAGE_DIRECTORY;\n const driver = await localForage.getDriver(NODE_FS_DRIVER_NAME);\n\n const initOptions = {\n baseDir: nodeFsDriverState.baseDir,\n name: STORAGE_INSTANCE_NAME,\n storeName: STORAGE_STORE_NAME,\n } satisfies NodeLocalForageOptions;\n\n await driver._initStorage(initOptions as unknown as Parameters<typeof driver._initStorage>[0]);\n driverInstance = driver;\n })().catch((error) => {\n initPromise = null;\n throw error;\n });\n\n await initPromise;\n\n return driverInstance as LocalForageDriver;\n}\n\n/**\n * Persistent storage utility object for data persistence across application sessions.\n * This object provides methods for storing, retrieving, and managing data using localForage,\n * with automatic initialization and error handling.\n */\nexport const storage = {\n /**\n * Retrieves a value from persistent storage by key.\n * This method fetches data that was previously stored using the set method.\n * Returns null if the key doesn't exist or if an error occurs.\n *\n * @param key - The unique identifier for the stored value.\n * @returns A promise that resolves to the stored value or null if not found.\n */\n async get<T = unknown>(key: string): Promise<T | null> {\n try {\n const driver = await ensureLocalForageReady();\n const result = await driver.getItem<T>(key);\n\n return result ?? null;\n }\n catch (error) {\n return catchError(error, { returnValue: null });\n }\n },\n /**\n * Stores a value in persistent storage with a unique key.\n * This method saves data that can be retrieved later using the get method.\n * The data is automatically serialized and stored in the configured storage directory.\n *\n * @param key - The unique identifier for the value to store.\n * @param value - The data to store (will be automatically serialized).\n * @returns A promise that resolves when the storage operation is complete.\n */\n async set<T = unknown>(key: string, value: T): Promise<void> {\n try {\n const driver = await ensureLocalForageReady();\n\n await driver.setItem(key, value);\n }\n catch (error) {\n catchError(error);\n }\n },\n /**\n * Removes a value from persistent storage by key.\n * This method permanently deletes the stored data associated with the specified key.\n *\n * @param key - The unique identifier of the value to remove.\n * @returns A promise that resolves when the removal operation is complete.\n */\n async remove(key: string): Promise<void> {\n try {\n const driver = await ensureLocalForageReady();\n\n await driver.removeItem(key);\n }\n catch (error) {\n catchError(error);\n }\n },\n /**\n * Retrieves all storage keys.\n * This method returns an array of all keys that currently have stored values.\n * Returns an empty array if no keys exist or if an error occurs.\n *\n * @returns A promise that resolves to an array of storage keys.\n */\n async keys(): Promise<string[]> {\n try {\n const driver = await ensureLocalForageReady();\n const keys = await driver.keys();\n\n if (!Array.isArray(keys)) {\n log.warn(`[Storage:keys] Invalid keys response:`, keys);\n return [];\n }\n\n return keys;\n }\n catch (error) {\n return catchError(error, { returnValue: [] });\n }\n },\n /**\n * Gets a human-readable log link for a storage key.\n * This method provides a formatted string that shows the storage directory path\n * and the key name for debugging and manual inspection purposes.\n *\n * @param key - The storage key to generate a log link for.\n * @returns A promise that resolves to a formatted log link string or null if an error occurs.\n */\n async getLogLink(key: string): Promise<string | null> {\n try {\n const storagePath = path.join(getEnv().CYBERSKILL_STORAGE_DIRECTORY, encodeKey(key));\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MAAM,GAEC;;AAQX,IAAa,IAAU;CASnB,MAAM,IAAiB,GAAgC;AACnD,MAAI;AAIA,UAFe,OADA,MAAM,GAAwB,EACjB,QAAW,EAAI,IAE1B;WAEd,GAAO;AACV,UAAO,EAAW,GAAO,EAAE,aAAa,MAAM,CAAC;;;CAYvD,MAAM,IAAiB,GAAa,GAAyB;AACzD,MAAI;AAGA,UAFe,MAAM,GAAwB,EAEhC,QAAQ,GAAK,EAAM;WAE7B,GAAO;AACV,KAAW,EAAM;;;CAUzB,MAAM,OAAO,GAA4B;AACrC,MAAI;AAGA,UAFe,MAAM,GAAwB,EAEhC,WAAW,EAAI;WAEzB,GAAO;AACV,KAAW,EAAM;;;CAUzB,MAAM,OAA0B;AAC5B,MAAI;GAEA,IAAM,IAAO,OADE,MAAM,GAAwB,EACnB,MAAM;AAOhC,UALK,MAAM,QAAQ,EAAK,GAKjB,KAJH,EAAI,KAAK,yCAAyC,EAAK,EAChD,EAAE;WAKV,GAAO;AACV,UAAO,EAAW,GAAO,EAAE,aAAa,EAAE,EAAE,CAAC;;;CAWrD,MAAM,WAAW,GAAqC;AAClD,MAAI;AAGA,UAAO,GAFa,EAAK,KAAK,GAAQ,CAAC,8BAA8B,EAAU,EAAI,CAAC,CAE9D,SAAS,EAAI;WAEhC,GAAO;AACV,UAAO,EAAW,GAAO,EAAE,aAAa,MAAM,CAAC;;;CAI1D"}
@@ -1,16 +1,4 @@
1
- import { BYTES_PER_MB as o, DEFAULT_UPLOAD_CONFIG as t } from "./upload.constant.js";
2
- import { E_UploadType as i } from "./upload.type.js";
3
- import { createUploadConfig as d, getAndValidateFile as p, getFileSizeFromStream as F, getFileWebStream as m, upload as E, validateFileExtension as U, validateUpload as _ } from "./upload.util.js";
4
- export {
5
- o as BYTES_PER_MB,
6
- t as DEFAULT_UPLOAD_CONFIG,
7
- i as E_UploadType,
8
- d as createUploadConfig,
9
- p as getAndValidateFile,
10
- F as getFileSizeFromStream,
11
- m as getFileWebStream,
12
- E as upload,
13
- U as validateFileExtension,
14
- _ as validateUpload
15
- };
16
- //# sourceMappingURL=index.js.map
1
+ import { E_UploadType as e } from "./upload.type.js";
2
+ import { BYTES_PER_MB as t, DEFAULT_UPLOAD_CONFIG as n } from "./upload.constant.js";
3
+ import { createUploadConfig as r, getAndValidateFile as i, getFileSizeFromStream as a, getFileWebStream as o, upload as s, validateFileExtension as c, validateUpload as l } from "./upload.util.js";
4
+ export { t as BYTES_PER_MB, n as DEFAULT_UPLOAD_CONFIG, e as E_UploadType, r as createUploadConfig, i as getAndValidateFile, a as getFileSizeFromStream, o as getFileWebStream, s as upload, c as validateFileExtension, l as validateUpload };
@@ -1,33 +1,59 @@
1
- import { E_UploadType as i } from "./upload.type.js";
2
- const o = 1024 * 1024, s = {
3
- [i.IMAGE]: {
4
- allowedExtensions: ["jpg", "jpeg", "png", "gif", "webp", "svg"],
5
- sizeLimit: 5 * 1024 * 1024
6
- // 5MB
7
- },
8
- [i.VIDEO]: {
9
- allowedExtensions: ["mp4", "avi", "mov", "wmv", "flv", "webm"],
10
- sizeLimit: 500 * 1024 * 1024
11
- // 500MB
12
- },
13
- [i.AUDIO]: {
14
- allowedExtensions: ["mp3", "wav", "ogg", "m4a", "aac"],
15
- sizeLimit: 50 * 1024 * 1024
16
- // 50MB
17
- },
18
- [i.DOCUMENT]: {
19
- allowedExtensions: ["pdf", "doc", "docx", "txt", "rtf"],
20
- sizeLimit: 10 * 1024 * 1024
21
- // 10MB
22
- },
23
- [i.OTHER]: {
24
- allowedExtensions: ["zip", "rar", "tar", "gz"],
25
- sizeLimit: 5 * 1024 * 1024
26
- // 5MB
27
- }
1
+ import { E_UploadType as e } from "./upload.type.js";
2
+ //#region src/node/upload/upload.constant.ts
3
+ var t = 1024 * 1024, n = {
4
+ [e.IMAGE]: {
5
+ allowedExtensions: [
6
+ "jpg",
7
+ "jpeg",
8
+ "png",
9
+ "gif",
10
+ "webp",
11
+ "svg"
12
+ ],
13
+ sizeLimit: 5 * 1024 * 1024
14
+ },
15
+ [e.VIDEO]: {
16
+ allowedExtensions: [
17
+ "mp4",
18
+ "avi",
19
+ "mov",
20
+ "wmv",
21
+ "flv",
22
+ "webm"
23
+ ],
24
+ sizeLimit: 500 * 1024 * 1024
25
+ },
26
+ [e.AUDIO]: {
27
+ allowedExtensions: [
28
+ "mp3",
29
+ "wav",
30
+ "ogg",
31
+ "m4a",
32
+ "aac"
33
+ ],
34
+ sizeLimit: 50 * 1024 * 1024
35
+ },
36
+ [e.DOCUMENT]: {
37
+ allowedExtensions: [
38
+ "pdf",
39
+ "doc",
40
+ "docx",
41
+ "txt",
42
+ "rtf"
43
+ ],
44
+ sizeLimit: 10 * 1024 * 1024
45
+ },
46
+ [e.OTHER]: {
47
+ allowedExtensions: [
48
+ "zip",
49
+ "rar",
50
+ "tar",
51
+ "gz"
52
+ ],
53
+ sizeLimit: 5 * 1024 * 1024
54
+ }
28
55
  };
29
- export {
30
- o as BYTES_PER_MB,
31
- s as DEFAULT_UPLOAD_CONFIG
32
- };
33
- //# sourceMappingURL=upload.constant.js.map
56
+ //#endregion
57
+ export { t as BYTES_PER_MB, n as DEFAULT_UPLOAD_CONFIG };
58
+
59
+ //# sourceMappingURL=upload.constant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload.constant.js","sources":["../../../src/node/upload/upload.constant.ts"],"sourcesContent":["import { E_UploadType } from './upload.type.js';\n\nexport const BYTES_PER_MB = 1024 * 1024;\n\nexport const DEFAULT_UPLOAD_CONFIG = {\n [E_UploadType.IMAGE]: {\n allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'],\n sizeLimit: 5 * 1024 * 1024, // 5MB\n },\n [E_UploadType.VIDEO]: {\n allowedExtensions: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'webm'],\n sizeLimit: 500 * 1024 * 1024, // 500MB\n },\n [E_UploadType.AUDIO]: {\n allowedExtensions: ['mp3', 'wav', 'ogg', 'm4a', 'aac'],\n sizeLimit: 50 * 1024 * 1024, // 50MB\n },\n [E_UploadType.DOCUMENT]: {\n allowedExtensions: ['pdf', 'doc', 'docx', 'txt', 'rtf'],\n sizeLimit: 10 * 1024 * 1024, // 10MB\n },\n [E_UploadType.OTHER]: {\n allowedExtensions: ['zip', 'rar', 'tar', 'gz'],\n sizeLimit: 5 * 1024 * 1024, // 5MB\n },\n};\n"],"names":["BYTES_PER_MB","DEFAULT_UPLOAD_CONFIG","E_UploadType"],"mappings":";AAEO,MAAMA,IAAe,OAAO,MAEtBC,IAAwB;AAAA,EACjC,CAACC,EAAa,KAAK,GAAG;AAAA,IAClB,mBAAmB,CAAC,OAAO,QAAQ,OAAO,OAAO,QAAQ,KAAK;AAAA,IAC9D,WAAW,IAAI,OAAO;AAAA;AAAA,EAAA;AAAA,EAE1B,CAACA,EAAa,KAAK,GAAG;AAAA,IAClB,mBAAmB,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,MAAM;AAAA,IAC7D,WAAW,MAAM,OAAO;AAAA;AAAA,EAAA;AAAA,EAE5B,CAACA,EAAa,KAAK,GAAG;AAAA,IAClB,mBAAmB,CAAC,OAAO,OAAO,OAAO,OAAO,KAAK;AAAA,IACrD,WAAW,KAAK,OAAO;AAAA;AAAA,EAAA;AAAA,EAE3B,CAACA,EAAa,QAAQ,GAAG;AAAA,IACrB,mBAAmB,CAAC,OAAO,OAAO,QAAQ,OAAO,KAAK;AAAA,IACtD,WAAW,KAAK,OAAO;AAAA;AAAA,EAAA;AAAA,EAE3B,CAACA,EAAa,KAAK,GAAG;AAAA,IAClB,mBAAmB,CAAC,OAAO,OAAO,OAAO,IAAI;AAAA,IAC7C,WAAW,IAAI,OAAO;AAAA;AAAA,EAAA;AAE9B;"}
1
+ {"version":3,"file":"upload.constant.js","names":[],"sources":["../../../src/node/upload/upload.constant.ts"],"sourcesContent":["import { E_UploadType } from './upload.type.js';\n\nexport const BYTES_PER_MB = 1024 * 1024;\n\nexport const DEFAULT_UPLOAD_CONFIG = {\n [E_UploadType.IMAGE]: {\n allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'],\n sizeLimit: 5 * 1024 * 1024, // 5MB\n },\n [E_UploadType.VIDEO]: {\n allowedExtensions: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'webm'],\n sizeLimit: 500 * 1024 * 1024, // 500MB\n },\n [E_UploadType.AUDIO]: {\n allowedExtensions: ['mp3', 'wav', 'ogg', 'm4a', 'aac'],\n sizeLimit: 50 * 1024 * 1024, // 50MB\n },\n [E_UploadType.DOCUMENT]: {\n allowedExtensions: ['pdf', 'doc', 'docx', 'txt', 'rtf'],\n sizeLimit: 10 * 1024 * 1024, // 10MB\n },\n [E_UploadType.OTHER]: {\n allowedExtensions: ['zip', 'rar', 'tar', 'gz'],\n sizeLimit: 5 * 1024 * 1024, // 5MB\n },\n};\n"],"mappings":";;AAEA,IAAa,IAAe,OAAO,MAEtB,IAAwB;EAChC,EAAa,QAAQ;EAClB,mBAAmB;GAAC;GAAO;GAAQ;GAAO;GAAO;GAAQ;GAAM;EAC/D,WAAW,IAAI,OAAO;EACzB;EACA,EAAa,QAAQ;EAClB,mBAAmB;GAAC;GAAO;GAAO;GAAO;GAAO;GAAO;GAAO;EAC9D,WAAW,MAAM,OAAO;EAC3B;EACA,EAAa,QAAQ;EAClB,mBAAmB;GAAC;GAAO;GAAO;GAAO;GAAO;GAAM;EACtD,WAAW,KAAK,OAAO;EAC1B;EACA,EAAa,WAAW;EACrB,mBAAmB;GAAC;GAAO;GAAO;GAAQ;GAAO;GAAM;EACvD,WAAW,KAAK,OAAO;EAC1B;EACA,EAAa,QAAQ;EAClB,mBAAmB;GAAC;GAAO;GAAO;GAAO;GAAK;EAC9C,WAAW,IAAI,OAAO;EACzB;CACJ"}
@@ -1,5 +1,8 @@
1
- var D = /* @__PURE__ */ ((O) => (O.IMAGE = "IMAGE", O.VIDEO = "VIDEO", O.AUDIO = "AUDIO", O.DOCUMENT = "DOCUMENT", O.OTHER = "OTHER", O))(D || {});
2
- export {
3
- D as E_UploadType
4
- };
5
- //# sourceMappingURL=upload.type.js.map
1
+ //#region src/node/upload/upload.type.ts
2
+ var e = /* @__PURE__ */ function(e) {
3
+ return e.IMAGE = "IMAGE", e.VIDEO = "VIDEO", e.AUDIO = "AUDIO", e.DOCUMENT = "DOCUMENT", e.OTHER = "OTHER", e;
4
+ }({});
5
+ //#endregion
6
+ export { e as E_UploadType };
7
+
8
+ //# sourceMappingURL=upload.type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload.type.js","sources":["../../../src/node/upload/upload.type.ts"],"sourcesContent":["export enum E_UploadType {\n IMAGE = 'IMAGE',\n VIDEO = 'VIDEO',\n AUDIO = 'AUDIO',\n DOCUMENT = 'DOCUMENT',\n OTHER = 'OTHER',\n}\n\nexport interface I_UploadValidationConfig {\n filename: string;\n fileSize?: number;\n}\n\nexport interface I_UploadTypeConfig {\n allowedExtensions: string[];\n sizeLimit: number;\n}\n\nexport interface I_UploadConfig {\n [E_UploadType.IMAGE]: I_UploadTypeConfig;\n [E_UploadType.VIDEO]: I_UploadTypeConfig;\n [E_UploadType.AUDIO]: I_UploadTypeConfig;\n [E_UploadType.DOCUMENT]: I_UploadTypeConfig;\n [E_UploadType.OTHER]: I_UploadTypeConfig;\n}\n\nexport interface I_UploadFileData {\n createReadStream: () => NodeJS.ReadableStream;\n filename: string;\n}\n\nexport interface I_UploadFile {\n file: I_UploadFileData;\n}\n\nexport interface I_UploadOptions {\n file: Promise<I_UploadFile>;\n path: string;\n type: E_UploadType;\n config?: I_UploadConfig;\n}\n"],"names":["E_UploadType"],"mappings":"AAAO,IAAKA,sBAAAA,OACRA,EAAA,QAAQ,SACRA,EAAA,QAAQ,SACRA,EAAA,QAAQ,SACRA,EAAA,WAAW,YACXA,EAAA,QAAQ,SALAA,IAAAA,KAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"upload.type.js","names":[],"sources":["../../../src/node/upload/upload.type.ts"],"sourcesContent":["export enum E_UploadType {\n IMAGE = 'IMAGE',\n VIDEO = 'VIDEO',\n AUDIO = 'AUDIO',\n DOCUMENT = 'DOCUMENT',\n OTHER = 'OTHER',\n}\n\nexport interface I_UploadValidationConfig {\n filename: string;\n fileSize?: number;\n}\n\nexport interface I_UploadTypeConfig {\n allowedExtensions: string[];\n sizeLimit: number;\n}\n\nexport interface I_UploadConfig {\n [E_UploadType.IMAGE]: I_UploadTypeConfig;\n [E_UploadType.VIDEO]: I_UploadTypeConfig;\n [E_UploadType.AUDIO]: I_UploadTypeConfig;\n [E_UploadType.DOCUMENT]: I_UploadTypeConfig;\n [E_UploadType.OTHER]: I_UploadTypeConfig;\n}\n\nexport interface I_UploadFileData {\n createReadStream: () => NodeJS.ReadableStream;\n filename: string;\n}\n\nexport interface I_UploadFile {\n file: I_UploadFileData;\n}\n\nexport interface I_UploadOptions {\n file: Promise<I_UploadFile>;\n path: string;\n type: E_UploadType;\n config?: I_UploadConfig;\n}\n"],"mappings":";AAAA,IAAY,IAAL,yBAAA,GAAA;QACH,EAAA,QAAA,SACA,EAAA,QAAA,SACA,EAAA,QAAA,SACA,EAAA,WAAA,YACA,EAAA,QAAA;KACH"}