@latticexyz/recs 2.0.0-main-788de8de → 2.0.0-next.1

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 (2) hide show
  1. package/CHANGELOG.md +0 -207
  2. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,212 +1,5 @@
1
1
  # Change Log
2
2
 
3
- ## 2.0.0-main-788de8de
4
-
5
- ### Patch Changes
6
-
7
- - [#1167](https://github.com/latticexyz/mud/pull/1167) [`1e2ad78e`](https://github.com/latticexyz/mud/commit/1e2ad78e277b551dd1b8efb0e4438fb10441644c) Thanks [@holic](https://github.com/holic)! - improve RECS error messages for v2 components
8
-
9
- - [#1214](https://github.com/latticexyz/mud/pull/1214) [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9) Thanks [@holic](https://github.com/holic)! - Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout.
10
-
11
- These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys.
12
-
13
- If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`.
14
-
15
- **Migrate existing RECS apps to new sync packages**
16
-
17
- As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything.
18
-
19
- 1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors)
20
-
21
- 2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain.
22
-
23
- ```diff
24
- - import { foundry } from "viem/chains";
25
- - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains";
26
- + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains";
27
-
28
- - export const supportedChains: MUDChain[] = [foundry, latticeTestnet];
29
- + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet];
30
- ```
31
-
32
- 3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object.
33
-
34
- ```diff
35
- - export async function getNetworkConfig(): Promise<NetworkConfig> {
36
- + export async function getNetworkConfig() {
37
- ```
38
-
39
- ```diff
40
- const initialBlockNumber = params.has("initialBlockNumber")
41
- ? Number(params.get("initialBlockNumber"))
42
- - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC
43
- + : world?.blockNumber ?? 0n;
44
- ```
45
-
46
- ```diff
47
- + return {
48
- + privateKey: getBurnerWallet().value,
49
- + chain,
50
- + worldAddress,
51
- + initialBlockNumber,
52
- + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
53
- + };
54
- ```
55
-
56
- 4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`.
57
-
58
- ```diff
59
- - import { setupMUDV2Network } from "@latticexyz/std-client";
60
- - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network";
61
- + import { createFaucetService } from "@latticexyz/network";
62
- + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem";
63
- + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
64
- + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
65
- ```
66
-
67
- ```diff
68
- - const result = await setupMUDV2Network({
69
- - ...
70
- - });
71
-
72
- + const clientOptions = {
73
- + chain: networkConfig.chain,
74
- + transport: transportObserver(fallback([webSocket(), http()])),
75
- + pollingInterval: 1000,
76
- + } as const satisfies ClientConfig;
77
-
78
- + const publicClient = createPublicClient(clientOptions);
79
-
80
- + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
81
- + const burnerWalletClient = createWalletClient({
82
- + ...clientOptions,
83
- + account: burnerAccount,
84
- + });
85
-
86
- + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({
87
- + world,
88
- + config: storeConfig,
89
- + address: networkConfig.worldAddress as Hex,
90
- + publicClient,
91
- + components: contractComponents,
92
- + startBlock: BigInt(networkConfig.initialBlockNumber),
93
- + indexerUrl: networkConfig.indexerUrl ?? undefined,
94
- + });
95
-
96
- + const worldContract = createContract({
97
- + address: networkConfig.worldAddress as Hex,
98
- + abi: IWorld__factory.abi,
99
- + publicClient,
100
- + walletClient: burnerWalletClient,
101
- + });
102
- ```
103
-
104
- ```diff
105
- // Request drip from faucet
106
- - const signer = result.network.signer.get();
107
- - if (networkConfig.faucetServiceUrl && signer) {
108
- - const address = await signer.getAddress();
109
- + if (networkConfig.faucetServiceUrl) {
110
- + const address = burnerAccount.address;
111
- ```
112
-
113
- ```diff
114
- const requestDrip = async () => {
115
- - const balance = await signer.getBalance();
116
- + const balance = await publicClient.getBalance({ address });
117
- console.info(`[Dev Faucet]: Player balance -> ${balance}`);
118
- - const lowBalance = balance?.lte(utils.parseEther("1"));
119
- + const lowBalance = balance < parseEther("1");
120
- ```
121
-
122
- You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor.
123
-
124
- The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes.
125
-
126
- ```diff
127
- + return {
128
- + world,
129
- + components,
130
- + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
131
- + publicClient,
132
- + walletClient: burnerWalletClient,
133
- + latestBlock$,
134
- + blockStorageOperations$,
135
- + waitForTransaction,
136
- + worldContract,
137
- + };
138
- ```
139
-
140
- 5. Update `createSystemCalls` with the new return type of `setupNetwork`.
141
-
142
- ```diff
143
- export function createSystemCalls(
144
- - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult,
145
- + { worldContract, waitForTransaction }: SetupNetworkResult,
146
- { Counter }: ClientComponents
147
- ) {
148
- const increment = async () => {
149
- - const tx = await worldSend("increment", []);
150
- - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash);
151
- + const tx = await worldContract.write.increment();
152
- + await waitForTransaction(tx);
153
- return getComponentValue(Counter, singletonEntity);
154
- };
155
- ```
156
-
157
- 6. (optional) If you still need a clock, you can create it with:
158
-
159
- ```ts
160
- import { map, filter } from "rxjs";
161
- import { createClock } from "@latticexyz/network";
162
-
163
- const clock = createClock({
164
- period: 1000,
165
- initialTime: 0,
166
- syncInterval: 5000,
167
- });
168
-
169
- world.registerDisposer(() => clock.dispose());
170
-
171
- latestBlock$
172
- .pipe(
173
- map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms
174
- filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block
175
- filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct
176
- )
177
- .subscribe(clock.update); // Update the local clock
178
- ```
179
-
180
- If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`:
181
-
182
- ```ts
183
- import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs";
184
-
185
- const syncProgress = useComponentValue(SyncProgress, singletonEntity, {
186
- message: "Connecting",
187
- percentage: 0,
188
- step: SyncStep.INITIALIZE,
189
- });
190
-
191
- if (syncProgress.step === SyncStep.LIVE) {
192
- // we're live!
193
- }
194
- ```
195
-
196
- - [#1195](https://github.com/latticexyz/mud/pull/1195) [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd) Thanks [@holic](https://github.com/holic)! - Update RECS components with v2 key/value schemas. This helps with encoding/decoding composite keys and strong types for keys/values.
197
-
198
- This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`:
199
-
200
- - `component.id` is now the on-chain `bytes32` hex representation of the table ID
201
- - `component.metadata.componentName` is the table name (e.g. `Position`)
202
- - `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`)
203
- - `component.metadata.keySchema` is an object with key names and their corresponding ABI types
204
- - `component.metadata.valueSchema` is an object with field names and their corresponding ABI types
205
-
206
- - Updated dependencies [[`48909d15`](https://github.com/latticexyz/mud/commit/48909d151b3dfceab128c120bc6bb77de53c456b), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`f03531d9`](https://github.com/latticexyz/mud/commit/f03531d97c999954a626ef63bc5bbae51a7b90f3), [`4e4a3415`](https://github.com/latticexyz/mud/commit/4e4a34150aeae988c8e61e25d55c227afb6c2d4b), [`53522998`](https://github.com/latticexyz/mud/commit/535229984565539e6168042150b45fe0f9b48b0f)]:
207
- - @latticexyz/schema-type@2.0.0-main-788de8de
208
- - @latticexyz/utils@2.0.0-main-788de8de
209
-
210
3
  ## 2.0.0-next.1
211
4
 
212
5
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/recs",
3
- "version": "2.0.0-main-788de8de",
3
+ "version": "2.0.0-next.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/latticexyz/mud.git",
@@ -15,8 +15,8 @@
15
15
  "dependencies": {
16
16
  "mobx": "^6.7.0",
17
17
  "rxjs": "7.5.5",
18
- "@latticexyz/schema-type": "2.0.0-main-788de8de",
19
- "@latticexyz/utils": "2.0.0-main-788de8de"
18
+ "@latticexyz/schema-type": "2.0.0-next.1",
19
+ "@latticexyz/utils": "2.0.0-next.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/jest": "^27.4.1",