Skip to content

Commit 13fe57b

Browse files
authored
Merge pull request #84 from appwrite/dev
2 parents 0e0c49a + e59d587 commit 13fe57b

File tree

14 files changed

+91
-65
lines changed

14 files changed

+91
-65
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change log
22

3+
## 0.21.0
4+
5+
* Add `queries` parameter to `client.subscribe()` for filtering Realtime events
6+
* Fix `Roles` enum removed from Teams service; `roles` parameter now accepts `string[]`
7+
* Fix parameter detection in overloaded methods to check for optional params (Account, Avatars, Graphql)
8+
39
## 0.20.0
410

511
* Add array-based enum parameters (e.g., `permissions: BrowserPermission[]`).

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

9-
**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).**
9+
**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).**
1010

1111
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)
1212

docs/examples/teams/create-membership.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```javascript
2-
import { Client, Teams, Roles } from "react-native-appwrite";
2+
import { Client, Teams } from "react-native-appwrite";
33

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

1010
const result = await teams.createMembership({
1111
teamId: '<TEAM_ID>',
12-
roles: [Roles.Admin],
12+
roles: [],
1313
email: 'email@example.com', // optional
1414
userId: '<USER_ID>', // optional
1515
phone: '+12065550100', // optional

docs/examples/teams/update-membership.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```javascript
2-
import { Client, Teams, Roles } from "react-native-appwrite";
2+
import { Client, Teams } from "react-native-appwrite";
33

44
const client = new Client()
55
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -10,7 +10,7 @@ const teams = new Teams(client);
1010
const result = await teams.updateMembership({
1111
teamId: '<TEAM_ID>',
1212
membershipId: '<MEMBERSHIP_ID>',
13-
roles: [Roles.Admin]
13+
roles: []
1414
});
1515

1616
console.log(result);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-native-appwrite",
33
"homepage": "https://appwrite.io/support",
44
"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",
5-
"version": "0.20.0",
5+
"version": "0.21.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/channel.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface Team { _team: any }
1313
interface Membership { _mem: any }
1414
interface Resolved { _res: any }
1515

16-
type Actionable = Document | Row | File | Execution | Team | Membership;
16+
type Actionable = Document | Row | File | Team | Membership;
1717

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

65-
// --- FUNCTION ROUTE ---
66-
execution(this: Channel<Func>, id: string = "*"): Channel<Execution> {
67-
return this.next<Execution>("executions", id);
68-
}
69-
7065
// --- TERMINAL ACTIONS ---
7166
// Restricted to the Actionable union
7267
create(this: Channel<Actionable>): Channel<Resolved> {
@@ -98,6 +93,10 @@ export class Channel<T> {
9893
return new Channel<Func>(["functions", normalize(id)]);
9994
}
10095

96+
static execution(id: string = "*") {
97+
return new Channel<Execution>(["executions", normalize(id)]);
98+
}
99+
101100
static team(id: string = "*") {
102101
return new Channel<Team>(["teams", normalize(id)]);
103102
}
@@ -106,9 +105,8 @@ export class Channel<T> {
106105
return new Channel<Membership>(["memberships", normalize(id)]);
107106
}
108107

109-
static account(userId: string = ""): string {
110-
const id = normalize(userId);
111-
return id === "*" ? "account" : `account.${id}`;
108+
static account(): string {
109+
return "account";
112110
}
113111

114112
// Global events

src/client.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Models } from './models';
22
import { Service } from './service';
33
import { Platform } from 'react-native';
4+
import { Query } from './query';
45
import JSONbigModule from 'json-bigint';
56
import BigNumber from 'bignumber.js';
67
const JSONbigParser = JSONbigModule({ storeAsString: false });
@@ -90,8 +91,10 @@ type Realtime = {
9091
url?: string;
9192
lastMessage?: RealtimeResponse;
9293
channels: Set<string>;
94+
queries: Set<string>;
9395
subscriptions: Map<number, {
9496
channels: string[];
97+
queries: string[];
9598
callback: (payload: RealtimeResponseEvent<any>) => void
9699
}>;
97100
subscriptionsCounter: number;
@@ -101,7 +104,7 @@ type Realtime = {
101104
connect: () => void;
102105
createSocket: () => void;
103106
createHeartbeat: () => void;
104-
cleanUp: (channels: string[]) => void;
107+
cleanUp: (channels: string[], queries: string[]) => void;
105108
onMessage: (event: MessageEvent) => void;
106109
}
107110

@@ -142,7 +145,7 @@ class Client {
142145
'x-sdk-name': 'React Native',
143146
'x-sdk-platform': 'client',
144147
'x-sdk-language': 'reactnative',
145-
'x-sdk-version': '0.20.0',
148+
'x-sdk-version': '0.21.0',
146149
'X-Appwrite-Response-Format': '1.8.0',
147150
};
148151

@@ -284,6 +287,7 @@ class Client {
284287
heartbeat: undefined,
285288
url: '',
286289
channels: new Set(),
290+
queries: new Set(),
287291
subscriptions: new Map(),
288292
subscriptionsCounter: 0,
289293
reconnect: true,
@@ -330,6 +334,9 @@ class Client {
330334
this.realtime.channels.forEach(channel => {
331335
channels.append('channels[]', channel);
332336
});
337+
this.realtime.queries.forEach(query => {
338+
channels.append('queries[]', query);
339+
});
333340

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

@@ -408,7 +415,7 @@ class Client {
408415
console.error(e);
409416
}
410417
},
411-
cleanUp: channels => {
418+
cleanUp: (channels, queries) => {
412419
this.realtime.channels.forEach(channel => {
413420
if (channels.includes(channel)) {
414421
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription] )=> {
@@ -420,6 +427,18 @@ class Client {
420427
}
421428
}
422429
})
430+
431+
this.realtime.queries.forEach(query => {
432+
if (queries.includes(query)) {
433+
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription]) => {
434+
return subscription.queries?.includes(query);
435+
})
436+
437+
if (!found) {
438+
this.realtime.queries.delete(query);
439+
}
440+
}
441+
})
423442
}
424443
}
425444

@@ -448,21 +467,29 @@ class Client {
448467
* @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
449468
* @returns {() => void} Unsubscribes from events.
450469
*/
451-
subscribe<T extends unknown>(channels: string | string[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
470+
subscribe<T extends unknown>(
471+
channels: string | string[],
472+
callback: (payload: RealtimeResponseEvent<T>) => void,
473+
queries: (string | Query)[] = []
474+
): () => void {
452475
let channelArray = typeof channels === 'string' ? [channels] : channels;
453476
channelArray.forEach(channel => this.realtime.channels.add(channel));
454477

478+
const queryStrings = (queries ?? []).map(q => typeof q === 'string' ? q : q.toString());
479+
queryStrings.forEach(query => this.realtime.queries.add(query));
480+
455481
const counter = this.realtime.subscriptionsCounter++;
456482
this.realtime.subscriptions.set(counter, {
457483
channels: channelArray,
484+
queries: queryStrings,
458485
callback
459486
});
460487

461488
this.realtime.connect();
462489

463490
return () => {
464491
this.realtime.subscriptions.delete(counter);
465-
this.realtime.cleanUp(channelArray);
492+
this.realtime.cleanUp(channelArray, queryStrings);
466493
this.realtime.connect();
467494
}
468495
}

src/enums/o-auth-provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ export enum OAuthProvider {
3838
Yandex = 'yandex',
3939
Zoho = 'zoho',
4040
Zoom = 'zoom',
41+
GithubImagine = 'githubImagine',
42+
GoogleImagine = 'googleImagine',
4143
}

src/enums/roles.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ export { BrowserPermission } from './enums/browser-permission';
2929
export { ImageFormat } from './enums/image-format';
3030
export { ExecutionMethod } from './enums/execution-method';
3131
export { ImageGravity } from './enums/image-gravity';
32-
export { Roles } from './enums/roles';
3332
export { ExecutionTrigger } from './enums/execution-trigger';
3433
export { ExecutionStatus } from './enums/execution-status';

0 commit comments

Comments
 (0)