@peerbit/document 12.2.0-874976b → 12.2.0-d15e444

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=document-put.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-put.d.ts","sourceRoot":"","sources":["../../benchmark/document-put.ts"],"names":[],"mappings":""}
@@ -0,0 +1,201 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ import { field, option, variant } from "@dao-xyz/borsh";
36
+ import { Program } from "@peerbit/program";
37
+ import { TestSession } from "@peerbit/test-utils";
38
+ import { Bench } from "tinybench";
39
+ import { Documents } from "../src/program.js";
40
+ // Run with:
41
+ // cd packages/programs/data/document/document
42
+ // node --loader ts-node/esm ./benchmark/document-put.ts
43
+ //
44
+ // Env:
45
+ // - DOC_WARMUP=1000
46
+ // - DOC_ITERATIONS=200
47
+ // - DOC_BYTES=1200
48
+ // - BENCH_JSON=1 (emit machine-readable JSON)
49
+ const payloadBytes = Math.max(1, Number.parseInt(process.env.DOC_BYTES || "1200", 10) || 1200);
50
+ const warmupIterations = Number.parseInt(process.env.DOC_WARMUP || "1000", 10);
51
+ const iterations = process.env.DOC_ITERATIONS
52
+ ? Number.parseInt(process.env.DOC_ITERATIONS, 10)
53
+ : undefined;
54
+ let Document = (() => {
55
+ let _classDecorators = [variant("document")];
56
+ let _classDescriptor;
57
+ let _classExtraInitializers = [];
58
+ let _classThis;
59
+ let _id_decorators;
60
+ let _id_initializers = [];
61
+ let _id_extraInitializers = [];
62
+ let _name_decorators;
63
+ let _name_initializers = [];
64
+ let _name_extraInitializers = [];
65
+ let _number_decorators;
66
+ let _number_initializers = [];
67
+ let _number_extraInitializers = [];
68
+ let _bytes_decorators;
69
+ let _bytes_initializers = [];
70
+ let _bytes_extraInitializers = [];
71
+ var Document = class {
72
+ static { _classThis = this; }
73
+ static {
74
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
75
+ _id_decorators = [field({ type: "string" })];
76
+ _name_decorators = [field({ type: option("string") })];
77
+ _number_decorators = [field({ type: option("u64") })];
78
+ _bytes_decorators = [field({ type: Uint8Array })];
79
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
80
+ __esDecorate(null, null, _name_decorators, { kind: "field", name: "name", static: false, private: false, access: { has: obj => "name" in obj, get: obj => obj.name, set: (obj, value) => { obj.name = value; } }, metadata: _metadata }, _name_initializers, _name_extraInitializers);
81
+ __esDecorate(null, null, _number_decorators, { kind: "field", name: "number", static: false, private: false, access: { has: obj => "number" in obj, get: obj => obj.number, set: (obj, value) => { obj.number = value; } }, metadata: _metadata }, _number_initializers, _number_extraInitializers);
82
+ __esDecorate(null, null, _bytes_decorators, { kind: "field", name: "bytes", static: false, private: false, access: { has: obj => "bytes" in obj, get: obj => obj.bytes, set: (obj, value) => { obj.bytes = value; } }, metadata: _metadata }, _bytes_initializers, _bytes_extraInitializers);
83
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
84
+ Document = _classThis = _classDescriptor.value;
85
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
86
+ __runInitializers(_classThis, _classExtraInitializers);
87
+ }
88
+ id = __runInitializers(this, _id_initializers, void 0);
89
+ name = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _name_initializers, void 0));
90
+ number = (__runInitializers(this, _name_extraInitializers), __runInitializers(this, _number_initializers, void 0));
91
+ bytes = (__runInitializers(this, _number_extraInitializers), __runInitializers(this, _bytes_initializers, void 0));
92
+ constructor(opts) {
93
+ __runInitializers(this, _bytes_extraInitializers);
94
+ if (opts) {
95
+ this.id = opts.id;
96
+ this.name = opts.name;
97
+ this.number = opts.number;
98
+ this.bytes = opts.bytes;
99
+ }
100
+ }
101
+ };
102
+ return Document = _classThis;
103
+ })();
104
+ let TestStore = (() => {
105
+ let _classDecorators = [variant("test_documents")];
106
+ let _classDescriptor;
107
+ let _classExtraInitializers = [];
108
+ let _classThis;
109
+ let _classSuper = Program;
110
+ let _docs_decorators;
111
+ let _docs_initializers = [];
112
+ let _docs_extraInitializers = [];
113
+ var TestStore = class extends _classSuper {
114
+ static { _classThis = this; }
115
+ static {
116
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
117
+ _docs_decorators = [field({ type: Documents })];
118
+ __esDecorate(null, null, _docs_decorators, { kind: "field", name: "docs", static: false, private: false, access: { has: obj => "docs" in obj, get: obj => obj.docs, set: (obj, value) => { obj.docs = value; } }, metadata: _metadata }, _docs_initializers, _docs_extraInitializers);
119
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
120
+ TestStore = _classThis = _classDescriptor.value;
121
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
122
+ __runInitializers(_classThis, _classExtraInitializers);
123
+ }
124
+ docs = __runInitializers(this, _docs_initializers, void 0);
125
+ constructor(properties) {
126
+ super();
127
+ __runInitializers(this, _docs_extraInitializers);
128
+ this.docs = properties?.docs ?? new Documents();
129
+ }
130
+ async open(options) {
131
+ await this.docs.open({ ...options, type: Document });
132
+ }
133
+ };
134
+ return TestStore = _classThis;
135
+ })();
136
+ const peersCount = 1;
137
+ const session = await TestSession.connected(peersCount);
138
+ const store = new TestStore({
139
+ docs: new Documents(),
140
+ });
141
+ const client = session.peers[0];
142
+ await client.open(store, {
143
+ args: {
144
+ replicate: {
145
+ factor: 1,
146
+ },
147
+ log: {
148
+ trim: { type: "length", to: 100 },
149
+ },
150
+ },
151
+ });
152
+ const payload = new Uint8Array(payloadBytes);
153
+ for (let i = 0; i < payload.length; i++) {
154
+ payload[i] = i % 256;
155
+ }
156
+ let idCounter = 0;
157
+ const suite = new Bench({
158
+ name: "document-put",
159
+ warmupIterations: Number.isFinite(warmupIterations) ? warmupIterations : 0,
160
+ iterations: typeof iterations === "number" && Number.isFinite(iterations)
161
+ ? iterations
162
+ : undefined,
163
+ });
164
+ suite.add("put (unique)", async () => {
165
+ const doc = new Document({
166
+ id: String(idCounter++),
167
+ name: "hello",
168
+ number: 1n,
169
+ bytes: payload,
170
+ });
171
+ await store.docs.put(doc, { unique: true });
172
+ });
173
+ try {
174
+ await suite.run();
175
+ if (process.env.BENCH_JSON === "1") {
176
+ const tasks = suite.tasks.map((task) => ({
177
+ name: task.name,
178
+ hz: task.result?.hz ?? null,
179
+ mean_ms: task.result?.mean ?? null,
180
+ rme: task.result?.rme ?? null,
181
+ samples: task.result?.samples?.length ?? null,
182
+ }));
183
+ process.stdout.write(JSON.stringify({
184
+ name: suite.name,
185
+ tasks,
186
+ meta: {
187
+ payloadBytes,
188
+ warmupIterations,
189
+ iterations: iterations ?? null,
190
+ },
191
+ }, null, 2));
192
+ }
193
+ else {
194
+ console.table(suite.table());
195
+ }
196
+ }
197
+ finally {
198
+ await store.drop();
199
+ await session.stop();
200
+ }
201
+ //# sourceMappingURL=document-put.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-put.js","sourceRoot":"","sources":["../../benchmark/document-put.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAsB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAqB,MAAM,mBAAmB,CAAC;AAEjE,YAAY;AACZ,gDAAgD;AAChD,0DAA0D;AAC1D,EAAE;AACF,OAAO;AACP,oBAAoB;AACpB,uBAAuB;AACvB,mBAAmB;AACnB,8CAA8C;AAE9C,M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I,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI;YAClC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI;YAC7B,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI;SAC7C,CAAC,CAAC,CAAC;QACJ,OAAO,CAAC,MAAM,CAAC,KAAK,CACnB,IAAI,CAAC,SAAS,CACb;YACC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK;YACL,IAAI,EAAE;gBACL,YAAY;gBACZ,gBAAgB;gBAChB,UAAU,EAAE,UAAU,IAAI,IAAI;aAC9B;SACD,EACD,IAAI,EACJ,CAAC,CACD,CACD,CAAC;IACH,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;AACF,CAAC;QAAS,CAAC;IACV,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACnB,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/document",
3
- "version": "12.2.0-874976b",
3
+ "version": "12.2.0-d15e444",
4
4
  "description": "Document store implementation",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -57,27 +57,27 @@
57
57
  "@libp2p/interface": "^3.1.0",
58
58
  "@libp2p/tcp": "^11.0.2",
59
59
  "@multiformats/multiaddr": "^13.0.1",
60
- "@peerbit/cache": "2.2.0-874976b",
61
- "@peerbit/crypto": "2.4.1-874976b",
62
- "@peerbit/logger": "2.0.0-874976b",
63
- "@peerbit/log": "5.0.6-874976b",
64
- "@peerbit/pubsub": "4.1.3-874976b",
65
- "@peerbit/program": "5.6.0-874976b",
66
- "@peerbit/rpc": "5.4.15-874976b",
67
- "@peerbit/shared-log": "12.2.0-874976b",
68
- "@peerbit/indexer-interface": "2.1.1-874976b",
69
- "@peerbit/indexer-simple": "1.2.2-874976b",
70
- "@peerbit/indexer-sqlite3": "2.1.0-874976b",
71
- "@peerbit/document-interface": "3.2.0-874976b",
72
- "@peerbit/indexer-cache": "0.2.2-874976b",
73
- "@peerbit/stream-interface": "5.3.1-874976b",
60
+ "@peerbit/cache": "2.2.0-d15e444",
61
+ "@peerbit/crypto": "2.4.1-d15e444",
62
+ "@peerbit/logger": "2.0.0-d15e444",
63
+ "@peerbit/log": "5.0.6-d15e444",
64
+ "@peerbit/pubsub": "4.1.3-d15e444",
65
+ "@peerbit/program": "5.6.0-d15e444",
66
+ "@peerbit/rpc": "5.4.15-d15e444",
67
+ "@peerbit/shared-log": "12.2.0-d15e444",
68
+ "@peerbit/indexer-interface": "2.1.1-d15e444",
69
+ "@peerbit/indexer-simple": "1.2.2-d15e444",
70
+ "@peerbit/indexer-sqlite3": "2.1.0-d15e444",
71
+ "@peerbit/document-interface": "3.2.0-d15e444",
72
+ "@peerbit/indexer-cache": "0.2.2-d15e444",
73
+ "@peerbit/stream-interface": "5.3.1-d15e444",
74
74
  "p-defer": "^4.0.0",
75
75
  "uint8arrays": "^5.1.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@peerbit/test-utils": "2.3.15-874976b",
79
- "@peerbit/time": "2.3.0-874976b",
80
- "peerbit": "4.4.15-874976b",
78
+ "@peerbit/test-utils": "2.3.15-d15e444",
79
+ "@peerbit/time": "2.3.0-d15e444",
80
+ "peerbit": "4.4.15-d15e444",
81
81
  "@types/pidusage": "^2.0.5",
82
82
  "pidusage": "^4.0.1",
83
83
  "uuid": "^10.0.0",