@apibara/indexer 2.0.0-beta.6 → 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.
- package/dist/index.cjs +17 -19
- package/dist/index.d.cts +9 -38
- package/dist/index.d.mts +9 -38
- package/dist/index.d.ts +9 -38
- package/dist/index.mjs +7 -9
- package/dist/plugins/index.cjs +7 -0
- package/dist/plugins/index.d.cts +4 -0
- package/dist/plugins/index.d.mts +4 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.mjs +5 -0
- package/dist/plugins/kv.cjs +131 -0
- package/dist/plugins/kv.d.cts +32 -0
- package/dist/plugins/kv.d.mts +32 -0
- package/dist/plugins/kv.d.ts +32 -0
- package/dist/plugins/kv.mjs +124 -0
- package/dist/plugins/persistence.cjs +182 -0
- package/dist/plugins/persistence.d.cts +50 -0
- package/dist/plugins/persistence.d.mts +50 -0
- package/dist/plugins/persistence.d.ts +50 -0
- package/dist/plugins/persistence.mjs +179 -0
- package/dist/shared/indexer.2c23c9cd.mjs +35 -0
- package/dist/shared/indexer.318d3617.cjs +47 -0
- package/dist/shared/{indexer.28bd9576.mjs → indexer.36530330.mjs} +9 -39
- package/dist/shared/indexer.500fd281.d.cts +23 -0
- package/dist/shared/{indexer.99ec3128.cjs → indexer.541d43eb.cjs} +16 -50
- package/dist/shared/{indexer.d227f25c.d.cts → indexer.b9c8f0d8.d.cts} +1 -1
- package/dist/shared/{indexer.d227f25c.d.mts → indexer.b9c8f0d8.d.mts} +1 -1
- package/dist/shared/{indexer.d227f25c.d.ts → indexer.b9c8f0d8.d.ts} +1 -1
- package/dist/shared/{indexer.26fbe988.d.ts → indexer.c7ed6b83.d.cts} +2 -20
- package/dist/shared/indexer.e1856641.d.mts +23 -0
- package/dist/shared/indexer.e4f2430f.d.ts +23 -0
- package/dist/shared/{indexer.ff960804.d.cts → indexer.e8bd138d.d.mts} +2 -20
- package/dist/shared/{indexer.9aa22867.d.mts → indexer.f761abcd.d.ts} +2 -20
- package/dist/sinks/csv.d.cts +1 -1
- package/dist/sinks/csv.d.mts +1 -1
- package/dist/sinks/csv.d.ts +1 -1
- package/dist/sinks/drizzle/index.cjs +210 -0
- package/dist/sinks/drizzle/index.d.cts +111 -0
- package/dist/sinks/drizzle/index.d.mts +111 -0
- package/dist/sinks/drizzle/index.d.ts +111 -0
- package/dist/sinks/drizzle/index.mjs +196 -0
- package/dist/sinks/sqlite.d.cts +1 -1
- package/dist/sinks/sqlite.d.mts +1 -1
- package/dist/sinks/sqlite.d.ts +1 -1
- package/dist/testing/index.cjs +16 -15
- package/dist/testing/index.d.cts +3 -2
- package/dist/testing/index.d.mts +3 -2
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.mjs +11 -10
- package/dist/vcr/index.cjs +25 -0
- package/dist/vcr/index.d.cts +18 -0
- package/dist/vcr/index.d.mts +18 -0
- package/dist/vcr/index.d.ts +18 -0
- package/dist/vcr/index.mjs +14 -0
- package/package.json +33 -11
- package/src/vcr/record.ts +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Cursor } from '@apibara/protocol';
|
|
2
|
+
import { TablesRelationalConfig, ExtractTablesWithRelations, SQL } from 'drizzle-orm';
|
|
3
|
+
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
4
|
+
import { PgTable, PgQueryResultHKT, PgTransaction, PgUpdateBase, PgInsertValue, PgUpdateSetSource, PgSelectBuilder, SelectedFields, TableConfig, PgTableWithColumns, PgDatabase, AnyPgTable, PgTableFn } from 'drizzle-orm/pg-core';
|
|
5
|
+
import { S as Sink, a as SinkCursorParams } from '../../shared/indexer.b9c8f0d8.mjs';
|
|
6
|
+
import { Range } from 'postgres-range';
|
|
7
|
+
|
|
8
|
+
declare class DrizzleSinkDelete<TTable extends PgTable, TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
9
|
+
private db;
|
|
10
|
+
private table;
|
|
11
|
+
private endCursor?;
|
|
12
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, table: TTable, endCursor?: Cursor | undefined);
|
|
13
|
+
where(where: SQL): Omit<PgUpdateBase<TTable, TQueryResult, undefined, false, "where">, "where">;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class DrizzleSinkInsert<TTable extends PgTable, TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
17
|
+
private db;
|
|
18
|
+
private table;
|
|
19
|
+
private endCursor?;
|
|
20
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, table: TTable, endCursor?: Cursor | undefined);
|
|
21
|
+
values(values: PgInsertValue<TTable> | PgInsertValue<TTable>[]): drizzle_orm_pg_core.PgInsertBase<TTable, TQueryResult, undefined, false, never>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class DrizzleSinkUpdate<TTable extends PgTable, TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
25
|
+
private db;
|
|
26
|
+
private table;
|
|
27
|
+
private endCursor?;
|
|
28
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, table: TTable, endCursor?: Cursor | undefined);
|
|
29
|
+
set(values: PgUpdateSetSource<TTable>): PgUpdateBase<TTable, TQueryResult>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare class DrizzleSinkTransaction<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
33
|
+
private db;
|
|
34
|
+
private endCursor?;
|
|
35
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, endCursor?: Cursor | undefined);
|
|
36
|
+
insert<TTable extends PgTable>(table: TTable): DrizzleSinkInsert<TTable, TQueryResult, TFullSchema, TSchema>;
|
|
37
|
+
update<TTable extends PgTable>(table: TTable): DrizzleSinkUpdate<TTable, TQueryResult, TFullSchema, TSchema>;
|
|
38
|
+
delete<TTable extends PgTable>(table: TTable): DrizzleSinkDelete<TTable, TQueryResult, TFullSchema, TSchema>;
|
|
39
|
+
select(): PgSelectBuilder<undefined>;
|
|
40
|
+
select<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type DrizzleSinkTables<TTableConfig extends Record<string, TableConfig>> = {
|
|
44
|
+
[K in keyof TTableConfig]: PgTableWithColumns<TTableConfig[K]>;
|
|
45
|
+
};
|
|
46
|
+
type DrizzleSinkOptions<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> = {
|
|
47
|
+
/**
|
|
48
|
+
* Database instance of drizzle-orm
|
|
49
|
+
*/
|
|
50
|
+
database: PgDatabase<TQueryResult, TFullSchema, TSchema>;
|
|
51
|
+
tables: AnyPgTable[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A sink that writes data to a PostgreSQL database using Drizzle ORM.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const sink = drizzle({
|
|
60
|
+
* database: db,
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* ...
|
|
64
|
+
* async transform({context, endCursor}){
|
|
65
|
+
* const { transaction } = useSink(context);
|
|
66
|
+
* const db = transaction(endCursor);
|
|
67
|
+
*
|
|
68
|
+
* db.insert(users).values([
|
|
69
|
+
* { id: 1, name: "John" },
|
|
70
|
+
* { id: 2, name: "Jane" },
|
|
71
|
+
* ]);
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare class DrizzleSink<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> extends Sink {
|
|
77
|
+
private _db;
|
|
78
|
+
private _tables;
|
|
79
|
+
constructor(options: DrizzleSinkOptions<TQueryResult, TFullSchema, TSchema>);
|
|
80
|
+
transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: {
|
|
81
|
+
db: DrizzleSinkTransaction<TQueryResult, TFullSchema, TSchema>;
|
|
82
|
+
}) => Promise<void>): Promise<void>;
|
|
83
|
+
invalidate(cursor?: Cursor): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
declare const drizzle: <TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>>(args: DrizzleSinkOptions<TQueryResult, TFullSchema, TSchema>) => DrizzleSink<TQueryResult, TFullSchema, TSchema>;
|
|
86
|
+
|
|
87
|
+
type Comparable = string | number;
|
|
88
|
+
type RangeBound<T extends Comparable> = T | {
|
|
89
|
+
value: T;
|
|
90
|
+
inclusive: boolean;
|
|
91
|
+
};
|
|
92
|
+
declare class Int8Range {
|
|
93
|
+
readonly range: Range<number>;
|
|
94
|
+
constructor(range: Range<number>);
|
|
95
|
+
get start(): RangeBound<number> | null;
|
|
96
|
+
get end(): RangeBound<number> | null;
|
|
97
|
+
}
|
|
98
|
+
declare const int8range: <TName extends string>(dbName: TName, fieldConfig?: unknown) => drizzle_orm_pg_core.PgCustomColumnBuilder<{
|
|
99
|
+
name: TName;
|
|
100
|
+
dataType: "custom";
|
|
101
|
+
columnType: "PgCustomColumn";
|
|
102
|
+
data: Int8Range;
|
|
103
|
+
driverParam: unknown;
|
|
104
|
+
enumValues: undefined;
|
|
105
|
+
generated: undefined;
|
|
106
|
+
}>;
|
|
107
|
+
|
|
108
|
+
declare const pgTable: PgTableFn;
|
|
109
|
+
declare const getDrizzleCursor: (cursor_range: [bigint | undefined, bigint | undefined] | bigint | undefined) => Int8Range;
|
|
110
|
+
|
|
111
|
+
export { DrizzleSink, DrizzleSinkDelete, type DrizzleSinkOptions, type DrizzleSinkTables, DrizzleSinkTransaction, DrizzleSinkUpdate, Int8Range, drizzle, getDrizzleCursor, int8range, pgTable };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Cursor } from '@apibara/protocol';
|
|
2
|
+
import { TablesRelationalConfig, ExtractTablesWithRelations, SQL } from 'drizzle-orm';
|
|
3
|
+
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
4
|
+
import { PgTable, PgQueryResultHKT, PgTransaction, PgUpdateBase, PgInsertValue, PgUpdateSetSource, PgSelectBuilder, SelectedFields, TableConfig, PgTableWithColumns, PgDatabase, AnyPgTable, PgTableFn } from 'drizzle-orm/pg-core';
|
|
5
|
+
import { S as Sink, a as SinkCursorParams } from '../../shared/indexer.b9c8f0d8.js';
|
|
6
|
+
import { Range } from 'postgres-range';
|
|
7
|
+
|
|
8
|
+
declare class DrizzleSinkDelete<TTable extends PgTable, TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
9
|
+
private db;
|
|
10
|
+
private table;
|
|
11
|
+
private endCursor?;
|
|
12
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, table: TTable, endCursor?: Cursor | undefined);
|
|
13
|
+
where(where: SQL): Omit<PgUpdateBase<TTable, TQueryResult, undefined, false, "where">, "where">;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class DrizzleSinkInsert<TTable extends PgTable, TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
17
|
+
private db;
|
|
18
|
+
private table;
|
|
19
|
+
private endCursor?;
|
|
20
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, table: TTable, endCursor?: Cursor | undefined);
|
|
21
|
+
values(values: PgInsertValue<TTable> | PgInsertValue<TTable>[]): drizzle_orm_pg_core.PgInsertBase<TTable, TQueryResult, undefined, false, never>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class DrizzleSinkUpdate<TTable extends PgTable, TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
25
|
+
private db;
|
|
26
|
+
private table;
|
|
27
|
+
private endCursor?;
|
|
28
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, table: TTable, endCursor?: Cursor | undefined);
|
|
29
|
+
set(values: PgUpdateSetSource<TTable>): PgUpdateBase<TTable, TQueryResult>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare class DrizzleSinkTransaction<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
33
|
+
private db;
|
|
34
|
+
private endCursor?;
|
|
35
|
+
constructor(db: PgTransaction<TQueryResult, TFullSchema, TSchema>, endCursor?: Cursor | undefined);
|
|
36
|
+
insert<TTable extends PgTable>(table: TTable): DrizzleSinkInsert<TTable, TQueryResult, TFullSchema, TSchema>;
|
|
37
|
+
update<TTable extends PgTable>(table: TTable): DrizzleSinkUpdate<TTable, TQueryResult, TFullSchema, TSchema>;
|
|
38
|
+
delete<TTable extends PgTable>(table: TTable): DrizzleSinkDelete<TTable, TQueryResult, TFullSchema, TSchema>;
|
|
39
|
+
select(): PgSelectBuilder<undefined>;
|
|
40
|
+
select<TSelection extends SelectedFields>(fields: TSelection): PgSelectBuilder<TSelection>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type DrizzleSinkTables<TTableConfig extends Record<string, TableConfig>> = {
|
|
44
|
+
[K in keyof TTableConfig]: PgTableWithColumns<TTableConfig[K]>;
|
|
45
|
+
};
|
|
46
|
+
type DrizzleSinkOptions<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> = {
|
|
47
|
+
/**
|
|
48
|
+
* Database instance of drizzle-orm
|
|
49
|
+
*/
|
|
50
|
+
database: PgDatabase<TQueryResult, TFullSchema, TSchema>;
|
|
51
|
+
tables: AnyPgTable[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A sink that writes data to a PostgreSQL database using Drizzle ORM.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const sink = drizzle({
|
|
60
|
+
* database: db,
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* ...
|
|
64
|
+
* async transform({context, endCursor}){
|
|
65
|
+
* const { transaction } = useSink(context);
|
|
66
|
+
* const db = transaction(endCursor);
|
|
67
|
+
*
|
|
68
|
+
* db.insert(users).values([
|
|
69
|
+
* { id: 1, name: "John" },
|
|
70
|
+
* { id: 2, name: "Jane" },
|
|
71
|
+
* ]);
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare class DrizzleSink<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> extends Sink {
|
|
77
|
+
private _db;
|
|
78
|
+
private _tables;
|
|
79
|
+
constructor(options: DrizzleSinkOptions<TQueryResult, TFullSchema, TSchema>);
|
|
80
|
+
transaction({ cursor, endCursor, finality }: SinkCursorParams, cb: (params: {
|
|
81
|
+
db: DrizzleSinkTransaction<TQueryResult, TFullSchema, TSchema>;
|
|
82
|
+
}) => Promise<void>): Promise<void>;
|
|
83
|
+
invalidate(cursor?: Cursor): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
declare const drizzle: <TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown> = Record<string, never>, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>>(args: DrizzleSinkOptions<TQueryResult, TFullSchema, TSchema>) => DrizzleSink<TQueryResult, TFullSchema, TSchema>;
|
|
86
|
+
|
|
87
|
+
type Comparable = string | number;
|
|
88
|
+
type RangeBound<T extends Comparable> = T | {
|
|
89
|
+
value: T;
|
|
90
|
+
inclusive: boolean;
|
|
91
|
+
};
|
|
92
|
+
declare class Int8Range {
|
|
93
|
+
readonly range: Range<number>;
|
|
94
|
+
constructor(range: Range<number>);
|
|
95
|
+
get start(): RangeBound<number> | null;
|
|
96
|
+
get end(): RangeBound<number> | null;
|
|
97
|
+
}
|
|
98
|
+
declare const int8range: <TName extends string>(dbName: TName, fieldConfig?: unknown) => drizzle_orm_pg_core.PgCustomColumnBuilder<{
|
|
99
|
+
name: TName;
|
|
100
|
+
dataType: "custom";
|
|
101
|
+
columnType: "PgCustomColumn";
|
|
102
|
+
data: Int8Range;
|
|
103
|
+
driverParam: unknown;
|
|
104
|
+
enumValues: undefined;
|
|
105
|
+
generated: undefined;
|
|
106
|
+
}>;
|
|
107
|
+
|
|
108
|
+
declare const pgTable: PgTableFn;
|
|
109
|
+
declare const getDrizzleCursor: (cursor_range: [bigint | undefined, bigint | undefined] | bigint | undefined) => Int8Range;
|
|
110
|
+
|
|
111
|
+
export { DrizzleSink, DrizzleSinkDelete, type DrizzleSinkOptions, type DrizzleSinkTables, DrizzleSinkTransaction, DrizzleSinkUpdate, Int8Range, drizzle, getDrizzleCursor, int8range, pgTable };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { sql, gt } from 'drizzle-orm';
|
|
2
|
+
import { S as Sink } from '../../shared/indexer.93d6b2eb.mjs';
|
|
3
|
+
import { customType, pgTable as pgTable$1 } from 'drizzle-orm/pg-core';
|
|
4
|
+
import range, { parse, serialize } from 'postgres-range';
|
|
5
|
+
import 'consola';
|
|
6
|
+
|
|
7
|
+
class DrizzleSinkDelete {
|
|
8
|
+
constructor(db, table, endCursor) {
|
|
9
|
+
this.db = db;
|
|
10
|
+
this.table = table;
|
|
11
|
+
this.endCursor = endCursor;
|
|
12
|
+
}
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
where(where) {
|
|
15
|
+
return this.db.update(this.table).set({
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
_cursor: sql`int8range(lower(_cursor), ${Number(this.endCursor?.orderKey)}, '[)')`
|
|
18
|
+
}).where(where);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class Int8Range {
|
|
23
|
+
constructor(range) {
|
|
24
|
+
this.range = range;
|
|
25
|
+
}
|
|
26
|
+
get start() {
|
|
27
|
+
return this.range.lower != null ? {
|
|
28
|
+
value: this.range.lower,
|
|
29
|
+
inclusive: this.range.isLowerBoundClosed()
|
|
30
|
+
} : null;
|
|
31
|
+
}
|
|
32
|
+
get end() {
|
|
33
|
+
return this.range.upper != null ? {
|
|
34
|
+
value: this.range.upper,
|
|
35
|
+
inclusive: this.range.isUpperBoundClosed()
|
|
36
|
+
} : null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const int8range = customType({
|
|
40
|
+
dataType: () => "int8range",
|
|
41
|
+
fromDriver: (value) => {
|
|
42
|
+
if (typeof value !== "string") {
|
|
43
|
+
throw new Error("Expected string");
|
|
44
|
+
}
|
|
45
|
+
const parsed = parse(value, (val) => Number.parseInt(val, 10));
|
|
46
|
+
return new Int8Range(parsed);
|
|
47
|
+
},
|
|
48
|
+
toDriver: (value) => serialize(value.range)
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const pgTable = (name, columns, extraConfig) => {
|
|
52
|
+
return pgTable$1(
|
|
53
|
+
name,
|
|
54
|
+
{
|
|
55
|
+
...columns,
|
|
56
|
+
_cursor: int8range("_cursor").notNull()
|
|
57
|
+
},
|
|
58
|
+
extraConfig
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
const getDrizzleCursor = (cursor_range) => {
|
|
62
|
+
const isArray = Array.isArray(cursor_range);
|
|
63
|
+
const [lower, upper] = isArray ? cursor_range : [cursor_range, void 0];
|
|
64
|
+
let isNoUpperBound = false;
|
|
65
|
+
if (!lower) {
|
|
66
|
+
throw new Error("Lower bound cursor is required");
|
|
67
|
+
}
|
|
68
|
+
if (!upper) {
|
|
69
|
+
isNoUpperBound = true;
|
|
70
|
+
}
|
|
71
|
+
return new Int8Range(
|
|
72
|
+
new range.Range(
|
|
73
|
+
Number(lower),
|
|
74
|
+
Number(upper),
|
|
75
|
+
range.RANGE_LB_INC | (isNoUpperBound ? range.RANGE_UB_INF : 0)
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
class DrizzleSinkInsert {
|
|
81
|
+
constructor(db, table, endCursor) {
|
|
82
|
+
this.db = db;
|
|
83
|
+
this.table = table;
|
|
84
|
+
this.endCursor = endCursor;
|
|
85
|
+
}
|
|
86
|
+
values(values) {
|
|
87
|
+
const originalInsert = this.db.insert(this.table);
|
|
88
|
+
const cursoredValues = (Array.isArray(values) ? values : [values]).map(
|
|
89
|
+
(v) => {
|
|
90
|
+
return {
|
|
91
|
+
...v,
|
|
92
|
+
_cursor: getDrizzleCursor(this.endCursor?.orderKey)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
return originalInsert.values(cursoredValues);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class DrizzleSinkSelect {
|
|
101
|
+
constructor(db, fields, endCursor) {
|
|
102
|
+
this.db = db;
|
|
103
|
+
this.fields = fields;
|
|
104
|
+
this.endCursor = endCursor;
|
|
105
|
+
}
|
|
106
|
+
from(source) {
|
|
107
|
+
if (this.fields) {
|
|
108
|
+
const originalFrom = this.db.select(this.fields).from(source);
|
|
109
|
+
return {
|
|
110
|
+
...originalFrom,
|
|
111
|
+
where: (where) => {
|
|
112
|
+
const combinedWhere = sql`${where ? sql`${where} AND ` : sql``}upper_inf(_cursor)`;
|
|
113
|
+
return originalFrom.where(combinedWhere);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return this.db.select().from(source).where(sql`upper_inf(_cursor)`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class DrizzleSinkUpdate {
|
|
122
|
+
constructor(db, table, endCursor) {
|
|
123
|
+
this.db = db;
|
|
124
|
+
this.table = table;
|
|
125
|
+
this.endCursor = endCursor;
|
|
126
|
+
}
|
|
127
|
+
set(values) {
|
|
128
|
+
const originalUpdate = this.db.update(this.table);
|
|
129
|
+
const originalSet = originalUpdate.set(values);
|
|
130
|
+
return {
|
|
131
|
+
...originalSet,
|
|
132
|
+
where: async (where) => {
|
|
133
|
+
await this.db.update(this.table).set({
|
|
134
|
+
_cursor: sql`int8range(lower(_cursor), ${Number(this.endCursor?.orderKey)}, '[)')`
|
|
135
|
+
}).where(sql`${where ? sql`${where} AND ` : sql``}upper_inf(_cursor)`).execute();
|
|
136
|
+
return originalSet.where(where);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
class DrizzleSinkTransaction {
|
|
143
|
+
constructor(db, endCursor) {
|
|
144
|
+
this.db = db;
|
|
145
|
+
this.endCursor = endCursor;
|
|
146
|
+
}
|
|
147
|
+
insert(table) {
|
|
148
|
+
return new DrizzleSinkInsert(this.db, table, this.endCursor);
|
|
149
|
+
}
|
|
150
|
+
update(table) {
|
|
151
|
+
return new DrizzleSinkUpdate(this.db, table, this.endCursor);
|
|
152
|
+
}
|
|
153
|
+
delete(table) {
|
|
154
|
+
return new DrizzleSinkDelete(this.db, table, this.endCursor);
|
|
155
|
+
}
|
|
156
|
+
select(fields) {
|
|
157
|
+
return new DrizzleSinkSelect(this.db, fields, this.endCursor);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var __defProp = Object.defineProperty;
|
|
162
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
163
|
+
var __publicField = (obj, key, value) => {
|
|
164
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
165
|
+
return value;
|
|
166
|
+
};
|
|
167
|
+
class DrizzleSink extends Sink {
|
|
168
|
+
constructor(options) {
|
|
169
|
+
super();
|
|
170
|
+
__publicField(this, "_db");
|
|
171
|
+
__publicField(this, "_tables");
|
|
172
|
+
const { database, tables } = options;
|
|
173
|
+
this._db = database;
|
|
174
|
+
this._tables = tables;
|
|
175
|
+
}
|
|
176
|
+
async transaction({ cursor, endCursor, finality }, cb) {
|
|
177
|
+
await this._db.transaction(async (db) => {
|
|
178
|
+
await cb({ db: new DrizzleSinkTransaction(db, endCursor) });
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async invalidate(cursor) {
|
|
182
|
+
await this._db.transaction(async (db) => {
|
|
183
|
+
for (const table of this._tables) {
|
|
184
|
+
await db.delete(table).where(gt(sql`lower(_cursor)`, sql`${Number(cursor?.orderKey)}`)).returning();
|
|
185
|
+
await db.update(table).set({
|
|
186
|
+
_cursor: sql`int8range(lower(_cursor), NULL, '[)')`
|
|
187
|
+
}).where(gt(sql`upper(_cursor)`, sql`${Number(cursor?.orderKey)}`));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const drizzle = (args) => {
|
|
193
|
+
return new DrizzleSink(args);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export { DrizzleSink, DrizzleSinkDelete, DrizzleSinkTransaction, DrizzleSinkUpdate, Int8Range, drizzle, getDrizzleCursor, int8range, pgTable };
|
package/dist/sinks/sqlite.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cursor } from '@apibara/protocol';
|
|
2
2
|
import { Database } from 'better-sqlite3';
|
|
3
|
-
import {
|
|
3
|
+
import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.b9c8f0d8.cjs';
|
|
4
4
|
|
|
5
5
|
type SqliteSinkOptions = {
|
|
6
6
|
/**
|
package/dist/sinks/sqlite.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cursor } from '@apibara/protocol';
|
|
2
2
|
import { Database } from 'better-sqlite3';
|
|
3
|
-
import {
|
|
3
|
+
import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.b9c8f0d8.mjs';
|
|
4
4
|
|
|
5
5
|
type SqliteSinkOptions = {
|
|
6
6
|
/**
|
package/dist/sinks/sqlite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cursor } from '@apibara/protocol';
|
|
2
2
|
import { Database } from 'better-sqlite3';
|
|
3
|
-
import {
|
|
3
|
+
import { S as Sink, a as SinkCursorParams, b as SinkData } from '../shared/indexer.b9c8f0d8.js';
|
|
4
4
|
|
|
5
5
|
type SqliteSinkOptions = {
|
|
6
6
|
/**
|
package/dist/testing/index.cjs
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const vitest = require('vitest');
|
|
4
|
-
const
|
|
5
|
-
require('
|
|
6
|
-
require('node:path');
|
|
7
|
-
require('consola');
|
|
8
|
-
require('klona/full');
|
|
9
|
-
require('node:assert');
|
|
10
|
-
require('node:fs');
|
|
11
|
-
require('@apibara/protocol/testing');
|
|
12
|
-
require('hookable');
|
|
4
|
+
const helper = require('../shared/indexer.318d3617.cjs');
|
|
5
|
+
const vcr_index = require('../shared/indexer.541d43eb.cjs');
|
|
13
6
|
require('node:async_hooks');
|
|
14
7
|
require('unctx');
|
|
15
8
|
require('@opentelemetry/api');
|
|
9
|
+
require('node:fs');
|
|
10
|
+
require('node:path');
|
|
11
|
+
require('node:fs/promises');
|
|
12
|
+
require('klona/full');
|
|
13
|
+
require('consola');
|
|
14
|
+
require('hookable');
|
|
15
|
+
require('node:assert');
|
|
16
16
|
require('../shared/indexer.a8b7ab1f.cjs');
|
|
17
|
+
require('@apibara/protocol/testing');
|
|
17
18
|
|
|
18
19
|
const test = vitest.test.extend({
|
|
19
20
|
vcr: {
|
|
@@ -35,11 +36,11 @@ async function withClient(cassetteName, range, callback) {
|
|
|
35
36
|
};
|
|
36
37
|
const context = {
|
|
37
38
|
async run(indexer) {
|
|
38
|
-
const client =
|
|
39
|
-
if (!
|
|
40
|
-
await
|
|
39
|
+
const client = vcr_index.loadCassette(vcrConfig, cassetteName);
|
|
40
|
+
if (!helper.isCassetteAvailable(vcrConfig, cassetteName)) {
|
|
41
|
+
await vcr_index.record(vcrConfig, client, indexer, cassetteOptions);
|
|
41
42
|
}
|
|
42
|
-
return await
|
|
43
|
+
return await vcr_index.replay(vcrConfig, indexer, cassetteName);
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
await callback(context);
|
|
@@ -57,7 +58,7 @@ function generateMockMessages(count = 10) {
|
|
|
57
58
|
}));
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
exports.VcrSink =
|
|
61
|
-
exports.vcr =
|
|
61
|
+
exports.VcrSink = vcr_index.VcrSink;
|
|
62
|
+
exports.vcr = vcr_index.vcr;
|
|
62
63
|
exports.generateMockMessages = generateMockMessages;
|
|
63
64
|
exports.test = test;
|
package/dist/testing/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as vitest from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { f as Indexer } from '../shared/indexer.c7ed6b83.cjs';
|
|
3
|
+
import { a as VcrReplayResult } from '../shared/indexer.500fd281.cjs';
|
|
3
4
|
import { Cursor } from '@apibara/protocol';
|
|
4
|
-
import {
|
|
5
|
+
import { S as Sink, b as SinkData, a as SinkCursorParams } from '../shared/indexer.b9c8f0d8.cjs';
|
|
5
6
|
import { MockStreamResponse } from '@apibara/protocol/testing';
|
|
6
7
|
import 'hookable';
|
|
7
8
|
|
package/dist/testing/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as vitest from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { f as Indexer } from '../shared/indexer.e8bd138d.mjs';
|
|
3
|
+
import { a as VcrReplayResult } from '../shared/indexer.e1856641.mjs';
|
|
3
4
|
import { Cursor } from '@apibara/protocol';
|
|
4
|
-
import {
|
|
5
|
+
import { S as Sink, b as SinkData, a as SinkCursorParams } from '../shared/indexer.b9c8f0d8.mjs';
|
|
5
6
|
import { MockStreamResponse } from '@apibara/protocol/testing';
|
|
6
7
|
import 'hookable';
|
|
7
8
|
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as vitest from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { f as Indexer } from '../shared/indexer.f761abcd.js';
|
|
3
|
+
import { a as VcrReplayResult } from '../shared/indexer.e4f2430f.js';
|
|
3
4
|
import { Cursor } from '@apibara/protocol';
|
|
4
|
-
import {
|
|
5
|
+
import { S as Sink, b as SinkData, a as SinkCursorParams } from '../shared/indexer.b9c8f0d8.js';
|
|
5
6
|
import { MockStreamResponse } from '@apibara/protocol/testing';
|
|
6
7
|
import 'hookable';
|
|
7
8
|
|
package/dist/testing/index.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { test as test$1 } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import 'node:path';
|
|
6
|
-
import 'consola';
|
|
7
|
-
import 'klona/full';
|
|
8
|
-
import 'node:assert';
|
|
9
|
-
import 'node:fs';
|
|
10
|
-
import '@apibara/protocol/testing';
|
|
11
|
-
import 'hookable';
|
|
2
|
+
import { i as isCassetteAvailable } from '../shared/indexer.2c23c9cd.mjs';
|
|
3
|
+
import { l as loadCassette, a as record, b as replay } from '../shared/indexer.36530330.mjs';
|
|
4
|
+
export { V as VcrSink, v as vcr } from '../shared/indexer.36530330.mjs';
|
|
12
5
|
import 'node:async_hooks';
|
|
13
6
|
import 'unctx';
|
|
14
7
|
import '@opentelemetry/api';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'node:path';
|
|
10
|
+
import 'node:fs/promises';
|
|
11
|
+
import 'klona/full';
|
|
12
|
+
import 'consola';
|
|
13
|
+
import 'hookable';
|
|
14
|
+
import 'node:assert';
|
|
15
15
|
import '../shared/indexer.93d6b2eb.mjs';
|
|
16
|
+
import '@apibara/protocol/testing';
|
|
16
17
|
|
|
17
18
|
const test = test$1.extend({
|
|
18
19
|
vcr: {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const helper = require('../shared/indexer.318d3617.cjs');
|
|
4
|
+
const vcr_index = require('../shared/indexer.541d43eb.cjs');
|
|
5
|
+
require('node:async_hooks');
|
|
6
|
+
require('unctx');
|
|
7
|
+
require('@opentelemetry/api');
|
|
8
|
+
require('node:fs');
|
|
9
|
+
require('node:path');
|
|
10
|
+
require('node:fs/promises');
|
|
11
|
+
require('klona/full');
|
|
12
|
+
require('consola');
|
|
13
|
+
require('hookable');
|
|
14
|
+
require('node:assert');
|
|
15
|
+
require('../shared/indexer.a8b7ab1f.cjs');
|
|
16
|
+
require('@apibara/protocol/testing');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.deserialize = helper.deserialize;
|
|
21
|
+
exports.isCassetteAvailable = helper.isCassetteAvailable;
|
|
22
|
+
exports.serialize = helper.serialize;
|
|
23
|
+
exports.loadCassette = vcr_index.loadCassette;
|
|
24
|
+
exports.record = vcr_index.record;
|
|
25
|
+
exports.replay = vcr_index.replay;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { V as VcrConfig, C as CassetteOptions } from '../shared/indexer.500fd281.cjs';
|
|
2
|
+
export { a as VcrReplayResult, l as loadCassette, r as replay } from '../shared/indexer.500fd281.cjs';
|
|
3
|
+
import { StreamDataResponse, Client } from '@apibara/protocol';
|
|
4
|
+
import { f as Indexer } from '../shared/indexer.c7ed6b83.cjs';
|
|
5
|
+
import '../shared/indexer.b9c8f0d8.cjs';
|
|
6
|
+
import 'hookable';
|
|
7
|
+
|
|
8
|
+
declare function deserialize(str: string): any;
|
|
9
|
+
declare function serialize(obj: Record<string, unknown>): string;
|
|
10
|
+
declare function isCassetteAvailable(vcrConfig: VcrConfig, cassetteName: string): boolean;
|
|
11
|
+
|
|
12
|
+
type CassetteDataType<TFilter, TBlock> = {
|
|
13
|
+
filter: TFilter;
|
|
14
|
+
messages: StreamDataResponse<TBlock>[];
|
|
15
|
+
};
|
|
16
|
+
declare function record<TFilter, TBlock, TTxnParams>(vcrConfig: VcrConfig, client: Client<TFilter, TBlock>, indexerArg: Indexer<TFilter, TBlock, TTxnParams>, cassetteOptions: CassetteOptions): Promise<void>;
|
|
17
|
+
|
|
18
|
+
export { type CassetteDataType, CassetteOptions, VcrConfig, deserialize, isCassetteAvailable, record, serialize };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { V as VcrConfig, C as CassetteOptions } from '../shared/indexer.e1856641.mjs';
|
|
2
|
+
export { a as VcrReplayResult, l as loadCassette, r as replay } from '../shared/indexer.e1856641.mjs';
|
|
3
|
+
import { StreamDataResponse, Client } from '@apibara/protocol';
|
|
4
|
+
import { f as Indexer } from '../shared/indexer.e8bd138d.mjs';
|
|
5
|
+
import '../shared/indexer.b9c8f0d8.mjs';
|
|
6
|
+
import 'hookable';
|
|
7
|
+
|
|
8
|
+
declare function deserialize(str: string): any;
|
|
9
|
+
declare function serialize(obj: Record<string, unknown>): string;
|
|
10
|
+
declare function isCassetteAvailable(vcrConfig: VcrConfig, cassetteName: string): boolean;
|
|
11
|
+
|
|
12
|
+
type CassetteDataType<TFilter, TBlock> = {
|
|
13
|
+
filter: TFilter;
|
|
14
|
+
messages: StreamDataResponse<TBlock>[];
|
|
15
|
+
};
|
|
16
|
+
declare function record<TFilter, TBlock, TTxnParams>(vcrConfig: VcrConfig, client: Client<TFilter, TBlock>, indexerArg: Indexer<TFilter, TBlock, TTxnParams>, cassetteOptions: CassetteOptions): Promise<void>;
|
|
17
|
+
|
|
18
|
+
export { type CassetteDataType, CassetteOptions, VcrConfig, deserialize, isCassetteAvailable, record, serialize };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { V as VcrConfig, C as CassetteOptions } from '../shared/indexer.e4f2430f.js';
|
|
2
|
+
export { a as VcrReplayResult, l as loadCassette, r as replay } from '../shared/indexer.e4f2430f.js';
|
|
3
|
+
import { StreamDataResponse, Client } from '@apibara/protocol';
|
|
4
|
+
import { f as Indexer } from '../shared/indexer.f761abcd.js';
|
|
5
|
+
import '../shared/indexer.b9c8f0d8.js';
|
|
6
|
+
import 'hookable';
|
|
7
|
+
|
|
8
|
+
declare function deserialize(str: string): any;
|
|
9
|
+
declare function serialize(obj: Record<string, unknown>): string;
|
|
10
|
+
declare function isCassetteAvailable(vcrConfig: VcrConfig, cassetteName: string): boolean;
|
|
11
|
+
|
|
12
|
+
type CassetteDataType<TFilter, TBlock> = {
|
|
13
|
+
filter: TFilter;
|
|
14
|
+
messages: StreamDataResponse<TBlock>[];
|
|
15
|
+
};
|
|
16
|
+
declare function record<TFilter, TBlock, TTxnParams>(vcrConfig: VcrConfig, client: Client<TFilter, TBlock>, indexerArg: Indexer<TFilter, TBlock, TTxnParams>, cassetteOptions: CassetteOptions): Promise<void>;
|
|
17
|
+
|
|
18
|
+
export { type CassetteDataType, CassetteOptions, VcrConfig, deserialize, isCassetteAvailable, record, serialize };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { d as deserialize, i as isCassetteAvailable, s as serialize } from '../shared/indexer.2c23c9cd.mjs';
|
|
2
|
+
export { l as loadCassette, a as record, b as replay } from '../shared/indexer.36530330.mjs';
|
|
3
|
+
import 'node:async_hooks';
|
|
4
|
+
import 'unctx';
|
|
5
|
+
import '@opentelemetry/api';
|
|
6
|
+
import 'node:fs';
|
|
7
|
+
import 'node:path';
|
|
8
|
+
import 'node:fs/promises';
|
|
9
|
+
import 'klona/full';
|
|
10
|
+
import 'consola';
|
|
11
|
+
import 'hookable';
|
|
12
|
+
import 'node:assert';
|
|
13
|
+
import '../shared/indexer.93d6b2eb.mjs';
|
|
14
|
+
import '@apibara/protocol/testing';
|