Skip to content

Commit 04c2f1f

Browse files
committed
fix casing in patch command payload; add advanced patching example
1 parent 7efe82c commit 04c2f1f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Added support for the following features:
1010
- More like this
1111
- [Suggestions](#suggestions)
1212
- [Revisions](#revisions)
13+
- [Advanced patching](#advanced-patching)
1314

1415
### 4.0.2 - 2018-09-14
1516
Added support for the following features:
@@ -736,6 +737,12 @@ const suggestionQueryResult = await session.query({ collection: "users" })
736737
// { name: { name: 'name', suggestions: [ 'john' ] } }
737738
```
738739

740+
### Advanced patching
741+
```javascript
742+
session.advanced.increment("users/1", "age", 1);
743+
session.advanced.patch("users/1", "underAge", false);
744+
await session.saveChanges();
745+
```
739746

740747
## Using object literals for entities
741748

src/Documents/Operations/PatchOperation.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { pick } from "stream-json/filters/Pick";
1818
import { filter } from "stream-json/filters/Filter";
1919
import { ignore } from "stream-json/filters/Ignore";
2020
import { parseRestOfOutput } from "../../Mapping/Json/Streams/Pipelines";
21+
import { ObjectUtil } from "../../Utility/ObjectUtil";
2122

2223
export interface Payload {
2324
patch: PatchRequest;
@@ -128,7 +129,17 @@ export class PatchCommand extends RavenCommand<PatchResult> {
128129

129130
this._id = id;
130131
this._changeVector = changeVector;
131-
this._patch = conventions.objectMapper.toObjectLiteral({ patch, patchIfMissing });
132+
this._patch = ObjectUtil.transformObjectKeys(
133+
conventions.objectMapper.toObjectLiteral({ patch, patchIfMissing }),
134+
{
135+
defaultTransform: "pascal",
136+
paths: [
137+
{
138+
transform: conventions.remoteEntityFieldNameConvention,
139+
path: /Values/i
140+
}
141+
]
142+
});
132143
this._skipPatchIfChangeVectorMismatch = skipPatchIfChangeVectorMismatch;
133144
this._returnDebugInformation = returnDebugInformation;
134145
this._test = test;
@@ -154,7 +165,7 @@ export class PatchCommand extends RavenCommand<PatchResult> {
154165
uri += "&test=true";
155166
}
156167

157-
const body = this._serializer.serialize(this._patch);
168+
const body = JSON.stringify(this._patch);
158169
const req = {
159170
method: "PATCH",
160171
uri,

test/Ported/Server/Patching/AdvancedPatchingTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("AdvancedPatchingTest", function () {
2020
afterEach(async () =>
2121
await disposeTestDocumentStore(store));
2222

23-
it.skip("can test with variables", async () => {
23+
it("can test with variables", async () => {
2424

2525
{
2626
const session = store.openSession();

0 commit comments

Comments
 (0)