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

zotero-schema-types

v2.0.1

Published

Zod schemas and TypeScript types generated from the official Zotero schema

Downloads

8

Readme

zotero-schema-types

The foundational package that ingests the official Zotero schema.json to generate and export Zod schemas and derived TypeScript types for the entire Zotero AI Translator Suite.

Features

  • Schema-driven development: Automatically generates types from Zotero's official schema
  • Type safety: Comprehensive TypeScript interfaces for all Zotero item types
  • Runtime validation: Zod schemas for validating data at runtime
  • Automatic updates: Fetches the latest schema from Zotero API with local caching
  • Item-specific types: Generates precise types for each Zotero item type (books, articles, etc.)

Installation

npm install zotero-schema-types

Usage

Basic Usage

import {
  ZoteroItemSchema,
  ZoteroBookItemSchema,
  ZoteroItem,
  ZoteroBookItem,
} from 'zotero-schema-types';

// Validate a Zotero item
const item: ZoteroItem = {
  data: {
    itemType: 'book',
    title: 'The Great Gatsby',
    // ... other properties
  },
};

const result = ZoteroItemSchema.safeParse(item);
if (result.success) {
  console.log('Valid item:', result.data);
} else {
  console.error('Invalid item:', result.error);
}

Advanced Usage

import {
  ZoteroSchemaProcessor,
  getItemTypeNames,
  getCreatorTypesForItem,
} from 'zotero-schema-types';

// Process schema and generate fresh types
const processor = new ZoteroSchemaProcessor();
await processor.processSchema();

// Use utility functions
const schema = await new SchemaFetcher().fetchSchema();
const itemTypes = getItemTypeNames(schema);
const creatorTypes = getCreatorTypesForItem(schema, 'book');

Development

Generate Types

Generate types from the latest Zotero schema:

npm run generate

Build

npm run build

Test

npm test

Architecture

The package is structured as follows:

  • src/utils/: Schema fetching and utility functions
  • src/generators/: Type and schema generation logic
  • src/types/: Generated TypeScript types (auto-generated)
  • src/schemas/: Generated Zod schemas (auto-generated)
  • scripts/: Build and generation scripts

Generated Types

The package generates the following types:

Base Types

  • ZoteroItem - Base item interface
  • ZoteroItemData - Item data structure
  • ZoteroCreator - Creator/author information
  • ZoteroTag - Tag information
  • ZoteroCollection - Collection structure
  • ZoteroSearch - Search queries
  • ZoteroLibrary - Library information

Item-Specific Types

  • ZoteroBookItem - Book items
  • ZoteroArticleItem - Journal articles
  • ZoteroWebsiteItem - Web pages
  • ... and many more for each Zotero item type

Validation Schemas

  • ZoteroItemSchema - Base item validation
  • ZoteroBookItemSchema - Book-specific validation
  • ZoteroArticleItemSchema - Article-specific validation
  • ... corresponding schemas for each type

Schema Caching

The package automatically caches the Zotero schema locally to improve performance and provide offline capabilities. The cache is updated whenever the schema is fetched from the API.

API Reference

Classes

ZoteroSchemaProcessor

Main class for processing Zotero schema and generating types.

SchemaFetcher

Handles fetching and caching of Zotero schema.

TypeGenerator

Generates TypeScript interfaces from schema.

ZodGenerator

Generates Zod validation schemas from schema.

Utility Functions

getItemTypeNames(schema)

Returns array of all available item type names.

getCreatorTypesForItem(schema, itemType)

Returns creator types valid for a specific item type.

getFieldsForItem(schema, itemType)

Returns fields available for a specific item type.

isValidItemType(schema, itemType)

Validates if an item type exists in the schema.

License

MIT