@latticexyz/cli 2.0.0-alpha.49 → 2.0.0-alpha.5

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 (82) hide show
  1. package/dist/chunk-6V563IAZ.js +283 -0
  2. package/dist/{chunk-ATAWDHWC.js → chunk-FPG73MVN.js} +5 -1
  3. package/dist/chunk-KJTPZOUH.js +3864 -0
  4. package/dist/{chunk-O6HOO6WA.js → chunk-L4YLJHLJ.js} +1 -9
  5. package/dist/{chunk-KPBNUPK6.js → chunk-SKNB74MT.js} +155 -159
  6. package/dist/chunk-VQTZJIFF.js +353 -0
  7. package/dist/{chunk-MXDV47JM.js → chunk-WZFXLDPK.js} +75 -24
  8. package/dist/chunk-YL4GJLLL.js +26139 -0
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +0 -22
  11. package/dist/mud.d.ts +1 -1
  12. package/dist/mud.js +319 -3971
  13. package/dist/mud2.d.ts +1 -0
  14. package/dist/mud2.js +25 -0
  15. package/dist/render-solidity/index.d.ts +3 -3
  16. package/dist/render-solidity/index.js +3 -4
  17. package/dist/render-ts/index.d.ts +2 -3
  18. package/dist/render-ts/index.js +3 -4
  19. package/dist/utils/deprecated/index.js +3 -3
  20. package/dist/utils/index.d.ts +9 -19
  21. package/dist/utils/index.js +7 -18
  22. package/package.json +19 -20
  23. package/src/commands/deploy-v2.ts +80 -64
  24. package/src/commands/deprecated/index.ts +22 -0
  25. package/src/commands/deprecated/test.ts +1 -1
  26. package/src/commands/gas-report.ts +54 -55
  27. package/src/commands/index.ts +2 -17
  28. package/src/commands/set-version.ts +39 -10
  29. package/src/commands/tablegen.ts +5 -5
  30. package/src/commands/test-v2.ts +71 -0
  31. package/src/commands/tsgen.ts +1 -1
  32. package/src/commands/worldgen.ts +5 -4
  33. package/src/contracts/BulkUpload.sol +13 -20
  34. package/src/contracts/Deploy.sol +3 -3
  35. package/src/contracts/LibDeploy.sol +1 -1
  36. package/src/contracts/LibDeployStub.sol +1 -1
  37. package/src/index.ts +1 -15
  38. package/src/mud.ts +4 -3
  39. package/src/mud2.ts +29 -0
  40. package/src/render-solidity/common.ts +4 -4
  41. package/src/render-solidity/field.ts +25 -2
  42. package/src/render-solidity/record.ts +14 -10
  43. package/src/render-solidity/renderSystemInterface.ts +4 -4
  44. package/src/render-solidity/renderTableIndex.ts +15 -0
  45. package/src/render-solidity/renderTypesFromConfig.ts +1 -1
  46. package/src/render-solidity/tableOptions.ts +2 -2
  47. package/src/render-solidity/tablegen.ts +13 -1
  48. package/src/render-solidity/types.ts +2 -1
  49. package/src/render-solidity/userType.ts +1 -2
  50. package/src/render-solidity/worldgen.ts +3 -3
  51. package/src/render-ts/recsV1TableOptions.ts +2 -2
  52. package/src/render-ts/renderRecsV1Tables.ts +2 -2
  53. package/src/render-ts/schemaTypesToRecsTypeStrings.ts +136 -136
  54. package/src/render-ts/tsgen.ts +1 -1
  55. package/src/render-ts/types.ts +1 -1
  56. package/src/utils/contractToInterface.ts +5 -3
  57. package/src/utils/deploy-v2.ts +85 -78
  58. package/src/utils/errors.ts +3 -34
  59. package/src/utils/foundry.ts +9 -0
  60. package/dist/chunk-5NC2OON2.js +0 -164
  61. package/dist/chunk-7GA2K5A6.js +0 -283
  62. package/dist/chunk-LPWKZQUI.js +0 -454
  63. package/dist/chunk-Q7D3SKYJ.js +0 -22908
  64. package/dist/chunk-SLIMIO4Z.js +0 -14358
  65. package/dist/config/index.d.ts +0 -408
  66. package/dist/config/index.js +0 -85
  67. package/dist/parseStoreConfig-899f574e.d.ts +0 -369
  68. package/src/config/commonSchemas.ts +0 -34
  69. package/src/config/dynamicResolution.ts +0 -49
  70. package/src/config/index.ts +0 -24
  71. package/src/config/loadConfig.ts +0 -39
  72. package/src/config/loadStoreConfig.ts +0 -18
  73. package/src/config/parseStoreConfig.test-d.ts +0 -40
  74. package/src/config/parseStoreConfig.ts +0 -314
  75. package/src/config/validation.ts +0 -163
  76. package/src/config/world/index.ts +0 -4
  77. package/src/config/world/loadWorldConfig.test-d.ts +0 -11
  78. package/src/config/world/loadWorldConfig.ts +0 -26
  79. package/src/config/world/parseWorldConfig.ts +0 -56
  80. package/src/config/world/resolveWorldConfig.ts +0 -80
  81. package/src/config/world/userTypes.ts +0 -74
  82. package/src/utils/typeUtils.ts +0 -17
@@ -1,12 +1,10 @@
1
1
  import {
2
+ SchemaTypeArrayToElement,
2
3
  formatAndWriteSolidity,
3
4
  getSchemaTypeInfo,
4
5
  importForAbiOrUserType,
5
6
  resolveAbiOrUserType
6
- } from "./chunk-5NC2OON2.js";
7
- import {
8
- SchemaTypeArrayToElement
9
- } from "./chunk-KPBNUPK6.js";
7
+ } from "./chunk-SKNB74MT.js";
10
8
 
11
9
  // src/render-solidity/tableOptions.ts
12
10
  import path from "path";
@@ -58,7 +56,7 @@ function getTableOptions(config) {
58
56
  return {
59
57
  tableIdName: tableName + "TableId",
60
58
  namespace: config.namespace,
61
- fileSelector: tableData.fileSelector
59
+ name: tableData.name
62
60
  };
63
61
  }
64
62
  })();
@@ -101,7 +99,7 @@ function renderCommonData({
101
99
  primaryKeys
102
100
  }) {
103
101
  const _tableId = staticResourceData ? "" : "_tableId";
104
- const _typedTableId = staticResourceData ? "" : "uint256 _tableId";
102
+ const _typedTableId = staticResourceData ? "" : "bytes32 _tableId";
105
103
  const _keyArgs = renderArguments(primaryKeys.map(({ name }) => name));
106
104
  const _typedKeyArgs = renderArguments(primaryKeys.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));
107
105
  const _primaryKeysDefinition = `
@@ -147,10 +145,10 @@ function renderWithStore(storeArgument, callback) {
147
145
  return result;
148
146
  }
149
147
  function renderTableId(staticResourceData) {
150
- const hardcodedTableId = `uint256(bytes32(abi.encodePacked(bytes16("${staticResourceData.namespace}"), bytes16("${staticResourceData.fileSelector}"))))`;
148
+ const hardcodedTableId = `bytes32(abi.encodePacked(bytes16("${staticResourceData.namespace}"), bytes16("${staticResourceData.name}")))`;
151
149
  const tableIdDefinition = `
152
- uint256 constant _tableId = ${hardcodedTableId};
153
- uint256 constant ${staticResourceData.tableIdName} = _tableId;
150
+ bytes32 constant _tableId = ${hardcodedTableId};
151
+ bytes32 constant ${staticResourceData.tableIdName} = _tableId;
154
152
  `;
155
153
  return {
156
154
  hardcodedTableId,
@@ -232,6 +230,28 @@ function renderFieldMethods(options) {
232
230
  }
233
231
  `
234
232
  );
233
+ result += renderWithStore(
234
+ storeArgument,
235
+ (_typedStore, _store, _commentSuffix) => `
236
+ /** Update ${portionData.title} of ${field.name}${_commentSuffix} at \`_index\` */
237
+ function update${field.methodNameSuffix}(${renderArguments([
238
+ _typedStore,
239
+ _typedTableId,
240
+ _typedKeyArgs,
241
+ "uint256 _index",
242
+ `${portionData.typeWithLocation} ${portionData.name}`
243
+ ])}) internal {
244
+ ${_primaryKeysDefinition}
245
+ ${_store}.updateInField(
246
+ _tableId,
247
+ _primaryKeys,
248
+ ${index},
249
+ _index * ${portionData.elementLength},
250
+ ${portionData.encoded}
251
+ );
252
+ }
253
+ `
254
+ );
235
255
  }
236
256
  }
237
257
  return result;
@@ -273,7 +293,8 @@ function fieldPortionData(field) {
273
293
  typeWithLocation: field.arrayElement.typeWithLocation,
274
294
  name: "_element",
275
295
  encoded: renderEncodeField({ ...field.arrayElement, arrayElement: void 0, name, methodNameSuffix }),
276
- title: "an element"
296
+ title: "an element",
297
+ elementLength: field.arrayElement.staticByteLength
277
298
  };
278
299
  } else {
279
300
  const name = "_slice";
@@ -281,7 +302,8 @@ function fieldPortionData(field) {
281
302
  typeWithLocation: `${field.typeId} memory`,
282
303
  name,
283
304
  encoded: renderEncodeField({ ...field, name, methodNameSuffix }),
284
- title: "a slice"
305
+ title: "a slice",
306
+ elementLength: 1
285
307
  };
286
308
  }
287
309
  }
@@ -382,16 +404,20 @@ function renderDecodeFunction({ structName, fields, staticFields, dynamicFields
382
404
  ${fieldNamePrefix}${field.name} = ${renderDecodeValueType(field, staticOffsets[index])};
383
405
  `
384
406
  )}
385
- uint256 _start;
386
- uint256 _end = ${totalStaticLength + 32};
387
- ${renderList(
407
+ // Store trims the blob if dynamic fields are all empty
408
+ if (_blob.length > ${totalStaticLength}) {
409
+ uint256 _start;
410
+ // skip static data length + dynamic lengths word
411
+ uint256 _end = ${totalStaticLength + 32};
412
+ ${renderList(
388
413
  dynamicFields,
389
414
  (field, index) => `
390
- _start = _end;
391
- _end += _encodedLengths.atIndex(${index});
392
- ${fieldNamePrefix}${field.name} = ${renderDecodeDynamicFieldPartial(field)};
393
- `
415
+ _start = _end;
416
+ _end += _encodedLengths.atIndex(${index});
417
+ ${fieldNamePrefix}${field.name} = ${renderDecodeDynamicFieldPartial(field)};
418
+ `
394
419
  )}
420
+ }
395
421
  }
396
422
  `;
397
423
  } else {
@@ -675,18 +701,43 @@ function renderTypesFromConfig(config) {
675
701
 
676
702
  // src/render-solidity/tablegen.ts
677
703
  import path3 from "path";
704
+
705
+ // src/render-solidity/renderTableIndex.ts
706
+ function renderTableIndex(options) {
707
+ return `${renderedSolidityHeader}
708
+
709
+ ${renderList(options, ({ outputPath, tableName, renderOptions: { structName, staticResourceData } }) => {
710
+ const imports = [tableName];
711
+ if (structName)
712
+ imports.push(structName);
713
+ if (staticResourceData)
714
+ imports.push(`${tableName}TableId`);
715
+ return `import { ${imports.join(", ")} } from "./${outputPath}";`;
716
+ })}
717
+ `;
718
+ }
719
+
720
+ // src/render-solidity/tablegen.ts
721
+ import { rmSync } from "fs";
678
722
  async function tablegen(config, outputBaseDirectory) {
679
723
  const allTableOptions = getTableOptions(config);
724
+ const uniqueTableDirectories = new Set(allTableOptions.map(({ outputPath }) => path3.dirname(outputPath)));
725
+ for (const tableDir of uniqueTableDirectories) {
726
+ rmSync(path3.join(outputBaseDirectory, tableDir), { recursive: true, force: true });
727
+ }
680
728
  for (const { outputPath, renderOptions } of allTableOptions) {
681
- const fullOutputPath = path3.join(outputBaseDirectory, outputPath);
682
- const output = renderTable(renderOptions);
683
- formatAndWriteSolidity(output, fullOutputPath, "Generated table");
729
+ const fullOutputPath2 = path3.join(outputBaseDirectory, outputPath);
730
+ const output2 = renderTable(renderOptions);
731
+ formatAndWriteSolidity(output2, fullOutputPath2, "Generated table");
684
732
  }
685
733
  if (Object.keys(config.enums).length > 0) {
686
- const fullOutputPath = path3.join(outputBaseDirectory, `${config.userTypesPath}.sol`);
687
- const output = renderTypesFromConfig(config);
688
- formatAndWriteSolidity(output, fullOutputPath, "Generated types file");
734
+ const fullOutputPath2 = path3.join(outputBaseDirectory, `${config.userTypesPath}.sol`);
735
+ const output2 = renderTypesFromConfig(config);
736
+ formatAndWriteSolidity(output2, fullOutputPath2, "Generated types file");
689
737
  }
738
+ const fullOutputPath = path3.join(outputBaseDirectory, `Tables.sol`);
739
+ const output = renderTableIndex(allTableOptions);
740
+ formatAndWriteSolidity(output, fullOutputPath, "Generated table index");
690
741
  }
691
742
 
692
743
  export {