Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 75 additions & 12 deletions _packages/native-preview/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,24 @@ export class Checker {
* declared type cannot be determined the checker yields the error type (use
* {@link Type.isErrorType} to detect it).
*/
async getDeclaredTypeOfSymbol(symbol: Symbol): Promise<Type> {
async getDeclaredTypeOfSymbol(symbol: Symbol): Promise<Type>;
async getDeclaredTypeOfSymbol(symbols: readonly Symbol[]): Promise<Type[]>;
async getDeclaredTypeOfSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Type | Type[]> {
if (Array.isArray(symbolOrSymbols)) {
const data = await this.client.apiRequest<TypeResponse[]>("getDeclaredTypesOfSymbols", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map((d, i) => {
return this.objectRegistry.getOrCreateType(d);
});
}
const sym = symbolOrSymbols as Symbol;
const data = await this.client.apiRequest<TypeResponse>("getDeclaredTypeOfSymbol", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return this.objectRegistry.getOrCreateType(data);
}
Expand Down Expand Up @@ -1632,20 +1645,45 @@ export class Checker {
* an unresolved alias the checker yields the unknown symbol (use
* {@link Checker.isUnknownSymbol} to detect it).
*/
async getAliasedSymbol(symbol: Symbol): Promise<Symbol> {
async getAliasedSymbol(symbol: Symbol): Promise<Symbol>;
async getAliasedSymbol(symbols: readonly Symbol[]): Promise<Symbol[]>;
async getAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Symbol | Symbol[]> {
if (Array.isArray(symbolOrSymbols)) {
const data = await this.client.apiRequest<SymbolResponse[]>("getAliasedSymbols", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map((d, i) => {
if (!d) throw new Error(`getAliasedSymbol returned no symbol for symbol ${symbolOrSymbols[i].id}`);
return this.objectRegistry.getOrCreateSymbol(d);
});
}
const sym = symbolOrSymbols as Symbol;
const data = await this.client.apiRequest<SymbolResponse>("getAliasedSymbol", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return this.objectRegistry.getOrCreateSymbol(data);
}

async getImmediateAliasedSymbol(symbol: Symbol): Promise<Symbol | undefined> {
async getImmediateAliasedSymbol(symbol: Symbol): Promise<Symbol | undefined>;
async getImmediateAliasedSymbol(symbols: readonly Symbol[]): Promise<(Symbol | undefined)[]>;
async getImmediateAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Symbol | (Symbol | undefined)[] | undefined> {
if (Array.isArray(symbolOrSymbols)) {
const data = await this.client.apiRequest<(SymbolResponse | null)[]>("getImmediateAliasedSymbols", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
}
const sym = symbolOrSymbols as Symbol;
const data = await this.client.apiRequest<SymbolResponse | null>("getImmediateAliasedSymbol", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}
Expand Down Expand Up @@ -1706,21 +1744,46 @@ export class Checker {
return signature.id === (await this.getWellKnownSignatures()).unknown;
}

async getExportsOfModule(symbol: Symbol): Promise<readonly Symbol[]> {
const data = await this.client.apiRequest<SymbolResponse[] | null>("getExportsOfModule", {
async getExportsOfModule(symbol: Symbol): Promise<Symbol[]>;
async getExportsOfModule(symbols: readonly Symbol[]): Promise<Symbol[][]>;
async getExportsOfModule(symbolOrSymbols: Symbol | readonly Symbol[]): Promise<Symbol[] | Symbol[][]> {
if (Array.isArray(symbolOrSymbols)) {
const data = await this.client.apiRequest<SymbolResponse[][]>("getExportsOfModules", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map(d => d ? d.map(s => this.objectRegistry.getOrCreateSymbol(s)) : []);
}
const sym = symbolOrSymbols as Symbol;
const data = await this.client.apiRequest<SymbolResponse[]>("getExportsOfModule", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

async getMemberInModuleExports(symbol: Symbol, name: string): Promise<Symbol | undefined> {
async getMemberInModuleExports(symbol: Symbol, name: string): Promise<Symbol | undefined>;
async getMemberInModuleExports(requests: readonly { symbol: Symbol; name: string; }[]): Promise<(Symbol | undefined)[]>;
async getMemberInModuleExports(
symbolOrRequests: Symbol | readonly { symbol: Symbol; name: string; }[],
name?: string,
): Promise<Symbol | (Symbol | undefined)[] | undefined> {
if (Array.isArray(symbolOrRequests)) {
const data = await this.client.apiRequest<(SymbolResponse | null)[]>("getMembersInModuleExports", {
snapshot: this.snapshotId,
project: this.project.id,
requests: symbolOrRequests.map(r => ({ symbol: r.symbol.id, name: r.name })),
});
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
}
const sym = symbolOrRequests as Symbol;
const data = await this.client.apiRequest<SymbolResponse | null>("getMemberInModuleExports", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
name,
symbol: sym.id,
name: name!,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}
Expand Down
87 changes: 75 additions & 12 deletions _packages/native-preview/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1164,11 +1164,24 @@ export class Checker {
* declared type cannot be determined the checker yields the error type (use
* {@link Type.isErrorType} to detect it).
*/
getDeclaredTypeOfSymbol(symbol: Symbol): Type {
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
getDeclaredTypeOfSymbol(symbols: readonly Symbol[]): Type[];
getDeclaredTypeOfSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Type | Type[] {
if (Array.isArray(symbolOrSymbols)) {
const data = this.client.apiRequest<TypeResponse[]>("getDeclaredTypesOfSymbols", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map((d, i) => {
return this.objectRegistry.getOrCreateType(d);
});
}
const sym = symbolOrSymbols as Symbol;
const data = this.client.apiRequest<TypeResponse>("getDeclaredTypeOfSymbol", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return this.objectRegistry.getOrCreateType(data);
}
Expand Down Expand Up @@ -1640,20 +1653,45 @@ export class Checker {
* an unresolved alias the checker yields the unknown symbol (use
* {@link Checker.isUnknownSymbol} to detect it).
*/
getAliasedSymbol(symbol: Symbol): Symbol {
getAliasedSymbol(symbol: Symbol): Symbol;
getAliasedSymbol(symbols: readonly Symbol[]): Symbol[];
getAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Symbol | Symbol[] {
if (Array.isArray(symbolOrSymbols)) {
const data = this.client.apiRequest<SymbolResponse[]>("getAliasedSymbols", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map((d, i) => {
if (!d) throw new Error(`getAliasedSymbol returned no symbol for symbol ${symbolOrSymbols[i].id}`);
return this.objectRegistry.getOrCreateSymbol(d);
});
}
const sym = symbolOrSymbols as Symbol;
const data = this.client.apiRequest<SymbolResponse>("getAliasedSymbol", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return this.objectRegistry.getOrCreateSymbol(data);
}

getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined {
getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined;
getImmediateAliasedSymbol(symbols: readonly Symbol[]): (Symbol | undefined)[];
getImmediateAliasedSymbol(symbolOrSymbols: Symbol | readonly Symbol[]): Symbol | (Symbol | undefined)[] | undefined {
if (Array.isArray(symbolOrSymbols)) {
const data = this.client.apiRequest<(SymbolResponse | null)[]>("getImmediateAliasedSymbols", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
}
const sym = symbolOrSymbols as Symbol;
const data = this.client.apiRequest<SymbolResponse | null>("getImmediateAliasedSymbol", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}
Expand Down Expand Up @@ -1714,21 +1752,46 @@ export class Checker {
return signature.id === (this.getWellKnownSignatures()).unknown;
}

getExportsOfModule(symbol: Symbol): readonly Symbol[] {
const data = this.client.apiRequest<SymbolResponse[] | null>("getExportsOfModule", {
getExportsOfModule(symbol: Symbol): Symbol[];
getExportsOfModule(symbols: readonly Symbol[]): Symbol[][];
getExportsOfModule(symbolOrSymbols: Symbol | readonly Symbol[]): Symbol[] | Symbol[][] {
if (Array.isArray(symbolOrSymbols)) {
const data = this.client.apiRequest<SymbolResponse[][]>("getExportsOfModules", {
snapshot: this.snapshotId,
project: this.project.id,
symbols: symbolOrSymbols.map(s => s.id),
});
return data.map(d => d ? d.map(s => this.objectRegistry.getOrCreateSymbol(s)) : []);
}
const sym = symbolOrSymbols as Symbol;
const data = this.client.apiRequest<SymbolResponse[]>("getExportsOfModule", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
symbol: sym.id,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

getMemberInModuleExports(symbol: Symbol, name: string): Symbol | undefined {
getMemberInModuleExports(symbol: Symbol, name: string): Symbol | undefined;
getMemberInModuleExports(requests: readonly { symbol: Symbol; name: string; }[]): (Symbol | undefined)[];
getMemberInModuleExports(
symbolOrRequests: Symbol | readonly { symbol: Symbol; name: string; }[],
name?: string,
): Symbol | (Symbol | undefined)[] | undefined {
if (Array.isArray(symbolOrRequests)) {
const data = this.client.apiRequest<(SymbolResponse | null)[]>("getMembersInModuleExports", {
snapshot: this.snapshotId,
project: this.project.id,
requests: symbolOrRequests.map(r => ({ symbol: r.symbol.id, name: r.name })),
});
return data.map(d => d ? this.objectRegistry.getOrCreateSymbol(d) : undefined);
}
const sym = symbolOrRequests as Symbol;
const data = this.client.apiRequest<SymbolResponse | null>("getMemberInModuleExports", {
snapshot: this.snapshotId,
project: this.project.id,
symbol: symbol.id,
name,
symbol: sym.id,
name: name!,
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}
Expand Down
Loading
Loading