Skip to content

Commit

Permalink
docs(backup): add multiplatform sample implementations and documentat…
Browse files Browse the repository at this point in the history
…ion (#3269)

Introduced examples showcasing `MPBackupImporter` and `MPBackupExporter` usage for different platforms. Updated documentation, README, and build configurations to support multiplatform samples, including JS and non-JS targets.
  • Loading branch information
vitorhugods authored Feb 6, 2025
1 parent 6f99a66 commit 87e30ee
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 66 deletions.
11 changes: 11 additions & 0 deletions backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
This module implements the Wire Cross-platform Backup solution.
Its purpose is to create a common implementation to be used by iOS, Web, and Android.

## Samples

If you want to jump straight to examples, checkout the `nonJs` and `js` versions in the documentation:
- [Importing](https://wireapp.github.io/kalium/backup/com.wire.backup.ingest/-m-p-backup-importer/index.html)
- [Exporting](https://wireapp.github.io/kalium/backup/com.wire.backup.dump/-m-p-backup-exporter/index.html)

## Data structure

To see the currently supported data (conversations, users, messages, etc.), check
[BackupData](https://wireapp.github.io/kalium/backup/com.wire.backup.data/-backup-message/index.html)

## Capabilities

> [!TIP]
Expand Down
1 change: 0 additions & 1 deletion backup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ android {
}
}

@Suppress("UnusedPrivateProperty")
kotlin {
// Makes visibility modifiers mandatory
// Useful for a library that will be called by other clients
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,8 @@ public abstract class CommonMPBackupExporter(
}
}

/**
* Entity able to serialize [BackupData] entities, like [BackupMessage], [BackupConversation], [BackupUser]
* into a cross-platform [BackupData] format.
*/
public expect class MPBackupExporter : CommonMPBackupExporter
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,9 @@ public abstract class CommonMPBackupImporter internal constructor(
internal abstract suspend fun unzipAllEntries(): BackupPageStorage
}

/**
* Entity able to parse backed-up data and returns
* digestible data in [BackupData] format.
* @sample samples.backup.BackupSample.commonImport
*/
public expect class MPBackupImporter : CommonMPBackupImporter
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
*/
package com.wire.backup.dump

import com.wire.backup.data.BackupConversation
import com.wire.backup.data.BackupMessage
import com.wire.backup.data.BackupQualifiedId
import com.wire.backup.data.BackupUser
import com.wire.backup.filesystem.BackupPage
import com.wire.backup.filesystem.BackupPageStorage
import com.wire.backup.filesystem.InMemoryBackupPageStorage
import com.wire.kalium.protobuf.backup.BackupData
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
import kotlinx.coroutines.Deferred
Expand All @@ -32,6 +36,11 @@ import okio.Source
import okio.buffer
import kotlin.js.Promise

/**
* Entity able to serialize [BackupData] entities, like [BackupMessage], [BackupConversation], [BackupUser]
* into a cross-platform [BackupData] format.
* @sample samples.backup.BackupSamplesJs.exportBackup
*/
@JsExport
public actual class MPBackupExporter(
selfUserId: BackupQualifiedId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.wire.backup.ingest

import com.wire.backup.data.BackupData
import com.wire.backup.dump.JSZip
import com.wire.backup.filesystem.BackupPage
import com.wire.backup.filesystem.BackupPageStorage
Expand All @@ -31,6 +32,12 @@ import okio.Sink
import org.khronos.webgl.Uint8Array
import kotlin.js.Promise

/**
* Entity able to parse backed-up data and returns
* digestible data in [BackupData] format.
* @sample samples.backup.BackupSamplesJs.peekBackup
* @sample samples.backup.BackupSamples.commonImport
*/
@JsExport
public actual class MPBackupImporter : CommonMPBackupImporter() {
private val inMemoryUnencryptedBuffer = Buffer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,26 @@
package com.wire.backup.dump

import com.rickclephas.kmp.nativecoroutines.NativeCoroutines
import com.wire.backup.data.BackupConversation
import com.wire.backup.data.BackupMessage
import com.wire.backup.data.BackupQualifiedId
import com.wire.backup.data.BackupUser
import com.wire.backup.filesystem.BackupPage
import com.wire.backup.filesystem.BackupPageStorage
import com.wire.backup.filesystem.FileBasedBackupPageStorage
import com.wire.kalium.protobuf.backup.BackupData
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import okio.FileSystem
import okio.Path.Companion.toPath
import okio.SYSTEM
import okio.Source

/**
* Entity able to serialize [BackupData] entities, like [BackupMessage], [BackupConversation], [BackupUser]
* into a cross-platform [BackupData] format.
* @sample samples.backup.BackupSamplesNonJS.exportBackup
*/
public actual class MPBackupExporter(
selfUserId: BackupQualifiedId,
workDirectory: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.wire.backup.ingest

public interface BackupFileUnzipper {
public fun interface BackupFileUnzipper {

/**
* Unzip all the entries stored within the file at [zipPath] to _some_ directory of choice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.wire.backup.ingest

import com.rickclephas.kmp.nativecoroutines.NativeCoroutines
import com.wire.backup.data.BackupData
import com.wire.backup.filesystem.BackupPageStorage
import com.wire.backup.filesystem.FileBasedBackupPageStorage
import okio.FileSystem
Expand All @@ -28,6 +29,12 @@ import okio.Sink
import kotlin.experimental.ExperimentalObjCName
import kotlin.native.ObjCName

/**
* Entity able to parse backed-up data and returns
* digestible data in [BackupData] format.
* @sample samples.backup.BackupSamplesNonJS.peekBackup
* @sample samples.backup.BackupSamples.commonImport
*/
@OptIn(ExperimentalObjCName::class)
public actual class MPBackupImporter(
private val pathToWorkDirectory: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.jetbrains.dokka.DokkaConfiguration.Visibility
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask

val documentedSubprojects = listOf(
"backup",
"calling",
"cli",
"cryptography",
Expand Down
1 change: 0 additions & 1 deletion data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ kaliumLibrary {
multiplatform { }
}

@Suppress("UnusedPrivateProperty")
kotlin {
sourceSets {
val commonMain by getting {
Expand Down
Loading

0 comments on commit 87e30ee

Please sign in to comment.