@crudmates/masq
Version:
Flexible field masking and relation selection for REST APIs and data filtering.
44 lines • 1.85 kB
TypeScript
/**
* masq: Flexible field masking and relation selection for REST, GraphQL, and data APIs.
* @packageDocumentation
*/
/**
* Parse a field mask string into an object structure, supporting aliasing with <alias>.
* Examples:
* id,name => { id: true, name: true }
* model<models>(make<makes>) => { model: { __alias: 'models', make: { __alias: 'makes' } } }
* * => { '*': true }
* id,name,branch(*) => { id: true, name: true, branch: { '*': true } }
* *,-password => { '*': true, password: false }
* id,name,-secret,branch(id,name,-internal) => { id: true, name: true, secret: false, branch: { id: true, name: true, internal: false } }
*/
export declare function parseFieldsSpec(fieldsSpec: string): Record<string, any>;
/**
* Apply a field mask to an object or array, supporting aliasing with __alias.
* If mask is a string, it is parsed first.
* @param obj - The object or array to filter
* @param mask - The field mask (object structure or string)
* @returns Filtered object/array with possible key renaming
*/
export declare function applyFieldMask(obj: any, mask: any): any;
/**
* Apply a field mask to an object or array, parsing the mask if needed.
*/
export declare function applyMask<T = any>(data: T, maskValue?: string | object): T;
/**
* Relation join descriptor for dynamic joins.
*/
export interface RelationJoin {
path: string;
alias: string;
}
/**
* Parse a relation string like model(make),bodyType,category into join descriptors.
* Returns an array of { path, alias } objects for use in dynamic joins.
*/
export declare function parseRelationsSpec(relationsStr: string | undefined, baseAlias: string): RelationJoin[];
/**
* Validate a mask object against allowed fields structure.
*/
export declare function isValidMask(maskObj: any, allowed: any): boolean;
//# sourceMappingURL=index.d.ts.map