Skip to content

Commit a0526e7

Browse files
authored
Merge pull request #3411 from SeedCompany/ts-plugin-resources
2 parents e4902e5 + 16e99d1 commit a0526e7

File tree

65 files changed

+188
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+188
-388
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
"ts-morph": "^25.0.1",
145145
"ts-node": "^10.9.1",
146146
"ts-patch": "^3.0.2",
147-
"ts-transformer-keys": "^0.4.4",
148147
"type-fest": "^4.15.0",
149148
"typescript": "~5.8.3",
150149
"typescript-transform-paths": "^3.4.6"

src/app.module.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Module } from '@nestjs/common';
22
import process from 'node:process';
3-
import { assert } from 'ts-essentials';
4-
import { keys } from 'ts-transformer-keys';
53
import { AdminModule } from './components/admin/admin.module';
64
import { AuthenticationModule } from './components/authentication/authentication.module';
75
import { AuthorizationModule } from './components/authorization/authorization.module';
@@ -45,11 +43,6 @@ import { CoreModule, LoggerModule } from './core';
4543

4644
import '@seedcompany/nest/patches';
4745

48-
assert(
49-
keys<{ foo: string }>().length === 1,
50-
'Sanity check for key transformer failed',
51-
);
52-
5346
if (process.env.NODE_ENV !== 'production') {
5447
Error.stackTraceLimit = Infinity;
5548
}

src/common/keysOf.spec.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/common/resource.dto.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { createMetadataDecorator } from '@seedcompany/nest';
1111
import { LazyGetter as Once } from 'lazy-get-decorator';
1212
import { DateTime } from 'luxon';
13-
import { keys as keysOf } from 'ts-transformer-keys';
1413
import type {
1514
ResourceDBMap,
1615
ResourceLike,
@@ -53,9 +52,6 @@ export const resolveByTypename =
5352
})
5453
@DbLabel('BaseNode')
5554
export abstract class Resource extends DataObject {
56-
static readonly Props: string[] = keysOf<Resource>();
57-
static readonly SecuredProps: string[] = [];
58-
5955
readonly __typename?: string;
6056

6157
@IdField()
@@ -77,8 +73,8 @@ export abstract class Resource extends DataObject {
7773
type Thunk<T> = T | (() => T);
7874

7975
export type ResourceShape<T> = AbstractClassType<T> & {
80-
Props: string[];
81-
SecuredProps: string[];
76+
Props?: string[];
77+
SecuredProps?: string[];
8278
// An optional list of props that exist on the BaseNode in the DB.
8379
// Default should probably be considered the props on Resource class.
8480
BaseNodeProps?: string[];
@@ -195,12 +191,24 @@ export class EnhancedResource<T extends ResourceShape<any>> {
195191

196192
@Once()
197193
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);
199201
}
200202

201203
@Once()
202204
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);
204212
}
205213

206214
@Once()

src/components/authentication/authentication.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { ForgotPassword } from '~/core/email/templates';
2222
import { disableAccessPolicies, Gel } from '~/core/gel';
2323
import { Privileges } from '../authorization';
2424
import { rolesForScope, withoutScope } from '../authorization/dto';
25-
import { AssignableRoles } from '../authorization/dto/assignable-roles';
25+
import { AssignableRoles } from '../authorization/dto/assignable-roles.dto';
2626
import { SystemAgentRepository } from '../user/system-agent.repository';
2727
import { AuthenticationRepository } from './authentication.repository';
2828
import { CryptoService } from './crypto.service';

src/components/authorization/assignable-roles.granter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type Role } from '~/common';
2-
import { AssignableRoles } from './dto/assignable-roles';
2+
import { AssignableRoles } from './dto/assignable-roles.dto';
33
import { Granter, ResourceGranter } from './policy';
44

55
@Granter(AssignableRoles)

src/components/authorization/dto/assignable-roles.ts renamed to src/components/authorization/dto/assignable-roles.dto.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import { RegisterResource } from '~/core/resources';
1717
@RegisterResource()
1818
@Calculated()
1919
export class AssignableRoles {
20-
static Props = [];
21-
static SecuredProps = [];
2220
static Relations = mapValues.fromList(Role, () => undefined)
2321
.asRecord satisfies ResourceRelationsShape;
2422
}

src/components/authorization/dto/beta-features.dto.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Field, ObjectType } from '@nestjs/graphql';
2-
import { keys as keysOf } from 'ts-transformer-keys';
32
import { Calculated, type ResourceRelationsShape } from '~/common';
43
import { RegisterResource } from '~/core/resources';
54
import { Granter, ResourceGranter } from '../policy';
@@ -10,9 +9,6 @@ import { Granter, ResourceGranter } from '../policy';
109
@Calculated()
1110
@ObjectType()
1211
export class BetaFeatures {
13-
static readonly Props = keysOf<BetaFeatures>();
14-
static readonly SecuredProps = [];
15-
1612
// Declaring as relations as well so privileges can use.
1713
static readonly Relations = {
1814
projectChangeRequests: undefined,

src/components/budget/dto/budget-record.dto.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Field, ObjectType } from '@nestjs/graphql';
2-
import { keys as keysOf } from 'ts-transformer-keys';
32
import {
43
Calculated,
54
type ID,
@@ -8,7 +7,6 @@ import {
87
type Secured,
98
SecuredFloatNullable,
109
SecuredInt,
11-
type SecuredProps,
1210
Sensitivity,
1311
SensitivityField,
1412
} from '~/common';
@@ -27,8 +25,6 @@ const Interfaces = IntersectTypes(Resource, ChangesetAware);
2725
implements: Interfaces.members,
2826
})
2927
export class BudgetRecord extends Interfaces {
30-
static readonly Props = keysOf<BudgetRecord>();
31-
static readonly SecuredProps = keysOf<SecuredProps<BudgetRecord>>();
3228
static readonly Parent = () => import('./budget.dto').then((m) => m.Budget);
3329

3430
@Field(() => Budget)

src/components/budget/dto/budget.dto.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { Field, ObjectType } from '@nestjs/graphql';
2-
import { keys as keysOf } from 'ts-transformer-keys';
32
import {
43
Calculated,
54
DbLabel,
65
IntersectTypes,
76
Resource,
87
type ResourceRelationsShape,
98
SecuredProperty,
10-
type SecuredProps,
119
Sensitivity,
1210
SensitivityField,
1311
} from '~/common';
@@ -28,8 +26,6 @@ const Interfaces = IntersectTypes(Resource, ChangesetAware);
2826
implements: Interfaces.members,
2927
})
3028
export class Budget extends Interfaces {
31-
static readonly Props = keysOf<Budget>();
32-
static readonly SecuredProps = keysOf<SecuredProps<Budget>>();
3329
static readonly Relations = (() => ({
3430
records: [BudgetRecord],
3531
})) satisfies ResourceRelationsShape;

0 commit comments

Comments
 (0)