Skip to content

Commit cf65e76

Browse files
authored
Merge pull request #159 from appwrite/dev
feat: Web SDK update for version 23.0.0
2 parents f4051c5 + ae5696e commit cf65e76

11 files changed

Lines changed: 68 additions & 41 deletions

File tree

CHANGELOG.md

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

3+
## 23.0.0
4+
5+
* Breaking: Made Channel.collection() require id parameter
6+
* Breaking: Made Channel.table() require id parameter
7+
* Breaking: Root factory methods require explicit IDs (databases, executions, tablesdb, bucket, function, team, membership)
8+
* Added ttl option to listDocuments and listRows for caching
9+
310
## 22.4.1
411

512
* Fix very large double values (for example 1.7976931348623157e+308) from being expanded into giant integer literals

README.md

Lines changed: 2 additions & 2 deletions
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-web/releases).**
9+
**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-web/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 Web 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

@@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
3333
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/appwrite@22.4.1"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@23.0.0"></script>
3737
```
3838

3939

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

src/channel.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ 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> {
@@ -44,9 +50,8 @@ export class Channel<T> {
4450

4551
// --- DATABASE ROUTE ---
4652
// Only available on Channel<Database>
47-
collection(this: Channel<Database>, id?: string): Channel<Collection> {
48-
// Default: wildcard collection ID
49-
return this.next<Collection>("collections", id ?? "*");
53+
collection(this: Channel<Database>, id: string): Channel<Collection> {
54+
return this.next<Collection>("collections", id);
5055
}
5156

5257
// Only available on Channel<Collection>
@@ -56,9 +61,8 @@ export class Channel<T> {
5661
}
5762

5863
// --- TABLESDB ROUTE ---
59-
table(this: Channel<TablesDB>, id?: string): Channel<Table> {
60-
// Default: wildcard table ID
61-
return this.next<Table>("tables", id ?? "*");
64+
table(this: Channel<TablesDB>, id: string): Channel<Table> {
65+
return this.next<Table>("tables", id);
6266
}
6367

6468
row(this: Channel<Table>, id?: string): Channel<Row> {
@@ -91,31 +95,31 @@ export class Channel<T> {
9195
}
9296

9397
// --- ROOT FACTORIES ---
94-
static database(id: string = "*") {
98+
static database(id: string) {
9599
return new Channel<Database>(["databases", normalize(id)]);
96100
}
97101

98-
static execution(id: string = "*") {
102+
static execution(id: string) {
99103
return new Channel<Execution>(["executions", normalize(id)]);
100104
}
101105

102-
static tablesdb(id: string = "*") {
106+
static tablesdb(id: string) {
103107
return new Channel<TablesDB>(["tablesdb", normalize(id)]);
104108
}
105109

106-
static bucket(id: string = "*") {
110+
static bucket(id: string) {
107111
return new Channel<Bucket>(["buckets", normalize(id)]);
108112
}
109113

110-
static function(id: string = "*") {
114+
static function(id: string) {
111115
return new Channel<Func>(["functions", normalize(id)]);
112116
}
113117

114-
static team(id: string = "*") {
118+
static team(id: string) {
115119
return new Channel<Team>(["teams", normalize(id)]);
116120
}
117121

118-
static membership(id: string = "*") {
122+
static membership(id: string) {
119123
return new Channel<Membership>(["memberships", normalize(id)]);
120124
}
121125

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class Client {
392392
'x-sdk-name': 'Web',
393393
'x-sdk-platform': 'client',
394394
'x-sdk-language': 'web',
395-
'x-sdk-version': '22.4.1',
395+
'x-sdk-version': '23.0.0',
396396
'X-Appwrite-Response-Format': '1.8.0',
397397
};
398398

src/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export namespace Models {
241241
*/
242242
$id: string;
243243
/**
244-
* Row automatically incrementing ID.
244+
* Row sequence ID.
245245
*/
246246
$sequence: number;
247247
/**
@@ -280,7 +280,7 @@ export namespace Models {
280280
*/
281281
$id: string;
282282
/**
283-
* Document automatically incrementing ID.
283+
* Document sequence ID.
284284
*/
285285
$sequence: number;
286286
/**

src/services/databases.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,12 @@ export class Databases {
351351
* @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.
352352
* @param {string} params.transactionId - Transaction ID to read uncommitted changes within the transaction.
353353
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
354+
* @param {number} params.ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
354355
* @throws {AppwriteException}
355356
* @returns {Promise<Models.DocumentList<Document>>}
356357
* @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.
357358
*/
358-
listDocuments<Document extends Models.Document = Models.DefaultDocument>(params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean }): Promise<Models.DocumentList<Document>>;
359+
listDocuments<Document extends Models.Document = Models.DefaultDocument>(params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number }): Promise<Models.DocumentList<Document>>;
359360
/**
360361
* Get a list of all the user's documents in a given collection. You can use the query params to filter your results.
361362
*
@@ -364,26 +365,28 @@ export class Databases {
364365
* @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.
365366
* @param {string} transactionId - Transaction ID to read uncommitted changes within the transaction.
366367
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
368+
* @param {number} ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
367369
* @throws {AppwriteException}
368370
* @returns {Promise<Models.DocumentList<Document>>}
369371
* @deprecated Use the object parameter style method for a better developer experience.
370372
*/
371-
listDocuments<Document extends Models.Document = Models.DefaultDocument>(databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean): Promise<Models.DocumentList<Document>>;
373+
listDocuments<Document extends Models.Document = Models.DefaultDocument>(databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number): Promise<Models.DocumentList<Document>>;
372374
listDocuments<Document extends Models.Document = Models.DefaultDocument>(
373-
paramsOrFirst: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean } | string,
374-
...rest: [(string)?, (string[])?, (string)?, (boolean)?]
375+
paramsOrFirst: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number } | string,
376+
...rest: [(string)?, (string[])?, (string)?, (boolean)?, (number)?]
375377
): Promise<Models.DocumentList<Document>> {
376-
let params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean };
378+
let params: { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
377379

378380
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
379-
params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean };
381+
params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
380382
} else {
381383
params = {
382384
databaseId: paramsOrFirst as string,
383385
collectionId: rest[0] as string,
384386
queries: rest[1] as string[],
385387
transactionId: rest[2] as string,
386-
total: rest[3] as boolean
388+
total: rest[3] as boolean,
389+
ttl: rest[4] as number
387390
};
388391
}
389392

@@ -392,6 +395,7 @@ export class Databases {
392395
const queries = params.queries;
393396
const transactionId = params.transactionId;
394397
const total = params.total;
398+
const ttl = params.ttl;
395399

396400
if (typeof databaseId === 'undefined') {
397401
throw new AppwriteException('Missing required parameter: "databaseId"');
@@ -411,6 +415,9 @@ export class Databases {
411415
if (typeof total !== 'undefined') {
412416
payload['total'] = total;
413417
}
418+
if (typeof ttl !== 'undefined') {
419+
payload['ttl'] = ttl;
420+
}
414421
const uri = new URL(this.client.config.endpoint + apiPath);
415422

416423
const apiHeaders: { [header: string]: string } = {

src/services/tables-db.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,11 @@ export class TablesDB {
351351
* @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.
352352
* @param {string} params.transactionId - Transaction ID to read uncommitted changes within the transaction.
353353
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
354+
* @param {number} params.ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
354355
* @throws {AppwriteException}
355356
* @returns {Promise<Models.RowList<Row>>}
356357
*/
357-
listRows<Row extends Models.Row = Models.DefaultRow>(params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean }): Promise<Models.RowList<Row>>;
358+
listRows<Row extends Models.Row = Models.DefaultRow>(params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number }): Promise<Models.RowList<Row>>;
358359
/**
359360
* Get a list of all the user's rows in a given table. You can use the query params to filter your results.
360361
*
@@ -363,26 +364,28 @@ export class TablesDB {
363364
* @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.
364365
* @param {string} transactionId - Transaction ID to read uncommitted changes within the transaction.
365366
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
367+
* @param {number} ttl - TTL (seconds) for cached responses when caching is enabled for select queries. Must be between 0 and 86400 (24 hours).
366368
* @throws {AppwriteException}
367369
* @returns {Promise<Models.RowList<Row>>}
368370
* @deprecated Use the object parameter style method for a better developer experience.
369371
*/
370-
listRows<Row extends Models.Row = Models.DefaultRow>(databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean): Promise<Models.RowList<Row>>;
372+
listRows<Row extends Models.Row = Models.DefaultRow>(databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number): Promise<Models.RowList<Row>>;
371373
listRows<Row extends Models.Row = Models.DefaultRow>(
372-
paramsOrFirst: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean } | string,
373-
...rest: [(string)?, (string[])?, (string)?, (boolean)?]
374+
paramsOrFirst: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number } | string,
375+
...rest: [(string)?, (string[])?, (string)?, (boolean)?, (number)?]
374376
): Promise<Models.RowList<Row>> {
375-
let params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean };
377+
let params: { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
376378

377379
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
378-
params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean };
380+
params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, queries?: string[], transactionId?: string, total?: boolean, ttl?: number };
379381
} else {
380382
params = {
381383
databaseId: paramsOrFirst as string,
382384
tableId: rest[0] as string,
383385
queries: rest[1] as string[],
384386
transactionId: rest[2] as string,
385-
total: rest[3] as boolean
387+
total: rest[3] as boolean,
388+
ttl: rest[4] as number
386389
};
387390
}
388391

@@ -391,6 +394,7 @@ export class TablesDB {
391394
const queries = params.queries;
392395
const transactionId = params.transactionId;
393396
const total = params.total;
397+
const ttl = params.ttl;
394398

395399
if (typeof databaseId === 'undefined') {
396400
throw new AppwriteException('Missing required parameter: "databaseId"');
@@ -410,6 +414,9 @@ export class TablesDB {
410414
if (typeof total !== 'undefined') {
411415
payload['total'] = total;
412416
}
417+
if (typeof ttl !== 'undefined') {
418+
payload['ttl'] = ttl;
419+
}
413420
const uri = new URL(this.client.config.endpoint + apiPath);
414421

415422
const apiHeaders: { [header: string]: string } = {

0 commit comments

Comments
 (0)