Skip to content

Commit

Permalink
Improved lens find interface output type (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
karelklima authored Nov 29, 2023
1 parent a8c90a4 commit 85c8529
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions library/lens/lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { decode } from "../decoder.ts";

import { QueryBuilder } from "./query_builder.ts";
import type { Entity } from "./types.ts";
import type { Entity, Unite } from "./types.ts";
import { QueryEngineProxy } from "../engine/query_engine_proxy.ts";

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Lens<
}

private decode(graph: Graph) {
return decode(graph, this.schema, this.context) as unknown as I[];
return decode(graph, this.schema, this.context) as unknown as Unite<I>[];
}

async count() {
Expand Down
8 changes: 5 additions & 3 deletions library/lens/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { SchemaInterfaceIdentity } from "../schema/mod.ts";

export type Entity<
T extends unknown = Record<string, unknown>,
> =
export type Entity<T extends unknown = Record<string, unknown>> =
& DeepPartial<T>
& SchemaInterfaceIdentity;

export type DeepPartial<T> = T extends Record<string, unknown>
? { [P in keyof T]?: DeepPartial<T[P]> }
: T;

export type Unite<T> = T extends Record<string, unknown>
? { [Key in keyof T]: T[Key] }
: T;
11 changes: 1 addition & 10 deletions library/schema/interface.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import type { SupportedDataTypes } from "./data_types.ts";
import type { PropertyPrototype, SchemaPrototype } from "./schema.ts";

type Prettify<T> =
& {
[K in keyof T]: T[K];
}
// deno-lint-ignore ban-types
& {};

type Unite<T> = T extends Record<string, unknown> ? {
[Key in keyof T]: T[Key];
}
type Unite<T> = T extends Record<string, unknown> ? { [Key in keyof T]: T[Key] }
: T;

type IsOptional<Property extends PropertyPrototype> = Property extends {
Expand Down

0 comments on commit 85c8529

Please sign in to comment.