Skip to content

Commit a977bd7

Browse files
committed
Update to latest edgedb driver with new codec handling
1 parent d5af9e6 commit a977bd7

File tree

17 files changed

+165
-95
lines changed

17 files changed

+165
-95
lines changed

shared/common/components/resultGrid/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ export const ResultGridContent = observer(function ResultGridContent({
164164
indexOffset -
165165
rowIndex
166166
}
167-
data={header.name ? data[dataIndex][header.name] : data[dataIndex]}
167+
data={
168+
header.key != null
169+
? data[dataIndex][header.key]
170+
: data[dataIndex]
171+
}
168172
/>
169173
);
170174
dataIndex += 1;

shared/common/components/resultGrid/state.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {SetCodec} from "edgedb/dist/codecs/set";
44
import {DataGridState} from "../dataGrid/state";
55
import {assertNever} from "../../utils/assertNever";
66
import {NamedTupleCodec} from "edgedb/dist/codecs/namedtuple";
7+
import {RecordCodec} from "edgedb/dist/codecs/record";
78

89
export function createResultGridState(codec: ICodec, data: any[]) {
910
return new ResultGridState(codec, data);
@@ -15,6 +16,7 @@ export interface GridHeader {
1516
id: string;
1617
parent: GridHeader | null;
1718
name: string | null;
19+
key: string | number | null;
1820
multi: boolean;
1921
codec: ICodec;
2022
typename: string;
@@ -76,7 +78,7 @@ export class ResultGridState {
7678
? tops.findIndex((top) => top > offsetRowIndex) - 1
7779
: offsetRowIndex;
7880
return {
79-
data: parentData[dataIndex]?.[header.parent.name!] ?? [],
81+
data: parentData[dataIndex]?.[header.parent.key!] ?? [],
8082
indexOffset: indexOffset + (tops ? tops[dataIndex] : dataIndex),
8183
endIndex: indexOffset + (tops ? tops[dataIndex + 1] : dataIndex + 1),
8284
};
@@ -97,8 +99,8 @@ function _getRowTops(
9799
if (!header.multi) continue;
98100
const colHeight =
99101
header.subHeaders && header.subHeaders[0].name !== null
100-
? _getRowTops(topsMap, item[header.name!], header.subHeaders)
101-
: item[header.name!].length;
102+
? _getRowTops(topsMap, item[header.key!], header.subHeaders)
103+
: item[header.key!].length;
102104
if (colHeight > height) {
103105
height = colHeight;
104106
}
@@ -139,6 +141,7 @@ function _getHeaders(
139141
id: parent ? `${parent.id}.${field.name}` : field.name,
140142
parent,
141143
name: field.name,
144+
key: field.name,
142145
multi,
143146
codec: subcodec,
144147
typename: getTypename(subcodec),
@@ -165,6 +168,7 @@ function _getHeaders(
165168
id: `${header.id}.__multi__`,
166169
parent: header,
167170
name: null,
171+
key: null,
168172
multi: false,
169173
codec: subcodec,
170174
typename: getTypename(subcodec),
@@ -180,6 +184,31 @@ function _getHeaders(
180184
}
181185
}
182186
return {headers, colCount};
187+
} else if (codec instanceof RecordCodec) {
188+
const subcodecs = codec.getSubcodecs();
189+
const headers: GridHeader[] = [];
190+
let i = 0;
191+
const names = codec.getNames();
192+
for (const name of names) {
193+
const subcodec = subcodecs[i];
194+
const startIndex = indexStart + i;
195+
const header: GridHeader = {
196+
id: name,
197+
parent,
198+
name: name,
199+
key: i,
200+
multi: false,
201+
codec: subcodec,
202+
typename: getTypename(subcodec),
203+
depth,
204+
startIndex,
205+
span: 1,
206+
subHeaders: null,
207+
};
208+
headers.push(header);
209+
i++;
210+
}
211+
return {headers, colCount: headers.length};
183212
}
184213
throw new Error(`unexpected codec kind: ${codec.getKind()}`);
185214
}
@@ -197,6 +226,7 @@ function getTypename(codec: ICodec): string {
197226
case "scalar":
198227
case "object":
199228
case "sparse_object":
229+
case "record":
200230
return codec.getKnownTypeName();
201231
case "array":
202232
case "range":

shared/common/decodeRawBuffer/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {_CodecsRegistry, _ReadBuffer, _ICodec} from "edgedb";
1+
import {_CodecsRegistry, _ReadBuffer, _ICodec, Options} from "edgedb";
22
import type {ProtocolVersion} from "edgedb/dist/ifaces";
33

44
export type EdgeDBSet = Array<any> & {_codec: _ICodec};
@@ -7,6 +7,7 @@ export function decode(
77
registry: InstanceType<typeof _CodecsRegistry>,
88
outCodecBuf: Uint8Array,
99
resultBuf: Uint8Array,
10+
options: Options,
1011
protocolVersion: ProtocolVersion = [0, 10]
1112
): EdgeDBSet | null {
1213
let result: EdgeDBSet | null = null;
@@ -28,7 +29,7 @@ export function decode(
2829

2930
buf.sliceInto(codecReadBuf, len - 4);
3031
codecReadBuf.discard(6);
31-
const val = codec.decode(codecReadBuf);
32+
const val = codec.decode(codecReadBuf, options.makeCodecContext());
3233
result.push(val);
3334
}
3435

shared/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"private": true,
55
"peerDependencies": {
6-
"edgedb": "1.6.0-canary.20241206T104839",
6+
"edgedb": "1.6.0-canary.20250111T054901",
77
"react": "^18.0.0",
88
"react-dom": "^18.0.0"
99
},

shared/inspector/buildItem.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {_ICodec} from "edgedb";
44
import {CodecKind} from "edgedb/dist/codecs/ifaces";
55
import {ObjectCodec} from "edgedb/dist/codecs/object";
66
import {NamedTupleCodec} from "edgedb/dist/codecs/namedtuple";
7+
import {RecordCodec} from "edgedb/dist/codecs/record";
78

89
import {buildScalarItem} from "./buildScalar";
910

@@ -16,6 +17,7 @@ export enum ItemType {
1617
Object,
1718
Tuple,
1819
NamedTuple,
20+
Record,
1921
Scalar,
2022
Other,
2123
}
@@ -40,7 +42,7 @@ export interface ArrayLikeItem extends _BaseItem {
4042
}
4143

4244
export interface ObjectLikeItem extends _BaseItem {
43-
type: ItemType.Object | ItemType.NamedTuple;
45+
type: ItemType.Object | ItemType.NamedTuple | ItemType.Record;
4446
data: {[key: string]: any};
4547
closingBracket: Item;
4648
}
@@ -299,12 +301,16 @@ export function expandItem(
299301
}
300302
break;
301303
case ItemType.NamedTuple:
304+
case ItemType.Record:
302305
{
303-
const fieldNames = (item.codec as NamedTupleCodec).getNames();
306+
const fieldNames = (
307+
item.codec as NamedTupleCodec | RecordCodec
308+
).getNames();
309+
const isRecord = item.type === ItemType.Record;
304310
const subCodecs = item.codec.getSubcodecs();
305311

306312
childItems = fieldNames.flatMap((fieldName, i) => {
307-
const data = item.data[fieldName];
313+
const data = item.data[isRecord ? i : fieldName];
308314

309315
const id = `${item.id}.${i}`;
310316

@@ -317,13 +323,13 @@ export function expandItem(
317323
label: (
318324
<>
319325
{fieldName}
320-
<span> := </span>
326+
<span>{isRecord ? ": " : " := "}</span>
321327
</>
322328
),
323329
fieldName: fieldName,
324330
},
325331
data,
326-
fieldName,
332+
isRecord ? i : fieldName,
327333
state.noMultiline,
328334
i < item.data.length - 1
329335
);
@@ -363,6 +369,7 @@ const itemTypes: {
363369
object: {type: ItemType.Object, brackets: "{}"},
364370
tuple: {type: ItemType.Tuple, brackets: "()"},
365371
namedtuple: {type: ItemType.NamedTuple, brackets: "()"},
372+
record: {type: ItemType.Record, brackets: "()"},
366373
scalar: {type: ItemType.Scalar, brackets: ""},
367374
};
368375

shared/inspector/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"license": "UNLICENSED",
66
"peerDependencies": {
7-
"edgedb": "1.6.0-canary.20241206T104839",
7+
"edgedb": "1.6.0-canary.20250111T054901",
88
"react": "^18.0.0",
99
"react-dom": "^18.0.0"
1010
},

shared/inspector/renderJsonResult.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export function _renderToJson(
9090
.join(",\n")}\n${depth}]`;
9191
}
9292
case "object":
93-
case "namedtuple": {
93+
case "namedtuple":
94+
case "record": {
9495
const subcodecs = codec.getSubcodecs();
9596
const explicitNum =
9697
codecKind === "object"
@@ -114,7 +115,7 @@ export function _renderToJson(
114115
depth +
115116
` "${fieldName}": ` +
116117
_renderToJson(
117-
val[fieldName],
118+
codecKind === "record" ? val[i] : val[fieldName],
118119
subcodecs[i],
119120
depth + " ",
120121
implicitLimit

shared/schemaGraph/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"license": "UNLICENSED",
66
"peerDependencies": {
7-
"edgedb": "1.6.0-canary.20241206T104839",
7+
"edgedb": "1.6.0-canary.20250111T054901",
88
"react": "^18.0.0",
99
"react-dom": "^18.0.0"
1010
},

shared/studio/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"react-window": "^1.8.10"
3030
},
3131
"peerDependencies": {
32-
"edgedb": "1.6.0-canary.20241206T104839",
32+
"edgedb": "1.6.0-canary.20250111T054901",
3333
"react": "^18.0.0",
3434
"react-dom": "^18.0.0"
3535
},

shared/studio/state/connection.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "mobx-keystone";
1111

1212
import {AuthenticationError} from "edgedb";
13-
import {Session} from "edgedb/dist/options";
13+
import {Options} from "edgedb/dist/options";
1414
import LRU from "edgedb/dist/primitives/lru";
1515
import {Capabilities} from "edgedb/dist/baseConn";
1616
import {AdminUIFetchConnection} from "edgedb/dist/fetchConn";
@@ -28,6 +28,7 @@ import {
2828
EdgeDBSet,
2929
QueryParams,
3030
codecsRegistry,
31+
baseOptions,
3132
} from "../utils/decodeRawBuffer";
3233
import {instanceCtx} from "./instance";
3334
import {sessionStateCtx} from "./sessionState";
@@ -121,13 +122,12 @@ export function createAuthenticatedFetch({
121122
};
122123
}
123124

124-
function setQueryTag(session: Session, tag: string) {
125-
session = new Session({...session});
126-
(session as any).annotations = new Map<string, string>(
127-
(session as any).annotations
128-
);
129-
(session as any).annotations.set("tag", tag);
130-
return session;
125+
function setQueryTag(options: Options, tag: string) {
126+
const annos = new Map((options as any).annotations as Map<string, string>);
127+
annos.set("tag", tag);
128+
const clone = (options as any)._cloneWith({});
129+
clone.annotations = annos;
130+
return clone as Options;
131131
}
132132

133133
@model("Connection")
@@ -154,7 +154,7 @@ export class Connection extends Model({
154154
get _state() {
155155
const sessionState = sessionStateCtx.get(this);
156156

157-
let state = Session.defaults();
157+
let state = baseOptions;
158158

159159
if (sessionState?.activeState.globals.length) {
160160
state = state.withGlobals(
@@ -283,10 +283,7 @@ export class Connection extends Model({
283283
let state = this._state;
284284

285285
if (opts.ignoreSessionConfig) {
286-
state = setQueryTag(
287-
Session.defaults().withGlobals(state.globals),
288-
"gel/ui"
289-
);
286+
state = setQueryTag(baseOptions.withGlobals(state.globals), "gel/ui");
290287
}
291288
if (opts.ignoreForceDatabaseError) {
292289
state = state.withConfig({force_database_error: "false"});
@@ -408,6 +405,7 @@ export class Connection extends Model({
408405
result: decode(
409406
outCodecBuf,
410407
resultBuf,
408+
state,
411409
this.conn.protocolVersion,
412410
opts.newCodec
413411
),

shared/studio/state/instance.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
import {AuthenticationError} from "edgedb";
1919

20-
import {Session} from "edgedb/dist/options";
20+
import {Options} from "edgedb/dist/options";
2121
import {AdminUIFetchConnection} from "edgedb/dist/fetchConn";
2222
import {OutputFormat, Cardinality} from "edgedb/dist/ifaces";
2323
import {codecsRegistry} from "../utils/decodeRawBuffer";
@@ -94,7 +94,7 @@ export class InstanceState extends Model({
9494
null,
9595
OutputFormat.BINARY,
9696
cardinality,
97-
Session.defaults()
97+
Options.defaults()
9898
)
9999
).result;
100100
}

shared/studio/tabs/queryEditor/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {ICodec} from "edgedb/dist/codecs/ifaces";
6969
import {SplitViewDirection} from "@edgedb/common/ui/splitView/model";
7070
import {createPortal} from "react-dom";
7171
import {RelativeTime} from "@edgedb/common/utils/relativeTime";
72+
import {RecordCodec} from "edgedb/dist/codecs/record";
7273

7374
export const QueryEditorView = observer(function QueryEditorView() {
7475
const editorState = useTabState(QueryEditor);
@@ -550,7 +551,8 @@ export function outputModeToggle(
550551
outputMode: OutputMode,
551552
setOutputMode: (mode: OutputMode) => void
552553
) {
553-
const tableOutputAvailable = codec instanceof ObjectCodec;
554+
const tableOutputAvailable =
555+
codec instanceof ObjectCodec || codec instanceof RecordCodec;
554556
const mode = tableOutputAvailable ? outputMode : OutputMode.Tree;
555557

556558
return {

shared/studio/tabs/queryEditor/state/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
QueryResultData,
3131
} from "../../../idbStore";
3232

33-
import {EdgeDBSet, decode} from "../../../utils/decodeRawBuffer";
33+
import {EdgeDBSet, baseOptions, decode} from "../../../utils/decodeRawBuffer";
3434
import {
3535
ErrorDetails,
3636
extractErrorDetails,
@@ -416,6 +416,7 @@ export class QueryEditor extends Model({
416416
? decode(
417417
resultData.outCodecBuf,
418418
resultData.resultBuf,
419+
baseOptions,
419420
resultData.protoVer ?? [1, 0]
420421
)
421422
: null

shared/studio/tabs/repl/state/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
extractErrorDetails,
2323
} from "../../../utils/extractErrorDetails";
2424
import {InspectorState, Item} from "@edgedb/inspector/state";
25-
import {decode, EdgeDBSet} from "../../../utils/decodeRawBuffer";
25+
import {baseOptions, decode, EdgeDBSet} from "../../../utils/decodeRawBuffer";
2626
import {CommandResult, handleSlashCommand} from "./commands";
2727
import {
2828
clearReplHistory,
@@ -326,6 +326,7 @@ export class Repl extends Model({
326326
? decode(
327327
resultData.outCodecBuf,
328328
resultData.resultBuf,
329+
baseOptions,
329330
resultData.protoVer ?? [1, 0]
330331
)
331332
: null

0 commit comments

Comments
 (0)