import { Driver, Transaction } from 'neo4j-driver'; import { OGMLogger } from './execution/executor'; import { InterfaceModel, InterfaceModelCompilers } from './interface-model'; import { FulltextInput, Model, ModelCompilers } from './model'; import { PolicyResolver } from './policy/resolver'; import type { PoliciesByModel, Policy, PolicyContext, PolicyDefaults } from './policy/types'; import { SchemaMetadata } from './schema/types'; import { SubgraphCloneResult, SubgraphConfig, SubgraphDeleteResult } from './subgraph/types'; export interface OGMConfig = Record, C extends PolicyContext = PolicyContext> { typeDefs: string; driver: Driver; logger?: OGMLogger; features?: { filters?: { String?: { MATCHES?: boolean; }; }; /** * Reject `where` filters that reference a field name not declared * on the target type. Default: `false` (preserves pre-1.7.5 * behaviour where typo'd field names compiled to * `n. = $param` against a non-existent property → empty * result silently). When `true`, the where compiler throws * `OGMError` on the first unknown field, surfacing the bug at * the call site instead of in the result. Recommended for new * codebases; opt-in for existing ones to avoid breaking queries * that happened to rely on the silent behaviour. */ strictWhere?: boolean; }; /** * Map of typeName → policies. Validated against the schema at init. * * Each entry's policies fire for that exact type AND for any concrete * type that implements an interface with the same key. See the v1.7.0 * inheritance rule (AND-restrictive, OR-permissive). */ policies?: PoliciesByModel; /** Defaults applied to every policy decision. */ policyDefaults?: PolicyDefaults; } export declare class OGM = Record, TInterfaceModelMap extends Record = Record> { private config; private schema; private models; private interfaceModels; private modelCompilers; private interfaceModelCompilers; private policyRegistry; private policyResolver; private policyDefaults; /** Marker for `unsafe.bypassPolicies()` clones. */ private globalBypass; constructor(config: OGMConfig); /** Internal cloning hook used by `unsafe.bypassPolicies()`. */ private cloneAsBypassed; /** * Vend a `Model` augmented with the per-request `ctx`. The returned * surface mirrors `OGM.model(name)` exactly — Models constructed via * `withContext` share the OGM's compilers and resolver but carry a * frozen `ctx` snapshot used in every policy decision. * * Discard the returned wrapper after the request finishes — it must * NOT outlive the ctx. */ withContext(ctx: C): OGMWithContext; /** * Escape hatches for opting OUT of policy enforcement. Use sparingly * and only at well-audited boundaries (data migrations, admin scripts, * explicit cross-tenant tooling). */ readonly unsafe: { /** * Returns an OGM identical to the current one but with all policies * disabled. Logs a warning on every call. Discard immediately after * the bypass operation completes. */ bypassPolicies: () => OGM; }; /** Internal: expose the resolver for the wrapper. */ _internalResolver(): PolicyResolver; /** Internal: expose defaults for the wrapper. */ _internalDefaults(): PolicyDefaults; /** Internal: expose registry for tests. */ _internalPolicyRegistry(): ReadonlyMap>; init(): Promise; assertIndexesAndConstraints(options?: { options?: { create?: boolean; }; }): Promise; model(name: K): Model, TModelMap[K] extends { SelectFields: infer S extends Record; } ? S : Record, TModelMap[K] extends { Where: infer W extends Record; } ? W : Record, TModelMap[K] extends { CreateInput: infer C extends Record; } ? C : Record, TModelMap[K] extends { UpdateInput: infer U extends Record; } ? U : Record, TModelMap[K] extends { ConnectInput: infer Co extends Record; } ? Co : Record, TModelMap[K] extends { DisconnectInput: infer D extends Record; } ? D : Record, TModelMap[K] extends { DeleteInput: infer De extends Record; } ? De : Record, TModelMap[K] extends { PluralKey: infer PK extends string; } ? PK : string, TModelMap[K] extends { MutationSelectFields: infer MS extends Record; } ? MS : Record, TModelMap[K] extends { Sort: infer So; } ? So : Record, TModelMap[K] extends { Fulltext: infer F; } ? F : FulltextInput>; /** @deprecated Legacy overload for backward compatibility with @neo4j/graphql-ogm. Use the single-generic overload instead. */ model<_T, K extends string>(name: K): Model; model>(name: string): Model; interfaceModel(name: K): InterfaceModel, TInterfaceModelMap[K] extends { Where: infer W; } ? W : Record, TInterfaceModelMap[K] extends { Sort: infer So; } ? So : Record>; interfaceModel>(name: string): InterfaceModel; /** * Clear all internal caches and release model references. * Call when disposing the OGM instance (e.g., in tests or module teardown). */ close(): void; /** * Execute a raw Cypher query and return mapped results. * Uses OGM-managed sessions with debug logging. */ $queryRaw>(cypher: string, params?: Record): Promise; /** * Execute a raw Cypher write operation and return affected counts. * Uses OGM-managed sessions with debug logging. */ $executeRaw(cypher: string, params?: Record): Promise<{ recordsAffected: number; }>; /** * Execute a callback within a Neo4j transaction. * Automatically commits on success and rolls back on error. * The callback receives an `ExecutionContext` to pass into model methods. * * Overloads: * - Callback: `$transaction(async (ctx) => { ... })` — interactive transaction * - Sequential: `$transaction([(ctx) => op1(ctx), (ctx) => op2(ctx)])` — array of operations */ $transaction(fn: (ctx: { transaction: Transaction; }) => Promise): Promise; $transaction(operations: { [K in keyof T]: (ctx: { transaction: Transaction; }) => Promise; }): Promise; /** * Clone a content subgraph rooted at the given source node. * * If a `transaction` is provided, uses it directly (caller manages commit/rollback). * Otherwise opens a session and transaction internally; commits on success, rolls back on error. */ $cloneSubgraph(sourceRootId: string, config: SubgraphConfig, transaction?: Transaction): Promise; /** * Delete a content subgraph rooted at the given node. * * If a `transaction` is provided, uses it directly (caller manages commit/rollback). * Otherwise opens a session and transaction internally; commits on success, rolls back on error. */ $deleteSubgraph(rootId: string, config: SubgraphConfig, transaction?: Transaction): Promise; } /** * Per-request wrapper around an `OGM` that injects `ctx` into every * `model(name)` call. Hand-rolled (not a Proxy) for explicit type * inference. Each `model(name)` call returns a NEW `Model` instance * carrying a `policyBinding` keyed on this wrapper's frozen ctx. */ export declare class OGMWithContext = Record, TInterfaceModelMap extends Record = Record, C extends PolicyContext = PolicyContext> { private readonly schema; private readonly driver; private readonly compilers; private readonly interfaceCompilers; private readonly logger; private readonly ctx; private readonly resolver; private readonly defaults; private readonly globalBypass; private readonly cache; private readonly interfaceCache; constructor(args: { schema: SchemaMetadata; driver: Driver; compilers: ModelCompilers; interfaceCompilers: InterfaceModelCompilers; logger: OGMLogger | undefined; ctx: C; resolver: PolicyResolver; defaults: PolicyDefaults; globalBypass: boolean; }); model(name: K): Model, TModelMap[K] extends { SelectFields: infer S extends Record; } ? S : Record, TModelMap[K] extends { Where: infer W extends Record; } ? W : Record, TModelMap[K] extends { CreateInput: infer Cin extends Record; } ? Cin : Record, TModelMap[K] extends { UpdateInput: infer U extends Record; } ? U : Record, TModelMap[K] extends { ConnectInput: infer Co extends Record; } ? Co : Record, TModelMap[K] extends { DisconnectInput: infer D extends Record; } ? D : Record, TModelMap[K] extends { DeleteInput: infer De extends Record; } ? De : Record, TModelMap[K] extends { PluralKey: infer PK extends string; } ? PK : string, TModelMap[K] extends { MutationSelectFields: infer MS extends Record; } ? MS : Record, TModelMap[K] extends { Sort: infer So; } ? So : Record, TModelMap[K] extends { Fulltext: infer F; } ? F : FulltextInput>; model>(name: string): Model; interfaceModel(name: K): InterfaceModel, TInterfaceModelMap[K] extends { Where: infer W; } ? W : Record, TInterfaceModelMap[K] extends { Sort: infer So; } ? So : Record>; interfaceModel>(name: string): InterfaceModel; } //# sourceMappingURL=ogm.d.ts.map