minip-bridge 1.0.21 → 1.0.23

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 (2) hide show
  1. package/package.json +5 -1
  2. package/src/fs/common.ts +50 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minip-bridge",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "minip webview bridge",
5
5
  "main": "index.ts",
6
6
  "module": "./dist/index.mjs",
@@ -13,6 +13,10 @@
13
13
  "./kysely": {
14
14
  "import": "./dist/kysely/index.mjs",
15
15
  "types": "./dist/kysely/index.d.mts"
16
+ },
17
+ "./fs": {
18
+ "import": "./dist/fs/index.mjs",
19
+ "types": "./dist/fs/index.d.mts"
16
20
  }
17
21
  },
18
22
  "scripts": {
package/src/fs/common.ts CHANGED
@@ -1,20 +1,22 @@
1
1
  import jsBridge from "../bridge";
2
2
  import { MResponseWithData } from "../types";
3
- import { FileStats } from "../types/FileStats";
3
+ import { FileStats } from "../types/filestats";
4
4
 
5
5
  export async function access(path: string, mode?: number): Promise<void> {
6
- return jsBridge.callNative({
7
- api: "fsAccess",
8
- data: {
9
- path,
10
- mode
11
- }
12
- }).then(res => {
13
- const r = res as MResponseWithData<boolean>
14
- if (!r.hasData() || !r.data) {
15
- throw new Error(r.msg ?? "cannot access this file or directory")
16
- }
17
- });
6
+ return jsBridge
7
+ .callNative({
8
+ api: "fsAccess",
9
+ data: {
10
+ path,
11
+ mode,
12
+ },
13
+ })
14
+ .then((res) => {
15
+ const r = res as MResponseWithData<boolean>;
16
+ if (!r.hasData() || !r.data) {
17
+ throw new Error(r.msg ?? "cannot access this file or directory");
18
+ }
19
+ });
18
20
  }
19
21
 
20
22
  export function accessSync(path: string, mode?: number) {
@@ -22,11 +24,11 @@ export function accessSync(path: string, mode?: number) {
22
24
  api: "fsAccessSync",
23
25
  data: {
24
26
  path,
25
- mode
26
- }
27
- }) as MResponseWithData<boolean>
27
+ mode,
28
+ },
29
+ }) as MResponseWithData<boolean>;
28
30
  if (!res.hasData() || !res.data) {
29
- throw new Error(res.msg ?? "cannot access this file or directory")
31
+ throw new Error(res.msg ?? "cannot access this file or directory");
30
32
  }
31
33
  }
32
34
 
@@ -34,18 +36,18 @@ export async function unlink(path: string) {
34
36
  await jsBridge.callNative({
35
37
  api: "fsUnlink",
36
38
  data: {
37
- path
38
- }
39
- })
39
+ path,
40
+ },
41
+ });
40
42
  }
41
43
 
42
44
  export function unlinkSync(path: string) {
43
45
  jsBridge.callNativeSync({
44
46
  api: "fsUnlinkSync",
45
47
  data: {
46
- path
47
- }
48
- })
48
+ path,
49
+ },
50
+ });
49
51
  }
50
52
 
51
53
  export async function rename(oldPath: string, newPath: string) {
@@ -53,9 +55,9 @@ export async function rename(oldPath: string, newPath: string) {
53
55
  api: "fsRename",
54
56
  data: {
55
57
  oldPath,
56
- newPath
57
- }
58
- })
58
+ newPath,
59
+ },
60
+ });
59
61
  }
60
62
 
61
63
  export function renameSync(oldPath: string, newPath: string) {
@@ -63,21 +65,21 @@ export function renameSync(oldPath: string, newPath: string) {
63
65
  api: "fsRenameSync",
64
66
  data: {
65
67
  oldPath,
66
- newPath
67
- }
68
- })
68
+ newPath,
69
+ },
70
+ });
69
71
  }
70
72
 
71
73
  // todo: check !!!!!
72
74
  export async function stat(path: string) {
73
- const res = await jsBridge.callNative({
75
+ const res = (await jsBridge.callNative({
74
76
  api: "fsStat",
75
77
  data: {
76
- path
77
- }
78
- }) as MResponseWithData<FileStats>
78
+ path,
79
+ },
80
+ })) as MResponseWithData<FileStats>;
79
81
 
80
- const file = res.data
82
+ const file = res.data;
81
83
 
82
84
  file.atime = new Date(file.atimeMs);
83
85
  file.mtime = new Date(file.mtimeMs);
@@ -99,22 +101,23 @@ export async function stat(path: string) {
99
101
  return (this.mode & S_IFLNK) === S_IFLNK;
100
102
  };
101
103
 
102
- return file
104
+ return file;
103
105
  }
104
106
 
105
107
  export function statSync(path: string) {
106
108
  const res = jsBridge.callNativeSync({
107
109
  api: "fsStatSync",
108
110
  data: {
109
- path
110
- }
111
- }) as MResponseWithData<FileStats>
111
+ path,
112
+ },
113
+ }) as MResponseWithData<FileStats>;
112
114
 
113
- const file = res.data
115
+ const file = res.data;
114
116
 
115
117
  file.atime = new Date(file.atimeMs);
116
118
  file.mtime = new Date(file.mtimeMs);
117
119
  file.ctime = new Date(file.ctimeMs);
120
+ file.birthtime = new Date(file.birthtimeMs);
118
121
 
119
122
  const S_IFDIR = 0o040000;
120
123
  const S_IFREG = 0o100000;
@@ -132,23 +135,23 @@ export function statSync(path: string) {
132
135
  return (this.mode & S_IFLNK) === S_IFLNK;
133
136
  };
134
137
 
135
- return file
138
+ return file;
136
139
  }
137
140
 
138
141
  export async function rm(path: string) {
139
142
  await jsBridge.callNative({
140
143
  api: "fsRm",
141
144
  data: {
142
- path
143
- }
144
- })
145
+ path,
146
+ },
147
+ });
145
148
  }
146
149
 
147
150
  export function rmSync(path: string) {
148
151
  jsBridge.callNativeSync({
149
152
  api: "fsRmSync",
150
153
  data: {
151
- path
152
- }
153
- })
154
- }
154
+ path,
155
+ },
156
+ });
157
+ }