@code-pushup/models
Advanced tools
Comparing version 0.8.0 to 0.8.1
254
index.js
@@ -1,2 +0,2 @@ | ||
// packages/models/src/lib/category-config.ts | ||
// packages/models/src/lib/audit.ts | ||
import { z as z2 } from "zod"; | ||
@@ -141,3 +141,97 @@ | ||
// packages/models/src/lib/audit.ts | ||
var auditSchema = z2.object({ | ||
slug: slugSchema("ID (unique within plugin)") | ||
}).merge( | ||
metaSchema({ | ||
titleDescription: "Descriptive name", | ||
descriptionDescription: "Description (markdown)", | ||
docsUrlDescription: "Link to documentation (rationale)", | ||
description: "List of scorable metrics for the given plugin" | ||
}) | ||
); | ||
var pluginAuditsSchema = z2.array(auditSchema, { | ||
description: "List of audits maintained in a plugin" | ||
}).refine( | ||
(auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata), | ||
(auditMetadata) => ({ | ||
message: duplicateSlugsInAuditsErrorMsg(auditMetadata) | ||
}) | ||
); | ||
function duplicateSlugsInAuditsErrorMsg(audits) { | ||
const duplicateRefs = getDuplicateSlugsInAudits(audits); | ||
return `In plugin audits the slugs are not unique: ${errorItems( | ||
duplicateRefs | ||
)}`; | ||
} | ||
function getDuplicateSlugsInAudits(audits) { | ||
return hasDuplicateStrings(audits.map(({ slug }) => slug)); | ||
} | ||
// packages/models/src/lib/audit-issue.ts | ||
import { z as z3 } from "zod"; | ||
var sourceFileLocationSchema = z3.object( | ||
{ | ||
file: filePathSchema("Relative path to source file in Git repo"), | ||
position: z3.object( | ||
{ | ||
startLine: positiveIntSchema("Start line"), | ||
startColumn: positiveIntSchema("Start column").optional(), | ||
endLine: positiveIntSchema("End line").optional(), | ||
endColumn: positiveIntSchema("End column").optional() | ||
}, | ||
{ description: "Location in file" } | ||
).optional() | ||
}, | ||
{ description: "Source file location" } | ||
); | ||
var issueSeveritySchema = z3.enum(["info", "warning", "error"], { | ||
description: "Severity level" | ||
}); | ||
var issueSchema = z3.object( | ||
{ | ||
message: z3.string({ description: "Descriptive error message" }).max(512), | ||
severity: issueSeveritySchema, | ||
source: sourceFileLocationSchema.optional() | ||
}, | ||
{ description: "Issue information" } | ||
); | ||
// packages/models/src/lib/audit-output.ts | ||
import { z as z4 } from "zod"; | ||
var auditOutputSchema = z4.object( | ||
{ | ||
slug: slugSchema("Reference to audit"), | ||
displayValue: z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(), | ||
value: positiveIntSchema("Raw numeric value"), | ||
score: z4.number({ | ||
description: "Value between 0 and 1" | ||
}).min(0).max(1), | ||
details: z4.object( | ||
{ | ||
issues: z4.array(issueSchema, { description: "List of findings" }) | ||
}, | ||
{ description: "Detailed information" } | ||
).optional() | ||
}, | ||
{ description: "Audit information" } | ||
); | ||
var auditOutputsSchema = z4.array(auditOutputSchema, { | ||
description: "List of JSON formatted audit output emitted by the runner process of a plugin" | ||
}).refine( | ||
(audits) => !getDuplicateSlugsInAudits2(audits), | ||
(audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) }) | ||
); | ||
function duplicateSlugsInAuditsErrorMsg2(audits) { | ||
const duplicateRefs = getDuplicateSlugsInAudits2(audits); | ||
return `In plugin audits the slugs are not unique: ${errorItems( | ||
duplicateRefs | ||
)}`; | ||
} | ||
function getDuplicateSlugsInAudits2(audits) { | ||
return hasDuplicateStrings(audits.map(({ slug }) => slug)); | ||
} | ||
// packages/models/src/lib/category-config.ts | ||
import { z as z5 } from "zod"; | ||
var categoryRefSchema = weightedRefSchema( | ||
@@ -147,4 +241,4 @@ "Weighted references to audits and/or groups for the category", | ||
).merge( | ||
z2.object({ | ||
type: z2.enum(["audit", "group"], { | ||
z5.object({ | ||
type: z5.enum(["audit", "group"], { | ||
description: "Discriminant for reference kind, affects where `slug` is looked up" | ||
@@ -170,4 +264,4 @@ }), | ||
).merge( | ||
z2.object({ | ||
isBinary: z2.boolean({ | ||
z5.object({ | ||
isBinary: z5.boolean({ | ||
description: 'Is this a binary category (i.e. only a perfect score considered a "pass")?' | ||
@@ -188,3 +282,3 @@ }).optional() | ||
} | ||
var categoriesSchema = z2.array(categoryConfigSchema, { | ||
var categoriesSchema = z5.array(categoryConfigSchema, { | ||
description: "Categorization of individual audits" | ||
@@ -211,5 +305,5 @@ }).min(1).refine( | ||
// packages/models/src/lib/persist-config.ts | ||
import { z as z3 } from "zod"; | ||
var formatSchema = z3.enum(["json", "md"]); | ||
var persistConfigSchema = z3.object({ | ||
import { z as z6 } from "zod"; | ||
var formatSchema = z6.enum(["json", "md"]); | ||
var persistConfigSchema = z6.object({ | ||
outputDir: filePathSchema("Artifacts folder").optional(), | ||
@@ -219,3 +313,3 @@ filename: fileNameSchema( | ||
).optional(), | ||
format: z3.array(formatSchema).optional() | ||
format: z6.array(formatSchema).optional() | ||
}); | ||
@@ -226,39 +320,9 @@ | ||
// packages/models/src/lib/plugin-config-audits.ts | ||
import { z as z4 } from "zod"; | ||
var auditSchema = z4.object({ | ||
slug: slugSchema("ID (unique within plugin)") | ||
}).merge( | ||
metaSchema({ | ||
titleDescription: "Descriptive name", | ||
descriptionDescription: "Description (markdown)", | ||
docsUrlDescription: "Link to documentation (rationale)", | ||
description: "List of scorable metrics for the given plugin" | ||
}) | ||
// packages/models/src/lib/group.ts | ||
import { z as z7 } from "zod"; | ||
var groupRefSchema = weightedRefSchema( | ||
"Weighted reference to a group", | ||
"Reference slug to a group within this plugin (e.g. 'max-lines')" | ||
); | ||
var pluginAuditsSchema = z4.array(auditSchema, { | ||
description: "List of audits maintained in a plugin" | ||
}).refine( | ||
(auditMetadata) => !getDuplicateSlugsInAudits(auditMetadata), | ||
(auditMetadata) => ({ | ||
message: duplicateSlugsInAuditsErrorMsg(auditMetadata) | ||
}) | ||
); | ||
function duplicateSlugsInAuditsErrorMsg(audits) { | ||
const duplicateRefs = getDuplicateSlugsInAudits(audits); | ||
return `In plugin audits the slugs are not unique: ${errorItems( | ||
duplicateRefs | ||
)}`; | ||
} | ||
function getDuplicateSlugsInAudits(audits) { | ||
return hasDuplicateStrings(audits.map(({ slug }) => slug)); | ||
} | ||
// packages/models/src/lib/plugin-config-groups.ts | ||
import { z as z5 } from "zod"; | ||
var auditGroupRefSchema = weightedRefSchema( | ||
"Weighted references to audits", | ||
"Reference slug to an audit within this plugin (e.g. 'max-lines')" | ||
); | ||
var auditGroupMetaSchema = metaSchema({ | ||
var groupMetaSchema = metaSchema({ | ||
titleDescription: "Descriptive name for the group", | ||
@@ -269,9 +333,9 @@ descriptionDescription: "Description of the group (markdown)", | ||
}); | ||
var auditGroupSchema = scorableSchema( | ||
'An audit group aggregates a set of audits into a single score which can be referenced from a category. E.g. the group slug "performance" groups audits and can be referenced in a category', | ||
auditGroupRefSchema, | ||
var groupSchema = scorableSchema( | ||
'A group aggregates a set of audits into a single score which can be referenced from a category. E.g. the group slug "performance" groups audits and can be referenced in a category', | ||
groupRefSchema, | ||
getDuplicateRefsInGroups, | ||
duplicateRefsInGroupsErrorMsg | ||
).merge(auditGroupMetaSchema); | ||
var auditGroupsSchema = z5.array(auditGroupSchema, { | ||
).merge(groupMetaSchema); | ||
var groupsSchema = z7.array(groupSchema, { | ||
description: "List of groups" | ||
@@ -284,12 +348,10 @@ }).optional().refine( | ||
); | ||
function duplicateRefsInGroupsErrorMsg(groupAudits) { | ||
const duplicateRefs = getDuplicateRefsInGroups(groupAudits); | ||
return `In plugin groups the audit refs are not unique: ${errorItems( | ||
function duplicateRefsInGroupsErrorMsg(groups) { | ||
const duplicateRefs = getDuplicateRefsInGroups(groups); | ||
return `In plugin groups the following references are not unique: ${errorItems( | ||
duplicateRefs | ||
)}`; | ||
} | ||
function getDuplicateRefsInGroups(groupAudits) { | ||
return hasDuplicateStrings( | ||
groupAudits.map(({ slug: ref }) => ref).filter(exists) | ||
); | ||
function getDuplicateRefsInGroups(groups) { | ||
return hasDuplicateStrings(groups.map(({ slug: ref }) => ref).filter(exists)); | ||
} | ||
@@ -304,72 +366,4 @@ function duplicateSlugsInGroupsErrorMsg(groups) { | ||
// packages/models/src/lib/plugin-config-runner.ts | ||
// packages/models/src/lib/runner-config.ts | ||
import { z as z8 } from "zod"; | ||
// packages/models/src/lib/plugin-process-output.ts | ||
import { z as z7 } from "zod"; | ||
// packages/models/src/lib/plugin-process-output-audit-issue.ts | ||
import { z as z6 } from "zod"; | ||
var sourceFileLocationSchema = z6.object( | ||
{ | ||
file: filePathSchema("Relative path to source file in Git repo"), | ||
position: z6.object( | ||
{ | ||
startLine: positiveIntSchema("Start line"), | ||
startColumn: positiveIntSchema("Start column").optional(), | ||
endLine: positiveIntSchema("End line").optional(), | ||
endColumn: positiveIntSchema("End column").optional() | ||
}, | ||
{ description: "Location in file" } | ||
).optional() | ||
}, | ||
{ description: "Source file location" } | ||
); | ||
var issueSeveritySchema = z6.enum(["info", "warning", "error"], { | ||
description: "Severity level" | ||
}); | ||
var issueSchema = z6.object( | ||
{ | ||
message: z6.string({ description: "Descriptive error message" }).max(512), | ||
severity: issueSeveritySchema, | ||
source: sourceFileLocationSchema.optional() | ||
}, | ||
{ description: "Issue information" } | ||
); | ||
// packages/models/src/lib/plugin-process-output.ts | ||
var auditOutputSchema = z7.object( | ||
{ | ||
slug: slugSchema("Reference to audit"), | ||
displayValue: z7.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(), | ||
value: positiveIntSchema("Raw numeric value"), | ||
score: z7.number({ | ||
description: "Value between 0 and 1" | ||
}).min(0).max(1), | ||
details: z7.object( | ||
{ | ||
issues: z7.array(issueSchema, { description: "List of findings" }) | ||
}, | ||
{ description: "Detailed information" } | ||
).optional() | ||
}, | ||
{ description: "Audit information" } | ||
); | ||
var auditOutputsSchema = z7.array(auditOutputSchema, { | ||
description: "List of JSON formatted audit output emitted by the runner process of a plugin" | ||
}).refine( | ||
(audits) => !getDuplicateSlugsInAudits2(audits), | ||
(audits) => ({ message: duplicateSlugsInAuditsErrorMsg2(audits) }) | ||
); | ||
function duplicateSlugsInAuditsErrorMsg2(audits) { | ||
const duplicateRefs = getDuplicateSlugsInAudits2(audits); | ||
return `In plugin audits the slugs are not unique: ${errorItems( | ||
duplicateRefs | ||
)}`; | ||
} | ||
function getDuplicateSlugsInAudits2(audits) { | ||
return hasDuplicateStrings(audits.map(({ slug }) => slug)); | ||
} | ||
// packages/models/src/lib/plugin-config-runner.ts | ||
var outputTransformSchema = z8.function().args(z8.unknown()).returns(z8.union([auditOutputsSchema, z8.promise(auditOutputsSchema)])); | ||
@@ -411,3 +405,3 @@ var runnerConfigSchema = z8.object( | ||
audits: pluginAuditsSchema, | ||
groups: auditGroupsSchema | ||
groups: groupsSchema | ||
}); | ||
@@ -530,3 +524,3 @@ var pluginConfigSchema = pluginMetaSchema.merge(pluginDataSchema).refine( | ||
audits: z12.array(auditReportSchema), | ||
groups: z12.array(auditGroupSchema).optional() | ||
groups: z12.array(groupSchema).optional() | ||
}) | ||
@@ -557,3 +551,2 @@ ); | ||
PERSIST_OUTPUT_DIR, | ||
auditGroupSchema, | ||
auditOutputsSchema, | ||
@@ -568,2 +561,3 @@ auditReportSchema, | ||
formatSchema, | ||
groupSchema, | ||
materialIconSchema, | ||
@@ -570,0 +564,0 @@ onProgressSchema, |
{ | ||
"name": "@code-pushup/models", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "zod": "^3.22.1", |
@@ -0,14 +1,14 @@ | ||
export { Audit, auditSchema, pluginAuditsSchema } from './lib/audit'; | ||
export { Issue, IssueSeverity } from './lib/audit-issue'; | ||
export { AuditOutput, AuditOutputs, auditOutputsSchema, } from './lib/audit-output'; | ||
export { CategoryConfig, CategoryRef, categoryConfigSchema, categoryRefSchema, } from './lib/category-config'; | ||
export { CoreConfig, coreConfigSchema, refineCoreConfig, unrefinedCoreConfigSchema, } from './lib/core-config'; | ||
export { Group, GroupRef, groupSchema } from './lib/group'; | ||
export { PERSIST_FILENAME, PERSIST_FORMAT, PERSIST_OUTPUT_DIR, } from './lib/implementation/constants'; | ||
export { MAX_DESCRIPTION_LENGTH, MAX_SLUG_LENGTH, MAX_TITLE_LENGTH, } from './lib/implementation/limits'; | ||
export { PERSIST_FILENAME, PERSIST_OUTPUT_DIR, PERSIST_FORMAT, } from './lib/implementation/constants'; | ||
export { materialIconSchema, filePathSchema, fileNameSchema, urlSchema, } from './lib/implementation/schemas'; | ||
export { fileNameSchema, filePathSchema, materialIconSchema, urlSchema, } from './lib/implementation/schemas'; | ||
export { Format, PersistConfig, formatSchema, persistConfigSchema, } from './lib/persist-config'; | ||
export { PluginConfig, pluginConfigSchema, PluginMeta, } from './lib/plugin-config'; | ||
export { Audit, auditSchema, pluginAuditsSchema, } from './lib/plugin-config-audits'; | ||
export { AuditGroup, AuditGroupRef, auditGroupSchema, } from './lib/plugin-config-groups'; | ||
export { OnProgress, RunnerConfig, RunnerFunction, onProgressSchema, runnerConfigSchema, } from './lib/plugin-config-runner'; | ||
export { AuditOutput, AuditOutputs, auditOutputsSchema, } from './lib/plugin-process-output'; | ||
export { Issue, IssueSeverity } from './lib/plugin-process-output-audit-issue'; | ||
export { PluginConfig, PluginMeta, pluginConfigSchema, } from './lib/plugin-config'; | ||
export { AuditReport, PluginReport, Report, auditReportSchema, pluginReportSchema, reportSchema, } from './lib/report'; | ||
export { OnProgress, RunnerConfig, RunnerFunction, onProgressSchema, runnerConfigSchema, } from './lib/runner-config'; | ||
export { UploadConfig, uploadConfigSchema } from './lib/upload-config'; |
Sorry, the diff of this file is too big to display
1213274
15745