UNPKG

mlld

Version:

mlld: llm scripting language

200 lines (198 loc) 6.94 kB
import { __name, __publicField } from './chunk-NJQT543K.mjs'; // core/types/variable/TypeGuards.ts function isSimpleText(variable) { return variable.type === "simple-text"; } __name(isSimpleText, "isSimpleText"); function isInterpolatedText(variable) { return variable.type === "interpolated-text"; } __name(isInterpolatedText, "isInterpolatedText"); function isTemplate(variable) { return variable.type === "template"; } __name(isTemplate, "isTemplate"); function isFileContent(variable) { return variable.type === "file-content"; } __name(isFileContent, "isFileContent"); function isSectionContent(variable) { return variable.type === "section-content"; } __name(isSectionContent, "isSectionContent"); function isObject(variable) { return variable.type === "object"; } __name(isObject, "isObject"); function isArray(variable) { return variable.type === "array"; } __name(isArray, "isArray"); function isComputed(variable) { return variable.type === "computed"; } __name(isComputed, "isComputed"); function isCommandResult(variable) { return variable.type === "command-result"; } __name(isCommandResult, "isCommandResult"); function isPath(variable) { return variable.type === "path"; } __name(isPath, "isPath"); function isImported(variable) { return variable.type === "imported"; } __name(isImported, "isImported"); function isExecutable(variable) { return variable.type === "executable"; } __name(isExecutable, "isExecutable"); function isPipelineInput(variable) { return variable.type === "pipeline-input"; } __name(isPipelineInput, "isPipelineInput"); function isStructuredValueVariable(variable) { return variable.type === "structured"; } __name(isStructuredValueVariable, "isStructuredValueVariable"); function isPrimitive(variable) { return variable.type === "primitive"; } __name(isPrimitive, "isPrimitive"); function isTextLike(variable) { return isSimpleText(variable) || isInterpolatedText(variable) || isTemplate(variable) || isFileContent(variable) || isSectionContent(variable) || isCommandResult(variable); } __name(isTextLike, "isTextLike"); function isStructured(variable) { return isObject(variable) || isArray(variable) || isStructuredValueVariable(variable); } __name(isStructured, "isStructured"); function isExternal(variable) { return isFileContent(variable) || isSectionContent(variable) || isImported(variable) || isCommandResult(variable) || isComputed(variable); } __name(isExternal, "isExternal"); var _VariableTypeGuards = class _VariableTypeGuards { /** * Check if variable has a specific type discriminator */ static hasType(variable, type) { return variable.type === type; } /** * Get all type discriminators that match the variable */ static getMatchingTypes(variable) { const types = [ variable.type ]; if (this.isTextLike(variable)) { types.push("simple-text"); } if (this.isStructured(variable)) { types.push("object"); } if (this.isExternal(variable)) { types.push("imported"); } return types; } /** * Validate that a variable matches expected type */ static validateType(variable, expectedType) { return variable.type === expectedType; } /** * Check if variable is of any of the specified types */ static isAnyType(variable, types) { return types.includes(variable.type); } /** * Filter variables by type */ static filterByType(variables, guard) { return variables.filter(guard); } /** * Find first variable of specified type */ static findByType(variables, guard) { return variables.find(guard); } /** * Count variables by type */ static countByType(variables, type) { return variables.filter((v) => v.type === type).length; } /** * Group variables by their types */ static groupByType(variables) { const groups = /* @__PURE__ */ new Map(); for (const variable of variables) { const existing = groups.get(variable.type) || []; existing.push(variable); groups.set(variable.type, existing); } return groups; } }; __name(_VariableTypeGuards, "VariableTypeGuards"); // Individual type guards __publicField(_VariableTypeGuards, "isSimpleText", isSimpleText); __publicField(_VariableTypeGuards, "isInterpolatedText", isInterpolatedText); __publicField(_VariableTypeGuards, "isTemplate", isTemplate); __publicField(_VariableTypeGuards, "isFileContent", isFileContent); __publicField(_VariableTypeGuards, "isSectionContent", isSectionContent); __publicField(_VariableTypeGuards, "isObject", isObject); __publicField(_VariableTypeGuards, "isArray", isArray); __publicField(_VariableTypeGuards, "isComputed", isComputed); __publicField(_VariableTypeGuards, "isCommandResult", isCommandResult); __publicField(_VariableTypeGuards, "isPath", isPath); __publicField(_VariableTypeGuards, "isImported", isImported); __publicField(_VariableTypeGuards, "isExecutable", isExecutable); __publicField(_VariableTypeGuards, "isPipelineInput", isPipelineInput); __publicField(_VariableTypeGuards, "isStructuredValue", isStructuredValueVariable); __publicField(_VariableTypeGuards, "isPrimitive", isPrimitive); // Composite type guards __publicField(_VariableTypeGuards, "isTextLike", isTextLike); __publicField(_VariableTypeGuards, "isStructured", isStructured); __publicField(_VariableTypeGuards, "isExternal", isExternal); var VariableTypeGuards = _VariableTypeGuards; var _FastTypeGuards = class _FastTypeGuards { /** * Fast check for text types (most common) */ static isAnyTextType(variable) { const type = variable.type; return type === "simple-text" || type === "interpolated-text" || type === "template" || type === "file-content" || type === "section-content" || type === "command-result"; } /** * Fast check for data types */ static isAnyDataType(variable) { const type = variable.type; return type === "object" || type === "array" || type === "computed" || type === "primitive"; } /** * Fast check for complex types that might need special handling */ static isComplexType(variable) { const type = variable.type; return type === "imported" || type === "executable" || type === "pipeline-input" || type === "path"; } /** * Check if variable type requires lazy evaluation */ static requiresLazyEvaluation(variable) { return isTemplate(variable) || isPipelineInput(variable) || isImported(variable) && variable.internal?.isComplex; } }; __name(_FastTypeGuards, "FastTypeGuards"); var FastTypeGuards = _FastTypeGuards; export { FastTypeGuards, VariableTypeGuards, isArray, isCommandResult, isComputed, isExecutable, isExternal, isFileContent, isImported, isInterpolatedText, isObject, isPath, isPipelineInput, isPrimitive, isSectionContent, isSimpleText, isStructured, isStructuredValueVariable, isTemplate, isTextLike }; //# sourceMappingURL=chunk-EIWSEMQ4.mjs.map //# sourceMappingURL=chunk-EIWSEMQ4.mjs.map