|
| 1 | +diff --git a/dist/cjs/base-sql.d.ts b/dist/cjs/base-sql.d.ts |
| 2 | +index 04c6083e33ca834e3e46599cc1b9f02ec6d2e08a..697b5010b7d311b89bfd87c2b732ca3bae16a095 100644 |
| 3 | +--- a/dist/cjs/base-sql.d.ts |
| 4 | ++++ b/dist/cjs/base-sql.d.ts |
| 5 | +@@ -13,4 +13,8 @@ export declare abstract class BaseSqlDatabase implements Database { |
| 6 | + saveStorage(blockHash: HexString, key: HexString, value: HexString | null): Promise<void>; |
| 7 | + saveStorageBatch(entries: KeyValueEntry[]): Promise<void>; |
| 8 | + queryStorage(blockHash: HexString, key: HexString): Promise<KeyValueEntry | null>; |
| 9 | ++ queryPagedKeys(blockHash: HexString, prefix: HexString): Promise<HexString[] | null>; |
| 10 | ++ savePagedKeys(blockHash: HexString, prefix: HexString, keys: HexString[]): Promise<void>; |
| 11 | ++ queryRpcCall(scope: string, method: string, params: string): Promise<string | null>; |
| 12 | ++ saveRpcCall(scope: string, method: string, params: string, result: string): Promise<void>; |
| 13 | + } |
| 14 | +diff --git a/dist/cjs/base-sql.js b/dist/cjs/base-sql.js |
| 15 | +index 5734ae19b072c0a878ae8aca70e1c7392075c579..f10d667006466c265564def304271733d0de6d3f 100644 |
| 16 | +--- a/dist/cjs/base-sql.js |
| 17 | ++++ b/dist/cjs/base-sql.js |
| 18 | +@@ -107,6 +107,51 @@ class BaseSqlDatabase { |
| 19 | + } |
| 20 | + }); |
| 21 | + } |
| 22 | ++ async queryPagedKeys(blockHash, prefix) { |
| 23 | ++ const db = await this.datasource; |
| 24 | ++ const row = await db.getRepository(_entities.PagedKeys).findOne({ |
| 25 | ++ where: { |
| 26 | ++ blockHash, |
| 27 | ++ prefix |
| 28 | ++ } |
| 29 | ++ }); |
| 30 | ++ return row ? JSON.parse(row.keys) : null; |
| 31 | ++ } |
| 32 | ++ async savePagedKeys(blockHash, prefix, keys) { |
| 33 | ++ const db = await this.datasource; |
| 34 | ++ await db.getRepository(_entities.PagedKeys).upsert({ |
| 35 | ++ blockHash, |
| 36 | ++ prefix, |
| 37 | ++ keys: JSON.stringify(keys) |
| 38 | ++ }, [ |
| 39 | ++ 'blockHash', |
| 40 | ++ 'prefix' |
| 41 | ++ ]); |
| 42 | ++ } |
| 43 | ++ async queryRpcCall(scope, method, params) { |
| 44 | ++ const db = await this.datasource; |
| 45 | ++ const row = await db.getRepository(_entities.RpcCall).findOne({ |
| 46 | ++ where: { |
| 47 | ++ scope, |
| 48 | ++ method, |
| 49 | ++ params |
| 50 | ++ } |
| 51 | ++ }); |
| 52 | ++ return row?.result ?? null; |
| 53 | ++ } |
| 54 | ++ async saveRpcCall(scope, method, params, result) { |
| 55 | ++ const db = await this.datasource; |
| 56 | ++ await db.getRepository(_entities.RpcCall).upsert({ |
| 57 | ++ scope, |
| 58 | ++ method, |
| 59 | ++ params, |
| 60 | ++ result |
| 61 | ++ }, [ |
| 62 | ++ 'scope', |
| 63 | ++ 'method', |
| 64 | ++ 'params' |
| 65 | ++ ]); |
| 66 | ++ } |
| 67 | + constructor(){ |
| 68 | + _define_property(this, "close", async ()=>{ |
| 69 | + const db = await this.datasource; |
| 70 | +diff --git a/dist/cjs/db/entities.d.ts b/dist/cjs/db/entities.d.ts |
| 71 | +index 879c444011b699b4a7bf4068c8874c2895209405..24cb0016d0535caf10a644591f6b3becd989dfdb 100644 |
| 72 | +--- a/dist/cjs/db/entities.d.ts |
| 73 | ++++ b/dist/cjs/db/entities.d.ts |
| 74 | +@@ -1,4 +1,17 @@ |
| 75 | + import type { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core'; |
| 76 | + import { EntitySchema } from 'typeorm'; |
| 77 | ++export type PagedKeysEntry = { |
| 78 | ++ blockHash: string; |
| 79 | ++ prefix: string; |
| 80 | ++ keys: string; |
| 81 | ++}; |
| 82 | ++export type RpcCallEntry = { |
| 83 | ++ scope: string; |
| 84 | ++ method: string; |
| 85 | ++ params: string; |
| 86 | ++ result: string; |
| 87 | ++}; |
| 88 | + export declare const KeyValuePair: EntitySchema<KeyValueEntry>; |
| 89 | + export declare const BlockEntity: EntitySchema<BlockEntry>; |
| 90 | ++export declare const PagedKeys: EntitySchema<PagedKeysEntry>; |
| 91 | ++export declare const RpcCall: EntitySchema<RpcCallEntry>; |
| 92 | +diff --git a/dist/cjs/db/entities.js b/dist/cjs/db/entities.js |
| 93 | +index 5e19c84a85685cc01772a85c104d642ed50e4f8a..e03ba46a3abdb0e4b23196604537d0aebed5669a 100644 |
| 94 | +--- a/dist/cjs/db/entities.js |
| 95 | ++++ b/dist/cjs/db/entities.js |
| 96 | +@@ -14,6 +14,12 @@ _export(exports, { |
| 97 | + }, |
| 98 | + get KeyValuePair () { |
| 99 | + return KeyValuePair; |
| 100 | ++ }, |
| 101 | ++ get PagedKeys () { |
| 102 | ++ return PagedKeys; |
| 103 | ++ }, |
| 104 | ++ get RpcCall () { |
| 105 | ++ return RpcCall; |
| 106 | + } |
| 107 | + }); |
| 108 | + const _typeorm = require("typeorm"); |
| 109 | +@@ -66,3 +72,46 @@ const BlockEntity = new _typeorm.EntitySchema({ |
| 110 | + } |
| 111 | + } |
| 112 | + }); |
| 113 | ++const PagedKeys = new _typeorm.EntitySchema({ |
| 114 | ++ name: 'PagedKeys', |
| 115 | ++ columns: { |
| 116 | ++ blockHash: { |
| 117 | ++ primary: true, |
| 118 | ++ type: 'varchar', |
| 119 | ++ nullable: false |
| 120 | ++ }, |
| 121 | ++ prefix: { |
| 122 | ++ primary: true, |
| 123 | ++ type: 'varchar', |
| 124 | ++ nullable: false |
| 125 | ++ }, |
| 126 | ++ keys: { |
| 127 | ++ type: 'text', |
| 128 | ++ nullable: false |
| 129 | ++ } |
| 130 | ++ } |
| 131 | ++}); |
| 132 | ++const RpcCall = new _typeorm.EntitySchema({ |
| 133 | ++ name: 'RpcCall', |
| 134 | ++ columns: { |
| 135 | ++ scope: { |
| 136 | ++ primary: true, |
| 137 | ++ type: 'varchar', |
| 138 | ++ nullable: false |
| 139 | ++ }, |
| 140 | ++ method: { |
| 141 | ++ primary: true, |
| 142 | ++ type: 'varchar', |
| 143 | ++ nullable: false |
| 144 | ++ }, |
| 145 | ++ params: { |
| 146 | ++ primary: true, |
| 147 | ++ type: 'varchar', |
| 148 | ++ nullable: false |
| 149 | ++ }, |
| 150 | ++ result: { |
| 151 | ++ type: 'text', |
| 152 | ++ nullable: false |
| 153 | ++ } |
| 154 | ++ } |
| 155 | ++}); |
| 156 | +diff --git a/dist/esm/base-sql.d.ts b/dist/esm/base-sql.d.ts |
| 157 | +index 04c6083e33ca834e3e46599cc1b9f02ec6d2e08a..697b5010b7d311b89bfd87c2b732ca3bae16a095 100644 |
| 158 | +--- a/dist/esm/base-sql.d.ts |
| 159 | ++++ b/dist/esm/base-sql.d.ts |
| 160 | +@@ -13,4 +13,8 @@ export declare abstract class BaseSqlDatabase implements Database { |
| 161 | + saveStorage(blockHash: HexString, key: HexString, value: HexString | null): Promise<void>; |
| 162 | + saveStorageBatch(entries: KeyValueEntry[]): Promise<void>; |
| 163 | + queryStorage(blockHash: HexString, key: HexString): Promise<KeyValueEntry | null>; |
| 164 | ++ queryPagedKeys(blockHash: HexString, prefix: HexString): Promise<HexString[] | null>; |
| 165 | ++ savePagedKeys(blockHash: HexString, prefix: HexString, keys: HexString[]): Promise<void>; |
| 166 | ++ queryRpcCall(scope: string, method: string, params: string): Promise<string | null>; |
| 167 | ++ saveRpcCall(scope: string, method: string, params: string, result: string): Promise<void>; |
| 168 | + } |
| 169 | +diff --git a/dist/esm/base-sql.js b/dist/esm/base-sql.js |
| 170 | +index 539cb415345dc9ac4eb0d32eb9e4bbda6e54df75..08739df5d4f3676e0c4d99c3e5ddd415caee854a 100644 |
| 171 | +--- a/dist/esm/base-sql.js |
| 172 | ++++ b/dist/esm/base-sql.js |
| 173 | +@@ -1,4 +1,4 @@ |
| 174 | +-import { BlockEntity, KeyValuePair } from './db/entities.js'; |
| 175 | ++import { BlockEntity, KeyValuePair, PagedKeys, RpcCall } from './db/entities.js'; |
| 176 | + export class BaseSqlDatabase { |
| 177 | + close = async ()=>{ |
| 178 | + const db = await this.datasource; |
| 179 | +@@ -88,4 +88,49 @@ export class BaseSqlDatabase { |
| 180 | + } |
| 181 | + }); |
| 182 | + } |
| 183 | ++ async queryPagedKeys(blockHash, prefix) { |
| 184 | ++ const db = await this.datasource; |
| 185 | ++ const row = await db.getRepository(PagedKeys).findOne({ |
| 186 | ++ where: { |
| 187 | ++ blockHash, |
| 188 | ++ prefix |
| 189 | ++ } |
| 190 | ++ }); |
| 191 | ++ return row ? JSON.parse(row.keys) : null; |
| 192 | ++ } |
| 193 | ++ async savePagedKeys(blockHash, prefix, keys) { |
| 194 | ++ const db = await this.datasource; |
| 195 | ++ await db.getRepository(PagedKeys).upsert({ |
| 196 | ++ blockHash, |
| 197 | ++ prefix, |
| 198 | ++ keys: JSON.stringify(keys) |
| 199 | ++ }, [ |
| 200 | ++ 'blockHash', |
| 201 | ++ 'prefix' |
| 202 | ++ ]); |
| 203 | ++ } |
| 204 | ++ async queryRpcCall(scope, method, params) { |
| 205 | ++ const db = await this.datasource; |
| 206 | ++ const row = await db.getRepository(RpcCall).findOne({ |
| 207 | ++ where: { |
| 208 | ++ scope, |
| 209 | ++ method, |
| 210 | ++ params |
| 211 | ++ } |
| 212 | ++ }); |
| 213 | ++ return row?.result ?? null; |
| 214 | ++ } |
| 215 | ++ async saveRpcCall(scope, method, params, result) { |
| 216 | ++ const db = await this.datasource; |
| 217 | ++ await db.getRepository(RpcCall).upsert({ |
| 218 | ++ scope, |
| 219 | ++ method, |
| 220 | ++ params, |
| 221 | ++ result |
| 222 | ++ }, [ |
| 223 | ++ 'scope', |
| 224 | ++ 'method', |
| 225 | ++ 'params' |
| 226 | ++ ]); |
| 227 | ++ } |
| 228 | + } |
| 229 | +diff --git a/dist/esm/db/entities.d.ts b/dist/esm/db/entities.d.ts |
| 230 | +index 879c444011b699b4a7bf4068c8874c2895209405..24cb0016d0535caf10a644591f6b3becd989dfdb 100644 |
| 231 | +--- a/dist/esm/db/entities.d.ts |
| 232 | ++++ b/dist/esm/db/entities.d.ts |
| 233 | +@@ -1,4 +1,17 @@ |
| 234 | + import type { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core'; |
| 235 | + import { EntitySchema } from 'typeorm'; |
| 236 | ++export type PagedKeysEntry = { |
| 237 | ++ blockHash: string; |
| 238 | ++ prefix: string; |
| 239 | ++ keys: string; |
| 240 | ++}; |
| 241 | ++export type RpcCallEntry = { |
| 242 | ++ scope: string; |
| 243 | ++ method: string; |
| 244 | ++ params: string; |
| 245 | ++ result: string; |
| 246 | ++}; |
| 247 | + export declare const KeyValuePair: EntitySchema<KeyValueEntry>; |
| 248 | + export declare const BlockEntity: EntitySchema<BlockEntry>; |
| 249 | ++export declare const PagedKeys: EntitySchema<PagedKeysEntry>; |
| 250 | ++export declare const RpcCall: EntitySchema<RpcCallEntry>; |
| 251 | +diff --git a/dist/esm/db/entities.js b/dist/esm/db/entities.js |
| 252 | +index b9acbe3aba398e7ddd034efeca4e1a081b478a83..bc92dd457944aed10638dd3d66faa9cb8bd4b031 100644 |
| 253 | +--- a/dist/esm/db/entities.js |
| 254 | ++++ b/dist/esm/db/entities.js |
| 255 | +@@ -48,3 +48,46 @@ export const BlockEntity = new EntitySchema({ |
| 256 | + } |
| 257 | + } |
| 258 | + }); |
| 259 | ++export const PagedKeys = new EntitySchema({ |
| 260 | ++ name: 'PagedKeys', |
| 261 | ++ columns: { |
| 262 | ++ blockHash: { |
| 263 | ++ primary: true, |
| 264 | ++ type: 'varchar', |
| 265 | ++ nullable: false |
| 266 | ++ }, |
| 267 | ++ prefix: { |
| 268 | ++ primary: true, |
| 269 | ++ type: 'varchar', |
| 270 | ++ nullable: false |
| 271 | ++ }, |
| 272 | ++ keys: { |
| 273 | ++ type: 'text', |
| 274 | ++ nullable: false |
| 275 | ++ } |
| 276 | ++ } |
| 277 | ++}); |
| 278 | ++export const RpcCall = new EntitySchema({ |
| 279 | ++ name: 'RpcCall', |
| 280 | ++ columns: { |
| 281 | ++ scope: { |
| 282 | ++ primary: true, |
| 283 | ++ type: 'varchar', |
| 284 | ++ nullable: false |
| 285 | ++ }, |
| 286 | ++ method: { |
| 287 | ++ primary: true, |
| 288 | ++ type: 'varchar', |
| 289 | ++ nullable: false |
| 290 | ++ }, |
| 291 | ++ params: { |
| 292 | ++ primary: true, |
| 293 | ++ type: 'varchar', |
| 294 | ++ nullable: false |
| 295 | ++ }, |
| 296 | ++ result: { |
| 297 | ++ type: 'text', |
| 298 | ++ nullable: false |
| 299 | ++ } |
| 300 | ++ } |
| 301 | ++}); |
0 commit comments