@effectstream/utils 0.100.14 → 0.100.15

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,107 @@
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
+ ## Install
14
+
15
+ ```bash
16
+ bun add @effectstream/utils
17
+ # or
18
+ npm install @effectstream/utils
19
+ ```
20
+
21
+ ## Standalone usage
22
+
23
+ The most useful exports for external consumers are the chain-aware
24
+ `AddressType` enum and the per-chain `TypeBox` schemas under
25
+ `TypeboxHelpers`. You can validate "which chain is this address from?"
26
+ across EVM, Cardano, Substrate, Algorand, Mina, Midnight, Avail,
27
+ Polkadot, and NEAR without depending on a runtime.
28
+
29
+ ```typescript
30
+ import { AddressType, AddressValidator } from "@effectstream/utils";
31
+ import { Value } from "@sinclair/typebox/value";
32
+
33
+ const addr = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd";
34
+ const isEvm = Value.Check(AddressValidator[AddressType.EVM], addr);
35
+ ```
36
+
37
+ ```typescript
38
+ import { TypeboxHelpers } from "@effectstream/utils";
39
+ import { Value } from "@sinclair/typebox/value";
40
+
41
+ // Compose your own schemas from chain-specific primitives.
42
+ Value.Check(TypeboxHelpers.Evm.Address, "0xab...");
43
+ Value.Check(TypeboxHelpers.Cardano.PolicyId, "abcd...");
44
+ ```
45
+
46
+ ## Inside EffectStream
47
+
48
+ A workhorse. `AddressType` is the most-imported symbol from this
49
+ package (~170 cross-package references); `TypeboxHelpers` and
50
+ `AddressAndType` are runners-up. Almost every chain integration, the
51
+ state machine, and the batcher pulls something from here.
52
+
53
+ ## Key exports
54
+
55
+ Address types and validators:
56
+
57
+ - `AddressType` — enum of chain identifiers (EVM, CARDANO, SUBSTRATE, ALGORAND, MINA, MIDNIGHT, AVAIL, POLKADOT, NEAR).
58
+ - `AddressValidator` — `Record<AddressType, TSchema>` of TypeBox validators, one per chain.
59
+ - `AddressAndType` — tagged-union shape for `{ type, address }` pairs.
60
+
61
+ TypeBox schemas:
62
+
63
+ - `TypeboxHelpers.{Evm,Cardano,Substrate,Algorand,Mina,Midnight,Avail,Polkadot,Near}` — `.Address`, `.BlockHash`, `.TxHash`, `.Signature`, `.PrivateKey`, plus chain-specific extras (`PolicyId`, `AssetName`, `Selector`, …).
64
+ - Plain primitives: `TypeboxHelpers.Uint256`, `BlockNumber`, `AbsoluteSlotNumber`, `EpochNumber`.
65
+
66
+ Type aliases (heavily imported as nominal types):
67
+
68
+ - `WalletAddress`, `EvmAddress`, `Signature`, `EvmPrivateKey`, `BlockHash`, `BlockNumber`, `EffectstreamBlockHash`, `EffectstreamBlockNumber`, `TimestampMs`, `Caip2`, `HexString0x`, `HexStringNo0x`.
69
+
70
+ Type-level utilities (`./types/misc.ts`):
71
+
72
+ - `MergeIntersects<T>`, `ShallowMergeIntersects<T>`, `RemoveUnknown<T>`, `Satisfies<Base, T>`, `Mutable<T>`, `DeepMutable<T>`, `DeepReadonly<T>`, `UnionToIntersection<U>`, `TypeErrorMessage`, `ValueOf<T>`, `ElementOf<T>`.
73
+
74
+ Result + binary helpers:
75
+
76
+ - `Result<T>`, `narrowResult`, success/failure constructors.
77
+ - `hexStringToUint8Array`, `uint8ArrayToHexString`.
78
+
79
+ Decorators:
80
+
81
+ - `bound` — method-binding decorator (heavily used in classes that pass methods around).
82
+
83
+ Viem helpers:
84
+
85
+ - `createViemPublicClient(...)`, `truncateSelector(...)`.
86
+
87
+ Concurrency (Effection-based):
88
+
89
+ - `conditionVariable<T>()`, `tryYield(...)`, `retry(...)`.
90
+
91
+ Subpath entries:
92
+
93
+ - `@effectstream/utils/node-env` — `dotenv`-aware env loader, for Node-only callers.
94
+ - `@effectstream/utils/runtime` — Effection runtime helpers.
95
+ - `@effectstream/utils/runtime-spawn` — child-process spawn helpers built on Effection.
96
+
97
+ ## Examples
98
+
99
+ Runnable: [`src/binary-search.test.ts`](./src/binary-search.test.ts),
100
+ [`src/concurrency/latch.test.ts`](./src/concurrency/latch.test.ts),
101
+ [`src/concurrency/retry.test.ts`](./src/concurrency/retry.test.ts), and
102
+ [`test/examples.test.ts`](./test/examples.test.ts).
103
+
104
+ ## Links
105
+
106
+ - Docs: https://effectstream.github.io/docs/packages/sdk/utils
107
+ - Source: https://github.com/PaimaStudios/paima-engine/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.15",
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
+ });