Comparing version 0.7.0-alpha.3 to 0.7.0-alpha.4
@@ -120,2 +120,3 @@ /*! | ||
readInt64(): number; | ||
readBigInt64Fallback(): bigint; | ||
readBigInt64(): bigint; | ||
@@ -122,0 +123,0 @@ readBuffer(size: number): Buffer; |
@@ -26,2 +26,3 @@ "use strict"; | ||
const EMPTY_BUFFER = buffer_1.Buffer.allocUnsafe(0); | ||
const isNode12 = !!buffer_1.Buffer["readBigInt64BE"]; | ||
class BufferError extends Error { | ||
@@ -668,6 +669,3 @@ } | ||
} | ||
readBigInt64() { | ||
if (this.pos + 8 > this.len) { | ||
throw new BufferError("buffer overread"); | ||
} | ||
readBigInt64Fallback() { | ||
const hi = this.buffer.readUInt32BE(this.pos); | ||
@@ -682,2 +680,15 @@ const lo = this.buffer.readUInt32BE(this.pos + 4); | ||
} | ||
readBigInt64() { | ||
if (this.pos + 8 > this.len) { | ||
throw new BufferError("buffer overread"); | ||
} | ||
if (isNode12) { | ||
const ret = this.buffer.readBigInt64BE(this.pos); | ||
this.pos += 8; | ||
return ret; | ||
} | ||
else { | ||
return this.readBigInt64Fallback(); | ||
} | ||
} | ||
readBuffer(size) { | ||
@@ -684,0 +695,0 @@ if (this.pos + size > this.len) { |
@@ -23,3 +23,3 @@ /*! | ||
import { ConnectConfig } from "./con_utils"; | ||
declare type QueryArgPrimitive = number | string | boolean | Buffer | Date | LocalDateTime | LocalDate | LocalTime | Duration | UUID; | ||
declare type QueryArgPrimitive = number | string | boolean | BigInt | Buffer | Date | LocalDateTime | LocalDate | LocalTime | Duration | UUID; | ||
declare type QueryArg = QueryArgPrimitive | QueryArgPrimitive[] | null; | ||
@@ -26,0 +26,0 @@ declare type QueryArgs = { |
@@ -23,2 +23,3 @@ "use strict"; | ||
const numbers_1 = require("./numbers"); | ||
const numerics_1 = require("./numerics"); | ||
const text_1 = require("./text"); | ||
@@ -50,2 +51,3 @@ const uuid_1 = require("./uuid"); | ||
["0000000000000000000000000000010f", "std::json"], | ||
["00000000000000000000000000000110", "std::bigint"], | ||
]); | ||
@@ -83,2 +85,3 @@ exports.KNOWN_TYPENAMES = (() => { | ||
registerScalarCodec("std::float64", numbers_1.Float64Codec); | ||
registerScalarCodec("std::bigint", numerics_1.BigIntCodec); | ||
registerScalarCodec("std::bool", boolean_1.BoolCodec); | ||
@@ -85,0 +88,0 @@ registerScalarCodec("std::json", json_1.JSONCodec); |
@@ -30,2 +30,3 @@ "use strict"; | ||
const set_1 = require("./set"); | ||
const uuid_1 = require("../datatypes/uuid"); | ||
const CODECS_CACHE_SIZE = 1000; | ||
@@ -156,2 +157,8 @@ const CODECS_BUILD_CACHE_SIZE = 200; | ||
res = codecs_1.SCALAR_CODECS.get(tid); | ||
if (!res) { | ||
if (codecs_1.KNOWN_TYPES.has(tid)) { | ||
throw new Error(`no JS codec for ${codecs_1.KNOWN_TYPES.get(tid)}`); | ||
} | ||
throw new Error(`node JS codec for the type with ID ${uuid_1.UUID.fromString(tid)}`); | ||
} | ||
if (!(res instanceof ifaces_1.ScalarCodec)) { | ||
@@ -158,0 +165,0 @@ throw new Error("could not build scalar codec: base scalar has a non-scalar codec"); |
@@ -24,5 +24,4 @@ /*! | ||
constructor(buffer: Buffer); | ||
private _toString; | ||
toString(): string; | ||
get buffer(): Buffer; | ||
toString(): string; | ||
valueOf(): string; | ||
@@ -29,0 +28,0 @@ toJSON(): string; |
@@ -30,7 +30,17 @@ "use strict"; | ||
} | ||
_toString() { | ||
toString() { | ||
if (this._str != null) { | ||
return this._str; | ||
} | ||
this._str = this._buf.toString("hex"); | ||
const sl = this._buf.toString("hex"); | ||
this._str = | ||
sl.slice(0, 8) + | ||
"-" + | ||
sl.slice(8, 12) + | ||
"-" + | ||
sl.slice(12, 16) + | ||
"-" + | ||
sl.slice(16, 20) + | ||
"-" + | ||
sl.slice(20, 32); | ||
return this._str; | ||
@@ -41,10 +51,7 @@ } | ||
} | ||
toString() { | ||
return this._toString(); | ||
} | ||
valueOf() { | ||
return this._toString(); | ||
return this.toString(); | ||
} | ||
toJSON() { | ||
return this._toString(); | ||
return this.toString(); | ||
} | ||
@@ -55,6 +62,6 @@ [Symbol.toPrimitive](hint) { | ||
} | ||
return this._toString(); | ||
return this.toString(); | ||
} | ||
[util.inspect.custom](_depth, options) { | ||
return `UUID [ ${util.inspect(this._toString(), options.showHidden, 0, options.colors)} ]`; | ||
return `UUID [ ${util.inspect(this.toString(), options.showHidden, 0, options.colors)} ]`; | ||
} | ||
@@ -61,0 +68,0 @@ static fromString(uuid) { |
@@ -79,2 +79,98 @@ "use strict"; | ||
}); | ||
test("fetch: bigint", async () => { | ||
const con = await testbase_1.asyncConnect(); | ||
let res; | ||
try { | ||
const testar = [ | ||
BigInt("0"), | ||
BigInt("-0"), | ||
BigInt("+0"), | ||
BigInt("1"), | ||
BigInt("-1"), | ||
BigInt("123"), | ||
BigInt("-123"), | ||
BigInt("123789"), | ||
BigInt("-123789"), | ||
BigInt("19876"), | ||
BigInt("-19876"), | ||
BigInt("19876"), | ||
BigInt("-19876"), | ||
BigInt("198761239812739812739801279371289371932"), | ||
BigInt("-198761182763908473812974620938742386"), | ||
BigInt("98761239812739812739801279371289371932"), | ||
BigInt("-98761182763908473812974620938742386"), | ||
BigInt("8761239812739812739801279371289371932"), | ||
BigInt("-8761182763908473812974620938742386"), | ||
BigInt("761239812739812739801279371289371932"), | ||
BigInt("-761182763908473812974620938742386"), | ||
BigInt("61239812739812739801279371289371932"), | ||
BigInt("-61182763908473812974620938742386"), | ||
BigInt("1239812739812739801279371289371932"), | ||
BigInt("-1182763908473812974620938742386"), | ||
BigInt("9812739812739801279371289371932"), | ||
BigInt("-3908473812974620938742386"), | ||
BigInt("98127373373209"), | ||
BigInt("-4620938742386"), | ||
BigInt("100000000000"), | ||
BigInt("-100000000000"), | ||
BigInt("10000000000"), | ||
BigInt("-10000000000"), | ||
BigInt("1000000000"), | ||
BigInt("-1000000000"), | ||
BigInt("100000000"), | ||
BigInt("-100000000"), | ||
BigInt("10000000"), | ||
BigInt("-10000000"), | ||
BigInt("1000000"), | ||
BigInt("-1000000"), | ||
BigInt("100000"), | ||
BigInt("-100000"), | ||
BigInt("10000"), | ||
BigInt("-10000"), | ||
BigInt("1000"), | ||
BigInt("-1000"), | ||
BigInt("100"), | ||
BigInt("-100"), | ||
BigInt("10"), | ||
BigInt("-10"), | ||
BigInt("100030000010"), | ||
BigInt("-100000600004"), | ||
BigInt("10000000100"), | ||
BigInt("-10030000000"), | ||
BigInt("1000040000"), | ||
BigInt("-1000000000"), | ||
BigInt("1010000001"), | ||
BigInt("-1000000001"), | ||
BigInt("1001001000"), | ||
BigInt("-10000099"), | ||
BigInt("99999"), | ||
BigInt("9999"), | ||
BigInt("999"), | ||
BigInt("1011"), | ||
BigInt("1009"), | ||
BigInt("1709"), | ||
]; | ||
for (let i = 0; i < 1000; i++) { | ||
const len = Math.floor(Math.random() * 30) + 1; | ||
let num = ""; | ||
for (let j = 0; j < len; j++) { | ||
num += "0123456789"[Math.floor(Math.random() * 10)]; | ||
} | ||
testar.push(BigInt(num)); | ||
} | ||
for (let i = 0; i < 1000; i++) { | ||
const len = Math.floor(Math.random() * 50) + 1; | ||
let num = ""; | ||
for (let j = 0; j < len; j++) { | ||
num += "0000000012"[Math.floor(Math.random() * 10)]; | ||
} | ||
testar.push(BigInt(num)); | ||
} | ||
res = await con.fetchOne("select <array<bigint>>$0", [testar]); | ||
expect(res).toEqual(testar); | ||
} | ||
finally { | ||
await con.close(); | ||
} | ||
}); | ||
test("fetch: positional args", async () => { | ||
@@ -438,3 +534,3 @@ const con = await testbase_1.asyncConnect(); | ||
`); | ||
expect(JSON.stringify(res)).toMatch(/^\{"id":"([\w\d]{32})"\}$/); | ||
expect(JSON.stringify(res)).toMatch(/^\{"id":"([\w\d\-]{36})"\}$/); | ||
expect(JSON.stringify(res)).not.toMatch(/"__tid__"/); | ||
@@ -445,3 +541,3 @@ res = await con.fetchOne(` | ||
`); | ||
expect(JSON.stringify(res)).toMatch(/"id":"([\w\d]{32})"/); | ||
expect(JSON.stringify(res)).toMatch(/"id":"([\w\d\-]{36})"/); | ||
res = await con.fetchOne(` | ||
@@ -467,6 +563,6 @@ select schema::Function { | ||
expect(res.buffer.length).toBe(16); | ||
res = await con.fetchOne("SELECT <uuid>'759637d8663511e9b9d4098002d459d5'"); | ||
res = await con.fetchOne("SELECT <uuid>'759637d8-6635-11e9-b9d4-098002d459d5'"); | ||
expect(res instanceof index_1.UUID).toBeTruthy(); | ||
expect(res.buffer.length).toBe(16); | ||
expect(res.toString()).toBe("759637d8663511e9b9d4098002d459d5"); | ||
expect(res.toString()).toBe("759637d8-6635-11e9-b9d4-098002d459d5"); | ||
} | ||
@@ -733,1 +829,17 @@ finally { | ||
}); | ||
test("fetch no codec", async () => { | ||
const con = await testbase_1.asyncConnect(); | ||
try { | ||
await con | ||
.fetchOne("select <decimal>1") | ||
.then(() => { | ||
throw new Error("an exception was expected"); | ||
}) | ||
.catch((e) => { | ||
expect(e.toString()).toMatch(/no JS codec for std::decimal/); | ||
}); | ||
} | ||
finally { | ||
await con.close(); | ||
} | ||
}); |
@@ -31,3 +31,4 @@ "use strict"; | ||
const uuid = index_1.UUID.fromString("1733d49c-66ed-11e9-aa14-784f439c9965"); | ||
expect(util.inspect(uuid)).toBe("UUID [ '1733d49c66ed11e9aa14784f439c9965' ]"); | ||
expect(util.inspect(uuid)).toBe("UUID [ '1733d49c-66ed-11e9-aa14-784f439c9965' ]"); | ||
expect(JSON.stringify([uuid])).toBe('["1733d49c-66ed-11e9-aa14-784f439c9965"]'); | ||
expect(() => { | ||
@@ -34,0 +35,0 @@ return +uuid; |
@@ -13,5 +13,5 @@ { | ||
}, | ||
"version": "0.7.0-alpha.3", | ||
"version": "0.7.0-alpha.4", | ||
"main": "./dist/src/index.js", | ||
"types": "./dist/index.d.ts", | ||
"types": "./dist/src/index.d.ts", | ||
"license": "Apache-2.0", | ||
@@ -18,0 +18,0 @@ "files": [ |
# The NodeJS driver for EdgeDB | ||
[![Build Status](https://github.com/edgedb/edgedb-js/workflows/Tests/badge.svg?event=push&branch=master)](https://github.com/edgedb/edgedb-js/) [![Join the community on Spectrum](https://img.shields.io/badge/join%20the%20community-on%20spectrum-blueviolet)](https://spectrum.chat/edgedb) | ||
[![Build Status](https://github.com/edgedb/edgedb-js/workflows/Tests/badge.svg?event=push&branch=master)](https://github.com/edgedb/edgedb-js/actions) [![NPM](https://img.shields.io/npm/v/edgedb)](https://www.npmjs.com/package/edgedb) [![Join the community on Spectrum](https://img.shields.io/badge/join%20the%20community-on%20spectrum-blueviolet)](https://spectrum.chat/edgedb) | ||
@@ -5,0 +5,0 @@ **edgedb** is the official [EdgeDB](https://github.com/edgedb/edgedb) driver |
@@ -33,2 +33,6 @@ /*! | ||
// @ts-ignore | ||
// tslint:disable-next-line | ||
const isNode12: boolean = !!Buffer["readBigInt64BE"]; | ||
export class BufferError extends Error {} | ||
@@ -823,7 +827,3 @@ | ||
readBigInt64(): bigint { | ||
if (this.pos + 8 > this.len) { | ||
throw new BufferError("buffer overread"); | ||
} | ||
// TODO(tailhook) use: readBigInt64BE (node 12.0) | ||
readBigInt64Fallback(): bigint { | ||
const hi = this.buffer.readUInt32BE(this.pos); | ||
@@ -840,2 +840,15 @@ const lo = this.buffer.readUInt32BE(this.pos + 4); | ||
readBigInt64(): bigint { | ||
if (this.pos + 8 > this.len) { | ||
throw new BufferError("buffer overread"); | ||
} | ||
if (isNode12) { | ||
const ret = this.buffer.readBigInt64BE(this.pos); | ||
this.pos += 8; | ||
return ret; | ||
} else { | ||
return this.readBigInt64Fallback(); | ||
} | ||
} | ||
readBuffer(size: number): Buffer { | ||
@@ -842,0 +855,0 @@ if (this.pos + size > this.len) { |
@@ -48,2 +48,3 @@ /*! | ||
| boolean | ||
| BigInt | ||
| Buffer | ||
@@ -50,0 +51,0 @@ | Date |
@@ -29,2 +29,3 @@ /*! | ||
} from "./numbers"; | ||
import {BigIntCodec} from "./numerics"; | ||
import {StrCodec} from "./text"; | ||
@@ -63,2 +64,3 @@ import {UUIDCodec} from "./uuid"; | ||
["0000000000000000000000000000010f", "std::json"], | ||
["00000000000000000000000000000110", "std::bigint"], | ||
]); | ||
@@ -114,2 +116,4 @@ | ||
registerScalarCodec("std::bigint", BigIntCodec); | ||
registerScalarCodec("std::bool", BoolCodec); | ||
@@ -116,0 +120,0 @@ |
@@ -29,2 +29,3 @@ /*! | ||
import {SetCodec} from "./set"; | ||
import {UUID} from "../datatypes/uuid"; | ||
@@ -190,2 +191,11 @@ const CODECS_CACHE_SIZE = 1000; | ||
res = SCALAR_CODECS.get(tid); | ||
if (!res) { | ||
if (KNOWN_TYPES.has(tid)) { | ||
throw new Error(`no JS codec for ${KNOWN_TYPES.get(tid)}`); | ||
} | ||
throw new Error( | ||
`node JS codec for the type with ID ${UUID.fromString(tid)}` | ||
); | ||
} | ||
if (!(res instanceof ScalarCodec)) { | ||
@@ -192,0 +202,0 @@ throw new Error( |
@@ -35,7 +35,28 @@ /*! | ||
private _toString(): string { | ||
toString(): string { | ||
if (this._str != null) { | ||
return this._str; | ||
} | ||
this._str = this._buf.toString("hex"); | ||
/* As benchmarked, the fastest way is to convert to a hex-string and | ||
then slice/concat with '-'. Calling `buf.slice()` multiple times | ||
is 4x slower; using the `[].join('-')` pattern is 2x slower than | ||
simple `str+str`. | ||
Overall, this nicer formatting is going to be 1.5x slower than | ||
just returning `buf.toString('hex')`. | ||
See https://gist.github.com/1st1/5a7e5a8ff36d49f492631c74bc007515 | ||
for more details. | ||
*/ | ||
const sl = this._buf.toString("hex"); | ||
this._str = | ||
sl.slice(0, 8) + | ||
"-" + | ||
sl.slice(8, 12) + | ||
"-" + | ||
sl.slice(12, 16) + | ||
"-" + | ||
sl.slice(16, 20) + | ||
"-" + | ||
sl.slice(20, 32); | ||
return this._str; | ||
@@ -48,12 +69,8 @@ } | ||
toString(): string { | ||
return this._toString(); | ||
} | ||
valueOf(): string { | ||
return this._toString(); | ||
return this.toString(); | ||
} | ||
toJSON(): string { | ||
return this._toString(); | ||
return this.toString(); | ||
} | ||
@@ -65,3 +82,3 @@ | ||
} | ||
return this._toString(); | ||
return this.toString(); | ||
} | ||
@@ -71,3 +88,3 @@ | ||
return `UUID [ ${util.inspect( | ||
this._toString(), | ||
this.toString(), | ||
options.showHidden, | ||
@@ -74,0 +91,0 @@ 0, |
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
470858
130
13856