Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Rico <sferadev@gmail.com>
  • Loading branch information
SferaDev committed Jan 9, 2024
1 parent 2e571e9 commit f6c7a51
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 250 deletions.
20 changes: 4 additions & 16 deletions cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,8 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
async deploySchema(workspace: string, region: string, database: string, branch: string, schema: Schemas.Schema) {
const xata = await this.getXataClient();
const compare = await xata.api.migrations.compareBranchWithUserSchema({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
schema
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { schema }
});

if (compare.edits.operations.length === 0) {
Expand All @@ -601,14 +595,8 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
if (!confirm) return this.exit(1);

await xata.api.migrations.applyBranchSchemaEdit({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
edits: compare.edits
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { edits: compare.edits }
});
}
}
Expand Down
10 changes: 2 additions & 8 deletions cli/src/commands/branch/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ export default class BranchCreate extends BaseCommand<typeof BranchCreate> {

try {
const result = await xata.api.branch.createBranch({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
from
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { from }
});

if (this.jsonEnabled()) return result;
Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ export default class Codegen extends BaseCommand<typeof Codegen> {
flags.branch
);
const branchDetails = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});
const { schema } = branchDetails;

Expand Down
18 changes: 3 additions & 15 deletions cli/src/commands/diff/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,12 @@ export default class Diff extends BaseCommand<typeof Diff> {
const apiRequest =
args.branch && args.base
? xata.api.migrations.compareBranchSchemas({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${args.branch}`,
branchName: args.base
},
pathParams: { workspace, region, dbBranchName: `${database}:${args.branch}`, branchName: args.base },
body: {}
})
: xata.api.migrations.compareBranchWithUserSchema({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
schema: { tables: [] },
schemaOperations
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { schema: { tables: [] }, schemaOperations }
});

const {
Expand Down
26 changes: 5 additions & 21 deletions cli/src/commands/import/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ export default class ImportCSV extends BaseCommand<typeof ImportCSV> {
const xata = await this.getXataClient();
const { workspace, region, database, branch } = await this.parseDatabase();
const { schema: existingSchema } = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});

const newSchema = {
Expand All @@ -226,14 +222,8 @@ export default class ImportCSV extends BaseCommand<typeof ImportCSV> {
};

const { edits } = await xata.api.migrations.compareBranchWithUserSchema({
pathParams: {
workspace,
region,
dbBranchName: `${database}:main`
},
body: {
schema: newSchema
}
pathParams: { workspace, region, dbBranchName: `${database}:main` },
body: { schema: newSchema }
});
if (edits.operations.length > 0) {
const destructiveOperations = edits.operations
Expand Down Expand Up @@ -275,14 +265,8 @@ export default class ImportCSV extends BaseCommand<typeof ImportCSV> {
}

await xata.api.migrations.applyBranchSchemaEdit({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
edits
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { edits }
});
}
}
Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/pull/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export default class Pull extends BaseCommand<typeof Pull> {
);

const { logs } = await xata.api.migrations.getBranchSchemaHistory({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: {
// TODO: Fix pagination in the API to start from last known migration and not from the beginning
// Also paginate until we get all migrations
Expand Down
16 changes: 3 additions & 13 deletions cli/src/commands/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export default class Push extends BaseCommand<typeof Push> {
);

const { logs } = await xata.api.migrations.getBranchSchemaHistory({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: {
// TODO: Fix pagination in the API to start from last known migration and not from the beginning
// Also paginate until we get all migrations
Expand Down Expand Up @@ -74,14 +70,8 @@ export default class Push extends BaseCommand<typeof Push> {

// TODO: Check for errors and print them
await xata.api.migrations.pushBranchMigrations({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
migrations: newMigrations
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { migrations: newMigrations }
});

this.log(`Pushed ${newMigrations.length} migrations to ${branch}`);
Expand Down
17 changes: 3 additions & 14 deletions cli/src/commands/random-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ export default class RandomData extends BaseCommand<typeof RandomData> {
const { workspace, region, database, branch } = await this.getParsedDatabaseURLWithBranch(flags.db, flags.branch);
const xata = await this.getXataClient();
const branchDetails = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});
if (!branchDetails) {
this.error('Could not resolve the current branch');
Expand All @@ -57,15 +53,8 @@ export default class RandomData extends BaseCommand<typeof RandomData> {
const records = generateRandomData(table, totalRecords);

await xata.api.records.bulkInsertTableRecords({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`,
tableName: table.name
},
body: {
records: records as any[]
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table.name },
body: { records: records as any[] }
});

this.info(
Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/rebase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export default class Rebase extends BaseCommand<typeof Rebase> {
this.info(`Rebase command is experimental, use with caution`);

const { logs } = await xata.api.migrations.getBranchSchemaHistory({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: {
// TODO: Fix pagination in the API to start from last known migration and not from the beginning
// Also paginate until we get all migrations
Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/schema/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ export default class SchemaDump extends BaseCommand<typeof SchemaDump> {

const xata = await this.getXataClient();
const branchDetails = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});
if (!branchDetails) return this.error('Could not resolve the current branch');
if (!flags.file) {
Expand Down
16 changes: 3 additions & 13 deletions cli/src/commands/schema/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ Beware that this can lead to ${chalk.bold(

const xata = await this.getXataClient();
const branchDetails = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});
if (!branchDetails) this.error('Could not get the schema from the current branch');

Expand Down Expand Up @@ -812,14 +808,8 @@ vectorDimension: \${vectorDimension}
}

await xata.api.migrations.applyBranchSchemaEdit({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
edits
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { edits }
});

this.success('Migration completed!');
Expand Down
26 changes: 5 additions & 21 deletions cli/src/commands/schema/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export default class UploadSchema extends BaseCommand<typeof UploadSchema> {

if (flags['create-only']) {
const { schema } = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});
if (schema.tables.length > 0) {
this.info(
Expand All @@ -54,14 +50,8 @@ export default class UploadSchema extends BaseCommand<typeof UploadSchema> {
}

const { edits } = await xata.api.migrations.compareBranchWithUserSchema({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
schema
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { schema }
});

if (edits.operations.length === 0) {
Expand All @@ -81,14 +71,8 @@ export default class UploadSchema extends BaseCommand<typeof UploadSchema> {
if (!confirm) return this.exit(1);

await xata.api.migrations.applyBranchSchemaEdit({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
},
body: {
edits
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { edits }
});
}
}
6 changes: 1 addition & 5 deletions cli/src/commands/shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ export default class Shell extends BaseCommand<typeof Shell> {
try {
const xata = await this.getXataClient();
const branchDetails = await xata.api.branch.getBranchDetails({
pathParams: {
workspace,
region,
dbBranchName: `${database}:${branch}`
}
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` }
});
const { schema } = branchDetails;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { beforeAll, describe, expect, test } from 'vitest';
import { XataApiClient } from '../../packages/client/src/api/client';
import { operationsByTag } from '../../packages/client/src/api/components';
import { describe, expect, test } from 'vitest';
import { XataApiClient } from './client';
import { operationsByTag } from './components';

let xata: XataApiClient;

beforeAll(async () => {
xata = new XataApiClient({
apiKey: 'fake-api-key'
});
});
const xata = new XataApiClient({ apiKey: 'fake-api-key' });

describe('API Proxy types', () => {
test('returns functions for all defined namespace operations', () => {
Expand All @@ -19,12 +13,14 @@ describe('API Proxy types', () => {
}
}
});

test('returns undefined for undefined namespaces', () => {
// @ts-ignore
// @ts-expect-error Not a valid namespace
expect(xata.undefinedNamespace).toBeUndefined();
});

test('returns undefined for undefined namespace operations', () => {
// @ts-ignore
// @ts-expect-error Not a valid operation
expect(xata.authentication.undefinedOperation).toBeUndefined();
});
});
11 changes: 2 additions & 9 deletions test/integration/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,8 @@ describe('integration tests', () => {
pathParams: { workspace, region, dbBranchName: `${database}:main`, tableName: 'planes' }
});
await api.table.setTableSchema({
pathParams: {
workspace,
region,
dbBranchName: `${database}:main`,
tableName: 'planes'
},
body: {
columns: [{ name: 'name', type: 'string' }]
}
pathParams: { workspace, region, dbBranchName: `${database}:main`, tableName: 'planes' },
body: { columns: [{ name: 'name', type: 'string' }] }
});

const planes = Array.from({ length: PAGINATION_DEFAULT_SIZE + 50 }, (_, index) => ({ name: `Plane ${index}` }));
Expand Down
Loading

0 comments on commit f6c7a51

Please sign in to comment.