@mastra/libsql 1.10.1-alpha.0 → 1.10.1-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/dist/index.js CHANGED
@@ -1170,6 +1170,33 @@ var LibSQLVector = class extends MastraVector {
1170
1170
  });
1171
1171
  }
1172
1172
  };
1173
+ var safeStringify = (value) => {
1174
+ const seen = /* @__PURE__ */ new WeakSet();
1175
+ const sanitize = (val) => {
1176
+ if (val === null || val === void 0) return val;
1177
+ if (typeof val === "function") return void 0;
1178
+ if (typeof val === "symbol") return void 0;
1179
+ if (typeof val === "bigint") return val.toString();
1180
+ if (typeof val !== "object") return val;
1181
+ if (seen.has(val)) return void 0;
1182
+ seen.add(val);
1183
+ if (typeof val.toJSON === "function") {
1184
+ return sanitize(val.toJSON());
1185
+ }
1186
+ if (Array.isArray(val)) {
1187
+ return val.map((item) => sanitize(item));
1188
+ }
1189
+ const result = {};
1190
+ for (const key of Object.keys(val)) {
1191
+ const sanitized = sanitize(val[key]);
1192
+ if (sanitized !== void 0) {
1193
+ result[key] = sanitized;
1194
+ }
1195
+ }
1196
+ return result;
1197
+ };
1198
+ return JSON.stringify(sanitize(value)) ?? "null";
1199
+ };
1173
1200
  function buildSelectColumns(tableName) {
1174
1201
  const schema = TABLE_SCHEMAS[tableName];
1175
1202
  return Object.keys(schema).map((col) => {
@@ -1236,12 +1263,12 @@ function prepareStatement({ tableName, record }) {
1236
1263
  }
1237
1264
  const colDef = schema[col];
1238
1265
  if (colDef?.type === "jsonb") {
1239
- return JSON.stringify(v);
1266
+ return safeStringify(v);
1240
1267
  }
1241
1268
  if (v instanceof Date) {
1242
1269
  return v.toISOString();
1243
1270
  }
1244
- return typeof v === "object" ? JSON.stringify(v) : v;
1271
+ return typeof v === "object" ? safeStringify(v) : v;
1245
1272
  });
1246
1273
  const placeholders = columnNames.map((col) => {
1247
1274
  const colDef = schema[col];
@@ -1284,12 +1311,12 @@ function transformToSqlValue(value, forceJsonStringify = false) {
1284
1311
  return null;
1285
1312
  }
1286
1313
  if (forceJsonStringify) {
1287
- return JSON.stringify(value);
1314
+ return safeStringify(value);
1288
1315
  }
1289
1316
  if (value instanceof Date) {
1290
1317
  return value.toISOString();
1291
1318
  }
1292
- return typeof value === "object" ? JSON.stringify(value) : value;
1319
+ return typeof value === "object" ? safeStringify(value) : value;
1293
1320
  }
1294
1321
  function prepareDeleteStatement({ tableName, keys }) {
1295
1322
  const parsedTableName = parseSqlIdentifier(tableName, "table name");
@@ -10605,7 +10632,7 @@ var WorkflowsLibSQL = class extends WorkflowsStorage {
10605
10632
  VALUES (?, ?, jsonb(?), ?, ?)
10606
10633
  ON CONFLICT(workflow_name, run_id)
10607
10634
  DO UPDATE SET snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
10608
- args: [workflowName, runId, JSON.stringify(snapshot), now, now]
10635
+ args: [workflowName, runId, safeStringify(snapshot), now, now]
10609
10636
  });
10610
10637
  await tx.commit();
10611
10638
  return snapshot.context;
@@ -10642,7 +10669,7 @@ var WorkflowsLibSQL = class extends WorkflowsStorage {
10642
10669
  const updatedSnapshot = { ...snapshot, ...opts };
10643
10670
  await tx.execute({
10644
10671
  sql: `UPDATE ${TABLE_WORKFLOW_SNAPSHOT} SET snapshot = jsonb(?) WHERE workflow_name = ? AND run_id = ?`,
10645
- args: [JSON.stringify(updatedSnapshot), workflowName, runId]
10672
+ args: [safeStringify(updatedSnapshot), workflowName, runId]
10646
10673
  });
10647
10674
  await tx.commit();
10648
10675
  return updatedSnapshot;