@leofcoin/peernet 1.1.76 → 1.1.77

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.
@@ -71,7 +71,7 @@ export default class Peernet {
71
71
  get selectedAccount(): string;
72
72
  get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
73
73
  get defaultStores(): string[];
74
- selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
74
+ selectAccount(account: string): Promise<void> | Promise<any[]>;
75
75
  addProto(name: any, proto: any): void;
76
76
  addCodec(codec: any): void;
77
77
  addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
@@ -131,12 +131,12 @@ export default class Peernet {
131
131
  providersFor(hash: string, store?: undefined): Promise<import("./dht/dht.js").DHTProviderMapValue>;
132
132
  get block(): {
133
133
  get: (hash: string) => Promise<any>;
134
- put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
134
+ put: (hash: string, data: Uint8Array) => Promise<void | any[]>;
135
135
  has: (hash: string) => Promise<boolean | any[]>;
136
136
  };
137
137
  get transaction(): {
138
138
  get: (hash: string) => Promise<any>;
139
- put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
139
+ put: (hash: string, data: Uint8Array) => Promise<void | any[]>;
140
140
  has: (hash: string) => Promise<boolean | any[]>;
141
141
  };
142
142
  requestData(hash: any, store: any): any;
@@ -153,7 +153,7 @@ export default class Peernet {
153
153
  * @param {String} hash
154
154
  * @param {Buffer} message
155
155
  */
156
- put: (hash: any, message: any) => Promise<void | any[] | IDBValidKey>;
156
+ put: (hash: any, message: any) => Promise<void | any[]>;
157
157
  /**
158
158
  * @param {String} hash
159
159
  * @return {Boolean}
@@ -173,7 +173,7 @@ export default class Peernet {
173
173
  * @param {String} hash
174
174
  * @param {Buffer} data
175
175
  */
176
- put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
176
+ put: (hash: any, data: any) => Promise<void | any[]>;
177
177
  /**
178
178
  * @param {String} hash
179
179
  * @return {Boolean}
@@ -193,7 +193,7 @@ export default class Peernet {
193
193
  * @param {String} hash
194
194
  * @param {Buffer} data
195
195
  */
196
- put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
196
+ put: (hash: any, data: any) => Promise<void | any[]>;
197
197
  /**
198
198
  * @param {String} hash
199
199
  * @return {Boolean}
@@ -223,7 +223,7 @@ export default class Peernet {
223
223
  * @param {Buffer} data
224
224
  * @param {String} storeName - storeName to access
225
225
  */
226
- put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<void | any[] | IDBValidKey>;
226
+ put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<void | any[]>;
227
227
  /**
228
228
  * @param {String} hash
229
229
  * @return {Boolean}
@@ -1,2 +1,2 @@
1
- export { P as default } from './peernet-haqFwGMk.js';
1
+ export { P as default } from './peernet-dyeDQR4X.js';
2
2
  import './value-wzPYMxsX.js';
package/exports/store.js CHANGED
@@ -1,6 +1,4 @@
1
1
  import { join } from 'path';
2
- import { homedir } from 'os';
3
- import { readdir, mkdir } from 'fs/promises';
4
2
  import { ClassicLevel } from 'classic-level';
5
3
 
6
4
  const encode = (string) => {
@@ -75,17 +73,22 @@ class KeyValue {
75
73
  }
76
74
  }
77
75
 
76
+ globalThis.process?.versions?.node ? false : true;
78
77
  const init = async (root, home = true) => {
79
78
  let _root = root;
80
- if (home)
79
+ const join = (await import('path')).join;
80
+ if (home) {
81
+ const homedir = (await import('os')).homedir;
81
82
  _root = join(homedir(), root);
82
- if (readdir)
83
- try {
84
- await readdir(_root);
85
- }
86
- catch (e) {
87
- await mkdir(_root, { recursive: true });
88
- }
83
+ }
84
+ const readdir = (await import('fs/promises')).readdir;
85
+ try {
86
+ await readdir(_root);
87
+ }
88
+ catch (e) {
89
+ const mkdir = (await import('fs/promises')).mkdir;
90
+ await mkdir(_root, { recursive: true });
91
+ }
89
92
  return _root;
90
93
  };
91
94
 
@@ -115,6 +118,15 @@ class Store {
115
118
  ? new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / Uint8Array.BYTES_PER_ELEMENT)
116
119
  : buffer;
117
120
  }
121
+ async has(key) {
122
+ try {
123
+ await this.get(key);
124
+ return true;
125
+ }
126
+ catch (error) {
127
+ return false;
128
+ }
129
+ }
118
130
  async get(key) {
119
131
  return this.toUint8Array(await this.db.get(this.toKeyPath(key)));
120
132
  }
@@ -8,7 +8,7 @@ export default class Identity {
8
8
  get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
9
9
  getAccounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
10
10
  load(password?: string): Promise<void>;
11
- selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
11
+ selectAccount(account: string): Promise<void> | Promise<any[]>;
12
12
  sign(hash: Uint8Array): any;
13
13
  lock(password: string): void;
14
14
  unlock(password: string): void;
@@ -71,7 +71,7 @@ export default class Peernet {
71
71
  get selectedAccount(): string;
72
72
  get accounts(): Promise<[[name: string, externalAddress: string, internalAddress: string]]>;
73
73
  get defaultStores(): string[];
74
- selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
74
+ selectAccount(account: string): Promise<void> | Promise<any[]>;
75
75
  addProto(name: any, proto: any): void;
76
76
  addCodec(codec: any): void;
77
77
  addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
@@ -131,12 +131,12 @@ export default class Peernet {
131
131
  providersFor(hash: string, store?: undefined): Promise<import("./dht/dht.js").DHTProviderMapValue>;
132
132
  get block(): {
133
133
  get: (hash: string) => Promise<any>;
134
- put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
134
+ put: (hash: string, data: Uint8Array) => Promise<void | any[]>;
135
135
  has: (hash: string) => Promise<boolean | any[]>;
136
136
  };
137
137
  get transaction(): {
138
138
  get: (hash: string) => Promise<any>;
139
- put: (hash: string, data: Uint8Array) => Promise<void | any[] | IDBValidKey>;
139
+ put: (hash: string, data: Uint8Array) => Promise<void | any[]>;
140
140
  has: (hash: string) => Promise<boolean | any[]>;
141
141
  };
142
142
  requestData(hash: any, store: any): any;
@@ -153,7 +153,7 @@ export default class Peernet {
153
153
  * @param {String} hash
154
154
  * @param {Buffer} message
155
155
  */
156
- put: (hash: any, message: any) => Promise<void | any[] | IDBValidKey>;
156
+ put: (hash: any, message: any) => Promise<void | any[]>;
157
157
  /**
158
158
  * @param {String} hash
159
159
  * @return {Boolean}
@@ -173,7 +173,7 @@ export default class Peernet {
173
173
  * @param {String} hash
174
174
  * @param {Buffer} data
175
175
  */
176
- put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
176
+ put: (hash: any, data: any) => Promise<void | any[]>;
177
177
  /**
178
178
  * @param {String} hash
179
179
  * @return {Boolean}
@@ -193,7 +193,7 @@ export default class Peernet {
193
193
  * @param {String} hash
194
194
  * @param {Buffer} data
195
195
  */
196
- put: (hash: any, data: any) => Promise<void | any[] | IDBValidKey>;
196
+ put: (hash: any, data: any) => Promise<void | any[]>;
197
197
  /**
198
198
  * @param {String} hash
199
199
  * @return {Boolean}
@@ -223,7 +223,7 @@ export default class Peernet {
223
223
  * @param {Buffer} data
224
224
  * @param {String} storeName - storeName to access
225
225
  */
226
- put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<void | any[] | IDBValidKey>;
226
+ put(hash: string, data: Uint8Array, storeName?: string | LeofcoinStorageClass): Promise<void | any[]>;
227
227
  /**
228
228
  * @param {String} hash
229
229
  * @return {Boolean}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.1.76",
3
+ "version": "1.1.77",
4
4
  "description": "",
5
5
  "browser": "./exports/browser/peernet.js",
6
6
  "exports": {