UNPKG

@kwaeri/steward

Version:

The @kwaeri/steward component module of the @kwaeri/cli user-executable framework.

220 lines (219 loc) 7.19 kB
/** * SPDX-PackageName: kwaeri/steward * SPDX-PackageVersion: 0.5.0 * SPDX-FileCopyrightText: © 2014 - 2022 Richard Winters <kirvedx@gmail.com> and contributors * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR MIT */ import { KWAERI, NodeKitOptions } from '@kwaeri/standards-types'; import { ConfigurationPromise } from '@kwaeri/configuration'; import { Migration, MigrationPromise } from '@kwaeri/migration'; export declare const DEFAULTS: { PROVIDER_LIST: string[]; }; export declare const DELEGATION: { FILE_GENERATOR: string; MIGRATION_GENERATOR: string; PASSWORD_GENERATOR: string; MIGRATOR: string; }; export declare const KUE_QUEST: { NEW: string; ADD: string; GENERATE: string; MIGRATIONS: string; }; export declare const KUE_SPECIFICATION: { PROJECT: string; ENDPOINT: string; COMPONENT: string; MIGRATION: string; PASSWORD: string; }; export declare type ServiceSubscriptions = any; export declare type ServiceProvidersContracts = ServiceSubscriptions; export declare type ServiceHelpText = any; export declare type ServiceProviderName = string; export declare type ServiceProviderNameList = ServiceProviderName[]; export declare type ServiceProvider = { instance: any; contracts: ServiceSubscriptions; helpText: ServiceHelpText; }; export declare type ServiceProvidersList = { [key: string]: ServiceProvider; }; export declare type ServiceProviderHelpTexts = { [key: string]: ServiceHelpText; }; export declare type ProvidersConfigurationPromise = { found?: boolean; list: ServiceProviderNameList; }; export declare type ProvidersContractsPromise = { result?: true; providers: ServiceProviderNameList; contracts: ServiceProvidersContracts; }; export declare type ProvidersHelpTextsPromise = { result?: true; providers: ServiceProviderNameList; helpTexts: ServiceProviderHelpTexts; }; export declare type AutomatonOptions = { type?: string; name?: string; extension?: string; }; export declare type AutomatonPromise = { specification: string; result: boolean; file?: string; path?: string; fullPath?: string; routine?: any[]; }; export declare type ContractPromise = { provider: string; result: boolean; file?: string; path?: string; fullPath?: string; routine?: any[]; }; export declare type DelegationPromise = { type?: string; specification: string; result: boolean; contracts: ContractPromise[]; }; export declare type ConfContextFlag = boolean | ConfigurationPromise; /** * Steward Class * * The Steward serves the CLI by mitigating the responsibility of * discovering service providers and their subscriptions, delegating * responsbility for commands received by the CLI for the end-user, * and responding back to the end user upon contract fulfillment. */ export declare class Steward { /** * @var { KWAERI.ENV.DEFAULT | KWAERI.ENV.PRODUCTION | KWAERI.ENV.TEST | undefined } environment */ environment: KWAERI.ENV.DEFAULT | KWAERI.ENV.PRODUCTION | KWAERI.ENV.TEST | undefined; /** * @var { Configuration } configuration; */ private configuration; /** * @var { ServiceProvidersList } serviceProviders */ private serviceProviders; /** * @var { Automaton } automaton */ /** * @var { Migrator } migrator */ migrator?: Migration; /** * @var { Cryptographer } cryptographer */ /** * Class constructor */ constructor(environment: KWAERI.ENV.DEFAULT | KWAERI.ENV.PRODUCTION | KWAERI.ENV.TEST | undefined); /** * Method to get a service provider's name based on the module import string. * * @param { String } moduleName The module import string * * @returns { String } The service provider's class name */ getServiceProvider(moduleName: string): String; /** * Method to load the service provider list from the cli configuration (or fallback * to the default list of service providers) * * @params none * * @returns { ProvidersConfigurationPromise } A list of service provider's (their module import strings) */ getProviders<T extends ProvidersConfigurationPromise>(): Promise<T>; /** * Method to discover service providers and the service contracts they offer * * @param none * * @returns { Promise<DiscoveryPromise> } Returns providers contract metadata */ getContracts<T extends ProvidersContractsPromise>(): Promise<T>; /** * Method to get help text from providers * * @param none * * @returns { Promise<DiscoveryPromise> } Returns providers contract metadata */ getHelpTexts<T extends ProvidersHelpTextsPromise>(): T; /** * Method which matches providers to the contracts requested. * * Finds the provider's name associated with the contract requisitioned by * the end user, by searching the contracts listed in the service provider * instance list that is stored with the steward, allowing the contract to * be delegated.. * * @param { NodeKitOptions } options * * @returns { Array<string> } An array of provider names */ matchProviders(options: NodeKitOptions): any; /** * Delegate fulfillment of user [subscriber] requisition [subscription] to * service provider [publisher] * * @param { NodeKitOptions } options Options for a user-requested action/command. * * @return { Promise<DelegationPromise> } */ delegate<T extends DelegationPromise>(options: NodeKitOptions): Promise<T>; /** * Invokes an array of factory methods; Each a method that executes a promise * thus that each is run sequentially. * * @param { () => Promise<any> } promiseFactories An array of promise executing factory methods * * @returns { any[] } An array of Fulfilled promises */ static serially: (promiseFactories: any[]) => any; /** * Invokes the { Automaton } for generating files/folders based upon the request * of the end-user * * @deprecated `generate()` has been deprecated in favor of the `delegate` metohd, as part of the user-executable proe * * * @param { GenerateFileType } options A { GenerateFileType } object which specifies options used by the { Automaton } in generating files/folders * * @return { void } */ generate<T extends AutomatonPromise>(options: NodeKitOptions): Promise<T>; /** * Method for running migrations * * @deprecated The migrations system is implemented no differently than anything else; Through the template * * @param { string } migrationPath A string representing the path to a directory where migrations exist * * @return { Promise<T> } */ migrate<T extends MigrationPromise>(options: NodeKitOptions): Promise<T>; /** * Hashes a string password using sha-256 encryption * * @param theString * * @return { string } The hashed string */ hash(theString: string): Promise<string>; }