Skip to content

Documentation / @imvu/client / Resource

Abstract Class: Resource<TRelations, TUpdates> ​

Defined in: packages/client/src/resources/Resource.ts:17

Shared state for any remotely addressable node, edge, or collection document.

Extends ​

Extended by ​

Type Parameters ​

Type ParameterDefault type
TRelationsAPIResource["relations"]
TUpdatesNonNullable<APIResource["updates"]>

Constructors ​

Constructor ​

ts
new Resource<TRelations, TUpdates>(client, options?): Resource<TRelations, TUpdates>;

Defined in: packages/client/src/resources/Resource.ts:23

Parameters ​

ParameterType
clientClient
options?ResourceOptions

Returns ​

Resource<TRelations, TUpdates>

Overrides ​

RemoteDocument.constructor

Properties ​

_id ​

ts
_id: string = '';

Defined in: packages/client/src/resources/Resource.ts:21


_url ​

ts
protected _url: string = '';

Defined in: packages/client/src/resources/RemoteDocument.ts:13

Inherited from ​

RemoteDocument._url


client ​

ts
protected readonly client: Client;

Defined in: packages/client/src/resources/RemoteDocument.ts:16

Inherited from ​

RemoteDocument.client


fetchedAt ​

ts
fetchedAt: number = 0;

Defined in: packages/client/src/resources/Resource.ts:39

When this instance last received data from the API (ms since epoch); 0 if never.


options ​

ts
protected options: ResourceOptions = {};

Defined in: packages/client/src/resources/Resource.ts:25


relations ​

ts
relations: Partial<TRelations> = {};

Defined in: packages/client/src/resources/Resource.ts:44

Internal


revision ​

ts
revision: number = 0;

Defined in: packages/client/src/resources/RemoteDocument.ts:8

Inherited from ​

RemoteDocument.revision


stale ​

ts
stale: boolean = false;

Defined in: packages/client/src/resources/RemoteDocument.ts:9

Inherited from ​

RemoteDocument.stale


updates ​

ts
updates: Partial<TUpdates> = {};

Defined in: packages/client/src/resources/Resource.ts:49

Internal


updateTarget ​

ts
updateTarget: 
  | APIUpdateTarget
  | null
  | undefined;

Defined in: packages/client/src/resources/RemoteDocument.ts:11

Undefined until metadata is loaded; null means the API explicitly provides no update target.

Inherited from ​

RemoteDocument.updateTarget

Accessors ​

id ​

Get Signature ​

ts
get id(): string;

Defined in: packages/client/src/resources/Resource.ts:34

Returns ​

string


url ​

Get Signature ​

ts
get url(): string;

Defined in: packages/client/src/resources/RemoteDocument.ts:28

Canonical REST URL and cache identity for this document.

Returns ​

string

Inherited from ​

RemoteDocument.url

Methods ​

_applyRemoteMetadata() ​

ts
_applyRemoteMetadata(url, updateTarget): void;

Defined in: packages/client/src/resources/RemoteDocument.ts:33

Internal

Apply address/update metadata from an authoritative REST response.

Parameters ​

ParameterType
urlstring
updateTargetAPIUpdateTarget | null

Returns ​

void

Inherited from ​

RemoteDocument._applyRemoteMetadata


_hydrate() ​

ts
_hydrate(node): void;

Defined in: packages/client/src/resources/Resource.ts:69

Internal

Refresh this canonical instance from an authoritative REST document.

Parameters ​

ParameterType
nodeAPIResource

Returns ​

void


_invalidate() ​

ts
_invalidate(): void;

Defined in: packages/client/src/resources/RemoteDocument.ts:40

Internal

Mark this document stale after an IMQ invalidation.

Returns ​

void

Inherited from ​

RemoteDocument._invalidate


_patch() ​

ts
_patch(data): void;

Defined in: packages/client/src/resources/Resource.ts:87

Internal

Assign fields from a raw (possibly partial) API payload. Used by build for the initial data and, later, by IMQ for in-place live updates — hence the in guards, so a partial payload only touches the fields it carries. Subclasses override this and call super._patch(data).

Parameters ​

ParameterType
dataRecord<string, any>

Returns ​

void


authenticated() ​

ts
protected authenticated(): void;

Defined in: packages/client/src/resources/Resource.ts:104

Returns ​

void


collectionRelationship() ​

ts
protected collectionRelationship<T, K>(
   relation, 
   cls, 
   options?
): Collection<T>;

Defined in: packages/client/src/resources/Resource.ts:122

Type Parameters ​

Type Parameter
T extends Resource<APIRelations, APIUpdateTarget>
K extends string | number | symbol

Parameters ​

ParameterType
relationK
clsConstructor<T>
options?CollectionOptions

Returns ​

Collection<T>


refresh() ​

ts
refresh(): Promise<Resource<TRelations, TUpdates>>;

Defined in: packages/client/src/resources/Resource.ts:95

Re-read this resource from REST and update it in place. Resolves to the same instance, so references held elsewhere see the fresh data and stale clears.

Returns ​

Promise<Resource<TRelations, TUpdates>>


relationship() ​

ts
protected relationship<T, K>(
   relation, 
   cls, 
   options?
): Promise<T | null>;

Defined in: packages/client/src/resources/Resource.ts:110

Type Parameters ​

Type Parameter
T extends Resource<APIRelations, APIUpdateTarget>
K extends string | number | symbol

Parameters ​

ParameterType
relationK
clsConstructor<T>
options?FetchOptions

Returns ​

Promise<T | null>


watch() ​

ts
watch(): Promise<DocumentWatch<Resource<TRelations, TUpdates>>>;

Defined in: packages/client/src/resources/RemoteDocument.ts:46

Observe explicit IMQ invalidations for this document.

Returns ​

Promise<DocumentWatch<Resource<TRelations, TUpdates>>>

Inherited from ​

RemoteDocument.watch


build() ​

ts
static build<T>(
   this, 
   client, 
   node
): T;

Defined in: packages/client/src/resources/Resource.ts:57

Construct a resource from a raw API node, then populate it via _patch. No validation — we trust the wire types and rely on tests for API drift (see MODERNIZATION.md). Fields keep their defaults until _patch overwrites them, so an instance is never in an unset state.

Type Parameters ​

Type Parameter
T extends Resource<any, APIUpdateTarget>

Parameters ​

ParameterType
thisnew (client, options?) => T
clientClient
nodeAPIResource

Returns ​

T

Released under the MIT License.