/** * Effect-based create operations for entities. * * Uses Ref for atomic state mutation, Effect Schema for validation, * and typed errors (ValidationError, DuplicateKeyError, ForeignKeyError). */ import { Effect, PubSub, Ref, type Schema } from "effect"; import { DuplicateKeyError, type ForeignKeyError, type HookError, type UniqueConstraintError, type ValidationError } from "../../errors/crud-errors.js"; import type { CustomIdGenerator } from "../../plugins/plugin-types.js"; import type { ComputedFieldsConfig } from "../../types/computed-types.js"; import type { CreateInput, CreateManyOptions, CreateManyResult } from "../../types/crud-types.js"; import type { DerivedIdConfig } from "../../types/database-config-types.js"; import type { HooksConfig } from "../../types/hook-types.js"; import type { CollectionIndexes } from "../../types/index-types.js"; import type { ChangeEvent } from "../../types/reactive-types.js"; import type { SearchIndexMap } from "../../types/search-types.js"; import { type NormalizedConstraints } from "./unique-check.js"; type HasId = { readonly id: string; }; type RelationshipConfig = { readonly type: "ref" | "inverse"; readonly target: string; readonly foreignKey?: string; }; /** * Create a single entity with validation, hooks, and foreign key checks. * * Steps: * 1. Strip computed field keys from input (they are derived, not stored) * 2. Generate ID if not provided, add timestamps * 3. Validate through Effect Schema * 4. Run beforeCreate hooks (can transform entity) * 5. Check for duplicate ID in Ref state * 6. Validate foreign key constraints * 7. Atomically add to Ref state * 8. Update indexes if provided */ export declare const create: (collectionName: string, schema: Schema.Codec, relationships: Record, ref: Ref.Ref>, stateRefs: Record>>, indexes?: CollectionIndexes, hooks?: HooksConfig, uniqueFields?: NormalizedConstraints, computed?: ComputedFieldsConfig, searchIndexRef?: Ref.Ref, searchIndexFields?: ReadonlyArray, idGeneratorName?: string, idGeneratorMap?: Map, changePubSub?: PubSub.PubSub, derivedId?: DerivedIdConfig) => (input: CreateInput) => Effect.Effect; /** * Create multiple entities with batch validation, hooks, and optional duplicate skipping. * * When `skipDuplicates` is true, entities that fail validation, have duplicate IDs, * or have a HookError are skipped and reported in the result. Otherwise, the first error * stops the operation. */ export declare const createMany: (collectionName: string, schema: Schema.Codec, relationships: Record, ref: Ref.Ref>, stateRefs: Record>>, indexes?: CollectionIndexes, hooks?: HooksConfig, uniqueFields?: NormalizedConstraints, computed?: ComputedFieldsConfig, searchIndexRef?: Ref.Ref, searchIndexFields?: ReadonlyArray, idGeneratorName?: string, idGeneratorMap?: Map, changePubSub?: PubSub.PubSub, derivedId?: DerivedIdConfig) => (inputs: ReadonlyArray>, options?: CreateManyOptions) => Effect.Effect, ValidationError | DuplicateKeyError | ForeignKeyError | HookError | UniqueConstraintError>; export {}; //# sourceMappingURL=create.d.ts.map