@jphutchins/code-review 0.1.0-alpha.57 → 0.1.0-alpha.58

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.js CHANGED
@@ -63,7 +63,9 @@ var Confidence = t.refinement(t.number, (n) => n >= 0 && n <= 1, "Confidence");
63
63
  var Likelihood = t.refinement(t.number, (n) => n >= 0 && n <= 1, "Likelihood");
64
64
  var FiniteNumber = t.refinement(t.number, (n) => Number.isFinite(n), "FiniteNumber");
65
65
  var NonNegativePrice = t.refinement(t.number, (n) => n >= 0, "NonNegativePrice");
66
- var SCHEMA_VERSION_RE = /^(0|[1-9]\d*)\.(\d+)\.(\d+)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
66
+ var SEMVER_SUFFIX = "(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?";
67
+ var SCHEMA_VERSION_RE = new RegExp(`^(0|[1-9]\\d*)\\.(\\d+)\\.(\\d+)${SEMVER_SUFFIX}$`);
68
+ var anchoredSchemaVersionPattern = (version) => `^${version.split(".").slice(0, 2).join("\\.")}\\.[0-9]+${SEMVER_SUFFIX}$`;
67
69
  var SchemaVersion = t.refinement(
68
70
  t.string,
69
71
  (s) => SCHEMA_VERSION_RE.test(s),
@@ -5489,11 +5491,20 @@ var deadlineCmd = defineCommand({
5489
5491
  }
5490
5492
  });
5491
5493
  var derivedSchemaVersion = (kind, raw) => kind === "findings" ? declaredVersion(raw) : void 0;
5492
- var printableSchema = (schemaPath) => {
5494
+ var printableSchema = (schemaPath, pinVersion) => {
5493
5495
  const schema = JSON.parse(readFileSync(schemaPath, "utf-8"));
5494
5496
  const enforcementSchema = Object.fromEntries(
5495
5497
  Object.entries(schema).filter(([key2]) => key2 !== "$schema")
5496
5498
  );
5499
+ if (!pinVersion) return JSON.stringify(enforcementSchema, null, 2);
5500
+ const properties = enforcementSchema["properties"];
5501
+ const schemaVersion = typeof properties === "object" && properties !== null ? properties["schema_version"] : void 0;
5502
+ if (typeof schemaVersion === "object" && schemaVersion !== null) {
5503
+ properties["schema_version"] = {
5504
+ ...schemaVersion,
5505
+ pattern: anchoredSchemaVersionPattern(DEFAULT_SCHEMA_VERSION)
5506
+ };
5507
+ }
5497
5508
  return JSON.stringify(enforcementSchema, null, 2);
5498
5509
  };
5499
5510
  var validateCmd = defineCommand({
@@ -5539,7 +5550,7 @@ var validateCmd = defineCommand({
5539
5550
  process.stderr.write(
5540
5551
  `
5541
5552
  The ${kind} document must conform to this schema (the field descriptions are the authoritative spec \u2014 match the property names exactly):
5542
- ${printableSchema(schemaPath)}
5553
+ ${printableSchema(schemaPath, kind === "findings" && schemaPath === schemaPathFor(kind))}
5543
5554
  `
5544
5555
  );
5545
5556
  }
@@ -6008,7 +6019,26 @@ var printSchemaCmd = defineCommand({
6008
6019
  run: async ({ args }) => {
6009
6020
  const schemaKind = requireSchemaKind(args.name);
6010
6021
  const schemaPath = requireSchemaPath(schemaKind, args["schema-version"]);
6011
- process.stdout.write(`${printableSchema(schemaPath)}
6022
+ process.stdout.write(
6023
+ `${printableSchema(schemaPath, schemaKind === "findings" && schemaPath === schemaPathFor(schemaKind))}
6024
+ `
6025
+ );
6026
+ }
6027
+ });
6028
+ var defaultVersionCmd = defineCommand({
6029
+ meta: {
6030
+ name: "default-version",
6031
+ description: "Print the in-force schema version the installed registry resolves by default \u2014 the value a draft should stamp as schema_version"
6032
+ },
6033
+ args: {
6034
+ kind: {
6035
+ type: "string",
6036
+ description: "Schema kind (findings | triage | prices); default: findings"
6037
+ }
6038
+ },
6039
+ run: async ({ args }) => {
6040
+ const kind = requireSchemaKind(args.kind || "findings");
6041
+ process.stdout.write(`${defaultVersion(kind)}
6012
6042
  `);
6013
6043
  }
6014
6044
  });
@@ -6679,6 +6709,7 @@ var main = defineCommand({
6679
6709
  extract: extractCmd,
6680
6710
  "validate-patches": validatePatchesCmd,
6681
6711
  "print-schema": printSchemaCmd,
6712
+ "default-version": defaultVersionCmd,
6682
6713
  "stop-gate": stopGateCmd,
6683
6714
  "budget-hook": budgetHookCmd,
6684
6715
  "print-settings": printSettingsCmd,
@@ -6690,6 +6721,6 @@ if (!process.env["VITEST"]) {
6690
6721
  await runMain(main);
6691
6722
  }
6692
6723
 
6693
- export { main, snapshotIfValid };
6724
+ export { main, printableSchema, snapshotIfValid };
6694
6725
  //# sourceMappingURL=index.js.map
6695
6726
  //# sourceMappingURL=index.js.map