Class: SolidResource
Hierarchy
TypedEventEmitter\<{notification: () =>void;update: () =>void},this>
↳ SolidResource
↳↳ SolidLeaf
Implements
Resource\<SolidLeafUri|SolidContainerUri>
Constructors
constructor
• new SolidResource(context): SolidResource
Parameters
| Name | Type | Description |
|---|---|---|
context |
ConnectedContext\<SolidConnectedPlugin[]> |
SolidLdoDatasetContext for the parent dataset |
Returns
Overrides
(EventEmitter as new () =\> ResourceEventEmitter).constructor
Defined in
packages/connected-solid/src/resources/SolidResource.ts:135
Properties
absent
• Protected absent: undefined | boolean
True if this resource has been fetched but does not exist
Defined in
packages/connected-solid/src/resources/SolidResource.ts:104
context
• Protected Readonly context: ConnectedContext\<SolidConnectedPlugin[]>
The ConnectedContext from the Parent Dataset
Defined in
packages/connected-solid/src/resources/SolidResource.ts:69
didInitialFetch
• Protected didInitialFetch: boolean = false
True if this resource has been fetched at least once
Defined in
packages/connected-solid/src/resources/SolidResource.ts:98
isError
• Readonly isError: false
Indicates that resources are not errors
Implementation of
Resource.isError
Defined in
packages/connected-solid/src/resources/SolidResource.ts:130
notificationSubscription
• Protected notificationSubscription: NotificationSubscription\<SolidConnectedPlugin, SolidNotificationMessage>
Handles notification subscriptions
Defined in
packages/connected-solid/src/resources/SolidResource.ts:122
requester
• Protected Readonly Abstract requester: BatchedRequester\<SolidContainer | SolidLeaf>
Batched Requester for the Resource
Defined in
packages/connected-solid/src/resources/SolidResource.ts:90
status
• Abstract status: ConnectedResult
The status of the last request made for this resource
Implementation of
Resource.status
Defined in
packages/connected-solid/src/resources/SolidResource.ts:84
type
• Readonly Abstract type: "SolidContainer" | "SolidLeaf"
The type of resource (leaf or container)
Implementation of
Resource.type
Defined in
packages/connected-solid/src/resources/SolidResource.ts:79
uri
• Readonly Abstract uri: SolidContainerUri | SolidLeafUri
The uri of the resource
Implementation of
Resource.uri
Defined in
packages/connected-solid/src/resources/SolidResource.ts:74
wacRule
• Protected Optional wacRule: WacRule
If a wac rule was fetched, it is cached here
Defined in
packages/connected-solid/src/resources/SolidResource.ts:116
wacUri
• Protected Optional wacUri: SolidLeafUri
If a wac uri is fetched, it is cached here
Defined in
packages/connected-solid/src/resources/SolidResource.ts:110
Methods
createAndOverwrite
▸ createAndOverwrite(): Promise\<ContainerCreateAndOverwriteResult | LeafCreateAndOverwriteResult>
Creates a resource at this URI and overwrites any that already exists
Returns
Promise\<ContainerCreateAndOverwriteResult | LeafCreateAndOverwriteResult>
CreateAndOverwriteResult
Example
Defined in
packages/connected-solid/src/resources/SolidResource.ts:493
createIfAbsent
▸ createIfAbsent(): Promise\<ContainerCreateIfAbsentResult | LeafCreateIfAbsentResult>
Creates a resource at this URI if the resource doesn't already exist
Returns
Promise\<ContainerCreateIfAbsentResult | LeafCreateIfAbsentResult>
CreateIfAbsentResult
Example
Defined in
packages/connected-solid/src/resources/SolidResource.ts:526
emitThisAndParent
▸ emitThisAndParent(): void
Emits an update event for both this resource and the parent
Returns
void
Defined in
packages/connected-solid/src/resources/SolidResource.ts:367
getParentContainer
▸ getParentContainer(): Promise\<undefined | SolidContainer | CheckRootResultError>
Returns
Promise\<undefined | SolidContainer | CheckRootResultError>
Defined in
packages/connected-solid/src/resources/SolidResource.ts:585
getRootContainer
▸ getRootContainer(): Promise\<SolidContainer | CheckRootResultError | NoRootContainerError\<SolidContainer | SolidLeaf>>
Gets the root container for this resource.
Returns
Promise\<SolidContainer | CheckRootResultError | NoRootContainerError\<SolidContainer | SolidLeaf>>
The root container for this resource
Example
Suppose the root container is at https://example.com/
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);
}
Defined in
packages/connected-solid/src/resources/SolidResource.ts:579
getWac
▸ getWac(options?): Promise\<ServerHttpError\<SolidContainer | SolidLeaf> | UnexpectedHttpError\<SolidContainer | SolidLeaf> | UnauthenticatedHttpError\<SolidContainer | SolidLeaf> | UnauthorizedHttpError\<SolidContainer | SolidLeaf> | NoncompliantPodError\<SolidContainer | SolidLeaf> | UnexpectedResourceError\<SolidContainer | SolidLeaf> | NotFoundHttpError\<SolidContainer | SolidLeaf> | GetWacRuleSuccess\<SolidContainer | SolidLeaf> | WacRuleAbsent\<SolidContainer | SolidLeaf>>
Retrieves web access control (WAC) rules for this resource
Parameters
| Name | Type | Description |
|---|---|---|
options? |
Object |
set the "ignoreCache" field to true to ignore any cached information on WAC rules. |
options.ignoreCache |
boolean |
- |
Returns
Promise\<ServerHttpError\<SolidContainer | SolidLeaf> | UnexpectedHttpError\<SolidContainer | SolidLeaf> | UnauthenticatedHttpError\<SolidContainer | SolidLeaf> | UnauthorizedHttpError\<SolidContainer | SolidLeaf> | NoncompliantPodError\<SolidContainer | SolidLeaf> | UnexpectedResourceError\<SolidContainer | SolidLeaf> | NotFoundHttpError\<SolidContainer | SolidLeaf> | GetWacRuleSuccess\<SolidContainer | SolidLeaf> | WacRuleAbsent\<SolidContainer | SolidLeaf>>
WAC Rules results
Example
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
);
}
Defined in
packages/connected-solid/src/resources/SolidResource.ts:648
getWacUri
▸ getWacUri(options?): Promise\<GetWacUriResult\<SolidContainer | SolidLeaf>>
Retrieves the URI for the web access control (WAC) rules for this resource
Parameters
| Name | Type | Description |
|---|---|---|
options? |
Object |
set the "ignoreCache" field to true to ignore any cached information on WAC rules. |
options.ignoreCache |
boolean |
- |
Returns
Promise\<GetWacUriResult\<SolidContainer | SolidLeaf>>
WAC Rules results
Defined in
packages/connected-solid/src/resources/SolidResource.ts:601
handleCreateAndOverwrite
▸ handleCreateAndOverwrite(): Promise\<ContainerCreateAndOverwriteResult | LeafCreateAndOverwriteResult>
Helper method that handles the core functions for creating and overwriting a resource
Returns
Promise\<ContainerCreateAndOverwriteResult | LeafCreateAndOverwriteResult>
DeleteResult
Defined in
packages/connected-solid/src/resources/SolidResource.ts:503
handleCreateIfAbsent
▸ handleCreateIfAbsent(): Promise\<ContainerCreateIfAbsentResult | LeafCreateIfAbsentResult>
Helper method that handles the core functions for creating a resource if absent
Returns
Promise\<ContainerCreateIfAbsentResult | LeafCreateIfAbsentResult>
DeleteResult
Defined in
packages/connected-solid/src/resources/SolidResource.ts:536
handleDelete
▸ handleDelete(): Promise\<DeleteResult\<SolidContainer | SolidLeaf>>
Helper method that handles the core functions for deleting a resource
Returns
Promise\<DeleteResult\<SolidContainer | SolidLeaf>>
DeleteResult
Defined in
packages/connected-solid/src/resources/SolidResource.ts:452
handleRead
▸ handleRead(): Promise\<ReadContainerResult | ReadLeafResult>
A helper method that handles the core functions for reading
Returns
Promise\<ReadContainerResult | ReadLeafResult>
ReadResult
Defined in
packages/connected-solid/src/resources/SolidResource.ts:397
isAbsent
▸ isAbsent(): undefined | boolean
Is this resource currently absent (it does not exist)
Returns
undefined | boolean
true if the resource is absent, false if not, undefined if unknown
Example
// 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());
}
Implementation of
Resource.isAbsent
Defined in
packages/connected-solid/src/resources/SolidResource.ts:319
isCreating
▸ isCreating(): boolean
Checks to see if this resource is being created
Returns
boolean
true if the resource is currently being created
Example
resource.read().then(() => {
// Logs "false"
console.log(resource.isCreating())
});
// Logs "true"
console.log(resource.isCreating());
Defined in
packages/connected-solid/src/resources/SolidResource.ts:183
isDeleting
▸ isDeleting(): boolean
Checks to see if this resource is being deleted
Returns
boolean
true if the resource is currently being deleted
Example
resource.read().then(() => {
// Logs "false"
console.log(resource.isDeleting())
});
// Logs "true"
console.log(resource.isDeleting());
Defined in
packages/connected-solid/src/resources/SolidResource.ts:219
isDoingInitialFetch
▸ isDoingInitialFetch(): boolean
Checks to see if this resource is being read for the first time
Returns
boolean
true if the resource is currently being read for the first time
Example
resource.read().then(() => {
// Logs "false"
console.log(resource.isDoingInitialFetch())
});
// Logs "true"
console.log(resource.isDoingInitialFetch());
Implementation of
Resource.isDoingInitialFetch
Defined in
packages/connected-solid/src/resources/SolidResource.ts:237
isFetched
▸ isFetched(): boolean
Check to see if this resource has been fetched
Returns
boolean
true if this resource has been fetched before
Example
// Logs "false"
console.log(resource.isFetched());
const result = await resource.read();
if (!result.isError) {
// Logs "true"
console.log(resource.isFetched());
}
Implementation of
Resource.isFetched
Defined in
packages/connected-solid/src/resources/SolidResource.ts:281
isLoading
▸ isLoading(): boolean
Checks to see if this resource is loading in any way
Returns
boolean
true if the resource is currently loading
Example
resource.read().then(() => {
// Logs "false"
console.log(resource.isLoading())
});
// Logs "true"
console.log(resource.isLoading());
Implementation of
Resource.isLoading
Defined in
packages/connected-solid/src/resources/SolidResource.ts:165
isPresent
▸ isPresent(): undefined | boolean
Is this resource currently present on the Pod
Returns
undefined | boolean
false if the resource is absent, true if not, undefined if unknown
Example
// 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());
}
Implementation of
Resource.isPresent
Defined in
packages/connected-solid/src/resources/SolidResource.ts:338
isReading
▸ isReading(): boolean
Checks to see if this resource is being read
Returns
boolean
true if the resource is currently being read
Example
resource.read().then(() => {
// Logs "false"
console.log(resource.isReading())
});
// Logs "true"
console.log(resource.isReading());
Defined in
packages/connected-solid/src/resources/SolidResource.ts:201
isReloading
▸ isReloading(): boolean
Checks to see if this resource is being read for a subsequent time
Returns
boolean
true if the resource is currently being read for a subsequent time
Example
await resource.read();
resource.read().then(() => {
// Logs "false"
console.log(resource.isCreating())
});
// Logs "true"
console.log(resource.isCreating());
Defined in
packages/connected-solid/src/resources/SolidResource.ts:256
isSubscribedToNotifications
▸ isSubscribedToNotifications(): boolean
Is this resource currently listening to notifications from this document
Returns
boolean
true if the resource is subscribed to notifications, false if not
Example
await resource.subscribeToNotifications();
// Logs "true"
console.log(resource.isSubscribedToNotifications());
Implementation of
Resource.isSubscribedToNotifications
Defined in
packages/connected-solid/src/resources/SolidResource.ts:353
isUnfetched
▸ isUnfetched(): boolean
Check to see if this resource is currently unfetched
Returns
boolean
true if the resource is currently unfetched
Example
// Logs "true"
console.log(resource.isUnetched());
const result = await resource.read();
if (!result.isError) {
// Logs "false"
console.log(resource.isUnfetched());
}
Implementation of
Resource.isUnfetched
Defined in
packages/connected-solid/src/resources/SolidResource.ts:300
onNotification
▸ onNotification(message): Promise\<void>
Function that triggers whenever a notification is recieved.
Parameters
| Name | Type |
|---|---|
message |
SolidNotificationMessage |
Returns
Promise\<void>
Defined in
packages/connected-solid/src/resources/SolidResource.ts:799
read
▸ read(): Promise\<ReadContainerResult | ReadLeafResult>
Reads the resource
Returns
Promise\<ReadContainerResult | ReadLeafResult>
Implementation of
Resource.read
Defined in
packages/connected-solid/src/resources/SolidResource.ts:416
readIfUnfetched
▸ readIfUnfetched(): Promise\<ReadContainerResult | ReadLeafResult>
Reads the resource if it isn't fetched yet
Returns
Promise\<ReadContainerResult | ReadLeafResult>
a ReadResult
Implementation of
Resource.readIfUnfetched
Defined in
packages/connected-solid/src/resources/SolidResource.ts:422
setWac
▸ setWac(wacRule): Promise\<ServerHttpError\<SolidContainer | SolidLeaf> | UnexpectedHttpError\<SolidContainer | SolidLeaf> | UnauthenticatedHttpError\<SolidContainer | SolidLeaf> | UnauthorizedHttpError\<SolidContainer | SolidLeaf> | NoncompliantPodError\<SolidContainer | SolidLeaf> | UnexpectedResourceError\<SolidContainer | SolidLeaf> | NotFoundHttpError\<SolidContainer | SolidLeaf> | SetWacRuleSuccess\<SolidContainer | SolidLeaf>>
Sets access rules for a specific resource
Parameters
| Name | Type | Description |
|---|---|---|
wacRule |
WacRule |
the access rules to set |
Returns
Promise\<ServerHttpError\<SolidContainer | SolidLeaf> | UnexpectedHttpError\<SolidContainer | SolidLeaf> | UnauthenticatedHttpError\<SolidContainer | SolidLeaf> | UnauthorizedHttpError\<SolidContainer | SolidLeaf> | NoncompliantPodError\<SolidContainer | SolidLeaf> | UnexpectedResourceError\<SolidContainer | SolidLeaf> | NotFoundHttpError\<SolidContainer | SolidLeaf> | SetWacRuleSuccess\<SolidContainer | SolidLeaf>>
SetWacRuleResult
Example
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
}
}
});
Defined in
packages/connected-solid/src/resources/SolidResource.ts:724
subscribeToNotifications
▸ subscribeToNotifications(callbacks?): Promise\<string>
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.
Parameters
| Name | Type |
|---|---|
callbacks? |
SubscriptionCallbacks\<SolidNotificationMessage> |
Returns
Promise\<string>
SubscriptionId: A string to use to unsubscribe
Example
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.
#### Implementation of
Resource.subscribeToNotifications
#### Defined in
[packages/connected-solid/src/resources/SolidResource.ts:787](https://github.com/o-development/ldo/blob/db87958cb6f858f6cf7340ba5d9536a3a794d587/packages/connected-solid/src/resources/SolidResource.ts#L787)
___
### toReadResult
▸ **toReadResult**(): [`ReadContainerResult`](../types/ReadContainerResult.md) \| [`ReadLeafResult`](../types/ReadLeafResult.md)
Converts the current state of this resource to a readResult
#### Returns
[`ReadContainerResult`](../types/ReadContainerResult.md) \| [`ReadLeafResult`](../types/ReadLeafResult.md)
a ReadResult
#### Defined in
[packages/connected-solid/src/resources/SolidResource.ts:411](https://github.com/o-development/ldo/blob/db87958cb6f858f6cf7340ba5d9536a3a794d587/packages/connected-solid/src/resources/SolidResource.ts#L411)
___
### unsubscribeFromAllNotifications
▸ **unsubscribeFromAllNotifications**(): `Promise`\<`void`\>
Unsubscribes from all notifications on this resource
#### Returns
`Promise`\<`void`\>
UnsubscribeResult[]
**`Example`**
```typescript
const subscriptionResult = await testContainer.subscribeToNotifications();
await testContainer.unsubscribeFromAllNotifications();
Implementation of
Resource.unsubscribeFromAllNotifications
Defined in
packages/connected-solid/src/resources/SolidResource.ts:851
unsubscribeFromNotifications
▸ unsubscribeFromNotifications(subscriptionId): Promise\<void>
Unsubscribes from changes made to this resource on the Pod
Parameters
| Name | Type |
|---|---|
subscriptionId |
string |
Returns
Promise\<void>
UnsubscribeResult
Example
const subscriptionId = await testContainer.subscribeToNotifications();
await testContainer.unsubscribeFromNotifications(subscriptionId);
Implementation of
Resource.unsubscribeFromNotifications
Defined in
packages/connected-solid/src/resources/SolidResource.ts:834
update
▸ update(datasetChanges): Promise\<IgnoredInvalidUpdateSuccess\<SolidContainer> | UpdateResult\<SolidLeaf>>
UPDATE METHODS
Parameters
| Name | Type |
|---|---|
datasetChanges |
DatasetChanges\<BaseQuad> |
Returns
Promise\<IgnoredInvalidUpdateSuccess\<SolidContainer> | UpdateResult\<SolidLeaf>>
Implementation of
Resource.update
Defined in
packages/connected-solid/src/resources/SolidResource.ts:550
updateWithCreateSuccess
▸ updateWithCreateSuccess(result): void
A helper method updates this resource's internal state upon create success
Parameters
| Name | Type |
|---|---|
result |
ResourceSuccess\<Resource\<string>> |
Returns
void
Defined in
packages/connected-solid/src/resources/SolidResource.ts:473
updateWithDeleteSuccess
▸ updateWithDeleteSuccess(_result): void
A helper method updates this resource's internal state upon delete success
Parameters
| Name | Type |
|---|---|
_result |
DeleteSuccess\<SolidResource> |
Returns
void
Defined in
packages/connected-solid/src/resources/SolidResource.ts:442
updateWithReadSuccess
▸ updateWithReadSuccess(result): void
A helper method updates this resource's internal state upon read success
Parameters
| Name | Type | Description |
|---|---|---|
result |
ReadSuccess\<Resource\<string>> |
the result of the read success |
Returns
void