Provider Comparison
Normalize environment variables, a local file, an HTTP response, and a seeded S3 object into one shared output schema.
Source
examples/provider-comparison/input.yaml
id: file-001
label: File Snapshot
owner: docs-team
examples/provider-comparison/main.rank
/// Normalizes environment, file, HTTP, and S3 inputs into one schema.
/// Shows multiple input surfaces converging on one output bundle.
use aws::{ S3 }
use std::Emit
use std::Env
use std::File
use std::HTTP
use std::Path
use std::collections::{ length, map }
SourceRecord = Object {
id: string,
label: string,
owner: string,
}
NormalizedRecord = Object {
source: `env` | `file` | `http` | `s3`,
id: string,
label: string,
owner: string,
}
ArticleAuthor = Object {
id: string,
name: string,
avatar: string,
email: string,
}
Article = Object {
slug: string,
title: string,
subtitle: string,
image: string,
author: ArticleAuthor,
dateCreated: string,
content: string,
}
SysEnv = Object {
PRODUCT_ID?: string,
PRODUCT_LABEL?: string,
PRODUCT_OWNER?: string,
S3_ENDPOINT?: string,
...: string,
}
{ PRODUCT_ID, PRODUCT_LABEL, PRODUCT_OWNER, S3_ENDPOINT } = Env<SysEnv> {}
env_record: NormalizedRecord = {
source: `env`,
id: PRODUCT_ID ?? `env-001`,
label: PRODUCT_LABEL ?? `Environment Snapshot`,
owner: PRODUCT_OWNER ?? `platform-runtime`,
}
file_result = File::Read<SourceRecord> {
path: Path::join([`input.yaml`]),
format: `yaml`,
}
file_record: NormalizedRecord = {
source: `file`,
id: file_result.body.id,
label: file_result.body.label,
owner: file_result.body.owner,
}
http_result = HTTP::Fetch<Article> {
url: `https://lorem-api.com/api/article/rank-http-fetch`,
method: `GET`,
headers: {
Accept: `application/json`,
},
cacheKey: `provider-comparison-rank-http-fetch-v1`,
}
http_record: NormalizedRecord = {
source: `http`,
id: http_result.body.slug,
label: http_result.body.title,
owner: http_result.body.author.email,
}
s3_endpoint = S3_ENDPOINT ?? `http://127.0.0.1:4566`
s3_client: aws::S3::ClientConfig = S3::createClient({
region: `us-east-1`,
endpoint: s3_endpoint,
credentials: {
accessKeyId: `test`,
secretAccessKey: `test`,
},
})
s3_result: aws::S3::ObjectResult<SourceRecord> = aws::S3::Object<SourceRecord> {
client: s3_client,
bucket: `rank-provider-comparison`,
key: `profiles/source.json`,
}
s3_record: NormalizedRecord = {
source: `s3`,
id: s3_result.object.id,
label: s3_result.object.label,
owner: s3_result.object.owner,
}
records: [NormalizedRecord] = [env_record, file_record, http_record, s3_record]
summary = {
totalSources: length(records),
sources: records |> map(|record: NormalizedRecord| record.source),
}
pub main = || Emit::manifest({
entries: [
{
path: Path::join([`comparison`, `normalized.json`]),
format: `json`,
value: records,
},
{
path: Path::join([`comparison`, `summary.yaml`]),
format: `yaml`,
value: summary,
},
]
})
Output
totalSources: 4
sources:
- env
- file
- http
- s3
Run it
Start LocalStack from the example directory:
cd examples/provider-comparison
docker compose up
Then run the Rank program from the workspace root:
npm run rank -- examples/provider-comparison --file-root out/provider-comparison
Optionally override the environment-backed record:
PRODUCT_LABEL="Env Override" npm run rank -- examples/provider-comparison --file-root out/provider-comparison
Key concepts
Env,File::Read,HTTP::Fetch, andaws::S3::Object<T>can all normalize into one shared schema.- The S3 input stays local and reproducible by seeding LocalStack in
docker-compose.yml. - A single emitted bundle makes cross-provider comparisons straightforward to inspect.