Skip to content

Commit b7ad302

Browse files
authored
fix(mutate): reflect support for providing transaction id in typings (#187)
1 parent f6f010a commit b7ad302

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/data/dataMethods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function _mutate<R extends Record<string, Any>>(
187187
}
188188

189189
const muts = Array.isArray(mut) ? mut : [mut]
190-
const transactionId = options && (options as Any).transactionId
190+
const transactionId = (options && options.transactionId) || undefined
191191
return _dataRequest(client, httpRequest, 'mutate', {mutations: muts, transactionId}, options)
192192
}
193193

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ export type BaseMutationOptions = RequestOptions & {
481481
dryRun?: boolean
482482
autoGenerateArrayKeys?: boolean
483483
skipCrossDatasetReferenceValidation?: boolean
484+
transactionId?: string
484485
}
485486

486487
/** @internal */

test/client.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,24 @@ describe('client', async () => {
917917
await expect(getClient().mutate(mutations, {tag: 'foobar'})).resolves.not.toThrow()
918918
})
919919

920+
test.skipIf(isEdge)('mutate() accepts transaction id', async () => {
921+
const mutations = [{delete: {id: 'abc123'}}]
922+
923+
nock(projectHost())
924+
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', {
925+
mutations,
926+
transactionId: 'spec-ific',
927+
})
928+
.reply(200, {
929+
transactionId: 'spec-ific',
930+
results: [{id: 'abc123', operation: 'delete', document: {_id: 'abc123'}}],
931+
})
932+
933+
await expect(
934+
getClient().mutate(mutations, {transactionId: 'spec-ific'})
935+
).resolves.not.toThrow()
936+
})
937+
920938
test.skipIf(isEdge)('mutate() accepts `autoGenerateArrayKeys`', async () => {
921939
const mutations = [
922940
{

0 commit comments

Comments
 (0)