@thru/thru-sdk 0.1.16 → 0.1.19
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/README.md +77 -0
- package/dist/{chunk-FDZQR6ZZ.js → chunk-PH7P5EEU.js} +168 -65
- package/dist/chunk-PH7P5EEU.js.map +1 -0
- package/dist/client.d.ts +16 -3
- package/dist/client.js +19 -3
- package/dist/client.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk.d.ts +4 -3
- package/dist/sdk.js +1 -1
- package/dist/{transactions-X2KKrGw6.d.ts → transactions-BzD9hYlc.d.ts} +552 -88
- package/package.json +11 -4
- package/thru-ts-client-sdk/__tests__/helpers/test-utils.ts +228 -0
- package/thru-ts-client-sdk/core/__tests__/bound-client.test.ts +354 -0
- package/thru-ts-client-sdk/core/__tests__/client.test.ts +53 -0
- package/thru-ts-client-sdk/core/bound-client.ts +23 -2
- package/thru-ts-client-sdk/defaults.ts +10 -1
- package/thru-ts-client-sdk/modules/__tests__/accounts.test.ts +406 -0
- package/thru-ts-client-sdk/modules/__tests__/blocks.test.ts +199 -0
- package/thru-ts-client-sdk/modules/__tests__/events.test.ts +74 -0
- package/thru-ts-client-sdk/modules/__tests__/height.test.ts +39 -0
- package/thru-ts-client-sdk/modules/__tests__/helpers.test.ts +288 -0
- package/thru-ts-client-sdk/modules/__tests__/keys.test.ts +55 -0
- package/thru-ts-client-sdk/modules/__tests__/proofs.test.ts +119 -0
- package/thru-ts-client-sdk/modules/__tests__/streaming.test.ts +152 -0
- package/thru-ts-client-sdk/modules/__tests__/transactions.test.ts +730 -0
- package/thru-ts-client-sdk/modules/__tests__/version.test.ts +40 -0
- package/thru-ts-client-sdk/modules/accounts.ts +14 -18
- package/thru-ts-client-sdk/modules/streaming.ts +102 -3
- package/thru-ts-client-sdk/modules/transactions.ts +136 -36
- package/thru-ts-client-sdk/modules/version.ts +10 -0
- package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +2 -3
- package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +7 -8
- package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +58 -10
- package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +12 -13
- package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +27 -26
- package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +7 -8
- package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +4 -5
- package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +213 -12
- package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +2 -3
- package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +68 -3
- package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +84 -78
- package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +24 -25
- package/thru-ts-client-sdk/sdk.ts +5 -3
- package/thru-ts-client-sdk/test-scripts/counter.ts +353 -100
- package/thru-ts-client-sdk/transactions/Transaction.ts +10 -10
- package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +12 -7
- package/thru-ts-client-sdk/transactions/__tests__/TransactionBuilder.test.ts +411 -0
- package/thru-ts-client-sdk/transactions/__tests__/utils.test.ts +214 -0
- package/thru-ts-client-sdk/transactions/types.ts +14 -4
- package/vitest.config.ts +31 -0
- package/dist/chunk-FDZQR6ZZ.js.map +0 -1
- package/thru-ts-client-sdk/transactions/__tests__/transaction.test.ts +0 -95
package/README.md
CHANGED
|
@@ -36,6 +36,83 @@ const { rawTransaction, signature } = await thru.transactions.buildAndSign({
|
|
|
36
36
|
await thru.transactions.send(rawTransaction);
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
### Using Filters
|
|
40
|
+
|
|
41
|
+
Many SDK functions support CEL (Common Expression Language) filters to query or stream data based on custom expressions evaluated server-side. Filters are constructed using the `create` function from `@bufbuild/protobuf` (already a dependency of `@thru/thru-sdk`).
|
|
42
|
+
|
|
43
|
+
#### Constructing Filters
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { create } from "@bufbuild/protobuf";
|
|
47
|
+
import {
|
|
48
|
+
FilterSchema,
|
|
49
|
+
FilterParamValueSchema,
|
|
50
|
+
type Filter,
|
|
51
|
+
type FilterParamValue
|
|
52
|
+
} from "@thru/thru-sdk";
|
|
53
|
+
|
|
54
|
+
// Create a filter parameter value
|
|
55
|
+
const paramValue = create(FilterParamValueSchema, {
|
|
56
|
+
kind: {
|
|
57
|
+
case: "bytesValue", // or "stringValue", "boolValue", "intValue", "doubleValue"
|
|
58
|
+
value: new Uint8Array(32), // the actual value
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Create the filter with a CEL expression
|
|
63
|
+
const filter = create(FilterSchema, {
|
|
64
|
+
expression: "meta.owner.value == params.owner_bytes",
|
|
65
|
+
params: {
|
|
66
|
+
owner_bytes: paramValue,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Filter Parameter Value Types
|
|
72
|
+
|
|
73
|
+
Filter parameters support these types:
|
|
74
|
+
- `{ case: "stringValue", value: string }` - for string parameters
|
|
75
|
+
- `{ case: "bytesValue", value: Uint8Array }` - for byte array parameters
|
|
76
|
+
- `{ case: "boolValue", value: boolean }` - for boolean parameters
|
|
77
|
+
- `{ case: "intValue", value: bigint }` - for integer parameters
|
|
78
|
+
- `{ case: "doubleValue", value: number }` - for floating-point parameters
|
|
79
|
+
|
|
80
|
+
#### Functions That Accept Filters
|
|
81
|
+
|
|
82
|
+
**Query Functions:**
|
|
83
|
+
- `thru.accounts.list({ filter })` - List accounts with filtering
|
|
84
|
+
- `thru.blocks.list({ filter })` - List blocks with filtering
|
|
85
|
+
- `thru.transactions.listForAccount(account, { filter })` - List transactions for an account with filtering
|
|
86
|
+
|
|
87
|
+
**Streaming Functions:**
|
|
88
|
+
- `thru.streaming.streamBlocks({ filter })` - Stream blocks with filtering
|
|
89
|
+
- `thru.streaming.streamAccountUpdates(address, { filter })` - Stream account updates with filtering
|
|
90
|
+
- `thru.streaming.streamTransactions({ filter })` - Stream transactions with filtering
|
|
91
|
+
- `thru.streaming.streamEvents({ filter })` - Stream events with filtering
|
|
92
|
+
|
|
93
|
+
#### Example: Filtering Accounts by Owner
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// List accounts owned by a specific public key
|
|
97
|
+
const ownerBytes = new Uint8Array(32); // your owner pubkey bytes
|
|
98
|
+
|
|
99
|
+
const ownerParam = create(FilterParamValueSchema, {
|
|
100
|
+
kind: {
|
|
101
|
+
case: "bytesValue",
|
|
102
|
+
value: ownerBytes,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const filter = create(FilterSchema, {
|
|
107
|
+
expression: "meta.owner.value == params.owner_bytes",
|
|
108
|
+
params: {
|
|
109
|
+
owner_bytes: ownerParam,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const response = await thru.accounts.list({ filter });
|
|
114
|
+
```
|
|
115
|
+
|
|
39
116
|
### Modules at a Glance
|
|
40
117
|
|
|
41
118
|
- `thru.blocks` — query finalized or raw blocks and stream height information
|