import type { CustomObjectDataRow, RecordQueryParams, RecordQueryResponse } from "../../../resources/custom-objects/records.js"; import { type ValidationIssue } from "./validation.js"; import type { AnyCustomObjectDefinition, CreateInput, RecordShape, UpdateInput } from "./types.js"; /** Successful write receipt when read access does not permit returning the record. */ export interface CustomObjectRecordWriteReceipt { readonly id: string; } /** A readable wire-level record or an ID-only write receipt. */ export type CustomObjectRecordWriteResult = CustomObjectDataRow | CustomObjectRecordWriteReceipt; /** A readable logical-key record or an ID-only write receipt. Check for `name` before reading record fields. */ export type TypedRecordWriteResult = RecordShape | CustomObjectRecordWriteReceipt; /** * Minimal records-resource surface consumed by {@link CustomObjectManager}. * * This is intentionally narrower than the full SDK client. Callers can pass the * real `client.customObjects.records` resource or a lightweight test double * exposing the same methods. */ export interface CustomObjectRecordsClient { create(customObjectApiName: string, body: Record): Promise<{ data?: CustomObjectRecordWriteResult; }>; retrieve(customObjectApiName: string, recordId: string): Promise; retrieveByExternalID(customObjectApiName: string, externalID: string): Promise; update(customObjectApiName: string, recordId: string, body: Record): Promise<{ data?: CustomObjectRecordWriteResult; }>; delete(customObjectApiName: string, recordId: string): Promise; query(customObjectApiName: string, params: RecordQueryParams): Promise; bulkCreate(customObjectApiName: string, body: { all_or_nothing?: boolean; rows_to_write: Array<{ [key: string]: unknown; }>; }): Promise<{ data?: CustomObjectRecordWriteResult[]; }>; bulkUpdate(customObjectApiName: string, body: { all_or_nothing?: boolean; rows_to_update: Array<{ id: string; [key: string]: unknown; }>; }): Promise<{ data?: CustomObjectRecordWriteResult[]; }>; bulkDelete(customObjectApiName: string, body: { all_or_nothing?: boolean; rows_to_delete: string[]; }): Promise; } /** Minimal SDK-shaped wrapper accepted by {@link CustomObjectManager.fromSDK}. */ interface CustomObjectManagerSDKLike { readonly customObjects: { readonly records: CustomObjectRecordsClient; }; } /** Response shape returned by low-level record queries. */ export interface CustomObjectRecordQueryResponse { /** Opaque pagination cursor returned by the backend, if any. */ readonly cursor: string | null; /** Raw backend rows returned for the query. */ readonly results: readonly CustomObjectDataRow[]; } /** Adapter request for batch creates. */ export interface CustomObjectRecordBulkCreateRequest { /** Whether the backend should reject the entire batch if any row fails. */ readonly allOrNothing?: boolean; /** Wire-level rows to create. */ readonly rowsToWrite: readonly Record[]; } /** Adapter request for batch updates. */ export interface CustomObjectRecordBulkUpdateRequest { /** Whether the backend should reject the entire batch if any row fails. */ readonly allOrNothing?: boolean; /** Wire-level rows to update, including each record id. */ readonly rowsToUpdate: readonly { id: string; [key: string]: unknown; }[]; } /** Adapter request for batch deletes. */ export interface CustomObjectRecordBulkDeleteRequest { /** Whether the backend should reject the entire batch if any row fails. */ readonly allOrNothing?: boolean; /** Record ids to delete. */ readonly rowsToDelete: readonly string[]; } /** * Small transport boundary used by the typed manager. * * Production code can use {@link createCustomObjectRecordAdapter}. Unit tests * can provide an in-memory or hand-rolled adapter without depending on a real * backend client. */ export interface CustomObjectRecordAdapter { /** Creates one record, returning readable fields or an ID-only receipt. */ create(customObjectApiName: string, body: Record): Promise; /** Retrieves one wire-level record by id. */ retrieve(customObjectApiName: string, recordId: string): Promise; /** Retrieves one wire-level record by external id. */ retrieveByExternalID(customObjectApiName: string, externalID: string): Promise; /** Updates one record, returning readable fields or an ID-only receipt. */ update(customObjectApiName: string, recordId: string, body: Record): Promise; /** Deletes one wire-level record. */ delete(customObjectApiName: string, recordId: string): Promise; /** Runs a backend query and returns raw rows. */ query(customObjectApiName: string, params: RecordQueryParams): Promise; /** Creates many records, returning readable fields or ID-only receipts in response order. */ bulkCreate(customObjectApiName: string, request: CustomObjectRecordBulkCreateRequest): Promise; /** Updates many records, returning readable fields or ID-only receipts in response order. */ bulkUpdate(customObjectApiName: string, request: CustomObjectRecordBulkUpdateRequest): Promise; /** Deletes many wire-level rows. */ bulkDelete(customObjectApiName: string, request: CustomObjectRecordBulkDeleteRequest): Promise; } /** Constructor options for {@link CustomObjectManager}. */ export interface CustomObjectManagerOptions { /** Records resource to use for transport. */ readonly records?: CustomObjectRecordsClient; /** Custom adapter implementation for tests or non-SDK backends. */ readonly adapter?: CustomObjectRecordAdapter; } /** Lightweight pagination options shared by list and query helpers. */ export interface TypedRecordPageOptions { /** Opaque pagination cursor returned by a prior call. */ readonly cursor?: string; /** Maximum number of records to return. */ readonly limit?: number; } /** Raw-query options for typed record queries. */ export interface TypedRecordQueryOptions extends TypedRecordPageOptions { /** RQL string to execute against the underlying backend. */ readonly query?: string; } /** Pagination result returned by typed list/query helpers. */ export interface TypedRecordPage { /** Opaque backend cursor, if another page is available. */ readonly cursor: string | null; /** Strongly typed logical-key records. */ readonly results: readonly RecordShape[]; } /** Batch-write flags shared by bulk create/update/delete helpers. */ export interface TypedBatchWriteOptions { /** Whether the backend should reject the entire batch if any row fails. */ readonly allOrNothing?: boolean; } /** * One logical update item for {@link TypedCustomObjectRecordManager.updateMany}. * * @typeParam TDefinition - Object definition whose update payload should be enforced. */ export type TypedBulkUpdateInput = { readonly id: string; } & UpdateInput; /** * Structured validation failure thrown by typed record managers. * * @typeParam TDefinition - Object definition whose payload validation failed. */ export declare class CustomObjectRecordValidationError extends Error { /** Definition whose payload validation failed. */ readonly definition: TDefinition; /** Operation that was being attempted. */ readonly operation: 'create' | 'update' | 'bulk-create' | 'bulk-update'; /** Field-level validation issues returned by the schema validators. */ readonly issues: readonly ValidationIssue[]; /** * Builds a validation error for a typed record operation. * * @typeParam TDefinition - Object definition whose payload validation failed. */ constructor(definition: TDefinition, operation: 'create' | 'update' | 'bulk-create' | 'bulk-update', issues: readonly ValidationIssue[]); } /** Options for creating an in-memory adapter. */ export interface InMemoryCustomObjectRecordAdapterOptions { /** Optional starting rows keyed by custom-object api name. */ readonly seedRowsByObjectApiName?: Readonly>; /** Optional deterministic clock used for tests. */ readonly now?: () => string; /** Optional deterministic id generator used for tests. */ readonly nextID?: (customObjectApiName: string) => string; /** * Optional raw-query evaluator. * * If omitted, the in-memory adapter supports pagination-only list/query calls * and rejects query strings that would require actual RQL evaluation. */ readonly queryEvaluator?: (args: { customObjectApiName: string; query: string; row: CustomObjectDataRow; }) => boolean; } /** * Records-resource adapter implementation for typed record managers. * * @param records - Low-level records resource to adapt into the manager-friendly transport boundary. * @returns Adapter implementation backed by the supplied records resource. */ export declare function createCustomObjectRecordAdapter(records: CustomObjectRecordsClient): CustomObjectRecordAdapter; /** * In-memory adapter useful for unit tests and local flows that should not depend * on a real SDK transport. */ export declare class InMemoryCustomObjectRecordAdapter implements CustomObjectRecordAdapter { private readonly rowsByObjectApiName; private readonly now; private readonly nextID; private readonly queryEvaluator?; private sequence; /** Builds a new in-memory adapter. */ constructor(options?: InMemoryCustomObjectRecordAdapterOptions); private rowMap; private requiredRow; private paginate; create(customObjectApiName: string, body: Record): Promise; retrieve(customObjectApiName: string, recordId: string): Promise; retrieveByExternalID(customObjectApiName: string, externalID: string): Promise; update(customObjectApiName: string, recordId: string, body: Record): Promise; delete(customObjectApiName: string, recordId: string): Promise; query(customObjectApiName: string, params: RecordQueryParams): Promise; bulkCreate(customObjectApiName: string, request: CustomObjectRecordBulkCreateRequest): Promise; bulkUpdate(customObjectApiName: string, request: CustomObjectRecordBulkUpdateRequest): Promise; bulkDelete(customObjectApiName: string, request: CustomObjectRecordBulkDeleteRequest): Promise; } /** * Definition-bound CRUD manager returned by {@link CustomObjectManager.forObject}. * * @typeParam TDefinition - Object definition whose logical field names and value * types should be enforced. */ export declare class TypedCustomObjectRecordManager { private readonly definition; private readonly adapter; /** * Creates a bound typed manager for one object definition. * * @param definition - Typed object definition to bind to the manager. * @param adapter - Transport adapter used for all record operations. */ constructor(definition: TDefinition, adapter: CustomObjectRecordAdapter); /** * Creates one typed record after local schema validation. * * @param input - Typed logical create payload. * @returns Created typed record, or an ID-only receipt when read access is unavailable. */ create(input: CreateInput): Promise>; /** * Creates many typed records after validating the full batch locally. * * @param rows - Typed logical create payloads. * @param options - Batch-write options forwarded to the adapter. * @returns Typed records or ID-only receipts in backend response order. */ createMany(rows: readonly CreateInput[], options?: TypedBatchWriteOptions): Promise[]>; /** * Retrieves one typed record by id. * * @param recordId - Backend record id to fetch. * @returns Typed record for the requested id. */ get(recordId: string): Promise>; /** * Retrieves one typed record by external id. * * @param externalID - External id to look up. * @returns Typed record for the requested external id. */ getByExternalID(externalID: string): Promise>; /** * Updates one typed record after local schema validation. * * @param recordId - Backend record id to update. * @param patch - Typed logical update payload. * @returns Updated typed record, or an ID-only receipt when read access is unavailable. */ update(recordId: string, patch: UpdateInput): Promise>; /** * Updates many typed records after validating the full batch locally. * * @param rows - Typed update payloads, each including a backend record id. * @param options - Batch-write options forwarded to the adapter. * @returns Typed records or ID-only receipts in backend response order. */ updateMany(rows: readonly TypedBulkUpdateInput[], options?: TypedBatchWriteOptions): Promise[]>; /** * Deletes one record by id. * * @param recordId - Backend record id to delete. */ delete(recordId: string): Promise; /** * Deletes many records by id. * * @param recordIDs - Backend record ids to delete. * @param options - Batch-write options forwarded to the adapter. */ deleteMany(recordIDs: readonly string[], options?: TypedBatchWriteOptions): Promise; /** * Lists records using backend pagination without applying any query filter. * * @param options - Pagination options for the backend list operation. * @returns Typed record page. */ list(options?: TypedRecordPageOptions): Promise>; /** * Queries records with an optional raw RQL filter string. * * @param options - Query and pagination options for the backend query operation. * @returns Typed record page. */ query(options?: TypedRecordQueryOptions): Promise>; } /** * Root manager that binds typed custom-object definitions to a transport adapter. * * Callers can pass either a records resource or a test adapter. If neither is * provided, the manager defaults to an in-memory adapter so unit tests can use * the same high-level API without bootstrapping a backend client. */ export declare class CustomObjectManager { private readonly adapter; /** * Creates a new custom-object manager. * * @param options - Optional records resource or adapter implementation. */ constructor(options?: CustomObjectManagerOptions); /** * Builds a manager from a records resource. * * @param records - Low-level records resource to wrap. * @returns Custom-object manager backed by that records resource. */ static fromRecords(records: CustomObjectRecordsClient): CustomObjectManager; /** * Builds a manager from a real SDK client. * * @param sdk - SDK-shaped client exposing `customObjects.records`. * @returns Custom-object manager backed by the SDK records resource. */ static fromSDK(sdk: CustomObjectManagerSDKLike): CustomObjectManager; /** * Builds a manager backed by an in-memory adapter. * * @param options - In-memory adapter options for seed data and deterministic behavior. * @returns Custom-object manager backed by an in-memory adapter. */ static inMemory(options?: InMemoryCustomObjectRecordAdapterOptions): CustomObjectManager; /** Returns the low-level adapter used by this manager. */ getAdapter(): CustomObjectRecordAdapter; /** * Returns a typed record manager bound to one object definition. * * @param definition - Typed object definition to bind. * @returns Definition-bound typed record manager. * @typeParam TDefinition - Object definition bound to the manager. */ forObject(definition: TDefinition): TypedCustomObjectRecordManager; /** * Short ergonomic alias for {@link forObject}. * * @param definition - Typed object definition to bind. * @returns Definition-bound typed record manager. * @typeParam TDefinition - Object definition bound to the manager. */ for(definition: TDefinition): TypedCustomObjectRecordManager; } /** Short alias for teams that prefer concise manager names. */ export declare class COManager extends CustomObjectManager { } export {}; //# sourceMappingURL=manager.d.ts.map