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
- // Create IPFS instance
27
- this.initIPFSInstance = () => __awaiter(this, void 0, void 0, function* () {
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/O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CAAC,GAAG,CAAC,CAAA;QACvC,CAAC;KAAA;CACJ;AAED,eAAe,0BAA0B,CAAA"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "opportunity-service",
3
- "version": "0.0.601",
3
+ "version": "0.0.605",
4
4
  "description": "A service layer that connects all services between the blockchain and ui.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- this.initIPFSInstance()
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