export type FrontendModelSearch = { /** * - Attribute name to search. */ column: string; /** * - Search operator. */ operator: "eq" | "like" | "notEq" | "gt" | "gteq" | "lt" | "lteq"; /** * - Relationship path from root model. */ path: string[]; /** * - Search value. */ value: ReturnType; }; export type FrontendModelTransportValue = null | boolean | number | string | object; export type FrontendModelAttributeValue = import("./base.js").FrontendModelAttributeValue; export type FrontendModelWithCountPayloadEntry = { attributeName: string; relationshipName: string; where?: Record; }; export type FrontendModelAbilitiesPayloadEntry = { modelName: string; actions: string[]; }; export type FrontendModelProjectionOptions = { /** * - Model-aware attribute select map or root-model shorthand. */ select?: Record | string | string[]; /** * - Extra attributes to load in addition to the defaults, keyed by model name or root-model shorthand. */ selectsExtra?: Record | string | string[]; /** * - Relationship preload tree. */ preload?: import("../database/query/index.js").NestedPreloadRecord | string | Array; /** * - Association count spec. */ withCount?: string | string[] | Record; }>; /** * - Ability actions to compute per record. */ abilities?: string[] | Record; /** * - Backend query data names/spec. */ queryData?: string | Array> | Record; }; export type FrontendModelEventRoutingOptions = { /** * - Query whose filters match events and whose projections shape event records. */ query?: FrontendModelQuery; /** * - Registration-local remote routing context. Its captured value partitions lifecycle server subscriptions and replaces the transport-wide context for this registration. */ requestContext?: import("../remote-request-context.js").RemoteRequestContext; }; export type FrontendModelEventOptionsObject = FrontendModelProjectionOptions & FrontendModelEventRoutingOptions; export type FrontendModelEventOptions = FrontendModelEventOptionsObject | FrontendModelQuery; export type FrontendModelProjectionPayload = { /** * - Normalized select map. */ select?: Record; /** * - Normalized extra select map. */ selectsExtra?: Record; /** * - Normalized preload tree. */ preload?: import("../database/query/index.js").NestedPreloadRecord; /** * - Normalized count specs. */ withCount?: FrontendModelWithCountPayloadEntry[]; /** * - Normalized ability specs. */ abilities?: FrontendModelAbilitiesPayloadEntry[]; /** * - Normalized queryData spec. */ queryData?: FrontendModelTransportValue; }; export type FrontendModelEventFilterPayload = { /** * - Relationship joins needed for matching. */ joins?: Record; /** * - Search predicates needed for matching. */ searches?: FrontendModelSearch[]; /** * - Structured where predicates needed for matching. */ where?: Record; }; export type FrontendModelEventFilterPayloadEntry = FrontendModelEventFilterPayload & { key: string; }; export type FrontendModelEventQueryPayload = { /** * - Stable event filter key, or null when no filter is present. */ eventFilterKey: string | null; /** * - Normalized event filter payload, or null when unfiltered. */ eventFilterPayload: FrontendModelEventFilterPayload | null; /** * - Normalized event serialization projection payload. */ projectionPayload: FrontendModelProjectionPayload; }; export type FrontendModelEventOptionsPayload = FrontendModelEventQueryPayload & { requestContext: import("../remote-request-context.js").RemoteRequestContext | undefined; }; export type FrontendModelSort = { /** * - Attribute name to sort by. */ column: string; /** * - Sort direction. */ direction: "asc" | "desc"; /** * - Relationship path from root model. */ path: string[]; }; export type FrontendModelGroup = { /** * - Attribute name to group by. */ column: string; /** * - Relationship path from root model. */ path: string[]; }; export type FrontendModelPluck = { /** * - Attribute name to pluck. */ column: string; /** * - Relationship path from root model. */ path: string[]; }; /** * FrontendModelSearch type. * @typedef {object} FrontendModelSearch * @property {string} column - Attribute name to search. * @property {"eq" | "like" | "notEq" | "gt" | "gteq" | "lt" | "lteq"} operator - Search operator. * @property {string[]} path - Relationship path from root model. * @property {ReturnType} value - Search value. */ /** * FrontendModelTransportValue type. * @typedef {null | boolean | number | string | object} FrontendModelTransportValue */ /** * FrontendModelAttributeValue type. * @typedef {import("./base.js").FrontendModelAttributeValue} FrontendModelAttributeValue */ /** * Defines this typedef. * @typedef {{attributeName: string, relationshipName: string, where?: Record}} FrontendModelWithCountPayloadEntry */ /** * Defines this typedef. * @typedef {{modelName: string, actions: string[]}} FrontendModelAbilitiesPayloadEntry */ /** * FrontendModelProjectionOptions type. * @typedef {object} FrontendModelProjectionOptions * @property {Record | string | string[]} [select] - Model-aware attribute select map or root-model shorthand. * @property {Record | string | string[]} [selectsExtra] - Extra attributes to load in addition to the defaults, keyed by model name or root-model shorthand. * @property {import("../database/query/index.js").NestedPreloadRecord | string | Array} [preload] - Relationship preload tree. * @property {string | string[] | Record}>} [withCount] - Association count spec. * @property {string[] | Record} [abilities] - Ability actions to compute per record. * @property {string | Array> | Record} [queryData] - Backend query data names/spec. */ /** * FrontendModelEventRoutingOptions type. * @typedef {object} FrontendModelEventRoutingOptions * @property {FrontendModelQuery} [query] - Query whose filters match events and whose projections shape event records. * @property {import("../remote-request-context.js").RemoteRequestContext} [requestContext] - Registration-local remote routing context. Its captured value partitions lifecycle server subscriptions and replaces the transport-wide context for this registration. */ /** * Defines this typedef. * @typedef {FrontendModelProjectionOptions & FrontendModelEventRoutingOptions} FrontendModelEventOptionsObject */ /** * FrontendModelEventOptions type. * @typedef {FrontendModelEventOptionsObject | FrontendModelQuery} FrontendModelEventOptions */ /** * FrontendModelProjectionPayload type. * @typedef {object} FrontendModelProjectionPayload * @property {Record} [select] - Normalized select map. * @property {Record} [selectsExtra] - Normalized extra select map. * @property {import("../database/query/index.js").NestedPreloadRecord} [preload] - Normalized preload tree. * @property {FrontendModelWithCountPayloadEntry[]} [withCount] - Normalized count specs. * @property {FrontendModelAbilitiesPayloadEntry[]} [abilities] - Normalized ability specs. * @property {FrontendModelTransportValue} [queryData] - Normalized queryData spec. */ /** * FrontendModelEventFilterPayload type. * @typedef {object} FrontendModelEventFilterPayload * @property {Record} [joins] - Relationship joins needed for matching. * @property {FrontendModelSearch[]} [searches] - Search predicates needed for matching. * @property {Record} [where] - Structured where predicates needed for matching. */ /** * Defines this typedef. * @typedef {FrontendModelEventFilterPayload & {key: string}} FrontendModelEventFilterPayloadEntry */ /** * FrontendModelEventQueryPayload type. * @typedef {object} FrontendModelEventQueryPayload * @property {string | null} eventFilterKey - Stable event filter key, or null when no filter is present. * @property {FrontendModelEventFilterPayload | null} eventFilterPayload - Normalized event filter payload, or null when unfiltered. * @property {FrontendModelProjectionPayload} projectionPayload - Normalized event serialization projection payload. */ /** * FrontendModelEventOptionsPayload type. * @typedef {FrontendModelEventQueryPayload & {requestContext: import("../remote-request-context.js").RemoteRequestContext | undefined}} FrontendModelEventOptionsPayload */ /** * FrontendModelSort type. * @typedef {object} FrontendModelSort * @property {string} column - Attribute name to sort by. * @property {"asc" | "desc"} direction - Sort direction. * @property {string[]} path - Relationship path from root model. */ /** * FrontendModelGroup type. * @typedef {object} FrontendModelGroup * @property {string} column - Attribute name to group by. * @property {string[]} path - Relationship path from root model. */ /** * FrontendModelPluck type. * @typedef {object} FrontendModelPluck * @property {string} column - Attribute name to pluck. * @property {string[]} path - Relationship path from root model. */ /** Error raised when a frontend-model query descriptor is malformed. */ export declare class FrontendModelQueryError extends Error { /** * Creates a frontend-model query error. * @param {string} message - Error message. */ constructor(message: string); } /** * Asserts the raw payload accepted by a shared frontend-model index command. * @param {ReturnType} payload - Raw index payload. * @returns {Record>} - Valid index payload. */ export declare function assertFrontendModelIndexPayload(payload: ReturnType): Record>; /** * Runs the normalizePreload helper. * @param {import("../database/query/index.js").NestedPreloadRecord | string | Array | boolean | undefined | null} preload - Preload shorthand. * @returns {import("../database/query/index.js").NestedPreloadRecord} - Normalized preload. */ export declare function normalizePreload(preload: import("../database/query/index.js").NestedPreloadRecord | string | Array | boolean | undefined | null): import("../database/query/index.js").NestedPreloadRecord; /** * Runs the normalizeSearchOperator helper. * @param {string} operator - Raw search operator. * @returns {"eq" | "like" | "notEq" | "gt" | "gteq" | "lt" | "lteq"} - Normalized operator. */ export declare function normalizeSearchOperator(operator: string): "eq" | "like" | "notEq" | "gt" | "gteq" | "lt" | "lteq"; /** * Runs the normalizeJoins helper. * @param {ReturnType} joins - Join payload. * @returns {Record>} - Normalized relationship descriptor joins. */ export declare function normalizeJoins(joins: ReturnType): Record>; /** * Normalize any supported sort payload into flat sort descriptors. * @param {ReturnType} sort - Sort payload. * @returns {FrontendModelSort[]} - Normalized sort definitions. */ export declare function normalizeSort(sort: ReturnType): FrontendModelSort[]; /** * Normalize any supported group payload into flat group descriptors. * @param {ReturnType} group - Group payload. * @returns {FrontendModelGroup[]} - Normalized group definitions. */ export declare function normalizeGroup(group: ReturnType): FrontendModelGroup[]; /** * Normalize any supported pluck payload into flat pluck descriptors. * @param {ReturnType} pluck - Pluck payload. * @returns {FrontendModelPluck[]} - Normalized pluck definitions. */ export declare function normalizePluck(pluck: ReturnType): FrontendModelPluck[]; /** * Query wrapper for frontend model commands. * @template {import("./base.js").FrontendModelClass} T */ export default class FrontendModelQuery { modelClass: T; _preload: import("../database/query/index.js").NestedPreloadRecord; _joins: {}; _where: {}; /** * Narrows the runtime value to the documented type. * @type {Record} */ _select: Record; /** * Narrows the runtime value to the documented type. * @type {Record} */ _selectsExtra: Record; _distinct: boolean; _limit: number | null; _offset: number | null; _page: number | null; _perPage: number | null; /** * Narrows the runtime value to the documented type. * @type {Array<{attributeName: string, relationshipName: string, where?: Record>}>} */ _withCount: Array<{ attributeName: string; relationshipName: string; where?: Record>; }>; /** * Narrows the runtime value to the documented type. * @type {Array>>} */ _queryData: Array>>; /** * Per-record ability spec. Normalized to a list of * `{modelName, actions}` entries — one entry per model that should * have ability results attached. The root query's model class * name is implicit via `"__root__"` when the caller used the flat * array form. * @type {Array<{modelName: string, actions: string[]}>} */ _abilities: Array<{ modelName: string; actions: string[]; }>; /** * Ransack. * @type {Record>[]} */ _ransack: Record>[]; /** * Searches. * @type {FrontendModelSearch[]} */ _searches: FrontendModelSearch[]; /** * Sort. * @type {FrontendModelSort[]} */ _sort: FrontendModelSort[]; /** * Group. * @type {FrontendModelGroup[]} */ _group: FrontendModelGroup[]; /** * Runs constructor. * @param {object} args - Constructor args. * @param {T} args.modelClass - Frontend model class. * @param {import("../database/query/index.js").NestedPreloadRecord} [args.preload] - Preload map. */ constructor({ modelClass, preload }: { modelClass: T; preload?: import("../database/query/index.js").NestedPreloadRecord; }); /** * Tell the backend to evaluate one or more ability actions against * each returned record (and its preloaded relations, when keyed by * model name) and ship the results back so the frontend can read * them via `record.can(action)`. * * Flat form — applies to the query's own model class: * ``` * const timelogs = await Timelog.where({taskId}) * .abilities(["update", "destroy"]) * .toArray() * timelogs[0].can("update") // → boolean * ``` * * Keyed form — targets records by model name, useful for preloaded * children: * ``` * const project = await Project * .preload("timelogs") * .abilities({Timelog: ["update", "destroy"]}) * .first() * project.timelogs().loaded()[0].can("update") // → boolean * ``` * * Keys in the keyed form are the backend model names (as returned by * `ModelClass.getModelName()` / the `modelName` field of the * frontend-model resource config). Values are the ability-action * strings — typically `"update"` / `"destroy"` / `"create"` / * `"read"`, but any custom action registered on the resource's * authorization ability is accepted. * @param {string[] | Record} spec - Ability actions to request for root or named models. * @returns {this} - This query for chaining. */ abilities(spec: string[] | Record): this; /** * Runs merge ability entry. * @param {{modelName: string, actions: string[]}} entry - Normalized model ability request to append. * @returns {void} */ _mergeAbilityEntry(entry: { modelName: string; actions: string[]; }): void; /** * Tell the backend index query to attach one or more association * counts to each returned record. Parses the same shapes as the * backend `ModelClassQuery#withCount`, then ships the normalized * entries as part of the `index` command payload. * @param {string | string[] | Record>}>} spec - Relationships whose counts should be serialized. * @returns {this} - This query for chaining. */ withCount(spec: string | string[] | Record>; }>): this; /** * Request one or more backend queryData entries for each returned * record. The spec is a name or nested-record shape matching the * `Model.queryData(name, fn)` registrations on the backend — the * frontend ships only these names; the SQL fragments stay server- * side. All resulting aliases are attached to the root record and * read back with `record.queryData(aliasName)`. * @param {string | Array>> | Record>} spec - Backend query-data names and arguments to serialize. * @returns {this} - This query for chaining. */ queryData(spec: string | Array>> | Record>): this; /** * Runs where. * @param {Record>} conditions - Root-model where conditions. * @returns {this} - Query with merged where conditions. */ where(conditions: Record>): this; /** * Runs scope. * @param {import("../utils/model-scope.js").ModelScopeDescriptor} scopeDescriptor - Scope descriptor. * @returns {this} - Scoped query. */ scope(scopeDescriptor: import("../utils/model-scope.js").ModelScopeDescriptor): this; /** * Runs ransack. * @param {Record>} params - Ransack-style params hash. Supports `s` key for sorting (e.g., `{s: "name asc"}`). * @returns {this} - Query with Ransack filters and sort applied. */ ransack(params: Record>): this; /** * Runs select with required root attributes. * @param {string[]} [requiredAttributes] - Extra required attributes for the root model. * @returns {Record} - Select map with required root attributes merged when root select exists. */ selectWithRequiredRootAttributes(requiredAttributes?: string[]): Record; /** * Runs preload. * @param {import("../database/query/index.js").NestedPreloadRecord | string | Array} preload - Preload to merge. * @returns {this} - Query with merged preloads. */ preload(preload: import("../database/query/index.js").NestedPreloadRecord | string | Array): this; /** * Runs select. * @param {Record | string | string[]} select - Model-aware attribute select map or root-model shorthand. * @returns {this} - Query with merged selected attributes. */ select(select: Record | string | string[]): this; /** * Like `select(...)`, but keeps the default serialized attributes and loads * the given extras in addition (for example attributes declared * `selectedByDefault: false`). Keyed by model name, with root-model shorthand. * @param {Record | string | string[]} select - Extra attributes to load, keyed by model name or root-model shorthand. * @returns {this} - Query with merged extra selected attributes. */ selectsExtra(select: Record | string | string[]): this; /** * Runs joins. * @param {Record> | Array>>} joins - Relationship descriptor joins. * @returns {this} - Query with merged joins. */ joins(joins: Record> | Array>>): this; /** * Returns the search result. * @param {string[]} path - Relationship path. * @param {string} column - Column or attribute name. * @param {"eq" | "like" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | ">" | ">=" | "<" | "<="} operator - Search operator. * @param {ReturnType} value - Search value. * @returns {this} - Query with appended search. */ search(path: string[], column: string, operator: "eq" | "like" | "notEq" | "gt" | "gteq" | "lt" | "lteq" | ">" | ">=" | "<" | "<=", value: ReturnType): this; /** * Runs sort. * @param {string | string[] | string[][] | [string, string] | Array<[string, string]> | Record> | Array>>} sort - Sort definition(s). * @returns {this} - Query with appended sort definitions. */ sort(sort: string | string[] | string[][] | [string, string] | Array<[string, string]> | Record> | Array>>): this; /** * Runs order. * @param {string | string[] | string[][] | [string, string] | Array<[string, string]> | Record> | Array>>} order - Order definition(s). * @returns {this} - Query with appended sort definitions. */ order(order: string | string[] | string[][] | [string, string] | Array<[string, string]> | Record> | Array>>): this; /** * Runs group. * @param {string | string[] | Record> | Array>>} group - Group definition(s). * @returns {this} - Query with appended group definitions. */ group(group: string | string[] | Record> | Array>>): this; /** * Runs distinct. * @param {boolean} [value] - Whether to request distinct rows. * @returns {this} - Query with distinct flag. */ distinct(value?: boolean): this; /** * Returns the limit result. * @param {number} value - Maximum number of records. * @returns {this} - Query with limit. */ limit(value: number): this; /** * Runs offset. * @param {number} value - Number of records to skip. * @returns {this} - Query with offset. */ offset(value: number): this; /** * Runs page. * @param {number} pageNumber - 1-based page number. * @returns {this} - Query with page applied. */ page(pageNumber: number): this; /** * Runs per page. * @param {number} perPage - Page size. * @returns {this} - Query with per-page applied. */ perPage(perPage: number): this; /** * Runs clone. * @returns {FrontendModelQuery} - Cloned query instance. */ clone(): FrontendModelQuery; /** * Runs get model class. * @returns {T} - Root model class. */ getModelClass(): T; /** * Runs preload payload. * @returns {Record>} - Payload preload hash when present. */ preloadPayload(): Record>; /** * Runs with count payload. * @returns {Record>} - Payload withCount array when present. */ withCountPayload(): Record>; /** * Runs abilities payload. * @returns {Record>} - Payload abilities array when present. */ abilitiesPayload(): Record>; /** * Runs query data payload. * @returns {Record>} - Payload queryData spec when present. */ queryDataPayload(): Record>; /** * Runs select payload. * @param {string[]} [requiredAttributes] - Extra required attributes for root model selection. * @returns {Record>} - Payload select hash when present. */ selectPayload(requiredAttributes?: string[]): Record>; /** * Runs selects extra payload. * @returns {Record>} - Payload selectsExtra hash when present. */ selectsExtraPayload(): Record>; /** * Runs search payload. * @returns {Record>} - Payload searches array when present. */ searchPayload(): Record>; /** * Runs ransack payload. * @returns {Record>} - Payload ransack hash when present. */ ransackPayload(): Record>; /** * Runs joins payload. * @returns {Record>} - Payload joins hash when present. */ joinsPayload(): Record>; /** * Runs sort payload. * @returns {Record>} - Payload sort array when present. */ sortPayload(): Record>; /** * Runs group payload. * @returns {Record>} - Payload group array when present. */ groupPayload(): Record>; /** * Runs distinct payload. * @returns {Record>} - Payload distinct flag when enabled. */ distinctPayload(): Record>; /** * Runs where payload. * @returns {Record>} - Payload where hash when present. */ wherePayload(): Record>; /** * Runs pagination payload. * @returns {Record>} - Payload pagination params when present. */ paginationPayload(): Record>; /** * Runs assert event query supported. * @returns {void} * @throws {Error} When the query contains list-only options that cannot filter a single lifecycle event. */ assertEventQuerySupported(): void; /** * Runs event projection payload. * @returns {FrontendModelProjectionPayload} - Projection payload used when serializing lifecycle events. */ eventProjectionPayload(): FrontendModelProjectionPayload; /** * Runs event filter payload. * @returns {FrontendModelEventFilterPayload | null} - Query pieces used to match lifecycle events. */ eventFilterPayload(): FrontendModelEventFilterPayload | null; /** * Returns the eventOptionsPayload result. * @returns {FrontendModelEventQueryPayload} - Combined event filter and projection payload. */ eventOptionsPayload(): FrontendModelEventQueryPayload; /** * Runs load. * @returns {Promise[]>} - Loaded model instances. */ load(): Promise[]>; /** * Runs to array. * @returns {Promise[]>} - Loaded model instances. */ toArray(): Promise[]>; /** * Runs count. * @returns {Promise} - Number of loaded model instances. */ count(): Promise; /** * Runs first. * @returns {Promise | null>} - First model matching query. */ first(): Promise | null>; /** * Runs last. * @returns {Promise | null>} - Last model matching query. */ last(): Promise | null>; /** * Runs pluck. * @param {...(string | string[] | Record> | Array>>)} columns - Pluck definition(s). * @returns {Promise>>} - Plucked values. */ pluck(...columns: (string | string[] | Record> | Array>>)[]): Promise>>; /** * Runs find. * @param {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} id - Record id. * @returns {Promise>} - Found model. */ find(id: import("../utils/model-primary-key.js").ModelPrimaryKeyValue): Promise>; /** * Runs find by. * @param {Record>} conditions - Conditions. * @returns {Promise | null>} - Found model or null. */ findBy(conditions: Record>): Promise | null>; /** * Runs find by or fail. * @param {Record>} conditions - Conditions. * @returns {Promise>} - Found model. */ findByOrFail(conditions: Record>): Promise>; /** * Runs find or initialize by. * @param {Record>} conditions - Conditions. * @returns {Promise>} - Existing or initialized model. */ findOrInitializeBy(conditions: Record>): Promise>; /** * Runs find or create by. * @param {Record>} conditions - Conditions. * @param {(model: InstanceType) => Promise | void} [callback] - Optional callback before save. * @returns {Promise>} - Existing or newly created model. */ findOrCreateBy(conditions: Record>, callback?: (model: InstanceType) => Promise | void): Promise>; /** * Runs validated structured conditions. * @param {Record>} conditions - Candidate structured conditions. * @returns {Record>} - Validated conditions. */ validatedStructuredConditions(conditions: Record>): Record>; } /** * Runs the frontendModelEventOptionsPayload helper. * @param {import("./base.js").FrontendModelClass} modelClass - Frontend model class. * @param {FrontendModelEventOptions} [options] - Event query or projection options. * @returns {FrontendModelEventOptionsPayload} - Normalized event subscription payload. */ export declare function frontendModelEventOptionsPayload(modelClass: import("./base.js").FrontendModelClass, options?: FrontendModelEventOptions): FrontendModelEventOptionsPayload; //# sourceMappingURL=query.d.ts.map