MAGDA Connector SDK
Magda Connectors
are Magda backend processes that go out to external datasources and copy their metadata into the Magda registry, so that they can be searched and have other aspects attached to them. A connector is simply a docker-based microservice that is invoked as a job. It scans the target datasource (usually an open-data portal), then completes and shuts down. We have connectors for a number of existing open data formats, otherwise you can easily write and run your own.
This SDK provides scaffolding that help you to create your own (nodeJs based) connectors easily.
The following two packages may help connector devleopment as well:
Example
See magda-ckan-connector
Content
JsonConnector
A base class for connectors for most any JSON-based catalog source.
export declare class JsonConnector {
readonly source: ConnectorSource;
readonly transformer: JsonTransformer;
readonly registry: AuthorizedRegistryClient;
readonly maxConcurrency: number;
readonly sourceTag?: string;
readonly configData?: JsonConnectorConfig;
constructor({
source,
transformer,
registry,
maxConcurrency,
sourceTag
}: JsonConnectorOptions);
readConfigData(): JsonConnectorConfig;
createAspectDefinitions(): Promise<ConnectionResult>;
createOrganization(organizationJson: object): Promise<Record | Error>;
createDataset(datasetJson: object): Promise<Record | Error>;
createDistribution(
distributionJson: object,
datasetJson: object
): Promise<Record | Error>;
createOrganizations(): Promise<ConnectionResult>;
createDatasetsAndDistributions(): Promise<ConnectionResult>;
trimRecords(): Promise<ConnectionResult>;
run(): Promise<ConnectionResult>;
runInteractive(options: JsonConnectorRunInteractiveOptions): void;
private shutdownOnIdle;
putRecord(record: Record, recordType: RecordType): Promise<Record | Error>;
private attachConnectorDataToSource;
private attachConnectorPresetAspects;
}
JsonTransformer
A base class for transformers for most any JSON-based catalog source.
A transformer takes source data and transforms it to registry records and aspects.
export declare abstract class JsonTransformer {
readonly sourceId: string;
private datasetAspectBuilders;
private distributionAspectBuilders;
private organizationAspectBuilders;
private organizationAspects;
private datasetAspects;
private distributionAspects;
private tenantId;
constructor({
sourceId,
libraries,
datasetAspectBuilders,
distributionAspectBuilders,
organizationAspectBuilders
}: JsonTransformerOptions);
organizationJsonToRecord(jsonOrganization: object): Record;
datasetJsonToRecord(jsonDataset: object): Record;
distributionJsonToRecord(
jsonDistribution: object,
jsonDataset: object
): Record;
getRequiredAspectDefinitions(): AspectDefinition[];
abstract getIdFromJsonOrganization(
jsonOrganization: any,
sourceId: string
): ConnectorRecordId;
abstract getIdFromJsonDataset(
jsonDataset: any,
sourceId: string
): ConnectorRecordId;
abstract getIdFromJsonDistribution(
jsonDistribution: any,
jsonDataset: any,
sourceId: string
): ConnectorRecordId;
abstract getNameFromJsonOrganization(jsonOrganization: any): string;
abstract getNameFromJsonDataset(jsonDataset: any): string;
abstract getNameFromJsonDistribution(
jsonDistribution: any,
jsonDataset: any
): string;
reviseOrganizationRecord(record: Record): Record;
jsonToRecord(
id: ConnectorRecordId,
name: string,
json: any,
aspects: CompiledAspects
): Record;
}
AuthorizedRegistryClient
A Magda registry client.
export declare class AuthorizedRegistryClient extends RegistryClient {
protected options: AuthorizedRegistryOptions;
protected jwt: string;
constructor(options: AuthorizedRegistryOptions);
putAspectDefinition(
aspectDefinition: AspectDefinition,
tenantId?: number
): Promise<AspectDefinition | Error>;
postHook(hook: WebHook): Promise<WebHook | Error>;
putHook(hook: WebHook): Promise<WebHook | Error>;
getHook(hookId: string): Promise<Maybe<WebHook> | Error>;
getHooks(): Promise<WebHook[] | Error>;
resumeHook(
webhookId: string,
succeeded?: boolean,
lastEventIdReceived?: string,
active?: boolean
): Promise<WebHookAcknowledgementResponse | Error>;
putRecord(record: Record, tenantId?: number): Promise<Record | Error>;
putRecordAspect(
recordId: string,
aspectId: string,
aspect: any,
tenantId?: number
): Promise<Record | Error>;
patchRecordAspect(
recordId: string,
aspectId: string,
aspectPatch: Operation[],
tenantId?: number
): Promise<Record | Error>;
deleteBySource(
sourceTagToPreserve: string,
sourceId: string,
tenantId?: number
): Promise<MultipleDeleteResult | "Processing" | Error>;
}
Other Utils & typescript definitions
export declare interface AspectBuilder {
aspectDefinition: AspectDefinition;
builderFunctionString: string;
setupFunctionString?: string;
}
declare class AspectCreationFailure {
readonly id: string;
readonly error: Error;
constructor(id: string, error: Error);
}
declare class AspectDefinition {
"id": string;
"name": string;
"jsonSchema": any;
}
declare class AspectDefinitionsApi {
protected basePath: string;
protected defaultHeaders: any;
protected _useQuerystring: boolean;
protected authentications: any;
constructor(basePath?: string);
set useQuerystring(value: boolean);
setApiKey(key: AspectDefinitionsApiApiKeys, value: string): void;
create(
xMagdaTenantId: number,
aspect: AspectDefinition,
xMagdaSession: string
): Promise<{
response: http.IncomingMessage;
body: AspectDefinition;
}>;
getAll(
xMagdaTenantId: number
): Promise<{
response: http.IncomingMessage;
body: Array<AspectDefinition>;
}>;
getById(
xMagdaTenantId: number,
id: string
): Promise<{
response: http.IncomingMessage;
body: AspectDefinition;
}>;
patchById(
xMagdaTenantId: number,
id: string,
aspectPatch: Array<Operation>,
xMagdaSession: string
): Promise<{
response: http.IncomingMessage;
body: AspectDefinition;
}>;
putById(
xMagdaTenantId: number,
id: string,
aspect: AspectDefinition,
xMagdaSession: string
): Promise<{
response: http.IncomingMessage;
body: AspectDefinition;
}>;
}
export declare abstract class BuilderFunctionParameters {
setup: any;
transformer: JsonTransformer;
reportProblem: ReportProblem;
libraries: object;
[propName: string]: any;
}
export declare interface BuilderSetupFunctionParameters {
transformer: JsonTransformer;
libraries: object;
}
export declare function buildersToCompiledAspects(
builders: AspectBuilder[],
setupParameters: BuilderSetupFunctionParameters,
buildParameters: BuilderFunctionParameters
): CompiledAspects;
export declare function cleanOrgTitle(title: string): string;
export declare interface CompiledAspects {
parameterNames: string[];
parameters: BuilderFunctionParameters;
aspects: CompiledAspect[];
}
export declare class ConnectorRecordId {
readonly id: string;
readonly type: RecordType;
readonly sourceId: string;
constructor(id: string, type: RecordType, sourceId: string);
toString(): string;
private get typeId();
}
export declare interface ConnectorSource {
readonly id: string;
readonly name: string;
readonly extras?: JsonConnectorConfigExtraMetaData;
readonly presetRecordAspects?: JsonConnectorConfigPresetAspect[];
getJsonDatasets(): AsyncPage<any[]>;
getJsonDataset(id: string): Promise<any>;
searchDatasetsByTitle(title: string, maxResults: number): AsyncPage<any[]>;
getJsonDistributions(dataset: any): AsyncPage<any[]>;
readonly hasFirstClassOrganizations: boolean;
getJsonFirstClassOrganizations(): AsyncPage<any[]>;
getJsonFirstClassOrganization(id: string): Promise<any>;
searchFirstClassOrganizationsByTitle(
title: string,
maxResults: number
): AsyncPage<any[]>;
getJsonDatasetPublisherId(dataset: any): string;
getJsonDatasetPublisher(dataset: any): Promise<any>;
}
export declare interface JsonConnectorOptions {
source: ConnectorSource;
transformer: JsonTransformer;
registry: AuthorizedRegistryClient;
maxConcurrency?: number;
sourceTag?: string;
}
export declare interface JsonConnectorRunInteractiveOptions {
timeoutSeconds: number;
listenPort: number;
transformerOptions: any;
}
export declare interface JsonTransformerOptions {
sourceId: string;
libraries?: object;
datasetAspectBuilders?: AspectBuilder[];
distributionAspectBuilders?: AspectBuilder[];
organizationAspectBuilders?: AspectBuilder[];
maxConcurrency?: number;
tenantId: number;
}
export declare const TenantConsts: any;