airbyte-faros-destination 0.4.49 → 0.4.51
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/lib/common/graphql-writer.d.ts +6 -2
- package/lib/common/graphql-writer.js +4 -4
- package/lib/common/graphql-writer.js.map +1 -1
- package/lib/common/types.d.ts +2 -0
- package/lib/common/types.js.map +1 -1
- package/lib/converters/azure-repos/commits.d.ts +7 -0
- package/lib/converters/azure-repos/commits.js +60 -0
- package/lib/converters/azure-repos/commits.js.map +1 -0
- package/lib/converters/azure-repos/common.d.ts +10 -1
- package/lib/converters/azure-repos/common.js +12 -0
- package/lib/converters/azure-repos/common.js.map +1 -1
- package/lib/converters/azure-repos/models.d.ts +8 -1
- package/lib/converters/azure-repos/models.js.map +1 -1
- package/lib/converters/azure-repos/pull_requests.js +7 -14
- package/lib/converters/azure-repos/pull_requests.js.map +1 -1
- package/lib/converters/azure-repos/repositories.js +9 -46
- package/lib/converters/azure-repos/repositories.js.map +1 -1
- package/lib/converters/jsonata.d.ts +3 -2
- package/lib/converters/jsonata.js +36 -5
- package/lib/converters/jsonata.js.map +1 -1
- package/lib/destination.js +21 -1
- package/lib/destination.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -5
- package/resources/spec.json +25 -7
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import { Dictionary } from 'ts-essentials';
|
|
1
2
|
import { GraphQLClient } from './graphql-client';
|
|
2
3
|
import { WriteStats } from './write-stats';
|
|
3
4
|
export interface RecordProcessorHandler {
|
|
4
5
|
handleRecordProcessingError: (stats: WriteStats, processRecord: () => Promise<void>) => Promise<void>;
|
|
5
6
|
}
|
|
7
|
+
export interface OriginProvider {
|
|
8
|
+
getOrigin: (record: Dictionary<any>) => string;
|
|
9
|
+
}
|
|
6
10
|
export declare class GraphQLWriter {
|
|
7
11
|
private readonly graphQLClient;
|
|
8
|
-
private readonly
|
|
12
|
+
private readonly originProvider;
|
|
9
13
|
private readonly stats;
|
|
10
14
|
private readonly recordProcessorHandler;
|
|
11
15
|
private readonly timestampedRecords;
|
|
12
|
-
constructor(graphQLClient: GraphQLClient,
|
|
16
|
+
constructor(graphQLClient: GraphQLClient, originProvider: OriginProvider, stats: WriteStats, recordProcessorHandler: RecordProcessorHandler);
|
|
13
17
|
write(result: any): Promise<boolean>;
|
|
14
18
|
end(): Promise<void>;
|
|
15
19
|
}
|
|
@@ -5,9 +5,9 @@ const lodash_1 = require("lodash");
|
|
|
5
5
|
const verror_1 = require("verror");
|
|
6
6
|
const types_1 = require("./types");
|
|
7
7
|
class GraphQLWriter {
|
|
8
|
-
constructor(graphQLClient,
|
|
8
|
+
constructor(graphQLClient, originProvider, stats, recordProcessorHandler) {
|
|
9
9
|
this.graphQLClient = graphQLClient;
|
|
10
|
-
this.
|
|
10
|
+
this.originProvider = originProvider;
|
|
11
11
|
this.stats = stats;
|
|
12
12
|
this.recordProcessorHandler = recordProcessorHandler;
|
|
13
13
|
this.timestampedRecords = [];
|
|
@@ -15,14 +15,14 @@ class GraphQLWriter {
|
|
|
15
15
|
async write(result) {
|
|
16
16
|
const [baseModel, operation] = result.model.split('__', 2);
|
|
17
17
|
if (!operation) {
|
|
18
|
-
await this.graphQLClient.writeRecord(result.model, result.record, this.
|
|
18
|
+
await this.graphQLClient.writeRecord(result.model, result.record, this.originProvider.getOrigin(result.record));
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
else if (Object.values(types_1.Operation).includes(operation)) {
|
|
22
22
|
this.timestampedRecords.push({
|
|
23
23
|
model: baseModel,
|
|
24
24
|
operation,
|
|
25
|
-
origin: this.
|
|
25
|
+
origin: this.originProvider.getOrigin(result.record),
|
|
26
26
|
...result.record,
|
|
27
27
|
});
|
|
28
28
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-writer.js","sourceRoot":"","sources":["../../src/common/graphql-writer.ts"],"names":[],"mappings":";;;AAAA,mCAA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CAAC;IAED,KAAK,CAAC,GAAG;QACP,KAAK,MAAM,MAAM,IAAI,IAAA,eAAM,EAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;YACjE,MAAM,IAAI,CAAC,sBAAsB,CAAC,2BAA2B,CAC3D,IAAI,CAAC,KAAK,EACV,KAAK,IAAI,EAAE;gBACT,MAAM,IAAI,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;gBAC5B,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAChC,GAAG,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,SAAS,EAAE,CACvC,CAAC;YACJ,CAAC,CACF,CAAC;SACH;QACD,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IACnC,CAAC;CACF;AAlDD,sCAkDC"}
|
package/lib/common/types.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface DestinationConfig extends AirbyteConfig {
|
|
|
17
17
|
readonly jsonata_expression?: string;
|
|
18
18
|
readonly jsonata_mode?: JSONataApplyMode;
|
|
19
19
|
readonly origin?: string;
|
|
20
|
+
readonly accept_input_records_origin?: boolean;
|
|
21
|
+
readonly replace_origin_map?: string;
|
|
20
22
|
readonly source_specific_configs?: Dictionary<any>;
|
|
21
23
|
readonly keep_alive?: boolean;
|
|
22
24
|
}
|
package/lib/common/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":";;;AAKA,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,kCAAuB,CAAA;IACvB,0BAAe,CAAA;AACjB,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAED,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":";;;AAKA,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,kCAAuB,CAAA;IACvB,0BAAe,CAAA;AACjB,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAED,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,sCAAa,CAAA;AACf,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAgBD,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;IACjB,kCAAqB,CAAA;AACvB,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AirbyteRecord } from 'faros-airbyte-cdk';
|
|
2
|
+
import { DestinationModel, DestinationRecord } from '../converter';
|
|
3
|
+
import { AzureReposConverter } from './common';
|
|
4
|
+
export declare class Commits extends AzureReposConverter {
|
|
5
|
+
readonly destinationModels: ReadonlyArray<DestinationModel>;
|
|
6
|
+
convert(record: AirbyteRecord): Promise<ReadonlyArray<DestinationRecord>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Commits = void 0;
|
|
4
|
+
const faros_js_client_1 = require("faros-js-client");
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
class Commits extends common_1.AzureReposConverter {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.destinationModels = [
|
|
10
|
+
'vcs_Commit',
|
|
11
|
+
'vcs_BranchCommitAssociation',
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
async convert(record) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
const source = this.streamName.source;
|
|
17
|
+
const commitItem = record.record.data;
|
|
18
|
+
const res = [];
|
|
19
|
+
const organizationName = this.getOrganizationFromUrl(commitItem.url);
|
|
20
|
+
const organization = { uid: organizationName, source };
|
|
21
|
+
if (!commitItem.repository)
|
|
22
|
+
return res;
|
|
23
|
+
const projectRepo = this.getProjectRepo(commitItem.repository);
|
|
24
|
+
const repository = {
|
|
25
|
+
name: projectRepo,
|
|
26
|
+
uid: projectRepo,
|
|
27
|
+
organization,
|
|
28
|
+
};
|
|
29
|
+
res.push({
|
|
30
|
+
model: 'vcs_Commit',
|
|
31
|
+
record: {
|
|
32
|
+
sha: commitItem.commitId,
|
|
33
|
+
uid: commitItem.commitId,
|
|
34
|
+
message: commitItem.comment,
|
|
35
|
+
htmlUrl: commitItem.remoteUrl,
|
|
36
|
+
createdAt: faros_js_client_1.Utils.toDate((_a = commitItem.committer) === null || _a === void 0 ? void 0 : _a.date),
|
|
37
|
+
author: { uid: (_b = commitItem.author) === null || _b === void 0 ? void 0 : _b.email, source },
|
|
38
|
+
repository,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
res.push({
|
|
42
|
+
model: 'vcs_BranchCommitAssociation',
|
|
43
|
+
record: {
|
|
44
|
+
commit: {
|
|
45
|
+
sha: commitItem.commitId,
|
|
46
|
+
uid: commitItem.commitId,
|
|
47
|
+
repository,
|
|
48
|
+
},
|
|
49
|
+
branch: {
|
|
50
|
+
name: (_c = commitItem.branch) === null || _c === void 0 ? void 0 : _c.name,
|
|
51
|
+
uid: (_d = commitItem.branch) === null || _d === void 0 ? void 0 : _d.name,
|
|
52
|
+
repository,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return res;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Commits = Commits;
|
|
60
|
+
//# sourceMappingURL=commits.js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,KAAK,EAAE,MAAM,EAAC;gBAC/C,UAAU;aACX;SACF,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC;YACP,KAAK,EAAE,6BAA6B;YACpC,MAAM,EAAE;gBACN,MAAM,EAAE;oBACN,GAAG,EAAE,UAAU,CAAC,QAAQ;oBACxB,GAAG,EAAE,UAAU,CAAC,QAAQ;oBACxB,UAAU;iBACX;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,MAAA,UAAU,CAAC,MAAM,0CAAE,IAAI;oBAC7B,GAAG,EAAE,MAAA,UAAU,CAAC,MAAM,0CAAE,IAAI;oBAC5B,UAAU;iBACX;aACF;SACF,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAtDD,0BAsDC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AirbyteRecord } from 'faros-airbyte-cdk';
|
|
2
2
|
import { Converter } from '../converter';
|
|
3
|
-
import { PullRequestReviewState, PullRequestState } from './models';
|
|
3
|
+
import { CommitRepository, PullRequestReviewState, PullRequestState } from './models';
|
|
4
4
|
export type ApplicationMapping = Record<string, {
|
|
5
5
|
name: string;
|
|
6
6
|
platform?: string;
|
|
@@ -11,6 +11,15 @@ export declare abstract class AzureReposConverter extends Converter {
|
|
|
11
11
|
/** Almost every Azurerepos record have id property */
|
|
12
12
|
id(record: AirbyteRecord): any;
|
|
13
13
|
getOrganizationFromUrl(url: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Azure repos have an additional hierarchy called 'project'.
|
|
16
|
+
* Repository names are not unique across projects so we must include
|
|
17
|
+
* the project name to make sure there are no collisions.
|
|
18
|
+
*
|
|
19
|
+
* @param repository The repository info which contains project info
|
|
20
|
+
* @returns The identifier for a repo unique across projects
|
|
21
|
+
*/
|
|
22
|
+
getProjectRepo(repository: CommitRepository): string;
|
|
14
23
|
convertStringToNumber(str: string): number;
|
|
15
24
|
convertPullRequestState(status: string): PullRequestState;
|
|
16
25
|
convertPullRequestReviewState(vote: number): PullRequestReviewState;
|
|
@@ -17,6 +17,18 @@ class AzureReposConverter extends converter_1.Converter {
|
|
|
17
17
|
getOrganizationFromUrl(url) {
|
|
18
18
|
return url.split('/')[3];
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Azure repos have an additional hierarchy called 'project'.
|
|
22
|
+
* Repository names are not unique across projects so we must include
|
|
23
|
+
* the project name to make sure there are no collisions.
|
|
24
|
+
*
|
|
25
|
+
* @param repository The repository info which contains project info
|
|
26
|
+
* @returns The identifier for a repo unique across projects
|
|
27
|
+
*/
|
|
28
|
+
getProjectRepo(repository) {
|
|
29
|
+
var _a;
|
|
30
|
+
return `${(_a = repository === null || repository === void 0 ? void 0 : repository.project) === null || _a === void 0 ? void 0 : _a.name}_${repository === null || repository === void 0 ? void 0 : repository.name}`;
|
|
31
|
+
}
|
|
20
32
|
convertStringToNumber(str) {
|
|
21
33
|
const lastString = str.split('-')[str.split('-').length - 1];
|
|
22
34
|
const onlyNumbers = lastString.replace(/[^\d.-]/g, '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/common.ts"],"names":[],"mappings":";;;AAEA,4CAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/common.ts"],"names":[],"mappings":";;;AAEA,4CAAuC;AACvC,qCAMkB;AAOlB,gCAAgC;AAChC,MAAsB,mBAAoB,SAAQ,qBAAS;IAA3D;;QACE,WAAM,GAAG,aAAa,CAAC;IA0EzB,CAAC;IAzEC,sDAAsD;IACtD,EAAE,CAAC,MAAqB;;QACtB,OAAO,MAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,0CAAE,IAAI,0CAAE,EAAE,CAAC;IAClC,CAAC;IAED,sBAAsB,CAAC,GAAW;QAChC,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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AE,uCAA8B,CAAC,SAAS;gBAClD,MAAM,EAAE,QAAQ,IAAI,EAAE;aACvB,CAAC;QACJ,IAAI,IAAI,GAAG,CAAC,CAAC;YACX,OAAO;gBACL,QAAQ,EAAE,uCAA8B,CAAC,MAAM;gBAC/C,MAAM,EAAE,QAAQ,IAAI,EAAE;aACvB,CAAC;QACJ,OAAO;YACL,QAAQ,EAAE,uCAA8B,CAAC,SAAS;YAClD,MAAM,EAAE,QAAQ,IAAI,EAAE;SACvB,CAAC;IACJ,CAAC;CACF;AA3ED,kDA2EC"}
|
|
@@ -21,7 +21,6 @@ export interface Branch {
|
|
|
21
21
|
aheadCount: number;
|
|
22
22
|
behindCount: number;
|
|
23
23
|
isBaseVersion: boolean;
|
|
24
|
-
commits: Commit[];
|
|
25
24
|
}
|
|
26
25
|
interface TagCommitObject {
|
|
27
26
|
objectId: string;
|
|
@@ -150,6 +149,14 @@ export interface Commit {
|
|
|
150
149
|
changeCounts: CommitChange;
|
|
151
150
|
url: string;
|
|
152
151
|
remoteUrl: string;
|
|
152
|
+
repository: CommitRepository;
|
|
153
|
+
branch: Branch;
|
|
154
|
+
}
|
|
155
|
+
export interface CommitRepository {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
url: string;
|
|
159
|
+
project: Project;
|
|
153
160
|
}
|
|
154
161
|
interface Href {
|
|
155
162
|
href: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/models.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/models.ts"],"names":[],"mappings":";;;AAiNA,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,gDAA6B,CAAA;IAC7B,0CAAuB,CAAA;IACvB,kCAAe,CAAA;IACf,oCAAiB,CAAA;AACnB,CAAC,EALW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAK1B;AAOD,IAAY,wBAKX;AALD,WAAY,wBAAwB;IAClC,6CAAiB,CAAA;IACjB,6CAAiB,CAAA;IACjB,yCAAa,CAAA;IACb,6CAAiB,CAAA;AACnB,CAAC,EALW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAKnC;AAOD,IAAY,8BAMX;AAND,WAAY,8BAA8B;IACxC,uDAAqB,CAAA;IACrB,yDAAuB,CAAA;IACvB,uEAAqC,CAAA;IACrC,yDAAuB,CAAA;IACvB,mDAAiB,CAAA;AACnB,CAAC,EANW,8BAA8B,GAA9B,sCAA8B,KAA9B,sCAA8B,QAMzC;AAOD,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,iDAA6B,CAAA;IAC7B,iCAAa,CAAA;IACb,qCAAiB,CAAA;AACnB,CAAC,EALW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAK3B"}
|
|
@@ -13,14 +13,15 @@ class PullRequests extends common_1.AzureReposConverter {
|
|
|
13
13
|
];
|
|
14
14
|
}
|
|
15
15
|
async convert(record) {
|
|
16
|
-
var _a, _b, _c
|
|
16
|
+
var _a, _b, _c;
|
|
17
17
|
const source = this.streamName.source;
|
|
18
18
|
const pullRequestItem = record.record.data;
|
|
19
19
|
const organizationName = this.getOrganizationFromUrl(pullRequestItem.repository.url);
|
|
20
20
|
const organization = { uid: organizationName, source };
|
|
21
|
+
const projectRepo = this.getProjectRepo(pullRequestItem.repository);
|
|
21
22
|
const repository = {
|
|
22
|
-
name:
|
|
23
|
-
uid:
|
|
23
|
+
name: projectRepo,
|
|
24
|
+
uid: projectRepo,
|
|
24
25
|
organization,
|
|
25
26
|
};
|
|
26
27
|
const pullRequest = {
|
|
@@ -29,13 +30,7 @@ class PullRequests extends common_1.AzureReposConverter {
|
|
|
29
30
|
repository,
|
|
30
31
|
};
|
|
31
32
|
const res = [];
|
|
32
|
-
const
|
|
33
|
-
for (const commit of pullRequestItem.commits) {
|
|
34
|
-
diffStats.linesAdded += (_a = commit.changeCounts.Add) !== null && _a !== void 0 ? _a : 0;
|
|
35
|
-
diffStats.linesDeleted += (_b = commit.changeCounts.Delete) !== null && _b !== void 0 ? _b : 0;
|
|
36
|
-
diffStats.filesChanged += (_c = commit.changeCounts.Edit) !== null && _c !== void 0 ? _c : 0;
|
|
37
|
-
}
|
|
38
|
-
for (const thread of (_d = pullRequestItem.threads) !== null && _d !== void 0 ? _d : []) {
|
|
33
|
+
for (const thread of (_a = pullRequestItem.threads) !== null && _a !== void 0 ? _a : []) {
|
|
39
34
|
for (const comment of thread.comments) {
|
|
40
35
|
res.push({
|
|
41
36
|
model: 'vcs_PullRequestComment',
|
|
@@ -51,7 +46,7 @@ class PullRequests extends common_1.AzureReposConverter {
|
|
|
51
46
|
});
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
|
-
const mergeCommitId = (
|
|
49
|
+
const mergeCommitId = (_b = pullRequestItem.lastMergeCommit) === null || _b === void 0 ? void 0 : _b.commitId;
|
|
55
50
|
const mergeCommit = mergeCommitId
|
|
56
51
|
? {
|
|
57
52
|
repository,
|
|
@@ -70,15 +65,13 @@ class PullRequests extends common_1.AzureReposConverter {
|
|
|
70
65
|
createdAt: faros_js_client_1.Utils.toDate(pullRequestItem.creationDate),
|
|
71
66
|
updatedAt: faros_js_client_1.Utils.toDate(pullRequestItem.creationDate),
|
|
72
67
|
mergedAt: faros_js_client_1.Utils.toDate(pullRequestItem.closedDate),
|
|
73
|
-
commitCount: pullRequestItem.commits.length,
|
|
74
68
|
commentCount: pullRequestItem.threads.length,
|
|
75
|
-
diffStats,
|
|
76
69
|
author: { uid: pullRequestItem.createdBy.uniqueName, source },
|
|
77
70
|
mergeCommit,
|
|
78
71
|
repository,
|
|
79
72
|
},
|
|
80
73
|
});
|
|
81
|
-
for (const reviewer of (
|
|
74
|
+
for (const reviewer of (_c = pullRequestItem.reviewers) !== null && _c !== void 0 ? _c : []) {
|
|
82
75
|
res.push({
|
|
83
76
|
model: 'vcs_PullRequestReview',
|
|
84
77
|
record: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull_requests.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/pull_requests.ts"],"names":[],"mappings":";;;AACA,qDAAsC;AAGtC,qCAA6C;AAG7C,MAAa,YAAa,SAAQ,4BAAmB;IAArD;;QACW,sBAAiB,GAAoC;YAC5D,iBAAiB;YACjB,uBAAuB;YACvB,wBAAwB;SACzB,CAAC;
|
|
1
|
+
{"version":3,"file":"pull_requests.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/pull_requests.ts"],"names":[],"mappings":";;;AACA,qDAAsC;AAGtC,qCAA6C;AAG7C,MAAa,YAAa,SAAQ,4BAAmB;IAArD;;QACW,sBAAiB,GAAoC;YAC5D,iBAAiB;YACjB,uBAAuB;YACvB,wBAAwB;SACzB,CAAC;IAuFJ,CAAC;IArFC,KAAK,CAAC,OAAO,CACX,MAAqB;;QAErB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QAEtC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAmB,CAAC;QAC1D,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAClD,eAAe,CAAC,UAAU,CAAC,GAAG,CAC/B,CAAC;QACF,MAAM,YAAY,GAAG,EAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAC,CAAC;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QACpE,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,WAAW;YACjB,GAAG,EAAE,WAAW;YAChB,YAAY;SACb,CAAC;QACF,MAAM,WAAW,GAAG;YAClB,MAAM,EAAE,eAAe,CAAC,aAAa;YACrC,GAAG,EAAE,eAAe,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC7C,UAAU;SACX,CAAC;QAEF,MAAM,GAAG,GAAwB,EAAE,CAAC;QAEpC,KAA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AM,CAAC,eAAe,CAAC,YAAY,CAAC;gBACrD,QAAQ,EAAE,uBAAK,CAAC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC;gBAClD,YAAY,EAAE,eAAe,CAAC,OAAO,CAAC,MAAM;gBAC5C,MAAM,EAAE,EAAC,GAAG,EAAE,eAAe,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAC;gBAC3D,WAAW;gBACX,UAAU;aACX;SACF,CAAC,CAAC;QAEH,KAAK,MAAM,QAAQ,IAAI,MAAA,eAAe,CAAC,SAAS,mCAAI,EAAE,EAAE;YACtD,GAAG,CAAC,IAAI,CAAC;gBACP,KAAK,EAAE,uBAAuB;gBAC9B,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC/C,GAAG,EAAE,QAAQ,CAAC,EAAE;oBAChB,OAAO,EAAE,QAAQ,CAAC,GAAG;oBACrB,KAAK,EAAE,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACxD,WAAW,EAAE,IAAI;oBACjB,QAAQ,EAAE,EAAC,GAAG,EAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAC;oBAC5C,WAAW;iBACZ;aACF,CAAC,CAAC;SACJ;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA5FD,oCA4FC"}
|
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Repositories = void 0;
|
|
4
|
-
const faros_js_client_1 = require("faros-js-client");
|
|
5
4
|
const common_1 = require("./common");
|
|
6
5
|
const models_1 = require("./models");
|
|
7
6
|
class Repositories extends common_1.AzureReposConverter {
|
|
8
7
|
constructor() {
|
|
9
8
|
super(...arguments);
|
|
10
9
|
this.destinationModels = [
|
|
11
|
-
'vcs_Branch',
|
|
12
|
-
'vcs_Commit',
|
|
13
|
-
'vcs_BranchCommitAssociation',
|
|
14
10
|
'vcs_Organization',
|
|
15
11
|
'vcs_Repository',
|
|
12
|
+
'vcs_Branch',
|
|
16
13
|
'vcs_Tag',
|
|
17
14
|
];
|
|
18
15
|
this.seenOrganizations = new Set();
|
|
19
16
|
}
|
|
20
17
|
async convert(record) {
|
|
21
|
-
var _a, _b, _c, _d
|
|
18
|
+
var _a, _b, _c, _d;
|
|
22
19
|
const source = this.streamName.source;
|
|
23
20
|
const repositoryItem = record.record.data;
|
|
24
21
|
const res = [];
|
|
25
22
|
const organizationName = this.getOrganizationFromUrl(repositoryItem.url);
|
|
26
23
|
const organization = { uid: organizationName, source };
|
|
24
|
+
const projectRepo = this.getProjectRepo(repositoryItem);
|
|
27
25
|
const repository = {
|
|
28
|
-
name:
|
|
29
|
-
uid:
|
|
26
|
+
name: projectRepo,
|
|
27
|
+
uid: projectRepo,
|
|
30
28
|
organization,
|
|
31
29
|
};
|
|
32
30
|
if (!this.seenOrganizations.has(organizationName)) {
|
|
@@ -39,37 +37,23 @@ class Repositories extends common_1.AzureReposConverter {
|
|
|
39
37
|
htmlUrl: `https://dev.azure.com/${organizationName}`,
|
|
40
38
|
type: { category: models_1.OrgTypeCategory.Organization, organizationName },
|
|
41
39
|
description: organizationName,
|
|
42
|
-
createdAt: null,
|
|
43
40
|
source,
|
|
44
41
|
},
|
|
45
42
|
});
|
|
46
43
|
}
|
|
47
|
-
let createdAt = null;
|
|
48
|
-
for (const branch of (_a = repositoryItem.branches) !== null && _a !== void 0 ? _a : []) {
|
|
49
|
-
if (createdAt == null &&
|
|
50
|
-
repositoryItem.defaultBranch.endsWith(branch.name)) {
|
|
51
|
-
createdAt = faros_js_client_1.Utils.toDate(branch.commits[branch.commits.length - 1].committer.date);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
44
|
res.push({
|
|
56
45
|
model: 'vcs_Repository',
|
|
57
46
|
record: {
|
|
58
|
-
|
|
59
|
-
uid: repositoryItem.name,
|
|
47
|
+
...repository,
|
|
60
48
|
fullName: repositoryItem.name,
|
|
61
49
|
description: repositoryItem.name,
|
|
62
50
|
private: repositoryItem.project.visibility == 'private',
|
|
63
|
-
language: null,
|
|
64
51
|
size: repositoryItem.size,
|
|
65
52
|
mainBranch: repositoryItem.defaultBranch,
|
|
66
53
|
htmlUrl: repositoryItem.webUrl,
|
|
67
|
-
createdAt,
|
|
68
|
-
updatedAt: null,
|
|
69
|
-
organization,
|
|
70
54
|
},
|
|
71
55
|
});
|
|
72
|
-
for (const branch of (
|
|
56
|
+
for (const branch of (_a = repositoryItem.branches) !== null && _a !== void 0 ? _a : []) {
|
|
73
57
|
res.push({
|
|
74
58
|
model: 'vcs_Branch',
|
|
75
59
|
record: {
|
|
@@ -78,30 +62,9 @@ class Repositories extends common_1.AzureReposConverter {
|
|
|
78
62
|
repository,
|
|
79
63
|
},
|
|
80
64
|
});
|
|
81
|
-
for (const commit of (_c = branch.commits) !== null && _c !== void 0 ? _c : []) {
|
|
82
|
-
res.push({
|
|
83
|
-
model: 'vcs_Commit',
|
|
84
|
-
record: {
|
|
85
|
-
sha: commit.commitId,
|
|
86
|
-
uid: commit.commitId,
|
|
87
|
-
message: commit.comment,
|
|
88
|
-
htmlUrl: commit.remoteUrl,
|
|
89
|
-
createdAt: faros_js_client_1.Utils.toDate(commit.committer.date),
|
|
90
|
-
author: { uid: commit.author.email, source },
|
|
91
|
-
repository,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
res.push({
|
|
95
|
-
model: 'vcs_BranchCommitAssociation',
|
|
96
|
-
record: {
|
|
97
|
-
commit: { sha: commit.commitId, uid: commit.commitId, repository },
|
|
98
|
-
branch: { name: branch.name, uid: branch.name, repository },
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
65
|
}
|
|
103
|
-
for (const tag of (
|
|
104
|
-
const commitId = (
|
|
66
|
+
for (const tag of (_b = repositoryItem.tags) !== null && _b !== void 0 ? _b : []) {
|
|
67
|
+
const commitId = (_d = (_c = tag.commit) === null || _c === void 0 ? void 0 : _c.taggedObject) === null || _d === void 0 ? void 0 : _d.objectId;
|
|
105
68
|
if (commitId) {
|
|
106
69
|
res.push({
|
|
107
70
|
model: 'vcs_Tag',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/repositories.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../../src/converters/azure-repos/repositories.ts"],"names":[],"mappings":";;;AAGA,qCAA6C;AAC7C,qCAAqD;AAErD,MAAa,YAAa,SAAQ,4BAAmB;IAArD;;QACW,sBAAiB,GAAoC;YAC5D,kBAAkB;YAClB,gBAAgB;YAChB,YAAY;YACZ,SAAS;SACV,CAAC;QAEM,sBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAwEhD,CAAC;IAtEC,KAAK,CAAC,OAAO,CACX,MAAqB;;QAErB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QACtC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAkB,CAAC;QACxD,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzE,MAAM,YAAY,GAAG,EAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAC,CAAC;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,WAAW;YACjB,GAAG,EAAE,WAAW;YAChB,YAAY;SACb,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;YACjD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YA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G,CAAC,IAAI;wBACd,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO;wBAC3B,MAAM,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAC;wBAClD,UAAU;qBACX;iBACF,CAAC,CAAC;aACJ;SACF;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAhFD,oCAgFC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { AirbyteRecord } from 'faros-airbyte-cdk';
|
|
2
2
|
import jsonata from 'jsonata';
|
|
3
|
-
import { Converter, DestinationModel, DestinationRecord } from './converter';
|
|
3
|
+
import { Converter, DestinationModel, DestinationRecord, StreamContext } from './converter';
|
|
4
4
|
/** Record converter to convert records using provided JSONata expression */
|
|
5
5
|
export declare class JSONataConverter extends Converter {
|
|
6
6
|
private readonly jsonataExpr;
|
|
7
7
|
readonly destinationModels: ReadonlyArray<DestinationModel>;
|
|
8
8
|
source: string;
|
|
9
|
+
private schema;
|
|
9
10
|
constructor(jsonataExpr: jsonata.Expression, destinationModels: ReadonlyArray<DestinationModel>);
|
|
10
11
|
id(): any;
|
|
11
|
-
convert(record: AirbyteRecord): Promise<ReadonlyArray<DestinationRecord>>;
|
|
12
|
+
convert(record: AirbyteRecord, ctx?: StreamContext): Promise<ReadonlyArray<DestinationRecord>>;
|
|
12
13
|
static make(expression: string, destinationModels: ReadonlyArray<DestinationModel>): JSONataConverter;
|
|
13
14
|
}
|
|
14
15
|
export declare enum JSONataApplyMode {
|
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.JSONataApplyMode = exports.JSONataConverter = void 0;
|
|
7
|
+
const assert_1 = require("assert");
|
|
8
|
+
const faros_js_client_1 = require("faros-js-client");
|
|
7
9
|
const jsonata_1 = __importDefault(require("jsonata"));
|
|
8
10
|
const verror_1 = require("verror");
|
|
9
11
|
const converter_1 = require("./converter");
|
|
@@ -14,16 +16,45 @@ class JSONataConverter extends converter_1.Converter {
|
|
|
14
16
|
this.jsonataExpr = jsonataExpr;
|
|
15
17
|
this.destinationModels = destinationModels;
|
|
16
18
|
this.source = 'JSONata';
|
|
19
|
+
this.schema = undefined;
|
|
17
20
|
}
|
|
18
21
|
id() {
|
|
19
22
|
return undefined;
|
|
20
23
|
}
|
|
21
|
-
async convert(record) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
async convert(record, ctx) {
|
|
25
|
+
if (!this.schema && (ctx === null || ctx === void 0 ? void 0 : ctx.farosClient) && (ctx === null || ctx === void 0 ? void 0 : ctx.graph)) {
|
|
26
|
+
this.schema = new faros_js_client_1.FarosGraphSchema(await ctx.farosClient.introspect(ctx.graph));
|
|
27
|
+
}
|
|
28
|
+
let jsonataResult = this.jsonataExpr.evaluate(record.record);
|
|
29
|
+
if (!jsonataResult)
|
|
24
30
|
return [];
|
|
25
|
-
if (!Array.isArray(
|
|
26
|
-
|
|
31
|
+
if (!Array.isArray(jsonataResult))
|
|
32
|
+
jsonataResult = [jsonataResult];
|
|
33
|
+
const res = [];
|
|
34
|
+
for (const result of jsonataResult) {
|
|
35
|
+
// We expect each jsonata result to conform to:
|
|
36
|
+
// { '<model>': {<record data>} } or
|
|
37
|
+
// { '<model>__<operation>': {<record data>} }
|
|
38
|
+
(0, assert_1.ok)(Object.keys(result).length == 1, 'jsonata result should contain a single key');
|
|
39
|
+
const [model, rec] = Object.entries(result).pop();
|
|
40
|
+
if (this.schema) {
|
|
41
|
+
if (model.endsWith('__Update')) {
|
|
42
|
+
for (const key of ['mask', 'patch', 'where']) {
|
|
43
|
+
this.schema.fixTimestampFields(rec[key], model.replace('__Update', ''));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (model.endsWith('__Deletion')) {
|
|
47
|
+
this.schema.fixTimestampFields(rec['where'], model.replace('__Deletion', ''));
|
|
48
|
+
}
|
|
49
|
+
else if (model.endsWith('__Upsert')) {
|
|
50
|
+
this.schema.fixTimestampFields(rec, model.replace('__Upsert', ''));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.schema.fixTimestampFields(rec, model);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
res.push({ model, record: rec });
|
|
57
|
+
}
|
|
27
58
|
return res;
|
|
28
59
|
}
|
|
29
60
|
static make(expression, destinationModels) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonata.js","sourceRoot":"","sources":["../../src/converters/jsonata.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"jsonata.js","sourceRoot":"","sources":["../../src/converters/jsonata.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA0B;AAE1B,qDAAiD;AACjD,sDAA8B;AAC9B,mCAA8B;AAE9B,2CAKqB;AAErB,4EAA4E;AAC5E,MAAa,gBAAiB,SAAQ,qBAAS;IAK7C,YACmB,WAA+B,EACvC,iBAAkD;QAE3D,KAAK,EAAE,CAAC;QAHS,gBAAW,GAAX,WAAW,CAAoB;QACvC,sBAAiB,GAAjB,iBAAiB,CAAiC;QAN7D,WAAM,GAAG,SAAS,CAAC;QAEX,WAAM,GAAqB,SAAS,CAAC;IAO7C,CAAC;IAED,EAAE;QACA,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAqB,EACrB,GAAmB;QAEnB,IAAI,CAAC,IAAI,CAAC,MAAM,KAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAA,KAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,KAAK,CAAA,EAAE;YAClD,IAAI,CAAC,MAAM,GAAG,IAAI,kCAAgB,CAChC,MAAM,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAC5C,CAAC;SACH;QAED,IAAI,aAAa,GAAG,IAAI,CAAC,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AAC,CAAC;iBACpE;qBAAM;oBACL,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;iBAC5C;aACF;YAED,GAAG,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC,CAAC;SAChC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,CAAC,IAAI,CACT,UAAkB,EAClB,iBAAkD;QAElD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE;YAClE,MAAM,IAAI,eAAM,CAAC,oCAAoC,CAAC,CAAC;SACxD;QACD,IAAI;YACF,MAAM,WAAW,GAAG,IAAA,iBAAO,EAAC,UAAU,CAAC,CAAC;YACxC,OAAO,IAAI,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;SAC7D;QAAC,OAAO,KAAU,EAAE;YACnB,MAAM,IAAI,eAAM,CACd,KAAK,EACL,4EAA4E,EAC5E,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,KAAK,CACZ,CAAC;SACH;IACH,CAAC;CACF;AAzFD,4CAyFC;AAED,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,yCAAqB,CAAA;AACvB,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B"}
|
package/lib/destination.js
CHANGED
|
@@ -306,7 +306,27 @@ class FarosDestination extends faros_airbyte_cdk_1.AirbyteDestination {
|
|
|
306
306
|
const graphQLClient = this.getGraphQLClient();
|
|
307
307
|
await graphQLClient.loadSchema();
|
|
308
308
|
await graphQLClient.resetData(origin, deleteModelEntries);
|
|
309
|
-
|
|
309
|
+
let originRemapper = undefined;
|
|
310
|
+
if (config.accept_input_records_origin && config.replace_origin_map) {
|
|
311
|
+
const originMap = JSON.parse(config.replace_origin_map);
|
|
312
|
+
originRemapper = (origin) => {
|
|
313
|
+
var _a;
|
|
314
|
+
return (_a = originMap[origin]) !== null && _a !== void 0 ? _a : origin;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const writer = new graphql_writer_1.GraphQLWriter(graphQLClient, config.accept_input_records_origin
|
|
318
|
+
? {
|
|
319
|
+
getOrigin: (record) => {
|
|
320
|
+
if (!record.origin) {
|
|
321
|
+
return origin;
|
|
322
|
+
}
|
|
323
|
+
if (!originRemapper) {
|
|
324
|
+
return record.origin;
|
|
325
|
+
}
|
|
326
|
+
return originRemapper(record.origin);
|
|
327
|
+
},
|
|
328
|
+
}
|
|
329
|
+
: { getOrigin: () => origin }, stats, this);
|
|
310
330
|
latestStateMessage = await this.writeEntries(streamContext, stdin, streams, converterDependencies, stats, writer);
|
|
311
331
|
}
|
|
312
332
|
else {
|