Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #36 from theodo/feat/import-event-store-visualizat…
Browse files Browse the repository at this point in the history
…ion-code

feature: import event store visualization code
  • Loading branch information
ThomasAribart authored Jun 27, 2022
2 parents 5dd7976 + de7124d commit 398a6f3
Show file tree
Hide file tree
Showing 50 changed files with 9,987 additions and 312 deletions.
4 changes: 4 additions & 0 deletions castore.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"path": "demo/implementation",
"name": "✨ Demo: Implementation"
},
{
"path": "demo/visualization",
"name": "✨ Demo: Visualization"
},
{
"path": ".",
"name": "🦫 castore root"
Expand Down
7 changes: 5 additions & 2 deletions demo/blueprint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
},
"dependencies": {
"@babel/runtime": "^7.18.3",
"@castore/event-store": "^0.3.91"
"@castore/event-store": "^0.3.91",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/cli": "^7.17.6",
Expand All @@ -52,7 +53,9 @@
"typescript": "^4.6.3"
},
"peerDependencies": {
"json-schema-to-ts": "^2.5.3"
"@castore/event-store": "^0.3.91",
"json-schema-to-ts": "^2.5.3",
"uuid": "^8.3.2"
},
"maintainers": [
"Thomas Aribart",
Expand Down
81 changes: 81 additions & 0 deletions demo/blueprint/src/commands/createUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { v4 as uuid } from 'uuid';

import { JSONSchemaCommand, tuple } from '@castore/event-store';

import { userEventStore, UserStatus } from 'users';

export const createUser = new JSONSchemaCommand({
commandId: 'CREATE_USER',
requiredEventStores: tuple(userEventStore),
inputSchema: {
type: 'object',
properties: {
firstName: { type: 'string', minLength: 3 },
lastName: { type: 'string', minLength: 3 },
},
required: ['firstName', 'lastName'],
additionalProperties: false,
} as const,
outputSchema: {
type: 'object',
properties: {
userId: { type: 'string', format: 'uuid' },
},
required: ['userId'],
additionalProperties: false,
} as const,
handler: async (input, eventStores) => {
const { firstName, lastName } = input;
const [usersStore] = eventStores;

const userId = uuid();

await usersStore.pushEvent({
aggregateId: userId,
version: 1,
type: 'USER_CREATED',
timestamp: new Date().toISOString(),
payload: {
firstName,
lastName,
},
});

return { userId };
},
});

export const deleteUser = new JSONSchemaCommand({
commandId: 'DELETE_USER',
requiredEventStores: tuple(userEventStore),
inputSchema: {
type: 'object',
properties: {
userId: { type: 'string', format: 'uuid' },
},
required: ['userId'],
additionalProperties: false,
} as const,
handler: async (input, eventStores) => {
const { userId } = input;
const [usersStore] = eventStores;

const { aggregate } = await usersStore.getAggregate(userId);

if (aggregate === undefined) {
throw new Error('User not found');
}

const { version, status } = aggregate;
if (status === UserStatus.REMOVED) {
throw new Error('User already removed');
}

await usersStore.pushEvent({
aggregateId: userId,
version: version + 1,
type: 'USER_REMOVED',
timestamp: new Date().toISOString(),
});
},
});
38 changes: 38 additions & 0 deletions demo/blueprint/src/commands/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { JSONSchemaCommand, tuple } from '@castore/event-store';

import { userEventStore, UserStatus } from 'users';

export const deleteUser = new JSONSchemaCommand({
commandId: 'DELETE_USER',
requiredEventStores: tuple(userEventStore),
inputSchema: {
type: 'object',
properties: {
userId: { type: 'string', format: 'uuid' },
},
required: ['userId'],
additionalProperties: false,
} as const,
handler: async (input, eventStores) => {
const { userId } = input;
const [usersStore] = eventStores;

const { aggregate } = await usersStore.getAggregate(userId);

if (aggregate === undefined) {
throw new Error('User not found');
}

const { version, status } = aggregate;
if (status === UserStatus.REMOVED) {
throw new Error('User already removed');
}

await usersStore.pushEvent({
aggregateId: userId,
version: version + 1,
type: 'USER_REMOVED',
timestamp: new Date().toISOString(),
});
},
});
2 changes: 2 additions & 0 deletions demo/blueprint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './counters';
export * from './users';
export { createUser } from './commands/createUser';
export { deleteUser } from './commands/deleteUser';
30 changes: 17 additions & 13 deletions demo/implementation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@
"license": "UNLICENSED",
"version": "0.3.91",
"scripts": {
"lint": "eslint '**/*.ts'",
"test-unit": "jest --maxWorkers=4 --passWithNoTests",
"test-type": "tsc --noEmit --emitDeclarationOnly false",
"test-coverage": "jest --maxWorkers=4 --passWithNoTests --coverage",
"test-circular": "yarn depcruise --validate dependency-cruiser.js .",
"deploy": "env-cmd sls deploy",
"deploy-function": "env-cmd sls deploy function -f",
"invoke-local": "env-cmd sls invoke local -f",
"lint-fix": "yarn linter-base-config --fix",
"lint-fix-all": "yarn lint-fix .",
"linter-base-config": "eslint --ext=js,ts .",
"log": "env-cmd sls logs -t -f",
"invoke-local": "env-cmd sls invoke local -f"
"test": "yarn test-linter && yarn test-type && yarn test-circular && yarn test-unit",
"test-circular": "yarn depcruise --validate dependency-cruiser.js .",
"test-linter": "yarn linter-base-config .",
"test-type": "tsc --noEmit --emitDeclarationOnly false",
"test-unit": "jest --maxWorkers=4 --passWithNoTests"
},
"dependencies": {
"@castore/demo-blueprint": "^0.3.91",
"@castore/event-store": "^0.3.91",
"@middy/core": "^3.0.4",
"@middy/validator": "^3.0.4",
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@serverless/typescript": "^3.0.0",
Expand All @@ -23,16 +33,10 @@
"dependency-cruiser": "^11.7.0",
"env-cmd": "^10.1.0",
"esbuild": "^0.14.13",
"eslint": "^8.14.0",
"json-schema-to-ts": "^2.5.3",
"serverless": "^3.1.0",
"serverless-esbuild": "^1.23.4",
"typescript": "^4.6.3"
},
"dependencies": {
"@castore/demo-blueprint": "^0.3.91",
"@castore/event-store": "^0.3.91",
"@middy/core": "^3.0.4",
"@middy/validator": "^3.0.4",
"source-map-support": "^0.5.19"
}
}
9 changes: 9 additions & 0 deletions demo/visualization/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const generateImportOrderRule = require('../../commonConfiguration/generateImportOrderRule');

module.exports = {
rules: generateImportOrderRule(__dirname),
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
};
2 changes: 2 additions & 0 deletions demo/visualization/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../.lintstagedrc');
module.exports = baseConfig;
25 changes: 25 additions & 0 deletions demo/visualization/config/checkEnvConsistency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { loadEnv } from 'vite';

const EXCLUDED_ENV_KEYS = ['VITE_USER_NODE_ENV'];

export const checkEnvConsistency = (mode: string): void => {
const env = loadEnv(mode, process.cwd());
const exampleEnv = loadEnv('example', process.cwd());

const envFilename = mode === 'development' ? '.env' : '.env.' + mode;
Object.keys(exampleEnv)
.filter(key => !EXCLUDED_ENV_KEYS.includes(key))
.forEach(key => {
if (!(key in env)) {
throw new Error(`${key} is not defined in ${envFilename}`);
}
});

Object.keys(env)
.filter(key => !EXCLUDED_ENV_KEYS.includes(key))
.forEach(key => {
if (!(key in exampleEnv)) {
throw new Error(`${key} is not defined in .env.example`);
}
});
};
11 changes: 11 additions & 0 deletions demo/visualization/config/getEnvWithProcessPrefix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { loadEnv } from 'vite';

// expose .env as process.env instead of import.meta since jest does not import meta yet
export const getEnvWithProcessPrefix = (mode: string): Record<string, string> =>
Object.entries(loadEnv(mode, process.cwd())).reduce(
(prev, [key, val]) => ({
...prev,
['process.env.' + key]: `"${val}"`,
}),
{},
);
2 changes: 2 additions & 0 deletions demo/visualization/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { checkEnvConsistency } from './checkEnvConsistency';
export { getEnvWithProcessPrefix } from './getEnvWithProcessPrefix';
3 changes: 3 additions & 0 deletions demo/visualization/dependency-cruiser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** @type {import('dependency-cruiser').IConfiguration} */
const baseConfig = require('../../dependency-cruiser');
module.exports = baseConfig;
18 changes: 18 additions & 0 deletions demo/visualization/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en" style="background-color: #efefef">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Castore</title>
<script>
if (global === undefined) {
var global = window;
}
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
82 changes: 82 additions & 0 deletions demo/visualization/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@castore/demo-visualization",
"scripts": {
"start": "vite",
"lint-fix": "yarn linter-base-config --fix",
"lint-fix-all": "yarn lint-fix .",
"linter-base-config": "eslint --ext=js,ts .",
"test": "yarn test-linter && yarn test-type && yarn test-circular && yarn test-unit",
"test-circular": "yarn depcruise --validate dependency-cruiser.js .",
"test-linter": "yarn linter-base-config .",
"test-type": "tsc --noEmit --emitDeclarationOnly false",
"test-unit": "jest --maxWorkers=4 --passWithNoTests --watchAll=false"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@castore/demo-blueprint": "^0.3.91",
"@castore/event-store": "^0.3.91",
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@mui/icons-material": "^5.6.2",
"@mui/lab": "^5.0.0-alpha.79",
"@mui/material": "^5.6.3",
"@mui/system": "^5.6.3",
"@rjsf/core": "^4.2.0",
"@rjsf/material-ui": "^4.2.0",
"@types/http-errors": "^1.8.2",
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"date-fns": "^2.28.0",
"file-saver": "^2.0.5",
"http-errors": "^2.0.0",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-json-view": "^1.21.3",
"react-scripts": "5.0.0",
"react-use": "^17.3.2",
"ts-toolbelt": "^9.6.0",
"uuid": "^8.3.2",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@types/file-saver": "^2.0.5",
"@types/lodash": "^4.14.178",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"@types/uuid": "^8.3.4",
"@vitejs/plugin-react": "^1.3.2",
"dependency-cruiser": "^11.7.0",
"eslint": "^8.14.0",
"json-schema-to-ts": "^2.5.3",
"rollup-plugin-visualizer": "^5.6.0",
"typescript": "^4.5.5",
"vite": "^2.9.12",
"vite-plugin-style-import": "^2.0.0",
"vite-plugin-svgr": "^2.1.0",
"vite-tsconfig-paths": "^3.5.0"
},
"peerDependencies": {
"@castore/demo-blueprint": "^0.3.91",
"@castore/event-store": "^0.3.91"
},
"eslintConfig": {
"extends": [
"react-app"
]
}
}
6 changes: 6 additions & 0 deletions demo/visualization/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"root": "demo/visualization",
"projectType": "application",
"tags": [],
"implicitDependencies": []
}
Binary file added demo/visualization/public/favicon.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions demo/visualization/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Loading

0 comments on commit 398a6f3

Please sign in to comment.