@subsquid/solana-stream 0.2.0-2-0.a5e4b7 → 0.2.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.
Files changed (104) hide show
  1. package/README.md +4 -0
  2. package/lib/{schema.d.ts → archive/schema.d.ts} +22 -32
  3. package/lib/archive/schema.d.ts.map +1 -0
  4. package/lib/{schema.js → archive/schema.js} +39 -55
  5. package/lib/archive/schema.js.map +1 -0
  6. package/lib/archive/source.d.ts +15 -0
  7. package/lib/archive/source.d.ts.map +1 -0
  8. package/lib/archive/source.js +98 -0
  9. package/lib/archive/source.js.map +1 -0
  10. package/lib/data/fields.d.ts +8 -0
  11. package/lib/data/fields.d.ts.map +1 -0
  12. package/lib/data/fields.js +46 -0
  13. package/lib/data/fields.js.map +1 -0
  14. package/lib/data/model.d.ts +79 -0
  15. package/lib/data/model.d.ts.map +1 -0
  16. package/lib/data/model.js +44 -0
  17. package/lib/data/model.js.map +1 -0
  18. package/lib/data/partial.d.ts +26 -0
  19. package/lib/data/partial.d.ts.map +1 -0
  20. package/lib/data/partial.js +3 -0
  21. package/lib/data/partial.js.map +1 -0
  22. package/lib/data/request.d.ts +108 -0
  23. package/lib/data/request.d.ts.map +1 -0
  24. package/lib/data/request.js +3 -0
  25. package/lib/data/request.js.map +1 -0
  26. package/lib/data/type-util.d.ts +20 -0
  27. package/lib/data/type-util.d.ts.map +1 -0
  28. package/lib/data/type-util.js +3 -0
  29. package/lib/data/type-util.js.map +1 -0
  30. package/lib/index.d.ts +3 -3
  31. package/lib/index.d.ts.map +1 -1
  32. package/lib/index.js +3 -3
  33. package/lib/index.js.map +1 -1
  34. package/lib/instruction.d.ts +3 -2
  35. package/lib/instruction.d.ts.map +1 -1
  36. package/lib/instruction.js +2 -2
  37. package/lib/instruction.js.map +1 -1
  38. package/lib/rpc/client.d.ts +17 -0
  39. package/lib/rpc/client.d.ts.map +1 -0
  40. package/lib/rpc/client.js +15 -0
  41. package/lib/rpc/client.js.map +1 -0
  42. package/lib/rpc/filter.d.ts +4 -0
  43. package/lib/rpc/filter.d.ts.map +1 -0
  44. package/lib/rpc/filter.js +357 -0
  45. package/lib/rpc/filter.js.map +1 -0
  46. package/lib/rpc/mapping.d.ts +5 -0
  47. package/lib/rpc/mapping.d.ts.map +1 -0
  48. package/lib/rpc/mapping.js +12 -0
  49. package/lib/rpc/mapping.js.map +1 -0
  50. package/lib/rpc/project.d.ts +5 -0
  51. package/lib/rpc/project.d.ts.map +1 -0
  52. package/lib/rpc/project.js +60 -0
  53. package/lib/rpc/project.js.map +1 -0
  54. package/lib/rpc/source.d.ts +15 -0
  55. package/lib/rpc/source.d.ts.map +1 -0
  56. package/lib/rpc/source.js +82 -0
  57. package/lib/rpc/source.js.map +1 -0
  58. package/lib/source.d.ts +101 -17
  59. package/lib/source.d.ts.map +1 -1
  60. package/lib/source.js +269 -70
  61. package/lib/source.js.map +1 -1
  62. package/package.json +15 -9
  63. package/src/{schema.ts → archive/schema.ts} +35 -54
  64. package/src/archive/source.ts +105 -0
  65. package/src/data/fields.ts +50 -0
  66. package/src/data/model.ts +154 -0
  67. package/src/data/partial.ts +31 -0
  68. package/src/data/request.ts +142 -0
  69. package/src/data/type-util.ts +42 -0
  70. package/src/index.ts +3 -3
  71. package/src/instruction.ts +9 -4
  72. package/src/rpc/client.ts +26 -0
  73. package/src/rpc/filter.ts +368 -0
  74. package/src/rpc/mapping.ts +13 -0
  75. package/src/rpc/project.ts +61 -0
  76. package/src/rpc/source.ts +90 -0
  77. package/src/source.ts +368 -92
  78. package/lib/objects/index.d.ts +0 -4
  79. package/lib/objects/index.d.ts.map +0 -1
  80. package/lib/objects/index.js +0 -23
  81. package/lib/objects/index.js.map +0 -1
  82. package/lib/objects/items.d.ts +0 -83
  83. package/lib/objects/items.d.ts.map +0 -1
  84. package/lib/objects/items.js +0 -260
  85. package/lib/objects/items.js.map +0 -1
  86. package/lib/objects/relations.d.ts +0 -3
  87. package/lib/objects/relations.d.ts.map +0 -1
  88. package/lib/objects/relations.js +0 -82
  89. package/lib/objects/relations.js.map +0 -1
  90. package/lib/objects/types.d.ts +0 -76
  91. package/lib/objects/types.d.ts.map +0 -1
  92. package/lib/objects/types.js +0 -29
  93. package/lib/objects/types.js.map +0 -1
  94. package/lib/query.d.ts +0 -46
  95. package/lib/query.d.ts.map +0 -1
  96. package/lib/query.js +0 -96
  97. package/lib/query.js.map +0 -1
  98. package/lib/schema.d.ts.map +0 -1
  99. package/lib/schema.js.map +0 -1
  100. package/src/objects/index.ts +0 -3
  101. package/src/objects/items.ts +0 -296
  102. package/src/objects/relations.ts +0 -90
  103. package/src/objects/types.ts +0 -88
  104. package/src/query.ts +0 -149
package/lib/schema.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AAoBA,0BAUC;AA7BD,2DAAgD;AAChD,iFAe2C;AAG3C,SAAgB,OAAO,CAAI,MAAqC,EAAE,GAAM;IACpE,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,EAAE,CAAA;IAC7B,IAAI,MAAM,GAAe,EAAE,CAAA;IAC3B,IAAI,GAAY,CAAA;IAChB,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACd,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1B,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC;AAEY,QAAA,kBAAkB,GAAG,IAAA,iCAAM,EAAC;IACrC,UAAU,EAAE,8BAAG;IACf,eAAe,EAAE,IAAA,gCAAK,EAAC,8BAAG,CAAC;IAC3B,eAAe,EAAE,IAAA,gCAAK,EAAC,8BAAG,CAAC;CAC9B,CAAC,CAAA;AAEW,QAAA,aAAa,GAAG,IAAA,wBAAQ,EAAC,CAAC,MAAsB,EAAE,EAAE;IAC7D,IAAI,WAA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C,OAAO,CAAC,CAAC;QAChC,aAAa,EAAE,IAAA,iCAAM,EAAC,IAAA,gCAAK,EAAC,YAAY,CAAC,CAAC;QAC1C,OAAO,EAAE,IAAA,iCAAM,EAAC,IAAA,gCAAK,EAAC,MAAM,CAAC,CAAC;KACjC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './types'
2
- export {setUpRelations} from './relations'
3
- export {blockFromPartial} from './items'
@@ -1,296 +0,0 @@
1
- import {Base58, Bytes} from '@subsquid/util-internal'
2
- import {getInstructionDescriptor} from '../instruction'
3
- import type * as base from './types'
4
-
5
- // TODO: is it needed?
6
- export {
7
- AddressTableLookup,
8
- BalanceFields,
9
- BalanceFieldSelection,
10
- BlockHeaderFields,
11
- BlockHeaderFieldSelection,
12
- Discriminator,
13
- InstructionFields,
14
- InstructionFieldSelection,
15
- LogMessageFields,
16
- LogMessageFieldSelection,
17
- PostTokenBalanceFields,
18
- PrePostTokenBalanceFields,
19
- PreTokenBalanceFields,
20
- RewardFields,
21
- RewardFieldSelection,
22
- TokenBalanceFields,
23
- TokenBalanceFieldSelection,
24
- TransactionFields,
25
- TransactionFieldSelection,
26
- } from '@subsquid/portal-client/lib/query/solana'
27
-
28
- export function blockFromPartial<F extends base.ReqiredFieldSelection>(src: base.BlockPartial<F>): base.Block<F> {
29
- // FIXME: why types are broken
30
- return Object.assign(new Block(), {
31
- header: Object.assign(new BlockHeader(), src.header),
32
- transactions: src.transactions?.map((i) => Object.assign(new Transaction(), i)) || [],
33
- instructions: src.instructions?.map((i) => Object.assign(new Instruction(), i)) || [],
34
- logs: src.logs?.map((i) => Object.assign(new LogMessage(), i)) || [],
35
- balances: src.balances?.map((i) => Object.assign(new Balance(), i)) || [],
36
- tokenBalances: src.tokenBalances?.map((i) => Object.assign(new TokenBalance(), i)) || [],
37
- rewards: src.rewards?.map((i) => Object.assign(new Reward(), i)) || [],
38
- }) as unknown as base.Block<F>
39
- }
40
-
41
- export interface Block extends base.Block {}
42
- export class Block {}
43
-
44
- export interface BlockHeader extends base.BlockHeader {}
45
- export class BlockHeader {}
46
-
47
- export interface Transaction extends base.Transaction {}
48
- export class Transaction {
49
- #block!: Block
50
- #instructions?: Instruction[]
51
- #balances?: Balance[]
52
- #tokenBalances?: TokenBalance[]
53
-
54
- get block(): Block {
55
- return this.#block
56
- }
57
-
58
- set block(value: Block) {
59
- this.#block = value
60
- }
61
-
62
- get instructions(): Instruction[] {
63
- if (this.#instructions == null) {
64
- this.#instructions = []
65
- }
66
- return this.#instructions
67
- }
68
-
69
- set instructions(value: Instruction[]) {
70
- this.#instructions = value
71
- }
72
-
73
- get balances(): Balance[] {
74
- if (this.#balances == null) {
75
- this.#balances = []
76
- }
77
- return this.#balances
78
- }
79
-
80
- set balances(value: Balance[]) {
81
- this.#balances = value
82
- }
83
-
84
- get tokenBalances(): TokenBalance[] {
85
- if (this.#tokenBalances == null) {
86
- this.#tokenBalances = []
87
- }
88
- return this.#tokenBalances
89
- }
90
-
91
- set tokenBalances(value: TokenBalance[]) {
92
- this.#tokenBalances = value
93
- }
94
- }
95
-
96
- export interface Instruction extends base.Instruction {}
97
- export class Instruction {
98
- #block!: Block
99
- #transaction?: Transaction
100
- #inner?: Instruction[]
101
- #parent?: Instruction
102
- #logs?: LogMessage[]
103
- #d1?: string
104
- #d2?: string
105
- #d4?: string
106
- #d8?: string
107
-
108
- get block(): Block {
109
- return this.#block
110
- }
111
-
112
- set block(value: Block) {
113
- this.#block = value
114
- }
115
-
116
- get transaction(): Transaction | undefined {
117
- return this.#transaction
118
- }
119
-
120
- set transaction(value: Transaction | undefined) {
121
- this.#transaction = value
122
- }
123
-
124
- getTransaction(): Transaction {
125
- if (this.#transaction == null) {
126
- throw new Error(`Transaction is not set on instruction`)
127
- } else {
128
- return this.#transaction
129
- }
130
- }
131
-
132
- get inner(): Instruction[] {
133
- if (this.#inner == null) {
134
- this.#inner = []
135
- }
136
- return this.#inner
137
- }
138
-
139
- set inner(instructions: Instruction[]) {
140
- this.#inner = instructions
141
- }
142
-
143
- get parent(): Instruction | undefined {
144
- return this.#parent
145
- }
146
-
147
- set parent(value: Instruction | undefined) {
148
- this.#parent = value
149
- }
150
-
151
- get logs(): LogMessage[] {
152
- if (this.#logs == null) {
153
- this.#logs = []
154
- }
155
- return this.#logs
156
- }
157
-
158
- set logs(value: LogMessage[]) {
159
- this.#logs = value
160
- }
161
-
162
- get d1(): Bytes {
163
- return this.#d1 ?? (this.#d1 = this.d8.slice(0, 4))
164
- }
165
-
166
- get d2(): Bytes {
167
- return this.#d2 ?? (this.#d2 = this.d8.slice(0, 6))
168
- }
169
-
170
- get d4(): Bytes {
171
- return this.#d4 ?? (this.#d4 = this.d8.slice(0, 10))
172
- }
173
-
174
- get d8(): Bytes {
175
- if (this.#d8) {
176
- return this.#d8
177
- } else {
178
- if (this.data == null) {
179
- throw new Error(`.data field is not available`)
180
- }
181
- return (this.#d8 = getInstructionDescriptor(this as {data: Base58}))
182
- }
183
- }
184
- }
185
-
186
- export interface LogMessage extends base.LogMessage {}
187
- export class LogMessage {
188
- #block!: Block
189
- #transaction?: Transaction
190
- #instruction?: Instruction
191
-
192
- get block(): Block {
193
- return this.#block
194
- }
195
-
196
- set block(value: Block) {
197
- this.#block = value
198
- }
199
-
200
- get transaction(): Transaction | undefined {
201
- return this.#transaction
202
- }
203
-
204
- set transaction(value: Transaction | undefined) {
205
- this.#transaction = value
206
- }
207
-
208
- getTransaction(): Transaction {
209
- if (this.#transaction == null) {
210
- throw new Error(`Transaction is not set on log message`)
211
- } else {
212
- return this.#transaction
213
- }
214
- }
215
-
216
- get instruction(): Instruction | undefined {
217
- return this.#instruction
218
- }
219
-
220
- set instruction(value: Instruction | undefined) {
221
- this.#instruction = value
222
- }
223
-
224
- getInstruction(): Instruction {
225
- if (this.#instruction == null) {
226
- throw new Error(`Instruction is not set on log message`)
227
- } else {
228
- return this.#instruction
229
- }
230
- }
231
- }
232
-
233
- export interface Balance extends base.Balance {}
234
- export class Balance {
235
- #block!: Block
236
- #transaction?: Transaction
237
-
238
- get block(): Block {
239
- return this.#block
240
- }
241
-
242
- set block(value: Block) {
243
- this.#block = value
244
- }
245
-
246
- get transaction(): Transaction | undefined {
247
- return this.#transaction
248
- }
249
-
250
- set transaction(value: Transaction | undefined) {
251
- this.#transaction = value
252
- }
253
-
254
- getTransaction(): Transaction {
255
- if (this.#transaction == null) {
256
- throw new Error(`Transaction is not set on balance change record`)
257
- } else {
258
- return this.#transaction
259
- }
260
- }
261
- }
262
-
263
- type A = base.TokenBalance
264
-
265
- export interface TokenBalance extends base.TokenBalance {}
266
- export class TokenBalance {
267
- #block!: Block
268
- #transaction?: Transaction
269
-
270
- get block(): Block {
271
- return this.#block
272
- }
273
-
274
- set block(value: Block) {
275
- this.#block = value
276
- }
277
-
278
- get transaction(): Transaction | undefined {
279
- return this.#transaction
280
- }
281
-
282
- set transaction(value: Transaction | undefined) {
283
- this.#transaction = value
284
- }
285
-
286
- getTransaction(): Transaction {
287
- if (this.#transaction == null) {
288
- throw new Error(`Transaction is not set on balance change record`)
289
- } else {
290
- return this.#transaction
291
- }
292
- }
293
- }
294
-
295
- export interface Reward extends base.Reward {}
296
- export class Reward {}
@@ -1,90 +0,0 @@
1
- import {bisect, maybeLast} from '@subsquid/util-internal'
2
- import {Block, ReqiredFieldSelection, Transaction} from './types'
3
-
4
- export function setUpRelations(block: Block<ReqiredFieldSelection>): void {
5
- block.transactions.sort((a, b) => a.transactionIndex - b.transactionIndex)
6
- block.instructions.sort(instructionCompare)
7
- block.logs.sort((a, b) => a.transactionIndex - b.transactionIndex || a.logIndex - b.logIndex)
8
-
9
- let txs: (Transaction<ReqiredFieldSelection> | undefined)[] = new Array(
10
- (maybeLast(block.transactions)?.transactionIndex ?? -1) + 1
11
- )
12
- for (let tx of block.transactions) {
13
- txs[tx.transactionIndex] = tx
14
- }
15
-
16
- for (let i = 0; i < block.instructions.length; i++) {
17
- let ins = block.instructions[i]
18
- let tx = txs[ins.transactionIndex]
19
- if (tx) {
20
- ins.transaction = tx
21
- tx.instructions.push(ins)
22
- }
23
- for (let j = i + 1; j < block.instructions.length; j++) {
24
- let next = block.instructions[j]
25
- if (isInner(ins, next)) {
26
- ins.inner.push(next)
27
- if (ins.instructionAddress.length + 1 == next.instructionAddress.length) {
28
- next.parent = ins
29
- }
30
- } else {
31
- break
32
- }
33
- }
34
- }
35
-
36
- for (let log of block.logs) {
37
- log.transaction = txs[log.transactionIndex]
38
- for (let i = bisect(block.instructions, log, instructionCompare); i < block.instructions.length; i++) {
39
- let ins = block.instructions[i]
40
- if (isInner(ins, log)) {
41
- ins.logs.push(log)
42
- if (ins.instructionAddress.length == log.instructionAddress.length) {
43
- log.instruction = ins
44
- }
45
- }
46
- }
47
- }
48
-
49
- for (let balance of block.balances) {
50
- let transaction = txs[balance.transactionIndex]
51
- if (transaction) {
52
- balance.transaction = transaction
53
- transaction.balances.push(balance)
54
- }
55
- }
56
-
57
- for (let tokenBalance of block.tokenBalances) {
58
- let transaction = txs[tokenBalance.transactionIndex]
59
- if (transaction) {
60
- tokenBalance.transaction = transaction
61
- transaction.tokenBalances.push(tokenBalance)
62
- }
63
- }
64
- }
65
-
66
- interface InstructionAddress {
67
- transactionIndex: number
68
- instructionAddress: number[]
69
- }
70
-
71
- function isInner(parent: InstructionAddress, inner: InstructionAddress): boolean {
72
- if (parent.transactionIndex != inner.transactionIndex) return false
73
- if (parent.instructionAddress.length > inner.instructionAddress.length) return false
74
- for (let i = 0; i < parent.instructionAddress.length; i++) {
75
- if (parent.instructionAddress[i] != inner.instructionAddress[i]) return false
76
- }
77
- return true
78
- }
79
-
80
- function instructionCompare(a: InstructionAddress, b: InstructionAddress): number {
81
- return a.transactionIndex - b.transactionIndex || addressCompare(a.instructionAddress, b.instructionAddress)
82
- }
83
-
84
- function addressCompare(a: number[], b: number[]): number {
85
- for (let i = 0; i < Math.min(a.length, b.length); i++) {
86
- let order = a[i] - b[i]
87
- if (order) return order
88
- }
89
- return a.length - b.length
90
- }
@@ -1,88 +0,0 @@
1
- import type {Solana} from '@subsquid/portal-client'
2
- import type {Bytes, Simplify, Trues} from '@subsquid/util-internal'
3
-
4
- export type FieldSelection = Solana.FieldSelection
5
-
6
- export type BlockPartial<F extends FieldSelection = Trues<FieldSelection>> = Solana.BlockData<F>
7
-
8
- export type Block<F extends FieldSelection = Trues<FieldSelection>> = {
9
- header: BlockHeader<F>
10
- transactions: Transaction<F>[]
11
- instructions: Instruction<F>[]
12
- logs: LogMessage<F>[]
13
- balances: Balance<F>[]
14
- tokenBalances: TokenBalance<F>[]
15
- rewards: Reward<F>[]
16
- }
17
- export type BlockHeader<F extends FieldSelection = Trues<FieldSelection>> = Solana.BlockHeader<F['block'] & {}>
18
- export type Transaction<F extends FieldSelection = Trues<FieldSelection>> = Simplify<
19
- Solana.Transaction<F['transaction'] & {}> & {
20
- block: Block<F>
21
- instructions: Instruction<F>[]
22
- logs: LogMessage<F>[]
23
- balances: Balance<F>[]
24
- tokenBalances: TokenBalance<F>[]
25
- }
26
- >
27
- export type Instruction<F extends FieldSelection = Trues<FieldSelection>> = Simplify<
28
- Solana.Instruction<F['instruction'] & {}> &
29
- ((F['instruction'] & {})['data'] extends true ? {d1: Bytes; d2: Bytes; d4: Bytes; d8: Bytes} : {}) & {
30
- block: Block<F>
31
- transaction?: Transaction<F>
32
- parent?: Instruction<F>
33
- inner: Instruction<F>[]
34
- logs: LogMessage<F>[]
35
- }
36
- >
37
- export type LogMessage<F extends FieldSelection = Trues<FieldSelection>> = Simplify<
38
- Solana.LogMessage<F['log'] & {}> & {
39
- block: Block<F>
40
- transaction?: Transaction<F>
41
- instruction?: Instruction<F>
42
- }
43
- >
44
- export type Balance<F extends FieldSelection = Trues<FieldSelection>> = Simplify<
45
- Solana.Balance<F['balance'] & {}> & {
46
- block: Block<F>
47
- transaction?: Transaction<F>
48
- }
49
- >
50
- export type TokenBalance<F extends FieldSelection = Trues<FieldSelection>> = Simplify<
51
- Solana.TokenBalance<F['tokenBalance'] & {}> & {
52
- block: Block<F>
53
- transaction?: Transaction<F>
54
- }
55
- >
56
- export type Reward<F extends FieldSelection = Trues<FieldSelection>> = Solana.Reward<
57
- F['reward'] & {
58
- block: Block<F>
59
- }
60
- >
61
-
62
- export const REQUIRED_FIELDS = {
63
- block: {
64
- number: true,
65
- hash: true,
66
- parentHash: true,
67
- },
68
- transaction: {
69
- transactionIndex: true,
70
- },
71
- log: {
72
- transactionIndex: true,
73
- instructionAddress: true,
74
- logIndex: true,
75
- },
76
- instruction: {
77
- transactionIndex: true,
78
- instructionAddress: true,
79
- },
80
- balance: {
81
- transactionIndex: true,
82
- },
83
- tokenBalance: {
84
- transactionIndex: true,
85
- },
86
- } as const satisfies Solana.FieldSelection
87
-
88
- export type ReqiredFieldSelection = typeof REQUIRED_FIELDS
package/src/query.ts DELETED
@@ -1,149 +0,0 @@
1
- import type {Solana} from '@subsquid/portal-client'
2
- import {Bytes, mergeSelection, Simplify, Trues, type MergeSelection} from '@subsquid/util-internal'
3
- import {applyRangeBound, mergeRangeRequests, type Range, type RangeRequest} from '@subsquid/util-internal-range'
4
-
5
- // TODO: is it needed?
6
- export {
7
- DataRequest,
8
- TransactionRequest,
9
- InstructionRequest,
10
- LogRequest,
11
- BalanceRequest,
12
- TokenBalanceRequest,
13
- RewardRequest,
14
- } from '@subsquid/portal-client/lib/query/solana'
15
-
16
- export type RequestOptions<R> = {range?: Range; request: R}
17
- export type LogRequestOptions = RequestOptions<Solana.LogRequest>
18
- export type TransactionRequestOptions = RequestOptions<Solana.TransactionRequest>
19
- export type InstructionRequestOptions = RequestOptions<Solana.InstructionRequest>
20
- export type TokenBalanceRequestOptions = RequestOptions<Solana.TokenBalanceRequest>
21
- export type BalanceRequestOptions = RequestOptions<Solana.BalanceRequest>
22
- export type RewardRequestOptions = RequestOptions<Solana.RewardRequest>
23
-
24
- export type SolanaQueryOptions<F extends Solana.FieldSelection = Solana.FieldSelection> = {
25
- fields: F
26
- requests: RangeRequest<Solana.DataRequest>[]
27
- }
28
-
29
- export class SolanaQueryBuilder<F extends Solana.FieldSelection = {block: {number: true; hash: true}}> {
30
- private range: Range = {from: 0}
31
- private requests: RangeRequest<Solana.DataRequest>[] = []
32
- private fields: F = {
33
- block: {number: true, hash: true},
34
- } as F
35
-
36
- private addRequest(type: keyof Solana.DataRequest, options: RequestOptions<any>): this {
37
- this.requests.push({
38
- range: options.range ?? {from: 0},
39
- request: {
40
- [type]: [mapRequest(options)],
41
- },
42
- })
43
- return this
44
- }
45
-
46
- includeAllBlocks(range?: Range): this {
47
- this.requests.push({range: range ?? {from: 0}, request: {includeAllBlocks: true}})
48
- return this
49
- }
50
-
51
- addLog(options: LogRequestOptions): this {
52
- return this.addRequest('logs', options)
53
- }
54
-
55
- addTransaction(options: TransactionRequestOptions): this {
56
- return this.addRequest('transactions', options)
57
- }
58
-
59
- addReward(options: RewardRequestOptions): this {
60
- return this.addRequest('rewards', options)
61
- }
62
-
63
- addBalance(options: BalanceRequestOptions): this {
64
- return this.addRequest('balances', options)
65
- }
66
-
67
- addTokenBalance(options: TokenBalanceRequestOptions): this {
68
- return this.addRequest('tokenBalances', options)
69
- }
70
-
71
- addInstruction(options: InstructionRequestOptions): this {
72
- return this.addRequest('instructions', options)
73
- }
74
-
75
- setRange(range: Range): this {
76
- this.range = range
77
- return this
78
- }
79
-
80
- setFields<F extends Solana.FieldSelection>(fields: F): SolanaQueryBuilder<F> {
81
- this.fields = fields as any
82
- return this as any
83
- }
84
-
85
- build(): SolanaQueryOptions<F> {
86
- let requests = mergeRangeRequests(this.requests, mergeDataRequests)
87
- return {
88
- fields: this.fields,
89
- requests: applyRangeBound(requests, this.range),
90
- }
91
- }
92
- }
93
-
94
- export function mergeDataRequests(...requests: Solana.DataRequest[]): Solana.DataRequest {
95
- let res: Solana.DataRequest = {}
96
- for (let req of requests) {
97
- res.transactions = concatRequestLists(res.transactions, req.transactions)
98
- res.logs = concatRequestLists(res.logs, req.logs)
99
- res.balances = concatRequestLists(res.balances, req.balances)
100
- res.tokenBalances = concatRequestLists(res.tokenBalances, req.tokenBalances)
101
- res.rewards = concatRequestLists(res.rewards, req.rewards)
102
- res.instructions = concatRequestLists(res.instructions, req.instructions)
103
- if (res.includeAllBlocks || req.includeAllBlocks) {
104
- res.includeAllBlocks = true
105
- }
106
- }
107
- return res
108
- }
109
-
110
- export type MergeQueryOptions<T extends SolanaQueryOptions, U extends SolanaQueryOptions> = SolanaQueryOptions<
111
- MergeSelection<T['fields'], U['fields']>
112
- > extends infer R
113
- ? R
114
- : never
115
-
116
- export type MergeQueryOptionsAll<T extends readonly SolanaQueryOptions[]> = T extends readonly [infer F, ...infer R]
117
- ? F extends SolanaQueryOptions
118
- ? R extends [SolanaQueryOptions, ...SolanaQueryOptions[]]
119
- ? MergeQueryOptions<F, MergeQueryOptionsAll<R>>
120
- : F
121
- : never
122
- : never
123
-
124
- export function mergeRequests(...requests: RangeRequest<Solana.DataRequest>[]): RangeRequest<Solana.DataRequest>[] {
125
- return mergeRangeRequests(requests, mergeDataRequests)
126
- }
127
-
128
- export function mergeQueries<T extends SolanaQueryOptions, U extends SolanaQueryOptions>(
129
- a: T,
130
- b: U
131
- ): MergeQueryOptions<T, U>
132
- export function mergeQueries<T extends readonly SolanaQueryOptions[]>(...queries: T): MergeQueryOptionsAll<T>
133
- export function mergeQueries<T extends readonly SolanaQueryOptions[]>(...queries: T) {
134
- return {
135
- fields: mergeSelection(...queries.map((q) => q.fields)),
136
- requests: mergeRequests(...queries.flatMap((q) => q.requests)),
137
- }
138
- }
139
-
140
- function concatRequestLists<T extends object>(a?: T[], b?: T[]): T[] | undefined {
141
- let result = [...(a || []), ...(b || [])]
142
- return result.length ? result : undefined
143
- }
144
-
145
- function mapRequest<T>(options: RequestOptions<T>): T {
146
- return {...options.request}
147
- }
148
-
149
-