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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@famgia/omnify-core

v0.0.79

Published

Core engine for omnify-schema

Readme

@famgia/omnify-core

Core engine for the Omnify schema system. Provides schema loading, validation, plugin management, and generator execution.

Installation

npm install @famgia/omnify-core

Usage

Load and Validate Schemas

import { loadSchemas, validateSchemas } from '@famgia/omnify-core';

// Load schemas from directory
const schemas = await loadSchemas('./schemas');

// Validate schemas
const result = validateSchemas(schemas);

if (!result.valid) {
  for (const error of result.errors) {
    console.error(`${error.schemaName}: ${error.message}`);
  }
}

Plugin Manager

import { PluginManager } from '@famgia/omnify-core';
import type { OmnifyPlugin } from '@famgia/omnify-types';

const manager = new PluginManager({
  cwd: process.cwd(),
  verbose: true,
  logger: console,
});

// Register a plugin
await manager.register(myPlugin);

// Get all registered custom types
const customTypes = manager.getCustomTypes();

// Run all generators
const result = await manager.runGenerators(schemas);

if (result.success) {
  for (const output of result.outputs) {
    console.log(`Generated: ${output.path}`);
  }
}

Generator Runner (DAG-based)

import { GeneratorRunner } from '@famgia/omnify-core';

const runner = new GeneratorRunner({
  cwd: process.cwd(),
  verbose: true,
  logger: console,
});

// Register generators (automatically sorts by dependencies)
runner.registerAll([
  {
    definition: schemaGenerator,
    pluginName: 'my-plugin',
    pluginConfig: {},
  },
  {
    definition: migrationGenerator,
    pluginName: 'my-plugin',
    pluginConfig: {},
  },
]);

// Execute in topological order
const result = await runner.runAll(schemas);

Error Handling

import { OmnifyError } from '@famgia/omnify-core';

try {
  await loadSchemas('./invalid-path');
} catch (error) {
  if (error instanceof OmnifyError) {
    console.error(`[${error.code}] ${error.message}`);
    if (error.schemaName) {
      console.error(`  Schema: ${error.schemaName}`);
    }
    if (error.suggestion) {
      console.error(`  Suggestion: ${error.suggestion}`);
    }
  }
}

API Reference

Functions

| Function | Description | |----------|-------------| | loadSchemas(path) | Load all YAML/JSON schema files from directory | | loadSchema(filePath) | Load a single schema file | | validateSchemas(schemas) | Validate schema collection | | validateSchema(schema) | Validate a single schema |

Classes

PluginManager

Manages plugin registration and generator execution.

new PluginManager(options: PluginManagerOptions)

interface PluginManagerOptions {
  cwd: string;
  verbose?: boolean;
  logger?: PluginLogger;
}

Methods:

  • register(plugin) - Register a plugin
  • getPlugin(name) - Get plugin by name
  • getCustomTypes() - Get all custom types
  • hasCustomType(name) - Check if custom type exists
  • getGenerators() - Get all registered generators
  • runGenerators(schemas) - Execute all generators

GeneratorRunner

Executes generators in dependency order using topological sort.

new GeneratorRunner(options: GeneratorRunnerOptions)

Methods:

  • register(generator) - Register a single generator
  • registerAll(generators) - Register multiple generators
  • runAll(schemas) - Execute all generators in order
  • getOrder() - Get execution order (for debugging)

OmnifyError

Custom error class with detailed error information.

class OmnifyError extends Error {
  code: string;
  schemaName?: string;
  propertyName?: string;
  filePath?: string;
  suggestion?: string;
}

Plugin System

Creating a Plugin

import type { OmnifyPlugin } from '@famgia/omnify-types';

const myPlugin: OmnifyPlugin = {
  name: 'my-plugin',
  version: '1.0.0',

  // Lifecycle hooks
  setup: async (context) => {
    console.log('Plugin initialized');
  },

  teardown: async () => {
    console.log('Plugin cleanup');
  },

  // Custom types
  types: [
    {
      name: 'Money',
      typescript: 'number',
      laravel: 'decimal',
      laravelParams: [10, 2],
    },
  ],

  // Generators
  generators: [
    {
      name: 'my-generator',
      description: 'Generate custom files',
      dependsOn: ['other-generator'],

      generate: async (ctx) => {
        return [{
          path: 'output/file.ts',
          content: '// Generated',
          type: 'other',
        }];
      },
    },
  ],
};

Generator Dependencies

Generators can specify dependsOn to control execution order:

generators: [
  {
    name: 'schema-generator',
    generate: async (ctx) => { /* ... */ },
  },
  {
    name: 'migration-generator',
    dependsOn: ['schema-generator'], // Runs after schema-generator
    generate: async (ctx) => {
      // Access previous outputs
      const schemaOutputs = ctx.previousOutputs.get('schema-generator');
      // ...
    },
  },
]

The GeneratorRunner uses Kahn's algorithm for topological sorting and detects circular dependencies.

Validation Rules

The validator checks for:

  • Valid schema structure (name, kind, properties)
  • Valid property types (built-in or custom)
  • Valid association types and references
  • Unique property names
  • Required fields presence
  • Circular reference detection

Related Packages

License

MIT