@latticexyz/store 2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77 → 2.2.18

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/dist/internal.js CHANGED
@@ -1,2 +1,303 @@
1
- import{g as d}from"./chunk-4TACS4IT.js";import{A as ue,B as xe,C as be,D as Se,E as Te,F as ke,G as Le,H as he,I as Be,J as Re,K as ve,L as Ae,M as Pe,N as De,O as Ne,P as He,Q as Ee,R as Ge,S as _e,T as Ce,U as Ke,V as Ie,a as $,b as q,c as F,d as J,e as Q,f as U,g as W,h as X,i as Y,j as Z,k as ee,l as te,m as oe,n as re,o as ae,p as ne,q as se,r as ce,s as ie,t as me,u as de,v as pe,w as le,x as ge,y as ye,z as fe}from"./chunk-5YJ4WITG.js";var p={staticData:"0x",encodedLengths:"0x",dynamicData:"0x"};import{toEventSelector as k,numberToHex as y,formatLog as L,parseEventLogs as h}from"viem";import g from"debug";var l=g("mud:store");l.log=console.debug.bind(console);var T=g("mud:store");T.log=console.error.bind(console);import{hexToResource as B,resourceToLabel as R}from"@latticexyz/common";async function et(r,{address:a,tableId:t,fromBlock:e,toBlock:o}={}){let n=[d.map(k),t??null],s=t?Array.isArray(t)?t:[t]:[],c=a?Array.isArray(a)?a:[a]:[];l(`getting store logs for ${s.length?s.map(B).map(R).join(", "):"all tables"} at ${c.length?c.join(", "):"any address"}`);let m=(await r.request({method:"eth_getLogs",params:[{address:a,topics:n,fromBlock:typeof e=="bigint"?y(e):e,toBlock:typeof o=="bigint"?y(o):o}]})).map(S=>L(S));return h({abi:d,args:{tableId:t},logs:m,strict:!0})}import{size as v}from"viem";import{logSort as A,spliceHex as f}from"@latticexyz/common";function P(r){return[r.address,r.args.tableId,r.args.keyTuple.join(",")].join(":")}function st(r){let a=r.slice().sort(A),t=new Map;for(let e of a){let o=P(e);if(e.eventName==="Store_SetRecord")t.delete(o),t.set(o,e);else if(e.eventName==="Store_SpliceStaticData"){let n=t.get(o),{staticData:s,encodedLengths:c,dynamicData:i}=n?.args??p,m={...e,eventName:"Store_SetRecord",args:{tableId:e.args.tableId,keyTuple:e.args.keyTuple,staticData:f(s,e.args.start,v(e.args.data),e.args.data),encodedLengths:c,dynamicData:i}};t.delete(o),t.set(o,m)}else if(e.eventName==="Store_SpliceDynamicData"){let n=t.get(o),{staticData:s,dynamicData:c}=n?.args??p,i={...e,eventName:"Store_SetRecord",args:{tableId:e.args.tableId,keyTuple:e.args.keyTuple,staticData:s,encodedLengths:e.args.encodedLengths,dynamicData:f(c,e.args.start,e.args.deleteCount,e.args.data)}};t.delete(o),t.set(o,i)}else e.eventName==="Store_DeleteRecord"&&t.delete(o)}return Array.from(t.values())}import{decodeKey as D,decodeValueArgs as N,getKeySchema as H,getSchemaTypes as u,getValueSchema as E}from"@latticexyz/protocol-parser/internal";function dt({table:r,log:a}){let t=u(H(r)),e=u(E(r)),o=D(t,a.args.keyTuple),n=N(e,a.args);return{...o,...n}}import{decodeValueArgs as G,getKeyTuple as _,getSchemaTypes as C,getValueSchema as K}from"@latticexyz/protocol-parser/internal";import{readContract as I}from"viem/actions";import{getAction as V}from"viem/utils";async function xt(r,{address:a,table:t,key:e,blockTag:o}){let[n,s,c]=await V(r,I,"readContract")({address:a,abi:j,functionName:"getRecord",args:[t.tableId,_(t,e)],blockTag:o});return{...e,...G(C(K(t)),{staticData:n,encodedLengths:s,dynamicData:c})}}var j=[{type:"function",name:"getRecord",inputs:[{name:"tableId",type:"bytes32",internalType:"ResourceId"},{name:"keyTuple",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"staticData",type:"bytes",internalType:"bytes"},{name:"encodedLengths",type:"bytes32",internalType:"EncodedLengths"},{name:"dynamicData",type:"bytes",internalType:"bytes"}],stateMutability:"view"}];import{concatHex as w,hexToBigInt as x,keccak256 as b,numberToHex as O,toBytes as z}from"viem";var M=x(b(z("mud.store")));function kt(r,a){return O(M^x(b(w([r,...a]))),{size:32})}export{te as AbiTypeScope,U as CODEGEN_DEFAULTS,Z as CONFIG_DEFAULTS,le as NoStaticKeyFieldError,ee as Scope,W as TABLE_CODEGEN_DEFAULTS,Y as TABLE_DEFAULTS,X as TABLE_DEPLOY_DEFAULTS,Ee as defineNamespaces,ne as defineSchema,Ie as defineStore,pe as defineTable,ue as defineTableShorthand,Se as defineTables,p as emptyRecord,fe as expandTableShorthand,oe as extendScope,_e as extendedScope,Te as extractInternalType,Ge as flattenNamespacedTables,st as flattenStoreLogs,$ as get,q as getPath,xt as getRecord,kt as getStaticDataLocation,et as getStoreLogs,F as hasOwnKey,J as isObject,se as isSchemaInput,ge as isTableShorthandInput,ke as isUserTypes,ce as isValidPrimaryKey,dt as logToRecord,ve as mapEnums,Q as mergeIfUndefined,Ae as resolveCodegen,Re as resolveEnums,De as resolveNamespace,He as resolveNamespaces,ae as resolveSchema,Ke as resolveStore,de as resolveTable,me as resolveTableCodegen,be as resolveTables,Be as scopeWithEnums,Le as scopeWithUserTypes,Pe as validateNamespace,Ne as validateNamespaces,re as validateSchema,Ce as validateStore,ie as validateTable,ye as validateTableShorthand,xe as validateTables,he as validateUserTypes};
1
+ import {
2
+ storeEventsAbi
3
+ } from "./chunk-ZBDA5HOY.js";
4
+ import {
5
+ AbiTypeScope,
6
+ CODEGEN_DEFAULTS,
7
+ CONFIG_DEFAULTS,
8
+ NoStaticKeyFieldError,
9
+ Scope,
10
+ TABLE_CODEGEN_DEFAULTS,
11
+ TABLE_DEFAULTS,
12
+ TABLE_DEPLOY_DEFAULTS,
13
+ defineNamespaces,
14
+ defineSchema,
15
+ defineStore,
16
+ defineTable,
17
+ defineTableShorthand,
18
+ defineTables,
19
+ expandTableShorthand,
20
+ extendScope,
21
+ extendedScope,
22
+ extractInternalType,
23
+ flattenNamespacedTables,
24
+ get,
25
+ getPath,
26
+ hasOwnKey,
27
+ isObject,
28
+ isSchemaInput,
29
+ isTableShorthandInput,
30
+ isUserTypes,
31
+ isValidPrimaryKey,
32
+ mapEnums,
33
+ mergeIfUndefined,
34
+ resolveCodegen,
35
+ resolveEnums,
36
+ resolveNamespace,
37
+ resolveNamespaces,
38
+ resolveSchema,
39
+ resolveStore,
40
+ resolveTable,
41
+ resolveTableCodegen,
42
+ resolveTables,
43
+ scopeWithEnums,
44
+ scopeWithUserTypes,
45
+ validateNamespace,
46
+ validateNamespaces,
47
+ validateSchema,
48
+ validateStore,
49
+ validateTable,
50
+ validateTableShorthand,
51
+ validateTables,
52
+ validateUserTypes
53
+ } from "./chunk-FULF4J63.js";
54
+
55
+ // ts/common.ts
56
+ var emptyRecord = {
57
+ staticData: "0x",
58
+ encodedLengths: "0x",
59
+ dynamicData: "0x"
60
+ };
61
+
62
+ // ts/getStoreLogs.ts
63
+ import {
64
+ toEventSelector,
65
+ numberToHex,
66
+ formatLog,
67
+ parseEventLogs
68
+ } from "viem";
69
+
70
+ // ts/debug.ts
71
+ import createDebug from "debug";
72
+ var debug = createDebug("mud:store");
73
+ debug.log = console.debug.bind(console);
74
+ var error = createDebug("mud:store");
75
+ error.log = console.error.bind(console);
76
+
77
+ // ts/getStoreLogs.ts
78
+ import { hexToResource, resourceToLabel } from "@latticexyz/common";
79
+ async function getStoreLogs(client, { address, tableId, fromBlock, toBlock } = {}) {
80
+ const topics = [storeEventsAbi.map(toEventSelector), tableId ?? null];
81
+ const tableIds = tableId ? Array.isArray(tableId) ? tableId : [tableId] : [];
82
+ const addresses = address ? Array.isArray(address) ? address : [address] : [];
83
+ debug(
84
+ `getting store logs for ${tableIds.length ? tableIds.map(hexToResource).map(resourceToLabel).join(", ") : "all tables"} at ${addresses.length ? addresses.join(", ") : "any address"}`
85
+ );
86
+ const logs = await client.request({
87
+ method: "eth_getLogs",
88
+ params: [
89
+ {
90
+ address,
91
+ topics,
92
+ fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
93
+ toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock
94
+ }
95
+ ]
96
+ });
97
+ const formattedLogs = logs.map((log) => formatLog(log));
98
+ return parseEventLogs({
99
+ abi: storeEventsAbi,
100
+ args: { tableId },
101
+ logs: formattedLogs,
102
+ strict: true
103
+ });
104
+ }
105
+
106
+ // ts/flattenStoreLogs.ts
107
+ import { size } from "viem";
108
+ import { logSort, spliceHex } from "@latticexyz/common";
109
+ function getKey(log) {
110
+ return [log.address, log.args.tableId, log.args.keyTuple.join(",")].join(":");
111
+ }
112
+ function flattenStoreLogs(logs) {
113
+ const sortedLogs = logs.slice().sort(logSort);
114
+ const records = /* @__PURE__ */ new Map();
115
+ for (const log of sortedLogs) {
116
+ const key = getKey(log);
117
+ if (log.eventName === "Store_SetRecord") {
118
+ records.delete(key);
119
+ records.set(key, log);
120
+ } else if (log.eventName === "Store_SpliceStaticData") {
121
+ const previousRecord = records.get(key);
122
+ const { staticData, encodedLengths, dynamicData } = previousRecord?.args ?? emptyRecord;
123
+ const nextRecord = {
124
+ ...log,
125
+ eventName: "Store_SetRecord",
126
+ args: {
127
+ tableId: log.args.tableId,
128
+ keyTuple: log.args.keyTuple,
129
+ staticData: spliceHex(staticData, log.args.start, size(log.args.data), log.args.data),
130
+ encodedLengths,
131
+ dynamicData
132
+ }
133
+ };
134
+ records.delete(key);
135
+ records.set(key, nextRecord);
136
+ } else if (log.eventName === "Store_SpliceDynamicData") {
137
+ const previousRecord = records.get(key);
138
+ const { staticData, dynamicData } = previousRecord?.args ?? emptyRecord;
139
+ const nextRecord = {
140
+ ...log,
141
+ eventName: "Store_SetRecord",
142
+ args: {
143
+ tableId: log.args.tableId,
144
+ keyTuple: log.args.keyTuple,
145
+ staticData,
146
+ encodedLengths: log.args.encodedLengths,
147
+ dynamicData: spliceHex(dynamicData, log.args.start, log.args.deleteCount, log.args.data)
148
+ }
149
+ };
150
+ records.delete(key);
151
+ records.set(key, nextRecord);
152
+ } else if (log.eventName === "Store_DeleteRecord") {
153
+ records.delete(key);
154
+ }
155
+ }
156
+ return Array.from(records.values());
157
+ }
158
+
159
+ // ts/logToRecord.ts
160
+ import {
161
+ decodeKey,
162
+ decodeValueArgs,
163
+ getKeySchema,
164
+ getSchemaTypes,
165
+ getValueSchema
166
+ } from "@latticexyz/protocol-parser/internal";
167
+ function logToRecord({
168
+ table,
169
+ log
170
+ }) {
171
+ const keySchema = getSchemaTypes(getKeySchema(table));
172
+ const valueSchema = getSchemaTypes(getValueSchema(table));
173
+ const key = decodeKey(keySchema, log.args.keyTuple);
174
+ const value = decodeValueArgs(valueSchema, log.args);
175
+ return { ...key, ...value };
176
+ }
177
+
178
+ // ts/getRecord.ts
179
+ import {
180
+ decodeValueArgs as decodeValueArgs2,
181
+ getKeyTuple,
182
+ getSchemaTypes as getSchemaTypes2,
183
+ getValueSchema as getValueSchema2
184
+ } from "@latticexyz/protocol-parser/internal";
185
+ import { readContract } from "viem/actions";
186
+ import { getAction } from "viem/utils";
187
+ async function getRecord(client, { address, table, key, blockTag }) {
188
+ const [staticData, encodedLengths, dynamicData] = await getAction(
189
+ client,
190
+ readContract,
191
+ "readContract"
192
+ )({
193
+ address,
194
+ abi,
195
+ functionName: "getRecord",
196
+ args: [table.tableId, getKeyTuple(table, key)],
197
+ blockTag
198
+ });
199
+ return {
200
+ ...key,
201
+ ...decodeValueArgs2(getSchemaTypes2(getValueSchema2(table)), { staticData, encodedLengths, dynamicData })
202
+ };
203
+ }
204
+ var abi = [
205
+ {
206
+ type: "function",
207
+ name: "getRecord",
208
+ inputs: [
209
+ {
210
+ name: "tableId",
211
+ type: "bytes32",
212
+ internalType: "ResourceId"
213
+ },
214
+ {
215
+ name: "keyTuple",
216
+ type: "bytes32[]",
217
+ internalType: "bytes32[]"
218
+ }
219
+ ],
220
+ outputs: [
221
+ {
222
+ name: "staticData",
223
+ type: "bytes",
224
+ internalType: "bytes"
225
+ },
226
+ {
227
+ name: "encodedLengths",
228
+ type: "bytes32",
229
+ internalType: "EncodedLengths"
230
+ },
231
+ {
232
+ name: "dynamicData",
233
+ type: "bytes",
234
+ internalType: "bytes"
235
+ }
236
+ ],
237
+ stateMutability: "view"
238
+ }
239
+ ];
240
+
241
+ // ts/getStaticDataLocation.ts
242
+ import { concatHex, hexToBigInt, keccak256, numberToHex as numberToHex2, toBytes } from "viem";
243
+ var SLOT = hexToBigInt(keccak256(toBytes("mud.store")));
244
+ function getStaticDataLocation(tableId, keyTuple) {
245
+ return numberToHex2(SLOT ^ hexToBigInt(keccak256(concatHex([tableId, ...keyTuple]))), { size: 32 });
246
+ }
247
+ export {
248
+ AbiTypeScope,
249
+ CODEGEN_DEFAULTS,
250
+ CONFIG_DEFAULTS,
251
+ NoStaticKeyFieldError,
252
+ Scope,
253
+ TABLE_CODEGEN_DEFAULTS,
254
+ TABLE_DEFAULTS,
255
+ TABLE_DEPLOY_DEFAULTS,
256
+ defineNamespaces,
257
+ defineSchema,
258
+ defineStore,
259
+ defineTable,
260
+ defineTableShorthand,
261
+ defineTables,
262
+ emptyRecord,
263
+ expandTableShorthand,
264
+ extendScope,
265
+ extendedScope,
266
+ extractInternalType,
267
+ flattenNamespacedTables,
268
+ flattenStoreLogs,
269
+ get,
270
+ getPath,
271
+ getRecord,
272
+ getStaticDataLocation,
273
+ getStoreLogs,
274
+ hasOwnKey,
275
+ isObject,
276
+ isSchemaInput,
277
+ isTableShorthandInput,
278
+ isUserTypes,
279
+ isValidPrimaryKey,
280
+ logToRecord,
281
+ mapEnums,
282
+ mergeIfUndefined,
283
+ resolveCodegen,
284
+ resolveEnums,
285
+ resolveNamespace,
286
+ resolveNamespaces,
287
+ resolveSchema,
288
+ resolveStore,
289
+ resolveTable,
290
+ resolveTableCodegen,
291
+ resolveTables,
292
+ scopeWithEnums,
293
+ scopeWithUserTypes,
294
+ validateNamespace,
295
+ validateNamespaces,
296
+ validateSchema,
297
+ validateStore,
298
+ validateTable,
299
+ validateTableShorthand,
300
+ validateTables,
301
+ validateUserTypes
302
+ };
2
303
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../ts/common.ts","../ts/getStoreLogs.ts","../ts/debug.ts","../ts/flattenStoreLogs.ts","../ts/logToRecord.ts","../ts/getRecord.ts","../ts/getStaticDataLocation.ts"],"sourcesContent":["import { SchemaAbiType, SchemaAbiTypeToPrimitiveType, StaticAbiType } from \"@latticexyz/schema-type/internal\";\n\nexport type KeySchema = {\n readonly [k: string]: {\n readonly type: StaticAbiType;\n };\n};\nexport type ValueSchema = {\n readonly [k: string]: {\n readonly type: SchemaAbiType;\n };\n};\n\n/** Map a table schema like `{ value: { type: \"uint256\" } }` to its primitive types like `{ value: bigint }` */\nexport type SchemaToPrimitives<schema extends ValueSchema> = {\n readonly [key in keyof schema]: SchemaAbiTypeToPrimitiveType<schema[key][\"type\"]>;\n};\n\nexport const emptyRecord = {\n staticData: \"0x\",\n encodedLengths: \"0x\",\n dynamicData: \"0x\",\n} as const;\n","import {\n BlockNumber,\n BlockTag,\n Address,\n Log,\n Hex,\n GetLogsErrorType,\n Client,\n toEventSelector,\n LogTopic,\n RpcLog,\n numberToHex,\n formatLog,\n parseEventLogs,\n} from \"viem\";\nimport { storeEventsAbi } from \"./storeEventsAbi\";\nimport { debug } from \"./debug\";\nimport { hexToResource, resourceToLabel } from \"@latticexyz/common\";\n\nexport type GetStoreLogsParameters<\n fromBlock extends BlockNumber | BlockTag | undefined = undefined,\n toBlock extends BlockNumber | BlockTag | undefined = undefined,\n> = {\n /** Store address or list of store addresses from which logs originated */\n address?: Address | Address[] | undefined;\n /** Optionally match a specific table ID or list of table IDs */\n tableId?: Hex | Hex[] | undefined;\n /** Block number or tag after which to include logs */\n fromBlock?: fromBlock | BlockNumber | BlockTag | undefined;\n /** Block number or tag before which to include logs */\n toBlock?: toBlock | BlockNumber | BlockTag | undefined;\n};\n\nexport type GetStoreLogsReturnType<\n fromBlock extends BlockNumber | BlockTag | undefined = undefined,\n toBlock extends BlockNumber | BlockTag | undefined = undefined,\n _pending extends boolean = (fromBlock extends \"pending\" ? true : false) | (toBlock extends \"pending\" ? true : false),\n> = Log<bigint, number, _pending, undefined, true, storeEventsAbi, undefined>[];\n\nexport type GetStoreLogsErrorType = GetLogsErrorType;\n\n/**\n * Returns an unordered list of store event logs matching the provided parameters.\n *\n * @param client - Client to use\n * @param parameters - {@link GetStoreLogsParameters}\n * @returns A list of event logs. {@link GetStoreLogsReturnType}\n *\n * @example\n * import { createClient, http } from 'viem'\n * import { mainnet } from 'viem/chains'\n * import { getStoreLogs } from '@latticexyz/store'\n *\n * const client = createPublicClient({\n * chain: mainnet,\n * transport: http(),\n * })\n * const storeLogs = await getStoreLogs(client)\n */\nexport async function getStoreLogs<\n fromBlock extends BlockNumber | BlockTag | undefined = undefined,\n toBlock extends BlockNumber | BlockTag | undefined = undefined,\n>(\n client: Client,\n { address, tableId, fromBlock, toBlock }: GetStoreLogsParameters<fromBlock, toBlock> = {},\n): Promise<GetStoreLogsReturnType<fromBlock, toBlock>> {\n /**\n * Note that this implementation follows Viem's [`getLogs`][0] action:\n * https://github.com/wevm/viem/blob/main/src/actions/public/getLogs.ts\n *\n * It's adapted to allow filtering by table ID(s), which Viem's `getLogs`\n * does not support due to how it builds topics.\n */\n\n const topics: LogTopic[] = [storeEventsAbi.map(toEventSelector), tableId ?? null];\n\n const tableIds = tableId ? (Array.isArray(tableId) ? tableId : [tableId]) : [];\n const addresses = address ? (Array.isArray(address) ? address : [address]) : [];\n debug(\n `getting store logs for ${\n tableIds.length ? tableIds.map(hexToResource).map(resourceToLabel).join(\", \") : \"all tables\"\n } at ${addresses.length ? addresses.join(\", \") : \"any address\"}`,\n );\n\n const logs: RpcLog[] = await client.request({\n method: \"eth_getLogs\",\n params: [\n {\n address,\n topics,\n fromBlock: typeof fromBlock === \"bigint\" ? numberToHex(fromBlock) : fromBlock,\n toBlock: typeof toBlock === \"bigint\" ? numberToHex(toBlock) : toBlock,\n },\n ],\n });\n\n const formattedLogs = logs.map((log) => formatLog(log));\n return parseEventLogs({\n abi: storeEventsAbi,\n args: { tableId },\n logs: formattedLogs,\n strict: true,\n }) as GetStoreLogsReturnType<fromBlock, toBlock>;\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:store\");\ndebug.log = console.debug.bind(console);\n\nexport const error = createDebug(\"mud:store\");\nerror.log = console.error.bind(console);\n","import { Log, size } from \"viem\";\nimport { storeEventsAbi } from \"./storeEventsAbi\";\nimport { emptyRecord } from \"./common\";\nimport { StoreLog, StoreSetRecordLog } from \"./storeLog\";\nimport { logSort, spliceHex } from \"@latticexyz/common\";\n\nfunction getKey(log: Log<bigint, number, boolean, undefined, true, storeEventsAbi, undefined>) {\n return [log.address, log.args.tableId, log.args.keyTuple.join(\",\")].join(\":\");\n}\n\nexport function flattenStoreLogs(logs: StoreLog[]): StoreSetRecordLog[] {\n const sortedLogs = logs.slice().sort(logSort);\n const records = new Map<string, StoreSetRecordLog>();\n\n for (const log of sortedLogs) {\n const key = getKey(log);\n\n if (log.eventName === \"Store_SetRecord\") {\n // maps preserve order, so always delete then set so the record gets\n // added to the end of the map, thus preserving the log order\n records.delete(key);\n records.set(key, log);\n } else if (log.eventName === \"Store_SpliceStaticData\") {\n const previousRecord = records.get(key);\n const { staticData, encodedLengths, dynamicData } = previousRecord?.args ?? emptyRecord;\n const nextRecord = {\n ...log,\n eventName: \"Store_SetRecord\",\n args: {\n tableId: log.args.tableId,\n keyTuple: log.args.keyTuple,\n staticData: spliceHex(staticData, log.args.start, size(log.args.data), log.args.data),\n encodedLengths,\n dynamicData,\n },\n } satisfies StoreSetRecordLog;\n // maps preserve order, so always delete then set so the record gets\n // added to the end of the map, thus preserving the log order\n records.delete(key);\n records.set(key, nextRecord);\n } else if (log.eventName === \"Store_SpliceDynamicData\") {\n const previousRecord = records.get(key);\n const { staticData, dynamicData } = previousRecord?.args ?? emptyRecord;\n const nextRecord = {\n ...log,\n eventName: \"Store_SetRecord\",\n args: {\n tableId: log.args.tableId,\n keyTuple: log.args.keyTuple,\n staticData,\n encodedLengths: log.args.encodedLengths,\n dynamicData: spliceHex(dynamicData, log.args.start, log.args.deleteCount, log.args.data),\n },\n } satisfies StoreSetRecordLog;\n // maps preserve order, so always delete then set so the record gets\n // added to the end of the map, thus preserving the log order\n records.delete(key);\n records.set(key, nextRecord);\n } else if (log.eventName === \"Store_DeleteRecord\") {\n records.delete(key);\n }\n }\n\n return Array.from(records.values());\n}\n","import { Table } from \"@latticexyz/config\";\nimport {\n decodeKey,\n decodeValueArgs,\n getKeySchema,\n getSchemaPrimitives,\n getSchemaTypes,\n getValueSchema,\n} from \"@latticexyz/protocol-parser/internal\";\nimport { StoreLog } from \"./storeLog\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\ntype PartialLog = Pick<Extract<StoreLog, { eventName: \"Store_SetRecord\" }>, \"args\">;\n\nexport type LogToRecordArgs<table extends PartialTable> = {\n table: table;\n log: PartialLog;\n};\n\nexport function logToRecord<table extends PartialTable>({\n table,\n log,\n}: LogToRecordArgs<table>): getSchemaPrimitives<table[\"schema\"]> {\n const keySchema = getSchemaTypes(getKeySchema(table));\n const valueSchema = getSchemaTypes(getValueSchema(table));\n const key = decodeKey(keySchema, log.args.keyTuple);\n const value = decodeValueArgs(valueSchema, log.args);\n return { ...key, ...value };\n}\n","import { Address, Client, Hex } from \"viem\";\nimport { Table } from \"@latticexyz/config\";\nimport {\n decodeValueArgs,\n getKeySchema,\n getKeyTuple,\n getSchemaPrimitives,\n getSchemaTypes,\n getValueSchema,\n} from \"@latticexyz/protocol-parser/internal\";\nimport { readContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\n\nexport type GetRecordOptions<table extends Table> = {\n address: Address;\n table: table;\n key: getSchemaPrimitives<getKeySchema<table>>;\n blockTag?: \"latest\" | \"pending\";\n};\n\nexport async function getRecord<table extends Table>(\n client: Client,\n { address, table, key, blockTag }: GetRecordOptions<table>,\n): Promise<getSchemaPrimitives<table[\"schema\"]>> {\n const [staticData, encodedLengths, dynamicData] = await getAction(\n client,\n readContract,\n \"readContract\",\n )({\n address,\n abi,\n functionName: \"getRecord\",\n args: [table.tableId, getKeyTuple(table, key) as readonly Hex[]],\n blockTag,\n });\n\n return {\n ...key,\n ...decodeValueArgs(getSchemaTypes(getValueSchema(table)), { staticData, encodedLengths, dynamicData }),\n };\n}\n\nconst abi = [\n {\n type: \"function\",\n name: \"getRecord\",\n inputs: [\n {\n name: \"tableId\",\n type: \"bytes32\",\n internalType: \"ResourceId\",\n },\n {\n name: \"keyTuple\",\n type: \"bytes32[]\",\n internalType: \"bytes32[]\",\n },\n ],\n outputs: [\n {\n name: \"staticData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n {\n name: \"encodedLengths\",\n type: \"bytes32\",\n internalType: \"EncodedLengths\",\n },\n {\n name: \"dynamicData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n ],\n stateMutability: \"view\",\n },\n] as const;\n","import { Hex, concatHex, hexToBigInt, keccak256, numberToHex, toBytes } from \"viem\";\n\n// TODO: move to protocol-parser?\n// equivalent of StoreCore._getStaticDataLocation\n\nconst SLOT = hexToBigInt(keccak256(toBytes(\"mud.store\")));\n\nexport function getStaticDataLocation(tableId: Hex, keyTuple: readonly Hex[]): Hex {\n return numberToHex(SLOT ^ hexToBigInt(keccak256(concatHex([tableId, ...keyTuple]))), { size: 32 });\n}\n"],"mappings":"+bAkBO,IAAMA,EAAc,CACzB,WAAY,KACZ,eAAgB,KAChB,YAAa,IACf,ECtBA,OAQE,mBAAAC,EAGA,eAAAC,EACA,aAAAC,EACA,kBAAAC,MACK,OCdP,OAAOC,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,WAAW,EAC5CC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EAE/B,IAAMC,EAAQF,EAAY,WAAW,EAC5CE,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EDWtC,OAAS,iBAAAC,EAAe,mBAAAC,MAAuB,qBA0C/C,eAAsBC,GAIpBC,EACA,CAAE,QAAAC,EAAS,QAAAC,EAAS,UAAAC,EAAW,QAAAC,CAAQ,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GAAGC,CAAQ,CAAC,CAAC,CAAC,EAAG,CAAE,KAAM,EAAG,CAAC,CACnG","names":["emptyRecord","toEventSelector","numberToHex","formatLog","parseEventLogs","createDebug","debug","error","hexToResource","resourceToLabel","getStoreLogs","client","address","tableId","fromBlock","toBlock","topics","storeEventsAbi","toEventSelector","tableIds","addresses","debug","formattedLogs","numberToHex","log","formatLog","parseEventLogs","size","logSort","spliceHex","getKey","log","flattenStoreLogs","logs","sortedLogs","records","key","previousRecord","staticData","encodedLengths","dynamicData","emptyRecord","nextRecord","size","decodeKey","decodeValueArgs","getKeySchema","getSchemaTypes","getValueSchema","logToRecord","table","log","keySchema","valueSchema","key","value","decodeValueArgs","getKeyTuple","getSchemaTypes","getValueSchema","readContract","getAction","getRecord","client","address","table","key","blockTag","staticData","encodedLengths","dynamicData","abi","concatHex","hexToBigInt","keccak256","numberToHex","toBytes","SLOT","getStaticDataLocation","tableId","keyTuple"]}
1
+ {"version":3,"sources":["../ts/common.ts","../ts/getStoreLogs.ts","../ts/debug.ts","../ts/flattenStoreLogs.ts","../ts/logToRecord.ts","../ts/getRecord.ts","../ts/getStaticDataLocation.ts"],"sourcesContent":["import { SchemaAbiType, SchemaAbiTypeToPrimitiveType, StaticAbiType } from \"@latticexyz/schema-type/internal\";\n\nexport type KeySchema = {\n readonly [k: string]: {\n readonly type: StaticAbiType;\n };\n};\nexport type ValueSchema = {\n readonly [k: string]: {\n readonly type: SchemaAbiType;\n };\n};\n\n/** Map a table schema like `{ value: { type: \"uint256\" } }` to its primitive types like `{ value: bigint }` */\nexport type SchemaToPrimitives<schema extends ValueSchema> = {\n readonly [key in keyof schema]: SchemaAbiTypeToPrimitiveType<schema[key][\"type\"]>;\n};\n\nexport const emptyRecord = {\n staticData: \"0x\",\n encodedLengths: \"0x\",\n dynamicData: \"0x\",\n} as const;\n","import {\n BlockNumber,\n BlockTag,\n Address,\n Log,\n Hex,\n GetLogsErrorType,\n Client,\n toEventSelector,\n LogTopic,\n RpcLog,\n numberToHex,\n formatLog,\n parseEventLogs,\n} from \"viem\";\nimport { storeEventsAbi } from \"./storeEventsAbi\";\nimport { debug } from \"./debug\";\nimport { hexToResource, resourceToLabel } from \"@latticexyz/common\";\n\nexport type GetStoreLogsParameters<\n fromBlock extends BlockNumber | BlockTag | undefined = undefined,\n toBlock extends BlockNumber | BlockTag | undefined = undefined,\n> = {\n /** Store address or list of store addresses from which logs originated */\n address?: Address | Address[] | undefined;\n /** Optionally match a specific table ID or list of table IDs */\n tableId?: Hex | Hex[] | undefined;\n /** Block number or tag after which to include logs */\n fromBlock?: fromBlock | BlockNumber | BlockTag | undefined;\n /** Block number or tag before which to include logs */\n toBlock?: toBlock | BlockNumber | BlockTag | undefined;\n};\n\nexport type GetStoreLogsReturnType<\n fromBlock extends BlockNumber | BlockTag | undefined = undefined,\n toBlock extends BlockNumber | BlockTag | undefined = undefined,\n _pending extends boolean = (fromBlock extends \"pending\" ? true : false) | (toBlock extends \"pending\" ? true : false),\n> = Log<bigint, number, _pending, undefined, true, storeEventsAbi, undefined>[];\n\nexport type GetStoreLogsErrorType = GetLogsErrorType;\n\n/**\n * Returns an unordered list of store event logs matching the provided parameters.\n *\n * @param client - Client to use\n * @param parameters - {@link GetStoreLogsParameters}\n * @returns A list of event logs. {@link GetStoreLogsReturnType}\n *\n * @example\n * import { createClient, http } from 'viem'\n * import { mainnet } from 'viem/chains'\n * import { getStoreLogs } from '@latticexyz/store'\n *\n * const client = createPublicClient({\n * chain: mainnet,\n * transport: http(),\n * })\n * const storeLogs = await getStoreLogs(client)\n */\nexport async function getStoreLogs<\n fromBlock extends BlockNumber | BlockTag | undefined = undefined,\n toBlock extends BlockNumber | BlockTag | undefined = undefined,\n>(\n client: Client,\n { address, tableId, fromBlock, toBlock }: GetStoreLogsParameters<fromBlock, toBlock> = {},\n): Promise<GetStoreLogsReturnType<fromBlock, toBlock>> {\n /**\n * Note that this implementation follows Viem's [`getLogs`][0] action:\n * https://github.com/wevm/viem/blob/main/src/actions/public/getLogs.ts\n *\n * It's adapted to allow filtering by table ID(s), which Viem's `getLogs`\n * does not support due to how it builds topics.\n */\n\n const topics: LogTopic[] = [storeEventsAbi.map(toEventSelector), tableId ?? null];\n\n const tableIds = tableId ? (Array.isArray(tableId) ? tableId : [tableId]) : [];\n const addresses = address ? (Array.isArray(address) ? address : [address]) : [];\n debug(\n `getting store logs for ${\n tableIds.length ? tableIds.map(hexToResource).map(resourceToLabel).join(\", \") : \"all tables\"\n } at ${addresses.length ? addresses.join(\", \") : \"any address\"}`,\n );\n\n const logs: RpcLog[] = await client.request({\n method: \"eth_getLogs\",\n params: [\n {\n address,\n topics,\n fromBlock: typeof fromBlock === \"bigint\" ? numberToHex(fromBlock) : fromBlock,\n toBlock: typeof toBlock === \"bigint\" ? numberToHex(toBlock) : toBlock,\n },\n ],\n });\n\n const formattedLogs = logs.map((log) => formatLog(log));\n return parseEventLogs({\n abi: storeEventsAbi,\n args: { tableId },\n logs: formattedLogs,\n strict: true,\n }) as GetStoreLogsReturnType<fromBlock, toBlock>;\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:store\");\ndebug.log = console.debug.bind(console);\n\nexport const error = createDebug(\"mud:store\");\nerror.log = console.error.bind(console);\n","import { Log, size } from \"viem\";\nimport { storeEventsAbi } from \"./storeEventsAbi\";\nimport { emptyRecord } from \"./common\";\nimport { StoreLog, StoreSetRecordLog } from \"./storeLog\";\nimport { logSort, spliceHex } from \"@latticexyz/common\";\n\nfunction getKey(log: Log<bigint, number, boolean, undefined, true, storeEventsAbi, undefined>) {\n return [log.address, log.args.tableId, log.args.keyTuple.join(\",\")].join(\":\");\n}\n\nexport function flattenStoreLogs(logs: StoreLog[]): StoreSetRecordLog[] {\n const sortedLogs = logs.slice().sort(logSort);\n const records = new Map<string, StoreSetRecordLog>();\n\n for (const log of sortedLogs) {\n const key = getKey(log);\n\n if (log.eventName === \"Store_SetRecord\") {\n // maps preserve order, so always delete then set so the record gets\n // added to the end of the map, thus preserving the log order\n records.delete(key);\n records.set(key, log);\n } else if (log.eventName === \"Store_SpliceStaticData\") {\n const previousRecord = records.get(key);\n const { staticData, encodedLengths, dynamicData } = previousRecord?.args ?? emptyRecord;\n const nextRecord = {\n ...log,\n eventName: \"Store_SetRecord\",\n args: {\n tableId: log.args.tableId,\n keyTuple: log.args.keyTuple,\n staticData: spliceHex(staticData, log.args.start, size(log.args.data), log.args.data),\n encodedLengths,\n dynamicData,\n },\n } satisfies StoreSetRecordLog;\n // maps preserve order, so always delete then set so the record gets\n // added to the end of the map, thus preserving the log order\n records.delete(key);\n records.set(key, nextRecord);\n } else if (log.eventName === \"Store_SpliceDynamicData\") {\n const previousRecord = records.get(key);\n const { staticData, dynamicData } = previousRecord?.args ?? emptyRecord;\n const nextRecord = {\n ...log,\n eventName: \"Store_SetRecord\",\n args: {\n tableId: log.args.tableId,\n keyTuple: log.args.keyTuple,\n staticData,\n encodedLengths: log.args.encodedLengths,\n dynamicData: spliceHex(dynamicData, log.args.start, log.args.deleteCount, log.args.data),\n },\n } satisfies StoreSetRecordLog;\n // maps preserve order, so always delete then set so the record gets\n // added to the end of the map, thus preserving the log order\n records.delete(key);\n records.set(key, nextRecord);\n } else if (log.eventName === \"Store_DeleteRecord\") {\n records.delete(key);\n }\n }\n\n return Array.from(records.values());\n}\n","import { Table } from \"@latticexyz/config\";\nimport {\n decodeKey,\n decodeValueArgs,\n getKeySchema,\n getSchemaPrimitives,\n getSchemaTypes,\n getValueSchema,\n} from \"@latticexyz/protocol-parser/internal\";\nimport { StoreLog } from \"./storeLog\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\ntype PartialLog = Pick<Extract<StoreLog, { eventName: \"Store_SetRecord\" }>, \"args\">;\n\nexport type LogToRecordArgs<table extends PartialTable> = {\n table: table;\n log: PartialLog;\n};\n\nexport function logToRecord<table extends PartialTable>({\n table,\n log,\n}: LogToRecordArgs<table>): getSchemaPrimitives<table[\"schema\"]> {\n const keySchema = getSchemaTypes(getKeySchema(table));\n const valueSchema = getSchemaTypes(getValueSchema(table));\n const key = decodeKey(keySchema, log.args.keyTuple);\n const value = decodeValueArgs(valueSchema, log.args);\n return { ...key, ...value };\n}\n","import { Address, Client, Hex } from \"viem\";\nimport { Table } from \"@latticexyz/config\";\nimport {\n decodeValueArgs,\n getKeySchema,\n getKeyTuple,\n getSchemaPrimitives,\n getSchemaTypes,\n getValueSchema,\n} from \"@latticexyz/protocol-parser/internal\";\nimport { readContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\n\nexport type GetRecordOptions<table extends Table> = {\n address: Address;\n table: table;\n key: getSchemaPrimitives<getKeySchema<table>>;\n blockTag?: \"latest\" | \"pending\";\n};\n\nexport async function getRecord<table extends Table>(\n client: Client,\n { address, table, key, blockTag }: GetRecordOptions<table>,\n): Promise<getSchemaPrimitives<table[\"schema\"]>> {\n const [staticData, encodedLengths, dynamicData] = await getAction(\n client,\n readContract,\n \"readContract\",\n )({\n address,\n abi,\n functionName: \"getRecord\",\n args: [table.tableId, getKeyTuple(table, key) as readonly Hex[]],\n blockTag,\n });\n\n return {\n ...key,\n ...decodeValueArgs(getSchemaTypes(getValueSchema(table)), { staticData, encodedLengths, dynamicData }),\n };\n}\n\nconst abi = [\n {\n type: \"function\",\n name: \"getRecord\",\n inputs: [\n {\n name: \"tableId\",\n type: \"bytes32\",\n internalType: \"ResourceId\",\n },\n {\n name: \"keyTuple\",\n type: \"bytes32[]\",\n internalType: \"bytes32[]\",\n },\n ],\n outputs: [\n {\n name: \"staticData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n {\n name: \"encodedLengths\",\n type: \"bytes32\",\n internalType: \"EncodedLengths\",\n },\n {\n name: \"dynamicData\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n ],\n stateMutability: \"view\",\n },\n] as const;\n","import { Hex, concatHex, hexToBigInt, keccak256, numberToHex, toBytes } from \"viem\";\n\n// TODO: move to protocol-parser?\n// equivalent of StoreCore._getStaticDataLocation\n\nconst SLOT = hexToBigInt(keccak256(toBytes(\"mud.store\")));\n\nexport function getStaticDataLocation(tableId: Hex, keyTuple: readonly Hex[]): Hex {\n return numberToHex(SLOT ^ hexToBigInt(keccak256(concatHex([tableId, ...keyTuple]))), { size: 32 });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAM,cAAc;AAAA,EACzB,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,aAAa;AACf;;;ACtBA;AAAA,EAQE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACdP,OAAO,iBAAiB;AAEjB,IAAM,QAAQ,YAAY,WAAW;AAC5C,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;AAE/B,IAAM,QAAQ,YAAY,WAAW;AAC5C,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;;;ADWtC,SAAS,eAAe,uBAAuB;AA0C/C,eAAsB,aAIpB,QACA,EAAE,SAAS,SAAS,WAAW,QAAQ,IAAgD,CAAC,GACnC;AASrD,QAAM,SAAqB,CAAC,eAAe,IAAI,eAAe,GAAG,WAAW,IAAI;AAEhF,QAAM,WAAW,UAAW,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO,IAAK,CAAC;AAC7E,QAAM,YAAY,UAAW,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO,IAAK,CAAC;AAC9E;AAAA,IACE,0BACE,SAAS,SAAS,SAAS,IAAI,aAAa,EAAE,IAAI,eAAe,EAAE,KAAK,IAAI,IAAI,YAClF,OAAO,UAAU,SAAS,UAAU,KAAK,IAAI,IAAI,aAAa;AAAA,EAChE;AAEA,QAAM,OAAiB,MAAM,OAAO,QAAQ;AAAA,IAC1C,QAAQ;AAAA,IACR,QAAQ;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA,WAAW,OAAO,cAAc,WAAW,YAAY,SAAS,IAAI;AAAA,QACpE,SAAS,OA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cAAc;AAAA,IACd,MAAM,CAAC,MAAM,SAAS,YAAY,OAAO,GAAG,CAAmB;AAAA,IAC/D;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAGF,iBAAgBC,gBAAeC,gBAAe,KAAK,CAAC,GAAG,EAAE,YAAY,gBAAgB,YAAY,CAAC;AAAA,EACvG;AACF;AAEA,IAAM,MAAM;AAAA,EACV;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,MACN;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,EACnB;AACF;;;AC7EA,SAAc,WAAW,aAAa,WAAW,eAAAC,cAAa,eAAe;AAK7E,IAAM,OAAO,YAAY,UAAU,QAAQ,WAAW,CAAC,CAAC;AAEjD,SAAS,sBAAsB,SAAc,UAA+B;AACjF,SAAOA,aAAY,OAAO,YAAY,UAAU,UAAU,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC;AACnG;","names":["decodeValueArgs","getSchemaTypes","getValueSchema","numberToHex"]}
@@ -1,2 +1,61 @@
1
- import{V as e}from"./chunk-5YJ4WITG.js";var o=e({namespace:"store",codegen:{storeImportPath:"./src"},userTypes:{ResourceId:{filePath:"./src/ResourceId.sol",type:"bytes32"},FieldLayout:{filePath:"./src/FieldLayout.sol",type:"bytes32"},Schema:{filePath:"./src/Schema.sol",type:"bytes32"}},tables:{StoreHooks:{schema:{tableId:"ResourceId",hooks:"bytes21[]"},key:["tableId"]},Tables:{schema:{tableId:"ResourceId",fieldLayout:"FieldLayout",keySchema:"Schema",valueSchema:"Schema",abiEncodedKeyNames:"bytes",abiEncodedFieldNames:"bytes"},key:["tableId"]},ResourceIds:{schema:{resourceId:"ResourceId",exists:"bool"},key:["resourceId"]},Hooks:{schema:{resourceId:"ResourceId",hooks:"bytes21[]"},key:["resourceId"],codegen:{tableIdArgument:!0},deploy:{disabled:!0}}}});export{o as default};
1
+ import {
2
+ defineStore
3
+ } from "./chunk-FULF4J63.js";
4
+
5
+ // mud.config.ts
6
+ var mud_config_default = defineStore({
7
+ namespace: "store",
8
+ codegen: {
9
+ storeImportPath: "./src"
10
+ },
11
+ userTypes: {
12
+ ResourceId: { filePath: "./src/ResourceId.sol", type: "bytes32" },
13
+ FieldLayout: { filePath: "./src/FieldLayout.sol", type: "bytes32" },
14
+ Schema: { filePath: "./src/Schema.sol", type: "bytes32" }
15
+ },
16
+ tables: {
17
+ StoreHooks: {
18
+ schema: {
19
+ tableId: "ResourceId",
20
+ hooks: "bytes21[]"
21
+ },
22
+ key: ["tableId"]
23
+ },
24
+ Tables: {
25
+ schema: {
26
+ tableId: "ResourceId",
27
+ fieldLayout: "FieldLayout",
28
+ keySchema: "Schema",
29
+ valueSchema: "Schema",
30
+ abiEncodedKeyNames: "bytes",
31
+ abiEncodedFieldNames: "bytes"
32
+ },
33
+ key: ["tableId"]
34
+ },
35
+ ResourceIds: {
36
+ schema: {
37
+ resourceId: "ResourceId",
38
+ exists: "bool"
39
+ },
40
+ key: ["resourceId"]
41
+ },
42
+ // This is generic, codegen-only table used by `filterFromList` in `Hook.sol`
43
+ Hooks: {
44
+ schema: {
45
+ resourceId: "ResourceId",
46
+ hooks: "bytes21[]"
47
+ },
48
+ key: ["resourceId"],
49
+ codegen: {
50
+ tableIdArgument: true
51
+ },
52
+ deploy: {
53
+ disabled: true
54
+ }
55
+ }
56
+ }
57
+ });
58
+ export {
59
+ mud_config_default as default
60
+ };
2
61
  //# sourceMappingURL=mud.config.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../mud.config.ts"],"sourcesContent":["import { defineStore } from \"./ts/config/v2/store\";\n\nexport default defineStore({\n namespace: \"store\",\n codegen: {\n storeImportPath: \"./src\",\n },\n userTypes: {\n ResourceId: { filePath: \"./src/ResourceId.sol\", type: \"bytes32\" },\n FieldLayout: { filePath: \"./src/FieldLayout.sol\", type: \"bytes32\" },\n Schema: { filePath: \"./src/Schema.sol\", type: \"bytes32\" },\n },\n tables: {\n StoreHooks: {\n schema: {\n tableId: \"ResourceId\",\n hooks: \"bytes21[]\",\n },\n key: [\"tableId\"],\n },\n Tables: {\n schema: {\n tableId: \"ResourceId\",\n fieldLayout: \"FieldLayout\",\n keySchema: \"Schema\",\n valueSchema: \"Schema\",\n abiEncodedKeyNames: \"bytes\",\n abiEncodedFieldNames: \"bytes\",\n },\n key: [\"tableId\"],\n },\n ResourceIds: {\n schema: {\n resourceId: \"ResourceId\",\n exists: \"bool\",\n },\n key: [\"resourceId\"],\n },\n // This is generic, codegen-only table used by `filterFromList` in `Hook.sol`\n Hooks: {\n schema: {\n resourceId: \"ResourceId\",\n hooks: \"bytes21[]\",\n },\n key: [\"resourceId\"],\n codegen: {\n tableIdArgument: true,\n },\n deploy: {\n disabled: true,\n },\n },\n },\n});\n"],"mappings":"wCAEA,IAAOA,EAAQC,EAAY,CACzB,UAAW,QACX,QAAS,CACP,gBAAiB,OACnB,EACA,UAAW,CACT,WAAY,CAAE,SAAU,uBAAwB,KAAM,SAAU,EAChE,YAAa,CAAE,SAAU,wBAAyB,KAAM,SAAU,EAClE,OAAQ,CAAE,SAAU,mBAAoB,KAAM,SAAU,CAC1D,EACA,OAAQ,CACN,WAAY,CACV,OAAQ,CACN,QAAS,aACT,MAAO,WACT,EACA,IAAK,CAAC,SAAS,CACjB,EACA,OAAQ,CACN,OAAQ,CACN,QAAS,aACT,YAAa,cACb,UAAW,SACX,YAAa,SACb,mBAAoB,QACpB,qBAAsB,OACxB,EACA,IAAK,CAAC,SAAS,CACjB,EACA,YAAa,CACX,OAAQ,CACN,WAAY,aACZ,OAAQ,MACV,EACA,IAAK,CAAC,YAAY,CACpB,EAEA,MAAO,CACL,OAAQ,CACN,WAAY,aACZ,MAAO,WACT,EACA,IAAK,CAAC,YAAY,EAClB,QAAS,CACP,gBAAiB,EACnB,EACA,OAAQ,CACN,SAAU,EACZ,CACF,CACF,CACF,CAAC","names":["mud_config_default","defineStore"]}
1
+ {"version":3,"sources":["../mud.config.ts"],"sourcesContent":["import { defineStore } from \"./ts/config/v2/store\";\n\nexport default defineStore({\n namespace: \"store\",\n codegen: {\n storeImportPath: \"./src\",\n },\n userTypes: {\n ResourceId: { filePath: \"./src/ResourceId.sol\", type: \"bytes32\" },\n FieldLayout: { filePath: \"./src/FieldLayout.sol\", type: \"bytes32\" },\n Schema: { filePath: \"./src/Schema.sol\", type: \"bytes32\" },\n },\n tables: {\n StoreHooks: {\n schema: {\n tableId: \"ResourceId\",\n hooks: \"bytes21[]\",\n },\n key: [\"tableId\"],\n },\n Tables: {\n schema: {\n tableId: \"ResourceId\",\n fieldLayout: \"FieldLayout\",\n keySchema: \"Schema\",\n valueSchema: \"Schema\",\n abiEncodedKeyNames: \"bytes\",\n abiEncodedFieldNames: \"bytes\",\n },\n key: [\"tableId\"],\n },\n ResourceIds: {\n schema: {\n resourceId: \"ResourceId\",\n exists: \"bool\",\n },\n key: [\"resourceId\"],\n },\n // This is generic, codegen-only table used by `filterFromList` in `Hook.sol`\n Hooks: {\n schema: {\n resourceId: \"ResourceId\",\n hooks: \"bytes21[]\",\n },\n key: [\"resourceId\"],\n codegen: {\n tableIdArgument: true,\n },\n deploy: {\n disabled: true,\n },\n },\n },\n});\n"],"mappings":";;;;;AAEA,IAAO,qBAAQ,YAAY;AAAA,EACzB,WAAW;AAAA,EACX,SAAS;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,WAAW;AAAA,IACT,YAAY,EAAE,UAAU,wBAAwB,MAAM,UAAU;AAAA,IAChE,aAAa,EAAE,UAAU,yBAAyB,MAAM,UAAU;AAAA,IAClE,QAAQ,EAAE,UAAU,oBAAoB,MAAM,UAAU;AAAA,EAC1D;AAAA,EACA,QAAQ;AAAA,IACN,YAAY;AAAA,MACV,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,OAAO;AAAA,MACT;AAAA,MACA,KAAK,CAAC,SAAS;AAAA,IACjB;AAAA,IACA,QAAQ;AAAA,MACN,QAAQ;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,QACb,WAAW;AAAA,QACX,aAAa;AAAA,QACb,oBAAoB;AAAA,QACpB,sBAAsB;AAAA,MACxB;AAAA,MACA,KAAK,CAAC,SAAS;AAAA,IACjB;AAAA,IACA,aAAa;AAAA,MACX,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,QAAQ;AAAA,MACV;AAAA,MACA,KAAK,CAAC,YAAY;AAAA,IACpB;AAAA;AAAA,IAEA,OAAO;AAAA,MACL,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAAA,MACA,KAAK,CAAC,YAAY;AAAA,MAClB,SAAS;AAAA,QACP,iBAAiB;AAAA,MACnB;AAAA,MACA,QAAQ;AAAA,QACN,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/store",
3
- "version": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77",
3
+ "version": "2.2.18",
4
4
  "description": "Store",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,10 +42,10 @@
42
42
  "abitype": "1.0.6",
43
43
  "arktype": "2.0.0-beta.6",
44
44
  "debug": "^4.3.4",
45
- "@latticexyz/common": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77",
46
- "@latticexyz/config": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77",
47
- "@latticexyz/protocol-parser": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77",
48
- "@latticexyz/schema-type": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77"
45
+ "@latticexyz/common": "2.2.18",
46
+ "@latticexyz/config": "2.2.18",
47
+ "@latticexyz/protocol-parser": "2.2.18",
48
+ "@latticexyz/schema-type": "2.2.18"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/debug": "^4.1.7",
@@ -54,8 +54,8 @@
54
54
  "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
55
55
  "solhint": "^3.3.7",
56
56
  "viem": "2.21.19",
57
- "@latticexyz/abi-ts": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77",
58
- "@latticexyz/gas-report": "2.2.18-ebe1aea8d4afb690ce1c7c2bcb42dc0f1faf6e77"
57
+ "@latticexyz/abi-ts": "2.2.18",
58
+ "@latticexyz/gas-report": "2.2.18"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "viem": "2.x"
@@ -1,2 +0,0 @@
1
- var i="event HelloStore(bytes32 indexed storeVersion)",t="event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)",o="event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)",s="event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)",n="event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)",e=[t,o,s,n];import{parseAbi as r}from"abitype";var p=r(e);export{i as a,t as b,o as c,s as d,n as e,e as f,p as g};
2
- //# sourceMappingURL=chunk-4TACS4IT.js.map
@@ -1,2 +0,0 @@
1
- function c(e,t){return typeof e=="object"&&e!=null&&o(e,t)?e[t]:void 0}function V(e,t){return t.length?V(c(e,t[0]),t.slice(1)):e}function o(e,t){return typeof e=="object"&&e!==null&&e.hasOwnProperty(t)}function r(e){return e!=null&&typeof e=="object"}function i(e,t){let s=[...new Set([...Object.keys(e),...Object.keys(t)])];return Object.fromEntries(s.map(n=>[n,typeof e[n]>"u"?t[n]:e[n]]))}var b={storeImportPath:"@latticexyz/store/src",userTypesFilename:"common.sol",outputDirectory:"codegen",indexFilename:"index.sol"},d={outputDirectory:"tables",tableIdArgument:!1,storeArgument:!1},O={disabled:!1},x={namespaceLabel:"",type:"table"},T={sourceDirectory:"src",namespace:""};import{schemaAbiTypes as W}from"@latticexyz/schema-type/internal";var de={types:{}},a={types:Object.fromEntries(W.map(e=>[e,e]))};function u(e,t){return{types:{...e.types,...t}}}import{fixedArrayToArray as J,isFixedArrayAbiType as S}from"@latticexyz/schema-type/internal";function h(e,t=a){if(!r(e))throw new Error(`Expected schema, received ${JSON.stringify(e)}`);for(let s of Object.values(e))if(!S(s)&&!o(t.types,s))throw new Error(`"${String(s)}" is not a valid type in this scope.`)}function k(e,t=a){return Object.fromEntries(Object.entries(e).map(([s,n])=>[s,{type:S(n)?J(n):t.types[n],internalType:n}]))}function he(e,t=a){return h(e,t),k(e,t)}function v(e,t=a){return typeof e=="object"&&e!=null&&Object.values(e).every(s=>S(s)||o(t.types,s))}import{isStaticAbiType as L}from"@latticexyz/schema-type/internal";import{resourceToHex as Y}from"@latticexyz/common";function q(e,t=a){return Object.entries(e).filter(([,s])=>o(t.types,s)&&L(t.types[s])).map(([s])=>s)}function H(e,t,s=a){return Array.isArray(e)&&e.every(n=>o(t,n)&&o(s.types,t[n])&&L(s.types[t[n]]))}function g(e,t=a,s={inStoreContext:!1}){if(typeof e!="object"||e==null)throw new Error(`Expected full table config, got \`${JSON.stringify(e)}\``);if(!o(e,"schema"))throw new Error("Missing schema input");if(h(e.schema,t),!o(e,"key")||!H(e.key,e.schema,t))throw new Error(`Invalid key. Expected \`(${q(e.schema,t).map(n=>`"${String(n)}"`).join(" | ")})[]\`, received \`${o(e,"key")&&Array.isArray(e.key)?`[${e.key.map(n=>`"${n}"`).join(", ")}]`:String(c(e,"key"))}\``);if(o(e,"namespace")&&typeof e.namespace=="string"&&e.namespace.length>14)throw new Error(`Table \`namespace\` must fit into a \`bytes14\`, but "${e.namespace}" is too long.`);if(o(e,"namespaceLabel")&&typeof e.namespaceLabel=="string"&&(!o(e,"namespace")||typeof e.namespace!="string")&&e.namespaceLabel.length>14)throw new Error(`Table \`namespace\` defaults to \`namespaceLabel\`, but must fit into a \`bytes14\` and "${e.namespaceLabel}" is too long. Provide explicit \`namespace\` override.`);if(o(e,"name")&&typeof e.name=="string"&&e.name.length>16)throw new Error(`Table \`name\` must fit into a \`bytes16\`, but "${e.name}" is too long.`);if(s.inStoreContext&&(o(e,"label")||o(e,"namespaceLabel")||o(e,"namespace")))throw new Error("Overrides of `label`, `namespaceLabel`, and `namespace` are not allowed for tables in this context.")}function R(e){let t=e.codegen;return{outputDirectory:c(t,"outputDirectory")??d.outputDirectory,tableIdArgument:c(t,"tableIdArgument")??d.tableIdArgument,storeArgument:c(t,"storeArgument")??d.storeArgument,dataStruct:c(t,"dataStruct")??Object.keys(e.schema).length-e.key.length>1}}function E(e,t=a){let s=e.namespaceLabel??x.namespaceLabel,n=e.namespace??s,p=e.label,y=e.name??p.slice(0,16),N=e.type??x.type,P=Y({type:N,namespace:n,name:y});return{label:p,type:N,namespace:n,namespaceLabel:s,name:y,tableId:P,schema:k(e.schema,t),key:e.key,codegen:R(e),deploy:i(e.deploy??{},O)}}function Le(e,t=a){return g(e,t),E(e,t)}import{isFixedArrayAbiType as z,isStaticAbiType as Q}from"@latticexyz/schema-type/internal";var Be="Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.";function D(e){return typeof e=="string"||r(e)&&Object.values(e).every(t=>typeof t=="string")}function A(e,t=a){if(typeof e=="string"){if(z(e)||o(t.types,e))return;throw new Error(`Invalid ABI type. \`${e}\` not found in scope.`)}if(typeof e=="object"&&e!==null){if(v(e,t)){if(o(e,"id")&&Q(t.types[e.id]))return;throw new Error("Invalid schema. Expected an `id` field with a static ABI type or an explicit `key` option.")}throw new Error("Invalid schema. Are you using invalid types or missing types in your scope?")}throw new Error("Invalid table shorthand.")}function l(e,t){return typeof e=="string"?{schema:{id:"bytes32",value:e},key:["id"]}:v(e,t)?{schema:e,key:["id"]}:e}function Ge(e,t=a){return A(e,t),l(e,t)}function m(e,t){if(r(e)){for(let s of Object.values(e))D(s)?A(s,t):g(s,t,{inStoreContext:!0});return}throw new Error(`Expected tables config, received ${JSON.stringify(e)}`)}function I(e,t){return Object.fromEntries(Object.entries(e).map(([s,n])=>[s,E(i(l(n,t),{label:s}),t)]))}function qe(e,t=a){return m(e,t),I(e,t)}import{mapObject as X}from"@latticexyz/common/utils";import{isSchemaAbiType as Z}from"@latticexyz/schema-type/internal";function ee(e){return X(e,t=>t.type)}function te(e){return r(e)&&Object.values(e).every(t=>Z(t.type))}function U(e,t=a){return te(e)?u(t,ee(e)):t}function F(e){if(!r(e))throw new Error(`Expected userTypes, received ${JSON.stringify(e)}`);for(let{type:t}of Object.values(e))if(!o(a.types,t))throw new Error(`"${String(t)}" is not a valid ABI type.`)}import{flatMorph as _}from"@ark/util";function se(e){return typeof e=="object"&&e!=null&&Object.values(e).every(t=>Array.isArray(t)&&t.every(s=>typeof s=="string"))}function j(e,t=a){if(se(e)){let s=Object.fromEntries(Object.keys(e).map(n=>[n,"uint8"]));return u(t,s)}return t}function ne(e){return e}function C(e){return _(e,(t,s)=>[t,_(s,(n,p)=>[p,n])])}function K(e){return r(e)?i(e,b):b}import{flatMorph as oe}from"@ark/util";function $(e,t){if(o(e,"namespace")&&typeof e.namespace=="string"&&e.namespace.length>14)throw new Error(`\`namespace\` must fit into a \`bytes14\`, but "${e.namespace}" is too long.`);o(e,"tables")&&m(e.tables,t)}function B(e,t=a){let s=e.label,n=e.namespace??s.slice(0,14);return{label:s,namespace:n,tables:I(oe(e.tables??{},(p,y)=>[p,i(l(y,t),{namespace:n,namespaceLabel:s})]),t)}}import{flatMorph as ae}from"@ark/util";import{groupBy as pe}from"@latticexyz/common/utils";function w(e,t){if(!r(e))throw new Error(`Expected namespaces, received ${JSON.stringify(e)}`);for(let s of Object.values(e))$(s,t)}function f(e,t){if(!r(e))throw new Error(`Expected namespaces config, received ${JSON.stringify(e)}`);let s=ae(e,(p,y)=>[p,B(i(y,{label:p}),t)]),n=Array.from(pe(Object.values(s),p=>p.namespace).entries()).filter(([,p])=>p.length>1).map(([p])=>p);if(n.length>0)throw new Error(`Found namespaces defined more than once in config: ${n.join(", ")}`);return s}function vt(e,t=a){return w(e,t),f(e,t)}function G(e){return Object.fromEntries(Object.entries(e.namespaces).flatMap(([t,s])=>Object.entries(s.tables).map(([n,p])=>[t===""?n:`${t}__${n}`,p])))}function M(e){return j(c(e,"enums"),U(c(e,"userTypes")))}function re(e){let t=M(e);if(o(e,"namespaces")){if(o(e,"namespace")||o(e,"tables"))throw new Error("Cannot use `namespaces` with `namespace` or `tables` keys.");w(e.namespaces,t)}if(o(e,"namespace")&&typeof e.namespace=="string"&&e.namespace.length>14)throw new Error(`\`namespace\` must fit into a \`bytes14\`, but "${e.namespace}" is too long.`);o(e,"tables")&&m(e.tables,t),o(e,"userTypes")&&F(e.userTypes)}function ce(e){let t=M(e),s=e.namespace??T.namespace,n=e.namespaces?{multipleNamespaces:!0,namespace:null,namespaces:f(e.namespaces,t)}:{multipleNamespaces:!1,namespace:s,namespaces:f({[s]:e},t)},p=G(n);return{...n,tables:p,sourceDirectory:e.sourceDirectory??T.sourceDirectory,userTypes:e.userTypes??{},enums:e.enums??{},enumValues:C(e.enums??{}),codegen:K(e.codegen)}}function Ft(e){return re(e),ce(e)}export{c as a,V as b,o as c,r as d,i as e,b as f,d as g,O as h,x as i,T as j,de as k,a as l,u as m,h as n,k as o,he as p,v as q,H as r,g as s,R as t,E as u,Le as v,Be as w,D as x,A as y,l as z,Ge as A,m as B,I as C,qe as D,ee as E,te as F,U as G,F as H,j as I,ne as J,C as K,K as L,$ as M,B as N,w as O,f as P,vt as Q,G as R,M as S,re as T,ce as U,Ft as V};
2
- //# sourceMappingURL=chunk-5YJ4WITG.js.map