@code-pushup/models 0.39.0 → 0.42.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/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // packages/models/src/lib/audit.ts
2
- import { z as z2 } from "zod";
3
-
4
1
  // packages/models/src/lib/implementation/schemas.ts
5
2
  import { MATERIAL_ICONS } from "vscode-material-icons";
6
3
  import { z } from "zod";
@@ -66,6 +63,7 @@ function missingRefsForCategoriesErrorMsg(categories, plugins) {
66
63
  }
67
64
 
68
65
  // packages/models/src/lib/implementation/schemas.ts
66
+ var primitiveValueSchema = z.union([z.string(), z.number()]);
69
67
  function executionMetaSchema(options = {
70
68
  descriptionDate: "Execution start date and time",
71
69
  descriptionDuration: "Execution duration in ms"
@@ -157,6 +155,7 @@ function hasNonZeroWeightedRef(refs) {
157
155
  }
158
156
 
159
157
  // packages/models/src/lib/audit.ts
158
+ import { z as z2 } from "zod";
160
159
  var auditSchema = z2.object({
161
160
  slug: slugSchema.describe("ID (unique within plugin)")
162
161
  }).merge(
@@ -186,7 +185,7 @@ function getDuplicateSlugsInAudits(audits) {
186
185
  }
187
186
 
188
187
  // packages/models/src/lib/audit-output.ts
189
- import { z as z4 } from "zod";
188
+ import { z as z5 } from "zod";
190
189
 
191
190
  // packages/models/src/lib/issue.ts
192
191
  import { z as z3 } from "zod";
@@ -217,16 +216,62 @@ var issueSchema = z3.object(
217
216
  { description: "Issue information" }
218
217
  );
219
218
 
219
+ // packages/models/src/lib/table.ts
220
+ import { z as z4 } from "zod";
221
+ var tableAlignmentSchema = z4.enum(["left", "center", "right"], {
222
+ description: "Cell alignment"
223
+ });
224
+ var tableColumnPrimitiveSchema = tableAlignmentSchema;
225
+ var tableColumnObjectSchema = z4.object({
226
+ key: z4.string(),
227
+ label: z4.string().optional(),
228
+ align: tableAlignmentSchema.optional()
229
+ });
230
+ var tableRowObjectSchema = z4.record(primitiveValueSchema, {
231
+ description: "Object row"
232
+ });
233
+ var tableRowPrimitiveSchema = z4.array(primitiveValueSchema, {
234
+ description: "Primitive row"
235
+ });
236
+ var tableSharedSchema = z4.object({
237
+ title: z4.string().optional().describe("Display title for table")
238
+ });
239
+ var tablePrimitiveSchema = tableSharedSchema.merge(
240
+ z4.object(
241
+ {
242
+ columns: z4.array(tableAlignmentSchema).optional(),
243
+ rows: z4.array(tableRowPrimitiveSchema)
244
+ },
245
+ { description: "Table with primitive rows and optional alignment columns" }
246
+ )
247
+ );
248
+ var tableObjectSchema = tableSharedSchema.merge(
249
+ z4.object(
250
+ {
251
+ columns: z4.union([
252
+ z4.array(tableAlignmentSchema),
253
+ z4.array(tableColumnObjectSchema)
254
+ ]).optional(),
255
+ rows: z4.array(tableRowObjectSchema)
256
+ },
257
+ {
258
+ description: "Table with object rows and optional alignment or object columns"
259
+ }
260
+ )
261
+ );
262
+ var tableSchema = (description = "Table information") => z4.union([tablePrimitiveSchema, tableObjectSchema], { description });
263
+
220
264
  // packages/models/src/lib/audit-output.ts
221
265
  var auditValueSchema = nonnegativeIntSchema.describe("Raw numeric value");
222
- var auditDisplayValueSchema = z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
223
- var auditDetailsSchema = z4.object(
266
+ var auditDisplayValueSchema = z5.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
267
+ var auditDetailsSchema = z5.object(
224
268
  {
225
- issues: z4.array(issueSchema, { description: "List of findings" })
269
+ issues: z5.array(issueSchema, { description: "List of findings" }).optional(),
270
+ table: tableSchema("Table of related findings").optional()
226
271
  },
227
272
  { description: "Detailed information" }
228
273
  );
229
- var auditOutputSchema = z4.object(
274
+ var auditOutputSchema = z5.object(
230
275
  {
231
276
  slug: slugSchema.describe("Reference to audit"),
232
277
  displayValue: auditDisplayValueSchema,
@@ -236,7 +281,7 @@ var auditOutputSchema = z4.object(
236
281
  },
237
282
  { description: "Audit information" }
238
283
  );
239
- var auditOutputsSchema = z4.array(auditOutputSchema, {
284
+ var auditOutputsSchema = z5.array(auditOutputSchema, {
240
285
  description: "List of JSON formatted audit output emitted by the runner process of a plugin"
241
286
  }).refine(
242
287
  (audits) => !getDuplicateSlugsInAudits2(audits),
@@ -253,13 +298,13 @@ function getDuplicateSlugsInAudits2(audits) {
253
298
  }
254
299
 
255
300
  // packages/models/src/lib/category-config.ts
256
- import { z as z5 } from "zod";
301
+ import { z as z6 } from "zod";
257
302
  var categoryRefSchema = weightedRefSchema(
258
303
  "Weighted references to audits and/or groups for the category",
259
304
  "Slug of an audit or group (depending on `type`)"
260
305
  ).merge(
261
- z5.object({
262
- type: z5.enum(["audit", "group"], {
306
+ z6.object({
307
+ type: z6.enum(["audit", "group"], {
263
308
  description: "Discriminant for reference kind, affects where `slug` is looked up"
264
309
  }),
265
310
  plugin: slugSchema.describe(
@@ -280,8 +325,8 @@ var categoryConfigSchema = scorableSchema(
280
325
  description: "Meta info for category"
281
326
  })
282
327
  ).merge(
283
- z5.object({
284
- isBinary: z5.boolean({
328
+ z6.object({
329
+ isBinary: z6.boolean({
285
330
  description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?'
286
331
  }).optional()
287
332
  })
@@ -297,7 +342,7 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
297
342
  metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
298
343
  );
299
344
  }
300
- var categoriesSchema = z5.array(categoryConfigSchema, {
345
+ var categoriesSchema = z6.array(categoryConfigSchema, {
301
346
  description: "Categorization of individual audits"
302
347
  }).refine(
303
348
  (categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
@@ -316,18 +361,18 @@ function getDuplicateSlugCategories(categories) {
316
361
  }
317
362
 
318
363
  // packages/models/src/lib/commit.ts
319
- import { z as z6 } from "zod";
320
- var commitSchema = z6.object(
364
+ import { z as z7 } from "zod";
365
+ var commitSchema = z7.object(
321
366
  {
322
- hash: z6.string({ description: "Commit SHA (full)" }).regex(
367
+ hash: z7.string({ description: "Commit SHA (full)" }).regex(
323
368
  /^[\da-f]{40}$/,
324
369
  "Commit SHA should be a 40-character hexadecimal string"
325
370
  ),
326
- message: z6.string({ description: "Commit message" }),
327
- date: z6.coerce.date({
371
+ message: z7.string({ description: "Commit message" }),
372
+ date: z7.coerce.date({
328
373
  description: "Date and time when commit was authored"
329
374
  }),
330
- author: z6.string({
375
+ author: z7.string({
331
376
  description: "Commit author name"
332
377
  }).trim()
333
378
  },
@@ -335,22 +380,22 @@ var commitSchema = z6.object(
335
380
  );
336
381
 
337
382
  // packages/models/src/lib/core-config.ts
338
- import { z as z12 } from "zod";
383
+ import { z as z13 } from "zod";
339
384
 
340
385
  // packages/models/src/lib/persist-config.ts
341
- import { z as z7 } from "zod";
342
- var formatSchema = z7.enum(["json", "md"]);
343
- var persistConfigSchema = z7.object({
386
+ import { z as z8 } from "zod";
387
+ var formatSchema = z8.enum(["json", "md"]);
388
+ var persistConfigSchema = z8.object({
344
389
  outputDir: filePathSchema.describe("Artifacts folder").optional(),
345
390
  filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
346
- format: z7.array(formatSchema).optional()
391
+ format: z8.array(formatSchema).optional()
347
392
  });
348
393
 
349
394
  // packages/models/src/lib/plugin-config.ts
350
- import { z as z10 } from "zod";
395
+ import { z as z11 } from "zod";
351
396
 
352
397
  // packages/models/src/lib/group.ts
353
- import { z as z8 } from "zod";
398
+ import { z as z9 } from "zod";
354
399
  var groupRefSchema = weightedRefSchema(
355
400
  "Weighted reference to a group",
356
401
  "Reference slug to a group within this plugin (e.g. 'max-lines')"
@@ -367,7 +412,7 @@ var groupSchema = scorableSchema(
367
412
  getDuplicateRefsInGroups,
368
413
  duplicateRefsInGroupsErrorMsg
369
414
  ).merge(groupMetaSchema);
370
- var groupsSchema = z8.array(groupSchema, {
415
+ var groupsSchema = z9.array(groupSchema, {
371
416
  description: "List of groups"
372
417
  }).optional().refine(
373
418
  (groups) => !getDuplicateSlugsInGroups(groups),
@@ -395,14 +440,14 @@ function getDuplicateSlugsInGroups(groups) {
395
440
  }
396
441
 
397
442
  // packages/models/src/lib/runner-config.ts
398
- import { z as z9 } from "zod";
399
- var outputTransformSchema = z9.function().args(z9.unknown()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
400
- var runnerConfigSchema = z9.object(
443
+ import { z as z10 } from "zod";
444
+ var outputTransformSchema = z10.function().args(z10.unknown()).returns(z10.union([auditOutputsSchema, z10.promise(auditOutputsSchema)]));
445
+ var runnerConfigSchema = z10.object(
401
446
  {
402
- command: z9.string({
447
+ command: z10.string({
403
448
  description: "Shell command to execute"
404
449
  }),
405
- args: z9.array(z9.string({ description: "Command arguments" })).optional(),
450
+ args: z10.array(z10.string({ description: "Command arguments" })).optional(),
406
451
  outputFile: filePathSchema.describe("Output path"),
407
452
  outputTransform: outputTransformSchema.optional()
408
453
  },
@@ -410,8 +455,8 @@ var runnerConfigSchema = z9.object(
410
455
  description: "How to execute runner"
411
456
  }
412
457
  );
413
- var onProgressSchema = z9.function().args(z9.unknown()).returns(z9.void());
414
- var runnerFunctionSchema = z9.function().args(onProgressSchema.optional()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
458
+ var onProgressSchema = z10.function().args(z10.unknown()).returns(z10.void());
459
+ var runnerFunctionSchema = z10.function().args(onProgressSchema.optional()).returns(z10.union([auditOutputsSchema, z10.promise(auditOutputsSchema)]));
415
460
 
416
461
  // packages/models/src/lib/plugin-config.ts
417
462
  var pluginMetaSchema = packageVersionSchema().merge(
@@ -422,13 +467,13 @@ var pluginMetaSchema = packageVersionSchema().merge(
422
467
  description: "Plugin metadata"
423
468
  })
424
469
  ).merge(
425
- z10.object({
470
+ z11.object({
426
471
  slug: slugSchema.describe("Unique plugin slug within core config"),
427
472
  icon: materialIconSchema
428
473
  })
429
474
  );
430
- var pluginDataSchema = z10.object({
431
- runner: z10.union([runnerConfigSchema, runnerFunctionSchema]),
475
+ var pluginDataSchema = z11.object({
476
+ runner: z11.union([runnerConfigSchema, runnerFunctionSchema]),
432
477
  audits: pluginAuditsSchema,
433
478
  groups: groupsSchema
434
479
  });
@@ -454,22 +499,22 @@ function getMissingRefsFromGroups(pluginCfg) {
454
499
  }
455
500
 
456
501
  // packages/models/src/lib/upload-config.ts
457
- import { z as z11 } from "zod";
458
- var uploadConfigSchema = z11.object({
502
+ import { z as z12 } from "zod";
503
+ var uploadConfigSchema = z12.object({
459
504
  server: urlSchema.describe("URL of deployed portal API"),
460
- apiKey: z11.string({
505
+ apiKey: z12.string({
461
506
  description: "API key with write access to portal (use `process.env` for security)"
462
507
  }),
463
508
  organization: slugSchema.describe(
464
509
  "Organization slug from Code PushUp portal"
465
510
  ),
466
511
  project: slugSchema.describe("Project slug from Code PushUp portal"),
467
- timeout: z11.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
512
+ timeout: z12.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
468
513
  });
469
514
 
470
515
  // packages/models/src/lib/core-config.ts
471
- var unrefinedCoreConfigSchema = z12.object({
472
- plugins: z12.array(pluginConfigSchema, {
516
+ var unrefinedCoreConfigSchema = z13.object({
517
+ plugins: z13.array(pluginConfigSchema, {
473
518
  description: "List of plugins to be used (official, community-provided, or custom)"
474
519
  }).min(1),
475
520
  /** portal configuration for persisting results */
@@ -501,7 +546,7 @@ var DEFAULT_PERSIST_FILENAME = "report";
501
546
  var DEFAULT_PERSIST_FORMAT = ["json", "md"];
502
547
 
503
548
  // packages/models/src/lib/report.ts
504
- import { z as z13 } from "zod";
549
+ import { z as z14 } from "zod";
505
550
  var auditReportSchema = auditSchema.merge(auditOutputSchema);
506
551
  var pluginReportSchema = pluginMetaSchema.merge(
507
552
  executionMetaSchema({
@@ -509,9 +554,9 @@ var pluginReportSchema = pluginMetaSchema.merge(
509
554
  descriptionDuration: "Duration of the plugin run in ms"
510
555
  })
511
556
  ).merge(
512
- z13.object({
513
- audits: z13.array(auditReportSchema).min(1),
514
- groups: z13.array(groupSchema).optional()
557
+ z14.object({
558
+ audits: z14.array(auditReportSchema).min(1),
559
+ groups: z14.array(groupSchema).optional()
515
560
  })
516
561
  ).refine(
517
562
  (pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
@@ -545,10 +590,10 @@ var reportSchema = packageVersionSchema({
545
590
  descriptionDuration: "Duration of the collect run in ms"
546
591
  })
547
592
  ).merge(
548
- z13.object(
593
+ z14.object(
549
594
  {
550
- categories: z13.array(categoryConfigSchema),
551
- plugins: z13.array(pluginReportSchema).min(1),
595
+ categories: z14.array(categoryConfigSchema),
596
+ plugins: z14.array(pluginReportSchema).min(1),
552
597
  commit: commitSchema.describe("Git commit for which report was collected").nullable()
553
598
  },
554
599
  { description: "Collect output data" }
@@ -564,40 +609,40 @@ var reportSchema = packageVersionSchema({
564
609
  );
565
610
 
566
611
  // packages/models/src/lib/reports-diff.ts
567
- import { z as z14 } from "zod";
612
+ import { z as z15 } from "zod";
568
613
  function makeComparisonSchema(schema) {
569
614
  const sharedDescription = schema.description || "Result";
570
- return z14.object({
615
+ return z15.object({
571
616
  before: schema.describe(`${sharedDescription} (source commit)`),
572
617
  after: schema.describe(`${sharedDescription} (target commit)`)
573
618
  });
574
619
  }
575
620
  function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
576
- return z14.object(
621
+ return z15.object(
577
622
  {
578
- changed: z14.array(diffSchema),
579
- unchanged: z14.array(resultSchema),
580
- added: z14.array(resultSchema),
581
- removed: z14.array(resultSchema)
623
+ changed: z15.array(diffSchema),
624
+ unchanged: z15.array(resultSchema),
625
+ added: z15.array(resultSchema),
626
+ removed: z15.array(resultSchema)
582
627
  },
583
628
  { description }
584
629
  );
585
630
  }
586
- var scorableMetaSchema = z14.object({
631
+ var scorableMetaSchema = z15.object({
587
632
  slug: slugSchema,
588
633
  title: titleSchema,
589
634
  docsUrl: docsUrlSchema
590
635
  });
591
636
  var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
592
- z14.object({
637
+ z15.object({
593
638
  plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
594
639
  })
595
640
  );
596
641
  var scorableDiffSchema = scorableMetaSchema.merge(
597
- z14.object({
642
+ z15.object({
598
643
  scores: makeComparisonSchema(scoreSchema).merge(
599
- z14.object({
600
- diff: z14.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
644
+ z15.object({
645
+ diff: z15.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
601
646
  })
602
647
  ).describe("Score comparison")
603
648
  })
@@ -608,10 +653,10 @@ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
608
653
  var categoryDiffSchema = scorableDiffSchema;
609
654
  var groupDiffSchema = scorableWithPluginDiffSchema;
610
655
  var auditDiffSchema = scorableWithPluginDiffSchema.merge(
611
- z14.object({
656
+ z15.object({
612
657
  values: makeComparisonSchema(auditValueSchema).merge(
613
- z14.object({
614
- diff: z14.number().int().describe("Value change (`values.after - values.before`)")
658
+ z15.object({
659
+ diff: z15.number().int().describe("Value change (`values.after - values.before`)")
615
660
  })
616
661
  ).describe("Audit `value` comparison"),
617
662
  displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
@@ -620,15 +665,15 @@ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
620
665
  })
621
666
  );
622
667
  var categoryResultSchema = scorableMetaSchema.merge(
623
- z14.object({ score: scoreSchema })
668
+ z15.object({ score: scoreSchema })
624
669
  );
625
670
  var groupResultSchema = scorableWithPluginMetaSchema.merge(
626
- z14.object({ score: scoreSchema })
671
+ z15.object({ score: scoreSchema })
627
672
  );
628
673
  var auditResultSchema = scorableWithPluginMetaSchema.merge(
629
674
  auditOutputSchema.pick({ score: true, value: true, displayValue: true })
630
675
  );
631
- var reportsDiffSchema = z14.object({
676
+ var reportsDiffSchema = z15.object({
632
677
  commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
633
678
  categories: makeArraysComparisonSchema(
634
679
  categoryDiffSchema,
@@ -693,9 +738,16 @@ export {
693
738
  pluginConfigSchema,
694
739
  pluginMetaSchema,
695
740
  pluginReportSchema,
741
+ primitiveValueSchema,
696
742
  reportSchema,
697
743
  reportsDiffSchema,
698
744
  runnerConfigSchema,
699
745
  runnerFunctionSchema,
746
+ tableAlignmentSchema,
747
+ tableColumnObjectSchema,
748
+ tableColumnPrimitiveSchema,
749
+ tableRowObjectSchema,
750
+ tableRowPrimitiveSchema,
751
+ tableSchema,
700
752
  uploadConfigSchema
701
753
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/models",
3
- "version": "0.39.0",
3
+ "version": "0.42.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "zod": "^3.22.1",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/code-pushup/cli.git",
15
+ "url": "git+https://github.com/code-pushup/cli.git",
16
16
  "directory": "packages/models"
17
17
  },
18
18
  "contributors": [
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { PrimitiveValue, primitiveValueSchema, } from './lib/implementation/schemas';
1
2
  export { Audit, auditSchema } from './lib/audit';
2
3
  export { AuditDetails, AuditOutput, AuditOutputs, auditDetailsSchema, auditOutputSchema, auditOutputsSchema, } from './lib/audit-output';
3
4
  export { CategoryConfig, CategoryRef, categoryConfigSchema, categoryRefSchema, } from './lib/category-config';
@@ -9,6 +10,7 @@ export { DEFAULT_PERSIST_FILENAME, DEFAULT_PERSIST_FORMAT, DEFAULT_PERSIST_OUTPU
9
10
  export { MAX_DESCRIPTION_LENGTH, MAX_ISSUE_MESSAGE_LENGTH, MAX_SLUG_LENGTH, MAX_TITLE_LENGTH, } from './lib/implementation/limits';
10
11
  export { MaterialIcon, materialIconSchema } from './lib/implementation/schemas';
11
12
  export { exists } from './lib/implementation/utils';
13
+ export { TableAlignment, tableAlignmentSchema, TableRowPrimitive, tableRowPrimitiveSchema, TableRowObject, tableRowObjectSchema, TableColumnPrimitive, tableColumnPrimitiveSchema, TableColumnObject, tableColumnObjectSchema, Table, tableSchema, } from './lib/table';
12
14
  export { Issue, IssueSeverity, issueSchema, issueSeveritySchema, } from './lib/issue';
13
15
  export { Format, PersistConfig, formatSchema, persistConfigSchema, } from './lib/persist-config';
14
16
  export { PluginConfig, PluginMeta, pluginConfigSchema, pluginMetaSchema, } from './lib/plugin-config';