-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathLCPLicenseRepository.swift
57 lines (47 loc) · 2.13 KB
/
LCPLicenseRepository.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright 2025 Readium Foundation. All rights reserved.
// Use of this source code is governed by the BSD-style license
// available in the top-level LICENSE file of the project.
//
import Foundation
/// The license repository stores registered licenses with their consumed rights (e.g. copy).
public protocol LCPLicenseRepository {
/// Adds a new `licenseDocument` to the repository, using `licenseDocument.id` as the
/// primary key.
///
/// ## Implementation notes:
///
/// * When adding a license for the first time, you **must** initialize the consumable user rights with
/// `licenseDocument.rights`.
/// * If the license already exists in the repository, it is updated **without overwriting** the existing
/// consumable user rights.
func addLicense(_ licenseDocument: LicenseDocument) async throws
/// Returns the `LicenseDocument` saved with the given `id`.
func license(for id: LicenseDocument.ID) async throws -> LicenseDocument?
/// Returns whether the device is already registered for the license with given `id` .
func isDeviceRegistered(for id: LicenseDocument.ID) async throws -> Bool
/// Marks the device as registered for the license with given `id`.
func registerDevice(for id: LicenseDocument.ID) async throws
/// Returns the consumable user rights for the license with given `id`.
func userRights(for id: LicenseDocument.ID) async throws -> LCPConsumableUserRights
/// Updates the consumable user rights for the license with given `id`.
func updateUserRights(
for id: LicenseDocument.ID,
with changes: (inout LCPConsumableUserRights) -> Void
) async throws
}
/// Holds the current state of consumable user rights for a license.
public struct LCPConsumableUserRights {
/// Maximum number of pages left to be printed.
///
/// If `nil`, there is no limit.
public var print: Int?
/// Maximum number of characters left to be copied to the clipboard.
///
/// If `nil`, there is no limit.
public var copy: Int?
public init(print: Int?, copy: Int?) {
self.print = print
self.copy = copy
}
}