Skip to content

Commit 8181faa

Browse files
authored
add Graph.deleteEntity (#151)
1 parent 16c1e16 commit 8181faa

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

.changeset/brave-flies-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphprotocol/grc-20": patch
3+
---
4+
5+
Add Graph.deleteEntity to delete entities

.claude/settings.local.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"permissions": {
3-
"allow": ["Bash(pnpm build:*)", "Bash(pnpm test:*)", "Bash(pnpm lint:*)", "Bash(pnpm lint:fix:*)"]
3+
"allow": [
4+
"Bash(pnpm build:*)",
5+
"Bash(pnpm test:*)",
6+
"Bash(pnpm lint:*)",
7+
"Bash(pnpm lint:fix:*)",
8+
"Bash(ls:*)",
9+
"Bash(grep:*)"
10+
]
411
}
512
}

src/graph/delete-entity.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { Id } from '../id.js';
3+
import { toGrcId } from '../id-utils.js';
4+
import { deleteEntity } from './delete-entity.js';
5+
6+
describe('deleteEntity', () => {
7+
it('should create a delete entity operation with valid ID', () => {
8+
const id = Id('5cade5757ecd41ae83481b22ffc2f94e');
9+
const result = deleteEntity({ id });
10+
11+
expect(result.id).toBe(id);
12+
expect(result.ops).toHaveLength(1);
13+
expect(result.ops[0]).toMatchObject({
14+
type: 'deleteEntity',
15+
id: toGrcId(id),
16+
});
17+
});
18+
19+
it('should throw an error when ID validation fails', () => {
20+
const id = 'invalid-id';
21+
22+
expect(() => deleteEntity({ id })).toThrow('Invalid id: "invalid-id"');
23+
});
24+
});

src/graph/delete-entity.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { deleteEntity as grcDeleteEntity } from '@geoprotocol/grc-20';
2+
import { Id } from '../id.js';
3+
import { assertValid, toGrcId } from '../id-utils.js';
4+
import type { CreateResult, DeleteEntityParams } from '../types.js';
5+
6+
/**
7+
* Deletes an entity.
8+
*
9+
* @example
10+
* ```ts
11+
* const { ops } = deleteEntity({ id: entityId });
12+
* ```
13+
*
14+
* @param params – {@link DeleteEntityParams}
15+
* @returns The operations to delete the entity.
16+
*/
17+
export const deleteEntity = ({ id }: DeleteEntityParams): CreateResult => {
18+
assertValid(id, '`id` in `deleteEntity`');
19+
20+
return { id: Id(id), ops: [grcDeleteEntity(toGrcId(id))] };
21+
};

src/graph/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from './create-property.js';
1212
export * from './create-relation.js';
1313
export * from './create-space.js';
1414
export * from './create-type.js';
15+
export * from './delete-entity.js';
1516
export * from './delete-relation.js';
1617
export * from './update-entity.js';
1718
export * from './update-relation.js';

0 commit comments

Comments
 (0)