@5minds/processcube_engine
Version:
The ProcessCube Engine. Stores and executes BPMNs.
87 lines • 3.1 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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeWorkerMessage = serializeWorkerMessage;
exports.deserializeWorkerMessage = deserializeWorkerMessage;
const uuid = __importStar(require("uuid"));
const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk");
function serializeWorkerMessage(message) {
return {
data: JSON.stringify(message, replacer),
};
}
function deserializeWorkerMessage(message) {
if (message && message.data) {
return JSON.parse(message.data, reviver);
}
else {
return {
id: uuid.v4(),
type: 'SystemMessage',
content: message,
};
}
}
const regexpDecoratorKey = '__REGEXP ';
const errorDecoratorKey = '__ERROR ';
function replacer(key, value) {
if (value instanceof Error) {
return errorDecoratorKey + (0, processcube_engine_sdk_1.serializeJson)(value);
}
if (value instanceof RegExp) {
return regexpDecoratorKey + value.toString();
}
return value;
}
function reviver(key, value) {
if (!value) {
return value;
}
const stringValue = value.toString();
if (stringValue.indexOf(regexpDecoratorKey) == 0) {
// Restores serialized regexp
const result = value.split(regexpDecoratorKey)[1].match(/\/(.*)\/(.*)?/);
return new RegExp(result[1], result[2] || '');
}
else if (stringValue.indexOf(errorDecoratorKey) == 0) {
const result = value.split(errorDecoratorKey)[1];
const deserializedError = (0, processcube_engine_sdk_1.deserializeJson)(result);
return deserializedError;
}
else {
return value;
}
}
//# sourceMappingURL=WorkerMessages.js.map