fleshing out apps a bit

This commit is contained in:
Michael Zhang 2023-03-29 20:56:52 -05:00
parent 86a2fabfcf
commit 917fb469af
16 changed files with 180 additions and 8 deletions

2
.envrc
View file

@ -1 +1,3 @@
use flake use flake
export DATABASE_URL=file:./dev.db

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
}
}

View file

@ -8,10 +8,11 @@ doc-watch:
doc-dependencies: docs/src/generated/spec/index.md doc-dependencies: docs/src/generated/spec/index.md
generated/spec/meta.schema.json: spec/meta.schema.yml generated/spec/meta.schema.json: spec/meta.schema.yml
yq . $< > $@ mkdir -p generated/spec
yq -o json . $< > $@
docs/src/generated/spec/index.md: generated/spec/meta.schema.json docs/src/generated/spec/index.md: generated/spec/meta.schema.json
mkdir -p generated/spec mkdir -p docs/src/generated/spec
node spec/generate.js node spec/generate.js
clean: clean:

9
apps/todos/Todos.ts Normal file
View file

@ -0,0 +1,9 @@
import { HookContext } from "../../src/api";
export default class {
constructor() {}
static registerHooks(ct: HookContext) {
ct.addSensitivePattern(//);
}
}

11
apps/todos/meta.json Normal file
View file

@ -0,0 +1,11 @@
{
"$schema": "../../generated/spec/meta.schema.json",
"title": "Todos",
"license": "MIT",
"depends": {},
"interfaces": {
"Todos": "./Todos.js"
}
}

View file

@ -1,3 +0,0 @@
{
"": "",
}

View file

@ -9,6 +9,7 @@
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"types": "./src/api.d.ts",
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"json-schema-static-docs": "^0.23.0", "json-schema-static-docs": "^0.23.0",

1
prisma/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/dev.db*

View file

View file

@ -0,0 +1,68 @@
-- CreateTable
CREATE TABLE "Node" (
"id" TEXT NOT NULL PRIMARY KEY,
"label" TEXT
);
-- CreateTable
CREATE TABLE "Edge" (
"id" TEXT NOT NULL PRIMARY KEY
);
-- CreateTable
CREATE TABLE "Interface" (
"id" TEXT NOT NULL PRIMARY KEY
);
-- CreateTable
CREATE TABLE "Graph" (
"label" TEXT,
"fromId" TEXT NOT NULL,
"toId" TEXT NOT NULL,
PRIMARY KEY ("fromId", "toId"),
CONSTRAINT "Graph_fromId_fkey" FOREIGN KEY ("fromId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Graph_toId_fkey" FOREIGN KEY ("toId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "NodeMeta" (
"nodeId" TEXT NOT NULL,
"appId" TEXT NOT NULL,
"key" TEXT NOT NULL,
"value" BLOB NOT NULL,
PRIMARY KEY ("nodeId", "appId", "key"),
CONSTRAINT "NodeMeta_nodeId_fkey" FOREIGN KEY ("nodeId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "NodeMeta_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "NodeImplements" (
"nodeId" TEXT NOT NULL,
"interfaceId" TEXT NOT NULL,
PRIMARY KEY ("nodeId", "interfaceId"),
CONSTRAINT "NodeImplements_nodeId_fkey" FOREIGN KEY ("nodeId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "NodeImplements_interfaceId_fkey" FOREIGN KEY ("interfaceId") REFERENCES "Interface" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "App" (
"id" TEXT NOT NULL PRIMARY KEY,
"localName" TEXT NOT NULL,
"title" TEXT NOT NULL,
"installed" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "Patterns" (
"id" TEXT NOT NULL PRIMARY KEY,
"pattern" TEXT NOT NULL,
"appId" TEXT NOT NULL,
"functionName" TEXT NOT NULL,
CONSTRAINT "Patterns_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "App_localName_key" ON "App"("localName");

View file

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"

View file

@ -15,6 +15,8 @@ model Node {
fromNodes Graph[] @relation(name: "fromNode") fromNodes Graph[] @relation(name: "fromNode")
toNodes Graph[] @relation(name: "toNode") toNodes Graph[] @relation(name: "toNode")
metadata NodeMeta[]
} }
model Edge { model Edge {
@ -38,6 +40,19 @@ model Graph {
@@id([fromId, toId]) @@id([fromId, toId])
} }
model NodeMeta {
nodeId String
toNode Node @relation(fields: [nodeId], references: [id])
appId String
app App @relation(fields: [appId], references: [id])
key String
value Bytes
@@id([nodeId, appId, key])
}
model NodeImplements { model NodeImplements {
nodeId String nodeId String
node Node @relation(fields: [nodeId], references: [id]) node Node @relation(fields: [nodeId], references: [id])
@ -47,3 +62,27 @@ model NodeImplements {
@@id([nodeId, interfaceId]) @@id([nodeId, interfaceId])
} }
model App {
id String @id @default(uuid())
localName String @unique
title String
installed DateTime
patterns Patterns[]
metaKeys NodeMeta[]
}
/// Regular expressions table
model Patterns {
id String @id @default(uuid())
pattern String
appId String
app App @relation(fields: [appId], references: [id])
functionName String
}

View file

@ -2,16 +2,33 @@ $id: "https://example.com/person.schema.json"
$schema: "http://json-schema.org/draft-07/schema" $schema: "http://json-schema.org/draft-07/schema"
title: Application title: Application
type: object type: object
additionalProperties: false
properties: properties:
name: $schema:
type: string type: string
title: URL
title:
type: string
required: true
title: Name of the application title: Name of the application
authors:
type: array
items: { type: string }
title: List of authors
license: license:
type: [string, "null"] type: [string, "null"]
title: SPDX Expression representing the license of the database. title: SPDX Expression representing the license of the database.
description: |- description: |-
If the software uses a proprietary license, use `null` to indicate that. If the software uses a proprietary license, use `null` to indicate that.
depends:
type: object
title: List of dependencies
interfaces:
type: object
title: List of interfaces

11
src/api.d.ts vendored Normal file
View file

@ -0,0 +1,11 @@
/**
* API for executed code
*/
/** Hook context */
export declare class HookContext {
/**
* Add a new sensitive pattern to the database.
*/
addSensitivePattern(pattern: RegExp): void;
}

View file

@ -44,7 +44,9 @@ export default class Database {
const prisma = new PrismaClient(); const prisma = new PrismaClient();
return await prisma.$transaction(async (client) => { return await prisma.$transaction(async (client) => {
const createdNode = client.node.create({ data: { label: request.label } }); const createdNode = client.node.create({
data: { label: request.label },
});
return createdNode; return createdNode;
}); });

View file

@ -10,6 +10,11 @@
"jsxImportSource": "solid-js", "jsxImportSource": "solid-js",
"types": ["vite/client"], "types": ["vite/client"],
"noEmit": true, "noEmit": true,
"isolatedModules": true "isolatedModules": true,
"baseUrl": ".",
"paths": {
"@panorama": ["src/*"]
}
} }
} }