@cldmv/slothlet
Version:
Slothlet: Modular API Loader for Node.js. Lazy mode dynamically loads API modules and submodules only when accessed, supporting both lazy and eager loading.
73 lines (68 loc) • 2.97 kB
JavaScript
/**
* @Project: @cldmv/slothlet
* @Filename: /index.cjs
* @Date: 2025-11-09 11:15:17 -08:00 (1762715717)
* @Author: Nate Hyson <CLDMV>
* @Email: <Shinrai@users.noreply.github.com>
* -----
* @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
* @Last modified time: 2025-11-09 14:43:17 -08:00 (1762728197)
* -----
* @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
*/
/**
* @fileoverview CommonJS entry point for @cldmv/slothlet - imports ESM implementation for single source of truth.
* @module @cldmv/slothlet
*/
/**
* CommonJS entry that dynamically imports the ESM implementation.
* This ensures single source of truth in index.mjs while maintaining CJS compatibility.
* Eliminates code duplication between entry points and ensures consistent behavior.
* @public
* @async
* @param {object} [options={}] - Configuration options for the slothlet instance
* @param {string} [options.dir="api"] - Directory to load API modules from
* @param {boolean} [options.lazy=false] - Use lazy loading (true) or eager loading (false)
* @param {number} [options.apiDepth=Infinity] - Maximum directory depth to scan
* @param {boolean} [options.debug=false] - Enable debug logging
* @param {string} [options.mode="singleton"] - Execution mode (singleton, vm, worker, fork)
* @param {string} [options.api_mode="auto"] - API structure mode (auto, function, object)
* @param {string} [options.runtime] - Runtime type ("async", "asynclocalstorage", "live", "livebindings", "experimental")
* @param {object} [options.context={}] - Context data for live bindings
* @param {object} [options.reference={}] - Reference objects to merge into API root
* @returns {Promise<function|object>} The bound API object with live-binding context
*
* @example // CJS usage
* const slothlet = require("@cldmv/slothlet");
* const api = await slothlet({ dir: "./api", context: { user: "alice" } });
* console.log(api.config.username); // Access configuration
*
* @example // CJS usage with runtime selection
* const slothlet = require("@cldmv/slothlet");
* const api = await slothlet({ dir: "./api", runtime: "live" });
*
* @example // CJS named destructuring
* const { slothlet } = require("@cldmv/slothlet");
* const api = await slothlet({ dir: "./api" });
*/
async function slothlet(options = {}) {
// Dynamic import of ESM entry point - single source of truth
const { default: esmSlothlet } = await import("./index.mjs");
return esmSlothlet(options);
}
/**
* CommonJS default export of the slothlet function.
* @public
*/
module.exports = slothlet;
/**
* Named export alias for the slothlet function.
* Provides the same functionality as the default export.
* @public
* @type {Function}
*
* @example // CJS named destructuring
* const { slothlet } = require("@cldmv/slothlet");
* const api = await slothlet({ dir: "./api" });
*/
module.exports.slothlet = slothlet; // optional named alias