-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathuse-entities.tsx
More file actions
49 lines (45 loc) · 1.67 KB
/
Copy pathuse-entities.tsx
File metadata and controls
49 lines (45 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { Entity } from '@graphprotocol/hypergraph';
import type * as Schema from 'effect/Schema';
import { useEntitiesPrivate } from '../internal/use-entities-private.js';
import { useEntitiesPublic } from '../internal/use-entities-public.js';
type UseEntitiesParams<S extends Schema.Schema.AnyNoContext> = {
mode: 'public' | 'private';
filter?: Entity.EntityFilter<Schema.Schema.Type<S>> | undefined;
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
space?: string | undefined;
first?: number | undefined;
offset?: number | undefined;
orderBy?:
| {
property: keyof Schema.Schema.Type<S>;
direction: 'asc' | 'desc';
}
| undefined;
backlinksTotalCountsTypeId1?: string | undefined;
};
export function useEntities<const S extends Schema.Schema.AnyNoContext>(type: S, params: UseEntitiesParams<S>) {
const { mode, filter, include, space, first, offset, orderBy, backlinksTotalCountsTypeId1 } = params;
const publicResult = useEntitiesPublic(type, {
enabled: mode === 'public',
filter,
include,
first,
offset,
space,
orderBy,
backlinksTotalCountsTypeId1,
});
const localResult = useEntitiesPrivate(type, { enabled: mode === 'private', filter, include, space });
if (mode === 'public') {
return {
...publicResult,
deleted: [],
};
}
return {
...publicResult,
data: localResult.entities as (Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number })[],
deleted: localResult.deletedEntities,
};
}