Skip to content

API reference / @jsprismarine/prismarine / world/changelog/PlainData

world/changelog/PlainData ​

Type Aliases ​

PlainData ​

PlainData = null | boolean | number | bigint | string | PlainTypedArray | readonly PlainData[] | PlainRecord

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:33

A value that survives a structured clone unchanged: ids, numbers, strings, plain objects, arrays and typed arrays.

No functions, no class instances with behavior and no undefined, so an object with methods (a Vector3, an entity) does not satisfy it and the compiler rejects it where plain data is required.

A plain value is a tree, as a JSON value is: no object or array holds itself, directly or further down. A structured clone would keep such a cycle, but plainOf, samePlain and estimatePlainBytes walk each value down to its leaves, which a cycle never reaches.


PlainRecord ​

PlainRecord = object

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:42

An object whose every property is PlainData.

Declare a shape that has to satisfy it with a type alias, not an interface: only an object type literal gets the implicit index signature that makes it assignable here.

Index Signature ​

[key: string]: PlainData


PlainTypedArray ​

PlainTypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:7

A typed array: the one kind of class instance plain data may hold.

The structured clone algorithm copies these, so a value holding one can still cross to another thread (ADR 0011).

Functions ​

isPlainList() ​

isPlainList(value): value is readonly PlainData[]

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:150

Whether a plain value is a list. Array.isArray does not narrow a readonly array type out of a union, so code that walks plain data asks this instead.

Parameters ​

value ​

PlainData

The value.

Returns ​

value is readonly PlainData[]

Whether it is a list.


isPlainRecord() ​

isPlainRecord(value): value is PlainRecord

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:140

Whether a plain value is an object of plain values, and not a list, a typed array or a primitive.

Parameters ​

value ​

PlainData

The value.

Returns ​

value is PlainRecord

Whether it is a PlainRecord.


plainOf() ​

plainOf(value): PlainData | undefined

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:57

Copies a value built from plain parts into PlainData, the way a JSON round trip would but without the string: an object field holding undefined is left out and an array item holding undefined becomes null. Typed arrays are copied.

Entity state holds interfaces such as an item stack or a position, which the compiler cannot prove plain because an interface has no index signature, so a setter that logs one copies it through here.

Parameters ​

value ​

unknown

The value to copy.

Returns ​

PlainData | undefined

The copy, or undefined when the value, or a part of it, has no plain form: a function, a symbol, undefined itself, or an object with a prototype of its own such as a Map.


samePlain() ​

samePlain(left, right): boolean

Defined in: packages/prismarine/src/world/changelog/PlainData.ts:105

Whether two plain values hold the same data: the same primitives (Object.is, so 0 and -0 differ), typed arrays of the same kind with equal elements, arrays with equal items in order, and objects with the same keys holding equal values in any order.

Parameters ​

left ​

PlainData

One value.

PlainData

The other.

Returns ​

boolean

Whether they are equal.