Skip to content

Commit

Permalink
Merge pull request #309 from ml054/v5.2
Browse files Browse the repository at this point in the history
V5.2
  • Loading branch information
ml054 authored May 17, 2022
2 parents b8e6cf6 + 78a22ee commit b2b8e4b
Show file tree
Hide file tree
Showing 103 changed files with 2,928 additions and 558 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/RavenClient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x, 18.x]
serverVersion: ["5.2", "5.3"]
fail-fast: false

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

- name: Check imports
run: npm run check-imports
run: npm run check-imports
76 changes: 56 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@
"devDependencies": {
"@types/bluebird": "^3.5.36",
"@types/md5": "^2.3.2",
"@types/mocha": "^9.1.0",
"@types/mocha": "^9.1.1",
"@types/pluralize": "0.0.29",
"@types/rimraf": "^3.0.2",
"@types/sinon": "^10.0.11",
"@types/unzipper": "^0.10.5",
"@types/util.promisify": "^1.0.4",
"@types/ws": "^7.4.0",
"@types/ws": "^7.4.7",
"cross-os": "^1.3.0",
"glob": "^7.2.0",
"glob": "^7.2.3",
"http-proxy-agent": "^5.0.0",
"lodash.orderby": "^4.6.0",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"open": "^8.4.0",
"rimraf": "^3.0.2",
"sinon": "^13.0.1",
"sinon": "^13.0.2",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"tslint": "^6.1.3",
Expand All @@ -92,7 +92,7 @@
"change-case": "^3.1.0",
"deprecate": "^1.1.1",
"md5": "^2.3.0",
"moment": "^2.29.2",
"moment": "^2.29.3",
"node-fetch": "^2.6.7",
"object.entries": "^1.1.5",
"object.values": "^1.1.5",
Expand Down
24 changes: 20 additions & 4 deletions src/Documents/BulkInsertOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TimeSeriesOperations } from "./TimeSeries/TimeSeriesOperations";
import { TimeSeriesValuesHelper } from "./Session/TimeSeries/TimeSeriesValuesHelper";

export class BulkInsertOperation {
private _options: BulkInsertOptions;
private readonly _generateEntityIdOnTheClient: GenerateEntityIdOnTheClient;

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

private _concurrentCheck: number = 0;
private _isInitialWrite: boolean = true;

private _bulkInsertAborted: Promise<void>;
private _abortReject: Function;
Expand All @@ -53,12 +55,15 @@ export class BulkInsertOperation {
private _requestBodyStream: stream.PassThrough;
private _pipelineFinished: Promise<void>;

public constructor(database: string, store: IDocumentStore) {
public constructor(database: string, store: IDocumentStore, options?: BulkInsertOptions) {
this._conventions = store.conventions;
if (StringUtil.isNullOrEmpty(database)) {
this._throwNoDatabase();
}
this._requestExecutor = store.getRequestExecutor(database);
this._useCompression = options ? options.useCompression : false;

this._options = options ?? {};

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

Expand Down Expand Up @@ -310,7 +315,7 @@ export class BulkInsertOperation {

this._requestBodyStream = new stream.PassThrough();
const bulkCommand =
new BulkInsertCommand(this._operationId, this._requestBodyStream, this._nodeTag);
new BulkInsertCommand(this._operationId, this._requestBodyStream, this._nodeTag, this._options.skipOverwriteIfUnchanged);
bulkCommand.useCompression = this._useCompression;

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

private readonly _stream: stream.Readable;
private _skipOverwriteIfUnchanged: boolean;
private readonly _id: number;
public useCompression: boolean;

public constructor(id: number, stream: stream.Readable, nodeTag: string) {
public constructor(id: number, stream: stream.Readable, nodeTag: string, skipOverwriteIfUnchanged: boolean) {
super();

this._stream = stream;
this._id = id;
this._selectedNodeTag = nodeTag;
this._skipOverwriteIfUnchanged = skipOverwriteIfUnchanged;
}

public createRequest(node: ServerNode): HttpRequestParameters {
const uri = node.url + "/databases/" + node.database + "/bulk_insert?id=" + this._id;
const uri = node.url
+ "/databases/" + node.database
+ "/bulk_insert?id=" + this._id
+ "&skipOverwriteIfUnchanged=" + (this._skipOverwriteIfUnchanged ? "true" : "false");

const headers = this._headers().typeAppJson().build();
// TODO: useCompression ? new GzipCompressingEntity(_stream) : _stream);
return {
Expand All @@ -815,3 +826,8 @@ export class BulkInsertCommand extends RavenCommand<void> {
}

}

export interface BulkInsertOptions {
useCompression?: boolean;
skipOverwriteIfUnchanged?: boolean;
}
4 changes: 2 additions & 2 deletions src/Documents/Commands/Batches/ClusterWideBatchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export class ClusterWideBatchCommand extends SingleNodeBatchCommand implements I
let options = super._appendOptions();

if (TypeUtil.isNullOrUndefined(this._disableAtomicDocumentWrites)) {
return ;
return "";
}

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

return options;
}
}
}
5 changes: 3 additions & 2 deletions src/Documents/Commands/ConditionalGetDocumentsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DocumentConventions } from "../Conventions/DocumentConventions";
import { readToEnd, stringToReadable } from "../../Utility/StreamUtil";
import { RavenCommandResponsePipeline } from "../../Http/RavenCommandResponsePipeline";
import { ObjectUtil } from "../../Utility/ObjectUtil";
import { CONSTANTS, HEADERS } from "../../Constants";

export class ConditionalGetDocumentsCommand extends RavenCommand<ConditionalGetResult> {

Expand All @@ -31,7 +32,7 @@ export class ConditionalGetDocumentsCommand extends RavenCommand<ConditionalGetR
uri,
method: "GET",
headers: {
"If-None-Match": `"${this._changeVector}"`
[HEADERS.IF_NONE_MATCH]: `"${this._changeVector}"`
}
}
}
Expand Down Expand Up @@ -101,4 +102,4 @@ export class ConditionalGetDocumentsCommand extends RavenCommand<ConditionalGetR
export interface ConditionalGetResult {
results: any[];
changeVector: string;
}
}
18 changes: 18 additions & 0 deletions src/Documents/Commands/GetDocumentsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface GetDocumentsByIdsCommandOptions
includes?: string[];
metadataOnly?: boolean;
timeSeriesIncludes?: AbstractTimeSeriesRange[];
revisionsIncludesByChangeVector?: string[];
revisionIncludeByDateTimeBefore?: Date;
compareExchangeValueIncludes?: string[];
}

Expand All @@ -61,6 +63,7 @@ export interface GetDocumentsResult {
includes: IRavenObject;
results: any[];
counterIncludes: IRavenObject;
revisionIncludes: any[];
timeSeriesIncludes: IRavenObject;
compareExchangeValueIncludes: IRavenObject;
nextPageStart: number;
Expand All @@ -77,6 +80,8 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
private _includeAllCounters: boolean;

private _timeSeriesIncludes: AbstractTimeSeriesRange[];
private _revisionsIncludeByChangeVector: string[];
private _revisionsIncludeByDateTime: Date;
private _compareExchangeValueIncludes: string[];

private readonly _metadataOnly: boolean;
Expand Down Expand Up @@ -114,6 +119,8 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
this._metadataOnly = opts.metadataOnly;
this._timeSeriesIncludes = opts.timeSeriesIncludes;
this._compareExchangeValueIncludes = opts.compareExchangeValueIncludes;
this._revisionsIncludeByDateTime = opts.revisionIncludeByDateTimeBefore;
this._revisionsIncludeByChangeVector = opts.revisionsIncludesByChangeVector;
} else if (opts.hasOwnProperty("start") && opts.hasOwnProperty("pageSize")) {
opts = opts as GetDocumentsStartingWithOptions;
this._start = opts.start;
Expand Down Expand Up @@ -224,6 +231,16 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
}
}

if (this._revisionsIncludeByChangeVector) {
for (const changeVector of this._revisionsIncludeByChangeVector) {
query += "&revisions=" + this._urlEncode(changeVector);
}
}

if (this._revisionsIncludeByDateTime) {
query += "&revisionsBefore=" + DateUtil.utc.stringify(this._revisionsIncludeByDateTime);
}

if (this._compareExchangeValueIncludes) {
for (const compareExchangeValue of this._compareExchangeValueIncludes) {
query += "&cmpxchg=" + this._urlEncode(compareExchangeValue);
Expand Down Expand Up @@ -336,6 +353,7 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
compareExchangeValueIncludes: ObjectUtil.mapCompareExchangeToLocalObject(json.CompareExchangeValueIncludes),
timeSeriesIncludes: ObjectUtil.mapTimeSeriesIncludesToLocalObject(json.TimeSeriesIncludes),
counterIncludes: ObjectUtil.mapCounterIncludesToLocalObject(json.CounterIncludes),
revisionIncludes: json.RevisionIncludes,
nextPageStart: json.NextPageStart
};
}
Expand Down
12 changes: 12 additions & 0 deletions src/Documents/Commands/GetRevisionsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ export class GetRevisionsCommand extends RavenCommand<IRavenArrayResult> {
this._conventions = conventions;
}

public get id(): string {
return this._id;
}

public get before(): Date {
return this._before;
}

public get changeVector(): string {
return this._changeVector;
}

public get changeVectors() {
return this._changeVectors;
}
Expand Down
Loading

0 comments on commit b2b8e4b

Please sign in to comment.