mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4e5c2d5fd5
commit
588eaeb2df
@ -30,13 +30,13 @@ export enum RoutingErrorType {
|
|||||||
MISSING_EXTENSION = "missing-ext",
|
MISSING_EXTENSION = "missing-ext",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RoutingError extends Error {
|
export class RoutingError<Query> extends Error {
|
||||||
/**
|
/**
|
||||||
* Will be set if the routing error originated in an extension route table
|
* Will be set if the routing error originated in an extension route table
|
||||||
*/
|
*/
|
||||||
public extensionName?: string;
|
public extensionName?: string;
|
||||||
|
|
||||||
constructor(public type: RoutingErrorType, public url: Url) {
|
constructor(public type: RoutingErrorType, public url: Url<Query>) {
|
||||||
super("routing error");
|
super("routing error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,7 +91,7 @@ export abstract class LensProtocolRouter extends Singleton {
|
|||||||
* @param url the parsed URL that initiated the `lens://` protocol
|
* @param url the parsed URL that initiated the `lens://` protocol
|
||||||
* @returns true if a route has been found
|
* @returns true if a route has been found
|
||||||
*/
|
*/
|
||||||
protected _routeToInternal(url: Url): RouteAttempt {
|
protected _routeToInternal(url: Url<Record<string, string>>): RouteAttempt {
|
||||||
return this._route(this.internalRoutes.entries(), url);
|
return this._route(this.internalRoutes.entries(), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ export abstract class LensProtocolRouter extends Singleton {
|
|||||||
* @param routes the array of path schemas, handler pairs to match against
|
* @param routes the array of path schemas, handler pairs to match against
|
||||||
* @param url the url (in its current state)
|
* @param url the url (in its current state)
|
||||||
*/
|
*/
|
||||||
protected _findMatchingRoute(routes: Iterable<[string, RouteHandler]>, url: Url): null | [match<Record<string, string>>, RouteHandler] {
|
protected _findMatchingRoute(routes: Iterable<[string, RouteHandler]>, url: Url<Record<string, string>>): null | [match<Record<string, string>>, RouteHandler] {
|
||||||
const matches: [match<Record<string, string>>, RouteHandler][] = [];
|
const matches: [match<Record<string, string>>, RouteHandler][] = [];
|
||||||
|
|
||||||
for (const [schema, handler] of routes) {
|
for (const [schema, handler] of routes) {
|
||||||
@ -128,7 +128,7 @@ export abstract class LensProtocolRouter extends Singleton {
|
|||||||
* @param routes the array of (path schemas, handler) pairs to match against
|
* @param routes the array of (path schemas, handler) pairs to match against
|
||||||
* @param url the url (in its current state)
|
* @param url the url (in its current state)
|
||||||
*/
|
*/
|
||||||
protected _route(routes: Iterable<[string, RouteHandler]>, url: Url, extensionName?: string): RouteAttempt {
|
protected _route(routes: Iterable<[string, RouteHandler]>, url: Url<Record<string, string>>, extensionName?: string): RouteAttempt {
|
||||||
const route = this._findMatchingRoute(routes, url);
|
const route = this._findMatchingRoute(routes, url);
|
||||||
|
|
||||||
if (!route) {
|
if (!route) {
|
||||||
@ -166,7 +166,7 @@ export abstract class LensProtocolRouter extends Singleton {
|
|||||||
* @param url the protocol request URI that was "open"-ed
|
* @param url the protocol request URI that was "open"-ed
|
||||||
* @returns either the found name or the instance of `LensExtension`
|
* @returns either the found name or the instance of `LensExtension`
|
||||||
*/
|
*/
|
||||||
protected async _findMatchingExtensionByName(url: Url): Promise<LensExtension | string> {
|
protected async _findMatchingExtensionByName(url: Url<Record<string, string>>): Promise<LensExtension | string> {
|
||||||
interface ExtensionUrlMatch {
|
interface ExtensionUrlMatch {
|
||||||
[EXTENSION_PUBLISHER_MATCH]: string;
|
[EXTENSION_PUBLISHER_MATCH]: string;
|
||||||
[EXTENSION_NAME_MATCH]: string;
|
[EXTENSION_NAME_MATCH]: string;
|
||||||
@ -222,7 +222,7 @@ export abstract class LensProtocolRouter extends Singleton {
|
|||||||
* Note: this function modifies its argument, do not reuse
|
* Note: this function modifies its argument, do not reuse
|
||||||
* @param url the protocol request URI that was "open"-ed
|
* @param url the protocol request URI that was "open"-ed
|
||||||
*/
|
*/
|
||||||
protected async _routeToExtension(url: Url): Promise<RouteAttempt> {
|
protected async _routeToExtension(url: Url<Record<string, string>>): Promise<RouteAttempt> {
|
||||||
const extension = await this._findMatchingExtensionByName(url);
|
const extension = await this._findMatchingExtensionByName(url);
|
||||||
|
|
||||||
if (typeof extension === "string") {
|
if (typeof extension === "string") {
|
||||||
|
|||||||
@ -39,7 +39,7 @@ export interface FallbackHandler {
|
|||||||
* @returns `true` if it should be routed internally to Lens, `false` if to an extension
|
* @returns `true` if it should be routed internally to Lens, `false` if to an extension
|
||||||
* @throws if `host` is not valid
|
* @throws if `host` is not valid
|
||||||
*/
|
*/
|
||||||
function checkHost(url: URLParse): boolean {
|
function checkHost<Query>(url: URLParse<Query>): boolean {
|
||||||
switch (url.host) {
|
switch (url.host) {
|
||||||
case "app":
|
case "app":
|
||||||
return true;
|
return true;
|
||||||
@ -112,7 +112,7 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _findMatchingExtensionByName(url: URLParse): Promise<LensExtension | string> {
|
protected async _findMatchingExtensionByName(url: URLParse<Record<string, string>>): Promise<LensExtension | string> {
|
||||||
const firstAttempt = await super._findMatchingExtensionByName(url);
|
const firstAttempt = await super._findMatchingExtensionByName(url);
|
||||||
|
|
||||||
if (typeof firstAttempt !== "string") {
|
if (typeof firstAttempt !== "string") {
|
||||||
@ -126,7 +126,7 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _routeToInternal(url: URLParse): RouteAttempt {
|
protected _routeToInternal(url: URLParse<Record<string, string>>): RouteAttempt {
|
||||||
const rawUrl = url.toString(); // for sending to renderer
|
const rawUrl = url.toString(); // for sending to renderer
|
||||||
const attempt = super._routeToInternal(url);
|
const attempt = super._routeToInternal(url);
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
|||||||
return attempt;
|
return attempt;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _routeToExtension(url: URLParse): Promise<RouteAttempt> {
|
protected async _routeToExtension(url: URLParse<Record<string, string>>): Promise<RouteAttempt> {
|
||||||
const rawUrl = url.toString(); // for sending to renderer
|
const rawUrl = url.toString(); // for sending to renderer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user