UNPKG

@nasriya/hypercloud

Version:

Nasriya HyperCloud is a lightweight Node.js HTTP2 framework.

290 lines (289 loc) 11.5 kB
import { RenderingCacheAsset } from '../../docs/docs'; import HyperCloudServer from '../../server'; import Component from './assets/Component'; import Page from './assets/Page'; import GlobalAssets from './managers/globalAssetsManager'; /** * This class is used inside a {@link HyperCloudServer} as * `{@link HyperCloudServer["rendering"]}` */ declare class RenderingManager { #private; constructor(server: HyperCloudServer); /** * Set or get your site/brand name. This will be used in page rendering. * @example * // Setup a default name * server.rendering.siteName.set('Nasriya Software'); * // or * server.rendering.siteName.set('Nasriya Software', 'default'); * // or * server.rendering.siteName.multilingual.set({ * default: 'Nasriya Software' * }); * @example * // Setup multilingual names * server.rendering.siteName.multilingual.set({ * default: 'Nasriya Software', * ar: "ناصرية سوفتوير" * }); */ readonly siteName: { /** * Set the name of your site or brand * @param name The site/brand name * @param lang The language you want to bind this name to (optional) */ set: (name: string, lang?: string) => void; /**Set the name of your site in different languages */ multilingual: { /** * Set your site or brand name in multiple languages * @param names An object containing a `lang: name` pairs * @example * server.rendering.siteName.multilingual.set({ * default: 'Nasriya Software', * ar: "ناصرية سوفتوير" * }); */ set: (names: Record<string, string>) => void; }; /** * Get the site/brand name * @param lang The language of the site/brand name */ get: (lang?: string) => string; }; readonly components: { readonly "__#7@#_storage": Record<string, Component>; readonly "__#7@#_registers": Promise<void>[]; readonly "__#7@#_helpers": { create: (component: Component) => void; register: (directory: string) => Promise<void>; }; register(paths: string | string[]): void; scan(): Promise<void>; readonly all: Component[]; readonly storage: Record<string, Component>; }; readonly pages: { readonly "__#6@#_storage": Record<string, Page>; readonly "__#6@#_registers": Promise<void>[]; readonly "__#6@#_helpers": { create: (page: Page) => void; register: (directory: string) => Promise<void>; }; register(paths: string | string[]): void; scan(): Promise<void>; readonly all: Page[]; readonly storage: Record<string, Page>; }; /**Set global assets for your server */ get assets(): GlobalAssets; /**The base URL of the assets used in the renderer */ get assetsBaseUrl(): string; /** * Increase your server's performance by enabling caching. * Caching stores the files in memory (RAM) which is way faster than * any other type of storage. * * **NOTE:** * * You can enable/disable caching of certain files */ readonly cache: { /**Enable caching for certain assets */ enableFor: { /** * Enable caching for certain files extensions for pages * @example * // Enable caching for all supported files * server.rendering.cache.enableFor.pages(); * @example * // Enable caching for JSON files * server.rendering.cache.enableFor.pages(['json']); * @example * // Enable caching for JavaScript and CSS files * server.rendering.cache.enableFor.pages(['js', 'css']); * @param extensions */ pages: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; /** * Enable caching for certain files extensions for components * @example * // Enable caching for all supported files * server.rendering.cache.enableFor.components(); * @example * // Enable caching for JSON files * server.rendering.cache.enableFor.components(['json']); * @example * // Enable caching for JavaScript and CSS files * server.rendering.cache.enableFor.components(['js', 'css']); * @param extensions */ components: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; /** * Enable caching for certain files extensions for global assets * @example * // Enable caching for all supported files * server.rendering.cache.enableFor.globalAssets(); * @example * // Enable caching for JSON files * server.rendering.cache.enableFor.globalAssets(['json']); * @example * // Enable caching for JavaScript and CSS files * server.rendering.cache.enableFor.globalAssets(['js', 'css']); * @param extensions */ globalAssets: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; /** * Enable caching for certain files extensions for pages and components * @example * // Enable caching for all supported files * server.rendering.cache.enableFor.everything(); * @example * // Enable caching for JSON files * server.rendering.cache.enableFor.everything(['json']); * @example * // Enable caching for JavaScript and CSS files * server.rendering.cache.enableFor.everything(['js', 'css']); * @param extensions */ everything: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; }; /**Disable caching for certain assets */ disableFor: { /** * Disable caching for certain files extensions for pages * @example * // Disable caching for all supported files * server.rendering.cache.disableFor.pages(); * @example * // Disable caching for JSON files * server.rendering.cache.disableFor.pages(['json']); * @example * // Disable caching for JavaScript and CSS files * server.rendering.cache.disableFor.pages(['js', 'css']); * @param extensions */ pages: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; /** * Disable caching for certain files extensions for components * @example * // Disable caching for all supported files * server.rendering.cache.disableFor.components(); * @example * // Disable caching for JSON files * server.rendering.cache.disableFor.components(['json']); * @example * // Disable caching for JavaScript and CSS files * server.rendering.cache.disableFor.components(['js', 'css']); * @param extensions */ components: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; /** * Disable caching for certain files extensions for global assets * @example * // Disable caching for all supported files * server.rendering.cache.disableFor.globalAssets(); * @example * // Disable caching for JSON files * server.rendering.cache.disableFor.globalAssets(['json']); * @example * // Disable caching for JavaScript and CSS files * server.rendering.cache.disableFor.globalAssets(['js', 'css']); * @param extensions */ globalAssets: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; /** * Disable caching for certain files extensions for pages and components * @example * // Disable caching for all supported files * server.rendering.cache.disableFor.everything(); * @example * // Disable caching for JSON files * server.rendering.cache.disableFor.everything(['json']); * @example * // Disable caching for JavaScript and CSS files * server.rendering.cache.disableFor.everything(['js', 'css']); * @param extensions */ everything: (extensions?: RenderingCacheAsset | RenderingCacheAsset[]) => void; }; /**Read the caching status of assets */ statusOf: { /**Read the caching status of supported files extensions for pages */ pages: () => { css: boolean; js: boolean; json: boolean; }; /**Read the caching status of supported files extensions for components */ components: () => { css: boolean; js: boolean; json: boolean; }; /**Read the caching status of supported files extensions for global assets */ globalAssets: () => { css: boolean; js: boolean; json: boolean; }; /**Read the caching status of supported files extensions for everything */ everything: () => { pages: { css: boolean; js: boolean; json: boolean; }; components: { css: boolean; js: boolean; json: boolean; }; globalAssets: { css: boolean; js: boolean; json: boolean; }; }; }; /**A module to update caching assets */ update: { /**Update the cache of all pages */ pages: () => Promise<{ updateType: string; total: number; updated: number; failed: { total: number; errors: any[]; }; }>; /**Update the cache of all the components */ components: () => Promise<{ updateType: string; total: number; updated: number; failed: { total: number; errors: any[]; }; }>; /**Update the cache of global assets */ globalAssets: () => Promise<void>; /**Update the cache of everything */ everything: () => Promise<(void | { updateType: string; total: number; updated: number; failed: { total: number; errors: any[]; }; })[]>; }; }; } export default RenderingManager;