Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/http-connection/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import { types } from "neo4j-driver-core"
import { BeginTransactionConfig } from "neo4j-driver-core/types/connection"


export const NEO4J_QUERY_CONTENT_TYPE = 'application/vnd.neo4j.query'
export const NEO4J_QUERY_JSONL_CONTENT_TYPE = 'application/vnd.neo4j.query.v1.0+jsonl';

export function encodeAuthToken(auth: types.AuthToken): string {
switch (auth.scheme) {
Expand Down
10 changes: 3 additions & 7 deletions src/http-connection/connection.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@ export default class HttpConnection extends Connection {

this._log?.debug(`${this} REQUEST: ${JSON.stringify(request)}`)

const res = await fetch(request.url, request)
const { body: rawQueryResponse, headers: [contentType] } = await readBodyAndReaders<RawQueryResponse>(request.url, res, 'content-type')

this._log?.debug(`${this} RESPONSE: { body: ${JSON.stringify(rawQueryResponse)}, headers: { content-type: ${contentType} }}`);

const res = await fetch(request.url, request)
const batchSize = config?.fetchSize ?? Number.MAX_SAFE_INTEGER
const codec = QueryResponseCodec.of(this._config, contentType ?? '', rawQueryResponse);
const codec = await QueryResponseCodec.ofResponse(this._config, request.url, res);

if (codec.error) {
throw codec.error
Expand All @@ -121,7 +117,7 @@ export default class HttpConnection extends Connection {
}

for (let i = 0; !observer.paused && i < batchSize && !observer.completed; i++) {
const { done, value: rawRecord } = stream.next()
const { done, value: rawRecord } = await stream.next()
if (!done) {
observer.onNext(rawRecord)
} else {
Expand Down
31 changes: 31 additions & 0 deletions src/http-connection/lang/line-splitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { TransformStreamDefaultController, Transformer } from "stream/web";

export default class LineSplitter implements Transformer<string, string> {
transform(chunk: string, controller: TransformStreamDefaultController<string>): void {
try {
const splitted = chunk.split('\n')
for (let i = 0; i < splitted.length - 1; i++) {
controller.enqueue(splitted[i])
}
} catch(e) {
controller.error(e)
}
}
}
Loading