Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edgedb

Package Overview
Dependencies
Maintainers
2
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edgedb - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

dist/src/bigint.d.ts

5

dist/src/buffer.d.ts

@@ -20,2 +20,3 @@ /*!

import char from "./chars";
import * as bi from "./bigint";
export declare class BufferError extends Error {

@@ -121,4 +122,4 @@ }

readInt64(): number;
readBigInt64Fallback(): bigint;
readBigInt64(): bigint;
readBigInt64Fallback(): bi.BigIntLike;
readBigInt64(): bi.BigIntLike;
readBuffer(size: number): Buffer;

@@ -125,0 +126,0 @@ readUUID(): string;

42

dist/src/buffer.js

@@ -22,2 +22,4 @@ "use strict";

const ring_1 = require("./ring");
const bi = require("./bigint");
const compat = require("./compat");
const BUFFER_INC_SIZE = 4096;

@@ -113,7 +115,8 @@ const BUFFER_RING_CAPACITY = 2048;

writeBigInt64(i) {
if (i < 0) {
i = BigInt("18446744073709551616") + i;
let ii = i;
if (ii < 0) {
ii = bi.add(bi.make("18446744073709551616"), i);
}
const hi = i >> BigInt(32);
const lo = i & BigInt(0xffffffff);
const hi = bi.rshift(ii, bi.make(32));
const lo = bi.bitand(ii, bi.make(0xffffffff));
this.writeUInt32(Number(hi));

@@ -648,7 +651,7 @@ this.writeUInt32(Number(lo));

reportInt64Overflow(hi, lo) {
const bhi = BigInt(hi);
const blo = BigInt(lo >>> 0);
const num = bhi * BigInt(0x100000000) + blo;
throw new Error(`integer overflow: cannot unpack <std::int64>'${num}' into JavaScript ` +
`Number type without losing precision`);
const bhi = bi.make(hi);
const blo = bi.make(lo >>> 0);
const num = bi.add(bi.mul(bhi, bi.make(0x100000000)), blo);
throw new Error(`integer overflow: cannot unpack <std::int64>'${num.toString()}' ` +
`into JavaScript Number type without losing precision`);
}

@@ -671,10 +674,17 @@ readInt64() {

readBigInt64Fallback() {
const hi = this.buffer.readUInt32BE(this.pos);
const lo = this.buffer.readUInt32BE(this.pos + 4);
this.pos += 8;
let res = (BigInt(hi) << BigInt(32)) + BigInt(lo);
if (hi >= 0x80000000) {
res = BigInt("-18446744073709551616") + res;
if (bi.hasNativeBigInt) {
const hi = this.buffer.readUInt32BE(this.pos);
const lo = this.buffer.readUInt32BE(this.pos + 4);
this.pos += 8;
let res = (BigInt(hi) << BigInt(32)) + BigInt(lo);
if (hi >= 0x80000000) {
res = BigInt("-18446744073709551616") + res;
}
return res;
}
return res;
else {
const buf = this.readBuffer(8);
const snum = compat.decodeInt64ToString(buf);
return bi.make(snum);
}
}

@@ -681,0 +691,0 @@ readBigInt64() {

@@ -18,3 +18,3 @@ /*!

*/
import { ICodec, Codec, uuid } from "./ifaces";
import { ICodec, Codec, uuid, CodecKind } from "./ifaces";
import { WriteBuffer, ReadBuffer } from "../buffer";

@@ -27,2 +27,4 @@ export declare class ArrayCodec extends Codec implements ICodec {

decode(buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getKind(): CodecKind;
}

@@ -90,2 +90,8 @@ "use strict";

}
getSubcodecs() {
return [this.subCodec];
}
getKind() {
return "array";
}
}

@@ -92,0 +98,0 @@ exports.ArrayCodec = ArrayCodec;

@@ -19,11 +19,10 @@ /*!

import { ReadBuffer, WriteBuffer } from "../buffer";
import { ICodec, Codec } from "./ifaces";
export declare const KNOWN_TYPES: Map<string, string>;
export declare const KNOWN_TYPENAMES: Map<string, string>;
import { ICodec, Codec, CodecKind } from "./ifaces";
export declare class NullCodec extends Codec implements ICodec {
encode(_buf: WriteBuffer, _object: any): void;
decode(_buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getKind(): CodecKind;
}
export declare const SCALAR_CODECS: Map<string, ICodec>;
export declare const NULL_CODEC_ID = "00000000000000000000000000000000";
export declare const NULL_CODEC: NullCodec;

@@ -29,32 +29,3 @@ "use strict";

const datetime_1 = require("./datetime");
exports.KNOWN_TYPES = new Map([
["00000000000000000000000000000001", "anytype"],
["00000000000000000000000000000002", "anytuple"],
["000000000000000000000000000000f0", "std"],
["000000000000000000000000000000ff", "empty-tuple"],
["00000000000000000000000000000100", "std::uuid"],
["00000000000000000000000000000101", "std::str"],
["00000000000000000000000000000102", "std::bytes"],
["00000000000000000000000000000103", "std::int16"],
["00000000000000000000000000000104", "std::int32"],
["00000000000000000000000000000105", "std::int64"],
["00000000000000000000000000000106", "std::float32"],
["00000000000000000000000000000107", "std::float64"],
["00000000000000000000000000000108", "std::decimal"],
["00000000000000000000000000000109", "std::bool"],
["0000000000000000000000000000010a", "std::datetime"],
["0000000000000000000000000000010b", "std::local_datetime"],
["0000000000000000000000000000010c", "std::local_date"],
["0000000000000000000000000000010d", "std::local_time"],
["0000000000000000000000000000010e", "std::duration"],
["0000000000000000000000000000010f", "std::json"],
["00000000000000000000000000000110", "std::bigint"],
]);
exports.KNOWN_TYPENAMES = (() => {
const res = new Map();
for (const [id, name] of exports.KNOWN_TYPES.entries()) {
res.set(name, id);
}
return res;
})();
const consts_1 = require("./consts");
class NullCodec extends ifaces_1.Codec {

@@ -67,9 +38,14 @@ encode(_buf, _object) {

}
getSubcodecs() {
return [];
}
getKind() {
return "scalar";
}
}
exports.NullCodec = NullCodec;
exports.SCALAR_CODECS = new Map();
exports.NULL_CODEC_ID = "00000000000000000000000000000000";
exports.NULL_CODEC = new NullCodec(exports.NULL_CODEC_ID);
exports.NULL_CODEC = new NullCodec(consts_1.NULL_CODEC_ID);
function registerScalarCodec(typename, type) {
const id = exports.KNOWN_TYPENAMES.get(typename);
const id = consts_1.KNOWN_TYPENAMES.get(typename);
if (id == null) {

@@ -76,0 +52,0 @@ throw new Error("unknown type name");

@@ -21,2 +21,3 @@ /*!

export declare type uuid = string;
export declare type CodecKind = "array" | "tuple" | "namedtuple" | "object" | "set" | "scalar";
export interface ICodec {

@@ -27,2 +28,6 @@ readonly tid: uuid;

decode(buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getSubcodecsNames(): string[];
getKind(): CodecKind;
getKnownTypeName(): string;
}

@@ -36,5 +41,12 @@ export interface IArgsCodec {

constructor(tid: uuid);
getKnownTypeName(): string;
getSubcodecsNames(): string[];
}
export declare abstract class ScalarCodec extends Codec {
private derivedFromTid;
constructor(tid: uuid, derivedFromTid?: uuid | null);
derive(tid: uuid): Codec;
getSubcodecs(): ICodec[];
getKind(): CodecKind;
getKnownTypeName(): string;
}

@@ -20,2 +20,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const consts_1 = require("./consts");
class Codec {

@@ -26,10 +27,33 @@ constructor(tid) {

}
getKnownTypeName() {
return "anytype";
}
getSubcodecsNames() {
return [];
}
}
exports.Codec = Codec;
class ScalarCodec extends Codec {
constructor(tid, derivedFromTid = null) {
super(tid);
this.derivedFromTid = null;
this.derivedFromTid = derivedFromTid;
}
derive(tid) {
const self = this.constructor;
return new self(tid);
return new self(tid, this.tid);
}
getSubcodecs() {
return [];
}
getKind() {
return "scalar";
}
getKnownTypeName() {
if (this.derivedFromTid) {
return consts_1.KNOWN_TYPES.get(this.derivedFromTid);
}
return consts_1.KNOWN_TYPES.get(this.tid) || "anytype";
}
}
exports.ScalarCodec = ScalarCodec;

@@ -19,3 +19,3 @@ /*!

/// <reference types="node" />
import { ICodec, Codec, uuid, IArgsCodec } from "./ifaces";
import { ICodec, Codec, uuid, IArgsCodec, CodecKind } from "./ifaces";
import { ReadBuffer, WriteBuffer } from "../buffer";

@@ -31,2 +31,5 @@ export declare class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {

decode(buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getSubcodecsNames(): string[];
getKind(): CodecKind;
}

@@ -97,3 +97,12 @@ "use strict";

}
getSubcodecs() {
return Array.from(this.subCodecs);
}
getSubcodecsNames() {
return Array.from(this.names);
}
getKind() {
return "namedtuple";
}
}
exports.NamedTupleCodec = NamedTupleCodec;

@@ -24,2 +24,6 @@ /*!

}
export declare class Int64StringCodec extends ScalarCodec implements ICodec {
encode(_buf: WriteBuffer, _object: any): void;
decode(buf: ReadBuffer): any;
}
export declare class Int32Codec extends ScalarCodec implements ICodec {

@@ -26,0 +30,0 @@ encode(buf: WriteBuffer, object: any): void;

@@ -21,2 +21,3 @@ "use strict";

const ifaces_1 = require("./ifaces");
const compat_1 = require("../compat");
class Int64Codec extends ifaces_1.ScalarCodec {

@@ -35,2 +36,11 @@ encode(buf, object) {

exports.Int64Codec = Int64Codec;
class Int64StringCodec extends ifaces_1.ScalarCodec {
encode(_buf, _object) {
throw new Error("not implemented");
}
decode(buf) {
return compat_1.decodeInt64ToString(buf.readBuffer(8));
}
}
exports.Int64StringCodec = Int64StringCodec;
class Int32Codec extends ifaces_1.ScalarCodec {

@@ -37,0 +47,0 @@ encode(buf, object) {

@@ -24,1 +24,9 @@ /*!

}
export declare class BigIntStringCodec extends ScalarCodec implements ICodec {
encode(_buf: WriteBuffer, _object: BigInt): void;
decode(buf: ReadBuffer): any;
}
export declare class DecimalStringCodec extends ScalarCodec implements ICodec {
encode(_buf: WriteBuffer, _object: BigInt): void;
decode(buf: ReadBuffer): any;
}

@@ -21,4 +21,2 @@ "use strict";

const ifaces_1 = require("./ifaces");
const NBASE = BigInt("10000");
const ZERO = BigInt("0");
const NUMERIC_POS = 0x0000;

@@ -28,2 +26,4 @@ const NUMERIC_NEG = 0x4000;

encode(buf, object) {
const NBASE = BigInt("10000");
const ZERO = BigInt("0");
const digits = [];

@@ -58,40 +58,100 @@ let sign = NUMERIC_POS;

decode(buf) {
const ndigits = buf.readUInt16();
const weight = buf.readInt16();
const sign = buf.readUInt16();
const dscale = buf.readUInt16();
let result = "";
switch (sign) {
case NUMERIC_POS:
break;
case NUMERIC_NEG:
result += "-";
break;
default:
throw new Error("bad bigint sign data");
return BigInt(decodeBigIntToString(buf));
}
}
exports.BigIntCodec = BigIntCodec;
class BigIntStringCodec extends ifaces_1.ScalarCodec {
encode(_buf, _object) {
throw new Error("not implemented");
}
decode(buf) {
return decodeBigIntToString(buf);
}
}
exports.BigIntStringCodec = BigIntStringCodec;
class DecimalStringCodec extends ifaces_1.ScalarCodec {
encode(_buf, _object) {
throw new Error("not implemented");
}
decode(buf) {
return decodeDecimalToString(buf);
}
}
exports.DecimalStringCodec = DecimalStringCodec;
function decodeBigIntToString(buf) {
const ndigits = buf.readUInt16();
const weight = buf.readInt16();
const sign = buf.readUInt16();
const dscale = buf.readUInt16();
let result = "";
switch (sign) {
case NUMERIC_POS:
break;
case NUMERIC_NEG:
result += "-";
break;
default:
throw new Error("bad bigint sign data");
}
if (dscale !== 0) {
throw new Error("bigint data has fractional part");
}
if (ndigits === 0) {
return "0";
}
let i = weight;
let d = 0;
while (i >= 0) {
if (i <= weight && d < ndigits) {
const digit = buf.readUInt16().toString();
result += d > 0 ? digit.padStart(4, "0") : digit;
d++;
}
if (dscale !== 0) {
throw new Error("bigint data has fractional part");
else {
result += "0000";
}
if (ndigits === 0) {
return BigInt("0");
}
let i = weight;
let d = 0;
while (i >= 0) {
if (i <= weight && d < ndigits) {
result += buf
.readUInt16()
.toString()
.padStart(4, "0");
d++;
i--;
}
return result;
}
function decodeDecimalToString(buf) {
const ndigits = buf.readUInt16();
const weight = buf.readInt16();
const sign = buf.readUInt16();
const dscale = buf.readUInt16();
let result = "";
switch (sign) {
case NUMERIC_POS:
break;
case NUMERIC_NEG:
result += "-";
break;
default:
throw new Error("bad decimal sign data");
}
let d = 0;
if (weight < 0) {
d = weight + 1;
result += "0";
}
else {
for (d = 0; d <= weight; d++) {
const digit = d < ndigits ? buf.readUInt16() : 0;
let sdigit = digit.toString();
if (d > 0) {
sdigit = sdigit.padStart(4, "0");
}
else {
result += "0000";
}
i--;
result += sdigit;
}
return BigInt(result);
}
if (dscale > 0) {
result += ".";
const end = result.length + dscale;
for (let i = 0; i < dscale; d++, i += 4) {
const digit = d >= 0 && d < ndigits ? buf.readUInt16() : 0;
result += digit.toString().padStart(4, "0");
}
result = result.slice(0, end);
}
return result;
}
exports.BigIntCodec = BigIntCodec;

@@ -18,3 +18,3 @@ /*!

*/
import { ICodec, Codec, uuid } from "./ifaces";
import { ICodec, Codec, uuid, CodecKind } from "./ifaces";
import { ReadBuffer, WriteBuffer } from "../buffer";

@@ -28,2 +28,5 @@ export declare class ObjectCodec extends Codec implements ICodec {

decode(buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getSubcodecsNames(): string[];
getKind(): CodecKind;
}

@@ -66,3 +66,12 @@ "use strict";

}
getSubcodecs() {
return Array.from(this.codecs);
}
getSubcodecsNames() {
return Array.from(this.names);
}
getKind() {
return "object";
}
}
exports.ObjectCodec = ObjectCodec;

@@ -20,6 +20,13 @@ /*!

import { ICodec, uuid } from "./ifaces";
interface StringCodecSpec {
decimal?: boolean;
bigint?: boolean;
int64?: boolean;
}
export declare class CodecsRegistry {
private codecsBuildCache;
private codecs;
private customScalarCodecs;
constructor();
setStringCodecs({ decimal, bigint, int64 }?: StringCodecSpec): void;
hasCodec(typeId: uuid): boolean;

@@ -30,1 +37,2 @@ getCodec(typeId: uuid): ICodec | null;

}
export {};

@@ -24,3 +24,6 @@ "use strict";

const codecs_1 = require("./codecs");
const consts_1 = require("./consts");
const tuple_1 = require("./tuple");
const numerics = require("./numerics");
const numbers = require("./numbers");
const array_1 = require("./array");

@@ -42,2 +45,5 @@ const namedtuple_1 = require("./namedtuple");

const CTYPE_ENUM = 7;
const DECIMAL_TYPEID = consts_1.KNOWN_TYPENAMES.get("std::decimal");
const BIGINT_TYPEID = consts_1.KNOWN_TYPENAMES.get("std::bigint");
const INT64_TYPEID = consts_1.KNOWN_TYPENAMES.get("std::int64");
class CodecsRegistry {

@@ -47,3 +53,24 @@ constructor() {

this.codecsBuildCache = new lru_1.default({ capacity: CODECS_BUILD_CACHE_SIZE });
this.customScalarCodecs = new Map();
}
setStringCodecs({ decimal, bigint, int64 } = {}) {
if (decimal) {
this.customScalarCodecs.set(DECIMAL_TYPEID, new numerics.DecimalStringCodec(DECIMAL_TYPEID));
}
else {
this.customScalarCodecs.delete(DECIMAL_TYPEID);
}
if (bigint) {
this.customScalarCodecs.set(BIGINT_TYPEID, new numerics.BigIntStringCodec(BIGINT_TYPEID));
}
else {
this.customScalarCodecs.delete(BIGINT_TYPEID);
}
if (int64) {
this.customScalarCodecs.set(INT64_TYPEID, new numbers.Int64StringCodec(INT64_TYPEID));
}
else {
this.customScalarCodecs.delete(INT64_TYPEID);
}
}
hasCodec(typeId) {

@@ -53,3 +80,3 @@ if (this.codecs.has(typeId)) {

}
return typeId === codecs_1.NULL_CODEC_ID || typeId === tuple_1.EMPTY_TUPLE_CODEC_ID;
return typeId === consts_1.NULL_CODEC_ID || typeId === tuple_1.EMPTY_TUPLE_CODEC_ID;
}

@@ -64,3 +91,3 @@ getCodec(typeId) {

}
if (typeId === codecs_1.NULL_CODEC_ID) {
if (typeId === consts_1.NULL_CODEC_ID) {
return codecs_1.NULL_CODEC;

@@ -160,6 +187,10 @@ }

case CTYPE_BASE_SCALAR: {
res = this.customScalarCodecs.get(tid);
if (res != null) {
break;
}
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)}`);
if (consts_1.KNOWN_TYPES.has(tid)) {
throw new Error(`no JS codec for ${consts_1.KNOWN_TYPES.get(tid)}`);
}

@@ -275,4 +306,4 @@ throw new Error(`node JS codec for the type with ID ${uuid_1.UUID.fromString(tid)}`);

if (res == null) {
if (codecs_1.KNOWN_TYPES.has(tid)) {
throw new Error(`could not build a codec for ${codecs_1.KNOWN_TYPES.get(tid)} type`);
if (consts_1.KNOWN_TYPES.has(tid)) {
throw new Error(`could not build a codec for ${consts_1.KNOWN_TYPES.get(tid)} type`);
}

@@ -279,0 +310,0 @@ else {

@@ -18,3 +18,3 @@ /*!

*/
import { ICodec, Codec, uuid } from "./ifaces";
import { ICodec, Codec, uuid, CodecKind } from "./ifaces";
import { WriteBuffer, ReadBuffer } from "../buffer";

@@ -28,2 +28,4 @@ export declare class SetCodec extends Codec implements ICodec {

private decodeSet;
getSubcodecs(): ICodec[];
getKind(): CodecKind;
}

@@ -101,3 +101,9 @@ "use strict";

}
getSubcodecs() {
return [this.subCodec];
}
getKind() {
return "set";
}
}
exports.SetCodec = SetCodec;

@@ -19,3 +19,3 @@ /*!

/// <reference types="node" />
import { ICodec, Codec, uuid, IArgsCodec } from "./ifaces";
import { ICodec, Codec, uuid, IArgsCodec, CodecKind } from "./ifaces";
import { ReadBuffer, WriteBuffer } from "../buffer";

@@ -28,2 +28,4 @@ export declare class TupleCodec extends Codec implements ICodec, IArgsCodec {

decode(buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getKind(): CodecKind;
}

@@ -34,4 +36,6 @@ export declare class EmptyTupleCodec extends Codec implements ICodec {

decode(buf: ReadBuffer): any;
getSubcodecs(): ICodec[];
getKind(): CodecKind;
}
export declare const EMPTY_TUPLE_CODEC_ID: string;
export declare const EMPTY_TUPLE_CODEC: EmptyTupleCodec;

@@ -20,3 +20,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const codecs_1 = require("./codecs");
const consts_1 = require("./consts");
const ifaces_1 = require("./ifaces");

@@ -92,2 +92,8 @@ const buffer_1 = require("../buffer");

}
getSubcodecs() {
return Array.from(this.subCodecs);
}
getKind() {
return "tuple";
}
}

@@ -113,2 +119,8 @@ exports.TupleCodec = TupleCodec;

}
getSubcodecs() {
return [];
}
getKind() {
return "tuple";
}
}

@@ -120,3 +132,3 @@ exports.EmptyTupleCodec = EmptyTupleCodec;

.unwrap();
exports.EMPTY_TUPLE_CODEC_ID = codecs_1.KNOWN_TYPENAMES.get("empty-tuple");
exports.EMPTY_TUPLE_CODEC_ID = consts_1.KNOWN_TYPENAMES.get("empty-tuple");
exports.EMPTY_TUPLE_CODEC = new EmptyTupleCodec(exports.EMPTY_TUPLE_CODEC_ID);

@@ -18,2 +18,3 @@ /*!

*/
/// <reference types="node" />
interface Inspect {

@@ -25,1 +26,2 @@ (...args: any): null;

export { inspect };
export declare function decodeInt64ToString(buf: Buffer): string;

@@ -30,1 +30,26 @@ "use strict";

}
function decodeInt64ToString(buf) {
if (buf.length !== 8) {
throw new Error("expected 8 bytes buffer");
}
let inp = Array.from(buf);
let negative = false;
if (inp[0] & 0x80) {
inp = inp.map((x) => x ^ 0xff);
inp[inp.length - 1]++;
negative = true;
}
let result = "0";
for (const digit of inp) {
let acc = digit;
let ret = "";
for (let j = result.length - 1; j >= 0; j--) {
const num = parseInt(result[j], 10) * 256 + acc;
ret = (num % 10) + ret;
acc = Math.floor(num / 10);
}
result = acc ? acc + ret : ret;
}
return negative ? `-${result}` : result;
}
exports.decodeInt64ToString = decodeInt64ToString;

@@ -21,2 +21,3 @@ "use strict";

const compat_1 = require("../compat");
const bi = require("../bigint");
const dateutil_1 = require("./dateutil");

@@ -186,5 +187,4 @@ exports.DATE_PRIVATE = Symbol.for("edgedb.datetime");

class Duration {
constructor(milliseconds = 0, microseconds = BigInt(0)) {
this._microseconds =
BigInt(Math.floor(milliseconds * 1000)) + microseconds;
constructor(milliseconds = 0, microseconds = bi.make(0)) {
this._microseconds = bi.add(bi.make(Math.floor(milliseconds * 1000)), microseconds);
}

@@ -206,4 +206,4 @@ static fromMicroseconds(microseconds) {

const micros = this._microseconds;
const bint_hour = micros / BigInt(3600000000);
let time = Number(micros - bint_hour * BigInt(3600000000));
const bint_hour = bi.div(micros, bi.make(3600000000));
let time = Number(bi.sub(micros, bi.mul(bint_hour, bi.make(3600000000))));
const hour = Number(bint_hour);

@@ -210,0 +210,0 @@ const tfrac = Math.trunc(time / 60000000);

@@ -25,2 +25,3 @@ /*!

export * from "./errors";
import * as codecs from "./codecs/ifaces";
import * as reg from "./codecs/registry";

@@ -32,1 +33,4 @@ import * as buf from "./buffer";

export declare const _introspect: typeof introspect.introspect;
export declare type _ICodec = codecs.ICodec;
import { plugJSBI } from "./bigint";
export declare const _plugJSBI: typeof plugJSBI;

@@ -39,1 +39,3 @@ "use strict";

exports._introspect = introspect.introspect;
const bigint_1 = require("./bigint");
exports._plugJSBI = bigint_1.plugJSBI;

@@ -175,2 +175,196 @@ "use strict";

});
test("fetch: decimal as string", async () => {
const con = await testbase_1.asyncConnect();
const registry = con.codecsRegistry;
registry.setStringCodecs({ decimal: true });
const vals = [
"0.001",
"0.001000",
"1.0",
"1.00000",
"0.00000000000000",
"1.00000000000000",
"-1.00000000000000",
"-2.00000000000000",
"1000000000000000.00000000000000",
"1234000000.00088883231",
"1234.00088883231",
"3123.23111",
"-3123000000.23111",
"3123.2311100000",
"-03123.0023111",
"3123.23111",
"3123.23111",
"10000.23111",
"100000.23111",
"1000000.23111",
"10000000.23111",
"100000000.23111",
"1000000000.23111",
"1000000000.3111",
"1000000000.111",
"1000000000.11",
"100000000.0",
"10000000.0",
"1000000.0",
"100000.0",
"10000.0",
"1000.0",
"100.0",
"100",
"100.1",
"100.12",
"100.123",
"100.1234",
"100.12345",
"100.123456",
"100.1234567",
"100.12345679",
"100.123456790",
"100.123456790000000000000000",
"1.0",
"0.0",
"-1.0",
"1.0E-1000",
"1E1000",
"0.000000000000000000000000001",
"0.000000000000010000000000001",
"0.00000000000000000000000001",
"0.00000000100000000000000001",
"0.0000000000000000000000001",
"0.000000000000000000000001",
"0.00000000000000000000001",
"0.0000000000000000000001",
"0.000000000000000000001",
"0.00000000000000000001",
"0.0000000000000000001",
"0.000000000000000001",
"0.00000000000000001",
"0.0000000000000001",
"0.000000000000001",
"0.00000000000001",
"0.0000000000001",
"0.000000000001",
"0.00000000001",
"0.0000000001",
"0.000000001",
"0.00000001",
"0.0000001",
"0.000001",
"0.00001",
"0.0001",
"0.001",
"0.01",
"0.1",
"-0.000000001",
"-0.00000001",
"-0.0000001",
"-0.000001",
"-0.00001",
"-0.0001",
"-0.001",
"-0.01",
"-0.1",
"0.10",
"0.100",
"0.1000",
"0.10000",
"0.100000",
"0.00001000",
"0.000010000",
"0.0000100000",
"0.00001000000",
"-0.10",
"-0.100",
"-0.1000",
"-0.10000",
"-0.100000",
"-0.00001000",
"-0.000010000",
"-0.0000100000",
"-0.00001000000",
"1" + "0".repeat(117) + "." + "0".repeat(161),
];
try {
const fetched = await con.fetchOne(`
WITH
inp := <array<str>>$0,
dec := <array<decimal>>inp,
SELECT
(<array<str>>dec, dec)
`, [vals]);
expect(fetched[0].length).toBe(vals.length);
for (let i = 0; i < fetched[0].length; i++) {
expect(fetched[0][i]).toBe(fetched[1][i]);
}
}
finally {
await con.close();
}
});
test("fetch: int64 as string", async () => {
const con = await testbase_1.asyncConnect();
const registry = con.codecsRegistry;
registry.setStringCodecs({ int64: true });
const vals = [
"0",
"-0",
"1",
"-1",
"11",
"-11",
"110000",
"-1100000",
"113",
"1152921504594725865",
"-1152921504594725865",
];
try {
const fetched = await con.fetchOne(`
WITH
inp := <array<str>>$0,
dec := <array<int64>>inp,
SELECT
(<array<str>>dec, dec)
`, [vals]);
expect(fetched[0].length).toBe(vals.length);
for (let i = 0; i < fetched[0].length; i++) {
expect(fetched[0][i]).toBe(fetched[1][i]);
}
}
finally {
await con.close();
}
});
test("fetch: bigint as string", async () => {
const con = await testbase_1.asyncConnect();
const registry = con.codecsRegistry;
registry.setStringCodecs({ bigint: true });
const vals = [
"0",
"-0",
"1",
"-1",
"11",
"-11",
"11001200000031231238172638172637981268371628312300000000",
"-11001231231238172638172637981268371628312300",
];
try {
const fetched = await con.fetchOne(`
WITH
inp := <array<str>>$0,
dec := <array<bigint>>inp,
SELECT
(<array<str>>dec, dec)
`, [vals]);
expect(fetched[0].length).toBe(vals.length);
for (let i = 0; i < fetched[0].length; i++) {
expect(fetched[0][i]).toBe(fetched[1][i]);
}
}
finally {
await con.close();
}
});
test("fetch: positional args", async () => {

@@ -177,0 +371,0 @@ const con = await testbase_1.asyncConnect();

@@ -13,3 +13,3 @@ {

},
"version": "0.7.2",
"version": "0.7.3",
"main": "./dist/src/index.node.js",

@@ -16,0 +16,0 @@ "types": "./dist/src/index.node.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc