import { SolidContainerUri, SolidLeafUri } from "../types.mjs"; import { CreateSuccess } from "../requester/results/success/CreateSuccess.mjs"; import { DeleteSuccess } from "../requester/results/success/DeleteSuccess.mjs"; import { CheckRootResultError } from "../requester/requests/checkRootContainer.mjs"; import { ReadContainerResult, ReadLeafResult } from "../requester/requests/readResource.mjs"; import { NoRootContainerError } from "../requester/results/error/NoRootContainerError.mjs"; import { WacRule } from "../wac/WacRule.mjs"; import { GetWacUriError, GetWacUriResult } from "../wac/getWacUri.mjs"; import { GetWacRuleSuccess } from "../wac/results/GetWacRuleSuccess.mjs"; import { GetWacRuleError } from "../wac/getWacRule.mjs"; import { SetWacRuleResult } from "../wac/setWacRule.mjs"; import { SolidNotificationMessage } from "../notifications/SolidNotificationMessage.mjs"; import { UpdateResult } from "../requester/requests/updateDataResource.mjs"; import { GetStorageDescriptionUriError, GetStorageDescriptionUriResult } from "../requester/requests/getStorageDescription.mjs"; import { SolidContainer } from "./SolidContainer.mjs"; import { DeleteResult } from "../requester/requests/deleteResource.mjs"; import { ContainerCreateAndOverwriteResult, ContainerCreateIfAbsentResult, LeafCreateAndOverwriteResult, LeafCreateIfAbsentResult } from "../requester/requests/createDataResource.mjs"; import { BatchedRequester } from "../requester/BatchedRequester.mjs"; import { SolidLeaf } from "./SolidLeaf.mjs"; import { SolidConnectedPlugin } from "../SolidConnectedPlugin.mjs"; import { ConnectedContext, ConnectedResult, IgnoredInvalidUpdateSuccess, NotificationSubscription, ReadSuccess, Resource, ResourceEventEmitter, ResourceSuccess, SubscriptionCallbacks, Unfetched } from "@ldo/connected"; import { DatasetChanges } from "@ldo/rdf-utils"; //#region src/resources/SolidResource.d.ts /** * Statuses shared between both Leaf and Container */ type SharedStatuses = Unfetched | DeleteResult | CreateSuccess; declare const SolidResource_base: new () => ResourceEventEmitter; declare abstract class SolidResource extends SolidResource_base implements Resource { /** * @internal * The ConnectedContext from the Parent Dataset */ protected readonly context: ConnectedContext; /** * The uri of the resource */ abstract readonly uri: SolidLeafUri | SolidContainerUri; /** * The type of resource (leaf or container) */ abstract readonly type: "SolidLeaf" | "SolidContainer"; /** * The status of the last request made for this resource */ abstract status: ConnectedResult; /** * @internal * Batched Requester for the Resource */ protected abstract readonly requester: BatchedRequester; /** * @internal * True if this resource has been fetched at least once */ protected didInitialFetch: boolean; /** * @internal * True if this resource has been fetched but does not exist */ protected absent: boolean | undefined; /** * @internal * If a wac uri is fetched, it is cached here */ protected wacUri?: SolidLeafUri; /** * @internal * If a wac rule was fetched, it is cached here */ protected wacRule?: WacRule; /** * @internal * Handles notification subscriptions */ protected notificationSubscription: NotificationSubscription; /** * Indicates that resources are not errors */ readonly isError: false; /** * @internal * If a storage description URI was fetched, it is cached here * * https://solidproject.org/TR/protocol#server-storage-description */ protected storageDescriptionUri?: SolidLeafUri; /** * @internal * If a root container uri as fetched from storage description, it is cached here * * https://solidproject.org/TR/protocol#storage-description-statements */ protected rootContainerFromStorageDescriptionUri?: SolidContainerUri; /** * @param context - SolidLdoDatasetContext for the parent dataset */ constructor(context: ConnectedContext); /** * =========================================================================== * GETTERS * =========================================================================== */ /** * Checks to see if this resource is loading in any way * @returns true if the resource is currently loading * * @example * ```typescript * resource.read().then(() => { * // Logs "false" * console.log(resource.isLoading()) * }); * // Logs "true" * console.log(resource.isLoading()); * ``` */ isLoading(): boolean; /** * Checks to see if this resource is being created * @returns true if the resource is currently being created * * @example * ```typescript * resource.read().then(() => { * // Logs "false" * console.log(resource.isCreating()) * }); * // Logs "true" * console.log(resource.isCreating()); * ``` */ isCreating(): boolean; /** * Checks to see if this resource is being read * @returns true if the resource is currently being read * * @example * ```typescript * resource.read().then(() => { * // Logs "false" * console.log(resource.isReading()) * }); * // Logs "true" * console.log(resource.isReading()); * ``` */ isReading(): boolean; /** * Checks to see if this resource is being deleted * @returns true if the resource is currently being deleted * * @example * ```typescript * resource.read().then(() => { * // Logs "false" * console.log(resource.isDeleting()) * }); * // Logs "true" * console.log(resource.isDeleting()); * ``` */ isDeleting(): boolean; /** * Checks to see if this resource is being read for the first time * @returns true if the resource is currently being read for the first time * * @example * ```typescript * resource.read().then(() => { * // Logs "false" * console.log(resource.isDoingInitialFetch()) * }); * // Logs "true" * console.log(resource.isDoingInitialFetch()); * ``` */ isDoingInitialFetch(): boolean; /** * Checks to see if this resource is being read for a subsequent time * @returns true if the resource is currently being read for a subsequent time * * @example * ```typescript * await resource.read(); * resource.read().then(() => { * // Logs "false" * console.log(resource.isCreating()) * }); * // Logs "true" * console.log(resource.isCreating()); * ``` */ isReloading(): boolean; /** * =========================================================================== * CHECKERS * =========================================================================== */ /** * Check to see if this resource has been fetched * @returns true if this resource has been fetched before * * @example * ```typescript * // Logs "false" * console.log(resource.isFetched()); * const result = await resource.read(); * if (!result.isError) { * // Logs "true" * console.log(resource.isFetched()); * } * ``` */ isFetched(): boolean; /** * Check to see if this resource is currently unfetched * @returns true if the resource is currently unfetched * * @example * ```typescript * // Logs "true" * console.log(resource.isUnetched()); * const result = await resource.read(); * if (!result.isError) { * // Logs "false" * console.log(resource.isUnfetched()); * } * ``` */ isUnfetched(): boolean; /** * Is this resource currently absent (it does not exist) * @returns true if the resource is absent, false if not, undefined if unknown * * @example * ```typescript * // Logs "undefined" * console.log(resource.isAbsent()); * const result = await resource.read(); * if (!result.isError) { * // False if the resource exists, true if it does not * console.log(resource.isAbsent()); * } * ``` */ isAbsent(): boolean | undefined; /** * Is this resource currently present on the Pod * @returns false if the resource is absent, true if not, undefined if unknown * * @example * ```typescript * // Logs "undefined" * console.log(resource.isPresent()); * const result = await resource.read(); * if (!result.isError) { * // True if the resource exists, false if it does not * console.log(resource.isPresent()); * } * ``` */ isPresent(): boolean | undefined; /** * Is this resource currently listening to notifications from this document * @returns true if the resource is subscribed to notifications, false if not * * @example * ```typescript * await resource.subscribeToNotifications(); * // Logs "true" * console.log(resource.isSubscribedToNotifications()); * ``` */ isSubscribedToNotifications(): boolean; /** * =========================================================================== * HELPER METHODS * =========================================================================== */ /** * @internal * Emits an update event for both this resource and the parent */ protected emitThisAndParent(): void; /** * =========================================================================== * READ METHODS * =========================================================================== */ /** * @internal * A helper method updates this resource's internal state upon read success * @param result - the result of the read success */ protected updateWithReadSuccess(result: ReadSuccess): void; /** * @internal * A helper method that handles the core functions for reading * @returns ReadResult */ protected handleRead(): Promise; /** * @internal * Converts the current state of this resource to a readResult * @returns a ReadResult */ protected abstract toReadResult(): ReadLeafResult | ReadContainerResult; /** * Reads the resource */ abstract read(): Promise; /** * Reads the resource if it isn't fetched yet * @returns a ReadResult */ readIfUnfetched(): Promise; /** * =========================================================================== * DELETE METHODS * =========================================================================== */ /** * @internal * A helper method updates this resource's internal state upon delete success * @param result - the result of the delete success */ updateWithDeleteSuccess(_result: DeleteSuccess): void; /** * @internal * Helper method that handles the core functions for deleting a resource * @returns DeleteResult */ protected handleDelete(): Promise>; /** * =========================================================================== * CREATE METHODS * =========================================================================== */ /** * A helper method updates this resource's internal state upon create success * @param _result - the result of the create success */ protected updateWithCreateSuccess(result: ResourceSuccess): void; /** * Creates a resource at this URI and overwrites any that already exists * @returns CreateAndOverwriteResult * * @example * ```typescript * const result = await resource.createAndOverwrite(); * if (!result.isError) { * // Do something * } * ``` */ abstract createAndOverwrite(): Promise; /** * @internal * Helper method that handles the core functions for creating and overwriting * a resource * @returns DeleteResult */ protected handleCreateAndOverwrite(): Promise; /** * Creates a resource at this URI if the resource doesn't already exist * @returns CreateIfAbsentResult * * @example * ```typescript * const result = await leaf.createIfAbsent(); * if (!result.isError) { * // Do something * } * ``` */ abstract createIfAbsent(): Promise; /** * @internal * Helper method that handles the core functions for creating a resource if * absent * @returns DeleteResult */ protected handleCreateIfAbsent(): Promise; /** * UPDATE METHODS */ abstract update(datasetChanges: DatasetChanges): Promise | IgnoredInvalidUpdateSuccess>; /** * =========================================================================== * PARENT CONTAINER METHODS * =========================================================================== */ /** * Retrieves the URI for the storage description of this resource * @param options - set the "ignoreCache" field to true to ignore cached URI * @returns results, containing SolidLeafUri when successful * * note: this is based on this.getWacUri method */ protected getStorageDescriptionUri(options?: { ignoreCache: boolean; }): Promise>; /** * Gets the root container for this resource. * @returns The root container for this resource * * @example * Suppose the root container is at `https://example.com/` * * ```typescript * const resource = ldoSolidDataset * .getResource("https://example.com/container/resource.ttl"); * const rootContainer = await resource.getRootContainer(); * if (!rootContainer.isError) { * // logs "https://example.com/" * console.log(rootContainer.uri); * } * ``` */ getRootContainer(): Promise>; /** * Gets the root container from this resource's storage description * https://solidproject.org/TR/protocol#server-storage-description * * Consider getRootContainer() instead, which tries multiple discovery strategies. * * @param options - Options object * @param options.ignoreCache {boolean} - ignore cached storage resource URI and root container values * * @returns SolidContainer or error objects */ getRootContainerFromStorageDescription(options?: { ignoreCache: boolean; }): Promise>; /** * https://solidproject.org/TR/protocol#client-storage-disovery */ abstract getRootContainerByTraversal(): Promise>; abstract getParentContainer(): Promise; /** * =========================================================================== * WEB ACCESS CONTROL METHODS * =========================================================================== */ /** * Retrieves the URI for the web access control (WAC) rules for this resource * @param options - set the "ignoreCache" field to true to ignore any cached * information on WAC rules. * @returns WAC Rules results */ protected getWacUri(options?: { ignoreCache: boolean; }): Promise>; /** * Retrieves web access control (WAC) rules for this resource * @param options - set the "ignoreCache" field to true to ignore any cached * information on WAC rules. * @returns WAC Rules results * * @example * ```typescript * const resource = ldoSolidDataset * .getResource("https://example.com/container/resource.ttl"); * const wacRulesResult = await resource.getWac(); * if (!wacRulesResult.isError) { * const wacRules = wacRulesResult.wacRule; * // True if the resource is publicly readable * console.log(wacRules.public.read); * // True if authenticated agents can write to the resource * console.log(wacRules.authenticated.write); * // True if the given WebId has append access * console.log( * wacRules.agent[https://example.com/person1/profile/card#me].append * ); * // True if the given WebId has control access * console.log( * wacRules.agent[https://example.com/person1/profile/card#me].control * ); * } * ``` */ getWac(options?: { ignoreCache: boolean; }): Promise | GetWacRuleError | GetWacRuleSuccess>; /** * Sets access rules for a specific resource * @param wacRule - the access rules to set * @returns SetWacRuleResult * * @example * ```typescript * const resource = ldoSolidDataset * .getResource("https://example.com/container/resource.ttl"); * const wacRulesResult = await resource.setWac({ * public: { * read: true, * write: false, * append: false, * control: false * }, * authenticated: { * read: true, * write: false, * append: true, * control: false * }, * agent: { * "https://example.com/person1/profile/card#me": { * read: true, * write: true, * append: true, * control: true * } * } * }); * ``` */ setWac(wacRule: WacRule): Promise | SetWacRuleResult>; /** * =========================================================================== * SUBSCRIPTION METHODS * =========================================================================== */ /** * Activates Websocket subscriptions on this resource. Updates, deletions, * and creations on this resource will be tracked and all changes will be * relected in LDO's resources and graph. * * @param onNotificationError - A callback function if there is an error * with notifications. * @returns SubscriptionId: A string to use to unsubscribe * * @example * ```typescript * const resource = solidLdoDataset * .getResource("https://example.com/spiderman"); * // A listener for if anything about spiderman in the global dataset is * // changed. Note that this will also listen for any local changes as well * // as changes to remote resources to which you have notification * // subscriptions enabled. * solidLdoDataset.addListener( * [namedNode("https://example.com/spiderman#spiderman"), null, null, null], * () => { * // Triggers when the file changes on the Pod or locally * console.log("Something changed about SpiderMan"); * }, * ); * * // Subscribe * const subscriptionId = await testContainer.subscribeToNotifications({ * // These are optional callbacks. A subscription will automatically keep * // the dataset in sync. Use these callbacks for additional functionality. * onNotification: (message) => console.log(message), * onNotificationError: (err) => console.log(err.message) * }); * // ... From there you can wait for a file to be changed on the Pod. */ subscribeToNotifications(callbacks?: SubscriptionCallbacks): Promise; /** * @internal * Function that triggers whenever a notification is recieved. */ protected onNotification(message: SolidNotificationMessage): Promise; /** * Unsubscribes from changes made to this resource on the Pod * * @returns UnsubscribeResult * * @example * ```typescript * const subscriptionId = await testContainer.subscribeToNotifications(); * await testContainer.unsubscribeFromNotifications(subscriptionId); * ``` */ unsubscribeFromNotifications(subscriptionId: string): Promise; /** * Unsubscribes from all notifications on this resource * * @returns UnsubscribeResult[] * * @example * ```typescript * const subscriptionResult = await testContainer.subscribeToNotifications(); * await testContainer.unsubscribeFromAllNotifications(); * ``` */ unsubscribeFromAllNotifications(): Promise; } //#endregion export { SharedStatuses, SolidResource }; //# sourceMappingURL=SolidResource.d.mts.map