npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@artinet/metadata-validator

v0.0.3

Published

a tool to validate metadata

Readme

@artinet/metadata-validator

A TypeScript library for validating Artinet service registration metadata against the official JSON schema.

This validator ensures that metadata provided during service registration conforms to the expected structure, formats, and constraints defined by the Artinet protocol.

Features

  • Validates metadata against the current Artinet registration JSON schema.
  • Provides clear error messages for validation failures.
  • Supports validation of both plain JavaScript objects and JSON strings.
  • Exports the underlying JSON schema and a generated Zod schema for advanced use cases.
  • Written in TypeScript with type definitions included.

Installation

npm install @artinet/metadata-validator
# or
yarn add @artinet/metadata-validator

Usage

import { MetadataValidator } from "@artinet/metadata-validator";
import type { IRegistration } from "@artinet/metadata-validator"; // Optional: For type safety

// 1. Create an instance of the validator
const validator = new MetadataValidator();

// 2. Define your metadata object (or load from a file/API)
const serviceMetadata: IRegistration = {
    // ... your registration metadata fields ...
    schemaVersion: "1.0.0",
    serviceName: "My Example Service",
    description: "This service does amazing things.",
    version: "1.0.1",
    capabilities: ["data-analysis", "ml-inference"],
    communication: {
        endpoints: [{ url: "https://api.example.com/service" }]
    },
    publicKey: {
        kty: "RSA",
        n: "...", // RSA modulus
        e: "AQAB" // RSA public exponent
    },
    contact: {
        email: "[email protected]"
    }
    // ... other fields as needed ...
};

// 3. Validate the metadata
const result = validator.validateMetadata(serviceMetadata);

// 4. Check the result
if (result.isValid) {
    console.log("Metadata is valid!");
    // result.serviceName and result.tags are available on success
    console.log("Service Name (lowercase):", result.serviceName);
    console.log("Extracted Tags:", result.tags);
} else {
    console.error("Metadata is invalid:");
    // Use formatErrors for user-friendly output
    const formattedErrors = validator.formatErrors(result.errors);
    formattedErrors.forEach(err => console.error(`- ${err}`));
    // Raw errors are also available:
    // console.error("Raw errors:", result.errors);
}

// You can also validate a JSON string directly:
const jsonMetadata = JSON.stringify(serviceMetadata);
const resultFromString = validator.validateMetadata(jsonMetadata);
console.log("Validation result from string:", resultFromString.isValid);

Validation Result (IResult)

The validateMetadata method returns an object conforming to the IResult interface:

interface IResult {
    isValid: boolean;
    errors: ErrorObject[]; // Array of Ajv error objects if invalid
    serviceName?: string; // Lowercase service name if valid
    tags?: string[];      // Extracted tags (serviceName, capabilities, tags) if valid
}

Exported Schemas

For advanced integration or inspection, the package also exports:

  • schema: The raw JSON schema object used for validation.
  • zodRegistrationSchema: A Zod schema object generated from the JSON schema, useful for runtime parsing and type inference with Zod.
import { schema, zodRegistrationSchema } from "@artinet/metadata-validator";

console.log("Raw JSON Schema:", schema);
// Use zodRegistrationSchema with Zod:
// const parsed = zodRegistrationSchema.safeParse(someData);

Development

  1. Clone the repository.
  2. Navigate to this package directory: cd modules/tools/metadata-validator
  3. Install dependencies: npm install
  4. Build: npm run build
  5. Run tests: npm test

Contributing

Contributions are welcome! Please follow standard Git practices (fork, feature branch, pull request). Ensure tests pass (npm test) before submitting a PR.

License

MIT