Class: Resource
Represents the current status of a specific Resource on a Pod as known by LDO.
Hierarchy
TypedEventEmitter
\<{update
: () =>void
},this
>
↳ Resource
↳↳ Container
↳↳ Leaf
Constructors
constructor
• new Resource(context
): Resource
Parameters
Name | Type | Description |
---|---|---|
context |
SolidLdoDatasetContext |
SolidLdoDatasetContext for the parent dataset |
Returns
Overrides
(EventEmitter as new () =\> TypedEmitter\<{ update: () =\> void; }\>).constructor
Defined in
packages/solid/src/resource/Resource.ts:101
Properties
absent
• Protected
absent: undefined
| boolean
True if this resource has been fetched but does not exist
Defined in
packages/solid/src/resource/Resource.ts:84
context
• Protected
Readonly
context: SolidLdoDatasetContext
The SolidLdoDatasetContext from the Parent Dataset
Defined in
packages/solid/src/resource/Resource.ts:51
didInitialFetch
• Protected
didInitialFetch: boolean
= false
True if this resource has been fetched at least once
Defined in
packages/solid/src/resource/Resource.ts:78
requester
• Protected
Readonly
Abstract
requester: BatchedRequester
Batched Requester for the Resource
Defined in
packages/solid/src/resource/Resource.ts:72
status
• Abstract
status: RequesterResult
The status of the last request made for this resource
Defined in
packages/solid/src/resource/Resource.ts:66
type
• Readonly
Abstract
type: string
The type of resource (leaf or container)
Defined in
packages/solid/src/resource/Resource.ts:61
uri
• Readonly
Abstract
uri: string
The uri of the resource
Defined in
packages/solid/src/resource/Resource.ts:56
wacRule
• Protected
Optional
wacRule: WacRule
If a wac rule was fetched, it is cached here
Defined in
packages/solid/src/resource/Resource.ts:96
wacUri
• Protected
Optional
wacUri: LeafUri
If a wac uri is fetched, it is cached here
Defined in
packages/solid/src/resource/Resource.ts:90
Methods
addListener
▸ addListener\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).addListener
Defined in
node_modules/typed-emitter/index.d.ts:22
createAndOverwrite
▸ createAndOverwrite(): Promise
\<ResourceResult
\<UnexpectedResourceError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
, Leaf
| Container
>>
Creates a resource at this URI and overwrites any that already exists
Returns
Promise
\<ResourceResult
\<UnexpectedResourceError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
, Leaf
| Container
>>
CreateAndOverwriteResult
Example
Defined in
packages/solid/src/resource/Resource.ts:444
createIfAbsent
▸ createIfAbsent(): Promise
\<ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
, Leaf
| Container
>>
Creates a resource at this URI if the resource doesn't already exist
Returns
Promise
\<ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
, Leaf
| Container
>>
CreateIfAbsentResult
Example
Defined in
packages/solid/src/resource/Resource.ts:480
emit
▸ emit\<E
>(event
, ...args
): boolean
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
...args |
Parameters \<{ update : () => void }[E ]> |
Returns
boolean
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).emit
Defined in
node_modules/typed-emitter/index.d.ts:32
emitThisAndParent
▸ emitThisAndParent(): void
Emits an update event for both this resource and the parent
Returns
void
Defined in
packages/solid/src/resource/Resource.ts:313
eventNames
▸ eventNames(): (string
| symbol
)[]
Returns
(string
| symbol
)[]
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).eventNames
Defined in
node_modules/typed-emitter/index.d.ts:34
getMaxListeners
▸ getMaxListeners(): number
Returns
number
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).getMaxListeners
Defined in
node_modules/typed-emitter/index.d.ts:39
getParentContainer
▸ getParentContainer(): Promise
\<undefined
| CheckRootResultError
| Container
>
Returns
Promise
\<undefined
| CheckRootResultError
| Container
>
Defined in
packages/solid/src/resource/Resource.ts:529
getRootContainer
▸ getRootContainer(): Promise
\<CheckRootResultError
| Container
>
Gets the root container for this resource.
Returns
Promise
\<CheckRootResultError
| Container
>
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/solid/src/resource/Resource.ts:527
getWac
▸ getWac(options?
): Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| NotFoundHttpError
| GetWacRuleSuccess
| WacRuleAbsent
>
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
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| NotFoundHttpError
| GetWacRuleSuccess
| WacRuleAbsent
>
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/solid/src/resource/Resource.ts:596
getWacUri
▸ getWacUri(options?
): Promise
\<GetWacUriResult
>
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
>
WAC Rules results
Defined in
packages/solid/src/resource/Resource.ts:545
handleCreateAndOverwrite
▸ handleCreateAndOverwrite(): Promise
\<UnexpectedResourceError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
>
Helper method that handles the core functions for creating and overwriting a resource
Returns
Promise
\<UnexpectedResourceError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
>
DeleteResult
Defined in
packages/solid/src/resource/Resource.ts:457
handleCreateIfAbsent
▸ handleCreateIfAbsent(): Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
>
Helper method that handles the core functions for creating a resource if absent
Returns
Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| CreateSuccess
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
>
DeleteResult
Defined in
packages/solid/src/resource/Resource.ts:493
handleDelete
▸ handleDelete(): Promise
\<DeleteResult
>
Helper method that handles the core functions for deleting a resource
Returns
Promise
\<DeleteResult
>
DeleteResult
Defined in
packages/solid/src/resource/Resource.ts:405
handleRead
▸ handleRead(): Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
>
A helper method that handles the core functions for reading
Returns
Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
>
ReadResult
Defined in
packages/solid/src/resource/Resource.ts:343
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 = resource.read();
if (!result.isError) {
// False if the resource exists, true if it does not
console.log(resource.isAbsent());
}
Defined in
packages/solid/src/resource/Resource.ts:280
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/solid/src/resource/Resource.ts:144
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/solid/src/resource/Resource.ts:180
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());
Defined in
packages/solid/src/resource/Resource.ts:198
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());
}
Defined in
packages/solid/src/resource/Resource.ts:242
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());
Defined in
packages/solid/src/resource/Resource.ts:126
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 = resource.read();
if (!result.isError) {
// True if the resource exists, false if it does not
console.log(resource.isPresent());
}
Defined in
packages/solid/src/resource/Resource.ts:299
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/solid/src/resource/Resource.ts:162
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/solid/src/resource/Resource.ts:217
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());
}
Defined in
packages/solid/src/resource/Resource.ts:261
listenerCount
▸ listenerCount\<E
>(event
): number
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
Returns
number
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).listenerCount
Defined in
node_modules/typed-emitter/index.d.ts:37
listeners
▸ listeners\<E
>(event
): { update
: () => void
}[E
][]
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
Returns
{ update
: () => void
}[E
][]
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).listeners
Defined in
node_modules/typed-emitter/index.d.ts:36
off
▸ off\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).off
Defined in
node_modules/typed-emitter/index.d.ts:28
on
▸ on\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).on
Defined in
node_modules/typed-emitter/index.d.ts:23
once
▸ once\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).once
Defined in
node_modules/typed-emitter/index.d.ts:24
prependListener
▸ prependListener\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).prependListener
Defined in
node_modules/typed-emitter/index.d.ts:25
prependOnceListener
▸ prependOnceListener\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).prependOnceListener
Defined in
node_modules/typed-emitter/index.d.ts:26
rawListeners
▸ rawListeners\<E
>(event
): { update
: () => void
}[E
][]
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
Returns
{ update
: () => void
}[E
][]
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).rawListeners
Defined in
node_modules/typed-emitter/index.d.ts:35
read
▸ read(): Promise
\<ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
, Leaf
| Container
>>
Reads the resource
Returns
Promise
\<ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
, Leaf
| Container
>>
Defined in
packages/solid/src/resource/Resource.ts:365
readIfUnfetched
▸ readIfUnfetched(): Promise
\<ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
, Leaf
| Container
>>
Reads the resource if it isn't fetched yet
Returns
Promise
\<ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
, Leaf
| Container
>>
a ReadResult
Defined in
packages/solid/src/resource/Resource.ts:373
removeAllListeners
▸ removeAllListeners\<E
>(event?
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event? |
E |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).removeAllListeners
Defined in
node_modules/typed-emitter/index.d.ts:29
removeListener
▸ removeListener\<E
>(event
, listener
): this
Type parameters
Name | Type |
---|---|
E |
extends "update" |
Parameters
Name | Type |
---|---|
event |
E |
listener |
{ update : () => void }[E ] |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).removeListener
Defined in
node_modules/typed-emitter/index.d.ts:30
setMaxListeners
▸ setMaxListeners(maxListeners
): this
Parameters
Name | Type |
---|---|
maxListeners |
number |
Returns
this
Inherited from
(EventEmitter as new () => TypedEmitter\<{ update: () => void; }>).setMaxListeners
Defined in
node_modules/typed-emitter/index.d.ts:40
setWac
▸ setWac(wacRule
): Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| NotFoundHttpError
| SetWacRuleSuccess
>
Sets access rules for a specific resource
Parameters
Name | Type | Description |
---|---|---|
wacRule |
WacRule |
the access rules to set |
Returns
Promise
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| NotFoundHttpError
| SetWacRuleSuccess
>
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/solid/src/resource/Resource.ts:669
toReadResult
▸ toReadResult(): ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
, Leaf
| Container
>
Converts the current state of this resource to a readResult
Returns
ResourceResult
\<UnexpectedResourceError
| NoncompliantPodError
| ServerHttpError
| UnexpectedHttpError
| UnauthenticatedHttpError
| UnauthorizedHttpError
| BinaryReadSuccess
| DataReadSuccess
| ContainerReadSuccess
| AbsentReadSuccess
, Leaf
| Container
>
a ReadResult
Defined in
packages/solid/src/resource/Resource.ts:357
updateWithCreateSuccess
▸ updateWithCreateSuccess(result
): void
A helper method updates this resource's internal state upon create success
Parameters
Name | Type |
---|---|
result |
ResourceSuccess |
Returns
void
Defined in
packages/solid/src/resource/Resource.ts:424
updateWithDeleteSuccess
▸ updateWithDeleteSuccess(_result
): void
A helper method updates this resource's internal state upon delete success
Parameters
Name | Type |
---|---|
_result |
DeleteSuccess |
Returns
void
Defined in
packages/solid/src/resource/Resource.ts:395
updateWithReadSuccess
▸ updateWithReadSuccess(result
): void
A helper method updates this resource's internal state upon read success
Parameters
Name | Type | Description |
---|---|---|
result |
ReadSuccess |
the result of the read success |
Returns
void