Git Product home page Git Product logo

denolang-example's Introduction

Description

Hierarchy service

flowchart LR
    User -->|HTTP|Deno
    Deno -->|Conn pool|MySQL

API

GET /ping

just ping :) always returns ok and status 200

GET /ping: Response

"ok"

POST /employees

Rewrites current employees hiearchy.

POST /employees: Request

Json shema for request:

{
 "$schema": "http://json-schema.org/draft-07/schema#",
 "type": "object",
 "patternProperties": {
  ".*": { "type": "string" },
 },
 "additionalProperties": false,
}

Example:

{
    "Pete": "Nick",
    "Barbara": "Nick",
    "Nick": "Sophie",
    "Sophie": "Jonas"
}

POST /employees: Response

Document representing unflattened hierarchy.

{"Jonas":{"Sophie":{"Nick":{"Pete":{},"Barbara":{}}}}}

GET /supervisors/:name/:levels

Returns supervisors of :name up to :levels in height.

GET /supervisors/:name/:levels: Request

Params:

  • name – case sensitive name of employee;
  • levels – integer specifying depth of search.

GET /supervisors/:name/:levels: Response

An unsorted array of supervisors names for :name. Empty array if :name does not exists or has no supervisors.

Example:

[ { "name": "Sophie" }, { "name": "Jonas" } ]

How to setup local dev environment

Copy config cp .env.dist .env

VsCode:

  1. Reopen in container
  2. Deno: cache depenencies

App is started in watch mode. Logs are in VsCode Terminal.

Some app setting are set in devcontainer.json.

Debugging

To start debugging session use Attach to remote. If you need to debug bootstrap, kill terminal process and start with denon run --allow-all --inspect-brk=127.0.0.1:9229 main.ts then 'Attach to remote'.

Workflow

lint and format

deno lint

deno fmt

running tests

deno test --allow-read

to watch tests:

denon test

updating snapshots

deno test --allow-all -- --update

How to deploy

docker build -t deno-container

helm install deno ./deno-chart

Port fowarding of app container:

export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=deno-chart,app.kubernetes.io/instance=deno" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8081/ping to use your application"
kubectl --namespace default port-forward $POD_NAME 8081:$CONTAINER_PORT

Test requests

located in test.http file. Supported by rest-client vscode extension

Features

  • [✅] parse payload, transform
  • [✅] store payload in mysql/maria
  • [✅] hande syntax errors in payload as 400 json excpetion
  • [✅] endopoint for supervisor from storage
  • [✅] devcontainer, readme.md
  • [✅] tests !
  • [✅] basic auth !!
  • [✅] helm for mysql and service !!!
  • [✅] todo service to mysql connection in k8s !!!!
  • [✅] move secrets from deployment to separate file that could be encrypted with sops
  • [✅] read sql from file
  • [] devcontainer with kind, helm. support for debugger into k8s attachment
  • [✅] extract app server from main.ts to separate module
  • [✅] int test with superdeno
  • [] create test only db for int tests (currently local db is used)
  • [] more int test cases
  • [✅] make insertion transactional
  • [✅] healthcheck handler
  • [] helm: mysql as a separate service with pv

denolang-example's People

Watchers

Kosta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.