@sentio/sdk 2.40.1-rc.1 → 2.40.1-rc.10
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/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +25 -69
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.js +10 -24
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.js +20 -52
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +11 -25
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.js +16 -40
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.js +13 -31
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/file.d.ts.map +1 -1
- package/lib/eth/codegen/file.js +5 -1
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/codegen/function-calls.d.ts +1 -0
- package/lib/eth/codegen/function-calls.d.ts.map +1 -1
- package/lib/eth/codegen/function-calls.js +3 -1
- package/lib/eth/codegen/function-calls.js.map +1 -1
- package/lib/eth/codegen/types.d.ts.map +1 -1
- package/lib/eth/codegen/types.js +23 -6
- package/lib/eth/codegen/types.js.map +1 -1
- package/lib/store/cache.d.ts +0 -3
- package/lib/store/cache.d.ts.map +1 -1
- package/lib/store/cache.js.map +1 -1
- package/lib/store/codegen.d.ts.map +1 -1
- package/lib/store/codegen.js +51 -34
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/store.d.ts +3 -3
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +2 -2
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.d.ts +6 -0
- package/lib/store/types.d.ts.map +1 -1
- package/lib/store/types.js +49 -1
- package/lib/store/types.js.map +1 -1
- package/package.json +5 -8
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +26 -69
- package/src/eth/builtin/internal/erc1155-processor.ts +11 -24
- package/src/eth/builtin/internal/erc20-processor.ts +21 -52
- package/src/eth/builtin/internal/erc20bytes-processor.ts +12 -25
- package/src/eth/builtin/internal/erc721-processor.ts +17 -40
- package/src/eth/builtin/internal/weth9-processor.ts +14 -31
- package/src/eth/codegen/file.ts +5 -0
- package/src/eth/codegen/function-calls.ts +4 -1
- package/src/eth/codegen/types.ts +32 -7
- package/src/store/cache.ts +0 -4
- package/src/store/codegen.ts +53 -34
- package/src/store/store.ts +5 -5
- package/src/store/types.ts +57 -0
@@ -151,6 +151,23 @@ export type TransferFromCallTrace = TypedCallTrace<
|
|
151
151
|
|
152
152
|
const templateContract = ERC721__factory.connect("0x0", DummyProvider);
|
153
153
|
|
154
|
+
const iface = new Interface([
|
155
|
+
"function approve(address to, uint256 tokenId) returns ()",
|
156
|
+
"function totalSupply() view returns (uint256)",
|
157
|
+
"function balanceOf(address owner) view returns (uint256 balance)",
|
158
|
+
"function getApproved(uint256 tokenId) view returns (address operator)",
|
159
|
+
"function isApprovedForAll(address owner, address operator) view returns (bool)",
|
160
|
+
"function name() view returns (string)",
|
161
|
+
"function ownerOf(uint256 tokenId) view returns (address owner)",
|
162
|
+
"function safeTransferFrom(address from, address to, uint256 tokenId) returns ()",
|
163
|
+
"function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) returns ()",
|
164
|
+
"function setApprovalForAll(address operator, bool _approved) returns ()",
|
165
|
+
"function supportsInterface(bytes4 interfaceId) view returns (bool)",
|
166
|
+
"function symbol() view returns (string)",
|
167
|
+
"function tokenURI(uint256 tokenId) view returns (string)",
|
168
|
+
"function transferFrom(address from, address to, uint256 tokenId) returns ()",
|
169
|
+
]);
|
170
|
+
|
154
171
|
export class ERC721ContractView extends ContractView<ERC721> {
|
155
172
|
constructor(contract: ERC721) {
|
156
173
|
super(contract);
|
@@ -164,9 +181,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
164
181
|
): Promise<bigint> {
|
165
182
|
try {
|
166
183
|
if (preparedData?.ethCallResults && ethCallContext) {
|
167
|
-
const iface = new Interface([
|
168
|
-
"function totalSupply() view returns (uint256)",
|
169
|
-
]);
|
170
184
|
const calldata = iface.encodeFunctionData("totalSupply", []);
|
171
185
|
const ethCallKey = makeEthCallKey({
|
172
186
|
context: ethCallContext,
|
@@ -195,9 +209,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
195
209
|
): Promise<bigint> {
|
196
210
|
try {
|
197
211
|
if (preparedData?.ethCallResults && ethCallContext) {
|
198
|
-
const iface = new Interface([
|
199
|
-
"function balanceOf(address) view returns (uint256)",
|
200
|
-
]);
|
201
212
|
const calldata = iface.encodeFunctionData("balanceOf", [owner]);
|
202
213
|
const ethCallKey = makeEthCallKey({
|
203
214
|
context: ethCallContext,
|
@@ -227,9 +238,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
227
238
|
): Promise<string> {
|
228
239
|
try {
|
229
240
|
if (preparedData?.ethCallResults && ethCallContext) {
|
230
|
-
const iface = new Interface([
|
231
|
-
"function getApproved(uint256) view returns (address)",
|
232
|
-
]);
|
233
241
|
const calldata = iface.encodeFunctionData("getApproved", [tokenId]);
|
234
242
|
const ethCallKey = makeEthCallKey({
|
235
243
|
context: ethCallContext,
|
@@ -262,9 +270,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
262
270
|
): Promise<boolean> {
|
263
271
|
try {
|
264
272
|
if (preparedData?.ethCallResults && ethCallContext) {
|
265
|
-
const iface = new Interface([
|
266
|
-
"function isApprovedForAll(address,address) view returns (bool)",
|
267
|
-
]);
|
268
273
|
const calldata = iface.encodeFunctionData("isApprovedForAll", [
|
269
274
|
owner,
|
270
275
|
operator,
|
@@ -297,7 +302,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
297
302
|
): Promise<string> {
|
298
303
|
try {
|
299
304
|
if (preparedData?.ethCallResults && ethCallContext) {
|
300
|
-
const iface = new Interface(["function name() view returns (string)"]);
|
301
305
|
const calldata = iface.encodeFunctionData("name", []);
|
302
306
|
const ethCallKey = makeEthCallKey({
|
303
307
|
context: ethCallContext,
|
@@ -324,9 +328,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
324
328
|
): Promise<string> {
|
325
329
|
try {
|
326
330
|
if (preparedData?.ethCallResults && ethCallContext) {
|
327
|
-
const iface = new Interface([
|
328
|
-
"function ownerOf(uint256) view returns (address)",
|
329
|
-
]);
|
330
331
|
const calldata = iface.encodeFunctionData("ownerOf", [tokenId]);
|
331
332
|
const ethCallKey = makeEthCallKey({
|
332
333
|
context: ethCallContext,
|
@@ -356,9 +357,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
356
357
|
): Promise<boolean> {
|
357
358
|
try {
|
358
359
|
if (preparedData?.ethCallResults && ethCallContext) {
|
359
|
-
const iface = new Interface([
|
360
|
-
"function supportsInterface(bytes4) view returns (bool)",
|
361
|
-
]);
|
362
360
|
const calldata = iface.encodeFunctionData("supportsInterface", [
|
363
361
|
interfaceId,
|
364
362
|
]);
|
@@ -391,9 +389,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
391
389
|
): Promise<string> {
|
392
390
|
try {
|
393
391
|
if (preparedData?.ethCallResults && ethCallContext) {
|
394
|
-
const iface = new Interface([
|
395
|
-
"function symbol() view returns (string)",
|
396
|
-
]);
|
397
392
|
const calldata = iface.encodeFunctionData("symbol", []);
|
398
393
|
const ethCallKey = makeEthCallKey({
|
399
394
|
context: ethCallContext,
|
@@ -420,9 +415,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
420
415
|
): Promise<string> {
|
421
416
|
try {
|
422
417
|
if (preparedData?.ethCallResults && ethCallContext) {
|
423
|
-
const iface = new Interface([
|
424
|
-
"function tokenURI(uint256) view returns (string)",
|
425
|
-
]);
|
426
418
|
const calldata = iface.encodeFunctionData("tokenURI", [tokenId]);
|
427
419
|
const ethCallKey = makeEthCallKey({
|
428
420
|
context: ethCallContext,
|
@@ -456,9 +448,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
456
448
|
): Promise<void> {
|
457
449
|
try {
|
458
450
|
if (preparedData?.ethCallResults && ethCallContext) {
|
459
|
-
const iface = new Interface([
|
460
|
-
"function approve(address,uint256) nonpayable returns ()",
|
461
|
-
]);
|
462
451
|
const calldata = iface.encodeFunctionData("approve", [to, tokenId]);
|
463
452
|
const ethCallKey = makeEthCallKey({
|
464
453
|
context: ethCallContext,
|
@@ -488,9 +477,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
488
477
|
): Promise<void> {
|
489
478
|
try {
|
490
479
|
if (preparedData?.ethCallResults && ethCallContext) {
|
491
|
-
const iface = new Interface([
|
492
|
-
"function safeTransferFrom(address,address,uint256) nonpayable returns ()",
|
493
|
-
]);
|
494
480
|
const calldata = iface.encodeFunctionData("safeTransferFrom", [
|
495
481
|
from,
|
496
482
|
to,
|
@@ -527,9 +513,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
527
513
|
): Promise<void> {
|
528
514
|
try {
|
529
515
|
if (preparedData?.ethCallResults && ethCallContext) {
|
530
|
-
const iface = new Interface([
|
531
|
-
"function safeTransferFrom(address,address,uint256,bytes) nonpayable returns ()",
|
532
|
-
]);
|
533
516
|
const calldata = iface.encodeFunctionData("safeTransferFrom", [
|
534
517
|
from,
|
535
518
|
to,
|
@@ -565,9 +548,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
565
548
|
): Promise<void> {
|
566
549
|
try {
|
567
550
|
if (preparedData?.ethCallResults && ethCallContext) {
|
568
|
-
const iface = new Interface([
|
569
|
-
"function setApprovalForAll(address,bool) nonpayable returns ()",
|
570
|
-
]);
|
571
551
|
const calldata = iface.encodeFunctionData("setApprovalForAll", [
|
572
552
|
operator,
|
573
553
|
_approved,
|
@@ -602,9 +582,6 @@ export class ERC721ContractView extends ContractView<ERC721> {
|
|
602
582
|
): Promise<void> {
|
603
583
|
try {
|
604
584
|
if (preparedData?.ethCallResults && ethCallContext) {
|
605
|
-
const iface = new Interface([
|
606
|
-
"function transferFrom(address,address,uint256) nonpayable returns ()",
|
607
|
-
]);
|
608
585
|
const calldata = iface.encodeFunctionData("transferFrom", [
|
609
586
|
from,
|
610
587
|
to,
|
@@ -108,6 +108,20 @@ export type AllowanceCallTrace = TypedCallTrace<
|
|
108
108
|
|
109
109
|
const templateContract = WETH9__factory.connect("0x0", DummyProvider);
|
110
110
|
|
111
|
+
const iface = new Interface([
|
112
|
+
"function name() view returns (string)",
|
113
|
+
"function approve(address guy, uint256 wad) returns (bool)",
|
114
|
+
"function totalSupply() view returns (uint256)",
|
115
|
+
"function transferFrom(address src, address dst, uint256 wad) returns (bool)",
|
116
|
+
"function withdraw(uint256 wad) returns ()",
|
117
|
+
"function decimals() view returns (uint8)",
|
118
|
+
"function balanceOf(address) view returns (uint256)",
|
119
|
+
"function symbol() view returns (string)",
|
120
|
+
"function transfer(address dst, uint256 wad) returns (bool)",
|
121
|
+
"function deposit() payable returns ()",
|
122
|
+
"function allowance(address, address) view returns (uint256)",
|
123
|
+
]);
|
124
|
+
|
111
125
|
export class WETH9ContractView extends ContractView<WETH9> {
|
112
126
|
constructor(contract: WETH9) {
|
113
127
|
super(contract);
|
@@ -121,7 +135,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
121
135
|
): Promise<string> {
|
122
136
|
try {
|
123
137
|
if (preparedData?.ethCallResults && ethCallContext) {
|
124
|
-
const iface = new Interface(["function name() view returns (string)"]);
|
125
138
|
const calldata = iface.encodeFunctionData("name", []);
|
126
139
|
const ethCallKey = makeEthCallKey({
|
127
140
|
context: ethCallContext,
|
@@ -147,9 +160,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
147
160
|
): Promise<bigint> {
|
148
161
|
try {
|
149
162
|
if (preparedData?.ethCallResults && ethCallContext) {
|
150
|
-
const iface = new Interface([
|
151
|
-
"function totalSupply() view returns (uint256)",
|
152
|
-
]);
|
153
163
|
const calldata = iface.encodeFunctionData("totalSupply", []);
|
154
164
|
const ethCallKey = makeEthCallKey({
|
155
165
|
context: ethCallContext,
|
@@ -177,9 +187,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
177
187
|
): Promise<bigint> {
|
178
188
|
try {
|
179
189
|
if (preparedData?.ethCallResults && ethCallContext) {
|
180
|
-
const iface = new Interface([
|
181
|
-
"function decimals() view returns (uint8)",
|
182
|
-
]);
|
183
190
|
const calldata = iface.encodeFunctionData("decimals", []);
|
184
191
|
const ethCallKey = makeEthCallKey({
|
185
192
|
context: ethCallContext,
|
@@ -206,9 +213,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
206
213
|
): Promise<bigint> {
|
207
214
|
try {
|
208
215
|
if (preparedData?.ethCallResults && ethCallContext) {
|
209
|
-
const iface = new Interface([
|
210
|
-
"function balanceOf(address) view returns (uint256)",
|
211
|
-
]);
|
212
216
|
const calldata = iface.encodeFunctionData("balanceOf", [arg0]);
|
213
217
|
const ethCallKey = makeEthCallKey({
|
214
218
|
context: ethCallContext,
|
@@ -237,9 +241,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
237
241
|
): Promise<string> {
|
238
242
|
try {
|
239
243
|
if (preparedData?.ethCallResults && ethCallContext) {
|
240
|
-
const iface = new Interface([
|
241
|
-
"function symbol() view returns (string)",
|
242
|
-
]);
|
243
244
|
const calldata = iface.encodeFunctionData("symbol", []);
|
244
245
|
const ethCallKey = makeEthCallKey({
|
245
246
|
context: ethCallContext,
|
@@ -267,9 +268,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
267
268
|
): Promise<bigint> {
|
268
269
|
try {
|
269
270
|
if (preparedData?.ethCallResults && ethCallContext) {
|
270
|
-
const iface = new Interface([
|
271
|
-
"function allowance(address,address) view returns (uint256)",
|
272
|
-
]);
|
273
271
|
const calldata = iface.encodeFunctionData("allowance", [arg0, arg1]);
|
274
272
|
const ethCallKey = makeEthCallKey({
|
275
273
|
context: ethCallContext,
|
@@ -304,9 +302,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
304
302
|
): Promise<boolean> {
|
305
303
|
try {
|
306
304
|
if (preparedData?.ethCallResults && ethCallContext) {
|
307
|
-
const iface = new Interface([
|
308
|
-
"function approve(address,uint256) nonpayable returns (bool)",
|
309
|
-
]);
|
310
305
|
const calldata = iface.encodeFunctionData("approve", [guy, wad]);
|
311
306
|
const ethCallKey = makeEthCallKey({
|
312
307
|
context: ethCallContext,
|
@@ -336,9 +331,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
336
331
|
): Promise<boolean> {
|
337
332
|
try {
|
338
333
|
if (preparedData?.ethCallResults && ethCallContext) {
|
339
|
-
const iface = new Interface([
|
340
|
-
"function transferFrom(address,address,uint256) nonpayable returns (bool)",
|
341
|
-
]);
|
342
334
|
const calldata = iface.encodeFunctionData("transferFrom", [
|
343
335
|
src,
|
344
336
|
dst,
|
@@ -372,9 +364,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
372
364
|
): Promise<void> {
|
373
365
|
try {
|
374
366
|
if (preparedData?.ethCallResults && ethCallContext) {
|
375
|
-
const iface = new Interface([
|
376
|
-
"function withdraw(uint256) nonpayable returns ()",
|
377
|
-
]);
|
378
367
|
const calldata = iface.encodeFunctionData("withdraw", [wad]);
|
379
368
|
const ethCallKey = makeEthCallKey({
|
380
369
|
context: ethCallContext,
|
@@ -405,9 +394,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
405
394
|
): Promise<boolean> {
|
406
395
|
try {
|
407
396
|
if (preparedData?.ethCallResults && ethCallContext) {
|
408
|
-
const iface = new Interface([
|
409
|
-
"function transfer(address,uint256) nonpayable returns (bool)",
|
410
|
-
]);
|
411
397
|
const calldata = iface.encodeFunctionData("transfer", [dst, wad]);
|
412
398
|
const ethCallKey = makeEthCallKey({
|
413
399
|
context: ethCallContext,
|
@@ -436,9 +422,6 @@ export class WETH9ContractView extends ContractView<WETH9> {
|
|
436
422
|
): Promise<void> {
|
437
423
|
try {
|
438
424
|
if (preparedData?.ethCallResults && ethCallContext) {
|
439
|
-
const iface = new Interface([
|
440
|
-
"function deposit() payable returns ()",
|
441
|
-
]);
|
442
425
|
const calldata = iface.encodeFunctionData("deposit", []);
|
443
426
|
const ethCallKey = makeEthCallKey({
|
444
427
|
context: ethCallContext,
|
package/src/eth/codegen/file.ts
CHANGED
@@ -13,6 +13,7 @@ import {
|
|
13
13
|
generateBoundFunctionCallEncoders,
|
14
14
|
generateBoundViewFunctions,
|
15
15
|
generateFunctionCallEncoders,
|
16
|
+
generateFunctionSignatures,
|
16
17
|
generateViewFunctions
|
17
18
|
} from './function-calls.js'
|
18
19
|
|
@@ -30,6 +31,10 @@ export function codeGenSentioFile(contract: Contract): string {
|
|
30
31
|
${Object.values(contract.functions).map(codegenCallTraceTypes).join('\n')}
|
31
32
|
|
32
33
|
const templateContract = ${contract.name}__factory.connect("0x0", DummyProvider)
|
34
|
+
|
35
|
+
const iface = new Interface([${Object.values(contract.functions)
|
36
|
+
.filter((f) => !reservedKeywords.has(f[0].name))
|
37
|
+
.flatMap((fs) => generateFunctionSignatures(fs))}])
|
33
38
|
|
34
39
|
export class ${contract.name}ContractView extends ContractView<${contract.name}> {
|
35
40
|
constructor (contract: ${contract.name}) {
|
@@ -17,6 +17,10 @@ export function generateViewFunctions(view: boolean, functions: FunctionDeclarat
|
|
17
17
|
return functions.flatMap((fn) => generateViewFunction(view, fn, includeArgTypes))
|
18
18
|
}
|
19
19
|
|
20
|
+
export function generateFunctionSignatures(functions: FunctionDeclaration[]): string[] {
|
21
|
+
return functions.map((fn) => `"function ${getFullSignatureWithOutputForFn(fn)}"`)
|
22
|
+
}
|
23
|
+
|
20
24
|
export function generateViewFunction(view: boolean, fn: FunctionDeclaration, includeArgTypes: boolean): string[] {
|
21
25
|
const isView = fn.stateMutability === 'view' || fn.stateMutability === 'pure'
|
22
26
|
if (view !== isView) {
|
@@ -41,7 +45,6 @@ export function generateViewFunction(view: boolean, fn: FunctionDeclaration, inc
|
|
41
45
|
})}overrides?: Overrides, preparedData?: PreparedData, ethCallContext?: EthCallContext): ${generateReturnTypes(fn)} {
|
42
46
|
try {
|
43
47
|
if (preparedData?.ethCallResults && ethCallContext) {
|
44
|
-
const iface = new Interface(["function ${getFullSignatureWithOutputForFn(fn)}"])
|
45
48
|
const calldata = iface.encodeFunctionData(
|
46
49
|
"${fn.name}",[${
|
47
50
|
fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
package/src/eth/codegen/types.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import {
|
2
2
|
AbiOutputParameter,
|
3
3
|
AbiParameter,
|
4
|
+
ArrayType,
|
5
|
+
EventArgDeclaration,
|
4
6
|
EventDeclaration,
|
5
7
|
FunctionDeclaration,
|
6
|
-
|
7
|
-
getSignatureForFn
|
8
|
+
TupleType
|
8
9
|
} from 'typechain'
|
9
10
|
import { EvmType } from 'typechain/dist/parser/parseEvmType.js'
|
10
11
|
|
@@ -48,6 +49,13 @@ export function getFullSignatureForFunction(fn: FunctionDeclaration): string {
|
|
48
49
|
.join(',')})`
|
49
50
|
}
|
50
51
|
|
52
|
+
export function getFullSignatureWithOutputForFn(fn: FunctionDeclaration) {
|
53
|
+
return `${fn.name}(${fn.inputs.map((i) => getArgumentForSignature(i)).join(', ')}) ${fn.stateMutability != 'nonpayable' ? fn.stateMutability + ' ' : ''}returns (${fn.outputs
|
54
|
+
.map((i) => getOutputArgumentForSignature(i))
|
55
|
+
.filter((s) => s != '')
|
56
|
+
.join(', ')})`
|
57
|
+
}
|
58
|
+
|
51
59
|
function getOutputArgumentForSignature(argument: AbiOutputParameter) {
|
52
60
|
if (argument.type.type == 'void') {
|
53
61
|
return ''
|
@@ -55,9 +63,26 @@ function getOutputArgumentForSignature(argument: AbiOutputParameter) {
|
|
55
63
|
return getArgumentForSignature(argument as AbiParameter)
|
56
64
|
}
|
57
65
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
function getArgumentForSignature(argument: EventArgDeclaration | AbiParameter): string {
|
67
|
+
if (argument.type.originalType === 'tuple') {
|
68
|
+
return getTypeWithName(
|
69
|
+
`(${(argument.type as TupleType).components.map((i) => getArgumentForSignature(i)).join(', ')})`,
|
70
|
+
argument.name
|
71
|
+
)
|
72
|
+
} else if (argument.type.originalType.startsWith('tuple')) {
|
73
|
+
const arr = argument.type as ArrayType
|
74
|
+
return getTypeWithName(
|
75
|
+
`${getArgumentForSignature({
|
76
|
+
name: '',
|
77
|
+
type: arr.itemType
|
78
|
+
})}[${arr.size?.toString() || ''}]`,
|
79
|
+
argument.name
|
80
|
+
)
|
81
|
+
} else {
|
82
|
+
return getTypeWithName(argument.type.originalType, argument.name)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
function getTypeWithName(type: string, name?: string) {
|
87
|
+
return (name ?? '').length > 0 ? `${type} ${name}` : type
|
63
88
|
}
|
package/src/store/cache.ts
CHANGED
package/src/store/codegen.ts
CHANGED
@@ -34,6 +34,7 @@ interface Class {
|
|
34
34
|
name: string
|
35
35
|
fields: Field[]
|
36
36
|
annotations: string[]
|
37
|
+
parent?: string
|
37
38
|
interfaces: string[]
|
38
39
|
}
|
39
40
|
|
@@ -98,7 +99,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
98
99
|
},
|
99
100
|
{
|
100
101
|
module: '@sentio/sdk/store',
|
101
|
-
types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn']
|
102
|
+
types: ['Entity', 'Required', 'One', 'Many', 'Column', 'ListColumn', 'AbstractEntity']
|
102
103
|
},
|
103
104
|
{
|
104
105
|
module: '@sentio/bigdecimal',
|
@@ -134,44 +135,60 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
134
135
|
})
|
135
136
|
}
|
136
137
|
}
|
138
|
+
|
137
139
|
for (const t of Object.values(schema.getTypeMap())) {
|
138
140
|
if (t.name.startsWith('__')) {
|
139
141
|
continue
|
140
142
|
}
|
141
143
|
|
142
144
|
if (t instanceof GraphQLObjectType) {
|
143
|
-
|
144
|
-
|
145
|
-
const
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
145
|
+
if (isEntity(t)) {
|
146
|
+
const fields: Field[] = []
|
147
|
+
for (const f of Object.values(t.getFields())) {
|
148
|
+
const type = genType(f.type)
|
149
|
+
const annotations: string[] = []
|
150
|
+
addTypeAnnotations(f.type, annotations)
|
151
|
+
if (isRelationType(f.type)) {
|
152
|
+
fields.push({
|
153
|
+
name: f.name,
|
154
|
+
type: `Promise<${type}>`,
|
155
|
+
annotations
|
156
|
+
})
|
157
|
+
const isMany = type.startsWith('Array')
|
158
|
+
fields.push({
|
159
|
+
name: f.name + 'ID' + (isMany ? 's' : ''),
|
160
|
+
type: isMany ? `Array<ID | undefined>` : `ID`,
|
161
|
+
annotations: []
|
162
|
+
})
|
163
|
+
} else {
|
164
|
+
fields.push({
|
165
|
+
name: f.name,
|
166
|
+
optional: !f.type.toString().endsWith('!'),
|
167
|
+
type: type.replace(' | undefined', ''),
|
168
|
+
annotations
|
169
|
+
})
|
170
|
+
}
|
171
|
+
}
|
172
|
+
classes.push({
|
173
|
+
name: t.name,
|
174
|
+
fields,
|
175
|
+
annotations: [`@Entity("${t.name}")`],
|
176
|
+
parent: 'AbstractEntity',
|
177
|
+
interfaces: t.getInterfaces().map((i) => i.name)
|
178
|
+
})
|
179
|
+
} else {
|
180
|
+
classes.push({
|
181
|
+
name: t.name,
|
182
|
+
fields: Object.values(t.getFields()).map((f) => ({
|
162
183
|
name: f.name,
|
163
184
|
optional: !f.type.toString().endsWith('!'),
|
164
|
-
type: type.replace(' | undefined', ''),
|
165
|
-
annotations
|
166
|
-
})
|
167
|
-
|
185
|
+
type: genType(f.type).replace(' | undefined', ''),
|
186
|
+
annotations: []
|
187
|
+
})),
|
188
|
+
annotations: [],
|
189
|
+
interfaces: t.getInterfaces().map((i) => i.name)
|
190
|
+
})
|
168
191
|
}
|
169
|
-
classes.push({
|
170
|
-
name: t.name,
|
171
|
-
fields,
|
172
|
-
annotations: [`@Entity("${t.name}")`],
|
173
|
-
interfaces: t.getInterfaces().map((i) => i.name)
|
174
|
-
})
|
175
192
|
}
|
176
193
|
}
|
177
194
|
|
@@ -201,13 +218,11 @@ ${classes
|
|
201
218
|
.map(
|
202
219
|
(c) => `
|
203
220
|
${c.annotations.join('\n')}
|
204
|
-
export class ${c.name} ${c.interfaces.length > 0 ? `implements ${c.interfaces.join(', ')}` : ''} {
|
221
|
+
export class ${c.name} ${c.parent ? `extends ${c.parent}` : ''} ${c.interfaces.length > 0 ? `implements ${c.interfaces.join(', ')}` : ''} {
|
205
222
|
${c.fields
|
206
223
|
.map((f) => `${f.annotations.map((a) => `\n\t${a}`).join('')}\n\t${f.name}${f.optional ? '?' : ''}: ${f.type}`)
|
207
224
|
.join('\n')}
|
208
|
-
|
209
|
-
constructor(data: Partial<${c.name}>) {}
|
210
|
-
|
225
|
+
${c.annotations.some((a) => a.startsWith('@Entity')) ? `constructor(data: Partial<${c.name}>) {super()}` : ''}
|
211
226
|
}`
|
212
227
|
)
|
213
228
|
.join('\n')}
|
@@ -256,3 +271,7 @@ function isRelationType(type: GraphQLOutputType): boolean {
|
|
256
271
|
return false
|
257
272
|
}
|
258
273
|
}
|
274
|
+
|
275
|
+
function isEntity(t: GraphQLObjectType) {
|
276
|
+
return t.astNode?.directives?.some((d) => d.name.value == 'entity')
|
277
|
+
}
|
package/src/store/store.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
import { StoreContext } from './context.js'
|
2
2
|
import { DatabaseSchema } from '../core/index.js'
|
3
3
|
import { BigDecimal } from '@sentio/bigdecimal'
|
4
|
-
import { Bytes, Float, ID, Int, Timestamp } from './types.js'
|
4
|
+
import { AbstractEntity as Entity, Bytes, Float, ID, Int, Timestamp } from './types.js'
|
5
5
|
import type { DBRequest, Entity as EntityStruct, RichValue } from '@sentio/protos'
|
6
6
|
import { DBRequest_DBOperator, DBResponse } from '@sentio/protos'
|
7
7
|
import { toBigInteger } from './convert.js'
|
8
8
|
import { PluginManager } from '@sentio/runtime'
|
9
9
|
import { Cursor } from './cursor.js'
|
10
|
-
import {
|
10
|
+
import { LocalCache } from './cache.js'
|
11
11
|
|
12
12
|
export interface EntityClass<T> {
|
13
13
|
new (data: Partial<T>): T
|
14
14
|
}
|
15
15
|
|
16
|
-
function getEntityName<T>(entity: EntityClass<T> | T | string): string {
|
16
|
+
export function getEntityName<T>(entity: EntityClass<T> | T | string): string {
|
17
17
|
if (entity == null) {
|
18
18
|
throw new Error("can't figure out entityName from undefined")
|
19
19
|
}
|
@@ -182,7 +182,7 @@ export class Store {
|
|
182
182
|
|
183
183
|
async list<T extends Entity, P extends keyof T, O extends Operators<T[P]>>(
|
184
184
|
entity: EntityClass<T>,
|
185
|
-
filters
|
185
|
+
filters?: ListFilter<T, P, O>[],
|
186
186
|
cursor?: Cursor
|
187
187
|
) {
|
188
188
|
if (cursor) {
|
@@ -191,7 +191,7 @@ export class Store {
|
|
191
191
|
return response.entityList?.entities.map((data) => this.newEntity(entity, data)) || []
|
192
192
|
}
|
193
193
|
// TODO Array.fromAsync when upgrade to node 22
|
194
|
-
return this.fromAsync(this.listIterator(entity, filters))
|
194
|
+
return this.fromAsync(this.listIterator(entity, filters ?? []))
|
195
195
|
}
|
196
196
|
|
197
197
|
private async fromAsync<T>(gen: AsyncIterable<T>): Promise<T[]> {
|
package/src/store/types.ts
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
import { RichStruct, RichValue } from '@sentio/protos'
|
2
|
+
import { BigDecimalConverter, BigIntConverter } from './convert.js'
|
3
|
+
import { getEntityName } from './store.js'
|
4
|
+
|
1
5
|
export type ID = string | Uint8Array
|
2
6
|
export type String = string
|
3
7
|
export type Int = number
|
@@ -6,3 +10,56 @@ export type Boolean = boolean
|
|
6
10
|
export type Timestamp = Date
|
7
11
|
export type Bytes = Uint8Array
|
8
12
|
export type BigInt = bigint
|
13
|
+
|
14
|
+
export abstract class AbstractEntity {
|
15
|
+
abstract id: ID
|
16
|
+
private readonly _data: RichStruct
|
17
|
+
|
18
|
+
toJSON() {
|
19
|
+
const obj: any = {}
|
20
|
+
|
21
|
+
for (const [field, value] of Object.entries(this._data.fields)) {
|
22
|
+
obj[field] = toJSValue(value)
|
23
|
+
}
|
24
|
+
return obj
|
25
|
+
}
|
26
|
+
|
27
|
+
toString() {
|
28
|
+
const obj = this.toJSON()
|
29
|
+
return `${getEntityName(this)} ${JSON.stringify(obj)}`
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
function toJSValue(value: RichValue): any {
|
34
|
+
if (value.nullValue) {
|
35
|
+
return null
|
36
|
+
}
|
37
|
+
if (value.bytesValue) {
|
38
|
+
return value.bytesValue
|
39
|
+
}
|
40
|
+
if (value.stringValue) {
|
41
|
+
return value.stringValue
|
42
|
+
}
|
43
|
+
if (value.bigdecimalValue) {
|
44
|
+
return BigDecimalConverter.to(value)
|
45
|
+
}
|
46
|
+
if (value.bigintValue) {
|
47
|
+
return BigIntConverter.to(value)
|
48
|
+
}
|
49
|
+
if (value.boolValue) {
|
50
|
+
return value.boolValue
|
51
|
+
}
|
52
|
+
if (value.timestampValue) {
|
53
|
+
return value.timestampValue
|
54
|
+
}
|
55
|
+
if (value.floatValue) {
|
56
|
+
return value.floatValue
|
57
|
+
}
|
58
|
+
if (value.intValue) {
|
59
|
+
return value.intValue
|
60
|
+
}
|
61
|
+
if (value.listValue) {
|
62
|
+
return value.listValue.values.map(toJSValue)
|
63
|
+
}
|
64
|
+
throw new Error('Unknown value type:' + JSON.stringify(value))
|
65
|
+
}
|