parent
ef4e07ce93
commit
9afd82ee69
@ -1,6 +1,6 @@ |
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
/* eslint-disable @typescript-eslint/no-explicit-any */ |
||||||
import type { ConnectedLdoDataset } from "./ConnectedLdoDataset"; |
import type { ConnectedLdoDataset } from "./ConnectedLdoDataset"; |
||||||
import type { ConnectedPlugin } from "./ConnectedPlugin"; |
import type { ConnectedPlugin } from "./types/ConnectedPlugin"; |
||||||
|
|
||||||
/** |
/** |
||||||
* Each Plugin comes with a context. This is the aggregate of all those contexts |
* Each Plugin comes with a context. This is the aggregate of all those contexts |
@ -1,7 +1,7 @@ |
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
/* eslint-disable @typescript-eslint/no-explicit-any */ |
||||||
import type { ConnectedContext } from "./ConnectedContext"; |
import type { ConnectedContext } from "./ConnectedContext"; |
||||||
import type { Resource } from "./Resource"; |
import type { Resource } from "../Resource"; |
||||||
import type { ErrorResult } from "./results/error/ErrorResult"; |
import type { ErrorResult } from "../results/error/ErrorResult"; |
||||||
|
|
||||||
/** |
/** |
||||||
* A ConnectedPlugin can be passed to a ConnectedDataset to allow it to connect |
* A ConnectedPlugin can be passed to a ConnectedDataset to allow it to connect |
@ -0,0 +1,12 @@ |
|||||||
|
import type { LdoBase, LdoBuilder } from "@ldo/ldo"; |
||||||
|
import type { ConnectedPlugin } from "./ConnectedPlugin"; |
||||||
|
import { SubjectNode } from "@ldo/rdf-utils"; |
||||||
|
|
||||||
|
export interface IConnectedLdoBuilder< |
||||||
|
Type extends LdoBase, |
||||||
|
Plugins extends ConnectedPlugin[], |
||||||
|
> extends LdoBuilder<Type> { |
||||||
|
fromLinkQuery(startingResource: Plugins[number]["types"]["resource"], startingSubject: SubjectNode | string, linkQueryInput:
|
||||||
|
|
||||||
|
) |
||||||
|
} |
@ -1,7 +1,7 @@ |
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
/* eslint-disable @typescript-eslint/no-explicit-any */ |
||||||
import type { LdoDataset } from "@ldo/ldo"; |
import type { LdoDataset } from "@ldo/ldo"; |
||||||
import type { ConnectedPlugin } from "./ConnectedPlugin"; |
import type { ConnectedPlugin } from "./ConnectedPlugin"; |
||||||
import type { InvalidIdentifierResource } from "./InvalidIdentifierResource"; |
import type { InvalidIdentifierResource } from "../InvalidIdentifierResource"; |
||||||
|
|
||||||
export type ReturnTypeFromArgs<Func, Arg> = Func extends ( |
export type ReturnTypeFromArgs<Func, Arg> = Func extends ( |
||||||
arg: Arg, |
arg: Arg, |
@ -0,0 +1,88 @@ |
|||||||
|
// 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, ShapeType } from "@ldo/ldo"; |
||||||
|
import { ProfileShapeType } from "packages/ldo/test/profileData"; |
||||||
|
import { SolidProfileShape } from "packages/ldo/test/profileData"; |
||||||
|
import { PostShShapeType } from "packages/solid-react/test/.ldo/post.shapeTypes"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Link Query Input |
||||||
|
*/ |
||||||
|
export type LQInputObject<Type> = Partial<{ |
||||||
|
[key in keyof Type]: LQInput<Type[key]>; |
||||||
|
}>; |
||||||
|
|
||||||
|
export type LQInputSubArray<Type> = Type extends object |
||||||
|
? LQInputObject<Type> |
||||||
|
: true; |
||||||
|
|
||||||
|
export type LQInput<Type> = Type extends LdSet<infer ArraySubType> |
||||||
|
? LQInputSubArray<ArraySubType> |
||||||
|
: LQInputSubArray<Type>; |
||||||
|
|
||||||
|
/** |
||||||
|
* Link Query Input Default |
||||||
|
*/ |
||||||
|
export type LQInputDefaultType<Type> = { |
||||||
|
[key in keyof Type]: Type[key] extends object ? undefined : true; |
||||||
|
}; |
||||||
|
|
||||||
|
export type LQInputDefault<Type> = |
||||||
|
LQInputDefaultType<Type> extends LQInput<Type> |
||||||
|
? LQInputDefaultType<Type> |
||||||
|
: never; |
||||||
|
|
||||||
|
/** |
||||||
|
* Link Query Return |
||||||
|
*/ |
||||||
|
export type LQReturnObject<Type, Input extends LQInputObject<Type>> = { |
||||||
|
[key in keyof Required<Type> as undefined extends Input[key] |
||||||
|
? never |
||||||
|
: key]: Input[key] extends LQInput<Type[key]> |
||||||
|
? undefined extends Type[key] |
||||||
|
? LQReturnRecursive<Type[key], Input[key]> | undefined |
||||||
|
: LQReturnRecursive<Type[key], Input[key]> |
||||||
|
: never; |
||||||
|
}; |
||||||
|
|
||||||
|
export type LQReturnSubArray<Type, Input> = Input extends LQInputSubArray<Input> |
||||||
|
? Type extends object |
||||||
|
? LQReturnObject<Type, Input> |
||||||
|
: Type |
||||||
|
: never; |
||||||
|
|
||||||
|
export type LQReturnRecursive< |
||||||
|
Type, |
||||||
|
Input extends LQInput<Type>, |
||||||
|
> = NonNullable<Type> extends LdSet<infer ArraySubType> |
||||||
|
? LdSet<LQReturnSubArray<ArraySubType, Input>> |
||||||
|
: LQReturnSubArray<Type, Input>; |
||||||
|
|
||||||
|
export type LQReturn<Type, Input extends LQInput<Type>> = LQReturnRecursive< |
||||||
|
Type, |
||||||
|
Input |
||||||
|
>; |
||||||
|
|
||||||
|
type ExpandDeep<T> = T extends LdSet<infer U> |
||||||
|
? LdSet<ExpandDeep<U>> // recursively expand arrays
|
||||||
|
: T extends object |
||||||
|
? { [K in keyof T]: ExpandDeep<T[K]> } // recursively expand objects
|
||||||
|
: T; // base case (primitive types)
|
||||||
|
|
||||||
|
function sampleFunction<Type extends LdoBase, Input extends LQInput<Type>>( |
||||||
|
_shapeType: ShapeType<Type>, |
||||||
|
_input: Input, |
||||||
|
): ExpandDeep<LQReturn<Type, Input>> { |
||||||
|
throw new Error("NotImplemented"); |
||||||
|
} |
||||||
|
|
||||||
|
type other = ExpandDeep<LQInput<SolidProfileShape>>; |
||||||
|
|
||||||
|
const value = sampleFunction(ProfileShapeType, { |
||||||
|
hasTelephone: { type: { "@id": true }, value: true }, |
||||||
|
}); |
||||||
|
|
||||||
|
value; |
Loading…
Reference in new issue