Skip to content

Commit

Permalink
updates for 0.5.17 release
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Jun 14, 2024
1 parent 76e59a3 commit 52414f7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 216 deletions.
284 changes: 70 additions & 214 deletions AutomergeUniffi/automerge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ public protocol DocProtocol: AnyObject {

func marksAt(obj: ObjId, heads: [ChangeHash]) throws -> [Mark]

func marksAtPosition(obj: ObjId, position: Position, heads: [ChangeHash]) throws -> [Mark]

func merge(other: Doc) throws

func mergeWithPatches(other: Doc) throws -> [Patch]
Expand Down Expand Up @@ -1141,6 +1143,18 @@ open class Doc:
})
}

open func marksAtPosition(obj: ObjId, position: Position, heads: [ChangeHash]) throws -> [Mark] {
try FfiConverterSequenceTypeMark.lift(rustCallWithError(FfiConverterTypeDocError.lift) {
uniffi_uniffi_automerge_fn_method_doc_marks_at_position(
self.uniffiClonePointer(),
FfiConverterTypeObjId.lower(obj),
FfiConverterTypePosition.lower(position),
FfiConverterSequenceTypeChangeHash.lower(heads),
$0
)
})
}

open func merge(other: Doc) throws { try rustCallWithError(FfiConverterTypeDocError.lift) {
uniffi_uniffi_automerge_fn_method_doc_merge(
self.uniffiClonePointer(),
Expand Down Expand Up @@ -1668,49 +1682,6 @@ public func FfiConverterTypeKeyValue_lower(_ value: KeyValue) -> RustBuffer {
FfiConverterTypeKeyValue.lower(value)
}

public struct MapValue {
public var value: [String: AmValue]

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(value: [String: AmValue]) {
self.value = value
}
}

extension MapValue: Equatable, Hashable {
public static func == (lhs: MapValue, rhs: MapValue) -> Bool {
if lhs.value != rhs.value {
return false
}
return true
}

public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
}

public struct FfiConverterTypeMapValue: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MapValue {
try MapValue(
value: FfiConverterDictionaryStringTypeAMValue.read(from: &buf)
)
}

public static func write(_ value: MapValue, into buf: inout [UInt8]) {
FfiConverterDictionaryStringTypeAMValue.write(value.value, into: &buf)
}
}

public func FfiConverterTypeMapValue_lift(_ buf: RustBuffer) throws -> MapValue {
try FfiConverterTypeMapValue.lift(buf)
}

public func FfiConverterTypeMapValue_lower(_ value: MapValue) -> RustBuffer {
FfiConverterTypeMapValue.lower(value)
}

public struct Mark {
public var start: UInt64
public var end: UInt64
Expand Down Expand Up @@ -1880,132 +1851,6 @@ public func FfiConverterTypePathElement_lower(_ value: PathElement) -> RustBuffe
FfiConverterTypePathElement.lower(value)
}

public struct TextValue {
public var value: String
public var marks: [Mark]

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(value: String, marks: [Mark]) {
self.value = value
self.marks = marks
}
}

extension TextValue: Equatable, Hashable {
public static func == (lhs: TextValue, rhs: TextValue) -> Bool {
if lhs.value != rhs.value {
return false
}
if lhs.marks != rhs.marks {
return false
}
return true
}

public func hash(into hasher: inout Hasher) {
hasher.combine(value)
hasher.combine(marks)
}
}

public struct FfiConverterTypeTextValue: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TextValue {
try TextValue(
value: FfiConverterString.read(from: &buf),
marks: FfiConverterSequenceTypeMark.read(from: &buf)
)
}

public static func write(_ value: TextValue, into buf: inout [UInt8]) {
FfiConverterString.write(value.value, into: &buf)
FfiConverterSequenceTypeMark.write(value.marks, into: &buf)
}
}

public func FfiConverterTypeTextValue_lift(_ buf: RustBuffer) throws -> TextValue {
try FfiConverterTypeTextValue.lift(buf)
}

public func FfiConverterTypeTextValue_lower(_ value: TextValue) -> RustBuffer {
FfiConverterTypeTextValue.lower(value)
}

// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.

public enum AmValue {
case scalar(
value: ScalarValue
)
case list(
value: [AmValue]
)
case map(
value: MapValue
)
case text(
value: TextValue
)
}

public struct FfiConverterTypeAMValue: FfiConverterRustBuffer {
typealias SwiftType = AmValue

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AmValue {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return try .scalar(
value: FfiConverterTypeScalarValue.read(from: &buf)
)

case 2: return try .list(
value: FfiConverterSequenceTypeAMValue.read(from: &buf)
)

case 3: return try .map(
value: FfiConverterTypeMapValue.read(from: &buf)
)

case 4: return try .text(
value: FfiConverterTypeTextValue.read(from: &buf)
)

default: throw UniffiInternalError.unexpectedEnumCase
}
}

public static func write(_ value: AmValue, into buf: inout [UInt8]) {
switch value {
case let .scalar(value):
writeInt(&buf, Int32(1))
FfiConverterTypeScalarValue.write(value, into: &buf)

case let .list(value):
writeInt(&buf, Int32(2))
FfiConverterSequenceTypeAMValue.write(value, into: &buf)

case let .map(value):
writeInt(&buf, Int32(3))
FfiConverterTypeMapValue.write(value, into: &buf)

case let .text(value):
writeInt(&buf, Int32(4))
FfiConverterTypeTextValue.write(value, into: &buf)
}
}
}

public func FfiConverterTypeAMValue_lift(_ buf: RustBuffer) throws -> AmValue {
try FfiConverterTypeAMValue.lift(buf)
}

public func FfiConverterTypeAMValue_lower(_ value: AmValue) -> RustBuffer {
FfiConverterTypeAMValue.lower(value)
}

extension AmValue: Equatable, Hashable {}

public enum DecodeSyncStateError {
case Internal(message: String)
}
Expand Down Expand Up @@ -2372,6 +2217,59 @@ extension PatchAction: Equatable, Hashable {}
// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.

public enum Position {
case cursor(
position: Cursor
)
case index(
position: UInt64
)
}

public struct FfiConverterTypePosition: FfiConverterRustBuffer {
typealias SwiftType = Position

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Position {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return try .cursor(
position: FfiConverterTypeCursor.read(from: &buf)
)

case 2: return try .index(
position: FfiConverterUInt64.read(from: &buf)
)

default: throw UniffiInternalError.unexpectedEnumCase
}
}

public static func write(_ value: Position, into buf: inout [UInt8]) {
switch value {
case let .cursor(position):
writeInt(&buf, Int32(1))
FfiConverterTypeCursor.write(position, into: &buf)

case let .index(position):
writeInt(&buf, Int32(2))
FfiConverterUInt64.write(position, into: &buf)
}
}
}

public func FfiConverterTypePosition_lift(_ buf: RustBuffer) throws -> Position {
try FfiConverterTypePosition.lift(buf)
}

public func FfiConverterTypePosition_lower(_ value: Position) -> RustBuffer {
FfiConverterTypePosition.lower(value)
}

extension Position: Equatable, Hashable {}

// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.

public enum Prop {
case key(
value: String
Expand Down Expand Up @@ -2892,28 +2790,6 @@ private struct FfiConverterSequenceTypePathElement: FfiConverterRustBuffer {
}
}

private struct FfiConverterSequenceTypeAMValue: FfiConverterRustBuffer {
typealias SwiftType = [AmValue]

public static func write(_ value: [AmValue], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeAMValue.write(item, into: &buf)
}
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [AmValue] {
let len: Int32 = try readInt(&buf)
var seq = [AmValue]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
try seq.append(FfiConverterTypeAMValue.read(from: &buf))
}
return seq
}
}

private struct FfiConverterSequenceTypeScalarValue: FfiConverterRustBuffer {
typealias SwiftType = [ScalarValue]

Expand Down Expand Up @@ -2980,29 +2856,6 @@ private struct FfiConverterSequenceTypeChangeHash: FfiConverterRustBuffer {
}
}

private struct FfiConverterDictionaryStringTypeAMValue: FfiConverterRustBuffer {
public static func write(_ value: [String: AmValue], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterTypeAMValue.write(value, into: &buf)
}
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: AmValue] {
let len: Int32 = try readInt(&buf)
var dict = [String: AmValue]()
dict.reserveCapacity(Int(len))
for _ in 0 ..< len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterTypeAMValue.read(from: &buf)
dict[key] = value
}
return dict
}
}

private struct FfiConverterDictionaryStringTypeValue: FfiConverterRustBuffer {
public static func write(_ value: [String: Value], into buf: inout [UInt8]) {
let len = Int32(value.count)
Expand Down Expand Up @@ -3300,6 +3153,9 @@ private var initializationResult: InitializationResult {
if uniffi_uniffi_automerge_checksum_method_doc_marks_at() != 57491 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_uniffi_automerge_checksum_method_doc_marks_at_position() != 19243 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_uniffi_automerge_checksum_method_doc_merge() != 8598 {
return InitializationResult.apiChecksumMismatch
}
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if ProcessInfo.processInfo.environment["LOCAL_BUILD"] != nil {
} else {
FFIbinaryTarget = .binaryTarget(
name: "automergeFFI",
url: "https://github.com/automerge/automerge-swift/releases/download/0.5.16/automergeFFI.xcframework.zip",
checksum: "434e7430c721b77b91038e6690f1a0a9a4b73e1b82b5f4cb6acfb1f950609cdf"
url: "https://github.com/automerge/automerge-swift/releases/download/0.5.17/automergeFFI.xcframework.zip",
checksum: "fb2a6fc45b427c87f39d11cf749c6f59052579996eae3b4881df69b1c25cbd5f"
)
}

Expand Down
11 changes: 11 additions & 0 deletions Sources/_CAutomergeUniffi/include/automergeFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ RustBuffer uniffi_uniffi_automerge_fn_method_doc_marks(void*_Nonnull ptr, RustBu
RustBuffer uniffi_uniffi_automerge_fn_method_doc_marks_at(void*_Nonnull ptr, RustBuffer obj, RustBuffer heads, RustCallStatus *_Nonnull out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_MARKS_AT_POSITION
#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_MARKS_AT_POSITION
RustBuffer uniffi_uniffi_automerge_fn_method_doc_marks_at_position(void*_Nonnull ptr, RustBuffer obj, RustBuffer position, RustBuffer heads, RustCallStatus *_Nonnull out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_MERGE
#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_FN_METHOD_DOC_MERGE
void uniffi_uniffi_automerge_fn_method_doc_merge(void*_Nonnull ptr, void*_Nonnull other, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -1154,6 +1159,12 @@ uint16_t uniffi_uniffi_automerge_checksum_method_doc_marks(void
#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_MARKS_AT
uint16_t uniffi_uniffi_automerge_checksum_method_doc_marks_at(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_MARKS_AT_POSITION
#define UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_MARKS_AT_POSITION
uint16_t uniffi_uniffi_automerge_checksum_method_doc_marks_at_position(void

);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_UNIFFI_AUTOMERGE_CHECKSUM_METHOD_DOC_MERGE
Expand Down

0 comments on commit 52414f7

Please sign in to comment.