@latticexyz/store 3.0.0-main-e85dc5349 → 3.0.0-main-560fd6a0c

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 CHANGED
@@ -1,4 +1,4 @@
1
- import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,renderWithStore as D}from"@latticexyz/common/codegen";function U(e){let n=e.storeArgument,{_typedTableId:r,_typedKeyArgs:t,_keyTupleDefinition:d}=ie(e),i="";for(let[c,o]of e.fields.entries()){if(!e.withDynamicFieldMethods&&o.isDynamic)continue;let m=`${o.typeWithLocation} ${o.name}`;if(e.withGetters&&(i+=_(e.withSuffixlessFieldMethods,o.name,a=>D(n,({_typedStore:l,_store:y,_commentSuffix:p,_methodNamePrefix:h})=>`
1
+ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,renderWithStore as L}from"@latticexyz/common/codegen";function U(e){let n=e.storeArgument,{_typedTableId:r,_typedKeyArgs:t,_keyTupleDefinition:d}=ie(e),i="";for(let[c,o]of e.fields.entries()){if(!e.withDynamicFieldMethods&&o.isDynamic)continue;let m=`${o.typeWithLocation} ${o.name}`;if(e.withGetters&&(i+=_(e.withSuffixlessFieldMethods,o.name,a=>L(n,({_typedStore:l,_store:y,_commentSuffix:p,_methodNamePrefix:h})=>`
2
2
  /**
3
3
  * @notice Get ${o.name}${p}.
4
4
  */
@@ -16,7 +16,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
16
16
  );`}
17
17
  return ${w(o)};
18
18
  }
19
- `))),i+=_(e.withSuffixlessFieldMethods,o.name,a=>D(n,({_typedStore:l,_store:y,_commentSuffix:p,_methodNamePrefix:h})=>{let f=S([l,r,t,m]),s=o.isDynamic?"setDynamicField":"setStaticField",u=A(o),g=o.isDynamic?`_tableId, _keyTuple, ${c-e.staticFields.length}, ${u}`:`_tableId, _keyTuple, ${c}, ${u}, _fieldLayout`;return`
19
+ `))),i+=_(e.withSuffixlessFieldMethods,o.name,a=>L(n,({_typedStore:l,_store:y,_commentSuffix:p,_methodNamePrefix:h})=>{let f=S([l,r,t,m]),s=o.isDynamic?"setDynamicField":"setStaticField",u=A(o),g=o.isDynamic?`_tableId, _keyTuple, ${c-e.staticFields.length}, ${u}`:`_tableId, _keyTuple, ${c}, ${u}, _fieldLayout`;return`
20
20
  /**
21
21
  * @notice Set ${o.name}${p}.
22
22
  */
@@ -27,7 +27,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
27
27
  `})),o.isDynamic){let a=ae(o),l=c-e.staticFields.length,{typeWrappingData:y}=o;e.withGetters&&(y&&y.kind==="staticArray"?i+=_(e.withSuffixlessFieldMethods,o.name,p=>`
28
28
  // The length of ${o.name}
29
29
  uint256 constant length${p} = ${y.staticLength};
30
- `):i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
30
+ `):i+=_(e.withSuffixlessFieldMethods,o.name,p=>L(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
31
31
  /**
32
32
  * @notice Get the length of ${o.name}${s}.
33
33
  */
@@ -38,7 +38,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
38
38
  return _byteLength / ${a.elementLength};
39
39
  }
40
40
  }
41
- `)),i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
41
+ `)),i+=_(e.withSuffixlessFieldMethods,o.name,p=>L(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
42
42
  /**
43
43
  * @notice Get an item of ${o.name}${s}.
44
44
  * @dev Reverts with Store_IndexOutOfBounds if \`_index\` is out of bounds for the array.
@@ -66,7 +66,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
66
66
  return ${a.decoded};
67
67
  }
68
68
  }
69
- `))),(!y||y.kind!=="staticArray")&&(i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
69
+ `))),(!y||y.kind!=="staticArray")&&(i+=_(e.withSuffixlessFieldMethods,o.name,p=>L(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
70
70
  /**
71
71
  * @notice Push ${a.title} to ${o.name}${s}.
72
72
  */
@@ -74,7 +74,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
74
74
  ${d}
75
75
  ${f}.pushToDynamicField(_tableId, _keyTuple, ${l}, ${a.encoded});
76
76
  }
77
- `)),i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
77
+ `)),i+=_(e.withSuffixlessFieldMethods,o.name,p=>L(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>`
78
78
  /**
79
79
  * @notice Pop ${a.title} from ${o.name}${s}.
80
80
  */
@@ -82,7 +82,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
82
82
  ${d}
83
83
  ${f}.popFromDynamicField(_tableId, _keyTuple, ${l}, ${a.elementLength});
84
84
  }
85
- `))),i+=_(e.withSuffixlessFieldMethods,o.name,p=>D(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>{let g=S([h,r,t,"uint256 _index",`${a.typeWithLocation} ${a.name}`]),b=`
85
+ `))),i+=_(e.withSuffixlessFieldMethods,o.name,p=>L(n,({_typedStore:h,_store:f,_commentSuffix:s,_methodNamePrefix:u})=>{let g=S([h,r,t,"uint256 _index",`${a.typeWithLocation} ${a.name}`]),b=`
86
86
  _tableId,
87
87
  _keyTuple,
88
88
  ${l},
@@ -285,10 +285,10 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
285
285
 
286
286
  ${Se(o)}
287
287
 
288
- ${De(m)}
289
-
290
288
  ${Le(m)}
291
289
 
290
+ ${De(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.
@@ -319,7 +319,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
319
319
  function encodeStatic(${T(e.map(({name:n,typeWithLocation:r})=>`${r} ${n}`))}) internal pure returns (bytes memory) {
320
320
  return abi.encodePacked(${T(e.map(({name:n})=>n))});
321
321
  }
322
- `}function De(e){return e.length===0?"":`
322
+ `}function Le(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).
@@ -332,7 +332,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
332
332
  );
333
333
  }
334
334
  }
335
- `}function Le(e){return e.length===0?"":`
335
+ `}function De(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.
@@ -340,11 +340,11 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
340
340
  function encodeDynamic(${T(e.map(({name:n,typeWithLocation:r})=>`${r} ${n}`))}) internal pure returns (bytes memory) {
341
341
  return abi.encodePacked(${T(e.map(n=>A(n)))});
342
342
  }
343
- `}import{renderEnums as Ie}from"@latticexyz/common/codegen";function z(e){return Ie(e.enums)}import Be from"node:fs/promises";import I from"node:path";import{formatAndWriteSolidity as W,loadAndExtractUserTypes as Me}from"@latticexyz/common/codegen";import Ee from"path";import{SchemaTypeArrayToElement as Fe}from"@latticexyz/schema-type/deprecated";import{AbiTypeToSchemaType as L,getStaticByteLength as B,SchemaType as x,SchemaTypeToAbiType as J}from"@latticexyz/schema-type/deprecated";import{parseStaticArray as Q}from"@latticexyz/config/library";function M(e,n,r){if(e in L){let d=L[e];return{schemaType:d,renderType:N(d)}}let t=Q(e);if(t){if(t.elementType in L)return xe(e,t.elementType,t.staticLength);throw new Error("Static arrays of user types are not supported")}return Ae(e,n,r)}function C(e,n,r,t){if(!(e in L||Q(e))){if(e in t){let i=t[e],c=i.importSymbol;return i.isRelativePath?{symbol:c,fromPath:i.fromPath,usedInPath:n}:{symbol:c,path:i.fromPath}}return{symbol:e,fromPath:r.codegen.userTypesFilename,usedInPath:n}}}function N(e){let n=B(e),r=n===0,t=J[e];return{typeId:t,typeWithLocation:r?t+" memory":t,enumName:x[e],staticByteLength:n,isDynamic:r,typeWrap:"",typeUnwrap:"",internalTypeId:t}}function Ae(e,n,r){if(e in n.enums){let t=x.UINT8,d=B(t),i=d===0,c=e;return{schemaType:t,renderType:{typeId:c,typeWithLocation:c,enumName:x[t],staticByteLength:d,isDynamic:i,typeWrap:`${e}`,typeUnwrap:"uint8",internalTypeId:`${J[t]}`}}}if(e in r){if(!(e in r))throw new Error(`User type "${e}" not found in MUD config`);let t=r[e],d=t.typeId,i=L[t.internalTypeId];return{schemaType:i,renderType:{typeId:d,typeWithLocation:d,enumName:x[i],staticByteLength:B(i),isDynamic:!1,typeWrap:`${d}.wrap`,typeUnwrap:`${d}.unwrap`,internalTypeId:t.internalTypeId}}}throw new Error(`User type "${e}" does not exist`)}function xe(e,n,r){let t=n+"[]",d=L[t];return{schemaType:d,renderType:{typeId:e,typeWithLocation:`${e} memory`,enumName:x[d],staticByteLength:0,isDynamic:!0,typeWrap:`toStaticArray_${n}_${r}`,typeUnwrap:`fromStaticArray_${n}_${r}`,typeWrappingData:{kind:"staticArray",elementType:n,staticLength:r},internalTypeId:t}}}import{getKeySchema as Re,getValueSchema as ke}from"@latticexyz/protocol-parser/internal";function ee(e,n){return Object.values(e.tables).map(t=>{let d=Re(t),i=ke(t),c=t.codegen.dataStruct,o=c||t.type==="offchainTable"||Object.keys(i).length>1,m=!o&&Object.keys(i).length===1,a=[],l=Object.entries(d).map(([s,u])=>{let g=u.internalType,{renderType:b}=M(g,e,n),E=C(g,t.codegen.outputDirectory,e,n);return E&&a.push(E),{...b,name:s,isDynamic:!1}}),y=Object.entries(i).map(([s,u])=>{let g=u.internalType,{renderType:b,schemaType:E}=M(g,e,n),P=C(g,t.codegen.outputDirectory,e,n);P&&a.push(P);let j=Fe[E];return{...b,arrayElement:j!==void 0?N(j):void 0,name:s}}),p=y.filter(({isDynamic:s})=>!s),h=y.filter(({isDynamic:s})=>s),f=t.codegen.tableIdArgument?void 0:{namespace:t.namespace,name:t.name,offchainOnly:t.type==="offchainTable"};return{outputPath:Ee.join(t.codegen.outputDirectory,`${t.label}.sol`),tableName:t.label,renderOptions:{imports:a,libraryName:t.label,structName:c?t.label+"Data":void 0,staticResourceData:f,storeImportPath:e.codegen.storeImportPath,keyTuple:l,fields:y,staticFields:p,dynamicFields:h,withGetters:t.type==="table",withRecordMethods:o,withDynamicFieldMethods:t.type==="table",withSuffixlessFieldMethods:m,storeArgument:t.codegen.storeArgument}}})}import{posixPath as we,renderList as Oe,renderedSolidityHeader as ve}from"@latticexyz/common/codegen";function te(e){return`
343
+ `}import{renderEnums as Ie}from"@latticexyz/common/codegen";function z(e){return Ie(e.enums)}import Be from"node:fs/promises";import I from"node:path";import{formatAndWriteSolidity as W,loadAndExtractUserTypes as Me}from"@latticexyz/common/codegen";import Ee from"path";import{SchemaTypeArrayToElement as Fe}from"@latticexyz/schema-type/deprecated";import{AbiTypeToSchemaType as D,getStaticByteLength as B,SchemaType as x,SchemaTypeToAbiType as J}from"@latticexyz/schema-type/deprecated";function Q(e){let n=e.match(/^(\w+)\[(\d+)\]$/);return n?{elementType:n[1],staticLength:Number.parseInt(n[2])}:null}function M(e,n,r){if(e in D){let d=D[e];return{schemaType:d,renderType:N(d)}}let t=Q(e);if(t){if(t.elementType in D)return xe(e,t.elementType,t.staticLength);throw new Error("Static arrays of user types are not supported")}return Ae(e,n,r)}function C(e,n,r,t){if(!(e in D||Q(e))){if(e in t){let i=t[e],c=i.importSymbol;return i.isRelativePath?{symbol:c,fromPath:i.fromPath,usedInPath:n}:{symbol:c,path:i.fromPath}}return{symbol:e,fromPath:r.codegen.userTypesFilename,usedInPath:n}}}function N(e){let n=B(e),r=n===0,t=J[e];return{typeId:t,typeWithLocation:r?t+" memory":t,enumName:x[e],staticByteLength:n,isDynamic:r,typeWrap:"",typeUnwrap:"",internalTypeId:t}}function Ae(e,n,r){if(e in n.enums){let t=x.UINT8,d=B(t),i=d===0,c=e;return{schemaType:t,renderType:{typeId:c,typeWithLocation:c,enumName:x[t],staticByteLength:d,isDynamic:i,typeWrap:`${e}`,typeUnwrap:"uint8",internalTypeId:`${J[t]}`}}}if(e in r){if(!(e in r))throw new Error(`User type "${e}" not found in MUD config`);let t=r[e],d=t.typeId,i=D[t.internalTypeId];return{schemaType:i,renderType:{typeId:d,typeWithLocation:d,enumName:x[i],staticByteLength:B(i),isDynamic:!1,typeWrap:`${d}.wrap`,typeUnwrap:`${d}.unwrap`,internalTypeId:t.internalTypeId}}}throw new Error(`User type "${e}" does not exist`)}function xe(e,n,r){let t=n+"[]",d=D[t];return{schemaType:d,renderType:{typeId:e,typeWithLocation:`${e} memory`,enumName:x[d],staticByteLength:0,isDynamic:!0,typeWrap:`toStaticArray_${n}_${r}`,typeUnwrap:`fromStaticArray_${n}_${r}`,typeWrappingData:{kind:"staticArray",elementType:n,staticLength:r},internalTypeId:t}}}import{getKeySchema as Re,getValueSchema as ke}from"@latticexyz/protocol-parser/internal";function ee(e,n){return Object.values(e.tables).map(t=>{let d=Re(t),i=ke(t),c=t.codegen.dataStruct,o=c||t.type==="offchainTable"||Object.keys(i).length>1,m=!o&&Object.keys(i).length===1,a=[],l=Object.entries(d).map(([s,u])=>{let g=u.internalType,{renderType:b}=M(g,e,n),E=C(g,t.codegen.outputDirectory,e,n);return E&&a.push(E),{...b,name:s,isDynamic:!1}}),y=Object.entries(i).map(([s,u])=>{let g=u.internalType,{renderType:b,schemaType:E}=M(g,e,n),P=C(g,t.codegen.outputDirectory,e,n);P&&a.push(P);let j=Fe[E];return{...b,arrayElement:j!==void 0?N(j):void 0,name:s}}),p=y.filter(({isDynamic:s})=>!s),h=y.filter(({isDynamic:s})=>s),f=t.codegen.tableIdArgument?void 0:{namespace:t.namespace,name:t.name,offchainOnly:t.type==="offchainTable"};return{outputPath:Ee.join(t.codegen.outputDirectory,`${t.label}.sol`),tableName:t.label,renderOptions:{imports:a,libraryName:t.label,structName:c?t.label+"Data":void 0,staticResourceData:f,storeImportPath:e.codegen.storeImportPath,keyTuple:l,fields:y,staticFields:p,dynamicFields:h,withGetters:t.type==="table",withRecordMethods:o,withDynamicFieldMethods:t.type==="table",withSuffixlessFieldMethods:m,storeArgument:t.codegen.storeArgument}}})}import{posixPath as we,renderList as Oe,renderedSolidityHeader as ve}from"@latticexyz/common/codegen";function te(e){return`
344
344
  ${ve}
345
345
 
346
346
  ${Oe(e,({outputPath:n,tableName:r,renderOptions:{structName:t}})=>{let d=[r];return t&&d.push(t),`import { ${d.join(", ")} } from "./${we(n)}";`})}
347
- `}import{mapObject as Ce}from"@latticexyz/common/utils";async function vt({rootDir:e,config:n,remappings:r}){let t=I.join(e,n.sourceDirectory,n.codegen.outputDirectory),d=Me(Ce(n.userTypes,o=>({...o,internalType:o.type})),t,r),i=ee(n,d),c=Array.from(new Set(i.map(({outputPath:o})=>I.dirname(o))));if(await Promise.all(c.map(async o=>{await Be.rm(I.join(t,o),{recursive:!0,force:!0})})),await Promise.all(i.map(async({outputPath:o,renderOptions:m})=>{let a=I.join(t,o),l=Z(m);await W(l,a,"Generated table")})),i.length>0){let o=I.join(t,n.codegen.indexFilename),m=te(i);await W(m,o,"Generated table index")}if(Object.keys(n.enums).length>0){let o=I.join(t,n.codegen.userTypesFilename),m=z(n);await W(m,o,"Generated types file")}}import{renderedSolidityHeader as Ne}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as We,staticAbiTypes as Pe}from"@latticexyz/schema-type/internal";import{getLeftPaddingBits as ne}from"@latticexyz/common/codegen";function re(e){return`
347
+ `}import{mapObject as Ce}from"@latticexyz/common/utils";async function Ot({rootDir:e,config:n,remappings:r}){let t=I.join(e,n.sourceDirectory,n.codegen.outputDirectory),d=Me(Ce(n.userTypes,o=>({...o,internalType:o.type})),t,r),i=ee(n,d),c=Array.from(new Set(i.map(({outputPath:o})=>I.dirname(o))));if(await Promise.all(c.map(async o=>{await Be.rm(I.join(t,o),{recursive:!0,force:!0})})),await Promise.all(i.map(async({outputPath:o,renderOptions:m})=>{let a=I.join(t,o),l=Z(m);await W(l,a,"Generated table")})),i.length>0){let o=I.join(t,n.codegen.indexFilename),m=te(i);await W(m,o,"Generated table index")}if(Object.keys(n.enums).length>0){let o=I.join(t,n.codegen.userTypesFilename),m=z(n);await W(m,o,"Generated types file")}}import{renderedSolidityHeader as Ne}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as We,staticAbiTypes as Pe}from"@latticexyz/schema-type/internal";import{getLeftPaddingBits as ne}from"@latticexyz/common/codegen";function re(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.
@@ -383,7 +383,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
383
383
  ${ne(e)}
384
384
  );
385
385
  }
386
- `}function Ut(){return`
386
+ `}function jt(){return`
387
387
  ${Ne}
388
388
  import { TightCoder } from "./TightCoder.sol";
389
389
  import { Slice } from "../Slice.sol";
@@ -398,7 +398,7 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
398
398
  ${Pe.map(e=>re({internalTypeId:e,staticByteLength:We[e]})).join(`
399
399
  `)}
400
400
  }
401
- `}import{renderedSolidityHeader as je}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as Ue,staticAbiTypes as Ge}from"@latticexyz/schema-type/internal";function Yt(){return`
401
+ `}import{renderedSolidityHeader as je}from"@latticexyz/common/codegen";import{staticAbiTypeToByteLength as Ue,staticAbiTypes as Ge}from"@latticexyz/schema-type/internal";function qt(){return`
402
402
  ${je}
403
403
  import { TightCoder } from "./TightCoder.sol";
404
404
 
@@ -431,7 +431,7 @@ 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 zt(){return`
434
+ `}function Zt(){return`
435
435
  ${He}
436
436
 
437
437
  import { Test } from "forge-std/Test.sol";
@@ -441,5 +441,5 @@ import{renderArguments as S,renderCommonData as ie,renderWithFieldSuffix as _,re
441
441
  contract TightCoderAutoTest is Test {
442
442
  ${Ke.map(e=>qe({typeId:e})).join("")}
443
443
  }
444
- `}export{N as getSchemaTypeInfo,ee as getTableOptions,Ae as getUserTypeInfo,C as importForAbiOrUserType,Ut as renderDecodeSlice,G as renderDecodeValueType,X as renderDeleteRecordMethods,Yt as renderEncodeArray,A as renderEncodeFieldSingle,U as renderFieldMethods,R as renderRecordData,Y as renderRecordMethods,Z as renderTable,zt as renderTightCoderAutoTest,qe as renderTightCoderAutoTestFunction,re as renderTightCoderDecode,oe as renderTightCoderEncode,z as renderTypesFromConfig,M as resolveAbiOrUserType,vt as tablegen};
444
+ `}export{N as getSchemaTypeInfo,ee as getTableOptions,Ae as getUserTypeInfo,C as importForAbiOrUserType,jt as renderDecodeSlice,G as renderDecodeValueType,X as renderDeleteRecordMethods,qt as renderEncodeArray,A as renderEncodeFieldSingle,U as renderFieldMethods,R as renderRecordData,Y as renderRecordMethods,Z as renderTable,Zt as renderTightCoderAutoTest,qe as renderTightCoderAutoTestFunction,re as renderTightCoderDecode,oe as renderTightCoderEncode,z as renderTypesFromConfig,M as resolveAbiOrUserType,Ot as tablegen};
445
445
  //# sourceMappingURL=codegen.js.map
@@ -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 { parseStaticArray } from \"@latticexyz/config/library\";\nimport { ImportDatum, RenderType, SolidityUserDefinedType } from \"@latticexyz/common/codegen\";\nimport { Store as StoreConfig } from \"../config/v2/output\";\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,gBAEAG,EAAM,UACF,wBAAwBI;AAAA;AAAA;AAAA,wBAGpBL,EAAcN,EAAQ,aAAa;AAAA,wBAEvC,mBAAmBW;AAAA;AAAA;AAAA,wBAGfL;AAAA;AAAA;AAAA,uBAIDQ,EAAwBP,CAAK;AAAA;AAAA,WAG5C,CACF,GAGFF,GAAUR,EAAsBG,EAAQ,2BAA4BO,EAAM,KAAOE,GAC/EX,EAAgBG,EAAe,CAAC,CAAE,YAAAS,EAAa,OAAAC,EAAQ,eAAA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,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","resolveAbiOrUserType","abiOrUserType","config","solidityUserTypes","schemaType","getSchemaTypeInfo","staticArray","getStaticArrayTypeInfo","getUserTypeInfo","importForAbiOrUserType","usedInDirectory","solidityUserType","symbol","staticByteLength","isDynamic","typeId","userType","abiType","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 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,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,KAA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6BACvC,OAAS,6BAAAC,GAA2B,kBAAAC,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","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,12 +1,5 @@
1
- import { F as FieldData, a as FullSchemaConfig, S as StoreConfig } from './storeConfig-55cad8c2.js';
2
- export { D as DEFAULTS, l as EnumsConfig, E as ExpandSchemaConfig, f as ExpandTableConfig, k as ExpandTablesConfig, m as FullEnumsConfig, e as FullTableConfig, j as FullTablesConfig, M as MUDUserConfig, c as SchemaConfig, b as ShorthandSchemaConfig, q as StoreUserConfig, T as TABLE_DEFAULTS, d as TableConfig, h as TablesConfig, U as UserTypesConfig, r as resolveUserTypes, n as zEnumsConfig, s as zPluginStoreConfig, z as zSchemaConfig, p as zStoreConfig, g as zTableConfig, i as zTablesConfig, o as zUserTypesConfig } from './storeConfig-55cad8c2.js';
3
1
  import { StaticAbiType, SchemaAbiType, SchemaAbiTypeToPrimitiveType } from '@latticexyz/schema-type/internal';
4
2
  import { Hex } from 'viem';
5
- import '@latticexyz/schema-type/deprecated';
6
- import 'zod';
7
- import '@latticexyz/common/type-utils';
8
- import '@latticexyz/config/library';
9
- import '@latticexyz/common/codegen';
10
3
 
11
4
  type KeySchema = {
12
5
  readonly [k: string]: {
@@ -32,23 +25,5 @@ type Tables = {
32
25
  type SchemaToPrimitives<schema extends ValueSchema> = {
33
26
  readonly [key in keyof schema]: SchemaAbiTypeToPrimitiveType<schema[key]["type"]>;
34
27
  };
35
- type ConfigFieldTypeToSchemaAbiType<T extends FieldData<string>> = T extends SchemaAbiType ? T : T extends `${string}[${string}]` ? "uint8[]" : "uint8";
36
- type ConfigFieldTypeToPrimitiveType<T extends FieldData<string>> = T extends SchemaAbiType ? SchemaAbiTypeToPrimitiveType<T> : T extends `${string}[${string}]` ? number[] : number;
37
- /** Map a table schema config like `{ value: "uint256", type: "SomeEnum" }` to its primitive types like `{ value: bigint, type: number }` */
38
- type SchemaConfigToPrimitives<T extends FullSchemaConfig> = {
39
- [key in keyof T]: ConfigFieldTypeToPrimitiveType<T[key]>;
40
- };
41
- type ConfigToTablesPrimitives<C extends StoreConfig> = {
42
- [key in keyof C["tables"]]: {
43
- key: SchemaConfigToPrimitives<C["tables"][key]["keySchema"]>;
44
- value: SchemaConfigToPrimitives<C["tables"][key]["valueSchema"]>;
45
- };
46
- };
47
- type ConfigToKeyPrimitives<C extends StoreConfig, Table extends keyof ConfigToTablesPrimitives<C>> = ConfigToTablesPrimitives<C>[Table]["key"];
48
- type ConfigToValuePrimitives<C extends StoreConfig, Table extends keyof ConfigToTablesPrimitives<C>> = ConfigToTablesPrimitives<C>[Table]["value"];
49
- type ConfigToRecordPrimitives<C extends StoreConfig, Table extends keyof ConfigToTablesPrimitives<C>> = {
50
- key: ConfigToKeyPrimitives<C, Table>;
51
- value: ConfigToValuePrimitives<C, Table>;
52
- };
53
28
 
54
- export { ConfigFieldTypeToPrimitiveType, ConfigFieldTypeToSchemaAbiType, ConfigToKeyPrimitives, ConfigToRecordPrimitives, ConfigToTablesPrimitives, ConfigToValuePrimitives, FieldData, FullSchemaConfig, KeySchema, SchemaConfigToPrimitives, SchemaToPrimitives, StoreConfig, Table, Tables, ValueSchema };
29
+ export { KeySchema, SchemaToPrimitives, Table, Tables, ValueSchema };
package/dist/internal.js CHANGED
@@ -1,2 +1 @@
1
- import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b}from"./chunk-RRYXNY5P.js";export{o as DEFAULTS,r as TABLE_DEFAULTS,f as resolveUserTypes,t as zEnumsConfig,b as zPluginStoreConfig,e as zSchemaConfig,a as zStoreConfig,m as zTableConfig,p as zTablesConfig,x as zUserTypesConfig};
2
1
  //# sourceMappingURL=internal.js.map