mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-20 02:04:23 +00:00
* Initial implementetation of backend integration
* Added parameters and interfaces moved
* Initial client implementation
* Additional changes for React FC's
* Updated snapshot of Footer
* Additional Copilot implementation
* Test adjustments and client implementation
* Additional test implementations
* Naming convetion for functions
* Changing {} to any
* Additional changes to the type
* Additional test changes
* Removal of prevention
* adding comment
* Additional changes to tests
* Moving logic based on comments
* client implementation along with corrected tests
---------
Co-authored-by: Predrag Klepic <v-prklepic@microsoft.com>
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { FeedOptions, Item, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos";
|
|
import { QueryCopilotSampleContainerId, QueryCopilotSampleDatabaseId } from "Common/Constants";
|
|
import { handleError } from "Common/ErrorHandlingUtils";
|
|
import { sampleDataClient } from "Common/SampleDataClient";
|
|
import { getPartitionKeyValue } from "Common/dataAccess/getPartitionKeyValue";
|
|
import { getCommonQueryOptions } from "Common/dataAccess/queryDocuments";
|
|
import DocumentId from "Explorer/Tree/DocumentId";
|
|
import { logConsoleProgress } from "Utils/NotificationConsoleUtils";
|
|
|
|
export const querySampleDocuments = (query: string, options: FeedOptions): QueryIterator<ItemDefinition & Resource> => {
|
|
options = getCommonQueryOptions(options);
|
|
return sampleDataClient()
|
|
.database(QueryCopilotSampleDatabaseId)
|
|
.container(QueryCopilotSampleContainerId)
|
|
.items.query(query, options);
|
|
};
|
|
|
|
export const readSampleDocument = async (documentId: DocumentId): Promise<Item> => {
|
|
const clearMessage = logConsoleProgress(`Reading item ${documentId.id()}`);
|
|
|
|
try {
|
|
const response = await sampleDataClient()
|
|
.database(QueryCopilotSampleDatabaseId)
|
|
.container(QueryCopilotSampleContainerId)
|
|
.item(documentId.id(), getPartitionKeyValue(documentId))
|
|
.read();
|
|
|
|
return response?.resource;
|
|
} catch (error) {
|
|
handleError(error, "ReadDocument", `Failed to read item ${documentId.id()}`);
|
|
throw error;
|
|
} finally {
|
|
clearMessage();
|
|
}
|
|
};
|