[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / world/changelog/PlainData

# world/changelog/PlainData

## Type Aliases

### PlainData

> **PlainData** = `null` \| `boolean` \| `number` \| `bigint` \| `string` \| [`PlainTypedArray`](#plaintypedarray) \| readonly [`PlainData`](#plaindata)[] \| [`PlainRecord`](#plainrecord)

Defined in: [packages/prismarine/src/world/changelog/PlainData.ts:33](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L33)

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](#plainof),
[samePlain](#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L42)

An object whose every property is [PlainData](#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`](#plaindata)

***

### PlainTypedArray

> **PlainTypedArray** = `Int8Array` \| `Uint8Array` \| `Uint8ClampedArray` \| `Int16Array` \| `Uint16Array` \| `Int32Array` \| `Uint32Array` \| `Float32Array` \| `Float64Array` \| `BigInt64Array` \| `BigUint64Array`

Defined in: [packages/prismarine/src/world/changelog/PlainData.ts:7](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L7)

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](https://jsprismarine.dev/adr/0011-a-world-exchanges-only-plain-data.md)).

## Functions

### isPlainList()

> **isPlainList**(`value`): `value is readonly PlainData[]`

Defined in: [packages/prismarine/src/world/changelog/PlainData.ts:150](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L150)

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`](#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L140)

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

#### Parameters

##### value

[`PlainData`](#plaindata)

The value.

#### Returns

`value is PlainRecord`

Whether it is a [PlainRecord](#plainrecord).

***

### plainOf()

> **plainOf**(`value`): [`PlainData`](#plaindata) \| `undefined`

Defined in: [packages/prismarine/src/world/changelog/PlainData.ts:57](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L57)

Copies a value built from plain parts into [PlainData](#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`](#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/changelog/PlainData.ts#L105)

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`](#plaindata)

One value.

##### right

[`PlainData`](#plaindata)

The other.

#### Returns

`boolean`

Whether they are equal.
