/** * CLI commands for LimitsModule * @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 { CreateLimitsModuleInput, LimitsModulePatch, LimitsModuleSelect, LimitsModuleFilter, LimitsModuleOrderBy, } from '../../orm/input-types'; import type { FindManyArgs, FindFirstArgs } from '../../orm/select-types'; const fieldSchema: FieldSchema = { actorTableId: 'uuid', aggregateTableId: 'uuid', apiName: 'string', capCheckTrigger: 'string', creditCodeItemsTableId: 'uuid', creditCodesTableId: 'uuid', creditRedemptionsTableId: 'uuid', databaseId: 'uuid', defaultTableId: 'uuid', defaultTableName: 'string', entityField: 'string', entityTableId: 'uuid', eventsTableId: 'uuid', id: 'uuid', limitAggregateCheckSoftFunction: 'string', limitCapsDefaultsTableId: 'uuid', limitCapsTableId: 'uuid', limitCheckFunction: 'string', limitCheckSoftFunction: 'string', limitCreditsTableId: 'uuid', limitDecrementFunction: 'string', limitDecrementTrigger: 'string', limitDefaults: 'json', limitIncrementFunction: 'string', limitIncrementTrigger: 'string', limitUpdateTrigger: 'string', limitWarningStateTableId: 'uuid', limitWarningsTableId: 'uuid', prefix: 'string', privateApiName: 'string', privateSchemaId: 'uuid', privateSchemaName: 'string', publicSchemaName: 'string', resolveCapFunction: 'string', schemaId: 'uuid', scope: 'string', tableId: 'uuid', tableName: 'string', }; const usage = '\nlimits-module \n\nCommands:\n list List limitsModule records\n find-first Find first matching limitsModule record\n get Get a limitsModule by ID\n create Create a new limitsModule\n update Update an existing limitsModule\n delete Delete a limitsModule\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 = { actorTableId: true, aggregateTableId: true, apiName: true, capCheckTrigger: true, creditCodeItemsTableId: true, creditCodesTableId: true, creditRedemptionsTableId: true, databaseId: true, defaultTableId: true, defaultTableName: true, entityField: true, entityTableId: true, eventsTableId: true, id: true, limitAggregateCheckSoftFunction: true, limitCapsDefaultsTableId: true, limitCapsTableId: true, limitCheckFunction: true, limitCheckSoftFunction: true, limitCreditsTableId: true, limitDecrementFunction: true, limitDecrementTrigger: true, limitDefaults: true, limitIncrementFunction: true, limitIncrementTrigger: true, limitUpdateTrigger: true, limitWarningStateTableId: true, limitWarningsTableId: true, prefix: true, privateApiName: true, privateSchemaId: true, privateSchemaName: true, publicSchemaName: true, resolveCapFunction: true, schemaId: true, scope: true, tableId: true, tableName: true, }; const findManyArgs = parseFindManyArgs< FindManyArgs & { select: LimitsModuleSelect; } >(argv, defaultSelect); const client = getClient(); const result = await client.limitsModule.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 = { actorTableId: true, aggregateTableId: true, apiName: true, capCheckTrigger: true, creditCodeItemsTableId: true, creditCodesTableId: true, creditRedemptionsTableId: true, databaseId: true, defaultTableId: true, defaultTableName: true, entityField: true, entityTableId: true, eventsTableId: true, id: true, limitAggregateCheckSoftFunction: true, limitCapsDefaultsTableId: true, limitCapsTableId: true, limitCheckFunction: true, limitCheckSoftFunction: true, limitCreditsTableId: true, limitDecrementFunction: true, limitDecrementTrigger: true, limitDefaults: true, limitIncrementFunction: true, limitIncrementTrigger: true, limitUpdateTrigger: true, limitWarningStateTableId: true, limitWarningsTableId: true, prefix: true, privateApiName: true, privateSchemaId: true, privateSchemaName: true, publicSchemaName: true, resolveCapFunction: true, schemaId: true, scope: true, tableId: true, tableName: true, }; const findFirstArgs = parseFindFirstArgs< FindFirstArgs & { select: LimitsModuleSelect; } >(argv, defaultSelect); const client = getClient(); const result = await client.limitsModule.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.limitsModule .findOne({ id: answers.id as string, select: { actorTableId: true, aggregateTableId: true, apiName: true, capCheckTrigger: true, creditCodeItemsTableId: true, creditCodesTableId: true, creditRedemptionsTableId: true, databaseId: true, defaultTableId: true, defaultTableName: true, entityField: true, entityTableId: true, eventsTableId: true, id: true, limitAggregateCheckSoftFunction: true, limitCapsDefaultsTableId: true, limitCapsTableId: true, limitCheckFunction: true, limitCheckSoftFunction: true, limitCreditsTableId: true, limitDecrementFunction: true, limitDecrementTrigger: true, limitDefaults: true, limitIncrementFunction: true, limitIncrementTrigger: true, limitUpdateTrigger: true, limitWarningStateTableId: true, limitWarningsTableId: true, prefix: true, privateApiName: true, privateSchemaId: true, privateSchemaName: true, publicSchemaName: true, resolveCapFunction: true, schemaId: true, scope: true, tableId: true, tableName: 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: 'actorTableId', message: 'actorTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'aggregateTableId', message: 'aggregateTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'apiName', message: 'apiName', required: false, skipPrompt: true, }, { type: 'text', name: 'capCheckTrigger', message: 'capCheckTrigger', required: false, skipPrompt: true, }, { type: 'text', name: 'creditCodeItemsTableId', message: 'creditCodeItemsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'creditCodesTableId', message: 'creditCodesTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'creditRedemptionsTableId', message: 'creditRedemptionsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'databaseId', message: 'databaseId', required: true, }, { type: 'text', name: 'defaultTableId', message: 'defaultTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'defaultTableName', message: 'defaultTableName', required: false, skipPrompt: true, }, { type: 'text', name: 'entityField', message: 'entityField', required: false, skipPrompt: true, }, { type: 'text', name: 'entityTableId', message: 'entityTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'eventsTableId', message: 'eventsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitAggregateCheckSoftFunction', message: 'limitAggregateCheckSoftFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCapsDefaultsTableId', message: 'limitCapsDefaultsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCapsTableId', message: 'limitCapsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCheckFunction', message: 'limitCheckFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCheckSoftFunction', message: 'limitCheckSoftFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCreditsTableId', message: 'limitCreditsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitDecrementFunction', message: 'limitDecrementFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitDecrementTrigger', message: 'limitDecrementTrigger', required: false, skipPrompt: true, }, { type: 'json', name: 'limitDefaults', message: 'limitDefaults', required: false, skipPrompt: true, }, { type: 'text', name: 'limitIncrementFunction', message: 'limitIncrementFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitIncrementTrigger', message: 'limitIncrementTrigger', required: false, skipPrompt: true, }, { type: 'text', name: 'limitUpdateTrigger', message: 'limitUpdateTrigger', required: false, skipPrompt: true, }, { type: 'text', name: 'limitWarningStateTableId', message: 'limitWarningStateTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitWarningsTableId', message: 'limitWarningsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'prefix', message: 'prefix', 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: 'privateSchemaName', message: 'privateSchemaName', required: false, skipPrompt: true, }, { type: 'text', name: 'publicSchemaName', message: 'publicSchemaName', required: false, skipPrompt: true, }, { type: 'text', name: 'resolveCapFunction', message: 'resolveCapFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'schemaId', message: 'schemaId', required: false, skipPrompt: true, }, { type: 'text', name: 'scope', message: 'scope', required: true, }, { type: 'text', name: 'tableId', message: 'tableId', required: false, skipPrompt: true, }, { type: 'text', name: 'tableName', message: 'tableName', required: false, skipPrompt: true, }, ]); const answers = coerceAnswers(rawAnswers, fieldSchema); const cleanedData = stripUndefined( answers, fieldSchema ) as CreateLimitsModuleInput['limitsModule']; const client = getClient(); const result = await client.limitsModule .create({ data: { actorTableId: cleanedData.actorTableId, aggregateTableId: cleanedData.aggregateTableId, apiName: cleanedData.apiName, capCheckTrigger: cleanedData.capCheckTrigger, creditCodeItemsTableId: cleanedData.creditCodeItemsTableId, creditCodesTableId: cleanedData.creditCodesTableId, creditRedemptionsTableId: cleanedData.creditRedemptionsTableId, databaseId: cleanedData.databaseId, defaultTableId: cleanedData.defaultTableId, defaultTableName: cleanedData.defaultTableName, entityField: cleanedData.entityField, entityTableId: cleanedData.entityTableId, eventsTableId: cleanedData.eventsTableId, limitAggregateCheckSoftFunction: cleanedData.limitAggregateCheckSoftFunction, limitCapsDefaultsTableId: cleanedData.limitCapsDefaultsTableId, limitCapsTableId: cleanedData.limitCapsTableId, limitCheckFunction: cleanedData.limitCheckFunction, limitCheckSoftFunction: cleanedData.limitCheckSoftFunction, limitCreditsTableId: cleanedData.limitCreditsTableId, limitDecrementFunction: cleanedData.limitDecrementFunction, limitDecrementTrigger: cleanedData.limitDecrementTrigger, limitDefaults: cleanedData.limitDefaults, limitIncrementFunction: cleanedData.limitIncrementFunction, limitIncrementTrigger: cleanedData.limitIncrementTrigger, limitUpdateTrigger: cleanedData.limitUpdateTrigger, limitWarningStateTableId: cleanedData.limitWarningStateTableId, limitWarningsTableId: cleanedData.limitWarningsTableId, prefix: cleanedData.prefix, privateApiName: cleanedData.privateApiName, privateSchemaId: cleanedData.privateSchemaId, privateSchemaName: cleanedData.privateSchemaName, publicSchemaName: cleanedData.publicSchemaName, resolveCapFunction: cleanedData.resolveCapFunction, schemaId: cleanedData.schemaId, scope: cleanedData.scope, tableId: cleanedData.tableId, tableName: cleanedData.tableName, }, select: { actorTableId: true, aggregateTableId: true, apiName: true, capCheckTrigger: true, creditCodeItemsTableId: true, creditCodesTableId: true, creditRedemptionsTableId: true, databaseId: true, defaultTableId: true, defaultTableName: true, entityField: true, entityTableId: true, eventsTableId: true, id: true, limitAggregateCheckSoftFunction: true, limitCapsDefaultsTableId: true, limitCapsTableId: true, limitCheckFunction: true, limitCheckSoftFunction: true, limitCreditsTableId: true, limitDecrementFunction: true, limitDecrementTrigger: true, limitDefaults: true, limitIncrementFunction: true, limitIncrementTrigger: true, limitUpdateTrigger: true, limitWarningStateTableId: true, limitWarningsTableId: true, prefix: true, privateApiName: true, privateSchemaId: true, privateSchemaName: true, publicSchemaName: true, resolveCapFunction: true, schemaId: true, scope: true, tableId: true, tableName: 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: 'actorTableId', message: 'actorTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'aggregateTableId', message: 'aggregateTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'apiName', message: 'apiName', required: false, skipPrompt: true, }, { type: 'text', name: 'capCheckTrigger', message: 'capCheckTrigger', required: false, skipPrompt: true, }, { type: 'text', name: 'creditCodeItemsTableId', message: 'creditCodeItemsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'creditCodesTableId', message: 'creditCodesTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'creditRedemptionsTableId', message: 'creditRedemptionsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'databaseId', message: 'databaseId', required: false, }, { type: 'text', name: 'defaultTableId', message: 'defaultTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'defaultTableName', message: 'defaultTableName', required: false, skipPrompt: true, }, { type: 'text', name: 'entityField', message: 'entityField', required: false, skipPrompt: true, }, { type: 'text', name: 'entityTableId', message: 'entityTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'eventsTableId', message: 'eventsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitAggregateCheckSoftFunction', message: 'limitAggregateCheckSoftFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCapsDefaultsTableId', message: 'limitCapsDefaultsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCapsTableId', message: 'limitCapsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCheckFunction', message: 'limitCheckFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCheckSoftFunction', message: 'limitCheckSoftFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitCreditsTableId', message: 'limitCreditsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitDecrementFunction', message: 'limitDecrementFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitDecrementTrigger', message: 'limitDecrementTrigger', required: false, skipPrompt: true, }, { type: 'json', name: 'limitDefaults', message: 'limitDefaults', required: false, skipPrompt: true, }, { type: 'text', name: 'limitIncrementFunction', message: 'limitIncrementFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'limitIncrementTrigger', message: 'limitIncrementTrigger', required: false, skipPrompt: true, }, { type: 'text', name: 'limitUpdateTrigger', message: 'limitUpdateTrigger', required: false, skipPrompt: true, }, { type: 'text', name: 'limitWarningStateTableId', message: 'limitWarningStateTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'limitWarningsTableId', message: 'limitWarningsTableId', required: false, skipPrompt: true, }, { type: 'text', name: 'prefix', message: 'prefix', 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: 'privateSchemaName', message: 'privateSchemaName', required: false, skipPrompt: true, }, { type: 'text', name: 'publicSchemaName', message: 'publicSchemaName', required: false, skipPrompt: true, }, { type: 'text', name: 'resolveCapFunction', message: 'resolveCapFunction', required: false, skipPrompt: true, }, { type: 'text', name: 'schemaId', message: 'schemaId', required: false, skipPrompt: true, }, { type: 'text', name: 'scope', message: 'scope', required: false, }, { type: 'text', name: 'tableId', message: 'tableId', required: false, skipPrompt: true, }, { type: 'text', name: 'tableName', message: 'tableName', required: false, skipPrompt: true, }, ]); const answers = coerceAnswers(rawAnswers, fieldSchema); const cleanedData = stripUndefined(answers, fieldSchema) as LimitsModulePatch; const client = getClient(); const result = await client.limitsModule .update({ where: { id: answers.id as string, }, data: { actorTableId: cleanedData.actorTableId, aggregateTableId: cleanedData.aggregateTableId, apiName: cleanedData.apiName, capCheckTrigger: cleanedData.capCheckTrigger, creditCodeItemsTableId: cleanedData.creditCodeItemsTableId, creditCodesTableId: cleanedData.creditCodesTableId, creditRedemptionsTableId: cleanedData.creditRedemptionsTableId, databaseId: cleanedData.databaseId, defaultTableId: cleanedData.defaultTableId, defaultTableName: cleanedData.defaultTableName, entityField: cleanedData.entityField, entityTableId: cleanedData.entityTableId, eventsTableId: cleanedData.eventsTableId, limitAggregateCheckSoftFunction: cleanedData.limitAggregateCheckSoftFunction, limitCapsDefaultsTableId: cleanedData.limitCapsDefaultsTableId, limitCapsTableId: cleanedData.limitCapsTableId, limitCheckFunction: cleanedData.limitCheckFunction, limitCheckSoftFunction: cleanedData.limitCheckSoftFunction, limitCreditsTableId: cleanedData.limitCreditsTableId, limitDecrementFunction: cleanedData.limitDecrementFunction, limitDecrementTrigger: cleanedData.limitDecrementTrigger, limitDefaults: cleanedData.limitDefaults, limitIncrementFunction: cleanedData.limitIncrementFunction, limitIncrementTrigger: cleanedData.limitIncrementTrigger, limitUpdateTrigger: cleanedData.limitUpdateTrigger, limitWarningStateTableId: cleanedData.limitWarningStateTableId, limitWarningsTableId: cleanedData.limitWarningsTableId, prefix: cleanedData.prefix, privateApiName: cleanedData.privateApiName, privateSchemaId: cleanedData.privateSchemaId, privateSchemaName: cleanedData.privateSchemaName, publicSchemaName: cleanedData.publicSchemaName, resolveCapFunction: cleanedData.resolveCapFunction, schemaId: cleanedData.schemaId, scope: cleanedData.scope, tableId: cleanedData.tableId, tableName: cleanedData.tableName, }, select: { actorTableId: true, aggregateTableId: true, apiName: true, capCheckTrigger: true, creditCodeItemsTableId: true, creditCodesTableId: true, creditRedemptionsTableId: true, databaseId: true, defaultTableId: true, defaultTableName: true, entityField: true, entityTableId: true, eventsTableId: true, id: true, limitAggregateCheckSoftFunction: true, limitCapsDefaultsTableId: true, limitCapsTableId: true, limitCheckFunction: true, limitCheckSoftFunction: true, limitCreditsTableId: true, limitDecrementFunction: true, limitDecrementTrigger: true, limitDefaults: true, limitIncrementFunction: true, limitIncrementTrigger: true, limitUpdateTrigger: true, limitWarningStateTableId: true, limitWarningsTableId: true, prefix: true, privateApiName: true, privateSchemaId: true, privateSchemaName: true, publicSchemaName: true, resolveCapFunction: true, schemaId: true, scope: true, tableId: true, tableName: 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.limitsModule .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); } }