UNPKG

@harishreddym/baqend

Version:

Baqend JavaScript SDK

886 lines (808 loc) 115 kB
import { Observable, Subscription } from 'rxjs'; /** * The global JSON type. */ export type json = object | any[]; /** * A generic class type. */ export interface Class<T> { new(...args: Array<any>): T; } /** * The global DB object to use. */ export const db: baqend; export default db; /** * <p>Creates a new Acl object, with an empty rule set for an object</p> */ export class Acl { constructor(metadata?: util.Metadata); readonly read: util.Permission; readonly write: util.Permission; /** <p>Removes all acl rules, read and write access is public afterwards</p> */ clear(): void; /** <p>Copies permissions from another ACL</p> */ copy(acl: Acl): Acl; /** <p>Gets whenever all users and roles have the permission to read the object</p> */ isPublicReadAllowed(): boolean; /** <p>Sets whenever all users and roles should have the permission to read the object</p> <p>Note: All other allow read rules will be removed.</p> */ setPublicReadAllowed(): void; /** <p>Checks whenever the user or role is explicit allowed to read the object</p> */ isReadAllowed(userOrRole: model.User | model.Role | string): boolean; /** <p>Checks whenever the user or role is explicit denied to read the object</p> */ isReadDenied(userOrRole: model.User | model.Role | string): boolean; /** <p>Allows the given user or rule to read the object</p> */ allowReadAccess(...userOrRole: (model.User | model.Role | string)[]): Acl; /** <p>Denies the given user or rule to read the object</p> */ denyReadAccess(...userOrRole: (model.User | model.Role | string)[]): Acl; /** <p>Deletes any read allow/deny rule for the given user or role</p> */ deleteReadAccess(...userOrRole: (model.User | model.Role | string)[]): Acl; /** <p>Gets whenever all users and roles have the permission to write the object</p> */ isPublicWriteAllowed(): boolean; /** <p>Sets whenever all users and roles should have the permission to write the object</p> <p>Note: All other allow write rules will be removed.</p> */ setPublicWriteAllowed(): void; /** <p>Checks whenever the user or role is explicit allowed to write the object</p> */ isWriteAllowed(userOrRole: model.User | model.Role | string): boolean; /** <p>Checks whenever the user or role is explicit denied to write the object</p> */ isWriteDenied(userOrRole: model.User | model.Role | string): boolean; /** <p>Allows the given user or rule to write the object</p> */ allowWriteAccess(...userOrRole: (model.User | model.Role | string)[]): Acl; /** <p>Denies the given user or rule to write the object</p> */ denyWriteAccess(...userOrRole: (model.User | model.Role | string)[]): Acl; /** <p>Deletes any write allow/deny rule for the given user or role</p> */ deleteWriteAccess(...userOrRole: (model.User | model.Role | string)[]): Acl; /** <p>A JSON representation of the set of rules</p> */ toJSON(): json; /** <p>Sets the acl rules form JSON</p> */ fromJSON(json: json): void; } export class EntityManager extends util.Lockable { constructor(entityManagerFactory: EntityManagerFactory); readonly isOpen: boolean; token: string; readonly isCachingDisabled: boolean; readonly isDeviceRegistered: boolean; readonly log: util.Logger; readonly entityManagerFactory: EntityManagerFactory; readonly metamodel: metamodel.Metamodel; readonly code: util.Code; readonly modules: util.Modules; readonly me: model.User | null; readonly deviceMe: model.Device | null; readonly tokenStorage: util.TokenStorage; readonly bloomFilter: caching.BloomFilter; readonly bloomFilterRefresh: number; /** <p>Connects this entityManager, used for synchronous and asynchronous initialization</p> */ connected(connector: connector.Connector, connectData: object, tokenStorage: util.TokenStorage): void; /** <p>Get an instance whose state may be lazily fetched</p> <p>If the requested instance does not exist in the database, the<br>EntityNotFoundError is thrown when the instance state is first accessed.<br>The application should not expect that the instance state will be available upon detachment,<br>unless it was accessed by the application while the entity manager was open.</p> */ getReference(entityClass: Class<binding.Entity> | string, key?: string): binding.Entity; /** <p>Creates an instance of {@link query.Builder<T>} for query creation and execution</p> <p>The query results are instances of the resultClass argument.</p> */ createQueryBuilder<T>(resultClass?: Class<T>): query.Builder<T>; /** <p>Clear the persistence context, causing all managed entities to become detached</p> <p>Changes made to entities that have not been flushed to the database will not be persisted.</p> */ clear(): void; /** <p>Close an application-managed entity manager</p> <p>After the close method has been invoked, all methods on the EntityManager instance<br>and any Query and TypedQuery objects obtained from it will throw the IllegalStateError<br>except for transaction, and isOpen (which will return false). If this method<br>is called when the entity manager is associated with an active transaction,<br>the persistence context remains managed until the transaction completes.</p> */ close(): void; /** <p>Check if the instance is a managed entity instance belonging to the current persistence context</p> */ contains(entity: binding.Entity): boolean; /** <p>Check if an object with the id from the given entity is already attached</p> */ containsById(entity: binding.Entity): boolean; /** <p>Remove the given entity from the persistence context, causing a managed entity to become detached</p> <p>Unflushed changes made to the entity if any (including removal of the entity),<br>will not be synchronized to the database. Entities which previously referenced the detached entity will continue<br>to reference it.</p> */ detach(entity: binding.Entity): Promise<binding.Entity>; /** <p>Resolve the depth by loading the referenced objects of the given entity</p> */ resolveDepth(entity: binding.Entity, options?: object): Promise<binding.Entity>; /** <p>Search for an entity of the specified oid</p> <p>If the entity instance is contained in the persistence context, it is returned from there.</p> */ load(entityClass: Class<binding.Entity> | string, oid: String, options?: object): Promise<binding.Entity>; insert(entity: binding.Entity, options: object): Promise<binding.Entity>; update(entity: binding.Entity, options: object): Promise<binding.Entity>; save(entity: binding.Entity, options: object, withoutLock?: boolean): Promise<binding.Entity>; optimisticSave(entity: binding.Entity, cb: Function): Promise<binding.Entity>; /** <p>Returns all referenced sub entities for the given depth and root entity</p> */ getSubEntities(entity: binding.Entity, depth: boolean | number, resolved?: binding.Entity[], initialEntity?: binding.Entity): binding.Entity[]; /** <p>Returns all referenced one level sub entities for the given path</p> */ getSubEntitiesByPath(entity: binding.Entity, path: string[]): binding.Entity[]; /** <p>Delete the entity instance.</p> */ delete(entity: binding.Entity, options: object): Promise<binding.Entity>; /** <p>Synchronize the persistence context to the underlying database.</p> */ flush(): Promise<any>; /** <p>Make an instance managed and persistent.</p> */ persist(entity: binding.Entity): void; /** <p>Refresh the state of the instance from the database, overwriting changes made to the entity, if any.</p> */ refresh(entity: binding.Entity, options: object): Promise<binding.Entity>; /** <p>Attach the instance to this database context, if it is not already attached</p> */ attach(entity: binding.Entity): void; /** <p>Opens a new window use for OAuth logins</p> */ openOAuthWindow(url: string, targetOrTitle: string, options: object): void; registerDevice(devicetype: string, subscription: object, device: model.Device): Promise<model.Device>; /** <p>The given entity will be checked by the validation code of the entity type.</p> */ validate(entity: binding.Entity): util.ValidationResult; /** <p>Adds the given object id to the cacheWhiteList if needed.</p> */ addToWhiteList(objectId: string): void; /** <p>Adds the given object id to the cacheBlackList if needed.</p> */ addToBlackList(objectId: string): void; /** <p>Checks the freshness of the bloom filter and does a reload if necessary</p> */ ensureBloomFilterFreshness(): void; /** <p>Checks for a given id, if revalidation is required, the resource is stale or caching was disabled</p> */ mustRevalidate(id: string): boolean; ensureCacheHeader(id: string, message: connector.Message, refresh: boolean): void; /** <p>Creates a absolute url for the given relative one</p> */ createURL(relativePath: string, authorize?: boolean): string; /** <p>Requests a perpetual token for the given user</p> <p>Only users with the admin role are allowed to request an API token.</p> */ requestAPIToken(entityClass: Class<binding.Entity> | Class<binding.Managed>, user: binding.User | String): Promise<any>; /** <p>Revoke all created tokens for the given user</p> <p>This method will revoke all previously issued tokens and the user must login again.</p> */ revokeAllTokens(entityClass: Class<binding.Entity> | Class<binding.Managed>, user: binding.User | String): Promise<any>; /** <p>Constructor for a new List collection</p> */ List<U>(...args: U[]): U[]; /** <p>Constructor for a new Set collection</p> */ Set<U>(collection?: Iterable<U>): Set<U>; /** <p>Constructor for a new Map collection</p> */ Map(collection?: Iterable<any>): Map<any, any>; /** <p>Constructor for a new GeoPoint</p> */ GeoPoint(latitude?: string | number | number[], longitude?: number): GeoPoint; User: binding.UserFactory; Role: binding.EntityFactory<model.Role>; Device: binding.DeviceFactory; [YourEntityClass: string]: any; File: binding.FileFactory; } /** * <p>Creates a new EntityManagerFactory connected to the given destination</p> */ export class EntityManagerFactory extends util.Lockable { constructor(options?: string | { host?: string, port?: number, secure?: boolean, basePath?: string, schema?: object, tokenStorage?: util.TokenStorage, tokenStorageFactory?: util.TokenStorageFactory, staleness?: number }); connection: connector.Connector; metamodel: metamodel.Metamodel; code: util.Code; tokenStorageFactory: util.TokenStorageFactory; /** <p>Apply additional configurations to this EntityManagerFactory</p> */ configure(options: { tokenStorage?: util.TokenStorage, tokenStorageFactory?: util.TokenStorageFactory, staleness?: number }): void; tokenStorage: util.TokenStorage; staleness: number; /** <p>Connects this EntityManager to the given destination</p> */ connect(hostOrApp: string, port?: number, secure?: boolean, basePath?: string): Promise<this>; /** <p>Connects this EntityManager to the given destination</p> */ connect(hostOrApp: string, secure?: boolean): Promise<this>; /** <p>Creates a new Metamodel instance, which is not connected</p> */ createMetamodel(): metamodel.Metamodel; /** <p>Create a new application-managed EntityManager.</p> */ createEntityManager(useSharedTokenStorage?: boolean): EntityManager; } /** * <p>Creates a new GeoPoint instance<br>From latitude and longitude<br>From a json object<br>Or an tuple of latitude and longitude</p> */ export class GeoPoint { constructor(latitude?: string | number | number[], longitude?: number); /** <p>Creates a GeoPoint with the user's current location, if available.</p> */ static current(): Promise<GeoPoint>; longitude: number; latitude: number; /** <p>Returns the distance from this GeoPoint to another in kilometers.</p> */ kilometersTo(point: GeoPoint): number; /** <p>Returns the distance from this GeoPoint to another in miles.</p> */ milesTo(point: GeoPoint): number; /** <p>Computes the arc, in radian, between two WGS-84 positions.</p> <p>The haversine formula implementation is taken from:<br>{@link http://<a href="http://www.movable-type.co.uk/scripts/latlong.html}">www.movable-type.co.uk/scripts/latlong.html}</a></p> <p>Returns the distance from this GeoPoint to another in radians.</p> */ radiansTo(point: GeoPoint): number; /** <p>A String representation in latitude, longitude format</p> */ toString(): string; /** <p>Returns a JSON representation of the GeoPoint</p> */ toJSON(): json; static DEG_TO_RAD: number; static EARTH_RADIUS_IN_KILOMETERS: number; static EARTH_RADIUS_IN_MILES: number; } export interface baqend extends EntityManager { /** <p>Configures the DB with additional config options</p> */ configure(options: { tokenStorage?: util.TokenStorage, tokenStorageFactory?: util.TokenStorageFactory, staleness?: number }): baqend; /** <p>Connects the DB with the server and calls the callback on success</p> */ connect(hostOrApp: string, secure?: boolean, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: Error) => Promise<any> | any): Promise<EntityManager>; } /** * <p>An event for a real-time query.</p> */ export class RealtimeEvent<T> { constructor(); target: query.Node<T>; data: T; operation: string; matchType: string; initial: boolean; index: number; date: Date; } export namespace binding { /** * <p>Adds a trailing slash to a string if it is missing</p> */ export function trailingSlashIt(str: string): string; export class Accessor { constructor(); getValue(object: object, attribute: metamodel.Attribute): any; setValue(object: object, attribute: metamodel.Attribute, value: any): void; } export interface DeviceFactory extends binding.EntityFactory<model.Device> { readonly me: model.Device; readonly isRegistered: boolean; /** <p>Loads the Public VAPID Key which can be used to subscribe a Browser for Web Push notifications</p> */ loadWebPushKey(): Promise<ArrayBuffer>; /** <p>Register a new device with the given device token and OS.</p> */ register(os: string, tokenOrSubscription: string | Subscription, doneCallback: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.Device>; /** <p>Register a new device with the given device token and OS.</p> */ register(os: string, tokenOrSubscription: string | PushSubscription, device?: model.Device, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.Device>; /** <p>Uses the info from the given {util.PushMessage} message to send an push notification.</p> */ push(pushMessage: util.PushMessage, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Push message will be used to send a push notification to a set of devices</p> */ PushMessage(devices?: Set<binding.Entity> | binding.Entity[], message?: string, subject?: string, sound?: string, badge?: number, data?: object): util.PushMessage; } export class Enhancer { constructor(); createProxy(superClass: Class<any>): Class<any>; static getBaqendType(typeConstructor: Class<any>): metamodel.ManagedType; static getIdentifier(typeConstructor: Class<any>): string; static setIdentifier(typeConstructor: Class<any>, identifier: string): void; enhance(type: metamodel.ManagedType, typeConstructor: Class<any>): void; /** <p>Enhance the prototype of the type</p> */ enhancePrototype(proto: object, type: metamodel.ManagedType): void; enhanceProperty(proto: object, attribute: metamodel.Attribute): void; } export class Entity extends binding.Managed { constructor(); id: string; key: string; readonly version: number; readonly acl: Acl; readonly createdAt: Date; readonly updatedAt: Date; /** <p>Waits on the previously requested operation on this object completes</p> */ ready(doneCallback?: (entity: this) => Promise<any> | any): Promise<this>; /** <p>Attach this object to the given db</p> */ attach(db: EntityManager): void; /** <p>Saves the object. Inserts the object if it doesn't exists and updates the object if the object exist.</p> */ save(options?: { force?: boolean, depth?: number | boolean, refresh?: boolean }, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<this>; /** <p>Inserts a new object. Inserts the object if it doesn't exists and raise an error if the object already exist.</p> */ insert(options?: { depth?: number | boolean, refresh?: boolean }, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<this>; /** <p>Updates an existing object</p> <p>Updates the object if it exists and raise an error if the object doesn't exist.</p> */ update(options?: { force?: boolean, depth?: number | boolean, refresh?: boolean }, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<this>; /** <p>Resolves the referenced object in the specified depth</p> <p>Only unresolved objects will be loaded unless the refresh option is specified.</p> <p>Removed objects will be marked as removed.</p> */ load(options?: { depth?: number | boolean, refresh?: boolean }, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<this>; /** <p>Deletes an existing object</p> */ delete(options?: { force?: boolean, depth?: number | boolean }, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<this>; /** <p>Saves the object and repeats the operation if the object is out of date</p> <p>In each pass the callback will be called. Ths first parameter of the callback is the entity and the second one<br>is a function to abort the process.</p> */ optimisticSave(cb: Function, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<this>; /** <p>Validates the entity by using the validation code of the entity type</p> */ validate(): util.ValidationResult; /** <p>Starts a partial update on this entity</p> */ partialUpdate(operations?: json): partialupdate.EntityPartialUpdateBuilder<this>; /** <p>Get all objects which refer to this object</p> */ getReferencing(options?: { classes?: string[] }): Promise<binding.Entity>; /** <p>Converts the object to an JSON-Object</p> */ toJSON(options?: boolean | { excludeMetadata?: boolean, depth?: number | boolean }): json; } export interface EntityFactory<T> extends binding.ManagedFactory<T> { /** <p>Loads the instance for the given id, or null if the id does not exists.</p> */ load(id: string, options?: { depth?: number | boolean, refresh?: boolean, local?: boolean }, doneCallback?: (entity: T) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<T>; /** <p>Gets an unloaded reference for the given id.</p> */ ref(id: string): T; /** <p>Creates a new instance and sets the DatabaseObject to the given json</p> */ fromJSON(json: json): T; /** <p>Creates a new query for this class</p> */ find(): query.Builder<T>; /** <p>Creates a new partial update for this class</p> */ partialUpdate(id: string, partialUpdate?: json): partialupdate.EntityPartialUpdateBuilder<T>; } /** * <p>This factory creates instances of type T, by invoking the {@link #new()} method<br>or by instantiating this factory directly</p> */ export interface Factory<T> { /** <p>Creates a new instance of the factory type</p> */ new(...args: any[]): T; /** <p>Creates a new instance of the factory type</p> */ newInstance(args?: any[]): T; } /** * <p>Creates a file object, which represents one specific file reference.<br>This File object can afterwards be used to up- and download the file contents or to retrieves and change the files<br>metadata.</p> * <p>The file data can be uploaded and downloaded as:</p> * <table class="table"><br> <tr><br> <th>type</th><br> <th>JavaScript type</th><br> <th>Description</th><br> </tr><br> <tr><br> <td>'arraybuffer'</td><br> <td>ArrayBuffer</td><br> <td>The content is represented as a fixed-length raw binary data buffer</td><br> </tr><br> <tr><br> <td>'blob'</th><br> <td>Blob</td><br> <td>The content is represented as a simple blob</td><br> </tr><br> <tr><br> <td>'json'</td><br> <td>object|array|string</td><br> <td>The file content is represented as json</td><br> </tr><br> <tr><br> <td>'text'</td><br> <td>string</td><br> <td>The file content is represented through the string</td><br> </tr><br> <tr><br> <td>'base64'</td><br> <td>string</td><br> <td>The file content as base64 encoded string</td><br> </tr><br> <tr><br> <td>'data-url'</td><br> <td>string</td><br> <td>A data url which represents the file content</td><br> </tr><br></table> */ export class File { constructor(fileOptions: string | { id?: string, name?: string, parent?: string, path?: string, data: string | Blob | File | ArrayBuffer | json, type?: string, mimeType?: string, size?: number, eTag?: string, lastModified: string | Date, acl?: Acl, headers?: { [key: string]: string } }); readonly id: string; readonly url: string; readonly name: string; readonly mimeType: string; readonly acl: Acl; readonly lastModified?: Date; readonly createdAt?: Date; readonly eTag: string; readonly headers: { [key: string]: string }; readonly size: number; readonly bucket: string; readonly key: string; readonly path: string; readonly parent: string; readonly isMetadataLoaded: boolean; readonly isFolder: boolean; /** <p>Parses an E-Tag header</p> */ static parseETag(eTag?: string): string; /** <p>Uploads the file content which was provided in the constructor or by uploadOptions.data</p> */ upload(uploadOptions?: { data?: string | Blob | File | ArrayBuffer | json, type?: string, mimeType?: string, eTag?: string, lastModified?: string, acl?: Acl, headers?: { [key: string]: string }, force?: boolean, progress?: (event: ProgressEvent) => any }, doneCallback?: (file: binding.File) => any, failCallback?: (error: error.PersistentError) => any): Promise<binding.File>; /** <p>Download a file and providing it in the requested type</p> */ download(downloadOptions?: { type?: string, refresh?: string }, doneCallback?: (data: string | Blob | File | ArrayBuffer | json) => any, failCallback?: (error: error.PersistentError) => any): Promise<(string|Blob|File|ArrayBuffer|json)>; /** <p>Deletes a file</p> */ delete(deleteOptions?: { force?: boolean }, doneCallback?: (data: binding.File) => any, failCallback?: (error: error.PersistentError) => any): Promise<(binding.File|Array<binding.File>)>; /** <p>Makes the given message a conditional request based on the file metadata</p> */ conditional(msg: connector.Message, options: { force?: boolean }): void; /** <p>Gets the file metadata of a file</p> */ loadMetadata(options?: { refresh?: boolean }, doneCallback?: (file: binding.File) => any, failCallback?: (error: error.PersistentError) => any): Promise<binding.File>; /** <p>Updates the matadata of this file.</p> */ saveMetadata(options?: { force?: boolean }, doneCallback?: (file: binding.File) => any, failCallback?: (error: error.PersistentError) => any): Promise<binding.File>; /** <p>Deserialize the given JSON file metadata back to this file instance</p> <p>If the JSON object contains an ID, it must match with this file ID, otherwise an exception is thrown.</p> */ fromJSON(json: json): void; /** <p>Serialize the file metadata of this object to json</p> */ toJSON(): json; /** <p>Checks whenever metadata are already loaded of the file, throws an error otherwise</p> */ checkAvailable(): void; } export interface FileFactory extends binding.Factory<binding.File> { /** <p>Creates a new FileFactory for the given type</p> */ create(db: EntityManager): binding.FileFactory; /** <p>Creates a new file</p> */ newInstance(args?: any[]): binding.File; /** <p>Deserialize the file metadata from a json object back to a new file instance</p> */ fromJSON(json: json): binding.File; /** <p>Updates the metadata of the root file directory formally the file &quot;bucket&quot;</p> */ saveMetadata(bucket: string, metadata: { [key: string]: util.Permission } | { load?: util.Permission, insert?: util.Permission, update?: util.Permission, delete?: util.Permission, query?: util.Permission }, doneCallback?: (bucketMetadata: { [key: string]: util.Permission }) => any, failCallback?: (error: error.PersistentError) => any): Promise<void>; /** <p>Gets the metadata of the root folder (formally the file &quot;bucket&quot;)</p> */ loadMetadata(bucket: string, options?: { refresh?: object }, doneCallback?: (bucketMetadata: { [key: string]: util.Permission }) => any, failCallback?: (error: error.PersistentError) => any): Promise<{ [key: string]: util.Permission }>; /** <p>Lists all the buckets.</p> */ listBuckets(doneCallback?: (files: binding.File[]) => any, failCallback?: (error: error.PersistentError) => any): Promise<binding.File[]>; /** <p>Lists the files (and folders) in the given folder.</p> */ listFiles(folderOrPath: binding.File | string, start: binding.File, count: number, doneCallback?: (files: binding.File[]) => any, failCallback?: (error: error.PersistentError) => any): Promise<binding.File[]>; /** <p>Creates a new file object which represents the file at the given ID</p> <p>Data provided to the constructor will be uploaded by invoking {@link upload()}.</p> */ new(fileOptions: string | { name?: string, parent?: string, data: string | Blob | File | ArrayBuffer | json, type?: string, mimeType?: string, eTag?: string, lastModified?: string, acl?: Acl, headers?: { [key: string]: string } }): binding.File; } /** * <p>The default constructor, copy all given properties to this object</p> */ export class Managed { constructor(properties?: { [key: string]: any }); /** <p>Initialize the given instance</p> */ static init(instance: binding.Managed, properties?: { [key: string]: any }): void; /** <p>Creates a subclass of this class</p> */ static extend(childClass: Class<any>): Class<any>; /** <p>Converts the managed object to an JSON-Object.</p> */ toJSON(): json; } export interface ManagedFactory<T> extends binding.Factory<T> { /** <p>Creates a new instance of the factory type</p> */ newInstance(args?: any[]): T; /** <p>Creates a new instance and sets the Managed Object to the given json</p> */ fromJSON(json: json): T; /** <p>Adds methods to instances of this factories type</p> */ addMethods(methods: { [key: string]: Function }): void; /** <p>Add a method to instances of this factories type</p> */ addMethod(name: string, fn: Function): void; methods: { [key: string]: Function }; readonly managedType: metamodel.ManagedType; readonly db: EntityManager; /** <p>Creates a new instance of the of this type</p> */ new(properties: { [key: string]: any }): T; } export class Role extends binding.Entity { constructor(); /** <p>Test if the given user has this role</p> */ hasUser(user: model.User): boolean; /** <p>Add the given user to this role</p> */ addUser(user: model.User): void; /** <p>Remove the given user from this role</p> */ removeUser(user: model.User): void; users: Set<model.User>; name: string; } export class User extends binding.Entity { constructor(); /** <p>Change the password of the given user</p> */ newPassword(currentPassword: string, password: string, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Change the username of the current user</p> */ changeUsername(newUsername: string, password: string, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Requests a perpetual token for the user</p> <p>Only users with the admin role are allowed to request an API token.</p> */ requestAPIToken(doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; username: string; inactive: boolean; } export interface UserFactory extends binding.EntityFactory<model.User> { readonly me: model.User; /** <p>Register a new user with the given username and password, if the username is not used by an another user.</p> */ register(user: string | model.User, password: string, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Log in the user with the given username and password and starts a user session</p> */ login(username: string, password: string, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Log in the user assiciated with the given token and starts a user session.</p> */ loginWithToken(token: string, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Log out the current logged in user and ends the active user session</p> */ logout(doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Change the password of the given user</p> */ newPassword(username: string, password: string, newPassword: string, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Sends an email with a link to reset the password for the given username</p> <p>The username must be a valid email address.</p> */ resetPassword(username: string, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Sends an email with a link to change the current username</p> <p>The user is identified by their current username and password.<br>The username must be a valid email address.</p> */ changeUsername(username: string, newUsername: string, password: string, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Requests a perpetual token for the given user</p> <p>Only users with the admin role are allowed to request an API token.</p> */ requestAPIToken(user: binding.User | String, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Revoke all created tokens for the given user</p> <p>This method will revoke all previously issued tokens and the user must login again.</p> */ revokeAllTokens(user: binding.User | String, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<any>; /** <p>Change the password of a user, which will be identified by the given token from the reset password e-mail</p> */ newPassword(token: string, newPassword: string, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Logs the user in with Google via OAuth</p> <p>Prompts the user for the Google login in a new window. Before using OAuth you need to setup your application<br>on the provider website, add the redirect uri: <code>https://example.net/db/User/OAuth/google</code> and copy the<br>client id and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is<br>logged in.</p> */ loginWithGoogle(clientID: string, options?: { title?: string, width?: number, height?: number, scope?: string, state?: object, timeout?: number, redirect?: string }, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Logs the user in with Facebook via OAuth</p> <p>Prompts the user for the Facebook login in a new window. Before using OAuth you need to setup your application<br>on the provider website, add the redirect uri: https://example.net/db/User/OAuth/facebook and copy the client id<br>and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.</p> */ loginWithFacebook(clientID: string, options?: { title?: string, width?: number, height?: number, scope?: string, state?: object, timeout?: number, redirect?: string }, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Logs the user in with GitHub via OAuth</p> <p>Prompts the user for the GitHub login in a new window. Before using OAuth you need to setup your application<br>on the provider website, add the redirect uri: https://example.net/db/User/OAuth/github and copy the client id<br>and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.</p> */ loginWithGitHub(clientID: string, options?: { title?: string, width?: number, height?: number, scope?: string, state?: object, timeout?: number, redirect?: string }, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Logs the user in with Twitter via OAuth</p> <p>Prompts the user for the Twitter login in a new window. Before using OAuth you need to setup your application<br>on the provider website, add the redirect uri: https://example.net/db/User/OAuth/twitter and copy the client id<br>and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.</p> */ loginWithTwitter(clientID: string, options?: { title?: string, width?: number, height?: number, timeout?: number, redirect?: string }, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Logs the user in with LinkedIn via OAuth</p> <p>Prompts the user for the LinkedIn login in a new window. Before using OAuth you need to setup your application<br>on the provider website, add the redirect uri: https://example.net/db/User/OAuth/linkedin and copy the client id<br>and the client secret to your Baqend dashboard settings. When the returned promise succeeds the user is logged in.</p> */ loginWithLinkedIn(clientID: string, options?: { title?: string, width?: number, height?: number, scope?: string, state?: object, timeout?: number, redirect?: string }, loginOption?: boolean | binding.UserFactory.LoginOption, doneCallback?: (entity: this) => Promise<any> | any, failCallback?: (error: error.PersistentError) => Promise<any> | any): Promise<model.User>; /** <p>Creates a new user object</p> */ new(properties: { [key: string]: any }): model.User; } export namespace UserFactory { export enum LoginOption { NO_LOGIN = -1, SESSION_LOGIN = 0, PERSIST_LOGIN = 1, } } } export namespace caching { /** * <p>A Bloom Filter is a client-side kept cache sketch of the server cache</p> */ export class BloomFilter { constructor(bloomFilter: { m: number, h: number, b: string }); readonly bytes: string; readonly bits: number; readonly hashes: number; readonly creation: number; /** <p>Returns whether this Bloom filter contains the given element.</p> */ contains(element: string): boolean; } } export namespace connector { export class Connector { constructor(host: string, port: number, secure: boolean, basePath: string); static create(host: string, port?: number, secure?: boolean, basePath?: string): connector.Connector; readonly host: string; readonly port: number; readonly secure: boolean; readonly basePath: string; readonly origin: string; send(message: connector.Message): Promise<connector.Message>; prepareRequest(message: connector.Message): void; /** <p>Convert the message entity to the sendable representation</p> */ toFormat(message: connector.Message): void; prepareResponse(message: connector.Message, response: object): Promise<any>; /** <p>Convert received data to the requested response entity type</p> */ fromFormat(response: object, entity: any, type: string): any; static RESPONSE_HEADERS: string[]; static connectors: connector.Connector[]; static connections: { [key: string]: connector.Connector }; } export class FetchConnector extends connector.Connector { constructor(); /** <p>Indicates if this connector implementation is usable for the given host and port</p> */ static isUsable(): boolean; } export class IFrameConnector extends connector.XMLHttpConnector { constructor(); /** <p>Indicates if this connector implementation is usable for the given host and port</p> */ static isUsable(host: string, port: number, secure: boolean): boolean; } export class Message { constructor(); /** <p>Creates a new message class with the given message specification</p> */ static create(specification: object): Class<Message>; /** <p>Creates a new message class with the given message specification and a full path</p> */ static createExternal(specification: object, members: object): Class<Message>; withCredentials: boolean; tokenStorage: util.TokenStorage; progressCallback: (event: ProgressEvent) => any; /** <p>Gets the value of a the specified request header</p> */ header(name: string): string; /** <p>Sets the value of a the specified request header</p> */ header(name: string, value: string): this; /** <p>Sets the entity type</p> */ entity(data: any, type?: 'json' | 'text' | 'blob' | 'buffer' | 'arraybuffer' | 'data-url' | 'form'): this; /** <p>Get the mimeType</p> */ mimeType(): string; /** <p>Sets the mimeType</p> */ mimeType(mimeType: string): this; /** <p>Gets the contentLength</p> */ contentLength(): number; /** <p>Sets the contentLength</p> */ contentLength(contentLength: number): this; /** <p>Gets the request conditional If-Match header</p> */ ifMatch(): string; /** <p>Sets the request conditional If-Match header</p> */ ifMatch(eTag: string): this; /** <p>Gets the request a ETag based conditional header</p> */ ifNoneMatch(): string; /** <p>Sets the request a ETag based conditional header</p> */ ifNoneMatch(eTag: string): this; /** <p>Gets the request date based conditional header</p> */ ifUnmodifiedSince(): string; /** <p>Sets the request date based conditional header</p> */ ifUnmodifiedSince(date: Date): this; /** <p>Indicates that the request should not be served by a local cache</p> */ noCache(): this; /** <p>Gets the cache control header</p> */ cacheControl(): string; /** <p>Sets the cache control header</p> */ cacheControl(value: string): this; /** <p>Gets the ACL of a file into the Baqend-Acl header</p> */ acl(): string; /** <p>Sets and encodes the ACL of a file into the Baqend-Acl header</p> */ acl(acl: Acl): this; /** <p>Gets and encodes the custom headers of a file into the Baqend-Custom-Headers header</p> */ customHeaders(): string; /** <p>Sets and encodes the custom headers of a file into the Baqend-Custom-Headers header</p> */ customHeaders(customHeaders: any): this; /** <p>Gets the request accept header</p> */ accept(): string; /** <p>Sets the request accept header</p> */ accept(accept: string): this; /** <p>Gets the response type which should be returned</p> */ responseType(): string; /** <p>Sets the response type which should be returned</p> */ responseType(type: string): this; /** <p>Gets the progress callback</p> */ progress(): (event: ProgressEvent) => any; /** <p>Sets the progress callback</p> */ progress(callback: (event: ProgressEvent) => any): this; /** <p>Adds the given string to the request path</p> <p>If the parameter is an object, it will be serialized as a query string.</p> */ addQueryString(query: string | { [key: string]: string }): this; /** <p>Handle the receive</p> */ doReceive(response: object): void; spec: object; } export class NodeConnector extends connector.Connector { constructor(); /** <p>Parse the cookie header</p> */ parseCookie(header: string): string | null; } export class XMLHttpConnector extends connector.Connector { constructor(); /** <p>Indicates if this connector implementation is usable for the given host and port</p> */ static isUsable(host: string, port: number, secure: boolean): boolean; } export class WebSocketConnector { constructor(url: String); static create(connector: connector.Connector, url?: String): connector.WebSocketConnector; openStream(tokenStorage: util.TokenStorage, id: string): connector.ObservableStream; static websockets: connector.Connector[]; } export class ObservableStream extends Observable<connector.ChannelMessage> { constructor(); /** <p>Sends a message</p> */ send(The: connector.ChannelMessage): any; } export interface ChannelMessage { id: string; type: string; date: Date; } export namespace Message { export enum StatusCode { NOT_MODIFIED = 304, BAD_CREDENTIALS = 460, BUCKET_NOT_FOUND = 461, INVALID_PERMISSION_MODIFICATION = 462, INVALID_TYPE_VALUE = 463, OBJECT_NOT_FOUND = 404, OBJECT_OUT_OF_DATE = 412, PERMISSION_DENIED = 466, QUERY_DISPOSED = 467, QUERY_NOT_SUPPORTED = 468, SCHEMA_NOT_COMPATIBLE = 469, SCHEMA_STILL_EXISTS = 470, SYNTAX_ERROR = 471, TRANSACTION_INACTIVE = 472, TYPE_ALREADY_EXISTS = 473, TYPE_STILL_REFERENCED = 474, SCRIPT_ABORTION = 475, } } } export namespace error { export class CommunicationError extends error.PersistentError { constructor(httpMessage: connector.Message, response: object); name: string; reason: string; status: number; } export class EntityExistsError extends error.PersistentError { constructor(entity: string); entity: binding.Entity; } export class IllegalEntityError extends error.PersistentError { constructor(entity: binding.Entity); entity: binding.Entity; } export class PersistentError extends Error { constructor(message: string, cause?: Error); } export class RollbackError extends error.PersistentError { constructor(cause: Error); } } export namespace message { /** * <p>Get the list of all available subresources</p> */ export class ListAllResources extends connector.Message { constructor(); } /** * <p>Get the API version of the Orestes-Server</p> */ export class ApiVersion extends connector.Message { constructor(); } /** * <p>The Swagger specification of the Orestes-Server</p> */ export class Specification extends connector.Message { constructor(); } /** * <p>Returns all changed objects</p> */ export class GetBloomFilter extends connector.Message { constructor(); } /** * <p>Clears the Bloom filter (TTLs and stale entries)</p> */ export class DeleteBloomFilter extends connector.Message { constructor(); } /** * <p>Get the current Orestes config</p> */ export class GetOrestesConfig extends connector.Message { constructor(); } /** * <p>Updates the current Orestes config</p> */ export class UpdateOrestesConfig extends connector.Message { constructor(body: json); } /** * <p>Connects a browser to this server</p> */ export class Connect extends connector.Message { constructor(); } /** * <p>Gets the status of the server health</p> */ export class Status extends connector.Message { constructor(); } /** * <p>Gets the event Endpoint</p> */ export class EventsUrl extends connector.Message { constructor(); } /** * <p>Determines whether the IP has exceeded its rate limit</p> */ export class BannedIp extends connector.Message { constructor(ip: string); } /** * <p>Always returns banned status for proper CDN handling</p> */ export class Banned extends connector.Message { constructor(); } /** * <p>Clears all rate-limiting information for all IPs</p> */ export class Unban extends connector.Message { constructor(); } /** * <p>Clears rate-limiting information for given IPs</p> */ export class UnbanIp extends connector.Message { constructor(ip: string); } /** * <p>List all bucket names<br>List all buckets</p> */ export class GetBucketNames extends connector.Message { constructor(); } /** * <p>List objects in bucket<br>List all object ids of the given bucket</p> */ export class GetBucketIds extends connector.Message { constructor(bucket: string, start: number, count: number); } /** * <p>Dump objects of bucket<br>Exports the complete data set of the bucket</p> */ export class ExportBucket extends connector.Message { constructor(bucket: string); } /** * <p>Upload all objects to the bucket<br>Imports the complete data set. For large uploads, this call will always return the status code 200.<br>If failures occur, they will be returned in the response body.</p> */ export class ImportBucket extends connector.Message { constructor(bucket: string, body: json); } /** * <p>Delete all objects in bucket<br>Delete all objects in the given bucket</p> */ export class TruncateBucket extends connector.Message { constructor(bucket: string); } /** * <p>Create object<br>Create the given object.<br>The created object will get a unique id.</p> */ export class CreateObject extends connector.Message { constructor(bucket: string, body: json); } /** * <p>Get object<br>Returns the specified object. Each object has one unique identifier and therefore only one URL.</p> */ export class GetObject extends connector.Message { constructor(bucket: string, oid: string); } /** * <p>Replace object<br>Replace the current object with the updated one.<br>To update a specific version of the object a version can be provided in the If-Match header.<br>The update will only be accepted, if the current version matches the provided one, otherwise the update<br>will be rejected.<br>The * wildcard matches any existing object but prevents an insertion if the object does not exist.</p> */ export class ReplaceObject extends connector.Message { constructor(bucket: string, oid: string, body: json); } /** * <p>Delete object<br>Deletes the object. The If-Match Header can be used to specify an expected version. The object will<br>only be deleted if the version matches the provided one. The * wildcard can be used to match any existing<br>version but results in an error if the object does not exist.</p> */ export class DeleteObject extends connector.Message { constructor(bucket: string, oid: string); } /** * <p>Get all available class schemas<br>Gets the complete schema</p> */ export class GetAllSchemas extends connector.Message { constructor(); } /** * <p>Create new class schemas and update existing class schemas<br>Updates the complete schema, merge all changes, reject the schema update if the schema changes aren't compatible</p> */ export class UpdateAllSchemas extends connector.Message { constructor(body: json); } /** * <p>Replace all currently created schemas with the new ones<br>Replace the complete schema, with the new one.</p> */ export class ReplaceAllSchemas extends connector.Message { constructor(body: json); } /** * <p>Get the class schema<br>Returns the schema definition of the class<br>The class definition contains a link to its parent class and all persistable fields with there types of the class</p> */ export class GetSchema extends connector.Message { constructor(bucket: string); } /** * <p>Update the class schema<br>Modify the schema definition of the class by adding all missing fields</p> */ export class UpdateSchema extends connector.Message { constructor(bucket: string, body: json); } /** * <p>Replace the class schema<br>Replace the schema definition of the class</p> */