From bf5098ed222305023daffa682f3e744d40c9932a Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 22 Mar 2023 20:31:24 -0500 Subject: [PATCH] Initial --- .envrc | 1 + .gitignore | 3 ++ design.md | 76 ++++++++++++++++++++++++++++++++++++ flake.lock | 93 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 35 +++++++++++++++++ proto/mznotes.proto | 4 ++ src/core/app.ts | 1 + src/core/db.ts | 12 ++++++ 8 files changed, 225 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 design.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 proto/mznotes.proto create mode 100644 src/core/app.ts create mode 100644 src/core/db.ts diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8276375 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +.pijul +.direnv diff --git a/design.md b/design.md new file mode 100644 index 0000000..0dfb860 --- /dev/null +++ b/design.md @@ -0,0 +1,76 @@ +- CLI API + + - `mznotes install` : Install a script into the database + - `mznotes show` : Show the information about a particular node, by ID + +- Database of nodes + code + + - Code + + - Code is all interface-based. Interface implementations give specific ways + behaviors are implemented + + - Standard interfaces: + - Indexed + + - Node definition + + ``` + struct Node { + metadata: KVStore, + implements: Set, + + edges: Set<(EdgeType, Edge)>, + } + ``` + + - Within the metadata kv store, keys are namespaced, according to the + application name. Application names must be registered ahead of time + + - Nodes implement interfaces, the code of which is fetched from the internet + and validated + + - Nodes are namespaced, although namespacing isn't the primary hierarchy + protocol. + + - This is needed because the database itself has a privileged namespace + - The privileged namespace is for keeping track of database state, for + example which scripts are trusted + + - Database service: + + - IFTTT Events + + - Local vs. distributed IFTTT events? + - Local means that ur particular device is repsonsible for running it + - Distributed means any device can consume the event??? + - is this even a good idea? Maybe just have one dedicated worker + device. For example, may not want to run certain automation tasks + on phone, while others may only be able to be run on phone + + - Cron tasks + - Sync protocol: + - After a modification, the modification gets written to a queue + - CRDT? + +- Other privileged concepts: + + - User: a pub/priv key pair + +- Use cases + + - Personal journaling (like Logseq) + - Weight / fitness tracking + - Calendar app (store events) + - Git app (store code) + - File backup + - Chat / Mail? + - Photo viewer + indexing using ML models for face detection / keywords + + - Not sure yet: + - Automatic sharing of database nodes? This seems like a bad idea for + multiple reasons. Maybe better to just have a specific app for + doing permission models + +- Other concerns + - Local protection using libsecret? diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a0487d9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,93 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1679466129, + "narHash": "sha256-BQt0ADAhPAwuoq3z+iprmHyw1NeyerOw1GiIEJkANGc=", + "owner": "nix-community", + "repo": "fenix", + "rev": "49237f7a76b98954306e77a7bd42f6491ad5c6a7", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1679262748, + "narHash": "sha256-DQCrrAFrkxijC6haUzOC5ZoFqpcv/tg2WxnyW3np1Cc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "60c1d71f2ba4c80178ec84523c2ca0801522e0a6", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1663551060, + "narHash": "sha256-e2SR4cVx9p7aW/XnVsGsWZBplApA9ZJUjc0fejJhnYo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8a5b9ee7b7a2b38267c9481f5c629c015108ab0d", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1679428647, + "narHash": "sha256-gyS7UDFNzQfRKJvUDlVuM8wXCIyreBmVq+aiPXhfTlk=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "3321799e8fac622db50fe8c3284062f7d0f1bf53", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c67274d --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + inputs = { fenix.url = "github:nix-community/fenix"; }; + + outputs = { self, nixpkgs, flake-utils, fenix }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ fenix.overlays.default ]; + }; + + toolchain = pkgs.fenix.stable; + in rec { + devShell = pkgs.mkShell { + packages = (with pkgs; [ + cargo-deny + cargo-edit + cargo-expand + cargo-flamegraph + cargo-watch + + deno + + (python310.withPackages (p: with p; [ ipython numpy scipy sympy ])) + ]) ++ (with toolchain; [ + cargo + rustc + clippy + + # Get the nightly version of rustfmt so we can wrap comments + pkgs.fenix.default.rustfmt + ]); + }; + }); +} diff --git a/proto/mznotes.proto b/proto/mznotes.proto new file mode 100644 index 0000000..aee8ac9 --- /dev/null +++ b/proto/mznotes.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; + +service Database { +} diff --git a/src/core/app.ts b/src/core/app.ts new file mode 100644 index 0000000..ddb914f --- /dev/null +++ b/src/core/app.ts @@ -0,0 +1 @@ +import { Database } from "./db.ts"; diff --git a/src/core/db.ts b/src/core/db.ts new file mode 100644 index 0000000..0607fbf --- /dev/null +++ b/src/core/db.ts @@ -0,0 +1,12 @@ +export default class Database { + public createNode(): Node { + // TODO: Calculate the interfaces that must be implemented + // Using the interface application rules + let node = new Node(); + } +} + +export class Node { + public delete() { + } +}