Skip to content

Commit 4ad8c0c

Browse files
API Reference (#163)
1 parent 16a79c5 commit 4ad8c0c

File tree

24 files changed

+336
-11
lines changed

24 files changed

+336
-11
lines changed

.github/workflows/docs-deploy.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Validate Gradle Wrapper
18+
uses: gradle/wrapper-validation-action@v1
19+
- uses: actions/cache@v3
20+
with:
21+
path: ~/.konan
22+
key: ${{ runner.os }}-${{ hashFiles('**/.lock') }}
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v3
25+
with:
26+
java-version: '17'
27+
distribution: 'temurin'
28+
- name: Set up Gradle
29+
uses: gradle/actions/setup-gradle@v4
30+
- name: Build Docs
31+
run: |
32+
./gradlew \
33+
-PGITHUB_PUBLISH_TOKEN=${{ secrets.GITHUB_TOKEN }} \
34+
dokkaGenerate
35+
shell: bash
36+
- name: Upload static files as artifact
37+
id: deployment
38+
uses: actions/upload-pages-artifact@v3
39+
with:
40+
path: build/dokka/html
41+
42+
# Deployment job
43+
deploy:
44+
environment:
45+
name: github-pages
46+
url: ${{ steps.deployment.outputs.page_url }}
47+
runs-on: ubuntu-latest
48+
needs: build
49+
steps:
50+
- name: Deploy to GitHub Pages
51+
id: deployment
52+
uses: actions/deploy-pages@v4

build.gradle.kts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import com.sun.net.httpserver.HttpExchange
2+
import com.sun.net.httpserver.HttpServer
3+
import java.net.InetSocketAddress
4+
import java.net.URLDecoder
5+
import java.nio.file.Files
6+
17
plugins {
28
alias(libs.plugins.jetbrainsCompose) apply false
39
alias(libs.plugins.compose.compiler) apply false
@@ -16,6 +22,8 @@ plugins {
1622
alias(libs.plugins.kotlinter) apply false
1723
alias(libs.plugins.keeper) apply false
1824
alias(libs.plugins.kotlin.atomicfu) apply false
25+
id("org.jetbrains.dokka") version libs.versions.dokkaBase
26+
id("dokka-convention")
1927
}
2028

2129
allprojects {
@@ -54,6 +62,58 @@ subprojects {
5462
version = LIBRARY_VERSION
5563
}
5664

57-
tasks.register<Delete>("clean") {
65+
tasks.getByName<Delete>("clean") {
5866
delete(rootProject.layout.buildDirectory)
5967
}
68+
69+
// Merges individual module docs into a single HTML output
70+
dependencies {
71+
dokka(project(":core:"))
72+
dokka(project(":connectors:supabase"))
73+
dokka(project(":compose:"))
74+
}
75+
76+
dokka {
77+
moduleName.set("PowerSync Kotlin")
78+
}
79+
80+
// Serve the generated Dokka documentation using a simple HTTP server
81+
// File changes are not watched here
82+
tasks.register("serveDokka") {
83+
group = "dokka"
84+
dependsOn("dokkaGenerate")
85+
doLast {
86+
val server = HttpServer.create(InetSocketAddress(0), 0)
87+
val root = file("build/dokka/html")
88+
89+
val handler =
90+
com.sun.net.httpserver.HttpHandler { exchange: HttpExchange ->
91+
val rawPath = exchange.requestURI.path
92+
val cleanPath = URLDecoder.decode(rawPath.removePrefix("/"), "UTF-8")
93+
val requestedFile = File(root, cleanPath)
94+
95+
val file =
96+
when {
97+
requestedFile.exists() && !requestedFile.isDirectory -> requestedFile
98+
else -> File(root, "index.html") // fallback
99+
}
100+
101+
val contentType =
102+
Files.probeContentType(file.toPath()) ?: "application/octet-stream"
103+
val bytes = file.readBytes()
104+
exchange.responseHeaders.add("Content-Type", contentType)
105+
exchange.sendResponseHeaders(200, bytes.size.toLong())
106+
exchange.responseBody.use { it.write(bytes) }
107+
}
108+
109+
server.createContext("/", handler)
110+
server.executor = null
111+
server.start()
112+
113+
println("📘 Serving Dokka docs at http://localhost:${server.address.port}/")
114+
println("Press Ctrl+C to stop.")
115+
116+
// Keep the task alive
117+
Thread.currentThread().join()
118+
}
119+
}

compose/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
alias(libs.plugins.compose.compiler)
99
alias(libs.plugins.kotlinter)
1010
id("com.powersync.plugins.sonatype")
11+
id("dokka-convention")
1112
}
1213

1314
kotlin {
@@ -45,3 +46,7 @@ android {
4546
}
4647

4748
setupGithubRepository()
49+
50+
dokka {
51+
moduleName.set("PowerSync Compose")
52+
}

connectors/supabase/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
alias(libs.plugins.androidLibrary)
99
alias(libs.plugins.kotlinter)
1010
id("com.powersync.plugins.sonatype")
11+
id("dokka-convention")
1112
}
1213

1314
kotlin {
@@ -51,3 +52,7 @@ android {
5152
}
5253

5354
setupGithubRepository()
55+
56+
dokka {
57+
moduleName.set("PowerSync Supabase Connector")
58+
}

core/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ plugins {
1919
id("com.powersync.plugins.sharedbuild")
2020
alias(libs.plugins.mokkery)
2121
alias(libs.plugins.kotlin.atomicfu)
22+
id("dokka-convention")
2223
}
2324

2425
val binariesFolder = project.layout.buildDirectory.dir("binaries/desktop")
@@ -295,3 +296,7 @@ tasks.withType<KotlinTest> {
295296
}
296297
}
297298
setupGithubRepository()
299+
300+
dokka {
301+
moduleName.set("PowerSync Core")
302+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
2-
public actual object BuildConfig {
3-
public actual val isDebug: Boolean
2+
internal actual object BuildConfig {
3+
actual val isDebug: Boolean
44
get() = com.powersync.BuildConfig.DEBUG
55
}

core/src/appleMain/kotlin/BuildConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import kotlin.experimental.ExperimentalNativeApi
22
import kotlin.native.Platform
33

44
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
5-
public actual object BuildConfig {
5+
internal actual object BuildConfig {
66
@OptIn(ExperimentalNativeApi::class)
7-
public actual val isDebug: Boolean = Platform.isDebugBinary
7+
actual val isDebug: Boolean = Platform.isDebugBinary
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
2-
public expect object BuildConfig {
3-
public val isDebug: Boolean
2+
internal expect object BuildConfig {
3+
val isDebug: Boolean
44
}

core/src/commonMain/kotlin/com/powersync/db/schema/Schema.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@ package com.powersync.db.schema
22

33
import kotlinx.serialization.Serializable
44

5+
/**
6+
* The schema used by the database.
7+
*
8+
* The implementation uses the schema as a "VIEW" on top of JSON data.
9+
* No migrations are required on the client.
10+
*/
511
public data class Schema(
612
val tables: List<Table>,
713
) {
814
init {
915
validate()
1016
}
1117

18+
/**
19+
* Secondary constructor to create a schema with a variable number of tables.
20+
*/
1221
public constructor(vararg tables: Table) : this(tables.asList())
1322

23+
/**
24+
* Validates the schema by ensuring there are no duplicate table names
25+
* and that each table is valid.
26+
*
27+
* @throws AssertionError if duplicate table names are found.
28+
*/
1429
public fun validate() {
1530
val tableNames = mutableSetOf<String>()
1631
tables.forEach { table ->
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
2-
public actual object BuildConfig {
2+
internal actual object BuildConfig {
33
/*
44
To debug on the JVM, you can:
55
- Set the com.powersync.debug property with System.setProperty("com.powersync.debug", true) BEFORE calling any powersync API.
66
- Start your java program with the -Dcom.powersync.debug=true command line argument.
77
- Set the POWERSYNC_JVM_DEBUG environment variable to "true" before starting your program.
88
*/
9-
public actual val isDebug: Boolean =
9+
actual val isDebug: Boolean =
1010
System.getProperty("com.powersync.debug") == "true" ||
1111
System.getenv("POWERSYNC_JVM_DEBUG") == "true"
1212
}

0 commit comments

Comments
 (0)