// This file is a stripped down version of a full-implmentation of a global // query interface found here https://github.com/o-development/ldo-query/blob/main/lib/ShapeQuery.ts // If I ever want to implement a global query interface, this is a good place // to start. import type { LdoBase, LdSet } from "@ldo/ldo"; // import { SolidProfileShapeShapeType } from "../../test/_ldo/solidProfile.shapeTypes"; // import type { SolidProfileShape } from "../../test/_ldo/solidProfile.typings"; /** * Link Query Input */ export type LQInput = LQInputObject; export type LQInputObject = Partial<{ [key in Exclude]: LQInputFlattenSet; }>; export type LQInputSubSet = Type extends object ? LQInputObject : true; export type LQInputFlattenSet = Type extends LdSet ? LQInputSubSet : LQInputSubSet; /** * Link Query Return */ export type LQReturn> = LQReturnObject< Type, Input >; export type LQReturnObject> = { [key in Exclude< keyof Required, "@context" > as undefined extends Input[key] ? never : key]: Input[key] extends LQInputFlattenSet ? undefined extends Type[key] ? LQReturnExpandSet | undefined : LQReturnExpandSet : never; }; export type LQReturnSubSet = Input extends LQInputSubSet ? Input extends LQInputObject ? Input extends true ? Type : LQReturnObject : Type : never; export type LQReturnExpandSet< Type, Input extends LQInputFlattenSet, > = NonNullable extends LdSet ? LdSet> : LQReturnSubSet; /** * Helper Functions */ export type ExpandDeep = T extends LdSet ? LdSet> // recursively expand sets : T extends object ? { [K in keyof T]: ExpandDeep } // recursively expand objects : T; // base case (primitive types) /** * ILinkQuery: Manages resources in a link query */ export interface LinkQueryRunOptions { reload?: boolean; } export interface ILinkQuery> { run( options?: LinkQueryRunOptions, ): Promise>>; subscribe(): Promise; unsubscribe(subscriptionId: string): Promise; unsubscribeAll(): Promise; fromSubject(): ExpandDeep>; }