@@ -10,7 +10,6 @@ import {
10
10
import { createMetadataDecorator } from '@seedcompany/nest' ;
11
11
import { LazyGetter as Once } from 'lazy-get-decorator' ;
12
12
import { DateTime } from 'luxon' ;
13
- import { keys as keysOf } from 'ts-transformer-keys' ;
14
13
import type {
15
14
ResourceDBMap ,
16
15
ResourceLike ,
@@ -53,9 +52,6 @@ export const resolveByTypename =
53
52
} )
54
53
@DbLabel ( 'BaseNode' )
55
54
export abstract class Resource extends DataObject {
56
- static readonly Props : string [ ] = keysOf < Resource > ( ) ;
57
- static readonly SecuredProps : string [ ] = [ ] ;
58
-
59
55
readonly __typename ?: string ;
60
56
61
57
@IdField ( )
@@ -77,8 +73,8 @@ export abstract class Resource extends DataObject {
77
73
type Thunk < T > = T | ( ( ) => T ) ;
78
74
79
75
export type ResourceShape < T > = AbstractClassType < T > & {
80
- Props : string [ ] ;
81
- SecuredProps : string [ ] ;
76
+ Props ? : string [ ] ;
77
+ SecuredProps ? : string [ ] ;
82
78
// An optional list of props that exist on the BaseNode in the DB.
83
79
// Default should probably be considered the props on Resource class.
84
80
BaseNodeProps ?: string [ ] ;
@@ -195,12 +191,24 @@ export class EnhancedResource<T extends ResourceShape<any>> {
195
191
196
192
@Once ( )
197
193
get props ( ) : ReadonlySet < keyof T [ 'prototype' ] & string > {
198
- return new Set < keyof T [ 'prototype' ] & string > ( this . type . Props as any ) ;
194
+ const props = this . type . Props ;
195
+ if ( ! props ) {
196
+ throw new Error (
197
+ `${ this . name } has no props declared.\n\nDecorate with @RegisterResource or a GraphQL type decorator and move it to a file named: *.dto.ts.` ,
198
+ ) ;
199
+ }
200
+ return new Set < keyof T [ 'prototype' ] & string > ( props ) ;
199
201
}
200
202
201
203
@Once ( )
202
204
get securedProps ( ) : ReadonlySet < SecuredResourceKey < T , false > > {
203
- return new Set < SecuredResourceKey < T , false > > ( this . type . SecuredProps as any ) ;
205
+ const props = this . type . SecuredProps ;
206
+ if ( ! props ) {
207
+ throw new Error (
208
+ `${ this . name } has no props declared.\n\nDecorate with @RegisterResource or a GraphQL type decorator and move it to a file named: *.dto.ts.` ,
209
+ ) ;
210
+ }
211
+ return new Set < SecuredResourceKey < T , false > > ( props as any ) ;
204
212
}
205
213
206
214
@Once ( )
0 commit comments