export = WOQLClient; /** * @typedef {import('./typedef').NamedResourceData} NamedResourceData */ /** * @license Apache Version 2 * @class * @classdesc The core functionality of the TerminusDB javascript client is * defined in the WOQLClient class - in the woqlClient.js file. This class provides * methods which allow you to directly get and set all of the configuration and API * endpoints of the client. The other parts of the WOQL core - connectionConfig.js * and connectionCapabilities.js - are used by the client to store internal state - they * should never have to be accessed directly. For situations where you want to communicate * with a TerminusDB server API, the WOQLClient class is all you will need. */ declare class WOQLClient { /** * @constructor * @param {string} serverUrl - the terminusdb server url * @param {typedef.ParamsObj} [params] - an object with the connection parameters * @example * //to connect with your local terminusDB * const client = new TerminusClient.WOQLClient(SERVER_URL,{user:"admin",key:"myKey"}) * async function getSchema() { * client.db("test") * client.checkout("dev") * const schema = await client.getSchema() * } * //The client has an internal state which defines what * //organization / database / repository / branch / ref it is currently attached to * * //to connect with your TerminusDB Cloud Instance * const client = new TerminusClient.WOQLClient('SERVER_CLOUD_URL/mycloudTeam', * {user:"myemail@something.com", organization:'mycloudTeam'}) * * client.setApiKey(MY_ACCESS_TOKEN) * * //to get the list of all organization's databases * async function callGetDatabases(){ * const dbList = await client.getDatabases() * console.log(dbList) * } * * async function getSchema() { * client.db("test") * client.checkout("dev") * const schema = await client.getSchema() * } */ constructor(serverUrl: string, params?: typedef.ParamsObj); connectionConfig: any; databaseList: any[]; organizationList: any[]; /** * set the api key to access the cloud resources * @param {string} accessToken */ setApiKey(accessToken: string): void; /** * add extra headers to your request * @param {object} customHeaders * @returns {object} */ customHeaders(customHeaders: any): any; _customHeaders: any; CONST: Readonly<{ POST: "POST"; GET: "GET"; DELETE: "DELETE"; PUT: "PUT"; HEAD: "HEAD"; QUERY_DOCUMENT: "QUERY_DOCUMENT"; SQUASH_BRANCH: "SQUASH_BRANCH"; UPDATE_SCHEMA: "UPDATE_SCHEMA"; CONNECT: "connect"; CREATE_DATABASE: "create_database"; READ_DATABASE: "read_database"; UPDATE_DATABASE: "update_database"; CREATE_USER: "create_user"; READ_USER: "read_user"; UPDATE_USER: "update_user"; CREATE_ORGANIZATION: "create_organization"; READ_ORGANIZATION: "read_organization"; UPDATE_ORGANIZATION: "update_organization"; GET_ROLES: "get_roles"; UPDATE_ROLES: "update_roles"; CREATE_GRAPH: "create_graph"; GET_TRIPLES: "get_triples"; INSERT_TRIPLES: "insert_triples"; UPDATE_TRIPLES: "update_triples"; CLASS_FRAME: "class_frame"; WOQL_QUERY: "woql_query"; CLONE: "clone"; CSV: "csv"; WOQL: "woql"; FRAME: "frame"; PUSH: "push"; PULL: "pull"; FETCH: "fetch"; REBASE: "rebase"; RESET: "reset"; BRANCH: "branch"; REMOTE: "remote"; CREATE_REMOTE: "create_remote"; GET_REMOTE: "get_remote"; UPDATE_REMOTE: "update_remote"; DELETE_REMOTE: "delete_remote"; RESET_BRANCH: "reset_branch"; ADD_CSV: "add_csv"; GET_CSV: "get_csv"; UPDATE_CSV: "update_csv"; MESSAGE: "message"; ACTION: "action"; INFO: "info"; OPTIMIZE_SYSTEM: "optimize_system"; GET_DIFF: "getDiff"; PATCH: "patch"; }>; /** * creates a copy of the client with identical internal state and context * useful if we want to change context for a particular API call without changing * the current client context * @returns {WOQLClient} new client object with identical state to original but * which can be manipulated independently * @example * let newClient = client.copy() */ copy(): import("./woqlClient"); /** * Gets the current connected server url * it can only be set creating a new WOQLCLient instance * @returns {string} */ server(): string; /** * Retrieve the URL of the server’s API base that we are currently connected to * @returns {string} the URL of the TerminusDB server api endpoint we are connected * to (typically server() + “api/”) * @example * let api_url = client.api() */ api(): string; /** * Gets/Sets the client’s internal organization context value, if you change the organization * name the databases list will be set to empty * @param {string | boolean} [orgId] the organization id to set the context to * @returns {string | boolean} * @example * client.organization("admin") */ organization(orgId?: string | boolean): string | boolean; /** * Checks if a database exists * * Returns true if a DB exists and false if it doesn't. Other results * throw an exception. * @param {string} [orgName] the organization id to set the context to * @param {string} [dbName] the db name to set the context to * @returns {Promise} * @example * async function executeIfDatabaseExists(f){ * const hasDB = await client.hasDatabase("admin", "testdb") * if (hasDB) { * f() * } * } */ hasDatabase(orgName?: string, dbName?: string): Promise; /** * Gets the organization's databases list. * * If no organization has been set up, the function throws an exception * @returns {Promise} * @example * async function callGetDatabases(){ * const dbList = await client.getDatabases() * console.log(dbList) * } */ getDatabases(): Promise; /** * Set/Get the organization's databases list (id, label, comment) that the current * user has access to on the server. * @param {array} [dbList] a list of databases the user has access to on the server, each having: * @returns {array} the organization's databases list * @example * //to get the list of all organization's databases * async function callGetDatabases(){ * await client.getDatabases() * console.log(client.databases()) * } * */ databases(dbList?: any[]): any[]; /** * Gets the current user object as returned by the connect capabilities response * user has fields: [id, name, notes, author] * @returns {Object} */ user(): any; /** * @desription Gets the user's organization id * @returns {string} the user organization name */ userOrganization(): string; /** * Gets the database's details * @param {string} [dbName] - the datbase name * @returns {object} the database description object */ databaseInfo(dbName?: string): any; /** * Sets / Gets the current database * @param {string} [dbId] - the database id to set the context to * @returns {string|boolean} - the current database or false * @example * client.db("mydb") */ db(dbId?: string): string | boolean; /** *Sets the internal client context to allow it to talk to the server’s internal system database * */ setSystemDb(): void; /** * Gets / Sets the client’s internal repository context value (defaults to ‘local’) * @param {typedef.RepoType | string} [repoId] - default value is local * @returns {string} the current repository id within the client context * @example * client.repo("origin") */ repo(repoId?: string): string; /** * Gets/Sets the client’s internal branch context value (defaults to ‘main’) * @param {string} [branchId] - the branch id to set the context to * @returns {string} the current branch id within the client context */ checkout(branchId?: string): string; /** * Sets / gets the current ref pointer (pointer to a commit within a branch) * Reference ID or Commit ID are unique hashes that are created whenever a new commit is recorded * @param {string} [commitId] - the reference ID or commit ID * @returns {string|boolean} the current commit id within the client context * @example * client.ref("mkz98k2h3j8cqjwi3wxxzuyn7cr6cw7") */ ref(commitId?: string): string | boolean; /** * Sets/Gets set the database basic connection credential * @param {typedef.CredentialObj} [newCredential] * @returns {typedef.CredentialObj | boolean} * @example * client.localAuth({user:"admin","key":"mykey","type":"basic"}) */ localAuth(newCredential?: typedef.CredentialObj): boolean | typedef.CredentialObj; /** * Use {@link #localAuth} instead. * @deprecated */ local_auth: (newCredential?: typedef.CredentialObj) => boolean | typedef.CredentialObj; /** * Sets/Gets the jwt token for authentication * we need this to connect 2 terminusdb server to each other for push, pull, clone actions * @param {typedef.CredentialObj} [newCredential] * @returns {typedef.CredentialObj | boolean} * @example * client.remoteAuth({"key":"dhfmnmjglkrelgkptohkn","type":"jwt"}) */ remoteAuth(newCredential?: typedef.CredentialObj): boolean | typedef.CredentialObj; /** * Use {@link #remoteAuth} instead. * @deprecated */ remote_auth: (newCredential?: typedef.CredentialObj) => boolean | typedef.CredentialObj; /** * Gets the string that will be written into the commit log for the current user * @returns {string} the current user * @example * client.author() */ author(): string; /** * @param {typedef.ParamsObj} params - a object with connection params * @example sets several of the internal state values in a single call * (similar to connect, but only sets internal client state, does not communicate with server) * client.set({key: "mypass", branch: "dev", repo: "origin"}) */ set(params: typedef.ParamsObj): void; /** * Generates a resource string for the required context * of the current context for "commits" "meta" "branch" and "ref" special resources * @param {typedef.ResourceType} resourceType - the type of resource string that is required - one * of “db”, “meta”, “repo”, “commits”, “branch”, “ref” * @param {string} [resourceId] - can be used to specify a specific branch / ref - if not supplied * the current context will be used * @returns {string} a resource string for the desired context * @example * const branch_resource = client.resource("branch") */ resource(resourceType: typedef.ResourceType, resourceId?: string): string; /** * You can call this to get the server info or override the start params * configuration, this.connectionConfig.server will be used if present, * or the promise will be rejected. * * @deprecated * * @param {typedef.ParamsObj} [params] - TerminusDB Server connection parameters * @returns {Promise} the connection capabilities response object or an error object * @example * client.connect() */ connect(params?: typedef.ParamsObj): Promise; /** * Creates a new database in TerminusDB server * @param {string} dbId - The id of the new database to be created * @param {typedef.DbDetails} dbDetails - object containing details about the database to be created * @param {string} [orgId] - optional organization id - if absent default local organization * id is used * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * //remember set schema:true if you need to add a schema graph * client.createDatabase("mydb", {label: "My Database", comment: "Testing", schema: true}) */ createDatabase(dbId: string, dbDetails: typedef.DbDetails, orgId?: string): Promise; /** * Update a database in TerminusDB server * @param {typedef.DbDoc} dbDoc - object containing details about the database to be updated * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.updateDatabase({id: "mydb", label: "My Database", comment: "Testing"}) */ updateDatabase(dbDoc: typedef.DbDoc): Promise; /** * Deletes a database from a TerminusDB server * @param {string} dbId The id of the database to be deleted * @param {string} [orgId] the id of the organization to which the database belongs * (in desktop use, this will always be “admin”) * @param {boolean} [force] * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.deleteDatabase("mydb") */ deleteDatabase(dbId: string, orgId?: string, force?: boolean): Promise; /** * Retrieve the contents of a graph within a TerminusDB as triples, encoded in * the turtle (ttl) format * @param {typedef.GraphType} graphType - type of graph to get triples from, * either “instance” or “schema” * @returns {Promise} A promise that returns the call response object (with * the contents being a string representing a set of triples in turtle (ttl) format), * or an Error if rejected. * @example * const turtle = await client.getTriples("schema", "alt") */ getTriples(graphType: typedef.GraphType): Promise; /** * Replace the contents of the specified graph with the passed triples encoded * in the turtle (ttl) format * @param {string} graphType - type of graph |instance|schema|inference| * @param {string} turtle - string encoding triples in turtle (ttl) format * @param {string} commitMsg - Textual message describing the reason for the update * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.updateTriples("schema", "alt", turtle_string, "dumping triples to graph alt") */ updateTriples(graphType: string, turtle: string, commitMsg: string): Promise; /** * Appends the passed turtle to the contents of a graph * @param {string} graphType type of graph |instance|schema|inference| * @param {string} turtle is a valid set of triples in turtle format (OWL) * @param {string} commitMsg Textual message describing the reason for the update * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ insertTriples(graphType: string, turtle: string, commitMsg: string): Promise; /** * Sends a message to the server * @param {string} message - textual string * @param {string} [pathname] - a server path to send the message to * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ message(message: string, pathname?: string): Promise; /** * Sends an action to the server * @param {string} actionName - structure of the action * @param {object} [payload] - a request body call * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ action(actionName: string, payload?: any): Promise; /** * Gets TerminusDB Server Information * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.info() */ info(): Promise; /** * Executes a WOQL query on the specified database and returns the results * @param {WOQLQuery} woql - an instance of the WOQLQuery class * @param {string} [commitMsg] - a message describing the reason for the change that will * be written into the commit log (only relevant if the query contains an update) * @param {boolean} [allWitnesses] * @param {string} [lastDataVersion] the last data version tracking id. * @param {boolean} [getDataVersion] If true the function will return object having result * and dataVersion. * @param {Array} [resources] csv resources supplied as strings * @returns {Promise} A promise that returns the call response object or object having *result* * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected. * @example * const result = await client.query(WOQL.star()) */ query(woql: WOQLQuery, commitMsg?: string, allWitnesses?: boolean, lastDataVersion?: string, getDataVersion?: boolean, resources?: typedef.NamedResourceData[]): Promise; /** * Creates a new branch with a TerminusDB database, starting from the current context of * the client (branch / ref) * @param {string} newBranchId - local identifier of the new branch the ID of the new branch * to be created * @param {boolean} [isEmpty] - if isEmpty is true it will create a empty branch. * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.branch("dev") */ branch(newBranchId: string, isEmpty?: boolean): Promise; /** * Squash branch commits * @param {string} branchId - local identifier of the new branch * @param {string} commitMsg - Textual message describing the reason for the update * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ squashBranch(branchId: string, commitMsg: string): Promise; /** * Reset branch to a commit id, Reference ID or Commit ID are unique hashes that are * created whenever a new commit is recorded * @param {string} branchId - local identifier of the new branch * @param {string} commitId - Reference ID or Commit ID * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ resetBranch(branchId: string, commitId: string): Promise; /** * Optimize db branch * @param {string} branchId - local identifier of the new branch * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ optimizeBranch(branchId: string): Promise; /** * Deletes a branch from database * @param {string} branchId - local identifier of the branch * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ deleteBranch(branchId: string): Promise; /** * Pull changes from a branch on a remote database to a branch on a local database * @param {typedef.RemoteRepoDetails} remoteSourceRepo - an object describing the source of the pull * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.pull({remote: "origin", remote_branch: "main", message: "Pulling from remote"}) */ pull(remoteSourceRepo: typedef.RemoteRepoDetails): Promise; /** * Fetch updates to a remote database to a remote repository with the local database * @param {string} remoteId - if of the remote to fetch (eg: 'origin') * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ fetch(remoteId: string): Promise; /** * Push changes from a branch on a local database to a branch on a remote database * @param {typedef.RemoteRepoDetails} remoteTargetRepo - an object describing the target of the push * {remote: "origin", "remote_branch": "main", "author": "admin", "message": "message"} * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.push({remote: "origin", remote_branch: "main", message: "Pulling from remote"}) */ push(remoteTargetRepo: typedef.RemoteRepoDetails): Promise; /** * Merges the passed branch into the current one using the rebase operation * @param {object} rebaseSource - json describing the source branch to be used as a base * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * //from the branch head * client.rebase({rebase_from: "admin/db_name/local/branch/branch_name", message: * "Merging from dev") * //or from a commit id * client.rebase({rebase_from: "admin/db_name/local/commit/9w8hk3y6rb8tjdy961de3i536ntkqd8", * message: "Merging from dev") */ rebase(rebaseSource: any): Promise; /** * Reset the current branch HEAD to the specified commit path * @param {string} commitPath - The commit path to set the current branch to * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ reset(commitPath: string): Promise; /** * Creates a new remote connection for the database * @param {string} remoteName - The name of the remote to create * @param {string} remoteLocation - The URL of the remote repository * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.createRemote("origin", "http://remote.server.com/org/db") */ createRemote(remoteName: string, remoteLocation: string): Promise; /** * Gets information about a remote connection * @param {string} remoteName - The name of the remote to retrieve * @returns {Promise} A promise that returns the remote details, or an Error if rejected. * @example * const remote = await client.getRemote("origin") */ getRemote(remoteName: string): Promise; /** * Updates an existing remote connection * @param {string} remoteName - The name of the remote to update * @param {string} remoteLocation - The new URL for the remote repository * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.updateRemote("origin", "http://new.remote.server.com/org/db") */ updateRemote(remoteName: string, remoteLocation: string): Promise; /** * Deletes a remote connection * @param {string} remoteName - The name of the remote to delete * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.deleteRemote("origin") */ deleteRemote(remoteName: string): Promise; /** * Clones a remote repo and creates a local copy * @param {typedef.CloneSourceDetails} cloneSource - object describing the source branch * to be used as a base * @param {string} newDbId - id of the new cloned database on the local server * @param {string} [orgId] - id of the local organization that the new cloned database * will be created in (in desktop mode this is always “admin”) * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.clonedb({remote_url: "https://my.terminusdb.com/myorg/mydb", label "Cloned DB", comment: "Cloned from mydb"}, newid: "mydb") */ clonedb(cloneSource: typedef.CloneSourceDetails, newDbId: string, orgId?: string): Promise; /** * Common request dispatch function * @property {string} action - the action name * @property {string} apiUrl - the server call endpoint * @property {object} [payload] - the post body * @property {boolean} [getDataVersion] - If true return response with data version * @property {boolean} [compress] - If true, compress the data if it is bigger than 1024 bytes * @returns {Promise} A promise that returns the call response object, or an Error if rejected. */ dispatch(action: any, apiUrl: any, payload: any, getDataVersion: any, compress?: boolean): Promise; /** * Generates the json structure for commit messages * @param {string} msg - textual string describing reason for the change * @param {string} [author] - optional author id string - if absent current user id will be used * @returns {object} */ generateCommitInfo(msg: string, author?: string): any; /** * Generates the json structure for commit descriptor * @param {string} commitId - a valid commit id o */ generateCommitDescriptor(commitId: string): { commit_descriptor: any; }; /** * Adds an author string (from the user object returned by connect) to the commit message. * @param {object} [rc_args] * @returns {object | boolean} */ prepareRevisionControlArgs(rc_args?: any): any; /** * to add a new document or a list of new documents into the instance or the schema graph. * @param {object} json * @param {typedef.DocParamsPost} [params] - the post parameters {@link #typedef.DocParamsPost} * @param {string} [dbId] - the dbid * @param {message} [string] - the insert commit message * @param {string} [lastDataVersion] the last data version tracking id. * @param {boolean} [getDataVersion] If true the function will return object having result * and dataVersion. * @returns {Promise} A promise that returns the call response object or object having *result* * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected. * @example * const json = [{ "@type" : "Class", * "@id" : "Coordinate", * "@key" : { '@type' : 'Hash', * '@fields' : ['x','y'] }, * "x" : "xsd:decimal", * "y" : "xsd:decimal" }, * { "@type" : "Class", * "@id" : "Country", * "@key" : { '@type' : 'Lexical', * '@fields' : [name] }, * "name" : "xsd:string", * "perimeter" : { "@type" : "List", * "@class" : "Coordinate" } }] * client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema documents") * * //if we would like to override the entire schema * const json = [ * {"@base": "terminusdb:///data/", * "@schema": "terminusdb:///schema#", * "@type": "@context" * }, * { * "@id": "Person", * "@key": { * "@type": "Random" * }, * "@type": "Class", * "name": { * "@class": "xsd:string", * "@type": "Optional" * } * }] * * // client.addDocument(json,{"graph_type":"schema","full_replace:true"}, "mydb","update the all schema"); * * // Here we will pass true to show how to get dataVersion * * const response = await client.addDocument(json, {"graph_type": "schema"}, * "mydb", * "add new schema", '', * true * ) * console.log(response); * * // This will output: * // { * // result: [ ...... ], * // dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs' * // } * * // Now we can use the data version we recieved as a response in previous * // function call and used it is next function call as lastDataVersion * * const response1 = await client.addDocument(json, {"graph_type": "schema"}, * "mydb", * "add new schema", response.dataVersion, * ) */ addDocument(json: any, params?: typedef.DocParamsPost, dbId?: string, message?: string, lastDataVersion?: string, getDataVersion?: boolean, compress?: boolean): Promise; /** * Use {@link #getDocument} instead. * @deprecated * * Retrieves all documents that match a given document template * @param {object} query - the query template * @param {typedef.DocParamsGet} [params] - the get parameters * @param {string} [dbId] - the database id * @param {string} [branch] - the database branch * @param {string} [lastDataVersion] the last data version tracking id. * @param {boolean} [getDataVersion] If true the function will return object having result * and dataVersion. * @returns {Promise} A promise that returns the call response object or object having *result* * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected. * @example * const query = { * "type": "Person", * "query": { "age": 42 }, * } * client.queryDocument(query, {"as_list":true}) * * * // Here we will pass true to show how to get dataVersion * const query = { * "type": "Person", * "query": { "age": 42 }, * } * * const response = await client.queryDocument(query, {"as_list": true}, '', '','',true); * console.log(response); * * // This will output: * // { * // result: [ * // { * // '@id': 'Person/052d60ffbd114bf5e7331b03f07fcb7', * // '@type': 'Person', * // age: 42, * // name: 'John', * // }, * // ], * // dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs' * // } * * // Now we can use the data version we recieved as a response in previous * // query and used it is next query as lastDataVersion * const query = { * "type": "Person", * "query": { "age": 18 }, * } * * const response1 = await client.queryDocument(query, {"as_list": true}, '', * '', * response.dataVersion * ); */ queryDocument(query: any, params?: typedef.DocParamsGet, dbId?: string, branch?: string, lastDataVersion?: string, getDataVersion?: boolean): Promise; /** * * @param {typedef.DocParamsGet} [params] - the get parameters, * you can pass document query search template with the params * @param {string} [dbId] - the database id * @param {string} [branch] - the database branch * @param {string} [lastDataVersion] the last data version tracking id. * @param {boolean} [getDataVersion] If true the function will return object having result * and dataVersion. * @param {object} [query] document query search template * @returns {Promise} A promise that returns the call response object or object having *result* * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected. * @example * //return the schema graph as a json array * client.getDocument({"graph_type":"schema","as_list":true}).then(result={ * console.log(result) * }) * * //retutn the Country class document from the schema graph * client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"}).then(result={ * console.log(result) * }) * * //pass a document query template to query the document interface * const queryTemplate = { "name": "Ireland"} * client.getDocument({"as_list":true, "@type":"Country" * query:queryTemplate}).then(result=>{ * console.log(result) * }) * * * // Here we will pass true to show how to get dataVersion * const response = await client.getDocument({"graph_type":"schema","as_list":true}, * "", * "", * "", * true * ) * console.log(response); * * // This will output: * // { * // result: [ ...... ], * // dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs' * // } * * // Now we can use the data version we recieved as a response in previous * // function call and used it is next function call as lastDataVersion * * const response1 = await client.getDocument({"graph_type":"schema","as_list":true}, * "", * "", * response.dataVersion, * ) */ getDocument(params?: typedef.DocParamsGet, dbId?: string, branch?: string, lastDataVersion?: string, getDataVersion?: boolean, query?: any): Promise; /** * * @param {object} json * @param {typedef.DocParamsPut} [params] - the Put parameters {@link #typedef.DocParamsPut} * @param {*} [dbId] - the database id * @param {*} [message] - the update commit message * @param {string} [lastDataVersion] the last data version tracking id. * @param {boolean} [getDataVersion] If true the function will return object having result * and dataVersion. * @param {boolean} [compress] If true, the function will create a new document if it doesn't exist. * @param {boolean} [create] Perform an *upsert* which inserts if the document * is not present (also works on nested documents) * @returns {Promise} A promise that returns the call response object or object having *result* * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected. * @example * client.updateDocument( * { * "@id": "Person", * "@key": { * "@type": "Random", * }, * "@type": "Class", * label: "xsd:string", * }, * { graph_type: "schema" } * ); * * * // Here we will pass true to show how to get dataVersion * const response = await client.updateDocument( { "@id": "Person", "@key": { "@type": "Random", }, "@type": "Class", label: "xsd:string", }, { graph_type: "schema" }, "", "", "", true ); * console.log(response); * * // This will output: * // { * // result: [ ...... ], * // dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs' * // } * * // Now we can use the data version we recieved as a response in previous * // function call and used it is next function call as lastDataVersion * * const response1 = await client.updateDocument( { "@id": "Person", "@key": { "@type": "Random", }, "@type": "Class", label: "xsd:string", }, { graph_type: "schema" }, "", "", response.dataVersion ); * * // update a document and create the linked document together * // we are update the document "Person/Person01" * // and create a new document {"@type": "Person","name": "child01"} at the same time * const response1 = await client.updateDocument( { "@id": "Person/Person01", "@type": "Person", "name": "Person01" "children":[{"@type": "Person","name": "child01"}] },{create:true}) */ updateDocument(json: any, params?: typedef.DocParamsPut, dbId?: any, message?: any, lastDataVersion?: string, getDataVersion?: boolean, compress?: boolean, create?: boolean): Promise; /** * to delete the document * @param {typedef.DocParamsDelete} [params] * @param {string} [dbId] - the database id * @param {string} [message] - the delete message * @param {string} [lastDataVersion] the last data version tracking id. * @param {boolean} [getDataVersion] If true the function will return object having result * and dataVersion. * @returns {Promise} A promise that returns the call response object or object having *result* * and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected. * @example * client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate']}) * * * // Here we will pass true to show how to get dataVersion * * const response = await client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate']}, * "", * "", * "", * true * ) * console.log(response); * * // This will output: * // { * // result: [ ...... ], * // dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs' * // } * * // Now we can use the data version we recieved as a response in previous * // function call and used it is next function call as lastDataVersion * * const response1 = await client.deleteDocument({"graph_type":"schema", * id:['Country','Coordinate']}, * "", * "", * response.dataVersion, * ) */ deleteDocument(params?: typedef.DocParamsDelete, dbId?: string, message?: string, lastDataVersion?: string, getDataVersion?: boolean): Promise; /** * The purpose of this method is to quickly discover the supported fields of a particular type. * @param {string} [type] - If given, the type to get information for. If omitted, information * for all types is returned * @param {string} [dbId] - the database id * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getSchemaFrame("Country") */ getSchemaFrame(type?: string, dbId?: string): Promise; /** * get the database schema in json format * @param {string} [dbId] - the database id * @param {string} [branch] - specific a branch/collection * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getSchema() */ getSchema(dbId?: string, branch?: string): Promise; /** * get all the schema classes (documents,subdocuments,abstracts) * @param {string} [dbId] - the database id * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getClasses() */ getClasses(dbId?: string): Promise; /** * get all the Enum Objects * @param {string} [dbId] * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getEnums() */ getEnums(dbId?: string): Promise; /** * get all the Document Classes (no abstract or subdocument) * @param {string} [dbId] * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getClassDocuments() */ getClassDocuments(dbId?: string): Promise; /** * get the database collections list * @param {string} [dbId] - the database id * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getBranches() */ getBranches(dbId?: string): Promise; /** * get the database collections list * @param {number} [start=0] - where to start printing the commit * information in the log (starting from the head of the current branch) * @param {number} [count=1] - The number of total commit log records to return * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getCommitsLog(count=10) */ getCommitsLog(start?: number, count?: number): Promise; /** * get the database prefixes object * @param {string} [dbId] - the database id * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getPrefixes() * //return object example * { * '@base': 'terminusdb:///data/', * '@schema': 'terminusdb:///schema#', * '@type': 'Context'} */ getPrefixes(dbId?: string): Promise; /** * Get the list of the user's organizations and the database related * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * async funtion callGetUserOrganizations(){ * await getUserOrganizations() * console.log(client.userOrganizations()) * } */ getUserOrganizations(): Promise; /** * Get/Set the list of the user's organizations (id, organization, label, comment). * @param {array} [orgList] a list of user's Organization * @returns {array} the user Organizations list * @example * async funtion callGetUserOrganizations(){ * await client.getUserOrganizations() * console.log(client.userOrganizations()) * } */ userOrganizations(orgList?: any[]): any[]; /** * Apply a patch object to another object * @param {object} before - The current state of JSON document * @param {object} patch - The patch object * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.patch( * { "@id" : "Person/Jane", "@type" : "Person", "name" : "Jane"}, * { "name" : { "@op" : "ValueSwap", "@before" : "Jane", "@after": "Janine" }} * ).then(patchResult=>{ * console.log(patchResult) * }) * //result example * //{ "@id" : "Person/Jane", "@type" : "Person", "name" : "Jannet"} */ patch(before: any, patch: any): Promise; /** * Apply a patch object to the current resource * @param {array} patch - The patch object * @param {string} message - The commit message * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * const patch = [ * { * "@id": "Obj/id1", * "name": { * "@op": "SwapValue", * "@before": "foo", * "@after": "bar" * } * }, * { * "@id": "Obj/id2", * "name": { * "@op": "SwapValue", * "@before": "foo", * "@after": "bar" * } * } * ] * client.db("mydb") * client.checkout("mybranch") * client.patchResource(patch,"apply patch to mybranch").then(patchResult=>{ * console.log(patchResult) * }) * // result example * // ["Obj/id1", * // "Obj/id2"] * // or conflict error 409 * // { * // "@type": "api:PatchError", * // "api:status": "api:conflict", * // "api:witnesses": [ * // { * // "@op": "InsertConflict", * // "@id_already_exists": "Person/Jane" * // } * //] * //} */ patchResource(patch: any[], message: string): Promise; /** * Get the patch of difference between two documents. * @param {object} before - The current state of JSON document * @param {object} after - The updated state of JSON document * @param {object} [options] - {keep:{}} Options to send to the diff endpoint. * The diff api outputs the changes between the input, * in options you can list the properties that you would like to see in the diff result in any case. * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.getJSONDiff( * { "@id": "Person/Jane", "@type": "Person", name: "Jane" }, * { "@id": "Person/Jane", "@type": "Person", name: "Janine" } * ).then(diffResult=>{ * console.log(diffResult) * }) * //result example * //{'@id': 'Person/Jane', * // name: { '@after': 'Janine', '@before': 'Jane', '@op': 'SwapValue' }} */ getJSONDiff(before: any, after: any, options?: any): Promise; /** * Get the patch of difference between two documents. * @param {string} dataVersion - The version from which to compare the object * @param {object} jsonObject - The updated state of JSON document * @param {string} id - The document id to be diffed * @param {object} [options] - {keep:{}} Options to send to the diff endpoint * the diff api outputs the changes between the input, * but you can list the properties that you would like to see in the diff result in any case. * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * const jsonObj = { "@id": "Person/Jane", "@type": "Person", name: "Janine" } * client.getVersionObjectDiff("main",jsonObj * "Person/Jane").then(diffResp=>{ * console.log(diffResp) * }) */ getVersionObjectDiff(dataVersion: string, jsonObject: any, id: string, options?: any): Promise; /** * Get the patch of difference between branches or commits. * @param {string} beforeVersion - Before branch/commit to compare * @param {string} afterVersion - After branch/commit to compare * @param {string} [id] - The document id to be diffed, * if it is omitted all the documents will be compared * @param {typedef.DiffObject} [options] - {keep:{},count:10,start:0} * Options to send to the diff endpoint. * The diff api outputs the changes between the input (branches or commits), * in options you can list the properties that you would like to see in the diff result in any case. * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * //This is to view all the changes between two commits * const beforeCommit = "a73ssscfx0kke7z76083cgswszdxy6l" * const afterCommit = "73rqpooz65kbsheuno5dsayh71x7wf4" * * client.getVersionDiff( beforeCommit, afterCommit).then(diffResult=>{ * console.log(diffResult) * }) * * //This is to view the changes between two commits but only for the given document * client.getVersionDiff( beforeCommit, afterCommit, "Person/Tom").then(diffResult=>{ * console.log(diffResult) * }) * * //This is to view the changes between a branch (head) and a commit for the given document * client.getVersionDiff("main", afterCommit, "Person/Tom" ).then(diffResult=>{ * console.log(diffResult) * }) * * //This is to view the changes between two branches with the keep options * const options = {"keep":{"@id":true, "name": true}, start:0, count:10} * client.getVersionDiff("main","mybranch",options).then(diffResult=>{ * console.log(diffResult) * }) */ getVersionDiff(beforeVersion: string, afterVersion: string, id?: string, options?: typedef.DiffObject): Promise; /** * Diff two different commits and apply changes on the current branch/commit. * If you would like to change branch or commit before apply use client.checkout("branchName") * @param {string} beforeVersion - Before branch/commit to compare * @param {string} afterVersion - After branch/commit to compare * @param {string} message - apply commit message * @param {boolean} [matchFinalState] - the default value is false * @param {object} [options] - {keep:{}} Options to send to the apply endpoint * @example * client.checkout("mybranch") * client.apply("mybranch","mybranch_new","merge main").then(result=>{ * console.log(result) * }) */ apply(beforeVersion: string, afterVersion: string, message: string, matchFinalState?: boolean, options?: any): Promise; /** * Get the document's history for a specific database or branch * @param {string} id - id of document to report history of * @param {typedef.DocHistoryParams} [historyParams] * @example * //this will return the last 5 commits for the Person/Anna document * client.checkout("mybranch") * client.docHistory("Person/Anna",{start:0,count:5}).then(result=>{ * console.log(result) * }) * //this will return the last and the first commit for the Person/Anna document * client.docHistory("Person/Anna",{updated:true,created:true}).then(result=>{ * console.log(result) * }) */ getDocumentHistory(id: string, historyParams?: typedef.DocHistoryParams): Promise; /** * Call a custom Api endpoit * @param {string} requestType - The current state of JSON document * @param {string} customRequestURL - The patch object * @param {object} [payload] - the request payload * @returns {Promise} A promise that returns the call response object, or an Error if rejected. * @example * client.sendCustomRequest("GET", "http://localhost:3030/changes/").then(result=>{ * console.log(result) * }) */ sendCustomRequest(requestType: string, customRequestURL: string, payload?: any): Promise; } declare namespace WOQLClient { export { NamedResourceData }; } import typedef = require("./typedef"); import WOQLQuery = require("./query/woqlCore"); type NamedResourceData = import('./typedef').NamedResourceData;