Skip to content

Commit f6f44f1

Browse files
author
Dijana Pavlovic
authored
Add support for protocol v2 (#1091)
1 parent 51eca53 commit f6f44f1

File tree

15 files changed

+267
-47
lines changed

15 files changed

+267
-47
lines changed

packages/driver/buildDeno.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ await run({
1212
destDir: "../deno",
1313
destEntriesToClean: ["_src", "mod.ts"],
1414
sourceFilter: (path) => {
15-
return !/cli\.mts$/.test(path);
15+
return !path.endsWith("cli.mts");
1616
},
1717
pathRewriteRules: [
1818
{ match: /^src\/index.node.ts$/, replace: "mod.ts" },
19+
{ match: /^src\/deno.json$/, replace: "deno.json" },
1920
{ match: /^src\//, replace: "_src/" },
2021
],
2122
injectImports: [
@@ -28,7 +29,7 @@ await run({
2829
from: "src/globals.deno.ts",
2930
},
3031
],
31-
}).then(async () =>
32+
}).then(() =>
3233
run({
3334
sourceDir: "./test",
3435
destDir: "../deno/test",

packages/driver/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"build:cli": "tsc --project tsconfig.cli.json",
4747
"build:cjs": "tsc --project tsconfig.json",
4848
"build:deno": "deno run --unstable --allow-all ./buildDeno.ts",
49-
"lint:fix": "tslint 'packages/*/src/**/*.ts'",
49+
"lint": "eslint --quiet",
50+
"lint:fix": "eslint --fix",
5051
"test": "NODE_OPTIONS='--experimental-global-webcrypto' npx jest --detectOpenHandles",
5152
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
5253
"gen-errors": "edb gen-errors-json --client | node genErrors.mjs",

packages/driver/src/baseConn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import LRU from "./primitives/lru";
4545
import type { SerializedSessionState } from "./options";
4646
import { Session } from "./options";
4747

48-
export const PROTO_VER: ProtocolVersion = [1, 0];
48+
export const PROTO_VER: ProtocolVersion = [2, 0];
4949
export const PROTO_VER_MIN: ProtocolVersion = [0, 9];
5050

5151
enum TransactionStatus {

packages/driver/src/codecs/array.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ import { NamedTupleCodec } from "./namedtuple";
2727
export class ArrayCodec extends Codec implements ICodec {
2828
private subCodec: ICodec;
2929
private len: number;
30-
31-
constructor(tid: uuid, subCodec: ICodec, len: number) {
30+
public typeName: string | null;
31+
32+
constructor(
33+
tid: uuid,
34+
typeName: string | null,
35+
subCodec: ICodec,
36+
len: number,
37+
) {
3238
super(tid);
3339
this.subCodec = subCodec;
3440
this.len = len;
41+
this.typeName = typeName;
3542
}
3643

3744
encode(buf: WriteBuffer, obj: any): void {

packages/driver/src/codecs/codecs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ export const INVALID_CODEC = new NullCodec(INVALID_CODEC_ID);
8080

8181
function registerScalarCodec(
8282
typename: string,
83-
type: new (tid: uuid) => ICodec,
83+
type: new (tid: uuid, typename: string | null) => ICodec,
8484
): void {
8585
const id = KNOWN_TYPENAMES.get(typename);
8686
if (id == null) {
8787
throw new InternalClientError("unknown type name");
8888
}
8989

90-
SCALAR_CODECS.set(id, new type(id));
90+
SCALAR_CODECS.set(id, new type(id, typename));
9191
}
9292

9393
registerScalarCodec("std::int16", Int16Codec);

packages/driver/src/codecs/enum.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ import { StrCodec } from "./text";
2222
export class EnumCodec extends StrCodec implements ICodec {
2323
readonly values: string[];
2424

25-
constructor(tid: uuid, derivedFromTid: uuid | null = null, values: string[]) {
26-
super(tid, derivedFromTid);
25+
constructor(
26+
tid: uuid,
27+
typeName: string | null,
28+
derivedFromTid: uuid | null = null,
29+
values: string[],
30+
) {
31+
super(tid, typeName, derivedFromTid);
2732
this.values = values;
2833
}
2934
}

packages/driver/src/codecs/ifaces.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,24 @@ export abstract class ScalarCodec extends Codec {
7070
private derivedFromTid: uuid | null = null;
7171
private typeName: string | null = null;
7272

73-
constructor(tid: uuid, derivedFromTid: uuid | null = null) {
73+
constructor(
74+
tid: uuid,
75+
typeName: string | null,
76+
derivedFromTid: uuid | null = null,
77+
) {
7478
super(tid);
7579
this.derivedFromTid = derivedFromTid;
80+
this.typeName = typeName;
7681
}
7782

7883
/** @internal */
7984
setTypeName(typeName: string): void {
8085
this.typeName = typeName;
8186
}
8287

83-
derive(tid: uuid): Codec {
88+
derive(tid: uuid, typeName: string | null): Codec {
8489
const self = this.constructor;
85-
return new (self as any)(tid, this.tid) as Codec;
90+
return new (self as any)(tid, this.tid, typeName) as Codec;
8691
}
8792

8893
getSubcodecs(): ICodec[] {

packages/driver/src/codecs/namedtuple.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ export class NamedTupleCodec extends Codec implements ICodec, IArgsCodec {
3232
private subCodecs: ICodec[];
3333
private names: string[];
3434
private namesSet: Set<string>;
35-
36-
constructor(tid: uuid, codecs: ICodec[], names: string[]) {
35+
public typeName: string | null;
36+
37+
constructor(
38+
tid: uuid,
39+
typeName: string | null,
40+
codecs: ICodec[],
41+
names: string[],
42+
) {
3743
super(tid);
3844
this.subCodecs = codecs;
3945
this.names = names;
4046
this.namesSet = new Set(names);
47+
this.typeName = typeName;
4148
}
4249

4350
encode(buf: WriteBuffer, object: any): void {

packages/driver/src/codecs/range.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ export class RangeCodec extends Codec implements ICodec {
9797
readonly tsModule = "edgedb";
9898

9999
private subCodec: ICodec;
100+
readonly typeName: string | null;
100101

101-
constructor(tid: uuid, subCodec: ICodec) {
102+
constructor(tid: uuid, typeName: string | null, subCodec: ICodec) {
102103
super(tid);
103104
this.subCodec = subCodec;
105+
this.typeName = typeName;
104106
}
105107

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

127129
private subCodec: ICodec;
130+
public typeName: string | null;
128131

129-
constructor(tid: uuid, subCodec: ICodec) {
132+
constructor(tid: uuid, typeName: string | null, subCodec: ICodec) {
130133
super(tid);
131134
this.subCodec = subCodec;
135+
this.typeName = typeName;
132136
}
133137

134138
encode(buf: WriteBuffer, obj: any): void {

0 commit comments

Comments
 (0)