@brew-lang/sdk 0.0.0-stage → 0.3.0-alpha

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.
@@ -0,0 +1,294 @@
1
+ /** Best-effort Java type -> TypeScript type. */
2
+ export declare function tsType(raw: string, isTreeClass?: (name: string) => boolean): string;
3
+ /**
4
+ * Strip a leading method type-parameter clause (`<T extends Comparable<T>>`)
5
+ * from a signature header, at any nesting depth. The clause must directly
6
+ * follow whitespace-separated modifier words, so a generic RETURN type
7
+ * (`List<Gadget> foo()`) is kept: "List<" has no space before "<".
8
+ */
9
+ export declare function stripTypeParams(header: string): string;
10
+ /** Split a Java parameter list on top-level commas. */
11
+ export declare function splitParams(params: string, isTreeClass?: (name: string) => boolean): Array<{
12
+ name: string;
13
+ type: string;
14
+ raw: string;
15
+ }>;
16
+ /** Class-like names referenced by a Java type expression ("List<org.bukkit.entity.Entity>" -> ["Entity"]). */
17
+ export declare function refNames(rawType: string, isTreeClass?: (name: string) => boolean): string[];
18
+ /**
19
+ * Like refNames, but also keeps the package-qualified form of each ref
20
+ * ("org.bukkit.World"), so a reference to a class the mirrored tree does
21
+ * not declare can be linked to the brew package providing it (see
22
+ * resolveExternalRef). Map: ref ("World", "Villager.Profession") ->
23
+ * qualified name ("org.bukkit.World", "Villager.Profession").
24
+ */
25
+ export declare function refQuals(rawType: string, isTreeClass?: (name: string) => boolean): Map<string, string>;
26
+ /**
27
+ * Collects interface members, resolving accessor/method name clashes the
28
+ * same way for javadoc pages and Java sources (shared by both parsers).
29
+ *
30
+ * TS allows method overloads and getter/setter pairs, but not two
31
+ * accessors of the same kind (setTypes(Tag) / setTypes(Collection)), nor
32
+ * a method or field sharing a property's name (header()/getHeader()).
33
+ */
34
+ export declare function createMemberCollector(): {
35
+ members: string[];
36
+ addMember: (member: string) => void;
37
+ };
38
+ /** Context shared by the javadoc and Java-source member parsers. */
39
+ export interface MemberContext {
40
+ /** Simple name of the declaring class (its constructors are skipped). */
41
+ className: string;
42
+ isTreeClass?: (name: string) => boolean;
43
+ /** Include static members. The git mirror sets this — utility classes are
44
+ * all-static, so skipping statics would empty them; the javadoc mirror
45
+ * leaves it off. (TS interfaces cannot declare `static`, so they are
46
+ * mirrored as plain members.) */
47
+ includeStatic?: boolean;
48
+ addRefs: (rawType: string) => void;
49
+ addMember: (member: string) => void;
50
+ }
51
+ /** Turn a parsed Java method signature into an interface member (shared by
52
+ * the javadoc and Java-source parsers). */
53
+ export declare function addMethodMember(sig: {
54
+ mods: string;
55
+ ret: string;
56
+ name: string;
57
+ params: string;
58
+ }, ctx: MemberContext): void;
59
+ /** Turn a parsed Java field signature into an interface member (shared by
60
+ * the javadoc and Java-source parsers). */
61
+ export declare function addFieldMember(sig: {
62
+ mods: string;
63
+ type: string;
64
+ name: string;
65
+ }, ctx: MemberContext): void;
66
+ /** Assemble the generated declaration from collected members (shared by the
67
+ * javadoc and Java-source generators). Mirrors emit `export declare class` —
68
+ * not `interface` — because only classes carry a static side, so static
69
+ * members (emitted with the `static` modifier) resolve as `Class.member` in
70
+ * editors and `declare class` is a drop-in for the interface shape. */
71
+ export declare function assembleInterface(opts: {
72
+ name: string;
73
+ fullName: string;
74
+ pkg: string;
75
+ /** First header line, e.g. `// Generated by brewc fetch from <url>`. */
76
+ sourceLine: string;
77
+ members: string[];
78
+ refs: Iterable<string>;
79
+ }): {
80
+ name: string;
81
+ ts: string;
82
+ refs: string[];
83
+ };
84
+ /**
85
+ * Generate the interface source from javadoc HTML (pure, testable).
86
+ * Targets the modern javadoc layout (`<div class="member-signature">`).
87
+ *
88
+ * `refs` lists the class-like names the members reference — candidates for
89
+ * imports; the fetch-javadoc mirror turns them into `import type` statements
90
+ * so the tree cross-references itself. `opts.name` / `opts.fullName` override
91
+ * the derived class name (nested classes declare as their last name segment,
92
+ * but keep the dotted name for @classloc).
93
+ */
94
+ export declare function apiDocsToInterface(html: string, url: string, opts?: {
95
+ name?: string;
96
+ fullName?: string;
97
+ isTreeClass?: (name: string) => boolean;
98
+ }): {
99
+ name: string;
100
+ ts: string;
101
+ refs: string[];
102
+ };
103
+ /** Extract class page paths from an allclasses-index/allclasses page (pure). */
104
+ export declare function extractClassLinks(html: string, opts?: {
105
+ includeNested?: boolean;
106
+ resolveFrom?: string;
107
+ }): string[];
108
+ /**
109
+ * Packages listed on a module-summary page (pure), e.g. the Oracle javadocs
110
+ * (docs.oracle.com/.../api/java.base) whose modules have no allclasses page:
111
+ * java/io/package-summary.html, java/lang/package-summary.html, ...
112
+ */
113
+ export declare function extractPackageLinks(html: string): string[];
114
+ /** True when an href is a nested class page (Outer.Inner.html / .java). */
115
+ export declare function isNestedHref(href: string): boolean;
116
+ /** The class indexes a mirror resolver needs (see buildClassIndex). */
117
+ export interface ClassIndexLike {
118
+ classIndex: Map<string, string[]>;
119
+ nestedIndex: Map<string, string>;
120
+ nestedOwners: Map<string, string[]>;
121
+ }
122
+ /**
123
+ * Index every class link (nested included) and pick the pages to mirror as
124
+ * files. `limit` caps the mirror and prunes the index so imports never
125
+ * point at pages that were not written.
126
+ */
127
+ export declare function indexLinks(allLinks: string[], limit?: number): {
128
+ links: string[];
129
+ classIndex: Map<string, string[]>;
130
+ nestedIndex: Map<string, string>;
131
+ nestedOwners: Map<string, string[]>;
132
+ nested: Map<string, string[]>;
133
+ };
134
+ /**
135
+ * Bind a reference to the mirrored page declaring it (shared by the javadoc
136
+ * and git mirrors): top-level names resolve to their declaring page, dotted
137
+ * refs (Villager.Profession) to their outer class's page, and a name claimed
138
+ * by several classes binds the one whose package is nearest to this file's.
139
+ */
140
+ export declare function makeResolver(index: ClassIndexLike, href: string, localNames: Set<string>): (ref: string) => string | null;
141
+ /** Every directory of a mirror that needs an index.ts (mirrorDirs of the
142
+ * javadoc roots and the git clone alike). */
143
+ export declare function mirrorDirs(outRoot: string, targets: Array<{
144
+ rootDir: string;
145
+ href: string;
146
+ }>): Set<string>;
147
+ /**
148
+ * Write an index (.ts, or .d.ts for a types-only package) for every
149
+ * directory of a mirror: class files re-export directly, subpackages as
150
+ * namespaces — except at a tree root with a single top package, which
151
+ * re-exports it flat so `import * as org from "..."` works.
152
+ */
153
+ export declare function writeMirrorIndexes(dirs: Set<string>, treeRoots: Set<string>, ext: string): void;
154
+ /** Write the package.json of a types-only mirror (`--package`). */
155
+ export declare function writeMirrorPackage(outDir: string, packageName: string, ext: string): void;
156
+ /**
157
+ * Write brew.json next to package.json: a map from every Java package this
158
+ * mirror covers to the npm package name, so other mirrors can link their
159
+ * external references into this package (see loadBrewMap/resolveExternalRef):
160
+ *
161
+ * { "java": { "org.bukkit": "@brew-types/java__org.spigotmc__spigot-api" } }
162
+ *
163
+ * Package names follow the @brew-types/<languageFileExtension>__<groupId>__<artifactId>
164
+ * standard (see brewPackageName), e.g. @brew-types/java__java.base for the
165
+ * java.base module (java.lang) and @brew-types/java__org.spigotmc__spigot-api
166
+ * for org.spigotmc:spigot-api (org.bukkit).
167
+ */
168
+ export declare function writeBrewJson(outDir: string, packageName: string, ext: string): void;
169
+ /**
170
+ * Load the union of the brew.json maps found in the given directories (each
171
+ * dir's own brew.json plus one level of subdirectories, so both
172
+ * node_modules/@brew-types and a packages/ dir work): java package prefix
173
+ * -> npm package name.
174
+ */
175
+ export declare function loadBrewMap(searchDirs: string[]): Map<string, string>;
176
+ /**
177
+ * Resolve a reference the mirrored tree does not declare to an import path
178
+ * in the brew package providing it (pure): with brew map
179
+ * { "org.bukkit": "@brew-types/java__org.spigotmc__spigot-api" }, the
180
+ * qualified name "org.bukkit.World" resolves to
181
+ * "@brew-types/java__org.spigotmc__spigot-api/org/bukkit/World". Nested
182
+ * classes (Outer.Inner) import from their outer class's file. The longest
183
+ * matching package prefix wins.
184
+ */
185
+ export declare function resolveExternalRef(ref: string, quals: Iterable<string>, brewMap: Map<string, string>): string | null;
186
+ /**
187
+ * Map every class of a javadoc tree to the page that declares it (pure,
188
+ * testable). Nested classes live in their outer class's page; they do not
189
+ * claim their simple name, which would shadow same-named top-level classes
190
+ * (TropicalFish.Pattern vs org.bukkit.block.banner.Pattern). Names claimed
191
+ * by more than one page are left out (an ambiguous import would silently
192
+ * bind the wrong class).
193
+ */
194
+ export declare function buildClassIndex(links: string[]): {
195
+ classIndex: Map<string, string[]>;
196
+ nestedIndex: Map<string, string>;
197
+ nestedOwners: Map<string, string[]>;
198
+ nested: Map<string, string[]>;
199
+ };
200
+ /** Module path importing toHref's class from a file living in fromDir (pure).
201
+ * Works for any href extension (.html javadoc pages, .java source files). */
202
+ export declare function importPathFor(fromDir: string, toHref: string): string;
203
+ /** Build the `import type` block for referenced classes (pure). */
204
+ export declare function importBlockFor(refs: string[], resolveImport: (ref: string) => string | null): string;
205
+ /** Insert an import block after the generated header comments (pure). */
206
+ export declare function withImports(ts: string, importBlock: string): string;
207
+ /** index.ts content for one directory: re-export files and subdirectories. */
208
+ /**
209
+ * Re-export statement for one class file (pure), or null when every name it
210
+ * declares was already claimed by an earlier sibling: two nested classes of
211
+ * the same name in one directory (Crafter.Orientation, Jigsaw.Orientation)
212
+ * cannot both be star-exported from its index.ts.
213
+ */
214
+ export declare function fileExportLine(file: string, names: string[], claimed: Set<string>): string | null;
215
+ /**
216
+ * index.ts content for one directory (pure). Class files re-export directly;
217
+ * subpackages re-export as namespaces named after their directory, so a tree
218
+ * mirrors Java paths: org/bukkit/index.ts gives org.bukkit.entity.Player.
219
+ * `opts.flat` re-exports subdirectories directly instead — used for the API
220
+ * root, so `import * as org from ".../spigot-api"` binds its top packages.
221
+ */
222
+ export declare function buildIndex(fileExports: string[], subdirs: string[], opts?: {
223
+ flat?: boolean;
224
+ }): string;
225
+ export interface FetchAllResult {
226
+ classes: number;
227
+ errors: string[];
228
+ }
229
+ /** Names of the interfaces a generated file declares (its class + nested). */
230
+ export declare function declaredNames(ts: string): Set<string>;
231
+ /** Swap the import block of an already-generated file (pure). */
232
+ export declare function replaceImports(ts: string, importBlock: string): string;
233
+ /**
234
+ * @brew-types package names are `<languageFileExtension>__<groupId>__<artifactId>`,
235
+ * double-underscore delimited — e.g. @brew-types/java__org.spigotmc__spigot-api —
236
+ * so snakecase groupIds/artifactIds of future languages stay readable and the
237
+ * name parses unambiguously. JDK modules put the module name in place of
238
+ * groupId/artifactId: @brew-types/java__java.base.
239
+ */
240
+ export declare function brewPackageName(language: string, ...rest: string[]): string;
241
+ /** Inverse of brewPackageName: split on the double-underscore delimiter.
242
+ * Two components => <language>__<module> (JDK module), three =>
243
+ * <language>__<groupId>__<artifactId> (Maven coordinates). */
244
+ export declare function parseBrewPackageName(name: string): {
245
+ language: string;
246
+ module?: string;
247
+ groupId?: string;
248
+ artifactId?: string;
249
+ } | null;
250
+ /**
251
+ * The base of every generated interface: java.lang.Object, provided by the
252
+ * @brew-types language packs — @brew-types/java__java.base: java.lang is a
253
+ * package inside the java.base module. Extending it gives every mirrored
254
+ * class Object's methods (toString, equals, hashCode, ...).
255
+ */
256
+ export declare const BASE_TYPE: {
257
+ name: string;
258
+ module: string;
259
+ };
260
+ export declare const BASE_IMPORT: string;
261
+ /**
262
+ * Extract javadoc roots linked from a landing page (pure, testable).
263
+ * Some hubs are not a javadoc root themselves: the SpigotMC hub
264
+ * (hub.spigotmc.org/javadocs) links each API's javadoc as
265
+ * <root>/index.html?overview-summary.html (bukkit/, spigot/).
266
+ */
267
+ export declare function discoverJavadocRoots(html: string, base: string): string[];
268
+ /**
269
+ * Walk the entire javadoc of a Bukkit/Spigot API: read the class list, fetch
270
+ * every class page, and mirror the package tree as .ts interfaces on disk,
271
+ * with an index.ts re-exporting each directory level.
272
+ *
273
+ * A base URL that is not a javadoc root itself works too when it links the
274
+ * javadoc roots (the SpigotMC hub); each discovered root is mirrored under
275
+ * its own subdirectory of outDir so same-named packages cannot collide.
276
+ */
277
+ export declare function fetchAllApiDocs(baseUrl: string, outDir: string, opts?: {
278
+ limit?: number;
279
+ concurrency?: number;
280
+ log?: (msg: string) => void;
281
+ /** npm package name for the mirror: writes a package.json so it can be
282
+ * installed (file:...) and imported by package specifier. */
283
+ packageName?: string;
284
+ }): Promise<FetchAllResult>;
285
+ /** Fetch a javadoc page and generate its TypeScript interface. */
286
+ export declare function fetchApiDocs(url: string): Promise<{
287
+ name: string;
288
+ ts: string;
289
+ }>;
290
+ /** Write a fetch result, used by the CLI. */
291
+ export declare function writeFetched(result: {
292
+ name: string;
293
+ ts: string;
294
+ }, output: string | null): string;