SDK value types and query building
The shared value layer gives the React Native SDK one way to describe resources, request choices, access rules, and query intent across all service APIs. It connects application values to Appwrite requests and turns JSON responses into predictable model-shaped data that account, database, storage, function, team, locale, integration, and realtime features can use.
Shared value layer
The value layer is the common language between application code and service APIs. Service classes use it to accept IDs, query strings, permissions, roles, enums, and record data, while the client carries those values to Appwrite and returns decoded response data.
The public SDK surface exposes the shared helpers together with the service classes. This keeps common concerns separate from domain work: a database service does not need to define its own ID or query format, and an application can use the same access helpers for documents, rows, files, or other resources. See queries, permissions, and roles for construction rules and models and enumerations for response shapes and fixed value sets.
Resource models
Resource models describe the business objects that service APIs return. They give application code a stable view of users, sessions, documents, rows, files, teams, memberships, executions, locale data, applications, OAuth grants, and other Appwrite resources without requiring each service to invent a separate response vocabulary.
Model hydration
Model hydration is the movement from a server JSON payload to a usable SDK response. The client decodes JSON, preserves large numeric values when possible, and returns the decoded object through the service's declared model type; the model type describes the shape for TypeScript but does not change the server object into a domain class.
This means a response can be handled as a normal object while still carrying shared resource fields such as $id, timestamps, parent resource IDs, and $permissions where the service provides them. The same response boundary also supports non-model results such as binary image data and empty action results.
References: src/client.ts• L1-44 src/client.ts• L689-785 src/models.ts• L237-312 src/…/account.ts• L19-34
Model families
The model families match the way applications use service results. A single-resource call returns one model, while a list call returns a named envelope that keeps the count beside the resource array.
| Model family | Shared role |
|---|---|
User, Session, Identity, and MFA models | Represent account state and authentication steps. |
Document and Row | Represent application records with system fields and application data. |
File and Execution | Represent stored files and function or site run results. |
Team and Membership | Represent group membership and team roles. |
| Locale models | Represent location details and selectable regional reference data. |
| Application, secret, scope, installation, consent, token, project, and organization models | Represent app registration, access grants, installed integrations, and OAuth state. |
| Transaction, subscriber, target, installation, and consent models | Represent transaction state, message targets, app connections, and consent state. |
| List models | Return total plus a domain-specific array such as documents, rows, files, or apps. |
Rows and documents support generic types so an application can add its own record fields while retaining the shared system fields. The default forms remain open for applications that do not provide a narrower record type.
Execution models use fixed enum values for the event that started a run. The current trigger set is HTTP, schedule, event, and email, which keeps execution results aligned with the service's accepted trigger vocabulary.
References: src/models.ts• L8-136 src/models.ts• L237-312 src/models.ts• L1168-1248 src/models.ts• L1644-1752 src/models.ts• L1986-2309 src/…/databases.ts• L327-412 src/…/tables-db.ts• L333-410
Request value builders
Request value builders turn common intent into the strings and objects expected by Appwrite. They reduce repeated wire-format code and keep related service APIs aligned when they create resources, filter lists, update fields, or grant access.
Resource identifiers
An identifier is the stable handle for a resource across its life cycle. ID.custom lets an application choose a known value, while ID.unique supplies a generated value for create operations; the chosen value is then reused by reads, updates, deletes, cursor queries, channels, and permissions.
The helper only chooses or returns a string. The target service remains responsible for accepting the final value under its own character and length rules.
References: src/id.ts• L1-27 src/…/account.ts• L36-62 src/…/databases.ts• L415-428 src/…/tables-db.ts• L411-420
Enumerated values
Enumerations constrain request values that have a fixed set of accepted meanings. The SDK exports values for authentication providers and factors, browser settings, image formats, function execution methods, execution triggers, execution states, country flags, and time zones; each member maps to the exact string that the Appwrite API expects.
The OAuth provider enum gives authentication calls one shared vocabulary across the supported consumer, enterprise, self-hosted, and platform providers. It includes Apple, Google, GitHub, Microsoft, OIDC, and other providers. The image format enum gives image operations the accepted format values, including automatic selection. The execution trigger enum gives execution models and service calls the same values for HTTP, scheduled, event, and email starts.
Enums make the TypeScript call site clear without changing the wire contract. The service still decides where a value is valid, while the enum helps prevent spelling and casing errors in supported request options.
The full value groups and their service use are described in models and enumerations.
References: src/index.ts• L23-36 src/…/execution-trigger.ts• L1-6 src/…/image-format.ts• L1-10 src/…/o-auth-provider.ts• L1-55 src/…/authentication-factor.ts• L1-6 src/…/execution-method.ts• L1-9 src/…/execution-status.ts• L1-7 src/…/account.ts• L8-10 src/…/functions.ts• L8-10
Query values
A query is a serialized description of one server-side list condition or list control. Query covers comparisons, text matching, null checks, date ranges, ordering, selection, paging, cursor movement, aggregation, grouping, joins, and composition; specialized helpers also describe array, relationship, spatial, and vector matching when the target resource supports those fields.
Service list methods accept query strings as part of their request inputs. The service supplies the resource context, while the query supplies the filter or control. Compound helpers preserve nested query objects so the server can evaluate the intended condition tree.
The SDK supports two ways to collect query values. Static Query helpers create one serialized query, while Query.Builder collects several fragments and returns the string[] expected by list methods. normalizeQueries also accepts strings, query objects, builders, and nested arrays, so service boundaries can turn these forms into one flat query list.
The query family is described in detail in queries, permissions, and roles.
References: src/query.ts• L4-37 src/query.ts• L40-137 src/query.ts• L285-325 src/query.ts• L630-751 src/query.ts• L795-1290 src/…/storage.ts• L18-40 src/…/realtime.ts• L7-10
Update operators
Update operators describe a change to an existing field rather than a condition for finding a resource. They support numeric changes, array edits, string changes, boolean toggles, and date changes. A service sends the resulting operator value as part of update data, so the server can apply the change to the stored value.
This separation matters because a query answers “which resources match?” while an update operator answers “how should this field change?” Mixing the two value families gives the server the wrong kind of instruction.
References: src/operator.ts• L1-55 src/operator.ts• L57-141 src/operator.ts• L181-307 src/…/databases.ts• L570-700
Permissions and roles
Access control is built from two values. A permission names the action that is allowed, and a role names the audience that receives the action. Permission creates actions such as read, create, update, or delete; Role identifies audiences such as any user, guests, one user, a team, one team member, or users with a label.
Resource creation and update APIs accept the resulting permission strings as an array. The helpers express policy intent, but Appwrite still enforces the policy and the resource service still controls where permissions are valid. See queries, permissions, and roles for the role and action matrix.
References: src/permission.ts• L1-22 src/role.ts• L1-100 src/…/databases.ts• L415-428 src/…/tables-db.ts• L411-420 src/…/storage.ts• L89-106
Service abstractions
Service abstractions give every domain API the same client-backed request path. Each service receives a configured Client, builds a domain endpoint and payload, and relies on the shared client to encode the request, decode the response, and report transport or Appwrite errors.
Service request boundary
The service layer keeps domain intent separate from transport work. Account, database, tables, storage, function, team, locale, avatar, messaging, presence, GraphQL, and realtime services expose domain operations, while the client handles common endpoint settings, project headers, authentication, JSON, multipart data, and response errors.
The shared Service base also prepares values at the request edge. It recursively flattens array data into bracketed request fields and turns a mobile file description with base64 content into bytes for upload. This gives service methods one common way to pass list values and file parts to the client.
References: src/service.ts• L1-49 src/client.ts• L164-186 src/client.ts• L689-785 src/…/account.ts• L12-34 src/…/graphql.ts• L9-65
Typed service results
Service method signatures connect an operation to the model it returns. A list operation names its list envelope, a record operation names its resource model, and generic record methods let application code provide a more precise data shape. The runtime response remains decoded JSON, but the declared result tells the engineer which fields and relationships the service promises.
This shared contract lets downstream code move between service areas without learning a new response pattern for each one. The same model vocabulary also supports deprecated service paths while newer services take over equivalent resources, such as rows replacing documents for table data.
References: src/…/databases.ts• L327-428 src/…/tables-db.ts• L333-434 src/…/teams.ts• L19-37 src/…/storage.ts• L18-40 src/index.ts• L1-22
Realtime value flow
Realtime uses the same value layer for event subscriptions. Channels identify a resource or resource action, queries narrow the events that reach a subscription, and decoded event payloads are delivered to the callback; the subscription can later replace its channels or queries without changing the application callback.
The flow connects application intent to server events.
flowchart LR
A[Application] --> B[Channel and Query values]
B --> C[Realtime subscription]
C --> D[Appwrite event stream]
D --> E[Decoded event payload]
E --> A
Channel builders also constrain valid resource paths and terminal actions at the type level. This gives realtime code a shared resource vocabulary instead of requiring each subscription to assemble channel text by hand.
References: src/channel.ts• L17-49 src/channel.ts• L52-160 src/…/realtime.ts• L7-29 src/…/realtime.ts• L450-628
Value flow across the SDK
The shared layer follows one broad path from application intent to a server result. The application chooses a service and supplies shared values; the service places them in a request; the client carries the request and decodes the result; the declared model or event type gives downstream code a known shape.
This diagram shows the relationship between the main value families.
flowchart LR
A[Application intent] --> B[ID, enum, Query, Operator, Permission, Role]
B --> C[Service operation]
C --> D[Client request boundary]
D --> E[Appwrite API]
E --> F[Decoded JSON or binary result]
F --> G[Models or event payload]
G --> A
The value builders do not replace service rules. Endpoint-specific fields, permissions, supported query attributes, authentication state, and server validation still determine whether a request succeeds.
Change checklist
When these files or sections are changed, remember to consider these:
- When a model or list envelope changes, check every service method that returns it and every generic record method that extends it.
- When application or OAuth models change, check the related service result types and the public model exports together.
- When an enum value changes, check both request parameters and response fields that use the same wire value.
- When JSON number handling changes, check IDs, query values, transaction data, model fields, and realtime payloads that can contain large integers.
- When a query or operator wire shape changes, check static helpers,
Query.Builder, query normalization, HTTP service payloads, and realtime subscription updates. - When query composition or join values change, check nested query parsing and every service that accepts multiple query input forms.
- When an ID format changes, check resource creation, path parameters, cursor queries, channel builders, and permission roles.
- When a permission action or role format changes, check all resource create and update inputs plus team membership role values.
- When the service request boundary changes, check array flattening, file-part byte conversion, GET fields, JSON and multipart bodies, decoded models, binary results, and error responses together.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A query uses an attribute that the target endpoint does not support. | The server rejects the request or returns results that do not match the intended filter. | Use the attribute contract of the selected list service. |
| A compound query is sent as a nested string instead of a query object. | The server cannot evaluate the intended and, or, relationship, or element-match tree. | Build compound values with the Query composition helpers and pass them through query normalization. |
| A builder or nested query input is not normalized at the service boundary. | A valid query object reaches the request as the wrong value shape. | Use normalizeQueries or a builder's build result for list inputs. |
| A custom or generated ID violates the target resource rules. | Creation fails and later operations have no stable resource handle. | Keep the ID within the service's allowed format and length. |
| A permission uses the wrong action or role. | The intended user loses access or an unintended audience gains access. | Compose the action with Permission and the audience with Role. |
| An update operator is used as a query filter. | The server receives a field change where it expects a match condition. | Use Query for reads and Operator for updates. |
| File content is not valid base64 when a mobile file part is created. | Byte conversion fails before the upload reaches Appwrite. | Give the file-part helper a valid base64 reader. |
| Application code assumes the declared model is a runtime class. | Class methods or runtime validation are missing even though TypeScript accepts the field shape. | Treat responses as decoded objects and use model types for compile-time guidance. |
| A list response is treated as a direct array. | The caller loses the named result field or reads total incorrectly. | Read the domain list envelope and its resource array. |
Key files
| File | Why to read it |
|---|---|
| src/index.ts | Shows the public shared helpers, model types, enums, and service classes. |
| src/client.ts | Defines the common request boundary, JSON value handling, response decoding, and error surface. |
| src/service.ts | Defines the base service relationship, shared array flattening, and mobile file-part conversion. |
| src/models.ts | Defines the resource vocabulary, list envelopes, generic record shapes, shared system fields, and application or OAuth models. |
| src/query.ts | Defines list filters, ordering, paging, composition, aggregation, joins, builders, normalization, and specialized query values. |
| src/operator.ts | Defines field update values for numeric, array, string, boolean, and date changes. |
| src/id.ts | Defines custom and generated resource identifiers. |
| src/permission.ts | Defines access actions. |
| src/role.ts | Defines access audiences. |
| src/channel.ts | Defines typed realtime resource paths and actions. |
| src/…/execution-trigger.ts | Defines the trigger vocabulary shared by execution requests and results. |
| src/…/image-format.ts | Defines the image format vocabulary used by image operations. |
| src/…/o-auth-provider.ts | Defines the current provider vocabulary used by OAuth sign-in requests. |
| src/…/databases.ts | Shows typed records, list queries, IDs, permissions, and service results in one resource area. |
| src/…/tables-db.ts | Shows the current row and transaction service using the shared model and query contracts. |
| src/…/realtime.ts | Shows how channels, queries, subscriptions, and decoded event payloads work together. |