@peerbit/indexer-sqlite3 0.0.1-cccc078
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.
- package/README.md +111 -0
- package/dist/benchmark/index.d.ts +2 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/dist/benchmark/index.js +6 -0
- package/dist/benchmark/index.js.map +1 -0
- package/dist/peerbit/sqlite3-bundler-friendly.mjs +14481 -0
- package/dist/peerbit/sqlite3-node.mjs +12561 -0
- package/dist/peerbit/sqlite3-opfs-async-proxy.js +826 -0
- package/dist/peerbit/sqlite3-worker1-bundler-friendly.mjs +35 -0
- package/dist/peerbit/sqlite3-worker1-promiser.js +193 -0
- package/dist/peerbit/sqlite3-worker1-promiser.mjs +187 -0
- package/dist/peerbit/sqlite3-worker1.js +46 -0
- package/dist/peerbit/sqlite3.js +14520 -0
- package/dist/peerbit/sqlite3.min.js +21695 -0
- package/dist/peerbit/sqlite3.mjs +14483 -0
- package/dist/peerbit/sqlite3.wasm +0 -0
- package/dist/peerbit/sqlite3.worker.min.js +17995 -0
- package/dist/src/engine.d.ts +90 -0
- package/dist/src/engine.d.ts.map +1 -0
- package/dist/src/engine.js +414 -0
- package/dist/src/engine.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/schema.d.ts +73 -0
- package/dist/src/schema.d.ts.map +1 -0
- package/dist/src/schema.js +1075 -0
- package/dist/src/schema.js.map +1 -0
- package/dist/src/sqlite3-messages.worker.d.ts +86 -0
- package/dist/src/sqlite3-messages.worker.d.ts.map +1 -0
- package/dist/src/sqlite3-messages.worker.js +9 -0
- package/dist/src/sqlite3-messages.worker.js.map +1 -0
- package/dist/src/sqlite3.browser.d.ts +4 -0
- package/dist/src/sqlite3.browser.d.ts.map +1 -0
- package/dist/src/sqlite3.browser.js +181 -0
- package/dist/src/sqlite3.browser.js.map +1 -0
- package/dist/src/sqlite3.d.ts +4 -0
- package/dist/src/sqlite3.d.ts.map +1 -0
- package/dist/src/sqlite3.js +51 -0
- package/dist/src/sqlite3.js.map +1 -0
- package/dist/src/sqlite3.wasm.d.ts +30 -0
- package/dist/src/sqlite3.wasm.d.ts.map +1 -0
- package/dist/src/sqlite3.wasm.js +180 -0
- package/dist/src/sqlite3.wasm.js.map +1 -0
- package/dist/src/sqlite3.worker.d.ts +2 -0
- package/dist/src/sqlite3.worker.d.ts.map +1 -0
- package/dist/src/sqlite3.worker.js +105 -0
- package/dist/src/sqlite3.worker.js.map +1 -0
- package/dist/src/types.d.ts +23 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +80 -0
- package/src/engine.ts +639 -0
- package/src/index.ts +16 -0
- package/src/schema.ts +1607 -0
- package/src/sqlite3-messages.worker.ts +123 -0
- package/src/sqlite3.browser.ts +245 -0
- package/src/sqlite3.ts +56 -0
- package/src/sqlite3.wasm.ts +211 -0
- package/src/sqlite3.worker.ts +109 -0
- package/src/types.ts +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Documents
|
|
2
|
+
|
|
3
|
+
Distributed document store.
|
|
4
|
+
|
|
5
|
+
This store is built on top of the base store. This store allows for type-safe document storage and retrieval accross peers.
|
|
6
|
+
|
|
7
|
+
As of now, go through the [tests](./src//__tests__/index.integration.test.ts) for documentation on how to use the module.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Example
|
|
12
|
+
```typescript
|
|
13
|
+
import { field, option, serialize, variant } from "@dao-xyz/borsh";
|
|
14
|
+
import { Program } from "@peerbit/program";
|
|
15
|
+
import { Peerbit } from "peerbit";
|
|
16
|
+
import {
|
|
17
|
+
Documents,
|
|
18
|
+
DocumentIndex,
|
|
19
|
+
SearchRequest,
|
|
20
|
+
StringMatch,
|
|
21
|
+
StringMatchMethod,
|
|
22
|
+
Results,
|
|
23
|
+
} from "@peerbit/document";
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@variant("document")
|
|
27
|
+
class Document {
|
|
28
|
+
@field({ type: "string" })
|
|
29
|
+
id: string;
|
|
30
|
+
|
|
31
|
+
@field({ type: option("string") })
|
|
32
|
+
name?: string;
|
|
33
|
+
|
|
34
|
+
@field({ type: option("u64") })
|
|
35
|
+
number?: bigint;
|
|
36
|
+
|
|
37
|
+
constructor(opts?: Document) {
|
|
38
|
+
if (opts) {
|
|
39
|
+
Object.assign(this, opts);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@variant("test_documents")
|
|
45
|
+
class TestStore extends Program {
|
|
46
|
+
@field({ type: Documents })
|
|
47
|
+
docs: Documents<Document>;
|
|
48
|
+
|
|
49
|
+
constructor(properties?: { docs: Documents<Document> }) {
|
|
50
|
+
super();
|
|
51
|
+
if (properties) {
|
|
52
|
+
this.docs = properties.docs;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async open(): Promise<void> {
|
|
56
|
+
await this.docs.open({
|
|
57
|
+
type: Document,
|
|
58
|
+
index: {
|
|
59
|
+
fields: (obj) => obj // here you can filter and transform what fields you want to index
|
|
60
|
+
}})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// later
|
|
65
|
+
|
|
66
|
+
const peer = await Peerbit.create ({libp2p: your_libp2p_instance})
|
|
67
|
+
const store = peer.open(new TestStore());
|
|
68
|
+
console.log(store.address) /// this address can be opened by another peer
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
// insert
|
|
72
|
+
let doc = new Document({
|
|
73
|
+
id: "1",
|
|
74
|
+
name: "hello world",
|
|
75
|
+
number: 1n,
|
|
76
|
+
});
|
|
77
|
+
let doc2 = new Document({
|
|
78
|
+
id: "2",
|
|
79
|
+
name: "hello world",
|
|
80
|
+
number: 2n,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
let doc3 = new Document({
|
|
84
|
+
id: "3",
|
|
85
|
+
name: "foo",
|
|
86
|
+
number: 3n,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await store.docs.put(doc);
|
|
90
|
+
await store.docs.put(doc2);
|
|
91
|
+
await store.docs.put(doc3);
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
// search for documents from another peer
|
|
95
|
+
const peer2 = await Peerbit.create ({libp2: another_libp2p_instance})
|
|
96
|
+
const store2 = peer2.open(store.address);
|
|
97
|
+
|
|
98
|
+
let responses: Document[] = await store2.docs.index.search(
|
|
99
|
+
new SearchRequest({
|
|
100
|
+
query: [
|
|
101
|
+
new StringMatch({
|
|
102
|
+
key: "name",
|
|
103
|
+
value: "ello",
|
|
104
|
+
method: StringMatchMethod.contains
|
|
105
|
+
}),
|
|
106
|
+
],
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
expect(responses]).to.have.length(2);
|
|
110
|
+
expect(responses.map((x) => x.value.id)).to.deep.equal(["1", "2"]);
|
|
111
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../benchmark/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { benchmarks } from "@peerbit/indexer-tests";
|
|
2
|
+
import { create } from "../src/index.js";
|
|
3
|
+
// Run with "node --loader ts-node/esm ./benchmark/index.ts"
|
|
4
|
+
await benchmarks(create, "transient");
|
|
5
|
+
await benchmarks(create, "persist");
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../benchmark/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,4DAA4D;AAE5D,MAAM,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AACtC,MAAM,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC"}
|