add readme and comments about shared dir

This commit is contained in:
arttu
2024-12-08 16:03:24 +02:00
parent 790fb4a7e1
commit 22ac1c4021
5 changed files with 16 additions and 7 deletions
+10
View File
@@ -0,0 +1,10 @@
### Shared directory
This directory contains code and types that is used by both frontend and backend. It is subject to some limitations. In files under this directory, you cannot:
- Use path aliases in imports: instead of `import ... from @/shared/...` use relative path `../types/`
- Import files from elsewhere in frontend into this directory
This is because backend code does not have frontend's path aliases defined, and the code from backend does not get access to any other files in frontend than this directory.
Check [validator readme](./validators/README.md) in it's own directory.
+2
View File
@@ -1,3 +1,5 @@
/* For types that describe data */
import * as Prisma from '../../../../backend/prisma/generated/now_test_client/default'
import * as LogPrisma from '../../../../backend/prisma/generated/now_log_test_client/default'
import { Editable, FixBigInt, RowState } from './util'
+2
View File
@@ -1,3 +1,5 @@
/* Misc types that are more miscellaneous or general than data-folder */
export enum Role {
Admin = 1,
EditUnrestricted = 2,
+2
View File
@@ -1,3 +1,5 @@
/* Util-types - generics or otherwise used for type-technical things */
/* This makes all fields optional, except for array-type fields.
Also wraps the objects inside arrays as Editable, adding rowState-field in them.
Applies itself recursively to all nested objects even inside arrays. */
-7
View File
@@ -33,10 +33,3 @@ To know if user is creating a new entry or editing existing one, check if the id
At the moment you can only create validators for existing and defined fields of editData. This is limiting in some cases and creating validators that check multiple fields (as is necessary in references) requires some trickery. Similarly you cannot create multiple validators for the same field.
Validators are only run if the data is defined! If the value of a key of editData == undefined, the data is not checked even if it is set as required in the validator. Similarly if a key does not exist in editData, it will not be checked even if the data would be required. This is also the case in backend. This may lead to mistakes getting into the db if some data must be set but it is not defined at all.
The files in this folder, and also backendTypes.d.ts, cannot
- Use path aliases in imports
- Import files from elsewhere in frontend
Because these files are used also by backend, and backend container only gets access to these files in frontend.