Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 0.21.0

* Add `queries` parameter to `client.subscribe()` for filtering Realtime events
* Fix `Roles` enum removed from Teams service; `roles` parameter now accepts `string[]`
* Fix parameter detection in overloaded methods to check for optional params (Account, Avatars, Graphql)

## 0.20.0

* Add array-based enum parameters (e.g., `permissions: BrowserPermission[]`).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).**
**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).**

Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/teams/create-membership.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Teams, Roles } from "react-native-appwrite";
import { Client, Teams } from "react-native-appwrite";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -9,7 +9,7 @@ const teams = new Teams(client);

const result = await teams.createMembership({
teamId: '<TEAM_ID>',
roles: [Roles.Admin],
roles: [],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Example with empty roles array doesn't demonstrate the new string-based usage.

Since the Roles enum was removed in favor of free-form strings, the example should show a realistic role value (e.g., ['owner']) rather than an empty array. An empty array may confuse users into thinking roles are no longer needed or supported.

-    roles: [],
+    roles: ['owner'],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
roles: [],
roles: ['owner'],
🤖 Prompt for AI Agents
In `@docs/examples/teams/create-membership.md` at line 12, The example uses an
empty roles array which doesn't show the new string-based usage; update the
example's payload (the object with the roles property) to include a realistic
string role like "owner" (e.g., set roles to ['owner'] or another meaningful
role) to demonstrate free-form string roles instead of leaving roles: [] in the
create-membership example.

email: 'email@example.com', // optional
userId: '<USER_ID>', // optional
phone: '+12065550100', // optional
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/teams/update-membership.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Teams, Roles } from "react-native-appwrite";
import { Client, Teams } from "react-native-appwrite";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -10,7 +10,7 @@ const teams = new Teams(client);
const result = await teams.updateMembership({
teamId: '<TEAM_ID>',
membershipId: '<MEMBERSHIP_ID>',
roles: [Roles.Admin]
roles: []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Same concern: empty roles array doesn't illustrate string-based roles.

Same as in create-membership.md — showing a concrete role string would make the example more useful.

-    roles: []
+    roles: ['owner']
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
roles: []
roles: ['owner']
🤖 Prompt for AI Agents
In `@docs/examples/teams/update-membership.md` at line 13, The example uses an
empty roles array which doesn't demonstrate string-based roles; update the
example in update-membership.md by replacing roles: [] with a concrete role
string like roles: ["member"] (or ["admin"] as appropriate) so readers see the
expected string-based role format; ensure the same pattern is applied
consistently where the roles property is shown (e.g., create-membership
examples).

});

console.log(result);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-native-appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
"version": "0.20.0",
"version": "0.21.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
16 changes: 7 additions & 9 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Team { _team: any }
interface Membership { _mem: any }
interface Resolved { _res: any }

type Actionable = Document | Row | File | Execution | Team | Membership;
type Actionable = Document | Row | File | Team | Membership;

function normalize(id: string): string {
const trimmed = id.trim();
Expand Down Expand Up @@ -62,11 +62,6 @@ export class Channel<T> {
return this.next<File>("files", id);
}

// --- FUNCTION ROUTE ---
execution(this: Channel<Func>, id: string = "*"): Channel<Execution> {
return this.next<Execution>("executions", id);
}

// --- TERMINAL ACTIONS ---
// Restricted to the Actionable union
create(this: Channel<Actionable>): Channel<Resolved> {
Expand Down Expand Up @@ -98,6 +93,10 @@ export class Channel<T> {
return new Channel<Func>(["functions", normalize(id)]);
}

static execution(id: string = "*") {
return new Channel<Execution>(["executions", normalize(id)]);
}

static team(id: string = "*") {
return new Channel<Team>(["teams", normalize(id)]);
}
Expand All @@ -106,9 +105,8 @@ export class Channel<T> {
return new Channel<Membership>(["memberships", normalize(id)]);
}

static account(userId: string = ""): string {
const id = normalize(userId);
return id === "*" ? "account" : `account.${id}`;
static account(): string {
return "account";
}

// Global events
Expand Down
37 changes: 32 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Models } from './models';
import { Service } from './service';
import { Platform } from 'react-native';
import { Query } from './query';
import JSONbigModule from 'json-bigint';
import BigNumber from 'bignumber.js';
const JSONbigParser = JSONbigModule({ storeAsString: false });
Expand Down Expand Up @@ -90,8 +91,10 @@ type Realtime = {
url?: string;
lastMessage?: RealtimeResponse;
channels: Set<string>;
queries: Set<string>;
subscriptions: Map<number, {
channels: string[];
queries: string[];
callback: (payload: RealtimeResponseEvent<any>) => void
}>;
subscriptionsCounter: number;
Expand All @@ -101,7 +104,7 @@ type Realtime = {
connect: () => void;
createSocket: () => void;
createHeartbeat: () => void;
cleanUp: (channels: string[]) => void;
cleanUp: (channels: string[], queries: string[]) => void;
onMessage: (event: MessageEvent) => void;
}

Expand Down Expand Up @@ -142,7 +145,7 @@ class Client {
'x-sdk-name': 'React Native',
'x-sdk-platform': 'client',
'x-sdk-language': 'reactnative',
'x-sdk-version': '0.20.0',
'x-sdk-version': '0.21.0',
'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down Expand Up @@ -284,6 +287,7 @@ class Client {
heartbeat: undefined,
url: '',
channels: new Set(),
queries: new Set(),
subscriptions: new Map(),
subscriptionsCounter: 0,
reconnect: true,
Expand Down Expand Up @@ -330,6 +334,9 @@ class Client {
this.realtime.channels.forEach(channel => {
channels.append('channels[]', channel);
});
this.realtime.queries.forEach(query => {
channels.append('queries[]', query);
});

const url = this.config.endpointRealtime + '/realtime?' + channels.toString();

Expand Down Expand Up @@ -408,7 +415,7 @@ class Client {
console.error(e);
}
},
cleanUp: channels => {
cleanUp: (channels, queries) => {
this.realtime.channels.forEach(channel => {
if (channels.includes(channel)) {
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription] )=> {
Expand All @@ -420,6 +427,18 @@ class Client {
}
}
})

this.realtime.queries.forEach(query => {
if (queries.includes(query)) {
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription]) => {
return subscription.queries?.includes(query);
})

if (!found) {
this.realtime.queries.delete(query);
}
}
})
}
}

Expand Down Expand Up @@ -448,21 +467,29 @@ class Client {
* @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
* @returns {() => void} Unsubscribes from events.
*/
subscribe<T extends unknown>(channels: string | string[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
subscribe<T extends unknown>(
channels: string | string[],
callback: (payload: RealtimeResponseEvent<T>) => void,
queries: (string | Query)[] = []
): () => void {
let channelArray = typeof channels === 'string' ? [channels] : channels;
channelArray.forEach(channel => this.realtime.channels.add(channel));

const queryStrings = (queries ?? []).map(q => typeof q === 'string' ? q : q.toString());
queryStrings.forEach(query => this.realtime.queries.add(query));

const counter = this.realtime.subscriptionsCounter++;
this.realtime.subscriptions.set(counter, {
channels: channelArray,
queries: queryStrings,
callback
});

this.realtime.connect();

return () => {
this.realtime.subscriptions.delete(counter);
this.realtime.cleanUp(channelArray);
this.realtime.cleanUp(channelArray, queryStrings);
this.realtime.connect();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/enums/o-auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ export enum OAuthProvider {
Yandex = 'yandex',
Zoho = 'zoho',
Zoom = 'zoom',
GithubImagine = 'githubImagine',
GoogleImagine = 'googleImagine',
}
5 changes: 0 additions & 5 deletions src/enums/roles.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ export { BrowserPermission } from './enums/browser-permission';
export { ImageFormat } from './enums/image-format';
export { ExecutionMethod } from './enums/execution-method';
export { ImageGravity } from './enums/image-gravity';
export { Roles } from './enums/roles';
export { ExecutionTrigger } from './enums/execution-trigger';
export { ExecutionStatus } from './enums/execution-status';
Loading