Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
13eba24
feat(backend,client,common): implementation
melancholiai Jan 23, 2024
d8a0a9f
feat(backend): tile location calculation
melancholiai Jan 29, 2024
af5d04f
feat(backend): added z,x,y to tile details
melancholiai Feb 4, 2024
22d4b0c
chore(backend,client,common): versioned as v1.0.0
melancholiai Feb 4, 2024
fab6a6e
fix(backend,client,common): versioned as v1.0.0-rc1
melancholiai Feb 4, 2024
0d05a67
feat(frontend): implementation
melancholiai Apr 15, 2024
7217ce0
refactor(frontend): setInterval in async
melancholiai Apr 16, 2024
7d70256
build(frontend): tsconfig type checking
melancholiai Apr 16, 2024
5c8c2c0
fix(backend,frontend): regenerated package-lock
melancholiai Apr 16, 2024
00cafd6
fix(backend,frontend): regenerated package-lock
melancholiai Apr 16, 2024
963b6ad
feat(backend): helm charts
melancholiai Apr 16, 2024
64e5a78
feat(backend): created dockerfile
melancholiai May 6, 2024
3930aef
test(client): added unit tests
melancholiai May 12, 2024
3418502
test(backend): added unit tests
melancholiai May 23, 2024
746cae9
ci(configurations): github workflow
melancholiai May 23, 2024
480f275
feat(backend,frontend): additional implementation
melancholiai Jun 4, 2024
696cfb2
feat(backend,frontend,common): added skipCount to tile schema
melancholiai Jun 5, 2024
0ceb420
feat(frontend): added optional basemap x-api-key
melancholiai Jun 9, 2024
21c0ce3
feat(frontend): material-ui migration wip
melancholiai Jun 18, 2024
cfda0b6
ci(configurations): ci wip
melancholiai Jun 18, 2024
33a1a50
feat(frontend): material ui migration
melancholiai Jun 18, 2024
7abd86e
fix(frontend): deployment config
melancholiai Jun 19, 2024
e995838
feat(frontend): added go to location and metric info
melancholiai Jun 26, 2024
be38952
fix(backend): redis credentials bug
melancholiai Jul 4, 2024
d1923ef
feat(frontend): additional improvements
melancholiai Jul 4, 2024
294d184
feat(backend,frontend,common,client): additional improvements
melancholiai Jul 18, 2024
07709c5
chore(client,common): bumped package versions
melancholiai Jul 18, 2024
1a9cb51
feat(backend,frontend): additional improvements
melancholiai Jul 21, 2024
f8bfbad
fix(deps): regenerated package.json
melancholiai Jul 21, 2024
3489e98
docs(backend, frontend): added docs
melancholiai Jul 22, 2024
b1f9d79
feat(backend,frontend,common): added renderedAt and renderCount
melancholiai Jul 29, 2024
3b9b5bf
fix(backend,common): run linters
melancholiai Jul 29, 2024
5630b10
refactor(deps): regenerated package-lock
melancholiai Jul 29, 2024
c79ca9f
refactor(backend,client,frontend): changes according to pr
melancholiai Aug 1, 2024
f5e6bb4
feat(frontend): overview map
melancholiai Aug 1, 2024
97b1246
refactor(frontend): slimmed app.tsx
melancholiai Aug 5, 2024
f2f2a4a
docs(backend, frontend): updated docs
melancholiai Aug 5, 2024
139e899
refactor(backend): using sMembers instead of keys
melancholiai Aug 6, 2024
5825a99
refactor(frontend): removed maplibre attribution control
melancholiai Aug 6, 2024
61a72f2
refactor(frontend): improved css
melancholiai Aug 8, 2024
d404493
feat(frontend): added state range inputs
melancholiai Aug 13, 2024
4d1a18c
chore(deps): updated package versions
melancholiai Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ignorePatterns": ["**/*.js", "dist", "helm", "coverage", "reports", ".husky"],
"ignorePatterns": ["**/*.js", "dist", "helm", "node_modules"],
"extends": ["@map-colonies/eslint-config/jest", "@map-colonies/eslint-config/ts-base"],
"parserOptions": {
"project": "./tsconfig.lint.json"
Expand Down
72 changes: 58 additions & 14 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ on: [pull_request]

jobs:
eslint:
name: Run eslint
name: Run TS Project eslint
runs-on: ubuntu-latest

strategy:
matrix:
node: [18.x, 20.x]

steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Check out TS Project Git repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 20
node-version: ${{ matrix.node }}

- name: Install dependencies
- name: Install TS Project dependencies
run: npm ci

- name: Run linters
- name: Build Lerna
run: npx lerna run build

- name: Run typecheck
run: npx lerna run typecheck

- name: Run TS Project linters
uses: wearerequired/lint-action@v1
with:
github_token: ${{ secrets.github_token }}
Expand All @@ -28,11 +38,37 @@ jobs:
prettier: true
eslint_extensions: ts

- name: Run local linters
run: npx lerna run lint:fix

openapi-lint:
name: Run OpenAPI lint Check
runs-on: ubuntu-latest

strategy:
matrix:
package: [backend]

steps:
- name: Check out TS Project Git repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install TS Project dependencies
run: npm ci

- name: Build Lerna
run: npx lerna run build

- name: OpenAPI Lint Checks
uses: nwestfall/openapi-action@v1.0.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
file: ./openapi3.yaml
file: ./packages/${{ matrix.package }}/openapi3.yaml

security:
runs-on: ubuntu-latest
Expand All @@ -56,28 +92,36 @@ jobs:
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: npm

- name: Install Node.js dependencies
run: npm ci

- name: Build Lerna
run: npx lerna run build

- name: Run tests
run: npm run test
run: npx lerna run test

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: Test Reporters
path: reports/**
path: packages/**/reports/**

build_image:
name: Build Image
runs-on: ubuntu-latest

strategy:
matrix:
package: [backend, frontend]

steps:
- name: Check out Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: build Docker image
run: docker build -t test-build:latest .
run: docker build -f ./packages/${{ matrix.package }}/Dockerfile -t ${{ matrix.package }}:latest .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/local.json
**/myvalues.yaml

# Logs
logs
*.log
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- lerna run lint
2 changes: 1 addition & 1 deletion .licrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This will indicate which licenses are not accepted.
# The rest will be accepted, except for the unknown licenses or dependencies without licenses.
unaccepted = ["LGPL"]
# Note that only one of the previous options can be enabled at once.
# Note that only one of the previous options can be enabled at once.
# If both of them are informed, only accepted will be considered.

[dependencies]
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ node_modules
coverage
helm
reports
jest.config*.js
lerna.json
181 changes: 82 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,101 @@
# Map Colonies typescript service template

----------------------------------

This is a basic repo template for building new MapColonies web services in Typescript.

### Template Features:

- eslint configuration by [@map-colonies/eslint-config](https://github.com/MapColonies/eslint-config)

- prettier configuration by [@map-colonies/prettier-config](https://github.com/MapColonies/prettier-config)

- jest

- .nvmrc

- Multi stage production-ready Dockerfile

- commitlint

- git hooks

- logging by [@map-colonies/js-logger](https://github.com/MapColonies/js-logger)

- OpenAPI request validation

- config load with [node-config](https://www.npmjs.com/package/node-config)

- Tracing and metrics by [@map-colonies/telemetry](https://github.com/MapColonies/telemetry)

- github templates

- bug report

- feature request

- pull request

- github actions

- on pull_request

- LGTM

- test

- lint

- snyk

## API
Checkout the OpenAPI spec [here](/openapi3.yaml)

## Installation

Install deps with npm

```bash
npm install
```
### Install Git Hooks
```bash
npx husky install
# detiler

this monorepo includes detiler backend, frontend, client and their common library

## detiler-backend
deploys an api used to maintain each and every metatile's metadata and query it according to selected filters

data is cached in redis and updated with each tile processing done by the [retiler](https://github.com/MapColonies/retiler) service

- leverages from unnecessary tile processing skip
- quick and easy kit comparison
- data maintenance for immediate and future BI

## detiler-frontend
a react app containing `deck.gl` map components presenting selected kit's metatiles.

data is colored in relation to some metric (state, update count, skip count, currentness, etc.) thus presenting for each tile it's metric in correlation with all other tiles.

### tile metadata example:
```json
{
"z":17,
"x":19520,
"y":5321,
"kit":"my-default-kit",
"state":666,
"updatedAt":1711907506,
"renderedAt":1711907506,
"createdAt":1711302106,
"updateCount":13,
"renderCount":11,
"skipCount":2,
"geoshape":"POLYGON ((34.453125 31.541748046875, 34.453125 31.53076171875, 34.464111328125 31.53076171875, 34.464111328125 31.541748046875, 34.453125 31.541748046875))",
"coordinates":"34.458618, 31.536255"
}
```

## Run Locally
### tile processing skip timeline:
this process will occur in `retiler` by quering `detiler-backend`

Clone the project
1. a tile is being candidate for processing
2. is the tile processing is attributed as forced? if so skip steps 3-5 and jump to step 6.
3. query the tile's details from the backend --and `renderedAt` field
4. fetch the tile's kit data timestamp (the timestamp is being maintained by osm2pgsql, with every append data timestamp is updated)
5. compare the two, if tile's `renderedAt` time is later than kit data time - the tile has already been processed with the most current data, meaning its processing can be skipped. thus we have the following branch, either:
- `renderedAt` >= kit timestamp - processing should be skipped: update the tile's details - `state`, `updateCount`, `updatedAt` and `skipCount` accordingly
- `renderedAt` < kit timestamp - processing is needed
6. process the tile and update the tile's details - `state`, `updateCount`, `updatedAt`, `renderCount` and `renderedAt` accordingly

```bash
## Configuration
the frontend app including its environment variables are being processed in buildtime.
to achieve runtime variables we inject for each variable it's value in runtime instead of a placeholder.

git clone https://link-to-project
see [.env.production](/packages/frontend/config/.env.production) and [env.sh](/packages/frontend/env.sh).

## Redis
### redis search index creation:
```

Go to the project directory

```bash

cd my-project

FT.CREATE tileDetailsIdx ON JSON PREFIX 1 tile:
SCHEMA $.kit AS kit TEXT $.updatedAt AS updatedAt NUMERIC $.renderedAt AS renderedAt NUMERIC $.createdAt AS createdAt NUMERIC $.updateCount AS updateCount NUMERIC $.renderCount AS renderCount NUMERIC $.skipCount AS skipCount NUMERIC $.coordiantes AS coordinates GEO $.geoshape AS geoshape GEOSHAPE SPHERICAL $.state AS state NUMERIC $.z AS z NUMERIC $.x AS x NUMERIC $.y AS y NUMERIC
```

Install dependencies
### redis post processing:
preferably we would use the `Redis Gears` module, but in the meantime the deprecated `Triggers and Functions` module is in use.

```bash

npm install
the following post processing function is being used to maintain additional metadata for each kit - it's `maxState` and `maxUpdatedAt`

execute with `redis-cli`
```

Start the server

```bash

npm run start

TFUNCTION LOAD REPLACE "#!js name=LibName api_version=1.0\n
function getMaximum(client, data) {
currentKit = client.call('json.get', data.key, 'kit');
currentState = client.call('json.get', data.key, 'state');
currentUpdatedAt = client.call('json.get', data.key, 'updatedAt');
key = 'kit:' + currentKit.slice(1, currentKit.length - 1);
maxState = client.call('hget', key, 'maxState');
if(maxState < currentState) {
client.call('hset', key, 'maxState', currentState);
}
maxUpdatedAt = client.call('hget', key, 'maxUpdatedAt');
if(maxUpdatedAt < currentUpdatedAt) {
client.call('hset', key, 'maxUpdatedAt', currentUpdatedAt);
}
}

redis.registerKeySpaceTrigger('KitLibrary', 'tile:', getMaximum);"
```

## Running Tests

To run tests, run the following command

```bash

npm run test
## Development
This repository is a monorepo managed by [`Lerna`](https://lerna.js.org/) and separated into multiple independent packages

## Building
```

To only run unit tests:
```bash
npm run test:unit
npx lerna run build
```

To only run integration tests:
```bash
npm run test:integration
## Tests
integration tests are missing due to `node-redis` library structure, [see open issue here](https://github.com/redis/node-redis/issues/2546)
```
npx lerna run test
```
10 changes: 6 additions & 4 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
"scope-enum": [2, "always", ["deps", "configurations"]],
}
extends: ['@commitlint/config-conventional'],
rules: {
'scope-enum': async ctx =>
[2, 'always', ["deps", "configurations", "helm", "backend", "client", "common", "frontend"]],
"scope-empty": [2, "never"],
}
};
6 changes: 0 additions & 6 deletions helm/Chart.yaml

This file was deleted.

Loading