Farmbot-Web-App/frontend/resources/interfaces.ts

104 lines
3.3 KiB
TypeScript
Raw Normal View History

2018-12-03 07:18:48 -07:00
import { Dictionary } from "farmbot/dist";
2017-06-29 12:54:02 -06:00
import { SequenceReducerState } from "../sequences/interfaces";
import { DesignerState } from "../farm_designer/interfaces";
import { CowardlyDictionary } from "../util";
import {
TaggedResource,
ResourceName,
TaggedToolSlotPointer,
2020-02-28 09:35:32 -07:00
TaggedTool,
2018-08-01 07:03:35 -06:00
} from "farmbot";
2017-06-29 12:54:02 -06:00
import { RegimenState } from "../regimens/reducer";
import { FarmwareState } from "../farmware/interfaces";
2018-10-15 17:23:58 -06:00
import { HelpState } from "../help/reducer";
2018-11-14 10:05:01 -07:00
import { UsageIndex } from "./in_use";
import { SequenceMeta } from "./sequence_meta";
2019-07-15 13:44:40 -06:00
import { AlertReducerState } from "../messages/interfaces";
2020-01-03 13:13:49 -07:00
import { RootFolderNode, FolderMeta } from "../folders/interfaces";
2017-06-29 12:54:02 -06:00
2018-11-14 10:05:01 -07:00
export type UUID = string;
export type VariableNameSet = Record<string, SequenceMeta | undefined>;
2018-11-25 16:19:19 -07:00
export type UUIDSet = Record<UUID, true>;
2017-06-29 12:54:02 -06:00
export interface ResourceIndex {
2018-11-14 07:35:05 -07:00
all: UUIDSet;
byKind: Record<ResourceName, Record<UUID, UUID>>;
2017-06-29 12:54:02 -06:00
byKindAndId: CowardlyDictionary<UUID>;
references: Dictionary<TaggedResource | undefined>;
/**
2018-11-25 16:19:19 -07:00
* PROBLEM: _efficiently_ tracking variable declarations across all sequences.
2018-11-27 11:24:29 -07:00
*
2018-11-25 16:19:19 -07:00
* USE CASE:
* * You have a sequence `Sequence.0.1`
* * It has 2 variables: `parent` and `parent1`.
2018-11-27 11:24:29 -07:00
*
* SOLUTION:
* * Create an index entry, indexed by UUID, for every variable declared in
* a sequence.
2018-11-06 07:21:55 -07:00
* * Within that entry, map the name of the var to a map of meta attrs.
2018-11-27 11:24:29 -07:00
*
2018-11-06 07:21:55 -07:00
* {
* ...
* "Sequence.0.1": {
* ...
* "parent": { label: "parent" },
* "parent1": { label: "parent1" },
* }
* ...
* }
*/
2018-12-20 20:18:10 -07:00
sequenceMetas: Record<UUID, VariableNameSet | undefined>;
2018-11-14 07:35:05 -07:00
/**
* PROBLEM:
* * We need to _efficiently_ track which resources are in_use.
* DISAMBIGUATION:
2018-11-25 16:19:19 -07:00
* * If resource deletion can cause a referential integrity error, it is said
* to be "in use"
2018-11-14 07:35:05 -07:00
* * Another way to think of the term "in use": "Can't be safely deleted"
* SCENARION:
2018-11-25 16:19:19 -07:00
* * A sequence (`Sequence.0.1`) has 2 "consumers":
2018-11-14 07:35:05 -07:00
* * A FarmEvent that triggers it (UUID: "FarmEvent.0.2")
2018-11-25 16:19:19 -07:00
* * A Sequence ("Sequence.0.3") that calls the sequence ("Sequence.0.1")
* via an `execute` block.
2018-11-14 07:35:05 -07:00
* SOLUTION:
2018-11-25 16:19:19 -07:00
* * Create an index (tracked by UUID), for every resource that is "inUse".
2018-11-20 08:27:46 -07:00
* * If it does not have an entry, it's not in use and can safely be deleted.
2018-11-14 07:35:05 -07:00
* {
2018-11-25 16:19:19 -07:00
* // "Sequence.0.1" has two "reservations": "FarmEvent.0.2", "Sequence.0.3"
* "Sequence.0.1": {
* "FarmEvent.0.2": true,
* "Sequence.0.3": true
* },
* "Sequence.0.5": undefined, // Not in use by anything
2018-11-14 07:35:05 -07:00
* }
*/
2018-11-14 10:05:01 -07:00
inUse: UsageIndex;
2019-12-05 09:12:14 -07:00
sequenceFolders: {
folders: RootFolderNode;
/** Local data about a `Folder` that is stored
* out-of-band rather than in the API. */
localMetaAttributes: Record<number, FolderMeta>;
searchTerm?: string;
filteredFolders?: RootFolderNode | undefined;
2019-12-05 09:12:14 -07:00
}
2017-06-29 12:54:02 -06:00
}
export interface RestResources {
/** Tells you if the sync finished yet. */
loaded: ResourceName[];
index: ResourceIndex;
consumers: {
sequences: SequenceReducerState;
regimens: RegimenState;
farm_designer: DesignerState;
farmware: FarmwareState;
2018-10-15 17:23:58 -06:00
help: HelpState;
2019-07-15 13:44:40 -06:00
alerts: AlertReducerState;
2017-06-29 12:54:02 -06:00
}
}
export interface SlotWithTool {
toolSlot: TaggedToolSlotPointer;
tool: TaggedTool | undefined;
}