opencode-supertask 0.1.0 → 0.1.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/cli/index.js CHANGED
@@ -9236,6 +9236,59 @@ var init_bun_sqlite = __esm({
9236
9236
  }
9237
9237
  });
9238
9238
 
9239
+ // node_modules/drizzle-orm/migrator.js
9240
+ import crypto from "crypto";
9241
+ import fs from "fs";
9242
+ function readMigrationFiles(config) {
9243
+ const migrationFolderTo = config.migrationsFolder;
9244
+ const migrationQueries = [];
9245
+ const journalPath = `${migrationFolderTo}/meta/_journal.json`;
9246
+ if (!fs.existsSync(journalPath)) {
9247
+ throw new Error(`Can't find meta/_journal.json file`);
9248
+ }
9249
+ const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
9250
+ const journal = JSON.parse(journalAsString);
9251
+ for (const journalEntry of journal.entries) {
9252
+ const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
9253
+ try {
9254
+ const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
9255
+ const result = query.split("--> statement-breakpoint").map((it) => {
9256
+ return it;
9257
+ });
9258
+ migrationQueries.push({
9259
+ sql: result,
9260
+ bps: journalEntry.breakpoints,
9261
+ folderMillis: journalEntry.when,
9262
+ hash: crypto.createHash("sha256").update(query).digest("hex")
9263
+ });
9264
+ } catch {
9265
+ throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
9266
+ }
9267
+ }
9268
+ return migrationQueries;
9269
+ }
9270
+ var init_migrator = __esm({
9271
+ "node_modules/drizzle-orm/migrator.js"() {
9272
+ "use strict";
9273
+ }
9274
+ });
9275
+
9276
+ // node_modules/drizzle-orm/bun-sqlite/migrator.js
9277
+ var migrator_exports = {};
9278
+ __export(migrator_exports, {
9279
+ migrate: () => migrate
9280
+ });
9281
+ function migrate(db2, config) {
9282
+ const migrations = readMigrationFiles(config);
9283
+ db2.dialect.migrate(migrations, db2.session, config);
9284
+ }
9285
+ var init_migrator2 = __esm({
9286
+ "node_modules/drizzle-orm/bun-sqlite/migrator.js"() {
9287
+ "use strict";
9288
+ init_migrator();
9289
+ }
9290
+ });
9291
+
9239
9292
  // src/core/db/schema.ts
9240
9293
  var schema_exports = {};
9241
9294
  __export(schema_exports, {
@@ -9344,8 +9397,14 @@ import { Database as Database2 } from "bun:sqlite";
9344
9397
  import { existsSync, mkdirSync } from "fs";
9345
9398
  import { homedir } from "os";
9346
9399
  import { join, dirname } from "path";
9400
+ import { fileURLToPath } from "url";
9401
+ function getMigrationsFolder() {
9402
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9403
+ return join(__dirname, "../../drizzle");
9404
+ }
9347
9405
  function initDb() {
9348
9406
  const dataDir = dirname(DB_FILE_PATH);
9407
+ const dbExisted = existsSync(DB_FILE_PATH);
9349
9408
  if (!existsSync(dataDir)) {
9350
9409
  mkdirSync(dataDir, { recursive: true });
9351
9410
  }
@@ -9361,6 +9420,14 @@ function initDb() {
9361
9420
  );
9362
9421
  `);
9363
9422
  _db = drizzle(_sqlite, { schema: schema_exports });
9423
+ if (!_migrationRan) {
9424
+ _migrationRan = true;
9425
+ try {
9426
+ migrate(_db, { migrationsFolder: getMigrationsFolder() });
9427
+ } catch (err) {
9428
+ console.error("[supertask] migration failed:", err instanceof Error ? err.message : String(err));
9429
+ }
9430
+ }
9364
9431
  return _db;
9365
9432
  }
9366
9433
  function getDb() {
@@ -9378,15 +9445,17 @@ function closeDb() {
9378
9445
  _db = null;
9379
9446
  }
9380
9447
  }
9381
- var DB_FILE_PATH, _sqlite, _db, db, sqlite;
9448
+ var DB_FILE_PATH, _sqlite, _db, _migrationRan, db, sqlite;
9382
9449
  var init_db2 = __esm({
9383
9450
  "src/core/db/index.ts"() {
9384
9451
  "use strict";
9385
9452
  init_bun_sqlite();
9453
+ init_migrator2();
9386
9454
  init_schema();
9387
9455
  DB_FILE_PATH = join(homedir(), ".local/share/opencode/tasks.db");
9388
9456
  _sqlite = null;
9389
9457
  _db = null;
9458
+ _migrationRan = false;
9390
9459
  db = new Proxy({}, {
9391
9460
  get(_, prop) {
9392
9461
  const target = getDb();
@@ -19047,59 +19116,6 @@ var init_config = __esm({
19047
19116
  }
19048
19117
  });
19049
19118
 
19050
- // node_modules/drizzle-orm/migrator.js
19051
- import crypto from "crypto";
19052
- import fs from "fs";
19053
- function readMigrationFiles(config) {
19054
- const migrationFolderTo = config.migrationsFolder;
19055
- const migrationQueries = [];
19056
- const journalPath = `${migrationFolderTo}/meta/_journal.json`;
19057
- if (!fs.existsSync(journalPath)) {
19058
- throw new Error(`Can't find meta/_journal.json file`);
19059
- }
19060
- const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
19061
- const journal = JSON.parse(journalAsString);
19062
- for (const journalEntry of journal.entries) {
19063
- const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
19064
- try {
19065
- const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
19066
- const result = query.split("--> statement-breakpoint").map((it) => {
19067
- return it;
19068
- });
19069
- migrationQueries.push({
19070
- sql: result,
19071
- bps: journalEntry.breakpoints,
19072
- folderMillis: journalEntry.when,
19073
- hash: crypto.createHash("sha256").update(query).digest("hex")
19074
- });
19075
- } catch {
19076
- throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
19077
- }
19078
- }
19079
- return migrationQueries;
19080
- }
19081
- var init_migrator = __esm({
19082
- "node_modules/drizzle-orm/migrator.js"() {
19083
- "use strict";
19084
- }
19085
- });
19086
-
19087
- // node_modules/drizzle-orm/bun-sqlite/migrator.js
19088
- var migrator_exports = {};
19089
- __export(migrator_exports, {
19090
- migrate: () => migrate
19091
- });
19092
- function migrate(db2, config) {
19093
- const migrations = readMigrationFiles(config);
19094
- db2.dialect.migrate(migrations, db2.session, config);
19095
- }
19096
- var init_migrator2 = __esm({
19097
- "node_modules/drizzle-orm/bun-sqlite/migrator.js"() {
19098
- "use strict";
19099
- init_migrator();
19100
- }
19101
- });
19102
-
19103
19119
  // src/core/services/task-run.service.ts
19104
19120
  var taskRuns2, TaskRunService;
19105
19121
  var init_task_run_service = __esm({
@@ -22939,8 +22955,8 @@ program2.command("init").description("Initialize SuperTask (create config + run
22939
22955
  const { getDb: getDb2 } = await Promise.resolve().then(() => (init_db2(), db_exports));
22940
22956
  const { migrate: migrate2 } = await Promise.resolve().then(() => (init_migrator2(), migrator_exports));
22941
22957
  const { join: pJoin, dirname: pDirname } = await import("path");
22942
- const { fileURLToPath } = await import("url");
22943
- const __dirname = pDirname(fileURLToPath(import.meta.url));
22958
+ const { fileURLToPath: fileURLToPath2 } = await import("url");
22959
+ const __dirname = pDirname(fileURLToPath2(import.meta.url));
22944
22960
  migrate2(getDb2(), { migrationsFolder: pJoin(__dirname, "../../drizzle") });
22945
22961
  console.log(JSON.stringify({ migrated: true }));
22946
22962
  }));
@@ -22948,8 +22964,8 @@ program2.command("migrate").description("Run database migrations").action(async
22948
22964
  const { getDb: getDb2 } = await Promise.resolve().then(() => (init_db2(), db_exports));
22949
22965
  const { migrate: migrate2 } = await Promise.resolve().then(() => (init_migrator2(), migrator_exports));
22950
22966
  const { join: join3, dirname: dirname3 } = await import("path");
22951
- const { fileURLToPath } = await import("url");
22952
- const __dirname = dirname3(fileURLToPath(import.meta.url));
22967
+ const { fileURLToPath: fileURLToPath2 } = await import("url");
22968
+ const __dirname = dirname3(fileURLToPath2(import.meta.url));
22953
22969
  migrate2(getDb2(), { migrationsFolder: join3(__dirname, "../../drizzle") });
22954
22970
  console.log(JSON.stringify({ migrated: true }));
22955
22971
  }));