From 4d7e5ef00b16d0a7a08eba13cc8f4c1e7c16040c Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Fri, 25 Sep 2020 12:05:37 +0200 Subject: [PATCH] Fix replaceByExample/updateByExample --- CHANGELOG.md | 6 ++++++ src/collection.ts | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8486eb4..35d6b7c93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,12 @@ This driver uses semantic versioning: - Fixed empty query results containing `[undefined]` ([#687](https://github.com/arangodb/arangojs/issues/683)) +- Fixed `updateByExample` and `replaceByExample` new value parameter name + + Note that these methods are still deprecated. Previously the `newValue` + parameter was incorrectly called `newData`, which prevented the methods from + working at all. + ## [7.0.1] - 2020-08-21 This is a maintenance release because the initial v7 release did not include diff --git a/src/collection.ts b/src/collection.ts index c13f89873..5654998f6 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -2175,7 +2175,7 @@ export interface DocumentCollection * Replaces all documents in the collection matching the given example. * * @param example - An object representing an example for the documents. - * @param newData - Document data to replace the matching documents with. + * @param newValue - Document data to replace the matching documents with. * @param options - Options for replacing the documents. * * @deprecated Simple Queries have been deprecated in ArangoDB 3.4 and can be @@ -2185,16 +2185,16 @@ export interface DocumentCollection * ```js * const db = new Database(); * const collection = db.collection("some-collection"); - * const newData = { flavor: "chocolate" }; + * const newValue = { flavor: "chocolate" }; * // const { replaced } = await collection.replaceByExample( * // { flavor: "strawberry" }, - * // newData + * // newValue * // ); * const cursor = await db.query(aql` * RETURN LENGTH( * FOR doc IN ${collection} * FILTER doc.flavor == "strawberry" - * REPLACE doc WITH ${newData} IN ${collection} + * REPLACE doc WITH ${newValue} IN ${collection} * RETURN 1 * ) * `); @@ -2203,7 +2203,7 @@ export interface DocumentCollection */ replaceByExample( example: Partial>, - newData: DocumentData, + newValue: DocumentData, options?: SimpleQueryReplaceByExampleOptions ): Promise; @@ -2211,7 +2211,7 @@ export interface DocumentCollection * Updates all documents in the collection matching the given example. * * @param example - An object representing an example for the documents. - * @param newData - Document data to update the matching documents with. + * @param newValue - Document data to update the matching documents with. * @param options - Options for updating the documents. * * @deprecated Simple Queries have been deprecated in ArangoDB 3.4 and can be @@ -2224,13 +2224,13 @@ export interface DocumentCollection * const newData = { color: "red" }; * // const { updated } = await collection.updateByExample( * // { flavor: "strawberry" }, - * // newData + * // newValue * // ); * const cursor = await db.query(aql` * RETURN LENGTH( * FOR doc IN ${collection} * FILTER doc.flavor == "strawberry" - * UPDATE doc WITH ${newData} IN ${collection} + * UPDATE doc WITH ${newValue} IN ${collection} * RETURN 1 * ) * `); @@ -2239,7 +2239,7 @@ export interface DocumentCollection */ updateByExample( example: Partial>, - newData: Patch>, + newValue: Patch>, options?: SimpleQueryUpdateByExampleOptions ): Promise; @@ -3756,7 +3756,7 @@ export class Collection replaceByExample( example: Partial>, - newData: DocumentData, + newValue: DocumentData, options?: SimpleQueryReplaceByExampleOptions ) { return this._db.request( @@ -3766,7 +3766,7 @@ export class Collection body: { ...options, example, - newData, + newValue, collection: this._name, }, }, @@ -3776,7 +3776,7 @@ export class Collection updateByExample( example: Partial>, - newData: Patch>, + newValue: Patch>, options?: SimpleQueryUpdateByExampleOptions ) { return this._db.request( @@ -3786,7 +3786,7 @@ export class Collection body: { ...options, example, - newData, + newValue, collection: this._name, }, },