Skip to content

Commit

Permalink
#3 WIP InMemoryStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgfeller committed Jun 22, 2023
1 parent 7a6466b commit b60d55e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
59 changes: 59 additions & 0 deletions DApps/InMemStorage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
""" Example DApp - fake Coop Supercard data """
from __future__ import annotations

import datetime
import typing

import fastapi
import fastapi.security
import pydantic
from core import (common_ids, dapp_attrs, keys, nodes, permissions, principals, users,
relationships, schemas)

from schema_formats import py_schema
from frontend import fastapi_dapp
app = fastapi.FastAPI()
app.include_router(fastapi_dapp.router)


def get_apps() -> tuple[dapp_attrs.DApp]:
return (IN_MEM_STORAGE_DAPP,)


fastapi_dapp.get_apps = get_apps


class InMemStorageDApp(dapp_attrs.DApp):

_ddhschema: py_schema.PySchemaElement = None
version = '0.0'
owner: typing.ClassVar[principals.Principal] = users.SystemUser
catalog = common_ids.CatalogCategory.system

def __init__(self, *a, **kw):
super().__init__(*a, **kw)

def get_schemas(self) -> dict[keys.DDHkey, schemas.AbstractSchema]:
""" Obtain initial schema for DApp """
return {}

def execute(self, req: dapp_attrs.ExecuteRequest):
""" obtain data by recursing to schema """
if req.op == nodes.Ops.get:
here, selection = req.access.ddhkey.split_at(req.key_split)
else:
raise ValueError(f'Unsupported {req.op=}')
return d


IN_MEM_STORAGE_DAPP = InMemStorageDApp(name='InMemStorageDApp', owner=users.SystemUser,
catalog=common_ids.CatalogCategory.system)


if __name__ == "__main__": # Debugging
import uvicorn
import os
port = 9051
os.environ['port'] = str(port)
uvicorn.run(app, host="0.0.0.0", port=port)
...
14 changes: 7 additions & 7 deletions core/common_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import typing
import enum

TrxId = typing.NewType('TrxId',str)
TrxId = typing.NewType('TrxId', str)
PersistId = typing.NewType('PersistId', str)
PrincipalId = typing.NewType('PrincipalId', str)
SessionId = typing.NewType('SessionId', str) # identifies the session

SessionId = typing.NewType('SessionId', str) # identifies the session


@enum.unique
class Label(str,enum.Enum):
class Label(str, enum.Enum):
""" labels and designators """
id = 'id'
free = 'free'
Expand All @@ -23,13 +22,14 @@ def __repr__(self): return self.value


@enum.unique
class CatalogCategory(str,enum.Enum):
class CatalogCategory(str, enum.Enum):
""" Top level catalog categories """
family = 'family'
employment = 'employment'
education = 'education'
living = 'living'
living = 'living'
finance = 'finance'
health = 'health'
system = 'system'

def __repr__(self): return self.value
def __repr__(self): return self.value

0 comments on commit b60d55e

Please sign in to comment.