UNPKG

@docuify/engine

Version:

A flexible, pluggable engine for building and transforming documentation content from source files.

77 lines (75 loc) 2.84 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // lib/core/query_context.ts var query_context_exports = {}; __export(query_context_exports, { QueryContext: () => QueryContext }); module.exports = __toCommonJS(query_context_exports); var import_isMatch = __toESM(require("lodash/isMatch")); var QueryContext = class { flatNodes; constructor(flatNodes) { this.flatNodes = flatNodes; } /** * Filters nodes by a deep partial `where` clause. * Returns a new array of matching nodes (immutable). */ findMany(where) { if (!where) return this.flatNodes; return this.flatNodes.filter((node) => (0, import_isMatch.default)(node, where)); } /** * Finds the first node matching `where`. * Returns undefined if none found. */ findFirst(where) { if (!where) return this.flatNodes[0]; return this.flatNodes.find((node) => (0, import_isMatch.default)(node, where)); } /** * Loads content from a given node if possible. * Throws if the node has no loadContent action or is not a file. * Returns loaded content as string. */ async loadContent(node) { if (node.type !== "file") { throw new Error("loadContent only supported for file nodes"); } if (!node.actions?.loadContent) { throw new Error(`Node at ${node.fullPath} has no content loader`); } return await node.actions.loadContent(); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { QueryContext });