org.jetbrains.kotlinx.jupyter.api.libraries.LibraryResources.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-api Show documentation
Show all versions of kotlin-jupyter-api Show documentation
API for libraries supporting Kotlin Jupyter notebooks
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),
)
}
}