@drodil/backstage-plugin-search-backend-module-qeta 2.14.0 → 3.0.0
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.
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var stream = require('stream');
|
|
4
|
+
var backstagePluginQetaCommon = require('@drodil/backstage-plugin-qeta-common');
|
|
4
5
|
|
|
5
6
|
class DefaultQetaCollatorFactory {
|
|
6
7
|
type = "qeta";
|
|
7
8
|
logger;
|
|
8
|
-
discovery;
|
|
9
9
|
auth;
|
|
10
|
+
api;
|
|
10
11
|
constructor(_config, options) {
|
|
11
12
|
this.logger = options.logger;
|
|
12
|
-
this.discovery = options.discovery;
|
|
13
13
|
this.auth = options.auth;
|
|
14
|
+
this.api = new backstagePluginQetaCommon.QetaClient({ discoveryApi: options.discovery });
|
|
14
15
|
}
|
|
15
16
|
static fromConfig(config, options) {
|
|
16
17
|
return new DefaultQetaCollatorFactory(config, options);
|
|
@@ -22,90 +23,84 @@ class DefaultQetaCollatorFactory {
|
|
|
22
23
|
this.logger.info("Executing QetaCollator");
|
|
23
24
|
let totalQuestions = Number.MAX_VALUE;
|
|
24
25
|
let indexedQuestions = 0;
|
|
25
|
-
const baseUrl = await this.discovery.getBaseUrl("qeta");
|
|
26
26
|
while (totalQuestions > indexedQuestions) {
|
|
27
|
-
let
|
|
27
|
+
let tok = void 0;
|
|
28
28
|
if (this.auth) {
|
|
29
29
|
const { token } = await this.auth.getPluginRequestToken({
|
|
30
30
|
onBehalfOf: await this.auth.getOwnServiceCredentials(),
|
|
31
31
|
targetPluginId: "qeta"
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
Authorization: `Bearer ${token}`
|
|
35
|
-
};
|
|
33
|
+
tok = token;
|
|
36
34
|
}
|
|
37
|
-
const
|
|
38
|
-
params.append("includeAnswers", "true");
|
|
39
|
-
params.append("includeComments", "true");
|
|
40
|
-
params.append("orderBy", "created");
|
|
41
|
-
params.append("order", "asc");
|
|
42
|
-
params.append("limit", "50");
|
|
43
|
-
params.append("offset", indexedQuestions.toString(10));
|
|
44
|
-
const response = await fetch(
|
|
45
|
-
`${baseUrl}/questions?${params.toString()}`,
|
|
35
|
+
const data = await this.api.getPosts(
|
|
46
36
|
{
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
includeAnswers: true,
|
|
38
|
+
includeComments: true,
|
|
39
|
+
orderBy: "created",
|
|
40
|
+
order: "asc",
|
|
41
|
+
limit: 50,
|
|
42
|
+
offset: indexedQuestions
|
|
43
|
+
},
|
|
44
|
+
{ token: tok }
|
|
49
45
|
);
|
|
50
|
-
|
|
51
|
-
if (!data || "errors" in data || !("questions" in data)) {
|
|
46
|
+
if (!data || "errors" in data || !("posts" in data)) {
|
|
52
47
|
this.logger.error(
|
|
53
|
-
`Error while fetching
|
|
48
|
+
`Error while fetching posts from qeta: ${JSON.stringify(data)}`
|
|
54
49
|
);
|
|
55
50
|
return;
|
|
56
51
|
}
|
|
57
|
-
const
|
|
58
|
-
this.logger.info(`Indexing ${
|
|
52
|
+
const posts = data.posts;
|
|
53
|
+
this.logger.info(`Indexing ${posts.length} posts`);
|
|
59
54
|
totalQuestions = data.total;
|
|
60
|
-
indexedQuestions +=
|
|
61
|
-
for (const
|
|
55
|
+
indexedQuestions += posts.length;
|
|
56
|
+
for (const post of posts) {
|
|
62
57
|
yield {
|
|
63
|
-
title:
|
|
64
|
-
text:
|
|
65
|
-
location: `/qeta/questions/${
|
|
58
|
+
title: post.title,
|
|
59
|
+
text: post.content,
|
|
60
|
+
location: post.type === "question" ? `/qeta/questions/${post.id}` : `/qeta/articles/${post.id}`,
|
|
66
61
|
docType: "qeta",
|
|
67
|
-
author:
|
|
68
|
-
score:
|
|
69
|
-
entityRefs:
|
|
70
|
-
answerCount:
|
|
71
|
-
views:
|
|
72
|
-
tags:
|
|
62
|
+
author: post.author,
|
|
63
|
+
score: post.score,
|
|
64
|
+
entityRefs: post.entities,
|
|
65
|
+
answerCount: post.answersCount,
|
|
66
|
+
views: post.views,
|
|
67
|
+
tags: post.tags
|
|
73
68
|
};
|
|
74
|
-
for (const answer of
|
|
69
|
+
for (const answer of post.answers ?? []) {
|
|
75
70
|
yield {
|
|
76
|
-
title: `${answer.correct ? "Correct answer" : "Answer"} for question ${
|
|
71
|
+
title: `${answer.correct ? "Correct answer" : "Answer"} for question ${post.title}`,
|
|
77
72
|
text: answer.content,
|
|
78
|
-
location: `/qeta/questions/${
|
|
73
|
+
location: `/qeta/questions/${post.id}#answer_${answer.id}`,
|
|
79
74
|
docType: "qeta",
|
|
80
|
-
entityRefs:
|
|
75
|
+
entityRefs: post.entities,
|
|
81
76
|
author: answer.author,
|
|
82
77
|
score: answer.score,
|
|
83
|
-
tags:
|
|
78
|
+
tags: post.tags,
|
|
84
79
|
correctAnswer: answer.correct
|
|
85
80
|
};
|
|
86
81
|
for (const comment of answer.comments ?? []) {
|
|
87
82
|
yield {
|
|
88
|
-
title: `Comment for ${
|
|
83
|
+
title: `Comment for ${post.title}`,
|
|
89
84
|
text: comment.content,
|
|
90
|
-
location: `/qeta/questions/${
|
|
85
|
+
location: `/qeta/questions/${post.id}#answer_${answer.id}`,
|
|
91
86
|
docType: "qeta",
|
|
92
87
|
author: comment.author,
|
|
93
88
|
score: answer.score,
|
|
94
|
-
tags:
|
|
95
|
-
entityRefs:
|
|
89
|
+
tags: post.tags,
|
|
90
|
+
entityRefs: post.entities
|
|
96
91
|
};
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
|
-
for (const comment of
|
|
94
|
+
for (const comment of post.comments ?? []) {
|
|
100
95
|
yield {
|
|
101
|
-
title: `Comment for ${
|
|
96
|
+
title: `Comment for ${post.title}`,
|
|
102
97
|
text: comment.content,
|
|
103
|
-
location: `/qeta/questions/${
|
|
98
|
+
location: post.type === "question" ? `/qeta/questions/${post.id}` : `/qeta/articles/${post.id}`,
|
|
104
99
|
docType: "qeta",
|
|
105
100
|
author: comment.author,
|
|
106
|
-
score:
|
|
107
|
-
tags:
|
|
108
|
-
entityRefs:
|
|
101
|
+
score: post.score,
|
|
102
|
+
tags: post.tags,
|
|
103
|
+
entityRefs: post.entities
|
|
109
104
|
};
|
|
110
105
|
}
|
|
111
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultQetaCollatorFactory.cjs.js","sources":["../../src/collators/DefaultQetaCollatorFactory.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport { Readable } from 'stream';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport {\n
|
|
1
|
+
{"version":3,"file":"DefaultQetaCollatorFactory.cjs.js","sources":["../../src/collators/DefaultQetaCollatorFactory.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport { Readable } from 'stream';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport {\n QetaApi,\n QetaClient,\n QetaDocument,\n} from '@drodil/backstage-plugin-qeta-common';\nimport {\n AuthService,\n DiscoveryService,\n LoggerService,\n} from '@backstage/backend-plugin-api';\n\nexport type QetaCollatorFactoryOptions = {\n logger: LoggerService;\n discovery: DiscoveryService;\n auth?: AuthService;\n};\n\nexport class DefaultQetaCollatorFactory implements DocumentCollatorFactory {\n public readonly type: string = 'qeta';\n private readonly logger: LoggerService;\n private readonly auth?: AuthService;\n private readonly api: QetaApi;\n\n private constructor(_config: Config, options: QetaCollatorFactoryOptions) {\n this.logger = options.logger;\n this.auth = options.auth;\n this.api = new QetaClient({ discoveryApi: options.discovery });\n }\n\n static fromConfig(config: Config, options: QetaCollatorFactoryOptions) {\n return new DefaultQetaCollatorFactory(config, options);\n }\n\n async getCollator() {\n return Readable.from(this.execute());\n }\n\n async *execute(): AsyncGenerator<QetaDocument> {\n this.logger.info('Executing QetaCollator');\n let totalQuestions = Number.MAX_VALUE;\n let indexedQuestions = 0;\n\n while (totalQuestions > indexedQuestions) {\n let tok = undefined;\n\n if (this.auth) {\n const { token } = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: 'qeta',\n });\n tok = token;\n }\n\n const data = await this.api.getPosts(\n {\n includeAnswers: true,\n includeComments: true,\n orderBy: 'created',\n order: 'asc',\n limit: 50,\n offset: indexedQuestions,\n },\n { token: tok },\n );\n\n if (!data || 'errors' in data || !('posts' in data)) {\n this.logger.error(\n `Error while fetching posts from qeta: ${JSON.stringify(data)}`,\n );\n return;\n }\n\n const posts = data.posts;\n this.logger.info(`Indexing ${posts.length} posts`);\n totalQuestions = data.total;\n indexedQuestions += posts.length;\n\n for (const post of posts) {\n yield {\n title: post.title,\n text: post.content,\n location:\n post.type === 'question'\n ? `/qeta/questions/${post.id}`\n : `/qeta/articles/${post.id}`,\n docType: 'qeta',\n author: post.author,\n score: post.score,\n entityRefs: post.entities,\n answerCount: post.answersCount,\n views: post.views,\n tags: post.tags,\n };\n\n for (const answer of post.answers ?? []) {\n yield {\n title: `${\n answer.correct ? 'Correct answer' : 'Answer'\n } for question ${post.title}`,\n text: answer.content,\n location: `/qeta/questions/${post.id}#answer_${answer.id}`,\n docType: 'qeta',\n entityRefs: post.entities,\n author: answer.author,\n score: answer.score,\n tags: post.tags,\n correctAnswer: answer.correct,\n };\n\n for (const comment of answer.comments ?? []) {\n yield {\n title: `Comment for ${post.title}`,\n text: comment.content,\n location: `/qeta/questions/${post.id}#answer_${answer.id}`,\n docType: 'qeta',\n author: comment.author,\n score: answer.score,\n tags: post.tags,\n entityRefs: post.entities,\n };\n }\n }\n\n for (const comment of post.comments ?? []) {\n yield {\n title: `Comment for ${post.title}`,\n text: comment.content,\n location:\n post.type === 'question'\n ? `/qeta/questions/${post.id}`\n : `/qeta/articles/${post.id}`,\n docType: 'qeta',\n author: comment.author,\n score: post.score,\n tags: post.tags,\n entityRefs: post.entities,\n };\n }\n }\n }\n }\n}\n"],"names":["QetaClient","Readable"],"mappings":";;;;;AAoBO,MAAM,0BAA8D,CAAA;AAAA,EACzD,I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,IAAA,CAAK,QAAY,IAAA,EAAI,EAAA;AACzC,UAAM,MAAA;AAAA,YACJ,KAAA,EAAO,CAAe,YAAA,EAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAAA,YAChC,MAAM,OAAQ,CAAA,OAAA;AAAA,YACd,QAAA,EACE,IAAK,CAAA,IAAA,KAAS,UACV,GAAA,CAAA,gBAAA,EAAmB,KAAK,EAAE,CAAA,CAAA,GAC1B,CAAkB,eAAA,EAAA,IAAA,CAAK,EAAE,CAAA,CAAA;AAAA,YAC/B,OAAS,EAAA,MAAA;AAAA,YACT,QAAQ,OAAQ,CAAA,MAAA;AAAA,YAChB,OAAO,IAAK,CAAA,KAAA;AAAA,YACZ,MAAM,IAAK,CAAA,IAAA;AAAA,YACX,YAAY,IAAK,CAAA,QAAA;AAAA,WACnB,CAAA;AAAA,SACF;AAAA,OACF;AAAA,KACF;AAAA,GACF;AACF;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ type QetaCollatorFactoryOptions = {
|
|
|
15
15
|
declare class DefaultQetaCollatorFactory implements DocumentCollatorFactory {
|
|
16
16
|
readonly type: string;
|
|
17
17
|
private readonly logger;
|
|
18
|
-
private readonly discovery;
|
|
19
18
|
private readonly auth?;
|
|
19
|
+
private readonly api;
|
|
20
20
|
private constructor();
|
|
21
21
|
static fromConfig(config: Config, options: QetaCollatorFactoryOptions): DefaultQetaCollatorFactory;
|
|
22
22
|
getCollator(): Promise<Readable>;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"search",
|
|
8
8
|
"backstage.io"
|
|
9
9
|
],
|
|
10
|
-
"version": "
|
|
10
|
+
"version": "3.0.0",
|
|
11
11
|
"main": "dist/index.cjs.js",
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
13
|
"prepublishOnly": "yarn tsc && yarn build",
|
|
@@ -41,15 +41,12 @@
|
|
|
41
41
|
"tsc": "tsc"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@backstage/backend-common": "^0.25.0",
|
|
45
44
|
"@backstage/backend-plugin-api": "^1.0.1",
|
|
46
|
-
"@backstage/backend-tasks": "^0.6.1",
|
|
47
45
|
"@backstage/config": "^1.2.0",
|
|
48
|
-
"@backstage/core-plugin-api": "^1.10.0",
|
|
49
46
|
"@backstage/errors": "^1.2.4",
|
|
50
47
|
"@backstage/plugin-search-backend-node": "^1.3.3",
|
|
51
48
|
"@backstage/plugin-search-common": "^1.2.14",
|
|
52
|
-
"@drodil/backstage-plugin-qeta-common": "^
|
|
49
|
+
"@drodil/backstage-plugin-qeta-common": "^3.0.0"
|
|
53
50
|
},
|
|
54
51
|
"devDependencies": {
|
|
55
52
|
"@backstage/backend-test-utils": "^1.0.1",
|