@code-pushup/utils 0.19.0 → 0.20.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 +57 -69
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -75,25 +75,15 @@ function executionMetaSchema(options = {
|
|
|
75
75
|
duration: z.number({ description: options.descriptionDuration })
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
function docsUrlSchema(description = "Documentation site") {
|
|
89
|
-
return urlSchema(description).optional().or(z.string().max(0));
|
|
90
|
-
}
|
|
91
|
-
function urlSchema(description) {
|
|
92
|
-
return z.string({ description }).url();
|
|
93
|
-
}
|
|
94
|
-
function titleSchema(description = "Descriptive name") {
|
|
95
|
-
return z.string({ description }).max(MAX_TITLE_LENGTH);
|
|
96
|
-
}
|
|
78
|
+
var slugSchema = z.string({ description: "Unique ID (human-readable, URL-safe)" }).regex(slugRegex, {
|
|
79
|
+
message: "The slug has to follow the pattern [0-9a-z] followed by multiple optional groups of -[0-9a-z]. e.g. my-slug"
|
|
80
|
+
}).max(MAX_SLUG_LENGTH, {
|
|
81
|
+
message: `slug can be max ${MAX_SLUG_LENGTH} characters long`
|
|
82
|
+
});
|
|
83
|
+
var descriptionSchema = z.string({ description: "Description (markdown)" }).max(MAX_DESCRIPTION_LENGTH).optional();
|
|
84
|
+
var urlSchema = z.string().url();
|
|
85
|
+
var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
|
|
86
|
+
var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
|
|
97
87
|
function metaSchema(options) {
|
|
98
88
|
const {
|
|
99
89
|
descriptionDescription,
|
|
@@ -103,24 +93,19 @@ function metaSchema(options) {
|
|
|
103
93
|
} = options ?? {};
|
|
104
94
|
return z.object(
|
|
105
95
|
{
|
|
106
|
-
title: titleSchema(titleDescription),
|
|
107
|
-
description: descriptionSchema(descriptionDescription),
|
|
108
|
-
docsUrl: docsUrlSchema(docsUrlDescription)
|
|
96
|
+
title: titleDescription ? titleSchema.describe(titleDescription) : titleSchema,
|
|
97
|
+
description: descriptionDescription ? descriptionSchema.describe(descriptionDescription) : descriptionSchema,
|
|
98
|
+
docsUrl: docsUrlDescription ? docsUrlSchema.describe(docsUrlDescription) : docsUrlSchema
|
|
109
99
|
},
|
|
110
100
|
{ description }
|
|
111
101
|
);
|
|
112
102
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}).min(1, { message: "file name is invalid" });
|
|
120
|
-
}
|
|
121
|
-
function positiveIntSchema(description) {
|
|
122
|
-
return z.number({ description }).int().nonnegative();
|
|
123
|
-
}
|
|
103
|
+
var filePathSchema = z.string().trim().min(1, { message: "path is invalid" });
|
|
104
|
+
var fileNameSchema = z.string().trim().regex(filenameRegex, {
|
|
105
|
+
message: `The filename has to be valid`
|
|
106
|
+
}).min(1, { message: "file name is invalid" });
|
|
107
|
+
var positiveIntSchema = z.number().int().positive();
|
|
108
|
+
var nonnegativeIntSchema = z.number().int().nonnegative();
|
|
124
109
|
function packageVersionSchema(options) {
|
|
125
110
|
const { versionDescription = "NPM version of the package", required } = options ?? {};
|
|
126
111
|
const packageSchema = z.string({ description: "NPM package name" });
|
|
@@ -133,14 +118,14 @@ function packageVersionSchema(options) {
|
|
|
133
118
|
{ description: "NPM package name and version of a published package" }
|
|
134
119
|
);
|
|
135
120
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
121
|
+
var weightSchema = nonnegativeIntSchema.describe(
|
|
122
|
+
"Coefficient for the given score (use weight 0 if only for display)"
|
|
123
|
+
);
|
|
139
124
|
function weightedRefSchema(description, slugDescription) {
|
|
140
125
|
return z.object(
|
|
141
126
|
{
|
|
142
|
-
slug: slugSchema(slugDescription),
|
|
143
|
-
weight: weightSchema("Weight used to calculate score")
|
|
127
|
+
slug: slugSchema.describe(slugDescription),
|
|
128
|
+
weight: weightSchema.describe("Weight used to calculate score")
|
|
144
129
|
},
|
|
145
130
|
{ description }
|
|
146
131
|
);
|
|
@@ -148,14 +133,14 @@ function weightedRefSchema(description, slugDescription) {
|
|
|
148
133
|
function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessageFn) {
|
|
149
134
|
return z.object(
|
|
150
135
|
{
|
|
151
|
-
slug: slugSchema('Human-readable unique ID, e.g. "performance"'),
|
|
136
|
+
slug: slugSchema.describe('Human-readable unique ID, e.g. "performance"'),
|
|
152
137
|
refs: z.array(refSchema).min(1).refine(
|
|
153
138
|
(refs) => !duplicateCheckFn(refs),
|
|
154
139
|
(refs) => ({
|
|
155
140
|
message: duplicateMessageFn(refs)
|
|
156
141
|
})
|
|
157
|
-
).refine(
|
|
158
|
-
message:
|
|
142
|
+
).refine(hasNonZeroWeightedRef, () => ({
|
|
143
|
+
message: "In a category there has to be at least one ref with weight > 0"
|
|
159
144
|
}))
|
|
160
145
|
},
|
|
161
146
|
{ description }
|
|
@@ -164,13 +149,13 @@ function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessa
|
|
|
164
149
|
var materialIconSchema = z.enum(MATERIAL_ICONS, {
|
|
165
150
|
description: "Icon from VSCode Material Icons extension"
|
|
166
151
|
});
|
|
167
|
-
function
|
|
168
|
-
return
|
|
152
|
+
function hasNonZeroWeightedRef(refs) {
|
|
153
|
+
return refs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
169
154
|
}
|
|
170
155
|
|
|
171
156
|
// packages/models/src/lib/audit.ts
|
|
172
157
|
var auditSchema = z2.object({
|
|
173
|
-
slug: slugSchema("ID (unique within plugin)")
|
|
158
|
+
slug: slugSchema.describe("ID (unique within plugin)")
|
|
174
159
|
}).merge(
|
|
175
160
|
metaSchema({
|
|
176
161
|
titleDescription: "Descriptive name",
|
|
@@ -197,17 +182,20 @@ function getDuplicateSlugsInAudits(audits) {
|
|
|
197
182
|
return hasDuplicateStrings(audits.map(({ slug }) => slug));
|
|
198
183
|
}
|
|
199
184
|
|
|
200
|
-
// packages/models/src/lib/audit-
|
|
185
|
+
// packages/models/src/lib/audit-output.ts
|
|
186
|
+
import { z as z4 } from "zod";
|
|
187
|
+
|
|
188
|
+
// packages/models/src/lib/issue.ts
|
|
201
189
|
import { z as z3 } from "zod";
|
|
202
190
|
var sourceFileLocationSchema = z3.object(
|
|
203
191
|
{
|
|
204
|
-
file: filePathSchema("Relative path to source file in Git repo"),
|
|
192
|
+
file: filePathSchema.describe("Relative path to source file in Git repo"),
|
|
205
193
|
position: z3.object(
|
|
206
194
|
{
|
|
207
|
-
startLine: positiveIntSchema("Start line"),
|
|
208
|
-
startColumn: positiveIntSchema("Start column").optional(),
|
|
209
|
-
endLine: positiveIntSchema("End line").optional(),
|
|
210
|
-
endColumn: positiveIntSchema("End column").optional()
|
|
195
|
+
startLine: positiveIntSchema.describe("Start line"),
|
|
196
|
+
startColumn: positiveIntSchema.describe("Start column").optional(),
|
|
197
|
+
endLine: positiveIntSchema.describe("End line").optional(),
|
|
198
|
+
endColumn: positiveIntSchema.describe("End column").optional()
|
|
211
199
|
},
|
|
212
200
|
{ description: "Location in file" }
|
|
213
201
|
).optional()
|
|
@@ -227,21 +215,21 @@ var issueSchema = z3.object(
|
|
|
227
215
|
);
|
|
228
216
|
|
|
229
217
|
// packages/models/src/lib/audit-output.ts
|
|
230
|
-
|
|
218
|
+
var auditDetailsSchema = z4.object(
|
|
219
|
+
{
|
|
220
|
+
issues: z4.array(issueSchema, { description: "List of findings" })
|
|
221
|
+
},
|
|
222
|
+
{ description: "Detailed information" }
|
|
223
|
+
);
|
|
231
224
|
var auditOutputSchema = z4.object(
|
|
232
225
|
{
|
|
233
|
-
slug: slugSchema("Reference to audit"),
|
|
226
|
+
slug: slugSchema.describe("Reference to audit"),
|
|
234
227
|
displayValue: z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
|
|
235
|
-
value:
|
|
228
|
+
value: nonnegativeIntSchema.describe("Raw numeric value"),
|
|
236
229
|
score: z4.number({
|
|
237
230
|
description: "Value between 0 and 1"
|
|
238
231
|
}).min(0).max(1),
|
|
239
|
-
details:
|
|
240
|
-
{
|
|
241
|
-
issues: z4.array(issueSchema, { description: "List of findings" })
|
|
242
|
-
},
|
|
243
|
-
{ description: "Detailed information" }
|
|
244
|
-
).optional()
|
|
232
|
+
details: auditDetailsSchema.optional()
|
|
245
233
|
},
|
|
246
234
|
{ description: "Audit information" }
|
|
247
235
|
);
|
|
@@ -271,7 +259,7 @@ var categoryRefSchema = weightedRefSchema(
|
|
|
271
259
|
type: z5.enum(["audit", "group"], {
|
|
272
260
|
description: "Discriminant for reference kind, affects where `slug` is looked up"
|
|
273
261
|
}),
|
|
274
|
-
plugin: slugSchema(
|
|
262
|
+
plugin: slugSchema.describe(
|
|
275
263
|
"Plugin slug (plugin should contain referenced audit or group)"
|
|
276
264
|
)
|
|
277
265
|
})
|
|
@@ -331,10 +319,8 @@ import { z as z11 } from "zod";
|
|
|
331
319
|
import { z as z6 } from "zod";
|
|
332
320
|
var formatSchema = z6.enum(["json", "md"]);
|
|
333
321
|
var persistConfigSchema = z6.object({
|
|
334
|
-
outputDir: filePathSchema("Artifacts folder").optional(),
|
|
335
|
-
filename: fileNameSchema(
|
|
336
|
-
"Artifacts file name (without extension)"
|
|
337
|
-
).optional(),
|
|
322
|
+
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
323
|
+
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
338
324
|
format: z6.array(formatSchema).optional()
|
|
339
325
|
});
|
|
340
326
|
|
|
@@ -395,7 +381,7 @@ var runnerConfigSchema = z8.object(
|
|
|
395
381
|
description: "Shell command to execute"
|
|
396
382
|
}),
|
|
397
383
|
args: z8.array(z8.string({ description: "Command arguments" })).optional(),
|
|
398
|
-
outputFile: filePathSchema("Output path"),
|
|
384
|
+
outputFile: filePathSchema.describe("Output path"),
|
|
399
385
|
outputTransform: outputTransformSchema.optional()
|
|
400
386
|
},
|
|
401
387
|
{
|
|
@@ -415,7 +401,7 @@ var pluginMetaSchema = packageVersionSchema().merge(
|
|
|
415
401
|
})
|
|
416
402
|
).merge(
|
|
417
403
|
z9.object({
|
|
418
|
-
slug: slugSchema("Unique plugin slug within core config"),
|
|
404
|
+
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
419
405
|
icon: materialIconSchema
|
|
420
406
|
})
|
|
421
407
|
);
|
|
@@ -448,12 +434,14 @@ function getMissingRefsFromGroups(pluginCfg) {
|
|
|
448
434
|
// packages/models/src/lib/upload-config.ts
|
|
449
435
|
import { z as z10 } from "zod";
|
|
450
436
|
var uploadConfigSchema = z10.object({
|
|
451
|
-
server: urlSchema("URL of deployed portal API"),
|
|
437
|
+
server: urlSchema.describe("URL of deployed portal API"),
|
|
452
438
|
apiKey: z10.string({
|
|
453
439
|
description: "API key with write access to portal (use `process.env` for security)"
|
|
454
440
|
}),
|
|
455
|
-
organization: slugSchema(
|
|
456
|
-
|
|
441
|
+
organization: slugSchema.describe(
|
|
442
|
+
"Organization slug from Code PushUp portal"
|
|
443
|
+
),
|
|
444
|
+
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
457
445
|
timeout: z10.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
458
446
|
});
|
|
459
447
|
|