wacom
Version:
Module which has common services and components which can be used on all projects.
1,320 lines (1,291 loc) • 68.6 kB
TypeScript
import * as i0 from '@angular/core';
import { InjectionToken, OnInit, EventEmitter, ElementRef, PipeTransform, Signal, WritableSignal, ComponentFactoryResolver, ApplicationRef, Injector, ComponentRef, ModuleWithProviders } from '@angular/core';
import { Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import * as _angular_platform_browser from '@angular/platform-browser';
import { Meta, Title, DomSanitizer } from '@angular/platform-browser';
import { Observable } from 'rxjs';
import { HttpErrorResponse, HttpClient } from '@angular/common/http';
import * as i13 from '@angular/common';
import { DatePipe } from '@angular/common';
import * as i14 from '@angular/forms';
interface Any {
[key: string]: string;
}
interface Config {
meta?: {
useTitleSuffix?: boolean;
warnMissingGuard?: boolean;
defaults?: {
title?: string;
titleSuffix?: string;
} & {
[key: string]: string | undefined;
};
};
alert?: {
alerts?: object;
text?: string;
type?: string;
icon?: string;
class?: string;
unique?: string;
progress?: boolean;
position?: string;
timeout?: number;
close?: any;
buttons?: any;
};
modal?: {
size?: any;
timeout?: any;
timestart?: any;
class?: string;
modals?: object;
position?: string;
closable?: boolean;
unique?: string;
};
popup?: {
popups?: object;
};
loader?: {
loaders?: object;
};
socket?: any;
io?: any;
http?: {
headers?: any;
url?: string;
};
store?: {
prefix?: string;
set?: (hold: any, value: any, cb?: () => void, errCb?: () => void) => Promise<boolean>;
get?: (hold: any, cb?: (value: string) => void, errCb?: () => void) => Promise<string>;
remove?: (hold: any, cb?: () => void, errCb?: () => void) => Promise<boolean>;
clear?: (cb?: () => void, errCb?: () => void) => Promise<boolean>;
};
}
declare const CONFIG_TOKEN: InjectionToken<Config>;
declare const DEFAULT_CONFIG: Config;
interface Alert {
onClose?: any;
alerts?: object;
component?: any;
text?: string;
icon?: string;
type?: string;
class?: string;
unique?: string;
progress?: boolean;
position?: string;
timeout?: any;
closable?: boolean;
close?: any;
buttons?: any;
[x: string]: any;
}
declare const DEFAULT_Alert: Alert;
interface Modal {
onOpen?: any;
onClose?: any;
onClickOutside?: any;
id?: number;
close?: any;
component?: any;
size?: any;
timeout?: any;
timestart?: any;
class?: string;
modals?: object;
position?: string;
closable?: boolean;
unique?: string;
[x: string]: any;
}
declare const DEFAULT_Modal: Modal;
interface CrudDocument {
_id: string;
appId?: string;
order?: number;
__created?: boolean;
__modified?: boolean;
}
interface CrudOptions<Document> {
name?: string;
alert?: string;
callback?: (resp: Document | Document[]) => void;
errCallback?: (resp: unknown) => void;
}
interface CrudServiceInterface<Document> {
get: (params: {
page: number;
}, options: CrudOptions<Document>) => any;
getDocs: () => Document[];
create: (doc: Document) => any;
update: (doc: Document) => any;
delete: (doc: Document) => any;
setPerPage?: (count: number) => void;
loaded: Promise<unknown>;
}
interface TableConfig<Document> {
paginate?: (page?: number) => void;
perPage?: number;
setPerPage?: ((count: number) => void) | undefined;
allDocs?: boolean;
create: (() => void) | null;
update: ((doc: Document) => void) | null;
delete: ((doc: Document) => void) | null;
buttons: ({
icon?: string;
click?: (doc: Document) => void;
hrefFunc?: (doc: Document) => string;
} | null)[];
headerButtons: ({
icon?: string;
click?: () => void;
hrefFunc?: (doc: Document) => string;
class?: string;
} | null)[];
}
declare class MetaService {
private router;
private meta;
private titleService;
private config;
private _meta;
constructor(router: Router, meta: Meta, titleService: Title, config: Config);
/**
* Sets the default meta tags.
*
* @param defaults - The default meta tags.
*/
setDefaults(defaults: {
[key: string]: string;
}): void;
/**
* Sets the title and optional title suffix.
*
* @param title - The title to set.
* @param titleSuffix - The title suffix to append.
* @returns The MetaService instance.
*/
setTitle(title?: string, titleSuffix?: string): MetaService;
/**
* Sets link tags.
*
* @param links - The links to set.
* @returns The MetaService instance.
*/
setLink(links: {
[key: string]: string;
}): MetaService;
/**
* Sets a meta tag.
*
* @param tag - The meta tag name.
* @param value - The meta tag value.
* @param prop - The meta tag property.
* @returns The MetaService instance.
*/
setTag(tag: string, value: string, prop?: string): MetaService;
/**
* Updates a meta tag.
*
* @param tag - The meta tag name.
* @param value - The meta tag value.
* @param prop - The meta tag property.
*/
private _updateMetaTag;
/**
* Removes a meta tag.
*
* @param tag - The meta tag name.
* @param prop - The meta tag property.
*/
removeTag(tag: string, prop?: string): void;
/**
* Warns about missing meta guards in routes.
*/
private _warnMissingGuard;
static ɵfac: i0.ɵɵFactoryDeclaration<MetaService, [null, null, null, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<MetaService>;
}
declare class MetaGuard {
private metaService;
private config;
static IDENTIFIER: string;
private _meta;
constructor(metaService: MetaService, config: Config);
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean;
private _processRouteMetaTags;
static ɵfac: i0.ɵɵFactoryDeclaration<MetaGuard, [null, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<MetaGuard>;
}
declare class AlertComponent {
alert: any;
component: any;
text: string;
class: string;
type: string;
progress: boolean;
position: string;
icon: string;
timeout: any;
close: any;
closable: any;
buttons: any;
constructor();
delete_animation: boolean;
remove(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<AlertComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<AlertComponent, "alert", never, {}, {}, never, never, false, never>;
}
declare class ModalComponent implements OnInit {
class: string;
size: string;
closable: boolean;
close: any;
onOpen: any;
timestart: any;
timeout: any;
showModal: boolean;
allowClose: boolean;
onClickOutside: any;
ngOnInit(): void;
ngAfterViewInit(): void;
ngOnDestroy(): void;
popStateListener(e: Event): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ModalComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<ModalComponent, "lib-modal", never, {}, {}, never, never, false, never>;
}
declare class LoaderComponent {
loader: any;
text: string;
class: string;
progress: boolean;
timeout: number;
close: any;
closable: any;
constructor();
ngOnInit(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<LoaderComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<LoaderComponent, "lib-loader", never, {}, {}, never, never, false, never>;
}
/**
* BaseComponent is an abstract class that provides basic functionality for managing the current timestamp.
*/
declare abstract class BaseComponent {
/**
* The current timestamp in milliseconds since the Unix epoch.
*/
now: number;
/**
* Refreshes the `now` property with the current timestamp.
*/
refreshNow(): void;
}
/**
* Abstract reusable base class for CRUD list views.
* It encapsulates pagination, modals, and document handling logic.
*
* @template Service - A service implementing CrudServiceInterface for a specific document type
* @template Document - The data model extending CrudDocument
*/
declare abstract class CrudComponent<Service extends CrudServiceInterface<Document>, Document extends CrudDocument, FormInterface> {
protected formService: unknown;
protected translate: {
translate: (key: string) => string;
};
/** Service responsible for data fetching, creating, updating, deleting */
protected service: Service;
/** The array of documents currently loaded and shown */
protected documents: Document[];
/** The reactive form instance generated from the provided config */
protected form: any;
/** Current pagination page */
protected page: number;
/** CoreService handles timing and copying helpers */
private __core;
/** AlertService handles alerts */
private __alert;
/** ChangeDetectorRef handles on push strategy */
private __cdr;
/** Internal reference to form service matching FormServiceInterface */
private __form;
/**
* Constructor
*
* @param formConfig - Object describing form title and its component structure
* @param formService - Any service that conforms to FormServiceInterface (usually casted)
* @param translate - An object providing a translate() method for i18n
* @param service - CRUD service implementing get/create/update/delete
*/
constructor(formConfig: unknown, formService: unknown, translate: {
translate: (key: string) => string;
}, service: Service, module?: string);
/**
* Loads documents for a given page.
*/
protected setDocuments(page?: number): Promise<void>;
protected updatableFields: string[];
/**
* Clears temporary metadata before document creation.
*/
protected preCreate(doc: Document): void;
/**
* Funciton which controls whether the create functionality is available.
*/
protected allowCreate(): boolean;
/**
* Funciton which controls whether the update and delete functionality is available.
*/
protected allowMutate(): boolean;
/**
* Funciton which controls whether the unique url functionality is available.
*/
protected allowUrl(): boolean;
protected allowSort(): boolean;
/**
* Funciton which prepare get crud options.
*/
protected getOptions(): CrudOptions<Document>;
/**
* Handles bulk creation and updating of documents.
* In creation mode, adds new documents.
* In update mode, syncs changes and deletes removed entries.
*/
protected bulkManagement(create?: boolean): () => void;
protected configType: 'server' | 'local';
protected perPage: number;
/**
* Configuration object used by the UI for rendering table and handling actions.
*/
protected getConfig(): TableConfig<Document>;
private _module;
}
declare class ClickOutsideDirective {
private elementRef;
clickOutside: EventEmitter<Event>;
constructor(elementRef: ElementRef);
onClick(event: Event): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ClickOutsideDirective, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<ClickOutsideDirective, "[clickOutside]", never, {}, { "clickOutside": "clickOutside"; }, never, never, false, never>;
}
declare class ArrPipe implements PipeTransform {
transform(data: any, type?: any, refresh?: any): any;
static ɵfac: i0.ɵɵFactoryDeclaration<ArrPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<ArrPipe, "arr", false>;
}
declare class MongodatePipe implements PipeTransform {
transform(_id: any): Date;
static ɵfac: i0.ɵɵFactoryDeclaration<MongodatePipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<MongodatePipe, "mongodate", false>;
}
declare class PaginationPipe implements PipeTransform {
transform(arr: any, config: any, sort: any, search?: string): any;
static ɵfac: i0.ɵɵFactoryDeclaration<PaginationPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<PaginationPipe, "page", false>;
}
declare class SafePipe {
private sanitizer;
constructor(sanitizer: DomSanitizer);
transform(html: any): _angular_platform_browser.SafeResourceUrl;
static ɵfac: i0.ɵɵFactoryDeclaration<SafePipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<SafePipe, "safe", false>;
}
declare class SearchPipe implements PipeTransform {
private c;
transform(given: any, s?: any, f?: any, l?: any, i?: any, reload?: any): any;
static ɵfac: i0.ɵɵFactoryDeclaration<SearchPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<SearchPipe, "search", false>;
}
declare class SplicePipe implements PipeTransform {
transform(from: any, which: any, refresh?: number): any;
static ɵfac: i0.ɵɵFactoryDeclaration<SplicePipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<SplicePipe, "splice", false>;
}
declare class SplitPipe implements PipeTransform {
transform(value: string, index?: number, devider?: string): unknown;
static ɵfac: i0.ɵɵFactoryDeclaration<SplitPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<SplitPipe, "split", false>;
}
declare class NumberPipe implements PipeTransform {
transform(value: unknown): number;
static ɵfac: i0.ɵɵFactoryDeclaration<NumberPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<NumberPipe, "number", false>;
}
declare class BaseService {
now: number;
refreshNow(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<BaseService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<BaseService>;
}
interface Selectitem {
name: string;
_id: string;
}
declare global {
interface String {
capitalize(): string;
}
}
declare class CoreService {
private platformId;
deviceID: string;
constructor(platformId: boolean);
/**
* Generates a UUID (Universally Unique Identifier) version 4.
*
* This implementation uses `Math.random()` to generate random values,
* making it suitable for general-purpose identifiers, but **not** for
* cryptographic or security-sensitive use cases.
*
* The format follows the UUID v4 standard: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
* where:
* - `x` is a random hexadecimal digit (0–f)
* - `4` indicates UUID version 4
* - `y` is one of 8, 9, A, or B
*
* Example: `f47ac10b-58cc-4372-a567-0e02b2c3d479`
*
* @returns A string containing a UUID v4.
*/
UUID(): string;
/**
* Converts an object to an array. Optionally holds keys instead of values.
*
* @param {any} obj - The object to be converted.
* @param {boolean} [holder=false] - If true, the keys will be held in the array; otherwise, the values will be held.
* @returns {any[]} The resulting array.
*/
ota(obj: any, holder?: boolean): any[];
/**
* Removes elements from `fromArray` that are present in `removeArray` based on a comparison field.
*
* @param {any[]} removeArray - The array of elements to remove.
* @param {any[]} fromArray - The array from which to remove elements.
* @param {string} [compareField='_id'] - The field to use for comparison.
* @returns {any[]} The modified `fromArray` with elements removed.
*/
splice(removeArray: any[], fromArray: any[], compareField?: string): any[];
/**
* Unites multiple _id values into a single unique _id.
* The resulting _id is unique regardless of the order of the input _id values.
*
* @param {...string[]} args - The _id values to be united.
* @returns {string} The unique combined _id.
*/
ids2id(...args: string[]): string;
private _afterWhile;
/**
* Delays the execution of a callback function for a specified amount of time.
* If called again within that time, the timer resets.
*
* @param {string | object | (() => void)} doc - A unique identifier for the timer, an object to host the timer, or the callback function.
* @param {() => void} [cb] - The callback function to execute after the delay.
* @param {number} [time=1000] - The delay time in milliseconds.
*/
afterWhile(doc: string | object | (() => void), cb?: () => void, time?: number): void;
/**
* Recursively copies properties from one object to another.
* Handles nested objects, arrays, and Date instances appropriately.
*
* @param from - The source object from which properties are copied.
* @param to - The target object to which properties are copied.
*/
copy(from: any, to: any): void;
device: string;
/**
* Detects the device type based on the user agent.
*/
detectDevice(): void;
/**
* Checks if the device is a mobile device.
* @returns {boolean} - Returns true if the device is a mobile device.
*/
isMobile(): boolean;
/**
* Checks if the device is a tablet.
* @returns {boolean} - Returns true if the device is a tablet.
*/
isTablet(): boolean;
/**
* Checks if the device is a web browser.
* @returns {boolean} - Returns true if the device is a web browser.
*/
isWeb(): boolean;
/**
* Checks if the device is an Android device.
* @returns {boolean} - Returns true if the device is an Android device.
*/
isAndroid(): boolean;
/**
* Checks if the device is an iOS device.
* @returns {boolean} - Returns true if the device is an iOS device.
*/
isIos(): boolean;
version: string;
appVersion: string;
dateVersion: string;
/**
* Sets the combined version string based on appVersion and dateVersion.
*/
setVersion(): void;
/**
* Sets the app version and updates the combined version string.
*
* @param {string} appVersion - The application version to set.
*/
setAppVersion(appVersion: string): void;
/**
* Sets the date version and updates the combined version string.
*
* @param {string} dateVersion - The date version to set.
*/
setDateVersion(dateVersion: string): void;
private _signals;
/**
* Emits a signal, optionally passing data to the listeners.
* @param signal - The name of the signal to emit.
* @param data - Optional data to pass to the listeners.
*/
emit(signal: string, data?: any): void;
/**
* Returns an Observable that emits values when the specified signal is emitted.
* Multiple components or services can subscribe to this Observable to be notified of the signal.
* @param signal - The name of the signal to listen for.
* @returns An Observable that emits when the signal is emitted.
*/
on(signal: string): Observable<any>;
/**
* Completes the Subject for a specific signal, effectively stopping any future emissions.
* This also unsubscribes all listeners for the signal.
* @param signal - The name of the signal to stop.
*/
off(signal: string): void;
private _completed;
private _completeResolvers;
/**
* Marks a task as complete.
* @param task - The task to mark as complete, identified by a string.
*/
complete(task: string, document?: unknown): void;
/**
* Waits for one or more tasks to be marked as complete.
*
* @param {string | string[]} tasks - The task or array of tasks to wait for.
* @returns {Promise<unknown>} A promise that resolves when all specified tasks are complete.
* - If a single task is provided, resolves with its completion result.
* - If multiple tasks are provided, resolves with an array of results in the same order.
*
* @remarks
* If any task is not yet completed, a resolver is attached. The developer is responsible for managing
* resolver cleanup if needed. Resolvers remain after resolution and are not removed automatically.
*/
onComplete(tasks: string | string[]): Promise<unknown>;
/**
* Returns a resolver function that checks if all given tasks are completed,
* and if so, calls the provided resolve function with their results.
*
* @param {string[]} tasks - The list of task names to monitor for completion.
* @param {(value: unknown) => void} resolve - The resolver function to call once all tasks are complete.
* @returns {(doc: unknown) => void} A function that can be registered as a resolver for each task.
*
* @remarks
* This function does not manage or clean up resolvers. It assumes the developer handles any potential duplicates or memory concerns.
*/
private _allCompleted;
/**
* Checks whether all specified tasks have been marked as completed.
*
* @param {string[]} tasks - The array of task names to check.
* @returns {boolean} `true` if all tasks are completed, otherwise `false`.
*/
private _isCompleted;
/**
* Checks if a task is completed.
* @param task - The task to check, identified by a string.
* @returns True if the task is completed, false otherwise.
*/
completed(task: string): unknown;
/**
* Clears the completed state for a specific task.
*
* This removes the task from the internal `_completed` store,
* allowing it to be awaited again in the future if needed.
* It does not affect pending resolvers or trigger any callbacks.
*
* @param task - The task identifier to clear from completed state.
*/
clearCompleted(task: string): void;
private _locked;
private _unlockResolvers;
/**
* Locks a resource to prevent concurrent access.
* @param which - The resource to lock, identified by a string.
*/
lock(which: string): void;
/**
* Unlocks a resource, allowing access.
* @param which - The resource to unlock, identified by a string.
*/
unlock(which: string): void;
/**
* Returns a Promise that resolves when the specified resource is unlocked.
* @param which - The resource to watch for unlocking, identified by a string.
* @returns A Promise that resolves when the resource is unlocked.
*/
onUnlock(which: string): Promise<void>;
/**
* Checks if a resource is locked.
* @param which - The resource to check, identified by a string.
* @returns True if the resource is locked, false otherwise.
*/
locked(which: string): boolean;
linkCollections: string[];
linkRealCollectionName: Record<string, string>;
linkIds: Record<string, Selectitem[]>;
addLink(name: string, reset: () => Selectitem[], realName?: string): void;
/**
* Converts a plain object into a signal-wrapped object.
* Optionally wraps specific fields of the object as individual signals,
* and merges them into the returned signal for fine-grained reactivity.
*
* @template Document - The type of the object being wrapped.
* @param {Document} document - The plain object to wrap into a signal.
* @param {Record<string, (doc: Document) => unknown>} [signalFields={}] -
* Optional map where each key is a field name and the value is a function
* to extract the initial value for that field. These fields will be wrapped
* as separate signals and embedded in the returned object.
*
* @returns {Signal<Document>} A signal-wrapped object, possibly containing
* nested field signals for more granular control.
*
* @example
* const user = { _id: '1', name: 'Alice', score: 42 };
* const sig = toSignal(user, { score: (u) => u.score });
* console.log(sig().name); // 'Alice'
* console.log(sig().score()); // 42 — field is now a signal
*/
toSignal<Document>(document: Document, signalFields?: Record<string, (doc: Document) => unknown>): Signal<Document>;
/**
* Converts an array of objects into an array of Angular signals.
* Optionally wraps specific fields of each object as individual signals.
*
* @template Document - The type of each object in the array.
* @param {Document[]} arr - Array of plain objects to convert into signals.
* @param {Record<string, (doc: Document) => unknown>} [signalFields={}] -
* Optional map where keys are field names and values are functions that extract the initial value
* from the object. These fields will be turned into separate signals.
*
* @returns {Signal<Document>[]} An array where each item is a signal-wrapped object,
* optionally with individual fields also wrapped in signals.
*
* @example
* toSignalsArray(users, {
* name: (u) => u.name,
* score: (u) => u.score,
* });
*/
toSignalsArray<Document>(arr: Document[], signalFields?: Record<string, (doc: Document) => unknown>): Signal<Document>[];
/**
* Adds a new object to the signals array.
* Optionally wraps specific fields of the object as individual signals before wrapping the whole object.
*
* @template Document - The type of the object being added.
* @param {Signal<Document>[]} signals - The signals array to append to.
* @param {Document} item - The object to wrap and push as a signal.
* @param {Record<string, (doc: Document) => unknown>} [signalFields={}] -
* Optional map of fields to be wrapped as signals within the object.
*
* @returns {void}
*/
pushSignal<Document>(signals: Signal<Document>[], item: Document, signalFields?: Record<string, (doc: Document) => unknown>): void;
/**
* Removes the first signal from the array whose object's field matches the provided value.
* @template Document
* @param {WritableSignal<Document>[]} signals - The signals array to modify.
* @param {unknown} value - The value to match.
* @param {string} [field='_id'] - The object field to match against.
* @returns {void}
*/
removeSignalByField<Document extends Record<string, unknown>>(signals: WritableSignal<Document>[], value: unknown, field?: string): void;
/**
* Returns a generic trackBy function for *ngFor, tracking by the specified object field.
* @template Document
* @param {string} field - The object field to use for tracking (e.g., '_id').
* @returns {(index: number, sig: Signal<Document>) => unknown} TrackBy function for Angular.
*/
trackBySignalField<Document extends Record<string, unknown>>(field: string): (_: number, sig: Signal<Document>) => unknown;
/**
* Finds the first signal in the array whose object's field matches the provided value.
* @template Document
* @param {Signal<Document>[]} signals - Array of signals to search.
* @param {unknown} value - The value to match.
* @param {string} [field='_id'] - The object field to match against.
* @returns {Signal<Document> | undefined} The found signal or undefined if not found.
*/
findSignalByField<Document extends Record<string, unknown>>(signals: Signal<Document>[], value: unknown, field?: string): Signal<Document> | undefined;
/**
* Updates the first writable signal in the array whose object's field matches the provided value.
* @template Document
* @param {WritableSignal<Document>[]} signals - Array of writable signals to search.
* @param {unknown} value - The value to match.
* @param {(val: Document) => Document} updater - Function to produce the updated object.
* @param {string} field - The object field to match against.
* @returns {void}
*/
updateSignalByField<Document extends Record<string, unknown>>(signals: WritableSignal<Document>[], value: unknown, updater: (val: Document) => Document, field: string): void;
static ɵfac: i0.ɵɵFactoryDeclaration<CoreService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<CoreService>;
}
declare class StoreService {
private config;
private core;
private _prefix;
constructor(config: Config, core: CoreService);
/**
* Sets the prefix for storage keys.
*
* @param prefix - The prefix to set.
*/
setPrefix(prefix: string): void;
/**
* Sets a value in storage.
*
* @param key - The storage key.
* @param value - The value to store.
* @param callback - The callback to execute on success.
* @param errCallback - The callback to execute on error.
*/
set(key: string, value: string, callback?: () => void, errCallback?: () => void): void;
/**
* Sets a value in storage asynchronously.
*
* @param key - The storage key.
* @param value - The value to store.
* @returns A promise that resolves to a boolean indicating success.
*/
setAsync(key: string, value: string): Promise<boolean>;
/**
* Gets a value from storage.
*
* @param key - The storage key.
* @param callback - The callback to execute with the retrieved value.
* @param errCallback - The callback to execute on error.
*/
get(key: string, callback?: (value: string) => void, errCallback?: () => void): void;
/**
* Gets a value from storage asynchronously.
*
* @param key - The storage key.
* @returns A promise that resolves to the retrieved value.
*/
getAsync(key: string): Promise<string>;
/**
* Sets a JSON value in storage.
*
* @param key - The storage key.
* @param value - The value to store.
* @param callback - The callback to execute on success.
* @param errCallback - The callback to execute on error.
*/
setJson(key: string, value: any, callback?: () => void, errCallback?: () => void): void;
/**
* Sets a JSON value in storage asynchronously.
*
* @param key - The storage key.
* @param value - The value to store.
* @returns A promise that resolves to a boolean indicating success.
*/
setJsonAsync(key: string, value: any): Promise<boolean>;
/**
* Gets a JSON value from storage.
*
* @param key - The storage key.
* @param callback - The callback to execute with the retrieved value.
* @param errCallback - The callback to execute on error.
*/
getJson(key: string, callback?: (value: any) => void, errCallback?: () => void): void;
/**
* Gets a JSON value from storage asynchronously.
*
* @param key - The storage key.
* @returns A promise that resolves to the retrieved value.
*/
getJsonAsync<T = any>(key: string): Promise<T | null>;
/**
* Removes a value from storage.
*
* @param key - The storage key.
* @param callback - The callback to execute on success.
* @param errCallback - The callback to execute on error.
* @returns A promise that resolves to a boolean indicating success.
*/
remove(key: string, callback?: () => void, errCallback?: () => void): Promise<boolean>;
/**
* Clears all values from storage.
*
* @param callback - The callback to execute on success.
* @param errCallback - The callback to execute on error.
* @returns A promise that resolves to a boolean indicating success.
*/
clear(callback?: () => void, errCallback?: () => void): Promise<boolean>;
/**
* Applies the configured prefix to a storage key.
*
* @param key - The storage key.
* @returns The prefixed storage key.
*/
private applyPrefix;
/**
* Checks if a value exists in storage.
*
* This function checks whether a value is present for the given key in the storage.
* It uses the configured storage mechanism if available; otherwise, it defaults to using `localStorage`.
*
* @param key - The storage key to check.
* @returns A promise that resolves to `true` if the value exists, otherwise `false`.
*
* @example
* const store = new StoreService(config, core);
*
* // Set a value and check if it exists
* await store.setAsync('exampleKey', 'exampleValue');
* const exists = await store.has('exampleKey');
* console.log(exists); // Output: true
*
* @notes
* - This method internally uses `getAsync` to retrieve the value and checks if it is not null or empty.
* - An empty string value will still return `true` as the key exists in storage.
*/
has(key: string): Promise<boolean>;
static ɵfac: i0.ɵɵFactoryDeclaration<StoreService, [{ optional: true; }, null]>;
static ɵprov: i0.ɵɵInjectableDeclaration<StoreService>;
}
declare class HttpService {
private store;
private http;
private _config;
errors: ((err: HttpErrorResponse, retry?: () => void) => {})[];
url: string;
locked: boolean;
awaitLocked: any[];
private _http;
private _headers;
private _http_headers;
constructor(store: StoreService, http: HttpClient, _config: Config);
setUrl(url: string): void;
removeUrl(): void;
set(key: any, value: any): void;
header(key: any): any;
remove(key: any): void;
private _httpMethod;
/**
* Internal method to handle HTTP requests for various methods (POST, PUT, PATCH, DELETE, GET).
*
* Features:
* - **Request Locking**: Manages request locking to prevent simultaneous requests.
* - **Acceptance Check**: Validates the server response against a user-defined `acceptance` function.
* If the check fails, the response is rejected with an error.
* - **Replace Logic**: Allows modification of specific parts of the response object, determined by a user-defined `replace` function.
* Can handle both objects and arrays within the response.
* - **Field Filtering**: Supports extracting specific fields from response objects or arrays.
* - **Legacy Support**: Compatible with callback-based usage alongside Observables.
* - **ReplaySubject**: Ensures that the response can be shared across multiple subscribers.
*
* @param url - The endpoint to send the HTTP request to (relative to the base URL).
* @param doc - The request payload for methods like POST, PUT, and PATCH.
* @param callback - A legacy callback function to handle the response.
* @param opts - Additional options:
* - `err`: Error handling callback.
* - `acceptance`: Function to validate the server response. Should return `true` for valid responses.
* - `replace`: Function to modify specific parts of the response data.
* - `fields`: Array of fields to extract from the response object(s).
* - `data`: Path in the response where the data resides for `replace` and `fields` operations.
* - `skipLock`: If `true`, bypasses request locking.
* - `url`: Overrides the base URL for this request.
* @param method - The HTTP method (e.g., 'post', 'put', 'patch', 'delete', 'get').
* @returns An Observable that emits the processed HTTP response or an error.
*/
private _post;
/**
* Public method to perform a POST request.
* - Supports legacy callback usage.
* - Returns an Observable for reactive programming.
*/
post(url: string, doc: any, callback?: (resp: any) => void, opts?: any): Observable<any>;
/**
* Public method to perform a PUT request.
* - Supports legacy callback usage.
* - Returns an Observable for reactive programming.
*/
put(url: string, doc: any, callback?: (resp: any) => void, opts?: any): Observable<any>;
/**
* Public method to perform a PATCH request.
* - Supports legacy callback usage.
* - Returns an Observable for reactive programming.
*/
patch(url: string, doc: any, callback?: (resp: any) => void, opts?: any): Observable<any>;
/**
* Public method to perform a DELETE request.
* - Supports legacy callback usage.
* - Returns an Observable for reactive programming.
*/
delete(url: string, callback?: (resp: any) => void, opts?: any): Observable<any>;
/**
* Public method to perform a GET request.
* - Supports legacy callback usage.
* - Returns an Observable for reactive programming.
*/
get(url: string, callback?: (resp: any) => void, opts?: any): Observable<any>;
clearLocked(): void;
lock(): void;
unlock(): void;
/**
* Handles HTTP errors.
* - Calls provided error callback and retries the request if needed.
*/
private handleError;
/**
* Internal method to trigger error handling callbacks.
*/
private err_handle;
private prepare_handle;
private response_handle;
/**
* Retrieves a nested object or property from the response based on a dot-separated path.
*
* @param resp - The response object to retrieve data from.
* @param base - A dot-separated string indicating the path to the desired property within the response.
* - Example: `'data.items'` will navigate through `resp.data.items`.
* - If empty, the entire response is returned.
* @returns The object or property located at the specified path within the response.
*/
private _getObjectToReplace;
/**
* Sets or replaces a nested object or property in the response based on a dot-separated path.
*
* @param resp - The response object to modify.
* @param base - A dot-separated string indicating the path to the property to replace.
* - Example: `'data.items'` will navigate through `resp.data.items`.
* @param doc - The new data or object to set at the specified path.
* @returns `void`.
*/
private _setObjectToReplace;
/**
* Creates a new object containing only specified fields from the input item.
*
* @param item - The input object to extract fields from.
* @param fields - An array of field names to include in the new object.
* - Example: `['id', 'name']` will create a new object with only the `id` and `name` properties from `item`.
* @returns A new object containing only the specified fields.
*/
private _newDoc;
static ɵfac: i0.ɵɵFactoryDeclaration<HttpService, [null, null, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<HttpService>;
}
declare class DomService {
private componentFactoryResolver;
private appRef;
private injector;
private providedIn;
constructor(componentFactoryResolver: ComponentFactoryResolver, appRef: ApplicationRef, injector: Injector);
/**
* Appends a component to a specified element by ID.
*
* @param component - The component to append.
* @param options - The options to project into the component.
* @param id - The ID of the element to append the component to.
* @returns An object containing the native element and the component reference.
*/
appendById(component: any, options: any | undefined, id: string): {
nativeElement: HTMLElement;
componentRef: ComponentRef<any>;
};
/**
* Appends a component to a specified element or to the body.
*
* @param component - The component to append.
* @param options - The options to project into the component.
* @param element - The element to append the component to. Defaults to body.
* @returns An object containing the native element and the component reference.
*/
appendComponent(component: any, options?: any, element?: HTMLElement): {
nativeElement: HTMLElement;
componentRef: ComponentRef<any>;
} | void;
/**
* Gets a reference to a dynamically created component.
*
* @param component - The component to create.
* @param options - The options to project into the component.
* @returns The component reference.
*/
getComponentRef(component: any, options?: any): ComponentRef<any>;
/**
* Projects the inputs onto the component.
*
* @param component - The component reference.
* @param options - The options to project into the component.
* @returns The component reference with the projected inputs.
*/
private projectComponentInputs;
static ɵfac: i0.ɵɵFactoryDeclaration<DomService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DomService>;
}
declare class AlertService {
private dom;
private config;
private alert;
private _container;
constructor(dom: DomService, config: Config);
private uniques;
private shortcuts;
private positionNumber;
show(opts: any | Alert): any;
open(opts: Alert): void;
info(opts: Alert): void;
success(opts: Alert): void;
warning(opts: Alert): void;
error(opts: Alert): void;
question(opts: Alert): void;
destroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<AlertService, [null, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<AlertService>;
}
interface CrudConfig<Document> {
signalFields?: Record<string, (doc: Document) => unknown>;
name: string;
_id?: string;
replace?: (doc: Document) => void;
unauthorized?: boolean;
appId?: string;
}
interface GetConfig {
page?: number;
perPage?: number;
query?: string;
}
/**
* Abstract class representing a CRUD (Create, Read, Update, Delete) service.
*
* This class provides methods for managing documents, interacting with an API,
* and storing/retrieving data from local storage. It is designed to be extended
* for specific document types.
*
* @template Document - The type of the document the service handles.
*/
declare abstract class CrudService<Document extends CrudDocument> extends BaseService {
private _config;
/**
* URL for the API.
*/
private _url;
/**
* Array of documents managed by this service.
*/
private _docs;
/**
* Number of documents per page.
*/
private _perPage;
/**
* Callbacks for filtering documents.
*/
private _filteredDocumentsCallbacks;
/**
* Constructs a CRUD service instance.
*
* @param _config - Configuration options for the CRUD service.
* @param __http - Service to handle HTTP requests.
* @param __store - Service to manage local storage of documents.
* @param __alert - Service to display alerts.
* @param __core - Core service for utility functions.
*/
protected __http: HttpService;
protected __store: StoreService;
protected __alert: AlertService;
protected __core: CoreService;
loaded: Promise<unknown>;
constructor(_config: CrudConfig<Document>);
restoreDocs(): void;
/**
* Saves the current set of documents to local storage.
*/
setDocs(): void;
/**
* Retrieves the current list of documents.
*
* @returns The list of documents.
*/
getDocs(): Document[];
/**
* Clears the current list of documents.
*
* Empties the internal documents array and saves the updated state to local storage.
*/
clearDocs(): void;
/**
* Adds multiple documents to the service and saves them to local storage.
*
* @param docs - An array of documents to add.
*/
addDocs(docs: Document[]): void;
/**
* Adds a single document to the service. If it already exists, it will be updated.
*
* @param doc - The document to add.
*/
addDoc(doc: Document): void;
/**
* Creates a new document with a temporary ID and status flags.
*
* @param doc - Optional base document to use for the new document.
* @returns A new document instance with default properties.
*/
new(doc?: Document): Document;
/**
* Retrieves a document by its unique ID or creates a new one if it doesn't exist.
*
* @param _id - The document ID to search for.
* @returns The found document or a new document if not found.
*/
doc(_id: string): Document;
/**
* Sets the number of documents to display per page.
*
* @param _perPage - Number of documents per page.
*/
setPerPage(_perPage: number): void;
/**
* Fetches a list of documents from the API with optional pagination.
*
* @param config - Optional pagination configuration.
* @param options - Optional callback and error handling configuration.
* @returns An observable that resolves with the list of documents.
*/
get(config?: GetConfig, options?: CrudOptions<Document>): Observable<Document[]>;
/**
* Sends a request to the API to create a new document.
*
* @param doc - The document to create.
* @param options - Optional callback and error handling configuration.
* @returns An observable that resolves with the created document, or emits an error if already created.
*/
create(doc?: Document, options?: CrudOptions<Document>): Observable<Document>;
/**
* Fetches a document from the API based on a query.
*
* @param query - The query object used to filter documents.
* @param options - Optional callback and error handling configuration.
* @returns An observable that resolves with the fetched document.
*/
fetch(query?: object, options?: CrudOptions<Document>): Observable<Document>;
/**
* Updates a document after a specified delay and returns an observable.
*
* @param doc - The document to update.
* @param options - Optional callback and error handling configuration.
* @returns An observable that emits the updated document.
*/
updateAfterWhile(doc: Document, options?: CrudOptions<Document>): Observable<Document>;
/**
* Updates a document in the API.
*
* @param doc - The document to update.
* @param options - Optional callback and error handling configuration.
* @returns An observable that resolves with the updated document.
*/
update(doc: Document, options?: CrudOptions<Document>): Observable<Document>;
/**
* Unique update a document field in the API.
*
* @param doc - The document to update.
* @param options - Optional callback and error handling configuration.
* @returns An observable that resolves with the updated document.
*/
unique(doc: Document, options?: CrudOptions<Document>): Observable<Document>;
/**
* Deletes a document from the API.
*
* @param doc - The document to delete.
* @param options - Optional callback and error handling configuration.
* @returns An observable that resolves with the deleted document.
*/
delete(doc: Document, options?: CrudOptions<Document>): Observable<Document>;
/**
* Filters documents based on specific conditions and stores the result in a provided object.
*
* @param storeObject - Object to store filtered documents.
* @param field - The field to filter by or a function to extract the field.
* @param valid - Optional function to check the validity of a document.
* @param sort - Function to sort the filtered documents.
* @returns A callback function that triggers the filtering process.
*/
filteredDocuments(storeObject: Record<string, Document[]>, field?: string | ((doc: Document) => string), valid?: (doc: Document) => boolean, sort?: (a: Document, b: Document) => number): () => void;
/**
* Generates a unique ID for a document.
*
* @param doc - The document for which to generate the ID.
* @returns The unique ID as a string.
*/
private _id;
/**
* Executes all registered filter document callbacks.
*/
private _filterDocuments;
private _fetchingId;
}
declare class MongoService {
private store;
private http;
private core;
private data;
private socket;
config(part: any, opts: any): {
arr: any;
obj: any;
} | undefined;
create(part: any, doc?: any, cb?: any, opts?: any): void;
fetch(part: any, opts?: any, cb?: any): any;
get(part: any, opts?: any, cb?: any): any;
set(part: any, opts?: any, resp?: any): {
arr: any;
obj: any;
};
private prepare_update;
update(part: any, doc: any, opts?: any, cb?: any): void;
unique(part: any, doc: any, opts?: any, cb?: any): void;
delete(part: any, doc: any, opts?: any, cb?: any): void;
_id(cb: any): void;
to_id(docs: any): any;
afterWhile(doc: any, cb: any, time?: number): void;
populate(doc: any, field: any, part: any): any;
on(parts: any, cb: any): any;
track(index: any, doc: any): any;
sortAscId(): (a: any, b: any) => 1 | -1;
sortDescId(): (a: any, b: any) => 1 | -1;
sortAscString(opts: any): (a: any, b: any) => any;
sortDescString(opts: any): (a: any, b: any) => any;
sortAscDate(opts: any): (a: any, b: any) => any;
sortDescDate(opts: any): (a: any, b: any) => any;
sortAscNumber(opts: any): (a: any, b: any) => any;
sortDescNumber(opts: any): (a: any, b: any) => any;
sortAscBoolean(opts: any): (a: any, b: any) => any;
sortDescBoolean(opts: any): (a: any, b: any) => any;
beArr(val: any, cb: any): void;
beObj(val: any, cb: any): void;
beDate(val: any, cb: any): void;
beString(val: any, cb: any): void;
beDoc: (val: any, cb: any) => void;
forceArr(val: any, cb: any): void;
forceObj(val: any, cb: any): void;
forceString(val: any, cb: any): void;
forceDoc: (val: any, cb: any) => void;
getCreated(val: any, cb: any, doc: any): void;
private replace;
renew(part: any, doc: any): any;
push(part: any, doc: any): any;
remove(part: any, doc: any): void;
constructor(store: StoreService, http: HttpService, core: CoreService