mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
feat: add schemas and utility functions for return processing; update styles and component structure
This commit is contained in:
7
libs/common/result/README.md
Normal file
7
libs/common/result/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# common-result
|
||||
|
||||
This library was generated with [Nx](https://nx.dev).
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `nx test common-result` to execute the unit tests.
|
||||
34
libs/common/result/eslint.config.mjs
Normal file
34
libs/common/result/eslint.config.mjs
Normal file
@@ -0,0 +1,34 @@
|
||||
import nx from '@nx/eslint-plugin';
|
||||
import baseConfig from '../../../eslint.config.mjs';
|
||||
|
||||
export default [
|
||||
...baseConfig,
|
||||
...nx.configs['flat/angular'],
|
||||
...nx.configs['flat/angular-template'],
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
rules: {
|
||||
'@angular-eslint/directive-selector': [
|
||||
'error',
|
||||
{
|
||||
type: 'attribute',
|
||||
prefix: 'lib',
|
||||
style: 'camelCase',
|
||||
},
|
||||
],
|
||||
'@angular-eslint/component-selector': [
|
||||
'error',
|
||||
{
|
||||
type: 'element',
|
||||
prefix: 'lib',
|
||||
style: 'kebab-case',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.html'],
|
||||
// Override or add rules here
|
||||
rules: {},
|
||||
},
|
||||
];
|
||||
21
libs/common/result/jest.config.ts
Normal file
21
libs/common/result/jest.config.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export default {
|
||||
displayName: 'common-result',
|
||||
preset: '../../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
coverageDirectory: '../../../coverage/libs/common/result',
|
||||
transform: {
|
||||
'^.+\\.(ts|mjs|js|html)$': [
|
||||
'jest-preset-angular',
|
||||
{
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||
},
|
||||
],
|
||||
},
|
||||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
||||
snapshotSerializers: [
|
||||
'jest-preset-angular/build/serializers/no-ng-attributes',
|
||||
'jest-preset-angular/build/serializers/ng-snapshot',
|
||||
'jest-preset-angular/build/serializers/html-comment',
|
||||
],
|
||||
};
|
||||
20
libs/common/result/project.json
Normal file
20
libs/common/result/project.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "common-result",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "libs/common/result/src",
|
||||
"prefix": "lib",
|
||||
"projectType": "library",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/common/result/jest.config.ts"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
}
|
||||
}
|
||||
}
|
||||
3
libs/common/result/src/index.ts
Normal file
3
libs/common/result/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './lib/response-args.schema';
|
||||
export * from './lib/entity-container.schema';
|
||||
export * from './lib/result';
|
||||
15
libs/common/result/src/lib/entity-container.schema.ts
Normal file
15
libs/common/result/src/lib/entity-container.schema.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const EntityContainerSchema = z.object({
|
||||
id: z.number(),
|
||||
uId: z.string(),
|
||||
displayLabel: z.string(),
|
||||
enabled: z.boolean(),
|
||||
selected: z.boolean(),
|
||||
});
|
||||
|
||||
export function entityContainerSchema<T>(data: z.ZodType<T>) {
|
||||
return EntityContainerSchema.extend({
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
25
libs/common/result/src/lib/response-args.schema.ts
Normal file
25
libs/common/result/src/lib/response-args.schema.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ResponseArgsSchema = z.object({
|
||||
error: z.boolean(),
|
||||
invalidProperties: z.record(z.string()),
|
||||
message: z.string().optional(),
|
||||
});
|
||||
|
||||
export function ResponseArgs<T>(resultSchema: z.ZodType<T>) {
|
||||
return ResponseArgsSchema.extend({
|
||||
result: resultSchema,
|
||||
});
|
||||
}
|
||||
|
||||
const ListResponseArgsSchema = ResponseArgsSchema.extend({
|
||||
skip: z.number(),
|
||||
take: z.number(),
|
||||
hits: z.number(),
|
||||
});
|
||||
|
||||
export function ListResponseArgs<T>(resultSchema: z.ZodType<T>) {
|
||||
return ListResponseArgsSchema.extend({
|
||||
result: resultSchema.array(),
|
||||
});
|
||||
}
|
||||
14
libs/common/result/src/lib/result.ts
Normal file
14
libs/common/result/src/lib/result.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const ResultStatus = {
|
||||
Idle: 'idle',
|
||||
Pending: 'pending',
|
||||
Success: 'success',
|
||||
Error: 'error',
|
||||
} as const;
|
||||
|
||||
export type ResultStatus = (typeof ResultStatus)[keyof typeof ResultStatus];
|
||||
|
||||
export interface Result<T> {
|
||||
status: ResultStatus;
|
||||
data: T;
|
||||
error?: unknown;
|
||||
}
|
||||
6
libs/common/result/src/test-setup.ts
Normal file
6
libs/common/result/src/test-setup.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
|
||||
|
||||
setupZoneTestEnv({
|
||||
errorOnUnknownElements: true,
|
||||
errorOnUnknownProperties: true,
|
||||
});
|
||||
28
libs/common/result/tsconfig.json
Normal file
28
libs/common/result/tsconfig.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
17
libs/common/result/tsconfig.lib.json
Normal file
17
libs/common/result/tsconfig.lib.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"inlineSources": true,
|
||||
"types": []
|
||||
},
|
||||
"exclude": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/test-setup.ts",
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts"
|
||||
],
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
16
libs/common/result/tsconfig.spec.json
Normal file
16
libs/common/result/tsconfig.spec.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"target": "es2016",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": [
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts",
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user