@acala-network/chopsticks-db 1.3.0 → 1.4.0

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.
@@ -13,4 +13,8 @@ export declare abstract class BaseSqlDatabase implements Database {
13
13
  saveStorage(blockHash: HexString, key: HexString, value: HexString | null): Promise<void>;
14
14
  saveStorageBatch(entries: KeyValueEntry[]): Promise<void>;
15
15
  queryStorage(blockHash: HexString, key: HexString): Promise<KeyValueEntry | null>;
16
+ queryPagedKeys(blockHash: HexString, prefix: HexString): Promise<HexString[] | null>;
17
+ savePagedKeys(blockHash: HexString, prefix: HexString, keys: HexString[]): Promise<void>;
18
+ queryRpcCall(scope: string, method: string, params: string): Promise<string | null>;
19
+ saveRpcCall(scope: string, method: string, params: string, result: string): Promise<void>;
16
20
  }
@@ -107,6 +107,51 @@ class BaseSqlDatabase {
107
107
  }
108
108
  });
109
109
  }
110
+ async queryPagedKeys(blockHash, prefix) {
111
+ const db = await this.datasource;
112
+ const row = await db.getRepository(_entities.PagedKeys).findOne({
113
+ where: {
114
+ blockHash,
115
+ prefix
116
+ }
117
+ });
118
+ return row ? JSON.parse(row.keys) : null;
119
+ }
120
+ async savePagedKeys(blockHash, prefix, keys) {
121
+ const db = await this.datasource;
122
+ await db.getRepository(_entities.PagedKeys).upsert({
123
+ blockHash,
124
+ prefix,
125
+ keys: JSON.stringify(keys)
126
+ }, [
127
+ 'blockHash',
128
+ 'prefix'
129
+ ]);
130
+ }
131
+ async queryRpcCall(scope, method, params) {
132
+ const db = await this.datasource;
133
+ const row = await db.getRepository(_entities.RpcCall).findOne({
134
+ where: {
135
+ scope,
136
+ method,
137
+ params
138
+ }
139
+ });
140
+ return row?.result ?? null;
141
+ }
142
+ async saveRpcCall(scope, method, params, result) {
143
+ const db = await this.datasource;
144
+ await db.getRepository(_entities.RpcCall).upsert({
145
+ scope,
146
+ method,
147
+ params,
148
+ result
149
+ }, [
150
+ 'scope',
151
+ 'method',
152
+ 'params'
153
+ ]);
154
+ }
110
155
  constructor(){
111
156
  _define_property(this, "close", async ()=>{
112
157
  const db = await this.datasource;
@@ -1,4 +1,17 @@
1
1
  import type { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core';
2
2
  import { EntitySchema } from 'typeorm';
3
+ export type PagedKeysEntry = {
4
+ blockHash: string;
5
+ prefix: string;
6
+ keys: string;
7
+ };
8
+ export type RpcCallEntry = {
9
+ scope: string;
10
+ method: string;
11
+ params: string;
12
+ result: string;
13
+ };
3
14
  export declare const KeyValuePair: EntitySchema<KeyValueEntry>;
4
15
  export declare const BlockEntity: EntitySchema<BlockEntry>;
16
+ export declare const PagedKeys: EntitySchema<PagedKeysEntry>;
17
+ export declare const RpcCall: EntitySchema<RpcCallEntry>;
@@ -14,6 +14,12 @@ _export(exports, {
14
14
  },
15
15
  get KeyValuePair () {
16
16
  return KeyValuePair;
17
+ },
18
+ get PagedKeys () {
19
+ return PagedKeys;
20
+ },
21
+ get RpcCall () {
22
+ return RpcCall;
17
23
  }
18
24
  });
19
25
  const _typeorm = require("typeorm");
@@ -66,3 +72,46 @@ const BlockEntity = new _typeorm.EntitySchema({
66
72
  }
67
73
  }
68
74
  });
75
+ const PagedKeys = new _typeorm.EntitySchema({
76
+ name: 'PagedKeys',
77
+ columns: {
78
+ blockHash: {
79
+ primary: true,
80
+ type: 'varchar',
81
+ nullable: false
82
+ },
83
+ prefix: {
84
+ primary: true,
85
+ type: 'varchar',
86
+ nullable: false
87
+ },
88
+ keys: {
89
+ type: 'text',
90
+ nullable: false
91
+ }
92
+ }
93
+ });
94
+ const RpcCall = new _typeorm.EntitySchema({
95
+ name: 'RpcCall',
96
+ columns: {
97
+ scope: {
98
+ primary: true,
99
+ type: 'varchar',
100
+ nullable: false
101
+ },
102
+ method: {
103
+ primary: true,
104
+ type: 'varchar',
105
+ nullable: false
106
+ },
107
+ params: {
108
+ primary: true,
109
+ type: 'varchar',
110
+ nullable: false
111
+ },
112
+ result: {
113
+ type: 'text',
114
+ nullable: false
115
+ }
116
+ }
117
+ });
@@ -13,4 +13,8 @@ export declare abstract class BaseSqlDatabase implements Database {
13
13
  saveStorage(blockHash: HexString, key: HexString, value: HexString | null): Promise<void>;
14
14
  saveStorageBatch(entries: KeyValueEntry[]): Promise<void>;
15
15
  queryStorage(blockHash: HexString, key: HexString): Promise<KeyValueEntry | null>;
16
+ queryPagedKeys(blockHash: HexString, prefix: HexString): Promise<HexString[] | null>;
17
+ savePagedKeys(blockHash: HexString, prefix: HexString, keys: HexString[]): Promise<void>;
18
+ queryRpcCall(scope: string, method: string, params: string): Promise<string | null>;
19
+ saveRpcCall(scope: string, method: string, params: string, result: string): Promise<void>;
16
20
  }
@@ -1,4 +1,4 @@
1
- import { BlockEntity, KeyValuePair } from './db/entities.js';
1
+ import { BlockEntity, KeyValuePair, PagedKeys, RpcCall } from './db/entities.js';
2
2
  export class BaseSqlDatabase {
3
3
  close = async ()=>{
4
4
  const db = await this.datasource;
@@ -88,4 +88,49 @@ export class BaseSqlDatabase {
88
88
  }
89
89
  });
90
90
  }
91
+ async queryPagedKeys(blockHash, prefix) {
92
+ const db = await this.datasource;
93
+ const row = await db.getRepository(PagedKeys).findOne({
94
+ where: {
95
+ blockHash,
96
+ prefix
97
+ }
98
+ });
99
+ return row ? JSON.parse(row.keys) : null;
100
+ }
101
+ async savePagedKeys(blockHash, prefix, keys) {
102
+ const db = await this.datasource;
103
+ await db.getRepository(PagedKeys).upsert({
104
+ blockHash,
105
+ prefix,
106
+ keys: JSON.stringify(keys)
107
+ }, [
108
+ 'blockHash',
109
+ 'prefix'
110
+ ]);
111
+ }
112
+ async queryRpcCall(scope, method, params) {
113
+ const db = await this.datasource;
114
+ const row = await db.getRepository(RpcCall).findOne({
115
+ where: {
116
+ scope,
117
+ method,
118
+ params
119
+ }
120
+ });
121
+ return row?.result ?? null;
122
+ }
123
+ async saveRpcCall(scope, method, params, result) {
124
+ const db = await this.datasource;
125
+ await db.getRepository(RpcCall).upsert({
126
+ scope,
127
+ method,
128
+ params,
129
+ result
130
+ }, [
131
+ 'scope',
132
+ 'method',
133
+ 'params'
134
+ ]);
135
+ }
91
136
  }
@@ -1,4 +1,17 @@
1
1
  import type { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core';
2
2
  import { EntitySchema } from 'typeorm';
3
+ export type PagedKeysEntry = {
4
+ blockHash: string;
5
+ prefix: string;
6
+ keys: string;
7
+ };
8
+ export type RpcCallEntry = {
9
+ scope: string;
10
+ method: string;
11
+ params: string;
12
+ result: string;
13
+ };
3
14
  export declare const KeyValuePair: EntitySchema<KeyValueEntry>;
4
15
  export declare const BlockEntity: EntitySchema<BlockEntry>;
16
+ export declare const PagedKeys: EntitySchema<PagedKeysEntry>;
17
+ export declare const RpcCall: EntitySchema<RpcCallEntry>;
@@ -48,3 +48,46 @@ export const BlockEntity = new EntitySchema({
48
48
  }
49
49
  }
50
50
  });
51
+ export const PagedKeys = new EntitySchema({
52
+ name: 'PagedKeys',
53
+ columns: {
54
+ blockHash: {
55
+ primary: true,
56
+ type: 'varchar',
57
+ nullable: false
58
+ },
59
+ prefix: {
60
+ primary: true,
61
+ type: 'varchar',
62
+ nullable: false
63
+ },
64
+ keys: {
65
+ type: 'text',
66
+ nullable: false
67
+ }
68
+ }
69
+ });
70
+ export const RpcCall = new EntitySchema({
71
+ name: 'RpcCall',
72
+ columns: {
73
+ scope: {
74
+ primary: true,
75
+ type: 'varchar',
76
+ nullable: false
77
+ },
78
+ method: {
79
+ primary: true,
80
+ type: 'varchar',
81
+ nullable: false
82
+ },
83
+ params: {
84
+ primary: true,
85
+ type: 'varchar',
86
+ nullable: false
87
+ },
88
+ result: {
89
+ type: 'text',
90
+ nullable: false
91
+ }
92
+ }
93
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-db",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -13,11 +13,11 @@
13
13
  "depcheck": "npx depcheck"
14
14
  },
15
15
  "dependencies": {
16
- "@acala-network/chopsticks-core": "1.3.0",
16
+ "@acala-network/chopsticks-core": "1.4.0",
17
17
  "@polkadot/util": "^14.0.1",
18
18
  "idb": "^8.0.3",
19
19
  "reflect-metadata": "^0.2.2",
20
- "sqlite3": "^5.1.7",
20
+ "sqlite3": "^6.0.1",
21
21
  "typeorm": "^0.3.26"
22
22
  },
23
23
  "devDependencies": {