@functionland/react-native-fula 1.9.0 → 1.12.1

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,286 +1,314 @@
1
- import Fula from '../interfaces/fulaNativeModule';
2
-
3
- /**
4
- * Get gets the value corresponding to the given key from the local datastore.
5
- // The key must be a valid ipld.Link.
6
- * @param config
7
- * @returns boolean
8
- */
9
-
10
- export const init = (
11
- identity: string, //privateKey of did identity
12
- storePath: string,
13
- bloxAddr: string,
14
- exchange: string,
15
- autoFlush: boolean = false,
16
- rootCid: string | null = null,
17
- useRelay: boolean = true,
18
- refresh: boolean = false
19
- ): Promise<{ peerId: string; rootCid: string; private_ref: string }> => {
20
- console.log(
21
- 'init in react-native started',
22
- identity,
23
- storePath,
24
- bloxAddr,
25
- exchange,
26
- autoFlush,
27
- useRelay
28
- );
29
- return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay, refresh);
30
- };
31
-
32
- /**
33
- * Get gets the value corresponding to the given key from the local datastore.
34
- // The key must be a valid ipld.Link.
35
- * @param config
36
- * @returns boolean
37
- */
38
-
39
- export const newClient = (
40
- identity: string, //privateKey of did identity
41
- storePath: string,
42
- bloxAddr: string,
43
- exchange: string,
44
- autoFlush: boolean = false,
45
- useRelay: boolean = true,
46
- refresh: boolean = false
47
- ): Promise<string> => {
48
- console.log(
49
- 'newClient in react-native started',
50
- identity,
51
- storePath,
52
- bloxAddr,
53
- exchange,
54
- autoFlush,
55
- useRelay,
56
- refresh
57
- );
58
- return Fula.newClient(identity, storePath, bloxAddr, exchange, autoFlush, useRelay, refresh);
59
- };
60
-
61
- /**
62
- * rm removes all data
63
- * @param path
64
- * @returns string: new cid of the root
65
- */
66
- export const logout = (
67
- identity: string,
68
- storePath: string
69
- ): Promise<boolean> => {
70
- return Fula.logout(identity, storePath);
71
- };
72
-
73
- /**
74
- * Checks if there are any un-synced changes on the device
75
- */
76
- export const checkFailedActions = (
77
- retry: boolean = false,
78
- timeout: number = 20
79
- ): Promise<boolean> => {
80
- return Fula.checkFailedActions(retry, timeout);
81
- };
82
-
83
- /**
84
- * Checks if there are any un-synced changes on the device
85
- */
86
- export const checkConnection = (timeout: number = 20): Promise<boolean> => {
87
- return Fula.checkConnection(timeout);
88
- };
89
-
90
- /**
91
- * Get gets the value corresponding to the given key from the local datastore.
92
- // The key must be a valid ipld.Link.
93
- * @param key
94
- * @returns value
95
- */
96
- export const get = (key: string): Promise<string> => {
97
- return Fula.get(key);
98
- };
99
-
100
- /**
101
- * Has checks whether the value corresponding to the given key is present in the local datastore.
102
- // The key must be a valid ipld.Link.
103
- * @param key
104
- * @returns boolean
105
- */
106
- export const has = (key: Uint8Array): Promise<boolean> => {
107
- return Fula.has(key);
108
- };
109
-
110
- /**
111
- * Push requests the given addr to download the root cid from this node.
112
- // The addr must be a valid multiaddr that includes peer ID.
113
- // this function.
114
- * @param addr
115
- * @returns null or error
116
- */
117
- export const push = (): Promise<string> => {
118
- return Fula.push();
119
- };
120
-
121
- /**
122
- * Put stores the given key value onto the local datastore.
123
- // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
124
- // to the given key.
125
- * @param key, value
126
- * @returns null or string
127
- */
128
- export const put = (value: string, codec: string): Promise<string> => {
129
- return Fula.put(value, codec);
130
- };
131
-
132
- /**
133
- * mkdir creates a directory at the given path.
134
- * @param path
135
- * @returns string: new cid of the root
136
- */
137
- export const mkdir = (path: string): Promise<string> => {
138
- return Fula.mkdir(path);
139
- };
140
-
141
- /**
142
- * writeFileContent writes content at a given path
143
- * @param path
144
- * @returns string: new cid of the root
145
- */
146
- export const writeFileContent = (
147
- path: string,
148
- content: string
149
- ): Promise<string> => {
150
- return Fula.writeFileContent(path, content);
151
- };
152
-
153
- /*
154
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
155
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
156
- // It keeps the original file modiifcation date
157
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
158
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
159
- // Returns: new cid of the root after this file is placed in the tree
160
- */
161
- export const writeFile = (
162
- fulaTargetFilename: string,
163
- localFilename: string
164
- ): Promise<string> => {
165
- return Fula.writeFile(fulaTargetFilename, localFilename);
166
- };
167
-
168
- /**
169
- * ls lists the name of files and folders at a given path
170
- * @param path
171
- * @returns string: list of items
172
- * TODO: Findout how is the string and convert to array
173
- */
174
- export const ls = (path: string): Promise<void | JSON> => {
175
- return Fula.ls(path)
176
- .then((res) => {
177
- let lsResult = [];
178
- let lsRows = res.split('!!!');
179
- for (const element of lsRows) {
180
- let rowItems = element.split('???');
181
- if (rowItems && rowItems[0]) {
182
- let item = {
183
- name: '',
184
- created: '',
185
- modified: '',
186
- };
187
- item.name = rowItems[0];
188
- if (rowItems[1]) {
189
- item.created = rowItems[1];
190
- }
191
- if (rowItems[2]) {
192
- item.modified = rowItems[2];
193
- }
194
- lsResult.push(item);
195
- }
196
- }
197
- let jsonRes = JSON.parse(JSON.stringify(lsResult));
198
- return jsonRes;
199
- })
200
- .catch((e) => {
201
- return e;
202
- });
203
- };
204
-
205
- /**
206
- * rm removes all files and folders at a given path
207
- * @param path
208
- * @returns string: new cid of the root
209
- */
210
- export const rm = (path: string): Promise<string> => {
211
- return Fula.rm(path);
212
- };
213
-
214
- /**
215
- * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
216
- * @param sourcePath, targetPath
217
- * @returns string: new cid of the root
218
- */
219
- export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
220
- return Fula.cp(sourcePath, targetPath);
221
- };
222
-
223
- /**
224
- * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
225
- * @param sourcePath, targetPath
226
- * @returns string: new cid of the root
227
- */
228
- export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
229
- return Fula.mv(sourcePath, targetPath);
230
- };
231
-
232
- /*
233
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
234
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
235
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
236
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
237
- // Returns: new cid of the root after this file is placed in the tree
238
- */
239
- export const readFile = (
240
- fulaTargetFilename: string,
241
- localFilename: string
242
- ): Promise<string> => {
243
- return Fula.readFile(fulaTargetFilename, localFilename);
244
- };
245
-
246
- /**
247
- * readFile reads content of a given path
248
- * @param path
249
- * @returns string: cotent
250
- */
251
- export const readFileContent = (path: string): Promise<string> => {
252
- return Fula.readFileContent(path);
253
- };
254
-
255
- /**
256
- * Shutdown closes all resources used by Client.
257
- // After calling this function Client must be discarded.
258
- * @param
259
- * @returns
260
- */
261
- export const shutdown = (): Promise<void> => {
262
- return Fula.shutdown();
263
- };
264
-
265
- /**
266
- * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
267
- * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
268
- * @param peerId, allow
269
- * @returns boolean: true if successful or false if not
270
- */
271
- export const setAuth = (
272
- peerId: string,
273
- allow: boolean
274
- ): Promise<boolean> => {
275
- return Fula.setAuth(peerId, allow);
276
- };
277
-
278
-
279
- /**
280
- * isReady checks if the connection is ready to be used.
281
- * @param filesystemCheck: also check if the wnfs is ready
282
- * @returns boolean: true if ready or false if not
283
- */
284
- export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
285
- return Fula.isReady(filesystemCheck);
286
- };
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+
3
+ /**
4
+ * Get gets the value corresponding to the given key from the local datastore.
5
+ // The key must be a valid ipld.Link.
6
+ * @param config
7
+ * @returns boolean
8
+ */
9
+
10
+ export const init = (
11
+ identity: string, //privateKey of did identity
12
+ storePath: string,
13
+ bloxAddr: string,
14
+ exchange: string,
15
+ autoFlush: boolean = false,
16
+ rootCid: string | null = null,
17
+ useRelay: boolean = true,
18
+ refresh: boolean = false
19
+ ): Promise<{ peerId: string; rootCid: string }> => {
20
+ console.log(
21
+ 'init in react-native started',
22
+ identity,
23
+ storePath,
24
+ bloxAddr,
25
+ exchange,
26
+ autoFlush,
27
+ useRelay
28
+ );
29
+ return Fula.init(
30
+ identity,
31
+ storePath,
32
+ bloxAddr,
33
+ exchange,
34
+ autoFlush,
35
+ rootCid,
36
+ useRelay,
37
+ refresh
38
+ );
39
+ };
40
+
41
+ /**
42
+ * Get gets the value corresponding to the given key from the local datastore.
43
+ // The key must be a valid ipld.Link.
44
+ * @param config
45
+ * @returns boolean
46
+ */
47
+
48
+ export const newClient = (
49
+ identity: string, //privateKey of did identity
50
+ storePath: string,
51
+ bloxAddr: string,
52
+ exchange: string,
53
+ autoFlush: boolean = false,
54
+ useRelay: boolean = true,
55
+ refresh: boolean = false
56
+ ): Promise<string> => {
57
+ console.log(
58
+ 'newClient in react-native started',
59
+ identity,
60
+ storePath,
61
+ bloxAddr,
62
+ exchange,
63
+ autoFlush,
64
+ useRelay,
65
+ refresh
66
+ );
67
+ return Fula.newClient(
68
+ identity,
69
+ storePath,
70
+ bloxAddr,
71
+ exchange,
72
+ autoFlush,
73
+ useRelay,
74
+ refresh
75
+ );
76
+ };
77
+
78
+ /**
79
+ * rm removes all data
80
+ * @param path
81
+ * @returns string: new cid of the root
82
+ */
83
+ export const logout = (
84
+ identity: string,
85
+ storePath: string
86
+ ): Promise<boolean> => {
87
+ return Fula.logout(identity, storePath);
88
+ };
89
+
90
+ /**
91
+ * Checks if there are any un-synced changes on the device
92
+ */
93
+ export const checkFailedActions = (
94
+ retry: boolean = false,
95
+ timeout: number = 20
96
+ ): Promise<boolean> => {
97
+ return Fula.checkFailedActions(retry, timeout);
98
+ };
99
+
100
+ /**
101
+ * Lists the cids that failed to be sent to backend and are kept only locally
102
+ */
103
+ export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
104
+ return Fula.listFailedActions(cids);
105
+ };
106
+
107
+ /**
108
+ * Checks if there are any un-synced changes on the device
109
+ */
110
+ export const checkConnection = (timeout: number = 20): Promise<boolean> => {
111
+ return Fula.checkConnection(timeout);
112
+ };
113
+
114
+ /**
115
+ * Get gets the value corresponding to the given key from the local datastore.
116
+ // The key must be a valid ipld.Link.
117
+ * @param key
118
+ * @returns value
119
+ */
120
+ export const get = (key: string): Promise<string> => {
121
+ return Fula.get(key);
122
+ };
123
+
124
+ /**
125
+ * Has checks whether the value corresponding to the given key is present in the local datastore.
126
+ // The key must be a valid ipld.Link.
127
+ * @param key
128
+ * @returns boolean
129
+ */
130
+ export const has = (key: Uint8Array): Promise<boolean> => {
131
+ return Fula.has(key);
132
+ };
133
+
134
+ /**
135
+ * Push requests the given addr to download the root cid from this node.
136
+ // The addr must be a valid multiaddr that includes peer ID.
137
+ // this function.
138
+ * @param addr
139
+ * @returns null or error
140
+ */
141
+ export const push = (): Promise<string> => {
142
+ return Fula.push();
143
+ };
144
+
145
+ //This method sends some test data to backedn
146
+ export const testData = (
147
+ identity: string,
148
+ bloxAddr: string
149
+ ): Promise<string> => {
150
+ return Fula.testData(identity, bloxAddr);
151
+ };
152
+
153
+ /**
154
+ * Put stores the given key value onto the local datastore.
155
+ // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
156
+ // to the given key.
157
+ * @param key, value
158
+ * @returns null or string
159
+ */
160
+ export const put = (value: string, codec: string): Promise<string> => {
161
+ return Fula.put(value, codec);
162
+ };
163
+
164
+ /**
165
+ * mkdir creates a directory at the given path.
166
+ * @param path
167
+ * @returns string: new cid of the root
168
+ */
169
+ export const mkdir = (path: string): Promise<string> => {
170
+ return Fula.mkdir(path);
171
+ };
172
+
173
+ /**
174
+ * writeFileContent writes content at a given path
175
+ * @param path
176
+ * @returns string: new cid of the root
177
+ */
178
+ export const writeFileContent = (
179
+ path: string,
180
+ content: string
181
+ ): Promise<string> => {
182
+ return Fula.writeFileContent(path, content);
183
+ };
184
+
185
+ /*
186
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
187
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
188
+ // It keeps the original file modiifcation date
189
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
190
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
191
+ // Returns: new cid of the root after this file is placed in the tree
192
+ */
193
+ export const writeFile = (
194
+ fulaTargetFilename: string,
195
+ localFilename: string
196
+ ): Promise<string> => {
197
+ return Fula.writeFile(fulaTargetFilename, localFilename);
198
+ };
199
+
200
+ /**
201
+ * ls lists the name of files and folders at a given path
202
+ * @param path
203
+ * @returns string: list of items
204
+ * TODO: Findout how is the string and convert to array
205
+ */
206
+ export const ls = (path: string): Promise<void | JSON> => {
207
+ return Fula.ls(path)
208
+ .then((res) => {
209
+ let lsResult = [];
210
+ let lsRows = res.split('!!!');
211
+ for (const element of lsRows) {
212
+ let rowItems = element.split('???');
213
+ if (rowItems && rowItems[0]) {
214
+ let item = {
215
+ name: '',
216
+ created: '',
217
+ modified: '',
218
+ };
219
+ item.name = rowItems[0];
220
+ if (rowItems[1]) {
221
+ item.created = rowItems[1];
222
+ }
223
+ if (rowItems[2]) {
224
+ item.modified = rowItems[2];
225
+ }
226
+ lsResult.push(item);
227
+ }
228
+ }
229
+ let jsonRes = JSON.parse(JSON.stringify(lsResult));
230
+ return jsonRes;
231
+ })
232
+ .catch((e) => {
233
+ return e;
234
+ });
235
+ };
236
+
237
+ /**
238
+ * rm removes all files and folders at a given path
239
+ * @param path
240
+ * @returns string: new cid of the root
241
+ */
242
+ export const rm = (path: string): Promise<string> => {
243
+ return Fula.rm(path);
244
+ };
245
+
246
+ /**
247
+ * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
248
+ * @param sourcePath, targetPath
249
+ * @returns string: new cid of the root
250
+ */
251
+ export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
252
+ return Fula.cp(sourcePath, targetPath);
253
+ };
254
+
255
+ /**
256
+ * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
257
+ * @param sourcePath, targetPath
258
+ * @returns string: new cid of the root
259
+ */
260
+ export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
261
+ return Fula.mv(sourcePath, targetPath);
262
+ };
263
+
264
+ /*
265
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
266
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
267
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
268
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
269
+ // Returns: new cid of the root after this file is placed in the tree
270
+ */
271
+ export const readFile = (
272
+ fulaTargetFilename: string,
273
+ localFilename: string
274
+ ): Promise<string> => {
275
+ return Fula.readFile(fulaTargetFilename, localFilename);
276
+ };
277
+
278
+ /**
279
+ * readFile reads content of a given path
280
+ * @param path
281
+ * @returns string: cotent
282
+ */
283
+ export const readFileContent = (path: string): Promise<string> => {
284
+ return Fula.readFileContent(path);
285
+ };
286
+
287
+ /**
288
+ * Shutdown closes all resources used by Client.
289
+ // After calling this function Client must be discarded.
290
+ * @param
291
+ * @returns
292
+ */
293
+ export const shutdown = (): Promise<void> => {
294
+ return Fula.shutdown();
295
+ };
296
+
297
+ /**
298
+ * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
299
+ * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
300
+ * @param peerId, allow
301
+ * @returns boolean: true if successful or false if not
302
+ */
303
+ export const setAuth = (peerId: string, allow: boolean): Promise<boolean> => {
304
+ return Fula.setAuth(peerId, allow);
305
+ };
306
+
307
+ /**
308
+ * isReady checks if the connection is ready to be used.
309
+ * @param filesystemCheck: also check if the wnfs is ready
310
+ * @returns boolean: true if ready or false if not
311
+ */
312
+ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
313
+ return Fula.isReady(filesystemCheck);
314
+ };