Skip to content

Commit

Permalink
fix: loosen json object constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Jun 6, 2023
1 parent e020ffc commit 44b88ae
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/dump/json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonObject } from "@bufbuild/protobuf";
import type { JsonObject } from "../model";
import * as model from "../model/index.js";
import { aif as dumpAif } from "./aif.js";
import { protobuf as dumpProtobuf } from "./protobuf.js";
Expand All @@ -8,7 +8,7 @@ export function json(
format: "aif" | "arguebuf"
): JsonObject {
if (format === "aif") {
return dumpAif(graph) as unknown as JsonObject;
return dumpAif(graph);
}

return dumpProtobuf(graph).toJson() as JsonObject;
Expand Down
4 changes: 2 additions & 2 deletions src/load/json.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { JsonObject } from "@bufbuild/protobuf";
import * as protoModel from "arg-services/graph/v1/graph_pb";
import type { JsonObject } from "../model";
import * as model from "../model/index.js";
import * as schemas from "../schemas/index.js";
import { aif as loadAif } from "./aif.js";
import { protobuf as loadProtobuf } from "./protobuf.js";

export function json(graph: JsonObject): model.Graph {
if (graph.locutions !== undefined) {
return loadAif(graph as unknown as schemas.aif.Graph);
return loadAif(graph as schemas.aif.Graph);
}

return loadProtobuf(protoModel.Graph.fromJson(graph));
Expand Down
2 changes: 1 addition & 1 deletion src/load/protobuf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { JsonObject } from "@bufbuild/protobuf";
import * as pb from "arg-services/graph/v1/graph_pb";
import * as date from "../date.js";
import type { JsonObject } from "../model";
import * as model from "../model/index.js";

function metadataFromProtobuf(obj?: pb.Metadata): model.Metadata | undefined {
Expand Down
1 change: 1 addition & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./reference.js";
export * from "./resource.js";
export * from "./userdata.js";
export { uuid } from "./utils.js";
export type { JsonObject } from "./utils.js";
2 changes: 1 addition & 1 deletion src/model/userdata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonObject } from "@bufbuild/protobuf";
import type { JsonObject } from "../model";

export type Userdata = JsonObject;
export type UserdataInterface = JsonObject;
2 changes: 1 addition & 1 deletion src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Mutable<T> = {
export type Mapping<T extends string | number | symbol, U> = {
[key in T]: U;
};

export type JsonObject = any;
export type PartiallyRequired<T, K extends keyof T> = Pick<T, K> &
Partial<Omit<T, K>>;
export type PartiallyOptional<T, K extends keyof T> = Pick<T, K> &
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/sadface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonObject } from "@bufbuild/protobuf";
import type { JsonObject } from "../model";

export interface Graph {
nodes: Array<Node>;
Expand Down
4 changes: 1 addition & 3 deletions test/ova.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import ovaGraph from "../data/arguebase-private/recap/format=ova,lang=de/Hamburg
import * as arguebuf from "../src/index.js";

test("graph: ova2arguebuf", () => {
const g = arguebuf.load.ova(
ovaGraph as unknown as arguebuf.schemas.ova.Graph
);
const g = arguebuf.load.ova(ovaGraph as arguebuf.schemas.ova.Graph);

// Test some graph properties
assertType<arguebuf.Graph>(g);
Expand Down

0 comments on commit 44b88ae

Please # to comment.