From efb294e1cc499c6d6521ea043cad21e10025fafa Mon Sep 17 00:00:00 2001 From: ssube Date: Tue, 11 Aug 2020 19:14:42 -0500 Subject: [PATCH] feat: sketch out config, label interfaces --- docs/api/cautious-journey.md | 12 ++++ docs/api/cautious-journey.resolvelabels.md | 22 +++++++ docs/api/index.md | 12 ++++ src/config.ts | 34 ++++++++++ src/index.html | 38 +++++++++++ src/index.ts | 1 + src/labels.ts | 73 ++++++++++++++++++++++ src/resolve.ts | 68 ++++++++++++++++++++ 8 files changed, 260 insertions(+) create mode 100644 docs/api/cautious-journey.md create mode 100644 docs/api/cautious-journey.resolvelabels.md create mode 100644 docs/api/index.md create mode 100644 src/config.ts create mode 100644 src/index.html create mode 100644 src/index.ts create mode 100644 src/labels.ts create mode 100644 src/resolve.ts diff --git a/docs/api/cautious-journey.md b/docs/api/cautious-journey.md new file mode 100644 index 0000000..f2a4888 --- /dev/null +++ b/docs/api/cautious-journey.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) + +## cautious-journey package + +## Functions + +| Function | Description | +| --- | --- | +| [resolveLabels(options)](./cautious-journey.resolvelabels.md) | | + diff --git a/docs/api/cautious-journey.resolvelabels.md b/docs/api/cautious-journey.resolvelabels.md new file mode 100644 index 0000000..6545150 --- /dev/null +++ b/docs/api/cautious-journey.resolvelabels.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [resolveLabels](./cautious-journey.resolvelabels.md) + +## resolveLabels() function + +Signature: + +```typescript +export declare function resolveLabels(options: ResolveInput): ResolveResult; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| options | ResolveInput | | + +Returns: + +ResolveResult + diff --git a/docs/api/index.md b/docs/api/index.md new file mode 100644 index 0000000..6ffaf2f --- /dev/null +++ b/docs/api/index.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) + +## API Reference + +## Packages + +| Package | Description | +| --- | --- | +| [cautious-journey](./cautious-journey.md) | | + diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..a8c8dde --- /dev/null +++ b/src/config.ts @@ -0,0 +1,34 @@ +import { FlagLabel, StateLabel } from './labels'; + +/** + * Config data for the app, loaded from CLI or DOM. + */ +export interface ConfigData { + /** + * Color palette for labels without their own. + */ + colors: Array; + + /** + * Individual flag labels. + */ + flags: Array; + + /** + * Grouped state labels. + */ + states: Array; +} + +/** + * Load the config from files or the hosting webpage. + * + * @todo + */ +export function initConfig(): ConfigData { + return { + colors: [], + flags: [], + states: [], + }; +} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..325e28c --- /dev/null +++ b/src/index.html @@ -0,0 +1,38 @@ + + + + + Mummies Took My Brunch + + + + + +
+ + + + diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..e9c2f01 --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +export { resolveLabels } from './resolve'; diff --git a/src/labels.ts b/src/labels.ts new file mode 100644 index 0000000..ce6611f --- /dev/null +++ b/src/labels.ts @@ -0,0 +1,73 @@ +/** + * A reference to another label. + */ +export interface LabelRef { + name: string; +} + +/** + * A set of labels to add and/or remove. + */ +export interface LabelSet { + adds: Array; + removes: Array; +} + +/** + * Common fields for all labels. + */ +export interface BaseLabel { + /** + * Label name. + */ + name: string; + + /** + * Display color. + */ + color?: string; + + /** + * + */ + desc?: string; + priority: number; + requires: Array; +} + +/** + * Individual labels: the equivalent of a checkbox. + */ +export interface FlagLabel extends BaseLabel, LabelSet { + /* empty */ +} + +/** + * The transition between two state values. + */ +export interface StateChange extends LabelSet { + /** + * Required labels for this state change to occur. + */ + matches: Array; +} + +/** + * One of many values for a particular state. + */ +export interface StateValue extends BaseLabel { + /** + * State changes that could occur to this value. + */ + becomes: Array; +} + +/** + * Grouped labels: the equivalent of a radio group. + */ +export interface StateLabel extends BaseLabel, LabelSet { + /** + * Values for this state. + */ + values: Array; +} diff --git a/src/resolve.ts b/src/resolve.ts new file mode 100644 index 0000000..3bf7307 --- /dev/null +++ b/src/resolve.ts @@ -0,0 +1,68 @@ +import { ConfigData } from './config'; + +/** + * How a label changed. + */ +export enum ChangeEffect { + EXISTING = 'existing', + CREATED = 'created', + REMOVED = 'removed', +} + +/** + * Details of a label change. + */ +export interface ChangeRecord { + cause: string; + effect: ChangeEffect; + label: string; +} + +/** + * Collected inputs for a resolver run. + */ +export interface ResolveInput { + config: ConfigData; + issue: string; + labels: Array; +} + +/** + * Collected results from a resolver run. + */ +export interface ResolveResult { + changes: Array; + errors: Array; + labels: Array; +} + +export function resolveLabels(options: ResolveInput): ResolveResult { + const activeLabels = new Set(options.labels); + + const sortedFlags = options.config.flags.sort((a, b) => a.priority - b.priority); + for (const flag of sortedFlags) { + const { name } = flag; + if (activeLabels.has(name)) { + // TODO: check removes + // TODO: check requires + } + } + + const sortedStates = options.config.states.sort((a, b) => a.priority - b.priority); + for (const state of sortedStates) { + for (const value of state.values) { + const name = `${state.name}/${value.name}`; + if (activeLabels.has(name)) { + // TODO: check removes + // TODO: check requires + // TODO: check becomes + } + } + } + + return { + changes: [], + errors: [], + labels: Array.from(activeLabels), + }; +}