@peerbit/log 4.0.0 → 4.0.1-9e66213

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/package.json CHANGED
@@ -1,106 +1,106 @@
1
1
  {
2
- "name": "@peerbit/log",
3
- "version": "4.0.0",
4
- "description": "Append-only log CRDT",
5
- "author": "dao.xyz",
6
- "license": "MIT",
7
- "sideEffects": false,
8
- "type": "module",
9
- "types": "./dist/src/index.d.ts",
10
- "typesVersions": {
11
- "*": {
12
- "*": [
13
- "*",
14
- "dist/*",
15
- "dist/src/*",
16
- "dist/src/*/index"
17
- ],
18
- "src/*": [
19
- "*",
20
- "dist/*",
21
- "dist/src/*",
22
- "dist/src/*/index"
23
- ]
24
- }
25
- },
26
- "files": [
27
- "src",
28
- "dist",
29
- "!dist/test",
30
- "!**/*.tsbuildinfo"
31
- ],
32
- "exports": {
33
- ".": {
34
- "types": "./dist/src/index.d.ts",
35
- "import": "./dist/src/index.js"
36
- }
37
- },
38
- "eslintConfig": {
39
- "extends": "peerbit",
40
- "parserOptions": {
41
- "project": true,
42
- "sourceType": "module"
43
- },
44
- "ignorePatterns": [
45
- "!.aegir.js",
46
- "test/ts-use",
47
- "*.d.ts"
48
- ]
49
- },
50
- "publishConfig": {
51
- "access": "public"
52
- },
53
- "engines": {
54
- "node": ">=16.15.1"
55
- },
56
- "keywords": [
57
- "ipfs",
58
- "log",
59
- "crdts",
60
- "crdt"
61
- ],
62
- "dependencies": {
63
- "@dao-xyz/borsh": "^5.2.3",
64
- "@peerbit/cache": "2.1.0",
65
- "@peerbit/blocks-interface": "^1.3.0",
66
- "@peerbit/crypto": "2.3.0",
67
- "@peerbit/logger": "1.0.3",
68
- "@peerbit/time": "2.0.7",
69
- "libp2p": "^1.8.1",
70
- "p-queue": "^8.0.1",
71
- "path-browserify": "^1.0.1",
72
- "uuid": "^9.0.0",
73
- "@peerbit/indexer-interface": "^1.0.0",
74
- "@peerbit/indexer-simple": "^1.0.0"
75
- },
76
- "devDependencies": {
77
- "@peerbit/test-utils": "2.0.34",
78
- "@types/yallist": "^4.0.4",
79
- "assert": "^2.0.0",
80
- "json-stringify-deterministic": "^1.0.7"
81
- },
82
- "contributors": [
83
- "haadcode",
84
- "aphelionz",
85
- "shamb0t",
86
- "thiagodelgado111",
87
- "mistakia",
88
- "satazor",
89
- "RichardLitt",
90
- "greenkeeperio-bot",
91
- "chrisdostert",
92
- "zachferland",
93
- "kaibakker",
94
- "dignifiedquire",
95
- "adam-palazzo"
96
- ],
97
- "scripts": {
98
- "clean": "aegir clean",
99
- "build": "aegir build --no-bundle",
100
- "test": "aegir test --target node",
101
- "lint": "aegir lint"
102
- },
103
- "localMaintainers": [
104
- "dao.xyz"
105
- ]
2
+ "name": "@peerbit/log",
3
+ "version": "4.0.1-9e66213",
4
+ "description": "Append-only log CRDT",
5
+ "author": "dao.xyz",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "type": "module",
9
+ "types": "./dist/src/index.d.ts",
10
+ "typesVersions": {
11
+ "*": {
12
+ "*": [
13
+ "*",
14
+ "dist/*",
15
+ "dist/src/*",
16
+ "dist/src/*/index"
17
+ ],
18
+ "src/*": [
19
+ "*",
20
+ "dist/*",
21
+ "dist/src/*",
22
+ "dist/src/*/index"
23
+ ]
24
+ }
25
+ },
26
+ "files": [
27
+ "src",
28
+ "dist",
29
+ "!dist/test",
30
+ "!**/*.tsbuildinfo"
31
+ ],
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/src/index.d.ts",
35
+ "import": "./dist/src/index.js"
36
+ }
37
+ },
38
+ "eslintConfig": {
39
+ "extends": "peerbit",
40
+ "parserOptions": {
41
+ "project": true,
42
+ "sourceType": "module"
43
+ },
44
+ "ignorePatterns": [
45
+ "!.aegir.js",
46
+ "test/ts-use",
47
+ "*.d.ts"
48
+ ]
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "engines": {
54
+ "node": ">=16.15.1"
55
+ },
56
+ "keywords": [
57
+ "ipfs",
58
+ "log",
59
+ "crdts",
60
+ "crdt"
61
+ ],
62
+ "dependencies": {
63
+ "@dao-xyz/borsh": "^5.2.3",
64
+ "@peerbit/cache": "2.1.0-9e66213",
65
+ "@peerbit/blocks-interface": "1.3.0-9e66213",
66
+ "@peerbit/crypto": "2.3.0-9e66213",
67
+ "@peerbit/logger": "1.0.3-9e66213",
68
+ "@peerbit/time": "2.0.7-9e66213",
69
+ "libp2p": "^1.8.1",
70
+ "p-queue": "^8.0.1",
71
+ "path-browserify": "^1.0.1",
72
+ "uuid": "^9.0.0",
73
+ "@peerbit/indexer-interface": "1.0.0-9e66213",
74
+ "@peerbit/indexer-simple": "1.0.0-9e66213"
75
+ },
76
+ "devDependencies": {
77
+ "@peerbit/test-utils": "2.0.35-9e66213",
78
+ "@types/yallist": "^4.0.4",
79
+ "assert": "^2.0.0",
80
+ "json-stringify-deterministic": "^1.0.7"
81
+ },
82
+ "contributors": [
83
+ "haadcode",
84
+ "aphelionz",
85
+ "shamb0t",
86
+ "thiagodelgado111",
87
+ "mistakia",
88
+ "satazor",
89
+ "RichardLitt",
90
+ "greenkeeperio-bot",
91
+ "chrisdostert",
92
+ "zachferland",
93
+ "kaibakker",
94
+ "dignifiedquire",
95
+ "adam-palazzo"
96
+ ],
97
+ "scripts": {
98
+ "clean": "aegir clean",
99
+ "build": "aegir build --no-bundle",
100
+ "test": "aegir test --target node",
101
+ "lint": "aegir lint"
102
+ },
103
+ "localMaintainers": [
104
+ "dao.xyz"
105
+ ]
106
106
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../benchmark/index.ts"],"names":[],"mappings":""}
@@ -1,143 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import B from "benchmark";
11
- import { field, option, serialize, variant } from "@dao-xyz/borsh";
12
- import { v4 as uuid } from "uuid";
13
- import crypto from "crypto";
14
- import { Log } from "../src/log.js";
15
- import { AnyBlockStore } from "@peerbit/blocks";
16
- import { Ed25519Keypair } from "@peerbit/crypto";
17
- import { BORSH_ENCODING } from "../src/encoding.js";
18
- import { Entry } from "../src/entry.js";
19
- // Run with "node --loader ts-node/esm ./benchmark/index.ts"
20
- let Document = class Document {
21
- id;
22
- name;
23
- number;
24
- bytes;
25
- constructor(opts) {
26
- this.id = opts.id;
27
- this.name = opts.name;
28
- this.number = opts.number;
29
- this.bytes = opts.bytes;
30
- }
31
- };
32
- __decorate([
33
- field({ type: "string" }),
34
- __metadata("design:type", String)
35
- ], Document.prototype, "id", void 0);
36
- __decorate([
37
- field({ type: option("string") }),
38
- __metadata("design:type", String)
39
- ], Document.prototype, "name", void 0);
40
- __decorate([
41
- field({ type: option("u64") }),
42
- __metadata("design:type", BigInt)
43
- ], Document.prototype, "number", void 0);
44
- __decorate([
45
- field({ type: Uint8Array }),
46
- __metadata("design:type", Uint8Array)
47
- ], Document.prototype, "bytes", void 0);
48
- Document = __decorate([
49
- variant("document"),
50
- __metadata("design:paramtypes", [Document])
51
- ], Document);
52
- let log;
53
- let store;
54
- const key = await Ed25519Keypair.create();
55
- const reset = async () => {
56
- log = new Log();
57
- store = new AnyBlockStore();
58
- await log.open(store, key, { encoding: BORSH_ENCODING(Document) });
59
- };
60
- await reset();
61
- class NestedEntry {
62
- entry;
63
- constructor(entry) {
64
- this.entry = entry;
65
- }
66
- }
67
- __decorate([
68
- field({ type: Entry }),
69
- __metadata("design:type", Entry)
70
- ], NestedEntry.prototype, "entry", void 0);
71
- const suite = new B.Suite({ delay: 100 });
72
- suite
73
- .add("1e3", {
74
- fn: async (deferred) => {
75
- const doc = new Document({
76
- id: uuid(),
77
- name: "hello",
78
- number: 1n,
79
- bytes: crypto.randomBytes(1e3)
80
- });
81
- await log.append(doc);
82
- deferred.resolve();
83
- },
84
- defer: true
85
- })
86
- .add("1e4", {
87
- fn: async (deferred) => {
88
- const doc = new Document({
89
- id: uuid(),
90
- name: "hello",
91
- number: 1n,
92
- bytes: crypto.randomBytes(1e4)
93
- });
94
- await log.append(doc);
95
- deferred.resolve();
96
- },
97
- defer: true
98
- })
99
- .add("1e5", {
100
- fn: async (deferred) => {
101
- const doc = new Document({
102
- id: uuid(),
103
- name: "hello",
104
- number: 1n,
105
- bytes: crypto.randomBytes(1e5)
106
- });
107
- const entry = await log.append(doc);
108
- serialize(new NestedEntry(entry.entry));
109
- serialize(new NestedEntry(entry.entry));
110
- serialize(new NestedEntry(entry.entry));
111
- serialize(new NestedEntry(entry.entry));
112
- serialize(new NestedEntry(entry.entry));
113
- serialize(new NestedEntry(entry.entry));
114
- serialize(new NestedEntry(entry.entry));
115
- serialize(new NestedEntry(entry.entry));
116
- serialize(new NestedEntry(entry.entry));
117
- serialize(new NestedEntry(entry.entry));
118
- deferred.resolve();
119
- },
120
- defer: true
121
- })
122
- .add("1e6", {
123
- fn: async (deferred) => {
124
- const doc = new Document({
125
- id: uuid(),
126
- name: "hello",
127
- number: 1n,
128
- bytes: crypto.randomBytes(1e5)
129
- });
130
- await log.append(doc);
131
- deferred.resolve();
132
- },
133
- defer: true
134
- })
135
- .on("cycle", async (event) => {
136
- console.log(String(event.target));
137
- await reset();
138
- })
139
- .on("error", (err) => {
140
- throw err;
141
- })
142
- .run();
143
- //# sourceMappingURL=index.js.map
@@ -1 +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AAC,CAAC;QACxC,SAAS,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,SAAS,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,SAAS,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAExC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IACD,KAAK,EAAE,IAAI;CACX,CAAC;KACD,GAAG,CAAC,KAAK,EAAE;IACX,EAAE,EAAE,KAAK,EAAE,QAAa,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC;YACxB,EAAE,EAAE,IAAI,EAAE;YACV,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC;SAC9B,CAAC,CAAC;QACH,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAEtB,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IACD,KAAK,EAAE,IAAI;CACX,CAAC;KACD,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE;IACjC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAClC,MAAM,KAAK,EAAE,CAAC;AACf,CAAC,CAAC;KACD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAQ,EAAE,EAAE;IACzB,MAAM,GAAG,CAAC;AACX,CAAC,CAAC;KACD,GAAG,EAAE,CAAC"}
@@ -1,70 +0,0 @@
1
- import { Entry } from "./entry.js";
2
- import { type AnyStore } from "@peerbit/any-store";
3
- import { HeadsCache } from "./heads-cache.js";
4
- import { type Blocks } from "@peerbit/blocks-interface";
5
- import { type Keychain } from "@peerbit/keychain";
6
- import { type Encoding } from "./encoding.js";
7
- import { Values } from "./values.js";
8
- import { EntryIndex } from "./entry-index.js";
9
- export type CacheUpdateOptions = {
10
- cache?: {
11
- update?: false;
12
- reset?: false;
13
- } | {
14
- update: true;
15
- reset?: boolean;
16
- };
17
- };
18
- interface Log<T> {
19
- blocks: Blocks;
20
- keychain?: Keychain;
21
- memory?: AnyStore;
22
- encoding: Encoding<any>;
23
- entryIndex: EntryIndex<T>;
24
- values: Values<T>;
25
- }
26
- export declare class HeadsIndex<T> {
27
- private _id;
28
- private _index;
29
- private _gids;
30
- private _headsCache;
31
- private _config;
32
- private _onGidRemoved?;
33
- constructor(id: Uint8Array);
34
- init(log: Log<T>, options?: {
35
- entries?: Entry<T>[];
36
- onGidRemoved?: (gid: string[]) => Promise<void> | void;
37
- }): Promise<HeadsCache<T> | undefined>;
38
- load(options?: {
39
- timeout?: number;
40
- replicate?: boolean;
41
- reload?: boolean;
42
- ignoreMissing?: boolean;
43
- } & CacheUpdateOptions): Promise<Entry<T>[] | undefined>;
44
- get headsCache(): HeadsCache<T> | undefined;
45
- close(): Promise<void> | undefined;
46
- drop(): Promise<void> | undefined;
47
- get id(): Uint8Array;
48
- get index(): Set<string>;
49
- get gids(): Map<string, Map<string, Entry<T>>>;
50
- get size(): number;
51
- reset(entries: Entry<T>[], options?: CacheUpdateOptions): Promise<void>;
52
- has(cid: string): boolean;
53
- put(entry: Entry<T>, options?: CacheUpdateOptions): Promise<void>;
54
- putAll(entries: Entry<T>[], options?: CacheUpdateOptions): Promise<void>;
55
- resetHeadsCache(): Promise<void>;
56
- updateHeadsCache(change?: {
57
- added?: (Entry<T> | string)[];
58
- removed?: (Entry<T> | string)[];
59
- }, reset?: boolean): Promise<void>;
60
- private _putOne;
61
- private _putAll;
62
- del(entry: {
63
- hash: string;
64
- meta: {
65
- gid: string;
66
- };
67
- }, options?: CacheUpdateOptions): Promise<boolean>;
68
- }
69
- export {};
70
- //# sourceMappingURL=heads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"heads.d.ts","sourceRoot":"","sources":["../../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EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;KAC3B,EACN,KAAK,CAAC,EAAE,OAAO;YAKF,OAAO;YA0BP,OAAO;IAMf,GAAG,CACR,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EAC9C,OAAO,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,OAAO,CAAC;CA+BnB"}
package/dist/src/heads.js DELETED
@@ -1,164 +0,0 @@
1
- import { Entry } from "./entry.js";
2
- import {} from "@peerbit/any-store";
3
- import { HeadsCache } from "./heads-cache.js";
4
- import {} from "@peerbit/blocks-interface";
5
- import {} from "@peerbit/keychain";
6
- import {} from "./encoding.js";
7
- import { Values } from "./values.js";
8
- import { logger } from "./logger.js";
9
- import { EntryIndex } from "./entry-index.js";
10
- export class HeadsIndex {
11
- _id;
12
- _index = new Set();
13
- _gids; // gid -> hash -> entry
14
- _headsCache;
15
- _config;
16
- _onGidRemoved;
17
- constructor(id) {
18
- this._gids = new Map();
19
- this._id = id;
20
- }
21
- async init(log, options = {}) {
22
- this._config = log;
23
- this._onGidRemoved = options.onGidRemoved;
24
- await this.reset(options?.entries || []);
25
- if (log.memory) {
26
- this._headsCache = new HeadsCache(this);
27
- return this._headsCache.init(await log.memory.sublevel("heads"));
28
- }
29
- }
30
- async load(options) {
31
- if (!this._headsCache || (this._headsCache.loaded && !options?.reload)) {
32
- return;
33
- }
34
- // TODO make below into a promise that concurrenct caklls can wait on?
35
- const heads = await this._headsCache?.load();
36
- if (!heads) {
37
- return;
38
- }
39
- const entries = await Promise.all(heads.map(async (x) => {
40
- const entry = await this._config.entryIndex.get(x, { load: true });
41
- if (!entry) {
42
- if (options?.ignoreMissing) {
43
- logger.error("Failed to load entry from head with hash: " + x);
44
- return;
45
- }
46
- else {
47
- throw new Error("Failed to load entry from head with hash: " + x);
48
- }
49
- }
50
- await entry.getMeta(); // TODO types,decrypt gid
51
- return entry;
52
- }));
53
- const filtered = entries.filter((x) => !!x);
54
- await this.reset(filtered);
55
- return filtered;
56
- }
57
- get headsCache() {
58
- return this._headsCache;
59
- }
60
- close() {
61
- return this._headsCache?.close();
62
- }
63
- drop() {
64
- return this._headsCache?.drop();
65
- }
66
- get id() {
67
- return this._id;
68
- }
69
- get index() {
70
- return this._index;
71
- }
72
- get gids() {
73
- return this._gids;
74
- }
75
- get size() {
76
- return this._index.size;
77
- }
78
- async reset(entries, options = { cache: { reset: true, update: true } }) {
79
- this._index.clear();
80
- const gidKeys = [...this._gids.keys()];
81
- this._gids = new Map();
82
- if (entries?.length > 0) {
83
- await this.putAll(entries, options); // reset cache = true
84
- }
85
- if (gidKeys.length > 0) {
86
- this._onGidRemoved?.(gidKeys);
87
- }
88
- }
89
- has(cid) {
90
- return this._index.has(cid);
91
- }
92
- async put(entry, options) {
93
- await this._putOne(entry);
94
- if (!options?.cache || options?.cache?.update) {
95
- await this._headsCache?.queue({ added: [entry] }, options?.cache?.reset);
96
- }
97
- }
98
- async putAll(entries, options) {
99
- await this._putAll(entries);
100
- if (!options?.cache || options?.cache?.update) {
101
- await this._headsCache?.queue({ added: entries }, options?.cache?.reset);
102
- }
103
- }
104
- async resetHeadsCache() {
105
- await this._headsCache?.queue({ added: [...this._index], removed: [] }, true);
106
- }
107
- async updateHeadsCache(change = {}, reset) {
108
- await this._headsCache?.queue(change, reset);
109
- }
110
- async _putOne(entry) {
111
- if (!entry.hash) {
112
- throw new Error("Missing hash");
113
- }
114
- if (this._index.has(entry.hash)) {
115
- return;
116
- }
117
- this._index.add(entry.hash);
118
- const map = this._gids.get(entry.meta.gid);
119
- if (!map) {
120
- const newMap = new Map();
121
- this._gids.set(entry.meta.gid, newMap);
122
- newMap.set(entry.hash, entry);
123
- }
124
- else {
125
- map.set(entry.hash, entry);
126
- }
127
- for (const next of entry.next) {
128
- const indexedEntry = this._config.entryIndex.getShallow(next);
129
- if (indexedEntry) {
130
- await this.del(indexedEntry, { cache: { update: false } }); // we dont update cache here because the put will update the cache that is calling _putOne
131
- }
132
- }
133
- }
134
- async _putAll(entries) {
135
- for (const entry of entries) {
136
- await this._putOne(entry);
137
- }
138
- }
139
- async del(entry, options) {
140
- const wasHead = this._index.delete(entry.hash);
141
- if (!wasHead) {
142
- return false;
143
- }
144
- let removedGids = undefined;
145
- const map = this._gids.get(entry.meta.gid);
146
- map.delete(entry.hash);
147
- if (map.size <= 0) {
148
- this._gids.delete(entry.meta.gid);
149
- (removedGids || (removedGids = new Set())).add(entry.meta.gid);
150
- }
151
- if (!entry.hash) {
152
- throw new Error("Missing hash");
153
- }
154
- if (removedGids) {
155
- await this._onGidRemoved?.([...removedGids]);
156
- }
157
- if (wasHead && !(options?.cache || options?.cache?.update)) {
158
- await this._headsCache?.queue({ removed: [entry.hash] }, options?.cache?.reset);
159
- }
160
- return wasHead;
161
- // this._headsCache = undefined; // TODO do smarter things here, only remove the element needed (?)
162
- }
163
- }
164
- //# sourceMappingURL=heads.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"heads.js","sourceRoot":"","sources":["../../src/heads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAe,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAiB,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAiB,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAc9C,MAAM,OAAO,UAAU;IACd,GAAG,CAAa;IAChB,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAC;IAChC,KA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AE,CAAC;YACjB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,CAAC,WAAW,EAAE,KAAK,CAC5B,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EACzB,OAAO,EAAE,KAAK,EAAE,KAAK,CACrB,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;QACf,uGAAuG;IACxG,CAAC;CACD"}
@@ -1,7 +0,0 @@
1
- export declare class StringArray {
2
- arr: string[];
3
- constructor(properties: {
4
- arr: string[];
5
- });
6
- }
7
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,qBAAa,WAAW;IAEvB,GAAG,EAAE,MAAM,EAAE,CAAC;gBAEF,UAAU,EAAE;QAAE,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE;CAGzC"}
package/dist/src/types.js DELETED
@@ -1,21 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { field, vec } from "@dao-xyz/borsh";
11
- export class StringArray {
12
- arr;
13
- constructor(properties) {
14
- this.arr = properties.arr;
15
- }
16
- }
17
- __decorate([
18
- field({ type: vec("string") }),
19
- __metadata("design:type", Array)
20
- ], StringArray.prototype, "arr", void 0);
21
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,OAAO,WAAW;IAEvB,GAAG,CAAW;IAEd,YAAY,UAA6B;QACxC,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;IAC3B,CAAC;CACD;AALA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;;wCACjB"}
@@ -1,27 +0,0 @@
1
- import { Entry } from "./entry.js";
2
- import { type ISortFunction } from "./log-sorting.js";
3
- import yallist from "yallist";
4
- import { EntryIndex } from "./entry-index.js";
5
- export type EntryNode = yallist.Node<string>;
6
- export declare class Values<T> {
7
- /**
8
- * Keep track of sorted elements in descending sort order (i.e. newest elements)
9
- */
10
- private _values;
11
- private _sortFn;
12
- private _byteLength;
13
- private _entryIndex;
14
- constructor(entryIndex: EntryIndex<T>, sortFn: ISortFunction, entries?: Entry<T>[]);
15
- toArray(): Promise<Entry<T>[]>;
16
- get head(): yallist.Node<string> | null;
17
- get tail(): yallist.Node<string> | null;
18
- get length(): number;
19
- get entryIndex(): EntryIndex<T>;
20
- put(value: Entry<T>): void;
21
- _put(value: Entry<T>): void;
22
- delete(value: Entry<T> | string): Promise<void>;
23
- deleteNode(node: EntryNode): void;
24
- pop(): string | undefined;
25
- get byteLength(): number;
26
- }
27
- //# sourceMappingURL=values.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../src/values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7C,qBAAa,MAAM,CAAC,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAgB;gBAGlC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,KAAK,CAAC,CAAC,CAAC,EAAO;IA4BzB,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAM9B,IAAI,IAAI,gCAEP;IACD,IAAI,IAAI,gCAEP;IACD,IAAI,MAAM,WAET;IAED,IAAI,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC,CAE9B;IACD,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAGnB,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IA6Bd,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM;IAwBrC,UAAU,CAAC,IAAI,EAAE,SAAS;IAQ1B,GAAG;IAQH,IAAI,UAAU,WAEb;CACD"}
@@ -1,130 +0,0 @@
1
- import { Entry } from "./entry.js";
2
- import {} from "./log-sorting.js";
3
- import yallist from "yallist";
4
- import { EntryIndex } from "./entry-index.js";
5
- export class Values {
6
- /**
7
- * Keep track of sorted elements in descending sort order (i.e. newest elements)
8
- */
9
- _values;
10
- _sortFn;
11
- _byteLength;
12
- _entryIndex;
13
- constructor(entryIndex, sortFn, entries = []) {
14
- this._values = yallist.create(entries
15
- .slice()
16
- .sort(sortFn)
17
- .reverse()
18
- .map((x) => {
19
- if (!x.hash)
20
- throw new Error("Unexpected");
21
- return x.hash; /* {
22
- hash: x.hash,
23
- byteLength: x._payload.byteLength,
24
- meta: {
25
- gids: x.gids,
26
- gid: x.gid,
27
- data: x.meta.data,
28
- },
29
- }; */
30
- }));
31
- this._byteLength = 0;
32
- entries.forEach((entry) => {
33
- this._byteLength += entry._payload.byteLength;
34
- });
35
- this._sortFn = sortFn;
36
- this._entryIndex = entryIndex;
37
- }
38
- toArray() {
39
- return Promise.all(this._values.toArrayReverse().map((x) => this._entryIndex.get(x))).then((arr) => arr.filter((x) => !!x)); // we do reverse because we assume the log is only meaningful if we read it from start to end
40
- }
41
- get head() {
42
- return this._values.head;
43
- }
44
- get tail() {
45
- return this._values.tail;
46
- }
47
- get length() {
48
- return this._values.length;
49
- }
50
- get entryIndex() {
51
- return this._entryIndex;
52
- }
53
- put(value) {
54
- return this._put(value);
55
- }
56
- _put(value) {
57
- // assume we want to insert at head (or somehere close)
58
- let walker = this._values.head;
59
- let last = undefined;
60
- while (walker) {
61
- const walkerValue = this._entryIndex.getShallow(walker.value);
62
- if (!walkerValue) {
63
- throw new Error("Missing walker value");
64
- }
65
- if (walkerValue.hash === value.hash) {
66
- return; // already exist!
67
- }
68
- if (this._sortFn(walkerValue, value) < 0) {
69
- break;
70
- }
71
- last = walker;
72
- walker = walker.next;
73
- continue;
74
- }
75
- this._byteLength += value._payload.byteLength;
76
- if (!value.hash) {
77
- throw new Error("Unexpected");
78
- }
79
- _insertAfter(this._values, last, value.hash);
80
- }
81
- async delete(value) {
82
- const hash = typeof value === "string" ? value : value.hash;
83
- // Assume we want to delete at tail (or somwhere close)
84
- let walker = this._values.tail;
85
- while (walker) {
86
- const walkerValue = this._entryIndex.getShallow(walker.value);
87
- if (!walkerValue) {
88
- throw new Error("Missing walker value");
89
- }
90
- if (walkerValue.hash === hash) {
91
- this._values.removeNode(walker);
92
- this._byteLength -= walkerValue.payloadByteLength;
93
- return;
94
- }
95
- walker = walker.prev; // prev will be undefined if you do removeNode(walker)
96
- }
97
- throw new Error(`Failed to delete. Could not find value with hash ${hash} in values list`);
98
- }
99
- deleteNode(node) {
100
- this._values.removeNode(node);
101
- this._byteLength -= this._entryIndex.getShallow(node.value).payloadByteLength;
102
- return;
103
- }
104
- pop() {
105
- const value = this._values.pop();
106
- if (value) {
107
- this._byteLength -= this._entryIndex.getShallow(value).payloadByteLength;
108
- }
109
- return value;
110
- }
111
- get byteLength() {
112
- return this._byteLength;
113
- }
114
- }
115
- function _insertAfter(self, node, value) {
116
- const inserted = !node
117
- ? new yallist.Node(value, null, self.head, self)
118
- : new yallist.Node(value, node, node.next, self);
119
- // is tail
120
- if (inserted.next === null) {
121
- self.tail = inserted;
122
- }
123
- // is head
124
- if (inserted.prev === null) {
125
- self.head = inserted;
126
- }
127
- self.length++;
128
- return inserted;
129
- }
130
- //# sourceMappingURL=values.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAsB,MAAM,kBAAkB,CAAC;AACtD,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C,MAAM,OAAO,MAAM;IAClB;;OAEG;IACK,OAAO,CAAkB;IACzB,OAAO,CAAgB;IACvB,WAAW,CAAS;IACpB,WAAW,CAAgB;IAEnC,YACC,UAAyB,EACzB,MAAqB,EACrB,UAAsB,EAAE;QAExB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAC5B,OAAO;aACL,KAAK,EAAE;aACP,IAAI,CAAC,MAAM,CAAC;aACZ,OAAO,EAAE;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACV,IAAI,CAAC,CAAC,CAAC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