From d4ce8d7f219a951cd4535f9faff29f55d5ee68a2 Mon Sep 17 00:00:00 2001 From: hsjobeki Date: Sun, 27 Nov 2022 14:40:17 +0100 Subject: [PATCH] strictly seperate nix types from data --- components/basicList/basicList.tsx | 3 +- components/preview/preview.tsx | 3 +- models/nix.ts | 349 +++++++++++++++++++++++++++- pages/index.tsx | 359 +---------------------------- types/nix.ts | 25 +- 5 files changed, 370 insertions(+), 369 deletions(-) diff --git a/components/basicList/basicList.tsx b/components/basicList/basicList.tsx index 13550bc..1a966e9 100644 --- a/components/basicList/basicList.tsx +++ b/components/basicList/basicList.tsx @@ -18,8 +18,7 @@ import FormControl from "@mui/material/FormControl"; import FormLabel from "@mui/material/FormLabel"; import ClearIcon from "@mui/icons-material/Clear"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; -import { nixTypes } from "../../models/nix"; -import { NixType } from "../../types/nix"; +import { NixType, nixTypes } from "../../types/nix"; export type BasicListItem = { item: React.ReactNode; diff --git a/components/preview/preview.tsx b/components/preview/preview.tsx index 3eb34b5..d80cb42 100644 --- a/components/preview/preview.tsx +++ b/components/preview/preview.tsx @@ -8,11 +8,10 @@ import { ListItemText, Typography, } from "@mui/material"; -import { info } from "console"; -import { FuncData } from "../../pages"; import LocalLibraryIcon from "@mui/icons-material/LocalLibrary"; import InputIcon from "@mui/icons-material/Input"; import OutputIcon from "@mui/icons-material/Output"; +import { FuncData } from "../../types/nix"; interface PreviewProps { func: FuncData; diff --git a/models/nix.ts b/models/nix.ts index 594fc7d..05915c2 100644 --- a/models/nix.ts +++ b/models/nix.ts @@ -1,10 +1,341 @@ -import { NixType } from "../types/nix"; +import { NixFunctionSet, NixType } from "../types/nix"; -export const nixTypes: NixType[] = [ - "any", - "attrset", - "list", - "string", - "bool", - "int", - ]; \ No newline at end of file +export const nixFuns: NixFunctionSet = { + mapAttrs: { + "attr-path": "builtins.mapAttrs", + "doc-url": + "https://nixos.org/manual/nix/stable/language/builtins.html#builtins-mapAttrs", + source: "builtin", + from: "attrset", + to: "attrset", + }, + "mapAttrs'": { + "attr-path": "lib.mapAttrs'", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-attrset", + source: "nixpkgs", + from: "attrset", + to: "attrset", + }, + genAttrs: { + "attr-path": "lib.genAttrs", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-attrset", + source: "nixpkgs", + from: "list", + to: "attrset", + }, + forEach: { + "attr-path": "lib.forEach", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + foldr: { + "attr-path": "lib.foldr", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "any", + }, + foldl: { + "attr-path": "lib.foldl", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "any", + }, + "foldl'": { + "attr-path": "lib.foldl'", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "any", + }, + imap0: { + "attr-path": "lib.imap0", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + imap1: { + "attr-path": "lib.imap1", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + concatMap: { + "attr-path": "lib.concatMap", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + flatten: { + "attr-path": "lib.flatten", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + remove: { + "attr-path": "lib.remove", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + findSingle: { + "attr-path": "lib.findSingle", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "any", + }, + findFirst: { + "attr-path": "lib.findFirst", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "any", + }, + any: { + "attr-path": "lib.any", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "bool", + }, + all: { + "attr-path": "lib.all", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "bool", + }, + count: { + "attr-path": "lib.count", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "int", + }, + optional: { + "attr-path": "lib.optional", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "bool", + to: "list", + }, + optionals: { + "attr-path": "lib.optionals", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "bool", + to: "list", + }, + toList: { + "attr-path": "lib.toList", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "any", + to: "list", + }, + toString: { + "attr-path": "builtins.toString'", + "doc-url": + "https://nixos.org/manual/nix/stable/language/builtins.html#builtins-toString", + source: "builtin", + from: "any" as NixType, + to: "string" as NixType, + }, + range: { + "attr-path": "lib.range", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "int", + to: "list", + }, + partition: { + "attr-path": "lib.partition", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + "groupBy'": { + "attr-path": "lib.groupBy'", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + groupBy: { + "attr-path": "lib.groupBy", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + zipListsWith: { + "attr-path": "lib.zipListsWith", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + zipLists: { + "attr-path": "lib.zipLists", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + reverseList: { + "attr-path": "lib.reverseList", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + listDfs: { + "attr-path": "lib.listDfs", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "attrset", + }, + toposort: { + "attr-path": "lib.toposort", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + sort: { + "attr-path": "lib.sort", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + compareLists: { + "attr-path": "lib.compareLists", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "int", + }, + naturalSort: { + "attr-path": "lib.naturalSort", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + take: { + "attr-path": "lib.take", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + sublist: { + "attr-path": "lib.sublist", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + last: { + "attr-path": "lib.last", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "any", + }, + init: { + "attr-path": "lib.init", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + crossLists: { + "attr-path": "lib.crossLists", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + unique: { + "attr-path": "lib.unique", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + intersectLists: { + "attr-path": "lib.intersectLists", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + subtractLists: { + "attr-path": "lib.subtractLists", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "list", + }, + mutuallyExclusive: { + "attr-path": "lib.mutuallyExclusive", + "doc-url": + "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", + source: "nixpkgs", + from: "list", + to: "bool", + }, + }; + \ No newline at end of file diff --git a/pages/index.tsx b/pages/index.tsx index 2246cb3..f6b43fb 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -2,362 +2,11 @@ import { BasicList, BasicListItem } from "../components/basicList"; import { useState, useMemo } from "react"; import { Box } from "@mui/material"; import FunctionItem from "../components/functionItem/functionItem"; -import { NixType } from "../types/basicDataView"; +import { NixType, nixTypes, FuncData } from "../types/nix"; +import { nixFuns } from "../models/nix"; import { Preview } from "../components/preview/preview"; -import { nixTypes } from "../models/nix"; -const libfuns = { - mapAttrs: { - "attr-path": "builtins.mapAttrs", - "doc-url": - "https://nixos.org/manual/nix/stable/language/builtins.html#builtins-mapAttrs", - source: "builtin", - from: "attrset", - to: "attrset", - }, - "mapAttrs'": { - "attr-path": "lib.mapAttrs'", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-attrset", - source: "nixpkgs", - from: "attrset", - to: "attrset", - }, - toString: { - "attr-path": "builtins.toString'", - "doc-url": - "https://nixos.org/manual/nix/stable/language/builtins.html#builtins-toString", - source: "builtin", - from: "any", - to: "string", - }, - genAttrs: { - "attr-path": "lib.genAttrs", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-attrset", - source: "nixpkgs", - from: "list", - to: "attrset", - }, - - forEach: { - "attr-path": "lib.forEach", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - foldr: { - "attr-path": "lib.foldr", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "any", - }, - foldl: { - "attr-path": "lib.foldl", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "any", - }, - "foldl'": { - "attr-path": "lib.foldl'", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "any", - }, - imap0: { - "attr-path": "lib.imap0", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - imap1: { - "attr-path": "lib.imap1", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - concatMap: { - "attr-path": "lib.concatMap", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - flatten: { - "attr-path": "lib.flatten", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - remove: { - "attr-path": "lib.remove", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - findSingle: { - "attr-path": "lib.findSingle", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "any", - }, - findFirst: { - "attr-path": "lib.findFirst", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "any", - }, - any: { - "attr-path": "lib.any", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "true", - }, - all: { - "attr-path": "lib.all", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "true", - }, - count: { - "attr-path": "lib.count", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "int", - }, - optional: { - "attr-path": "lib.optional", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "bool", - to: "list", - }, - optionals: { - "attr-path": "lib.optionals", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "bool", - to: "list", - }, - toList: { - "attr-path": "lib.toList", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "any", - to: "list", - }, - range: { - "attr-path": "lib.range", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "int", - to: "list", - }, - partition: { - "attr-path": "lib.partition", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - "groupBy'": { - "attr-path": "lib.groupBy'", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - groupBy: { - "attr-path": "lib.groupBy", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - zipListsWith: { - "attr-path": "lib.zipListsWith", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - zipLists: { - "attr-path": "lib.zipLists", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - reverseList: { - "attr-path": "lib.reverseList", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - listDfs: { - "attr-path": "lib.listDfs", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "attrset", - }, - toposort: { - "attr-path": "lib.toposort", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - sort: { - "attr-path": "lib.sort", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - compareLists: { - "attr-path": "lib.compareLists", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "int", - }, - naturalSort: { - "attr-path": "lib.naturalSort", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - take: { - "attr-path": "lib.take", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - sublist: { - "attr-path": "lib.sublist", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - last: { - "attr-path": "lib.last", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "any", - }, - init: { - "attr-path": "lib.init", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - crossLists: { - "attr-path": "lib.crossLists", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - unique: { - "attr-path": "lib.unique", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - intersectLists: { - "attr-path": "lib.intersectLists", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - subtractLists: { - "attr-path": "lib.subtractLists", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "list", - }, - mutuallyExclusive: { - "attr-path": "lib.mutuallyExclusive", - "doc-url": - "https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists", - source: "nixpkgs", - from: "list", - to: "bool", - }, -}; - -export type FuncData = { - name: string; - info: { - "attr-path": string; - "doc-url": string; - source: string; - from: string; - to: string; - }; -}; - -const mockData: FuncData[] = Object.entries(libfuns).map(([key, value]) => ({ +const mockData: FuncData[] = Object.entries(nixFuns).map(([key, value]) => ({ name: key, info: value, })); @@ -378,7 +27,7 @@ const search = }); }; const filter = - (to: NixType, from: NixType) => + (to: NixType[], from: NixType[]) => (data: FuncData[]): FuncData[] => { return data.filter( ({ info }) => from.includes(info.from) && to.includes(info.to) diff --git a/types/nix.ts b/types/nix.ts index 88ab749..264e7d7 100644 --- a/types/nix.ts +++ b/types/nix.ts @@ -1 +1,24 @@ -export type NixType = "attrset" | "list" | "string" | "int" | "bool" | "any"; \ No newline at end of file +export type NixType = "attrset" | "list" | "string" | "int" | "bool" | "any"; +export const nixTypes: NixType[] = [ + "any", + "attrset", + "list", + "string", + "bool", + "int", + ]; + +export type FuncData = { + name: string; + info: NixFunctionMeta; +}; + +export type NixFunctionMeta = { + "attr-path": string; + "doc-url": string; + source: string; + from: NixType; + to: NixType; +} + +export type NixFunctionSet = {[name:string]: NixFunctionMeta} \ No newline at end of file