import { type Json, type JsonObject, type ModuleFilePath, type SerializedEnumSchema, type SerializedSchema, type SourcePath } from "@valbuild/core"; import { type SchemaSourceSnapshot } from "./resolveSchemaSourceFixes.js"; /** * Which of the project's languages governs a path, or `null` for none. * * THE question the whole feature turns on. A locale scope is a subtree in one * language, and three things open one: a `locale` field on an object, a record * keyed by `s.locale()`, and a locale parameter in a router's key * (`s.router(router, { locale: … }, item)`, where the URL names the language). Once this can * be answered from the schema and the source alone, everything downstream falls * out of it — the Studio's locale filter, deep links, ``, and knowing * what to translate from and into. * * One implementation, so the Studio, the server and the validation worker cannot * disagree about what language a piece of content is in. * * `null` means no scope governs the path — which is the answer for most content * in most projects, and for every project that has not declared any languages. */ export declare function localeAt(path: SourcePath, snapshot: SchemaSourceSnapshot): string | null; /** * Where the scope governing a path opens, and how. * * - `field`: the node `depth` segments down has a locale field. `depth` 0 is the * module root. * - `record-key`: segment `depth` is a key of a locale-keyed record, which sits * `depth` segments down. * - `route-key`: segment `depth` is a route whose parameters name the language, * in the router `depth` segments down (in practice the module root). * * The opener is what decides where an editor goes when the Studio's language * changes under them — the same entry in another language for a key, the * parent for a field. See `relocateForLocale`. */ export type LocaleScope = { locale: string; depth: number; } & ({ kind: "field"; } | { kind: "record-key"; keySchema: SerializedSchema; } | { kind: "route-key"; router: SerializedSchema & { type: "record"; }; }); /** * The scope that governs a path, read from that module's schema and source * alone, or `null` where none does. * * {@link localeAt} for a caller that already has the module in hand — the * Studio, which has the project's languages from its own provider and would * otherwise have to assemble a snapshot of every module to ask about one. */ export declare function localeScopeAt(path: SourcePath, schema: SerializedSchema, source: Json, available: readonly string[]): LocaleScope | null; /** * The language a whole module is in: the one its root's locale field names, or * `null` where its root has none. * * The only way a module is in one language as a whole — a locale-keyed record * or a router at the root is every one of its languages at once. Needs no path, * so a list of modules can ask it of each. */ export declare function localeOfModuleRoot(schema: SerializedSchema, source: Json, available: readonly string[]): string | null; /** * The language a locale schema's value MEANS, or `null` if it means none of * the project's. * * `s.locale()` stores the tag itself. An enum with `.locales(...)` stores a * value that stands for one — `nb` for `nb-NO` — and, on a router parameter, * `null` for a URL that left the segment out, which `{ null: tag }` names. * Anything else is not a locale and means nothing here. * * Callers reading a FIELD pass only strings: a field that holds `null` has no * language, whatever its schema says about URLs. */ export declare function localeMeantBy(schema: SerializedSchema, value: string | null, available: readonly string[]): string | null; /** * The tag an enum's `.locales(...)` maps a value to, as written — `null` is * the `{ null }` mapping — or `undefined` where it maps none. * * An own property: a plain object inherits `toString` and the rest, and an * enum value is allowed to be spelled like one. */ export declare function enumLocaleTag(schema: SerializedEnumSchema, value: string | null): string | undefined; /** * Whether a schema is a locale: `s.locale()`, or an enum `.locales(...)` made * one. */ export declare function isLocaleSchema(schema: SerializedSchema): boolean; /** * Whether a router's URLs name the language each page is in — one of its route * parameters is a locale (`s.router(router, { locale: … }, item)`). */ export declare function hasLocaleRouteParam(schema: SerializedSchema): boolean; /** * The language a router's key is in, where one of its route parameters is a * locale — `/nb/blog/hei` is `nb-NO` when `locale` maps `nb` to it. * * Answered from the key alone, with no content read: which is what lets the * Studio's page tree filter every page of a site without loading one of them. */ export declare function localeOfRouteKey(schema: SerializedSchema & { type: "record"; }, moduleFilePath: ModuleFilePath, key: string, available: readonly string[]): string | null; /** * The route parameters a key gives its router, and which of them is the * language — or `null` where the router has no locale parameter or the key is * not one of its URLs. */ export declare function localeParamOfRouteKey(schema: SerializedSchema & { type: "record"; }, moduleFilePath: ModuleFilePath, key: string): { name: string; schema: SerializedSchema; value: string | null; values: Record; } | null; /** The child of a source value at a segment, or `null` where there is none. */ export declare function childSource(source: Json, segment: string): Json; /** * Whether `source` is a JSON object rather than an array or a primitive. * * A type predicate rather than the inline checks, because `Array.isArray` does * NOT narrow `JsonArray` out of `Json` — it is `readonly Json[]`, and the * built-in guard only narrows mutable arrays. Without this, every read of a * property would need an assertion. */ export declare function isJsonObject(source: Json): source is JsonObject;