Skip to content

Commit b2b8e4b

Browse files
authored
Merge pull request #309 from ml054/v5.2
V5.2
2 parents b8e6cf6 + 78a22ee commit b2b8e4b

File tree

103 files changed

+2928
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2928
-558
lines changed

.github/workflows/RavenClient.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
strategy:
2626
matrix:
27-
node-version: [12.x, 14.x, 16.x]
27+
node-version: [12.x, 14.x, 16.x, 18.x]
2828
serverVersion: ["5.2", "5.3"]
2929
fail-fast: false
3030

@@ -71,4 +71,4 @@ jobs:
7171
run: node -e "require('./dist').DocumentStore"
7272

7373
- name: Check imports
74-
run: npm run check-imports
74+
run: npm run check-imports

package-lock.json

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

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@
5656
"devDependencies": {
5757
"@types/bluebird": "^3.5.36",
5858
"@types/md5": "^2.3.2",
59-
"@types/mocha": "^9.1.0",
59+
"@types/mocha": "^9.1.1",
6060
"@types/pluralize": "0.0.29",
6161
"@types/rimraf": "^3.0.2",
6262
"@types/sinon": "^10.0.11",
6363
"@types/unzipper": "^0.10.5",
6464
"@types/util.promisify": "^1.0.4",
65-
"@types/ws": "^7.4.0",
65+
"@types/ws": "^7.4.7",
6666
"cross-os": "^1.3.0",
67-
"glob": "^7.2.0",
67+
"glob": "^7.2.3",
6868
"http-proxy-agent": "^5.0.0",
6969
"lodash.orderby": "^4.6.0",
7070
"mocha": "^9.2.2",
7171
"nyc": "^15.1.0",
7272
"open": "^8.4.0",
7373
"rimraf": "^3.0.2",
74-
"sinon": "^13.0.1",
74+
"sinon": "^13.0.2",
7575
"source-map-support": "^0.5.21",
7676
"ts-node": "^10.7.0",
7777
"tslint": "^6.1.3",
@@ -92,7 +92,7 @@
9292
"change-case": "^3.1.0",
9393
"deprecate": "^1.1.1",
9494
"md5": "^2.3.0",
95-
"moment": "^2.29.2",
95+
"moment": "^2.29.3",
9696
"node-fetch": "^2.6.7",
9797
"object.entries": "^1.1.5",
9898
"object.values": "^1.1.5",

src/Documents/BulkInsertOperation.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { TimeSeriesOperations } from "./TimeSeries/TimeSeriesOperations";
2828
import { TimeSeriesValuesHelper } from "./Session/TimeSeries/TimeSeriesValuesHelper";
2929

3030
export class BulkInsertOperation {
31+
private _options: BulkInsertOptions;
3132
private readonly _generateEntityIdOnTheClient: GenerateEntityIdOnTheClient;
3233

3334
private readonly _requestExecutor: RequestExecutor;
@@ -45,6 +46,7 @@ export class BulkInsertOperation {
4546
private readonly _timeSeriesBatchSize: number;
4647

4748
private _concurrentCheck: number = 0;
49+
private _isInitialWrite: boolean = true;
4850

4951
private _bulkInsertAborted: Promise<void>;
5052
private _abortReject: Function;
@@ -53,12 +55,15 @@ export class BulkInsertOperation {
5355
private _requestBodyStream: stream.PassThrough;
5456
private _pipelineFinished: Promise<void>;
5557

56-
public constructor(database: string, store: IDocumentStore) {
58+
public constructor(database: string, store: IDocumentStore, options?: BulkInsertOptions) {
5759
this._conventions = store.conventions;
5860
if (StringUtil.isNullOrEmpty(database)) {
5961
this._throwNoDatabase();
6062
}
6163
this._requestExecutor = store.getRequestExecutor(database);
64+
this._useCompression = options ? options.useCompression : false;
65+
66+
this._options = options ?? {};
6267

6368
this._timeSeriesBatchSize = this._conventions.bulkInsert.timeSeriesBatchSize;
6469

@@ -310,7 +315,7 @@ export class BulkInsertOperation {
310315

311316
this._requestBodyStream = new stream.PassThrough();
312317
const bulkCommand =
313-
new BulkInsertCommand(this._operationId, this._requestBodyStream, this._nodeTag);
318+
new BulkInsertCommand(this._operationId, this._requestBodyStream, this._nodeTag, this._options.skipOverwriteIfUnchanged);
314319
bulkCommand.useCompression = this._useCompression;
315320

316321
const bulkCommandPromise = this._requestExecutor.execute(bulkCommand);
@@ -787,19 +792,25 @@ export class BulkInsertCommand extends RavenCommand<void> {
787792
}
788793

789794
private readonly _stream: stream.Readable;
795+
private _skipOverwriteIfUnchanged: boolean;
790796
private readonly _id: number;
791797
public useCompression: boolean;
792798

793-
public constructor(id: number, stream: stream.Readable, nodeTag: string) {
799+
public constructor(id: number, stream: stream.Readable, nodeTag: string, skipOverwriteIfUnchanged: boolean) {
794800
super();
795801

796802
this._stream = stream;
797803
this._id = id;
798804
this._selectedNodeTag = nodeTag;
805+
this._skipOverwriteIfUnchanged = skipOverwriteIfUnchanged;
799806
}
800807

801808
public createRequest(node: ServerNode): HttpRequestParameters {
802-
const uri = node.url + "/databases/" + node.database + "/bulk_insert?id=" + this._id;
809+
const uri = node.url
810+
+ "/databases/" + node.database
811+
+ "/bulk_insert?id=" + this._id
812+
+ "&skipOverwriteIfUnchanged=" + (this._skipOverwriteIfUnchanged ? "true" : "false");
813+
803814
const headers = this._headers().typeAppJson().build();
804815
// TODO: useCompression ? new GzipCompressingEntity(_stream) : _stream);
805816
return {
@@ -815,3 +826,8 @@ export class BulkInsertCommand extends RavenCommand<void> {
815826
}
816827

817828
}
829+
830+
export interface BulkInsertOptions {
831+
useCompression?: boolean;
832+
skipOverwriteIfUnchanged?: boolean;
833+
}

src/Documents/Commands/Batches/ClusterWideBatchCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export class ClusterWideBatchCommand extends SingleNodeBatchCommand implements I
2727
let options = super._appendOptions();
2828

2929
if (TypeUtil.isNullOrUndefined(this._disableAtomicDocumentWrites)) {
30-
return ;
30+
return "";
3131
}
3232

3333
options
3434
+= "&disableAtomicDocumentWrites=" + (this._disableAtomicDocumentWrites ? "true" : "false");
3535

3636
return options;
3737
}
38-
}
38+
}

src/Documents/Commands/ConditionalGetDocumentsCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DocumentConventions } from "../Conventions/DocumentConventions";
88
import { readToEnd, stringToReadable } from "../../Utility/StreamUtil";
99
import { RavenCommandResponsePipeline } from "../../Http/RavenCommandResponsePipeline";
1010
import { ObjectUtil } from "../../Utility/ObjectUtil";
11+
import { CONSTANTS, HEADERS } from "../../Constants";
1112

1213
export class ConditionalGetDocumentsCommand extends RavenCommand<ConditionalGetResult> {
1314

@@ -31,7 +32,7 @@ export class ConditionalGetDocumentsCommand extends RavenCommand<ConditionalGetR
3132
uri,
3233
method: "GET",
3334
headers: {
34-
"If-None-Match": `"${this._changeVector}"`
35+
[HEADERS.IF_NONE_MATCH]: `"${this._changeVector}"`
3536
}
3637
}
3738
}
@@ -101,4 +102,4 @@ export class ConditionalGetDocumentsCommand extends RavenCommand<ConditionalGetR
101102
export interface ConditionalGetResult {
102103
results: any[];
103104
changeVector: string;
104-
}
105+
}

src/Documents/Commands/GetDocumentsCommand.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface GetDocumentsByIdsCommandOptions
4343
includes?: string[];
4444
metadataOnly?: boolean;
4545
timeSeriesIncludes?: AbstractTimeSeriesRange[];
46+
revisionsIncludesByChangeVector?: string[];
47+
revisionIncludeByDateTimeBefore?: Date;
4648
compareExchangeValueIncludes?: string[];
4749
}
4850

@@ -61,6 +63,7 @@ export interface GetDocumentsResult {
6163
includes: IRavenObject;
6264
results: any[];
6365
counterIncludes: IRavenObject;
66+
revisionIncludes: any[];
6467
timeSeriesIncludes: IRavenObject;
6568
compareExchangeValueIncludes: IRavenObject;
6669
nextPageStart: number;
@@ -77,6 +80,8 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
7780
private _includeAllCounters: boolean;
7881

7982
private _timeSeriesIncludes: AbstractTimeSeriesRange[];
83+
private _revisionsIncludeByChangeVector: string[];
84+
private _revisionsIncludeByDateTime: Date;
8085
private _compareExchangeValueIncludes: string[];
8186

8287
private readonly _metadataOnly: boolean;
@@ -114,6 +119,8 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
114119
this._metadataOnly = opts.metadataOnly;
115120
this._timeSeriesIncludes = opts.timeSeriesIncludes;
116121
this._compareExchangeValueIncludes = opts.compareExchangeValueIncludes;
122+
this._revisionsIncludeByDateTime = opts.revisionIncludeByDateTimeBefore;
123+
this._revisionsIncludeByChangeVector = opts.revisionsIncludesByChangeVector;
117124
} else if (opts.hasOwnProperty("start") && opts.hasOwnProperty("pageSize")) {
118125
opts = opts as GetDocumentsStartingWithOptions;
119126
this._start = opts.start;
@@ -224,6 +231,16 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
224231
}
225232
}
226233

234+
if (this._revisionsIncludeByChangeVector) {
235+
for (const changeVector of this._revisionsIncludeByChangeVector) {
236+
query += "&revisions=" + this._urlEncode(changeVector);
237+
}
238+
}
239+
240+
if (this._revisionsIncludeByDateTime) {
241+
query += "&revisionsBefore=" + DateUtil.utc.stringify(this._revisionsIncludeByDateTime);
242+
}
243+
227244
if (this._compareExchangeValueIncludes) {
228245
for (const compareExchangeValue of this._compareExchangeValueIncludes) {
229246
query += "&cmpxchg=" + this._urlEncode(compareExchangeValue);
@@ -336,6 +353,7 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
336353
compareExchangeValueIncludes: ObjectUtil.mapCompareExchangeToLocalObject(json.CompareExchangeValueIncludes),
337354
timeSeriesIncludes: ObjectUtil.mapTimeSeriesIncludesToLocalObject(json.TimeSeriesIncludes),
338355
counterIncludes: ObjectUtil.mapCounterIncludesToLocalObject(json.CounterIncludes),
356+
revisionIncludes: json.RevisionIncludes,
339357
nextPageStart: json.NextPageStart
340358
};
341359
}

src/Documents/Commands/GetRevisionsCommand.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ export class GetRevisionsCommand extends RavenCommand<IRavenArrayResult> {
5959
this._conventions = conventions;
6060
}
6161

62+
public get id(): string {
63+
return this._id;
64+
}
65+
66+
public get before(): Date {
67+
return this._before;
68+
}
69+
70+
public get changeVector(): string {
71+
return this._changeVector;
72+
}
73+
6274
public get changeVectors() {
6375
return this._changeVectors;
6476
}

0 commit comments

Comments
 (0)