Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-flies-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphprotocol/grc-20": patch
---

Add Graph.deleteEntity to delete entities
9 changes: 8 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"permissions": {
"allow": ["Bash(pnpm build:*)", "Bash(pnpm test:*)", "Bash(pnpm lint:*)", "Bash(pnpm lint:fix:*)"]
"allow": [
"Bash(pnpm build:*)",
"Bash(pnpm test:*)",
"Bash(pnpm lint:*)",
"Bash(pnpm lint:fix:*)",
"Bash(ls:*)",
"Bash(grep:*)"
]
}
}
24 changes: 24 additions & 0 deletions src/graph/delete-entity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { Id } from '../id.js';
import { toGrcId } from '../id-utils.js';
import { deleteEntity } from './delete-entity.js';

describe('deleteEntity', () => {
it('should create a delete entity operation with valid ID', () => {
const id = Id('5cade5757ecd41ae83481b22ffc2f94e');
const result = deleteEntity({ id });

expect(result.id).toBe(id);
expect(result.ops).toHaveLength(1);
expect(result.ops[0]).toMatchObject({
type: 'deleteEntity',
id: toGrcId(id),
});
});

it('should throw an error when ID validation fails', () => {
const id = 'invalid-id';

expect(() => deleteEntity({ id })).toThrow('Invalid id: "invalid-id"');
});
});
21 changes: 21 additions & 0 deletions src/graph/delete-entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { deleteEntity as grcDeleteEntity } from '@geoprotocol/grc-20';
import { Id } from '../id.js';
import { assertValid, toGrcId } from '../id-utils.js';
import type { CreateResult, DeleteEntityParams } from '../types.js';

/**
* Deletes an entity.
*
* @example
* ```ts
* const { ops } = deleteEntity({ id: entityId });
* ```
*
* @param params – {@link DeleteEntityParams}
* @returns The operations to delete the entity.
*/
export const deleteEntity = ({ id }: DeleteEntityParams): CreateResult => {
assertValid(id, '`id` in `deleteEntity`');

return { id: Id(id), ops: [grcDeleteEntity(toGrcId(id))] };
};
1 change: 1 addition & 0 deletions src/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './create-property.js';
export * from './create-relation.js';
export * from './create-space.js';
export * from './create-type.js';
export * from './delete-entity.js';
export * from './delete-relation.js';
export * from './update-entity.js';
export * from './update-relation.js';
Loading