UNPKG

@nativescript/appwrite

Version:
559 lines 15.7 kB
import { Utils } from '@nativescript/core'; export class Client { constructor() { this._native = NSCAppwriteClient.alloc().init(); } setEndpoint(endpoint) { this._native.setEndpoint(endpoint); return this; } setProject(project) { this._native.setProject(project); return this; } setKey(key) { this._native.setKey(key); return this; } setJWT(jwt) { this._native.setJWT(jwt); return this; } setSelfSigned(status) { this._native.setSelfSigned(status); return this; } setSession(session) { this._native.setSession(session); return this; } addHeader(key, value) { this._native.addHeader(key, value); return this; } setForwardedUserAgent(value) { this._native.setForwardedUserAgent(value); return this; } setLocale(value) { this._native.setLocale(value); return this; } get native() { return this._native; } } export class ID { static custom(id) { return NSCAppwriteID.custom(id); } static unique() { return NSCAppwriteID.unique(); } } export class Target { constructor(target) { this._native = target; } get native() { return this._native; } get createdAt() { return this.native.createdAt; } get expired() { return this.native.expired; } get id() { return this.native.id; } get identifier() { return this.native.identifier; } get name() { return this.native.name; } get providerId() { return this.native.providerId; } get providerType() { return this.native.providerType; } get updatedAt() { return this.native.updatedAt; } get userId() { return this.native.userId; } } export class User { constructor(user) { this._native = user; } get native() { return this._native; } get accessedAt() { return this.native.accessedAt; } get createdAt() { return this.native.createdAt; } get email() { return this.native.email; } get emailVerification() { return this.native.emailVerification; } get id() { return this.native.id; } get labels() { return Utils.dataDeserialize(this.native.labels); } get mfa() { return this.native.mfa; } get name() { return this.native.name; } get password() { return this.native.password; } get passwordUpdate() { return this.native.passwordUpdate; } get phone() { return this.native.phone; } get phoneVerification() { return this.native.phoneVerification; } get prefs() { return Utils.dataDeserialize(this.native.prefs); } get registration() { return this.native.registration; } get status() { return this.native.status; } get targets() { const count = this.native.targets.count; const ret = new Array(count); for (let i = 0; i < count; i++) { const target = this.native.targets.objectAtIndex(i); ret[i] = new Target(target); } return ret; } get updatedAt() { return this.native.updatedAt; } get userHash() { return this.native.userHash; } toJSON() { try { const ret = JSON.parse(this.native.toJson()); console.log(ret); return ret; } catch (error) { console.log('Error parsing JSON:', error); return {}; } } } export class Account { constructor(client) { this._native = NSCAppwriteAccount.alloc().initWithClient(client.native); } get native() { return this._native; } create(userId, email, password, name) { return new Promise((resolve, reject) => { this.native.create(userId, email, password, name ?? null, (response, error) => { if (error) { reject(error); } else { resolve(new User(response)); } }); }); } createEmailPasswordSession(email, password) { return new Promise((resolve, reject) => { this.native.createEmailPasswordSession(email, password, (session, error) => { if (error) { reject(error); } else { resolve(new Session(session)); } }); }); } createSession(userId, secret) { return new Promise((resolve, reject) => { this.native.createSession(userId, secret, (session, error) => { if (error) { reject(error); } else { resolve(new Session(session)); } }); }); } createAnonymousSession() { return new Promise((resolve, reject) => { this.native.createAnonymousSession((session, error) => { if (error) { reject(error); } else { resolve(new Session(session)); } }); }); } deleteSession(sessionId) { return new Promise((resolve, reject) => { this.native.deleteSession(sessionId, (error) => { if (error) { reject(error); } else { resolve(); } }); }); } } export class Document { constructor(document) { this._native = document; } get native() { return this._native; } get collectionId() { return this.native.collectionId; } get createdAt() { return this.native.createdAt; } get data() { return Utils.dataDeserialize(this.native.data); } get databaseId() { return this.native.databaseId; } get id() { return this.native.id; } get permissions() { return Utils.dataDeserialize(this.native.permissions); } get updatedAt() { return this.native.updatedAt; } toJSON() { return { collectionId: this.collectionId, createdAt: this.createdAt, data: this.data, databaseId: this.databaseId, id: this.id, permissions: this.permissions, updatedAt: this.updatedAt, }; } } export class Databases { constructor(client) { this._native = NSCAppwriteDatabases.alloc().init(client.native); } get native() { return this._native; } createDocument(databaseId, collectionId, documentId, data = {}, permissions = []) { return new Promise((resolve, reject) => { this.native.createDocument(databaseId, collectionId, documentId, Utils.dataSerialize(data ?? {}, true), Utils.dataSerialize(permissions ?? [], true), (document, error) => { if (error) { reject(error); } else { resolve(new Document(document)); } }); }); } getDocument(databaseId, collectionId, documentId, queries = []) { return new Promise((resolve, reject) => { this.native.getDocument(databaseId, collectionId, documentId, Utils.dataSerialize(queries ?? [], true), (document, error) => { if (error) { reject(error); } else { resolve(new Document(document)); } }); }); } listDocuments(databaseId, collectionId, queries = []) { return new Promise((resolve, reject) => { this.native.listDocuments(databaseId, collectionId, Utils.dataSerialize(queries ?? [], true), (documents, error) => { if (error) { reject(error); } else { const count = documents.count; const ret = new Array(count); for (let i = 0; i < count; i++) { const doc = documents.objectAtIndex(i); ret[i] = new Document(doc); } resolve(ret); } }); }); } updateDocument(databaseId, collectionId, documentId, data, permissions = []) { return new Promise((resolve, reject) => { this.native.updateDocument(databaseId, collectionId, documentId, Utils.dataSerialize(data ?? {}, true), Utils.dataSerialize(permissions ?? [], true), (document, error) => { if (error) { reject(error); } else { resolve(new Document(document)); } }); }); } deleteDocument(databaseId, collectionId, documentId) { return new Promise((resolve, reject) => { this.native.deleteDocument(databaseId, collectionId, documentId, (error) => { if (error) { reject(error); } else { resolve(); } }); }); } } export class Functions { constructor(client) { this._native = NSCAppwriteFunctions.alloc().init(client.native); } get native() { return this._native; } } export class Storage { constructor(client) { this._native = NSCAppwriteStorage.alloc().init(client.native); } get native() { return this._native; } } export class Session { constructor(session) { this._native = session; } get native() { return this._native; } get clientCode() { return this.native.clientCode; } get clientEngine() { return this.native.clientEngine; } get clientEngineVersion() { return this.native.clientEngineVersion; } get clientName() { return this.native.clientName; } get clientType() { return this.native.clientType; } get clientVersion() { return this.native.clientVersion; } get countryCode() { return this.native.countryCode; } get countryName() { return this.native.countryName; } get createdAt() { return this.native.createdAt; } get current() { return this.native.current; } get deviceBrand() { return this.native.deviceBrand; } get deviceModel() { return this.native.deviceModel; } get deviceName() { return this.native.deviceName; } get expire() { return this.native.expire; } get factors() { return Utils.dataDeserialize(this.native.factors); } get id() { return this.native.id; } get ip() { return this.native.ip; } get mfaUpdatedAt() { return this.native.mfaUpdatedAt; } get osCode() { return this.native.osCode; } get osName() { return this.native.osName; } get osVersion() { return this.native.osVersion; } get provider() { return this.native.provider; } get providerAccessToken() { return this.native.providerAccessToken; } get providerAccessTokenExpiry() { return this.native.providerAccessTokenExpiry; } get providerRefreshToken() { return this.native.providerRefreshToken; } get providerUid() { return this.native.providerUid; } get secret() { return this.native.secret; } get updatedAt() { return this.native.updatedAt; } get userId() { return this.native.userId; } toJSON() { return { clientCode: this.clientCode, clientEngine: this.clientEngine, clientEngineVersion: this.clientEngineVersion, clientName: this.clientName, clientType: this.clientType, clientVersion: this.clientVersion, countryCode: this.countryCode, countryName: this.countryName, createdAt: this.createdAt, current: this.current, deviceBrand: this.deviceBrand, deviceModel: this.deviceModel, deviceName: this.deviceName, expire: this.expire, factors: this.factors, id: this.id, ip: this.ip, mfaUpdatedAt: this.mfaUpdatedAt, osCode: this.osCode, osName: this.osName, osVersion: this.osVersion, provider: this.provider, providerAccessToken: this.providerAccessToken, providerAccessTokenExpiry: this.providerAccessTokenExpiry, providerRefreshToken: this.providerRefreshToken, providerUid: this.providerUid, secret: this.secret, updatedAt: this.updatedAt, userId: this.userId, }; } } export class Query { static between(attribute, start, end) { if (typeof start === 'number' && typeof end === 'number') { return NSCAppwriteQuery.betweenStartEnd(attribute, start, end); } return NSCAppwriteQuery.betweenStartSEndS(attribute, start, end); } static contains(attribute, value) { return NSCAppwriteQuery.containsValue(attribute, value); } static cursorAfter(id) { return NSCAppwriteQuery.cursorAfter(id); } static cursorBefore(id) { return NSCAppwriteQuery.cursorBefore(id); } static endsWith(attribute, value) { return NSCAppwriteQuery.endsWithValue(attribute, value); } static equal(attribute, value) { return NSCAppwriteQuery.equalValue(attribute, value); } static greaterThanEqual(attribute, value) { return NSCAppwriteQuery.greaterThanEqualValue(attribute, value); } static greaterThan(attribute, value) { return NSCAppwriteQuery.greaterThanValue(attribute, value); } static isNotNull(attribute) { return NSCAppwriteQuery.isNotNull(attribute); } static isNull(attribute) { return NSCAppwriteQuery.isNull(attribute); } static lessThanEqualWithAttribute(attribute, value) { return NSCAppwriteQuery.lessThanEqualWithAttributeValue(attribute, value); } static lessThan(attribute, value) { return NSCAppwriteQuery.lessThanValue(attribute, value); } static limit(limit) { return NSCAppwriteQuery.limit(limit); } static notEqual(attribute, value) { return NSCAppwriteQuery.notEqualValue(attribute, value); } static offset(offset) { return NSCAppwriteQuery.offset(offset); } static orderAsc(attribute) { return NSCAppwriteQuery.orderAsc(attribute); } static orderDesc(attribute) { return NSCAppwriteQuery.orderDesc(attribute); } static search(attribute, value) { return NSCAppwriteQuery.searchValue(attribute, value); } static select(attributes) { return NSCAppwriteQuery.select(Utils.dataSerialize(attributes, true)); } static startsWith(attribute, value) { return NSCAppwriteQuery.startsWithValue(attribute, value); } } //# sourceMappingURL=index.ios.js.map