alepha 0.15.1 → 0.15.3

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 (523) hide show
  1. package/README.md +68 -80
  2. package/dist/api/audits/index.d.ts +10 -33
  3. package/dist/api/audits/index.d.ts.map +1 -1
  4. package/dist/api/audits/index.js +10 -33
  5. package/dist/api/audits/index.js.map +1 -1
  6. package/dist/api/files/index.d.ts +10 -3
  7. package/dist/api/files/index.d.ts.map +1 -1
  8. package/dist/api/files/index.js +10 -3
  9. package/dist/api/files/index.js.map +1 -1
  10. package/dist/api/jobs/index.d.ts +162 -155
  11. package/dist/api/jobs/index.d.ts.map +1 -1
  12. package/dist/api/jobs/index.js +10 -3
  13. package/dist/api/jobs/index.js.map +1 -1
  14. package/dist/api/keys/index.d.ts +413 -0
  15. package/dist/api/keys/index.d.ts.map +1 -0
  16. package/dist/api/keys/index.js +476 -0
  17. package/dist/api/keys/index.js.map +1 -0
  18. package/dist/api/notifications/index.d.ts +10 -4
  19. package/dist/api/notifications/index.d.ts.map +1 -1
  20. package/dist/api/notifications/index.js +10 -4
  21. package/dist/api/notifications/index.js.map +1 -1
  22. package/dist/api/parameters/index.d.ts +43 -50
  23. package/dist/api/parameters/index.d.ts.map +1 -1
  24. package/dist/api/parameters/index.js +30 -37
  25. package/dist/api/parameters/index.js.map +1 -1
  26. package/dist/api/users/index.d.ts +1081 -760
  27. package/dist/api/users/index.d.ts.map +1 -1
  28. package/dist/api/users/index.js +2539 -218
  29. package/dist/api/users/index.js.map +1 -1
  30. package/dist/api/verifications/index.d.ts +138 -132
  31. package/dist/api/verifications/index.d.ts.map +1 -1
  32. package/dist/api/verifications/index.js +12 -4
  33. package/dist/api/verifications/index.js.map +1 -1
  34. package/dist/batch/index.d.ts +20 -40
  35. package/dist/batch/index.d.ts.map +1 -1
  36. package/dist/batch/index.js +31 -44
  37. package/dist/batch/index.js.map +1 -1
  38. package/dist/bucket/index.d.ts +440 -8
  39. package/dist/bucket/index.d.ts.map +1 -1
  40. package/dist/bucket/index.js +1861 -12
  41. package/dist/bucket/index.js.map +1 -1
  42. package/dist/cache/core/index.d.ts +179 -7
  43. package/dist/cache/core/index.d.ts.map +1 -1
  44. package/dist/cache/core/index.js +213 -7
  45. package/dist/cache/core/index.js.map +1 -1
  46. package/dist/cache/redis/index.d.ts +1 -0
  47. package/dist/cache/redis/index.d.ts.map +1 -1
  48. package/dist/cache/redis/index.js +4 -0
  49. package/dist/cache/redis/index.js.map +1 -1
  50. package/dist/cli/index.d.ts +638 -5645
  51. package/dist/cli/index.d.ts.map +1 -1
  52. package/dist/cli/index.js +2550 -368
  53. package/dist/cli/index.js.map +1 -1
  54. package/dist/command/index.d.ts +203 -45
  55. package/dist/command/index.d.ts.map +1 -1
  56. package/dist/command/index.js +2060 -71
  57. package/dist/command/index.js.map +1 -1
  58. package/dist/core/index.browser.js +70 -40
  59. package/dist/core/index.browser.js.map +1 -1
  60. package/dist/core/index.d.ts +34 -13
  61. package/dist/core/index.d.ts.map +1 -1
  62. package/dist/core/index.js +90 -40
  63. package/dist/core/index.js.map +1 -1
  64. package/dist/core/index.native.js +70 -40
  65. package/dist/core/index.native.js.map +1 -1
  66. package/dist/datetime/index.d.ts +15 -0
  67. package/dist/datetime/index.d.ts.map +1 -1
  68. package/dist/datetime/index.js +15 -0
  69. package/dist/datetime/index.js.map +1 -1
  70. package/dist/email/index.d.ts +323 -20
  71. package/dist/email/index.d.ts.map +1 -1
  72. package/dist/email/index.js +1857 -7
  73. package/dist/email/index.js.map +1 -1
  74. package/dist/fake/index.d.ts +90 -8
  75. package/dist/fake/index.d.ts.map +1 -1
  76. package/dist/fake/index.js +91 -20
  77. package/dist/fake/index.js.map +1 -1
  78. package/dist/lock/core/index.d.ts +11 -4
  79. package/dist/lock/core/index.d.ts.map +1 -1
  80. package/dist/lock/core/index.js +11 -4
  81. package/dist/lock/core/index.js.map +1 -1
  82. package/dist/logger/index.d.ts +17 -66
  83. package/dist/logger/index.d.ts.map +1 -1
  84. package/dist/logger/index.js +14 -63
  85. package/dist/logger/index.js.map +1 -1
  86. package/dist/mcp/index.d.ts +10 -30
  87. package/dist/mcp/index.d.ts.map +1 -1
  88. package/dist/mcp/index.js +12 -35
  89. package/dist/mcp/index.js.map +1 -1
  90. package/dist/orm/index.browser.js +3 -3
  91. package/dist/orm/index.browser.js.map +1 -1
  92. package/dist/orm/index.bun.js +39 -20
  93. package/dist/orm/index.bun.js.map +1 -1
  94. package/dist/orm/index.d.ts +517 -540
  95. package/dist/orm/index.d.ts.map +1 -1
  96. package/dist/orm/index.js +58 -71
  97. package/dist/orm/index.js.map +1 -1
  98. package/dist/queue/core/index.d.ts +18 -10
  99. package/dist/queue/core/index.d.ts.map +1 -1
  100. package/dist/queue/core/index.js +14 -6
  101. package/dist/queue/core/index.js.map +1 -1
  102. package/dist/react/auth/index.browser.js +108 -0
  103. package/dist/react/auth/index.browser.js.map +1 -0
  104. package/dist/react/auth/index.d.ts +100 -0
  105. package/dist/react/auth/index.d.ts.map +1 -0
  106. package/dist/react/auth/index.js +145 -0
  107. package/dist/react/auth/index.js.map +1 -0
  108. package/dist/react/core/index.d.ts +469 -0
  109. package/dist/react/core/index.d.ts.map +1 -0
  110. package/dist/react/core/index.js +464 -0
  111. package/dist/react/core/index.js.map +1 -0
  112. package/dist/react/form/index.d.ts +232 -0
  113. package/dist/react/form/index.d.ts.map +1 -0
  114. package/dist/react/form/index.js +432 -0
  115. package/dist/react/form/index.js.map +1 -0
  116. package/dist/react/head/index.browser.js +423 -0
  117. package/dist/react/head/index.browser.js.map +1 -0
  118. package/dist/react/head/index.d.ts +288 -0
  119. package/dist/react/head/index.d.ts.map +1 -0
  120. package/dist/react/head/index.js +465 -0
  121. package/dist/react/head/index.js.map +1 -0
  122. package/dist/react/i18n/index.d.ts +175 -0
  123. package/dist/react/i18n/index.d.ts.map +1 -0
  124. package/dist/react/i18n/index.js +224 -0
  125. package/dist/react/i18n/index.js.map +1 -0
  126. package/dist/react/router/index.browser.js +1974 -0
  127. package/dist/react/router/index.browser.js.map +1 -0
  128. package/dist/react/router/index.d.ts +1956 -0
  129. package/dist/react/router/index.d.ts.map +1 -0
  130. package/dist/react/router/index.js +4722 -0
  131. package/dist/react/router/index.js.map +1 -0
  132. package/dist/react/websocket/index.d.ts +117 -0
  133. package/dist/react/websocket/index.d.ts.map +1 -0
  134. package/dist/react/websocket/index.js +107 -0
  135. package/dist/react/websocket/index.js.map +1 -0
  136. package/dist/redis/index.bun.js +4 -0
  137. package/dist/redis/index.bun.js.map +1 -1
  138. package/dist/redis/index.d.ts +41 -44
  139. package/dist/redis/index.d.ts.map +1 -1
  140. package/dist/redis/index.js +16 -25
  141. package/dist/redis/index.js.map +1 -1
  142. package/dist/retry/index.d.ts +11 -2
  143. package/dist/retry/index.d.ts.map +1 -1
  144. package/dist/retry/index.js +11 -2
  145. package/dist/retry/index.js.map +1 -1
  146. package/dist/scheduler/index.d.ts +11 -2
  147. package/dist/scheduler/index.d.ts.map +1 -1
  148. package/dist/scheduler/index.js +11 -2
  149. package/dist/scheduler/index.js.map +1 -1
  150. package/dist/security/index.d.ts +140 -49
  151. package/dist/security/index.d.ts.map +1 -1
  152. package/dist/security/index.js +164 -32
  153. package/dist/security/index.js.map +1 -1
  154. package/dist/server/auth/index.d.ts +12 -7
  155. package/dist/server/auth/index.d.ts.map +1 -1
  156. package/dist/server/auth/index.js +12 -7
  157. package/dist/server/auth/index.js.map +1 -1
  158. package/dist/server/cache/index.d.ts +7 -22
  159. package/dist/server/cache/index.d.ts.map +1 -1
  160. package/dist/server/cache/index.js +7 -22
  161. package/dist/server/cache/index.js.map +1 -1
  162. package/dist/server/compress/index.d.ts +10 -2
  163. package/dist/server/compress/index.d.ts.map +1 -1
  164. package/dist/server/compress/index.js +10 -2
  165. package/dist/server/compress/index.js.map +1 -1
  166. package/dist/server/cookies/index.d.ts +40 -16
  167. package/dist/server/cookies/index.d.ts.map +1 -1
  168. package/dist/server/cookies/index.js +7 -5
  169. package/dist/server/cookies/index.js.map +1 -1
  170. package/dist/server/core/index.d.ts +124 -23
  171. package/dist/server/core/index.d.ts.map +1 -1
  172. package/dist/server/core/index.js +231 -14
  173. package/dist/server/core/index.js.map +1 -1
  174. package/dist/server/cors/index.d.ts +13 -23
  175. package/dist/server/cors/index.d.ts.map +1 -1
  176. package/dist/server/cors/index.js +7 -21
  177. package/dist/server/cors/index.js.map +1 -1
  178. package/dist/server/health/index.d.ts +8 -2
  179. package/dist/server/health/index.d.ts.map +1 -1
  180. package/dist/server/health/index.js +8 -2
  181. package/dist/server/health/index.js.map +1 -1
  182. package/dist/server/helmet/index.d.ts +11 -3
  183. package/dist/server/helmet/index.d.ts.map +1 -1
  184. package/dist/server/helmet/index.js +11 -3
  185. package/dist/server/helmet/index.js.map +1 -1
  186. package/dist/server/links/index.d.ts +11 -6
  187. package/dist/server/links/index.d.ts.map +1 -1
  188. package/dist/server/links/index.js +11 -6
  189. package/dist/server/links/index.js.map +1 -1
  190. package/dist/server/metrics/index.d.ts +10 -3
  191. package/dist/server/metrics/index.d.ts.map +1 -1
  192. package/dist/server/metrics/index.js +10 -3
  193. package/dist/server/metrics/index.js.map +1 -1
  194. package/dist/server/multipart/index.d.ts +9 -3
  195. package/dist/server/multipart/index.d.ts.map +1 -1
  196. package/dist/server/multipart/index.js +9 -3
  197. package/dist/server/multipart/index.js.map +1 -1
  198. package/dist/server/proxy/index.d.ts +8 -2
  199. package/dist/server/proxy/index.d.ts.map +1 -1
  200. package/dist/server/proxy/index.js +8 -2
  201. package/dist/server/proxy/index.js.map +1 -1
  202. package/dist/server/rate-limit/index.d.ts +30 -35
  203. package/dist/server/rate-limit/index.d.ts.map +1 -1
  204. package/dist/server/rate-limit/index.js +18 -55
  205. package/dist/server/rate-limit/index.js.map +1 -1
  206. package/dist/server/static/index.d.ts +137 -4
  207. package/dist/server/static/index.d.ts.map +1 -1
  208. package/dist/server/static/index.js +1853 -5
  209. package/dist/server/static/index.js.map +1 -1
  210. package/dist/server/swagger/index.d.ts +309 -6
  211. package/dist/server/swagger/index.d.ts.map +1 -1
  212. package/dist/server/swagger/index.js +1854 -6
  213. package/dist/server/swagger/index.js.map +1 -1
  214. package/dist/sms/index.d.ts +309 -7
  215. package/dist/sms/index.d.ts.map +1 -1
  216. package/dist/sms/index.js +1856 -7
  217. package/dist/sms/index.js.map +1 -1
  218. package/dist/system/index.browser.js +1218 -0
  219. package/dist/system/index.browser.js.map +1 -0
  220. package/dist/{file → system}/index.d.ts +343 -16
  221. package/dist/system/index.d.ts.map +1 -0
  222. package/dist/{file → system}/index.js +419 -22
  223. package/dist/system/index.js.map +1 -0
  224. package/dist/thread/index.d.ts +11 -2
  225. package/dist/thread/index.d.ts.map +1 -1
  226. package/dist/thread/index.js +11 -2
  227. package/dist/thread/index.js.map +1 -1
  228. package/dist/topic/core/index.d.ts +12 -5
  229. package/dist/topic/core/index.d.ts.map +1 -1
  230. package/dist/topic/core/index.js +12 -5
  231. package/dist/topic/core/index.js.map +1 -1
  232. package/dist/vite/index.d.ts +5 -6272
  233. package/dist/vite/index.d.ts.map +1 -1
  234. package/dist/vite/index.js +23 -10
  235. package/dist/vite/index.js.map +1 -1
  236. package/dist/websocket/index.d.ts +12 -8
  237. package/dist/websocket/index.d.ts.map +1 -1
  238. package/dist/websocket/index.js +12 -8
  239. package/dist/websocket/index.js.map +1 -1
  240. package/package.json +82 -11
  241. package/src/api/audits/index.ts +10 -33
  242. package/src/api/files/__tests__/$bucket.spec.ts +1 -1
  243. package/src/api/files/controllers/AdminFileStatsController.spec.ts +1 -1
  244. package/src/api/files/controllers/FileController.spec.ts +1 -1
  245. package/src/api/files/index.ts +10 -3
  246. package/src/api/files/jobs/FileJobs.spec.ts +1 -1
  247. package/src/api/files/services/FileService.spec.ts +1 -1
  248. package/src/api/jobs/index.ts +10 -3
  249. package/src/api/keys/controllers/AdminApiKeyController.ts +75 -0
  250. package/src/api/keys/controllers/ApiKeyController.ts +103 -0
  251. package/src/api/keys/entities/apiKeyEntity.ts +41 -0
  252. package/src/api/keys/index.ts +49 -0
  253. package/src/api/keys/schemas/adminApiKeyQuerySchema.ts +7 -0
  254. package/src/api/keys/schemas/adminApiKeyResourceSchema.ts +17 -0
  255. package/src/api/keys/schemas/createApiKeyBodySchema.ts +7 -0
  256. package/src/api/keys/schemas/createApiKeyResponseSchema.ts +11 -0
  257. package/src/api/keys/schemas/listApiKeyResponseSchema.ts +15 -0
  258. package/src/api/keys/schemas/revokeApiKeyParamsSchema.ts +5 -0
  259. package/src/api/keys/schemas/revokeApiKeyResponseSchema.ts +5 -0
  260. package/src/api/keys/services/ApiKeyService.spec.ts +553 -0
  261. package/src/api/keys/services/ApiKeyService.ts +306 -0
  262. package/src/api/logs/TODO.md +55 -0
  263. package/src/api/notifications/index.ts +10 -4
  264. package/src/api/parameters/index.ts +9 -30
  265. package/src/api/parameters/primitives/$config.ts +12 -4
  266. package/src/api/parameters/services/ConfigStore.ts +9 -3
  267. package/src/api/users/__tests__/ApiKeys-integration.spec.ts +1035 -0
  268. package/src/api/users/__tests__/ApiKeys.spec.ts +401 -0
  269. package/src/api/users/index.ts +14 -3
  270. package/src/api/users/primitives/$realm.ts +33 -5
  271. package/src/api/users/providers/RealmProvider.ts +1 -12
  272. package/src/api/users/services/SessionService.ts +1 -1
  273. package/src/api/verifications/controllers/VerificationController.ts +2 -0
  274. package/src/api/verifications/index.ts +10 -4
  275. package/src/batch/index.ts +9 -36
  276. package/src/batch/primitives/$batch.ts +0 -8
  277. package/src/batch/providers/BatchProvider.ts +29 -2
  278. package/src/bucket/__tests__/shared.ts +1 -1
  279. package/src/bucket/index.ts +13 -6
  280. package/src/bucket/primitives/$bucket.ts +1 -1
  281. package/src/bucket/providers/LocalFileStorageProvider.ts +1 -1
  282. package/src/bucket/providers/MemoryFileStorageProvider.ts +1 -1
  283. package/src/cache/core/__tests__/shared.ts +30 -0
  284. package/src/cache/core/index.ts +11 -6
  285. package/src/cache/core/primitives/$cache.spec.ts +5 -0
  286. package/src/cache/core/providers/CacheProvider.ts +17 -0
  287. package/src/cache/core/providers/MemoryCacheProvider.ts +300 -1
  288. package/src/cache/redis/__tests__/cache-redis.spec.ts +5 -0
  289. package/src/cache/redis/providers/RedisCacheProvider.ts +9 -0
  290. package/src/cli/apps/AlephaCli.ts +1 -14
  291. package/src/cli/apps/AlephaPackageBuilderCli.ts +10 -1
  292. package/src/cli/atoms/buildOptions.ts +99 -9
  293. package/src/cli/commands/build.ts +150 -37
  294. package/src/cli/commands/db.ts +22 -18
  295. package/src/cli/commands/deploy.ts +1 -1
  296. package/src/cli/commands/dev.ts +1 -20
  297. package/src/cli/commands/gen/env.ts +5 -2
  298. package/src/cli/commands/gen/openapi.ts +5 -2
  299. package/src/cli/commands/init.spec.ts +588 -0
  300. package/src/cli/commands/init.ts +115 -58
  301. package/src/cli/commands/lint.ts +7 -1
  302. package/src/cli/commands/typecheck.ts +11 -0
  303. package/src/cli/providers/AppEntryProvider.ts +1 -1
  304. package/src/cli/providers/ViteBuildProvider.ts +8 -50
  305. package/src/cli/providers/ViteDevServerProvider.ts +35 -16
  306. package/src/cli/services/AlephaCliUtils.ts +52 -121
  307. package/src/cli/services/PackageManagerUtils.ts +129 -11
  308. package/src/cli/services/ProjectScaffolder.spec.ts +97 -0
  309. package/src/cli/services/ProjectScaffolder.ts +148 -81
  310. package/src/cli/services/ViteUtils.ts +82 -0
  311. package/src/cli/{assets/claudeMd.ts → templates/agentMd.ts} +37 -24
  312. package/src/cli/templates/apiAppSecurityTs.ts +11 -0
  313. package/src/cli/templates/apiIndexTs.ts +30 -0
  314. package/src/cli/templates/gitignore.ts +39 -0
  315. package/src/cli/{assets → templates}/mainCss.ts +11 -2
  316. package/src/cli/templates/mainServerTs.ts +33 -0
  317. package/src/cli/templates/webAppRouterTs.ts +74 -0
  318. package/src/cli/templates/webHelloComponentTsx.ts +30 -0
  319. package/src/command/helpers/Runner.spec.ts +139 -0
  320. package/src/command/helpers/Runner.ts +7 -22
  321. package/src/command/index.ts +12 -4
  322. package/src/command/providers/CliProvider.spec.ts +1392 -0
  323. package/src/command/providers/CliProvider.ts +320 -47
  324. package/src/core/Alepha.ts +34 -27
  325. package/src/core/__tests__/Alepha-start.spec.ts +4 -4
  326. package/src/core/helpers/jsonSchemaToTypeBox.spec.ts +771 -0
  327. package/src/core/helpers/jsonSchemaToTypeBox.ts +62 -10
  328. package/src/core/index.shared.ts +1 -0
  329. package/src/core/index.ts +20 -0
  330. package/src/core/providers/EventManager.spec.ts +0 -71
  331. package/src/core/providers/EventManager.ts +3 -15
  332. package/src/core/providers/Json.ts +2 -14
  333. package/src/datetime/index.ts +15 -0
  334. package/src/email/index.ts +10 -5
  335. package/src/email/providers/LocalEmailProvider.spec.ts +1 -1
  336. package/src/email/providers/LocalEmailProvider.ts +1 -1
  337. package/src/fake/__tests__/keyName.example.ts +1 -1
  338. package/src/fake/__tests__/keyName.spec.ts +5 -5
  339. package/src/fake/index.ts +9 -6
  340. package/src/fake/providers/FakeProvider.spec.ts +258 -40
  341. package/src/fake/providers/FakeProvider.ts +133 -19
  342. package/src/lock/core/index.ts +11 -4
  343. package/src/logger/index.ts +17 -66
  344. package/src/mcp/index.ts +10 -27
  345. package/src/mcp/transports/SseMcpTransport.ts +0 -11
  346. package/src/orm/__tests__/PostgresProvider.spec.ts +2 -2
  347. package/src/orm/index.browser.ts +2 -2
  348. package/src/orm/index.bun.ts +5 -3
  349. package/src/orm/index.ts +23 -53
  350. package/src/orm/providers/drivers/BunSqliteProvider.ts +5 -1
  351. package/src/orm/providers/drivers/CloudflareD1Provider.ts +57 -30
  352. package/src/orm/providers/drivers/DatabaseProvider.ts +9 -1
  353. package/src/orm/providers/drivers/NodeSqliteProvider.ts +4 -1
  354. package/src/orm/services/Repository.ts +7 -3
  355. package/src/queue/core/index.ts +14 -6
  356. package/src/react/auth/__tests__/$auth.spec.ts +202 -0
  357. package/src/react/auth/hooks/useAuth.ts +32 -0
  358. package/src/react/auth/index.browser.ts +13 -0
  359. package/src/react/auth/index.shared.ts +2 -0
  360. package/src/react/auth/index.ts +48 -0
  361. package/src/react/auth/providers/ReactAuthProvider.ts +16 -0
  362. package/src/react/auth/services/ReactAuth.ts +135 -0
  363. package/src/react/core/__tests__/Router.spec.tsx +169 -0
  364. package/src/react/core/components/ClientOnly.tsx +49 -0
  365. package/src/react/core/components/ErrorBoundary.tsx +73 -0
  366. package/src/react/core/contexts/AlephaContext.ts +7 -0
  367. package/src/react/core/contexts/AlephaProvider.tsx +42 -0
  368. package/src/react/core/hooks/useAction.browser.spec.tsx +569 -0
  369. package/src/react/core/hooks/useAction.ts +480 -0
  370. package/src/react/core/hooks/useAlepha.ts +26 -0
  371. package/src/react/core/hooks/useClient.ts +17 -0
  372. package/src/react/core/hooks/useEvents.ts +51 -0
  373. package/src/react/core/hooks/useInject.ts +12 -0
  374. package/src/react/core/hooks/useStore.ts +52 -0
  375. package/src/react/core/index.ts +90 -0
  376. package/src/react/form/components/FormState.tsx +17 -0
  377. package/src/react/form/errors/FormValidationError.ts +18 -0
  378. package/src/react/form/hooks/useForm.browser.spec.tsx +366 -0
  379. package/src/react/form/hooks/useForm.ts +47 -0
  380. package/src/react/form/hooks/useFormState.ts +130 -0
  381. package/src/react/form/index.ts +44 -0
  382. package/src/react/form/services/FormModel.ts +614 -0
  383. package/src/react/head/helpers/SeoExpander.spec.ts +203 -0
  384. package/src/react/head/helpers/SeoExpander.ts +142 -0
  385. package/src/react/head/hooks/useHead.spec.tsx +288 -0
  386. package/src/react/head/hooks/useHead.ts +62 -0
  387. package/src/react/head/index.browser.ts +26 -0
  388. package/src/react/head/index.ts +44 -0
  389. package/src/react/head/interfaces/Head.ts +105 -0
  390. package/src/react/head/primitives/$head.ts +25 -0
  391. package/src/react/head/providers/BrowserHeadProvider.browser.spec.ts +196 -0
  392. package/src/react/head/providers/BrowserHeadProvider.ts +212 -0
  393. package/src/react/head/providers/HeadProvider.ts +168 -0
  394. package/src/react/head/providers/ServerHeadProvider.ts +31 -0
  395. package/src/react/i18n/__tests__/integration.spec.tsx +239 -0
  396. package/src/react/i18n/components/Localize.spec.tsx +357 -0
  397. package/src/react/i18n/components/Localize.tsx +35 -0
  398. package/src/react/i18n/hooks/useI18n.browser.spec.tsx +438 -0
  399. package/src/react/i18n/hooks/useI18n.ts +18 -0
  400. package/src/react/i18n/index.ts +41 -0
  401. package/src/react/i18n/primitives/$dictionary.ts +69 -0
  402. package/src/react/i18n/providers/I18nProvider.spec.ts +389 -0
  403. package/src/react/i18n/providers/I18nProvider.ts +278 -0
  404. package/src/react/router/__tests__/page-head-browser.browser.spec.ts +95 -0
  405. package/src/react/router/__tests__/page-head.spec.ts +48 -0
  406. package/src/react/router/__tests__/seo-head.spec.ts +125 -0
  407. package/src/react/router/atoms/ssrManifestAtom.ts +58 -0
  408. package/src/react/router/components/ErrorViewer.tsx +872 -0
  409. package/src/react/router/components/Link.tsx +23 -0
  410. package/src/react/router/components/NestedView.tsx +223 -0
  411. package/src/react/router/components/NotFound.tsx +30 -0
  412. package/src/react/router/constants/PAGE_PRELOAD_KEY.ts +6 -0
  413. package/src/react/router/contexts/RouterLayerContext.ts +12 -0
  414. package/src/react/router/errors/Redirection.ts +28 -0
  415. package/src/react/router/hooks/useActive.ts +52 -0
  416. package/src/react/router/hooks/useQueryParams.ts +63 -0
  417. package/src/react/router/hooks/useRouter.ts +20 -0
  418. package/src/react/router/hooks/useRouterState.ts +11 -0
  419. package/src/react/router/index.browser.ts +45 -0
  420. package/src/react/router/index.shared.ts +19 -0
  421. package/src/react/router/index.ts +146 -0
  422. package/src/react/router/primitives/$page.browser.spec.tsx +851 -0
  423. package/src/react/router/primitives/$page.spec.tsx +676 -0
  424. package/src/react/router/primitives/$page.ts +489 -0
  425. package/src/react/router/providers/ReactBrowserProvider.ts +312 -0
  426. package/src/react/router/providers/ReactBrowserRendererProvider.ts +25 -0
  427. package/src/react/router/providers/ReactBrowserRouterProvider.ts +168 -0
  428. package/src/react/router/providers/ReactPageProvider.ts +726 -0
  429. package/src/react/router/providers/ReactPreloadProvider.spec.ts +142 -0
  430. package/src/react/router/providers/ReactPreloadProvider.ts +85 -0
  431. package/src/react/router/providers/ReactServerProvider.spec.tsx +316 -0
  432. package/src/react/router/providers/ReactServerProvider.ts +487 -0
  433. package/src/react/router/providers/ReactServerTemplateProvider.spec.ts +210 -0
  434. package/src/react/router/providers/ReactServerTemplateProvider.ts +542 -0
  435. package/src/react/router/providers/SSRManifestProvider.ts +334 -0
  436. package/src/react/router/services/ReactPageServerService.ts +48 -0
  437. package/src/react/router/services/ReactPageService.ts +27 -0
  438. package/src/react/router/services/ReactRouter.ts +262 -0
  439. package/src/react/websocket/hooks/useRoom.tsx +242 -0
  440. package/src/react/websocket/index.ts +7 -0
  441. package/src/redis/__tests__/redis.spec.ts +13 -0
  442. package/src/redis/index.ts +9 -25
  443. package/src/redis/providers/BunRedisProvider.ts +9 -0
  444. package/src/redis/providers/NodeRedisProvider.ts +8 -0
  445. package/src/redis/providers/RedisProvider.ts +16 -0
  446. package/src/retry/index.ts +11 -2
  447. package/src/router/index.ts +15 -0
  448. package/src/scheduler/index.ts +11 -2
  449. package/src/security/__tests__/BasicAuth.spec.ts +2 -0
  450. package/src/security/__tests__/ServerSecurityProvider.spec.ts +90 -5
  451. package/src/security/index.ts +15 -10
  452. package/src/security/interfaces/IssuerResolver.ts +27 -0
  453. package/src/security/primitives/$issuer.ts +55 -0
  454. package/src/security/providers/SecurityProvider.ts +179 -0
  455. package/src/security/providers/ServerBasicAuthProvider.ts +6 -2
  456. package/src/security/providers/ServerSecurityProvider.ts +63 -41
  457. package/src/server/auth/index.ts +12 -7
  458. package/src/server/cache/index.ts +7 -22
  459. package/src/server/compress/index.ts +10 -2
  460. package/src/server/cookies/index.ts +7 -5
  461. package/src/server/cookies/primitives/$cookie.ts +33 -11
  462. package/src/server/core/index.ts +16 -6
  463. package/src/server/core/interfaces/ServerRequest.ts +83 -1
  464. package/src/server/core/primitives/$action.spec.ts +1 -1
  465. package/src/server/core/primitives/$action.ts +8 -3
  466. package/src/server/core/providers/NodeHttpServerProvider.spec.ts +9 -3
  467. package/src/server/core/providers/NodeHttpServerProvider.ts +9 -3
  468. package/src/server/core/services/ServerRequestParser.spec.ts +520 -0
  469. package/src/server/core/services/ServerRequestParser.ts +306 -13
  470. package/src/server/cors/index.ts +7 -21
  471. package/src/server/cors/primitives/$cors.ts +6 -2
  472. package/src/server/health/index.ts +8 -2
  473. package/src/server/helmet/index.ts +11 -3
  474. package/src/server/links/index.ts +11 -6
  475. package/src/server/metrics/index.ts +10 -3
  476. package/src/server/multipart/index.ts +9 -3
  477. package/src/server/proxy/index.ts +8 -2
  478. package/src/server/rate-limit/index.ts +21 -25
  479. package/src/server/rate-limit/primitives/$rateLimit.ts +6 -2
  480. package/src/server/rate-limit/providers/ServerRateLimitProvider.spec.ts +38 -14
  481. package/src/server/rate-limit/providers/ServerRateLimitProvider.ts +22 -56
  482. package/src/server/static/index.ts +8 -2
  483. package/src/server/static/providers/ServerStaticProvider.ts +1 -1
  484. package/src/server/swagger/index.ts +9 -4
  485. package/src/server/swagger/providers/ServerSwaggerProvider.ts +1 -1
  486. package/src/sms/index.ts +9 -5
  487. package/src/sms/providers/LocalSmsProvider.spec.ts +1 -1
  488. package/src/sms/providers/LocalSmsProvider.ts +1 -1
  489. package/src/system/index.browser.ts +36 -0
  490. package/src/system/index.ts +62 -0
  491. package/src/system/index.workerd.ts +1 -0
  492. package/src/{file → system}/providers/FileSystemProvider.ts +24 -0
  493. package/src/{file → system}/providers/MemoryFileSystemProvider.ts +116 -3
  494. package/src/system/providers/MemoryShellProvider.ts +164 -0
  495. package/src/{file → system}/providers/NodeFileSystemProvider.spec.ts +2 -2
  496. package/src/{file → system}/providers/NodeFileSystemProvider.ts +47 -2
  497. package/src/system/providers/NodeShellProvider.ts +184 -0
  498. package/src/system/providers/ShellProvider.ts +74 -0
  499. package/src/{file → system}/services/FileDetector.spec.ts +2 -2
  500. package/src/thread/index.ts +11 -2
  501. package/src/topic/core/index.ts +12 -5
  502. package/src/vite/tasks/buildClient.ts +2 -7
  503. package/src/vite/tasks/buildServer.ts +19 -13
  504. package/src/vite/tasks/generateCloudflare.ts +10 -7
  505. package/src/vite/tasks/generateDocker.ts +4 -0
  506. package/src/websocket/index.ts +12 -8
  507. package/dist/file/index.d.ts.map +0 -1
  508. package/dist/file/index.js.map +0 -1
  509. package/src/cli/assets/apiIndexTs.ts +0 -16
  510. package/src/cli/assets/mainServerTs.ts +0 -24
  511. package/src/cli/assets/webAppRouterTs.ts +0 -16
  512. package/src/cli/assets/webHelloComponentTsx.ts +0 -20
  513. package/src/cli/providers/ViteTemplateProvider.ts +0 -27
  514. package/src/file/index.ts +0 -43
  515. /package/src/cli/{assets → templates}/apiHelloControllerTs.ts +0 -0
  516. /package/src/cli/{assets → templates}/biomeJson.ts +0 -0
  517. /package/src/cli/{assets → templates}/dummySpecTs.ts +0 -0
  518. /package/src/cli/{assets → templates}/editorconfig.ts +0 -0
  519. /package/src/cli/{assets → templates}/mainBrowserTs.ts +0 -0
  520. /package/src/cli/{assets → templates}/tsconfigJson.ts +0 -0
  521. /package/src/cli/{assets → templates}/webIndexTs.ts +0 -0
  522. /package/src/{file → system}/errors/FileError.ts +0 -0
  523. /package/src/{file → system}/services/FileDetector.ts +0 -0
@@ -1,11 +1,13 @@
1
- import { $hook, $inject, $module, Alepha, KIND, Primitive, createPrimitive } from "alepha";
1
+ import { $hook, $inject, $module, Alepha, AlephaError, Json, KIND, Primitive, createPrimitive, isFileLike } from "alepha";
2
2
  import { AlephaServer, ServerRouterProvider } from "alepha/server";
3
3
  import { createReadStream } from "node:fs";
4
- import { access, readdir, stat } from "node:fs/promises";
4
+ import { access, copyFile, cp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
5
5
  import { basename, isAbsolute, join } from "node:path";
6
6
  import { DateTimeProvider } from "alepha/datetime";
7
- import { FileDetector } from "alepha/file";
8
7
  import { $logger } from "alepha/logger";
8
+ import { PassThrough, Readable } from "node:stream";
9
+ import { fileURLToPath } from "node:url";
10
+ import { exec, spawn } from "node:child_process";
9
11
 
10
12
  //#region ../../src/server/static/primitives/$serve.ts
11
13
  /**
@@ -17,6 +19,1846 @@ const $serve = (options = {}) => {
17
19
  var ServePrimitive = class extends Primitive {};
18
20
  $serve[KIND] = ServePrimitive;
19
21
 
22
+ //#endregion
23
+ //#region ../../src/system/providers/FileSystemProvider.ts
24
+ /**
25
+ * FileSystem interface providing utilities for working with files.
26
+ */
27
+ var FileSystemProvider = class {};
28
+
29
+ //#endregion
30
+ //#region ../../src/system/providers/MemoryFileSystemProvider.ts
31
+ /**
32
+ * In-memory implementation of FileSystemProvider for testing.
33
+ *
34
+ * This provider stores all files and directories in memory, making it ideal for
35
+ * unit tests that need to verify file operations without touching the real file system.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // In tests, substitute the real FileSystemProvider with MemoryFileSystemProvider
40
+ * const alepha = Alepha.create().with({
41
+ * provide: FileSystemProvider,
42
+ * use: MemoryFileSystemProvider,
43
+ * });
44
+ *
45
+ * // Run code that uses FileSystemProvider
46
+ * const service = alepha.inject(MyService);
47
+ * await service.saveFile("test.txt", "Hello World");
48
+ *
49
+ * // Verify the file was written
50
+ * const memoryFs = alepha.inject(MemoryFileSystemProvider);
51
+ * expect(memoryFs.files.get("test.txt")?.toString()).toBe("Hello World");
52
+ * ```
53
+ */
54
+ var MemoryFileSystemProvider = class {
55
+ json = $inject(Json);
56
+ /**
57
+ * In-memory storage for files (path -> content)
58
+ */
59
+ files = /* @__PURE__ */ new Map();
60
+ /**
61
+ * In-memory storage for directories
62
+ */
63
+ directories = /* @__PURE__ */ new Set();
64
+ /**
65
+ * Track mkdir calls for test assertions
66
+ */
67
+ mkdirCalls = [];
68
+ /**
69
+ * Track writeFile calls for test assertions
70
+ */
71
+ writeFileCalls = [];
72
+ /**
73
+ * Track readFile calls for test assertions
74
+ */
75
+ readFileCalls = [];
76
+ /**
77
+ * Track rm calls for test assertions
78
+ */
79
+ rmCalls = [];
80
+ /**
81
+ * Track join calls for test assertions
82
+ */
83
+ joinCalls = [];
84
+ /**
85
+ * Error to throw on mkdir (for testing error handling)
86
+ */
87
+ mkdirError = null;
88
+ /**
89
+ * Error to throw on writeFile (for testing error handling)
90
+ */
91
+ writeFileError = null;
92
+ /**
93
+ * Error to throw on readFile (for testing error handling)
94
+ */
95
+ readFileError = null;
96
+ constructor(options = {}) {
97
+ this.mkdirError = options.mkdirError ?? null;
98
+ this.writeFileError = options.writeFileError ?? null;
99
+ this.readFileError = options.readFileError ?? null;
100
+ }
101
+ /**
102
+ * Join path segments using forward slashes.
103
+ * Uses Node's path.join for proper normalization (handles .. and .)
104
+ */
105
+ join(...paths) {
106
+ this.joinCalls.push(paths);
107
+ return join(...paths);
108
+ }
109
+ /**
110
+ * Create a FileLike object from various sources.
111
+ */
112
+ createFile(options) {
113
+ if ("path" in options) {
114
+ const filePath = options.path;
115
+ const buffer = this.files.get(filePath);
116
+ if (buffer === void 0) throw new Error(`ENOENT: no such file or directory, open '${filePath}'`);
117
+ return {
118
+ name: options.name ?? filePath.split("/").pop() ?? "file",
119
+ type: options.type ?? "application/octet-stream",
120
+ size: buffer.byteLength,
121
+ lastModified: Date.now(),
122
+ stream: () => {
123
+ throw new Error("Stream not implemented in MemoryFileSystemProvider");
124
+ },
125
+ arrayBuffer: async () => buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength),
126
+ text: async () => buffer.toString("utf-8")
127
+ };
128
+ }
129
+ if ("buffer" in options) {
130
+ const buffer = options.buffer;
131
+ return {
132
+ name: options.name ?? "file",
133
+ type: options.type ?? "application/octet-stream",
134
+ size: buffer.byteLength,
135
+ lastModified: Date.now(),
136
+ stream: () => {
137
+ throw new Error("Stream not implemented in MemoryFileSystemProvider");
138
+ },
139
+ arrayBuffer: async () => buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength),
140
+ text: async () => buffer.toString("utf-8")
141
+ };
142
+ }
143
+ if ("text" in options) {
144
+ const buffer = Buffer.from(options.text, "utf-8");
145
+ return {
146
+ name: options.name ?? "file.txt",
147
+ type: options.type ?? "text/plain",
148
+ size: buffer.byteLength,
149
+ lastModified: Date.now(),
150
+ stream: () => {
151
+ throw new Error("Stream not implemented in MemoryFileSystemProvider");
152
+ },
153
+ arrayBuffer: async () => buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength),
154
+ text: async () => options.text
155
+ };
156
+ }
157
+ throw new Error("MemoryFileSystemProvider.createFile: unsupported options. Only buffer and text are supported.");
158
+ }
159
+ /**
160
+ * Remove a file or directory from memory.
161
+ */
162
+ async rm(path, options) {
163
+ this.rmCalls.push({
164
+ path,
165
+ options
166
+ });
167
+ if (!(this.files.has(path) || this.directories.has(path)) && !options?.force) throw new Error(`ENOENT: no such file or directory, rm '${path}'`);
168
+ if (this.directories.has(path)) if (options?.recursive) {
169
+ this.directories.delete(path);
170
+ for (const filePath of this.files.keys()) if (filePath.startsWith(`${path}/`)) this.files.delete(filePath);
171
+ for (const dirPath of this.directories) if (dirPath.startsWith(`${path}/`)) this.directories.delete(dirPath);
172
+ } else throw new Error(`EISDIR: illegal operation on a directory, rm '${path}'`);
173
+ else this.files.delete(path);
174
+ }
175
+ /**
176
+ * Copy a file or directory in memory.
177
+ */
178
+ async cp(src, dest, options) {
179
+ if (this.directories.has(src)) {
180
+ if (!options?.recursive) throw new Error(`Cannot copy directory without recursive option: ${src}`);
181
+ this.directories.add(dest);
182
+ for (const [filePath, content] of this.files) if (filePath.startsWith(`${src}/`)) {
183
+ const newPath = filePath.replace(src, dest);
184
+ this.files.set(newPath, Buffer.from(content));
185
+ }
186
+ } else if (this.files.has(src)) {
187
+ const content = this.files.get(src);
188
+ this.files.set(dest, Buffer.from(content));
189
+ } else throw new Error(`ENOENT: no such file or directory, cp '${src}'`);
190
+ }
191
+ /**
192
+ * Move/rename a file or directory in memory.
193
+ */
194
+ async mv(src, dest) {
195
+ if (this.directories.has(src)) {
196
+ this.directories.delete(src);
197
+ this.directories.add(dest);
198
+ for (const [filePath, content] of this.files) if (filePath.startsWith(`${src}/`)) {
199
+ const newPath = filePath.replace(src, dest);
200
+ this.files.delete(filePath);
201
+ this.files.set(newPath, content);
202
+ }
203
+ } else if (this.files.has(src)) {
204
+ const content = this.files.get(src);
205
+ this.files.delete(src);
206
+ this.files.set(dest, content);
207
+ } else throw new Error(`ENOENT: no such file or directory, mv '${src}'`);
208
+ }
209
+ /**
210
+ * Create a directory in memory.
211
+ */
212
+ async mkdir(path, options) {
213
+ this.mkdirCalls.push({
214
+ path,
215
+ options
216
+ });
217
+ if (this.mkdirError) throw this.mkdirError;
218
+ if (this.directories.has(path) && !options?.recursive) throw new Error(`EEXIST: file already exists, mkdir '${path}'`);
219
+ this.directories.add(path);
220
+ if (options?.recursive) {
221
+ const parts = path.split("/").filter(Boolean);
222
+ let current = "";
223
+ for (const part of parts) {
224
+ current = current ? `${current}/${part}` : part;
225
+ this.directories.add(current);
226
+ }
227
+ }
228
+ }
229
+ /**
230
+ * List files in a directory.
231
+ */
232
+ async ls(path, options) {
233
+ const normalizedPath = path.replace(/\/$/, "");
234
+ const entries = /* @__PURE__ */ new Set();
235
+ for (const filePath of this.files.keys()) if (filePath.startsWith(`${normalizedPath}/`)) {
236
+ const relativePath = filePath.slice(normalizedPath.length + 1);
237
+ const parts = relativePath.split("/");
238
+ if (options?.recursive) entries.add(relativePath);
239
+ else entries.add(parts[0]);
240
+ }
241
+ for (const dirPath of this.directories) if (dirPath.startsWith(`${normalizedPath}/`) && dirPath !== normalizedPath) {
242
+ const relativePath = dirPath.slice(normalizedPath.length + 1);
243
+ const parts = relativePath.split("/");
244
+ if (options?.recursive) entries.add(relativePath);
245
+ else if (parts.length === 1) entries.add(parts[0]);
246
+ }
247
+ let result = Array.from(entries);
248
+ if (!options?.hidden) result = result.filter((entry) => !entry.startsWith("."));
249
+ return result.sort();
250
+ }
251
+ /**
252
+ * Check if a file or directory exists in memory.
253
+ */
254
+ async exists(path) {
255
+ return this.files.has(path) || this.directories.has(path);
256
+ }
257
+ /**
258
+ * Read a file from memory.
259
+ */
260
+ async readFile(path) {
261
+ this.readFileCalls.push(path);
262
+ if (this.readFileError) throw this.readFileError;
263
+ const content = this.files.get(path);
264
+ if (!content) throw new Error(`ENOENT: no such file or directory, open '${path}'`);
265
+ return content;
266
+ }
267
+ /**
268
+ * Read a file from memory as text.
269
+ */
270
+ async readTextFile(path) {
271
+ return (await this.readFile(path)).toString("utf-8");
272
+ }
273
+ /**
274
+ * Read a file from memory as JSON.
275
+ */
276
+ async readJsonFile(path) {
277
+ const text = await this.readTextFile(path);
278
+ return this.json.parse(text);
279
+ }
280
+ /**
281
+ * Write a file to memory.
282
+ */
283
+ async writeFile(path, data) {
284
+ const dataStr = typeof data === "string" ? data : data instanceof Buffer || data instanceof Uint8Array ? data.toString("utf-8") : await data.text();
285
+ this.writeFileCalls.push({
286
+ path,
287
+ data: dataStr
288
+ });
289
+ if (this.writeFileError) throw this.writeFileError;
290
+ const buffer = typeof data === "string" ? Buffer.from(data, "utf-8") : data instanceof Buffer ? data : data instanceof Uint8Array ? Buffer.from(data) : Buffer.from(await data.text(), "utf-8");
291
+ this.files.set(path, buffer);
292
+ }
293
+ /**
294
+ * Reset all in-memory state (useful between tests).
295
+ */
296
+ reset() {
297
+ this.files.clear();
298
+ this.directories.clear();
299
+ this.mkdirCalls = [];
300
+ this.writeFileCalls = [];
301
+ this.readFileCalls = [];
302
+ this.rmCalls = [];
303
+ this.joinCalls = [];
304
+ this.mkdirError = null;
305
+ this.writeFileError = null;
306
+ this.readFileError = null;
307
+ }
308
+ /**
309
+ * Check if a file was written during the test.
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * expect(fs.wasWritten("/project/tsconfig.json")).toBe(true);
314
+ * ```
315
+ */
316
+ wasWritten(path) {
317
+ return this.writeFileCalls.some((call) => call.path === path);
318
+ }
319
+ /**
320
+ * Check if a file was written with content matching a pattern.
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * expect(fs.wasWrittenMatching("/project/tsconfig.json", /extends/)).toBe(true);
325
+ * ```
326
+ */
327
+ wasWrittenMatching(path, pattern) {
328
+ const call = this.writeFileCalls.find((c) => c.path === path);
329
+ return call ? pattern.test(call.data) : false;
330
+ }
331
+ /**
332
+ * Check if a file was read during the test.
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * expect(fs.wasRead("/project/package.json")).toBe(true);
337
+ * ```
338
+ */
339
+ wasRead(path) {
340
+ return this.readFileCalls.includes(path);
341
+ }
342
+ /**
343
+ * Check if a file was deleted during the test.
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * expect(fs.wasDeleted("/project/old-file.txt")).toBe(true);
348
+ * ```
349
+ */
350
+ wasDeleted(path) {
351
+ return this.rmCalls.some((call) => call.path === path);
352
+ }
353
+ /**
354
+ * Get the content of a file as a string (convenience method for testing).
355
+ */
356
+ getFileContent(path) {
357
+ return this.files.get(path)?.toString("utf-8");
358
+ }
359
+ };
360
+
361
+ //#endregion
362
+ //#region ../../src/system/providers/MemoryShellProvider.ts
363
+ /**
364
+ * In-memory implementation of ShellProvider for testing.
365
+ *
366
+ * Records all commands that would be executed without actually running them.
367
+ * Can be configured to return specific outputs or throw errors for testing.
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * // In tests, substitute the real ShellProvider with MemoryShellProvider
372
+ * const alepha = Alepha.create().with({
373
+ * provide: ShellProvider,
374
+ * use: MemoryShellProvider,
375
+ * });
376
+ *
377
+ * // Configure mock behavior
378
+ * const shell = alepha.inject(MemoryShellProvider);
379
+ * shell.configure({
380
+ * outputs: { "echo hello": "hello\n" },
381
+ * errors: { "failing-cmd": "Command failed" },
382
+ * });
383
+ *
384
+ * // Or use the fluent API
385
+ * shell.outputs.set("another-cmd", "output");
386
+ * shell.errors.set("another-error", "Error message");
387
+ *
388
+ * // Run code that uses ShellProvider
389
+ * const service = alepha.inject(MyService);
390
+ * await service.doSomething();
391
+ *
392
+ * // Verify commands were called
393
+ * expect(shell.calls).toHaveLength(2);
394
+ * expect(shell.calls[0].command).toBe("yarn install");
395
+ * ```
396
+ */
397
+ var MemoryShellProvider = class {
398
+ /**
399
+ * All recorded shell calls.
400
+ */
401
+ calls = [];
402
+ /**
403
+ * Simulated outputs for specific commands.
404
+ */
405
+ outputs = /* @__PURE__ */ new Map();
406
+ /**
407
+ * Commands that should throw an error.
408
+ */
409
+ errors = /* @__PURE__ */ new Map();
410
+ /**
411
+ * Commands considered installed in the system PATH.
412
+ */
413
+ installedCommands = /* @__PURE__ */ new Set();
414
+ /**
415
+ * Configure the mock with predefined outputs, errors, and installed commands.
416
+ */
417
+ configure(options) {
418
+ if (options.outputs) for (const [cmd, output] of Object.entries(options.outputs)) this.outputs.set(cmd, output);
419
+ if (options.errors) for (const [cmd, error] of Object.entries(options.errors)) this.errors.set(cmd, error);
420
+ if (options.installedCommands) for (const cmd of options.installedCommands) this.installedCommands.add(cmd);
421
+ return this;
422
+ }
423
+ /**
424
+ * Record command and return simulated output.
425
+ */
426
+ async run(command, options = {}) {
427
+ this.calls.push({
428
+ command,
429
+ options
430
+ });
431
+ const errorMsg = this.errors.get(command);
432
+ if (errorMsg) throw new Error(errorMsg);
433
+ return this.outputs.get(command) ?? "";
434
+ }
435
+ /**
436
+ * Check if a specific command was called.
437
+ */
438
+ wasCalled(command) {
439
+ return this.calls.some((call) => call.command === command);
440
+ }
441
+ /**
442
+ * Check if a command matching a pattern was called.
443
+ */
444
+ wasCalledMatching(pattern) {
445
+ return this.calls.some((call) => pattern.test(call.command));
446
+ }
447
+ /**
448
+ * Get all calls matching a pattern.
449
+ */
450
+ getCallsMatching(pattern) {
451
+ return this.calls.filter((call) => pattern.test(call.command));
452
+ }
453
+ /**
454
+ * Check if a command is installed.
455
+ */
456
+ async isInstalled(command) {
457
+ return this.installedCommands.has(command);
458
+ }
459
+ /**
460
+ * Reset all recorded state.
461
+ */
462
+ reset() {
463
+ this.calls = [];
464
+ this.outputs.clear();
465
+ this.errors.clear();
466
+ this.installedCommands.clear();
467
+ }
468
+ };
469
+
470
+ //#endregion
471
+ //#region ../../src/system/services/FileDetector.ts
472
+ /**
473
+ * Service for detecting file types and getting content types.
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * const detector = alepha.inject(FileDetector);
478
+ *
479
+ * // Get content type from filename
480
+ * const mimeType = detector.getContentType("image.png"); // "image/png"
481
+ *
482
+ * // Detect file type by magic bytes
483
+ * const stream = createReadStream('image.png');
484
+ * const result = await detector.detectFileType(stream, 'image.png');
485
+ * console.log(result.mimeType); // 'image/png'
486
+ * console.log(result.verified); // true if magic bytes match
487
+ * ```
488
+ */
489
+ var FileDetector = class FileDetector {
490
+ /**
491
+ * Magic byte signatures for common file formats.
492
+ * Each signature is represented as an array of bytes or null (wildcard).
493
+ */
494
+ static MAGIC_BYTES = {
495
+ png: [{
496
+ signature: [
497
+ 137,
498
+ 80,
499
+ 78,
500
+ 71,
501
+ 13,
502
+ 10,
503
+ 26,
504
+ 10
505
+ ],
506
+ mimeType: "image/png"
507
+ }],
508
+ jpg: [
509
+ {
510
+ signature: [
511
+ 255,
512
+ 216,
513
+ 255,
514
+ 224
515
+ ],
516
+ mimeType: "image/jpeg"
517
+ },
518
+ {
519
+ signature: [
520
+ 255,
521
+ 216,
522
+ 255,
523
+ 225
524
+ ],
525
+ mimeType: "image/jpeg"
526
+ },
527
+ {
528
+ signature: [
529
+ 255,
530
+ 216,
531
+ 255,
532
+ 226
533
+ ],
534
+ mimeType: "image/jpeg"
535
+ },
536
+ {
537
+ signature: [
538
+ 255,
539
+ 216,
540
+ 255,
541
+ 227
542
+ ],
543
+ mimeType: "image/jpeg"
544
+ },
545
+ {
546
+ signature: [
547
+ 255,
548
+ 216,
549
+ 255,
550
+ 232
551
+ ],
552
+ mimeType: "image/jpeg"
553
+ }
554
+ ],
555
+ jpeg: [
556
+ {
557
+ signature: [
558
+ 255,
559
+ 216,
560
+ 255,
561
+ 224
562
+ ],
563
+ mimeType: "image/jpeg"
564
+ },
565
+ {
566
+ signature: [
567
+ 255,
568
+ 216,
569
+ 255,
570
+ 225
571
+ ],
572
+ mimeType: "image/jpeg"
573
+ },
574
+ {
575
+ signature: [
576
+ 255,
577
+ 216,
578
+ 255,
579
+ 226
580
+ ],
581
+ mimeType: "image/jpeg"
582
+ },
583
+ {
584
+ signature: [
585
+ 255,
586
+ 216,
587
+ 255,
588
+ 227
589
+ ],
590
+ mimeType: "image/jpeg"
591
+ },
592
+ {
593
+ signature: [
594
+ 255,
595
+ 216,
596
+ 255,
597
+ 232
598
+ ],
599
+ mimeType: "image/jpeg"
600
+ }
601
+ ],
602
+ gif: [{
603
+ signature: [
604
+ 71,
605
+ 73,
606
+ 70,
607
+ 56,
608
+ 55,
609
+ 97
610
+ ],
611
+ mimeType: "image/gif"
612
+ }, {
613
+ signature: [
614
+ 71,
615
+ 73,
616
+ 70,
617
+ 56,
618
+ 57,
619
+ 97
620
+ ],
621
+ mimeType: "image/gif"
622
+ }],
623
+ webp: [{
624
+ signature: [
625
+ 82,
626
+ 73,
627
+ 70,
628
+ 70,
629
+ null,
630
+ null,
631
+ null,
632
+ null,
633
+ 87,
634
+ 69,
635
+ 66,
636
+ 80
637
+ ],
638
+ mimeType: "image/webp"
639
+ }],
640
+ bmp: [{
641
+ signature: [66, 77],
642
+ mimeType: "image/bmp"
643
+ }],
644
+ ico: [{
645
+ signature: [
646
+ 0,
647
+ 0,
648
+ 1,
649
+ 0
650
+ ],
651
+ mimeType: "image/x-icon"
652
+ }],
653
+ tiff: [{
654
+ signature: [
655
+ 73,
656
+ 73,
657
+ 42,
658
+ 0
659
+ ],
660
+ mimeType: "image/tiff"
661
+ }, {
662
+ signature: [
663
+ 77,
664
+ 77,
665
+ 0,
666
+ 42
667
+ ],
668
+ mimeType: "image/tiff"
669
+ }],
670
+ tif: [{
671
+ signature: [
672
+ 73,
673
+ 73,
674
+ 42,
675
+ 0
676
+ ],
677
+ mimeType: "image/tiff"
678
+ }, {
679
+ signature: [
680
+ 77,
681
+ 77,
682
+ 0,
683
+ 42
684
+ ],
685
+ mimeType: "image/tiff"
686
+ }],
687
+ pdf: [{
688
+ signature: [
689
+ 37,
690
+ 80,
691
+ 68,
692
+ 70,
693
+ 45
694
+ ],
695
+ mimeType: "application/pdf"
696
+ }],
697
+ zip: [
698
+ {
699
+ signature: [
700
+ 80,
701
+ 75,
702
+ 3,
703
+ 4
704
+ ],
705
+ mimeType: "application/zip"
706
+ },
707
+ {
708
+ signature: [
709
+ 80,
710
+ 75,
711
+ 5,
712
+ 6
713
+ ],
714
+ mimeType: "application/zip"
715
+ },
716
+ {
717
+ signature: [
718
+ 80,
719
+ 75,
720
+ 7,
721
+ 8
722
+ ],
723
+ mimeType: "application/zip"
724
+ }
725
+ ],
726
+ rar: [{
727
+ signature: [
728
+ 82,
729
+ 97,
730
+ 114,
731
+ 33,
732
+ 26,
733
+ 7
734
+ ],
735
+ mimeType: "application/vnd.rar"
736
+ }],
737
+ "7z": [{
738
+ signature: [
739
+ 55,
740
+ 122,
741
+ 188,
742
+ 175,
743
+ 39,
744
+ 28
745
+ ],
746
+ mimeType: "application/x-7z-compressed"
747
+ }],
748
+ tar: [{
749
+ signature: [
750
+ 117,
751
+ 115,
752
+ 116,
753
+ 97,
754
+ 114
755
+ ],
756
+ mimeType: "application/x-tar"
757
+ }],
758
+ gz: [{
759
+ signature: [31, 139],
760
+ mimeType: "application/gzip"
761
+ }],
762
+ tgz: [{
763
+ signature: [31, 139],
764
+ mimeType: "application/gzip"
765
+ }],
766
+ mp3: [
767
+ {
768
+ signature: [255, 251],
769
+ mimeType: "audio/mpeg"
770
+ },
771
+ {
772
+ signature: [255, 243],
773
+ mimeType: "audio/mpeg"
774
+ },
775
+ {
776
+ signature: [255, 242],
777
+ mimeType: "audio/mpeg"
778
+ },
779
+ {
780
+ signature: [
781
+ 73,
782
+ 68,
783
+ 51
784
+ ],
785
+ mimeType: "audio/mpeg"
786
+ }
787
+ ],
788
+ wav: [{
789
+ signature: [
790
+ 82,
791
+ 73,
792
+ 70,
793
+ 70,
794
+ null,
795
+ null,
796
+ null,
797
+ null,
798
+ 87,
799
+ 65,
800
+ 86,
801
+ 69
802
+ ],
803
+ mimeType: "audio/wav"
804
+ }],
805
+ ogg: [{
806
+ signature: [
807
+ 79,
808
+ 103,
809
+ 103,
810
+ 83
811
+ ],
812
+ mimeType: "audio/ogg"
813
+ }],
814
+ flac: [{
815
+ signature: [
816
+ 102,
817
+ 76,
818
+ 97,
819
+ 67
820
+ ],
821
+ mimeType: "audio/flac"
822
+ }],
823
+ mp4: [
824
+ {
825
+ signature: [
826
+ null,
827
+ null,
828
+ null,
829
+ null,
830
+ 102,
831
+ 116,
832
+ 121,
833
+ 112
834
+ ],
835
+ mimeType: "video/mp4"
836
+ },
837
+ {
838
+ signature: [
839
+ null,
840
+ null,
841
+ null,
842
+ null,
843
+ 102,
844
+ 116,
845
+ 121,
846
+ 112,
847
+ 105,
848
+ 115,
849
+ 111,
850
+ 109
851
+ ],
852
+ mimeType: "video/mp4"
853
+ },
854
+ {
855
+ signature: [
856
+ null,
857
+ null,
858
+ null,
859
+ null,
860
+ 102,
861
+ 116,
862
+ 121,
863
+ 112,
864
+ 109,
865
+ 112,
866
+ 52,
867
+ 50
868
+ ],
869
+ mimeType: "video/mp4"
870
+ }
871
+ ],
872
+ webm: [{
873
+ signature: [
874
+ 26,
875
+ 69,
876
+ 223,
877
+ 163
878
+ ],
879
+ mimeType: "video/webm"
880
+ }],
881
+ avi: [{
882
+ signature: [
883
+ 82,
884
+ 73,
885
+ 70,
886
+ 70,
887
+ null,
888
+ null,
889
+ null,
890
+ null,
891
+ 65,
892
+ 86,
893
+ 73,
894
+ 32
895
+ ],
896
+ mimeType: "video/x-msvideo"
897
+ }],
898
+ mov: [{
899
+ signature: [
900
+ null,
901
+ null,
902
+ null,
903
+ null,
904
+ 102,
905
+ 116,
906
+ 121,
907
+ 112,
908
+ 113,
909
+ 116,
910
+ 32,
911
+ 32
912
+ ],
913
+ mimeType: "video/quicktime"
914
+ }],
915
+ mkv: [{
916
+ signature: [
917
+ 26,
918
+ 69,
919
+ 223,
920
+ 163
921
+ ],
922
+ mimeType: "video/x-matroska"
923
+ }],
924
+ docx: [{
925
+ signature: [
926
+ 80,
927
+ 75,
928
+ 3,
929
+ 4
930
+ ],
931
+ mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
932
+ }],
933
+ xlsx: [{
934
+ signature: [
935
+ 80,
936
+ 75,
937
+ 3,
938
+ 4
939
+ ],
940
+ mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
941
+ }],
942
+ pptx: [{
943
+ signature: [
944
+ 80,
945
+ 75,
946
+ 3,
947
+ 4
948
+ ],
949
+ mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
950
+ }],
951
+ doc: [{
952
+ signature: [
953
+ 208,
954
+ 207,
955
+ 17,
956
+ 224,
957
+ 161,
958
+ 177,
959
+ 26,
960
+ 225
961
+ ],
962
+ mimeType: "application/msword"
963
+ }],
964
+ xls: [{
965
+ signature: [
966
+ 208,
967
+ 207,
968
+ 17,
969
+ 224,
970
+ 161,
971
+ 177,
972
+ 26,
973
+ 225
974
+ ],
975
+ mimeType: "application/vnd.ms-excel"
976
+ }],
977
+ ppt: [{
978
+ signature: [
979
+ 208,
980
+ 207,
981
+ 17,
982
+ 224,
983
+ 161,
984
+ 177,
985
+ 26,
986
+ 225
987
+ ],
988
+ mimeType: "application/vnd.ms-powerpoint"
989
+ }]
990
+ };
991
+ /**
992
+ * All possible format signatures for checking against actual file content
993
+ */
994
+ static ALL_SIGNATURES = Object.entries(FileDetector.MAGIC_BYTES).flatMap(([ext, signatures]) => signatures.map((sig) => ({
995
+ ext,
996
+ ...sig
997
+ })));
998
+ /**
999
+ * MIME type map for file extensions.
1000
+ *
1001
+ * Can be used to get the content type of file based on its extension.
1002
+ * Feel free to add more mime types in your project!
1003
+ */
1004
+ static mimeMap = {
1005
+ json: "application/json",
1006
+ txt: "text/plain",
1007
+ html: "text/html",
1008
+ htm: "text/html",
1009
+ xml: "application/xml",
1010
+ csv: "text/csv",
1011
+ pdf: "application/pdf",
1012
+ md: "text/markdown",
1013
+ markdown: "text/markdown",
1014
+ rtf: "application/rtf",
1015
+ css: "text/css",
1016
+ js: "application/javascript",
1017
+ mjs: "application/javascript",
1018
+ ts: "application/typescript",
1019
+ jsx: "text/jsx",
1020
+ tsx: "text/tsx",
1021
+ zip: "application/zip",
1022
+ rar: "application/vnd.rar",
1023
+ "7z": "application/x-7z-compressed",
1024
+ tar: "application/x-tar",
1025
+ gz: "application/gzip",
1026
+ tgz: "application/gzip",
1027
+ png: "image/png",
1028
+ jpg: "image/jpeg",
1029
+ jpeg: "image/jpeg",
1030
+ gif: "image/gif",
1031
+ webp: "image/webp",
1032
+ svg: "image/svg+xml",
1033
+ bmp: "image/bmp",
1034
+ ico: "image/x-icon",
1035
+ tiff: "image/tiff",
1036
+ tif: "image/tiff",
1037
+ mp3: "audio/mpeg",
1038
+ wav: "audio/wav",
1039
+ ogg: "audio/ogg",
1040
+ m4a: "audio/mp4",
1041
+ aac: "audio/aac",
1042
+ flac: "audio/flac",
1043
+ mp4: "video/mp4",
1044
+ webm: "video/webm",
1045
+ avi: "video/x-msvideo",
1046
+ mov: "video/quicktime",
1047
+ wmv: "video/x-ms-wmv",
1048
+ flv: "video/x-flv",
1049
+ mkv: "video/x-matroska",
1050
+ doc: "application/msword",
1051
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1052
+ xls: "application/vnd.ms-excel",
1053
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1054
+ ppt: "application/vnd.ms-powerpoint",
1055
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
1056
+ woff: "font/woff",
1057
+ woff2: "font/woff2",
1058
+ ttf: "font/ttf",
1059
+ otf: "font/otf",
1060
+ eot: "application/vnd.ms-fontobject"
1061
+ };
1062
+ /**
1063
+ * Reverse MIME type map for looking up extensions from MIME types.
1064
+ * Prefers shorter, more common extensions when multiple exist.
1065
+ */
1066
+ static reverseMimeMap = (() => {
1067
+ const reverse = {};
1068
+ for (const [ext, mimeType] of Object.entries(FileDetector.mimeMap)) if (!reverse[mimeType]) reverse[mimeType] = ext;
1069
+ return reverse;
1070
+ })();
1071
+ /**
1072
+ * Returns the file extension for a given MIME type.
1073
+ *
1074
+ * @param mimeType - The MIME type to look up
1075
+ * @returns The file extension (without dot), or "bin" if not found
1076
+ *
1077
+ * @example
1078
+ * ```typescript
1079
+ * const detector = alepha.inject(FileDetector);
1080
+ * const ext = detector.getExtensionFromMimeType("image/png"); // "png"
1081
+ * const ext2 = detector.getExtensionFromMimeType("application/octet-stream"); // "bin"
1082
+ * ```
1083
+ */
1084
+ getExtensionFromMimeType(mimeType) {
1085
+ return FileDetector.reverseMimeMap[mimeType] || "bin";
1086
+ }
1087
+ /**
1088
+ * Returns the content type of file based on its filename.
1089
+ *
1090
+ * @param filename - The filename to check
1091
+ * @returns The MIME type
1092
+ *
1093
+ * @example
1094
+ * ```typescript
1095
+ * const detector = alepha.inject(FileDetector);
1096
+ * const mimeType = detector.getContentType("image.png"); // "image/png"
1097
+ * ```
1098
+ */
1099
+ getContentType(filename) {
1100
+ const ext = filename.toLowerCase().split(".").pop() || "";
1101
+ return FileDetector.mimeMap[ext] || "application/octet-stream";
1102
+ }
1103
+ /**
1104
+ * Detects the file type by checking magic bytes against the stream content.
1105
+ *
1106
+ * @param stream - The readable stream to check
1107
+ * @param filename - The filename (used to get the extension)
1108
+ * @returns File type information including MIME type, extension, and verification status
1109
+ *
1110
+ * @example
1111
+ * ```typescript
1112
+ * const detector = alepha.inject(FileDetector);
1113
+ * const stream = createReadStream('image.png');
1114
+ * const result = await detector.detectFileType(stream, 'image.png');
1115
+ * console.log(result.mimeType); // 'image/png'
1116
+ * console.log(result.verified); // true if magic bytes match
1117
+ * ```
1118
+ */
1119
+ async detectFileType(stream, filename) {
1120
+ const expectedMimeType = this.getContentType(filename);
1121
+ const lastDotIndex = filename.lastIndexOf(".");
1122
+ const ext = lastDotIndex > 0 ? filename.substring(lastDotIndex + 1).toLowerCase() : "";
1123
+ const { buffer, stream: newStream } = await this.peekBytes(stream, 16);
1124
+ const expectedSignatures = FileDetector.MAGIC_BYTES[ext];
1125
+ if (expectedSignatures) {
1126
+ for (const { signature, mimeType } of expectedSignatures) if (this.matchesSignature(buffer, signature)) return {
1127
+ mimeType,
1128
+ extension: ext,
1129
+ verified: true,
1130
+ stream: newStream
1131
+ };
1132
+ }
1133
+ for (const { ext: detectedExt, signature, mimeType } of FileDetector.ALL_SIGNATURES) if (detectedExt !== ext && this.matchesSignature(buffer, signature)) return {
1134
+ mimeType,
1135
+ extension: detectedExt,
1136
+ verified: true,
1137
+ stream: newStream
1138
+ };
1139
+ return {
1140
+ mimeType: expectedMimeType,
1141
+ extension: ext,
1142
+ verified: false,
1143
+ stream: newStream
1144
+ };
1145
+ }
1146
+ /**
1147
+ * Reads all bytes from a stream and returns the first N bytes along with a new stream containing all data.
1148
+ * This approach reads the entire stream upfront to avoid complex async handling issues.
1149
+ *
1150
+ * @protected
1151
+ */
1152
+ async peekBytes(stream, numBytes) {
1153
+ const chunks = [];
1154
+ for await (const chunk of stream) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
1155
+ const allData = Buffer.concat(chunks);
1156
+ return {
1157
+ buffer: allData.subarray(0, numBytes),
1158
+ stream: Readable.from(allData)
1159
+ };
1160
+ }
1161
+ /**
1162
+ * Checks if a buffer matches a magic byte signature.
1163
+ *
1164
+ * @protected
1165
+ */
1166
+ matchesSignature(buffer, signature) {
1167
+ if (buffer.length < signature.length) return false;
1168
+ for (let i = 0; i < signature.length; i++) if (signature[i] !== null && buffer[i] !== signature[i]) return false;
1169
+ return true;
1170
+ }
1171
+ };
1172
+
1173
+ //#endregion
1174
+ //#region ../../src/system/providers/NodeFileSystemProvider.ts
1175
+ /**
1176
+ * Node.js implementation of FileSystem interface.
1177
+ *
1178
+ * @example
1179
+ * ```typescript
1180
+ * const fs = alepha.inject(NodeFileSystemProvider);
1181
+ *
1182
+ * // Create from URL
1183
+ * const file1 = fs.createFile({ url: "file:///path/to/file.png" });
1184
+ *
1185
+ * // Create from Buffer
1186
+ * const file2 = fs.createFile({ buffer: Buffer.from("hello"), name: "hello.txt" });
1187
+ *
1188
+ * // Create from text
1189
+ * const file3 = fs.createFile({ text: "Hello, world!", name: "greeting.txt" });
1190
+ *
1191
+ * // File operations
1192
+ * await fs.mkdir("/tmp/mydir", { recursive: true });
1193
+ * await fs.cp("/src/file.txt", "/dest/file.txt");
1194
+ * await fs.mv("/old/path.txt", "/new/path.txt");
1195
+ * const files = await fs.ls("/tmp");
1196
+ * await fs.rm("/tmp/file.txt");
1197
+ * ```
1198
+ */
1199
+ var NodeFileSystemProvider = class {
1200
+ detector = $inject(FileDetector);
1201
+ json = $inject(Json);
1202
+ join(...paths) {
1203
+ return join(...paths);
1204
+ }
1205
+ /**
1206
+ * Creates a FileLike object from various sources.
1207
+ *
1208
+ * @param options - Options for creating the file
1209
+ * @returns A FileLike object
1210
+ *
1211
+ * @example
1212
+ * ```typescript
1213
+ * const fs = alepha.inject(NodeFileSystemProvider);
1214
+ *
1215
+ * // From URL
1216
+ * const file1 = fs.createFile({ url: "https://example.com/image.png" });
1217
+ *
1218
+ * // From Buffer
1219
+ * const file2 = fs.createFile({
1220
+ * buffer: Buffer.from("hello"),
1221
+ * name: "hello.txt",
1222
+ * type: "text/plain"
1223
+ * });
1224
+ *
1225
+ * // From text
1226
+ * const file3 = fs.createFile({ text: "Hello!", name: "greeting.txt" });
1227
+ *
1228
+ * // From stream with detection
1229
+ * const stream = createReadStream("/path/to/file.png");
1230
+ * const file4 = fs.createFile({ stream, name: "image.png" });
1231
+ * ```
1232
+ */
1233
+ createFile(options) {
1234
+ if ("path" in options) {
1235
+ const path = options.path;
1236
+ const filename = path.split("/").pop() || "file";
1237
+ return this.createFileFromUrl(`file://${path}`, {
1238
+ type: options.type,
1239
+ name: options.name || filename
1240
+ });
1241
+ }
1242
+ if ("url" in options) return this.createFileFromUrl(options.url, {
1243
+ type: options.type,
1244
+ name: options.name
1245
+ });
1246
+ if ("response" in options) {
1247
+ if (!options.response.body) throw new AlephaError("Response has no body stream");
1248
+ const res = options.response;
1249
+ const sizeHeader = res.headers.get("content-length");
1250
+ const size = sizeHeader ? parseInt(sizeHeader, 10) : void 0;
1251
+ let name = options.name;
1252
+ const contentDisposition = res.headers.get("content-disposition");
1253
+ if (contentDisposition && !name) {
1254
+ const match = contentDisposition.match(/filename="?([^"]+)"?/);
1255
+ if (match) name = match[1];
1256
+ }
1257
+ const type = options.type || res.headers.get("content-type") || void 0;
1258
+ return this.createFileFromStream(options.response.body, {
1259
+ type,
1260
+ name,
1261
+ size
1262
+ });
1263
+ }
1264
+ if ("file" in options) return this.createFileFromWebFile(options.file, {
1265
+ type: options.type,
1266
+ name: options.name,
1267
+ size: options.size
1268
+ });
1269
+ if ("buffer" in options) return this.createFileFromBuffer(options.buffer, {
1270
+ type: options.type,
1271
+ name: options.name
1272
+ });
1273
+ if ("arrayBuffer" in options) return this.createFileFromBuffer(Buffer.from(options.arrayBuffer), {
1274
+ type: options.type,
1275
+ name: options.name
1276
+ });
1277
+ if ("text" in options) return this.createFileFromBuffer(Buffer.from(options.text, "utf-8"), {
1278
+ type: options.type || "text/plain",
1279
+ name: options.name || "file.txt"
1280
+ });
1281
+ if ("stream" in options) return this.createFileFromStream(options.stream, {
1282
+ type: options.type,
1283
+ name: options.name,
1284
+ size: options.size
1285
+ });
1286
+ throw new AlephaError("Invalid createFile options: no valid source provided");
1287
+ }
1288
+ /**
1289
+ * Removes a file or directory.
1290
+ *
1291
+ * @param path - The path to remove
1292
+ * @param options - Remove options
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * const fs = alepha.inject(NodeFileSystemProvider);
1297
+ *
1298
+ * // Remove a file
1299
+ * await fs.rm("/tmp/file.txt");
1300
+ *
1301
+ * // Remove a directory recursively
1302
+ * await fs.rm("/tmp/mydir", { recursive: true });
1303
+ *
1304
+ * // Remove with force (no error if doesn't exist)
1305
+ * await fs.rm("/tmp/maybe-exists.txt", { force: true });
1306
+ * ```
1307
+ */
1308
+ async rm(path, options) {
1309
+ await rm(path, options);
1310
+ }
1311
+ /**
1312
+ * Copies a file or directory.
1313
+ *
1314
+ * @param src - Source path
1315
+ * @param dest - Destination path
1316
+ * @param options - Copy options
1317
+ *
1318
+ * @example
1319
+ * ```typescript
1320
+ * const fs = alepha.inject(NodeFileSystemProvider);
1321
+ *
1322
+ * // Copy a file
1323
+ * await fs.cp("/src/file.txt", "/dest/file.txt");
1324
+ *
1325
+ * // Copy a directory recursively
1326
+ * await fs.cp("/src/dir", "/dest/dir", { recursive: true });
1327
+ *
1328
+ * // Copy with force (overwrite existing)
1329
+ * await fs.cp("/src/file.txt", "/dest/file.txt", { force: true });
1330
+ * ```
1331
+ */
1332
+ async cp(src, dest, options) {
1333
+ if ((await stat(src)).isDirectory()) {
1334
+ if (!options?.recursive) throw new Error(`Cannot copy directory without recursive option: ${src}`);
1335
+ await cp(src, dest, {
1336
+ recursive: true,
1337
+ force: options?.force ?? false
1338
+ });
1339
+ } else await copyFile(src, dest);
1340
+ }
1341
+ /**
1342
+ * Moves/renames a file or directory.
1343
+ *
1344
+ * @param src - Source path
1345
+ * @param dest - Destination path
1346
+ *
1347
+ * @example
1348
+ * ```typescript
1349
+ * const fs = alepha.inject(NodeFileSystemProvider);
1350
+ *
1351
+ * // Move/rename a file
1352
+ * await fs.mv("/old/path.txt", "/new/path.txt");
1353
+ *
1354
+ * // Move a directory
1355
+ * await fs.mv("/old/dir", "/new/dir");
1356
+ * ```
1357
+ */
1358
+ async mv(src, dest) {
1359
+ await rename(src, dest);
1360
+ }
1361
+ /**
1362
+ * Creates a directory.
1363
+ *
1364
+ * @param path - The directory path to create
1365
+ * @param options - Mkdir options
1366
+ *
1367
+ * @example
1368
+ * ```typescript
1369
+ * const fs = alepha.inject(NodeFileSystemProvider);
1370
+ *
1371
+ * // Create a directory
1372
+ * await fs.mkdir("/tmp/mydir");
1373
+ *
1374
+ * // Create nested directories
1375
+ * await fs.mkdir("/tmp/path/to/dir", { recursive: true });
1376
+ *
1377
+ * // Create with specific permissions
1378
+ * await fs.mkdir("/tmp/mydir", { mode: 0o755 });
1379
+ * ```
1380
+ */
1381
+ async mkdir(path, options = {}) {
1382
+ const p = mkdir(path, {
1383
+ recursive: options.recursive ?? true,
1384
+ mode: options.mode
1385
+ });
1386
+ if (options.force === false) await p;
1387
+ else await p.catch(() => {});
1388
+ }
1389
+ /**
1390
+ * Lists files in a directory.
1391
+ *
1392
+ * @param path - The directory path to list
1393
+ * @param options - List options
1394
+ * @returns Array of filenames
1395
+ *
1396
+ * @example
1397
+ * ```typescript
1398
+ * const fs = alepha.inject(NodeFileSystemProvider);
1399
+ *
1400
+ * // List files in a directory
1401
+ * const files = await fs.ls("/tmp");
1402
+ * console.log(files); // ["file1.txt", "file2.txt", "subdir"]
1403
+ *
1404
+ * // List with hidden files
1405
+ * const allFiles = await fs.ls("/tmp", { hidden: true });
1406
+ *
1407
+ * // List recursively
1408
+ * const allFilesRecursive = await fs.ls("/tmp", { recursive: true });
1409
+ * ```
1410
+ */
1411
+ async ls(path, options) {
1412
+ const entries = await readdir(path);
1413
+ const filteredEntries = options?.hidden ? entries : entries.filter((e) => !e.startsWith("."));
1414
+ if (options?.recursive) {
1415
+ const allFiles = [];
1416
+ for (const entry of filteredEntries) {
1417
+ const fullPath = join(path, entry);
1418
+ if ((await stat(fullPath)).isDirectory()) {
1419
+ allFiles.push(entry);
1420
+ const subFiles = await this.ls(fullPath, options);
1421
+ allFiles.push(...subFiles.map((f) => join(entry, f)));
1422
+ } else allFiles.push(entry);
1423
+ }
1424
+ return allFiles;
1425
+ }
1426
+ return filteredEntries;
1427
+ }
1428
+ /**
1429
+ * Checks if a file or directory exists.
1430
+ *
1431
+ * @param path - The path to check
1432
+ * @returns True if the path exists, false otherwise
1433
+ *
1434
+ * @example
1435
+ * ```typescript
1436
+ * const fs = alepha.inject(NodeFileSystemProvider);
1437
+ *
1438
+ * if (await fs.exists("/tmp/file.txt")) {
1439
+ * console.log("File exists");
1440
+ * }
1441
+ * ```
1442
+ */
1443
+ async exists(path) {
1444
+ try {
1445
+ await access(path);
1446
+ return true;
1447
+ } catch {
1448
+ return false;
1449
+ }
1450
+ }
1451
+ /**
1452
+ * Reads the content of a file.
1453
+ *
1454
+ * @param path - The file path to read
1455
+ * @returns The file content as a Buffer
1456
+ *
1457
+ * @example
1458
+ * ```typescript
1459
+ * const fs = alepha.inject(NodeFileSystemProvider);
1460
+ *
1461
+ * const buffer = await fs.readFile("/tmp/file.txt");
1462
+ * console.log(buffer.toString("utf-8"));
1463
+ * ```
1464
+ */
1465
+ async readFile(path) {
1466
+ return await readFile(path);
1467
+ }
1468
+ /**
1469
+ * Writes data to a file.
1470
+ *
1471
+ * @param path - The file path to write to
1472
+ * @param data - The data to write (Buffer or string)
1473
+ *
1474
+ * @example
1475
+ * ```typescript
1476
+ * const fs = alepha.inject(NodeFileSystemProvider);
1477
+ *
1478
+ * // Write string
1479
+ * await fs.writeFile("/tmp/file.txt", "Hello, world!");
1480
+ *
1481
+ * // Write Buffer
1482
+ * await fs.writeFile("/tmp/file.bin", Buffer.from([0x01, 0x02, 0x03]));
1483
+ * ```
1484
+ */
1485
+ async writeFile(path, data) {
1486
+ if (isFileLike(data)) {
1487
+ await writeFile(path, Readable.from(data.stream()));
1488
+ return;
1489
+ }
1490
+ await writeFile(path, data);
1491
+ }
1492
+ /**
1493
+ * Reads the content of a file as a string.
1494
+ *
1495
+ * @param path - The file path to read
1496
+ * @returns The file content as a string
1497
+ *
1498
+ * @example
1499
+ * ```typescript
1500
+ * const fs = alepha.inject(NodeFileSystemProvider);
1501
+ * const content = await fs.readTextFile("/tmp/file.txt");
1502
+ * ```
1503
+ */
1504
+ async readTextFile(path) {
1505
+ return (await this.readFile(path)).toString("utf-8");
1506
+ }
1507
+ /**
1508
+ * Reads the content of a file as JSON.
1509
+ *
1510
+ * @param path - The file path to read
1511
+ * @returns The parsed JSON content
1512
+ *
1513
+ * @example
1514
+ * ```typescript
1515
+ * const fs = alepha.inject(NodeFileSystemProvider);
1516
+ * const config = await fs.readJsonFile<{ name: string }>("/tmp/config.json");
1517
+ * ```
1518
+ */
1519
+ async readJsonFile(path) {
1520
+ const text = await this.readTextFile(path);
1521
+ return this.json.parse(text);
1522
+ }
1523
+ /**
1524
+ * Creates a FileLike object from a Web File.
1525
+ *
1526
+ * @protected
1527
+ */
1528
+ createFileFromWebFile(source, options = {}) {
1529
+ const name = options.name ?? source.name;
1530
+ return {
1531
+ name,
1532
+ type: options.type ?? (source.type || this.detector.getContentType(name)),
1533
+ size: options.size ?? source.size ?? 0,
1534
+ lastModified: source.lastModified || Date.now(),
1535
+ stream: () => source.stream(),
1536
+ arrayBuffer: async () => {
1537
+ return await source.arrayBuffer();
1538
+ },
1539
+ text: async () => {
1540
+ return await source.text();
1541
+ }
1542
+ };
1543
+ }
1544
+ /**
1545
+ * Creates a FileLike object from a Buffer.
1546
+ *
1547
+ * @protected
1548
+ */
1549
+ createFileFromBuffer(source, options = {}) {
1550
+ const name = options.name ?? "file";
1551
+ return {
1552
+ name,
1553
+ type: options.type ?? this.detector.getContentType(options.name ?? name),
1554
+ size: source.byteLength,
1555
+ lastModified: Date.now(),
1556
+ stream: () => Readable.from(source),
1557
+ arrayBuffer: async () => {
1558
+ return this.bufferToArrayBuffer(source);
1559
+ },
1560
+ text: async () => {
1561
+ return source.toString("utf-8");
1562
+ }
1563
+ };
1564
+ }
1565
+ /**
1566
+ * Creates a FileLike object from a stream.
1567
+ *
1568
+ * @protected
1569
+ */
1570
+ createFileFromStream(source, options = {}) {
1571
+ let buffer = null;
1572
+ return {
1573
+ name: options.name ?? "file",
1574
+ type: options.type ?? this.detector.getContentType(options.name ?? "file"),
1575
+ size: options.size ?? 0,
1576
+ lastModified: Date.now(),
1577
+ stream: () => source,
1578
+ _buffer: null,
1579
+ arrayBuffer: async () => {
1580
+ buffer ??= await this.streamToBuffer(source);
1581
+ return this.bufferToArrayBuffer(buffer);
1582
+ },
1583
+ text: async () => {
1584
+ buffer ??= await this.streamToBuffer(source);
1585
+ return buffer.toString("utf-8");
1586
+ }
1587
+ };
1588
+ }
1589
+ /**
1590
+ * Creates a FileLike object from a URL.
1591
+ *
1592
+ * @protected
1593
+ */
1594
+ createFileFromUrl(url, options = {}) {
1595
+ const parsedUrl = new URL(url);
1596
+ const filename = options.name || parsedUrl.pathname.split("/").pop() || "file";
1597
+ let buffer = null;
1598
+ return {
1599
+ name: filename,
1600
+ type: options.type ?? this.detector.getContentType(filename),
1601
+ size: 0,
1602
+ lastModified: Date.now(),
1603
+ stream: () => this.createStreamFromUrl(url),
1604
+ arrayBuffer: async () => {
1605
+ buffer ??= await this.loadFromUrl(url);
1606
+ return this.bufferToArrayBuffer(buffer);
1607
+ },
1608
+ text: async () => {
1609
+ buffer ??= await this.loadFromUrl(url);
1610
+ return buffer.toString("utf-8");
1611
+ },
1612
+ filepath: url
1613
+ };
1614
+ }
1615
+ /**
1616
+ * Gets a streaming response from a URL.
1617
+ *
1618
+ * @protected
1619
+ */
1620
+ getStreamingResponse(url) {
1621
+ const stream = new PassThrough();
1622
+ fetch(url).then((res) => Readable.fromWeb(res.body).pipe(stream)).catch((err) => stream.destroy(err));
1623
+ return stream;
1624
+ }
1625
+ /**
1626
+ * Loads data from a URL.
1627
+ *
1628
+ * @protected
1629
+ */
1630
+ async loadFromUrl(url) {
1631
+ const parsedUrl = new URL(url);
1632
+ if (parsedUrl.protocol === "file:") return await readFile(fileURLToPath(url));
1633
+ else if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:") {
1634
+ const response = await fetch(url);
1635
+ if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
1636
+ const arrayBuffer = await response.arrayBuffer();
1637
+ return Buffer.from(arrayBuffer);
1638
+ } else throw new Error(`Unsupported protocol: ${parsedUrl.protocol}`);
1639
+ }
1640
+ /**
1641
+ * Creates a stream from a URL.
1642
+ *
1643
+ * @protected
1644
+ */
1645
+ createStreamFromUrl(url) {
1646
+ const parsedUrl = new URL(url);
1647
+ if (parsedUrl.protocol === "file:") return createReadStream(fileURLToPath(url));
1648
+ else if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:") return this.getStreamingResponse(url);
1649
+ else throw new AlephaError(`Unsupported protocol: ${parsedUrl.protocol}`);
1650
+ }
1651
+ /**
1652
+ * Converts a stream-like object to a Buffer.
1653
+ *
1654
+ * @protected
1655
+ */
1656
+ async streamToBuffer(streamLike) {
1657
+ const stream = streamLike instanceof Readable ? streamLike : Readable.fromWeb(streamLike);
1658
+ return new Promise((resolve, reject) => {
1659
+ const buffer = [];
1660
+ stream.on("data", (chunk) => buffer.push(Buffer.from(chunk)));
1661
+ stream.on("end", () => resolve(Buffer.concat(buffer)));
1662
+ stream.on("error", (err) => reject(new AlephaError("Error converting stream", { cause: err })));
1663
+ });
1664
+ }
1665
+ /**
1666
+ * Converts a Node.js Buffer to an ArrayBuffer.
1667
+ *
1668
+ * @protected
1669
+ */
1670
+ bufferToArrayBuffer(buffer) {
1671
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
1672
+ }
1673
+ };
1674
+
1675
+ //#endregion
1676
+ //#region ../../src/system/providers/NodeShellProvider.ts
1677
+ /**
1678
+ * Node.js implementation of ShellProvider.
1679
+ *
1680
+ * Executes shell commands using Node.js child_process module.
1681
+ * Supports binary resolution from node_modules/.bin for local packages.
1682
+ */
1683
+ var NodeShellProvider = class {
1684
+ log = $logger();
1685
+ fs = $inject(FileSystemProvider);
1686
+ /**
1687
+ * Run a shell command or binary.
1688
+ */
1689
+ async run(command, options = {}) {
1690
+ const { resolve = false, capture = false, root, env } = options;
1691
+ const cwd = root ?? process.cwd();
1692
+ this.log.debug(`Shell: ${command}`, {
1693
+ cwd,
1694
+ resolve,
1695
+ capture
1696
+ });
1697
+ let executable;
1698
+ let args;
1699
+ if (resolve) {
1700
+ const [bin, ...rest] = command.split(" ");
1701
+ executable = await this.resolveExecutable(bin, cwd);
1702
+ args = rest;
1703
+ } else [executable, ...args] = command.split(" ");
1704
+ if (capture) return this.execCapture(command, {
1705
+ cwd,
1706
+ env
1707
+ });
1708
+ return this.execInherit(executable, args, {
1709
+ cwd,
1710
+ env
1711
+ });
1712
+ }
1713
+ /**
1714
+ * Execute command with inherited stdio (streams to terminal).
1715
+ */
1716
+ async execInherit(executable, args, options) {
1717
+ const proc = spawn(executable, args, {
1718
+ stdio: "inherit",
1719
+ cwd: options.cwd,
1720
+ env: {
1721
+ ...process.env,
1722
+ ...options.env
1723
+ }
1724
+ });
1725
+ return new Promise((resolve, reject) => {
1726
+ proc.on("exit", (code) => {
1727
+ if (code === 0 || code === null) resolve("");
1728
+ else reject(new AlephaError(`Command exited with code ${code}`));
1729
+ });
1730
+ proc.on("error", reject);
1731
+ });
1732
+ }
1733
+ /**
1734
+ * Execute command and capture stdout.
1735
+ */
1736
+ execCapture(command, options) {
1737
+ return new Promise((resolve, reject) => {
1738
+ exec(command, {
1739
+ cwd: options.cwd,
1740
+ env: {
1741
+ ...process.env,
1742
+ LOG_FORMAT: "pretty",
1743
+ ...options.env
1744
+ }
1745
+ }, (err, stdout) => {
1746
+ if (err) {
1747
+ err.stdout = stdout;
1748
+ reject(err);
1749
+ } else resolve(stdout);
1750
+ });
1751
+ });
1752
+ }
1753
+ /**
1754
+ * Resolve executable path from node_modules/.bin.
1755
+ *
1756
+ * Search order:
1757
+ * 1. Local: node_modules/.bin/
1758
+ * 2. Pnpm nested: node_modules/alepha/node_modules/.bin/
1759
+ * 3. Monorepo: Walk up to 3 parent directories
1760
+ */
1761
+ async resolveExecutable(name, root) {
1762
+ const suffix = process.platform === "win32" ? ".cmd" : "";
1763
+ let execPath = await this.findExecutable(root, `node_modules/.bin/${name}${suffix}`);
1764
+ if (!execPath) execPath = await this.findExecutable(root, `node_modules/alepha/node_modules/.bin/${name}${suffix}`);
1765
+ if (!execPath) {
1766
+ let parentDir = this.fs.join(root, "..");
1767
+ for (let i = 0; i < 3; i++) {
1768
+ execPath = await this.findExecutable(parentDir, `node_modules/.bin/${name}${suffix}`);
1769
+ if (execPath) break;
1770
+ parentDir = this.fs.join(parentDir, "..");
1771
+ }
1772
+ }
1773
+ if (!execPath) throw new AlephaError(`Could not find executable for '${name}'. Make sure the package is installed.`);
1774
+ return execPath;
1775
+ }
1776
+ /**
1777
+ * Check if executable exists at path.
1778
+ */
1779
+ async findExecutable(root, relativePath) {
1780
+ const fullPath = this.fs.join(root, relativePath);
1781
+ if (await this.fs.exists(fullPath)) return fullPath;
1782
+ }
1783
+ /**
1784
+ * Check if a command is installed and available in the system PATH.
1785
+ */
1786
+ isInstalled(command) {
1787
+ return new Promise((resolve) => {
1788
+ exec(process.platform === "win32" ? `where ${command}` : `command -v ${command}`, (error) => resolve(!error));
1789
+ });
1790
+ }
1791
+ };
1792
+
1793
+ //#endregion
1794
+ //#region ../../src/system/providers/ShellProvider.ts
1795
+ /**
1796
+ * Abstract provider for executing shell commands and binaries.
1797
+ *
1798
+ * Implementations:
1799
+ * - `NodeShellProvider` - Real shell execution using Node.js child_process
1800
+ * - `MemoryShellProvider` - In-memory mock for testing
1801
+ *
1802
+ * @example
1803
+ * ```typescript
1804
+ * class MyService {
1805
+ * protected readonly shell = $inject(ShellProvider);
1806
+ *
1807
+ * async build() {
1808
+ * // Run shell command directly
1809
+ * await this.shell.run("yarn install");
1810
+ *
1811
+ * // Run local binary with resolution
1812
+ * await this.shell.run("vite build", { resolve: true });
1813
+ *
1814
+ * // Capture output
1815
+ * const output = await this.shell.run("echo hello", { capture: true });
1816
+ * }
1817
+ * }
1818
+ * ```
1819
+ */
1820
+ var ShellProvider = class {};
1821
+
1822
+ //#endregion
1823
+ //#region ../../src/system/index.ts
1824
+ /**
1825
+ * | type | quality | stability |
1826
+ * |------|---------|-----------|
1827
+ * | tooling | standard | stable |
1828
+ *
1829
+ * System-level abstractions for portable code across runtimes.
1830
+ *
1831
+ * **Features:**
1832
+ * - File system operations (read, write, exists, etc.)
1833
+ * - Shell command execution
1834
+ * - File type detection and MIME utilities
1835
+ * - Memory implementations for testing
1836
+ *
1837
+ * @module alepha.system
1838
+ */
1839
+ const AlephaSystem = $module({
1840
+ name: "alepha.system",
1841
+ primitives: [],
1842
+ services: [
1843
+ FileDetector,
1844
+ FileSystemProvider,
1845
+ MemoryFileSystemProvider,
1846
+ NodeFileSystemProvider,
1847
+ ShellProvider,
1848
+ MemoryShellProvider,
1849
+ NodeShellProvider
1850
+ ],
1851
+ register: (alepha) => alepha.with({
1852
+ optional: true,
1853
+ provide: FileSystemProvider,
1854
+ use: NodeFileSystemProvider
1855
+ }).with({
1856
+ optional: true,
1857
+ provide: ShellProvider,
1858
+ use: alepha.isTest() ? MemoryShellProvider : NodeShellProvider
1859
+ })
1860
+ });
1861
+
20
1862
  //#endregion
21
1863
  //#region ../../src/server/static/providers/ServerStaticProvider.ts
22
1864
  var ServerStaticProvider = class {
@@ -171,9 +2013,15 @@ var ServerStaticProvider = class {
171
2013
  //#endregion
172
2014
  //#region ../../src/server/static/index.ts
173
2015
  /**
174
- * Create static file server with `$static()`.
2016
+ * | type | quality | stability |
2017
+ * |------|---------|-----------|
2018
+ * | backend | standard | stable |
2019
+ *
2020
+ * Static file serving.
2021
+ *
2022
+ * **Features:**
2023
+ * - Serve static files from directory
175
2024
  *
176
- * @see {@link ServerStaticProvider}
177
2025
  * @module alepha.server.static
178
2026
  */
179
2027
  const AlephaServerStatic = $module({