Comparing version 1.6.0-canary.20240501T133708 to 1.6.0-canary.20240501T145919
@@ -1,3 +0,3 @@ | ||
import { Client, ConnectOptions } from "./baseClient"; | ||
import { Client, type ConnectOptions } from "./baseClient"; | ||
export declare function createClient(): Client; | ||
export declare function createHttpClient(options?: string | ConnectOptions | null): Client; |
@@ -19,29 +19,20 @@ /*! | ||
import { BaseRawConnection } from "./baseConn"; | ||
import { ICodec } from "./codecs/ifaces"; | ||
import { CodecsRegistry } from "./codecs/registry"; | ||
import { Address, NormalizedConnectConfig } from "./conUtils"; | ||
import type { ICodec } from "./codecs/ifaces"; | ||
import type { CodecsRegistry } from "./codecs/registry"; | ||
import type { NormalizedConnectConfig } from "./conUtils"; | ||
import type { HttpSCRAMAuth } from "./httpScram"; | ||
import { ProtocolVersion, QueryArgs, QueryOptions } from "./ifaces"; | ||
import { Session } from "./options"; | ||
interface FetchConfig { | ||
address: Address | string; | ||
database: string; | ||
tlsSecurity?: string; | ||
user?: string; | ||
token?: string; | ||
} | ||
import { type ProtocolVersion, type QueryArgs, type QueryOptions } from "./ifaces"; | ||
import type { Session } from "./options"; | ||
import { type AuthenticatedFetch } from "./utils"; | ||
declare class BaseFetchConnection extends BaseRawConnection { | ||
protected config: FetchConfig; | ||
protected addr: string; | ||
protected authenticatedFetch: AuthenticatedFetch; | ||
protected abortSignal: AbortSignal | null; | ||
constructor(config: FetchConfig, registry: CodecsRegistry); | ||
protected _buildAddr(): string; | ||
constructor(fetch: AuthenticatedFetch, registry: CodecsRegistry); | ||
protected _waitForMessage(): Promise<void>; | ||
protected __sendData(data: Uint8Array): Promise<void>; | ||
protected _sendData(data: Uint8Array): void; | ||
static create<T extends typeof BaseFetchConnection>(this: T, config: FetchConfig, registry: CodecsRegistry): InstanceType<T>; | ||
static create<T extends typeof BaseFetchConnection>(this: T, fetch: AuthenticatedFetch, registry: CodecsRegistry): InstanceType<T>; | ||
} | ||
export declare class AdminUIFetchConnection extends BaseFetchConnection { | ||
adminUIMode: boolean; | ||
protected _buildAddr(): string; | ||
rawParse(query: string, state: Session, options?: QueryOptions, abortSignal?: AbortSignal | null): Promise<[ | ||
@@ -58,5 +49,4 @@ ICodec, | ||
export declare class FetchConnection extends BaseFetchConnection { | ||
protected _buildAddr(): string; | ||
static createConnectWithTimeout(httpSCRAMAuth: HttpSCRAMAuth): (addr: Address, config: NormalizedConnectConfig, registry: CodecsRegistry) => Promise<FetchConnection>; | ||
static createConnectWithTimeout(httpSCRAMAuth: HttpSCRAMAuth): (config: NormalizedConnectConfig, registry: CodecsRegistry) => Promise<FetchConnection>; | ||
} | ||
export {}; |
@@ -54,2 +54,3 @@ "use strict"; | ||
const event_1 = __importDefault(require("./primitives/event")); | ||
const utils_1 = require("./utils"); | ||
const PROTO_MIME = `application/x.edgedb.v_${baseConn_1.PROTO_VER[0]}_${baseConn_1.PROTO_VER[1]}.binary'`; | ||
@@ -61,13 +62,8 @@ const STUDIO_CAPABILITIES = (baseConn_1.RESTRICTED_CAPABILITIES | | ||
class BaseFetchConnection extends baseConn_1.BaseRawConnection { | ||
config; | ||
addr; | ||
authenticatedFetch; | ||
abortSignal = null; | ||
constructor(config, registry) { | ||
constructor(fetch, registry) { | ||
super(registry); | ||
this.config = config; | ||
this.addr = this._buildAddr(); | ||
this.authenticatedFetch = fetch; | ||
} | ||
_buildAddr() { | ||
this.throwNotImplemented("_buildAddr"); | ||
} | ||
async _waitForMessage() { | ||
@@ -93,15 +89,8 @@ if (this.buffer.takeMessage()) { | ||
try { | ||
const headers = { | ||
"Content-Type": PROTO_MIME, | ||
}; | ||
if (this.config.user !== undefined) { | ||
headers["X-EdgeDB-User"] = this.config.user; | ||
} | ||
if (this.config.token !== undefined) { | ||
headers.Authorization = `Bearer ${this.config.token}`; | ||
} | ||
const resp = await fetch(this.addr, { | ||
const resp = await this.authenticatedFetch("", { | ||
method: "post", | ||
body: data, | ||
headers, | ||
headers: { | ||
"Content-Type": PROTO_MIME, | ||
}, | ||
signal: this.abortSignal, | ||
@@ -135,4 +124,4 @@ }); | ||
} | ||
static create(config, registry) { | ||
const conn = new this(config, registry); | ||
static create(fetch, registry) { | ||
const conn = new this(fetch, registry); | ||
conn.connected = true; | ||
@@ -145,12 +134,2 @@ conn.connWaiter.set(); | ||
adminUIMode = true; | ||
_buildAddr() { | ||
const config = this.config; | ||
if (typeof config.address === "string") { | ||
return `${config.address}/db/${config.database}`; | ||
} | ||
const { address, tlsSecurity, database } = config; | ||
const protocol = tlsSecurity === "insecure" ? "http" : "https"; | ||
const baseUrl = `${protocol}://${address[0]}:${address[1]}`; | ||
return `${baseUrl}/db/${database}`; | ||
} | ||
async rawParse(query, state, options, abortSignal) { | ||
@@ -176,31 +155,7 @@ this.abortSignal = abortSignal ?? null; | ||
exports.AdminUIFetchConnection = AdminUIFetchConnection; | ||
const _tokens = new WeakMap(); | ||
class FetchConnection extends BaseFetchConnection { | ||
_buildAddr() { | ||
const config = this.config; | ||
if (typeof config.address === "string") { | ||
return `${config.address}/db/${config.database}`; | ||
} | ||
const { address, tlsSecurity, database } = config; | ||
const protocol = tlsSecurity === "insecure" ? "http" : "https"; | ||
const baseUrl = `${protocol}://${address[0]}:${address[1]}`; | ||
return `${baseUrl}/db/${database}`; | ||
} | ||
static createConnectWithTimeout(httpSCRAMAuth) { | ||
return async function connectWithTimeout(addr, config, registry) { | ||
const { connectionParams: { tlsSecurity, user, password = "", secretKey }, } = config; | ||
let token = secretKey ?? _tokens.get(config); | ||
if (!token) { | ||
const protocol = tlsSecurity === "insecure" ? "http" : "https"; | ||
const baseUrl = `${protocol}://${addr[0]}:${addr[1]}`; | ||
token = await httpSCRAMAuth(baseUrl, user, password); | ||
_tokens.set(config, token); | ||
} | ||
const conn = new FetchConnection({ | ||
address: addr, | ||
tlsSecurity, | ||
database: config.connectionParams.database, | ||
user: config.connectionParams.user, | ||
token, | ||
}, registry); | ||
return async function connectWithTimeout(config, registry) { | ||
const fetch = await (0, utils_1.getAuthenticatedFetch)(config.connectionParams, httpSCRAMAuth); | ||
const conn = new FetchConnection(fetch, registry); | ||
conn.connected = true; | ||
@@ -207,0 +162,0 @@ conn.connWaiter.set(); |
@@ -1,3 +0,3 @@ | ||
import { Client, ConnectOptions } from "./baseClient"; | ||
import { Client, type ConnectOptions } from "./baseClient"; | ||
export declare function createClient(options?: string | ConnectOptions | null): Client; | ||
export declare function createHttpClient(options?: string | ConnectOptions | null): Client; |
@@ -204,4 +204,4 @@ "use strict"; | ||
} | ||
static async connectWithTimeout(addr, config, registry, useTls = true) { | ||
const sock = this.newSock(addr, useTls ? getTlsOptions(config.connectionParams) : undefined); | ||
static async connectWithTimeout(config, registry, useTls = true) { | ||
const sock = this.newSock(config.connectionParams.address, useTls ? getTlsOptions(config.connectionParams) : undefined); | ||
const conn = new this(sock, config, registry); | ||
@@ -236,3 +236,3 @@ const connPromise = conn.connect(); | ||
try { | ||
return this.connectWithTimeout(addr, config, registry, false); | ||
return this.connectWithTimeout(config, registry, false); | ||
} | ||
@@ -244,3 +244,3 @@ catch { | ||
`Attempted to connect using the following credentials:\n` + | ||
`${config.connectionParams.explainConfig()}\n`); | ||
`${config.connectionParams.explainConfig()}\n`, { cause: e }); | ||
break; | ||
@@ -254,3 +254,3 @@ case "ECONNREFUSED": | ||
`Attempted to connect using the following credentials:\n` + | ||
`${config.connectionParams.explainConfig()}\n`); | ||
`${config.connectionParams.explainConfig()}\n`, { cause: e }); | ||
break; | ||
@@ -260,3 +260,3 @@ default: | ||
`Attempted to connect using the following credentials:\n` + | ||
`${config.connectionParams.explainConfig()}\n`); | ||
`${config.connectionParams.explainConfig()}\n`, { cause: e }); | ||
break; | ||
@@ -263,0 +263,0 @@ } |
@@ -18,6 +18,6 @@ /*! | ||
*/ | ||
import { BaseRawConnection } from "./baseConn"; | ||
import { CodecsRegistry } from "./codecs/registry"; | ||
import { Address, NormalizedConnectConfig } from "./conUtils"; | ||
export type ConnectWithTimeout = (addr: Address, config: NormalizedConnectConfig, registry: CodecsRegistry) => Promise<BaseRawConnection>; | ||
import type { BaseRawConnection } from "./baseConn"; | ||
import type { CodecsRegistry } from "./codecs/registry"; | ||
import type { NormalizedConnectConfig } from "./conUtils"; | ||
export type ConnectWithTimeout = (config: NormalizedConnectConfig, registry: CodecsRegistry) => Promise<BaseRawConnection>; | ||
export declare function retryingConnect(connectWithTimeout: ConnectWithTimeout, config: NormalizedConnectConfig, registry: CodecsRegistry): Promise<BaseRawConnection>; |
@@ -53,3 +53,3 @@ "use strict"; | ||
try { | ||
return await connectWithTimeout(config.connectionParams.address, config, registry); | ||
return await connectWithTimeout(config, registry); | ||
} | ||
@@ -56,0 +56,0 @@ catch (e) { |
@@ -18,3 +18,5 @@ /*! | ||
*/ | ||
import { ProtocolVersion } from "./ifaces"; | ||
import type { ResolvedConnectConfig } from "./conUtils"; | ||
import type { HttpSCRAMAuth } from "./httpScram"; | ||
import type { ProtocolVersion } from "./ifaces"; | ||
export declare function getUniqueId(prefix?: string): string; | ||
@@ -29,1 +31,3 @@ export declare function sleep(durationMillis: number): Promise<void>; | ||
} | ||
export type AuthenticatedFetch = (path: string, init: RequestInit) => Promise<Response>; | ||
export declare function getAuthenticatedFetch(config: ResolvedConnectConfig, httpSCRAMAuth: HttpSCRAMAuth, basePath?: string): Promise<AuthenticatedFetch>; |
@@ -20,3 +20,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.versionGreaterThanOrEqual = exports.versionGreaterThan = exports.sleep = exports.getUniqueId = void 0; | ||
exports.getAuthenticatedFetch = exports.versionGreaterThanOrEqual = exports.versionGreaterThan = exports.sleep = exports.getUniqueId = void 0; | ||
const idCounter = {}; | ||
@@ -54,1 +54,28 @@ function getUniqueId(prefix = "") { | ||
exports.versionGreaterThanOrEqual = versionGreaterThanOrEqual; | ||
const _tokens = new WeakMap(); | ||
async function getAuthenticatedFetch(config, httpSCRAMAuth, basePath) { | ||
let token = config.secretKey ?? _tokens.get(config); | ||
const { address, tlsSecurity, database } = config; | ||
const protocol = tlsSecurity === "insecure" ? "http" : "https"; | ||
const baseUrl = `${protocol}://${address[0]}:${address[1]}`; | ||
const databaseUrl = `${baseUrl}/db/${database}/${basePath ?? ""}`; | ||
if (!token && config.password != null) { | ||
token = await httpSCRAMAuth(baseUrl, config.user, config.password); | ||
_tokens.set(config, token); | ||
} | ||
return (path, init) => { | ||
const url = new URL(path, databaseUrl); | ||
const headers = new Headers(init.headers); | ||
if (config.user !== undefined) { | ||
headers.append("X-EdgeDB-User", config.user); | ||
} | ||
if (token !== undefined) { | ||
headers.append("Authorization", `Bearer ${token}`); | ||
} | ||
return fetch(url, { | ||
...init, | ||
headers, | ||
}); | ||
}; | ||
} | ||
exports.getAuthenticatedFetch = getAuthenticatedFetch; |
{ | ||
"name": "edgedb", | ||
"version": "1.6.0-canary.20240501T133708", | ||
"version": "1.6.0-canary.20240501T145919", | ||
"description": "The official Node.js client library for EdgeDB", | ||
@@ -46,3 +46,3 @@ "homepage": "https://edgedb.com/docs", | ||
"build:deno": "deno run --unstable --allow-all ./buildDeno.ts", | ||
"test": "npx --node-options='--experimental-fetch' jest --detectOpenHandles", | ||
"test": "npx jest --detectOpenHandles", | ||
"lint": "tslint 'packages/*/src/**/*.ts'", | ||
@@ -49,0 +49,0 @@ "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
543570
14172
11