@utaba/deep-memory 0.18.0 → 0.19.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 { au as StorageRepositoryConfig, aB as StoredRepository, ad as RepositoryFilter, T as PaginatedResult, aC as StoredRepositorySummary, ah as RepositoryUpdate, g as DeleteProgressCallback, af as RepositoryStats, O as MemoryVocabulary, U as PaginationOptions, aM as VocabularyChangeRecord, ay as StoredEntity, az as StoredEntityUpdate, an as StorageFindQuery, aA as StoredRelationship, a5 as RelationshipQueryOptions, am as StorageExploreOptions, ao as StorageNeighborhood, as as StoragePathOptions, at as StoragePathResult, aw as StorageTimelineOptions, ax as StorageTimelineResult, s as ExportChunk, J as ImportChunk, B as BulkImportOptions, d as BulkImportResult } from './portability-CAeyzSCx.js';
1
+ import { au as StorageRepositoryConfig, aB as StoredRepository, ad as RepositoryFilter, T as PaginatedResult, aC as StoredRepositorySummary, ah as RepositoryUpdate, g as DeleteProgressCallback, af as RepositoryStats, O as MemoryVocabulary, U as PaginationOptions, aM as VocabularyChangeRecord, ay as StoredEntity, az as StoredEntityUpdate, an as StorageFindQuery, aA as StoredRelationship, a5 as RelationshipQueryOptions, am as StorageExploreOptions, ao as StorageNeighborhood, as as StoragePathOptions, at as StoragePathResult, aw as StorageTimelineOptions, ax as StorageTimelineResult, s as ExportChunk, J as ImportChunk, B as BulkImportOptions, d as BulkImportResult } from './portability-BHyXmv5-.js';
2
2
 
3
3
  /** Result returned by ensureSchema describing what actions were taken. */
4
4
  interface EnsureSchemaResult {
@@ -1,4 +1,4 @@
1
- import { au as StorageRepositoryConfig, aB as StoredRepository, ad as RepositoryFilter, T as PaginatedResult, aC as StoredRepositorySummary, ah as RepositoryUpdate, g as DeleteProgressCallback, af as RepositoryStats, O as MemoryVocabulary, U as PaginationOptions, aM as VocabularyChangeRecord, ay as StoredEntity, az as StoredEntityUpdate, an as StorageFindQuery, aA as StoredRelationship, a5 as RelationshipQueryOptions, am as StorageExploreOptions, ao as StorageNeighborhood, as as StoragePathOptions, at as StoragePathResult, aw as StorageTimelineOptions, ax as StorageTimelineResult, s as ExportChunk, J as ImportChunk, B as BulkImportOptions, d as BulkImportResult } from './portability-CAeyzSCx.cjs';
1
+ import { au as StorageRepositoryConfig, aB as StoredRepository, ad as RepositoryFilter, T as PaginatedResult, aC as StoredRepositorySummary, ah as RepositoryUpdate, g as DeleteProgressCallback, af as RepositoryStats, O as MemoryVocabulary, U as PaginationOptions, aM as VocabularyChangeRecord, ay as StoredEntity, az as StoredEntityUpdate, an as StorageFindQuery, aA as StoredRelationship, a5 as RelationshipQueryOptions, am as StorageExploreOptions, ao as StorageNeighborhood, as as StoragePathOptions, at as StoragePathResult, aw as StorageTimelineOptions, ax as StorageTimelineResult, s as ExportChunk, J as ImportChunk, B as BulkImportOptions, d as BulkImportResult } from './portability-BHyXmv5-.cjs';
2
2
 
3
3
  /** Result returned by ensureSchema describing what actions were taken. */
4
4
  interface EnsureSchemaResult {
package/dist/index.cjs CHANGED
@@ -3657,7 +3657,7 @@ var EventBus = class {
3657
3657
  };
3658
3658
 
3659
3659
  // src/portability/RepositoryExporter.ts
3660
- var LIBRARY_VERSION = true ? "0.18.0" : "0.1.0";
3660
+ var LIBRARY_VERSION = true ? "0.19.0" : "0.1.0";
3661
3661
  var RepositoryExporter = class {
3662
3662
  storage;
3663
3663
  provenance;
@@ -3689,6 +3689,9 @@ var RepositoryExporter = class {
3689
3689
  type: repo.type,
3690
3690
  label: repo.label,
3691
3691
  description: repo.description,
3692
+ legal: repo.legal,
3693
+ owner: repo.owner,
3694
+ metadata: repo.metadata,
3692
3695
  vocabularyVersion: vocabulary.version,
3693
3696
  governanceMode: repo.governanceConfig.mode
3694
3697
  },
@@ -4086,7 +4089,10 @@ var RepositoryImporter = class {
4086
4089
  type: target.config.type,
4087
4090
  label: target.config.label,
4088
4091
  description: target.config.description,
4092
+ legal: target.config.legal,
4093
+ owner: target.config.owner,
4089
4094
  governanceConfig: target.config.governance ?? { mode: "open" },
4095
+ metadata: target.config.metadata,
4090
4096
  createdAt: now,
4091
4097
  createdBy: this.actorId
4092
4098
  });
@@ -4601,6 +4607,7 @@ var DeepMemory = class {
4601
4607
  /** Import a repository from a portable archive */
4602
4608
  async importRepository(archive, options) {
4603
4609
  await this.ensureInitialized();
4610
+ this.validateRepositoryId(options.target.repositoryId);
4604
4611
  await this.globalEventBus.emit("import:started", { repositoryId: options.target.repositoryId });
4605
4612
  const importer = new RepositoryImporter({
4606
4613
  storage: this.storage,
@@ -4701,6 +4708,7 @@ var DeepMemory = class {
4701
4708
  */
4702
4709
  async importRepositoryStream(header, chunks, options) {
4703
4710
  await this.ensureInitialized();
4711
+ this.validateRepositoryId(options.target.repositoryId);
4704
4712
  const importer = new RepositoryImporter({
4705
4713
  storage: this.storage,
4706
4714
  actorId: this.provenance.getContext().actorId,
@@ -4972,12 +4980,16 @@ var GremlinCompiler = class {
4972
4980
  }
4973
4981
  }
4974
4982
  }
4975
- if (returnMode === "terminal" && spec.dedup !== false) {
4983
+ const emitProjection = spec.projection !== void 0 && returnMode === "terminal";
4984
+ if (returnMode === "terminal" && !emitProjection && spec.dedup !== false) {
4976
4985
  parts.push(".dedup()");
4977
4986
  }
4978
4987
  if (returnMode === "path") {
4979
4988
  parts.push(".simplePath()");
4980
4989
  }
4990
+ if (emitProjection) {
4991
+ parts.push(emitProjectionTerminal(spec.projection));
4992
+ }
4981
4993
  const limit = spec.limit ?? 50;
4982
4994
  const offset = spec.offset ?? 0;
4983
4995
  const pOffset = nextParam(offset);
@@ -4985,7 +4997,8 @@ var GremlinCompiler = class {
4985
4997
  parts.push(`.range(${pOffset}, ${pEnd})`);
4986
4998
  params["_limit"] = limit;
4987
4999
  params["_offset"] = offset;
4988
- if (returnMode === "terminal") {
5000
+ if (emitProjection) {
5001
+ } else if (returnMode === "terminal") {
4989
5002
  parts.push(`.${VERTEX_PROJECT_EXPR}`);
4990
5003
  } else {
4991
5004
  parts.push(`.path().by(${VERTEX_PROJECT_EXPR}).by(${EDGE_PROJECT_EXPR})`);
@@ -5081,6 +5094,31 @@ function compileRepeatStep(step, nextParam, useEdgeEmission) {
5081
5094
  }
5082
5095
  return parts.join("");
5083
5096
  }
5097
+ var SAFE_PROJECTION_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
5098
+ function assertSafeProjectionKey(key) {
5099
+ if (!SAFE_PROJECTION_KEY_RE.test(key)) {
5100
+ throw new Error(
5101
+ `Unsafe projection property name: "${key}". Property names must match ${SAFE_PROJECTION_KEY_RE.source}.`
5102
+ );
5103
+ }
5104
+ }
5105
+ function emitProjectionTerminal(projection) {
5106
+ const properties = projection.properties;
5107
+ const mode = projection.mode ?? "values";
5108
+ const distinct = projection.distinct ?? false;
5109
+ for (const prop of properties) {
5110
+ assertSafeProjectionKey(prop);
5111
+ }
5112
+ const singleProperty = properties.length === 1;
5113
+ const keyExpr = singleProperty ? `values('${properties[0]}')` : `project(${properties.map((p) => `'${p}'`).join(",")})${properties.map((p) => `.by(values('${p}'))`).join("")}`;
5114
+ if (mode === "count") {
5115
+ return `.group().by(${keyExpr}).by(count()).unfold()`;
5116
+ }
5117
+ if (distinct) {
5118
+ return `.${keyExpr}.dedup()`;
5119
+ }
5120
+ return `.${keyExpr}`;
5121
+ }
5084
5122
  function compilePropertyFilter(filter, nextParam) {
5085
5123
  const key = nextParam(filter.key);
5086
5124
  switch (filter.operator) {
@@ -5190,17 +5228,35 @@ var CypherCompiler = class {
5190
5228
  }
5191
5229
  lastNode = targetNode;
5192
5230
  }
5193
- const matchClause = `MATCH ${matchParts[0]}${matchParts.slice(1).join("")}`;
5231
+ const bindPath = spec.returnMode === "path";
5232
+ const pathBinding = bindPath ? "p = " : "";
5233
+ const matchClause = `MATCH ${pathBinding}${matchParts[0]}${matchParts.slice(1).join("")}`;
5194
5234
  const whereClause = whereClauses.length > 0 ? `
5195
5235
  WHERE ${whereClauses.join(" AND ")}` : "";
5196
5236
  let returnClause;
5197
- if (spec.returnMode === "path") {
5198
- const allNodes = Array.from({ length: nodeIndex }, (_, i) => `n${i}`);
5199
- const allRels = steps.map((_, i) => `r${i}`);
5200
- returnClause = `RETURN ${[...allNodes, ...allRels].join(", ")}`;
5237
+ const emitProjection = spec.projection !== void 0 && spec.returnMode !== "path" && spec.returnMode !== "all";
5238
+ if (emitProjection) {
5239
+ const projection = spec.projection;
5240
+ const mode = projection.mode ?? "values";
5241
+ const distinct = projection.distinct ?? false;
5242
+ const projectionColumns = projection.properties.map((prop) => {
5243
+ assertSafeProjectionKey2(prop);
5244
+ return `${lastNode}.${prop} AS ${prop}`;
5245
+ });
5246
+ if (mode === "count") {
5247
+ returnClause = `RETURN ${projectionColumns.join(", ")}, count(*) AS count`;
5248
+ } else if (distinct) {
5249
+ returnClause = `RETURN DISTINCT ${projectionColumns.join(", ")}`;
5250
+ } else {
5251
+ returnClause = `RETURN ${projectionColumns.join(", ")}`;
5252
+ }
5253
+ } else if (spec.returnMode === "path") {
5254
+ returnClause = "RETURN nodes(p) AS pathNodes, relationships(p) AS pathRels, length(p) AS pathLength";
5201
5255
  } else if (spec.returnMode === "all") {
5202
5256
  const allNodes = Array.from({ length: nodeIndex }, (_, i) => `n${i}`);
5203
- returnClause = spec.dedup !== false ? `RETURN DISTINCT ${allNodes.join(", ")}` : `RETURN ${allNodes.join(", ")}`;
5257
+ const allRels = steps.map((_, i) => `r${i}`);
5258
+ const projection = [...allNodes, ...allRels].join(", ");
5259
+ returnClause = spec.dedup !== false ? `RETURN DISTINCT ${projection}` : `RETURN ${projection}`;
5204
5260
  } else {
5205
5261
  returnClause = spec.dedup !== false ? `RETURN DISTINCT ${lastNode}` : `RETURN ${lastNode}`;
5206
5262
  }
@@ -5221,6 +5277,14 @@ ${returnClause}${skipClause}${limitClause}`;
5221
5277
  };
5222
5278
  }
5223
5279
  };
5280
+ var SAFE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
5281
+ function assertSafeProjectionKey2(key) {
5282
+ if (!SAFE_KEY_RE.test(key)) {
5283
+ throw new Error(
5284
+ `Unsafe projection property name: "${key}". Property names must match ${SAFE_KEY_RE.source}.`
5285
+ );
5286
+ }
5287
+ }
5224
5288
  function compilePropertyFilterCypher(nodeAlias, filter, nextParam) {
5225
5289
  const prop = `${nodeAlias}.${filter.key}`;
5226
5290
  switch (filter.operator) {
@@ -5625,6 +5689,7 @@ var InMemoryStorageProvider = class {
5625
5689
  for (let depth = 0; depth < options.depth; depth++) {
5626
5690
  const layer = {};
5627
5691
  const nextFrontier = /* @__PURE__ */ new Set();
5692
+ const layerBucketSeen = /* @__PURE__ */ new Map();
5628
5693
  for (const frontierEntityId of currentFrontier) {
5629
5694
  for (const rel of store.relationships.values()) {
5630
5695
  const isSource = rel.sourceEntityId === frontierEntityId;
@@ -5662,6 +5727,13 @@ var InMemoryStorageProvider = class {
5662
5727
  continue;
5663
5728
  }
5664
5729
  const relType = rel.relationshipType;
5730
+ let bucketSeen = layerBucketSeen.get(relType);
5731
+ if (!bucketSeen) {
5732
+ bucketSeen = /* @__PURE__ */ new Set();
5733
+ layerBucketSeen.set(relType, bucketSeen);
5734
+ }
5735
+ if (bucketSeen.has(connectedEntityId)) continue;
5736
+ bucketSeen.add(connectedEntityId);
5665
5737
  if (!layer[relType]) {
5666
5738
  layer[relType] = { total: 0, entities: [], relationships: [] };
5667
5739
  }