glossarist 0.4.44 → 0.4.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glossarist",
3
- "version": "0.4.44",
3
+ "version": "0.4.45",
4
4
  "description": "JavaScript SDK for Glossarist GCR packages — read, write, validate, and manage terminology concepts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,16 +1,19 @@
1
- // @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
2
1
  export class ValidationError {
3
- constructor(path, message, severity = 'error') {
2
+ readonly path: string;
3
+ readonly message: string;
4
+ readonly severity: 'error' | 'warning';
5
+
6
+ constructor(path: string, message: string, severity: 'error' | 'warning' = 'error') {
4
7
  this.path = path;
5
8
  this.message = message;
6
9
  this.severity = severity;
7
10
  }
8
11
 
9
- toString() {
12
+ toString(): string {
10
13
  return `[${this.severity.toUpperCase()}] ${this.path}: ${this.message}`;
11
14
  }
12
15
 
13
- toJSON() {
16
+ toJSON(): { path: string; message: string; severity: string } {
14
17
  return { path: this.path, message: this.message, severity: this.severity };
15
18
  }
16
19
  }
@@ -1,53 +1,52 @@
1
- // @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
2
1
  import { ValidationError } from './validation-error.js';
3
2
 
4
3
  export class ValidationResult {
5
- constructor() {
6
- this._issues = [];
7
- }
4
+ private readonly _issues: ValidationError[] = [];
5
+
6
+ constructor() {}
8
7
 
9
- get valid() {
8
+ get valid(): boolean {
10
9
  return this._issues.filter(e => e.severity === 'error').length === 0;
11
10
  }
12
11
 
13
- get errors() {
12
+ get errors(): ReadonlyArray<ValidationError> {
14
13
  return this._issues.filter(e => e.severity === 'error');
15
14
  }
16
15
 
17
- get warnings() {
16
+ get warnings(): ReadonlyArray<ValidationError> {
18
17
  return this._issues.filter(e => e.severity === 'warning');
19
18
  }
20
19
 
21
- addError(pathOrMessage, message) {
20
+ addError(path: string, message?: string): this {
22
21
  if (message === undefined) {
23
- this._issues.push(new ValidationError('', pathOrMessage, 'error'));
22
+ this._issues.push(new ValidationError('', path, 'error'));
24
23
  } else {
25
- this._issues.push(new ValidationError(pathOrMessage, message, 'error'));
24
+ this._issues.push(new ValidationError(path, message, 'error'));
26
25
  }
27
26
  return this;
28
27
  }
29
28
 
30
- addWarning(pathOrMessage, message) {
29
+ addWarning(path: string, message?: string): this {
31
30
  if (message === undefined) {
32
- this._issues.push(new ValidationError('', pathOrMessage, 'warning'));
31
+ this._issues.push(new ValidationError('', path, 'warning'));
33
32
  } else {
34
- this._issues.push(new ValidationError(pathOrMessage, message, 'warning'));
33
+ this._issues.push(new ValidationError(path, message, 'warning'));
35
34
  }
36
35
  return this;
37
36
  }
38
37
 
39
- merge(other) {
38
+ merge(other: ValidationResult): this {
40
39
  if (other instanceof ValidationResult) {
41
40
  for (const issue of other._issues) this._issues.push(issue);
42
41
  }
43
42
  return this;
44
43
  }
45
44
 
46
- toJSON() {
45
+ toJSON(): { valid: boolean; errors: unknown[]; warnings: unknown[] } {
47
46
  return {
48
47
  valid: this.valid,
49
- errors: this.errors.map(e => e.toJSON ? e.toJSON() : e),
50
- warnings: this.warnings.map(e => e.toJSON ? e.toJSON() : e),
48
+ errors: this.errors.map(e => typeof e.toJSON === 'function' ? e.toJSON() : e),
49
+ warnings: this.warnings.map(e => typeof e.toJSON === 'function' ? e.toJSON() : e),
51
50
  };
52
51
  }
53
52
  }
@@ -1,15 +1,17 @@
1
- // @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
2
- export class ValidationRule {
3
- constructor(name, severity = 'error') {
1
+ import type { ValidationResult } from './validation-result.js';
2
+
3
+ export abstract class ValidationRule {
4
+ readonly name: string;
5
+ readonly severity: 'error' | 'warning';
6
+
7
+ constructor(name: string, severity: 'error' | 'warning' = 'error') {
4
8
  this.name = name;
5
9
  this.severity = severity;
6
10
  }
7
11
 
8
- validate(_value, _path, _result) {
9
- throw new Error(`${this.constructor.name} must implement validate()`);
10
- }
12
+ abstract validate(concept: unknown, path: string, result: ValidationResult): void;
11
13
 
12
- addIssue(result, path, message) {
14
+ addIssue(result: ValidationResult, path: string, message: string): void {
13
15
  if (this.severity === 'warning') {
14
16
  result.addWarning(path, message);
15
17
  } else {