@wener/common 2.0.3 → 2.0.6

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 (312) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/qwen3vl/utils.js.map +1 -1
  4. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  5. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  6. package/lib/ai/vision/index.js +2 -2
  7. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  8. package/lib/cn/ChineseResidentIdNo.js +55 -41
  9. package/lib/cn/ChineseResidentIdNo.js.map +1 -1
  10. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  11. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  12. package/lib/cn/DivisionCode.js +220 -235
  13. package/lib/cn/DivisionCode.mod.js +6 -1
  14. package/lib/cn/DivisionCode.test.js +92 -121
  15. package/lib/cn/Mod11.js +18 -37
  16. package/lib/cn/Mod11.js.map +1 -1
  17. package/lib/cn/Mod31.js +23 -41
  18. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  19. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  20. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  21. package/lib/cn/formatChineseAmount.js +46 -71
  22. package/lib/cn/index.js +6 -6
  23. package/lib/cn/mod.js +5 -3
  24. package/lib/cn/parseChineseNumber.js +81 -85
  25. package/lib/cn/parseChineseNumber.test.js +183 -261
  26. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  27. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  28. package/lib/cn/pinyin/loader.js +13 -11
  29. package/lib/cn/pinyin/preload.js +2 -1
  30. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  31. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  32. package/lib/cn/pinyin/transform.js +11 -11
  33. package/lib/cn/types.d.js +2 -2
  34. package/lib/consola/createStandardConsolaReporter.js +14 -15
  35. package/lib/consola/formatLogObject.js +149 -133
  36. package/lib/consola/formatLogObject.js.map +1 -1
  37. package/lib/consola/formatLogObject.test.js +167 -178
  38. package/lib/consola/index.js +2 -2
  39. package/lib/data/formatSort.js +14 -12
  40. package/lib/data/formatSort.test.js +33 -33
  41. package/lib/data/index.js +3 -3
  42. package/lib/data/maybeNumber.js +23 -23
  43. package/lib/data/maybeNumber.js.map +1 -1
  44. package/lib/data/parseSort.js +75 -68
  45. package/lib/data/parseSort.test.js +196 -187
  46. package/lib/data/resolvePagination.js +38 -39
  47. package/lib/data/resolvePagination.test.js +228 -218
  48. package/lib/data/types.d.js +2 -2
  49. package/lib/data/types.d.js.map +1 -1
  50. package/lib/dayjs/dayjs.js +20 -20
  51. package/lib/dayjs/formatDuration.js +56 -56
  52. package/lib/dayjs/formatDuration.js.map +1 -1
  53. package/lib/dayjs/formatDuration.test.js +63 -77
  54. package/lib/dayjs/index.js +4 -4
  55. package/lib/dayjs/parseDuration.js +21 -26
  56. package/lib/dayjs/parseRelativeTime.js +65 -66
  57. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  58. package/lib/dayjs/resolveRelativeTime.js +74 -144
  59. package/lib/dayjs/resolveRelativeTime.js.map +1 -1
  60. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  61. package/lib/decimal/index.js +1 -1
  62. package/lib/decimal/parseDecimal.js +12 -12
  63. package/lib/drain3/Drain.js +321 -0
  64. package/lib/drain3/Drain.js.map +1 -0
  65. package/lib/drain3/LogCluster.js +38 -0
  66. package/lib/drain3/LogCluster.js.map +1 -0
  67. package/lib/drain3/Node.js +39 -0
  68. package/lib/drain3/Node.js.map +1 -0
  69. package/lib/drain3/TemplateMiner.js +205 -0
  70. package/lib/drain3/TemplateMiner.js.map +1 -0
  71. package/lib/drain3/index.js +31 -0
  72. package/lib/drain3/index.js.map +1 -0
  73. package/lib/drain3/persistence/FilePersistence.js +24 -0
  74. package/lib/drain3/persistence/FilePersistence.js.map +1 -0
  75. package/lib/drain3/persistence/MemoryPersistence.js +18 -0
  76. package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
  77. package/lib/drain3/persistence/PersistenceHandler.js +5 -0
  78. package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
  79. package/lib/drain3/types.js +7 -0
  80. package/lib/drain3/types.js.map +1 -0
  81. package/lib/emittery/emitter.js +7 -7
  82. package/lib/emittery/index.js +1 -1
  83. package/lib/foundation/schema/SexType.js +15 -12
  84. package/lib/foundation/schema/index.js +1 -1
  85. package/lib/foundation/schema/parseSexType.js +15 -16
  86. package/lib/foundation/schema/types.js +8 -6
  87. package/lib/fs/FileSystemError.js +18 -18
  88. package/lib/fs/IFileSystem.d.js +2 -2
  89. package/lib/fs/IFileSystem.d.js.map +1 -1
  90. package/lib/fs/MemoryFileSystem.test.js +172 -181
  91. package/lib/fs/createBrowserFileSystem.js +222 -233
  92. package/lib/fs/createBrowserFileSystem.js.map +1 -1
  93. package/lib/fs/createMemoryFileSystem.js +473 -510
  94. package/lib/fs/createMemoryFileSystem.js.map +1 -1
  95. package/lib/fs/createSandboxFileSystem.js +102 -101
  96. package/lib/fs/createSandboxFileSystem.js.map +1 -1
  97. package/lib/fs/createWebDavFileSystem.js +162 -132
  98. package/lib/fs/createWebDavFileSystem.js.map +1 -1
  99. package/lib/fs/createWebFileSystem.js +202 -0
  100. package/lib/fs/createWebFileSystem.js.map +1 -0
  101. package/lib/fs/findMimeType.js +14 -14
  102. package/lib/fs/findMimeType.js.map +1 -1
  103. package/lib/fs/index.js +7 -7
  104. package/lib/fs/index.js.map +1 -1
  105. package/lib/fs/minio/createMinioFileSystem.js +977 -0
  106. package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
  107. package/lib/fs/minio/index.js +2 -0
  108. package/lib/fs/minio/index.js.map +1 -0
  109. package/lib/fs/orpc/FileSystemContract.js +57 -57
  110. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  111. package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
  112. package/lib/fs/orpc/index.js +2 -2
  113. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  114. package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
  115. package/lib/fs/orpc/server/index.js +1 -1
  116. package/lib/fs/s3/createS3MiniFileSystem.js +756 -689
  117. package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
  118. package/lib/fs/s3/index.js +1 -1
  119. package/lib/fs/s3/s3mini.test.js +524 -553
  120. package/lib/fs/scandir.js +56 -56
  121. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  122. package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
  123. package/lib/fs/server/createNodeFileSystem.js +407 -380
  124. package/lib/fs/server/createNodeFileSystem.js.map +1 -1
  125. package/lib/fs/server/dbfs.test.js +201 -214
  126. package/lib/fs/server/index.js +1 -1
  127. package/lib/fs/server/loadTestDatabase.js +40 -43
  128. package/lib/fs/tests/runFileSystemTest.js +352 -315
  129. package/lib/fs/tests/runFileSystemTest.js.map +1 -1
  130. package/lib/fs/types.js +17 -20
  131. package/lib/fs/utils/getFileUrl.js +24 -30
  132. package/lib/fs/utils.js +17 -17
  133. package/lib/fs/utils.js.map +1 -1
  134. package/lib/fs/webdav/index.js +2 -0
  135. package/lib/fs/webdav/index.js.map +1 -0
  136. package/lib/index.js +2 -2
  137. package/lib/jsonschema/JsonSchema.js +216 -155
  138. package/lib/jsonschema/JsonSchema.js.map +1 -1
  139. package/lib/jsonschema/JsonSchema.test.js +123 -124
  140. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  141. package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
  142. package/lib/jsonschema/index.js +2 -2
  143. package/lib/jsonschema/types.d.js +2 -2
  144. package/lib/jsonschema/types.d.js.map +1 -1
  145. package/lib/meta/defineFileType.js +32 -38
  146. package/lib/meta/defineInit.js +39 -35
  147. package/lib/meta/defineMetadata.js +37 -34
  148. package/lib/meta/defineMetadata.js.map +1 -1
  149. package/lib/meta/defineMetadata.test.js +13 -12
  150. package/lib/meta/index.js +3 -3
  151. package/lib/orpc/createOpenApiContractClient.js +26 -24
  152. package/lib/orpc/createOpenApiContractClient.js.map +1 -1
  153. package/lib/orpc/createRpcContractClient.js +37 -31
  154. package/lib/orpc/index.js +2 -2
  155. package/lib/orpc/resolveLinkPlugins.js +25 -25
  156. package/lib/password/PHC.js +187 -189
  157. package/lib/password/PHC.js.map +1 -1
  158. package/lib/password/PHC.test.js +517 -535
  159. package/lib/password/Password.js +85 -80
  160. package/lib/password/Password.test.js +330 -364
  161. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  162. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
  163. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  164. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
  165. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  166. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
  167. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  168. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
  169. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  170. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
  171. package/lib/password/index.js +5 -5
  172. package/lib/password/server/index.js +1 -1
  173. package/lib/resource/Identifiable.js +2 -2
  174. package/lib/resource/ListQuery.js +42 -42
  175. package/lib/resource/ListQuery.js.map +1 -1
  176. package/lib/resource/getTitleOfResource.js +5 -5
  177. package/lib/resource/index.js +2 -2
  178. package/lib/resource/index.js.map +1 -1
  179. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  180. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  181. package/lib/resource/schema/ResourceActionType.js +117 -115
  182. package/lib/resource/schema/ResourceStatus.js +94 -92
  183. package/lib/resource/schema/ResourceType.js +25 -23
  184. package/lib/resource/schema/index.js +5 -5
  185. package/lib/resource/schema/types.js +86 -55
  186. package/lib/resource/schema/types.test.js +16 -13
  187. package/lib/s3/formatS3Url.js +60 -60
  188. package/lib/s3/formatS3Url.js.map +1 -1
  189. package/lib/s3/formatS3Url.test.js +238 -261
  190. package/lib/s3/index.js +2 -2
  191. package/lib/s3/parseS3Url.js +61 -60
  192. package/lib/s3/parseS3Url.js.map +1 -1
  193. package/lib/s3/parseS3Url.test.js +270 -269
  194. package/lib/schema/SchemaRegistry.js +41 -42
  195. package/lib/schema/SchemaRegistry.js.map +1 -1
  196. package/lib/schema/SchemaRegistry.mod.js +1 -1
  197. package/lib/schema/TypeSchema.d.js +2 -2
  198. package/lib/schema/TypeSchema.d.js.map +1 -1
  199. package/lib/schema/createSchemaData.js +113 -67
  200. package/lib/schema/createSchemaData.js.map +1 -1
  201. package/lib/schema/findJsonSchemaByPath.js +28 -23
  202. package/lib/schema/findJsonSchemaByPath.js.map +1 -1
  203. package/lib/schema/formatZodError.js +113 -134
  204. package/lib/schema/formatZodError.js.map +1 -1
  205. package/lib/schema/formatZodError.test.js +192 -195
  206. package/lib/schema/getSchemaCache.js +7 -7
  207. package/lib/schema/getSchemaOptions.js +17 -16
  208. package/lib/schema/index.js +6 -6
  209. package/lib/schema/toJsonSchema.js +196 -190
  210. package/lib/schema/toJsonSchema.js.map +1 -1
  211. package/lib/schema/toJsonSchema.test.js +34 -26
  212. package/lib/schema/validate.js +106 -97
  213. package/lib/schema/validate.js.map +1 -1
  214. package/lib/tools/generateSchema.js +40 -40
  215. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  216. package/lib/utils/buildBaseUrl.js +8 -8
  217. package/lib/utils/buildRedactorFormSchema.js +55 -54
  218. package/lib/utils/buildRedactorFormSchema.js.map +1 -1
  219. package/lib/utils/getEstimateProcessTime.js +24 -19
  220. package/lib/utils/index.js +3 -3
  221. package/lib/utils/resolveFeatureOptions.js +9 -9
  222. package/package.json +37 -18
  223. package/src/ai/qwen3vl/utils.ts +1 -1
  224. package/src/ai/vision/index.ts +2 -2
  225. package/src/cn/ChineseResidentIdNo.ts +1 -1
  226. package/src/cn/Mod11.ts +1 -1
  227. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
  228. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
  229. package/src/cn/index.ts +1 -2
  230. package/src/cn/parseChineseNumber.test.ts +4 -4
  231. package/src/consola/formatLogObject.ts +6 -6
  232. package/src/consola/index.ts +1 -1
  233. package/src/data/index.ts +3 -4
  234. package/src/data/maybeNumber.ts +1 -1
  235. package/src/data/parseSort.test.ts +0 -1
  236. package/src/data/resolvePagination.ts +2 -2
  237. package/src/data/types.d.ts +2 -2
  238. package/src/dayjs/formatDuration.ts +10 -11
  239. package/src/dayjs/index.ts +1 -1
  240. package/src/dayjs/parseRelativeTime.ts +1 -1
  241. package/src/dayjs/resolveRelativeTime.ts +11 -14
  242. package/src/drain3/Drain.test.ts +378 -0
  243. package/src/drain3/Drain.ts +394 -0
  244. package/src/drain3/LogCluster.ts +46 -0
  245. package/src/drain3/Node.ts +53 -0
  246. package/src/drain3/TemplateMiner.ts +246 -0
  247. package/src/drain3/index.ts +34 -0
  248. package/src/drain3/persistence/FilePersistence.ts +24 -0
  249. package/src/drain3/persistence/MemoryPersistence.ts +23 -0
  250. package/src/drain3/persistence/PersistenceHandler.ts +19 -0
  251. package/src/drain3/types.ts +75 -0
  252. package/src/fs/IFileSystem.d.ts +1 -2
  253. package/src/fs/createBrowserFileSystem.ts +7 -5
  254. package/src/fs/createMemoryFileSystem.ts +9 -13
  255. package/src/fs/createSandboxFileSystem.ts +1 -1
  256. package/src/fs/createWebDavFileSystem.ts +30 -17
  257. package/src/fs/createWebFileSystem.ts +242 -0
  258. package/src/fs/findMimeType.ts +1 -4
  259. package/src/fs/index.ts +5 -5
  260. package/src/fs/minio/createMinioFileSystem.ts +1148 -0
  261. package/src/fs/minio/index.ts +1 -0
  262. package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
  263. package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
  264. package/src/fs/s3/createS3MiniFileSystem.ts +120 -79
  265. package/src/fs/s3/s3fs.test.ts +441 -0
  266. package/src/fs/s3/s3mini.test.ts +2 -2
  267. package/src/fs/server/createDatabaseFileSystem.ts +78 -114
  268. package/src/fs/server/createNodeFileSystem.ts +32 -13
  269. package/src/fs/server/dbfs.test.ts +13 -8
  270. package/src/fs/server/index.ts +1 -0
  271. package/src/fs/server/loadTestDatabase.ts +8 -119
  272. package/src/fs/tests/runFileSystemTest.ts +29 -28
  273. package/src/fs/utils.ts +1 -1
  274. package/src/fs/webdav/index.ts +1 -0
  275. package/src/jsonschema/JsonSchema.ts +5 -5
  276. package/src/jsonschema/forEachJsonSchema.ts +1 -1
  277. package/src/jsonschema/index.ts +1 -1
  278. package/src/jsonschema/types.d.ts +1 -1
  279. package/src/meta/defineMetadata.ts +1 -1
  280. package/src/meta/index.ts +2 -3
  281. package/src/orm/createSqliteDialect.ts +17 -0
  282. package/src/orm/index.ts +1 -0
  283. package/src/orpc/createOpenApiContractClient.ts +3 -3
  284. package/src/orpc/index.ts +1 -1
  285. package/src/password/PHC.ts +3 -3
  286. package/src/password/createArgon2PasswordAlgorithm.ts +2 -2
  287. package/src/password/createBase64PasswordAlgorithm.ts +2 -2
  288. package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
  289. package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
  290. package/src/password/createScryptPasswordAlgorithm.ts +4 -4
  291. package/src/password/index.ts +2 -2
  292. package/src/resource/ListQuery.ts +4 -1
  293. package/src/resource/index.ts +3 -3
  294. package/src/resource/schema/index.ts +4 -4
  295. package/src/s3/formatS3Url.test.ts +1 -1
  296. package/src/s3/formatS3Url.ts +2 -2
  297. package/src/s3/index.ts +1 -1
  298. package/src/s3/parseS3Url.ts +1 -1
  299. package/src/schema/SchemaRegistry.ts +2 -2
  300. package/src/schema/TypeSchema.d.ts +6 -6
  301. package/src/schema/createSchemaData.ts +5 -5
  302. package/src/schema/findJsonSchemaByPath.ts +5 -5
  303. package/src/schema/formatZodError.test.ts +2 -1
  304. package/src/schema/formatZodError.ts +50 -62
  305. package/src/schema/index.ts +5 -5
  306. package/src/schema/toJsonSchema.ts +6 -6
  307. package/src/schema/validate.ts +2 -2
  308. package/src/utils/buildRedactorFormSchema.ts +4 -4
  309. package/src/utils/formatNumber.ts +18 -0
  310. package/src/utils/formatPercent.ts +17 -0
  311. package/src/utils/index.ts +3 -3
  312. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,137 +1,167 @@
1
- import { maybeFunction } from "@wener/utils";
1
+ import { maybeFunction } from '@wener/utils';
2
2
  export function createWebDavFileSystem({ client }) {
3
- let fs = new WebdavFS({
4
- client
5
- });
6
- return fs;
3
+ let fs = new WebdavFS({
4
+ client,
5
+ });
6
+ return fs;
7
7
  }
8
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 && 'status' in input && typeof input.status === 'number') {
42
- return input.data;
43
- }
44
- return input;
45
- }
46
- async readdir(path, { glob, recursive, depth, kind, hidden, signal } = {}) {
47
- // webdav depth 只支持 0,1
48
- let o = {};
49
- if (recursive) {
50
- o.deep = true;
51
- }
52
- let res = await this.client.getDirectoryContents(path, {
53
- deep: recursive,
54
- signal
55
- });
56
- let out = this.getData(res);
57
- if (!recursive && typeof depth === 'number' && depth >= 2) {
58
- let l = depth;
59
- let cur = out;
60
- while(l-- > 1){
61
- let sub = (await Promise.all(cur.map(async (v)=>{
62
- if (v.type === 'directory') {
63
- return this.getData(await this.client.getDirectoryContents(v.filename, {
64
- signal
65
- }));
66
- }
67
- return [];
68
- }))).flat();
69
- out = out.concat(...sub);
70
- cur = sub;
71
- }
72
- }
73
- if (glob) {
74
- const { default: def, matcher = def.matcher } = await import("micromatch");
75
- const match = matcher(glob);
76
- out = out.filter((v)=>match(v.filename));
77
- }
78
- if (kind) {
79
- out = out.filter((v)=>v.type === kind);
80
- }
81
- if (!hidden) {
82
- out = out.filter((v)=>!v.basename.startsWith('.'));
83
- }
84
- return out.map((stat)=>this.toEntry(stat));
85
- }
86
- async stat(path, { signal } = {}) {
87
- const res = await this.client.stat(path, {
88
- details: true,
89
- signal
90
- });
91
- return this.toEntry(this.getData(res));
92
- }
93
- async mkdir(path, { recursive, signal } = {}) {
94
- await this.client.createDirectory(path, {
95
- recursive,
96
- signal
97
- });
98
- }
99
- async readFile(path, options = {}) {
100
- const format = options.encoding === 'text' ? 'text' : 'binary';
101
- const res = await this.client.getFileContents(path, {
102
- format,
103
- ...options
104
- });
105
- return this.getData(res);
106
- }
107
- async writeFile(path, data, options = {}) {
108
- await this.client.putFileContents(path, data, options);
109
- }
110
- async rm(path, { signal, force, recursive } = {}) {
111
- try {
112
- await this.client.deleteFile(path);
113
- } catch (e) {
114
- if (force && e.status === 404) {
115
- return;
116
- }
117
- throw e;
118
- }
119
- }
120
- async rename(oldPath, newPath, options = {}) {
121
- await this.client.moveFile(oldPath, newPath, options);
122
- }
123
- async exists(path) {
124
- return await this.client.exists(path);
125
- }
126
- async copy(src, dest, options = {}) {
127
- await this.client.copyFile(src, dest, options);
128
- }
129
- createReadStream(path, options = {}) {
130
- return this.client.createReadStream(path, options);
131
- }
132
- createWriteStream(path, options = {}) {
133
- return this.client.createWriteStream(path, options);
134
- }
9
+ _client;
10
+ constructor({
11
+ client = () => {
12
+ throw new Error('WebdavFS client not initialized');
13
+ },
14
+ }) {
15
+ this._client = client;
16
+ }
17
+ set client(client) {
18
+ this._client = client;
19
+ }
20
+ get client() {
21
+ return maybeFunction(this._client);
22
+ }
23
+ toEntry(input) {
24
+ const { filename: path, basename, lastmod, type: kind, etag, size, mime } = input;
25
+ let meta = {};
26
+ if (etag) {
27
+ meta.etag = etag;
28
+ }
29
+ if (mime) {
30
+ meta.mime = mime;
31
+ }
32
+ return {
33
+ directory: path.substring(0, path.lastIndexOf('/')) || '/',
34
+ path,
35
+ name: basename,
36
+ mtime: +new Date(lastmod),
37
+ kind,
38
+ meta,
39
+ size,
40
+ };
41
+ }
42
+ getData(input) {
43
+ if (
44
+ input &&
45
+ typeof input === 'object' &&
46
+ 'data' in input && // 'headers' in input &&
47
+ 'status' in input &&
48
+ typeof input.status === 'number'
49
+ ) {
50
+ return input.data;
51
+ }
52
+ return input;
53
+ }
54
+ async readdir(path, { glob, recursive, depth, kind, hidden, signal } = {}) {
55
+ // webdav depth 只支持 0,1
56
+ let o = {};
57
+ if (recursive) {
58
+ o.deep = true;
59
+ }
60
+ let res = await this.client.getDirectoryContents(path, {
61
+ deep: recursive,
62
+ signal,
63
+ });
64
+ let out = this.getData(res);
65
+ if (!recursive && typeof depth === 'number' && depth >= 2) {
66
+ let l = depth;
67
+ let cur = out;
68
+ while (l-- > 1) {
69
+ let sub = (
70
+ await Promise.all(
71
+ cur.map(async (v) => {
72
+ if (v.type === 'directory') {
73
+ return this.getData(
74
+ await this.client.getDirectoryContents(v.filename, {
75
+ signal,
76
+ }),
77
+ );
78
+ }
79
+ return [];
80
+ }),
81
+ )
82
+ ).flat();
83
+ out = out.concat(...sub);
84
+ cur = sub;
85
+ }
86
+ }
87
+ if (glob) {
88
+ const { default: def, matcher = def.matcher } = await import('micromatch');
89
+ const match = matcher(glob);
90
+ out = out.filter((v) => match(v.filename));
91
+ }
92
+ if (kind) {
93
+ out = out.filter((v) => v.type === kind);
94
+ }
95
+ if (!hidden) {
96
+ out = out.filter((v) => !v.basename.startsWith('.'));
97
+ }
98
+ return out.map((stat) => this.toEntry(stat));
99
+ }
100
+ async stat(path, { signal } = {}) {
101
+ const res = await this.client.stat(path, {
102
+ details: true,
103
+ signal,
104
+ });
105
+ return this.toEntry(this.getData(res));
106
+ }
107
+ async mkdir(path, { recursive, signal } = {}) {
108
+ await this.client.createDirectory(path, {
109
+ recursive,
110
+ signal,
111
+ });
112
+ }
113
+ async readFile(path, options = {}) {
114
+ const format = options.encoding === 'text' ? 'text' : 'binary';
115
+ const res = await this.client.getFileContents(path, {
116
+ format,
117
+ ...options,
118
+ });
119
+ return this.getData(res);
120
+ }
121
+ async writeFile(path, data, options = {}) {
122
+ // Convert web ReadableStream to something WebDAV client can handle
123
+ let webdavData = data;
124
+ if (data instanceof ReadableStream) {
125
+ // Convert web ReadableStream to Buffer
126
+ const reader = data.getReader();
127
+ const chunks = [];
128
+ while (true) {
129
+ const { done, value } = await reader.read();
130
+ if (done) break;
131
+ if (value) chunks.push(value);
132
+ }
133
+ webdavData = Buffer.concat(chunks);
134
+ } else if (ArrayBuffer.isView(data) && !(data instanceof Buffer)) {
135
+ // Convert ArrayBufferView to Buffer
136
+ webdavData = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
137
+ }
138
+ await this.client.putFileContents(path, webdavData, options);
139
+ }
140
+ async rm(path, { signal: _signal, force, recursive: _recursive } = {}) {
141
+ try {
142
+ await this.client.deleteFile(path);
143
+ } catch (e) {
144
+ if (force && e.status === 404) {
145
+ return;
146
+ }
147
+ throw e;
148
+ }
149
+ }
150
+ async rename(oldPath, newPath, options = {}) {
151
+ await this.client.moveFile(oldPath, newPath, options);
152
+ }
153
+ async exists(path) {
154
+ return await this.client.exists(path);
155
+ }
156
+ async copy(src, dest, options = {}) {
157
+ await this.client.copyFile(src, dest, options);
158
+ }
159
+ createReadStream(path, options = {}) {
160
+ return this.client.createReadStream(path, options);
161
+ }
162
+ createWriteStream(path, options = {}) {
163
+ return this.client.createWriteStream(path, options);
164
+ }
135
165
  };
136
166
 
137
- //# sourceMappingURL=createWebDavFileSystem.js.map
167
+ //# sourceMappingURL=createWebDavFileSystem.js.map
@@ -1 +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} 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\t&& typeof 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\t&& typeof 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: string | Buffer | ArrayBuffer | Readable, options = {}): Promise<void> {\n\t\tawait this.client.putFileContents(path, data, options);\n\t}\n\n\tasync rm(path: string, { signal, force, 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","putFileContents","rm","force","deleteFile","e","rename","oldPath","newPath","moveFile","exists","copy","src","dest","copyFile","createReadStream","createWriteStream"],"mappings":"AACA,SAASA,aAAa,QAA4B,eAAe;AAYjE,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,IAAIA,OAAOA,MAAmC,EAAE;QAC/C,IAAI,CAACG,OAAO,GAAGH;IAChB;IAEA,IAAIA,SAAuB;QAC1B,OAAOF,cAAc,IAAI,CAACK,OAAO;IAClC;IAEQE,QAAQC,KAAe,EAAa;QAC3C,MAAM,EAAEC,UAAUC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,MAAMC,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGT;QAC5E,IAAIU,OAA4B,CAAC;QACjC,IAAIH,MAAM;YACTG,IAAI,CAAC,OAAO,GAAGH;QAChB;QACA,IAAIE,MAAM;YACTC,IAAI,CAAC,OAAO,GAAGD;QAChB;QACA,OAAO;YACNE,WAAWT,KAAKU,SAAS,CAAC,GAAGV,KAAKW,WAAW,CAAC,SAAS;YACvDX;YACAY,MAAMX;YACNY,OAAO,CAAC,IAAIC,KAAKZ;YACjBE;YACAI;YACAF;QACD;IACD;IAEQS,QAAWjB,KAAkC,EAAK;QACzD,IACCA,SACG,OAAOA,UAAU,YACjB,UAAUA,SAEV,YAAYA,SACZ,OAAOA,MAAMkB,MAAM,KAAK,UAC1B;YACD,OAAOlB,MAAMmB,IAAI;QAClB;QACA,OAAOnB;IACR;IAEA,MAAMoB,QACLlB,IAAY,EACZ,EAAEmB,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;IAEA,MAAMC,OAAOC,OAAe,EAAEC,OAAe,EAAEZ,UAAU,CAAC,CAAC,EAAiB;QAC3E,MAAM,IAAI,CAACzD,MAAM,CAACsE,QAAQ,CAACF,SAASC,SAASZ;IAC9C;IAEA,MAAMc,OAAO/D,IAAY,EAAoB;QAC5C,OAAO,MAAM,IAAI,CAACR,MAAM,CAACuE,MAAM,CAAC/D;IACjC;IAEA,MAAMgE,KAAKC,GAAW,EAAEC,IAAY,EAAEjB,UAAU,CAAC,CAAC,EAAiB;QAClE,MAAM,IAAI,CAACzD,MAAM,CAAC2E,QAAQ,CAACF,KAAKC,MAAMjB;IACvC;IAEAmB,iBAAiBpE,IAAY,EAAEiD,UAAU,CAAC,CAAC,EAAY;QACtD,OAAO,IAAI,CAACzD,MAAM,CAAC4E,gBAAgB,CAACpE,MAAMiD;IAC3C;IAEAoB,kBAAkBrE,IAAY,EAAEiD,UAAU,CAAC,CAAC,EAAY;QACvD,OAAO,IAAI,CAACzD,MAAM,CAAC6E,iBAAiB,CAACrE,MAAMiD;IAC5C;AACD"}
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,u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UAAU;QACvE;QACA,MAAM,IAAI,CAAC7E,MAAM,CAAC8E,eAAe,CAACtE,MAAMsD,YAAYL;IACrD;IAEA,MAAMsB,GAAGvE,IAAY,EAAE,EAAEuB,QAAQiD,OAAO,EAAEC,KAAK,EAAErD,WAAWsD,UAAU,EAAa,GAAG,CAAC,CAAC,EAAiB;QACxG,IAAI;YACH,MAAM,IAAI,CAAClF,MAAM,CAACmF,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,202 @@
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) return this.root;
14
+ let current = this.root;
15
+ for (let i = 0; i < parts.length; i++) {
16
+ const part = parts[i];
17
+ const isLast = i === parts.length - 1;
18
+ try {
19
+ // Try to get as directory first
20
+ current = await current.getDirectoryHandle(part);
21
+ } catch (e) {
22
+ if (e.name === 'TypeMismatchError' || e.name === 'NotFoundError') {
23
+ if (isLast) {
24
+ // Might be a file
25
+ try {
26
+ return await current.getFileHandle(part);
27
+ } catch (_e2) {
28
+ throw new FileSystemError(`File not found: ${path}`, 'ENOENT');
29
+ }
30
+ }
31
+ }
32
+ if (e.name === 'NotFoundError') {
33
+ throw new FileSystemError(`Path not found: ${path}`, 'ENOENT');
34
+ }
35
+ throw e;
36
+ }
37
+ }
38
+ return current;
39
+ }
40
+ async _getParent(path) {
41
+ const normalized = normalize(path);
42
+ const parentPath = dirname(normalized);
43
+ const name = basename(normalized);
44
+ if (!name) throw new FileSystemError('Invalid path', 'EINVAL');
45
+ const parentHandle = await this._getHandle(parentPath);
46
+ if (parentHandle.kind !== 'directory') {
47
+ throw new FileSystemError(`Parent is not a directory: ${parentPath}`, 'ENOTDIR');
48
+ }
49
+ return {
50
+ parent: parentHandle,
51
+ name,
52
+ };
53
+ }
54
+ async stat(path, options) {
55
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
56
+ const handle = await this._getHandle(path);
57
+ return this._handleToStat(handle, path);
58
+ }
59
+ async _handleToStat(handle, path) {
60
+ let size = 0;
61
+ let mtime = 0;
62
+ if (handle.kind === 'file') {
63
+ const file = await handle.getFile();
64
+ size = file.size;
65
+ mtime = file.lastModified;
66
+ }
67
+ return {
68
+ path,
69
+ directory: dirname(path),
70
+ name: handle.name,
71
+ kind: handle.kind,
72
+ size,
73
+ mtime,
74
+ meta: {},
75
+ };
76
+ }
77
+ async exists(path) {
78
+ try {
79
+ await this._getHandle(path);
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
85
+ async readdir(path, options) {
86
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
87
+ const handle = await this._getHandle(path);
88
+ if (handle.kind !== 'directory') {
89
+ throw new FileSystemError(`Not a directory: ${path}`, 'ENOTDIR');
90
+ }
91
+ const entries = [];
92
+ // @ts-expect-error - FileSystemDirectoryHandle is async iterable in modern browsers
93
+ for await (const entry of handle.values()) {
94
+ entries.push(await this._handleToStat(entry, join(path, entry.name)));
95
+ }
96
+ return entries;
97
+ }
98
+ async mkdir(path, options) {
99
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
100
+ const normalized = normalize(path);
101
+ const parts = normalized.split('/').filter(Boolean);
102
+ let current = this.root;
103
+ if (options?.recursive) {
104
+ for (const part of parts) {
105
+ current = await current.getDirectoryHandle(part, {
106
+ create: true,
107
+ });
108
+ }
109
+ } else {
110
+ const parentPath = dirname(normalized);
111
+ const name = basename(normalized);
112
+ try {
113
+ const parent = await this._getHandle(parentPath);
114
+ if (parent.kind !== 'directory') throw new FileSystemError(`Parent not a directory: ${parentPath}`, 'ENOTDIR');
115
+ await parent.getDirectoryHandle(name, {
116
+ create: true,
117
+ });
118
+ } catch (e) {
119
+ if (e.code === 'ENOENT' || e.name === 'NotFoundError') {
120
+ throw new FileSystemError(`Parent does not exist: ${parentPath}`, 'ENOENT');
121
+ }
122
+ throw e;
123
+ }
124
+ }
125
+ }
126
+ async readFile(path, options) {
127
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
128
+ const handle = await this._getHandle(path);
129
+ if (handle.kind !== 'file') throw new FileSystemError(`Is a directory: ${path}`, 'EISDIR');
130
+ const file = await handle.getFile();
131
+ if (options?.encoding === 'text') {
132
+ return await file.text();
133
+ } else {
134
+ const buffer = await file.arrayBuffer();
135
+ return new Uint8Array(buffer);
136
+ }
137
+ }
138
+ async writeFile(path, data, options) {
139
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
140
+ if (options?.overwrite === false) {
141
+ if (await this.exists(path)) {
142
+ throw new FileSystemError(`File already exists: ${path}`, 'EEXIST');
143
+ }
144
+ }
145
+ const { parent, name } = await this._getParent(path);
146
+ const handle = await parent.getFileHandle(name, {
147
+ create: true,
148
+ });
149
+ const writable = await handle.createWritable();
150
+ await writable.write(data);
151
+ await writable.close();
152
+ }
153
+ async rm(path, options) {
154
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
155
+ const { parent, name } = await this._getParent(path);
156
+ try {
157
+ await parent.removeEntry(name, {
158
+ recursive: options?.recursive,
159
+ });
160
+ } catch (e) {
161
+ if (e.name === 'NotFoundError') {
162
+ if (!options?.force) throw new FileSystemError(`File not found: ${path}`, 'ENOENT');
163
+ } else if (e.name === 'InvalidModificationError') {
164
+ throw new FileSystemError(`Directory not empty: ${path}`, 'ENOTEMPTY');
165
+ } else {
166
+ throw e;
167
+ }
168
+ }
169
+ }
170
+ async rename(oldPath, newPath, options) {
171
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
172
+ // File System Access API doesn't support move/rename directly
173
+ // Fallback to copy + delete
174
+ await this.copy(oldPath, newPath, {
175
+ overwrite: options?.overwrite,
176
+ });
177
+ await this.rm(oldPath, {
178
+ recursive: true,
179
+ });
180
+ }
181
+ async copy(src, dest, options) {
182
+ if (options?.signal?.aborted) throw new FileSystemError('Operation aborted', 'ABORT_ERR');
183
+ const srcHandle = await this._getHandle(src);
184
+ if (srcHandle.kind === 'file') {
185
+ const file = await srcHandle.getFile();
186
+ await this.writeFile(dest, await file.arrayBuffer(), {
187
+ overwrite: options?.overwrite,
188
+ });
189
+ } else {
190
+ // Directory copy
191
+ await this.mkdir(dest);
192
+ const entries = await this.readdir(src);
193
+ for (const entry of entries) {
194
+ await this.copy(entry.path, join(dest, entry.name), options);
195
+ }
196
+ }
197
+ }
198
+ getUrl(_file) {
199
+ return undefined;
200
+ }
201
+ };
202
+ //# 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,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;YAC3D,OAAO;gBACN,MAAMW;YACP;QACD;IACD;IAEA,MAAMgD,OAAOC,OAAe,EAAEC,OAAe,EAAEjE,OAAuB,EAAiB;QACtF,IAAIA,SAAS0B,QAAQC,SAAS,MAAM,IAAI7B,gBAAgB,qBAAqB;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"}
@@ -1,17 +1,17 @@
1
- import { types } from "mime-types";
2
- import pathe from "pathe";
1
+ import { types } from 'mime-types';
2
+ import pathe from 'pathe';
3
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;
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
15
  }
16
16
 
17
- //# sourceMappingURL=findMimeType.js.map
17
+ //# sourceMappingURL=findMimeType.js.map
@@ -1 +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\n\t\t.extname('x.' + path)\n\t\t.toLowerCase()\n\t\t.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,MAChBI,OAAO,CAAC,OAAOF,MACfG,WAAW,GACXC,KAAK,CAAC;IAER,IAAI,CAACH,WAAW;QACf,OAAO;IACR;IAEA,OAAOJ,KAAK,CAACI,UAAU,IAAI;AAC5B"}
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"}