This commit upgrades TypeScript to the latest version 5.3 and introduces `verbatimModuleSyntax` in line with the official Vue guide recommendatinos (vuejs/docs#2592). By enforcing `import type` for type-only imports, this commit improves code clarity and supports tooling optimization, ensuring imports are only bundled when necessary for runtime. Changes: - Bump TypeScript to 5.3.3 across the project. - Adjust import statements to utilize `import type` where applicable, promoting cleaner and more efficient code.
40 lines
1023 B
TypeScript
40 lines
1023 B
TypeScript
import { isString } from '@/TypeHelpers';
|
|
import { type INodeDataErrorContext, NodeDataError } from './NodeDataError';
|
|
import type { NodeData } from './NodeData';
|
|
|
|
export class NodeValidator {
|
|
constructor(private readonly context: INodeDataErrorContext) {
|
|
|
|
}
|
|
|
|
public assertValidName(nameValue: string) {
|
|
return this
|
|
.assert(
|
|
() => Boolean(nameValue),
|
|
'missing name',
|
|
)
|
|
.assert(
|
|
() => isString(nameValue),
|
|
`Name (${JSON.stringify(nameValue)}) is not a string but ${typeof nameValue}.`,
|
|
);
|
|
}
|
|
|
|
public assertDefined(node: NodeData) {
|
|
return this.assert(
|
|
() => node !== undefined && node !== null && Object.keys(node).length > 0,
|
|
'missing node data',
|
|
);
|
|
}
|
|
|
|
public assert(validationPredicate: () => boolean, errorMessage: string) {
|
|
if (!validationPredicate()) {
|
|
this.throw(errorMessage);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public throw(errorMessage: string): never {
|
|
throw new NodeDataError(errorMessage, this.context);
|
|
}
|
|
}
|