UNPKG

183 kBTypeScriptView Raw
1/// <reference lib="dom" />
2/// <reference lib="esnext.asynciterable" />
3
4import { AbortError } from '@azure/abort-controller';
5import { AbortSignal as AbortSignal_2 } from 'node-abort-controller';
6import { Pipeline } from '@azure/core-rest-pipeline';
7import { RestError } from '@azure/core-rest-pipeline';
8import { TokenCredential } from '@azure/core-auth';
9
10export { AbortError }
11
12export declare interface Agent {
13 maxFreeSockets: number;
14 maxSockets: number;
15 sockets: any;
16 requests: any;
17 destroy(): void;
18}
19
20export declare type AggregateType = "Average" | "Count" | "Max" | "Min" | "Sum";
21
22export declare const BulkOperationType: {
23 readonly Create: "Create";
24 readonly Upsert: "Upsert";
25 readonly Read: "Read";
26 readonly Delete: "Delete";
27 readonly Replace: "Replace";
28 readonly Patch: "Patch";
29};
30
31/**
32 * Options object used to modify bulk execution.
33 * continueOnError (Default value: false) - Continues bulk execution when an operation fails ** NOTE THIS WILL DEFAULT TO TRUE IN the 4.0 RELEASE
34 */
35export declare interface BulkOptions {
36 continueOnError?: boolean;
37}
38
39export declare type BulkPatchOperation = OperationBase & {
40 operationType: typeof BulkOperationType.Patch;
41 id: string;
42};
43
44/**
45 * Provides iterator for change feed.
46 *
47 * Use `Items.changeFeed()` to get an instance of the iterator.
48 */
49export declare class ChangeFeedIterator<T> {
50 private clientContext;
51 private resourceId;
52 private resourceLink;
53 private partitionKey;
54 private changeFeedOptions;
55 private static readonly IfNoneMatchAllHeaderValue;
56 private nextIfNoneMatch;
57 private ifModifiedSince;
58 private lastStatusCode;
59 private isPartitionSpecified;
60 /**
61 * Gets a value indicating whether there are potentially additional results that can be retrieved.
62 *
63 * Initially returns true. This value is set based on whether the last execution returned a continuation token.
64 *
65 * @returns Boolean value representing if whether there are potentially additional results that can be retrieved.
66 */
67 get hasMoreResults(): boolean;
68 /**
69 * Gets an async iterator which will yield pages of results from Azure Cosmos DB.
70 */
71 getAsyncIterator(): AsyncIterable<ChangeFeedResponse<Array<T & Resource>>>;
72 /**
73 * Read feed and retrieves the next page of results in Azure Cosmos DB.
74 */
75 fetchNext(): Promise<ChangeFeedResponse<Array<T & Resource>>>;
76 private getFeedResponse;
77}
78
79/**
80 * Specifies options for the change feed
81 *
82 * Some of these options control where and when to start reading from the change feed. The order of precedence is:
83 * - continuation
84 * - startTime
85 * - startFromBeginning
86 *
87 * If none of those options are set, it will start reading changes from the first `ChangeFeedIterator.fetchNext()` call.
88 */
89export declare interface ChangeFeedOptions {
90 /**
91 * Max amount of items to return per page
92 */
93 maxItemCount?: number;
94 /**
95 * The continuation token to start from.
96 *
97 * This is equivalent to the etag and continuation value from the `ChangeFeedResponse`
98 */
99 continuation?: string;
100 /**
101 * The session token to use. If not specified, will use the most recent captured session token to start with.
102 */
103 sessionToken?: string;
104 /**
105 * Signals whether to start from the beginning or not.
106 */
107 startFromBeginning?: boolean;
108 /**
109 * Specified the start time to start reading changes from.
110 */
111 startTime?: Date;
112}
113
114/**
115 * A single response page from the Azure Cosmos DB Change Feed
116 */
117export declare class ChangeFeedResponse<T> {
118 /**
119 * Gets the items returned in the response from Azure Cosmos DB
120 */
121 readonly result: T;
122 /**
123 * Gets the number of items returned in the response from Azure Cosmos DB
124 */
125 readonly count: number;
126 /**
127 * Gets the status code of the response from Azure Cosmos DB
128 */
129 readonly statusCode: number;
130 /**
131 * Gets the request charge for this request from the Azure Cosmos DB service.
132 */
133 get requestCharge(): number;
134 /**
135 * Gets the activity ID for the request from the Azure Cosmos DB service.
136 */
137 get activityId(): string;
138 /**
139 * Gets the continuation token to be used for continuing enumeration of the Azure Cosmos DB service.
140 *
141 * This is equivalent to the `etag` property.
142 */
143 get continuation(): string;
144 /**
145 * Gets the session token for use in session consistency reads from the Azure Cosmos DB service.
146 */
147 get sessionToken(): string;
148 /**
149 * Gets the entity tag associated with last transaction in the Azure Cosmos DB service,
150 * which can be used as If-Non-Match Access condition for ReadFeed REST request or
151 * `continuation` property of `ChangeFeedOptions` parameter for
152 * `Items.changeFeed()`
153 * to get feed changes since the transaction specified by this entity tag.
154 *
155 * This is equivalent to the `continuation` property.
156 */
157 get etag(): string;
158 /**
159 * Response headers of the response from Azure Cosmos DB
160 */
161 headers: CosmosHeaders;
162}
163
164/**
165 * @hidden
166 * @hidden
167 */
168export declare class ClientContext {
169 private cosmosClientOptions;
170 private globalEndpointManager;
171 private readonly sessionContainer;
172 private connectionPolicy;
173 private pipeline;
174 partitionKeyDefinitionCache: {
175 [containerUrl: string]: any;
176 };
177 constructor(cosmosClientOptions: CosmosClientOptions, globalEndpointManager: GlobalEndpointManager);
178 /** @hidden */
179 read<T>({ path, resourceType, resourceId, options, partitionKey, }: {
180 path: string;
181 resourceType: ResourceType;
182 resourceId: string;
183 options?: RequestOptions;
184 partitionKey?: PartitionKey;
185 }): Promise<Response_2<T & Resource>>;
186 queryFeed<T>({ path, resourceType, resourceId, resultFn, query, options, partitionKeyRangeId, partitionKey, }: {
187 path: string;
188 resourceType: ResourceType;
189 resourceId: string;
190 resultFn: (result: {
191 [key: string]: any;
192 }) => any[];
193 query: SqlQuerySpec | string;
194 options: FeedOptions;
195 partitionKeyRangeId?: string;
196 partitionKey?: PartitionKey;
197 }): Promise<Response_2<T & Resource>>;
198 getQueryPlan(path: string, resourceType: ResourceType, resourceId: string, query: SqlQuerySpec | string, options?: FeedOptions): Promise<Response_2<PartitionedQueryExecutionInfo>>;
199 queryPartitionKeyRanges(collectionLink: string, query?: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<PartitionKeyRange>;
200 delete<T>({ path, resourceType, resourceId, options, partitionKey, method, }: {
201 path: string;
202 resourceType: ResourceType;
203 resourceId: string;
204 options?: RequestOptions;
205 partitionKey?: PartitionKey;
206 method?: HTTPMethod;
207 }): Promise<Response_2<T & Resource>>;
208 patch<T>({ body, path, resourceType, resourceId, options, partitionKey, }: {
209 body: any;
210 path: string;
211 resourceType: ResourceType;
212 resourceId: string;
213 options?: RequestOptions;
214 partitionKey?: PartitionKey;
215 }): Promise<Response_2<T & Resource>>;
216 create<T, U = T>({ body, path, resourceType, resourceId, options, partitionKey, }: {
217 body: T;
218 path: string;
219 resourceType: ResourceType;
220 resourceId: string;
221 options?: RequestOptions;
222 partitionKey?: PartitionKey;
223 }): Promise<Response_2<T & U & Resource>>;
224 private processQueryFeedResponse;
225 private applySessionToken;
226 replace<T>({ body, path, resourceType, resourceId, options, partitionKey, }: {
227 body: any;
228 path: string;
229 resourceType: ResourceType;
230 resourceId: string;
231 options?: RequestOptions;
232 partitionKey?: PartitionKey;
233 }): Promise<Response_2<T & Resource>>;
234 upsert<T, U = T>({ body, path, resourceType, resourceId, options, partitionKey, }: {
235 body: T;
236 path: string;
237 resourceType: ResourceType;
238 resourceId: string;
239 options?: RequestOptions;
240 partitionKey?: PartitionKey;
241 }): Promise<Response_2<T & U & Resource>>;
242 execute<T>({ sprocLink, params, options, partitionKey, }: {
243 sprocLink: string;
244 params?: any[];
245 options?: RequestOptions;
246 partitionKey?: PartitionKey;
247 }): Promise<Response_2<T>>;
248 /**
249 * Gets the Database account information.
250 * @param options - `urlConnection` in the options is the endpoint url whose database account needs to be retrieved.
251 * If not present, current client's url will be used.
252 */
253 getDatabaseAccount(options?: RequestOptions): Promise<Response_2<DatabaseAccount>>;
254 getWriteEndpoint(): Promise<string>;
255 getReadEndpoint(): Promise<string>;
256 getWriteEndpoints(): Promise<readonly string[]>;
257 getReadEndpoints(): Promise<readonly string[]>;
258 batch<T>({ body, path, partitionKey, resourceId, options, }: {
259 body: T;
260 path: string;
261 partitionKey: string;
262 resourceId: string;
263 options?: RequestOptions;
264 }): Promise<Response_2<any>>;
265 bulk<T>({ body, path, partitionKeyRangeId, resourceId, bulkOptions, options, }: {
266 body: T;
267 path: string;
268 partitionKeyRangeId: string;
269 resourceId: string;
270 bulkOptions?: BulkOptions;
271 options?: RequestOptions;
272 }): Promise<Response_2<any>>;
273 private captureSessionToken;
274 clearSessionToken(path: string): void;
275 private getSessionParams;
276 private isMasterResource;
277 private buildHeaders;
278 /**
279 * Returns collection of properties which are derived from the context for Request Creation
280 * @returns
281 */
282 private getContextDerivedPropsForRequestCreation;
283}
284
285export declare class ClientSideMetrics {
286 readonly requestCharge: number;
287 constructor(requestCharge: number);
288 /**
289 * Adds one or more ClientSideMetrics to a copy of this instance and returns the result.
290 */
291 add(...clientSideMetricsArray: ClientSideMetrics[]): ClientSideMetrics;
292 static readonly zero: ClientSideMetrics;
293 static createFromArray(...clientSideMetricsArray: ClientSideMetrics[]): ClientSideMetrics;
294}
295
296/**
297 * Use to read or delete a given {@link Conflict} by id.
298 *
299 * @see {@link Conflicts} to query or read all conflicts.
300 */
301export declare class Conflict {
302 readonly container: Container;
303 readonly id: string;
304 private readonly clientContext;
305 private partitionKey?;
306 /**
307 * Returns a reference URL to the resource. Used for linking in Permissions.
308 */
309 get url(): string;
310 /**
311 * @hidden
312 * @param container - The parent {@link Container}.
313 * @param id - The id of the given {@link Conflict}.
314 */
315 constructor(container: Container, id: string, clientContext: ClientContext, partitionKey?: PartitionKey);
316 /**
317 * Read the {@link ConflictDefinition} for the given {@link Conflict}.
318 */
319 read(options?: RequestOptions): Promise<ConflictResponse>;
320 /**
321 * Delete the given {@link ConflictDefinition}.
322 */
323 delete(options?: RequestOptions): Promise<ConflictResponse>;
324}
325
326export declare interface ConflictDefinition {
327 /** The id of the conflict */
328 id?: string;
329 /** Source resource id */
330 resourceId?: string;
331 resourceType?: ResourceType;
332 operationType?: OperationType;
333 content?: string;
334}
335
336export declare enum ConflictResolutionMode {
337 Custom = "Custom",
338 LastWriterWins = "LastWriterWins"
339}
340
341/**
342 * Represents the conflict resolution policy configuration for specifying how to resolve conflicts
343 * in case writes from different regions result in conflicts on documents in the collection in the Azure Cosmos DB service.
344 */
345export declare interface ConflictResolutionPolicy {
346 /**
347 * Gets or sets the <see cref="ConflictResolutionMode"/> in the Azure Cosmos DB service. By default it is {@link ConflictResolutionMode.LastWriterWins}.
348 */
349 mode?: keyof typeof ConflictResolutionMode;
350 /**
351 * Gets or sets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution.
352 * This path must be present in each document and must be an integer value.
353 * In case of a conflict occurring on a document, the document with the higher integer value in the specified path will be picked.
354 * If the path is unspecified, by default the timestamp path will be used.
355 *
356 * This value should only be set when using {@link ConflictResolutionMode.LastWriterWins}.
357 *
358 * ```typescript
359 * conflictResolutionPolicy.ConflictResolutionPath = "/name/first";
360 * ```
361 *
362 */
363 conflictResolutionPath?: string;
364 /**
365 * Gets or sets the {@link StoredProcedure} which is used for conflict resolution in the Azure Cosmos DB service.
366 * This stored procedure may be created after the {@link Container} is created and can be changed as required.
367 *
368 * 1. This value should only be set when using {@link ConflictResolutionMode.Custom}.
369 * 2. In case the stored procedure fails or throws an exception, the conflict resolution will default to registering conflicts in the conflicts feed.
370 *
371 * ```typescript
372 * conflictResolutionPolicy.ConflictResolutionProcedure = "resolveConflict"
373 * ```
374 */
375 conflictResolutionProcedure?: string;
376}
377
378export declare class ConflictResponse extends ResourceResponse<ConflictDefinition & Resource> {
379 constructor(resource: ConflictDefinition & Resource, headers: CosmosHeaders, statusCode: number, conflict: Conflict);
380 /** A reference to the {@link Conflict} corresponding to the returned {@link ConflictDefinition}. */
381 readonly conflict: Conflict;
382}
383
384/**
385 * Use to query or read all conflicts.
386 *
387 * @see {@link Conflict} to read or delete a given {@link Conflict} by id.
388 */
389export declare class Conflicts {
390 readonly container: Container;
391 private readonly clientContext;
392 constructor(container: Container, clientContext: ClientContext);
393 /**
394 * Queries all conflicts.
395 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
396 * @param options - Use to set options like response page size, continuation tokens, etc.
397 * @returns {@link QueryIterator} Allows you to return results in an array or iterate over them one at a time.
398 */
399 query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
400 /**
401 * Queries all conflicts.
402 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
403 * @param options - Use to set options like response page size, continuation tokens, etc.
404 * @returns {@link QueryIterator} Allows you to return results in an array or iterate over them one at a time.
405 */
406 query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
407 /**
408 * Reads all conflicts
409 * @param options - Use to set options like response page size, continuation tokens, etc.
410 */
411 readAll(options?: FeedOptions): QueryIterator<ConflictDefinition & Resource>;
412 }
413
414 /** Determines the connection behavior of the CosmosClient. Note, we currently only support Gateway Mode. */
415 export declare enum ConnectionMode {
416 /** Gateway mode talks to an intermediate gateway which handles the direct communication with your individual partitions. */
417 Gateway = 0
418 }
419
420 /**
421 * Represents the Connection policy associated with a CosmosClient in the Azure Cosmos DB database service.
422 */
423 export declare interface ConnectionPolicy {
424 /** Determines which mode to connect to Cosmos with. (Currently only supports Gateway option) */
425 connectionMode?: ConnectionMode;
426 /** Request timeout (time to wait for response from network peer). Represented in milliseconds. */
427 requestTimeout?: number;
428 /**
429 * Flag to enable/disable automatic redirecting of requests based on read/write operations. Default true.
430 * Required to call client.dispose() when this is set to true after destroying the CosmosClient inside another process or in the browser.
431 */
432 enableEndpointDiscovery?: boolean;
433 /** List of azure regions to be used as preferred locations for read requests. */
434 preferredLocations?: string[];
435 /** RetryOptions object which defines several configurable properties used during retry. */
436 retryOptions?: RetryOptions;
437 /**
438 * The flag that enables writes on any locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service.
439 * Default is `false`.
440 */
441 useMultipleWriteLocations?: boolean;
442 /** Rate in milliseconds at which the client will refresh the endpoints list in the background */
443 endpointRefreshRateInMs?: number;
444 /** Flag to enable/disable background refreshing of endpoints. Defaults to false.
445 * Endpoint discovery using `enableEndpointsDiscovery` will still work for failed requests. */
446 enableBackgroundEndpointRefreshing?: boolean;
447 }
448
449 /**
450 * Represents the consistency levels supported for Azure Cosmos DB client operations.<br>
451 * The requested ConsistencyLevel must match or be weaker than that provisioned for the database account.
452 * Consistency levels.
453 *
454 * Consistency levels by order of strength are Strong, BoundedStaleness, Session, Consistent Prefix, and Eventual.
455 *
456 * See https://aka.ms/cosmos-consistency for more detailed documentation on Consistency Levels.
457 */
458 export declare enum ConsistencyLevel {
459 /**
460 * Strong Consistency guarantees that read operations always return the value that was last written.
461 */
462 Strong = "Strong",
463 /**
464 * Bounded Staleness guarantees that reads are not too out-of-date.
465 * This can be configured based on number of operations (MaxStalenessPrefix) or time (MaxStalenessIntervalInSeconds).
466 */
467 BoundedStaleness = "BoundedStaleness",
468 /**
469 * Session Consistency guarantees monotonic reads (you never read old data, then new, then old again),
470 * monotonic writes (writes are ordered) and read your writes (your writes are immediately visible to your reads)
471 * within any single session.
472 */
473 Session = "Session",
474 /**
475 * Eventual Consistency guarantees that reads will return a subset of writes.
476 * All writes will be eventually be available for reads.
477 */
478 Eventual = "Eventual",
479 /**
480 * ConsistentPrefix Consistency guarantees that reads will return some prefix of all writes with no gaps.
481 * All writes will be eventually be available for reads.
482 */
483 ConsistentPrefix = "ConsistentPrefix"
484 }
485
486 /**
487 * @hidden
488 */
489 export declare const Constants: {
490 HttpHeaders: {
491 Authorization: string;
492 ETag: string;
493 MethodOverride: string;
494 Slug: string;
495 ContentType: string;
496 LastModified: string;
497 ContentEncoding: string;
498 CharacterSet: string;
499 UserAgent: string;
500 IfModifiedSince: string;
501 IfMatch: string;
502 IfNoneMatch: string;
503 ContentLength: string;
504 AcceptEncoding: string;
505 KeepAlive: string;
506 CacheControl: string;
507 TransferEncoding: string;
508 ContentLanguage: string;
509 ContentLocation: string;
510 ContentMd5: string;
511 ContentRange: string;
512 Accept: string;
513 AcceptCharset: string;
514 AcceptLanguage: string;
515 IfRange: string;
516 IfUnmodifiedSince: string;
517 MaxForwards: string;
518 ProxyAuthorization: string;
519 AcceptRanges: string;
520 ProxyAuthenticate: string;
521 RetryAfter: string;
522 SetCookie: string;
523 WwwAuthenticate: string;
524 Origin: string;
525 Host: string;
526 AccessControlAllowOrigin: string;
527 AccessControlAllowHeaders: string;
528 KeyValueEncodingFormat: string;
529 WrapAssertionFormat: string;
530 WrapAssertion: string;
531 WrapScope: string;
532 SimpleToken: string;
533 HttpDate: string;
534 Prefer: string;
535 Location: string;
536 Referer: string;
537 A_IM: string;
538 Query: string;
539 IsQuery: string;
540 IsQueryPlan: string;
541 SupportedQueryFeatures: string;
542 QueryVersion: string;
543 Continuation: string;
544 PageSize: string;
545 ItemCount: string;
546 ActivityId: string;
547 PreTriggerInclude: string;
548 PreTriggerExclude: string;
549 PostTriggerInclude: string;
550 PostTriggerExclude: string;
551 IndexingDirective: string;
552 SessionToken: string;
553 ConsistencyLevel: string;
554 XDate: string;
555 CollectionPartitionInfo: string;
556 CollectionServiceInfo: string;
557 RetryAfterInMilliseconds: string;
558 RetryAfterInMs: string;
559 IsFeedUnfiltered: string;
560 ResourceTokenExpiry: string;
561 EnableScanInQuery: string;
562 EmitVerboseTracesInQuery: string;
563 EnableCrossPartitionQuery: string;
564 ParallelizeCrossPartitionQuery: string;
565 ResponseContinuationTokenLimitInKB: string;
566 PopulateQueryMetrics: string;
567 QueryMetrics: string;
568 Version: string;
569 OwnerFullName: string;
570 OwnerId: string;
571 PartitionKey: string;
572 PartitionKeyRangeID: string;
573 MaxEntityCount: string;
574 CurrentEntityCount: string;
575 CollectionQuotaInMb: string;
576 CollectionCurrentUsageInMb: string;
577 MaxMediaStorageUsageInMB: string;
578 CurrentMediaStorageUsageInMB: string;
579 RequestCharge: string;
580 PopulateQuotaInfo: string;
581 MaxResourceQuota: string;
582 OfferType: string;
583 OfferThroughput: string;
584 AutoscaleSettings: string;
585 DisableRUPerMinuteUsage: string;
586 IsRUPerMinuteUsed: string;
587 OfferIsRUPerMinuteThroughputEnabled: string;
588 IndexTransformationProgress: string;
589 LazyIndexingProgress: string;
590 IsUpsert: string;
591 SubStatus: string;
592 EnableScriptLogging: string;
593 ScriptLogResults: string;
594 ALLOW_MULTIPLE_WRITES: string;
595 IsBatchRequest: string;
596 IsBatchAtomic: string;
597 BatchContinueOnError: string;
598 DedicatedGatewayPerRequestCacheStaleness: string;
599 ForceRefresh: string;
600 };
601 WritableLocations: string;
602 ReadableLocations: string;
603 LocationUnavailableExpirationTimeInMs: number;
604 ENABLE_MULTIPLE_WRITABLE_LOCATIONS: string;
605 DefaultUnavailableLocationExpirationTimeMS: number;
606 ThrottleRetryCount: string;
607 ThrottleRetryWaitTimeInMs: string;
608 CurrentVersion: string;
609 AzureNamespace: string;
610 AzurePackageName: string;
611 SDKName: string;
612 SDKVersion: string;
613 DefaultMaxBulkRequestBodySizeInBytes: number;
614 Quota: {
615 CollectionSize: string;
616 };
617 Path: {
618 Root: string;
619 DatabasesPathSegment: string;
620 CollectionsPathSegment: string;
621 UsersPathSegment: string;
622 DocumentsPathSegment: string;
623 PermissionsPathSegment: string;
624 StoredProceduresPathSegment: string;
625 TriggersPathSegment: string;
626 UserDefinedFunctionsPathSegment: string;
627 ConflictsPathSegment: string;
628 AttachmentsPathSegment: string;
629 PartitionKeyRangesPathSegment: string;
630 SchemasPathSegment: string;
631 OffersPathSegment: string;
632 TopologyPathSegment: string;
633 DatabaseAccountPathSegment: string;
634 };
635 PartitionKeyRange: PartitionKeyRangePropertiesNames;
636 QueryRangeConstants: {
637 MinInclusive: string;
638 MaxExclusive: string;
639 min: string;
640 };
641 /**
642 * @deprecated Use EffectivePartitionKeyConstants instead
643 */
644 EffectiveParitionKeyConstants: {
645 MinimumInclusiveEffectivePartitionKey: string;
646 MaximumExclusiveEffectivePartitionKey: string;
647 };
648 EffectivePartitionKeyConstants: {
649 MinimumInclusiveEffectivePartitionKey: string;
650 MaximumExclusiveEffectivePartitionKey: string;
651 };
652 };
653
654 /**
655 * Operations for reading, replacing, or deleting a specific, existing container by id.
656 *
657 * @see {@link Containers} for creating new containers, and reading/querying all containers; use `.containers`.
658 *
659 * Note: all these operations make calls against a fixed budget.
660 * You should design your system such that these calls scale sublinearly with your application.
661 * For instance, do not call `container(id).read()` before every single `item.read()` call, to ensure the container exists;
662 * do this once on application start up.
663 */
664 export declare class Container {
665 readonly database: Database;
666 readonly id: string;
667 private readonly clientContext;
668 private $items;
669 /**
670 * Operations for creating new items, and reading/querying all items
671 *
672 * For reading, replacing, or deleting an existing item, use `.item(id)`.
673 *
674 * @example Create a new item
675 * ```typescript
676 * const {body: createdItem} = await container.items.create({id: "<item id>", properties: {}});
677 * ```
678 */
679 get items(): Items;
680 private $scripts;
681 /**
682 * All operations for Stored Procedures, Triggers, and User Defined Functions
683 */
684 get scripts(): Scripts;
685 private $conflicts;
686 /**
687 * Operations for reading and querying conflicts for the given container.
688 *
689 * For reading or deleting a specific conflict, use `.conflict(id)`.
690 */
691 get conflicts(): Conflicts;
692 /**
693 * Returns a reference URL to the resource. Used for linking in Permissions.
694 */
695 get url(): string;
696 /**
697 * Returns a container instance. Note: You should get this from `database.container(id)`, rather than creating your own object.
698 * @param database - The parent {@link Database}.
699 * @param id - The id of the given container.
700 * @hidden
701 */
702 constructor(database: Database, id: string, clientContext: ClientContext);
703 /**
704 * Used to read, replace, or delete a specific, existing {@link Item} by id.
705 *
706 * Use `.items` for creating new items, or querying/reading all items.
707 *
708 * @param id - The id of the {@link Item}.
709 * @param partitionKeyValue - The value of the {@link Item} partition key
710 * @example Replace an item
711 * `const {body: replacedItem} = await container.item("<item id>", "<partition key value>").replace({id: "<item id>", title: "Updated post", authorID: 5});`
712 */
713 item(id: string, partitionKeyValue?: PartitionKey): Item;
714 /**
715 * Used to read, replace, or delete a specific, existing {@link Conflict} by id.
716 *
717 * Use `.conflicts` for creating new conflicts, or querying/reading all conflicts.
718 * @param id - The id of the {@link Conflict}.
719 */
720 conflict(id: string, partitionKey?: PartitionKey): Conflict;
721 /** Read the container's definition */
722 read(options?: RequestOptions): Promise<ContainerResponse>;
723 /** Replace the container's definition */
724 replace(body: ContainerDefinition, options?: RequestOptions): Promise<ContainerResponse>;
725 /** Delete the container */
726 delete(options?: RequestOptions): Promise<ContainerResponse>;
727 /**
728 * Gets the partition key definition first by looking into the cache otherwise by reading the collection.
729 * @deprecated This method has been renamed to readPartitionKeyDefinition.
730 */
731 getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>;
732 /**
733 * Gets the partition key definition first by looking into the cache otherwise by reading the collection.
734 * @hidden
735 */
736 readPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>;
737 /**
738 * Gets offer on container. If none exists, returns an OfferResponse with undefined.
739 */
740 readOffer(options?: RequestOptions): Promise<OfferResponse>;
741 getQueryPlan(query: string | SqlQuerySpec): Promise<Response_2<PartitionedQueryExecutionInfo>>;
742 readPartitionKeyRanges(feedOptions?: FeedOptions): QueryIterator<PartitionKeyRange>;
743 /**
744 * Delete all documents belong to the container for the provided partition key value
745 * @param partitionKey - The partition key value of the items to be deleted
746 */
747 deleteAllItemsForPartitionKey(partitionKey: PartitionKey, options?: RequestOptions): Promise<ContainerResponse>;
748 }
749
750 export declare interface ContainerDefinition {
751 /** The id of the container. */
752 id?: string;
753 /** The partition key for the container. */
754 partitionKey?: PartitionKeyDefinition;
755 /** The indexing policy associated with the container. */
756 indexingPolicy?: IndexingPolicy;
757 /** The default time to live in seconds for items in a container. */
758 defaultTtl?: number;
759 /** The conflict resolution policy used to resolve conflicts in a container. */
760 conflictResolutionPolicy?: ConflictResolutionPolicy;
761 /** Policy for additional keys that must be unique per partition key */
762 uniqueKeyPolicy?: UniqueKeyPolicy;
763 /** Geospatial configuration for a collection. Type is set to Geography by default */
764 geospatialConfig?: {
765 type: GeospatialType;
766 };
767 }
768
769 export declare interface ContainerRequest extends VerboseOmit<ContainerDefinition, "partitionKey"> {
770 throughput?: number;
771 maxThroughput?: number;
772 autoUpgradePolicy?: {
773 throughputPolicy: {
774 incrementPercent: number;
775 };
776 };
777 partitionKey?: string | PartitionKeyDefinition;
778 }
779
780 /** Response object for Container operations */
781 export declare class ContainerResponse extends ResourceResponse<ContainerDefinition & Resource> {
782 constructor(resource: ContainerDefinition & Resource, headers: CosmosHeaders, statusCode: number, container: Container);
783 /** A reference to the {@link Container} that the returned {@link ContainerDefinition} corresponds to. */
784 readonly container: Container;
785 }
786
787 /**
788 * Operations for creating new containers, and reading/querying all containers
789 *
790 * @see {@link Container} for reading, replacing, or deleting an existing container; use `.container(id)`.
791 *
792 * Note: all these operations make calls against a fixed budget.
793 * You should design your system such that these calls scale sublinearly with your application.
794 * For instance, do not call `containers.readAll()` before every single `item.read()` call, to ensure the container exists;
795 * do this once on application start up.
796 */
797 export declare class Containers {
798 readonly database: Database;
799 private readonly clientContext;
800 constructor(database: Database, clientContext: ClientContext);
801 /**
802 * Queries all containers.
803 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
804 * @param options - Use to set options like response page size, continuation tokens, etc.
805 * @returns {@link QueryIterator} Allows you to return specific containers in an array or iterate over them one at a time.
806 * @example Read all containers to array.
807 * ```typescript
808 * const querySpec: SqlQuerySpec = {
809 * query: "SELECT * FROM root r WHERE r.id = @container",
810 * parameters: [
811 * {name: "@container", value: "Todo"}
812 * ]
813 * };
814 * const {body: containerList} = await client.database("<db id>").containers.query(querySpec).fetchAll();
815 * ```
816 */
817 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
818 /**
819 * Queries all containers.
820 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
821 * @param options - Use to set options like response page size, continuation tokens, etc.
822 * @returns {@link QueryIterator} Allows you to return specific containers in an array or iterate over them one at a time.
823 * @example Read all containers to array.
824 * ```typescript
825 * const querySpec: SqlQuerySpec = {
826 * query: "SELECT * FROM root r WHERE r.id = @container",
827 * parameters: [
828 * {name: "@container", value: "Todo"}
829 * ]
830 * };
831 * const {body: containerList} = await client.database("<db id>").containers.query(querySpec).fetchAll();
832 * ```
833 */
834 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
835 /**
836 * Creates a container.
837 *
838 * A container is a named logical container for items.
839 *
840 * A database may contain zero or more named containers and each container consists of
841 * zero or more JSON items.
842 *
843 * Being schema-free, the items in a container do not need to share the same structure or fields.
844 *
845 *
846 * Since containers are application resources, they can be authorized using either the
847 * master key or resource keys.
848 *
849 * @param body - Represents the body of the container.
850 * @param options - Use to set options like response page size, continuation tokens, etc.
851 */
852 create(body: ContainerRequest, options?: RequestOptions): Promise<ContainerResponse>;
853 /**
854 * Checks if a Container exists, and, if it doesn't, creates it.
855 * This will make a read operation based on the id in the `body`, then if it is not found, a create operation.
856 * You should confirm that the output matches the body you passed in for non-default properties (i.e. indexing policy/etc.)
857 *
858 * A container is a named logical container for items.
859 *
860 * A database may contain zero or more named containers and each container consists of
861 * zero or more JSON items.
862 *
863 * Being schema-free, the items in a container do not need to share the same structure or fields.
864 *
865 *
866 * Since containers are application resources, they can be authorized using either the
867 * master key or resource keys.
868 *
869 * @param body - Represents the body of the container.
870 * @param options - Use to set options like response page size, continuation tokens, etc.
871 */
872 createIfNotExists(body: ContainerRequest, options?: RequestOptions): Promise<ContainerResponse>;
873 /**
874 * Read all containers.
875 * @param options - Use to set options like response page size, continuation tokens, etc.
876 * @returns {@link QueryIterator} Allows you to return all containers in an array or iterate over them one at a time.
877 * @example Read all containers to array.
878 * ```typescript
879 * const {body: containerList} = await client.database("<db id>").containers.readAll().fetchAll();
880 * ```
881 */
882 readAll(options?: FeedOptions): QueryIterator<ContainerDefinition & Resource>;
883 }
884
885 /**
886 * Provides a client-side logical representation of the Azure Cosmos DB database account.
887 * This client is used to configure and execute requests in the Azure Cosmos DB database service.
888 * @example Instantiate a client and create a new database
889 * ```typescript
890 * const client = new CosmosClient({endpoint: "<URL HERE>", auth: {masterKey: "<KEY HERE>"}});
891 * await client.databases.create({id: "<datbase name here>"});
892 * ```
893 * @example Instantiate a client with custom Connection Policy
894 * ```typescript
895 * const connectionPolicy = new ConnectionPolicy();
896 * connectionPolicy.RequestTimeout = 10000;
897 * const client = new CosmosClient({
898 * endpoint: "<URL HERE>",
899 * auth: {masterKey: "<KEY HERE>"},
900 * connectionPolicy
901 * });
902 * ```
903 */
904 export declare class CosmosClient {
905 /**
906 * Used for creating new databases, or querying/reading all databases.
907 *
908 * Use `.database(id)` to read, replace, or delete a specific, existing database by id.
909 *
910 * @example Create a new database
911 * ```typescript
912 * const {resource: databaseDefinition, database} = await client.databases.create({id: "<name here>"});
913 * ```
914 */
915 readonly databases: Databases;
916 /**
917 * Used for querying & reading all offers.
918 *
919 * Use `.offer(id)` to read, or replace existing offers.
920 */
921 readonly offers: Offers;
922 private clientContext;
923 private endpointRefresher;
924 /**
925 * Creates a new {@link CosmosClient} object from a connection string. Your database connection string can be found in the Azure Portal
926 */
927 constructor(connectionString: string);
928 /**
929 * Creates a new {@link CosmosClient} object. See {@link CosmosClientOptions} for more details on what options you can use.
930 * @param options - bag of options; require at least endpoint and auth to be configured
931 */
932 constructor(options: CosmosClientOptions);
933 /**
934 * Get information about the current {@link DatabaseAccount} (including which regions are supported, etc.)
935 */
936 getDatabaseAccount(options?: RequestOptions): Promise<ResourceResponse<DatabaseAccount>>;
937 /**
938 * Gets the currently used write endpoint url. Useful for troubleshooting purposes.
939 *
940 * The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.
941 */
942 getWriteEndpoint(): Promise<string>;
943 /**
944 * Gets the currently used read endpoint. Useful for troubleshooting purposes.
945 *
946 * The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.
947 */
948 getReadEndpoint(): Promise<string>;
949 /**
950 * Gets the known write endpoints. Useful for troubleshooting purposes.
951 *
952 * The urls may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.
953 */
954 getWriteEndpoints(): Promise<readonly string[]>;
955 /**
956 * Gets the currently used read endpoint. Useful for troubleshooting purposes.
957 *
958 * The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.
959 */
960 getReadEndpoints(): Promise<readonly string[]>;
961 /**
962 * Used for reading, updating, or deleting a existing database by id or accessing containers belonging to that database.
963 *
964 * This does not make a network call. Use `.read` to get info about the database after getting the {@link Database} object.
965 *
966 * @param id - The id of the database.
967 * @example Create a new container off of an existing database
968 * ```typescript
969 * const container = client.database("<database id>").containers.create("<container id>");
970 * ```
971 *
972 * @example Delete an existing database
973 * ```typescript
974 * await client.database("<id here>").delete();
975 * ```
976 */
977 database(id: string): Database;
978 /**
979 * Used for reading, or updating a existing offer by id.
980 * @param id - The id of the offer.
981 */
982 offer(id: string): Offer;
983 /**
984 * Clears background endpoint refresher. Use client.dispose() when destroying the CosmosClient within another process.
985 */
986 dispose(): void;
987 private backgroundRefreshEndpointList;
988 }
989
990 export declare interface CosmosClientOptions {
991 /** The service endpoint to use to create the client. */
992 endpoint: string;
993 /** The account master or readonly key */
994 key?: string;
995 /** An object that contains resources tokens.
996 * Keys for the object are resource Ids and values are the resource tokens.
997 */
998 resourceTokens?: {
999 [resourcePath: string]: string;
1000 };
1001 /** A user supplied function for resolving header authorization tokens.
1002 * Allows users to generating their own auth tokens, potentially using a separate service
1003 */
1004 tokenProvider?: TokenProvider;
1005 /** AAD token from `@azure/identity`
1006 * Obtain a credential object by creating an `@azure/identity` credential object
1007 * We will then use your credential object and a scope URL (your cosmos db endpoint)
1008 * to authenticate requests to Cosmos
1009 */
1010 aadCredentials?: TokenCredential;
1011 /** An array of {@link Permission} objects. */
1012 permissionFeed?: PermissionDefinition[];
1013 /** An instance of {@link ConnectionPolicy} class.
1014 * This parameter is optional and the default connectionPolicy will be used if omitted.
1015 */
1016 connectionPolicy?: ConnectionPolicy;
1017 /** An optional parameter that represents the consistency level.
1018 * It can take any value from {@link ConsistencyLevel}.
1019 */
1020 consistencyLevel?: keyof typeof ConsistencyLevel;
1021 defaultHeaders?: CosmosHeaders_2;
1022 /** An optional custom http(s) Agent to be used in NodeJS enironments
1023 * Use an agent such as https://github.com/TooTallNate/node-proxy-agent if you need to connect to Cosmos via a proxy
1024 */
1025 agent?: Agent;
1026 /** A custom string to append to the default SDK user agent. */
1027 userAgentSuffix?: string;
1028 }
1029
1030 /**
1031 * @hidden
1032 */
1033 declare enum CosmosContainerChildResourceKind {
1034 Item = "ITEM",
1035 StoredProcedure = "STORED_PROCEDURE",
1036 UserDefinedFunction = "USER_DEFINED_FUNCTION",
1037 Trigger = "TRIGGER"
1038 }
1039
1040 export declare interface CosmosHeaders {
1041 [key: string]: any;
1042 }
1043
1044 declare interface CosmosHeaders_2 {
1045 [key: string]: string | boolean | number;
1046 }
1047
1048 /**
1049 * @hidden
1050 */
1051 declare enum CosmosKeyType {
1052 PrimaryMaster = "PRIMARY_MASTER",
1053 SecondaryMaster = "SECONDARY_MASTER",
1054 PrimaryReadOnly = "PRIMARY_READONLY",
1055 SecondaryReadOnly = "SECONDARY_READONLY"
1056 }
1057
1058 /**
1059 * Experimental internal only
1060 * Generates the payload representing the permission configuration for the sas token.
1061 */
1062 export declare function createAuthorizationSasToken(masterKey: string, sasTokenProperties: SasTokenProperties): Promise<string>;
1063
1064 export declare type CreateOperation = OperationWithItem & {
1065 operationType: typeof BulkOperationType.Create;
1066 };
1067
1068 export declare interface CreateOperationInput {
1069 partitionKey?: string | number | null | Record<string, unknown> | undefined;
1070 ifMatch?: string;
1071 ifNoneMatch?: string;
1072 operationType: typeof BulkOperationType.Create;
1073 resourceBody: JSONObject;
1074 }
1075
1076 /**
1077 * Operations for reading or deleting an existing database.
1078 *
1079 * @see {@link Databases} for creating new databases, and reading/querying all databases; use `client.databases`.
1080 *
1081 * Note: all these operations make calls against a fixed budget.
1082 * You should design your system such that these calls scale sublinearly with your application.
1083 * For instance, do not call `database.read()` before every single `item.read()` call, to ensure the database exists;
1084 * do this once on application start up.
1085 */
1086 export declare class Database {
1087 readonly client: CosmosClient;
1088 readonly id: string;
1089 private clientContext;
1090 /**
1091 * Used for creating new containers, or querying/reading all containers.
1092 *
1093 * Use `.database(id)` to read, replace, or delete a specific, existing {@link Database} by id.
1094 *
1095 * @example Create a new container
1096 * ```typescript
1097 * const {body: containerDefinition, container} = await client.database("<db id>").containers.create({id: "<container id>"});
1098 * ```
1099 */
1100 readonly containers: Containers;
1101 /**
1102 * Used for creating new users, or querying/reading all users.
1103 *
1104 * Use `.user(id)` to read, replace, or delete a specific, existing {@link User} by id.
1105 */
1106 readonly users: Users;
1107 /**
1108 * Returns a reference URL to the resource. Used for linking in Permissions.
1109 */
1110 get url(): string;
1111 /** Returns a new {@link Database} instance.
1112 *
1113 * Note: the intention is to get this object from {@link CosmosClient} via `client.database(id)`, not to instantiate it yourself.
1114 */
1115 constructor(client: CosmosClient, id: string, clientContext: ClientContext);
1116 /**
1117 * Used to read, replace, or delete a specific, existing {@link Database} by id.
1118 *
1119 * Use `.containers` creating new containers, or querying/reading all containers.
1120 *
1121 * @example Delete a container
1122 * ```typescript
1123 * await client.database("<db id>").container("<container id>").delete();
1124 * ```
1125 */
1126 container(id: string): Container;
1127 /**
1128 * Used to read, replace, or delete a specific, existing {@link User} by id.
1129 *
1130 * Use `.users` for creating new users, or querying/reading all users.
1131 */
1132 user(id: string): User;
1133 /** Read the definition of the given Database. */
1134 read(options?: RequestOptions): Promise<DatabaseResponse>;
1135 /** Delete the given Database. */
1136 delete(options?: RequestOptions): Promise<DatabaseResponse>;
1137 /**
1138 * Gets offer on database. If none exists, returns an OfferResponse with undefined.
1139 */
1140 readOffer(options?: RequestOptions): Promise<OfferResponse>;
1141 }
1142
1143 /**
1144 * Represents a DatabaseAccount in the Azure Cosmos DB database service.
1145 */
1146 export declare class DatabaseAccount {
1147 /** The list of writable locations for a geo-replicated database account. */
1148 readonly writableLocations: Location_2[];
1149 /** The list of readable locations for a geo-replicated database account. */
1150 readonly readableLocations: Location_2[];
1151 /**
1152 * The self-link for Databases in the databaseAccount.
1153 * @deprecated Use `databasesLink`
1154 */
1155 get DatabasesLink(): string;
1156 /** The self-link for Databases in the databaseAccount. */
1157 readonly databasesLink: string;
1158 /**
1159 * The self-link for Media in the databaseAccount.
1160 * @deprecated Use `mediaLink`
1161 */
1162 get MediaLink(): string;
1163 /** The self-link for Media in the databaseAccount. */
1164 readonly mediaLink: string;
1165 /**
1166 * Attachment content (media) storage quota in MBs ( Retrieved from gateway ).
1167 * @deprecated use `maxMediaStorageUsageInMB`
1168 */
1169 get MaxMediaStorageUsageInMB(): number;
1170 /** Attachment content (media) storage quota in MBs ( Retrieved from gateway ). */
1171 readonly maxMediaStorageUsageInMB: number;
1172 /**
1173 * Current attachment content (media) usage in MBs (Retrieved from gateway )
1174 *
1175 * Value is returned from cached information updated periodically and is not guaranteed
1176 * to be real time.
1177 *
1178 * @deprecated use `currentMediaStorageUsageInMB`
1179 */
1180 get CurrentMediaStorageUsageInMB(): number;
1181 /**
1182 * Current attachment content (media) usage in MBs (Retrieved from gateway )
1183 *
1184 * Value is returned from cached information updated periodically and is not guaranteed
1185 * to be real time.
1186 */
1187 readonly currentMediaStorageUsageInMB: number;
1188 /**
1189 * Gets the UserConsistencyPolicy settings.
1190 * @deprecated use `consistencyPolicy`
1191 */
1192 get ConsistencyPolicy(): ConsistencyLevel;
1193 /** Gets the UserConsistencyPolicy settings. */
1194 readonly consistencyPolicy: ConsistencyLevel;
1195 readonly enableMultipleWritableLocations: boolean;
1196 constructor(body: {
1197 [key: string]: any;
1198 }, headers: CosmosHeaders);
1199 }
1200
1201 export declare interface DatabaseDefinition {
1202 /** The id of the database. */
1203 id?: string;
1204 }
1205
1206 export declare interface DatabaseRequest extends DatabaseDefinition {
1207 /** Throughput for this database. */
1208 throughput?: number;
1209 maxThroughput?: number;
1210 autoUpgradePolicy?: {
1211 throughputPolicy: {
1212 incrementPercent: number;
1213 };
1214 };
1215 }
1216
1217 /** Response object for Database operations */
1218 export declare class DatabaseResponse extends ResourceResponse<DatabaseDefinition & Resource> {
1219 constructor(resource: DatabaseDefinition & Resource, headers: CosmosHeaders, statusCode: number, database: Database);
1220 /** A reference to the {@link Database} that the returned {@link DatabaseDefinition} corresponds to. */
1221 readonly database: Database;
1222 }
1223
1224 /**
1225 * Operations for creating new databases, and reading/querying all databases
1226 *
1227 * @see {@link Database} for reading or deleting an existing database; use `client.database(id)`.
1228 *
1229 * Note: all these operations make calls against a fixed budget.
1230 * You should design your system such that these calls scale sublinearly with your application.
1231 * For instance, do not call `databases.readAll()` before every single `item.read()` call, to ensure the database exists;
1232 * do this once on application start up.
1233 */
1234 export declare class Databases {
1235 readonly client: CosmosClient;
1236 private readonly clientContext;
1237 /**
1238 * @hidden
1239 * @param client - The parent {@link CosmosClient} for the Database.
1240 */
1241 constructor(client: CosmosClient, clientContext: ClientContext);
1242 /**
1243 * Queries all databases.
1244 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
1245 * @param options - Use to set options like response page size, continuation tokens, etc.
1246 * @returns {@link QueryIterator} Allows you to return all databases in an array or iterate over them one at a time.
1247 * @example Read all databases to array.
1248 * ```typescript
1249 * const querySpec: SqlQuerySpec = {
1250 * query: "SELECT * FROM root r WHERE r.id = @db",
1251 * parameters: [
1252 * {name: "@db", value: "Todo"}
1253 * ]
1254 * };
1255 * const {body: databaseList} = await client.databases.query(querySpec).fetchAll();
1256 * ```
1257 */
1258 query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
1259 /**
1260 * Queries all databases.
1261 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
1262 * @param options - Use to set options like response page size, continuation tokens, etc.
1263 * @returns {@link QueryIterator} Allows you to return all databases in an array or iterate over them one at a time.
1264 * @example Read all databases to array.
1265 * ```typescript
1266 * const querySpec: SqlQuerySpec = {
1267 * query: "SELECT * FROM root r WHERE r.id = @db",
1268 * parameters: [
1269 * {name: "@db", value: "Todo"}
1270 * ]
1271 * };
1272 * const {body: databaseList} = await client.databases.query(querySpec).fetchAll();
1273 * ```
1274 */
1275 query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
1276 /**
1277 * Send a request for creating a database.
1278 *
1279 * A database manages users, permissions and a set of containers.
1280 * Each Azure Cosmos DB Database Account is able to support multiple independent named databases,
1281 * with the database being the logical container for data.
1282 *
1283 * Each Database consists of one or more containers, each of which in turn contain one or more
1284 * documents. Since databases are an administrative resource, the Service Master Key will be
1285 * required in order to access and successfully complete any action using the User APIs.
1286 *
1287 * @param body - The {@link DatabaseDefinition} that represents the {@link Database} to be created.
1288 * @param options - Use to set options like response page size, continuation tokens, etc.
1289 */
1290 create(body: DatabaseRequest, options?: RequestOptions): Promise<DatabaseResponse>;
1291 /**
1292 * Check if a database exists, and if it doesn't, create it.
1293 * This will make a read operation based on the id in the `body`, then if it is not found, a create operation.
1294 *
1295 * A database manages users, permissions and a set of containers.
1296 * Each Azure Cosmos DB Database Account is able to support multiple independent named databases,
1297 * with the database being the logical container for data.
1298 *
1299 * Each Database consists of one or more containers, each of which in turn contain one or more
1300 * documents. Since databases are an an administrative resource, the Service Master Key will be
1301 * required in order to access and successfully complete any action using the User APIs.
1302 *
1303 * @param body - The {@link DatabaseDefinition} that represents the {@link Database} to be created.
1304 * @param options - Additional options for the request
1305 */
1306 createIfNotExists(body: DatabaseRequest, options?: RequestOptions): Promise<DatabaseResponse>;
1307 /**
1308 * Reads all databases.
1309 * @param options - Use to set options like response page size, continuation tokens, etc.
1310 * @returns {@link QueryIterator} Allows you to return all databases in an array or iterate over them one at a time.
1311 * @example Read all databases to array.
1312 * ```typescript
1313 * const {body: databaseList} = await client.databases.readAll().fetchAll();
1314 * ```
1315 */
1316 readAll(options?: FeedOptions): QueryIterator<DatabaseDefinition & Resource>;
1317 }
1318
1319 /** Defines a target data type of an index path specification in the Azure Cosmos DB service. */
1320 export declare enum DataType {
1321 /** Represents a numeric data type. */
1322 Number = "Number",
1323 /** Represents a string data type. */
1324 String = "String",
1325 /** Represents a point data type. */
1326 Point = "Point",
1327 /** Represents a line string data type. */
1328 LineString = "LineString",
1329 /** Represents a polygon data type. */
1330 Polygon = "Polygon",
1331 /** Represents a multi-polygon data type. */
1332 MultiPolygon = "MultiPolygon"
1333 }
1334
1335 export declare const DEFAULT_PARTITION_KEY_PATH: "/_partitionKey";
1336
1337 export declare type DeleteOperation = OperationBase & {
1338 operationType: typeof BulkOperationType.Delete;
1339 id: string;
1340 };
1341
1342 export declare interface DeleteOperationInput {
1343 partitionKey?: string | number | null | Record<string, unknown> | undefined;
1344 operationType: typeof BulkOperationType.Delete;
1345 id: string;
1346 }
1347
1348 export declare interface ErrorBody {
1349 code: string;
1350 message: string;
1351 /**
1352 * @hidden
1353 */
1354 additionalErrorInfo?: PartitionedQueryExecutionInfo;
1355 }
1356
1357 export declare class ErrorResponse extends Error {
1358 code?: number;
1359 substatus?: number;
1360 body?: ErrorBody;
1361 headers?: CosmosHeaders;
1362 activityId?: string;
1363 retryAfterInMs?: number;
1364 retryAfterInMilliseconds?: number;
1365 [key: string]: any;
1366 }
1367
1368 export declare type ExistingKeyOperation = {
1369 op: keyof typeof PatchOperationType;
1370 value: any;
1371 path: string;
1372 };
1373
1374 /**
1375 * @hidden
1376 */
1377 export declare function extractPartitionKey(document: unknown, partitionKeyDefinition: PartitionKeyDefinition): PartitionKey[];
1378
1379 /**
1380 * The feed options and query methods.
1381 */
1382 export declare interface FeedOptions extends SharedOptions {
1383 /** Opaque token for continuing the enumeration. Default: undefined
1384 * @deprecated Use continuationToken instead.
1385 */
1386 continuation?: string;
1387 /** Opaque token for continuing the enumeration. Default: undefined */
1388 continuationToken?: string;
1389 /**
1390 * Limits the size of the continuation token in the response. Default: undefined
1391 *
1392 * Continuation Tokens contain optional data that can be removed from the serialization before writing it out to a header.
1393 * By default we are capping this to 1kb to avoid long headers (Node.js has a global header size limit).
1394 * A user may set this field to allow for longer headers, which can help the backend optimize query execution."
1395 */
1396 continuationTokenLimitInKB?: number;
1397 /**
1398 * Allow scan on the queries which couldn't be served as indexing was opted out on the requested paths. Default: false
1399 *
1400 * In general, it is best to avoid using this setting. Scans are relatively expensive and take a long time to serve.
1401 */
1402 enableScanInQuery?: boolean;
1403 /**
1404 * The maximum number of concurrent operations that run client side during parallel query execution in the
1405 * Azure Cosmos DB database service. Negative values make the system automatically decides the number of
1406 * concurrent operations to run. Default: 0 (no parallelism)
1407 */
1408 maxDegreeOfParallelism?: number;
1409 /**
1410 * Max number of items to be returned in the enumeration operation. Default: undefined (server will defined payload)
1411 *
1412 * Expirimenting with this value can usually result in the biggest performance changes to the query.
1413 *
1414 * The smaller the item count, the faster the first result will be delivered (for non-aggregates). For larger amounts,
1415 * it will take longer to serve the request, but you'll usually get better throughput for large queries (i.e. if you need 1000 items
1416 * before you can do any other actions, set `maxItemCount` to 1000. If you can start doing work after the first 100, set `maxItemCount` to 100.)
1417 */
1418 maxItemCount?: number;
1419 /**
1420 * Note: consider using changeFeed instead.
1421 *
1422 * Indicates a change feed request. Must be set to "Incremental feed", or omitted otherwise. Default: false
1423 */
1424 useIncrementalFeed?: boolean;
1425 /** Conditions Associated with the request. */
1426 accessCondition?: {
1427 /** Conditional HTTP method header type (IfMatch or IfNoneMatch). */
1428 type: string;
1429 /** Conditional HTTP method header value (the _etag field from the last version you read). */
1430 condition: string;
1431 };
1432 /**
1433 * Enable returning query metrics in response headers. Default: false
1434 *
1435 * Used for debugging slow or expensive queries. Also increases response size and if you're using a low max header size in Node.js,
1436 * you can run into issues faster.
1437 */
1438 populateQueryMetrics?: boolean;
1439 /**
1440 * Enable buffering additional items during queries. Default: false
1441 *
1442 * This will buffer an additional page at a time (multiplied by maxDegreeOfParallelism) from the server in the background.
1443 * This improves latency by fetching pages before they are needed by the client. If you're draining all of the results from the
1444 * server, like `.fetchAll`, you should usually enable this. If you're only fetching one page at a time via continuation token,
1445 * you should avoid this. If you're draining more than one page, but not the entire result set, it may help improve latency, but
1446 * it will increase the total amount of RU/s use to serve the entire query (as some pages will be fetched more than once).
1447 */
1448 bufferItems?: boolean;
1449 /**
1450 * This setting forces the query to use a query plan. Default: false
1451 *
1452 * Note: this will disable continuation token support, even for single partition queries.
1453 *
1454 * For queries like aggregates and most cross partition queries, this happens anyway.
1455 * However, since the library doesn't know what type of query it is until we get back the first response,
1456 * some optimization can't happen until later.
1457 *
1458 * If this setting is enabled, it will force query plan for the query, which will save some network requests
1459 * and ensure parallelism can happen. Useful for when you know you're doing cross-partition or aggregate queries.
1460 */
1461 forceQueryPlan?: boolean;
1462 /** Limits the query to a specific partition key. Default: undefined
1463 *
1464 * Scoping a query to a single partition can be accomplished two ways:
1465 *
1466 * `container.items.query('SELECT * from c', { partitionKey: "foo" }).toArray()`
1467 * `container.items.query('SELECT * from c WHERE c.yourPartitionKey = "foo"').toArray()`
1468 *
1469 * The former is useful when the query body is out of your control
1470 * but you still want to restrict it to a single partition. Example: an end user specified query.
1471 */
1472 partitionKey?: any;
1473 }
1474
1475 export declare class FeedResponse<TResource> {
1476 readonly resources: TResource[];
1477 private readonly headers;
1478 readonly hasMoreResults: boolean;
1479 constructor(resources: TResource[], headers: CosmosHeaders, hasMoreResults: boolean);
1480 get continuation(): string;
1481 get continuationToken(): string;
1482 get queryMetrics(): string;
1483 get requestCharge(): number;
1484 get activityId(): string;
1485 }
1486
1487 /** @hidden */
1488 declare type FetchFunctionCallback = (options: FeedOptions) => Promise<Response_2<any>>;
1489
1490 export declare enum GeospatialType {
1491 /** Represents data in round-earth coordinate system. */
1492 Geography = "Geography",
1493 /** Represents data in Eucledian(flat) coordinate system. */
1494 Geometry = "Geometry"
1495 }
1496
1497 /**
1498 * @hidden
1499 * This internal class implements the logic for endpoint management for geo-replicated database accounts.
1500 */
1501 export declare class GlobalEndpointManager {
1502 private readDatabaseAccount;
1503 /**
1504 * The endpoint used to create the client instance.
1505 */
1506 private defaultEndpoint;
1507 /**
1508 * Flag to enable/disable automatic redirecting of requests based on read/write operations.
1509 */
1510 enableEndpointDiscovery: boolean;
1511 private isRefreshing;
1512 private options;
1513 /**
1514 * List of azure regions to be used as preferred locations for read requests.
1515 */
1516 private preferredLocations;
1517 private writeableLocations;
1518 private readableLocations;
1519 private unavailableReadableLocations;
1520 private unavailableWriteableLocations;
1521 /**
1522 * @param options - The document client instance.
1523 */
1524 constructor(options: CosmosClientOptions, readDatabaseAccount: (opts: RequestOptions) => Promise<ResourceResponse<DatabaseAccount>>);
1525 /**
1526 * Gets the current read endpoint from the endpoint cache.
1527 */
1528 getReadEndpoint(): Promise<string>;
1529 /**
1530 * Gets the current write endpoint from the endpoint cache.
1531 */
1532 getWriteEndpoint(): Promise<string>;
1533 getReadEndpoints(): Promise<ReadonlyArray<string>>;
1534 getWriteEndpoints(): Promise<ReadonlyArray<string>>;
1535 markCurrentLocationUnavailableForRead(endpoint: string): Promise<void>;
1536 markCurrentLocationUnavailableForWrite(endpoint: string): Promise<void>;
1537 canUseMultipleWriteLocations(resourceType?: ResourceType, operationType?: OperationType): boolean;
1538 resolveServiceEndpoint(resourceType: ResourceType, operationType: OperationType): Promise<string>;
1539 /**
1540 * Refreshes the endpoint list by clearning stale unavailability and then
1541 * retrieving the writable and readable locations from the geo-replicated database account
1542 * and then updating the locations cache.
1543 * We skip the refreshing if enableEndpointDiscovery is set to False
1544 */
1545 refreshEndpointList(): Promise<void>;
1546 private refreshEndpoints;
1547 private refreshStaleUnavailableLocations;
1548 /**
1549 * update the locationUnavailability to undefined if the location is available again
1550 * @param now - current time
1551 * @param unavailableLocations - list of unavailable locations
1552 * @param allLocations - list of all locations
1553 */
1554 private updateLocation;
1555 private cleanUnavailableLocationList;
1556 /**
1557 * Gets the database account first by using the default endpoint, and if that doesn't returns
1558 * use the endpoints for the preferred locations in the order they are specified to get
1559 * the database account.
1560 */
1561 private getDatabaseAccountFromAnyEndpoint;
1562 /**
1563 * Gets the locational endpoint using the location name passed to it using the default endpoint.
1564 *
1565 * @param defaultEndpoint - The default endpoint to use for the endpoint.
1566 * @param locationName - The location name for the azure region like "East US".
1567 */
1568 private static getLocationalEndpoint;
1569 }
1570
1571 export declare interface GroupByAliasToAggregateType {
1572 [key: string]: AggregateType;
1573 }
1574
1575 export declare type GroupByExpressions = string[];
1576
1577 /**
1578 * @hidden
1579 */
1580 export declare enum HTTPMethod {
1581 get = "GET",
1582 patch = "PATCH",
1583 post = "POST",
1584 put = "PUT",
1585 delete = "DELETE"
1586 }
1587
1588 export declare interface Index {
1589 kind: keyof typeof IndexKind;
1590 dataType: keyof typeof DataType;
1591 precision?: number;
1592 }
1593
1594 export declare interface IndexedPath {
1595 path: string;
1596 indexes?: Index[];
1597 }
1598
1599 /**
1600 * Specifies the supported indexing modes.
1601 */
1602 export declare enum IndexingMode {
1603 /**
1604 * Index is updated synchronously with a create or update operation.
1605 *
1606 * With consistent indexing, query behavior is the same as the default consistency level for the container.
1607 * The index is always kept up to date with the data.
1608 */
1609 consistent = "consistent",
1610 /**
1611 * Index is updated asynchronously with respect to a create or update operation.
1612 *
1613 * With lazy indexing, queries are eventually consistent. The index is updated when the container is idle.
1614 */
1615 lazy = "lazy",
1616 /** No Index is provided. */
1617 none = "none"
1618 }
1619
1620 export declare interface IndexingPolicy {
1621 /** The indexing mode (consistent or lazy) {@link IndexingMode}. */
1622 indexingMode?: keyof typeof IndexingMode;
1623 automatic?: boolean;
1624 /** An array of {@link IncludedPath} represents the paths to be included for indexing. */
1625 includedPaths?: IndexedPath[];
1626 /** An array of {@link IncludedPath} represents the paths to be excluded for indexing. */
1627 excludedPaths?: IndexedPath[];
1628 spatialIndexes?: SpatialIndex[];
1629 }
1630
1631 /**
1632 * Specifies the supported Index types.
1633 */
1634 export declare enum IndexKind {
1635 /**
1636 * This is supplied for a path which requires sorting.
1637 */
1638 Range = "Range",
1639 /**
1640 * This is supplied for a path which requires geospatial indexing.
1641 */
1642 Spatial = "Spatial"
1643 }
1644
1645 /**
1646 * Used to perform operations on a specific item.
1647 *
1648 * @see {@link Items} for operations on all items; see `container.items`.
1649 */
1650 export declare class Item {
1651 readonly container: Container;
1652 readonly id: string;
1653 private readonly clientContext;
1654 private partitionKey;
1655 /**
1656 * Returns a reference URL to the resource. Used for linking in Permissions.
1657 */
1658 get url(): string;
1659 /**
1660 * @hidden
1661 * @param container - The parent {@link Container}.
1662 * @param id - The id of the given {@link Item}.
1663 * @param partitionKey - The primary key of the given {@link Item} (only for partitioned containers).
1664 */
1665 constructor(container: Container, id: string, partitionKey: PartitionKey, clientContext: ClientContext);
1666 /**
1667 * Read the item's definition.
1668 *
1669 * Any provided type, T, is not necessarily enforced by the SDK.
1670 * You may get more or less properties and it's up to your logic to enforce it.
1671 * If the type, T, is a class, it won't pass `typeof` comparisons, because it won't have a match prototype.
1672 * It's recommended to only use interfaces.
1673 *
1674 * There is no set schema for JSON items. They may contain any number of custom properties.
1675 *
1676 * @param options - Additional options for the request
1677 *
1678 * @example Using custom type for response
1679 * ```typescript
1680 * interface TodoItem {
1681 * title: string;
1682 * done: bool;
1683 * id: string;
1684 * }
1685 *
1686 * let item: TodoItem;
1687 * ({body: item} = await item.read<TodoItem>());
1688 * ```
1689 */
1690 read<T extends ItemDefinition = any>(options?: RequestOptions): Promise<ItemResponse<T>>;
1691 /**
1692 * Replace the item's definition.
1693 *
1694 * There is no set schema for JSON items. They may contain any number of custom properties.
1695 *
1696 * @param body - The definition to replace the existing {@link Item}'s definition with.
1697 * @param options - Additional options for the request
1698 */
1699 replace(body: ItemDefinition, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>;
1700 /**
1701 * Replace the item's definition.
1702 *
1703 * Any provided type, T, is not necessarily enforced by the SDK.
1704 * You may get more or less properties and it's up to your logic to enforce it.
1705 *
1706 * There is no set schema for JSON items. They may contain any number of custom properties.
1707 *
1708 * @param body - The definition to replace the existing {@link Item}'s definition with.
1709 * @param options - Additional options for the request
1710 */
1711 replace<T extends ItemDefinition>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>;
1712 /**
1713 * Delete the item.
1714 *
1715 * Any provided type, T, is not necessarily enforced by the SDK.
1716 * You may get more or less properties and it's up to your logic to enforce it.
1717 *
1718 * @param options - Additional options for the request
1719 */
1720 delete<T extends ItemDefinition = any>(options?: RequestOptions): Promise<ItemResponse<T>>;
1721 /**
1722 * Perform a JSONPatch on the item.
1723 *
1724 * Any provided type, T, is not necessarily enforced by the SDK.
1725 * You may get more or less properties and it's up to your logic to enforce it.
1726 *
1727 * @param options - Additional options for the request
1728 */
1729 patch<T extends ItemDefinition = any>(body: PatchRequestBody, options?: RequestOptions): Promise<ItemResponse<T>>;
1730 }
1731
1732 /**
1733 * Items in Cosmos DB are simply JSON objects.
1734 * Most of the Item operations allow for your to provide your own type
1735 * that extends the very simple ItemDefinition.
1736 *
1737 * You cannot use any reserved keys. You can see the reserved key list
1738 * in {@link ItemBody}
1739 */
1740 export declare interface ItemDefinition {
1741 /** The id of the item. User settable property. Uniquely identifies the item along with the partition key */
1742 id?: string;
1743 /** Time to live in seconds for collections with TTL enabled */
1744 ttl?: number;
1745 [key: string]: any;
1746 }
1747
1748 export declare class ItemResponse<T extends ItemDefinition> extends ResourceResponse<T & Resource> {
1749 constructor(resource: T & Resource, headers: CosmosHeaders, statusCode: number, subsstatusCode: number, item: Item);
1750 /** Reference to the {@link Item} the response corresponds to. */
1751 readonly item: Item;
1752 }
1753
1754 /**
1755 * Operations for creating new items, and reading/querying all items
1756 *
1757 * @see {@link Item} for reading, replacing, or deleting an existing container; use `.item(id)`.
1758 */
1759 export declare class Items {
1760 readonly container: Container;
1761 private readonly clientContext;
1762 /**
1763 * Create an instance of {@link Items} linked to the parent {@link Container}.
1764 * @param container - The parent container.
1765 * @hidden
1766 */
1767 constructor(container: Container, clientContext: ClientContext);
1768 /**
1769 * Queries all items.
1770 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
1771 * @param options - Used for modifying the request (for instance, specifying the partition key).
1772 * @example Read all items to array.
1773 * ```typescript
1774 * const querySpec: SqlQuerySpec = {
1775 * query: "SELECT * FROM Families f WHERE f.lastName = @lastName",
1776 * parameters: [
1777 * {name: "@lastName", value: "Hendricks"}
1778 * ]
1779 * };
1780 * const {result: items} = await items.query(querySpec).fetchAll();
1781 * ```
1782 */
1783 query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
1784 /**
1785 * Queries all items.
1786 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
1787 * @param options - Used for modifying the request (for instance, specifying the partition key).
1788 * @example Read all items to array.
1789 * ```typescript
1790 * const querySpec: SqlQuerySpec = {
1791 * query: "SELECT firstname FROM Families f WHERE f.lastName = @lastName",
1792 * parameters: [
1793 * {name: "@lastName", value: "Hendricks"}
1794 * ]
1795 * };
1796 * const {result: items} = await items.query<{firstName: string}>(querySpec).fetchAll();
1797 * ```
1798 */
1799 query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
1800 /**
1801 * Create a `ChangeFeedIterator` to iterate over pages of changes
1802 *
1803 * @deprecated Use `changeFeed` instead.
1804 *
1805 * @example Read from the beginning of the change feed.
1806 * ```javascript
1807 * const iterator = items.readChangeFeed({ startFromBeginning: true });
1808 * const firstPage = await iterator.fetchNext();
1809 * const firstPageResults = firstPage.result
1810 * const secondPage = await iterator.fetchNext();
1811 * ```
1812 */
1813 readChangeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
1814 /**
1815 * Create a `ChangeFeedIterator` to iterate over pages of changes
1816 * @deprecated Use `changeFeed` instead.
1817 *
1818 */
1819 readChangeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
1820 /**
1821 * Create a `ChangeFeedIterator` to iterate over pages of changes
1822 * @deprecated Use `changeFeed` instead.
1823 */
1824 readChangeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
1825 /**
1826 * Create a `ChangeFeedIterator` to iterate over pages of changes
1827 * @deprecated Use `changeFeed` instead.
1828 */
1829 readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
1830 /**
1831 * Create a `ChangeFeedIterator` to iterate over pages of changes
1832 *
1833 * @example Read from the beginning of the change feed.
1834 * ```javascript
1835 * const iterator = items.readChangeFeed({ startFromBeginning: true });
1836 * const firstPage = await iterator.fetchNext();
1837 * const firstPageResults = firstPage.result
1838 * const secondPage = await iterator.fetchNext();
1839 * ```
1840 */
1841 changeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
1842 /**
1843 * Create a `ChangeFeedIterator` to iterate over pages of changes
1844 */
1845 changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
1846 /**
1847 * Create a `ChangeFeedIterator` to iterate over pages of changes
1848 */
1849 changeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
1850 /**
1851 * Create a `ChangeFeedIterator` to iterate over pages of changes
1852 */
1853 changeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
1854 /**
1855 * Read all items.
1856 *
1857 * There is no set schema for JSON items. They may contain any number of custom properties.
1858 *
1859 * @param options - Used for modifying the request (for instance, specifying the partition key).
1860 * @example Read all items to array.
1861 * ```typescript
1862 * const {body: containerList} = await items.readAll().fetchAll();
1863 * ```
1864 */
1865 readAll(options?: FeedOptions): QueryIterator<ItemDefinition>;
1866 /**
1867 * Read all items.
1868 *
1869 * Any provided type, T, is not necessarily enforced by the SDK.
1870 * You may get more or less properties and it's up to your logic to enforce it.
1871 *
1872 * There is no set schema for JSON items. They may contain any number of custom properties.
1873 *
1874 * @param options - Used for modifying the request (for instance, specifying the partition key).
1875 * @example Read all items to array.
1876 * ```typescript
1877 * const {body: containerList} = await items.readAll().fetchAll();
1878 * ```
1879 */
1880 readAll<T extends ItemDefinition>(options?: FeedOptions): QueryIterator<T>;
1881 /**
1882 * Create an item.
1883 *
1884 * Any provided type, T, is not necessarily enforced by the SDK.
1885 * You may get more or less properties and it's up to your logic to enforce it.
1886 *
1887 * There is no set schema for JSON items. They may contain any number of custom properties.
1888 *
1889 * @param body - Represents the body of the item. Can contain any number of user defined properties.
1890 * @param options - Used for modifying the request (for instance, specifying the partition key).
1891 */
1892 create<T extends ItemDefinition = any>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>;
1893 /**
1894 * Upsert an item.
1895 *
1896 * There is no set schema for JSON items. They may contain any number of custom properties.
1897 *
1898 * @param body - Represents the body of the item. Can contain any number of user defined properties.
1899 * @param options - Used for modifying the request (for instance, specifying the partition key).
1900 */
1901 upsert(body: unknown, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>;
1902 /**
1903 * Upsert an item.
1904 *
1905 * Any provided type, T, is not necessarily enforced by the SDK.
1906 * You may get more or less properties and it's up to your logic to enforce it.
1907 *
1908 * There is no set schema for JSON items. They may contain any number of custom properties.
1909 *
1910 * @param body - Represents the body of the item. Can contain any number of user defined properties.
1911 * @param options - Used for modifying the request (for instance, specifying the partition key).
1912 */
1913 upsert<T extends ItemDefinition>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>;
1914 /**
1915 * Execute bulk operations on items.
1916 *
1917 * Bulk takes an array of Operations which are typed based on what the operation does.
1918 * The choices are: Create, Upsert, Read, Replace, and Delete
1919 *
1920 * Usage example:
1921 * ```typescript
1922 * // partitionKey is optional at the top level if present in the resourceBody
1923 * const operations: OperationInput[] = [
1924 * {
1925 * operationType: "Create",
1926 * resourceBody: { id: "doc1", name: "sample", key: "A" }
1927 * },
1928 * {
1929 * operationType: "Upsert",
1930 * partitionKey: 'A',
1931 * resourceBody: { id: "doc2", name: "other", key: "A" }
1932 * }
1933 * ]
1934 *
1935 * await database.container.items.bulk(operations)
1936 * ```
1937 *
1938 * @param operations - List of operations. Limit 100
1939 * @param bulkOptions - Optional options object to modify bulk behavior. Pass \{ continueOnError: true \} to continue executing operations when one fails. (Defaults to false) ** NOTE: THIS WILL DEFAULT TO TRUE IN THE 4.0 RELEASE
1940 * @param options - Used for modifying the request.
1941 */
1942 bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<OperationResponse[]>;
1943 /**
1944 * Execute transactional batch operations on items.
1945 *
1946 * Batch takes an array of Operations which are typed based on what the operation does. Batch is transactional and will rollback all operations if one fails.
1947 * The choices are: Create, Upsert, Read, Replace, and Delete
1948 *
1949 * Usage example:
1950 * ```typescript
1951 * // partitionKey is required as a second argument to batch, but defaults to the default partition key
1952 * const operations: OperationInput[] = [
1953 * {
1954 * operationType: "Create",
1955 * resourceBody: { id: "doc1", name: "sample", key: "A" }
1956 * },
1957 * {
1958 * operationType: "Upsert",
1959 * partitionKey: 'A',
1960 * resourceBody: { id: "doc2", name: "other", key: "A" }
1961 * }
1962 * ]
1963 *
1964 * await database.container.items.batch(operations)
1965 * ```
1966 *
1967 * @param operations - List of operations. Limit 100
1968 * @param options - Used for modifying the request
1969 */
1970 batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions): Promise<Response_2<OperationResponse[]>>;
1971 }
1972
1973 export declare interface JSONArray extends ArrayLike<JSONValue> {
1974 }
1975
1976 export declare interface JSONObject {
1977 [key: string]: JSONValue;
1978 }
1979
1980 export declare type JSONValue = boolean | number | string | null | JSONArray | JSONObject;
1981
1982 /**
1983 * Used to specify the locations that are available, read is index 1 and write is index 0.
1984 */
1985 declare interface Location_2 {
1986 name: string;
1987 databaseAccountEndpoint: string;
1988 unavailable?: boolean;
1989 lastUnavailabilityTimestampInMs?: number;
1990 }
1991 export { Location_2 as Location }
1992
1993 /**
1994 * Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,
1995 * allowing you to log those results or handle errors.
1996 * @hidden
1997 */
1998 export declare type Next<T> = (context: RequestContext) => Promise<Response_2<T>>;
1999
2000 /**
2001 * Use to read or replace an existing {@link Offer} by id.
2002 *
2003 * @see {@link Offers} to query or read all offers.
2004 */
2005 export declare class Offer {
2006 readonly client: CosmosClient;
2007 readonly id: string;
2008 private readonly clientContext;
2009 /**
2010 * Returns a reference URL to the resource. Used for linking in Permissions.
2011 */
2012 get url(): string;
2013 /**
2014 * @hidden
2015 * @param client - The parent {@link CosmosClient} for the Database Account.
2016 * @param id - The id of the given {@link Offer}.
2017 */
2018 constructor(client: CosmosClient, id: string, clientContext: ClientContext);
2019 /**
2020 * Read the {@link OfferDefinition} for the given {@link Offer}.
2021 */
2022 read(options?: RequestOptions): Promise<OfferResponse>;
2023 /**
2024 * Replace the given {@link Offer} with the specified {@link OfferDefinition}.
2025 * @param body - The specified {@link OfferDefinition}
2026 */
2027 replace(body: OfferDefinition, options?: RequestOptions): Promise<OfferResponse>;
2028 }
2029
2030 export declare interface OfferDefinition {
2031 id?: string;
2032 offerType?: string;
2033 offerVersion?: string;
2034 resource?: string;
2035 offerResourceId?: string;
2036 content?: {
2037 offerThroughput: number;
2038 offerIsRUPerMinuteThroughputEnabled: boolean;
2039 offerMinimumThroughputParameters?: {
2040 maxThroughputEverProvisioned: number;
2041 maxConsumedStorageEverInKB: number;
2042 };
2043 offerAutopilotSettings?: {
2044 tier: number;
2045 maximumTierThroughput: number;
2046 autoUpgrade: boolean;
2047 maxThroughput: number;
2048 };
2049 };
2050 }
2051
2052 export declare class OfferResponse extends ResourceResponse<OfferDefinition & Resource> {
2053 constructor(resource: OfferDefinition & Resource, headers: CosmosHeaders, statusCode: number, offer?: Offer);
2054 /** A reference to the {@link Offer} corresponding to the returned {@link OfferDefinition}. */
2055 readonly offer: Offer;
2056 }
2057
2058 /**
2059 * Use to query or read all Offers.
2060 *
2061 * @see {@link Offer} to read or replace an existing {@link Offer} by id.
2062 */
2063 export declare class Offers {
2064 readonly client: CosmosClient;
2065 private readonly clientContext;
2066 /**
2067 * @hidden
2068 * @param client - The parent {@link CosmosClient} for the offers.
2069 */
2070 constructor(client: CosmosClient, clientContext: ClientContext);
2071 /**
2072 * Query all offers.
2073 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
2074 */
2075 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
2076 /**
2077 * Query all offers.
2078 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
2079 */
2080 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
2081 /**
2082 * Read all offers.
2083 * @example Read all offers to array.
2084 * ```typescript
2085 * const {body: offerList} = await client.offers.readAll().fetchAll();
2086 * ```
2087 */
2088 readAll(options?: FeedOptions): QueryIterator<OfferDefinition & Resource>;
2089 }
2090
2091 export declare type Operation = CreateOperation | UpsertOperation | ReadOperation | DeleteOperation | ReplaceOperation | BulkPatchOperation;
2092
2093 export declare interface OperationBase {
2094 partitionKey?: string;
2095 ifMatch?: string;
2096 ifNoneMatch?: string;
2097 }
2098
2099 export declare type OperationInput = CreateOperationInput | UpsertOperationInput | ReadOperationInput | DeleteOperationInput | ReplaceOperationInput | PatchOperationInput;
2100
2101 export declare interface OperationResponse {
2102 statusCode: number;
2103 requestCharge: number;
2104 eTag?: string;
2105 resourceBody?: JSONObject;
2106 }
2107
2108 /**
2109 * @hidden
2110 */
2111 export declare enum OperationType {
2112 Create = "create",
2113 Replace = "replace",
2114 Upsert = "upsert",
2115 Delete = "delete",
2116 Read = "read",
2117 Query = "query",
2118 Execute = "execute",
2119 Batch = "batch",
2120 Patch = "patch"
2121 }
2122
2123 export declare type OperationWithItem = OperationBase & {
2124 resourceBody: JSONObject;
2125 };
2126
2127 /**
2128 * @hidden
2129 */
2130 export declare interface PartitionedQueryExecutionInfo {
2131 partitionedQueryExecutionInfoVersion: number;
2132 queryInfo: QueryInfo;
2133 queryRanges: QueryRange[];
2134 }
2135
2136 export declare type PartitionKey = PartitionKeyDefinition | string | number | unknown;
2137
2138 export declare interface PartitionKeyDefinition {
2139 /**
2140 * An array of paths for which data within the collection can be partitioned. Paths must not contain a wildcard or
2141 * a trailing slash. For example, the JSON property “AccountNumber” is specified as “/AccountNumber”. The array must
2142 * contain only a single value.
2143 */
2144 paths: string[];
2145 /**
2146 * An optional field, if not specified the default value is 1. To use the large partition key set the version to 2.
2147 * To learn about large partition keys, see [how to create containers with large partition key](https://docs.microsoft.com/en-us/azure/cosmos-db/large-partition-keys) article.
2148 */
2149 version?: number;
2150 systemKey?: boolean;
2151 }
2152
2153 /**
2154 * @hidden
2155 */
2156 export declare interface PartitionKeyRange {
2157 id: string;
2158 minInclusive: string;
2159 maxExclusive: string;
2160 ridPrefix: number;
2161 throughputFraction: number;
2162 status: string;
2163 parents: string[];
2164 }
2165
2166 export declare interface PartitionKeyRangePropertiesNames {
2167 MinInclusive: "minInclusive";
2168 MaxExclusive: "maxExclusive";
2169 Id: "id";
2170 }
2171
2172 export declare type PatchOperation = ExistingKeyOperation | RemoveOperation;
2173
2174 export declare interface PatchOperationInput {
2175 partitionKey?: string | number | null | Record<string, unknown> | undefined;
2176 ifMatch?: string;
2177 ifNoneMatch?: string;
2178 operationType: typeof BulkOperationType.Patch;
2179 resourceBody: PatchRequestBody;
2180 id: string;
2181 }
2182
2183 export declare const PatchOperationType: {
2184 readonly add: "add";
2185 readonly replace: "replace";
2186 readonly remove: "remove";
2187 readonly set: "set";
2188 readonly incr: "incr";
2189 };
2190
2191 export declare type PatchRequestBody = {
2192 operations: PatchOperation[];
2193 condition?: string;
2194 } | PatchOperation[];
2195
2196 /**
2197 * Use to read, replace, or delete a given {@link Permission} by id.
2198 *
2199 * @see {@link Permissions} to create, upsert, query, or read all Permissions.
2200 */
2201 export declare class Permission {
2202 readonly user: User;
2203 readonly id: string;
2204 private readonly clientContext;
2205 /**
2206 * Returns a reference URL to the resource. Used for linking in Permissions.
2207 */
2208 get url(): string;
2209 /**
2210 * @hidden
2211 * @param user - The parent {@link User}.
2212 * @param id - The id of the given {@link Permission}.
2213 */
2214 constructor(user: User, id: string, clientContext: ClientContext);
2215 /**
2216 * Read the {@link PermissionDefinition} of the given {@link Permission}.
2217 */
2218 read(options?: RequestOptions): Promise<PermissionResponse>;
2219 /**
2220 * Replace the given {@link Permission} with the specified {@link PermissionDefinition}.
2221 * @param body - The specified {@link PermissionDefinition}.
2222 */
2223 replace(body: PermissionDefinition, options?: RequestOptions): Promise<PermissionResponse>;
2224 /**
2225 * Delete the given {@link Permission}.
2226 */
2227 delete(options?: RequestOptions): Promise<PermissionResponse>;
2228 }
2229
2230 export declare interface PermissionBody {
2231 /** System generated resource token for the particular resource and user */
2232 _token: string;
2233 }
2234
2235 export declare interface PermissionDefinition {
2236 /** The id of the permission */
2237 id: string;
2238 /** The mode of the permission, must be a value of {@link PermissionMode} */
2239 permissionMode: PermissionMode;
2240 /** The link of the resource that the permission will be applied to. */
2241 resource: string;
2242 resourcePartitionKey?: string | any[];
2243 }
2244
2245 /**
2246 * Enum for permission mode values.
2247 */
2248 export declare enum PermissionMode {
2249 /** Permission not valid. */
2250 None = "none",
2251 /** Permission applicable for read operations only. */
2252 Read = "read",
2253 /** Permission applicable for all operations. */
2254 All = "all"
2255 }
2256
2257 export declare class PermissionResponse extends ResourceResponse<PermissionDefinition & PermissionBody & Resource> {
2258 constructor(resource: PermissionDefinition & PermissionBody & Resource, headers: CosmosHeaders, statusCode: number, permission: Permission);
2259 /** A reference to the {@link Permission} corresponding to the returned {@link PermissionDefinition}. */
2260 readonly permission: Permission;
2261 }
2262
2263 /**
2264 * Use to create, replace, query, and read all Permissions.
2265 *
2266 * @see {@link Permission} to read, replace, or delete a specific permission by id.
2267 */
2268 declare class Permissions_2 {
2269 readonly user: User;
2270 private readonly clientContext;
2271 /**
2272 * @hidden
2273 * @param user - The parent {@link User}.
2274 */
2275 constructor(user: User, clientContext: ClientContext);
2276 /**
2277 * Query all permissions.
2278 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
2279 */
2280 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
2281 /**
2282 * Query all permissions.
2283 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
2284 */
2285 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
2286 /**
2287 * Read all permissions.
2288 * @example Read all permissions to array.
2289 * ```typescript
2290 * const {body: permissionList} = await user.permissions.readAll().fetchAll();
2291 * ```
2292 */
2293 readAll(options?: FeedOptions): QueryIterator<PermissionDefinition & Resource>;
2294 /**
2295 * Create a permission.
2296 *
2297 * A permission represents a per-User Permission to access a specific resource
2298 * e.g. Item or Container.
2299 * @param body - Represents the body of the permission.
2300 */
2301 create(body: PermissionDefinition, options?: RequestOptions): Promise<PermissionResponse>;
2302 /**
2303 * Upsert a permission.
2304 *
2305 * A permission represents a per-User Permission to access a
2306 * specific resource e.g. Item or Container.
2307 */
2308 upsert(body: PermissionDefinition, options?: RequestOptions): Promise<PermissionResponse>;
2309 }
2310 export { Permissions_2 as Permissions }
2311
2312 /**
2313 * Plugins allow you to customize the behavior of the SDk with additional logging, retry, or additional functionality.
2314 *
2315 * A plugin is a function which returns a `Promise<Response<T>>`, and is passed a RequestContext and Next object.
2316 *
2317 * Next is a function which takes in requestContext returns a promise. You must await/then that promise which will contain the response from further plugins,
2318 * allowing you to log those results or handle errors.
2319 *
2320 * RequestContext is an object which controls what operation is happening, against which endpoint, and more. Modifying this and passing it along via next is how
2321 * you modify future SDK behavior.
2322 *
2323 * @hidden
2324 */
2325 declare type Plugin_2<T> = (context: RequestContext, next: Next<T>) => Promise<Response_2<T>>;
2326 export { Plugin_2 as Plugin }
2327
2328 /**
2329 * Specifies which event to run for the specified plugin
2330 *
2331 * @hidden
2332 */
2333 export declare interface PluginConfig {
2334 /**
2335 * The event to run the plugin on
2336 */
2337 on: keyof typeof PluginOn;
2338 /**
2339 * The plugin to run
2340 */
2341 plugin: Plugin_2<any>;
2342 }
2343
2344 /**
2345 * Used to specify which type of events to execute this plug in on.
2346 *
2347 * @hidden
2348 */
2349 export declare enum PluginOn {
2350 /**
2351 * Will be executed per network request
2352 */
2353 request = "request",
2354 /**
2355 * Will be executed per API operation
2356 */
2357 operation = "operation"
2358 }
2359
2360 /**
2361 * @hidden
2362 */
2363 export declare interface QueryInfo {
2364 top?: any;
2365 orderBy?: any[];
2366 orderByExpressions?: any[];
2367 offset?: number;
2368 limit?: number;
2369 aggregates?: AggregateType[];
2370 groupByExpressions?: GroupByExpressions;
2371 groupByAliasToAggregateType: GroupByAliasToAggregateType;
2372 rewrittenQuery?: any;
2373 distinctType: string;
2374 hasSelectValue: boolean;
2375 }
2376
2377 /**
2378 * Represents a QueryIterator Object, an implementation of feed or query response that enables
2379 * traversal and iterating over the response
2380 * in the Azure Cosmos DB database service.
2381 */
2382 export declare class QueryIterator<T> {
2383 private clientContext;
2384 private query;
2385 private options;
2386 private fetchFunctions;
2387 private resourceLink?;
2388 private resourceType?;
2389 private fetchAllTempResources;
2390 private fetchAllLastResHeaders;
2391 private queryExecutionContext;
2392 private queryPlanPromise;
2393 private isInitialized;
2394 /**
2395 * @hidden
2396 */
2397 constructor(clientContext: ClientContext, query: SqlQuerySpec | string, options: FeedOptions, fetchFunctions: FetchFunctionCallback | FetchFunctionCallback[], resourceLink?: string, resourceType?: ResourceType);
2398 /**
2399 * Gets an async iterator that will yield results until completion.
2400 *
2401 * NOTE: AsyncIterators are a very new feature and you might need to
2402 * use polyfils/etc. in order to use them in your code.
2403 *
2404 * If you're using TypeScript, you can use the following polyfill as long
2405 * as you target ES6 or higher and are running on Node 6 or higher.
2406 *
2407 * ```typescript
2408 * if (!Symbol || !Symbol.asyncIterator) {
2409 * (Symbol as any).asyncIterator = Symbol.for("Symbol.asyncIterator");
2410 * }
2411 * ```
2412 *
2413 * @example Iterate over all databases
2414 * ```typescript
2415 * for await(const { resources: db } of client.databases.readAll().getAsyncIterator()) {
2416 * console.log(`Got ${db} from AsyncIterator`);
2417 * }
2418 * ```
2419 */
2420 getAsyncIterator(): AsyncIterable<FeedResponse<T>>;
2421 /**
2422 * Determine if there are still remaining resources to processs based on the value of the continuation token or the
2423 * elements remaining on the current batch in the QueryIterator.
2424 * @returns true if there is other elements to process in the QueryIterator.
2425 */
2426 hasMoreResults(): boolean;
2427 /**
2428 * Fetch all pages for the query and return a single FeedResponse.
2429 */
2430 fetchAll(): Promise<FeedResponse<T>>;
2431 /**
2432 * Retrieve the next batch from the feed.
2433 *
2434 * This may or may not fetch more pages from the backend depending on your settings
2435 * and the type of query. Aggregate queries will generally fetch all backend pages
2436 * before returning the first batch of responses.
2437 */
2438 fetchNext(): Promise<FeedResponse<T>>;
2439 /**
2440 * Reset the QueryIterator to the beginning and clear all the resources inside it
2441 */
2442 reset(): void;
2443 private toArrayImplementation;
2444 private createPipelinedExecutionContext;
2445 private fetchQueryPlan;
2446 private needsQueryPlan;
2447 private initPromise;
2448 private init;
2449 private _init;
2450 private handleSplitError;
2451 }
2452
2453 export declare class QueryMetrics {
2454 readonly retrievedDocumentCount: number;
2455 readonly retrievedDocumentSize: number;
2456 readonly outputDocumentCount: number;
2457 readonly outputDocumentSize: number;
2458 readonly indexHitDocumentCount: number;
2459 readonly totalQueryExecutionTime: TimeSpan;
2460 readonly queryPreparationTimes: QueryPreparationTimes;
2461 readonly indexLookupTime: TimeSpan;
2462 readonly documentLoadTime: TimeSpan;
2463 readonly vmExecutionTime: TimeSpan;
2464 readonly runtimeExecutionTimes: RuntimeExecutionTimes;
2465 readonly documentWriteTime: TimeSpan;
2466 readonly clientSideMetrics: ClientSideMetrics;
2467 constructor(retrievedDocumentCount: number, retrievedDocumentSize: number, outputDocumentCount: number, outputDocumentSize: number, indexHitDocumentCount: number, totalQueryExecutionTime: TimeSpan, queryPreparationTimes: QueryPreparationTimes, indexLookupTime: TimeSpan, documentLoadTime: TimeSpan, vmExecutionTime: TimeSpan, runtimeExecutionTimes: RuntimeExecutionTimes, documentWriteTime: TimeSpan, clientSideMetrics: ClientSideMetrics);
2468 /**
2469 * Gets the IndexHitRatio
2470 * @hidden
2471 */
2472 get indexHitRatio(): number;
2473 /**
2474 * returns a new QueryMetrics instance that is the addition of this and the arguments.
2475 */
2476 add(queryMetricsArray: QueryMetrics[]): QueryMetrics;
2477 /**
2478 * Output the QueryMetrics as a delimited string.
2479 * @hidden
2480 */
2481 toDelimitedString(): string;
2482 static readonly zero: QueryMetrics;
2483 /**
2484 * Returns a new instance of the QueryMetrics class that is the aggregation of an array of query metrics.
2485 */
2486 static createFromArray(queryMetricsArray: QueryMetrics[]): QueryMetrics;
2487 /**
2488 * Returns a new instance of the QueryMetrics class this is deserialized from a delimited string.
2489 */
2490 static createFromDelimitedString(delimitedString: string, clientSideMetrics?: ClientSideMetrics): QueryMetrics;
2491 }
2492
2493 export declare const QueryMetricsConstants: {
2494 RetrievedDocumentCount: string;
2495 RetrievedDocumentSize: string;
2496 OutputDocumentCount: string;
2497 OutputDocumentSize: string;
2498 IndexHitRatio: string;
2499 IndexHitDocumentCount: string;
2500 TotalQueryExecutionTimeInMs: string;
2501 QueryCompileTimeInMs: string;
2502 LogicalPlanBuildTimeInMs: string;
2503 PhysicalPlanBuildTimeInMs: string;
2504 QueryOptimizationTimeInMs: string;
2505 IndexLookupTimeInMs: string;
2506 DocumentLoadTimeInMs: string;
2507 VMExecutionTimeInMs: string;
2508 DocumentWriteTimeInMs: string;
2509 QueryEngineTimes: string;
2510 SystemFunctionExecuteTimeInMs: string;
2511 UserDefinedFunctionExecutionTimeInMs: string;
2512 RetrievedDocumentCountText: string;
2513 RetrievedDocumentSizeText: string;
2514 OutputDocumentCountText: string;
2515 OutputDocumentSizeText: string;
2516 IndexUtilizationText: string;
2517 TotalQueryExecutionTimeText: string;
2518 QueryPreparationTimesText: string;
2519 QueryCompileTimeText: string;
2520 LogicalPlanBuildTimeText: string;
2521 PhysicalPlanBuildTimeText: string;
2522 QueryOptimizationTimeText: string;
2523 QueryEngineTimesText: string;
2524 IndexLookupTimeText: string;
2525 DocumentLoadTimeText: string;
2526 WriteOutputTimeText: string;
2527 RuntimeExecutionTimesText: string;
2528 TotalExecutionTimeText: string;
2529 SystemFunctionExecuteTimeText: string;
2530 UserDefinedFunctionExecutionTimeText: string;
2531 ClientSideQueryMetricsText: string;
2532 RetriesText: string;
2533 RequestChargeText: string;
2534 FetchExecutionRangesText: string;
2535 SchedulingMetricsText: string;
2536 };
2537
2538 export declare class QueryPreparationTimes {
2539 readonly queryCompilationTime: TimeSpan;
2540 readonly logicalPlanBuildTime: TimeSpan;
2541 readonly physicalPlanBuildTime: TimeSpan;
2542 readonly queryOptimizationTime: TimeSpan;
2543 constructor(queryCompilationTime: TimeSpan, logicalPlanBuildTime: TimeSpan, physicalPlanBuildTime: TimeSpan, queryOptimizationTime: TimeSpan);
2544 /**
2545 * returns a new QueryPreparationTimes instance that is the addition of this and the arguments.
2546 */
2547 add(...queryPreparationTimesArray: QueryPreparationTimes[]): QueryPreparationTimes;
2548 /**
2549 * Output the QueryPreparationTimes as a delimited string.
2550 */
2551 toDelimitedString(): string;
2552 static readonly zero: QueryPreparationTimes;
2553 /**
2554 * Returns a new instance of the QueryPreparationTimes class that is the
2555 * aggregation of an array of QueryPreparationTimes.
2556 */
2557 static createFromArray(queryPreparationTimesArray: QueryPreparationTimes[]): QueryPreparationTimes;
2558 /**
2559 * Returns a new instance of the QueryPreparationTimes class this is deserialized from a delimited string.
2560 */
2561 static createFromDelimitedString(delimitedString: string): QueryPreparationTimes;
2562 }
2563
2564 /**
2565 * @hidden
2566 */
2567 export declare interface QueryRange {
2568 min: string;
2569 max: string;
2570 isMinInclusive: boolean;
2571 isMaxInclusive: boolean;
2572 }
2573
2574 export declare type ReadOperation = OperationBase & {
2575 operationType: typeof BulkOperationType.Read;
2576 id: string;
2577 };
2578
2579 export declare interface ReadOperationInput {
2580 partitionKey?: string | number | boolean | null | Record<string, unknown> | undefined;
2581 operationType: typeof BulkOperationType.Read;
2582 id: string;
2583 }
2584
2585 export declare type RemoveOperation = {
2586 op: "remove";
2587 path: string;
2588 };
2589
2590 export declare type ReplaceOperation = OperationWithItem & {
2591 operationType: typeof BulkOperationType.Replace;
2592 id: string;
2593 };
2594
2595 export declare interface ReplaceOperationInput {
2596 partitionKey?: string | number | null | Record<string, unknown> | undefined;
2597 ifMatch?: string;
2598 ifNoneMatch?: string;
2599 operationType: typeof BulkOperationType.Replace;
2600 resourceBody: JSONObject;
2601 id: string;
2602 }
2603
2604 /**
2605 * @hidden
2606 */
2607 export declare interface RequestContext {
2608 path?: string;
2609 operationType?: OperationType;
2610 client?: ClientContext;
2611 retryCount?: number;
2612 resourceType?: ResourceType;
2613 resourceId?: string;
2614 globalEndpointManager: GlobalEndpointManager;
2615 connectionPolicy: ConnectionPolicy;
2616 requestAgent: Agent;
2617 body?: any;
2618 headers?: CosmosHeaders_2;
2619 endpoint?: string;
2620 method: HTTPMethod;
2621 partitionKeyRangeId?: string;
2622 options: FeedOptions | RequestOptions;
2623 plugins: PluginConfig[];
2624 partitionKey?: PartitionKey;
2625 pipeline?: Pipeline;
2626 }
2627
2628 /** @hidden */
2629 declare interface RequestInfo_2 {
2630 verb: HTTPMethod;
2631 path: string;
2632 resourceId: string;
2633 resourceType: ResourceType;
2634 headers: CosmosHeaders;
2635 }
2636 export { RequestInfo_2 as RequestInfo }
2637
2638 /**
2639 * Options that can be specified for a requested issued to the Azure Cosmos DB servers.=
2640 */
2641 export declare interface RequestOptions extends SharedOptions {
2642 /** Conditions Associated with the request. */
2643 accessCondition?: {
2644 /** Conditional HTTP method header type (IfMatch or IfNoneMatch). */
2645 type: string;
2646 /** Conditional HTTP method header value (the _etag field from the last version you read). */
2647 condition: string;
2648 };
2649 /** Consistency level required by the client. */
2650 consistencyLevel?: string;
2651 /**
2652 * DisableRUPerMinuteUsage is used to enable/disable Request Units(RUs)/minute capacity
2653 * to serve the request if regular provisioned RUs/second is exhausted.
2654 */
2655 disableRUPerMinuteUsage?: boolean;
2656 /** Enables or disables logging in JavaScript stored procedures. */
2657 enableScriptLogging?: boolean;
2658 /** Specifies indexing directives (index, do not index .. etc). */
2659 indexingDirective?: string;
2660 /** The offer throughput provisioned for a container in measurement of Requests-per-Unit. */
2661 offerThroughput?: number;
2662 /**
2663 * Offer type when creating document containers.
2664 *
2665 * This option is only valid when creating a document container.
2666 */
2667 offerType?: string;
2668 /** Enables/disables getting document container quota related stats for document container read requests. */
2669 populateQuotaInfo?: boolean;
2670 /** Indicates what is the post trigger to be invoked after the operation. */
2671 postTriggerInclude?: string | string[];
2672 /** Indicates what is the pre trigger to be invoked before the operation. */
2673 preTriggerInclude?: string | string[];
2674 /** Expiry time (in seconds) for resource token associated with permission (applicable only for requests on permissions). */
2675 resourceTokenExpirySeconds?: number;
2676 /** (Advanced use case) The url to connect to. */
2677 urlConnection?: string;
2678 /** Disable automatic id generation (will cause creates to fail if id isn't on the definition) */
2679 disableAutomaticIdGeneration?: boolean;
2680 }
2681
2682 export declare interface Resource {
2683 /** Required. User settable property. Unique name that identifies the item, that is, no two items share the same ID within a database. The id must not exceed 255 characters. */
2684 id: string;
2685 /** System generated property. The resource ID (_rid) is a unique identifier that is also hierarchical per the resource stack on the resource model. It is used internally for placement and navigation of the item resource. */
2686 _rid: string;
2687 /** System generated property. Specifies the last updated timestamp of the resource. The value is a timestamp. */
2688 _ts: number;
2689 /** System generated property. The unique addressable URI for the resource. */
2690 _self: string;
2691 /** System generated property. Represents the resource etag required for optimistic concurrency control. */
2692 _etag: string;
2693 }
2694
2695 export declare class ResourceResponse<TResource> {
2696 readonly resource: TResource | undefined;
2697 readonly headers: CosmosHeaders_2;
2698 readonly statusCode: StatusCode;
2699 readonly substatus?: SubStatusCode;
2700 constructor(resource: TResource | undefined, headers: CosmosHeaders_2, statusCode: StatusCode, substatus?: SubStatusCode);
2701 get requestCharge(): number;
2702 get activityId(): string;
2703 get etag(): string;
2704 }
2705
2706 /**
2707 * @hidden
2708 */
2709 export declare enum ResourceType {
2710 none = "",
2711 database = "dbs",
2712 offer = "offers",
2713 user = "users",
2714 permission = "permissions",
2715 container = "colls",
2716 conflicts = "conflicts",
2717 sproc = "sprocs",
2718 udf = "udfs",
2719 trigger = "triggers",
2720 item = "docs",
2721 pkranges = "pkranges",
2722 partitionkey = "partitionKey"
2723 }
2724
2725 /**
2726 * @hidden
2727 */
2728 declare interface Response_2<T> {
2729 headers: CosmosHeaders;
2730 result?: T;
2731 code?: number;
2732 substatus?: number;
2733 }
2734 export { Response_2 as Response }
2735
2736 export { RestError }
2737
2738 /**
2739 * Represents the Retry policy assocated with throttled requests in the Azure Cosmos DB database service.
2740 */
2741 export declare interface RetryOptions {
2742 /** Max number of retries to be performed for a request. Default value 9. */
2743 maxRetryAttemptCount: number;
2744 /** Fixed retry interval in milliseconds to wait between each retry ignoring the retryAfter returned as part of the response. */
2745 fixedRetryIntervalInMilliseconds: number;
2746 /** Max wait time in seconds to wait for a request while the retries are happening. Default value 30 seconds. */
2747 maxWaitTimeInSeconds: number;
2748 }
2749
2750 export declare class RuntimeExecutionTimes {
2751 readonly queryEngineExecutionTime: TimeSpan;
2752 readonly systemFunctionExecutionTime: TimeSpan;
2753 readonly userDefinedFunctionExecutionTime: TimeSpan;
2754 constructor(queryEngineExecutionTime: TimeSpan, systemFunctionExecutionTime: TimeSpan, userDefinedFunctionExecutionTime: TimeSpan);
2755 /**
2756 * returns a new RuntimeExecutionTimes instance that is the addition of this and the arguments.
2757 */
2758 add(...runtimeExecutionTimesArray: RuntimeExecutionTimes[]): RuntimeExecutionTimes;
2759 /**
2760 * Output the RuntimeExecutionTimes as a delimited string.
2761 */
2762 toDelimitedString(): string;
2763 static readonly zero: RuntimeExecutionTimes;
2764 /**
2765 * Returns a new instance of the RuntimeExecutionTimes class that is
2766 * the aggregation of an array of RuntimeExecutionTimes.
2767 */
2768 static createFromArray(runtimeExecutionTimesArray: RuntimeExecutionTimes[]): RuntimeExecutionTimes;
2769 /**
2770 * Returns a new instance of the RuntimeExecutionTimes class this is deserialized from a delimited string.
2771 */
2772 static createFromDelimitedString(delimitedString: string): RuntimeExecutionTimes;
2773 }
2774
2775 /**
2776 * @hidden
2777 */
2778 export declare enum SasTokenPermissionKind {
2779 ContainerCreateItems = 1,
2780 ContainerReplaceItems = 2,
2781 ContainerUpsertItems = 4,
2782 ContainerDeleteItems = 128,
2783 ContainerExecuteQueries = 1,
2784 ContainerReadFeeds = 2,
2785 ContainerCreateStoreProcedure = 16,
2786 ContainerReadStoreProcedure = 4,
2787 ContainerReplaceStoreProcedure = 32,
2788 ContainerDeleteStoreProcedure = 64,
2789 ContainerCreateTriggers = 256,
2790 ContainerReadTriggers = 16,
2791 ContainerReplaceTriggers = 512,
2792 ContainerDeleteTriggers = 1024,
2793 ContainerCreateUserDefinedFunctions = 2048,
2794 ContainerReadUserDefinedFunctions = 8,
2795 ContainerReplaceUserDefinedFunctions = 4096,
2796 ContainerDeleteUserDefinedFunctions = 8192,
2797 ContainerExecuteStoredProcedure = 128,
2798 ContainerReadConflicts = 32,
2799 ContainerDeleteConflicts = 16384,
2800 ContainerReadAny = 64,
2801 ContainerFullAccess = 4294967295,
2802 ItemReadAny = 65536,
2803 ItemFullAccess = 65,
2804 ItemRead = 64,
2805 ItemReplace = 65536,
2806 ItemUpsert = 131072,
2807 ItemDelete = 262144,
2808 StoreProcedureRead = 128,
2809 StoreProcedureReplace = 1048576,
2810 StoreProcedureDelete = 2097152,
2811 StoreProcedureExecute = 4194304,
2812 UserDefinedFuntionRead = 256,
2813 UserDefinedFuntionReplace = 8388608,
2814 UserDefinedFuntionDelete = 16777216,
2815 TriggerRead = 512,
2816 TriggerReplace = 33554432,
2817 TriggerDelete = 67108864
2818 }
2819
2820 export declare class SasTokenProperties {
2821 user: string;
2822 userTag: string;
2823 databaseName: string;
2824 containerName: string;
2825 resourceName: string;
2826 resourcePath: string;
2827 resourceKind: CosmosContainerChildResourceKind;
2828 partitionKeyValueRanges: string[];
2829 startTime: Date;
2830 expiryTime: Date;
2831 keyType: CosmosKeyType | number;
2832 controlPlaneReaderScope: number;
2833 controlPlaneWriterScope: number;
2834 dataPlaneReaderScope: number;
2835 dataPlaneWriterScope: number;
2836 cosmosContainerChildResourceKind: CosmosContainerChildResourceKind;
2837 cosmosKeyType: CosmosKeyType;
2838 }
2839
2840 export declare class Scripts {
2841 readonly container: Container;
2842 private readonly clientContext;
2843 /**
2844 * @param container - The parent {@link Container}.
2845 * @hidden
2846 */
2847 constructor(container: Container, clientContext: ClientContext);
2848 /**
2849 * Used to read, replace, or delete a specific, existing {@link StoredProcedure} by id.
2850 *
2851 * Use `.storedProcedures` for creating new stored procedures, or querying/reading all stored procedures.
2852 * @param id - The id of the {@link StoredProcedure}.
2853 */
2854 storedProcedure(id: string): StoredProcedure;
2855 /**
2856 * Used to read, replace, or delete a specific, existing {@link Trigger} by id.
2857 *
2858 * Use `.triggers` for creating new triggers, or querying/reading all triggers.
2859 * @param id - The id of the {@link Trigger}.
2860 */
2861 trigger(id: string): Trigger;
2862 /**
2863 * Used to read, replace, or delete a specific, existing {@link UserDefinedFunction} by id.
2864 *
2865 * Use `.userDefinedFunctions` for creating new user defined functions, or querying/reading all user defined functions.
2866 * @param id - The id of the {@link UserDefinedFunction}.
2867 */
2868 userDefinedFunction(id: string): UserDefinedFunction;
2869 private $sprocs;
2870 /**
2871 * Operations for creating new stored procedures, and reading/querying all stored procedures.
2872 *
2873 * For reading, replacing, or deleting an existing stored procedure, use `.storedProcedure(id)`.
2874 */
2875 get storedProcedures(): StoredProcedures;
2876 private $triggers;
2877 /**
2878 * Operations for creating new triggers, and reading/querying all triggers.
2879 *
2880 * For reading, replacing, or deleting an existing trigger, use `.trigger(id)`.
2881 */
2882 get triggers(): Triggers;
2883 private $udfs;
2884 /**
2885 * Operations for creating new user defined functions, and reading/querying all user defined functions.
2886 *
2887 * For reading, replacing, or deleting an existing user defined function, use `.userDefinedFunction(id)`.
2888 */
2889 get userDefinedFunctions(): UserDefinedFunctions;
2890 }
2891
2892 /**
2893 * The default function for setting header token using the masterKey
2894 * @hidden
2895 */
2896 export declare function setAuthorizationTokenHeaderUsingMasterKey(verb: HTTPMethod, resourceId: string, resourceType: ResourceType, headers: CosmosHeaders, masterKey: string): Promise<void>;
2897
2898 /**
2899 * Options that can be specified for a requested issued to the Azure Cosmos DB servers.=
2900 */
2901 export declare interface SharedOptions {
2902 /** Enables/disables getting document container quota related stats for document container read requests. */
2903 sessionToken?: string;
2904 /** (Advanced use case) Initial headers to start with when sending requests to Cosmos */
2905 initialHeaders?: CosmosHeaders;
2906 /**
2907 * abortSignal to pass to all underlying network requests created by this method call. See https://developer.mozilla.org/en-US/docs/Web/API/AbortController
2908 * @example Cancel a read request
2909 * ```typescript
2910 * const controller = new AbortController()
2911 * const {result: item} = await items.query('SELECT * from c', { abortSignal: controller.signal});
2912 * controller.abort()
2913 * ```
2914 */
2915 abortSignal?: AbortSignal_2;
2916 /**
2917 * Sets the staleness value associated with the request in the Azure CosmosDB service. For requests where the {@link
2918 * com.azure.cosmos.ConsistencyLevel} is {@link com.azure.cosmos.ConsistencyLevel#EVENTUAL} or {@link com.azure.cosmos.ConsistencyLevel#SESSION}, responses from the
2919 * integrated cache are guaranteed to be no staler than value indicated by this maxIntegratedCacheStaleness. When the
2920 * consistency level is not set, this property is ignored.
2921 *
2922 * <p>Default value is null</p>
2923 *
2924 * <p>Cache Staleness is supported in milliseconds granularity. Anything smaller than milliseconds will be ignored.</p>
2925 */
2926 maxIntegratedCacheStalenessInMs?: number;
2927 }
2928
2929 export declare interface SpatialIndex {
2930 path: string;
2931 types: SpatialType[];
2932 boundingBox: {
2933 xmin: number;
2934 ymin: number;
2935 xmax: number;
2936 ymax: number;
2937 };
2938 }
2939
2940 export declare enum SpatialType {
2941 LineString = "LineString",
2942 MultiPolygon = "MultiPolygon",
2943 Point = "Point",
2944 Polygon = "Polygon"
2945 }
2946
2947 /**
2948 * Represents a parameter in a Parameterized SQL query, specified in {@link SqlQuerySpec}
2949 */
2950 export declare interface SqlParameter {
2951 /** Name of the parameter. (i.e. `@lastName`) */
2952 name: string;
2953 /** Value of the parameter (this is safe to come from users, assuming they are authorized) */
2954 value: JSONValue;
2955 }
2956
2957 /**
2958 * Represents a SQL query in the Azure Cosmos DB service.
2959 *
2960 * Queries with inputs should be parameterized to protect against SQL injection.
2961 *
2962 * @example Parameterized SQL Query
2963 * ```typescript
2964 * const query: SqlQuerySpec = {
2965 * query: "SELECT * FROM Families f where f.lastName = @lastName",
2966 * parameters: [
2967 * {name: "@lastName", value: "Wakefield"}
2968 * ]
2969 * };
2970 * ```
2971 */
2972 export declare interface SqlQuerySpec {
2973 /** The text of the SQL query */
2974 query: string;
2975 /** The parameters you provide in the query */
2976 parameters?: SqlParameter[];
2977 }
2978
2979 /**
2980 * @hidden
2981 */
2982 export declare type StatusCode = number;
2983
2984 /**
2985 * @hidden
2986 */
2987 export declare const StatusCodes: StatusCodesType;
2988
2989 /**
2990 * @hidden
2991 */
2992 export declare interface StatusCodesType {
2993 Ok: 200;
2994 Created: 201;
2995 Accepted: 202;
2996 NoContent: 204;
2997 NotModified: 304;
2998 BadRequest: 400;
2999 Unauthorized: 401;
3000 Forbidden: 403;
3001 NotFound: 404;
3002 MethodNotAllowed: 405;
3003 RequestTimeout: 408;
3004 Conflict: 409;
3005 Gone: 410;
3006 PreconditionFailed: 412;
3007 RequestEntityTooLarge: 413;
3008 TooManyRequests: 429;
3009 RetryWith: 449;
3010 InternalServerError: 500;
3011 ServiceUnavailable: 503;
3012 ENOTFOUND: "ENOTFOUND";
3013 OperationPaused: 1200;
3014 OperationCancelled: 1201;
3015 }
3016
3017 /**
3018 * Operations for reading, replacing, deleting, or executing a specific, existing stored procedure by id.
3019 *
3020 * For operations to create, read all, or query Stored Procedures,
3021 */
3022 export declare class StoredProcedure {
3023 readonly container: Container;
3024 readonly id: string;
3025 private readonly clientContext;
3026 /**
3027 * Returns a reference URL to the resource. Used for linking in Permissions.
3028 */
3029 get url(): string;
3030 /**
3031 * Creates a new instance of {@link StoredProcedure} linked to the parent {@link Container}.
3032 * @param container - The parent {@link Container}.
3033 * @param id - The id of the given {@link StoredProcedure}.
3034 * @hidden
3035 */
3036 constructor(container: Container, id: string, clientContext: ClientContext);
3037 /**
3038 * Read the {@link StoredProcedureDefinition} for the given {@link StoredProcedure}.
3039 */
3040 read(options?: RequestOptions): Promise<StoredProcedureResponse>;
3041 /**
3042 * Replace the given {@link StoredProcedure} with the specified {@link StoredProcedureDefinition}.
3043 * @param body - The specified {@link StoredProcedureDefinition} to replace the existing definition.
3044 */
3045 replace(body: StoredProcedureDefinition, options?: RequestOptions): Promise<StoredProcedureResponse>;
3046 /**
3047 * Delete the given {@link StoredProcedure}.
3048 */
3049 delete(options?: RequestOptions): Promise<StoredProcedureResponse>;
3050 /**
3051 * Execute the given {@link StoredProcedure}.
3052 *
3053 * The specified type, T, is not enforced by the client.
3054 * Be sure to validate the response from the stored procedure matches the type, T, you provide.
3055 *
3056 * @param partitionKey - The partition key to use when executing the stored procedure
3057 * @param params - Array of parameters to pass as arguments to the given {@link StoredProcedure}.
3058 * @param options - Additional options, such as the partition key to invoke the {@link StoredProcedure} on.
3059 */
3060 execute<T = any>(partitionKey: PartitionKey, params?: any[], options?: RequestOptions): Promise<ResourceResponse<T>>;
3061 }
3062
3063 export declare interface StoredProcedureDefinition {
3064 /**
3065 * The id of the {@link StoredProcedure}.
3066 */
3067 id?: string;
3068 /**
3069 * The body of the {@link StoredProcedure}. This is a JavaScript function.
3070 */
3071 body?: string | ((...inputs: any[]) => void);
3072 }
3073
3074 export declare class StoredProcedureResponse extends ResourceResponse<StoredProcedureDefinition & Resource> {
3075 constructor(resource: StoredProcedureDefinition & Resource, headers: CosmosHeaders, statusCode: number, storedProcedure: StoredProcedure);
3076 /**
3077 * A reference to the {@link StoredProcedure} which the {@link StoredProcedureDefinition} corresponds to.
3078 */
3079 readonly storedProcedure: StoredProcedure;
3080 /**
3081 * Alias for storedProcedure.
3082 *
3083 * A reference to the {@link StoredProcedure} which the {@link StoredProcedureDefinition} corresponds to.
3084 */
3085 get sproc(): StoredProcedure;
3086 }
3087
3088 /**
3089 * Operations for creating, upserting, or reading/querying all Stored Procedures.
3090 *
3091 * For operations to read, replace, delete, or execute a specific, existing stored procedure by id, see `container.storedProcedure()`.
3092 */
3093 export declare class StoredProcedures {
3094 readonly container: Container;
3095 private readonly clientContext;
3096 /**
3097 * @param container - The parent {@link Container}.
3098 * @hidden
3099 */
3100 constructor(container: Container, clientContext: ClientContext);
3101 /**
3102 * Query all Stored Procedures.
3103 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3104 * @example Read all stored procedures to array.
3105 * ```typescript
3106 * const querySpec: SqlQuerySpec = {
3107 * query: "SELECT * FROM root r WHERE r.id = @sproc",
3108 * parameters: [
3109 * {name: "@sproc", value: "Todo"}
3110 * ]
3111 * };
3112 * const {body: sprocList} = await containers.storedProcedures.query(querySpec).fetchAll();
3113 * ```
3114 */
3115 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
3116 /**
3117 * Query all Stored Procedures.
3118 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3119 * @example Read all stored procedures to array.
3120 * ```typescript
3121 * const querySpec: SqlQuerySpec = {
3122 * query: "SELECT * FROM root r WHERE r.id = @sproc",
3123 * parameters: [
3124 * {name: "@sproc", value: "Todo"}
3125 * ]
3126 * };
3127 * const {body: sprocList} = await containers.storedProcedures.query(querySpec).fetchAll();
3128 * ```
3129 */
3130 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
3131 /**
3132 * Read all stored procedures.
3133 * @example Read all stored procedures to array.
3134 * ```typescript
3135 * const {body: sprocList} = await containers.storedProcedures.readAll().fetchAll();
3136 * ```
3137 */
3138 readAll(options?: FeedOptions): QueryIterator<StoredProcedureDefinition & Resource>;
3139 /**
3140 * Create a StoredProcedure.
3141 *
3142 * Azure Cosmos DB allows stored procedures to be executed in the storage tier,
3143 * directly against an item container. The script
3144 * gets executed under ACID transactions on the primary storage partition of the
3145 * specified container. For additional details,
3146 * refer to the server-side JavaScript API documentation.
3147 */
3148 create(body: StoredProcedureDefinition, options?: RequestOptions): Promise<StoredProcedureResponse>;
3149 }
3150
3151 /**
3152 * @hidden
3153 */
3154 export declare type SubStatusCode = number;
3155
3156 export declare class TimeoutError extends Error {
3157 readonly code: string;
3158 constructor(message?: string);
3159 }
3160
3161 /**
3162 * Represents a time interval.
3163 *
3164 * @param days - Number of days.
3165 * @param hours - Number of hours.
3166 * @param minutes - Number of minutes.
3167 * @param seconds - Number of seconds.
3168 * @param milliseconds - Number of milliseconds.
3169 * @hidden
3170 */
3171 export declare class TimeSpan {
3172 protected _ticks: number;
3173 constructor(days: number, hours: number, minutes: number, seconds: number, milliseconds: number);
3174 /**
3175 * Returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.
3176 * @param ts - The time interval to add.
3177 */
3178 add(ts: TimeSpan): TimeSpan;
3179 /**
3180 * Returns a new TimeSpan object whose value is the difference of the specified TimeSpan object and this instance.
3181 * @param ts - The time interval to subtract.
3182 */
3183 subtract(ts: TimeSpan): TimeSpan;
3184 /**
3185 * Compares this instance to a specified object and returns an integer that indicates whether this
3186 * instance is shorter than, equal to, or longer than the specified object.
3187 * @param value - The time interval to add.
3188 */
3189 compareTo(value: TimeSpan): 1 | -1 | 0;
3190 /**
3191 * Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.
3192 */
3193 duration(): TimeSpan;
3194 /**
3195 * Returns a value indicating whether this instance is equal to a specified object.
3196 * @param value - The time interval to check for equality.
3197 */
3198 equals(value: TimeSpan): boolean;
3199 /**
3200 * Returns a new TimeSpan object whose value is the negated value of this instance.
3201 * @param value - The time interval to check for equality.
3202 */
3203 negate(): TimeSpan;
3204 days(): number;
3205 hours(): number;
3206 milliseconds(): number;
3207 seconds(): number;
3208 ticks(): number;
3209 totalDays(): number;
3210 totalHours(): number;
3211 totalMilliseconds(): number;
3212 totalMinutes(): number;
3213 totalSeconds(): number;
3214 static fromTicks(value: number): TimeSpan;
3215 static readonly zero: TimeSpan;
3216 static readonly maxValue: TimeSpan;
3217 static readonly minValue: TimeSpan;
3218 static isTimeSpan(timespan: TimeSpan): number;
3219 static additionDoesOverflow(a: number, b: number): boolean;
3220 static subtractionDoesUnderflow(a: number, b: number): boolean;
3221 static compare(t1: TimeSpan, t2: TimeSpan): 1 | 0 | -1;
3222 static interval(value: number, scale: number): TimeSpan;
3223 static fromMilliseconds(value: number): TimeSpan;
3224 static fromSeconds(value: number): TimeSpan;
3225 static fromMinutes(value: number): TimeSpan;
3226 static fromHours(value: number): TimeSpan;
3227 static fromDays(value: number): TimeSpan;
3228 }
3229
3230 export declare type TokenProvider = (requestInfo: RequestInfo_2) => Promise<string>;
3231
3232 /**
3233 * Operations to read, replace, or delete a {@link Trigger}.
3234 *
3235 * Use `container.triggers` to create, upsert, query, or read all.
3236 */
3237 export declare class Trigger {
3238 readonly container: Container;
3239 readonly id: string;
3240 private readonly clientContext;
3241 /**
3242 * Returns a reference URL to the resource. Used for linking in Permissions.
3243 */
3244 get url(): string;
3245 /**
3246 * @hidden
3247 * @param container - The parent {@link Container}.
3248 * @param id - The id of the given {@link Trigger}.
3249 */
3250 constructor(container: Container, id: string, clientContext: ClientContext);
3251 /**
3252 * Read the {@link TriggerDefinition} for the given {@link Trigger}.
3253 */
3254 read(options?: RequestOptions): Promise<TriggerResponse>;
3255 /**
3256 * Replace the given {@link Trigger} with the specified {@link TriggerDefinition}.
3257 * @param body - The specified {@link TriggerDefinition} to replace the existing definition with.
3258 */
3259 replace(body: TriggerDefinition, options?: RequestOptions): Promise<TriggerResponse>;
3260 /**
3261 * Delete the given {@link Trigger}.
3262 */
3263 delete(options?: RequestOptions): Promise<TriggerResponse>;
3264 }
3265
3266 export declare interface TriggerDefinition {
3267 /** The id of the trigger. */
3268 id?: string;
3269 /** The body of the trigger, it can also be passed as a stringifed function */
3270 body: (() => void) | string;
3271 /** The type of the trigger, should be one of the values of {@link TriggerType}. */
3272 triggerType: TriggerType;
3273 /** The trigger operation, should be one of the values of {@link TriggerOperation}. */
3274 triggerOperation: TriggerOperation;
3275 }
3276
3277 /**
3278 * Enum for trigger operation values.
3279 * specifies the operations on which a trigger should be executed.
3280 */
3281 export declare enum TriggerOperation {
3282 /** All operations. */
3283 All = "all",
3284 /** Create operations only. */
3285 Create = "create",
3286 /** Update operations only. */
3287 Update = "update",
3288 /** Delete operations only. */
3289 Delete = "delete",
3290 /** Replace operations only. */
3291 Replace = "replace"
3292 }
3293
3294 export declare class TriggerResponse extends ResourceResponse<TriggerDefinition & Resource> {
3295 constructor(resource: TriggerDefinition & Resource, headers: CosmosHeaders, statusCode: number, trigger: Trigger);
3296 /** A reference to the {@link Trigger} corresponding to the returned {@link TriggerDefinition}. */
3297 readonly trigger: Trigger;
3298 }
3299
3300 /**
3301 * Operations to create, upsert, query, and read all triggers.
3302 *
3303 * Use `container.triggers` to read, replace, or delete a {@link Trigger}.
3304 */
3305 export declare class Triggers {
3306 readonly container: Container;
3307 private readonly clientContext;
3308 /**
3309 * @hidden
3310 * @param container - The parent {@link Container}.
3311 */
3312 constructor(container: Container, clientContext: ClientContext);
3313 /**
3314 * Query all Triggers.
3315 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3316 */
3317 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
3318 /**
3319 * Query all Triggers.
3320 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3321 */
3322 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
3323 /**
3324 * Read all Triggers.
3325 * @example Read all trigger to array.
3326 * ```typescript
3327 * const {body: triggerList} = await container.triggers.readAll().fetchAll();
3328 * ```
3329 */
3330 readAll(options?: FeedOptions): QueryIterator<TriggerDefinition & Resource>;
3331 /**
3332 * Create a trigger.
3333 *
3334 * Azure Cosmos DB supports pre and post triggers defined in JavaScript to be executed
3335 * on creates, updates and deletes.
3336 *
3337 * For additional details, refer to the server-side JavaScript API documentation.
3338 */
3339 create(body: TriggerDefinition, options?: RequestOptions): Promise<TriggerResponse>;
3340 }
3341
3342 /**
3343 * Enum for trigger type values.
3344 * Specifies the type of the trigger.
3345 */
3346 export declare enum TriggerType {
3347 /** Trigger should be executed before the associated operation(s). */
3348 Pre = "pre",
3349 /** Trigger should be executed after the associated operation(s). */
3350 Post = "post"
3351 }
3352
3353 /** Interface for a single unique key passed as part of UniqueKeyPolicy */
3354 export declare interface UniqueKey {
3355 paths: string[];
3356 }
3357
3358 /** Interface for setting unique keys on container creation */
3359 export declare interface UniqueKeyPolicy {
3360 uniqueKeys: UniqueKey[];
3361 }
3362
3363 export declare type UpsertOperation = OperationWithItem & {
3364 operationType: typeof BulkOperationType.Upsert;
3365 };
3366
3367 export declare interface UpsertOperationInput {
3368 partitionKey?: string | number | null | Record<string, unknown> | undefined;
3369 ifMatch?: string;
3370 ifNoneMatch?: string;
3371 operationType: typeof BulkOperationType.Upsert;
3372 resourceBody: JSONObject;
3373 }
3374
3375 /**
3376 * Used to read, replace, and delete Users.
3377 *
3378 * Additionally, you can access the permissions for a given user via `user.permission` and `user.permissions`.
3379 *
3380 * @see {@link Users} to create, upsert, query, or read all.
3381 */
3382 export declare class User {
3383 readonly database: Database;
3384 readonly id: string;
3385 private readonly clientContext;
3386 /**
3387 * Operations for creating, upserting, querying, or reading all operations.
3388 *
3389 * See `client.permission(id)` to read, replace, or delete a specific Permission by id.
3390 */
3391 readonly permissions: Permissions_2;
3392 /**
3393 * Returns a reference URL to the resource. Used for linking in Permissions.
3394 */
3395 get url(): string;
3396 /**
3397 * @hidden
3398 * @param database - The parent {@link Database}.
3399 */
3400 constructor(database: Database, id: string, clientContext: ClientContext);
3401 /**
3402 * Operations to read, replace, or delete a specific Permission by id.
3403 *
3404 * See `client.permissions` for creating, upserting, querying, or reading all operations.
3405 */
3406 permission(id: string): Permission;
3407 /**
3408 * Read the {@link UserDefinition} for the given {@link User}.
3409 */
3410 read(options?: RequestOptions): Promise<UserResponse>;
3411 /**
3412 * Replace the given {@link User}'s definition with the specified {@link UserDefinition}.
3413 * @param body - The specified {@link UserDefinition} to replace the definition.
3414 */
3415 replace(body: UserDefinition, options?: RequestOptions): Promise<UserResponse>;
3416 /**
3417 * Delete the given {@link User}.
3418 */
3419 delete(options?: RequestOptions): Promise<UserResponse>;
3420 }
3421
3422 /**
3423 * Used to read, replace, or delete a specified User Definied Function by id.
3424 *
3425 * @see {@link UserDefinedFunction} to create, upsert, query, read all User Defined Functions.
3426 */
3427 export declare class UserDefinedFunction {
3428 readonly container: Container;
3429 readonly id: string;
3430 private readonly clientContext;
3431 /**
3432 * Returns a reference URL to the resource. Used for linking in Permissions.
3433 */
3434 get url(): string;
3435 /**
3436 * @hidden
3437 * @param container - The parent {@link Container}.
3438 * @param id - The id of the given {@link UserDefinedFunction}.
3439 */
3440 constructor(container: Container, id: string, clientContext: ClientContext);
3441 /**
3442 * Read the {@link UserDefinedFunctionDefinition} for the given {@link UserDefinedFunction}.
3443 */
3444 read(options?: RequestOptions): Promise<UserDefinedFunctionResponse>;
3445 /**
3446 * Replace the given {@link UserDefinedFunction} with the specified {@link UserDefinedFunctionDefinition}.
3447 * @param options -
3448 */
3449 replace(body: UserDefinedFunctionDefinition, options?: RequestOptions): Promise<UserDefinedFunctionResponse>;
3450 /**
3451 * Delete the given {@link UserDefined}.
3452 */
3453 delete(options?: RequestOptions): Promise<UserDefinedFunctionResponse>;
3454 }
3455
3456 export declare interface UserDefinedFunctionDefinition {
3457 /** The id of the {@link UserDefinedFunction} */
3458 id?: string;
3459 /** The body of the user defined function, it can also be passed as a stringifed function */
3460 body?: string | (() => void);
3461 }
3462
3463 export declare class UserDefinedFunctionResponse extends ResourceResponse<UserDefinedFunctionDefinition & Resource> {
3464 constructor(resource: UserDefinedFunctionDefinition & Resource, headers: CosmosHeaders, statusCode: number, udf: UserDefinedFunction);
3465 /** A reference to the {@link UserDefinedFunction} corresponding to the returned {@link UserDefinedFunctionDefinition}. */
3466 readonly userDefinedFunction: UserDefinedFunction;
3467 /**
3468 * Alias for `userDefinedFunction(id)`.
3469 *
3470 * A reference to the {@link UserDefinedFunction} corresponding to the returned {@link UserDefinedFunctionDefinition}.
3471 */
3472 get udf(): UserDefinedFunction;
3473 }
3474
3475 /**
3476 * Used to create, upsert, query, or read all User Defined Functions.
3477 *
3478 * @see {@link UserDefinedFunction} to read, replace, or delete a given User Defined Function by id.
3479 */
3480 export declare class UserDefinedFunctions {
3481 readonly container: Container;
3482 private readonly clientContext;
3483 /**
3484 * @hidden
3485 * @param container - The parent {@link Container}.
3486 */
3487 constructor(container: Container, clientContext: ClientContext);
3488 /**
3489 * Query all User Defined Functions.
3490 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3491 */
3492 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
3493 /**
3494 * Query all User Defined Functions.
3495 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3496 */
3497 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
3498 /**
3499 * Read all User Defined Functions.
3500 * @example Read all User Defined Functions to array.
3501 * ```typescript
3502 * const {body: udfList} = await container.userDefinedFunctions.readAll().fetchAll();
3503 * ```
3504 */
3505 readAll(options?: FeedOptions): QueryIterator<UserDefinedFunctionDefinition & Resource>;
3506 /**
3507 * Create a UserDefinedFunction.
3508 *
3509 * Azure Cosmos DB supports JavaScript UDFs which can be used inside queries, stored procedures and triggers.
3510 *
3511 * For additional details, refer to the server-side JavaScript API documentation.
3512 *
3513 */
3514 create(body: UserDefinedFunctionDefinition, options?: RequestOptions): Promise<UserDefinedFunctionResponse>;
3515 }
3516
3517 /**
3518 * Enum for udf type values.
3519 * Specifies the types of user defined functions.
3520 */
3521 export declare enum UserDefinedFunctionType {
3522 /** The User Defined Function is written in JavaScript. This is currently the only option. */
3523 Javascript = "Javascript"
3524 }
3525
3526 export declare interface UserDefinition {
3527 /** The id of the user. */
3528 id?: string;
3529 }
3530
3531 export declare class UserResponse extends ResourceResponse<UserDefinition & Resource> {
3532 constructor(resource: UserDefinition & Resource, headers: CosmosHeaders, statusCode: number, user: User);
3533 /** A reference to the {@link User} corresponding to the returned {@link UserDefinition}. */
3534 readonly user: User;
3535 }
3536
3537 /**
3538 * Used to create, upsert, query, and read all users.
3539 *
3540 * @see {@link User} to read, replace, or delete a specific User by id.
3541 */
3542 export declare class Users {
3543 readonly database: Database;
3544 private readonly clientContext;
3545 /**
3546 * @hidden
3547 * @param database - The parent {@link Database}.
3548 */
3549 constructor(database: Database, clientContext: ClientContext);
3550 /**
3551 * Query all users.
3552 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3553 */
3554 query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>;
3555 /**
3556 * Query all users.
3557 * @param query - Query configuration for the operation. See {@link SqlQuerySpec} for more info on how to configure a query.
3558 */
3559 query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>;
3560 /**
3561 * Read all users.-
3562 * @example Read all users to array.
3563 * ```typescript
3564 * const {body: usersList} = await database.users.readAll().fetchAll();
3565 * ```
3566 */
3567 readAll(options?: FeedOptions): QueryIterator<UserDefinition & Resource>;
3568 /**
3569 * Create a database user with the specified {@link UserDefinition}.
3570 * @param body - The specified {@link UserDefinition}.
3571 */
3572 create(body: UserDefinition, options?: RequestOptions): Promise<UserResponse>;
3573 /**
3574 * Upsert a database user with a specified {@link UserDefinition}.
3575 * @param body - The specified {@link UserDefinition}.
3576 */
3577 upsert(body: UserDefinition, options?: RequestOptions): Promise<UserResponse>;
3578 }
3579
3580 declare type VerboseOmit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
3581
3582 export { }
3583
\No newline at end of file