本页为英文技术参考;字段、编号与支持状态直接来自同一契约源。中文学习路线见 开发文档。
State
Expose a current, revisioned value and observe changes. State is useful for a view of current data; event history and private durable storage serve different purposes.
Contract: nexa.state/100. API index.
Typical sequence
Define the owned state and schema, then read a snapshot before a conditional update. Pass the exact returned revision to CompareExchangeOwned and reconcile conflicts.
Behavior and limits
A watch can report a gap; recover with a fresh Read. Uninitialized state is explicit and must not be confused with a failed read or with a valid empty value.
The recorded Host maps 6 of 6 operations in this group. A mapping is subject to permission, phase, scope, platform and business preconditions. Host snapshot identifies the source revision; negotiate against the actual installed Host.
Operations
Describe · Read · Watch · DefineOwned · UpdateOwned · CompareExchangeOwned
Describe
QualifiedRequest → StateDescriptor
| Property | Contract |
|---|---|
| Local SDK method ID | 1 |
| Kind | Query |
| Permission | nexa.state.read |
| Legal phases | Initialize, PostInitialize, Checkup, Finalize, Active |
| Idempotency | ReadOnly |
| Host status | Mapped in recorded snapshot |
Request fields
| Field | Type | Meaning |
|---|---|---|
Id | QualifiedId | Identity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path. |
Successful result
Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.
Failure and retry
Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.
C binding (call fragment; the caller supplies the encoded request and buffers):
nx_State_Describe(&reply, request, &options);The next resume receives the reply. Check nx_reply_success before nx_State_Describe_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.
Read
StateReadRequest → StateSnapshot
| Property | Contract |
|---|---|
| Local SDK method ID | 2 |
| Kind | Query |
| Permission | nexa.state.read |
| Legal phases | Initialize, PostInitialize, Checkup, Finalize, Active |
| Idempotency | ReadOnly |
| Host status | Mapped in recorded snapshot |
Request fields
| Field | Type | Meaning |
|---|---|---|
Id | QualifiedId | Identity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path. |
Scope | ScopedTarget | Explicit target scope. The Host checks that the caller is authorized for it. |
Successful result
Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.
Failure and retry
Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.
C binding (call fragment; the caller supplies the encoded request and buffers):
nx_State_Read(&reply, request, &options);The next resume receives the reply. Check nx_reply_success before nx_State_Read_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.
Watch
StateReadRequest → SubscriptionRef
| Property | Contract |
|---|---|
| Local SDK method ID | 3 |
| Kind | Subscription |
| Permission | nexa.state.read |
| Legal phases | Initialize, PostInitialize, Checkup, Finalize, Active |
| Idempotency | ReadOnly |
| Host status | Mapped in recorded snapshot |
Request fields
| Field | Type | Meaning |
|---|---|---|
Id | QualifiedId | Identity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path. |
Scope | ScopedTarget | Explicit target scope. The Host checks that the caller is authorized for it. |
Successful result
Retain the subscription identity, consume bounded batches or callbacks as specified, handle gaps, and release it when no longer needed.
Failure and retry
Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.
C binding (call fragment; the caller supplies the encoded request and buffers):
nx_State_Watch(&reply, request, &options);The next resume receives the reply. Check nx_reply_success before nx_State_Watch_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.
DefineOwned
StateDescriptor → RegistrationRef
| Property | Contract |
|---|---|
| Local SDK method ID | 4 |
| Kind | Registration |
| Permission | nexa.state.write |
| Legal phases | Initialize |
| Idempotency | RequiredKey |
| Host status | Mapped in recorded snapshot |
Request fields
| Field | Type | Meaning |
|---|---|---|
Id | QualifiedId | Identity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path. |
Schema | SchemaRef | Exact schema identity, version and fingerprint used to validate Value. |
Scope | ScopedTarget | Explicit target scope. The Host checks that the caller is authorized for it. |
Successful result
Retain the registration identity for the permitted update/release operation. Staged registrations become visible only at group activation.
Failure and retry
Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Preserve structured errors; see recovery guidance.
C binding (call fragment; the caller supplies the encoded request and buffers):
nx_State_DefineOwned(&reply, request, &options);The next resume receives the reply. Check nx_reply_success before nx_State_DefineOwned_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.
UpdateOwned
| Property | Contract |
|---|---|
| Local SDK method ID | 5 |
| Kind | Mutation |
| Permission | nexa.state.write |
| Legal phases | Active |
| Idempotency | RequiredKey |
| Host status | Mapped in recorded snapshot |
Request fields
| Field | Type | Meaning |
|---|---|---|
Id | QualifiedId | Identity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path. |
Scope | ScopedTarget | Explicit target scope. The Host checks that the caller is authorized for it. |
Value | AbiValue | Payload interpreted using the accompanying or declared schema; Null is not a substitute for an error. |
ExpectedRevision | Revision | Revision observed before this change. Preserve it exactly; a mismatch requires re-reading and reconciling the target. |
Successful result
Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.
Failure and retry
Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.
C binding (call fragment; the caller supplies the encoded request and buffers):
nx_State_UpdateOwned(&reply, request, &options);The next resume receives the reply. Check nx_reply_success before nx_State_UpdateOwned_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.
CompareExchangeOwned
| Property | Contract |
|---|---|
| Local SDK method ID | 6 |
| Kind | Mutation |
| Permission | nexa.state.write |
| Legal phases | Active |
| Idempotency | RequiredKey |
| Host status | Mapped in recorded snapshot |
Use the revision from the latest authoritative snapshot. On conflict, re-read and reconcile; do not increment or synthesize a revision token.
Request fields
| Field | Type | Meaning |
|---|---|---|
Id | QualifiedId | Identity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path. |
Scope | ScopedTarget | Explicit target scope. The Host checks that the caller is authorized for it. |
Value | AbiValue | Payload interpreted using the accompanying or declared schema; Null is not a substitute for an error. |
ExpectedRevision | Revision | Revision observed before this change. Preserve it exactly; a mismatch requires re-reading and reconciling the target. |
Successful result
Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.
Failure and retry
Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.
C binding (call fragment; the caller supplies the encoded request and buffers):
nx_State_CompareExchangeOwned(&reply, request, &options);The next resume receives the reply. Check nx_reply_success before nx_State_CompareExchangeOwned_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.
来源: NexaCL-Plugin-SDK · Apache-2.0.