Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template: remove callback, fix options #921

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tools/generate/template/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import * as util from './Utils';
* @returns {Operation}
* @state {HttpState}
*/
export function get(path, options, callback) {
return request('GET', path, null, options, callback);
export function get(path, options) {
return request('GET', path, null, options);
}

/**
Expand All @@ -52,8 +52,8 @@ export function get(path, options, callback) {
* @returns {Operation}
* @state {HttpState}
*/
export function post(path, options, callback) {
return request('POST', path, null, options, callback);
export function post(path, options) {
return request('POST', path, null, options);
}

/**
Expand All @@ -70,7 +70,7 @@ export function post(path, options, callback) {
* @returns {Operation}
* @state {HttpState}
*/
export function request(method, path, body, options = {}, callback = s => s) {
export function request(method, path, body, options = {}) {
return async state => {
const [resolvedMethod, resolvedPath, resolvedData, resolvedoptions] =
expandReferences(state, method, path, body, options);
Expand All @@ -85,7 +85,7 @@ export function request(method, path, body, options = {}, callback = s => s) {
}
);

return util.prepareNextState(state, response, callback);
return util.prepareNextState(state, response);
};
}

Expand Down
10 changes: 4 additions & 6 deletions tools/generate/template/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ import {
} from '@openfn/language-common/util';
import nodepath from 'node:path';

export const prepareNextState = (state, response, callback = s => s) => {
export const prepareNextState = (state, response) => {
const { body, ...responseWithoutBody } = response;

if (!state.references) {
state.references = [];
}

const nextState = {
return {
...composeNextState(state, response.body),
response: responseWithoutBody,
};

return callback(nextState);
};

// This helper function will call out to the backend service
// and add authorisation headers
// Refer to the common request function for options and details
export const request = (configuration = {}, method, path, options) => {
// You might want to check that the path is not an absolute URL befor
// You might want to check that the path is not an absolute URL before
// appending credentials commonRequest will do this for you if you
// pass a baseURL to it and you don't need to build a path here
// assertRelativeUrl(path);
Expand Down Expand Up @@ -66,5 +64,5 @@ export const request = (configuration = {}, method, path, options) => {
const safePath = nodepath.join(path);

// Make the actual request
return commonRequest(method, safePath, options);
return commonRequest(method, safePath, opts);
};
Loading