@magda/connector-sdk 2.3.2-alpha.0 → 2.3.2-alpha.1
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/dist/index.d.ts +19 -0
- package/dist/index.js +53 -7
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -218,6 +218,9 @@ export declare class ConnectionResult {
|
|
|
218
218
|
distributionsConnected: number;
|
|
219
219
|
recordsTrimmed: number;
|
|
220
220
|
trimStillProcessing: boolean;
|
|
221
|
+
organizationsSkiped: number;
|
|
222
|
+
datasetsSkiped: number;
|
|
223
|
+
distributionsSkiped: number;
|
|
221
224
|
aspectDefinitionFailures: AspectCreationFailure[];
|
|
222
225
|
organizationFailures: RecordCreationFailure[];
|
|
223
226
|
datasetFailures: RecordCreationFailure[];
|
|
@@ -255,6 +258,11 @@ export declare interface ConnectorSource {
|
|
|
255
258
|
* before use ConnectorSource.presetRecordAspects as backup --- more for test cases
|
|
256
259
|
*/
|
|
257
260
|
readonly presetRecordAspects?: JsonConnectorConfigPresetAspect[];
|
|
261
|
+
/**
|
|
262
|
+
* This field is not compulsory and JsonConnector will try to locate its value from commandline parameters
|
|
263
|
+
* before use ConnectorSource.customJsFilterCode as backup --- more for test cases
|
|
264
|
+
*/
|
|
265
|
+
readonly customJsFilterCode?: string;
|
|
258
266
|
/**
|
|
259
267
|
* Get all of the datasets as pages of objects.
|
|
260
268
|
*
|
|
@@ -398,7 +406,9 @@ export declare class JsonConnector {
|
|
|
398
406
|
readonly maxConcurrency: number;
|
|
399
407
|
readonly sourceTag?: string;
|
|
400
408
|
readonly configData?: JsonConnectorConfig;
|
|
409
|
+
private readonly recordFilterFunction;
|
|
401
410
|
constructor({ source, transformer, registry, maxConcurrency, sourceTag }: JsonConnectorOptions);
|
|
411
|
+
createRecordFilterFunction(): RecordFilterFunctionType;
|
|
402
412
|
readConfigData(): JsonConnectorConfig;
|
|
403
413
|
createAspectDefinitions(): Promise<ConnectionResult>;
|
|
404
414
|
createOrganization(organizationJson: object): Promise<Record_2 | Error>;
|
|
@@ -437,6 +447,13 @@ export declare interface JsonConnectorConfig {
|
|
|
437
447
|
ignoreOrganisationNames?: string[];
|
|
438
448
|
extras?: JsonConnectorConfigExtraMetaData;
|
|
439
449
|
presetRecordAspects?: JsonConnectorConfigPresetAspect[];
|
|
450
|
+
/**
|
|
451
|
+
* Custom JS code to filter out records
|
|
452
|
+
* The the following variables are available in scope:
|
|
453
|
+
* - jsonData: the original record json data before transformation
|
|
454
|
+
* - type: a string represent the type of the record. e.g. "Organization" | "Dataset" | "Distribution"
|
|
455
|
+
*/
|
|
456
|
+
customJsFilterCode?: string;
|
|
440
457
|
}
|
|
441
458
|
|
|
442
459
|
/**
|
|
@@ -740,6 +757,8 @@ declare class RecordCreationFailure {
|
|
|
740
757
|
constructor(id: ConnectorRecordId, parentId: ConnectorRecordId, error: Error);
|
|
741
758
|
}
|
|
742
759
|
|
|
760
|
+
declare type RecordFilterFunctionType = (jsonData: any, type: "Dataset" | "Distribution" | "Organization") => boolean;
|
|
761
|
+
|
|
743
762
|
declare class RecordHistoryApi {
|
|
744
763
|
protected basePath: string;
|
|
745
764
|
protected defaultHeaders: any;
|
package/dist/index.js
CHANGED
|
@@ -23547,6 +23547,12 @@ class ConnectionResult {
|
|
|
23547
23547
|
this.distributionsConnected = 0;
|
|
23548
23548
|
this.recordsTrimmed = 0;
|
|
23549
23549
|
this.trimStillProcessing = false;
|
|
23550
|
+
// skipped organizations due to user supplied record filter function
|
|
23551
|
+
this.organizationsSkiped = 0;
|
|
23552
|
+
// skipped dataset records due to user supplied record filter function
|
|
23553
|
+
this.datasetsSkiped = 0;
|
|
23554
|
+
// skipped distribution records due to user supplied record filter function
|
|
23555
|
+
this.distributionsSkiped = 0;
|
|
23550
23556
|
this.aspectDefinitionFailures = Array();
|
|
23551
23557
|
this.organizationFailures = Array();
|
|
23552
23558
|
this.datasetFailures = Array();
|
|
@@ -23563,6 +23569,9 @@ class ConnectionResult {
|
|
|
23563
23569
|
"Distributions Connected: " + this.distributionsConnected + "\n";
|
|
23564
23570
|
result +=
|
|
23565
23571
|
"Organizations Connected: " + this.organizationsConnected + "\n";
|
|
23572
|
+
result += "Datasets Skipped: " + this.datasetsSkiped + "\n";
|
|
23573
|
+
result += "Distributions Skipped: " + this.distributionsSkiped + "\n";
|
|
23574
|
+
result += "Organizations Skipped: " + this.organizationsSkiped + "\n";
|
|
23566
23575
|
result += "Records Trimmed: " + this.recordsTrimmed + "\n";
|
|
23567
23576
|
if (this.trimStillProcessing) {
|
|
23568
23577
|
result += "(trim still processing) \n";
|
|
@@ -23601,6 +23610,9 @@ class ConnectionResult {
|
|
|
23601
23610
|
total.organizationsConnected += result.organizationsConnected;
|
|
23602
23611
|
total.datasetsConnected += result.datasetsConnected;
|
|
23603
23612
|
total.distributionsConnected += result.distributionsConnected;
|
|
23613
|
+
total.organizationsSkiped += result.organizationsSkiped;
|
|
23614
|
+
total.datasetsSkiped += result.datasetsSkiped;
|
|
23615
|
+
total.distributionsSkiped += result.distributionsSkiped;
|
|
23604
23616
|
total.recordsTrimmed += result.recordsTrimmed;
|
|
23605
23617
|
total.trimStillProcessing =
|
|
23606
23618
|
result.trimStillProcessing || total.trimStillProcessing;
|
|
@@ -54146,8 +54158,19 @@ class JsonConnector {
|
|
|
54146
54158
|
this.maxConcurrency = maxConcurrency;
|
|
54147
54159
|
this.sourceTag = sourceTag;
|
|
54148
54160
|
this.configData = this.readConfigData();
|
|
54161
|
+
this.recordFilterFunction = this.createRecordFilterFunction();
|
|
54162
|
+
}
|
|
54163
|
+
createRecordFilterFunction() {
|
|
54164
|
+
var _a;
|
|
54165
|
+
if (!((_a = this.configData) === null || _a === void 0 ? void 0 : _a.customJsFilterCode)) {
|
|
54166
|
+
return () => true;
|
|
54167
|
+
}
|
|
54168
|
+
const code = this.configData.customJsFilterCode;
|
|
54169
|
+
const filterFunction = new Function("jsonData", "type", code);
|
|
54170
|
+
return filterFunction;
|
|
54149
54171
|
}
|
|
54150
54172
|
readConfigData() {
|
|
54173
|
+
var _a, _b;
|
|
54151
54174
|
try {
|
|
54152
54175
|
const argv = yargs_1.parse(process_1.default.argv);
|
|
54153
54176
|
if (!argv) {
|
|
@@ -54166,6 +54189,9 @@ class JsonConnector {
|
|
|
54166
54189
|
if (this.source.presetRecordAspects) {
|
|
54167
54190
|
configData.presetRecordAspects = this.source.presetRecordAspects;
|
|
54168
54191
|
}
|
|
54192
|
+
if ((_a = this.source) === null || _a === void 0 ? void 0 : _a.customJsFilterCode) {
|
|
54193
|
+
configData.customJsFilterCode = (_b = this.source) === null || _b === void 0 ? void 0 : _b.customJsFilterCode;
|
|
54194
|
+
}
|
|
54169
54195
|
}
|
|
54170
54196
|
else {
|
|
54171
54197
|
configData = {
|
|
@@ -54178,6 +54204,9 @@ class JsonConnector {
|
|
|
54178
54204
|
if (argv.presetRecordAspects) {
|
|
54179
54205
|
configData.presetRecordAspects = argv.presetRecordAspects;
|
|
54180
54206
|
}
|
|
54207
|
+
if (argv.customJsFilterCode) {
|
|
54208
|
+
configData.customJsFilterCode = argv.customJsFilterCode;
|
|
54209
|
+
}
|
|
54181
54210
|
}
|
|
54182
54211
|
}
|
|
54183
54212
|
else {
|
|
@@ -54245,6 +54274,10 @@ class JsonConnector {
|
|
|
54245
54274
|
if (!organization) {
|
|
54246
54275
|
return;
|
|
54247
54276
|
}
|
|
54277
|
+
if (this.recordFilterFunction(organization, "Organization") === false) {
|
|
54278
|
+
result.organizationsSkiped++;
|
|
54279
|
+
return;
|
|
54280
|
+
}
|
|
54248
54281
|
const recordOrError = yield this.createOrganization(organization);
|
|
54249
54282
|
if (recordOrError instanceof Error) {
|
|
54250
54283
|
result.organizationFailures.push(new RecordCreationFailure_1.default(this.transformer.getIdFromJsonOrganization(organization, this.source.id), undefined, recordOrError));
|
|
@@ -54262,11 +54295,19 @@ class JsonConnector {
|
|
|
54262
54295
|
const result = new ConnectionResult_1.default();
|
|
54263
54296
|
const datasets = this.source.getJsonDatasets();
|
|
54264
54297
|
yield AsyncPage_1.forEachAsync(datasets, this.maxConcurrency, (dataset) => __awaiter(this, void 0, void 0, function* () {
|
|
54298
|
+
if (this.recordFilterFunction(dataset, "Dataset") === false) {
|
|
54299
|
+
result.datasetsSkiped++;
|
|
54300
|
+
return;
|
|
54301
|
+
}
|
|
54265
54302
|
const record = this.transformer.datasetJsonToRecord(dataset);
|
|
54266
54303
|
const distributions = this.source.getJsonDistributions(dataset);
|
|
54267
54304
|
if (distributions) {
|
|
54268
54305
|
const distributionIds = [];
|
|
54269
54306
|
yield AsyncPage_1.forEachAsync(distributions, 1, (distribution) => __awaiter(this, void 0, void 0, function* () {
|
|
54307
|
+
if (this.recordFilterFunction(distribution, "Distribution") === false) {
|
|
54308
|
+
result.distributionsSkiped++;
|
|
54309
|
+
return;
|
|
54310
|
+
}
|
|
54270
54311
|
const recordOrError = yield this.createDistribution(distribution, dataset);
|
|
54271
54312
|
if (recordOrError instanceof Error) {
|
|
54272
54313
|
result.distributionFailures.push(new RecordCreationFailure_1.default(this.transformer.getIdFromJsonDistribution(distribution, dataset, this.source.id), this.transformer.getIdFromJsonDataset(dataset, this.source.id), recordOrError));
|
|
@@ -54293,15 +54334,20 @@ class JsonConnector {
|
|
|
54293
54334
|
if (publisher) {
|
|
54294
54335
|
const publisherId = this.transformer.getIdFromJsonOrganization(publisher, this.source.id);
|
|
54295
54336
|
if (publisherId) {
|
|
54296
|
-
|
|
54297
|
-
|
|
54298
|
-
result.organizationFailures.push(new RecordCreationFailure_1.default(publisherId, undefined, recordOrError));
|
|
54337
|
+
if (this.recordFilterFunction(publisher, "Organization") === false) {
|
|
54338
|
+
result.distributionsSkiped++;
|
|
54299
54339
|
}
|
|
54300
54340
|
else {
|
|
54301
|
-
|
|
54302
|
-
|
|
54303
|
-
|
|
54304
|
-
|
|
54341
|
+
const recordOrError = yield this.createOrganization(publisher);
|
|
54342
|
+
if (recordOrError instanceof Error) {
|
|
54343
|
+
result.organizationFailures.push(new RecordCreationFailure_1.default(publisherId, undefined, recordOrError));
|
|
54344
|
+
}
|
|
54345
|
+
else {
|
|
54346
|
+
record.aspects["dataset-publisher"] = {
|
|
54347
|
+
publisher: publisherId.toString()
|
|
54348
|
+
};
|
|
54349
|
+
++result.organizationsConnected;
|
|
54350
|
+
}
|
|
54305
54351
|
}
|
|
54306
54352
|
}
|
|
54307
54353
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magda/connector-sdk",
|
|
3
3
|
"description": "MAGDA Connector SDK",
|
|
4
|
-
"version": "2.3.2-alpha.
|
|
4
|
+
"version": "2.3.2-alpha.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
|
|
7
7
|
"compile": "webpack && webpack --env.target=web",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"browser": "dist/index-web.js",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@magda/typescript-common": "^2.3.2-alpha.
|
|
17
|
+
"@magda/typescript-common": "^2.3.2-alpha.1",
|
|
18
18
|
"@microsoft/api-extractor": "7.15.2",
|
|
19
19
|
"ts-loader": "^6.2.1",
|
|
20
20
|
"typescript": "~4.2.4",
|