@mastra/mssql 0.3.6 → 0.4.0-alpha.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @mastra/mssql
2
2
 
3
+ ## 0.4.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 376913a: Update peerdeps of @mastra/core
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [8fbf79e]
12
+ - @mastra/core@0.16.0-alpha.1
13
+
14
+ ## 0.3.7-alpha.0
15
+
16
+ ### Patch Changes
17
+
18
+ - 6f5eb7a: Throw if an empty or whitespace-only threadId is passed when getting messages
19
+ - Updated dependencies [fd83526]
20
+ - Updated dependencies [d0b90ab]
21
+ - Updated dependencies [6f5eb7a]
22
+ - Updated dependencies [a01cf14]
23
+ - Updated dependencies [a9e50ee]
24
+ - Updated dependencies [5397eb4]
25
+ - Updated dependencies [c9f4e4a]
26
+ - Updated dependencies [0acbc80]
27
+ - @mastra/core@0.16.0-alpha.0
28
+
3
29
  ## 0.3.6
4
30
 
5
31
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -467,6 +467,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
467
467
  selectBy,
468
468
  orderByStatement
469
469
  }) {
470
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
470
471
  const include = selectBy?.include;
471
472
  if (!include) return null;
472
473
  const unionQueries = [];
@@ -538,11 +539,12 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
538
539
  return dedupedRows;
539
540
  }
540
541
  async getMessages(args) {
541
- const { threadId, format, selectBy } = args;
542
+ const { threadId, resourceId, format, selectBy } = args;
542
543
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
543
544
  const orderByStatement = `ORDER BY [seq_id] DESC`;
544
545
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
545
546
  try {
547
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
546
548
  let rows = [];
547
549
  const include = selectBy?.include || [];
548
550
  if (include?.length) {
@@ -580,7 +582,8 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
580
582
  domain: error.ErrorDomain.STORAGE,
581
583
  category: error.ErrorCategory.THIRD_PARTY,
582
584
  details: {
583
- threadId
585
+ threadId,
586
+ resourceId: resourceId ?? ""
584
587
  }
585
588
  },
586
589
  error$1
@@ -631,29 +634,24 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
631
634
  }
632
635
  }
633
636
  async getMessagesPaginated(args) {
634
- const { threadId, selectBy } = args;
635
- const { page = 0, perPage: perPageInput } = selectBy?.pagination || {};
636
- const orderByStatement = `ORDER BY [seq_id] DESC`;
637
- if (selectBy?.include?.length) {
638
- await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
639
- }
637
+ const { threadId, resourceId, format, selectBy } = args;
638
+ const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
640
639
  try {
641
- const { threadId: threadId2, format, selectBy: selectBy2 } = args;
642
- const { page: page2 = 0, perPage: perPageInput2, dateRange } = selectBy2?.pagination || {};
640
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
643
641
  const fromDate = dateRange?.start;
644
642
  const toDate = dateRange?.end;
645
643
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
646
- const orderByStatement2 = `ORDER BY [seq_id] DESC`;
647
- let messages2 = [];
648
- if (selectBy2?.include?.length) {
649
- const includeMessages = await this._getIncludedMessages({ threadId: threadId2, selectBy: selectBy2, orderByStatement: orderByStatement2 });
650
- if (includeMessages) messages2.push(...includeMessages);
644
+ const orderByStatement = `ORDER BY [seq_id] DESC`;
645
+ let messages = [];
646
+ if (selectBy?.include?.length) {
647
+ const includeMessages = await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
648
+ if (includeMessages) messages.push(...includeMessages);
651
649
  }
652
- const perPage = perPageInput2 !== void 0 ? perPageInput2 : storage.resolveMessageLimit({ last: selectBy2?.last, defaultLimit: 40 });
653
- const currentOffset = page2 * perPage;
650
+ const perPage = perPageInput !== void 0 ? perPageInput : storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
651
+ const currentOffset = page * perPage;
654
652
  const conditions = ["[thread_id] = @threadId"];
655
653
  const request = this.pool.request();
656
- request.input("threadId", threadId2);
654
+ request.input("threadId", threadId);
657
655
  if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
658
656
  conditions.push("[createdAt] >= @fromDate");
659
657
  request.input("fromDate", fromDate.toISOString());
@@ -666,35 +664,35 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
666
664
  const countQuery = `SELECT COUNT(*) as total FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${whereClause}`;
667
665
  const countResult = await request.query(countQuery);
668
666
  const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
669
- if (total === 0 && messages2.length > 0) {
670
- const parsedIncluded = this._parseAndFormatMessages(messages2, format);
667
+ if (total === 0 && messages.length > 0) {
668
+ const parsedIncluded = this._parseAndFormatMessages(messages, format);
671
669
  return {
672
670
  messages: parsedIncluded,
673
671
  total: parsedIncluded.length,
674
- page: page2,
672
+ page,
675
673
  perPage,
676
674
  hasMore: false
677
675
  };
678
676
  }
679
- const excludeIds = messages2.map((m) => m.id);
677
+ const excludeIds = messages.map((m) => m.id);
680
678
  if (excludeIds.length > 0) {
681
679
  const excludeParams = excludeIds.map((_, idx) => `@id${idx}`);
682
680
  conditions.push(`id NOT IN (${excludeParams.join(", ")})`);
683
681
  excludeIds.forEach((id, idx) => request.input(`id${idx}`, id));
684
682
  }
685
683
  const finalWhereClause = `WHERE ${conditions.join(" AND ")}`;
686
- const dataQuery = `${selectStatement} FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${finalWhereClause} ${orderByStatement2} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
684
+ const dataQuery = `${selectStatement} FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${finalWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
687
685
  request.input("offset", currentOffset);
688
686
  request.input("limit", perPage);
689
687
  const rowsResult = await request.query(dataQuery);
690
688
  const rows = rowsResult.recordset || [];
691
689
  rows.sort((a, b) => a.seq_id - b.seq_id);
692
- messages2.push(...rows);
693
- const parsed = this._parseAndFormatMessages(messages2, format);
690
+ messages.push(...rows);
691
+ const parsed = this._parseAndFormatMessages(messages, format);
694
692
  return {
695
693
  messages: parsed,
696
694
  total: total + excludeIds.length,
697
- page: page2,
695
+ page,
698
696
  perPage,
699
697
  hasMore: currentOffset + rows.length < total
700
698
  };
@@ -706,6 +704,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
706
704
  category: error.ErrorCategory.THIRD_PARTY,
707
705
  details: {
708
706
  threadId,
707
+ resourceId: resourceId ?? "",
709
708
  page
710
709
  }
711
710
  },