@latticexyz/common 2.0.0-next.16 → 2.0.0-next.17
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/chunk-YEN6EYTC.js +2 -0
- package/dist/chunk-YEN6EYTC.js.map +1 -0
- package/dist/codegen.d.ts +105 -13
- package/dist/codegen.js +22 -31
- package/dist/codegen.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/codegen/render-solidity/common.test.ts +83 -0
- package/src/codegen/render-solidity/common.ts +85 -36
- package/src/codegen/render-solidity/renderEnums.ts +3 -0
- package/src/codegen/render-solidity/renderTypeHelpers.ts +19 -0
- package/src/codegen/render-solidity/types.ts +5 -0
- package/src/codegen/utils/contractToInterface.ts +59 -41
- package/src/codegen/utils/extractUserTypes.ts +7 -0
- package/src/codegen/utils/format.ts +11 -0
- package/src/codegen/utils/formatAndWrite.ts +12 -0
- package/src/codegen/utils/loadUserTypesFile.ts +7 -0
- package/dist/chunk-TCWGPC6G.js +0 -2
- package/dist/chunk-TCWGPC6G.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{stringToHex as o,concatHex as t}from"viem";var c={table:"tb",offchainTable:"ot",namespace:"ns",module:"md",system:"sy"};function u(e){let r=c[e.type];return t([o(r,{size:2}),o(e.namespace.slice(0,14),{size:14}),o(e.name.slice(0,16),{size:16})])}import s from"debug";var n=s("mud:common"),m=s("mud:common");n.log=console.debug.bind(console);m.log=console.error.bind(console);export{n as a,c as b,u as c};
|
|
2
|
+
//# sourceMappingURL=chunk-YEN6EYTC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resourceToHex.ts","../src/debug.ts"],"sourcesContent":["import { Hex, stringToHex, concatHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType } from \"./resourceTypes\";\n\n/** @internal */\nexport const resourceTypeIds = {\n // keep these in sync with storeResourceTypes.sol\n table: \"tb\",\n offchainTable: \"ot\",\n // keep these in sync with worldResourceTypes.sol\n namespace: \"ns\",\n module: \"md\",\n system: \"sy\",\n} as const satisfies Record<ResourceType, string>;\n\nexport function resourceToHex(resource: Omit<Resource, \"resourceId\">): Hex {\n const typeId = resourceTypeIds[resource.type];\n return concatHex([\n stringToHex(typeId, { size: 2 }),\n stringToHex(resource.namespace.slice(0, 14), { size: 14 }),\n stringToHex(resource.name.slice(0, 16), { size: 16 }),\n ]);\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:common\");\nexport const error = createDebug(\"mud:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n"],"mappings":"AAAA,OAAc,eAAAA,EAAa,aAAAC,MAAiB,OAKrC,IAAMC,EAAkB,CAE7B,MAAO,KACP,cAAe,KAEf,UAAW,KACX,OAAQ,KACR,OAAQ,IACV,EAEO,SAASC,EAAcC,EAA6C,CACzE,IAAMC,EAASH,EAAgBE,EAAS,IAAI,EAC5C,OAAOH,EAAU,CACfD,EAAYK,EAAQ,CAAE,KAAM,CAAE,CAAC,EAC/BL,EAAYI,EAAS,UAAU,MAAM,EAAG,EAAE,EAAG,CAAE,KAAM,EAAG,CAAC,EACzDJ,EAAYI,EAAS,KAAK,MAAM,EAAG,EAAE,EAAG,CAAE,KAAM,EAAG,CAAC,CACtD,CAAC,CACH,CCtBA,OAAOE,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,YAAY,EAChCE,EAAQF,EAAY,YAAY,EAG7CC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EAGtCC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO","names":["stringToHex","concatHex","resourceTypeIds","resourceToHex","resource","typeId","createDebug","debug","error"]}
|
package/dist/codegen.d.ts
CHANGED
|
@@ -16,12 +16,17 @@ type ImportDatum = AbsoluteImportDatum | RelativeImportDatum;
|
|
|
16
16
|
interface StaticResourceData {
|
|
17
17
|
/** Name of the table id constant to render. */
|
|
18
18
|
tableIdName: string;
|
|
19
|
+
/** Table namespace string */
|
|
19
20
|
namespace: string;
|
|
21
|
+
/** Table name string */
|
|
20
22
|
name: string;
|
|
23
|
+
/** Whether the table is offchain only (does not use storage) */
|
|
21
24
|
offchainOnly: boolean;
|
|
22
25
|
}
|
|
23
26
|
interface RenderType {
|
|
27
|
+
/** Fully-qualified name of the user-defined type (may include a library name as prefix) */
|
|
24
28
|
typeId: string;
|
|
29
|
+
/** Fully-qualified name of the user-defined type (may include a library name as prefix), followed by location (none/memory/storage) */
|
|
25
30
|
typeWithLocation: string;
|
|
26
31
|
/** The name of the enum element in SchemaType to use for schema registration (e.g. "UINT256_ARRAY") */
|
|
27
32
|
enumName: string;
|
|
@@ -60,7 +65,10 @@ interface RenderEnum {
|
|
|
60
65
|
memberNames: string[];
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Common header for all codegenerated solidity files
|
|
70
|
+
*/
|
|
71
|
+
declare const renderedSolidityHeader = "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.24;\n\n/* Autogenerated file. Do not edit manually. */";
|
|
64
72
|
/**
|
|
65
73
|
* Renders a list of lines
|
|
66
74
|
*/
|
|
@@ -69,14 +77,24 @@ declare function renderList<T>(list: T[], renderItem: (item: T, index: number) =
|
|
|
69
77
|
* Renders a comma-separated list of arguments for solidity functions, ignoring empty and undefined ones
|
|
70
78
|
*/
|
|
71
79
|
declare function renderArguments(args: (string | undefined)[]): string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
keyTuple: RenderKeyTuple[];
|
|
75
|
-
}): {
|
|
80
|
+
interface RenderedCommonData {
|
|
81
|
+
/** `_tableId` variable prefixed with its type (empty string if absent) */
|
|
76
82
|
_typedTableId: string;
|
|
83
|
+
/** Comma-separated table key names prefixed with their types (empty string if 0 keys) */
|
|
77
84
|
_typedKeyArgs: string;
|
|
85
|
+
/** Definition and initialization of the dynamic `_keyTuple` bytes32 array */
|
|
78
86
|
_keyTupleDefinition: string;
|
|
79
|
-
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Renders some solidity statements commonly used within table libraries
|
|
90
|
+
* @param param0.staticResourceData static data about the table library
|
|
91
|
+
* @param param0.keyTuple key tuple of the table library
|
|
92
|
+
* @returns Rendered statement strings
|
|
93
|
+
*/
|
|
94
|
+
declare function renderCommonData({ staticResourceData, keyTuple, }: {
|
|
95
|
+
staticResourceData?: StaticResourceData;
|
|
96
|
+
keyTuple: RenderKeyTuple[];
|
|
97
|
+
}): RenderedCommonData;
|
|
80
98
|
/** For 2 paths which are relative to a common root, create a relative import path from one to another */
|
|
81
99
|
declare function solidityRelativeImportPath(fromPath: string, usedInPath: string): string;
|
|
82
100
|
/**
|
|
@@ -94,24 +112,61 @@ declare function renderRelativeImports(imports: RelativeImportDatum[]): string;
|
|
|
94
112
|
* Identical symbols from different paths are NOT handled, they should be checked before rendering.
|
|
95
113
|
*/
|
|
96
114
|
declare function renderAbsoluteImports(imports: AbsoluteImportDatum[]): string;
|
|
97
|
-
|
|
115
|
+
interface RenderWithStoreCallbackData {
|
|
116
|
+
/** `_store` variable prefixed with its type (undefined if library name) */
|
|
98
117
|
_typedStore: string | undefined;
|
|
118
|
+
/** `_store` variable (undefined if library name) */
|
|
99
119
|
_store: string;
|
|
120
|
+
/** Empty string if storeArgument is false, otherwise `" (using the specified store)"` */
|
|
100
121
|
_commentSuffix: string;
|
|
122
|
+
/** Prefix to differentiate different kinds of store usage within methods */
|
|
101
123
|
_methodNamePrefix: string;
|
|
124
|
+
/** Whether FieldLayout variable should be passed to store methods */
|
|
102
125
|
_useExplicitFieldLayout?: boolean;
|
|
103
|
-
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Renders several versions of the callback's result, which access Store in different ways
|
|
129
|
+
* @param storeArgument whether to render a version with `IStore _store` as an argument
|
|
130
|
+
* @param callback renderer for a method which uses store
|
|
131
|
+
* @returns Concatenated results of all callback calls
|
|
132
|
+
*/
|
|
133
|
+
declare function renderWithStore(storeArgument: boolean, callback: (data: RenderWithStoreCallbackData) => string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Renders several versions of the callback's result, which have different method name suffixes
|
|
136
|
+
* @param withSuffixlessFieldMethods whether to render methods with an empty suffix
|
|
137
|
+
* @param fieldName name of the field which the methods access, used for a suffix
|
|
138
|
+
* @param callback renderer for a method to be suffixed
|
|
139
|
+
* @returns Concatenated results of all callback calls
|
|
140
|
+
*/
|
|
104
141
|
declare function renderWithFieldSuffix(withSuffixlessFieldMethods: boolean, fieldName: string, callback: (_methodNameSuffix: string) => string): string;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
declare function
|
|
142
|
+
/**
|
|
143
|
+
* Renders `_tableId` variable definition and initialization, and its alias which uses the provided `tableIdName`.
|
|
144
|
+
* @param param0 static resource data needed to construct the table id
|
|
145
|
+
*/
|
|
146
|
+
declare function renderTableId({ namespace, name, offchainOnly, tableIdName, }: Pick<StaticResourceData, "namespace" | "name" | "offchainOnly" | "tableIdName">): string;
|
|
147
|
+
/**
|
|
148
|
+
* Renders solidity typecasts to get from the given type to `bytes32`
|
|
149
|
+
* @param name variable name to be typecasted
|
|
150
|
+
* @param param1 type data
|
|
151
|
+
*/
|
|
152
|
+
declare function renderValueTypeToBytes32(name: string, { typeUnwrap, internalTypeId }: Pick<RenderType, "typeUnwrap" | "internalTypeId">): string;
|
|
153
|
+
/**
|
|
154
|
+
* Whether the storage representation of the given solidity type is left aligned
|
|
155
|
+
*/
|
|
110
156
|
declare function isLeftAligned(field: Pick<RenderType, "internalTypeId">): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* The number of padding bits in the storage representation of a right-aligned solidity type
|
|
159
|
+
*/
|
|
111
160
|
declare function getLeftPaddingBits(field: Pick<RenderType, "internalTypeId" | "staticByteLength">): number;
|
|
112
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Render a list of enum data as solidity enum definitions
|
|
164
|
+
*/
|
|
113
165
|
declare function renderEnums(enums: RenderEnum[]): string;
|
|
114
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Renders the necessary helper functions to typecast to/from the types of given fields and keys
|
|
169
|
+
*/
|
|
115
170
|
declare function renderTypeHelpers(options: {
|
|
116
171
|
fields: RenderField[];
|
|
117
172
|
keyTuple: RenderKeyTuple[];
|
|
@@ -147,29 +202,66 @@ declare function contractToInterface(data: string, contractName: string): {
|
|
|
147
202
|
};
|
|
148
203
|
|
|
149
204
|
interface SolidityUserDefinedType {
|
|
205
|
+
/** Fully-qualified name of the user-defined type (may include a library name as prefix) */
|
|
150
206
|
typeId: string;
|
|
207
|
+
/** Name of the wrapped primitive type */
|
|
151
208
|
internalTypeId: string;
|
|
209
|
+
/** Symbol which must be imported to use the type (either the type name, or the library name where the type is defined) */
|
|
152
210
|
importSymbol: string;
|
|
211
|
+
/** Path to the solidity file which contains the user type */
|
|
153
212
|
fromPath: string;
|
|
213
|
+
/** Whether `fromPath` is relative */
|
|
154
214
|
isRelativePath: boolean;
|
|
155
215
|
}
|
|
156
216
|
/**
|
|
157
217
|
* Parse the solidity data to extract user-defined type information.
|
|
158
218
|
* @param data contents of a solidity file with the user types declarations
|
|
159
219
|
* @param userTypeNames names of the user types to extract
|
|
220
|
+
* @param fromPath path to the solidity file from which the user types are extracted
|
|
221
|
+
* @returns record of type names mapped to the extracted type information
|
|
160
222
|
*/
|
|
161
223
|
declare function extractUserTypes(data: string, userTypeNames: string[], fromPath: string): Record<string, SolidityUserDefinedType>;
|
|
162
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Formats solidity code using prettier
|
|
227
|
+
* @param content solidity code
|
|
228
|
+
* @param prettierConfigPath optional path to a prettier config
|
|
229
|
+
* @returns formatted solidity code
|
|
230
|
+
*/
|
|
163
231
|
declare function formatSolidity(content: string, prettierConfigPath?: string): Promise<string>;
|
|
232
|
+
/**
|
|
233
|
+
* Formats typescript code using prettier
|
|
234
|
+
* @param content typescript code
|
|
235
|
+
* @returns formatted typescript code
|
|
236
|
+
*/
|
|
164
237
|
declare function formatTypescript(content: string): Promise<string>;
|
|
165
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Formats solidity code using prettier and write it to a file
|
|
241
|
+
* @param output solidity code
|
|
242
|
+
* @param fullOutputPath full path to the output file
|
|
243
|
+
* @param logPrefix prefix for debug logs
|
|
244
|
+
*/
|
|
166
245
|
declare function formatAndWriteSolidity(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Formats typescript code using prettier and write it to a file
|
|
248
|
+
* @param output typescript code
|
|
249
|
+
* @param fullOutputPath full path to the output file
|
|
250
|
+
* @param logPrefix prefix for debug logs
|
|
251
|
+
*/
|
|
167
252
|
declare function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string): Promise<void>;
|
|
168
253
|
|
|
169
254
|
type UserType = {
|
|
170
255
|
filePath: string;
|
|
171
256
|
internalType: SchemaAbiType;
|
|
172
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* Load the user type files and extract type information from them.
|
|
260
|
+
* @param userTypes record of user type data mapped by type names
|
|
261
|
+
* @param outputBaseDirectory base path to the output directory
|
|
262
|
+
* @param remappings solc remappings
|
|
263
|
+
* @returns record of the user type information mapped by type names
|
|
264
|
+
*/
|
|
173
265
|
declare function loadAndExtractUserTypes(userTypes: Record<string, UserType>, outputBaseDirectory: string, remappings: [string, string][]): Record<string, SolidityUserDefinedType>;
|
|
174
266
|
|
|
175
267
|
/**
|
package/dist/codegen.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
pragma solidity >=0.8.
|
|
1
|
+
import{a as u,c as Y}from"./chunk-YEN6EYTC.js";import{a as p}from"./chunk-UPQEB2HW.js";import X from"path";import{parse as _,visit as f}from"@solidity-parser/parser";function ie(t,r){let n=_(t),i=j(_(t),r),s=[],o=[],a=[];if(!i)throw new p(`Contract not found: ${r}`);return f(i,{FunctionDefinition({name:y,visibility:T,parameters:c,stateMutability:R,returnParameters:g,isConstructor:L,isFallback:k,isReceiveEther:W}){try{if(L||k||W)return;if(T==="default")throw new p("Visibility is not specified");if(T==="external"||T==="public"){o.push({name:y===null?"":y,parameters:c.map(m),stateMutability:R||"",returnParameters:g===null?[]:g.map(m)});for(let{typeName:I}of c.concat(g??[])){let O=l(I);s=s.concat(b(n,O))}}}catch(I){throw I instanceof p&&(I.message=`Function "${y}" in contract "${r}": ${I.message}`),I}},CustomErrorDefinition({name:y,parameters:T}){a.push({name:y,parameters:T.map(m)});for(let c of T){let R=l(c.typeName);s=s.concat(b(n,R))}}}),{functions:o,errors:a,symbolImports:s}}function j(t,r){let n;return f(t,{ContractDefinition(i){i.name===r&&(n=i)}}),n}function m({name:t,typeName:r,storageLocation:n}){let i="",{name:s,stateMutability:o}=h(r);return i+=s,o!==null&&(i+=` ${o}`),n!==null&&(i+=` ${n}`),t!==null&&(i+=` ${t}`),i}function h(t){if(t===null)return{name:"",stateMutability:null};if(t.type==="ElementaryTypeName")return{name:t.name,stateMutability:t.stateMutability};if(t.type==="UserDefinedTypeName")return{name:t.namePath,stateMutability:null};if(t.type==="ArrayTypeName"){let r="";t.length?.type==="NumberLiteral"?r=t.length.number:t.length?.type==="Identifier"&&(r=t.length.name);let{name:n,stateMutability:i}=h(t.baseTypeName);return{name:`${n}[${r}]`,stateMutability:i}}else throw new p(`Invalid typeName.type ${t.type}`)}function l(t){if(t?.type==="UserDefinedTypeName")return[t.namePath.split(".")[0]];if(t?.type==="ArrayTypeName"){let r=l(t.baseTypeName);if(t.length?.type==="Identifier"){let n=t.length.name;r.push(n.split(".")[0])}return r}else return[]}function b(t,r){let n=[];for(let i of r){let s;if(f(t,{ImportDirective({path:o,symbolAliases:a}){if(a)for(let y of a){let T=y[1]||y[0];if(i===T){s={symbol:y[0],path:o};return}}}}),s)n.push(s);else throw new p(`Symbol "${i}" has no explicit import`)}return n}import{parse as H,visit as K}from"@solidity-parser/parser";function U(t,r,n){let i=H(t),s=n.at(0)===".",o={};return K(i,{TypeDefinition({name:a,definition:y},T){if(y.name.includes("fixed"))throw new p("Fixed point numbers are not supported by MUD");if(r.includes(a)){if(a in o)throw new p(`File has multiple user types with the same name: ${a}`);T?.type==="ContractDefinition"?o[a]={typeId:`${T.name}.${a}`,internalTypeId:y.name,importSymbol:T.name,fromPath:n,isRelativePath:s}:o[a]={typeId:a,internalTypeId:y.name,importSymbol:a,fromPath:n,isRelativePath:s}}}}),o}import d from"prettier";import V from"prettier-plugin-solidity";async function E(t,r){let n;r&&(n=await d.resolveConfig(r));try{return d.format(t,{plugins:[V],parser:"solidity-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...n})}catch(i){let s;return i instanceof Error?s=i.message:s=i,console.log(`Error during output formatting: ${s}`),t}}async function x(t){return d.format(t,{parser:"typescript"})}import{mkdir as $,writeFile as w}from"fs/promises";import{dirname as v}from"path";var A=u.extend("codegen"),z=u.extend("codegen");A.log=console.debug.bind(console);z.log=console.error.bind(console);async function le(t,r,n){let i=await E(t);await $(v(r),{recursive:!0}),await w(r,i),A(`${n}: ${r}`)}async function fe(t,r,n){let i=await x(t);await $(v(r),{recursive:!0}),await w(r,i),A(`${n}: ${r}`)}import{readFileSync as D}from"fs";import J from"path";function be(t,r,n){let i={};for(let[o,{filePath:a}]of Object.entries(t))a in i||(i[a]=[]),i[a].push(o);let s={};for(let[o,a]of Object.entries(i)){let{filePath:y,data:T}=G(r,o,n),c=U(T,a,y);for(let[R,g]of Object.entries(c))if(g.internalTypeId!==t[R].internalType)throw new p(`User type "${R}" has internal type "${g.internalTypeId}" but config specifies "${t[R].internalType}"`);s={...s,...c}}return s}function G(t,r,n){if(r.at(0)===".")return{filePath:"./"+J.relative(t,r),data:D(r,"utf8")};{let i=r;for(let[s,o]of n)if(i.includes(s)){i=i.replace(s,o);break}return{filePath:r,data:D(i,"utf8")}}}function B(t){return t.replace(/\\/g,"/")}var P=`// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.24;
|
|
3
3
|
|
|
4
|
-
/* Autogenerated file. Do not edit manually. */`;function S(r
|
|
5
|
-
bytes32[] memory _keyTuple = new bytes32[](${
|
|
6
|
-
${S(
|
|
7
|
-
`;return{_typedTableId:n,_typedKeyArgs:i,_keyTupleDefinition:s}}function
|
|
8
|
-
`)}function
|
|
9
|
-
`+
|
|
10
|
-
`+n("")),s}function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
abi.encodePacked(
|
|
14
|
-
${n?"RESOURCE_OFFCHAIN_TABLE":"RESOURCE_TABLE"},
|
|
15
|
-
bytes14("${r}"),
|
|
16
|
-
bytes16("${t}")
|
|
17
|
-
)
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
`,o=`
|
|
21
|
-
ResourceId constant _tableId = ${s};
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */`;function S(t,r){return M("",t,r)}function N(t){let r=t.filter(n=>n!==void 0&&n!=="");return M(",",r,n=>n)}function Le({staticResourceData:t,keyTuple:r}){let n=t?"":"ResourceId _tableId",i=N(r.map(({name:o,typeWithLocation:a})=>`${a} ${o}`)),s=`
|
|
5
|
+
bytes32[] memory _keyTuple = new bytes32[](${r.length});
|
|
6
|
+
${S(r,(o,a)=>`_keyTuple[${a}] = ${q(o.name,o)};`)}
|
|
7
|
+
`;return{_typedTableId:n,_typedKeyArgs:i,_keyTupleDefinition:s}}function C(t,r){return B("./"+X.relative("./"+r,"./"+t))}function ke(t){return F(t.map(r=>"path"in r?r:{symbol:r.symbol,path:C(r.fromPath,r.usedInPath)}))}function We(t){return F(t.map(({symbol:r,fromPath:n,usedInPath:i})=>({symbol:r,path:C(n,i)})))}function F(t){let r=new Map;for(let{symbol:i,path:s}of t)r.has(s)||r.set(s,new Set),r.get(s)?.add(i);let n=[];for(let[i,s]of r){let o=[...s].join(", ");n.push(`import { ${o} } from "${B(i)}";`)}return n.join(`
|
|
8
|
+
`)}function Oe(t,r){let n="";return n+=r({_typedStore:void 0,_store:"StoreSwitch",_commentSuffix:"",_methodNamePrefix:""}),n+=r({_typedStore:void 0,_store:"StoreCore",_commentSuffix:"",_methodNamePrefix:"_",_useExplicitFieldLayout:!0}),t&&(n+=`
|
|
9
|
+
`+r({_typedStore:"IStore _store",_store:"_store",_commentSuffix:" (using the specified store)",_methodNamePrefix:""})),n}function je(t,r,n){let i=`${r[0].toUpperCase()}${r.slice(1)}`,s="";return s+=n(i),t&&(s+=`
|
|
10
|
+
`+n("")),s}function He({namespace:t,name:r,offchainOnly:n,tableIdName:i}){return`
|
|
11
|
+
// Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(t)}, name: ${JSON.stringify(r)}, typeId: ${n?"RESOURCE_OFFCHAIN_TABLE":"RESOURCE_TABLE"} });\`
|
|
12
|
+
ResourceId constant _tableId = ResourceId.wrap(${Y({type:n?"offchainTable":"table",namespace:t,name:r})});
|
|
22
13
|
ResourceId constant ${i} = _tableId;
|
|
23
|
-
|
|
24
|
-
`)}function
|
|
14
|
+
`}function q(t,{typeUnwrap:r,internalTypeId:n}){let i=r.length?`${r}(${t})`:t;if(n==="bytes32")return i;if(/^bytes\d{1,2}$/.test(n))return`bytes32(${i})`;if(/^uint\d{1,3}$/.test(n))return`bytes32(uint256(${i}))`;if(/^int\d{1,3}$/.test(n))return`bytes32(uint256(int256(${i})))`;if(n==="address")return`bytes32(uint256(uint160(${i})))`;if(n==="bool")return`_boolToBytes32(${i})`;throw new Error(`Unknown value type id ${n}`)}function Q(t){return/^bytes\d{1,2}$/.test(t.internalTypeId)}function Ke(t){return Q(t)?0:256-t.staticByteLength*8}function M(t,r,n){return r.map((i,s)=>n(i,s)+(s===r.length-1?"":t)).join(`
|
|
15
|
+
`)}function Je(t){let r=P;return r+=S(t,({name:n,memberNames:i})=>`
|
|
25
16
|
enum ${n} {
|
|
26
|
-
${
|
|
17
|
+
${N(i)}
|
|
27
18
|
}
|
|
28
|
-
`),
|
|
19
|
+
`),r}function Xe(t){let{fields:r,keyTuple:n}=t,i="";for(let s of Z([...r,...n]))i+=s;return r.some(({internalTypeId:s})=>s.match("bool"))&&(i+=`
|
|
29
20
|
/**
|
|
30
21
|
* @notice Cast a value to a bool.
|
|
31
22
|
* @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool.
|
|
@@ -47,7 +38,7 @@ pragma solidity >=0.8.21;
|
|
|
47
38
|
result := value
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
|
-
`),i}function
|
|
41
|
+
`),i}function Z(t){let r=new Map,n=new Map;for(let{typeWrappingData:i,typeWrap:s,typeUnwrap:o,internalTypeId:a}of t){if(!i)continue;let{kind:y}=i;if(y==="staticArray"){let{elementType:T,staticLength:c}=i;r.set(s,ee(s,T,c,a)),n.set(o,te(o,T,c,a))}}return[...r.values(),...n.values()]}function ee(t,r,n,i){return`
|
|
51
42
|
/**
|
|
52
43
|
* @notice Cast a dynamic array to a static array.
|
|
53
44
|
* @dev In memory static arrays are just dynamic arrays without the 32 length bytes,
|
|
@@ -57,10 +48,10 @@ pragma solidity >=0.8.21;
|
|
|
57
48
|
* @param _value The dynamic array to cast.
|
|
58
49
|
* @return _result The static array.
|
|
59
50
|
*/
|
|
60
|
-
function ${
|
|
51
|
+
function ${t}(
|
|
61
52
|
${i} memory _value
|
|
62
53
|
) pure returns (
|
|
63
|
-
${
|
|
54
|
+
${r}[${n}] memory _result
|
|
64
55
|
) {
|
|
65
56
|
if (_value.length < ${n}) {
|
|
66
57
|
// return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption
|
|
@@ -73,15 +64,15 @@ pragma solidity >=0.8.21;
|
|
|
73
64
|
}
|
|
74
65
|
}
|
|
75
66
|
}
|
|
76
|
-
`}function
|
|
67
|
+
`}function te(t,r,n,i){let s=n*32;return`
|
|
77
68
|
/**
|
|
78
69
|
* @notice Copy a static array to a dynamic array.
|
|
79
70
|
* @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array.
|
|
80
71
|
* @param _value The static array to copy.
|
|
81
72
|
* @return _result The dynamic array.
|
|
82
73
|
*/
|
|
83
|
-
function ${
|
|
84
|
-
${
|
|
74
|
+
function ${t}(
|
|
75
|
+
${r}[${n}] memory _value
|
|
85
76
|
) pure returns (
|
|
86
77
|
${i} memory _result
|
|
87
78
|
) {
|
|
@@ -94,5 +85,5 @@ pragma solidity >=0.8.21;
|
|
|
94
85
|
}
|
|
95
86
|
Memory.copy(fromPointer, toPointer, ${s});
|
|
96
87
|
}
|
|
97
|
-
`}import{SchemaType as e}from"@latticexyz/schema-type/deprecated";var
|
|
88
|
+
`}import{SchemaType as e}from"@latticexyz/schema-type/deprecated";var it={[e.UINT8]:"RecsType.Number",[e.UINT16]:"RecsType.Number",[e.UINT24]:"RecsType.Number",[e.UINT32]:"RecsType.Number",[e.UINT40]:"RecsType.Number",[e.UINT48]:"RecsType.Number",[e.UINT56]:"RecsType.BigInt",[e.UINT64]:"RecsType.BigInt",[e.UINT72]:"RecsType.BigInt",[e.UINT80]:"RecsType.BigInt",[e.UINT88]:"RecsType.BigInt",[e.UINT96]:"RecsType.BigInt",[e.UINT104]:"RecsType.BigInt",[e.UINT112]:"RecsType.BigInt",[e.UINT120]:"RecsType.BigInt",[e.UINT128]:"RecsType.BigInt",[e.UINT136]:"RecsType.BigInt",[e.UINT144]:"RecsType.BigInt",[e.UINT152]:"RecsType.BigInt",[e.UINT160]:"RecsType.BigInt",[e.UINT168]:"RecsType.BigInt",[e.UINT176]:"RecsType.BigInt",[e.UINT184]:"RecsType.BigInt",[e.UINT192]:"RecsType.BigInt",[e.UINT200]:"RecsType.BigInt",[e.UINT208]:"RecsType.BigInt",[e.UINT216]:"RecsType.BigInt",[e.UINT224]:"RecsType.BigInt",[e.UINT232]:"RecsType.BigInt",[e.UINT240]:"RecsType.BigInt",[e.UINT248]:"RecsType.BigInt",[e.UINT256]:"RecsType.BigInt",[e.INT8]:"RecsType.Number",[e.INT16]:"RecsType.Number",[e.INT24]:"RecsType.Number",[e.INT32]:"RecsType.Number",[e.INT40]:"RecsType.Number",[e.INT48]:"RecsType.Number",[e.INT56]:"RecsType.BigInt",[e.INT64]:"RecsType.BigInt",[e.INT72]:"RecsType.BigInt",[e.INT80]:"RecsType.BigInt",[e.INT88]:"RecsType.BigInt",[e.INT96]:"RecsType.BigInt",[e.INT104]:"RecsType.BigInt",[e.INT112]:"RecsType.BigInt",[e.INT120]:"RecsType.BigInt",[e.INT128]:"RecsType.BigInt",[e.INT136]:"RecsType.BigInt",[e.INT144]:"RecsType.BigInt",[e.INT152]:"RecsType.BigInt",[e.INT160]:"RecsType.BigInt",[e.INT168]:"RecsType.BigInt",[e.INT176]:"RecsType.BigInt",[e.INT184]:"RecsType.BigInt",[e.INT192]:"RecsType.BigInt",[e.INT200]:"RecsType.BigInt",[e.INT208]:"RecsType.BigInt",[e.INT216]:"RecsType.BigInt",[e.INT224]:"RecsType.BigInt",[e.INT232]:"RecsType.BigInt",[e.INT240]:"RecsType.BigInt",[e.INT248]:"RecsType.BigInt",[e.INT256]:"RecsType.BigInt",[e.BYTES1]:"RecsType.String",[e.BYTES2]:"RecsType.String",[e.BYTES3]:"RecsType.String",[e.BYTES4]:"RecsType.String",[e.BYTES5]:"RecsType.String",[e.BYTES6]:"RecsType.String",[e.BYTES7]:"RecsType.String",[e.BYTES8]:"RecsType.String",[e.BYTES9]:"RecsType.String",[e.BYTES10]:"RecsType.String",[e.BYTES11]:"RecsType.String",[e.BYTES12]:"RecsType.String",[e.BYTES13]:"RecsType.String",[e.BYTES14]:"RecsType.String",[e.BYTES15]:"RecsType.String",[e.BYTES16]:"RecsType.String",[e.BYTES17]:"RecsType.String",[e.BYTES18]:"RecsType.String",[e.BYTES19]:"RecsType.String",[e.BYTES20]:"RecsType.String",[e.BYTES21]:"RecsType.String",[e.BYTES22]:"RecsType.String",[e.BYTES23]:"RecsType.String",[e.BYTES24]:"RecsType.String",[e.BYTES25]:"RecsType.String",[e.BYTES26]:"RecsType.String",[e.BYTES27]:"RecsType.String",[e.BYTES28]:"RecsType.String",[e.BYTES29]:"RecsType.String",[e.BYTES30]:"RecsType.String",[e.BYTES31]:"RecsType.String",[e.BYTES32]:"RecsType.String",[e.BOOL]:"RecsType.Boolean",[e.ADDRESS]:"RecsType.String",[e.UINT8_ARRAY]:"RecsType.NumberArray",[e.UINT16_ARRAY]:"RecsType.NumberArray",[e.UINT24_ARRAY]:"RecsType.NumberArray",[e.UINT32_ARRAY]:"RecsType.NumberArray",[e.UINT40_ARRAY]:"RecsType.NumberArray",[e.UINT48_ARRAY]:"RecsType.NumberArray",[e.UINT56_ARRAY]:"RecsType.BigIntArray",[e.UINT64_ARRAY]:"RecsType.BigIntArray",[e.UINT72_ARRAY]:"RecsType.BigIntArray",[e.UINT80_ARRAY]:"RecsType.BigIntArray",[e.UINT88_ARRAY]:"RecsType.BigIntArray",[e.UINT96_ARRAY]:"RecsType.BigIntArray",[e.UINT104_ARRAY]:"RecsType.BigIntArray",[e.UINT112_ARRAY]:"RecsType.BigIntArray",[e.UINT120_ARRAY]:"RecsType.BigIntArray",[e.UINT128_ARRAY]:"RecsType.BigIntArray",[e.UINT136_ARRAY]:"RecsType.BigIntArray",[e.UINT144_ARRAY]:"RecsType.BigIntArray",[e.UINT152_ARRAY]:"RecsType.BigIntArray",[e.UINT160_ARRAY]:"RecsType.BigIntArray",[e.UINT168_ARRAY]:"RecsType.BigIntArray",[e.UINT176_ARRAY]:"RecsType.BigIntArray",[e.UINT184_ARRAY]:"RecsType.BigIntArray",[e.UINT192_ARRAY]:"RecsType.BigIntArray",[e.UINT200_ARRAY]:"RecsType.BigIntArray",[e.UINT208_ARRAY]:"RecsType.BigIntArray",[e.UINT216_ARRAY]:"RecsType.BigIntArray",[e.UINT224_ARRAY]:"RecsType.BigIntArray",[e.UINT232_ARRAY]:"RecsType.BigIntArray",[e.UINT240_ARRAY]:"RecsType.BigIntArray",[e.UINT248_ARRAY]:"RecsType.BigIntArray",[e.UINT256_ARRAY]:"RecsType.BigIntArray",[e.INT8_ARRAY]:"RecsType.NumberArray",[e.INT16_ARRAY]:"RecsType.NumberArray",[e.INT24_ARRAY]:"RecsType.NumberArray",[e.INT32_ARRAY]:"RecsType.NumberArray",[e.INT40_ARRAY]:"RecsType.NumberArray",[e.INT48_ARRAY]:"RecsType.NumberArray",[e.INT56_ARRAY]:"RecsType.BigIntArray",[e.INT64_ARRAY]:"RecsType.BigIntArray",[e.INT72_ARRAY]:"RecsType.BigIntArray",[e.INT80_ARRAY]:"RecsType.BigIntArray",[e.INT88_ARRAY]:"RecsType.BigIntArray",[e.INT96_ARRAY]:"RecsType.BigIntArray",[e.INT104_ARRAY]:"RecsType.BigIntArray",[e.INT112_ARRAY]:"RecsType.BigIntArray",[e.INT120_ARRAY]:"RecsType.BigIntArray",[e.INT128_ARRAY]:"RecsType.BigIntArray",[e.INT136_ARRAY]:"RecsType.BigIntArray",[e.INT144_ARRAY]:"RecsType.BigIntArray",[e.INT152_ARRAY]:"RecsType.BigIntArray",[e.INT160_ARRAY]:"RecsType.BigIntArray",[e.INT168_ARRAY]:"RecsType.BigIntArray",[e.INT176_ARRAY]:"RecsType.BigIntArray",[e.INT184_ARRAY]:"RecsType.BigIntArray",[e.INT192_ARRAY]:"RecsType.BigIntArray",[e.INT200_ARRAY]:"RecsType.BigIntArray",[e.INT208_ARRAY]:"RecsType.BigIntArray",[e.INT216_ARRAY]:"RecsType.BigIntArray",[e.INT224_ARRAY]:"RecsType.BigIntArray",[e.INT232_ARRAY]:"RecsType.BigIntArray",[e.INT240_ARRAY]:"RecsType.BigIntArray",[e.INT248_ARRAY]:"RecsType.BigIntArray",[e.INT256_ARRAY]:"RecsType.BigIntArray",[e.BYTES1_ARRAY]:"RecsType.BigIntArray",[e.BYTES2_ARRAY]:"RecsType.BigIntArray",[e.BYTES3_ARRAY]:"RecsType.BigIntArray",[e.BYTES4_ARRAY]:"RecsType.BigIntArray",[e.BYTES5_ARRAY]:"RecsType.BigIntArray",[e.BYTES6_ARRAY]:"RecsType.BigIntArray",[e.BYTES7_ARRAY]:"RecsType.BigIntArray",[e.BYTES8_ARRAY]:"RecsType.BigIntArray",[e.BYTES9_ARRAY]:"RecsType.BigIntArray",[e.BYTES10_ARRAY]:"RecsType.BigIntArray",[e.BYTES11_ARRAY]:"RecsType.BigIntArray",[e.BYTES12_ARRAY]:"RecsType.BigIntArray",[e.BYTES13_ARRAY]:"RecsType.BigIntArray",[e.BYTES14_ARRAY]:"RecsType.BigIntArray",[e.BYTES15_ARRAY]:"RecsType.BigIntArray",[e.BYTES16_ARRAY]:"RecsType.BigIntArray",[e.BYTES17_ARRAY]:"RecsType.BigIntArray",[e.BYTES18_ARRAY]:"RecsType.BigIntArray",[e.BYTES19_ARRAY]:"RecsType.BigIntArray",[e.BYTES20_ARRAY]:"RecsType.BigIntArray",[e.BYTES21_ARRAY]:"RecsType.BigIntArray",[e.BYTES22_ARRAY]:"RecsType.BigIntArray",[e.BYTES23_ARRAY]:"RecsType.BigIntArray",[e.BYTES24_ARRAY]:"RecsType.BigIntArray",[e.BYTES25_ARRAY]:"RecsType.BigIntArray",[e.BYTES26_ARRAY]:"RecsType.BigIntArray",[e.BYTES27_ARRAY]:"RecsType.BigIntArray",[e.BYTES28_ARRAY]:"RecsType.BigIntArray",[e.BYTES29_ARRAY]:"RecsType.BigIntArray",[e.BYTES30_ARRAY]:"RecsType.BigIntArray",[e.BYTES31_ARRAY]:"RecsType.BigIntArray",[e.BYTES32_ARRAY]:"RecsType.BigIntArray",[e.BOOL_ARRAY]:"RecsType.T",[e.ADDRESS_ARRAY]:"RecsType.StringArray",[e.BYTES]:"RecsType.String",[e.STRING]:"RecsType.String"};export{ie as contractToInterface,U as extractUserTypes,le as formatAndWriteSolidity,fe as formatAndWriteTypescript,E as formatSolidity,x as formatTypescript,Ke as getLeftPaddingBits,Q as isLeftAligned,be as loadAndExtractUserTypes,B as posixPath,F as renderAbsoluteImports,N as renderArguments,Le as renderCommonData,Je as renderEnums,ke as renderImports,S as renderList,We as renderRelativeImports,He as renderTableId,Xe as renderTypeHelpers,q as renderValueTypeToBytes32,je as renderWithFieldSuffix,Oe as renderWithStore,P as renderedSolidityHeader,it as schemaTypesToRecsTypeStrings,C as solidityRelativeImportPath};
|
|
98
89
|
//# sourceMappingURL=codegen.js.map
|