@relevanceai/sdk 2.0.0 → 2.0.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/dist-cjs/generated/VecDBApi.js +1682 -0
- package/dist-cjs/generated/_VecDBApiSchemaTypes.js +3 -0
- package/dist-cjs/generated/index.js +17 -0
- package/dist-cjs/index.js +18 -0
- package/dist-cjs/services/discovery/Dataset.js +126 -0
- package/dist-cjs/services/discovery/index.js +159 -0
- package/dist-cjs/services/index.js +18 -0
- package/dist-cjs/services/vecdb/Dataset.js +137 -0
- package/dist-cjs/services/vecdb/index.js +137 -0
- package/dist-cjs/shared/BaseClient.js +35 -0
- package/dist-cjs/shared/generate.js +90 -0
- package/dist-cjs/shared/serviceConfigs.js +10 -0
- package/dist-es/generated/VecDBApi.js +2579 -0
- package/dist-es/generated/_VecDBApiSchemaTypes.js +2 -0
- package/dist-es/generated/index.js +1 -0
- package/dist-es/index.js +2 -0
- package/dist-es/services/discovery/Dataset.js +126 -0
- package/dist-es/services/discovery/index.js +159 -0
- package/dist-es/services/index.js +2 -0
- package/dist-es/services/vecdb/Dataset.js +356 -0
- package/dist-es/services/vecdb/index.js +184 -0
- package/dist-es/shared/BaseClient.js +82 -0
- package/dist-es/shared/generate.js +224 -0
- package/dist-es/shared/serviceConfigs.js +7 -0
- package/dist-types/generated/VecDBApi.d.ts +632 -0
- package/dist-types/generated/_VecDBApiSchemaTypes.d.ts +22299 -0
- package/dist-types/generated/index.d.ts +1 -0
- package/dist-types/index.d.ts +2 -0
- 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 +1 -0
- package/dist-types/services/vecdb/Dataset.d.ts +52 -0
- package/dist-types/services/vecdb/index.d.ts +44 -0
- package/dist-types/shared/BaseClient.d.ts +28 -0
- package/dist-types/shared/generate.d.ts +1 -0
- package/dist-types/shared/serviceConfigs.d.ts +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
var __values = (this && this.__values) || function(o) {
|
|
28
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
+
if (m) return m.call(o);
|
|
30
|
+
if (o && typeof o.length === "number") return {
|
|
31
|
+
next: function () {
|
|
32
|
+
if (o && i >= o.length) o = void 0;
|
|
33
|
+
return { value: o && o[i++], done: !o };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
+
};
|
|
38
|
+
import { VecDBApiClient } from '../../';
|
|
39
|
+
import { Dataset } from './Dataset';
|
|
40
|
+
export function QueryBuilder() {
|
|
41
|
+
return new _QueryBuilder();
|
|
42
|
+
}
|
|
43
|
+
export function FilterBuilder() {
|
|
44
|
+
return new _FilterBuilder();
|
|
45
|
+
}
|
|
46
|
+
var _FilterBuilder = /** @class */ (function () {
|
|
47
|
+
function _FilterBuilder() {
|
|
48
|
+
this.body = { filters: [], fieldsToAggregate: [], fieldsToAggregateStats: [] };
|
|
49
|
+
}
|
|
50
|
+
_FilterBuilder.prototype.buildFilters = function () {
|
|
51
|
+
return this.body.filters;
|
|
52
|
+
};
|
|
53
|
+
_FilterBuilder.prototype.rawFilter = function (filter) {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push(filter);
|
|
56
|
+
return this;
|
|
57
|
+
};
|
|
58
|
+
_FilterBuilder.prototype.filter = function (type, key, value) {
|
|
59
|
+
var _a;
|
|
60
|
+
var _b;
|
|
61
|
+
var options = [];
|
|
62
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
63
|
+
options[_i - 3] = arguments[_i];
|
|
64
|
+
}
|
|
65
|
+
(_b = this.body.filters) === null || _b === void 0 ? void 0 : _b.push((_a = {},
|
|
66
|
+
_a[type] = __assign({ key: key, value: value }, options),
|
|
67
|
+
_a));
|
|
68
|
+
return this;
|
|
69
|
+
};
|
|
70
|
+
_FilterBuilder.prototype.match = function (field, value) {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ match: { field: field, value: value } });
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
75
|
+
_FilterBuilder.prototype.wildcard = function (field, value) {
|
|
76
|
+
var _a;
|
|
77
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ wildcard: { field: field, value: value } });
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
_FilterBuilder.prototype.range = function (field, options) {
|
|
81
|
+
var _a;
|
|
82
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ range: __assign({ field: field }, options) });
|
|
83
|
+
return this;
|
|
84
|
+
};
|
|
85
|
+
_FilterBuilder.prototype.or = function (filters) {
|
|
86
|
+
var _a;
|
|
87
|
+
(_a = this.body.filters) === null || _a === void 0 ? void 0 : _a.push({ or: filters.map(function (f) { var _a; return (_a = f.body.filters) !== null && _a !== void 0 ? _a : []; }) });
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
return _FilterBuilder;
|
|
91
|
+
}());
|
|
92
|
+
export { _FilterBuilder };
|
|
93
|
+
var _QueryBuilder = /** @class */ (function (_super) {
|
|
94
|
+
__extends(_QueryBuilder, _super);
|
|
95
|
+
function _QueryBuilder() {
|
|
96
|
+
var _this = _super.call(this) || this;
|
|
97
|
+
_this.shouldPerformTextQuery = false;
|
|
98
|
+
return _this;
|
|
99
|
+
}
|
|
100
|
+
_QueryBuilder.prototype.build = function () {
|
|
101
|
+
if (!this.shouldPerformTextQuery)
|
|
102
|
+
return this.body;
|
|
103
|
+
if (!this.defaultQueryValue)
|
|
104
|
+
throw new Error("Please set the search query by calling .query('my search query') before performing a text search.");
|
|
105
|
+
this.body.query = this.defaultQueryValue;
|
|
106
|
+
return this.body;
|
|
107
|
+
};
|
|
108
|
+
_QueryBuilder.prototype.vector = function (field) {
|
|
109
|
+
var e_1, _a;
|
|
110
|
+
var args = [];
|
|
111
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
112
|
+
args[_i - 1] = arguments[_i];
|
|
113
|
+
}
|
|
114
|
+
if (!Array.isArray(this.body.vectorSearchQuery))
|
|
115
|
+
this.body.vectorSearchQuery = [];
|
|
116
|
+
var payload = { field: field }; // TODO components['schemas']['simpleSearchAndFlatFilterItem']['search']['vectorSearchQuery']
|
|
117
|
+
var inferredModelMatch = field.match(/_(.*)_.*vector_/); // title_text@1-0_vector_ -> text@1-0
|
|
118
|
+
if (inferredModelMatch && inferredModelMatch[1])
|
|
119
|
+
payload.model = inferredModelMatch[1]; // this can be overridden
|
|
120
|
+
try {
|
|
121
|
+
for (var args_1 = __values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
|
|
122
|
+
var arg = args_1_1.value;
|
|
123
|
+
if (typeof arg === 'number')
|
|
124
|
+
payload.weight = arg; // weight
|
|
125
|
+
else
|
|
126
|
+
payload = __assign(__assign({}, payload), arg); // options
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
130
|
+
finally {
|
|
131
|
+
try {
|
|
132
|
+
if (args_1_1 && !args_1_1.done && (_a = args_1.return)) _a.call(args_1);
|
|
133
|
+
}
|
|
134
|
+
finally { if (e_1) throw e_1.error; }
|
|
135
|
+
}
|
|
136
|
+
this.body.vectorSearchQuery.push(payload);
|
|
137
|
+
return this;
|
|
138
|
+
};
|
|
139
|
+
_QueryBuilder.prototype.sort = function (field, direction) {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.body) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b.length))
|
|
142
|
+
this.body.sort = {};
|
|
143
|
+
this.body.sort[field] = direction;
|
|
144
|
+
return this;
|
|
145
|
+
};
|
|
146
|
+
_QueryBuilder.prototype.rawOption = function (key, value) {
|
|
147
|
+
this.body[key] = value;
|
|
148
|
+
return this;
|
|
149
|
+
};
|
|
150
|
+
_QueryBuilder.prototype.minimumRelevance = function (value) {
|
|
151
|
+
this.body.minimumRelevance = value;
|
|
152
|
+
return this;
|
|
153
|
+
};
|
|
154
|
+
_QueryBuilder.prototype.page = function (value) {
|
|
155
|
+
this.body.page = value;
|
|
156
|
+
return this;
|
|
157
|
+
};
|
|
158
|
+
_QueryBuilder.prototype.pageSize = function (value) {
|
|
159
|
+
this.body.pageSize = value;
|
|
160
|
+
return this;
|
|
161
|
+
};
|
|
162
|
+
_QueryBuilder.prototype.includeFields = function (fields) {
|
|
163
|
+
this.body.includeFields = fields;
|
|
164
|
+
return this;
|
|
165
|
+
};
|
|
166
|
+
_QueryBuilder.prototype.ask = function (query, field, options) {
|
|
167
|
+
var _a;
|
|
168
|
+
this.body.instantAnswerQuery = __assign(__assign({ query: query, field: field, preset: (_a = options.preset) !== null && _a !== void 0 ? _a : 'support3' }, (options.titleReferenceField ? { titleReferenceField: options.titleReferenceField } : {})), (options.urlReferenceField ? { urlReferenceField: options.urlReferenceField } : {}));
|
|
169
|
+
return this;
|
|
170
|
+
};
|
|
171
|
+
return _QueryBuilder;
|
|
172
|
+
}(_FilterBuilder));
|
|
173
|
+
export { _QueryBuilder };
|
|
174
|
+
var VecDBClient = /** @class */ (function () {
|
|
175
|
+
function VecDBClient(config) {
|
|
176
|
+
this.apiClient = new VecDBApiClient(config !== null && config !== void 0 ? config : {});
|
|
177
|
+
}
|
|
178
|
+
VecDBClient.prototype.dataset = function (name, options) {
|
|
179
|
+
var dataset = new Dataset(this, name, options);
|
|
180
|
+
return dataset;
|
|
181
|
+
};
|
|
182
|
+
return VecDBClient;
|
|
183
|
+
}());
|
|
184
|
+
export { VecDBClient };
|
|
@@ -0,0 +1,82 @@
|
|
|
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 };
|
|
@@ -0,0 +1,224 @@
|
|
|
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();
|