Skip to content

Commit fef3101

Browse files
Added version data to cursor lookups, and renamed Cursor to CursorProtocol
1 parent 5fe606f commit fef3101

File tree

4 files changed

+64
-40
lines changed

4 files changed

+64
-40
lines changed

Sources/CodableDatastore/Persistence/Cursor.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
/// An opaque type ``Persistence``s may use to indicate a position in their storage.
1010
///
1111
/// - Note: A cursor is only valid within the same transaction for the same persistence it was created for.
12-
public protocol Cursor<P> {
13-
associatedtype P: Persistence
12+
public protocol CursorProtocol<P> {
13+
associatedtype P: _Persistence
1414
var persistence: P { get }
1515

1616
// var transaction: Transaction<P> { get }
1717
}
1818

1919
/// An opaque type ``Persistence``s may use to indicate the position of an instance in their storage.
20-
public protocol InstanceCursor: Cursor {}
20+
public protocol InstanceCursorProtocol<P>: InsertionCursorProtocol {}
2121

2222
/// An opaque type ``Persistence``s may use to indicate the position a new instance should be inserted in their storage.
23-
public protocol InsertionCursor: Cursor {}
23+
public protocol InsertionCursorProtocol<P>: CursorProtocol {}

Sources/CodableDatastore/Persistence/Disk Persistence/DiskPersistence.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,18 @@ extension DiskPersistence {
438438
public func primaryIndexCursor<IdentifierType: Indexable>(
439439
for identifier: IdentifierType,
440440
datastoreKey: String
441-
) async throws -> (cursor: any InstanceCursor, data: Data) {
441+
) async throws -> (
442+
cursor: any InstanceCursorProtocol,
443+
instanceData: Data,
444+
versionData: Data
445+
) {
442446
preconditionFailure("Unimplemented")
443447
}
444448

445449
public func primaryIndexCursor<IdentifierType: Indexable>(
446450
inserting identifier: IdentifierType,
447451
datastoreKey: String
448-
) async throws -> any InsertionCursor {
452+
) async throws -> any InsertionCursorProtocol {
449453
preconditionFailure("Unimplemented")
450454
}
451455

@@ -454,7 +458,11 @@ extension DiskPersistence {
454458
identifier: IdentifierType,
455459
indexName: String,
456460
datastoreKey: String
457-
) async throws -> (cursor: any InstanceCursor, data: Data) {
461+
) async throws -> (
462+
cursor: any InstanceCursorProtocol,
463+
instanceData: Data,
464+
versionData: Data
465+
) {
458466
preconditionFailure("Unimplemented")
459467
}
460468

@@ -463,7 +471,7 @@ extension DiskPersistence {
463471
identifier: IdentifierType,
464472
indexName: String,
465473
datastoreKey: String
466-
) async throws -> any InsertionCursor {
474+
) async throws -> any InsertionCursorProtocol {
467475
preconditionFailure("Unimplemented")
468476
}
469477

@@ -472,7 +480,7 @@ extension DiskPersistence {
472480
identifier: IdentifierType,
473481
indexName: String,
474482
datastoreKey: String
475-
) async throws -> any InstanceCursor {
483+
) async throws -> any InstanceCursorProtocol {
476484
preconditionFailure("Unimplemented")
477485
}
478486

@@ -481,7 +489,7 @@ extension DiskPersistence {
481489
identifier: IdentifierType,
482490
indexName: String,
483491
datastoreKey: String
484-
) async throws -> any InsertionCursor {
492+
) async throws -> any InsertionCursorProtocol {
485493
preconditionFailure("Unimplemented")
486494
}
487495
}
@@ -493,14 +501,14 @@ extension DiskPersistence {
493501
versionData: Data,
494502
identifierValue: IdentifierType,
495503
instanceData: Data,
496-
cursor: some InsertionCursor,
504+
cursor: some InsertionCursorProtocol,
497505
datastoreKey: String
498506
) async throws {
499507
preconditionFailure("Unimplemented")
500508
}
501509

502510
public func deletePrimaryIndexEntry(
503-
cursor: some InstanceCursor,
511+
cursor: some InstanceCursorProtocol,
504512
datastoreKey: String
505513
) async throws {
506514
preconditionFailure("Unimplemented")
@@ -517,15 +525,15 @@ extension DiskPersistence {
517525
indexValue: IndexType,
518526
identifierValue: IdentifierType,
519527
instanceData: Data,
520-
cursor: some InsertionCursor,
528+
cursor: some InsertionCursorProtocol,
521529
indexName: String,
522530
datastoreKey: String
523531
) async throws {
524532
preconditionFailure("Unimplemented")
525533
}
526534

527535
public func deleteDirectIndexEntry(
528-
cursor: some InstanceCursor,
536+
cursor: some InstanceCursorProtocol,
529537
indexName: String,
530538
datastoreKey: String
531539
) async throws {
@@ -542,15 +550,15 @@ extension DiskPersistence {
542550
public func persistSecondaryIndexEntry<IndexType: Indexable, IdentifierType: Indexable>(
543551
indexValue: IndexType,
544552
identifierValue: IdentifierType,
545-
cursor: some InsertionCursor,
553+
cursor: some InsertionCursorProtocol,
546554
indexName: String,
547555
datastoreKey: String
548556
) async throws {
549557
preconditionFailure("Unimplemented")
550558
}
551559

552560
public func deleteSecondaryIndexEntry(
553-
cursor: some InstanceCursor,
561+
cursor: some InstanceCursorProtocol,
554562
indexName: String,
555563
datastoreKey: String
556564
) async throws {

Sources/CodableDatastore/Persistence/Memory Persistence/MemoryPersistence.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ extension MemoryPersistence: _Persistence {
2828
public func primaryIndexCursor<IdentifierType: Indexable>(
2929
for identifier: IdentifierType,
3030
datastoreKey: String
31-
) async throws -> (cursor: any InstanceCursor, data: Data) {
31+
) async throws -> (
32+
cursor: any InstanceCursorProtocol,
33+
instanceData: Data,
34+
versionData: Data
35+
) {
3236
preconditionFailure("Unimplemented")
3337
}
3438

3539
public func primaryIndexCursor<IdentifierType: Indexable>(
3640
inserting identifier: IdentifierType,
3741
datastoreKey: String
38-
) async throws -> any InsertionCursor {
42+
) async throws -> any InsertionCursorProtocol {
3943
preconditionFailure("Unimplemented")
4044
}
4145

@@ -44,7 +48,11 @@ extension MemoryPersistence: _Persistence {
4448
identifier: IdentifierType,
4549
indexName: String,
4650
datastoreKey: String
47-
) async throws -> (cursor: any InstanceCursor, data: Data) {
51+
) async throws -> (
52+
cursor: any InstanceCursorProtocol,
53+
instanceData: Data,
54+
versionData: Data
55+
) {
4856
preconditionFailure("Unimplemented")
4957
}
5058

@@ -53,7 +61,7 @@ extension MemoryPersistence: _Persistence {
5361
identifier: IdentifierType,
5462
indexName: String,
5563
datastoreKey: String
56-
) async throws -> any InsertionCursor {
64+
) async throws -> any InsertionCursorProtocol {
5765
preconditionFailure("Unimplemented")
5866
}
5967

@@ -62,7 +70,7 @@ extension MemoryPersistence: _Persistence {
6270
identifier: IdentifierType,
6371
indexName: String,
6472
datastoreKey: String
65-
) async throws -> any InstanceCursor {
73+
) async throws -> any InstanceCursorProtocol {
6674
preconditionFailure("Unimplemented")
6775
}
6876

@@ -71,22 +79,22 @@ extension MemoryPersistence: _Persistence {
7179
identifier: IdentifierType,
7280
indexName: String,
7381
datastoreKey: String
74-
) async throws -> any InsertionCursor {
82+
) async throws -> any InsertionCursorProtocol {
7583
preconditionFailure("Unimplemented")
7684
}
7785

7886
public func persistPrimaryIndexEntry<IdentifierType: Indexable>(
7987
versionData: Data,
8088
identifierValue: IdentifierType,
8189
instanceData: Data,
82-
cursor: some InsertionCursor,
90+
cursor: some InsertionCursorProtocol,
8391
datastoreKey: String
8492
) async throws {
8593
preconditionFailure("Unimplemented")
8694
}
8795

8896
public func deletePrimaryIndexEntry(
89-
cursor: some InstanceCursor,
97+
cursor: some InstanceCursorProtocol,
9098
datastoreKey: String
9199
) async throws {
92100
preconditionFailure("Unimplemented")
@@ -103,15 +111,15 @@ extension MemoryPersistence: _Persistence {
103111
indexValue: IndexType,
104112
identifierValue: IdentifierType,
105113
instanceData: Data,
106-
cursor: some InsertionCursor,
114+
cursor: some InsertionCursorProtocol,
107115
indexName: String,
108116
datastoreKey: String
109117
) async throws {
110118
preconditionFailure("Unimplemented")
111119
}
112120

113121
public func deleteDirectIndexEntry(
114-
cursor: some InstanceCursor,
122+
cursor: some InstanceCursorProtocol,
115123
indexName: String,
116124
datastoreKey: String
117125
) async throws {
@@ -128,15 +136,15 @@ extension MemoryPersistence: _Persistence {
128136
public func persistSecondaryIndexEntry<IndexType: Indexable, IdentifierType: Indexable>(
129137
indexValue: IndexType,
130138
identifierValue: IdentifierType,
131-
cursor: some InsertionCursor,
139+
cursor: some InsertionCursorProtocol,
132140
indexName: String,
133141
datastoreKey: String
134142
) async throws {
135143
preconditionFailure("Unimplemented")
136144
}
137145

138146
public func deleteSecondaryIndexEntry(
139-
cursor: some InstanceCursor,
147+
cursor: some InstanceCursorProtocol,
140148
indexName: String,
141149
datastoreKey: String
142150
) async throws {

Sources/CodableDatastore/Persistence/Persistence.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public protocol _Persistence {
4141
func primaryIndexCursor<IdentifierType: Indexable>(
4242
for identifier: IdentifierType,
4343
datastoreKey: String
44-
) async throws -> (cursor: any InstanceCursor, data: Data)
44+
) async throws -> (
45+
cursor: any InstanceCursorProtocol,
46+
instanceData: Data,
47+
versionData: Data
48+
)
4549

4650
/// Load a cursor for inserting the specified identifier in the primary index of the specified datastore key.
4751
///
@@ -53,7 +57,7 @@ public protocol _Persistence {
5357
func primaryIndexCursor<IdentifierType: Indexable>(
5458
inserting identifier: IdentifierType,
5559
datastoreKey: String
56-
) async throws -> any InsertionCursor
60+
) async throws -> any InsertionCursorProtocol
5761

5862
/// Load a cursor for the specified indexedValue in a direct index of the specified datastore key.
5963
///
@@ -69,7 +73,11 @@ public protocol _Persistence {
6973
identifier: IdentifierType,
7074
indexName: String,
7175
datastoreKey: String
72-
) async throws -> (cursor: any InstanceCursor, data: Data)
76+
) async throws -> (
77+
cursor: any InstanceCursorProtocol,
78+
instanceData: Data,
79+
versionData: Data
80+
)
7381

7482
/// Load a cursor for inserting the specified indexedValue in a direct index of the specified datastore key.
7583
///
@@ -85,7 +93,7 @@ public protocol _Persistence {
8593
identifier: IdentifierType,
8694
indexName: String,
8795
datastoreKey: String
88-
) async throws -> any InsertionCursor
96+
) async throws -> any InsertionCursorProtocol
8997

9098
/// Load a cursor for the specified indexedValue in a secondary index of the specified datastore key.
9199
///
@@ -101,7 +109,7 @@ public protocol _Persistence {
101109
identifier: IdentifierType,
102110
indexName: String,
103111
datastoreKey: String
104-
) async throws -> any InstanceCursor
112+
) async throws -> any InstanceCursorProtocol
105113

106114
/// Load a cursor for inserting the specified indexedValue in a secondary index of the specified datastore key.
107115
///
@@ -117,7 +125,7 @@ public protocol _Persistence {
117125
identifier: IdentifierType,
118126
indexName: String,
119127
datastoreKey: String
120-
) async throws -> any InsertionCursor
128+
) async throws -> any InsertionCursorProtocol
121129

122130
/// Create or update an entry in the primary index of a data store.
123131
///
@@ -132,7 +140,7 @@ public protocol _Persistence {
132140
versionData: Data,
133141
identifierValue: IdentifierType,
134142
instanceData: Data,
135-
cursor: some InsertionCursor,
143+
cursor: some InsertionCursorProtocol,
136144
datastoreKey: String
137145
) async throws
138146

@@ -143,7 +151,7 @@ public protocol _Persistence {
143151
/// - cursor: The location of the entry to delete.
144152
/// - datastoreKey: The key of the datastore the index belongs to.
145153
func deletePrimaryIndexEntry(
146-
cursor: some InstanceCursor,
154+
cursor: some InstanceCursorProtocol,
147155
datastoreKey: String
148156
) async throws
149157

@@ -169,7 +177,7 @@ public protocol _Persistence {
169177
indexValue: IndexType,
170178
identifierValue: IdentifierType,
171179
instanceData: Data,
172-
cursor: some InsertionCursor,
180+
cursor: some InsertionCursorProtocol,
173181
indexName: String,
174182
datastoreKey: String
175183
) async throws
@@ -180,7 +188,7 @@ public protocol _Persistence {
180188
/// - indexName: The name of the index.
181189
/// - datastoreKey: The key of the datastore the index belongs to.
182190
func deleteDirectIndexEntry(
183-
cursor: some InstanceCursor,
191+
cursor: some InstanceCursorProtocol,
184192
indexName: String,
185193
datastoreKey: String
186194
) async throws
@@ -206,7 +214,7 @@ public protocol _Persistence {
206214
func persistSecondaryIndexEntry<IndexType: Indexable, IdentifierType: Indexable>(
207215
indexValue: IndexType,
208216
identifierValue: IdentifierType,
209-
cursor: some InsertionCursor,
217+
cursor: some InsertionCursorProtocol,
210218
indexName: String,
211219
datastoreKey: String
212220
) async throws
@@ -217,7 +225,7 @@ public protocol _Persistence {
217225
/// - indexName: The name of the index.
218226
/// - datastoreKey: The key of the datastore the index belongs to.
219227
func deleteSecondaryIndexEntry(
220-
cursor: some InstanceCursor,
228+
cursor: some InstanceCursorProtocol,
221229
indexName: String,
222230
datastoreKey: String
223231
) async throws

0 commit comments

Comments
 (0)