@apibara/indexer 2.0.0-beta.5 → 2.0.0-beta.7

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 (62) hide show
  1. package/dist/index.cjs +50 -0
  2. package/dist/index.d.cts +18 -0
  3. package/dist/index.d.mts +18 -0
  4. package/dist/index.d.ts +18 -0
  5. package/dist/index.mjs +34 -0
  6. package/dist/plugins/index.cjs +7 -0
  7. package/dist/plugins/index.d.cts +4 -0
  8. package/dist/plugins/index.d.mts +4 -0
  9. package/dist/plugins/index.d.ts +4 -0
  10. package/dist/plugins/index.mjs +5 -0
  11. package/dist/plugins/kv.cjs +131 -0
  12. package/dist/plugins/kv.d.cts +32 -0
  13. package/dist/plugins/kv.d.mts +32 -0
  14. package/dist/plugins/kv.d.ts +32 -0
  15. package/dist/plugins/kv.mjs +124 -0
  16. package/dist/plugins/persistence.cjs +182 -0
  17. package/dist/plugins/persistence.d.cts +50 -0
  18. package/dist/plugins/persistence.d.mts +50 -0
  19. package/dist/plugins/persistence.d.ts +50 -0
  20. package/dist/plugins/persistence.mjs +179 -0
  21. package/dist/shared/indexer.2c23c9cd.mjs +35 -0
  22. package/dist/shared/indexer.318d3617.cjs +47 -0
  23. package/dist/shared/indexer.36530330.mjs +249 -0
  24. package/dist/shared/indexer.500fd281.d.cts +23 -0
  25. package/dist/shared/indexer.541d43eb.cjs +266 -0
  26. package/dist/shared/indexer.93d6b2eb.mjs +17 -0
  27. package/dist/shared/indexer.a8b7ab1f.cjs +25 -0
  28. package/dist/shared/indexer.b9c8f0d8.d.cts +19 -0
  29. package/dist/shared/indexer.b9c8f0d8.d.mts +19 -0
  30. package/dist/shared/indexer.b9c8f0d8.d.ts +19 -0
  31. package/dist/shared/indexer.c7ed6b83.d.cts +82 -0
  32. package/dist/shared/indexer.e1856641.d.mts +23 -0
  33. package/dist/shared/indexer.e4f2430f.d.ts +23 -0
  34. package/dist/shared/indexer.e8bd138d.d.mts +82 -0
  35. package/dist/shared/indexer.f761abcd.d.ts +82 -0
  36. package/dist/sinks/csv.cjs +85 -0
  37. package/dist/sinks/csv.d.cts +66 -0
  38. package/dist/sinks/csv.d.mts +66 -0
  39. package/dist/sinks/csv.d.ts +66 -0
  40. package/dist/sinks/csv.mjs +78 -0
  41. package/dist/sinks/drizzle/index.cjs +210 -0
  42. package/dist/sinks/drizzle/index.d.cts +111 -0
  43. package/dist/sinks/drizzle/index.d.mts +111 -0
  44. package/dist/sinks/drizzle/index.d.ts +111 -0
  45. package/dist/sinks/drizzle/index.mjs +196 -0
  46. package/dist/sinks/sqlite.cjs +90 -0
  47. package/dist/sinks/sqlite.d.cts +71 -0
  48. package/dist/sinks/sqlite.d.mts +71 -0
  49. package/dist/sinks/sqlite.d.ts +71 -0
  50. package/dist/sinks/sqlite.mjs +87 -0
  51. package/dist/testing/index.cjs +64 -0
  52. package/dist/testing/index.d.cts +40 -0
  53. package/dist/testing/index.d.mts +40 -0
  54. package/dist/testing/index.d.ts +40 -0
  55. package/dist/testing/index.mjs +60 -0
  56. package/dist/vcr/index.cjs +25 -0
  57. package/dist/vcr/index.d.cts +18 -0
  58. package/dist/vcr/index.d.mts +18 -0
  59. package/dist/vcr/index.d.ts +18 -0
  60. package/dist/vcr/index.mjs +14 -0
  61. package/package.json +33 -11
  62. package/src/vcr/record.ts +1 -1
@@ -0,0 +1,249 @@
1
+ import { a as indexerAsyncContext, u as useIndexerContext, t as tracer, s as serialize, d as deserialize } from './indexer.2c23c9cd.mjs';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { klona } from 'klona/full';
5
+ import consola from 'consola';
6
+ import { createHooks, createDebugger } from 'hookable';
7
+ import assert from 'node:assert';
8
+ import { d as defaultSink, S as Sink } from './indexer.93d6b2eb.mjs';
9
+ import fs$1 from 'node:fs';
10
+ import { MockClient } from '@apibara/protocol/testing';
11
+
12
+ function defineIndexer(streamConfig) {
13
+ return (config) => ({
14
+ streamConfig,
15
+ ...config
16
+ });
17
+ }
18
+ function createIndexer({
19
+ streamConfig,
20
+ ...options
21
+ }) {
22
+ const indexer = {
23
+ options,
24
+ streamConfig,
25
+ hooks: createHooks()
26
+ };
27
+ if (indexer.options.debug) {
28
+ createDebugger(indexer.hooks, { tag: "indexer" });
29
+ }
30
+ indexer.hooks.addHooks(indexer.options.hooks ?? {});
31
+ for (const plugin of indexer.options.plugins ?? []) {
32
+ plugin(indexer);
33
+ }
34
+ return indexer;
35
+ }
36
+ async function run(client, indexer) {
37
+ await indexerAsyncContext.callAsync({}, async () => {
38
+ const context = useIndexerContext();
39
+ const sink = indexer.options.sink ?? defaultSink();
40
+ context.sink = sink;
41
+ await indexer.hooks.callHook("run:before");
42
+ const isFactoryMode = indexer.options.factory !== void 0;
43
+ const request = indexer.streamConfig.Request.make({
44
+ filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
45
+ finality: indexer.options.finality,
46
+ startingCursor: indexer.options.startingCursor
47
+ });
48
+ const options = {};
49
+ await indexer.hooks.callHook("connect:before", { request, options });
50
+ let mainFilter;
51
+ if (isFactoryMode) {
52
+ mainFilter = request.filter[1];
53
+ }
54
+ let stream = client.streamData(request, options)[Symbol.asyncIterator]();
55
+ await indexer.hooks.callHook("connect:after");
56
+ while (true) {
57
+ const { value: message, done } = await stream.next();
58
+ if (done) {
59
+ break;
60
+ }
61
+ await indexer.hooks.callHook("message", { message });
62
+ switch (message._tag) {
63
+ case "data": {
64
+ await tracer.startActiveSpan("message data", async (span) => {
65
+ const blocks = message.data.data;
66
+ const { cursor, endCursor, finality } = message.data;
67
+ await sink.transaction(
68
+ { cursor, endCursor, finality },
69
+ async (txn) => {
70
+ context.sinkTransaction = txn;
71
+ let block;
72
+ if (isFactoryMode) {
73
+ assert(indexer.options.factory !== void 0);
74
+ const [factoryBlock, mainBlock] = blocks;
75
+ block = mainBlock;
76
+ if (factoryBlock !== null) {
77
+ const { filter } = await indexer.options.factory({
78
+ block: factoryBlock,
79
+ context
80
+ });
81
+ if (filter) {
82
+ mainFilter = indexer.streamConfig.mergeFilter(
83
+ mainFilter,
84
+ filter
85
+ );
86
+ const request2 = indexer.streamConfig.Request.make({
87
+ filter: [indexer.options.filter, mainFilter],
88
+ finality: indexer.options.finality,
89
+ startingCursor: cursor
90
+ });
91
+ await indexer.hooks.callHook("connect:factory", {
92
+ request: request2,
93
+ endCursor
94
+ });
95
+ stream = client.streamData(request2, options)[Symbol.asyncIterator]();
96
+ const { value: message2 } = await stream.next();
97
+ assert(message2._tag === "data");
98
+ const [_factoryBlock, _block] = message2.data.data;
99
+ block = _block;
100
+ }
101
+ }
102
+ } else {
103
+ block = blocks[0];
104
+ }
105
+ if (block) {
106
+ await tracer.startActiveSpan("handler", async (span2) => {
107
+ await indexer.hooks.callHook("handler:before", {
108
+ block,
109
+ endCursor,
110
+ finality
111
+ });
112
+ try {
113
+ await indexer.options.transform({
114
+ block,
115
+ cursor,
116
+ endCursor,
117
+ finality,
118
+ context
119
+ });
120
+ await indexer.hooks.callHook("handler:after", {
121
+ block,
122
+ finality,
123
+ endCursor
124
+ });
125
+ } catch (error) {
126
+ assert(error instanceof Error);
127
+ await indexer.hooks.callHook("handler:exception", {
128
+ error
129
+ });
130
+ throw error;
131
+ }
132
+ span2.end();
133
+ });
134
+ }
135
+ }
136
+ );
137
+ await indexer.hooks.callHook("transaction:commit", {
138
+ finality,
139
+ endCursor
140
+ });
141
+ span.end();
142
+ });
143
+ break;
144
+ }
145
+ case "invalidate": {
146
+ await tracer.startActiveSpan("message invalidate", async (span) => {
147
+ await sink.invalidate(message.invalidate.cursor);
148
+ });
149
+ break;
150
+ }
151
+ default: {
152
+ consola.warn("unexpected message", message);
153
+ throw new Error("not implemented");
154
+ }
155
+ }
156
+ await indexer.hooks.callHook("run:after");
157
+ }
158
+ });
159
+ }
160
+
161
+ async function record(vcrConfig, client, indexerArg, cassetteOptions) {
162
+ const indexer = klona(indexerArg);
163
+ const messages = [];
164
+ indexer.hooks.addHooks({
165
+ "connect:before"({ options, request }) {
166
+ request.startingCursor = cassetteOptions.startingCursor;
167
+ options.endingCursor = cassetteOptions.endingCursor;
168
+ },
169
+ message({ message }) {
170
+ messages.push(message);
171
+ },
172
+ async "run:after"() {
173
+ const output = {
174
+ filter: indexer.options.filter,
175
+ messages
176
+ };
177
+ const filePath = path.join(
178
+ vcrConfig.cassetteDir,
179
+ `${cassetteOptions.name}.json`
180
+ );
181
+ await fs.writeFile(filePath, serialize(output), { flag: "w" });
182
+ }
183
+ });
184
+ await run(client, indexer);
185
+ }
186
+
187
+ var __defProp = Object.defineProperty;
188
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
189
+ var __publicField = (obj, key, value) => {
190
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
191
+ return value;
192
+ };
193
+ const transactionHelper = (context) => {
194
+ return {
195
+ insert: (data) => {
196
+ context.buffer.push(...data);
197
+ }
198
+ };
199
+ };
200
+ class VcrSink extends Sink {
201
+ constructor() {
202
+ super(...arguments);
203
+ __publicField(this, "result", []);
204
+ }
205
+ write({ data, endCursor }) {
206
+ if (data.length === 0)
207
+ return;
208
+ this.result.push({ data, endCursor });
209
+ }
210
+ async transaction({ cursor, endCursor, finality }, cb) {
211
+ const context = {
212
+ buffer: []
213
+ };
214
+ const writer = transactionHelper(context);
215
+ await cb({ writer });
216
+ this.write({ data: context.buffer, endCursor });
217
+ }
218
+ async invalidate(cursor) {
219
+ throw new Error("Not implemented");
220
+ }
221
+ }
222
+ function vcr() {
223
+ return new VcrSink();
224
+ }
225
+
226
+ async function replay(vcrConfig, indexer, cassetteName) {
227
+ const client = loadCassette(vcrConfig, cassetteName);
228
+ const sink = vcr();
229
+ await run(client, indexer);
230
+ return {
231
+ outputs: sink.result
232
+ };
233
+ }
234
+ function loadCassette(vcrConfig, cassetteName) {
235
+ const filePath = path.join(vcrConfig.cassetteDir, `${cassetteName}.json`);
236
+ const data = fs$1.readFileSync(filePath, "utf8");
237
+ const cassetteData = deserialize(data);
238
+ const { filter, messages } = cassetteData;
239
+ return new MockClient((request, options) => {
240
+ assert.deepStrictEqual(
241
+ request.filter,
242
+ filter,
243
+ "Request and Cassette filter mismatch"
244
+ );
245
+ return messages;
246
+ });
247
+ }
248
+
249
+ export { VcrSink as V, record as a, replay as b, createIndexer as c, defineIndexer as d, loadCassette as l, run as r, vcr as v };
@@ -0,0 +1,23 @@
1
+ import { Cursor, Client } from '@apibara/protocol';
2
+ import { f as Indexer } from './indexer.c7ed6b83.cjs';
3
+ import { b as SinkData } from './indexer.b9c8f0d8.cjs';
4
+
5
+ type VcrConfig = {
6
+ cassetteDir: string;
7
+ };
8
+ type CassetteOptions = {
9
+ name: string;
10
+ startingCursor: Cursor;
11
+ endingCursor: Cursor;
12
+ };
13
+
14
+ declare function replay<TFilter, TBlock, TTxnParams>(vcrConfig: VcrConfig, indexer: Indexer<TFilter, TBlock, TTxnParams>, cassetteName: string): Promise<VcrReplayResult>;
15
+ type VcrReplayResult = {
16
+ outputs: Array<{
17
+ endCursor?: Cursor;
18
+ data: SinkData[];
19
+ }>;
20
+ };
21
+ declare function loadCassette<TFilter, TBlock>(vcrConfig: VcrConfig, cassetteName: string): Client<TFilter, TBlock>;
22
+
23
+ export { type CassetteOptions as C, type VcrConfig as V, type VcrReplayResult as a, loadCassette as l, replay as r };
@@ -0,0 +1,266 @@
1
+ 'use strict';
2
+
3
+ const helper = require('./indexer.318d3617.cjs');
4
+ const fs = require('node:fs/promises');
5
+ const path = require('node:path');
6
+ const full = require('klona/full');
7
+ const consola = require('consola');
8
+ const hookable = require('hookable');
9
+ const assert = require('node:assert');
10
+ const sink = require('./indexer.a8b7ab1f.cjs');
11
+ const fs$1 = require('node:fs');
12
+ const testing = require('@apibara/protocol/testing');
13
+
14
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
15
+
16
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
17
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
18
+ const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
19
+ const assert__default = /*#__PURE__*/_interopDefaultCompat(assert);
20
+ const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
21
+
22
+ function defineIndexer(streamConfig) {
23
+ return (config) => ({
24
+ streamConfig,
25
+ ...config
26
+ });
27
+ }
28
+ function createIndexer({
29
+ streamConfig,
30
+ ...options
31
+ }) {
32
+ const indexer = {
33
+ options,
34
+ streamConfig,
35
+ hooks: hookable.createHooks()
36
+ };
37
+ if (indexer.options.debug) {
38
+ hookable.createDebugger(indexer.hooks, { tag: "indexer" });
39
+ }
40
+ indexer.hooks.addHooks(indexer.options.hooks ?? {});
41
+ for (const plugin of indexer.options.plugins ?? []) {
42
+ plugin(indexer);
43
+ }
44
+ return indexer;
45
+ }
46
+ async function run(client, indexer) {
47
+ await helper.indexerAsyncContext.callAsync({}, async () => {
48
+ const context = helper.useIndexerContext();
49
+ const sink$1 = indexer.options.sink ?? sink.defaultSink();
50
+ context.sink = sink$1;
51
+ await indexer.hooks.callHook("run:before");
52
+ const isFactoryMode = indexer.options.factory !== void 0;
53
+ const request = indexer.streamConfig.Request.make({
54
+ filter: isFactoryMode ? [indexer.options.filter, {}] : [indexer.options.filter],
55
+ finality: indexer.options.finality,
56
+ startingCursor: indexer.options.startingCursor
57
+ });
58
+ const options = {};
59
+ await indexer.hooks.callHook("connect:before", { request, options });
60
+ let mainFilter;
61
+ if (isFactoryMode) {
62
+ mainFilter = request.filter[1];
63
+ }
64
+ let stream = client.streamData(request, options)[Symbol.asyncIterator]();
65
+ await indexer.hooks.callHook("connect:after");
66
+ while (true) {
67
+ const { value: message, done } = await stream.next();
68
+ if (done) {
69
+ break;
70
+ }
71
+ await indexer.hooks.callHook("message", { message });
72
+ switch (message._tag) {
73
+ case "data": {
74
+ await helper.tracer.startActiveSpan("message data", async (span) => {
75
+ const blocks = message.data.data;
76
+ const { cursor, endCursor, finality } = message.data;
77
+ await sink$1.transaction(
78
+ { cursor, endCursor, finality },
79
+ async (txn) => {
80
+ context.sinkTransaction = txn;
81
+ let block;
82
+ if (isFactoryMode) {
83
+ assert__default(indexer.options.factory !== void 0);
84
+ const [factoryBlock, mainBlock] = blocks;
85
+ block = mainBlock;
86
+ if (factoryBlock !== null) {
87
+ const { filter } = await indexer.options.factory({
88
+ block: factoryBlock,
89
+ context
90
+ });
91
+ if (filter) {
92
+ mainFilter = indexer.streamConfig.mergeFilter(
93
+ mainFilter,
94
+ filter
95
+ );
96
+ const request2 = indexer.streamConfig.Request.make({
97
+ filter: [indexer.options.filter, mainFilter],
98
+ finality: indexer.options.finality,
99
+ startingCursor: cursor
100
+ });
101
+ await indexer.hooks.callHook("connect:factory", {
102
+ request: request2,
103
+ endCursor
104
+ });
105
+ stream = client.streamData(request2, options)[Symbol.asyncIterator]();
106
+ const { value: message2 } = await stream.next();
107
+ assert__default(message2._tag === "data");
108
+ const [_factoryBlock, _block] = message2.data.data;
109
+ block = _block;
110
+ }
111
+ }
112
+ } else {
113
+ block = blocks[0];
114
+ }
115
+ if (block) {
116
+ await helper.tracer.startActiveSpan("handler", async (span2) => {
117
+ await indexer.hooks.callHook("handler:before", {
118
+ block,
119
+ endCursor,
120
+ finality
121
+ });
122
+ try {
123
+ await indexer.options.transform({
124
+ block,
125
+ cursor,
126
+ endCursor,
127
+ finality,
128
+ context
129
+ });
130
+ await indexer.hooks.callHook("handler:after", {
131
+ block,
132
+ finality,
133
+ endCursor
134
+ });
135
+ } catch (error) {
136
+ assert__default(error instanceof Error);
137
+ await indexer.hooks.callHook("handler:exception", {
138
+ error
139
+ });
140
+ throw error;
141
+ }
142
+ span2.end();
143
+ });
144
+ }
145
+ }
146
+ );
147
+ await indexer.hooks.callHook("transaction:commit", {
148
+ finality,
149
+ endCursor
150
+ });
151
+ span.end();
152
+ });
153
+ break;
154
+ }
155
+ case "invalidate": {
156
+ await helper.tracer.startActiveSpan("message invalidate", async (span) => {
157
+ await sink$1.invalidate(message.invalidate.cursor);
158
+ });
159
+ break;
160
+ }
161
+ default: {
162
+ consola__default.warn("unexpected message", message);
163
+ throw new Error("not implemented");
164
+ }
165
+ }
166
+ await indexer.hooks.callHook("run:after");
167
+ }
168
+ });
169
+ }
170
+
171
+ async function record(vcrConfig, client, indexerArg, cassetteOptions) {
172
+ const indexer = full.klona(indexerArg);
173
+ const messages = [];
174
+ indexer.hooks.addHooks({
175
+ "connect:before"({ options, request }) {
176
+ request.startingCursor = cassetteOptions.startingCursor;
177
+ options.endingCursor = cassetteOptions.endingCursor;
178
+ },
179
+ message({ message }) {
180
+ messages.push(message);
181
+ },
182
+ async "run:after"() {
183
+ const output = {
184
+ filter: indexer.options.filter,
185
+ messages
186
+ };
187
+ const filePath = path__default.join(
188
+ vcrConfig.cassetteDir,
189
+ `${cassetteOptions.name}.json`
190
+ );
191
+ await fs__default.writeFile(filePath, helper.serialize(output), { flag: "w" });
192
+ }
193
+ });
194
+ await run(client, indexer);
195
+ }
196
+
197
+ var __defProp = Object.defineProperty;
198
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
199
+ var __publicField = (obj, key, value) => {
200
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
201
+ return value;
202
+ };
203
+ const transactionHelper = (context) => {
204
+ return {
205
+ insert: (data) => {
206
+ context.buffer.push(...data);
207
+ }
208
+ };
209
+ };
210
+ class VcrSink extends sink.Sink {
211
+ constructor() {
212
+ super(...arguments);
213
+ __publicField(this, "result", []);
214
+ }
215
+ write({ data, endCursor }) {
216
+ if (data.length === 0)
217
+ return;
218
+ this.result.push({ data, endCursor });
219
+ }
220
+ async transaction({ cursor, endCursor, finality }, cb) {
221
+ const context = {
222
+ buffer: []
223
+ };
224
+ const writer = transactionHelper(context);
225
+ await cb({ writer });
226
+ this.write({ data: context.buffer, endCursor });
227
+ }
228
+ async invalidate(cursor) {
229
+ throw new Error("Not implemented");
230
+ }
231
+ }
232
+ function vcr() {
233
+ return new VcrSink();
234
+ }
235
+
236
+ async function replay(vcrConfig, indexer, cassetteName) {
237
+ const client = loadCassette(vcrConfig, cassetteName);
238
+ const sink = vcr();
239
+ await run(client, indexer);
240
+ return {
241
+ outputs: sink.result
242
+ };
243
+ }
244
+ function loadCassette(vcrConfig, cassetteName) {
245
+ const filePath = path__default.join(vcrConfig.cassetteDir, `${cassetteName}.json`);
246
+ const data = fs__default$1.readFileSync(filePath, "utf8");
247
+ const cassetteData = helper.deserialize(data);
248
+ const { filter, messages } = cassetteData;
249
+ return new testing.MockClient((request, options) => {
250
+ assert__default.deepStrictEqual(
251
+ request.filter,
252
+ filter,
253
+ "Request and Cassette filter mismatch"
254
+ );
255
+ return messages;
256
+ });
257
+ }
258
+
259
+ exports.VcrSink = VcrSink;
260
+ exports.createIndexer = createIndexer;
261
+ exports.defineIndexer = defineIndexer;
262
+ exports.loadCassette = loadCassette;
263
+ exports.record = record;
264
+ exports.replay = replay;
265
+ exports.run = run;
266
+ exports.vcr = vcr;
@@ -0,0 +1,17 @@
1
+ import consola from 'consola';
2
+
3
+ class Sink {
4
+ }
5
+ class DefaultSink extends Sink {
6
+ async transaction({ cursor, endCursor, finality }, cb) {
7
+ await cb({});
8
+ }
9
+ async invalidate(cursor) {
10
+ consola.info(`Invalidating cursor ${cursor?.orderKey}`);
11
+ }
12
+ }
13
+ function defaultSink() {
14
+ return new DefaultSink();
15
+ }
16
+
17
+ export { DefaultSink as D, Sink as S, defaultSink as d };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const consola = require('consola');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
6
+
7
+ const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
8
+
9
+ class Sink {
10
+ }
11
+ class DefaultSink extends Sink {
12
+ async transaction({ cursor, endCursor, finality }, cb) {
13
+ await cb({});
14
+ }
15
+ async invalidate(cursor) {
16
+ consola__default.info(`Invalidating cursor ${cursor?.orderKey}`);
17
+ }
18
+ }
19
+ function defaultSink() {
20
+ return new DefaultSink();
21
+ }
22
+
23
+ exports.DefaultSink = DefaultSink;
24
+ exports.Sink = Sink;
25
+ exports.defaultSink = defaultSink;
@@ -0,0 +1,19 @@
1
+ import { Cursor, DataFinality } from '@apibara/protocol';
2
+
3
+ type SinkData = Record<string, unknown>;
4
+ type SinkCursorParams = {
5
+ cursor?: Cursor;
6
+ endCursor?: Cursor;
7
+ finality: DataFinality;
8
+ };
9
+ declare abstract class Sink<TTxnParams = unknown> {
10
+ abstract transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TTxnParams) => Promise<void>): Promise<void>;
11
+ abstract invalidate(cursor?: Cursor): Promise<void>;
12
+ }
13
+ declare class DefaultSink extends Sink<unknown> {
14
+ transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: unknown) => Promise<void>): Promise<void>;
15
+ invalidate(cursor?: Cursor): Promise<void>;
16
+ }
17
+ declare function defaultSink(): DefaultSink;
18
+
19
+ export { DefaultSink as D, Sink as S, type SinkCursorParams as a, type SinkData as b, defaultSink as d };
@@ -0,0 +1,19 @@
1
+ import { Cursor, DataFinality } from '@apibara/protocol';
2
+
3
+ type SinkData = Record<string, unknown>;
4
+ type SinkCursorParams = {
5
+ cursor?: Cursor;
6
+ endCursor?: Cursor;
7
+ finality: DataFinality;
8
+ };
9
+ declare abstract class Sink<TTxnParams = unknown> {
10
+ abstract transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TTxnParams) => Promise<void>): Promise<void>;
11
+ abstract invalidate(cursor?: Cursor): Promise<void>;
12
+ }
13
+ declare class DefaultSink extends Sink<unknown> {
14
+ transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: unknown) => Promise<void>): Promise<void>;
15
+ invalidate(cursor?: Cursor): Promise<void>;
16
+ }
17
+ declare function defaultSink(): DefaultSink;
18
+
19
+ export { DefaultSink as D, Sink as S, type SinkCursorParams as a, type SinkData as b, defaultSink as d };
@@ -0,0 +1,19 @@
1
+ import { Cursor, DataFinality } from '@apibara/protocol';
2
+
3
+ type SinkData = Record<string, unknown>;
4
+ type SinkCursorParams = {
5
+ cursor?: Cursor;
6
+ endCursor?: Cursor;
7
+ finality: DataFinality;
8
+ };
9
+ declare abstract class Sink<TTxnParams = unknown> {
10
+ abstract transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: TTxnParams) => Promise<void>): Promise<void>;
11
+ abstract invalidate(cursor?: Cursor): Promise<void>;
12
+ }
13
+ declare class DefaultSink extends Sink<unknown> {
14
+ transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: unknown) => Promise<void>): Promise<void>;
15
+ invalidate(cursor?: Cursor): Promise<void>;
16
+ }
17
+ declare function defaultSink(): DefaultSink;
18
+
19
+ export { DefaultSink as D, Sink as S, type SinkCursorParams as a, type SinkData as b, defaultSink as d };