feat(sdk): show and lock immutable document properties in the mobile example apps - #4820
Conversation
…example app Parity for the protocol v14 `immutable` / `immutableAllowSetting` document-type keywords (#4815), the same treatment `indexOnly` got: - ContractJson: `documentTypeImmutability` reads both lists off the raw schema (an allowance outside `immutable` is dropped, DPP refuses such contracts), and `immutablePropertyLock` resolves a property to EDITABLE / FROZEN / SETTABLE_ONCE against the stored document. - DocumentTypeDetailsScreen lists the frozen and settable-once properties under Document Settings. - DocumentActionsScreen's replace form disables frozen fields and captions settable-once ones, so a user is not charged for a replace consensus is guaranteed to reject (code 40128). - Unit tests for the helpers. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 10 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR HygieneState: waiting-bots · commit
Self-review is an author attestation that you have read the diff: This report does not bypass CI or repository protection rules. |
…xample app Swift half of the protocol v14 `immutable` / `immutableAllowSetting` parity (#4815), mirroring the Kotlin commit: - New `DocumentTypeImmutability` value type (deduped, sorted lists + `lockState(for:hasStoredValue:)` -> editable / frozen / settableOnce), exposed on `PersistentDocumentType` as computed accessors read off the persisted `schemaJSON`. No new stored column: one would move the entity hash and cost a DashSchema version plus a fixture store, which a display-only keyword does not justify. - DocumentTypeDetailsView and StorageRecordDetailViews list the frozen and settable-once properties. - DocumentFieldsView badges each property and disables frozen fields on the replace flow (TransitionDetailView passes the type's immutability only for documentReplace); ReplaceDocumentView shows which frozen properties the stored document already has a value for. - 9 unit tests; migration tests unchanged and passing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
|
Issue being fixed or feature implemented
Follow-up to #4815 (
immutable/immutableAllowSettingdocument-type keywords) and #4817 (their JavaScript surface). Nothing is required for correctness on mobile, consensus enforces the keywords, but without this the example apps let a user edit a frozen property and pay for a guaranteed rejection (code 40128). This gives Swift and Kotlin the same parity treatment theindexOnlykeyword got in #4509.What was done?
Kotlin (KotlinExampleApp only; the SDK keeps no document-type model)
ContractJson.kt:documentTypeImmutability(schema)reads both keywords off the raw schema (animmutableAllowSettingentry outsideimmutableis dropped, DPP refuses such contracts at registration), andimmutablePropertyLock(property, immutability, hasStoredValue)resolves a property toEDITABLE,FROZENorSETTABLE_ONCE(settable-once only while the stored document has no value).DocumentTypeDetailsScreen.kt: "Immutable Properties" and "Settable Once While Absent" rows under Document Settings.DocumentActionsScreen.kt: the replace form disables frozen fields and captions them, and captions settable-once fields; presence is read from the probed document's fields. Submission semantics are unchanged.DocumentTypeImmutabilityTest.kt: parsing, dropped allowance outsideimmutable, non-string entries ignored, and the three lock states.Swift (SwiftDashSDK + SwiftExampleApp)
DocumentTypeImmutabilityvalue type: deduped, sortedimmutableProperties/immutableAllowSettingpluslockState(for:hasStoredValue:)returning.editable,.frozenor.settableOnce, with the same semantics as the Kotlin helper.PersistentDocumentTypeexposesimmutability,immutablePropertiesandimmutableAllowSettingas computed accessors read off the persistedschemaJSON. Deliberately no new stored column:schemaJSONalready persists the whole type dictionary, and a new column moves the entity hash, which since feat(sdk)!: key limits on every client: wasm-dpp2, platform-wallet, FFI, Kotlin and Swift #4811 (DashSchemaV5) costs a schema version, frozen model copies and a fixture store.indexOnlypredates that discipline. The frozen V1/V4 schemas are untouched and the migration tests still pass.DocumentTypeDetailsViewand the document-type record inStorageRecordDetailViewslist the frozen and settable-once properties.DocumentFieldsViewbadges each property ("Immutable" / "Immutable once set") and disables frozen fields;TransitionDetailViewpasses the type's immutability only fordocumentReplace. That generic builder never loads the stored document, so settable-once fields stay editable there with the caption.ReplaceDocumentViewon the Documents tab does have the stored document and shows which frozen properties already hold a value.How Has This Been Tested?
DocumentTypeImmutabilityTestadded (parsing, dropped allowance outsideimmutable, non-string entries ignored, the three lock states). No JDK on this machine, so the Kotlin build and tests rely on CI.swift test --filter DocumentTypeImmutabilityTests(9 tests) andswift test --filter "DashModelMigrationTests|DocumentTypeImmutabilityTests|DataContractParserPreProgrammedTests"(28 tests, 1 skipped) pass;xcodebuildof SwiftExampleApp for the iPhone 17 simulator builds clean. No simulator UAT was run. Whether the FFI forwards the two keywords in the contract JSON handed toDataContractParseris not verified against a devnet here; it rests on the same pathindexOnly,countableandterminalalready use.Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code