opportunity-service 0.0.601 → 0.0.605
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,11 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
const IPFS = require('ipfs');
|
11
2
|
const OrbitDB = require('orbit-db');
|
12
|
-
const Identities = require('orbit-db-identity-provider');
|
13
|
-
const options = { id: 'local-id' };
|
14
3
|
const operations = ['>', '<', '==', '>=', '<='];
|
15
4
|
const optionsToWrite = {
|
16
5
|
// Give write access to the creator of the database
|
17
6
|
accessController: {
|
18
7
|
type: 'orbitdb',
|
8
|
+
create: 'true',
|
19
9
|
admin: ['*'],
|
20
10
|
write: ['*'],
|
21
11
|
},
|
@@ -23,102 +13,8 @@ const optionsToWrite = {
|
|
23
13
|
};
|
24
14
|
class OpportunityStorageProvider {
|
25
15
|
constructor(address) {
|
26
|
-
//
|
27
|
-
this.
|
28
|
-
return yield IPFS.create({
|
29
|
-
repo: Math.random().toString(),
|
30
|
-
start: true,
|
31
|
-
preload: {
|
32
|
-
enabled: false,
|
33
|
-
},
|
34
|
-
EXPERIMENTAL: { pubsub: true },
|
35
|
-
});
|
36
|
-
});
|
37
|
-
this.initIPFSInstance();
|
38
|
-
this.listen(address);
|
39
|
-
}
|
40
|
-
listen(address = '') {
|
41
|
-
this.initIPFSInstance().then((ipfs) => __awaiter(this, void 0, void 0, function* () {
|
42
|
-
var _a, _b;
|
43
|
-
const orbitdb = yield OrbitDB.createInstance(ipfs);
|
44
|
-
// Create / Open a database
|
45
|
-
if (address == '') {
|
46
|
-
this.db = yield orbitdb.docs('database.default');
|
47
|
-
console.log(this.db);
|
48
|
-
console.log(this.db.address);
|
49
|
-
}
|
50
|
-
else {
|
51
|
-
if (!((_a = this.db) === null || _a === void 0 ? void 0 : _a.dbname) || ((_b = this.db) === null || _b === void 0 ? void 0 : _b.dbname) == '') {
|
52
|
-
console.log('Connecting orbitdb to: ' + address);
|
53
|
-
this.db = yield orbitdb.docs(address, {
|
54
|
-
accessController: {
|
55
|
-
type: 'orbitdb',
|
56
|
-
admin: ['*'],
|
57
|
-
write: ['*']
|
58
|
-
},
|
59
|
-
indexBy: 'collection'
|
60
|
-
});
|
61
|
-
//await this.db.load();
|
62
|
-
}
|
63
|
-
console.log(this.db);
|
64
|
-
}
|
65
|
-
// Listen for updates from peers
|
66
|
-
this.db.events.on("replicated", address => {
|
67
|
-
console.log(this.db.iterator({ limit: -1 }).collect());
|
68
|
-
});
|
69
|
-
// Add an entry
|
70
|
-
const hash = yield this.db.put({ _id: 0, collection: "hmm" });
|
71
|
-
console.log(hash);
|
72
|
-
// Query
|
73
|
-
const result = this.db.iterator({ limit: -1 }).collect();
|
74
|
-
console.log(JSON.stringify(result, null, 2));
|
75
|
-
}));
|
76
|
-
}
|
77
|
-
/**
|
78
|
-
* Returns a Promise that resolves to the multihash of the entry as a String.
|
79
|
-
* @param doc
|
80
|
-
* @returns
|
81
|
-
*/
|
82
|
-
store(doc) {
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
84
|
-
try {
|
85
|
-
const hash = yield this.db.put(doc).then(hash => {
|
86
|
-
return hash;
|
87
|
-
});
|
88
|
-
return hash;
|
89
|
-
}
|
90
|
-
catch (error) {
|
91
|
-
console.log(error);
|
92
|
-
return '';
|
93
|
-
}
|
94
|
-
});
|
95
|
-
}
|
96
|
-
/**
|
97
|
-
* Returns an Array of all Objects that match the given key in their _id field or the field specified by indexBy. If no document with
|
98
|
-
* that key exists, this returns an empty array.
|
99
|
-
* @param key
|
100
|
-
*/
|
101
|
-
retrieveDoc(key = '', collection) {
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
103
|
-
try {
|
104
|
-
const docs = yield this.db.get(key);
|
105
|
-
return docs;
|
106
|
-
}
|
107
|
-
catch (error) {
|
108
|
-
console.log(error);
|
109
|
-
return [];
|
110
|
-
}
|
111
|
-
});
|
112
|
-
}
|
113
|
-
retrieveDocsByCollection(collection) {
|
114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
115
|
-
return yield this.db.query((doc) => doc[collection] == collection);
|
116
|
-
});
|
117
|
-
}
|
118
|
-
deleteDoc(key) {
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
120
|
-
const hash = yield this.db.del(key);
|
121
|
-
});
|
16
|
+
// this.initIPFSInstance()
|
17
|
+
//this.listen(address)
|
122
18
|
}
|
123
19
|
}
|
124
20
|
export default OpportunityStorageProvider;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"OpportunityStorageProvider.js","sourceRoot":"","sources":["../../../src/modules/storage/OpportunityStorageProvider.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"OpportunityStorageProvider.js","sourceRoot":"","sources":["../../../src/modules/storage/OpportunityStorageProvider.ts"],"names":[],"mappings":"AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAQnC,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAE/C,MAAM,cAAc,GAAG;IACnB,mDAAmD;IACnD,gBAAgB,EAAE;QAChB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,KAAK,EAAE,CAAC,GAAG,CAAC;KACb;IACD,OAAO,EAAE,YAAY;CACxB,CAAA;AAGD,MAAM,0BAA0B;IAG5B,YAAY,OAAe;QACxB,0BAA0B;QACzB,sBAAsB;IAC1B,CAAC;CA0FJ;AAED,eAAe,0BAA0B,CAAA"}
|
package/package.json
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
const IPFS = require('ipfs')
|
2
2
|
const OrbitDB = require('orbit-db')
|
3
|
-
const Identities = require('orbit-db-identity-provider')
|
4
|
-
const options = { id: 'local-id'}
|
5
3
|
|
6
4
|
import {
|
7
5
|
DisputeDoc,
|
@@ -15,6 +13,7 @@ const optionsToWrite = {
|
|
15
13
|
// Give write access to the creator of the database
|
16
14
|
accessController: {
|
17
15
|
type: 'orbitdb', //OrbitDBAccessController
|
16
|
+
create: 'true',
|
18
17
|
admin: ['*'],
|
19
18
|
write: ['*'],
|
20
19
|
},
|
@@ -26,10 +25,10 @@ class OpportunityStorageProvider {
|
|
26
25
|
private db: any
|
27
26
|
|
28
27
|
constructor(address: string) {
|
29
|
-
|
30
|
-
this.listen(address)
|
28
|
+
// this.initIPFSInstance()
|
29
|
+
//this.listen(address)
|
31
30
|
}
|
32
|
-
|
31
|
+
/*
|
33
32
|
|
34
33
|
// Create IPFS instance
|
35
34
|
initIPFSInstance = async () => {
|
@@ -56,13 +55,14 @@ class OpportunityStorageProvider {
|
|
56
55
|
|
57
56
|
if (!this.db?.dbname || this.db?.dbname == '') {
|
58
57
|
console.log('Connecting orbitdb to: ' + address)
|
58
|
+
|
59
59
|
this.db = await orbitdb.docs(address, {
|
60
|
+
type: 'docstore',
|
60
61
|
accessController: {
|
61
|
-
type: 'orbitdb',
|
62
62
|
admin: ['*'],
|
63
63
|
write: ['*']
|
64
|
-
|
65
|
-
indexBy: 'collection'
|
64
|
+
},
|
65
|
+
//indexBy: 'collection'
|
66
66
|
})
|
67
67
|
|
68
68
|
//await this.db.load();
|
@@ -86,11 +86,7 @@ class OpportunityStorageProvider {
|
|
86
86
|
}
|
87
87
|
|
88
88
|
|
89
|
-
|
90
|
-
* Returns a Promise that resolves to the multihash of the entry as a String.
|
91
|
-
* @param doc
|
92
|
-
* @returns
|
93
|
-
*/
|
89
|
+
|
94
90
|
async store(doc: DisputeDoc | WorkRelationshipDoc | UserSummaryDoc): Promise<string> {
|
95
91
|
try {
|
96
92
|
const hash = await this.db.put(doc).then(hash => {
|
@@ -104,11 +100,6 @@ class OpportunityStorageProvider {
|
|
104
100
|
}
|
105
101
|
}
|
106
102
|
|
107
|
-
/**
|
108
|
-
* Returns an Array of all Objects that match the given key in their _id field or the field specified by indexBy. If no document with
|
109
|
-
* that key exists, this returns an empty array.
|
110
|
-
* @param key
|
111
|
-
*/
|
112
103
|
async retrieveDoc(key: string = '', collection: string): Promise<DisputeDoc> | Promise<WorkRelationshipDoc> | Promise<UserSummaryDoc> {
|
113
104
|
try {
|
114
105
|
const docs = await this.db.get(key)
|
@@ -125,7 +116,7 @@ class OpportunityStorageProvider {
|
|
125
116
|
|
126
117
|
async deleteDoc(key: string) {
|
127
118
|
const hash = await this.db.del(key)
|
128
|
-
}
|
119
|
+
}*/
|
129
120
|
}
|
130
121
|
|
131
122
|
export default OpportunityStorageProvider
|