Skip to content

Commit f2794a8

Browse files
authored
Merge pull request #237 from ml054/v4.2
v4.2
2 parents a2c683d + c2bbc1c commit f2794a8

29 files changed

+701
-82
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Documents/Commands/Batches/SingleNodeBatchCommand.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ export class SingleNodeBatchCommand extends RavenCommand<BatchCommandResult> imp
148148
if (replicationOptions) {
149149
result += `&waitForReplicasTimeout=${TimeUtil.millisToTimeSpan(replicationOptions.timeout)}`;
150150

151-
if (replicationOptions.throwOnTimeout) {
152-
result += "&throwOnTimeoutInWaitForReplicas=true";
153-
}
151+
result += "&throwOnTimeoutInWaitForReplicas=" + (replicationOptions.throwOnTimeout ? "true" : "false");
154152

155153
result += "&numberOfReplicasToWaitFor=";
156154
result += replicationOptions.majority ? "majority" : replicationOptions.replicas;

src/Documents/DocumentStoreBase.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
BeforeConversionToEntityEventArgs,
1515
AfterConversionToEntityEventArgs,
1616
FailedRequestEventArgs,
17-
TopologyUpdatedEventArgs
17+
TopologyUpdatedEventArgs,
18+
BeforeRequestEventArgs,
19+
SucceedRequestEventArgs
1820
} from "./Session/SessionEvents";
1921
import { OperationExecutor } from "./Operations/OperationExecutor";
2022
import { IDocumentSession } from "./Session/IDocumentSession";
@@ -275,6 +277,14 @@ export abstract class DocumentStoreBase
275277
eventName: "afterConversionToEntity",
276278
eventHandler: (eventArgs: AfterConversionToEntityEventArgs) => void
277279
): this;
280+
public addSessionListener(
281+
eventName: "beforeRequest",
282+
eventHandler: (eventArgs: BeforeRequestEventArgs) => void
283+
): this;
284+
public addSessionListener(
285+
eventName: "succeedRequest",
286+
eventHandler: (eventArgs: SucceedRequestEventArgs) => void
287+
): this;
278288
public addSessionListener(eventName: any, eventHandler: (eventArgs: any) => void): this {
279289
this._eventHandlers.push([eventName, eventHandler]);
280290
return this;
@@ -308,6 +318,14 @@ export abstract class DocumentStoreBase
308318
eventName: "afterConversionToEntity",
309319
eventHandler: (eventArgs: AfterConversionToEntityEventArgs) => void
310320
): void;
321+
public removeSessionListener(
322+
eventName: "beforeRequest",
323+
eventHandler: (eventArgs: BeforeRequestEventArgs) => void
324+
): void;
325+
public removeSessionListener(
326+
eventName: "succeedRequest",
327+
eventHandler: (eventArgs: SucceedRequestEventArgs) => void
328+
): void;
311329
public removeSessionListener(eventName: any, eventHandler: (eventArgs: any) => void): void {
312330
const toRemove = this._eventHandlers
313331
.filter(x => x[0] === eventName && x[1] === eventHandler)[0];
@@ -320,7 +338,10 @@ export abstract class DocumentStoreBase
320338
public registerEvents(session: DocumentSession): void;
321339
public registerEvents(requestExecutorOrSession: RequestExecutor | DocumentSession): void {
322340
this._eventHandlers.forEach(([eventName, eventHandler]) => {
323-
if (eventName === "failedRequest" || eventName === "topologyUpdated") {
341+
if (eventName === "failedRequest"
342+
|| eventName === "topologyUpdated"
343+
|| eventName === "beforeRequest"
344+
|| eventName === "succeedRequest") {
324345
(requestExecutorOrSession as RequestExecutor).on(eventName as any, eventHandler);
325346
} else {
326347
(requestExecutorOrSession as DocumentSession).on(eventName, eventHandler);

src/Documents/Indexes/AbstractIndexCreationTask.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export abstract class AbstractIndexCreationTask extends AbstractGenericIndexCrea
2626
indexDefinitionBuilder.patternReferencesCollectionName = this.patternReferencesCollectionName;
2727
indexDefinitionBuilder.additionalSources = this.additionalSources;
2828
indexDefinitionBuilder.configuration = this.configuration;
29+
indexDefinitionBuilder.lockMode = this.lockMode;
30+
indexDefinitionBuilder.priority = this.priority;
2931

3032
return indexDefinitionBuilder.toIndexDefinition(this.conventions);
3133
}

src/Documents/Indexes/AbstractJavaScriptIndexCreationTask.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export class AbstractJavaScriptIndexCreationTask extends AbstractIndexCreationTa
77

88
protected constructor() {
99
super();
10-
this._definition.lockMode = "Unlock";
11-
this._definition.priority = "Normal";
1210
}
1311

1412
public get maps() {
@@ -83,12 +81,16 @@ export class AbstractJavaScriptIndexCreationTask extends AbstractIndexCreationTa
8381

8482
public createIndexDefinition(): IndexDefinition {
8583
this._definition.type = this.isMapReduce ? "JavaScriptMapReduce" : "JavaScriptMap";
84+
this._definition.name = this.getIndexName();
8685

8786
if (this.additionalSources) {
8887
this._definition.additionalSources = this.additionalSources;
8988
} else {
9089
this._definition.additionalSources = {};
9190
}
91+
this._definition.configuration = this.configuration;
92+
this._definition.lockMode = this.lockMode;
93+
this._definition.priority = this.priority;
9294

9395
return this._definition;
9496
}

src/Documents/Indexes/AbstractMultiMapIndexCreationTask.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class AbstractMultiMapIndexCreationTask extends AbstractIndexCreationTask
3434
indexDefinitionBuilder.patternReferencesCollectionName = this.patternReferencesCollectionName;
3535
indexDefinitionBuilder.additionalSources = this.additionalSources;
3636
indexDefinitionBuilder.configuration = this.configuration;
37+
indexDefinitionBuilder.lockMode = this.lockMode;
38+
indexDefinitionBuilder.priority = this.priority;
3739

3840
const indexDefinition = indexDefinitionBuilder.toIndexDefinition(this.conventions, false);
3941
indexDefinition.maps = new Set(this.maps);

src/Documents/Session/AbstractDocumentQuery.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,24 @@ export abstract class AbstractDocumentQuery<T extends object, TSelf extends Abst
418418
this._timeout = waitTimeout || AbstractDocumentQuery._getDefaultTimeout();
419419
}
420420

421+
protected _getLazyQueryOperation() {
422+
if (!this._queryOperation) {
423+
this._queryOperation = this._initializeQueryOperation();
424+
}
425+
426+
const clazz = this._conventions.getJsTypeByDocumentType(this._clazz);
427+
return new LazyQueryOperation<T>(
428+
this._theSession.conventions,
429+
this._queryOperation,
430+
this,
431+
clazz);
432+
}
433+
421434
protected _initializeQueryOperation(): QueryOperation {
435+
const beforeQueryEventArgs = new SessionBeforeQueryEventArgs(
436+
this._theSession, new DocumentQueryCustomization(this));
437+
this._theSession.emit("beforeQuery", beforeQueryEventArgs);
438+
422439
const indexQuery = this.getIndexQuery();
423440
return new QueryOperation(
424441
this._theSession,
@@ -1951,10 +1968,6 @@ export abstract class AbstractDocumentQuery<T extends object, TSelf extends Abst
19511968
return Promise.resolve();
19521969
}
19531970

1954-
const beforeQueryEventArgs = new SessionBeforeQueryEventArgs(
1955-
this._theSession, new DocumentQueryCustomization(this));
1956-
this._theSession.emit("beforeQuery", beforeQueryEventArgs);
1957-
19581971
this._queryOperation = this._initializeQueryOperation();
19591972
return this._executeActualQuery();
19601973
}
@@ -2103,16 +2116,8 @@ export abstract class AbstractDocumentQuery<T extends object, TSelf extends Abst
21032116
}
21042117

21052118
public lazily(): Lazy<T[]> {
2106-
if (!this._queryOperation) {
2107-
this._queryOperation = this._initializeQueryOperation();
2108-
}
2119+
const lazyQueryOperation = this._getLazyQueryOperation();
21092120

2110-
const clazz = this._conventions.getJsTypeByDocumentType(this._clazz);
2111-
const lazyQueryOperation = new LazyQueryOperation<T>(
2112-
this._theSession.conventions,
2113-
this._queryOperation,
2114-
this,
2115-
clazz);
21162121
return (this._theSession as DocumentSession)
21172122
.addLazyOperation(lazyQueryOperation);
21182123
}

src/Documents/Session/DocumentSessionRevisions.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { AdvancedSessionExtensionBase } from "./AdvancedSessionExtensionBase";
21
import {
32
IRevisionsSessionOperations,
43
SessionRevisionsMetadataOptions,
@@ -12,11 +11,9 @@ import { DocumentType } from "../DocumentAbstractions";
1211
import { ErrorFirstCallback } from "../../Types/Callbacks";
1312
import * as PromiseUtil from "../../Utility/PromiseUtil";
1413
import { RevisionsCollectionObject } from "../../Types";
15-
import { ForceRevisionStrategy } from "./ForceRevisionStrategy";
16-
import { throwError } from "../../Exceptions/index";
17-
import { StringUtil } from "../../Utility/StringUtil";
14+
import { DocumentSessionRevisionsBase } from "./DocumentSessionRevisionsBase";
1815

19-
export class DocumentSessionRevisions extends AdvancedSessionExtensionBase implements IRevisionsSessionOperations {
16+
export class DocumentSessionRevisions extends DocumentSessionRevisionsBase implements IRevisionsSessionOperations {
2017

2118
public constructor(session: InMemoryDocumentSessionOperations) {
2219
super(session);
@@ -173,42 +170,5 @@ export class DocumentSessionRevisions extends AdvancedSessionExtensionBase imple
173170
: operation.getRevision(documentType);
174171
}
175172

176-
forceRevisionCreationFor<T extends object>(entity: T)
177-
forceRevisionCreationFor<T extends object>(entity: T, strategy: ForceRevisionStrategy)
178-
forceRevisionCreationFor<T extends object>(id: string)
179-
forceRevisionCreationFor<T extends object>(id: string, strategy: ForceRevisionStrategy)
180-
forceRevisionCreationFor<T extends object>(entityOrId: T | string, strategy: ForceRevisionStrategy = "Before") {
181-
if (!entityOrId) {
182-
throwError("InvalidArgumentException", "Entity cannot be null");
183-
}
184-
185-
if (TypeUtil.isString(entityOrId)) {
186-
this._addIdToList(entityOrId, strategy);
187-
} else {
188-
const documentInfo = this._session.documentsByEntity.get(entityOrId);
189-
if (!documentInfo) {
190-
throwError("InvalidOperationException", "Cannot create a revision for the requested entity because it is Not tracked by the session");
191-
}
192-
193-
this._addIdToList(documentInfo.id, strategy);
194-
}
195-
}
196173

197-
private _addIdToList(id: string, requestedStrategy: ForceRevisionStrategy) {
198-
if (StringUtil.isNullOrEmpty(id)) {
199-
throwError("InvalidArgumentException", "Id cannot be null or empty");
200-
}
201-
202-
const existingStrategy = this._session.idsForCreatingForcedRevisions.get(id);
203-
const idAlreadyAdded = !!existingStrategy;
204-
if (idAlreadyAdded && existingStrategy !== requestedStrategy) {
205-
throwError("InvalidOperationException", "A request for creating a revision was already made for document "
206-
+ id + " in the current session but with a different force strategy. New strategy requested: " + requestedStrategy
207-
+ ". Previous strategy: " + existingStrategy + ".");
208-
}
209-
210-
if (!idAlreadyAdded) {
211-
this._session.idsForCreatingForcedRevisions.set(id, requestedStrategy);
212-
}
213-
}
214174
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {ForceRevisionStrategy} from "./ForceRevisionStrategy";
2+
import {throwError} from "../../Exceptions";
3+
import {TypeUtil} from "../../Utility/TypeUtil";
4+
import {StringUtil} from "../../Utility/StringUtil";
5+
import {AdvancedSessionExtensionBase} from "./AdvancedSessionExtensionBase";
6+
7+
export class DocumentSessionRevisionsBase extends AdvancedSessionExtensionBase {
8+
forceRevisionCreationFor<T extends object>(entity: T)
9+
forceRevisionCreationFor<T extends object>(entity: T, strategy: ForceRevisionStrategy)
10+
forceRevisionCreationFor<T extends object>(id: string)
11+
forceRevisionCreationFor<T extends object>(id: string, strategy: ForceRevisionStrategy)
12+
forceRevisionCreationFor<T extends object>(entityOrId: T | string, strategy: ForceRevisionStrategy = "Before") {
13+
if (!entityOrId) {
14+
throwError("InvalidArgumentException", "Entity cannot be null");
15+
}
16+
17+
if (TypeUtil.isString(entityOrId)) {
18+
this._addIdToList(entityOrId, strategy);
19+
} else {
20+
const documentInfo = this._session.documentsByEntity.get(entityOrId);
21+
if (!documentInfo) {
22+
throwError("InvalidOperationException", "Cannot create a revision for the requested entity because it is Not tracked by the session");
23+
}
24+
25+
this._addIdToList(documentInfo.id, strategy);
26+
}
27+
}
28+
29+
private _addIdToList(id: string, requestedStrategy: ForceRevisionStrategy) {
30+
if (StringUtil.isNullOrEmpty(id)) {
31+
throwError("InvalidArgumentException", "Id cannot be null or empty");
32+
}
33+
34+
const existingStrategy = this._session.idsForCreatingForcedRevisions.get(id);
35+
const idAlreadyAdded = !!existingStrategy;
36+
if (idAlreadyAdded && existingStrategy !== requestedStrategy) {
37+
throwError("InvalidOperationException", "A request for creating a revision was already made for document "
38+
+ id + " in the current session but with a different force strategy. New strategy requested: " + requestedStrategy
39+
+ ". Previous strategy: " + existingStrategy + ".");
40+
}
41+
42+
if (!idAlreadyAdded) {
43+
this._session.idsForCreatingForcedRevisions.set(id, requestedStrategy);
44+
}
45+
}
46+
}

src/Documents/Session/InMemoryDocumentSessionOperations.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,18 @@ export abstract class InMemoryDocumentSessionOperations
661661
}
662662
}
663663

664-
public registerMissing(id: string): void {
664+
public registerMissing(idOrIds: string | string[]): void {
665665
if (this.noTracking) {
666666
return;
667667
}
668668

669-
this._knownMissingIds.add(id);
669+
if (TypeUtil.isArray(idOrIds)) {
670+
for (const id of idOrIds) {
671+
this._knownMissingIds.add(id);
672+
}
673+
} else {
674+
this._knownMissingIds.add(idOrIds);
675+
}
670676
}
671677

672678
public unregisterMissing(id: string) {
@@ -1541,6 +1547,12 @@ export abstract class InMemoryDocumentSessionOperations
15411547
documentInfo.document = document;
15421548

15431549
Object.assign(entity, documentInfo.entity);
1550+
1551+
const documentInfoById = this.documentsById.getValue(documentInfo.id);
1552+
1553+
if (documentInfoById) {
1554+
documentInfoById.entity = entity;
1555+
}
15441556
}
15451557

15461558
/**

0 commit comments

Comments
 (0)