Skip to content

Commit

Permalink
feat: redis sync worker
Browse files Browse the repository at this point in the history
  • Loading branch information
adalinesimonian committed Mar 7, 2024
1 parent bb4c938 commit c0666c7
Show file tree
Hide file tree
Showing 53 changed files with 3,246 additions and 414 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# compiled output
/dist
/node_modules
packages/*/dist
packages/*/*.tsbuildinfo

# Logs
logs
Expand Down Expand Up @@ -48,3 +50,10 @@ junit.xml
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Redis
.redis

# Env
.env
packages/*/.env
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"typescript.enablePromptUseWorkspaceTsdk": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.rulers": [80, 120]
"editor.rulers": [80, 120],
"files.associations": {
"*.env": "properties"
}
}
9 changes: 9 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-after-install.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable */
//prettier-ignore
module.exports = {
name: "@yarnpkg/plugin-after-install",
factory: function (require) {
"use strict";var plugin=(()=>{var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var r=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var I=(t,o)=>{for(var e in o)s(t,e,{get:o[e],enumerable:!0})},h=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of x(o))!C.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(a=g(o,n))||a.enumerable});return t};var k=t=>h(s({},"__esModule",{value:!0}),t);var P={};I(P,{default:()=>y});var d=r("@yarnpkg/core");var f=r("@yarnpkg/core"),c={afterInstall:{description:"Hook that will always run after install",type:f.SettingsType.STRING,default:""}};var p=r("clipanion"),u=r("@yarnpkg/core");var m=r("@yarnpkg/shell"),l=async(t,o)=>{let e=t.get("afterInstall"),a=!!t.projectCwd?.endsWith(`dlx-${process.pid}`);return e&&!a?(o&&console.log("Running `afterInstall` hook..."),(0,m.execute)(e,[],{cwd:t.projectCwd||void 0})):0};var i=class extends p.Command{async execute(){let o=await u.Configuration.find(this.context.cwd,this.context.plugins);return l(o,!1)}};i.paths=[["after-install"]];var w={configuration:c,commands:[i],hooks:{afterAllInstalled:async(t,o)=>{if(o?.mode===d.InstallMode.UpdateLockfile)return;if(await l(t.configuration,!0))throw new Error("The `afterInstall` hook failed, see output above.")}}},y=w;return k(P);})();
return plugin;
}
};
324 changes: 162 additions & 162 deletions .yarn/releases/yarn-4.1.0.cjs → .yarn/releases/yarn-4.1.1.cjs
100755 → 100644

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint",
"version": "8.56.0-sdk",
"version": "8.57.0-sdk",
"main": "./lib/api.js",
"type": "commonjs",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion .yarn/sdks/prettier/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier",
"version": "3.2.4-sdk",
"version": "3.2.5-sdk",
"main": "./index.cjs",
"type": "commonjs",
"bin": "./bin/prettier.cjs"
Expand Down
10 changes: 9 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
yarnPath: .yarn/releases/yarn-4.1.0.cjs
enableGlobalCache: false

plugins:
- checksum: 0a2a35fbed2f33f0df1ceb1db51bf72554201f994eaecb86cbc62a295c3d05f7cc44fa8be8e64fc5e1c0bee4f529a17a0cc429ea9e3486ad467443291d5a8e3b
path: .yarn/plugins/@yarnpkg/plugin-after-install.cjs
spec: 'https://raw.githubusercontent.com/mhassan1/yarn-plugin-after-install/v0.6.0/bundles/@yarnpkg/plugin-after-install.js'

yarnPath: .yarn/releases/yarn-4.1.1.cjs

afterInstall: yarn mkenvlink
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: yarn workspace ordbokapi run start:prod
worker: yarn workspace uib-ord-sync run start:prod
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.8'
services:
redis:
image: redis/redis-stack:7.2.0-v9
ports:
- '${REDIS_PORT}:6379'
- '${REDIS_INSIGHT_PORT}:8001'
volumes:
- ./.redis:/data
42 changes: 42 additions & 0 deletions mkenvlink.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { promises as fs } from 'fs';
import path from 'path';

// makes a link to the .env file in the root in each package directory in the
// monorepo (packages/*) so that each package can access the same environment
// variables

const rootDir = path.dirname(new URL(import.meta.url).pathname);

const rootEnvPath = path.join(rootDir, '.env');
const packagesPath = path.join(rootDir, 'packages');

// create .env if it doesn't exist

try {
await fs.access(rootEnvPath);
} catch (err) {
if (err.code === 'ENOENT') {
await import('./writeenv.mjs');
} else {
throw err;
}
}

const packageDirs = await fs.readdir(packagesPath, { withFileTypes: true });

for (const packageDir of packageDirs) {
if (!packageDir.isDirectory()) continue;

const packageEnvPath = path.join(packagesPath, packageDir.name, '.env');

try {
await fs.unlink(packageEnvPath);
} catch (err) {
if (err.code !== 'ENOENT') throw err;
}

await fs.symlink(rootEnvPath, packageEnvPath);

const relativePath = path.relative(rootDir, packageEnvPath);
console.log(`Laga lenkje frå ${relativePath} til .env`);
}
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
"packages/*"
],
"scripts": {
"build": "yarn workspaces foreach -ptA --exclude ordbokapi-monorepo run build"
"build": "yarn workspaces foreach -ptA --exclude ordbokapi-monorepo run build",
"mkenvlink": "node mkenvlink.mjs",
"redis:start": "docker-compose -f ./docker-compose.yml up -d",
"redis:stop": "docker-compose -f ./docker-compose.yml down",
"redis:clear": "yarn redis:stop && node -e \"require('fs').rmSync('.redis', { recursive: true, force: true })\""
},
"devDependencies": {
"eslint": "^8.42.0",
"prettier": "^3.0.0",
"typescript": "^5.1.3"
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"typescript": "^5.4.2"
},
"jest": {
"moduleFileExtensions": [
Expand All @@ -42,7 +46,6 @@
},
"volta": {
"node": "21.6.2",
"yarn": "4.1.0"
},
"packageManager": "[email protected]"
"yarn": "4.1.1"
}
}
72 changes: 37 additions & 35 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"yarn": ">=4.0.2"
},
"scripts": {
"build": "nest build && node ./copy-head.mjs",
"build": "tsc --build tsconfig.build.json && node ./copy-head.mjs",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start": "tsc --build tsconfig.build.json && node dist/main",
"start:dev": "run-on-tsc-build yarn node dist/main.js",
"start:debug": "NEST_DEBUG=true yarn start:dev",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
Expand All @@ -24,48 +24,50 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@apollo/server": "^4.9.5",
"@apollo/server": "^4.10.1",
"@as-integrations/fastify": "^2.1.1",
"@nestjs/apollo": "^12.0.11",
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/graphql": "^12.0.11",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.0",
"@nestjs/apollo": "^12.1.0",
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.3.3",
"@nestjs/graphql": "^12.1.1",
"@nestjs/platform-fastify": "^10.3.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"fastify": "^4.25.1",
"class-validator": "^0.14.1",
"fastify": "^4.26.2",
"graphql": "^16.8.1",
"memjs": "^1.3.1",
"reflect-metadata": "^0.2.0",
"memjs": "^1.3.2",
"ordbokapi-common": "workspace:^",
"reflect-metadata": "^0.2.1",
"request-ip": "^3.3.0",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/memjs": "^1",
"@types/node": "^20.3.1",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.3",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/memjs": "^1.3.3",
"@types/node": "^20.11.25",
"@types/request-ip": "^0.0.41",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"prettier": "^3.0.0",
"prettier": "^3.2.5",
"run-on-tsc-build": "workspace:^",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"supertest": "^6.3.4",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
"typescript": "^5.4.2"
},
"jest": {
"moduleFileExtensions": [
Expand Down
7 changes: 6 additions & 1 deletion packages/api/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
"compilerOptions": {
"rootDir": "./src"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"],
"references": [{ "path": "../common" }]
}
5 changes: 3 additions & 2 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"target": "ES2022",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
Expand All @@ -17,5 +17,6 @@
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true
}
},
"references": [{ "path": "../common" }]
}
25 changes: 25 additions & 0 deletions packages/common/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
35 changes: 35 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "ordbokapi-common",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "tsc",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0",
"@redis/json": "^1.0.6",
"ioredis": "^5.3.2",
"luxon": "^3.4.4",
"redis": "^4.6.13",
"reflect-metadata": "^0.2.1",
"rxjs": "^7.8.1"
},
"peerDependencies": {
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0"
},
"devDependencies": {
"@types/luxon": "^3.4.2",
"@types/node": "^20.11.25",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"typescript": "^5.4.2"
}
}
4 changes: 4 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * as providers from './providers';
export * from './providers';
export * from './types';
export * from './utils';
3 changes: 3 additions & 0 deletions packages/common/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './redis.service';
export * from './uib-api.service';
export * from './uib-redis.service';
Loading

0 comments on commit c0666c7

Please sign in to comment.