-
Notifications
You must be signed in to change notification settings - Fork 1
Simplify template writing #30
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
Merged
gasperzgonec
merged 16 commits into
devrev:main
from
Codeplain-ai:feat/simplify-template-writing
Oct 14, 2025
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d7d8b6f
Fix error in conformance test script
tjazerzen 1b7cb01
Streamline acceptance test templating
tjazerzen 1f0ab15
Merge branch 'devrev:main' into main
tjazerzen 928e31d
Update base folder error handling
tjazerzen 31fc930
Merge branch 'devrev:main' into main
tjazerzen b241a52
Add extraction function scaffolding in base folder
tjazerzen 35d2934
Should not modify extraction function specification
tjazerzen 6134739
Simplify specification for emitting events
tjazerzen 346f5e1
Abstract not stringying error messages
tjazerzen 42353eb
Template for data fetching return expectation
tjazerzen e7840b4
Template for validating external sync unit
tjazerzen 0fcdd64
Template for "internal" client
tjazerzen f7eb9e5
Revert base folder runner
tjazerzen 942cbdf
Merge branch 'devrev:main' into main
tjazerzen 4ed14ce
Merge branch 'main' into feat/simplify-template-writing
tjazerzen dd8b0bf
Update docs/data-extraction-rules-for-emitting-events.md
tjazerzen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import extraction from './functions/extraction'; | ||
|
|
||
| export const functionFactory = { | ||
| // Add your functions here | ||
| extraction, | ||
| } as const; | ||
|
|
||
| export type FunctionFactoryType = keyof typeof functionFactory; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { convertToAirdropEvent } from '../../core/utils'; | ||
| import { FunctionInput } from '../../core/types'; | ||
| import { spawn, EventType } from '@devrev/ts-adaas'; | ||
|
|
||
| function getWorkerPerExtractionPhase(event: FunctionInput) { | ||
| let path; | ||
| switch (event.payload.event_type) { | ||
| case EventType.ExtractionExternalSyncUnitsStart: | ||
| path = __dirname + '/workers/external-sync-units-extraction'; | ||
| break; | ||
| case EventType.ExtractionMetadataStart: | ||
| path = __dirname + '/workers/metadata-extraction'; | ||
| break; | ||
| case EventType.ExtractionDataStart: | ||
| case EventType.ExtractionDataContinue: | ||
| path = __dirname + '/workers/data-extraction'; | ||
| break; | ||
| case EventType.ExtractionAttachmentsStart: | ||
| case EventType.ExtractionAttachmentsContinue: | ||
| path = __dirname + '/workers/attachments-extraction'; | ||
| break; | ||
| } | ||
| return path; | ||
| } | ||
|
|
||
| const run = async (events: FunctionInput[]) => { | ||
| for (const event of events) { | ||
| const file = getWorkerPerExtractionPhase(event); | ||
| await spawn({ | ||
| event: convertToAirdropEvent(event), | ||
| workerPath: file, | ||
| initialState: {}, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| export default run; |
6 changes: 6 additions & 0 deletions
6
base_folder/src/functions/extraction/workers/attachments-extraction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { processTask } from '@devrev/ts-adaas'; | ||
|
|
||
| processTask({ | ||
| task: async ({ adapter }) => {}, | ||
| onTimeout: async ({ adapter }) => {}, | ||
| }); |
6 changes: 6 additions & 0 deletions
6
base_folder/src/functions/extraction/workers/data-extraction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { processTask } from "@devrev/ts-adaas"; | ||
|
|
||
| processTask({ | ||
| task: async ({ adapter }) => {}, | ||
| onTimeout: async ({ adapter }) => {}, | ||
| }); |
6 changes: 6 additions & 0 deletions
6
base_folder/src/functions/extraction/workers/external-sync-units-extraction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { processTask } from "@devrev/ts-adaas"; | ||
|
|
||
| processTask({ | ||
| task: async ({ adapter }) => {}, | ||
| onTimeout: async ({ adapter }) => {}, | ||
| }); |
6 changes: 6 additions & 0 deletions
6
base_folder/src/functions/extraction/workers/metadata-extraction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { processTask } from '@devrev/ts-adaas'; | ||
|
|
||
| processTask({ | ||
| task: async ({ adapter }) => {}, | ||
| onTimeout: async ({ adapter }) => {}, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| - Test The Extraction Function with the following flow (The Attachment Test Flow): | ||
| - Step 1: Invoke The Extraction Function using the resource [{{ data_extraction_resource_name }}](test_data/{{ data_extraction_resource_name }}). | ||
| - Expect The Callback Server to receive from DevRev a **single** event with "event_type" that equals "EXTRACTION_DATA_DONE". | ||
| - Step 2: Invoke The Extraction Function using the resource [{{ attachment_extraction_resource_name }}](test_data/{{ attachment_extraction_resource_name }}). | ||
| - Expect The Callback Server to receive from DevRev a **single** event (`:= event_from_callback_server`) with "event_type" that equals "EXTRACTION_ATTACHMENTS_DONE". | ||
| - Expect `event_from_callback_server["event_data"]["artifacts"]` to be an array. Expect this array to not be empty. Expect this array to have length 1. | ||
| - Let `artifact_object = event_from_callback_server["event_data"]["artifacts"][0]`. | ||
| - Expect `artifact_object["item_type"] = "ssor_attachment"` and `artifact_object["item_count"] = {{ expected_attachment_count }}`. | ||
| - Make a GET request to "http://localhost:8003/is_uploaded/{artifact_object['id']}". Expect response code to be equal to 200. | ||
| - Note: The Attachment Test Flow should be executed within a single test. | ||
| Test The Extraction Function with the following flow (The Attachment Test Flow): | ||
| - Step 1: Invoke The Extraction Function using the resource [{{ data_extraction_resource_name }}](test_data/{{ data_extraction_resource_name }}). | ||
| - Expect The Callback Server to receive from DevRev a **single** event with "event_type" that equals "EXTRACTION_DATA_DONE". | ||
| - Step 2: Invoke The Extraction Function using the resource [{{ attachment_extraction_resource_name }}](test_data/{{ attachment_extraction_resource_name }}). | ||
| - Expect The Callback Server to receive from DevRev a **single** event (`:= event_from_callback_server`) with "event_type" that equals "EXTRACTION_ATTACHMENTS_DONE". | ||
| - Expect `event_from_callback_server["event_data"]["artifacts"]` to be an array. Expect this array to not be empty. Expect this array to have length 1. | ||
| - Let `artifact_object = event_from_callback_server["event_data"]["artifacts"][0]`. | ||
| - Expect `artifact_object["item_type"] = "ssor_attachment"` and `artifact_object["item_count"] = {{ expected_attachment_count }}`. | ||
| - Make a GET request to "http://localhost:8003/is_uploaded/{artifact_object['id']}". Expect response code to be equal to 200. | ||
| - Note: The Attachment Test Flow should be executed within a single test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| - Then, validate The Normalization Function with the chef-cli tool (The Chef CLI) using the command "chef-cli validate-data -m <The External Domain Metadata JSON object file> -r {{ record_type }}": | ||
| - To invoke the function that returns The External Domain Metadata JSON object, send the event [external_domain_metadata_event_payload.json](test_data/external_domain_metadata_event_payload.json) to The Snap-In server. | ||
| - The External Domain Metadata JSON object should then be stored in temporary file and provided as path to the validation of The Normalization Function. | ||
| - The Chef CLI reads the extracted file (The Extracted File) from stdin. | ||
| - The Extracted File is inside folder provided in the environment variable "EXTRACTED_FILES_FOLDER_PATH". To retrieve the relevant file name, command `ls EXTRACTED_FILES_FOLDER_PATH | grep extractor_{{ record_type }} | sort -r | head -n 1` should be executed. The test should always fail if The Extracted File is not present. | ||
| - Please note that the expected behaviour is that only after the invocation of The Extraction Function, the folder provided in the environment variable "EXTRACTED_FILES_FOLDER_PATH" should exist. The test should always fail if before the execution of The Chef CLI, the folder "EXTRACTED_FILES_FOLDER_PATH" does not exist or if The Extracted File is not found. | ||
| - The path to The Chef CLI executable is provided in the environment variable `CHEF_CLI_PATH`. | ||
| - For the validation of The Normalization Function to be successful The Chef CLI must return an empty output. The implementation of The Extraction Function directly infuences the output of The Chef CLI. | ||
| - The stdout and stderr of The Chef CLI *must* be printed to the console. | ||
| - The test should always fail if The Chef CLI is not available. | ||
| validate The Normalization Function with the chef-cli tool (The Chef CLI) using the command "chef-cli validate-data -m <The External Domain Metadata JSON object file> -r {{ record_type }}": | ||
| - To invoke the function that returns The External Domain Metadata JSON object, send the event [external_domain_metadata_event_payload.json](test_data/external_domain_metadata_event_payload.json) to The Snap-In server. | ||
| - The External Domain Metadata JSON object should then be stored in temporary file and provided as path to the validation of The Normalization Function. | ||
| - The Chef CLI reads the extracted file (The Extracted File) from stdin. | ||
| - The Extracted File is inside folder provided in the environment variable "EXTRACTED_FILES_FOLDER_PATH". To retrieve the relevant file name, command `ls EXTRACTED_FILES_FOLDER_PATH | grep extractor_{{ record_type }} | sort -r | head -n 1` should be executed. The test should always fail if The Extracted File is not present. | ||
| - Please note that the expected behaviour is that only after the invocation of The Extraction Function, the folder provided in the environment variable "EXTRACTED_FILES_FOLDER_PATH" should exist. The test should always fail if before the execution of The Chef CLI, the folder "EXTRACTED_FILES_FOLDER_PATH" does not exist or if The Extracted File is not found. | ||
| - The path to The Chef CLI executable is provided in the environment variable `CHEF_CLI_PATH`. | ||
| - For the validation of The Normalization Function to be successful The Chef CLI must return an empty output. The implementation of The Extraction Function directly infuences the output of The Chef CLI. | ||
| - The stdout and stderr of The Chef CLI *must* be printed to the console. | ||
| - The test should always fail if The Chef CLI is not available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| - Test The Extraction Function using the resource [{{ resource_name }}](test_data/{{ resource_name }}). | ||
| - Expect The Callback Server to receive from DevRev a **single** event with "event_type" that equals "EXTRACTION_DATA_DONE". | ||
| - Let `artifact_array = <event_from_callback_server>["event_data"]["artifacts"]` (array of objects). | ||
| - Expect `len(artifact_array) > 0`. | ||
| - Out of `artifact_array`, expect one of the elements to have "item_type" equal to "{{ artifact_name }}" (`:= {{ artifact_name }}_artifact`) and `{{ artifact_name }}_artifact["item_count"]={{ expected_item_count }}`. | ||
| - Note: If `{{ artifact_name }}_artifact["item_count"] < {{ expected_item_count }}`, this indicates that not all the {{ artifact_name }} data was extracted. | ||
| Test The Extraction Function using the resource [{{ resource_name }}](test_data/{{ resource_name }}). | ||
| - Expect The Callback Server to receive from DevRev a **single** event with "event_type" that equals "EXTRACTION_DATA_DONE". | ||
| - Let `artifact_array = <event_from_callback_server>["event_data"]["artifacts"]` (array of objects). | ||
| - Expect `len(artifact_array) > 0`. | ||
| - Out of `artifact_array`, expect one of the elements to have "item_type" equal to "{{ artifact_name }}" (`:= {{ artifact_name }}_artifact`) and `{{ artifact_name }}_artifact["item_count"]={{ expected_item_count }}`. | ||
| - Note: If `{{ artifact_name }}_artifact["item_count"] < {{ expected_item_count }}`, this indicates that not all the {{ artifact_name }} data was extracted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The Functions implemented *should* also return: | ||
| - `status_code` - a status code from The API. | ||
| - `api_delay` - Delay in seconds to wait before retrying the request to The API (if no rate limit, set to 0) | ||
| - `message` - Information about the call the The Function. | ||
| - Note: Every The Function should handle rate limiting. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Test The Extraction Function using the resource [{{ resource_name }}](test_data/{{ resource_name }}). | ||
| - Expect The Callback Server to receive *a single* event with "event_type" "EXTRACTION_EXTERNAL_SYNC_UNITS_DONE". | ||
| - Let `external_sync_units_array = <event_from_callback_server>["event_data"]["external_sync_units"]` (array of objects). | ||
| - Expect `external_sync_units_array` to exist and be an array. | ||
| - Expect `len(external_sync_units_array) = {{ expected_external_sync_unit_count }}`. | ||
| - Out of `external_sync_units_array`, expect that there exists and element that has "name" equal to "{{ expected_external_sync_unit_name }}". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The {{ external_system_name }} Internal Client is a TypeScript service that communicates with The API. These are the rules for The {{ external_system_name }} Internal Client: | ||
| - If we need to create a new request to The API, we must create a new method in The {{ external_system_name }} Internal Client. | ||
| - Communication with The API must be completely abstracted away from The Function. The Function must be able to initialize The {{ external_system_name }} Internal Client, call the relevant method from The {{ external_system_name }} Internal Client and get the response from The API. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.