Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/opfs.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455import { z } from "zod";
/** * Canonical virtual path stored and exchanged by adapters. * * Public path-taking APIs also accept relative and non-canonical input because * `normalizePath()` resolves it first. `PathSchema` is for already-normalized * values at persistence and adapter seams. */export const PathSchema: z.ZodType<PathType, PathType> = z.string().refine( (value: string) => value === "/" || ( value.startsWith("/") && !value.endsWith("/") && !value.includes("//") && !value.includes("\\") && !value.includes("\0") && value.split("/").slice(1).every((part: string) => part.length > 0 && part !== "." && part !== "..") ), "Expected a canonical virtual filesystem path.",);
/** A validated canonical virtual filesystem path. */export type PathType = import("./_schema_types.ts").PathType;
/** Stable non-empty diagnostic name assigned to one adapter implementation. */export const AdapterNameSchema: z.ZodType<AdapterNameType, AdapterNameType> = z.string().min(1);
/** A validated adapter diagnostic name. */export type AdapterNameType = import("./_schema_types.ts").AdapterNameType;
/** * Valid entry kinds exposed by the filesystem facade and every adapter. * * The package uses the same two kinds as the File System API. Adapters must not * invent a third kind for links, database rows, or provider-specific objects. */export const EntryKindSchema: z.ZodType<EntryKindType, EntryKindType> = z.enum(["file", "directory"]);
/** A validated filesystem entry kind. */export type EntryKindType = import("./_schema_types.ts").EntryKindType;
/** * Execution contexts that can host browser storage access. * * `worker` is used only when the runtime exposes a generic worker shape but the * library cannot prove whether it is dedicated, shared, or service-worker * execution. `unknown` means that no supported browser execution context was * detected. */export const OpfsContextSchema: z.ZodType<OpfsContextType, OpfsContextType> = z.enum([ "window", "dedicated-worker", "shared-worker", "service-worker", "worker", "unknown",]);
/** A validated browser execution context classification. */export type OpfsContextType = import("./_schema_types.ts").OpfsContextType;
/** * Mutation coordination policies supported by {@link createFileSystem}. * * `auto` uses Web Locks when the current realm exposes them. Otherwise it uses * an in-realm FIFO lock. `none` disables library coordination and transfers all * concurrency responsibility to the caller or adapter. */export const CoordinationModeSchema: z.ZodType<CoordinationModeType, CoordinationModeType> = z.enum(["auto", "web-locks", "local", "none"]);
/** A validated mutation coordination policy. */export type CoordinationModeType = import("./_schema_types.ts").CoordinationModeType;
/** * Write modes shared by the facade and adapters. * * `replace` starts from an empty file. `append` starts at the current end. * `update` preserves existing bytes and starts at the requested byte offset. */export const WriteModeSchema: z.ZodType<WriteModeType, WriteModeType> = z.enum(["replace", "append", "update"]);
/** A validated file write mode. */export type WriteModeType = import("./_schema_types.ts").WriteModeType;
/** * How one operation is provided by the selected storage stack. * * `native` means the immediate backend performs the operation directly. * `emulated` means the facade composes weaker primitives. `partitioned` means * the logical operation is preserved by splitting one value into multiple * provider records or blocks. `unsupported` means no safe implementation is * available for the selected stack. */export const SupportModeSchema: z.ZodType<SupportModeType, SupportModeType> = z.enum(["native", "emulated", "partitioned", "unsupported"]);
/** A validated storage support mode. */export type SupportModeType = import("./_schema_types.ts").SupportModeType;
/** * Metrics collection cost selected for one filesystem or protocol client. * * `basic` counts operations, bytes, failures, and chosen native/emulated paths. * `timing` also reads the monotonic clock around operations. `none` removes * metrics bookkeeping from hot paths when the caller is measuring raw overhead. */export const MetricsModeSchema: z.ZodType<MetricsModeType, MetricsModeType> = z.enum(["none", "basic", "timing"]);
/** A validated metrics collection mode. */export type MetricsModeType = import("./_schema_types.ts").MetricsModeType;
/** * Physical partition policy for backends with a smaller value limit than the * logical file size the application wants to expose. */export const PartitionModeSchema: z.ZodType<PartitionModeType, PartitionModeType> = z.enum(["never", "auto", "always"]);
/** A validated physical partition policy. */export type PartitionModeType = import("./_schema_types.ts").PartitionModeType;
/** * Inspectable physical layout used when one logical file spans provider values. * * `thresholdBytes` is the logical size where `auto` starts partitioning. When * omitted, callers can use `partBytes` as the conservative threshold. `stream` * means native stream writes use this layout so input size does not determine * facade memory growth. */export const AdapterPartitionSchema: z.ZodType<AdapterPartitionType, AdapterPartitionType> = z.object({ /** Partitioning policy selected for this adapter. */ mode: PartitionModeSchema, /** Physical part or block size used by the layout. */ partBytes: z.number().int().positive(), /** Logical size where `auto` starts partitioning when the adapter knows it. */ thresholdBytes: z.number().int().positive().optional(), /** Whether streamed writes already use the partitioned layout. */ stream: z.boolean().optional(), /** Maximum physical part or block count when the adapter knows it. */ maxParts: z.number().int().positive().optional(), /** Stable name of the physical layout strategy. */ layout: z.string().min(1),}).strict();
/** A validated physical partition layout. */export type AdapterPartitionType = import("./_schema_types.ts").AdapterPartitionType;
/** * Optional backend limits that can be inspected before work begins. * * Missing values mean the adapter cannot state a portable hard limit. They do * not mean unlimited. Provider-specific clients can expose additional limits * through their own public constants and request planners. */export const AdapterLimitsSchema: z.ZodType<AdapterLimitsType, AdapterLimitsType> = z.object({ /** Maximum logical file size accepted by this configured adapter. */ maxFileBytes: z.number().int().positive().optional(), /** Maximum materialized value accepted by one physical backend record. */ maxValueBytes: z.number().int().positive().optional(), /** Maximum serialized key size when the backend has one. */ maxKeyBytes: z.number().int().positive().optional(), /** Minimum legal provider part/block size when multipart work is used. */ minPartBytes: z.number().int().positive().optional(), /** Maximum legal provider part/block size. */ maxPartBytes: z.number().int().positive().optional(), /** Maximum provider part/block count for one logical object. */ maxParts: z.number().int().positive().optional(), /** Maximum useful provider concurrency known by this adapter. */ maxConcurrency: z.number().int().positive().optional(), /** Maximum bytes in one transactional/batched provider mutation. */ maxBatchBytes: z.number().int().positive().optional(),}).strict();
/** Portable hard limits known by one configured adapter. */export type AdapterLimitsType = import("./_schema_types.ts").AdapterLimitsType;
/** * Performance routes that the filesystem facade can deliberately bypass. * * Every field defaults to true. Disabling a route forces the semantically safe * fallback where one exists. This is useful for differential testing and for * applications that prefer a slower but more observable or more portable path. */export const OptimizationSchema: z.ZodType<OptimizationType, OptimizationType> = z.object({ /** Use adapter-native streaming reads instead of materialized `readFile()`. */ streamRead: z.boolean(), /** Use adapter-native streaming writes when the requested mode supports them. */ streamWrite: z.boolean(), /** Forward byte ranges directly instead of materializing and slicing locally. */ rangeRead: z.boolean(), /** Use adapter-native/server-side copy instead of read plus write. */ nativeCopy: z.boolean(), /** Use adapter-native move/rename instead of copy then remove. */ nativeMove: z.boolean(),}).strict();
/** Resolved performance-route policy for one filesystem facade. */export type OptimizationType = import("./_schema_types.ts").OptimizationType;
/** * Stable adapter capability description. * * These flags describe native adapter operations, not operations that the * facade can emulate. `streamWriteModes` is intentionally mode-specific: an * object store can stream a complete replacement while append/update still * require a read-modify-write cycle. `nativeCopy` identifies server-side or * host-native copy so the facade does not move bytes through JavaScript when * the backend can copy them directly. */export const AdapterCapabilitiesSchema: z.ZodType<AdapterCapabilitiesType, AdapterCapabilitiesType> = z.object({ /** Adapter can materialize file bytes through `readFile()`. */ read: z.boolean(), /** Adapter can commit materialized file bytes through `writeFile()`. */ write: z.boolean(), /** Adapter can open a native/bounded provider stream without facade materialization. */ streamRead: z.boolean(), /** Write modes that `writeStream()` can perform without facade materialization. */ streamWriteModes: z.array(WriteModeSchema).readonly(), /** Adapter can satisfy byte ranges without reading the complete file first. */ rangeRead: z.boolean(), /** Adapter can copy bytes without routing them through the filesystem facade. */ nativeCopy: z.boolean(), /** Adapter can move/rename through one backend-native operation. */ nativeMove: z.boolean(), /** Adapter exposes a long-lived asynchronous positional writer. */ positionalWrite: z.boolean(), /** Adapter exposes a synchronous random-access file resource. */ syncAccess: z.boolean(),});
/** Native operations implemented by one adapter. */export type AdapterCapabilitiesType = import("./_schema_types.ts").AdapterCapabilitiesType;
/** * Stable error categories exposed by the package. * * Adapters map runtime-specific failures into these categories so consumers do * not need separate branches for DOMException, Deno, Bun, Node, SQL, and * document-database error classes. */export const ErrorCodeSchema: z.ZodType<ErrorCodeType, ErrorCodeType> = z.enum([ "unavailable", "not-found", "already-exists", "type-mismatch", "invalid-path", "invalid-operation", "not-supported", "locked", "quota-exceeded", "permission-denied", "aborted", "too-large", "unknown",]);
/** A validated package error category. */export type ErrorCodeType = import("./_schema_types.ts").ErrorCodeType;
/** Version stored with record-backed filesystem entries. */export const RecordVersionSchema: z.ZodType<RecordVersionType, RecordVersionType> = z.literal(1);
/** Persisted record format version. */export type RecordVersionType = import("./_schema_types.ts").RecordVersionType;
/** * Fields shared by every persisted record-store entry. * * The virtual path is the durable identity. `parent` is stored separately so * document and SQL backends can list one directory without scanning every * record or reconstructing parents from strings. */const RecordBaseSchema = z.object({ /** Persistence format version used to reject incompatible record layouts. */ version: RecordVersionSchema, /** Canonical virtual path and durable logical record identity. */ path: PathSchema, /** Canonical direct-parent path indexed by listing-oriented backends. */ parent: PathSchema, /** Final path segment presented by directory iteration. */ name: z.string(), /** Last modification time represented as Unix epoch milliseconds. */ lastModified: z.number().int().nonnegative(),});
/** Persisted directory record used by record-store adapters. */const DirectoryRecordSchemaDefinition = RecordBaseSchema.extend({ /** Discriminator that prevents a directory row from carrying file bytes. */ kind: z.literal("directory"),});
/** Persisted directory validator with an explicit public type boundary. */export const DirectoryRecordSchema: z.ZodType<DirectoryRecordType, DirectoryRecordType> = DirectoryRecordSchemaDefinition;
/** A validated persisted directory record. */export type DirectoryRecordType = import("./_schema_types.ts").DirectoryRecordType;
/** Persisted file record used by record-store adapters. */const FileRecordSchemaDefinition = RecordBaseSchema.extend({ /** Discriminator that selects the file-record branch. */ kind: z.literal("file"), /** Base64 file body used by JSON/document/SQL-compatible record stores. */ data: z.string(), /** Decoded byte length retained without re-decoding `data` during stat calls. */ size: z.number().int().nonnegative(), /** Media type retained by backends that can preserve file metadata. */ mediaType: z.string(),});
/** Persisted file validator with an explicit public type boundary. */export const FileRecordSchema: z.ZodType<FileRecordType, FileRecordType> = FileRecordSchemaDefinition;
/** A validated persisted file record. */export type FileRecordType = import("./_schema_types.ts").FileRecordType;
/** * Persisted record format shared by RxDB, unstorage, db0, and Drizzle record drivers. * * File bytes use base64 text because every target ecosystem can preserve JSON * strings. This costs about one third more storage than raw bytes. Native file * adapters do not use this format. */const RecordSchemaDefinition = z.discriminatedUnion("kind", [DirectoryRecordSchemaDefinition, FileRecordSchemaDefinition]);
/** Persisted record validator with an explicit public type boundary. */export const RecordSchema: z.ZodType<RecordType, RecordType> = RecordSchemaDefinition;
/** A validated record-store filesystem entry. */export type RecordType = import("./_schema_types.ts").RecordType;
/** SQL dialects currently exposed by db0's public Database contract. */export const Db0DialectSchema: z.ZodType<Db0DialectType, Db0DialectType> = z.enum(["mysql", "postgresql", "sqlite", "libsql"]);
/** A validated db0 SQL dialect. */export type Db0DialectType = import("./_schema_types.ts").Db0DialectType;
/** Safe unqualified SQL identifier used for adapter-owned table names. */export const SqlIdentifierSchema: z.ZodType<SqlIdentifierType, SqlIdentifierType> = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
/** A validated unqualified SQL identifier. */export type SqlIdentifierType = import("./_schema_types.ts").SqlIdentifierType;
/** Storage family owned by one backend driver. */export const DriverKindSchema: z.ZodType<DriverKindType, DriverKindType> = z.enum(["file", "record", "object"]);
/** A validated backend driver family. */export type DriverKindType = import("./_schema_types.ts").DriverKindType;
/** Why one driver limit exists. */export const LimitKindSchema: z.ZodType<LimitKindType, LimitKindType> = z.enum(["hard", "policy", "dynamic"]);
/** A validated limit kind. */export type LimitKindType = import("./_schema_types.ts").LimitKindType;
/** Layer that supplied one limit value. */export const LimitSourceSchema: z.ZodType<LimitSourceType, LimitSourceType> = z.enum(["provider", "implementation", "user", "probe"]);
/** A validated limit source. */export type LimitSourceType = import("./_schema_types.ts").LimitSourceType;
/** Unit used by one numeric limit. */export const LimitUnitSchema: z.ZodType<LimitUnitType, LimitUnitType> = z.enum(["bytes", "count", "milliseconds", "operations"]);
/** A validated limit unit. */export type LimitUnitType = import("./_schema_types.ts").LimitUnitType;
/** * One inspectable storage limit with explicit provenance. * * A hard provider limit is not interchangeable with a project safety policy or * a user-selected ceiling. `value` can be absent only for a dynamic limit whose * current value has not been probed. */export const LimitSchema: z.ZodType<LimitType, LimitType> = z.object({ /** Stable machine-readable limit code. */ code: z.string().min(1), /** Whether the limit is hard, policy-driven, or dynamic. */ kind: LimitKindSchema, /** Layer that supplied the limit value. */ source: LimitSourceSchema, /** Unit used by the numeric value. */ unit: LimitUnitSchema, /** Current numeric limit when known. */ value: z.number().nonnegative().optional(), /** Human-readable context for diagnostics. */ detail: z.string().min(1).optional(),}).strict().superRefine((value, ctx) => { if (value.value === undefined && value.kind !== "dynamic") { ctx.addIssue({ code: "custom", message: "Only dynamic limits can omit their current value." }); }});
/** A validated storage limit. */export type LimitType = import("./_schema_types.ts").LimitType;
/** Current state of one driver requirement. */export const RequirementStateSchema: z.ZodType<RequirementStateType, RequirementStateType> = z.enum(["available", "missing", "unknown"]);
/** A validated requirement state. */export type RequirementStateType = import("./_schema_types.ts").RequirementStateType;
/** * One runtime, provider, permission, or configuration requirement. * * Definitions can report `unknown` before probing. Configured drivers should * prefer `available` or `missing` when the state is already known. */export const RequirementSchema: z.ZodType<RequirementType, RequirementType> = z.object({ /** Stable machine-readable requirement code. */ code: z.string().min(1), /** Current known availability state. */ state: RequirementStateSchema, /** Concrete reason when the requirement is missing. */ reason: z.string().min(1).optional(),}).strict().superRefine((value, ctx) => { if (value.state === "missing" && value.reason === undefined) { ctx.addIssue({ code: "custom", message: "Missing requirements need a concrete reason." }); }});
/** A validated driver requirement. */export type RequirementType = import("./_schema_types.ts").RequirementType;
/** Ownership state for one configured driver backend resource. */export const DriverOwnershipSchema: z.ZodType<DriverOwnershipType, DriverOwnershipType> = z.enum(["none", "borrowed", "owned"]);
/** A validated configured-driver backend ownership state. */export type DriverOwnershipType = import("./_schema_types.ts").DriverOwnershipType;
/** * One independently controllable driver optimization. * * `changesBehavior` means request count, failure timing, storage layout, * consistency, atomicity, or another observable property can differ when the * optimization is enabled. Such optimizations must be disableable. */export const DriverOptimizationSchema: z.ZodType<DriverOptimizationType, DriverOptimizationType> = z.object({ /** Stable machine-readable optimization code. */ code: z.string().min(1), /** Current enabled state. */ enabled: z.boolean(), /** Whether this optimization changes observable behavior. */ changesBehavior: z.boolean(), /** Whether callers can turn this optimization off. */ disableable: z.boolean(), /** Human-readable detail for diagnostics or documentation. */ detail: z.string().min(1).optional(),}).strict().superRefine((value, ctx) => { if (value.changesBehavior && !value.disableable) { ctx.addIssue({ code: "custom", message: "Behavior-changing optimizations must be disableable." }); }});
/** A validated driver optimization declaration. */export type DriverOptimizationType = import("./_schema_types.ts").DriverOptimizationType;