@sqd-pipes/delta-db 0.0.1-alpha.1 → 0.0.1-alpha.3
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 +3 -3
- package/src/delta-db.node +0 -0
- package/src/index.d.ts +16 -13
- package/src/index.js +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqd-pipes/delta-db",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.3",
|
|
4
4
|
"description": "Embedded rollback-aware computation engine for blockchain data",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "napi build --cargo-cwd
|
|
15
|
-
"build:debug": "napi build --cargo-cwd
|
|
14
|
+
"build": "napi build --cargo-cwd ../../.. --features napi --release --dts native.d.ts src",
|
|
15
|
+
"build:debug": "napi build --cargo-cwd ../../.. --features napi --dts native.d.ts src",
|
|
16
16
|
"test": "vitest run",
|
|
17
17
|
"test:watch": "vitest"
|
|
18
18
|
},
|
package/src/delta-db.node
CHANGED
|
Binary file
|
package/src/index.d.ts
CHANGED
|
@@ -17,34 +17,36 @@ export interface DeltaDbCursor {
|
|
|
17
17
|
hash: string
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
export type DeltaOperation = 'insert' | 'update' | 'delete'
|
|
21
|
+
|
|
21
22
|
export interface DeltaRecord {
|
|
22
23
|
table: string
|
|
23
|
-
operation:
|
|
24
|
+
operation: DeltaOperation
|
|
24
25
|
key: Record<string, any>
|
|
25
26
|
values: Record<string, any>
|
|
26
|
-
prevValues
|
|
27
|
+
prevValues: Record<string, any> | null
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/** A batch of delta records. */
|
|
30
30
|
export interface DeltaBatch {
|
|
31
31
|
sequence: number
|
|
32
|
-
finalizedHead
|
|
33
|
-
latestHead
|
|
34
|
-
records:
|
|
32
|
+
finalizedHead: DeltaDbCursor | null
|
|
33
|
+
latestHead: DeltaDbCursor | null
|
|
34
|
+
records: DeltaRecord[]
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/** Input for the atomic `ingest()` method. */
|
|
38
38
|
export interface IngestInput {
|
|
39
|
-
/** Table name → rows
|
|
40
|
-
data: Record<string,
|
|
39
|
+
/** Table name → rows: `{tableName: [{col: val}, ...], ...}`. */
|
|
40
|
+
data: Record<string, Record<string, any>[]>
|
|
41
41
|
/** Unfinalized blocks with hashes for fork resolution. */
|
|
42
|
-
rollbackChain?:
|
|
42
|
+
rollbackChain?: DeltaDbCursor[]
|
|
43
43
|
/** Finalized head cursor — both number and hash stored. */
|
|
44
44
|
finalizedHead: DeltaDbCursor
|
|
45
|
+
/** Called with each delta batch. When provided, batch is auto-acked. */
|
|
46
|
+
onDelta?: (batch: DeltaBatch) => void
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
/** Delta DB
|
|
49
|
+
/** Delta DB wrapper. */
|
|
48
50
|
export declare class DeltaDb {
|
|
49
51
|
/** Open a new DeltaDb instance. */
|
|
50
52
|
static open(config: DeltaDbConfig): DeltaDb
|
|
@@ -52,7 +54,7 @@ export declare class DeltaDb {
|
|
|
52
54
|
* Process a batch of rows for a raw table.
|
|
53
55
|
* Returns true if backpressure should be applied.
|
|
54
56
|
*/
|
|
55
|
-
processBatch(table: string, block: number, rows:
|
|
57
|
+
processBatch(table: string, block: number, rows: Record<string, any>[]): boolean
|
|
56
58
|
/** Roll back all state after fork_point. */
|
|
57
59
|
rollback(forkPoint: number): void
|
|
58
60
|
/** Finalize all state up to and including the given block. */
|
|
@@ -60,13 +62,14 @@ export declare class DeltaDb {
|
|
|
60
62
|
/**
|
|
61
63
|
* Atomic ingest: process all tables, store rollback chain, finalize, flush.
|
|
62
64
|
* Returns the delta batch, or null if no records produced.
|
|
65
|
+
* When `onDelta` is provided in input, it is called and batch is auto-acked.
|
|
63
66
|
*/
|
|
64
67
|
ingest(input: IngestInput): DeltaBatch | null
|
|
65
68
|
/**
|
|
66
69
|
* Find the common ancestor between our state and the Portal's chain.
|
|
67
70
|
* Returns the matching block cursor, or null if no common ancestor found.
|
|
68
71
|
*/
|
|
69
|
-
resolveForkCursor(previousBlocks:
|
|
72
|
+
resolveForkCursor(previousBlocks: DeltaDbCursor[]): DeltaDbCursor | null
|
|
70
73
|
/** Flush buffered deltas into a batch. Returns null if no pending records. */
|
|
71
74
|
flush(): DeltaBatch | null
|
|
72
75
|
/** Acknowledge a flushed batch by sequence number. */
|
package/src/index.js
CHANGED
|
@@ -44,7 +44,12 @@ class DeltaDb {
|
|
|
44
44
|
rollbackChain: input.rollbackChain,
|
|
45
45
|
finalizedHead: input.finalizedHead,
|
|
46
46
|
})
|
|
47
|
-
|
|
47
|
+
const batch = buf ? decode(buf) : null
|
|
48
|
+
if (batch && input.onDelta) {
|
|
49
|
+
input.onDelta(batch)
|
|
50
|
+
this.#native.ack(batch.sequence)
|
|
51
|
+
}
|
|
52
|
+
return batch
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
/**
|