Skip to content

Commit 6626d79

Browse files
committed
docs: add library API docstrings
1 parent 5fd1d18 commit 6626d79

151 files changed

Lines changed: 1317 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libraries/mc-common/src/constants.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { Vector3, RGB, RGBA } from "@minecraft/server";
22

3+
/**
4+
* Type definition for a property value.
5+
*/
36
export type PropertyValue = string | number | boolean | Vector3 | undefined;
47

8+
/**
9+
* Shared max effect value.
10+
*/
511
export const MAX_EFFECT = 20000000;
612

13+
/**
14+
* Shared center entity value.
15+
*/
716
export const CENTER_ENTITY = { x: 0.5, y: 0, z: 0.5 };
817

18+
/**
19+
* Type definition for a color.
20+
*/
921
export type Color = RGBA | RGB;
1022

1123
/**
@@ -45,6 +57,9 @@ export namespace Colors {
4557
export const Clear: RGBA = { ...Colors.Black, alpha: 0 };
4658
}
4759

60+
/**
61+
* Shared replaceable blocks value.
62+
*/
4863
export const REPLACEABLE_BLOCKS = [
4964
"vine",
5065
"fern",
@@ -61,6 +76,9 @@ export const REPLACEABLE_BLOCKS = [
6176
"snow_layer",
6277
];
6378

79+
/**
80+
* Shared candles value.
81+
*/
6482
export const CANDLES = [
6583
"candle",
6684
"white_candle",
@@ -81,6 +99,9 @@ export const CANDLES = [
8199
"pink_candle",
82100
];
83101

102+
/**
103+
* Shared colors value.
104+
*/
84105
export const COLORS = [
85106
"white",
86107
"light_gray",
@@ -100,6 +121,9 @@ export const COLORS = [
100121
"pink",
101122
];
102123

124+
/**
125+
* Shared wood types value.
126+
*/
103127
export const WOOD_TYPES = [
104128
"oak",
105129
"spruce",
@@ -115,6 +139,9 @@ export const WOOD_TYPES = [
115139
"warped",
116140
];
117141

142+
/**
143+
* Allowed values for a chat color.
144+
*/
118145
export enum ChatColor {
119146
Aqua = `§b`,
120147
Black = `§0`,
@@ -146,11 +173,17 @@ export enum ChatColor {
146173
Yellow = `§e`,
147174
}
148175

176+
/**
177+
* Allowed values for an environment.
178+
*/
149179
export enum Environment {
150180
Development = "development",
151181
Production = "production",
152182
}
153183

184+
/**
185+
* Allowed values for an oxidization.
186+
*/
154187
export enum Oxidization {
155188
Normal = 0,
156189
Exposed = 1,

libraries/mc-common/src/data/data_storage.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ import { DataUtils, DynamicObject } from "./utils";
44
import { PropertyValue } from "../constants";
55
import { DataStorageEvents, DeleteDataEvent, ReadDataEvent, WriteDataEvent } from "./event";
66

7+
/**
8+
* Options for configuring the data storage.
9+
*/
710
export interface DataStorageOptions {
811
object?: DynamicObject;
912
gzip?: boolean;
1013
}
1114

15+
/**
16+
* Provides data storage behavior.
17+
*/
1218
export class DataStorage {
1319
static instances = new Map<string, DataStorage>();
1420

@@ -235,6 +241,9 @@ export class DataStorage {
235241
onWrite?(): void {}
236242
}
237243

244+
/**
245+
* Interface describing a versioned data.
246+
*/
238247
export interface VersionedDataSchema {
239248
minFormat: number;
240249
maxFormat: number;
@@ -243,6 +252,9 @@ export interface VersionedDataSchema {
243252

244253
// TODO: Cache gzipped data storage.
245254

255+
/**
256+
* Provides versioned data storage behavior.
257+
*/
246258
export class VersionedDataStorage extends DataStorage {
247259
readonly formatVersion: number;
248260
schemas = new Map<string, VersionedDataSchema>();
@@ -288,12 +300,18 @@ export class VersionedDataStorage extends DataStorage {
288300
}
289301
}
290302

303+
/**
304+
* Provides local storage behavior.
305+
*/
291306
export class LocalStorage extends DataStorage {
292307
constructor() {
293308
super("mcutils:local_storage");
294309
}
295310
}
296311

312+
/**
313+
* Provides session storage behavior.
314+
*/
297315
export class SessionStorage extends DataStorage {
298316
constructor() {
299317
super("mcutils:session_storage");
@@ -304,7 +322,13 @@ export class SessionStorage extends DataStorage {
304322
}
305323
}
306324

325+
/**
326+
* Shared local storage value.
327+
*/
307328
export const localStorage = new LocalStorage();
329+
/**
330+
* Shared session storage value.
331+
*/
308332
export const sessionStorage = new SessionStorage();
309333

310334
// Events

libraries/mc-common/src/data/decode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ungzip, Data } from "pako";
22

3+
/**
4+
* Utility helpers for decode.
5+
*/
36
export class DecodeUtils {
47
/**
58
* Decodes a Base64-encoded string into raw bytes.

libraries/mc-common/src/data/dynamic_storage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Vector3 } from "@minecraft/server";
22
import { DataStorageOptions, VersionedDataStorage } from "./data_storage";
33

4+
/**
5+
* Provides dynamic storage behavior.
6+
*/
47
export class DynamicStorage {
58
readonly store: VersionedDataStorage;
69

libraries/mc-common/src/data/encode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { gzip as pakoGZip, Uint8ArrayReturnType } from "pako";
22

3+
/**
4+
* Utility helpers for encode.
5+
*/
36
export class EncodeUtils {
47
/**
58
* Compresses the provided string to gzip format.

libraries/mc-common/src/data/event.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { DataStorage } from "../data";
22
import { EventSignal } from "../event";
33

4+
/**
5+
* Event payload for data callbacks.
6+
*/
47
export abstract class DataEvent {
58
constructor(store: DataStorage, propertyName?: string) {
69
this.store = store;
@@ -11,18 +14,39 @@ export abstract class DataEvent {
1114
readonly propertyName: string | undefined;
1215
}
1316

17+
/**
18+
* Event payload for read data callbacks.
19+
*/
1420
export class ReadDataEvent extends DataEvent {}
1521

22+
/**
23+
* Event payload for write data callbacks.
24+
*/
1625
export class WriteDataEvent extends DataEvent {}
1726

27+
/**
28+
* Event payload for delete data callbacks.
29+
*/
1830
export class DeleteDataEvent extends DataEvent {}
1931

32+
/**
33+
* Event signal for subscribing to read data events.
34+
*/
2035
export class ReadDataEventSignal extends EventSignal<ReadDataEvent> {}
2136

37+
/**
38+
* Event signal for subscribing to write data events.
39+
*/
2240
export class WriteDataEventSignal extends EventSignal<WriteDataEvent> {}
2341

42+
/**
43+
* Event signal for subscribing to delete data events.
44+
*/
2445
export class DeleteDataEventSignal extends EventSignal<DeleteDataEvent> {}
2546

47+
/**
48+
* Provides data storage events behavior.
49+
*/
2650
export class DataStorageEvents {
2751
private constructor() {}
2852

libraries/mc-common/src/data/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import { ConditionUtils } from "../validation";
2727
*/
2828
export type DynamicObject = World | Entity | ItemStack | ContainerSlot;
2929

30+
/**
31+
* Utility helpers for data.
32+
*/
3033
export abstract class DataUtils {
3134
/**
3235
* Creates a deep copy of JSON data.

libraries/mc-common/src/error.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import { LocationInUnloadedChunkError, LocationOutOfWorldBoundariesError } from "@minecraft/server";
66

7+
/**
8+
* Utility helpers for error.
9+
*/
710
export class ErrorUtils {
811
/**
912
* Wraps the callback in a try-catch statement, making the error silent.
@@ -61,11 +64,17 @@ export class ErrorUtils {
6164
}
6265
}
6366

67+
/**
68+
* Interface describing a validation issue.
69+
*/
6470
export interface ValidationIssue {
6571
path: string;
6672
message: string;
6773
}
6874

75+
/**
76+
* Provides validation error behavior.
77+
*/
6978
export class ValidationError extends Error {
7079
public readonly issues: ValidationIssue[];
7180

libraries/mc-common/src/event/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
/**
2+
* Interface describing an event listener.
3+
*/
14
export interface EventListener<T, O> {
25
callback: (event: T) => void;
36
options?: O;
47
}
58

9+
/**
10+
* Event signal for subscribing to event signal events.
11+
*/
612
export abstract class EventSignal<T, O = undefined> {
713
listeners: EventListener<T, O>[] = [];
814

libraries/mc-common/src/identifier.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
ItemType,
1212
} from "@minecraft/server";
1313

14+
/**
15+
* Type definition for an id.
16+
*/
1417
export type Id =
1518
| string
1619
| String
@@ -26,6 +29,9 @@ export type Id =
2629
| EffectType
2730
| EnchantmentType;
2831

32+
/**
33+
* Provides identifier behavior.
34+
*/
2935
export class Identifier {
3036
namespace: string;
3137
path: string;

0 commit comments

Comments
 (0)