@utaba/deep-memory-storage-sqlserver 0.2.0 → 0.4.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.d.cts CHANGED
@@ -1,6 +1,7 @@
1
+ import * as _utaba_deep_memory_types from '@utaba/deep-memory/types';
2
+ import { StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighborhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
1
3
  import sql from 'mssql';
2
4
  import { StorageProvider, EnsureSchemaResult, SearchProvider, SearchableEntity } from '@utaba/deep-memory/providers';
3
- import { StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighbourhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
4
5
 
5
6
  /** Configuration for SqlServerStorageProvider */
6
7
  interface SqlServerStorageProviderConfig {
@@ -17,7 +18,7 @@ declare class SqlServerStorageProvider implements StorageProvider {
17
18
  constructor(config: SqlServerStorageProviderConfig);
18
19
  private t;
19
20
  private getPool;
20
- initialise(): Promise<void>;
21
+ initialize(): Promise<void>;
21
22
  dispose(): Promise<void>;
22
23
  /**
23
24
  * Ensure the target database exists. If constructed with a sql.config and the
@@ -32,7 +33,11 @@ declare class SqlServerStorageProvider implements StorageProvider {
32
33
  getRepository(repositoryId: string): Promise<StoredRepository | null>;
33
34
  listRepositories(filter?: RepositoryFilter): Promise<PaginatedResult<StoredRepositorySummary>>;
34
35
  updateRepository(repositoryId: string, updates: RepositoryUpdate): Promise<StoredRepository>;
35
- deleteRepository(repositoryId: string): Promise<void>;
36
+ deleteRepository(repositoryId: string, _onProgress?: _utaba_deep_memory_types.DeleteProgressCallback): Promise<void>;
37
+ deleteAllContents(repositoryId: string, _onProgress?: _utaba_deep_memory_types.DeleteProgressCallback): Promise<{
38
+ deletedEntities: number;
39
+ deletedRelationships: number;
40
+ }>;
36
41
  getRepositoryStats(repositoryId: string): Promise<RepositoryStats>;
37
42
  getVocabulary(repositoryId: string): Promise<MemoryVocabulary>;
38
43
  saveVocabulary(repositoryId: string, vocabulary: MemoryVocabulary): Promise<void>;
@@ -60,11 +65,11 @@ declare class SqlServerStorageProvider implements StorageProvider {
60
65
  deleteRelationshipsByType(repositoryId: string, relationshipType: string): Promise<{
61
66
  deletedRelationships: number;
62
67
  }>;
63
- exploreNeighbourhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighbourhood>;
68
+ exploreNeighborhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighborhood>;
64
69
  findPaths(repositoryId: string, sourceId: string, targetId: string, options: StoragePathOptions): Promise<StoragePathResult>;
65
70
  getTimeline(repositoryId: string, entityId: string, options: StorageTimelineOptions): Promise<StorageTimelineResult>;
66
71
  exportAll(repositoryId: string): AsyncIterable<ExportChunk>;
67
- importBulk(repositoryId: string, data: ImportChunk[]): Promise<BulkImportResult>;
72
+ importBulk(repositoryId: string, data: ImportChunk[], _options?: _utaba_deep_memory_types.BulkImportOptions): Promise<BulkImportResult>;
68
73
  /** Creates a TVP table from an array of string IDs (eliminates plan cache bloat from IN clauses). */
69
74
  private createIdListTvp;
70
75
  /** Returns a StoredEntity without the embedding column (lighter I/O). */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import * as _utaba_deep_memory_types from '@utaba/deep-memory/types';
2
+ import { StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighborhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
1
3
  import sql from 'mssql';
2
4
  import { StorageProvider, EnsureSchemaResult, SearchProvider, SearchableEntity } from '@utaba/deep-memory/providers';
3
- import { StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighbourhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
4
5
 
5
6
  /** Configuration for SqlServerStorageProvider */
6
7
  interface SqlServerStorageProviderConfig {
@@ -17,7 +18,7 @@ declare class SqlServerStorageProvider implements StorageProvider {
17
18
  constructor(config: SqlServerStorageProviderConfig);
18
19
  private t;
19
20
  private getPool;
20
- initialise(): Promise<void>;
21
+ initialize(): Promise<void>;
21
22
  dispose(): Promise<void>;
22
23
  /**
23
24
  * Ensure the target database exists. If constructed with a sql.config and the
@@ -32,7 +33,11 @@ declare class SqlServerStorageProvider implements StorageProvider {
32
33
  getRepository(repositoryId: string): Promise<StoredRepository | null>;
33
34
  listRepositories(filter?: RepositoryFilter): Promise<PaginatedResult<StoredRepositorySummary>>;
34
35
  updateRepository(repositoryId: string, updates: RepositoryUpdate): Promise<StoredRepository>;
35
- deleteRepository(repositoryId: string): Promise<void>;
36
+ deleteRepository(repositoryId: string, _onProgress?: _utaba_deep_memory_types.DeleteProgressCallback): Promise<void>;
37
+ deleteAllContents(repositoryId: string, _onProgress?: _utaba_deep_memory_types.DeleteProgressCallback): Promise<{
38
+ deletedEntities: number;
39
+ deletedRelationships: number;
40
+ }>;
36
41
  getRepositoryStats(repositoryId: string): Promise<RepositoryStats>;
37
42
  getVocabulary(repositoryId: string): Promise<MemoryVocabulary>;
38
43
  saveVocabulary(repositoryId: string, vocabulary: MemoryVocabulary): Promise<void>;
@@ -60,11 +65,11 @@ declare class SqlServerStorageProvider implements StorageProvider {
60
65
  deleteRelationshipsByType(repositoryId: string, relationshipType: string): Promise<{
61
66
  deletedRelationships: number;
62
67
  }>;
63
- exploreNeighbourhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighbourhood>;
68
+ exploreNeighborhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighborhood>;
64
69
  findPaths(repositoryId: string, sourceId: string, targetId: string, options: StoragePathOptions): Promise<StoragePathResult>;
65
70
  getTimeline(repositoryId: string, entityId: string, options: StorageTimelineOptions): Promise<StorageTimelineResult>;
66
71
  exportAll(repositoryId: string): AsyncIterable<ExportChunk>;
67
- importBulk(repositoryId: string, data: ImportChunk[]): Promise<BulkImportResult>;
72
+ importBulk(repositoryId: string, data: ImportChunk[], _options?: _utaba_deep_memory_types.BulkImportOptions): Promise<BulkImportResult>;
68
73
  /** Creates a TVP table from an array of string IDs (eliminates plan cache bloat from IN clauses). */
69
74
  private createIdListTvp;
70
75
  /** Returns a StoredEntity without the embedding column (lighter I/O). */
package/dist/index.js CHANGED
@@ -406,13 +406,13 @@ var SqlServerStorageProvider = class {
406
406
  getPool() {
407
407
  if (!this.pool) {
408
408
  throw new ProviderError(
409
- "SqlServerStorageProvider not initialised. Call initialise() first."
409
+ "SqlServerStorageProvider not initialized. Call initialize() first."
410
410
  );
411
411
  }
412
412
  return this.pool;
413
413
  }
414
414
  // ─── Lifecycle ────────────────────────────────────────────────────
415
- async initialise() {
415
+ async initialize() {
416
416
  if (this.config.connection instanceof sql.ConnectionPool) {
417
417
  this.pool = this.config.connection;
418
418
  this.ownsPool = false;
@@ -667,13 +667,23 @@ var SqlServerStorageProvider = class {
667
667
  if (!updated) throw new RepositoryNotFoundError(repositoryId);
668
668
  return updated;
669
669
  }
670
- async deleteRepository(repositoryId) {
670
+ async deleteRepository(repositoryId, _onProgress) {
671
671
  const pool = this.getPool();
672
672
  const result = await pool.request().input("id", sql.UniqueIdentifier, repositoryId).query(`DELETE FROM ${this.t("dm_repositories")} WHERE [repository_id] = @id`);
673
673
  if (result.rowsAffected[0] === 0) {
674
674
  throw new RepositoryNotFoundError(repositoryId);
675
675
  }
676
676
  }
677
+ async deleteAllContents(repositoryId, _onProgress) {
678
+ await this.assertRepository(repositoryId);
679
+ const pool = this.getPool();
680
+ const relResult = await pool.request().input("id", sql.UniqueIdentifier, repositoryId).query(`DELETE FROM ${this.t("dm_relationships")} WHERE [repository_id] = @id`);
681
+ const entityResult = await pool.request().input("id", sql.UniqueIdentifier, repositoryId).query(`DELETE FROM ${this.t("dm_entities")} WHERE [repository_id] = @id`);
682
+ return {
683
+ deletedEntities: entityResult.rowsAffected[0] ?? 0,
684
+ deletedRelationships: relResult.rowsAffected[0] ?? 0
685
+ };
686
+ }
677
687
  async getRepositoryStats(repositoryId) {
678
688
  await this.assertRepository(repositoryId);
679
689
  const pool = this.getPool();
@@ -1117,9 +1127,9 @@ var SqlServerStorageProvider = class {
1117
1127
  return { deletedRelationships: result.rowsAffected[0] ?? 0 };
1118
1128
  }
1119
1129
  // ─── Graph Traversal ────────────────────────────────────────────
1120
- async exploreNeighbourhood(repositoryId, entityId, options) {
1121
- const centre = await this.getEntityLight(repositoryId, entityId);
1122
- if (!centre) {
1130
+ async exploreNeighborhood(repositoryId, entityId, options) {
1131
+ const center = await this.getEntityLight(repositoryId, entityId);
1132
+ if (!center) {
1123
1133
  throw new EntityNotFoundError(entityId);
1124
1134
  }
1125
1135
  const layers = [];
@@ -1181,7 +1191,7 @@ var SqlServerStorageProvider = class {
1181
1191
  currentFrontier = nextFrontier;
1182
1192
  if (nextFrontier.size === 0) break;
1183
1193
  }
1184
- return { centreId: entityId, layers };
1194
+ return { centerId: entityId, layers };
1185
1195
  }
1186
1196
  async findPaths(repositoryId, sourceId, targetId, options) {
1187
1197
  const [source, target] = await Promise.all([
@@ -1363,7 +1373,7 @@ var SqlServerStorageProvider = class {
1363
1373
  }
1364
1374
  }
1365
1375
  }
1366
- async importBulk(repositoryId, data) {
1376
+ async importBulk(repositoryId, data, _options) {
1367
1377
  await this.assertRepository(repositoryId);
1368
1378
  const pool = this.getPool();
1369
1379
  let entitiesImported = 0;
@@ -1563,7 +1573,7 @@ var SqlServerStorageProvider = class {
1563
1573
  // src/SqlServerSearchProvider.ts
1564
1574
  import sql2 from "mssql";
1565
1575
  import { ProviderError as ProviderError2 } from "@utaba/deep-memory";
1566
- function normaliseRank(rank) {
1576
+ function normalizeRank(rank) {
1567
1577
  return Math.min(1, Math.max(0, rank / 1e3));
1568
1578
  }
1569
1579
  function buildHighlights(query, row) {
@@ -1663,7 +1673,7 @@ var SqlServerSearchProvider = class {
1663
1673
  const total = rows.length > 0 ? rows[0]["total_count"] : 0;
1664
1674
  const items = rows.map((row) => ({
1665
1675
  id: row["entity_id"],
1666
- score: normaliseRank(row["ft_rank"]),
1676
+ score: normalizeRank(row["ft_rank"]),
1667
1677
  highlights: buildHighlights(query, row)
1668
1678
  }));
1669
1679
  return {