@getanthill/datastore
Version:
Event-Sourced Datastore
121 lines • 3.82 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 = '_logs';
const CORRELATION_FIELD = 'log_id';
const model = {
...c.COMPONENT_STRING,
description: 'Model name linked to this log',
};
const correlation_id = {
...c.COMPONENT_CORRELATION_ID,
description: 'Correlation id linked to this log',
};
const message = {
...c.COMPONENT_STRING,
};
const context = {
type: 'object',
description: 'Log context',
};
const level = {
...c.COMPONENT_INTEGER,
description: 'Log level',
minimum: 0,
maximum: 100,
};
exports.properties = {
model,
correlation_id,
level,
message,
context,
};
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: ['level', 'model', 'message'],
properties: exports.properties,
},
},
[c.EVENT_TYPE_UPDATED]: {
'0_0_0': {
additionalProperties: false,
required: ['level', 'model', 'message'],
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: { model: 1, correlation_id: 1 },
opts: { name: 'entity_type_1_correlation_id_1' },
},
{
collection: MODEL_NAME,
fields: { created_at: 1, level: 1 },
opts: { name: 'created_at_1_level_1' },
},
{
collection: MODEL_NAME,
fields: { created_at: 1 },
opts: { name: 'created_at_ttl', expireAfterSeconds: 10368000 }, // Remove the events after 3 months
},
{
collection: `${MODEL_NAME}_events`,
fields: { created_at: 1 },
opts: { name: 'created_at_ttl', expireAfterSeconds: 2592000 }, // Remove the events after 30 days
},
],
};
exports.default = modelConfig;
//# sourceMappingURL=_logs.js.map