@utaba/deep-memory-storage-sqlserver 0.5.0 → 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 +42 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +42 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -48,6 +48,10 @@ declare class SqlServerStorageProvider implements StorageProvider {
|
|
|
48
48
|
getEntities(repositoryId: string, entityIds: string[]): Promise<Map<string, StoredEntity>>;
|
|
49
49
|
updateEntity(repositoryId: string, entityId: string, updates: StoredEntityUpdate): Promise<StoredEntity>;
|
|
50
50
|
deleteEntity(repositoryId: string, entityId: string): Promise<void>;
|
|
51
|
+
deleteEntities(repositoryId: string, ids: string[]): Promise<{
|
|
52
|
+
deleted: string[];
|
|
53
|
+
notFound: string[];
|
|
54
|
+
}>;
|
|
51
55
|
deleteEntitiesByType(repositoryId: string, entityType: string): Promise<{
|
|
52
56
|
deletedEntities: number;
|
|
53
57
|
deletedRelationships: number;
|
|
@@ -62,6 +66,10 @@ declare class SqlServerStorageProvider implements StorageProvider {
|
|
|
62
66
|
*/
|
|
63
67
|
private buildRelationshipUnion;
|
|
64
68
|
deleteRelationship(repositoryId: string, relationshipId: string): Promise<void>;
|
|
69
|
+
deleteRelationships(repositoryId: string, ids: string[]): Promise<{
|
|
70
|
+
deleted: string[];
|
|
71
|
+
notFound: string[];
|
|
72
|
+
}>;
|
|
65
73
|
deleteRelationshipsByType(repositoryId: string, relationshipType: string): Promise<{
|
|
66
74
|
deletedRelationships: number;
|
|
67
75
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ declare class SqlServerStorageProvider implements StorageProvider {
|
|
|
48
48
|
getEntities(repositoryId: string, entityIds: string[]): Promise<Map<string, StoredEntity>>;
|
|
49
49
|
updateEntity(repositoryId: string, entityId: string, updates: StoredEntityUpdate): Promise<StoredEntity>;
|
|
50
50
|
deleteEntity(repositoryId: string, entityId: string): Promise<void>;
|
|
51
|
+
deleteEntities(repositoryId: string, ids: string[]): Promise<{
|
|
52
|
+
deleted: string[];
|
|
53
|
+
notFound: string[];
|
|
54
|
+
}>;
|
|
51
55
|
deleteEntitiesByType(repositoryId: string, entityType: string): Promise<{
|
|
52
56
|
deletedEntities: number;
|
|
53
57
|
deletedRelationships: number;
|
|
@@ -62,6 +66,10 @@ declare class SqlServerStorageProvider implements StorageProvider {
|
|
|
62
66
|
*/
|
|
63
67
|
private buildRelationshipUnion;
|
|
64
68
|
deleteRelationship(repositoryId: string, relationshipId: string): Promise<void>;
|
|
69
|
+
deleteRelationships(repositoryId: string, ids: string[]): Promise<{
|
|
70
|
+
deleted: string[];
|
|
71
|
+
notFound: string[];
|
|
72
|
+
}>;
|
|
65
73
|
deleteRelationshipsByType(repositoryId: string, relationshipType: string): Promise<{
|
|
66
74
|
deletedRelationships: number;
|
|
67
75
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -847,18 +847,20 @@ var SqlServerStorageProvider = class {
|
|
|
847
847
|
}
|
|
848
848
|
const updated = {
|
|
849
849
|
...existing,
|
|
850
|
+
entityType: updates.entityType ?? existing.entityType,
|
|
850
851
|
label: updates.label ?? existing.label,
|
|
851
852
|
slug: updates.slug ?? existing.slug,
|
|
852
|
-
summary: updates.summary
|
|
853
|
+
summary: updates.summary === void 0 ? existing.summary : updates.summary ?? void 0,
|
|
853
854
|
properties: updates.properties ?? existing.properties,
|
|
854
|
-
data: updates.data
|
|
855
|
-
dataFormat: updates.dataFormat
|
|
855
|
+
data: updates.data === void 0 ? existing.data : updates.data ?? void 0,
|
|
856
|
+
dataFormat: updates.dataFormat === void 0 ? existing.dataFormat : updates.dataFormat ?? void 0,
|
|
856
857
|
provenance: updates.provenance,
|
|
857
858
|
embedding: updates.embedding ?? existing.embedding
|
|
858
859
|
};
|
|
859
|
-
const req = pool.request().input("repoId", sql.UniqueIdentifier, repositoryId).input("entityId", sql.NVarChar, entityId).input("slug", sql.NVarChar, updated.slug).input("label", sql.NVarChar, updated.label).input("summary", sql.NVarChar, updated.summary ?? null).input("properties", sql.NVarChar, JSON.stringify(updated.properties)).input("data", sql.NVarChar, updated.data ?? null).input("dataFormat", sql.NVarChar, updated.dataFormat ?? null).input("embedding", sql.NVarChar, updated.embedding ? JSON.stringify(updated.embedding) : null).input("modifiedBy", sql.NVarChar, updates.provenance.modifiedBy).input("modifiedByType", sql.NVarChar, updates.provenance.modifiedByType).input("modifiedAt", sql.NVarChar, updates.provenance.modifiedAt).input("modifiedInConversation", sql.NVarChar, updates.provenance.modifiedInConversation ?? null).input("modifiedFromMessage", sql.NVarChar, updates.provenance.modifiedFromMessage ?? null);
|
|
860
|
+
const req = pool.request().input("repoId", sql.UniqueIdentifier, repositoryId).input("entityId", sql.NVarChar, entityId).input("entityType", sql.NVarChar, updated.entityType).input("slug", sql.NVarChar, updated.slug).input("label", sql.NVarChar, updated.label).input("summary", sql.NVarChar, updated.summary ?? null).input("properties", sql.NVarChar, JSON.stringify(updated.properties)).input("data", sql.NVarChar, updated.data ?? null).input("dataFormat", sql.NVarChar, updated.dataFormat ?? null).input("embedding", sql.NVarChar, updated.embedding ? JSON.stringify(updated.embedding) : null).input("modifiedBy", sql.NVarChar, updates.provenance.modifiedBy).input("modifiedByType", sql.NVarChar, updates.provenance.modifiedByType).input("modifiedAt", sql.NVarChar, updates.provenance.modifiedAt).input("modifiedInConversation", sql.NVarChar, updates.provenance.modifiedInConversation ?? null).input("modifiedFromMessage", sql.NVarChar, updates.provenance.modifiedFromMessage ?? null);
|
|
860
861
|
await req.query(`
|
|
861
862
|
UPDATE ${this.t("dm_entities")} SET
|
|
863
|
+
[entity_type] = @entityType,
|
|
862
864
|
[slug] = @slug,
|
|
863
865
|
[label] = @label,
|
|
864
866
|
[summary] = @summary,
|
|
@@ -892,6 +894,28 @@ var SqlServerStorageProvider = class {
|
|
|
892
894
|
throw new EntityNotFoundError(entityId);
|
|
893
895
|
}
|
|
894
896
|
}
|
|
897
|
+
async deleteEntities(repositoryId, ids) {
|
|
898
|
+
if (ids.length === 0) return { deleted: [], notFound: [] };
|
|
899
|
+
const pool = this.getPool();
|
|
900
|
+
const tvp1 = this.createIdListTvp(ids);
|
|
901
|
+
const cascadeReq = pool.request().input("repoId", sql.UniqueIdentifier, repositoryId).input("entityIds", tvp1);
|
|
902
|
+
await cascadeReq.query(`
|
|
903
|
+
DELETE FROM ${this.t("dm_relationships")}
|
|
904
|
+
WHERE [repository_id] = @repoId AND [source_entity_id] IN (SELECT [id] FROM @entityIds);
|
|
905
|
+
DELETE FROM ${this.t("dm_relationships")}
|
|
906
|
+
WHERE [repository_id] = @repoId AND [target_entity_id] IN (SELECT [id] FROM @entityIds);
|
|
907
|
+
`);
|
|
908
|
+
const tvp2 = this.createIdListTvp(ids);
|
|
909
|
+
const result = await pool.request().input("repoId", sql.UniqueIdentifier, repositoryId).input("entityIds", tvp2).query(
|
|
910
|
+
`DELETE FROM ${this.t("dm_entities")}
|
|
911
|
+
OUTPUT DELETED.[entity_id]
|
|
912
|
+
WHERE [repository_id] = @repoId
|
|
913
|
+
AND [entity_id] IN (SELECT [id] FROM @entityIds)`
|
|
914
|
+
);
|
|
915
|
+
const deleted = result.recordset.map((row) => row.entity_id);
|
|
916
|
+
const deletedSet = new Set(deleted);
|
|
917
|
+
return { deleted, notFound: ids.filter((id) => !deletedSet.has(id)) };
|
|
918
|
+
}
|
|
895
919
|
async deleteEntitiesByType(repositoryId, entityType) {
|
|
896
920
|
await this.assertRepository(repositoryId);
|
|
897
921
|
const pool = this.getPool();
|
|
@@ -1117,6 +1141,20 @@ var SqlServerStorageProvider = class {
|
|
|
1117
1141
|
throw new RelationshipNotFoundError(relationshipId);
|
|
1118
1142
|
}
|
|
1119
1143
|
}
|
|
1144
|
+
async deleteRelationships(repositoryId, ids) {
|
|
1145
|
+
if (ids.length === 0) return { deleted: [], notFound: [] };
|
|
1146
|
+
const pool = this.getPool();
|
|
1147
|
+
const tvp = this.createIdListTvp(ids);
|
|
1148
|
+
const result = await pool.request().input("repoId", sql.UniqueIdentifier, repositoryId).input("relIds", tvp).query(
|
|
1149
|
+
`DELETE FROM ${this.t("dm_relationships")}
|
|
1150
|
+
OUTPUT DELETED.[relationship_id]
|
|
1151
|
+
WHERE [repository_id] = @repoId
|
|
1152
|
+
AND [relationship_id] IN (SELECT [id] FROM @relIds)`
|
|
1153
|
+
);
|
|
1154
|
+
const deleted = result.recordset.map((row) => row.relationship_id);
|
|
1155
|
+
const deletedSet = new Set(deleted);
|
|
1156
|
+
return { deleted, notFound: ids.filter((id) => !deletedSet.has(id)) };
|
|
1157
|
+
}
|
|
1120
1158
|
async deleteRelationshipsByType(repositoryId, relationshipType) {
|
|
1121
1159
|
await this.assertRepository(repositoryId);
|
|
1122
1160
|
const pool = this.getPool();
|