Skip to content
Draft
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
46 changes: 46 additions & 0 deletions MIGRATION_REVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# v2 Migration Review

Migrated `@devrev/ts-adaas` 1.20.0 → `@devrev/airsync-sdk` 2.0.0-beta.6.
Baseline was already the latest stable v1 (1.20.0, migration-free), so no v1
baseline upgrade was needed. Only sections needing a second look are noted; the
rest applied cleanly.

## Sections

- §1 package rename — high
- §2 `AirdropEvent` → `AirSyncEvent` — high
- §3 worker split (`processExtractionTask` / `processLoadingTask`) — high
- §4 emit → return — high
- §4 onTimeout rewrites — medium: the progress-only `onTimeout` handlers in
`data-extraction` (resumable) and both loading workers were **deleted** — the
SDK's phase-aware default emits the same continuation. The `metadata` and
`external-sync-units` handlers were **kept** and converted to
`return { status: 'error', error: {...} }` because each carried a custom
timeout message that the SDK default would otherwise replace with a generated
one. Confirm these two non-resumable phases should still surface those exact
messages.
- §6 loading pass-through (`load-data`, `load-attachments`) — high
- §6 attachment streaming (`attachments-extraction`) — medium: replaced the v1
`streamAttachments` result branching (delay/error/done emits) with a straight
`return adapter.streamAttachments(...)`. This also dropped the surrounding
`try/catch` whose only action was `console.error` + swallow (it emitted
nothing). The returned `TaskResult` already encodes delay/error/success, so
behavior is preserved or improved; confirm no bespoke catch handling is
wanted here.
- §7 external sync units via repo — high (connector already pushed ESUs to the
`EXTERNAL_SYNC_UNITS` repo; only the trailing emit changed to `return`)
- §10 `Mappers` `.data` unwrap — high (only a commented-out template example was
updated; no live mapper read exists in this connector)

Verified no-ops (no code changed): §5 (no `WorkerAdapter` annotations/
constructions), §8 (no SDK fields in `ExtractorState`/`LoaderState`, no
`lastSync*`, no `AdapterState`), §9 (connector imports `axios` directly, never
the SDK axios surface; no `statusCode` on the streaming error), §11–§15 (no
legacy modules, deleted enum members, deep imports, or `workerPath`), §16 (the
connector has no jest test suite).

## Verification

tsc ✓ · lint ✓ · build ✓ · test — n/a (no jest suite; `npm test` reports "No
tests found" on both the pre-migration and post-migration tree — a pre-existing
condition, not caused by this migration).
14 changes: 7 additions & 7 deletions code/package-lock.json

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

2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"yargs": "^17.6.2"
},
"dependencies": {
"@devrev/ts-adaas": "1.20.0",
"@devrev/airsync-sdk": "2.0.0-beta.6",
"@devrev/typescript-sdk": "1.1.78",
"axios": "^1.16.0",
"dotenv": "^16.0.3",
Expand Down
2 changes: 1 addition & 1 deletion code/src/functions/external-system/data-denormalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExternalSystemAttachment, ExternalSystemItem } from '@devrev/ts-adaas';
import { ExternalSystemAttachment, ExternalSystemItem } from '@devrev/airsync-sdk';
import { ExternalAttachment, ExternalTodo } from './types';

export function denormalizeTodo(item: ExternalSystemItem): ExternalTodo {
Expand Down
2 changes: 1 addition & 1 deletion code/src/functions/external-system/data-normalization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExternalSyncUnit, NormalizedAttachment, NormalizedItem } from '@devrev/ts-adaas';
import { ExternalSyncUnit, NormalizedAttachment, NormalizedItem } from '@devrev/airsync-sdk';
import { ExternalAttachment, ExternalTodo, ExternalTodoList, ExternalUser } from './types';

// TODO: Replace with your actual normalization functions that will be used to
Expand Down
4 changes: 2 additions & 2 deletions code/src/functions/external-system/http-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AirdropEvent, ExternalSystemItemLoadingResponse } from '@devrev/ts-adaas';
import { AirSyncEvent, ExternalSystemItemLoadingResponse } from '@devrev/airsync-sdk';
import { ExternalAttachment, ExternalTodo, ExternalTodoList, ExternalUser } from './types';

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -85,7 +85,7 @@ export class HttpClient {
private apiEndpoint: string;
private apiToken: string;

constructor(event: AirdropEvent) {
constructor(event: AirSyncEvent) {
// TODO: Replace with the API endpoint of the external system. This is
// passed through the event payload (e.g. event.payload.connection_data.org_id
// or a keyring subdomain field).
Expand Down
4 changes: 2 additions & 2 deletions code/src/functions/extraction/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AirdropEvent, spawn } from '@devrev/ts-adaas';
import { AirSyncEvent, spawn } from '@devrev/airsync-sdk';

import initialDomainMapping from '../external-system/initial_domain_mapping.json';

Expand All @@ -19,7 +19,7 @@ export const initialExtractorState: ExtractorState = {
attachments: { completed: false },
};

const run = async (events: AirdropEvent[]) => {
const run = async (events: AirSyncEvent[]) => {
for (const event of events) {
await spawn<ExtractorState>({
event,
Expand Down
38 changes: 9 additions & 29 deletions code/src/functions/extraction/workers/attachments-extraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import axios from 'axios';
import {
ExternalSystemAttachmentStreamingParams,
ExternalSystemAttachmentStreamingResponse,
ExtractorEventType,
processTask,
} from '@devrev/ts-adaas';
processExtractionTask,
} from '@devrev/airsync-sdk';

// TODO: Replace with function for fetching attachment streams from the
// external system. This function should return either a stream of the
Expand Down Expand Up @@ -47,33 +46,14 @@ async function getFileStream({
}
}

processTask({
processExtractionTask({
task: async ({ adapter }) => {
try {
const response = await adapter.streamAttachments({
stream: getFileStream,
return adapter.streamAttachments({
stream: getFileStream,

// TODO: If needed you can specify how many attachments to stream at
// once. Minimum is 1 and maximum is 50.
// batchSize: 10,
});

if (response?.delay) {
await adapter.emit(ExtractorEventType.AttachmentExtractionDelayed, {
delay: response.delay,
});
} else if (response?.error) {
await adapter.emit(ExtractorEventType.AttachmentExtractionError, {
error: response.error,
});
} else {
await adapter.emit(ExtractorEventType.AttachmentExtractionDone);
}
} catch (error) {
console.error('An error occured while processing a task.', error);
}
},
onTimeout: async ({ adapter }) => {
await adapter.emit(ExtractorEventType.AttachmentExtractionProgress);
// TODO: If needed you can specify how many attachments to stream at
// once. Minimum is 1 and maximum is 50.
// batchSize: 10,
});
},
});
13 changes: 5 additions & 8 deletions code/src/functions/extraction/workers/data-extraction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtractorEventType, processTask } from '@devrev/ts-adaas';
import { processExtractionTask } from '@devrev/airsync-sdk';

import { normalizeAttachment, normalizeTodo, normalizeUser } from '../../external-system/data-normalization';
import { HttpClient } from '../../external-system/http-client';
Expand Down Expand Up @@ -48,7 +48,7 @@ const itemTypesToExtract: ItemTypeToExtract[] = [
},
];

processTask<ExtractorState>({
processExtractionTask<ExtractorState>({
task: async ({ adapter }) => {
adapter.initializeRepos(repos);

Expand All @@ -60,9 +60,9 @@ processTask<ExtractorState>({
// system. This is just an example how you can iterate over the item types,
// extract them, push them to the repo, and save the state.
for (const itemTypeToExtract of itemTypesToExtract) {
// If the worker is about to time out, exit early so that `onTimeout` can run and emit progress.
// If the worker is about to time out, hand off for continuation.
if (adapter.isTimeout) {
return;
return { status: 'progress' };
}

if (!adapter.shouldExtract(itemTypeToExtract.name)) {
Expand All @@ -75,9 +75,6 @@ processTask<ExtractorState>({
adapter.state[itemTypeToExtract.name].completed = true;
}

await adapter.emit(ExtractorEventType.DataExtractionDone);
},
onTimeout: async ({ adapter }) => {
await adapter.emit(ExtractorEventType.DataExtractionProgress);
return { status: 'success' };
},
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
AirSyncDefaultItemTypes,
ExternalSyncUnit,
ExtractorEventType,
processTask,
} from '@devrev/ts-adaas';
processExtractionTask,
} from '@devrev/airsync-sdk';

import { normalizeTodoList } from '../../external-system/data-normalization';
import { HttpClient } from '../../external-system/http-client';

processTask({
processExtractionTask({
task: async ({ adapter }) => {
adapter.initializeRepos([
{
Expand Down Expand Up @@ -36,13 +35,12 @@ processTask({
.getRepo(AirSyncDefaultItemTypes.EXTERNAL_SYNC_UNITS)
?.push(externalSyncUnits);

await adapter.emit(ExtractorEventType.ExternalSyncUnitExtractionDone);
},
onTimeout: async ({ adapter }) => {
await adapter.emit(ExtractorEventType.ExternalSyncUnitExtractionError, {
error: {
message: 'Failed to extract external sync units. Lambda timeout.',
},
});
return { status: 'success' };
},
onTimeout: async () => ({
status: 'error',
error: {
message: 'Failed to extract external sync units. Lambda timeout.',
},
}),
});
15 changes: 7 additions & 8 deletions code/src/functions/extraction/workers/metadata-extraction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtractorEventType, processTask } from '@devrev/ts-adaas';
import { processExtractionTask } from '@devrev/airsync-sdk';

import staticExternalDomainMetadata from '../../external-system/external_domain_metadata.json';

Expand All @@ -8,7 +8,7 @@ const repos = [
},
];

processTask({
processExtractionTask({
task: async ({ adapter }) => {
adapter.initializeRepos(repos);

Expand All @@ -21,11 +21,10 @@ processTask({
};

await adapter.getRepo('external_domain_metadata')?.push([externalDomainMetadata]);
await adapter.emit(ExtractorEventType.MetadataExtractionDone);
},
onTimeout: async ({ adapter }) => {
await adapter.emit(ExtractorEventType.MetadataExtractionError, {
error: { message: 'Failed to extract metadata. Lambda timeout.' },
});
return { status: 'success' };
},
onTimeout: async () => ({
status: 'error',
error: { message: 'Failed to extract metadata. Lambda timeout.' },
}),
});
4 changes: 2 additions & 2 deletions code/src/functions/loading/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AirdropEvent, spawn } from '@devrev/ts-adaas';
import { AirSyncEvent, spawn } from '@devrev/airsync-sdk';

import initialDomainMapping from '../external-system/initial_domain_mapping.json';

Expand All @@ -11,7 +11,7 @@ export interface LoaderState {}
// This state will be used as a starting point for the loading process.
export const initialLoaderState: LoaderState = {};

const run = async (events: AirdropEvent[]) => {
const run = async (events: AirSyncEvent[]) => {
for (const event of events) {
await spawn<LoaderState>({
event,
Expand Down
20 changes: 4 additions & 16 deletions code/src/functions/loading/workers/load-attachments.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {
ExternalSystemAttachment,
ExternalSystemItemLoadingParams,
LoaderEventType,
processTask,
} from '@devrev/ts-adaas';
processLoadingTask,
} from '@devrev/airsync-sdk';

import { denormalizeAttachment } from '../../external-system/data-denormalization';
import { HttpClient } from '../../external-system/http-client';
Expand All @@ -23,21 +22,10 @@ async function createAttachment({ item, mappers, event }: ExternalSystemItemLoad
return createAttachmentResponse;
}

processTask<LoaderState>({
processLoadingTask<LoaderState>({
task: async ({ adapter }) => {
const { reports, processed_files } = await adapter.loadAttachments({
return adapter.loadAttachments({
create: createAttachment,
});

await adapter.emit(LoaderEventType.AttachmentLoadingDone, {
reports,
processed_files,
});
},
onTimeout: async ({ adapter }) => {
await adapter.emit(LoaderEventType.AttachmentLoadingProgress, {
reports: adapter.reports,
processed_files: adapter.processedFiles,
});
},
});
22 changes: 5 additions & 17 deletions code/src/functions/loading/workers/load-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {
ExternalSystemItem,
ExternalSystemItemLoadingParams,
ExternalSystemItemLoadingResponse,
LoaderEventType,
processTask,
} from '@devrev/ts-adaas';
processLoadingTask,
} from '@devrev/airsync-sdk';

import { denormalizeTodo } from '../../external-system/data-denormalization';
import { HttpClient } from '../../external-system/http-client';
Expand Down Expand Up @@ -50,17 +49,17 @@ async function updateTodo({
// sync_unit: event.payload.event_context.sync_unit,
// target: item.id.devrev,
// });
// const todoExternalId = syncMapperRecordResponse.data.sync_mapper_record.external_ids[0];
// const todoExternalId = syncMapperRecordResponse.sync_mapper_record.external_ids[0];

const todo = denormalizeTodo(item);

const updateTodoResponse = await httpClient.updateTodo(todo);
return updateTodoResponse;
}

processTask<LoaderState>({
processLoadingTask<LoaderState>({
task: async ({ adapter }) => {
const { reports, processed_files } = await adapter.loadItemTypes({
return adapter.loadItemTypes({
itemTypesToLoad: [
{
itemType: 'todos',
Expand All @@ -69,16 +68,5 @@ processTask<LoaderState>({
},
],
});

await adapter.emit(LoaderEventType.DataLoadingDone, {
reports,
processed_files,
});
},
onTimeout: async ({ adapter }) => {
await adapter.emit(LoaderEventType.DataLoadingProgress, {
reports: adapter.reports,
processed_files: adapter.processedFiles,
});
},
});
Loading
Loading