api type-guards
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { hasApiExport, hasDefaultExport, isManifestClassConstructorType } from './type-guards/index.js';
|
||||
import { hasApiExport, hasDefaultExport, isManifestApiConstructorType } from './type-guards/index.js';
|
||||
import type { ManifestApi, ClassConstructor, ManifestElementAndApi } from './types.js';
|
||||
import { loadExtensionApi } from './load-extension-api.function.js';
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function createExtensionApi<ApiType = unknown>(
|
||||
): Promise<ApiType | undefined> {
|
||||
const js = await loadExtensionApi(manifest);
|
||||
|
||||
if (isManifestClassConstructorType<ApiType>(manifest)) {
|
||||
if (isManifestApiConstructorType<ApiType>(manifest)) {
|
||||
return new manifest.api(...constructorArguments);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from './is-manifest-class-instance-type.function.js';
|
||||
export * from './is-manifest-classable-type.function.js';
|
||||
export * from './is-manifest-api-instance-type.function.js';
|
||||
export * from './is-manifest-apiable-type.function.js';
|
||||
export * from './is-manifest-element-name-type.function.js';
|
||||
export * from './is-manifest-elementable-type.function.js';
|
||||
export * from './is-manifest-js-type.function.js';
|
||||
@@ -8,4 +8,4 @@ export * from './is-manifest-api-js-type.function.js';
|
||||
export * from './is-manifest-loader-type.function.js';
|
||||
export * from './has-default-export.function.js';
|
||||
export * from './has-element-export.function.js';
|
||||
export * from './has-api-export.function.js';
|
||||
export * from './has-api-export.function.js';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ClassConstructor, ManifestApi } from '../types.js';
|
||||
|
||||
export function isManifestClassConstructorType<ApiType>(manifest: unknown): manifest is ManifestApiWithClassConstructor<ApiType> {
|
||||
export function isManifestApiConstructorType<ApiType>(manifest: unknown): manifest is ManifestApiWithClassConstructor<ApiType> {
|
||||
return typeof manifest === 'object' && manifest !== null && (manifest as ManifestApi).api !== undefined;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { ManifestBase, ManifestApi } from '../types.js';
|
||||
import { isManifestJSType } from './is-manifest-js-type.function.js';
|
||||
import { isManifestLoaderType } from './is-manifest-loader-type.function.js';
|
||||
import { isManifestApiConstructorType } from './is-manifest-api-instance-type.function.js';
|
||||
import { isManifestApiJSType } from './is-manifest-api-js-type.function.js';
|
||||
|
||||
export function isManifestApiType(manifest: ManifestBase): manifest is ManifestApi {
|
||||
return (
|
||||
isManifestApiConstructorType(manifest) ||
|
||||
isManifestLoaderType<object>(manifest) ||
|
||||
isManifestApiJSType<object>(manifest) ||
|
||||
isManifestJSType<object>(manifest)
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { ManifestBase, ManifestApi } from '../types.js';
|
||||
import { isManifestJSType } from './is-manifest-js-type.function.js';
|
||||
import { isManifestLoaderType } from './is-manifest-loader-type.function.js';
|
||||
import { isManifestClassConstructorType } from './is-manifest-class-instance-type.function.js';
|
||||
|
||||
export function isManifestClassableType(manifest: ManifestBase): manifest is ManifestApi {
|
||||
return (
|
||||
isManifestClassConstructorType(manifest) ||
|
||||
isManifestLoaderType<object>(manifest) ||
|
||||
isManifestJSType<object>(manifest)
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ManifestElement, ManifestBase } from '../types.js';
|
||||
import { isManifestElementJSType } from './is-manifest-element-js-type.function.js';
|
||||
import { isManifestElementNameType } from './is-manifest-element-name-type.function.js';
|
||||
import { isManifestJSType } from './is-manifest-js-type.function.js';
|
||||
import { isManifestLoaderType } from './is-manifest-loader-type.function.js';
|
||||
@@ -9,6 +10,7 @@ export function isManifestElementableType<ElementType extends HTMLElement = HTML
|
||||
return (
|
||||
isManifestElementNameType(manifest) ||
|
||||
isManifestLoaderType<ElementType>(manifest) ||
|
||||
isManifestElementJSType<ElementType>(manifest) ||
|
||||
isManifestJSType<ElementType>(manifest)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user