Skip to content

@web-engine-dev/resources


@web-engine-dev/resources / ResourceRegistryImpl

Class: ResourceRegistryImpl ​

Global registry mapping resource typeId strings to their schemas and descriptors.

Provides iteration over all registered scene resources (for serialization) and sorted access (for editor UI display order).

Remarks ​

Thread-safety: This registry is expected to be populated at module load time and read during runtime. It is not designed for concurrent writes. Registration should occur before any systems start reading from it.

Constructors ​

Constructor ​

new ResourceRegistryImpl(): ResourceRegistryImpl

Returns ​

ResourceRegistryImpl

Accessors ​

size ​

Get Signature ​

get size(): number

The number of registered scene resources.

Returns ​

number

Methods ​

[iterator]() ​

[iterator](): Iterator<[string, ResourceRegistryEntry]>

Iterate all registered scene resources as [typeId, entry] pairs.

Iteration order is insertion order (Map semantics).

Returns ​

Iterator<[string, ResourceRegistryEntry]>


clear() ​

clear(): void

Remove all entries from the registry.

Intended for use in test harnesses to reset state between tests. Production code should not call this.

Returns ​

void


getByDescriptor() ​

getByDescriptor<T>(descriptor): ResourceSchema | undefined

Look up a schema by its resource descriptor.

Extracts the string key from descriptor.type. If the descriptor uses a symbol-based type (from defineResource), this returns undefined because scene-serializable resources must use string-based types.

Type Parameters ​

T ​

T

Parameters ​

descriptor ​

ResourceDescriptor<T>

The resource descriptor to look up

Returns ​

ResourceSchema | undefined

The resource schema, or undefined if not found


getByTypeId() ​

getByTypeId(typeId): ResourceRegistryEntry | undefined

Look up a registry entry by its typeId string.

Parameters ​

typeId ​

string

The stable type identifier from the schema

Returns ​

ResourceRegistryEntry | undefined

The registry entry, or undefined if not found


register() ​

register<T>(descriptor, schema): void

Register a scene resource with its schema.

Type Parameters ​

T ​

T

Parameters ​

descriptor ​

ResourceDescriptor<T>

The resource descriptor (must have a string type matching schema.typeId)

schema ​

ResourceSchema

The resource schema defining fields, defaults, and serialization metadata

Returns ​

void

Throws ​

If a resource with the same typeId is already registered


sortedEntries() ​

sortedEntries(): object[]

Returns all entries sorted by displayOrder (ascending).

Schemas without a displayOrder property default to Infinity, placing them after all explicitly ordered entries. Entries with equal order are sorted by typeId for deterministic output.

Returns ​

object[]

Sorted array of entry objects with typeId, descriptor, and schema

Proprietary software. All rights reserved.