Skip to content

Instantly share code, notes, and snippets.

View topshot99's full-sized avatar

Manik Khandelwal topshot99

View GitHub Profile
@topshot99
topshot99 / typescript-inheritance-issue.md
Created September 24, 2025 12:46
Debugging Continuation Token Loss in Azure Cosmos DB SDK

Debugging Continuation Token Loss in Azure Cosmos DB SDK:

The Context: A Clean Architecture Refactoring

While working on the Azure Cosmos DB JavaScript SDK, I decided to refactor the continuation token management system to use inheritance for better code organization. Previously, we had separate, independent classes handling different query types, which led to code duplication and maintenance overhead.

The refactoring goal was to:

  • Extract common continuation token logic into a BaseContinuationTokenManager
  • Create specialized subclasses like OrderByQueryContinuationTokenManager and ParallelQueryContinuationTokenManager
  • Eliminate code duplication across query types
  • Make the system more maintainable and extensible
@topshot99
topshot99 / Add Custom Headers.md
Created September 18, 2023 10:44
Adding custom headers to request using plugin

Adding custom headers to a request using Plugin

In this Node.js code example, we demonstrate how to add a custom HTTP header to requests made to Azure Cosmos DB using the Azure Cosmos DB Node.js SDK. We use a plugin-based approach to seamlessly inject custom headers into Cosmos DB requests.

import{RequestContext, Next, Response, PluginOn,CosmosClient} from "@azure/cosmos";
const key = "<cosmos key>";
const endpoint = "<cosmos endpoint>";

// Define a function to add a custom header
function addCustomHeader(
@topshot99
topshot99 / cross-paritition-continuation-token-demo.md
Last active July 11, 2023 07:41
JS sdk supporting continuation token for stremeable cross partition queries

The Node SDK currently provides support for continuation tokens in streamable/non-aggregate cross-partition queries.

Here are the steps to use it:

const querySpec = {
  query: "SELECT * FROM c WHERE c.status = @status",
  parameters: [{ name: "@status", value: "active" }],
};
@topshot99
topshot99 / Get-ActivityId.md
Last active July 10, 2023 06:45
Accessing Activity ID for an cosmos DB transaction

The provided code snippet illustrates the process of extracting the activity ID from the response object when making requests to Cosmos DB. It includes an example of creating a Cosmos DB item and retrieving the activity ID from the response headers, specifically the "x-ms-activity-id" header. The extracted activity ID is then logged to the console.

// Create a sample Cosmos DB item and extract the activity ID from the response
const response = await container.items.create({ id: "<item id>"});
//checking if the create request was successful
if(response.statusCode === 201){
@topshot99
topshot99 / Debug-location-endpoints.md
Last active July 7, 2023 06:00
Debugging Location Endpoints: Cosmos DB Client

The below code sets up a Cosmos DB client and logs various account details such as the database account, read and write endpoints, and the available read and write endpoints. It can be used for debugging purposes to verify the location endpoints of an existing Cosmos DB client.

const { CosmosClient } = require('@azure/cosmos');

//replace with your endpoint and key
const client = new CosmosClient(
    { endpoint: <your-endpoint>,