@wora/relay-store
Version:
@wora Relay Store
60 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var RelayRecordState_1 = tslib_1.__importDefault(require("relay-runtime/lib/store/RelayRecordState"));
var cache_persist_1 = require("@wora/cache-persist");
var EXISTENT = RelayRecordState_1.default.EXISTENT, NONEXISTENT = RelayRecordState_1.default.NONEXISTENT, UNKNOWN = RelayRecordState_1.default.UNKNOWN;
var RecordSource = (function () {
function RecordSource(persistOptions) {
if (persistOptions === void 0) { persistOptions = {}; }
var persistOptionsRecordSource = tslib_1.__assign({ prefix: 'relay-records', serialize: true }, persistOptions);
this._cache = new cache_persist_1.Cache(persistOptionsRecordSource);
}
RecordSource.prototype.isRehydrated = function () {
return this._cache.isRehydrated();
};
RecordSource.prototype.purge = function () {
this._cache.purge();
return this._cache.flush();
};
RecordSource.prototype.restore = function () {
return this._cache.restore();
};
RecordSource.prototype.clear = function () {
this._cache.purge();
};
RecordSource.prototype.delete = function (dataID) {
this._cache.delete(dataID);
};
RecordSource.prototype.get = function (dataID) {
return this._cache.get(dataID);
};
RecordSource.prototype.getRecordIDs = function () {
return this._cache.getAllKeys();
};
RecordSource.prototype.getStatus = function (dataID) {
var state = this._cache.getState();
if (!this._cache.has(dataID)) {
return UNKNOWN;
}
return state[dataID] == null ? NONEXISTENT : EXISTENT;
};
RecordSource.prototype.has = function (dataID) {
return this._cache.has(dataID);
};
RecordSource.prototype.remove = function (dataID) {
this._cache.remove(dataID);
};
RecordSource.prototype.set = function (dataID, record) {
this._cache.set(dataID, record);
};
RecordSource.prototype.size = function () {
return this._cache.getAllKeys().length;
};
RecordSource.prototype.toJSON = function () {
return this._cache.getState();
};
return RecordSource;
}());
exports.RecordSource = RecordSource;
//# sourceMappingURL=RecordSource.js.map