Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for protocol v2 #1091

Merged
merged 9 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/driver/buildDeno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ await run({
destDir: "../deno",
destEntriesToClean: ["_src", "mod.ts"],
sourceFilter: (path) => {
return !/cli\.mts$/.test(path);
return !path.endsWith("cli.mts");
},
pathRewriteRules: [
{ match: /^src\/index.node.ts$/, replace: "mod.ts" },
{ match: /^src\/deno.json$/, replace: "deno.json" },
{ match: /^src\//, replace: "_src/" },
],
injectImports: [
Expand All @@ -28,7 +29,7 @@ await run({
from: "src/globals.deno.ts",
},
],
}).then(async () =>
}).then(() =>
run({
sourceDir: "./test",
destDir: "../deno/test",
Expand Down
3 changes: 2 additions & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"build:cli": "tsc --project tsconfig.cli.json",
"build:cjs": "tsc --project tsconfig.json",
"build:deno": "deno run --unstable --allow-all ./buildDeno.ts",
"lint:fix": "tslint 'packages/*/src/**/*.ts'",
"lint": "eslint --quiet",
"lint:fix": "eslint --fix",
"test": "NODE_OPTIONS='--experimental-global-webcrypto' npx jest --detectOpenHandles",
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"gen-errors": "edb gen-errors-json --client | node genErrors.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/baseConn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import LRU from "./primitives/lru";
import type { SerializedSessionState } from "./options";
import { Session } from "./options";

export const PROTO_VER: ProtocolVersion = [1, 0];
export const PROTO_VER: ProtocolVersion = [2, 0];
export const PROTO_VER_MIN: ProtocolVersion = [0, 9];

enum TransactionStatus {
Expand Down
11 changes: 9 additions & 2 deletions packages/driver/src/codecs/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ import { NamedTupleCodec } from "./namedtuple";
export class ArrayCodec extends Codec implements ICodec {
private subCodec: ICodec;
private len: number;

constructor(tid: uuid, subCodec: ICodec, len: number) {
public typeName: string | null;

constructor(
tid: uuid,
typeName: string | null,
subCodec: ICodec,
len: number,
) {
super(tid);
this.subCodec = subCodec;
this.len = len;
this.typeName = typeName;
}

encode(buf: WriteBuffer, obj: any): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/codecs/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ export const INVALID_CODEC = new NullCodec(INVALID_CODEC_ID);

function registerScalarCodec(
typename: string,
type: new (tid: uuid) => ICodec,
type: new (tid: uuid, typename: string | null) => ICodec,
): void {
const id = KNOWN_TYPENAMES.get(typename);
if (id == null) {
throw new InternalClientError("unknown type name");
}

SCALAR_CODECS.set(id, new type(id));
SCALAR_CODECS.set(id, new type(id, typename));
}

registerScalarCodec("std::int16", Int16Codec);
Expand Down
9 changes: 7 additions & 2 deletions packages/driver/src/codecs/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ import { StrCodec } from "./text";
export class EnumCodec extends StrCodec implements ICodec {
readonly values: string[];

constructor(tid: uuid, derivedFromTid: uuid | null = null, values: string[]) {
super(tid, derivedFromTid);
constructor(
tid: uuid,
typeName: string | null,
derivedFromTid: uuid | null = null,
values: string[],
) {
super(tid, typeName, derivedFromTid);
this.values = values;
}
}
11 changes: 8 additions & 3 deletions packages/driver/src/codecs/ifaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,24 @@ export abstract class ScalarCodec extends Codec {
private derivedFromTid: uuid | null = null;
private typeName: string | null = null;

constructor(tid: uuid, derivedFromTid: uuid | null = null) {
constructor(
tid: uuid,
typeName: string | null,
derivedFromTid: uuid | null = null,
) {
super(tid);
this.derivedFromTid = derivedFromTid;
this.typeName = typeName;
}

/** @internal */
setTypeName(typeName: string): void {
this.typeName = typeName;
}

derive(tid: uuid): Codec {
derive(tid: uuid, typeName: string | null): Codec {
const self = this.constructor;
return new (self as any)(tid, this.tid) as Codec;
return new (self as any)(tid, this.tid, typeName) as Codec;
}

getSubcodecs(): ICodec[] {
Expand Down
11 changes: 9 additions & 2 deletions packages/driver/src/codecs/namedtuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
private subCodecs: ICodec[];
private names: string[];
private namesSet: Set<string>;

constructor(tid: uuid, codecs: ICodec[], names: string[]) {
public typeName: string | null;

constructor(
tid: uuid,
typeName: string | null,
codecs: ICodec[],
names: string[],
) {
super(tid);
this.subCodecs = codecs;
this.names = names;
this.namesSet = new Set(names);
this.typeName = typeName;
}

encode(buf: WriteBuffer, object: any): void {
Expand Down
8 changes: 6 additions & 2 deletions packages/driver/src/codecs/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ export class RangeCodec extends Codec implements ICodec {
readonly tsModule = "edgedb";

private subCodec: ICodec;
readonly typeName: string | null;

constructor(tid: uuid, subCodec: ICodec) {
constructor(tid: uuid, typeName: string | null, subCodec: ICodec) {
super(tid);
this.subCodec = subCodec;
this.typeName = typeName;
}

encode(buf: WriteBuffer, obj: any) {
Expand All @@ -125,10 +127,12 @@ export class MultiRangeCodec extends Codec implements ICodec {
readonly tsModule = "edgedb";

private subCodec: ICodec;
public typeName: string | null;

constructor(tid: uuid, subCodec: ICodec) {
constructor(tid: uuid, typeName: string | null, subCodec: ICodec) {
super(tid);
this.subCodec = subCodec;
this.typeName = typeName;
}

encode(buf: WriteBuffer, obj: any): void {
Expand Down
Loading
Loading