This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
2349 lines (2067 loc) · 73.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for @maidsafe/safe-node-app 0.8.1
// Project: https://github.com/maidsafe/safe_app_nodejs
// Definitions by: Benno Zeeman <https://github.com/b-zee>
/// <reference types="node" />
// TODO: Update JSdoc to match
declare module '@maidsafe/safe-node-app/src/api/emulations/nfs' {
import { MutableData } from '@maidsafe/safe-node-app/src/api/mutable';
import { CONSTANTS } from '@maidsafe/safe-node-app';
/**
* A NFS-style NfsFile
*
* _Note_: As this application layer, the network does not check any of the
* metadata provided.
*/
class NfsFile {
constructor(ref: any);
/**
* XOR address of file's underlying {@link ImmutableData} data map
*/
dataMapName: Buffer;
/**
* Get metadata passed during file insertion of update
*/
userMetadata: Buffer;
/**
* Get UTC date of file context creation
*/
created: Date;
/**
* Get UTC date of file context modification
*/
modified: Date;
/**
* Get file size
*
* @example
* // Assumes {@link MutableData} interface has been obtained
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.create('<buffer or string>');
* const fileSize = await fileContext.size();
* } catch (err) {
* throw err;
* }
* };
*/
size(): Promise<number>;
/**
* Read the file.
* CONSTANTS.NFS_FILE_START and CONSTANTS.NFS_FILE_END may be used
* to read the entire content of the file. These constants are
* exposed by the safe-app-nodejs package.
*
* @throws {ERR_FILE_NOT_FOUND}
* @example
* // Assumes {@link MutableData} interface has been obtained
* const position = safe.CONSTANTS.NFS_FILE_START;
* const len = safe.CONSTANTS.NFS_FILE_END;
* const openMode = safe.CONSTANTS.NFS_FILE_MODE_READ;
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* let fileContext = await nfs.create('<buffer or string>');
* fileContext = await nfs.open(fileContext, openMode);
* const data = await fileContext.read(position, len);
* } catch (err) {
* throw err;
* }
* };
*/
read(position: number | CONSTANTS.MD_ENTRIES_EMPTY, len: number | CONSTANTS.NFS_FILE_END): Promise<[Buffer, number]>;
/**
* Write file. Does not commit file to network.
*
* @throws {ERR_FILE_NOT_FOUND}
* @example
* // Assumes {@link MutableData} interface has been obtained
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.open();
* await fileContext.write('<buffer or string>');
* } catch (err) {
* throw err;
* }
* };
*/
write(content: Buffer | string): Promise<void>;
/**
* Close file and commit to network.
*
* @throws {ERR_FILE_NOT_FOUND}
* @example
* // Assumes {@link MutableData} interface has been obtained
* const content = '<html><body><h1>WebSite</h1></body></html>';
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.open();
* await fileContext.write('<buffer or string>');
* await fileContext.close();
* } catch (err) {
* throw err;
* }
* };
*/
close(): Promise<void>;
/**
* Which version was this? Equals the underlying MutableData's entry version.
*/
version: number;
}
/**
* NFS emulation on top of a {@link MutableData}
*/
class NFS {
/**
* Instantiate the NFS emulation layer rapping a MutableData instance
*/
constructor(mData: MutableData);
/**
* Helper function to create and save file to the network
*
* @returns a newly created file
* @example
* // Assumes {@link MutableData} interface has been obtained
* const content = '<html><body><h1>WebSite</h1></body></html>';
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.create(content);
* } catch(err) {
* throw err;
* }
* };
*/
create(content: string | Buffer): Promise<NfsFile>;
/**
* Find the file of the given filename (aka keyName in the MutableData)
*
* @param fileName - the path/file name
* @returns the file found for that path
* @example
* // Assumes {@link MutableData} interface has been obtained
* const content = '<html><body><h1>WebSite</h1></body></html>';
* const asyncFn = async () => {
* const fileName = 'index.html';
* try {
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.create(content);
* await nfs.insert(fileName, fileContext);
* const fileContext = await nfs.fetch(fileName);
* } catch(err) {
* throw err;
* }
* };
*/
fetch(fileName: string): Promise<NfsFile>;
/**
* Insert the given file into the underlying {@link MutableData}, directly commit
* to the network.
*
* _Note_: As this application layer, the network does not check any
* of the metadata provided.
*
* @param fileName The path to store the file under
* @param file The file to serialise and store
* @param userMetadata
* @returns The same file
* @example
* // Assumes {@link MutableData} interface has been obtained
* const content = '<html><body><h1>WebSite</h1></body></html>';
* const userMetadata = 'text/html';
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* let fileContext = await nfs.create(content);
* const fileName = 'index.html';
* fileContext = await nfs.insert(fileName, fileContext, userMetadata);
* } catch(err) {
* throw err;
* }
* };
*/
insert(fileName: string | Buffer, file: NfsFile, userMetadata?: string | Buffer): Promise<NfsFile>;
/**
* Replace a path with a new file. Directly commit to the network.
*
* CONSTANTS.GET_NEXT_VERSION: Applies update to next file version.
*
* _Note_: As this application layer, the network does not check any
* of the metadata provided.
*
* @param fileName the path to store the file under
* @param file - the file to serialise and store
* @param version the version successor number
* @param userMetadata optional parameter for updating user metadata
* @returns the same file
* @example
* // Assumes {@link MutableData} interface has been obtained
* const content = '<html><body><h1>Updated WebSite</h1></body></html>';
* const userMetadata = 'text/html';
* const asyncFn = async () => {
* try {
* const version = safe.CONSTANTS.GET_NEXT_VERSION;
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.create(content);
* const fileName = 'index.html';
* fileContext = await nfs.update(fileName, fileContext, version + 1, userMetadata);
* } catch(err) {
* throw err;
* }
* };
*/
update(fileName: string | Buffer, file: NfsFile, version: number | CONSTANTS.GET_NEXT_VERSION, userMetadata: string | Buffer): Promise<NfsFile>;
/**
* Delete a file from path. Directly commit to the network.
*
* @param fileName
* @param version the version successor number
* @returns version of deleted file
* @example
* // Assumes {@link MutableData} interface has been obtained
* const content = '<html><body><h1>Updated WebSite</h1></body></html>';
* const fileName = 'index.html';
* const asyncFn = async () => {
* try {
* const version = await mData.getVersion();
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.create(content);
* fileContext = await nfs.insert(fileName, fileContext);
* const version = await nfs.delete(fileName, version + 1);
* } catch(err) {
* throw err;
* }
* };
*/
delete(fileName: string | Buffer, version: number): Promise<number>;
/**
* Open a file for reading or writing.
*
* Open modes (these constants are exported by the safe-app-nodejs package):
*
* CONSTANTS.NFS_FILE_MODE_OVERWRITE: Replaces the entire content of the file when writing data.
*
* CONSTANTS.NFS_FILE_MODE_APPEND: Appends to existing data in the file.
*
* CONSTANTS.NFS_FILE_MODE_READ: Open file to read.
*
* @param file If no {@link File} is passed, then a new instance is created in {@link CONSTANTS.NFS_FILE_MODE_OVERWRITE}
* @param openMode defaults to CONSTANTS.NFS_FILE_MODE_OVERWRITE
* @example
* // Assumes {@link MutableData} interface has been obtained
* const asyncFn = async () => {
* try {
* const nfs = await mData.emulateAs('NFS');
* const fileContext = await nfs.open();
* } catch(err) {
* throw err;
* }
* };
*/
open(file: NfsFile | undefined | null, openMode?: number | CONSTANTS.NFS_FILE_MODE_OVERWRITE | CONSTANTS.NFS_FILE_MODE_APPEND | CONSTANTS.NFS_FILE_MODE_READ): Promise<NfsFile>;
}
}
// TODO: FIX RDFLIB RETURN TYPES
declare module '@maidsafe/safe-node-app/src/api/emulations/rdf' {
import { MutableData, NameAndTag } from '@maidsafe/safe-node-app/src/api/mutable';
import { CONSTANTS } from '@maidsafe/safe-node-app';
/**
* RDF Emulation on top of a MutableData
*/
class RDF {
public mData: MutableData;
public graphStore: any;
public id: any;
public vocabs: any;
/**
* Instantiate the RDF emulation layer wrapping a MutableData instance
*
* @param mData the MutableData to wrap around
*/
constructor(mData: MutableData);
/**
* @param id
*/
setId(id: any): void;
/**
* @param ids list of id's to fetch e.g. ['safe://mywebid.mypubname', ...]
*/
nowOrWhenFetched(ids?: string[]): Promise<any>;
/**
* @param uri
*/
namespace(uri: any): any;
/**
* @param value Literal value
* @param languageOrDatatype Either i18n language tag or XSD URI data type
* @example
* // Assumes {@link MutableData} interface has been obtained
* const asyncFn = async () => {
* try {
* const rdf = await mData.emulateAs('RDF');
* const discoveryDate = new Date("18 Feb 1930");
* const dateTimeDataType = "http://www.w3.org/2001/XMLSchema#dateTime";
* let literalNode = rdf.literal(discoveryDate.toISOString(), dateTimeDataType);
* console.log( JSON.stringify(literalNode) );
*
* // Alternatively
* literalNode = rdf.literal("Aardvark", "en-US");
* console.log( JSON.stringify(literalNode) );
* } catch (err) {
* throw err;
* }
* };
*/
literal(value: string | number, languageOrDatatype?: string): any;
/**
* @param nodes
*/
collection(nodes: any): any;
bnode(): any;
/**
* @param uri
*/
sym(uri: any): any;
/**
* @param subject
* @param predicate
* @param object
*/
any(subject: any, predicate: any, object: any, provenance: any): any;
/**
* @param subject
* @param predicate
* @param object
*/
each(subject: any, predicate: any, object: any, provenance: any): any;
/**
* @param subject
* @param predicate
* @param object
*/
statementsMatching(subject: any, predicate: any, object: any, provenance: any): any;
/**
* @param subject
* @param predicate
* @param object
*/
removeMany(subject: any, predicate: any, object: any, provenance: any): any;
/**
* @param data
* @param mimeType
* @param id
*/
parse(data: any, mimeType: any, id: any, provenance: any): any;
/**
* @param subject
* @param predicate
* @param object
*/
add(subject: any, predicate: any, object: any, provenance: any): any;
/**
* @param mimeType
*/
serialise(mimeType: any): Promise<unknown>;
/**
* Commit the RDF document to the underlying MutableData on the network
*
* @param toEncrypt
*/
commit(toEncrypt?: boolean): Promise<NameAndTag>;
/**
* Append the triples to the RDF document into the underlying MutableData on the network
*/
append(): Promise<NameAndTag>;
}
}
declare module '@maidsafe/safe-node-app/src/api/emulations/web_id' {
import { MutableData } from '@maidsafe/safe-node-app/src/api/mutable';
import { RDF } from '@maidsafe/safe-node-app/src/api/emulations/rdf';
/**
* WebID Emulation on top of a MutableData using RDF emulation
*/
class WebID {
public mData: MutableData;
public rdf: RDF;
public vocabs: any;
/**
* Instantiate the WebID emulation layer wrapping a MutableData instance,
* while making use of the RDF emulation to manipulate the MD entries
*
* @param mData the MutableData to wrap around
*/
constructor(mData: MutableData);
/**
* Initialises WebID interface by emulating underlying {@link MutableData}
* as RDF and sets common namespace prefixes on instance
*/
init(): void;
/**
* Fetches committed WebId data from underlying MutableData and loads in graph store
*
* @example
* // Assumes {@link MutableData} interface has been obtained
* const asyncFn = async () => {
* try {
* const webid = await mData.emulateAs('WebId');
* await webid.fetchContent();
* } catch(err) {
* throw err;
* }
* };
*/
fetchContent(): Promise<any>;
/**
* Creates WebId as RDF data and commits to underlying MutableData
*
* @param profile
* @param nick profile.nick
* @example
* // Assumes {@link MutableData} interface has been obtained
* const profile = {
* nick: "safedev",
* name: "SAFENetwork Developer",
* uri: "safe://id.safedev"
* };
* const asyncFn = async () => {
* try {
* const webid = await mData.emulateAs('WebId');
* await webid.create(profile, profile.nick);
* } catch(err) {
* throw err;
* }
* };
*/
create(profile: any, displayName?: string): Promise<any>;
/**
* Updates WebId as RDF data and commits to underlying MutableData
*
* @example
* // Assumes {@link MutableData} interface has been obtained
* const profile = {
* nick: "safedev",
* name: "SAFENetwork Developer",
* uri: "safe://id.safedev"
* };
* const asyncFn = async () => {
* try {
* const webid = await mData.emulateAs('WebId');
* await webid.create(profile, profile.nick);
* let updatedProfile = Object.assign({}, profile, { name: "Alexander Fleming" });
* await webid.update(profile);
* } catch(err) {
* throw err;
* }
* };
*/
update(profile: any): Promise<any>;
/**
* Serialises WebId RDF data
*
* @returns RDF document according to mime type
* @example
* // Assumes {@link MutableData} interface has been obtained
* const mimeType = "text/turtle";
* const profile = {
* nick: "safedev",
* name: "SAFENetwork Developer",
* uri: "safe://id.safedev"
* };
* const asyncFn = async () => {
* try {
* const webid = await mData.emulateAs('WebId');
* await webid.create(profile, profile.nick);
* const serialised = await webid.serialise(mimeType);
* } catch(err) {
* throw err;
* }
* };
*/
serialise(mimeType: string): Promise<string>;
}
}
declare module '@maidsafe/safe-node-app/src/api/cipher_opt' {
import { PubEncKey } from '@maidsafe/safe-node-app/src/api/crypto';
/**
* Holds the reference to a Cipher Options, either PlainText, Symmetric or Asymmetric
*/
export class CipherOpt { }
/**
* Provides encryption methods for committing {@link ImmutableData}
*/
export class CipherOptInterface {
/**
* Create a plaintext cipher
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* const cipherOpt = await app.cipherOpt.newPlainText();
* const immdWriter = await app.immutableData.create();
* await idWriter.write('<public file buffer data>');
* const idAddress = await idWriter.close(cipherOpt);
* };
*/
newPlainText(): Promise<CipherOpt>;
/**
* Create a new symmetric cipher
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* const cipherOpt = await app.cipherOpt.newSymmetric();
* const immdWriter = await app.immutableData.create();
* await idWriter.write('Data for my eyes only.');
* const idAddress = await idWriter.close(cipherOpt);
* };
*/
newSymmetric(): Promise<CipherOpt>;
/**
* Create a new Asymmetric Cipher for the given public encryption key
* @param pubEncKey
* @throws {MISSING_PUB_ENC_KEY}
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* // For this example you're encrypting data with our own public encryption key,
* // which only you will be able to deciper, however,
* // the use case is for encrypting with the intended recipient's public encryption key.
* const pubEncKey = await app.crypto.getAppPubEncKey();
* const cipherOpt = await app.cipherOpt.newAsymmetric(pubEncKey);
* const immdWriter = await app.immutableData.create();
* const data = 'Data only decipherable by the holder of the private encryption key
* which is paired to the public encryption key supplied to asymmetric cipher.';
* await idWriter.write(data);
* const idAddress = await idWriter.close(cipherOpt);
* };
*/
newAsymmetric(pubEncKey: PubEncKey): Promise<CipherOpt>;
}
}
declare module '@maidsafe/safe-node-app/src/web_fetch' {
import { MutableData } from '@maidsafe/safe-node-app/src/api/mutable';
/**
* holds additional options for the `webFetch` function.
*/
interface WebFetchOptions {
/**
* range of bytes to be retrieved.
* The `start` attribute is expected to be the start offset, while the `end`
* attribute of the `range` object the end position (both inclusive) to be
* retrieved, e.g. with `range: { start: 2, end: 3 }` the 3rd and 4th bytes
* of data will be retrieved. If `end` is not specified, the bytes retrived
* will be from the `start` offset untill the end of the file. The ranges
* values are also used to populate the `Content-Range` and `Content-Length`
* headers in the response.
*/
range: { start: number, end: number };
}
/**
* holds information about a network resource fetched from a `safe://`-URL
*/
interface NetworkResource {
/**
* the network resource object
*/
content: MutableData;
/**
* the type of the resource fetched, e.g. 'NFS'
*/
resourceType: string;
/**
* the parsed path from the provided URL
*/
parsedPath: any;
/**
* Undocumented property. (@b-zee)
*/
mimeType: string;
}
}
declare module '@maidsafe/safe-node-app/src/app' {
import { AuthInterface } from '@maidsafe/safe-node-app/src/api/auth';
import { CryptoInterface } from '@maidsafe/safe-node-app/src/api/crypto';
import { CipherOptInterface } from '@maidsafe/safe-node-app/src/api/cipher_opt';
import { ImmutableDataInterface } from '@maidsafe/safe-node-app/src/api/immutable';
import { MutableDataInterface } from '@maidsafe/safe-node-app/src/api/mutable';
import { WebInterface } from '@maidsafe/safe-node-app/src/api/web';
import { WebFetchOptions, NetworkResource } from '@maidsafe/safe-node-app/src/web_fetch';
import { AppInfo, InitOptions } from '@maidsafe/safe-node-app';
/**
* Holds the information about the account.
*/
interface AccountInfo {
/**
* number of mutations performed with this account
*/
mutations_done: number;
/**
* number of remaining mutations allowed for this account
*/
mutations_available: number;
}
/**
* Holds one sessions with the network and is the primary interface to interact
* with the network. As such it also provides all API-Providers connected through
* this session.
*/
class SAFEApp {
/**
* get the AuthInterface instance connected to this session
*/
auth: AuthInterface;
/**
* get the Crypto instance connected to this session
*/
crypto: CryptoInterface;
/**
* get the CipherOptInterface instance connected to this session
*/
cipherOpt: CipherOptInterface;
/**
* get the ImmutableDataInterface instance connected to this session
*/
immutableData: ImmutableDataInterface;
/**
* get the MutableDataInterface instance connected to this session
*/
mutableData: MutableDataInterface;
/**
* Manage Web RDF Data.
*/
web: WebInterface;
/**
* Helper to lookup a given `safe://`-url in accordance with the convention
* and find the requested object.
*
* @param url the url you want to fetch
* @param options additional options
* @returns the object with body of content and headers
*/
webFetch(url: string, options?: WebFetchOptions): Promise<{ body: string, headers: any }>;
/**
* Experimental function to lookup a given `safe://`-URL in accordance with the
* public name resolution and find the requested network resource.
*
* @param url the url you want to fetch
* @returns the network resource found from the passed URL
*/
fetch(url: string): Promise<NetworkResource>;
/**
* Returns true if current network connection state is INIT.
* This is state means the library has been initialised but there is no
* connection made with the network yet.
*/
isNetStateInit(): boolean;
/**
* Returns true if current network connection state is CONNECTED.
*/
isNetStateConnected(): boolean;
/**
* Returns true if current network connection state is DISCONNECTED.
*/
isNetStateDisconnected(): boolean;
/**
* The current appInfo
*/
appInfo: AppInfo;
/**
* Generate the log path for the provided filename. If the filename provided
* is null, it then returns the path of where the safe_core log file is
* located.
*
* @param logFilename optional log filename to generate the path
*/
logPath(logFilename?: string): Promise<String>;
/**
* Returns account information, e.g. number of mutations done and available.
*/
getAccountInfo(): Promise<AccountInfo>;
/**
* Create a SAFEApp and try to login it through the `authUri`
*
* @param appInfo the AppInfo
* @param authUri URI containing the authentication info
* @param networkStateCallBack optional callback function to receive network state updates
* @param initialisation options
* @returns authenticated and connected SAFEApp
*/
static fromAuthUri(appInfo: AppInfo, authUri: string, networkStateCallBack?: () => any, initialisation?: InitOptions): Promise<SAFEApp>;
/**
* Returns the name of the app's own container.
*/
getOwnContainerName(): Promise<string>;
/**
* Reconnect to the metwork
* Must be invoked when the client decides to connect back after the connection was lost.
*/
reconnect(): void;
/**
* Resets the object cache kept by the underlyging library.
*/
clearanyCache(): void;
/**
* @returns true if the underlyging library was compiled against mock-routing.
*/
appIsMock(): boolean;
}
}
declare module '@maidsafe/safe-node-app/src/api/immutable' {
import { CipherOpt } from '@maidsafe/safe-node-app/src/api/cipher_opt';
import { SAFEApp } from '@maidsafe/safe-node-app/src/app';
/**
* {@link ImmutableDataInterface} reader
*/
class Reader {
/**
* Holds the connection to read an existing ImmutableData
*/
constructor();
/**
* Read the given amount of bytes from the network
*
* @param options [options.offset=0] start position. [options.end=size] end position or end of data.
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* const readOptions =
* {
* offset: 0, // starts reading from this byte position
* end: null // ends reading at this byte position
* };
* try {
* const iDataReader = await app.immutableData.fetch(iDataAddress)
* const data = await iDataReader.read(readOptions)
* } catch(err) {
* throw err;
* }
* };
*/
read(options?: { offset: number, end: number }): Promise<Buffer>;
/**
* The size of the immutable data on the network
* @returns length in bytes
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* try {
* const size = await iDataReader.size()
* } catch(err) {
* throw err;
* }
* };
*/
size(): Promise<number>;
/**
* Get the XOR-URL of the {@link ImmutableDataInterface}.
*
* @param mimeType (experimental) the MIME type to encode in the XOR-URL as
* the codec of the content
* @returns The XOR-URL of the ImmutableData.
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* try {
* const cipherOpt = await app.cipherOpt.newPlainText();
* const iDataWriter = await app.immutableData.create()
* const data = `Most proteins are glycosylated.
* Mass spectrometry methods are used for mapping glycoprotein.`;
* await iDataWriter.write(data);
* const iDataAddress = await iDataWriter.close(cipherOpt);
* const idReader = await app.immutableData.fetch(iDataAddress);
* const mimeType = 'text/plain';
* const xorUrl = idReader.getXorUrl(mimeType);
* } catch(err) {
* throw err;
* }
* };
*/
getXorUrl(mimeType: string): string;
}
/**
* Holds an Immutable Data Writer
*/
class Writer {
/**
* Append the given data to {@link ImmutableDataInterface}. This does not commit data to network.
*
* @param data The string or buffer to write
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* try {
* const iDataWriter = await app.immutableData.create()
* const data = `Most proteins are glycosylated.
* Mass spectrometry methods are used for mapping glycoprotein.`;
* await iDataWriter.write(data);
* } catch(err) {
* throw err;
* }
* };
*/
write(data: string | Buffer): Promise<void>;
/**
* Close and commit the {@link ImmutableDataInterface} to the network.
*
* @param cipherOpt The cipher method with which to encrypt data
* @param getXorUrl (experimental) if the XOR-URL shall also be returned along with the xor address
* @param mimeType (experimental) the MIME type to encode in the XOR-URL as the codec of the content
* @returns The XOR address to the data once written to the network, or an object that contains both the XOR address and XOR URL.
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* try {
* const cipherOpt = await app.cipherOpt.newPlainText();
* const iDataWriter = await app.immutableData.create()
* const data = `Most proteins are glycosylated.
* Mass spectrometry methods are used for mapping glycoprotein.`;
* await iDataWriter.write(data);
* const iDataAddress = await iDataWriter.close(cipherOpt);
*
* // Alternatively:
* // const getXorUrl = true;
* // const mimeType = 'text/plain';
* // const iDataMeta = await iDataWriter.close(cipherOpt, getXorUrl, mimeType);
* } catch(err) {
* throw err;
* }
* };
*/
close(cipherOpt: CipherOpt, getXorUrl?: boolean, mimeType?: string): Promise<Buffer | { name: Buffer, xorUrl: String }>;
}
/**
* Interact with Immutable Data of the Network through this Interface.
*
* Access it through your {SAFEApp} instance under `app.immutableData`
*/
class ImmutableDataInterface {
/**
* Interact with Immutable Data of the Network through this Interface.
*
* Access it through your {SAFEApp} instance under `app.immutableData`
*/
constructor(app: SAFEApp);
/**
* Create a new {@link ImmutableDataInterface} writer
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* try {
* const iDataWriter = await app.immutableData.create()
* } catch(err) {
* throw err;
* }
* };
*/
create(): Promise<Writer>;
/**
* Look up an existing {@link ImmutableDataInterface} for the given address
*
* @param address XOR address
* @example
* // Assumes {@link initialiseApp|SAFEApp} interface has been obtained
* const asyncFn = async () => {
* try {
* const iDataReader = await app.immutableData.fetch(iDataAddress);
* } catch(err) {
* throw err;
* }
* };
*/
fetch(address: Buffer): Promise<Reader>;
}
}
declare module '@maidsafe/safe-node-app/src/api/mutable' {
import { CONSTANTS } from '@maidsafe/safe-node-app';
import { SAFEApp } from '@maidsafe/safe-node-app/src/app';
import { PubSignKey } from '@maidsafe/safe-node-app/src/api/crypto';
import { NFS } from '@maidsafe/safe-node-app/src/api/emulations/nfs';
import { RDF } from '@maidsafe/safe-node-app/src/api/emulations/rdf';
import { WebID } from '@maidsafe/safe-node-app/src/api/emulations/web_id';
/**
* Holds the permissions of a MutableData object
*/
class Permissions {
/**
* Total number of permission entries
*
* @returns number of entries
*/
len(): Promise<number>;
/**
* Lookup the permissions of a specifc key
*
* @param signKey The key to lookup for. Defaults to USER_ANYONE.
* @returns the permission set for that key
*/
getPermissionSet(signKey?: PubSignKey | CONSTANTS.USER_ANYONE): Promise<any>;