@neo4j-labs/experimental-query-api-wrapper 0.0.1-alpha01
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +19 -0
- package/LICENSE +201 -0
- package/README.adoc +24 -0
- package/example/index.js +36 -0
- package/example/package.json +15 -0
- package/jest.config.ts +196 -0
- package/lib/http-connection/connection-provider.http.js +127 -0
- package/lib/http-connection/connection.http.js +214 -0
- package/lib/http-connection/index.js +24 -0
- package/lib/http-connection/query.codec.js +602 -0
- package/lib/http-connection/stream-observers.js +141 -0
- package/lib/index.js +279 -0
- package/lib/logging.js +20 -0
- package/lib/types.js +2 -0
- package/lib/wrapper-session.impl.js +21 -0
- package/lib/wrapper.impl.js +34 -0
- package/package.json +44 -0
- package/tsconfig.build.json +6 -0
- package/tsconfig.json +20 -0
- package/types/http-connection/connection-provider.http.d.ts +50 -0
- package/types/http-connection/connection.http.d.ts +45 -0
- package/types/http-connection/index.d.ts +18 -0
- package/types/http-connection/query.codec.d.ts +152 -0
- package/types/http-connection/stream-observers.d.ts +51 -0
- package/types/index.d.ts +247 -0
- package/types/logging.d.ts +14 -0
- package/types/types.d.ts +35 -0
- package/types/wrapper-session.impl.d.ts +27 -0
- package/types/wrapper.impl.d.ts +28 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [https://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
var __extends = (this && this.__extends) || (function () {
|
|
19
|
+
var extendStatics = function (d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
return function (d, b) {
|
|
26
|
+
if (typeof b !== "function" && b !== null)
|
|
27
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
28
|
+
extendStatics(d, b);
|
|
29
|
+
function __() { this.constructor = d; }
|
|
30
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
34
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
36
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
37
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
38
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
39
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
43
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
44
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
+
function step(op) {
|
|
47
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
49
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
+
switch (op[0]) {
|
|
52
|
+
case 0: case 1: t = op; break;
|
|
53
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
+
default:
|
|
57
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
+
if (t[2]) _.ops.pop();
|
|
62
|
+
_.trys.pop(); continue;
|
|
63
|
+
}
|
|
64
|
+
op = body.call(thisArg, _);
|
|
65
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
70
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
71
|
+
if (!m) return o;
|
|
72
|
+
var i = m.call(o), r, ar = [], e;
|
|
73
|
+
try {
|
|
74
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
75
|
+
}
|
|
76
|
+
catch (error) { e = { error: error }; }
|
|
77
|
+
finally {
|
|
78
|
+
try {
|
|
79
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
80
|
+
}
|
|
81
|
+
finally { if (e) throw e.error; }
|
|
82
|
+
}
|
|
83
|
+
return ar;
|
|
84
|
+
};
|
|
85
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
+
var neo4j_driver_core_1 = require("neo4j-driver-core");
|
|
87
|
+
var stream_observers_1 = require("./stream-observers");
|
|
88
|
+
var query_codec_1 = require("./query.codec");
|
|
89
|
+
var HttpConnection = /** @class */ (function (_super) {
|
|
90
|
+
__extends(HttpConnection, _super);
|
|
91
|
+
function HttpConnection(config) {
|
|
92
|
+
var _this = _super.call(this) || this;
|
|
93
|
+
_this._release = config.release;
|
|
94
|
+
_this._auth = config.auth;
|
|
95
|
+
_this._scheme = config.scheme;
|
|
96
|
+
_this._address = config.address;
|
|
97
|
+
_this._database = config.database;
|
|
98
|
+
_this._config = config.config;
|
|
99
|
+
return _this;
|
|
100
|
+
}
|
|
101
|
+
HttpConnection.prototype.run = function (query, parameters, config) {
|
|
102
|
+
var _this = this;
|
|
103
|
+
var _a, _b;
|
|
104
|
+
var observer = new stream_observers_1.ResultStreamObserver({
|
|
105
|
+
highRecordWatermark: (_a = config === null || config === void 0 ? void 0 : config.highRecordWatermark) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER,
|
|
106
|
+
lowRecordWatermark: (_b = config === null || config === void 0 ? void 0 : config.lowRecordWatermark) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER,
|
|
107
|
+
afterComplete: config === null || config === void 0 ? void 0 : config.afterComplete,
|
|
108
|
+
server: this._address
|
|
109
|
+
});
|
|
110
|
+
var requestCodec = new query_codec_1.QueryRequestCodec(this._auth, query, parameters, config);
|
|
111
|
+
this._abortController = new AbortController();
|
|
112
|
+
fetch(this._getTransactionApi(), {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
mode: 'cors',
|
|
115
|
+
headers: {
|
|
116
|
+
'Content-Type': requestCodec.contentType,
|
|
117
|
+
Accept: requestCodec.accept,
|
|
118
|
+
Authorization: requestCodec.authorization,
|
|
119
|
+
},
|
|
120
|
+
signal: this._abortController.signal,
|
|
121
|
+
body: JSON.stringify(requestCodec.body)
|
|
122
|
+
}).
|
|
123
|
+
then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
+
var _a;
|
|
125
|
+
return __generator(this, function (_b) {
|
|
126
|
+
switch (_b.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
_a = [res.headers.get('content-type')];
|
|
129
|
+
return [4 /*yield*/, res.json()];
|
|
130
|
+
case 1: return [2 /*return*/, _a.concat([(_b.sent())])];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}); })
|
|
134
|
+
.catch(function (error) { return observer.onError(error); })
|
|
135
|
+
.then(function (_a) {
|
|
136
|
+
var _b = __read(_a, 2), contentType = _b[0], rawQueryResponse = _b[1];
|
|
137
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
138
|
+
var batchSize, codec, stream, iterate, i, _c, done, rawRecord;
|
|
139
|
+
var _d;
|
|
140
|
+
return __generator(this, function (_e) {
|
|
141
|
+
switch (_e.label) {
|
|
142
|
+
case 0:
|
|
143
|
+
console.log(JSON.stringify(rawQueryResponse, undefined, 4));
|
|
144
|
+
if (rawQueryResponse == null) {
|
|
145
|
+
// is already dead
|
|
146
|
+
return [2 /*return*/];
|
|
147
|
+
}
|
|
148
|
+
batchSize = (_d = config === null || config === void 0 ? void 0 : config.fetchSize) !== null && _d !== void 0 ? _d : Number.MAX_SAFE_INTEGER;
|
|
149
|
+
codec = new query_codec_1.QueryResponseCodec(this._config, contentType, rawQueryResponse);
|
|
150
|
+
if (codec.hasError) {
|
|
151
|
+
throw codec.error;
|
|
152
|
+
}
|
|
153
|
+
observer.onKeys(codec.keys);
|
|
154
|
+
stream = codec.stream();
|
|
155
|
+
_e.label = 1;
|
|
156
|
+
case 1:
|
|
157
|
+
if (!!observer.completed) return [3 /*break*/, 4];
|
|
158
|
+
if (!observer.paused) return [3 /*break*/, 3];
|
|
159
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 20); })];
|
|
160
|
+
case 2:
|
|
161
|
+
_e.sent();
|
|
162
|
+
return [3 /*break*/, 1];
|
|
163
|
+
case 3:
|
|
164
|
+
iterate = true;
|
|
165
|
+
for (i = 0; iterate && !observer.paused && i < batchSize; i++) {
|
|
166
|
+
_c = stream.next(), done = _c.done, rawRecord = _c.value;
|
|
167
|
+
if (!done) {
|
|
168
|
+
observer.onNext(rawRecord);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
iterate = false;
|
|
172
|
+
observer.onCompleted(codec.meta);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return [3 /*break*/, 1];
|
|
176
|
+
case 4: return [2 /*return*/];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
})
|
|
181
|
+
.catch(function (error) { return observer.onError(error); })
|
|
182
|
+
.finally(function () {
|
|
183
|
+
_this._abortController = undefined;
|
|
184
|
+
});
|
|
185
|
+
return observer;
|
|
186
|
+
};
|
|
187
|
+
HttpConnection.prototype._getTransactionApi = function () {
|
|
188
|
+
var address = "".concat(this._scheme, "://").concat(this._address.asHostPort(), "/db/").concat(this._database === '' ? 'neo4j' : this._database, "/query/v2");
|
|
189
|
+
return address;
|
|
190
|
+
};
|
|
191
|
+
HttpConnection.prototype.getProtocolVersion = function () {
|
|
192
|
+
return 0;
|
|
193
|
+
};
|
|
194
|
+
HttpConnection.prototype.isOpen = function () {
|
|
195
|
+
return true;
|
|
196
|
+
};
|
|
197
|
+
HttpConnection.prototype.hasOngoingObservableRequests = function () {
|
|
198
|
+
return this._abortController != null;
|
|
199
|
+
};
|
|
200
|
+
HttpConnection.prototype.resetAndFlush = function () {
|
|
201
|
+
var _a;
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
return __generator(this, function (_b) {
|
|
204
|
+
(_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort((0, neo4j_driver_core_1.newError)('User aborted operation.'));
|
|
205
|
+
return [2 /*return*/];
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
HttpConnection.prototype.release = function () {
|
|
210
|
+
return this._release();
|
|
211
|
+
};
|
|
212
|
+
return HttpConnection;
|
|
213
|
+
}(neo4j_driver_core_1.Connection));
|
|
214
|
+
exports.default = HttpConnection;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [https://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.HttpConnectionProvider = void 0;
|
|
23
|
+
var connection_provider_http_1 = __importDefault(require("./connection-provider.http"));
|
|
24
|
+
exports.HttpConnectionProvider = connection_provider_http_1.default;
|