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

package.dist.src.internal.storage-control-client.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageControlClient = void 0;
const generated_types_1 = require("@gomomento/generated-types");
var grpcControl = generated_types_1.control.control_client;
const headers_interceptor_1 = require("./grpc/headers-interceptor");
const cache_service_error_mapper_1 = require("../errors/cache-service-error-mapper");
const grpc_js_1 = require("@grpc/grpc-js");
const __1 = require("..");
const package_json_1 = require("../../package.json");
const utils_1 = require("@gomomento/sdk-core/dist/src/internal/utils");
const sdk_core_1 = require("@gomomento/sdk-core");
const retry_interceptor_1 = require("./grpc/retry-interceptor");
const utils_2 = require("@gomomento/sdk-core/dist/src/utils");
class StorageControlClient {
    /**
     * @param {StorageClientProps} props
     */
    constructor(props) {
        this.logger = props.configuration.getLoggerFactory().getLogger(this);
        this.cacheServiceErrorMapper = new cache_service_error_mapper_1.CacheServiceErrorMapper(false);
        const headers = [
            new headers_interceptor_1.Header('Authorization', props.credentialProvider.getAuthToken()),
            new headers_interceptor_1.Header('agent', `nodejs:store:${package_json_1.version}`),
            new headers_interceptor_1.Header('runtime-version', `nodejs:${process.versions.node}`),
        ];
        this.interceptors = [
            headers_interceptor_1.HeaderInterceptor.createHeadersInterceptor(headers),
            retry_interceptor_1.RetryInterceptor.createRetryInterceptor({
                clientName: 'StorageControlClient',
                loggerFactory: props.configuration.getLoggerFactory(),
                overallRequestTimeoutMs: StorageControlClient.REQUEST_TIMEOUT_MS,
            }),
        ];
        this.logger.debug(`Creating storage control client using endpoint: '${props.credentialProvider.getControlEndpoint()}`);
        this.clientWrapper = new grpcControl.ScsControlClient(props.credentialProvider.getControlEndpoint(), props.credentialProvider.isControlEndpointSecure()
            ? grpc_js_1.ChannelCredentials.createSsl()
            : grpc_js_1.ChannelCredentials.createInsecure());
    }
    close() {
        this.logger.debug('Closing storage control client');
        this.clientWrapper.close();
    }
    async createStore(name) {
        try {
            (0, utils_1.validateStoreName)(name);
        }
        catch (err) {
            return this.cacheServiceErrorMapper.returnOrThrowError(err, err => new sdk_core_1.CreateStore.Error(err));
        }
        this.logger.debug(`Creating store: ${name}`);
        const request = new grpcControl._CreateStoreRequest({
            store_name: name,
        });
        return await new Promise((resolve, reject) => {
            this.clientWrapper.CreateStore(request, { interceptors: this.interceptors }, (err, _resp) => {
                if (err) {
                    const sdkError = this.cacheServiceErrorMapper.convertError(err);
                    if (sdkError.errorCode() ===
                        __1.MomentoErrorCode.STORE_ALREADY_EXISTS_ERROR) {
                        resolve(new sdk_core_1.CreateStore.AlreadyExists());
                    }
                    else {
                        this.cacheServiceErrorMapper.resolveOrRejectError({
                            err: err,
                            errorResponseFactoryFn: e => new sdk_core_1.CreateStore.Error(e),
                            resolveFn: resolve,
                            rejectFn: reject,
                        });
                    }
                }
                else {
                    resolve(new sdk_core_1.CreateStore.Success());
                }
            });
        });
    }
    async deleteStore(name) {
        try {
            (0, utils_1.validateStoreName)(name);
        }
        catch (err) {
            return this.cacheServiceErrorMapper.returnOrThrowError(err, err => new sdk_core_1.DeleteStore.Error(err));
        }
        const request = new grpcControl._DeleteStoreRequest({
            store_name: name,
        });
        this.logger.debug(`Deleting store: ${name}`);
        return await new Promise((resolve, reject) => {
            this.clientWrapper.DeleteStore(request, { interceptors: this.interceptors }, (err, _resp) => {
                if (err) {
                    this.cacheServiceErrorMapper.resolveOrRejectError({
                        err: err,
                        errorResponseFactoryFn: e => new sdk_core_1.DeleteStore.Error(e),
                        resolveFn: resolve,
                        rejectFn: reject,
                    });
                }
                else {
                    resolve(new sdk_core_1.DeleteStore.Success());
                }
            });
        });
    }
    async listStores() {
        const request = new grpcControl._ListStoresRequest();
        request.next_token = '';
        this.logger.debug("Issuing 'listStores' request");
        return await new Promise((resolve, reject) => {
            this.clientWrapper.ListStores(request, { interceptors: this.interceptors }, (err, resp) => {
                if (err || !resp) {
                    this.cacheServiceErrorMapper.resolveOrRejectError({
                        err: err,
                        errorResponseFactoryFn: e => new __1.ListStores.Error(e),
                        resolveFn: resolve,
                        rejectFn: reject,
                    });
                }
                else {
                    const stores = resp.store.map(store => {
                        const storeName = store.store_name;
                        return new __1.StoreInfo(storeName);
                    });
                    resolve(new __1.ListStores.Success(stores));
                }
            });
        });
    }
}
exports.StorageControlClient = StorageControlClient;
StorageControlClient.REQUEST_TIMEOUT_MS = (0, utils_2.secondsToMilliseconds)(60);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmFnZS1jb250cm9sLWNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9pbnRlcm5hbC9zdG9yYWdlLWNvbnRyb2wtY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGdFQUFtRDtBQUNuRCxJQUFPLFdBQVcsR0FBRyx5QkFBTyxDQUFDLGNBQWMsQ0FBQztBQUM1QyxvRUFBcUU7QUFDckUscUZBQTZFO0FBQzdFLDJDQUE4RDtBQUM5RCwwQkFBMEU7QUFDMUUscURBQTJDO0FBQzNDLHVFQUE4RTtBQUM5RSxrREFBNkQ7QUFDN0QsZ0VBQTBEO0FBRTFELDhEQUF5RTtBQUV6RSxNQUFhLG9CQUFvQjtJQVEvQjs7T0FFRztJQUNILFlBQVksS0FBNEI7UUFDdEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxLQUFLLENBQUMsYUFBYSxDQUFDLGdCQUFnQixFQUFFLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQ3JFLElBQUksQ0FBQyx1QkFBdUIsR0FBRyxJQUFJLG9EQUF1QixDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQ2xFLE1BQU0sT0FBTyxHQUFHO1lBQ2QsSUFBSSw0QkFBTSxDQUFDLGVBQWUsRUFBRSxLQUFLLENBQUMsa0JBQWtCLENBQUMsWUFBWSxFQUFFLENBQUM7WUFDcEUs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+IHtcbiAgICAgIHRoaXMuY2xpZW50V3JhcHBlci5MaXN0U3RvcmVzKFxuICAgICAgICByZXF1ZXN0LFxuICAgICAgICB7aW50ZXJjZXB0b3JzOiB0aGlzLmludGVyY2VwdG9yc30sXG4gICAgICAgIChlcnIsIHJlc3ApID0+IHtcbiAgICAgICAgICBpZiAoZXJyIHx8ICFyZXNwKSB7XG4gICAgICAgICAgICB0aGlzLmNhY2hlU2VydmljZUVycm9yTWFwcGVyLnJlc29sdmVPclJlamVjdEVycm9yKHtcbiAgICAgICAgICAgICAgZXJyOiBlcnIsXG4gICAgICAgICAgICAgIGVycm9yUmVzcG9uc2VGYWN0b3J5Rm46IGUgPT4gbmV3IExpc3RTdG9yZXMuRXJyb3IoZSksXG4gICAgICAgICAgICAgIHJlc29sdmVGbjogcmVzb2x2ZSxcbiAgICAgICAgICAgICAgcmVqZWN0Rm46IHJlamVjdCxcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBjb25zdCBzdG9yZXMgPSByZXNwLnN0b3JlLm1hcChzdG9yZSA9PiB7XG4gICAgICAgICAgICAgIGNvbnN0IHN0b3JlTmFtZSA9IHN0b3JlLnN0b3JlX25hbWU7XG4gICAgICAgICAgICAgIHJldHVybiBuZXcgU3RvcmVJbmZvKHN0b3JlTmFtZSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIHJlc29sdmUobmV3IExpc3RTdG9yZXMuU3VjY2VzcyhzdG9yZXMpKTtcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICk7XG4gICAgfSk7XG4gIH1cbn1cbiJdfQ==




© 2015 - 2025 Weber Informatics LLC | Privacy Policy