@peerbit/any-store 2.0.2 → 2.1.0-55cebfe

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.
Files changed (49) hide show
  1. package/dist/src/index.d.ts +4 -0
  2. package/dist/src/index.d.ts.map +1 -0
  3. package/dist/src/index.js +2 -0
  4. package/dist/src/index.js.map +1 -0
  5. package/{lib/esm → dist/src}/level.d.ts +4 -2
  6. package/dist/src/level.d.ts.map +1 -0
  7. package/{lib/esm → dist/src}/level.js +15 -10
  8. package/dist/src/level.js.map +1 -0
  9. package/{lib/esm → dist/src}/memory.d.ts +4 -2
  10. package/dist/src/memory.d.ts.map +1 -0
  11. package/{lib/esm → dist/src}/memory.js +6 -2
  12. package/dist/src/memory.js.map +1 -0
  13. package/{lib/esm → dist/src}/store.browser.d.ts +2 -1
  14. package/dist/src/store.browser.d.ts.map +1 -0
  15. package/{lib/esm → dist/src}/store.browser.js +1 -1
  16. package/dist/src/store.browser.js.map +1 -0
  17. package/{lib/esm → dist/src}/store.d.ts +1 -0
  18. package/dist/src/store.d.ts.map +1 -0
  19. package/{lib/esm → dist/src}/store.js +1 -1
  20. package/{lib/esm → dist/src}/store.js.map +1 -1
  21. package/package.json +80 -50
  22. package/src/index.ts +4 -2
  23. package/src/level.ts +17 -14
  24. package/src/memory.ts +7 -3
  25. package/src/store.browser.ts +1 -1
  26. package/src/store.ts +2 -1
  27. package/LICENSE +0 -202
  28. package/lib/esm/index.d.ts +0 -3
  29. package/lib/esm/index.js +0 -4
  30. package/lib/esm/index.js.map +0 -1
  31. package/lib/esm/interface.d.ts +0 -18
  32. package/lib/esm/interface.js +0 -2
  33. package/lib/esm/interface.js.map +0 -1
  34. package/lib/esm/level.js.map +0 -1
  35. package/lib/esm/memory.js.map +0 -1
  36. package/lib/esm/opfs-worker-messages.d.ts +0 -122
  37. package/lib/esm/opfs-worker-messages.js +0 -325
  38. package/lib/esm/opfs-worker-messages.js.map +0 -1
  39. package/lib/esm/opfs-worker.d.ts +0 -8
  40. package/lib/esm/opfs-worker.js +0 -276
  41. package/lib/esm/opfs-worker.js.map +0 -1
  42. package/lib/esm/opfs.d.ts +0 -27
  43. package/lib/esm/opfs.js +0 -148
  44. package/lib/esm/opfs.js.map +0 -1
  45. package/lib/esm/store.browser.js.map +0 -1
  46. package/src/interface.ts +0 -20
  47. package/src/opfs-worker-messages.ts +0 -210
  48. package/src/opfs-worker.ts +0 -347
  49. package/src/opfs.ts +0 -205
@@ -0,0 +1,4 @@
1
+ import type { AnyStore } from "@peerbit/any-store-interface";
2
+ export { createStore } from "./store.js";
3
+ export type { AnyStore };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,YAAY,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createStore } from "./store.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -1,5 +1,5 @@
1
- import { AbstractLevel } from "abstract-level";
2
- import { AnyStore } from "./interface.js";
1
+ import { type AnyStore } from "@peerbit/any-store-interface";
2
+ import { type AbstractLevel } from "abstract-level";
3
3
  export declare class LevelStore implements AnyStore {
4
4
  readonly store: AbstractLevel<any, any, any>;
5
5
  constructor(store: AbstractLevel<any, any, any>);
@@ -13,4 +13,6 @@ export declare class LevelStore implements AnyStore {
13
13
  del(key: string): Promise<void>;
14
14
  size(): Promise<number>;
15
15
  sublevel(name: string): Promise<LevelStore>;
16
+ persisted(): boolean;
16
17
  }
18
+ //# sourceMappingURL=level.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../../src/level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAOpD,qBAAa,UAAW,YAAW,QAAQ;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;gBAAnC,KAAK,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAExD,MAAM;IAIA,KAAK;IAWL,IAAI;IAYJ,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAehD,QAAQ,IAAI,cAAc,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;IAS7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAQlC,GAAG,CAAC,GAAG,EAAE,MAAM;IAkBf,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IA6BvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAI3B,SAAS;CAGT"}
@@ -1,3 +1,5 @@
1
+ import {} from "@peerbit/any-store-interface";
2
+ import {} from "abstract-level";
1
3
  import { ClassicLevel } from "classic-level";
2
4
  const isNotFoundError = (err) => err.toString().indexOf("NotFoundError: Key not found in database") === -1 &&
3
5
  err.toString().indexOf("NotFound") === -1;
@@ -19,8 +21,9 @@ export class LevelStore {
19
21
  }
20
22
  }
21
23
  async open() {
22
- if (!this.store)
24
+ if (!this.store) {
23
25
  return Promise.reject(new Error("No cache store found to open"));
26
+ }
24
27
  if (this.status() !== "open") {
25
28
  await this.store.open();
26
29
  return Promise.resolve();
@@ -45,7 +48,7 @@ export class LevelStore {
45
48
  }
46
49
  async *iterator() {
47
50
  const iterator = this.store.iterator({
48
- valueEncoding: "view"
51
+ valueEncoding: "view",
49
52
  });
50
53
  for await (const [key, value] of iterator) {
51
54
  yield [key, value];
@@ -55,11 +58,10 @@ export class LevelStore {
55
58
  await this.store.clear();
56
59
  }
57
60
  async put(key, value) {
58
- // Remove when https://github.com/Level/classic-level/issues/87 is fixed
59
- /* if (this.store instanceof ClassicLevel) {
60
- await this.store.del(key, { sync: true });
61
- } */
62
- return this.store.put(key, value, { valueEncoding: "view" });
61
+ return this.store.put(key, value, {
62
+ valueEncoding: "view",
63
+ sync: true,
64
+ }); // sync option to make sure read after write behaves correctly
63
65
  }
64
66
  // Remove a value and key from the cache
65
67
  async del(key) {
@@ -83,17 +85,17 @@ export class LevelStore {
83
85
  if (this.store instanceof ClassicLevel) {
84
86
  const e = this.store.keys({
85
87
  limit: 1,
86
- fillCache: !1
88
+ fillCache: !1,
87
89
  }), a = await e.next();
88
90
  await e.close();
89
91
  const t = this.store.keys({
90
92
  limit: 1,
91
93
  reverse: !0,
92
- fillCache: !1
94
+ fillCache: !1,
93
95
  }), s = await t.next();
94
96
  return (await t.close(),
95
97
  this.store.approximateSize(a, s + "\uffff", {
96
- keyEncoding: "utf8"
98
+ keyEncoding: "utf8",
97
99
  }));
98
100
  }
99
101
  else {
@@ -106,5 +108,8 @@ export class LevelStore {
106
108
  async sublevel(name) {
107
109
  return new LevelStore(this.store.sublevel(name, { valueEncoding: "view" }));
108
110
  }
111
+ persisted() {
112
+ return this.store instanceof ClassicLevel;
113
+ }
109
114
  }
110
115
  //# sourceMappingURL=level.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"level.js","sourceRoot":"","sources":["../../src/level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAsB,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAA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AAI,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACvC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACrB,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QAC1B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,KAAK,YAAY,YAAY,CAAC;IAC3C,CAAC;CACD"}
@@ -1,4 +1,4 @@
1
- import { AnyStore } from "./interface.js";
1
+ import { type AnyStore } from "@peerbit/any-store-interface";
2
2
  export declare class MemoryStore implements AnyStore {
3
3
  private store;
4
4
  private sublevels;
@@ -10,8 +10,10 @@ export declare class MemoryStore implements AnyStore {
10
10
  get(key: string): Uint8Array | undefined;
11
11
  iterator(): AsyncGenerator<[string, Uint8Array], void, void>;
12
12
  clear(): void;
13
- put(key: string, value: Uint8Array): Map<string, Uint8Array>;
13
+ put(key: string, value: Uint8Array): void;
14
14
  del(key: string): void;
15
15
  sublevel(name: string): MemoryStore;
16
16
  size(): number;
17
+ persisted(): boolean;
17
18
  }
19
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,qBAAa,WAAY,YAAW,QAAQ;IAC3C,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,MAAM,CAAU;;IAMxB,MAAM;IAIN,KAAK;IAOL,IAAI;IAIJ,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIjC,QAAQ,IAAI,cAAc,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;IAMnE,KAAK,IAAI,IAAI;IAOb,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAKlC,GAAG,CAAC,GAAG,EAAE,MAAM;IAIf,QAAQ,CAAC,IAAI,EAAE,MAAM;IAerB,IAAI;IAQJ,SAAS;CAGT"}
@@ -1,3 +1,4 @@
1
+ import {} from "@peerbit/any-store-interface";
1
2
  export class MemoryStore {
2
3
  store;
3
4
  sublevels;
@@ -33,7 +34,7 @@ export class MemoryStore {
33
34
  }
34
35
  }
35
36
  put(key, value) {
36
- return this.store.set(key, value);
37
+ this.store.set(key, value);
37
38
  }
38
39
  // Remove a value and key from the cache
39
40
  del(key) {
@@ -53,10 +54,13 @@ export class MemoryStore {
53
54
  }
54
55
  size() {
55
56
  let size = 0;
56
- for (const [k, v] of this.store) {
57
+ for (const [_k, v] of this.store) {
57
58
  size += v.byteLength;
58
59
  }
59
60
  return size;
60
61
  }
62
+ persisted() {
63
+ return false;
64
+ }
61
65
  }
62
66
  //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,8BAA8B,CAAC;AAE7D,MAAM,OAAO,WAAW;IACf,KAAK,CAA0B;IAC/B,SAAS,CAA2B;IACpC,MAAM,CAAU;IACxB;QACC,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,MAAM;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxC,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,KAAK,MAAM,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AM,EAAE,CAAC;YACjB,GAAG,CAAC,IAAI,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,IAAI;QACH,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAClC,IAAI,IAAI,CAAC,CAAC,UAAU,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,SAAS;QACR,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
@@ -1,3 +1,4 @@
1
+ import { OPFSStore } from "@peerbit/any-store-opfs/opfs-store";
1
2
  import { MemoryStore } from "./memory.js";
2
- import { OPFSStore } from "./opfs.js";
3
3
  export declare const createStore: (directory?: string) => MemoryStore | OPFSStore;
4
+ //# sourceMappingURL=store.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.browser.d.ts","sourceRoot":"","sources":["../../src/store.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,eAAO,MAAM,WAAW,eAAgB,MAAM,4BAE7C,CAAC"}
@@ -1,5 +1,5 @@
1
+ import { OPFSStore } from "@peerbit/any-store-opfs/opfs-store";
1
2
  import { MemoryStore } from "./memory.js";
2
- import { OPFSStore } from "./opfs.js";
3
3
  export const createStore = (directory) => {
4
4
  return directory ? new OPFSStore(directory) : new MemoryStore();
5
5
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.browser.js","sourceRoot":"","sources":["../../src/store.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAkB,EAAE,EAAE;IACjD,OAAO,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC;AACjE,CAAC,CAAC;AAEF;;IAEI"}
@@ -1,3 +1,4 @@
1
1
  import { LevelStore } from "./level.js";
2
2
  import { MemoryStore } from "./memory.js";
3
3
  export declare const createStore: (directory?: string) => LevelStore | MemoryStore;
4
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK1C,eAAO,MAAM,WAAW,eAAgB,MAAM,6BAI7C,CAAC"}
@@ -1,5 +1,5 @@
1
- import { LevelStore } from "./level.js";
2
1
  import { Level } from "level";
2
+ import { LevelStore } from "./level.js";
3
3
  import { MemoryStore } from "./memory.js";
4
4
  /* import os from 'os'
5
5
  import { check } from 'diskusage' */
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C;oCACoC;AAEpC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAkB,EAAE,EAAE;IACjD,OAAO,SAAS;QACf,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF;;IAEI"}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;oCACoC;AAEpC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAkB,EAAE,EAAE;IACjD,OAAO,SAAS;QACf,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF;;IAEI"}
package/package.json CHANGED
@@ -1,52 +1,82 @@
1
1
  {
2
- "name": "@peerbit/any-store",
3
- "version": "2.0.2",
4
- "description": "Level with lazy transactions",
5
- "type": "module",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "files": [
10
- "lib",
11
- "src",
12
- "src/nginx-template.conf",
13
- "!src/**/__tests__",
14
- "!lib/**/__tests__",
15
- "LICENSE"
16
- ],
17
- "module": "lib/esm/index.js",
18
- "types": "lib/esm/index.d.ts",
19
- "exports": {
20
- "import": "./lib/esm/index.js",
21
- "require": "./lib/cjs/index.js"
22
- },
23
- "browser": {
24
- "./lib/esm/store.js": "./lib/esm/store.browser.js",
25
- "./store.js": "./lib/esm/store.browser.js"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/dao-xyz/peerbit"
30
- },
31
- "homepage": "https://github.com/dao-xyz/peerbit",
32
- "bugs": "https://github.com/dao-xyz/peerbit/issues",
33
- "scripts": {
34
- "clean": "shx rm -rf lib/*",
35
- "build": "yarn clean && tsc -p tsconfig.json",
36
- "test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
37
- "test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
38
- "test:integration": "node ../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit"
39
- },
40
- "license": "MIT",
41
- "dependencies": {
42
- "@peerbit/crypto": "^2.2.0",
43
- "@peerbit/logger": "1.0.2",
44
- "@peerbit/time": "2.0.6",
45
- "level": "^8.0.0",
46
- "uuid": "^9.0.0"
47
- },
48
- "localMaintainers": [
49
- "dao.xyz"
50
- ],
51
- "gitHead": "fcd486b9a5c3b7d94e2ae14f1b06ab2a0f7841ad"
2
+ "name": "@peerbit/any-store",
3
+ "version": "2.1.0-55cebfe",
4
+ "description": "Level with lazy transactions",
5
+ "sideEffects": false,
6
+ "type": "module",
7
+ "types": "./dist/src/index.d.ts",
8
+ "typesVersions": {
9
+ "*": {
10
+ "*": [
11
+ "*",
12
+ "dist/*",
13
+ "dist/src/*",
14
+ "dist/src/*/index"
15
+ ],
16
+ "src/*": [
17
+ "*",
18
+ "dist/*",
19
+ "dist/src/*",
20
+ "dist/src/*/index"
21
+ ]
22
+ }
23
+ },
24
+ "files": [
25
+ "src",
26
+ "dist",
27
+ "!dist/test",
28
+ "!**/*.tsbuildinfo"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/src/index.d.ts",
33
+ "import": "./dist/src/index.js"
34
+ }
35
+ },
36
+ "eslintConfig": {
37
+ "extends": "peerbit",
38
+ "parserOptions": {
39
+ "project": true,
40
+ "sourceType": "module"
41
+ },
42
+ "ignorePatterns": [
43
+ "!.aegir.js",
44
+ "test/ts-use",
45
+ "*.d.ts"
46
+ ]
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "browser": {
52
+ "./dist/src/store.js": "./dist/src/store.browser.js"
53
+ },
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "https://github.com/dao-xyz/peerbit"
57
+ },
58
+ "homepage": "https://github.com/dao-xyz/peerbit",
59
+ "bugs": "https://github.com/dao-xyz/peerbit/issues",
60
+ "scripts": {
61
+ "clean": "aegir clean",
62
+ "build": "aegir build --no-bundle",
63
+ "test": "aegir test",
64
+ "lint": "aegir lint"
65
+ },
66
+ "license": "MIT",
67
+ "dependencies": {
68
+ "@peerbit/crypto": "2.3.0-55cebfe",
69
+ "@peerbit/logger": "1.0.3-55cebfe",
70
+ "@peerbit/any-store-opfs": "1.0.0-55cebfe",
71
+ "@peerbit/any-store-interface": "1.0.0-55cebfe",
72
+ "@peerbit/time": "2.0.7-55cebfe",
73
+ "level": "^8.0.0",
74
+ "uuid": "^9.0.0"
75
+ },
76
+ "devDependencies": {
77
+ "@types/uuid": "^9.0.8"
78
+ },
79
+ "localMaintainers": [
80
+ "dao.xyz"
81
+ ]
52
82
  }
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
- export * from "./interface.js";
1
+ import type { AnyStore } from "@peerbit/any-store-interface";
2
+
2
3
  export { createStore } from "./store.js";
3
- export * as api from "./opfs-worker-messages.js";
4
+
5
+ export type { AnyStore };
package/src/level.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { AbstractLevel } from "abstract-level";
2
- import { AnyStore } from "./interface.js";
1
+ import { type AnyStore } from "@peerbit/any-store-interface";
2
+ import { type AbstractLevel } from "abstract-level";
3
3
  import { ClassicLevel } from "classic-level";
4
4
 
5
- const isNotFoundError = (err) =>
5
+ const isNotFoundError = (err: any) =>
6
6
  err.toString().indexOf("NotFoundError: Key not found in database") === -1 &&
7
7
  err.toString().indexOf("NotFound") === -1;
8
8
 
@@ -25,8 +25,9 @@ export class LevelStore implements AnyStore {
25
25
  }
26
26
 
27
27
  async open() {
28
- if (!this.store)
28
+ if (!this.store) {
29
29
  return Promise.reject(new Error("No cache store found to open"));
30
+ }
30
31
  if (this.status() !== "open") {
31
32
  await this.store.open();
32
33
  return Promise.resolve();
@@ -52,7 +53,7 @@ export class LevelStore implements AnyStore {
52
53
 
53
54
  async *iterator(): AsyncGenerator<[string, Uint8Array], void, void> {
54
55
  const iterator = this.store.iterator<any, Uint8Array>({
55
- valueEncoding: "view"
56
+ valueEncoding: "view",
56
57
  });
57
58
  for await (const [key, value] of iterator) {
58
59
  yield [key, value];
@@ -64,12 +65,10 @@ export class LevelStore implements AnyStore {
64
65
  }
65
66
 
66
67
  async put(key: string, value: Uint8Array) {
67
- // Remove when https://github.com/Level/classic-level/issues/87 is fixed
68
- /* if (this.store instanceof ClassicLevel) {
69
- await this.store.del(key, { sync: true });
70
- } */
71
-
72
- return this.store.put(key, value, { valueEncoding: "view" });
68
+ return this.store.put(key, value, {
69
+ valueEncoding: "view",
70
+ sync: true,
71
+ } as any); // sync option to make sure read after write behaves correctly
73
72
  }
74
73
 
75
74
  // Remove a value and key from the cache
@@ -96,20 +95,20 @@ export class LevelStore implements AnyStore {
96
95
  if (this.store instanceof ClassicLevel) {
97
96
  const e = this.store.keys({
98
97
  limit: 1,
99
- fillCache: !1
98
+ fillCache: !1,
100
99
  }),
101
100
  a = await e.next();
102
101
  await e.close();
103
102
  const t = this.store.keys({
104
103
  limit: 1,
105
104
  reverse: !0,
106
- fillCache: !1
105
+ fillCache: !1,
107
106
  }),
108
107
  s = await t.next();
109
108
  return (
110
109
  await t.close(),
111
110
  this.store.approximateSize(a, s + "\uffff", {
112
- keyEncoding: "utf8"
111
+ keyEncoding: "utf8",
113
112
  })
114
113
  );
115
114
  } else {
@@ -123,4 +122,8 @@ export class LevelStore implements AnyStore {
123
122
  async sublevel(name: string) {
124
123
  return new LevelStore(this.store.sublevel(name, { valueEncoding: "view" }));
125
124
  }
125
+
126
+ persisted() {
127
+ return this.store instanceof ClassicLevel;
128
+ }
126
129
  }
package/src/memory.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyStore } from "./interface.js";
1
+ import { type AnyStore } from "@peerbit/any-store-interface";
2
2
 
3
3
  export class MemoryStore implements AnyStore {
4
4
  private store: Map<string, Uint8Array>;
@@ -42,7 +42,7 @@ export class MemoryStore implements AnyStore {
42
42
  }
43
43
 
44
44
  put(key: string, value: Uint8Array) {
45
- return this.store.set(key, value);
45
+ this.store.set(key, value);
46
46
  }
47
47
 
48
48
  // Remove a value and key from the cache
@@ -67,9 +67,13 @@ export class MemoryStore implements AnyStore {
67
67
 
68
68
  size() {
69
69
  let size = 0;
70
- for (const [k, v] of this.store) {
70
+ for (const [_k, v] of this.store) {
71
71
  size += v.byteLength;
72
72
  }
73
73
  return size;
74
74
  }
75
+
76
+ persisted() {
77
+ return false;
78
+ }
75
79
  }
@@ -1,5 +1,5 @@
1
+ import { OPFSStore } from "@peerbit/any-store-opfs/opfs-store";
1
2
  import { MemoryStore } from "./memory.js";
2
- import { OPFSStore } from "./opfs.js";
3
3
 
4
4
  export const createStore = (directory?: string) => {
5
5
  return directory ? new OPFSStore(directory) : new MemoryStore();
package/src/store.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { LevelStore } from "./level.js";
2
1
  import { Level } from "level";
2
+ import { LevelStore } from "./level.js";
3
3
  import { MemoryStore } from "./memory.js";
4
+
4
5
  /* import os from 'os'
5
6
  import { check } from 'diskusage' */
6
7