Utility class for managing artifact extract rules and performing extraction.

Handles:

  • Hierarchical rule inheritance from parent artifact types
  • Rule override resolution (child rules override parent rules by name)
  • Safe execution of extractor JavaScript code
  • Error handling and timeout management

Constructors

Methods

  • Deserializes stored attributes from ArtifactVersionAttribute records.

    Converts JSON strings back to their original types for use in application.

    Parameters

    • storedAttributes: {
          Name: string;
          StandardProperty?: string;
          Type: string;
          Value: string;
      }[]

      Array of attribute records from database

    Returns ExtractedArtifactAttribute[]

    Array of extracted attributes with deserialized values

    Example

    const stored = await artifactVersionAttributes.load();
    const attributes = ArtifactExtractor.DeserializeFromStorage(stored);
    // attributes have parsed JSON values, not strings
  • Private

    Executes an extractor function with timeout protection.

    Creates a sandboxed environment where the extractor code can run safely with access to the content but isolated from the global scope.

    Parameters

    • content: string

      The artifact content to extract from

    • extractorCode: string

      JavaScript code that performs the extraction

    • timeoutMs: number

      Maximum execution time in milliseconds

    Returns Promise<any>

    The extracted value

    Throws

    Error if execution times out or fails

  • Extracts attributes from artifact content using the provided extract rules.

    Executes each extractor function in a controlled environment with timeout and error handling. Failed extractors can either throw or return null values based on configuration.

    Parameters

    Returns Promise<ArtifactExtractionResult>

    Extraction result with attributes, errors, and timing information

    Example

    const result = await ArtifactExtractor.ExtractAttributes({
    content: '{"subject": "Hello", "body": "World"}',
    extractRules: [
    {
    name: 'subject',
    type: 'string',
    standardProperty: 'name',
    extractor: 'const parsed = JSON.parse(content); return parsed.subject;'
    }
    ]
    });
    // result.attributes = [{ name: 'subject', type: 'string', value: 'Hello', standardProperty: 'name' }]
  • Finds a specific standard property value from extracted attributes.

    Convenience method for retrieving attributes mapped to standard properties like 'name', 'description', etc.

    Parameters

    • attributes: ExtractedArtifactAttribute[]

      Array of extracted attributes

    • standardProperty: "description" | "displayHtml" | "displayMarkdown" | "name"

      The standard property to find

    Returns any

    The value of the attribute, or null if not found

    Example

    const name = ArtifactExtractor.GetStandardProperty(attributes, 'name');
    const description = ArtifactExtractor.GetStandardProperty(attributes, 'description');
  • Resolves extract rules with hierarchical inheritance.

    Child artifact types inherit all rules from their parent/grandparent types, but can override rules with the same name. This method resolves the final set of rules by walking up the hierarchy and merging rules.

    Parameters

    • artifactTypeChain: {
          ExtractRules?: string;
      }[]

      Array of artifact types from most specific (child) to least specific (root parent) Each element should have an ExtractRules JSON string

    Returns ArtifactExtractRule[]

    Resolved array of extract rules with overrides applied

    Example

    // Parent type has rules: [{ name: 'title', ... }, { name: 'author', ... }]
    // Child type has rules: [{ name: 'title', ... (override) }, { name: 'date', ... (new) }]
    const resolved = ArtifactExtractor.ResolveExtractRules([
    childType.ExtractRules,
    parentType.ExtractRules
    ]);
    // Result: [{ name: 'title' (from child), ... }, { name: 'author' (from parent), ... }, { name: 'date' (from child), ... }]
  • Serializes extracted attributes for storage in ArtifactVersionAttribute table.

    Converts extracted attribute values to JSON strings suitable for database storage.

    Parameters

    Returns {
        name: string;
        standardProperty?: string;
        type: string;
        value: string;
    }[]

    Array of objects ready for database insertion

    Example

    const serialized = ArtifactExtractor.SerializeForStorage(result.attributes);
    // Can now insert these into ArtifactVersionAttribute table
    for (const attr of serialized) {
    await artifactVersionAttribute.save({
    ArtifactVersionID: versionId,
    Name: attr.name,
    Type: attr.type,
    Value: attr.value,
    StandardProperty: attr.standardProperty
    });
    }