@tauri-apps/plugin-fs 2.0.0-alpha.2 → 2.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,84 @@
1
- var f$1=Object.defineProperty;var g$1=(a,b)=>{for(var c in b)f$1(a,c,{get:b[c],enumerable:!0});};var e=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$1=(a,b,c)=>(e(a,b,"read from private field"),c?c.call(a):b.get(a)),i$1=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j$1=(a,b,c,d)=>(e(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
1
+ /******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+ /* global Reflect, Promise, SuppressedError, Symbol */
16
+
17
+
18
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
19
+ var e = new Error(message);
20
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
21
+ };
2
22
 
3
- var T$1={};g$1(T$1,{Channel:()=>i,PluginListener:()=>o,addPluginListener:()=>l$1,convertFileSrc:()=>v$1,invoke:()=>u$1,transformCallback:()=>_$1});function _$1(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}var r,i=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$1(this,r,()=>{});this.id=_$1(n=>{h$1(this,r).call(this,n);});}set onmessage(n){j$1(this,r,n);}get onmessage(){return h$1(this,r)}toJSON(){return `__CHANNEL__:${this.id}`}};r=new WeakMap;var o=class{constructor(n,s,t){this.plugin=n,this.event=s,this.channelId=t;}async unregister(){return u$1(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l$1(e,n,s){let t=new i;return t.onmessage=s,u$1(`plugin:${e}|register_listener`,{event:n,handler:t}).then(()=>new o(e,n,t.id))}async function u$1(e,n={},s){return window.__TAURI_INTERNALS__.invoke(e,n,s)}function v$1(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}
23
+ /**
24
+ * Sends a message to the backend.
25
+ * @example
26
+ * ```typescript
27
+ * import { invoke } from '@tauri-apps/api/primitives';
28
+ * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
29
+ * ```
30
+ *
31
+ * @param cmd The command name.
32
+ * @param args The optional arguments to pass to the command.
33
+ * @param options The request options.
34
+ * @return A promise resolving or rejecting to the backend response.
35
+ *
36
+ * @since 1.0.0
37
+ */
38
+ async function invoke(cmd, args = {}, options) {
39
+ return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
40
+ }
4
41
 
5
- var U={};g$1(U,{BaseDirectory:()=>t,appCacheDir:()=>p,appConfigDir:()=>s,appDataDir:()=>u,appLocalDataDir:()=>c,appLogDir:()=>w,audioDir:()=>a,basename:()=>H,cacheDir:()=>l,configDir:()=>g,dataDir:()=>d,delimiter:()=>E,desktopDir:()=>m,dirname:()=>z,documentDir:()=>y,downloadDir:()=>h,executableDir:()=>f,extname:()=>F,fontDir:()=>P,homeDir:()=>_,isAbsolute:()=>S,join:()=>j,localDataDir:()=>v,normalize:()=>N,pictureDir:()=>A,publicDir:()=>D,resolve:()=>I,resolveResource:()=>C,resourceDir:()=>b,runtimeDir:()=>L,sep:()=>k,tempDir:()=>x,templateDir:()=>R,videoDir:()=>T});var t=(r=>(r[r.Audio=1]="Audio",r[r.Cache=2]="Cache",r[r.Config=3]="Config",r[r.Data=4]="Data",r[r.LocalData=5]="LocalData",r[r.Document=6]="Document",r[r.Download=7]="Download",r[r.Picture=8]="Picture",r[r.Public=9]="Public",r[r.Video=10]="Video",r[r.Resource=11]="Resource",r[r.Temp=12]="Temp",r[r.AppConfig=13]="AppConfig",r[r.AppData=14]="AppData",r[r.AppLocalData=15]="AppLocalData",r[r.AppCache=16]="AppCache",r[r.AppLog=17]="AppLog",r[r.Desktop=18]="Desktop",r[r.Executable=19]="Executable",r[r.Font=20]="Font",r[r.Home=21]="Home",r[r.Runtime=22]="Runtime",r[r.Template=23]="Template",r))(t||{});async function s(){return u$1("plugin:path|resolve_directory",{directory:13})}async function u(){return u$1("plugin:path|resolve_directory",{directory:14})}async function c(){return u$1("plugin:path|resolve_directory",{directory:15})}async function p(){return u$1("plugin:path|resolve_directory",{directory:16})}async function a(){return u$1("plugin:path|resolve_directory",{directory:1})}async function l(){return u$1("plugin:path|resolve_directory",{directory:2})}async function g(){return u$1("plugin:path|resolve_directory",{directory:3})}async function d(){return u$1("plugin:path|resolve_directory",{directory:4})}async function m(){return u$1("plugin:path|resolve_directory",{directory:18})}async function y(){return u$1("plugin:path|resolve_directory",{directory:6})}async function h(){return u$1("plugin:path|resolve_directory",{directory:7})}async function f(){return u$1("plugin:path|resolve_directory",{directory:19})}async function P(){return u$1("plugin:path|resolve_directory",{directory:20})}async function _(){return u$1("plugin:path|resolve_directory",{directory:21})}async function v(){return u$1("plugin:path|resolve_directory",{directory:5})}async function A(){return u$1("plugin:path|resolve_directory",{directory:8})}async function D(){return u$1("plugin:path|resolve_directory",{directory:9})}async function b(){return u$1("plugin:path|resolve_directory",{directory:11})}async function C(i){return u$1("plugin:path|resolve_directory",{directory:11,path:i})}async function L(){return u$1("plugin:path|resolve_directory",{directory:22})}async function R(){return u$1("plugin:path|resolve_directory",{directory:23})}async function T(){return u$1("plugin:path|resolve_directory",{directory:10})}async function w(){return u$1("plugin:path|resolve_directory",{directory:17})}async function x(i){return u$1("plugin:path|resolve_directory",{directory:12})}function k(){return window.__TAURI_INTERNALS__.plugins.path.sep}function E(){return window.__TAURI_INTERNALS__.plugins.path.delimiter}async function I(...i){return u$1("plugin:path|resolve",{paths:i})}async function N(i){return u$1("plugin:path|normalize",{path:i})}async function j(...i){return u$1("plugin:path|join",{paths:i})}async function z(i){return u$1("plugin:path|dirname",{path:i})}async function F(i){return u$1("plugin:path|extname",{path:i})}async function H(i,e){return u$1("plugin:path|basename",{path:i,ext:e})}async function S(i){return u$1("plugin:path|isAbsolute",{path:i})}
42
+ // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
43
+ // SPDX-License-Identifier: Apache-2.0
44
+ // SPDX-License-Identifier: MIT
45
+ /**
46
+ * The path module provides utilities for working with file and directory paths.
47
+ *
48
+ * This package is also accessible with `window.__TAURI__.path` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
49
+ *
50
+ * It is recommended to allowlist only the APIs you use for optimal bundle size and security.
51
+ * @module
52
+ */
53
+ /**
54
+ * @since 2.0.0
55
+ */
56
+ var BaseDirectory;
57
+ (function (BaseDirectory) {
58
+ BaseDirectory[BaseDirectory["Audio"] = 1] = "Audio";
59
+ BaseDirectory[BaseDirectory["Cache"] = 2] = "Cache";
60
+ BaseDirectory[BaseDirectory["Config"] = 3] = "Config";
61
+ BaseDirectory[BaseDirectory["Data"] = 4] = "Data";
62
+ BaseDirectory[BaseDirectory["LocalData"] = 5] = "LocalData";
63
+ BaseDirectory[BaseDirectory["Document"] = 6] = "Document";
64
+ BaseDirectory[BaseDirectory["Download"] = 7] = "Download";
65
+ BaseDirectory[BaseDirectory["Picture"] = 8] = "Picture";
66
+ BaseDirectory[BaseDirectory["Public"] = 9] = "Public";
67
+ BaseDirectory[BaseDirectory["Video"] = 10] = "Video";
68
+ BaseDirectory[BaseDirectory["Resource"] = 11] = "Resource";
69
+ BaseDirectory[BaseDirectory["Temp"] = 12] = "Temp";
70
+ BaseDirectory[BaseDirectory["AppConfig"] = 13] = "AppConfig";
71
+ BaseDirectory[BaseDirectory["AppData"] = 14] = "AppData";
72
+ BaseDirectory[BaseDirectory["AppLocalData"] = 15] = "AppLocalData";
73
+ BaseDirectory[BaseDirectory["AppCache"] = 16] = "AppCache";
74
+ BaseDirectory[BaseDirectory["AppLog"] = 17] = "AppLog";
75
+ BaseDirectory[BaseDirectory["Desktop"] = 18] = "Desktop";
76
+ BaseDirectory[BaseDirectory["Executable"] = 19] = "Executable";
77
+ BaseDirectory[BaseDirectory["Font"] = 20] = "Font";
78
+ BaseDirectory[BaseDirectory["Home"] = 21] = "Home";
79
+ BaseDirectory[BaseDirectory["Runtime"] = 22] = "Runtime";
80
+ BaseDirectory[BaseDirectory["Template"] = 23] = "Template";
81
+ })(BaseDirectory || (BaseDirectory = {}));
6
82
 
7
83
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
8
84
  // SPDX-License-Identifier: Apache-2.0
@@ -61,7 +137,7 @@ var U={};g$1(U,{BaseDirectory:()=>t,appCacheDir:()=>p,appConfigDir:()=>s,appData
61
137
  * @since 2.0.0
62
138
  */
63
139
  async function readTextFile(filePath, options = {}) {
64
- return await u$1("plugin:fs|read_text_file", {
140
+ return await invoke("plugin:fs|read_text_file", {
65
141
  path: filePath,
66
142
  options,
67
143
  });
@@ -78,7 +154,7 @@ async function readTextFile(filePath, options = {}) {
78
154
  * @since 2.0.0
79
155
  */
80
156
  async function readBinaryFile(filePath, options = {}) {
81
- const arr = await u$1("plugin:fs|read_file", {
157
+ const arr = await invoke("plugin:fs|read_file", {
82
158
  path: filePath,
83
159
  options,
84
160
  });
@@ -113,7 +189,7 @@ async function writeTextFile(path, contents, options) {
113
189
  else {
114
190
  fileOptions = contents;
115
191
  }
116
- return await u$1("plugin:fs|write_file", {
192
+ return await invoke("plugin:fs|write_file", {
117
193
  path: file.path,
118
194
  contents: Array.from(new TextEncoder().encode(file.contents)),
119
195
  options: fileOptions,
@@ -149,7 +225,7 @@ async function writeBinaryFile(path, contents, options) {
149
225
  // @ts-expect-error in this case `contents` is always a BinaryFileContents
150
226
  file.contents = contents !== null && contents !== void 0 ? contents : [];
151
227
  }
152
- return await u$1("plugin:fs|write_file", {
228
+ return await invoke("plugin:fs|write_file", {
153
229
  path: file.path,
154
230
  contents: Array.from(file.contents instanceof ArrayBuffer
155
231
  ? new Uint8Array(file.contents)
@@ -178,7 +254,7 @@ async function writeBinaryFile(path, contents, options) {
178
254
  * @since 2.0.0
179
255
  */
180
256
  async function readDir(dir, options = {}) {
181
- return await u$1("plugin:fs|read_dir", {
257
+ return await invoke("plugin:fs|read_dir", {
182
258
  path: dir,
183
259
  options,
184
260
  });
@@ -199,7 +275,7 @@ async function readDir(dir, options = {}) {
199
275
  * @since 2.0.0
200
276
  */
201
277
  async function createDir(dir, options = {}) {
202
- return await u$1("plugin:fs|create_dir", {
278
+ return await invoke("plugin:fs|create_dir", {
203
279
  path: dir,
204
280
  options,
205
281
  });
@@ -219,7 +295,7 @@ async function createDir(dir, options = {}) {
219
295
  * @since 2.0.0
220
296
  */
221
297
  async function removeDir(dir, options = {}) {
222
- return await u$1("plugin:fs|remove_dir", {
298
+ return await invoke("plugin:fs|remove_dir", {
223
299
  path: dir,
224
300
  options,
225
301
  });
@@ -238,7 +314,7 @@ async function removeDir(dir, options = {}) {
238
314
  * @since 2.0.0
239
315
  */
240
316
  async function copyFile(source, destination, options = {}) {
241
- return await u$1("plugin:fs|copy_file", {
317
+ return await invoke("plugin:fs|copy_file", {
242
318
  source,
243
319
  destination,
244
320
  options,
@@ -258,7 +334,7 @@ async function copyFile(source, destination, options = {}) {
258
334
  * @since 2.0.0
259
335
  */
260
336
  async function removeFile(file, options = {}) {
261
- return await u$1("plugin:fs|remove_file", {
337
+ return await invoke("plugin:fs|remove_file", {
262
338
  path: file,
263
339
  options,
264
340
  });
@@ -277,7 +353,7 @@ async function removeFile(file, options = {}) {
277
353
  * @since 2.0.0
278
354
  */
279
355
  async function renameFile(oldPath, newPath, options = {}) {
280
- return await u$1("plugin:fs|rename_file", {
356
+ return await invoke("plugin:fs|rename_file", {
281
357
  oldPath,
282
358
  newPath,
283
359
  options,
@@ -295,7 +371,7 @@ async function renameFile(oldPath, newPath, options = {}) {
295
371
  * @since 2.0.0
296
372
  */
297
373
  async function exists(path) {
298
- return await u$1("plugin:fs|exists", { path });
374
+ return await invoke("plugin:fs|exists", { path });
299
375
  }
300
376
  /**
301
377
  * Returns the metadata for the given path.
@@ -303,7 +379,7 @@ async function exists(path) {
303
379
  * @since 2.0.0
304
380
  */
305
381
  async function metadata(path) {
306
- return await u$1("plugin:fs|metadata", {
382
+ return await invoke("plugin:fs|metadata", {
307
383
  path,
308
384
  }).then((metadata) => {
309
385
  const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
@@ -316,5 +392,5 @@ async function metadata(path) {
316
392
  });
317
393
  }
318
394
 
319
- export { t as BaseDirectory, t as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
395
+ export { BaseDirectory, BaseDirectory as Dir, copyFile, createDir, exists, metadata, readBinaryFile, readDir, readTextFile, removeDir, removeFile, renameFile, writeBinaryFile, writeTextFile as writeFile, writeTextFile };
320
396
  //# sourceMappingURL=index.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-fs",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Access the file system.",
5
5
  "license": "MIT or APACHE-2.0",
6
6
  "authors": [
@@ -25,7 +25,7 @@
25
25
  "tslib": "^2.4.1"
26
26
  },
27
27
  "dependencies": {
28
- "@tauri-apps/api": "2.0.0-alpha.9"
28
+ "@tauri-apps/api": "2.0.0-alpha.11"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "rollup -c"