/** * Base ResourceResolver with shared logic * * 核心设计原则: * - 用户写入时可以使用简单 local id(如 "alice", "tag-123") * - subjectTemplate 定义 local id 如何映射到 URI(如 "{id}.ttl#it", "#{id}") * - 写入时:local id + template → relativePath → baseUrl + relativePath * - 读取时:row.id 是 base-relative resource id,可从 base 下精确定位资源 */ import type { PodTable } from '../schema'; import type { QueryCondition } from '../query-conditions'; import type { ResourceResolver } from './types'; interface TemplateVariable { raw: string; field: string; transforms: string[]; } export declare abstract class BaseResourceResolver implements ResourceResolver { abstract readonly mode: 'fragment' | 'document'; protected podBaseUrl: string; constructor(podBaseUrl: string); abstract getContainerUrl(table: PodTable): string; abstract getResourceUrl(table: PodTable): string; abstract getResourceUrlForSubject(subjectUri: string): string; abstract resolveSelectSources(table: PodTable, containerUrl: string, condition?: QueryCondition, listContainer?: (url?: string) => Promise): Promise; abstract resolveSubjectsForMutation(table: PodTable, condition: QueryCondition, findSubjects: (resourceUrl: string) => Promise, listContainer: () => Promise): Promise; /** * 从 subject URI 解析出 ORM row id。 * * `id()` 是虚拟列,不写入 RDF 谓词;读取时它暴露 base-relative * resource id,而不是 subjectTemplate 中的本地 `{id}` slot。需要本地 * slot 时使用 parsePodResourceRef(...).templateValues.id 或 * extractPodResourceTemplateValue。 * * 例如: * - uri = "http://pod/items/alice.ttl#it", template = "{id}.ttl#it" → id = "alice.ttl#it" * - uri = "http://pod/tags.ttl#tag-1", template = "#{id}" → id = "tags.ttl#tag-1" * - uri = "http://pod/a/2026/05/07.ttl#x", template = "{yyyy}/{MM}/{dd}.ttl#{id}" → id = "2026/05/07.ttl#x" */ parseId(table: PodTable, subjectUri: string): string; /** * 从 id 构建完整的 subject URI * * 两步构建: * 1. 根据 subjectTemplate 应用 id → relativePath * 2. subjectUri = baseUrl + relativePath */ resolveSubject(table: PodTable, record: Record, index?: number): string; /** * Extract the local template `{id}` variable for template transforms and link * normalization. This is distinct from the public `id()` resource locator. */ protected parseTemplateId(table: PodTable, subjectUri: string): string | null; protected extractRelativeSubjectId(table: PodTable, subjectUri: string): string; protected extractBaseRelativeResourceId(table: PodTable, subjectUri: string): string; private extractTemplateRelativeSubjectId; protected isBaseRelativeSubjectId(value: string): boolean; protected acceptsFragmentOnlyResourceId(table: PodTable): boolean; protected resolveBaseRelativeSubjectId(table: PodTable, value: string): string | null; protected hasVirtualIdColumn(table: PodTable): boolean; /** * 获取表的 base URL,用于 id 解析 */ protected getBaseUrlForTable(table: PodTable): string; protected getSubjectBaseUrl(table: PodTable): string; /** * 获取有效的 subjectTemplate */ protected getEffectiveTemplate(table: PodTable): string; /** * 获取默认模板 * 子类应该重写此方法 */ protected abstract getDefaultTemplate(): string; /** * 生成 UUID */ protected generateUuid(): string; /** * 应用模板生成相对路径 * * @param record 记录数据 * @param template 模板 (如 "{id}.ttl#it") * @returns 相对路径 (如 "alice.ttl#it") */ protected applyTemplate(record: Record, template: string, table?: PodTable, index?: number): string; /** * 从相对路径反向解析出所有模板变量 * * @param relativePath 相对路径 (如 "room1/index.ttl#alice") * @param template 模板 (如 "{chatId}/index.ttl#{id}") * @returns 所有变量的键值对,解析失败返回 null */ protected extractVarsFromTemplate(relativePath: string, template: string): Record | null; /** * 从相对路径反向解析出 id(向后兼容) */ protected extractIdFromTemplate(relativePath: string, template: string): string | null; /** * Extract id values from a query condition * Shared logic for both fragment and document mode */ extractIdValues(condition: QueryCondition | Record | undefined): string[]; /** * Extract values for specific columns from a query condition * Used for subjectTemplate variable resolution */ extractTemplateValues(condition: QueryCondition | Record | undefined, columns: string[]): Record; protected collectColumnValue(condition: any, targetCol: string): string | undefined; protected collectIdValues(condition: any, ids: string[]): void; protected normalizeConditionColumnName(target: unknown): string; protected parseTemplateVariable(token: string): TemplateVariable; protected getTemplateVariables(template: string): TemplateVariable[]; protected createTimeContext(record: Record): { yyyy: string; MM: string; dd: string; HH: string; mm: string; ss: string; }; protected applyTemplateTransforms(value: unknown, variable: TemplateVariable, table?: PodTable, field?: string): string; protected normalizeTemplateValue(value: unknown, table?: PodTable, field?: string): string; protected extractTemplateId(value: string, table?: PodTable, field?: string): string; protected isLinkColumn(column: any): boolean; protected slugifyValue(value: string): string; /** * Resolve base URL for a table's base configuration */ protected resolveBaseUrl(table: PodTable): string; /** * 检查是否为绝对 URI */ protected isAbsoluteUri(value: string): boolean; /** * Fallback id 提取(当 subjectUri 不以 baseUrl 开头时) */ protected extractIdFallback(subjectUri: string): string; } export {}; //# sourceMappingURL=base-resolver.d.ts.map