"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isString_1 = __importDefault(require("lodash/isString"));
var storage_1 = require("../storage");
var kinvey_1 = require("../kinvey");
var QUERY_CACHE_TAG = '_QueryCache';
var SYNC_CACHE_TAG = 'kinvey_sync';
function isValidTag(tag) {
    var regexp = /^[a-z0-9-]+$/i;
    return isString_1.default(tag) && regexp.test(tag);
}
exports.isValidTag = isValidTag;
var DataStoreCache = /** @class */ (function (_super) {
    __extends(DataStoreCache, _super);
    function DataStoreCache(collectionName, tag) {
        var _this = this;
        if (tag && !isValidTag(tag)) {
            throw new Error('A tag can only contain letters, numbers, and "-".');
        }
        if (tag) {
            _this = _super.call(this, kinvey_1.getAppKey(), collectionName + "." + tag) || this;
        }
        else {
            _this = _super.call(this, kinvey_1.getAppKey(), collectionName) || this;
        }
        return _this;
    }
    DataStoreCache.clear = function () {
        return storage_1.Storage.clear(kinvey_1.getAppKey());
    };
    return DataStoreCache;
}(storage_1.Storage));
exports.DataStoreCache = DataStoreCache;
var QueryCache = /** @class */ (function (_super) {
    __extends(QueryCache, _super);
    function QueryCache(tag) {
        return _super.call(this, QUERY_CACHE_TAG, tag) || this;
    }
    return QueryCache;
}(DataStoreCache));
exports.QueryCache = QueryCache;
var SyncEvent;
(function (SyncEvent) {
    SyncEvent["Create"] = "POST";
    SyncEvent["Update"] = "PUT";
    SyncEvent["Delete"] = "DELETE";
})(SyncEvent = exports.SyncEvent || (exports.SyncEvent = {}));
;
var SyncCache = /** @class */ (function (_super) {
    __extends(SyncCache, _super);
    function SyncCache(tag) {
        return _super.call(this, SYNC_CACHE_TAG, tag) || this;
    }
    return SyncCache;
}(DataStoreCache));
exports.SyncCache = SyncCache;
//# sourceMappingURL=cache.js.map