@interopio/search-api 2.5.1 → 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,84 +0,0 @@
1
- import { IOConnectCore } from "@interopio/core";
2
- import { nanoid } from "nanoid/non-secure";
3
- import { IOConnectSearch } from "../../search";
4
- import { ProviderController } from "../controllers/provider";
5
- import { nonEmptyStringDecoder, queryResultDecoder } from "../shared/decoders";
6
- import { QueryIdentification } from "../shared/types";
7
- import { extractErrorMsg } from "../shared/utils";
8
-
9
- export class ProviderQueryModel {
10
- constructor(
11
- private readonly myData: IOConnectSearch.QueryConfig,
12
- private readonly controller: ProviderController,
13
- private readonly logger: IOConnectCore.Logger.API,
14
- private readonly identification: QueryIdentification
15
- ) {}
16
-
17
- private get id(): string {
18
- return this.identification.queryId;
19
- }
20
-
21
- private get search(): string {
22
- return this.myData.search;
23
- }
24
-
25
- private get providers(): IOConnectSearch.ProviderData[] | undefined {
26
- return this.myData.providers;
27
- }
28
-
29
- private get types(): IOConnectSearch.SearchType[] | undefined {
30
- return this.myData.types;
31
- }
32
-
33
- private get providerLimits(): IOConnectSearch.ProviderLimits | undefined {
34
- return this.myData.providerLimits;
35
- }
36
-
37
- public get myQueryData(): IOConnectSearch.QueryConfig {
38
- return Object.assign({}, this.myData);
39
- }
40
-
41
- public exposeFacade(): IOConnectSearch.ProviderQuery {
42
- const providerQueryFacade: IOConnectSearch.ProviderQuery = {
43
- id: this.id,
44
- search: this.search,
45
- providers: this.providers,
46
- types: this.types,
47
- providerLimits: this.providerLimits,
48
- sendResult: this.sendResult.bind(this),
49
- error: this.error.bind(this),
50
- done: this.done.bind(this)
51
- };
52
-
53
- return Object.freeze(providerQueryFacade);
54
- }
55
-
56
- private sendResult(result: IOConnectSearch.QueryResult): void {
57
- queryResultDecoder.runWithException(result);
58
-
59
- const commandId = nanoid(10);
60
-
61
- this.logger.trace(`[${commandId}] Received a valid result, forwarding to the controller`);
62
-
63
- return this.controller.processProviderQueryResult({ identification: this.identification, result, commandId });
64
- }
65
-
66
- private error(error: string): void {
67
- const commandId = nanoid(10);
68
-
69
- nonEmptyStringDecoder.runWithException(error);
70
-
71
- this.logger.trace(`[${commandId}] Received a valid error, forwarding to the controller`);
72
-
73
- this.controller.processProviderQueryError({ identification: this.identification, error, commandId }).catch((error) => this.logger.warn(`Error processing the error signal for this provider: ${this.id}, error: ${extractErrorMsg(error)}`));
74
- }
75
-
76
- private done(): void {
77
- const commandId = nanoid(10);
78
-
79
- this.logger.trace(`[${commandId}] Received a valid done, forwarding to the controller`);
80
-
81
- this.controller.processProviderQueryDone({ identification: this.identification, commandId }).catch((error) => this.logger.warn(`Error processing the done signal for this provider: ${this.identification.providerId}, error: ${extractErrorMsg(error)}`));
82
- }
83
-
84
- }
@@ -1,91 +0,0 @@
1
- import { IOConnectCore } from "@interopio/core";
2
- import { nanoid } from "nanoid/non-secure";
3
- import { IOConnectSearch } from "../../search";
4
- import { ProviderController } from "../controllers/provider";
5
-
6
- export class ProviderModel {
7
-
8
- constructor(
9
- private readonly myData: IOConnectSearch.ProviderData,
10
- private readonly controller: ProviderController,
11
- private readonly logger: IOConnectCore.Logger.API
12
- ) {}
13
-
14
- private get id(): string {
15
- return this.myData.id;
16
- }
17
-
18
- private get name(): string {
19
- return this.myData.name;
20
- }
21
-
22
- private get appName(): string | undefined {
23
- return this.myData.appName;
24
- }
25
-
26
- private get types(): IOConnectSearch.SearchType[] | undefined {
27
- return this.myData.types;
28
- }
29
-
30
- public get myProviderData(): IOConnectSearch.ProviderData {
31
- return Object.assign({}, this.myData);
32
- }
33
-
34
- public exposeFacade(): IOConnectSearch.Provider {
35
- const providerFacade: IOConnectSearch.Provider = {
36
- interopId: this.myData.interopId,
37
- id: this.id,
38
- name: this.name,
39
- appName: this.appName,
40
- types: this.types,
41
- onQuery: this.onQuery.bind(this),
42
- onQueryCancel: this.onQueryCancel.bind(this),
43
- unregister: this.unregister.bind(this)
44
- };
45
-
46
- return Object.freeze(providerFacade);
47
- }
48
-
49
- private onQuery(callback: (query: IOConnectSearch.ProviderQuery) => void): IOConnectSearch.UnsubscribeFunction {
50
- if (typeof callback !== "function") {
51
- throw new Error("onQuery requires a callback of type function");
52
- }
53
-
54
- const commandId = nanoid(10);
55
-
56
- this.logger.info(`[${commandId}] received a valid onQuery request, forwarding to the controller.`);
57
-
58
- const unsubscribe = this.controller.processProviderOnQuery({ callback, id: this.id, commandId });
59
-
60
- this.logger.info(`[${commandId}] the onQuery request was completed.`);
61
-
62
- return unsubscribe;
63
- }
64
-
65
- private onQueryCancel(callback: (query: { id: string; }) => void): IOConnectSearch.UnsubscribeFunction {
66
- if (typeof callback !== "function") {
67
- throw new Error("onQuery requires a callback of type function");
68
- }
69
-
70
- const commandId = nanoid(10);
71
-
72
- this.logger.info(`[${commandId}] received a valid onQueryCancel request, forwarding to the controller.`);
73
-
74
- const unsubscribe = this.controller.processProviderOnQueryCancel({ callback, id: this.id, commandId });
75
-
76
- this.logger.info(`[${commandId}] the onQueryCancel request was completed.`);
77
-
78
- return unsubscribe;
79
- }
80
-
81
- private async unregister(): Promise<void> {
82
- const commandId = nanoid(10);
83
-
84
- this.logger.info(`[${commandId}] received a valid unregister request, forwarding to the controller.`);
85
-
86
- await this.controller.processProviderUnregister({ id: this.id, commandId });
87
-
88
- this.logger.info(`[${commandId}] the unregister request was completed.`);
89
- }
90
-
91
- }
@@ -1,75 +0,0 @@
1
- import { IOConnectSearch } from "../../search";
2
- import { LimitTestResult, ProviderQueryLimit, ProviderQueryResultCommand, QueryProviderResultsTracker } from "../shared/types";
3
-
4
- // important to work in O(1)
5
- export class LimitsTracker {
6
- private readonly limitsLookup: { [key in string]: { [key in string]: QueryProviderResultsTracker } } = {};
7
- private readonly limitsData: { [key in string]: ProviderQueryLimit } = {};
8
-
9
- public enableTracking(limits: IOConnectSearch.ProviderLimits, queryId: string): void {
10
- this.limitsLookup[queryId] = {};
11
- this.limitsData[queryId] = {
12
- maxResults: limits.maxResults ? limits.maxResults : Number.MAX_SAFE_INTEGER,
13
- maxResultsPerType: limits.maxResultsPerType ? limits.maxResultsPerType : Number.MAX_SAFE_INTEGER
14
- };
15
- }
16
-
17
- public testResultLimit(command: ProviderQueryResultCommand): LimitTestResult | undefined {
18
- const foundLookup = this.limitsLookup[command.identification.queryId];
19
- const limitData = this.limitsData[command.identification.queryId];
20
-
21
- if (!foundLookup || !limitData) {
22
- return;
23
- }
24
-
25
- let providerStateLookup = foundLookup[command.identification.providerId];
26
-
27
- if (!providerStateLookup) {
28
- providerStateLookup = { total: 0 };
29
- foundLookup[command.identification.providerId] = providerStateLookup;
30
- }
31
-
32
- if ((providerStateLookup.total + 1) > limitData.maxResults) {
33
- return { maxLimitHit: true };
34
- }
35
-
36
- const resultTypeName = command.result.type.name;
37
-
38
- if (!resultTypeName) {
39
- return;
40
- }
41
-
42
- const currentResultTypeCount = providerStateLookup[resultTypeName] || 0;
43
-
44
- if ((currentResultTypeCount + 1) > limitData.maxResultsPerType) {
45
- return { maxLimitPerTypeHit: true };
46
- }
47
-
48
- }
49
-
50
- public update(command: ProviderQueryResultCommand): void {
51
- const foundLookup = this.limitsLookup[command.identification.queryId];
52
- const limitData = this.limitsData[command.identification.queryId];
53
-
54
- if (!foundLookup || !limitData) {
55
- return;
56
- }
57
-
58
- const providerStateLookup = foundLookup[command.identification.providerId];
59
-
60
- providerStateLookup.total += 1;
61
-
62
- const resultTypeName = command.result.type.name;
63
-
64
- if (!resultTypeName) {
65
- return;
66
- }
67
-
68
- providerStateLookup[resultTypeName] = providerStateLookup[resultTypeName] ? providerStateLookup[resultTypeName] + 1 : 1;
69
- }
70
-
71
- public cleanTracking(queryId: string): void {
72
- delete this.limitsLookup[queryId];
73
- delete this.limitsData[queryId];
74
- }
75
- }
@@ -1,41 +0,0 @@
1
- import { IOConnectCore } from "@interopio/core";
2
- import { IOConnectSearch } from "../../search";
3
- import { ClientController } from "../controllers/client";
4
- import { GlueController } from "../controllers/glue";
5
- import { ProviderController } from "../controllers/provider";
6
- import { ClientQuery } from "../models/client-query";
7
- import { ProviderModel } from "../models/provider";
8
- import { ProviderQueryModel } from "../models/provider-query";
9
- import { QueryIdentification } from "../shared/types";
10
- import { QueryResultsPublisher } from "./publisher";
11
- import { AsyncSequelizer } from "./sequelizer";
12
-
13
- export class ModelFactory {
14
-
15
- constructor(
16
- private readonly glueController: GlueController,
17
- private readonly glue: IOConnectCore.API,
18
- private readonly flushSequelizer: AsyncSequelizer
19
- ) {}
20
-
21
- public buildProviderModel(providerData: IOConnectSearch.ProviderData, controller: ProviderController): ProviderModel {
22
- return new ProviderModel(providerData, controller, this.glue.logger.subLogger(`search.provider.model.${providerData.name}`));
23
- }
24
-
25
- public buildProviderQueryModel(queryConfig: IOConnectSearch.QueryConfig, identification: QueryIdentification, controller: ProviderController): ProviderQueryModel {
26
- return new ProviderQueryModel(queryConfig, controller, this.glue.logger.subLogger(`search.provider.${identification.providerId}.query.${identification.queryId}`), identification);
27
- }
28
-
29
- public buildPublisher(clientInstanceId: string, queryId: string, isLegacy: boolean): QueryResultsPublisher {
30
- return new QueryResultsPublisher(
31
- this.flushSequelizer,
32
- this.glueController,
33
- this.glue.logger.subLogger(`search.results.publisher.${queryId}`),
34
- clientInstanceId, queryId, isLegacy
35
- );
36
- }
37
-
38
- public buildClientQueryModel(masterQueryId: string, controller: ClientController): ClientQuery {
39
- return new ClientQuery(controller, this.glue.logger.subLogger(`search.provider.model.${masterQueryId}`), masterQueryId);
40
- }
41
- }
@@ -1,178 +0,0 @@
1
- import { IOConnectCore } from "@interopio/core";
2
- import { IOConnectSearch } from "../../search";
3
- import { GlueController } from "../controllers/glue";
4
- import { ProviderModel } from "../models/provider";
5
- import { FLUSH_TIMEOUT_MS } from "../shared/constants";
6
- import { LegacySearchResultItem, PublisherQueryResultBatch, ProviderQueryResultCommand, ProviderQueryErrorCommand, ProviderQueue } from "../shared/types";
7
- import { extractErrorMsg } from "../shared/utils";
8
- import { AsyncSequelizer } from "./sequelizer";
9
-
10
- export class QueryResultsPublisher {
11
-
12
- private queues: { [key in string]: ProviderQueue } = {};
13
-
14
- constructor(
15
- private readonly sequelizer: AsyncSequelizer,
16
- private readonly glueController: GlueController,
17
- private readonly logger: IOConnectCore.Logger.API,
18
- private readonly clientInstanceId: string,
19
- private readonly queryId: string,
20
- private readonly isLegacy: boolean
21
- ) {}
22
-
23
- public checkProviderSuspended(providerId: string): boolean {
24
- return this.queues[providerId] ? !!this.queues[providerId].suspended : false;
25
- }
26
-
27
- public syncSuspendProvider(providerId: string, commandId: string): void {
28
- const providerQueue = this.queues[providerId];
29
-
30
- if (!providerQueue) {
31
- this.logger.warn(`[${commandId}] Cannot suspend provider: ${providerId}, because there is no provider queue. This happens when the provider queue was already cancelled or completed`);
32
-
33
- return;
34
- }
35
-
36
- providerQueue.suspended = true;
37
- }
38
-
39
- public configureProviders(providers: ProviderModel[]): void {
40
- providers.forEach((provider) => {
41
- this.queues[provider.myProviderData.id] = {
42
- providerData: provider,
43
- pendingResults: []
44
- };
45
- });
46
- }
47
-
48
- public queueResult(command: ProviderQueryResultCommand): void {
49
- const { commandId, identification } = command;
50
-
51
- this.logger.trace(`[${commandId}] Queuing a new result from provider: ${identification.providerId}`);
52
-
53
- const providerQueue = this.queues[identification.providerId];
54
-
55
- if (!providerQueue) {
56
- this.logger.warn(`[${commandId}] Cannot queue this result, because there is no provider queue. This happens when the provider queue was already cancelled or completed`);
57
-
58
- return;
59
- }
60
-
61
- const result = this.isLegacy ? this.translateLegacySearchItem(command.result) : command.result;
62
-
63
- providerQueue.pendingResults.push(result);
64
-
65
- clearTimeout(providerQueue.flushTimer);
66
-
67
- if (providerQueue.pendingResults.length === 10) {
68
- this.logger.trace(`[${commandId}] Reached the limit in the queue buffer, flushing to the client.`);
69
- this.flushProviderQueue(identification.providerId, commandId);
70
-
71
- return;
72
- }
73
-
74
- this.logger.trace(`[${commandId}] The limit in the queue buffer is not reached yet, setting a flush timer.`);
75
-
76
- providerQueue.flushTimer = setTimeout(() => {
77
- this.logger.trace(`[${commandId}] Reached the time limit in the queue buffer, flushing to the client.`);
78
- this.flushProviderQueue(identification.providerId, commandId);
79
- }, FLUSH_TIMEOUT_MS);
80
- }
81
-
82
- public cancel(commandId: string): void {
83
- this.logger.trace(`[${commandId}] Cancelling queue ${this.queryId}.`);
84
-
85
- Object.values(this.queues).forEach((queue) => clearTimeout(queue.flushTimer));
86
-
87
- this.queues = {};
88
-
89
- this.logger.trace(`[${commandId}] Queue ${this.queryId} publisher cancelled.`);
90
-
91
- }
92
-
93
- public async markProviderDone(providerId: string, commandId: string): Promise<void> {
94
- this.logger.trace(`[${commandId}] Marking provider ${providerId} as done.`);
95
-
96
- const providerQueue = this.queues[providerId];
97
-
98
- if (!providerQueue) {
99
- this.logger.info(`[${commandId}] Cannot mark this queue as done, because there is no provider queue. This happens when the provider queue was already cancelled, completed or the provider sent an error`);
100
-
101
- return;
102
- }
103
-
104
- clearTimeout(providerQueue.flushTimer);
105
-
106
- await this.flushProviderQueue(providerId, commandId);
107
-
108
- delete this.queues[providerId];
109
-
110
- this.logger.trace(`[${commandId}] Provider ${providerId} marked as done.`);
111
- }
112
-
113
- public markProviderError(command: ProviderQueryErrorCommand): void {
114
- const providerQueue = this.queues[command.identification.providerId];
115
-
116
- if (!providerQueue) {
117
- this.logger.warn(`[${command.commandId}] Cannot mark this provider as errored, because there is no provider queue. This happens when the provider queue was already cancelled, completed or the provider sent and error`);
118
-
119
- return;
120
- }
121
-
122
- this.glueController.sendClientErrorMessage(command.error, this.clientInstanceId, this.queryId, providerQueue.providerData.myProviderData)
123
- .catch((error) => this.logger.warn(`[${command.commandId}] The client errored when handling error message for query: ${this.queryId} -> ${extractErrorMsg(error)}`));
124
- }
125
-
126
- public cleanPublisher(commandId: string): void {
127
- Object.values(this.queues).forEach((queue) => clearTimeout(queue.flushTimer));
128
-
129
- this.queues = {};
130
-
131
- this.glueController.sendClientQueueCompleted(this.clientInstanceId, this.queryId)
132
- .catch((error) => this.logger.warn(`[${commandId}] The client errored when handling search end message for query: ${this.queryId} -> ${extractErrorMsg(error)}`));
133
- }
134
-
135
- private async flushProviderQueue(providerId: string, commandId: string): Promise<void> {
136
-
137
- await this.sequelizer.enqueue<void>(async () => {
138
- const providerQueue = this.queues[providerId];
139
-
140
- if (!providerQueue) {
141
- this.logger.warn(`[${commandId}] Cannot flush this queue, because there is no provider queue. This happens when the provider queue was already cancelled, completed or the provider sent and error`);
142
-
143
- return;
144
- }
145
-
146
- if (!providerQueue.pendingResults.length) {
147
- this.logger.info(`[${commandId}] This provider does not have any pending results to flush.`);
148
- return;
149
- }
150
-
151
- const resultBatch: PublisherQueryResultBatch = {
152
- results: providerQueue.pendingResults,
153
- provider: providerQueue.providerData.myProviderData
154
- };
155
-
156
- providerQueue.pendingResults = [];
157
-
158
- try {
159
- await this.glueController.sendClientResultsBatch(resultBatch, this.clientInstanceId, this.queryId);
160
- } catch (error) {
161
- this.logger.warn(`[${commandId}] The client errored when handling search results for query: ${this.queryId} -> ${extractErrorMsg(error)}`);
162
- }
163
- });
164
-
165
- }
166
-
167
- private translateLegacySearchItem(searchResult: IOConnectSearch.QueryResult): LegacySearchResultItem {
168
- return {
169
- type: searchResult.type.name,
170
- category: searchResult.type.displayName,
171
- id: searchResult.id,
172
- displayName: searchResult.displayName,
173
- description: searchResult.description,
174
- iconURL: searchResult.iconURL,
175
- action: searchResult.action
176
- };
177
- }
178
- }
@@ -1,48 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export class AsyncSequelizer {
3
-
4
- private readonly queue: Array<{ action: () => Promise<any>; resolve: (args?: any) => void; reject: (err?: any) => void }> = [];
5
- private isExecutingQueue = false;
6
-
7
- constructor(private readonly minSequenceInterval: number = 0) { }
8
-
9
- public enqueue<T>(action: () => Promise<T>): Promise<T> {
10
- return new Promise<T>((resolve, reject) => {
11
- this.queue.push({ action, resolve, reject });
12
- this.executeQueue();
13
- });
14
- }
15
-
16
- private async executeQueue(): Promise<void> {
17
- if (this.isExecutingQueue) {
18
- return;
19
- }
20
-
21
- this.isExecutingQueue = true;
22
-
23
- while (this.queue.length) {
24
- const operation = this.queue.shift();
25
-
26
- // this satisfies the strict typescript mode
27
- if (!operation) {
28
- this.isExecutingQueue = false;
29
- return;
30
- }
31
-
32
- try {
33
- const actionResult = await operation.action();
34
- operation.resolve(actionResult);
35
- } catch (error) {
36
- operation.reject(error);
37
- }
38
-
39
- await this.intervalBreak();
40
- }
41
-
42
- this.isExecutingQueue = false;
43
- }
44
-
45
- private intervalBreak(): Promise<void> {
46
- return new Promise((res) => setTimeout(res, this.minSequenceInterval));
47
- }
48
- }
@@ -1,11 +0,0 @@
1
- export const MAIN_PROVIDER_METHOD_NAME = "T42.Search.Provider";
2
-
3
- export const MAIN_CLIENT_METHOD_NAME = "T42.Search.Client";
4
-
5
- export const SEQUELIZER_INTERVAL_MS = 10;
6
-
7
- export const FLUSH_SEQUELIZER_INTERVAL_MS = 10;
8
-
9
- export const FLUSH_TIMEOUT_MS = 100;
10
-
11
- export const STALE_QUERY_TIMEOUT_MS = 900000;
@@ -1,123 +0,0 @@
1
- import { Decoder, string, number, object, optional, array, oneOf, constant, anyJson } from "decoder-validate";
2
- import { IOConnectSearch } from "../../search";
3
- import { QueryStatus, Operation, ProtocolProviderError, ProtocolSearchCompleted, ProtocolSearchResultsBatch } from "./protocol";
4
- import { LegacySearchResultItem, SearchCancelRequest } from "./types";
5
-
6
- export const nonEmptyStringDecoder: Decoder<string> = string().where((s) => s.length > 0, "Expected a non-empty string");
7
- export const nonNegativeNumberDecoder: Decoder<number> = number().where((num) => num >= 0, "Expected a non-negative number");
8
-
9
- export const searchTypeDecoder: Decoder<IOConnectSearch.SearchType> = object({
10
- name: nonEmptyStringDecoder,
11
- displayName: optional(nonEmptyStringDecoder)
12
- });
13
-
14
- export const providerData: Decoder<IOConnectSearch.ProviderData> = object({
15
- id: nonEmptyStringDecoder,
16
- interopId: nonEmptyStringDecoder,
17
- name: nonEmptyStringDecoder,
18
- appName: optional(nonEmptyStringDecoder),
19
- types: optional(array(searchTypeDecoder))
20
- });
21
-
22
- export const providerLimitsDecoder: Decoder<IOConnectSearch.ProviderLimits> = object({
23
- maxResults: optional(nonNegativeNumberDecoder),
24
- maxResultsPerType: optional(nonNegativeNumberDecoder)
25
- });
26
-
27
- export const queryConfigDecoder: Decoder<IOConnectSearch.QueryConfig> = object({
28
- search: nonEmptyStringDecoder,
29
- providers: optional(array(providerData)),
30
- types: optional(array(searchTypeDecoder)),
31
- providerLimits: optional(providerLimitsDecoder)
32
- });
33
-
34
- export const providerRegistrationConfig: Decoder<IOConnectSearch.ProviderRegistrationConfig> = object({
35
- name: nonEmptyStringDecoder,
36
- types: optional(array(searchTypeDecoder))
37
- });
38
-
39
- export const operationDecoder: Decoder<Operation> = oneOf<"search" | "info" | "cancel">(
40
- constant("cancel"),
41
- constant("info"),
42
- constant("search")
43
- );
44
-
45
- export const queryStatusDecoder: Decoder<QueryStatus> = oneOf<"done" | "in-progress" | "error">(
46
- constant("done"),
47
- constant("in-progress"),
48
- constant("error")
49
- );
50
-
51
- export const searchCancelRequestDecoder: Decoder<SearchCancelRequest> = object({
52
- id: nonEmptyStringDecoder
53
- });
54
-
55
- export const mainActionDecoder: Decoder<IOConnectSearch.MainAction> = object({
56
- method: nonEmptyStringDecoder,
57
- target: optional(oneOf<{ instance: string } | "all">(
58
- object({ instance: nonEmptyStringDecoder }),
59
- constant("all")
60
- )),
61
- params: optional(anyJson())
62
- });
63
-
64
- export const secondaryActionDecoder: Decoder<IOConnectSearch.SecondaryAction> = object({
65
- name: nonEmptyStringDecoder,
66
- method: nonEmptyStringDecoder,
67
- target: optional(oneOf<{ instance: string } | "all">(
68
- object({ instance: nonEmptyStringDecoder }),
69
- constant("all")
70
- )),
71
- params: optional(anyJson())
72
- });
73
-
74
- export const queryResultDecoder: Decoder<IOConnectSearch.QueryResult> = object({
75
- type: searchTypeDecoder,
76
- id: optional(nonEmptyStringDecoder),
77
- displayName: optional(nonEmptyStringDecoder),
78
- description: optional(nonEmptyStringDecoder),
79
- iconURL: optional(nonEmptyStringDecoder),
80
- metadata: optional(anyJson()),
81
- action: optional(mainActionDecoder),
82
- secondaryActions: optional(array(secondaryActionDecoder))
83
- });
84
-
85
- export const legacySearchResultItemDecoder: Decoder<LegacySearchResultItem> = object({
86
- type: string(),
87
- category: optional(string()),
88
- id: optional(string()),
89
- displayName: optional(string()),
90
- description: optional(string()),
91
- iconURL: optional(string()),
92
- action: optional(mainActionDecoder)
93
- });
94
-
95
- export const protocolSearchResultsBatchDecoder: Decoder<ProtocolSearchResultsBatch> = object({
96
- items: array(oneOf<IOConnectSearch.QueryResult | LegacySearchResultItem>(
97
- queryResultDecoder,
98
- legacySearchResultItemDecoder
99
- )),
100
- provider: optional(providerData),
101
- queryId: nonEmptyStringDecoder,
102
- status: constant("in-progress")
103
- });
104
-
105
- export const protocolSearchCompletedDecoder: Decoder<ProtocolSearchCompleted> = object({
106
- items: array(oneOf<IOConnectSearch.QueryResult | LegacySearchResultItem>(
107
- queryResultDecoder,
108
- legacySearchResultItemDecoder
109
- )),
110
- queryId: nonEmptyStringDecoder,
111
- status: constant("done")
112
- });
113
-
114
- export const protocolProviderErrorDecoder: Decoder<ProtocolProviderError> = object({
115
- items: array(oneOf<IOConnectSearch.QueryResult | LegacySearchResultItem>(
116
- queryResultDecoder,
117
- legacySearchResultItemDecoder
118
- )),
119
- provider: optional(providerData),
120
- queryId: nonEmptyStringDecoder,
121
- errorMessage: nonEmptyStringDecoder,
122
- status: constant("error")
123
- });