UNPKG

n8n

Version:

n8n Workflow Automation Tool

73 lines 3.17 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DbStore = void 0; const db_1 = require("@n8n/db"); const di_1 = require("@n8n/di"); const chunk_1 = __importDefault(require("lodash/chunk")); const constants_1 = require("./constants"); const MAX_READ_BATCH_SIZE = 900; let DbStore = class DbStore { constructor(repository) { this.repository = repository; } async write({ executionId }, payload, tx) { const repo = this.getRepository(tx); await repo.upsert({ ...payload, executionId }, ['executionId']); } async read({ executionId }, tx) { const repo = this.getRepository(tx); const result = await repo.findOne({ where: { executionId }, select: ['data', 'workflowData', 'workflowVersionId'], }); if (!result) return null; return { ...result, version: constants_1.EXECUTION_DATA_BUNDLE_VERSION }; } async readMany(refs) { const bundles = new Map(); if (refs.length === 0) return bundles; const ids = refs.map((r) => r.executionId); for (const batch of (0, chunk_1.default)(ids, MAX_READ_BATCH_SIZE)) { const rows = await this.repository.find({ where: { executionId: (0, db_1.In)(batch) }, select: ['executionId', 'data', 'workflowData', 'workflowVersionId'], }); for (const row of rows) { bundles.set(row.executionId, { data: row.data, workflowData: row.workflowData, workflowVersionId: row.workflowVersionId, version: constants_1.EXECUTION_DATA_BUNDLE_VERSION, }); } } return bundles; } async delete(ref) { const ids = (Array.isArray(ref) ? ref : [ref]).map((r) => r.executionId); await this.repository.deleteMany(ids); } getRepository(tx) { return tx ? tx.getRepository(db_1.ExecutionData) : this.repository; } }; exports.DbStore = DbStore; exports.DbStore = DbStore = __decorate([ (0, di_1.Service)(), __metadata("design:paramtypes", [db_1.ExecutionDataRepository]) ], DbStore); //# sourceMappingURL=db-store.js.map