diff --git a/packages/demo-react/src/dashboard/Dashboard.tsx b/packages/demo-react/src/dashboard/Dashboard.tsx index 19726b3..12a4d6a 100644 --- a/packages/demo-react/src/dashboard/Dashboard.tsx +++ b/packages/demo-react/src/dashboard/Dashboard.tsx @@ -17,7 +17,6 @@ export const Dashboard: FunctionComponent = () => { const mainContainer = useDataResource(containerUri); - if (mainContainer instanceof AccessRules) { console.log("here"); } diff --git a/packages/solid/src/resource-old/notes.ts b/packages/solid/src/resource-old/notes.ts index 7696d83..9c020ae 100644 --- a/packages/solid/src/resource-old/notes.ts +++ b/packages/solid/src/resource-old/notes.ts @@ -29,22 +29,20 @@ const thing = { "AbsentContainerResource|AbsentChildDataResource|": ["create"], "AbsentContainerResource|AbsentChildDataResource|UnfetchedContainerResource|UnfetchedChildDataResource|": ["createIfAbsent"], + "AbsentBinaryResource|": ["upload"], "AbsentBinaryResource|UnfetchedBinaryResource|": ["uploadIfAbsent"], }; - import { LdoDataset } from "@ldo/ldo"; import { Quad } from "@rdfjs/types"; import { create } from "domain"; import { URL } from "url"; import { SolidLdoDataset } from "../SolidLdoDataset"; - export type ResourceStatus = BinaryResourceStatus | DataResourceStatus | ErrorResource | ErrorResourceStatus; export type BinaryResourceStore; - /** * Method and information definitions */ @@ -71,7 +69,6 @@ export interface IContainerResource extends IResource { clearIfPresent - export interface BinaryResource { uri: string; isLoading: boolean; @@ -247,8 +244,6 @@ export interface UnfetchedContainerResource { clearIfPresent(): Promise; } - - export interface LdoSolidError extends Error { forResource: unknown // Some Kind of Resource -} \ No newline at end of file +} diff --git a/packages/solid/src/resource/abstract/Resource.ts b/packages/solid/src/resource/abstract/Resource.ts index 9d4fb8e..0a8e6d3 100644 --- a/packages/solid/src/resource/abstract/Resource.ts +++ b/packages/solid/src/resource/abstract/Resource.ts @@ -1 +1,36 @@ -export class Resource {}; \ No newline at end of file +import type { AbsentContainer } from "../concrete/AbsentContainer"; +import type { AbsentLeaf } from "../concrete/AbsentLeaf"; +import type { BinaryLeaf } from "../concrete/BinaryLeaf"; +import type { BranchContainer } from "../concrete/BranchContainer"; +import type { DataLeaf } from "../concrete/DataLeaf"; +import type { RootContainer } from "../concrete/RootContainer"; +import type { UnfetchedLeaf } from "../concrete/UnfetchedLeaf"; +import type { UnfetchedContainer } from "../concrete/UnfetchedContainer"; +import type { SolidLdoError } from "../error/SolidLdoError"; +import type { FetchedClass } from "./fetchStatus/Fetched"; +import type { AbsentClass } from "./fetchStatus/Absent"; +import type { PresentClass } from "./fetchStatus/Present"; + +export type ResourceClass = + | RootContainer + | BranchContainer + | DataLeaf + | BinaryLeaf + | AbsentContainer + | AbsentLeaf + | UnfetchedContainer + | UnfetchedLeaf; +export abstract class Resource { + readonly uri: string; + readonly lastUpdated: Date; + + abstract read(): Promise; + abstract readIfUnfetched(): Promise; + + abstract createIfAbsent(): Promise; + abstract createOrOverride(): Promise; + + abstract deleteIfPresent(): Promise; + + abstract getCurrent(): ResourceClass; +} diff --git a/packages/solid/src/resource/abstract/container/Container.ts b/packages/solid/src/resource/abstract/container/Container.ts index 0765b0e..1cb88a6 100644 --- a/packages/solid/src/resource/abstract/container/Container.ts +++ b/packages/solid/src/resource/abstract/container/Container.ts @@ -1,3 +1,13 @@ +import { SolidLdoError } from "../../error/SolidLdoError"; import { PotentialDataResource } from "../dataResource/potentialDataResource"; -export class Container extends PotentialDataResource {} +export class Container extends PotentialDataResource { + async read(): Promise { + // Make query + // Select the Kind of Leaf + // Create it + + // Post Processing + throw new Error("Not Implemented"); + } +} diff --git a/packages/solid/src/resource/abstract/container/PresentContainer.ts b/packages/solid/src/resource/abstract/container/PresentContainer.ts index e69de29..67cf181 100644 --- a/packages/solid/src/resource/abstract/container/PresentContainer.ts +++ b/packages/solid/src/resource/abstract/container/PresentContainer.ts @@ -0,0 +1,9 @@ +import { Mixin } from "ts-mixer"; +import type { BranchContainer } from "../../concrete/BranchContainer"; +import type { RootContainer } from "../../concrete/RootContainer"; +import { DataResource } from "../dataResource/DataResource"; +import { Container } from "./Container"; +import { Present } from "../fetchStatus/Present"; + +export type PresentContainerClass = RootContainer | BranchContainer; +export class PresentContainer extends Mixin(Container, Present, DataResource) {} diff --git a/packages/solid/src/resource/abstract/dataResource/PotentialDataResource.ts b/packages/solid/src/resource/abstract/dataResource/PotentialDataResource.ts index 202b0c2..e6d6691 100644 --- a/packages/solid/src/resource/abstract/dataResource/PotentialDataResource.ts +++ b/packages/solid/src/resource/abstract/dataResource/PotentialDataResource.ts @@ -4,6 +4,8 @@ import type { BranchContainer } from "../../concrete/BranchContainer"; import type { RootContainer } from "../../concrete/RootContainer"; import type { UnfetchedContainer } from "../../concrete/UnfetchedContainer"; import type { UnfetchedLeaf } from "../../concrete/UnfetchedLeaf"; +import type { SolidLdoError } from "../../error/SolidLdoError"; +import type { ResourceClass } from "../Resource"; import { Resource } from "../Resource"; import type { DataResource } from "./DataResource"; @@ -15,4 +17,10 @@ export type PotentialDataResourceClass = | AbsentLeaf | UnfetchedContainer | UnfetchedLeaf; -export class PotentialDataResource extends Resource {} +export abstract class PotentialDataResource extends Resource< + ResourceClass, + SolidLdoError +> { + + abstract +} diff --git a/packages/solid/src/resource/abstract/fetchStatus/Absent.ts b/packages/solid/src/resource/abstract/fetchStatus/Absent.ts index cdce77c..204a4cd 100644 --- a/packages/solid/src/resource/abstract/fetchStatus/Absent.ts +++ b/packages/solid/src/resource/abstract/fetchStatus/Absent.ts @@ -1,13 +1,17 @@ import type { AbsentContainer } from "../../concrete/AbsentContainer"; import type { AbsentLeaf } from "../../concrete/AbsentLeaf"; +import type { SolidLdoError } from "../../error/SolidLdoError"; import { Fetched } from "./Fetched"; +import type { PresentClass } from "./Present"; export type AbsentClass = AbsentContainer | AbsentLeaf; -export class Absent extends Fetched { +export abstract class Absent extends Fetched { public get isAbsent(): true { return true; } public get isPresent(): false { return false; } + + abstract create(...args: unknown[]): Promise; } diff --git a/packages/solid/src/resource/abstract/fetchStatus/FetchStatus.ts b/packages/solid/src/resource/abstract/fetchStatus/FetchStatus.ts index 9e7ecbf..f90454d 100644 --- a/packages/solid/src/resource/abstract/fetchStatus/FetchStatus.ts +++ b/packages/solid/src/resource/abstract/fetchStatus/FetchStatus.ts @@ -1,4 +1,6 @@ -export abstract class FetchStatus { +import { Resource } from "../Resource"; + +export abstract class FetchStatus extends Resource { public abstract get didInitialFetch(): boolean; public abstract get isAbsent(): boolean | undefined; public abstract get isPresent(): boolean | undefined; diff --git a/packages/solid/src/resource/abstract/fetchStatus/Fetched.ts b/packages/solid/src/resource/abstract/fetchStatus/Fetched.ts index 4f056f1..05b7756 100644 --- a/packages/solid/src/resource/abstract/fetchStatus/Fetched.ts +++ b/packages/solid/src/resource/abstract/fetchStatus/Fetched.ts @@ -17,4 +17,8 @@ export abstract class Fetched extends FetchStatus { public get didInitialFetch(): true { return true; } + + async readIfUnfetched(): Promise { + return this; + } } diff --git a/packages/solid/src/resource/abstract/fetchStatus/Present.ts b/packages/solid/src/resource/abstract/fetchStatus/Present.ts index 5645b34..d980993 100644 --- a/packages/solid/src/resource/abstract/fetchStatus/Present.ts +++ b/packages/solid/src/resource/abstract/fetchStatus/Present.ts @@ -9,7 +9,7 @@ export type PresentClass = | BranchContainer | DataLeaf | BinaryLeaf; -export class Present extends Fetched { +export abstract class Present extends Fetched { public get isAbsent(): false { return false; } diff --git a/packages/solid/src/resource/abstract/fetchStatus/Unfetched.ts b/packages/solid/src/resource/abstract/fetchStatus/Unfetched.ts index bae2c05..855b099 100644 --- a/packages/solid/src/resource/abstract/fetchStatus/Unfetched.ts +++ b/packages/solid/src/resource/abstract/fetchStatus/Unfetched.ts @@ -1,9 +1,14 @@ import type { UnfetchedContainer } from "../../concrete/UnfetchedContainer"; import type { UnfetchedLeaf } from "../../concrete/UnfetchedLeaf"; +import type { SolidLdoError } from "../../error/SolidLdoError"; import { FetchStatus } from "./FetchStatus"; +import type { FetchedClass } from "./Fetched"; export type UnfetchedClass = UnfetchedContainer | UnfetchedLeaf; -export abstract class Unfetched extends FetchStatus { +export abstract class Unfetched< + ReadReturn extends FetchedClass, + ReadError extends SolidLdoError, +> extends FetchStatus { public get didInitialFetch(): false { return false; } @@ -13,4 +18,9 @@ export abstract class Unfetched extends FetchStatus { public get isPresent(): undefined { return undefined; } + + async readIfUnfetched(): Promise { + return this.read(); + } + abstract read(): Promise; } diff --git a/packages/solid/src/resource/abstract/leaf/FetchedLeaf.ts b/packages/solid/src/resource/abstract/leaf/FetchedLeaf.ts new file mode 100644 index 0000000..2c73569 --- /dev/null +++ b/packages/solid/src/resource/abstract/leaf/FetchedLeaf.ts @@ -0,0 +1,9 @@ +import { Mixin } from "ts-mixer"; +import { Leaf } from "./Leaf"; +import { Fetched } from "../fetchStatus/Fetched"; +import type { DataLeaf } from "../../concrete/DataLeaf"; +import type { BinaryLeaf } from "../../concrete/BinaryLeaf"; +import type { AbsentLeaf } from "../../concrete/AbsentLeaf"; + +export type FetchedLeafClass = DataLeaf | BinaryLeaf | AbsentLeaf; +export abstract class FetchedLeaf extends Mixin(Leaf, Fetched) {} diff --git a/packages/solid/src/resource/abstract/leaf/Leaf.ts b/packages/solid/src/resource/abstract/leaf/Leaf.ts index 12bc6d4..832779d 100644 --- a/packages/solid/src/resource/abstract/leaf/Leaf.ts +++ b/packages/solid/src/resource/abstract/leaf/Leaf.ts @@ -2,6 +2,32 @@ import type { AbsentLeaf } from "../../concrete/AbsentLeaf"; import type { BinaryLeaf } from "../../concrete/BinaryLeaf"; import type { DataLeaf } from "../../concrete/DataLeaf"; import type { UnfetchedLeaf } from "../../concrete/UnfetchedLeaf"; +import { SolidLdoError } from "../../error/SolidLdoError"; +import { Resource, ResourceClass } from "../Resource"; +import { FetchedClass } from "../fetchStatus/Fetched"; +import { PresentClass } from "../fetchStatus/Present"; +import type { FetchedLeafClass } from "./FetchedLeaf"; +import { PresentLeafClass } from "./PresentLeaf"; export type LeafClass = DataLeaf | BinaryLeaf | AbsentLeaf | UnfetchedLeaf; -export class Leaf {} +export abstract class Leaf extends Resource { + async read(): Promise { + // Make query + // Select the Kind of Leaf + // Create it + + // Post Processing + throw new Error("Not Implemented"); + } + + async createIfAbsent(): Promise; + async createIfAbsent(blob: Blob): Promise; + async createIfAbsent(_blob?: Blob): Promise { + + return new SolidLdoError(); + } + + getCurrent(): LeafClass { + throw new Error("Not Implemented"); + } +} diff --git a/packages/solid/src/resource/abstract/leaf/PotentialBinaryLeaf.ts b/packages/solid/src/resource/abstract/leaf/PotentialBinaryLeaf.ts deleted file mode 100644 index e69de29..0000000 diff --git a/packages/solid/src/resource/abstract/leaf/PotentialDataLeaf.ts b/packages/solid/src/resource/abstract/leaf/PotentialDataLeaf.ts deleted file mode 100644 index 79bb967..0000000 --- a/packages/solid/src/resource/abstract/leaf/PotentialDataLeaf.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Mixin } from "ts-mixer"; -import type { AbsentLeaf } from "../../concrete/AbsentLeaf"; -import type { DataLeaf } from "../../concrete/DataLeaf"; -import type { UnfetchedLeaf } from "../../concrete/UnfetchedLeaf"; -import { PotentialDataResource } from "../dataResource/potentialDataResource"; -import { Leaf } from "./Leaf"; - -export type PotentialDataLeafClass = DataLeaf | AbsentLeaf | UnfetchedLeaf; -export class PotentialDataLeaf extends Mixin(Leaf, PotentialDataResource) {} diff --git a/packages/solid/src/resource/abstract/leaf/PresentLeaf.ts b/packages/solid/src/resource/abstract/leaf/PresentLeaf.ts index 520de66..4997088 100644 --- a/packages/solid/src/resource/abstract/leaf/PresentLeaf.ts +++ b/packages/solid/src/resource/abstract/leaf/PresentLeaf.ts @@ -1,8 +1,8 @@ import { Mixin } from "ts-mixer"; -import { Leaf } from "./Leaf"; +import { FetchedLeaf } from "./FetchedLeaf"; import { Present } from "../fetchStatus/Present"; import type { DataLeaf } from "../../concrete/DataLeaf"; import type { BinaryLeaf } from "../../concrete/BinaryLeaf"; export type PresentLeafClass = DataLeaf | BinaryLeaf; -export class PresentLeaf extends Mixin(Leaf, Present) {} +export abstract class PresentLeaf extends Mixin(FetchedLeaf, Present) {} diff --git a/packages/solid/src/resource/concrete/AbsentLeaf.ts b/packages/solid/src/resource/concrete/AbsentLeaf.ts index d94658c..f21d00f 100644 --- a/packages/solid/src/resource/concrete/AbsentLeaf.ts +++ b/packages/solid/src/resource/concrete/AbsentLeaf.ts @@ -1,5 +1,21 @@ import { Mixin } from "ts-mixer"; -import { Absent } from "../abstract/fetchStatus/Absent"; -import { PotentialBinaryLeaf } from "../abstract/leaf/PotentialBinaryLeaf"; +import { Absent, AbsentClass } from "../abstract/fetchStatus/Absent"; +import { FetchedLeaf, FetchedLeafClass } from "../abstract/leaf/FetchedLeaf"; +import { FetchedClass } from "../abstract/fetchStatus/Fetched"; +import { PresentClass } from "../abstract/fetchStatus/Present"; +import { SolidLdoError } from "../error/SolidLdoError"; -export class AbsentLeaf extends Mixin(Absent, PotentialBinaryLeaf) {} +export class AbsentLeaf extends Mixin(Absent, FetchedLeaf) { + create(...args: unknown[]): Promise { + throw new Error("Method not implemented."); + } + read(): Promise { + throw new Error("Method not implemented."); + } + createOrOverride(): Promise { + throw new Error("Method not implemented."); + } + deleteIfPresent(): Promise { + throw new Error("Method not implemented."); + } +} diff --git a/packages/solid/src/resource/concrete/BranchContainer.ts b/packages/solid/src/resource/concrete/BranchContainer.ts index 3986ebe..3c01df6 100644 --- a/packages/solid/src/resource/concrete/BranchContainer.ts +++ b/packages/solid/src/resource/concrete/BranchContainer.ts @@ -1 +1,3 @@ -export class BranchContainer {} +import { PresentContainer } from "../abstract/container/PresentContainer"; + +export class BranchContainer extends PresentContainer {} diff --git a/packages/solid/src/resource/error/SolidLdoError.ts b/packages/solid/src/resource/error/SolidLdoError.ts new file mode 100644 index 0000000..edcc711 --- /dev/null +++ b/packages/solid/src/resource/error/SolidLdoError.ts @@ -0,0 +1 @@ +export class SolidLdoError extends Error {}