Skip to content

Commit bb9a337

Browse files
committed
Fix TypeError in res.host
Fixes #604.
1 parent 968a1a8 commit bb9a337

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Fixed view properties not being passed correctly when creating views ([#621](https://github.com/arangodb/arangojs/issues/621))
1313

14+
- Renamed internal `response.host` attribute to `response.arangojsHostId` ([#604](https://github.com/arangodb/arangojs/pull/604))
15+
16+
In some environments the `host` attribute is already present and read-only.
17+
This should avoid a `TypeError` being thrown when a value is assigned by
18+
arangojs.
19+
1420
## [6.11.0] - 2019-08-16
1521

1622
### Changed

src/collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export abstract class BaseCollection<T extends object = any>
435435
collection: this.name
436436
}
437437
},
438-
res => new ArrayCursor(this._connection, res.body, res.host)
438+
res => new ArrayCursor(this._connection, res.body, res.arangojsHostId)
439439
);
440440
}
441441

@@ -495,7 +495,7 @@ export abstract class BaseCollection<T extends object = any>
495495
collection: this.name
496496
}
497497
},
498-
res => new ArrayCursor(this._connection, res.body, res.host)
498+
res => new ArrayCursor(this._connection, res.body, res.arangojsHostId)
499499
);
500500
}
501501

@@ -767,7 +767,7 @@ export abstract class BaseCollection<T extends object = any>
767767
collection: this.name
768768
}
769769
},
770-
res => new ArrayCursor(this._connection, res.body, res.host)
770+
res => new ArrayCursor(this._connection, res.body, res.arangojsHostId)
771771
);
772772
}
773773
}

src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class Connection {
207207
}
208208
this._queue.push(task);
209209
} else {
210-
response.host = host;
210+
response.arangojsHostId = host;
211211
task.resolve(response);
212212
}
213213
}

src/database.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { AnalyzerDescription, ArangoAnalyzer } from "./analyzer";
22
import { AqlLiteral, AqlQuery, isAqlLiteral, isAqlQuery } from "./aql-query";
3-
import { ArangoCollection, constructCollection, DocumentCollection, EdgeCollection, isArangoCollection } from "./collection";
3+
import {
4+
ArangoCollection,
5+
constructCollection,
6+
DocumentCollection,
7+
EdgeCollection,
8+
isArangoCollection
9+
} from "./collection";
410
import { Config, Connection } from "./connection";
511
import { ArrayCursor } from "./cursor";
612
import { isArangoError } from "./error";
@@ -503,7 +509,12 @@ export class Database {
503509
timeout
504510
},
505511
res =>
506-
new ArrayCursor(this._connection, res.body, res.host, allowDirtyRead)
512+
new ArrayCursor(
513+
this._connection,
514+
res.body,
515+
res.arangojsHostId,
516+
allowDirtyRead
517+
)
507518
);
508519
}
509520

src/test/99-load-balancing.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,24 @@ describeIm("Single-server with follower", function() {
123123
it("supports dirty reads", async () => {
124124
expect((conn as any)._urls).to.have.lengthOf(2);
125125
const res1 = await getResponse(true);
126-
expect(res1.host).to.be.a("number");
126+
expect(res1.arangojsHostId).to.be.a("number");
127127
const headers1 = res1.request.getHeaders();
128128
expect(headers1).to.include.keys("x-arango-allow-dirty-read");
129129
const res2 = await getResponse(true);
130-
expect(res2.host).to.be.a("number");
131-
expect(res2.host).not.to.equal(res1.host);
130+
expect(res2.arangojsHostId).to.be.a("number");
131+
expect(res2.arangojsHostId).not.to.equal(res1.arangojsHostId);
132132
const headers2 = res2.request.getHeaders();
133133
expect(headers2).to.include.keys("x-arango-allow-dirty-read");
134134
});
135135
it("supports non-dirty reads", async () => {
136136
expect((conn as any)._urls).to.have.lengthOf(2);
137137
const res1 = await getResponse();
138-
expect(res1.host).to.be.a("number");
138+
expect(res1.arangojsHostId).to.be.a("number");
139139
const headers1 = res1.request.getHeaders();
140140
expect(headers1).not.to.include.keys("x-arango-allow-dirty-read");
141141
const res2 = await getResponse();
142-
expect(res2.host).to.be.a("number");
143-
expect(res2.host).to.equal(res1.host);
142+
expect(res2.arangojsHostId).to.be.a("number");
143+
expect(res2.arangojsHostId).to.equal(res1.arangojsHostId);
144144
const headers2 = res2.request.getHeaders();
145145
expect(headers2).not.to.include.keys("x-arango-allow-dirty-read");
146146
});

src/util/request.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Errback } from "./types";
1414
export type ArangojsResponse = IncomingMessage & {
1515
request: ClientRequest;
1616
body?: any;
17-
host?: number;
17+
arangojsHostId?: number;
1818
};
1919

2020
export type ArangojsError = Error & {

0 commit comments

Comments
 (0)