@wener/common 2.0.2 → 2.0.5

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 (410) hide show
  1. package/lib/ai/qwen3vl/index.js +2 -0
  2. package/lib/ai/qwen3vl/index.js.map +1 -0
  3. package/lib/ai/qwen3vl/utils.js +31 -0
  4. package/lib/ai/qwen3vl/utils.js.map +1 -0
  5. package/lib/ai/vision/DocLayoutElementTypeSchema.js +28 -0
  6. package/lib/ai/vision/DocLayoutElementTypeSchema.js.map +1 -0
  7. package/lib/ai/vision/ImageAnnotationSchema.js +50 -0
  8. package/lib/ai/vision/ImageAnnotationSchema.js.map +1 -0
  9. package/lib/ai/vision/index.js +3 -0
  10. package/lib/ai/vision/index.js.map +1 -0
  11. package/lib/ai/vision/resolveImageAnnotation.js +105 -0
  12. package/lib/ai/vision/resolveImageAnnotation.js.map +1 -0
  13. package/lib/cn/ChineseResidentIdNo.js +22 -15
  14. package/lib/cn/ChineseResidentIdNo.js.map +1 -0
  15. package/lib/cn/ChineseResidentIdNo.test.js +1 -1
  16. package/lib/cn/DivisionCode.js +30 -25
  17. package/lib/cn/DivisionCode.js.map +1 -0
  18. package/lib/cn/DivisionCode.test.js +1 -1
  19. package/lib/cn/Mod11.js +38 -81
  20. package/lib/cn/Mod11.js.map +1 -0
  21. package/lib/cn/Mod31.js +41 -90
  22. package/lib/cn/Mod31.js.map +1 -0
  23. package/lib/cn/UnifiedSocialCreditCode.js +43 -34
  24. package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
  25. package/lib/cn/UnifiedSocialCreditCode.test.js +1 -1
  26. package/lib/cn/formatChineseAmount.js +77 -0
  27. package/lib/cn/formatChineseAmount.js.map +1 -0
  28. package/lib/cn/index.js +7 -1
  29. package/lib/cn/index.js.map +1 -0
  30. package/lib/cn/parseChineseNumber.js +94 -0
  31. package/lib/cn/parseChineseNumber.js.map +1 -0
  32. package/lib/cn/parseChineseNumber.test.js +278 -0
  33. package/lib/cn/pinyin/cartesianProduct.js +22 -0
  34. package/lib/cn/pinyin/cartesianProduct.js.map +1 -0
  35. package/lib/cn/pinyin/cartesianProduct.test.js +179 -0
  36. package/lib/cn/pinyin/data.json +23573 -0
  37. package/lib/cn/pinyin/loader.js +14 -0
  38. package/lib/cn/pinyin/loader.js.map +1 -0
  39. package/lib/cn/pinyin/preload.js +3 -0
  40. package/lib/cn/pinyin/preload.js.map +1 -0
  41. package/lib/cn/pinyin/toPinyin.test.js +167 -0
  42. package/lib/cn/pinyin/toPinyinPure.js +33 -0
  43. package/lib/cn/pinyin/toPinyinPure.js.map +1 -0
  44. package/lib/cn/pinyin/transform.js +14 -0
  45. package/lib/cn/pinyin/transform.js.map +1 -0
  46. package/lib/cn/types.d.js +2 -0
  47. package/lib/cn/types.d.js.map +1 -0
  48. package/lib/consola/createStandardConsolaReporter.js +6 -6
  49. package/lib/consola/createStandardConsolaReporter.js.map +1 -0
  50. package/lib/consola/formatLogObject.js +66 -146
  51. package/lib/consola/formatLogObject.js.map +1 -0
  52. package/lib/consola/formatLogObject.test.js +184 -0
  53. package/lib/consola/index.js +1 -0
  54. package/lib/consola/index.js.map +1 -0
  55. package/lib/data/formatSort.js +6 -5
  56. package/lib/data/formatSort.js.map +1 -0
  57. package/lib/data/index.js +1 -0
  58. package/lib/data/index.js.map +1 -0
  59. package/lib/data/maybeNumber.js +6 -8
  60. package/lib/data/maybeNumber.js.map +1 -0
  61. package/lib/data/parseSort.js +22 -28
  62. package/lib/data/parseSort.js.map +1 -0
  63. package/lib/data/resolvePagination.js +13 -17
  64. package/lib/data/resolvePagination.js.map +1 -0
  65. package/lib/data/types.d.js +2 -0
  66. package/lib/data/types.d.js.map +1 -0
  67. package/lib/dayjs/dayjs.js +21 -19
  68. package/lib/dayjs/dayjs.js.map +1 -0
  69. package/lib/dayjs/formatDuration.js +15 -14
  70. package/lib/dayjs/formatDuration.js.map +1 -0
  71. package/lib/dayjs/index.js +2 -0
  72. package/lib/dayjs/index.js.map +1 -0
  73. package/lib/dayjs/parseDuration.js +5 -8
  74. package/lib/dayjs/parseDuration.js.map +1 -0
  75. package/lib/dayjs/parseRelativeTime.js +90 -0
  76. package/lib/dayjs/parseRelativeTime.js.map +1 -0
  77. package/lib/dayjs/parseRelativeTime.test.js +247 -0
  78. package/lib/dayjs/resolveRelativeTime.js +87 -0
  79. package/lib/dayjs/resolveRelativeTime.js.map +1 -0
  80. package/lib/dayjs/resolveRelativeTime.test.js +310 -0
  81. package/lib/decimal/index.js +1 -0
  82. package/lib/decimal/index.js.map +1 -0
  83. package/lib/decimal/parseDecimal.js +3 -1
  84. package/lib/decimal/parseDecimal.js.map +1 -0
  85. package/lib/drain3/Drain.js +356 -0
  86. package/lib/drain3/Drain.js.map +1 -0
  87. package/lib/drain3/LogCluster.js +38 -0
  88. package/lib/drain3/LogCluster.js.map +1 -0
  89. package/lib/drain3/Node.js +39 -0
  90. package/lib/drain3/Node.js.map +1 -0
  91. package/lib/drain3/TemplateMiner.js +204 -0
  92. package/lib/drain3/TemplateMiner.js.map +1 -0
  93. package/lib/drain3/index.js +31 -0
  94. package/lib/drain3/index.js.map +1 -0
  95. package/lib/drain3/persistence/FilePersistence.js +24 -0
  96. package/lib/drain3/persistence/FilePersistence.js.map +1 -0
  97. package/lib/drain3/persistence/MemoryPersistence.js +18 -0
  98. package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
  99. package/lib/drain3/persistence/PersistenceHandler.js +5 -0
  100. package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
  101. package/lib/drain3/types.js +7 -0
  102. package/lib/drain3/types.js.map +1 -0
  103. package/lib/emittery/emitter.js +10 -0
  104. package/lib/emittery/emitter.js.map +1 -0
  105. package/lib/emittery/index.js +2 -0
  106. package/lib/emittery/index.js.map +1 -0
  107. package/lib/foundation/schema/SexType.js +5 -3
  108. package/lib/foundation/schema/SexType.js.map +1 -0
  109. package/lib/foundation/schema/index.js +1 -0
  110. package/lib/foundation/schema/index.js.map +1 -0
  111. package/lib/foundation/schema/parseSexType.js +1 -0
  112. package/lib/foundation/schema/parseSexType.js.map +1 -0
  113. package/lib/foundation/schema/types.js +4 -2
  114. package/lib/foundation/schema/types.js.map +1 -0
  115. package/lib/fs/FileSystemError.js +23 -0
  116. package/lib/fs/FileSystemError.js.map +1 -0
  117. package/lib/fs/IFileSystem.d.js +3 -0
  118. package/lib/fs/IFileSystem.d.js.map +1 -0
  119. package/lib/fs/MemoryFileSystem.test.js +188 -0
  120. package/lib/fs/createBrowserFileSystem.js +250 -0
  121. package/lib/fs/createBrowserFileSystem.js.map +1 -0
  122. package/lib/fs/createMemoryFileSystem.js +517 -0
  123. package/lib/fs/createMemoryFileSystem.js.map +1 -0
  124. package/lib/fs/createSandboxFileSystem.js +108 -0
  125. package/lib/fs/createSandboxFileSystem.js.map +1 -0
  126. package/lib/fs/createWebDavFileSystem.js +154 -0
  127. package/lib/fs/createWebDavFileSystem.js.map +1 -0
  128. package/lib/fs/createWebFileSystem.js +225 -0
  129. package/lib/fs/createWebFileSystem.js.map +1 -0
  130. package/lib/fs/findMimeType.js +17 -0
  131. package/lib/fs/findMimeType.js.map +1 -0
  132. package/lib/fs/index.js +8 -0
  133. package/lib/fs/index.js.map +1 -0
  134. package/lib/fs/minio/createMinioFileSystem.js +974 -0
  135. package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
  136. package/lib/fs/minio/index.js +2 -0
  137. package/lib/fs/minio/index.js.map +1 -0
  138. package/lib/fs/orpc/FileSystemContract.js +93 -0
  139. package/lib/fs/orpc/FileSystemContract.js.map +1 -0
  140. package/lib/fs/orpc/createContractClientFileSystem.js +93 -0
  141. package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -0
  142. package/lib/fs/orpc/index.js +3 -0
  143. package/lib/fs/orpc/index.js.map +1 -0
  144. package/lib/fs/orpc/server/createFileSystemContractImpl.js +63 -0
  145. package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -0
  146. package/lib/fs/orpc/server/index.js +2 -0
  147. package/lib/fs/orpc/server/index.js.map +1 -0
  148. package/lib/fs/s3/createS3MiniFileSystem.js +753 -0
  149. package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -0
  150. package/lib/fs/s3/index.js +2 -0
  151. package/lib/fs/s3/index.js.map +1 -0
  152. package/lib/fs/s3/s3mini.test.js +584 -0
  153. package/lib/fs/scandir.js +59 -0
  154. package/lib/fs/scandir.js.map +1 -0
  155. package/lib/fs/server/createDatabaseFileSystem.js +750 -0
  156. package/lib/fs/server/createDatabaseFileSystem.js.map +1 -0
  157. package/lib/fs/server/createNodeFileSystem.js +426 -0
  158. package/lib/fs/server/createNodeFileSystem.js.map +1 -0
  159. package/lib/fs/server/dbfs.test.js +221 -0
  160. package/lib/fs/server/index.js +2 -0
  161. package/lib/fs/server/index.js.map +1 -0
  162. package/lib/fs/server/loadTestDatabase.js +127 -0
  163. package/lib/fs/server/loadTestDatabase.js.map +1 -0
  164. package/lib/fs/tests/runFileSystemTest.js +319 -0
  165. package/lib/fs/tests/runFileSystemTest.js.map +1 -0
  166. package/lib/fs/types.js +27 -0
  167. package/lib/fs/types.js.map +1 -0
  168. package/lib/fs/utils/getFileUrl.js +35 -0
  169. package/lib/fs/utils/getFileUrl.js.map +1 -0
  170. package/lib/fs/utils.js +22 -0
  171. package/lib/fs/utils.js.map +1 -0
  172. package/lib/fs/webdav/index.js +2 -0
  173. package/lib/fs/webdav/index.js.map +1 -0
  174. package/lib/index.js +1 -0
  175. package/lib/index.js.map +1 -0
  176. package/lib/jsonschema/JsonSchema.js +146 -172
  177. package/lib/jsonschema/JsonSchema.js.map +1 -0
  178. package/lib/jsonschema/forEachJsonSchema.js +44 -0
  179. package/lib/jsonschema/forEachJsonSchema.js.map +1 -0
  180. package/lib/jsonschema/index.js +2 -0
  181. package/lib/jsonschema/index.js.map +1 -0
  182. package/lib/jsonschema/types.d.js +2 -0
  183. package/lib/jsonschema/types.d.js.map +1 -0
  184. package/lib/meta/defineFileType.js +20 -103
  185. package/lib/meta/defineFileType.js.map +1 -0
  186. package/lib/meta/defineInit.js +31 -250
  187. package/lib/meta/defineInit.js.map +1 -0
  188. package/lib/meta/defineMetadata.js +24 -140
  189. package/lib/meta/defineMetadata.js.map +1 -0
  190. package/lib/meta/index.js +1 -0
  191. package/lib/meta/index.js.map +1 -0
  192. package/lib/orpc/createOpenApiContractClient.js +27 -0
  193. package/lib/orpc/createOpenApiContractClient.js.map +1 -0
  194. package/lib/orpc/createRpcContractClient.js +34 -0
  195. package/lib/orpc/createRpcContractClient.js.map +1 -0
  196. package/lib/orpc/index.js +3 -0
  197. package/lib/orpc/index.js.map +1 -0
  198. package/lib/orpc/resolveLinkPlugins.js +28 -0
  199. package/lib/orpc/resolveLinkPlugins.js.map +1 -0
  200. package/lib/password/PHC.js +63 -87
  201. package/lib/password/PHC.js.map +1 -0
  202. package/lib/password/PHC.test.js +11 -3
  203. package/lib/password/Password.js +29 -294
  204. package/lib/password/Password.js.map +1 -0
  205. package/lib/password/Password.test.js +35 -22
  206. package/lib/password/createArgon2PasswordAlgorithm.js +35 -191
  207. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -0
  208. package/lib/password/createBase64PasswordAlgorithm.js +8 -141
  209. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -0
  210. package/lib/password/createBcryptPasswordAlgorithm.js +13 -168
  211. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -0
  212. package/lib/password/createPBKDF2PasswordAlgorithm.js +46 -228
  213. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -0
  214. package/lib/password/createScryptPasswordAlgorithm.js +55 -211
  215. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -0
  216. package/lib/password/index.js +1 -0
  217. package/lib/password/index.js.map +1 -0
  218. package/lib/password/server/index.js +1 -0
  219. package/lib/password/server/index.js.map +1 -0
  220. package/lib/resource/Identifiable.js +2 -0
  221. package/lib/resource/Identifiable.js.map +1 -0
  222. package/lib/resource/ListQuery.js +21 -93
  223. package/lib/resource/ListQuery.js.map +1 -0
  224. package/lib/resource/getTitleOfResource.js +3 -5
  225. package/lib/resource/getTitleOfResource.js.map +1 -0
  226. package/lib/resource/index.js +1 -0
  227. package/lib/resource/index.js.map +1 -0
  228. package/lib/resource/schema/AnyResourceSchema.js +2 -1
  229. package/lib/resource/schema/AnyResourceSchema.js.map +1 -0
  230. package/lib/resource/schema/BaseResourceSchema.js +2 -1
  231. package/lib/resource/schema/BaseResourceSchema.js.map +1 -0
  232. package/lib/resource/schema/ResourceActionType.js +6 -4
  233. package/lib/resource/schema/ResourceActionType.js.map +1 -0
  234. package/lib/resource/schema/ResourceStatus.js +5 -3
  235. package/lib/resource/schema/ResourceStatus.js.map +1 -0
  236. package/lib/resource/schema/ResourceType.js +5 -3
  237. package/lib/resource/schema/ResourceType.js.map +1 -0
  238. package/lib/resource/schema/index.js +1 -0
  239. package/lib/resource/schema/index.js.map +1 -0
  240. package/lib/resource/schema/types.js +16 -20
  241. package/lib/resource/schema/types.js.map +1 -0
  242. package/lib/s3/formatS3Url.js +65 -0
  243. package/lib/s3/formatS3Url.js.map +1 -0
  244. package/lib/s3/formatS3Url.test.js +262 -0
  245. package/lib/s3/index.js +3 -0
  246. package/lib/s3/index.js.map +1 -0
  247. package/lib/s3/parseS3Url.js +65 -0
  248. package/lib/s3/parseS3Url.js.map +1 -0
  249. package/lib/s3/parseS3Url.test.js +270 -0
  250. package/lib/schema/SchemaRegistry.js +38 -38
  251. package/lib/schema/SchemaRegistry.js.map +1 -0
  252. package/lib/schema/TypeSchema.d.js +2 -0
  253. package/lib/schema/TypeSchema.d.js.map +1 -0
  254. package/lib/schema/createSchemaData.js +26 -125
  255. package/lib/schema/createSchemaData.js.map +1 -0
  256. package/lib/schema/findJsonSchemaByPath.js +13 -36
  257. package/lib/schema/findJsonSchemaByPath.js.map +1 -0
  258. package/lib/schema/formatZodError.js +138 -0
  259. package/lib/schema/formatZodError.js.map +1 -0
  260. package/lib/schema/formatZodError.test.js +196 -0
  261. package/lib/schema/getSchemaCache.js +5 -5
  262. package/lib/schema/getSchemaCache.js.map +1 -0
  263. package/lib/schema/getSchemaOptions.js +8 -11
  264. package/lib/schema/getSchemaOptions.js.map +1 -0
  265. package/lib/schema/index.js +2 -1
  266. package/lib/schema/index.js.map +1 -0
  267. package/lib/schema/toJsonSchema.js +50 -293
  268. package/lib/schema/toJsonSchema.js.map +1 -0
  269. package/lib/schema/validate.js +34 -46
  270. package/lib/schema/validate.js.map +1 -0
  271. package/lib/tools/generateSchema.js +39 -197
  272. package/lib/tools/generateSchema.js.map +1 -0
  273. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +55 -143
  274. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -0
  275. package/lib/utils/buildBaseUrl.js +13 -0
  276. package/lib/utils/buildBaseUrl.js.map +1 -0
  277. package/lib/utils/buildRedactorFormSchema.js +59 -0
  278. package/lib/utils/buildRedactorFormSchema.js.map +1 -0
  279. package/lib/utils/getEstimateProcessTime.js +12 -11
  280. package/lib/utils/getEstimateProcessTime.js.map +1 -0
  281. package/lib/utils/index.js +3 -0
  282. package/lib/utils/index.js.map +1 -0
  283. package/lib/utils/resolveFeatureOptions.js +12 -0
  284. package/lib/utils/resolveFeatureOptions.js.map +1 -0
  285. package/package.json +80 -13
  286. package/src/ai/qwen3vl/index.ts +1 -0
  287. package/src/ai/qwen3vl/utils.ts +36 -0
  288. package/src/ai/vision/DocLayoutElementTypeSchema.ts +30 -0
  289. package/src/ai/vision/ImageAnnotationSchema.ts +60 -0
  290. package/src/ai/vision/index.ts +2 -0
  291. package/src/ai/vision/resolveImageAnnotation.ts +135 -0
  292. package/src/cn/ChineseResidentIdNo.test.ts +1 -1
  293. package/src/cn/ChineseResidentIdNo.ts +9 -1
  294. package/src/cn/DivisionCode.test.ts +1 -1
  295. package/src/cn/DivisionCode.ts +8 -0
  296. package/src/cn/Mod11.ts +1 -1
  297. package/src/cn/UnifiedSocialCreditCode.test.ts +1 -1
  298. package/src/cn/UnifiedSocialCreditCode.ts +15 -0
  299. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
  300. package/src/cn/formatChineseAmount.ts +61 -0
  301. package/src/cn/index.ts +7 -1
  302. package/src/cn/parseChineseNumber.test.ts +159 -0
  303. package/src/cn/parseChineseNumber.ts +97 -0
  304. package/src/cn/pinyin/cartesianProduct.test.ts +64 -0
  305. package/src/cn/pinyin/cartesianProduct.ts +24 -0
  306. package/src/cn/pinyin/data.json +23573 -0
  307. package/src/cn/pinyin/loader.ts +12 -0
  308. package/src/cn/pinyin/preload.ts +3 -0
  309. package/src/cn/pinyin/toPinyin.test.ts +12 -0
  310. package/src/cn/pinyin/toPinyinPure.ts +43 -0
  311. package/src/cn/pinyin/transform.ts +12 -0
  312. package/src/consola/formatLogObject.test.ts +27 -0
  313. package/src/consola/formatLogObject.ts +40 -12
  314. package/src/data/maybeNumber.ts +1 -1
  315. package/src/data/parseSort.test.ts +0 -1
  316. package/src/data/types.d.ts +2 -2
  317. package/src/dayjs/dayjs.ts +18 -18
  318. package/src/dayjs/formatDuration.ts +2 -2
  319. package/src/dayjs/index.ts +3 -1
  320. package/src/dayjs/parseRelativeTime.test.ts +185 -0
  321. package/src/dayjs/parseRelativeTime.ts +115 -0
  322. package/src/dayjs/resolveRelativeTime.test.ts +357 -0
  323. package/src/dayjs/resolveRelativeTime.ts +164 -0
  324. package/src/drain3/Drain.test.ts +378 -0
  325. package/src/drain3/Drain.ts +394 -0
  326. package/src/drain3/LogCluster.ts +46 -0
  327. package/src/drain3/Node.ts +53 -0
  328. package/src/drain3/TemplateMiner.ts +246 -0
  329. package/src/drain3/index.ts +36 -0
  330. package/src/drain3/persistence/FilePersistence.ts +24 -0
  331. package/src/drain3/persistence/MemoryPersistence.ts +23 -0
  332. package/src/drain3/persistence/PersistenceHandler.ts +19 -0
  333. package/src/drain3/types.ts +75 -0
  334. package/src/emittery/emitter.ts +9 -0
  335. package/src/emittery/index.ts +1 -0
  336. package/src/fs/FileSystemError.ts +26 -0
  337. package/src/fs/IFileSystem.d.ts +101 -0
  338. package/src/fs/MemoryFileSystem.test.ts +37 -0
  339. package/src/fs/createBrowserFileSystem.ts +293 -0
  340. package/src/fs/createMemoryFileSystem.ts +600 -0
  341. package/src/fs/createSandboxFileSystem.ts +136 -0
  342. package/src/fs/createWebDavFileSystem.ts +190 -0
  343. package/src/fs/createWebFileSystem.ts +242 -0
  344. package/src/fs/findMimeType.ts +20 -0
  345. package/src/fs/index.ts +8 -0
  346. package/src/fs/minio/createMinioFileSystem.ts +1148 -0
  347. package/src/fs/minio/index.ts +1 -0
  348. package/src/fs/orpc/FileSystemContract.ts +92 -0
  349. package/src/fs/orpc/createContractClientFileSystem.ts +115 -0
  350. package/src/fs/orpc/index.ts +2 -0
  351. package/src/fs/orpc/server/createFileSystemContractImpl.ts +64 -0
  352. package/src/fs/orpc/server/index.ts +1 -0
  353. package/src/fs/s3/createS3MiniFileSystem.ts +871 -0
  354. package/src/fs/s3/index.ts +1 -0
  355. package/src/fs/s3/s3fs.test.ts +441 -0
  356. package/src/fs/s3/s3mini.test.ts +264 -0
  357. package/src/fs/scandir.ts +75 -0
  358. package/src/fs/server/createDatabaseFileSystem.ts +668 -0
  359. package/src/fs/server/createNodeFileSystem.ts +518 -0
  360. package/src/fs/server/dbfs.test.ts +48 -0
  361. package/src/fs/server/index.ts +1 -0
  362. package/src/fs/server/loadTestDatabase.ts +131 -0
  363. package/src/fs/tests/runFileSystemTest.ts +289 -0
  364. package/src/fs/types.ts +29 -0
  365. package/src/fs/utils/getFileUrl.ts +44 -0
  366. package/src/fs/utils.ts +23 -0
  367. package/src/fs/webdav/index.ts +1 -0
  368. package/src/jsonschema/JsonSchema.ts +118 -110
  369. package/src/jsonschema/forEachJsonSchema.ts +50 -0
  370. package/src/jsonschema/index.ts +1 -0
  371. package/src/jsonschema/types.d.ts +1 -1
  372. package/src/meta/defineMetadata.ts +1 -1
  373. package/src/orpc/createOpenApiContractClient.ts +52 -0
  374. package/src/orpc/createRpcContractClient.ts +50 -0
  375. package/src/orpc/index.ts +2 -0
  376. package/src/orpc/resolveLinkPlugins.ts +29 -0
  377. package/src/password/PHC.ts +6 -6
  378. package/src/password/Password.test.ts +1 -1
  379. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  380. package/src/password/createBase64PasswordAlgorithm.ts +2 -2
  381. package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
  382. package/src/password/createPBKDF2PasswordAlgorithm.ts +4 -4
  383. package/src/password/createScryptPasswordAlgorithm.ts +4 -4
  384. package/src/resource/ListQuery.ts +4 -1
  385. package/src/resource/index.ts +2 -2
  386. package/src/resource/schema/AnyResourceSchema.ts +16 -2
  387. package/src/s3/formatS3Url.test.ts +254 -0
  388. package/src/s3/formatS3Url.ts +84 -0
  389. package/src/s3/index.ts +2 -0
  390. package/src/s3/parseS3Url.test.ts +258 -0
  391. package/src/s3/parseS3Url.ts +88 -0
  392. package/src/schema/SchemaRegistry.ts +35 -33
  393. package/src/schema/TypeSchema.d.ts +6 -6
  394. package/src/schema/createSchemaData.ts +4 -4
  395. package/src/schema/findJsonSchemaByPath.ts +4 -4
  396. package/src/schema/formatZodError.test.ts +197 -0
  397. package/src/schema/formatZodError.ts +139 -0
  398. package/src/schema/getSchemaOptions.ts +2 -2
  399. package/src/schema/index.ts +1 -1
  400. package/src/schema/toJsonSchema.ts +6 -6
  401. package/src/schema/validate.ts +1 -1
  402. package/src/utils/buildBaseUrl.ts +12 -0
  403. package/src/utils/buildRedactorFormSchema.ts +85 -0
  404. package/src/utils/index.ts +4 -0
  405. package/src/utils/resolveFeatureOptions.ts +14 -0
  406. package/src/cn/ChineseResidentIdNo.mod.ts +0 -7
  407. package/src/cn/DivisionCode.mod.ts +0 -7
  408. package/src/cn/UnifiedSocialCreditCode.mod.ts +0 -7
  409. package/src/cn/mod.ts +0 -3
  410. package/src/schema/SchemaRegistry.mod.ts +0 -1
@@ -0,0 +1,108 @@
1
+ import { join, normalize, relative, sep } from "pathe";
2
+ import { getPath } from "./utils";
3
+ let SandboxSecurityError = class SandboxSecurityError extends Error {
4
+ constructor(message){
5
+ super(message);
6
+ this.name = 'SandboxSecurityError';
7
+ }
8
+ };
9
+ export function createSandboxFileSystem(fs, basePath) {
10
+ return new SandboxFS(fs, basePath);
11
+ }
12
+ let SandboxFS = class SandboxFS {
13
+ fs;
14
+ basePath;
15
+ constructor(fs, basePath){
16
+ this.fs = fs;
17
+ this.basePath = normalize(basePath);
18
+ }
19
+ _resolvePath(userPath) {
20
+ const fullPath = join(this.basePath, userPath);
21
+ const normalizedFullPath = normalize(fullPath);
22
+ const rel = relative(this.basePath, normalizedFullPath);
23
+ if (rel.startsWith('..') || rel === '..') {
24
+ throw new SandboxSecurityError(`Path traversal attempt detected: ${userPath}`);
25
+ }
26
+ return normalizedFullPath;
27
+ }
28
+ _stripPath(fullPath) {
29
+ const relPath = relative(this.basePath, fullPath);
30
+ // 保证返回的是一个以 '/' 开头的绝对路径(在沙箱内)
31
+ return sep + relPath.split(sep).join('/');
32
+ }
33
+ _processStat(stat) {
34
+ stat.path = this._stripPath(stat.path);
35
+ stat.directory = this._stripPath(stat.directory);
36
+ return stat;
37
+ }
38
+ async stat(path, options) {
39
+ const fullPath = this._resolvePath(path);
40
+ const result = await this.fs.stat(fullPath, options);
41
+ return this._processStat(result);
42
+ }
43
+ async readdir(dir, options) {
44
+ const fullPath = this._resolvePath(dir);
45
+ const results = await this.fs.readdir(fullPath, options);
46
+ return results.map((stat)=>this._processStat(stat));
47
+ }
48
+ async exists(path) {
49
+ try {
50
+ const fullPath = this._resolvePath(path);
51
+ return await this.fs.exists(fullPath);
52
+ } catch (e) {
53
+ if (e instanceof SandboxSecurityError) {
54
+ return false; // 越界访问视为不存在
55
+ }
56
+ throw e;
57
+ }
58
+ }
59
+ mkdir(path, options) {
60
+ const fullPath = this._resolvePath(path);
61
+ return this.fs.mkdir(fullPath, options);
62
+ }
63
+ readFile(path, options) {
64
+ const fullPath = this._resolvePath(path);
65
+ return this.fs.readFile(fullPath, options);
66
+ }
67
+ writeFile(path, data, options) {
68
+ const fullPath = this._resolvePath(path);
69
+ return this.fs.writeFile(fullPath, data, options);
70
+ }
71
+ rm(path, options) {
72
+ const fullPath = this._resolvePath(path);
73
+ return this.fs.rm(fullPath, options);
74
+ }
75
+ rename(oldPath, newPath, options) {
76
+ const fullOldPath = this._resolvePath(oldPath);
77
+ const fullNewPath = this._resolvePath(newPath);
78
+ return this.fs.rename(fullOldPath, fullNewPath, options);
79
+ }
80
+ copy(src, dest, options) {
81
+ const fullSrc = this._resolvePath(src);
82
+ const fullDest = this._resolvePath(dest);
83
+ return this.fs.copy(fullSrc, fullDest, options);
84
+ }
85
+ createReadStream(path, options) {
86
+ const fullPath = this._resolvePath(path);
87
+ if (!this.fs.createReadStream) {
88
+ throw new Error('Underlying filesystem does not support createReadStream');
89
+ }
90
+ return this.fs.createReadStream(fullPath, options);
91
+ }
92
+ createWriteStream(path, options) {
93
+ const fullPath = this._resolvePath(path);
94
+ if (!this.fs.createWriteStream) {
95
+ throw new Error('Underlying filesystem does not support createWriteStream');
96
+ }
97
+ return this.fs.createWriteStream(fullPath, options);
98
+ }
99
+ getUrl(file, options) {
100
+ let path = this._resolvePath(getPath(file.path));
101
+ if (this.fs.getUrl) {
102
+ return this.fs.getUrl(path, options);
103
+ }
104
+ return;
105
+ }
106
+ };
107
+
108
+ //# sourceMappingURL=createSandboxFileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fs/createSandboxFileSystem.ts"],"sourcesContent":["import { join, normalize, relative, sep } from 'pathe';\nimport type { IFileStat, IServerFileSystem, ReadFileOptions } from './IFileSystem';\nimport { getPath } from './utils';\n\nclass SandboxSecurityError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'SandboxSecurityError';\n\t}\n}\n\nexport function createSandboxFileSystem(\n\tfs: IServerFileSystem,\n\tbasePath: string,\n): IServerFileSystem & {\n\tfs: IServerFileSystem;\n\tbasePath: string;\n} {\n\treturn new SandboxFS(fs, basePath);\n}\n\nclass SandboxFS implements IServerFileSystem {\n\tfs: IServerFileSystem;\n\tbasePath: string;\n\n\tconstructor(fs: IServerFileSystem, basePath: string) {\n\t\tthis.fs = fs;\n\t\tthis.basePath = normalize(basePath);\n\t}\n\n\tprivate _resolvePath(userPath: string): string {\n\t\tconst fullPath = join(this.basePath, userPath);\n\n\t\tconst normalizedFullPath = normalize(fullPath);\n\n\t\tconst rel = relative(this.basePath, normalizedFullPath);\n\t\tif (rel.startsWith('..') || rel === '..') {\n\t\t\tthrow new SandboxSecurityError(`Path traversal attempt detected: ${userPath}`);\n\t\t}\n\t\treturn normalizedFullPath;\n\t}\n\n\tprivate _stripPath(fullPath: string): string {\n\t\tconst relPath = relative(this.basePath, fullPath);\n\t\t// 保证返回的是一个以 '/' 开头的绝对路径(在沙箱内)\n\t\treturn sep + relPath.split(sep).join('/');\n\t}\n\n\tprivate _processStat(stat: IFileStat): IFileStat {\n\t\tstat.path = this._stripPath(stat.path);\n\t\tstat.directory = this._stripPath(stat.directory);\n\t\treturn stat;\n\t}\n\n\tasync stat(path: string, options?: any): Promise<IFileStat> {\n\t\tconst fullPath = this._resolvePath(path);\n\t\tconst result = await this.fs.stat(fullPath, options);\n\t\treturn this._processStat(result);\n\t}\n\n\tasync readdir(dir: string, options?: any): Promise<IFileStat[]> {\n\t\tconst fullPath = this._resolvePath(dir);\n\t\tconst results = await this.fs.readdir(fullPath, options);\n\t\treturn results.map((stat) => this._processStat(stat));\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\ttry {\n\t\t\tconst fullPath = this._resolvePath(path);\n\t\t\treturn await this.fs.exists(fullPath);\n\t\t} catch (e) {\n\t\t\tif (e instanceof SandboxSecurityError) {\n\t\t\t\treturn false; // 越界访问视为不存在\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tmkdir(path: string, options?: any): Promise<void> {\n\t\tconst fullPath = this._resolvePath(path);\n\t\treturn this.fs.mkdir(fullPath, options);\n\t}\n\n\treadFile(path: string, options?: ReadFileOptions & { encoding: 'text' }): Promise<string>;\n\treadFile(path: string, options?: ReadFileOptions): Promise<Uint8Array>;\n\treadFile(path: string, options?: ReadFileOptions): Promise<string | Uint8Array> {\n\t\tconst fullPath = this._resolvePath(path);\n\t\treturn this.fs.readFile(fullPath, options);\n\t}\n\n\twriteFile(path: string, data: any, options?: any): Promise<void> {\n\t\tconst fullPath = this._resolvePath(path);\n\t\treturn this.fs.writeFile(fullPath, data, options);\n\t}\n\n\trm(path: string, options?: any): Promise<void> {\n\t\tconst fullPath = this._resolvePath(path);\n\t\treturn this.fs.rm(fullPath, options);\n\t}\n\n\trename(oldPath: string, newPath: string, options?: any): Promise<void> {\n\t\tconst fullOldPath = this._resolvePath(oldPath);\n\t\tconst fullNewPath = this._resolvePath(newPath);\n\t\treturn this.fs.rename(fullOldPath, fullNewPath, options);\n\t}\n\n\tcopy(src: string, dest: string, options?: any): Promise<void> {\n\t\tconst fullSrc = this._resolvePath(src);\n\t\tconst fullDest = this._resolvePath(dest);\n\t\treturn this.fs.copy(fullSrc, fullDest, options);\n\t}\n\n\tcreateReadStream(path: string, options?: any): any {\n\t\tconst fullPath = this._resolvePath(path);\n\t\tif (!this.fs.createReadStream) {\n\t\t\tthrow new Error('Underlying filesystem does not support createReadStream');\n\t\t}\n\t\treturn this.fs.createReadStream(fullPath, options);\n\t}\n\n\tcreateWriteStream(path: string, options?: any): any {\n\t\tconst fullPath = this._resolvePath(path);\n\t\tif (!this.fs.createWriteStream) {\n\t\t\tthrow new Error('Underlying filesystem does not support createWriteStream');\n\t\t}\n\t\treturn this.fs.createWriteStream(fullPath, options);\n\t}\n\n\tgetUrl(file: IFileStat, options?: any): string | undefined {\n\t\tlet path = this._resolvePath(getPath(file.path));\n\t\tif (this.fs.getUrl) {\n\t\t\treturn this.fs.getUrl(path, options);\n\t\t}\n\t\treturn;\n\t}\n}\n"],"names":["join","normalize","relative","sep","getPath","SandboxSecurityError","Error","message","name","createSandboxFileSystem","fs","basePath","SandboxFS","_resolvePath","userPath","fullPath","normalizedFullPath","rel","startsWith","_stripPath","relPath","split","_processStat","stat","path","directory","options","result","readdir","dir","results","map","exists","e","mkdir","readFile","writeFile","data","rm","rename","oldPath","newPath","fullOldPath","fullNewPath","copy","src","dest","fullSrc","fullDest","createReadStream","createWriteStream","getUrl","file"],"mappings":"AAAA,SAASA,IAAI,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,GAAG,QAAQ,QAAQ;AAEvD,SAASC,OAAO,QAAQ,UAAU;AAElC,IAAA,AAAMC,uBAAN,MAAMA,6BAA6BC;IAClC,YAAYC,OAAe,CAAE;QAC5B,KAAK,CAACA;QACN,IAAI,CAACC,IAAI,GAAG;IACb;AACD;AAEA,OAAO,SAASC,wBACfC,EAAqB,EACrBC,QAAgB;IAKhB,OAAO,IAAIC,UAAUF,IAAIC;AAC1B;AAEA,IAAA,AAAMC,YAAN,MAAMA;IACLF,GAAsB;IACtBC,SAAiB;IAEjB,YAAYD,EAAqB,EAAEC,QAAgB,CAAE;QACpD,IAAI,CAACD,EAAE,GAAGA;QACV,IAAI,CAACC,QAAQ,GAAGV,UAAUU;IAC3B;IAEQE,aAAaC,QAAgB,EAAU;QAC9C,MAAMC,WAAWf,KAAK,IAAI,CAACW,QAAQ,EAAEG;QAErC,MAAME,qBAAqBf,UAAUc;QAErC,MAAME,MAAMf,SAAS,IAAI,CAACS,QAAQ,EAAEK;QACpC,IAAIC,IAAIC,UAAU,CAAC,SAASD,QAAQ,MAAM;YACzC,MAAM,IAAIZ,qBAAqB,CAAC,iCAAiC,EAAES,UAAU;QAC9E;QACA,OAAOE;IACR;IAEQG,WAAWJ,QAAgB,EAAU;QAC5C,MAAMK,UAAUlB,SAAS,IAAI,CAACS,QAAQ,EAAEI;QACxC,8BAA8B;QAC9B,OAAOZ,MAAMiB,QAAQC,KAAK,CAAClB,KAAKH,IAAI,CAAC;IACtC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E1B,OAAa,EAAsB;QAC1D,IAAIF,OAAO,IAAI,CAACX,YAAY,CAACT,QAAQgD,KAAK5B,IAAI;QAC9C,IAAI,IAAI,CAACd,EAAE,CAACyC,MAAM,EAAE;YACnB,OAAO,IAAI,CAACzC,EAAE,CAACyC,MAAM,CAAC3B,MAAME;QAC7B;QACA;IACD;AACD"}
@@ -0,0 +1,154 @@
1
+ import { maybeFunction } from "@wener/utils";
2
+ export function createWebDavFileSystem({ client }) {
3
+ let fs = new WebdavFS({
4
+ client
5
+ });
6
+ return fs;
7
+ }
8
+ let WebdavFS = class WebdavFS {
9
+ _client;
10
+ constructor({ client = ()=>{
11
+ throw new Error('WebdavFS client not initialized');
12
+ } }){
13
+ this._client = client;
14
+ }
15
+ set client(client) {
16
+ this._client = client;
17
+ }
18
+ get client() {
19
+ return maybeFunction(this._client);
20
+ }
21
+ toEntry(input) {
22
+ const { filename: path, basename, lastmod, type: kind, etag, size, mime } = input;
23
+ let meta = {};
24
+ if (etag) {
25
+ meta.etag = etag;
26
+ }
27
+ if (mime) {
28
+ meta.mime = mime;
29
+ }
30
+ return {
31
+ directory: path.substring(0, path.lastIndexOf('/')) || '/',
32
+ path,
33
+ name: basename,
34
+ mtime: +new Date(lastmod),
35
+ kind,
36
+ meta,
37
+ size
38
+ };
39
+ }
40
+ getData(input) {
41
+ if (input && typeof input === 'object' && 'data' in input && // 'headers' in input &&
42
+ 'status' in input && typeof input.status === 'number') {
43
+ return input.data;
44
+ }
45
+ return input;
46
+ }
47
+ async readdir(path, { glob, recursive, depth, kind, hidden, signal } = {}) {
48
+ // webdav depth 只支持 0,1
49
+ let o = {};
50
+ if (recursive) {
51
+ o.deep = true;
52
+ }
53
+ let res = await this.client.getDirectoryContents(path, {
54
+ deep: recursive,
55
+ signal
56
+ });
57
+ let out = this.getData(res);
58
+ if (!recursive && typeof depth === 'number' && depth >= 2) {
59
+ let l = depth;
60
+ let cur = out;
61
+ while(l-- > 1){
62
+ let sub = (await Promise.all(cur.map(async (v)=>{
63
+ if (v.type === 'directory') {
64
+ return this.getData(await this.client.getDirectoryContents(v.filename, {
65
+ signal
66
+ }));
67
+ }
68
+ return [];
69
+ }))).flat();
70
+ out = out.concat(...sub);
71
+ cur = sub;
72
+ }
73
+ }
74
+ if (glob) {
75
+ const { default: def, matcher = def.matcher } = await import("micromatch");
76
+ const match = matcher(glob);
77
+ out = out.filter((v)=>match(v.filename));
78
+ }
79
+ if (kind) {
80
+ out = out.filter((v)=>v.type === kind);
81
+ }
82
+ if (!hidden) {
83
+ out = out.filter((v)=>!v.basename.startsWith('.'));
84
+ }
85
+ return out.map((stat)=>this.toEntry(stat));
86
+ }
87
+ async stat(path, { signal } = {}) {
88
+ const res = await this.client.stat(path, {
89
+ details: true,
90
+ signal
91
+ });
92
+ return this.toEntry(this.getData(res));
93
+ }
94
+ async mkdir(path, { recursive, signal } = {}) {
95
+ await this.client.createDirectory(path, {
96
+ recursive,
97
+ signal
98
+ });
99
+ }
100
+ async readFile(path, options = {}) {
101
+ const format = options.encoding === 'text' ? 'text' : 'binary';
102
+ const res = await this.client.getFileContents(path, {
103
+ format,
104
+ ...options
105
+ });
106
+ return this.getData(res);
107
+ }
108
+ async writeFile(path, data, options = {}) {
109
+ // Convert web ReadableStream to something WebDAV client can handle
110
+ let webdavData = data;
111
+ if (data instanceof ReadableStream) {
112
+ // Convert web ReadableStream to Buffer
113
+ const reader = data.getReader();
114
+ const chunks = [];
115
+ while(true){
116
+ const { done, value } = await reader.read();
117
+ if (done) break;
118
+ if (value) chunks.push(value);
119
+ }
120
+ webdavData = Buffer.concat(chunks);
121
+ } else if (ArrayBuffer.isView(data) && !(data instanceof Buffer)) {
122
+ // Convert ArrayBufferView to Buffer
123
+ webdavData = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
124
+ }
125
+ await this.client.putFileContents(path, webdavData, options);
126
+ }
127
+ async rm(path, { signal: _signal, force, recursive: _recursive } = {}) {
128
+ try {
129
+ await this.client.deleteFile(path);
130
+ } catch (e) {
131
+ if (force && e.status === 404) {
132
+ return;
133
+ }
134
+ throw e;
135
+ }
136
+ }
137
+ async rename(oldPath, newPath, options = {}) {
138
+ await this.client.moveFile(oldPath, newPath, options);
139
+ }
140
+ async exists(path) {
141
+ return await this.client.exists(path);
142
+ }
143
+ async copy(src, dest, options = {}) {
144
+ await this.client.copyFile(src, dest, options);
145
+ }
146
+ createReadStream(path, options = {}) {
147
+ return this.client.createReadStream(path, options);
148
+ }
149
+ createWriteStream(path, options = {}) {
150
+ return this.client.createWriteStream(path, options);
151
+ }
152
+ };
153
+
154
+ //# sourceMappingURL=createWebDavFileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fs/createWebDavFileSystem.ts"],"sourcesContent":["import type { Readable, Writable } from 'node:stream';\nimport { maybeFunction, type MaybeFunction } from '@wener/utils';\nimport type { FileStat, GetDirectoryContentsOptions, ResponseDataDetailed, WebDAVClient } from 'webdav';\nimport type {\n\tIFileStat,\n\tIFileSystem,\n\tMkdirOptions,\n\tReaddirOptions,\n\tReadFileOptions,\n\tRmOptions,\n\tStatOptions,\n\tWritableData,\n\tWriteFileOptions,\n} from './IFileSystem';\n\nexport function createWebDavFileSystem({ client }: { client: MaybeFunction<WebDAVClient> }): IFileSystem {\n\tlet fs = new WebdavFS({ client });\n\treturn fs;\n}\n\nclass WebdavFS implements IFileSystem {\n\t_client: MaybeFunction<WebDAVClient>;\n\n\tconstructor({\n\t\tclient = () => {\n\t\t\tthrow new Error('WebdavFS client not initialized');\n\t\t},\n\t}: {\n\t\tclient?: MaybeFunction<WebDAVClient>;\n\t}) {\n\t\tthis._client = client;\n\t}\n\n\tset client(client: MaybeFunction<WebDAVClient>) {\n\t\tthis._client = client;\n\t}\n\n\tget client(): WebDAVClient {\n\t\treturn maybeFunction(this._client);\n\t}\n\n\tprivate toEntry(input: FileStat): IFileStat {\n\t\tconst { filename: path, basename, lastmod, type: kind, etag, size, mime } = input;\n\t\tlet meta: Record<string, any> = {};\n\t\tif (etag) {\n\t\t\tmeta.etag = etag;\n\t\t}\n\t\tif (mime) {\n\t\t\tmeta.mime = mime;\n\t\t}\n\t\treturn {\n\t\t\tdirectory: path.substring(0, path.lastIndexOf('/')) || '/',\n\t\t\tpath,\n\t\t\tname: basename,\n\t\t\tmtime: +new Date(lastmod),\n\t\t\tkind,\n\t\t\tmeta,\n\t\t\tsize,\n\t\t};\n\t}\n\n\tprivate getData<T>(input: ResponseDataDetailed<T> | T): T {\n\t\tif (\n\t\t\tinput &&\n\t\t\ttypeof input === 'object' &&\n\t\t\t'data' in input &&\n\t\t\t// 'headers' in input &&\n\t\t\t'status' in input &&\n\t\t\ttypeof input.status === 'number'\n\t\t) {\n\t\t\treturn input.data;\n\t\t}\n\t\treturn input as T;\n\t}\n\n\tasync readdir(\n\t\tpath: string,\n\t\t{ glob, recursive, depth, kind, hidden, signal }: ReaddirOptions = {},\n\t): Promise<IFileStat[]> {\n\t\t// webdav depth 只支持 0,1\n\t\tlet o: GetDirectoryContentsOptions = {};\n\t\tif (recursive) {\n\t\t\to.deep = true;\n\t\t}\n\t\tlet res = await this.client.getDirectoryContents(path, {\n\t\t\tdeep: recursive,\n\t\t\tsignal,\n\t\t});\n\n\t\tlet out: FileStat[] = this.getData(res);\n\n\t\tif (!recursive && typeof depth === 'number' && depth >= 2) {\n\t\t\tlet l = depth;\n\t\t\tlet cur = out;\n\t\t\twhile (l-- > 1) {\n\t\t\t\tlet sub = (\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tcur.map(async (v) => {\n\t\t\t\t\t\t\tif (v.type === 'directory') {\n\t\t\t\t\t\t\t\treturn this.getData(await this.client.getDirectoryContents(v.filename, { signal }));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn [];\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t).flat();\n\t\t\t\tout = out.concat(...sub);\n\t\t\t\tcur = sub;\n\t\t\t}\n\t\t}\n\n\t\tif (glob) {\n\t\t\tconst { default: def, matcher = def.matcher } = await import('micromatch');\n\t\t\tconst match = matcher(glob);\n\t\t\tout = out.filter((v) => match(v.filename));\n\t\t}\n\t\tif (kind) {\n\t\t\tout = out.filter((v) => v.type === kind);\n\t\t}\n\t\tif (!hidden) {\n\t\t\tout = out.filter((v) => !v.basename.startsWith('.'));\n\t\t}\n\t\treturn out.map((stat) => this.toEntry(stat));\n\t}\n\n\tasync stat(path: string, { signal }: StatOptions = {}): Promise<IFileStat> {\n\t\tconst res = await this.client.stat(path, { details: true, signal });\n\t\treturn this.toEntry(this.getData(res));\n\t}\n\n\tasync mkdir(path: string, { recursive, signal }: MkdirOptions = {}): Promise<void> {\n\t\tawait this.client.createDirectory(path, { recursive, signal });\n\t}\n\n\tasync readFile(path: string, options: ReadFileOptions = {}): Promise<any> {\n\t\tconst format = options.encoding === 'text' ? 'text' : 'binary';\n\t\tconst res = await this.client.getFileContents(path, { format, ...options });\n\t\treturn this.getData(res);\n\t}\n\n\tasync writeFile(path: string, data: WritableData, options: WriteFileOptions = {}): Promise<void> {\n\t\t// Convert web ReadableStream to something WebDAV client can handle\n\t\tlet webdavData: string | Buffer | ArrayBuffer | Readable = data as string | Buffer | ArrayBuffer | Readable;\n\t\tif (data instanceof ReadableStream) {\n\t\t\t// Convert web ReadableStream to Buffer\n\t\t\tconst reader = data.getReader();\n\t\t\tconst chunks: Uint8Array[] = [];\n\t\t\twhile (true) {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done) break;\n\t\t\t\tif (value) chunks.push(value);\n\t\t\t}\n\t\t\twebdavData = Buffer.concat(chunks);\n\t\t} else if (ArrayBuffer.isView(data) && !(data instanceof Buffer)) {\n\t\t\t// Convert ArrayBufferView to Buffer\n\t\t\twebdavData = Buffer.from(data.buffer, data.byteOffset, data.byteLength);\n\t\t}\n\t\tawait this.client.putFileContents(path, webdavData, options);\n\t}\n\n\tasync rm(path: string, { signal: _signal, force, recursive: _recursive }: RmOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tawait this.client.deleteFile(path);\n\t\t} catch (e: any) {\n\t\t\tif (force && e.status === 404) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tasync rename(oldPath: string, newPath: string, options = {}): Promise<void> {\n\t\tawait this.client.moveFile(oldPath, newPath, options);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\treturn await this.client.exists(path);\n\t}\n\n\tasync copy(src: string, dest: string, options = {}): Promise<void> {\n\t\tawait this.client.copyFile(src, dest, options);\n\t}\n\n\tcreateReadStream(path: string, options = {}): Readable {\n\t\treturn this.client.createReadStream(path, options);\n\t}\n\n\tcreateWriteStream(path: string, options = {}): Writable {\n\t\treturn this.client.createWriteStream(path, options);\n\t}\n}\n"],"names":["maybeFunction","createWebDavFileSystem","client","fs","WebdavFS","_client","Error","toEntry","input","filename","path","basename","lastmod","type","kind","etag","size","mime","meta","directory","substring","lastIndexOf","name","mtime","Date","getData","status","data","readdir","glob","recursive","depth","hidden","signal","o","deep","res","getDirectoryContents","out","l","cur","sub","Promise","all","map","v","flat","concat","default","def","matcher","match","filter","startsWith","stat","details","mkdir","createDirectory","readFile","options","format","encoding","getFileContents","writeFile","webdavData","ReadableStream","reader","getReader","chunks","done","value","read","push","Buffer","ArrayBuffer","isView","from","buffer","byteOffset","byteLength","putFileContents","rm","_signal","force","_recursive","deleteFile","e","rename","oldPath","newPath","moveFile","exists","copy","src","dest","copyFile","createReadStream","createWriteStream"],"mappings":"AACA,SAASA,aAAa,QAA4B,eAAe;AAcjE,OAAO,SAASC,uBAAuB,EAAEC,MAAM,EAA2C;IACzF,IAAIC,KAAK,IAAIC,SAAS;QAAEF;IAAO;IAC/B,OAAOC;AACR;AAEA,IAAA,AAAMC,WAAN,MAAMA;IACLC,QAAqC;IAErC,YAAY,EACXH,SAAS;QACR,MAAM,IAAII,MAAM;IACjB,CAAC,EAGD,CAAE;QACF,IAAI,CAACD,OAAO,GAAGH;IAChB;IAEA,IA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AACmF,UAAU,CAAC3E;QAC9B,EAAE,OAAO4E,GAAQ;YAChB,IAAIH,SAASG,EAAE5D,MAAM,KAAK,KAAK;gBAC9B;YACD;YACA,MAAM4D;QACP;IACD;IAEA,MAAMC,OAAOC,OAAe,EAAEC,OAAe,EAAE9B,UAAU,CAAC,CAAC,EAAiB;QAC3E,MAAM,IAAI,CAACzD,MAAM,CAACwF,QAAQ,CAACF,SAASC,SAAS9B;IAC9C;IAEA,MAAMgC,OAAOjF,IAAY,EAAoB;QAC5C,OAAO,MAAM,IAAI,CAACR,MAAM,CAACyF,MAAM,CAACjF;IACjC;IAEA,MAAMkF,KAAKC,GAAW,EAAEC,IAAY,EAAEnC,UAAU,CAAC,CAAC,EAAiB;QAClE,MAAM,IAAI,CAACzD,MAAM,CAAC6F,QAAQ,CAACF,KAAKC,MAAMnC;IACvC;IAEAqC,iBAAiBtF,IAAY,EAAEiD,UAAU,CAAC,CAAC,EAAY;QACtD,OAAO,IAAI,CAACzD,MAAM,CAAC8F,gBAAgB,CAACtF,MAAMiD;IAC3C;IAEAsC,kBAAkBvF,IAAY,EAAEiD,UAAU,CAAC,CAAC,EAAY;QACvD,OAAO,IAAI,CAACzD,MAAM,CAAC+F,iBAAiB,CAACvF,MAAMiD;IAC5C;AACD"}
@@ -0,0 +1,225 @@
1
+ import { basename, dirname, join, normalize } from "pathe";
2
+ import { FileSystemError } from "./FileSystemError.js";
3
+ export function createWebFileSystem(options) {
4
+ return new WebFileSystem(options);
5
+ }
6
+ let WebFileSystem = class WebFileSystem {
7
+ root;
8
+ constructor({ root }) {
9
+ this.root = root;
10
+ }
11
+ async _getHandle(path) {
12
+ const parts = normalize(path).split("/").filter(Boolean);
13
+ if (parts.length === 0)
14
+ return this.root;
15
+ let current = this.root;
16
+ for (let i = 0; i < parts.length; i++) {
17
+ const part = parts[i];
18
+ const isLast = i === parts.length - 1;
19
+ try {
20
+ // Try to get as directory first
21
+ current = await current.getDirectoryHandle(part);
22
+ }
23
+ catch (e) {
24
+ if (e.name === "TypeMismatchError" || e.name === "NotFoundError") {
25
+ if (isLast) {
26
+ // Might be a file
27
+ try {
28
+ return await current.getFileHandle(part);
29
+ }
30
+ catch (_e2) {
31
+ throw new FileSystemError(`File not found: ${path}`, "ENOENT");
32
+ }
33
+ }
34
+ }
35
+ if (e.name === "NotFoundError") {
36
+ throw new FileSystemError(`Path not found: ${path}`, "ENOENT");
37
+ }
38
+ throw e;
39
+ }
40
+ }
41
+ return current;
42
+ }
43
+ async _getParent(path) {
44
+ const normalized = normalize(path);
45
+ const parentPath = dirname(normalized);
46
+ const name = basename(normalized);
47
+ if (!name)
48
+ throw new FileSystemError("Invalid path", "EINVAL");
49
+ const parentHandle = await this._getHandle(parentPath);
50
+ if (parentHandle.kind !== "directory") {
51
+ throw new FileSystemError(`Parent is not a directory: ${parentPath}`, "ENOTDIR");
52
+ }
53
+ return {
54
+ parent: parentHandle,
55
+ name
56
+ };
57
+ }
58
+ async stat(path, options) {
59
+ if (options?.signal?.aborted)
60
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
61
+ const handle = await this._getHandle(path);
62
+ return this._handleToStat(handle, path);
63
+ }
64
+ async _handleToStat(handle, path) {
65
+ let size = 0;
66
+ let mtime = 0;
67
+ if (handle.kind === "file") {
68
+ const file = await handle.getFile();
69
+ size = file.size;
70
+ mtime = file.lastModified;
71
+ }
72
+ return {
73
+ path,
74
+ directory: dirname(path),
75
+ name: handle.name,
76
+ kind: handle.kind,
77
+ size,
78
+ mtime,
79
+ meta: {}
80
+ };
81
+ }
82
+ async exists(path) {
83
+ try {
84
+ await this._getHandle(path);
85
+ return true;
86
+ }
87
+ catch {
88
+ return false;
89
+ }
90
+ }
91
+ async readdir(path, options) {
92
+ if (options?.signal?.aborted)
93
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
94
+ const handle = await this._getHandle(path);
95
+ if (handle.kind !== "directory") {
96
+ throw new FileSystemError(`Not a directory: ${path}`, "ENOTDIR");
97
+ }
98
+ const entries = [];
99
+ // @ts-expect-error - FileSystemDirectoryHandle is async iterable in modern browsers
100
+ for await (const entry of handle.values()) {
101
+ entries.push(await this._handleToStat(entry, join(path, entry.name)));
102
+ }
103
+ return entries;
104
+ }
105
+ async mkdir(path, options) {
106
+ if (options?.signal?.aborted)
107
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
108
+ const normalized = normalize(path);
109
+ const parts = normalized.split("/").filter(Boolean);
110
+ let current = this.root;
111
+ if (options?.recursive) {
112
+ for (const part of parts) {
113
+ current = await current.getDirectoryHandle(part, {
114
+ create: true
115
+ });
116
+ }
117
+ }
118
+ else {
119
+ const parentPath = dirname(normalized);
120
+ const name = basename(normalized);
121
+ try {
122
+ const parent = await this._getHandle(parentPath);
123
+ if (parent.kind !== "directory")
124
+ throw new FileSystemError(`Parent not a directory: ${parentPath}`, "ENOTDIR");
125
+ await parent.getDirectoryHandle(name, {
126
+ create: true
127
+ });
128
+ }
129
+ catch (e) {
130
+ if (e.code === "ENOENT" || e.name === "NotFoundError") {
131
+ throw new FileSystemError(`Parent does not exist: ${parentPath}`, "ENOENT");
132
+ }
133
+ throw e;
134
+ }
135
+ }
136
+ }
137
+ async readFile(path, options) {
138
+ if (options?.signal?.aborted)
139
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
140
+ const handle = await this._getHandle(path);
141
+ if (handle.kind !== "file")
142
+ throw new FileSystemError(`Is a directory: ${path}`, "EISDIR");
143
+ const file = await handle.getFile();
144
+ if (options?.encoding === "text") {
145
+ return await file.text();
146
+ }
147
+ else {
148
+ const buffer = await file.arrayBuffer();
149
+ return new Uint8Array(buffer);
150
+ }
151
+ }
152
+ async writeFile(path, data, options) {
153
+ if (options?.signal?.aborted)
154
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
155
+ if (options?.overwrite === false) {
156
+ if (await this.exists(path)) {
157
+ throw new FileSystemError(`File already exists: ${path}`, "EEXIST");
158
+ }
159
+ }
160
+ const { parent, name } = await this._getParent(path);
161
+ const handle = await parent.getFileHandle(name, {
162
+ create: true
163
+ });
164
+ const writable = await handle.createWritable();
165
+ await writable.write(data);
166
+ await writable.close();
167
+ }
168
+ async rm(path, options) {
169
+ if (options?.signal?.aborted)
170
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
171
+ const { parent, name } = await this._getParent(path);
172
+ try {
173
+ await parent.removeEntry(name, {
174
+ recursive: options?.recursive
175
+ });
176
+ }
177
+ catch (e) {
178
+ if (e.name === "NotFoundError") {
179
+ if (!options?.force)
180
+ throw new FileSystemError(`File not found: ${path}`, "ENOENT");
181
+ }
182
+ else if (e.name === "InvalidModificationError") {
183
+ throw new FileSystemError(`Directory not empty: ${path}`, "ENOTEMPTY");
184
+ }
185
+ else {
186
+ throw e;
187
+ }
188
+ }
189
+ }
190
+ async rename(oldPath, newPath, options) {
191
+ if (options?.signal?.aborted)
192
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
193
+ // File System Access API doesn't support move/rename directly
194
+ // Fallback to copy + delete
195
+ await this.copy(oldPath, newPath, {
196
+ overwrite: options?.overwrite
197
+ });
198
+ await this.rm(oldPath, {
199
+ recursive: true
200
+ });
201
+ }
202
+ async copy(src, dest, options) {
203
+ if (options?.signal?.aborted)
204
+ throw new FileSystemError("Operation aborted", "ABORT_ERR");
205
+ const srcHandle = await this._getHandle(src);
206
+ if (srcHandle.kind === "file") {
207
+ const file = await srcHandle.getFile();
208
+ await this.writeFile(dest, await file.arrayBuffer(), {
209
+ overwrite: options?.overwrite
210
+ });
211
+ }
212
+ else {
213
+ // Directory copy
214
+ await this.mkdir(dest);
215
+ const entries = await this.readdir(src);
216
+ for (const entry of entries) {
217
+ await this.copy(entry.path, join(dest, entry.name), options);
218
+ }
219
+ }
220
+ }
221
+ getUrl(_file) {
222
+ return undefined;
223
+ }
224
+ };
225
+ //# sourceMappingURL=createWebFileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fs/createWebFileSystem.ts"],"sourcesContent":["import { basename, dirname, join, normalize } from 'pathe';\nimport { FileSystemError } from './FileSystemError';\nimport type {\n\tCopyOptions,\n\tIFileStat,\n\tIFileSystem,\n\tMkdirOptions,\n\tReadFileOptions,\n\tReaddirOptions,\n\tRenameOptions,\n\tRmOptions,\n\tStatOptions,\n\tWriteFileOptions,\n} from './IFileSystem';\n\nexport function createWebFileSystem(options: { root: FileSystemDirectoryHandle }): IFileSystem {\n\treturn new WebFileSystem(options);\n}\n\nclass WebFileSystem implements IFileSystem {\n\tprivate readonly root: FileSystemDirectoryHandle;\n\n\tconstructor({ root }: { root: FileSystemDirectoryHandle }) {\n\t\tthis.root = root;\n\t}\n\n\tprivate async _getHandle(path: string): Promise<FileSystemHandle> {\n\t\tconst parts = normalize(path).split('/').filter(Boolean);\n\t\tif (parts.length === 0) return this.root;\n\n\t\tlet current: FileSystemDirectoryHandle = this.root;\n\n\t\tfor (let i = 0; i < parts.length; i++) {\n\t\t\tconst part = parts[i];\n\t\t\tconst isLast = i === parts.length - 1;\n\n\t\t\ttry {\n\t\t\t\t// Try to get as directory first\n\t\t\t\tcurrent = await current.getDirectoryHandle(part);\n\t\t\t} catch (e: any) {\n\t\t\t\tif (e.name === 'TypeMismatchError' || e.name === 'NotFoundError') {\n\t\t\t\t\tif (isLast) {\n\t\t\t\t\t\t// Might be a file\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await current.getFileHandle(part);\n\t\t\t\t\t\t} catch (_e2) {\n\t\t\t\t\t\t\tthrow new FileSystemError(`File not found: ${path}`, 'ENOENT');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (e.name === 'NotFoundError') {\n\t\t\t\t\tthrow new FileSystemError(`Path not found: ${path}`, 'ENOENT');\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t\treturn current;\n\t}\n\n\tprivate async _getParent(path: string): Promise<{ parent: FileSystemDirectoryHandle; name: string }> {\n\t\tconst normalized = normalize(path);\n\t\tconst parentPath = dirname(normalized);\n\t\tconst name = basename(normalized);\n\n\t\tif (!name) throw new FileSystemError('Invalid path', 'EINVAL');\n\n\t\tconst parentHandle = await this._getHandle(parentPath);\n\t\tif (parentHandle.kind !== 'directory') {\n\t\t\tthrow new FileSystemError(`Parent is not a directory: ${parentPath}`, 'ENOTDIR');\n\t\t}\n\n\t\treturn { parent: parentHandle as FileSystemDirectoryHandle, name };\n\t}\n\n\tasync stat(path: string, options?: StatOptions): Promise<IFileStat> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tconst handle = await this._getHandle(path);\n\t\treturn this._handleToStat(handle, path);\n\t}\n\n\tprivate async _handleToStat(handle: FileSystemHandle, path: string): Promise<IFileStat> {\n\t\tlet size = 0;\n\t\tlet mtime = 0;\n\n\t\tif (handle.kind === 'file') {\n\t\t\tconst file = await (handle as FileSystemFileHandle).getFile();\n\t\t\tsize = file.size;\n\t\t\tmtime = file.lastModified;\n\t\t}\n\n\t\treturn {\n\t\t\tpath,\n\t\t\tdirectory: dirname(path),\n\t\t\tname: handle.name,\n\t\t\tkind: handle.kind,\n\t\t\tsize,\n\t\t\tmtime,\n\t\t\tmeta: {},\n\t\t};\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait this._getHandle(path);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync readdir(path: string, options?: ReaddirOptions): Promise<IFileStat[]> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tconst handle = await this._getHandle(path);\n\t\tif (handle.kind !== 'directory') {\n\t\t\tthrow new FileSystemError(`Not a directory: ${path}`, 'ENOTDIR');\n\t\t}\n\n\t\tconst entries: IFileStat[] = [];\n\t\t// @ts-expect-error - FileSystemDirectoryHandle is async iterable in modern browsers\n\t\tfor await (const entry of (handle as FileSystemDirectoryHandle).values()) {\n\t\t\tentries.push(await this._handleToStat(entry, join(path, entry.name)));\n\t\t}\n\t\treturn entries;\n\t}\n\n\tasync mkdir(path: string, options?: MkdirOptions): Promise<void> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tconst normalized = normalize(path);\n\t\tconst parts = normalized.split('/').filter(Boolean);\n\t\tlet current = this.root;\n\n\t\tif (options?.recursive) {\n\t\t\tfor (const part of parts) {\n\t\t\t\tcurrent = await current.getDirectoryHandle(part, { create: true });\n\t\t\t}\n\t\t} else {\n\t\t\tconst parentPath = dirname(normalized);\n\t\t\tconst name = basename(normalized);\n\t\t\ttry {\n\t\t\t\tconst parent = await this._getHandle(parentPath);\n\t\t\t\tif (parent.kind !== 'directory') throw new FileSystemError(`Parent not a directory: ${parentPath}`, 'ENOTDIR');\n\t\t\t\tawait (parent as FileSystemDirectoryHandle).getDirectoryHandle(name, { create: true });\n\t\t\t} catch (e: any) {\n\t\t\t\tif (e.code === 'ENOENT' || e.name === 'NotFoundError') {\n\t\t\t\t\tthrow new FileSystemError(`Parent does not exist: ${parentPath}`, 'ENOENT');\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\treadFile(path: string, options?: ReadFileOptions & { encoding: 'text' }): Promise<string>;\n\treadFile(path: string, options?: ReadFileOptions): Promise<Uint8Array>;\n\tasync readFile(path: string, options?: ReadFileOptions): Promise<string | Uint8Array> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tconst handle = await this._getHandle(path);\n\t\tif (handle.kind !== 'file') throw new FileSystemError(`Is a directory: ${path}`, 'EISDIR');\n\n\t\tconst file = await (handle as FileSystemFileHandle).getFile();\n\n\t\tif (options?.encoding === 'text') {\n\t\t\treturn await file.text();\n\t\t} else {\n\t\t\tconst buffer = await file.arrayBuffer();\n\t\t\treturn new Uint8Array(buffer);\n\t\t}\n\t}\n\n\tasync writeFile(\n\t\tpath: string,\n\t\tdata: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | ReadableStream,\n\t\toptions?: WriteFileOptions,\n\t): Promise<void> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tif (options?.overwrite === false) {\n\t\t\tif (await this.exists(path)) {\n\t\t\t\tthrow new FileSystemError(`File already exists: ${path}`, 'EEXIST');\n\t\t\t}\n\t\t}\n\n\t\tconst { parent, name } = await this._getParent(path);\n\t\tconst handle = await parent.getFileHandle(name, { create: true });\n\n\t\tconst writable = await (handle as any).createWritable();\n\t\tawait writable.write(data);\n\t\tawait writable.close();\n\t}\n\n\tasync rm(path: string, options?: RmOptions): Promise<void> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tconst { parent, name } = await this._getParent(path);\n\n\t\ttry {\n\t\t\tawait (parent as any).removeEntry(name, { recursive: options?.recursive });\n\t\t} catch (e: any) {\n\t\t\tif (e.name === 'NotFoundError') {\n\t\t\t\tif (!options?.force) throw new FileSystemError(`File not found: ${path}`, 'ENOENT');\n\t\t\t} else if (e.name === 'InvalidModificationError') {\n\t\t\t\tthrow new FileSystemError(`Directory not empty: ${path}`, 'ENOTEMPTY');\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync rename(oldPath: string, newPath: string, options?: RenameOptions): Promise<void> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\t// File System Access API doesn't support move/rename directly\n\t\t// Fallback to copy + delete\n\t\tawait this.copy(oldPath, newPath, { overwrite: options?.overwrite });\n\t\tawait this.rm(oldPath, { recursive: true });\n\t}\n\n\tasync copy(src: string, dest: string, options?: CopyOptions): Promise<void> {\n\t\tif (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');\n\n\t\tconst srcHandle = await this._getHandle(src);\n\n\t\tif (srcHandle.kind === 'file') {\n\t\t\tconst file = await (srcHandle as FileSystemFileHandle).getFile();\n\t\t\tawait this.writeFile(dest, await file.arrayBuffer(), { overwrite: options?.overwrite });\n\t\t} else {\n\t\t\t// Directory copy\n\t\t\tawait this.mkdir(dest);\n\t\t\tconst entries = await this.readdir(src);\n\t\t\tfor (const entry of entries) {\n\t\t\t\tawait this.copy(entry.path, join(dest, entry.name), options);\n\t\t\t}\n\t\t}\n\t}\n\n\tgetUrl(_file: IFileStat | string): string | undefined {\n\t\treturn undefined;\n\t}\n}\n"],"names":["basename","dirname","join","normalize","FileSystemError","createWebFileSystem","options","WebFileSystem","root","_getHandle","path","parts","split","filter","Boolean","length","current","i","part","isLast","getDirectoryHandle","e","name","getFileHandle","_e2","_getParent","normalized","parentPath","parentHandle","kind","parent","stat","signal","aborted","handle","_handleToStat","size","mtime","file","getFile","lastModified","directory","meta","exists","readdir","entries","entry","values","push","mkdir","recursive","create","code","readFile","encoding","text","buffer","arrayBuffer","Uint8Array","writeFile","data","overwrite","writable","createWritable","write","close","rm","removeEntry","force","rename","oldPath","newPath","copy","src","dest","srcHandle","getUrl","_file","undefined"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,IAAI,EAAEC,SAAS,QAAQ,QAAQ;AAC3D,SAASC,eAAe,QAAQ,oBAAoB;AAcpD,OAAO,SAASC,oBAAoBC,OAA4C;IAC/E,OAAO,IAAIC,cAAcD;AAC1B;AAEA,IAAA,AAAMC,gBAAN,MAAMA;IACYC,KAAgC;IAEjD,YAAY,EAAEA,IAAI,EAAuC,CAAE;QAC1D,IAAI,CAACA,IAAI,GAAGA;IACb;IAEA,MAAcC,WAAWC,IAAY,EAA6B;QACjE,MAAMC,QAAQR,UAAUO,MAAME,KAAK,CAAC,KAAKC,MAAM,CAACC;QAChD,IAAIH,MAAMI,MAAM,KAAK,GAAG,OAAO,IAAI,CAACP,IAAI;QAExC,IAAIQ,UAAqC,IAAI,CAACR,IAAI;QAElD,IAAK,IAAIS,IAAI,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BAAqB;QAE7E,8DAA8D;QAC9D,4BAA4B;QAC5B,MAAM,IAAI,CAACoE,IAAI,CAACF,SAASC,SAAS;YAAEV,WAAWvD,SAASuD;QAAU;QAClE,MAAM,IAAI,CAACK,EAAE,CAACI,SAAS;YAAEpB,WAAW;QAAK;IAC1C;IAEA,MAAMsB,KAAKC,GAAW,EAAEC,IAAY,EAAEpE,OAAqB,EAAiB;QAC3E,IAAIA,SAAS0B,QAAQC,SAAS,MAAM,IAAI7B,gBAAgB,qBAAqB;QAE7E,MAAMuE,YAAY,MAAM,IAAI,CAAClE,UAAU,CAACgE;QAExC,IAAIE,UAAU9C,IAAI,KAAK,QAAQ;YAC9B,MAAMS,OAAO,MAAM,AAACqC,UAAmCpC,OAAO;YAC9D,MAAM,IAAI,CAACoB,SAAS,CAACe,MAAM,MAAMpC,KAAKmB,WAAW,IAAI;gBAAEI,WAAWvD,SAASuD;YAAU;QACtF,OAAO;YACN,iBAAiB;YACjB,MAAM,IAAI,CAACZ,KAAK,CAACyB;YACjB,MAAM7B,UAAU,MAAM,IAAI,CAACD,OAAO,CAAC6B;YACnC,KAAK,MAAM3B,SAASD,QAAS;gBAC5B,MAAM,IAAI,CAAC2B,IAAI,CAAC1B,MAAMpC,IAAI,EAAER,KAAKwE,MAAM5B,MAAMxB,IAAI,GAAGhB;YACrD;QACD;IACD;IAEAsE,OAAOC,KAAyB,EAAsB;QACrD,OAAOC;IACR;AACD"}
@@ -0,0 +1,17 @@
1
+ import { types } from "mime-types";
2
+ import pathe from "pathe";
3
+ export function findMimeType(path) {
4
+ // fix extname error
5
+ // https://github.com/jshttp/mime-types/issues/111
6
+ if (!path || typeof path !== 'string') {
7
+ return false;
8
+ }
9
+ // get the extension ("ext" or ".ext" or full path)
10
+ const extension = pathe.extname(`x.${path}`).toLowerCase().slice(1);
11
+ if (!extension) {
12
+ return false;
13
+ }
14
+ return types[extension] || false;
15
+ }
16
+
17
+ //# sourceMappingURL=findMimeType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fs/findMimeType.ts"],"sourcesContent":["import { types } from 'mime-types';\nimport pathe from 'pathe';\n\nexport function findMimeType(path: string | undefined | null) {\n\t// fix extname error\n\t// https://github.com/jshttp/mime-types/issues/111\n\n\tif (!path || typeof path !== 'string') {\n\t\treturn false;\n\t}\n\n\t// get the extension (\"ext\" or \".ext\" or full path)\n\tconst extension = pathe.extname(`x.${path}`).toLowerCase().slice(1);\n\n\tif (!extension) {\n\t\treturn false;\n\t}\n\n\treturn types[extension] || false;\n}\n"],"names":["types","pathe","findMimeType","path","extension","extname","toLowerCase","slice"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAa;AACnC,OAAOC,WAAW,QAAQ;AAE1B,OAAO,SAASC,aAAaC,IAA+B;IAC3D,oBAAoB;IACpB,kDAAkD;IAElD,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;QACtC,OAAO;IACR;IAEA,mDAAmD;IACnD,MAAMC,YAAYH,MAAMI,OAAO,CAAC,CAAC,EAAE,EAAEF,MAAM,EAAEG,WAAW,GAAGC,KAAK,CAAC;IAEjE,IAAI,CAACH,WAAW;QACf,OAAO;IACR;IAEA,OAAOJ,KAAK,CAACI,UAAU,IAAI;AAC5B"}
@@ -0,0 +1,8 @@
1
+ export { createSandboxFileSystem } from "./createSandboxFileSystem.js";
2
+ export { createMemoryFileSystem } from "./createMemoryFileSystem.js";
3
+ export { createBrowserFileSystem } from "./createBrowserFileSystem.js";
4
+ export { createWebFileSystem } from "./createWebFileSystem.js";
5
+ export { findMimeType } from "./findMimeType.js";
6
+ export { FileUrlOptionsSchema } from "./types.js";
7
+ export { FileSystemError, FileSystemErrorCode } from "./FileSystemError.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fs/index.ts"],"sourcesContent":["export type * from './IFileSystem';\nexport { createSandboxFileSystem } from './createSandboxFileSystem';\nexport { createMemoryFileSystem } from './createMemoryFileSystem';\nexport { createBrowserFileSystem } from './createBrowserFileSystem';\nexport { createWebFileSystem } from './createWebFileSystem';\nexport { findMimeType } from './findMimeType';\nexport { type FileUrlOptions, FileUrlOptionsSchema } from './types';\nexport { FileSystemError, FileSystemErrorCode } from './FileSystemError';\n"],"names":["createSandboxFileSystem","createMemoryFileSystem","createBrowserFileSystem","createWebFileSystem","findMimeType","FileUrlOptionsSchema","FileSystemError","FileSystemErrorCode"],"mappings":"AACA,SAASA,uBAAuB,QAAQ,4BAA4B;AACpE,SAASC,sBAAsB,QAAQ,2BAA2B;AAClE,SAASC,uBAAuB,QAAQ,4BAA4B;AACpE,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAA8BC,oBAAoB,QAAQ,UAAU;AACpE,SAASC,eAAe,EAAEC,mBAAmB,QAAQ,oBAAoB"}