Skip to content

Commit 72497db

Browse files
authored
Merge pull request #152 from gregolsky/v4.0
patch serialization fixes; exports tweaks
2 parents eab25cd + 9c72080 commit 72497db

File tree

10 files changed

+61
-12
lines changed

10 files changed

+61
-12
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ before_install:
3030
- pwd && ls
3131
script:
3232
- npm run lint
33-
- npm run test
33+
- npm run test
34+
- npm run build
35+
- node -e "require('./dist').DocumentStore"

README.md

Lines changed: 11 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,16 @@ 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+
// increments *age* field by 1
744+
745+
session.advanced.patch("users/1", "underAge", false);
746+
// sets *underAge* field to *false*
747+
748+
await session.saveChanges();
749+
```
739750

740751
## Using object literals for entities
741752

src/Documents/Commands/GetRevisionsCommand.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { DocumentConventions, IRavenArrayResult, ServerNode } from "../..";
2-
import { RavenCommand } from "../../../src/Http/RavenCommand";
31
import { TypeUtil } from "../../Utility/TypeUtil";
42
import { HttpRequestParameters } from "../../Primitives/Http";
53
import { DateUtil } from "../../Utility/DateUtil";
64
import * as stream from "readable-stream";
75
import { GetDocumentsCommand } from "./GetDocumentsCommand";
6+
import { RavenCommand } from "../../Http/RavenCommand";
7+
import { IRavenArrayResult } from "../../Types";
8+
import { DocumentConventions } from "../Conventions/DocumentConventions";
9+
import { ServerNode } from "../../Http/ServerNode";
810

911
export class GetRevisionsCommand extends RavenCommand<IRavenArrayResult> {
1012

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,

src/Documents/Session/DocumentStreamIterable.ts renamed to src/Documents/Session/DocumentResultStream.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { StreamResult } from "../Commands/StreamResult";
22
import { TypedEventEmitter } from "../../Primitives/Events";
33
import { StreamQueryStatistics } from "./StreamQueryStatistics";
44

5-
export interface StreamingQueryEvents {
6-
"afterStreamExecuted": object;
7-
}
8-
95
export interface DocumentStreamResultEvents<TEntity extends object> {
106
data: StreamResult<TEntity>;
117
error: Error;

src/Documents/Session/DocumentSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { IRevisionsSessionOperations } from "./IRevisionsSessionOperations";
5353
import { DocumentSessionRevisions } from "./DocumentSessionRevisions";
5454
import * as StreamUtil from "../../Utility/StreamUtil";
5555
import { StreamResult } from "../Commands/StreamResult";
56-
import { DocumentResultStream } from "./DocumentStreamIterable";
56+
import { DocumentResultStream } from "./DocumentResultStream";
5757
import { StreamOperation } from "./Operations/StreamOperation";
5858
import { QueryOperation } from "./Operations/QueryOperation";
5959
import { StreamQueryStatisticsCallback } from "./IAdvancedSessionOperations";

src/Documents/Session/IAdvancedSessionOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { IEagerSessionOperations } from "./Operations/Lazy/IEagerSessionOperatio
1919
import { JavaScriptArray } from "./JavaScriptArray";
2020
import { IRevisionsSessionOperations } from "./IRevisionsSessionOperations";
2121
import * as stream from "readable-stream";
22-
import { DocumentResultStream } from "../Session/DocumentStreamIterable";
22+
import { DocumentResultStream } from "../Session/DocumentResultStream";
2323

2424
export type StreamQueryStatisticsCallback = (stats: StreamQueryStatistics) => void;
2525

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export {
129129
SetIndexesPriorityOperation,
130130
SetIndexesPriorityOperationParameters
131131
} from "./Documents/Operations/Indexes/SetIndexesPriorityOperation";
132+
export * from "./Documents/Operations/PatchRequest";
132133

133134
// INDEXES
134135
export { GetIndexOperation } from "./Documents/Operations/Indexes/GetIndexOperation";
@@ -188,6 +189,7 @@ export * from "./Documents/Session/RawDocumentQuery";
188189
export * from "./Documents/Session/SessionEvents";
189190
export * from "./Documents/Session/WhereParams";
190191
export * from "./Documents/Session/IMetadataDictionary";
192+
export * from "./Documents/Session/DocumentResultStream";
191193
export * from "./Documents/Commands/StreamResult";
192194

193195
// QUERIES

test/Documents/ReadmeSamples.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,31 @@ describe("Readme query samples", function () {
430430

431431
});
432432

433+
it("can use advanced.patch", async () => {
434+
store.conventions.findCollectionNameForObjectLiteral = () => "users";
435+
436+
{
437+
const session = store.openSession();
438+
await session.store({ name: "Matilda", age: 17, underAge: true }, "users/1");
439+
await session.saveChanges();
440+
}
441+
442+
{
443+
const session = store.openSession();
444+
session.advanced.increment("users/1", "age", 1);
445+
session.advanced.patch("users/1", "underAge", false);
446+
await session.saveChanges();
447+
}
448+
449+
{
450+
const session = store.openSession();
451+
const loaded: any = await session.load("users/1");
452+
assert.strictEqual(loaded.underAge, false);
453+
assert.strictEqual(loaded.age, 18);
454+
assert.strictEqual(loaded.name, "Matilda");
455+
}
456+
});
457+
433458
describe("with revisions set up", function() {
434459

435460
beforeEach(async () => testContext.setupRevisions(store, false, 5));

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)