@clarigen/cli 3.1.0 → 3.2.0

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/index.cjs CHANGED
@@ -31,9 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  CONFIG_FILE: () => CONFIG_FILE,
34
- ClarinetConfigSchema: () => ClarinetConfigSchema,
34
+ ClarinetConfig: () => ClarinetConfig,
35
35
  Config: () => Config,
36
- ConfigFileSchema: () => ConfigFileSchema,
36
+ ConfigFile: () => ConfigFile,
37
37
  DEPLOYMENT_NETWORKS: () => DEPLOYMENT_NETWORKS,
38
38
  FN_TYPES: () => FN_TYPES,
39
39
  OutputType: () => OutputType,
@@ -178,8 +178,8 @@ function clarityNameMatcher(line) {
178
178
  return /[\w|\-|\?|\!]+/.exec(line);
179
179
  }
180
180
  function findItemNameFromLine(line) {
181
- const fnType = FN_TYPES.find((type) => {
182
- return line.startsWith(`(define-${type}`);
181
+ const fnType = FN_TYPES.find((type3) => {
182
+ return line.startsWith(`(define-${type3}`);
183
183
  });
184
184
  if (fnType) {
185
185
  const prefix = `(define-${fnType} (`;
@@ -192,13 +192,13 @@ function findItemNameFromLine(line) {
192
192
  }
193
193
  return match[0];
194
194
  }
195
- for (const type of VAR_TYPES) {
196
- const prefix = `(define-${type} `;
195
+ for (const type3 of VAR_TYPES) {
196
+ const prefix = `(define-${type3} `;
197
197
  if (!line.startsWith(prefix)) continue;
198
198
  const startString = line.slice(prefix.length);
199
199
  const match = clarityNameMatcher(startString);
200
200
  if (!match) {
201
- console.debug(`[claridocs]: Unable to determine ${type} name from line:
201
+ console.debug(`[claridocs]: Unable to determine ${type3} name from line:
202
202
  \`${line}\``);
203
203
  return;
204
204
  }
@@ -220,8 +220,8 @@ function isComment(line) {
220
220
  return line.startsWith(";;");
221
221
  }
222
222
  function getFnName(line) {
223
- const fnType = FN_TYPES.find((type) => {
224
- return line.startsWith(`(define-${type}`);
223
+ const fnType = FN_TYPES.find((type3) => {
224
+ return line.startsWith(`(define-${type3}`);
225
225
  });
226
226
  if (typeof fnType === "undefined") return;
227
227
  const prefix = `(define-${fnType} (`;
@@ -522,29 +522,37 @@ function generateReadme(session, excluded) {
522
522
  contractLines.push(line);
523
523
  });
524
524
  const fileContents = `# Contracts
525
-
526
- ${contractLines.join("\n")}
525
+
526
+ ${contractLines.join("\n")}
527
527
  `;
528
528
  return fileContents;
529
529
  }
530
530
 
531
531
  // src/config.ts
532
- var import_zod2 = require("zod");
532
+ var import_arktype2 = require("arktype");
533
533
 
534
534
  // src/clarinet-config.ts
535
- var import_zod = require("zod");
535
+ var import_arktype = require("arktype");
536
536
  var import_promises2 = require("fs/promises");
537
537
  var import_toml = require("@iarna/toml");
538
- var ClarinetConfigSchema = import_zod.z.object({
539
- project: import_zod.z.object({
540
- requirements: import_zod.z.array(import_zod.z.object({ contract_id: import_zod.z.string() })).optional(),
541
- cache_location: import_zod.z.object({ path: import_zod.z.string() }).optional()
538
+ var ClarinetConfig = (0, import_arktype.type)({
539
+ project: (0, import_arktype.type)({
540
+ requirements: (0, import_arktype.type)({
541
+ contract_id: (0, import_arktype.type)("string").describe("Contract ID")
542
+ }).array().describe("Project requirements").optional(),
543
+ cache_location: (0, import_arktype.type)({
544
+ path: (0, import_arktype.type)("string").describe("Cache location path")
545
+ }).optional()
542
546
  }),
543
- contracts: import_zod.z.record(import_zod.z.string(), import_zod.z.object({ path: import_zod.z.string() })).optional()
547
+ contracts: (0, import_arktype.type)({
548
+ "[string]": (0, import_arktype.type)({
549
+ path: (0, import_arktype.type)("string").describe("Contract path")
550
+ })
551
+ }).optional()
544
552
  });
545
553
  async function getClarinetConfig(path) {
546
554
  const file = await (0, import_promises2.readFile)(path, "utf-8");
547
- const config = ClarinetConfigSchema.parse((0, import_toml.parse)(file));
555
+ const config = ClarinetConfig.assert((0, import_toml.parse)(file));
548
556
  return config;
549
557
  }
550
558
 
@@ -559,23 +567,23 @@ var OutputType = /* @__PURE__ */ ((OutputType2) => {
559
567
  OutputType2["Docs"] = "docs";
560
568
  return OutputType2;
561
569
  })(OutputType || {});
562
- var typesSchema = import_zod2.z.object({
563
- output: import_zod2.z.string().optional(),
564
- outputs: import_zod2.z.array(import_zod2.z.string()).optional(),
565
- include_accounts: import_zod2.z.boolean().optional(),
566
- after: import_zod2.z.string().optional(),
567
- include_boot_contracts: import_zod2.z.boolean().optional(),
568
- watch_folders: import_zod2.z.array(import_zod2.z.string()).optional()
570
+ var typesSchema = (0, import_arktype2.type)({
571
+ "output?": (0, import_arktype2.type)("string").describe("Path to the output file"),
572
+ "outputs?": (0, import_arktype2.type)("string[]").describe("Paths to the output files"),
573
+ "include_accounts?": (0, import_arktype2.type)("boolean").describe("Include accounts in the output"),
574
+ "after?": (0, import_arktype2.type)("string").describe("Script to run after the output is generated"),
575
+ "include_boot_contracts?": (0, import_arktype2.type)("boolean").describe("Include boot contracts in the output"),
576
+ "watch_folders?": (0, import_arktype2.type)("string[]").describe("Folders to watch for changes")
569
577
  }).optional();
570
- var ConfigFileSchema = import_zod2.z.object({
571
- clarinet: import_zod2.z.string(),
578
+ var ConfigFile = (0, import_arktype2.type)({
579
+ clarinet: (0, import_arktype2.type)("string").describe("Path to the Clarinet config file"),
572
580
  ["types" /* ESM */]: typesSchema,
573
581
  ["esm" /* ESM_OLD */]: typesSchema,
574
- ["docs" /* Docs */]: import_zod2.z.object({
575
- output: import_zod2.z.string().optional(),
576
- outputs: import_zod2.z.array(import_zod2.z.string()).optional(),
577
- exclude: import_zod2.z.array(import_zod2.z.string()).optional(),
578
- after: import_zod2.z.string().optional()
582
+ ["docs" /* Docs */]: (0, import_arktype2.type)({
583
+ "output?": (0, import_arktype2.type)("string").describe("Path to docs output folder. Defaults to ./docs"),
584
+ "outputs?": (0, import_arktype2.type)("string[]").describe("Paths to docs output folders"),
585
+ "exclude?": (0, import_arktype2.type)("string[]").describe("Contracts to exclude from docs generation"),
586
+ "after?": (0, import_arktype2.type)("string").describe("Script to run after docs are generated")
579
587
  }).optional()
580
588
  });
581
589
  var defaultConfigFile = {
@@ -599,36 +607,36 @@ var Config = class {
599
607
  const clarinet = await getClarinetConfig((0, import_path3.resolve)(cwd ?? "", config.clarinet));
600
608
  return new this(config, clarinet, cwd);
601
609
  }
602
- getOutputs(type) {
610
+ getOutputs(type3) {
603
611
  var _a, _b;
604
- const singlePath = (_a = this.configFile[type]) == null ? void 0 : _a.output;
605
- const multiPath = ((_b = this.configFile[type]) == null ? void 0 : _b.outputs) || [];
612
+ const singlePath = (_a = this.configFile[type3]) == null ? void 0 : _a.output;
613
+ const multiPath = ((_b = this.configFile[type3]) == null ? void 0 : _b.outputs) || [];
606
614
  if (singlePath !== void 0) return [singlePath];
607
615
  return multiPath;
608
616
  }
609
- outputResolve(type, filePath) {
610
- const outputs = this.getOutputs(type);
611
- if (!this.supports(type)) return null;
617
+ outputResolve(type3, filePath) {
618
+ const outputs = this.getOutputs(type3);
619
+ if (!this.supports(type3)) return null;
612
620
  return outputs.map((path) => {
613
621
  return (0, import_path3.resolve)(this.cwd, path, filePath || "");
614
622
  });
615
623
  }
616
- async writeOutput(type, contents, filePath) {
617
- const paths = this.outputResolve(type, filePath);
624
+ async writeOutput(type3, contents, filePath) {
625
+ const paths = this.outputResolve(type3, filePath);
618
626
  if (paths === null) return null;
619
627
  await Promise.all(
620
628
  paths.map(async (path) => {
621
629
  await writeFile(path, contents);
622
- log.debug(`Generated ${type} file at ${(0, import_path3.relative)(this.cwd, path)}`);
630
+ log.debug(`Generated ${type3} file at ${(0, import_path3.relative)(this.cwd, path)}`);
623
631
  })
624
632
  );
625
633
  return paths;
626
634
  }
627
- supports(type) {
628
- return this.getOutputs(type).length > 0;
635
+ supports(type3) {
636
+ return this.getOutputs(type3).length > 0;
629
637
  }
630
- type(type) {
631
- return this.configFile[type];
638
+ type(type3) {
639
+ return this.configFile[type3];
632
640
  }
633
641
  get esm() {
634
642
  return this.configFile["types" /* ESM */];
@@ -658,16 +666,12 @@ async function getConfig(cwd) {
658
666
  if (await fileExists(path)) {
659
667
  const toml = await (0, import_promises3.readFile)(path, "utf-8");
660
668
  const parsedToml = (0, import_toml2.parse)(toml);
661
- const parseResult = ConfigFileSchema.safeParse(parsedToml);
662
- if (parseResult.success) {
663
- sessionConfig = parseResult.data;
664
- } else {
665
- logger.error("Error parsing Clarigen.toml:");
666
- parseResult.error.errors.forEach((e) => {
667
- logger.error(`${e.path.join(".")}: ${e.message}`);
668
- });
669
- throw new Error("Error parsing Clarigen.toml");
669
+ const parsed = ConfigFile(parsedToml);
670
+ if (parsed instanceof import_arktype2.type.errors) {
671
+ logger.error(`Error parsing Clarigen config: ${parsed.summary}`);
672
+ throw new Error(`Error parsing Clarigen config: ${parsed.summary}`);
670
673
  }
674
+ sessionConfig = parsed;
671
675
  } else {
672
676
  sessionConfig = defaultConfigFile;
673
677
  }
@@ -770,9 +774,9 @@ var jsTypeFromAbiType = (val, isArgument = false) => {
770
774
  return `${innerType} | null`;
771
775
  } else if ((0, import_core4.isClarityAbiTuple)(val)) {
772
776
  const tupleDefs = [];
773
- val.tuple.forEach(({ name, type }) => {
777
+ val.tuple.forEach(({ name, type: type3 }) => {
774
778
  const camelName = (0, import_core5.toCamelCase)(name);
775
- const innerType = jsTypeFromAbiType(type, isArgument);
779
+ const innerType = jsTypeFromAbiType(type3, isArgument);
776
780
  tupleDefs.push(`"${camelName}": ${innerType};`);
777
781
  });
778
782
  return `{
@@ -972,9 +976,9 @@ export const simnet = {
972
976
  function encodeVariables(variables) {
973
977
  return variables.map((v) => {
974
978
  let varLine = `${encodeVariableName(v.name)}: `;
975
- const type = jsTypeFromAbiType(v.type);
979
+ const type3 = jsTypeFromAbiType(v.type);
976
980
  const varJSON = serialize(v);
977
- varLine += `${varJSON} as TypedAbiVariable<${type}>`;
981
+ varLine += `${varJSON} as TypedAbiVariable<${type3}>`;
978
982
  return varLine;
979
983
  });
980
984
  }
@@ -1011,6 +1015,20 @@ function serializeArray(key, lines) {
1011
1015
  }
1012
1016
 
1013
1017
  // src/files/variables.ts
1018
+ function clarityVersionForContract(contract) {
1019
+ switch (contract.contract_interface.clarity_version) {
1020
+ case "Clarity1":
1021
+ return 1;
1022
+ case "Clarity2":
1023
+ return 2;
1024
+ case "Clarity3":
1025
+ return 3;
1026
+ case "Clarity4":
1027
+ return 4;
1028
+ default:
1029
+ return 3;
1030
+ }
1031
+ }
1014
1032
  function getVariablesV2(contract, simnet, verbose) {
1015
1033
  const [deployer] = contract.contract_id.split(".");
1016
1034
  const fakeId = `${(0, import_core8.getContractName)(contract.contract_id)}-vars`;
@@ -1046,7 +1064,7 @@ ${varFn}`;
1046
1064
  fakeId,
1047
1065
  fullSrc,
1048
1066
  {
1049
- clarityVersion: 3
1067
+ clarityVersion: clarityVersionForContract(contract)
1050
1068
  },
1051
1069
  deployer
1052
1070
  );
@@ -1293,9 +1311,9 @@ async function afterESM(config) {
1293
1311
  // Annotate the CommonJS export names for ESM import in node:
1294
1312
  0 && (module.exports = {
1295
1313
  CONFIG_FILE,
1296
- ClarinetConfigSchema,
1314
+ ClarinetConfig,
1297
1315
  Config,
1298
- ConfigFileSchema,
1316
+ ConfigFile,
1299
1317
  DEPLOYMENT_NETWORKS,
1300
1318
  FN_TYPES,
1301
1319
  OutputType,