From 917fb469afddd0ce3c384fb2c65a07677d05b477 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 29 Mar 2023 20:56:52 -0500 Subject: [PATCH] fleshing out apps a bit --- .envrc | 2 + .vscode/settings.json | 5 ++ Makefile | 5 +- apps/todos/Todos.ts | 9 +++ apps/todos/meta.json | 11 +++ apps/todos/meta.json5 | 3 - package.json | 1 + prisma/.gitignore | 1 + prisma/dev.db | 0 .../20230330015624_initial/migration.sql | 68 +++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 39 +++++++++++ spec/meta.schema.yml | 19 +++++- src/api.d.ts | 11 +++ src/core/db.ts | 4 +- tsconfig.json | 7 +- 16 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 apps/todos/Todos.ts create mode 100644 apps/todos/meta.json delete mode 100644 apps/todos/meta.json5 create mode 100644 prisma/.gitignore delete mode 100644 prisma/dev.db create mode 100644 prisma/migrations/20230330015624_initial/migration.sql create mode 100644 prisma/migrations/migration_lock.toml create mode 100644 src/api.d.ts diff --git a/.envrc b/.envrc index 3550a30..078c439 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,3 @@ use flake + +export DATABASE_URL=file:./dev.db \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..faa8f17 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "[prisma]": { + "editor.defaultFormatter": "Prisma.prisma" + } +} diff --git a/Makefile b/Makefile index 12a5179..4fed1f6 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,11 @@ doc-watch: doc-dependencies: docs/src/generated/spec/index.md 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 - mkdir -p generated/spec + mkdir -p docs/src/generated/spec node spec/generate.js clean: diff --git a/apps/todos/Todos.ts b/apps/todos/Todos.ts new file mode 100644 index 0000000..8c5c7b2 --- /dev/null +++ b/apps/todos/Todos.ts @@ -0,0 +1,9 @@ +import { HookContext } from "../../src/api"; + +export default class { + constructor() {} + + static registerHooks(ct: HookContext) { + ct.addSensitivePattern(//); + } +} diff --git a/apps/todos/meta.json b/apps/todos/meta.json new file mode 100644 index 0000000..cdb57a0 --- /dev/null +++ b/apps/todos/meta.json @@ -0,0 +1,11 @@ +{ + "$schema": "../../generated/spec/meta.schema.json", + "title": "Todos", + "license": "MIT", + + "depends": {}, + + "interfaces": { + "Todos": "./Todos.js" + } +} diff --git a/apps/todos/meta.json5 b/apps/todos/meta.json5 deleted file mode 100644 index d00ebf9..0000000 --- a/apps/todos/meta.json5 +++ /dev/null @@ -1,3 +0,0 @@ -{ - "": "", -} diff --git a/package.json b/package.json index e850d3a..ceee48b 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "keywords": [], "author": "", "license": "ISC", + "types": "./src/api.d.ts", "devDependencies": { "@types/express": "^4.17.17", "json-schema-static-docs": "^0.23.0", diff --git a/prisma/.gitignore b/prisma/.gitignore new file mode 100644 index 0000000..890c522 --- /dev/null +++ b/prisma/.gitignore @@ -0,0 +1 @@ +/dev.db* \ No newline at end of file diff --git a/prisma/dev.db b/prisma/dev.db deleted file mode 100644 index e69de29..0000000 diff --git a/prisma/migrations/20230330015624_initial/migration.sql b/prisma/migrations/20230330015624_initial/migration.sql new file mode 100644 index 0000000..e59b1a4 --- /dev/null +++ b/prisma/migrations/20230330015624_initial/migration.sql @@ -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"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5e5c47 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -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" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f8e7f8f..1884699 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -15,6 +15,8 @@ model Node { fromNodes Graph[] @relation(name: "fromNode") toNodes Graph[] @relation(name: "toNode") + + metadata NodeMeta[] } model Edge { @@ -38,6 +40,19 @@ model Graph { @@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 { nodeId String node Node @relation(fields: [nodeId], references: [id]) @@ -47,3 +62,27 @@ model NodeImplements { @@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 +} diff --git a/spec/meta.schema.yml b/spec/meta.schema.yml index d0e58fd..b945e50 100644 --- a/spec/meta.schema.yml +++ b/spec/meta.schema.yml @@ -2,16 +2,33 @@ $id: "https://example.com/person.schema.json" $schema: "http://json-schema.org/draft-07/schema" title: Application type: object +additionalProperties: false properties: - name: + $schema: type: string + title: URL + + title: + type: string + required: true title: Name of the application + authors: + type: array + items: { type: string } + title: List of authors + license: type: [string, "null"] title: SPDX Expression representing the license of the database. description: |- 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 diff --git a/src/api.d.ts b/src/api.d.ts new file mode 100644 index 0000000..b9488e4 --- /dev/null +++ b/src/api.d.ts @@ -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; +} diff --git a/src/core/db.ts b/src/core/db.ts index d9878a7..d2ed19b 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -44,7 +44,9 @@ export default class Database { const prisma = new PrismaClient(); 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; }); diff --git a/tsconfig.json b/tsconfig.json index 249b273..a3ffc16 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,11 @@ "jsxImportSource": "solid-js", "types": ["vite/client"], "noEmit": true, - "isolatedModules": true + "isolatedModules": true, + + "baseUrl": ".", + "paths": { + "@panorama": ["src/*"] + } } }