@intlayer/config 6.1.6 → 7.0.0-canary.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 (236) hide show
  1. package/dist/cjs/_virtual/rolldown_runtime.cjs +34 -0
  2. package/dist/cjs/alias.cjs +27 -100
  3. package/dist/cjs/alias.cjs.map +1 -1
  4. package/dist/cjs/built.cjs +7 -25
  5. package/dist/cjs/built.cjs.map +1 -1
  6. package/dist/cjs/bundleJSFile.cjs +30 -51
  7. package/dist/cjs/bundleJSFile.cjs.map +1 -1
  8. package/dist/cjs/client.cjs +19 -52
  9. package/dist/cjs/configFile/buildConfigurationFields.cjs +100 -657
  10. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  11. package/dist/cjs/configFile/getConfiguration.cjs +60 -114
  12. package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
  13. package/dist/cjs/configFile/index.cjs +8 -25
  14. package/dist/cjs/configFile/loadConfigurationFile.cjs +22 -47
  15. package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
  16. package/dist/cjs/configFile/searchConfigurationFile.cjs +49 -55
  17. package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
  18. package/dist/cjs/defaultValues/build.cjs +23 -35
  19. package/dist/cjs/defaultValues/build.cjs.map +1 -1
  20. package/dist/cjs/defaultValues/content.cjs +68 -70
  21. package/dist/cjs/defaultValues/content.cjs.map +1 -1
  22. package/dist/cjs/defaultValues/editor.cjs +29 -41
  23. package/dist/cjs/defaultValues/editor.cjs.map +1 -1
  24. package/dist/cjs/defaultValues/index.cjs +62 -0
  25. package/dist/cjs/defaultValues/index.cjs.map +1 -0
  26. package/dist/cjs/defaultValues/internationalization.cjs +23 -34
  27. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  28. package/dist/cjs/defaultValues/log.cjs +17 -29
  29. package/dist/cjs/defaultValues/log.cjs.map +1 -1
  30. package/dist/cjs/defaultValues/routing.cjs +38 -0
  31. package/dist/cjs/defaultValues/routing.cjs.map +1 -0
  32. package/dist/cjs/extractErrorMessage.cjs +95 -0
  33. package/dist/cjs/extractErrorMessage.cjs.map +1 -0
  34. package/dist/cjs/index.cjs +67 -98
  35. package/dist/cjs/loadEnvFile.cjs +30 -51
  36. package/dist/cjs/loadEnvFile.cjs.map +1 -1
  37. package/dist/cjs/loadExternalFile/bundleFile.cjs +74 -0
  38. package/dist/cjs/loadExternalFile/bundleFile.cjs.map +1 -0
  39. package/dist/cjs/loadExternalFile/loadExternalFile.cjs +86 -0
  40. package/dist/cjs/loadExternalFile/loadExternalFile.cjs.map +1 -0
  41. package/dist/cjs/loadExternalFile/parseFileContent.cjs +67 -0
  42. package/dist/cjs/loadExternalFile/parseFileContent.cjs.map +1 -0
  43. package/dist/cjs/loadExternalFile/transpileTSToMJS.cjs +60 -0
  44. package/dist/cjs/loadExternalFile/transpileTSToMJS.cjs.map +1 -0
  45. package/dist/cjs/logger.cjs +124 -152
  46. package/dist/cjs/logger.cjs.map +1 -1
  47. package/dist/cjs/package.cjs +12 -0
  48. package/dist/cjs/package.cjs.map +1 -0
  49. package/dist/cjs/retryManager.cjs +42 -49
  50. package/dist/cjs/retryManager.cjs.map +1 -1
  51. package/dist/cjs/utils/ESMxCJSHelpers.cjs +24 -33
  52. package/dist/cjs/utils/ESMxCJSHelpers.cjs.map +1 -1
  53. package/dist/cjs/utils/cache.cjs +426 -0
  54. package/dist/cjs/utils/cache.cjs.map +1 -0
  55. package/dist/cjs/utils/clearModuleCache.cjs +23 -46
  56. package/dist/cjs/utils/clearModuleCache.cjs.map +1 -1
  57. package/dist/cjs/utils/extractErrorMessage.cjs +95 -0
  58. package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -0
  59. package/dist/cjs/utils/getExtension.cjs +12 -35
  60. package/dist/cjs/utils/getExtension.cjs.map +1 -1
  61. package/dist/cjs/utils/getPackageJsonPath.cjs +37 -0
  62. package/dist/cjs/utils/getPackageJsonPath.cjs.map +1 -0
  63. package/dist/cjs/utils/logStack.cjs +16 -0
  64. package/dist/cjs/utils/logStack.cjs.map +1 -0
  65. package/dist/cjs/utils/normalizePath.cjs +15 -27
  66. package/dist/cjs/utils/normalizePath.cjs.map +1 -1
  67. package/dist/esm/_virtual/rolldown_runtime.mjs +17 -0
  68. package/dist/esm/alias.mjs +23 -74
  69. package/dist/esm/alias.mjs.map +1 -1
  70. package/dist/esm/built.mjs +5 -3
  71. package/dist/esm/built.mjs.map +1 -1
  72. package/dist/esm/bundleJSFile.mjs +26 -25
  73. package/dist/esm/bundleJSFile.mjs.map +1 -1
  74. package/dist/esm/client.mjs +4 -31
  75. package/dist/esm/configFile/buildConfigurationFields.mjs +97 -674
  76. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  77. package/dist/esm/configFile/getConfiguration.mjs +52 -75
  78. package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
  79. package/dist/esm/configFile/index.mjs +5 -3
  80. package/dist/esm/configFile/loadConfigurationFile.mjs +22 -23
  81. package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
  82. package/dist/esm/configFile/searchConfigurationFile.mjs +45 -30
  83. package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
  84. package/dist/esm/defaultValues/build.mjs +16 -11
  85. package/dist/esm/defaultValues/build.mjs.map +1 -1
  86. package/dist/esm/defaultValues/content.mjs +48 -34
  87. package/dist/esm/defaultValues/content.mjs.map +1 -1
  88. package/dist/esm/defaultValues/editor.mjs +17 -11
  89. package/dist/esm/defaultValues/editor.mjs.map +1 -1
  90. package/dist/esm/defaultValues/index.mjs +21 -0
  91. package/dist/esm/defaultValues/index.mjs.map +1 -0
  92. package/dist/esm/defaultValues/internationalization.mjs +13 -7
  93. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  94. package/dist/esm/defaultValues/log.mjs +10 -4
  95. package/dist/esm/defaultValues/log.mjs.map +1 -1
  96. package/dist/esm/defaultValues/routing.mjs +25 -0
  97. package/dist/esm/defaultValues/routing.mjs.map +1 -0
  98. package/dist/esm/extractErrorMessage.mjs +94 -0
  99. package/dist/esm/extractErrorMessage.mjs.map +1 -0
  100. package/dist/esm/index.mjs +18 -61
  101. package/dist/esm/loadEnvFile.mjs +27 -17
  102. package/dist/esm/loadEnvFile.mjs.map +1 -1
  103. package/dist/esm/loadExternalFile/bundleFile.mjs +68 -0
  104. package/dist/esm/loadExternalFile/bundleFile.mjs.map +1 -0
  105. package/dist/esm/loadExternalFile/loadExternalFile.mjs +81 -0
  106. package/dist/esm/loadExternalFile/loadExternalFile.mjs.map +1 -0
  107. package/dist/esm/loadExternalFile/parseFileContent.mjs +63 -0
  108. package/dist/esm/loadExternalFile/parseFileContent.mjs.map +1 -0
  109. package/dist/esm/loadExternalFile/transpileTSToMJS.mjs +55 -0
  110. package/dist/esm/loadExternalFile/transpileTSToMJS.mjs.map +1 -0
  111. package/dist/esm/logger.mjs +110 -115
  112. package/dist/esm/logger.mjs.map +1 -1
  113. package/dist/esm/package.mjs +6 -0
  114. package/dist/esm/package.mjs.map +1 -0
  115. package/dist/esm/retryManager.mjs +40 -23
  116. package/dist/esm/retryManager.mjs.map +1 -1
  117. package/dist/esm/utils/ESMxCJSHelpers.mjs +20 -6
  118. package/dist/esm/utils/ESMxCJSHelpers.mjs.map +1 -1
  119. package/dist/esm/utils/cache.mjs +414 -0
  120. package/dist/esm/utils/cache.mjs.map +1 -0
  121. package/dist/esm/utils/clearModuleCache.mjs +22 -21
  122. package/dist/esm/utils/clearModuleCache.mjs.map +1 -1
  123. package/dist/esm/utils/extractErrorMessage.mjs +94 -0
  124. package/dist/esm/utils/extractErrorMessage.mjs.map +1 -0
  125. package/dist/esm/utils/getExtension.mjs +11 -11
  126. package/dist/esm/utils/getExtension.mjs.map +1 -1
  127. package/dist/esm/utils/getPackageJsonPath.mjs +33 -0
  128. package/dist/esm/utils/getPackageJsonPath.mjs.map +1 -0
  129. package/dist/esm/utils/logStack.mjs +16 -0
  130. package/dist/esm/utils/logStack.mjs.map +1 -0
  131. package/dist/esm/utils/normalizePath.mjs +14 -3
  132. package/dist/esm/utils/normalizePath.mjs.map +1 -1
  133. package/dist/types/alias.d.ts +20 -12
  134. package/dist/types/alias.d.ts.map +1 -1
  135. package/dist/types/built.d.ts +7 -6
  136. package/dist/types/built.d.ts.map +1 -1
  137. package/dist/types/bundleJSFile.d.ts +97 -93
  138. package/dist/types/bundleJSFile.d.ts.map +1 -1
  139. package/dist/types/client.d.ts +3 -5
  140. package/dist/types/configFile/buildConfigurationFields.d.ts +7 -2
  141. package/dist/types/configFile/buildConfigurationFields.d.ts.map +1 -1
  142. package/dist/types/configFile/getConfiguration.d.ts +19 -15
  143. package/dist/types/configFile/getConfiguration.d.ts.map +1 -1
  144. package/dist/types/configFile/index.d.ts +4 -3
  145. package/dist/types/configFile/loadConfigurationFile.d.ts +8 -3
  146. package/dist/types/configFile/loadConfigurationFile.d.ts.map +1 -1
  147. package/dist/types/configFile/searchConfigurationFile.d.ts +6 -4
  148. package/dist/types/configFile/searchConfigurationFile.d.ts.map +1 -1
  149. package/dist/types/defaultValues/build.d.ts +10 -4
  150. package/dist/types/defaultValues/build.d.ts.map +1 -1
  151. package/dist/types/defaultValues/content.d.ts +23 -16
  152. package/dist/types/defaultValues/content.d.ts.map +1 -1
  153. package/dist/types/defaultValues/editor.d.ts +14 -9
  154. package/dist/types/defaultValues/editor.d.ts.map +1 -1
  155. package/dist/types/defaultValues/index.d.ts +14 -0
  156. package/dist/types/defaultValues/index.d.ts.map +1 -0
  157. package/dist/types/defaultValues/internationalization.d.ts +12 -6
  158. package/dist/types/defaultValues/internationalization.d.ts.map +1 -1
  159. package/dist/types/defaultValues/log.d.ts +7 -2
  160. package/dist/types/defaultValues/log.d.ts.map +1 -1
  161. package/dist/types/defaultValues/routing.d.ts +14 -0
  162. package/dist/types/defaultValues/routing.d.ts.map +1 -0
  163. package/dist/types/extractErrorMessage.d.ts +5 -0
  164. package/dist/types/extractErrorMessage.d.ts.map +1 -0
  165. package/dist/types/index.d.ts +21 -17
  166. package/dist/types/loadEnvFile.d.ts +8 -5
  167. package/dist/types/loadEnvFile.d.ts.map +1 -1
  168. package/dist/types/loadExternalFile/bundleFile.d.ts +10 -0
  169. package/dist/types/loadExternalFile/bundleFile.d.ts.map +1 -0
  170. package/dist/types/loadExternalFile/loadExternalFile.d.ts +25 -0
  171. package/dist/types/loadExternalFile/loadExternalFile.d.ts.map +1 -0
  172. package/dist/types/loadExternalFile/parseFileContent.d.ts +29 -0
  173. package/dist/types/loadExternalFile/parseFileContent.d.ts.map +1 -0
  174. package/dist/types/loadExternalFile/transpileTSToMJS.d.ts +9 -0
  175. package/dist/types/loadExternalFile/transpileTSToMJS.d.ts.map +1 -0
  176. package/dist/types/logger.d.ts +41 -37
  177. package/dist/types/logger.d.ts.map +1 -1
  178. package/dist/types/retryManager.d.ts +26 -8
  179. package/dist/types/retryManager.d.ts.map +1 -1
  180. package/dist/types/utils/ESMxCJSHelpers.d.ts +16 -2
  181. package/dist/types/utils/ESMxCJSHelpers.d.ts.map +1 -1
  182. package/dist/types/utils/cache.d.ts +50 -0
  183. package/dist/types/utils/cache.d.ts.map +1 -0
  184. package/dist/types/utils/clearModuleCache.d.ts +4 -1
  185. package/dist/types/utils/clearModuleCache.d.ts.map +1 -1
  186. package/dist/types/utils/extractErrorMessage.d.ts +5 -0
  187. package/dist/types/utils/extractErrorMessage.d.ts.map +1 -0
  188. package/dist/types/utils/getExtension.d.ts +6 -2
  189. package/dist/types/utils/getExtension.d.ts.map +1 -1
  190. package/dist/types/utils/getPackageJsonPath.d.ts +10 -0
  191. package/dist/types/utils/getPackageJsonPath.d.ts.map +1 -0
  192. package/dist/types/utils/logStack.d.ts +7 -0
  193. package/dist/types/utils/logStack.d.ts.map +1 -0
  194. package/dist/types/utils/normalizePath.d.ts +4 -1
  195. package/dist/types/utils/normalizePath.d.ts.map +1 -1
  196. package/package.json +40 -35
  197. package/LICENSE +0 -202
  198. package/dist/cjs/client.cjs.map +0 -1
  199. package/dist/cjs/configFile/index.cjs.map +0 -1
  200. package/dist/cjs/defaultValues/middleware.cjs +0 -47
  201. package/dist/cjs/defaultValues/middleware.cjs.map +0 -1
  202. package/dist/cjs/getSandboxContext.cjs +0 -64
  203. package/dist/cjs/getSandboxContext.cjs.map +0 -1
  204. package/dist/cjs/index.cjs.map +0 -1
  205. package/dist/cjs/loadExternalFile.cjs +0 -105
  206. package/dist/cjs/loadExternalFile.cjs.map +0 -1
  207. package/dist/cjs/types/config.cjs +0 -17
  208. package/dist/cjs/types/config.cjs.map +0 -1
  209. package/dist/cjs/types/locales.cjs +0 -310
  210. package/dist/cjs/types/locales.cjs.map +0 -1
  211. package/dist/esm/client.mjs.map +0 -1
  212. package/dist/esm/configFile/index.mjs.map +0 -1
  213. package/dist/esm/defaultValues/middleware.mjs +0 -17
  214. package/dist/esm/defaultValues/middleware.mjs.map +0 -1
  215. package/dist/esm/getSandboxContext.mjs +0 -40
  216. package/dist/esm/getSandboxContext.mjs.map +0 -1
  217. package/dist/esm/index.mjs.map +0 -1
  218. package/dist/esm/loadExternalFile.mjs +0 -81
  219. package/dist/esm/loadExternalFile.mjs.map +0 -1
  220. package/dist/esm/types/config.mjs +0 -1
  221. package/dist/esm/types/config.mjs.map +0 -1
  222. package/dist/esm/types/locales.mjs +0 -286
  223. package/dist/esm/types/locales.mjs.map +0 -1
  224. package/dist/types/client.d.ts.map +0 -1
  225. package/dist/types/configFile/index.d.ts.map +0 -1
  226. package/dist/types/defaultValues/middleware.d.ts +0 -8
  227. package/dist/types/defaultValues/middleware.d.ts.map +0 -1
  228. package/dist/types/getSandboxContext.d.ts +0 -4
  229. package/dist/types/getSandboxContext.d.ts.map +0 -1
  230. package/dist/types/index.d.ts.map +0 -1
  231. package/dist/types/loadExternalFile.d.ts +0 -8
  232. package/dist/types/loadExternalFile.d.ts.map +0 -1
  233. package/dist/types/types/config.d.ts +0 -659
  234. package/dist/types/types/config.d.ts.map +0 -1
  235. package/dist/types/types/locales.d.ts +0 -564
  236. package/dist/types/types/locales.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseFileContent.cjs","names":["baseRequire: NodeJS.Require","ESMxCJSRequire","mockedRequire: NodeJS.Require","sandboxContext: Context","loadEnvFile","candidates: unknown[]"],"sources":["../../../src/loadExternalFile/parseFileContent.ts"],"sourcesContent":["import { type Context, runInNewContext } from 'node:vm';\nimport * as esbuild from 'esbuild';\nimport { type LoadEnvFileOptions, loadEnvFile } from '../loadEnvFile';\nimport { ESMxCJSRequire } from '../utils/ESMxCJSHelpers';\n\nexport type SandBoxContextOptions = {\n envVarOptions?: LoadEnvFileOptions;\n projectRequire?: NodeJS.Require;\n additionalEnvVars?: Record<string, string>;\n /**\n * Map of specifier -> mocked export to be returned when code in the VM calls require(specifier).\n * Example:\n * mocks: {\n * '@intlayer/config/built': { getConfig: () => ({}), Locales: {} }\n * }\n */\n mocks?: Record<string, any>;\n /**\n * Optional alias map if you want to redirect specifiers.\n * Useful when user code imports a subpath you want to collapse.\n * Example:\n * aliases: { '@intlayer/config/built': '@intlayer/config' }\n */\n aliases?: Record<string, string>;\n};\n\nexport const getSandBoxContext = (options?: SandBoxContextOptions): Context => {\n const { envVarOptions, projectRequire, additionalEnvVars, mocks, aliases } =\n options ?? {};\n\n let additionalGlobalVar = {};\n\n const baseRequire: NodeJS.Require =\n typeof projectRequire === 'function' ? projectRequire : ESMxCJSRequire;\n\n // Wrap require to honor mocks and aliases inside the VM\n const mockedRequire: NodeJS.Require = (() => {\n const mockTable = Object.assign(\n {\n esbuild,\n },\n mocks\n );\n const aliasTable = Object.assign({}, aliases);\n\n const wrappedRequire = function mockableRequire(id: string) {\n const target = aliasTable?.[id] ? aliasTable[id] : id;\n\n if (mockTable && Object.hasOwn(mockTable, target)) {\n return mockTable[target];\n }\n\n // If the original id was aliased, allow mocks to be defined on either key.\n if (target !== id && mockTable && Object.hasOwn(mockTable, id)) {\n return mockTable[id];\n }\n\n return baseRequire(target);\n } as NodeJS.Require;\n\n // Mirror NodeJS.Require properties\n wrappedRequire.resolve = baseRequire.resolve.bind(baseRequire);\n wrappedRequire.main = baseRequire.main;\n wrappedRequire.extensions = baseRequire.extensions;\n wrappedRequire.cache = baseRequire.cache;\n\n return wrappedRequire;\n })();\n\n try {\n // Dynamically try to require React if it's installed in the project\n additionalGlobalVar = {\n React: baseRequire('react'),\n };\n } catch (_err) {\n // React is not installed, so we don't inject it\n }\n\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n process: {\n ...process,\n env: {\n ...process.env,\n ...loadEnvFile(envVarOptions),\n ...additionalEnvVars,\n },\n },\n console,\n require: mockedRequire,\n ...additionalGlobalVar,\n };\n\n // Dynamically inject all global variables\n Object.getOwnPropertyNames(globalThis).forEach((key) => {\n if (!(key in sandboxContext)) {\n sandboxContext[key] = globalThis[key as keyof typeof globalThis];\n }\n });\n\n return sandboxContext;\n};\n\nexport const parseFileContent = <T>(\n fileContentString: string,\n options?: SandBoxContextOptions\n): T | undefined => {\n const sandboxContext = getSandBoxContext(options);\n\n // Force strict mode so illegal writes throw instead of silently failing.\n runInNewContext(`\"use strict\";\\n${fileContentString}`, sandboxContext);\n\n const candidates: unknown[] = [\n sandboxContext.exports?.default,\n sandboxContext.module?.exports?.defaults,\n sandboxContext.module?.exports?.default,\n sandboxContext.module?.exports,\n ];\n\n for (const candidate of candidates) {\n if (\n candidate &&\n typeof candidate === 'object' &&\n Object.keys(candidate as object).length > 0\n ) {\n return candidate as T;\n }\n }\n};\n"],"mappings":";;;;;;;;;AA0BA,MAAa,qBAAqB,YAA6C;CAC7E,MAAM,EAAE,eAAe,gBAAgB,mBAAmB,OAAO,YAC/D,WAAW,EAAE;CAEf,IAAI,sBAAsB,EAAE;CAE5B,MAAMA,cACJ,OAAO,mBAAmB,aAAa,iBAAiBC;CAG1D,MAAMC,uBAAuC;EAC3C,MAAM,YAAY,OAAO,OACvB,EACE,SACD,EACD,MACD;EACD,MAA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
+ const require_loadExternalFile_bundleFile = require('./bundleFile.cjs');
3
+ let node_path = require("node:path");
4
+ node_path = require_rolldown_runtime.__toESM(node_path);
5
+ let esbuild = require("esbuild");
6
+ esbuild = require_rolldown_runtime.__toESM(esbuild);
7
+ let node_url = require("node:url");
8
+ node_url = require_rolldown_runtime.__toESM(node_url);
9
+
10
+ //#region src/loadExternalFile/transpileTSToMJS.ts
11
+ const getTransformationOptions = (filePath) => ({
12
+ loader: {
13
+ ".js": "js",
14
+ ".jsx": "jsx",
15
+ ".mjs": "js",
16
+ ".ts": "ts",
17
+ ".tsx": "tsx",
18
+ ".cjs": "js",
19
+ ".json": "json",
20
+ ".md": "text",
21
+ ".mdx": "text"
22
+ },
23
+ format: "cjs",
24
+ target: "node20",
25
+ platform: "node",
26
+ write: false,
27
+ packages: "external",
28
+ bundle: true,
29
+ tsconfig: (0, node_path.join)(process.cwd(), "tsconfig.json"),
30
+ define: { "import.meta.url": JSON.stringify((0, node_url.pathToFileURL)(filePath).href) }
31
+ });
32
+ const transpileTSToMJSSync = (code, filePath, options) => {
33
+ return (0, esbuild.buildSync)({
34
+ stdin: {
35
+ contents: code,
36
+ loader: require_loadExternalFile_bundleFile.getLoader((0, node_path.extname)(filePath)),
37
+ resolveDir: (0, node_path.dirname)(filePath),
38
+ sourcefile: filePath
39
+ },
40
+ ...getTransformationOptions(filePath),
41
+ ...options
42
+ }).outputFiles?.[0].text;
43
+ };
44
+ const transpileTSToMJS = async (code, filePath, options) => {
45
+ return (await (0, esbuild.build)({
46
+ stdin: {
47
+ contents: code,
48
+ loader: require_loadExternalFile_bundleFile.getLoader((0, node_path.extname)(filePath)),
49
+ resolveDir: (0, node_path.dirname)(filePath),
50
+ sourcefile: filePath
51
+ },
52
+ ...getTransformationOptions(filePath),
53
+ ...options
54
+ })).outputFiles?.[0].text;
55
+ };
56
+
57
+ //#endregion
58
+ exports.transpileTSToMJS = transpileTSToMJS;
59
+ exports.transpileTSToMJSSync = transpileTSToMJSSync;
60
+ //# sourceMappingURL=transpileTSToMJS.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpileTSToMJS.cjs","names":["getLoader"],"sources":["../../../src/loadExternalFile/transpileTSToMJS.ts"],"sourcesContent":["import { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n build,\n buildSync,\n type Plugin,\n} from 'esbuild';\nimport { getLoader } from './bundleFile';\n\nexport type ESBuildPlugin = Plugin;\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: join(process.cwd(), 'tsconfig.json'),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n },\n});\n\nexport const transpileTSToMJSSync = (\n code: string,\n filePath: string,\n options?: BuildOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = buildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n\nexport const transpileTSToMJS = async (\n code: string,\n filePath: string,\n options?: BuildOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = await build({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAM,4BAA4B,cAAoC;CACpE,QAAQ;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,UAAU;CACV,QAAQ;CACR,8BAAe,QAAQ,KAAK,EAAE,gBAAgB;CAC9C,QAAQ,EACN,mBAAmB,KAAK,sCAAwB,SAAS,CAAC,KAAK,EAChE;CACF;AAED,MAAa,wBACX,MACA,UACA,YACuB;AAiBvB,+BAb4C;EAC1C,OAAO;GACL,UAAU;GACV,QALWA,qEADW,SAAS,CACA;GAM/B,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,CAEsC,cAAc,GAAG;;AAK3D,MAAa,mBAAmB,OAC9B,MACA,UACA,YACgC;AAiBhC,SAbkC,yBAAY;EAC5C,OAAO;GACL,UAAU;GACV,QALWA,qEADW,SAAS,CACA;GAM/B,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,EAEsC,cAAc,GAAG"}
@@ -1,166 +1,138 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var logger_exports = {};
20
- __export(logger_exports, {
21
- ANSIColors: () => ANSIColors,
22
- clock: () => clock,
23
- colon: () => colon,
24
- colorize: () => colorize,
25
- colorizeKey: () => colorizeKey,
26
- colorizeLocales: () => colorizeLocales,
27
- colorizeNumber: () => colorizeNumber,
28
- colorizePath: () => colorizePath,
29
- getAppLogger: () => getAppLogger,
30
- logger: () => logger,
31
- removeColor: () => removeColor,
32
- spinnerFrames: () => spinnerFrames,
33
- v: () => v,
34
- x: () => x
35
- });
36
- module.exports = __toCommonJS(logger_exports);
1
+
2
+ //#region src/logger.ts
37
3
  const logger = (content, details) => {
38
- const isVerbose = details?.isVerbose ?? false;
39
- const mode = details?.config?.mode ?? "default";
40
- const level = details?.level ?? "info";
41
- const prefix = Boolean(details?.config?.prefix) ? details?.config?.prefix : void 0;
42
- const log = details?.config?.log ?? console.log;
43
- const info = details?.config?.info ?? console.info;
44
- const warn = details?.config?.warn ?? console.warn;
45
- const error = details?.config?.error ?? console.error;
46
- const debug = details?.config?.debug ?? console.debug;
47
- if (mode === "disabled") return;
48
- if (isVerbose && mode !== "verbose") return;
49
- const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
50
- if (level === "debug") {
51
- return debug(...flatContent);
52
- }
53
- if (level === "info") {
54
- return info(...flatContent);
55
- }
56
- if (level === "warn") {
57
- return warn(...flatContent);
58
- }
59
- if (level === "error") {
60
- return error(...flatContent);
61
- }
62
- log(...flatContent);
4
+ const isVerbose = details?.isVerbose ?? false;
5
+ const mode = details?.config?.mode ?? "default";
6
+ const level = details?.level ?? "info";
7
+ const prefix = details?.config?.prefix ? details?.config?.prefix : void 0;
8
+ const log = details?.config?.log ?? console.log;
9
+ const info = details?.config?.info ?? console.info;
10
+ const warn = details?.config?.warn ?? console.warn;
11
+ const error = details?.config?.error ?? console.error;
12
+ const debug = details?.config?.debug ?? console.debug;
13
+ if (mode === "disabled") return;
14
+ if (isVerbose && mode !== "verbose") return;
15
+ const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
16
+ if (level === "debug") return debug(...flatContent);
17
+ if (level === "info") return info(...flatContent);
18
+ if (level === "warn") return warn(...flatContent);
19
+ if (level === "error") return error(...flatContent);
20
+ log(...flatContent);
63
21
  };
64
- var ANSIColors = /* @__PURE__ */ ((ANSIColors2) => {
65
- ANSIColors2["RESET"] = "\x1B[0m";
66
- ANSIColors2["GREY"] = "\x1B[90m";
67
- ANSIColors2["GREY_DARK"] = "\x1B[38;5;239m";
68
- ANSIColors2["BLUE"] = "\x1B[34m";
69
- ANSIColors2["RED"] = "\x1B[31m";
70
- ANSIColors2["GREEN"] = "\x1B[32m";
71
- ANSIColors2["YELLOW"] = "\x1B[33m";
72
- ANSIColors2["MAGENTA"] = "\x1B[35m";
73
- ANSIColors2["BEIGE"] = "\x1B[38;5;3m";
74
- ANSIColors2["CYAN"] = "\x1B[36m";
75
- ANSIColors2["WHITE"] = "\x1B[37m";
76
- return ANSIColors2;
77
- })(ANSIColors || {});
78
- const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
22
+ let ANSIColors = /* @__PURE__ */ function(ANSIColors$1) {
23
+ ANSIColors$1["RESET"] = "\x1B[0m";
24
+ ANSIColors$1["GREY"] = "\x1B[90m";
25
+ ANSIColors$1["GREY_DARK"] = "\x1B[38;5;239m";
26
+ ANSIColors$1["BLUE"] = "\x1B[34m";
27
+ ANSIColors$1["RED"] = "\x1B[31m";
28
+ ANSIColors$1["GREEN"] = "\x1B[32m";
29
+ ANSIColors$1["YELLOW"] = "\x1B[38;5;226m";
30
+ ANSIColors$1["MAGENTA"] = "\x1B[35m";
31
+ ANSIColors$1["BEIGE"] = "\x1B[38;5;3m";
32
+ ANSIColors$1["ORANGE"] = "\x1B[38;5;208m";
33
+ ANSIColors$1["CYAN"] = "\x1B[36m";
34
+ ANSIColors$1["WHITE"] = "\x1B[37m";
35
+ return ANSIColors$1;
36
+ }({});
37
+ const spinnerFrames = [
38
+ "⠋",
39
+ "⠙",
40
+ "⠹",
41
+ "⠸",
42
+ "⠼",
43
+ "⠴",
44
+ "⠦",
45
+ "⠧",
46
+ "⠇",
47
+ "⠏"
48
+ ];
49
+ /**
50
+ * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.
51
+ * It allows overriding the default configuration by passing a config object in the details parameter.
52
+ * The configuration is merged with the default configuration from the intlayer config file.
53
+ */
79
54
  const getAppLogger = (configuration, globalDetails) => (content, details) => logger(content, {
80
- ...details ?? {},
81
- config: {
82
- ...configuration?.log,
83
- ...globalDetails?.config,
84
- ...details?.config ?? {}
85
- }
55
+ ...details ?? {},
56
+ config: {
57
+ ...configuration?.log,
58
+ ...globalDetails?.config,
59
+ ...details?.config ?? {}
60
+ }
86
61
  });
87
- const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? "\x1B[0m" /* RESET */ : reset : "\x1B[0m" /* RESET */}` : s;
88
- const colorizeLocales = (locales, color = "\x1B[32m" /* GREEN */, reset = "\x1B[0m" /* RESET */) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
89
- const colorizeKey = (keyPath, color = "\x1B[38;5;3m" /* BEIGE */, reset = "\x1B[0m" /* RESET */) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
90
- const colorizePath = (path, color = "\x1B[90m" /* GREY */, reset = "\x1B[0m" /* RESET */) => [path].flat().map((p) => colorize(p, color, reset)).join(`, `);
62
+ const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? ANSIColors.RESET : reset : ANSIColors.RESET}` : s;
63
+ const colorizeLocales = (locales, color = ANSIColors.GREEN, reset = ANSIColors.RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
64
+ const colorizeKey = (keyPath, color = ANSIColors.BEIGE, reset = ANSIColors.RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
65
+ const colorizePath = (path, color = ANSIColors.GREY, reset = ANSIColors.RESET) => [path].flat().map((p) => colorize(p, color, reset)).join(`, `);
66
+ /**
67
+ * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.
68
+ *
69
+ * Examples:
70
+ * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // "'\x1b[31m2\x1b[0m"
71
+ */
91
72
  const colorizeNumber = (number, options = {
92
- zero: "\x1B[34m" /* BLUE */,
93
- one: "\x1B[34m" /* BLUE */,
94
- two: "\x1B[34m" /* BLUE */,
95
- few: "\x1B[34m" /* BLUE */,
96
- many: "\x1B[34m" /* BLUE */,
97
- other: "\x1B[34m" /* BLUE */
73
+ zero: ANSIColors.BLUE,
74
+ one: ANSIColors.BLUE,
75
+ two: ANSIColors.BLUE,
76
+ few: ANSIColors.BLUE,
77
+ many: ANSIColors.BLUE,
78
+ other: ANSIColors.BLUE
98
79
  }) => {
99
- if (number === 0) {
100
- const color2 = options.zero ?? "\x1B[32m" /* GREEN */;
101
- return colorize(number.toString(), color2);
102
- }
103
- const rule = new Intl.PluralRules("en").select(number);
104
- const color = options[rule];
105
- return colorize(number.toString(), color);
80
+ if (number === 0) {
81
+ const color$1 = options.zero ?? ANSIColors.GREEN;
82
+ return colorize(number.toString(), color$1);
83
+ }
84
+ const color = options[new Intl.PluralRules("en").select(number)];
85
+ return colorize(number.toString(), color);
106
86
  };
107
87
  const removeColor = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
108
88
  const getLength = (length) => {
109
- let value = 0;
110
- if (typeof length === "number") {
111
- value = length;
112
- }
113
- if (typeof length === "string") {
114
- value = length.length;
115
- }
116
- if (Array.isArray(length) && length.every((l) => typeof l === "string")) {
117
- value = Math.max(...length.map((str) => str.length));
118
- }
119
- if (Array.isArray(length) && length.every((l) => typeof l === "number")) {
120
- value = Math.max(...length);
121
- }
122
- return Math.max(value, 0);
89
+ let value = 0;
90
+ if (typeof length === "number") value = length;
91
+ if (typeof length === "string") value = length.length;
92
+ if (Array.isArray(length) && length.every((l) => typeof l === "string")) value = Math.max(...length.map((str) => str.length));
93
+ if (Array.isArray(length) && length.every((l) => typeof l === "number")) value = Math.max(...length);
94
+ return Math.max(value, 0);
123
95
  };
124
96
  const defaultColonOptions = {
125
- colSize: 0,
126
- minSize: 0,
127
- maxSize: Infinity,
128
- pad: "right",
129
- padChar: "0"
97
+ colSize: 0,
98
+ minSize: 0,
99
+ maxSize: Infinity,
100
+ pad: "right",
101
+ padChar: "0"
130
102
  };
131
- const colon = (text, options) => [text].flat().map((text2) => {
132
- const { colSize, minSize, maxSize, pad, padChar } = {
133
- ...defaultColonOptions,
134
- ...options ?? {}
135
- };
136
- const length = getLength(colSize);
137
- const spacesLength = Math.max(
138
- minSize,
139
- Math.min(maxSize, length - removeColor(text2).length)
140
- );
141
- if (pad === "left") {
142
- return `${" ".repeat(spacesLength)}${text2}`;
143
- }
144
- return `${text2}${" ".repeat(spacesLength)}`;
103
+ /**
104
+ * Create a string of spaces of a given length.
105
+ *
106
+ * @param colSize - The length of the string to create.
107
+ * @returns A string of spaces.
108
+ */
109
+ const colon = (text, options) => [text].flat().map((text$1) => {
110
+ const { colSize, minSize, maxSize, pad, padChar } = {
111
+ ...defaultColonOptions,
112
+ ...options ?? {}
113
+ };
114
+ const length = getLength(colSize);
115
+ const spacesLength = Math.max(minSize, Math.min(maxSize, length - removeColor(text$1).length));
116
+ if (pad === "left") return `${" ".repeat(spacesLength)}${text$1}`;
117
+ return `${text$1}${" ".repeat(spacesLength)}`;
145
118
  }).join("");
146
- const x = colorize("\u2717", "\x1B[31m" /* RED */);
147
- const v = colorize("\u2713", "\x1B[32m" /* GREEN */);
148
- const clock = colorize("\u23F2", "\x1B[34m" /* BLUE */);
149
- // Annotate the CommonJS export names for ESM import in node:
150
- 0 && (module.exports = {
151
- ANSIColors,
152
- clock,
153
- colon,
154
- colorize,
155
- colorizeKey,
156
- colorizeLocales,
157
- colorizeNumber,
158
- colorizePath,
159
- getAppLogger,
160
- logger,
161
- removeColor,
162
- spinnerFrames,
163
- v,
164
- x
165
- });
119
+ const x = colorize("", ANSIColors.RED);
120
+ const v = colorize("", ANSIColors.GREEN);
121
+ const clock = colorize("", ANSIColors.BLUE);
122
+
123
+ //#endregion
124
+ exports.ANSIColors = ANSIColors;
125
+ exports.clock = clock;
126
+ exports.colon = colon;
127
+ exports.colorize = colorize;
128
+ exports.colorizeKey = colorizeKey;
129
+ exports.colorizeLocales = colorizeLocales;
130
+ exports.colorizeNumber = colorizeNumber;
131
+ exports.colorizePath = colorizePath;
132
+ exports.getAppLogger = getAppLogger;
133
+ exports.logger = logger;
134
+ exports.removeColor = removeColor;
135
+ exports.spinnerFrames = spinnerFrames;
136
+ exports.v = v;
137
+ exports.x = x;
166
138
  //# sourceMappingURL=logger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/logger.ts"],"sourcesContent":["import type { CustomIntlayerConfig } from './types/config';\nimport { Locales } from './types/locales';\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nexport const logger: Logger = (content, details) => {\n const isVerbose = details?.isVerbose ?? false;\n const mode = details?.config?.mode ?? 'default';\n const level = details?.level ?? 'info';\n const prefix = Boolean(details?.config?.prefix)\n ? details?.config?.prefix\n : undefined;\n const log = details?.config?.log ?? console.log;\n const info = details?.config?.info ?? console.info;\n const warn = details?.config?.warn ?? console.warn;\n const error = details?.config?.error ?? console.error;\n const debug = details?.config?.debug ?? console.debug;\n\n if (mode === 'disabled') return;\n\n if (isVerbose && mode !== 'verbose') return;\n\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n\n if (level === 'debug') {\n return debug(...flatContent);\n }\n\n if (level === 'info') {\n return info(...flatContent);\n }\n\n if (level === 'warn') {\n return warn(...flatContent);\n }\n\n if (level === 'error') {\n return error(...flatContent);\n }\n\n log(...flatContent);\n};\n\nexport enum ANSIColors {\n RESET = '\\x1b[0m',\n GREY = '\\x1b[90m',\n GREY_DARK = '\\x1b[38;5;239m',\n BLUE = '\\x1b[34m',\n RED = '\\x1b[31m',\n GREEN = '\\x1b[32m',\n YELLOW = '\\x1b[33m',\n MAGENTA = '\\x1b[35m',\n BEIGE = '\\x1b[38;5;3m',\n CYAN = '\\x1b[36m',\n WHITE = '\\x1b[37m',\n}\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: CustomIntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n s: string,\n color?: ANSIColors,\n reset?: boolean | ANSIColors\n): string =>\n color\n ? `${color}${s}${reset ? (typeof reset === 'boolean' ? ANSIColors.RESET : reset) : ANSIColors.RESET}`\n : s;\n\nexport const colorizeLocales = (\n locales: Locales | Locales[],\n color = ANSIColors.GREEN,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color = ANSIColors.BEIGE,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color = ANSIColors.GREY,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [path]\n .flat()\n .map((p) => colorize(p, color, reset))\n .join(`, `);\n\n/**\n * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.\n *\n * Examples:\n * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // \"'\\x1b[31m2\\x1b[0m\"\n */\nexport const colorizeNumber = (\n number: number,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColors>> = {\n zero: ANSIColors.BLUE,\n one: ANSIColors.BLUE,\n two: ANSIColors.BLUE,\n few: ANSIColors.BLUE,\n many: ANSIColors.BLUE,\n other: ANSIColors.BLUE,\n }\n): string => {\n if (number === 0) {\n const color = options.zero ?? ANSIColors.GREEN;\n return colorize(number.toString(), color);\n }\n\n const rule = new Intl.PluralRules('en').select(number);\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'string')) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'number')) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad, padChar } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', ANSIColors.RED);\nexport const v = colorize('✓', ANSIColors.GREEN);\nexport const clock = colorize('⏲', ANSIColors.BLUE);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAM,SAAiB,CAAC,SAAS,YAAY;AAClD,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,OAAO,SAAS,QAAQ,QAAQ;AACtC,QAAM,QAAQ,SAAS,SAAS;AAChC,QAAM,SAAS,QAAQ,SAAS,QAAQ,MAAM,IAC1C,SAAS,QAAQ,SACjB;AACJ,QAAM,MAAM,SAAS,QAAQ,OAAO,QAAQ;AAC5C,QAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;AAC9C,QAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;AAC9C,QAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;AAChD,QAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;AAEhD,MAAI,SAAS,WAAY;AAEzB,MAAI,aAAa,SAAS,UAAW;AAErC,QAAM,cAAc,SAAS,CAAC,QAAQ,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK;AAE5E,MAAI,UAAU,SAAS;AACrB,WAAO,MAAM,GAAG,WAAW;AAAA,EAC7B;AAEA,MAAI,UAAU,QAAQ;AACpB,WAAO,KAAK,GAAG,WAAW;AAAA,EAC5B;AAEA,MAAI,UAAU,QAAQ;AACpB,WAAO,KAAK,GAAG,WAAW;AAAA,EAC5B;AAEA,MAAI,UAAU,SAAS;AACrB,WAAO,MAAM,GAAG,WAAW;AAAA,EAC7B;AAEA,MAAI,GAAG,WAAW;AACpB;A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I;AAAA,IAClD,GAAG;AAAA,IACH,GAAI,WAAW,CAAC;AAAA,EAClB;AAEA,QAAM,SAAS,UAAU,OAAO;AAChC,QAAM,eAAe,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,IAAI,SAAU,SAAS,YAAYA,KAAI,EAAE,MAAM;AAAA,EACtD;AAEA,MAAI,QAAQ,QAAQ;AAClB,WAAO,GAAG,IAAI,OAAO,YAAY,CAAC,GAAGA,KAAI;AAAA,EAC3C;AAEA,SAAO,GAAGA,KAAI,GAAG,IAAI,OAAO,YAAY,CAAC;AAC3C,CAAC,EACA,KAAK,EAAE;AAEL,MAAM,IAAI,SAAS,UAAK,oBAAc;AACtC,MAAM,IAAI,SAAS,UAAK,sBAAgB;AACxC,MAAM,QAAQ,SAAS,UAAK,qBAAe;","names":["ANSIColors","color","text"]}
1
+ {"version":3,"file":"logger.cjs","names":["logger: Logger","color","value: number","text"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { CustomIntlayerConfig, Locale } from '@intlayer/types';\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nexport const logger: Logger = (content, details) => {\n const isVerbose = details?.isVerbose ?? false;\n const mode = details?.config?.mode ?? 'default';\n const level = details?.level ?? 'info';\n const prefix = details?.config?.prefix ? details?.config?.prefix : undefined;\n const log = details?.config?.log ?? console.log;\n const info = details?.config?.info ?? console.info;\n const warn = details?.config?.warn ?? console.warn;\n const error = details?.config?.error ?? console.error;\n const debug = details?.config?.debug ?? console.debug;\n\n if (mode === 'disabled') return;\n\n if (isVerbose && mode !== 'verbose') return;\n\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n\n if (level === 'debug') {\n return debug(...flatContent);\n }\n\n if (level === 'info') {\n return info(...flatContent);\n }\n\n if (level === 'warn') {\n return warn(...flatContent);\n }\n\n if (level === 'error') {\n return error(...flatContent);\n }\n\n log(...flatContent);\n};\n\nexport enum ANSIColors {\n RESET = '\\x1b[0m',\n GREY = '\\x1b[90m',\n GREY_DARK = '\\x1b[38;5;239m',\n BLUE = '\\x1b[34m',\n RED = '\\x1b[31m',\n GREEN = '\\x1b[32m',\n YELLOW = '\\x1b[38;5;226m',\n MAGENTA = '\\x1b[35m',\n BEIGE = '\\x1b[38;5;3m',\n ORANGE = '\\x1b[38;5;208m',\n CYAN = '\\x1b[36m',\n WHITE = '\\x1b[37m',\n}\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: CustomIntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n s: string,\n color?: ANSIColors,\n reset?: boolean | ANSIColors\n): string =>\n color\n ? `${color}${s}${reset ? (typeof reset === 'boolean' ? ANSIColors.RESET : reset) : ANSIColors.RESET}`\n : s;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color = ANSIColors.GREEN,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color = ANSIColors.BEIGE,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color = ANSIColors.GREY,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [path]\n .flat()\n .map((p) => colorize(p, color, reset))\n .join(`, `);\n\n/**\n * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.\n *\n * Examples:\n * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // \"'\\x1b[31m2\\x1b[0m\"\n */\nexport const colorizeNumber = (\n number: number,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColors>> = {\n zero: ANSIColors.BLUE,\n one: ANSIColors.BLUE,\n two: ANSIColors.BLUE,\n few: ANSIColors.BLUE,\n many: ANSIColors.BLUE,\n other: ANSIColors.BLUE,\n }\n): string => {\n if (number === 0) {\n const color = options.zero ?? ANSIColors.GREEN;\n return colorize(number.toString(), color);\n }\n\n const rule = new Intl.PluralRules('en').select(number);\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'string')) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'number')) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad, padChar } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', ANSIColors.RED);\nexport const v = colorize('✓', ANSIColors.GREEN);\nexport const clock = colorize('⏲', ANSIColors.BLUE);\n"],"mappings":";;AAUA,MAAaA,UAAkB,SAAS,YAAY;CAClD,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,OAAO,SAAS,QAAQ,QAAQ;CACtC,MAAM,QAAQ,SAAS,SAAS;CAChC,MAAM,SAAS,SAAS,QAAQ,SAAS,SAAS,QAAQ,SAAS;CACnE,MAAM,MAAM,SAAS,QAAQ,OAAO,QAAQ;CAC5C,MAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;CAC9C,MAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;CAC9C,MAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;CAChD,MAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;AAEhD,KAAI,SAAS,WAAY;AAEzB,KAAI,aAAa,SAAS,UAAW;CAErC,MAAM,cAAc,SAAS,CAAC,QAAQ,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM;AAE7E,KAAI,UAAU,QACZ,QAAO,MAAM,GAAG,YAAY;AAG9B,KAAI,UAAU,OACZ,QAAO,KAAK,GAAG,YAAY;AAG7B,KAAI,UAAU,OACZ,QAAO,KAAK,GAAG,YAAY;AAG7B,KAAI,UAAU,QACZ,QAAO,MAAM,GAAG,YAAY;AAG9B,KAAI,GAAG,YAAY;;AAGrB,IAAY,oDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGF,MAAa,gBAAgB;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;;;;;;AAO/E,MAAa,gBACV,eAAsC,mBACtC,S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KAAI,OAAO,WAAW,SACpB,SAAQ,OAAO;AAEjB,KAAI,MAAM,QAAQ,OAAO,IAAI,OAAO,OAAO,MAAM,OAAO,MAAM,SAAS,CACrE,SAAQ,KAAK,IAAI,GAAG,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC;AAEtD,KAAI,MAAM,QAAQ,OAAO,IAAI,OAAO,OAAO,MAAM,OAAO,MAAM,SAAS,CACrE,SAAQ,KAAK,IAAI,GAAG,OAAO;AAE7B,QAAO,KAAK,IAAI,OAAO,EAAE;;AAG3B,MAAM,sBAAsB;CAC1B,SAAS;CACT,SAAS;CACT,SAAS;CACT,KAAK;CACL,SAAS;CACV;;;;;;;AAQD,MAAa,SACX,MACA,YAQA,CAAC,KAAK,CACH,MAAM,CACN,KAAK,WAAS;CACb,MAAM,EAAE,SAAS,SAAS,SAAS,KAAK,YAAY;EAClD,GAAG;EACH,GAAI,WAAW,EAAE;EAClB;CAED,MAAM,SAAS,UAAU,QAAQ;CACjC,MAAM,eAAe,KAAK,IACxB,SACA,KAAK,IAAI,SAAU,SAAS,YAAYC,OAAK,CAAC,OAAO,CACtD;AAED,KAAI,QAAQ,OACV,QAAO,GAAG,IAAI,OAAO,aAAa,GAAGA;AAGvC,QAAO,GAAGA,SAAO,IAAI,OAAO,aAAa;EACzC,CACD,KAAK,GAAG;AAEb,MAAa,IAAI,SAAS,KAAK,WAAW,IAAI;AAC9C,MAAa,IAAI,SAAS,KAAK,WAAW,MAAM;AAChD,MAAa,QAAQ,SAAS,KAAK,WAAW,KAAK"}
@@ -0,0 +1,12 @@
1
+
2
+ //#region package.json
3
+ var version = "7.0.0-canary.0";
4
+
5
+ //#endregion
6
+ Object.defineProperty(exports, 'version', {
7
+ enumerable: true,
8
+ get: function () {
9
+ return version;
10
+ }
11
+ });
12
+ //# sourceMappingURL=package.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.cjs","names":[],"sources":["../../package.json"],"sourcesContent":["{\n \"name\": \"@intlayer/config\",\n \"version\": \"7.0.0-canary.0\",\n \"private\": false,\n \"description\": \"Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.\",\n \"keywords\": [\n \"intlayer\",\n \"layer\",\n \"abstraction\",\n \"data\",\n \"internationalization\",\n \"i18n\",\n \"typescript\",\n \"javascript\",\n \"json\",\n \"file\"\n ],\n \"homepage\": \"https://intlayer.org\",\n \"bugs\": {\n \"url\": \"https://github.com/aymericzip/intlayer/issues\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/aymericzip/intlayer.git\"\n },\n \"license\": \"Apache-2.0\",\n \"author\": {\n \"name\": \"Aymeric PINEAU\",\n \"url\": \"https://github.com/aymericzip\"\n },\n \"contributors\": [\n {\n \"name\": \"Aymeric Pineau\",\n \"email\": \"ay.pineau@gmail.com\",\n \"url\": \"https://github.com/aymericzip\"\n }\n ],\n \"sideEffects\": false,\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"browser\": \"./dist/esm/client.mjs\",\n \"require\": \"./dist/cjs/index.cjs\",\n \"import\": \"./dist/esm/index.mjs\"\n },\n \"./client\": {\n \"types\": \"./dist/types/client.d.ts\",\n \"require\": \"./dist/cjs/client.cjs\",\n \"import\": \"./dist/esm/client.mjs\"\n },\n \"./built\": {\n \"types\": \"./dist/types/built.d.ts\",\n \"require\": \"./dist/cjs/built.cjs\",\n \"import\": \"./dist/esm/built.mjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"main\": \"dist/cjs/index.cjs\",\n \"module\": \"dist/esm/index.mjs\",\n \"types\": \"dist/types/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \".\": [\n \"./dist/types/index.d.ts\"\n ],\n \"client\": [\n \"./dist/types/client.d.ts\"\n ],\n \"built\": [\n \"./dist/types/built.d.ts\"\n ],\n \"package.json\": [\n \"./package.json\"\n ]\n }\n },\n \"files\": [\n \"./dist\",\n \"./package.json\"\n ],\n \"scripts\": {\n \"build\": \"tsdown --config tsdown.config.ts\",\n \"build:ci\": \"tsdown --config tsdown.config.ts\",\n \"clean\": \"rimraf ./dist .turbo\",\n \"dev\": \"tsdown --config tsdown.config.ts --watch\",\n \"format\": \"biome format . --check\",\n \"format:fix\": \"biome format --write .\",\n \"lint\": \"biome lint .\",\n \"lint:fix\": \"biome lint --write .\",\n \"prepublish\": \"cp -f ../../../README.md ./README.md\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"tsc --noEmit --project tsconfig.types.json\"\n },\n \"dependencies\": {\n \"@intlayer/types\": \"workspace:*\",\n \"deepmerge\": \"4.3.1\",\n \"dotenv\": \"16.6.1\",\n \"esbuild\": \"0.25.2\"\n },\n \"devDependencies\": {\n \"@types/node\": \"24.9.1\",\n \"@utils/ts-config\": \"workspace:*\",\n \"@utils/ts-config-types\": \"workspace:*\",\n \"@utils/tsdown-config\": \"workspace:*\",\n \"rimraf\": \"6.0.1\",\n \"tsdown\": \"0.15.9\",\n \"typescript\": \"5.9.3\",\n \"vitest\": \"4.0.3\"\n },\n \"peerDependencies\": {\n \"intlayer\": \"workspace:*\",\n \"react\": \">=16.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"intlayer\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n }\n },\n \"engines\": {\n \"node\": \">=14.18\"\n },\n \"bug\": {\n \"url\": \"https://github.com/aymericzip/intlayer/issues\"\n }\n}\n"],"mappings":";;cAEa"}
@@ -1,52 +1,45 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var retryManager_exports = {};
20
- __export(retryManager_exports, {
21
- retryManager: () => retryManager
22
- });
23
- module.exports = __toCommonJS(retryManager_exports);
24
- var import_logger = require('./logger.cjs');
1
+ const require_logger = require('./logger.cjs');
2
+ const require_utils_extractErrorMessage = require('./utils/extractErrorMessage.cjs');
3
+
4
+ //#region src/retryManager.ts
25
5
  const DEFAULT_MAX_RETRY = 3;
26
6
  const DEFAULT_DELAY = 0;
27
- const retryManager = (fn, {
28
- maxRetry = DEFAULT_MAX_RETRY,
29
- delay = DEFAULT_DELAY,
30
- onError
31
- } = {}) => (
32
- // ───────────────────────────────^ returned wrapper function
33
- async (...args) => {
34
- for (let attempt = 0; ; attempt++) {
35
- try {
36
- return await fn(...args);
37
- } catch (err) {
38
- onError?.(err);
39
- (0, import_logger.logger)(["Request failed", err], {
40
- level: "error"
41
- });
42
- if (attempt >= maxRetry) throw err;
43
- if (delay > 0) await new Promise((res) => setTimeout(res, delay));
44
- }
45
- }
46
- }
47
- );
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {
50
- retryManager
51
- });
7
+ /**
8
+ * Wrap an async function `fn` so it’s retried on failure.
9
+ *
10
+ * @param fn The async function to wrap
11
+ * @param options { maxRetry, delay }
12
+ * @returns A new function with the same signature as `fn`
13
+ */
14
+ const retryManager = (fn, { maxRetry = DEFAULT_MAX_RETRY, delay = DEFAULT_DELAY, onError, onMaxTryReached } = {}) => async (...args) => {
15
+ let lastError;
16
+ for (let attempt = 0; attempt <= maxRetry; attempt++) try {
17
+ return await fn(...args);
18
+ } catch (err) {
19
+ lastError = err;
20
+ const error = require_utils_extractErrorMessage.extractErrorMessage(err);
21
+ if (attempt >= maxRetry) {
22
+ if (onMaxTryReached) {
23
+ onMaxTryReached?.({
24
+ error,
25
+ attempt,
26
+ maxRetry
27
+ });
28
+ return null;
29
+ }
30
+ throw err;
31
+ }
32
+ if (onError) onError?.({
33
+ error,
34
+ attempt,
35
+ maxRetry
36
+ });
37
+ else require_logger.logger(error, { level: "error" });
38
+ if (delay > 0) await new Promise((res) => setTimeout(res, delay));
39
+ }
40
+ throw lastError ?? /* @__PURE__ */ new Error("Unexpected: retry loop completed without result");
41
+ };
42
+
43
+ //#endregion
44
+ exports.retryManager = retryManager;
52
45
  //# sourceMappingURL=retryManager.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/retryManager.ts"],"sourcesContent":["import { logger } from './logger';\n\nexport type RetryManagerOptions = {\n /** maximum number of retries before giving up */\n maxRetry?: number;\n /** delay between attempts, in milliseconds */\n delay?: number;\n /** function to call when an error occurs */\n onError?: (err: Error) => void;\n};\n\nconst DEFAULT_MAX_RETRY = 3;\nconst DEFAULT_DELAY = 0;\n\n/**\n * Wrap an async function `fn` so it’s retried on failure.\n *\n * @param fn The async function to wrap\n * @param options { maxRetry, delay }\n * @returns A new function with the same signature as `fn`\n */\nexport const retryManager =\n <Args extends any[], R>(\n fn: (...args: Args) => Promise<R>,\n {\n maxRetry = DEFAULT_MAX_RETRY,\n delay = DEFAULT_DELAY,\n onError,\n }: RetryManagerOptions = {}\n ): ((...args: Args) => Promise<R>) =>\n // ───────────────────────────────^ returned wrapper function\n async (...args: Args): Promise<R> => {\n for (let attempt = 0; ; attempt++) {\n try {\n return await fn(...args);\n } catch (err) {\n onError?.(err as Error);\n logger(['Request failed', err], {\n level: 'error',\n });\n if (attempt >= maxRetry) throw err; // out of retries\n if (delay > 0) await new Promise((res) => setTimeout(res, delay));\n }\n }\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AAWvB,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AASf,MAAM,eACX,CACE,IACA;AAAA,EACE,WAAW;AAAA,EACX,QAAQ;AAAA,EACR;AACF,IAAyB,CAAC;AAAA;AAAA,EAG5B,UAAU,SAA2B;AACnC,aAAS,UAAU,KAAK,WAAW;AACjC,UAAI;AACF,eAAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,KAAK;AACZ,kBAAU,GAAY;AACtB,kCAAO,CAAC,kBAAkB,GAAG,GAAG;AAAA,UAC9B,OAAO;AAAA,QACT,CAAC;AACD,YAAI,WAAW,SAAU,OAAM;AAC/B,YAAI,QAAQ,EAAG,OAAM,IAAI,QAAQ,CAAC,QAAQ,WAAW,KAAK,KAAK,CAAC;AAAA,MAClE;AAAA,IACF;AAAA,EACF;AAAA;","names":[]}
1
+ {"version":3,"file":"retryManager.cjs","names":["lastError: unknown","extractErrorMessage"],"sources":["../../src/retryManager.ts"],"sourcesContent":["import { logger } from './logger';\nimport { extractErrorMessage } from './utils/extractErrorMessage';\n\nexport type RetryManagerOptions = {\n /** maximum number of retries before giving up */\n maxRetry?: number;\n /** delay between attempts, in milliseconds */\n delay?: number;\n /** function to call when an error occurs */\n onError?: (details: {\n error: string;\n attempt: number;\n maxRetry: number;\n }) => void;\n /** function to call when the maximum number of retries is reached */\n onMaxTryReached?: (details: {\n error: string;\n attempt: number;\n maxRetry: number;\n }) => void;\n};\n\nconst DEFAULT_MAX_RETRY = 3;\nconst DEFAULT_DELAY = 0;\n\n/**\n * Wrap an async function `fn` so it’s retried on failure.\n *\n * @param fn The async function to wrap\n * @param options { maxRetry, delay }\n * @returns A new function with the same signature as `fn`\n */\nexport const retryManager =\n <Args extends any[], R>(\n fn: (...args: Args) => Promise<R>,\n {\n maxRetry = DEFAULT_MAX_RETRY,\n delay = DEFAULT_DELAY,\n onError,\n onMaxTryReached,\n }: RetryManagerOptions = {}\n ): ((...args: Args) => Promise<R>) =>\n // ───────────────────────────────^ returned wrapper function\n async (...args: Args): Promise<R> => {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= maxRetry; attempt++) {\n try {\n return await fn(...args);\n } catch (err) {\n lastError = err;\n const error = extractErrorMessage(err);\n\n // If this was the last attempt, handle max retry reached\n if (attempt >= maxRetry) {\n if (onMaxTryReached) {\n onMaxTryReached?.({ error, attempt, maxRetry });\n return null as R;\n }\n\n // Otherwise, throw the error\n throw err;\n }\n\n if (onError) {\n onError?.({ error, attempt, maxRetry });\n } else {\n logger(error, {\n level: 'error',\n });\n }\n\n // Wait before retrying\n if (delay > 0) {\n await new Promise((res) => setTimeout(res, delay));\n }\n }\n }\n\n // This should never be reached, but TypeScript needs it\n throw (\n lastError ?? new Error('Unexpected: retry loop completed without result')\n );\n };\n"],"mappings":";;;;AAsBA,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;;;;;;;;AAStB,MAAa,gBAET,IACA,EACE,WAAW,mBACX,QAAQ,eACR,SACA,oBACuB,EAAE,KAG7B,OAAO,GAAG,SAA2B;CACnC,IAAIA;AAEJ,MAAK,IAAI,UAAU,GAAG,WAAW,UAAU,UACzC,KAAI;AACF,SAAO,MAAM,GAAG,GAAG,KAAK;UACjB,KAAK;AACZ,cAAY;EACZ,MAAM,QAAQC,sDAAoB,IAAI;AAGtC,MAAI,WAAW,UAAU;AACvB,OAAI,iBAAiB;AACnB,sBAAkB;KAAE;KAAO;KAAS;KAAU,CAAC;AAC/C,WAAO;;AAIT,SAAM;;AAGR,MAAI,QACF,WAAU;GAAE;GAAO;GAAS;GAAU,CAAC;MAEvC,uBAAO,OAAO,EACZ,OAAO,SACR,CAAC;AAIJ,MAAI,QAAQ,EACV,OAAM,IAAI,SAAS,QAAQ,WAAW,KAAK,MAAM,CAAC;;AAMxD,OACE,6BAAa,IAAI,MAAM,kDAAkD"}