Skip to content

Commit

Permalink
Properly handles notion database internalId
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd committed Jan 17, 2025
1 parent eb949d6 commit 6d95b84
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 69 deletions.
19 changes: 3 additions & 16 deletions front/components/assistant_builder/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import type {
import type { ConnectorProvider } from "@dust-tt/types";
import {
assertNever,
getGoogleSheetTableIdFromContentNodeInternalId,
getMicrosoftSheetContentNodeInternalIdFromTableId,
getNotionDatabaseTableIdFromContentNodeInternalId,
isGoogleSheetContentNodeInternalId,
} from "@dust-tt/types";

Expand Down Expand Up @@ -286,29 +283,19 @@ export function getTableIdForContentNode(
}

switch (dataSource.connectorProvider) {
case "notion":
return getNotionDatabaseTableIdFromContentNodeInternalId(
contentNode.internalId
);

case "google_drive":
if (!isGoogleSheetContentNodeInternalId(contentNode.internalId)) {
throw new Error(
`Google Drive ContentNode internalId ${contentNode.internalId} is not a Google Sheet internal ID`
);
}
return getGoogleSheetTableIdFromContentNodeInternalId(
contentNode.internalId
);

case "microsoft":
return getMicrosoftSheetContentNodeInternalIdFromTableId(
contentNode.internalId
);
return contentNode.internalId;

// For static tables, the tableId is the contentNode internalId.
case null:
case "snowflake":
case "microsoft":
case "notion":
return contentNode.internalId;

case "confluence":
Expand Down
21 changes: 4 additions & 17 deletions front/lib/api/content_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import type {
CoreAPIContentNode,
DataSourceViewType,
} from "@dust-tt/types";
import {
assertNever,
getGoogleSheetContentNodeInternalIdFromTableId,
getMicrosoftSheetContentNodeInternalIdFromTableId,
getNotionDatabaseContentNodeInternalIdFromTableId,
MIME_TYPES,
} from "@dust-tt/types";
import { assertNever, MIME_TYPES } from "@dust-tt/types";

import type { DataSourceViewResource } from "@app/lib/resources/data_source_view_resource";

Expand All @@ -20,18 +14,11 @@ export function getContentNodeInternalIdFromTableId(
const { dataSource } = dataSourceView;

switch (dataSource.connectorProvider) {
case "google_drive":
return getGoogleSheetContentNodeInternalIdFromTableId(tableId);

case "notion":
return getNotionDatabaseContentNodeInternalIdFromTableId(tableId);

case "microsoft":
return getMicrosoftSheetContentNodeInternalIdFromTableId(tableId);

// For static and snowflake tables, the contentNode internalId is the tableId.
case null:
case "microsoft":
case "snowflake":
case "google_drive":
case "notion":
return tableId;

case "intercom":
Expand Down
17 changes: 0 additions & 17 deletions types/src/connectors/google_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export function getGoogleSheetContentNodeInternalId(
return getGoogleSheetTableId(googleFileId, googleSheetId);
}

// Get the Content Node Id for a sheet within a Google Spreadsheet from the
// table ID.
// In this case, the table ID is the same as the Content Node ID.
export function getGoogleSheetContentNodeInternalIdFromTableId(
tableId: string
): string {
return tableId;
}

// Recover the Google-provided file ID and the ID of the sheet within the
// spreadsheet from the Content Node ID of a sheet.
export function getGoogleIdsFromSheetContentNodeInternalId(
Expand All @@ -42,14 +33,6 @@ export function getGoogleIdsFromSheetContentNodeInternalId(
return { googleFileId, googleSheetId };
}

// Get the Table ID for a sheet within a Google Spreadsheet from the
// Content Node ID of the sheet.
export function getGoogleSheetTableIdFromContentNodeInternalId(
internalId: string
): string {
return internalId;
}

// Check if a Content Node ID is a valid Content Node ID for a sheet within a
// Google Spreadsheet.
export function isGoogleSheetContentNodeInternalId(
Expand Down
6 changes: 0 additions & 6 deletions types/src/connectors/microsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ export function microsoftIncrementalSyncWorkflowId(connectorId: ModelId) {
return `microsoft-incrementalSync-${connectorId}`;
}

export function getMicrosoftSheetContentNodeInternalIdFromTableId(
tableId: string
): string {
return tableId;
}

export function microsoftGarbageCollectionWorkflowId(connectorId: ModelId) {
return `microsoft-garbageCollection-${connectorId}`;
}
13 changes: 0 additions & 13 deletions types/src/connectors/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,3 @@ export function getNotionDatabaseTableIdFromContentNodeInternalId(
// so we can just use the same function.
return getNotionDatabaseTableId(internalId);
}

// Recover the Content Node ID for a Notion database (which is also the notion-provided database ID)
// from the Table ID.
export function getNotionDatabaseContentNodeInternalIdFromTableId(
tableId: string
): string {
if (!tableId.startsWith("notion-")) {
throw new Error(
`Invalid tableId format. Expected a tableId in the format notion-<databaseId>`
);
}
return tableId.replace("notion-", "");
}

0 comments on commit 6d95b84

Please sign in to comment.