/** * CLI commands for RealtimeModule * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ import { CLIOptions, Inquirerer, extractFirst } from 'inquirerer'; import { getClient } from '../executor'; import { coerceAnswers, parseFindFirstArgs, parseFindManyArgs, stripUndefined } from '../utils'; import type { FieldSchema } from '../utils'; import type { CreateRealtimeModuleInput, RealtimeModulePatch, RealtimeModuleSelect, RealtimeModuleFilter, RealtimeModuleOrderBy, } from '../../orm/input-types'; import type { FindManyArgs, FindFirstArgs } from '../../orm/select-types'; const fieldSchema: FieldSchema = { apiName: 'string', changeLogTableId: 'uuid', databaseId: 'uuid', id: 'uuid', interval: 'string', listenerNodeTableId: 'uuid', notifyChannel: 'string', premake: 'int', privateApiName: 'string', privateSchemaId: 'uuid', retentionHours: 'int', schemaId: 'uuid', sourceRegistryTableId: 'uuid', subscriptionsSchemaId: 'uuid', }; const usage = '\nrealtime-module \n\nCommands:\n list List realtimeModule records\n find-first Find first matching realtimeModule record\n get Get a realtimeModule by ID\n create Create a new realtimeModule\n update Update an existing realtimeModule\n delete Delete a realtimeModule\n\nList Options:\n --limit Max number of records to return (forward pagination)\n --last Number of records from the end (backward pagination)\n --after Cursor for forward pagination\n --before Cursor for backward pagination\n --offset Number of records to skip\n --select Comma-separated list of fields to return\n --where.. Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.. Condition filter (dot-notation)\n --orderBy Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select Comma-separated list of fields to return\n --where.. Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.. Condition filter (dot-notation)\n --orderBy Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\n --help, -h Show this help message\n'; export default async ( argv: Partial>, prompter: Inquirerer, _options: CLIOptions ) => { if (argv.help || argv.h) { console.log(usage); process.exit(0); } const { first: subcommand, newArgv } = extractFirst(argv); if (!subcommand) { const answer = await prompter.prompt(argv, [ { type: 'autocomplete', name: 'subcommand', message: 'What do you want to do?', options: ['list', 'find-first', 'get', 'create', 'update', 'delete'], }, ]); return handleTableSubcommand(answer.subcommand as string, newArgv, prompter); } return handleTableSubcommand(subcommand, newArgv, prompter); }; async function handleTableSubcommand( subcommand: string, argv: Partial>, prompter: Inquirerer ) { switch (subcommand) { case 'list': return handleList(argv, prompter); case 'find-first': return handleFindFirst(argv, prompter); case 'get': return handleGet(argv, prompter); case 'create': return handleCreate(argv, prompter); case 'update': return handleUpdate(argv, prompter); case 'delete': return handleDelete(argv, prompter); default: console.log(usage); process.exit(1); } } async function handleList(argv: Partial>, _prompter: Inquirerer) { try { const defaultSelect = { apiName: true, changeLogTableId: true, databaseId: true, id: true, interval: true, listenerNodeTableId: true, notifyChannel: true, premake: true, privateApiName: true, privateSchemaId: true, retentionHours: true, schemaId: true, sourceRegistryTableId: true, subscriptionsSchemaId: true, }; const findManyArgs = parseFindManyArgs< FindManyArgs & { select: RealtimeModuleSelect; } >(argv, defaultSelect); const client = getClient(); const result = await client.realtimeModule.findMany(findManyArgs).execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Failed to list records.'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } } async function handleFindFirst(argv: Partial>, _prompter: Inquirerer) { try { const defaultSelect = { apiName: true, changeLogTableId: true, databaseId: true, id: true, interval: true, listenerNodeTableId: true, notifyChannel: true, premake: true, privateApiName: true, privateSchemaId: true, retentionHours: true, schemaId: true, sourceRegistryTableId: true, subscriptionsSchemaId: true, }; const findFirstArgs = parseFindFirstArgs< FindFirstArgs & { select: RealtimeModuleSelect; } >(argv, defaultSelect); const client = getClient(); const result = await client.realtimeModule.findFirst(findFirstArgs).execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Failed to find record.'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } } async function handleGet(argv: Partial>, prompter: Inquirerer) { try { const answers = await prompter.prompt(argv, [ { type: 'text', name: 'id', message: 'id', required: true, }, ]); const client = getClient(); const result = await client.realtimeModule .findOne({ id: answers.id as string, select: { apiName: true, changeLogTableId: true, databaseId: true, id: true, interval: true, listenerNodeTableId: true, notifyChannel: true, premake: true, privateApiName: true, privateSchemaId: true, retentionHours: true, schemaId: true, sourceRegistryTableId: true, subscriptionsSchemaId: true, }, }) .execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Record not found.'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } } async function handleCreate(argv: Partial>, prompter: Inquirerer) { try { const rawAnswers = await prompter.prompt(argv, [ { type: 'text', name: 'apiName', message: 'apiName', required: false, skipPrompt: true, }, { type: 'text', name: 'changeLogTableId', message: 'changeLogTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'databaseId', message: 'databaseId', required: true, }, { type: 'text', name: 'interval', message: 'interval', required: false, skipPrompt: true, }, { type: 'text', name: 'listenerNodeTableId', message: 'listenerNodeTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'notifyChannel', message: 'notifyChannel', required: false, skipPrompt: true, }, { type: 'text', name: 'premake', message: 'premake', required: false, skipPrompt: true, }, { type: 'text', name: 'privateApiName', message: 'privateApiName', required: false, skipPrompt: true, }, { type: 'text', name: 'privateSchemaId', message: 'privateSchemaId', required: false, skipPrompt: true, }, { type: 'text', name: 'retentionHours', message: 'retentionHours', required: false, skipPrompt: true, }, { type: 'text', name: 'schemaId', message: 'schemaId', required: false, skipPrompt: true, }, { type: 'text', name: 'sourceRegistryTableId', message: 'sourceRegistryTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'subscriptionsSchemaId', message: 'subscriptionsSchemaId', required: false, skipPrompt: true, }, ]); const answers = coerceAnswers(rawAnswers, fieldSchema); const cleanedData = stripUndefined( answers, fieldSchema ) as CreateRealtimeModuleInput['realtimeModule']; const client = getClient(); const result = await client.realtimeModule .create({ data: { apiName: cleanedData.apiName, changeLogTableId: cleanedData.changeLogTableId, databaseId: cleanedData.databaseId, interval: cleanedData.interval, listenerNodeTableId: cleanedData.listenerNodeTableId, notifyChannel: cleanedData.notifyChannel, premake: cleanedData.premake, privateApiName: cleanedData.privateApiName, privateSchemaId: cleanedData.privateSchemaId, retentionHours: cleanedData.retentionHours, schemaId: cleanedData.schemaId, sourceRegistryTableId: cleanedData.sourceRegistryTableId, subscriptionsSchemaId: cleanedData.subscriptionsSchemaId, }, select: { apiName: true, changeLogTableId: true, databaseId: true, id: true, interval: true, listenerNodeTableId: true, notifyChannel: true, premake: true, privateApiName: true, privateSchemaId: true, retentionHours: true, schemaId: true, sourceRegistryTableId: true, subscriptionsSchemaId: true, }, }) .execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Failed to create record.'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } } async function handleUpdate(argv: Partial>, prompter: Inquirerer) { try { const rawAnswers = await prompter.prompt(argv, [ { type: 'text', name: 'id', message: 'id', required: true, }, { type: 'text', name: 'apiName', message: 'apiName', required: false, skipPrompt: true, }, { type: 'text', name: 'changeLogTableId', message: 'changeLogTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'databaseId', message: 'databaseId', required: false, }, { type: 'text', name: 'interval', message: 'interval', required: false, skipPrompt: true, }, { type: 'text', name: 'listenerNodeTableId', message: 'listenerNodeTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'notifyChannel', message: 'notifyChannel', required: false, skipPrompt: true, }, { type: 'text', name: 'premake', message: 'premake', required: false, skipPrompt: true, }, { type: 'text', name: 'privateApiName', message: 'privateApiName', required: false, skipPrompt: true, }, { type: 'text', name: 'privateSchemaId', message: 'privateSchemaId', required: false, skipPrompt: true, }, { type: 'text', name: 'retentionHours', message: 'retentionHours', required: false, skipPrompt: true, }, { type: 'text', name: 'schemaId', message: 'schemaId', required: false, skipPrompt: true, }, { type: 'text', name: 'sourceRegistryTableId', message: 'sourceRegistryTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'subscriptionsSchemaId', message: 'subscriptionsSchemaId', required: false, skipPrompt: true, }, ]); const answers = coerceAnswers(rawAnswers, fieldSchema); const cleanedData = stripUndefined(answers, fieldSchema) as RealtimeModulePatch; const client = getClient(); const result = await client.realtimeModule .update({ where: { id: answers.id as string, }, data: { apiName: cleanedData.apiName, changeLogTableId: cleanedData.changeLogTableId, databaseId: cleanedData.databaseId, interval: cleanedData.interval, listenerNodeTableId: cleanedData.listenerNodeTableId, notifyChannel: cleanedData.notifyChannel, premake: cleanedData.premake, privateApiName: cleanedData.privateApiName, privateSchemaId: cleanedData.privateSchemaId, retentionHours: cleanedData.retentionHours, schemaId: cleanedData.schemaId, sourceRegistryTableId: cleanedData.sourceRegistryTableId, subscriptionsSchemaId: cleanedData.subscriptionsSchemaId, }, select: { apiName: true, changeLogTableId: true, databaseId: true, id: true, interval: true, listenerNodeTableId: true, notifyChannel: true, premake: true, privateApiName: true, privateSchemaId: true, retentionHours: true, schemaId: true, sourceRegistryTableId: true, subscriptionsSchemaId: true, }, }) .execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Failed to update record.'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } } async function handleDelete(argv: Partial>, prompter: Inquirerer) { try { const rawAnswers = await prompter.prompt(argv, [ { type: 'text', name: 'id', message: 'id', required: true, }, ]); const answers = coerceAnswers(rawAnswers, fieldSchema); const client = getClient(); const result = await client.realtimeModule .delete({ where: { id: answers.id as string, }, select: { id: true, }, }) .execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Failed to delete record.'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } }