Skip to content

Commit

Permalink
updated for license
Browse files Browse the repository at this point in the history
  • Loading branch information
biozal committed Oct 11, 2024
1 parent 1d8a2eb commit 9202939
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions App/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func loadAppConfig() -> AppConfig {
guard let path = Bundle.main.path(forResource: "capellaConfig", ofType: "plist") else {
fatalError("Could not load atlasConfig.plist file!")
}

// Any errors here indicate that the capellaConfig.plist file has not been formatted properly.
// Expected key/values:
// "endpointUrl": "your App Services URL"
Expand Down
7 changes: 0 additions & 7 deletions App/Data/AuthenticationService.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// AuthenticationService.swift
// App
//
// Created by Aaron LaBeau on 10/10/24.
//

import Foundation

public class AuthenticationService : NSObject {
Expand Down
35 changes: 35 additions & 0 deletions App/Data/DatabaseService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ actor DatabaseService {

}

/// Initializes the database for the specified user, sets up collections, indexes, queries, and replication.
///
/// This function creates and configures a database using the sanitized username as the database name. It sets up
/// the necessary collections, indexes, and queries used for live queries, and initializes the replicator to
/// sync data with a remote endpoint. The function also manages replication status and updates the app’s
/// `databaseState` accordingly.
///
/// - Parameter user: The `User` object containing the credentials and username to be used for the database name
/// and authentication in the replication process.
///
/// - Important: The function sanitizes the username by replacing certain characters (`@` and `.`) with hyphens (`-`)
/// to create a valid database name. Ensure the username is correctly formatted to avoid unexpected errors.
///
/// - Throws: An error if there is an issue opening the database, creating the collection, setting up queries,
/// or configuring the replicator.
///
/// - Note: The function updates the app’s `databaseState` to reflect the current status (e.g., `.notInitialized`, `.open`, or `.error`).
/// These updates are dispatched on the main thread to ensure UI responsiveness.
///
/// ### Function Behavior:
/// 1. **Database Initialization**:
/// - The function attempts to open or create a database using the sanitized username.
/// 2. **Collection Setup**:
/// - It creates or retrieves a collection named `_taskCollectionName` in the scope `_scopeName`.
/// 3. **Index Creation**:
/// - An index is created on the `"ownerId"` field of the collection for efficient querying.
/// 4. **Query Setup**:
/// - Queries are created for fetching all tasks and tasks belonging to the user using live queries.
/// 5. **Replicator Configuration**:
/// - The replicator is configured with the user’s credentials and an endpoint URL from the app’s configuration.
/// - The replicator is set to run continuously, synchronizing data bidirectionally (`pushAndPull`).
/// 6. **Replication Listener**:
/// - A listener monitors the replication status and logs changes, updating the UI state as needed.
///
/// - SeeAlso: `Database`, `Replicator`, `CollectionConfiguration`, `ValueIndexConfiguration`
func initializeDatabase(user: User) {
do {

Expand Down

0 comments on commit 9202939

Please sign in to comment.