Skip to content

Commit ccce8b6

Browse files
added better value error messaging
1 parent cc19d18 commit ccce8b6

File tree

4 files changed

+73
-150
lines changed

4 files changed

+73
-150
lines changed

__tests__/Aggregate.spec.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,24 @@
3030
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33-
import {
34-
guard,
35-
} from '@cosmicmind/foundationjs'
36-
import {
37-
uuidv4,
38-
} from 'lib0/random'
3933
import {
4034
it,
4135
expect,
4236
describe,
4337
} from 'vitest'
38+
4439
import {
4540
string,
4641
} from 'yup'
4742

43+
import {
44+
uuidv4,
45+
} from 'lib0/random'
46+
47+
import {
48+
guard,
49+
} from '@cosmicmind/foundationjs'
50+
4851
import {
4952
Entity,
5053
Aggregate,
@@ -219,4 +222,4 @@ describe('Aggregate', () => {
219222
expect(a1.name).toBe('jonathan')
220223
expect(a1.version).toBe(version)
221224
})
222-
})
225+
})

eslint.config.js

Lines changed: 48 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,55 @@
1-
import eslintPlugin from '@typescript-eslint/eslint-plugin'
2-
import eslintParser from '@typescript-eslint/parser'
3-
import importPlugin from 'eslint-plugin-import'
1+
import eslint from "@eslint/js"
2+
import globals from "globals"
3+
import typescriptEslint from "typescript-eslint"
4+
import stylisticJsPlugin from "@stylistic/eslint-plugin-js"
45

5-
export default [
6+
export default typescriptEslint.config(
7+
{ ignores: ["**/*.d.ts", "**/coverage", "**/dist"] },
68
{
7-
files: [ '**/*.{js,ts}' ], // Apply to JavaScript and TypeScript files
8-
ignores: [ 'node_modules', 'dist' ], // Replace .eslintignore contents
9+
extends: [
10+
eslint.configs.recommended,
11+
...typescriptEslint.configs.recommended,
12+
],
13+
files: ["**/*.{ts}"],
914
languageOptions: {
10-
ecmaVersion: 2021,
11-
sourceType: 'module',
12-
parser: eslintParser,
13-
},
14-
plugins: {
15-
'@typescript-eslint': eslintPlugin,
16-
import: importPlugin,
17-
},
18-
settings: {
19-
'import/resolver': {
20-
typescript: {
21-
// Resolve using tsconfig.json
22-
project: './tsconfig.json',
23-
},
15+
ecmaVersion: "latest",
16+
sourceType: "module",
17+
globals: globals.browser,
18+
parserOptions: {
19+
parser: typescriptEslint.parser,
2420
},
2521
},
2622
rules: {
27-
'@typescript-eslint/no-inferrable-types': 'off',
28-
'@typescript-eslint/explicit-function-return-type': 'off',
29-
'@typescript-eslint/no-empty-interface': 'error',
30-
'@typescript-eslint/no-explicit-any': 'warn',
31-
'@typescript-eslint/explicit-module-boundary-types': 'error',
32-
'@typescript-eslint/no-unused-vars': [
33-
'error',
34-
{
35-
argsIgnorePattern: '^_',
36-
varsIgnorePattern: '^_',
37-
}
38-
],
39-
eqeqeq: 'error',
40-
camelcase: 'error',
41-
'no-console': 'error',
42-
'no-lonely-if': 'error',
43-
'comma-dangle': [
44-
'error',
45-
{
46-
arrays: 'never',
47-
objects: 'always-multiline',
48-
imports: 'always-multiline',
49-
exports: 'always-multiline',
50-
functions: 'never',
51-
}
52-
],
53-
indent: [ 'error', 4, { SwitchCase: 1 } ],
54-
'no-tabs': 'error',
55-
'object-curly-spacing': [ 'error', 'always' ],
56-
'array-bracket-spacing': [ 'error', 'always' ],
57-
curly: [ 'error', 'all' ],
58-
'template-curly-spacing': 'error',
59-
'no-trailing-spaces': 'error',
60-
'space-before-blocks': 'error',
61-
semi: [ 'error', 'never' ],
62-
quotes: [ 'error', 'single', { avoidEscape: true } ],
63-
'object-curly-newline': [
64-
'error',
65-
{
66-
multiline: true,
67-
minProperties: 2,
68-
consistent: true,
69-
}
70-
],
71-
'object-property-newline': [
72-
'error',
73-
{
74-
allowAllPropertiesOnSameLine: true,
75-
}
76-
],
77-
'object-shorthand': 'error',
78-
'no-param-reassign': [ 'error', { props: false } ],
79-
'no-extra-parens': 'error',
80-
'no-return-await': 'error',
81-
'no-self-compare': 'error',
82-
'no-template-curly-in-string': 'error',
83-
'no-throw-literal': 'error',
84-
'no-undef-init': 'error',
85-
'no-unmodified-loop-condition': 'error',
86-
'no-unneeded-ternary': 'error',
87-
'no-unreachable-loop': 'error',
88-
'no-unsafe-optional-chaining': 'error',
89-
'no-unused-expressions': 'error',
90-
'no-use-before-define': [
91-
'error',
92-
{
93-
functions: false, classes: true, variables: true,
94-
}
95-
],
96-
'no-useless-backreference': 'error',
97-
'no-useless-call': 'error',
98-
'no-useless-computed-key': 'error',
99-
'no-useless-concat': 'error',
100-
'no-useless-constructor': 'error',
101-
'no-useless-rename': 'error',
102-
'no-useless-return': 'error',
103-
'no-var': 'error',
104-
'nonblock-statement-body-position': 'error',
105-
'one-var-declaration-per-line': 'error',
106-
'prefer-arrow-callback': 'error',
107-
'prefer-const': 'error',
108-
'prefer-exponentiation-operator': 'error',
109-
'prefer-numeric-literals': 'error',
110-
'prefer-object-spread': 'error',
111-
'prefer-promise-reject-errors': 'error',
112-
'prefer-template': 'error',
113-
'prefer-rest-params': 'error',
114-
'rest-spread-spacing': 'error',
115-
'require-atomic-updates': 'error',
116-
'require-await': 'error',
117-
'import/order': [
118-
'error',
119-
{
120-
groups: [
121-
'builtin',
122-
'external',
123-
'internal',
124-
'parent',
125-
'sibling',
126-
'index'
127-
],
128-
alphabetize: {
129-
order: 'asc',
130-
caseInsensitive: true,
131-
},
132-
}
133-
],
23+
"@stylistic/js/semi": ["error", "never"],
24+
"@stylistic/js/block-spacing": ["error", "always"],
25+
"@stylistic/js/comma-dangle": ["error", {
26+
"arrays": "never",
27+
"objects": "always-multiline",
28+
"imports": "always-multiline",
29+
"exports": "always-multiline",
30+
"functions": "never",
31+
}],
32+
"@stylistic/js/indent": ["error", 4, { SwitchCase: 1 }],
33+
34+
// Spacing rules
35+
"@stylistic/js/object-curly-spacing": ["error", "always"],
36+
"@stylistic/js/array-bracket-spacing": ["error", "never"],
37+
"@stylistic/js/space-in-parens": ["error", "never"],
38+
"@stylistic/js/space-infix-ops": ["error"],
39+
40+
// Line rules
41+
"@stylistic/js/eol-last": ["error", "always"],
42+
"@stylistic/js/no-trailing-spaces": ["error"],
43+
"@stylistic/js/max-len": ["error", { "code": 255 }],
44+
45+
// Other formatting rules
46+
"@stylistic/js/quotes": ["error", "single"],
47+
"@stylistic/js/brace-style": ["error", "1tbs"],
48+
"@stylistic/js/arrow-spacing": ["error", { "before": true, "after": true }],
49+
"@stylistic/js/keyword-spacing": ["error", { "before": true, "after": true }],
50+
},
51+
plugins: {
52+
"@stylistic/js": stylisticJsPlugin, // Correct, explicit key-value entry.
13453
},
135-
}
136-
]
54+
},
55+
)

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cosmicmind/domainjs",
3-
"version": "0.0.1-rc-030725-4.1",
3+
"version": "0.0.1-rc-053125-4",
44
"description": "A domain-driven design framework for scalable systems.",
55
"keywords": [
66
"typescript",
@@ -22,9 +22,9 @@
2222
"access": "public"
2323
},
2424
"type": "module",
25-
"main": "dist/lib-cjs.cjs",
26-
"module": "dist/lib-es.js",
27-
"types": "dist/src/index.d.ts",
25+
"main": "./dist/lib-cjs.cjs",
26+
"module": "./dist/lib-es.js",
27+
"types": "./dist/src/index.d.ts",
2828
"exports": {
2929
".": {
3030
"import": "./dist/lib-es.js",
@@ -53,21 +53,21 @@
5353
"@cosmicmind/patternjs": "^0.0.1-rc-030725-3",
5454
"npm-run-all": "^4.1.5",
5555
"tslib": "^2.8.1",
56-
"typescript": "^5.8.2",
57-
"vite": "^6.2.1",
56+
"typescript": "^5.8.3",
57+
"vite": "^6.3.4",
5858
"vite-plugin-dts": "^4.5.3",
5959
"vitest": "^3.0.2"
6060
},
6161
"devDependencies": {
6262
"@microsoft/eslint-formatter-sarif": "^3.1.0",
63-
"@types/node": "^22.13.9",
64-
"@typescript-eslint/eslint-plugin": "^8.26.0",
65-
"@typescript-eslint/parser": "^8.26.0",
66-
"@vitest/coverage-v8": "^3.0.8",
67-
"eslint": "^9.21.0",
68-
"eslint-import-resolver-typescript": "^3.8.3",
63+
"@types/node": "^22.15.3",
64+
"@typescript-eslint/eslint-plugin": "^8.28.0",
65+
"@typescript-eslint/parser": "^8.28.0",
66+
"@vitest/coverage-v8": "^3.1.2",
67+
"eslint": "^9.26.0",
68+
"eslint-import-resolver-typescript": "^3.10.1",
6969
"eslint-plugin-import": "^2.31.0",
70-
"lib0": "^0.2.99",
70+
"lib0": "^0.2.105",
7171
"terser": "^5.39.0",
7272
"ts-node": "^10.9.2",
7373
"yup": "^1.6.1"

src/Value.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ function createValue<V extends Value<ValueTypeFor<V>>>(target: V, value: ValueTy
168168
const vo = new Proxy(target, createValueHandler(handler))
169169

170170
if (false === handler.validator?.(value, vo)) {
171-
throwErrorAndTrace(`${JSON.stringify(target)} is invalid: ${JSON.stringify(value)}`, handler)
171+
const className = target.constructor.name
172+
throwErrorAndTrace(`${className} is invalid: ${JSON.stringify(value)}`, handler)
172173
}
173174

174175
handler.created?.(vo)

0 commit comments

Comments
 (0)