@mastra/libsql 1.17.0-alpha.1 → 1.17.0-alpha.4

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,64 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 1.17.0-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix factory storage error classification and schema drift handling. ([#20002](https://github.com/mastra-ai/mastra/pull/20002))
8
+
9
+ - `isUniqueViolation` in the LibSQL factory storage now only matches real unique-index violations (`SQLITE_CONSTRAINT_UNIQUE` / `SQLITE_CONSTRAINT_PRIMARYKEY`). Previously any `SQLITE_CONSTRAINT` failure — including NOT NULL violations — was reported as a "Unique constraint violation", which masked the real error (seen as `Unique constraint violation on collection 'factory_rule_evaluations'` when polled ingestion inserted nullable columns into a stale table).
10
+ - `ensureCollections` in both the LibSQL and Postgres factory storage adapters now relaxes stale NOT NULL constraints when a column becomes nullable in the schema. Postgres uses `ALTER COLUMN ... DROP NOT NULL`; LibSQL rebuilds the table in place since SQLite cannot drop NOT NULL directly. Existing rows and unique indexes are preserved.
11
+
12
+ - Updated dependencies:
13
+ - @mastra/core@1.52.0-alpha.13
14
+
15
+ ## 1.17.0-alpha.3
16
+
17
+ ### Minor Changes
18
+
19
+ - Added configurable local journal modes while preserving WAL as the default. ([#19901](https://github.com/mastra-ai/mastra/pull/19901))
20
+
21
+ ```ts
22
+ const storage = new LibSQLStore({
23
+ id: 'local-storage',
24
+ url: 'file:./mastra.db',
25
+ journalMode: 'delete',
26
+ });
27
+ ```
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [[`c7d30cd`](https://github.com/mastra-ai/mastra/commit/c7d30cd86009c407df91105591f03cd6e3d2854d), [`ef03fbc`](https://github.com/mastra-ai/mastra/commit/ef03fbcc556bcbc04c9b3d06fab88771ecaa043c), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`4e68363`](https://github.com/mastra-ai/mastra/commit/4e683634f94ebd062d26a3bb6093a8dfc7263d37), [`9251370`](https://github.com/mastra-ai/mastra/commit/9251370ad413af464aa22d7566338bec5613e8de)]:
32
+ - @mastra/core@1.52.0-alpha.11
33
+
34
+ ## 1.17.0-alpha.2
35
+
36
+ ### Patch Changes
37
+
38
+ - Replaced GitHub-specific Mastra Code session state with Factory project and linked-repository identities. This lets SDK consumers represent sessions independently of a source-control provider and select a repository explicitly when sandbox execution is required. ([#19849](https://github.com/mastra-ai/mastra/pull/19849))
39
+
40
+ Updated Mastra Code onboarding to be Factory-first: create a Factory by name, then link repositories from your connected source-control installations in a separate step. A Factory is valid with zero linked repositories, and the Board, Metrics, and Audit pages stay available for any server-backed Factory. Factory pages keep project-scoped data separate from repository-scoped intake and provide a repository selector when a Factory has multiple linked repositories. Creating a Factory from a local folder remains available as a secondary option.
41
+
42
+ **Before**
43
+
44
+ ```ts
45
+ const state = { githubProjectId: 'project-1', sandboxId, sandboxWorkdir };
46
+ ```
47
+
48
+ **After**
49
+
50
+ ```ts
51
+ const state = {
52
+ factoryProjectId: 'factory-project-1',
53
+ projectRepositoryId: 'project-repository-1',
54
+ sandboxId,
55
+ sandboxWorkdir,
56
+ };
57
+ ```
58
+
59
+ - Updated dependencies [[`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9)]:
60
+ - @mastra/core@1.52.0-alpha.10
61
+
3
62
  ## 1.17.0-alpha.1
4
63
 
5
64
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-libsql
3
3
  description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/libsql"
6
- version: "1.17.0-alpha.1"
6
+ version: "1.17.0-alpha.4"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.17.0-alpha.1",
2
+ "version": "1.17.0-alpha.4",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -88,6 +88,8 @@ Start Mastra's development server:
88
88
  npx mastra dev
89
89
  ```
90
90
 
91
+ For Agent Builder development, you can also use `mastra factory dev`, which uses the same dev runtime and flags as `mastra dev` and writes to the same `.mastra/output` directory. Both commands share a dev lock and can't run simultaneously in the same project. See the [CLI reference](https://mastra.ai/reference/cli/mastra) for details.
92
+
91
93
  The Agent Builder is mounted at `http://localhost:4111/agent-builder`.
92
94
 
93
95
  ## Disabling the Builder
package/dist/index.cjs CHANGED
@@ -13365,8 +13365,10 @@ function assertIdentifier(kind, name) {
13365
13365
  }
13366
13366
  }
13367
13367
  function isUniqueViolation(error) {
13368
+ const code = typeof error === "object" && error !== null ? error.code : void 0;
13369
+ if (code === "SQLITE_CONSTRAINT_UNIQUE" || code === "SQLITE_CONSTRAINT_PRIMARYKEY") return true;
13368
13370
  const message = error instanceof Error ? error.message : String(error);
13369
- return message.includes("UNIQUE constraint failed") || message.includes("SQLITE_CONSTRAINT");
13371
+ return message.includes("UNIQUE constraint failed") || message.includes("SQLITE_CONSTRAINT_UNIQUE") || message.includes("SQLITE_CONSTRAINT_PRIMARYKEY");
13370
13372
  }
13371
13373
  function primaryKeyOf(schema) {
13372
13374
  const pks = Object.entries(schema.columns).filter(([, spec]) => spec.type === "uuid-pk" || spec.primaryKey);
@@ -13676,6 +13678,20 @@ var LibSQLFactoryStorage = class extends storage.FactoryStorage {
13676
13678
  async initStorage() {
13677
13679
  await this.#client.execute("SELECT 1");
13678
13680
  }
13681
+ async withTransaction(fn) {
13682
+ if (this.#config.url.includes(":memory:")) return fn(this.ops);
13683
+ const transaction = await this.#client.transaction("write");
13684
+ try {
13685
+ const result = await fn(new LibSQLFactoryStorageOps(transaction, this.#schemas));
13686
+ await transaction.commit();
13687
+ return result;
13688
+ } catch (error) {
13689
+ await transaction.rollback();
13690
+ throw error;
13691
+ } finally {
13692
+ transaction.close();
13693
+ }
13694
+ }
13679
13695
  async ensureCollections(schemas) {
13680
13696
  for (const schema of schemas) {
13681
13697
  await this.#ensureCollection(schema);
@@ -13696,6 +13712,35 @@ var LibSQLFactoryStorage = class extends storage.FactoryStorage {
13696
13712
  if (spec.default !== void 0) ddl += ` DEFAULT ${serializeDefault(spec.default)}`;
13697
13713
  return ddl;
13698
13714
  }
13715
+ /**
13716
+ * A table created by an older schema may still say NOT NULL on a column the
13717
+ * current schema declares nullable — inserts of null then fail on databases
13718
+ * that predate the change. SQLite has no `ALTER COLUMN DROP NOT NULL`, so
13719
+ * relaxation swaps in a table rebuilt from the current schema (create shadow
13720
+ * → copy → drop → rename) atomically.
13721
+ */
13722
+ async #relaxDriftedNotNulls(schema) {
13723
+ const info = await this.#client.execute(`PRAGMA table_info("${schema.name}")`);
13724
+ const hasDrift = info.rows.some((row) => {
13725
+ const spec = schema.columns[String(row.name)];
13726
+ if (!spec || spec.type === "uuid-pk" || spec.primaryKey) return false;
13727
+ return spec.nullable === true && Number(row.notnull) === 1;
13728
+ });
13729
+ if (!hasDrift) return;
13730
+ const ddl = Object.entries(schema.columns).map(([name, spec]) => this.#columnDdl(name, spec));
13731
+ const shadow = `${schema.name}__nullable_rebuild`;
13732
+ const cols = Object.keys(schema.columns).map((name) => `"${name}"`).join(", ");
13733
+ await this.#client.batch(
13734
+ [
13735
+ `DROP TABLE IF EXISTS "${shadow}"`,
13736
+ `CREATE TABLE "${shadow}" (${ddl.join(", ")})`,
13737
+ `INSERT INTO "${shadow}" (${cols}) SELECT ${cols} FROM "${schema.name}"`,
13738
+ `DROP TABLE "${schema.name}"`,
13739
+ `ALTER TABLE "${shadow}" RENAME TO "${schema.name}"`
13740
+ ],
13741
+ "write"
13742
+ );
13743
+ }
13699
13744
  async #ensureCollection(schema) {
13700
13745
  assertIdentifier("collection", schema.name);
13701
13746
  primaryKeyOf(schema);
@@ -13707,6 +13752,7 @@ var LibSQLFactoryStorage = class extends storage.FactoryStorage {
13707
13752
  if (existing.has(name)) continue;
13708
13753
  await this.#client.execute(`ALTER TABLE "${schema.name}" ADD COLUMN ${this.#columnDdl(name, spec)}`);
13709
13754
  }
13755
+ await this.#relaxDriftedNotNulls(schema);
13710
13756
  for (const index of schema.uniqueIndexes ?? []) {
13711
13757
  assertIdentifier("index", index.name);
13712
13758
  index.columns.forEach((column) => assertIdentifier("column", column));