All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.preview-leaderboard-client.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PreviewLeaderboardClient = void 0;
const sdk_core_1 = require("@gomomento/sdk-core");
const leaderboard_data_client_1 = require("./internal/leaderboard-data-client");
const leaderboard_1 = require("./internal/leaderboard");
const index_1 = require("./index");
/**
 * PREVIEW Momento Leaderboard Client
 * WARNING: the API for this client is not yet stable and may change without notice.
 * Please contact Momento if you would like to try this preview.
 *
 * Leaderboard methods return a response object unique to each request.
 * The response object is resolved to a type-safe object of one of several
 * sub-types. See the documentation for each response type for details.
 */
class PreviewLeaderboardClient {
    constructor(props) {
        var _a, _b;
        const configuration = (_a = props === null || props === void 0 ? void 0 : props.configuration) !== null && _a !== void 0 ? _a : getDefaultLeaderboardConfiguration();
        const allProps = {
            configuration: configuration,
            credentialProvider: (_b = props === null || props === void 0 ? void 0 : props.credentialProvider) !== null && _b !== void 0 ? _b : (0, sdk_core_1.getDefaultCredentialProvider)(),
        };
        this.configuration = configuration;
        this.logger = configuration.getLoggerFactory().getLogger(this);
        this.logger.debug('Creating Momento LeaderboardClient');
        this.dataClient = new leaderboard_data_client_1.LeaderboardDataClient(allProps, '0'); // only creating one leaderboard client
        // Initialize middlewares that have init methods. These currently start
        // background tasks for logging that will execute until they are explicitly
        // stopped. This is usually handled by the client's close method, but if
        // there is ever a chance that this client constructor may fail after these
        // methods are called, it is up to you to catch the exception and call close
        // on each of these manually.
        this.configuration.getMiddlewares().forEach(m => {
            if (m.init) {
                m.init();
            }
        });
    }
    close() {
        this.dataClient.close();
        this.configuration.getMiddlewares().forEach(m => {
            if (m.close) {
                m.close();
            }
        });
    }
    /**
     * Creates an instance of LeaderboardClient with floating point scores up until 53 bits of precision.
     */
    leaderboard(cacheName, leaderboardName) {
        return new leaderboard_1.Leaderboard(this.dataClient, cacheName, leaderboardName);
    }
}
exports.PreviewLeaderboardClient = PreviewLeaderboardClient;
function getDefaultLeaderboardConfiguration() {
    const config = index_1.LeaderboardConfigurations.Laptop.latest();
    const logger = config.getLoggerFactory().getLogger('LeaderboardClient');
    logger.info('No configuration provided to LeaderboardClient. Using default "Laptop" configuration, suitable for development. For production use, consider specifying an explicit configuration.');
    return config;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJldmlldy1sZWFkZXJib2FyZC1jbGllbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHJldmlldy1sZWFkZXJib2FyZC1jbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsa0RBSzZCO0FBQzdCLGdGQUF5RTtBQUV6RSx3REFBbUQ7QUFFbkQsbUNBQTRFO0FBRzVFOzs7Ozs7OztHQVFHO0FBQ0gsTUFBYSx3QkFBd0I7SUFLbkMsWUFBWSxLQUE4Qjs7UUFDeEMsTUFBTSxhQUFhLEdBQ2pCLE1BQUEsS0FBSyxhQUFMLEtBQUssdUJBQUwsS0FBSyxDQUFFLGFBQWEsbUNBQUksa0NBQWtDLEVBQUUsQ0FBQztRQUMvRCxNQUFNLFFBQVEsR0FBOEI7WUFDMUMsYUFBYSxFQUFFLGFBQWE7WUFDNUIsa0JBQWtCLEVBQ2hCLE1BQUEsS0FBSyxhQUFMLEtBQUssdUJBQUwsS0FBSyxDQUFFLGtCQUFrQixtQ0FBSSxJQUFBLHVDQUE0QixHQUFFO1NBQzlELENBQUM7UUFDRixJQUFJLENBQUMsYUFBYSxHQUFHLGFBQWEsQ0FBQztRQUVuQyxJQUFJLENBQUMsTUFBTSxHQUFHLGFBQWEsQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsQ0FBQztRQUMvRCxJQUFJLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxvQ0FBb0MsQ0FBQyxDQUFDO1FBQ3hELElBQU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