@apibara/indexer 2.0.0-beta.9 → 2.1.0-beta.2
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/dist/index.cjs +271 -39
- package/dist/index.d.cts +1 -16
- package/dist/index.d.mts +1 -16
- package/dist/index.d.ts +1 -16
- package/dist/index.mjs +262 -25
- package/dist/internal/index.cjs +10 -0
- package/dist/internal/index.d.cts +3 -0
- package/dist/internal/index.d.mts +3 -0
- package/dist/internal/index.d.ts +3 -0
- package/dist/internal/index.mjs +8 -0
- package/dist/internal/plugins.cjs +38 -0
- package/dist/internal/plugins.d.cts +13 -0
- package/dist/internal/plugins.d.mts +13 -0
- package/dist/internal/plugins.d.ts +13 -0
- package/dist/internal/plugins.mjs +34 -0
- package/dist/internal/testing.cjs +118 -0
- package/dist/internal/testing.d.cts +42 -0
- package/dist/internal/testing.d.mts +42 -0
- package/dist/internal/testing.d.ts +42 -0
- package/dist/internal/testing.mjs +113 -0
- package/dist/plugins/index.cjs +39 -3
- package/dist/plugins/index.d.cts +16 -2
- package/dist/plugins/index.d.mts +16 -2
- package/dist/plugins/index.d.ts +16 -2
- package/dist/plugins/index.mjs +36 -3
- package/dist/shared/indexer.077335f3.cjs +15 -0
- package/dist/shared/indexer.2416906c.cjs +29 -0
- package/dist/shared/indexer.601ceab0.cjs +7 -0
- package/dist/shared/indexer.9b21ddd2.mjs +5 -0
- package/dist/shared/indexer.a55ad619.mjs +12 -0
- package/dist/shared/indexer.fedcd831.d.cts +100 -0
- package/dist/shared/indexer.fedcd831.d.mts +100 -0
- package/dist/shared/indexer.fedcd831.d.ts +100 -0
- package/dist/shared/indexer.ff25c953.mjs +26 -0
- package/dist/testing/index.cjs +52 -50
- package/dist/testing/index.d.cts +8 -36
- package/dist/testing/index.d.mts +8 -36
- package/dist/testing/index.d.ts +8 -36
- package/dist/testing/index.mjs +47 -47
- package/dist/vcr/index.cjs +84 -17
- package/dist/vcr/index.d.cts +16 -7
- package/dist/vcr/index.d.mts +16 -7
- package/dist/vcr/index.d.ts +16 -7
- package/dist/vcr/index.mjs +75 -11
- package/package.json +22 -42
- package/src/compose.test.ts +76 -0
- package/src/compose.ts +71 -0
- package/src/context.ts +14 -8
- package/src/index.ts +0 -5
- package/src/indexer.test.ts +125 -186
- package/src/indexer.ts +278 -151
- package/src/internal/index.ts +6 -0
- package/src/internal/plugins.ts +1 -0
- package/src/internal/testing.ts +148 -0
- package/src/plugins/config.ts +4 -4
- package/src/plugins/context.ts +40 -0
- package/src/plugins/index.ts +8 -1
- package/src/plugins/logger.ts +30 -0
- package/src/plugins/persistence.ts +24 -187
- package/src/testing/index.ts +58 -3
- package/src/vcr/record.ts +5 -3
- package/src/vcr/replay.ts +8 -18
- package/dist/plugins/kv.cjs +0 -131
- package/dist/plugins/kv.d.cts +0 -32
- package/dist/plugins/kv.d.mts +0 -32
- package/dist/plugins/kv.d.ts +0 -32
- package/dist/plugins/kv.mjs +0 -124
- package/dist/plugins/persistence.cjs +0 -182
- package/dist/plugins/persistence.d.cts +0 -50
- package/dist/plugins/persistence.d.mts +0 -50
- package/dist/plugins/persistence.d.ts +0 -50
- package/dist/plugins/persistence.mjs +0 -179
- package/dist/shared/indexer.2c23c9cd.mjs +0 -35
- package/dist/shared/indexer.318d3617.cjs +0 -47
- package/dist/shared/indexer.36530330.mjs +0 -249
- package/dist/shared/indexer.500fd281.d.cts +0 -23
- package/dist/shared/indexer.541d43eb.cjs +0 -266
- package/dist/shared/indexer.93d6b2eb.mjs +0 -17
- package/dist/shared/indexer.a8b7ab1f.cjs +0 -25
- package/dist/shared/indexer.b9c8f0d8.d.cts +0 -19
- package/dist/shared/indexer.b9c8f0d8.d.mts +0 -19
- package/dist/shared/indexer.b9c8f0d8.d.ts +0 -19
- package/dist/shared/indexer.c7ed6b83.d.cts +0 -82
- package/dist/shared/indexer.e1856641.d.mts +0 -23
- package/dist/shared/indexer.e4f2430f.d.ts +0 -23
- package/dist/shared/indexer.e8bd138d.d.mts +0 -82
- package/dist/shared/indexer.f761abcd.d.ts +0 -82
- package/dist/sinks/csv.cjs +0 -85
- package/dist/sinks/csv.d.cts +0 -66
- package/dist/sinks/csv.d.mts +0 -66
- package/dist/sinks/csv.d.ts +0 -66
- package/dist/sinks/csv.mjs +0 -78
- package/dist/sinks/drizzle/index.cjs +0 -212
- package/dist/sinks/drizzle/index.d.cts +0 -153
- package/dist/sinks/drizzle/index.d.mts +0 -153
- package/dist/sinks/drizzle/index.d.ts +0 -153
- package/dist/sinks/drizzle/index.mjs +0 -198
- package/dist/sinks/sqlite.cjs +0 -90
- package/dist/sinks/sqlite.d.cts +0 -71
- package/dist/sinks/sqlite.d.mts +0 -71
- package/dist/sinks/sqlite.d.ts +0 -71
- package/dist/sinks/sqlite.mjs +0 -87
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useKVStore.ts +0 -12
- package/src/hooks/useSink.ts +0 -13
- package/src/plugins/kv.test.ts +0 -120
- package/src/plugins/kv.ts +0 -132
- package/src/plugins/persistence.test.ts +0 -151
- package/src/sink.ts +0 -36
- package/src/sinks/csv.test.ts +0 -65
- package/src/sinks/csv.ts +0 -159
- package/src/sinks/drizzle/Int8Range.ts +0 -52
- package/src/sinks/drizzle/delete.ts +0 -42
- package/src/sinks/drizzle/drizzle.test.ts +0 -239
- package/src/sinks/drizzle/drizzle.ts +0 -115
- package/src/sinks/drizzle/index.ts +0 -6
- package/src/sinks/drizzle/insert.ts +0 -42
- package/src/sinks/drizzle/select.ts +0 -44
- package/src/sinks/drizzle/transaction.ts +0 -49
- package/src/sinks/drizzle/update.ts +0 -47
- package/src/sinks/drizzle/utils.ts +0 -99
- package/src/sinks/sqlite.test.ts +0 -99
- package/src/sinks/sqlite.ts +0 -170
- package/src/testing/helper.ts +0 -13
- package/src/testing/indexer.ts +0 -35
- package/src/testing/setup.ts +0 -59
- package/src/testing/vcr.ts +0 -54
package/dist/plugins/kv.cjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('node:assert');
|
|
4
|
-
const helper = require('../shared/indexer.318d3617.cjs');
|
|
5
|
-
require('node:fs/promises');
|
|
6
|
-
require('node:path');
|
|
7
|
-
require('klona/full');
|
|
8
|
-
require('consola');
|
|
9
|
-
require('hookable');
|
|
10
|
-
require('node:fs');
|
|
11
|
-
require('@apibara/protocol/testing');
|
|
12
|
-
const plugins_index = require('./index.cjs');
|
|
13
|
-
require('node:async_hooks');
|
|
14
|
-
require('unctx');
|
|
15
|
-
require('@opentelemetry/api');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
18
|
-
|
|
19
|
-
const assert__default = /*#__PURE__*/_interopDefaultCompat(assert);
|
|
20
|
-
|
|
21
|
-
var __defProp = Object.defineProperty;
|
|
22
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
23
|
-
var __publicField = (obj, key, value) => {
|
|
24
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
|
-
return value;
|
|
26
|
-
};
|
|
27
|
-
function kv({
|
|
28
|
-
database
|
|
29
|
-
}) {
|
|
30
|
-
return plugins_index.defineIndexerPlugin((indexer) => {
|
|
31
|
-
indexer.hooks.hook("run:before", () => {
|
|
32
|
-
KVStore.initialize(database);
|
|
33
|
-
});
|
|
34
|
-
indexer.hooks.hook("handler:before", ({ finality, endCursor }) => {
|
|
35
|
-
const ctx = helper.useIndexerContext();
|
|
36
|
-
assert__default(endCursor, new Error("endCursor cannot be undefined"));
|
|
37
|
-
ctx.kv = new KVStore(database, finality, endCursor);
|
|
38
|
-
ctx.kv.beginTransaction();
|
|
39
|
-
});
|
|
40
|
-
indexer.hooks.hook("handler:after", () => {
|
|
41
|
-
const ctx = helper.useIndexerContext();
|
|
42
|
-
ctx.kv.commitTransaction();
|
|
43
|
-
ctx.kv = null;
|
|
44
|
-
});
|
|
45
|
-
indexer.hooks.hook("handler:exception", () => {
|
|
46
|
-
const ctx = helper.useIndexerContext();
|
|
47
|
-
ctx.kv.rollbackTransaction();
|
|
48
|
-
ctx.kv = null;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
class KVStore {
|
|
53
|
-
constructor(_db, _finality, _endCursor) {
|
|
54
|
-
this._db = _db;
|
|
55
|
-
this._finality = _finality;
|
|
56
|
-
this._endCursor = _endCursor;
|
|
57
|
-
/** Sqlite Queries Prepare Statements */
|
|
58
|
-
__publicField(this, "_beginTxnQuery");
|
|
59
|
-
__publicField(this, "_commitTxnQuery");
|
|
60
|
-
__publicField(this, "_rollbackTxnQuery");
|
|
61
|
-
__publicField(this, "_getQuery");
|
|
62
|
-
__publicField(this, "_updateToBlockQuery");
|
|
63
|
-
__publicField(this, "_insertIntoKvsQuery");
|
|
64
|
-
__publicField(this, "_delQuery");
|
|
65
|
-
this._beginTxnQuery = this._db.prepare(statements.beginTxn);
|
|
66
|
-
this._commitTxnQuery = this._db.prepare(statements.commitTxn);
|
|
67
|
-
this._rollbackTxnQuery = this._db.prepare(statements.rollbackTxn);
|
|
68
|
-
this._getQuery = this._db.prepare(statements.get);
|
|
69
|
-
this._updateToBlockQuery = this._db.prepare(statements.updateToBlock);
|
|
70
|
-
this._insertIntoKvsQuery = this._db.prepare(statements.insertIntoKvs);
|
|
71
|
-
this._delQuery = this._db.prepare(statements.del);
|
|
72
|
-
}
|
|
73
|
-
static initialize(db) {
|
|
74
|
-
db.prepare(statements.createTable).run();
|
|
75
|
-
}
|
|
76
|
-
beginTransaction() {
|
|
77
|
-
this._beginTxnQuery.run();
|
|
78
|
-
}
|
|
79
|
-
commitTransaction() {
|
|
80
|
-
this._commitTxnQuery.run();
|
|
81
|
-
}
|
|
82
|
-
rollbackTransaction() {
|
|
83
|
-
this._rollbackTxnQuery.run();
|
|
84
|
-
}
|
|
85
|
-
get(key) {
|
|
86
|
-
const row = this._getQuery.get(key);
|
|
87
|
-
return row ? helper.deserialize(row.v) : void 0;
|
|
88
|
-
}
|
|
89
|
-
put(key, value) {
|
|
90
|
-
this._updateToBlockQuery.run(Number(this._endCursor.orderKey), key);
|
|
91
|
-
this._insertIntoKvsQuery.run(
|
|
92
|
-
Number(this._endCursor.orderKey),
|
|
93
|
-
key,
|
|
94
|
-
helper.serialize(value)
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
del(key) {
|
|
98
|
-
this._delQuery.run(Number(this._endCursor.orderKey), key);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const statements = {
|
|
102
|
-
beginTxn: "BEGIN TRANSACTION",
|
|
103
|
-
commitTxn: "COMMIT TRANSACTION",
|
|
104
|
-
rollbackTxn: "ROLLBACK TRANSACTION",
|
|
105
|
-
createTable: `
|
|
106
|
-
CREATE TABLE IF NOT EXISTS kvs (
|
|
107
|
-
from_block INTEGER NOT NULL,
|
|
108
|
-
to_block INTEGER,
|
|
109
|
-
k TEXT NOT NULL,
|
|
110
|
-
v BLOB NOT NULL,
|
|
111
|
-
PRIMARY KEY (from_block, k)
|
|
112
|
-
);`,
|
|
113
|
-
get: `
|
|
114
|
-
SELECT v
|
|
115
|
-
FROM kvs
|
|
116
|
-
WHERE k = ? AND to_block IS NULL`,
|
|
117
|
-
updateToBlock: `
|
|
118
|
-
UPDATE kvs
|
|
119
|
-
SET to_block = ?
|
|
120
|
-
WHERE k = ? AND to_block IS NULL`,
|
|
121
|
-
insertIntoKvs: `
|
|
122
|
-
INSERT INTO kvs (from_block, to_block, k, v)
|
|
123
|
-
VALUES (?, NULL, ?, ?)`,
|
|
124
|
-
del: `
|
|
125
|
-
UPDATE kvs
|
|
126
|
-
SET to_block = ?
|
|
127
|
-
WHERE k = ? AND to_block IS NULL`
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
exports.KVStore = KVStore;
|
|
131
|
-
exports.kv = kv;
|
package/dist/plugins/kv.d.cts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { I as IndexerPlugin } from '../shared/indexer.c7ed6b83.cjs';
|
|
2
|
-
import { DataFinality, Cursor } from '@apibara/protocol';
|
|
3
|
-
import { Database } from 'better-sqlite3';
|
|
4
|
-
import 'hookable';
|
|
5
|
-
import '../shared/indexer.b9c8f0d8.cjs';
|
|
6
|
-
|
|
7
|
-
declare function kv<TFilter, TBlock, TTxnParams>({ database, }: {
|
|
8
|
-
database: Database;
|
|
9
|
-
}): IndexerPlugin<TFilter, TBlock, TTxnParams>;
|
|
10
|
-
declare class KVStore {
|
|
11
|
-
private _db;
|
|
12
|
-
private _finality;
|
|
13
|
-
private _endCursor;
|
|
14
|
-
/** Sqlite Queries Prepare Statements */
|
|
15
|
-
private _beginTxnQuery;
|
|
16
|
-
private _commitTxnQuery;
|
|
17
|
-
private _rollbackTxnQuery;
|
|
18
|
-
private _getQuery;
|
|
19
|
-
private _updateToBlockQuery;
|
|
20
|
-
private _insertIntoKvsQuery;
|
|
21
|
-
private _delQuery;
|
|
22
|
-
constructor(_db: Database, _finality: DataFinality, _endCursor: Cursor);
|
|
23
|
-
static initialize(db: Database): void;
|
|
24
|
-
beginTransaction(): void;
|
|
25
|
-
commitTransaction(): void;
|
|
26
|
-
rollbackTransaction(): void;
|
|
27
|
-
get<T>(key: string): T;
|
|
28
|
-
put<T>(key: string, value: T): void;
|
|
29
|
-
del(key: string): void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { KVStore, kv };
|
package/dist/plugins/kv.d.mts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { I as IndexerPlugin } from '../shared/indexer.e8bd138d.mjs';
|
|
2
|
-
import { DataFinality, Cursor } from '@apibara/protocol';
|
|
3
|
-
import { Database } from 'better-sqlite3';
|
|
4
|
-
import 'hookable';
|
|
5
|
-
import '../shared/indexer.b9c8f0d8.mjs';
|
|
6
|
-
|
|
7
|
-
declare function kv<TFilter, TBlock, TTxnParams>({ database, }: {
|
|
8
|
-
database: Database;
|
|
9
|
-
}): IndexerPlugin<TFilter, TBlock, TTxnParams>;
|
|
10
|
-
declare class KVStore {
|
|
11
|
-
private _db;
|
|
12
|
-
private _finality;
|
|
13
|
-
private _endCursor;
|
|
14
|
-
/** Sqlite Queries Prepare Statements */
|
|
15
|
-
private _beginTxnQuery;
|
|
16
|
-
private _commitTxnQuery;
|
|
17
|
-
private _rollbackTxnQuery;
|
|
18
|
-
private _getQuery;
|
|
19
|
-
private _updateToBlockQuery;
|
|
20
|
-
private _insertIntoKvsQuery;
|
|
21
|
-
private _delQuery;
|
|
22
|
-
constructor(_db: Database, _finality: DataFinality, _endCursor: Cursor);
|
|
23
|
-
static initialize(db: Database): void;
|
|
24
|
-
beginTransaction(): void;
|
|
25
|
-
commitTransaction(): void;
|
|
26
|
-
rollbackTransaction(): void;
|
|
27
|
-
get<T>(key: string): T;
|
|
28
|
-
put<T>(key: string, value: T): void;
|
|
29
|
-
del(key: string): void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { KVStore, kv };
|
package/dist/plugins/kv.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { I as IndexerPlugin } from '../shared/indexer.f761abcd.js';
|
|
2
|
-
import { DataFinality, Cursor } from '@apibara/protocol';
|
|
3
|
-
import { Database } from 'better-sqlite3';
|
|
4
|
-
import 'hookable';
|
|
5
|
-
import '../shared/indexer.b9c8f0d8.js';
|
|
6
|
-
|
|
7
|
-
declare function kv<TFilter, TBlock, TTxnParams>({ database, }: {
|
|
8
|
-
database: Database;
|
|
9
|
-
}): IndexerPlugin<TFilter, TBlock, TTxnParams>;
|
|
10
|
-
declare class KVStore {
|
|
11
|
-
private _db;
|
|
12
|
-
private _finality;
|
|
13
|
-
private _endCursor;
|
|
14
|
-
/** Sqlite Queries Prepare Statements */
|
|
15
|
-
private _beginTxnQuery;
|
|
16
|
-
private _commitTxnQuery;
|
|
17
|
-
private _rollbackTxnQuery;
|
|
18
|
-
private _getQuery;
|
|
19
|
-
private _updateToBlockQuery;
|
|
20
|
-
private _insertIntoKvsQuery;
|
|
21
|
-
private _delQuery;
|
|
22
|
-
constructor(_db: Database, _finality: DataFinality, _endCursor: Cursor);
|
|
23
|
-
static initialize(db: Database): void;
|
|
24
|
-
beginTransaction(): void;
|
|
25
|
-
commitTransaction(): void;
|
|
26
|
-
rollbackTransaction(): void;
|
|
27
|
-
get<T>(key: string): T;
|
|
28
|
-
put<T>(key: string, value: T): void;
|
|
29
|
-
del(key: string): void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { KVStore, kv };
|
package/dist/plugins/kv.mjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { u as useIndexerContext, d as deserialize, s as serialize } from '../shared/indexer.2c23c9cd.mjs';
|
|
3
|
-
import 'node:fs/promises';
|
|
4
|
-
import 'node:path';
|
|
5
|
-
import 'klona/full';
|
|
6
|
-
import 'consola';
|
|
7
|
-
import 'hookable';
|
|
8
|
-
import 'node:fs';
|
|
9
|
-
import '@apibara/protocol/testing';
|
|
10
|
-
import { defineIndexerPlugin } from './index.mjs';
|
|
11
|
-
import 'node:async_hooks';
|
|
12
|
-
import 'unctx';
|
|
13
|
-
import '@opentelemetry/api';
|
|
14
|
-
|
|
15
|
-
var __defProp = Object.defineProperty;
|
|
16
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
-
var __publicField = (obj, key, value) => {
|
|
18
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
|
-
return value;
|
|
20
|
-
};
|
|
21
|
-
function kv({
|
|
22
|
-
database
|
|
23
|
-
}) {
|
|
24
|
-
return defineIndexerPlugin((indexer) => {
|
|
25
|
-
indexer.hooks.hook("run:before", () => {
|
|
26
|
-
KVStore.initialize(database);
|
|
27
|
-
});
|
|
28
|
-
indexer.hooks.hook("handler:before", ({ finality, endCursor }) => {
|
|
29
|
-
const ctx = useIndexerContext();
|
|
30
|
-
assert(endCursor, new Error("endCursor cannot be undefined"));
|
|
31
|
-
ctx.kv = new KVStore(database, finality, endCursor);
|
|
32
|
-
ctx.kv.beginTransaction();
|
|
33
|
-
});
|
|
34
|
-
indexer.hooks.hook("handler:after", () => {
|
|
35
|
-
const ctx = useIndexerContext();
|
|
36
|
-
ctx.kv.commitTransaction();
|
|
37
|
-
ctx.kv = null;
|
|
38
|
-
});
|
|
39
|
-
indexer.hooks.hook("handler:exception", () => {
|
|
40
|
-
const ctx = useIndexerContext();
|
|
41
|
-
ctx.kv.rollbackTransaction();
|
|
42
|
-
ctx.kv = null;
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
class KVStore {
|
|
47
|
-
constructor(_db, _finality, _endCursor) {
|
|
48
|
-
this._db = _db;
|
|
49
|
-
this._finality = _finality;
|
|
50
|
-
this._endCursor = _endCursor;
|
|
51
|
-
/** Sqlite Queries Prepare Statements */
|
|
52
|
-
__publicField(this, "_beginTxnQuery");
|
|
53
|
-
__publicField(this, "_commitTxnQuery");
|
|
54
|
-
__publicField(this, "_rollbackTxnQuery");
|
|
55
|
-
__publicField(this, "_getQuery");
|
|
56
|
-
__publicField(this, "_updateToBlockQuery");
|
|
57
|
-
__publicField(this, "_insertIntoKvsQuery");
|
|
58
|
-
__publicField(this, "_delQuery");
|
|
59
|
-
this._beginTxnQuery = this._db.prepare(statements.beginTxn);
|
|
60
|
-
this._commitTxnQuery = this._db.prepare(statements.commitTxn);
|
|
61
|
-
this._rollbackTxnQuery = this._db.prepare(statements.rollbackTxn);
|
|
62
|
-
this._getQuery = this._db.prepare(statements.get);
|
|
63
|
-
this._updateToBlockQuery = this._db.prepare(statements.updateToBlock);
|
|
64
|
-
this._insertIntoKvsQuery = this._db.prepare(statements.insertIntoKvs);
|
|
65
|
-
this._delQuery = this._db.prepare(statements.del);
|
|
66
|
-
}
|
|
67
|
-
static initialize(db) {
|
|
68
|
-
db.prepare(statements.createTable).run();
|
|
69
|
-
}
|
|
70
|
-
beginTransaction() {
|
|
71
|
-
this._beginTxnQuery.run();
|
|
72
|
-
}
|
|
73
|
-
commitTransaction() {
|
|
74
|
-
this._commitTxnQuery.run();
|
|
75
|
-
}
|
|
76
|
-
rollbackTransaction() {
|
|
77
|
-
this._rollbackTxnQuery.run();
|
|
78
|
-
}
|
|
79
|
-
get(key) {
|
|
80
|
-
const row = this._getQuery.get(key);
|
|
81
|
-
return row ? deserialize(row.v) : void 0;
|
|
82
|
-
}
|
|
83
|
-
put(key, value) {
|
|
84
|
-
this._updateToBlockQuery.run(Number(this._endCursor.orderKey), key);
|
|
85
|
-
this._insertIntoKvsQuery.run(
|
|
86
|
-
Number(this._endCursor.orderKey),
|
|
87
|
-
key,
|
|
88
|
-
serialize(value)
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
del(key) {
|
|
92
|
-
this._delQuery.run(Number(this._endCursor.orderKey), key);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const statements = {
|
|
96
|
-
beginTxn: "BEGIN TRANSACTION",
|
|
97
|
-
commitTxn: "COMMIT TRANSACTION",
|
|
98
|
-
rollbackTxn: "ROLLBACK TRANSACTION",
|
|
99
|
-
createTable: `
|
|
100
|
-
CREATE TABLE IF NOT EXISTS kvs (
|
|
101
|
-
from_block INTEGER NOT NULL,
|
|
102
|
-
to_block INTEGER,
|
|
103
|
-
k TEXT NOT NULL,
|
|
104
|
-
v BLOB NOT NULL,
|
|
105
|
-
PRIMARY KEY (from_block, k)
|
|
106
|
-
);`,
|
|
107
|
-
get: `
|
|
108
|
-
SELECT v
|
|
109
|
-
FROM kvs
|
|
110
|
-
WHERE k = ? AND to_block IS NULL`,
|
|
111
|
-
updateToBlock: `
|
|
112
|
-
UPDATE kvs
|
|
113
|
-
SET to_block = ?
|
|
114
|
-
WHERE k = ? AND to_block IS NULL`,
|
|
115
|
-
insertIntoKvs: `
|
|
116
|
-
INSERT INTO kvs (from_block, to_block, k, v)
|
|
117
|
-
VALUES (?, NULL, ?, ?)`,
|
|
118
|
-
del: `
|
|
119
|
-
UPDATE kvs
|
|
120
|
-
SET to_block = ?
|
|
121
|
-
WHERE k = ? AND to_block IS NULL`
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export { KVStore, kv };
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const helper = require('../shared/indexer.318d3617.cjs');
|
|
4
|
-
require('node:fs/promises');
|
|
5
|
-
require('node:path');
|
|
6
|
-
require('klona/full');
|
|
7
|
-
require('consola');
|
|
8
|
-
require('hookable');
|
|
9
|
-
require('node:assert');
|
|
10
|
-
require('node:fs');
|
|
11
|
-
require('@apibara/protocol/testing');
|
|
12
|
-
const plugins_index = require('./index.cjs');
|
|
13
|
-
require('node:async_hooks');
|
|
14
|
-
require('unctx');
|
|
15
|
-
require('@opentelemetry/api');
|
|
16
|
-
|
|
17
|
-
var __defProp = Object.defineProperty;
|
|
18
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
19
|
-
var __publicField = (obj, key, value) => {
|
|
20
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
function sqlitePersistence({
|
|
24
|
-
database
|
|
25
|
-
}) {
|
|
26
|
-
return plugins_index.defineIndexerPlugin((indexer) => {
|
|
27
|
-
let store;
|
|
28
|
-
indexer.hooks.hook("run:before", () => {
|
|
29
|
-
SqlitePersistence.initialize(database);
|
|
30
|
-
store = new SqlitePersistence(database);
|
|
31
|
-
});
|
|
32
|
-
indexer.hooks.hook("connect:before", ({ request }) => {
|
|
33
|
-
const { cursor, filter } = store.get();
|
|
34
|
-
if (cursor) {
|
|
35
|
-
request.startingCursor = cursor;
|
|
36
|
-
}
|
|
37
|
-
if (filter) {
|
|
38
|
-
request.filter[1] = filter;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
indexer.hooks.hook("transaction:commit", ({ endCursor }) => {
|
|
42
|
-
if (endCursor) {
|
|
43
|
-
store.put({ cursor: endCursor });
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
indexer.hooks.hook("connect:factory", ({ request, endCursor }) => {
|
|
47
|
-
if (request.filter[1]) {
|
|
48
|
-
store.put({ cursor: endCursor, filter: request.filter[1] });
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
class SqlitePersistence {
|
|
54
|
-
constructor(_db) {
|
|
55
|
-
this._db = _db;
|
|
56
|
-
/** Sqlite Queries Prepare Statements */
|
|
57
|
-
__publicField(this, "_getCheckpointQuery");
|
|
58
|
-
__publicField(this, "_putCheckpointQuery");
|
|
59
|
-
__publicField(this, "_delCheckpointQuery");
|
|
60
|
-
__publicField(this, "_getFilterQuery");
|
|
61
|
-
__publicField(this, "_updateFilterToBlockQuery");
|
|
62
|
-
__publicField(this, "_insertFilterQuery");
|
|
63
|
-
__publicField(this, "_delFilterQuery");
|
|
64
|
-
this._getCheckpointQuery = this._db.prepare(statements.getCheckpoint);
|
|
65
|
-
this._putCheckpointQuery = this._db.prepare(statements.putCheckpoint);
|
|
66
|
-
this._delCheckpointQuery = this._db.prepare(statements.delCheckpoint);
|
|
67
|
-
this._getFilterQuery = this._db.prepare(statements.getFilter);
|
|
68
|
-
this._updateFilterToBlockQuery = this._db.prepare(
|
|
69
|
-
statements.updateFilterToBlock
|
|
70
|
-
);
|
|
71
|
-
this._insertFilterQuery = this._db.prepare(statements.insertFilter);
|
|
72
|
-
this._delFilterQuery = this._db.prepare(statements.delFilter);
|
|
73
|
-
}
|
|
74
|
-
static initialize(db) {
|
|
75
|
-
db.prepare(statements.createCheckpointsTable).run();
|
|
76
|
-
db.prepare(statements.createFiltersTable).run();
|
|
77
|
-
}
|
|
78
|
-
get() {
|
|
79
|
-
const cursor = this._getCheckpoint();
|
|
80
|
-
const filter = this._getFilter();
|
|
81
|
-
return { cursor, filter };
|
|
82
|
-
}
|
|
83
|
-
put({ cursor, filter }) {
|
|
84
|
-
if (cursor) {
|
|
85
|
-
this._putCheckpoint(cursor);
|
|
86
|
-
if (filter) {
|
|
87
|
-
this._putFilter(filter, cursor);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
del() {
|
|
92
|
-
this._delCheckpoint();
|
|
93
|
-
this._delFilter();
|
|
94
|
-
}
|
|
95
|
-
// --- CHECKPOINTS TABLE METHODS ---
|
|
96
|
-
_getCheckpoint() {
|
|
97
|
-
const row = this._getCheckpointQuery.get("default");
|
|
98
|
-
if (!row)
|
|
99
|
-
return void 0;
|
|
100
|
-
return { orderKey: BigInt(row.order_key), uniqueKey: row.unique_key };
|
|
101
|
-
}
|
|
102
|
-
_putCheckpoint(cursor) {
|
|
103
|
-
this._putCheckpointQuery.run(
|
|
104
|
-
"default",
|
|
105
|
-
Number(cursor.orderKey),
|
|
106
|
-
cursor.uniqueKey
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
_delCheckpoint() {
|
|
110
|
-
this._delCheckpointQuery.run("default");
|
|
111
|
-
}
|
|
112
|
-
// --- FILTERS TABLE METHODS ---
|
|
113
|
-
_getFilter() {
|
|
114
|
-
const row = this._getFilterQuery.get("default");
|
|
115
|
-
if (!row)
|
|
116
|
-
return void 0;
|
|
117
|
-
return helper.deserialize(row.filter);
|
|
118
|
-
}
|
|
119
|
-
_putFilter(filter, endCursor) {
|
|
120
|
-
this._updateFilterToBlockQuery.run(Number(endCursor.orderKey), "default");
|
|
121
|
-
this._insertFilterQuery.run(
|
|
122
|
-
"default",
|
|
123
|
-
helper.serialize(filter),
|
|
124
|
-
Number(endCursor.orderKey)
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
_delFilter() {
|
|
128
|
-
this._delFilterQuery.run("default");
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
const statements = {
|
|
132
|
-
beginTxn: "BEGIN TRANSACTION",
|
|
133
|
-
commitTxn: "COMMIT TRANSACTION",
|
|
134
|
-
rollbackTxn: "ROLLBACK TRANSACTION",
|
|
135
|
-
createCheckpointsTable: `
|
|
136
|
-
CREATE TABLE IF NOT EXISTS checkpoints (
|
|
137
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
138
|
-
order_key INTEGER NOT NULL,
|
|
139
|
-
unique_key TEXT
|
|
140
|
-
);`,
|
|
141
|
-
createFiltersTable: `
|
|
142
|
-
CREATE TABLE IF NOT EXISTS filters (
|
|
143
|
-
id TEXT NOT NULL,
|
|
144
|
-
filter BLOB NOT NULL,
|
|
145
|
-
from_block INTEGER NOT NULL,
|
|
146
|
-
to_block INTEGER,
|
|
147
|
-
PRIMARY KEY (id, from_block)
|
|
148
|
-
);`,
|
|
149
|
-
getCheckpoint: `
|
|
150
|
-
SELECT *
|
|
151
|
-
FROM checkpoints
|
|
152
|
-
WHERE id = ?`,
|
|
153
|
-
putCheckpoint: `
|
|
154
|
-
INSERT INTO checkpoints (id, order_key, unique_key)
|
|
155
|
-
VALUES (?, ?, ?)
|
|
156
|
-
ON CONFLICT(id) DO UPDATE SET
|
|
157
|
-
order_key = excluded.order_key,
|
|
158
|
-
unique_key = excluded.unique_key`,
|
|
159
|
-
delCheckpoint: `
|
|
160
|
-
DELETE FROM checkpoints
|
|
161
|
-
WHERE id = ?`,
|
|
162
|
-
getFilter: `
|
|
163
|
-
SELECT *
|
|
164
|
-
FROM filters
|
|
165
|
-
WHERE id = ? AND to_block IS NULL`,
|
|
166
|
-
updateFilterToBlock: `
|
|
167
|
-
UPDATE filters
|
|
168
|
-
SET to_block = ?
|
|
169
|
-
WHERE id = ? AND to_block IS NULL`,
|
|
170
|
-
insertFilter: `
|
|
171
|
-
INSERT INTO filters (id, filter, from_block)
|
|
172
|
-
VALUES (?, ?, ?)
|
|
173
|
-
ON CONFLICT(id, from_block) DO UPDATE SET
|
|
174
|
-
filter = excluded.filter,
|
|
175
|
-
from_block = excluded.from_block`,
|
|
176
|
-
delFilter: `
|
|
177
|
-
DELETE FROM filters
|
|
178
|
-
WHERE id = ?`
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
exports.SqlitePersistence = SqlitePersistence;
|
|
182
|
-
exports.sqlitePersistence = sqlitePersistence;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { I as IndexerPlugin } from '../shared/indexer.c7ed6b83.cjs';
|
|
2
|
-
import { Cursor } from '@apibara/protocol';
|
|
3
|
-
import { Database } from 'better-sqlite3';
|
|
4
|
-
import 'hookable';
|
|
5
|
-
import '../shared/indexer.b9c8f0d8.cjs';
|
|
6
|
-
|
|
7
|
-
declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
|
|
8
|
-
database: Database;
|
|
9
|
-
}): IndexerPlugin<TFilter, TBlock, TTxnParams>;
|
|
10
|
-
declare class SqlitePersistence<TFilter> {
|
|
11
|
-
private _db;
|
|
12
|
-
/** Sqlite Queries Prepare Statements */
|
|
13
|
-
private _getCheckpointQuery;
|
|
14
|
-
private _putCheckpointQuery;
|
|
15
|
-
private _delCheckpointQuery;
|
|
16
|
-
private _getFilterQuery;
|
|
17
|
-
private _updateFilterToBlockQuery;
|
|
18
|
-
private _insertFilterQuery;
|
|
19
|
-
private _delFilterQuery;
|
|
20
|
-
constructor(_db: Database);
|
|
21
|
-
static initialize(db: Database): void;
|
|
22
|
-
get(): {
|
|
23
|
-
cursor?: Cursor;
|
|
24
|
-
filter?: TFilter;
|
|
25
|
-
};
|
|
26
|
-
put({ cursor, filter }: {
|
|
27
|
-
cursor?: Cursor;
|
|
28
|
-
filter?: TFilter;
|
|
29
|
-
}): void;
|
|
30
|
-
del(): void;
|
|
31
|
-
private _getCheckpoint;
|
|
32
|
-
private _putCheckpoint;
|
|
33
|
-
private _delCheckpoint;
|
|
34
|
-
private _getFilter;
|
|
35
|
-
private _putFilter;
|
|
36
|
-
private _delFilter;
|
|
37
|
-
}
|
|
38
|
-
type CheckpointRow = {
|
|
39
|
-
id: string;
|
|
40
|
-
order_key: number;
|
|
41
|
-
unique_key?: `0x${string}`;
|
|
42
|
-
};
|
|
43
|
-
type FilterRow = {
|
|
44
|
-
id: string;
|
|
45
|
-
filter: string;
|
|
46
|
-
from_block: number;
|
|
47
|
-
to_block?: number;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export { type CheckpointRow, type FilterRow, SqlitePersistence, sqlitePersistence };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { I as IndexerPlugin } from '../shared/indexer.e8bd138d.mjs';
|
|
2
|
-
import { Cursor } from '@apibara/protocol';
|
|
3
|
-
import { Database } from 'better-sqlite3';
|
|
4
|
-
import 'hookable';
|
|
5
|
-
import '../shared/indexer.b9c8f0d8.mjs';
|
|
6
|
-
|
|
7
|
-
declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
|
|
8
|
-
database: Database;
|
|
9
|
-
}): IndexerPlugin<TFilter, TBlock, TTxnParams>;
|
|
10
|
-
declare class SqlitePersistence<TFilter> {
|
|
11
|
-
private _db;
|
|
12
|
-
/** Sqlite Queries Prepare Statements */
|
|
13
|
-
private _getCheckpointQuery;
|
|
14
|
-
private _putCheckpointQuery;
|
|
15
|
-
private _delCheckpointQuery;
|
|
16
|
-
private _getFilterQuery;
|
|
17
|
-
private _updateFilterToBlockQuery;
|
|
18
|
-
private _insertFilterQuery;
|
|
19
|
-
private _delFilterQuery;
|
|
20
|
-
constructor(_db: Database);
|
|
21
|
-
static initialize(db: Database): void;
|
|
22
|
-
get(): {
|
|
23
|
-
cursor?: Cursor;
|
|
24
|
-
filter?: TFilter;
|
|
25
|
-
};
|
|
26
|
-
put({ cursor, filter }: {
|
|
27
|
-
cursor?: Cursor;
|
|
28
|
-
filter?: TFilter;
|
|
29
|
-
}): void;
|
|
30
|
-
del(): void;
|
|
31
|
-
private _getCheckpoint;
|
|
32
|
-
private _putCheckpoint;
|
|
33
|
-
private _delCheckpoint;
|
|
34
|
-
private _getFilter;
|
|
35
|
-
private _putFilter;
|
|
36
|
-
private _delFilter;
|
|
37
|
-
}
|
|
38
|
-
type CheckpointRow = {
|
|
39
|
-
id: string;
|
|
40
|
-
order_key: number;
|
|
41
|
-
unique_key?: `0x${string}`;
|
|
42
|
-
};
|
|
43
|
-
type FilterRow = {
|
|
44
|
-
id: string;
|
|
45
|
-
filter: string;
|
|
46
|
-
from_block: number;
|
|
47
|
-
to_block?: number;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export { type CheckpointRow, type FilterRow, SqlitePersistence, sqlitePersistence };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { I as IndexerPlugin } from '../shared/indexer.f761abcd.js';
|
|
2
|
-
import { Cursor } from '@apibara/protocol';
|
|
3
|
-
import { Database } from 'better-sqlite3';
|
|
4
|
-
import 'hookable';
|
|
5
|
-
import '../shared/indexer.b9c8f0d8.js';
|
|
6
|
-
|
|
7
|
-
declare function sqlitePersistence<TFilter, TBlock, TTxnParams>({ database, }: {
|
|
8
|
-
database: Database;
|
|
9
|
-
}): IndexerPlugin<TFilter, TBlock, TTxnParams>;
|
|
10
|
-
declare class SqlitePersistence<TFilter> {
|
|
11
|
-
private _db;
|
|
12
|
-
/** Sqlite Queries Prepare Statements */
|
|
13
|
-
private _getCheckpointQuery;
|
|
14
|
-
private _putCheckpointQuery;
|
|
15
|
-
private _delCheckpointQuery;
|
|
16
|
-
private _getFilterQuery;
|
|
17
|
-
private _updateFilterToBlockQuery;
|
|
18
|
-
private _insertFilterQuery;
|
|
19
|
-
private _delFilterQuery;
|
|
20
|
-
constructor(_db: Database);
|
|
21
|
-
static initialize(db: Database): void;
|
|
22
|
-
get(): {
|
|
23
|
-
cursor?: Cursor;
|
|
24
|
-
filter?: TFilter;
|
|
25
|
-
};
|
|
26
|
-
put({ cursor, filter }: {
|
|
27
|
-
cursor?: Cursor;
|
|
28
|
-
filter?: TFilter;
|
|
29
|
-
}): void;
|
|
30
|
-
del(): void;
|
|
31
|
-
private _getCheckpoint;
|
|
32
|
-
private _putCheckpoint;
|
|
33
|
-
private _delCheckpoint;
|
|
34
|
-
private _getFilter;
|
|
35
|
-
private _putFilter;
|
|
36
|
-
private _delFilter;
|
|
37
|
-
}
|
|
38
|
-
type CheckpointRow = {
|
|
39
|
-
id: string;
|
|
40
|
-
order_key: number;
|
|
41
|
-
unique_key?: `0x${string}`;
|
|
42
|
-
};
|
|
43
|
-
type FilterRow = {
|
|
44
|
-
id: string;
|
|
45
|
-
filter: string;
|
|
46
|
-
from_block: number;
|
|
47
|
-
to_block?: number;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export { type CheckpointRow, type FilterRow, SqlitePersistence, sqlitePersistence };
|