@typedb/driver-http 3.12.2 → 3.13.6
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/dist/index.cjs +23 -12
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +18 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9,10 +9,11 @@ function remoteOrigin(params) {
|
|
|
9
9
|
if (isBasicParams(params)) return `${params.addresses[0]}`;
|
|
10
10
|
else return `${params.translatedAddresses[0].external}`;
|
|
11
11
|
}
|
|
12
|
+
var SCHEME_PREFIX_REGEX = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
12
13
|
function hostPortFromOrigin(origin) {
|
|
14
|
+
if (!SCHEME_PREFIX_REGEX.test(origin)) return origin;
|
|
13
15
|
try {
|
|
14
|
-
|
|
15
|
-
return url.host;
|
|
16
|
+
return new URL(origin).host;
|
|
16
17
|
} catch (e) {
|
|
17
18
|
return origin;
|
|
18
19
|
}
|
|
@@ -23,14 +24,23 @@ function resolveOrigin(params, primaryAddress) {
|
|
|
23
24
|
for (const addr of params.addresses) {
|
|
24
25
|
if (hostPortFromOrigin(addr) === target) return addr;
|
|
25
26
|
}
|
|
27
|
+
return originWithScheme(primaryAddress, params.addresses[0]);
|
|
26
28
|
} else {
|
|
27
29
|
for (const ta of params.translatedAddresses) {
|
|
28
30
|
if (hostPortFromOrigin(ta.internal) === target || hostPortFromOrigin(ta.external) === target) {
|
|
29
31
|
return ta.external;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
return originWithScheme(primaryAddress, params.translatedAddresses[0].external);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function originWithScheme(address, referenceOrigin) {
|
|
38
|
+
if (SCHEME_PREFIX_REGEX.test(address)) return address;
|
|
39
|
+
try {
|
|
40
|
+
return `${new URL(referenceOrigin).protocol}//${address}`;
|
|
41
|
+
} catch (e2) {
|
|
42
|
+
return `https://${address}`;
|
|
32
43
|
}
|
|
33
|
-
return primaryAddress;
|
|
34
44
|
}
|
|
35
45
|
function allOrigins(params) {
|
|
36
46
|
if (isBasicParams(params)) return params.addresses;
|
|
@@ -190,6 +200,7 @@ var TypeDBHttpDriver = class {
|
|
|
190
200
|
return result;
|
|
191
201
|
}
|
|
192
202
|
async apiReqOnce(method, path, body, options) {
|
|
203
|
+
const triedOrigins = /* @__PURE__ */ new Set([this.currentOrigin]);
|
|
193
204
|
const initial = await this.tryApiReq(method, path, body, options);
|
|
194
205
|
if (isApiErrResp(initial)) return initial;
|
|
195
206
|
let result = initial;
|
|
@@ -200,7 +211,8 @@ var TypeDBHttpDriver = class {
|
|
|
200
211
|
}
|
|
201
212
|
if (result === null || !result.ok) {
|
|
202
213
|
const startOrigin = this.currentOrigin;
|
|
203
|
-
|
|
214
|
+
triedOrigins.add(startOrigin);
|
|
215
|
+
const fallback = await this.tryFallbackOrigins(method, path, body, options, triedOrigins);
|
|
204
216
|
if (isApiErrResp(fallback)) return fallback;
|
|
205
217
|
if (fallback !== null && (result === null || fallback.ok)) {
|
|
206
218
|
result = fallback;
|
|
@@ -219,7 +231,7 @@ var TypeDBHttpDriver = class {
|
|
|
219
231
|
let resp;
|
|
220
232
|
try {
|
|
221
233
|
resp = await fetch(url, { method, body: bodyString, headers });
|
|
222
|
-
} catch (
|
|
234
|
+
} catch (e3) {
|
|
223
235
|
return null;
|
|
224
236
|
}
|
|
225
237
|
if (resp.status === HTTP_UNAUTHORIZED) {
|
|
@@ -228,7 +240,7 @@ var TypeDBHttpDriver = class {
|
|
|
228
240
|
headers = this.authHeaders(tokenResp.ok.token, options);
|
|
229
241
|
try {
|
|
230
242
|
resp = await fetch(url, { method, body: bodyString, headers });
|
|
231
|
-
} catch (
|
|
243
|
+
} catch (e4) {
|
|
232
244
|
return null;
|
|
233
245
|
}
|
|
234
246
|
}
|
|
@@ -244,7 +256,7 @@ var TypeDBHttpDriver = class {
|
|
|
244
256
|
let json;
|
|
245
257
|
try {
|
|
246
258
|
json = await resp.json();
|
|
247
|
-
} catch (
|
|
259
|
+
} catch (e5) {
|
|
248
260
|
return false;
|
|
249
261
|
}
|
|
250
262
|
if (!isMisdirectedError(json)) return false;
|
|
@@ -253,12 +265,11 @@ var TypeDBHttpDriver = class {
|
|
|
253
265
|
this.switchOrigin(newOrigin);
|
|
254
266
|
return true;
|
|
255
267
|
}
|
|
256
|
-
async tryFallbackOrigins(method, path, body, options) {
|
|
268
|
+
async tryFallbackOrigins(method, path, body, options, triedOrigins) {
|
|
257
269
|
const origins = allOrigins(this.params);
|
|
258
|
-
const failedOrigin = this.currentOrigin;
|
|
259
270
|
let lastError = null;
|
|
260
271
|
for (const origin of origins) {
|
|
261
|
-
if (origin
|
|
272
|
+
if (triedOrigins.has(origin)) continue;
|
|
262
273
|
this.switchOrigin(origin);
|
|
263
274
|
const initial = await this.tryApiReq(method, path, body, options);
|
|
264
275
|
if (initial === null) continue;
|
|
@@ -297,7 +308,7 @@ var TypeDBHttpDriver = class {
|
|
|
297
308
|
let resp;
|
|
298
309
|
try {
|
|
299
310
|
resp = await fetch(url, { method: "POST", body: JSON.stringify(body), headers: { "Content-Type": "application/json" } });
|
|
300
|
-
} catch (
|
|
311
|
+
} catch (e6) {
|
|
301
312
|
return driverError("HDR2", `Cannot connect to server at ${this.currentOrigin}`);
|
|
302
313
|
}
|
|
303
314
|
const json = await this.jsonOrNull(resp);
|
|
@@ -311,7 +322,7 @@ var TypeDBHttpDriver = class {
|
|
|
311
322
|
async jsonOrNull(resp) {
|
|
312
323
|
try {
|
|
313
324
|
return await resp.json();
|
|
314
|
-
} catch (
|
|
325
|
+
} catch (e7) {
|
|
315
326
|
return null;
|
|
316
327
|
}
|
|
317
328
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,9 +16,7 @@ type DriverParams = DriverParamsBasic | DriverParamsTranslated;
|
|
|
16
16
|
declare function isBasicParams(params: DriverParams): params is DriverParamsBasic;
|
|
17
17
|
declare function isTranslatedParams(params: DriverParams): params is DriverParamsTranslated;
|
|
18
18
|
declare function remoteOrigin(params: DriverParams): string;
|
|
19
|
-
/** Extract host:port from a URL string. "https://127.0.0.1:18000" → "127.0.0.1:18000" */
|
|
20
19
|
declare function hostPortFromOrigin(origin: string): string;
|
|
21
|
-
/** Resolve an advertised primaryAddress (a full origin) to the matching configured address, else itself. */
|
|
22
20
|
declare function resolveOrigin(params: DriverParams, primaryAddress: string): string;
|
|
23
21
|
/** Return all configured origins for connection error fallback. */
|
|
24
22
|
declare function allOrigins(params: DriverParams): string[];
|
|
@@ -125,7 +123,7 @@ type ConjunctionIndex$1 = number;
|
|
|
125
123
|
type VariableInfo = {
|
|
126
124
|
name: string | null;
|
|
127
125
|
};
|
|
128
|
-
type ConstraintAny = ConstraintIsa | ConstraintIsaExact | ConstraintHas | ConstraintLinks | ConstraintSub | ConstraintSubExact | ConstraintOwns | ConstraintRelates | ConstraintPlays | ConstraintExpression | ConstraintFunction | ConstraintComparison | ConstraintIs | ConstraintIid | ConstraintKind | ConstraintValue | ConstraintLabel | ConstraintOr | ConstraintNot | ConstraintTry;
|
|
126
|
+
type ConstraintAny = ConstraintIsa | ConstraintIsaExact | ConstraintHas | ConstraintLinks | ConstraintSub | ConstraintSubExact | ConstraintOwns | ConstraintRelates | ConstraintPlays | ConstraintExpression | ConstraintFunction | ConstraintComparison | ConstraintIs | ConstraintIid | ConstraintDeleteConcepts | ConstraintKind | ConstraintValue | ConstraintLabel | ConstraintOr | ConstraintNot | ConstraintTry;
|
|
129
127
|
type ConstraintSpan = {
|
|
130
128
|
begin: number;
|
|
131
129
|
end: number;
|
|
@@ -218,6 +216,11 @@ interface ConstraintIid {
|
|
|
218
216
|
concept: ConstraintVertexVariable;
|
|
219
217
|
iid: string;
|
|
220
218
|
}
|
|
219
|
+
interface ConstraintDeleteConcepts {
|
|
220
|
+
tag: "deleteConcepts";
|
|
221
|
+
textSpan: ConstraintSpan;
|
|
222
|
+
variables: ConstraintVertexVariable[];
|
|
223
|
+
}
|
|
221
224
|
interface ConstraintLabel {
|
|
222
225
|
tag: "label";
|
|
223
226
|
textSpan: ConstraintSpan;
|
|
@@ -535,4 +538,4 @@ type GivenRows = {
|
|
|
535
538
|
[varName: string]: GivenRowEntry;
|
|
536
539
|
}[];
|
|
537
540
|
|
|
538
|
-
export { type AnalyzeOptions, type AnalyzeResponse, type AnalyzedConjunction, type AnalyzedFetch, type AnalyzedFunction, type AnalyzedPipeline, type Answer, type AnswerType, type ApiError, type ApiErrorResponse, type ApiOkResponse, type ApiResponse, type Attribute, type AttributeType, type Concept, type ConceptDocument, type ConceptDocumentsQueryResponse, type ConceptRow, type ConceptRowAnswer, type ConceptRowsQueryResponse, type ConceptRowsQueryResponseLegacy, type ConjunctionAnnotations, type ConstraintAny, type ConstraintComparison, type ConstraintExpression, type ConstraintExpressionLegacy, type ConstraintFunction, type ConstraintHas, type ConstraintIid, type ConstraintIs, type ConstraintIsa, type ConstraintIsaExact, type ConstraintKind, type ConstraintLabel, type ConstraintLinks, type ConstraintLinksLegacy, type ConstraintNot, type ConstraintOr, type ConstraintOwns, type ConstraintPlays, type ConstraintRelates, type ConstraintSpan, type ConstraintSub, type ConstraintSubExact, type ConstraintTry, type ConstraintValue, type ConstraintVertexAny, type ConstraintVertexLabel, type ConstraintVertexNamedRole, type ConstraintVertexValue, type ConstraintVertexVariable, type Database, type DatabasesListResponse, type Distribution, type DriverParams, type DriverParamsBasic, type DriverParamsTranslated, type EdgeKind, type Entity, type EntityType, type FetchAnnotationFieldEntry, type FunctionReturnStructure, type FunctionSingleReturnSelector, type Given, type GivenRowEntry, type GivenRows, type InstantiableType, type MisdirectedError, type OkQueryResponse, type PipelineStage, type QueryConjunctionLegacy, type QueryOptions, type QueryResponse, type QueryResponseBase, type QueryStructureLegacy, type QueryType, type Reducer, type Relation, type RelationType, type ReplicationRole, type ReplicationStatus, type RoleType, type Server, type ServersListResponse, type SignInResponse, type ThingKind, type TransactionOpenResponse, type TransactionOptions, type TransactionType, type TranslatedAddress, type Type, TypeDBHttpDriver, type TypeKind, type User, type UsersListResponse, type Value, type ValueKind, type ValueType, type VariableAnnotations, type VariableId, type VariableInfo, type VersionResponse, allOrigins, driverError, getVariableName, hostPortFromOrigin, isApiError, isApiErrorResponse, isBasicParams, isMisdirectedError, isOkResponse, isQueryResponseLegacy, isTranslatedParams, remoteOrigin, resolveOrigin };
|
|
541
|
+
export { type AnalyzeOptions, type AnalyzeResponse, type AnalyzedConjunction, type AnalyzedFetch, type AnalyzedFunction, type AnalyzedPipeline, type Answer, type AnswerType, type ApiError, type ApiErrorResponse, type ApiOkResponse, type ApiResponse, type Attribute, type AttributeType, type Concept, type ConceptDocument, type ConceptDocumentsQueryResponse, type ConceptRow, type ConceptRowAnswer, type ConceptRowsQueryResponse, type ConceptRowsQueryResponseLegacy, type ConjunctionAnnotations, type ConstraintAny, type ConstraintComparison, type ConstraintDeleteConcepts, type ConstraintExpression, type ConstraintExpressionLegacy, type ConstraintFunction, type ConstraintHas, type ConstraintIid, type ConstraintIs, type ConstraintIsa, type ConstraintIsaExact, type ConstraintKind, type ConstraintLabel, type ConstraintLinks, type ConstraintLinksLegacy, type ConstraintNot, type ConstraintOr, type ConstraintOwns, type ConstraintPlays, type ConstraintRelates, type ConstraintSpan, type ConstraintSub, type ConstraintSubExact, type ConstraintTry, type ConstraintValue, type ConstraintVertexAny, type ConstraintVertexLabel, type ConstraintVertexNamedRole, type ConstraintVertexValue, type ConstraintVertexVariable, type Database, type DatabasesListResponse, type Distribution, type DriverParams, type DriverParamsBasic, type DriverParamsTranslated, type EdgeKind, type Entity, type EntityType, type FetchAnnotationFieldEntry, type FunctionReturnStructure, type FunctionSingleReturnSelector, type Given, type GivenRowEntry, type GivenRows, type InstantiableType, type MisdirectedError, type OkQueryResponse, type PipelineStage, type QueryConjunctionLegacy, type QueryOptions, type QueryResponse, type QueryResponseBase, type QueryStructureLegacy, type QueryType, type Reducer, type Relation, type RelationType, type ReplicationRole, type ReplicationStatus, type RoleType, type Server, type ServersListResponse, type SignInResponse, type ThingKind, type TransactionOpenResponse, type TransactionOptions, type TransactionType, type TranslatedAddress, type Type, TypeDBHttpDriver, type TypeKind, type User, type UsersListResponse, type Value, type ValueKind, type ValueType, type VariableAnnotations, type VariableId, type VariableInfo, type VersionResponse, allOrigins, driverError, getVariableName, hostPortFromOrigin, isApiError, isApiErrorResponse, isBasicParams, isMisdirectedError, isOkResponse, isQueryResponseLegacy, isTranslatedParams, remoteOrigin, resolveOrigin };
|
package/dist/index.mjs
CHANGED
|
@@ -9,10 +9,11 @@ function remoteOrigin(params) {
|
|
|
9
9
|
if (isBasicParams(params)) return `${params.addresses[0]}`;
|
|
10
10
|
else return `${params.translatedAddresses[0].external}`;
|
|
11
11
|
}
|
|
12
|
+
var SCHEME_PREFIX_REGEX = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
12
13
|
function hostPortFromOrigin(origin) {
|
|
14
|
+
if (!SCHEME_PREFIX_REGEX.test(origin)) return origin;
|
|
13
15
|
try {
|
|
14
|
-
|
|
15
|
-
return url.host;
|
|
16
|
+
return new URL(origin).host;
|
|
16
17
|
} catch {
|
|
17
18
|
return origin;
|
|
18
19
|
}
|
|
@@ -23,14 +24,23 @@ function resolveOrigin(params, primaryAddress) {
|
|
|
23
24
|
for (const addr of params.addresses) {
|
|
24
25
|
if (hostPortFromOrigin(addr) === target) return addr;
|
|
25
26
|
}
|
|
27
|
+
return originWithScheme(primaryAddress, params.addresses[0]);
|
|
26
28
|
} else {
|
|
27
29
|
for (const ta of params.translatedAddresses) {
|
|
28
30
|
if (hostPortFromOrigin(ta.internal) === target || hostPortFromOrigin(ta.external) === target) {
|
|
29
31
|
return ta.external;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
34
|
+
return originWithScheme(primaryAddress, params.translatedAddresses[0].external);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function originWithScheme(address, referenceOrigin) {
|
|
38
|
+
if (SCHEME_PREFIX_REGEX.test(address)) return address;
|
|
39
|
+
try {
|
|
40
|
+
return `${new URL(referenceOrigin).protocol}//${address}`;
|
|
41
|
+
} catch {
|
|
42
|
+
return `https://${address}`;
|
|
32
43
|
}
|
|
33
|
-
return primaryAddress;
|
|
34
44
|
}
|
|
35
45
|
function allOrigins(params) {
|
|
36
46
|
if (isBasicParams(params)) return params.addresses;
|
|
@@ -190,6 +200,7 @@ var TypeDBHttpDriver = class {
|
|
|
190
200
|
return result;
|
|
191
201
|
}
|
|
192
202
|
async apiReqOnce(method, path, body, options) {
|
|
203
|
+
const triedOrigins = /* @__PURE__ */ new Set([this.currentOrigin]);
|
|
193
204
|
const initial = await this.tryApiReq(method, path, body, options);
|
|
194
205
|
if (isApiErrResp(initial)) return initial;
|
|
195
206
|
let result = initial;
|
|
@@ -200,7 +211,8 @@ var TypeDBHttpDriver = class {
|
|
|
200
211
|
}
|
|
201
212
|
if (result === null || !result.ok) {
|
|
202
213
|
const startOrigin = this.currentOrigin;
|
|
203
|
-
|
|
214
|
+
triedOrigins.add(startOrigin);
|
|
215
|
+
const fallback = await this.tryFallbackOrigins(method, path, body, options, triedOrigins);
|
|
204
216
|
if (isApiErrResp(fallback)) return fallback;
|
|
205
217
|
if (fallback !== null && (result === null || fallback.ok)) {
|
|
206
218
|
result = fallback;
|
|
@@ -253,12 +265,11 @@ var TypeDBHttpDriver = class {
|
|
|
253
265
|
this.switchOrigin(newOrigin);
|
|
254
266
|
return true;
|
|
255
267
|
}
|
|
256
|
-
async tryFallbackOrigins(method, path, body, options) {
|
|
268
|
+
async tryFallbackOrigins(method, path, body, options, triedOrigins) {
|
|
257
269
|
const origins = allOrigins(this.params);
|
|
258
|
-
const failedOrigin = this.currentOrigin;
|
|
259
270
|
let lastError = null;
|
|
260
271
|
for (const origin of origins) {
|
|
261
|
-
if (origin
|
|
272
|
+
if (triedOrigins.has(origin)) continue;
|
|
262
273
|
this.switchOrigin(origin);
|
|
263
274
|
const initial = await this.tryApiReq(method, path, body, options);
|
|
264
275
|
if (initial === null) continue;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@typedb/driver-http", "version": "3.
|
|
1
|
+
{"name": "@typedb/driver-http", "version": "3.13.6", "description": "TypeDB HTTP Driver", "author": "TypeDB Community <community@typedb.com>", "license": "Apache-2.0", "homepage": "https://typedb.com", "repository": {"type": "git", "url": "https://github.com/typedb/typedb-driver"}, "bugs": {"url": "https://github.com/typedb/typedb-driver/issues"}, "keywords": ["database", "typedb"], "main": "dist/index.cjs", "module": "dist/index.mjs", "types": "dist/index.d.ts", "type": "module", "exports": {".": {"types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs"}}, "scripts": {"build:dev": "tsc", "build": "tsup", "test": "cucumber-js", "docs": "typedoc"}, "packageManager": "pnpm@8.15.9", "packageConfig": {"access": "public"}, "devDependencies": {"@cucumber/cucumber": "9.0.0", "@types/node": "24.0.12", "tsup": "8.5.0", "typedoc": "^0.28.7", "typescript": "5.8.3"}}
|