Skip to content

Commit

Permalink
Build from edgedb-js e3676c4035f184a27375bd24b85568e6c55b0071
Browse files Browse the repository at this point in the history
  • Loading branch information
edgedb-ci committed Mar 25, 2022
1 parent 4641000 commit e2f5db9
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 483 deletions.
9 changes: 3 additions & 6 deletions _src/codecs/namedtuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import {Buffer} from "../globals.deno.ts";
import {ICodec, Codec, uuid, IArgsCodec, CodecKind} from "./ifaces.ts";
import {ReadBuffer, WriteBuffer} from "../primitives/buffer.ts";
import {EmptyTupleCodec} from "./tuple.ts";
import {generateType, NamedTupleConstructor} from "../datatypes/namedtuple.ts";

export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
private subCodecs: ICodec[];
private tupleCls: NamedTupleConstructor;
private names: string[];
private namesSet: Set<string>;

Expand All @@ -34,7 +32,6 @@ export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
this.subCodecs = codecs;
this.names = names;
this.namesSet = new Set(names);
this.tupleCls = generateType(names);
}

encode(_buf: WriteBuffer, _object: any): void {
Expand Down Expand Up @@ -90,7 +87,6 @@ export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
decode(buf: ReadBuffer): any {
const els = buf.readUInt32();
const subCodecs = this.subCodecs;
const cls = this.tupleCls;
if (els !== subCodecs.length) {
throw new Error(
`cannot decode NamedTuple: expected ` +
Expand All @@ -99,7 +95,8 @@ export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
}

const elemBuf = ReadBuffer.alloc();
const result = new cls(els);
const names = this.names;
const result: any = {};
for (let i = 0; i < els; i++) {
buf.discard(4); // reserved
const elemLen = buf.readInt32();
Expand All @@ -109,7 +106,7 @@ export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
val = subCodecs[i].decode(elemBuf);
elemBuf.finish();
}
result[i] = val;
result[names[i]] = val;
}

return result;
Expand Down
12 changes: 3 additions & 9 deletions _src/codecs/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ import {Buffer} from "../globals.deno.ts";
import {ICodec, Codec, uuid, CodecKind} from "./ifaces.ts";
import {ReadBuffer, WriteBuffer} from "../primitives/buffer.ts";
import {ONE, AT_LEAST_ONE} from "./consts.ts";
import {
generateType,
ObjectConstructor,
EDGE_POINTER_IS_LINKPROP,
} from "../datatypes/object.ts";

const EDGE_POINTER_IS_LINKPROP = 1 << 1;

export class ObjectCodec extends Codec implements ICodec {
private codecs: ICodec[];
private names: string[];
private namesSet: Set<string>;
private cardinalities: number[];
private objectType: ObjectConstructor;

constructor(
tid: uuid,
Expand All @@ -56,7 +52,6 @@ export class ObjectCodec extends Codec implements ICodec {
this.names = newNames;
this.namesSet = new Set(newNames);
this.cardinalities = cards;
this.objectType = generateType(newNames, flags);
}

encode(_buf: WriteBuffer, _object: any): void {
Expand Down Expand Up @@ -163,7 +158,6 @@ export class ObjectCodec extends Codec implements ICodec {
decode(buf: ReadBuffer): any {
const codecs = this.codecs;
const names = this.names;
const objType = this.objectType;

const els = buf.readUInt32();
if (els !== codecs.length) {
Expand All @@ -173,7 +167,7 @@ export class ObjectCodec extends Codec implements ICodec {
}

const elemBuf = ReadBuffer.alloc();
const result: any = new objType();
const result: any = {};
for (let i = 0; i < els; i++) {
buf.discard(4); // reserved
const elemLen = buf.readInt32();
Expand Down
9 changes: 4 additions & 5 deletions _src/codecs/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import {ICodec, Codec, uuid, CodecKind} from "./ifaces.ts";
import {WriteBuffer, ReadBuffer} from "../primitives/buffer.ts";
import {ArrayCodec} from "./array.ts";
import {Set} from "../datatypes/set.ts";

export class SetCodec extends Codec implements ICodec {
private subCodec: ICodec;
Expand Down Expand Up @@ -48,7 +47,7 @@ export class SetCodec extends Codec implements ICodec {
buf.discard(4); // reserved

if (ndims === 0) {
return new Set(0);
return [];
}
if (ndims !== 1) {
throw new Error(`expected 1-dimensional array of records of arrays`);
Expand All @@ -58,7 +57,7 @@ export class SetCodec extends Codec implements ICodec {

buf.discard(4); // ignore the lower bound info

const result = new Set(len);
const result = new Array(len);
const elemBuf = ReadBuffer.alloc();
const subCodec = this.subCodec;

Expand Down Expand Up @@ -95,7 +94,7 @@ export class SetCodec extends Codec implements ICodec {
buf.discard(4); // reserved

if (ndims === 0) {
return new Set(0);
return [];
}
if (ndims !== 1) {
throw new Error(`invalid set dimensinality: ${ndims}`);
Expand All @@ -105,7 +104,7 @@ export class SetCodec extends Codec implements ICodec {

buf.discard(4); // ignore the lower bound info

const result = new Set(len);
const result = new Array(len);
const elemBuf = ReadBuffer.alloc();
const subCodec = this.subCodec;

Expand Down
16 changes: 2 additions & 14 deletions _src/codecs/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ import {KNOWN_TYPENAMES} from "./consts.ts";
import {ICodec, Codec, uuid, IArgsCodec, CodecKind} from "./ifaces.ts";
import {ReadBuffer, WriteBuffer} from "../primitives/buffer.ts";

import {
introspectMethod,
IntrospectableType,
CollectionInfo,
} from "../datatypes/introspect.ts";

class Tuple extends Array implements IntrospectableType {
[introspectMethod](): CollectionInfo {
return {kind: "tuple"};
}
}

export class TupleCodec extends Codec implements ICodec, IArgsCodec {
private subCodecs: ICodec[];

Expand Down Expand Up @@ -98,7 +86,7 @@ export class TupleCodec extends Codec implements ICodec, IArgsCodec {
}

const elemBuf = ReadBuffer.alloc();
const result = new Tuple(els);
const result = new Array(els);
for (let i = 0; i < els; i++) {
buf.discard(4); // reserved
const elemLen = buf.readInt32();
Expand Down Expand Up @@ -149,7 +137,7 @@ export class EmptyTupleCodec extends Codec implements ICodec {
`cannot decode empty Tuple: expected 0 elements, received ${els}`
);
}
return new Tuple();
return [];
}

getSubcodecs(): ICodec[] {
Expand Down
4 changes: 2 additions & 2 deletions _src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {ymd2ord, ord2ymd} from "./datatypes/dateutil.ts";
browser and NodeJS environments.
*/

/* We customize the `console.log()` rendering of EdgeDB objects
/* We customize the `console.log()` rendering of some EdgeDB objects
in NodeJS. In browsers, however, it's not possible to customize that,
so we're just creating a shell of "util.inspect" so that NodeJS code
can compile unchanged for the browser environment.
Expand Down Expand Up @@ -63,7 +63,7 @@ export function decodeInt64ToString(buf: Buffer): string {
throw new Error("expected 8 bytes buffer");
}

let inp: number[] = Array.from(buf);
let inp: number[] = Array.from(buf);

let negative = false;
if (inp[0] & 0x80) {
Expand Down
43 changes: 0 additions & 43 deletions _src/datatypes/introspect.ts

This file was deleted.

Loading

0 comments on commit e2f5db9

Please sign in to comment.