@thru/thru-sdk 0.1.28 → 0.1.30

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 CHANGED
@@ -67,6 +67,29 @@ for await (const update of thru.streaming.trackTransaction(signature)) {
67
67
  }
68
68
  ```
69
69
 
70
+ ## Client Configuration
71
+
72
+ `createThruClient` accepts advanced transport options so you can customize networking, interceptors, and default call behaviour:
73
+
74
+ ```ts
75
+ const thru = createThruClient({
76
+ baseUrl: "https://grpc-web.alphanet.thruput.org",
77
+ transportOptions: {
78
+ useBinaryFormat: false,
79
+ defaultTimeoutMs: 10_000,
80
+ },
81
+ interceptors: [authInterceptor],
82
+ callOptions: {
83
+ timeoutMs: 5_000,
84
+ headers: [["x-team", "sdk"]],
85
+ },
86
+ });
87
+ ```
88
+
89
+ - `transportOptions` are passed to `createGrpcWebTransport`. Provide custom fetch implementations, JSON/binary options, or merge additional interceptors.
90
+ - `interceptors` let you append cross-cutting logic (auth, metrics) without re-implementing transports.
91
+ - `callOptions` act as defaults for **every** RPC. You can set timeouts, headers, or a shared `AbortSignal`, and each module call merges in per-request overrides.
92
+
70
93
  ## Domain Models
71
94
 
72
95
  The SDK revolves around immutable domain classes. They copy mutable buffers, expose clear invariants, and provide conversion helpers where needed.
@@ -87,6 +110,33 @@ All classes are exported from the root package for easy access:
87
110
  import { Block, Account, ChainEvent } from "@thru/thru-sdk";
88
111
  ```
89
112
 
113
+ ### Primitives
114
+
115
+ `Pubkey` and `Signature` wrap the 32-byte Ed25519 public key and 64-byte signature primitives, respectively. They centralize validation, conversion, and proto interop so you can work with either Thru-formatted strings (`ta...` / `ts...`), hex, or raw bytes without sprinkling helpers throughout your app.
116
+
117
+ ```ts
118
+ import { Pubkey, Signature } from "@thru/thru-sdk";
119
+
120
+ const payer = Pubkey.from("taDs2..."); // accepts ta string, hex, or Uint8Array
121
+ const sig = Signature.from("ts8Lk..."); // accepts ts string, hex, or Uint8Array
122
+
123
+ payer.toBytes(); // defensive copy
124
+ payer.toThruFmt(); // "ta..." string
125
+ payer.toProtoPubkey(); // thru.common.v1.Pubkey
126
+ payer.toProtoTaPubkey(); // thru.common.v1.TaPubkey
127
+
128
+ sig.toBytes();
129
+ sig.toThruFmt(); // "ts..." string
130
+ sig.toProtoSignature(); // thru.common.v1.Signature
131
+ sig.toProtoTsSignature(); // thru.common.v1.TsSignature
132
+
133
+ // Helper namespace now returns these domain objects:
134
+ const parsed = sdk.helpers.createPubkey("taFeePayerAddress...");
135
+ const signature = sdk.helpers.createSignature(sigBytes);
136
+ ```
137
+
138
+ The bound client accepts either raw bytes or the new primitives; call `.toBytes()` on `Pubkey`/`Signature` when you need to interop with legacy code.
139
+
90
140
  ## View Options
91
141
 
92
142
  When fetching resources, you can control which parts of the resource are returned using view options. This allows you to optimize network usage by only fetching the data you need.
@@ -231,23 +281,17 @@ for await (const update of thru.streaming.trackTransaction(signature)) {
231
281
  Server-side filtering is supported everywhere via CEL expressions:
232
282
 
233
283
  ```ts
234
- import { create } from "@bufbuild/protobuf";
235
- import {
236
- FilterSchema,
237
- FilterParamValueSchema,
238
- } from "@thru/thru-sdk";
284
+ import { Filter, FilterParamValue } from "@thru/thru-sdk";
239
285
 
240
- const ownerBytes = new Uint8Array(32);
241
- const ownerParam = create(FilterParamValueSchema, {
242
- kind: { case: "bytesValue", value: ownerBytes },
243
- });
244
-
245
- const filter = create(FilterSchema, {
246
- expression: "meta.owner.value == params.owner_bytes",
247
- params: { owner_bytes: ownerParam },
286
+ const ownerFilter = new Filter({
287
+ expression: "account.meta.owner.value == params.owner",
288
+ params: {
289
+ owner: FilterParamValue.pubkey("taExampleAddress..."),
290
+ min_balance: FilterParamValue.uint(1_000_000n),
291
+ },
248
292
  });
249
293
 
250
- const accounts = await thru.accounts.list({ filter });
294
+ const accounts = await thru.accounts.list({ filter: ownerFilter });
251
295
  ```
252
296
 
253
297
  Accepted parameter kinds:
@@ -256,11 +300,18 @@ Accepted parameter kinds:
256
300
  - `boolValue`
257
301
  - `intValue`
258
302
  - `doubleValue`
303
+ - `uintValue`
304
+ - `pubkeyValue`
305
+ - `signatureValue`
306
+ - `taPubkeyValue`
307
+ - `tsSignatureValue`
259
308
 
260
309
  Functions that take filters:
261
310
  - List APIs: `thru.accounts.list`, `thru.blocks.list`, `thru.transactions.listForAccount`
262
311
  - Streams: `thru.streaming.streamBlocks`, `thru.streaming.streamAccountUpdates`, `thru.streaming.streamTransactions`, `thru.streaming.streamEvents`
263
312
 
313
+ Use the helper constructors on `FilterParamValue` to safely build parameters from raw bytes, ta/ts-encoded strings, or simple numbers.
314
+
264
315
  ## Modules Overview
265
316
 
266
317
  - `thru.blocks` — fetch/stream blocks and height snapshots
@@ -268,7 +319,24 @@ Functions that take filters:
268
319
  - `thru.transactions` — build, sign, submit, track, and inspect transactions
269
320
  - `thru.events` — query event history
270
321
  - `thru.proofs` — generate state proofs
322
+ - `thru.consensus` — build version contexts and stringify consensus states
271
323
  - `thru.streaming` — streaming wrappers for blocks, accounts, transactions, events
272
324
  - `thru.helpers` — address, signature, and block-hash conversion helpers
273
325
 
274
326
  The public surface is fully domain-based; reaching for lower-level protobuf structures is no longer necessary.
327
+
328
+ ## Streaming helpers
329
+
330
+ Async iterable utilities make it easier to consume streaming APIs:
331
+
332
+ ```ts
333
+ import { collectStream, firstStreamValue } from "@thru/thru-sdk";
334
+
335
+ const updates = await collectStream(thru.streaming.streamBlocks({ startSlot: height.finalized }), {
336
+ limit: 5,
337
+ });
338
+
339
+ const firstEvent = await firstStreamValue(thru.streaming.streamEvents());
340
+ ```
341
+
342
+ `collectStream` gathers values (optionally respecting `AbortSignal`s), `firstStreamValue` returns the first item, and `forEachStreamValue` lets you run async handlers for each streamed update.