@xpert-ai/plugin-sdk 3.6.1 → 3.6.2
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/index.cjs.js +21268 -1023
- package/index.esm.js +20893 -666
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/lib/data/datasource/adapter.strategy.d.ts +20 -0
- package/src/lib/data/datasource/index.d.ts +5 -0
- package/src/lib/data/datasource/strategy.decorator.d.ts +2 -0
- package/src/lib/data/datasource/strategy.interface.d.ts +19 -0
- package/src/lib/data/datasource/strategy.registry.d.ts +7 -0
- package/src/lib/data/datasource/types.d.ts +255 -0
- package/src/lib/data/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"dependencies": {},
|
|
6
6
|
"main": "./index.cjs.js",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"@metad/contracts": "*",
|
|
14
14
|
"@nestjs/common": "*",
|
|
15
15
|
"@nestjs/core": "*",
|
|
16
|
-
"@nestjs/microservices": "*",
|
|
17
16
|
"lodash-es": "*",
|
|
18
17
|
"i18next-fs-backend": "*",
|
|
19
18
|
"i18next": "*",
|
|
20
19
|
"zod": "*",
|
|
21
20
|
"fs": "*",
|
|
21
|
+
"stream": "*",
|
|
22
22
|
"path": "*"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IDataSourceStrategy } from './strategy.interface';
|
|
2
|
+
import { AdapterBaseOptions, DBQueryRunner, DBQueryRunnerType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Helper base class to wrap existing adapter query runner implementations
|
|
5
|
+
* into datasource strategies consumable by the plugin SDK.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AdapterDataSourceStrategy<TOptions extends AdapterBaseOptions = AdapterBaseOptions> implements IDataSourceStrategy<TOptions> {
|
|
8
|
+
private readonly runnerClass;
|
|
9
|
+
private readonly extraArgs;
|
|
10
|
+
abstract readonly type: string;
|
|
11
|
+
abstract readonly name: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
private configurationSchemaCache;
|
|
14
|
+
protected constructor(runnerClass: DBQueryRunnerType, extraArgs?: unknown[]);
|
|
15
|
+
create(options: TOptions): Promise<DBQueryRunner>;
|
|
16
|
+
configurationSchema(): Promise<Record<string, unknown>>;
|
|
17
|
+
teardown(runner: DBQueryRunner): Promise<void>;
|
|
18
|
+
protected instantiateRunner(options: TOptions | undefined): DBQueryRunner;
|
|
19
|
+
getClassType(): DBQueryRunnerType;
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AdapterBaseOptions, DBQueryRunner, DBQueryRunnerType } from "./types";
|
|
2
|
+
export interface IDataSourceStrategy<TOptions extends AdapterBaseOptions = AdapterBaseOptions> {
|
|
3
|
+
readonly type: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly description?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Create a query runner for the given data source options.
|
|
8
|
+
*/
|
|
9
|
+
create(options: TOptions): Promise<DBQueryRunner> | DBQueryRunner;
|
|
10
|
+
/**
|
|
11
|
+
* Optional configuration schema description for UI generation.
|
|
12
|
+
*/
|
|
13
|
+
configurationSchema?(): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Cleanup hook invoked when a runner is no longer needed.
|
|
16
|
+
*/
|
|
17
|
+
teardown?(runner: DBQueryRunner): Promise<void> | void;
|
|
18
|
+
getClassType(): DBQueryRunnerType;
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IDataSourceStrategy } from './strategy.interface';
|
|
4
|
+
import { AdapterBaseOptions } from './types';
|
|
5
|
+
export declare class DataSourceStrategyRegistry<TOptions extends AdapterBaseOptions = any> extends BaseStrategyRegistry<IDataSourceStrategy<TOptions>> {
|
|
6
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
7
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import * as _axios from 'axios';
|
|
5
|
+
import { Readable } from 'stream';
|
|
6
|
+
import { IColumnDef, IDSSchema, IDSTable } from '@metad/contracts';
|
|
7
|
+
export { IColumnDef, IDSSchema, IDSTable } from '@metad/contracts';
|
|
8
|
+
/**
|
|
9
|
+
* The base options for DB adapters
|
|
10
|
+
*/
|
|
11
|
+
export interface AdapterBaseOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Ref to debug in `createConnection` of `mysql`
|
|
14
|
+
*/
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Ref to trace in `createConnection` of `mysql`
|
|
18
|
+
*/
|
|
19
|
+
trace?: boolean;
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
}
|
|
25
|
+
export declare enum DBSyntaxEnum {
|
|
26
|
+
SQL = "sql",
|
|
27
|
+
MDX = "mdx"
|
|
28
|
+
}
|
|
29
|
+
export declare enum DBProtocolEnum {
|
|
30
|
+
SQL = "sql",
|
|
31
|
+
XMLA = "xmla"
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options of single query
|
|
35
|
+
*/
|
|
36
|
+
export interface QueryOptions {
|
|
37
|
+
catalog?: string;
|
|
38
|
+
headers?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
export interface QueryResult<T = unknown> {
|
|
41
|
+
status: 'OK' | 'ERROR';
|
|
42
|
+
data?: Array<T>;
|
|
43
|
+
columns?: Array<IColumnDef>;
|
|
44
|
+
stats?: any;
|
|
45
|
+
error?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Duties:
|
|
49
|
+
* - Convert error messages into a unified format
|
|
50
|
+
* - Connect different types of data sources
|
|
51
|
+
*/
|
|
52
|
+
export interface DBQueryRunner {
|
|
53
|
+
type: string;
|
|
54
|
+
name: string;
|
|
55
|
+
syntax: DBSyntaxEnum;
|
|
56
|
+
protocol: DBProtocolEnum;
|
|
57
|
+
host: string;
|
|
58
|
+
port: number | string;
|
|
59
|
+
jdbcDriver: string;
|
|
60
|
+
configurationSchema: Record<string, unknown>;
|
|
61
|
+
jdbcUrl(schema?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Execute a sql query
|
|
64
|
+
*
|
|
65
|
+
* @param sql
|
|
66
|
+
*/
|
|
67
|
+
run(sql: string): Promise<any>;
|
|
68
|
+
/**
|
|
69
|
+
* Execute a sql query with options
|
|
70
|
+
*
|
|
71
|
+
* @param query
|
|
72
|
+
* @param options
|
|
73
|
+
*/
|
|
74
|
+
runQuery(query: string, options?: QueryOptions): Promise<QueryResult | any>;
|
|
75
|
+
/**
|
|
76
|
+
* Get catalog (schema or database) list in data source
|
|
77
|
+
*/
|
|
78
|
+
getCatalogs(): Promise<IDSSchema[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Get schema of table in catalog (schema or database)
|
|
81
|
+
*
|
|
82
|
+
* @param catalog
|
|
83
|
+
* @param tableName
|
|
84
|
+
*/
|
|
85
|
+
getSchema(catalog?: string, tableName?: string): Promise<IDSSchema[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Describe a sql query result schema
|
|
88
|
+
*
|
|
89
|
+
* @param catalog
|
|
90
|
+
* @param statement
|
|
91
|
+
*/
|
|
92
|
+
describe(catalog: string, statement: string): Promise<{
|
|
93
|
+
columns?: IDSTable['columns'];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Ping the db
|
|
97
|
+
*/
|
|
98
|
+
ping(): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Create a new catalog (schema) in database
|
|
101
|
+
*
|
|
102
|
+
* @param catalog
|
|
103
|
+
*/
|
|
104
|
+
createCatalog?(catalog: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Create or append table data
|
|
107
|
+
*
|
|
108
|
+
* @param params
|
|
109
|
+
* @param options
|
|
110
|
+
*/
|
|
111
|
+
import(params: CreationTable, options?: QueryOptions): Promise<any>;
|
|
112
|
+
/**
|
|
113
|
+
* Drop a table
|
|
114
|
+
*
|
|
115
|
+
* @param name Table name
|
|
116
|
+
* @param options
|
|
117
|
+
*/
|
|
118
|
+
dropTable(name: string, options?: QueryOptions): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Teardown all resources:
|
|
121
|
+
* - close connection
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
teardown(): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
export type DBQueryRunnerType = new (options?: AdapterBaseOptions, ...args: unknown[]) => DBQueryRunner;
|
|
127
|
+
export interface ColumnDef {
|
|
128
|
+
/**
|
|
129
|
+
* Key of data object
|
|
130
|
+
*/
|
|
131
|
+
name: string;
|
|
132
|
+
/**
|
|
133
|
+
* Name of table column
|
|
134
|
+
*/
|
|
135
|
+
fieldName: string;
|
|
136
|
+
/**
|
|
137
|
+
* Object value type, convert to db type
|
|
138
|
+
*/
|
|
139
|
+
type: string;
|
|
140
|
+
/**
|
|
141
|
+
* Is primary key column
|
|
142
|
+
*/
|
|
143
|
+
isKey: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* length of type for column: varchar, decimal ...
|
|
146
|
+
*/
|
|
147
|
+
length?: number;
|
|
148
|
+
/**
|
|
149
|
+
* fraction of type for decimal
|
|
150
|
+
*/
|
|
151
|
+
fraction?: number;
|
|
152
|
+
}
|
|
153
|
+
export interface CreationTable {
|
|
154
|
+
catalog?: string;
|
|
155
|
+
table?: string;
|
|
156
|
+
name: string;
|
|
157
|
+
columns: ColumnDef[];
|
|
158
|
+
data?: any[];
|
|
159
|
+
file?: File;
|
|
160
|
+
mergeType?: 'APPEND' | 'DELETE' | 'MERGE';
|
|
161
|
+
format?: 'csv' | 'json' | 'parquet' | 'orc' | 'data';
|
|
162
|
+
columnSeparator?: string;
|
|
163
|
+
withHeader?: number;
|
|
164
|
+
}
|
|
165
|
+
export declare abstract class BaseQueryRunner<T extends AdapterBaseOptions = AdapterBaseOptions> implements DBQueryRunner {
|
|
166
|
+
type: string;
|
|
167
|
+
name: string;
|
|
168
|
+
syntax: DBSyntaxEnum;
|
|
169
|
+
protocol: DBProtocolEnum;
|
|
170
|
+
jdbcDriver: string;
|
|
171
|
+
abstract get host(): string;
|
|
172
|
+
abstract get port(): number | string;
|
|
173
|
+
options: T;
|
|
174
|
+
jdbcUrl(schema?: string): string;
|
|
175
|
+
get configurationSchema(): any;
|
|
176
|
+
constructor(options?: T);
|
|
177
|
+
run(sql: string): Promise<any>;
|
|
178
|
+
abstract runQuery(query: string, options?: QueryOptions): Promise<QueryResult>;
|
|
179
|
+
abstract getCatalogs(): Promise<IDSSchema[]>;
|
|
180
|
+
abstract getSchema(catalog?: string, tableName?: string): Promise<IDSSchema[]>;
|
|
181
|
+
describe(catalog: string, statement: string): Promise<{
|
|
182
|
+
columns?: IDSTable['columns'];
|
|
183
|
+
}>;
|
|
184
|
+
abstract ping(): Promise<void>;
|
|
185
|
+
import({ name, columns, data }: {
|
|
186
|
+
name: any;
|
|
187
|
+
columns: any;
|
|
188
|
+
data: any;
|
|
189
|
+
}, options?: {
|
|
190
|
+
catalog?: string;
|
|
191
|
+
}): Promise<void>;
|
|
192
|
+
dropTable(name: string, options?: any): Promise<void>;
|
|
193
|
+
abstract teardown(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
export interface HttpAdapterOptions extends AdapterBaseOptions {
|
|
196
|
+
url?: string;
|
|
197
|
+
}
|
|
198
|
+
export declare abstract class BaseHTTPQueryRunner<T extends HttpAdapterOptions = HttpAdapterOptions> extends BaseQueryRunner<T> {
|
|
199
|
+
get url(): string;
|
|
200
|
+
get host(): string;
|
|
201
|
+
get port(): number | string;
|
|
202
|
+
get configurationSchema(): {};
|
|
203
|
+
get(): Promise<_axios.AxiosResponse<any, any>>;
|
|
204
|
+
post(data: any, options?: any): Promise<_axios.AxiosResponse<any, any>>;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Adapter options for sql db
|
|
208
|
+
*/
|
|
209
|
+
export interface SQLAdapterOptions extends AdapterBaseOptions {
|
|
210
|
+
url?: string;
|
|
211
|
+
/**
|
|
212
|
+
* Database name, used as catalog
|
|
213
|
+
*/
|
|
214
|
+
catalog?: string;
|
|
215
|
+
use_ssl?: boolean;
|
|
216
|
+
ssl_cacert?: string;
|
|
217
|
+
version?: number;
|
|
218
|
+
}
|
|
219
|
+
export declare abstract class BaseSQLQueryRunner<T extends SQLAdapterOptions = SQLAdapterOptions> extends BaseQueryRunner<T> {
|
|
220
|
+
syntax: DBSyntaxEnum;
|
|
221
|
+
protocol: DBProtocolEnum;
|
|
222
|
+
get host(): string;
|
|
223
|
+
get port(): string | number;
|
|
224
|
+
abstract createCatalog?(catalog: string): Promise<void>;
|
|
225
|
+
ping(): Promise<void>;
|
|
226
|
+
}
|
|
227
|
+
export interface File {
|
|
228
|
+
/** Name of the form field associated with this file. */
|
|
229
|
+
fieldname: string;
|
|
230
|
+
/** Name of the file on the uploader's computer. */
|
|
231
|
+
originalname: string;
|
|
232
|
+
/**
|
|
233
|
+
* Value of the `Content-Transfer-Encoding` header for this file.
|
|
234
|
+
* @deprecated since July 2015
|
|
235
|
+
* @see RFC 7578, Section 4.7
|
|
236
|
+
*/
|
|
237
|
+
encoding: string;
|
|
238
|
+
/** Value of the `Content-Type` header for this file. */
|
|
239
|
+
mimetype: string;
|
|
240
|
+
/** Size of the file in bytes. */
|
|
241
|
+
size: number;
|
|
242
|
+
/**
|
|
243
|
+
* A readable stream of this file. Only available to the `_handleFile`
|
|
244
|
+
* callback for custom `StorageEngine`s.
|
|
245
|
+
*/
|
|
246
|
+
stream: Readable;
|
|
247
|
+
/** `DiskStorage` only: Directory to which this file has been uploaded. */
|
|
248
|
+
destination: string;
|
|
249
|
+
/** `DiskStorage` only: Name of this file within `destination`. */
|
|
250
|
+
filename: string;
|
|
251
|
+
/** `DiskStorage` only: Full path to the uploaded file. */
|
|
252
|
+
path: string;
|
|
253
|
+
/** `MemoryStorage` only: A Buffer containing the entire file. */
|
|
254
|
+
buffer: Buffer;
|
|
255
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './datasource/index';
|