Map

near-runtime-ts > "near" > collections > Map

Class: Map

A map class that implements a persistent unordered map. NOTE: The Map doesn't store keys, so if you need to retrieve them, include keys in the values.

Type parameters

K

V

Hierarchy

Map

Index

Constructors

  • constructor

Methods

  • contains

  • delete

  • get

  • set

  • values

Constructors

constructor

new Map(prefix: string): Map

Defined in near.ts:678

Creates or restores a persistent map with a given storage prefix. Always use a unique storage prefix for different collections.

Parameters:

Name

Type

Description

prefix

string

A prefix to use for every key of this map.

Returns: Map

Methods

contains

contains(key: K): bool

Defined in near.ts:718

Parameters:

Name

Type

Description

key

K

Key to check.

Returns: bool True if the given key present in the map.

delete

delete(key: K): void

Defined in near.ts:726

Removes value and the key from the map.

Parameters:

Name

Type

Description

key

K

Key to remove.

Returns: void

get

get(key: K, defaultValue?: V): V

Defined in near.ts:735

Parameters:

Name

Type

Default value

Description

key

K

-

Key of the element.

Default value defaultValue

V

null

The default value if the key is not present.

Returns: V Value for the given key or the default value.

set

set(key: K, value: V): void

Defined in near.ts:744

Sets the new value for the given key.

Parameters:

Name

Type

Description

key

K

Key of the element.

value

V

The new value of the element.

Returns: void

values

values(start?: K, end?: K, limit?: i32, startInclusive?: bool): V[]

Defined in near.ts:704

Returns values of the map between the given start key and the end key.

Parameters:

Name

Type

Default value

Description

Default value start

K

null

Starting from which key to include values. Default is `null`, means from the beginning.

Default value end

K

null

Up to which key include values (inclusive). Default is `null`, means to the end.

Default value limit

i32

-1

The maximum number of values to return. Default is `-1`, means no limit.

Default value startInclusive

bool

true

Whether the start key is inclusive. Default is `true`, means include start key. It's useful to set it to false for pagination.

Returns: V[]