Skip to content

Commit

Permalink
✨ [feat]: Repair documentation generation and fix config for vite
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Jan 12, 2024
1 parent 10be023 commit 368aa11
Show file tree
Hide file tree
Showing 709 changed files with 8,255 additions and 7,135 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"es2021": true,
"node": true
},
"extends": "standard-with-typescript",
"extends": ["standard-with-typescript", "plugin:import/typescript"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
Expand All @@ -24,6 +24,13 @@
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-proto": "off",
"valid-typeof": "off"
"valid-typeof": "off",
"import/no-cycle": [
"error",
{
"maxDepth": 10,
"ignoreExternal": true
}
]
}
}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"arrowParens": "avoid",
"jsxSingleQuote": false,
"printWidth": 100,
"printWidth": 120,
"semi": true,
"singleQuote": false,
"tabWidth": 2
Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
"version": "1.0.0",
"description": "TypeScript form validation using Decorators",
"license": "MIT",
"workspaces": [
"packages/*"
],
"scripts": {
"lint": "eslint 'packages/*/src/**/*.ts' --fix",
"clean": "rm -rf docs dist packages/core/dist packages/react/dist",
"build": "tsc --build",
"typedoc": "typedoc",
"docs": "bash scripts/generate-docs.sh",
"core/test": "npm run test --prefix=packages/core",
"core/build": "npm run build --prefix=packages/core",
Expand All @@ -21,20 +25,17 @@
"react/deploy:patch": "npm run deploy:patch --prefix=packages/react",
"react/test": "npm run test --prefix=packages/react",
"react/build": "npm run build --prefix=packages/react",
"react/build:noTest": "npm run build:noTest --prefix=packages/react",
"pushAll": "git add . && bash scripts/commit.sh --group=chore --message=\"Automated commit\" && git push"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint"
}
},
"devDependencies": {
"@mxssfd/typedoc-theme": "^1.1.3",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"eslint": "^8.51.0",
"circular-dependency-plugin": "^5.2.2",
"eslint": "^8.56.0",
"eslint-config-standard-with-typescript": "^39.1.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -44,10 +45,8 @@
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.8",
"typedoc": "^0.25.1",
"typescript": "^5.2.2"
},
"workspaces": [
"packages/*"
]
}
}
131 changes: 15 additions & 116 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,120 +1,19 @@
import * as Decorators from "./src/decorators";
import {
createClassDecorator,
createClassValidator,
createFieldDecorator,
createFieldValidator,
} from "./src/decorators";
import { attribute } from "./src/decorators/data/structural/attribute";
import TdvCoreApi from "./src/index";
import * as Localization from "./src/localization";
import * as Reflection from "./src/reflection";
import * as Strategy from "./src/strategy";
import * as Utilities from "./src/utilities";
import * as Validation from "./src/validation";
import { Form } from "./src/validation/models/Form";
import * as Decorators from "@decorators";
import * as Localization from "@localization";
import * as Reflection from "@reflection";
import * as Strategy from "@strategy";
import * as Utilities from "@utilities";
import * as Validation from "@validation";

export { Decorators, Localization, Reflection, Strategy, Utilities, Validation };

export import PrimitiveSet = Utilities.PrimitiveSet;
export import createClassDecorator = Decorators.createClassDecorator;
export import createClassValidator = Decorators.createClassValidator;
export import createFieldDecorator = Decorators.createFieldDecorator;
export import createFieldValidator = Decorators.createFieldValidator;
export import Form = Validation.Form;
export import attribute = Decorators.attribute;
export import Class = Utilities.Types.Class;
export import UnwrapClass = Utilities.Types.UnwrapClass;
export import ValidationResult = Validation.ValidationResult;

export {
Form,
attribute,
createClassDecorator,
createClassValidator,
createFieldDecorator,
createFieldValidator,
};

export { Decorators, Localization, Reflection, Strategy, Utilities, Validation };

/**
* An overridable interface designed for disabling nested validation on custom object types.
* - when specified ***(example 1)***: an object type is considered primitive and it's simplified errors render as `string[]`
* - when not specified ***(example 2)***: an object type is considered as is and it's simplified errors are evaluated by {@link Strategy.Impl.Errors evaluate<T, string[]>})
*
* @example
* 1: Disabling nested form validation for `Coordinate` class by augmenting the `PrimitiveSet` interface from `tdv-core`. This is a way of treating custom object types as primitives and avoiding recursive field validation
* ```ts
* // coordinate.ts - model class which is considered primitive
* export class Coordinate {
* x: number;
* y: number;
* }
* ```
*
* <div style="height: 1rem"></div>
*
* ```ts
* // index.ts - entry point of the app
* declare module "tdv-core" {
* interface PrimitiveSet {
* // Specify object types as primitives here
* values: [Coordinate];
* }
* }
* ```
*
* <div style="height: 1rem"></div>
*
* ```ts
* // consumer.ts - model class which holds Coordinate property
* import { createFieldValidator } from "tdv-core";
*
* // custom Coordinate validator
* function MinX(minX: number) {
* return createFieldValidator<Coordinate>(coordinate => ({
* key: "MinX",
* valid: coordinate.x >= minX,
* message: `Minimum X is ${minX}`
* }))
* }
*
* // Coordinate class definition
* class Consumer {
* \@MinX(10)
* coordinate: Coordinate; // primitive, doesn't validate recursively
* }
*
* const engine = new ValidationEngine(Consumer);
* const payload = { coordinate: { x: 9, y: 23 } };
* const { errors } = engine.validate(payload);
* const coordinateErrors = errors.coordinate;
* console.log(coordinateErrors); // ["Minimum X is 10"]
* ```
*
* @example
* 2: Default behavior - nested field validation is enabled for `Coordinate` class. It uses `\@attribute` for supplying validation engine with the runtime schema representation of the decorated field (if \@attribute is not defined then a type mismatch occurs between runtime type and compiled type)
* ```ts
* // coordinate.ts
* import { collection } from "tdv-core";
*
* export class Coordinate {
* \@collection.number.ValueMin(10, { message: "Minimum X is 10" })
* x: number;
* y: number;
* }
* ```
*
* <div style="height: 1rem"></div>
*
* ```ts
* // consumer.ts - model class which holds Coordinate property
* import { attribute, Localization, Form, Utilities } from "tdv-core";
*
* class Consumer {
* \@attribute(Coordinate) // enables deep validation
* coordinate: Coordinate; // non-primitive
* }
*
* const engine = new ValidationEngine(Consumer);
* const payload = { coordinate: { x: 9, y: 23 } };
* const { errors } = engine.validate(payload);
* const coordinateErrors = errors.coordinate;
* console.log(coordinateErrors); // { root: [], data: { x: ["Minimum X is 10"], y: [] } }
* ```
*/
export interface PrimitiveSet {}

export default TdvCoreApi;
Loading

0 comments on commit 368aa11

Please sign in to comment.