@starkeep/storage-sqlite 0.6.2 → 0.7.0

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/index.cjs CHANGED
@@ -206,8 +206,14 @@ function applyLocalSchemaDdl(db) {
206
206
  compiler.schema.createTable("shared_app_label_keys").ifNotExists().addColumn("app_id", "text", (c) => c.notNull()).addColumn("key", "text", (c) => c.notNull()).addColumn("description", "text").addColumn("created_at", "text", (c) => c.notNull().defaultTo(import_kysely2.sql`(datetime('now'))`)).addPrimaryKeyConstraint("pk_shared_app_label_keys", ["app_id", "key"]).compile().sql
207
207
  );
208
208
  db.exec(
209
- compiler.schema.createTable("shared_app_registry").ifNotExists().addColumn("app_id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull()).addColumn("version", "text", (c) => c.notNull()).addColumn("tier", "text", (c) => c.notNull().defaultTo("app")).addColumn("manifest", "text", (c) => c.notNull()).addColumn("status", "text", (c) => c.notNull().defaultTo("installing")).addColumn("hmac_secret", "text", (c) => c.notNull()).addColumn("installed_at", "text", (c) => c.notNull().defaultTo(import_kysely2.sql`(datetime('now'))`)).addColumn("updated_at", "text", (c) => c.notNull().defaultTo(import_kysely2.sql`(datetime('now'))`)).compile().sql
209
+ compiler.schema.createTable("shared_app_registry").ifNotExists().addColumn("app_id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull()).addColumn("version", "text", (c) => c.notNull()).addColumn("tier", "text", (c) => c.notNull().defaultTo("app")).addColumn("manifest", "text", (c) => c.notNull()).addColumn("status", "text", (c) => c.notNull().defaultTo("installing")).addColumn("hmac_secret", "text", (c) => c.notNull()).addColumn("installed_at", "text", (c) => c.notNull().defaultTo(import_kysely2.sql`(datetime('now'))`)).addColumn("updated_at", "text", (c) => c.notNull().defaultTo(import_kysely2.sql`(datetime('now'))`)).addColumn("source_dir", "text").compile().sql
210
210
  );
211
+ const registryColumns = db.prepare("SELECT name FROM pragma_table_info('shared_app_registry')").all();
212
+ if (!registryColumns.some((c) => c.name === "source_dir")) {
213
+ db.exec(
214
+ compiler.schema.alterTable("shared_app_registry").addColumn("source_dir", "text").compile().sql
215
+ );
216
+ }
211
217
  db.exec(
212
218
  compiler.schema.createTable("shared_app_install_steps").ifNotExists().addColumn("app_id", "text", (c) => c.notNull()).addColumn(
213
219
  "operation",
@@ -789,6 +795,7 @@ var SqliteAppSyncableNamespaceStore = class {
789
795
  // src/app-syncable/apply.ts
790
796
  var import_kysely4 = require("kysely");
791
797
  var import_protocol_primitives5 = require("@starkeep/protocol-primitives");
798
+ var import_shared_space_api2 = require("@starkeep/shared-space-api");
792
799
  var import_storage_adapter5 = require("@starkeep/storage-adapter");
793
800
  function runCompiled(db, compiled) {
794
801
  db.prepare(compiled.sql).run(...compiled.parameters.map(toSqliteParam));
@@ -814,6 +821,7 @@ var SqliteAppSyncableApplier = class {
814
821
  `SqliteAppSyncableApplier: table "${entry.table}" not declared for app "${entry.appId}"`
815
822
  );
816
823
  }
824
+ (0, import_shared_space_api2.requireWellFormedFileIndexRow)(entry);
817
825
  const fullName = appSyncableTableName(entry.appId, entry.table);
818
826
  const { pkColumns } = tableInfo;
819
827
  if (entry.op === "insert") {
@@ -1034,7 +1042,7 @@ function nodeIdOf(updatedAt, entry) {
1034
1042
 
1035
1043
  // src/app-syncable/tables.ts
1036
1044
  var import_kysely5 = require("kysely");
1037
- var import_shared_space_api2 = require("@starkeep/shared-space-api");
1045
+ var import_shared_space_api3 = require("@starkeep/shared-space-api");
1038
1046
  var import_protocol_primitives6 = require("@starkeep/protocol-primitives");
1039
1047
  function createSyncableTable(db, fullName, columns, indexes = []) {
1040
1048
  let tb = compiler.schema.createTable(fullName).ifNotExists();
@@ -1058,7 +1066,7 @@ function createSyncableTable(db, fullName, columns, indexes = []) {
1058
1066
  );
1059
1067
  for (const index of indexes) {
1060
1068
  db.exec(
1061
- compiler.schema.createIndex((0, import_shared_space_api2.syncableIndexName)(fullName, [...index.columns])).ifNotExists().on(fullName).columns([...index.columns]).compile().sql
1069
+ compiler.schema.createIndex((0, import_shared_space_api3.syncableIndexName)(fullName, [...index.columns])).ifNotExists().on(fullName).columns([...index.columns]).compile().sql
1062
1070
  );
1063
1071
  }
1064
1072
  }
@@ -1081,11 +1089,11 @@ function createAppSyncableTables(db, appId, tables) {
1081
1089
  function createReservedFileRecordsTable(db, appId) {
1082
1090
  createSyncableTable(
1083
1091
  db,
1084
- appSyncableTableName(appId, import_shared_space_api2.FILE_RECORDS_TABLE),
1092
+ appSyncableTableName(appId, import_shared_space_api3.FILE_RECORDS_TABLE),
1085
1093
  // Through the one mapping, like `createAppSyncableTables` above. This was a
1086
1094
  // hand-written ternary whose Postgres twin in `dsql-ddl.ts` answered
1087
1095
  // `bigint` where this one answered `integer`, for one declared type.
1088
- import_shared_space_api2.FILE_RECORDS_COLUMNS.map((c) => ({
1096
+ import_shared_space_api3.FILE_RECORDS_COLUMNS.map((c) => ({
1089
1097
  name: c.name,
1090
1098
  type: (0, import_protocol_primitives6.sqliteColumnType)(c.type),
1091
1099
  notNull: Boolean(c.notNull),
@@ -1094,8 +1102,8 @@ function createReservedFileRecordsTable(db, appId) {
1094
1102
  );
1095
1103
  }
1096
1104
  function appSyncableNamespaceTables(syncable) {
1097
- const declared = syncable.tables.map((t) => (0, import_shared_space_api2.appSyncableTableInfo)(t.name, t.columns));
1098
- return syncable.files ? [...declared, import_shared_space_api2.FILE_RECORDS_TABLE_INFO] : declared;
1105
+ const declared = syncable.tables.map((t) => (0, import_shared_space_api3.appSyncableTableInfo)(t.name, t.columns));
1106
+ return syncable.files ? [...declared, import_shared_space_api3.FILE_RECORDS_TABLE_INFO] : declared;
1099
1107
  }
1100
1108
  function registerAppSyncableNamespace(db, appId, syncable) {
1101
1109
  createAppSyncableTables(db, appId, syncable.tables);