Files
speckle-server/packages/server/modules/cli/commands/db/seed/commits.ts
T
Kristaps Fabians Geikins bde148f286 chore(server): migrating fully to ESM (#5042)
* wip

* some extra fixes

* stuff kinda works?

* need to figure out mocks

* need to figure out mocks

* fix db listener

* gqlgen fix

* minor gqlgen watch adjustment

* lint fixes

* delete old codegen file

* converting migrations to ESM

* getModuleDIrectory

* vitest sort of works

* added back ts-vitest

* resolve gql double load

* fixing test timeout configs

* TSC lint fix

* fix automate tests

* moar debugging

* debugging

* more debugging

* codegen update

* server works

* yargs migrated

* chore(server): getting rid of global mocks for Server ESM (#5046)

* got rid of email mock

* got rid of comment mocks

* got rid of multi region mocks

* got rid of stripe mock

* admin override mock updated

* removed final mock

* fixing import.meta.resolve calls

* another import.meta.resolve fix

* added requested test

* nyc ESM fix

* removed unneeded deps + linting

* yarn lock forgot to commit

* tryna fix flakyness

* email capture util fix

* sendEmail fix

* fix TSX check

* sender transporter fix + CR comments

* merge main fix

* test fixx

* circleci fix

* gqlgen bigint fix

* error formatter fix

* more error formatting improvements

* esmloader added to Dockerfile

* more dockerfile fixes

* bg jobs fix
2025-07-14 10:26:19 +03:00

78 lines
2.4 KiB
TypeScript

import { db } from '@/db/knex'
import { cliLogger as logger } from '@/observability/logging'
import { StreamNotFoundError } from '@/modules/core/errors/stream'
import { UserNotFoundError } from '@/modules/core/errors/user'
import { getStreamFactory } from '@/modules/core/repositories/streams'
import { getUserFactory } from '@/modules/core/repositories/users'
import { ForbiddenError } from '@/modules/shared/errors'
import { BasicTestCommit, createTestCommits } from '@/test/speckle-helpers/commitHelper'
import dayjs from 'dayjs'
import { times } from 'lodash-es'
import { CommandModule } from 'yargs'
import { ProjectRecordVisibility } from '@/modules/core/helpers/types'
const command: CommandModule<
unknown,
{ streamId: string; count: number; authorId: string }
> = {
command: 'commits <authorId> <streamId> <count>',
describe: 'Generate fake commits into the specified stream',
builder: {
authorId: {
describe: 'ID of the user who is going to be the commit author',
type: 'string'
},
streamId: {
describe: 'ID of the stream that should receive the commits',
type: 'string'
},
count: {
describe: 'Commit count',
type: 'number',
default: 50
}
},
handler: async (argv) => {
const getUser = getUserFactory({ db })
const getStream = getStreamFactory({ db })
const count = argv.count
const streamId = argv.streamId
const authorId = argv.authorId
const date = dayjs().toISOString()
const user = await getUser(authorId)
if (!user?.id) {
throw new UserNotFoundError(`User with ID ${authorId} not found`)
}
const stream = await getStream({ streamId, userId: user.id })
if (!stream?.id) {
throw new StreamNotFoundError(`Stream with ID ${streamId} not found`)
}
if (stream.visibility !== ProjectRecordVisibility.Public && !stream.role) {
throw new ForbiddenError(
`Commit author does not have access to the specified stream ${streamId}`
)
}
logger.info(`Generating ${count} objects & commits for stream ${streamId}...`)
await createTestCommits(
times(
count,
(i): BasicTestCommit => ({
id: '',
objectId: '',
branchId: '',
streamId,
authorId,
message: `#${i} - ${date} - Fake commit batch`
})
)
)
logger.info(`...done`)
}
}
export = command