@interopio/search-api 2.0.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.
@@ -0,0 +1,118 @@
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 { MainController } from "../controllers/main";
6
+ import { ProviderController } from "../controllers/provider";
7
+ import { SearchFacade } from "../facade";
8
+ import { FLUSH_SEQUELIZER_INTERVAL_MS, SEQUELIZER_INTERVAL_MS } from "./constants";
9
+ import { AsyncSequelizer } from "../services/sequelizer";
10
+ import { LimitsTracker } from "../services/limits-tracker";
11
+ import { ModelFactory } from "../services/model-factory";
12
+
13
+ export class IoC {
14
+ private _glueController!: GlueController;
15
+ private _facade!: SearchFacade;
16
+ private _mainController!: MainController;
17
+ private _providerController!: ProviderController;
18
+ private _clientController!: ClientController;
19
+ private _asyncSequelizer!: AsyncSequelizer;
20
+ private _flushSequelizer!: AsyncSequelizer;
21
+ private _limitsTracker!: LimitsTracker;
22
+ private _modelFactory!: ModelFactory;
23
+
24
+ constructor(
25
+ private readonly glue: IOConnectCore.API, private readonly config?: IOConnectSearch.Config
26
+ ) {}
27
+
28
+ public get glueController(): GlueController {
29
+ if (!this._glueController) {
30
+ this._glueController = new GlueController(this.glue);
31
+ }
32
+
33
+ return this._glueController;
34
+ }
35
+
36
+ public get main(): MainController {
37
+ if (!this._mainController) {
38
+ this._mainController = new MainController(
39
+ this.glue.logger.subLogger("search.main.controller"),
40
+ this.glueController,
41
+ this.clientController,
42
+ this.providerController
43
+ );
44
+ }
45
+
46
+ return this._mainController;
47
+ }
48
+
49
+ public get clientController(): ClientController {
50
+ if (!this._clientController) {
51
+ this._clientController = new ClientController(
52
+ this.glue.logger.subLogger("search.client.controller"),
53
+ this.glueController,
54
+ this.modelFactory
55
+ );
56
+ }
57
+
58
+ return this._clientController;
59
+ }
60
+
61
+ public get providerController(): ProviderController {
62
+ if (!this._providerController) {
63
+ this._providerController = new ProviderController(
64
+ this.glue.logger.subLogger("search.provider.controller"),
65
+ this.glueController,
66
+ this.sequelizer,
67
+ this.limitsTracker,
68
+ this.modelFactory
69
+ );
70
+ }
71
+
72
+ return this._providerController;
73
+ }
74
+
75
+ public get facade(): SearchFacade {
76
+ if (!this._facade) {
77
+ this._facade = new SearchFacade(this.main);
78
+ }
79
+
80
+ return this._facade;
81
+ }
82
+
83
+ public get sequelizer(): AsyncSequelizer {
84
+ if (!this._asyncSequelizer) {
85
+ this._asyncSequelizer = new AsyncSequelizer(SEQUELIZER_INTERVAL_MS);
86
+ }
87
+
88
+ return this._asyncSequelizer;
89
+ }
90
+
91
+ public get flushSequelizer(): AsyncSequelizer {
92
+ if (!this._flushSequelizer) {
93
+ this._flushSequelizer = new AsyncSequelizer(FLUSH_SEQUELIZER_INTERVAL_MS);
94
+ }
95
+
96
+ return this._flushSequelizer;
97
+ }
98
+
99
+ public get limitsTracker(): LimitsTracker {
100
+ if (!this._limitsTracker) {
101
+ this._limitsTracker = new LimitsTracker();
102
+ }
103
+
104
+ return this._limitsTracker;
105
+ }
106
+
107
+ public get modelFactory(): ModelFactory {
108
+ if (!this._modelFactory) {
109
+ this._modelFactory = new ModelFactory(
110
+ this.glueController,
111
+ this.glue,
112
+ this.flushSequelizer
113
+ );
114
+ }
115
+
116
+ return this._modelFactory;
117
+ }
118
+ }
@@ -0,0 +1,71 @@
1
+ import { IOConnectSearch } from "../../search";
2
+ import { LegacySearchResultItem } from "./types";
3
+
4
+ export const SEARCH_QUERY_STATUSES: {
5
+ done: "done",
6
+ inProgress: "in-progress",
7
+ error: "error"
8
+ } = {
9
+ done: "done",
10
+ inProgress: "in-progress",
11
+ error: "error"
12
+ };
13
+
14
+ export const CLIENT_TO_PROVIDER_PROTOCOL_OPERATIONS: {
15
+ info: "info",
16
+ search: "search",
17
+ cancel: "cancel"
18
+ } = {
19
+ info: "info",
20
+ search: "search",
21
+ cancel: "cancel"
22
+ };
23
+
24
+ export type Operation = "search" | "info" | "cancel";
25
+
26
+ export type QueryStatus = "done" | "in-progress" | "error";
27
+
28
+ export interface ProtocolSearchResultsBatch {
29
+ items: (IOConnectSearch.QueryResult | LegacySearchResultItem)[];
30
+ provider?: IOConnectSearch.ProviderData;
31
+ queryId: string;
32
+ status: "in-progress";
33
+ }
34
+
35
+ export interface ProtocolSearchCompleted {
36
+ items: (IOConnectSearch.QueryResult | LegacySearchResultItem)[];
37
+ queryId: string;
38
+ status: "done";
39
+ }
40
+
41
+ export interface ProtocolProviderError {
42
+ items: (IOConnectSearch.QueryResult | LegacySearchResultItem)[];
43
+ provider?: IOConnectSearch.ProviderData;
44
+ queryId: string;
45
+ errorMessage: string;
46
+ status: "error";
47
+ }
48
+
49
+ export interface ProtocolQueryCancelRequest {
50
+ operation: "cancel",
51
+ id: string;
52
+ }
53
+
54
+ export interface ProtocolProviderInfoRequest {
55
+ operation: "info"
56
+ }
57
+
58
+ export interface ProtocolProviderInfoResponse {
59
+ supportedTypes: string[];
60
+ providers: IOConnectSearch.ProviderData[];
61
+ apiVersion: "1";
62
+ }
63
+
64
+ export interface ProtocolSearchRequest extends IOConnectSearch.QueryConfig {
65
+ operation: "search"
66
+ apiVersion: "1"
67
+ }
68
+
69
+ export interface ProtocolSearchResponse {
70
+ id: string;
71
+ }
@@ -0,0 +1,103 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { IOConnectSearch } from "../../search";
3
+ import { ClientQuery } from "../models/client-query";
4
+ import { ProviderModel } from "../models/provider";
5
+ import { QueryResultsPublisher } from "../services/publisher";
6
+ import { ProtocolProviderInfoResponse } from "./protocol";
7
+
8
+ export interface LegacySearchRequest {
9
+ search: string;
10
+ limit: number;
11
+ categoryLimit: number;
12
+ types: string[];
13
+ }
14
+
15
+ export interface LegacySearchResultItem {
16
+ type: string;
17
+ category?: string;
18
+ id?: string;
19
+ displayName?: string;
20
+ description?: string;
21
+ iconURL?: string;
22
+ action?: {
23
+ method: string;
24
+ params?: any;
25
+ }
26
+ }
27
+
28
+ export interface QueryIdentification {
29
+ queryId: string;
30
+ providerId: string;
31
+ }
32
+
33
+ export interface ActiveQuery {
34
+ queryId: string;
35
+ callerInstanceId: string;
36
+ providersAtWork: ProviderModel[];
37
+ requestedTypes?: IOConnectSearch.SearchType[];
38
+ publisher: QueryResultsPublisher;
39
+ staleTimer: NodeJS.Timeout;
40
+ }
41
+
42
+ export interface SearchCancelRequest {
43
+ id: string;
44
+ }
45
+
46
+ export interface ProviderQueryDoneCommand {
47
+ identification: QueryIdentification;
48
+ commandId: string;
49
+ }
50
+
51
+ export interface ProviderQueryErrorCommand {
52
+ identification: QueryIdentification;
53
+ commandId: string;
54
+ error: string;
55
+ }
56
+
57
+ export interface ProviderQueryResultCommand {
58
+ identification: QueryIdentification;
59
+ commandId: string;
60
+ result: IOConnectSearch.QueryResult;
61
+ }
62
+
63
+ export interface PublisherQueryResultBatch {
64
+ results: (IOConnectSearch.QueryResult | LegacySearchResultItem)[];
65
+ provider: IOConnectSearch.ProviderData;
66
+ }
67
+
68
+ export interface InteropServerProvider {
69
+ interopId: string;
70
+ info: ProtocolProviderInfoResponse;
71
+ }
72
+
73
+ export interface InteropServerQueryIdentification {
74
+ interopId: string;
75
+ queryId: string;
76
+ }
77
+
78
+ export interface ActiveClientQuery {
79
+ servers: InteropServerQueryIdentification[],
80
+ model: ClientQuery
81
+ }
82
+
83
+ export interface ProviderQueue {
84
+ pendingResults: (IOConnectSearch.QueryResult | LegacySearchResultItem)[],
85
+ providerData: ProviderModel;
86
+ flushTimer?: NodeJS.Timeout;
87
+ suspended?: boolean;
88
+ }
89
+
90
+ export interface QueryProviderResultsTracker {
91
+ total: number;
92
+ [key: string]: number;
93
+ }
94
+
95
+ export interface ProviderQueryLimit {
96
+ maxResults: number;
97
+ maxResultsPerType: number;
98
+ }
99
+
100
+ export interface LimitTestResult {
101
+ maxLimitHit?: boolean;
102
+ maxLimitPerTypeHit?: boolean;
103
+ }
@@ -0,0 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ export const extractErrorMsg = (error: any): string => {
3
+ const stringError = typeof error === "string" ?
4
+ error :
5
+ error.message ? JSON.stringify(error.message) :
6
+ JSON.stringify(error);
7
+
8
+ return stringError;
9
+ };