chore(server): core IoC 27 - getObjectFactory
This commit is contained in:
@@ -15,7 +15,10 @@ import {
|
||||
} from '@/modules/core/repositories/branches'
|
||||
import { getUser } from '@/modules/core/repositories/users'
|
||||
import { createObject } from '@/modules/core/services/objects'
|
||||
import { getObject, getStreamObjectsFactory } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getObjectFactory,
|
||||
getStreamObjectsFactory
|
||||
} from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
createCommentReplyAndNotifyFactory,
|
||||
createCommentThreadAndNotifyFactory
|
||||
@@ -89,6 +92,7 @@ const command: CommandModule<
|
||||
}
|
||||
},
|
||||
handler: async (argv) => {
|
||||
const getObject = getObjectFactory({ db })
|
||||
const getStreamObjects = getStreamObjectsFactory({ db })
|
||||
const markCommentViewed = markCommentViewedFactory({ db })
|
||||
const validateInputAttachments = validateInputAttachmentsFactory({
|
||||
|
||||
@@ -18,7 +18,10 @@ import {
|
||||
import { getUser } from '@/modules/core/repositories/users'
|
||||
import { createCommitByBranchIdFactory } from '@/modules/core/services/commit/management'
|
||||
import { createObject } from '@/modules/core/services/objects'
|
||||
import { getObject, getStreamObjectsFactory } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getObjectFactory,
|
||||
getStreamObjectsFactory
|
||||
} from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
createCommentReplyAndNotifyFactory,
|
||||
createCommentThreadAndNotifyFactory
|
||||
@@ -87,6 +90,8 @@ const command: CommandModule<
|
||||
}
|
||||
},
|
||||
handler: async (argv) => {
|
||||
const getObject = getObjectFactory({ db })
|
||||
|
||||
const getStreamObjects = getStreamObjectsFactory({ db })
|
||||
const markCommentViewed = markCommentViewedFactory({ db })
|
||||
const validateInputAttachments = validateInputAttachmentsFactory({
|
||||
|
||||
@@ -46,7 +46,6 @@ const {
|
||||
insertStreamCommitsFactory,
|
||||
insertBranchCommitsFactory
|
||||
} = require('@/modules/core/repositories/commits')
|
||||
const { getObject } = require('@/modules/core/repositories/objects')
|
||||
const {
|
||||
getBranchByIdFactory,
|
||||
markCommitBranchUpdatedFactory,
|
||||
@@ -57,6 +56,7 @@ const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
|
||||
const {
|
||||
addCommitCreatedActivity
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const { getObjectFactory } = require('@/modules/core/repositories/objects')
|
||||
|
||||
const streamResourceCheck = streamResourceCheckFactory({
|
||||
checkStreamResourceAccess: checkStreamResourceAccessFactory({ db })
|
||||
@@ -74,6 +74,7 @@ const createComment = createCommentFactory({
|
||||
commentsEventsEmit: CommentsEmitter.emit
|
||||
})
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -68,7 +68,6 @@ const {
|
||||
insertStreamCommitsFactory,
|
||||
insertBranchCommitsFactory
|
||||
} = require('@/modules/core/repositories/commits')
|
||||
const { getObject } = require('@/modules/core/repositories/objects')
|
||||
const {
|
||||
getBranchByIdFactory,
|
||||
markCommitBranchUpdatedFactory,
|
||||
@@ -78,6 +77,7 @@ const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
|
||||
const {
|
||||
addCommitCreatedActivity
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const { getObjectFactory } = require('@/modules/core/repositories/objects')
|
||||
|
||||
const streamResourceCheck = streamResourceCheckFactory({
|
||||
checkStreamResourceAccess: checkStreamResourceAccessFactory({ db })
|
||||
@@ -124,6 +124,7 @@ const getComments = getCommentsLegacyFactory({ db })
|
||||
const getResourceCommentCount = getResourceCommentCountFactory({ db })
|
||||
const getStreamCommentCount = getStreamCommentCountFactory({ db })
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { SpeckleObject } from '@/modules/core/domain/objects/types'
|
||||
import { Optional } from '@speckle/shared'
|
||||
|
||||
export type GetStreamObjects = (
|
||||
streamId: string,
|
||||
objectIds: string[]
|
||||
) => Promise<SpeckleObject[]>
|
||||
|
||||
export type GetObject = (
|
||||
objectId: string,
|
||||
streamId: string
|
||||
) => Promise<Optional<SpeckleObject>>
|
||||
|
||||
@@ -73,8 +73,8 @@ const {
|
||||
addCommitUpdatedActivity,
|
||||
addCommitMovedActivity
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const { getObject } = require('@/modules/core/repositories/objects')
|
||||
const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
|
||||
const { getObjectFactory } = require('@/modules/core/repositories/objects')
|
||||
|
||||
// subscription events
|
||||
const COMMIT_CREATED = CommitPubsubEvents.CommitCreated
|
||||
@@ -89,6 +89,7 @@ const deleteCommitAndNotify = deleteCommitAndNotifyFactory({
|
||||
addCommitDeletedActivity
|
||||
})
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -8,7 +8,10 @@ import {
|
||||
|
||||
import { Roles } from '@speckle/shared'
|
||||
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
import { db } from '@/db/knex'
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
|
||||
const getStreamObject: NonNullable<Resolvers['Stream']>['object'] =
|
||||
async function object(parent, args) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import {
|
||||
updateCommitFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { db } from '@/db/knex'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
createBranchFactory,
|
||||
getBranchByIdFactory,
|
||||
@@ -52,7 +51,9 @@ import {
|
||||
addCommitMovedActivity,
|
||||
addCommitUpdatedActivity
|
||||
} from '@/modules/activitystream/services/commitActivity'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
executeBatchedSelect
|
||||
} from '@/modules/shared/helpers/dbHelper'
|
||||
import { Knex } from 'knex'
|
||||
import { GetStreamObjects } from '@/modules/core/domain/objects/operations'
|
||||
import { GetObject, GetStreamObjects } from '@/modules/core/domain/objects/operations'
|
||||
|
||||
const tables = {
|
||||
objects: (db: Knex) => db<ObjectRecord>(Objects.name)
|
||||
@@ -25,15 +25,15 @@ export const getStreamObjectsFactory =
|
||||
return await q
|
||||
}
|
||||
|
||||
export async function getObject(
|
||||
objectId: string,
|
||||
streamId: string
|
||||
): Promise<Optional<ObjectRecord>> {
|
||||
return await Objects.knex<ObjectRecord[]>()
|
||||
.where(Objects.col.id, objectId)
|
||||
.andWhere(Objects.col.streamId, streamId)
|
||||
.first()
|
||||
}
|
||||
export const getObjectFactory =
|
||||
(deps: { db: Knex }): GetObject =>
|
||||
async (objectId: string, streamId: string): Promise<Optional<ObjectRecord>> => {
|
||||
return await tables
|
||||
.objects(deps.db)
|
||||
.where(Objects.col.id, objectId)
|
||||
.andWhere(Objects.col.streamId, streamId)
|
||||
.first()
|
||||
}
|
||||
|
||||
export function getBatchedStreamObjects(
|
||||
streamId: string,
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
UpdateCommit,
|
||||
UpdateCommitAndNotify
|
||||
} from '@/modules/core/domain/commits/operations'
|
||||
import { GetObject } from '@/modules/core/domain/objects/operations'
|
||||
import {
|
||||
CommitCreateError,
|
||||
CommitDeleteError,
|
||||
@@ -42,7 +43,6 @@ import {
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { CommitRecord } from '@/modules/core/helpers/types'
|
||||
import { getCommitFactory } from '@/modules/core/repositories/commits'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getCommitStream,
|
||||
getStream,
|
||||
@@ -85,7 +85,7 @@ export async function markCommitReceivedAndNotify(params: {
|
||||
export const createCommitByBranchIdFactory =
|
||||
(deps: {
|
||||
createCommit: StoreCommit
|
||||
getObject: typeof getObject
|
||||
getObject: GetObject
|
||||
getBranchById: GetBranchById
|
||||
insertStreamCommits: InsertStreamCommits
|
||||
insertBranchCommits: InsertBranchCommits
|
||||
|
||||
@@ -44,11 +44,11 @@ const {
|
||||
insertStreamCommitsFactory,
|
||||
insertBranchCommitsFactory
|
||||
} = require('@/modules/core/repositories/commits')
|
||||
const { getObject } = require('@/modules/core/repositories/objects')
|
||||
const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
|
||||
const {
|
||||
addCommitCreatedActivity
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const { getObjectFactory } = require('@/modules/core/repositories/objects')
|
||||
|
||||
const db = knex
|
||||
const Commits = () => knex('commits')
|
||||
@@ -69,6 +69,7 @@ const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
|
||||
deleteBranchById: deleteBranchByIdFactory({ db: knex })
|
||||
})
|
||||
|
||||
const getObject = getObjectFactory({ db: knex })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -54,8 +54,8 @@ const {
|
||||
addCommitCreatedActivity,
|
||||
addCommitUpdatedActivity
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const { getObject } = require('@/modules/core/repositories/objects')
|
||||
const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
|
||||
const { getObjectFactory } = require('@/modules/core/repositories/objects')
|
||||
|
||||
const createBranch = createBranchFactory({ db })
|
||||
const createBranchAndNotify = createBranchAndNotifyFactory({
|
||||
@@ -72,6 +72,7 @@ const deleteCommitAndNotify = deleteCommitAndNotifyFactory({
|
||||
addCommitDeletedActivity
|
||||
})
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -70,9 +70,9 @@ import {
|
||||
insertBranchCommitsFactory,
|
||||
insertStreamCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import { VersionsEmitter } from '@/modules/core/events/versionsEmitter'
|
||||
import { addCommitCreatedActivity } from '@/modules/activitystream/services/commitActivity'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
|
||||
const getStreamBranchByName = getStreamBranchByNameFactory({ db })
|
||||
const createBranch = createBranchFactory({ db })
|
||||
@@ -85,6 +85,7 @@ const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
|
||||
deleteBranchById: deleteBranchByIdFactory({ db })
|
||||
})
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -52,16 +52,17 @@ const {
|
||||
createCommitByBranchIdFactory,
|
||||
createCommitByBranchNameFactory
|
||||
} = require('@/modules/core/services/commit/management')
|
||||
const { getObject } = require('@/modules/core/repositories/objects')
|
||||
const { markCommitStreamUpdated } = require('@/modules/core/repositories/streams')
|
||||
const { VersionsEmitter } = require('@/modules/core/events/versionsEmitter')
|
||||
const {
|
||||
addCommitCreatedActivity
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const { getObjectFactory } = require('@/modules/core/repositories/objects')
|
||||
|
||||
const createBranch = createBranchFactory({ db })
|
||||
const getCommit = getCommitFactory({ db })
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -36,7 +36,10 @@ import {
|
||||
insertBranchCommitsFactory,
|
||||
insertStreamCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getObject, getStreamObjectsFactory } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getObjectFactory,
|
||||
getStreamObjectsFactory
|
||||
} from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getOnboardingBaseStream,
|
||||
getStream,
|
||||
@@ -63,9 +66,10 @@ const crossServerSyncModule: SpeckleModule = {
|
||||
moduleLogger.info('🔄️ Init cross-server-sync module')
|
||||
},
|
||||
finalize() {
|
||||
const getStreamObjects = getStreamObjectsFactory({ db })
|
||||
|
||||
crossServerSyncLogger.info('⬇️ Ensuring base onboarding stream asynchronously...')
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const getStreamObjects = getStreamObjectsFactory({ db })
|
||||
const markCommentViewed = markCommentViewedFactory({ db })
|
||||
const validateInputAttachments = validateInputAttachmentsFactory({
|
||||
getBlobs: getBlobsFactory({ db })
|
||||
|
||||
@@ -5,7 +5,6 @@ import { CreateCommentInput } from '@/test/graphql/generated/graphql'
|
||||
import { getStream, getStreamCollaborators } from '@/modules/core/repositories/streams'
|
||||
import { Roles, timeoutAt } from '@speckle/shared'
|
||||
import { createObject } from '@/modules/core/services/objects'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import ObjectLoader from '@speckle/objectloader'
|
||||
import { noop } from 'lodash'
|
||||
import { crossServerSyncLogger } from '@/logging/logging'
|
||||
@@ -31,6 +30,7 @@ import {
|
||||
} from '@/modules/comments/domain/operations'
|
||||
import { GetStreamBranchByName } from '@/modules/core/domain/branches/operations'
|
||||
import { CreateCommitByBranchId } from '@/modules/core/domain/commits/operations'
|
||||
import { GetObject } from '@/modules/core/domain/objects/operations'
|
||||
|
||||
type LocalResources = Awaited<ReturnType<ReturnType<typeof getLocalResourcesFactory>>>
|
||||
type LocalResourcesWithCommit = LocalResources & { newCommitId: string }
|
||||
@@ -489,7 +489,7 @@ const saveNewCommitFactory =
|
||||
|
||||
type CreateNewObjectDeps = {
|
||||
createObject: typeof createObject
|
||||
getObject: typeof getObject
|
||||
getObject: GetObject
|
||||
}
|
||||
|
||||
const createNewObjectFactory =
|
||||
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
insertBranchCommitsFactory,
|
||||
insertStreamCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getBranchByIdFactory,
|
||||
getStreamBranchByNameFactory,
|
||||
@@ -39,7 +38,9 @@ import {
|
||||
import { markCommitStreamUpdated } from '@/modules/core/repositories/streams'
|
||||
import { VersionsEmitter } from '@/modules/core/events/versionsEmitter'
|
||||
import { addCommitCreatedActivity } from '@/modules/activitystream/services/commitActivity'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
insertBranchCommitsFactory,
|
||||
insertStreamCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getObject } from '@/modules/core/repositories/objects'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
import { markCommitStreamUpdated } from '@/modules/core/repositories/streams'
|
||||
import {
|
||||
createCommitByBranchIdFactory,
|
||||
@@ -21,6 +21,7 @@ import { createObject } from '@/modules/core/services/objects'
|
||||
import { BasicTestUser } from '@/test/authHelper'
|
||||
import { BasicTestStream } from '@/test/speckle-helpers/streamHelper'
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
createCommit: createCommitFactory({ db }),
|
||||
getObject,
|
||||
|
||||
Reference in New Issue
Block a user