UNPKG

@cfworker/cosmos

Version:

Azure Cosmos DB client for Cloudflare Workers and service workers

55 lines (54 loc) 1.32 kB
export class CosmosResponse { response; constructor(response) { this.response = response; } get status() { return this.response.status; } get headers() { return this.response.headers; } get body() { return this.response.body; } get activityId() { return this.response.headers.get('x-ms-activity-id'); } get etag() { return this.response.headers.get('etag'); } get requestCharge() { return parseInt(this.response.headers.get('x-ms-request-charge')); } get raw() { return this.response; } } export class ItemResponse extends CosmosResponse { constructor(response) { super(response); } json() { return this.response.json(); } } export class FeedResponse extends CosmosResponse { next; itemsProperty; constructor(response, next, itemsProperty) { super(response); this.next = next; this.itemsProperty = itemsProperty; } get count() { return parseInt(this.response.headers.get('x-ms-item-count')); } get hasNext() { return this.response.headers.has('x-ms-continuation'); } async json() { const data = await this.response.json(); return data[this.itemsProperty]; } }