Skip to content

API Reference #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy Docs

on:
push:
branches: [ 'main' ]

permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- uses: actions/cache@v3
with:
path: ~/.konan
key: ${{ runner.os }}-${{ hashFiles('**/.lock') }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build Docs
run: |
./gradlew \
-PGITHUB_PUBLISH_TOKEN=${{ secrets.GITHUB_TOKEN }} \
dokkaGenerate
shell: bash
- name: Upload static files as artifact
id: deployment
uses: actions/upload-pages-artifact@v3
with:
path: build/dokka/html

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
62 changes: 61 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpServer
import java.net.InetSocketAddress
import java.net.URLDecoder
import java.nio.file.Files

plugins {
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.compose.compiler) apply false
Expand All @@ -16,6 +22,8 @@ plugins {
alias(libs.plugins.kotlinter) apply false
alias(libs.plugins.keeper) apply false
alias(libs.plugins.kotlin.atomicfu) apply false
id("org.jetbrains.dokka") version libs.versions.dokkaBase
id("dokka-convention")
}

allprojects {
Expand Down Expand Up @@ -54,6 +62,58 @@ subprojects {
version = LIBRARY_VERSION
}

tasks.register<Delete>("clean") {
tasks.getByName<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

// Merges individual module docs into a single HTML output
dependencies {
dokka(project(":core:"))
dokka(project(":connectors:supabase"))
dokka(project(":compose:"))
}

dokka {
moduleName.set("PowerSync Kotlin")
}

// Serve the generated Dokka documentation using a simple HTTP server
// File changes are not watched here
tasks.register("serveDokka") {
group = "dokka"
dependsOn("dokkaGenerate")
doLast {
val server = HttpServer.create(InetSocketAddress(0), 0)
val root = file("build/dokka/html")

val handler =
com.sun.net.httpserver.HttpHandler { exchange: HttpExchange ->
val rawPath = exchange.requestURI.path
val cleanPath = URLDecoder.decode(rawPath.removePrefix("/"), "UTF-8")
val requestedFile = File(root, cleanPath)

val file =
when {
requestedFile.exists() && !requestedFile.isDirectory -> requestedFile
else -> File(root, "index.html") // fallback
}

val contentType =
Files.probeContentType(file.toPath()) ?: "application/octet-stream"
val bytes = file.readBytes()
exchange.responseHeaders.add("Content-Type", contentType)
exchange.sendResponseHeaders(200, bytes.size.toLong())
exchange.responseBody.use { it.write(bytes) }
}

server.createContext("/", handler)
server.executor = null
server.start()

println("📘 Serving Dokka docs at http://localhost:${server.address.port}/")
println("Press Ctrl+C to stop.")

// Keep the task alive
Thread.currentThread().join()
}
}
5 changes: 5 additions & 0 deletions compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.compose.compiler)
alias(libs.plugins.kotlinter)
id("com.powersync.plugins.sonatype")
id("dokka-convention")
}

kotlin {
Expand Down Expand Up @@ -45,3 +46,7 @@ android {
}

setupGithubRepository()

dokka {
moduleName.set("PowerSync Compose")
}
5 changes: 5 additions & 0 deletions connectors/supabase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinter)
id("com.powersync.plugins.sonatype")
id("dokka-convention")
}

kotlin {
Expand Down Expand Up @@ -51,3 +52,7 @@ android {
}

setupGithubRepository()

dokka {
moduleName.set("PowerSync Supabase Connector")
}
5 changes: 5 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
id("com.powersync.plugins.sharedbuild")
alias(libs.plugins.mokkery)
alias(libs.plugins.kotlin.atomicfu)
id("dokka-convention")
}

val binariesFolder = project.layout.buildDirectory.dir("binaries/desktop")
Expand Down Expand Up @@ -295,3 +296,7 @@ tasks.withType<KotlinTest> {
}
}
setupGithubRepository()

dokka {
moduleName.set("PowerSync Core")
}
4 changes: 2 additions & 2 deletions core/src/androidMain/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
public actual object BuildConfig {
public actual val isDebug: Boolean
internal actual object BuildConfig {
actual val isDebug: Boolean
get() = com.powersync.BuildConfig.DEBUG
}
4 changes: 2 additions & 2 deletions core/src/appleMain/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.Platform

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
public actual object BuildConfig {
internal actual object BuildConfig {
@OptIn(ExperimentalNativeApi::class)
public actual val isDebug: Boolean = Platform.isDebugBinary
actual val isDebug: Boolean = Platform.isDebugBinary
}
4 changes: 2 additions & 2 deletions core/src/commonMain/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
public expect object BuildConfig {
public val isDebug: Boolean
internal expect object BuildConfig {
val isDebug: Boolean
}
15 changes: 15 additions & 0 deletions core/src/commonMain/kotlin/com/powersync/db/schema/Schema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@ package com.powersync.db.schema

import kotlinx.serialization.Serializable

/**
* The schema used by the database.
*
* The implementation uses the schema as a "VIEW" on top of JSON data.
* No migrations are required on the client.
*/
public data class Schema(
val tables: List<Table>,
) {
init {
validate()
}

/**
* Secondary constructor to create a schema with a variable number of tables.
*/
public constructor(vararg tables: Table) : this(tables.asList())

/**
* Validates the schema by ensuring there are no duplicate table names
* and that each table is valid.
*
* @throws AssertionError if duplicate table names are found.
*/
public fun validate() {
val tableNames = mutableSetOf<String>()
tables.forEach { table ->
Expand Down
4 changes: 2 additions & 2 deletions core/src/jvmMain/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
public actual object BuildConfig {
internal actual object BuildConfig {
/*
To debug on the JVM, you can:
- Set the com.powersync.debug property with System.setProperty("com.powersync.debug", true) BEFORE calling any powersync API.
- Start your java program with the -Dcom.powersync.debug=true command line argument.
- Set the POWERSYNC_JVM_DEBUG environment variable to "true" before starting your program.
*/
public actual val isDebug: Boolean =
actual val isDebug: Boolean =
System.getProperty("com.powersync.debug") == "true" ||
System.getenv("POWERSYNC_JVM_DEBUG") == "true"
}
18 changes: 18 additions & 0 deletions docs/assets/discord.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions docs/assets/doc-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:root {
--dokka-logo-image-url: url('../images/powersync-logo.png');
}

.footer-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 8px;
margin-top: auto;
box-sizing: border-box;
background-color: var(--footer-background);
color: var(--footer-font-color);
}

.footer-title {
margin-bottom: 8px;
}

.footer-column {
flex: 1 1 0;
align-items: center;
text-align: center;
min-width: 300px;
padding: 8px;
}

.footer-icon-row {
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
48 changes: 48 additions & 0 deletions docs/assets/dokka-templates/includes/footer.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<#macro display>
<@template_cmd name="pathToRoot">
<div style="margin-top:auto">
<div class="footer-container">
<div class="footer-column">
<strong class="footer-title">Community</strong>
<div class="footer-icon-row">
<a href="https://discord.gg/powersync" target="_blank">
<img src="./${pathToRoot}images/discord.svg" loading="lazy" alt="Discord" height="24">
</a>
<a href="https://twitter.com/powersync_" target="_blank">
<img src="./${pathToRoot}images/x.svg" loading="lazy" alt="Twitter" height="20">
</a>
<a href="https://www.youtube.com/@powersync_" target="_blank">
<img src="./${pathToRoot}images/youtube.svg" loading="lazy" alt="YouTube" width="32" height="28">
</a>
<a href="https://www.linkedin.com/showcase/journeyapps-powersync/" target="_blank">
<img src="./${pathToRoot}images/linkedin.svg" loading="lazy" alt="LinkedIn" height="24">
</a>
</div>
</div>

<div class="footer-column">
<strong class="footer-title">More</strong>
<div class="footer-icon-row">
<a href="https://github.com/powersync-ja" target="_blank">
<img src="./${pathToRoot}images/github.svg" loading="lazy" alt="GitHub" height="24">
</a>
<a href="https://www.powersync.com/" target="_blank">
<img src="./${pathToRoot}images/web.svg" loading="lazy" alt="Website" height="30">
</a>
</div>
</div>
</div>

<div class="footer-container">
<span>© 2025 Journey Mobile, Inc.</span>
<span class="pull-right">
<span>Generated by </span>
<a class="footer--link footer--link_external" href="https://github.com/Kotlin/dokka">
<span>dokka</span>
</a>
</span>
</div>

</div>
</@template_cmd>
</#macro>
22 changes: 22 additions & 0 deletions docs/assets/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/assets/linkedin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/assets/logo-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/powersync-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/assets/web.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading