Merge pull request #3399 from specklesystems/fabians/quick-js-to-ts-4

chore(server): quick js to ts #4 - remaining commits resolvers (thats it!)
This commit is contained in:
Alessandro Magionami 2024-10-28 15:18:16 +01:00 коммит произвёл GitHub
Родитель 11c13796c2 9783537ea9
Коммит c9ef276343
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 80 добавлений и 75 удалений

Просмотреть файл

@ -1,73 +0,0 @@
const { withFilter } = require('graphql-subscriptions')
const {
pubsub,
CommitSubscriptions: CommitPubsubEvents
} = require('@/modules/shared/utils/subscriptions')
const { authorizeResolver } = require('@/modules/shared')
const { Roles } = require('@speckle/shared')
/**
* TODO: Clean up and move to commitsNew.ts
*/
// subscription events
const COMMIT_CREATED = CommitPubsubEvents.CommitCreated
const COMMIT_UPDATED = CommitPubsubEvents.CommitUpdated
const COMMIT_DELETED = CommitPubsubEvents.CommitDeleted
/** @type {import('@/modules/core/graph/generated/graphql').Resolvers} */
module.exports = {
Subscription: {
commitCreated: {
subscribe: withFilter(
() => pubsub.asyncIterator([COMMIT_CREATED]),
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)
return payload.streamId === variables.streamId
}
)
},
commitUpdated: {
subscribe: withFilter(
() => pubsub.asyncIterator([COMMIT_UPDATED]),
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)
const streamMatch = payload.streamId === variables.streamId
if (streamMatch && variables.commitId) {
return payload.commitId === variables.commitId
}
return streamMatch
}
)
},
commitDeleted: {
subscribe: withFilter(
() => pubsub.asyncIterator([COMMIT_DELETED]),
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)
return payload.streamId === variables.streamId
}
)
}
}
}

Просмотреть файл

@ -1,5 +1,9 @@
import { CommitNotFoundError } from '@/modules/core/errors/commit'
import { publish } from '@/modules/shared/utils/subscriptions'
import {
CommitSubscriptions,
filteredSubscribe,
publish
} from '@/modules/shared/utils/subscriptions'
import { authorizeResolver } from '@/modules/shared'
import {
@ -381,5 +385,56 @@ export = {
await batchDeleteCommits(args.input, ctx.userId!)
return true
}
},
Subscription: {
commitCreated: {
subscribe: filteredSubscribe(
CommitSubscriptions.CommitCreated,
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)
return payload.streamId === variables.streamId
}
)
},
commitUpdated: {
subscribe: filteredSubscribe(
CommitSubscriptions.CommitUpdated,
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)
const streamMatch = payload.streamId === variables.streamId
if (streamMatch && variables.commitId) {
return payload.commitId === variables.commitId
}
return streamMatch
}
)
},
commitDeleted: {
subscribe: filteredSubscribe(
CommitSubscriptions.CommitDeleted,
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)
return payload.streamId === variables.streamId
}
)
}
}
} as Resolvers

Просмотреть файл

@ -46,7 +46,11 @@ import {
UpdateModelInput,
SubscriptionBranchDeletedArgs,
BranchDeleteInput,
DeleteModelInput
DeleteModelInput,
SubscriptionCommitCreatedArgs,
CommitCreateInput,
SubscriptionCommitUpdatedArgs,
CommitUpdateInput
} from '@/modules/core/graph/generated/graphql'
import { Merge } from 'type-fest'
import {
@ -61,6 +65,7 @@ import {
ProjectAutomationsUpdatedMessageGraphQLReturn
} from '@/modules/automate/helpers/graphTypes'
import { CommentRecord } from '@/modules/comments/helpers/types'
import { CommitRecord } from '@/modules/core/helpers/types'
import { BranchRecord } from '@/modules/core/helpers/types'
/**
@ -325,6 +330,24 @@ type SubscriptionTypeMap = {
payload: { branchDeleted: BranchDeleteInput | DeleteModelInput; streamId: string }
variables: SubscriptionBranchDeletedArgs
}
[CommitSubscriptions.CommitCreated]: {
payload: {
commitCreated: CommitCreateInput & { id: string; authorId: string }
streamId: string
}
variables: SubscriptionCommitCreatedArgs
}
[CommitSubscriptions.CommitUpdated]: {
payload: { commitUpdated: CommitUpdateInput; streamId: string; commitId: string }
variables: SubscriptionCommitUpdatedArgs
}
[CommitSubscriptions.CommitDeleted]: {
payload: {
commitDeleted: CommitRecord & { streamId: string; branchId: string }
streamId: string
}
variables: SubscriptionCommitUpdatedArgs
}
} & { [k in SubscriptionEvent]: { payload: unknown; variables: unknown } }
type SubscriptionEvent =