From 139f9d33f9c2a12d1c66f89095e72e71e1d34d28 Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Wed, 20 Nov 2024 12:33:59 +0100 Subject: [PATCH] Add missing options Fixes DE-940. Fixes DE-946. Fixes DE-947. Fixes DE-956. --- CHANGELOG.md | 16 ++++++++++++++++ src/collection.ts | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94522771..0113f880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,6 +131,22 @@ This driver uses semantic versioning: This property is always present if the error has a `response` property. In normal use this should always be the case. +- Added `keepNull` option to `CollectionInsertOptions` type (DE-946) + + This option was previously missing from the type. + +- Added `allowDirtyRead` option to `DocumentExistsOptions` type (DE-956) + + This option was previously missing from the type. + +- Added `ignoreRevs` option to `CollectionBatchReadOptions` type (DE-947) + + This option was previously missing from the type. + +- Added `options` argument to `CollectionTruncateOptions` type (DE-940) + + There was previously no way to pass options to the `truncate` method. + - Added `database` property to `Analyzer`, `ArrayCursor`, `BatchedArrayCursor`, `Collection`, `Graph`, `Job`, `Route`, `Transaction` and `View` types (DE-935) diff --git a/src/collection.ts b/src/collection.ts index 7a90485d..a9566f90 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -483,6 +483,21 @@ export type CollectionChecksumOptions = { withData?: boolean; }; +/** + * Options for truncating collections. + */ +export type CollectionTruncateOptions = { + /** + * Whether the collection should be compacted after truncation. + */ + compact?: boolean; + /** + * Whether data should be synchronized to disk before returning from this + * operation. + */ + waitForSync?: boolean; +}; + /** * Options for dropping collections. */ @@ -623,6 +638,12 @@ export type CreateCollectionOptions = { * Options for checking whether a document exists in a collection. */ export type DocumentExistsOptions = { + /** + * If set to `true`, the request will explicitly permit ArangoDB to return a + * potentially dirty or stale result and arangojs will load balance the + * request without distinguishing between leaders and followers. + */ + allowDirtyRead?: boolean; /** * If set to a document revision, the document will only match if its `_rev` * matches the given revision. @@ -673,6 +694,13 @@ export type CollectionBatchReadOptions = { * request without distinguishing between leaders and followers. */ allowDirtyRead?: boolean; + /** + * If set to `false`, the existing document will only be modified if its + * `_rev` property matches the same property on the new data. + * + * Default: `true` + */ + ignoreRevs?: boolean; }; /** @@ -715,6 +743,13 @@ export type CollectionInsertOptions = { * Default: `"conflict" */ overwriteMode?: "ignore" | "update" | "replace" | "conflict"; + /** + * If set to `false`, properties with a value of `null` will be removed from + * the new document. + * + * Default: `true` + */ + keepNull?: boolean; /** * If set to `false`, object properties that already exist in the old * document will be overwritten rather than merged when an existing document @@ -1306,7 +1341,7 @@ export interface DocumentCollection< * // the collection "some-collection" is now empty * ``` */ - truncate(): Promise>; + truncate(options?: CollectionTruncateOptions): Promise>; /** * Deletes the collection from the database. * @@ -2896,10 +2931,11 @@ export class Collection< return result; } - truncate(): Promise> { + truncate(options?: CollectionTruncateOptions): Promise> { return this._db.request({ method: "PUT", path: `/_api/collection/${this._name}/truncate`, + search: options, }); }