@usearete/sdk 0.2.0 → 0.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.
Files changed (39) hide show
  1. package/README.md +118 -0
  2. package/dist/index.cjs +7393 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +802 -129
  5. package/dist/index.esm.js +3447 -526
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/ssr/handlers.cjs +794 -0
  8. package/dist/ssr/handlers.cjs.map +1 -0
  9. package/dist/ssr/handlers.esm.js +523 -4
  10. package/dist/ssr/handlers.esm.js.map +1 -1
  11. package/dist/ssr/index.cjs +795 -0
  12. package/dist/ssr/index.cjs.map +1 -0
  13. package/dist/ssr/index.esm.js +523 -4
  14. package/dist/ssr/index.esm.js.map +1 -1
  15. package/dist/ssr/nextjs-app.cjs +859 -0
  16. package/dist/ssr/nextjs-app.cjs.map +1 -0
  17. package/dist/ssr/nextjs-app.esm.js +523 -4
  18. package/dist/ssr/nextjs-app.esm.js.map +1 -1
  19. package/dist/ssr/tanstack-start.cjs +881 -0
  20. package/dist/ssr/tanstack-start.cjs.map +1 -0
  21. package/dist/ssr/tanstack-start.esm.js +523 -4
  22. package/dist/ssr/tanstack-start.esm.js.map +1 -1
  23. package/dist/ssr/vite.cjs +887 -0
  24. package/dist/ssr/vite.cjs.map +1 -0
  25. package/dist/ssr/vite.esm.js +523 -4
  26. package/dist/ssr/vite.esm.js.map +1 -1
  27. package/package.json +10 -8
  28. package/dist/index.js +0 -4448
  29. package/dist/index.js.map +0 -1
  30. package/dist/ssr/handlers.js +0 -294
  31. package/dist/ssr/handlers.js.map +0 -1
  32. package/dist/ssr/index.js +0 -295
  33. package/dist/ssr/index.js.map +0 -1
  34. package/dist/ssr/nextjs-app.js +0 -359
  35. package/dist/ssr/nextjs-app.js.map +0 -1
  36. package/dist/ssr/tanstack-start.js +0 -381
  37. package/dist/ssr/tanstack-start.js.map +0 -1
  38. package/dist/ssr/vite.js +0 -387
  39. package/dist/ssr/vite.js.map +0 -1
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Pure TypeScript SDK for generated stack definitions, program SDKs, prepared operation execution, and chain reads.
4
4
 
5
+ Connected clients expose the typed six-route transaction relay as `client.transactions`. Wallet adapters receive it per invocation from `client.transaction` and `client.inspectOperation`, so a shared wallet can safely serve multiple clients. Sessions expose `session.transactions` and accept a `transactions` override. HTTP `u64` fields are decimal strings on the wire and `bigint` in the SDK; sends are never automatically retried.
6
+
5
7
  ## Installation
6
8
 
7
9
  ```bash
@@ -81,6 +83,64 @@ Each packaged, attached, or standalone program is canonically available under `s
81
83
  - `defaults` - reusable program defaults
82
84
  - `math` - pure protocol calculations
83
85
 
86
+ ### Program Read Transports
87
+
88
+ Generated account readers use a `ProgramReadDescriptor` for each program. Local
89
+ generation emits an explicit `local-http` descriptor, so the endpoint must come
90
+ from the connection call:
91
+
92
+ ```ts
93
+ const client = await Arete.connect(LOCAL_STACK, {
94
+ url: 'ws://localhost:8877',
95
+ httpUrl: 'http://localhost:8877',
96
+ });
97
+ ```
98
+
99
+ Installed hosted SDKs instead contain a complete `hosted-binding` descriptor:
100
+ the release, read endpoint, binding ID, and auth metadata are pinned together.
101
+ Hosted account reads ignore `httpUrl` and stack HTTP endpoints. A
102
+ `programReads` runtime override must replace that complete descriptor; release,
103
+ binding, and endpoint fields are never patched independently.
104
+
105
+ Stack and program queries remain stack-HTTP operations. They continue to use
106
+ `httpUrl` or `stack.endpoints.http` and do not use a hosted Program Read binding.
107
+ Composition sessions accept only complete hosted descriptors or complete hosted
108
+ overrides, and never infer Program Read endpoints from their members.
109
+
110
+ ### Hosted Solana Gateway Transports
111
+
112
+ Hosted composition installs also emit complete, independent `chain` and
113
+ `transactions` gateway bindings. Construct both authenticated transports from
114
+ those generated descriptors instead of using a LiveSpec query endpoint:
115
+
116
+ ```ts
117
+ import { createHostedSolanaGatewayTransports } from '@usearete/sdk';
118
+ import { MY_STACK_HOSTED_BINDINGS } from './generated/my-stack';
119
+
120
+ const { chain, transactions } = createHostedSolanaGatewayTransports(
121
+ {
122
+ chain: MY_STACK_HOSTED_BINDINGS.chain,
123
+ transactions: MY_STACK_HOSTED_BINDINGS.transactions,
124
+ },
125
+ {
126
+ auth: { publishableKey: import.meta.env.VITE_ARETE_PUBLISHABLE_KEY },
127
+ }
128
+ );
129
+ ```
130
+
131
+ The helper mints tokens for the exact `solana-gateway-binding` target. `read`,
132
+ `transaction:inspect`, and `transaction:send` use separate scope caches. An
133
+ authentication failure is refreshed at most once, and transaction requests are
134
+ replayed only when the gateway explicitly reports that upstream dispatch did
135
+ not begin. Chain and transaction descriptors may intentionally share the same
136
+ endpoint and binding ID.
137
+
138
+ Generated hosted compositions additionally export
139
+ `create<StackName>HostedSession(options)`. It constructs these transports and
140
+ passes them to the explicit composition session; the lower-level
141
+ `create<StackName>Session(options)` continues to require caller-supplied `chain`
142
+ and `transactions` transports.
143
+
84
144
  ### Raw Instructions
85
145
 
86
146
  Use raw handlers when you want exact wire control and will compose the transaction yourself:
@@ -307,20 +367,78 @@ for await (const update of session.stacks.myStack.views.settlementGame.list.watc
307
367
  const game = await session.stacks.myStack.views.settlementGame.state.get('game-123');
308
368
  ```
309
369
 
370
+ Every options object is a protocol v2 query with independent ordered membership. Different windows and filters on the same view can run concurrently, while equivalent normalized queries share one reference-counted wire subscription:
371
+
372
+ ```ts
373
+ const rounds = session.stacks.ore.views.OreRound.latest;
374
+
375
+ const firstPage = rounds.watch({ take: 10 });
376
+ const secondPage = rounds.watch({ take: 10, skip: 10 });
377
+
378
+ for await (const update of firstPage) {
379
+ if (update.type === 'remove') {
380
+ console.log(`${update.key} left the first-page window`);
381
+ }
382
+ }
383
+ ```
384
+
385
+ Completed authoritative snapshots replace membership for their exact query after reconnect. Cursor queries created with `after` receive incremental snapshots and merge without pruning.
386
+
387
+ Low-level `QueryLease.refresh()` returns a `Promise<void>` that resolves after the refreshed subscription's next complete snapshot is committed. Registration, send, and subscription failures reject and are published on the lease's `QuerySnapshot.error`, with `isRefreshing` cleared. Subscriptions created with snapshots disabled resolve after the refresh request is sent.
388
+
389
+ ### Connection recovery
390
+
391
+ `autoConnect` and `autoReconnect` default to `true` and control separate lifecycle phases. Set `autoConnect: false` to create a disconnected client that the application connects later. Set `autoReconnect: false` when the application wants to handle post-disconnect recovery itself:
392
+
393
+ ```ts
394
+ const client = await Arete.connect(MY_STACK, {
395
+ autoConnect: false,
396
+ autoReconnect: false,
397
+ });
398
+ ```
399
+
400
+ The same independent options are available per stack member in `createSession(...)` and on React's `AreteProvider`.
401
+
402
+ ### Caller-supplied schema diagnostics
403
+
404
+ Core view schemas continue to filter rejected entities. React view hooks additionally accept `onSchemaValidationError`, which reports `{ view, key?, entity, error }` without changing accepted data.
405
+
406
+ ## Safe amount parsing
407
+
408
+ `toRawAmount(input, decimals)` throws when user input is invalid. Form and API boundaries can use `safeToRawAmount(input, decimals)` instead:
409
+
410
+ ```ts
411
+ import { safeToRawAmount } from '@usearete/sdk';
412
+
413
+ const result = safeToRawAmount({ ui: amountText }, 9);
414
+ if (!result.success) {
415
+ console.error(result.error);
416
+ return;
417
+ }
418
+
419
+ console.log(result.data); // bigint in raw base units
420
+ ```
421
+
422
+ It returns `{ success: true, data } | { success: false, error }` and never throws for an invalid amount input.
423
+
310
424
  ## Update Types
311
425
 
312
426
  ```ts
313
427
  type Update<T> =
314
428
  | { type: 'upsert'; key: string; data: T }
315
429
  | { type: 'patch'; key: string; data: Partial<T> }
430
+ | { type: 'remove'; key: string }
316
431
  | { type: 'delete'; key: string };
317
432
 
318
433
  type RichUpdate<T> =
319
434
  | { type: 'created'; key: string; data: T }
320
435
  | { type: 'updated'; key: string; before: T; after: T; patch?: unknown }
436
+ | { type: 'removed'; key: string; lastKnown?: T }
321
437
  | { type: 'deleted'; key: string; lastKnown?: T };
322
438
  ```
323
439
 
440
+ `remove` means an entity left only this query's filter or window. `delete` means the source entity was deleted and is removed from every query for that view.
441
+
324
442
  ## License
325
443
 
326
444
  MIT