Framework Migration Guide

swift-ddd-kit  1.3 → 1.4

EventStore 契約、本機事件儲存與 iOS — 給「依賴 swift-ddd-kit 的下游專案」的升級指南,一併涵蓋 1.4 預覽版期間的變更

target: swift-ddd-kit Swift 6.1+ / Ubuntu / macOS 15+ / iOS 18+ ⚠ source-breaking + behaviour change audience: human + AI agent
version transition
FROM1.3
→
TO1.4

1.3.0 之後的下一個穩定版是 1.4.0。1.4 把每個 EventStore 該怎麼做寫成一份契約 (revision 從 0 起算、版本不符一律丟 DDDError.commitConflict、purge 改為永久的 tombstone), 新增檔案式的 PersistentEventStore,並讓 DDDCore、EventSourcing、LocalEventStore 以 product 發佈、可建置於 iOS 18+。1.4 預覽版期間已發佈的 Postgres read model 強化、template variables 與 forwarder 變更也在本指南內。 AggregateRoot / DomainEvent / Usecase 的介面不變。

誰受影響

如果你的專案…要看的項目
依賴 swift-ddd-kit 的任何 productSB1 swift-kurrentdb ≥ 2.6.0、SB6 Swift 6.1+
以 iOS 或 Mac Catalyst 為建置目標SB5 最低版本 18
對 DDDError.Code 或 EventStoreClientError 寫了沒有 default 的 switchSB2
用 DomainEventGeneratorPlugin/generate event 產生事件SB3 產出檔的 import
使用 ContextForwarder 的 ForwardingRuleSB4、BC8
自己實作或包裝 EventStoreClientSB7、BC2
呼叫 purge,或 catch 版本衝突錯誤BC1、BC3、BC5
在測試裡用 InMemoryStorageCoordinator 或 InMemoryEventStoreClientBC4
使用 Postgres read model 或 Kurrent 的 subscription runnerBC6、BC7
只用 AggregateRoot / DomainEvent / Usecase 與內建 storebump 版本、重新生成、跑測試;再讀一次 BC1

🤖 AI Migration Manifest(機器可讀)

若你是 AI agent,正在把一個依賴 swift-ddd-kit 的專案從 1.3 升到 1.4 — 直接消化下方 JSON。每條規則含 kind(變更類型)、mechanical (能否純文字取代)、before/after、action(對下游要做什麼)。 套用順序:先處理 source-breaking 讓專案編得過,再逐條檢查 behaviour-change (編譯器不會指出這些)。scope 標示要掃描的程式碼位置。

{
  "schema": "swift-ddd-kit-migration/v1",
  "package": "swift-ddd-kit",
  "from": "1.3",
  "to": "1.4",
  "domainLayerImpact": "none",
  "applyOrder": ["source-breaking", "behaviour-change", "new"],
  "rules": [
    {
      "id": "SB1",
      "kind": "source-breaking",
      "mechanical": true,
      "scope": "Package.swift of the downstream project, only if it depends on swift-kurrentdb directly",
      "before": ".package(url: \"https://github.com/gradyzhuo/swift-kurrentdb.git\", from: \"2.3.0\")",
      "after": ".package(url: \"https://github.com/gradyzhuo/swift-kurrentdb.git\", from: \"2.6.0\")",
      "action": "swift-ddd-kit 1.4 requires swift-kurrentdb 2.6.0 or later (its reads report tombstoned streams as KurrentError.resourceDeleted). Raise any direct requirement below 2.6.0."
    },
    {
      "id": "SB2",
      "kind": "source-breaking",
      "mechanical": false,
      "scope": "exhaustive switch statements over DDDError.Code or EventStoreClientError without a default",
      "before": "switch error.code { case .aggregateNotFound: ... }",
      "after": "add cases .commitConflict (501), .streamPurged (502), .storeUnavailable (503), .storeCorrupted (504); for EventStoreClientError add .subscriptionGroupNotFound(stream:group:) and .tombstoneUnsupported",
      "action": "Handle the new enum cases or add a default."
    },
    {
      "id": "SB3",
      "kind": "source-breaking",
      "mechanical": false,
      "scope": "event.yaml and event-generator-config.yaml of targets using DomainEventGeneratorPlugin",
      "before": "generated files import KurrentSupport and KurrentDB; event.yaml may name KurrentSupport.CustomMetadata",
      "after": "generated files import Foundation, DDDCore and EventSourcing only",
      "action": "If event.yaml qualifies a type with KurrentSupport (e.g. KurrentSupport.CustomMetadata) or uses an unqualified type only KurrentSupport/KurrentDB provide, either change it to EventSourcing.CustomMetadata / unqualified CustomMetadata, or add `dependencies: [KurrentSupport]` to event-generator-config.yaml. Then regenerate."
    },
    {
      "id": "SB4",
      "kind": "source-breaking",
      "mechanical": false,
      "scope": "ForwardingRule translate closures (ContextForwarder)",
      "before": "ForwardingRule(eventTypes: [\"X\"]) { record in try makeEvent(record) }   // PublishedLanguageEvent?",
      "after": "ForwardingRule(eventTypes: [\"X\"]) { record in [try makeEvent(record)] } // [PublishedLanguageEvent]",
      "action": "Return an array; return [] where the closure returned nil. When one record yields several events, give each a stable, distinct eventId."
    },
    {
      "id": "SB5",
      "kind": "source-breaking",
      "mechanical": false,
      "scope": "iOS and Mac Catalyst deployment targets of any project building any swift-ddd-kit product",
      "before": "iOS / Mac Catalyst deployment target below 18",
      "after": "iOS / Mac Catalyst deployment target 18 or later",
      "action": "Package.swift now declares .iOS(.v18); it applies to every product. Raise the deployment target to 18. macOS (15+) and Linux projects are unaffected."
    },
    {
      "id": "SB6",
      "kind": "source-breaking",
      "mechanical": false,
      "scope": "toolchain used to build the downstream project",
      "before": "Swift 6.0 toolchain",
      "after": "Swift 6.1 or later (swift-tools-version: 6.1)",
      "action": "Build with Swift 6.1 or later."
    },
    {
      "id": "SB7",
      "kind": "source-breaking",
      "mechanical": false,
      "scope": "types conforming to EventStoreClient (wrappers, decorators, custom fakes)",
      "before": "conformance implements append, readStream, deleteStream, subscribePersistent",
      "after": "conformance also implements ensurePersistentSubscription(stream:group:settings:), deletePersistentSubscription(stream:group:) and tombstoneStream(name:)",
      "action": "Implement or forward the two persistent-subscription requirements (no default; compile error otherwise). Also forward tombstoneStream(name:) — see BC2."
    },
    {
      "id": "BC1",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "every call of purge(byId:) on a repository or store",
      "before": "KurrentStorageCoordinator.purge soft-deletes; the id could be written again; EventSourcingRepository.purge threw aggregateNotFound for an unknown id",
      "after": "purge tombstones the stream permanently; a later non-empty append throws DDDError.streamPurged (502); purge of a never-written id succeeds and reserves the id forever; EventSourcingRepository.purge no longer calls find first",
      "action": "Do not purge ids that will be reused. Remove code relying on purge-then-recreate or on aggregateNotFound from purge. purge succeeds every time it is repeated and checks no version, so code using read-then-purge as a run-once guard must become find, markDelete, save (version-checked: one caller wins, the others get DDDError.commitConflict), then purge."
    },
    {
      "id": "BC2",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "types conforming to EventStoreClient, including wrappers around LiveEventStoreClient",
      "before": "no tombstoneStream requirement",
      "after": "func tombstoneStream(name: String) async throws { try await base.tombstoneStream(name: name) }",
      "action": "Without it the conformance still compiles (deprecated default, warning), but KurrentStorageCoordinator.purge throws EventStoreClientError.tombstoneUnsupported at run time and nothing is purged. Implement or forward it."
    },
    {
      "id": "BC3",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "catch clauses around append/save",
      "before": "catch KurrentError.wrongExpectedVersion / EventStoreClientError.wrongExpectedRevision / InMemoryStorageCoordinatorError.versionConflict",
      "after": "catch let error as DDDError where error.code == .commitConflict { let conflict = error.commitConflict }",
      "action": "Version conflicts from KurrentStorageCoordinator and InMemoryEventStore are always DDDError.commitConflict (501), carrying CommitConflict { id, expected, actual }."
    },
    {
      "id": "BC4",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "tests and code using InMemoryStorageCoordinator, InMemoryEventStoreClient, or relying on store edge cases",
      "before": "InMemoryStorageCoordinator: 1-based revisions, version nil unchecked; fetchEvents sorted by occurred",
      "after": "InMemoryEventStore: 0-based revisions, version nil requires a new stream; fetchEvents in stream order; empty append returns nil without writing; save with no new events does not call the store; InMemoryEventStoreClient models tombstones and event-id idempotency",
      "action": "Rename InMemoryStorageCoordinator to InMemoryEventStore (the old name is a deprecated typealias) and update tests that assert revisions or conflicts."
    },
    {
      "id": "BC5",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "callers passing very large expected versions to KurrentStorageCoordinator.append",
      "before": "version > Int64.max was sent to KurrentDB, which returned an internal gRPC error",
      "after": "version > UInt64(Int64.max) is not sent; throws DDDError.commitConflict with actual = the stream's last revision (nil if absent), or streamPurged if the stream is tombstoned",
      "action": "Nothing to change unless code matched on the old gRPC error."
    },
    {
      "id": "BC6",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "Postgres read model stores, PostgresReadModelMigration, PostgresReadModelSnapshots",
      "before": "unconditional upsert into read_model_snapshots",
      "after": "default SnapshotWriteMode.monotonic writes read_model_snapshots_monotonic and only accepts a strictly newer revision",
      "action": "Existing users of the default table either rebuild (KurrentProjection.rebuild) or pass writeMode: .overwrite. Pass the same tableName/writeMode to the migration, the stores and PostgresReadModelSnapshots."
    },
    {
      "id": "BC7",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "KurrentProjection.PersistentSubscriptionRunner and TransactionalSubscriptionRunner",
      "before": "runners subscribed to an existing group only; transactional runner dispatched projectors concurrently; generated apply() used default: return",
      "after": "subscriptionSetup defaults to .ensure(...): the runner creates the group, recreates it if it disappears and rethrows subscriptionGroupNotFound; projectors dispatch sequentially in registration order; generated apply() uses default: continue",
      "action": "Credentials need permission to create persistent subscriptions, or pass subscriptionSetup: .manual. Restart run() after subscriptionGroupNotFound (restart loop with backoff). Regenerate projector code."
    },
    {
      "id": "BC8",
      "kind": "behaviour-change",
      "mechanical": false,
      "scope": "ContextForwarder hosts",
      "before": "a missing subscription group made the forwarder retry forever",
      "after": "the forwarder recreates the group from subscriptionSettings.startFrom (default .end) and rethrows; events written while the group was missing are not forwarded",
      "action": "No code change; be aware of the gap when a group is recreated from .end."
    },
    {
      "id": "N1",
      "kind": "new",
      "mechanical": false,
      "scope": "imports of RecordedEventLike, EventTypeMapper, CustomMetadata",
      "after": "defined in EventSourcing; KurrentSupport keeps public typealiases",
      "action": "Nothing required; `import KurrentSupport` code keeps compiling."
    },
    {
      "id": "N2",
      "kind": "new",
      "mechanical": false,
      "scope": "iOS/macOS apps that want a local event store",
      "after": "PersistentEventStore.open(directory:eventMapper:) in the LocalEventStore product",
      "action": "Optional. See the README section 'Local Event Store (iOS and macOS apps)'."
    },
    {
      "id": "N3",
      "kind": "new",
      "mechanical": false,
      "scope": "Package.swift product dependencies",
      "after": ".product(name: \"DDDCore\" | \"EventSourcing\" | \"LocalEventStore\", package: \"swift-ddd-kit\")",
      "action": "Optional. Apps can depend on these three products without pulling in the DDDKit umbrella."
    },
    {
      "id": "N4",
      "kind": "new",
      "mechanical": false,
      "scope": "1.4 additions",
      "after": "TemplateVariables, TemplateVariablesDefinition, VariablesGeneratorPlugin; ForwardedRecord.metadata and decodeMetadata(_:); SnapshotWriteMode, ReadModelSnapshotPurging, ReadModel.readModelTypeName, KurrentProjection.rebuild, KurrentProjection.SubscriptionSetup; PublishedLanguageEvent.actorId; onCommitted(_:) and CommittedProjection on both runners",
      "action": "Optional."
    }
  ],
  "downstreamProcedure": [
    "Use a Swift 6.1+ toolchain (SB6).",
    "Bump swift-ddd-kit to from: \"1.4.0\"; raise any direct swift-kurrentdb requirement to 2.6.0 (SB1).",
    "Raise iOS / Mac Catalyst deployment targets to 18 (SB5).",
    "Rebuild and regenerate generated code; fix event.yaml types or add the KurrentSupport dependency (SB3).",
    "Fix ForwardingRule closures to return arrays (SB4).",
    "Handle the new DDDError.Code and EventStoreClientError cases (SB2).",
    "In custom EventStoreClient conformances, implement or forward ensurePersistentSubscription, deletePersistentSubscription and tombstoneStream (SB7, BC2).",
    "Replace catches of the old conflict errors with DDDError.commitConflict (BC3).",
    "Rename InMemoryStorageCoordinator to InMemoryEventStore and fix tests that assert revisions (BC4).",
    "Review every purge call: purged ids can never be written again (BC1).",
    "Postgres read models: choose writeMode .monotonic (rebuild) or .overwrite (keep the existing table) (BC6).",
    "Subscription runners: grant permission to create groups or use .manual; restart run() on subscriptionGroupNotFound (BC7).",
    "Build; run the test suite."
  ]
}

Source-breaking 變更

這些變更會讓既有程式碼編不過,編譯器會指出位置。

SB1  dependency  swift-kurrentdb ≥ 2.6.0

2.6.0 讓讀取已 tombstone 的 stream 回報 KurrentError.resourceDeleted,1.4 的 purge 語意依賴它。 swift-ddd-kit 1.3 要求 2.3.0;若你的 Package.swift 直接依賴 swift-kurrentdb,下限要一起提高。

- .package(url: "https://github.com/gradyzhuo/swift-kurrentdb.git", from: "2.3.0")
+ .package(url: "https://github.com/gradyzhuo/swift-kurrentdb.git", from: "2.6.0")

SB2  enum case  DDDError.Code 501–504 與 EventStoreClientError 新 case

型別新增 case來源
DDDError.CodecommitConflict(501)、streamPurged(502)、storeUnavailable(503)、storeCorrupted(504)1.4.0
EventStoreClientErrortombstoneUnsupported1.4.0
EventStoreClientErrorsubscriptionGroupNotFound(stream:group:)1.4.0-beta.12

沒有 default 的 exhaustive switch 需要補上這些 case。storeUnavailable 的原因以 error.storeUnavailableReason(DDDError.StoreUnavailableReason:invalidLocation、 streamNameTooLong、io、occupied、closed)讀取;目前只有 PersistentEventStore 丟 503/504。

SB3  codegen  Generator 產出檔的 import

產出檔現在 import Foundation、DDDCore、EventSourcing,不再 import KurrentSupport/KurrentDB。 若 event.yaml 以 KurrentSupport 限定型別(例如 KurrentSupport.CustomMetadata),或使用只有 KurrentSupport/KurrentDB 提供的非限定型別,重新生成後會編譯失敗;KurrentSupport 的 typealias 無法補救,因為該模組沒被 import。二選一:

做法一:改型別名稱(event.yaml)

- actorMetadata: KurrentSupport.CustomMetadata
+ actorMetadata: EventSourcing.CustomMetadata
  # 或非限定的 CustomMetadata

做法二:補依賴(event-generator-config.yaml)

accessModifier: public
dependencies:
  - KurrentSupport

SB4  signature  ForwardingRule.translate 回傳陣列(1.4.0-beta.9)

- ForwardingRule(eventTypes: ["X"]) { record in try makeEvent(record) }      // PublishedLanguageEvent?
+ ForwardingRule(eventTypes: ["X"]) { record in [try makeEvent(record)] }    // [PublishedLanguageEvent]

原本回 nil 的地方改回 []。一筆紀錄產生多個事件時,每個事件要有穩定且不重複的 eventId(見 ForwardingRule 的 doc comment)。

SB5  platform  iOS/Mac Catalyst 最低版本 18

Package.swift 的 platforms 加上 .iOS(.v18),這個值套用到本 package 的每一個 product, 不只新的三個。以 iOS 或 Mac Catalyst 18 以下為目標建置任一 product 的專案會建置失敗,需把 deployment target 提高到 18。 只建置 macOS(仍是 15+)或 Linux 的專案不受影響。

SB6  toolchain  Swift 6.1+(1.4.0-beta.12)

swift-tools-version 從 6.0 提高到 6.1,Swift 6.0 工具鏈無法再建置本 package。

SB7  protocol  EventStoreClient 新 requirement(1.4.0-beta.12)

自訂的 EventStoreClient conformance(wrapper、decorator、自製 fake)必須實作 ensurePersistentSubscription(stream:group:settings:) 與 deletePersistentSubscription(stream:group:),這兩個沒有預設實作。 1.4 另外新增的 tombstoneStream(name:) 有預設實作,編得過但執行時會失敗,見 BC2。

行為變更

編譯器不會指出這些 以下變更不影響編譯,但改變執行結果。升級後請逐條對照自己的程式碼與測試。

BC1  permanent  purge 改為 tombstone

  • KurrentStorageCoordinator.purge 呼叫 KurrentDB 的 tombstone(.any):stream 永遠無法再寫入,之後對同一 id 的 append 丟 DDDError.streamPurged(502)。先 purge 再用同一個 id 重建 aggregate 的做法不再可行。
  • 對從未寫過的 id 呼叫 purge 也會成功,並讓該 id 永久保留。不要 purge 之後還會使用的 id。
  • EventSourcingRepository.purge 不再先 find:未知的 id 不再丟 aggregateNotFound,已 soft-delete 的 aggregate 也可以被 purge。
  • 重複 purge 同一個 id 每次都成功,也不檢查版本。以「讀取 → purge」保證只執行一次的程式(例如一次性 token)不再有保證:並發的請求會全部成功。改成 find → markDelete → save → purge;save 會檢查版本,只有一個請求成功,其餘丟 DDDError.commitConflict。
  • 資料不會被物理抹除:KurrentDB 保留到 scavenge;PersistentEventStore 則從 stream 檔中移除 payload。

BC2  runtime  wrapper 必須轉呼叫 tombstoneStream(name:)

EventStoreClient 新增 tombstoneStream(name:)。協定擴充提供標為 deprecated 的預設實作,所以舊的 conformance 編得過,只有一個 deprecation 警告;但 purge 在執行時丟 EventStoreClientError.tombstoneUnsupported,stream 也不會被 purge。

struct LoggingClient: EventStoreClient {
    let base: any EventStoreClient
    // ...其他 requirement...
    func tombstoneStream(name: String) async throws {
        try await base.tombstoneStream(name: name)
    }
}

BC3  error  版本衝突統一丟 DDDError.commitConflict

KurrentStorageCoordinator 與 InMemoryEventStore 在衝突時都丟 DDDError.commitConflict(501),取代 EventStoreClientError.wrongExpectedRevision、KurrentError.wrongExpectedVersion、InMemoryStorageCoordinatorError.versionConflict。

- } catch KurrentError.wrongExpectedVersion { ... }
+ } catch let error as DDDError where error.code == .commitConflict {
+     let conflict = error.commitConflict   // CommitConflict { id, expected, actual }
+     ...
+ }

BC4  contract  其他 store 行為

  • 空陣列的 append 直接回傳 nil,不寫入也不呼叫 client。
  • 對已存在的 stream 傳 version: nil 會衝突(nil 代表要求 stream 尚不存在)。
  • fetchEvents 依 stream 回傳的順序,不再依 occurred 排序。
  • EventSourcingRepository.save 在沒有新事件時不呼叫 store。
  • InMemoryStorageCoordinator 更名為 InMemoryEventStore(舊名保留為 deprecated typealias,最早 1.6 移除),revision 從 0 起算。斷言 revision 或衝突的測試要更新。
  • InMemoryEventStoreClient 現在模擬 tombstone 與事件 id 冪等重送,與真 server 一致。

BC5  error  超過 Int64.max 的預期 revision

KurrentDB 無法接受大於 Int64.max 的預期 revision,以前會得到 server 回的 gRPC 內部錯誤。現在 KurrentStorageCoordinator.append 在 version 大於 UInt64(Int64.max) 時不送出 append,改丟 DDDError.commitConflict,actual 為讀 stream 得到的尾端 revision(stream 不存在時為 nil); 該 stream 已被 tombstone 時丟 streamPurged。Int64.max 本身照常送出。

BC6  default  Postgres snapshot 預設改為 monotonic(1.4.0-beta.12)

Postgres stores 與 PostgresReadModelMigration 預設 SnapshotWriteMode.monotonic:只接受嚴格較新的 revision, 寫入 read_model_snapshots_monotonic 表。原本使用預設表 read_model_snapshots 的專案二選一:以 KurrentProjection.rebuild 重建,或傳 writeMode: .overwrite 沿用舊表與舊行為。 migration、stores 與 PostgresReadModelSnapshots 要傳相同的 tableName/writeMode。

BC7  runner  Subscription runner 自行管理 group(1.4.0-beta.12)

  • 兩個 runner 的 subscriptionSetup: 預設 .ensure(...):訂閱前建立 group;group 消失時重建並丟 subscriptionGroupNotFound,呼叫端要再呼叫 run()(例如帶 backoff 的重啟迴圈)。需要建立 persistent subscription 的權限;沒有權限時傳 .manual 維持舊行為。
  • TransactionalSubscriptionRunner 依註冊順序逐一 dispatch projector,不再併發。
  • 生成的 projector apply() 改用 default: continue,遇到未列出的事件不再中斷整個 fold。重新生成即可。

BC8  forwarder  ContextForwarder 重建遺失的 group(1.4.0-beta.11)

訂閱 group 在執行期間消失時,forwarder 以原本的設定重建 group 並丟出錯誤,讓外層在 backoff 後重新訂閱。新 group 從 subscriptionSettings.startFrom(預設 .end)開始讀,group 消失期間寫入的事件不會補送。

新增功能

以下都不需要修改既有程式碼。

ID新增說明來源
N1RecordedEventLike、EventTypeMapper、CustomMetadata 移到 EventSourcingKurrentSupport 保留同名 typealias,既有的 import KurrentSupport 程式碼不需修改。非 Kurrent 的 store 可以重用生成的 mapper。1.4.0
N2PersistentEventStore(LocalEventStore)給 iOS/macOS app 的檔案式 EventStore,每個 stream 一個 JSON 檔、原子寫入。一個目錄只能開一個 instance,repository 與 projector 共用它;在 .defaultIsolation(MainActor.self) 的 target 中,aggregate、projector 與 read model 要宣告為 nonisolated。見 README 的 Local Event Store 章節。1.4.0
N3DDDCore、EventSourcing、LocalEventStore product三者只依賴彼此、Foundation 與 swift-log,可建置於 iOS 18+;app 不必拉進 DDDKit umbrella。1.4.0
BC4InMemoryEventStore符合 EventStore 契約的 in-memory store,取代 InMemoryStorageCoordinator。1.4.0
—ContextReceiverWebSocket 支援 macOSPulsar WebSocket transport 不再限 Linux。1.4.0(#32)
N4Template variables:TemplateVariables、TemplateVariablesDefinition、VariablesGeneratorPluginvariables.yaml 生成型別化的 protocol;PlaceholderSubstitution 以單一遍歷填入 %Placeholder%。1.4.0-beta.9
N4ForwardedRecord.metadata、decodeMetadata(_:)forwarder rule 可讀 KurrentDB 的 custom metadata,自選解碼型別。1.4.0-beta.10
N4SnapshotWriteMode、ReadModelSnapshotPurging、ReadModel.readModelTypeName、KurrentProjection.rebuild、KurrentProjection.SubscriptionSetupPostgres read model 上線強化(行為面見 BC6、BC7)。1.4.0-beta.12
N4PublishedLanguageEvent.actorId選填;為 nil 時不出現在 wire 上,既有 consumer 收到的訊息不變。1.4.0-beta.13
N4onCommitted(_:)、KurrentProjection.CommittedProjection兩個 runner 的 opt-in after-commit hook,在背景依序執行,不延遲下一筆 delivery。1.4.0-beta.14

1.4 預覽版與 1.4.0

每個 main-line tag 一列,依 git log --first-parent 整理。

Tag使用者看得到的變更PR
1.4.0-beta.9Template variables 框架;ForwardingRule.translate 回傳陣列(SB4)。—
1.4.0-beta.10ForwardedRecord 帶 custom metadata,rule 自選解碼型別。#24
1.4.0-beta.11ContextForwarder 重建遺失的 subscription group(BC8)。#25
1.4.0-beta.12Postgres read model 上線強化(BC6、BC7、SB7);Swift 6.1 下限(SB6);各版本的 DocC 文件站。#26 #27 #28
1.4.0-beta.13PublishedLanguageEvent.actorId。#29
1.4.0-beta.14兩個 runner 的 onCommitted(_:) after-commit hook。#30
1.4.0EventStore 契約(SB1–SB3、BC1–BC4、N1);ContextReceiverWebSocket 支援 macOS;PersistentEventStore(N2)。product、iOS 18 與 Int64.max 防護(SB5、N3、BC5)。#31 #32 #33 #34
1.4.0-beta.0 到 beta.8 這些預覽版屬於已停用的版本線。只在那條線上出現的模組,例如 NotificationDefinition,不在 1.4.0 內。

升級步驟清單

先處理會讓編譯失敗的項目,再逐條檢查行為變更。

  1. 工具鏈 — 使用 Swift 6.1 以上(SB6)。
  2. Bump 依賴 — swift-ddd-kit 改成 from: "1.4.0";若直接依賴 swift-kurrentdb,下限改成 2.6.0(SB1)。
  3. iOS 目標 — iOS/Mac Catalyst 的 deployment target 提高到 18(SB5)。
  4. 重新生成 — 重建讓 plugin 重新產生程式碼;event.yaml 若以 KurrentSupport 限定型別,改型別或在 config 補 dependencies(SB3)。
  5. Forwarder rule — ForwardingRule 的 closure 改回傳陣列(SB4)。
  6. Exhaustive switch — 補上 DDDError.Code 501–504 與 EventStoreClientError 的新 case(SB2)。
  7. 自訂 EventStoreClient — 實作或轉呼叫 ensurePersistentSubscription、deletePersistentSubscription 與 tombstoneStream;確認沒有 tombstoneStream 的 deprecation 警告(SB7、BC2)。
  8. 衝突處理 — catch 舊衝突錯誤的地方改成 DDDError.commitConflict(BC3)。
  9. In-memory store — InMemoryStorageCoordinator 改成 InMemoryEventStore,更新斷言 revision 的測試(BC4)。
  10. Purge — 逐一檢查 purge 的呼叫:被 purge 的 id 永遠無法再寫入(BC1)。
  11. Postgres read model — 選定 writeMode:.monotonic 搭配 rebuild,或 .overwrite 沿用既有表(BC6)。
  12. Runner — 確認帳號能建立 persistent subscription,否則傳 subscriptionSetup: .manual;run() 丟 subscriptionGroupNotFound 後要重新啟動(BC7)。
  13. 編譯 + 測試 — swift build 解掉剩餘錯誤,跑測試套件確認行為。

參考 KurrentDB 版本

kurrentplatform/kurrentdb:26.1.3 CI 的 kurrent-live-contract job 以這個 image 對真實 KurrentDB 執行 KurrentLiveContractTests, 它是 EventStore 契約中「KurrentDB 現行行為」的參考 server。升級 KurrentDB 時,請重新跑一次這組測試。