feat(dynamodb): support querying, editing, and exporting
This commit is contained in:
73 files changed
+4493
-134
No files matched your search
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { formatDocumentStoreIdLabel, serializeDocumentStoreId } from "@/lib/app/documentJsonValues";
|
||||
import { buildDocumentFilterCondition, currentDocumentFilterJson, documentStoreProviderFor } from "@/lib/app/documentStoreProvider";
|
||||
import { applyDocumentStoreIdentityPlan, insertDocumentStoreDocument } from "@/lib/app/documentStoreSave";
|
||||
|
||||
describe("DynamoDB document store provider", () => {
|
||||
it("uses a dedicated provider and describes a cursor-backed read", () => {
|
||||
const provider = documentStoreProviderFor("dynamodb");
|
||||
|
||||
expect(provider.kind).toBe("dynamodb");
|
||||
expect(
|
||||
provider.queryPreview({
|
||||
collection: "orders",
|
||||
filterJson: '{"tenant_id":"tenant-a","$index":"by_status"}',
|
||||
sortJson: '{"created_at":-1}',
|
||||
skip: 100,
|
||||
limit: 50,
|
||||
}),
|
||||
).toContain('DBX DYNAMODB QUERY / SCAN\ntable: "orders"\nlimit: 50');
|
||||
});
|
||||
|
||||
it("keeps composite key identity and large-number wrappers intact", () => {
|
||||
const id = {
|
||||
tenant_id: "tenant-a",
|
||||
sequence: { $dbxDynamoDb: { version: 1, type: "number", value: "9007199254740993" } },
|
||||
};
|
||||
|
||||
expect(serializeDocumentStoreId(id, "dynamodb")).toBe('{"tenant_id":"tenant-a","sequence":{"$dbxDynamoDb":{"version":1,"type":"number","value":"9007199254740993"}}}');
|
||||
expect(formatDocumentStoreIdLabel(id, "dynamodb")).toBe('{"tenant_id":"tenant-a","sequence":{"$dbxDynamoDb":{"version":1,"type":"number","value":"9007199254740993"}}}');
|
||||
});
|
||||
|
||||
it("builds DynamoDB-compatible structured filters", () => {
|
||||
expect(currentDocumentFilterJson("", { amount: { $gte: 50 } }, "dynamodb")).toBe('{"amount":{"$gte":50}}');
|
||||
expect(buildDocumentFilterCondition({ id: "contains", fieldName: "customer", mode: "like", rawValue: "Acme", conjunction: "AND" }, { kind: "dynamodb" })).toEqual({ customer: { $contains: "Acme" } });
|
||||
expect(buildDocumentFilterCondition({ id: "not-contains", fieldName: "customer", mode: "not-like", rawValue: "Test", conjunction: "AND" }, { kind: "dynamodb" })).toEqual({ customer: { $notContains: "Test" } });
|
||||
});
|
||||
|
||||
it("uses conditional insert semantics even when a new item has an explicit identity", async () => {
|
||||
const insert = vi.fn(async () => "created");
|
||||
const update = vi.fn(async () => 1);
|
||||
|
||||
await insertDocumentStoreDocument({
|
||||
kind: "dynamodb",
|
||||
explicitId: '{"tenant_id":"tenant-a","order_id":"order-1001"}',
|
||||
document: { tenant_id: "tenant-a", order_id: "order-1001", amount: 42 },
|
||||
apis: { insert, update },
|
||||
});
|
||||
|
||||
expect(insert).toHaveBeenCalledWith('{"tenant_id":"tenant-a","order_id":"order-1001","amount":42}', undefined);
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("delegates a DynamoDB rekey to one atomic backend update", async () => {
|
||||
const calls: string[] = [];
|
||||
const insert = vi.fn(async () => {
|
||||
calls.push("insert");
|
||||
return "created";
|
||||
});
|
||||
const update = vi.fn(async () => {
|
||||
calls.push("update");
|
||||
return 1;
|
||||
});
|
||||
const remove = vi.fn(async () => {
|
||||
calls.push("delete");
|
||||
return 1;
|
||||
});
|
||||
|
||||
await applyDocumentStoreIdentityPlan({
|
||||
kind: "dynamodb",
|
||||
plan: {
|
||||
action: "rekey",
|
||||
writeId: '{"tenant_id":"tenant-a","order_id":"order-1002"}',
|
||||
deleteId: '{"tenant_id":"tenant-a","order_id":"order-1001"}',
|
||||
},
|
||||
document: { tenant_id: "tenant-a", order_id: "order-1002", amount: 42 },
|
||||
apis: { insert, update, delete: remove },
|
||||
});
|
||||
|
||||
expect(calls).toEqual(["update"]);
|
||||
expect(update).toHaveBeenCalledWith('{"tenant_id":"tenant-a","order_id":"order-1001"}', '{"tenant_id":"tenant-a","order_id":"order-1002","amount":42}', undefined);
|
||||
expect(insert).not.toHaveBeenCalled();
|
||||
expect(remove).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { connectionDisplayUrlScheme, connectionUrlPlaceholder } from "@/lib/connection/connectionPresentation";
|
||||
import { applyParsedConnectionUrl, parseConnectionUrl } from "@/lib/connection/connectionUrl";
|
||||
import { connectionCanChooseVisibleDatabases } from "@/lib/connection/connectionVisibleDatabases";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
describe("DynamoDB connection presentation", () => {
|
||||
it("uses a DynamoDB endpoint URL as the connection placeholder", () => {
|
||||
expect(connectionUrlPlaceholder("dynamodb")).toBe("https://dynamodb.us-east-1.amazonaws.com");
|
||||
expect(connectionDisplayUrlScheme({ db_type: "dynamodb", ssl: true })).toBe("https");
|
||||
expect(connectionDisplayUrlScheme({ db_type: "dynamodb", ssl: false })).toBe("http");
|
||||
});
|
||||
|
||||
it("parses an HTTPS endpoint while DynamoDB is selected", () => {
|
||||
expect(parseConnectionUrl("https://dynamodb.eu-west-1.amazonaws.com", "dynamodb")).toMatchObject({
|
||||
dbType: "dynamodb",
|
||||
driverProfile: "dynamodb",
|
||||
host: "dynamodb.eu-west-1.amazonaws.com",
|
||||
port: 443,
|
||||
database: "eu-west-1",
|
||||
ssl: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the selected region for a custom endpoint URL", () => {
|
||||
const parsed = parseConnectionUrl("http://127.0.0.1:8000", "dynamodb");
|
||||
const config = applyParsedConnectionUrl(
|
||||
{
|
||||
db_type: "dynamodb",
|
||||
driver_profile: "dynamodb",
|
||||
name: "DynamoDB Local",
|
||||
host: "127.0.0.1",
|
||||
port: 8000,
|
||||
username: "local",
|
||||
password: "local",
|
||||
database: "ap-southeast-1",
|
||||
} as Omit<ConnectionConfig, "id">,
|
||||
parsed,
|
||||
);
|
||||
|
||||
expect(config.database).toBe("ap-southeast-1");
|
||||
expect(config.username).toBe("local");
|
||||
expect(config.password).toBe("local");
|
||||
});
|
||||
|
||||
it("does not offer database visibility selection", () => {
|
||||
expect(connectionCanChooseVisibleDatabases({ db_type: "dynamodb" })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -5,8 +5,10 @@ describe("databaseDriverManifest", () => {
|
||||
it("uses agent cursor only for agent or external runtimes", () => {
|
||||
expect(databaseRuntimeMode("gaussdb")).toBe("native");
|
||||
expect(databaseRuntimeMode("meilisearch")).toBe("native");
|
||||
expect(databaseRuntimeMode("dynamodb")).toBe("native");
|
||||
expect(usesAgentCursorForQuery("gaussdb")).toBe(false);
|
||||
expect(usesAgentCursorForQuery("meilisearch")).toBe(false);
|
||||
expect(usesAgentCursorForQuery("dynamodb")).toBe(false);
|
||||
expect(usesAgentCursorForQuery("mysql")).toBe(false);
|
||||
expect(usesAgentCursorForQuery("jdbc")).toBe(true);
|
||||
expect(usesAgentCursorForQuery("prestosql")).toBe(true);
|
||||
|
||||
@@ -28,6 +28,7 @@ describe("sidebar tree item layout", () => {
|
||||
});
|
||||
|
||||
it("renders navigation leaf actions without expanders", () => {
|
||||
expect(canTreeNodeShowExpander({ type: "dynamodb-table", childCount: 0 })).toBe(false);
|
||||
expect(canTreeNodeShowExpander({ type: "nacos-namespace", childCount: 0 })).toBe(false);
|
||||
expect(canTreeNodeShowExpander({ type: "nacos-access-control", childCount: 0 })).toBe(false);
|
||||
expect(canTreeNodeShowExpander({ type: "etcd-root", childCount: 0 })).toBe(false);
|
||||
|
||||
@@ -12,6 +12,11 @@ import {
|
||||
} from "@/lib/sidebar/treeNodeClick";
|
||||
|
||||
describe("treeNodeClick", () => {
|
||||
it("opens DynamoDB tables in the document browser on single or double activation", () => {
|
||||
expect(treeNodeRowAction("dynamodb-table", false, "single", "dynamodb")).toBe("toggle");
|
||||
expect(treeNodeRowDoubleClickAction("dynamodb-table", false, "double", false, "dynamodb")).toBe("toggle");
|
||||
});
|
||||
|
||||
it("opens synonym nodes as synonym source", () => {
|
||||
expect(objectSourceKindForTreeNode("synonym")).toBe("SYNONYM");
|
||||
expect(treeNodeRowAction("synonym", false)).toBe("open-source");
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { classifySqlRisk } from "@/lib/sql/sqlRisk";
|
||||
|
||||
describe("DynamoDB statement risk", () => {
|
||||
it("treats generated scan statements as reads", () => {
|
||||
expect(classifySqlRisk('DBX DYNAMODB SCAN\ntable: "orders"\nlimit: 1000', { dialect: "dynamodb" }).risk).toBe("read");
|
||||
expect(classifySqlRisk('DBX DYNAMODB QUERY / SCAN\ntable: "orders"\nfilter:\n{"status":"SHIPPED"}', { dialect: "dynamodb" }).risk).toBe("read");
|
||||
});
|
||||
|
||||
it("treats generated item changes as writes", () => {
|
||||
for (const operation of ["INSERT ITEM", "PUT ITEM", "DELETE ITEM"]) {
|
||||
expect(classifySqlRisk(`DBX DYNAMODB ${operation}\ntable: "orders"`, { dialect: "dynamodb" }).risk).toBe("write");
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps unknown DynamoDB operations unsafe", () => {
|
||||
expect(classifySqlRisk('DBX DYNAMODB UNKNOWN\ntable: "orders"', { dialect: "dynamodb" }).risk).toBe("unknown");
|
||||
});
|
||||
});
|
||||
@@ -42,9 +42,16 @@ export function serializeDocumentStoreId(value: unknown, kind: DocumentStoreKind
|
||||
if (kind !== "mongodb" && isLosslessJsonNumber(value)) return value.raw;
|
||||
if (kind === "elasticsearch") return String(value);
|
||||
if (kind === "meilisearch") return typeof value === "string" ? `__dbx_meilisearch_string_id__${JSON.stringify(value)}` : String(value);
|
||||
if (kind === "dynamodb") return stringifyJsonPreservingLargeNumbers(value);
|
||||
return serializeMongoDocumentId(value);
|
||||
}
|
||||
|
||||
export function formatDocumentStoreIdLabel(value: unknown, kind: DocumentStoreKind): string {
|
||||
if (value === null || value === undefined) return "";
|
||||
if (typeof value === "object") return stringifyDocumentStoreValue(value, kind);
|
||||
return String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a whole document JSON payload for MongoDB / Elasticsearch editors.
|
||||
* Accepts standard JSON and Extended JSON objects; rejects non-object roots.
|
||||
|
||||
@@ -4,7 +4,7 @@ import { isElasticsearchCompatibleDatabaseType, isMeilisearchDatabaseType, type
|
||||
import { quoteUnquotedObjectKeys } from "@/lib/mongo/mongoShellCommand";
|
||||
import { formatMongoShellLiteral } from "@/lib/mongo/mongoDocumentValues";
|
||||
|
||||
export type DocumentStoreKind = "mongodb" | "elasticsearch" | "meilisearch";
|
||||
export type DocumentStoreKind = "mongodb" | "dynamodb" | "elasticsearch" | "meilisearch";
|
||||
export type DocumentFilterMode = "equals" | "not-equals" | "like" | "not-like" | "greater-than" | "greater-than-or-equal" | "less-than" | "less-than-or-equal" | "is-null" | "is-not-null";
|
||||
export type DocumentFilterValueType = "auto" | "string" | "number" | "boolean" | "object-id" | "date" | "int32" | "int64" | "decimal128" | "json";
|
||||
export type ElasticsearchBoolClause = "filter" | "must" | "should" | "must_not";
|
||||
@@ -150,6 +150,23 @@ const meilisearchDocumentProvider: DocumentStoreProvider = {
|
||||
sortInputForColumn: mongoDocumentProvider.sortInputForColumn,
|
||||
};
|
||||
|
||||
const dynamodbDocumentProvider: DocumentStoreProvider = {
|
||||
kind: "dynamodb",
|
||||
filterInputLabel: "filter",
|
||||
sortInputLabel: "sort key",
|
||||
documentsLabel: ({ total, totalIsExact, t }) => `${totalIsExact ? "" : "≥"}${t("dynamodb.items", { count: total })}`,
|
||||
queryPreview: ({ collection, filterJson, sortJson, limit }) => {
|
||||
const filter = documentStorePreviewJson(filterJson);
|
||||
const sort = documentStorePreviewJson(sortJson);
|
||||
const operation = filterJson?.includes('"$index"') || (filterJson && filterJson !== "{}") ? "QUERY / SCAN" : "SCAN";
|
||||
const lines = [`DBX DYNAMODB ${operation}`, `table: ${JSON.stringify(collection)}`, `limit: ${limit}`];
|
||||
if (filter) lines.push("filter:", filter);
|
||||
if (sort) lines.push("sort:", sort);
|
||||
return lines.join("\n");
|
||||
},
|
||||
sortInputForColumn: mongoDocumentProvider.sortInputForColumn,
|
||||
};
|
||||
|
||||
function documentStorePreviewJson(value?: string): string | null {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed || trimmed === "{}") return null;
|
||||
@@ -161,6 +178,7 @@ function documentStorePreviewJson(value?: string): string | null {
|
||||
}
|
||||
|
||||
export function documentStoreProviderFor(databaseType?: DatabaseType): DocumentStoreProvider {
|
||||
if (databaseType === "dynamodb") return dynamodbDocumentProvider;
|
||||
if (isElasticsearchCompatibleDatabaseType(databaseType)) return elasticsearchDocumentProvider;
|
||||
if (isMeilisearchDatabaseType(databaseType)) return meilisearchDocumentProvider;
|
||||
return mongoDocumentProvider;
|
||||
@@ -482,8 +500,10 @@ export function buildDocumentFilterCondition(rule: DocumentFilterRule, options:
|
||||
case "not-equals":
|
||||
return { [rule.fieldName]: { $ne: value } };
|
||||
case "like":
|
||||
if (options.kind === "dynamodb") return { [rule.fieldName]: { $contains: value } };
|
||||
return { [rule.fieldName]: { $regex: escapeRegexLiteral(textValue), $options: "i" } };
|
||||
case "not-like":
|
||||
if (options.kind === "dynamodb") return { [rule.fieldName]: { $notContains: value } };
|
||||
return { [rule.fieldName]: { $not: { $regex: escapeRegexLiteral(textValue), $options: "i" } } };
|
||||
case "greater-than":
|
||||
return { [rule.fieldName]: { $gt: value } };
|
||||
@@ -670,6 +690,7 @@ type DocumentQueryInputNormalizer = (input: string) => string | null;
|
||||
|
||||
const documentQueryInputNormalizers: Record<DocumentStoreKind, DocumentQueryInputNormalizer> = {
|
||||
mongodb: normalizeJsonArgument,
|
||||
dynamodb: quoteUnquotedObjectKeys,
|
||||
elasticsearch: quoteUnquotedObjectKeys,
|
||||
meilisearch: quoteUnquotedObjectKeys,
|
||||
};
|
||||
|
||||
@@ -37,12 +37,26 @@ export async function writeDocumentStoreDocument(options: { kind: DocumentStoreK
|
||||
|
||||
/**
|
||||
* Apply an identity plan for an existing document save.
|
||||
* Rekey always writes first, then deletes the old identity — a failed write never deletes.
|
||||
* DynamoDB rekeys atomically in the backend. Other stores write first, then
|
||||
* delete the old identity so a failed write never deletes the source.
|
||||
* Plan coordinates are assumed distinct for rekey (same identity is always `replace`).
|
||||
*/
|
||||
export async function applyDocumentStoreIdentityPlan(options: { kind: DocumentStoreKind; plan: DocumentStoreIdentityPlan; document: Record<string, unknown>; apis: DocumentStoreWriteApis }): Promise<void> {
|
||||
const { kind, plan, document, apis } = options;
|
||||
|
||||
// DynamoDB handles both same-key replacement and key migration in the
|
||||
// backend. Rekey uses one TransactWriteItems request, keyed by the old id.
|
||||
if (kind === "dynamodb") {
|
||||
await writeDocumentStoreDocument({
|
||||
kind,
|
||||
op: "put",
|
||||
id: plan.action === "rekey" ? plan.deleteId : plan.writeId,
|
||||
document,
|
||||
apis,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (plan.action === "replace") {
|
||||
await writeDocumentStoreDocument({
|
||||
kind,
|
||||
@@ -55,7 +69,6 @@ export async function applyDocumentStoreIdentityPlan(options: { kind: DocumentSt
|
||||
return;
|
||||
}
|
||||
|
||||
// Path-identity stores write under the new id first; Mongo inserts a new document.
|
||||
if (kind !== "mongodb") {
|
||||
await writeDocumentStoreDocument({
|
||||
kind,
|
||||
@@ -81,7 +94,7 @@ export async function applyDocumentStoreIdentityPlan(options: { kind: DocumentSt
|
||||
/** Insert a new document (optional explicit path identity uses put). */
|
||||
export async function insertDocumentStoreDocument(options: { kind: DocumentStoreKind; document: Record<string, unknown>; explicitId?: string | null; routing?: string; apis: Pick<DocumentStoreWriteApis, "insert" | "update"> }): Promise<void> {
|
||||
const { kind, document, explicitId, routing, apis } = options;
|
||||
if (kind !== "mongodb" && explicitId) {
|
||||
if (kind !== "mongodb" && kind !== "dynamodb" && explicitId) {
|
||||
await writeDocumentStoreDocument({
|
||||
kind,
|
||||
op: "put",
|
||||
|
||||
@@ -698,6 +698,8 @@ export const mongoDropCollection = forward("mongoDropCollection");
|
||||
export const mongoRenameCollection = forward("mongoRenameCollection");
|
||||
export const mongoCloneCollection = forward("mongoCloneCollection");
|
||||
export const documentFindDocuments = forward("documentFindDocuments");
|
||||
export const documentCountDocuments = forward("documentCountDocuments");
|
||||
export const dynamodbDescribeTable = forward("dynamodbDescribeTable");
|
||||
export const elasticsearchCountDocuments = forward("elasticsearchCountDocuments");
|
||||
export const mongoFindDocuments = forward("mongoFindDocuments");
|
||||
export const mongoParseShellCommand = forward("mongoParseShellCommand");
|
||||
@@ -856,6 +858,9 @@ export type {
|
||||
EtcdPreflightResponse,
|
||||
EtcdDangerousApproval,
|
||||
DocumentQueryResult,
|
||||
DynamoDbKeyInfo,
|
||||
DynamoDbIndexInfo,
|
||||
DynamoDbTableDescription,
|
||||
MongoDocumentResult,
|
||||
HistoryEntry,
|
||||
HistoryConnectionFilter,
|
||||
|
||||
@@ -98,6 +98,7 @@ import type {
|
||||
EtcdWatchPollResponse,
|
||||
EtcdLeaseListResponse,
|
||||
DocumentQueryResult,
|
||||
DynamoDbTableDescription,
|
||||
MongoDocumentResult,
|
||||
MongoCollectionStatsResult,
|
||||
MongoCloneCollectionResult,
|
||||
@@ -3561,7 +3562,7 @@ export async function mongoFindOne(connectionId: string, database: string, colle
|
||||
});
|
||||
}
|
||||
|
||||
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, collation?: string, executionId?: string): Promise<DocumentQueryResult> {
|
||||
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, collation?: string, executionId?: string, cursor?: string): Promise<DocumentQueryResult> {
|
||||
return post("/api/document-store/find-documents", {
|
||||
connectionId,
|
||||
database,
|
||||
@@ -3572,10 +3573,24 @@ export async function documentFindDocuments(connectionId: string, database: stri
|
||||
projection,
|
||||
sort,
|
||||
collation,
|
||||
cursor,
|
||||
executionId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function documentCountDocuments(connectionId: string, collection: string, filter?: string, executionId?: string): Promise<number> {
|
||||
return post("/api/document-store/count-documents", {
|
||||
connectionId,
|
||||
collection,
|
||||
filter,
|
||||
executionId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function dynamodbDescribeTable(connectionId: string, table: string): Promise<DynamoDbTableDescription> {
|
||||
return post("/api/document-store/dynamodb-describe-table", { connectionId, table });
|
||||
}
|
||||
|
||||
export async function elasticsearchCountDocuments(connectionId: string, index: string, filter?: string, executionId?: string): Promise<number> {
|
||||
return post("/api/document-store/elasticsearch-count-documents", {
|
||||
connectionId,
|
||||
|
||||
@@ -3286,6 +3286,31 @@ export interface DocumentQueryResult {
|
||||
extended_documents?: any[];
|
||||
total: number;
|
||||
total_is_exact?: boolean;
|
||||
next_cursor?: string;
|
||||
}
|
||||
|
||||
export interface DynamoDbKeyInfo {
|
||||
name: string;
|
||||
attributeType: "S" | "N" | "B" | string;
|
||||
}
|
||||
|
||||
export interface DynamoDbIndexInfo {
|
||||
name: string;
|
||||
kind: "global" | "local" | string;
|
||||
partitionKey: DynamoDbKeyInfo;
|
||||
sortKey?: DynamoDbKeyInfo;
|
||||
projectionType: "ALL" | "KEYS_ONLY" | "INCLUDE" | string;
|
||||
nonKeyAttributes: string[];
|
||||
}
|
||||
|
||||
export interface DynamoDbTableDescription {
|
||||
name: string;
|
||||
status: string;
|
||||
itemCount: number;
|
||||
sizeBytes: number;
|
||||
partitionKey: DynamoDbKeyInfo;
|
||||
sortKey?: DynamoDbKeyInfo;
|
||||
indexes: DynamoDbIndexInfo[];
|
||||
}
|
||||
|
||||
// Kept for callers that are specifically using MongoDB APIs.
|
||||
@@ -3448,7 +3473,7 @@ export async function mongoParseShellCommand(source: string): Promise<MongoComma
|
||||
return normalizeRustMongoCommand(raw);
|
||||
}
|
||||
|
||||
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, collation?: string, executionId?: string): Promise<DocumentQueryResult> {
|
||||
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, collation?: string, executionId?: string, cursor?: string): Promise<DocumentQueryResult> {
|
||||
return invoke("document_find_documents", {
|
||||
connectionId,
|
||||
database,
|
||||
@@ -3459,10 +3484,24 @@ export async function documentFindDocuments(connectionId: string, database: stri
|
||||
projection,
|
||||
sort,
|
||||
collation,
|
||||
cursor,
|
||||
executionId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function documentCountDocuments(connectionId: string, collection: string, filter?: string, executionId?: string): Promise<number> {
|
||||
return invoke("document_count_documents", {
|
||||
connectionId,
|
||||
collection,
|
||||
filter,
|
||||
executionId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function dynamodbDescribeTable(connectionId: string, table: string): Promise<DynamoDbTableDescription> {
|
||||
return invoke("dynamodb_describe_table", { connectionId, table });
|
||||
}
|
||||
|
||||
export async function elasticsearchCountDocuments(connectionId: string, index: string, filter?: string, executionId?: string): Promise<number> {
|
||||
return invoke("elasticsearch_count_documents", {
|
||||
connectionId,
|
||||
|
||||
@@ -136,6 +136,7 @@ export function connectionDisplayUrlScheme(connection: Pick<ConnectionConfig, "d
|
||||
case "chromadb":
|
||||
case "rqlite":
|
||||
case "turso":
|
||||
case "dynamodb":
|
||||
case "mq":
|
||||
case "consul":
|
||||
return connection.ssl ? "https" : "http";
|
||||
@@ -197,6 +198,9 @@ export function connectionUrlPlaceholder(dbType: DatabaseType): string {
|
||||
case "mongodb":
|
||||
return "mongodb://user:password@host:port/database";
|
||||
|
||||
case "dynamodb":
|
||||
return "https://dynamodb.us-east-1.amazonaws.com";
|
||||
|
||||
case "clickhouse":
|
||||
return "clickhouse://user:password@host:port/database";
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
|
||||
zookeeper: { type: "zookeeper", profile: "zookeeper", label: "Apache ZooKeeper", defaultPort: 2181 },
|
||||
mongodb: { type: "mongodb", profile: "mongodb", label: "MongoDB", defaultPort: 27017 },
|
||||
"mongodb+srv": { type: "mongodb", profile: "mongodb", label: "MongoDB", defaultPort: 27017 },
|
||||
dynamodb: { type: "dynamodb", profile: "dynamodb", label: "Amazon DynamoDB", defaultPort: 443 },
|
||||
clickhouse: { type: "clickhouse", profile: "clickhouse", label: "ClickHouse", defaultPort: 8123 },
|
||||
sqlserver: { type: "sqlserver", profile: "sqlserver", label: "SQL Server", defaultPort: 1433 },
|
||||
mssql: { type: "sqlserver", profile: "sqlserver", label: "SQL Server", defaultPort: 1433 },
|
||||
@@ -83,6 +84,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
|
||||
|
||||
const HTTP_SELECTED_PROFILES: Record<string, ConnectionProfile> = {
|
||||
clickhouse: SCHEME_PROFILES.clickhouse,
|
||||
dynamodb: SCHEME_PROFILES.dynamodb,
|
||||
elasticsearch: SCHEME_PROFILES.elasticsearch,
|
||||
easysearch: SCHEME_PROFILES.easysearch,
|
||||
meilisearch: SCHEME_PROFILES.meilisearch,
|
||||
@@ -190,6 +192,10 @@ function databaseFromPath(pathname: string): string | undefined {
|
||||
return decodeUrlPart(value.split("/")[0]);
|
||||
}
|
||||
|
||||
function dynamodbRegionFromHost(hostname: string): string | undefined {
|
||||
return hostname.toLowerCase().match(/^dynamodb(?:-fips)?\.([a-z0-9-]+)\.(?:amazonaws\.com(?:\.cn)?|api\.aws)$/)?.[1];
|
||||
}
|
||||
|
||||
function parseZooKeeperUrl(source: string): ParsedConnectionUrl | null {
|
||||
const match = source.match(/^zookeeper:\/\/([^/?#]+)(\/[^?#]*)?(\?[^#]*)?$/i);
|
||||
if (!match) return null;
|
||||
@@ -665,7 +671,7 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
|
||||
...(profile.type === "sqlserver" && parsed.port ? { portExplicit: true } : {}),
|
||||
username: mysqlCredentials?.username ?? decodeUrlPart(parsed.username),
|
||||
password: mysqlCredentials?.password ?? decodeUrlPart(parsed.password),
|
||||
database: profile.type === "victoriametrics" ? "metrics" : isMeilisearch ? undefined : databaseFromPath(parsed.pathname),
|
||||
database: profile.type === "victoriametrics" ? "metrics" : profile.type === "dynamodb" ? dynamodbRegionFromHost(parsed.hostname) : isMeilisearch ? undefined : databaseFromPath(parsed.pathname),
|
||||
urlParams: effectiveUrlParams,
|
||||
ssl: scheme === "rediss" || scheme === "https" || urlParamsRequireTls(profile.type, effectiveUrlParams) || (profile.type === "mysql" && isTidbCloudHost(parsed.hostname)),
|
||||
...(profile.type === "victoriametrics" ? { apiPath: parsed.pathname.replace(/\/+$/, "") } : {}),
|
||||
@@ -759,7 +765,7 @@ export function applyParsedConnectionUrl(config: Omit<ConnectionConfig, "id">, p
|
||||
name: parsed.name?.trim() || config.name,
|
||||
username: applyParsedUsername(config, parsed),
|
||||
password: applyParsedPassword(config, parsed),
|
||||
database: parsed.database,
|
||||
database: parsed.dbType === "dynamodb" ? parsed.database || config.database || "us-east-1" : parsed.database,
|
||||
url_params: parsed.urlParams,
|
||||
ssl: parsed.ssl,
|
||||
connection_string: parsed.connectionString,
|
||||
|
||||
@@ -5,7 +5,7 @@ const DRAFT_VISIBLE_DATABASES_PREFIX = "__visible_draft_";
|
||||
|
||||
// Turso and Cloudflare D1 target one fixed SQLite-compatible `main` namespace;
|
||||
// non-database services expose their own root objects rather than database namespaces.
|
||||
const UNSUPPORTED_VISIBLE_DATABASE_TYPES = new Set<DatabaseType>(["turso", "cloudflare-d1", "elasticsearch", "easysearch", "meilisearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos", "consul"]);
|
||||
const UNSUPPORTED_VISIBLE_DATABASE_TYPES = new Set<DatabaseType>(["turso", "cloudflare-d1", "dynamodb", "elasticsearch", "easysearch", "meilisearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos", "consul"]);
|
||||
|
||||
type VisibleDatabaseConnectionFields = Pick<
|
||||
ConnectionConfig,
|
||||
|
||||
@@ -27,6 +27,7 @@ export const DATABASE_NAMESPACE_CREATION_MATRIX = {
|
||||
clickhouse: { connection: "database" },
|
||||
sqlserver: { connection: "database", database: "schema" },
|
||||
mongodb: { connection: "special" },
|
||||
dynamodb: { deferred: "table creation requires dedicated DynamoDB key and capacity options" },
|
||||
oracle: { deferred: "Oracle schemas are users; database creation is not a normal connected DDL action" },
|
||||
elasticsearch: { deferred: "index creation is not modeled as database creation" },
|
||||
easysearch: { deferred: "index creation is not modeled as database creation" },
|
||||
|
||||
@@ -27,6 +27,7 @@ export const DATABASE_PROPERTY_EDITING_MATRIX = {
|
||||
clickhouse: { deferred: "database property editing not verified for first pass" },
|
||||
sqlserver: { deferred: "database options are broad administrative settings and need a dedicated editor" },
|
||||
mongodb: { deferred: "database options are not modeled as SQL database properties" },
|
||||
dynamodb: { deferred: "table settings require a dedicated DynamoDB workflow" },
|
||||
oracle: { deferred: "Oracle database properties are instance/user/tablespace administration" },
|
||||
elasticsearch: { deferred: "index settings are not database properties" },
|
||||
easysearch: { deferred: "index settings are not database properties" },
|
||||
|
||||
@@ -27,6 +27,7 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
||||
"consul-overview",
|
||||
"mongo-gridfs",
|
||||
"mongo-bucket",
|
||||
"dynamodb-table",
|
||||
"vector-collection",
|
||||
"elasticsearch-index",
|
||||
"user-admin",
|
||||
@@ -38,7 +39,7 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
||||
"extension",
|
||||
]);
|
||||
|
||||
const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "mongo-collection", "mongo-bucket", "vector-collection", "elasticsearch-index"]);
|
||||
const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
|
||||
|
||||
const emptyContainerTypes: Set<TreeNodeType> = new Set(["saved-sql-root", "saved-sql-folder", "type"]);
|
||||
|
||||
@@ -58,12 +59,13 @@ const pinnableTypes: Set<TreeNodeType> = new Set([
|
||||
"mongo-gridfs",
|
||||
"mongo-bucket",
|
||||
"mongo-collection",
|
||||
"dynamodb-table",
|
||||
"vector-collection",
|
||||
"elasticsearch-index",
|
||||
"nacos-namespace",
|
||||
]);
|
||||
|
||||
const commentTypes: Set<TreeNodeType> = new Set(["connection", "schema", "table", "view", "materialized_view", "column", "mongo-collection", "vector-collection", "elasticsearch-index"]);
|
||||
const commentTypes: Set<TreeNodeType> = new Set(["connection", "schema", "table", "view", "materialized_view", "column", "mongo-collection", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
|
||||
|
||||
export const SIDEBAR_INDENT_DEFAULT_PX = 16;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export type SidebarSelectionCopyAction = "copy-name" | "none";
|
||||
export type SidebarActivation = "single" | "double";
|
||||
|
||||
const dataNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view"]);
|
||||
const documentBrowserNodeTypes = new Set<TreeNodeType>(["mongo-collection", "mongo-bucket"]);
|
||||
const documentBrowserNodeTypes = new Set<TreeNodeType>(["mongo-collection", "mongo-bucket", "dynamodb-table"]);
|
||||
const toggleLeafNodeTypes = new Set<TreeNodeType>([
|
||||
"redis-db",
|
||||
"mq-tenant",
|
||||
@@ -24,6 +24,7 @@ const toggleLeafNodeTypes = new Set<TreeNodeType>([
|
||||
"mongo-gridfs",
|
||||
"mongo-collection",
|
||||
"mongo-bucket",
|
||||
"dynamodb-table",
|
||||
"vector-collection",
|
||||
"elasticsearch-index",
|
||||
"user-admin",
|
||||
|
||||
@@ -50,10 +50,29 @@ export function classifySqlRisk(sql: string, options: SqlRiskOptions = {}): SqlR
|
||||
return { ...highest, statements };
|
||||
}
|
||||
|
||||
export function classifySqlStatementRisk(sql: string, _options: SqlRiskOptions = {}): SqlRiskStatementAssessment {
|
||||
export function classifySqlStatementRisk(sql: string, options: SqlRiskOptions = {}): SqlRiskStatementAssessment {
|
||||
const dynamodbRisk = classifyDynamoDbStatementRisk(sql, options.dialect);
|
||||
if (dynamodbRisk) return dynamodbRisk;
|
||||
return classifyTokens(tokenizeSqlForRisk(sql));
|
||||
}
|
||||
|
||||
function classifyDynamoDbStatementRisk(sql: string, dialect?: DatabaseType | string): SqlRiskStatementAssessment | null {
|
||||
if (dialect !== "dynamodb") return null;
|
||||
const header = sql
|
||||
.split(/\r?\n/)
|
||||
.find((line) => line.trim())
|
||||
?.trim()
|
||||
.toUpperCase();
|
||||
if (header === "DBX DYNAMODB SCAN" || header === "DBX DYNAMODB QUERY / SCAN") {
|
||||
return { risk: "read", firstKeyword: "dbx" };
|
||||
}
|
||||
if (header === "DBX DYNAMODB INSERT ITEM" || header === "DBX DYNAMODB PUT ITEM" || header === "DBX DYNAMODB DELETE ITEM") {
|
||||
return { risk: "write", firstKeyword: "dbx" };
|
||||
}
|
||||
if (header?.startsWith("DBX DYNAMODB")) return { risk: "unknown", firstKeyword: "dbx" };
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isSqlRiskMutation(risk: SqlRiskLevel): boolean {
|
||||
return risk !== "read";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user