@latticexyz/store 3.0.0-main-3440a86b5 → 3.0.0-main-69eb63b59

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 (65) hide show
  1. package/dist/chunk-3PAPLPW2.js +2 -0
  2. package/dist/chunk-3PAPLPW2.js.map +1 -0
  3. package/dist/codegen.d.ts +28 -14
  4. package/dist/codegen.js +177 -177
  5. package/dist/codegen.js.map +1 -1
  6. package/dist/config/v2.d.ts +3 -3
  7. package/dist/config/v2.js +1 -1
  8. package/dist/index.d.ts +3 -3
  9. package/dist/index.js +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/{output-12804d29.d.ts → input-e69ffb2f.d.ts} +93 -94
  12. package/dist/mud.config.d.ts +238 -110
  13. package/dist/mud.config.js +1 -1
  14. package/dist/mud.config.js.map +1 -1
  15. package/dist/namespacedTables-264f21b1.d.ts +147 -0
  16. package/dist/store-3b37a8c0.d.ts +72 -0
  17. package/out/Callbacks.sol/Callbacks.json +1 -1
  18. package/out/Callbacks.t.sol/CallbacksTest.json +1 -1
  19. package/out/Gas.t.sol/GasTest.json +1 -1
  20. package/out/Gas.t.sol/SolidityStorage.json +1 -1
  21. package/out/Gas.t.sol/SomeContract.json +1 -1
  22. package/out/GasStorageLoad.t.sol/GasStorageLoadTest.json +1 -1
  23. package/out/Hook.sol/HookInstance.json +1 -1
  24. package/out/Hook.sol/HookLib.json +1 -1
  25. package/out/Hook.t.sol/HookTest.json +1 -1
  26. package/out/Hooks.sol/Hooks.json +1 -1
  27. package/out/KeyEncoding.sol/KeyEncoding.json +1 -1
  28. package/out/KeyEncoding.t.sol/KeyEncodingTest.json +1 -1
  29. package/out/MirrorSubscriber.sol/MirrorSubscriber.json +1 -1
  30. package/out/Mixed.sol/Mixed.json +1 -1
  31. package/out/Mixed.t.sol/MixedTest.json +1 -1
  32. package/out/ResourceIds.sol/ResourceIds.json +1 -1
  33. package/out/Store.sol/Store.json +1 -1
  34. package/out/StoreCore.sol/StoreCore.json +1 -1
  35. package/out/StoreCore.sol/StoreCoreInternal.json +1 -1
  36. package/out/StoreCore.t.sol/StoreCoreTest.json +1 -1
  37. package/out/StoreCoreDynamic.t.sol/StoreCoreDynamicTest.json +1 -1
  38. package/out/StoreCoreGas.t.sol/StoreCoreGasTest.json +1 -1
  39. package/out/StoreHook.t.sol/StoreHookTest.json +1 -1
  40. package/out/StoreHooks.sol/StoreHooks.json +1 -1
  41. package/out/StoreHooks.t.sol/StoreHooksTest.json +1 -1
  42. package/out/StoreHooksColdLoad.t.sol/StoreHooksColdLoadTest.json +1 -1
  43. package/out/StoreKernel.sol/StoreKernel.json +1 -1
  44. package/out/StoreMock.sol/StoreMock.json +1 -1
  45. package/out/StoreMock.t.sol/StoreMockTest.json +1 -1
  46. package/out/StoreRead.sol/StoreRead.json +1 -1
  47. package/out/StoreSwitch.sol/StoreSwitch.json +1 -1
  48. package/out/StoreSwitch.t.sol/MockSystem.json +1 -1
  49. package/out/StoreSwitch.t.sol/StoreSwitchTest.json +1 -1
  50. package/out/StoreSwitch.t.sol/StoreSwitchTestStore.json +1 -1
  51. package/out/Tables.sol/Tables.json +1 -1
  52. package/out/Vector2.sol/Vector2.json +1 -1
  53. package/out/Vector2.t.sol/Vector2Test.json +1 -1
  54. package/out/build-info/{ab717ad6a3f348702f22d62ec82363af.json → 946dc2faf2e29137d1fd87e41e62942e.json} +1 -1
  55. package/package.json +7 -7
  56. package/src/codegen/tables/Hooks.sol +1 -1
  57. package/src/codegen/tables/ResourceIds.sol +1 -1
  58. package/src/codegen/tables/StoreHooks.sol +1 -1
  59. package/src/codegen/tables/Tables.sol +3 -3
  60. package/dist/chunk-ACZGBP2R.js +0 -2
  61. package/dist/chunk-ACZGBP2R.js.map +0 -1
  62. package/dist/chunk-AHN74BAP.js +0 -2
  63. package/dist/chunk-AHN74BAP.js.map +0 -1
  64. package/dist/generics-627f4c31.d.ts +0 -29
  65. package/dist/storeWithShorthands-fc46d9a7.d.ts +0 -219
package/dist/codegen.js CHANGED
@@ -1,262 +1,262 @@
1
- import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,renderWithStore as L}from"@latticexyz/common/codegen";function G(e){let t=e.storeArgument,{_typedTableId:r,_typedKeyArgs:n,_keyTupleDefinition:o}=ae(e),a="";for(let[c,i]of e.fields.entries()){if(!e.withDynamicFieldMethods&&i.isDynamic)continue;let m=`${i.typeWithLocation} ${i.name}`;if(e.withGetters&&(a+=b(e.withSuffixlessFieldMethods,i.name,d=>L(t,({_typedStore:s,_store:u,_commentSuffix:p,_methodNamePrefix:h})=>`
1
+ import{renderArguments as S,renderCommonData as se,renderWithFieldSuffix as _,renderWithStore as D}from"@latticexyz/common/codegen";function K(e){let t=e.storeArgument,{_typedTableId:n,_typedKeyArgs:r,_keyTupleDefinition:s}=se(e),a="";for(let[i,d]of e.fields.entries()){if(!e.withDynamicFieldMethods&&d.isDynamic)continue;let y=`${d.typeWithLocation} ${d.name}`;if(e.withGetters&&(a+=_(e.withSuffixlessFieldMethods,d.name,o=>D(t,({_typedStore:c,_store:p,_commentSuffix:l,_methodNamePrefix:h})=>`
2
2
  /**
3
- * @notice Get ${i.name}${p}.
3
+ * @notice Get ${d.name}${l}.
4
4
  */
5
- function ${h}get${d}(${S([s,r,n])}) internal view returns (${m}) {
6
- ${o}
7
- ${i.isDynamic?`bytes memory _blob = ${u}.getDynamicField(
5
+ function ${h}get${o}(${S([c,n,r])}) internal view returns (${y}) {
6
+ ${s}
7
+ ${d.isDynamic?`bytes memory _blob = ${p}.getDynamicField(
8
8
  _tableId,
9
9
  _keyTuple,
10
- ${c-e.staticFields.length}
11
- );`:`bytes32 _blob = ${u}.getStaticField(
10
+ ${i-e.staticFields.length}
11
+ );`:`bytes32 _blob = ${p}.getStaticField(
12
12
  _tableId,
13
13
  _keyTuple,
14
- ${c},
14
+ ${i},
15
15
  _fieldLayout
16
16
  );`}
17
- return ${O(i)};
17
+ return ${N(d)};
18
18
  }
19
- `))),a+=b(e.withSuffixlessFieldMethods,i.name,d=>L(t,({_typedStore:s,_store:u,_commentSuffix:p,_methodNamePrefix:h})=>{let f=S([s,r,n,m]),l=i.isDynamic?"setDynamicField":"setStaticField",y=A(i),g=i.isDynamic?`_tableId, _keyTuple, ${c-e.staticFields.length}, ${y}`:`_tableId, _keyTuple, ${c}, ${y}, _fieldLayout`;return`
19
+ `))),a+=_(e.withSuffixlessFieldMethods,d.name,o=>D(t,({_typedStore:c,_store:p,_commentSuffix:l,_methodNamePrefix:h})=>{let f=S([c,n,r,y]),m=d.isDynamic?"setDynamicField":"setStaticField",u=E(d),L=d.isDynamic?`_tableId, _keyTuple, ${i-e.staticFields.length}, ${u}`:`_tableId, _keyTuple, ${i}, ${u}, _fieldLayout`;return`
20
20
  /**
21
- * @notice Set ${i.name}${p}.
21
+ * @notice Set ${d.name}${l}.
22
22
  */
23
- function ${h}set${d}(${f}) internal {
24
- ${o}
25
- ${u}.${l}(${g});
23
+ function ${h}set${o}(${f}) internal {
24
+ ${s}
25
+ ${p}.${m}(${L});
26
26
  }
27
- `})),i.isDynamic){let d=de(i),s=c-e.staticFields.length,{typeWrappingData:u}=i;e.withGetters&&(u&&u.kind==="staticArray"?a+=b(e.withSuffixlessFieldMethods,i.name,p=>`
28
- // The length of ${i.name}
29
- uint256 constant length${p} = ${u.staticLength};
30
- `):a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
27
+ `})),d.isDynamic){let o=ce(d),c=i-e.staticFields.length,{typeWrappingData:p}=d;e.withGetters&&(p&&p.kind==="staticArray"?a+=_(e.withSuffixlessFieldMethods,d.name,l=>`
28
+ // The length of ${d.name}
29
+ uint256 constant length${l} = ${p.staticLength};
30
+ `):a+=_(e.withSuffixlessFieldMethods,d.name,l=>D(t,({_typedStore:h,_store:f,_commentSuffix:m,_methodNamePrefix:u})=>`
31
31
  /**
32
- * @notice Get the length of ${i.name}${l}.
32
+ * @notice Get the length of ${d.name}${m}.
33
33
  */
34
- function ${y}length${p}(${S([h,r,n])}) internal view returns (uint256) {
35
- ${o}
36
- uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${s});
34
+ function ${u}length${l}(${S([h,n,r])}) internal view returns (uint256) {
35
+ ${s}
36
+ uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${c});
37
37
  unchecked {
38
- return _byteLength / ${d.elementLength};
38
+ return _byteLength / ${o.elementLength};
39
39
  }
40
40
  }
41
- `)),a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
41
+ `)),a+=_(e.withSuffixlessFieldMethods,d.name,l=>D(t,({_typedStore:h,_store:f,_commentSuffix:m,_methodNamePrefix:u})=>`
42
42
  /**
43
- * @notice Get an item of ${i.name}${l}.
43
+ * @notice Get an item of ${d.name}${m}.
44
44
  * @dev Reverts with Store_IndexOutOfBounds if \`_index\` is out of bounds for the array.
45
45
  */
46
- function ${y}getItem${p}(${S([h,r,n,"uint256 _index"])}) internal view returns (${d.typeWithLocation}) {
47
- ${o}
46
+ function ${u}getItem${l}(${S([h,n,r,"uint256 _index"])}) internal view returns (${o.typeWithLocation}) {
47
+ ${s}
48
48
 
49
- ${u&&u.kind==="staticArray"&&i.arrayElement?`
50
- uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${s});
51
- uint256 dynamicLength = _byteLength / ${d.elementLength};
52
- uint256 staticLength = ${u.staticLength};
49
+ ${p&&p.kind==="staticArray"&&d.arrayElement?`
50
+ uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${c});
51
+ uint256 dynamicLength = _byteLength / ${o.elementLength};
52
+ uint256 staticLength = ${p.staticLength};
53
53
 
54
54
  if (_index < staticLength && _index >= dynamicLength) {
55
- return ${v(i.arrayElement,`bytes${i.arrayElement.staticByteLength}(new bytes(0))`)};
55
+ return ${W(d.arrayElement,`bytes${d.arrayElement.staticByteLength}(new bytes(0))`)};
56
56
  }`:""}
57
57
 
58
58
  unchecked {
59
59
  bytes memory _blob = ${f}.getDynamicFieldSlice(
60
60
  _tableId,
61
61
  _keyTuple,
62
- ${s},
63
- _index * ${d.elementLength},
64
- (_index + 1) * ${d.elementLength}
62
+ ${c},
63
+ _index * ${o.elementLength},
64
+ (_index + 1) * ${o.elementLength}
65
65
  );
66
- return ${d.decoded};
66
+ return ${o.decoded};
67
67
  }
68
68
  }
69
- `))),(!u||u.kind!=="staticArray")&&(a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
69
+ `))),(!p||p.kind!=="staticArray")&&(a+=_(e.withSuffixlessFieldMethods,d.name,l=>D(t,({_typedStore:h,_store:f,_commentSuffix:m,_methodNamePrefix:u})=>`
70
70
  /**
71
- * @notice Push ${d.title} to ${i.name}${l}.
71
+ * @notice Push ${o.title} to ${d.name}${m}.
72
72
  */
73
- function ${y}push${p}(${S([h,r,n,`${d.typeWithLocation} ${d.name}`])}) internal {
74
- ${o}
75
- ${f}.pushToDynamicField(_tableId, _keyTuple, ${s}, ${d.encoded});
73
+ function ${u}push${l}(${S([h,n,r,`${o.typeWithLocation} ${o.name}`])}) internal {
74
+ ${s}
75
+ ${f}.pushToDynamicField(_tableId, _keyTuple, ${c}, ${o.encoded});
76
76
  }
77
- `)),a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
77
+ `)),a+=_(e.withSuffixlessFieldMethods,d.name,l=>D(t,({_typedStore:h,_store:f,_commentSuffix:m,_methodNamePrefix:u})=>`
78
78
  /**
79
- * @notice Pop ${d.title} from ${i.name}${l}.
79
+ * @notice Pop ${o.title} from ${d.name}${m}.
80
80
  */
81
- function ${y}pop${p}(${S([h,r,n])}) internal {
82
- ${o}
83
- ${f}.popFromDynamicField(_tableId, _keyTuple, ${s}, ${d.elementLength});
81
+ function ${u}pop${l}(${S([h,n,r])}) internal {
82
+ ${s}
83
+ ${f}.popFromDynamicField(_tableId, _keyTuple, ${c}, ${o.elementLength});
84
84
  }
85
- `))),a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>{let g=S([h,r,n,"uint256 _index",`${d.typeWithLocation} ${d.name}`]),T=`
85
+ `))),a+=_(e.withSuffixlessFieldMethods,d.name,l=>D(t,({_typedStore:h,_store:f,_commentSuffix:m,_methodNamePrefix:u})=>{let L=S([h,n,r,"uint256 _index",`${o.typeWithLocation} ${o.name}`]),A=`
86
86
  _tableId,
87
87
  _keyTuple,
88
- ${s},
89
- uint40(_index * ${d.elementLength}),
88
+ ${c},
89
+ uint40(_index * ${o.elementLength}),
90
90
  uint40(_encoded.length),
91
91
  _encoded
92
92
  `;return`
93
93
  /**
94
- * @notice Update ${d.title} of ${i.name}${l} at \`_index\`.
94
+ * @notice Update ${o.title} of ${d.name}${m} at \`_index\`.
95
95
  */
96
- function ${y}update${p}(${g}) internal {
97
- ${o}
96
+ function ${u}update${l}(${L}) internal {
97
+ ${s}
98
98
  unchecked {
99
- bytes memory _encoded = ${d.encoded};
100
- ${f}.spliceDynamicData(${T});
99
+ bytes memory _encoded = ${o.encoded};
100
+ ${f}.spliceDynamicData(${A});
101
101
  }
102
102
  }
103
- `}))}}return a}function A(e){let t;return e.arrayElement?t="EncodeArray.encode":e.isDynamic?t="bytes":t="abi.encodePacked",`${t}(${e.typeUnwrap}(${e.name}))`}function H(e,t){let{staticByteLength:r}=e,n=`Bytes.getBytes${r}(_blob, ${t})`;return v(e,n)}function v(e,t){let{staticByteLength:r,internalTypeId:n}=e,o=r*8,a;if(n.match(/^uint\d{1,3}$/)||n==="address")a=`${n}(${t})`;else if(n.match(/^int\d{1,3}$/))a=`${n}(uint${o}(${t}))`;else if(n.match(/^bytes\d{1,2}$/))a=t;else if(n==="bool")a=`_toBool(uint8(${t}))`;else throw new Error(`Unknown value type id ${n}`);return`${e.typeWrap}(${a})`}function de(e){if(e.arrayElement){let t="_element",r={...e.arrayElement,arrayElement:void 0,name:t};return{typeWithLocation:e.arrayElement.typeWithLocation,name:t,encoded:A(r),decoded:O(r),title:"an element",elementLength:e.arrayElement.staticByteLength}}else{let t="_slice",r={...e,name:t};return{typeWithLocation:`${e.typeId} memory`,name:t,encoded:A(r),decoded:O(r),title:"a slice",elementLength:1}}}function O(e){let{isDynamic:t,arrayElement:r}=e;return r?`${e.typeWrap}(
104
- SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_${r.internalTypeId}()
105
- )`:t?`${e.typeWrap}(${e.internalTypeId}(_blob))`:v(e,`bytes${e.staticByteLength}(_blob)`)}import{renderArguments as $,renderCommonData as Y,renderList as K,renderWithStore as F}from"@latticexyz/common/codegen";function X(e){let{structName:t,storeArgument:r}=e,{_typedTableId:n,_typedKeyArgs:o,_keyTupleDefinition:a}=Y(e),c="";return e.withGetters&&(c+=F(r,({_typedStore:i,_store:m,_commentSuffix:d,_methodNamePrefix:s})=>`
103
+ `}))}}return a}function E(e){let t;return e.arrayElement?t="EncodeArray.encode":e.isDynamic?t="bytes":t="abi.encodePacked",`${t}(${e.typeUnwrap}(${e.name}))`}function q(e,t){let{staticByteLength:n}=e,r=`Bytes.getBytes${n}(_blob, ${t})`;return W(e,r)}function W(e,t){let{staticByteLength:n,internalTypeId:r}=e,s=n*8,a;if(r.match(/^uint\d{1,3}$/)||r==="address")a=`${r}(${t})`;else if(r.match(/^int\d{1,3}$/))a=`${r}(uint${s}(${t}))`;else if(r.match(/^bytes\d{1,2}$/))a=t;else if(r==="bool")a=`_toBool(uint8(${t}))`;else throw new Error(`Unknown value type id ${r}`);return`${e.typeWrap}(${a})`}function ce(e){if(e.arrayElement){let t="_element",n={...e.arrayElement,arrayElement:void 0,name:t};return{typeWithLocation:e.arrayElement.typeWithLocation,name:t,encoded:E(n),decoded:N(n),title:"an element",elementLength:e.arrayElement.staticByteLength}}else{let t="_slice",n={...e,name:t};return{typeWithLocation:`${e.typeId} memory`,name:t,encoded:E(n),decoded:N(n),title:"a slice",elementLength:1}}}function N(e){let{isDynamic:t,arrayElement:n}=e;return n?`${e.typeWrap}(
104
+ SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_${n.internalTypeId}()
105
+ )`:t?`${e.typeWrap}(${e.internalTypeId}(_blob))`:W(e,`bytes${e.staticByteLength}(_blob)`)}import{renderArguments as g,renderCommonData as V,renderList as Y,renderWithStore as k}from"@latticexyz/common/codegen";function Z(e){let{structName:t,storeArgument:n}=e,{_typedTableId:r,_typedKeyArgs:s,_keyTupleDefinition:a}=V(e),i="";return e.withGetters&&(i+=k(n,({_typedStore:d,_store:y,_commentSuffix:o,_methodNamePrefix:c})=>`
106
106
  /**
107
- * @notice Get the full data${d}.
107
+ * @notice Get the full data${o}.
108
108
  */
109
- function ${s}get(${$([i,n,o])}) internal view returns (${se(e)}) {
109
+ function ${c}get(${g([d,r,s])}) internal view returns (${le(e)}) {
110
110
  ${a}
111
111
 
112
112
  (
113
113
  bytes memory _staticData,
114
114
  EncodedLengths _encodedLengths,
115
115
  bytes memory _dynamicData
116
- ) = ${m}.getRecord(_tableId, _keyTuple, _fieldLayout);
116
+ ) = ${y}.getRecord(_tableId, _keyTuple, _fieldLayout);
117
117
  return decode(_staticData, _encodedLengths, _dynamicData);
118
118
  }
119
- `)),c+=F(r,({_typedStore:i,_store:m,_commentSuffix:d,_methodNamePrefix:s,_useExplicitFieldLayout:u})=>{let p=$([i,n,o,$(e.fields.map(({name:f,typeWithLocation:l})=>`${l} ${f}`))]),h="_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData"+(u?", _fieldLayout":"");return`
119
+ `)),i+=k(n,({_typedStore:d,_store:y,_commentSuffix:o,_methodNamePrefix:c,_useExplicitFieldLayout:p})=>{let l=g([d,r,s,g(e.fields.map(({name:f,typeWithLocation:m})=>`${m} ${f}`))]),h="_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData"+(p?", _fieldLayout":"");return`
120
120
  /**
121
- * @notice Set the full data using individual values${d}.
121
+ * @notice Set the full data using individual values${o}.
122
122
  */
123
- function ${s}set(${p}) internal {
124
- ${R(e)}
123
+ function ${c}set(${l}) internal {
124
+ ${w(e)}
125
125
 
126
126
  ${a}
127
127
 
128
- ${m}.setRecord(${h});
128
+ ${y}.setRecord(${h});
129
129
  }
130
- `}),t!==void 0&&(c+=F(r,({_typedStore:i,_store:m,_commentSuffix:d,_methodNamePrefix:s,_useExplicitFieldLayout:u})=>{let p=$([i,n,o,`${t} memory _table`]),h="_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData"+(u?", _fieldLayout":"");return`
130
+ `}),t!==void 0&&(i+=k(n,({_typedStore:d,_store:y,_commentSuffix:o,_methodNamePrefix:c,_useExplicitFieldLayout:p})=>{let l=g([d,r,s,`${t} memory _table`]),h="_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData"+(p?", _fieldLayout":"");return`
131
131
  /**
132
- * @notice Set the full data using the data struct${d}.
132
+ * @notice Set the full data using the data struct${o}.
133
133
  */
134
- function ${s}set(${p}) internal {
135
- ${R(e,"_table.")}
134
+ function ${c}set(${l}) internal {
135
+ ${w(e,"_table.")}
136
136
 
137
137
  ${a}
138
138
 
139
- ${m}.setRecord(${h});
139
+ ${y}.setRecord(${h});
140
140
  }
141
- `})),c+=ce(e),c}function R(e,t=""){let r="";return e.staticFields.length>0?r+=`
141
+ `})),i+=me(e),i}function w(e,t=""){let n="";return e.staticFields.length>0?n+=`
142
142
  bytes memory _staticData = encodeStatic(
143
- ${$(e.staticFields.map(({name:n})=>`${t}${n}`))}
143
+ ${g(e.staticFields.map(({name:r})=>`${t}${r}`))}
144
144
  );
145
- `:r+="bytes memory _staticData;",e.dynamicFields.length>0?r+=`
145
+ `:n+="bytes memory _staticData;",e.dynamicFields.length>0?n+=`
146
146
  EncodedLengths _encodedLengths = encodeLengths(
147
- ${$(e.dynamicFields.map(({name:n})=>`${t}${n}`))}
147
+ ${g(e.dynamicFields.map(({name:r})=>`${t}${r}`))}
148
148
  );
149
149
  bytes memory _dynamicData = encodeDynamic(
150
- ${$(e.dynamicFields.map(({name:n})=>`${t}${n}`))}
150
+ ${g(e.dynamicFields.map(({name:r})=>`${t}${r}`))}
151
151
  );
152
- `:r+=`
152
+ `:n+=`
153
153
  EncodedLengths _encodedLengths;
154
154
  bytes memory _dynamicData;
155
- `,r}function V(e){let{storeArgument:t}=e,{_typedTableId:r,_typedKeyArgs:n,_keyTupleDefinition:o}=Y(e);return F(t,({_typedStore:a,_store:c,_commentSuffix:i,_methodNamePrefix:m,_useExplicitFieldLayout:d})=>{let s=$([a,r,n]),u="_tableId, _keyTuple"+(d?", _fieldLayout":"");return`
155
+ `,n}function z(e){let{storeArgument:t}=e,{_typedTableId:n,_typedKeyArgs:r,_keyTupleDefinition:s}=V(e);return k(t,({_typedStore:a,_store:i,_commentSuffix:d,_methodNamePrefix:y,_useExplicitFieldLayout:o})=>{let c=g([a,n,r]),p="_tableId, _keyTuple"+(o?", _fieldLayout":"");return`
156
156
  /**
157
- * @notice Delete all data for given keys${i}.
157
+ * @notice Delete all data for given keys${d}.
158
158
  */
159
- function ${m}deleteRecord(${s}) internal {
160
- ${o}
161
- ${c}.deleteRecord(${u});
159
+ function ${y}deleteRecord(${c}) internal {
160
+ ${s}
161
+ ${i}.deleteRecord(${p});
162
162
  }
163
- `})}function ce({structName:e,fields:t,staticFields:r,dynamicFields:n}){let o=e?`${e} memory _table`:$(t.map(({name:d,typeWithLocation:s})=>`${s} ${d}`)),a=e?"_table.":"",c=r.map(()=>0),i=0;for(let[d,s]of r.entries())c[d]=i,i+=s.staticByteLength;let m="";return r.length>0&&(m+=`
163
+ `})}function me({structName:e,fields:t,staticFields:n,dynamicFields:r}){let s=e?`${e} memory _table`:g(t.map(({name:o,typeWithLocation:c})=>`${c} ${o}`)),a=e?"_table.":"",i=n.map(()=>0),d=0;for(let[o,c]of n.entries())i[o]=d,d+=c.staticByteLength;let y="";return n.length>0&&(y+=`
164
164
  /**
165
165
  * @notice Decode the tightly packed blob of static data using this table's field layout.
166
166
  */
167
- function decodeStatic(bytes memory _blob) internal pure returns (${$(r.map(({name:d,typeWithLocation:s})=>`${s} ${d}`))}) {
168
- ${K(r,(d,s)=>`
169
- ${d.name} = ${H(d,c[s])};
167
+ function decodeStatic(bytes memory _blob) internal pure returns (${g(n.map(({name:o,typeWithLocation:c})=>`${c} ${o}`))}) {
168
+ ${Y(n,(o,c)=>`
169
+ ${o.name} = ${q(o,i[c])};
170
170
  `)}
171
171
  }
172
- `),n.length>0&&(m+=`
172
+ `),r.length>0&&(y+=`
173
173
  /**
174
174
  * @notice Decode the tightly packed blob of dynamic data using the encoded lengths.
175
175
  */
176
- function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${$(n.map(({name:d,typeWithLocation:s})=>`${s} ${d}`))}) {
177
- ${K(n,(d,s)=>s===0?`
176
+ function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${g(r.map(({name:o,typeWithLocation:c})=>`${c} ${o}`))}) {
177
+ ${Y(r,(o,c)=>c===0?`
178
178
  uint256 _start;
179
179
  uint256 _end;
180
180
  unchecked {
181
- _end = _encodedLengths.atIndex(${s});
181
+ _end = _encodedLengths.atIndex(${c});
182
182
  }
183
- ${d.name} = ${q(d)};
183
+ ${o.name} = ${X(o)};
184
184
  `:`
185
185
  _start = _end;
186
186
  unchecked {
187
- _end += _encodedLengths.atIndex(${s});
187
+ _end += _encodedLengths.atIndex(${c});
188
188
  }
189
- ${d.name} = ${q(d)};
189
+ ${o.name} = ${X(o)};
190
190
  `)}
191
191
  }
192
- `),m+=`
192
+ `),y+=`
193
193
  /**
194
194
  * @notice Decode the tightly packed blobs using this table's field layout.
195
- * ${r.length>0?"@param _staticData Tightly packed static fields.":""}
196
- * ${n.length>0?"@param _encodedLengths Encoded lengths of dynamic fields.":""}
197
- * ${n.length>0?"@param _dynamicData Tightly packed dynamic fields.":""}
195
+ * ${n.length>0?"@param _staticData Tightly packed static fields.":""}
196
+ * ${r.length>0?"@param _encodedLengths Encoded lengths of dynamic fields.":""}
197
+ * ${r.length>0?"@param _dynamicData Tightly packed dynamic fields.":""}
198
198
  */
199
199
  function decode(
200
- bytes memory ${r.length>0?"_staticData":""},
201
- EncodedLengths ${n.length>0?"_encodedLengths":""},
202
- bytes memory ${n.length>0?"_dynamicData":""}
203
- ) internal pure returns (${o}) {
204
- `,r.length>0&&(m+=`
205
- (${$(r.map(d=>`${a}${d.name}`))}) = decodeStatic(_staticData);
206
- `),n.length>0&&(m+=`
207
- (${$(n.map(d=>`${a}${d.name}`))}) = decodeDynamic(_encodedLengths, _dynamicData);
208
- `),m+=`
200
+ bytes memory ${n.length>0?"_staticData":""},
201
+ EncodedLengths ${r.length>0?"_encodedLengths":""},
202
+ bytes memory ${r.length>0?"_dynamicData":""}
203
+ ) internal pure returns (${s}) {
204
+ `,n.length>0&&(y+=`
205
+ (${g(n.map(o=>`${a}${o.name}`))}) = decodeStatic(_staticData);
206
+ `),r.length>0&&(y+=`
207
+ (${g(r.map(o=>`${a}${o.name}`))}) = decodeDynamic(_encodedLengths, _dynamicData);
208
+ `),y+=`
209
209
  }
210
- `,m}function se({structName:e,fields:t}){return e?`${e} memory _table`:$(t.map(({name:r,typeWithLocation:n})=>`${n} ${r}`))}function q(e){let{typeId:t,arrayElement:r,typeWrap:n}=e;return r?`${n}(
211
- SliceLib.getSubslice(_blob, _start, _end).decodeArray_${r.typeId}()
212
- )`:`${n}(
210
+ `,y}function le({structName:e,fields:t}){return e?`${e} memory _table`:g(t.map(({name:n,typeWithLocation:r})=>`${r} ${n}`))}function X(e){let{typeId:t,arrayElement:n,typeWrap:r}=e;return n?`${r}(
211
+ SliceLib.getSubslice(_blob, _start, _end).decodeArray_${n.typeId}()
212
+ )`:`${r}(
213
213
  ${t}(
214
214
  SliceLib.getSubslice(_blob, _start, _end).toBytes()
215
215
  )
216
- )`}import{renderArguments as _,renderCommonData as he,renderList as B,renderImports as fe,renderTableId as $e,renderTypeHelpers as ge,renderWithStore as Te,renderedSolidityHeader as _e}from"@latticexyz/common/codegen";var k={TOTAL_LENGTH:240,NUM_STATIC_FIELDS:232,NUM_DYNAMIC_FIELDS:224};function Z(e){return`FieldLayout constant _fieldLayout = FieldLayout.wrap(${pe(e)});`}function pe(e){let t=e.filter(({isDynamic:c})=>!c),r=e.length-t.length,n=0n,o=0;if(e.length>28)throw new Error("FieldLayout: too many fields");if(r>5)throw new Error("FieldLayout: too many dynamic fields");for(let c=0;c<t.length;c++){let{isDynamic:i,staticByteLength:m}=e[c];if(i)throw new Error("FieldLayout: static type after dynamic type");o+=m,n|=BigInt(m)<<BigInt((31-4-c)*8)}return n|=BigInt(o)<<BigInt(k.TOTAL_LENGTH),n|=BigInt(t.length)<<BigInt(k.NUM_STATIC_FIELDS),n|=BigInt(r)<<BigInt(k.NUM_DYNAMIC_FIELDS),`0x${n.toString(16).padStart(64,"0")}`}import{keySchemaToHex as be,valueSchemaToHex as Se}from"@latticexyz/protocol-parser/internal";function z(e){let{imports:t,libraryName:r,structName:n,staticResourceData:o,storeImportPath:a,fields:c,staticFields:i,dynamicFields:m,withRecordMethods:d,storeArgument:s,keyTuple:u}=e,{_typedTableId:p,_typedKeyArgs:h,_keyTupleDefinition:f}=he(e);return`
217
- ${_e}
216
+ )`}import{renderArguments as b,renderCommonData as $e,renderList as C,renderImports as ge,renderTableId as Te,renderTypeHelpers as be,renderWithStore as _e,renderedSolidityHeader as Le,renderImportPath as T}from"@latticexyz/common/codegen";var O={TOTAL_LENGTH:240,NUM_STATIC_FIELDS:232,NUM_DYNAMIC_FIELDS:224};function J(e){return`FieldLayout constant _fieldLayout = FieldLayout.wrap(${fe(e)});`}function fe(e){let t=e.filter(({isDynamic:i})=>!i),n=e.length-t.length,r=0n,s=0;if(e.length>28)throw new Error("FieldLayout: too many fields");if(n>5)throw new Error("FieldLayout: too many dynamic fields");for(let i=0;i<t.length;i++){let{isDynamic:d,staticByteLength:y}=e[i];if(d)throw new Error("FieldLayout: static type after dynamic type");s+=y,r|=BigInt(y)<<BigInt((31-4-i)*8)}return r|=BigInt(s)<<BigInt(O.TOTAL_LENGTH),r|=BigInt(t.length)<<BigInt(O.NUM_STATIC_FIELDS),r|=BigInt(n)<<BigInt(O.NUM_DYNAMIC_FIELDS),`0x${r.toString(16).padStart(64,"0")}`}import{keySchemaToHex as Se,valueSchemaToHex as De}from"@latticexyz/protocol-parser/internal";function Q(e){let{imports:t,libraryName:n,structName:r,staticResourceData:s,storeImportPath:a,fields:i,staticFields:d,dynamicFields:y,withRecordMethods:o,storeArgument:c,keyTuple:p}=e,{_typedTableId:l,_typedKeyArgs:h,_keyTupleDefinition:f}=$e(e);return`
217
+ ${Le}
218
218
 
219
219
  // Import store internals
220
- import { IStore } from "${a}IStore.sol";
221
- import { StoreSwitch } from "${a}StoreSwitch.sol";
222
- import { StoreCore } from "${a}StoreCore.sol";
223
- import { Bytes } from "${a}Bytes.sol";
224
- import { Memory } from "${a}Memory.sol";
225
- import { SliceLib } from "${a}Slice.sol";
226
- import { EncodeArray } from "${a}tightcoder/EncodeArray.sol";
227
- import { FieldLayout } from "${a}FieldLayout.sol";
228
- import { Schema } from "${a}Schema.sol";
229
- import { EncodedLengths, EncodedLengthsLib } from "${a}EncodedLengths.sol";
230
- import { ResourceId } from "${a}ResourceId.sol";
220
+ import { IStore } from "${T(a,"IStore.sol")}";
221
+ import { StoreSwitch } from "${T(a,"StoreSwitch.sol")}";
222
+ import { StoreCore } from "${T(a,"StoreCore.sol")}";
223
+ import { Bytes } from "${T(a,"Bytes.sol")}";
224
+ import { Memory } from "${T(a,"Memory.sol")}";
225
+ import { SliceLib } from "${T(a,"Slice.sol")}";
226
+ import { EncodeArray } from "${T(a,"tightcoder/EncodeArray.sol")}";
227
+ import { FieldLayout } from "${T(a,"FieldLayout.sol")}";
228
+ import { Schema } from "${T(a,"Schema.sol")}";
229
+ import { EncodedLengths, EncodedLengthsLib } from "${T(a,"EncodedLengths.sol")}";
230
+ import { ResourceId } from "${T(a,"ResourceId.sol")}";
231
231
 
232
232
  ${t.length>0?`
233
233
  // Import user types
234
- ${fe(t)}
234
+ ${ge(t)}
235
235
  `:""}
236
236
 
237
- ${n?`
238
- struct ${n} {
239
- ${B(c,({name:l,typeId:y})=>`${y} ${l};`)}
237
+ ${r?`
238
+ struct ${r} {
239
+ ${C(i,({name:m,typeId:u})=>`${u} ${m};`)}
240
240
  }
241
241
  `:""}
242
242
 
243
- library ${r} {
244
- ${o?$e(o):""}
243
+ library ${n} {
244
+ ${s?Te(s):""}
245
245
 
246
- ${Z(c)}
246
+ ${J(i)}
247
247
 
248
- // Hex-encoded key schema of (${u.map(l=>l.internalTypeId).join(", ")})
249
- Schema constant _keySchema = Schema.wrap(${be(Object.fromEntries(u.map(l=>[l.name,l.internalTypeId])))});
250
- // Hex-encoded value schema of (${c.map(l=>l.internalTypeId).join(", ")})
251
- Schema constant _valueSchema = Schema.wrap(${Se(Object.fromEntries(c.map(l=>[l.name,l.internalTypeId])))});
248
+ // Hex-encoded key schema of (${p.map(m=>m.internalTypeId).join(", ")})
249
+ Schema constant _keySchema = Schema.wrap(${Se(Object.fromEntries(p.map(m=>[m.name,m.internalTypeId])))});
250
+ // Hex-encoded value schema of (${i.map(m=>m.internalTypeId).join(", ")})
251
+ Schema constant _valueSchema = Schema.wrap(${De(Object.fromEntries(i.map(m=>[m.name,m.internalTypeId])))});
252
252
 
253
253
  /**
254
254
  * @notice Get the table's key field names.
255
255
  * @return keyNames An array of strings with the names of key fields.
256
256
  */
257
257
  function getKeyNames() internal pure returns (string[] memory keyNames) {
258
- keyNames = new string[](${u.length});
259
- ${B(u,(l,y)=>`keyNames[${y}] = "${l.name}";`)}
258
+ keyNames = new string[](${p.length});
259
+ ${C(p,(m,u)=>`keyNames[${u}] = "${m.name}";`)}
260
260
  }
261
261
 
262
262
  /**
@@ -264,30 +264,30 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
264
264
  * @return fieldNames An array of strings with the names of value fields.
265
265
  */
266
266
  function getFieldNames() internal pure returns (string[] memory fieldNames) {
267
- fieldNames = new string[](${c.length});
268
- ${B(c,(l,y)=>`fieldNames[${y}] = "${l.name}";`)}
267
+ fieldNames = new string[](${i.length});
268
+ ${C(i,(m,u)=>`fieldNames[${u}] = "${m.name}";`)}
269
269
  }
270
270
 
271
- ${Te(s,({_typedStore:l,_store:y,_commentSuffix:g,_methodNamePrefix:T})=>`
271
+ ${_e(c,({_typedStore:m,_store:u,_commentSuffix:L,_methodNamePrefix:A})=>`
272
272
  /**
273
- * @notice Register the table with its config${g}.
273
+ * @notice Register the table with its config${L}.
274
274
  */
275
- function ${T}register(${_([l,p])}) internal {
276
- ${y}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
275
+ function ${A}register(${b([m,l])}) internal {
276
+ ${u}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
277
277
  }
278
278
  `)}
279
279
 
280
- ${G(e)}
280
+ ${K(e)}
281
281
 
282
- ${d?X(e):""}
282
+ ${o?Z(e):""}
283
283
 
284
- ${V(e)}
284
+ ${z(e)}
285
285
 
286
- ${Le(i)}
286
+ ${Ie(d)}
287
287
 
288
- ${De(m)}
288
+ ${Ae(y)}
289
289
 
290
- ${Ie(m)}
290
+ ${xe(y)}
291
291
 
292
292
  /**
293
293
  * @notice Encode all of a record's fields.
@@ -295,8 +295,8 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
295
295
  * @return The lengths of the dynamic fields (packed into a single bytes32 value).
296
296
  * @return The dynamic (variable length) data, encoded into a sequence of bytes.
297
297
  */
298
- function encode(${_(e.fields.map(({name:l,typeWithLocation:y})=>`${y} ${l}`))}) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
299
- ${R(e)}
298
+ function encode(${b(e.fields.map(({name:m,typeWithLocation:u})=>`${u} ${m}`))}) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
299
+ ${w(e)}
300
300
 
301
301
  return (_staticData, _encodedLengths, _dynamicData);
302
302
  }
@@ -304,47 +304,47 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
304
304
  /**
305
305
  * @notice Encode keys as a bytes32 array using this table's field layout.
306
306
  */
307
- function encodeKeyTuple(${_([h])}) internal pure returns (bytes32[] memory) {
307
+ function encodeKeyTuple(${b([h])}) internal pure returns (bytes32[] memory) {
308
308
  ${f}
309
309
  return _keyTuple;
310
310
  }
311
311
  }
312
312
 
313
- ${ge(e)}
314
- `}function Le(e){return e.length===0?"":`
313
+ ${be(e)}
314
+ `}function Ie(e){return e.length===0?"":`
315
315
  /**
316
316
  * @notice Tightly pack static (fixed length) data using this table's schema.
317
317
  * @return The static data, encoded into a sequence of bytes.
318
318
  */
319
- function encodeStatic(${_(e.map(({name:t,typeWithLocation:r})=>`${r} ${t}`))}) internal pure returns (bytes memory) {
320
- return abi.encodePacked(${_(e.map(({name:t})=>t))});
319
+ function encodeStatic(${b(e.map(({name:t,typeWithLocation:n})=>`${n} ${t}`))}) internal pure returns (bytes memory) {
320
+ return abi.encodePacked(${b(e.map(({name:t})=>t))});
321
321
  }
322
- `}function De(e){return e.length===0?"":`
322
+ `}function Ae(e){return e.length===0?"":`
323
323
  /**
324
324
  * @notice Tightly pack dynamic data lengths using this table's schema.
325
325
  * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value).
326
326
  */
327
- function encodeLengths(${_(e.map(({name:t,typeWithLocation:r})=>`${r} ${t}`))}) internal pure returns (EncodedLengths _encodedLengths) {
327
+ function encodeLengths(${b(e.map(({name:t,typeWithLocation:n})=>`${n} ${t}`))}) internal pure returns (EncodedLengths _encodedLengths) {
328
328
  // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits
329
329
  unchecked {
330
330
  _encodedLengths = EncodedLengthsLib.pack(
331
- ${_(e.map(({name:t,arrayElement:r})=>r?`${t}.length * ${r.staticByteLength}`:`bytes(${t}).length`))}
331
+ ${b(e.map(({name:t,arrayElement:n})=>n?`${t}.length * ${n.staticByteLength}`:`bytes(${t}).length`))}
332
332
  );
333
333
  }
334
334
  }
335
- `}function Ie(e){return e.length===0?"":`
335
+ `}function xe(e){return e.length===0?"":`
336
336
  /**
337
337
  * @notice Tightly pack dynamic (variable length) data using this table's schema.
338
338
  * @return The dynamic data, encoded into a sequence of bytes.
339
339
  */
340
- function encodeDynamic(${_(e.map(({name:t,typeWithLocation:r})=>`${r} ${t}`))}) internal pure returns (bytes memory) {
341
- return abi.encodePacked(${_(e.map(t=>A(t)))});
340
+ function encodeDynamic(${b(e.map(({name:t,typeWithLocation:n})=>`${n} ${t}`))}) internal pure returns (bytes memory) {
341
+ return abi.encodePacked(${b(e.map(t=>E(t)))});
342
342
  }
343
- `}import{renderEnums as Ae}from"@latticexyz/common/codegen";function J(e){return Ae(e.enums)}import Me from"node:fs/promises";import I from"node:path";import{formatAndWriteSolidity as P,loadAndExtractUserTypes as Ce}from"@latticexyz/common/codegen";import Fe from"path";import{SchemaTypeArrayToElement as Re}from"@latticexyz/schema-type/deprecated";import{AbiTypeToSchemaType as D,getStaticByteLength as M,SchemaType as x,SchemaTypeToAbiType as Q}from"@latticexyz/schema-type/deprecated";function ee(e){let t=e.match(/^(\w+)\[(\d+)\]$/);return t?{elementType:t[1],staticLength:Number.parseInt(t[2])}:null}function C(e,t,r){if(e in D){let o=D[e];return{schemaType:o,renderType:W(o)}}let n=ee(e);if(n){if(n.elementType in D)return Ee(e,n.elementType,n.staticLength);throw new Error("Static arrays of user types are not supported")}return xe(e,t,r)}function N(e,t,r,n){if(!(e in D||ee(e))){if(e in n){let a=n[e],c=a.importSymbol;return a.isRelativePath?{symbol:c,fromPath:a.fromPath,usedInPath:t}:{symbol:c,path:a.fromPath}}return{symbol:e,fromPath:r.codegen.userTypesFilename,usedInPath:t}}}function W(e){let t=M(e),r=t===0,n=Q[e];return{typeId:n,typeWithLocation:r?n+" memory":n,enumName:x[e],staticByteLength:t,isDynamic:r,typeWrap:"",typeUnwrap:"",internalTypeId:n}}function xe(e,t,r){if(e in t.enums){let n=x.UINT8,o=M(n),a=o===0,c=e;return{schemaType:n,renderType:{typeId:c,typeWithLocation:c,enumName:x[n],staticByteLength:o,isDynamic:a,typeWrap:`${e}`,typeUnwrap:"uint8",internalTypeId:`${Q[n]}`}}}if(e in r){if(!(e in r))throw new Error(`User type "${e}" not found in MUD config`);let n=r[e],o=n.typeId,a=D[n.internalTypeId];return{schemaType:a,renderType:{typeId:o,typeWithLocation:o,enumName:x[a],staticByteLength:M(a),isDynamic:!1,typeWrap:`${o}.wrap`,typeUnwrap:`${o}.unwrap`,internalTypeId:n.internalTypeId}}}throw new Error(`User type "${e}" does not exist`)}function Ee(e,t,r){let n=t+"[]",o=D[n];return{schemaType:o,renderType:{typeId:e,typeWithLocation:`${e} memory`,enumName:x[o],staticByteLength:0,isDynamic:!0,typeWrap:`toStaticArray_${t}_${r}`,typeUnwrap:`fromStaticArray_${t}_${r}`,typeWrappingData:{kind:"staticArray",elementType:t,staticLength:r},internalTypeId:n}}}import{getKeySchema as ke,getValueSchema as we}from"@latticexyz/protocol-parser/internal";function te(e,t){return Object.values(e.namespaces).flatMap(o=>Object.values(o.tables)).map(o=>{let a=ke(o),c=we(o),i=o.codegen.dataStruct,m=i||o.type==="offchainTable"||Object.keys(c).length>1,d=!m&&Object.keys(c).length===1,s=[],u=Object.entries(a).map(([y,g])=>{let T=g.internalType,{renderType:w}=C(T,e,t),E=N(T,o.codegen.outputDirectory,e,t);return E&&s.push(E),{...w,name:y,isDynamic:!1}}),p=Object.entries(c).map(([y,g])=>{let T=g.internalType,{renderType:w,schemaType:E}=C(T,e,t),j=N(T,o.codegen.outputDirectory,e,t);j&&s.push(j);let U=Re[E];return{...w,arrayElement:U!==void 0?W(U):void 0,name:y}}),h=p.filter(({isDynamic:y})=>!y),f=p.filter(({isDynamic:y})=>y),l=o.codegen.tableIdArgument?void 0:{namespace:o.namespace,name:o.name,offchainOnly:o.type==="offchainTable"};return{outputPath:Fe.join(o.codegen.outputDirectory,`${o.label}.sol`),tableName:o.label,renderOptions:{imports:s,libraryName:o.label,structName:i?o.label+"Data":void 0,staticResourceData:l,storeImportPath:e.codegen.storeImportPath,keyTuple:u,fields:p,staticFields:h,dynamicFields:f,withGetters:o.type==="table",withRecordMethods:m,withDynamicFieldMethods:o.type==="table",withSuffixlessFieldMethods:d,storeArgument:o.codegen.storeArgument}}})}import{posixPath as Oe,renderList as ve,renderedSolidityHeader as Be}from"@latticexyz/common/codegen";function ne(e){return`
344
- ${Be}
343
+ `}import{renderEnums as Ee}from"@latticexyz/common/codegen";function _t(e){return Ee(e.enums)}import Ue from"node:fs/promises";import B from"node:path";import{formatAndWriteSolidity as G,renderEnums as je}from"@latticexyz/common/codegen";import{renderList as Fe,renderedSolidityHeader as Re}from"@latticexyz/common/codegen";import ee from"node:path/posix";function te(e,t){return`
344
+ ${Re}
345
345
 
346
- ${ve(e,({outputPath:t,tableName:r,renderOptions:{structName:n}})=>{let o=[r];return n&&o.push(n),`import { ${o.join(", ")} } from "./${Oe(t)}";`})}
347
- `}import{mapObject as Ne}from"@latticexyz/common/utils";async function vt({rootDir:e,config:t,remappings:r}){let n=I.join(e,t.sourceDirectory,t.codegen.outputDirectory),o=Ce(Ne(t.userTypes,i=>({...i,internalType:i.type})),n,r),a=te(t,o),c=Array.from(new Set(a.map(({outputPath:i})=>I.dirname(i))));if(await Promise.all(c.map(async i=>{await Me.rm(I.join(n,i),{recursive:!0,force:!0})})),await Promise.all(a.map(async({outputPath:i,renderOptions:m})=>{let d=I.join(n,i),s=z(m);await P(s,d,"Generated table")})),a.length>0){let i=I.join(n,t.codegen.indexFilename),m=ne(a);await P(m,i,"Generated table index")}if(Object.keys(t.enums).length>0){let i=I.join(n,t.codegen.userTypesFilename),m=J(t);await P(m,i,"Generated types file")}}import{renderedSolidityHeader as We}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as Pe,staticAbiTypes as je}from"@latticexyz/schema-type/internal";import{getLeftPaddingBits as re}from"@latticexyz/common/codegen";function oe(e){return`
346
+ ${Fe(t,({outputPath:n,tableName:r,renderOptions:{structName:s}})=>{let a=[r];return s&&a.push(s),`import { ${a.join(", ")} } from "./${ee.relative(ee.dirname(e),n)}";`})}
347
+ `}import{uniqueBy as Ge}from"@latticexyz/common/utils";import ke from"node:path";function v({config:e}){return ke.join(e.sourceDirectory,e.codegen.outputDirectory,e.codegen.userTypesFilename)}import{groupBy as we}from"@latticexyz/common/utils";function ne({config:e}){let t=Object.keys(e.enums).map(a=>({type:"enum",name:a,abiType:"uint8",importPath:"./"+v({config:e})})),n=Object.entries(e.userTypes).map(([a,i])=>({type:"userType",name:a,abiType:i.type,importPath:i.filePath})),r=[...t,...n],s=Array.from(we(r,a=>a.name).entries()).filter(([,a])=>a.length>1).map(([a])=>a);if(s.length>0)throw new Error(`Found enums and user types sharing the same name: ${s.join(", ")}`);return r}import I from"path";import{SchemaTypeArrayToElement as Ne}from"@latticexyz/schema-type/deprecated";import{AbiTypeToSchemaType as F,getStaticByteLength as P,SchemaType as R,SchemaTypeToAbiType as Oe}from"@latticexyz/schema-type/deprecated";function ve(e){let t=e.match(/^(\w+)\[(\d+)\]$/);return t?{elementType:t[1],staticLength:Number.parseInt(t[2])}:null}function U(e,t){if(e in F){let s=F[e];return{schemaType:s,renderType:j(s)}}let n=ve(e);if(n){if(n.elementType in F)return Me(e,n.elementType,n.staticLength);throw new Error("Static arrays of user types are not supported")}let r=t.find(s=>s.name===e);if(!r)throw new Error(`User type "${e}" not found`);return Be(r)}function j(e){let t=P(e),n=t===0,r=Oe[e];return{typeId:r,typeWithLocation:n?r+" memory":r,enumName:R[e],staticByteLength:t,isDynamic:n,typeWrap:"",typeUnwrap:"",internalTypeId:r}}function Be(e){switch(e.type){case"enum":{let t=R.UINT8,n=P(t),r=n===0;return{schemaType:t,renderType:{typeId:e.name,typeWithLocation:e.name,enumName:R[t],staticByteLength:n,isDynamic:r,typeWrap:e.name,typeUnwrap:e.abiType,internalTypeId:e.abiType}}}case"userType":{let t=F[e.abiType];return{schemaType:t,renderType:{typeId:e.name,typeWithLocation:e.name,enumName:R[t],staticByteLength:P(t),isDynamic:!1,typeWrap:`${e.name}.wrap`,typeUnwrap:`${e.name}.unwrap`,internalTypeId:e.abiType}}}}}function Me(e,t,n){let r=t+"[]",s=F[r];return{schemaType:s,renderType:{typeId:e,typeWithLocation:`${e} memory`,enumName:R[s],staticByteLength:0,isDynamic:!0,typeWrap:`toStaticArray_${t}_${n}`,typeUnwrap:`fromStaticArray_${t}_${n}`,typeWrappingData:{kind:"staticArray",elementType:t,staticLength:n},internalTypeId:r}}}import{getKeySchema as We,getValueSchema as Ce}from"@latticexyz/protocol-parser/internal";import{isDefined as Pe}from"@latticexyz/common/utils";function re({tables:e,rootDir:t,codegenDir:n,userTypes:r,storeImportPath:s}){return e.map(i=>{let d=I.join(t,n,i.codegen.outputDirectory,`${i.label}.sol`),y=We(i),o=Ce(i),c=i.codegen.dataStruct,p=c||i.type==="offchainTable"||Object.keys(o).length>1,l=!p&&Object.keys(o).length===1,h=Object.values(i.schema).map($=>r.find(x=>x.name===$.internalType)).filter(Pe).map($=>({symbol:$.name.replace(/\..*$/,""),path:$.importPath.startsWith(".")?"./"+I.relative(I.dirname(d),I.join(t,$.importPath)):$.importPath})),f=Object.entries(y).map(([$,x])=>{let{renderType:M}=U(x.internalType,r);return{...M,name:$,isDynamic:!1}}),m=Object.entries(o).map(([$,x])=>{let{renderType:M,schemaType:de}=U(x.internalType,r),H=Ne[de];return{...M,arrayElement:H!==void 0?j(H):void 0,name:$}}),u=m.filter(({isDynamic:$})=>!$),L=m.filter(({isDynamic:$})=>$),A=i.codegen.tableIdArgument?void 0:{namespace:i.namespace,name:i.name,offchainOnly:i.type==="offchainTable"};return{outputPath:d,tableName:i.label,renderOptions:{imports:h,libraryName:i.label,structName:c?i.label+"Data":void 0,staticResourceData:A,storeImportPath:s.startsWith(".")?"./"+I.relative(I.dirname(d),I.join(t,s)):s,keyTuple:f,fields:m,staticFields:u,dynamicFields:L,withGetters:i.type==="table",withRecordMethods:p,withDynamicFieldMethods:i.type==="table",withSuffixlessFieldMethods:l,storeArgument:i.codegen.storeArgument}}})}async function Xt({rootDir:e,config:t}){let n=ne({config:t});if(Object.keys(t.enums).length>0){let r=B.join(e,v({config:t})),s=je(t.enums);await G(s,r,"Generated types file with enums")}await Promise.all(Object.values(t.namespaces).map(async r=>{let a=t.sourceDirectory,i=B.join(a,t.codegen.outputDirectory),d=Object.values(r.tables);if(d.length===0)return;let y=re({tables:d,rootDir:e,codegenDir:i,userTypes:n,storeImportPath:t.codegen.storeImportPath}),o=Ge(y.map(({outputPath:l})=>B.dirname(l)),l=>l);await Promise.all(o.map(l=>Ue.rm(l,{recursive:!0,force:!0}))),await Promise.all(y.map(async({outputPath:l,renderOptions:h})=>{let f=Q(h);return await G(f,l,"Generated table")}));let c=B.join(e,i,t.codegen.indexFilename),p=te(c,y);await G(p,c,"Generated table index")}))}import{renderedSolidityHeader as He}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as Ke,staticAbiTypes as qe}from"@latticexyz/schema-type/internal";import{getLeftPaddingBits as oe}from"@latticexyz/common/codegen";function ie(e){return`
348
348
  /**
349
349
  * @notice Decodes a slice into an array of ${e.internalTypeId}.
350
350
  * @dev Uses TightCoder for initial decoding, and then assembly for memory conversion.
@@ -359,13 +359,13 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
359
359
  bytes32[] memory _genericArray = TightCoder.decode(
360
360
  _input,
361
361
  ${e.staticByteLength},
362
- ${re(e)}
362
+ ${oe(e)}
363
363
  );
364
364
  assembly {
365
365
  _output := _genericArray
366
366
  }
367
367
  }
368
- `}function ie(e){return`
368
+ `}function ae(e){return`
369
369
 
370
370
  /**
371
371
  * @notice Encodes an array of ${e.internalTypeId} into a tightly packed bytes representation.
@@ -380,11 +380,11 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
380
380
  return TightCoder.encode(
381
381
  _genericArray,
382
382
  ${e.staticByteLength},
383
- ${re(e)}
383
+ ${oe(e)}
384
384
  );
385
385
  }
386
- `}function Ut(){return`
387
- ${We}
386
+ `}function nn(){return`
387
+ ${He}
388
388
  import { TightCoder } from "./TightCoder.sol";
389
389
  import { Slice } from "../Slice.sol";
390
390
 
@@ -395,11 +395,11 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
395
395
  * @dev This library provides functions for decoding slices into arrays of basic uint types.
396
396
  */
397
397
  library DecodeSlice {
398
- ${je.map(e=>oe({internalTypeId:e,staticByteLength:Pe[e]})).join(`
398
+ ${qe.map(e=>ie({internalTypeId:e,staticByteLength:Ke[e]})).join(`
399
399
  `)}
400
400
  }
401
- `}import{renderedSolidityHeader as Ue}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as Ge,staticAbiTypes as He}from"@latticexyz/schema-type/internal";function Yt(){return`
402
- ${Ue}
401
+ `}import{renderedSolidityHeader as Ye}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as Xe,staticAbiTypes as Ve}from"@latticexyz/schema-type/internal";function sn(){return`
402
+ ${Ye}
403
403
  import { TightCoder } from "./TightCoder.sol";
404
404
 
405
405
  /**
@@ -408,10 +408,10 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
408
408
  * @dev This library provides utilities for encoding arrays into tightly packed bytes representations.
409
409
  */
410
410
  library EncodeArray {
411
- ${He.map(e=>ie({internalTypeId:e,staticByteLength:Ge[e]})).join(`
411
+ ${Ve.map(e=>ae({internalTypeId:e,staticByteLength:Xe[e]})).join(`
412
412
  `)}
413
413
  }
414
- `}import{renderedSolidityHeader as Ke}from"@latticexyz/common/codegen";import{staticAbiTypes as qe}from"@latticexyz/schema-type/internal";function Ye({typeId:e}){return`
414
+ `}import{renderedSolidityHeader as Ze}from"@latticexyz/common/codegen";import{staticAbiTypes as ze}from"@latticexyz/schema-type/internal";function Je({typeId:e}){return`
415
415
  function testEncodeDecodeArray_${e}(
416
416
  ${e} val0,
417
417
  ${e} val1,
@@ -431,15 +431,15 @@ import{renderArguments as S,renderCommonData as ae,renderWithFieldSuffix as b,re
431
431
  assertEq(decoded[1], val1);
432
432
  assertEq(decoded[2], val2);
433
433
  }
434
- `}function zt(){return`
435
- ${Ke}
434
+ `}function yn(){return`
435
+ ${Ze}
436
436
 
437
437
  import { Test } from "forge-std/Test.sol";
438
438
  import { EncodeArray } from "../../src/tightcoder/EncodeArray.sol";
439
439
  import { SliceLib } from "../../src/Slice.sol";
440
440
 
441
441
  contract TightCoderAutoTest is Test {
442
- ${qe.map(e=>Ye({typeId:e})).join("")}
442
+ ${ze.map(e=>Je({typeId:e})).join("")}
443
443
  }
444
- `}export{W as getSchemaTypeInfo,te as getTableOptions,xe as getUserTypeInfo,N as importForAbiOrUserType,Ut as renderDecodeSlice,H as renderDecodeValueType,V as renderDeleteRecordMethods,Yt as renderEncodeArray,A as renderEncodeFieldSingle,G as renderFieldMethods,R as renderRecordData,X as renderRecordMethods,z as renderTable,zt as renderTightCoderAutoTest,Ye as renderTightCoderAutoTestFunction,oe as renderTightCoderDecode,ie as renderTightCoderEncode,J as renderTypesFromConfig,C as resolveAbiOrUserType,vt as tablegen};
444
+ `}export{j as getSchemaTypeInfo,re as getTableOptions,Be as getUserTypeInfo,nn as renderDecodeSlice,q as renderDecodeValueType,z as renderDeleteRecordMethods,sn as renderEncodeArray,E as renderEncodeFieldSingle,K as renderFieldMethods,w as renderRecordData,Z as renderRecordMethods,Q as renderTable,yn as renderTightCoderAutoTest,Je as renderTightCoderAutoTestFunction,ie as renderTightCoderDecode,ae as renderTightCoderEncode,_t as renderTypesFromConfig,U as resolveAbiOrUserType,Xt as tablegen};
445
445
  //# sourceMappingURL=codegen.js.map