@mastra/libsql 1.21.1 → 1.22.0-alpha.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/dist/docs/SKILL.md +1 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-deployment-workers.md +2 -2
  5. package/dist/docs/references/docs-storage.md +2 -0
  6. package/dist/docs/references/integrations-databases-libsql.md +16 -0
  7. package/dist/docs/references/reference-core-mastra-class.md +1 -1
  8. package/dist/index.cjs +31 -10
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +31 -10
  11. package/dist/index.js.map +1 -1
  12. package/dist/storage/db/client.d.ts +31 -0
  13. package/dist/storage/db/client.d.ts.map +1 -0
  14. package/dist/storage/db/index.d.ts +1 -1
  15. package/dist/storage/db/index.d.ts.map +1 -1
  16. package/dist/storage/db/utils.d.ts +1 -1
  17. package/dist/storage/db/utils.d.ts.map +1 -1
  18. package/dist/storage/db/write-lock.d.ts +2 -2
  19. package/dist/storage/db/write-lock.d.ts.map +1 -1
  20. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  21. package/dist/storage/domains/background-tasks/index.d.ts +3 -1
  22. package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
  23. package/dist/storage/domains/blobs/index.d.ts.map +1 -1
  24. package/dist/storage/domains/channels/index.d.ts.map +1 -1
  25. package/dist/storage/domains/datasets/index.d.ts.map +1 -1
  26. package/dist/storage/domains/experiments/index.d.ts.map +1 -1
  27. package/dist/storage/domains/favorites/index.d.ts.map +1 -1
  28. package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
  29. package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
  30. package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -1
  31. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  32. package/dist/storage/domains/notifications/index.d.ts.map +1 -1
  33. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
  34. package/dist/storage/domains/schedules/index.d.ts.map +1 -1
  35. package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
  36. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  37. package/dist/storage/domains/skills/index.d.ts.map +1 -1
  38. package/dist/storage/domains/thread-state/index.d.ts.map +1 -1
  39. package/dist/storage/domains/tool-provider-connections/index.d.ts.map +1 -1
  40. package/dist/storage/domains/utils.d.ts +1 -1
  41. package/dist/storage/domains/utils.d.ts.map +1 -1
  42. package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -1
  43. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  44. package/dist/storage/domains/workspaces/index.d.ts.map +1 -1
  45. package/dist/storage/factory-storage.d.ts.map +1 -1
  46. package/dist/storage/index.d.ts +12 -1
  47. package/dist/storage/index.d.ts.map +1 -1
  48. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2966,7 +2966,7 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksS
2966
2966
  }
2967
2967
  });
2968
2968
  }
2969
- async updateTask(taskId, update) {
2969
+ async updateTask(taskId, update, options) {
2970
2970
  const setClauses = [];
2971
2971
  const params = [];
2972
2972
  if ("status" in update) {
@@ -3001,12 +3001,17 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends BackgroundTasksS
3001
3001
  setClauses.push("completedAt = ?");
3002
3002
  params.push(update.completedAt?.toISOString() ?? null);
3003
3003
  }
3004
- if (setClauses.length === 0) return;
3004
+ if (setClauses.length === 0) return false;
3005
3005
  params.push(taskId);
3006
- await this.#client.execute({
3007
- sql: `UPDATE ${TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE id = ?`,
3006
+ let where = "id = ?";
3007
+ if (options?.expectedStatus) {
3008
+ where += " AND status = ?";
3009
+ params.push(options.expectedStatus);
3010
+ }
3011
+ return (await this.#client.execute({
3012
+ sql: `UPDATE ${TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE ${where}`,
3008
3013
  args: params
3009
- });
3014
+ })).rowsAffected > 0;
3010
3015
  }
3011
3016
  async getTask(taskId) {
3012
3017
  const row = (await this.#client.execute({
@@ -4616,6 +4621,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4616
4621
  "tags",
4617
4622
  "comment",
4618
4623
  "toolMockReport",
4624
+ "metadata",
4619
4625
  "organizationId",
4620
4626
  "projectId",
4621
4627
  "attempt"
@@ -4762,6 +4768,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4762
4768
  input: safelyParseJSON(row.input),
4763
4769
  output: row.output ? safelyParseJSON(row.output) : null,
4764
4770
  groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : null,
4771
+ metadata: row.metadata ? safelyParseJSON(row.metadata) : null,
4765
4772
  error: row.error ? safelyParseJSON(row.error) : null,
4766
4773
  startedAt: ensureDate(row.startedAt),
4767
4774
  completedAt: ensureDate(row.completedAt),
@@ -5064,6 +5071,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
5064
5071
  input: input.input,
5065
5072
  output: input.output,
5066
5073
  groundTruth: input.groundTruth,
5074
+ metadata: input.metadata ?? null,
5067
5075
  error: input.error ?? null,
5068
5076
  startedAt: input.startedAt.toISOString(),
5069
5077
  completedAt: input.completedAt.toISOString(),
@@ -5086,6 +5094,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
5086
5094
  input: input.input,
5087
5095
  output: input.output,
5088
5096
  groundTruth: input.groundTruth,
5097
+ metadata: input.metadata ?? null,
5089
5098
  error: input.error,
5090
5099
  startedAt: input.startedAt,
5091
5100
  completedAt: input.completedAt,
@@ -5140,7 +5149,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
5140
5149
  await this.#client.execute({
5141
5150
  sql: `UPDATE ${TABLE_EXPERIMENT_RESULTS} SET
5142
5151
  "itemDatasetVersion" = ?, "organizationId" = ?, "projectId" = ?,
5143
- "input" = ?, "output" = ?, "groundTruth" = ?, "error" = ?,
5152
+ "input" = ?, "output" = ?, "groundTruth" = ?, "metadata" = ?, "error" = ?,
5144
5153
  "startedAt" = ?, "completedAt" = ?, "retryCount" = ?, "attempt" = ?,
5145
5154
  "traceId" = ?, "status" = ?, "tags" = ?, "toolMockReport" = ?
5146
5155
  WHERE "id" = ?`,
@@ -5151,6 +5160,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
5151
5160
  JSON.stringify(input.input),
5152
5161
  input.output != null ? JSON.stringify(input.output) : null,
5153
5162
  input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
5163
+ input.metadata != null ? JSON.stringify(input.metadata) : null,
5154
5164
  input.error != null ? JSON.stringify(input.error) : null,
5155
5165
  input.startedAt.toISOString(),
5156
5166
  input.completedAt.toISOString(),
@@ -13054,7 +13064,7 @@ var WorkflowsLibSQL = class WorkflowsLibSQL extends WorkflowsStorage {
13054
13064
  sql: `INSERT INTO ${TABLE_WORKFLOW_SNAPSHOT} (workflow_name, run_id, resourceId, snapshot, createdAt, updatedAt)
13055
13065
  VALUES (?, ?, ?, jsonb(?), ?, ?)
13056
13066
  ON CONFLICT(workflow_name, run_id)
13057
- DO UPDATE SET resourceId = excluded.resourceId, snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
13067
+ DO UPDATE SET resourceId = COALESCE(excluded.resourceId, ${TABLE_WORKFLOW_SNAPSHOT}.resourceId), snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
13058
13068
  args: [
13059
13069
  workflowName,
13060
13070
  runId,
@@ -13854,6 +13864,15 @@ var LibSQLFactoryStorageOps = class {
13854
13864
  async findMany(collection, where, opts) {
13855
13865
  return this.#select(collection, where, opts);
13856
13866
  }
13867
+ async count(collection, where) {
13868
+ const schema = this.#schema(collection);
13869
+ const filter = this.#buildWhere(schema, where);
13870
+ const result = await this.#client.execute({
13871
+ sql: `SELECT COUNT(*) AS count FROM "${schema.name}" WHERE ${filter.sql}`,
13872
+ args: filter.args
13873
+ });
13874
+ return Number(result.rows[0]?.count ?? 0);
13875
+ }
13857
13876
  async #insertOne(collection, row) {
13858
13877
  const schema = this.#schema(collection);
13859
13878
  const pk = primaryKeyOf(schema);
@@ -14003,7 +14022,7 @@ var LibSQLFactoryStorage = class extends FactoryStorage {
14003
14022
  });
14004
14023
  }
14005
14024
  async close() {
14006
- this.#client.close();
14025
+ await this.#client.close();
14007
14026
  }
14008
14027
  authDatabase() {
14009
14028
  return {
@@ -14123,10 +14142,12 @@ var LibSQLStore = class extends MastraCompositeStore {
14123
14142
  };
14124
14143
  if ("url" in config) {
14125
14144
  if (config.url.includes(":memory:")) this.shouldCacheInit = false;
14126
- this.isLocalDb = config.url.startsWith("file:") || config.url.includes(":memory:");
14145
+ this.isLocalDb = (config.url.startsWith("file:") || config.url.includes(":memory:")) && !config.syncUrl;
14127
14146
  this.client = createClient({
14128
14147
  url: config.url,
14129
14148
  ...config.authToken ? { authToken: config.authToken } : {},
14149
+ ...config.syncUrl ? { syncUrl: config.syncUrl } : {},
14150
+ ...config.syncInterval !== void 0 ? { syncInterval: config.syncInterval } : {},
14130
14151
  ...this.isLocalDb ? { timeout: this.connectionTimeoutMs } : {}
14131
14152
  });
14132
14153
  this.pragmasReady = this.isLocalDb ? this.applyLocalPragmas() : Promise.resolve();
@@ -14250,7 +14271,7 @@ var LibSQLStore = class extends MastraCompositeStore {
14250
14271
  * Safe to call more than once; subsequent calls are no-ops.
14251
14272
  */
14252
14273
  async close() {
14253
- if (!this.client.closed) this.client.close();
14274
+ if (!this.client.closed) await this.client.close();
14254
14275
  }
14255
14276
  };
14256
14277
  //#endregion