@serenityjs/nbt 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @serenityjs/nbt
2
2
 
3
+ ## 0.8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2b1b755`](https://github.com/SerenityJS/serenity/commit/2b1b7550799534f58061e330133bbd459635837c) Thanks [@PMK744](https://github.com/PMK744)! - init v0.8.4-beta
8
+
3
9
  ## 0.8.3
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -8,157 +8,212 @@ declare enum TagType {
8
8
  Long = 4,
9
9
  Float = 5,
10
10
  Double = 6,
11
- ByteArray = 7,
11
+ ByteList = 7,
12
12
  String = 8,
13
13
  List = 9,
14
14
  Compound = 10,
15
- IntArray = 11,
16
- LongArray = 12
15
+ IntList = 11,
16
+ LongList = 12
17
17
  }
18
18
 
19
- interface TagProperties<T = unknown> {
20
- name: string;
21
- value: T;
22
- }
23
- interface ReadingProperties {
19
+ interface ReadWriteOptions {
24
20
  name: boolean;
25
21
  type: boolean;
22
+ varint: boolean;
26
23
  }
27
- interface WritingProperties {
28
- name: boolean;
29
- type: boolean;
30
- }
31
- declare class Tag<T = unknown> {
32
- /**
33
- * The nbt tag type of the data type.
34
- */
35
- static readonly type: TagType;
24
+
25
+ declare abstract class BaseTag {
36
26
  /**
37
27
  * The nbt tag type of the data type.
38
28
  */
39
- readonly type: TagType;
29
+ abstract readonly type: TagType;
40
30
  /**
41
- * The name of the tag.
31
+ * The name of the nbt tag.
42
32
  */
43
- name: string;
33
+ name: string | null;
44
34
  /**
45
- * The value of the tag.
35
+ * Convert the tag to a JSON object.
46
36
  */
47
- value: T;
48
- constructor(properties?: Partial<TagProperties<T>>);
49
- toJSON(): TagProperties<T> & {
50
- type: TagType;
51
- };
52
- static from(buffer: Buffer, varint?: boolean): Tag;
37
+ abstract toJSON(): unknown;
53
38
  /**
54
- * Read a nbt tag from a binary stream.
39
+ * Read the nbt tag from the stream.
55
40
  * @param stream The binary stream to read from.
56
- * @param varint Whether to read the tag as a varint.
41
+ * @param options The options for reading the tag.
57
42
  */
58
- static read(_stream: BinaryStream, _varint?: number | boolean, _properties?: Partial<ReadingProperties>): Tag;
43
+ static read(_stream: BinaryStream, _options?: ReadWriteOptions): BaseTag;
59
44
  /**
60
- * Write a nbt tag to a binary stream.
45
+ * Write the nbt tag to the stream.
61
46
  * @param stream The binary stream to write to.
62
- * @param value The value of the tag.
63
- * @param varint Whether to write the tag as a varint.
47
+ * @param value The value of the tag to write.
48
+ * @param options The options for writing the tag.
64
49
  */
65
- static write(_stream: BinaryStream, _value: Tag, _varint?: number | boolean, _properties?: Partial<WritingProperties>): void;
66
- protected static readString(stream: BinaryStream, varint?: boolean): string;
67
- protected static writeString(value: string, stream: BinaryStream, varint?: boolean): void;
50
+ static write(_stream: BinaryStream, _value: BaseTag, _options?: ReadWriteOptions): void;
68
51
  }
69
52
 
70
- declare class ByteTag extends Tag<number> {
71
- static readonly type = TagType.Byte;
72
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): ByteTag;
73
- static write(stream: BinaryStream, value: ByteTag, varint: boolean, properties?: Partial<WritingProperties>): void;
53
+ declare class ByteTag extends Number implements BaseTag {
54
+ readonly type = TagType.Byte;
55
+ name: string | null;
56
+ /**
57
+ * Create a new ByteTag instance.
58
+ * @param value The byte value.
59
+ * @param name The name of the tag, defaults to null.
60
+ */
61
+ constructor(value: number, name?: string | null);
62
+ toJSON(): number;
63
+ static read(stream: BinaryStream, options?: ReadWriteOptions): ByteTag;
64
+ static write(stream: BinaryStream, value: ByteTag, options?: ReadWriteOptions): void;
74
65
  }
75
66
 
76
- declare class ShortTag extends Tag<number> {
77
- static readonly type = TagType.Short;
78
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): Tag;
79
- static write(stream: BinaryStream, value: ShortTag, varint: boolean, properties?: Partial<WritingProperties>): void;
67
+ declare class ShortTag extends Number implements BaseTag {
68
+ readonly type = TagType.Short;
69
+ name: string | null;
70
+ /**
71
+ * Create a new ShortTag instance.
72
+ * @param value The short value.
73
+ * @param name The name of the tag, defaults to null.
74
+ */
75
+ constructor(value: number, name?: string | null);
76
+ toJSON(): number;
77
+ static read(stream: BinaryStream, options?: ReadWriteOptions): ShortTag;
78
+ static write(stream: BinaryStream, value: ShortTag, options?: ReadWriteOptions): void;
80
79
  }
81
80
 
82
- declare class IntTag extends Tag<number> {
83
- static readonly type = TagType.Int;
84
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): Tag;
85
- static write(stream: BinaryStream, value: IntTag, varint: boolean, properties?: Partial<WritingProperties>): void;
81
+ declare class IntTag extends Number implements BaseTag {
82
+ readonly type = TagType.Int;
83
+ name: string | null;
84
+ /**
85
+ * Create a new IntTag instance.
86
+ * @param value The int value.
87
+ * @param name The name of the tag, defaults to null.
88
+ */
89
+ constructor(value: number, name?: string | null);
90
+ toJSON(): number;
91
+ static read(stream: BinaryStream, options?: ReadWriteOptions): IntTag;
92
+ static write(stream: BinaryStream, value: IntTag, options?: ReadWriteOptions): void;
86
93
  }
87
94
 
88
- declare class LongTag extends Tag<bigint> {
89
- static readonly type = TagType.Long;
90
- toJSON(): TagProperties<bigint> & {
91
- type: TagType;
92
- };
93
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): Tag;
94
- static write(stream: BinaryStream, value: LongTag, varint: boolean, properties?: Partial<WritingProperties>): void;
95
+ declare class LongTag extends String implements BaseTag {
96
+ readonly type = TagType.Long;
97
+ name: string | null;
98
+ /**
99
+ * Create a new LongTag instance.
100
+ * @param value The long value.
101
+ * @param name The name of the tag, defaults to null.
102
+ */
103
+ constructor(value: bigint, name?: string | null);
104
+ toJSON(): string;
105
+ static read(stream: BinaryStream, options?: ReadWriteOptions): LongTag;
106
+ static write(stream: BinaryStream, value: LongTag, options?: ReadWriteOptions): void;
95
107
  }
96
108
 
97
- declare class FloatTag extends Tag<number> {
98
- static readonly type = TagType.Float;
99
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): Tag;
100
- static write(stream: BinaryStream, value: FloatTag, varint: boolean, properties?: Partial<WritingProperties>): void;
109
+ declare class FloatTag extends Number implements BaseTag {
110
+ readonly type = TagType.Float;
111
+ name: string | null;
112
+ /**
113
+ * Create a new FloatTag instance.
114
+ * @param value The float value.
115
+ * @param name The name of the tag, defaults to null.
116
+ */
117
+ constructor(value: number, name?: string | null);
118
+ toJSON(): number;
119
+ static read(stream: BinaryStream, options?: ReadWriteOptions): FloatTag;
120
+ static write(stream: BinaryStream, value: FloatTag, options?: ReadWriteOptions): void;
101
121
  }
102
122
 
103
- declare class DoubleTag extends Tag<number> {
104
- static readonly type = TagType.Double;
105
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): Tag;
106
- static write(stream: BinaryStream, value: DoubleTag, varint: boolean, properties?: Partial<WritingProperties>): void;
123
+ declare class DoubleTag extends Number implements BaseTag {
124
+ readonly type = TagType.Double;
125
+ name: string | null;
126
+ /**
127
+ * Create a new DoubleTag instance.
128
+ * @param value The double value.
129
+ * @param name The name of the tag, defaults to null.
130
+ */
131
+ constructor(value: number, name?: string | null);
132
+ toJSON(): number;
133
+ static read(stream: BinaryStream, options?: ReadWriteOptions): DoubleTag;
134
+ static write(stream: BinaryStream, value: DoubleTag, options?: ReadWriteOptions): void;
107
135
  }
108
136
 
109
- declare class ByteArrayTag extends Tag<Array<number>> {
110
- static readonly type = TagType.ByteArray;
111
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): ByteArrayTag;
112
- static write(stream: BinaryStream, value: ByteArrayTag, varint: boolean, properties?: Partial<WritingProperties>): void;
137
+ declare class ByteListTag extends Array<number> implements BaseTag {
138
+ readonly type = TagType.ByteList;
139
+ name: string | null;
140
+ /**
141
+ * Create a new ByteListTag instance.
142
+ * @param elements The elements of the byte list.
143
+ * @param name The name of the tag, defaults to null.
144
+ */
145
+ constructor(elements: Array<number>, name?: string | null);
146
+ map<U>(callbackfn: (value: number, index: number, array: Array<number>) => U, thisArg?: unknown): Array<U>;
147
+ toJSON(): Array<number>;
148
+ static read(stream: BinaryStream, options?: ReadWriteOptions): ByteListTag;
149
+ static write(stream: BinaryStream, value: ByteListTag, options?: ReadWriteOptions): void;
113
150
  }
114
151
 
115
- declare class StringTag extends Tag<string> {
116
- static readonly type = TagType.String;
117
- static read(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): Tag;
118
- static write(stream: BinaryStream, value: StringTag, varint?: boolean, properties?: Partial<WritingProperties>): void;
152
+ declare class StringTag extends String implements BaseTag {
153
+ readonly type = TagType.String;
154
+ name: string | null;
155
+ /**
156
+ * Create a new StringTag instance.
157
+ * @param value The string value.
158
+ * @param name The name of the tag, defaults to null.
159
+ */
160
+ constructor(value: string, name?: string | null);
161
+ toJSON(): string;
162
+ static read(stream: BinaryStream, options?: ReadWriteOptions): StringTag;
163
+ static write(stream: BinaryStream, value: StringTag, options?: ReadWriteOptions): void;
119
164
  }
120
165
 
121
- type GenericList<T extends Tag<unknown>> = Array<T>;
122
- declare class ListTag<T extends Tag> extends Tag<GenericList<T>> {
123
- static readonly type = TagType.List;
124
- readonly listType: TagType;
125
- value: GenericList<T>;
126
- constructor(properties: Partial<TagProperties<GenericList<T>>> & {
127
- listType: TagType;
128
- });
129
- push(...tag: Array<T>): void;
130
- static read<T extends Tag>(stream: BinaryStream, varint: boolean, properties?: Partial<ReadingProperties>): ListTag<T>;
131
- static write<T extends Tag>(stream: BinaryStream, value: ListTag<T>, varint: boolean, properties?: Partial<ReadingProperties>): void;
166
+ declare class ListTag<T extends BaseTag> extends Array<T> implements BaseTag {
167
+ readonly type = TagType.List;
168
+ name: string | null;
169
+ /**
170
+ * Create a new ListTag instance.
171
+ * @param elements The elements of the list.
172
+ * @param name The name of the tag, defaults to null.
173
+ */
174
+ constructor(elements?: Array<T>, name?: string | null);
175
+ map<U>(callbackfn: (value: T, index: number, array: Array<T>) => U, thisArg?: unknown): Array<U>;
176
+ toJSON(): Array<unknown>;
177
+ static read<T extends BaseTag>(stream: BinaryStream, options?: ReadWriteOptions): ListTag<T>;
178
+ static write<T extends BaseTag>(stream: BinaryStream, value: ListTag<T>, options?: ReadWriteOptions): void;
132
179
  }
133
180
 
134
- type GenericCompound<T = Record<string, Tag>> = T;
135
- declare class CompoundTag<T> extends Tag<GenericCompound<T>> {
136
- static readonly type = TagType.Compound;
137
- value: T;
138
- constructor(properties?: Partial<TagProperties<T>>);
139
- hasTag(name: string): boolean;
140
- getTag<K extends Tag>(name: string): K;
141
- getTags(): Array<Tag>;
142
- setTag(name: string, tag: Tag): void;
143
- addTag(tag: Tag): void;
144
- removeTag(name: string): void;
145
- createByteTag(properties: Partial<TagProperties<number>>): ByteTag;
146
- createShortTag(properties: Partial<TagProperties<number>>): ShortTag;
147
- createIntTag(properties: Partial<TagProperties<number>>): IntTag;
148
- createLongTag(properties: Partial<TagProperties<bigint>>): LongTag;
149
- createFloatTag(properties: Partial<TagProperties<number>>): FloatTag;
150
- createDoubleTag(properties: Partial<TagProperties<number>>): DoubleTag;
151
- createStringTag(properties: Partial<TagProperties<string>>): StringTag;
152
- createListTag<T extends Tag>(properties: Partial<TagProperties<Array<T>>> & {
153
- listType: TagType;
154
- }): ListTag<T>;
155
- createCompoundTag<T>(properties: Partial<TagProperties<GenericCompound<T>>>): CompoundTag<T>;
156
- toJSON(): TagProperties<T> & {
157
- type: TagType;
158
- };
159
- static read<T>(stream: BinaryStream, varint?: boolean, properties?: Partial<ReadingProperties>): CompoundTag<T>;
160
- static write<T>(stream: BinaryStream, value: CompoundTag<T>, varint?: boolean, properties?: Partial<WritingProperties>): void;
161
- static from<T>(buffer: Buffer, varint?: boolean): CompoundTag<T>;
181
+ declare class CompoundTag extends Map<string, BaseTag> implements BaseTag {
182
+ readonly type = TagType.Compound;
183
+ name: string | null;
184
+ /**
185
+ * Create a new CompoundTag instance.
186
+ * @param name The name of the tag, defaults to null.
187
+ */
188
+ constructor(name?: string | null);
189
+ toJSON(): Record<string, unknown>;
190
+ /**
191
+ * Get a nbt tag by its key.
192
+ * @param key The key of the tag to retrieve.
193
+ * @returns The tag associated with the key, or undefined if not found.
194
+ */
195
+ get<T extends BaseTag>(key: string): T | undefined;
196
+ /**
197
+ * Set a nbt tag with a specific key.
198
+ * @param key The key to associate with the tag.
199
+ * @param value The tag to set.
200
+ * @returns The current instance for method chaining.
201
+ */
202
+ set<T extends BaseTag>(key: string, value: T): this;
203
+ /**
204
+ * Add multiple tags to the compound tag.
205
+ * @param tags An array of tags to add.
206
+ * @returns The current instance for method chaining.
207
+ */
208
+ push<T extends BaseTag>(...tags: Array<T>): this;
209
+ /**
210
+ * Add a single tag to the compound tag.
211
+ * @param tag The tag to add to the compound tag.
212
+ * @returns The tag that was added.
213
+ */
214
+ add<T extends BaseTag>(tag: T): T;
215
+ static read(stream: BinaryStream, options?: ReadWriteOptions): CompoundTag;
216
+ static write(stream: BinaryStream, value: CompoundTag, options?: ReadWriteOptions): void;
162
217
  }
163
218
 
164
- export { ByteArrayTag, ByteTag, CompoundTag, DoubleTag, FloatTag, IntTag, ListTag, LongTag, type ReadingProperties, ShortTag, StringTag, Tag, type TagProperties, TagType, type WritingProperties };
219
+ export { BaseTag, ByteListTag, ByteTag, CompoundTag, DoubleTag, FloatTag, IntTag, ListTag, LongTag, ShortTag, StringTag, TagType };