@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.cjs
CHANGED
|
@@ -878,18 +878,20 @@ var SqlServerStorageProvider = class {
|
|
|
878
878
|
}
|
|
879
879
|
const updated = {
|
|
880
880
|
...existing,
|
|
881
|
+
entityType: updates.entityType ?? existing.entityType,
|
|
881
882
|
label: updates.label ?? existing.label,
|
|
882
883
|
slug: updates.slug ?? existing.slug,
|
|
883
|
-
summary: updates.summary
|
|
884
|
+
summary: updates.summary === void 0 ? existing.summary : updates.summary ?? void 0,
|
|
884
885
|
properties: updates.properties ?? existing.properties,
|
|
885
|
-
data: updates.data
|
|
886
|
-
dataFormat: updates.dataFormat
|
|
886
|
+
data: updates.data === void 0 ? existing.data : updates.data ?? void 0,
|
|
887
|
+
dataFormat: updates.dataFormat === void 0 ? existing.dataFormat : updates.dataFormat ?? void 0,
|
|
887
888
|
provenance: updates.provenance,
|
|
888
889
|
embedding: updates.embedding ?? existing.embedding
|
|
889
890
|
};
|
|
890
|
-
const req = pool.request().input("repoId", import_mssql.default.UniqueIdentifier, repositoryId).input("entityId", import_mssql.default.NVarChar, entityId).input("slug", import_mssql.default.NVarChar, updated.slug).input("label", import_mssql.default.NVarChar, updated.label).input("summary", import_mssql.default.NVarChar, updated.summary ?? null).input("properties", import_mssql.default.NVarChar, JSON.stringify(updated.properties)).input("data", import_mssql.default.NVarChar, updated.data ?? null).input("dataFormat", import_mssql.default.NVarChar, updated.dataFormat ?? null).input("embedding", import_mssql.default.NVarChar, updated.embedding ? JSON.stringify(updated.embedding) : null).input("modifiedBy", import_mssql.default.NVarChar, updates.provenance.modifiedBy).input("modifiedByType", import_mssql.default.NVarChar, updates.provenance.modifiedByType).input("modifiedAt", import_mssql.default.NVarChar, updates.provenance.modifiedAt).input("modifiedInConversation", import_mssql.default.NVarChar, updates.provenance.modifiedInConversation ?? null).input("modifiedFromMessage", import_mssql.default.NVarChar, updates.provenance.modifiedFromMessage ?? null);
|
|
891
|
+
const req = pool.request().input("repoId", import_mssql.default.UniqueIdentifier, repositoryId).input("entityId", import_mssql.default.NVarChar, entityId).input("entityType", import_mssql.default.NVarChar, updated.entityType).input("slug", import_mssql.default.NVarChar, updated.slug).input("label", import_mssql.default.NVarChar, updated.label).input("summary", import_mssql.default.NVarChar, updated.summary ?? null).input("properties", import_mssql.default.NVarChar, JSON.stringify(updated.properties)).input("data", import_mssql.default.NVarChar, updated.data ?? null).input("dataFormat", import_mssql.default.NVarChar, updated.dataFormat ?? null).input("embedding", import_mssql.default.NVarChar, updated.embedding ? JSON.stringify(updated.embedding) : null).input("modifiedBy", import_mssql.default.NVarChar, updates.provenance.modifiedBy).input("modifiedByType", import_mssql.default.NVarChar, updates.provenance.modifiedByType).input("modifiedAt", import_mssql.default.NVarChar, updates.provenance.modifiedAt).input("modifiedInConversation", import_mssql.default.NVarChar, updates.provenance.modifiedInConversation ?? null).input("modifiedFromMessage", import_mssql.default.NVarChar, updates.provenance.modifiedFromMessage ?? null);
|
|
891
892
|
await req.query(`
|
|
892
893
|
UPDATE ${this.t("dm_entities")} SET
|
|
894
|
+
[entity_type] = @entityType,
|
|
893
895
|
[slug] = @slug,
|
|
894
896
|
[label] = @label,
|
|
895
897
|
[summary] = @summary,
|
|
@@ -923,6 +925,28 @@ var SqlServerStorageProvider = class {
|
|
|
923
925
|
throw new import_deep_memory.EntityNotFoundError(entityId);
|
|
924
926
|
}
|
|
925
927
|
}
|
|
928
|
+
async deleteEntities(repositoryId, ids) {
|
|
929
|
+
if (ids.length === 0) return { deleted: [], notFound: [] };
|
|
930
|
+
const pool = this.getPool();
|
|
931
|
+
const tvp1 = this.createIdListTvp(ids);
|
|
932
|
+
const cascadeReq = pool.request().input("repoId", import_mssql.default.UniqueIdentifier, repositoryId).input("entityIds", tvp1);
|
|
933
|
+
await cascadeReq.query(`
|
|
934
|
+
DELETE FROM ${this.t("dm_relationships")}
|
|
935
|
+
WHERE [repository_id] = @repoId AND [source_entity_id] IN (SELECT [id] FROM @entityIds);
|
|
936
|
+
DELETE FROM ${this.t("dm_relationships")}
|
|
937
|
+
WHERE [repository_id] = @repoId AND [target_entity_id] IN (SELECT [id] FROM @entityIds);
|
|
938
|
+
`);
|
|
939
|
+
const tvp2 = this.createIdListTvp(ids);
|
|
940
|
+
const result = await pool.request().input("repoId", import_mssql.default.UniqueIdentifier, repositoryId).input("entityIds", tvp2).query(
|
|
941
|
+
`DELETE FROM ${this.t("dm_entities")}
|
|
942
|
+
OUTPUT DELETED.[entity_id]
|
|
943
|
+
WHERE [repository_id] = @repoId
|
|
944
|
+
AND [entity_id] IN (SELECT [id] FROM @entityIds)`
|
|
945
|
+
);
|
|
946
|
+
const deleted = result.recordset.map((row) => row.entity_id);
|
|
947
|
+
const deletedSet = new Set(deleted);
|
|
948
|
+
return { deleted, notFound: ids.filter((id) => !deletedSet.has(id)) };
|
|
949
|
+
}
|
|
926
950
|
async deleteEntitiesByType(repositoryId, entityType) {
|
|
927
951
|
await this.assertRepository(repositoryId);
|
|
928
952
|
const pool = this.getPool();
|
|
@@ -1148,6 +1172,20 @@ var SqlServerStorageProvider = class {
|
|
|
1148
1172
|
throw new import_deep_memory.RelationshipNotFoundError(relationshipId);
|
|
1149
1173
|
}
|
|
1150
1174
|
}
|
|
1175
|
+
async deleteRelationships(repositoryId, ids) {
|
|
1176
|
+
if (ids.length === 0) return { deleted: [], notFound: [] };
|
|
1177
|
+
const pool = this.getPool();
|
|
1178
|
+
const tvp = this.createIdListTvp(ids);
|
|
1179
|
+
const result = await pool.request().input("repoId", import_mssql.default.UniqueIdentifier, repositoryId).input("relIds", tvp).query(
|
|
1180
|
+
`DELETE FROM ${this.t("dm_relationships")}
|
|
1181
|
+
OUTPUT DELETED.[relationship_id]
|
|
1182
|
+
WHERE [repository_id] = @repoId
|
|
1183
|
+
AND [relationship_id] IN (SELECT [id] FROM @relIds)`
|
|
1184
|
+
);
|
|
1185
|
+
const deleted = result.recordset.map((row) => row.relationship_id);
|
|
1186
|
+
const deletedSet = new Set(deleted);
|
|
1187
|
+
return { deleted, notFound: ids.filter((id) => !deletedSet.has(id)) };
|
|
1188
|
+
}
|
|
1151
1189
|
async deleteRelationshipsByType(repositoryId, relationshipType) {
|
|
1152
1190
|
await this.assertRepository(repositoryId);
|
|
1153
1191
|
const pool = this.getPool();
|