@sandstone-mc/mcdoc-ts-generator 0.1.0
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/README.md +15 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +3150 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +3086 -0
- package/dist/typegen/compile.d.ts +2 -0
- package/dist/typegen/export.d.ts +39 -0
- package/dist/typegen/import.d.ts +6 -0
- package/dist/typegen/index.d.ts +38 -0
- package/dist/typegen/mcdoc/assert.d.ts +427 -0
- package/dist/typegen/mcdoc/bind.d.ts +61 -0
- package/dist/typegen/mcdoc/complex/dispatcher.d.ts +34 -0
- package/dist/typegen/mcdoc/complex/index.d.ts +3 -0
- package/dist/typegen/mcdoc/complex/indexed.d.ts +47 -0
- package/dist/typegen/mcdoc/complex/template.d.ts +54 -0
- package/dist/typegen/mcdoc/dispatcher_symbol.d.ts +58 -0
- package/dist/typegen/mcdoc/index.d.ts +425 -0
- package/dist/typegen/mcdoc/list/array/byte.d.ts +20 -0
- package/dist/typegen/mcdoc/list/array/index.d.ts +3 -0
- package/dist/typegen/mcdoc/list/array/int.d.ts +20 -0
- package/dist/typegen/mcdoc/list/array/long.d.ts +20 -0
- package/dist/typegen/mcdoc/list/index.d.ts +2 -0
- package/dist/typegen/mcdoc/list/list.d.ts +66 -0
- package/dist/typegen/mcdoc/multi/enum.d.ts +8 -0
- package/dist/typegen/mcdoc/multi/index.d.ts +4 -0
- package/dist/typegen/mcdoc/multi/struct.d.ts +31 -0
- package/dist/typegen/mcdoc/multi/tuple.d.ts +62 -0
- package/dist/typegen/mcdoc/multi/union.d.ts +62 -0
- package/dist/typegen/mcdoc/primitives/any.d.ts +7 -0
- package/dist/typegen/mcdoc/primitives/boolean.d.ts +7 -0
- package/dist/typegen/mcdoc/primitives/byte.d.ts +19 -0
- package/dist/typegen/mcdoc/primitives/concrete.d.ts +37 -0
- package/dist/typegen/mcdoc/primitives/double.d.ts +27 -0
- package/dist/typegen/mcdoc/primitives/float.d.ts +19 -0
- package/dist/typegen/mcdoc/primitives/index.d.ts +12 -0
- package/dist/typegen/mcdoc/primitives/int.d.ts +35 -0
- package/dist/typegen/mcdoc/primitives/literal.d.ts +14 -0
- package/dist/typegen/mcdoc/primitives/long.d.ts +19 -0
- package/dist/typegen/mcdoc/primitives/reference.d.ts +54 -0
- package/dist/typegen/mcdoc/primitives/short.d.ts +19 -0
- package/dist/typegen/mcdoc/primitives/string.d.ts +28 -0
- package/dist/typegen/mcdoc/utils.d.ts +20 -0
- package/dist/util/config.d.ts +1 -0
- package/dist/util/fetch.d.ts +18 -0
- package/dist/util/index.d.ts +22 -0
- package/package.json +58 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
import { type NonEmptyList } from '..';
|
|
4
|
+
/**
|
|
5
|
+
* Arguments that can be passed to the template handler.
|
|
6
|
+
*/
|
|
7
|
+
export type TemplateArgs = {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Handles `template` types which are generic type definitions.
|
|
12
|
+
*
|
|
13
|
+
* A template type has:
|
|
14
|
+
* - `typeParams`: The generic definitions (e.g., `<T, U>`)
|
|
15
|
+
* - `child`: The actual type definition that uses those generics
|
|
16
|
+
*
|
|
17
|
+
* Example mcdoc:
|
|
18
|
+
* ```mcdoc
|
|
19
|
+
* type Template<A, B> = struct {
|
|
20
|
+
* first: A,
|
|
21
|
+
* second: B,
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Generates a TypeScript type alias:
|
|
26
|
+
* ```ts
|
|
27
|
+
* type Template<A, B> = { first: A; second: B }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function mcdoc_template(type: mcdoc.McdocType): (args: Record<string, unknown>) => {
|
|
31
|
+
readonly type: ts.TypeNode;
|
|
32
|
+
} | {
|
|
33
|
+
readonly child_dispatcher: [parent_count: number, property: string][] & {
|
|
34
|
+
0: [parent_count: number, property: string];
|
|
35
|
+
};
|
|
36
|
+
readonly type: ts.TypeNode;
|
|
37
|
+
} | {
|
|
38
|
+
readonly imports: {
|
|
39
|
+
readonly ordered: NonEmptyList<string>;
|
|
40
|
+
readonly check: Map<string, number>;
|
|
41
|
+
};
|
|
42
|
+
readonly type: ts.TypeNode;
|
|
43
|
+
} | {
|
|
44
|
+
readonly imports: {
|
|
45
|
+
readonly ordered: NonEmptyList<string>;
|
|
46
|
+
readonly check: Map<string, number>;
|
|
47
|
+
};
|
|
48
|
+
readonly child_dispatcher: [parent_count: number, property: string][] & {
|
|
49
|
+
0: [parent_count: number, property: string];
|
|
50
|
+
};
|
|
51
|
+
readonly type: ts.TypeNode;
|
|
52
|
+
};
|
|
53
|
+
export declare const McdocTemplate: typeof mcdoc_template;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import type { SymbolMap, SymbolUtil } from '@spyglassmc/core';
|
|
3
|
+
import { type NonEmptyList } from '.';
|
|
4
|
+
export type DispatcherReferenceCounter = {
|
|
5
|
+
/**
|
|
6
|
+
* Map<path: string, location_counts_index: number>
|
|
7
|
+
*/
|
|
8
|
+
locations: Map<string, number>;
|
|
9
|
+
location_counts: [path: string, count: number][];
|
|
10
|
+
};
|
|
11
|
+
export declare const dispatcher_references: Map<string, DispatcherReferenceCounter>;
|
|
12
|
+
type DispatcherSymbolResult = {
|
|
13
|
+
/**
|
|
14
|
+
* The main exported type `SymbolName<CASE>` and all supporting type aliases (member types, map, keys, fallback, unknown)
|
|
15
|
+
*/
|
|
16
|
+
readonly types: (ts.TypeAliasDeclaration | ts.EnumDeclaration)[];
|
|
17
|
+
/**
|
|
18
|
+
* Import paths required by this dispatcher
|
|
19
|
+
*/
|
|
20
|
+
readonly imports?: {
|
|
21
|
+
readonly ordered: NonEmptyList<string>;
|
|
22
|
+
readonly check: Map<string, number>;
|
|
23
|
+
};
|
|
24
|
+
readonly references?: DispatcherReferenceCounter;
|
|
25
|
+
/**
|
|
26
|
+
* Number of required generic parameters for this dispatcher (excluding CASE).
|
|
27
|
+
* Determined by whether the first member is a template type.
|
|
28
|
+
*/
|
|
29
|
+
readonly generic_count: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Generates a dispatcher symbol map with the following structure:
|
|
33
|
+
* ```ts
|
|
34
|
+
* export type NameFallbackType<T> = { ... } // Only if %unknown is present
|
|
35
|
+
* type NameNoneType<T> = { ... } // Only if %none is present
|
|
36
|
+
* type NameMemberA<T> = { ... }
|
|
37
|
+
* type NameMemberB<T> = { ... }
|
|
38
|
+
* type NameMap<T> = { 'a': NameMemberA<T>, 'b': NameMemberB<T> }
|
|
39
|
+
* type NameKeys = keyof NameMap<unknown>
|
|
40
|
+
* type NameFallback<T> = NameMemberA<T> | NameMemberB<T> | NameFallbackType<T>
|
|
41
|
+
* export type SymbolName<T, CASE extends ('map' | 'keys' | '%fallback' | '%none') = 'map'> = ...
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Generic parameters (e.g., `<T>`) are only present if the dispatcher members are template types.
|
|
45
|
+
* When present, generics are extracted from the first member and propagated to all type aliases.
|
|
46
|
+
* CASE always comes after any dispatcher generics in the main Symbol type because required type generics must proceed optional ones.
|
|
47
|
+
*
|
|
48
|
+
* Special keys in dispatcher members:
|
|
49
|
+
* - `%unknown`: Defines fallback type for arbitrary string keys not in the map, doesn't actually work because of TypeScript limitations
|
|
50
|
+
* - `%none`: Indicates the dispatcher key can be omitted. Handled during dispatcher use.
|
|
51
|
+
*
|
|
52
|
+
* Also populates `dispatcherPropertiesMap` with the dispatcher's properties.
|
|
53
|
+
*/
|
|
54
|
+
export declare function dispatcher_symbol(id: string, name: string, members: SymbolMap, dispatcher_properties: Map<string, {
|
|
55
|
+
supports_none?: true;
|
|
56
|
+
}>, module_map: SymbolMap, symbols: SymbolUtil): DispatcherSymbolResult;
|
|
57
|
+
export declare const DispatcherSymbol: typeof dispatcher_symbol;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
export type NonEmptyList<T> = T[] & {
|
|
4
|
+
0: T;
|
|
5
|
+
};
|
|
6
|
+
export type TypeHandlerResult = {
|
|
7
|
+
readonly type: ts.TypeNode | ts.TypeAliasDeclaration;
|
|
8
|
+
readonly imports?: {
|
|
9
|
+
/**
|
|
10
|
+
* Cannot include duplicates, but uses a list to preserve order.
|
|
11
|
+
*/
|
|
12
|
+
readonly ordered: NonEmptyList<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Maps import strings to the the index in `ordered` where they appear.
|
|
15
|
+
*/
|
|
16
|
+
readonly check: Map<string, number>;
|
|
17
|
+
};
|
|
18
|
+
readonly docs?: NonEmptyList<string | [string]>;
|
|
19
|
+
readonly child_dispatcher?: NonEmptyList<[parent_count: number, property: string]>;
|
|
20
|
+
};
|
|
21
|
+
export type TypeHandler<RESULT = TypeHandlerResult> = (type: mcdoc.McdocType) => ((args: Record<string, unknown>) => RESULT);
|
|
22
|
+
declare class TypeHandlersClass {
|
|
23
|
+
static readonly any: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
24
|
+
readonly type: ts.KeywordTypeNode<ts.SyntaxKind.UnknownKeyword>;
|
|
25
|
+
};
|
|
26
|
+
static readonly boolean: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
27
|
+
readonly type: ts.KeywordTypeNode<ts.SyntaxKind.BooleanKeyword>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* An `NBTByte`.
|
|
31
|
+
*
|
|
32
|
+
* Contains a generic with the actual range encoded:
|
|
33
|
+
* ```ts
|
|
34
|
+
* { min?: number; max?: number, leftExclusive?: boolean; rightExclusive?: boolean }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
static readonly byte: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
38
|
+
readonly type: ts.TypeReferenceNode;
|
|
39
|
+
readonly docs: NonEmptyList<string>;
|
|
40
|
+
readonly imports: {
|
|
41
|
+
readonly ordered: NonEmptyList<string>;
|
|
42
|
+
readonly check: Map<string, number>;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: ts.TypeReferenceNode;
|
|
46
|
+
readonly imports: {
|
|
47
|
+
readonly ordered: NonEmptyList<string>;
|
|
48
|
+
readonly check: Map<string, number>;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* An `NBTByteArray`.
|
|
53
|
+
*
|
|
54
|
+
* Contains a generic with the length range encoded when applicable.
|
|
55
|
+
*/
|
|
56
|
+
static readonly byte_array: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
57
|
+
readonly type: ts.TypeReferenceNode;
|
|
58
|
+
readonly imports: {
|
|
59
|
+
ordered: NonEmptyList<string>;
|
|
60
|
+
check: Map<string, number>;
|
|
61
|
+
};
|
|
62
|
+
readonly docs: NonEmptyList<string>;
|
|
63
|
+
} | {
|
|
64
|
+
readonly type: ts.TypeReferenceNode;
|
|
65
|
+
readonly imports: {
|
|
66
|
+
ordered: NonEmptyList<string>;
|
|
67
|
+
check: Map<string, number>;
|
|
68
|
+
};
|
|
69
|
+
readonly docs?: never;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* A type reference with generic parameters.
|
|
73
|
+
*
|
|
74
|
+
* References `template` types or members of a dispatcher that include their own generics.
|
|
75
|
+
*/
|
|
76
|
+
static readonly concrete: McdocConcreteType;
|
|
77
|
+
/**
|
|
78
|
+
* `Dispatcher['namespace:...']...`
|
|
79
|
+
*
|
|
80
|
+
* With no generic defaults to `map`. Can include a generic parameter for special cases.
|
|
81
|
+
* - `map`: The full symbol map.
|
|
82
|
+
* - `keys`: The keys of the symbol map.
|
|
83
|
+
* - `%fallback`: The union of all symbol values.
|
|
84
|
+
* - `%unknown`: The intersection of all symbol values.
|
|
85
|
+
*/
|
|
86
|
+
static readonly dispatcher: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
87
|
+
readonly type: ts.TypeNode;
|
|
88
|
+
readonly imports: {
|
|
89
|
+
readonly ordered: NonEmptyList<string>;
|
|
90
|
+
readonly check: Map<string, number>;
|
|
91
|
+
};
|
|
92
|
+
} | {
|
|
93
|
+
readonly child_dispatcher: [parent_count: number, property: string][] & {
|
|
94
|
+
0: [parent_count: number, property: string];
|
|
95
|
+
};
|
|
96
|
+
readonly type: ts.TypeNode;
|
|
97
|
+
readonly imports: {
|
|
98
|
+
readonly ordered: NonEmptyList<string>;
|
|
99
|
+
readonly check: Map<string, number>;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
static readonly double: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
103
|
+
readonly type: ts.ParenthesizedTypeNode;
|
|
104
|
+
readonly docs: NonEmptyList<string>;
|
|
105
|
+
readonly imports: {
|
|
106
|
+
readonly ordered: NonEmptyList<string>;
|
|
107
|
+
readonly check: Map<string, number>;
|
|
108
|
+
};
|
|
109
|
+
} | {
|
|
110
|
+
readonly type: ts.ParenthesizedTypeNode;
|
|
111
|
+
readonly imports: {
|
|
112
|
+
readonly ordered: NonEmptyList<string>;
|
|
113
|
+
readonly check: Map<string, number>;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
static readonly enum: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
117
|
+
readonly type: ts.ParenthesizedTypeNode;
|
|
118
|
+
};
|
|
119
|
+
static readonly float: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
120
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
121
|
+
readonly docs: NonEmptyList<string>;
|
|
122
|
+
readonly imports: {
|
|
123
|
+
readonly ordered: NonEmptyList<string>;
|
|
124
|
+
readonly check: Map<string, number>;
|
|
125
|
+
};
|
|
126
|
+
} | {
|
|
127
|
+
readonly type: ts.TypeReferenceNode;
|
|
128
|
+
readonly imports: {
|
|
129
|
+
readonly ordered: NonEmptyList<string>;
|
|
130
|
+
readonly check: Map<string, number>;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Indexes into a dispatcher type to access a specific property.
|
|
135
|
+
*
|
|
136
|
+
* Used for accessing nested properties from dispatched types, e.g.:
|
|
137
|
+
* `minecraft:environment_attribute[[%key]][attribute_track]`
|
|
138
|
+
*
|
|
139
|
+
* Generates indexed access types like:
|
|
140
|
+
* `SymbolEnvironmentAttribute[K]['attribute_track']`
|
|
141
|
+
*/
|
|
142
|
+
static readonly indexed: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
143
|
+
readonly type: ts.TypeNode;
|
|
144
|
+
readonly imports: {
|
|
145
|
+
readonly ordered: NonEmptyList<string>;
|
|
146
|
+
readonly check: Map<string, number>;
|
|
147
|
+
};
|
|
148
|
+
} | {
|
|
149
|
+
readonly child_dispatcher: [parent_count: number, property: string][] & {
|
|
150
|
+
0: [parent_count: number, property: string];
|
|
151
|
+
};
|
|
152
|
+
readonly type: ts.TypeNode;
|
|
153
|
+
readonly imports: {
|
|
154
|
+
readonly ordered: NonEmptyList<string>;
|
|
155
|
+
readonly check: Map<string, number>;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* An `NBTInt`.
|
|
160
|
+
*
|
|
161
|
+
* Contains a generic with the actual range encoded:
|
|
162
|
+
* ```ts
|
|
163
|
+
* { min?: number; max?: number, beginExclusive?: boolean; endExclusive?: boolean }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
static readonly int: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
167
|
+
readonly type: ts.TypeReferenceNode;
|
|
168
|
+
readonly docs: NonEmptyList<string>;
|
|
169
|
+
readonly imports: {
|
|
170
|
+
readonly ordered: NonEmptyList<string>;
|
|
171
|
+
readonly check: Map<string, number>;
|
|
172
|
+
};
|
|
173
|
+
} | {
|
|
174
|
+
readonly type: ts.TypeReferenceNode;
|
|
175
|
+
readonly imports: {
|
|
176
|
+
readonly ordered: NonEmptyList<string>;
|
|
177
|
+
readonly check: Map<string, number>;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* An `NBTIntArray`.
|
|
182
|
+
*
|
|
183
|
+
* Contains a generic with the length range encoded when applicable.
|
|
184
|
+
*/
|
|
185
|
+
static readonly int_array: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
186
|
+
readonly type: ts.TypeReferenceNode;
|
|
187
|
+
readonly imports: {
|
|
188
|
+
ordered: NonEmptyList<string>;
|
|
189
|
+
check: Map<string, number>;
|
|
190
|
+
};
|
|
191
|
+
readonly docs: NonEmptyList<string>;
|
|
192
|
+
} | {
|
|
193
|
+
readonly type: ts.TypeReferenceNode;
|
|
194
|
+
readonly imports: {
|
|
195
|
+
ordered: NonEmptyList<string>;
|
|
196
|
+
check: Map<string, number>;
|
|
197
|
+
};
|
|
198
|
+
readonly docs?: never;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* An `NBTList`.
|
|
202
|
+
*/
|
|
203
|
+
static readonly list: McdocListType;
|
|
204
|
+
static readonly literal: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
205
|
+
readonly type: ts.LiteralTypeNode;
|
|
206
|
+
} | {
|
|
207
|
+
readonly type: ts.TypeReferenceNode;
|
|
208
|
+
readonly imports: {
|
|
209
|
+
readonly ordered: NonEmptyList<string>;
|
|
210
|
+
readonly check: Map<string, number>;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* An `NBTLong`.
|
|
215
|
+
*/
|
|
216
|
+
static readonly long: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
217
|
+
readonly type: ts.TypeReferenceNode;
|
|
218
|
+
readonly docs: NonEmptyList<string>;
|
|
219
|
+
readonly imports: {
|
|
220
|
+
readonly ordered: NonEmptyList<string>;
|
|
221
|
+
readonly check: Map<string, number>;
|
|
222
|
+
};
|
|
223
|
+
} | {
|
|
224
|
+
readonly type: ts.TypeReferenceNode;
|
|
225
|
+
readonly imports: {
|
|
226
|
+
readonly ordered: NonEmptyList<string>;
|
|
227
|
+
readonly check: Map<string, number>;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* An `NBTLongArray`.
|
|
232
|
+
*
|
|
233
|
+
* Contains a generic with the length range encoded when applicable.
|
|
234
|
+
*/
|
|
235
|
+
static readonly long_array: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
236
|
+
readonly type: ts.TypeReferenceNode;
|
|
237
|
+
readonly imports: {
|
|
238
|
+
ordered: NonEmptyList<string>;
|
|
239
|
+
check: Map<string, number>;
|
|
240
|
+
};
|
|
241
|
+
readonly docs: NonEmptyList<string>;
|
|
242
|
+
} | {
|
|
243
|
+
readonly type: ts.TypeReferenceNode;
|
|
244
|
+
readonly imports: {
|
|
245
|
+
ordered: NonEmptyList<string>;
|
|
246
|
+
check: Map<string, number>;
|
|
247
|
+
};
|
|
248
|
+
readonly docs?: never;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* @deprecated Unused.
|
|
252
|
+
*/
|
|
253
|
+
static readonly mapped: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
254
|
+
readonly type: ts.KeywordTypeNode<ts.SyntaxKind.UnknownKeyword>;
|
|
255
|
+
};
|
|
256
|
+
static readonly reference: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
257
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
258
|
+
} | {
|
|
259
|
+
readonly child_dispatcher: [[0, string]];
|
|
260
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
261
|
+
} | {
|
|
262
|
+
readonly docs: (string | [string])[] & {
|
|
263
|
+
0: string | [string];
|
|
264
|
+
};
|
|
265
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
266
|
+
} | {
|
|
267
|
+
readonly docs: (string | [string])[] & {
|
|
268
|
+
0: string | [string];
|
|
269
|
+
};
|
|
270
|
+
readonly child_dispatcher: [[0, string]];
|
|
271
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
272
|
+
} | {
|
|
273
|
+
readonly imports: {
|
|
274
|
+
readonly ordered: NonEmptyList<string>;
|
|
275
|
+
readonly check: Map<string, number>;
|
|
276
|
+
};
|
|
277
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
278
|
+
} | {
|
|
279
|
+
readonly imports: {
|
|
280
|
+
readonly ordered: NonEmptyList<string>;
|
|
281
|
+
readonly check: Map<string, number>;
|
|
282
|
+
};
|
|
283
|
+
readonly child_dispatcher: [[0, string]];
|
|
284
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
285
|
+
} | {
|
|
286
|
+
readonly imports: {
|
|
287
|
+
readonly ordered: NonEmptyList<string>;
|
|
288
|
+
readonly check: Map<string, number>;
|
|
289
|
+
};
|
|
290
|
+
readonly docs: (string | [string])[] & {
|
|
291
|
+
0: string | [string];
|
|
292
|
+
};
|
|
293
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
294
|
+
} | {
|
|
295
|
+
readonly imports: {
|
|
296
|
+
readonly ordered: NonEmptyList<string>;
|
|
297
|
+
readonly check: Map<string, number>;
|
|
298
|
+
};
|
|
299
|
+
readonly docs: (string | [string])[] & {
|
|
300
|
+
0: string | [string];
|
|
301
|
+
};
|
|
302
|
+
readonly child_dispatcher: [[0, string]];
|
|
303
|
+
readonly type: ts.TypeReferenceNode | ts.ParenthesizedTypeNode;
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* An `NBTShort`.
|
|
307
|
+
*
|
|
308
|
+
* Contains a generic with the actual range encoded:
|
|
309
|
+
* ```ts
|
|
310
|
+
* { min?: number; max?: number, beginExclusive?: boolean; endExclusive?: boolean }
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
static readonly short: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
314
|
+
readonly type: ts.TypeReferenceNode;
|
|
315
|
+
readonly docs: NonEmptyList<string>;
|
|
316
|
+
readonly imports: {
|
|
317
|
+
readonly ordered: NonEmptyList<string>;
|
|
318
|
+
readonly check: Map<string, number>;
|
|
319
|
+
};
|
|
320
|
+
} | {
|
|
321
|
+
readonly type: ts.TypeReferenceNode;
|
|
322
|
+
readonly imports: {
|
|
323
|
+
readonly ordered: NonEmptyList<string>;
|
|
324
|
+
readonly check: Map<string, number>;
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
static readonly string: (type: mcdoc.McdocType) => ((args: Record<string, unknown>) => {
|
|
328
|
+
readonly type: ts.KeywordTypeNode<ts.SyntaxKind.StringKeyword>;
|
|
329
|
+
}) | ((args: Record<string, unknown>) => {
|
|
330
|
+
readonly type: ts.TemplateLiteralTypeNode;
|
|
331
|
+
}) | ((args: Record<string, unknown>) => {
|
|
332
|
+
readonly type: ts.TemplateLiteralTypeNode;
|
|
333
|
+
readonly docs: NonEmptyList<string>;
|
|
334
|
+
readonly imports?: never;
|
|
335
|
+
} | {
|
|
336
|
+
readonly type: ts.TypeNode;
|
|
337
|
+
readonly imports: {
|
|
338
|
+
ordered: NonEmptyList<string>;
|
|
339
|
+
check: Map<string, number>;
|
|
340
|
+
};
|
|
341
|
+
readonly docs?: never;
|
|
342
|
+
}) | ((args: Record<string, unknown>) => {
|
|
343
|
+
readonly type: ts.UnionTypeNode;
|
|
344
|
+
}) | ((args: Record<string, unknown>) => {
|
|
345
|
+
readonly type: ts.ParenthesizedTypeNode;
|
|
346
|
+
});
|
|
347
|
+
static readonly struct: McdocStructType;
|
|
348
|
+
/**
|
|
349
|
+
* A type alias with generic parameters.
|
|
350
|
+
*
|
|
351
|
+
* Is referenced with `concrete` types.
|
|
352
|
+
*/
|
|
353
|
+
static readonly template: McdocTemplateType;
|
|
354
|
+
/**
|
|
355
|
+
* Used in a single place, CubicBezier. Lol.
|
|
356
|
+
*/
|
|
357
|
+
static readonly tuple: McdocTupleType;
|
|
358
|
+
static readonly union: McdocUnionType;
|
|
359
|
+
/**
|
|
360
|
+
* @deprecated Unused.
|
|
361
|
+
*/
|
|
362
|
+
static readonly unsafe: (type: mcdoc.McdocType) => (args: Record<string, unknown>) => {
|
|
363
|
+
readonly type: ts.KeywordTypeNode<ts.SyntaxKind.UnknownKeyword>;
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
export declare const TypeHandlers: typeof TypeHandlersClass;
|
|
367
|
+
/**
|
|
368
|
+
* Used to broaden the `type` field in the `TypeHandlerResult` for top-level typegen handling.
|
|
369
|
+
*/
|
|
370
|
+
export declare function get_type_handler(type: mcdoc.McdocType): TypeHandler;
|
|
371
|
+
type McdocListType = TypeHandler<{
|
|
372
|
+
readonly child_dispatcher?: NonEmptyList<[parent_count: number, property: string]>;
|
|
373
|
+
readonly type: ts.TypeReferenceNode;
|
|
374
|
+
readonly imports?: {
|
|
375
|
+
readonly ordered: NonEmptyList<string>;
|
|
376
|
+
readonly check: Map<string, number>;
|
|
377
|
+
};
|
|
378
|
+
readonly docs?: NonEmptyList<string | [string]>;
|
|
379
|
+
}>;
|
|
380
|
+
type McdocStructType = TypeHandler<{
|
|
381
|
+
readonly child_dispatcher?: NonEmptyList<[parent_count: number, property: string]>;
|
|
382
|
+
readonly type: ts.TypeLiteralNode | ts.TypeReferenceNode | ts.ParenthesizedTypeNode | ts.KeywordTypeNode<ts.SyntaxKind.UnknownKeyword>;
|
|
383
|
+
readonly imports?: {
|
|
384
|
+
readonly ordered: NonEmptyList<string>;
|
|
385
|
+
readonly check: Map<string, number>;
|
|
386
|
+
};
|
|
387
|
+
readonly docs?: NonEmptyList<string | [string]>;
|
|
388
|
+
}>;
|
|
389
|
+
type McdocTupleType = TypeHandler<{
|
|
390
|
+
readonly docs?: NonEmptyList<string | [string]>;
|
|
391
|
+
readonly child_dispatcher?: NonEmptyList<[parent_count: number, property: string]>;
|
|
392
|
+
readonly imports?: {
|
|
393
|
+
readonly ordered: NonEmptyList<string>;
|
|
394
|
+
readonly check: Map<string, number>;
|
|
395
|
+
};
|
|
396
|
+
readonly type: ts.TupleTypeNode;
|
|
397
|
+
}>;
|
|
398
|
+
type McdocUnionType = TypeHandler<{
|
|
399
|
+
readonly docs?: NonEmptyList<string | [string]>;
|
|
400
|
+
readonly child_dispatcher?: NonEmptyList<[number, string]>;
|
|
401
|
+
readonly imports?: {
|
|
402
|
+
readonly ordered: NonEmptyList<string>;
|
|
403
|
+
readonly check: Map<string, number>;
|
|
404
|
+
};
|
|
405
|
+
readonly type: ts.TypeNode;
|
|
406
|
+
}>;
|
|
407
|
+
type McdocConcreteType = TypeHandler<{
|
|
408
|
+
readonly docs?: NonEmptyList<string | [string]>;
|
|
409
|
+
readonly child_dispatcher?: NonEmptyList<[parent_count: number, property: string]>;
|
|
410
|
+
readonly type: ts.TypeReferenceNode | ts.TypeNode;
|
|
411
|
+
readonly imports?: {
|
|
412
|
+
readonly ordered: NonEmptyList<string>;
|
|
413
|
+
readonly check: Map<string, number>;
|
|
414
|
+
};
|
|
415
|
+
}>;
|
|
416
|
+
type McdocTemplateType = TypeHandler<{
|
|
417
|
+
readonly child_dispatcher?: NonEmptyList<[parent_count: number, property: string]>;
|
|
418
|
+
readonly type: ts.TypeNode;
|
|
419
|
+
readonly imports?: {
|
|
420
|
+
readonly ordered: NonEmptyList<string>;
|
|
421
|
+
readonly check: Map<string, number>;
|
|
422
|
+
};
|
|
423
|
+
readonly docs: never;
|
|
424
|
+
}>;
|
|
425
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
import type { NonEmptyList } from '../..';
|
|
4
|
+
declare function mcdoc_byte_array(type: mcdoc.McdocType): (args: Record<string, unknown>) => {
|
|
5
|
+
readonly type: ts.TypeReferenceNode;
|
|
6
|
+
readonly imports: {
|
|
7
|
+
ordered: NonEmptyList<string>;
|
|
8
|
+
check: Map<string, number>;
|
|
9
|
+
};
|
|
10
|
+
readonly docs: NonEmptyList<string>;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: ts.TypeReferenceNode;
|
|
13
|
+
readonly imports: {
|
|
14
|
+
ordered: NonEmptyList<string>;
|
|
15
|
+
check: Map<string, number>;
|
|
16
|
+
};
|
|
17
|
+
readonly docs?: never;
|
|
18
|
+
};
|
|
19
|
+
export declare const McdocByteArray: typeof mcdoc_byte_array;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
import type { NonEmptyList } from '../..';
|
|
4
|
+
declare function mcdoc_int_array(type: mcdoc.McdocType): (args: Record<string, unknown>) => {
|
|
5
|
+
readonly type: ts.TypeReferenceNode;
|
|
6
|
+
readonly imports: {
|
|
7
|
+
ordered: NonEmptyList<string>;
|
|
8
|
+
check: Map<string, number>;
|
|
9
|
+
};
|
|
10
|
+
readonly docs: NonEmptyList<string>;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: ts.TypeReferenceNode;
|
|
13
|
+
readonly imports: {
|
|
14
|
+
ordered: NonEmptyList<string>;
|
|
15
|
+
check: Map<string, number>;
|
|
16
|
+
};
|
|
17
|
+
readonly docs?: never;
|
|
18
|
+
};
|
|
19
|
+
export declare const McdocIntArray: typeof mcdoc_int_array;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
import type { NonEmptyList } from '../..';
|
|
4
|
+
declare function mcdoc_long_array(type: mcdoc.McdocType): (args: Record<string, unknown>) => {
|
|
5
|
+
readonly type: ts.TypeReferenceNode;
|
|
6
|
+
readonly imports: {
|
|
7
|
+
ordered: NonEmptyList<string>;
|
|
8
|
+
check: Map<string, number>;
|
|
9
|
+
};
|
|
10
|
+
readonly docs: NonEmptyList<string>;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: ts.TypeReferenceNode;
|
|
13
|
+
readonly imports: {
|
|
14
|
+
ordered: NonEmptyList<string>;
|
|
15
|
+
check: Map<string, number>;
|
|
16
|
+
};
|
|
17
|
+
readonly docs?: never;
|
|
18
|
+
};
|
|
19
|
+
export declare const McdocLongArray: typeof mcdoc_long_array;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
import { type NonEmptyList } from '..';
|
|
4
|
+
declare function mcdoc_list(type: mcdoc.McdocType): (args: Record<string, unknown>) => {
|
|
5
|
+
readonly type: ts.TypeReferenceNode;
|
|
6
|
+
readonly docs: NonEmptyList<string>;
|
|
7
|
+
} | {
|
|
8
|
+
readonly child_dispatcher: [number, string][] & {
|
|
9
|
+
0: [number, string];
|
|
10
|
+
};
|
|
11
|
+
readonly type: ts.TypeReferenceNode;
|
|
12
|
+
readonly docs: NonEmptyList<string>;
|
|
13
|
+
} | {
|
|
14
|
+
readonly imports: {
|
|
15
|
+
readonly ordered: NonEmptyList<string>;
|
|
16
|
+
readonly check: Map<string, number>;
|
|
17
|
+
};
|
|
18
|
+
readonly type: ts.TypeReferenceNode;
|
|
19
|
+
readonly docs: NonEmptyList<string>;
|
|
20
|
+
} | {
|
|
21
|
+
readonly imports: {
|
|
22
|
+
readonly ordered: NonEmptyList<string>;
|
|
23
|
+
readonly check: Map<string, number>;
|
|
24
|
+
};
|
|
25
|
+
readonly child_dispatcher: [number, string][] & {
|
|
26
|
+
0: [number, string];
|
|
27
|
+
};
|
|
28
|
+
readonly type: ts.TypeReferenceNode;
|
|
29
|
+
readonly docs: NonEmptyList<string>;
|
|
30
|
+
} | {
|
|
31
|
+
readonly type: ts.TypeReferenceNode;
|
|
32
|
+
} | {
|
|
33
|
+
readonly child_dispatcher: [number, string][] & {
|
|
34
|
+
0: [number, string];
|
|
35
|
+
};
|
|
36
|
+
readonly type: ts.TypeReferenceNode;
|
|
37
|
+
} | {
|
|
38
|
+
readonly imports: {
|
|
39
|
+
readonly ordered: NonEmptyList<string>;
|
|
40
|
+
readonly check: Map<string, number>;
|
|
41
|
+
};
|
|
42
|
+
readonly type: ts.TypeReferenceNode;
|
|
43
|
+
} | {
|
|
44
|
+
readonly imports: {
|
|
45
|
+
readonly ordered: NonEmptyList<string>;
|
|
46
|
+
readonly check: Map<string, number>;
|
|
47
|
+
};
|
|
48
|
+
readonly child_dispatcher: [number, string][] & {
|
|
49
|
+
0: [number, string];
|
|
50
|
+
};
|
|
51
|
+
readonly type: ts.TypeReferenceNode;
|
|
52
|
+
};
|
|
53
|
+
export declare const McdocList: typeof mcdoc_list;
|
|
54
|
+
/**
|
|
55
|
+
* Generates TypeScript property signatures and documentation for a length range constraint.
|
|
56
|
+
* Used by list and primitive array types (byte_array, int_array, long_array).
|
|
57
|
+
*
|
|
58
|
+
* @param range The numeric range constraint
|
|
59
|
+
* @param label Label for docs (e.g., "List", "Array")
|
|
60
|
+
* @returns Object with `generic` (property signatures) and `docs` (documentation strings)
|
|
61
|
+
*/
|
|
62
|
+
export declare function length_range_generic(range: mcdoc.NumericRange, label: string): {
|
|
63
|
+
generic: ts.PropertySignature[];
|
|
64
|
+
docs: NonEmptyList<string>;
|
|
65
|
+
};
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
export declare function enum_docs(enum_type: mcdoc.EnumType): string[];
|
|
4
|
+
declare function mcdoc_enum(type: mcdoc.McdocType): (args: Record<string, unknown>) => {
|
|
5
|
+
readonly type: ts.ParenthesizedTypeNode;
|
|
6
|
+
};
|
|
7
|
+
export declare const McdocEnum: typeof mcdoc_enum;
|
|
8
|
+
export {};
|