database.utils.js

"use strict";
/***************************************************
* Licensed Materials - Property of HCL.
* (c)Copyright HCL America, Inc. 2023-2024
****************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.documentSave = exports.getLastError = exports.fetchAllViewDocuments = exports.getFormFromUNID = exports.getDocument = exports.setCurrentDocument = exports.getCurrentDocument = exports.getCurrentViewDocument = exports.getObjectMetadata = exports.clearCache = exports.getServiceObject = exports.getServiceEntry = exports.getServiceName = exports._notes_vmx_utils = exports._notes_utils = void 0;
const tslib_1 = require("tslib");
/**
 * @file Database Utilities
 * @module database.utils
 * @category Database Utilities
 */
const notesf_base_utils = tslib_1.__importStar(require("../notes/database.utils"));
const notesf_vmx_utils = tslib_1.__importStar(require("../notes/voltmx/database.utils"));
const API = tslib_1.__importStar(require("../rosetta/API"));
const notesf = () => API.isCurrentFrameworkVoltMX() ? notesf_vmx_utils : notesf_base_utils;
exports._notes_utils = notesf_base_utils;
exports._notes_vmx_utils = notesf_vmx_utils;
/**
 * Returns the Object Service name contained in the serverDatabase string.
 * @param {*} serverDatabase - contains the server name (optional) and object service name
 * @returns {string}
 */
const getServiceName = (serverDatabase) => {
    return notesf().getServiceName(serverDatabase);
};
exports.getServiceName = getServiceName;
/**
 * Returns the serviceEntry class for the Object Service.
 * @param {*} serverDatabase - contains the server name (optional) and object service name
 * @returns {class}
 */
const getServiceEntry = (serverDatabase) => {
    return notesf().getServiceEntry(serverDatabase);
};
exports.getServiceEntry = getServiceEntry;
/**
 * Returns a table/object from the Object Service.
 * @param {*} serverDatabase - contains the server name (optional) and object service name
 * @param {*} name - table/object name within the service
 * @returns {any}
 */
const getServiceObject = (serverDatabase, name) => {
    return notesf().getServiceObject(serverDatabase, name);
};
exports.getServiceObject = getServiceObject;
/**
 * Clears the local documents cache for the specified service.
 *
 * This will force documents to be read from the server. Caution: changes to documents not saved will be lost.
 *
 * @param {*} serverDatabase - contains the server name (optional) and object service name.
 * @param {string} [name] - table/object name within the service. If no table name is specified, all documents are cleared.
 */
const clearCache = (serverDatabase, name) => {
    notesf().clearCache(serverDatabase, name);
};
exports.clearCache = clearCache;
/**
 * Returns the table/object metadata.
 * @param {*} serviceEntry - entry for an Object Service
 * @param {*} objectName - table/object name
 * @param {*} keywords - [FAILSILENT] causes empty results to be returned if an error occurs
 * @returns {Promise<Array>}
 */
const getObjectMetadata = (serviceEntry, objectName, keywords) => {
    return notesf().getObjectMetadata(serviceEntry, objectName, keywords);
};
exports.getObjectMetadata = getObjectMetadata;
/**
 * Returns the current View document from the local cache.
 * @returns {object}
 */
const getCurrentViewDocument = () => {
    return notesf().getCurrentViewDocument();
};
exports.getCurrentViewDocument = getCurrentViewDocument;
/**
 * Returns the current Form document from the local cache.
 * @returns {object}
 */
const getCurrentDocument = () => {
    return notesf().getCurrentDocument();
};
exports.getCurrentDocument = getCurrentDocument;
/**
 * Sets the current document using form name and UNID.
 * @param {*} formName - form name.
 * @param {*} UNID - Unique ID of the document
 * @returns {Promise<object>}
 */
const setCurrentDocument = (formName, UNID) => {
    return notesf().setCurrentDocument(formName, UNID);
};
exports.setCurrentDocument = setCurrentDocument;
/**
 * Gets document using form name and UNID and makes it the current document.
 * Document is loaded from server if not in local cache.
 * @param {*} formName - form name.
 * @param {*} UNID - Unique ID of the document
 * @returns {Promise<object>}
 */
const getDocument = (formName, UNID) => {
    return notesf().getDocument(formName, UNID);
};
exports.getDocument = getDocument;
/**
 * Get form from document UNID.
 * Only works when using online access.
 * @param {*} UNID - Unique ID of the document.
 * @returns {Promise<string>}
 */
function getFormFromUNID(UNID) {
    return notesf().getFormFromUNID(UNID);
}
exports.getFormFromUNID = getFormFromUNID;
/**
 * Fetch all view documents using six concurrent promises.
 * Increases performance when reading a large number of documents from the server.
 * @param {*} pageSize - number of document to read concurrently.
 * @returns {Promise<any>}
 */
function fetchAllViewDocuments(pageSize = 10) {
    return notesf().fetchAllViewDocuments(pageSize);
}
exports.fetchAllViewDocuments = fetchAllViewDocuments;
/**
 * Returns the last Error occurring in Service.
 * @param {*} serviceEntry - entry for an Object Service
 * @returns {Error}
 */
const getLastError = (serviceEntry) => {
    return notesf().getLastError(serviceEntry);
};
exports.getLastError = getLastError;
/**
 * Saves the document to the server.
 * @param {*} serviceEntry - entry for an Object Service
 * @param {*} formName - form name
 * @param {*} formDocument - form document object
 * @returns {Promise<boolean>}
 */
function documentSave(serviceEntry, formName, formDocument) {
    return notesf().documentSave(serviceEntry, formName, formDocument);
}
exports.documentSave = documentSave;
//# sourceMappingURL=database.utils.js.map