     1	/**
     2	 * @file Main entry point for the schema library.
     3	 * Assembles and exports the `createSchema` factory function and related utilities.
     4	 */
     5	
     6	import { Schema } from './Schema.js'
     7	import CorePlugin from './CorePlugin.js'
     8	
     9	/**
    10	 * @type {Object.<string, Function>}
    11	 * Stores all registered type handlers. This is now a directly managed object.
    12	 */
    13	const globalTypes = {}
    14	
    15	/**
    16	 * @type {Object.<string, Function>}
    17	 * Stores all registered validator handlers. This is now a directly managed object.
    18	 */
    19	const globalValidators = {}
    20	
    21	/**
    22	 * Registers a new type handler.
    23	 * @param {string} name - The name of the type (e.g., 'string', 'email').
    24	 * @param {Function} handler - The function to handle the type casting.
    25	 */
    26	export function addType (name, handler) {
    27	  if (typeof handler !== 'function') {
    28	    throw new Error(`Type handler for '${name}' must be a function.`)
    29	  }
    30	  globalTypes[name] = handler
    31	}
    32	
    33	/**
    34	 * Registers a new validator handler.
    35	 * @param {string} name - The name of the validator (e.g., 'min', 'required').
    36	 * @param {Function} handler - The function to handle the validation logic.
    37	 */
    38	export function addValidator (name, handler) {
    39	  if (typeof handler !== 'function') {
    40	    throw new Error(`Validator handler for '${name}' must be a function.`)
    41	  }
    42	  globalValidators[name] = handler
    43	}
    44	
    45	/**
    46	 * Installs a plugin by calling its `install` method.
    47	 * @param {{install: Function}} plugin - A plugin object with an `install` method.
    48	 * @returns {void}
    49	 */
    50	export function use (plugin) {
    51	  if (typeof plugin.install !== 'function') {
    52	    throw new Error('Plugin must have an install method.')
    53	  }
    54	  // Pass the addType and addValidator functions directly to the plugin
    55	  plugin.install({ addType, addValidator })
    56	}
    57	
    58	/**
    59	 * The main factory function for creating new schema instances.
    60	 * Each created schema will use the currently registered global types and validators.
    61	 * @param {object} structure - The schema definition object.
    62	 * @returns {import('./Schema').Schema} A new schema instance.
    63	 */
    64	const createSchema = (structure) => new Schema(structure, globalTypes, globalValidators)
    65	
    66	// Attach the registration methods directly to the factory function for convenience.
    67	// This maintains the existing public API from the original code.
    68	createSchema.addType = addType
    69	createSchema.addValidator = addValidator
    70	createSchema.use = use
    71	
    72	// Automatically install the core plugin to provide out-of-the-box functionality.
    73	createSchema.use(CorePlugin)
    74	
    75	// Export all functions as named exports
    76	export { createSchema }
    77	// export { createKnexTable, generateKnexMigration } from './createKnexTable.js';
