@wener/common 2.0.5 → 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 (206) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  4. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  5. package/lib/ai/vision/index.js +2 -2
  6. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  7. package/lib/cn/ChineseResidentIdNo.js +55 -41
  8. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  9. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  10. package/lib/cn/DivisionCode.js +220 -235
  11. package/lib/cn/DivisionCode.mod.js +6 -1
  12. package/lib/cn/DivisionCode.test.js +92 -121
  13. package/lib/cn/Mod11.js +18 -37
  14. package/lib/cn/Mod31.js +23 -41
  15. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  16. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  17. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  18. package/lib/cn/formatChineseAmount.js +46 -71
  19. package/lib/cn/index.js +6 -6
  20. package/lib/cn/mod.js +5 -3
  21. package/lib/cn/parseChineseNumber.js +81 -85
  22. package/lib/cn/parseChineseNumber.test.js +183 -261
  23. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  24. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  25. package/lib/cn/pinyin/loader.js +13 -11
  26. package/lib/cn/pinyin/preload.js +2 -1
  27. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  28. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  29. package/lib/cn/pinyin/transform.js +11 -11
  30. package/lib/cn/types.d.js +2 -2
  31. package/lib/consola/createStandardConsolaReporter.js +14 -15
  32. package/lib/consola/formatLogObject.js +149 -133
  33. package/lib/consola/formatLogObject.test.js +167 -178
  34. package/lib/consola/index.js +2 -2
  35. package/lib/data/formatSort.js +14 -12
  36. package/lib/data/formatSort.test.js +33 -33
  37. package/lib/data/index.js +3 -3
  38. package/lib/data/maybeNumber.js +23 -23
  39. package/lib/data/parseSort.js +75 -68
  40. package/lib/data/parseSort.test.js +196 -187
  41. package/lib/data/resolvePagination.js +38 -39
  42. package/lib/data/resolvePagination.test.js +228 -218
  43. package/lib/data/types.d.js +2 -2
  44. package/lib/dayjs/dayjs.js +20 -20
  45. package/lib/dayjs/formatDuration.js +56 -56
  46. package/lib/dayjs/formatDuration.test.js +63 -77
  47. package/lib/dayjs/index.js +4 -4
  48. package/lib/dayjs/parseDuration.js +21 -26
  49. package/lib/dayjs/parseRelativeTime.js +65 -66
  50. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  51. package/lib/dayjs/resolveRelativeTime.js +73 -72
  52. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  53. package/lib/decimal/index.js +1 -1
  54. package/lib/decimal/parseDecimal.js +12 -12
  55. package/lib/drain3/Drain.js +303 -338
  56. package/lib/drain3/LogCluster.js +25 -25
  57. package/lib/drain3/Node.js +24 -24
  58. package/lib/drain3/TemplateMiner.js +197 -196
  59. package/lib/drain3/index.js +5 -5
  60. package/lib/drain3/persistence/FilePersistence.js +19 -19
  61. package/lib/drain3/persistence/MemoryPersistence.js +8 -8
  62. package/lib/drain3/persistence/PersistenceHandler.js +2 -2
  63. package/lib/drain3/types.js +2 -2
  64. package/lib/emittery/emitter.js +7 -7
  65. package/lib/emittery/index.js +1 -1
  66. package/lib/foundation/schema/SexType.js +15 -12
  67. package/lib/foundation/schema/index.js +1 -1
  68. package/lib/foundation/schema/parseSexType.js +15 -16
  69. package/lib/foundation/schema/types.js +8 -6
  70. package/lib/fs/FileSystemError.js +18 -18
  71. package/lib/fs/IFileSystem.d.js +2 -2
  72. package/lib/fs/MemoryFileSystem.test.js +172 -181
  73. package/lib/fs/createBrowserFileSystem.js +222 -235
  74. package/lib/fs/createMemoryFileSystem.js +472 -510
  75. package/lib/fs/createSandboxFileSystem.js +102 -101
  76. package/lib/fs/createWebDavFileSystem.js +162 -149
  77. package/lib/fs/createWebFileSystem.js +197 -220
  78. package/lib/fs/findMimeType.js +14 -14
  79. package/lib/fs/index.js +7 -7
  80. package/lib/fs/minio/createMinioFileSystem.js +959 -956
  81. package/lib/fs/minio/index.js +1 -1
  82. package/lib/fs/orpc/FileSystemContract.js +57 -57
  83. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  84. package/lib/fs/orpc/index.js +2 -2
  85. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  86. package/lib/fs/orpc/server/index.js +1 -1
  87. package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
  88. package/lib/fs/s3/index.js +1 -1
  89. package/lib/fs/s3/s3mini.test.js +524 -553
  90. package/lib/fs/scandir.js +56 -56
  91. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  92. package/lib/fs/server/createNodeFileSystem.js +407 -405
  93. package/lib/fs/server/dbfs.test.js +201 -214
  94. package/lib/fs/server/index.js +1 -1
  95. package/lib/fs/server/loadTestDatabase.js +40 -43
  96. package/lib/fs/tests/runFileSystemTest.js +352 -316
  97. package/lib/fs/types.js +17 -20
  98. package/lib/fs/utils/getFileUrl.js +24 -30
  99. package/lib/fs/utils.js +17 -17
  100. package/lib/fs/webdav/index.js +1 -1
  101. package/lib/index.js +2 -2
  102. package/lib/jsonschema/JsonSchema.js +216 -155
  103. package/lib/jsonschema/JsonSchema.test.js +123 -124
  104. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  105. package/lib/jsonschema/index.js +2 -2
  106. package/lib/jsonschema/types.d.js +2 -2
  107. package/lib/meta/defineFileType.js +32 -38
  108. package/lib/meta/defineInit.js +39 -35
  109. package/lib/meta/defineMetadata.js +37 -34
  110. package/lib/meta/defineMetadata.test.js +13 -12
  111. package/lib/meta/index.js +3 -3
  112. package/lib/orpc/createOpenApiContractClient.js +26 -24
  113. package/lib/orpc/createRpcContractClient.js +37 -31
  114. package/lib/orpc/index.js +2 -2
  115. package/lib/orpc/resolveLinkPlugins.js +25 -25
  116. package/lib/password/PHC.js +187 -189
  117. package/lib/password/PHC.test.js +517 -535
  118. package/lib/password/Password.js +85 -80
  119. package/lib/password/Password.test.js +330 -364
  120. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  121. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  122. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  123. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  124. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  125. package/lib/password/index.js +5 -5
  126. package/lib/password/server/index.js +1 -1
  127. package/lib/resource/Identifiable.js +2 -2
  128. package/lib/resource/ListQuery.js +42 -42
  129. package/lib/resource/getTitleOfResource.js +5 -5
  130. package/lib/resource/index.js +2 -2
  131. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  132. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  133. package/lib/resource/schema/ResourceActionType.js +117 -115
  134. package/lib/resource/schema/ResourceStatus.js +94 -92
  135. package/lib/resource/schema/ResourceType.js +25 -23
  136. package/lib/resource/schema/index.js +5 -5
  137. package/lib/resource/schema/types.js +86 -55
  138. package/lib/resource/schema/types.test.js +16 -13
  139. package/lib/s3/formatS3Url.js +60 -60
  140. package/lib/s3/formatS3Url.test.js +238 -261
  141. package/lib/s3/index.js +2 -2
  142. package/lib/s3/parseS3Url.js +61 -60
  143. package/lib/s3/parseS3Url.test.js +270 -269
  144. package/lib/schema/SchemaRegistry.js +41 -42
  145. package/lib/schema/SchemaRegistry.mod.js +1 -1
  146. package/lib/schema/TypeSchema.d.js +2 -2
  147. package/lib/schema/createSchemaData.js +113 -67
  148. package/lib/schema/findJsonSchemaByPath.js +28 -23
  149. package/lib/schema/formatZodError.js +112 -131
  150. package/lib/schema/formatZodError.test.js +192 -195
  151. package/lib/schema/getSchemaCache.js +7 -7
  152. package/lib/schema/getSchemaOptions.js +17 -16
  153. package/lib/schema/index.js +6 -6
  154. package/lib/schema/toJsonSchema.js +195 -189
  155. package/lib/schema/toJsonSchema.test.js +34 -26
  156. package/lib/schema/validate.js +105 -96
  157. package/lib/tools/generateSchema.js +40 -40
  158. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  159. package/lib/utils/buildBaseUrl.js +8 -8
  160. package/lib/utils/buildRedactorFormSchema.js +54 -53
  161. package/lib/utils/getEstimateProcessTime.js +24 -19
  162. package/lib/utils/index.js +3 -3
  163. package/lib/utils/resolveFeatureOptions.js +9 -9
  164. package/package.json +14 -14
  165. package/src/ai/vision/index.ts +2 -2
  166. package/src/cn/index.ts +1 -2
  167. package/src/consola/index.ts +1 -1
  168. package/src/data/index.ts +3 -4
  169. package/src/data/resolvePagination.ts +2 -2
  170. package/src/dayjs/formatDuration.ts +8 -9
  171. package/src/dayjs/index.ts +1 -1
  172. package/src/dayjs/parseRelativeTime.ts +1 -1
  173. package/src/dayjs/resolveRelativeTime.ts +1 -1
  174. package/src/drain3/Drain.test.ts +2 -2
  175. package/src/drain3/index.ts +2 -4
  176. package/src/fs/createWebDavFileSystem.ts +2 -7
  177. package/src/fs/createWebFileSystem.ts +1 -1
  178. package/src/fs/index.ts +4 -4
  179. package/src/fs/minio/createMinioFileSystem.ts +2 -2
  180. package/src/fs/minio/index.ts +1 -1
  181. package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
  182. package/src/fs/server/createDatabaseFileSystem.ts +84 -120
  183. package/src/fs/server/dbfs.test.ts +14 -10
  184. package/src/fs/server/index.ts +1 -0
  185. package/src/fs/server/loadTestDatabase.ts +8 -119
  186. package/src/jsonschema/index.ts +1 -1
  187. package/src/meta/index.ts +2 -3
  188. package/src/orm/createSqliteDialect.ts +17 -0
  189. package/src/orm/index.ts +1 -0
  190. package/src/orpc/createOpenApiContractClient.ts +1 -1
  191. package/src/orpc/index.ts +1 -1
  192. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  193. package/src/password/index.ts +2 -2
  194. package/src/resource/index.ts +3 -3
  195. package/src/resource/schema/index.ts +4 -4
  196. package/src/s3/index.ts +1 -1
  197. package/src/schema/SchemaRegistry.ts +1 -1
  198. package/src/schema/createSchemaData.ts +1 -1
  199. package/src/schema/findJsonSchemaByPath.ts +1 -1
  200. package/src/schema/index.ts +5 -5
  201. package/src/schema/validate.ts +1 -1
  202. package/src/utils/buildRedactorFormSchema.ts +1 -1
  203. package/src/utils/formatNumber.ts +18 -0
  204. package/src/utils/formatPercent.ts +17 -0
  205. package/src/utils/index.ts +3 -3
  206. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,225 +1,202 @@
1
- import { basename, dirname, join, normalize } from "pathe";
2
- import { FileSystemError } from "./FileSystemError.js";
1
+ import { basename, dirname, join, normalize } from 'pathe';
2
+ import { FileSystemError } from './FileSystemError.js';
3
3
  export function createWebFileSystem(options) {
4
- return new WebFileSystem(options);
4
+ return new WebFileSystem(options);
5
5
  }
6
6
  let WebFileSystem = class WebFileSystem {
7
- root;
8
- constructor({ root }) {
9
- this.root = root;
10
- }
11
- async _getHandle(path) {
12
- const parts = normalize(path).split("/").filter(Boolean);
13
- if (parts.length === 0)
14
- return this.root;
15
- let current = this.root;
16
- for (let i = 0; i < parts.length; i++) {
17
- const part = parts[i];
18
- const isLast = i === parts.length - 1;
19
- try {
20
- // Try to get as directory first
21
- current = await current.getDirectoryHandle(part);
22
- }
23
- catch (e) {
24
- if (e.name === "TypeMismatchError" || e.name === "NotFoundError") {
25
- if (isLast) {
26
- // Might be a file
27
- try {
28
- return await current.getFileHandle(part);
29
- }
30
- catch (_e2) {
31
- throw new FileSystemError(`File not found: ${path}`, "ENOENT");
32
- }
33
- }
34
- }
35
- if (e.name === "NotFoundError") {
36
- throw new FileSystemError(`Path not found: ${path}`, "ENOENT");
37
- }
38
- throw e;
39
- }
40
- }
41
- return current;
42
- }
43
- async _getParent(path) {
44
- const normalized = normalize(path);
45
- const parentPath = dirname(normalized);
46
- const name = basename(normalized);
47
- if (!name)
48
- throw new FileSystemError("Invalid path", "EINVAL");
49
- const parentHandle = await this._getHandle(parentPath);
50
- if (parentHandle.kind !== "directory") {
51
- throw new FileSystemError(`Parent is not a directory: ${parentPath}`, "ENOTDIR");
52
- }
53
- return {
54
- parent: parentHandle,
55
- name
56
- };
57
- }
58
- async stat(path, options) {
59
- if (options?.signal?.aborted)
60
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
61
- const handle = await this._getHandle(path);
62
- return this._handleToStat(handle, path);
63
- }
64
- async _handleToStat(handle, path) {
65
- let size = 0;
66
- let mtime = 0;
67
- if (handle.kind === "file") {
68
- const file = await handle.getFile();
69
- size = file.size;
70
- mtime = file.lastModified;
71
- }
72
- return {
73
- path,
74
- directory: dirname(path),
75
- name: handle.name,
76
- kind: handle.kind,
77
- size,
78
- mtime,
79
- meta: {}
80
- };
81
- }
82
- async exists(path) {
83
- try {
84
- await this._getHandle(path);
85
- return true;
86
- }
87
- catch {
88
- return false;
89
- }
90
- }
91
- async readdir(path, options) {
92
- if (options?.signal?.aborted)
93
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
94
- const handle = await this._getHandle(path);
95
- if (handle.kind !== "directory") {
96
- throw new FileSystemError(`Not a directory: ${path}`, "ENOTDIR");
97
- }
98
- const entries = [];
99
- // @ts-expect-error - FileSystemDirectoryHandle is async iterable in modern browsers
100
- for await (const entry of handle.values()) {
101
- entries.push(await this._handleToStat(entry, join(path, entry.name)));
102
- }
103
- return entries;
104
- }
105
- async mkdir(path, options) {
106
- if (options?.signal?.aborted)
107
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
108
- const normalized = normalize(path);
109
- const parts = normalized.split("/").filter(Boolean);
110
- let current = this.root;
111
- if (options?.recursive) {
112
- for (const part of parts) {
113
- current = await current.getDirectoryHandle(part, {
114
- create: true
115
- });
116
- }
117
- }
118
- else {
119
- const parentPath = dirname(normalized);
120
- const name = basename(normalized);
121
- try {
122
- const parent = await this._getHandle(parentPath);
123
- if (parent.kind !== "directory")
124
- throw new FileSystemError(`Parent not a directory: ${parentPath}`, "ENOTDIR");
125
- await parent.getDirectoryHandle(name, {
126
- create: true
127
- });
128
- }
129
- catch (e) {
130
- if (e.code === "ENOENT" || e.name === "NotFoundError") {
131
- throw new FileSystemError(`Parent does not exist: ${parentPath}`, "ENOENT");
132
- }
133
- throw e;
134
- }
135
- }
136
- }
137
- async readFile(path, options) {
138
- if (options?.signal?.aborted)
139
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
140
- const handle = await this._getHandle(path);
141
- if (handle.kind !== "file")
142
- throw new FileSystemError(`Is a directory: ${path}`, "EISDIR");
143
- const file = await handle.getFile();
144
- if (options?.encoding === "text") {
145
- return await file.text();
146
- }
147
- else {
148
- const buffer = await file.arrayBuffer();
149
- return new Uint8Array(buffer);
150
- }
151
- }
152
- async writeFile(path, data, options) {
153
- if (options?.signal?.aborted)
154
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
155
- if (options?.overwrite === false) {
156
- if (await this.exists(path)) {
157
- throw new FileSystemError(`File already exists: ${path}`, "EEXIST");
158
- }
159
- }
160
- const { parent, name } = await this._getParent(path);
161
- const handle = await parent.getFileHandle(name, {
162
- create: true
163
- });
164
- const writable = await handle.createWritable();
165
- await writable.write(data);
166
- await writable.close();
167
- }
168
- async rm(path, options) {
169
- if (options?.signal?.aborted)
170
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
171
- const { parent, name } = await this._getParent(path);
172
- try {
173
- await parent.removeEntry(name, {
174
- recursive: options?.recursive
175
- });
176
- }
177
- catch (e) {
178
- if (e.name === "NotFoundError") {
179
- if (!options?.force)
180
- throw new FileSystemError(`File not found: ${path}`, "ENOENT");
181
- }
182
- else if (e.name === "InvalidModificationError") {
183
- throw new FileSystemError(`Directory not empty: ${path}`, "ENOTEMPTY");
184
- }
185
- else {
186
- throw e;
187
- }
188
- }
189
- }
190
- async rename(oldPath, newPath, options) {
191
- if (options?.signal?.aborted)
192
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
193
- // File System Access API doesn't support move/rename directly
194
- // Fallback to copy + delete
195
- await this.copy(oldPath, newPath, {
196
- overwrite: options?.overwrite
197
- });
198
- await this.rm(oldPath, {
199
- recursive: true
200
- });
201
- }
202
- async copy(src, dest, options) {
203
- if (options?.signal?.aborted)
204
- throw new FileSystemError("Operation aborted", "ABORT_ERR");
205
- const srcHandle = await this._getHandle(src);
206
- if (srcHandle.kind === "file") {
207
- const file = await srcHandle.getFile();
208
- await this.writeFile(dest, await file.arrayBuffer(), {
209
- overwrite: options?.overwrite
210
- });
211
- }
212
- else {
213
- // Directory copy
214
- await this.mkdir(dest);
215
- const entries = await this.readdir(src);
216
- for (const entry of entries) {
217
- await this.copy(entry.path, join(dest, entry.name), options);
218
- }
219
- }
220
- }
221
- getUrl(_file) {
222
- return undefined;
223
- }
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
+ }
224
201
  };
225
202
  //# sourceMappingURL=createWebFileSystem.js.map
@@ -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
package/lib/fs/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export { createSandboxFileSystem } from "./createSandboxFileSystem.js";
2
- export { createMemoryFileSystem } from "./createMemoryFileSystem.js";
3
- export { createBrowserFileSystem } from "./createBrowserFileSystem.js";
4
- export { createWebFileSystem } from "./createWebFileSystem.js";
5
- export { findMimeType } from "./findMimeType.js";
6
- export { FileUrlOptionsSchema } from "./types.js";
7
- export { FileSystemError, FileSystemErrorCode } from "./FileSystemError.js";
1
+ export { createBrowserFileSystem } from './createBrowserFileSystem.js';
2
+ export { createMemoryFileSystem } from './createMemoryFileSystem.js';
3
+ export { createSandboxFileSystem } from './createSandboxFileSystem.js';
4
+ export { createWebFileSystem } from './createWebFileSystem.js';
5
+ export { FileSystemError, FileSystemErrorCode } from './FileSystemError.js';
6
+ export { findMimeType } from './findMimeType.js';
7
+ export { FileUrlOptionsSchema } from './types.js';
8
8
  //# sourceMappingURL=index.js.map