@utaba/deep-memory 0.3.0 → 0.5.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.
@@ -1,4 +1,4 @@
1
- import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighbourhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-1KBMVBGJ.js';
1
+ import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighborhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-B-8J4nQQ.cjs';
2
2
 
3
3
  /** Result returned by ensureSchema describing what actions were taken. */
4
4
  interface EnsureSchemaResult {
@@ -22,8 +22,8 @@ interface EnsureSchemaResult {
22
22
  * based on the requested detail level.
23
23
  */
24
24
  interface StorageProvider {
25
- /** Optional initialisation (e.g., database connection) */
26
- initialise?(): Promise<void>;
25
+ /** Optional initialization (e.g., database connection) */
26
+ initialize?(): Promise<void>;
27
27
  /** Optional cleanup (e.g., close connections) */
28
28
  dispose?(): Promise<void>;
29
29
  /** Optional schema creation / migration (e.g., create tables if they don't exist) */
@@ -62,7 +62,7 @@ interface StorageProvider {
62
62
  deleteRelationshipsByType(repositoryId: string, relationshipType: string): Promise<{
63
63
  deletedRelationships: number;
64
64
  }>;
65
- exploreNeighbourhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighbourhood>;
65
+ exploreNeighborhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighborhood>;
66
66
  findPaths(repositoryId: string, sourceId: string, targetId: string, options: StoragePathOptions): Promise<StoragePathResult>;
67
67
  getTimeline(repositoryId: string, entityId: string, options: StorageTimelineOptions): Promise<StorageTimelineResult>;
68
68
  exportAll(repositoryId: string): AsyncIterable<ExportChunk>;
@@ -1,4 +1,4 @@
1
- import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighbourhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-1KBMVBGJ.cjs';
1
+ import { S as StorageRepositoryConfig, c as StoredRepository, d as RepositoryFilter, e as PaginatedResult, f as StoredRepositorySummary, g as RepositoryUpdate, h as DeleteProgressCallback, i as RepositoryStats, M as MemoryVocabulary, j as PaginationOptions, V as VocabularyChangeRecord, k as StoredEntity, l as StoredEntityUpdate, m as StorageFindQuery, n as StoredRelationship, o as RelationshipQueryOptions, p as StorageExploreOptions, q as StorageNeighborhood, r as StoragePathOptions, s as StoragePathResult, t as StorageTimelineOptions, u as StorageTimelineResult, v as ExportChunk, I as ImportChunk, B as BulkImportOptions, w as BulkImportResult } from './portability-B-8J4nQQ.js';
2
2
 
3
3
  /** Result returned by ensureSchema describing what actions were taken. */
4
4
  interface EnsureSchemaResult {
@@ -22,8 +22,8 @@ interface EnsureSchemaResult {
22
22
  * based on the requested detail level.
23
23
  */
24
24
  interface StorageProvider {
25
- /** Optional initialisation (e.g., database connection) */
26
- initialise?(): Promise<void>;
25
+ /** Optional initialization (e.g., database connection) */
26
+ initialize?(): Promise<void>;
27
27
  /** Optional cleanup (e.g., close connections) */
28
28
  dispose?(): Promise<void>;
29
29
  /** Optional schema creation / migration (e.g., create tables if they don't exist) */
@@ -62,7 +62,7 @@ interface StorageProvider {
62
62
  deleteRelationshipsByType(repositoryId: string, relationshipType: string): Promise<{
63
63
  deletedRelationships: number;
64
64
  }>;
65
- exploreNeighbourhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighbourhood>;
65
+ exploreNeighborhood(repositoryId: string, entityId: string, options: StorageExploreOptions): Promise<StorageNeighborhood>;
66
66
  findPaths(repositoryId: string, sourceId: string, targetId: string, options: StoragePathOptions): Promise<StoragePathResult>;
67
67
  getTimeline(repositoryId: string, entityId: string, options: StorageTimelineOptions): Promise<StorageTimelineResult>;
68
68
  exportAll(repositoryId: string): AsyncIterable<ExportChunk>;
package/dist/index.cjs CHANGED
@@ -332,6 +332,12 @@ var EntityManager = class {
332
332
  this.storage = storage;
333
333
  this.embedding = embedding;
334
334
  }
335
+ repositoryId;
336
+ vocabularyEngine;
337
+ provenanceTracker;
338
+ eventBus;
339
+ storage;
340
+ embedding;
335
341
  /** Create one or more entities with vocabulary validation, ID generation, provenance, and events */
336
342
  async create(inputs) {
337
343
  const results = [];
@@ -695,7 +701,7 @@ function jaroWinklerSimilarity(a, b, scalingFactor = 0.1) {
695
701
  }
696
702
  return jaro + commonPrefix * Math.min(scalingFactor, 0.25) * (1 - jaro);
697
703
  }
698
- function normaliseTypeName(name) {
704
+ function normalizeTypeName(name) {
699
705
  return name.toLowerCase().trim().replace(/[-\s.]+/g, "_").replace(/[^a-z0-9_]/g, "");
700
706
  }
701
707
  function toScreamingSnakeCase(name) {
@@ -711,6 +717,11 @@ var RelationshipManager = class {
711
717
  this.eventBus = eventBus;
712
718
  this.storage = storage;
713
719
  }
720
+ repositoryId;
721
+ vocabularyEngine;
722
+ provenanceTracker;
723
+ eventBus;
724
+ storage;
714
725
  /** Create one or more relationships with vocabulary validation, provenance, and events */
715
726
  async create(inputs) {
716
727
  const results = [];
@@ -1645,8 +1656,12 @@ var GraphTraversal = class {
1645
1656
  this.graphTraversalProvider = graphTraversalProvider;
1646
1657
  this.vocabularyEngine = vocabularyEngine;
1647
1658
  }
1648
- /** BFS neighbourhood exploration from a centre entity */
1649
- async exploreNeighbourhood(entityId, options) {
1659
+ repositoryId;
1660
+ storage;
1661
+ graphTraversalProvider;
1662
+ vocabularyEngine;
1663
+ /** BFS neighborhood exploration from a center entity */
1664
+ async exploreNeighborhood(entityId, options) {
1650
1665
  const storageOptions = {
1651
1666
  depth: options?.depth ?? 1,
1652
1667
  relationshipTypes: options?.relationshipTypes,
@@ -1656,13 +1671,13 @@ var GraphTraversal = class {
1656
1671
  offsetPerType: options?.offsetPerType ?? 0,
1657
1672
  relationshipPropertyFilters: options?.relationshipPropertyFilters
1658
1673
  };
1659
- const storageResult = await this.storage.exploreNeighbourhood(
1674
+ const storageResult = await this.storage.exploreNeighborhood(
1660
1675
  this.repositoryId,
1661
1676
  entityId,
1662
1677
  storageOptions
1663
1678
  );
1664
- const centreEntity = await this.storage.getEntity(this.repositoryId, entityId);
1665
- if (!centreEntity) {
1679
+ const centerEntity = await this.storage.getEntity(this.repositoryId, entityId);
1680
+ if (!centerEntity) {
1666
1681
  throw new EntityNotFoundError(entityId);
1667
1682
  }
1668
1683
  const detailLevel = options?.detailLevel ?? "summary";
@@ -1686,11 +1701,11 @@ var GraphTraversal = class {
1686
1701
  return layer;
1687
1702
  });
1688
1703
  return {
1689
- centre: {
1690
- id: centreEntity.id,
1691
- slug: centreEntity.slug,
1692
- entityType: centreEntity.entityType,
1693
- label: centreEntity.label
1704
+ center: {
1705
+ id: centerEntity.id,
1706
+ slug: centerEntity.slug,
1707
+ entityType: centerEntity.entityType,
1708
+ label: centerEntity.label
1694
1709
  },
1695
1710
  layers,
1696
1711
  statistics: {
@@ -2244,8 +2259,8 @@ var MemoryRepository = class {
2244
2259
  };
2245
2260
  }
2246
2261
  // ─── Graph Traversal ───────────────────────────────────────────────
2247
- async exploreNeighbourhood(entityId, options) {
2248
- return this.graphTraversal.exploreNeighbourhood(entityId, options);
2262
+ async exploreNeighborhood(entityId, options) {
2263
+ return this.graphTraversal.exploreNeighborhood(entityId, options);
2249
2264
  }
2250
2265
  async findPaths(sourceId, targetId, options) {
2251
2266
  return this.graphTraversal.findPaths(sourceId, targetId, options);
@@ -2275,7 +2290,7 @@ var MemoryRepository = class {
2275
2290
  storageOptions
2276
2291
  );
2277
2292
  const entity = await this.storage.getEntity(this.repositoryId, entityId);
2278
- const centreRef = {
2293
+ const centerRef = {
2279
2294
  id: entityId,
2280
2295
  slug: entity?.slug ?? entityId,
2281
2296
  label: entity?.label ?? entityId
@@ -2321,7 +2336,7 @@ var MemoryRepository = class {
2321
2336
  timestamp: e.timestamp,
2322
2337
  eventType: e.eventType,
2323
2338
  description: `${rel.type} relationship created ${direction} ${otherRef.label}`,
2324
- relatedEntities: [centreRef, otherRef],
2339
+ relatedEntities: [centerRef, otherRef],
2325
2340
  relationship: relDetail
2326
2341
  };
2327
2342
  }
@@ -2329,13 +2344,13 @@ var MemoryRepository = class {
2329
2344
  return {
2330
2345
  timestamp: e.timestamp,
2331
2346
  eventType: e.eventType,
2332
- description: `${centreRef.label} ${action}`,
2333
- relatedEntities: [centreRef]
2347
+ description: `${centerRef.label} ${action}`,
2348
+ relatedEntities: [centerRef]
2334
2349
  };
2335
2350
  });
2336
2351
  return {
2337
2352
  id: entityId,
2338
- slug: centreRef.slug,
2353
+ slug: centerRef.slug,
2339
2354
  totalEvents: storageResult.total,
2340
2355
  returned: events.length,
2341
2356
  events
@@ -2418,14 +2433,14 @@ var SemanticDeduplicator = class {
2418
2433
  /**
2419
2434
  * Check whether a proposed type name is a duplicate of an existing type.
2420
2435
  * Uses embedding similarity if an EmbeddingProvider is available, otherwise falls back
2421
- * to Jaro-Winkler string similarity on normalised type names.
2436
+ * to Jaro-Winkler string similarity on normalized type names.
2422
2437
  */
2423
2438
  async checkDuplicate(proposedType, proposedDescription, existingTypes) {
2424
2439
  if (existingTypes.length === 0) {
2425
2440
  return { isDuplicate: false, matches: [] };
2426
2441
  }
2427
- const normProposed = normaliseTypeName(proposedType);
2428
- const exactMatch = existingTypes.find((t) => normaliseTypeName(t.type) === normProposed);
2442
+ const normProposed = normalizeTypeName(proposedType);
2443
+ const exactMatch = existingTypes.find((t) => normalizeTypeName(t.type) === normProposed);
2429
2444
  if (exactMatch) {
2430
2445
  return {
2431
2446
  isDuplicate: true,
@@ -2461,10 +2476,10 @@ var SemanticDeduplicator = class {
2461
2476
  };
2462
2477
  }
2463
2478
  checkWithStringSimilarity(proposedType, existingTypes) {
2464
- const normProposed = normaliseTypeName(proposedType);
2479
+ const normProposed = normalizeTypeName(proposedType);
2465
2480
  const matches = [];
2466
2481
  for (const existing of existingTypes) {
2467
- const normExisting = normaliseTypeName(existing.type);
2482
+ const normExisting = normalizeTypeName(existing.type);
2468
2483
  const similarity = jaroWinklerSimilarity(normProposed, normExisting);
2469
2484
  if (similarity >= this.threshold) {
2470
2485
  matches.push({
@@ -2625,7 +2640,7 @@ function canPropose(governanceConfig, _proposal) {
2625
2640
  case "locked":
2626
2641
  return {
2627
2642
  allowed: false,
2628
- reason: "Vocabulary is locked. Only organisation admins can modify the vocabulary via the admin API."
2643
+ reason: "Vocabulary is locked. Only organization admins can modify the vocabulary via the admin API."
2629
2644
  };
2630
2645
  case "managed":
2631
2646
  case "open":
@@ -3065,9 +3080,9 @@ function validateEntityUpdate(input, entityTypeDef) {
3065
3080
  return ok();
3066
3081
  }
3067
3082
  function validateRelationship(input, vocabulary, sourceEntityType, targetEntityType) {
3068
- const normalisedType = toScreamingSnakeCase(input.relationshipType);
3083
+ const normalizedType = toScreamingSnakeCase(input.relationshipType);
3069
3084
  const relTypeDef = vocabulary.relationshipTypes.find(
3070
- (rt) => rt.type === normalisedType
3085
+ (rt) => rt.type === normalizedType
3071
3086
  );
3072
3087
  if (!relTypeDef) {
3073
3088
  const closest = findClosestType(input.relationshipType, vocabulary.relationshipTypes);
@@ -3392,7 +3407,7 @@ var EventBus = class {
3392
3407
  };
3393
3408
 
3394
3409
  // src/portability/RepositoryExporter.ts
3395
- var LIBRARY_VERSION = true ? "0.3.0" : "0.1.0";
3410
+ var LIBRARY_VERSION = true ? "0.5.0" : "0.1.0";
3396
3411
  var RepositoryExporter = class {
3397
3412
  storage;
3398
3413
  provenance;
@@ -3608,7 +3623,7 @@ function diffArrays(from, to) {
3608
3623
  // src/portability/MigrationEngine.ts
3609
3624
  var MigrationEngine = class {
3610
3625
  /**
3611
- * Analyse and migrate vocabulary differences between source and target.
3626
+ * Analyze and migrate vocabulary differences between source and target.
3612
3627
  *
3613
3628
  * @param sourceVocabulary - vocabulary from the export archive
3614
3629
  * @param targetVocabulary - vocabulary in the target repository
@@ -4048,7 +4063,7 @@ var DeepMemory = class {
4048
4063
  graphTraversalProvider;
4049
4064
  provenance;
4050
4065
  globalEventBus;
4051
- initialised = false;
4066
+ initialized = false;
4052
4067
  constructor(config) {
4053
4068
  this.storage = config.storage;
4054
4069
  this.search = config.search;
@@ -4058,16 +4073,16 @@ var DeepMemory = class {
4058
4073
  this.provenance = new ProvenanceTracker(config.provenance);
4059
4074
  this.globalEventBus = new EventBus(config.provenance);
4060
4075
  }
4061
- /** Initialise the storage provider and optional providers (call once before use) */
4062
- async ensureInitialised() {
4063
- if (!this.initialised) {
4064
- if (this.storage.initialise) {
4065
- await this.storage.initialise();
4076
+ /** Initialize the storage provider and optional providers (call once before use) */
4077
+ async ensureInitialized() {
4078
+ if (!this.initialized) {
4079
+ if (this.storage.initialize) {
4080
+ await this.storage.initialize();
4066
4081
  }
4067
- if (this.graphTraversalProvider?.initialise) {
4068
- await this.graphTraversalProvider.initialise();
4082
+ if (this.graphTraversalProvider?.initialize) {
4083
+ await this.graphTraversalProvider.initialize();
4069
4084
  }
4070
- this.initialised = true;
4085
+ this.initialized = true;
4071
4086
  }
4072
4087
  }
4073
4088
  /** Create or migrate the storage schema. Call once at deployment / startup, not per-request. */
@@ -4079,15 +4094,15 @@ var DeepMemory = class {
4079
4094
  schemaVersion: 0
4080
4095
  };
4081
4096
  try {
4082
- await this.ensureInitialised();
4097
+ await this.ensureInitialized();
4083
4098
  } catch {
4084
4099
  }
4085
4100
  let result = noOpResult;
4086
4101
  if (this.storage.ensureSchema) {
4087
4102
  result = await this.storage.ensureSchema();
4088
4103
  }
4089
- if (!this.initialised) {
4090
- await this.ensureInitialised();
4104
+ if (!this.initialized) {
4105
+ await this.ensureInitialized();
4091
4106
  }
4092
4107
  return result;
4093
4108
  }
@@ -4102,7 +4117,7 @@ var DeepMemory = class {
4102
4117
  }
4103
4118
  /** Create a new memory repository */
4104
4119
  async createRepository(config) {
4105
- await this.ensureInitialised();
4120
+ await this.ensureInitialized();
4106
4121
  const repositoryId = config.repositoryId ?? generateId();
4107
4122
  this.validateRepositoryId(repositoryId);
4108
4123
  const context = this.provenance.getContext();
@@ -4159,7 +4174,7 @@ var DeepMemory = class {
4159
4174
  }
4160
4175
  /** Open an existing repository */
4161
4176
  async openRepository(repositoryId) {
4162
- await this.ensureInitialised();
4177
+ await this.ensureInitialized();
4163
4178
  this.validateRepositoryId(repositoryId);
4164
4179
  const storedRepo = await this.storage.getRepository(repositoryId);
4165
4180
  if (!storedRepo) {
@@ -4188,7 +4203,7 @@ var DeepMemory = class {
4188
4203
  }
4189
4204
  /** List all repositories */
4190
4205
  async listRepositories(filter) {
4191
- await this.ensureInitialised();
4206
+ await this.ensureInitialized();
4192
4207
  const result = await this.storage.listRepositories(filter);
4193
4208
  return {
4194
4209
  items: result.items.map((stored) => ({
@@ -4206,7 +4221,7 @@ var DeepMemory = class {
4206
4221
  }
4207
4222
  /** Update repository metadata and settings */
4208
4223
  async updateRepository(repositoryId, updates) {
4209
- await this.ensureInitialised();
4224
+ await this.ensureInitialized();
4210
4225
  this.validateRepositoryId(repositoryId);
4211
4226
  const updated = await this.storage.updateRepository(repositoryId, updates);
4212
4227
  await this.globalEventBus.emit("repository:updated", { repositoryId });
@@ -4214,7 +4229,7 @@ var DeepMemory = class {
4214
4229
  }
4215
4230
  /** Delete a repository */
4216
4231
  async deleteRepository(repositoryId) {
4217
- await this.ensureInitialised();
4232
+ await this.ensureInitialized();
4218
4233
  this.validateRepositoryId(repositoryId);
4219
4234
  const stats = await this.storage.getRepositoryStats(repositoryId);
4220
4235
  await this.globalEventBus.emit("delete:started", {
@@ -4235,7 +4250,7 @@ var DeepMemory = class {
4235
4250
  }
4236
4251
  /** Delete all entities and relationships in a repository, preserving the repository and vocabulary */
4237
4252
  async deleteAllContents(repositoryId) {
4238
- await this.ensureInitialised();
4253
+ await this.ensureInitialized();
4239
4254
  this.validateRepositoryId(repositoryId);
4240
4255
  const stats = await this.storage.getRepositoryStats(repositoryId);
4241
4256
  await this.globalEventBus.emit("delete:started", {
@@ -4256,7 +4271,7 @@ var DeepMemory = class {
4256
4271
  }
4257
4272
  /** Export a repository to a portable archive */
4258
4273
  async exportRepository(repositoryId, options) {
4259
- await this.ensureInitialised();
4274
+ await this.ensureInitialized();
4260
4275
  const stats = await this.storage.getRepositoryStats(repositoryId);
4261
4276
  await this.globalEventBus.emit("export:started", {
4262
4277
  repositoryId,
@@ -4278,7 +4293,7 @@ var DeepMemory = class {
4278
4293
  }
4279
4294
  /** Import a repository from a portable archive */
4280
4295
  async importRepository(archive, options) {
4281
- await this.ensureInitialised();
4296
+ await this.ensureInitialized();
4282
4297
  await this.globalEventBus.emit("import:started", { repositoryId: options.target.repositoryId });
4283
4298
  const importer = new RepositoryImporter({
4284
4299
  storage: this.storage,
@@ -4306,7 +4321,7 @@ var DeepMemory = class {
4306
4321
  * Use for large repositories to avoid loading everything into memory.
4307
4322
  */
4308
4323
  async *exportRepositoryStream(repositoryId, options) {
4309
- await this.ensureInitialised();
4324
+ await this.ensureInitialized();
4310
4325
  const exporter = new RepositoryExporter({
4311
4326
  storage: this.storage,
4312
4327
  provenance: this.provenance.getContext(),
@@ -4363,7 +4378,7 @@ var DeepMemory = class {
4363
4378
  * Use for large repositories to avoid loading everything into memory.
4364
4379
  */
4365
4380
  async importRepositoryStream(header, chunks, options) {
4366
- await this.ensureInitialised();
4381
+ await this.ensureInitialized();
4367
4382
  const importer = new RepositoryImporter({
4368
4383
  storage: this.storage,
4369
4384
  actorId: this.provenance.getContext().actorId,
@@ -4403,7 +4418,7 @@ var DeepMemory = class {
4403
4418
  if (this.storage.dispose) {
4404
4419
  await this.storage.dispose();
4405
4420
  }
4406
- this.initialised = false;
4421
+ this.initialized = false;
4407
4422
  }
4408
4423
  };
4409
4424
 
@@ -4418,7 +4433,7 @@ var InMemoryStorageProvider = class {
4418
4433
  return store;
4419
4434
  }
4420
4435
  // ─── Lifecycle ─────────────────────────────────────────────────────
4421
- async initialise() {
4436
+ async initialize() {
4422
4437
  }
4423
4438
  async dispose() {
4424
4439
  this.stores.clear();
@@ -4735,7 +4750,7 @@ var InMemoryStorageProvider = class {
4735
4750
  return { deletedRelationships };
4736
4751
  }
4737
4752
  // ─── Graph Traversal ───────────────────────────────────────────────
4738
- async exploreNeighbourhood(repositoryId, entityId, options) {
4753
+ async exploreNeighborhood(repositoryId, entityId, options) {
4739
4754
  const store = this.getStore(repositoryId);
4740
4755
  if (!store.entities.has(entityId)) {
4741
4756
  throw new EntityNotFoundError(entityId);
@@ -4801,7 +4816,7 @@ var InMemoryStorageProvider = class {
4801
4816
  if (nextFrontier.size === 0) break;
4802
4817
  }
4803
4818
  return {
4804
- centreId: entityId,
4819
+ centerId: entityId,
4805
4820
  layers
4806
4821
  };
4807
4822
  }