Skip to content

Commit

Permalink
Merge pull request #813 from OpenFn/collections-dont-override
Browse files Browse the repository at this point in the history
worker: allow steps to specify their own adaptor version
  • Loading branch information
josephjclark authored Nov 8, 2024
2 parents e0e19b2 + 606f23b commit 2e24251
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-clocks-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/ws-worker': patch
---

Allow steps to specify their own adaptor version
12 changes: 10 additions & 2 deletions packages/ws-worker/src/util/convert-lightning-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ export default (
const job = step as Job;
if (job.expression?.match(/(collections\.)/)) {
hasCollections = true;
job.adaptors ??= [];
job.adaptors.push(`@openfn/language-collections@${collectionsVersion}`);
if (
!job.adaptors?.find((v) =>
v.startsWith('@openfn/language-collections')
)
) {
job.adaptors ??= [];
job.adaptors.push(
`@openfn/language-collections@${collectionsVersion}`
);
}
}
});
return hasCollections;
Expand Down
31 changes: 30 additions & 1 deletion packages/ws-worker/test/util/convert-lightning-plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,36 @@ test('append the collections adaptor to jobs that use it', (t) => {
t.deepEqual(b.adaptors, ['common', '@openfn/[email protected]']);
});

test('append the collections credential to jobs that use it', (t) => {
test('do not append the collections adaptor to jobs that already have it', (t) => {
const run: Partial<LightningPlan> = {
id: 'w',
jobs: [
createNode({
id: 'a',
body: 'collections.each("c", "k", (state) => state)',
adaptor: '@openfn/language-collections@latest',
}),
],
triggers: [{ id: 't', type: 'cron' }],
edges: [createEdge('t', 'a')],
};

const { plan } = convertPlan(run as LightningPlan, {
collectionsVersion: '1.0.0',
});

const [_t, a] = plan.workflow.steps;

// @ts-ignore
t.deepEqual(a.adaptors, ['@openfn/language-collections@latest']);

t.deepEqual(plan.workflow.credentials, {
collections_token: true,
collections_endpoint: true,
});
});

test('append the collections credential to workflows that use it', (t) => {
const run: Partial<LightningPlan> = {
id: 'w',
jobs: [
Expand Down

0 comments on commit 2e24251

Please sign in to comment.