@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,248 +1,237 @@
1
- import { dirname, join, normalize } from "pathe";
1
+ import { dirname, join, normalize } from 'pathe';
2
+
2
3
  let BrowserFSError = class BrowserFSError extends Error {
3
- code;
4
- constructor(message, code){
5
- super(message), this.code = code;
6
- this.name = 'BrowserFSError';
7
- }
4
+ code;
5
+ constructor(message, code) {
6
+ super(message), (this.code = code);
7
+ this.name = 'BrowserFSError';
8
+ }
8
9
  };
9
10
  /**
10
11
  * Creates an IFileSystem instance backed by the browser's File System Access API.
11
12
  * @param root A FileSystemDirectoryHandle, usually obtained from `window.showDirectoryPicker()`.
12
13
  */ export function createBrowserFileSystem(root) {
13
- return new BrowserFS(root);
14
+ return new BrowserFS(root);
14
15
  }
15
16
  let BrowserFS = class BrowserFS {
16
- root;
17
- node;
18
- constructor(root){
19
- this.root = root;
20
- this.node = {
21
- path: '/',
22
- name: '',
23
- directory: '',
24
- kind: 'directory',
25
- mtime: 0,
26
- size: 0,
27
- meta: {
28
- handle: root
29
- }
30
- };
31
- }
32
- /**
17
+ root;
18
+ node;
19
+ constructor(root) {
20
+ this.root = root;
21
+ this.node = {
22
+ path: '/',
23
+ name: '',
24
+ directory: '',
25
+ kind: 'directory',
26
+ mtime: 0,
27
+ size: 0,
28
+ meta: {
29
+ handle: root,
30
+ },
31
+ };
32
+ }
33
+ /**
33
34
  * Resolves a path string to a file or directory handle. This is the core navigation logic.
34
35
  * @returns A tuple of [handle, parentHandle, name] or [null, parentHandle, name] if not found.
35
36
  */ async _getHandle(path) {
36
- const normalized = normalize(path);
37
- if (normalized === '/' || normalized === '.') {
38
- return [
39
- this.root,
40
- null,
41
- this.root.name
42
- ];
43
- }
44
- const parts = normalized.split('/').filter((p)=>p);
45
- const name = parts.pop();
46
- let parent = this.root;
47
- for (const part of parts){
48
- try {
49
- parent = await parent.getDirectoryHandle(part);
50
- } catch (e) {
51
- if (e.name === 'NotFoundError' || e.name === 'TypeMismatchError') {
52
- return [
53
- null,
54
- null,
55
- name
56
- ]; // Parent path does not exist or is a file
57
- }
58
- throw e;
59
- }
60
- }
61
- try {
62
- // Check for file first, then directory
63
- const handle = await parent.getFileHandle(name).catch(()=>parent.getDirectoryHandle(name));
64
- return [
65
- handle,
66
- parent,
67
- name
68
- ];
69
- } catch (e) {
70
- if (e.name === 'NotFoundError') {
71
- return [
72
- null,
73
- parent,
74
- name
75
- ]; // Entry not found
76
- }
77
- throw e;
78
- }
79
- }
80
- /**
37
+ const normalized = normalize(path);
38
+ if (normalized === '/' || normalized === '.') {
39
+ return [this.root, null, this.root.name];
40
+ }
41
+ const parts = normalized.split('/').filter((p) => p);
42
+ const name = parts.pop();
43
+ let parent = this.root;
44
+ for (const part of parts) {
45
+ try {
46
+ parent = await parent.getDirectoryHandle(part);
47
+ } catch (e) {
48
+ if (e.name === 'NotFoundError' || e.name === 'TypeMismatchError') {
49
+ return [null, null, name]; // Parent path does not exist or is a file
50
+ }
51
+ throw e;
52
+ }
53
+ }
54
+ try {
55
+ // Check for file first, then directory
56
+ const handle = await parent.getFileHandle(name).catch(() => parent.getDirectoryHandle(name));
57
+ return [handle, parent, name];
58
+ } catch (e) {
59
+ if (e.name === 'NotFoundError') {
60
+ return [null, parent, name]; // Entry not found
61
+ }
62
+ throw e;
63
+ }
64
+ }
65
+ /**
81
66
  * Converts a FileSystemHandle into our standard IFileStat object.
82
67
  */ async _toFileStat(handle, path) {
83
- const isFile = handle.kind === 'file';
84
- const file = isFile ? await handle.getFile() : undefined;
85
- return {
86
- name: handle.name,
87
- kind: handle.kind,
88
- path: path,
89
- directory: dirname(path),
90
- size: file?.size ?? 0,
91
- mtime: file?.lastModified ?? Date.now(),
92
- meta: {
93
- handle,
94
- file
95
- }
96
- };
97
- }
98
- // --- IFileSystem Implementation ---
99
- async stat(path) {
100
- const [handle] = await this._getHandle(path);
101
- if (!handle) {
102
- throw new BrowserFSError(`Path not found: ${path}`, 'ENOENT');
103
- }
104
- return this._toFileStat(handle, path);
105
- }
106
- async exists(path) {
107
- const [handle] = await this._getHandle(path);
108
- return !!handle;
109
- }
110
- async readdir(dir, options) {
111
- const [handle] = await this._getHandle(dir);
112
- if (!handle) {
113
- throw new BrowserFSError(`Directory not found: ${dir}`, 'ENOENT');
114
- }
115
- if (handle.kind !== 'directory') {
116
- throw new BrowserFSError(`Not a directory: ${dir}`, 'ENOTDIR');
117
- }
118
- const entries = [];
119
- for await (const entry of handle.values()){
120
- entries.push(await this._toFileStat(entry, join(dir, entry.name)));
121
- }
122
- return entries;
123
- }
124
- async mkdir(path, options = {}) {
125
- const parts = normalize(path).split('/').filter((p)=>p);
126
- let currentDir = this.root;
127
- for (const part of parts){
128
- try {
129
- currentDir = await currentDir.getDirectoryHandle(part, {
130
- create: options.recursive
131
- });
132
- } catch (e) {
133
- // If recursive is false, getDirectoryHandle throws if a segment is missing.
134
- // We re-throw a more standard error.
135
- if (e.name === 'NotFoundError' && !options.recursive) {
136
- throw new BrowserFSError(`Cannot create directory: Parent does not exist for path ${path}`, 'ENOENT');
137
- }
138
- // If it's another error (like a file with the same name), re-throw it.
139
- throw e;
140
- }
141
- }
142
- }
143
- async readFile(path, options) {
144
- const [handle] = await this._getHandle(path);
145
- if (!handle || handle.kind !== 'file') {
146
- throw new BrowserFSError(`File not found: ${path}`, 'ENOENT');
147
- }
148
- const file = await handle.getFile();
149
- return options?.encoding === 'text' ? file.text() : file.bytes();
150
- }
151
- async writeFile(path, data, options = {}) {
152
- const { overwrite = true } = options;
153
- const [handle, parent, name] = await this._getHandle(path);
154
- if (!parent) {
155
- throw new BrowserFSError(`Parent directory does not exist for path: ${path}`, 'ENOENT');
156
- }
157
- if (handle && !overwrite) {
158
- throw new BrowserFSError(`File already exists: ${path}`, 'EEXIST');
159
- }
160
- const fileHandle = await parent.getFileHandle(name, {
161
- create: true
162
- });
163
- const writable = await fileHandle.createWritable();
164
- await writable.write(data);
165
- await writable.close();
166
- }
167
- async rm(path, options = {}) {
168
- const { recursive = false, force = false } = options;
169
- const [handle, parent, name] = await this._getHandle(path);
170
- if (!handle) {
171
- if (force) return; // If force is true, do not error on not found.
172
- throw new BrowserFSError(`Path not found: ${path}`, 'ENOENT');
173
- }
174
- if (!parent) {
175
- throw new BrowserFSError(`Cannot remove root directory`);
176
- }
177
- await parent.removeEntry(name, {
178
- recursive
179
- });
180
- }
181
- async rename(oldPath, newPath, options) {
182
- // The File System Access API does NOT have a native move/rename.
183
- // The standard workaround is to copy, then delete the original.
184
- await this.copy(oldPath, newPath, options);
185
- await this.rm(oldPath, {
186
- recursive: true
187
- });
188
- }
189
- async copy(srcPath, destPath, options) {
190
- const [srcHandle] = await this._getHandle(srcPath);
191
- if (!srcHandle) {
192
- throw new BrowserFSError(`Source not found: ${srcPath}`, 'ENOENT');
193
- }
194
- const [destHandle, destParent, destName] = await this._getHandle(destPath);
195
- if (!destParent) {
196
- throw new BrowserFSError(`Destination directory does not exist: ${dirname(destPath)}`, 'ENOENT');
197
- }
198
- if (destHandle && !options?.overwrite) {
199
- throw new BrowserFSError(`Destination already exists: ${destPath}`, 'EEXIST');
200
- }
201
- if (destHandle?.kind === 'directory' && srcHandle.kind === 'file') {
202
- throw new BrowserFSError(`Cannot overwrite a directory with a file: ${destPath}`, 'EISDIR');
203
- }
204
- await this._copyEntry(srcHandle, destParent, destName);
205
- }
206
- async _copyEntry(srcHandle, destDirHandle, newName) {
207
- if (srcHandle.kind === 'file') {
208
- const file = await srcHandle.getFile();
209
- const destFileHandle = await destDirHandle.getFileHandle(newName, {
210
- create: true
211
- });
212
- const writable = await destFileHandle.createWritable();
213
- await writable.write(file);
214
- await writable.close();
215
- } else if (srcHandle.kind === 'directory') {
216
- const newDirHandle = await destDirHandle.getDirectoryHandle(newName, {
217
- create: true
218
- });
219
- for await (const entry of srcHandle.values()){
220
- await this._copyEntry(entry, newDirHandle, entry.name);
221
- }
222
- }
223
- }
224
- async createUrl(stat, options) {
225
- // The handle is stored in the meta property in our _toFileStat method
226
- const handle = stat.meta.handle;
227
- if (handle?.kind !== 'file') {
228
- // Return a placeholder or throw an error for directories
229
- return '';
230
- }
231
- const file = await handle.getFile();
232
- return URL.createObjectURL(file);
233
- }
234
- createReadStream() {
235
- throw new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');
236
- }
237
- createWriteStream() {
238
- throw new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');
239
- }
240
- createWritableStream() {
241
- throw new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');
242
- }
243
- createReadableStream() {
244
- throw new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');
245
- }
68
+ const isFile = handle.kind === 'file';
69
+ const file = isFile ? await handle.getFile() : undefined;
70
+ return {
71
+ name: handle.name,
72
+ kind: handle.kind,
73
+ path: path,
74
+ directory: dirname(path),
75
+ size: file?.size ?? 0,
76
+ mtime: file?.lastModified ?? Date.now(),
77
+ meta: {
78
+ handle,
79
+ file,
80
+ },
81
+ };
82
+ }
83
+ // --- IFileSystem Implementation ---
84
+ async stat(path) {
85
+ const [handle] = await this._getHandle(path);
86
+ if (!handle) {
87
+ throw new BrowserFSError(`Path not found: ${path}`, 'ENOENT');
88
+ }
89
+ return this._toFileStat(handle, path);
90
+ }
91
+ async exists(path) {
92
+ const [handle] = await this._getHandle(path);
93
+ return !!handle;
94
+ }
95
+ async readdir(dir, _options) {
96
+ const [handle] = await this._getHandle(dir);
97
+ if (!handle) {
98
+ throw new BrowserFSError(`Directory not found: ${dir}`, 'ENOENT');
99
+ }
100
+ if (handle.kind !== 'directory') {
101
+ throw new BrowserFSError(`Not a directory: ${dir}`, 'ENOTDIR');
102
+ }
103
+ const entries = [];
104
+ // FileSystemDirectoryHandle.values() is part of the File System Access API
105
+ // but not yet in TypeScript's lib.dom.d.ts
106
+ for await (const entry of handle.values()) {
107
+ entries.push(await this._toFileStat(entry, join(dir, entry.name)));
108
+ }
109
+ return entries;
110
+ }
111
+ async mkdir(path, options = {}) {
112
+ const parts = normalize(path)
113
+ .split('/')
114
+ .filter((p) => p);
115
+ let currentDir = this.root;
116
+ for (const part of parts) {
117
+ try {
118
+ currentDir = await currentDir.getDirectoryHandle(part, {
119
+ create: options.recursive,
120
+ });
121
+ } catch (e) {
122
+ // If recursive is false, getDirectoryHandle throws if a segment is missing.
123
+ // We re-throw a more standard error.
124
+ if (e.name === 'NotFoundError' && !options.recursive) {
125
+ throw new BrowserFSError(`Cannot create directory: Parent does not exist for path ${path}`, 'ENOENT');
126
+ }
127
+ // If it's another error (like a file with the same name), re-throw it.
128
+ throw e;
129
+ }
130
+ }
131
+ }
132
+ async readFile(path, options) {
133
+ const [handle] = await this._getHandle(path);
134
+ if (!handle || handle.kind !== 'file') {
135
+ throw new BrowserFSError(`File not found: ${path}`, 'ENOENT');
136
+ }
137
+ const file = await handle.getFile();
138
+ return options?.encoding === 'text' ? file.text() : file.bytes();
139
+ }
140
+ async writeFile(path, data, options = {}) {
141
+ const { overwrite = true } = options;
142
+ const [handle, parent, name] = await this._getHandle(path);
143
+ if (!parent) {
144
+ throw new BrowserFSError(`Parent directory does not exist for path: ${path}`, 'ENOENT');
145
+ }
146
+ if (handle && !overwrite) {
147
+ throw new BrowserFSError(`File already exists: ${path}`, 'EEXIST');
148
+ }
149
+ const fileHandle = await parent.getFileHandle(name, {
150
+ create: true,
151
+ });
152
+ const writable = await fileHandle.createWritable();
153
+ await writable.write(data);
154
+ await writable.close();
155
+ }
156
+ async rm(path, options = {}) {
157
+ const { recursive = false, force = false } = options;
158
+ const [handle, parent, name] = await this._getHandle(path);
159
+ if (!handle) {
160
+ if (force) return; // If force is true, do not error on not found.
161
+ throw new BrowserFSError(`Path not found: ${path}`, 'ENOENT');
162
+ }
163
+ if (!parent) {
164
+ throw new BrowserFSError(`Cannot remove root directory`);
165
+ }
166
+ await parent.removeEntry(name, {
167
+ recursive,
168
+ });
169
+ }
170
+ async rename(oldPath, newPath, options) {
171
+ // The File System Access API does NOT have a native move/rename.
172
+ // The standard workaround is to copy, then delete the original.
173
+ await this.copy(oldPath, newPath, options);
174
+ await this.rm(oldPath, {
175
+ recursive: true,
176
+ });
177
+ }
178
+ async copy(srcPath, destPath, options) {
179
+ const [srcHandle] = await this._getHandle(srcPath);
180
+ if (!srcHandle) {
181
+ throw new BrowserFSError(`Source not found: ${srcPath}`, 'ENOENT');
182
+ }
183
+ const [destHandle, destParent, destName] = await this._getHandle(destPath);
184
+ if (!destParent) {
185
+ throw new BrowserFSError(`Destination directory does not exist: ${dirname(destPath)}`, 'ENOENT');
186
+ }
187
+ if (destHandle && !options?.overwrite) {
188
+ throw new BrowserFSError(`Destination already exists: ${destPath}`, 'EEXIST');
189
+ }
190
+ if (destHandle?.kind === 'directory' && srcHandle.kind === 'file') {
191
+ throw new BrowserFSError(`Cannot overwrite a directory with a file: ${destPath}`, 'EISDIR');
192
+ }
193
+ await this._copyEntry(srcHandle, destParent, destName);
194
+ }
195
+ async _copyEntry(srcHandle, destDirHandle, newName) {
196
+ if (srcHandle.kind === 'file') {
197
+ const file = await srcHandle.getFile();
198
+ const destFileHandle = await destDirHandle.getFileHandle(newName, {
199
+ create: true,
200
+ });
201
+ const writable = await destFileHandle.createWritable();
202
+ await writable.write(file);
203
+ await writable.close();
204
+ } else if (srcHandle.kind === 'directory') {
205
+ const newDirHandle = await destDirHandle.getDirectoryHandle(newName, {
206
+ create: true,
207
+ });
208
+ for await (const entry of srcHandle.values()) {
209
+ await this._copyEntry(entry, newDirHandle, entry.name);
210
+ }
211
+ }
212
+ }
213
+ async createUrl(stat, _options) {
214
+ // The handle is stored in the meta property in our _toFileStat method
215
+ const handle = stat.meta.handle;
216
+ if (handle?.kind !== 'file') {
217
+ // Return a placeholder or throw an error for directories
218
+ return '';
219
+ }
220
+ const file = await handle.getFile();
221
+ return URL.createObjectURL(file);
222
+ }
223
+ createReadStream() {
224
+ throw new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');
225
+ }
226
+ createWriteStream() {
227
+ throw new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');
228
+ }
229
+ createWritableStream() {
230
+ throw new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');
231
+ }
232
+ createReadableStream() {
233
+ throw new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');
234
+ }
246
235
  };
247
236
 
248
- //# sourceMappingURL=createBrowserFileSystem.js.map
237
+ //# sourceMappingURL=createBrowserFileSystem.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fs/createBrowserFileSystem.ts"],"sourcesContent":["import { dirname, join, normalize } from 'pathe';\nimport type {\n\tCopyOptions,\n\tIFileStat,\n\tIFileSystem,\n\tMkdirOptions,\n\tReaddirOptions,\n\tReadFileOptions,\n\tRenameOptions,\n\tRmOptions,\n\tWriteFileOptions,\n} from './IFileSystem';\nimport type { FileUrlOptions } from './types';\n\nclass BrowserFSError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic code?: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'BrowserFSError';\n\t}\n}\n\ntype BrowserFile = IFileStat & {\n\tkind: 'file';\n\tmeta: {\n\t\thandle: FileSystemFileHandle;\n\t\tfile: File;\n\t};\n};\n\ntype BrowserDirectory = IFileStat & {\n\tkind: 'directory';\n\tmeta: {\n\t\thandle: FileSystemDirectoryHandle;\n\t};\n};\n\ntype BrowserNode = BrowserFile | BrowserDirectory;\n\n/**\n * Creates an IFileSystem instance backed by the browser's File System Access API.\n * @param root A FileSystemDirectoryHandle, usually obtained from `window.showDirectoryPicker()`.\n */\nexport function createBrowserFileSystem(root: FileSystemDirectoryHandle): IFileSystem {\n\treturn new BrowserFS(root);\n}\n\nclass BrowserFS implements IFileSystem {\n\troot: FileSystemDirectoryHandle;\n\tnode: BrowserDirectory;\n\n\tconstructor(root: FileSystemDirectoryHandle) {\n\t\tthis.root = root;\n\t\tthis.node = {\n\t\t\tpath: '/',\n\t\t\tname: '',\n\t\t\tdirectory: '',\n\t\t\tkind: 'directory',\n\t\t\tmtime: 0,\n\t\t\tsize: 0,\n\t\t\tmeta: {\n\t\t\t\thandle: root,\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Resolves a path string to a file or directory handle. This is the core navigation logic.\n\t * @returns A tuple of [handle, parentHandle, name] or [null, parentHandle, name] if not found.\n\t */\n\tprivate async _getHandle(path: string): Promise<[FileSystemHandle | null, FileSystemDirectoryHandle | null, string]> {\n\t\tconst normalized = normalize(path);\n\t\tif (normalized === '/' || normalized === '.') {\n\t\t\treturn [this.root, null, this.root.name];\n\t\t}\n\n\t\tconst parts = normalized.split('/').filter((p) => p);\n\t\tconst name = parts.pop()!;\n\n\t\tlet parent: FileSystemDirectoryHandle = this.root;\n\t\tfor (const part of parts) {\n\t\t\ttry {\n\t\t\t\tparent = await parent.getDirectoryHandle(part);\n\t\t\t} catch (e: any) {\n\t\t\t\tif (e.name === 'NotFoundError' || e.name === 'TypeMismatchError') {\n\t\t\t\t\treturn [null, null, name]; // Parent path does not exist or is a file\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\t// Check for file first, then directory\n\t\t\tconst handle = await parent.getFileHandle(name).catch(() => parent.getDirectoryHandle(name));\n\t\t\treturn [handle, parent, name];\n\t\t} catch (e: any) {\n\t\t\tif (e.name === 'NotFoundError') {\n\t\t\t\treturn [null, parent, name]; // Entry not found\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t/**\n\t * Converts a FileSystemHandle into our standard IFileStat object.\n\t */\n\tprivate async _toFileStat(handle: FileSystemHandle, path: string): Promise<IFileStat> {\n\t\tconst isFile = handle.kind === 'file';\n\t\tconst file = isFile ? await (handle as FileSystemFileHandle).getFile() : undefined;\n\n\t\treturn {\n\t\t\tname: handle.name,\n\t\t\tkind: handle.kind,\n\t\t\tpath: path,\n\t\t\tdirectory: dirname(path),\n\t\t\tsize: file?.size ?? 0,\n\t\t\tmtime: file?.lastModified ?? Date.now(),\n\t\t\tmeta: { handle, file },\n\t\t};\n\t}\n\n\t// --- IFileSystem Implementation ---\n\n\tasync stat(path: string): Promise<IFileStat> {\n\t\tconst [handle] = await this._getHandle(path);\n\t\tif (!handle) {\n\t\t\tthrow new BrowserFSError(`Path not found: ${path}`, 'ENOENT');\n\t\t}\n\t\treturn this._toFileStat(handle, path);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\tconst [handle] = await this._getHandle(path);\n\t\treturn !!handle;\n\t}\n\n\tasync readdir(dir: string, options?: ReaddirOptions): Promise<IFileStat[]> {\n\t\tconst [handle] = await this._getHandle(dir);\n\t\tif (!handle) {\n\t\t\tthrow new BrowserFSError(`Directory not found: ${dir}`, 'ENOENT');\n\t\t}\n\t\tif (handle.kind !== 'directory') {\n\t\t\tthrow new BrowserFSError(`Not a directory: ${dir}`, 'ENOTDIR');\n\t\t}\n\n\t\tconst entries: IFileStat[] = [];\n\t\tfor await (const entry of (handle as FileSystemDirectoryHandle).values()) {\n\t\t\tentries.push(await this._toFileStat(entry, join(dir, entry.name)));\n\t\t}\n\t\treturn entries;\n\t}\n\n\tasync mkdir(path: string, options: MkdirOptions = {}): Promise<void> {\n\t\tconst parts = normalize(path)\n\t\t\t.split('/')\n\t\t\t.filter((p) => p);\n\t\tlet currentDir = this.root;\n\n\t\tfor (const part of parts) {\n\t\t\ttry {\n\t\t\t\tcurrentDir = await currentDir.getDirectoryHandle(part, { create: options.recursive });\n\t\t\t} catch (e: any) {\n\t\t\t\t// If recursive is false, getDirectoryHandle throws if a segment is missing.\n\t\t\t\t// We re-throw a more standard error.\n\t\t\t\tif (e.name === 'NotFoundError' && !options.recursive) {\n\t\t\t\t\tthrow new BrowserFSError(`Cannot create directory: Parent does not exist for path ${path}`, 'ENOENT');\n\t\t\t\t}\n\t\t\t\t// If it's another error (like a file with the same name), re-throw it.\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\tconst [handle] = await this._getHandle(path);\n\t\tif (!handle || handle.kind !== 'file') {\n\t\t\tthrow new BrowserFSError(`File not found: ${path}`, 'ENOENT');\n\t\t}\n\t\tconst file = await (handle as FileSystemFileHandle).getFile();\n\t\treturn options?.encoding === 'text' ? file.text() : file.bytes();\n\t}\n\n\tasync writeFile(path: string, data: any, options: WriteFileOptions = {}): Promise<void> {\n\t\tconst { overwrite = true } = options;\n\t\tconst [handle, parent, name] = await this._getHandle(path);\n\n\t\tif (!parent) {\n\t\t\tthrow new BrowserFSError(`Parent directory does not exist for path: ${path}`, 'ENOENT');\n\t\t}\n\t\tif (handle && !overwrite) {\n\t\t\tthrow new BrowserFSError(`File already exists: ${path}`, 'EEXIST');\n\t\t}\n\n\t\tconst fileHandle = await parent.getFileHandle(name, { create: true });\n\t\tconst writable = await fileHandle.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\tconst { recursive = false, force = false } = options;\n\t\tconst [handle, parent, name] = await this._getHandle(path);\n\n\t\tif (!handle) {\n\t\t\tif (force) return; // If force is true, do not error on not found.\n\t\t\tthrow new BrowserFSError(`Path not found: ${path}`, 'ENOENT');\n\t\t}\n\t\tif (!parent) {\n\t\t\tthrow new BrowserFSError(`Cannot remove root directory`);\n\t\t}\n\n\t\tawait parent.removeEntry(name, { recursive });\n\t}\n\n\tasync rename(oldPath: string, newPath: string, options?: RenameOptions): Promise<void> {\n\t\t// The File System Access API does NOT have a native move/rename.\n\t\t// The standard workaround is to copy, then delete the original.\n\t\tawait this.copy(oldPath, newPath, options);\n\t\tawait this.rm(oldPath, { recursive: true });\n\t}\n\n\tasync copy(srcPath: string, destPath: string, options?: CopyOptions): Promise<void> {\n\t\tconst [srcHandle] = await this._getHandle(srcPath);\n\t\tif (!srcHandle) {\n\t\t\tthrow new BrowserFSError(`Source not found: ${srcPath}`, 'ENOENT');\n\t\t}\n\n\t\tconst [destHandle, destParent, destName] = await this._getHandle(destPath);\n\t\tif (!destParent) {\n\t\t\tthrow new BrowserFSError(`Destination directory does not exist: ${dirname(destPath)}`, 'ENOENT');\n\t\t}\n\t\tif (destHandle && !options?.overwrite) {\n\t\t\tthrow new BrowserFSError(`Destination already exists: ${destPath}`, 'EEXIST');\n\t\t}\n\t\tif (destHandle?.kind === 'directory' && srcHandle.kind === 'file') {\n\t\t\tthrow new BrowserFSError(`Cannot overwrite a directory with a file: ${destPath}`, 'EISDIR');\n\t\t}\n\n\t\tawait this._copyEntry(srcHandle, destParent, destName);\n\t}\n\n\tprivate async _copyEntry(\n\t\tsrcHandle: FileSystemHandle,\n\t\tdestDirHandle: FileSystemDirectoryHandle,\n\t\tnewName: string,\n\t): Promise<void> {\n\t\tif (srcHandle.kind === 'file') {\n\t\t\tconst file = await (srcHandle as FileSystemFileHandle).getFile();\n\t\t\tconst destFileHandle = await destDirHandle.getFileHandle(newName, { create: true });\n\t\t\tconst writable = await destFileHandle.createWritable();\n\t\t\tawait writable.write(file);\n\t\t\tawait writable.close();\n\t\t} else if (srcHandle.kind === 'directory') {\n\t\t\tconst newDirHandle = await destDirHandle.getDirectoryHandle(newName, { create: true });\n\t\t\tfor await (const entry of (srcHandle as FileSystemDirectoryHandle).values()) {\n\t\t\t\tawait this._copyEntry(entry, newDirHandle, entry.name);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync createUrl(stat: IFileStat, options?: FileUrlOptions): Promise<string> {\n\t\t// The handle is stored in the meta property in our _toFileStat method\n\t\tconst handle = stat.meta.handle as FileSystemHandle | undefined;\n\t\tif (handle?.kind !== 'file') {\n\t\t\t// Return a placeholder or throw an error for directories\n\t\t\treturn '';\n\t\t}\n\t\tconst file = await (handle as FileSystemFileHandle).getFile();\n\t\treturn URL.createObjectURL(file);\n\t}\n\n\tcreateReadStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');\n\t}\n\n\tcreateWriteStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');\n\t}\n\n\tcreateWritableStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');\n\t}\n\n\tcreateReadableStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');\n\t}\n}\n"],"names":["dirname","join","normalize","BrowserFSError","Error","message","code","name","createBrowserFileSystem","root","BrowserFS","node","path","directory","kind","mtime","size","meta","handle","_getHandle","normalized","parts","split","filter","p","pop","parent","part","getDirectoryHandle","e","getFileHandle","catch","_toFileStat","isFile","file","getFile","undefined","lastModified","Date","now","stat","exists","readdir","dir","options","entries","entry","values","push","mkdir","currentDir","create","recursive","readFile","encoding","text","bytes","writeFile","data","overwrite","fileHandle","writable","createWritable","write","close","rm","force","removeEntry","rename","oldPath","newPath","copy","srcPath","destPath","srcHandle","destHandle","destParent","destName","_copyEntry","destDirHandle","newName","destFileHandle","newDirHandle","createUrl","URL","createObjectURL","createReadStream","createWriteStream","createWritableStream","createReadableStream"],"mappings":"AAAA,SAASA,OAAO,EAAEC,IAAI,EAAEC,SAAS,QAAQ,QAAQ;AAcjD,IAAA,AAAMC,iBAAN,MAAMA,uBAAuBC;;IAC5B,YACCC,OAAe,EACf,AAAOC,IAAa,CACnB;QACD,KAAK,CAACD,eAFCC,OAAAA;QAGP,IAAI,CAACC,IAAI,GAAG;IACb;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,MAAM1B,SAASsB,KAAKvB,IAAI,CAACC,MAAM;QAC/B,IAAIA,QAAQJ,SAAS,QAAQ;YAC5B,yDAAyD;YACzD,OAAO;QACR;QACA,MAAMoB,OAAO,MAAM,AAAChB,OAAgCiB,OAAO;QAC3D,OAAOiD,IAAIC,eAAe,CAACnD;IAC5B;IAEAoD,mBAA0B;QACzB,MAAM,IAAIlF,MAAM;IACjB;IAEAmF,oBAA2B;QAC1B,MAAM,IAAInF,MAAM;IACjB;IAEAoF,uBAA8B;QAC7B,MAAM,IAAIpF,MAAM;IACjB;IAEAqF,uBAA8B;QAC7B,MAAM,IAAIrF,MAAM;IACjB;AACD"}
1
+ {"version":3,"sources":["../../src/fs/createBrowserFileSystem.ts"],"sourcesContent":["import { dirname, join, normalize } from 'pathe';\nimport type {\n\tCopyOptions,\n\tIFileStat,\n\tIFileSystem,\n\tMkdirOptions,\n\tReaddirOptions,\n\tReadFileOptions,\n\tRenameOptions,\n\tRmOptions,\n\tWriteFileOptions,\n} from './IFileSystem';\nimport type { FileUrlOptions } from './types';\n\nclass BrowserFSError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic code?: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'BrowserFSError';\n\t}\n}\n\ntype BrowserFile = IFileStat & {\n\tkind: 'file';\n\tmeta: {\n\t\thandle: FileSystemFileHandle;\n\t\tfile: File;\n\t};\n};\n\ntype BrowserDirectory = IFileStat & {\n\tkind: 'directory';\n\tmeta: {\n\t\thandle: FileSystemDirectoryHandle;\n\t};\n};\n\ntype _BrowserNode = BrowserFile | BrowserDirectory;\n\n/**\n * Creates an IFileSystem instance backed by the browser's File System Access API.\n * @param root A FileSystemDirectoryHandle, usually obtained from `window.showDirectoryPicker()`.\n */\nexport function createBrowserFileSystem(root: FileSystemDirectoryHandle): IFileSystem {\n\treturn new BrowserFS(root);\n}\n\nclass BrowserFS implements IFileSystem {\n\troot: FileSystemDirectoryHandle;\n\tnode: BrowserDirectory;\n\n\tconstructor(root: FileSystemDirectoryHandle) {\n\t\tthis.root = root;\n\t\tthis.node = {\n\t\t\tpath: '/',\n\t\t\tname: '',\n\t\t\tdirectory: '',\n\t\t\tkind: 'directory',\n\t\t\tmtime: 0,\n\t\t\tsize: 0,\n\t\t\tmeta: {\n\t\t\t\thandle: root,\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Resolves a path string to a file or directory handle. This is the core navigation logic.\n\t * @returns A tuple of [handle, parentHandle, name] or [null, parentHandle, name] if not found.\n\t */\n\tprivate async _getHandle(path: string): Promise<[FileSystemHandle | null, FileSystemDirectoryHandle | null, string]> {\n\t\tconst normalized = normalize(path);\n\t\tif (normalized === '/' || normalized === '.') {\n\t\t\treturn [this.root, null, this.root.name];\n\t\t}\n\n\t\tconst parts = normalized.split('/').filter((p) => p);\n\t\tconst name = parts.pop()!;\n\n\t\tlet parent: FileSystemDirectoryHandle = this.root;\n\t\tfor (const part of parts) {\n\t\t\ttry {\n\t\t\t\tparent = await parent.getDirectoryHandle(part);\n\t\t\t} catch (e: any) {\n\t\t\t\tif (e.name === 'NotFoundError' || e.name === 'TypeMismatchError') {\n\t\t\t\t\treturn [null, null, name]; // Parent path does not exist or is a file\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\t// Check for file first, then directory\n\t\t\tconst handle = await parent.getFileHandle(name).catch(() => parent.getDirectoryHandle(name));\n\t\t\treturn [handle, parent, name];\n\t\t} catch (e: any) {\n\t\t\tif (e.name === 'NotFoundError') {\n\t\t\t\treturn [null, parent, name]; // Entry not found\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t/**\n\t * Converts a FileSystemHandle into our standard IFileStat object.\n\t */\n\tprivate async _toFileStat(handle: FileSystemHandle, path: string): Promise<IFileStat> {\n\t\tconst isFile = handle.kind === 'file';\n\t\tconst file = isFile ? await (handle as FileSystemFileHandle).getFile() : undefined;\n\n\t\treturn {\n\t\t\tname: handle.name,\n\t\t\tkind: handle.kind,\n\t\t\tpath: path,\n\t\t\tdirectory: dirname(path),\n\t\t\tsize: file?.size ?? 0,\n\t\t\tmtime: file?.lastModified ?? Date.now(),\n\t\t\tmeta: { handle, file },\n\t\t};\n\t}\n\n\t// --- IFileSystem Implementation ---\n\n\tasync stat(path: string): Promise<IFileStat> {\n\t\tconst [handle] = await this._getHandle(path);\n\t\tif (!handle) {\n\t\t\tthrow new BrowserFSError(`Path not found: ${path}`, 'ENOENT');\n\t\t}\n\t\treturn this._toFileStat(handle, path);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\tconst [handle] = await this._getHandle(path);\n\t\treturn !!handle;\n\t}\n\n\tasync readdir(dir: string, _options?: ReaddirOptions): Promise<IFileStat[]> {\n\t\tconst [handle] = await this._getHandle(dir);\n\t\tif (!handle) {\n\t\t\tthrow new BrowserFSError(`Directory not found: ${dir}`, 'ENOENT');\n\t\t}\n\t\tif (handle.kind !== 'directory') {\n\t\t\tthrow new BrowserFSError(`Not a directory: ${dir}`, 'ENOTDIR');\n\t\t}\n\n\t\tconst entries: IFileStat[] = [];\n\t\t// FileSystemDirectoryHandle.values() is part of the File System Access API\n\t\t// but not yet in TypeScript's lib.dom.d.ts\n\t\tfor await (const entry of (handle as any).values()) {\n\t\t\tentries.push(await this._toFileStat(entry, join(dir, entry.name)));\n\t\t}\n\t\treturn entries;\n\t}\n\n\tasync mkdir(path: string, options: MkdirOptions = {}): Promise<void> {\n\t\tconst parts = normalize(path)\n\t\t\t.split('/')\n\t\t\t.filter((p) => p);\n\t\tlet currentDir = this.root;\n\n\t\tfor (const part of parts) {\n\t\t\ttry {\n\t\t\t\tcurrentDir = await currentDir.getDirectoryHandle(part, { create: options.recursive });\n\t\t\t} catch (e: any) {\n\t\t\t\t// If recursive is false, getDirectoryHandle throws if a segment is missing.\n\t\t\t\t// We re-throw a more standard error.\n\t\t\t\tif (e.name === 'NotFoundError' && !options.recursive) {\n\t\t\t\t\tthrow new BrowserFSError(`Cannot create directory: Parent does not exist for path ${path}`, 'ENOENT');\n\t\t\t\t}\n\t\t\t\t// If it's another error (like a file with the same name), re-throw it.\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\tconst [handle] = await this._getHandle(path);\n\t\tif (!handle || handle.kind !== 'file') {\n\t\t\tthrow new BrowserFSError(`File not found: ${path}`, 'ENOENT');\n\t\t}\n\t\tconst file = await (handle as FileSystemFileHandle).getFile();\n\t\treturn options?.encoding === 'text' ? file.text() : file.bytes();\n\t}\n\n\tasync writeFile(path: string, data: any, options: WriteFileOptions = {}): Promise<void> {\n\t\tconst { overwrite = true } = options;\n\t\tconst [handle, parent, name] = await this._getHandle(path);\n\n\t\tif (!parent) {\n\t\t\tthrow new BrowserFSError(`Parent directory does not exist for path: ${path}`, 'ENOENT');\n\t\t}\n\t\tif (handle && !overwrite) {\n\t\t\tthrow new BrowserFSError(`File already exists: ${path}`, 'EEXIST');\n\t\t}\n\n\t\tconst fileHandle = await parent.getFileHandle(name, { create: true });\n\t\tconst writable = await fileHandle.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\tconst { recursive = false, force = false } = options;\n\t\tconst [handle, parent, name] = await this._getHandle(path);\n\n\t\tif (!handle) {\n\t\t\tif (force) return; // If force is true, do not error on not found.\n\t\t\tthrow new BrowserFSError(`Path not found: ${path}`, 'ENOENT');\n\t\t}\n\t\tif (!parent) {\n\t\t\tthrow new BrowserFSError(`Cannot remove root directory`);\n\t\t}\n\n\t\tawait parent.removeEntry(name, { recursive });\n\t}\n\n\tasync rename(oldPath: string, newPath: string, options?: RenameOptions): Promise<void> {\n\t\t// The File System Access API does NOT have a native move/rename.\n\t\t// The standard workaround is to copy, then delete the original.\n\t\tawait this.copy(oldPath, newPath, options);\n\t\tawait this.rm(oldPath, { recursive: true });\n\t}\n\n\tasync copy(srcPath: string, destPath: string, options?: CopyOptions): Promise<void> {\n\t\tconst [srcHandle] = await this._getHandle(srcPath);\n\t\tif (!srcHandle) {\n\t\t\tthrow new BrowserFSError(`Source not found: ${srcPath}`, 'ENOENT');\n\t\t}\n\n\t\tconst [destHandle, destParent, destName] = await this._getHandle(destPath);\n\t\tif (!destParent) {\n\t\t\tthrow new BrowserFSError(`Destination directory does not exist: ${dirname(destPath)}`, 'ENOENT');\n\t\t}\n\t\tif (destHandle && !options?.overwrite) {\n\t\t\tthrow new BrowserFSError(`Destination already exists: ${destPath}`, 'EEXIST');\n\t\t}\n\t\tif (destHandle?.kind === 'directory' && srcHandle.kind === 'file') {\n\t\t\tthrow new BrowserFSError(`Cannot overwrite a directory with a file: ${destPath}`, 'EISDIR');\n\t\t}\n\n\t\tawait this._copyEntry(srcHandle, destParent, destName);\n\t}\n\n\tprivate async _copyEntry(\n\t\tsrcHandle: FileSystemHandle,\n\t\tdestDirHandle: FileSystemDirectoryHandle,\n\t\tnewName: string,\n\t): Promise<void> {\n\t\tif (srcHandle.kind === 'file') {\n\t\t\tconst file = await (srcHandle as FileSystemFileHandle).getFile();\n\t\t\tconst destFileHandle = await destDirHandle.getFileHandle(newName, { create: true });\n\t\t\tconst writable = await destFileHandle.createWritable();\n\t\t\tawait writable.write(file);\n\t\t\tawait writable.close();\n\t\t} else if (srcHandle.kind === 'directory') {\n\t\t\tconst newDirHandle = await destDirHandle.getDirectoryHandle(newName, { create: true });\n\t\t\tfor await (const entry of (srcHandle as any).values()) {\n\t\t\t\tawait this._copyEntry(entry, newDirHandle, entry.name);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync createUrl(stat: IFileStat, _options?: FileUrlOptions): Promise<string> {\n\t\t// The handle is stored in the meta property in our _toFileStat method\n\t\tconst handle = stat.meta.handle as FileSystemHandle | undefined;\n\t\tif (handle?.kind !== 'file') {\n\t\t\t// Return a placeholder or throw an error for directories\n\t\t\treturn '';\n\t\t}\n\t\tconst file = await (handle as FileSystemFileHandle).getFile();\n\t\treturn URL.createObjectURL(file);\n\t}\n\n\tcreateReadStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');\n\t}\n\n\tcreateWriteStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');\n\t}\n\n\tcreateWritableStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use writeFile instead.');\n\t}\n\n\tcreateReadableStream(): never {\n\t\tthrow new Error('Streaming is not implemented for BrowserFS. Use readFile instead.');\n\t}\n}\n"],"names":["dirname","join","normalize","BrowserFSError","Error","message","code","name","createBrowserFileSystem","root","BrowserFS","node","path","directory","kind","mtime","size","meta","handle","_getHandle","normalized","parts","split","filter","p","pop","parent","part","getDirectoryHandle","e","getFileHandle","catch","_toFileStat","isFile","file","getFile","undefined","lastModified","Date","now","stat","exists","readdir","dir","_options","entries","entry","values","push","mkdir","options","currentDir","create","recursive","readFile","encoding","text","bytes","writeFile","data","overwrite","fileHandle","writable","createWritable","write","close","rm","force","removeEntry","rename","oldPath","newPath","copy","srcPath","destPath","srcHandle","destHandle","destParent","destName","_copyEntry","destDirHandle","newName","destFileHandle","newDirHandle","createUrl","URL","createObjectURL","createReadStream","createWriteStream","createWritableStream","createReadableStream"],"mappings":"AAAA,SAASA,OAAO,EAAEC,IAAI,EAAEC,SAAS,QAAQ,QAAQ;AAcjD,IAAA,AAAMC,iBAAN,MAAMA,uBAAuBC;;IAC5B,YACCC,OAAe,EACf,AAAOC,IAAa,CACnB;QACD,KAAK,CAACD,eAFCC,OAAAA;QAGP,IAAI,CAACC,IAAI,GAAG;IACb;AACD;AAmBA;;;CAGC,GACD,OAAO,SAASC,wBAAwBC,IAA+B;IACtE,OAAO,IAAIC,UAAUD;AACtB;AAEA,IAAA,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