@effectstream/utils 0.100.14 → 0.100.16

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 ADDED
@@ -0,0 +1,112 @@
1
+ # @effectstream/utils
2
+
3
+ Shared utilities for the EffectStream framework — chain-aware address
4
+ types and validators, TypeBox schemas, Effection-based concurrency
5
+ primitives, viem helpers, and small type-level utilities. No runtime
6
+ dependency on the rest of EffectStream; safe to use standalone in any
7
+ TypeScript project.
8
+
9
+ This is the bottom-of-stack package: `@effectstream/crypto`,
10
+ `@effectstream/concise`, `@effectstream/wallets`, and most node packages
11
+ depend on it.
12
+
13
+ - Shared chain-aware types, TypeBox schemas, viem helpers, Effection primitives.
14
+ - Bottom-of-stack: `crypto`, `concise`, `wallets`, and most node packages depend on it.
15
+ - Safe to use standalone, no runtime dependency on the rest of Effectstream.
16
+ - `AddressType` is the most-imported symbol from the package (~170 cross-package references).
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ bun add @effectstream/utils
22
+ # or
23
+ npm install @effectstream/utils
24
+ ```
25
+
26
+ ## Standalone usage
27
+
28
+ The most useful exports for external consumers are the chain-aware
29
+ `AddressType` enum and the per-chain `TypeBox` schemas under
30
+ `TypeboxHelpers`. You can validate "which chain is this address from?"
31
+ across EVM, Cardano, Substrate, Algorand, Mina, Midnight, Avail,
32
+ Polkadot, and NEAR without depending on a runtime.
33
+
34
+ ```typescript
35
+ import { AddressType, AddressValidator } from "@effectstream/utils";
36
+ import { Value } from "@sinclair/typebox/value";
37
+
38
+ const addr = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd";
39
+ const isEvm = Value.Check(AddressValidator[AddressType.EVM], addr);
40
+ ```
41
+
42
+ ```typescript
43
+ import { TypeboxHelpers } from "@effectstream/utils";
44
+ import { Value } from "@sinclair/typebox/value";
45
+
46
+ // Compose your own schemas from chain-specific primitives.
47
+ Value.Check(TypeboxHelpers.Evm.Address, "0xab...");
48
+ Value.Check(TypeboxHelpers.Cardano.PolicyId, "abcd...");
49
+ ```
50
+
51
+ ## Inside EffectStream
52
+
53
+ A workhorse. `AddressType` is the most-imported symbol from this
54
+ package (~170 cross-package references); `TypeboxHelpers` and
55
+ `AddressAndType` are runners-up. Almost every chain integration, the
56
+ state machine, and the batcher pulls something from here.
57
+
58
+ ## Key exports
59
+
60
+ Address types and validators:
61
+
62
+ - `AddressType` — enum of chain identifiers (EVM, CARDANO, SUBSTRATE, ALGORAND, MINA, MIDNIGHT, AVAIL, POLKADOT, NEAR).
63
+ - `AddressValidator` — `Record<AddressType, TSchema>` of TypeBox validators, one per chain.
64
+ - `AddressAndType` — tagged-union shape for `{ type, address }` pairs.
65
+
66
+ TypeBox schemas:
67
+
68
+ - `TypeboxHelpers.{Evm,Cardano,Substrate,Algorand,Mina,Midnight,Avail,Polkadot,Near}` — `.Address`, `.BlockHash`, `.TxHash`, `.Signature`, `.PrivateKey`, plus chain-specific extras (`PolicyId`, `AssetName`, `Selector`, …).
69
+ - Plain primitives: `TypeboxHelpers.Uint256`, `BlockNumber`, `AbsoluteSlotNumber`, `EpochNumber`.
70
+
71
+ Type aliases (heavily imported as nominal types):
72
+
73
+ - `WalletAddress`, `EvmAddress`, `Signature`, `EvmPrivateKey`, `BlockHash`, `BlockNumber`, `EffectstreamBlockHash`, `EffectstreamBlockNumber`, `TimestampMs`, `Caip2`, `HexString0x`, `HexStringNo0x`.
74
+
75
+ Type-level utilities (`./types/misc.ts`):
76
+
77
+ - `MergeIntersects<T>`, `ShallowMergeIntersects<T>`, `RemoveUnknown<T>`, `Satisfies<Base, T>`, `Mutable<T>`, `DeepMutable<T>`, `DeepReadonly<T>`, `UnionToIntersection<U>`, `TypeErrorMessage`, `ValueOf<T>`, `ElementOf<T>`.
78
+
79
+ Result + binary helpers:
80
+
81
+ - `Result<T>`, `narrowResult`, success/failure constructors.
82
+ - `hexStringToUint8Array`, `uint8ArrayToHexString`.
83
+
84
+ Decorators:
85
+
86
+ - `bound` — method-binding decorator (heavily used in classes that pass methods around).
87
+
88
+ Viem helpers:
89
+
90
+ - `createViemPublicClient(...)`, `truncateSelector(...)`.
91
+
92
+ Concurrency (Effection-based):
93
+
94
+ - `conditionVariable<T>()`, `tryYield(...)`, `retry(...)`.
95
+
96
+ Subpath entries:
97
+
98
+ - `@effectstream/utils/node-env` — `dotenv`-aware env loader, for Node-only callers.
99
+ - `@effectstream/utils/runtime` — Effection runtime helpers.
100
+ - `@effectstream/utils/runtime-spawn` — child-process spawn helpers built on Effection.
101
+
102
+ ## Examples
103
+
104
+ Runnable: [`src/binary-search.test.ts`](./src/binary-search.test.ts),
105
+ [`src/concurrency/latch.test.ts`](./src/concurrency/latch.test.ts),
106
+ [`src/concurrency/retry.test.ts`](./src/concurrency/retry.test.ts), and
107
+ [`test/examples.test.ts`](./test/examples.test.ts).
108
+
109
+ ## Links
110
+
111
+ - Docs: https://effectstream.github.io/docs/packages/sdk/utils
112
+ - Source: https://github.com/effectstream/effectstream/tree/main/packages/effectstream-sdk/utils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/utils",
3
- "version": "0.100.14",
3
+ "version": "0.100.16",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -0,0 +1,33 @@
1
+ // Examples copied verbatim from README.md. If you change one, change both.
2
+
3
+ import { test, expect } from "bun:test";
4
+ import { Value } from "@sinclair/typebox/value";
5
+ import {
6
+ AddressType,
7
+ AddressValidator,
8
+ binarySearch,
9
+ TypeboxHelpers,
10
+ } from "../src/mod.ts";
11
+
12
+ test("README: validate an EVM address with AddressValidator", () => {
13
+ const addr = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd";
14
+ const isEvm = Value.Check(AddressValidator[AddressType.EVM], addr);
15
+ expect(isEvm).toBe(true);
16
+ });
17
+
18
+ test("README: an EVM address is rejected by the Cardano validator", () => {
19
+ const addr = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd";
20
+ const isCardano = Value.Check(AddressValidator[AddressType.CARDANO], addr);
21
+ expect(isCardano).toBe(false);
22
+ });
23
+
24
+ test("README: TypeboxHelpers.Evm.Address matches the same schema", () => {
25
+ const addr = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd";
26
+ expect(Value.Check(TypeboxHelpers.Evm.Address, addr)).toBe(true);
27
+ });
28
+
29
+ test("README: binarySearch finds the left-most index >= target", () => {
30
+ const arr = [1, 3, 5, 7, 9];
31
+ expect(binarySearch(arr, 5, (v) => v)).toBe(2);
32
+ expect(binarySearch(arr, 6, (v) => v)).toBe(3);
33
+ });