From ec8839cdb0ecb0711db9f863b3c375627e135a50 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 20 Feb 2020 14:41:03 +1100 Subject: [PATCH 1/4] fix: update packages to resolve type errors Update prime-core package.json to resolving typing errors between @accounts/typeorm and typeorm which causes compilation to fail. --- package.json | 2 +- packages/prime-core/package.json | 2 +- yarn.lock | 37 +++++++++++++++++++------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 23d01f278..358110773 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "link": "lerna exec -- yarn link", "unlink": "lerna exec -- yarn unlink", "clean": "lerna run clean && rimraf {.cache,node_modules,reports,packages/**/{node_modules,lib,build,coverage},yarn.lock}", - "compile": "lerna run compile", + "compile": "lerna run compile --stream", "lint": "tslint ./packages/*/{src,__tests__}/*.{ts,tsx}", "lint:ci": "mkdir -p reports/junit && yarn lint --formatters-dir node_modules/tslint-junit-formatter/formatters --format junit -o ./reports/junit/tslint.xml", "publish": "lerna publish prerelease", diff --git a/packages/prime-core/package.json b/packages/prime-core/package.json index feae86c8b..bd851a312 100644 --- a/packages/prime-core/package.json +++ b/packages/prime-core/package.json @@ -40,7 +40,7 @@ "@accounts/graphql-api": "^0.19.0", "@accounts/password": "^0.19.0", "@accounts/server": "^0.19.0", - "@accounts/typeorm": "^0.19.0", + "@accounts/typeorm": "^0.22.0", "@casl/ability": "3.4.0", "@graphql-modules/core": "^0.7.0", "@primecms/field": "^0.3.4-beta.1", diff --git a/yarn.lock b/yarn.lock index 6f74ceb40..338602f18 100644 --- a/yarn.lock +++ b/yarn.lock @@ -82,16 +82,16 @@ speakeasy "^2.0.0" tslib "1.10.0" -"@accounts/typeorm@^0.19.0": - version "0.19.0" - resolved "https://registry.yarnpkg.com/@accounts/typeorm/-/typeorm-0.19.0.tgz#043f896b4121d5f3a3fdeccd5874c7f899b47d5a" - integrity sha512-gYyTchFL1hL0bMlW5Ms2RDTFmp+Tha2BYGEM+anRqv0inZCG+vatDrdpn2fAXY94e5mvXpcLwYJiZ38tT6kpKg== +"@accounts/typeorm@^0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@accounts/typeorm/-/typeorm-0.22.0.tgz#90ad1fb78668589fe2972fc93d669472c87552b1" + integrity sha512-oeNBebLL3lEv14dh1f7Kf+QlTXYlxriDTY0QX3DAJkX18l6FWgFOO4FTpiNT2mZ0C2zZ5kk4by+2ug0g2c/jbQ== dependencies: - "@accounts/types" "^0.19.0" + "@accounts/types" "^0.22.0" lodash "^4.17.15" reflect-metadata "^0.1.13" tslib "1.10.0" - typeorm "^0.2.17" + typeorm "^0.2.22" "@accounts/types@^0.19.0": version "0.19.0" @@ -100,6 +100,13 @@ dependencies: tslib "1.10.0" +"@accounts/types@^0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@accounts/types/-/types-0.22.0.tgz#5b1bc49a0e9d97c6fd7bc0928d8d9a5e7321d20a" + integrity sha512-EwQSX2V7bjXJ810H/a+FhFgcViPYi0lVHNuqqU5Qal6tUcB0hvV3rfI7am1H1nv3MG3tjx/FAcBuQdbpoDGPiQ== + dependencies: + tslib "1.10.0" + "@ant-design/colors@^3.1.0": version "3.2.2" resolved "https://registry.yarnpkg.com/@ant-design/colors/-/colors-3.2.2.tgz#5ad43d619e911f3488ebac303d606e66a8423903" @@ -3743,10 +3750,10 @@ apollo-utilities@^1.0.1, apollo-utilities@^1.3.0: ts-invariant "^0.4.0" tslib "^1.9.3" -app-root-path@^2.0.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.2.1.tgz#d0df4a682ee408273583d43f6f79e9892624bc9a" - integrity sha512-91IFKeKk7FjfmezPKkwtaRvSpnUc4gDwPAjA1YZ9Gn0q0PPeW+vbeUsZuyDwjI7+QTHhcLen2v25fi/AmhvbJA== +app-root-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-3.0.0.tgz#210b6f43873227e18a4b810a032283311555d5ad" + integrity sha512-qMcx+Gy2UZynHjOHOIXPNvpf+9cjvk3cWrBBK7zg4gH9+clobJRb9NGzcT7mQTcV/6Gm/1WelUtqxVXnNlrwcw== append-transform@^0.4.0: version "0.4.0" @@ -18532,12 +18539,12 @@ typeorm-typedi-extensions@^0.2.0: resolved "https://registry.yarnpkg.com/typeorm-typedi-extensions/-/typeorm-typedi-extensions-0.2.3.tgz#94fca2656206d771bf6d2242f5aab570511188e8" integrity sha512-T9i1NvRZNjPn9Jb8oT772ihfn6PwdqDVpzPCtKSqjkZGOgXrCkdyD3dDrzfMaoWJ1afU58bVx2CMb95FzT42Ow== -typeorm@^0.2.0, typeorm@^0.2.17: - version "0.2.19" - resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.19.tgz#a0cff0714180e5720df157df02c5759a1a646dc3" - integrity sha512-xKVx/W41zckQ7v8WYcpRhSKpjXDKG/Jgjy0RWvYelR8ZnfyblNRL12jF4P8tIhwXv6l5t01s7HEc9lR+zb6Gtg== +typeorm@^0.2.21, typeorm@^0.2.22: + version "0.2.22" + resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.22.tgz#e85166e29ee4e4248ed73b2b8c977f364ffba606" + integrity sha512-mDEnMtzRwX4zMYbyzM9xDn7jvGs8hfQ2ymOBq36Zxq1RVM642numwlRbr4W8dU7ZYx8CQUE9rmk+sU0baHD9Rw== dependencies: - app-root-path "^2.0.1" + app-root-path "^3.0.0" buffer "^5.1.0" chalk "^2.4.2" cli-highlight "^2.0.0" From 4ef1bfabb3623fe14dc7b9900e838fb085e4d5ca Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 20 Feb 2020 14:41:07 +1100 Subject: [PATCH 2/4] fix: resolve user.meta is not a function Resolve the user.meta is not a function error by making user.meta a static function which takes an id as an argument due to entities not inheriting their types methods. --- packages/prime-core/src/entities/User.ts | 14 ++++++++------ .../src/modules/internal/resolvers/UserResolver.ts | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/prime-core/src/entities/User.ts b/packages/prime-core/src/entities/User.ts index 919cc6612..6231d078b 100644 --- a/packages/prime-core/src/entities/User.ts +++ b/packages/prime-core/src/entities/User.ts @@ -6,17 +6,19 @@ import { UserMeta } from './UserMeta'; @Entity() @ObjectType() export class User extends AccountsUser { - @Field(type => ID) - public id = super.id; - - public async meta(): Promise { + public static async meta(id: string): Promise { const metaRepo = getRepository(UserMeta); - let meta = await metaRepo.findOne(this.id); + let meta = await metaRepo.findOne(id); + if (!meta) { meta = new UserMeta(); - meta.id = this.id; + meta.id = id; await metaRepo.save(meta); } + return meta; } + + @Field(type => ID) + public id = super.id; } diff --git a/packages/prime-core/src/modules/internal/resolvers/UserResolver.ts b/packages/prime-core/src/modules/internal/resolvers/UserResolver.ts index 3841d72bc..4eff40fb5 100644 --- a/packages/prime-core/src/modules/internal/resolvers/UserResolver.ts +++ b/packages/prime-core/src/modules/internal/resolvers/UserResolver.ts @@ -40,8 +40,8 @@ export class UserResolver { @Authorized() @Query(returns => User) public async getUser(@Ctx() context: Context) { - const user = await this.userRepository.findOneOrFail(context.user.id); - const meta = await user.meta(); + const meta = await User.meta(context.user.id); + return { ...context.user, meta, @@ -60,7 +60,7 @@ export class UserResolver { }); (result as any).resolveNode = async user => { user.emails = await this.userEmailRepository.find({ user }); - const meta = await user.meta(); + const meta = await User.meta(user.id); return { ...user, meta, @@ -131,7 +131,7 @@ export class UserResolver { @Ctx() context: Context ) { const user = await this.userRepository.findOneOrFail(id); - const meta = await user.meta(); + const meta = await User.meta(id); meta.profile = input.profile; context.ability.throwUnlessCan('update', user); await this.userRepository.save(user); @@ -171,7 +171,7 @@ export class UserResolver { } @FieldResolver(returns => UserMeta) - public async meta(@Root() user: User): Promise { - return user.meta(); + public meta(@Root() user: User): Promise { + return User.meta(user.id); } } From 2e11c96ce8f04732e305c8d14d326d18a7db88d2 Mon Sep 17 00:00:00 2001 From: Birkir Gudjonsson Date: Fri, 17 Jul 2020 16:09:12 +0000 Subject: [PATCH 3/4] Update yarn.lock --- yarn.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/yarn.lock b/yarn.lock index b04c0716b..b7026ed76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -69,6 +69,7 @@ jwt-decode "2.2.0" lodash "4.17.15" tslib "1.11.2" + typeorm "^0.2.22" "@accounts/two-factor@^0.27.0": version "0.27.0" From 1dae1872fe8a3f24cb38dcf90b01f2d7acca3ebc Mon Sep 17 00:00:00 2001 From: Birkir Gudjonsson Date: Fri, 17 Jul 2020 16:09:48 +0000 Subject: [PATCH 4/4] Update yarn.lock --- yarn.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index b7026ed76..b04c0716b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -69,7 +69,6 @@ jwt-decode "2.2.0" lodash "4.17.15" tslib "1.11.2" - typeorm "^0.2.22" "@accounts/two-factor@^0.27.0": version "0.27.0"