|
| 1 | +// |
| 2 | +// PersistenceDatastore.swift |
| 3 | +// CodableDatastore |
| 4 | +// |
| 5 | +// Created by Dimitri Bouniol on 2023-06-10. |
| 6 | +// Copyright © 2023 Mochi Development, Inc. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import Foundation |
| 10 | + |
| 11 | +typealias DatastoreIdentifier = TypedIdentifier<DiskPersistence<ReadOnly>.Datastore> |
| 12 | +typealias DatastoreRootIdentifier = DatedIdentifier<DiskPersistence<ReadOnly>.Datastore> |
| 13 | + |
| 14 | +extension DiskPersistence { |
| 15 | + actor Datastore { |
| 16 | + let id: DatastoreIdentifier |
| 17 | + |
| 18 | + unowned let snapshot: Snapshot<AccessMode> |
| 19 | + |
| 20 | + var currentRootIdentifier: DatastoreRootIdentifier? |
| 21 | + var cachedDescriptor: DatastoreDescriptor? |
| 22 | + |
| 23 | + var lastUpdateDescriptorTask: Task<Any, Error>? |
| 24 | + |
| 25 | + init( |
| 26 | + id: DatastoreIdentifier, |
| 27 | + snapshot: Snapshot<AccessMode> |
| 28 | + ) { |
| 29 | + self.id = id |
| 30 | + self.snapshot = snapshot |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +// MARK: - Common URL Accessors |
| 36 | +extension DiskPersistence.Datastore { |
| 37 | + /// The URL that points to the Snapshot directory. |
| 38 | + nonisolated var datastoreURL: URL { |
| 39 | + snapshot |
| 40 | + .datastoresURL |
| 41 | + .appendingPathComponent("\(id).datastore", isDirectory: true) |
| 42 | + } |
| 43 | + |
| 44 | + /// The URL that points to the Root directory. |
| 45 | + nonisolated var rootURL: URL { |
| 46 | + datastoreURL |
| 47 | + .appendingPathComponent("Root", isDirectory: true) |
| 48 | + } |
| 49 | + |
| 50 | + /// The URL that points to the DirectIndexes directory. |
| 51 | + nonisolated var directIndexesURL: URL { |
| 52 | + datastoreURL |
| 53 | + .appendingPathComponent("DirectIndexes", isDirectory: true) |
| 54 | + } |
| 55 | + |
| 56 | + /// The URL that points to the SecondaryIndexes directory. |
| 57 | + nonisolated var secondaryIndexesURL: URL { |
| 58 | + datastoreURL |
| 59 | + .appendingPathComponent("SecondaryIndexes", isDirectory: true) |
| 60 | + } |
| 61 | +} |
0 commit comments