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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 21.1.0

* Added ability to create columns and indexes synchronously while creating a table

## 21.0.0

* Rename `VCSDeploymentType` enum to `VCSReferenceType`
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-anonymous-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-email-password-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-email-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-magic-url-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-mfa-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-o-auth-2-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-phone-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/update-magic-url-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/account/update-phone-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<YOUR_PROJECT_ID>') // Your project ID
.setSession(''); // The user session to authenticate with

const account = new sdk.Account(client);

Expand Down
4 changes: 3 additions & 1 deletion docs/examples/databases/create-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ const result = await databases.createCollection({
name: '<NAME>',
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
documentSecurity: false, // optional
enabled: false // optional
enabled: false, // optional
attributes: [], // optional
indexes: [] // optional
});
4 changes: 3 additions & 1 deletion docs/examples/tablesdb/create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ const result = await tablesDB.createTable({
name: '<NAME>',
permissions: [sdk.Permission.read(sdk.Role.any())], // optional
rowSecurity: false, // optional
enabled: false // optional
enabled: false, // optional
columns: [], // optional
indexes: [] // optional
});
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": "node-appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
"version": "21.0.0",
"version": "21.1.0",
"license": "BSD-3-Clause",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AppwriteException extends Error {
}

function getUserAgent() {
let ua = 'AppwriteNodeJSSDK/21.0.0';
let ua = 'AppwriteNodeJSSDK/21.1.0';

// `process` is a global in Node.js, but not fully available in all runtimes.
const platform: string[] = [];
Expand Down Expand Up @@ -82,7 +82,7 @@ class Client {
'x-sdk-name': 'Node.js',
'x-sdk-platform': 'server',
'x-sdk-language': 'nodejs',
'x-sdk-version': '21.0.0',
'x-sdk-version': '21.1.0',
'user-agent' : getUserAgent(),
'X-Appwrite-Response-Format': '1.8.0',
};
Expand Down
28 changes: 21 additions & 7 deletions src/services/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,13 @@ export class Databases {
* @param {string[]} params.permissions - An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} params.documentSecurity - Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} params.enabled - Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.
* @param {object[]} params.attributes - Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.
* @param {object[]} params.indexes - Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).
* @throws {AppwriteException}
* @returns {Promise<Models.Collection>}
* @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.createTable` instead.
*/
createCollection(params: { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean }): Promise<Models.Collection>;
createCollection(params: { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean, attributes?: object[], indexes?: object[] }): Promise<Models.Collection>;
/**
* Create a new Collection. Before using this route, you should create a new database resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
*
Expand All @@ -761,27 +763,31 @@ export class Databases {
* @param {string[]} permissions - An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} documentSecurity - Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} enabled - Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.
* @param {object[]} attributes - Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.
* @param {object[]} indexes - Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).
* @throws {AppwriteException}
* @returns {Promise<Models.Collection>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createCollection(databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean): Promise<Models.Collection>;
createCollection(databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean, attributes?: object[], indexes?: object[]): Promise<Models.Collection>;
createCollection(
paramsOrFirst: { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean } | string,
...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?]
paramsOrFirst: { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean, attributes?: object[], indexes?: object[] } | string,
...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?, (object[])?, (object[])?]
): Promise<Models.Collection> {
let params: { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean };
let params: { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean, attributes?: object[], indexes?: object[] };

if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean };
params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean, attributes?: object[], indexes?: object[] };
} else {
params = {
databaseId: paramsOrFirst as string,
collectionId: rest[0] as string,
name: rest[1] as string,
permissions: rest[2] as string[],
documentSecurity: rest[3] as boolean,
enabled: rest[4] as boolean
enabled: rest[4] as boolean,
attributes: rest[5] as object[],
indexes: rest[6] as object[]
};
}

Expand All @@ -791,6 +797,8 @@ export class Databases {
const permissions = params.permissions;
const documentSecurity = params.documentSecurity;
const enabled = params.enabled;
const attributes = params.attributes;
const indexes = params.indexes;

if (typeof databaseId === 'undefined') {
throw new AppwriteException('Missing required parameter: "databaseId"');
Expand Down Expand Up @@ -819,6 +827,12 @@ export class Databases {
if (typeof enabled !== 'undefined') {
payload['enabled'] = enabled;
}
if (typeof attributes !== 'undefined') {
payload['attributes'] = attributes;
}
if (typeof indexes !== 'undefined') {
payload['indexes'] = indexes;
}
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
Expand Down
28 changes: 21 additions & 7 deletions src/services/tables-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,12 @@ export class TablesDB {
* @param {string[]} params.permissions - An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} params.rowSecurity - Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} params.enabled - Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.
* @param {object[]} params.columns - Array of column definitions to create. Each column should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.
* @param {object[]} params.indexes - Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of column keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).
* @throws {AppwriteException}
* @returns {Promise<Models.Table>}
*/
createTable(params: { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean }): Promise<Models.Table>;
createTable(params: { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean, columns?: object[], indexes?: object[] }): Promise<Models.Table>;
/**
* Create a new Table. Before using this route, you should create a new database resource using either a [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) API or directly from your database console.
*
Expand All @@ -754,27 +756,31 @@ export class TablesDB {
* @param {string[]} permissions - An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} rowSecurity - Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).
* @param {boolean} enabled - Is table enabled? When set to 'disabled', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.
* @param {object[]} columns - Array of column definitions to create. Each column should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.
* @param {object[]} indexes - Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of column keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).
* @throws {AppwriteException}
* @returns {Promise<Models.Table>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createTable(databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean): Promise<Models.Table>;
createTable(databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean, columns?: object[], indexes?: object[]): Promise<Models.Table>;
createTable(
paramsOrFirst: { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean } | string,
...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?]
paramsOrFirst: { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean, columns?: object[], indexes?: object[] } | string,
...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?, (object[])?, (object[])?]
): Promise<Models.Table> {
let params: { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean };
let params: { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean, columns?: object[], indexes?: object[] };

if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean };
params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, name: string, permissions?: string[], rowSecurity?: boolean, enabled?: boolean, columns?: object[], indexes?: object[] };
} else {
params = {
databaseId: paramsOrFirst as string,
tableId: rest[0] as string,
name: rest[1] as string,
permissions: rest[2] as string[],
rowSecurity: rest[3] as boolean,
enabled: rest[4] as boolean
enabled: rest[4] as boolean,
columns: rest[5] as object[],
indexes: rest[6] as object[]
};
}

Expand All @@ -784,6 +790,8 @@ export class TablesDB {
const permissions = params.permissions;
const rowSecurity = params.rowSecurity;
const enabled = params.enabled;
const columns = params.columns;
const indexes = params.indexes;

if (typeof databaseId === 'undefined') {
throw new AppwriteException('Missing required parameter: "databaseId"');
Expand Down Expand Up @@ -812,6 +820,12 @@ export class TablesDB {
if (typeof enabled !== 'undefined') {
payload['enabled'] = enabled;
}
if (typeof columns !== 'undefined') {
payload['columns'] = columns;
}
if (typeof indexes !== 'undefined') {
payload['indexes'] = indexes;
}
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
Expand Down