import assert from 'assert'; import { OakException } from "oak-domain/lib/types"; import { createDebugStore } from '../debugStore'; import { cloneDeep, mergeConcatArray } from "oak-domain/lib/utils/lodash"; import commonAspectDict, { registerPorts } from 'oak-common-aspect'; import oakDomainI18nData from 'oak-domain/lib/data/i18n'; export default class DebugConnector { debugStore; contextBuilder; aspectDict; constructor(storageSchema, contextBuilder, aspectDict, triggers, checkers, watchers, timers, startRoutines, initialData, common, importations, exportations) { assert(initialData.i18n); initialData.i18n.push(...oakDomainI18nData); this.debugStore = createDebugStore(storageSchema, contextBuilder, triggers, checkers, watchers, timers, startRoutines, initialData, common); this.contextBuilder = contextBuilder; this.aspectDict = mergeConcatArray(aspectDict, commonAspectDict); if (importations || exportations) { registerPorts(importations || [], exportations || []); } } getRouter() { throw new Error('not available in debugConnector'); return ''; } ; async callAspect(name, params, context) { const str = await context?.toString(); const contextBackend = this.contextBuilder(this.debugStore); await contextBackend.begin(); if (str) { await contextBackend.initialize(JSON.parse(str)); } let { opRecords } = contextBackend; let message; try { const result = await this.aspectDict[name](cloneDeep(params), contextBackend); await contextBackend.refineOpRecords(); opRecords = contextBackend.opRecords; message = contextBackend.getMessage(); await contextBackend.commit(); return { result, opRecords: opRecords, message, }; } catch (err) { await contextBackend.rollback(); if (err instanceof OakException) { throw err; } if (err instanceof Error) { const exception = await contextBackend.tryDeduceException(err); if (exception) { throw exception; } } throw err; } } parseRequest() { throw new Error('not available in debugConnector'); return {}; } serializeResult() { throw new Error('not available in debugConnector'); return {}; } serializeException() { throw new Error('not available in debugConnector'); return {}; } getSocketPath() { throw new Error('not available in debugConnector'); return {}; } getSocketPointRouter() { throw new Error('not available in debugConnector'); return {}; } getSocketPoint() { throw new Error('not available in debugConnector'); return {}; } ; getBridgeRouter() { throw new Error('not available in debugConnector'); return ''; } ; makeBridgeUrl(url) { return url; } getEndpointRouter() { return ''; } parseBridgeRequestQuery(urlParams) { throw new Error('not available in debugConnector'); return {}; } async getFullData(keys) { return this.debugStore.getCurrentData(keys); } getCorsHeader() { throw new Error('not available in debugConnector'); return []; } } ;