Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connections RPC front end #3543

Merged
merged 7 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mathesar_ui/src/3rd-party-apis/github-releases.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExternalApi } from '@mathesar/api/utils/requestUtils';
import { getExternalApi } from '@mathesar/api/rest/utils/requestUtils';

/**
* GitHub's REST API gives way more info than we have here. See [docs][1]. But
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,6 @@ export interface CommonCreationProps {
nickname: string;
}

export interface CreateFromKnownConnectionProps extends CommonCreationProps {
credentials: { connection: ConnectionReference };
create_database: boolean;
}

/**
* The `create_database` field is not present on this variant because we do not
* support creating the database in this case. The reason for this restriction
* is that we need a valid connection to an existing database in order to first
* create one. In theory, we could ask the user to supply such a connection but
* Sean and Brent deemed that approach to add too much additional complexity to
* the UI to justify its inclusion. We predict that if someone already has a
* PostgreSQL user, they are likely to already have a PostgreSQL database too.
*/
export interface CreateFromScratchProps extends CommonCreationProps {
credentials: {
user: string;
password: string;
host: string;
port: string;
};
}

export interface CreateWithNewUserProps extends CommonCreationProps {
credentials: {
create_user_via: ConnectionReference;
Expand All @@ -77,16 +54,6 @@ export interface CreateWithNewUserProps extends CommonCreationProps {
create_database: boolean;
}

function createFromKnownConnection(props: CreateFromKnownConnectionProps) {
const url = '/api/ui/v0/connections/create_from_known_connection/';
return postAPI<Connection>(url, props);
}

function createFromScratch(props: CreateFromScratchProps) {
const url = '/api/ui/v0/connections/create_from_scratch/';
return postAPI<Connection>(url, props);
}

function createWithNewUser(props: CreateWithNewUserProps) {
const url = '/api/ui/v0/connections/create_with_new_user/';
return postAPI<Connection>(url, props);
Expand Down Expand Up @@ -116,8 +83,6 @@ function deleteConnection(

export default {
list,
createFromKnownConnection,
createFromScratch,
createWithNewUser,
update,
delete: deleteConnection,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PaginatedResponse } from '@mathesar/api/utils/requestUtils';
import type { Column } from '@mathesar/api/types/tables/columns';
import type { JpPath } from '@mathesar/api/types/tables/joinable_tables';
import type { PaginatedResponse } from '@mathesar/api/rest/utils/requestUtils';
import type { Column } from '@mathesar/api/rest/types/tables/columns';
import type { JpPath } from '@mathesar/api/rest/types/tables/joinable_tables';
import type { SchemaEntry } from '@mathesar/AppTypes';

export type QueryColumnAlias = string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PaginatedResponse } from '@mathesar/api/utils/requestUtils';
import type { PaginatedResponse } from '@mathesar/api/rest/utils/requestUtils';
import type { Column } from './tables/columns';

export type MinimalColumnDetails = Pick<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* endpoint: /api/db/v0/tables/<table_id>/joinable_tables/
*/

import type { TableEntry } from '@mathesar/api/types/tables';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Column } from './columns';

type ForeignKeyId = number;
Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions mathesar_ui/src/api/rpc/connections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

export const sampleDataOptions = [
'library_management',
'movie_collection',
] as const;

export type SampleDataSchemaIdentifier = (typeof sampleDataOptions)[number];

export interface Connection {
id: number;
nickname: string;
database: string;
username: string;
host: string;
port: number;
}

export const connections = {
add_from_known_connection: rpcMethodTypeContainer<
{
nickname: Connection['nickname'];
database: Connection['database'];
/** When true, create a new database if needed. Defaults to False. */
create_db?: boolean;
/**
* When present, reuse the credentials from a known connection. When
* omitted, use the credentials from the internal DB server.
*/
connection_id?: Connection['id'];
/** Sample data to load. Defaults to none. */
sample_data?: SampleDataSchemaIdentifier[];
},
Connection
>(),

add_from_scratch: rpcMethodTypeContainer<
{
nickname: Connection['nickname'];
database: Connection['database'];
user: Connection['username'];
password: string;
host: Connection['host'];
port: Connection['port'];
/** Sample data to load. Defaults to none. */
sample_data?: SampleDataSchemaIdentifier[];
},
Connection
>(),
};
13 changes: 13 additions & 0 deletions mathesar_ui/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Cookies from 'js-cookie';

import { buildRpcApi } from '@mathesar/packages/json-rpc-client-builder';
import { connections } from './connections';

/** Mathesar's JSON-RPC API */
export const api = buildRpcApi({
endpoint: '/api/rpc/v0/',
getHeaders: () => ({ 'X-CSRFToken': Cookies.get('csrftoken') }),
methodTree: {
connections,
},
});
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/ModificationStatus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onDestroy } from 'svelte';
import { _ } from 'svelte-i18n';
import { fade } from 'svelte/transition';
import type { RequestStatus } from '@mathesar/api/utils/requestUtils';
import type { RequestStatus } from '@mathesar/api/rest/utils/requestUtils';
import StatusIndicator from './StatusIndicator.svelte';

let incomingRequestState: RequestStatus['state'] | undefined;
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/QueryName.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import type { QueryInstance } from '@mathesar/api/types/queries';
import type { QueryInstance } from '@mathesar/api/rest/types/queries';
import { iconExploration } from '@mathesar/icons';
import NameWithIcon from './NameWithIcon.svelte';

Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/SelectTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { _ } from 'svelte-i18n';
import { Select } from '@mathesar-component-library';
import type { SelectProps } from '@mathesar-component-library/types';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import TableName from './TableName.svelte';

type $$Events = Select<TableEntry | undefined>['$$events_def'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import type { TableEntry } from '@mathesar/api/types/tables';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import { importVerifiedTables } from '@mathesar/stores/tables';
import type { SelectProps } from '@mathesar-component-library/types';
import SelectTable from './SelectTable.svelte';
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/TableName.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { ComponentProps } from 'svelte';

import type { TableEntry } from '@mathesar/api/types/tables';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import { isTableImportConfirmationRequired } from '@mathesar/utils/tables';
import { iconTable } from '@mathesar/icons';
import NameWithIcon from './NameWithIcon.svelte';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CancelOrProceedButtonPair,
} from '@mathesar-component-library';
import { toast } from '@mathesar/stores/toast';
import type { RequestStatus } from '@mathesar/api/utils/requestUtils';
import type { RequestStatus } from '@mathesar/api/rest/utils/requestUtils';
import {
type ColumnWithAbstractType,
type ColumnTypeOptionsSaveArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Writable } from 'svelte/store';
import { _ } from 'svelte-i18n';
import { LabeledInput, Select } from '@mathesar-component-library';
import type { DurationUnit } from '@mathesar/api/types/tables/columns';
import type { DurationUnit } from '@mathesar/api/rest/types/tables/columns';
import type { DurationConfig } from '@mathesar/utils/duration/types';
import type { FormValues } from '@mathesar-component-library/types';
import { DurationSpecification } from '@mathesar/utils/duration';
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/abstract-type-control/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
AbstractTypeDbConfig,
AbstractTypeDisplayConfig,
} from '@mathesar/stores/abstract-types/types';
import type { Column } from '@mathesar/api/types/tables/columns';
import type { Column } from '@mathesar/api/rest/types/tables/columns';
import { readable } from 'svelte/store';
import DurationConfiguration from './config-components/DurationConfiguration.svelte';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { Button, iconSearch, Icon } from '@mathesar-component-library';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import { iconExpandRight } from '@mathesar/icons';
import { getRecordSelectorFromContext } from '@mathesar/systems/record-selector/RecordSelectorController';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { _ } from 'svelte-i18n';
import type { Connection } from '@mathesar/api/connections';
import type { Connection } from '@mathesar/api/rest/connections';
import { iconDatabase, iconConnection } from '@mathesar/icons';
import { getDatabasePageUrl, CONNECTIONS_URL } from '@mathesar/routes/urls';
import { connectionsStore } from '@mathesar/stores/databases';
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/src/components/breadcrumb/EntitySelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
currentTableId,
tables as tablesStore,
} from '@mathesar/stores/tables';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import { getExplorationPageUrl } from '@mathesar/routes/urls';
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import { iconTable } from '@mathesar/icons';
import { queries as queriesStore } from '@mathesar/stores/queries';
import type { QueryInstance } from '@mathesar/api/types/queries';
import type { QueryInstance } from '@mathesar/api/rest/types/queries';
import { getLinkForTableItem } from '@mathesar/utils/tables';
import BreadcrumbSelector from './BreadcrumbSelector.svelte';
import type {
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/src/components/breadcrumb/breadcrumbTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryInstance } from '@mathesar/api/types/queries';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { QueryInstance } from '@mathesar/api/rest/types/queries';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Database, SchemaEntry } from '@mathesar/AppTypes';
import type {
ComponentAndProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BooleanDisplayOptions } from '@mathesar/api/types/tables/columns';
import type { BooleanDisplayOptions } from '@mathesar/api/rest/types/tables/columns';
import type {
ComponentAndProps,
SelectProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
} from '@mathesar-component-library/types';
import type { DBObjectEntry } from '@mathesar/AppTypes';
import type { DateTimeFormatter } from '@mathesar/utils/date-time/types';
import type { Column } from '@mathesar/api/types/tables/columns';
import type { FkConstraint } from '@mathesar/api/types/tables/constraints';
import type { Column } from '@mathesar/api/rest/types/tables/columns';
import type { FkConstraint } from '@mathesar/api/rest/types/tables/constraints';

export type CellColumnLike = Pick<
Column,
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/cell-fabric/data-types/date.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isDefinedNonNullable } from '@mathesar-component-library';
import type { DateDisplayOptions } from '@mathesar/api/types/tables/columns';
import type { DateDisplayOptions } from '@mathesar/api/rest/types/tables/columns';
import type { ComponentAndProps } from '@mathesar-component-library/types';
import {
DateTimeFormatter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isDefinedNonNullable } from '@mathesar-component-library';
import type { TimeStampDisplayOptions } from '@mathesar/api/types/tables/columns';
import type { TimeStampDisplayOptions } from '@mathesar/api/rest/types/tables/columns';
import type { ComponentAndProps } from '@mathesar-component-library/types';
import {
DateTimeFormatter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ComponentAndProps,
FormattedInputProps,
} from '@mathesar-component-library/types';
import type { DurationDisplayOptions } from '@mathesar/api/types/tables/columns';
import type { DurationDisplayOptions } from '@mathesar/api/rest/types/tables/columns';
import {
DurationFormatter,
DurationSpecification,
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/cell-fabric/data-types/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import type {
MoneyColumn,
NumberFormat,
} from '@mathesar/api/types/tables/columns';
} from '@mathesar/api/rest/types/tables/columns';
import type { ComponentAndProps } from '@mathesar-component-library/types';
import MoneyCell from './components/money/MoneyCell.svelte';
import MoneyCellInput from './components/money/MoneyCellInput.svelte';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
NumberColumn,
NumberDisplayOptions,
NumberFormat,
} from '@mathesar/api/types/tables/columns';
} from '@mathesar/api/rest/types/tables/columns';
import NumberCell from './components/number/NumberCell.svelte';
import NumberCellInput from './components/number/NumberCellInput.svelte';
import type { NumberCellExternalProps } from './components/typeDefinitions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ComponentAndProps,
TextInputProps,
} from '@mathesar-component-library/types';
import type { TextTypeOptions } from '@mathesar/api/types/tables/columns';
import type { TextTypeOptions } from '@mathesar/api/rest/types/tables/columns';
import GrowableTextArea from '@mathesar/components/GrowableTextArea.svelte';
import TextAreaCell from './components/textarea/TextAreaCell.svelte';
import TextBoxCell from './components/textbox/TextBoxCell.svelte';
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/cell-fabric/data-types/time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isDefinedNonNullable } from '@mathesar-component-library';
import type { TimeDisplayOptions } from '@mathesar/api/types/tables/columns';
import type { TimeDisplayOptions } from '@mathesar/api/rest/types/tables/columns';
import type { ComponentAndProps } from '@mathesar-component-library/types';
import {
DateTimeFormatter,
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/src/components/cell-fabric/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ComponentAndProps } from '@mathesar-component-library/types';
import type { TableEntry } from '@mathesar/api/types/tables';
import type { Column } from '@mathesar/api/types/tables/columns';
import type { TableEntry } from '@mathesar/api/rest/types/tables';
import type { Column } from '@mathesar/api/rest/types/tables/columns';
import type { CellInfo } from '@mathesar/stores/abstract-types/types';
import type { RecordSummariesForSheet } from '@mathesar/stores/table-data/record-summaries/recordSummaryUtils';
import DataTypes from './data-types';
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/column/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CellColumnLike } from '@mathesar/components/cell-fabric/data-types/typeDefinitions';
import type { ConstraintType } from '@mathesar/api/types/tables/constraints';
import type { ConstraintType } from '@mathesar/api/rest/types/tables/constraints';

// Since the ColumnName component is being used
// in Tables, Queries & DataImport and many more in the future
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/filter-entry/FilterEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import type RecordSummaryStore from '@mathesar/stores/table-data/record-summaries/RecordSummaryStore';
import type { RecordSummariesForColumn } from '@mathesar/stores/table-data/record-summaries/recordSummaryUtils';
import type { ReadableMapLike } from '@mathesar/typeUtils';
import type { ConstraintType } from '@mathesar/api/types/tables/constraints';
import type { ConstraintType } from '@mathesar/api/rest/types/tables/constraints';
import type { FilterEntryColumnLike } from './types';
import { FILTER_INPUT_CLASS, validateFilterEntry } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/filter-entry/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FkConstraint } from '@mathesar/api/types/tables/constraints';
import type { FkConstraint } from '@mathesar/api/rest/types/tables/constraints';
import { isDefinedNonNullable } from '@mathesar-component-library';
import {
getEqualityFiltersForAbstractType,
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
unite,
withSideChannelSubscriptions,
} from '@mathesar-component-library';
import type { RequestStatus } from '@mathesar/api/utils/requestUtils';
import type { RequestStatus } from '@mathesar/api/rest/utils/requestUtils';
import {
comboErrorsKey,
disabledKey,
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/group-entry/GroupEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { iconDeleteMajor } from '@mathesar/icons';
import type { ReadableMapLike } from '@mathesar/typeUtils';
import ColumnName from '@mathesar/components/column/ColumnName.svelte';
import type { ConstraintType } from '@mathesar/api/types/tables/constraints';
import type { ConstraintType } from '@mathesar/api/rest/types/tables/constraints';
import type { GroupEntryColumnLike } from './types';

type T = $$Generic;
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/components/sort-entry/SortEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import ColumnName from '@mathesar/components/column/ColumnName.svelte';
import { iconDeleteMajor } from '@mathesar/icons';
import type { ReadableMapLike } from '@mathesar/typeUtils';
import type { ConstraintType } from '@mathesar/api/types/tables/constraints';
import type { ConstraintType } from '@mathesar/api/rest/types/tables/constraints';
import {
type SortDirection,
allowedSortDirections,
Expand Down
Loading
Loading