Comparing version 1.5.4 to 1.5.5
@@ -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; |
@@ -28,3 +28,3 @@ /*! | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: unknown): void; | ||
@@ -35,3 +35,3 @@ decode(buf: ReadBuffer): LocalDateTime; | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: unknown): void; | ||
@@ -42,3 +42,3 @@ decode(buf: ReadBuffer): LocalDate; | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: unknown): void; | ||
@@ -50,3 +50,3 @@ decode(buf: ReadBuffer): LocalTime; | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: unknown): void; | ||
@@ -57,3 +57,3 @@ decode(buf: ReadBuffer): Duration; | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: unknown): void; | ||
@@ -64,5 +64,5 @@ decode(buf: ReadBuffer): RelativeDuration; | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: unknown): void; | ||
decode(buf: ReadBuffer): DateDuration; | ||
} |
@@ -50,3 +50,3 @@ "use strict"; | ||
tsType = "LocalDateTime"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -86,3 +86,3 @@ if (!(object instanceof datetime_1.LocalDateTime)) { | ||
tsType = "LocalDate"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -103,3 +103,3 @@ if (!(object instanceof datetime_1.LocalDate)) { | ||
tsType = "LocalTime"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -151,3 +151,3 @@ if (!(object instanceof datetime_1.LocalTime)) { | ||
tsType = "Duration"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -210,3 +210,3 @@ if (!(object instanceof datetime_1.Duration)) { | ||
tsType = "RelativeDuration"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -257,3 +257,3 @@ if (!(object instanceof datetime_1.RelativeDuration)) { | ||
tsType = "DateDuration"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -260,0 +260,0 @@ if (!(object instanceof datetime_1.DateDuration)) { |
@@ -47,4 +47,4 @@ /*! | ||
readonly tsType: string; | ||
readonly importedType: boolean; | ||
readonly tsModule: string | null; | ||
getKnownTypeName(): string; | ||
} |
@@ -56,3 +56,3 @@ "use strict"; | ||
tsType = "unknown"; | ||
importedType = false; | ||
tsModule = null; | ||
getKnownTypeName() { | ||
@@ -59,0 +59,0 @@ if (this.typeName) { |
@@ -22,5 +22,5 @@ /*! | ||
tsType: string; | ||
importedType: boolean; | ||
tsModule: string; | ||
encode(buf: WriteBuffer, object: any): void; | ||
decode(buf: ReadBuffer): any; | ||
} |
@@ -26,3 +26,3 @@ "use strict"; | ||
tsType = "ConfigMemory"; | ||
importedType = true; | ||
tsModule = "edgedb"; | ||
encode(buf, object) { | ||
@@ -29,0 +29,0 @@ if (!(object instanceof memory_1.ConfigMemory)) { |
@@ -22,2 +22,4 @@ /*! | ||
export declare class RangeCodec extends Codec implements ICodec { | ||
readonly tsType = "Range"; | ||
readonly tsModule = "edgedb"; | ||
private subCodec; | ||
@@ -31,2 +33,4 @@ constructor(tid: uuid, subCodec: ICodec); | ||
export declare class MultiRangeCodec extends Codec implements ICodec { | ||
readonly tsType = "MultiRange"; | ||
readonly tsModule = "edgedb"; | ||
private subCodec; | ||
@@ -33,0 +37,0 @@ constructor(tid: uuid, subCodec: ICodec); |
@@ -76,2 +76,4 @@ "use strict"; | ||
class RangeCodec extends ifaces_1.Codec { | ||
tsType = "Range"; | ||
tsModule = "edgedb"; | ||
subCodec; | ||
@@ -97,2 +99,4 @@ constructor(tid, subCodec) { | ||
class MultiRangeCodec extends ifaces_1.Codec { | ||
tsType = "MultiRange"; | ||
tsModule = "edgedb"; | ||
subCodec; | ||
@@ -99,0 +103,0 @@ constructor(tid, subCodec) { |
@@ -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 @@ } |
@@ -10,2 +10,3 @@ import type { ICodec } from "../codecs/ifaces"; | ||
query: string; | ||
importMap: ImportMap; | ||
imports: Set<string>; | ||
@@ -24,3 +25,3 @@ }; | ||
readonly: boolean; | ||
imports: Set<string>; | ||
imports: ImportMap; | ||
walk: (codec: CodecLike, context?: CodecGeneratorContext) => string; | ||
@@ -33,3 +34,3 @@ generators: CodecGeneratorMap; | ||
type: string; | ||
imports: Set<string>; | ||
imports: ImportMap; | ||
}; | ||
@@ -46,1 +47,5 @@ declare const genDef: <Codec extends CodecLike>(codecType: AbstractClass<Codec>, generator: CodecGenerator<Codec>) => readonly [AbstractClass<CodecLike>, CodecGenerator<CodecLike>]; | ||
export declare const defaultApplyCardinalityToTsType: (ctx: Pick<CodecGeneratorContext, "readonly">) => (type: string, cardinality: Cardinality) => string; | ||
export declare class ImportMap extends Map<string, Set<string>> { | ||
add(module: string, specifier: string): this; | ||
merge(map: ImportMap): ImportMap; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultApplyCardinalityToTsType = exports.generateTsObjectField = exports.generateTsObject = exports.defaultCodecGenerators = exports.defineCodecGeneratorTuple = exports.generateTSTypeFromCodec = exports.analyzeQuery = void 0; | ||
exports.ImportMap = exports.defaultApplyCardinalityToTsType = exports.generateTsObjectField = exports.generateTsObject = exports.defaultCodecGenerators = exports.defineCodecGeneratorTuple = exports.generateTSTypeFromCodec = exports.analyzeQuery = void 0; | ||
const array_1 = require("../codecs/array"); | ||
@@ -22,2 +22,3 @@ const enum_1 = require("../codecs/enum"); | ||
const result = (0, exports.generateTSTypeFromCodec)(outCodec, cardinality); | ||
const imports = args.imports.merge(result.imports); | ||
return { | ||
@@ -28,3 +29,4 @@ result: result.type, | ||
query, | ||
imports: new Set([...args.imports, ...result.imports]), | ||
importMap: imports, | ||
imports: imports.get("edgedb") ?? new Set(), | ||
}; | ||
@@ -45,3 +47,3 @@ } | ||
...options, | ||
imports: new Set(), | ||
imports: new ImportMap(), | ||
walk: (codec, innerContext) => { | ||
@@ -72,4 +74,4 @@ innerContext ??= context; | ||
genDef(ifaces_1.ScalarCodec, (codec, ctx) => { | ||
if (codec.importedType) { | ||
ctx.imports.add(codec.tsType); | ||
if (codec.tsModule) { | ||
ctx.imports.add(codec.tsModule, codec.tsType); | ||
} | ||
@@ -109,4 +111,4 @@ return codec.tsType; | ||
} | ||
ctx.imports.add("Range"); | ||
return `Range<${ctx.walk(subCodec)}>`; | ||
ctx.imports.add(codec.tsModule, codec.tsType); | ||
return `${codec.tsType}<${ctx.walk(subCodec)}>`; | ||
}), | ||
@@ -118,4 +120,4 @@ genDef(range_1.MultiRangeCodec, (codec, ctx) => { | ||
} | ||
ctx.imports.add("MultiRange"); | ||
return `MultiRange<${ctx.walk(subCodec)}>`; | ||
ctx.imports.add(codec.tsModule, codec.tsType); | ||
return `${codec.tsType}<${ctx.walk(subCodec)}>`; | ||
}), | ||
@@ -164,1 +166,20 @@ ]); | ||
exports.defaultApplyCardinalityToTsType = defaultApplyCardinalityToTsType; | ||
class ImportMap extends Map { | ||
add(module, specifier) { | ||
if (!this.has(module)) { | ||
this.set(module, new Set()); | ||
} | ||
this.get(module).add(specifier); | ||
return this; | ||
} | ||
merge(map) { | ||
const out = new ImportMap(); | ||
for (const [mod, specifiers] of [...this, ...map]) { | ||
for (const specifier of specifiers) { | ||
out.add(mod, specifier); | ||
} | ||
} | ||
return out; | ||
} | ||
} | ||
exports.ImportMap = ImportMap; |
@@ -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.5.4", | ||
"version": "1.5.5", | ||
"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'", |
Sorry, the diff of this file is not supported yet
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
545628
14224
11