Skip to main content

Crate tabnas_multisource

Crate tabnas_multisource 

Source
Expand description

Load partial values from multiple external sources into one parse result, as a plugin for the tabnas parsing engine over the jsonic relaxed-JSON grammar.

A directive character (@ by default) marks a reference in the input. The plugin resolves the reference to a source, processes that source into a value, and splices the value into the output, recursively, so a loaded source can reference more sources.

use tabnas_multisource::{make_with, MapResolver, MultiSourceOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let sources = MapResolver::from([("a.jsonic", "a:1")]);
    let parser = make_with(MultiSourceOptions::new(sources));
    assert_eq!(parser.parse(r#"@"a.jsonic" b:2"#)?.to_string(), r#"{"a":1,"b":2}"#);
    Ok(())
}

TypeScript is canonical: ts/src/multisource.ts defines behaviour, option names and defaults. The shared fixtures in test/spec/*.tsv are the parity contract across TypeScript, Go and Rust. Differences are recorded in DIVERGENCE.md at the repository root.

§Untrusted input

Following @ references is this plugin’s whole job, which is exactly why the boundary matters. A reference reaches only what the configured Resolver can see, so the resolver is the sandbox:

  • MapResolver and a FileResolver over a MapFs touch no disk at all.
  • FileResolver::with_root confines every candidate path to one directory, so @"../../etc/passwd" resolves to nothing rather than to a file. The root and the candidate are both resolved through the filesystem before they are compared, so a symbolic link inside the root is judged by where it points; a link created between that check and the read is beyond what a resolver can see.
  • A cycle between sources raises multisource_cycle, and a chain longer than MultiSourceOptions::max_depth raises multisource_depth, so neither hangs nor overflows the stack.

A loaded value is still data, never instructions, and splicing is not sanitising: escaping for SQL, HTML or a shell remains the caller’s job.

Structs§

Dependency
One record that target tar pulled in source src during a parse.
DirEntry
One entry of a directory listing.
FileResolver
Resolve references against a filesystem.
MapFs
An in-memory filesystem: relative, slash-separated paths to content.
MapResolver
Resolve references against a map of path to content.
MultiSourceError
A registration failure: a host grammar without the rules the plugin modifies, a directive character already taken, or a grammar the engine refused.
MultiSourceOptions
Configuration for the plugin.
OsFs
The real filesystem, addressed by absolute native paths.
PathSpec
The path to a source, including the base prefix when there is one.
PkgResolver
Resolve references inside node_modules folders.
PreloadOptions
Which folders to scan, and for what.
ProcessorInput
What a Processor is given.
Resolution
A source and where it was found.
ResolverInput
What a Resolver is given: the plugin options and the parse metadata for the enclosing source.

Enums§

ProcessorEntry
How one source kind becomes a value.

Constants§

DEFAULT_MARKCHAR
The default directive character.
DEFAULT_MAX_DEPTH
How deep a chain of sources may nest before the parse is failed.
NONE
An unknown or missing source-reference extension.
PLUGIN_NAME
The plugin name, as the engine records it.
RULE_NAME
The rule and directive this plugin installs.
TOP
The top of the dependency tree: the DependencyMap target key used for sources referenced directly by the top-level parse.
VERSION
VERSION is this crate’s version. It MUST equal ts/package.json “version” and the version field in rs/Cargo.toml: the release orchestrator rewrites all of them, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/multisource.ts and const VERSION in go/multisource.go.

Traits§

Processor
Convert resolved source content into a value.
Resolver
Find the source content a reference names.
SourceFs
A read-only view of a filesystem.

Functions§

build_potentials
Every path a reference could name: the path itself, then the implicit extensions, then a folder index file, then a folder index file that repeats the folder name.
default_implicit_ext
The default implicit extensions.
default_processor
The fallback: the source text, as a string.
default_processors
The default processor table: raw text for an unknown kind, the strict JSON reader for json, and a re-parse with the live engine for jsonic and jsc.
ext_kind
The source kind: the extension of the LAST path segment, without the dot, or NONE when that segment has no dot.
json_processor
Read the source as standard JSON.
jsonic_processor
Re-parse the source with the live engine, so a nested reference is resolved by the same plugin and every plugin installed beside it.
make
A jsonic parser with the plugin installed over default options: no sources, so every reference raises multisource_not_found.
make_with
A jsonic parser with the plugin installed over options.
multisource
Install the plugin on parser.
os_fs
The real filesystem as a shared handle.
parse
Parse src with options.
parse_nested
Parse src as a source nested depth levels inside the document.
plugin
Build the plugin with default options: no sources, so every reference raises multisource_not_found.
plugin_with
Build the plugin for options.
preload_files
Scan the folders in options on the real filesystem, returning full path to content for every file matching one of the extensions.
preload_files_with
Scan the folders in options on filesystem.
resolve_path_spec
Normalize a reference into a PathSpec against base.
source_dir
The directory a relative reference inside path resolves against.

Type Aliases§

DependencyMap
A flattened dependency tree, keyed by target full path and then by source full path.
SharedFs
A shared filesystem handle.
SharedResolver
A shared resolver handle.