@onlineapps/conn-orch-cookbook 2.0.10 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/index.js +92 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/conn-orch-cookbook",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "Complete cookbook toolkit for all services - unified wrapper including core, executor, transformer, and router functionality",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"homepage": "https://github.com/onlineapps/connector-cookbook#readme",
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@onlineapps/cookbook-core": "2.1.16",
|
|
50
|
-
"@onlineapps/cookbook-executor": "1.0.
|
|
51
|
-
"@onlineapps/cookbook-router": "1.0.
|
|
50
|
+
"@onlineapps/cookbook-executor": "1.0.6",
|
|
51
|
+
"@onlineapps/cookbook-router": "1.0.7",
|
|
52
52
|
"@onlineapps/cookbook-template-helpers": "1.0.3",
|
|
53
|
-
"@onlineapps/cookbook-transformer": "1.1.
|
|
53
|
+
"@onlineapps/cookbook-transformer": "1.1.5",
|
|
54
54
|
"jsonpath": "1.1.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
package/src/index.js
CHANGED
|
@@ -92,13 +92,82 @@ const templateHelpers = require('@onlineapps/cookbook-template-helpers');
|
|
|
92
92
|
* const result = await processor.process(cookbook);
|
|
93
93
|
*/
|
|
94
94
|
function createProcessor(config = {}) {
|
|
95
|
-
|
|
95
|
+
if (!config || typeof config !== 'object') {
|
|
96
|
+
throw new Error('[conn-orch-cookbook:createProcessor] Invalid config - Expected object');
|
|
97
|
+
}
|
|
98
|
+
|
|
96
99
|
const router = config.mqClient && config.registryClient
|
|
97
100
|
? createRouter(config.mqClient, config.registryClient, config.router)
|
|
98
101
|
: null;
|
|
99
102
|
const transformer = createTransformer(config.transformer);
|
|
100
103
|
const mapper = new ResponseMapper(config.transformer);
|
|
101
104
|
|
|
105
|
+
/**
|
|
106
|
+
* NOTE:
|
|
107
|
+
* cookbook-executor validates the cookbook in its constructor.
|
|
108
|
+
* This connector therefore creates the executor lazily when a cookbook is provided.
|
|
109
|
+
*
|
|
110
|
+
* Also NOTE:
|
|
111
|
+
* cookbook-executor currently expects `step.id` internally. Our V2.1 format uses `step.step_id`.
|
|
112
|
+
* We add `id` = `step_id` ONLY for executor execution to keep runtime behavior predictable.
|
|
113
|
+
*/
|
|
114
|
+
const normalizeStepForExecutor = (step) => {
|
|
115
|
+
if (!step || typeof step !== 'object') return step;
|
|
116
|
+
|
|
117
|
+
const normalized = { ...step };
|
|
118
|
+
if (normalized.step_id && !normalized.id) {
|
|
119
|
+
normalized.id = normalized.step_id;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
switch (normalized.type) {
|
|
123
|
+
case 'foreach':
|
|
124
|
+
if (Array.isArray(normalized.body)) {
|
|
125
|
+
normalized.body = normalized.body.map(normalizeStepForExecutor);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case 'fork_join':
|
|
129
|
+
if (normalized.branches && typeof normalized.branches === 'object' && !Array.isArray(normalized.branches)) {
|
|
130
|
+
normalized.branches = Object.fromEntries(
|
|
131
|
+
Object.entries(normalized.branches).map(([k, v]) => [k, normalizeStepForExecutor(v)])
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case 'switch':
|
|
136
|
+
if (normalized.cases && typeof normalized.cases === 'object' && !Array.isArray(normalized.cases)) {
|
|
137
|
+
normalized.cases = Object.fromEntries(
|
|
138
|
+
Object.entries(normalized.cases).map(([k, v]) => [k, normalizeStepForExecutor(v)])
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (normalized.default) {
|
|
142
|
+
normalized.default = normalizeStepForExecutor(normalized.default);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
case 'steps':
|
|
146
|
+
if (Array.isArray(normalized.steps)) {
|
|
147
|
+
normalized.steps = normalized.steps.map(normalizeStepForExecutor);
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return normalized;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const normalizeCookbookForExecutor = (cookbook) => {
|
|
158
|
+
if (!cookbook || typeof cookbook !== 'object') {
|
|
159
|
+
throw new Error('[conn-orch-cookbook:createProcessor] Invalid cookbook - Expected object');
|
|
160
|
+
}
|
|
161
|
+
if (!Array.isArray(cookbook.steps)) {
|
|
162
|
+
throw new Error('[conn-orch-cookbook:createProcessor] Invalid cookbook - Expected cookbook.steps as array');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
...cookbook,
|
|
167
|
+
steps: cookbook.steps.map(normalizeStepForExecutor)
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
|
|
102
171
|
return {
|
|
103
172
|
/**
|
|
104
173
|
* Process a cookbook through the full pipeline
|
|
@@ -106,7 +175,7 @@ function createProcessor(config = {}) {
|
|
|
106
175
|
* @param {Object} [context={}] - Execution context
|
|
107
176
|
* @returns {Promise<Object>} Execution result
|
|
108
177
|
*/
|
|
109
|
-
async process(cookbook,
|
|
178
|
+
async process(cookbook, input = {}) {
|
|
110
179
|
// Parse if string (file path)
|
|
111
180
|
if (typeof cookbook === 'string') {
|
|
112
181
|
cookbook = await parseCookbookFromFile(cookbook);
|
|
@@ -118,19 +187,15 @@ function createProcessor(config = {}) {
|
|
|
118
187
|
// Validate all references
|
|
119
188
|
validateAllReferences(cookbook);
|
|
120
189
|
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
...context,
|
|
124
|
-
router,
|
|
125
|
-
transformer,
|
|
126
|
-
mapper
|
|
127
|
-
};
|
|
190
|
+
const cookbookForExecutor = normalizeCookbookForExecutor(cookbook);
|
|
191
|
+
const executor = new CookbookExecutor(cookbookForExecutor, config.executor || {});
|
|
128
192
|
|
|
129
|
-
|
|
193
|
+
// Execute
|
|
194
|
+
return executor.execute(input);
|
|
130
195
|
},
|
|
131
196
|
|
|
132
197
|
// Expose components for direct access
|
|
133
|
-
executor,
|
|
198
|
+
executor: null,
|
|
134
199
|
router,
|
|
135
200
|
transformer,
|
|
136
201
|
mapper
|
|
@@ -156,8 +221,20 @@ function createProcessor(config = {}) {
|
|
|
156
221
|
* });
|
|
157
222
|
*/
|
|
158
223
|
async function executeStep(step, context = {}) {
|
|
159
|
-
|
|
160
|
-
|
|
224
|
+
if (!step || typeof step !== 'object') {
|
|
225
|
+
throw new Error('[conn-orch-cookbook:executeStep] Invalid step - Expected object');
|
|
226
|
+
}
|
|
227
|
+
if (!step.step_id) {
|
|
228
|
+
throw new Error('[conn-orch-cookbook:executeStep] Missing step.step_id - Expected V2.1 step');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const cookbook = {
|
|
232
|
+
version: '2.1.0',
|
|
233
|
+
steps: [step]
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const processor = createProcessor();
|
|
237
|
+
return await processor.process(cookbook, context);
|
|
161
238
|
}
|
|
162
239
|
|
|
163
240
|
/**
|
|
@@ -175,8 +252,8 @@ async function executeStep(step, context = {}) {
|
|
|
175
252
|
* });
|
|
176
253
|
*/
|
|
177
254
|
async function executeWorkflow(cookbook, context = {}) {
|
|
178
|
-
const
|
|
179
|
-
return
|
|
255
|
+
const processor = createProcessor();
|
|
256
|
+
return await processor.process(cookbook, context);
|
|
180
257
|
}
|
|
181
258
|
|
|
182
259
|
// Export everything as unified interface
|