Skip to main content

TypeIndexedMap

@webda/models


Class: TypeIndexedMap<V>

Defined in: packages/models/src/repositories/typeindexedmap.ts:32

Storage map of a MemoryRepository indexing its entries by stored __type

Every model of a MemoryStore shares one storage map: without an index, a query parses every document of the store to find the ones of its model. This map keeps, for each stored __type, the keys holding it, so MemoryRepository.query only visits the entries of its model and subclasses.

The index is lazy: a write only records the key, its __type is read (one JSON.parse) the first time a query needs it. Every write path goes through set / delete / clear — repositories, persistence reload, raw patches of migrations — so the index can never miss an entry.

keysOfTypes returns the keys in the map insertion order, as iterating the map does: query results and offset continuation tokens are unchanged.

Extends​

  • Map<string, V>

Type Parameters​

V​

V = string

Constructors​

Constructor​

new TypeIndexedMap<V>(entries?): TypeIndexedMap<V>

Defined in: packages/models/src/repositories/typeindexedmap.ts:47

Parameters​

entries?​

Iterable<readonly [string, V], any, any> | null

initial entries

Returns​

TypeIndexedMap<V>

Overrides​

Map<string, V>.constructor

Properties​

[toStringTag]​

readonly [toStringTag]: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:137

Inherited from​

Map.[toStringTag]


size​

readonly size: number

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:45

Returns​

the number of elements in the Map.

Inherited from​

Map.size


[species]​

readonly static [species]: MapConstructor

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:319

Inherited from​

Map.[species]

Methods​

[iterator]()​

[iterator](): MapIterator<[string, V]>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:143

Returns an iterable of entries in the map.

Returns​

MapIterator<[string, V]>

Inherited from​

Map.[iterator]


clear()​

clear(): void

Defined in: packages/models/src/repositories/typeindexedmap.ts:98

Delete every entry

Returns​

void

Overrides​

Map.clear


delete()​

delete(key): boolean

Defined in: packages/models/src/repositories/typeindexedmap.ts:88

Delete an entry

Parameters​

key​

string

the key

Returns​

boolean

true when the entry existed

Overrides​

Map.delete


entries()​

entries(): MapIterator<[string, V]>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:148

Returns an iterable of key, value pairs for every entry in the map.

Returns​

MapIterator<[string, V]>

Inherited from​

Map.entries


forEach()​

forEach(callbackfn, thisArg?): void

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:28

Executes a provided function once per each key/value pair in the Map, in insertion order.

Parameters​

callbackfn​

(value, key, map) => void

thisArg?​

any

Returns​

void

Inherited from​

Map.forEach


get()​

get(key): V | undefined

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:33

Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

Parameters​

key​

string

Returns​

V | undefined

Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

Inherited from​

Map.get


has()​

has(key): boolean

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.collection.d.ts:37

Parameters​

key​

string

Returns​

boolean

boolean indicating whether an element with the specified key exists or not.

Inherited from​

Map.has


keys()​

keys(): MapIterator<string>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:153

Returns an iterable of keys in the map

Returns​

MapIterator<string>

Inherited from​

Map.keys


keysOfTypes()​

keysOfTypes(accept): string[]

Defined in: packages/models/src/repositories/typeindexedmap.ts:169

Keys whose stored __type is accepted, in map insertion order

Unreadable entries (not JSON, not a string) are always returned so the error of reading them surfaces.

Parameters​

accept​

(type) => boolean

whether entries of a stored type are wanted, called once per distinct type, with undefined for untyped entries

Returns​

string[]

the keys


set()​

set(key, value): this

Defined in: packages/models/src/repositories/typeindexedmap.ts:74

Set an entry: its type is indexed on the next read

Parameters​

key​

string

the key

value​

V

the stored value

Returns​

this

this

Overrides​

Map.set


values()​

values(): MapIterator<V>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts:158

Returns an iterable of values in the map

Returns​

MapIterator<V>

Inherited from​

Map.values


groupBy()​

static groupBy<K, T>(items, keySelector): Map<K, T[]>

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2024.collection.d.ts:25

Groups members of an iterable according to the return value of the passed callback.

Type Parameters​

K​

K

T​

T

Parameters​

items​

Iterable<T>

An iterable.

keySelector​

(item, index) => K

A callback which will be invoked for each item in items.

Returns​

Map<K, T[]>

Inherited from​

Map.groupBy