diff --git a/src/schema.ts b/src/schema.ts index cc98994..c84008f 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1,11 +1,5 @@ import { z } from "zod"; -/** Compile-time assertion that fails when a boolean type is not `true`. */ -type AssertTrue = T; - -/** Bidirectional assignability check used to catch schema/type drift. */ -type IsEquivalent = [A] extends [B] ? ([B] extends [A] ? true : false) : false; - /** * Canonical virtual path stored and exchanged by adapters. * @@ -27,7 +21,7 @@ export const PathSchema = z.string().refine( ); /** A validated canonical virtual filesystem path. */ -export type PathType = string; +export type PathType = z.output; /** Stable non-empty diagnostic name assigned to one adapter implementation. */ export const AdapterNameSchema = z.string().min(1); @@ -44,7 +38,7 @@ export type AdapterNameType = z.output; export const EntryKindSchema = z.enum(["file", "directory"]); /** A validated filesystem entry kind. */ -export type EntryKindType = "file" | "directory"; +export type EntryKindType = z.output; /** * Execution contexts that can host browser storage access. @@ -64,13 +58,7 @@ export const OpfsContextSchema = z.enum([ ]); /** A validated browser execution context classification. */ -export type OpfsContextType = - | "window" - | "dedicated-worker" - | "shared-worker" - | "service-worker" - | "worker" - | "unknown"; +export type OpfsContextType = z.output; /** * Mutation coordination policies supported by {@link createFileSystem}. @@ -82,7 +70,7 @@ export type OpfsContextType = export const CoordinationModeSchema = z.enum(["auto", "web-locks", "local", "none"]); /** A validated mutation coordination policy. */ -export type CoordinationModeType = "auto" | "web-locks" | "local" | "none"; +export type CoordinationModeType = z.output; /** * Write modes shared by the facade and adapters. @@ -93,7 +81,7 @@ export type CoordinationModeType = "auto" | "web-locks" | "local" | "none"; export const WriteModeSchema = z.enum(["replace", "append", "update"]); /** A validated file write mode. */ -export type WriteModeType = "replace" | "append" | "update"; +export type WriteModeType = z.output; /** * How one operation is provided by the selected storage stack. @@ -107,7 +95,7 @@ export type WriteModeType = "replace" | "append" | "update"; export const SupportModeSchema = z.enum(["native", "emulated", "partitioned", "unsupported"]); /** A validated storage support mode. */ -export type SupportModeType = "native" | "emulated" | "partitioned" | "unsupported"; +export type SupportModeType = z.output; /** * Metrics collection cost selected for one filesystem or protocol client. @@ -119,7 +107,7 @@ export type SupportModeType = "native" | "emulated" | "partitioned" | "unsupport export const MetricsModeSchema = z.enum(["none", "basic", "timing"]); /** A validated metrics collection mode. */ -export type MetricsModeType = "none" | "basic" | "timing"; +export type MetricsModeType = z.output; /** * Physical partition policy for backends with a smaller value limit than the @@ -128,7 +116,7 @@ export type MetricsModeType = "none" | "basic" | "timing"; export const PartitionModeSchema = z.enum(["never", "auto", "always"]); /** A validated physical partition policy. */ -export type PartitionModeType = "never" | "auto" | "always"; +export type PartitionModeType = z.output; /** * Inspectable physical layout used when one logical file spans provider values. @@ -154,24 +142,7 @@ export const AdapterPartitionSchema = z.object({ }).strict(); /** A validated physical partition layout. */ -export interface AdapterPartitionType { - /** Partitioning policy selected for this adapter. */ - readonly mode: PartitionModeType; - /** Physical part or block size used by the layout. */ - readonly partBytes: number; - /** Logical size where `auto` starts partitioning when known. */ - readonly thresholdBytes?: number | undefined; - /** Whether streamed writes already use the partitioned layout. */ - readonly stream?: boolean | undefined; - /** Maximum physical part or block count when known. */ - readonly maxParts?: number | undefined; - /** Stable name of the physical layout strategy. */ - readonly layout: string; -} - -type _AdapterPartitionTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type AdapterPartitionType = z.output; /** * Optional backend limits that can be inspected before work begins. @@ -200,28 +171,7 @@ export const AdapterLimitsSchema = z.object({ }).strict(); /** Portable hard limits known by one configured adapter. */ -export interface AdapterLimitsType { - /** Maximum logical file size accepted by this configured adapter. */ - readonly maxFileBytes?: number | undefined; - /** Maximum materialized backend value size when the backend has one. */ - readonly maxValueBytes?: number | undefined; - /** Maximum serialized key size when the backend has one. */ - readonly maxKeyBytes?: number | undefined; - /** Minimum legal provider part or block size. */ - readonly minPartBytes?: number | undefined; - /** Maximum legal provider part or block size. */ - readonly maxPartBytes?: number | undefined; - /** Maximum provider part or block count for one logical object. */ - readonly maxParts?: number | undefined; - /** Maximum useful concurrency known by this adapter. */ - readonly maxConcurrency?: number | undefined; - /** Maximum bytes allowed in one batched or transactional mutation. */ - readonly maxBatchBytes?: number | undefined; -} - -type _AdapterLimitsTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type AdapterLimitsType = z.output; /** * Performance routes that the filesystem facade can deliberately bypass. @@ -244,22 +194,7 @@ export const OptimizationSchema = z.object({ }).strict(); /** Resolved performance-route policy for one filesystem facade. */ -export interface OptimizationType { - /** Enables adapter-native streaming reads when available. */ - readonly streamRead: boolean; - /** Enables adapter-native streaming writes when available. */ - readonly streamWrite: boolean; - /** Enables native range reads when available. */ - readonly rangeRead: boolean; - /** Enables adapter-native or server-side copy routes when available. */ - readonly nativeCopy: boolean; - /** Enables adapter-native move or rename routes when available. */ - readonly nativeMove: boolean; -} - -type _OptimizationTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type OptimizationType = z.output; /** * Stable adapter capability description. @@ -293,30 +228,7 @@ export const AdapterCapabilitiesSchema = z.object({ }); /** Native operations implemented by one adapter. */ -export interface AdapterCapabilitiesType { - /** Adapter can materialize file bytes through `readFile()`. */ - readonly read: boolean; - /** Adapter can commit materialized file bytes through `writeFile()`. */ - readonly write: boolean; - /** Adapter can open a native read stream. */ - readonly streamRead: boolean; - /** Write modes that `writeStream()` can perform natively. */ - readonly streamWriteModes: readonly WriteModeType[]; - /** Adapter can satisfy byte ranges without whole-file materialization. */ - readonly rangeRead: boolean; - /** Adapter can copy bytes without routing them through the facade. */ - readonly nativeCopy: boolean; - /** Adapter can move or rename through one backend-native route. */ - readonly nativeMove: boolean; - /** Adapter exposes a long-lived asynchronous positional writer. */ - readonly positionalWrite: boolean; - /** Adapter exposes a synchronous random-access file resource. */ - readonly syncAccess: boolean; -} - -type _AdapterCapabilitiesTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type AdapterCapabilitiesType = z.output; /** * Stable error categories exposed by the package. @@ -342,22 +254,7 @@ export const ErrorCodeSchema = z.enum([ ]); /** A validated package error category. */ -export type ErrorCodeType = - | "unavailable" - | "not-found" - | "already-exists" - | "type-mismatch" - | "invalid-path" - | "invalid-operation" - | "not-supported" - | "locked" - | "quota-exceeded" - | "permission-denied" - | "aborted" - | "too-large" - | "unknown"; - -type _ErrorCodeTypeMatchesSchema = AssertTrue>>; +export type ErrorCodeType = z.output; /** Version stored with record-backed filesystem entries. */ export const RecordVersionSchema = z.literal(1); @@ -437,35 +334,25 @@ export type SqlIdentifierType = z.output; export const DriverKindSchema = z.enum(["file", "record", "object"]); /** A validated backend driver family. */ -export type DriverKindType = "file" | "record" | "object"; - -type _DriverKindTypeMatchesSchema = AssertTrue>>; +export type DriverKindType = z.output; /** Why one driver limit exists. */ export const LimitKindSchema = z.enum(["hard", "policy", "dynamic"]); /** A validated limit kind. */ -export type LimitKindType = "hard" | "policy" | "dynamic"; - -type _LimitKindTypeMatchesSchema = AssertTrue>>; +export type LimitKindType = z.output; /** Layer that supplied one limit value. */ export const LimitSourceSchema = z.enum(["provider", "implementation", "user", "probe"]); /** A validated limit source. */ -export type LimitSourceType = "provider" | "implementation" | "user" | "probe"; - -type _LimitSourceTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type LimitSourceType = z.output; /** Unit used by one numeric limit. */ export const LimitUnitSchema = z.enum(["bytes", "count", "milliseconds", "operations"]); /** A validated limit unit. */ -export type LimitUnitType = "bytes" | "count" | "milliseconds" | "operations"; - -type _LimitUnitTypeMatchesSchema = AssertTrue>>; +export type LimitUnitType = z.output; /** * One inspectable storage limit with explicit provenance. @@ -494,32 +381,13 @@ export const LimitSchema = z.object({ }); /** A validated storage limit. */ -export interface LimitType { - /** Stable machine-readable limit code. */ - readonly code: string; - /** Whether the limit is hard, policy-driven, or dynamic. */ - readonly kind: LimitKindType; - /** Layer that supplied the limit value. */ - readonly source: LimitSourceType; - /** Unit used by the numeric value. */ - readonly unit: LimitUnitType; - /** Current numeric limit when known. */ - readonly value?: number | undefined; - /** Human-readable context for diagnostics. */ - readonly detail?: string | undefined; -} - -type _LimitTypeMatchesSchema = AssertTrue>>; +export type LimitType = z.output; /** Current state of one driver requirement. */ export const RequirementStateSchema = z.enum(["available", "missing", "unknown"]); /** A validated requirement state. */ -export type RequirementStateType = "available" | "missing" | "unknown"; - -type _RequirementStateTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type RequirementStateType = z.output; /** * One runtime, provider, permission, or configuration requirement. @@ -541,26 +409,13 @@ export const RequirementSchema = z.object({ }); /** A validated driver requirement. */ -export interface RequirementType { - /** Stable machine-readable requirement code. */ - readonly code: string; - /** Current known availability state. */ - readonly state: RequirementStateType; - /** Concrete reason when the requirement is missing. */ - readonly reason?: string | undefined; -} - -type _RequirementTypeMatchesSchema = AssertTrue>>; +export type RequirementType = z.output; /** Ownership state for one configured driver backend resource. */ export const DriverOwnershipSchema = z.enum(["none", "borrowed", "owned"]); /** A validated configured-driver backend ownership state. */ -export type DriverOwnershipType = "none" | "borrowed" | "owned"; - -type _DriverOwnershipTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type DriverOwnershipType = z.output; /** * One independently controllable driver optimization. @@ -587,19 +442,4 @@ export const DriverOptimizationSchema = z.object({ }); /** A validated driver optimization declaration. */ -export interface DriverOptimizationType { - /** Stable machine-readable optimization code. */ - readonly code: string; - /** Current enabled state. */ - readonly enabled: boolean; - /** Whether this optimization changes observable behavior. */ - readonly changesBehavior: boolean; - /** Whether callers can turn this optimization off. */ - readonly disableable: boolean; - /** Human-readable detail for diagnostics or documentation. */ - readonly detail?: string | undefined; -} - -type _DriverOptimizationTypeMatchesSchema = AssertTrue< - IsEquivalent> ->; +export type DriverOptimizationType = z.output;