mirror of
https://github.com/apple/pkl.git
synced 2026-07-07 05:25:17 +02:00
Apply pkl formatter to codebase (#1236)
This applies the Pkl formatter to `stdlib/` and `.circleci/`
This commit is contained in:
+17
-13
@@ -17,8 +17,8 @@
|
|||||||
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.2.0#/PklCI.pkl"
|
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.2.0#/PklCI.pkl"
|
||||||
|
|
||||||
import "jobs/BuildNativeJob.pkl"
|
import "jobs/BuildNativeJob.pkl"
|
||||||
import "jobs/GradleCheckJob.pkl"
|
|
||||||
import "jobs/DeployJob.pkl"
|
import "jobs/DeployJob.pkl"
|
||||||
|
import "jobs/GradleCheckJob.pkl"
|
||||||
import "jobs/SimpleGradleJob.pkl"
|
import "jobs/SimpleGradleJob.pkl"
|
||||||
|
|
||||||
local prbJobs: Listing<String> = gradleCheckJobs.keys.toListing()
|
local prbJobs: Listing<String> = gradleCheckJobs.keys.toListing()
|
||||||
@@ -130,18 +130,21 @@ jobs {
|
|||||||
[jobName] = job.job
|
[jobName] = job.job
|
||||||
}
|
}
|
||||||
["bench"] = new SimpleGradleJob { command = "bench:jmh" }.job
|
["bench"] = new SimpleGradleJob { command = "bench:jmh" }.job
|
||||||
["gradle-compatibility"] = new SimpleGradleJob {
|
["gradle-compatibility"] =
|
||||||
name = "gradle compatibility"
|
new SimpleGradleJob {
|
||||||
command = #"""
|
name = "gradle compatibility"
|
||||||
:pkl-gradle:build \
|
command =
|
||||||
:pkl-gradle:compatibilityTestReleases
|
#"""
|
||||||
"""#
|
:pkl-gradle:build \
|
||||||
}.job
|
:pkl-gradle:compatibilityTestReleases
|
||||||
|
"""#
|
||||||
|
}.job
|
||||||
["deploy-snapshot"] = new DeployJob { command = "publishToSonatype" }.job
|
["deploy-snapshot"] = new DeployJob { command = "publishToSonatype" }.job
|
||||||
["deploy-release"] = new DeployJob {
|
["deploy-release"] =
|
||||||
isRelease = true
|
new DeployJob {
|
||||||
command = "publishToSonatype closeAndReleaseSonatypeStagingRepository"
|
isRelease = true
|
||||||
}.job
|
command = "publishToSonatype closeAndReleaseSonatypeStagingRepository"
|
||||||
|
}.job
|
||||||
["github-release"] {
|
["github-release"] {
|
||||||
docker {
|
docker {
|
||||||
new { image = "maniator/gh:v2.40.1" }
|
new { image = "maniator/gh:v2.40.1" }
|
||||||
@@ -150,7 +153,8 @@ jobs {
|
|||||||
new AttachWorkspaceStep { at = "." }
|
new AttachWorkspaceStep { at = "." }
|
||||||
new RunStep {
|
new RunStep {
|
||||||
name = "Publish release on GitHub"
|
name = "Publish release on GitHub"
|
||||||
command = #"""
|
command =
|
||||||
|
#"""
|
||||||
# exclude build_artifacts.txt from publish
|
# exclude build_artifacts.txt from publish
|
||||||
rm -f */build/executable/*.build_artifacts.txt
|
rm -f */build/executable/*.build_artifacts.txt
|
||||||
find */build/executable/* -type d | xargs rm -rf
|
find */build/executable/* -type d | xargs rm -rf
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ extends "GradleJob.pkl"
|
|||||||
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.5.0#/Config.pkl"
|
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.5.0#/Config.pkl"
|
||||||
|
|
||||||
/// The architecture to use
|
/// The architecture to use
|
||||||
arch: "amd64"|"aarch64"
|
arch: "amd64" | "aarch64"
|
||||||
|
|
||||||
/// Whether to link to musl. Otherwise, links to glibc.
|
/// Whether to link to musl. Otherwise, links to glibc.
|
||||||
musl: Boolean = false
|
musl: Boolean = false
|
||||||
@@ -44,40 +44,45 @@ local setupLinuxEnvironment: Config.RunStep =
|
|||||||
new {
|
new {
|
||||||
name = "Set up environment"
|
name = "Set up environment"
|
||||||
shell = "#!/bin/bash -exo pipefail"
|
shell = "#!/bin/bash -exo pipefail"
|
||||||
command = new Listing {
|
command =
|
||||||
#"""
|
new Listing {
|
||||||
sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \
|
#"""
|
||||||
&& microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \
|
sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \
|
||||||
&& microdnf clean all \
|
&& microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \
|
||||||
&& rm -rf /var/cache/dnf
|
&& microdnf clean all \
|
||||||
|
&& rm -rf /var/cache/dnf
|
||||||
|
|
||||||
# install jdk
|
# install jdk
|
||||||
curl -Lf \
|
curl -Lf \
|
||||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module
|
||||||
|
.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64")
|
||||||
|
"x64"
|
||||||
|
else
|
||||||
|
"aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||||
|
|
||||||
mkdir /jdk \
|
mkdir /jdk \
|
||||||
&& cd /jdk \
|
&& cd /jdk \
|
||||||
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
||||||
|
|
||||||
mkdir -p ~/staticdeps/bin
|
mkdir -p ~/staticdeps/bin
|
||||||
|
|
||||||
cp /usr/lib/gcc/\#(if (arch == "amd64") "x86_64" else "aarch64")-redhat-linux/8/libstdc++.a ~/staticdeps
|
cp /usr/lib/gcc/\#(if (arch == "amd64") "x86_64" else "aarch64")-redhat-linux/8/libstdc++.a ~/staticdeps
|
||||||
|
|
||||||
# install zlib
|
# install zlib
|
||||||
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
|
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
|
||||||
curl -Lf https://github.com/madler/zlib/releases/download/v\#(zlibVersion)/zlib-\#(zlibVersion).tar.gz -o /tmp/zlib.tar.gz
|
curl -Lf https://github.com/madler/zlib/releases/download/v\#(zlibVersion)/zlib-\#(zlibVersion).tar.gz -o /tmp/zlib.tar.gz
|
||||||
|
|
||||||
mkdir -p /tmp/dep_zlib-\#(zlibVersion) \
|
mkdir -p /tmp/dep_zlib-\#(zlibVersion) \
|
||||||
&& cd /tmp/dep_zlib-\#(zlibVersion) \
|
&& cd /tmp/dep_zlib-\#(zlibVersion) \
|
||||||
&& cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \
|
&& cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \
|
||||||
&& echo "zlib-\#(zlibVersion): configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \
|
&& echo "zlib-\#(zlibVersion): configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \
|
||||||
&& echo "zlib-\#(zlibVersion): make..." && make -s -j4 \
|
&& echo "zlib-\#(zlibVersion): make..." && make -s -j4 \
|
||||||
&& echo "zlib-\#(zlibVersion): make install..." && make -s install \
|
&& echo "zlib-\#(zlibVersion): make install..." && make -s install \
|
||||||
&& rm -rf /tmp/dep_zlib-\#(zlibVersion)
|
&& rm -rf /tmp/dep_zlib-\#(zlibVersion)
|
||||||
fi
|
fi
|
||||||
"""#
|
"""#
|
||||||
// don't need musl on aarch because GraalVM only supports musl builds on x86
|
// don't need musl on aarch because GraalVM only supports musl builds on x86
|
||||||
when (arch == "amd64") {
|
when (arch == "amd64") {
|
||||||
#"""
|
#"""
|
||||||
# install musl
|
# install musl
|
||||||
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
|
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
|
||||||
@@ -95,25 +100,28 @@ local setupLinuxEnvironment: Config.RunStep =
|
|||||||
ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc
|
ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc
|
||||||
fi
|
fi
|
||||||
"""#
|
"""#
|
||||||
}
|
}
|
||||||
}.join("\n\n")
|
}.join("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
local setupMacEnvironment: Config.RunStep =
|
local setupMacEnvironment: Config.RunStep = new {
|
||||||
new {
|
name = "Set up environment"
|
||||||
name = "Set up environment"
|
shell = "#!/bin/bash -exo pipefail"
|
||||||
shell = "#!/bin/bash -exo pipefail"
|
command =
|
||||||
command =
|
#"""
|
||||||
#"""
|
# install jdk
|
||||||
# install jdk
|
curl -Lf \
|
||||||
curl -Lf \
|
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module
|
||||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_mac_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64")
|
||||||
|
"x64"
|
||||||
|
else
|
||||||
|
"aarch64")_mac_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||||
|
|
||||||
mkdir $HOME/jdk \
|
mkdir $HOME/jdk \
|
||||||
&& cd $HOME/jdk \
|
&& cd $HOME/jdk \
|
||||||
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
||||||
"""#
|
"""#
|
||||||
}
|
}
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
when (os == "linux") {
|
when (os == "linux") {
|
||||||
@@ -134,7 +142,8 @@ steps {
|
|||||||
when (arch == "amd64") {
|
when (arch == "amd64") {
|
||||||
new Config.RunStep {
|
new Config.RunStep {
|
||||||
name = "Installing Rosetta 2"
|
name = "Installing Rosetta 2"
|
||||||
command = """
|
command =
|
||||||
|
"""
|
||||||
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
|
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
@@ -146,7 +155,8 @@ steps {
|
|||||||
when (module.os == "windows") {
|
when (module.os == "windows") {
|
||||||
shell = "bash.exe"
|
shell = "bash.exe"
|
||||||
}
|
}
|
||||||
command = #"""
|
command =
|
||||||
|
#"""
|
||||||
export PATH=~/staticdeps/bin:$PATH
|
export PATH=~/staticdeps/bin:$PATH
|
||||||
./gradlew \#(module.gradleArgs) \#(project):buildNative
|
./gradlew \#(module.gradleArgs) \#(project):buildNative
|
||||||
"""#
|
"""#
|
||||||
|
|||||||
@@ -22,14 +22,12 @@ import "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1.0.3#/URI.pk
|
|||||||
isRelease: Boolean = false
|
isRelease: Boolean = false
|
||||||
|
|
||||||
/// The OS to run on
|
/// The OS to run on
|
||||||
os: "macOS"|"linux"|"windows"
|
os: "macOS" | "linux" | "windows"
|
||||||
|
|
||||||
/// The version of Java to use.
|
/// The version of Java to use.
|
||||||
javaVersion: "17.0"|"21.0"
|
javaVersion: "17.0" | "21.0"
|
||||||
|
|
||||||
fixed javaVersionFull =
|
fixed javaVersionFull = if (javaVersion == "17.0") "17.0.9+9" else "21.0.5+11"
|
||||||
if (javaVersion == "17.0") "17.0.9+9"
|
|
||||||
else "21.0.5+11"
|
|
||||||
|
|
||||||
fixed jdkVersionAlt = javaVersionFull.replaceLast("+", "_")
|
fixed jdkVersionAlt = javaVersionFull.replaceLast("+", "_")
|
||||||
|
|
||||||
@@ -38,21 +36,24 @@ fixed majorJdkVersion = javaVersionFull.split(".").first
|
|||||||
fixed jdkGitHubReleaseName =
|
fixed jdkGitHubReleaseName =
|
||||||
let (ver =
|
let (ver =
|
||||||
// 17.0.9+9 is missing some binaries (see https://github.com/adoptium/adoptium-support/issues/994)
|
// 17.0.9+9 is missing some binaries (see https://github.com/adoptium/adoptium-support/issues/994)
|
||||||
if (javaVersionFull == "17.0.9+9" && os == "windows") "jdk-17.0.9+9.1"
|
if (javaVersionFull == "17.0.9+9" && os == "windows")
|
||||||
else "jdk-\(javaVersionFull)"
|
"jdk-17.0.9+9.1"
|
||||||
|
else
|
||||||
|
"jdk-\(javaVersionFull)"
|
||||||
)
|
)
|
||||||
URI.encodeComponent(ver)
|
URI.encodeComponent(ver)
|
||||||
|
|
||||||
fixed gradleArgs = new Listing {
|
fixed gradleArgs =
|
||||||
"--info"
|
new Listing {
|
||||||
"--stacktrace"
|
"--info"
|
||||||
"-DtestReportsDir=${HOME}/test-results"
|
"--stacktrace"
|
||||||
"-DpklMultiJdkTesting=true"
|
"-DtestReportsDir=${HOME}/test-results"
|
||||||
when (isRelease) {
|
"-DpklMultiJdkTesting=true"
|
||||||
"-DreleaseBuild=true"
|
when (isRelease) {
|
||||||
}
|
"-DreleaseBuild=true"
|
||||||
...extraGradleArgs
|
}
|
||||||
}.join(" ")
|
...extraGradleArgs
|
||||||
|
}.join(" ")
|
||||||
|
|
||||||
extraGradleArgs: Listing<String>
|
extraGradleArgs: Listing<String>
|
||||||
|
|
||||||
@@ -84,7 +85,8 @@ job: Config.Job = new {
|
|||||||
new Config.RunStep {
|
new Config.RunStep {
|
||||||
name = "Set up environment"
|
name = "Set up environment"
|
||||||
shell = "bash.exe"
|
shell = "bash.exe"
|
||||||
command = #"""
|
command =
|
||||||
|
#"""
|
||||||
# install jdk
|
# install jdk
|
||||||
curl -Lf \
|
curl -Lf \
|
||||||
https://github.com/adoptium/temurin\#(majorJdkVersion)-binaries/releases/download/\#(jdkGitHubReleaseName)/OpenJDK\#(majorJdkVersion)U-jdk_x64_windows_hotspot_\#(jdkVersionAlt).zip -o /tmp/jdk.zip
|
https://github.com/adoptium/temurin\#(majorJdkVersion)-binaries/releases/download/\#(jdkGitHubReleaseName)/OpenJDK\#(majorJdkVersion)U-jdk_x64_windows_hotspot_\#(jdkVersionAlt).zip -o /tmp/jdk.zip
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ javaVersion = "21.0"
|
|||||||
steps {
|
steps {
|
||||||
new Config.RunStep {
|
new Config.RunStep {
|
||||||
name = module.name
|
name = module.name
|
||||||
command = """
|
command =
|
||||||
|
"""
|
||||||
./gradlew \(module.gradleArgs) \(module.command)
|
./gradlew \(module.gradleArgs) \(module.command)
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|||||||
+313
-313
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
–– Pkl Error ––
|
–– Pkl Error ––
|
||||||
Expected value of type `*RemoteDependency|Project(isValidLoadDependency)`, but got a different `pkl.Project`.
|
Expected value of type `*RemoteDependency | Project(isValidLoadDependency)`, but got a different `pkl.Project`.
|
||||||
Value: new ModuleClass { package = null; tests {}; dependencies {}; evaluatorSetting...
|
Value: new ModuleClass { package = null; tests {}; dependencies {}; evaluatorSetting...
|
||||||
|
|
||||||
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency|Project(isValidLoadDependency)>
|
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency | Project(isValidLoadDependency)>
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
at pkl.Project#dependencies (pkl:Project)
|
at pkl.Project#dependencies (pkl:Project)
|
||||||
|
|
||||||
* Value is not of type `Project(isValidLoadDependency)` because:
|
* Value is not of type `Project(isValidLoadDependency)` because:
|
||||||
|
|||||||
+12
-11
@@ -26,7 +26,7 @@
|
|||||||
/// * amends this template
|
/// * amends this template
|
||||||
/// * is named _doc-package-info.pkl_
|
/// * is named _doc-package-info.pkl_
|
||||||
/// * is passed to the _pkldoc_ command together with the modules to generate documentation for.
|
/// * is passed to the _pkldoc_ command together with the modules to generate documentation for.
|
||||||
///
|
///
|
||||||
/// Each module to generate documentation must declare a module name that starts with a package [name].
|
/// Each module to generate documentation must declare a module name that starts with a package [name].
|
||||||
/// For example, the following are valid module declarations for package _com.example_:
|
/// For example, the following are valid module declarations for package _com.example_:
|
||||||
/// * `module com.example.Birds`
|
/// * `module com.example.Birds`
|
||||||
@@ -66,11 +66,11 @@
|
|||||||
@ModuleInfo { minPklVersion = "0.30.0" }
|
@ModuleInfo { minPklVersion = "0.30.0" }
|
||||||
module pkl.DocPackageInfo
|
module pkl.DocPackageInfo
|
||||||
|
|
||||||
|
// used by doc comments
|
||||||
|
import "pkl:DocPackageInfo"
|
||||||
|
import "pkl:Project"
|
||||||
import "pkl:reflect"
|
import "pkl:reflect"
|
||||||
import "pkl:semver"
|
import "pkl:semver"
|
||||||
// used by doc comments
|
|
||||||
import "pkl:Project"
|
|
||||||
import "pkl:DocPackageInfo"
|
|
||||||
|
|
||||||
/// The name of this package.
|
/// The name of this package.
|
||||||
name: PackageName
|
name: PackageName
|
||||||
@@ -173,19 +173,20 @@ class PackageDependency {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A package name.
|
/// A package name.
|
||||||
typealias PackageName =
|
typealias PackageName = String(!contains("/"))
|
||||||
String(!contains("/"))
|
|
||||||
|
|
||||||
/// A package version.
|
/// A package version.
|
||||||
typealias PackageVersion =
|
typealias PackageVersion = String(semver.isValid(this))
|
||||||
String(semver.isValid(this))
|
|
||||||
|
|
||||||
@Unlisted
|
@Unlisted
|
||||||
fixed overview: String(!isBlank) = moduleMirror.docComment ??
|
fixed overview: String(!isBlank) =
|
||||||
throw("""
|
moduleMirror.docComment
|
||||||
|
?? throw(
|
||||||
|
"""
|
||||||
Missing overview documentation for package `\(name)`.
|
Missing overview documentation for package `\(name)`.
|
||||||
To fix this problem, add a doc comment to `doc-package-info.pkl` (above `amends "pkl:DocPackageInfo"`).
|
To fix this problem, add a doc comment to `doc-package-info.pkl` (above `amends "pkl:DocPackageInfo"`).
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
@Unlisted
|
@Unlisted
|
||||||
fixed overviewImports: Map<String, Uri> = moduleMirror.imports
|
fixed overviewImports: Map<String, Uri> = moduleMirror.imports
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ allowedResources: Listing<String(isRegex)>?
|
|||||||
/// - `"auto"`: Format if the process' stdin, stdout, or stderr are connected to a console.
|
/// - `"auto"`: Format if the process' stdin, stdout, or stderr are connected to a console.
|
||||||
/// - `"always"`: Always format
|
/// - `"always"`: Always format
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
color: ("never"|"auto"|"always")?
|
color: ("never" | "auto" | "always")?
|
||||||
|
|
||||||
/// Disables the file system cache for `package:` modules.
|
/// Disables the file system cache for `package:` modules.
|
||||||
///
|
///
|
||||||
@@ -116,21 +116,17 @@ externalResourceReaders: Mapping<String, ExternalReader>?
|
|||||||
/// - `"compact"`: All structures passed to trace() will be emitted on a single line.
|
/// - `"compact"`: All structures passed to trace() will be emitted on a single line.
|
||||||
/// - `"pretty"`: All structures passed to trace() will be indented and emitted across multiple lines.
|
/// - `"pretty"`: All structures passed to trace() will be indented and emitted across multiple lines.
|
||||||
@Since { version = "0.30.0" }
|
@Since { version = "0.30.0" }
|
||||||
traceMode: ("compact"|"pretty")?
|
traceMode: ("compact" | "pretty")?
|
||||||
|
|
||||||
const local hostnameRegex = Regex(#"https?://([^/?#]*)"#)
|
local const hostnameRegex = Regex(#"https?://([^/?#]*)"#)
|
||||||
|
|
||||||
const local hasNonEmptyHostname = (it: String) ->
|
local const hasNonEmptyHostname = (it: String) ->
|
||||||
let (hostname = hostnameRegex.findMatchesIn(it).getOrNull(0)?.groups?.getOrNull(1)?.value)
|
let (hostname = hostnameRegex.findMatchesIn(it).getOrNull(0)?.groups?.getOrNull(1)?.value)
|
||||||
hostname != null && hostname.length > 0
|
hostname != null && hostname.length > 0
|
||||||
|
|
||||||
/// A key or value in [Http.rewrites].
|
/// A key or value in [Http.rewrites].
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
typealias HttpRewrite = String(
|
typealias HttpRewrite = String(startsWith(Regex("https?://")), endsWith("/"), hasNonEmptyHostname)
|
||||||
startsWith(Regex("https?://")),
|
|
||||||
endsWith("/"),
|
|
||||||
hasNonEmptyHostname
|
|
||||||
)
|
|
||||||
|
|
||||||
/// Settings that control how Pkl talks to HTTP(S) servers.
|
/// Settings that control how Pkl talks to HTTP(S) servers.
|
||||||
class Http {
|
class Http {
|
||||||
@@ -226,7 +222,7 @@ class Proxy {
|
|||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
class ExternalReader {
|
class ExternalReader {
|
||||||
/// The external reader executable.
|
/// The external reader executable.
|
||||||
///
|
///
|
||||||
/// Will be spawned with the same environment variables and working directory as the Pkl process.
|
/// Will be spawned with the same environment variables and working directory as the Pkl process.
|
||||||
/// Executable is resolved according to the operating system's process spawning rules.
|
/// Executable is resolved according to the operating system's process spawning rules.
|
||||||
/// On macOS, Linux, and Windows platforms, this may be:
|
/// On macOS, Linux, and Windows platforms, this may be:
|
||||||
|
|||||||
+41
-40
@@ -41,7 +41,7 @@
|
|||||||
/// 2. Set [projectFileUri] to the enclosing module's URI.
|
/// 2. Set [projectFileUri] to the enclosing module's URI.
|
||||||
/// This is necessary to determine the correct project directory, as well as for resolving
|
/// This is necessary to determine the correct project directory, as well as for resolving
|
||||||
/// local project dependencies correctly.
|
/// local project dependencies correctly.
|
||||||
///
|
///
|
||||||
/// The [newInstance()] helper method exists as a convenient way to set this when embedding
|
/// The [newInstance()] helper method exists as a convenient way to set this when embedding
|
||||||
/// project definitions.
|
/// project definitions.
|
||||||
///
|
///
|
||||||
@@ -95,11 +95,11 @@ tests: Listing<String>(isDistinct)
|
|||||||
/// Tells if the project is a local module named `PklProject`, is not self, and has a [package] section
|
/// Tells if the project is a local module named `PklProject`, is not self, and has a [package] section
|
||||||
local isValidLoadDependency = (it: Project) ->
|
local isValidLoadDependency = (it: Project) ->
|
||||||
isUriLocal(projectFileUri, it.projectFileUri)
|
isUriLocal(projectFileUri, it.projectFileUri)
|
||||||
&& it.projectFileUri.endsWith("/PklProject")
|
&& it.projectFileUri.endsWith("/PklProject")
|
||||||
&& it != module
|
&& it != module
|
||||||
&& it.package != null
|
&& it.package != null
|
||||||
|
|
||||||
const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
local const function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||||
// This is an imperfect check; should also check that the URIs have the same authority.
|
// This is an imperfect check; should also check that the URIs have the same authority.
|
||||||
// We should improve this if/when there is a URI library in the stdlib.
|
// We should improve this if/when there is a URI library in the stdlib.
|
||||||
uri1.substring(0, uri1.indexOf(":")) == uri2.substring(0, uri2.indexOf(":"))
|
uri1.substring(0, uri1.indexOf(":")) == uri2.substring(0, uri2.indexOf(":"))
|
||||||
@@ -125,7 +125,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// import "@birds/canary.pkl" // Import a module from the `birds` dependency
|
/// import "@birds/canary.pkl" // Import a module from the `birds` dependency
|
||||||
///
|
///
|
||||||
/// birdIndex = read("@birds/index.txt") // Read a file from the `birds` dependency
|
/// birdIndex = read("@birds/index.txt") // Read a file from the `birds` dependency
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@@ -139,7 +139,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
|||||||
///
|
///
|
||||||
/// 1. `GET https://example.com/foo@0.5.0` to retrieve the metadata JSON file.
|
/// 1. `GET https://example.com/foo@0.5.0` to retrieve the metadata JSON file.
|
||||||
/// 2. Given the metadata JSON file, make a GET request to the package URI ZIP archive.
|
/// 2. Given the metadata JSON file, make a GET request to the package URI ZIP archive.
|
||||||
///
|
///
|
||||||
/// If this project is published as a package, these dependencies are included within the published
|
/// If this project is published as a package, these dependencies are included within the published
|
||||||
/// package metadata.
|
/// package metadata.
|
||||||
///
|
///
|
||||||
@@ -149,7 +149,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
|||||||
/// This is useful when structuring a single repository that publishes multiple packages.
|
/// This is useful when structuring a single repository that publishes multiple packages.
|
||||||
///
|
///
|
||||||
/// To specify a local project dependency, import the relative `PklProject` file.
|
/// To specify a local project dependency, import the relative `PklProject` file.
|
||||||
///
|
///
|
||||||
/// The local project dependency must define its own [package].
|
/// The local project dependency must define its own [package].
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
@@ -176,7 +176,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
|||||||
/// 1. Gather all dependencies, both direct and transitive.
|
/// 1. Gather all dependencies, both direct and transitive.
|
||||||
/// 2. For each package's major version, determine the highest declared minor version.
|
/// 2. For each package's major version, determine the highest declared minor version.
|
||||||
/// 3. Write each resolved dependency to sibling file `PklProject.deps.json`.
|
/// 3. Write each resolved dependency to sibling file `PklProject.deps.json`.
|
||||||
dependencies: Mapping<String(!contains("/")), *RemoteDependency|Project(isValidLoadDependency)>
|
dependencies: Mapping<String(!contains("/")), *RemoteDependency | Project(isValidLoadDependency)>
|
||||||
|
|
||||||
local isFileBasedProject = projectFileUri.startsWith("file:")
|
local isFileBasedProject = projectFileUri.startsWith("file:")
|
||||||
|
|
||||||
@@ -196,12 +196,12 @@ local isFileBasedProject = projectFileUri.startsWith("file:")
|
|||||||
/// - [modulePath][EvaluatorSettings.modulePath]
|
/// - [modulePath][EvaluatorSettings.modulePath]
|
||||||
/// - [rootDir][EvaluatorSettings.rootDir]
|
/// - [rootDir][EvaluatorSettings.rootDir]
|
||||||
/// - [moduleCacheDir][EvaluatorSettings.moduleCacheDir]
|
/// - [moduleCacheDir][EvaluatorSettings.moduleCacheDir]
|
||||||
///
|
///
|
||||||
/// For each of these, relative paths are resolved against the project's enclosing directory.
|
/// For each of these, relative paths are resolved against the project's enclosing directory.
|
||||||
evaluatorSettings: EvaluatorSettingsModule(
|
evaluatorSettings: EvaluatorSettingsModule(
|
||||||
(modulePath != null).implies(isFileBasedProject),
|
(modulePath != null).implies(isFileBasedProject),
|
||||||
(rootDir != null).implies(isFileBasedProject),
|
(rootDir != null).implies(isFileBasedProject),
|
||||||
(moduleCacheDir != null).implies(isFileBasedProject)
|
(moduleCacheDir != null).implies(isFileBasedProject),
|
||||||
)
|
)
|
||||||
|
|
||||||
/// The URI of the PklProject file.
|
/// The URI of the PklProject file.
|
||||||
@@ -224,11 +224,12 @@ function newInstance(enclosingModule: Module): Project = new {
|
|||||||
projectFileUri = reflect.Module(enclosingModule).uri
|
projectFileUri = reflect.Module(enclosingModule).uri
|
||||||
}
|
}
|
||||||
|
|
||||||
const local hasVersion = (it: Uri) ->
|
local const hasVersion = (it: Uri) ->
|
||||||
let (versionSep = it.lastIndexOf("@"))
|
let (versionSep = it.lastIndexOf("@"))
|
||||||
if (versionSep == -1) false
|
if (versionSep == -1)
|
||||||
else let (version = it.drop(versionSep + 1))
|
false
|
||||||
semver.parseOrNull(version) != null
|
else
|
||||||
|
let (version = it.drop(versionSep + 1)) semver.parseOrNull(version) != null
|
||||||
|
|
||||||
typealias PackageUri = Uri(startsWith("package:"), hasVersion)
|
typealias PackageUri = Uri(startsWith("package:"), hasVersion)
|
||||||
|
|
||||||
@@ -368,7 +369,7 @@ class Package {
|
|||||||
/// ```
|
/// ```
|
||||||
/// license = "Apache-2.0"
|
/// license = "Apache-2.0"
|
||||||
/// ```
|
/// ```
|
||||||
license: (CommonSpdxLicenseIdentifier|String)?
|
license: (CommonSpdxLicenseIdentifier | String)?
|
||||||
|
|
||||||
/// The full text of the license associated with this package.
|
/// The full text of the license associated with this package.
|
||||||
licenseText: String?
|
licenseText: String?
|
||||||
@@ -412,30 +413,30 @@ typealias EvaluatorSettings = EvaluatorSettingsModule
|
|||||||
/// Common software licenses in the [SPDX License List](https://spdx.org/licenses/).
|
/// Common software licenses in the [SPDX License List](https://spdx.org/licenses/).
|
||||||
typealias CommonSpdxLicenseIdentifier =
|
typealias CommonSpdxLicenseIdentifier =
|
||||||
"Apache-2.0"
|
"Apache-2.0"
|
||||||
|"MIT"
|
| "MIT"
|
||||||
|"BSD-2-Clause"
|
| "BSD-2-Clause"
|
||||||
|"BSD-3-Clause"
|
| "BSD-3-Clause"
|
||||||
|"ISC"
|
| "ISC"
|
||||||
|"GPL-3.0"
|
| "GPL-3.0"
|
||||||
|"GPL-2.0"
|
| "GPL-2.0"
|
||||||
|"MPL-2.0"
|
| "MPL-2.0"
|
||||||
|"MPL-1.1"
|
| "MPL-1.1"
|
||||||
|"MPL-1.0"
|
| "MPL-1.0"
|
||||||
|"AGPL-1.0-only"
|
| "AGPL-1.0-only"
|
||||||
|"AGPL-1.0-or-later"
|
| "AGPL-1.0-or-later"
|
||||||
|"AGPL-3.0-only"
|
| "AGPL-3.0-only"
|
||||||
|"AGPL-3.0-or-later"
|
| "AGPL-3.0-or-later"
|
||||||
|"LGPL-2.0-only"
|
| "LGPL-2.0-only"
|
||||||
|"LGPL-2.0-or-later"
|
| "LGPL-2.0-or-later"
|
||||||
|"LGPL-2.1-only"
|
| "LGPL-2.1-only"
|
||||||
|"LGPL-2.1-or-later"
|
| "LGPL-2.1-or-later"
|
||||||
|"LGPL-3.0-only"
|
| "LGPL-3.0-only"
|
||||||
|"LGPL-3.0-or-later"
|
| "LGPL-3.0-or-later"
|
||||||
|"EPL-1.0"
|
| "EPL-1.0"
|
||||||
|"EPL-2.0"
|
| "EPL-2.0"
|
||||||
|"UPL-1.0"
|
| "UPL-1.0"
|
||||||
|"BSL-1.0"
|
| "BSL-1.0"
|
||||||
|"Unlicense"
|
| "Unlicense"
|
||||||
|
|
||||||
@Unlisted
|
@Unlisted
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
|
|||||||
+188
-92
@@ -21,8 +21,8 @@
|
|||||||
module pkl.base
|
module pkl.base
|
||||||
|
|
||||||
import "pkl:jsonnet"
|
import "pkl:jsonnet"
|
||||||
import "pkl:xml"
|
|
||||||
import "pkl:protobuf"
|
import "pkl:protobuf"
|
||||||
|
import "pkl:xml"
|
||||||
|
|
||||||
/// The top type of the type hierarchy.
|
/// The top type of the type hierarchy.
|
||||||
///
|
///
|
||||||
@@ -96,15 +96,26 @@ abstract external class Module {
|
|||||||
value = outer
|
value = outer
|
||||||
renderer =
|
renderer =
|
||||||
let (format = read?("prop:pkl.outputFormat") ?? "pcf")
|
let (format = read?("prop:pkl.outputFormat") ?? "pcf")
|
||||||
if (format == "json") new JsonRenderer {}
|
if (format == "json")
|
||||||
else if (format == "jsonnet") new jsonnet.Renderer {}
|
new JsonRenderer {}
|
||||||
else if (format == "pcf") new PcfRenderer {}
|
else if (format == "jsonnet")
|
||||||
else if (format == "plist") new PListRenderer {}
|
new jsonnet.Renderer {}
|
||||||
else if (format == "properties") new PropertiesRenderer {}
|
else if (format == "pcf")
|
||||||
else if (format == "textproto") new protobuf.Renderer {}
|
new PcfRenderer {}
|
||||||
else if (format == "xml") new xml.Renderer {}
|
else if (format == "plist")
|
||||||
else if (format == "yaml") new YamlRenderer {}
|
new PListRenderer {}
|
||||||
else throw("Unknown output format: `\(format)`. Supported formats are `json`, `jsonnet`, `pcf`, `plist`, `properties`, `textproto`, `xml`, `yaml`.")
|
else if (format == "properties")
|
||||||
|
new PropertiesRenderer {}
|
||||||
|
else if (format == "textproto")
|
||||||
|
new protobuf.Renderer {}
|
||||||
|
else if (format == "xml")
|
||||||
|
new xml.Renderer {}
|
||||||
|
else if (format == "yaml")
|
||||||
|
new YamlRenderer {}
|
||||||
|
else
|
||||||
|
throw(
|
||||||
|
"Unknown output format: `\(format)`. Supported formats are `json`, `jsonnet`, `pcf`, `plist`, `properties`, `textproto`, `xml`, `yaml`."
|
||||||
|
)
|
||||||
text = renderer.renderDocument(value)
|
text = renderer.renderDocument(value)
|
||||||
bytes = text.encodeToBytes("UTF-8")
|
bytes = text.encodeToBytes("UTF-8")
|
||||||
}
|
}
|
||||||
@@ -179,7 +190,18 @@ class SourceCode extends Annotation {
|
|||||||
/// - `"x = 42"` is valid source code for language `"Pkl"`.
|
/// - `"x = 42"` is valid source code for language `"Pkl"`.
|
||||||
/// - `"42"` is valid source code for language `"PklExpr"`.
|
/// - `"42"` is valid source code for language `"PklExpr"`.
|
||||||
/// - `"42"` is valid source code for language `"Pkl"` with [prefix] `"x = "`.
|
/// - `"42"` is valid source code for language `"Pkl"` with [prefix] `"x = "`.
|
||||||
language: "Go"|"HTML"|"Java"|"JavaScript"|"Markdown"|"Pkl"|"PklExpr"|"Python"|"Ruby"|"SQL"|"Swift"|String
|
language: "Go"
|
||||||
|
| "HTML"
|
||||||
|
| "Java"
|
||||||
|
| "JavaScript"
|
||||||
|
| "Markdown"
|
||||||
|
| "Pkl"
|
||||||
|
| "PklExpr"
|
||||||
|
| "Python"
|
||||||
|
| "Ruby"
|
||||||
|
| "SQL"
|
||||||
|
| "Swift"
|
||||||
|
| String
|
||||||
|
|
||||||
/// A source code prefix to help tools understand the source code.
|
/// A source code prefix to help tools understand the source code.
|
||||||
///
|
///
|
||||||
@@ -307,7 +329,7 @@ abstract class ValueRenderer {
|
|||||||
/// Paths are matched against path specs component-wise in reverse order.
|
/// Paths are matched against path specs component-wise in reverse order.
|
||||||
/// For example, paths `server.timeout` and `racks[*].server.timeout`
|
/// For example, paths `server.timeout` and `racks[*].server.timeout`
|
||||||
/// both match path spec `server.timeout`, whereas path `server.timeout.millis` does not.
|
/// both match path spec `server.timeout`, whereas path `server.timeout.millis` does not.
|
||||||
converters: Mapping<Class|String, (unknown) -> Any>
|
converters: Mapping<Class | String, (unknown) -> Any>
|
||||||
|
|
||||||
/// The file extension associated with this output format,
|
/// The file extension associated with this output format,
|
||||||
/// or [null] if this format does not have an extension.
|
/// or [null] if this format does not have an extension.
|
||||||
@@ -426,7 +448,7 @@ class YamlRenderer extends ValueRenderer {
|
|||||||
/// At present, the mode only affects which String values are quoted in YAML.
|
/// At present, the mode only affects which String values are quoted in YAML.
|
||||||
/// For example, `x = "yes"` is rendered as `x: 'yes'` in modes `"compat"` and `"1.1"`,
|
/// For example, `x = "yes"` is rendered as `x: 'yes'` in modes `"compat"` and `"1.1"`,
|
||||||
/// and as `x: yes` in mode `"1.2"`.
|
/// and as `x: yes` in mode `"1.2"`.
|
||||||
mode: "compat"|"1.1"|"1.2" = "compat"
|
mode: "compat" | "1.1" | "1.2" = "compat"
|
||||||
|
|
||||||
/// The number of spaces to use for indenting output.
|
/// The number of spaces to use for indenting output.
|
||||||
indentWidth: Int(this > 1) = 2
|
indentWidth: Int(this > 1) = 2
|
||||||
@@ -965,7 +987,7 @@ typealias UInt32 = Int(isBetween(0, 4294967295))
|
|||||||
typealias UInt = Int(isPositive)
|
typealias UInt = Int(isPositive)
|
||||||
|
|
||||||
/// A value that can be compared to another value of the same type with `<`, `>`, `<=`, and `>=`.
|
/// A value that can be compared to another value of the same type with `<`, `>`, `<=`, and `>=`.
|
||||||
typealias Comparable = String|Number|Duration|DataSize
|
typealias Comparable = String | Number | Duration | DataSize
|
||||||
|
|
||||||
/// A 64-bit floating-point number conforming to the IEEE 754 binary64 format.
|
/// A 64-bit floating-point number conforming to the IEEE 754 binary64 format.
|
||||||
///
|
///
|
||||||
@@ -1266,37 +1288,37 @@ external class String extends Any {
|
|||||||
external function repeat(count: UInt): String
|
external function repeat(count: UInt): String
|
||||||
|
|
||||||
/// Tells whether this string contains [pattern].
|
/// Tells whether this string contains [pattern].
|
||||||
external function contains(pattern: String|Regex): Boolean
|
external function contains(pattern: String | Regex): Boolean
|
||||||
|
|
||||||
/// Tells whether this string matches [regex] in its entirety.
|
/// Tells whether this string matches [regex] in its entirety.
|
||||||
@AlsoKnownAs { names { "test" } }
|
@AlsoKnownAs { names { "test" } }
|
||||||
external function matches(regex: Regex): Boolean
|
external function matches(regex: Regex): Boolean
|
||||||
|
|
||||||
/// Tells whether this string starts with [pattern].
|
/// Tells whether this string starts with [pattern].
|
||||||
external function startsWith(pattern: String|Regex): Boolean
|
external function startsWith(pattern: String | Regex): Boolean
|
||||||
|
|
||||||
/// Tells whether this string ends with [pattern].
|
/// Tells whether this string ends with [pattern].
|
||||||
external function endsWith(pattern: String|Regex): Boolean
|
external function endsWith(pattern: String | Regex): Boolean
|
||||||
|
|
||||||
/// Returns the zero-based index of the first occurrence of [pattern]
|
/// Returns the zero-based index of the first occurrence of [pattern]
|
||||||
/// in this string.
|
/// in this string.
|
||||||
///
|
///
|
||||||
/// Throws if [pattern] does not occur in this string.
|
/// Throws if [pattern] does not occur in this string.
|
||||||
external function indexOf(pattern: String|Regex): Int
|
external function indexOf(pattern: String | Regex): Int
|
||||||
|
|
||||||
/// Returns the zero-based index of the first occurrence of [pattern]
|
/// Returns the zero-based index of the first occurrence of [pattern]
|
||||||
/// in this string, or [null] if [pattern] does not occur in this string.
|
/// in this string, or [null] if [pattern] does not occur in this string.
|
||||||
external function indexOfOrNull(pattern: String|Regex): Int?
|
external function indexOfOrNull(pattern: String | Regex): Int?
|
||||||
|
|
||||||
/// Returns the zero-based index of the last occurrence of [pattern]
|
/// Returns the zero-based index of the last occurrence of [pattern]
|
||||||
/// in this string.
|
/// in this string.
|
||||||
///
|
///
|
||||||
/// Throws if [pattern] does not occur in this string.
|
/// Throws if [pattern] does not occur in this string.
|
||||||
external function lastIndexOf(pattern: String|Regex): Int
|
external function lastIndexOf(pattern: String | Regex): Int
|
||||||
|
|
||||||
/// Returns the zero-based index of the last occurrence of [pattern]
|
/// Returns the zero-based index of the last occurrence of [pattern]
|
||||||
/// in this string, or [null] if [pattern] does not occur in this string.
|
/// in this string, or [null] if [pattern] does not occur in this string.
|
||||||
external function lastIndexOfOrNull(pattern: String|Regex): Int?
|
external function lastIndexOfOrNull(pattern: String | Regex): Int?
|
||||||
|
|
||||||
/// Returns the first [n] characters of this string.
|
/// Returns the first [n] characters of this string.
|
||||||
///
|
///
|
||||||
@@ -1338,32 +1360,41 @@ external class String extends Any {
|
|||||||
/// Replaces the first occurrence of [pattern] in this string with [replacement].
|
/// Replaces the first occurrence of [pattern] in this string with [replacement].
|
||||||
///
|
///
|
||||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||||
external function replaceFirst(pattern: String|Regex, replacement: String): String
|
external function replaceFirst(pattern: String | Regex, replacement: String): String
|
||||||
|
|
||||||
/// Replaces the last occurrence of [pattern] in this string with [replacement].
|
/// Replaces the last occurrence of [pattern] in this string with [replacement].
|
||||||
///
|
///
|
||||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||||
external function replaceLast(pattern: String|Regex, replacement: String): String
|
external function replaceLast(pattern: String | Regex, replacement: String): String
|
||||||
|
|
||||||
/// Replaces all occurrences of [pattern] in this string with [replacement].
|
/// Replaces all occurrences of [pattern] in this string with [replacement].
|
||||||
///
|
///
|
||||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||||
external function replaceAll(pattern: String|Regex, replacement: String): String
|
external function replaceAll(pattern: String | Regex, replacement: String): String
|
||||||
|
|
||||||
/// Replaces the first occurrence of [pattern] in this string with the return value of [mapper].
|
/// Replaces the first occurrence of [pattern] in this string with the return value of [mapper].
|
||||||
///
|
///
|
||||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||||
external function replaceFirstMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
external function replaceFirstMapped(
|
||||||
|
pattern: String | Regex,
|
||||||
|
mapper: (RegexMatch) -> String,
|
||||||
|
): String
|
||||||
|
|
||||||
/// Replaces the last occurrence of [pattern] in this string with the return value of [mapper].
|
/// Replaces the last occurrence of [pattern] in this string with the return value of [mapper].
|
||||||
///
|
///
|
||||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||||
external function replaceLastMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
external function replaceLastMapped(
|
||||||
|
pattern: String | Regex,
|
||||||
|
mapper: (RegexMatch) -> String,
|
||||||
|
): String
|
||||||
|
|
||||||
/// Replaces all occurrences of [pattern] in this string with the return value of [mapper].
|
/// Replaces all occurrences of [pattern] in this string with the return value of [mapper].
|
||||||
///
|
///
|
||||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||||
external function replaceAllMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
external function replaceAllMapped(
|
||||||
|
pattern: String | Regex,
|
||||||
|
mapper: (RegexMatch) -> String,
|
||||||
|
): String
|
||||||
|
|
||||||
/// Replaces the characters between [start] and [exclusiveEnd] with [replacement].
|
/// Replaces the characters between [start] and [exclusiveEnd] with [replacement].
|
||||||
///
|
///
|
||||||
@@ -1404,10 +1435,10 @@ external class String extends Any {
|
|||||||
external function padEnd(width: Int, char: Char)
|
external function padEnd(width: Int, char: Char)
|
||||||
|
|
||||||
/// Splits this string around matches of [pattern].
|
/// Splits this string around matches of [pattern].
|
||||||
external function split(pattern: String|Regex): List<String>
|
external function split(pattern: String | Regex): List<String>
|
||||||
|
|
||||||
/// Splits this string matches of [pattern], up to [limit] substrings.
|
/// Splits this string matches of [pattern], up to [limit] substrings.
|
||||||
///
|
///
|
||||||
/// Returns a [List] with at most [limit] elements.
|
/// Returns a [List] with at most [limit] elements.
|
||||||
/// If the limit has been reached, the last entry will contain the un-split remainder of this string.
|
/// If the limit has been reached, the last entry will contain the un-split remainder of this string.
|
||||||
///
|
///
|
||||||
@@ -1418,8 +1449,8 @@ external class String extends Any {
|
|||||||
/// "a.b.c".splitLimit(".", 50) == List("a", "b", "c")
|
/// "a.b.c".splitLimit(".", 50) == List("a", "b", "c")
|
||||||
/// "a.b:c".splitLimit(Regex("[.:]"), 3) == List("a", "b", "c")
|
/// "a.b:c".splitLimit(Regex("[.:]"), 3) == List("a", "b", "c")
|
||||||
/// ```
|
/// ```
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
external function splitLimit(pattern: String|Regex, limit: Int(this > 0)): List<String>
|
external function splitLimit(pattern: String | Regex, limit: Int(this > 0)): List<String>
|
||||||
|
|
||||||
/// Converts the first character of this string to title case.
|
/// Converts the first character of this string to title case.
|
||||||
///
|
///
|
||||||
@@ -1489,7 +1520,7 @@ external class String extends Any {
|
|||||||
/// * `"UTF-16"`: <https://en.wikipedia.org/wiki/UTF-16>
|
/// * `"UTF-16"`: <https://en.wikipedia.org/wiki/UTF-16>
|
||||||
/// * `"ISO-8859-1"` (also known as latin1): <https://en.wikipedia.org/wiki/ISO/IEC_8859-1>
|
/// * `"ISO-8859-1"` (also known as latin1): <https://en.wikipedia.org/wiki/ISO/IEC_8859-1>
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
typealias Charset = "UTF-8"|"UTF-16"|"ISO-8859-1"
|
typealias Charset = "UTF-8" | "UTF-16" | "ISO-8859-1"
|
||||||
|
|
||||||
/// A string representing a [URI](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier).
|
/// A string representing a [URI](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier).
|
||||||
typealias Uri = String
|
typealias Uri = String
|
||||||
@@ -1556,7 +1587,7 @@ class RegexMatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The unit of a [Duration].
|
/// The unit of a [Duration].
|
||||||
typealias DurationUnit = "ns"|"us"|"ms"|"s"|"min"|"h"|"d"
|
typealias DurationUnit = "ns" | "us" | "ms" | "s" | "min" | "h" | "d"
|
||||||
|
|
||||||
/// A quantity of elapsed time, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `min`).
|
/// A quantity of elapsed time, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `min`).
|
||||||
external class Duration extends Any {
|
external class Duration extends Any {
|
||||||
@@ -1630,7 +1661,8 @@ external class Duration extends Any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The unit of a [DataSize].
|
/// The unit of a [DataSize].
|
||||||
typealias DataSizeUnit = "b"|"kb"|"kib"|"mb"|"mib"|"gb"|"gib"|"tb"|"tib"|"pb"|"pib"
|
typealias DataSizeUnit =
|
||||||
|
"b" | "kb" | "kib" | "mb" | "mib" | "gb" | "gib" | "tb" | "tib" | "pb" | "pib"
|
||||||
|
|
||||||
/// A quantity of binary data, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `mb`).
|
/// A quantity of binary data, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `mb`).
|
||||||
external class DataSize extends Any {
|
external class DataSize extends Any {
|
||||||
@@ -1894,7 +1926,7 @@ class Listing<out Element> extends Object {
|
|||||||
/// Returns the element at [index].
|
/// Returns the element at [index].
|
||||||
///
|
///
|
||||||
/// Returns [default] applied to [index] if [index] is outside the bounds of this listing.
|
/// Returns [default] applied to [index] if [index] is outside the bounds of this listing.
|
||||||
///
|
///
|
||||||
/// This is equivalent to `getOrNull(index) ?? default.apply(index)`.
|
/// This is equivalent to `getOrNull(index) ?? default.apply(index)`.
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
external function getOrDefault(index: Int): Element
|
external function getOrDefault(index: Int): Element
|
||||||
@@ -1989,13 +2021,13 @@ class Listing<out Element> extends Object {
|
|||||||
external function distinctBy(selector: (Element) -> Any): Listing<Element>
|
external function distinctBy(selector: (Element) -> Any): Listing<Element>
|
||||||
|
|
||||||
/// Tells if [predicate] holds for every element of this listing.
|
/// Tells if [predicate] holds for every element of this listing.
|
||||||
///
|
///
|
||||||
/// Returns [true] for an empty listing.
|
/// Returns [true] for an empty listing.
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
external function every(predicate: (Element) -> Boolean): Boolean
|
external function every(predicate: (Element) -> Boolean): Boolean
|
||||||
|
|
||||||
/// Tells if [predicate] holds for at least one element of this listing.
|
/// Tells if [predicate] holds for at least one element of this listing.
|
||||||
///
|
///
|
||||||
/// Returns [false] for an empty listing.
|
/// Returns [false] for an empty listing.
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
external function any(predicate: (Element) -> Boolean): Boolean
|
external function any(predicate: (Element) -> Boolean): Boolean
|
||||||
@@ -2018,7 +2050,10 @@ class Listing<out Element> extends Object {
|
|||||||
/// Folds this listing in iteration order using [operator], starting with [initial].
|
/// Folds this listing in iteration order using [operator], starting with [initial].
|
||||||
///
|
///
|
||||||
/// The first parameter of [operator] is the zero-based index of the current element.
|
/// The first parameter of [operator] is the zero-based index of the current element.
|
||||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
external function foldIndexed<Result>(
|
||||||
|
initial: Result,
|
||||||
|
operator: (Int, Result, Element) -> Result,
|
||||||
|
): Result
|
||||||
|
|
||||||
/// Converts the elements of this listing to strings and concatenates them inserting [separator] between elements.
|
/// Converts the elements of this listing to strings and concatenates them inserting [separator] between elements.
|
||||||
external function join(separator: String): String
|
external function join(separator: String): String
|
||||||
@@ -2052,9 +2087,9 @@ class Mapping<out Key, out Value> extends Object {
|
|||||||
|
|
||||||
/// Tells if this mapping contains [key].
|
/// Tells if this mapping contains [key].
|
||||||
external function containsKey(key: Any): Boolean
|
external function containsKey(key: Any): Boolean
|
||||||
|
|
||||||
/// Tells if this mapping contains an entry with the given [value].
|
/// Tells if this mapping contains an entry with the given [value].
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
external function containsValue(value: Any): Boolean
|
external function containsValue(value: Any): Boolean
|
||||||
|
|
||||||
/// Returns the value associated with [key] or [null] if this mapping does not contain [key].
|
/// Returns the value associated with [key] or [null] if this mapping does not contain [key].
|
||||||
@@ -2066,20 +2101,20 @@ class Mapping<out Key, out Value> extends Object {
|
|||||||
/// not contain [key].
|
/// not contain [key].
|
||||||
///
|
///
|
||||||
/// This is equivalent to `getOrNull(key) ?? default.apply(key)`.
|
/// This is equivalent to `getOrNull(key) ?? default.apply(key)`.
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
external function getOrDefault(key: Any): Value
|
external function getOrDefault(key: Any): Value
|
||||||
|
|
||||||
/// Folds the entries of this mapping in iteration order using [operator], starting with [initial].
|
/// Folds the entries of this mapping in iteration order using [operator], starting with [initial].
|
||||||
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
||||||
|
|
||||||
/// Tells if [predicate] holds for every entry of this mapping.
|
/// Tells if [predicate] holds for every entry of this mapping.
|
||||||
///
|
///
|
||||||
/// Returns [true] for an empty mapping.
|
/// Returns [true] for an empty mapping.
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
external function every(predicate: (Key, Value) -> Boolean): Boolean
|
external function every(predicate: (Key, Value) -> Boolean): Boolean
|
||||||
|
|
||||||
/// Tells if [predicate] holds for at least one entry of this mapping.
|
/// Tells if [predicate] holds for at least one entry of this mapping.
|
||||||
///
|
///
|
||||||
/// Returns [false] for an empty mapping.
|
/// Returns [false] for an empty mapping.
|
||||||
@Since { version = "0.27.0" }
|
@Since { version = "0.27.0" }
|
||||||
external function any(predicate: (Key, Value) -> Boolean): Boolean
|
external function any(predicate: (Key, Value) -> Boolean): Boolean
|
||||||
@@ -2119,13 +2154,15 @@ external class Function3<in Param1, in Param2, in Param3, out Result> extends Fu
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A function literal with four parameters.
|
/// A function literal with four parameters.
|
||||||
external class Function4<in Param1, in Param2, in Param3, in Param4, out Result> extends Function<Result> {
|
external class Function4<in Param1, in Param2, in Param3, in Param4, out Result>
|
||||||
|
extends Function<Result> {
|
||||||
@AlsoKnownAs { names { "call"; "invoke" } }
|
@AlsoKnownAs { names { "call"; "invoke" } }
|
||||||
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4): Result
|
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4): Result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A function literal with five parameters.
|
/// A function literal with five parameters.
|
||||||
external class Function5<in Param1, in Param2, in Param3, in Param4, in Param5, out Result> extends Function<Result> {
|
external class Function5<in Param1, in Param2, in Param3, in Param4, in Param5, out Result>
|
||||||
|
extends Function<Result> {
|
||||||
@AlsoKnownAs { names { "call"; "invoke" } }
|
@AlsoKnownAs { names { "call"; "invoke" } }
|
||||||
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4, p5: Param5): Result
|
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4, p5: Param5): Result
|
||||||
}
|
}
|
||||||
@@ -2157,7 +2194,7 @@ external const function Undefined(): nothing
|
|||||||
const function TODO(): nothing = throw("TODO")
|
const function TODO(): nothing = throw("TODO")
|
||||||
|
|
||||||
/// Creates a null value that turns into [defaultValue] when amended.
|
/// Creates a null value that turns into [defaultValue] when amended.
|
||||||
external const function Null(defaultValue: Object|Function<Object>): Null
|
external const function Null(defaultValue: Object | Function<Object>): Null
|
||||||
|
|
||||||
/// Constructs a [Pair].
|
/// Constructs a [Pair].
|
||||||
external const function Pair<First, Second>(first: First, second: Second): Pair<First, Second>
|
external const function Pair<First, Second>(first: First, second: Second): Pair<First, Second>
|
||||||
@@ -2312,7 +2349,9 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// Same as [split()] but returns [null] if [index] is outside range `0`..[length].
|
/// Same as [split()] but returns [null] if [index] is outside range `0`..[length].
|
||||||
abstract function splitOrNull(index: Int): Pair<Collection<Element>, Collection<Element>>?
|
abstract function splitOrNull(index: Int): Pair<Collection<Element>, Collection<Element>>?
|
||||||
|
|
||||||
abstract function partition(predicate: (Element) -> Boolean): Pair<Collection<Element>, Collection<Element>>
|
abstract function partition(
|
||||||
|
predicate: (Element) -> Boolean,
|
||||||
|
): Pair<Collection<Element>, Collection<Element>>
|
||||||
|
|
||||||
/// The zero-based index of the first occurrence of [element] in this collection.
|
/// The zero-based index of the first occurrence of [element] in this collection.
|
||||||
///
|
///
|
||||||
@@ -2384,11 +2423,11 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// List(4, 6, 8).findIndex((n) -> n.isEven) == 0
|
/// List(4, 6, 8).findIndex((n) -> n.isEven) == 0
|
||||||
/// import("pkl:test").catch(() -> List(5, 7, 9).findLast((n) -> n.isEven))
|
/// import("pkl:test").catch(() -> List(5, 7, 9).findLast((n) -> n.isEven))
|
||||||
/// ```
|
/// ```
|
||||||
@AlsoKnownAs { names { "indexWhere" }}
|
@AlsoKnownAs { names { "indexWhere" } }
|
||||||
abstract function findIndex(predicate: (Element) -> Boolean): Int
|
abstract function findIndex(predicate: (Element) -> Boolean): Int
|
||||||
|
|
||||||
/// Same as [findIndex()] but returns [null] if [predicate] does not hold for any element in this collection.
|
/// Same as [findIndex()] but returns [null] if [predicate] does not hold for any element in this collection.
|
||||||
@AlsoKnownAs { names { "indexWhere" }}
|
@AlsoKnownAs { names { "indexWhere" } }
|
||||||
abstract function findIndexOrNull(predicate: (Element) -> Boolean): Int?
|
abstract function findIndexOrNull(predicate: (Element) -> Boolean): Int?
|
||||||
|
|
||||||
/// The index of the last element for which [predicate] returns [true].
|
/// The index of the last element for which [predicate] returns [true].
|
||||||
@@ -2401,11 +2440,11 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// List(4, 6, 8).findLastIndex((n) -> n.isEven) == 2
|
/// List(4, 6, 8).findLastIndex((n) -> n.isEven) == 2
|
||||||
/// import("pkl:test").catch(() -> List(5, 7, 9).findLastIndex((n) -> n.isEven))
|
/// import("pkl:test").catch(() -> List(5, 7, 9).findLastIndex((n) -> n.isEven))
|
||||||
/// ```
|
/// ```
|
||||||
@AlsoKnownAs { names { "lastIndexWhere" }}
|
@AlsoKnownAs { names { "lastIndexWhere" } }
|
||||||
abstract function findLastIndex(predicate: (Element) -> Boolean): Int
|
abstract function findLastIndex(predicate: (Element) -> Boolean): Int
|
||||||
|
|
||||||
/// Same as [findLastIndex()] but returns [null] if [predicate] does not hold for any element in this collection.
|
/// Same as [findLastIndex()] but returns [null] if [predicate] does not hold for any element in this collection.
|
||||||
@AlsoKnownAs { names { "lastIndexWhere" }}
|
@AlsoKnownAs { names { "lastIndexWhere" } }
|
||||||
abstract function findLastIndexOrNull(predicate: (Element) -> Boolean): Int?
|
abstract function findLastIndexOrNull(predicate: (Element) -> Boolean): Int?
|
||||||
|
|
||||||
/// The number of elements for which [predicate] returns [true].
|
/// The number of elements for which [predicate] returns [true].
|
||||||
@@ -2510,7 +2549,9 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// List(1, 2, 3).mapNonNull((n) -> if (n.isOdd) null else n + 2) == List(4)
|
/// List(1, 2, 3).mapNonNull((n) -> if (n.isOdd) null else n + 2) == List(4)
|
||||||
/// ```
|
/// ```
|
||||||
@AlsoKnownAs { names { "filterMap" } }
|
@AlsoKnownAs { names { "filterMap" } }
|
||||||
abstract function mapNonNull<Result>(transform: (Element) -> Result): Collection<Result(this != null)>
|
abstract function mapNonNull<Result>(
|
||||||
|
transform: (Element) -> Result,
|
||||||
|
): Collection<Result(this != null)>
|
||||||
|
|
||||||
/// Transforms this collection by applying [transform] to each element and removing resulting [null] elements.
|
/// Transforms this collection by applying [transform] to each element and removing resulting [null] elements.
|
||||||
///
|
///
|
||||||
@@ -2522,7 +2563,9 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// List(1, 2, 3, 4, null).mapNonNullIndexed((i, n) -> if (n?.isOdd ?? true) null else n * i) == List(2, 12)
|
/// List(1, 2, 3, 4, null).mapNonNullIndexed((i, n) -> if (n?.isOdd ?? true) null else n * i) == List(2, 12)
|
||||||
/// ```
|
/// ```
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
abstract function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): Collection<Result(this != null)>
|
abstract function mapNonNullIndexed<Result>(
|
||||||
|
transform: (Int, Element) -> Result,
|
||||||
|
): Collection<Result(this != null)>
|
||||||
|
|
||||||
/// Applies a collection-generating [transform] to each element in this collection
|
/// Applies a collection-generating [transform] to each element in this collection
|
||||||
/// and concatenates the resulting collections.
|
/// and concatenates the resulting collections.
|
||||||
@@ -2536,7 +2579,9 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// [transform] takes two arguments: the index of the element, and the element itself.
|
/// [transform] takes two arguments: the index of the element, and the element itself.
|
||||||
///
|
///
|
||||||
/// Throws if [transform] produces a non-collection value.
|
/// Throws if [transform] produces a non-collection value.
|
||||||
abstract function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): Collection<Result>
|
abstract function flatMapIndexed<Result>(
|
||||||
|
transform: (Int, Element) -> Collection<Result>,
|
||||||
|
): Collection<Result>
|
||||||
|
|
||||||
/// Concatenates the elements in this collection, each of which must itself be a collection.
|
/// Concatenates the elements in this collection, each of which must itself be a collection.
|
||||||
///
|
///
|
||||||
@@ -2547,7 +2592,7 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// Adds [element] to this collection.
|
/// Adds [element] to this collection.
|
||||||
///
|
///
|
||||||
/// For [List], [element] is appended.
|
/// For [List], [element] is appended.
|
||||||
abstract function add<Other>(element: Other): Collection<Element|Other>
|
abstract function add<Other>(element: Other): Collection<Element | Other>
|
||||||
|
|
||||||
/// Returns the first [n] elements in this collection.
|
/// Returns the first [n] elements in this collection.
|
||||||
@AlsoKnownAs { names { "limit" } }
|
@AlsoKnownAs { names { "limit" } }
|
||||||
@@ -2588,15 +2633,18 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// Folds this collection in iteration order using [operator], starting with [initial].
|
/// Folds this collection in iteration order using [operator], starting with [initial].
|
||||||
///
|
///
|
||||||
/// The first parameter of [operator] is the zero-based index of the current element.
|
/// The first parameter of [operator] is the zero-based index of the current element.
|
||||||
abstract function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
abstract function foldIndexed<Result>(
|
||||||
|
initial: Result,
|
||||||
|
operator: (Int, Result, Element) -> Result,
|
||||||
|
): Result
|
||||||
|
|
||||||
/// Folds this collection in iteration order using [operator], starting with the first element.
|
/// Folds this collection in iteration order using [operator], starting with the first element.
|
||||||
///
|
///
|
||||||
/// Throws if this collection is empty.
|
/// Throws if this collection is empty.
|
||||||
abstract function reduce<Result>(operator: (Element|Result, Element) -> Result): Result
|
abstract function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||||
|
|
||||||
/// Same as [reduce()] but returns [null] if this collection is empty.
|
/// Same as [reduce()] but returns [null] if this collection is empty.
|
||||||
abstract function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result?
|
abstract function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||||
|
|
||||||
/// Groups the elements in this collection according to keys returned by [selector].
|
/// Groups the elements in this collection according to keys returned by [selector].
|
||||||
abstract function groupBy<Key>(selector: (Element) -> Key): Map<Key, Collection<Element>>
|
abstract function groupBy<Key>(selector: (Element) -> Key): Map<Key, Collection<Element>>
|
||||||
@@ -2659,10 +2707,12 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// [comparator] should return [true] if its first argument is less than its second argument, and [false] otherwise.
|
/// [comparator] should return [true] if its first argument is less than its second argument, and [false] otherwise.
|
||||||
///
|
///
|
||||||
/// Throws if this collection is empty.
|
/// Throws if this collection is empty.
|
||||||
abstract function maxWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element
|
abstract function maxWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||||
|
|
||||||
/// Same as [maxWith()] but returns [null] if this collection is empty.
|
/// Same as [maxWith()] but returns [null] if this collection is empty.
|
||||||
abstract function maxWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
abstract function maxWithOrNull(
|
||||||
|
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||||
|
): Element?
|
||||||
|
|
||||||
/// Sorts this collection of [Comparable] elements in ascending order.
|
/// Sorts this collection of [Comparable] elements in ascending order.
|
||||||
///
|
///
|
||||||
@@ -2687,7 +2737,9 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
/// ```
|
/// ```
|
||||||
/// List(1, 2, 3).sortWith((a, b) -> a > b)) == List(3, 2, 1)
|
/// List(1, 2, 3).sortWith((a, b) -> a > b)) == List(3, 2, 1)
|
||||||
/// ```
|
/// ```
|
||||||
abstract function sortWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Collection<Element>
|
abstract function sortWith(
|
||||||
|
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||||
|
): Collection<Element>
|
||||||
|
|
||||||
/// Reverses the order of elements in this collection.
|
/// Reverses the order of elements in this collection.
|
||||||
abstract function reverse(): Collection<Element>
|
abstract function reverse(): Collection<Element>
|
||||||
@@ -2725,7 +2777,10 @@ abstract external class Collection<out Element> extends Any {
|
|||||||
abstract function toSet(): Set<Element>
|
abstract function toSet(): Set<Element>
|
||||||
|
|
||||||
/// Converts this collection to a map by extracting a key and value from each element using the given functions.
|
/// Converts this collection to a map by extracting a key and value from each element using the given functions.
|
||||||
abstract function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
abstract function toMap<Key, Value>(
|
||||||
|
keyExtractor: (Element) -> Key,
|
||||||
|
valueExtractor: (Element) -> Value,
|
||||||
|
): Map<Key, Value>
|
||||||
|
|
||||||
/// Converts this collection to a [Listing].
|
/// Converts this collection to a [Listing].
|
||||||
abstract function toListing(): Listing<Element>
|
abstract function toListing(): Listing<Element>
|
||||||
@@ -2959,8 +3014,12 @@ external class List<out Element> extends Collection<Element> {
|
|||||||
external function mapIndexed<Result>(transform: (Int, Element) -> Result): List<Result>
|
external function mapIndexed<Result>(transform: (Int, Element) -> Result): List<Result>
|
||||||
|
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
external function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): List<Result(this != null)>
|
external function mapNonNullIndexed<Result>(
|
||||||
external function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): List<Result>
|
transform: (Int, Element) -> Result,
|
||||||
|
): List<Result(this != null)>
|
||||||
|
external function flatMapIndexed<Result>(
|
||||||
|
transform: (Int, Element) -> Collection<Result>,
|
||||||
|
): List<Result>
|
||||||
|
|
||||||
external function filterIsInstance<Type>(clazz: Class<Type>): List<Type>
|
external function filterIsInstance<Type>(clazz: Class<Type>): List<Type>
|
||||||
|
|
||||||
@@ -3013,27 +3072,35 @@ external class List<out Element> extends Collection<Element> {
|
|||||||
external function every(predicate: (Element) -> Boolean): Boolean
|
external function every(predicate: (Element) -> Boolean): Boolean
|
||||||
external function any(predicate: (Element) -> Boolean): Boolean
|
external function any(predicate: (Element) -> Boolean): Boolean
|
||||||
|
|
||||||
external function add<Other>(element: Other): List<Element|Other>
|
external function add<Other>(element: Other): List<Element | Other>
|
||||||
|
|
||||||
/// Replaces the element at [index] with [replacement].
|
/// Replaces the element at [index] with [replacement].
|
||||||
///
|
///
|
||||||
/// Throws if [index] is outside the bounds of this list.
|
/// Throws if [index] is outside the bounds of this list.
|
||||||
external function replace<Other>(index: Int, replacement: Other): List<Element|Other>
|
external function replace<Other>(index: Int, replacement: Other): List<Element | Other>
|
||||||
|
|
||||||
/// Replaces the element at [index] with [replacement].
|
/// Replaces the element at [index] with [replacement].
|
||||||
///
|
///
|
||||||
/// Returns [null] if [index] is outside the bounds of this list.
|
/// Returns [null] if [index] is outside the bounds of this list.
|
||||||
external function replaceOrNull<Other>(index: Int, replacement: Other): List<Element|Other>?
|
external function replaceOrNull<Other>(index: Int, replacement: Other): List<Element | Other>?
|
||||||
|
|
||||||
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
||||||
///
|
///
|
||||||
/// Throws if [range] or [exclusiveEnd] is outside the bounds of this list.
|
/// Throws if [range] or [exclusiveEnd] is outside the bounds of this list.
|
||||||
external function replaceRange<Other>(start: Int, exclusiveEnd: Int, replacement: Collection<Other>): List<Element|Other>
|
external function replaceRange<Other>(
|
||||||
|
start: Int,
|
||||||
|
exclusiveEnd: Int,
|
||||||
|
replacement: Collection<Other>,
|
||||||
|
): List<Element | Other>
|
||||||
|
|
||||||
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
||||||
///
|
///
|
||||||
/// Returns [null] if [range] or [exclusiveEnd] is outside the bounds of this list.
|
/// Returns [null] if [range] or [exclusiveEnd] is outside the bounds of this list.
|
||||||
external function replaceRangeOrNull<Other>(start: Int, exclusiveEnd: Int, replacement: Collection<Other>): List<Element|Other>?
|
external function replaceRangeOrNull<Other>(
|
||||||
|
start: Int,
|
||||||
|
exclusiveEnd: Int,
|
||||||
|
replacement: Collection<Other>,
|
||||||
|
): List<Element | Other>?
|
||||||
|
|
||||||
external function find(predicate: (Element) -> Boolean): Element
|
external function find(predicate: (Element) -> Boolean): Element
|
||||||
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
||||||
@@ -3067,10 +3134,13 @@ external class List<out Element> extends Collection<Element> {
|
|||||||
|
|
||||||
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
||||||
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
||||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
external function foldIndexed<Result>(
|
||||||
|
initial: Result,
|
||||||
|
operator: (Int, Result, Element) -> Result,
|
||||||
|
): Result
|
||||||
|
|
||||||
external function reduce<Result>(operator: (Element|Result, Element) -> Result): Result
|
external function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||||
external function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result?
|
external function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||||
|
|
||||||
external function groupBy<Key>(selector: (Element) -> Key): Map<Key, List<Element>>
|
external function groupBy<Key>(selector: (Element) -> Key): Map<Key, List<Element>>
|
||||||
|
|
||||||
@@ -3108,7 +3178,10 @@ external class List<out Element> extends Collection<Element> {
|
|||||||
|
|
||||||
external function toSet(): Set<Element>
|
external function toSet(): Set<Element>
|
||||||
|
|
||||||
external function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
external function toMap<Key, Value>(
|
||||||
|
keyExtractor: (Element) -> Key,
|
||||||
|
valueExtractor: (Element) -> Value,
|
||||||
|
): Map<Key, Value>
|
||||||
|
|
||||||
external function toListing(): Listing<Element>
|
external function toListing(): Listing<Element>
|
||||||
|
|
||||||
@@ -3176,8 +3249,12 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
external function mapIndexed<Result>(transform: (Int, Element) -> Result): Set<Result>
|
external function mapIndexed<Result>(transform: (Int, Element) -> Result): Set<Result>
|
||||||
|
|
||||||
@Since { version = "0.29.0" }
|
@Since { version = "0.29.0" }
|
||||||
external function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): Set<Result(this != null)>
|
external function mapNonNullIndexed<Result>(
|
||||||
external function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): Set<Result>
|
transform: (Int, Element) -> Result,
|
||||||
|
): Set<Result(this != null)>
|
||||||
|
external function flatMapIndexed<Result>(
|
||||||
|
transform: (Int, Element) -> Collection<Result>,
|
||||||
|
): Set<Result>
|
||||||
|
|
||||||
external function filterIsInstance<Type>(clazz: Class<Type>): Set<Type>
|
external function filterIsInstance<Type>(clazz: Class<Type>): Set<Type>
|
||||||
|
|
||||||
@@ -3186,7 +3263,7 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
external function every(predicate: (Element) -> Boolean): Boolean
|
external function every(predicate: (Element) -> Boolean): Boolean
|
||||||
external function any(predicate: (Element) -> Boolean): Boolean
|
external function any(predicate: (Element) -> Boolean): Boolean
|
||||||
|
|
||||||
external function add<Other>(element: Other): Set<Element|Other>
|
external function add<Other>(element: Other): Set<Element | Other>
|
||||||
|
|
||||||
external function find(predicate: (Element) -> Boolean): Element
|
external function find(predicate: (Element) -> Boolean): Element
|
||||||
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
||||||
@@ -3208,10 +3285,13 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
|
|
||||||
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
||||||
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
||||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
external function foldIndexed<Result>(
|
||||||
|
initial: Result,
|
||||||
|
operator: (Int, Result, Element) -> Result,
|
||||||
|
): Result
|
||||||
|
|
||||||
external function reduce<Result>(operator: (Element|Result, Element) -> Result): Result
|
external function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||||
external function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result?
|
external function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||||
|
|
||||||
external function groupBy<Key>(selector: (Element) -> Key): Map<Key, Set<Element>>
|
external function groupBy<Key>(selector: (Element) -> Key): Map<Key, Set<Element>>
|
||||||
|
|
||||||
@@ -3223,8 +3303,10 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
external function minBy(selector: (Element) -> Int): Element
|
external function minBy(selector: (Element) -> Int): Element
|
||||||
external function minByOrNull(selector: (Element) -> Int): Element?
|
external function minByOrNull(selector: (Element) -> Int): Element?
|
||||||
|
|
||||||
external function minWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element
|
external function minWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||||
external function minWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
external function minWithOrNull(
|
||||||
|
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||||
|
): Element?
|
||||||
|
|
||||||
external max: Element
|
external max: Element
|
||||||
external maxOrNull: Element?
|
external maxOrNull: Element?
|
||||||
@@ -3232,12 +3314,16 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
external function maxBy(selector: (Element) -> Int): Element
|
external function maxBy(selector: (Element) -> Int): Element
|
||||||
external function maxByOrNull(selector: (Element) -> Int): Element?
|
external function maxByOrNull(selector: (Element) -> Int): Element?
|
||||||
|
|
||||||
external function maxWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element
|
external function maxWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||||
external function maxWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
external function maxWithOrNull(
|
||||||
|
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||||
|
): Element?
|
||||||
|
|
||||||
external function sort(): List<Element>
|
external function sort(): List<Element>
|
||||||
external function sortBy(selector: (Element) -> Comparable): List<Element>
|
external function sortBy(selector: (Element) -> Comparable): List<Element>
|
||||||
external function sortWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): List<Element>
|
external function sortWith(
|
||||||
|
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||||
|
): List<Element>
|
||||||
|
|
||||||
external function reverse(): List<Element>
|
external function reverse(): List<Element>
|
||||||
|
|
||||||
@@ -3249,7 +3335,10 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
|
|
||||||
external function toSet(): Set<Element>
|
external function toSet(): Set<Element>
|
||||||
|
|
||||||
external function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
external function toMap<Key, Value>(
|
||||||
|
keyExtractor: (Element) -> Key,
|
||||||
|
valueExtractor: (Element) -> Value,
|
||||||
|
): Map<Key, Value>
|
||||||
|
|
||||||
external function toListing(): Listing<Element>
|
external function toListing(): Listing<Element>
|
||||||
|
|
||||||
@@ -3257,7 +3346,7 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
|
|
||||||
/// The intersection of this set and [other].
|
/// The intersection of this set and [other].
|
||||||
external function intersect(other: Set): Set<Element>
|
external function intersect(other: Set): Set<Element>
|
||||||
|
|
||||||
/// The difference of this set and [other].
|
/// The difference of this set and [other].
|
||||||
external function difference(other: Set): Set<Element>
|
external function difference(other: Set): Set<Element>
|
||||||
}
|
}
|
||||||
@@ -3271,7 +3360,7 @@ external class Set<out Element> extends Collection<Element> {
|
|||||||
/// Map("name", "Pigeon", "age", 42).keys == Set("name", "age")
|
/// Map("name", "Pigeon", "age", 42).keys == Set("name", "age")
|
||||||
/// Map("name", "Pigeon", "age", 42).values == Set("Pigeon", 42)
|
/// Map("name", "Pigeon", "age", 42).values == Set("Pigeon", 42)
|
||||||
/// ```
|
/// ```
|
||||||
external const function Map<Key, Value>(keysAndValues: VarArgs<Key|Value>): Map<Key, Value>
|
external const function Map<Key, Value>(keysAndValues: VarArgs<Key | Value>): Map<Key, Value>
|
||||||
|
|
||||||
/// A mapping from keys to values.
|
/// A mapping from keys to values.
|
||||||
///
|
///
|
||||||
@@ -3313,7 +3402,10 @@ external class Map<out Key, out Value> extends Any {
|
|||||||
external function containsValue(value: Any): Boolean
|
external function containsValue(value: Any): Boolean
|
||||||
|
|
||||||
/// Adds or updates [key] to [value].
|
/// Adds or updates [key] to [value].
|
||||||
external function put<NewKey, NewValue>(key: NewKey, value: NewValue): Map<NewKey|Key, NewValue|Value>
|
external function put<NewKey, NewValue>(
|
||||||
|
key: NewKey,
|
||||||
|
value: NewValue,
|
||||||
|
): Map<NewKey | Key, NewValue | Value>
|
||||||
|
|
||||||
/// Removes the map entry with the given key.
|
/// Removes the map entry with the given key.
|
||||||
///
|
///
|
||||||
@@ -3327,7 +3419,9 @@ external class Map<out Key, out Value> extends Any {
|
|||||||
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
||||||
|
|
||||||
/// Transforms the entries of this map using [transform].
|
/// Transforms the entries of this map using [transform].
|
||||||
external function map<NewKey, NewValue>(transform: (Key, Value) -> Pair<NewKey, NewValue>): Map<NewKey, NewValue>
|
external function map<NewKey, NewValue>(
|
||||||
|
transform: (Key, Value) -> Pair<NewKey, NewValue>,
|
||||||
|
): Map<NewKey, NewValue>
|
||||||
|
|
||||||
/// Transforms the keys of this map using [transform].
|
/// Transforms the keys of this map using [transform].
|
||||||
external function mapKeys<NewKey>(transform: (Key, Value) -> NewKey): Map<NewKey, Value>
|
external function mapKeys<NewKey>(transform: (Key, Value) -> NewKey): Map<NewKey, Value>
|
||||||
@@ -3336,7 +3430,9 @@ external class Map<out Key, out Value> extends Any {
|
|||||||
external function mapValues<NewValue>(transform: (Key, Value) -> NewValue): Map<Key, NewValue>
|
external function mapValues<NewValue>(transform: (Key, Value) -> NewValue): Map<Key, NewValue>
|
||||||
|
|
||||||
/// Applies a map-generating [transform] to each map entry and concatenates the resulting maps.
|
/// Applies a map-generating [transform] to each map entry and concatenates the resulting maps.
|
||||||
external function flatMap<NewKey, NewValue>(transform: (Key, Value) -> Map<NewKey, NewValue>): Map<NewKey, NewValue>
|
external function flatMap<NewKey, NewValue>(
|
||||||
|
transform: (Key, Value) -> Map<NewKey, NewValue>,
|
||||||
|
): Map<NewKey, NewValue>
|
||||||
|
|
||||||
/// Tells if [predicate] holds for every entry of this map.
|
/// Tells if [predicate] holds for every entry of this map.
|
||||||
///
|
///
|
||||||
|
|||||||
+3
-3
@@ -45,15 +45,15 @@ class Parser {
|
|||||||
/// Value converters to apply to parsed values.
|
/// Value converters to apply to parsed values.
|
||||||
///
|
///
|
||||||
/// For further information see [PcfRenderer.converters].
|
/// For further information see [PcfRenderer.converters].
|
||||||
converters: Mapping<Class|String(!isEmpty), (unknown) -> unknown>
|
converters: Mapping<Class | String(!isEmpty), (unknown) -> unknown>
|
||||||
|
|
||||||
/// Parses [source] as a JSON document.
|
/// Parses [source] as a JSON document.
|
||||||
///
|
///
|
||||||
/// Throws if an error occurs during parsing.
|
/// Throws if an error occurs during parsing.
|
||||||
///
|
///
|
||||||
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
||||||
external function parse(source: Resource|String): Value
|
external function parse(source: Resource | String): Value
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pkl representation of a JSON value.
|
/// Pkl representation of a JSON value.
|
||||||
typealias Value = Null|Boolean|Number|String|Listing|Dynamic|Mapping
|
typealias Value = Null | Boolean | Number | String | Listing | Dynamic | Mapping
|
||||||
|
|||||||
+1
-1
@@ -78,7 +78,7 @@ class Renderer extends ValueRenderer {
|
|||||||
/// If non-empty, renders object fields and array elements on separate lines,
|
/// If non-empty, renders object fields and array elements on separate lines,
|
||||||
/// and strings containing newlines as `|||` multiline text blocks,
|
/// and strings containing newlines as `|||` multiline text blocks,
|
||||||
/// with the given leading line [indent].
|
/// with the given leading line [indent].
|
||||||
indent: String|/*Deprecated*/Null = " "
|
indent: String | /*Deprecated*/ Null = " "
|
||||||
|
|
||||||
/// Whether to omit Jsonnet object fields whose value is `null`.
|
/// Whether to omit Jsonnet object fields whose value is `null`.
|
||||||
omitNullProperties: Boolean = true
|
omitNullProperties: Boolean = true
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ external minPositiveFloat: Float
|
|||||||
/// [1]: https://en.wikipedia.org/wiki/E_(mathematical_constant)
|
/// [1]: https://en.wikipedia.org/wiki/E_(mathematical_constant)
|
||||||
external e: Float
|
external e: Float
|
||||||
|
|
||||||
|
|
||||||
/// The number [π][1].
|
/// The number [π][1].
|
||||||
///
|
///
|
||||||
/// [1]: https://en.wikipedia.org/wiki/Pi
|
/// [1]: https://en.wikipedia.org/wiki/Pi
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ class VirtualMachine {
|
|||||||
/// The operating system of a platform.
|
/// The operating system of a platform.
|
||||||
class OperatingSystem {
|
class OperatingSystem {
|
||||||
/// The name of this operating system.
|
/// The name of this operating system.
|
||||||
name: "macOS"|"Linux"|"Windows"|String
|
name: "macOS" | "Linux" | "Windows" | String
|
||||||
|
|
||||||
/// The version of this operating system.
|
/// The version of this operating system.
|
||||||
version: String
|
version: String
|
||||||
|
|||||||
+4
-4
@@ -216,7 +216,7 @@ external class Module extends Declaration {
|
|||||||
/// A class or type alias declaration.
|
/// A class or type alias declaration.
|
||||||
abstract external class TypeDeclaration extends Declaration {
|
abstract external class TypeDeclaration extends Declaration {
|
||||||
/// The class or type alias reflected upon.
|
/// The class or type alias reflected upon.
|
||||||
abstract hidden reflectee: base.Class|base.TypeAlias
|
abstract hidden reflectee: base.Class | base.TypeAlias
|
||||||
|
|
||||||
/// The module enclosing this type declaration.
|
/// The module enclosing this type declaration.
|
||||||
///
|
///
|
||||||
@@ -298,7 +298,7 @@ external class Property extends Declaration {
|
|||||||
allModifiers: Set<Modifier>
|
allModifiers: Set<Modifier>
|
||||||
|
|
||||||
/// The annotations of this module, appended with any from the containing class's superclasses.
|
/// The annotations of this module, appended with any from the containing class's superclasses.
|
||||||
///
|
///
|
||||||
/// Annotations are ordered starting with the current class and walking up the class hierarchy.
|
/// Annotations are ordered starting with the current class and walking up the class hierarchy.
|
||||||
@Since { version = "0.30.0" }
|
@Since { version = "0.30.0" }
|
||||||
allAnnotations: List<Annotation>
|
allAnnotations: List<Annotation>
|
||||||
@@ -341,13 +341,13 @@ external class TypeParameter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A modifier of a [Declaration].
|
/// A modifier of a [Declaration].
|
||||||
typealias Modifier = "abstract"|"external"|"hidden"|"open"|"fixed"|"const"
|
typealias Modifier = "abstract" | "external" | "hidden" | "open" | "fixed" | "const"
|
||||||
|
|
||||||
/// The variance of a [TypeParameter].
|
/// The variance of a [TypeParameter].
|
||||||
///
|
///
|
||||||
/// An "in" type parameter is contravariant.
|
/// An "in" type parameter is contravariant.
|
||||||
/// An "out" type parameter is covariant.
|
/// An "out" type parameter is covariant.
|
||||||
typealias Variance = "in"|"out"
|
typealias Variance = "in" | "out"
|
||||||
|
|
||||||
/// A type as it occurs, say, in a type annotation.
|
/// A type as it occurs, say, in a type annotation.
|
||||||
abstract external class Type {
|
abstract external class Type {
|
||||||
|
|||||||
+48
-31
@@ -47,7 +47,8 @@ function Version(version: String): Version =
|
|||||||
/// ```
|
/// ```
|
||||||
function parseOrNull(version: String): Version? =
|
function parseOrNull(version: String): Version? =
|
||||||
let (groups = versionRegex.matchEntire(version)?.groups)
|
let (groups = versionRegex.matchEntire(version)?.groups)
|
||||||
if (groups == null) null
|
if (groups == null)
|
||||||
|
null
|
||||||
else
|
else
|
||||||
new Version {
|
new Version {
|
||||||
major = groups[1].value.toInt()
|
major = groups[1].value.toInt()
|
||||||
@@ -99,9 +100,15 @@ class Version {
|
|||||||
/// - `"1.0.0-0.3.7"`
|
/// - `"1.0.0-0.3.7"`
|
||||||
/// - `"1.0.0-x.7.z.92"`
|
/// - `"1.0.0-x.7.z.92"`
|
||||||
/// - `"1.0.0-x-y-z.–"`
|
/// - `"1.0.0-x-y-z.–"`
|
||||||
preRelease: String(matches(Regex(#"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*"#)))?
|
preRelease: String(
|
||||||
|
matches(
|
||||||
|
Regex(
|
||||||
|
#"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*"#,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)?
|
||||||
|
|
||||||
hidden fixed preReleaseIdentifiers: List<Int|String> =
|
hidden fixed preReleaseIdentifiers: List<Int | String> =
|
||||||
if (preRelease == null) List() else preRelease.split(".").map((it) -> it.toIntOrNull() ?? it)
|
if (preRelease == null) List() else preRelease.split(".").map((it) -> it.toIntOrNull() ?? it)
|
||||||
|
|
||||||
/// Build metadata MAY be denoted by appending a plus sign and a series of dot separated identifiers immediately following the patch or pre-release version.
|
/// Build metadata MAY be denoted by appending a plus sign and a series of dot separated identifiers immediately following the patch or pre-release version.
|
||||||
@@ -119,8 +126,7 @@ class Version {
|
|||||||
/// Note: Unlike `==`, [equals()] and comparison methods such as [isLessThan()] ignore [build].
|
/// Note: Unlike `==`, [equals()] and comparison methods such as [isLessThan()] ignore [build].
|
||||||
build: String(matches(Regex(#"[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*"#)))?
|
build: String(matches(Regex(#"[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*"#)))?
|
||||||
|
|
||||||
hidden fixed buildIdentifiers: List<String> =
|
hidden fixed buildIdentifiers: List<String> = if (build == null) List() else build.split(".")
|
||||||
if (build == null) List() else build.split(".")
|
|
||||||
|
|
||||||
/// Tells whether this version is equal to [other] according to semantic versioning rules.
|
/// Tells whether this version is equal to [other] according to semantic versioning rules.
|
||||||
///
|
///
|
||||||
@@ -160,23 +166,19 @@ class Version {
|
|||||||
major < other.major
|
major < other.major
|
||||||
|| major == other.major && minor < other.minor
|
|| major == other.major && minor < other.minor
|
||||||
|| major == other.major && minor == other.minor && patch < other.patch
|
|| major == other.major && minor == other.minor && patch < other.patch
|
||||||
||
|
|| major == other.major
|
||||||
major == other.major
|
&& minor == other.minor
|
||||||
&& minor == other.minor
|
&& patch == other.patch
|
||||||
&& patch == other.patch
|
&& isPreReleaseLessThan(other)
|
||||||
&& isPreReleaseLessThan(other)
|
|
||||||
|
|
||||||
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
|
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
|
||||||
function isLessThanOrEquals(other: Version): Boolean =
|
function isLessThanOrEquals(other: Version): Boolean = isLessThan(other) || equals(other)
|
||||||
isLessThan(other) || equals(other)
|
|
||||||
|
|
||||||
/// Tells whether this version is greater than [other] according to semantic versioning rules.
|
/// Tells whether this version is greater than [other] according to semantic versioning rules.
|
||||||
function isGreaterThan(other: Version): Boolean =
|
function isGreaterThan(other: Version): Boolean = other.isLessThan(this)
|
||||||
other.isLessThan(this)
|
|
||||||
|
|
||||||
/// Tells whether this version is greater than or equal to [other] according to semantic versioning rules.
|
/// Tells whether this version is greater than or equal to [other] according to semantic versioning rules.
|
||||||
function isGreaterThanOrEquals(other: Version): Boolean =
|
function isGreaterThanOrEquals(other: Version): Boolean = other.isLessThanOrEquals(this)
|
||||||
other.isLessThanOrEquals(this)
|
|
||||||
|
|
||||||
/// A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes.
|
/// A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes.
|
||||||
function isNormal(): Boolean = preRelease == null && build == null
|
function isNormal(): Boolean = preRelease == null && build == null
|
||||||
@@ -187,24 +189,39 @@ class Version {
|
|||||||
/// Strips [preRelease] and [build] from this version.
|
/// Strips [preRelease] and [build] from this version.
|
||||||
function toNormal(): Version = (this) { preRelease = null; build = null }
|
function toNormal(): Version = (this) { preRelease = null; build = null }
|
||||||
|
|
||||||
function toString() = "\(major).\(minor).\(patch)\(if (preRelease != null) "-\(preRelease)" else "")\(if (build != null) "+\(build)" else "")"
|
function toString() =
|
||||||
|
"\(major).\(minor).\(patch)\(if (preRelease != null) "-\(preRelease)" else "")\(if (build != null) "+\(build)" else "")"
|
||||||
|
|
||||||
local function isPreReleaseLessThan(other: Version): Boolean =
|
local function isPreReleaseLessThan(other: Version): Boolean =
|
||||||
if (preRelease == null) false
|
if (preRelease == null)
|
||||||
else if (other.preRelease == null) true
|
false
|
||||||
else if (preRelease == other.preRelease) false
|
else if (other.preRelease == null)
|
||||||
|
true
|
||||||
|
else if (preRelease == other.preRelease)
|
||||||
|
false
|
||||||
else
|
else
|
||||||
let (result = preReleaseIdentifiers
|
let (result =
|
||||||
.zip(other.preReleaseIdentifiers)
|
preReleaseIdentifiers
|
||||||
.fold(null, (result, next) ->
|
.zip(other.preReleaseIdentifiers)
|
||||||
if (result != null) result
|
.fold(null, (result, next) ->
|
||||||
else
|
if (result != null)
|
||||||
if (next.first == next.second) null
|
result
|
||||||
else if (next.first.getClass() == next.second.getClass()) next.first < next.second
|
else if (next.first == next.second)
|
||||||
else next.first is Int
|
null
|
||||||
)
|
else if (next.first.getClass() == next.second.getClass())
|
||||||
) if (result != null) result else preReleaseIdentifiers.length < other.preReleaseIdentifiers.length
|
next.first < next.second
|
||||||
|
else
|
||||||
|
next.first is Int
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if (result != null)
|
||||||
|
result
|
||||||
|
else
|
||||||
|
preReleaseIdentifiers.length < other.preReleaseIdentifiers.length
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||||
local versionRegex = Regex(#"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"#)
|
local versionRegex =
|
||||||
|
Regex(
|
||||||
|
#"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"#,
|
||||||
|
)
|
||||||
|
|||||||
+4
-7
@@ -28,10 +28,7 @@ function escapeWithSingleQuotes(str: String): String =
|
|||||||
else if (acc.last.last != "'" && ch != "'")
|
else if (acc.last.last != "'" && ch != "'")
|
||||||
acc.replace(acc.lastIndex, acc.last.add(ch))
|
acc.replace(acc.lastIndex, acc.last.add(ch))
|
||||||
else
|
else
|
||||||
acc.add(List(ch)))
|
acc.add(List(ch))
|
||||||
let (grouped = str.chars.fold(List(), processChar))
|
)
|
||||||
grouped
|
let (grouped = str.chars.fold(List(), processChar))
|
||||||
.map((chSeq) ->
|
grouped.map((chSeq) -> if (chSeq == List("'")) #"\'"# else "'\(chSeq.join(""))'").join("")
|
||||||
if (chSeq == List("'")) #"\'"#
|
|
||||||
else "'\(chSeq.join(""))'")
|
|
||||||
.join("")
|
|
||||||
|
|||||||
+4
-4
@@ -39,13 +39,13 @@ class Renderer extends ValueRenderer {
|
|||||||
indent: String = " "
|
indent: String = " "
|
||||||
|
|
||||||
/// The XML version to use.
|
/// The XML version to use.
|
||||||
xmlVersion: *"1.0"|"1.1"
|
xmlVersion: *"1.0" | "1.1"
|
||||||
|
|
||||||
/// The name of the XML document's root element.
|
/// The name of the XML document's root element.
|
||||||
rootElementName: String(!isEmpty) = "root"
|
rootElementName: String(!isEmpty) = "root"
|
||||||
|
|
||||||
/// The attributes of the XML document's root element.
|
/// The attributes of the XML document's root element.
|
||||||
rootElementAttributes: Mapping<String(!isEmpty), String|Boolean|Int|Float>
|
rootElementAttributes: Mapping<String(!isEmpty), String | Boolean | Int | Float>
|
||||||
|
|
||||||
external function renderDocument(value: Any): String
|
external function renderDocument(value: Any): String
|
||||||
|
|
||||||
@@ -83,12 +83,12 @@ function Element(_name: String(!isEmpty)): Dynamic = new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an [Inline] directive for [_value].
|
/// Creates an [Inline] directive for [_value].
|
||||||
function Inline(_value: Object|Collection|Map): Inline = new { value = _value }
|
function Inline(_value: Object | Collection | Map): Inline = new { value = _value }
|
||||||
|
|
||||||
/// Inlines the members of [value] into the enclosing XML element,
|
/// Inlines the members of [value] into the enclosing XML element,
|
||||||
/// without rendering an XML element for [value] itself.
|
/// without rendering an XML element for [value] itself.
|
||||||
class Inline {
|
class Inline {
|
||||||
value: Object|Collection|Map
|
value: Object | Collection | Map
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an XML [Comment] with the given [_text].
|
/// Creates an XML [Comment] with the given [_text].
|
||||||
|
|||||||
+5
-5
@@ -50,7 +50,7 @@ class Parser {
|
|||||||
/// - `"compat"` - YAML 1.1 _or_ 1.2 (default)
|
/// - `"compat"` - YAML 1.1 _or_ 1.2 (default)
|
||||||
/// - `"1.1"` - YAML 1.1
|
/// - `"1.1"` - YAML 1.1
|
||||||
/// - `"1.2"` - YAML 1.2 (Core schema)
|
/// - `"1.2"` - YAML 1.2 (Core schema)
|
||||||
mode: "compat"|"1.1"|"1.2" = "compat"
|
mode: "compat" | "1.1" | "1.2" = "compat"
|
||||||
|
|
||||||
/// Determines what the parser produces when parsing YAML `!!map` types.
|
/// Determines what the parser produces when parsing YAML `!!map` types.
|
||||||
///
|
///
|
||||||
@@ -64,7 +64,7 @@ class Parser {
|
|||||||
/// Value converters to apply to parsed values.
|
/// Value converters to apply to parsed values.
|
||||||
///
|
///
|
||||||
/// For further information see [PcfRenderer.converters].
|
/// For further information see [PcfRenderer.converters].
|
||||||
converters: Mapping<Class|String(!isEmpty), (unknown) -> unknown>
|
converters: Mapping<Class | String(!isEmpty), (unknown) -> unknown>
|
||||||
|
|
||||||
/// The maximum number of aliases for collection nodes.
|
/// The maximum number of aliases for collection nodes.
|
||||||
///
|
///
|
||||||
@@ -77,15 +77,15 @@ class Parser {
|
|||||||
/// Throws if an error occurs during parsing, or if [source] contains multiple YAML documents.
|
/// Throws if an error occurs during parsing, or if [source] contains multiple YAML documents.
|
||||||
///
|
///
|
||||||
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
||||||
external function parse(source: Resource|String): Value
|
external function parse(source: Resource | String): Value
|
||||||
|
|
||||||
/// Parses all YAML documents contained in [source].
|
/// Parses all YAML documents contained in [source].
|
||||||
///
|
///
|
||||||
/// Throws if an error occurs during parsing.
|
/// Throws if an error occurs during parsing.
|
||||||
///
|
///
|
||||||
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
||||||
external function parseAll(source: Resource|String): List<Value>
|
external function parseAll(source: Resource | String): List<Value>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pkl representation of a YAML value.
|
/// Pkl representation of a YAML value.
|
||||||
typealias Value = Null|Boolean|Number|String|Listing|Dynamic|Mapping
|
typealias Value = Null | Boolean | Number | String | Listing | Dynamic | Mapping
|
||||||
|
|||||||
Reference in New Issue
Block a user