delete method

Future<String?> delete(
  1. String id, {
  2. String? scope,
})

Deletes a memory entry by id. With no explicit scope, scans project then user storage. Returns the scope it was deleted from, or null when the id exists in neither.

Implementation

Future<String?> delete(String id, {String? scope}) async {
  await _refreshConfig();
  final candidateScopes = <String>[
    if (scope != null)
      scope
    else ...[
      'project',
      if (_userRoot != null) 'user',
    ],
  ];
  for (final s in candidateScopes) {
    if (s == 'user') {
      await userStore; // no-op when there is no user root
      if (_userStorage == null) continue;
      if (await _kbStoreFor('user', _userStorage!).deleteRecord(id)) {
        return s;
      }
    } else {
      await projectStore;
      if (await _kbStoreFor('project', _projectStorage!).deleteRecord(id)) {
        return s;
      }
    }
  }
  return null;
}