ReferenceSDK and runtime

Route events to workers

Configure the SDK entry point and match incoming event types to packaged worker files.

Entry point and worker routing

A CommonJS-oriented extraction entry point under code/src/functions/extraction/index.ts uses the public SDK and the bundled template mapping. Stateful initialization requires a valid IDM when its version state is missing or changes:

import { AirSyncEvent, spawn } from '@devrev/airsync-sdk';
import initialDomainMapping from '../external-system/initial_domain_mapping.json';

type ConnectorState = { cursor: string | null; completed: boolean };

export async function run(events: AirSyncEvent[]): Promise<void> {
  for (const event of events) {
    await spawn<ConnectorState>({
      event,
      initialState: { cursor: null, completed: false },
      initialDomainMapping,
      baseWorkerPath: __dirname,
      options: { timeout: 60_000, batchSize: 2_000 },
    });
  }
}

baseWorkerPath is the directory containing workers/. Package compiled worker files with the snap-in. workerPathOverrides maps incoming EventType values to path suffixes (for example /workers/cleanup.js) appended to that base when a custom layout or deletion worker is needed. Follow the public template layout for bundle and manifest wiring.

Incoming event familyDefault workerCan continue?
START_EXTRACTING_EXTERNAL_SYNC_UNITSexternal-sync-units-extraction.jsNo
START_EXTRACTING_METADATA, CONTINUE_EXTRACTING_METADATAmetadata-extraction.jsYes
START_EXTRACTING_DATA, CONTINUE_EXTRACTING_DATAdata-extraction.jsYes
START_EXTRACTING_ATTACHMENTS, CONTINUE_EXTRACTING_ATTACHMENTSattachments-extraction.jsYes
START_LOADING_DATA, CONTINUE_LOADING_DATAload-data.jsYes
START_LOADING_ATTACHMENTS, CONTINUE_LOADING_ATTACHMENTSload-attachments.jsYes
State-deletion eventsNo default worker; SDK acknowledgementNo

A missing metadata worker is a configuration error. Do not assume a misspelled or unbundled required worker will complete successfully.

Related:

Last updated on