@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.
Files changed (32) hide show
  1. package/README.md +27 -49
  2. package/package.json +3 -2
  3. package/dist-cjs/generated/DiscoveryApi.js +0 -1378
  4. package/dist-cjs/generated/_DiscoveryApiSchemaTypes.js +0 -3
  5. package/dist-cjs/generated/index.js +0 -17
  6. package/dist-cjs/index.js +0 -18
  7. package/dist-cjs/services/discovery/Dataset.js +0 -126
  8. package/dist-cjs/services/discovery/index.js +0 -159
  9. package/dist-cjs/services/index.js +0 -3
  10. package/dist-cjs/shared/BaseClient.js +0 -35
  11. package/dist-cjs/shared/generate.js +0 -90
  12. package/dist-cjs/shared/serviceConfigs.js +0 -10
  13. package/dist-es/generated/DiscoveryApi.js +0 -2123
  14. package/dist-es/generated/_DiscoveryApiSchemaTypes.js +0 -2
  15. package/dist-es/generated/index.js +0 -1
  16. package/dist-es/index.js +0 -2
  17. package/dist-es/services/discovery/Dataset.js +0 -126
  18. package/dist-es/services/discovery/index.js +0 -159
  19. package/dist-es/services/index.js +0 -3
  20. package/dist-es/shared/BaseClient.js +0 -82
  21. package/dist-es/shared/generate.js +0 -224
  22. package/dist-es/shared/serviceConfigs.js +0 -7
  23. package/dist-types/generated/DiscoveryApi.d.ts +0 -518
  24. package/dist-types/generated/_DiscoveryApiSchemaTypes.d.ts +0 -20001
  25. package/dist-types/generated/index.d.ts +0 -1
  26. package/dist-types/index.d.ts +0 -1
  27. package/dist-types/services/discovery/Dataset.d.ts +0 -0
  28. package/dist-types/services/discovery/index.d.ts +0 -0
  29. package/dist-types/services/index.d.ts +0 -0
  30. package/dist-types/shared/BaseClient.d.ts +0 -28
  31. package/dist-types/shared/generate.d.ts +0 -1
  32. package/dist-types/shared/serviceConfigs.d.ts +0 -8
@@ -1,2 +0,0 @@
1
- ;
2
- export {};
@@ -1 +0,0 @@
1
- export * from "./DiscoveryApi";
package/dist-es/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './generated';
2
- // 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,3 +0,0 @@
1
- "use strict";
2
- // Not interested in this right now
3
- // export * from './discovery';
@@ -1,82 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var _a, _b;
38
- import fetch from 'cross-fetch';
39
- import { serviceConfigs } from './serviceConfigs';
40
- var envVars = {
41
- project: (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.RELEVANCE_PROJECT,
42
- api_key: (_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.RELEVANCE_API_KEY,
43
- };
44
- var _GenericClient = /** @class */ (function () {
45
- function _GenericClient(config) {
46
- this.config = config;
47
- this.serviceConfig = serviceConfigs[config.service_name];
48
- }
49
- _GenericClient.prototype.SendRequest = function (_a) {
50
- var _b, _c, _d, _e, _f;
51
- var input = _a.input, path = _a.path, method = _a.method, options = _a.options;
52
- return __awaiter(this, void 0, void 0, function () {
53
- var settings, final_dataset_id, res, _g, _h, _j, body;
54
- return __generator(this, function (_k) {
55
- switch (_k.label) {
56
- case 0:
57
- settings = {
58
- method: method,
59
- headers: { authorization: "".concat((_b = this.config.project) !== null && _b !== void 0 ? _b : envVars.project, ":").concat((_c = this.config.api_key) !== null && _c !== void 0 ? _c : envVars.api_key) },
60
- };
61
- if (method.toLowerCase() !== 'get')
62
- settings.body = JSON.stringify(input);
63
- final_dataset_id = (_e = (_d = options === null || options === void 0 ? void 0 : options.dataset_id) !== null && _d !== void 0 ? _d : this.config.dataset_id) !== null && _e !== void 0 ? _e : "";
64
- return [4 /*yield*/, fetch("".concat((_f = this.config.endpoint) !== null && _f !== void 0 ? _f : this.serviceConfig.endpoint, "/latest").concat(path.replace('{dataset_id}', final_dataset_id)), settings)];
65
- case 1:
66
- res = _k.sent();
67
- if (!!res.ok) return [3 /*break*/, 3];
68
- _g = Error.bind;
69
- _j = (_h = "".concat(path, " ").concat(method, " failed with status ").concat(res.status, ": ")).concat;
70
- return [4 /*yield*/, res.text()];
71
- case 2: throw new (_g.apply(Error, [void 0, _j.apply(_h, [(_k.sent())])]))();
72
- case 3: return [4 /*yield*/, res.json()];
73
- case 4:
74
- body = _k.sent();
75
- return [2 /*return*/, { body: body }];
76
- }
77
- });
78
- });
79
- };
80
- return _GenericClient;
81
- }());
82
- export { _GenericClient };
@@ -1,224 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var __values = (this && this.__values) || function(o) {
38
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
- if (m) return m.call(o);
40
- if (o && typeof o.length === "number") return {
41
- next: function () {
42
- if (o && i >= o.length) o = void 0;
43
- return { value: o && o[i++], done: !o };
44
- }
45
- };
46
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
- };
48
- var __read = (this && this.__read) || function (o, n) {
49
- var m = typeof Symbol === "function" && o[Symbol.iterator];
50
- if (!m) return o;
51
- var i = m.call(o), r, ar = [], e;
52
- try {
53
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
- }
55
- catch (error) { e = { error: error }; }
56
- finally {
57
- try {
58
- if (r && !r.done && (m = i["return"])) m.call(i);
59
- }
60
- finally { if (e) throw e.error; }
61
- }
62
- return ar;
63
- };
64
- import fetch from 'cross-fetch';
65
- import { promises as fs } from 'fs';
66
- import openapiTS from 'openapi-typescript';
67
- import { serviceConfigs } from './serviceConfigs';
68
- // download schema using cross-fetch
69
- // convert to sdk with typescript, can supply middleware methods that will be run ???
70
- function GetFlattenedSchema(schema) {
71
- var e_1, _a, e_2, _b;
72
- var _c, _d, _e;
73
- if (!schema.paths)
74
- throw new Error('No paths in schema ${config.schema_url}');
75
- var final = [];
76
- try {
77
- for (var _f = __values(Object.entries(schema.paths)), _g = _f.next(); !_g.done; _g = _f.next()) {
78
- var _h = __read(_g.value, 2), path = _h[0], methods = _h[1];
79
- try {
80
- for (var _j = (e_2 = void 0, __values(Object.entries(methods))), _k = _j.next(); !_k.done; _k = _j.next()) {
81
- var _l = __read(_k.value, 2), method = _l[0], pathData = _l[1];
82
- var operation = pathData; // object.entries didnt work here
83
- var operationSummaryName = (_e = ((_d = (_c = operation === null || operation === void 0 ? void 0 : operation.operationId) !== null && _c !== void 0 ? _c : operation === null || operation === void 0 ? void 0 : operation.summary) !== null && _d !== void 0 ? _d : "".concat(path, "-").concat(method))) === null || _e === void 0 ? void 0 : _e.replace(/[^A-Za-z0-9]/g, "");
84
- final.push({ path: path, method: method, operation: operation, operationSummaryName: operationSummaryName });
85
- }
86
- }
87
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
88
- finally {
89
- try {
90
- if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
91
- }
92
- finally { if (e_2) throw e_2.error; }
93
- }
94
- }
95
- }
96
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
97
- finally {
98
- try {
99
- if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
100
- }
101
- finally { if (e_1) throw e_1.error; }
102
- }
103
- return final;
104
- }
105
- function GenerateSDKFromOpenAPISchema(_a) {
106
- var config = _a.config;
107
- return __awaiter(this, void 0, void 0, function () {
108
- var openapiSchema, typescriptOutput, _b, sdkText, pipeline, pipeline_1, pipeline_1_1, fn;
109
- var e_3, _c;
110
- return __generator(this, function (_d) {
111
- switch (_d.label) {
112
- case 0: return [4 /*yield*/, fetch(config.schema_url)];
113
- case 1: return [4 /*yield*/, (_d.sent()).json()];
114
- case 2:
115
- openapiSchema = _d.sent();
116
- _b = 'interface definitions {[id:string]:any};\n';
117
- return [4 /*yield*/, openapiTS(openapiSchema)];
118
- case 3:
119
- typescriptOutput = _b + (_d.sent());
120
- sdkText = '';
121
- pipeline = [
122
- function () {
123
- sdkText += "import {CommandInput,_GenericClient,CommandOutput,_ClientInput,_GenericMethodOptions} from '../shared/BaseClient';\n import {operations} from './_".concat(config.name, "SchemaTypes';\n");
124
- },
125
- function () {
126
- var e_4, _a;
127
- try {
128
- for (var _b = __values(GetFlattenedSchema(openapiSchema)), _c = _b.next(); !_c.done; _c = _b.next()) {
129
- var _d = _c.value, path = _d.path, method = _d.method, operation = _d.operation, operationSummaryName = _d.operationSummaryName;
130
- if (method.toLowerCase() !== 'get' && operation.requestBody) {
131
- sdkText += "\n export type ".concat(operationSummaryName, "Input = operations['").concat(operation.operationId, "']['requestBody']['content']['application/json']");
132
- }
133
- else {
134
- sdkText += "\n export type ".concat(operationSummaryName, "Input = {}");
135
- }
136
- sdkText += "\nexport type ".concat(operationSummaryName, "Output = operations['").concat(operation.operationId, "']['responses']['200']['content']['application/json']");
137
- }
138
- }
139
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
140
- finally {
141
- try {
142
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
143
- }
144
- finally { if (e_4) throw e_4.error; }
145
- }
146
- },
147
- function () {
148
- sdkText += "\nexport class ".concat(config.name, "Client extends _GenericClient {\n constructor(config:_ClientInput){\n super({...config,service_name:'").concat(config.name, "'});\n }");
149
- },
150
- function () {
151
- var e_5, _a;
152
- try {
153
- for (var _b = __values(GetFlattenedSchema(openapiSchema)), _c = _b.next(); !_c.done; _c = _b.next()) {
154
- var _d = _c.value, path = _d.path, method = _d.method, operationSummaryName = _d.operationSummaryName;
155
- sdkText += "\n public async ".concat(operationSummaryName, "(\n input: CommandInput<").concat(operationSummaryName, "Input>,\n options?: _GenericMethodOptions\n ):Promise<CommandOutput<").concat(operationSummaryName, "Output>> {\n return this.SendRequest({\n input,\n method:'").concat(method, "',\n path:'").concat(path, "',\n options\n });\n }");
156
- }
157
- }
158
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
159
- finally {
160
- try {
161
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
162
- }
163
- finally { if (e_5) throw e_5.error; }
164
- }
165
- },
166
- function () {
167
- sdkText += '}';
168
- }
169
- ];
170
- try {
171
- for (pipeline_1 = __values(pipeline), pipeline_1_1 = pipeline_1.next(); !pipeline_1_1.done; pipeline_1_1 = pipeline_1.next()) {
172
- fn = pipeline_1_1.value;
173
- fn();
174
- }
175
- }
176
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
177
- finally {
178
- try {
179
- if (pipeline_1_1 && !pipeline_1_1.done && (_c = pipeline_1.return)) _c.call(pipeline_1);
180
- }
181
- finally { if (e_3) throw e_3.error; }
182
- }
183
- return [4 /*yield*/, fs.writeFile("./src/generated/".concat(config.name, ".ts"), sdkText)];
184
- case 4:
185
- _d.sent();
186
- return [4 /*yield*/, fs.writeFile("./src/generated/_".concat(config.name, "SchemaTypes.ts"), typescriptOutput)];
187
- case 5:
188
- _d.sent();
189
- return [2 /*return*/];
190
- }
191
- });
192
- });
193
- }
194
- function GenerateSDKS() {
195
- return __awaiter(this, void 0, void 0, function () {
196
- var indexFileContent, _a, _b, config;
197
- var e_6, _c;
198
- return __generator(this, function (_d) {
199
- switch (_d.label) {
200
- case 0:
201
- indexFileContent = '';
202
- try {
203
- for (_a = __values(Object.values(serviceConfigs)), _b = _a.next(); !_b.done; _b = _a.next()) {
204
- config = _b.value;
205
- GenerateSDKFromOpenAPISchema({ config: config });
206
- indexFileContent += "export * from \"./".concat(config.name, "\";\n");
207
- }
208
- }
209
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
210
- finally {
211
- try {
212
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
213
- }
214
- finally { if (e_6) throw e_6.error; }
215
- }
216
- return [4 /*yield*/, fs.writeFile("./src/generated/index.ts", indexFileContent)];
217
- case 1:
218
- _d.sent();
219
- return [2 /*return*/];
220
- }
221
- });
222
- });
223
- }
224
- GenerateSDKS();
@@ -1,7 +0,0 @@
1
- export var serviceConfigs = {
2
- DiscoveryApi: {
3
- schema_url: 'https://api.ap-southeast-2.relevance.ai/latest/openapi_schema.json',
4
- endpoint: 'https://api.ap-southeast-2.relevance.ai',
5
- name: 'DiscoveryApi',
6
- },
7
- };