This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from theodo/feat/import-event-store-visualizat…
…ion-code feature: import event store visualization code
- Loading branch information
Showing
50 changed files
with
9,987 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const baseConfig = require('../../.lintstagedrc'); | ||
module.exports = baseConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"`, | ||
}), | ||
{}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { checkEnvConsistency } from './checkEnvConsistency'; | ||
export { getEnvWithProcessPrefix } from './getEnvWithProcessPrefix'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"root": "demo/visualization", | ||
"projectType": "application", | ||
"tags": [], | ||
"implicitDependencies": [] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.