@getanthill/datastore
Version:
Event-Sourced Datastore
97 lines • 3.17 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.properties = void 0;
const c = __importStar(require("../../constants"));
const MODEL_DATABASE = 'datastore';
const MODEL_NAME = '_cache';
const CORRELATION_FIELD = 'cache_id';
const value = {
type: 'object',
description: 'Cache value',
};
const expires_by = {
...c.COMPONENT_DATE,
description: 'Cache entry expiration date',
};
exports.properties = {
value,
expires_by,
};
const modelConfig = {
is_enabled: true,
db: MODEL_DATABASE,
name: MODEL_NAME,
correlation_field: CORRELATION_FIELD,
retry_duration: 5000,
schema: {
model: {
additionalProperties: true,
properties: exports.properties,
},
events: {
[c.EVENT_TYPE_CREATED]: {
'0_0_0': {
additionalProperties: false,
required: ['value'],
properties: exports.properties,
},
},
[c.EVENT_TYPE_UPDATED]: {
'0_0_0': {
additionalProperties: false,
required: ['value'],
properties: exports.properties,
},
},
[c.EVENT_TYPE_RESTORED]: {
'0_0_0': {
properties: exports.properties,
},
},
[c.EVENT_TYPE_ROLLBACKED]: {
'0_0_0': {
properties: exports.properties,
},
},
},
},
indexes: [
{
collection: MODEL_NAME,
fields: { expires_by: 1 },
// Remove the cache entry after 30 days
opts: { name: 'expires_by_ttl', expireAfterSeconds: 3600 * 24 * 30 },
},
{
collection: `${MODEL_NAME}_events`,
fields: { expires_by: 1 },
// Remove the events after 1 day
opts: { name: 'expires_by_ttl', expireAfterSeconds: 3600 * 24 },
},
],
};
exports.default = modelConfig;
//# sourceMappingURL=_cache.js.map