Apply changed comments of JS-SDK (#42)
This commit is contained in:
parent
7477cbaf0f
commit
23b9a6a00a
|
@ -33,7 +33,7 @@ class CRDTArray: CRDTContainer {
|
|||
}
|
||||
|
||||
/**
|
||||
* `insert` inserts the given element after the given previous element.
|
||||
* `insert` adds a new node after the the given node.
|
||||
*/
|
||||
func insert(value: CRDTElement, afterCreatedAt: TimeTicket) throws {
|
||||
try self.elements.insert(value, afterCreatedAt: afterCreatedAt)
|
||||
|
@ -82,8 +82,7 @@ class CRDTArray: CRDTContainer {
|
|||
}
|
||||
|
||||
/**
|
||||
* `getPreviousCreatedAt` returns the creation time of
|
||||
* the previous element of the given element.
|
||||
* `getPreviousCreatedAt` returns the creation time of the previous node.
|
||||
*/
|
||||
func getPreviousCreatedAt(createdAt: TimeTicket) throws -> TimeTicket {
|
||||
return try self.elements.getPreviousCreatedAt(ofCreatedAt: createdAt)
|
||||
|
@ -152,21 +151,21 @@ extension CRDTArray {
|
|||
}
|
||||
|
||||
/**
|
||||
* `subPath` returns subPath of JSONPath of the given `createdAt` element.
|
||||
* `subPath` returns the sub path of the given element.
|
||||
*/
|
||||
func subPath(createdAt: TimeTicket) throws -> String {
|
||||
return try self.elements.subPath(createdAt: createdAt)
|
||||
}
|
||||
|
||||
/**
|
||||
* `delete` physically deletes child element.
|
||||
* `delete` physically deletes the given element.
|
||||
*/
|
||||
func delete(element: CRDTElement) throws {
|
||||
try self.elements.delete(element)
|
||||
}
|
||||
|
||||
/**
|
||||
* `remove` removes the element of the given index.
|
||||
* `remove` removes the element of the given creation time.
|
||||
*/
|
||||
@discardableResult
|
||||
func remove(createdAt: TimeTicket, executedAt: TimeTicket) throws -> CRDTElement {
|
||||
|
|
|
@ -99,6 +99,9 @@ extension CRDTElement {
|
|||
* `CRDTContainer` represents CRDTArray or CRDtObject.
|
||||
*/
|
||||
protocol CRDTContainer: CRDTElement {
|
||||
/**
|
||||
* `subPath` returns the sub path of the given element.
|
||||
*/
|
||||
func subPath(createdAt: TimeTicket) throws -> String
|
||||
|
||||
func delete(element: CRDTElement) throws
|
||||
|
|
|
@ -62,7 +62,7 @@ class CRDTObject: CRDTContainer {
|
|||
}
|
||||
|
||||
/**
|
||||
* `keys` returns array of this object.
|
||||
* `keys` returns array of keys in this object.
|
||||
*/
|
||||
var keys: [String] {
|
||||
return self.map { $0.key }
|
||||
|
@ -127,7 +127,7 @@ extension CRDTObject {
|
|||
}
|
||||
|
||||
/**
|
||||
* `delete` physically deletes child element.
|
||||
* `delete` physically deletes the given element.
|
||||
*/
|
||||
func delete(element: CRDTElement) throws {
|
||||
try self.memberNodes.delete(value: element)
|
||||
|
|
|
@ -105,7 +105,7 @@ class CRDTRoot {
|
|||
}
|
||||
|
||||
/**
|
||||
* `registerRemovedElement` registers the given element to hash table.
|
||||
* `registerRemovedElement` registers the given element to the hash set.
|
||||
*/
|
||||
func registerRemovedElement(_ element: CRDTElement) {
|
||||
self.removedElementSetByCreatedAt.insert(element.createdAt)
|
||||
|
@ -140,7 +140,7 @@ class CRDTRoot {
|
|||
}
|
||||
|
||||
/**
|
||||
* `garbageLength` returns length of nodes which should garbage collection task
|
||||
* `garbageLength` returns length of nodes which can be garbage collected.
|
||||
*/
|
||||
var garbageLength: Int {
|
||||
var count = 0
|
||||
|
|
|
@ -161,7 +161,7 @@ class RGATreeList {
|
|||
}
|
||||
|
||||
/**
|
||||
* `insert` adds next element of previously created node.
|
||||
* `insert` adds a new node with the value after the given node.
|
||||
*/
|
||||
func insert(_ value: CRDTElement, afterCreatedAt createdAt: TimeTicket, executedAt: TimeTicket? = nil) throws {
|
||||
let executedAt: TimeTicket = executedAt ?? value.createdAt
|
||||
|
@ -214,14 +214,14 @@ class RGATreeList {
|
|||
}
|
||||
|
||||
/**
|
||||
* `insert` adds the given element after the last creation time.
|
||||
* `insert` adds the given element after the last node.
|
||||
*/
|
||||
func insert(_ value: CRDTElement) throws {
|
||||
try self.insert(value, afterCreatedAt: self.last.createdAt)
|
||||
}
|
||||
|
||||
/**
|
||||
* `get` returns the element of the given index.
|
||||
* `get` returns the element of the given creation time.
|
||||
*/
|
||||
func get(createdAt: TimeTicket) throws -> CRDTElement {
|
||||
guard let node = self.nodeMapByCreatedAt[createdAt] else {
|
||||
|
@ -234,7 +234,7 @@ class RGATreeList {
|
|||
}
|
||||
|
||||
/**
|
||||
* `subpath` subpath of JSONPath based on the creation time of the node.
|
||||
* `subPath` returns the sub path of the given element.
|
||||
*/
|
||||
func subPath(createdAt: TimeTicket) throws -> String {
|
||||
guard let node = self.nodeMapByCreatedAt[createdAt] else {
|
||||
|
@ -247,7 +247,7 @@ class RGATreeList {
|
|||
}
|
||||
|
||||
/**
|
||||
* `delete` physically purges child element.
|
||||
* `delete` physically purges element.
|
||||
*/
|
||||
func delete(_ value: CRDTElement) throws {
|
||||
guard let node = self.nodeMapByCreatedAt[value.createdAt] else {
|
||||
|
@ -359,7 +359,7 @@ class RGATreeList {
|
|||
}
|
||||
|
||||
/**
|
||||
* `getLastCreatedAt` returns the creation time of last elements.
|
||||
* `getLastCreatedAt` returns the creation time of last element.
|
||||
*/
|
||||
func getLastCreatedAt() -> TimeTicket {
|
||||
return self.last.createdAt
|
||||
|
|
|
@ -33,13 +33,14 @@ struct ChangePack {
|
|||
private let changes: [Change]
|
||||
|
||||
/**
|
||||
* `snapshot` is a byte array that encode the document.
|
||||
* `snapshot` is a byte array that encodes the document.
|
||||
*/
|
||||
private let snapshot: Data?
|
||||
|
||||
/**
|
||||
* `minSyncedTicket` is the minimum logical time taken by clients who attach
|
||||
* the document. It used to collect garbage on the replica on the client.
|
||||
* to the document. It is used to collect garbage on the replica on the
|
||||
* client.
|
||||
*/
|
||||
private let minSyncedTicket: TimeTicket?
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ struct Checkpoint: Equatable {
|
|||
}
|
||||
|
||||
/**
|
||||
* `forward` updates the given checkpoint with those values when it is greater
|
||||
* than the values of internal properties.
|
||||
* `forward` creates a new instance with the given checkpoint if it is
|
||||
* greater than the values of internal properties.
|
||||
*/
|
||||
mutating func forward(other: Checkpoint) {
|
||||
if self == other {
|
||||
|
|
|
@ -34,6 +34,10 @@ public enum DocEventType: String {
|
|||
case remoteChange = "remote-change"
|
||||
}
|
||||
|
||||
/**
|
||||
* An event that occurs in ``Document``. It can be delivered
|
||||
* using ``Document/eventStream``.
|
||||
*/
|
||||
public protocol DocEvent {
|
||||
var type: DocEventType { get }
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@ import Foundation
|
|||
*/
|
||||
public typealias Presence = [String: Any]
|
||||
|
||||
/**
|
||||
* A CRDT-based data type. We can representing the model
|
||||
* of the application. And we can edit it even while offline.
|
||||
*
|
||||
*/
|
||||
public actor Document {
|
||||
private let key: String
|
||||
private var root: CRDTRoot
|
||||
|
@ -45,7 +50,7 @@ public actor Document {
|
|||
/**
|
||||
* `update` executes the given updater to update this document.
|
||||
*/
|
||||
public func update(updater: (_ root: JSONObject) -> Void, message: String? = nil) {
|
||||
public func update(_ updater: (_ root: JSONObject) -> Void, message: String? = nil) {
|
||||
let clone = self.cloned
|
||||
let context = ChangeContext(id: self.changeID.next(), root: clone, message: message)
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ struct AddOperation: Operation {
|
|||
}
|
||||
|
||||
/**
|
||||
* `effectedCreatedAt` returns the time of the effected element.
|
||||
* `effectedCreatedAt` returns the creation time of the effected element.
|
||||
*/
|
||||
var effectedCreatedAt: TimeTicket {
|
||||
return self.value.createdAt
|
||||
|
|
|
@ -43,7 +43,7 @@ struct MoveOperation: Operation {
|
|||
if parent == nil {
|
||||
log = "fail to find \(self.parentCreatedAt)"
|
||||
} else {
|
||||
log = "fail to execute, only array can execute add"
|
||||
log = "fail to execute, only array can execute move"
|
||||
}
|
||||
Logger.fatal(log)
|
||||
throw YorkieError.unexpected(message: log)
|
||||
|
@ -53,7 +53,7 @@ struct MoveOperation: Operation {
|
|||
}
|
||||
|
||||
/**
|
||||
* `effectedCreatedAt` returns the time of the effected element.
|
||||
* `effectedCreatedAt` returns the creation time of the effected element.
|
||||
*/
|
||||
var effectedCreatedAt: TimeTicket {
|
||||
return self.createdAt
|
||||
|
@ -63,6 +63,6 @@ struct MoveOperation: Operation {
|
|||
* `structureAsString` returns a string containing the meta data.
|
||||
*/
|
||||
var structureAsString: String {
|
||||
return "\(self.parentCreatedAt.structureAsString).MOV"
|
||||
return "\(self.parentCreatedAt.structureAsString).MOVE"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ protocol Operation {
|
|||
var executedAt: TimeTicket { get set }
|
||||
|
||||
/**
|
||||
* `effectedCreatedAt` returns the time of the effected element.
|
||||
* `effectedCreatedAt` returns the creation time of the effected element.
|
||||
*/
|
||||
var effectedCreatedAt: TimeTicket { get }
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ struct RemoveOperation: Operation {
|
|||
}
|
||||
|
||||
/**
|
||||
* `effectedCreatedAt` returns the time of the effected element.
|
||||
* `effectedCreatedAt` returns the creation time of the effected element.
|
||||
*/
|
||||
var effectedCreatedAt: TimeTicket {
|
||||
return self.parentCreatedAt
|
||||
|
|
|
@ -59,7 +59,7 @@ struct SetOperation: Operation {
|
|||
}
|
||||
|
||||
/**
|
||||
* `effectedCreatedAt` returns the time of the effected element.
|
||||
* `effectedCreatedAt` returns the creation time of the effected element.
|
||||
*/
|
||||
var effectedCreatedAt: TimeTicket {
|
||||
return self.value.createdAt
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
/// ``JSONObjectable`` provide a way to make a dictionary including members of a type confirming ``JSONObjectable``.
|
||||
/// `JSONObjectable` provides a way to make a dictionary including members of a type confirming ``JSONObjectable``.
|
||||
public protocol JSONObjectable: Codable {
|
||||
/// The members of ``JSONObjectable/excludedMembers`` is not included in a dictionary made by ``JSONObjectable/toJsonObject``.
|
||||
/// The members of excludedMembers is not included in a dictionary made by toJsonObject.
|
||||
var excludedMembers: [String] { get }
|
||||
}
|
||||
|
||||
public extension JSONObjectable {
|
||||
/// ``toJsonObject`` make a dictionary including members of a type confirming ``JSONObjectable``.
|
||||
/// `toJsonObject` make a dictionary including members of a type confirming ``JSONObjectable``.
|
||||
internal var toJsonObject: [String: Any] {
|
||||
guard let data = try? JSONEncoder().encode(self),
|
||||
let dictionary = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
|
||||
|
@ -51,8 +51,8 @@ public extension JSONObjectable {
|
|||
}
|
||||
}
|
||||
|
||||
/// ``toJsonArray`` provide a way to make an array including types confiming``JSONObjectable``, arrys, and values.
|
||||
internal extension Array {
|
||||
/// `toJsonArray` provides a way to make an array including types confiming``JSONObjectable``, arrys, and values.
|
||||
var toJsonArray: [Any] {
|
||||
self.map {
|
||||
if let value = $0 as? JSONObjectable {
|
||||
|
|
|
@ -93,7 +93,7 @@ class MoveOperationTests: XCTestCase {
|
|||
try target.execute(root: root)
|
||||
|
||||
XCTAssertEqual(root.debugDescription, "{\"k-a1\":\"a1\",\"k-a3\":[\"b1\",\"value-to-move\",{\"k-c1\":\"c1\"}]}")
|
||||
XCTAssertEqual(target.structureAsString, "4:actor-1:0.MOV")
|
||||
XCTAssertEqual(target.structureAsString, "4:actor-1:0.MOVE")
|
||||
XCTAssertEqual(target.effectedCreatedAt, target.createdAt)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue