@haex-space/vault-sdk 2.0.0 → 2.2.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.
@@ -92,6 +92,15 @@ interface DatabaseQueryResult {
92
92
  interface DatabaseExecuteParams {
93
93
  statements: string[];
94
94
  }
95
+ interface MigrationResult {
96
+ appliedCount: number;
97
+ alreadyAppliedCount: number;
98
+ appliedMigrations: string[];
99
+ }
100
+ interface Migration {
101
+ name: string;
102
+ sql: string;
103
+ }
95
104
  interface DatabaseTableInfo {
96
105
  name: string;
97
106
  columns: DatabaseColumnInfo[];
@@ -219,17 +228,20 @@ declare class DatabaseAPI {
219
228
  createTable(tableName: string, columns: string): Promise<void>;
220
229
  dropTable(tableName: string): Promise<void>;
221
230
  /**
222
- * Registers extension migrations with HaexVault for CRDT synchronization
223
- * HaexVault will validate and execute these migrations, ensuring only
224
- * tables with the correct prefix are manipulated
231
+ * Registers and applies extension migrations with HaexVault
232
+ *
233
+ * HaexVault will:
234
+ * 1. Validate all SQL statements (ensure only extension's own tables are accessed)
235
+ * 2. Store migrations with applied_at = NULL
236
+ * 3. Query pending migrations sorted by name
237
+ * 4. Apply pending migrations and set up CRDT triggers
238
+ * 5. Mark successful migrations with applied_at timestamp
239
+ *
225
240
  * @param extensionVersion - The version of the extension
226
241
  * @param migrations - Array of migration objects with name and SQL content
227
- * @returns Promise that resolves when migrations are registered
242
+ * @returns Promise with migration result (applied count, already applied count, applied migration names)
228
243
  */
229
- registerMigrationsAsync(extensionVersion: string, migrations: Array<{
230
- name: string;
231
- sql: string;
232
- }>): Promise<void>;
244
+ registerMigrationsAsync(extensionVersion: string, migrations: Migration[]): Promise<MigrationResult>;
233
245
  insert(tableName: string, data: Record<string, unknown>): Promise<number>;
234
246
  update(tableName: string, data: Record<string, unknown>, where: string, whereParams?: unknown[]): Promise<number>;
235
247
  delete(tableName: string, where: string, whereParams?: unknown[]): Promise<number>;
@@ -458,16 +470,20 @@ declare class HaexVaultClient {
458
470
  lastInsertId?: number;
459
471
  }>;
460
472
  /**
461
- * Registers extension migrations with HaexVault for CRDT synchronization
462
- * HaexVault will validate and execute these migrations
473
+ * Registers and applies extension migrations with HaexVault
474
+ *
475
+ * HaexVault will:
476
+ * 1. Validate all SQL statements (ensure only extension's own tables are accessed)
477
+ * 2. Store migrations with applied_at = NULL
478
+ * 3. Query pending migrations sorted by name
479
+ * 4. Apply pending migrations and set up CRDT triggers
480
+ * 5. Mark successful migrations with applied_at timestamp
481
+ *
463
482
  * @param extensionVersion - The version of the extension
464
483
  * @param migrations - Array of migration objects with name and SQL content
465
- * @returns Promise that resolves when migrations are registered
484
+ * @returns Promise with migration result (applied count, already applied count, applied migration names)
466
485
  */
467
- registerMigrationsAsync(extensionVersion: string, migrations: Array<{
468
- name: string;
469
- sql: string;
470
- }>): Promise<void>;
486
+ registerMigrationsAsync(extensionVersion: string, migrations: Migration[]): Promise<MigrationResult>;
471
487
  requestDatabasePermission(request: DatabasePermissionRequest): Promise<PermissionResponse>;
472
488
  checkDatabasePermission(resource: string, operation: "read" | "write"): Promise<boolean>;
473
489
  respondToSearch(requestId: string, results: SearchResult[]): Promise<void>;
@@ -92,6 +92,15 @@ interface DatabaseQueryResult {
92
92
  interface DatabaseExecuteParams {
93
93
  statements: string[];
94
94
  }
95
+ interface MigrationResult {
96
+ appliedCount: number;
97
+ alreadyAppliedCount: number;
98
+ appliedMigrations: string[];
99
+ }
100
+ interface Migration {
101
+ name: string;
102
+ sql: string;
103
+ }
95
104
  interface DatabaseTableInfo {
96
105
  name: string;
97
106
  columns: DatabaseColumnInfo[];
@@ -219,17 +228,20 @@ declare class DatabaseAPI {
219
228
  createTable(tableName: string, columns: string): Promise<void>;
220
229
  dropTable(tableName: string): Promise<void>;
221
230
  /**
222
- * Registers extension migrations with HaexVault for CRDT synchronization
223
- * HaexVault will validate and execute these migrations, ensuring only
224
- * tables with the correct prefix are manipulated
231
+ * Registers and applies extension migrations with HaexVault
232
+ *
233
+ * HaexVault will:
234
+ * 1. Validate all SQL statements (ensure only extension's own tables are accessed)
235
+ * 2. Store migrations with applied_at = NULL
236
+ * 3. Query pending migrations sorted by name
237
+ * 4. Apply pending migrations and set up CRDT triggers
238
+ * 5. Mark successful migrations with applied_at timestamp
239
+ *
225
240
  * @param extensionVersion - The version of the extension
226
241
  * @param migrations - Array of migration objects with name and SQL content
227
- * @returns Promise that resolves when migrations are registered
242
+ * @returns Promise with migration result (applied count, already applied count, applied migration names)
228
243
  */
229
- registerMigrationsAsync(extensionVersion: string, migrations: Array<{
230
- name: string;
231
- sql: string;
232
- }>): Promise<void>;
244
+ registerMigrationsAsync(extensionVersion: string, migrations: Migration[]): Promise<MigrationResult>;
233
245
  insert(tableName: string, data: Record<string, unknown>): Promise<number>;
234
246
  update(tableName: string, data: Record<string, unknown>, where: string, whereParams?: unknown[]): Promise<number>;
235
247
  delete(tableName: string, where: string, whereParams?: unknown[]): Promise<number>;
@@ -458,16 +470,20 @@ declare class HaexVaultClient {
458
470
  lastInsertId?: number;
459
471
  }>;
460
472
  /**
461
- * Registers extension migrations with HaexVault for CRDT synchronization
462
- * HaexVault will validate and execute these migrations
473
+ * Registers and applies extension migrations with HaexVault
474
+ *
475
+ * HaexVault will:
476
+ * 1. Validate all SQL statements (ensure only extension's own tables are accessed)
477
+ * 2. Store migrations with applied_at = NULL
478
+ * 3. Query pending migrations sorted by name
479
+ * 4. Apply pending migrations and set up CRDT triggers
480
+ * 5. Mark successful migrations with applied_at timestamp
481
+ *
463
482
  * @param extensionVersion - The version of the extension
464
483
  * @param migrations - Array of migration objects with name and SQL content
465
- * @returns Promise that resolves when migrations are registered
484
+ * @returns Promise with migration result (applied count, already applied count, applied migration names)
466
485
  */
467
- registerMigrationsAsync(extensionVersion: string, migrations: Array<{
468
- name: string;
469
- sql: string;
470
- }>): Promise<void>;
486
+ registerMigrationsAsync(extensionVersion: string, migrations: Migration[]): Promise<MigrationResult>;
471
487
  requestDatabasePermission(request: DatabasePermissionRequest): Promise<PermissionResponse>;
472
488
  checkDatabasePermission(resource: string, operation: "read" | "write"): Promise<boolean>;
473
489
  respondToSearch(requestId: string, results: SearchResult[]): Promise<void>;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HaexHubConfig, a as HaexVaultClient } from './client-O_JEOzfx.mjs';
2
- export { A as ApplicationContext, C as ContextChangedEvent, u as DEFAULT_TIMEOUT, D as DatabaseAPI, m as DatabaseColumnInfo, k as DatabaseExecuteParams, g as DatabasePermission, h as DatabasePermissionRequest, i as DatabaseQueryParams, j as DatabaseQueryResult, l as DatabaseTableInfo, t as ErrorCode, e as EventCallback, E as ExtensionInfo, F as FilesystemAPI, w as HAEXTENSION_EVENTS, v as HaexHubError, d as HaexHubEvent, b as HaexHubRequest, c as HaexHubResponse, x as HaextensionEvent, f as PermissionResponse, s as PermissionStatus, P as PermissionsAPI, n as SearchQuery, p as SearchRequestEvent, o as SearchResult, T as TABLE_SEPARATOR, W as WebAPI, q as WebRequestOptions, r as WebResponse } from './client-O_JEOzfx.mjs';
1
+ import { H as HaexHubConfig, a as HaexVaultClient } from './client-Dr3nKgRa.mjs';
2
+ export { A as ApplicationContext, C as ContextChangedEvent, u as DEFAULT_TIMEOUT, D as DatabaseAPI, m as DatabaseColumnInfo, k as DatabaseExecuteParams, g as DatabasePermission, h as DatabasePermissionRequest, i as DatabaseQueryParams, j as DatabaseQueryResult, l as DatabaseTableInfo, t as ErrorCode, e as EventCallback, E as ExtensionInfo, F as FilesystemAPI, w as HAEXTENSION_EVENTS, v as HaexHubError, d as HaexHubEvent, b as HaexHubRequest, c as HaexHubResponse, x as HaextensionEvent, f as PermissionResponse, s as PermissionStatus, P as PermissionsAPI, n as SearchQuery, p as SearchRequestEvent, o as SearchResult, T as TABLE_SEPARATOR, W as WebAPI, q as WebRequestOptions, r as WebResponse } from './client-Dr3nKgRa.mjs';
3
3
  export { HaextensionConfig } from './node.mjs';
4
4
  import 'drizzle-orm/sqlite-proxy';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HaexHubConfig, a as HaexVaultClient } from './client-O_JEOzfx.js';
2
- export { A as ApplicationContext, C as ContextChangedEvent, u as DEFAULT_TIMEOUT, D as DatabaseAPI, m as DatabaseColumnInfo, k as DatabaseExecuteParams, g as DatabasePermission, h as DatabasePermissionRequest, i as DatabaseQueryParams, j as DatabaseQueryResult, l as DatabaseTableInfo, t as ErrorCode, e as EventCallback, E as ExtensionInfo, F as FilesystemAPI, w as HAEXTENSION_EVENTS, v as HaexHubError, d as HaexHubEvent, b as HaexHubRequest, c as HaexHubResponse, x as HaextensionEvent, f as PermissionResponse, s as PermissionStatus, P as PermissionsAPI, n as SearchQuery, p as SearchRequestEvent, o as SearchResult, T as TABLE_SEPARATOR, W as WebAPI, q as WebRequestOptions, r as WebResponse } from './client-O_JEOzfx.js';
1
+ import { H as HaexHubConfig, a as HaexVaultClient } from './client-Dr3nKgRa.js';
2
+ export { A as ApplicationContext, C as ContextChangedEvent, u as DEFAULT_TIMEOUT, D as DatabaseAPI, m as DatabaseColumnInfo, k as DatabaseExecuteParams, g as DatabasePermission, h as DatabasePermissionRequest, i as DatabaseQueryParams, j as DatabaseQueryResult, l as DatabaseTableInfo, t as ErrorCode, e as EventCallback, E as ExtensionInfo, F as FilesystemAPI, w as HAEXTENSION_EVENTS, v as HaexHubError, d as HaexHubEvent, b as HaexHubRequest, c as HaexHubResponse, x as HaextensionEvent, f as PermissionResponse, s as PermissionStatus, P as PermissionsAPI, n as SearchQuery, p as SearchRequestEvent, o as SearchResult, T as TABLE_SEPARATOR, W as WebAPI, q as WebRequestOptions, r as WebResponse } from './client-Dr3nKgRa.js';
3
3
  export { HaextensionConfig } from './node.js';
4
4
  import 'drizzle-orm/sqlite-proxy';
5
5
 
package/dist/index.js CHANGED
@@ -522,18 +522,27 @@ var DatabaseAPI = class {
522
522
  await this.execute(query);
523
523
  }
524
524
  /**
525
- * Registers extension migrations with HaexVault for CRDT synchronization
526
- * HaexVault will validate and execute these migrations, ensuring only
527
- * tables with the correct prefix are manipulated
525
+ * Registers and applies extension migrations with HaexVault
526
+ *
527
+ * HaexVault will:
528
+ * 1. Validate all SQL statements (ensure only extension's own tables are accessed)
529
+ * 2. Store migrations with applied_at = NULL
530
+ * 3. Query pending migrations sorted by name
531
+ * 4. Apply pending migrations and set up CRDT triggers
532
+ * 5. Mark successful migrations with applied_at timestamp
533
+ *
528
534
  * @param extensionVersion - The version of the extension
529
535
  * @param migrations - Array of migration objects with name and SQL content
530
- * @returns Promise that resolves when migrations are registered
536
+ * @returns Promise with migration result (applied count, already applied count, applied migration names)
531
537
  */
532
538
  async registerMigrationsAsync(extensionVersion, migrations) {
533
- await this.client.request(HAEXTENSION_METHODS.database.registerMigrations, {
534
- extensionVersion,
535
- migrations
536
- });
539
+ return this.client.request(
540
+ HAEXTENSION_METHODS.database.registerMigrations,
541
+ {
542
+ extensionVersion,
543
+ migrations
544
+ }
545
+ );
537
546
  }
538
547
  async insert(tableName, data) {
539
548
  const keys = Object.keys(data);
@@ -1022,11 +1031,18 @@ var HaexVaultClient = class {
1022
1031
  };
1023
1032
  }
1024
1033
  /**
1025
- * Registers extension migrations with HaexVault for CRDT synchronization
1026
- * HaexVault will validate and execute these migrations
1034
+ * Registers and applies extension migrations with HaexVault
1035
+ *
1036
+ * HaexVault will:
1037
+ * 1. Validate all SQL statements (ensure only extension's own tables are accessed)
1038
+ * 2. Store migrations with applied_at = NULL
1039
+ * 3. Query pending migrations sorted by name
1040
+ * 4. Apply pending migrations and set up CRDT triggers
1041
+ * 5. Mark successful migrations with applied_at timestamp
1042
+ *
1027
1043
  * @param extensionVersion - The version of the extension
1028
1044
  * @param migrations - Array of migration objects with name and SQL content
1029
- * @returns Promise that resolves when migrations are registered
1045
+ * @returns Promise with migration result (applied count, already applied count, applied migration names)
1030
1046
  */
1031
1047
  async registerMigrationsAsync(extensionVersion, migrations) {
1032
1048
  return this.database.registerMigrationsAsync(extensionVersion, migrations);