Files
speckle-server/packages/server/modules/cli/commands/db/seed/commits.ts
T
Iain Sproat 4d01e13a84 feat(structured logging) (#1242)
* Revert "Revert structured logging 2 (#1240)"
This reverts commit 78ecaeffcb.
* Logging should not be bundled into core shared directory
* making sure observability stuff isnt bundled into frontend


Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2022-12-06 11:51:18 +00:00

69 lines
1.9 KiB
TypeScript

import { cliLogger } from '@/logging/logging'
import { getStream } from '@/modules/core/repositories/streams'
import { getUser } from '@/modules/core/repositories/users'
import { BasicTestCommit, createTestCommits } from '@/test/speckle-helpers/commitHelper'
import dayjs from 'dayjs'
import { times } from 'lodash'
import { CommandModule } from 'yargs'
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 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 Error(`User with ID ${authorId} not found`)
}
const stream = await getStream({ streamId, userId: user.id })
if (!stream?.id) {
throw new Error(`Stream with ID ${streamId} not found`)
}
if (!stream.isPublic && !stream.role) {
throw new Error(
`Commit author does not have access to the specified stream ${streamId}`
)
}
cliLogger.info(`Generating ${count} objects & commits for stream ${streamId}...`)
await createTestCommits(
times(
count,
(i): BasicTestCommit => ({
id: '',
objectId: '',
streamId,
authorId,
message: `#${i} - ${date} - Fake commit batch`
})
)
)
cliLogger.info(`...done`)
}
}
export = command