deepspace 0.3.4 → 0.3.6

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/worker.d.ts CHANGED
@@ -2845,11 +2845,13 @@ declare const COST_RATES: {
2845
2845
  * ])
2846
2846
  * ```
2847
2847
  *
2848
- * **SQL formatting requirement:** D1's `exec()` is single-line-per-statement.
2849
- * Each migration string can hold multiple statements separated by `;`, but
2850
- * every statement must fit on one line. Multi-line statements (column lists
2851
- * across newlines) fail with `D1_EXEC_ERROR: incomplete input`. If you need
2852
- * complex migrations, write each statement on its own line within the string.
2848
+ * **SQL formatting:** statements may span multiple lines freely. The runner
2849
+ * splits each migration string on `;` and runs each fragment via
2850
+ * `prepare().run()`. That sidesteps `db.exec()`'s newline-or-semicolon quirks
2851
+ * (it's optimized for migration files, not inline strings) and gets you
2852
+ * predictable single-statement semantics. Trailing `;` after the last
2853
+ * statement is fine; semicolons inside string literals are not (we use a
2854
+ * naive split, since DDL almost never has them).
2853
2855
  *
2854
2856
  * Each entry in the array is one migration. The runner records the index of
2855
2857
  * each successfully-applied migration in `_dpc_migrations`; subsequent calls
package/dist/worker.js CHANGED
@@ -6118,9 +6118,9 @@ var COST_RATES = {
6118
6118
 
6119
6119
  // src/server/utils/d1-migrations.ts
6120
6120
  var META_TABLE = "_dpc_migrations";
6121
- var META_BOOTSTRAP_SQL = `CREATE TABLE IF NOT EXISTS ${META_TABLE} (idx INTEGER PRIMARY KEY, applied_at TEXT NOT NULL);`;
6121
+ var META_BOOTSTRAP_SQL = `CREATE TABLE IF NOT EXISTS ${META_TABLE} (idx INTEGER PRIMARY KEY, applied_at TEXT NOT NULL)`;
6122
6122
  async function runMigrations(db, migrations) {
6123
- await db.exec(META_BOOTSTRAP_SQL);
6123
+ await db.prepare(META_BOOTSTRAP_SQL).run();
6124
6124
  const row = await db.prepare(`SELECT COUNT(*) AS n FROM ${META_TABLE}`).first();
6125
6125
  const fromVersion = row?.n ?? 0;
6126
6126
  if (fromVersion >= migrations.length) {
@@ -6128,18 +6128,23 @@ async function runMigrations(db, migrations) {
6128
6128
  }
6129
6129
  let current = fromVersion;
6130
6130
  for (let i = fromVersion; i < migrations.length; i++) {
6131
- const sql = migrations[i];
6132
- try {
6133
- await db.exec(sql);
6134
- } catch (err) {
6135
- const msg = err instanceof Error ? err.message : String(err);
6136
- throw new Error(`Migration ${i} failed (db at version=${current}): ${msg}`);
6131
+ const statements = splitStatements(migrations[i]);
6132
+ for (const stmt of statements) {
6133
+ try {
6134
+ await db.prepare(stmt).run();
6135
+ } catch (err) {
6136
+ const msg = err instanceof Error ? err.message : String(err);
6137
+ throw new Error(`Migration ${i} failed (db at version=${current}): ${msg}`);
6138
+ }
6137
6139
  }
6138
6140
  await db.prepare(`INSERT INTO ${META_TABLE} (idx, applied_at) VALUES (?, ?)`).bind(i, (/* @__PURE__ */ new Date()).toISOString()).run();
6139
6141
  current = i + 1;
6140
6142
  }
6141
6143
  return { fromVersion, toVersion: current, applied: current - fromVersion };
6142
6144
  }
6145
+ function splitStatements(sql) {
6146
+ return sql.split(";").map((s) => s.trim()).filter((s) => s.length > 0);
6147
+ }
6143
6148
  export {
6144
6149
  AI_CHATS_SCHEMA,
6145
6150
  AI_MESSAGES_SCHEMA,