Skip to content

Commit a1966ef

Browse files
authored
Bugfix: Remove no-op onInstance functions (#386)
1 parent a401279 commit a1966ef

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

packages/spectral/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prismatic-io/spectral",
3-
"version": "10.12.1",
3+
"version": "10.12.2",
44
"description": "Utility library for building Prismatic connectors and code-native integrations",
55
"keywords": ["prismatic"],
66
"main": "dist/index.js",

packages/spectral/src/serverTypes/convertIntegration.ts

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -985,45 +985,46 @@ const generateOnInstanceWrapperFn = (
985985
componentRegistry: ComponentRegistry,
986986
customFn?: TriggerEventFunction,
987987
): TriggerEventFunction | undefined => {
988-
const onInstanceFn: TriggerEventFunction | undefined =
989-
componentRef && typeof onTrigger !== "function"
990-
? async (context, params) => {
991-
// @ts-expect-error: _components isn't part of the public API
992-
const _components = context._components ?? {
993-
invokeTrigger: () => {},
994-
};
995-
const invokeTrigger: TriggerActionInvokeFunction = _components.invokeTrigger;
996-
const cniContext = createCNIContext(context, componentRegistry);
988+
const usesComponentRef = componentRef && typeof onTrigger !== "function";
997989

998-
// Using runWithContext allows for component action invocation via manifest.
999-
return await runWithContext(cniContext, async () => {
1000-
const invokeResponse =
1001-
(await invokeTrigger(
1002-
invokeTriggerComponentInput(componentRef, onTrigger, eventName),
1003-
cniContext,
1004-
null,
1005-
params,
1006-
)) || {};
1007-
1008-
let customResponse: TriggerEventFunctionReturn = {};
1009-
if (customFn) {
1010-
customResponse = (await customFn(cniContext, params)) || {};
1011-
}
1012-
1013-
return merge(invokeResponse, customResponse);
1014-
});
990+
if (usesComponentRef) {
991+
return async (context, params) => {
992+
// @ts-expect-error: _components isn't part of the public API
993+
const _components = context._components ?? {
994+
invokeTrigger: () => {},
995+
};
996+
const invokeTrigger: TriggerActionInvokeFunction = _components.invokeTrigger;
997+
const cniContext = createCNIContext(context, componentRegistry);
998+
999+
// Using runWithContext allows for component action invocation via manifest.
1000+
return await runWithContext(cniContext, async () => {
1001+
const invokeResponse =
1002+
(await invokeTrigger(
1003+
invokeTriggerComponentInput(componentRef, onTrigger, eventName),
1004+
cniContext,
1005+
null,
1006+
params,
1007+
)) || {};
1008+
1009+
let customResponse: TriggerEventFunctionReturn = {};
1010+
if (customFn) {
1011+
customResponse = (await customFn(cniContext, params)) || {};
10151012
}
1016-
: async (context, params) => {
1017-
if (customFn) {
1018-
const cniContext = createCNIContext(context, componentRegistry);
1019-
// Using runWithContext allows for component action invocation via manifest.
1020-
return await runWithContext(cniContext, async () => {
1021-
return await customFn(cniContext, params);
1022-
});
1023-
}
1024-
};
10251013

1026-
return onInstanceFn;
1014+
return merge(invokeResponse, customResponse);
1015+
});
1016+
};
1017+
} else if (customFn) {
1018+
return async (context, params) => {
1019+
const cniContext = createCNIContext(context, componentRegistry);
1020+
// Using runWithContext allows for component action invocation via manifest.
1021+
return await runWithContext(cniContext, async () => {
1022+
return await customFn(cniContext, params);
1023+
});
1024+
};
1025+
} else {
1026+
return;
1027+
}
10271028
};
10281029

10291030
const convertOnExecution =

0 commit comments

Comments
 (0)