@latticexyz/store 3.0.0-main-69e23a36b → 3.0.0-main-2da9e48cd
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/codegen.js +163 -163
- package/dist/codegen.js.map +1 -1
- package/package.json +7 -7
package/dist/codegen.js
CHANGED
@@ -1,113 +1,113 @@
|
|
1
|
-
import{renderArguments as S,renderCommonData as
|
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})=>`
|
2
2
|
/**
|
3
|
-
* @notice Get ${
|
3
|
+
* @notice Get ${i.name}${p}.
|
4
4
|
*/
|
5
|
-
function ${h}get${
|
6
|
-
${
|
7
|
-
${
|
5
|
+
function ${h}get${d}(${S([s,r,n])}) internal view returns (${m}) {
|
6
|
+
${o}
|
7
|
+
${i.isDynamic?`bytes memory _blob = ${u}.getDynamicField(
|
8
8
|
_tableId,
|
9
9
|
_keyTuple,
|
10
10
|
${c-e.staticFields.length}
|
11
|
-
);`:`bytes32 _blob = ${
|
11
|
+
);`:`bytes32 _blob = ${u}.getStaticField(
|
12
12
|
_tableId,
|
13
13
|
_keyTuple,
|
14
14
|
${c},
|
15
15
|
_fieldLayout
|
16
16
|
);`}
|
17
|
-
return ${
|
17
|
+
return ${O(i)};
|
18
18
|
}
|
19
|
-
`))),
|
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`
|
20
20
|
/**
|
21
|
-
* @notice Set ${
|
21
|
+
* @notice Set ${i.name}${p}.
|
22
22
|
*/
|
23
|
-
function ${h}set${
|
24
|
-
${
|
25
|
-
${
|
23
|
+
function ${h}set${d}(${f}) internal {
|
24
|
+
${o}
|
25
|
+
${u}.${l}(${g});
|
26
26
|
}
|
27
|
-
`})),
|
28
|
-
// The length of ${
|
29
|
-
uint256 constant length${p} = ${
|
30
|
-
`):
|
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})=>`
|
31
31
|
/**
|
32
|
-
* @notice Get the length of ${
|
32
|
+
* @notice Get the length of ${i.name}${l}.
|
33
33
|
*/
|
34
|
-
function ${
|
35
|
-
${
|
36
|
-
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${
|
34
|
+
function ${y}length${p}(${S([h,r,n])}) internal view returns (uint256) {
|
35
|
+
${o}
|
36
|
+
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${s});
|
37
37
|
unchecked {
|
38
|
-
return _byteLength / ${
|
38
|
+
return _byteLength / ${d.elementLength};
|
39
39
|
}
|
40
40
|
}
|
41
|
-
`)),
|
41
|
+
`)),a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
|
42
42
|
/**
|
43
|
-
* @notice Get an item of ${
|
43
|
+
* @notice Get an item of ${i.name}${l}.
|
44
44
|
* @dev Reverts with Store_IndexOutOfBounds if \`_index\` is out of bounds for the array.
|
45
45
|
*/
|
46
|
-
function ${
|
47
|
-
${
|
46
|
+
function ${y}getItem${p}(${S([h,r,n,"uint256 _index"])}) internal view returns (${d.typeWithLocation}) {
|
47
|
+
${o}
|
48
48
|
|
49
|
-
${
|
50
|
-
uint256 _byteLength = ${f}.getDynamicFieldLength(_tableId, _keyTuple, ${
|
51
|
-
uint256 dynamicLength = _byteLength / ${
|
52
|
-
uint256 staticLength = ${
|
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};
|
53
53
|
|
54
54
|
if (_index < staticLength && _index >= dynamicLength) {
|
55
|
-
return ${
|
55
|
+
return ${v(i.arrayElement,`bytes${i.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
|
-
${
|
63
|
-
_index * ${
|
64
|
-
(_index + 1) * ${
|
62
|
+
${s},
|
63
|
+
_index * ${d.elementLength},
|
64
|
+
(_index + 1) * ${d.elementLength}
|
65
65
|
);
|
66
|
-
return ${
|
66
|
+
return ${d.decoded};
|
67
67
|
}
|
68
68
|
}
|
69
|
-
`))),(!
|
69
|
+
`))),(!u||u.kind!=="staticArray")&&(a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
|
70
70
|
/**
|
71
|
-
* @notice Push ${
|
71
|
+
* @notice Push ${d.title} to ${i.name}${l}.
|
72
72
|
*/
|
73
|
-
function ${
|
74
|
-
${
|
75
|
-
${f}.pushToDynamicField(_tableId, _keyTuple, ${
|
73
|
+
function ${y}push${p}(${S([h,r,n,`${d.typeWithLocation} ${d.name}`])}) internal {
|
74
|
+
${o}
|
75
|
+
${f}.pushToDynamicField(_tableId, _keyTuple, ${s}, ${d.encoded});
|
76
76
|
}
|
77
|
-
`)),
|
77
|
+
`)),a+=b(e.withSuffixlessFieldMethods,i.name,p=>L(t,({_typedStore:h,_store:f,_commentSuffix:l,_methodNamePrefix:y})=>`
|
78
78
|
/**
|
79
|
-
* @notice Pop ${
|
79
|
+
* @notice Pop ${d.title} from ${i.name}${l}.
|
80
80
|
*/
|
81
|
-
function ${
|
82
|
-
${
|
83
|
-
${f}.popFromDynamicField(_tableId, _keyTuple, ${
|
81
|
+
function ${y}pop${p}(${S([h,r,n])}) internal {
|
82
|
+
${o}
|
83
|
+
${f}.popFromDynamicField(_tableId, _keyTuple, ${s}, ${d.elementLength});
|
84
84
|
}
|
85
|
-
`))),
|
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=`
|
86
86
|
_tableId,
|
87
87
|
_keyTuple,
|
88
|
-
${
|
89
|
-
uint40(_index * ${
|
88
|
+
${s},
|
89
|
+
uint40(_index * ${d.elementLength}),
|
90
90
|
uint40(_encoded.length),
|
91
91
|
_encoded
|
92
92
|
`;return`
|
93
93
|
/**
|
94
|
-
* @notice Update ${
|
94
|
+
* @notice Update ${d.title} of ${i.name}${l} at \`_index\`.
|
95
95
|
*/
|
96
|
-
function ${
|
97
|
-
${
|
96
|
+
function ${y}update${p}(${g}) internal {
|
97
|
+
${o}
|
98
98
|
unchecked {
|
99
|
-
bytes memory _encoded = ${
|
100
|
-
${f}.spliceDynamicData(${
|
99
|
+
bytes memory _encoded = ${d.encoded};
|
100
|
+
${f}.spliceDynamicData(${T});
|
101
101
|
}
|
102
102
|
}
|
103
|
-
`}))}}return
|
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
104
|
SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_${r.internalTypeId}()
|
105
|
-
)`:
|
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})=>`
|
106
106
|
/**
|
107
|
-
* @notice Get the full data${
|
107
|
+
* @notice Get the full data${d}.
|
108
108
|
*/
|
109
|
-
function ${
|
110
|
-
${
|
109
|
+
function ${s}get(${$([i,n,o])}) internal view returns (${se(e)}) {
|
110
|
+
${a}
|
111
111
|
|
112
112
|
(
|
113
113
|
bytes memory _staticData,
|
@@ -116,147 +116,147 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
116
116
|
) = ${m}.getRecord(_tableId, _keyTuple, _fieldLayout);
|
117
117
|
return decode(_staticData, _encodedLengths, _dynamicData);
|
118
118
|
}
|
119
|
-
`)),c+=F(r,({_typedStore:
|
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`
|
120
120
|
/**
|
121
|
-
* @notice Set the full data using individual values${
|
121
|
+
* @notice Set the full data using individual values${d}.
|
122
122
|
*/
|
123
|
-
function ${
|
123
|
+
function ${s}set(${p}) internal {
|
124
124
|
${R(e)}
|
125
125
|
|
126
|
-
${
|
126
|
+
${a}
|
127
127
|
|
128
128
|
${m}.setRecord(${h});
|
129
129
|
}
|
130
|
-
`}),
|
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`
|
131
131
|
/**
|
132
|
-
* @notice Set the full data using the data struct${
|
132
|
+
* @notice Set the full data using the data struct${d}.
|
133
133
|
*/
|
134
|
-
function ${
|
134
|
+
function ${s}set(${p}) internal {
|
135
135
|
${R(e,"_table.")}
|
136
136
|
|
137
|
-
${
|
137
|
+
${a}
|
138
138
|
|
139
139
|
${m}.setRecord(${h});
|
140
140
|
}
|
141
|
-
`})),c+=
|
141
|
+
`})),c+=ce(e),c}function R(e,t=""){let r="";return e.staticFields.length>0?r+=`
|
142
142
|
bytes memory _staticData = encodeStatic(
|
143
|
-
${$(e.staticFields.map(({name:
|
143
|
+
${$(e.staticFields.map(({name:n})=>`${t}${n}`))}
|
144
144
|
);
|
145
145
|
`:r+="bytes memory _staticData;",e.dynamicFields.length>0?r+=`
|
146
146
|
EncodedLengths _encodedLengths = encodeLengths(
|
147
|
-
${$(e.dynamicFields.map(({name:
|
147
|
+
${$(e.dynamicFields.map(({name:n})=>`${t}${n}`))}
|
148
148
|
);
|
149
149
|
bytes memory _dynamicData = encodeDynamic(
|
150
|
-
${$(e.dynamicFields.map(({name:
|
150
|
+
${$(e.dynamicFields.map(({name:n})=>`${t}${n}`))}
|
151
151
|
);
|
152
152
|
`:r+=`
|
153
153
|
EncodedLengths _encodedLengths;
|
154
154
|
bytes memory _dynamicData;
|
155
|
-
`,r}function
|
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`
|
156
156
|
/**
|
157
|
-
* @notice Delete all data for given keys${
|
157
|
+
* @notice Delete all data for given keys${i}.
|
158
158
|
*/
|
159
|
-
function ${m}deleteRecord(${
|
160
|
-
${
|
161
|
-
${c}.deleteRecord(${
|
159
|
+
function ${m}deleteRecord(${s}) internal {
|
160
|
+
${o}
|
161
|
+
${c}.deleteRecord(${u});
|
162
162
|
}
|
163
|
-
`})}function
|
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+=`
|
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:
|
168
|
-
${
|
169
|
-
${
|
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])};
|
170
170
|
`)}
|
171
171
|
}
|
172
|
-
`),
|
172
|
+
`),n.length>0&&(m+=`
|
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 (${$(
|
177
|
-
${
|
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?`
|
178
178
|
uint256 _start;
|
179
179
|
uint256 _end;
|
180
180
|
unchecked {
|
181
|
-
_end = _encodedLengths.atIndex(${
|
181
|
+
_end = _encodedLengths.atIndex(${s});
|
182
182
|
}
|
183
|
-
${
|
183
|
+
${d.name} = ${q(d)};
|
184
184
|
`:`
|
185
185
|
_start = _end;
|
186
186
|
unchecked {
|
187
|
-
_end += _encodedLengths.atIndex(${
|
187
|
+
_end += _encodedLengths.atIndex(${s});
|
188
188
|
}
|
189
|
-
${
|
189
|
+
${d.name} = ${q(d)};
|
190
190
|
`)}
|
191
191
|
}
|
192
192
|
`),m+=`
|
193
193
|
/**
|
194
194
|
* @notice Decode the tightly packed blobs using this table's field layout.
|
195
195
|
* ${r.length>0?"@param _staticData Tightly packed static fields.":""}
|
196
|
-
* ${
|
197
|
-
* ${
|
196
|
+
* ${n.length>0?"@param _encodedLengths Encoded lengths of dynamic fields.":""}
|
197
|
+
* ${n.length>0?"@param _dynamicData Tightly packed dynamic fields.":""}
|
198
198
|
*/
|
199
199
|
function decode(
|
200
200
|
bytes memory ${r.length>0?"_staticData":""},
|
201
|
-
EncodedLengths ${
|
202
|
-
bytes memory ${
|
203
|
-
) internal pure returns (${
|
201
|
+
EncodedLengths ${n.length>0?"_encodedLengths":""},
|
202
|
+
bytes memory ${n.length>0?"_dynamicData":""}
|
203
|
+
) internal pure returns (${o}) {
|
204
204
|
`,r.length>0&&(m+=`
|
205
|
-
(${$(r.map(
|
206
|
-
`),
|
207
|
-
(${$(
|
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
208
|
`),m+=`
|
209
209
|
}
|
210
|
-
`,m}function
|
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
211
|
SliceLib.getSubslice(_blob, _start, _end).decodeArray_${r.typeId}()
|
212
|
-
)`:`${
|
213
|
-
${
|
212
|
+
)`:`${n}(
|
213
|
+
${t}(
|
214
214
|
SliceLib.getSubslice(_blob, _start, _end).toBytes()
|
215
215
|
)
|
216
|
-
)`}import{renderArguments as
|
217
|
-
${
|
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}
|
218
218
|
|
219
219
|
// Import store internals
|
220
|
-
import { IStore } from "${
|
221
|
-
import { StoreSwitch } from "${
|
222
|
-
import { StoreCore } from "${
|
223
|
-
import { Bytes } from "${
|
224
|
-
import { Memory } from "${
|
225
|
-
import { SliceLib } from "${
|
226
|
-
import { EncodeArray } from "${
|
227
|
-
import { FieldLayout } from "${
|
228
|
-
import { Schema } from "${
|
229
|
-
import { EncodedLengths, EncodedLengthsLib } from "${
|
230
|
-
import { ResourceId } from "${
|
231
|
-
|
232
|
-
${
|
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";
|
231
|
+
|
232
|
+
${t.length>0?`
|
233
233
|
// Import user types
|
234
|
-
${
|
234
|
+
${fe(t)}
|
235
235
|
`:""}
|
236
236
|
|
237
|
-
${
|
238
|
-
struct ${
|
239
|
-
${
|
237
|
+
${n?`
|
238
|
+
struct ${n} {
|
239
|
+
${B(c,({name:l,typeId:y})=>`${y} ${l};`)}
|
240
240
|
}
|
241
241
|
`:""}
|
242
242
|
|
243
243
|
library ${r} {
|
244
|
-
${
|
244
|
+
${o?$e(o):""}
|
245
245
|
|
246
|
-
${
|
246
|
+
${Z(c)}
|
247
247
|
|
248
|
-
// Hex-encoded key schema of (${
|
249
|
-
Schema constant _keySchema = Schema.wrap(${
|
250
|
-
// Hex-encoded value schema of (${c.map(
|
251
|
-
Schema constant _valueSchema = Schema.wrap(${
|
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])))});
|
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[](${
|
259
|
-
${
|
258
|
+
keyNames = new string[](${u.length});
|
259
|
+
${B(u,(l,y)=>`keyNames[${y}] = "${l.name}";`)}
|
260
260
|
}
|
261
261
|
|
262
262
|
/**
|
@@ -265,37 +265,37 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
265
265
|
*/
|
266
266
|
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
267
267
|
fieldNames = new string[](${c.length});
|
268
|
-
${
|
268
|
+
${B(c,(l,y)=>`fieldNames[${y}] = "${l.name}";`)}
|
269
269
|
}
|
270
270
|
|
271
|
-
${
|
271
|
+
${Te(s,({_typedStore:l,_store:y,_commentSuffix:g,_methodNamePrefix:T})=>`
|
272
272
|
/**
|
273
273
|
* @notice Register the table with its config${g}.
|
274
274
|
*/
|
275
|
-
function ${
|
276
|
-
${
|
275
|
+
function ${T}register(${_([l,p])}) internal {
|
276
|
+
${y}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
277
277
|
}
|
278
278
|
`)}
|
279
279
|
|
280
|
-
${
|
280
|
+
${G(e)}
|
281
281
|
|
282
|
-
${
|
282
|
+
${d?X(e):""}
|
283
283
|
|
284
|
-
${
|
284
|
+
${V(e)}
|
285
285
|
|
286
|
-
${
|
287
|
-
|
288
|
-
${Le(m)}
|
286
|
+
${Le(i)}
|
289
287
|
|
290
288
|
${De(m)}
|
291
289
|
|
290
|
+
${Ie(m)}
|
291
|
+
|
292
292
|
/**
|
293
293
|
* @notice Encode all of a record's fields.
|
294
294
|
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
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(${
|
298
|
+
function encode(${_(e.fields.map(({name:l,typeWithLocation:y})=>`${y} ${l}`))}) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
299
299
|
${R(e)}
|
300
300
|
|
301
301
|
return (_staticData, _encodedLengths, _dynamicData);
|
@@ -304,47 +304,47 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
304
304
|
/**
|
305
305
|
* @notice Encode keys as a bytes32 array using this table's field layout.
|
306
306
|
*/
|
307
|
-
function encodeKeyTuple(${
|
307
|
+
function encodeKeyTuple(${_([h])}) internal pure returns (bytes32[] memory) {
|
308
308
|
${f}
|
309
309
|
return _keyTuple;
|
310
310
|
}
|
311
311
|
}
|
312
312
|
|
313
|
-
${
|
314
|
-
`}function
|
313
|
+
${ge(e)}
|
314
|
+
`}function Le(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(${
|
320
|
-
return abi.encodePacked(${
|
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))});
|
321
321
|
}
|
322
|
-
`}function
|
322
|
+
`}function De(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(${
|
327
|
+
function encodeLengths(${_(e.map(({name:t,typeWithLocation:r})=>`${r} ${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
|
-
${
|
331
|
+
${_(e.map(({name:t,arrayElement:r})=>r?`${t}.length * ${r.staticByteLength}`:`bytes(${t}).length`))}
|
332
332
|
);
|
333
333
|
}
|
334
334
|
}
|
335
|
-
`}function
|
335
|
+
`}function Ie(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(${
|
341
|
-
return abi.encodePacked(${
|
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)))});
|
342
342
|
}
|
343
|
-
`}import{renderEnums as
|
344
|
-
${
|
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}
|
345
345
|
|
346
|
-
${
|
347
|
-
`}import{mapObject as
|
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`
|
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 ie,renderWithFieldSuffix as _,re
|
|
359
359
|
bytes32[] memory _genericArray = TightCoder.decode(
|
360
360
|
_input,
|
361
361
|
${e.staticByteLength},
|
362
|
-
${
|
362
|
+
${re(e)}
|
363
363
|
);
|
364
364
|
assembly {
|
365
365
|
_output := _genericArray
|
366
366
|
}
|
367
367
|
}
|
368
|
-
`}function
|
368
|
+
`}function ie(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 ie,renderWithFieldSuffix as _,re
|
|
380
380
|
return TightCoder.encode(
|
381
381
|
_genericArray,
|
382
382
|
${e.staticByteLength},
|
383
|
-
${
|
383
|
+
${re(e)}
|
384
384
|
);
|
385
385
|
}
|
386
|
-
`}function
|
387
|
-
${
|
386
|
+
`}function Ut(){return`
|
387
|
+
${We}
|
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 ie,renderWithFieldSuffix as _,re
|
|
395
395
|
* @dev This library provides functions for decoding slices into arrays of basic uint types.
|
396
396
|
*/
|
397
397
|
library DecodeSlice {
|
398
|
-
${
|
398
|
+
${je.map(e=>oe({internalTypeId:e,staticByteLength:Pe[e]})).join(`
|
399
399
|
`)}
|
400
400
|
}
|
401
|
-
`}import{renderedSolidityHeader as
|
402
|
-
${
|
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}
|
403
403
|
import { TightCoder } from "./TightCoder.sol";
|
404
404
|
|
405
405
|
/**
|
@@ -408,10 +408,10 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
|
|
408
408
|
* @dev This library provides utilities for encoding arrays into tightly packed bytes representations.
|
409
409
|
*/
|
410
410
|
library EncodeArray {
|
411
|
-
${
|
411
|
+
${He.map(e=>ie({internalTypeId:e,staticByteLength:Ge[e]})).join(`
|
412
412
|
`)}
|
413
413
|
}
|
414
|
-
`}import{renderedSolidityHeader as
|
414
|
+
`}import{renderedSolidityHeader as Ke}from"@latticexyz/common/codegen";import{staticAbiTypes as qe}from"@latticexyz/schema-type/internal";function Ye({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 ie,renderWithFieldSuffix as _,re
|
|
431
431
|
assertEq(decoded[1], val1);
|
432
432
|
assertEq(decoded[2], val2);
|
433
433
|
}
|
434
|
-
`}function
|
435
|
-
${
|
434
|
+
`}function zt(){return`
|
435
|
+
${Ke}
|
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
|
-
${
|
442
|
+
${qe.map(e=>Ye({typeId:e})).join("")}
|
443
443
|
}
|
444
|
-
`}export{
|
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};
|
445
445
|
//# sourceMappingURL=codegen.js.map
|
package/dist/codegen.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../ts/codegen/field.ts","../ts/codegen/record.ts","../ts/codegen/renderTable.ts","../ts/constants.ts","../ts/codegen/renderFieldLayout.ts","../ts/codegen/renderTypesFromConfig.ts","../ts/codegen/tablegen.ts","../ts/codegen/tableOptions.ts","../ts/codegen/userType.ts","../ts/codegen/renderTableIndex.ts","../ts/codegen/tightcoder/renderDecodeSlice.ts","../ts/codegen/tightcoder/renderFunctions.ts","../ts/codegen/tightcoder/renderEncodeArray.ts","../ts/codegen/tightcoder/renderTightCoderAutoTest.ts"],"sourcesContent":["import {\n renderArguments,\n renderCommonData,\n RenderField,\n RenderType,\n renderWithFieldSuffix,\n renderWithStore,\n} from \"@latticexyz/common/codegen\";\nimport { RenderTableOptions } from \"./types\";\n\n/**\n * Returns Solidity code for all the field-specific table methods (get, set, push, pop, etc.)\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nexport function renderFieldMethods(options: RenderTableOptions): string {\n const storeArgument = options.storeArgument;\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n let result = \"\";\n for (const [schemaIndex, field] of options.fields.entries()) {\n if (!options.withDynamicFieldMethods && field.isDynamic) {\n continue;\n }\n\n // For dynamic fields, compute the field index relative to the end of the static fields\n const _typedFieldName = `${field.typeWithLocation} ${field.name}`;\n\n if (options.withGetters) {\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}get${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal view returns (${_typedFieldName}) {\n ${_keyTupleDefinition}\n ${\n field.isDynamic\n ? `bytes memory _blob = ${_store}.getDynamicField(\n _tableId,\n _keyTuple,\n ${schemaIndex - options.staticFields.length}\n );`\n : `bytes32 _blob = ${_store}.getStaticField(\n _tableId,\n _keyTuple,\n ${schemaIndex},\n _fieldLayout\n );`\n }\n return ${renderDecodeFieldSingle(field)};\n }\n `,\n ),\n );\n }\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(storeArgument, ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => {\n const externalArguments = renderArguments([_typedStore, _typedTableId, _typedKeyArgs, _typedFieldName]);\n const setFieldMethod = field.isDynamic ? \"setDynamicField\" : \"setStaticField\";\n const encodeFieldSingle = renderEncodeFieldSingle(field);\n const internalArguments = field.isDynamic\n ? `_tableId, _keyTuple, ${schemaIndex - options.staticFields.length}, ${encodeFieldSingle}`\n : `_tableId, _keyTuple, ${schemaIndex}, ${encodeFieldSingle}, _fieldLayout`;\n\n return `\n /**\n * @notice Set ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}set${_methodNameSuffix}(${externalArguments}) internal {\n ${_keyTupleDefinition}\n ${_store}.${setFieldMethod}(${internalArguments});\n }\n `;\n }),\n );\n\n if (field.isDynamic) {\n const portionData = fieldPortionData(field);\n const dynamicSchemaIndex = schemaIndex - options.staticFields.length;\n const { typeWrappingData } = field;\n\n if (options.withGetters) {\n if (typeWrappingData && typeWrappingData.kind === \"staticArray\") {\n result += renderWithFieldSuffix(\n options.withSuffixlessFieldMethods,\n field.name,\n (_methodNameSuffix) =>\n `\n // The length of ${field.name}\n uint256 constant length${_methodNameSuffix} = ${typeWrappingData.staticLength};\n `,\n );\n } else {\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get the length of ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal view returns (uint256) {\n ${_keyTupleDefinition}\n uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex});\n unchecked {\n return _byteLength / ${portionData.elementLength};\n }\n }\n `,\n ),\n );\n }\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get an item of ${field.name}${_commentSuffix}.\n * @dev Reverts with Store_IndexOutOfBounds if \\`_index\\` is out of bounds for the array.\n */\n function ${_methodNamePrefix}getItem${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n \"uint256 _index\",\n ])}) internal view returns (${portionData.typeWithLocation}) {\n ${_keyTupleDefinition}\n\n ${\n // If the index is within the static length,\n // but ahead of the dynamic length, return zero\n typeWrappingData && typeWrappingData.kind === \"staticArray\" && field.arrayElement\n ? `\n uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex});\n uint256 dynamicLength = _byteLength / ${portionData.elementLength};\n uint256 staticLength = ${typeWrappingData.staticLength};\n\n if (_index < staticLength && _index >= dynamicLength) {\n return ${renderCastStaticBytesToType(field.arrayElement, `bytes${field.arrayElement.staticByteLength}(new bytes(0))`)};\n }`\n : ``\n }\n\n unchecked {\n bytes memory _blob = ${_store}.getDynamicFieldSlice(\n _tableId,\n _keyTuple,\n ${dynamicSchemaIndex},\n _index * ${portionData.elementLength},\n (_index + 1) * ${portionData.elementLength}\n );\n return ${portionData.decoded};\n }\n }\n `,\n ),\n );\n }\n\n if (!typeWrappingData || typeWrappingData.kind !== \"staticArray\") {\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Push ${portionData.title} to ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}push${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n `${portionData.typeWithLocation} ${portionData.name}`,\n ])}) internal {\n ${_keyTupleDefinition}\n ${_store}.pushToDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.encoded});\n }\n `,\n ),\n );\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Pop ${portionData.title} from ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}pop${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal {\n ${_keyTupleDefinition}\n ${_store}.popFromDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.elementLength});\n }\n `,\n ),\n );\n }\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(storeArgument, ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => {\n const externalArguments = renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n \"uint256 _index\",\n `${portionData.typeWithLocation} ${portionData.name}`,\n ]);\n\n const internalArguments = `\n _tableId,\n _keyTuple,\n ${dynamicSchemaIndex},\n uint40(_index * ${portionData.elementLength}),\n uint40(_encoded.length),\n _encoded \n `;\n\n return `\n /**\n * @notice Update ${portionData.title} of ${field.name}${_commentSuffix} at \\`_index\\`.\n */\n function ${_methodNamePrefix}update${_methodNameSuffix}(${externalArguments}) internal {\n ${_keyTupleDefinition}\n unchecked {\n bytes memory _encoded = ${portionData.encoded};\n ${_store}.spliceDynamicData(${internalArguments});\n }\n }\n `;\n }),\n );\n }\n }\n return result;\n}\n\n/**\n * Returns Solidity code for how to encode a particular field into bytes before storing onchain\n * @param field RenderField\n * @returns string of Solidity code\n */\nexport function renderEncodeFieldSingle(field: RenderField) {\n let func;\n if (field.arrayElement) {\n func = \"EncodeArray.encode\";\n } else if (field.isDynamic) {\n func = \"bytes\";\n } else {\n func = \"abi.encodePacked\";\n }\n return `${func}(${field.typeUnwrap}(${field.name}))`;\n}\n\n/**\n * Returns Solidity code for decoding a bytes value into its Solidity primitive type\n * @param field description of field type\n * @param offset byte-length offset of value in encoded bytes\n * @returns string of Solidity code\n */\nexport function renderDecodeValueType(field: RenderType, offset: number) {\n const { staticByteLength } = field;\n\n const innerSlice = `Bytes.getBytes${staticByteLength}(_blob, ${offset})`;\n\n return renderCastStaticBytesToType(field, innerSlice);\n}\n\n/**\n * Returns Solidity code for how to cast a bytesN value to a particular type, which is assumed to have the same byte length\n * @param field description of resulting field type\n * @param staticBytes bytesN value\n * @returns string of Solidity code\n */\nfunction renderCastStaticBytesToType(field: RenderType, staticBytes: string) {\n const { staticByteLength, internalTypeId } = field;\n const bits = staticByteLength * 8;\n\n let result;\n if (internalTypeId.match(/^uint\\d{1,3}$/) || internalTypeId === \"address\") {\n result = `${internalTypeId}(${staticBytes})`;\n } else if (internalTypeId.match(/^int\\d{1,3}$/)) {\n result = `${internalTypeId}(uint${bits}(${staticBytes}))`;\n } else if (internalTypeId.match(/^bytes\\d{1,2}$/)) {\n result = staticBytes;\n } else if (internalTypeId === \"bool\") {\n result = `_toBool(uint8(${staticBytes}))`;\n } else {\n throw new Error(`Unknown value type id ${internalTypeId}`);\n }\n return `${field.typeWrap}(${result})`;\n}\n\ninterface FieldPortionData {\n /** Fully-qualified name of the user-defined type (may include a library name as prefix), followed by location (none/memory/storage) */\n typeWithLocation: string;\n /** Name of the field portion variable */\n name: string;\n /** Solidity code which encodes the field portion variable into bytes (for storing onchain) */\n encoded: string;\n /** Solidity code which decodes `_blob` variable into the field portion variable's type */\n decoded: string;\n /** Description of the field portion kind (\"an element\" or \"a slice\") */\n title: string;\n /** Byte length of array elements for arrays, 1 otherwise */\n elementLength: number;\n}\n\n/**\n * Returns data to describe either an array element, or a bytes slice, depending on the provided field type\n */\nfunction fieldPortionData(field: RenderField): FieldPortionData {\n if (field.arrayElement) {\n const name = \"_element\";\n const elementFieldData = { ...field.arrayElement, arrayElement: undefined, name };\n return {\n typeWithLocation: field.arrayElement.typeWithLocation,\n name,\n encoded: renderEncodeFieldSingle(elementFieldData),\n decoded: renderDecodeFieldSingle(elementFieldData),\n title: \"an element\",\n elementLength: field.arrayElement.staticByteLength,\n };\n } else {\n const name = \"_slice\";\n const elementFieldData = { ...field, name };\n return {\n typeWithLocation: `${field.typeId} memory`,\n name,\n encoded: renderEncodeFieldSingle(elementFieldData),\n decoded: renderDecodeFieldSingle(elementFieldData),\n title: \"a slice\",\n elementLength: 1,\n };\n }\n}\n\n/**\n * Returns Solidity code for how to decode `_blob` variable into the particular field type\n * @param field RenderField\n * @returns string of Solidity code\n */\nfunction renderDecodeFieldSingle(field: RenderField) {\n const { isDynamic, arrayElement } = field;\n if (arrayElement) {\n // arrays\n return `${field.typeWrap}(\n SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_${arrayElement.internalTypeId}()\n )`;\n } else if (isDynamic) {\n // bytes/string\n return `${field.typeWrap}(${field.internalTypeId}(_blob))`;\n } else {\n return renderCastStaticBytesToType(field, `bytes${field.staticByteLength}(_blob)`);\n }\n}\n","import {\n RenderDynamicField,\n renderArguments,\n renderCommonData,\n renderList,\n renderWithStore,\n} from \"@latticexyz/common/codegen\";\nimport { renderDecodeValueType } from \"./field\";\nimport { RenderTableOptions } from \"./types\";\n\n/**\n * Returns Solidity code for whole-record methods (get, set)\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nexport function renderRecordMethods(options: RenderTableOptions) {\n const { structName, storeArgument } = options;\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n let result = \"\";\n\n if (options.withGetters) {\n result += renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get the full data${_commentSuffix}.\n */\n function ${_methodNamePrefix}get(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal view returns (${renderDecodedRecord(options)}) {\n ${_keyTupleDefinition}\n \n (\n bytes memory _staticData,\n EncodedLengths _encodedLengths,\n bytes memory _dynamicData\n ) = ${_store}.getRecord(_tableId, _keyTuple, _fieldLayout);\n return decode(_staticData, _encodedLengths, _dynamicData);\n }\n `,\n );\n }\n\n result += renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => {\n const externalArguments = renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n renderArguments(options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`)),\n ]);\n\n const internalArguments =\n \"_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData\" +\n (_useExplicitFieldLayout ? \", _fieldLayout\" : \"\");\n\n return `\n /** \n * @notice Set the full data using individual values${_commentSuffix}.\n */\n function ${_methodNamePrefix}set(${externalArguments}) internal {\n ${renderRecordData(options)}\n\n ${_keyTupleDefinition}\n\n ${_store}.setRecord(${internalArguments});\n }\n `;\n },\n );\n\n if (structName !== undefined) {\n result += renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => {\n const externalArguments = renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n `${structName} memory _table`,\n ]);\n\n const internalArguments =\n \"_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData\" +\n (_useExplicitFieldLayout ? \", _fieldLayout\" : \"\");\n\n return `\n /**\n * @notice Set the full data using the data struct${_commentSuffix}.\n */\n function ${_methodNamePrefix}set(${externalArguments}) internal {\n ${renderRecordData(options, \"_table.\")}\n\n ${_keyTupleDefinition}\n\n ${_store}.setRecord(${internalArguments});\n }\n `;\n },\n );\n }\n\n result += renderDecodeFunctions(options);\n\n return result;\n}\n\n/**\n * Returns Solidity code to prepare variables needed to store encoded record on chain\n * @param options RenderTableOptions\n * @param namePrefix optional field name prefix to change how the field is accessed\n * @returns string of Solidity code\n */\nexport function renderRecordData(options: RenderTableOptions, namePrefix = \"\") {\n let result = \"\";\n if (options.staticFields.length > 0) {\n result += `\n bytes memory _staticData = encodeStatic(\n ${renderArguments(options.staticFields.map(({ name }) => `${namePrefix}${name}`))}\n );\n `;\n } else {\n result += `bytes memory _staticData;`;\n }\n\n if (options.dynamicFields.length > 0) {\n result += `\n EncodedLengths _encodedLengths = encodeLengths(\n ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))}\n );\n bytes memory _dynamicData = encodeDynamic(\n ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))}\n );\n `;\n } else {\n result += `\n EncodedLengths _encodedLengths;\n bytes memory _dynamicData;\n `;\n }\n\n return result;\n}\n\n/**\n * Returns Solidity code for the delete record method\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nexport function renderDeleteRecordMethods(options: RenderTableOptions) {\n const { storeArgument } = options;\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n return renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => {\n const externalArguments = renderArguments([_typedStore, _typedTableId, _typedKeyArgs]);\n const internalArguments = \"_tableId, _keyTuple\" + (_useExplicitFieldLayout ? \", _fieldLayout\" : \"\");\n\n return `\n /** \n * @notice Delete all data for given keys${_commentSuffix}.\n */\n function ${_methodNamePrefix}deleteRecord(${externalArguments}) internal {\n ${_keyTupleDefinition}\n ${_store}.deleteRecord(${internalArguments});\n }\n `;\n },\n );\n}\n\n/**\n * Returns Solidity code for the `decode` function that parses a bytes blob into the typed table data\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nfunction renderDecodeFunctions({ structName, fields, staticFields, dynamicFields }: RenderTableOptions) {\n // either set struct properties, or just variables\n const renderedDecodedRecord = structName\n ? `${structName} memory _table`\n : renderArguments(fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));\n const fieldNamePrefix = structName ? \"_table.\" : \"\";\n\n // Static field offsets\n const staticOffsets = staticFields.map(() => 0);\n let _acc = 0;\n for (const [index, field] of staticFields.entries()) {\n staticOffsets[index] = _acc;\n _acc += field.staticByteLength;\n }\n\n let result = \"\";\n\n if (staticFields.length > 0) {\n result += `\n /**\n * @notice Decode the tightly packed blob of static data using this table's field layout.\n */\n function decodeStatic(bytes memory _blob) internal pure returns (${renderArguments(\n staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) {\n ${renderList(\n staticFields,\n (field, index) => `\n ${field.name} = ${renderDecodeValueType(field, staticOffsets[index])};\n `,\n )}\n }\n `;\n }\n\n if (dynamicFields.length > 0) {\n result += `\n /**\n * @notice Decode the tightly packed blob of dynamic data using the encoded lengths.\n */\n function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${renderArguments(\n dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) {\n ${renderList(\n dynamicFields,\n // unchecked is only dangerous if _encodedLengths (and _blob) is invalid,\n // but it's assumed to be valid, and this function is meant to be mostly used internally\n (field, index) => {\n if (index === 0) {\n return `\n uint256 _start;\n uint256 _end;\n unchecked {\n _end = _encodedLengths.atIndex(${index});\n }\n ${field.name} = ${renderDecodeDynamicFieldPartial(field)};\n `;\n } else {\n return `\n _start = _end;\n unchecked {\n _end += _encodedLengths.atIndex(${index});\n }\n ${field.name} = ${renderDecodeDynamicFieldPartial(field)};\n `;\n }\n },\n )}\n }\n `;\n }\n\n result += `\n /**\n * @notice Decode the tightly packed blobs using this table's field layout.\n * ${staticFields.length > 0 ? \"@param _staticData Tightly packed static fields.\" : \"\"}\n * ${dynamicFields.length > 0 ? \"@param _encodedLengths Encoded lengths of dynamic fields.\" : \"\"}\n * ${dynamicFields.length > 0 ? \"@param _dynamicData Tightly packed dynamic fields.\" : \"\"}\n */\n function decode(\n bytes memory ${staticFields.length > 0 ? \"_staticData\" : \"\"},\n EncodedLengths ${dynamicFields.length > 0 ? \"_encodedLengths\" : \"\"},\n bytes memory ${dynamicFields.length > 0 ? \"_dynamicData\" : \"\"}\n ) internal pure returns (${renderedDecodedRecord}) {\n `;\n\n if (staticFields.length > 0) {\n result += `\n (${renderArguments(staticFields.map((field) => `${fieldNamePrefix}${field.name}`))}) = decodeStatic(_staticData);\n `;\n }\n if (dynamicFields.length > 0) {\n result += `\n (${renderArguments(\n dynamicFields.map((field) => `${fieldNamePrefix}${field.name}`),\n )}) = decodeDynamic(_encodedLengths, _dynamicData);\n `;\n }\n\n result += `\n }\n `;\n\n return result;\n}\n\n/**\n * Returns Solidity code for the return value of a record getter\n * @param options RenderDynamicField\n * @returns string of Solidity code\n */\nfunction renderDecodedRecord({ structName, fields }: RenderTableOptions) {\n if (structName) {\n return `${structName} memory _table`;\n } else {\n return renderArguments(fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));\n }\n}\n\n/**\n * Returns Solidity code for decoding onchain bytes into typed field data\n * @param options RenderDynamicField\n * @returns string of Solidity code\n */\nfunction renderDecodeDynamicFieldPartial(field: RenderDynamicField) {\n const { typeId, arrayElement, typeWrap } = field;\n if (arrayElement) {\n // arrays\n return `${typeWrap}(\n SliceLib.getSubslice(_blob, _start, _end).decodeArray_${arrayElement.typeId}()\n )`;\n } else {\n // bytes/string\n return `${typeWrap}(\n ${typeId}(\n SliceLib.getSubslice(_blob, _start, _end).toBytes()\n )\n )`;\n }\n}\n","import {\n RenderDynamicField,\n renderArguments,\n renderCommonData,\n renderList,\n renderImports,\n renderTableId,\n renderTypeHelpers,\n renderWithStore,\n renderedSolidityHeader,\n RenderStaticField,\n} from \"@latticexyz/common/codegen\";\nimport { renderEncodeFieldSingle, renderFieldMethods } from \"./field\";\nimport { renderDeleteRecordMethods, renderRecordData, renderRecordMethods } from \"./record\";\nimport { renderFieldLayout } from \"./renderFieldLayout\";\nimport { RenderTableOptions } from \"./types\";\nimport { KeySchema, ValueSchema, keySchemaToHex, valueSchemaToHex } from \"@latticexyz/protocol-parser/internal\";\n\n/**\n * Renders Solidity code for a MUD table library, using the specified options\n * @param options options for rendering the table\n * @returns string of Solidity code\n */\nexport function renderTable(options: RenderTableOptions) {\n const {\n imports,\n libraryName,\n structName,\n staticResourceData,\n storeImportPath,\n fields,\n staticFields,\n dynamicFields,\n withRecordMethods,\n storeArgument,\n keyTuple,\n } = options;\n\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n return `\n ${renderedSolidityHeader}\n\n // Import store internals\n import { IStore } from \"${storeImportPath}IStore.sol\";\n import { StoreSwitch } from \"${storeImportPath}StoreSwitch.sol\";\n import { StoreCore } from \"${storeImportPath}StoreCore.sol\";\n import { Bytes } from \"${storeImportPath}Bytes.sol\";\n import { Memory } from \"${storeImportPath}Memory.sol\";\n import { SliceLib } from \"${storeImportPath}Slice.sol\";\n import { EncodeArray } from \"${storeImportPath}tightcoder/EncodeArray.sol\";\n import { FieldLayout } from \"${storeImportPath}FieldLayout.sol\";\n import { Schema } from \"${storeImportPath}Schema.sol\";\n import { EncodedLengths, EncodedLengthsLib } from \"${storeImportPath}EncodedLengths.sol\";\n import { ResourceId } from \"${storeImportPath}ResourceId.sol\";\n\n ${\n imports.length > 0\n ? `\n // Import user types\n ${renderImports(imports)}\n `\n : \"\"\n }\n\n ${\n !structName\n ? \"\"\n : `\n struct ${structName} {\n ${renderList(fields, ({ name, typeId }) => `${typeId} ${name};`)}\n }\n `\n }\n\n library ${libraryName} {\n ${staticResourceData ? renderTableId(staticResourceData) : \"\"}\n \n ${renderFieldLayout(fields)}\n\n // Hex-encoded key schema of (${keyTuple.map((field) => field.internalTypeId).join(\", \")})\n Schema constant _keySchema = Schema.wrap(${keySchemaToHex(\n Object.fromEntries(keyTuple.map((field) => [field.name, field.internalTypeId])) as KeySchema,\n )});\n // Hex-encoded value schema of (${fields.map((field) => field.internalTypeId).join(\", \")})\n Schema constant _valueSchema = Schema.wrap(${valueSchemaToHex(\n Object.fromEntries(fields.map((field) => [field.name, field.internalTypeId])) as ValueSchema,\n )});\n\n /**\n * @notice Get the table's key field names.\n * @return keyNames An array of strings with the names of key fields.\n */\n function getKeyNames() internal pure returns (string[] memory keyNames) {\n keyNames = new string[](${keyTuple.length});\n ${renderList(keyTuple, (keyElement, index) => `keyNames[${index}] = \"${keyElement.name}\";`)}\n }\n\n /**\n * @notice Get the table's value field names.\n * @return fieldNames An array of strings with the names of value fields.\n */\n function getFieldNames() internal pure returns (string[] memory fieldNames) {\n fieldNames = new string[](${fields.length});\n ${renderList(fields, (field, index) => `fieldNames[${index}] = \"${field.name}\";`)}\n }\n\n ${renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Register the table with its config${_commentSuffix}.\n */\n function ${_methodNamePrefix}register(${renderArguments([_typedStore, _typedTableId])}) internal {\n ${_store}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());\n }\n `,\n )}\n\n ${renderFieldMethods(options)}\n\n ${withRecordMethods ? renderRecordMethods(options) : \"\"}\n\n ${renderDeleteRecordMethods(options)}\n\n ${renderEncodeStatic(staticFields)}\n\n ${renderEncodeLengths(dynamicFields)}\n\n ${renderEncodeDynamic(dynamicFields)}\n\n /**\n * @notice Encode all of a record's fields.\n * @return The static (fixed length) data, encoded into a sequence of bytes.\n * @return The lengths of the dynamic fields (packed into a single bytes32 value).\n * @return The dynamic (variable length) data, encoded into a sequence of bytes.\n */\n function encode(${renderArguments(\n options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (bytes memory, EncodedLengths, bytes memory) {\n ${renderRecordData(options)}\n\n return (_staticData, _encodedLengths, _dynamicData);\n }\n \n /**\n * @notice Encode keys as a bytes32 array using this table's field layout.\n */\n function encodeKeyTuple(${renderArguments([_typedKeyArgs])}) internal pure returns (bytes32[] memory) {\n ${_keyTupleDefinition}\n return _keyTuple;\n }\n }\n\n ${renderTypeHelpers(options)}\n `;\n}\n\n/**\n * Renders solidity code for `encodeStatic` method, which encodes the provided fields into a blob for storage\n * (nothing is rendered if static fields array is empty)\n * @param staticFields array of data about static fields to be encoded\n * @returns string of Solidity code\n */\nfunction renderEncodeStatic(staticFields: RenderStaticField[]) {\n if (staticFields.length === 0) return \"\";\n\n return `\n /**\n * @notice Tightly pack static (fixed length) data using this table's schema.\n * @return The static data, encoded into a sequence of bytes.\n */\n function encodeStatic(${renderArguments(\n staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (bytes memory) {\n return abi.encodePacked(${renderArguments(staticFields.map(({ name }) => name))});\n }\n `;\n}\n\n/**\n * Renders solidity code for `encodeLengths` method, which tightly packs the lengths of the provided fields\n * (nothing is rendered if dynamic fields array is empty)\n * @param dynamicFields array of data about dynamic fields to have their lengths encoded\n * @returns string of Solidity code\n */\nfunction renderEncodeLengths(dynamicFields: RenderDynamicField[]) {\n if (dynamicFields.length === 0) return \"\";\n\n return `\n /**\n * @notice Tightly pack dynamic data lengths using this table's schema.\n * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value).\n */\n function encodeLengths(${renderArguments(\n dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (EncodedLengths _encodedLengths) {\n // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits\n unchecked {\n _encodedLengths = EncodedLengthsLib.pack(\n ${renderArguments(\n dynamicFields.map(({ name, arrayElement }) => {\n if (arrayElement) {\n return `${name}.length * ${arrayElement.staticByteLength}`;\n } else {\n return `bytes(${name}).length`;\n }\n }),\n )}\n );\n }\n }\n `;\n}\n\n/**\n * Renders solidity code for `encodeDynamic` method, which encodes the provided fields into a blob for storage\n * (nothing is rendered if dynamic fields array is empty)\n * @param dynamicFields array of data about dynamic fields to be encoded\n * @returns string of Solidity code\n */\nfunction renderEncodeDynamic(dynamicFields: RenderDynamicField[]) {\n if (dynamicFields.length === 0) return \"\";\n\n return `\n /**\n * @notice Tightly pack dynamic (variable length) data using this table's schema.\n * @return The dynamic data, encoded into a sequence of bytes.\n */\n function encodeDynamic(${renderArguments(\n dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (bytes memory) {\n return abi.encodePacked(${renderArguments(dynamicFields.map((field) => renderEncodeFieldSingle(field)))});\n }\n `;\n}\n","/* Shared constants */\n// Make sure these stay aligned with @latticexyz/store/src/constants.sol\n\n// Total byte length of an EVM word\nexport const WORD_SIZE = 32;\n// Index of the last byte in an EVM word\nexport const WORD_LAST_INDEX = 31;\n// Conversion for bit shifting\nexport const BYTE_TO_BITS = 8;\n\n// Schema's capacity\nexport const MAX_TOTAL_FIELDS = 28;\n// FieldLayout's capacity\nexport const MAX_STATIC_FIELDS = 28;\n// EncodedLengths's capacity\nexport const MAX_DYNAMIC_FIELDS = 5;\n\n// FieldLayout and Schema have the same offsets for metadata\nexport const LayoutOffsets = {\n TOTAL_LENGTH: (WORD_SIZE - 2) * BYTE_TO_BITS,\n NUM_STATIC_FIELDS: (WORD_SIZE - 2 - 1) * BYTE_TO_BITS,\n NUM_DYNAMIC_FIELDS: (WORD_SIZE - 2 - 1 - 1) * BYTE_TO_BITS,\n};\n","import { RenderType } from \"@latticexyz/common/codegen\";\nimport { BYTE_TO_BITS, LayoutOffsets, MAX_DYNAMIC_FIELDS, MAX_TOTAL_FIELDS, WORD_LAST_INDEX } from \"../constants\";\n\ntype FieldLayoutRenderType = Pick<RenderType, \"isDynamic\" | \"staticByteLength\">;\n\n/**\n * Renders Solidity code that defines and initializes `_fieldLayout` constant\n * @param fields array of field data necessary to construct FieldLayout\n * @returns string of Solidity code\n */\nexport function renderFieldLayout(fields: FieldLayoutRenderType[]): string {\n return `FieldLayout constant _fieldLayout = FieldLayout.wrap(${encodeFieldLayout(fields)});`;\n}\n\n// Make sure this logic stays aligned with @latticexyz/store/src/FieldLayout.sol\n/**\n * Returns Solidity hexadecimal which represents the encoded FieldLayout\n * @param fields array of field data necessary to construct FieldLayout\n * @returns string of Solidity code\n */\nfunction encodeFieldLayout(fields: FieldLayoutRenderType[]): string {\n const staticFields = fields.filter(({ isDynamic }) => !isDynamic);\n const numDynamicFields = fields.length - staticFields.length;\n\n let fieldLayout = 0n;\n let totalLength = 0;\n const totalFields = fields.length;\n\n if (totalFields > MAX_TOTAL_FIELDS) throw new Error(\"FieldLayout: too many fields\");\n if (numDynamicFields > MAX_DYNAMIC_FIELDS) throw new Error(\"FieldLayout: too many dynamic fields\");\n\n for (let i = 0; i < staticFields.length; i++) {\n const { isDynamic, staticByteLength } = fields[i];\n if (isDynamic) throw new Error(`FieldLayout: static type after dynamic type`);\n\n totalLength += staticByteLength;\n fieldLayout |= BigInt(staticByteLength) << BigInt((WORD_LAST_INDEX - 4 - i) * BYTE_TO_BITS);\n }\n\n fieldLayout |= BigInt(totalLength) << BigInt(LayoutOffsets.TOTAL_LENGTH);\n fieldLayout |= BigInt(staticFields.length) << BigInt(LayoutOffsets.NUM_STATIC_FIELDS);\n fieldLayout |= BigInt(numDynamicFields) << BigInt(LayoutOffsets.NUM_DYNAMIC_FIELDS);\n\n return `0x${fieldLayout.toString(16).padStart(64, \"0\")}`;\n}\n","import { renderEnums } from \"@latticexyz/common/codegen\";\nimport { Store } from \"../config/v2\";\n\n/**\n * Renders Solidity code for enums defined in the provided config\n */\nexport function renderTypesFromConfig(config: Store) {\n return renderEnums(config.enums);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatAndWriteSolidity, loadAndExtractUserTypes } from \"@latticexyz/common/codegen\";\nimport { getTableOptions } from \"./tableOptions\";\nimport { renderTable } from \"./renderTable\";\nimport { renderTypesFromConfig } from \"./renderTypesFromConfig\";\nimport { renderTableIndex } from \"./renderTableIndex\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\nimport { mapObject } from \"@latticexyz/common/utils\";\n\nexport type TablegenOptions = {\n /**\n * MUD project root directory where all other relative paths are resolved from.\n */\n rootDir: string;\n config: StoreConfig;\n remappings: [string, string][];\n};\n\nexport async function tablegen({ rootDir, config, remappings }: TablegenOptions) {\n const outputDirectory = path.join(rootDir, config.sourceDirectory, config.codegen.outputDirectory);\n const solidityUserTypes = loadAndExtractUserTypes(\n mapObject(config.userTypes, (type) => ({ ...type, internalType: type.type })),\n outputDirectory,\n remappings,\n );\n const allTableOptions = getTableOptions(config, solidityUserTypes);\n\n const uniqueTableDirectories = Array.from(new Set(allTableOptions.map(({ outputPath }) => path.dirname(outputPath))));\n await Promise.all(\n uniqueTableDirectories.map(async (tableDir) => {\n await fs.rm(path.join(outputDirectory, tableDir), { recursive: true, force: true });\n }),\n );\n\n // write tables to files\n await Promise.all(\n allTableOptions.map(async ({ outputPath, renderOptions }) => {\n const fullOutputPath = path.join(outputDirectory, outputPath);\n const output = renderTable(renderOptions);\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated table\");\n }),\n );\n\n // write table index\n if (allTableOptions.length > 0) {\n const fullOutputPath = path.join(outputDirectory, config.codegen.indexFilename);\n const output = renderTableIndex(allTableOptions);\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated table index\");\n }\n\n // write types to file\n if (Object.keys(config.enums).length > 0) {\n const fullOutputPath = path.join(outputDirectory, config.codegen.userTypesFilename);\n const output = renderTypesFromConfig(config);\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated types file\");\n }\n}\n","import path from \"path\";\nimport { SchemaTypeArrayToElement } from \"@latticexyz/schema-type/deprecated\";\nimport {\n ImportDatum,\n RenderDynamicField,\n RenderField,\n RenderKeyTuple,\n RenderStaticField,\n SolidityUserDefinedType,\n} from \"@latticexyz/common/codegen\";\nimport { RenderTableOptions } from \"./types\";\nimport { getSchemaTypeInfo, importForAbiOrUserType, resolveAbiOrUserType } from \"./userType\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\nimport { getKeySchema, getValueSchema } from \"@latticexyz/protocol-parser/internal\";\n\nexport interface TableOptions {\n /** Path where the file is expected to be written (relative to project root) */\n outputPath: string;\n /** Name of the table, as used in filename and library name */\n tableName: string;\n /** Options for `renderTable` function */\n renderOptions: RenderTableOptions;\n}\n\n/**\n * Transforms store config and available solidity user types into useful options for `tablegen` and `renderTable`\n */\nexport function getTableOptions(\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): TableOptions[] {\n const options = Object.values(config.tables).map((table): TableOptions => {\n const keySchema = getKeySchema(table);\n const valueSchema = getValueSchema(table);\n\n // struct adds methods to get/set all values at once\n const withStruct = table.codegen.dataStruct;\n // operate on all fields at once; always render for offchain tables; for only 1 field keep them if struct is also kept\n const withRecordMethods = withStruct || table.type === \"offchainTable\" || Object.keys(valueSchema).length > 1;\n // field methods can include simply get/set if there's only 1 field and no record methods\n const withSuffixlessFieldMethods = !withRecordMethods && Object.keys(valueSchema).length === 1;\n // list of any symbols that need to be imported\n const imports: ImportDatum[] = [];\n\n const keyTuple = Object.entries(keySchema).map(([name, field]): RenderKeyTuple => {\n const abiOrUserType = field.internalType;\n const { renderType } = resolveAbiOrUserType(abiOrUserType, config, solidityUserTypes);\n\n const importDatum = importForAbiOrUserType(\n abiOrUserType,\n table.codegen.outputDirectory,\n config,\n solidityUserTypes,\n );\n if (importDatum) imports.push(importDatum);\n\n return {\n ...renderType,\n name,\n isDynamic: false,\n };\n });\n\n const fields = Object.entries(valueSchema).map(([name, field]): RenderField => {\n const abiOrUserType = field.internalType;\n const { renderType, schemaType } = resolveAbiOrUserType(abiOrUserType, config, solidityUserTypes);\n\n const importDatum = importForAbiOrUserType(\n abiOrUserType,\n table.codegen.outputDirectory,\n config,\n solidityUserTypes,\n );\n if (importDatum) imports.push(importDatum);\n\n const elementType = SchemaTypeArrayToElement[schemaType];\n return {\n ...renderType,\n arrayElement: elementType !== undefined ? getSchemaTypeInfo(elementType) : undefined,\n name,\n };\n });\n\n const staticFields = fields.filter(({ isDynamic }) => !isDynamic) as RenderStaticField[];\n const dynamicFields = fields.filter(({ isDynamic }) => isDynamic) as RenderDynamicField[];\n\n // With tableIdArgument: tableId is a dynamic argument for each method\n // Without tableIdArgument: tableId is a file-level constant generated from `staticResourceData`\n const staticResourceData = table.codegen.tableIdArgument\n ? undefined\n : {\n namespace: table.namespace,\n name: table.name,\n offchainOnly: table.type === \"offchainTable\",\n };\n\n return {\n outputPath: path.join(table.codegen.outputDirectory, `${table.label}.sol`),\n tableName: table.label,\n renderOptions: {\n imports,\n libraryName: table.label,\n structName: withStruct ? table.label + \"Data\" : undefined,\n staticResourceData,\n storeImportPath: config.codegen.storeImportPath,\n keyTuple,\n fields,\n staticFields,\n dynamicFields,\n withGetters: table.type === \"table\",\n withRecordMethods,\n withDynamicFieldMethods: table.type === \"table\",\n withSuffixlessFieldMethods,\n storeArgument: table.codegen.storeArgument,\n },\n };\n });\n\n return options;\n}\n","import {\n AbiTypeToSchemaType,\n getStaticByteLength,\n SchemaType,\n SchemaTypeToAbiType,\n} from \"@latticexyz/schema-type/deprecated\";\nimport { ImportDatum, RenderType, SolidityUserDefinedType } from \"@latticexyz/common/codegen\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\n\nfunction parseStaticArray(abiType: string) {\n const matches = abiType.match(/^(\\w+)\\[(\\d+)\\]$/);\n if (!matches) return null;\n return {\n elementType: matches[1],\n staticLength: Number.parseInt(matches[2]),\n };\n}\n\n/**\n * Resolve an abi or user type into a SchemaType and RenderType\n */\nexport function resolveAbiOrUserType(\n abiOrUserType: string,\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): {\n schemaType: SchemaType;\n renderType: RenderType;\n} {\n // abi types which directly mirror a SchemaType\n if (abiOrUserType in AbiTypeToSchemaType) {\n const schemaType = AbiTypeToSchemaType[abiOrUserType];\n return {\n schemaType,\n renderType: getSchemaTypeInfo(schemaType),\n };\n }\n // static arrays\n const staticArray = parseStaticArray(abiOrUserType);\n if (staticArray) {\n if (staticArray.elementType in AbiTypeToSchemaType) {\n return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);\n } else {\n throw new Error(\"Static arrays of user types are not supported\");\n }\n }\n // user types\n return getUserTypeInfo(abiOrUserType, config, solidityUserTypes);\n}\n\n/**\n * Get the required import for SchemaType|userType (`undefined` means that no import is required)\n */\nexport function importForAbiOrUserType(\n abiOrUserType: string,\n usedInDirectory: string,\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): ImportDatum | undefined {\n // abi types which directly mirror a SchemaType\n if (abiOrUserType in AbiTypeToSchemaType) {\n return undefined;\n }\n // static arrays\n const staticArray = parseStaticArray(abiOrUserType);\n if (staticArray) {\n return undefined;\n }\n // user-defined types in a user-provided file\n if (abiOrUserType in solidityUserTypes) {\n // these types can have a library name as their import symbol\n const solidityUserType = solidityUserTypes[abiOrUserType];\n const symbol = solidityUserType.importSymbol;\n if (solidityUserType.isRelativePath) {\n return {\n symbol,\n fromPath: solidityUserType.fromPath,\n usedInPath: usedInDirectory,\n };\n } else {\n return {\n symbol,\n path: solidityUserType.fromPath,\n };\n }\n }\n // other user types\n return {\n symbol: abiOrUserType,\n fromPath: config.codegen.userTypesFilename,\n usedInPath: usedInDirectory,\n };\n}\n\nexport function getSchemaTypeInfo(schemaType: SchemaType): RenderType {\n const staticByteLength = getStaticByteLength(schemaType);\n const isDynamic = staticByteLength === 0;\n const typeId = SchemaTypeToAbiType[schemaType];\n return {\n typeId,\n typeWithLocation: isDynamic ? typeId + \" memory\" : typeId,\n enumName: SchemaType[schemaType],\n staticByteLength,\n isDynamic,\n typeWrap: \"\",\n typeUnwrap: \"\",\n internalTypeId: typeId,\n };\n}\n\nexport function getUserTypeInfo(\n userType: string,\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): {\n schemaType: SchemaType;\n renderType: RenderType;\n} {\n // enums\n if (userType in config.enums) {\n const schemaType = SchemaType.UINT8;\n const staticByteLength = getStaticByteLength(schemaType);\n const isDynamic = staticByteLength === 0;\n const typeId = userType;\n return {\n schemaType,\n renderType: {\n typeId,\n typeWithLocation: typeId,\n enumName: SchemaType[schemaType],\n staticByteLength,\n isDynamic,\n typeWrap: `${userType}`,\n typeUnwrap: `uint8`,\n internalTypeId: `${SchemaTypeToAbiType[schemaType]}`,\n },\n };\n }\n // user-defined types\n if (userType in solidityUserTypes) {\n if (!(userType in solidityUserTypes)) {\n throw new Error(`User type \"${userType}\" not found in MUD config`);\n }\n const solidityUserType = solidityUserTypes[userType];\n const typeId = solidityUserType.typeId;\n const schemaType = AbiTypeToSchemaType[solidityUserType.internalTypeId];\n return {\n schemaType,\n renderType: {\n typeId,\n typeWithLocation: typeId,\n enumName: SchemaType[schemaType],\n staticByteLength: getStaticByteLength(schemaType),\n isDynamic: false,\n typeWrap: `${typeId}.wrap`,\n typeUnwrap: `${typeId}.unwrap`,\n internalTypeId: solidityUserType.internalTypeId,\n },\n };\n }\n // invalid\n throw new Error(`User type \"${userType}\" does not exist`);\n}\n\nfunction getStaticArrayTypeInfo(abiType: string, elementType: string, staticLength: number) {\n const internalTypeId = elementType + \"[]\";\n const schemaType = AbiTypeToSchemaType[internalTypeId];\n return {\n schemaType,\n renderType: {\n typeId: abiType,\n typeWithLocation: `${abiType} memory`,\n enumName: SchemaType[schemaType],\n staticByteLength: 0,\n isDynamic: true,\n typeWrap: `toStaticArray_${elementType}_${staticLength}`,\n typeUnwrap: `fromStaticArray_${elementType}_${staticLength}`,\n typeWrappingData: {\n kind: \"staticArray\",\n elementType,\n staticLength,\n },\n internalTypeId,\n },\n } as const;\n}\n","import { posixPath, renderList, renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { TableOptions } from \"./tableOptions\";\n\n/**\n * Returns Solidity code for table index file that imports all codegen tables\n * @param options table definitions\n * @returns string of Solidity code\n */\nexport function renderTableIndex(options: TableOptions[]) {\n return `\n ${renderedSolidityHeader}\n\n ${renderList(options, ({ outputPath, tableName, renderOptions: { structName } }) => {\n const imports = [tableName];\n if (structName) imports.push(structName);\n\n return `import { ${imports.join(\", \")} } from \"./${posixPath(outputPath)}\";`;\n })}\n `;\n}\n","import { renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { staticAbiTypeToByteLength, staticAbiTypes } from \"@latticexyz/schema-type/internal\";\nimport { renderTightCoderDecode } from \"./renderFunctions\";\n\n/**\n * Renders `DecodeSlice` library with the necessary header and imports,\n * which provides methods for decoding `Slice` into arrays of all primitive types\n * @returns string of Solidity code\n */\nexport function renderDecodeSlice() {\n return `\n ${renderedSolidityHeader}\n import { TightCoder } from \"./TightCoder.sol\";\n import { Slice } from \"../Slice.sol\";\n\n /**\n * @title DecodeSlice Library \n * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)\n * @notice A library for decoding slices of data into specific data types.\n * @dev This library provides functions for decoding slices into arrays of basic uint types.\n */\n library DecodeSlice {\n ${staticAbiTypes\n .map((staticAbiType) =>\n renderTightCoderDecode({\n internalTypeId: staticAbiType,\n staticByteLength: staticAbiTypeToByteLength[staticAbiType],\n }),\n )\n .join(\"\\n\")}\n }\n `;\n}\n","import { RenderType, getLeftPaddingBits } from \"@latticexyz/common/codegen\";\n\n/**\n * Renders `decodeArray_*` method for decoding `Slice` into the array of provided primitive type\n * @param element name and byte length of the primitive type\n * @returns string of Solidity code\n */\nexport function renderTightCoderDecode(element: Pick<RenderType, \"internalTypeId\" | \"staticByteLength\">) {\n return `\n /**\n * @notice Decodes a slice into an array of ${element.internalTypeId}.\n * @dev Uses TightCoder for initial decoding, and then assembly for memory conversion.\n * @param _input The slice to decode.\n * @return _output The decoded array of ${element.internalTypeId}.\n */\n function decodeArray_${element.internalTypeId}(\n Slice _input\n ) internal pure returns (\n ${element.internalTypeId}[] memory _output\n ) {\n bytes32[] memory _genericArray = TightCoder.decode(\n _input,\n ${element.staticByteLength},\n ${getLeftPaddingBits(element)}\n );\n assembly {\n _output := _genericArray\n }\n }\n `;\n}\n\n/**\n * Renders `encode` method for encoding the array of provided primitive type into `Slice`\n * @param element name and byte length of the primitive type\n * @returns string of Solidity code\n */\nexport function renderTightCoderEncode(element: Pick<RenderType, \"internalTypeId\" | \"staticByteLength\">) {\n return `\n\n /**\n * @notice Encodes an array of ${element.internalTypeId} into a tightly packed bytes representation.\n * @param _input The array of ${element.internalTypeId} values to be encoded.\n * @return The resulting tightly packed bytes representation of the input array.\n */\n function encode(${element.internalTypeId}[] memory _input) internal pure returns (bytes memory) {\n bytes32[] memory _genericArray;\n assembly {\n _genericArray := _input\n }\n return TightCoder.encode(\n _genericArray,\n ${element.staticByteLength},\n ${getLeftPaddingBits(element)}\n );\n }\n `;\n}\n","import { renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { staticAbiTypeToByteLength, staticAbiTypes } from \"@latticexyz/schema-type/internal\";\nimport { renderTightCoderEncode } from \"./renderFunctions\";\n\n/**\n * Renders `EncodeArray` library with the necessary header and imports,\n * which provides methods for encoding arrays of all primitive types into `Slice`\n * @returns string of Solidity code\n */\nexport function renderEncodeArray() {\n return `\n ${renderedSolidityHeader}\n import { TightCoder } from \"./TightCoder.sol\";\n\n /**\n * @title EncodeArray \n * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)\n * @dev This library provides utilities for encoding arrays into tightly packed bytes representations.\n */\n library EncodeArray {\n ${staticAbiTypes\n .map((staticAbiType) =>\n renderTightCoderEncode({\n internalTypeId: staticAbiType,\n staticByteLength: staticAbiTypeToByteLength[staticAbiType],\n }),\n )\n .join(\"\\n\")}\n }\n `;\n}\n","import { renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { staticAbiTypes } from \"@latticexyz/schema-type/internal\";\n\nexport function renderTightCoderAutoTestFunction({ typeId }: { typeId: string }) {\n return `\n function testEncodeDecodeArray_${typeId}(\n ${typeId} val0,\n ${typeId} val1,\n ${typeId} val2\n ) public {\n ${typeId}[] memory input = new ${typeId}[](3);\n input[0] = val0;\n input[1] = val1;\n input[2] = val2;\n\n bytes memory encoded = EncodeArray.encode(input);\n assertEq(encoded, abi.encodePacked(val0, val1, val2));\n\n ${typeId}[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_${typeId}();\n assertEq(decoded.length, 3);\n assertEq(decoded[0], val0);\n assertEq(decoded[1], val1);\n assertEq(decoded[2], val2);\n }\n `;\n}\n\nexport function renderTightCoderAutoTest() {\n return `\n ${renderedSolidityHeader}\n\n import { Test } from \"forge-std/Test.sol\";\n import { EncodeArray } from \"../../src/tightcoder/EncodeArray.sol\";\n import { SliceLib } from \"../../src/Slice.sol\";\n\n contract TightCoderAutoTest is Test {\n ${staticAbiTypes.map((staticAbiType) => renderTightCoderAutoTestFunction({ typeId: staticAbiType })).join(\"\")}\n }\n `;\n}\n"],"mappings":"AAAA,OACE,mBAAAA,EACA,oBAAAC,GAGA,yBAAAC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AA;AAAA;AAAA,QAOEC,GAAe,IAAKI,GAAkBH,GAAiC,CAAE,OAAQG,CAAc,CAAC,CAAC,EAAE,KAAK,EAAE;AAAA;AAAA,GAGlH","names":["renderArguments","renderCommonData","renderWithFieldSuffix","renderWithStore","renderFieldMethods","options","storeArgument","_typedTableId","_typedKeyArgs","_keyTupleDefinition","result","schemaIndex","field","_typedFieldName","_methodNameSuffix","_typedStore","_store","_commentSuffix","_methodNamePrefix","renderDecodeFieldSingle","externalArguments","setFieldMethod","encodeFieldSingle","renderEncodeFieldSingle","internalArguments","portionData","fieldPortionData","dynamicSchemaIndex","typeWrappingData","renderCastStaticBytesToType","func","renderDecodeValueType","offset","staticByteLength","innerSlice","staticBytes","internalTypeId","bits","name","elementFieldData","isDynamic","arrayElement","renderArguments","renderCommonData","renderList","renderWithStore","renderRecordMethods","options","structName","storeArgument","_typedTableId","_typedKeyArgs","_keyTupleDefinition","renderCommonData","result","renderWithStore","_typedStore","_store","_commentSuffix","_methodNamePrefix","renderArguments","renderDecodedRecord","_useExplicitFieldLayout","externalArguments","name","typeWithLocation","internalArguments","renderRecordData","renderDecodeFunctions","namePrefix","renderDeleteRecordMethods","fields","staticFields","dynamicFields","renderedDecodedRecord","fieldNamePrefix","staticOffsets","_acc","index","field","renderList","renderDecodeValueType","renderDecodeDynamicFieldPartial","typeId","arrayElement","typeWrap","renderArguments","renderCommonData","renderList","renderImports","renderTableId","renderTypeHelpers","renderWithStore","renderedSolidityHeader","LayoutOffsets","renderFieldLayout","fields","encodeFieldLayout","staticFields","isDynamic","numDynamicFields","fieldLayout","totalLength","i","staticByteLength","LayoutOffsets","keySchemaToHex","valueSchemaToHex","renderTable","options","imports","libraryName","structName","staticResourceData","storeImportPath","fields","staticFields","dynamicFields","withRecordMethods","storeArgument","keyTuple","_typedTableId","_typedKeyArgs","_keyTupleDefinition","renderCommonData","renderedSolidityHeader","renderImports","renderList","name","typeId","renderTableId","renderFieldLayout","field","keyElement","index","renderWithStore","_typedStore","_store","_commentSuffix","_methodNamePrefix","renderArguments","renderFieldMethods","renderRecordMethods","renderDeleteRecordMethods","renderEncodeStatic","renderEncodeLengths","renderEncodeDynamic","typeWithLocation","renderRecordData","renderTypeHelpers","arrayElement","renderEncodeFieldSingle","renderEnums","renderTypesFromConfig","config","fs","path","formatAndWriteSolidity","loadAndExtractUserTypes","path","SchemaTypeArrayToElement","AbiTypeToSchemaType","getStaticByteLength","SchemaType","SchemaTypeToAbiType","parseStaticArray","abiType","matches","resolveAbiOrUserType","abiOrUserType","config","solidityUserTypes","schemaType","getSchemaTypeInfo","staticArray","getStaticArrayTypeInfo","getUserTypeInfo","importForAbiOrUserType","usedInDirectory","solidityUserType","symbol","staticByteLength","isDynamic","typeId","userType","elementType","staticLength","internalTypeId","getKeySchema","getValueSchema","getTableOptions","config","solidityUserTypes","table","keySchema","valueSchema","withStruct","withRecordMethods","withSuffixlessFieldMethods","imports","keyTuple","name","field","abiOrUserType","renderType","resolveAbiOrUserType","importDatum","importForAbiOrUserType","fields","schemaType","elementType","SchemaTypeArrayToElement","getSchemaTypeInfo","staticFields","isDynamic","dynamicFields","staticResourceData","path","posixPath","renderList","renderedSolidityHeader","renderTableIndex","options","outputPath","tableName","structName","imports","mapObject","tablegen","rootDir","config","remappings","outputDirectory","path","solidityUserTypes","loadAndExtractUserTypes","type","allTableOptions","getTableOptions","uniqueTableDirectories","outputPath","tableDir","fs","renderOptions","fullOutputPath","output","renderTable","formatAndWriteSolidity","renderTableIndex","renderTypesFromConfig","renderedSolidityHeader","staticAbiTypeToByteLength","staticAbiTypes","getLeftPaddingBits","renderTightCoderDecode","element","renderTightCoderEncode","renderDecodeSlice","renderedSolidityHeader","staticAbiTypes","staticAbiType","renderTightCoderDecode","staticAbiTypeToByteLength","renderedSolidityHeader","staticAbiTypeToByteLength","staticAbiTypes","renderEncodeArray","renderedSolidityHeader","staticAbiTypes","staticAbiType","renderTightCoderEncode","staticAbiTypeToByteLength","renderedSolidityHeader","staticAbiTypes","renderTightCoderAutoTestFunction","typeId","renderTightCoderAutoTest","staticAbiType"]}
|
1
|
+
{"version":3,"sources":["../ts/codegen/field.ts","../ts/codegen/record.ts","../ts/codegen/renderTable.ts","../ts/constants.ts","../ts/codegen/renderFieldLayout.ts","../ts/codegen/renderTypesFromConfig.ts","../ts/codegen/tablegen.ts","../ts/codegen/tableOptions.ts","../ts/codegen/userType.ts","../ts/codegen/renderTableIndex.ts","../ts/codegen/tightcoder/renderDecodeSlice.ts","../ts/codegen/tightcoder/renderFunctions.ts","../ts/codegen/tightcoder/renderEncodeArray.ts","../ts/codegen/tightcoder/renderTightCoderAutoTest.ts"],"sourcesContent":["import {\n renderArguments,\n renderCommonData,\n RenderField,\n RenderType,\n renderWithFieldSuffix,\n renderWithStore,\n} from \"@latticexyz/common/codegen\";\nimport { RenderTableOptions } from \"./types\";\n\n/**\n * Returns Solidity code for all the field-specific table methods (get, set, push, pop, etc.)\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nexport function renderFieldMethods(options: RenderTableOptions): string {\n const storeArgument = options.storeArgument;\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n let result = \"\";\n for (const [schemaIndex, field] of options.fields.entries()) {\n if (!options.withDynamicFieldMethods && field.isDynamic) {\n continue;\n }\n\n // For dynamic fields, compute the field index relative to the end of the static fields\n const _typedFieldName = `${field.typeWithLocation} ${field.name}`;\n\n if (options.withGetters) {\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}get${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal view returns (${_typedFieldName}) {\n ${_keyTupleDefinition}\n ${\n field.isDynamic\n ? `bytes memory _blob = ${_store}.getDynamicField(\n _tableId,\n _keyTuple,\n ${schemaIndex - options.staticFields.length}\n );`\n : `bytes32 _blob = ${_store}.getStaticField(\n _tableId,\n _keyTuple,\n ${schemaIndex},\n _fieldLayout\n );`\n }\n return ${renderDecodeFieldSingle(field)};\n }\n `,\n ),\n );\n }\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(storeArgument, ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => {\n const externalArguments = renderArguments([_typedStore, _typedTableId, _typedKeyArgs, _typedFieldName]);\n const setFieldMethod = field.isDynamic ? \"setDynamicField\" : \"setStaticField\";\n const encodeFieldSingle = renderEncodeFieldSingle(field);\n const internalArguments = field.isDynamic\n ? `_tableId, _keyTuple, ${schemaIndex - options.staticFields.length}, ${encodeFieldSingle}`\n : `_tableId, _keyTuple, ${schemaIndex}, ${encodeFieldSingle}, _fieldLayout`;\n\n return `\n /**\n * @notice Set ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}set${_methodNameSuffix}(${externalArguments}) internal {\n ${_keyTupleDefinition}\n ${_store}.${setFieldMethod}(${internalArguments});\n }\n `;\n }),\n );\n\n if (field.isDynamic) {\n const portionData = fieldPortionData(field);\n const dynamicSchemaIndex = schemaIndex - options.staticFields.length;\n const { typeWrappingData } = field;\n\n if (options.withGetters) {\n if (typeWrappingData && typeWrappingData.kind === \"staticArray\") {\n result += renderWithFieldSuffix(\n options.withSuffixlessFieldMethods,\n field.name,\n (_methodNameSuffix) =>\n `\n // The length of ${field.name}\n uint256 constant length${_methodNameSuffix} = ${typeWrappingData.staticLength};\n `,\n );\n } else {\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get the length of ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal view returns (uint256) {\n ${_keyTupleDefinition}\n uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex});\n unchecked {\n return _byteLength / ${portionData.elementLength};\n }\n }\n `,\n ),\n );\n }\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get an item of ${field.name}${_commentSuffix}.\n * @dev Reverts with Store_IndexOutOfBounds if \\`_index\\` is out of bounds for the array.\n */\n function ${_methodNamePrefix}getItem${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n \"uint256 _index\",\n ])}) internal view returns (${portionData.typeWithLocation}) {\n ${_keyTupleDefinition}\n\n ${\n // If the index is within the static length,\n // but ahead of the dynamic length, return zero\n typeWrappingData && typeWrappingData.kind === \"staticArray\" && field.arrayElement\n ? `\n uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex});\n uint256 dynamicLength = _byteLength / ${portionData.elementLength};\n uint256 staticLength = ${typeWrappingData.staticLength};\n\n if (_index < staticLength && _index >= dynamicLength) {\n return ${renderCastStaticBytesToType(field.arrayElement, `bytes${field.arrayElement.staticByteLength}(new bytes(0))`)};\n }`\n : ``\n }\n\n unchecked {\n bytes memory _blob = ${_store}.getDynamicFieldSlice(\n _tableId,\n _keyTuple,\n ${dynamicSchemaIndex},\n _index * ${portionData.elementLength},\n (_index + 1) * ${portionData.elementLength}\n );\n return ${portionData.decoded};\n }\n }\n `,\n ),\n );\n }\n\n if (!typeWrappingData || typeWrappingData.kind !== \"staticArray\") {\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Push ${portionData.title} to ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}push${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n `${portionData.typeWithLocation} ${portionData.name}`,\n ])}) internal {\n ${_keyTupleDefinition}\n ${_store}.pushToDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.encoded});\n }\n `,\n ),\n );\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Pop ${portionData.title} from ${field.name}${_commentSuffix}.\n */\n function ${_methodNamePrefix}pop${_methodNameSuffix}(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal {\n ${_keyTupleDefinition}\n ${_store}.popFromDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.elementLength});\n }\n `,\n ),\n );\n }\n\n result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) =>\n renderWithStore(storeArgument, ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => {\n const externalArguments = renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n \"uint256 _index\",\n `${portionData.typeWithLocation} ${portionData.name}`,\n ]);\n\n const internalArguments = `\n _tableId,\n _keyTuple,\n ${dynamicSchemaIndex},\n uint40(_index * ${portionData.elementLength}),\n uint40(_encoded.length),\n _encoded \n `;\n\n return `\n /**\n * @notice Update ${portionData.title} of ${field.name}${_commentSuffix} at \\`_index\\`.\n */\n function ${_methodNamePrefix}update${_methodNameSuffix}(${externalArguments}) internal {\n ${_keyTupleDefinition}\n unchecked {\n bytes memory _encoded = ${portionData.encoded};\n ${_store}.spliceDynamicData(${internalArguments});\n }\n }\n `;\n }),\n );\n }\n }\n return result;\n}\n\n/**\n * Returns Solidity code for how to encode a particular field into bytes before storing onchain\n * @param field RenderField\n * @returns string of Solidity code\n */\nexport function renderEncodeFieldSingle(field: RenderField) {\n let func;\n if (field.arrayElement) {\n func = \"EncodeArray.encode\";\n } else if (field.isDynamic) {\n func = \"bytes\";\n } else {\n func = \"abi.encodePacked\";\n }\n return `${func}(${field.typeUnwrap}(${field.name}))`;\n}\n\n/**\n * Returns Solidity code for decoding a bytes value into its Solidity primitive type\n * @param field description of field type\n * @param offset byte-length offset of value in encoded bytes\n * @returns string of Solidity code\n */\nexport function renderDecodeValueType(field: RenderType, offset: number) {\n const { staticByteLength } = field;\n\n const innerSlice = `Bytes.getBytes${staticByteLength}(_blob, ${offset})`;\n\n return renderCastStaticBytesToType(field, innerSlice);\n}\n\n/**\n * Returns Solidity code for how to cast a bytesN value to a particular type, which is assumed to have the same byte length\n * @param field description of resulting field type\n * @param staticBytes bytesN value\n * @returns string of Solidity code\n */\nfunction renderCastStaticBytesToType(field: RenderType, staticBytes: string) {\n const { staticByteLength, internalTypeId } = field;\n const bits = staticByteLength * 8;\n\n let result;\n if (internalTypeId.match(/^uint\\d{1,3}$/) || internalTypeId === \"address\") {\n result = `${internalTypeId}(${staticBytes})`;\n } else if (internalTypeId.match(/^int\\d{1,3}$/)) {\n result = `${internalTypeId}(uint${bits}(${staticBytes}))`;\n } else if (internalTypeId.match(/^bytes\\d{1,2}$/)) {\n result = staticBytes;\n } else if (internalTypeId === \"bool\") {\n result = `_toBool(uint8(${staticBytes}))`;\n } else {\n throw new Error(`Unknown value type id ${internalTypeId}`);\n }\n return `${field.typeWrap}(${result})`;\n}\n\ninterface FieldPortionData {\n /** Fully-qualified name of the user-defined type (may include a library name as prefix), followed by location (none/memory/storage) */\n typeWithLocation: string;\n /** Name of the field portion variable */\n name: string;\n /** Solidity code which encodes the field portion variable into bytes (for storing onchain) */\n encoded: string;\n /** Solidity code which decodes `_blob` variable into the field portion variable's type */\n decoded: string;\n /** Description of the field portion kind (\"an element\" or \"a slice\") */\n title: string;\n /** Byte length of array elements for arrays, 1 otherwise */\n elementLength: number;\n}\n\n/**\n * Returns data to describe either an array element, or a bytes slice, depending on the provided field type\n */\nfunction fieldPortionData(field: RenderField): FieldPortionData {\n if (field.arrayElement) {\n const name = \"_element\";\n const elementFieldData = { ...field.arrayElement, arrayElement: undefined, name };\n return {\n typeWithLocation: field.arrayElement.typeWithLocation,\n name,\n encoded: renderEncodeFieldSingle(elementFieldData),\n decoded: renderDecodeFieldSingle(elementFieldData),\n title: \"an element\",\n elementLength: field.arrayElement.staticByteLength,\n };\n } else {\n const name = \"_slice\";\n const elementFieldData = { ...field, name };\n return {\n typeWithLocation: `${field.typeId} memory`,\n name,\n encoded: renderEncodeFieldSingle(elementFieldData),\n decoded: renderDecodeFieldSingle(elementFieldData),\n title: \"a slice\",\n elementLength: 1,\n };\n }\n}\n\n/**\n * Returns Solidity code for how to decode `_blob` variable into the particular field type\n * @param field RenderField\n * @returns string of Solidity code\n */\nfunction renderDecodeFieldSingle(field: RenderField) {\n const { isDynamic, arrayElement } = field;\n if (arrayElement) {\n // arrays\n return `${field.typeWrap}(\n SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_${arrayElement.internalTypeId}()\n )`;\n } else if (isDynamic) {\n // bytes/string\n return `${field.typeWrap}(${field.internalTypeId}(_blob))`;\n } else {\n return renderCastStaticBytesToType(field, `bytes${field.staticByteLength}(_blob)`);\n }\n}\n","import {\n RenderDynamicField,\n renderArguments,\n renderCommonData,\n renderList,\n renderWithStore,\n} from \"@latticexyz/common/codegen\";\nimport { renderDecodeValueType } from \"./field\";\nimport { RenderTableOptions } from \"./types\";\n\n/**\n * Returns Solidity code for whole-record methods (get, set)\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nexport function renderRecordMethods(options: RenderTableOptions) {\n const { structName, storeArgument } = options;\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n let result = \"\";\n\n if (options.withGetters) {\n result += renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Get the full data${_commentSuffix}.\n */\n function ${_methodNamePrefix}get(${renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n ])}) internal view returns (${renderDecodedRecord(options)}) {\n ${_keyTupleDefinition}\n \n (\n bytes memory _staticData,\n EncodedLengths _encodedLengths,\n bytes memory _dynamicData\n ) = ${_store}.getRecord(_tableId, _keyTuple, _fieldLayout);\n return decode(_staticData, _encodedLengths, _dynamicData);\n }\n `,\n );\n }\n\n result += renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => {\n const externalArguments = renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n renderArguments(options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`)),\n ]);\n\n const internalArguments =\n \"_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData\" +\n (_useExplicitFieldLayout ? \", _fieldLayout\" : \"\");\n\n return `\n /** \n * @notice Set the full data using individual values${_commentSuffix}.\n */\n function ${_methodNamePrefix}set(${externalArguments}) internal {\n ${renderRecordData(options)}\n\n ${_keyTupleDefinition}\n\n ${_store}.setRecord(${internalArguments});\n }\n `;\n },\n );\n\n if (structName !== undefined) {\n result += renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => {\n const externalArguments = renderArguments([\n _typedStore,\n _typedTableId,\n _typedKeyArgs,\n `${structName} memory _table`,\n ]);\n\n const internalArguments =\n \"_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData\" +\n (_useExplicitFieldLayout ? \", _fieldLayout\" : \"\");\n\n return `\n /**\n * @notice Set the full data using the data struct${_commentSuffix}.\n */\n function ${_methodNamePrefix}set(${externalArguments}) internal {\n ${renderRecordData(options, \"_table.\")}\n\n ${_keyTupleDefinition}\n\n ${_store}.setRecord(${internalArguments});\n }\n `;\n },\n );\n }\n\n result += renderDecodeFunctions(options);\n\n return result;\n}\n\n/**\n * Returns Solidity code to prepare variables needed to store encoded record on chain\n * @param options RenderTableOptions\n * @param namePrefix optional field name prefix to change how the field is accessed\n * @returns string of Solidity code\n */\nexport function renderRecordData(options: RenderTableOptions, namePrefix = \"\") {\n let result = \"\";\n if (options.staticFields.length > 0) {\n result += `\n bytes memory _staticData = encodeStatic(\n ${renderArguments(options.staticFields.map(({ name }) => `${namePrefix}${name}`))}\n );\n `;\n } else {\n result += `bytes memory _staticData;`;\n }\n\n if (options.dynamicFields.length > 0) {\n result += `\n EncodedLengths _encodedLengths = encodeLengths(\n ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))}\n );\n bytes memory _dynamicData = encodeDynamic(\n ${renderArguments(options.dynamicFields.map(({ name }) => `${namePrefix}${name}`))}\n );\n `;\n } else {\n result += `\n EncodedLengths _encodedLengths;\n bytes memory _dynamicData;\n `;\n }\n\n return result;\n}\n\n/**\n * Returns Solidity code for the delete record method\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nexport function renderDeleteRecordMethods(options: RenderTableOptions) {\n const { storeArgument } = options;\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n return renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix, _useExplicitFieldLayout }) => {\n const externalArguments = renderArguments([_typedStore, _typedTableId, _typedKeyArgs]);\n const internalArguments = \"_tableId, _keyTuple\" + (_useExplicitFieldLayout ? \", _fieldLayout\" : \"\");\n\n return `\n /** \n * @notice Delete all data for given keys${_commentSuffix}.\n */\n function ${_methodNamePrefix}deleteRecord(${externalArguments}) internal {\n ${_keyTupleDefinition}\n ${_store}.deleteRecord(${internalArguments});\n }\n `;\n },\n );\n}\n\n/**\n * Returns Solidity code for the `decode` function that parses a bytes blob into the typed table data\n * @param options RenderTableOptions\n * @returns string of Solidity code\n */\nfunction renderDecodeFunctions({ structName, fields, staticFields, dynamicFields }: RenderTableOptions) {\n // either set struct properties, or just variables\n const renderedDecodedRecord = structName\n ? `${structName} memory _table`\n : renderArguments(fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));\n const fieldNamePrefix = structName ? \"_table.\" : \"\";\n\n // Static field offsets\n const staticOffsets = staticFields.map(() => 0);\n let _acc = 0;\n for (const [index, field] of staticFields.entries()) {\n staticOffsets[index] = _acc;\n _acc += field.staticByteLength;\n }\n\n let result = \"\";\n\n if (staticFields.length > 0) {\n result += `\n /**\n * @notice Decode the tightly packed blob of static data using this table's field layout.\n */\n function decodeStatic(bytes memory _blob) internal pure returns (${renderArguments(\n staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) {\n ${renderList(\n staticFields,\n (field, index) => `\n ${field.name} = ${renderDecodeValueType(field, staticOffsets[index])};\n `,\n )}\n }\n `;\n }\n\n if (dynamicFields.length > 0) {\n result += `\n /**\n * @notice Decode the tightly packed blob of dynamic data using the encoded lengths.\n */\n function decodeDynamic(EncodedLengths _encodedLengths, bytes memory _blob) internal pure returns (${renderArguments(\n dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) {\n ${renderList(\n dynamicFields,\n // unchecked is only dangerous if _encodedLengths (and _blob) is invalid,\n // but it's assumed to be valid, and this function is meant to be mostly used internally\n (field, index) => {\n if (index === 0) {\n return `\n uint256 _start;\n uint256 _end;\n unchecked {\n _end = _encodedLengths.atIndex(${index});\n }\n ${field.name} = ${renderDecodeDynamicFieldPartial(field)};\n `;\n } else {\n return `\n _start = _end;\n unchecked {\n _end += _encodedLengths.atIndex(${index});\n }\n ${field.name} = ${renderDecodeDynamicFieldPartial(field)};\n `;\n }\n },\n )}\n }\n `;\n }\n\n result += `\n /**\n * @notice Decode the tightly packed blobs using this table's field layout.\n * ${staticFields.length > 0 ? \"@param _staticData Tightly packed static fields.\" : \"\"}\n * ${dynamicFields.length > 0 ? \"@param _encodedLengths Encoded lengths of dynamic fields.\" : \"\"}\n * ${dynamicFields.length > 0 ? \"@param _dynamicData Tightly packed dynamic fields.\" : \"\"}\n */\n function decode(\n bytes memory ${staticFields.length > 0 ? \"_staticData\" : \"\"},\n EncodedLengths ${dynamicFields.length > 0 ? \"_encodedLengths\" : \"\"},\n bytes memory ${dynamicFields.length > 0 ? \"_dynamicData\" : \"\"}\n ) internal pure returns (${renderedDecodedRecord}) {\n `;\n\n if (staticFields.length > 0) {\n result += `\n (${renderArguments(staticFields.map((field) => `${fieldNamePrefix}${field.name}`))}) = decodeStatic(_staticData);\n `;\n }\n if (dynamicFields.length > 0) {\n result += `\n (${renderArguments(\n dynamicFields.map((field) => `${fieldNamePrefix}${field.name}`),\n )}) = decodeDynamic(_encodedLengths, _dynamicData);\n `;\n }\n\n result += `\n }\n `;\n\n return result;\n}\n\n/**\n * Returns Solidity code for the return value of a record getter\n * @param options RenderDynamicField\n * @returns string of Solidity code\n */\nfunction renderDecodedRecord({ structName, fields }: RenderTableOptions) {\n if (structName) {\n return `${structName} memory _table`;\n } else {\n return renderArguments(fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));\n }\n}\n\n/**\n * Returns Solidity code for decoding onchain bytes into typed field data\n * @param options RenderDynamicField\n * @returns string of Solidity code\n */\nfunction renderDecodeDynamicFieldPartial(field: RenderDynamicField) {\n const { typeId, arrayElement, typeWrap } = field;\n if (arrayElement) {\n // arrays\n return `${typeWrap}(\n SliceLib.getSubslice(_blob, _start, _end).decodeArray_${arrayElement.typeId}()\n )`;\n } else {\n // bytes/string\n return `${typeWrap}(\n ${typeId}(\n SliceLib.getSubslice(_blob, _start, _end).toBytes()\n )\n )`;\n }\n}\n","import {\n RenderDynamicField,\n renderArguments,\n renderCommonData,\n renderList,\n renderImports,\n renderTableId,\n renderTypeHelpers,\n renderWithStore,\n renderedSolidityHeader,\n RenderStaticField,\n} from \"@latticexyz/common/codegen\";\nimport { renderEncodeFieldSingle, renderFieldMethods } from \"./field\";\nimport { renderDeleteRecordMethods, renderRecordData, renderRecordMethods } from \"./record\";\nimport { renderFieldLayout } from \"./renderFieldLayout\";\nimport { RenderTableOptions } from \"./types\";\nimport { KeySchema, ValueSchema, keySchemaToHex, valueSchemaToHex } from \"@latticexyz/protocol-parser/internal\";\n\n/**\n * Renders Solidity code for a MUD table library, using the specified options\n * @param options options for rendering the table\n * @returns string of Solidity code\n */\nexport function renderTable(options: RenderTableOptions) {\n const {\n imports,\n libraryName,\n structName,\n staticResourceData,\n storeImportPath,\n fields,\n staticFields,\n dynamicFields,\n withRecordMethods,\n storeArgument,\n keyTuple,\n } = options;\n\n const { _typedTableId, _typedKeyArgs, _keyTupleDefinition } = renderCommonData(options);\n\n return `\n ${renderedSolidityHeader}\n\n // Import store internals\n import { IStore } from \"${storeImportPath}IStore.sol\";\n import { StoreSwitch } from \"${storeImportPath}StoreSwitch.sol\";\n import { StoreCore } from \"${storeImportPath}StoreCore.sol\";\n import { Bytes } from \"${storeImportPath}Bytes.sol\";\n import { Memory } from \"${storeImportPath}Memory.sol\";\n import { SliceLib } from \"${storeImportPath}Slice.sol\";\n import { EncodeArray } from \"${storeImportPath}tightcoder/EncodeArray.sol\";\n import { FieldLayout } from \"${storeImportPath}FieldLayout.sol\";\n import { Schema } from \"${storeImportPath}Schema.sol\";\n import { EncodedLengths, EncodedLengthsLib } from \"${storeImportPath}EncodedLengths.sol\";\n import { ResourceId } from \"${storeImportPath}ResourceId.sol\";\n\n ${\n imports.length > 0\n ? `\n // Import user types\n ${renderImports(imports)}\n `\n : \"\"\n }\n\n ${\n !structName\n ? \"\"\n : `\n struct ${structName} {\n ${renderList(fields, ({ name, typeId }) => `${typeId} ${name};`)}\n }\n `\n }\n\n library ${libraryName} {\n ${staticResourceData ? renderTableId(staticResourceData) : \"\"}\n \n ${renderFieldLayout(fields)}\n\n // Hex-encoded key schema of (${keyTuple.map((field) => field.internalTypeId).join(\", \")})\n Schema constant _keySchema = Schema.wrap(${keySchemaToHex(\n Object.fromEntries(keyTuple.map((field) => [field.name, field.internalTypeId])) as KeySchema,\n )});\n // Hex-encoded value schema of (${fields.map((field) => field.internalTypeId).join(\", \")})\n Schema constant _valueSchema = Schema.wrap(${valueSchemaToHex(\n Object.fromEntries(fields.map((field) => [field.name, field.internalTypeId])) as ValueSchema,\n )});\n\n /**\n * @notice Get the table's key field names.\n * @return keyNames An array of strings with the names of key fields.\n */\n function getKeyNames() internal pure returns (string[] memory keyNames) {\n keyNames = new string[](${keyTuple.length});\n ${renderList(keyTuple, (keyElement, index) => `keyNames[${index}] = \"${keyElement.name}\";`)}\n }\n\n /**\n * @notice Get the table's value field names.\n * @return fieldNames An array of strings with the names of value fields.\n */\n function getFieldNames() internal pure returns (string[] memory fieldNames) {\n fieldNames = new string[](${fields.length});\n ${renderList(fields, (field, index) => `fieldNames[${index}] = \"${field.name}\";`)}\n }\n\n ${renderWithStore(\n storeArgument,\n ({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => `\n /**\n * @notice Register the table with its config${_commentSuffix}.\n */\n function ${_methodNamePrefix}register(${renderArguments([_typedStore, _typedTableId])}) internal {\n ${_store}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());\n }\n `,\n )}\n\n ${renderFieldMethods(options)}\n\n ${withRecordMethods ? renderRecordMethods(options) : \"\"}\n\n ${renderDeleteRecordMethods(options)}\n\n ${renderEncodeStatic(staticFields)}\n\n ${renderEncodeLengths(dynamicFields)}\n\n ${renderEncodeDynamic(dynamicFields)}\n\n /**\n * @notice Encode all of a record's fields.\n * @return The static (fixed length) data, encoded into a sequence of bytes.\n * @return The lengths of the dynamic fields (packed into a single bytes32 value).\n * @return The dynamic (variable length) data, encoded into a sequence of bytes.\n */\n function encode(${renderArguments(\n options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (bytes memory, EncodedLengths, bytes memory) {\n ${renderRecordData(options)}\n\n return (_staticData, _encodedLengths, _dynamicData);\n }\n \n /**\n * @notice Encode keys as a bytes32 array using this table's field layout.\n */\n function encodeKeyTuple(${renderArguments([_typedKeyArgs])}) internal pure returns (bytes32[] memory) {\n ${_keyTupleDefinition}\n return _keyTuple;\n }\n }\n\n ${renderTypeHelpers(options)}\n `;\n}\n\n/**\n * Renders solidity code for `encodeStatic` method, which encodes the provided fields into a blob for storage\n * (nothing is rendered if static fields array is empty)\n * @param staticFields array of data about static fields to be encoded\n * @returns string of Solidity code\n */\nfunction renderEncodeStatic(staticFields: RenderStaticField[]) {\n if (staticFields.length === 0) return \"\";\n\n return `\n /**\n * @notice Tightly pack static (fixed length) data using this table's schema.\n * @return The static data, encoded into a sequence of bytes.\n */\n function encodeStatic(${renderArguments(\n staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (bytes memory) {\n return abi.encodePacked(${renderArguments(staticFields.map(({ name }) => name))});\n }\n `;\n}\n\n/**\n * Renders solidity code for `encodeLengths` method, which tightly packs the lengths of the provided fields\n * (nothing is rendered if dynamic fields array is empty)\n * @param dynamicFields array of data about dynamic fields to have their lengths encoded\n * @returns string of Solidity code\n */\nfunction renderEncodeLengths(dynamicFields: RenderDynamicField[]) {\n if (dynamicFields.length === 0) return \"\";\n\n return `\n /**\n * @notice Tightly pack dynamic data lengths using this table's schema.\n * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value).\n */\n function encodeLengths(${renderArguments(\n dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (EncodedLengths _encodedLengths) {\n // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits\n unchecked {\n _encodedLengths = EncodedLengthsLib.pack(\n ${renderArguments(\n dynamicFields.map(({ name, arrayElement }) => {\n if (arrayElement) {\n return `${name}.length * ${arrayElement.staticByteLength}`;\n } else {\n return `bytes(${name}).length`;\n }\n }),\n )}\n );\n }\n }\n `;\n}\n\n/**\n * Renders solidity code for `encodeDynamic` method, which encodes the provided fields into a blob for storage\n * (nothing is rendered if dynamic fields array is empty)\n * @param dynamicFields array of data about dynamic fields to be encoded\n * @returns string of Solidity code\n */\nfunction renderEncodeDynamic(dynamicFields: RenderDynamicField[]) {\n if (dynamicFields.length === 0) return \"\";\n\n return `\n /**\n * @notice Tightly pack dynamic (variable length) data using this table's schema.\n * @return The dynamic data, encoded into a sequence of bytes.\n */\n function encodeDynamic(${renderArguments(\n dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`),\n )}) internal pure returns (bytes memory) {\n return abi.encodePacked(${renderArguments(dynamicFields.map((field) => renderEncodeFieldSingle(field)))});\n }\n `;\n}\n","/* Shared constants */\n// Make sure these stay aligned with @latticexyz/store/src/constants.sol\n\n// Total byte length of an EVM word\nexport const WORD_SIZE = 32;\n// Index of the last byte in an EVM word\nexport const WORD_LAST_INDEX = 31;\n// Conversion for bit shifting\nexport const BYTE_TO_BITS = 8;\n\n// Schema's capacity\nexport const MAX_TOTAL_FIELDS = 28;\n// FieldLayout's capacity\nexport const MAX_STATIC_FIELDS = 28;\n// EncodedLengths's capacity\nexport const MAX_DYNAMIC_FIELDS = 5;\n\n// FieldLayout and Schema have the same offsets for metadata\nexport const LayoutOffsets = {\n TOTAL_LENGTH: (WORD_SIZE - 2) * BYTE_TO_BITS,\n NUM_STATIC_FIELDS: (WORD_SIZE - 2 - 1) * BYTE_TO_BITS,\n NUM_DYNAMIC_FIELDS: (WORD_SIZE - 2 - 1 - 1) * BYTE_TO_BITS,\n};\n","import { RenderType } from \"@latticexyz/common/codegen\";\nimport { BYTE_TO_BITS, LayoutOffsets, MAX_DYNAMIC_FIELDS, MAX_TOTAL_FIELDS, WORD_LAST_INDEX } from \"../constants\";\n\ntype FieldLayoutRenderType = Pick<RenderType, \"isDynamic\" | \"staticByteLength\">;\n\n/**\n * Renders Solidity code that defines and initializes `_fieldLayout` constant\n * @param fields array of field data necessary to construct FieldLayout\n * @returns string of Solidity code\n */\nexport function renderFieldLayout(fields: FieldLayoutRenderType[]): string {\n return `FieldLayout constant _fieldLayout = FieldLayout.wrap(${encodeFieldLayout(fields)});`;\n}\n\n// Make sure this logic stays aligned with @latticexyz/store/src/FieldLayout.sol\n/**\n * Returns Solidity hexadecimal which represents the encoded FieldLayout\n * @param fields array of field data necessary to construct FieldLayout\n * @returns string of Solidity code\n */\nfunction encodeFieldLayout(fields: FieldLayoutRenderType[]): string {\n const staticFields = fields.filter(({ isDynamic }) => !isDynamic);\n const numDynamicFields = fields.length - staticFields.length;\n\n let fieldLayout = 0n;\n let totalLength = 0;\n const totalFields = fields.length;\n\n if (totalFields > MAX_TOTAL_FIELDS) throw new Error(\"FieldLayout: too many fields\");\n if (numDynamicFields > MAX_DYNAMIC_FIELDS) throw new Error(\"FieldLayout: too many dynamic fields\");\n\n for (let i = 0; i < staticFields.length; i++) {\n const { isDynamic, staticByteLength } = fields[i];\n if (isDynamic) throw new Error(`FieldLayout: static type after dynamic type`);\n\n totalLength += staticByteLength;\n fieldLayout |= BigInt(staticByteLength) << BigInt((WORD_LAST_INDEX - 4 - i) * BYTE_TO_BITS);\n }\n\n fieldLayout |= BigInt(totalLength) << BigInt(LayoutOffsets.TOTAL_LENGTH);\n fieldLayout |= BigInt(staticFields.length) << BigInt(LayoutOffsets.NUM_STATIC_FIELDS);\n fieldLayout |= BigInt(numDynamicFields) << BigInt(LayoutOffsets.NUM_DYNAMIC_FIELDS);\n\n return `0x${fieldLayout.toString(16).padStart(64, \"0\")}`;\n}\n","import { renderEnums } from \"@latticexyz/common/codegen\";\nimport { Store } from \"../config/v2\";\n\n/**\n * Renders Solidity code for enums defined in the provided config\n */\nexport function renderTypesFromConfig(config: Store) {\n return renderEnums(config.enums);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatAndWriteSolidity, loadAndExtractUserTypes } from \"@latticexyz/common/codegen\";\nimport { getTableOptions } from \"./tableOptions\";\nimport { renderTable } from \"./renderTable\";\nimport { renderTypesFromConfig } from \"./renderTypesFromConfig\";\nimport { renderTableIndex } from \"./renderTableIndex\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\nimport { mapObject } from \"@latticexyz/common/utils\";\n\nexport type TablegenOptions = {\n /**\n * MUD project root directory where all other relative paths are resolved from.\n */\n rootDir: string;\n config: StoreConfig;\n remappings: [string, string][];\n};\n\nexport async function tablegen({ rootDir, config, remappings }: TablegenOptions) {\n const outputDirectory = path.join(rootDir, config.sourceDirectory, config.codegen.outputDirectory);\n const solidityUserTypes = loadAndExtractUserTypes(\n mapObject(config.userTypes, (type) => ({ ...type, internalType: type.type })),\n outputDirectory,\n remappings,\n );\n const allTableOptions = getTableOptions(config, solidityUserTypes);\n\n const uniqueTableDirectories = Array.from(new Set(allTableOptions.map(({ outputPath }) => path.dirname(outputPath))));\n await Promise.all(\n uniqueTableDirectories.map(async (tableDir) => {\n await fs.rm(path.join(outputDirectory, tableDir), { recursive: true, force: true });\n }),\n );\n\n // write tables to files\n await Promise.all(\n allTableOptions.map(async ({ outputPath, renderOptions }) => {\n const fullOutputPath = path.join(outputDirectory, outputPath);\n const output = renderTable(renderOptions);\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated table\");\n }),\n );\n\n // write table index\n if (allTableOptions.length > 0) {\n const fullOutputPath = path.join(outputDirectory, config.codegen.indexFilename);\n const output = renderTableIndex(allTableOptions);\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated table index\");\n }\n\n // write types to file\n if (Object.keys(config.enums).length > 0) {\n const fullOutputPath = path.join(outputDirectory, config.codegen.userTypesFilename);\n const output = renderTypesFromConfig(config);\n await formatAndWriteSolidity(output, fullOutputPath, \"Generated types file\");\n }\n}\n","import path from \"path\";\nimport { SchemaTypeArrayToElement } from \"@latticexyz/schema-type/deprecated\";\nimport {\n ImportDatum,\n RenderDynamicField,\n RenderField,\n RenderKeyTuple,\n RenderStaticField,\n SolidityUserDefinedType,\n} from \"@latticexyz/common/codegen\";\nimport { RenderTableOptions } from \"./types\";\nimport { getSchemaTypeInfo, importForAbiOrUserType, resolveAbiOrUserType } from \"./userType\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\nimport { getKeySchema, getValueSchema } from \"@latticexyz/protocol-parser/internal\";\n\nexport interface TableOptions {\n /** Path where the file is expected to be written (relative to project root) */\n outputPath: string;\n /** Name of the table, as used in filename and library name */\n tableName: string;\n /** Options for `renderTable` function */\n renderOptions: RenderTableOptions;\n}\n\n/**\n * Transforms store config and available solidity user types into useful options for `tablegen` and `renderTable`\n */\nexport function getTableOptions(\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): TableOptions[] {\n const tables = Object.values(config.namespaces).flatMap((namespace) => Object.values(namespace.tables));\n const options = tables.map((table): TableOptions => {\n const keySchema = getKeySchema(table);\n const valueSchema = getValueSchema(table);\n\n // struct adds methods to get/set all values at once\n const withStruct = table.codegen.dataStruct;\n // operate on all fields at once; always render for offchain tables; for only 1 field keep them if struct is also kept\n const withRecordMethods = withStruct || table.type === \"offchainTable\" || Object.keys(valueSchema).length > 1;\n // field methods can include simply get/set if there's only 1 field and no record methods\n const withSuffixlessFieldMethods = !withRecordMethods && Object.keys(valueSchema).length === 1;\n // list of any symbols that need to be imported\n const imports: ImportDatum[] = [];\n\n const keyTuple = Object.entries(keySchema).map(([name, field]): RenderKeyTuple => {\n const abiOrUserType = field.internalType;\n const { renderType } = resolveAbiOrUserType(abiOrUserType, config, solidityUserTypes);\n\n const importDatum = importForAbiOrUserType(\n abiOrUserType,\n table.codegen.outputDirectory,\n config,\n solidityUserTypes,\n );\n if (importDatum) imports.push(importDatum);\n\n return {\n ...renderType,\n name,\n isDynamic: false,\n };\n });\n\n const fields = Object.entries(valueSchema).map(([name, field]): RenderField => {\n const abiOrUserType = field.internalType;\n const { renderType, schemaType } = resolveAbiOrUserType(abiOrUserType, config, solidityUserTypes);\n\n const importDatum = importForAbiOrUserType(\n abiOrUserType,\n table.codegen.outputDirectory,\n config,\n solidityUserTypes,\n );\n if (importDatum) imports.push(importDatum);\n\n const elementType = SchemaTypeArrayToElement[schemaType];\n return {\n ...renderType,\n arrayElement: elementType !== undefined ? getSchemaTypeInfo(elementType) : undefined,\n name,\n };\n });\n\n const staticFields = fields.filter(({ isDynamic }) => !isDynamic) as RenderStaticField[];\n const dynamicFields = fields.filter(({ isDynamic }) => isDynamic) as RenderDynamicField[];\n\n // With tableIdArgument: tableId is a dynamic argument for each method\n // Without tableIdArgument: tableId is a file-level constant generated from `staticResourceData`\n const staticResourceData = table.codegen.tableIdArgument\n ? undefined\n : {\n namespace: table.namespace,\n name: table.name,\n offchainOnly: table.type === \"offchainTable\",\n };\n\n return {\n outputPath: path.join(table.codegen.outputDirectory, `${table.label}.sol`),\n tableName: table.label,\n renderOptions: {\n imports,\n libraryName: table.label,\n structName: withStruct ? table.label + \"Data\" : undefined,\n staticResourceData,\n storeImportPath: config.codegen.storeImportPath,\n keyTuple,\n fields,\n staticFields,\n dynamicFields,\n withGetters: table.type === \"table\",\n withRecordMethods,\n withDynamicFieldMethods: table.type === \"table\",\n withSuffixlessFieldMethods,\n storeArgument: table.codegen.storeArgument,\n },\n };\n });\n\n return options;\n}\n","import {\n AbiTypeToSchemaType,\n getStaticByteLength,\n SchemaType,\n SchemaTypeToAbiType,\n} from \"@latticexyz/schema-type/deprecated\";\nimport { ImportDatum, RenderType, SolidityUserDefinedType } from \"@latticexyz/common/codegen\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\n\nfunction parseStaticArray(abiType: string) {\n const matches = abiType.match(/^(\\w+)\\[(\\d+)\\]$/);\n if (!matches) return null;\n return {\n elementType: matches[1],\n staticLength: Number.parseInt(matches[2]),\n };\n}\n\n/**\n * Resolve an abi or user type into a SchemaType and RenderType\n */\nexport function resolveAbiOrUserType(\n abiOrUserType: string,\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): {\n schemaType: SchemaType;\n renderType: RenderType;\n} {\n // abi types which directly mirror a SchemaType\n if (abiOrUserType in AbiTypeToSchemaType) {\n const schemaType = AbiTypeToSchemaType[abiOrUserType];\n return {\n schemaType,\n renderType: getSchemaTypeInfo(schemaType),\n };\n }\n // static arrays\n const staticArray = parseStaticArray(abiOrUserType);\n if (staticArray) {\n if (staticArray.elementType in AbiTypeToSchemaType) {\n return getStaticArrayTypeInfo(abiOrUserType, staticArray.elementType, staticArray.staticLength);\n } else {\n throw new Error(\"Static arrays of user types are not supported\");\n }\n }\n // user types\n return getUserTypeInfo(abiOrUserType, config, solidityUserTypes);\n}\n\n/**\n * Get the required import for SchemaType|userType (`undefined` means that no import is required)\n */\nexport function importForAbiOrUserType(\n abiOrUserType: string,\n usedInDirectory: string,\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): ImportDatum | undefined {\n // abi types which directly mirror a SchemaType\n if (abiOrUserType in AbiTypeToSchemaType) {\n return undefined;\n }\n // static arrays\n const staticArray = parseStaticArray(abiOrUserType);\n if (staticArray) {\n return undefined;\n }\n // user-defined types in a user-provided file\n if (abiOrUserType in solidityUserTypes) {\n // these types can have a library name as their import symbol\n const solidityUserType = solidityUserTypes[abiOrUserType];\n const symbol = solidityUserType.importSymbol;\n if (solidityUserType.isRelativePath) {\n return {\n symbol,\n fromPath: solidityUserType.fromPath,\n usedInPath: usedInDirectory,\n };\n } else {\n return {\n symbol,\n path: solidityUserType.fromPath,\n };\n }\n }\n // other user types\n return {\n symbol: abiOrUserType,\n fromPath: config.codegen.userTypesFilename,\n usedInPath: usedInDirectory,\n };\n}\n\nexport function getSchemaTypeInfo(schemaType: SchemaType): RenderType {\n const staticByteLength = getStaticByteLength(schemaType);\n const isDynamic = staticByteLength === 0;\n const typeId = SchemaTypeToAbiType[schemaType];\n return {\n typeId,\n typeWithLocation: isDynamic ? typeId + \" memory\" : typeId,\n enumName: SchemaType[schemaType],\n staticByteLength,\n isDynamic,\n typeWrap: \"\",\n typeUnwrap: \"\",\n internalTypeId: typeId,\n };\n}\n\nexport function getUserTypeInfo(\n userType: string,\n config: StoreConfig,\n solidityUserTypes: Record<string, SolidityUserDefinedType>,\n): {\n schemaType: SchemaType;\n renderType: RenderType;\n} {\n // enums\n if (userType in config.enums) {\n const schemaType = SchemaType.UINT8;\n const staticByteLength = getStaticByteLength(schemaType);\n const isDynamic = staticByteLength === 0;\n const typeId = userType;\n return {\n schemaType,\n renderType: {\n typeId,\n typeWithLocation: typeId,\n enumName: SchemaType[schemaType],\n staticByteLength,\n isDynamic,\n typeWrap: `${userType}`,\n typeUnwrap: `uint8`,\n internalTypeId: `${SchemaTypeToAbiType[schemaType]}`,\n },\n };\n }\n // user-defined types\n if (userType in solidityUserTypes) {\n if (!(userType in solidityUserTypes)) {\n throw new Error(`User type \"${userType}\" not found in MUD config`);\n }\n const solidityUserType = solidityUserTypes[userType];\n const typeId = solidityUserType.typeId;\n const schemaType = AbiTypeToSchemaType[solidityUserType.internalTypeId];\n return {\n schemaType,\n renderType: {\n typeId,\n typeWithLocation: typeId,\n enumName: SchemaType[schemaType],\n staticByteLength: getStaticByteLength(schemaType),\n isDynamic: false,\n typeWrap: `${typeId}.wrap`,\n typeUnwrap: `${typeId}.unwrap`,\n internalTypeId: solidityUserType.internalTypeId,\n },\n };\n }\n // invalid\n throw new Error(`User type \"${userType}\" does not exist`);\n}\n\nfunction getStaticArrayTypeInfo(abiType: string, elementType: string, staticLength: number) {\n const internalTypeId = elementType + \"[]\";\n const schemaType = AbiTypeToSchemaType[internalTypeId];\n return {\n schemaType,\n renderType: {\n typeId: abiType,\n typeWithLocation: `${abiType} memory`,\n enumName: SchemaType[schemaType],\n staticByteLength: 0,\n isDynamic: true,\n typeWrap: `toStaticArray_${elementType}_${staticLength}`,\n typeUnwrap: `fromStaticArray_${elementType}_${staticLength}`,\n typeWrappingData: {\n kind: \"staticArray\",\n elementType,\n staticLength,\n },\n internalTypeId,\n },\n } as const;\n}\n","import { posixPath, renderList, renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { TableOptions } from \"./tableOptions\";\n\n/**\n * Returns Solidity code for table index file that imports all codegen tables\n * @param options table definitions\n * @returns string of Solidity code\n */\nexport function renderTableIndex(options: TableOptions[]) {\n return `\n ${renderedSolidityHeader}\n\n ${renderList(options, ({ outputPath, tableName, renderOptions: { structName } }) => {\n const imports = [tableName];\n if (structName) imports.push(structName);\n\n return `import { ${imports.join(\", \")} } from \"./${posixPath(outputPath)}\";`;\n })}\n `;\n}\n","import { renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { staticAbiTypeToByteLength, staticAbiTypes } from \"@latticexyz/schema-type/internal\";\nimport { renderTightCoderDecode } from \"./renderFunctions\";\n\n/**\n * Renders `DecodeSlice` library with the necessary header and imports,\n * which provides methods for decoding `Slice` into arrays of all primitive types\n * @returns string of Solidity code\n */\nexport function renderDecodeSlice() {\n return `\n ${renderedSolidityHeader}\n import { TightCoder } from \"./TightCoder.sol\";\n import { Slice } from \"../Slice.sol\";\n\n /**\n * @title DecodeSlice Library \n * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)\n * @notice A library for decoding slices of data into specific data types.\n * @dev This library provides functions for decoding slices into arrays of basic uint types.\n */\n library DecodeSlice {\n ${staticAbiTypes\n .map((staticAbiType) =>\n renderTightCoderDecode({\n internalTypeId: staticAbiType,\n staticByteLength: staticAbiTypeToByteLength[staticAbiType],\n }),\n )\n .join(\"\\n\")}\n }\n `;\n}\n","import { RenderType, getLeftPaddingBits } from \"@latticexyz/common/codegen\";\n\n/**\n * Renders `decodeArray_*` method for decoding `Slice` into the array of provided primitive type\n * @param element name and byte length of the primitive type\n * @returns string of Solidity code\n */\nexport function renderTightCoderDecode(element: Pick<RenderType, \"internalTypeId\" | \"staticByteLength\">) {\n return `\n /**\n * @notice Decodes a slice into an array of ${element.internalTypeId}.\n * @dev Uses TightCoder for initial decoding, and then assembly for memory conversion.\n * @param _input The slice to decode.\n * @return _output The decoded array of ${element.internalTypeId}.\n */\n function decodeArray_${element.internalTypeId}(\n Slice _input\n ) internal pure returns (\n ${element.internalTypeId}[] memory _output\n ) {\n bytes32[] memory _genericArray = TightCoder.decode(\n _input,\n ${element.staticByteLength},\n ${getLeftPaddingBits(element)}\n );\n assembly {\n _output := _genericArray\n }\n }\n `;\n}\n\n/**\n * Renders `encode` method for encoding the array of provided primitive type into `Slice`\n * @param element name and byte length of the primitive type\n * @returns string of Solidity code\n */\nexport function renderTightCoderEncode(element: Pick<RenderType, \"internalTypeId\" | \"staticByteLength\">) {\n return `\n\n /**\n * @notice Encodes an array of ${element.internalTypeId} into a tightly packed bytes representation.\n * @param _input The array of ${element.internalTypeId} values to be encoded.\n * @return The resulting tightly packed bytes representation of the input array.\n */\n function encode(${element.internalTypeId}[] memory _input) internal pure returns (bytes memory) {\n bytes32[] memory _genericArray;\n assembly {\n _genericArray := _input\n }\n return TightCoder.encode(\n _genericArray,\n ${element.staticByteLength},\n ${getLeftPaddingBits(element)}\n );\n }\n `;\n}\n","import { renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { staticAbiTypeToByteLength, staticAbiTypes } from \"@latticexyz/schema-type/internal\";\nimport { renderTightCoderEncode } from \"./renderFunctions\";\n\n/**\n * Renders `EncodeArray` library with the necessary header and imports,\n * which provides methods for encoding arrays of all primitive types into `Slice`\n * @returns string of Solidity code\n */\nexport function renderEncodeArray() {\n return `\n ${renderedSolidityHeader}\n import { TightCoder } from \"./TightCoder.sol\";\n\n /**\n * @title EncodeArray \n * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)\n * @dev This library provides utilities for encoding arrays into tightly packed bytes representations.\n */\n library EncodeArray {\n ${staticAbiTypes\n .map((staticAbiType) =>\n renderTightCoderEncode({\n internalTypeId: staticAbiType,\n staticByteLength: staticAbiTypeToByteLength[staticAbiType],\n }),\n )\n .join(\"\\n\")}\n }\n `;\n}\n","import { renderedSolidityHeader } from \"@latticexyz/common/codegen\";\nimport { staticAbiTypes } from \"@latticexyz/schema-type/internal\";\n\nexport function renderTightCoderAutoTestFunction({ typeId }: { typeId: string }) {\n return `\n function testEncodeDecodeArray_${typeId}(\n ${typeId} val0,\n ${typeId} val1,\n ${typeId} val2\n ) public {\n ${typeId}[] memory input = new ${typeId}[](3);\n input[0] = val0;\n input[1] = val1;\n input[2] = val2;\n\n bytes memory encoded = EncodeArray.encode(input);\n assertEq(encoded, abi.encodePacked(val0, val1, val2));\n\n ${typeId}[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_${typeId}();\n assertEq(decoded.length, 3);\n assertEq(decoded[0], val0);\n assertEq(decoded[1], val1);\n assertEq(decoded[2], val2);\n }\n `;\n}\n\nexport function renderTightCoderAutoTest() {\n return `\n ${renderedSolidityHeader}\n\n import { Test } from \"forge-std/Test.sol\";\n import { EncodeArray } from \"../../src/tightcoder/EncodeArray.sol\";\n import { SliceLib } from \"../../src/Slice.sol\";\n\n contract TightCoderAutoTest is Test {\n ${staticAbiTypes.map((staticAbiType) => renderTightCoderAutoTestFunction({ typeId: staticAbiType })).join(\"\")}\n }\n `;\n}\n"],"mappings":"AAAA,OACE,mBAAAA,EACA,oBAAAC,GAGA,yBAAAC,EACA,mBAAAC,MACK,6BAQA,SAASC,EAAmBC,EAAqC,CACtE,IAAMC,EAAgBD,EAAQ,cACxB,CAAE,cAAAE,EAAe,cAAAC,EAAe,oBAAAC,CAAoB,EAAIR,GAAiBI,CAAO,EAElFK,EAAS,GACb,OAAW,CAACC,EAAaC,CAAK,IAAKP,EAAQ,OAAO,QAAQ,EAAG,CAC3D,GAAI,CAACA,EAAQ,yBAA2BO,EAAM,UAC5C,SAIF,IAAMC,EAAkB,GAAGD,EAAM,oBAAoBA,EAAM,OA0D3D,GAxDIP,EAAQ,cACVK,GAAUR,EAAsBG,EAAQ,2BAA4BO,EAAM,KAAOE,GAC/EX,EACEG,EACA,CAAC,CAAE,YAAAS,EAAa,OAAAC,EAAQ,eAAAC,EAAgB,kBAAAC,CAAkB,IAAM;AAAA;AAAA,6BAE7CN,EAAM,OAAOK;AAAA;AAAA,uBAEnBC,OAAuBJ,KAAqBd,EAAgB,CACrEe,EACAR,EACAC,CACF,CAAC,6BAA6BK;AAAA,gBAC1BJ;AAAA,gB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AAAC,OAAsB,mCAQnD,SAASC,IAAoB,CAClC,MAAO;AAAA,MACHC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QASEC,GACC,IAAKC,GACJC,GAAuB,CACrB,eAAgBD,EAChB,iBAAkBE,GAA0BF,CAAa,CAC3D,CAAC,CACH,EACC,KAAK;AAAA,CAAI;AAAA;AAAA,GAGlB,CC9BA,OAAS,0BAAAG,OAA8B,6BACvC,OAAS,kBAAAC,OAAsB,mCAExB,SAASC,GAAiC,CAAE,OAAAC,CAAO,EAAuB,CAC/E,MAAO;AAAA,qCAC4BA;AAAA,QAC7BA;AAAA,QACAA;AAAA,QACAA;AAAA;AAAA,QAEAA,0BAA+BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAQ/BA,gEAAqEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAO7E,CAEO,SAASC,IAA2B,CACzC,MAAO;AAAA,MACHJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOEC,GAAe,IAAKI,GAAkBH,GAAiC,CAAE,OAAQG,CAAc,CAAC,CAAC,EAAE,KAAK,EAAE;AAAA;AAAA,GAGlH","names":["renderArguments","renderCommonData","renderWithFieldSuffix","renderWithStore","renderFieldMethods","options","storeArgument","_typedTableId","_typedKeyArgs","_keyTupleDefinition","result","schemaIndex","field","_typedFieldName","_methodNameSuffix","_typedStore","_store","_commentSuffix","_methodNamePrefix","renderDecodeFieldSingle","externalArguments","setFieldMethod","encodeFieldSingle","renderEncodeFieldSingle","internalArguments","portionData","fieldPortionData","dynamicSchemaIndex","typeWrappingData","renderCastStaticBytesToType","func","renderDecodeValueType","offset","staticByteLength","innerSlice","staticBytes","internalTypeId","bits","name","elementFieldData","isDynamic","arrayElement","renderArguments","renderCommonData","renderList","renderWithStore","renderRecordMethods","options","structName","storeArgument","_typedTableId","_typedKeyArgs","_keyTupleDefinition","renderCommonData","result","renderWithStore","_typedStore","_store","_commentSuffix","_methodNamePrefix","renderArguments","renderDecodedRecord","_useExplicitFieldLayout","externalArguments","name","typeWithLocation","internalArguments","renderRecordData","renderDecodeFunctions","namePrefix","renderDeleteRecordMethods","fields","staticFields","dynamicFields","renderedDecodedRecord","fieldNamePrefix","staticOffsets","_acc","index","field","renderList","renderDecodeValueType","renderDecodeDynamicFieldPartial","typeId","arrayElement","typeWrap","renderArguments","renderCommonData","renderList","renderImports","renderTableId","renderTypeHelpers","renderWithStore","renderedSolidityHeader","LayoutOffsets","renderFieldLayout","fields","encodeFieldLayout","staticFields","isDynamic","numDynamicFields","fieldLayout","totalLength","i","staticByteLength","LayoutOffsets","keySchemaToHex","valueSchemaToHex","renderTable","options","imports","libraryName","structName","staticResourceData","storeImportPath","fields","staticFields","dynamicFields","withRecordMethods","storeArgument","keyTuple","_typedTableId","_typedKeyArgs","_keyTupleDefinition","renderCommonData","renderedSolidityHeader","renderImports","renderList","name","typeId","renderTableId","renderFieldLayout","field","keyElement","index","renderWithStore","_typedStore","_store","_commentSuffix","_methodNamePrefix","renderArguments","renderFieldMethods","renderRecordMethods","renderDeleteRecordMethods","renderEncodeStatic","renderEncodeLengths","renderEncodeDynamic","typeWithLocation","renderRecordData","renderTypeHelpers","arrayElement","renderEncodeFieldSingle","renderEnums","renderTypesFromConfig","config","fs","path","formatAndWriteSolidity","loadAndExtractUserTypes","path","SchemaTypeArrayToElement","AbiTypeToSchemaType","getStaticByteLength","SchemaType","SchemaTypeToAbiType","parseStaticArray","abiType","matches","resolveAbiOrUserType","abiOrUserType","config","solidityUserTypes","schemaType","getSchemaTypeInfo","staticArray","getStaticArrayTypeInfo","getUserTypeInfo","importForAbiOrUserType","usedInDirectory","solidityUserType","symbol","staticByteLength","isDynamic","typeId","userType","elementType","staticLength","internalTypeId","getKeySchema","getValueSchema","getTableOptions","config","solidityUserTypes","namespace","table","keySchema","valueSchema","withStruct","withRecordMethods","withSuffixlessFieldMethods","imports","keyTuple","name","field","abiOrUserType","renderType","resolveAbiOrUserType","importDatum","importForAbiOrUserType","fields","schemaType","elementType","SchemaTypeArrayToElement","getSchemaTypeInfo","staticFields","isDynamic","dynamicFields","staticResourceData","path","posixPath","renderList","renderedSolidityHeader","renderTableIndex","options","outputPath","tableName","structName","imports","mapObject","tablegen","rootDir","config","remappings","outputDirectory","path","solidityUserTypes","loadAndExtractUserTypes","type","allTableOptions","getTableOptions","uniqueTableDirectories","outputPath","tableDir","fs","renderOptions","fullOutputPath","output","renderTable","formatAndWriteSolidity","renderTableIndex","renderTypesFromConfig","renderedSolidityHeader","staticAbiTypeToByteLength","staticAbiTypes","getLeftPaddingBits","renderTightCoderDecode","element","renderTightCoderEncode","renderDecodeSlice","renderedSolidityHeader","staticAbiTypes","staticAbiType","renderTightCoderDecode","staticAbiTypeToByteLength","renderedSolidityHeader","staticAbiTypeToByteLength","staticAbiTypes","renderEncodeArray","renderedSolidityHeader","staticAbiTypes","staticAbiType","renderTightCoderEncode","staticAbiTypeToByteLength","renderedSolidityHeader","staticAbiTypes","renderTightCoderAutoTestFunction","typeId","renderTightCoderAutoTest","staticAbiType"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@latticexyz/store",
|
3
|
-
"version": "3.0.0-main-
|
3
|
+
"version": "3.0.0-main-2da9e48cd",
|
4
4
|
"description": "Store",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -46,10 +46,10 @@
|
|
46
46
|
"abitype": "1.0.0",
|
47
47
|
"arktype": "1.0.29-alpha",
|
48
48
|
"viem": "2.9.20",
|
49
|
-
"@latticexyz/common": "3.0.0-main-
|
50
|
-
"@latticexyz/config": "3.0.0-main-
|
51
|
-
"@latticexyz/protocol-parser": "3.0.0-main-
|
52
|
-
"@latticexyz/schema-type": "3.0.0-main-
|
49
|
+
"@latticexyz/common": "3.0.0-main-2da9e48cd",
|
50
|
+
"@latticexyz/config": "3.0.0-main-2da9e48cd",
|
51
|
+
"@latticexyz/protocol-parser": "3.0.0-main-2da9e48cd",
|
52
|
+
"@latticexyz/schema-type": "3.0.0-main-2da9e48cd"
|
53
53
|
},
|
54
54
|
"devDependencies": {
|
55
55
|
"@arktype/attest": "0.7.5",
|
@@ -62,8 +62,8 @@
|
|
62
62
|
"tsup": "^6.7.0",
|
63
63
|
"tsx": "^3.12.6",
|
64
64
|
"vitest": "0.34.6",
|
65
|
-
"@latticexyz/abi-ts": "3.0.0-main-
|
66
|
-
"@latticexyz/gas-report": "3.0.0-main-
|
65
|
+
"@latticexyz/abi-ts": "3.0.0-main-2da9e48cd",
|
66
|
+
"@latticexyz/gas-report": "3.0.0-main-2da9e48cd"
|
67
67
|
},
|
68
68
|
"scripts": {
|
69
69
|
"build": "pnpm run build:tightcoder && pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts && pnpm run build:js",
|