Skip to content

Commit 9dae7f1

Browse files
authored
Merge pull request #3420 from SeedCompany/no-resources-check
2 parents a3d88c7 + 24a606a commit 9dae7f1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/common/resource.dto.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,20 @@ export class EnhancedResource<T extends ResourceShape<any>> {
161161
}
162162

163163
/**
164-
* An semi-ordered set of interfaces the resource.
164+
* A semi-ordered set of interfaces the resource.
165165
*/
166166
@Once()
167167
get interfaces(): ReadonlySet<EnhancedResource<any>> {
168168
return new Set(
169-
getParentTypes(this.type)
170-
.slice(1) // not self
171-
.filter(isResourceClass)
169+
getParentTypes(this.type, [])
170+
.filter(
171+
(cls): cls is ResourceShape<any> =>
172+
// Is declared as interface. i.e. avoids DataObject.
173+
GqlClassType.get(cls) === 'interface' &&
174+
// Avoid intersected classes.
175+
// getParentTypes will give us the intersect-ees directly.
176+
!cls.name.startsWith('Intersection'),
177+
)
172178
.map(EnhancedResource.of),
173179
);
174180
}
@@ -246,8 +252,9 @@ export class EnhancedResource<T extends ResourceShape<any>> {
246252
const type: ResourceShape<any> | undefined = list
247253
? rawType[0]!
248254
: rawType;
249-
const resource: EnhancedResource<any> | undefined =
250-
type && isResourceClass(type) ? EnhancedResource.of(type) : undefined;
255+
const resource: EnhancedResource<any> | undefined = type?.prototype
256+
? EnhancedResource.of(type)
257+
: undefined;
251258
const rel: EnhancedRelation<T> = { name, list, type, resource };
252259
return [name, rel];
253260
}),
@@ -330,11 +337,6 @@ export interface EnhancedRelation<TResourceStatic extends ResourceShape<any>> {
330337
readonly resource?: EnhancedResource<any>;
331338
}
332339

333-
export const isResourceClass = <T>(
334-
cls: AbstractClassType<T>,
335-
): cls is ResourceShape<T> =>
336-
'Props' in cls && Array.isArray(cls.Props) && cls.Props.length > 0;
337-
338340
export type DBType<TResourceStatic extends ResourceShape<any>> =
339341
ResourceShape<any> extends TResourceStatic
340342
? typeof e.Resource // short-circuit non-specific types

0 commit comments

Comments
 (0)