@trayio/cdk-dsl 2.7.0 → 2.9.0
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/README.md +64 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -479,12 +479,7 @@ export const myOperationHandler =
|
|
|
479
479
|
.usingHttp((http) =>
|
|
480
480
|
http.post('https://someapi.com/someresource')
|
|
481
481
|
.handleRequest((ctx, input, request) =>
|
|
482
|
-
request.withBodyAsFile(
|
|
483
|
-
name: 'test-image',
|
|
484
|
-
url: 'https://tray.io/favicon.ico', // url of the source file
|
|
485
|
-
mime_type: 'image/png',
|
|
486
|
-
expires: 0,
|
|
487
|
-
})
|
|
482
|
+
request.withBodyAsFile(input.file) // where file is of type FileReference.
|
|
488
483
|
)
|
|
489
484
|
.handleResponse((ctx, input, response) =>
|
|
490
485
|
response.parseWithBodyAsJson()
|
|
@@ -722,3 +717,66 @@ OperationHandlerTestSetup.configureHandlerTest(
|
|
|
722
717
|
```
|
|
723
718
|
|
|
724
719
|
It is worth noting that while the DSL can be used to write complex functional tests, in practice, a connector test's focus is more about making sure that operations are properly communicating with the underlying implementation instead of testing its functionality, but ultimately it is up to the developer to decide how much and what type of coverage suits a given connector best.
|
|
720
|
+
|
|
721
|
+
## File Handling.
|
|
722
|
+
|
|
723
|
+
### An example operation for a file download.
|
|
724
|
+
|
|
725
|
+
```typescript
|
|
726
|
+
// input.ts
|
|
727
|
+
export type DownloadFileInput = {}; // add input params as needed.
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
// output.ts
|
|
732
|
+
import { FileReference } from '@trayio/cdk-dsl/dist/connector/operation/OperationHandler';
|
|
733
|
+
|
|
734
|
+
export type DownloadFileOutput = {
|
|
735
|
+
file: FileReference;
|
|
736
|
+
};
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
```typescript
|
|
740
|
+
// handler.ts
|
|
741
|
+
handler.usingHttp((http) =>
|
|
742
|
+
http
|
|
743
|
+
.get('https://someapi.com/someresource')
|
|
744
|
+
.handleRequest((ctx, input, request) => request.withoutBody())
|
|
745
|
+
.handleResponse((ctx, input, response) =>
|
|
746
|
+
response.parseWithBodyAsFile<DownloadFileOutput['file']>((file) =>
|
|
747
|
+
OperationHandlerResult.success({ file })
|
|
748
|
+
)
|
|
749
|
+
)
|
|
750
|
+
);
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
### An example operation for a file upload.
|
|
754
|
+
|
|
755
|
+
_(Note: This upload operation is not applicable for multipart/form-data endpoints)_
|
|
756
|
+
|
|
757
|
+
```typescript
|
|
758
|
+
// input.ts
|
|
759
|
+
import { FileReference } from '@trayio/cdk-dsl/dist/connector/operation/OperationHandler';
|
|
760
|
+
|
|
761
|
+
export type UploadFileInput = {
|
|
762
|
+
file: FileReference;
|
|
763
|
+
};
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
```typescript
|
|
767
|
+
// output.ts
|
|
768
|
+
export type UploadFileOutput = {
|
|
769
|
+
id: number; // response from the API.
|
|
770
|
+
};
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
```typescript
|
|
774
|
+
// handler.ts
|
|
775
|
+
handler.usingHttp((http) =>
|
|
776
|
+
http
|
|
777
|
+
.post('https://someapi.com/someresource')
|
|
778
|
+
.handleRequest((ctx, input, request) =>
|
|
779
|
+
request.withBodyAsFile(input.file)
|
|
780
|
+
)
|
|
781
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
782
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-dsl",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "A DSL for connector development",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@trayio/commons": "2.
|
|
17
|
+
"@trayio/commons": "2.9.0"
|
|
18
18
|
},
|
|
19
19
|
"typesVersions": {
|
|
20
20
|
"*": {
|