UNPKG

amazon-qldb-kvs-nodejs

Version:

A helper module, simplifying basic interactions with Amazon Quantum Ledger Database for Node.js through a simple key-value store interface.

122 lines (121 loc) 7.09 kB
/// <reference types="node" /> import { QldbDriver } from "amazon-qldb-driver-nodejs"; import { GetDigestCommandOutput, QLDB } from "@aws-sdk/client-qldb"; import { LedgerMetadata } from "./GetMetadata"; import { UpsertResult } from "./UpsertDocument"; export declare class QLDBKVS { qldbDriver: QldbDriver; ledgerName: string; tableName: string; tableState: string; /** * Initialize QLDBKVS object * @param ledgerName A name of QLDB ledger to use * @param tableName A name of QLDB table * @param checkForTable A boolean value to check table if table exists and create if it is not exests (dafault=true) * @param maxConcurrentTransactions The driver internally uses a pool of sessions to execute the transactions. * The maxConcurrentTransactions parameter specifies the number of sessions that the driver can hold in the pool. * @returns {QLDBKVS} initialized */ constructor(ledgerName: string, tableName: string, checkForTable?: boolean, maxConcurrentTransactions?: number); /** * Verify that table exists and create it if it doesn't * @param tableName string The name of the table * @returns A promise with "true" if table exists * @throws Error: If error happen during the process. */ private assureTableExists; /** * Download a value as a file to the local file system * @param key A value of a key attribute to retrieve the document. * @param localFilePath A path on a local file system where to store the result file * @returns A promise with a path to a new file, retrieved from QLDB. * @throws Error: If error happen during the process. */ downloadAsFile(key: string, localFilePath: string): Promise<string>; /** * Upload file to QLDB as utf8 buffer (blob) * @param key A value of a key attribute. * @param filePath A path to a file on a local file system. * @returns A promise with an object containing a document Id and transaction Id * @throws Error: If error happen during the process. */ uploadAsFile(key: string, filePath: string): Promise<UpsertResult>; /** * Get value for a corresponding key as JSON object * @param key A value of a key attribute to retrieve the record from. * @param withVersionNumber If true, return the value along with it's version number from the ledger * @returns Promise with a value object as JSON. */ getValue(key: string, withVersionNumber?: boolean): Promise<object | Buffer>; /** * Get values by array of keys * @param keys An array of values of key attribute to retrieve the record from. * @param withVersionNumbers If true, returns values along with their version numbers from the ledger * @returns Promise with an array of value objects as JSON. */ getValues(keys: string[], withVersionNumbers?: boolean): Promise<object[] | Buffer[]>; /** * Put a JSON object to QLDB as a key/value record * @param key A value of a key attribute to save the record with. * @param value A value of a value attribute to save the record with. If it's not a string, it will be converted to Amazon Ion before submitting to the ledger. * @param version number (OPTIONAL) The versions of the document to make sure we update the right version. Function will return an error if the most recent version in the ledger is different. * @returns A promise with an object containing a document Id and transaction Id */ setValue(key: string, value: any, version?: number): Promise<UpsertResult>; /** * Put a JSON object to QLDB as a key/value record * @param keys String[] An array of key attributes to save the records with. * @param values any [] An array of values of a value attributes to save the records with. If they are not a string, they will be converted to Amazon Ion before submitting to the ledger. * @param versions number [] (OPTIONAL) An array of the versions of the documents to make sure we update the right version. Function will return an error if the most recent version in the ledger is different. * @returns A promise with an object containing a document Id and transaction Id */ setValues(keys: string[], values: any[], versions?: number[]): Promise<UpsertResult[]>; /** * Get most recent metadata for a corresponding key as JSON object * @param key A value of a key attribute to retrieve the record from. * @param transactionId A transaction Id for the version of the document you would like to retrieve (optional). * @returns Promise with a value object as JSON. */ getMetadata(key: string): Promise<LedgerMetadata>; /** * Get the metadata for a specific documentId and transactionId as JSON object * @param documentId A document Id generated by the QLDB service. * @param transactionId A transaction Id for the version of the document you would like to retrieve (optional). * @returns Promise with a value object as JSON. */ getMetadataByDocIdAndTxId(documentId: string, transactionId: string): Promise<LedgerMetadata>; /** * Get complete history of a document, associated with the certain key * @param {string} key A value of a key attribute to retrieve the record from. * @param {string} fromDateISO OPTIONAL String, containing a from date and time in ISO format like `2019-06-05T00:00:00Z` to query revisions history from. * @param {string} toDateISO OPTIONAL String, containing a to date and time in ISO format like `2019-06-05T00:00:00Z` to query revisions history to. * @returns Promise with an array of documents as JSON. */ getHistory(key: string, fromDateISO?: string, toDateISO?: string): Promise<object[]>; /** * Get value for a corresponding key as JSON object * @param {LedgerMetadata} ledgerMetadata is an object that holds ledger metadata returned by function "getMetadata(key)" * @returns Promise with a boolean */ verifyLedgerMetadata(ledgerMetadata: LedgerMetadata): Promise<boolean>; /** * Get document revision by metadata * @param {LedgerMetadata} ledgerMetadata is an object that holds ledger metadata returned by function "getMetadata(key)" * @returns Document with document revision */ getDocumentRevisionByLedgerMetadata(ledgerMetadata: LedgerMetadata): Promise<any>; /** * Verify document revision hash * @param {JSON} documentRevision is an object that holds document revision returned by function "getDocumentRevisionByLedgerMetadata(ledgerMetadata)" or "getHistory(key)" * @returns Document with document revision */ verifyDocumentRevisionHash(documentRevision: any): boolean; /** * Gets the most recent ledger digest. * @returns A JSON document with ledger digest. * @param ledgerName A name of the ledger * @throws Error: If error happen during the process. */ getLedgerDigest(ledgerName: string, qldbClient: QLDB): Promise<GetDigestCommandOutput>; }