Skip to content

Commit f92b081

Browse files
committed
fix: mutateIn decrement no longer increment
1 parent 75106e7 commit f92b081

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/cbjs/src/sdspecs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ export class MutateInSpec<
819819
return MutateInSpec._create(
820820
binding.protocol_subdoc_opcode.counter,
821821
path,
822-
+decrementBy as Value,
822+
(-1 * +decrementBy) as Value,
823823
options
824824
);
825825
}

tests/cbjs/tests/kv.mutateIn.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,26 @@ describe.shuffle('kv mutateIn', async () => {
522522
arr: [1, 2, 3, 4, 5, 6],
523523
});
524524
});
525+
526+
test('should decrement the value without using a binary collection', async ({
527+
serverTestContext,
528+
testDocKey,
529+
expect,
530+
}) => {
531+
const result = await serverTestContext.collection
532+
.mutateIn(testDocKey)
533+
.decrement('int', 4);
534+
535+
expect(result.content[0].value).toEqual(10);
536+
expect(result.cas).toBeNonZeroCAS();
537+
expect(result.token).toBeMutationToken();
538+
539+
const resultGet = await serverTestContext.collection.get(testDocKey);
540+
541+
expect(resultGet.content).toStrictEqual({
542+
int: 10,
543+
str: 'hello',
544+
arr: [1, 2, 3],
545+
});
546+
});
525547
});

0 commit comments

Comments
 (0)