@code-pushup/models 0.5.0 → 0.5.3

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
@@ -182,6 +182,23 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
182
182
  metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
183
183
  );
184
184
  }
185
+ var categoriesSchema = z2.array(categoryConfigSchema, {
186
+ description: "Categorization of individual audits"
187
+ }).min(1).refine(
188
+ (categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
189
+ (categoryCfg) => ({
190
+ message: duplicateSlugCategoriesErrorMsg(categoryCfg)
191
+ })
192
+ );
193
+ function duplicateSlugCategoriesErrorMsg(categories) {
194
+ const duplicateStringSlugs = getDuplicateSlugCategories(categories);
195
+ return `In the categories, the following slugs are duplicated: ${errorItems(
196
+ duplicateStringSlugs
197
+ )}`;
198
+ }
199
+ function getDuplicateSlugCategories(categories) {
200
+ return hasDuplicateStrings(categories.map(({ slug }) => slug));
201
+ }
185
202
 
186
203
  // packages/models/src/lib/core-config.ts
187
204
  import { z as z11 } from "zod";
@@ -190,12 +207,11 @@ import { z as z11 } from "zod";
190
207
  import { z as z3 } from "zod";
191
208
  var formatSchema = z3.enum(["json", "md"]);
192
209
  var persistConfigSchema = z3.object({
193
- outputDir: filePathSchema("Artifacts folder"),
194
- filename: fileNameSchema("Artifacts file name (without extension)").default(
195
- "report"
196
- ),
197
- format: z3.array(formatSchema).default(["json"]).optional()
198
- // @TODO remove default or optional value and otherwise it will not set defaults.
210
+ outputDir: filePathSchema("Artifacts folder").optional(),
211
+ filename: fileNameSchema(
212
+ "Artifacts file name (without extension)"
213
+ ).optional(),
214
+ format: z3.array(formatSchema).optional()
199
215
  });
200
216
 
201
217
  // packages/models/src/lib/plugin-config.ts
@@ -429,17 +445,10 @@ var unrefinedCoreConfigSchema = z11.object({
429
445
  description: "List of plugins to be used (official, community-provided, or custom)"
430
446
  }),
431
447
  /** portal configuration for persisting results */
432
- persist: persistConfigSchema,
448
+ persist: persistConfigSchema.optional(),
433
449
  /** portal configuration for uploading results */
434
450
  upload: uploadConfigSchema.optional(),
435
- categories: z11.array(categoryConfigSchema, {
436
- description: "Categorization of individual audits"
437
- }).min(1).refine(
438
- (categories) => !getDuplicateSlugCategories(categories),
439
- (categories) => ({
440
- message: duplicateSlugCategoriesErrorMsg(categories)
441
- })
442
- )
451
+ categories: categoriesSchema
443
452
  });
444
453
  var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
445
454
  function refineCoreConfig(schema) {
@@ -490,15 +499,11 @@ function getMissingRefsForCategories(coreCfg) {
490
499
  }
491
500
  return missingRefs.length ? missingRefs : false;
492
501
  }
493
- function duplicateSlugCategoriesErrorMsg(categories) {
494
- const duplicateStringSlugs = getDuplicateSlugCategories(categories);
495
- return `In the categories, the following slugs are duplicated: ${errorItems(
496
- duplicateStringSlugs
497
- )}`;
498
- }
499
- function getDuplicateSlugCategories(categories) {
500
- return hasDuplicateStrings(categories.map(({ slug }) => slug));
501
- }
502
+
503
+ // packages/models/src/lib/implementation/constants.ts
504
+ var PERSIST_OUTPUT_DIR = ".code-pushup";
505
+ var PERSIST_FORMAT = ["json"];
506
+ var PERSIST_FILENAME = "report";
502
507
 
503
508
  // packages/models/src/lib/report.ts
504
509
  import { z as z12 } from "zod";
@@ -534,6 +539,9 @@ export {
534
539
  MAX_DESCRIPTION_LENGTH,
535
540
  MAX_SLUG_LENGTH,
536
541
  MAX_TITLE_LENGTH,
542
+ PERSIST_FILENAME,
543
+ PERSIST_FORMAT,
544
+ PERSIST_OUTPUT_DIR,
537
545
  auditGroupSchema,
538
546
  auditOutputsSchema,
539
547
  auditReportSchema,
@@ -541,6 +549,8 @@ export {
541
549
  categoryConfigSchema,
542
550
  categoryRefSchema,
543
551
  coreConfigSchema,
552
+ fileNameSchema,
553
+ filePathSchema,
544
554
  formatSchema,
545
555
  materialIconSchema,
546
556
  onProgressSchema,
@@ -552,5 +562,6 @@ export {
552
562
  reportSchema,
553
563
  runnerConfigSchema,
554
564
  unrefinedCoreConfigSchema,
555
- uploadConfigSchema
565
+ uploadConfigSchema,
566
+ urlSchema
556
567
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/models",
3
- "version": "0.5.0",
3
+ "version": "0.5.3",
4
4
  "dependencies": {
5
5
  "zod": "^3.22.1",
6
6
  "@code-pushup/portal-client": "^0.1.2"
package/src/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { CategoryConfig, CategoryRef, categoryConfigSchema, categoryRefSchema, } from './lib/category-config';
2
2
  export { CoreConfig, coreConfigSchema, refineCoreConfig, unrefinedCoreConfigSchema, } from './lib/core-config';
3
3
  export { MAX_DESCRIPTION_LENGTH, MAX_SLUG_LENGTH, MAX_TITLE_LENGTH, } from './lib/implementation/limits';
4
- export { materialIconSchema } from './lib/implementation/schemas';
4
+ export { PERSIST_FILENAME, PERSIST_OUTPUT_DIR, PERSIST_FORMAT, } from './lib/implementation/constants';
5
+ export { materialIconSchema, filePathSchema, fileNameSchema, urlSchema, } from './lib/implementation/schemas';
5
6
  export { Format, PersistConfig, formatSchema, persistConfigSchema, } from './lib/persist-config';
6
7
  export { PluginConfig, pluginConfigSchema, PluginMeta, } from './lib/plugin-config';
7
8
  export { Audit, auditSchema, pluginAuditsSchema, } from './lib/plugin-config-audits';
@@ -85,3 +85,94 @@ export declare const categoryConfigSchema: z.ZodObject<{
85
85
  }>;
86
86
  export type CategoryConfig = z.infer<typeof categoryConfigSchema>;
87
87
  export declare function duplicateRefsInCategoryMetricsErrorMsg(metrics: CategoryRef[]): string;
88
+ export declare const categoriesSchema: z.ZodEffects<z.ZodArray<z.ZodObject<{
89
+ description: z.ZodOptional<z.ZodString>;
90
+ title: z.ZodString;
91
+ docsUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodString]>;
92
+ slug: z.ZodString;
93
+ refs: z.ZodEffects<z.ZodEffects<z.ZodArray<z.ZodObject<{
94
+ slug: z.ZodString;
95
+ weight: z.ZodNumber;
96
+ type: z.ZodEnum<["audit", "group"]>;
97
+ plugin: z.ZodString;
98
+ }, "strip", z.ZodTypeAny, {
99
+ type: "audit" | "group";
100
+ slug: string;
101
+ weight: number;
102
+ plugin: string;
103
+ }, {
104
+ type: "audit" | "group";
105
+ slug: string;
106
+ weight: number;
107
+ plugin: string;
108
+ }>, "many">, {
109
+ type: "audit" | "group";
110
+ slug: string;
111
+ weight: number;
112
+ plugin: string;
113
+ }[], {
114
+ type: "audit" | "group";
115
+ slug: string;
116
+ weight: number;
117
+ plugin: string;
118
+ }[]>, {
119
+ type: "audit" | "group";
120
+ slug: string;
121
+ weight: number;
122
+ plugin: string;
123
+ }[], {
124
+ type: "audit" | "group";
125
+ slug: string;
126
+ weight: number;
127
+ plugin: string;
128
+ }[]>;
129
+ isBinary: z.ZodOptional<z.ZodBoolean>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ title: string;
132
+ slug: string;
133
+ refs: {
134
+ type: "audit" | "group";
135
+ slug: string;
136
+ weight: number;
137
+ plugin: string;
138
+ }[];
139
+ description?: string | undefined;
140
+ docsUrl?: string | undefined;
141
+ isBinary?: boolean | undefined;
142
+ }, {
143
+ title: string;
144
+ slug: string;
145
+ refs: {
146
+ type: "audit" | "group";
147
+ slug: string;
148
+ weight: number;
149
+ plugin: string;
150
+ }[];
151
+ description?: string | undefined;
152
+ docsUrl?: string | undefined;
153
+ isBinary?: boolean | undefined;
154
+ }>, "many">, {
155
+ title: string;
156
+ slug: string;
157
+ refs: {
158
+ type: "audit" | "group";
159
+ slug: string;
160
+ weight: number;
161
+ plugin: string;
162
+ }[];
163
+ description?: string | undefined;
164
+ docsUrl?: string | undefined;
165
+ isBinary?: boolean | undefined;
166
+ }[], {
167
+ title: string;
168
+ slug: string;
169
+ refs: {
170
+ type: "audit" | "group";
171
+ slug: string;
172
+ weight: number;
173
+ plugin: string;
174
+ }[];
175
+ description?: string | undefined;
176
+ docsUrl?: string | undefined;
177
+ isBinary?: boolean | undefined;
178
+ }[]>;