Skip to content

Commit

Permalink
Add type definitions for new label system
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed May 19, 2024
1 parent 8c64297 commit 531a6bf
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/types/classifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { array, defaulted, number, object, record, string, type Infer } from 'superstruct';
import { Label } from './label';

export const Classifier = object({
/** User-facing name of the classifier */
name: string(),

/** Short description of the classifier */
description: string(),

/** Ordering - higher values are placed earlier in lists */
sort: defaulted(number(), 0),

// Components not from info.json (added during load)
// ==================================================

/** Slug of classifier, added during parsing */
slug: string(),

/** `README.md` of classifier, added during parsing */
readme: string(),

/** Labels within this classifier */
labels: record(string(), Label),

/** Sort order for labels within this classifier */
labelOrder: array(string()),
});

export type TClassifier = Infer<typeof Classifier>;
80 changes: 80 additions & 0 deletions src/types/label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
defaulted,
number,
object,
string,
record,
array,
optional,
boolean,
type Infer,
} from 'superstruct';

export const Label = object({
/** User-facing name of the label */
name: string(),

/** Short description of the label */
description: string(),

/** Ordering - higher values are placed earlier in lists */
sort: defaulted(number(), 0),

/** Color to use when representing the label */
color: string(),

/**
* Used to associate this label with other categories.
*
* * Each key should be a classifier within the project.
* * Each value should be an array of labels within that classifier, which
* should be associated with this label.
*/
associations: defaulted(
record(string(), array(string())),
{},
),

/** URLs associated with the label */
links: defaulted(
object({
/** URL of the source repository of the label */
repo: optional(string()),

/** URL of the site demonstrating the label */
site: optional(string()),

/** URL of the documentation site for the label */
docs: optional(string()),
}),
{},
),

/** Information about the package distribution of the label */
package: optional(object({
/** Installation command */
command: string(),
/** URL for viewing the label's package listing */
url: string(),
})),

// Components not from info.json (added during load)
// ==================================================

/** Slug of label, added during loading */
slug: string(),

/** `README.md` of label, added during loading */
readme: string(),

/** Whether the label has an asciinema demo in `demo.cast` */
hasDemo: boolean(),

/** Whether the label has an icon in `icon.png` */
hasIcon: boolean(),

/** Whether the label has a banner image in `banner.png` */
hasBanner: boolean(),
});

export type TLabel = Infer<typeof Label>;

0 comments on commit 531a6bf

Please sign in to comment.