@camunda8/sdk
Version:
[](https://www.npmjs.com/package/@camunda8/sdk)
42 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSpecializedRestApiJobClass = void 0;
const C8Dto_1 = require("./C8Dto");
/**
* REST Job class factory that creates specialized RestApiJob classes based on input variables and custom headers.
* This factory caches the created classes to avoid creating the same class multiple times.
* It uses a memoization technique to store the classes in a Map, where the key is a stringified version of the input variables and custom headers.
* A Specialized REST Job class is the generic Job Dto specialised with the LosslessDto for the variables and custom headers payload.
*/
const factory = createMemoizedSpecializedRestApiJobClassFactory();
// Creates a specialized RestApiJob class that is cached based on input variables and custom headers.
const createSpecializedRestApiJobClass = (inputVariableDto, customHeaders) => {
// Assuming `createMemoizedSpecializedRestApiJobClassFactory` is available
return factory(inputVariableDto, customHeaders);
};
exports.createSpecializedRestApiJobClass = createSpecializedRestApiJobClass;
function createMemoizedSpecializedRestApiJobClassFactory() {
const cache = new Map();
return function (inputVariableDto, customHeadersDto) {
// Create a unique cache key based on the class and inputs
const cacheKey = JSON.stringify({
inputVariableDto,
customHeadersDto,
});
// Check for cached result
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
// Create a new class that extends the original class
class NewRestApiJobClass extends C8Dto_1.RestApiJob {
}
// Use Reflect to define the metadata on the new class's prototype
Reflect.defineMetadata('child:class', inputVariableDto, NewRestApiJobClass.prototype, 'variables');
Reflect.defineMetadata('child:class', customHeadersDto, NewRestApiJobClass.prototype, 'customHeaders');
// Store the new class in cache
cache.set(cacheKey, NewRestApiJobClass);
// Return the new class
return NewRestApiJobClass;
};
}
//# sourceMappingURL=RestApiJobClassFactory.js.map