@latticexyz/common 2.2.18-8d0ce55e964e646a1c804c401df01c4deb866f30 → 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/actions.cjs +334 -0
  2. package/dist/actions.cjs.map +1 -0
  3. package/dist/actions.d.cts +27 -0
  4. package/dist/actions.js +39 -1
  5. package/dist/actions.js.map +1 -1
  6. package/dist/chains.cjs +106 -0
  7. package/dist/chains.cjs.map +1 -0
  8. package/dist/chains.d.cts +968 -0
  9. package/dist/chains.js +75 -1
  10. package/dist/chains.js.map +1 -1
  11. package/dist/chunk-D4GDXAMP.js +64 -0
  12. package/dist/{chunk-ZIUX7JCQ.js.map → chunk-D4GDXAMP.js.map} +1 -1
  13. package/dist/chunk-IYZZFDNO.js +16 -0
  14. package/dist/{chunk-ZV2KGJCD.js.map → chunk-IYZZFDNO.js.map} +1 -1
  15. package/dist/chunk-MF5NFUW7.js +12 -0
  16. package/dist/{chunk-QQCZY3XJ.js.map → chunk-MF5NFUW7.js.map} +1 -1
  17. package/dist/chunk-MK6UECU7.js +11 -0
  18. package/dist/{chunk-TCWGPC6G.js.map → chunk-MK6UECU7.js.map} +1 -1
  19. package/dist/chunk-MYWRXQQH.js +208 -0
  20. package/dist/{chunk-6FIKI2CG.js.map → chunk-MYWRXQQH.js.map} +1 -1
  21. package/dist/chunk-Z6SVAIZN.js +70 -0
  22. package/dist/{chunk-DPUUE7NM.js.map → chunk-Z6SVAIZN.js.map} +1 -1
  23. package/dist/codegen.cjs +889 -0
  24. package/dist/codegen.cjs.map +1 -0
  25. package/dist/codegen.d.cts +228 -0
  26. package/dist/codegen.js +706 -49
  27. package/dist/codegen.js.map +1 -1
  28. package/dist/errors.cjs +38 -0
  29. package/dist/errors.cjs.map +1 -0
  30. package/dist/errors.d.cts +5 -0
  31. package/dist/errors.js +6 -1
  32. package/dist/foundry.cjs +105 -0
  33. package/dist/foundry.cjs.map +1 -0
  34. package/dist/foundry.d.cts +69 -0
  35. package/dist/foundry.js +71 -2
  36. package/dist/foundry.js.map +1 -1
  37. package/dist/getContract-CA0EdVg6.d.cts +20 -0
  38. package/dist/index.cjs +597 -0
  39. package/dist/index.cjs.map +1 -0
  40. package/dist/index.d.cts +160 -0
  41. package/dist/index.js +233 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/internal.cjs +459 -0
  44. package/dist/internal.cjs.map +1 -0
  45. package/dist/internal.d.cts +36 -0
  46. package/dist/internal.js +205 -9
  47. package/dist/internal.js.map +1 -1
  48. package/dist/kms.cjs +204 -0
  49. package/dist/kms.cjs.map +1 -0
  50. package/dist/kms.d.cts +18 -0
  51. package/dist/kms.js +168 -1
  52. package/dist/kms.js.map +1 -1
  53. package/dist/type-utils.cjs +19 -0
  54. package/dist/type-utils.cjs.map +1 -0
  55. package/dist/type-utils.d.cts +19 -0
  56. package/dist/utils.cjs +174 -0
  57. package/dist/utils.cjs.map +1 -0
  58. package/dist/utils.d.cts +40 -0
  59. package/dist/utils.js +122 -1
  60. package/dist/utils.js.map +1 -1
  61. package/package.json +102 -12
  62. package/dist/chunk-6FIKI2CG.js +0 -2
  63. package/dist/chunk-DPUUE7NM.js +0 -2
  64. package/dist/chunk-QQCZY3XJ.js +0 -2
  65. package/dist/chunk-TCWGPC6G.js +0 -2
  66. package/dist/chunk-ZIUX7JCQ.js +0 -2
  67. package/dist/chunk-ZV2KGJCD.js +0 -2
@@ -0,0 +1,889 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/codegen/index.ts
31
+ var codegen_exports = {};
32
+ __export(codegen_exports, {
33
+ abiToInterface: () => abiToInterface,
34
+ contractToInterface: () => contractToInterface,
35
+ findContractNode: () => findContractNode,
36
+ formatAndWriteSolidity: () => formatAndWriteSolidity,
37
+ formatAndWriteTypescript: () => formatAndWriteTypescript,
38
+ formatSolidity: () => formatSolidity,
39
+ formatTypescript: () => formatTypescript,
40
+ getLeftPaddingBits: () => getLeftPaddingBits,
41
+ isLeftAligned: () => isLeftAligned,
42
+ renderArguments: () => renderArguments,
43
+ renderCommonData: () => renderCommonData,
44
+ renderEnums: () => renderEnums,
45
+ renderImportPath: () => renderImportPath,
46
+ renderImports: () => renderImports,
47
+ renderList: () => renderList,
48
+ renderTableId: () => renderTableId,
49
+ renderTypeHelpers: () => renderTypeHelpers,
50
+ renderValueTypeToBytes32: () => renderValueTypeToBytes32,
51
+ renderWithFieldSuffix: () => renderWithFieldSuffix,
52
+ renderWithStore: () => renderWithStore,
53
+ renderedSolidityHeader: () => renderedSolidityHeader,
54
+ schemaTypesToRecsTypeStrings: () => schemaTypesToRecsTypeStrings
55
+ });
56
+ module.exports = __toCommonJS(codegen_exports);
57
+
58
+ // src/codegen/render-solidity/abiToInterface.ts
59
+ var import_abitype = require("abitype");
60
+
61
+ // src/resourceToHex.ts
62
+ var import_viem = require("viem");
63
+ var resourceTypeIds = {
64
+ // keep these in sync with storeResourceTypes.sol
65
+ table: "tb",
66
+ offchainTable: "ot",
67
+ // keep these in sync with worldResourceTypes.sol
68
+ namespace: "ns",
69
+ system: "sy"
70
+ };
71
+ function resourceToHex(resource) {
72
+ const typeId = resourceTypeIds[resource.type];
73
+ if (resource.namespace.length > 14) {
74
+ throw new Error(`Namespaces must fit into \`bytes14\`, but "${resource.namespace}" is too long.`);
75
+ }
76
+ return (0, import_viem.concatHex)([
77
+ (0, import_viem.stringToHex)(typeId, { size: 2 }),
78
+ (0, import_viem.stringToHex)(resource.namespace, { size: 14 }),
79
+ (0, import_viem.stringToHex)(resource.name.slice(0, 16), { size: 16 })
80
+ ]);
81
+ }
82
+
83
+ // src/hexToResource.ts
84
+ var import_viem2 = require("viem");
85
+
86
+ // src/resourceTypes.ts
87
+ var resourceTypes = ["table", "offchainTable", "namespace", "system"];
88
+
89
+ // src/resourceToLabel.ts
90
+ var rootNamespace = "";
91
+ function resourceToLabel({
92
+ namespace,
93
+ name
94
+ }) {
95
+ return namespace === rootNamespace ? name : `${namespace}__${name}`;
96
+ }
97
+
98
+ // src/hexToResource.ts
99
+ var resourceTypeIdToType = Object.fromEntries(
100
+ Object.entries(resourceTypeIds).map(([key, value]) => [value, key])
101
+ );
102
+ function getResourceType(resourceTypeId) {
103
+ const type = resourceTypeIdToType[resourceTypeId];
104
+ if (resourceTypes.includes(type)) {
105
+ return type;
106
+ }
107
+ }
108
+ function hexToResource(hex) {
109
+ const resourceTypeId = (0, import_viem2.hexToString)((0, import_viem2.sliceHex)(hex, 0, 2)).replace(/\0+$/, "");
110
+ const type = getResourceType(resourceTypeId);
111
+ const namespace = (0, import_viem2.hexToString)((0, import_viem2.sliceHex)(hex, 2, 16)).replace(/\0+$/, "");
112
+ const name = (0, import_viem2.hexToString)((0, import_viem2.sliceHex)(hex, 16, 32)).replace(/\0+$/, "");
113
+ if (!type) {
114
+ throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);
115
+ }
116
+ return { resourceId: hex, type, namespace, name };
117
+ }
118
+
119
+ // src/codegen/render-solidity/renderImportPath.ts
120
+ var import_node_path = __toESM(require("path"), 1);
121
+ function winToPosix(segment) {
122
+ return segment.replaceAll(import_node_path.default.win32.sep, import_node_path.default.posix.sep);
123
+ }
124
+ function renderImportPath(basePath, ...segments) {
125
+ const fullPath = import_node_path.default.posix.join(winToPosix(basePath), ...segments.map(winToPosix)).replace(/\/$/, "");
126
+ if (basePath.startsWith(".")) {
127
+ const relativePath = "./" + fullPath;
128
+ return relativePath.replace(/^(\.\/)+\./, ".");
129
+ }
130
+ return fullPath;
131
+ }
132
+
133
+ // src/codegen/render-solidity/common.ts
134
+ var renderedSolidityHeader = `// SPDX-License-Identifier: MIT
135
+ pragma solidity >=0.8.24;
136
+
137
+ /* Autogenerated file. Do not edit manually. */`;
138
+ function renderList(list, renderItem) {
139
+ return internalRenderList("", list, renderItem);
140
+ }
141
+ function renderArguments(args) {
142
+ const filteredArgs = args.filter((arg) => arg !== void 0 && arg !== "");
143
+ return internalRenderList(",", filteredArgs, (arg) => arg);
144
+ }
145
+ function renderCommonData({
146
+ staticResourceData,
147
+ keyTuple
148
+ }) {
149
+ const _typedTableId = staticResourceData ? "" : "ResourceId _tableId";
150
+ const _typedKeyArgs = renderArguments(keyTuple.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));
151
+ const _keyTupleDefinition = `
152
+ bytes32[] memory _keyTuple = new bytes32[](${keyTuple.length});
153
+ ${renderList(keyTuple, (key, index) => `_keyTuple[${index}] = ${renderValueTypeToBytes32(key.name, key)};`)}
154
+ `;
155
+ return {
156
+ _typedTableId,
157
+ _typedKeyArgs,
158
+ _keyTupleDefinition
159
+ };
160
+ }
161
+ function renderImports(imports) {
162
+ const aggregatedImports = /* @__PURE__ */ new Map();
163
+ for (const { symbol, path: path3 } of imports) {
164
+ if (!aggregatedImports.has(path3)) {
165
+ aggregatedImports.set(path3, /* @__PURE__ */ new Set());
166
+ }
167
+ aggregatedImports.get(path3)?.add(symbol);
168
+ }
169
+ const renderedImports = [];
170
+ for (const [path3, symbols] of aggregatedImports) {
171
+ const renderedSymbols = [...symbols].join(", ");
172
+ renderedImports.push(`import { ${renderedSymbols} } from "${renderImportPath(path3)}";`);
173
+ }
174
+ return renderedImports.join("\n");
175
+ }
176
+ function renderWithStore(storeArgument, callback) {
177
+ let result = "";
178
+ result += callback({ _typedStore: void 0, _store: "StoreSwitch", _commentSuffix: "", _methodNamePrefix: "" });
179
+ result += callback({
180
+ _typedStore: void 0,
181
+ _store: "StoreCore",
182
+ _commentSuffix: "",
183
+ _methodNamePrefix: "_",
184
+ _useExplicitFieldLayout: true
185
+ });
186
+ if (storeArgument) {
187
+ result += "\n" + callback({
188
+ _typedStore: "IStore _store",
189
+ _store: "_store",
190
+ _commentSuffix: " (using the specified store)",
191
+ _methodNamePrefix: ""
192
+ });
193
+ }
194
+ return result;
195
+ }
196
+ function renderWithFieldSuffix(withSuffixlessFieldMethods, fieldName, callback) {
197
+ const methodNameSuffix = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`;
198
+ let result = "";
199
+ result += callback(methodNameSuffix);
200
+ if (withSuffixlessFieldMethods) {
201
+ result += "\n" + callback("");
202
+ }
203
+ return result;
204
+ }
205
+ function renderTableId({
206
+ namespace,
207
+ name,
208
+ offchainOnly
209
+ }) {
210
+ const tableId = resourceToHex({
211
+ type: offchainOnly ? "offchainTable" : "table",
212
+ namespace,
213
+ name
214
+ });
215
+ const resource = hexToResource(tableId);
216
+ return `
217
+ // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(
218
+ resource.namespace
219
+ )}, name: ${JSON.stringify(resource.name)}, typeId: ${offchainOnly ? "RESOURCE_OFFCHAIN_TABLE" : "RESOURCE_TABLE"} });\`
220
+ ResourceId constant _tableId = ResourceId.wrap(${tableId});
221
+ `;
222
+ }
223
+ function renderValueTypeToBytes32(name, { typeUnwrap, internalTypeId }) {
224
+ const innerText = typeUnwrap.length ? `${typeUnwrap}(${name})` : name;
225
+ if (internalTypeId === "bytes32") {
226
+ return innerText;
227
+ } else if (/^bytes\d{1,2}$/.test(internalTypeId)) {
228
+ return `bytes32(${innerText})`;
229
+ } else if (/^uint\d{1,3}$/.test(internalTypeId)) {
230
+ return `bytes32(uint256(${innerText}))`;
231
+ } else if (/^int\d{1,3}$/.test(internalTypeId)) {
232
+ return `bytes32(uint256(int256(${innerText})))`;
233
+ } else if (internalTypeId === "address") {
234
+ return `bytes32(uint256(uint160(${innerText})))`;
235
+ } else if (internalTypeId === "bool") {
236
+ return `_boolToBytes32(${innerText})`;
237
+ } else {
238
+ throw new Error(`Unknown value type id ${internalTypeId}`);
239
+ }
240
+ }
241
+ function isLeftAligned(field) {
242
+ return /^bytes\d{1,2}$/.test(field.internalTypeId);
243
+ }
244
+ function getLeftPaddingBits(field) {
245
+ if (isLeftAligned(field)) {
246
+ return 0;
247
+ } else {
248
+ return 256 - field.staticByteLength * 8;
249
+ }
250
+ }
251
+ function internalRenderList(lineTerminator, list, renderItem) {
252
+ return list.map((item, index) => renderItem(item, index) + (index === list.length - 1 ? "" : lineTerminator)).join("\n");
253
+ }
254
+
255
+ // src/codegen/render-solidity/abiToInterface.ts
256
+ function formatParam(param) {
257
+ return (0, import_abitype.formatAbiParameter)(param);
258
+ }
259
+ function formatFunction(item) {
260
+ const params = item.inputs.map(formatParam).join(", ");
261
+ const returns = item.outputs.map(formatParam).join(", ");
262
+ return `function ${item.name}(${params}) external${returns.length ? ` returns (${returns})` : ""}`;
263
+ }
264
+ function formatSystemId(systemId) {
265
+ const resource = hexToResource(systemId);
266
+ return `
267
+ // equivalent to \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify(
268
+ resource.namespace
269
+ )}, name: ${JSON.stringify(resource.name)}, typeId: RESOURCE_SYSTEM });\`
270
+ ResourceId constant systemId = ResourceId.wrap(${systemId});
271
+ `;
272
+ }
273
+ function abiToInterface({ name, systemId, abi }) {
274
+ const imports = systemId ? [`{ ResourceId } from "@latticexyz/store/src/ResourceId.sol"`] : [];
275
+ const errors = abi.filter((item) => item.type === "error");
276
+ const functions = abi.filter((item) => item.type === "function");
277
+ return `
278
+ ${renderedSolidityHeader}
279
+
280
+ ${imports.map((item) => `import ${item};`).join("\n")}
281
+
282
+ ${systemId ? formatSystemId(systemId) : ""}
283
+
284
+ interface ${name} {
285
+ ${errors.map((item) => `${(0, import_abitype.formatAbiItem)(item)};`).join("\n")}
286
+
287
+ ${functions.map((item) => {
288
+ if ([...item.inputs, ...item.outputs].some((param) => param.type.startsWith("tuple"))) {
289
+ return `// TODO: replace tuple with struct
290
+ // ${formatFunction(item)};`;
291
+ }
292
+ return `${formatFunction(item)};`;
293
+ }).join("\n")}
294
+ }
295
+ `;
296
+ }
297
+
298
+ // src/codegen/render-solidity/renderEnums.ts
299
+ function renderEnums(enums) {
300
+ const enumDefinitions = Object.entries(enums).map(
301
+ ([name, values]) => `
302
+ enum ${name} {
303
+ ${values.join(", ")}
304
+ }
305
+ `
306
+ );
307
+ return `
308
+ ${renderedSolidityHeader}
309
+ ${enumDefinitions.join("")}
310
+ `;
311
+ }
312
+
313
+ // src/codegen/render-solidity/renderTypeHelpers.ts
314
+ function renderTypeHelpers(options) {
315
+ const { fields, keyTuple } = options;
316
+ let result = "";
317
+ for (const wrappingHelper of getWrappingHelpers([...fields, ...keyTuple])) {
318
+ result += wrappingHelper;
319
+ }
320
+ if (fields.some(({ internalTypeId }) => internalTypeId.match("bool"))) {
321
+ result += `
322
+ /**
323
+ * @notice Cast a value to a bool.
324
+ * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool.
325
+ * @param value The uint8 value to convert.
326
+ * @return result The boolean value.
327
+ */
328
+ function _toBool(uint8 value) pure returns (bool result) {
329
+ assembly {
330
+ result := value
331
+ }
332
+ }
333
+ `;
334
+ }
335
+ if (keyTuple.some(({ internalTypeId }) => internalTypeId.match("bool"))) {
336
+ result += `
337
+ /**
338
+ * @notice Cast a bool to a bytes32.
339
+ * @dev The boolean value is casted to a bytes32 value with 0 or 1 at the least significant bit.
340
+ */
341
+ function _boolToBytes32(bool value) pure returns (bytes32 result) {
342
+ assembly {
343
+ result := value
344
+ }
345
+ }
346
+ `;
347
+ }
348
+ return result;
349
+ }
350
+ function getWrappingHelpers(array) {
351
+ const wrappers = /* @__PURE__ */ new Map();
352
+ const unwrappers = /* @__PURE__ */ new Map();
353
+ for (const { typeWrappingData, typeWrap, typeUnwrap, internalTypeId } of array) {
354
+ if (!typeWrappingData) continue;
355
+ const { kind } = typeWrappingData;
356
+ if (kind === "staticArray") {
357
+ const { elementType, staticLength } = typeWrappingData;
358
+ wrappers.set(typeWrap, renderWrapperStaticArray(typeWrap, elementType, staticLength, internalTypeId));
359
+ unwrappers.set(typeUnwrap, renderUnwrapperStaticArray(typeUnwrap, elementType, staticLength, internalTypeId));
360
+ }
361
+ }
362
+ return [...wrappers.values(), ...unwrappers.values()];
363
+ }
364
+ function renderWrapperStaticArray(functionName, elementType, staticLength, internalTypeId) {
365
+ return `
366
+ /**
367
+ * @notice Cast a dynamic array to a static array.
368
+ * @dev In memory static arrays are just dynamic arrays without the 32 length bytes,
369
+ * so this function moves the pointer to the first element of the dynamic array.
370
+ * If the length of the dynamic array is smaller than the static length,
371
+ * the function returns an uninitialized array to avoid memory corruption.
372
+ * @param _value The dynamic array to cast.
373
+ * @return _result The static array.
374
+ */
375
+ function ${functionName}(
376
+ ${internalTypeId} memory _value
377
+ ) pure returns (
378
+ ${elementType}[${staticLength}] memory _result
379
+ ) {
380
+ if (_value.length < ${staticLength}) {
381
+ // return an uninitialized array if the length is smaller than the fixed length to avoid memory corruption
382
+ return _result;
383
+ } else {
384
+ // in memory static arrays are just dynamic arrays without the 32 length bytes
385
+ // (without the length check this could lead to memory corruption)
386
+ assembly {
387
+ _result := add(_value, 0x20)
388
+ }
389
+ }
390
+ }
391
+ `;
392
+ }
393
+ function renderUnwrapperStaticArray(functionName, elementType, staticLength, internalTypeId) {
394
+ const byteLength = staticLength * 32;
395
+ return `
396
+ /**
397
+ * @notice Copy a static array to a dynamic array.
398
+ * @dev Static arrays don't have a length prefix, so this function copies the memory from the static array to a new dynamic array.
399
+ * @param _value The static array to copy.
400
+ * @return _result The dynamic array.
401
+ */
402
+ function ${functionName}(
403
+ ${elementType}[${staticLength}] memory _value
404
+ ) pure returns (
405
+ ${internalTypeId} memory _result
406
+ ) {
407
+ _result = new ${internalTypeId}(${staticLength});
408
+ uint256 fromPointer;
409
+ uint256 toPointer;
410
+ assembly {
411
+ fromPointer := _value
412
+ toPointer := add(_result, 0x20)
413
+ }
414
+ Memory.copy(fromPointer, toPointer, ${byteLength});
415
+ }
416
+ `;
417
+ }
418
+
419
+ // src/codegen/render-typescript/schemaTypesToRecsTypeStrings.ts
420
+ var import_deprecated = require("@latticexyz/schema-type/deprecated");
421
+ var schemaTypesToRecsTypeStrings = {
422
+ [import_deprecated.SchemaType.UINT8]: "RecsType.Number",
423
+ [import_deprecated.SchemaType.UINT16]: "RecsType.Number",
424
+ [import_deprecated.SchemaType.UINT24]: "RecsType.Number",
425
+ [import_deprecated.SchemaType.UINT32]: "RecsType.Number",
426
+ [import_deprecated.SchemaType.UINT40]: "RecsType.Number",
427
+ [import_deprecated.SchemaType.UINT48]: "RecsType.Number",
428
+ [import_deprecated.SchemaType.UINT56]: "RecsType.BigInt",
429
+ [import_deprecated.SchemaType.UINT64]: "RecsType.BigInt",
430
+ [import_deprecated.SchemaType.UINT72]: "RecsType.BigInt",
431
+ [import_deprecated.SchemaType.UINT80]: "RecsType.BigInt",
432
+ [import_deprecated.SchemaType.UINT88]: "RecsType.BigInt",
433
+ [import_deprecated.SchemaType.UINT96]: "RecsType.BigInt",
434
+ [import_deprecated.SchemaType.UINT104]: "RecsType.BigInt",
435
+ [import_deprecated.SchemaType.UINT112]: "RecsType.BigInt",
436
+ [import_deprecated.SchemaType.UINT120]: "RecsType.BigInt",
437
+ [import_deprecated.SchemaType.UINT128]: "RecsType.BigInt",
438
+ [import_deprecated.SchemaType.UINT136]: "RecsType.BigInt",
439
+ [import_deprecated.SchemaType.UINT144]: "RecsType.BigInt",
440
+ [import_deprecated.SchemaType.UINT152]: "RecsType.BigInt",
441
+ [import_deprecated.SchemaType.UINT160]: "RecsType.BigInt",
442
+ [import_deprecated.SchemaType.UINT168]: "RecsType.BigInt",
443
+ [import_deprecated.SchemaType.UINT176]: "RecsType.BigInt",
444
+ [import_deprecated.SchemaType.UINT184]: "RecsType.BigInt",
445
+ [import_deprecated.SchemaType.UINT192]: "RecsType.BigInt",
446
+ [import_deprecated.SchemaType.UINT200]: "RecsType.BigInt",
447
+ [import_deprecated.SchemaType.UINT208]: "RecsType.BigInt",
448
+ [import_deprecated.SchemaType.UINT216]: "RecsType.BigInt",
449
+ [import_deprecated.SchemaType.UINT224]: "RecsType.BigInt",
450
+ [import_deprecated.SchemaType.UINT232]: "RecsType.BigInt",
451
+ [import_deprecated.SchemaType.UINT240]: "RecsType.BigInt",
452
+ [import_deprecated.SchemaType.UINT248]: "RecsType.BigInt",
453
+ [import_deprecated.SchemaType.UINT256]: "RecsType.BigInt",
454
+ [import_deprecated.SchemaType.INT8]: "RecsType.Number",
455
+ [import_deprecated.SchemaType.INT16]: "RecsType.Number",
456
+ [import_deprecated.SchemaType.INT24]: "RecsType.Number",
457
+ [import_deprecated.SchemaType.INT32]: "RecsType.Number",
458
+ [import_deprecated.SchemaType.INT40]: "RecsType.Number",
459
+ [import_deprecated.SchemaType.INT48]: "RecsType.Number",
460
+ [import_deprecated.SchemaType.INT56]: "RecsType.BigInt",
461
+ [import_deprecated.SchemaType.INT64]: "RecsType.BigInt",
462
+ [import_deprecated.SchemaType.INT72]: "RecsType.BigInt",
463
+ [import_deprecated.SchemaType.INT80]: "RecsType.BigInt",
464
+ [import_deprecated.SchemaType.INT88]: "RecsType.BigInt",
465
+ [import_deprecated.SchemaType.INT96]: "RecsType.BigInt",
466
+ [import_deprecated.SchemaType.INT104]: "RecsType.BigInt",
467
+ [import_deprecated.SchemaType.INT112]: "RecsType.BigInt",
468
+ [import_deprecated.SchemaType.INT120]: "RecsType.BigInt",
469
+ [import_deprecated.SchemaType.INT128]: "RecsType.BigInt",
470
+ [import_deprecated.SchemaType.INT136]: "RecsType.BigInt",
471
+ [import_deprecated.SchemaType.INT144]: "RecsType.BigInt",
472
+ [import_deprecated.SchemaType.INT152]: "RecsType.BigInt",
473
+ [import_deprecated.SchemaType.INT160]: "RecsType.BigInt",
474
+ [import_deprecated.SchemaType.INT168]: "RecsType.BigInt",
475
+ [import_deprecated.SchemaType.INT176]: "RecsType.BigInt",
476
+ [import_deprecated.SchemaType.INT184]: "RecsType.BigInt",
477
+ [import_deprecated.SchemaType.INT192]: "RecsType.BigInt",
478
+ [import_deprecated.SchemaType.INT200]: "RecsType.BigInt",
479
+ [import_deprecated.SchemaType.INT208]: "RecsType.BigInt",
480
+ [import_deprecated.SchemaType.INT216]: "RecsType.BigInt",
481
+ [import_deprecated.SchemaType.INT224]: "RecsType.BigInt",
482
+ [import_deprecated.SchemaType.INT232]: "RecsType.BigInt",
483
+ [import_deprecated.SchemaType.INT240]: "RecsType.BigInt",
484
+ [import_deprecated.SchemaType.INT248]: "RecsType.BigInt",
485
+ [import_deprecated.SchemaType.INT256]: "RecsType.BigInt",
486
+ [import_deprecated.SchemaType.BYTES1]: "RecsType.String",
487
+ [import_deprecated.SchemaType.BYTES2]: "RecsType.String",
488
+ [import_deprecated.SchemaType.BYTES3]: "RecsType.String",
489
+ [import_deprecated.SchemaType.BYTES4]: "RecsType.String",
490
+ [import_deprecated.SchemaType.BYTES5]: "RecsType.String",
491
+ [import_deprecated.SchemaType.BYTES6]: "RecsType.String",
492
+ [import_deprecated.SchemaType.BYTES7]: "RecsType.String",
493
+ [import_deprecated.SchemaType.BYTES8]: "RecsType.String",
494
+ [import_deprecated.SchemaType.BYTES9]: "RecsType.String",
495
+ [import_deprecated.SchemaType.BYTES10]: "RecsType.String",
496
+ [import_deprecated.SchemaType.BYTES11]: "RecsType.String",
497
+ [import_deprecated.SchemaType.BYTES12]: "RecsType.String",
498
+ [import_deprecated.SchemaType.BYTES13]: "RecsType.String",
499
+ [import_deprecated.SchemaType.BYTES14]: "RecsType.String",
500
+ [import_deprecated.SchemaType.BYTES15]: "RecsType.String",
501
+ [import_deprecated.SchemaType.BYTES16]: "RecsType.String",
502
+ [import_deprecated.SchemaType.BYTES17]: "RecsType.String",
503
+ [import_deprecated.SchemaType.BYTES18]: "RecsType.String",
504
+ [import_deprecated.SchemaType.BYTES19]: "RecsType.String",
505
+ [import_deprecated.SchemaType.BYTES20]: "RecsType.String",
506
+ [import_deprecated.SchemaType.BYTES21]: "RecsType.String",
507
+ [import_deprecated.SchemaType.BYTES22]: "RecsType.String",
508
+ [import_deprecated.SchemaType.BYTES23]: "RecsType.String",
509
+ [import_deprecated.SchemaType.BYTES24]: "RecsType.String",
510
+ [import_deprecated.SchemaType.BYTES25]: "RecsType.String",
511
+ [import_deprecated.SchemaType.BYTES26]: "RecsType.String",
512
+ [import_deprecated.SchemaType.BYTES27]: "RecsType.String",
513
+ [import_deprecated.SchemaType.BYTES28]: "RecsType.String",
514
+ [import_deprecated.SchemaType.BYTES29]: "RecsType.String",
515
+ [import_deprecated.SchemaType.BYTES30]: "RecsType.String",
516
+ [import_deprecated.SchemaType.BYTES31]: "RecsType.String",
517
+ [import_deprecated.SchemaType.BYTES32]: "RecsType.String",
518
+ [import_deprecated.SchemaType.BOOL]: "RecsType.Boolean",
519
+ [import_deprecated.SchemaType.ADDRESS]: "RecsType.String",
520
+ [import_deprecated.SchemaType.UINT8_ARRAY]: "RecsType.NumberArray",
521
+ [import_deprecated.SchemaType.UINT16_ARRAY]: "RecsType.NumberArray",
522
+ [import_deprecated.SchemaType.UINT24_ARRAY]: "RecsType.NumberArray",
523
+ [import_deprecated.SchemaType.UINT32_ARRAY]: "RecsType.NumberArray",
524
+ [import_deprecated.SchemaType.UINT40_ARRAY]: "RecsType.NumberArray",
525
+ [import_deprecated.SchemaType.UINT48_ARRAY]: "RecsType.NumberArray",
526
+ [import_deprecated.SchemaType.UINT56_ARRAY]: "RecsType.BigIntArray",
527
+ [import_deprecated.SchemaType.UINT64_ARRAY]: "RecsType.BigIntArray",
528
+ [import_deprecated.SchemaType.UINT72_ARRAY]: "RecsType.BigIntArray",
529
+ [import_deprecated.SchemaType.UINT80_ARRAY]: "RecsType.BigIntArray",
530
+ [import_deprecated.SchemaType.UINT88_ARRAY]: "RecsType.BigIntArray",
531
+ [import_deprecated.SchemaType.UINT96_ARRAY]: "RecsType.BigIntArray",
532
+ [import_deprecated.SchemaType.UINT104_ARRAY]: "RecsType.BigIntArray",
533
+ [import_deprecated.SchemaType.UINT112_ARRAY]: "RecsType.BigIntArray",
534
+ [import_deprecated.SchemaType.UINT120_ARRAY]: "RecsType.BigIntArray",
535
+ [import_deprecated.SchemaType.UINT128_ARRAY]: "RecsType.BigIntArray",
536
+ [import_deprecated.SchemaType.UINT136_ARRAY]: "RecsType.BigIntArray",
537
+ [import_deprecated.SchemaType.UINT144_ARRAY]: "RecsType.BigIntArray",
538
+ [import_deprecated.SchemaType.UINT152_ARRAY]: "RecsType.BigIntArray",
539
+ [import_deprecated.SchemaType.UINT160_ARRAY]: "RecsType.BigIntArray",
540
+ [import_deprecated.SchemaType.UINT168_ARRAY]: "RecsType.BigIntArray",
541
+ [import_deprecated.SchemaType.UINT176_ARRAY]: "RecsType.BigIntArray",
542
+ [import_deprecated.SchemaType.UINT184_ARRAY]: "RecsType.BigIntArray",
543
+ [import_deprecated.SchemaType.UINT192_ARRAY]: "RecsType.BigIntArray",
544
+ [import_deprecated.SchemaType.UINT200_ARRAY]: "RecsType.BigIntArray",
545
+ [import_deprecated.SchemaType.UINT208_ARRAY]: "RecsType.BigIntArray",
546
+ [import_deprecated.SchemaType.UINT216_ARRAY]: "RecsType.BigIntArray",
547
+ [import_deprecated.SchemaType.UINT224_ARRAY]: "RecsType.BigIntArray",
548
+ [import_deprecated.SchemaType.UINT232_ARRAY]: "RecsType.BigIntArray",
549
+ [import_deprecated.SchemaType.UINT240_ARRAY]: "RecsType.BigIntArray",
550
+ [import_deprecated.SchemaType.UINT248_ARRAY]: "RecsType.BigIntArray",
551
+ [import_deprecated.SchemaType.UINT256_ARRAY]: "RecsType.BigIntArray",
552
+ [import_deprecated.SchemaType.INT8_ARRAY]: "RecsType.NumberArray",
553
+ [import_deprecated.SchemaType.INT16_ARRAY]: "RecsType.NumberArray",
554
+ [import_deprecated.SchemaType.INT24_ARRAY]: "RecsType.NumberArray",
555
+ [import_deprecated.SchemaType.INT32_ARRAY]: "RecsType.NumberArray",
556
+ [import_deprecated.SchemaType.INT40_ARRAY]: "RecsType.NumberArray",
557
+ [import_deprecated.SchemaType.INT48_ARRAY]: "RecsType.NumberArray",
558
+ [import_deprecated.SchemaType.INT56_ARRAY]: "RecsType.BigIntArray",
559
+ [import_deprecated.SchemaType.INT64_ARRAY]: "RecsType.BigIntArray",
560
+ [import_deprecated.SchemaType.INT72_ARRAY]: "RecsType.BigIntArray",
561
+ [import_deprecated.SchemaType.INT80_ARRAY]: "RecsType.BigIntArray",
562
+ [import_deprecated.SchemaType.INT88_ARRAY]: "RecsType.BigIntArray",
563
+ [import_deprecated.SchemaType.INT96_ARRAY]: "RecsType.BigIntArray",
564
+ [import_deprecated.SchemaType.INT104_ARRAY]: "RecsType.BigIntArray",
565
+ [import_deprecated.SchemaType.INT112_ARRAY]: "RecsType.BigIntArray",
566
+ [import_deprecated.SchemaType.INT120_ARRAY]: "RecsType.BigIntArray",
567
+ [import_deprecated.SchemaType.INT128_ARRAY]: "RecsType.BigIntArray",
568
+ [import_deprecated.SchemaType.INT136_ARRAY]: "RecsType.BigIntArray",
569
+ [import_deprecated.SchemaType.INT144_ARRAY]: "RecsType.BigIntArray",
570
+ [import_deprecated.SchemaType.INT152_ARRAY]: "RecsType.BigIntArray",
571
+ [import_deprecated.SchemaType.INT160_ARRAY]: "RecsType.BigIntArray",
572
+ [import_deprecated.SchemaType.INT168_ARRAY]: "RecsType.BigIntArray",
573
+ [import_deprecated.SchemaType.INT176_ARRAY]: "RecsType.BigIntArray",
574
+ [import_deprecated.SchemaType.INT184_ARRAY]: "RecsType.BigIntArray",
575
+ [import_deprecated.SchemaType.INT192_ARRAY]: "RecsType.BigIntArray",
576
+ [import_deprecated.SchemaType.INT200_ARRAY]: "RecsType.BigIntArray",
577
+ [import_deprecated.SchemaType.INT208_ARRAY]: "RecsType.BigIntArray",
578
+ [import_deprecated.SchemaType.INT216_ARRAY]: "RecsType.BigIntArray",
579
+ [import_deprecated.SchemaType.INT224_ARRAY]: "RecsType.BigIntArray",
580
+ [import_deprecated.SchemaType.INT232_ARRAY]: "RecsType.BigIntArray",
581
+ [import_deprecated.SchemaType.INT240_ARRAY]: "RecsType.BigIntArray",
582
+ [import_deprecated.SchemaType.INT248_ARRAY]: "RecsType.BigIntArray",
583
+ [import_deprecated.SchemaType.INT256_ARRAY]: "RecsType.BigIntArray",
584
+ [import_deprecated.SchemaType.BYTES1_ARRAY]: "RecsType.BigIntArray",
585
+ [import_deprecated.SchemaType.BYTES2_ARRAY]: "RecsType.BigIntArray",
586
+ [import_deprecated.SchemaType.BYTES3_ARRAY]: "RecsType.BigIntArray",
587
+ [import_deprecated.SchemaType.BYTES4_ARRAY]: "RecsType.BigIntArray",
588
+ [import_deprecated.SchemaType.BYTES5_ARRAY]: "RecsType.BigIntArray",
589
+ [import_deprecated.SchemaType.BYTES6_ARRAY]: "RecsType.BigIntArray",
590
+ [import_deprecated.SchemaType.BYTES7_ARRAY]: "RecsType.BigIntArray",
591
+ [import_deprecated.SchemaType.BYTES8_ARRAY]: "RecsType.BigIntArray",
592
+ [import_deprecated.SchemaType.BYTES9_ARRAY]: "RecsType.BigIntArray",
593
+ [import_deprecated.SchemaType.BYTES10_ARRAY]: "RecsType.BigIntArray",
594
+ [import_deprecated.SchemaType.BYTES11_ARRAY]: "RecsType.BigIntArray",
595
+ [import_deprecated.SchemaType.BYTES12_ARRAY]: "RecsType.BigIntArray",
596
+ [import_deprecated.SchemaType.BYTES13_ARRAY]: "RecsType.BigIntArray",
597
+ [import_deprecated.SchemaType.BYTES14_ARRAY]: "RecsType.BigIntArray",
598
+ [import_deprecated.SchemaType.BYTES15_ARRAY]: "RecsType.BigIntArray",
599
+ [import_deprecated.SchemaType.BYTES16_ARRAY]: "RecsType.BigIntArray",
600
+ [import_deprecated.SchemaType.BYTES17_ARRAY]: "RecsType.BigIntArray",
601
+ [import_deprecated.SchemaType.BYTES18_ARRAY]: "RecsType.BigIntArray",
602
+ [import_deprecated.SchemaType.BYTES19_ARRAY]: "RecsType.BigIntArray",
603
+ [import_deprecated.SchemaType.BYTES20_ARRAY]: "RecsType.BigIntArray",
604
+ [import_deprecated.SchemaType.BYTES21_ARRAY]: "RecsType.BigIntArray",
605
+ [import_deprecated.SchemaType.BYTES22_ARRAY]: "RecsType.BigIntArray",
606
+ [import_deprecated.SchemaType.BYTES23_ARRAY]: "RecsType.BigIntArray",
607
+ [import_deprecated.SchemaType.BYTES24_ARRAY]: "RecsType.BigIntArray",
608
+ [import_deprecated.SchemaType.BYTES25_ARRAY]: "RecsType.BigIntArray",
609
+ [import_deprecated.SchemaType.BYTES26_ARRAY]: "RecsType.BigIntArray",
610
+ [import_deprecated.SchemaType.BYTES27_ARRAY]: "RecsType.BigIntArray",
611
+ [import_deprecated.SchemaType.BYTES28_ARRAY]: "RecsType.BigIntArray",
612
+ [import_deprecated.SchemaType.BYTES29_ARRAY]: "RecsType.BigIntArray",
613
+ [import_deprecated.SchemaType.BYTES30_ARRAY]: "RecsType.BigIntArray",
614
+ [import_deprecated.SchemaType.BYTES31_ARRAY]: "RecsType.BigIntArray",
615
+ [import_deprecated.SchemaType.BYTES32_ARRAY]: "RecsType.BigIntArray",
616
+ [import_deprecated.SchemaType.BOOL_ARRAY]: "RecsType.T",
617
+ // no boolean array
618
+ [import_deprecated.SchemaType.ADDRESS_ARRAY]: "RecsType.StringArray",
619
+ [import_deprecated.SchemaType.BYTES]: "RecsType.String",
620
+ [import_deprecated.SchemaType.STRING]: "RecsType.String"
621
+ };
622
+
623
+ // src/codegen/utils/contractToInterface.ts
624
+ var import_parser = require("@solidity-parser/parser");
625
+
626
+ // src/errors/MUDError.ts
627
+ var MUDError = class extends Error {
628
+ constructor() {
629
+ super(...arguments);
630
+ this.name = "MUDError";
631
+ }
632
+ };
633
+
634
+ // src/codegen/utils/contractToInterface.ts
635
+ function contractToInterface(source, contractName) {
636
+ const ast = (0, import_parser.parse)(source);
637
+ const contractNode = findContractNode(ast, contractName);
638
+ let symbolImports = [];
639
+ const functions = [];
640
+ const errors = [];
641
+ if (!contractNode) {
642
+ throw new MUDError(`Contract not found: ${contractName}`);
643
+ }
644
+ (0, import_parser.visit)(contractNode, {
645
+ FunctionDefinition({
646
+ name,
647
+ visibility,
648
+ parameters,
649
+ stateMutability,
650
+ returnParameters,
651
+ isConstructor,
652
+ isFallback,
653
+ isReceiveEther
654
+ }) {
655
+ try {
656
+ if (isConstructor || isFallback || isReceiveEther) return;
657
+ if (visibility === "default") throw new MUDError(`Visibility is not specified`);
658
+ if (visibility === "external" || visibility === "public") {
659
+ functions.push({
660
+ name: name === null ? "" : name,
661
+ parameters: parameters.map(parseParameter),
662
+ stateMutability: stateMutability || "",
663
+ returnParameters: returnParameters === null ? [] : returnParameters.map(parseParameter)
664
+ });
665
+ for (const { typeName } of parameters.concat(returnParameters ?? [])) {
666
+ const symbols = typeNameToSymbols(typeName);
667
+ symbolImports = symbolImports.concat(symbolsToImports(ast, symbols));
668
+ }
669
+ }
670
+ } catch (error3) {
671
+ if (error3 instanceof MUDError) {
672
+ error3.message = `Function "${name}" in contract "${contractName}": ${error3.message}`;
673
+ }
674
+ throw error3;
675
+ }
676
+ },
677
+ CustomErrorDefinition({ name, parameters }) {
678
+ errors.push({
679
+ name,
680
+ parameters: parameters.map(parseParameter)
681
+ });
682
+ for (const parameter of parameters) {
683
+ const symbols = typeNameToSymbols(parameter.typeName);
684
+ symbolImports = symbolImports.concat(symbolsToImports(ast, symbols));
685
+ }
686
+ }
687
+ });
688
+ return {
689
+ functions,
690
+ errors,
691
+ symbolImports
692
+ };
693
+ }
694
+ function findContractNode(ast, contractName) {
695
+ let contract = void 0;
696
+ (0, import_parser.visit)(ast, {
697
+ ContractDefinition(node) {
698
+ if (node.name === contractName) {
699
+ contract = node;
700
+ }
701
+ }
702
+ });
703
+ return contract;
704
+ }
705
+ function parseParameter({ name, typeName, storageLocation }) {
706
+ let typedNameWithLocation = "";
707
+ const { name: flattenedTypeName, stateMutability } = flattenTypeName(typeName);
708
+ typedNameWithLocation += flattenedTypeName;
709
+ if (stateMutability !== null) {
710
+ typedNameWithLocation += ` ${stateMutability}`;
711
+ }
712
+ if (storageLocation !== null) {
713
+ typedNameWithLocation += ` ${storageLocation}`;
714
+ }
715
+ if (name !== null) {
716
+ typedNameWithLocation += ` ${name}`;
717
+ }
718
+ return typedNameWithLocation;
719
+ }
720
+ function flattenTypeName(typeName) {
721
+ if (typeName === null) {
722
+ return {
723
+ name: "",
724
+ stateMutability: null
725
+ };
726
+ }
727
+ if (typeName.type === "ElementaryTypeName") {
728
+ return {
729
+ name: typeName.name,
730
+ stateMutability: typeName.stateMutability
731
+ };
732
+ } else if (typeName.type === "UserDefinedTypeName") {
733
+ return {
734
+ name: typeName.namePath,
735
+ stateMutability: null
736
+ };
737
+ } else if (typeName.type === "ArrayTypeName") {
738
+ let length = "";
739
+ if (typeName.length?.type === "NumberLiteral") {
740
+ length = typeName.length.number;
741
+ } else if (typeName.length?.type === "Identifier") {
742
+ length = typeName.length.name;
743
+ }
744
+ const { name, stateMutability } = flattenTypeName(typeName.baseTypeName);
745
+ return {
746
+ name: `${name}[${length}]`,
747
+ stateMutability
748
+ };
749
+ } else {
750
+ throw new MUDError(`Invalid typeName.type ${typeName.type}`);
751
+ }
752
+ }
753
+ function typeNameToSymbols(typeName) {
754
+ if (typeName?.type === "UserDefinedTypeName") {
755
+ const symbol = typeName.namePath.split(".")[0];
756
+ return [symbol];
757
+ } else if (typeName?.type === "ArrayTypeName") {
758
+ const symbols = typeNameToSymbols(typeName.baseTypeName);
759
+ if (typeName.length?.type === "Identifier") {
760
+ const innerTypeName = typeName.length.name;
761
+ symbols.push(innerTypeName.split(".")[0]);
762
+ }
763
+ return symbols;
764
+ } else {
765
+ return [];
766
+ }
767
+ }
768
+ function symbolsToImports(ast, symbols) {
769
+ const imports = [];
770
+ for (const symbol of symbols) {
771
+ let symbolImport;
772
+ (0, import_parser.visit)(ast, {
773
+ ImportDirective({ path: path3, symbolAliases }) {
774
+ if (symbolAliases) {
775
+ for (const symbolAndAlias of symbolAliases) {
776
+ const symbolAlias = symbolAndAlias[1] || symbolAndAlias[0];
777
+ if (symbol === symbolAlias) {
778
+ symbolImport = {
779
+ // always use the original symbol for interface imports
780
+ symbol: symbolAndAlias[0],
781
+ path: path3
782
+ };
783
+ return;
784
+ }
785
+ }
786
+ }
787
+ }
788
+ });
789
+ if (symbolImport) {
790
+ imports.push(symbolImport);
791
+ } else {
792
+ throw new MUDError(`Symbol "${symbol}" has no explicit import`);
793
+ }
794
+ }
795
+ return imports;
796
+ }
797
+
798
+ // src/codegen/utils/format.ts
799
+ var import_prettier = __toESM(require("prettier"), 1);
800
+ var import_prettier_plugin_solidity = __toESM(require("prettier-plugin-solidity"), 1);
801
+ async function formatSolidity(content, prettierConfigPath) {
802
+ let config;
803
+ if (prettierConfigPath) {
804
+ config = await import_prettier.default.resolveConfig(prettierConfigPath);
805
+ }
806
+ try {
807
+ return import_prettier.default.format(content, {
808
+ plugins: [import_prettier_plugin_solidity.default],
809
+ parser: "solidity-parse",
810
+ printWidth: 120,
811
+ semi: true,
812
+ tabWidth: 2,
813
+ useTabs: false,
814
+ bracketSpacing: true,
815
+ ...config
816
+ });
817
+ } catch (error3) {
818
+ let message;
819
+ if (error3 instanceof Error) {
820
+ message = error3.message;
821
+ } else {
822
+ message = error3;
823
+ }
824
+ console.log(`Error during output formatting: ${message}`);
825
+ return content;
826
+ }
827
+ }
828
+ async function formatTypescript(content) {
829
+ return import_prettier.default.format(content, {
830
+ parser: "typescript"
831
+ });
832
+ }
833
+
834
+ // src/codegen/utils/formatAndWrite.ts
835
+ var import_promises = __toESM(require("fs/promises"), 1);
836
+ var import_node_path2 = __toESM(require("path"), 1);
837
+
838
+ // src/debug.ts
839
+ var import_debug = __toESM(require("debug"), 1);
840
+ var debug = (0, import_debug.default)("mud:common");
841
+ var error = (0, import_debug.default)("mud:common");
842
+ debug.log = console.debug.bind(console);
843
+ error.log = console.error.bind(console);
844
+
845
+ // src/codegen/debug.ts
846
+ var debug2 = debug.extend("codegen");
847
+ var error2 = debug.extend("codegen");
848
+ debug2.log = console.debug.bind(console);
849
+ error2.log = console.error.bind(console);
850
+
851
+ // src/codegen/utils/formatAndWrite.ts
852
+ async function formatAndWriteSolidity(output, fullOutputPath, logPrefix) {
853
+ const formattedOutput = await formatSolidity(output);
854
+ await import_promises.default.mkdir(import_node_path2.default.dirname(fullOutputPath), { recursive: true });
855
+ await import_promises.default.writeFile(fullOutputPath, formattedOutput);
856
+ debug2(`${logPrefix}: ${fullOutputPath}`);
857
+ }
858
+ async function formatAndWriteTypescript(output, fullOutputPath, logPrefix) {
859
+ const formattedOutput = await formatTypescript(output);
860
+ await import_promises.default.mkdir(import_node_path2.default.dirname(fullOutputPath), { recursive: true });
861
+ await import_promises.default.writeFile(fullOutputPath, formattedOutput);
862
+ debug2(`${logPrefix}: ${fullOutputPath}`);
863
+ }
864
+ // Annotate the CommonJS export names for ESM import in node:
865
+ 0 && (module.exports = {
866
+ abiToInterface,
867
+ contractToInterface,
868
+ findContractNode,
869
+ formatAndWriteSolidity,
870
+ formatAndWriteTypescript,
871
+ formatSolidity,
872
+ formatTypescript,
873
+ getLeftPaddingBits,
874
+ isLeftAligned,
875
+ renderArguments,
876
+ renderCommonData,
877
+ renderEnums,
878
+ renderImportPath,
879
+ renderImports,
880
+ renderList,
881
+ renderTableId,
882
+ renderTypeHelpers,
883
+ renderValueTypeToBytes32,
884
+ renderWithFieldSuffix,
885
+ renderWithStore,
886
+ renderedSolidityHeader,
887
+ schemaTypesToRecsTypeStrings
888
+ });
889
+ //# sourceMappingURL=codegen.cjs.map