@functionland/react-native-fula 1.12.0 → 1.13.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,301 +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
- * Lists the cids that failed to be sent to backend and are kept only locally
85
- */
86
- export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
87
- return Fula.listFailedActions(cids);
88
- };
89
-
90
- /**
91
- * Checks if there are any un-synced changes on the device
92
- */
93
- export const checkConnection = (timeout: number = 20): Promise<boolean> => {
94
- return Fula.checkConnection(timeout);
95
- };
96
-
97
- /**
98
- * Get gets the value corresponding to the given key from the local datastore.
99
- // The key must be a valid ipld.Link.
100
- * @param key
101
- * @returns value
102
- */
103
- export const get = (key: string): Promise<string> => {
104
- return Fula.get(key);
105
- };
106
-
107
- /**
108
- * Has checks whether the value corresponding to the given key is present in the local datastore.
109
- // The key must be a valid ipld.Link.
110
- * @param key
111
- * @returns boolean
112
- */
113
- export const has = (key: Uint8Array): Promise<boolean> => {
114
- return Fula.has(key);
115
- };
116
-
117
- /**
118
- * Push requests the given addr to download the root cid from this node.
119
- // The addr must be a valid multiaddr that includes peer ID.
120
- // this function.
121
- * @param addr
122
- * @returns null or error
123
- */
124
- export const push = (): Promise<string> => {
125
- return Fula.push();
126
- };
127
-
128
- //This method sends some test data to backedn
129
- export const testData = (
130
- identity: string,
131
- bloxAddr: string
132
- ): Promise<string> => {
133
- return Fula.testData(identity, bloxAddr);
134
- };
135
-
136
- /**
137
- * Put stores the given key value onto the local datastore.
138
- // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
139
- // to the given key.
140
- * @param key, value
141
- * @returns null or string
142
- */
143
- export const put = (value: string, codec: string): Promise<string> => {
144
- return Fula.put(value, codec);
145
- };
146
-
147
- /**
148
- * mkdir creates a directory at the given path.
149
- * @param path
150
- * @returns string: new cid of the root
151
- */
152
- export const mkdir = (path: string): Promise<string> => {
153
- return Fula.mkdir(path);
154
- };
155
-
156
- /**
157
- * writeFileContent writes content at a given path
158
- * @param path
159
- * @returns string: new cid of the root
160
- */
161
- export const writeFileContent = (
162
- path: string,
163
- content: string
164
- ): Promise<string> => {
165
- return Fula.writeFileContent(path, content);
166
- };
167
-
168
- /*
169
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
170
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
171
- // It keeps the original file modiifcation date
172
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
173
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
174
- // Returns: new cid of the root after this file is placed in the tree
175
- */
176
- export const writeFile = (
177
- fulaTargetFilename: string,
178
- localFilename: string
179
- ): Promise<string> => {
180
- return Fula.writeFile(fulaTargetFilename, localFilename);
181
- };
182
-
183
- /**
184
- * ls lists the name of files and folders at a given path
185
- * @param path
186
- * @returns string: list of items
187
- * TODO: Findout how is the string and convert to array
188
- */
189
- export const ls = (path: string): Promise<void | JSON> => {
190
- return Fula.ls(path)
191
- .then((res) => {
192
- let lsResult = [];
193
- let lsRows = res.split('!!!');
194
- for (const element of lsRows) {
195
- let rowItems = element.split('???');
196
- if (rowItems && rowItems[0]) {
197
- let item = {
198
- name: '',
199
- created: '',
200
- modified: '',
201
- };
202
- item.name = rowItems[0];
203
- if (rowItems[1]) {
204
- item.created = rowItems[1];
205
- }
206
- if (rowItems[2]) {
207
- item.modified = rowItems[2];
208
- }
209
- lsResult.push(item);
210
- }
211
- }
212
- let jsonRes = JSON.parse(JSON.stringify(lsResult));
213
- return jsonRes;
214
- })
215
- .catch((e) => {
216
- return e;
217
- });
218
- };
219
-
220
- /**
221
- * rm removes all files and folders at a given path
222
- * @param path
223
- * @returns string: new cid of the root
224
- */
225
- export const rm = (path: string): Promise<string> => {
226
- return Fula.rm(path);
227
- };
228
-
229
- /**
230
- * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
231
- * @param sourcePath, targetPath
232
- * @returns string: new cid of the root
233
- */
234
- export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
235
- return Fula.cp(sourcePath, targetPath);
236
- };
237
-
238
- /**
239
- * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
240
- * @param sourcePath, targetPath
241
- * @returns string: new cid of the root
242
- */
243
- export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
244
- return Fula.mv(sourcePath, targetPath);
245
- };
246
-
247
- /*
248
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
249
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
250
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
251
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
252
- // Returns: new cid of the root after this file is placed in the tree
253
- */
254
- export const readFile = (
255
- fulaTargetFilename: string,
256
- localFilename: string
257
- ): Promise<string> => {
258
- return Fula.readFile(fulaTargetFilename, localFilename);
259
- };
260
-
261
- /**
262
- * readFile reads content of a given path
263
- * @param path
264
- * @returns string: cotent
265
- */
266
- export const readFileContent = (path: string): Promise<string> => {
267
- return Fula.readFileContent(path);
268
- };
269
-
270
- /**
271
- * Shutdown closes all resources used by Client.
272
- // After calling this function Client must be discarded.
273
- * @param
274
- * @returns
275
- */
276
- export const shutdown = (): Promise<void> => {
277
- return Fula.shutdown();
278
- };
279
-
280
- /**
281
- * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
282
- * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
283
- * @param peerId, allow
284
- * @returns boolean: true if successful or false if not
285
- */
286
- export const setAuth = (
287
- peerId: string,
288
- allow: boolean
289
- ): Promise<boolean> => {
290
- return Fula.setAuth(peerId, allow);
291
- };
292
-
293
-
294
- /**
295
- * isReady checks if the connection is ready to be used.
296
- * @param filesystemCheck: also check if the wnfs is ready
297
- * @returns boolean: true if ready or false if not
298
- */
299
- export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
300
- return Fula.isReady(filesystemCheck);
301
- };
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
+ };