feat: add schemas and utility functions for return processing; update styles and component structure

This commit is contained in:
Lorenz Hilpert
2025-03-12 16:13:47 +01:00
parent abce5f43e2
commit 5bba1dff8f
80 changed files with 1187 additions and 157 deletions

View 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.

View 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: {},
},
];

View 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',
],
};

View 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"
}
}
}

View File

@@ -0,0 +1,3 @@
export * from './lib/response-args.schema';
export * from './lib/entity-container.schema';
export * from './lib/result';

View 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,
});
}

View 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(),
});
}

View 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;
}

View File

@@ -0,0 +1,6 @@
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
setupZoneTestEnv({
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
});

View 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
}
}

View 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"]
}

View 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"
]
}