nikku / node-xsd-schema-validator

A schema (XSD) validator for NodeJS
https://www.npmjs.com/package/xsd-schema-validator
MIT License
51 stars 24 forks source link

Publish the new types + a suggestion to export result type seperately #41

Closed baskager closed 6 months ago

baskager commented 7 months ago

What should we do?

The new types are not yet available in the latest version on npmjs.com. Additionally I would like to add the suggestion of providing a separate type for the result object. In our project we have done the following:

declare module "xsd-schema-validator" {
    export function validateXML(
        // Type comes straight from the package, so not going to fix this linter warning.
        // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
        xml: string | ReadableStream | { file: string },
        pathToXsd: string
    ): Promise<xmlSchemaValidatorResult>;

    export type xmlSchemaValidatorResult = {
        valid: boolean;
        result: string;
        messages: string[];
    };
}

Let me know if I should create a PR for this and if you agree with the naming conventions etc.

Why should we do it?

Point one: The latest "@types/xml-schema-validator" package contains types for older versions, this breaks updating to post v0.8, of which the latest version does not yet supply its own types

Point two: A separate result type is a bit cleaner when writing TypeScript on "strict" settings, e.g:

const result: xmlSchemaValidatorResult = await validator.validateXML(xml, xsdFilePath);

Thank you :1st_place_medal:

nikku commented 7 months ago

I have not tested the types extensively yet, and hence did not get to a release. Happy to take a PR to improve the types.

I'll want to verify that the types work locally as well using the typescript compiler (cf. https://github.com/bpmn-io/min-dash/blob/main/tsconfig.json or others).

baskager commented 6 months ago

Have been able to validate that the type declaration above works in our use case, bit busy mixing work with taking care of my dad (recently had a severe stroke) so will create the PR in between everything, might need a reminder though given the situation.

Thanks!

nikku commented 6 months ago

Released with v0.9.0

baskager commented 6 months ago

Hi, completely forgot about this. Thanks for merging it in! :)