@relevanceai/sdk 1.149.0 → 2.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.
- package/README.md +27 -49
- package/package.json +3 -2
- package/dist-cjs/generated/DiscoveryApi.js +0 -1378
- package/dist-cjs/generated/_DiscoveryApiSchemaTypes.js +0 -3
- package/dist-cjs/generated/index.js +0 -17
- package/dist-cjs/index.js +0 -18
- package/dist-cjs/services/discovery/Dataset.js +0 -126
- package/dist-cjs/services/discovery/index.js +0 -159
- package/dist-cjs/services/index.js +0 -3
- package/dist-cjs/shared/BaseClient.js +0 -35
- package/dist-cjs/shared/generate.js +0 -90
- package/dist-cjs/shared/serviceConfigs.js +0 -10
- package/dist-es/generated/DiscoveryApi.js +0 -2123
- package/dist-es/generated/_DiscoveryApiSchemaTypes.js +0 -2
- package/dist-es/generated/index.js +0 -1
- package/dist-es/index.js +0 -2
- package/dist-es/services/discovery/Dataset.js +0 -126
- package/dist-es/services/discovery/index.js +0 -159
- package/dist-es/services/index.js +0 -3
- package/dist-es/shared/BaseClient.js +0 -82
- package/dist-es/shared/generate.js +0 -224
- package/dist-es/shared/serviceConfigs.js +0 -7
- package/dist-types/generated/DiscoveryApi.d.ts +0 -518
- package/dist-types/generated/_DiscoveryApiSchemaTypes.d.ts +0 -20001
- package/dist-types/generated/index.d.ts +0 -1
- package/dist-types/index.d.ts +0 -1
- package/dist-types/services/discovery/Dataset.d.ts +0 -0
- package/dist-types/services/discovery/index.d.ts +0 -0
- package/dist-types/services/index.d.ts +0 -0
- package/dist-types/shared/BaseClient.d.ts +0 -28
- package/dist-types/shared/generate.d.ts +0 -1
- package/dist-types/shared/serviceConfigs.d.ts +0 -8
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./DiscoveryApi"), exports);
|
package/dist-cjs/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./generated"), exports);
|
|
18
|
-
// export * from './services';
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { QueryBuilder, DiscoveryClient, _QueryBuilder } from ".";
|
|
3
|
-
// import { DeleteDocumentOutput, DeleteWhereOutput, GetDocumentOutput, SimpleSearchPostOutput, BulkInsertOutput,UpdateWhereOutput,BulkUpdateOutput } from "../..";
|
|
4
|
-
// import { _GenericMethodOptions } from "../../shared/BaseClient";
|
|
5
|
-
// interface searchOptions {
|
|
6
|
-
// debounce?:number;
|
|
7
|
-
// rawPayload?:any;
|
|
8
|
-
// }
|
|
9
|
-
// export class Dataset {
|
|
10
|
-
// client: DiscoveryClient;
|
|
11
|
-
// name: string;
|
|
12
|
-
// config: any;
|
|
13
|
-
// debounceTimer?:NodeJS.Timeout;
|
|
14
|
-
// constructor(client: DiscoveryClient, name: string, options: any) {
|
|
15
|
-
// // TODO validate name
|
|
16
|
-
// this.client = client;
|
|
17
|
-
// this.name = name;
|
|
18
|
-
// this.config = options;
|
|
19
|
-
// }
|
|
20
|
-
// get datasetName(): string {
|
|
21
|
-
// return this.name;
|
|
22
|
-
// };
|
|
23
|
-
// async insertDocument(document: any, options?: _GenericMethodOptions) {
|
|
24
|
-
// const response = await this.client.apiClient.Insert({
|
|
25
|
-
// document,
|
|
26
|
-
// ...options
|
|
27
|
-
// }, { dataset_id: this.name });
|
|
28
|
-
// return response.body;
|
|
29
|
-
// }
|
|
30
|
-
// // without options
|
|
31
|
-
// async search(): Promise<SimpleSearchPostOutput>;
|
|
32
|
-
// async search(query?: _QueryBuilder): Promise<SimpleSearchPostOutput>;
|
|
33
|
-
// async search(options?:searchOptions): Promise<SimpleSearchPostOutput>;
|
|
34
|
-
// async search(query?: _QueryBuilder,options?:searchOptions): Promise<SimpleSearchPostOutput>;
|
|
35
|
-
// async search(...args:any[]) {
|
|
36
|
-
// let payload: any = {};
|
|
37
|
-
// let options:searchOptions = {};
|
|
38
|
-
// for (const arg of args) {
|
|
39
|
-
// if (arg instanceof _QueryBuilder) {
|
|
40
|
-
// payload = {...payload,...arg.build()};
|
|
41
|
-
// }
|
|
42
|
-
// else {
|
|
43
|
-
// options = arg;
|
|
44
|
-
// if (options.rawPayload) payload = {...payload,...options.rawPayload};
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// const reqCallback = async () => await this.client.apiClient.SimpleSearchPost(payload, { dataset_id: this.name });
|
|
48
|
-
// if (options.debounce && this.debounceTimer) {
|
|
49
|
-
// clearTimeout(this.debounceTimer);
|
|
50
|
-
// return new Promise((resolve) => {
|
|
51
|
-
// this.debounceTimer = setTimeout(async () => {const res = await reqCallback();resolve(res)},options.debounce);
|
|
52
|
-
// });
|
|
53
|
-
// } else {
|
|
54
|
-
// const response = await reqCallback();
|
|
55
|
-
// return response.body;
|
|
56
|
-
// }
|
|
57
|
-
// }
|
|
58
|
-
// async insertDocuments(documents: any, options?: _GenericMethodOptions & { batchSize?: number,retryCount?:number, progressCallback?: (progress:BulkInsertOutput[]) => any }):Promise<BulkInsertOutput> {
|
|
59
|
-
// const results = await this._GenericBulkOperation<any,BulkInsertOutput>({
|
|
60
|
-
// data:documents??[],
|
|
61
|
-
// ...options,
|
|
62
|
-
// fn:async (documentsSlice) => (await this.client.apiClient.BulkInsert({ documents:documentsSlice }, { dataset_id: this.name })).body
|
|
63
|
-
// });
|
|
64
|
-
// const finalResults = results.reduce((prev,cur) => {
|
|
65
|
-
// prev.failed_documents = prev.failed_documents.concat(cur.failed_documents);
|
|
66
|
-
// prev.inserted += cur.inserted
|
|
67
|
-
// return prev;
|
|
68
|
-
// },{inserted:0,failed_documents:[]});
|
|
69
|
-
// return finalResults;
|
|
70
|
-
// }
|
|
71
|
-
// // TODO - ChunkSearch, insert, insertAndVectorize?, vectorize,
|
|
72
|
-
// async _GenericBulkOperation<InputItem,OutputItem>({data,batchSize,fn,retryCount}:{
|
|
73
|
-
// data:InputItem[],
|
|
74
|
-
// fn:(data:InputItem[]) => Promise<OutputItem>,
|
|
75
|
-
// batchSize?:number,
|
|
76
|
-
// retryCount?:number,
|
|
77
|
-
// progressCallback?:(progress:OutputItem[]) => any
|
|
78
|
-
// }):Promise<OutputItem[]> {
|
|
79
|
-
// batchSize = batchSize ?? 10000;
|
|
80
|
-
// retryCount = retryCount ?? 1;
|
|
81
|
-
// const results:OutputItem[] = [];
|
|
82
|
-
// for (let i = 0; i < data?.length; i += batchSize) {
|
|
83
|
-
// for (let retrysSoFar = 0; retrysSoFar < retryCount; retrysSoFar++) {
|
|
84
|
-
// try {
|
|
85
|
-
// const res = await fn(data.slice(i, i + batchSize));
|
|
86
|
-
// results.push(res);
|
|
87
|
-
// break;
|
|
88
|
-
// } catch (e) { console.error(`Bulk operation failed with error, retrying - ${e}`) }
|
|
89
|
-
// }
|
|
90
|
-
// }
|
|
91
|
-
// return results;
|
|
92
|
-
// }
|
|
93
|
-
// async updateDocument(documentId: string, partialUpdates: any) {
|
|
94
|
-
// const response = await this.client.apiClient.Update({ id: documentId, updates: partialUpdates });
|
|
95
|
-
// return response.body;
|
|
96
|
-
// }
|
|
97
|
-
// async updateDocuments(updates: any, options?: _GenericMethodOptions & { batchSize?: number,retryCount?:number, progressCallback?: (progress:BulkUpdateOutput[]) => any }):Promise<BulkUpdateOutput> {
|
|
98
|
-
// const results = await this._GenericBulkOperation<any,BulkUpdateOutput>({
|
|
99
|
-
// data:updates??[],
|
|
100
|
-
// ...options,
|
|
101
|
-
// fn:async (updatesSlice) => (await this.client.apiClient.BulkUpdate({ updates:updatesSlice }, { dataset_id: this.name })).body
|
|
102
|
-
// });
|
|
103
|
-
// const finalResults = results.reduce((prev,cur) => {
|
|
104
|
-
// prev.failed_documents = prev.failed_documents.concat(cur.failed_documents);
|
|
105
|
-
// prev.inserted += cur.inserted
|
|
106
|
-
// return prev;
|
|
107
|
-
// },{inserted:0,failed_documents:[]});
|
|
108
|
-
// return finalResults;
|
|
109
|
-
// }
|
|
110
|
-
// async updateDocumentsWhere(filters: _QueryBuilder, partialUpdates: {[id:string]:any}):Promise<UpdateWhereOutput> {
|
|
111
|
-
// return (await this.client.apiClient.UpdateWhere({ filters: filters.build().filters, updates: partialUpdates })).body;
|
|
112
|
-
// }
|
|
113
|
-
// async getDocument(documentId: string):Promise<GetDocumentOutput> {
|
|
114
|
-
// return (await this.client.apiClient.GetDocument({document_id:documentId})).body;
|
|
115
|
-
// }
|
|
116
|
-
// async deleteDocument(documentId: string):Promise<DeleteDocumentOutput> {
|
|
117
|
-
// return (await this.client.apiClient.DeleteDocument({id:documentId})).body;
|
|
118
|
-
// }
|
|
119
|
-
// async deleteDocuments(documentIds: [string]):Promise<DeleteWhereOutput> {
|
|
120
|
-
// const filters = QueryBuilder().match('_id',documentIds);
|
|
121
|
-
// return (await this.client.apiClient.DeleteWhere({ filters: filters.build().filters??[] })).body;
|
|
122
|
-
// }
|
|
123
|
-
// async deleteDocumentsWhere(filters: _QueryBuilder):Promise<DeleteWhereOutput> {
|
|
124
|
-
// return (await this.client.apiClient.DeleteWhere({ filters: filters.build().filters??[]})).body;
|
|
125
|
-
// }
|
|
126
|
-
// }
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { DiscoveryApiClient, BulkInsertInput, BulkInsertOutput } from '../../';
|
|
3
|
-
// import { _ClientInput, CommandInput, CommandOutput, _GenericMethodOptions } from '../../shared/BaseClient';
|
|
4
|
-
// import { operations, components } from '../../generated/_DiscoveryApiSchemaTypes';
|
|
5
|
-
// import { Dataset } from './Dataset';
|
|
6
|
-
// type bodyType = operations['SimpleSearchPost']['requestBody']['content']['application/json'];
|
|
7
|
-
// export function QueryBuilder():_QueryBuilder{
|
|
8
|
-
// return new _QueryBuilder();
|
|
9
|
-
// }
|
|
10
|
-
// export function FilterBuilder():_FilterBuilder{
|
|
11
|
-
// return new _FilterBuilder();
|
|
12
|
-
// }
|
|
13
|
-
// export class _FilterBuilder {
|
|
14
|
-
// body: bodyType;
|
|
15
|
-
// constructor() {
|
|
16
|
-
// this.body = {filters:[],fieldsToAggregate:[],fieldsToAggregateStats:[]};
|
|
17
|
-
// }
|
|
18
|
-
// buildFilters() {
|
|
19
|
-
// return this.body.filters;
|
|
20
|
-
// }
|
|
21
|
-
// rawFilter(filter: components['schemas']['filterListItem']) {
|
|
22
|
-
// this.body.filters?.push(filter);
|
|
23
|
-
// return this;
|
|
24
|
-
// }
|
|
25
|
-
// filter(type: string, key: string, value: string, ...options: any) {
|
|
26
|
-
// this.body.filters?.push({
|
|
27
|
-
// [type]: {
|
|
28
|
-
// key,
|
|
29
|
-
// value,
|
|
30
|
-
// ...options
|
|
31
|
-
// }
|
|
32
|
-
// });
|
|
33
|
-
// return this;
|
|
34
|
-
// }
|
|
35
|
-
// match(field: string, value: any) {
|
|
36
|
-
// this.body.filters?.push({ match: { key: field, value } });
|
|
37
|
-
// return this;
|
|
38
|
-
// }
|
|
39
|
-
// wildcard(field: string, value: any) {
|
|
40
|
-
// this.body.filters?.push({ wildcard: { key: field, value } });
|
|
41
|
-
// return this;
|
|
42
|
-
// }
|
|
43
|
-
// selfreference(fielda: string, fieldb: string, operation: "<=" | ">=" | "<" | ">" | "==" | "!=") {
|
|
44
|
-
// this.body.filters?.push({ selfreference: { a: fielda, b: fieldb, operation } });
|
|
45
|
-
// return this;
|
|
46
|
-
// }
|
|
47
|
-
// range(field: string, options: Omit<components['schemas']['filterListItem']['range'],'key'>) {
|
|
48
|
-
// this.body.filters?.push({ range: { key: field, ...options } });
|
|
49
|
-
// return this;
|
|
50
|
-
// }
|
|
51
|
-
// or(filters: _FilterBuilder[]) {
|
|
52
|
-
// this.body.filters?.push({ or: filters.map(f => f.body.filters ?? []) });
|
|
53
|
-
// return this;
|
|
54
|
-
// }
|
|
55
|
-
// not(filter: _FilterBuilder) {
|
|
56
|
-
// this.body.filters?.push({ not: filter.body?.filters ?? [] });
|
|
57
|
-
// return this;
|
|
58
|
-
// }
|
|
59
|
-
// }
|
|
60
|
-
// export class _QueryBuilder extends _FilterBuilder {
|
|
61
|
-
// defaultQueryValue?: string;
|
|
62
|
-
// shouldPerformTextQuery:boolean;
|
|
63
|
-
// constructor() {
|
|
64
|
-
// super();
|
|
65
|
-
// this.shouldPerformTextQuery = false;
|
|
66
|
-
// }
|
|
67
|
-
// build() {
|
|
68
|
-
// if (!this.shouldPerformTextQuery) return this.body;
|
|
69
|
-
// if (!this.defaultQueryValue) throw new Error("Please set the search query by calling .query('my search query') before performing a text search.");
|
|
70
|
-
// this.body.query = this.defaultQueryValue;
|
|
71
|
-
// return this.body;
|
|
72
|
-
// }
|
|
73
|
-
// query(query:string,fieldsToSearch?: bodyType['fieldsToSearch']) {
|
|
74
|
-
// this.defaultQueryValue = query;
|
|
75
|
-
// if (fieldsToSearch) this.body.fieldsToSearch = fieldsToSearch;
|
|
76
|
-
// return this;
|
|
77
|
-
// }
|
|
78
|
-
// queryConfig(weight:number,options?:bodyType['queryConfig']) {
|
|
79
|
-
// this.body.queryConfig = {weight,...(options??{})};
|
|
80
|
-
// return this;
|
|
81
|
-
// }
|
|
82
|
-
// text(field?:string): _QueryBuilder;
|
|
83
|
-
// text(field?:string,weight?:number):_QueryBuilder{
|
|
84
|
-
// this.shouldPerformTextQuery = true;
|
|
85
|
-
// if (!field) return this; // support searching all fields
|
|
86
|
-
// if (!this.body.fieldsToSearch) this.body.fieldsToSearch = [];
|
|
87
|
-
// if (!weight) this.body.fieldsToSearch.push(field);
|
|
88
|
-
// else this.body.fieldsToSearch.push({field,weight});
|
|
89
|
-
// return this;
|
|
90
|
-
// }
|
|
91
|
-
// vector(field: string, weight?: number): _QueryBuilder;
|
|
92
|
-
// vector(field: string, options?: components['schemas']['vectorSearchQuery']): _QueryBuilder;
|
|
93
|
-
// vector(field: string, weight?: number, options?: components['schemas']['vectorSearchQuery']): _QueryBuilder;
|
|
94
|
-
// vector(field: string, ...args:any[]) {
|
|
95
|
-
// if (!Array.isArray(this.body.vectorSearchQuery)) this.body.vectorSearchQuery = [];
|
|
96
|
-
// let payload:components['schemas']['vectorSearchQuery'] = {field};
|
|
97
|
-
// const inferredModelMatch = field.match(/_(.*)_.*vector_/) // title_text@1-0_vector_ -> text@1-0
|
|
98
|
-
// if (inferredModelMatch && inferredModelMatch[1]) payload.model = inferredModelMatch[1]; // this can be overridden
|
|
99
|
-
// for (const arg of args) {
|
|
100
|
-
// if (typeof arg ==='number') payload.weight = arg; // weight
|
|
101
|
-
// else payload = {...payload,...arg}; // options
|
|
102
|
-
// }
|
|
103
|
-
// this.body.vectorSearchQuery.push(payload);
|
|
104
|
-
// return this;
|
|
105
|
-
// }
|
|
106
|
-
// sort(field: string, direction: 'asc' | 'desc') {
|
|
107
|
-
// if (!this?.body?.sort?.length) this.body.sort = {};
|
|
108
|
-
// this.body.sort[field] = direction;
|
|
109
|
-
// return this;
|
|
110
|
-
// }
|
|
111
|
-
// textSort(field: string, direction: 'asc' | 'desc') {
|
|
112
|
-
// if (!this?.body?.textSort?.length) this.body.textSort = {};
|
|
113
|
-
// this.body.textSort[field] = direction;
|
|
114
|
-
// return this;
|
|
115
|
-
// }
|
|
116
|
-
// rawOption(key: string, value: any) {
|
|
117
|
-
// (this.body as any)[key] = value;
|
|
118
|
-
// return this;
|
|
119
|
-
// }
|
|
120
|
-
// minimumRelevance(value: bodyType['minimumRelevance']) {
|
|
121
|
-
// this.body.minimumRelevance = value;
|
|
122
|
-
// return this;
|
|
123
|
-
// }
|
|
124
|
-
// page(value: bodyType['page']) {
|
|
125
|
-
// this.body.page = value;
|
|
126
|
-
// return this;
|
|
127
|
-
// }
|
|
128
|
-
// pageSize(value: bodyType['pageSize']) {
|
|
129
|
-
// this.body.pageSize = value;
|
|
130
|
-
// return this;
|
|
131
|
-
// }
|
|
132
|
-
// includeFields(fields:bodyType['includeFields']) {
|
|
133
|
-
// this.body.includeFields = fields;
|
|
134
|
-
// }
|
|
135
|
-
// excludeFields(fields:bodyType['excludeFields']) {
|
|
136
|
-
// this.body.excludeFields = fields;
|
|
137
|
-
// }
|
|
138
|
-
// includeVectors(whetherToInclude:bodyType['includeVectors']){
|
|
139
|
-
// this.body.includeVectors = whetherToInclude;
|
|
140
|
-
// }
|
|
141
|
-
// aggregate(field: string, options?: { options?: any, aggregates?: _QueryBuilder }) {
|
|
142
|
-
// this.body.fieldsToAggregate?.push({ field, ...options, fieldsToAggregate: options?.aggregates?.body.fieldsToAggregate ?? [] });
|
|
143
|
-
// return this;
|
|
144
|
-
// }
|
|
145
|
-
// aggregateStats(field: string, interval?: number) {
|
|
146
|
-
// this.body.fieldsToAggregateStats?.push({ field, interval });
|
|
147
|
-
// return this;
|
|
148
|
-
// }
|
|
149
|
-
// }
|
|
150
|
-
// export class DiscoveryClient {
|
|
151
|
-
// apiClient:DiscoveryApiClient;
|
|
152
|
-
// constructor(config?: _ClientInput) {
|
|
153
|
-
// this.apiClient = new DiscoveryApiClient(config ?? {});
|
|
154
|
-
// }
|
|
155
|
-
// dataset(name: string, options?: any) {
|
|
156
|
-
// let dataset = new Dataset(this, name, options);
|
|
157
|
-
// return dataset;
|
|
158
|
-
// }
|
|
159
|
-
// }
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a, _b;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports._GenericClient = void 0;
|
|
8
|
-
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
9
|
-
const serviceConfigs_1 = require("./serviceConfigs");
|
|
10
|
-
const envVars = {
|
|
11
|
-
project: (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.RELEVANCE_PROJECT,
|
|
12
|
-
api_key: (_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.RELEVANCE_API_KEY,
|
|
13
|
-
};
|
|
14
|
-
class _GenericClient {
|
|
15
|
-
constructor(config) {
|
|
16
|
-
this.config = config;
|
|
17
|
-
this.serviceConfig = serviceConfigs_1.serviceConfigs[config.service_name];
|
|
18
|
-
}
|
|
19
|
-
async SendRequest({ input, path, method, options }) {
|
|
20
|
-
var _a, _b, _c, _d, _e;
|
|
21
|
-
const settings = {
|
|
22
|
-
method,
|
|
23
|
-
headers: { authorization: `${(_a = this.config.project) !== null && _a !== void 0 ? _a : envVars.project}:${(_b = this.config.api_key) !== null && _b !== void 0 ? _b : envVars.api_key}` },
|
|
24
|
-
};
|
|
25
|
-
if (method.toLowerCase() !== 'get')
|
|
26
|
-
settings.body = JSON.stringify(input);
|
|
27
|
-
const final_dataset_id = (_d = (_c = options === null || options === void 0 ? void 0 : options.dataset_id) !== null && _c !== void 0 ? _c : this.config.dataset_id) !== null && _d !== void 0 ? _d : "";
|
|
28
|
-
const res = await (0, cross_fetch_1.default)(`${(_e = this.config.endpoint) !== null && _e !== void 0 ? _e : this.serviceConfig.endpoint}/latest${path.replace('{dataset_id}', final_dataset_id)}`, settings);
|
|
29
|
-
if (!res.ok)
|
|
30
|
-
throw new Error(`${path} ${method} failed with status ${res.status}: ${(await res.text())}`);
|
|
31
|
-
const body = await res.json();
|
|
32
|
-
return { body };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports._GenericClient = _GenericClient;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const openapi_typescript_1 = __importDefault(require("openapi-typescript"));
|
|
9
|
-
const serviceConfigs_1 = require("./serviceConfigs");
|
|
10
|
-
// download schema using cross-fetch
|
|
11
|
-
// convert to sdk with typescript, can supply middleware methods that will be run ???
|
|
12
|
-
function GetFlattenedSchema(schema) {
|
|
13
|
-
var _a, _b, _c;
|
|
14
|
-
if (!schema.paths)
|
|
15
|
-
throw new Error('No paths in schema ${config.schema_url}');
|
|
16
|
-
const final = [];
|
|
17
|
-
for (const [path, methods] of Object.entries(schema.paths)) {
|
|
18
|
-
for (const [method, pathData] of Object.entries(methods)) {
|
|
19
|
-
const operation = pathData; // object.entries didnt work here
|
|
20
|
-
const operationSummaryName = (_c = ((_b = (_a = operation === null || operation === void 0 ? void 0 : operation.operationId) !== null && _a !== void 0 ? _a : operation === null || operation === void 0 ? void 0 : operation.summary) !== null && _b !== void 0 ? _b : `${path}-${method}`)) === null || _c === void 0 ? void 0 : _c.replace(/[^A-Za-z0-9]/g, "");
|
|
21
|
-
final.push({ path, method, operation, operationSummaryName });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return final;
|
|
25
|
-
}
|
|
26
|
-
async function GenerateSDKFromOpenAPISchema({ config }) {
|
|
27
|
-
const openapiSchema = await (await (0, cross_fetch_1.default)(config.schema_url)).json();
|
|
28
|
-
const typescriptOutput = 'interface definitions {[id:string]:any};\n' + (await (0, openapi_typescript_1.default)(openapiSchema));
|
|
29
|
-
let sdkText = '';
|
|
30
|
-
const pipeline = [
|
|
31
|
-
() => {
|
|
32
|
-
sdkText += `import {CommandInput,_GenericClient,CommandOutput,_ClientInput,_GenericMethodOptions} from '../shared/BaseClient';
|
|
33
|
-
import {operations} from './_${config.name}SchemaTypes';
|
|
34
|
-
`;
|
|
35
|
-
},
|
|
36
|
-
() => {
|
|
37
|
-
for (const { path, method, operation, operationSummaryName } of GetFlattenedSchema(openapiSchema)) {
|
|
38
|
-
if (method.toLowerCase() !== 'get' && operation.requestBody) {
|
|
39
|
-
sdkText += `
|
|
40
|
-
export type ${operationSummaryName}Input = operations['${operation.operationId}']['requestBody']['content']['application/json']`;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
sdkText += `
|
|
44
|
-
export type ${operationSummaryName}Input = {}`;
|
|
45
|
-
}
|
|
46
|
-
sdkText += `
|
|
47
|
-
export type ${operationSummaryName}Output = operations['${operation.operationId}']['responses']['200']['content']['application/json']`;
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
() => {
|
|
51
|
-
sdkText += `
|
|
52
|
-
export class ${config.name}Client extends _GenericClient {
|
|
53
|
-
constructor(config:_ClientInput){
|
|
54
|
-
super({...config,service_name:'${config.name}'});
|
|
55
|
-
}`;
|
|
56
|
-
},
|
|
57
|
-
() => {
|
|
58
|
-
for (const { path, method, operationSummaryName } of GetFlattenedSchema(openapiSchema)) {
|
|
59
|
-
sdkText += `
|
|
60
|
-
public async ${operationSummaryName}(
|
|
61
|
-
input: CommandInput<${operationSummaryName}Input>,
|
|
62
|
-
options?: _GenericMethodOptions
|
|
63
|
-
):Promise<CommandOutput<${operationSummaryName}Output>> {
|
|
64
|
-
return this.SendRequest({
|
|
65
|
-
input,
|
|
66
|
-
method:'${method}',
|
|
67
|
-
path:'${path}',
|
|
68
|
-
options
|
|
69
|
-
});
|
|
70
|
-
}`;
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
() => {
|
|
74
|
-
sdkText += '}';
|
|
75
|
-
}
|
|
76
|
-
];
|
|
77
|
-
for (const fn of pipeline)
|
|
78
|
-
fn();
|
|
79
|
-
await fs_1.promises.writeFile(`./src/generated/${config.name}.ts`, sdkText);
|
|
80
|
-
await fs_1.promises.writeFile(`./src/generated/_${config.name}SchemaTypes.ts`, typescriptOutput);
|
|
81
|
-
}
|
|
82
|
-
async function GenerateSDKS() {
|
|
83
|
-
let indexFileContent = '';
|
|
84
|
-
for (const config of Object.values(serviceConfigs_1.serviceConfigs)) {
|
|
85
|
-
GenerateSDKFromOpenAPISchema({ config });
|
|
86
|
-
indexFileContent += `export * from "./${config.name}";\n`;
|
|
87
|
-
}
|
|
88
|
-
await fs_1.promises.writeFile(`./src/generated/index.ts`, indexFileContent);
|
|
89
|
-
}
|
|
90
|
-
GenerateSDKS();
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serviceConfigs = void 0;
|
|
4
|
-
exports.serviceConfigs = {
|
|
5
|
-
DiscoveryApi: {
|
|
6
|
-
schema_url: 'https://api.ap-southeast-2.relevance.ai/latest/openapi_schema.json',
|
|
7
|
-
endpoint: 'https://api.ap-southeast-2.relevance.ai',
|
|
8
|
-
name: 'DiscoveryApi',
|
|
9
|
-
},
|
|
10
|
-
};
|