Skip to content

Commit

Permalink
feat(models): allow non-integer weights in refs
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Jun 5, 2024
1 parent b79191e commit 016e011
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/models/docs/models-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ _Object containing the following properties:_
| Property | Description | Type |
| :---------------- | :----------------------------------------------------------------- | :---------------------------------------------------------------- |
| **`slug`** (\*) | Slug of an audit or group (depending on `type`) | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) |
| **`weight`** (\*) | Weight used to calculate score | `number` (_int, ≥0_) |
| **`weight`** (\*) | Weight used to calculate score | `number` (_≥0_) |
| **`type`** (\*) | Discriminant for reference kind, affects where `slug` is looked up | `'audit' \| 'group'` |
| **`plugin`** (\*) | Plugin slug (plugin should contain referenced audit or group) | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) |

Expand Down Expand Up @@ -207,7 +207,7 @@ _Object containing the following properties:_
| Property | Description | Type |
| :---------------- | :-------------------------------------------------------------- | :---------------------------------------------------------------- |
| **`slug`** (\*) | Reference slug to a group within this plugin (e.g. 'max-lines') | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) |
| **`weight`** (\*) | Weight used to calculate score | `number` (_int, ≥0_) |
| **`weight`** (\*) | Weight used to calculate score | `number` (_≥0_) |

_(\*) Required._

Expand Down
4 changes: 3 additions & 1 deletion packages/models/src/lib/implementation/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export const positiveIntSchema = z.number().int().positive();

export const nonnegativeIntSchema = z.number().int().nonnegative();

export const nonnegativeNumberSchema = z.number().nonnegative();

export function packageVersionSchema<TRequired extends boolean>(options?: {
versionDescription?: string;
required?: TRequired;
Expand All @@ -140,7 +142,7 @@ export function packageVersionSchema<TRequired extends boolean>(options?: {
}

/** Schema for a weight */
export const weightSchema = nonnegativeIntSchema.describe(
export const weightSchema = nonnegativeNumberSchema.describe(
'Coefficient for the given score (use weight 0 if only for display)',
);

Expand Down

0 comments on commit 016e011

Please sign in to comment.