@colyseus/schema
Version:
Binary state serializer with delta encoding for games
69 lines (68 loc) • 3.13 kB
TypeScript
import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $refId } from "../symbols.js";
import { ChangeTree, IRef } from "../../encoder/ChangeTree.js";
import { Collection } from "../HelperTypes.js";
import type { StateView } from "../../encoder/StateView.js";
import type { Schema } from "../../Schema.js";
export declare class MapSchema<V = any, K extends string = string> implements Map<K, V>, Collection<K, V, [K, V]>, IRef {
[$changes]: ChangeTree;
[$refId]?: number;
protected childType: new () => V;
protected [$childType]: string | typeof Schema;
protected $items: Map<K, V>;
protected $indexes: Map<number, K>;
protected deletedItems: {
[index: string]: V;
};
static [$encoder]: import("../../encoder/EncodeOperation.js").EncodeOperation<any>;
static [$decoder]: import("../../decoder/DecodeOperation.js").DecodeOperation<any>;
/**
* Determine if a property must be filtered.
* - If returns false, the property is NOT going to be encoded.
* - If returns true, the property is going to be encoded.
*
* Encoding with "filters" happens in two steps:
* - First, the encoder iterates over all "not owned" properties and encodes them.
* - Then, the encoder iterates over all "owned" properties per instance and encodes them.
*/
static [$filter](ref: MapSchema, index: number, view: StateView): boolean;
static is(type: any): boolean;
constructor(initialValues?: Map<K, V> | Record<K, V>);
/** Iterator */
[Symbol.iterator](): ReturnType<Map<K, V>[typeof Symbol.iterator]>;
get [Symbol.toStringTag](): string;
static get [Symbol.species](): typeof MapSchema;
set(key: K, value: V): this;
get(key: K): V | undefined;
/**
* Returns the value for `key` if present. Otherwise inserts `defaultValue`
* (tracked as an ADD change, like `set()`) and returns it.
*
* Mirrors `Map.prototype.getOrInsert` (TC39 "upsert" proposal, typed in
* TypeScript 6's standard library).
*/
getOrInsert(key: K, defaultValue: V): V;
/**
* Returns the value for `key` if present. Otherwise computes a value via
* `callbackfn(key)`, inserts it (tracked as an ADD change, like `set()`)
* and returns it. The callback is only invoked when the key is missing.
*
* Mirrors `Map.prototype.getOrInsertComputed` (TC39 "upsert" proposal,
* typed in TypeScript 6's standard library).
*/
getOrInsertComputed(key: K, callbackfn: (key: K) => V): V;
delete(key: K): boolean;
clear(): void;
has(key: K): boolean;
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void): void;
entries(): MapIterator<[K, V]>;
keys(): MapIterator<K>;
values(): MapIterator<V>;
get size(): number;
protected setIndex(index: number, key: K): void;
protected getIndex(index: number): K;
[$getByIndex](index: number): V | undefined;
[$deleteByIndex](index: number): void;
protected [$onEncodeEnd](): void;
toJSON(): any;
clone(isDecoding?: boolean): MapSchema<V>;
}