Skip to content

Commit 2dd834c

Browse files
authored
Merge pull request #164 from gregolsky/v4.0
sync up with jvm f50f79080d050a47ccc84e76d9bd2ab0e2a42b71
2 parents 2f57933 + ffd519e commit 2dd834c

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const CONSTANTS = {
2828
RAVEN_JS_TYPE: "Raven-Node-Type",
2929
CHANGE_VECTOR: "@change-vector",
3030
EXPIRES: "@expires",
31+
ALL_DOCUMENTS_COLLECTION: "@all_docs",
3132
EMPTY_COLLECTION: "@empty",
3233
NESTED_OBJECT_TYPES: "@nested-object-types",
3334
IGNORE_CASE_TRANSFORM_REGEX:

src/Documents/BulkInsertOperation.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { DocumentConventions } from "./Conventions/DocumentConventions";
2020
import { ServerNode } from "../Http/ServerNode";
2121
import { AbstractCallback } from "../Types/Callbacks";
2222
import { passResultToCallback } from "../Utility/PromiseUtil";
23+
import { BatchOperation } from "./Session/Operations/BatchOperation";
2324

2425
export class BulkInsertOperation {
2526
private readonly _generateEntityIdOnTheClient: GenerateEntityIdOnTheClient;
@@ -191,7 +192,23 @@ export class BulkInsertOperation {
191192
}
192193

193194
const jsonString = JsonSerializer.getDefault().serialize(json);
194-
this._currentWriter.push(`{"Id":"${id}","Type":"PUT","Document":${jsonString}}`);
195+
this._currentWriter.push(`{"Id":"${BulkInsertOperation._writeId(id)}","Type":"PUT","Document":${jsonString}}`);
196+
}
197+
198+
private static _writeId(input: string): string {
199+
let result = "";
200+
for (let i = 0; i < input.length; i++) {
201+
const c = input[i];
202+
if (`"` === c) {
203+
if (i === 0 || input[i - 1] !== `\\`) {
204+
result += `\\`;
205+
}
206+
}
207+
208+
result += c;
209+
}
210+
211+
return result;
195212
}
196213

197214
private async _checkIfBulkInsertWasAborted() {

src/Documents/Operations/Revisions/ConfigureRevisionsOperation.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ export class ConfigureRevisionsOperation implements IMaintenanceOperation<Config
1717
}
1818

1919
public getCommand(conventions: DocumentConventions): RavenCommand<ConfigureRevisionsOperationResult> {
20-
return new ConfigureRevisionsCommand(conventions, this._configuration);
20+
return new ConfigureRevisionsCommand(this._configuration);
2121
}
2222
}
2323

2424
export class ConfigureRevisionsCommand extends RavenCommand<ConfigureRevisionsOperationResult> {
25-
private readonly _conventions: DocumentConventions;
2625
private readonly _configuration: RevisionsConfiguration;
2726

28-
public constructor(conventions: DocumentConventions, configuration: RevisionsConfiguration) {
27+
public constructor(configuration: RevisionsConfiguration) {
2928
super();
30-
this._conventions = conventions;
3129
this._configuration = configuration;
3230
}
3331

src/Documents/Session/DocumentSession.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ export class DocumentSession extends InMemoryDocumentSessionOperations
400400
}
401401

402402
const patchRequest = new PatchRequest();
403-
patchRequest.script = "this." + path + " += args.val_" + this._valsCount + ";";
403+
const variable = `this.${path}`;
404+
const value = `args.val_${this._valsCount}`;
405+
patchRequest.script = `${variable} = ${variable} ? ${variable} + ${value} : ${value};`;
404406
const valKey = "val_" + this._valsCount;
405407
patchRequest.values = { [valKey]: valueToAdd };
406408

@@ -546,7 +548,8 @@ export class DocumentSession extends InMemoryDocumentSessionOperations
546548

547549
if (!isIndex && !isCollection) {
548550
const entityType = this.conventions.findEntityType(opts.documentType);
549-
collection = this.conventions.getCollectionNameForType(entityType);
551+
collection = this.conventions.getCollectionNameForType(entityType)
552+
|| CONSTANTS.Documents.Metadata.ALL_DOCUMENTS_COLLECTION;
550553
}
551554

552555
return { indexName, collection };

0 commit comments

Comments
 (0)