All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlinx.jupyter.api.libraries.LibraryResources.kt Maven / Gradle / Ivy

There is a newer version: 0.12.0-335
Show newest version
package org.jetbrains.kotlinx.jupyter.api.libraries

import kotlinx.serialization.Serializable
import org.jetbrains.kotlinx.jupyter.util.ResourceBunchSerializer
import org.jetbrains.kotlinx.jupyter.util.replaceVariables

enum class ResourcePathType {
    /**
     * URL resource. Resource is attached by link.
     * Examples:
     * - https://github.com/Kotlin/kotlin-jupyter/lib.js
     * - file:///C:/Users/lib.js
     */
    URL,

    /**
     * URL resource. Resource is embedded into notebook.
     */
    URL_EMBEDDED,

    /**
     * Local resource.
     * Examples:
     * - /usr/lib/lib.js
     * - libs/lib.js
     */
    LOCAL_PATH,

    /**
     * Path which should be resolved as resource by current classpath
     * Example:
     * - META-INF/libs/lib.js
     */
    CLASSPATH_PATH,
}

enum class ResourceType {
    JS,
    CSS,
}

@Serializable
data class ResourceLocation(
    val path: String,
    val type: ResourcePathType,
) : VariablesSubstitutionAware {
    override fun replaceVariables(mapping: Map): ResourceLocation {
        return ResourceLocation(replaceVariables(path, mapping), type)
    }
}

@Serializable(ResourceBunchSerializer::class)
data class ResourceFallbacksBundle(
    val locations: List,
) : VariablesSubstitutionAware {
    constructor(vararg locations: ResourceLocation) : this(listOf(*locations))

    override fun replaceVariables(mapping: Map): ResourceFallbacksBundle {
        return ResourceFallbacksBundle(locations.map { it.replaceVariables(mapping) })
    }
}

@Serializable
data class LibraryResource(
    val bundles: List,
    val type: ResourceType,
    val name: String,
) : VariablesSubstitutionAware {
    override fun replaceVariables(mapping: Map): LibraryResource {
        return LibraryResource(
            bundles.map { it.replaceVariables(mapping) },
            type,
            replaceVariables(name, mapping),
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy