Skip to content

Commit

Permalink
chore(server): cross-server-sync IoC Part 2 (#2907)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabis94 authored Sep 9, 2024
1 parent 2243df5 commit f53bdd6
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 153 deletions.
32 changes: 31 additions & 1 deletion packages/server/modules/cli/commands/download/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { CommandModule } from 'yargs'
import { cliLogger } from '@/logging/logging'
import { downloadProject } from '@/modules/cross-server-sync/services/project'
import { downloadProjectFactory } from '@/modules/cross-server-sync/services/project'
import { downloadCommitFactory } from '@/modules/cross-server-sync/services/commit'
import { getStream, getStreamCollaborators } from '@/modules/core/repositories/streams'
import { getStreamBranchByName } from '@/modules/core/repositories/branches'
import { getUser } from '@/modules/core/repositories/users'
import { createCommitByBranchId } from '@/modules/core/services/commit/management'
import { createObject } from '@/modules/core/services/objects'
import { getObject } from '@/modules/core/repositories/objects'
import {
createCommentReplyAndNotify,
createCommentThreadAndNotify
} from '@/modules/comments/services/management'
import { createStreamReturnRecord } from '@/modules/core/services/streams/management'
import { createBranchAndNotify } from '@/modules/core/services/branch/management'

const command: CommandModule<
unknown,
Expand Down Expand Up @@ -34,6 +47,23 @@ const command: CommandModule<
}
},
handler: async (argv) => {
const downloadProject = downloadProjectFactory({
downloadCommit: downloadCommitFactory({
getStream,
getStreamBranchByName,
getStreamCollaborators,
getUser,
createCommitByBranchId,
createObject,
getObject,
createCommentThreadAndNotify,
createCommentReplyAndNotify
}),
createStreamReturnRecord,
getUser,
getStreamBranchByName,
createBranchAndNotify
})
await downloadProject(argv, { logger: cliLogger })
}
}
Expand Down
26 changes: 26 additions & 0 deletions packages/server/modules/cross-server-sync/domain/operations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Logger } from '@/logging/logging'
import { StreamRecord } from '@/modules/core/helpers/types'

export type DownloadCommit = (
argv: {
Expand Down Expand Up @@ -38,3 +39,28 @@ export type DownloadCommit = (
commitId: string
branchId: string
}>

export type DownloadProject = (
params: {
/**
* An FE2 project URL (must be publicly accessible)
*/
projectUrl: string
/**
* ID of user that should own the project locally
*/
authorId: string
syncComments?: boolean
/**
* Specify if target project is private
*/
token?: string
},
options?: Partial<{
logger: Logger
}>
) => Promise<{
newProjectUrl: string
projectId: string
project: StreamRecord
}>
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { crossServerSyncLogger } from '@/logging/logging'
import {
createCommentReplyAndNotify,
createCommentThreadAndNotify
} from '@/modules/comments/services/management'
import { getStreamBranchByName } from '@/modules/core/repositories/branches'
import { getObject } from '@/modules/core/repositories/objects'
import {
getOnboardingBaseStream,
getStream,
getStreamCollaborators,
markOnboardingBaseStream
} from '@/modules/core/repositories/streams'
import { getFirstAdmin } from '@/modules/core/repositories/users'
import { downloadProject } from '@/modules/cross-server-sync/services/project'
import { getFirstAdmin, getUser } from '@/modules/core/repositories/users'
import { createBranchAndNotify } from '@/modules/core/services/branch/management'
import { createCommitByBranchId } from '@/modules/core/services/commit/management'
import { createObject } from '@/modules/core/services/objects'
import { createStreamReturnRecord } from '@/modules/core/services/streams/management'
import { downloadCommitFactory } from '@/modules/cross-server-sync/services/commit'
import { downloadProjectFactory } from '@/modules/cross-server-sync/services/project'
import {
getOnboardingStreamCacheBustNumber,
getOnboardingStreamUrl
Expand Down Expand Up @@ -52,6 +65,24 @@ export async function ensureOnboardingProject() {
}

logger.info('Onboarding stream not found, pulling from target server...')

const downloadProject = downloadProjectFactory({
downloadCommit: downloadCommitFactory({
getStream,
getStreamBranchByName,
getStreamCollaborators,
getUser,
createCommitByBranchId,
createObject,
getObject,
createCommentThreadAndNotify,
createCommentReplyAndNotify
}),
createStreamReturnRecord,
getUser,
getStreamBranchByName,
createBranchAndNotify
})
const res = await downloadProject(
{
projectUrl: metadata.url,
Expand Down
Loading

0 comments on commit f53bdd6

Please sign in to comment.