/** * Internal sync service option contracts and validation. * * Holds the internal option/result types (`InternalSyncProvider`, * `InternalSyncServiceOptions`, `InternalSyncService`) plus every validation * rule the bootstrap enforces before it opens a SQLite runtime: service * options, effect-lease headroom against the ACTIVE provider's transport * timeouts, projection routes, and entity/property ownership. Also owns the * writer-identity derivation used by the runtime, supervisors, and shutdown. * * None of these types are part of the root application contract; the service * bootstrap re-exports them for internal entrypoints and tests. */ import type { HikouteiEntity, ResolvedHikouteiEntityDescriptor } from "../../api/entity.js"; import type { Hikoutei } from "../../api/hikouteiCore.js"; import type { EntityDescriptorResolutionFailure } from "../../api/internalEntityRegistry.js"; import type { TypedSheetsEntityWriterOptions } from "../../../contracts/sync-orm/writer.js"; import type { InternalSyncProjectionConfig } from "./contracts.js"; import type { RegisteredSyncProjectionDefinition, SyncSheetsProvisioner } from "../../../contracts/sheets/sheetsProvisioning.js"; import type { SyncSheetsProvider, SyncSheetsTableReader } from "../../../contracts/sheets/syncSheets.js"; import type { CoordinatorLaneEvent } from "../../../contracts/sheets/mutationCoordinator/laneTelemetry.js"; import type { GoogleSheetsApiProviderOptions } from "../../../contracts/sheets/googleSheetsApi.js"; import type { ExistingSheetAdoptionSpec } from "./adopt/existingSheetAdoption.js"; import { type EffectWorkerSupervisor, type WorkerReport } from "@hikoutei/ikisaki"; import type { SqlStorageAdapter } from "../../../contracts/storage/sql.js"; import type { MappedUserInputPollingReport } from "../../../contracts/sheets/userInputPolling.js"; import type { SyncTimingSink } from "../../../contracts/shared/observability/syncTiming.js"; import type { SyncPollingSupervisor } from "./SyncPollingSupervisor.js"; /** * Storage surface owned by the internal sync service: the engine consumes * the adapter-neutral SQL executor plus graceful close. The concrete * MikroORM adapter satisfies this structurally; the composition root owns * the construction (and any adapter-specific casting inside `composition/`). */ export type SyncServiceStorage = SqlStorageAdapter & { /** Closes the underlying SQLite connection; `force` skips graceful waits. */ close(force?: boolean): Promise; }; /** Provider capability required by internal service startup (incl. table reads). */ export type InternalSyncProvider = SyncSheetsProvider & SyncSheetsTableReader; /** Internal service options; none are part of the root application contract. */ export interface InternalSyncServiceOptions { readonly dbName: string; readonly entities: readonly HikouteiEntity[]; readonly projections: InternalSyncProjectionConfig; /** * Injected provider used by fake/in-process tests; mutually exclusive with * `googleSheetsApi`. The coordinator wraps it exactly like the real * provider so mutations share one mutation lane. */ readonly provider?: InternalSyncProvider; /** Optional provisioner for injected providers that do not own setup. */ readonly provisioner?: SyncSheetsProvisioner; /** * The full service-account Google Sheets API provider owns provisioning, * outbound effects, table reads, anchors, and snapshots with no Apps * Script at all. Requires Application Default Credentials (a service * account shared on the spreadsheet). Never part of the root API. */ readonly googleSheetsApi?: GoogleSheetsApiProviderOptions; /** * Existing-sheet adoption (MVP, direct mode only). In `dry-run` mode the * service reads the foreign tab, analyzes header-name bindings, and throws * `ExistingSheetAdoptionDryRunReportError` carrying the full report before * any provisioning mutation or supervisor start. In `adopt` mode the * seeding engine (`adopt/adoptionSeeding.ts`) binds every existing row before the * CleanupScanner can ever observe the tab (fail-closed ordering, D5). */ readonly adopt?: ExistingSheetAdoptionSpec; readonly writerId?: string; readonly workerId?: string; readonly maxEffects?: number; /** * Dispatch-unit concurrency inside one worker pass (default 1 = sequential * read-ahead pipeline). Route-disjoint units may overlap; same-route units * always serialize. Internal tuning knob, not part of the root API. */ readonly maxConcurrentUnits?: number; /** Internal lease for one remote effect batch; must exceed provider timeout. */ readonly effectLeaseDurationMs?: number; readonly effectIdleIntervalMs?: number; readonly onTiming?: SyncTimingSink; readonly onEffectReport?: (report: WorkerReport) => void; readonly onEffectError?: (error: unknown) => void; readonly pollingIntervalMs?: number; /** Maximum interval between metadata-preserving safety scans. */ readonly pollingFullScanIntervalMs?: number; /** Injectable clock for the polling coordinator cadence; defaults to Date.now. */ readonly now?: () => number; /** Optional per-spreadsheet mutation-lane key for the provider coordinator. */ readonly coordinatorLaneKeyForPhysicalSheet?: (physicalSheetId: string) => string; /** Optional diagnostic observer for coordinator mutation-lane events. */ readonly onCoordinatorLaneEvent?: (event: CoordinatorLaneEvent) => void; readonly onPollingReport?: (report: MappedUserInputPollingReport) => void; readonly onPollingError?: (error: unknown) => void; /** Minimum delay between System_State reconciliation scans (default 60s). */ readonly reconciliationIntervalMs?: number; /** Observability sink for one completed System_State reconciliation scan. */ readonly onReconciliationReport?: (report: { readonly effectsEnqueued: number; }) => void; /** Error sink for System_State reconciliation scan failures. */ readonly onReconciliationError?: (error: unknown) => void; } /** Runtime returned to an internal service entrypoint, not to root consumers. */ export interface InternalSyncService { readonly hikoutei: Hikoutei; /** Internal inspection handle; never part of the root application API. */ readonly storage: SyncServiceStorage; readonly projectionDefinitions: readonly RegisteredSyncProjectionDefinition[]; /** Retries durable OPEN system-wins commands after predecessors settle. */ readonly retryDeferredConflicts: () => Promise; readonly effectSupervisor: EffectWorkerSupervisor; readonly pollingSupervisor: SyncPollingSupervisor; stop(): Promise; close(): Promise; } /** * Maps a structured descriptor-registry failure to the internal * `SyncServiceError` contract with unchanged `INVALID_OPTIONS` messages. */ export declare function throwSyncResolutionError(failure: EntityDescriptorResolutionFailure): never; export declare function validateServiceOptions(options: InternalSyncServiceOptions, descriptors: ReadonlyMap): void; export declare function createWriterOptions(options: InternalSyncServiceOptions): TypedSheetsEntityWriterOptions; //# sourceMappingURL=serviceOptions.d.ts.map