Skip to content

Commit

Permalink
Implement processing v2 (#32)
Browse files Browse the repository at this point in the history
* Implement v2 of processing

* Create a function which works with both v1 and v2 processing

* Use payload instead of __payload when passing to vm

* Minor refactor

* Extend test

* Clarify test

* Refactor processing naming based on docs discussion

* Refactor function arguments

* Final naming refactor

* Fix README

* Update OIS version
  • Loading branch information
Siegrift authored Nov 27, 2023
1 parent ca5b171 commit a170578
Show file tree
Hide file tree
Showing 8 changed files with 999 additions and 186 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"tsc": "tsc --project ."
},
"dependencies": {
"@api3/ois": "^2.2.1",
"@api3/ois": "^2.3.0",
"@api3/promise-utils": "^0.4.0",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 89 additions & 14 deletions src/processing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,115 @@ The pre/post processing is only supported for Node.js environments and uses inte

## Documentation

The processing module exports two main functions:
The processing module exports a multiple functions related to processing (both version 1 and 2). The most important
functions are:

<!-- NOTE: These are copied over from "processing.d.ts" from "dist" file. -->

```ts
/**
* Pre-processes API call parameters based on the provided endpoint's processing specifications.
* Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
*
* @param preProcessingSpecifications The v1 pre-processing specifications.
* @param endpointParameters The parameters to be pre-processed.
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
*
* @returns A promise that resolves to the pre-processed parameters.
*/
export declare const preProcessEndpointParametersV1: (
preProcessingSpecifications: ProcessingSpecifications | undefined,
endpointParameters: EndpointParameters,
processingOptions?: GoAsyncOptions
) => Promise<EndpointParameters>;

/**
* Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
* API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
* allows skipping API calls in which case the response is the result of pre-processing.
*
* @param response The response to be post-processed.
* @param postProcessingSpecifications The v1 post-processing specifications.
* @param endpointParameters The endpoint parameters.
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
*
* @returns A promise that resolves to the post-processed response.
*/
export declare const postProcessResponseV1: (
response: unknown,
postProcessingSpecifications: ProcessingSpecifications | undefined,
endpointParameters: EndpointParameters,
processingOptions?: GoAsyncOptions
) => Promise<unknown>;

/**
* Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
*
* @param preProcessingSpecificationV2 The v2 pre-processing specification.
* @param endpointParameters The parameters to be pre-processed.
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
*
* @returns A promise that resolves to the pre-processed parameters.
*/
export declare const preProcessEndpointParametersV2: (
preProcessingSpecificationV2: ProcessingSpecificationV2 | undefined,
endpointParameters: EndpointParameters,
processingOptions?: GoAsyncOptions
) => Promise<PreProcessingV2Response>;

/**
* Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
* API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
* allows skipping API calls in which case the response is the result of pre-processing.
*
* @param response The response to be post-processed.
* @param postProcessingSpecificationV2 The v2 post-processing specification.
* @param endpointParameters The endpoint parameters.
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
*
* @returns A promise that resolves to the post-processed response.
*/
export declare const postProcessResponseV2: (
response: unknown,
postProcessingSpecificationV2: ProcessingSpecificationV2 | undefined,
endpointParameters: EndpointParameters,
processingOptions?: GoAsyncOptions
) => Promise<PostProcessingV2Response>;

/**
* Pre-processes endpoint parameters based on the provided endpoint's processing specifications. Internally it
* determines what processing implementation should be used.
*
* @param endpoint The endpoint containing processing specifications.
* @param apiCallParameters The parameters to be pre-processed.
* @param endpointParameters The parameters to be pre-processed.
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
*
* @returns A promise that resolves to the pre-processed parameters.
*/
export declare const preProcessApiCallParameters: (
export declare const preProcessEndpointParameters: (
endpoint: Endpoint,
apiCallParameters: ApiCallParameters,
endpointParameters: EndpointParameters,
processingOptions?: GoAsyncOptions
) => Promise<ApiCallParameters>;
) => Promise<PreProcessingV2Response>;

/**
* Post-processes the API call response based on the provided endpoint's processing specifications.
* Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
* API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
* allows skipping API calls in which case the response is the result of pre-processing.
*
* @param apiCallResponse The raw response obtained from the API call.
* This function determines what processing version should be used and provides a common interface. This is useful for
* services that want to use processing and don't care which processing version is used.
*
* @param response The response to be post-processed.
* @param endpoint The endpoint containing processing specifications.
* @param apiCallParameters The parameters used in the API call.
* @param endpointParameters The endpoint parameters.
* @param processingOptions Options to control the async processing behavior like retries and timeouts.
*
* @returns A promise that resolves to the post-processed API call response.
* @returns A promise that resolves to the post-processed response.
*/
export declare const postProcessApiCallResponse: (
apiCallResponse: unknown,
export declare const postProcessResponse: (
response: unknown,
endpoint: Endpoint,
apiCallParameters: ApiCallParameters,
endpointParameters: EndpointParameters,
processingOptions?: GoAsyncOptions
) => Promise<unknown>;
) => Promise<PostProcessingV2Response>;
```
Loading

0 comments on commit a170578

Please sign in to comment.