1
0
Fork 0
mirror of synced 2024-06-14 00:34:51 +12:00

Updated SDKs

This commit is contained in:
eldadfux 2019-08-06 17:00:08 +03:00
parent fb5873ef7a
commit 2ec497d88c
21 changed files with 437 additions and 298 deletions

View file

@ -0,0 +1,14 @@
let sdk = new Appwrite();
sdk
setProject('')
setKey('')
;
let promise = sdk.database.getCollection('[COLLECTION_ID]');
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});

View file

@ -5,7 +5,7 @@ sdk
setKey('')
;
let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 1);
let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0);
promise.then(function (response) {
console.log(response);

View file

@ -5,7 +5,7 @@ sdk
setKey('')
;
let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0);
let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 1);
promise.then(function (response) {
console.log(response);

View file

@ -2,7 +2,7 @@
"name": "appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)",
"version": "v1.0.7",
"version": "v1.0.8",
"license": "BSD-3-Clause",
"main": "src/sdk.js",
"repository": {

View file

@ -132,7 +132,7 @@
globalParams.push({key: key, value: value});
};
addGlobalHeader('x-sdk-version', 'appwrite:javascript:v1.0.7');
addGlobalHeader('x-sdk-version', 'appwrite:javascript:v1.0.8');
addGlobalHeader('content-type', '');
/**
@ -1049,26 +1049,15 @@
},
/**
* List Documents
* Get Collection
*
* Get a list of all the user documents. You can use the query params to
* filter your results. On admin mode, this endpoint will return a list of all
* of the project documents. [Learn more about different API
* modes](/docs/modes).
* Get collection by its unique ID. This endpoint response returns a JSON
* object with the collection metadata.
*
* @param {string} collectionId
* @param {array} filters
* @param {number} offset
* @param {number} limit
* @param {string} orderField
* @param {string} orderType
* @param {string} orderCast
* @param {string} search
* @param {number} first
* @param {number} last
* @throws {Error}
* @return {Promise} */
listDocuments: function(collectionId, filters = [], offset = 0, limit = 50, orderField = '$uid', orderType = 'ASC', orderCast = 'string', search = '', first = 0, last = 0) {
getCollection: function(collectionId) {
if(collectionId === undefined) {
throw new Error('Missing required parameter: "collectionId"');
}
@ -1078,52 +1067,6 @@
return http
.get(path, {'content-type': 'application/json'},
{
'filters': filters,
'offset': offset,
'limit': limit,
'order-field': orderField,
'order-type': orderType,
'order-cast': orderCast,
'search': search,
'first': first,
'last': last
});
},
/**
* Create Document
*
* Create a new Document.
*
* @param {string} collectionId
* @param {string} data
* @param {array} read
* @param {array} write
* @param {string} parentDocument
* @param {string} parentProperty
* @param {string} parentPropertyType
* @throws {Error}
* @return {Promise} */
createDocument: function(collectionId, data, read = [], write = [], parentDocument = '', parentProperty = '', parentPropertyType = 'assign') {
if(collectionId === undefined) {
throw new Error('Missing required parameter: "collectionId"');
}
if(data === undefined) {
throw new Error('Missing required parameter: "data"');
}
let path = '/database/{collectionId}'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return http
.post(path, {'content-type': 'application/json'},
{
'data': data,
'read': read,
'write': write,
'parentDocument': parentDocument,
'parentProperty': parentProperty,
'parentPropertyType': parentPropertyType
});
},
@ -1182,6 +1125,85 @@
});
},
/**
* List Documents
*
* Get a list of all the user documents. You can use the query params to
* filter your results. On admin mode, this endpoint will return a list of all
* of the project documents. [Learn more about different API
* modes](/docs/modes).
*
* @param {string} collectionId
* @param {array} filters
* @param {number} offset
* @param {number} limit
* @param {string} orderField
* @param {string} orderType
* @param {string} orderCast
* @param {string} search
* @param {number} first
* @param {number} last
* @throws {Error}
* @return {Promise} */
listDocuments: function(collectionId, filters = [], offset = 0, limit = 50, orderField = '$uid', orderType = 'ASC', orderCast = 'string', search = '', first = 0, last = 0) {
if(collectionId === undefined) {
throw new Error('Missing required parameter: "collectionId"');
}
let path = '/database/{collectionId}/documents'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return http
.get(path, {'content-type': 'application/json'},
{
'filters': filters,
'offset': offset,
'limit': limit,
'order-field': orderField,
'order-type': orderType,
'order-cast': orderCast,
'search': search,
'first': first,
'last': last
});
},
/**
* Create Document
*
* Create a new Document.
*
* @param {string} collectionId
* @param {string} data
* @param {array} read
* @param {array} write
* @param {string} parentDocument
* @param {string} parentProperty
* @param {string} parentPropertyType
* @throws {Error}
* @return {Promise} */
createDocument: function(collectionId, data, read = [], write = [], parentDocument = '', parentProperty = '', parentPropertyType = 'assign') {
if(collectionId === undefined) {
throw new Error('Missing required parameter: "collectionId"');
}
if(data === undefined) {
throw new Error('Missing required parameter: "data"');
}
let path = '/database/{collectionId}/documents'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return http
.post(path, {'content-type': 'application/json'},
{
'data': data,
'read': read,
'write': write,
'parentDocument': parentDocument,
'parentProperty': parentProperty,
'parentPropertyType': parentPropertyType
});
},
/**
* Get Document
*
@ -1201,7 +1223,7 @@
throw new Error('Missing required parameter: "documentId"');
}
let path = '/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
let path = '/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
return http
.get(path, {'content-type': 'application/json'},
@ -1233,7 +1255,7 @@
throw new Error('Missing required parameter: "data"');
}
let path = '/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
let path = '/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
return http
.patch(path, {'content-type': 'application/json'},
@ -1264,7 +1286,7 @@
throw new Error('Missing required parameter: "documentId"');
}
let path = '/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
let path = '/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
return http
.delete(path, {'content-type': 'application/json'},

View file

@ -1,5 +1,5 @@
(function(window){window.Appwrite=function(){let config={endpoint:'https://appwrite.test/v1',project:'',key:'',locale:'',mode:'',};let setEndpoint=function(endpoint){config.endpoint=endpoint;return this};let setProject=function(value){http.addGlobalHeader('X-Appwrite-Project',value);config.project=value;return this};let setKey=function(value){http.addGlobalHeader('X-Appwrite-Key',value);config.key=value;return this};let setLocale=function(value){http.addGlobalHeader('X-Appwrite-Locale',value);config.locale=value;return this};let setMode=function(value){http.addGlobalHeader('X-Appwrite-Mode',value);config.mode=value;return this};let http=function(document){let globalParams=[],globalHeaders=[];let addParam=function(url,param,value){let a=document.createElement('a'),regex=/(?:\?|&|&)+([^=]+)(?:=([^&]*))*/g;let match,str=[];a.href=url;param=encodeURIComponent(param);while(match=regex.exec(a.search))if(param!==match[1])str.push(match[1]+(match[2]?"="+match[2]:""));str.push(param+(value?"="+encodeURIComponent(value):""));a.search=str.join("&");return a.href};let buildQuery=function(params){let str=[];for(let p in params){if(params.hasOwnProperty(p)){str.push(encodeURIComponent(p)+"="+encodeURIComponent(params[p]))}}
return str.join("&")};let addGlobalHeader=function(key,value){globalHeaders[key]={key:key.toLowerCase(),value:value.toLowerCase()}};let addGlobalParam=function(key,value){globalParams.push({key:key,value:value})};addGlobalHeader('x-sdk-version','appwrite:javascript:v1.0.7');addGlobalHeader('content-type','');let call=function(method,path,headers={},params={},progress=null){let i;path=config.endpoint+path;if(-1===['GET','POST','PUT','DELETE','TRACE','HEAD','OPTIONS','CONNECT','PATCH'].indexOf(method)){throw new Error('var method must contain a valid HTTP method name')}
return str.join("&")};let addGlobalHeader=function(key,value){globalHeaders[key]={key:key.toLowerCase(),value:value.toLowerCase()}};let addGlobalParam=function(key,value){globalParams.push({key:key,value:value})};addGlobalHeader('x-sdk-version','appwrite:javascript:v1.0.8');addGlobalHeader('content-type','');let call=function(method,path,headers={},params={},progress=null){let i;path=config.endpoint+path;if(-1===['GET','POST','PUT','DELETE','TRACE','HEAD','OPTIONS','CONNECT','PATCH'].indexOf(method)){throw new Error('var method must contain a valid HTTP method name')}
if(typeof path!=='string'){throw new Error('var path must be of type string')}
if(typeof headers!=='object'){throw new Error('var headers must be of type object')}
for(i=0;i<globalParams.length;i++){path=addParam(path,globalParams[i].key,globalParams[i].value)}
@ -43,20 +43,21 @@ let path='/avatars/favicon';return http.get(path,{'content-type':'application/js
let path='/avatars/flags/{code}'.replace(new RegExp('{code}','g'),code);return http.get(path,{'content-type':'application/json'},{'width':width,'height':height,'quality':quality})},getImage:function(url,width=400,height=400){if(url===undefined){throw new Error('Missing required parameter: "url"')}
let path='/avatars/image';return http.get(path,{'content-type':'application/json'},{'url':url,'width':width,'height':height})},getQR:function(text,size=400,margin=1,download=0){if(text===undefined){throw new Error('Missing required parameter: "text"')}
let path='/avatars/qr';return http.get(path,{'content-type':'application/json'},{'text':text,'size':size,'margin':margin,'download':download})}};let database={listCollections:function(search='',limit=25,offset=0,orderType='ASC'){let path='/database';return http.get(path,{'content-type':'application/json'},{'search':search,'limit':limit,'offset':offset,'orderType':orderType})},createCollection:function(name,read=[],write=[],rules=[]){if(name===undefined){throw new Error('Missing required parameter: "name"')}
let path='/database';return http.post(path,{'content-type':'application/json'},{'name':name,'read':read,'write':write,'rules':rules})},listDocuments:function(collectionId,filters=[],offset=0,limit=50,orderField='$uid',orderType='ASC',orderCast='string',search='',first=0,last=0){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}'.replace(new RegExp('{collectionId}','g'),collectionId);return http.get(path,{'content-type':'application/json'},{'filters':filters,'offset':offset,'limit':limit,'order-field':orderField,'order-type':orderType,'order-cast':orderCast,'search':search,'first':first,'last':last})},createDocument:function(collectionId,data,read=[],write=[],parentDocument='',parentProperty='',parentPropertyType='assign'){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
if(data===undefined){throw new Error('Missing required parameter: "data"')}
let path='/database/{collectionId}'.replace(new RegExp('{collectionId}','g'),collectionId);return http.post(path,{'content-type':'application/json'},{'data':data,'read':read,'write':write,'parentDocument':parentDocument,'parentProperty':parentProperty,'parentPropertyType':parentPropertyType})},updateCollection:function(collectionId,name,read=[],write=[],rules=[]){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database';return http.post(path,{'content-type':'application/json'},{'name':name,'read':read,'write':write,'rules':rules})},getCollection:function(collectionId){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}'.replace(new RegExp('{collectionId}','g'),collectionId);return http.get(path,{'content-type':'application/json'},{})},updateCollection:function(collectionId,name,read=[],write=[],rules=[]){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
if(name===undefined){throw new Error('Missing required parameter: "name"')}
let path='/database/{collectionId}'.replace(new RegExp('{collectionId}','g'),collectionId);return http.put(path,{'content-type':'application/json'},{'name':name,'read':read,'write':write,'rules':rules})},deleteCollection:function(collectionId){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}'.replace(new RegExp('{collectionId}','g'),collectionId);return http.delete(path,{'content-type':'application/json'},{})},getDocument:function(collectionId,documentId){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}'.replace(new RegExp('{collectionId}','g'),collectionId);return http.delete(path,{'content-type':'application/json'},{})},listDocuments:function(collectionId,filters=[],offset=0,limit=50,orderField='$uid',orderType='ASC',orderCast='string',search='',first=0,last=0){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}/documents'.replace(new RegExp('{collectionId}','g'),collectionId);return http.get(path,{'content-type':'application/json'},{'filters':filters,'offset':offset,'limit':limit,'order-field':orderField,'order-type':orderType,'order-cast':orderCast,'search':search,'first':first,'last':last})},createDocument:function(collectionId,data,read=[],write=[],parentDocument='',parentProperty='',parentPropertyType='assign'){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
if(data===undefined){throw new Error('Missing required parameter: "data"')}
let path='/database/{collectionId}/documents'.replace(new RegExp('{collectionId}','g'),collectionId);return http.post(path,{'content-type':'application/json'},{'data':data,'read':read,'write':write,'parentDocument':parentDocument,'parentProperty':parentProperty,'parentPropertyType':parentPropertyType})},getDocument:function(collectionId,documentId){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
if(documentId===undefined){throw new Error('Missing required parameter: "documentId"')}
let path='/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}','g'),collectionId).replace(new RegExp('{documentId}','g'),documentId);return http.get(path,{'content-type':'application/json'},{})},updateDocument:function(collectionId,documentId,data,read=[],write=[]){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}','g'),collectionId).replace(new RegExp('{documentId}','g'),documentId);return http.get(path,{'content-type':'application/json'},{})},updateDocument:function(collectionId,documentId,data,read=[],write=[]){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
if(documentId===undefined){throw new Error('Missing required parameter: "documentId"')}
if(data===undefined){throw new Error('Missing required parameter: "data"')}
let path='/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}','g'),collectionId).replace(new RegExp('{documentId}','g'),documentId);return http.patch(path,{'content-type':'application/json'},{'data':data,'read':read,'write':write})},deleteDocument:function(collectionId,documentId){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
let path='/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}','g'),collectionId).replace(new RegExp('{documentId}','g'),documentId);return http.patch(path,{'content-type':'application/json'},{'data':data,'read':read,'write':write})},deleteDocument:function(collectionId,documentId){if(collectionId===undefined){throw new Error('Missing required parameter: "collectionId"')}
if(documentId===undefined){throw new Error('Missing required parameter: "documentId"')}
let path='/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}','g'),collectionId).replace(new RegExp('{documentId}','g'),documentId);return http.delete(path,{'content-type':'application/json'},{})}};let locale={getLocale:function(){let path='/locale';return http.get(path,{'content-type':'application/json'},{})},getCountries:function(){let path='/locale/countries';return http.get(path,{'content-type':'application/json'},{})},getCountriesEU:function(){let path='/locale/countries/eu';return http.get(path,{'content-type':'application/json'},{})},getCountriesPhones:function(){let path='/locale/countries/phones';return http.get(path,{'content-type':'application/json'},{})}};let projects={listProjects:function(){let path='/projects';return http.get(path,{'content-type':'application/json'},{})},createProject:function(name,teamId,description='',logo='',url='',clients=[],legalName='',legalCountry='',legalState='',legalCity='',legalAddress='',legalTaxId=''){if(name===undefined){throw new Error('Missing required parameter: "name"')}
let path='/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}','g'),collectionId).replace(new RegExp('{documentId}','g'),documentId);return http.delete(path,{'content-type':'application/json'},{})}};let locale={getLocale:function(){let path='/locale';return http.get(path,{'content-type':'application/json'},{})},getCountries:function(){let path='/locale/countries';return http.get(path,{'content-type':'application/json'},{})},getCountriesEU:function(){let path='/locale/countries/eu';return http.get(path,{'content-type':'application/json'},{})},getCountriesPhones:function(){let path='/locale/countries/phones';return http.get(path,{'content-type':'application/json'},{})}};let projects={listProjects:function(){let path='/projects';return http.get(path,{'content-type':'application/json'},{})},createProject:function(name,teamId,description='',logo='',url='',clients=[],legalName='',legalCountry='',legalState='',legalCity='',legalAddress='',legalTaxId=''){if(name===undefined){throw new Error('Missing required parameter: "name"')}
if(teamId===undefined){throw new Error('Missing required parameter: "teamId"')}
let path='/projects';return http.post(path,{'content-type':'application/json'},{'name':name,'teamId':teamId,'description':description,'logo':logo,'url':url,'clients':clients,'legalName':legalName,'legalCountry':legalCountry,'legalState':legalState,'legalCity':legalCity,'legalAddress':legalAddress,'legalTaxId':legalTaxId})},getProject:function(projectId){if(projectId===undefined){throw new Error('Missing required parameter: "projectId"')}
let path='/projects/{projectId}'.replace(new RegExp('{projectId}','g'),projectId);return http.get(path,{'content-type':'application/json'},{})},updateProject:function(projectId,name,description='',logo='',url='',clients=[],legalName='',legalCountry='',legalState='',legalCity='',legalAddress='',legalTaxId=''){if(projectId===undefined){throw new Error('Missing required parameter: "projectId"')}

View file

@ -0,0 +1,14 @@
let sdk = new Appwrite();
sdk
setProject('')
setKey('')
;
let promise = sdk.database.getCollection('[COLLECTION_ID]');
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});

View file

@ -5,7 +5,7 @@ sdk
setKey('')
;
let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 1);
let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0);
promise.then(function (response) {
console.log(response);

View file

@ -5,7 +5,7 @@ sdk
setKey('')
;
let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0);
let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 1);
promise.then(function (response) {
console.log(response);

View file

@ -7,7 +7,7 @@ class Client {
this.endpoint = 'https://appwrite.test/v1';
this.headers = {
'content-type': '',
'x-sdk-version': 'appwrite:nodejs:v1.0.17',
'x-sdk-version': 'appwrite:nodejs:v1.0.18',
};
this.selfSigned = false;
}

View file

@ -54,69 +54,20 @@ class Database extends Service {
}
/**
* List Documents
* Get Collection
*
* Get a list of all the user documents. You can use the query params to
* filter your results. On admin mode, this endpoint will return a list of all
* of the project documents. [Learn more about different API
* modes](/docs/modes).
* Get collection by its unique ID. This endpoint response returns a JSON
* object with the collection metadata.
*
* @param string collectionId
* @param array filters
* @param number offset
* @param number limit
* @param string orderField
* @param string orderType
* @param string orderCast
* @param string search
* @param number first
* @param number last
* @throws Exception
* @return {}
*/
async listDocuments(collectionId, filters = [], offset = 0, limit = 50, orderField = '$uid', orderType = 'ASC', orderCast = 'string', search = '', first = 0, last = 0) {
async getCollection(collectionId) {
let path = '/database/{collectionId}'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return await this.client.call('get', path, {'content-type': 'application/json'},
{
'filters': filters,
'offset': offset,
'limit': limit,
'order-field': orderField,
'order-type': orderType,
'order-cast': orderCast,
'search': search,
'first': first,
'last': last
});
}
/**
* Create Document
*
* Create a new Document.
*
* @param string collectionId
* @param string data
* @param array read
* @param array write
* @param string parentDocument
* @param string parentProperty
* @param string parentPropertyType
* @throws Exception
* @return {}
*/
async createDocument(collectionId, data, read = [], write = [], parentDocument = '', parentProperty = '', parentPropertyType = 'assign') {
let path = '/database/{collectionId}'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return await this.client.call('post', path, {'content-type': 'application/json'},
{
'data': data,
'read': read,
'write': write,
'parentDocument': parentDocument,
'parentProperty': parentProperty,
'parentPropertyType': parentPropertyType
});
}
@ -163,6 +114,73 @@ class Database extends Service {
});
}
/**
* List Documents
*
* Get a list of all the user documents. You can use the query params to
* filter your results. On admin mode, this endpoint will return a list of all
* of the project documents. [Learn more about different API
* modes](/docs/modes).
*
* @param string collectionId
* @param array filters
* @param number offset
* @param number limit
* @param string orderField
* @param string orderType
* @param string orderCast
* @param string search
* @param number first
* @param number last
* @throws Exception
* @return {}
*/
async listDocuments(collectionId, filters = [], offset = 0, limit = 50, orderField = '$uid', orderType = 'ASC', orderCast = 'string', search = '', first = 0, last = 0) {
let path = '/database/{collectionId}/documents'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return await this.client.call('get', path, {'content-type': 'application/json'},
{
'filters': filters,
'offset': offset,
'limit': limit,
'order-field': orderField,
'order-type': orderType,
'order-cast': orderCast,
'search': search,
'first': first,
'last': last
});
}
/**
* Create Document
*
* Create a new Document.
*
* @param string collectionId
* @param string data
* @param array read
* @param array write
* @param string parentDocument
* @param string parentProperty
* @param string parentPropertyType
* @throws Exception
* @return {}
*/
async createDocument(collectionId, data, read = [], write = [], parentDocument = '', parentProperty = '', parentPropertyType = 'assign') {
let path = '/database/{collectionId}/documents'.replace(new RegExp('{collectionId}', 'g'), collectionId);
return await this.client.call('post', path, {'content-type': 'application/json'},
{
'data': data,
'read': read,
'write': write,
'parentDocument': parentDocument,
'parentProperty': parentProperty,
'parentPropertyType': parentPropertyType
});
}
/**
* Get Document
*
@ -175,7 +193,7 @@ class Database extends Service {
* @return {}
*/
async getDocument(collectionId, documentId) {
let path = '/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
let path = '/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
return await this.client.call('get', path, {'content-type': 'application/json'},
{
@ -194,7 +212,7 @@ class Database extends Service {
* @return {}
*/
async updateDocument(collectionId, documentId, data, read = [], write = []) {
let path = '/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
let path = '/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
return await this.client.call('patch', path, {'content-type': 'application/json'},
{
@ -217,7 +235,7 @@ class Database extends Service {
* @return {}
*/
async deleteDocument(collectionId, documentId) {
let path = '/database/{collectionId}/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
let path = '/database/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId);
return await this.client.call('delete', path, {'content-type': 'application/json'},
{

View file

@ -2,7 +2,7 @@
"name": "node-appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)",
"version": "v1.0.17",
"version": "v1.0.18",
"license": "BSD-3-Clause",
"main": "index.js",
"repository": {

View file

@ -34,48 +34,19 @@ POST https://appwrite.test/v1/database
| write | array | An array of write permissions. [Learn more about permissions and roles](/docs/permissions). | [] |
| rules | array | Array of collection structure rules. Each rule define a collection field name, data type and validation | [] |
## List Documents
## Get Collection
```http request
GET https://appwrite.test/v1/database/{collectionId}
```
** Get a list of all the user documents. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project documents. [Learn more about different API modes](/docs/modes). **
** Get collection by its unique ID. This endpoint response returns a JSON object with the collection metadata. **
### Parameters
| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| collectionId | string | **Required** Collection unique ID. | |
| filters | array | Array of filter strings. Each filter is constructed from a key name, comparison operator (=, !=, &gt;, &lt;, &lt;=, &gt;=) and a value. You can also use a dot (.) separator in attribute names to filter by child document attributes. Examples: &#039;name=John Doe&#039; or &#039;category.$uid&gt;=5bed2d152c362&#039; | [] |
| offset | integer | Offset value. Use this value to manage pagination. | 0 |
| limit | integer | Maximum number of documents to return in response. Use this value to manage pagination. | 50 |
| order-field | string | Document field that results will be sorted by. | $uid |
| order-type | string | Order direction. Possible values are DESC for descending order, or ASC for ascending order. | ASC |
| order-cast | string | Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string. | string |
| search | string | Search query. Enter any free text search. The database will try to find a match against all document attributes and children. | |
| first | integer | Return only first document. Pass 1 for true or 0 for false. The default value is 0. | 0 |
| last | integer | Return only last document. Pass 1 for true or 0 for false. The default value is 0. | 0 |
## Create Document
```http request
POST https://appwrite.test/v1/database/{collectionId}
```
** Create a new Document. **
### Parameters
| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| collectionId | string | **Required** Collection unique ID. | |
| data | string | Document data as JSON string. | |
| read | array | An array of read permissions. [Learn more about permissions and roles](/docs/permissions). | [] |
| write | array | An array of write permissions. [Learn more about permissions and roles](/docs/permissions). | [] |
| parentDocument | string | Parent document unique ID. Use when you want your new document to be a child of a parent document. | |
| parentProperty | string | Parent document property name. Use when you want your new document to be a child of a parent document. | |
| parentPropertyType | string | Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document. | assign |
## Update Collection
@ -109,10 +80,53 @@ DELETE https://appwrite.test/v1/database/{collectionId}
| --- | --- | --- | --- |
| collectionId | string | **Required** Collection unique ID. | |
## List Documents
```http request
GET https://appwrite.test/v1/database/{collectionId}/documents
```
** Get a list of all the user documents. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project documents. [Learn more about different API modes](/docs/modes). **
### Parameters
| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| collectionId | string | **Required** Collection unique ID. | |
| filters | array | Array of filter strings. Each filter is constructed from a key name, comparison operator (=, !=, &gt;, &lt;, &lt;=, &gt;=) and a value. You can also use a dot (.) separator in attribute names to filter by child document attributes. Examples: &#039;name=John Doe&#039; or &#039;category.$uid&gt;=5bed2d152c362&#039; | [] |
| offset | integer | Offset value. Use this value to manage pagination. | 0 |
| limit | integer | Maximum number of documents to return in response. Use this value to manage pagination. | 50 |
| order-field | string | Document field that results will be sorted by. | $uid |
| order-type | string | Order direction. Possible values are DESC for descending order, or ASC for ascending order. | ASC |
| order-cast | string | Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string. | string |
| search | string | Search query. Enter any free text search. The database will try to find a match against all document attributes and children. | |
| first | integer | Return only first document. Pass 1 for true or 0 for false. The default value is 0. | 0 |
| last | integer | Return only last document. Pass 1 for true or 0 for false. The default value is 0. | 0 |
## Create Document
```http request
POST https://appwrite.test/v1/database/{collectionId}/documents
```
** Create a new Document. **
### Parameters
| Field Name | Type | Description | Default |
| --- | --- | --- | --- |
| collectionId | string | **Required** Collection unique ID. | |
| data | string | Document data as JSON string. | |
| read | array | An array of read permissions. [Learn more about permissions and roles](/docs/permissions). | [] |
| write | array | An array of write permissions. [Learn more about permissions and roles](/docs/permissions). | [] |
| parentDocument | string | Parent document unique ID. Use when you want your new document to be a child of a parent document. | |
| parentProperty | string | Parent document property name. Use when you want your new document to be a child of a parent document. | |
| parentPropertyType | string | Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document. | assign |
## Get Document
```http request
GET https://appwrite.test/v1/database/{collectionId}/{documentId}
GET https://appwrite.test/v1/database/{collectionId}/documents/{documentId}
```
** Get document by its unique ID. This endpoint response returns a JSON object with the document data. **
@ -127,7 +141,7 @@ GET https://appwrite.test/v1/database/{collectionId}/{documentId}
## Update Document
```http request
PATCH https://appwrite.test/v1/database/{collectionId}/{documentId}
PATCH https://appwrite.test/v1/database/{collectionId}/documents/{documentId}
```
### Parameters
@ -143,7 +157,7 @@ PATCH https://appwrite.test/v1/database/{collectionId}/{documentId}
## Delete Document
```http request
DELETE https://appwrite.test/v1/database/{collectionId}/{documentId}
DELETE https://appwrite.test/v1/database/{collectionId}/documents/{documentId}
```
** Delete document by its unique ID. This endpoint deletes only the parent documents, his attributes and relations to other documents. Child documents **will not** be deleted. **

View file

@ -0,0 +1,15 @@
<?php
use Appwrite\Client;
use Appwrite\Services\Database;
$client = new Client();
$client
setProject('')
setKey('')
;
$database = new Database($client);
$result = $database->getCollection('[COLLECTION_ID]');

View file

@ -12,4 +12,4 @@ $client
$projects = new Projects($client);
$result = $projects->createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 1);
$result = $projects->createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0);

View file

@ -12,4 +12,4 @@ $client
$projects = new Projects($client);
$result = $projects->updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0);
$result = $projects->updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 1);

View file

@ -37,7 +37,7 @@ class Client
*/
protected $headers = [
'content-type' => '',
'x-sdk-version' => 'appwrite:php:v1.0.0',
'x-sdk-version' => 'appwrite:php:v1.0.1',
];
/**

View file

@ -64,76 +64,25 @@ class Database extends Service
}
/**
* List Documents
* Get Collection
*
* Get a list of all the user documents. You can use the query params to
* filter your results. On admin mode, this endpoint will return a list of all
* of the project documents. [Learn more about different API
* modes](/docs/modes).
* Get collection by its unique ID. This endpoint response returns a JSON
* object with the collection metadata.
*
* @param string $collectionId
* @param array $filters
* @param integer $offset
* @param integer $limit
* @param string $orderField
* @param string $orderType
* @param string $orderCast
* @param string $search
* @param integer $first
* @param integer $last
* @throws Exception
* @return array
*/
public function listDocuments($collectionId, $filters = [], $offset = 0, $limit = 50, $orderField = '$uid', $orderType = 'ASC', $orderCast = 'string', $search = '', $first = 0, $last = 0)
public function getCollection($collectionId)
{
$path = str_replace(['{collectionId}'], [$collectionId], '/database/{collectionId}');
$params = [];
$params['filters'] = $filters;
$params['offset'] = $offset;
$params['limit'] = $limit;
$params['order-field'] = $orderField;
$params['order-type'] = $orderType;
$params['order-cast'] = $orderCast;
$params['search'] = $search;
$params['first'] = $first;
$params['last'] = $last;
return $this->client->call(Client::METHOD_GET, $path, [
], $params);
}
/**
* Create Document
*
* Create a new Document.
*
* @param string $collectionId
* @param string $data
* @param array $read
* @param array $write
* @param string $parentDocument
* @param string $parentProperty
* @param string $parentPropertyType
* @throws Exception
* @return array
*/
public function createDocument($collectionId, $data, $read = [], $write = [], $parentDocument = '', $parentProperty = '', $parentPropertyType = 'assign')
{
$path = str_replace(['{collectionId}'], [$collectionId], '/database/{collectionId}');
$params = [];
$params['data'] = $data;
$params['read'] = $read;
$params['write'] = $write;
$params['parentDocument'] = $parentDocument;
$params['parentProperty'] = $parentProperty;
$params['parentPropertyType'] = $parentPropertyType;
return $this->client->call(Client::METHOD_POST, $path, [
], $params);
}
/**
* Update Collection
*
@ -181,6 +130,77 @@ class Database extends Service
], $params);
}
/**
* List Documents
*
* Get a list of all the user documents. You can use the query params to
* filter your results. On admin mode, this endpoint will return a list of all
* of the project documents. [Learn more about different API
* modes](/docs/modes).
*
* @param string $collectionId
* @param array $filters
* @param integer $offset
* @param integer $limit
* @param string $orderField
* @param string $orderType
* @param string $orderCast
* @param string $search
* @param integer $first
* @param integer $last
* @throws Exception
* @return array
*/
public function listDocuments($collectionId, $filters = [], $offset = 0, $limit = 50, $orderField = '$uid', $orderType = 'ASC', $orderCast = 'string', $search = '', $first = 0, $last = 0)
{
$path = str_replace(['{collectionId}'], [$collectionId], '/database/{collectionId}/documents');
$params = [];
$params['filters'] = $filters;
$params['offset'] = $offset;
$params['limit'] = $limit;
$params['order-field'] = $orderField;
$params['order-type'] = $orderType;
$params['order-cast'] = $orderCast;
$params['search'] = $search;
$params['first'] = $first;
$params['last'] = $last;
return $this->client->call(Client::METHOD_GET, $path, [
], $params);
}
/**
* Create Document
*
* Create a new Document.
*
* @param string $collectionId
* @param string $data
* @param array $read
* @param array $write
* @param string $parentDocument
* @param string $parentProperty
* @param string $parentPropertyType
* @throws Exception
* @return array
*/
public function createDocument($collectionId, $data, $read = [], $write = [], $parentDocument = '', $parentProperty = '', $parentPropertyType = 'assign')
{
$path = str_replace(['{collectionId}'], [$collectionId], '/database/{collectionId}/documents');
$params = [];
$params['data'] = $data;
$params['read'] = $read;
$params['write'] = $write;
$params['parentDocument'] = $parentDocument;
$params['parentProperty'] = $parentProperty;
$params['parentPropertyType'] = $parentPropertyType;
return $this->client->call(Client::METHOD_POST, $path, [
], $params);
}
/**
* Get Document
*
@ -194,7 +214,7 @@ class Database extends Service
*/
public function getDocument($collectionId, $documentId)
{
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/{collectionId}/{documentId}');
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/{collectionId}/documents/{documentId}');
$params = [];
@ -215,7 +235,7 @@ class Database extends Service
*/
public function updateDocument($collectionId, $documentId, $data, $read = [], $write = [])
{
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/{collectionId}/{documentId}');
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/{collectionId}/documents/{documentId}');
$params = [];
$params['data'] = $data;
@ -240,7 +260,7 @@ class Database extends Service
*/
public function deleteDocument($collectionId, $documentId)
{
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/{collectionId}/{documentId}');
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/{collectionId}/documents/{documentId}');
$params = [];

View file

@ -32,44 +32,16 @@ class Database(Service):
return self.client.call('post', path, {
}, params)
def list_documents(self, collection_id, filtersstring(4) ""[]""
=[], offset=0, limit=50, order_field='$uid', order_type='ASC', order_cast='string', search='', first=0, last=0):
"""List Documents"""
def get_collection(self, collection_id):
"""Get Collection"""
params = {}
path = '/database/{collectionId}'
path.replace('{collectionId}', collection_id)
params['filters'] = filters
params['offset'] = offset
params['limit'] = limit
params['order-field'] = order_field
params['order-type'] = order_type
params['order-cast'] = order_cast
params['search'] = search
params['first'] = first
params['last'] = last
return self.client.call('get', path, {
}, params)
def create_document(self, collection_id, data, readstring(4) ""[]""
=[], writestring(4) ""[]""
=[], parent_document='', parent_property='', parent_property_type='assign'):
"""Create Document"""
params = {}
path = '/database/{collectionId}'
path.replace('{collectionId}', collection_id)
params['data'] = data
params['read'] = read
params['write'] = write
params['parentDocument'] = parent_document
params['parentProperty'] = parent_property
params['parentPropertyType'] = parent_property_type
return self.client.call('post', path, {
}, params)
def update_collection(self, collection_id, name, readstring(4) ""[]""
=[], writestring(4) ""[]""
=[], rulesstring(4) ""[]""
@ -97,11 +69,49 @@ class Database(Service):
return self.client.call('delete', path, {
}, params)
def list_documents(self, collection_id, filtersstring(4) ""[]""
=[], offset=0, limit=50, order_field='$uid', order_type='ASC', order_cast='string', search='', first=0, last=0):
"""List Documents"""
params = {}
path = '/database/{collectionId}/documents'
path.replace('{collectionId}', collection_id)
params['filters'] = filters
params['offset'] = offset
params['limit'] = limit
params['order-field'] = order_field
params['order-type'] = order_type
params['order-cast'] = order_cast
params['search'] = search
params['first'] = first
params['last'] = last
return self.client.call('get', path, {
}, params)
def create_document(self, collection_id, data, readstring(4) ""[]""
=[], writestring(4) ""[]""
=[], parent_document='', parent_property='', parent_property_type='assign'):
"""Create Document"""
params = {}
path = '/database/{collectionId}/documents'
path.replace('{collectionId}', collection_id)
params['data'] = data
params['read'] = read
params['write'] = write
params['parentDocument'] = parent_document
params['parentProperty'] = parent_property
params['parentPropertyType'] = parent_property_type
return self.client.call('post', path, {
}, params)
def get_document(self, collection_id, document_id):
"""Get Document"""
params = {}
path = '/database/{collectionId}/{documentId}'
path = '/database/{collectionId}/documents/{documentId}'
path.replace('{collectionId}', collection_id)
path.replace('{documentId}', document_id)
@ -114,7 +124,7 @@ class Database(Service):
"""Update Document"""
params = {}
path = '/database/{collectionId}/{documentId}'
path = '/database/{collectionId}/documents/{documentId}'
path.replace('{collectionId}', collection_id)
path.replace('{documentId}', document_id)
params['data'] = data
@ -128,7 +138,7 @@ class Database(Service):
"""Delete Document"""
params = {}
path = '/database/{collectionId}/{documentId}'
path = '/database/{collectionId}/documents/{documentId}'
path.replace('{collectionId}', collection_id)
path.replace('{documentId}', document_id)

View file

@ -29,43 +29,17 @@ module Appwrite
}, params);
end
def list_documents(collection_id:, filters: [], offset: 0, limit: 50, order_field: '$uid', order_type: 'ASC', order_cast: 'string', search: '', first: 0, last: 0)
def get_collection(collection_id:)
path = '/database/{collectionId}'
.gsub('{collection_id}', collection_id)
params = {
'filters': filters,
'offset': offset,
'limit': limit,
'order-field': order_field,
'order-type': order_type,
'order-cast': order_cast,
'search': search,
'first': first,
'last': last
}
return @client.call('get', path, {
}, params);
end
def create_document(collection_id:, data:, read: [], write: [], parent_document: '', parent_property: '', parent_property_type: 'assign')
path = '/database/{collectionId}'
.gsub('{collection_id}', collection_id)
params = {
'data': data,
'read': read,
'write': write,
'parentDocument': parent_document,
'parentProperty': parent_property,
'parentPropertyType': parent_property_type
}
return @client.call('post', path, {
}, params);
end
def update_collection(collection_id:, name:, read: [], write: [], rules: [])
path = '/database/{collectionId}'
.gsub('{collection_id}', collection_id)
@ -92,8 +66,45 @@ module Appwrite
}, params);
end
def list_documents(collection_id:, filters: [], offset: 0, limit: 50, order_field: '$uid', order_type: 'ASC', order_cast: 'string', search: '', first: 0, last: 0)
path = '/database/{collectionId}/documents'
.gsub('{collection_id}', collection_id)
params = {
'filters': filters,
'offset': offset,
'limit': limit,
'order-field': order_field,
'order-type': order_type,
'order-cast': order_cast,
'search': search,
'first': first,
'last': last
}
return @client.call('get', path, {
}, params);
end
def create_document(collection_id:, data:, read: [], write: [], parent_document: '', parent_property: '', parent_property_type: 'assign')
path = '/database/{collectionId}/documents'
.gsub('{collection_id}', collection_id)
params = {
'data': data,
'read': read,
'write': write,
'parentDocument': parent_document,
'parentProperty': parent_property,
'parentPropertyType': parent_property_type
}
return @client.call('post', path, {
}, params);
end
def get_document(collection_id:, document_id:)
path = '/database/{collectionId}/{documentId}'
path = '/database/{collectionId}/documents/{documentId}'
.gsub('{collection_id}', collection_id)
.gsub('{document_id}', document_id)
@ -105,7 +116,7 @@ module Appwrite
end
def update_document(collection_id:, document_id:, data:, read: [], write: [])
path = '/database/{collectionId}/{documentId}'
path = '/database/{collectionId}/documents/{documentId}'
.gsub('{collection_id}', collection_id)
.gsub('{document_id}', document_id)
@ -120,7 +131,7 @@ module Appwrite
end
def delete_document(collection_id:, document_id:)
path = '/database/{collectionId}/{documentId}'
path = '/database/{collectionId}/documents/{documentId}'
.gsub('{collection_id}', collection_id)
.gsub('{document_id}', document_id)

View file

@ -38,7 +38,7 @@ $cli
$clients = [
'php' => [
'version' => 'v1.0.0',
'version' => 'v1.0.1',
'result' => __DIR__ . '/../sdks/php/',
'gitURL' => 'https://github.com/appwrite/sdk-for-php.git',
'gitRepo' => 'git@github.com:appwrite/sdk-for-php.git',
@ -46,7 +46,7 @@ $cli
'gitUserName' => 'appwrite',
],
'js' => [
'version' => 'v1.0.7',
'version' => 'v1.0.8',
'result' => __DIR__ . '/../sdks/js/',
'gitURL' => 'https://github.com/appwrite/sdk-for-js.git',
'gitRepo' => 'git@github.com:appwrite/sdk-for-js.git',
@ -54,7 +54,7 @@ $cli
'gitUserName' => 'appwrite',
],
'node' => [
'version' => 'v1.0.17',
'version' => 'v1.0.18',
'result' => __DIR__ . '/../sdks/node/',
'gitURL' => 'https://github.com/appwrite/sdk-for-node.git',
'gitRepo' => 'git@github.com:appwrite/sdk-for-node.git',