/** * CLI command for mutation requestDatabase * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ import { CLIOptions, Inquirerer } from 'inquirerer'; import { getClient } from '../executor'; import { unflattenDotNotation, buildSelectFromPaths } from '../utils'; import type { RequestDatabaseVariables } from '../../orm/mutation'; import type { RequestDatabasePayloadSelect } from '../../orm/input-types'; export default async ( argv: Partial>, prompter: Inquirerer, _options: CLIOptions ) => { try { if (argv.help || argv.h) { console.log( "request-database - Requests a database and returns a ticket (database_provision_module row) to poll.\n\nPass exactly one of preset_slug or modules. Pass organization_id to have the organization own the database from the start (the caller must be an owner of that organization); the requesting user is still the identity bootstrapped into the new database. Omit it for a personal database. The pool, presets, and owner bootstrap are private implementation details: a warm pool hit fulfills the ticket immediately (fulfilled_at set, deferred owner bootstrap), otherwise the database is cold-provisioned asynchronously with exactly the requested modules. Poll the ticket until status = 'completed'; it then carries database_id and fulfilled_at.\n\nExample usage:\n SELECT * FROM metaschema_public.request_database('my_app', 'example.com', preset_slug := 'full');\n SELECT * FROM metaschema_public.request_database('my_app', 'example.com', modules := '[\"users_module\", \"emails_module\"]'::jsonb);\n SELECT * FROM metaschema_public.request_database('team_app', 'example.com', preset_slug := 'full', organization_id := '00000000-0000-0000-0000-000000000000'::uuid);\n\nUsage: request-database [OPTIONS]\n" ); process.exit(0); } const answers = await prompter.prompt(argv, [ { type: 'text', name: 'input', message: 'The exclusive input argument for this mutation. An object type, make sure to see documentation for this object\u2019s fields.', required: true, }, ]); const client = getClient(); const parsedAnswers = unflattenDotNotation(answers); const selectFields = buildSelectFromPaths((argv.select as string) ?? 'clientMutationId'); const result = await client.mutation .requestDatabase( parsedAnswers as unknown as RequestDatabaseVariables, { select: selectFields, } as unknown as { select: RequestDatabasePayloadSelect; } ) .execute(); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.error('Failed: requestDatabase'); if (error instanceof Error) { console.error(error.message); } process.exit(1); } };