@altostra/core
Version:
Core library for shared types and logic
74 lines (73 loc) • 3.28 kB
TypeScript
/// <reference types="node" />
import type { Readable } from 'stream';
import type { Maybe } from "../../common/Maybe";
import type { TypeValidation } from '@altostra/type-validations';
import type { TemplateDescriptor, TemplateMetadata } from "./Common";
/**
* Template interface
*/
export interface Template<TTemplatesProviderType extends string> extends TemplateDescriptor<TTemplatesProviderType> {
/**
* The type of the provider that provided this template
*/
readonly type: TTemplatesProviderType;
/**
* The name of this template
*/
readonly name: string;
/**
* Gets the metadata for this template
* @returns Template metadata for this template
*/
getTemplateMetadata(): Promise<TemplateMetadata>;
/**
* Gets zip of the templates content
*/
getZippedFiles(): Promise<Maybe<Readable>>;
}
/**
* Basic implementation of `Template<T>`
*/
export declare abstract class TemplateBase<TTemplatesProviderType extends string> implements Template<TTemplatesProviderType> {
readonly type: TTemplatesProviderType;
readonly name: string;
constructor(type: TTemplatesProviderType, name: string);
abstract getTemplateMetadata(): Promise<TemplateMetadata>;
abstract getZippedFiles(): Promise<Maybe<Readable>>;
}
export declare const isAnyTemplateDescriptor: import("@altostra/type-validations").ObjectOfTypeValidation<TemplateDescriptor<string>>;
/**
* Creates a new `TypeValidation` that validates that a given value is a `TemplateDescriptor`
* of one of the specified types.
* @param type Define which `TemplateDescriptor` types are acceptable by the created
* `TypeValidation`
* @param types Define which `TemplateDescriptor` types are acceptable by the created
* `TypeValidation`
* @returns A `TypeValidation` that validates that a given value is a `TemplateDescriptor`
* of one of the specified types.
*/
export declare function createTemplateDescriptorValidation<TType extends string>(type: TType, ...types: TType[]): TypeValidation<TemplateDescriptor<TType>>;
/**
* [DEPRECATED] Checks if a value is a `TemplateDescriptor`
* @param val The value to check
* @param type Optional specific type to check
* @returns `true` if the provided value is template descriptor, and if `type`
* was provided, that the descriptor's type equals to the provided `type` \
* Otherwise, `false`
* @deprecated This function is dangerous when used with other type validations \
* Use `createTemplateDescriptorValidation` to create a proper validation
*/
export declare const isTemplateDescriptor: <TTemplatesProviderType extends string = string>(val: unknown, type?: TTemplatesProviderType | undefined) => val is TemplateDescriptor<TTemplatesProviderType>;
export declare function isTemplate<TTemplatesProviderType extends string = string>(val: unknown, type?: TTemplatesProviderType): val is Template<TTemplatesProviderType>;
/**
* A template for an empty project
*/
export declare class EmptyTemplate extends TemplateBase<''> {
/**
* Creates new empty project template
* @param name The name for the empty project template
*/
constructor(name: string);
getTemplateMetadata(): Promise<TemplateMetadata>;
getZippedFiles(): Promise<Maybe<Readable>>;
}