@fileverse/api 0.0.2 → 0.0.3

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
@@ -75,9 +75,6 @@ function getRuntimeConfig() {
75
75
  get DB_PATH() {
76
76
  return process.env.DB_PATH;
77
77
  },
78
- get DATABASE_URL() {
79
- return process.env.DATABASE_URL;
80
- },
81
78
  get PORT() {
82
79
  return process.env.PORT || STATIC_CONFIG.DEFAULT_PORT;
83
80
  },
@@ -124,9 +121,6 @@ var init_config = __esm({
124
121
  get DB_PATH() {
125
122
  return process.env.DB_PATH;
126
123
  },
127
- get DATABASE_URL() {
128
- return process.env.DATABASE_URL;
129
- },
130
124
  get PORT() {
131
125
  return process.env.PORT || STATIC_CONFIG.DEFAULT_PORT;
132
126
  },
@@ -388,11 +382,11 @@ var init_publish = __esm({
388
382
  });
389
383
 
390
384
  // src/domain/portal/saveApiKey.ts
391
- async function addApiKey(input) {
385
+ function addApiKey(input) {
392
386
  if (!input.apiKeySeed || !input.name || !input.collaboratorAddress || !input.portalAddress) {
393
387
  throw new Error("apiKeySeed, name, collaboratorAddress, and portalAddress are required");
394
388
  }
395
- const portal = await PortalsModel.findByPortalAddress(input.portalAddress);
389
+ const portal = PortalsModel.findByPortalAddress(input.portalAddress);
396
390
  if (!portal) {
397
391
  throw new Error(`Portal with address ${input.portalAddress} does not exist`);
398
392
  }
@@ -528,251 +522,51 @@ var init_infra = __esm({
528
522
  }
529
523
  });
530
524
 
531
- // src/infra/database/adapters/sqlite-adapter.ts
525
+ // src/infra/database/connection.ts
532
526
  import Database from "better-sqlite3";
533
- var SqliteAdapter;
534
- var init_sqlite_adapter = __esm({
535
- "src/infra/database/adapters/sqlite-adapter.ts"() {
527
+ var DatabaseConnectionManager, databaseConnectionManager;
528
+ var init_connection = __esm({
529
+ "src/infra/database/connection.ts"() {
536
530
  "use strict";
537
531
  init_esm_shims();
538
- init_infra();
539
532
  init_config();
540
- SqliteAdapter = class {
541
- db;
542
- constructor(dbPath) {
543
- this.db = new Database(dbPath, {
544
- verbose: config.NODE_ENV === "development" ? (msg) => logger.debug(String(msg)) : void 0
545
- });
546
- this.db.pragma("journal_mode = WAL");
547
- this.db.pragma("foreign_keys = ON");
548
- this.db.prepare("SELECT 1").get();
549
- logger.info(`SQLite database connected: ${dbPath}`);
550
- }
551
- async select(sql, params = []) {
552
- const stmt = this.db.prepare(sql);
553
- return stmt.all(params);
554
- }
555
- async selectOne(sql, params = []) {
556
- const stmt = this.db.prepare(sql);
557
- return stmt.get(params);
558
- }
559
- async execute(sql, params = []) {
560
- const stmt = this.db.prepare(sql);
561
- const result = stmt.run(params);
562
- return {
563
- changes: result.changes,
564
- lastInsertRowid: result.lastInsertRowid
565
- };
566
- }
567
- async transaction(callback) {
568
- this.db.exec("SAVEPOINT txn");
569
- try {
570
- const result = await callback(this);
571
- this.db.exec("RELEASE txn");
572
- return result;
573
- } catch (err) {
574
- this.db.exec("ROLLBACK TO txn");
575
- throw err;
576
- }
577
- }
578
- async exec(sql) {
579
- this.db.exec(sql);
580
- }
581
- async close() {
582
- this.db.close();
583
- logger.info("Database connection closed");
584
- }
585
- };
586
- }
587
- });
588
-
589
- // src/infra/database/adapters/pg-adapter.ts
590
- import pg from "pg";
591
- function translateParams(sql) {
592
- let idx = 0;
593
- return sql.replace(/\?/g, () => `$${++idx}`);
594
- }
595
- function mapRow(row) {
596
- const mapped = {};
597
- for (const [key, value] of Object.entries(row)) {
598
- const mappedKey = COLUMN_NAME_MAP[key] ?? key;
599
- mapped[mappedKey] = value instanceof Date ? value.toISOString() : value;
600
- }
601
- return mapped;
602
- }
603
- var Pool, COLUMN_NAME_MAP, PgClientAdapter, PgAdapter;
604
- var init_pg_adapter = __esm({
605
- "src/infra/database/adapters/pg-adapter.ts"() {
606
- "use strict";
607
- init_esm_shims();
608
533
  init_infra();
609
- ({ Pool } = pg);
610
- COLUMN_NAME_MAP = {
611
- ddocid: "ddocId",
612
- localversion: "localVersion",
613
- onchainversion: "onchainVersion",
614
- syncstatus: "syncStatus",
615
- isdeleted: "isDeleted",
616
- onchainfileid: "onChainFileId",
617
- portaladdress: "portalAddress",
618
- createdat: "createdAt",
619
- updatedat: "updatedAt",
620
- linkkey: "linkKey",
621
- linkkeynonce: "linkKeyNonce",
622
- commentkey: "commentKey",
623
- portalseed: "portalSeed",
624
- owneraddress: "ownerAddress",
625
- apikeyseed: "apiKeySeed",
626
- collaboratoraddress: "collaboratorAddress",
627
- fileid: "fileId",
628
- retrycount: "retryCount",
629
- lasterror: "lastError",
630
- lockedat: "lockedAt",
631
- nextretryat: "nextRetryAt",
632
- userophash: "userOpHash",
633
- pendingpayload: "pendingPayload",
634
- folderid: "folderId",
635
- folderref: "folderRef",
636
- foldername: "folderName",
637
- metadataipfshash: "metadataIPFSHash",
638
- contentipfshash: "contentIPFSHash",
639
- lasttransactionhash: "lastTransactionHash",
640
- lasttransactionblocknumber: "lastTransactionBlockNumber",
641
- lasttransactionblocktimestamp: "lastTransactionBlockTimestamp",
642
- created_at: "created_at",
643
- updated_at: "updated_at"
644
- };
645
- PgClientAdapter = class {
646
- constructor(client) {
647
- this.client = client;
534
+ DatabaseConnectionManager = class _DatabaseConnectionManager {
535
+ static instance;
536
+ db = null;
537
+ constructor() {
648
538
  }
649
- async select(sql, params = []) {
650
- const result = await this.client.query(translateParams(sql), params);
651
- return result.rows.map((row) => mapRow(row));
652
- }
653
- async selectOne(sql, params = []) {
654
- const result = await this.client.query(translateParams(sql), params);
655
- return result.rows[0] ? mapRow(result.rows[0]) : void 0;
656
- }
657
- async execute(sql, params = []) {
658
- const result = await this.client.query(translateParams(sql), params);
659
- return { changes: result.rowCount ?? 0, lastInsertRowid: 0 };
660
- }
661
- async transaction(callback) {
662
- await this.client.query("SAVEPOINT nested_txn");
663
- try {
664
- const result = await callback(this);
665
- await this.client.query("RELEASE SAVEPOINT nested_txn");
666
- return result;
667
- } catch (err) {
668
- await this.client.query("ROLLBACK TO SAVEPOINT nested_txn");
669
- throw err;
539
+ static getInstance() {
540
+ if (!_DatabaseConnectionManager.instance) {
541
+ _DatabaseConnectionManager.instance = new _DatabaseConnectionManager();
670
542
  }
543
+ return _DatabaseConnectionManager.instance;
671
544
  }
672
- async exec(sql) {
673
- await this.client.query(sql);
545
+ getConnection() {
546
+ if (!this.db) {
547
+ const dbPath = config.DB_PATH;
548
+ this.db = new Database(dbPath, {
549
+ verbose: config.NODE_ENV === "development" ? (msg) => logger.debug(String(msg)) : void 0
550
+ });
551
+ this.db.pragma("journal_mode = WAL");
552
+ this.db.pragma("foreign_keys = ON");
553
+ this.db.prepare("SELECT 1").get();
554
+ logger.info(`SQLite database connected: ${dbPath}`);
555
+ }
556
+ return this.db;
674
557
  }
675
558
  async close() {
676
- }
677
- };
678
- PgAdapter = class {
679
- pool;
680
- constructor(connectionString) {
681
- const url = new URL(connectionString);
682
- const isLocal = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1";
683
- const sslDisabled = connectionString.includes("sslmode=disable");
684
- const needsSsl = !isLocal && !sslDisabled;
685
- this.pool = new Pool({
686
- connectionString,
687
- // pg requires password to be a string; local trust/peer auth uses empty string
688
- password: url.password || "",
689
- max: 20,
690
- idleTimeoutMillis: 3e4,
691
- ssl: needsSsl ? { rejectUnauthorized: false } : void 0
692
- });
693
- logger.info(`PostgreSQL pool created (ssl: ${needsSsl ? "on" : "off"})`);
694
- }
695
- async select(sql, params = []) {
696
- const result = await this.pool.query(translateParams(sql), params);
697
- return result.rows.map((row) => mapRow(row));
698
- }
699
- async selectOne(sql, params = []) {
700
- const result = await this.pool.query(translateParams(sql), params);
701
- return result.rows[0] ? mapRow(result.rows[0]) : void 0;
702
- }
703
- async execute(sql, params = []) {
704
- const result = await this.pool.query(translateParams(sql), params);
705
- return { changes: result.rowCount ?? 0, lastInsertRowid: 0 };
706
- }
707
- async transaction(callback) {
708
- const client = await this.pool.connect();
709
- try {
710
- await client.query("BEGIN");
711
- const clientAdapter = new PgClientAdapter(client);
712
- const result = await callback(clientAdapter);
713
- await client.query("COMMIT");
714
- return result;
715
- } catch (err) {
716
- await client.query("ROLLBACK");
717
- throw err;
718
- } finally {
719
- client.release();
559
+ if (this.db) {
560
+ this.db.close();
561
+ this.db = null;
562
+ logger.info("Database connection closed");
720
563
  }
721
564
  }
722
- async exec(sql) {
723
- await this.pool.query(sql);
724
- }
725
- async close() {
726
- await this.pool.end();
727
- logger.info("PostgreSQL pool closed");
565
+ isConnected() {
566
+ return this.db !== null && this.db.open;
728
567
  }
729
568
  };
730
- }
731
- });
732
-
733
- // src/infra/database/connection.ts
734
- var connection_exports = {};
735
- __export(connection_exports, {
736
- closeAdapter: () => closeAdapter,
737
- getAdapter: () => getAdapter,
738
- getAdapterSync: () => getAdapterSync
739
- });
740
- async function getAdapter() {
741
- if (adapter) return adapter;
742
- const databaseUrl = config.DATABASE_URL;
743
- const dbPath = config.DB_PATH;
744
- if (databaseUrl) {
745
- adapter = new PgAdapter(databaseUrl);
746
- } else if (dbPath) {
747
- adapter = new SqliteAdapter(dbPath);
748
- } else {
749
- throw new Error("Either DATABASE_URL or DB_PATH must be set");
750
- }
751
- return adapter;
752
- }
753
- function getAdapterSync() {
754
- if (!adapter) {
755
- throw new Error(
756
- "Database adapter not initialized. Call getAdapter() at startup first."
757
- );
758
- }
759
- return adapter;
760
- }
761
- async function closeAdapter() {
762
- if (adapter) {
763
- await adapter.close();
764
- adapter = null;
765
- }
766
- }
767
- var adapter;
768
- var init_connection = __esm({
769
- "src/infra/database/connection.ts"() {
770
- "use strict";
771
- init_esm_shims();
772
- init_sqlite_adapter();
773
- init_pg_adapter();
774
- init_config();
775
- adapter = null;
569
+ databaseConnectionManager = DatabaseConnectionManager.getInstance();
776
570
  }
777
571
  });
778
572
 
@@ -787,6 +581,9 @@ var init_constants3 = __esm({
787
581
  });
788
582
 
789
583
  // src/infra/database/query-builder.ts
584
+ function getDb() {
585
+ return databaseConnectionManager.getConnection();
586
+ }
790
587
  var QueryBuilder;
791
588
  var init_query_builder = __esm({
792
589
  "src/infra/database/query-builder.ts"() {
@@ -795,17 +592,24 @@ var init_query_builder = __esm({
795
592
  init_connection();
796
593
  init_constants3();
797
594
  QueryBuilder = class {
798
- static async select(sql, params = []) {
799
- return getAdapterSync().select(sql, params);
595
+ static select(sql, params = []) {
596
+ const stmt = getDb().prepare(sql);
597
+ return stmt.all(params);
800
598
  }
801
- static async selectOne(sql, params = []) {
802
- return getAdapterSync().selectOne(sql, params);
599
+ static selectOne(sql, params = []) {
600
+ const stmt = getDb().prepare(sql);
601
+ return stmt.get(params);
803
602
  }
804
- static async execute(sql, params = []) {
805
- return getAdapterSync().execute(sql, params);
603
+ static execute(sql, params = []) {
604
+ const stmt = getDb().prepare(sql);
605
+ const result = stmt.run(params);
606
+ return {
607
+ changes: result.changes,
608
+ lastInsertRowid: result.lastInsertRowid
609
+ };
806
610
  }
807
- static async transaction(callback) {
808
- return getAdapterSync().transaction(callback);
611
+ static transaction(callback) {
612
+ return getDb().transaction(callback)();
809
613
  }
810
614
  static paginate(sql, options = {}) {
811
615
  let query = sql;
@@ -827,12 +631,17 @@ var init_query_builder = __esm({
827
631
  });
828
632
 
829
633
  // src/infra/database/index.ts
634
+ function getDb2() {
635
+ return databaseConnectionManager.getConnection();
636
+ }
637
+ var database_default;
830
638
  var init_database = __esm({
831
639
  "src/infra/database/index.ts"() {
832
640
  "use strict";
833
641
  init_esm_shims();
834
642
  init_connection();
835
643
  init_query_builder();
644
+ database_default = getDb2;
836
645
  }
837
646
  });
838
647
 
@@ -856,22 +665,22 @@ var init_portals_model = __esm({
856
665
  init_database();
857
666
  PortalsModel = class {
858
667
  static TABLE = "portals";
859
- static async findByPortalAddress(portalAddress) {
668
+ static findByPortalAddress(portalAddress) {
860
669
  const sql = `SELECT _id, portalAddress, portalSeed, ownerAddress, createdAt, updatedAt FROM ${this.TABLE} WHERE portalAddress = ?`;
861
670
  return QueryBuilder.selectOne(sql, [portalAddress]);
862
671
  }
863
- static async create(input) {
672
+ static create(input) {
864
673
  const _id = uuidv72();
865
674
  const now = (/* @__PURE__ */ new Date()).toISOString();
866
675
  const sql = `INSERT INTO ${this.TABLE} (_id, portalAddress, portalSeed, ownerAddress, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?)`;
867
- await QueryBuilder.execute(sql, [_id, input.portalAddress, input.portalSeed, input.ownerAddress, now, now]);
868
- const created = await this.findByPortalAddress(input.portalAddress);
676
+ QueryBuilder.execute(sql, [_id, input.portalAddress, input.portalSeed, input.ownerAddress, now, now]);
677
+ const created = this.findByPortalAddress(input.portalAddress);
869
678
  if (!created) {
870
679
  throw new Error("Failed to create portal");
871
680
  }
872
681
  return created;
873
682
  }
874
- static async update(portalAddress, input) {
683
+ static update(portalAddress, input) {
875
684
  const now = (/* @__PURE__ */ new Date()).toISOString();
876
685
  const keys = [];
877
686
  const values = [];
@@ -886,15 +695,15 @@ var init_portals_model = __esm({
886
695
  const updateChain = keys.join(", ");
887
696
  const sql = `UPDATE ${this.TABLE} SET ${updateChain} WHERE portalAddress = ?`;
888
697
  values.push(portalAddress);
889
- await QueryBuilder.execute(sql, values);
890
- const updated = await this.findByPortalAddress(portalAddress);
698
+ QueryBuilder.execute(sql, values);
699
+ const updated = this.findByPortalAddress(portalAddress);
891
700
  if (!updated) {
892
701
  throw new Error("Failed to update portal");
893
702
  }
894
703
  return updated;
895
704
  }
896
- static async upsert(input) {
897
- const existing = await this.findByPortalAddress(input.portalAddress);
705
+ static upsert(input) {
706
+ const existing = this.findByPortalAddress(input.portalAddress);
898
707
  if (existing) {
899
708
  return this.update(input.portalAddress, {
900
709
  portalSeed: input.portalSeed,
@@ -917,12 +726,12 @@ var init_apikeys_model = __esm({
917
726
  init_database();
918
727
  ApiKeysModel = class {
919
728
  static TABLE = "api_keys";
920
- static async create(input) {
729
+ static create(input) {
921
730
  const _id = uuidv73();
922
731
  const now = (/* @__PURE__ */ new Date()).toISOString();
923
- const sql = `INSERT INTO ${this.TABLE} (_id, apiKeySeed, name, collaboratorAddress, portalAddress, createdAt)
732
+ const sql = `INSERT INTO ${this.TABLE} (_id, apiKeySeed, name, collaboratorAddress, portalAddress, createdAt)
924
733
  VALUES (?, ?, ?, ?, ?, ?)`;
925
- const result = await QueryBuilder.execute(sql, [
734
+ const result = QueryBuilder.execute(sql, [
926
735
  _id,
927
736
  input.apiKeySeed,
928
737
  input.name,
@@ -933,29 +742,29 @@ var init_apikeys_model = __esm({
933
742
  if (result.changes === 0) {
934
743
  throw new Error("Failed to create API key");
935
744
  }
936
- const created = await this.findById(_id);
745
+ const created = this.findById(_id);
937
746
  if (!created) {
938
747
  throw new Error("Failed to create API key");
939
748
  }
940
749
  return created;
941
750
  }
942
- static async findById(_id) {
751
+ static findById(_id) {
943
752
  const sql = `SELECT _id, apiKeySeed, name, collaboratorAddress, portalAddress, createdAt, isDeleted FROM ${this.TABLE} WHERE _id = ? AND isDeleted = 0`;
944
753
  return QueryBuilder.selectOne(sql, [_id]);
945
754
  }
946
- static async findByCollaboratorAddress(collaboratorAddress) {
755
+ static findByCollaboratorAddress(collaboratorAddress) {
947
756
  const sql = `SELECT _id, apiKeySeed, name, collaboratorAddress, portalAddress, createdAt, isDeleted FROM ${this.TABLE} WHERE collaboratorAddress = ? AND isDeleted = 0 LIMIT 1`;
948
757
  return QueryBuilder.selectOne(sql, [collaboratorAddress]);
949
758
  }
950
- static async delete(_id) {
759
+ static delete(_id) {
951
760
  const sql = `UPDATE ${this.TABLE} SET isDeleted = 1 WHERE _id = ?`;
952
- await QueryBuilder.execute(sql, [_id]);
761
+ QueryBuilder.execute(sql, [_id]);
953
762
  }
954
- static async findByPortalAddress(portalAddress) {
763
+ static findByPortalAddress(portalAddress) {
955
764
  const sql = `SELECT _id, apiKeySeed, name, collaboratorAddress, portalAddress, createdAt, isDeleted FROM ${this.TABLE} WHERE portalAddress = ? AND isDeleted = 0`;
956
765
  return QueryBuilder.selectOne(sql, [portalAddress]);
957
766
  }
958
- static async findByApiKey(apiKey) {
767
+ static findByApiKey(apiKey) {
959
768
  const sql = `SELECT _id, apiKeySeed, name, collaboratorAddress, portalAddress, createdAt, isDeleted FROM ${this.TABLE} WHERE apiKeySeed = ? AND isDeleted = 0`;
960
769
  return QueryBuilder.selectOne(sql, [apiKey]);
961
770
  }
@@ -997,7 +806,7 @@ var init_models = __esm({
997
806
  });
998
807
 
999
808
  // src/domain/portal/savePortal.ts
1000
- async function savePortal(input) {
809
+ function savePortal(input) {
1001
810
  if (!input.portalAddress || !input.portalSeed || !input.ownerAddress) {
1002
811
  throw new Error("portalAddress, portalSeed, and ownerAddress are required");
1003
812
  }
@@ -1016,9 +825,9 @@ var migrations_exports = {};
1016
825
  __export(migrations_exports, {
1017
826
  runMigrations: () => runMigrations
1018
827
  });
1019
- async function runMigrations() {
1020
- const adapter2 = getAdapterSync();
1021
- await adapter2.exec(STABLE_SCHEMA);
828
+ function runMigrations() {
829
+ const db = database_default();
830
+ db.exec(STABLE_SCHEMA);
1022
831
  logger.debug("Database schema ready");
1023
832
  }
1024
833
  var STABLE_SCHEMA;
@@ -1026,7 +835,7 @@ var init_migrations = __esm({
1026
835
  "src/infra/database/migrations/index.ts"() {
1027
836
  "use strict";
1028
837
  init_esm_shims();
1029
- init_connection();
838
+ init_database();
1030
839
  init_infra();
1031
840
  STABLE_SCHEMA = `
1032
841
  CREATE TABLE IF NOT EXISTS files (
@@ -1037,8 +846,8 @@ CREATE TABLE IF NOT EXISTS files (
1037
846
  localVersion INTEGER NOT NULL DEFAULT 1,
1038
847
  onchainVersion INTEGER NOT NULL DEFAULT 0,
1039
848
  syncStatus TEXT NOT NULL DEFAULT 'pending',
1040
- createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
1041
- updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
849
+ createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
850
+ updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
1042
851
  isDeleted INTEGER NOT NULL DEFAULT 0,
1043
852
  portalAddress TEXT NOT NULL,
1044
853
  metadata TEXT DEFAULT '{}',
@@ -1058,8 +867,8 @@ CREATE TABLE IF NOT EXISTS portals (
1058
867
  portalAddress TEXT NOT NULL UNIQUE,
1059
868
  portalSeed TEXT NOT NULL UNIQUE,
1060
869
  ownerAddress TEXT NOT NULL,
1061
- createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
1062
- updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
870
+ createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
871
+ updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
1063
872
  );
1064
873
 
1065
874
  CREATE TABLE IF NOT EXISTS api_keys (
@@ -1068,7 +877,7 @@ CREATE TABLE IF NOT EXISTS api_keys (
1068
877
  name TEXT NOT NULL,
1069
878
  collaboratorAddress TEXT NOT NULL UNIQUE,
1070
879
  portalAddress TEXT NOT NULL,
1071
- createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
880
+ createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
1072
881
  isDeleted INTEGER NOT NULL DEFAULT 0
1073
882
  );
1074
883
 
@@ -1104,8 +913,8 @@ CREATE TABLE IF NOT EXISTS folders (
1104
913
  lastTransactionHash TEXT,
1105
914
  lastTransactionBlockNumber INTEGER NOT NULL,
1106
915
  lastTransactionBlockTimestamp INTEGER NOT NULL,
1107
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
1108
- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
916
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
917
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
1109
918
  );
1110
919
  CREATE INDEX IF NOT EXISTS idx_folders_folderRef_folderId ON folders(folderRef, folderId);
1111
920
  CREATE INDEX IF NOT EXISTS idx_folders_folderRef ON folders(folderRef);
@@ -1339,16 +1148,16 @@ import { toUint8Array as toUint8Array5 } from "js-base64";
1339
1148
  import { stringToBytes as stringToBytes2 } from "viem";
1340
1149
  import { toAESKey as toAESKey2, aesDecrypt } from "@fileverse/crypto/webcrypto";
1341
1150
  var SAVED_DATA_ENCRYPTION_KEY_INFO = "SAVED_DATA_ENCRYPTION_KEY";
1342
- async function initializeWithData(data) {
1151
+ function initializeWithData(data) {
1343
1152
  const { keyMaterial, appMaterial } = data;
1344
- await savePortal({
1153
+ savePortal({
1345
1154
  portalAddress: appMaterial.portalAddress,
1346
1155
  portalSeed: appMaterial.portalSeed,
1347
1156
  ownerAddress: appMaterial.ownerAddress
1348
1157
  });
1349
- const existingApiKey = await ApiKeysModel.findByApiKey(keyMaterial.apiKeySeed);
1158
+ const existingApiKey = ApiKeysModel.findByApiKey(keyMaterial.apiKeySeed);
1350
1159
  if (!existingApiKey) {
1351
- await addApiKey({
1160
+ addApiKey({
1352
1161
  apiKeySeed: keyMaterial.apiKeySeed,
1353
1162
  name: keyMaterial.name,
1354
1163
  collaboratorAddress: keyMaterial.collaboratorAddress,
@@ -1377,7 +1186,7 @@ var decryptSavedData = async (apiKey, encryptedData) => {
1377
1186
  };
1378
1187
 
1379
1188
  // src/cli/index.ts
1380
- var program = new Command().name("fileverse-api").description("Run the Fileverse API server").version("0.0.2").option("--apiKey <key>", "API key for authentication").option("--rpcUrl <url>", "RPC URL for blockchain connection").option("--port <port>", "Port to run the server on", "8001").option("--db <path>", "Database path").action(async (options) => {
1189
+ var program = new Command().name("fileverse-api").description("Run the Fileverse API server").version("0.0.3").option("--apiKey <key>", "API key for authentication").option("--rpcUrl <url>", "RPC URL for blockchain connection").option("--port <port>", "Port to run the server on", "8001").option("--db <path>", "Database path").action(async (options) => {
1381
1190
  try {
1382
1191
  console.log("Fileverse API - Starting initialization...\n");
1383
1192
  if (needsPrompting(options)) {
@@ -1402,12 +1211,10 @@ var program = new Command().name("fileverse-api").description("Run the Fileverse
1402
1211
  loadConfig();
1403
1212
  console.log(`\u2713 Configuration saved to ${envPath}
1404
1213
  `);
1405
- const { getAdapter: getAdapter2 } = await Promise.resolve().then(() => (init_connection(), connection_exports));
1406
- await getAdapter2();
1407
1214
  const { runMigrations: runMigrations2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
1408
- await runMigrations2();
1215
+ runMigrations2();
1409
1216
  console.log("\u2713 Database migrations complete");
1410
- const result = await initializeWithData({
1217
+ const result = initializeWithData({
1411
1218
  keyMaterial,
1412
1219
  appMaterial,
1413
1220
  id: data.id