Skip to content

Commit 7f42a2d

Browse files
authored
Merge pull request #92 from appwrite/dev
feat: React Native SDK update for version 1.0.0
2 parents d287ed8 + 767fae9 commit 7f42a2d

File tree

10 files changed

+70
-41
lines changed

10 files changed

+70
-41
lines changed

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/databases/list-documents.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const result = await databases.listDocuments({
1212
collectionId: '<COLLECTION_ID>',
1313
queries: [], // optional
1414
transactionId: '<TRANSACTION_ID>', // optional
15-
total: false // optional
15+
total: false, // optional
16+
ttl: 0 // optional
1617
});
1718

1819
console.log(result);

docs/examples/tablesdb/list-rows.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const result = await tablesDB.listRows({
1212
tableId: '<TABLE_ID>',
1313
queries: [], // optional
1414
transactionId: '<TRANSACTION_ID>', // optional
15-
total: false // optional
15+
total: false, // optional
16+
ttl: 0 // optional
1617
});
1718

1819
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.24.1",
5+
"version": "1.0.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/channel.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,28 @@ interface Resolved { _res: any }
1616
type Actionable = Document | Row | File | Team | Membership;
1717

1818
function normalize(id: string): string {
19-
const trimmed = id.trim();
20-
return trimmed === "" ? "*" : trimmed;
19+
if (id === undefined || id === null) {
20+
throw new Error("Channel ID is required");
21+
}
22+
const trimmed = String(id).trim();
23+
if (trimmed === "") {
24+
throw new Error("Channel ID is required");
25+
}
26+
return trimmed;
2127
}
2228

2329
export class Channel<T> {
2430
declare _type: T;
2531

2632
private constructor(private readonly segments: string[]) {}
2733

28-
private next<N>(segment: string, id: string = "*"): Channel<N> {
29-
return new Channel<N>([...this.segments, segment, normalize(id)]) as any;
34+
private next<N>(segment: string, id?: string): Channel<N> {
35+
const segments =
36+
id === undefined
37+
? [...this.segments, segment]
38+
: [...this.segments, segment, normalize(id)];
39+
40+
return new Channel<N>(segments) as any;
3041
}
3142

3243
private resolve(action: string): Channel<Resolved> {
@@ -39,26 +50,26 @@ export class Channel<T> {
3950

4051
// --- DATABASE ROUTE ---
4152
// Only available on Channel<Database>
42-
collection(this: Channel<Database>, id: string = "*"): Channel<Collection> {
53+
collection(this: Channel<Database>, id: string): Channel<Collection> {
4354
return this.next<Collection>("collections", id);
4455
}
4556

4657
// Only available on Channel<Collection>
47-
document(this: Channel<Collection>, id: string = "*"): Channel<Document> {
58+
document(this: Channel<Collection>, id?: string): Channel<Document> {
4859
return this.next<Document>("documents", id);
4960
}
5061

5162
// --- TABLESDB ROUTE ---
52-
table(this: Channel<TablesDB>, id: string = "*"): Channel<Table> {
63+
table(this: Channel<TablesDB>, id: string): Channel<Table> {
5364
return this.next<Table>("tables", id);
5465
}
5566

56-
row(this: Channel<Table>, id: string = "*"): Channel<Row> {
67+
row(this: Channel<Table>, id?: string): Channel<Row> {
5768
return this.next<Row>("rows", id);
5869
}
5970

6071
// --- BUCKET ROUTE ---
61-
file(this: Channel<Bucket>, id: string = "*"): Channel<File> {
72+
file(this: Channel<Bucket>, id?: string): Channel<File> {
6273
return this.next<File>("files", id);
6374
}
6475

@@ -81,31 +92,31 @@ export class Channel<T> {
8192
}
8293

8394
// --- ROOT FACTORIES ---
84-
static database(id: string = "*") {
95+
static database(id: string) {
8596
return new Channel<Database>(["databases", normalize(id)]);
8697
}
8798

88-
static tablesdb(id: string = "*") {
99+
static tablesdb(id: string) {
89100
return new Channel<TablesDB>(["tablesdb", normalize(id)]);
90101
}
91102

92-
static bucket(id: string = "*") {
103+
static bucket(id: string) {
93104
return new Channel<Bucket>(["buckets", normalize(id)]);
94105
}
95106

96-
static function(id: string = "*") {
107+
static function(id: string) {
97108
return new Channel<Func>(["functions", normalize(id)]);
98109
}
99110

100-
static execution(id: string = "*") {
111+
static execution(id: string) {
101112
return new Channel<Execution>(["executions", normalize(id)]);
102113
}
103114

104-
static team(id: string = "*") {
115+
static team(id: string) {
105116
return new Channel<Team>(["teams", normalize(id)]);
106117
}
107118

108-
static membership(id: string = "*") {
119+
static membership(id: string) {
109120
return new Channel<Membership>(["memberships", normalize(id)]);
110121
}
111122

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Client {
158158
'x-sdk-name': 'React Native',
159159
'x-sdk-platform': 'client',
160160
'x-sdk-language': 'reactnative',
161-
'x-sdk-version': '0.24.1',
161+
'x-sdk-version': '1.0.0',
162162
'X-Appwrite-Response-Format': '1.8.0',
163163
};
164164

src/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export namespace Models {
238238
*/
239239
$id: string;
240240
/**
241-
* Row automatically incrementing ID.
241+
* Row sequence ID.
242242
*/
243243
$sequence: number;
244244
/**
@@ -277,7 +277,7 @@ export namespace Models {
277277
*/
278278
$id: string;
279279
/**
280-
* Document automatically incrementing ID.
280+
* Document sequence ID.
281281
*/
282282
$sequence: number;
283283
/**

src/services/databases.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,12 @@ export class Databases extends Service {
315315
* @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long.
316316
* @param {string} params.transactionId - Transaction ID to read uncommitted changes within the transaction.
317317
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
318+
* @param {number} params.ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
318319
* @throws {AppwriteException}
319320
* @returns {Promise}
320321
* @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.
321322
*/
322-
listDocuments<Document extends Models.Document = Models.DefaultDocument>(params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean }): Promise<Models.DocumentList<Document>>;
323+
listDocuments<Document extends Models.Document = Models.DefaultDocument>(params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number }): Promise<Models.DocumentList<Document>>;
323324
/**
324325
* Get a list of all the user's documents in a given collection. You can use the query params to filter your results.
325326
*
@@ -328,26 +329,28 @@ export class Databases extends Service {
328329
* @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long.
329330
* @param {string} transactionId - Transaction ID to read uncommitted changes within the transaction.
330331
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
332+
* @param {number} ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
331333
* @throws {AppwriteException}
332334
* @returns {Promise<Models.DocumentList<Document>>}
333335
* @deprecated Use the object parameter style method for a better developer experience.
334336
*/
335-
listDocuments<Document extends Models.Document = Models.DefaultDocument>(databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean): Promise<Models.DocumentList<Document>>;
337+
listDocuments<Document extends Models.Document = Models.DefaultDocument>(databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number): Promise<Models.DocumentList<Document>>;
336338
listDocuments<Document extends Models.Document = Models.DefaultDocument>(
337-
paramsOrFirst: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean } | string,
338-
...rest: [(string)?, (string[])?, (string)?, (boolean)?]
339+
paramsOrFirst: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number } | string,
340+
...rest: [(string)?, (string[])?, (string)?, (boolean)?, (number)?]
339341
): Promise<Models.DocumentList<Document>> {
340-
let params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean };
342+
let params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
341343

342344
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
343-
params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean };
345+
params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
344346
} else {
345347
params = {
346348
databaseId: paramsOrFirst as string,
347349
collectionId: rest[0] as string,
348350
queries: rest[1] as string[],
349351
transactionId: rest[2] as string,
350-
total: rest[3] as boolean
352+
total: rest[3] as boolean,
353+
ttl: rest[4] as number
351354
};
352355
}
353356

@@ -356,6 +359,7 @@ export class Databases extends Service {
356359
const queries = params.queries;
357360
const transactionId = params.transactionId;
358361
const total = params.total;
362+
const ttl = params.ttl;
359363

360364
if (typeof databaseId === 'undefined') {
361365
throw new AppwriteException('Missing required parameter: "databaseId"');
@@ -380,6 +384,10 @@ export class Databases extends Service {
380384
payload['total'] = total;
381385
}
382386

387+
if (typeof ttl !== 'undefined') {
388+
payload['ttl'] = ttl;
389+
}
390+
383391
const uri = new URL(this.client.config.endpoint + apiPath);
384392
return this.client.call('get', uri, {
385393
}, payload);

src/services/tables-db.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,11 @@ export class TablesDB extends Service {
315315
* @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long.
316316
* @param {string} params.transactionId - Transaction ID to read uncommitted changes within the transaction.
317317
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
318+
* @param {number} params.ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
318319
* @throws {AppwriteException}
319320
* @returns {Promise}
320321
*/
321-
listRows<Row extends Models.Row = Models.DefaultRow>(params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean }): Promise<Models.RowList<Row>>;
322+
listRows<Row extends Models.Row = Models.DefaultRow>(params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number }): Promise<Models.RowList<Row>>;
322323
/**
323324
* Get a list of all the user's rows in a given table. You can use the query params to filter your results.
324325
*
@@ -327,26 +328,28 @@ export class TablesDB extends Service {
327328
* @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long.
328329
* @param {string} transactionId - Transaction ID to read uncommitted changes within the transaction.
329330
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
331+
* @param {number} ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
330332
* @throws {AppwriteException}
331333
* @returns {Promise<Models.RowList<Row>>}
332334
* @deprecated Use the object parameter style method for a better developer experience.
333335
*/
334-
listRows<Row extends Models.Row = Models.DefaultRow>(databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean): Promise<Models.RowList<Row>>;
336+
listRows<Row extends Models.Row = Models.DefaultRow>(databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number): Promise<Models.RowList<Row>>;
335337
listRows<Row extends Models.Row = Models.DefaultRow>(
336-
paramsOrFirst: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean } | string,
337-
...rest: [(string)?, (string[])?, (string)?, (boolean)?]
338+
paramsOrFirst: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number } | string,
339+
...rest: [(string)?, (string[])?, (string)?, (boolean)?, (number)?]
338340
): Promise<Models.RowList<Row>> {
339-
let params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean };
341+
let params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
340342

341343
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
342-
params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean };
344+
params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
343345
} else {
344346
params = {
345347
databaseId: paramsOrFirst as string,
346348
tableId: rest[0] as string,
347349
queries: rest[1] as string[],
348350
transactionId: rest[2] as string,
349-
total: rest[3] as boolean
351+
total: rest[3] as boolean,
352+
ttl: rest[4] as number
350353
};
351354
}
352355

@@ -355,6 +358,7 @@ export class TablesDB extends Service {
355358
const queries = params.queries;
356359
const transactionId = params.transactionId;
357360
const total = params.total;
361+
const ttl = params.ttl;
358362

359363
if (typeof databaseId === 'undefined') {
360364
throw new AppwriteException('Missing required parameter: "databaseId"');
@@ -379,6 +383,10 @@ export class TablesDB extends Service {
379383
payload['total'] = total;
380384
}
381385

386+
if (typeof ttl !== 'undefined') {
387+
payload['ttl'] = ttl;
388+
}
389+
382390
const uri = new URL(this.client.config.endpoint + apiPath);
383391
return this.client.call('get', uri, {
384392
}, payload);

src/services/teams.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export class Teams extends Service {
371371
*
372372
*
373373
* @param {string} params.teamId - Team ID.
374-
* @param {string[]} params.roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.
374+
* @param {string[]} params.roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long.
375375
* @param {string} params.email - Email of the new team member.
376376
* @param {string} params.userId - ID of the user to be added to a team.
377377
* @param {string} params.phone - Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.
@@ -392,7 +392,7 @@ export class Teams extends Service {
392392
*
393393
*
394394
* @param {string} teamId - Team ID.
395-
* @param {string[]} roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.
395+
* @param {string[]} roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long.
396396
* @param {string} email - Email of the new team member.
397397
* @param {string} userId - ID of the user to be added to a team.
398398
* @param {string} phone - Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.
@@ -531,7 +531,7 @@ export class Teams extends Service {
531531
*
532532
* @param {string} params.teamId - Team ID.
533533
* @param {string} params.membershipId - Membership ID.
534-
* @param {string[]} params.roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.
534+
* @param {string[]} params.roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long.
535535
* @throws {AppwriteException}
536536
* @returns {Promise}
537537
*/
@@ -542,7 +542,7 @@ export class Teams extends Service {
542542
*
543543
* @param {string} teamId - Team ID.
544544
* @param {string} membershipId - Membership ID.
545-
* @param {string[]} roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.
545+
* @param {string[]} roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long.
546546
* @throws {AppwriteException}
547547
* @returns {Promise<Models.Membership>}
548548
* @deprecated Use the object parameter style method for a better developer experience.

0 commit comments

Comments
 (0)