veryfront/resource

Import

TypeScript
import { resource, resourceRegistry } from "veryfront/resource";

Examples

TypeScript
import { resource } from "veryfront/resource";import { defineSchema } from "veryfront/schemas"; const docsBySection: Record<string, string> = {  agents: "Agents accept messages, tools, context, and runtime options.",  tools: "Tools expose schema-backed callable capabilities.",}; const docs = resource({  pattern: "docs/:section",  description: "API documentation",  paramsSchema: defineSchema((v) => v.object({ section: v.string() }))(),  load: ({ section }) => {    return { content: docsBySection[section] ?? "Section not found." };  },}); const result = await docs.load({ section: "agents" });

API

resource(config)

Create a typed resource definition with unique URI-template parameter names.

PropertyTypeDescriptionSource
pattern?stringURI template using :name parameters. Hierarchical (/users/:id) and rootless (docs:collection/:id) paths are supported, as are embedded and query parameters (/file-:base.:ext?lang=:lang). Opaque identifiers such as urn:isbn remain literal. Parameter names must be unique and separated by literal text; the first following literal delimits an embedded value. A : directly following an alphanumeric character is always data, never a parameter: write /files/file-:id, not /files/file:id. This keeps opaque colon identifiers literal under one uniform rule.source
descriptionstringResource descriptionsource
title?stringsource
paramsSchema<code>Schema<TParams></code>Schema that validates and transforms URI parameterssource
load<code>(params: TParams) => Promise<TData> | TData</code>Function returning resource contentsource
subscribe?<code>(params: TParams) => AsyncIterable<TData></code>Async iterable for real-time resource updatessource
mcp?McpConfigMCP configuration. enabled: false hides the resource from lists and reads.source

Returns: <code>Resource<TParams, TData></code>

Exports

Functions

NameDescriptionSource
resourceCreate a typed resource definition with unique URI-template parameter names.source

Types

NameDescriptionSource
ResourcePublic API contract for resource.source
ResourceConfigConfiguration used by resource. URI captures are decoded exactly once before schema validation; malformed percent escapes do not match a resource.source

Constants

NameDescriptionSource
resourceRegistryShared resource registry value.source