mlld
Version:
mlld: llm scripting language
450 lines (448 loc) • 14.5 kB
JavaScript
import { __name } from './chunk-NJQWMXLH.mjs';
// core/types/variable/VariableFactories.ts
function createSimpleTextVariable(name, value, source, metadata) {
return VariableFactory.createSimpleText(name, value, source, metadata);
}
__name(createSimpleTextVariable, "createSimpleTextVariable");
function createInterpolatedTextVariable(name, value, interpolationPoints, source, metadata) {
return VariableFactory.createInterpolatedText(name, value, interpolationPoints, source, metadata);
}
__name(createInterpolatedTextVariable, "createInterpolatedTextVariable");
function createTemplateVariable(name, value, parameters, templateSyntax, source, metadata) {
return VariableFactory.createTemplate(name, value, parameters, templateSyntax, source, metadata);
}
__name(createTemplateVariable, "createTemplateVariable");
function createFileContentVariable(name, value, filePath, source, metadata) {
return VariableFactory.createFileContent(name, value, filePath, source, void 0, metadata);
}
__name(createFileContentVariable, "createFileContentVariable");
function createSectionContentVariable(name, value, filePath, sectionName, sectionSyntax, source, metadata) {
return VariableFactory.createSectionContent(name, value, filePath, sectionName, sectionSyntax, source, metadata);
}
__name(createSectionContentVariable, "createSectionContentVariable");
function createObjectVariable(name, value, isComplex, source, metadata) {
return VariableFactory.createObject(name, value, isComplex, source, metadata);
}
__name(createObjectVariable, "createObjectVariable");
function createArrayVariable(name, value, isComplex, source, metadata) {
return VariableFactory.createArray(name, value, isComplex, source, metadata);
}
__name(createArrayVariable, "createArrayVariable");
function createComputedVariable(name, value, language, sourceCode, source, metadata) {
return VariableFactory.createComputed(name, value, language, sourceCode, source, metadata);
}
__name(createComputedVariable, "createComputedVariable");
function createCommandResultVariable(name, value, command, source, exitCode, stderr, metadata) {
return VariableFactory.createCommandResult(name, value, command, source, exitCode, stderr, metadata);
}
__name(createCommandResultVariable, "createCommandResultVariable");
function createPathVariable(name, resolvedPath, originalPath, isURL, isAbsolute, source, metadata) {
return VariableFactory.createPath(name, resolvedPath, originalPath, isURL, isAbsolute, source, metadata);
}
__name(createPathVariable, "createPathVariable");
function createImportedVariable(name, value, originalType, importPath, isModule, variableName, source, metadata) {
return VariableFactory.createImported(name, value, originalType, importPath, isModule, variableName, source, metadata);
}
__name(createImportedVariable, "createImportedVariable");
function createExecutableVariable(name, type, template, paramNames, language, source, metadata) {
return VariableFactory.createExecutable(name, type, template, paramNames, language, source, metadata);
}
__name(createExecutableVariable, "createExecutableVariable");
function createPipelineInputVariable(name, value, format, rawText, source, pipelineStage) {
return VariableFactory.createPipelineInput(name, value, format, rawText, source, pipelineStage);
}
__name(createPipelineInputVariable, "createPipelineInputVariable");
function createStructuredValueVariable(name, value, source, metadata) {
return VariableFactory.createStructuredValue(name, value, source, metadata);
}
__name(createStructuredValueVariable, "createStructuredValueVariable");
function createPrimitiveVariable(name, value, source, metadata) {
return VariableFactory.createPrimitive(name, value, source, metadata);
}
__name(createPrimitiveVariable, "createPrimitiveVariable");
var _VariableFactory = class _VariableFactory {
// =========================================================================
// TEXT VARIABLE FACTORIES
// =========================================================================
/**
* Create a SimpleTextVariable
*/
static createSimpleText(name, value, source, metadata) {
return {
type: "simple-text",
name,
value,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create an InterpolatedTextVariable
*/
static createInterpolatedText(name, value, interpolationPoints, source, metadata) {
return {
type: "interpolated-text",
name,
value,
interpolationPoints,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create a TemplateVariable
*/
static createTemplate(name, value, parameters, templateSyntax, source, metadata) {
return {
type: "template",
name,
value,
parameters,
templateSyntax,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
// =========================================================================
// CONTENT VARIABLE FACTORIES
// =========================================================================
/**
* Create a FileContentVariable
*/
static createFileContent(name, value, filePath, source, encoding, metadata) {
return {
type: "file-content",
name,
value,
filePath,
encoding,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create a SectionContentVariable
*/
static createSectionContent(name, value, filePath, sectionName, sectionSyntax, source, metadata) {
return {
type: "section-content",
name,
value,
filePath,
sectionName,
sectionSyntax,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
// =========================================================================
// STRUCTURED DATA FACTORIES
// =========================================================================
/**
* Create an ObjectVariable
*/
static createObject(name, value, isComplex, source, metadata) {
return {
type: "object",
name,
value,
isComplex,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create an ArrayVariable
*/
static createArray(name, value, isComplex, source, metadata) {
return {
type: "array",
name,
value,
isComplex,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
// =========================================================================
// COMPUTED VARIABLE FACTORIES
// =========================================================================
/**
* Create a ComputedVariable
*/
static createComputed(name, value, language, sourceCode, source, metadata) {
return {
type: "computed",
name,
value,
language,
sourceCode,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create a CommandResultVariable
*/
static createCommandResult(name, value, command, source, exitCode, stderr, metadata) {
return {
type: "command-result",
name,
value,
command,
exitCode,
stderr,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
// =========================================================================
// SPECIAL VARIABLE FACTORIES
// =========================================================================
/**
* Create a PathVariable
*/
static createPath(name, resolvedPath, originalPath, isURL, isAbsolute, source, metadata) {
return {
type: "path",
name,
value: {
resolvedPath,
originalPath,
isURL,
isAbsolute
},
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create an ImportedVariable
*/
static createImported(name, value, originalType, importPath, isModule, variableName, source, metadata) {
return {
type: "imported",
name,
value,
originalType,
importSource: {
path: importPath,
isModule,
variableName
},
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create an ExecutableVariable
*/
static createExecutable(name, type, template, paramNames, language, source, metadata) {
return {
type: "executable",
name,
value: {
type,
template,
language
},
paramNames,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
/**
* Create a PipelineInputVariable
*/
static createPipelineInput(name, value, format, rawText, source, pipelineStage) {
return {
type: "pipeline-input",
name,
value,
format,
rawText,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata: {
isPipelineInput: true,
pipelineStage
}
};
}
/**
* Create a StructuredValueVariable
*/
static createStructuredValue(name, value, source, metadata) {
const structuredMetadata = {
...metadata,
isStructuredValue: true,
structuredValueType: value.type
};
return {
type: "structured",
name,
value,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata: structuredMetadata
};
}
/**
* Create a PrimitiveVariable
*/
static createPrimitive(name, value, source, metadata) {
return {
type: "primitive",
name,
value,
primitiveType: value === null ? "null" : typeof value,
source,
createdAt: Date.now(),
modifiedAt: Date.now(),
metadata
};
}
// =========================================================================
// CONVENIENCE FACTORY METHODS
// =========================================================================
/**
* Create a variable with auto-detected type based on value
*/
static createAutoTyped(name, value, source, metadata) {
if (typeof value === "string") {
return this.createSimpleText(name, value, source, metadata);
} else if (typeof value === "number" || typeof value === "boolean" || value === null) {
return this.createPrimitive(name, value, source, metadata);
} else if (Array.isArray(value)) {
return this.createArray(name, value, false, source, metadata);
} else if (typeof value === "object" && value !== null) {
return this.createObject(name, value, false, source, metadata);
} else {
return this.createSimpleText(name, String(value), source, metadata);
}
}
/**
* Create a template variable with auto-detected syntax
*/
static createTemplateAutoSyntax(name, value, parameters, source, metadata) {
const templateSyntax = value.includes("{{") && value.includes("}}") ? "double-bracket" : "backtick";
const finalSource = source || {
directive: "var",
syntax: "template",
wrapperType: templateSyntax === "double-bracket" ? void 0 : "backtick",
hasInterpolation: true,
isMultiLine: value.includes("\n")
};
return this.createTemplate(name, value, parameters, templateSyntax, finalSource, metadata);
}
/**
* Create an object variable with complexity detection
*/
static createObjectWithComplexityDetection(name, value, source, metadata) {
const isComplex = this.detectComplexity(value);
return this.createObject(name, value, isComplex, source, metadata);
}
/**
* Create an array variable with complexity detection
*/
static createArrayWithComplexityDetection(name, value, source, metadata) {
const isComplex = value.some(
(item) => typeof item === "object" && item !== null && this.detectComplexity(item)
);
return this.createArray(name, value, isComplex, source, metadata);
}
// =========================================================================
// HELPER METHODS
// =========================================================================
/**
* Simple complexity detection heuristic
*/
static detectComplexity(value) {
if (typeof value !== "object" || value === null) {
return false;
}
for (const key in value) {
const item = value[key];
if (typeof item === "object" && item !== null) {
return true;
}
if (typeof item === "string" && (item.includes("/") || item.includes("@"))) {
return true;
}
}
return false;
}
/**
* Validate variable creation parameters
*/
static validateCreationParams(name, value, source) {
const errors = [];
if (!name || typeof name !== "string") {
errors.push("Variable name must be a non-empty string");
}
if (name && !name.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)) {
errors.push("Variable name must be a valid identifier");
}
if (!source || typeof source !== "object") {
errors.push("Variable source must be provided");
}
if (source && !source.directive) {
errors.push("Variable source must have a directive");
}
return {
valid: errors.length === 0,
errors
};
}
/**
* Clone a variable with updated metadata
*/
static cloneWithMetadata(variable, newMetadata) {
return {
...variable,
metadata: { ...variable.metadata, ...newMetadata },
modifiedAt: Date.now()
};
}
/**
* Update variable value while preserving type safety
*/
static updateValue(variable, newValue) {
return {
...variable,
value: newValue,
modifiedAt: Date.now()
};
}
};
__name(_VariableFactory, "VariableFactory");
var VariableFactory = _VariableFactory;
export { VariableFactory, createArrayVariable, createCommandResultVariable, createComputedVariable, createExecutableVariable, createFileContentVariable, createImportedVariable, createInterpolatedTextVariable, createObjectVariable, createPathVariable, createPipelineInputVariable, createPrimitiveVariable, createSectionContentVariable, createSimpleTextVariable, createStructuredValueVariable, createTemplateVariable };
//# sourceMappingURL=chunk-CHF7KR7X.mjs.map
//# sourceMappingURL=chunk-CHF7KR7X.mjs.map