@coherentglobal/spark-execute-sdk 0.4.10 → 0.4.11

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/browser.js CHANGED
@@ -7157,7 +7157,6 @@ var _require = require("@coherentglobal/wasm-runner"),
7157
7157
  var validate = require("./validate.js");
7158
7158
  var processModels = require("./models.js");
7159
7159
  var findModel = require("./findModels.js");
7160
- var registry = {};
7161
7160
  var Spark = /*#__PURE__*/function () {
7162
7161
  /**
7163
7162
  * @param {object} config
@@ -7166,6 +7165,11 @@ var Spark = /*#__PURE__*/function () {
7166
7165
  var _this$config$sparkEnd, _this$config, _this$config$sparkEnd2, _this$config$sparkEnd3, _this$config2, _this$config2$sparkEn, _ref, _this$config$sparkEnd4, _this$config3, _this$config3$sparkEn, _this$config4, _this$config4$sparkEn, _this$config$sparkEnd5, _this$config5, _this$config5$sparkEn, _this$config6;
7167
7166
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7168
7167
  (0, _classCallCheck2["default"])(this, Spark);
7168
+ /**
7169
+ * @private
7170
+ */
7171
+ this._registry = undefined;
7172
+
7169
7173
  /**
7170
7174
  * @private
7171
7175
  */
@@ -7327,8 +7331,8 @@ var Spark = /*#__PURE__*/function () {
7327
7331
  case 2:
7328
7332
  versionID = version_id || (input === null || input === void 0 ? void 0 : (_input$request_meta = input.request_meta) === null || _input$request_meta === void 0 ? void 0 : _input$request_meta.version_id) || (input === null || input === void 0 ? void 0 : (_input$request_meta2 = input.request_meta) === null || _input$request_meta2 === void 0 ? void 0 : _input$request_meta2.version_uuid);
7329
7333
  lookup = {
7330
- model: this.offlineModel,
7331
- onlineEndpoint: this.onlineModelEndpoint
7334
+ model: this.offlineModel.bind(this),
7335
+ onlineEndpoint: this.onlineModelEndpoint.bind(this)
7332
7336
  };
7333
7337
  _context.next = 6;
7334
7338
  return lookup[this.priority[0]](input, versionID, this);
@@ -7359,13 +7363,14 @@ var Spark = /*#__PURE__*/function () {
7359
7363
  }, {
7360
7364
  key: "offlineModel",
7361
7365
  value: function () {
7362
- var _offlineModel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(input, versionID, ds) {
7366
+ var _offlineModel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(input, versionID) {
7367
+ var _this = this;
7363
7368
  var model, modelVersionId, callback, _model2$metaData$Engi, _model2$metaData, _model2$metaData$Engi2, _model2$metaData$Engi3, _model2$metaData2, _model2$metaData2$Eng, _model2, result;
7364
7369
  return _regenerator["default"].wrap(function _callee3$(_context3) {
7365
7370
  while (1) {
7366
7371
  switch (_context3.prev = _context3.next) {
7367
7372
  case 0:
7368
- model = findModel(input.request_meta, ds.model);
7373
+ model = findModel(input.request_meta, this.model);
7369
7374
  modelVersionId = versionID || model && (model === null || model === void 0 ? void 0 : model.versionId);
7370
7375
  if (!(input !== null && input !== void 0 && input.request_meta)) {
7371
7376
  input.request_meta = {};
@@ -7374,7 +7379,7 @@ var Spark = /*#__PURE__*/function () {
7374
7379
  input.request_meta.version_id = modelVersionId;
7375
7380
  }
7376
7381
  _context3.prev = 4;
7377
- if (!(registry instanceof WasmRunner)) {
7382
+ if (this._registry === undefined) {
7378
7383
  /**
7379
7384
  * Options is the request data the the runner dispatch
7380
7385
  * receives from the wasm model
@@ -7391,12 +7396,12 @@ var Spark = /*#__PURE__*/function () {
7391
7396
  hasFolderName = options === null || options === void 0 ? void 0 : options.folder_name;
7392
7397
  hasServiceName = options === null || options === void 0 ? void 0 : options.service_name;
7393
7398
  hasVersionId = options === null || options === void 0 ? void 0 : options.version_id;
7394
- if (!(hasVersionId && !registry.isExist(hasVersionId))) {
7399
+ if (!(hasVersionId && !_this._registry.isExist(hasVersionId))) {
7395
7400
  _context2.next = 8;
7396
7401
  break;
7397
7402
  }
7398
7403
  _context2.next = 6;
7399
- return registry.append({
7404
+ return _this._registry.append({
7400
7405
  id: hasVersionId,
7401
7406
  url: model.binary,
7402
7407
  meta: {
@@ -7408,10 +7413,10 @@ var Spark = /*#__PURE__*/function () {
7408
7413
  _context2.next = 12;
7409
7414
  break;
7410
7415
  case 8:
7411
- _model = ds._getModelByMeta(hasFolderName, hasServiceName);
7416
+ _model = _this._getModelByMeta(hasFolderName, hasServiceName);
7412
7417
  hasVersionId = _model === null || _model === void 0 ? void 0 : _model.versionId;
7413
7418
  _context2.next = 12;
7414
- return registry.append({
7419
+ return _this._registry.append({
7415
7420
  id: hasVersionId,
7416
7421
  url: _model.binary,
7417
7422
  meta: {
@@ -7428,19 +7433,19 @@ var Spark = /*#__PURE__*/function () {
7428
7433
  }
7429
7434
  }, _callee2);
7430
7435
  }));
7431
- return function callback(_x6) {
7436
+ return function callback(_x5) {
7432
7437
  return _ref2.apply(this, arguments);
7433
7438
  };
7434
7439
  }();
7435
- registry = new WasmRunner("", callback);
7440
+ this._registry = new WasmRunner("", callback);
7436
7441
  }
7437
- if (registry.isExist(modelVersionId)) {
7442
+ if (this._registry.isExist(modelVersionId)) {
7438
7443
  _context3.next = 10;
7439
7444
  break;
7440
7445
  }
7441
- _model2 = findModel(input.request_meta, ds.model);
7446
+ _model2 = findModel(input.request_meta, this.model);
7442
7447
  _context3.next = 10;
7443
- return registry.append({
7448
+ return this._registry.append({
7444
7449
  id: modelVersionId,
7445
7450
  url: _model2.binary,
7446
7451
  meta: {
@@ -7450,7 +7455,7 @@ var Spark = /*#__PURE__*/function () {
7450
7455
  });
7451
7456
  case 10:
7452
7457
  _context3.next = 12;
7453
- return registry.execute(input, modelVersionId, function () {});
7458
+ return this._registry.execute(input, modelVersionId, function () {});
7454
7459
  case 12:
7455
7460
  result = _context3.sent;
7456
7461
  return _context3.abrupt("return", result);
@@ -7463,9 +7468,9 @@ var Spark = /*#__PURE__*/function () {
7463
7468
  return _context3.stop();
7464
7469
  }
7465
7470
  }
7466
- }, _callee3, null, [[4, 16]]);
7471
+ }, _callee3, this, [[4, 16]]);
7467
7472
  }));
7468
- function offlineModel(_x3, _x4, _x5) {
7473
+ function offlineModel(_x3, _x4) {
7469
7474
  return _offlineModel.apply(this, arguments);
7470
7475
  }
7471
7476
  return offlineModel;
@@ -7473,43 +7478,43 @@ var Spark = /*#__PURE__*/function () {
7473
7478
  }, {
7474
7479
  key: "onlineModelEndpoint",
7475
7480
  value: function () {
7476
- var _onlineModelEndpoint = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input, versionID, ds) {
7481
+ var _onlineModelEndpoint = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input, versionID) {
7477
7482
  var isPublic, token, header, options, modelUrl, response, result;
7478
7483
  return _regenerator["default"].wrap(function _callee4$(_context4) {
7479
7484
  while (1) {
7480
7485
  switch (_context4.prev = _context4.next) {
7481
7486
  case 0:
7482
- isPublic = ds.authType === "public";
7487
+ isPublic = this.authType === "public";
7483
7488
  token = "";
7484
7489
  if (isPublic) {
7485
7490
  _context4.next = 12;
7486
7491
  break;
7487
7492
  }
7488
- if (!(ds.token.constructor.name === "AsyncFunction")) {
7493
+ if (!(this.token.constructor.name === "AsyncFunction")) {
7489
7494
  _context4.next = 9;
7490
7495
  break;
7491
7496
  }
7492
7497
  _context4.next = 6;
7493
- return ds.token();
7498
+ return this.token();
7494
7499
  case 6:
7495
7500
  token = _context4.sent;
7496
7501
  _context4.next = 10;
7497
7502
  break;
7498
7503
  case 9:
7499
- if (typeof ds.token === "function") {
7500
- token = ds.token();
7504
+ if (typeof this.token === "function") {
7505
+ token = this.token();
7501
7506
  } else {
7502
- token = ds.token;
7507
+ token = this.token;
7503
7508
  }
7504
7509
  case 10:
7505
- if (!utils.isEmpty(ds.token)) {
7510
+ if (!utils.isEmpty(this.token)) {
7506
7511
  _context4.next = 12;
7507
7512
  break;
7508
7513
  }
7509
7514
  throw new WasmRunnerErrors.UnauthorizedError();
7510
7515
  case 12:
7511
7516
  _context4.prev = 12;
7512
- header = !isPublic ? utils.getAuthHeaders(token, ds.authType, ds.tenant) : {};
7517
+ header = !isPublic ? utils.getAuthHeaders(token, this.authType, this.tenant) : {};
7513
7518
  options = {
7514
7519
  method: "POST",
7515
7520
  body: JSON.stringify({
@@ -7520,7 +7525,7 @@ var Spark = /*#__PURE__*/function () {
7520
7525
  "content-type": "application/json"
7521
7526
  }), header)
7522
7527
  };
7523
- modelUrl = new URL("/".concat(ds.tenant, "/api/v3/").concat(!isPublic ? "execute" : "public"), ds.url);
7528
+ modelUrl = new URL("/".concat(this.tenant, "/api/v3/").concat(!isPublic ? "execute" : "public"), this.url);
7524
7529
  _context4.next = 18;
7525
7530
  return fetch(modelUrl, options);
7526
7531
  case 18:
@@ -7539,9 +7544,9 @@ var Spark = /*#__PURE__*/function () {
7539
7544
  return _context4.stop();
7540
7545
  }
7541
7546
  }
7542
- }, _callee4, null, [[12, 25]]);
7547
+ }, _callee4, this, [[12, 25]]);
7543
7548
  }));
7544
- function onlineModelEndpoint(_x7, _x8, _x9) {
7549
+ function onlineModelEndpoint(_x6, _x7) {
7545
7550
  return _onlineModelEndpoint.apply(this, arguments);
7546
7551
  }
7547
7552
  return onlineModelEndpoint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coherentglobal/spark-execute-sdk",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "",
5
5
  "main": "src/node.js",
6
6
  "browser": "dist/browser.js",
package/src/browser.js CHANGED
@@ -5,13 +5,18 @@ const validate = require("./validate.js");
5
5
  const processModels = require("./models.js");
6
6
  const findModel = require("./findModels.js");
7
7
 
8
- let registry = {};
8
+
9
9
 
10
10
  class Spark {
11
11
  /**
12
12
  * @param {object} config
13
13
  */
14
14
  constructor(config, options = {}) {
15
+ /**
16
+ * @private
17
+ */
18
+ this._registry = undefined;
19
+
15
20
  /**
16
21
  * @private
17
22
  */
@@ -143,8 +148,8 @@ class Spark {
143
148
  input?.request_meta?.version_id ||
144
149
  input?.request_meta?.version_uuid;
145
150
  let lookup = {
146
- model: this.offlineModel,
147
- onlineEndpoint: this.onlineModelEndpoint,
151
+ model: this.offlineModel.bind(this),
152
+ onlineEndpoint: this.onlineModelEndpoint.bind(this),
148
153
  };
149
154
 
150
155
  let response;
@@ -156,8 +161,8 @@ class Spark {
156
161
  return response;
157
162
  }
158
163
 
159
- async offlineModel(input, versionID, ds) {
160
- const model = findModel(input.request_meta, ds.model);
164
+ async offlineModel(input, versionID) {
165
+ const model = findModel(input.request_meta, this.model);
161
166
  const modelVersionId = versionID || (model && model?.versionId);
162
167
 
163
168
  if (!input?.request_meta) {
@@ -168,7 +173,7 @@ class Spark {
168
173
  }
169
174
 
170
175
  try {
171
- if (!(registry instanceof WasmRunner)) {
176
+ if (this._registry === undefined) {
172
177
  /**
173
178
  * Options is the request data the the runner dispatch
174
179
  * receives from the wasm model
@@ -180,8 +185,8 @@ class Spark {
180
185
  const hasServiceName = options?.service_name;
181
186
  let hasVersionId = options?.version_id;
182
187
 
183
- if (hasVersionId && !registry.isExist(hasVersionId)) {
184
- await registry.append({
188
+ if (hasVersionId && !this._registry.isExist(hasVersionId)) {
189
+ await this._registry.append({
185
190
  id: hasVersionId,
186
191
  url: model.binary,
187
192
  meta: {
@@ -192,9 +197,9 @@ class Spark {
192
197
  },
193
198
  });
194
199
  } else {
195
- const model = ds._getModelByMeta(hasFolderName, hasServiceName);
200
+ const model = this._getModelByMeta(hasFolderName, hasServiceName);
196
201
  hasVersionId = model?.versionId;
197
- await registry.append({
202
+ await this._registry.append({
198
203
  id: hasVersionId,
199
204
  url: model.binary,
200
205
  meta: {
@@ -207,13 +212,13 @@ class Spark {
207
212
  }
208
213
  return hasVersionId;
209
214
  };
210
- registry = new WasmRunner("", callback);
215
+ this._registry = new WasmRunner("", callback);
211
216
  }
212
217
 
213
- if (!registry.isExist(modelVersionId)) {
214
- const model = findModel(input.request_meta, ds.model);
218
+ if (!this._registry.isExist(modelVersionId)) {
219
+ const model = findModel(input.request_meta, this.model);
215
220
 
216
- await registry.append({
221
+ await this._registry.append({
217
222
  id: modelVersionId,
218
223
  url: model.binary,
219
224
  meta: {
@@ -222,35 +227,35 @@ class Spark {
222
227
  },
223
228
  });
224
229
  }
225
- const result = await registry.execute(input, modelVersionId, () => { });
230
+ const result = await this._registry.execute(input, modelVersionId, () => { });
226
231
  return result;
227
232
  } catch (err) {
228
233
  return err;
229
234
  }
230
235
  }
231
236
 
232
- async onlineModelEndpoint(input, versionID, ds) {
233
- const isPublic = ds.authType === "public";
237
+ async onlineModelEndpoint(input, versionID) {
238
+ const isPublic = this.authType === "public";
234
239
 
235
240
  let token = "";
236
241
 
237
242
  if (!isPublic) {
238
- if (ds.token.constructor.name === "AsyncFunction") {
239
- token = await ds.token();
240
- } else if (typeof ds.token === "function") {
241
- token = ds.token();
243
+ if (this.token.constructor.name === "AsyncFunction") {
244
+ token = await this.token();
245
+ } else if (typeof this.token === "function") {
246
+ token = this.token();
242
247
  } else {
243
- token = ds.token;
248
+ token = this.token;
244
249
  }
245
250
 
246
- if (utils.isEmpty(ds.token)) {
251
+ if (utils.isEmpty(this.token)) {
247
252
  throw new WasmRunnerErrors.UnauthorizedError();
248
253
  }
249
254
  }
250
255
 
251
256
  try {
252
257
  const header = !isPublic
253
- ? utils.getAuthHeaders(token, ds.authType, ds.tenant)
258
+ ? utils.getAuthHeaders(token, this.authType, this.tenant)
254
259
  : {};
255
260
 
256
261
  const options = {
@@ -263,8 +268,8 @@ class Spark {
263
268
  };
264
269
 
265
270
  const modelUrl = new URL(
266
- `/${ds.tenant}/api/v3/${!isPublic ? "execute" : "public"}`,
267
- ds.url
271
+ `/${this.tenant}/api/v3/${!isPublic ? "execute" : "public"}`,
272
+ this.url
268
273
  );
269
274
 
270
275
  const response = await fetch(modelUrl, options);