@mastra/core 0.1.2 → 0.1.3

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/core.esm.js CHANGED
@@ -1357,7 +1357,7 @@ var DataLayer = /*#__PURE__*/function () {
1357
1357
  }
1358
1358
  uniqueRecords = Array.from(uniqueRecordsMap.values());
1359
1359
  externalIds = uniqueRecords.map(function (record) {
1360
- return record.externalId;
1360
+ return String(record.externalId);
1361
1361
  });
1362
1362
  _context16.next = 9;
1363
1363
  return this.db.record.findMany({
@@ -1379,7 +1379,7 @@ var DataLayer = /*#__PURE__*/function () {
1379
1379
  toUpdate = [];
1380
1380
  uniqueRecords.forEach(function (record) {
1381
1381
  var existing = existingRecords.find(function (existingRecord) {
1382
- return existingRecord.externalId === record.externalId;
1382
+ return existingRecord.externalId === String(record.externalId);
1383
1383
  });
1384
1384
  if (existing) {
1385
1385
  toUpdate.push(_extends({}, record, {
@@ -1387,6 +1387,7 @@ var DataLayer = /*#__PURE__*/function () {
1387
1387
  }));
1388
1388
  } else {
1389
1389
  toCreate.push(_extends({}, record, {
1390
+ externalId: String(record.externalId),
1390
1391
  entityId: entityId
1391
1392
  }));
1392
1393
  }
@@ -1394,6 +1395,7 @@ var DataLayer = /*#__PURE__*/function () {
1394
1395
  createPromise = toCreate.length ? this.db.record.createMany({
1395
1396
  data: toCreate.map(function (record) {
1396
1397
  return _extends({}, record, {
1398
+ externalId: String(record.externalId),
1397
1399
  data: record.data
1398
1400
  });
1399
1401
  })
@@ -3206,19 +3208,6 @@ function allowedKey(key) {
3206
3208
  }
3207
3209
  return false;
3208
3210
  }
3209
- function transformKey(input) {
3210
- // Use a regular expression to match 'get', followed by any characters and then the first uppercase letter
3211
- return input.replace(/^(get|Get)([A-Z][a-z]*)/, function (_, __, firstPart) {
3212
- // Convert the first meaningful part to lowercase
3213
- return firstPart.toLowerCase();
3214
- }).replace(/^([a-z]+)([A-Z].*)?$/, function (_, firstPart) {
3215
- // Return the first part in lowercase
3216
- return firstPart.toLowerCase();
3217
- }).replace(/^([a-z]+)([A-Z].*)?$/, function (_, firstPart) {
3218
- // Return the first part in lowercase
3219
- return firstPart.toLowerCase();
3220
- });
3221
- }
3222
3211
  function extractPlural(input) {
3223
3212
  // Use a regular expression to match the pattern
3224
3213
  var regex = /^get([A-Z][a-z]*(?:[A-Z][a-z]*)*)(?:([A-Z][a-z]+))?$/;
@@ -3256,7 +3245,8 @@ function getEntityKey(key) {
3256
3245
  }
3257
3246
  return removeDuplicateWord(pluralS.toLowerCase());
3258
3247
  }
3259
- return transformKey(key);
3248
+ return key;
3249
+ // return transformKey(key);
3260
3250
  }
3261
3251
  function generateSyncs(_ref4) {
3262
3252
  var client = _ref4.client,
@@ -3291,7 +3281,7 @@ function generateSyncs(_ref4) {
3291
3281
  event: eventKey,
3292
3282
  executor: function () {
3293
3283
  var _executor = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
3294
- var event, connectionId, options, api, result, resultData, records;
3284
+ var event, connectionId, options, api, result, resultData, fallbackIDKey, records;
3295
3285
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3296
3286
  while (1) switch (_context.prev = _context.next) {
3297
3287
  case 0:
@@ -3316,14 +3306,17 @@ function generateSyncs(_ref4) {
3316
3306
  result = _context.sent;
3317
3307
  // First see if we are getting the list data
3318
3308
  resultData = (result == null ? void 0 : result[listDataKey]) || [result];
3309
+ fallbackIDKey = Object.keys(resultData[0]).find(function (k) {
3310
+ return k.includes('id');
3311
+ }) || 'id';
3319
3312
  records = resultData == null ? void 0 : resultData.map(function (d) {
3320
3313
  return {
3321
- externalId: d[idKey],
3314
+ externalId: d[idKey] || d[fallbackIDKey],
3322
3315
  data: d,
3323
3316
  entityType: entityKey.toUpperCase()
3324
3317
  };
3325
3318
  });
3326
- _context.next = 14;
3319
+ _context.next = 15;
3327
3320
  return dataLayer == null ? void 0 : dataLayer.syncData({
3328
3321
  name: name,
3329
3322
  connectionId: connectionId,
@@ -3332,7 +3325,7 @@ function generateSyncs(_ref4) {
3332
3325
  type: entityKey.toUpperCase(),
3333
3326
  lastSyncId: event == null ? void 0 : event.id
3334
3327
  });
3335
- case 14:
3328
+ case 15:
3336
3329
  case "end":
3337
3330
  return _context.stop();
3338
3331
  }
@@ -3347,7 +3340,9 @@ function generateSyncs(_ref4) {
3347
3340
  };
3348
3341
  events[name + "." + entityKey + "/sync"] = {
3349
3342
  schema: inputSchema,
3350
- handler: handler
3343
+ handler: handler,
3344
+ fields: properties,
3345
+ entityType: entityKey
3351
3346
  };
3352
3347
  }
3353
3348
  });
@@ -4631,17 +4626,17 @@ var Framework = /*#__PURE__*/function () {
4631
4626
  }();
4632
4627
  _proto.subscribeEvent = /*#__PURE__*/function () {
4633
4628
  var _subscribeEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref19) {
4634
- var _process$env$INNGEST_;
4629
+ var _this$config$runner$u, _this$config$runner, _ref20, _this$config$runner$s, _this$config$runner2;
4635
4630
  var id, _ref19$interval, interval, _ref19$timeout, timeout, inngestApiUrl, inngestApiToken, startTime, _poll;
4636
4631
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
4637
4632
  while (1) switch (_context8.prev = _context8.next) {
4638
4633
  case 0:
4639
4634
  id = _ref19.id, _ref19$interval = _ref19.interval, interval = _ref19$interval === void 0 ? 5000 : _ref19$interval, _ref19$timeout = _ref19.timeout, timeout = _ref19$timeout === void 0 ? 60000 : _ref19$timeout;
4640
- inngestApiUrl = process.env.INNGEST_URL;
4641
- inngestApiToken = (_process$env$INNGEST_ = process.env.INNGEST_SIGNING_KEY) != null ? _process$env$INNGEST_ : '123';
4635
+ inngestApiUrl = (_this$config$runner$u = (_this$config$runner = this.config.runner) == null ? void 0 : _this$config$runner.uri) != null ? _this$config$runner$u : process.env.INNGEST_URL;
4636
+ inngestApiToken = (_ref20 = (_this$config$runner$s = (_this$config$runner2 = this.config.runner) == null ? void 0 : _this$config$runner2.signingKey) != null ? _this$config$runner$s : process.env.INNGEST_SIGNING_KEY) != null ? _ref20 : '123';
4642
4637
  startTime = Date.now();
4643
4638
  _poll = /*#__PURE__*/function () {
4644
- var _ref20 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
4639
+ var _ref21 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
4645
4640
  var response, _yield$response$json, data, error, lastRun, elapsedTime;
4646
4641
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
4647
4642
  while (1) switch (_context7.prev = _context7.next) {
@@ -4715,7 +4710,7 @@ var Framework = /*#__PURE__*/function () {
4715
4710
  }, _callee7, null, [[0, 18]]);
4716
4711
  }));
4717
4712
  return function poll() {
4718
- return _ref20.apply(this, arguments);
4713
+ return _ref21.apply(this, arguments);
4719
4714
  };
4720
4715
  }();
4721
4716
  return _context8.abrupt("return", _poll());
@@ -4723,7 +4718,7 @@ var Framework = /*#__PURE__*/function () {
4723
4718
  case "end":
4724
4719
  return _context8.stop();
4725
4720
  }
4726
- }, _callee8);
4721
+ }, _callee8, this);
4727
4722
  }));
4728
4723
  function subscribeEvent(_x7) {
4729
4724
  return _subscribeEvent.apply(this, arguments);
@@ -4731,13 +4726,13 @@ var Framework = /*#__PURE__*/function () {
4731
4726
  return subscribeEvent;
4732
4727
  }();
4733
4728
  _proto.triggerEvent = /*#__PURE__*/function () {
4734
- var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref21) {
4729
+ var _triggerEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref22) {
4735
4730
  var _this3 = this;
4736
- var key, data, user, _ref21$integrationNam, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
4731
+ var key, data, user, _ref22$integrationNam, integrationName, returnObj, integrationEvents, integrationEvent, event, workflowEvent;
4737
4732
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
4738
4733
  while (1) switch (_context11.prev = _context11.next) {
4739
4734
  case 0:
4740
- key = _ref21.key, data = _ref21.data, user = _ref21.user, _ref21$integrationNam = _ref21.integrationName, integrationName = _ref21$integrationNam === void 0 ? this.config.name : _ref21$integrationNam;
4735
+ key = _ref22.key, data = _ref22.data, user = _ref22.user, _ref22$integrationNam = _ref22.integrationName, integrationName = _ref22$integrationNam === void 0 ? this.config.name : _ref22$integrationNam;
4741
4736
  _context11.prev = 1;
4742
4737
  returnObj = {
4743
4738
  event: {}
@@ -4768,11 +4763,11 @@ var Framework = /*#__PURE__*/function () {
4768
4763
  subscribe: function () {
4769
4764
  var _subscribe = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_temp) {
4770
4765
  var _event$ids;
4771
- var _ref22, interval, timeout;
4766
+ var _ref23, interval, timeout;
4772
4767
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
4773
4768
  while (1) switch (_context9.prev = _context9.next) {
4774
4769
  case 0:
4775
- _ref22 = _temp === void 0 ? {} : _temp, interval = _ref22.interval, timeout = _ref22.timeout;
4770
+ _ref23 = _temp === void 0 ? {} : _temp, interval = _ref23.interval, timeout = _ref23.timeout;
4776
4771
  return _context9.abrupt("return", _this3.subscribeEvent({
4777
4772
  id: (_event$ids = event.ids) == null ? void 0 : _event$ids[0],
4778
4773
  interval: interval,
@@ -4805,11 +4800,11 @@ var Framework = /*#__PURE__*/function () {
4805
4800
  subscribe: function () {
4806
4801
  var _subscribe2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(_temp2) {
4807
4802
  var _workflowEvent$ids;
4808
- var _ref23, interval, timeout;
4803
+ var _ref24, interval, timeout;
4809
4804
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
4810
4805
  while (1) switch (_context10.prev = _context10.next) {
4811
4806
  case 0:
4812
- _ref23 = _temp2 === void 0 ? {} : _temp2, interval = _ref23.interval, timeout = _ref23.timeout;
4807
+ _ref24 = _temp2 === void 0 ? {} : _temp2, interval = _ref24.interval, timeout = _ref24.timeout;
4813
4808
  return _context10.abrupt("return", _this3.subscribeEvent({
4814
4809
  id: (_workflowEvent$ids = workflowEvent.ids) == null ? void 0 : _workflowEvent$ids[0],
4815
4810
  interval: interval,
@@ -4847,12 +4842,12 @@ var Framework = /*#__PURE__*/function () {
4847
4842
  _proto.triggerSystemEvent =
4848
4843
  /*#__PURE__*/
4849
4844
  function () {
4850
- var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref24) {
4845
+ var _triggerSystemEvent = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref25) {
4851
4846
  var key, data, user, event, systemEvent;
4852
4847
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
4853
4848
  while (1) switch (_context12.prev = _context12.next) {
4854
4849
  case 0:
4855
- key = _ref24.key, data = _ref24.data, user = _ref24.user;
4850
+ key = _ref25.key, data = _ref25.data, user = _ref25.user;
4856
4851
  _context12.next = 3;
4857
4852
  return client.send({
4858
4853
  name: key,
@@ -4890,10 +4885,10 @@ var Framework = /*#__PURE__*/function () {
4890
4885
  }();
4891
4886
  _proto.createRouter = function createRouter() {
4892
4887
  var self = this;
4893
- var makeWebhookUrl = function makeWebhookUrl(_ref25) {
4888
+ var makeWebhookUrl = function makeWebhookUrl(_ref26) {
4894
4889
  var _self$config;
4895
- var event = _ref25.event,
4896
- name = _ref25.name;
4890
+ var event = _ref26.event,
4891
+ name = _ref26.name;
4897
4892
  return encodeURI("" + (self == null || (_self$config = self.config) == null ? void 0 : _self$config.systemHostURL) + self.routes.webhook + "?name=" + name + "&event=" + event);
4898
4893
  };
4899
4894
  var makeRedirectURI = function makeRedirectURI() {
@@ -4933,10 +4928,10 @@ var Framework = /*#__PURE__*/function () {
4933
4928
  inngest: '/inngest',
4934
4929
  webhook: '/webhook'
4935
4930
  };
4936
- return Object.entries(registry).reduce(function (acc, _ref26) {
4931
+ return Object.entries(registry).reduce(function (acc, _ref27) {
4937
4932
  var _extends3;
4938
- var key = _ref26[0],
4939
- value = _ref26[1];
4933
+ var key = _ref27[0],
4934
+ value = _ref27[1];
4940
4935
  return _extends({}, acc, (_extends3 = {}, _extends3[key] = "" + _this4.config.routeRegistrationPath + value, _extends3));
4941
4936
  }, {});
4942
4937
  }