@qrvey/enginex-resolvers
v0.0.1-1247-beta.1
Published
Builds connection definitions for `@qrvey/enginex` by reading the environment. The definition it returns is what you hand to `Enginex.create()` — which then exposes the read verbs (`query`, `count`, `storageExists`, `stream`, …). Depends on `@qrvey/engine
Downloads
62
Maintainers
Keywords
Readme
@qrvey/enginex-resolvers
Builds connection definitions for @qrvey/enginex by reading the environment. The definition
it returns is what you hand to Enginex.create() — which then exposes the read verbs
(query, count, storageExists, stream, …). Depends on @qrvey/enginex; never the reverse.
Usage
import { Enginex } from '@qrvey/enginex';
import { fromDefaultStorage } from '@qrvey/enginex-resolvers';
const db = await Enginex.create(fromDefaultStorage()); // the configured default storageTarget a specific storage, or let the default resolve:
import { fromStorage, fromDefaultStorage } from '@qrvey/enginex-resolvers';
fromStorage({ engine: 'clickhouse' });
fromStorage({ engine: 'elasticsearch' });
fromStorage({ engine: 'opensearch' });
fromDefaultStorage({ autoConnect: true });Internal env vars
fromStorage() / fromDefaultStorage() read engine-specific vars.
ClickHouse:
| Var | Meaning | Default |
| --------------------- | ---------- | ------------ |
| CLICKHOUSE_URL | server URL | required |
| CLICKHOUSE_USER | username | default |
| CLICKHOUSE_PASSWORD | password | (none) |
| CLICKHOUSE_DATABASE | database | default |
Elasticsearch / OpenSearch — same shape under a ELASTICSEARCH_* or OPENSEARCH_* prefix:
| Var | Meaning | Default |
| ------------------------ | ------------------------------------------ | ------------ |
| <PREFIX>_HOST | node URL | required |
| <PREFIX>_AUTH_USER | basic-auth username | (none) |
| <PREFIX>_AUTH_PASSWORD | basic-auth password | (none) |
| <PREFIX>_AUTH_TYPE | override: basic / aws_sigv4 / none | (inferred) |
| AWS_DEFAULT_REGION | AWS SigV4 region (when no basic auth) | us-east-1 |
The resolver returns the auth strategy as config.auth: taken from <PREFIX>_AUTH_TYPE when
set, otherwise inferred — basic when <PREFIX>_AUTH_USER/_AUTH_PASSWORD are present, else
AWS SigV4. Set <PREFIX>_AUTH_TYPE=none for an unauthenticated (local) node.
Passing auth
Set the env for the mode you want; fromStorage({ engine }) puts it on config.auth, and
the adapter builds the client accordingly:
# basic — inferred from user/pass (or set OPENSEARCH_AUTH_TYPE=basic)
OPENSEARCH_HOST=https://opensearch:9200
OPENSEARCH_AUTH_USER=app
OPENSEARCH_AUTH_PASSWORD=secret
# aws_sigv4 — inferred when no user/pass; region from AWS_DEFAULT_REGION
OPENSEARCH_HOST=https://my-domain.us-east-1.es.amazonaws.com
AWS_DEFAULT_REGION=us-east-1
# none — must be explicit (unauthenticated local node)
OPENSEARCH_HOST=http://localhost:9200
OPENSEARCH_AUTH_TYPE=none// e.g. with the aws_sigv4 env above
const def = fromStorage({ engine: 'opensearch' });
// → { source: 'internal', engine: 'opensearch',
// config: { url: '…', auth: 'aws_sigv4', region: 'us-east-1' }, … }fromDefaultStorage() picks the default storage: DEFAULT_STORAGE when set, otherwise
the single storage whose env vars are configured (it errors if none — or several — are
configured). Each engine has its own prefix (CLICKHOUSE_*, ELASTICSEARCH_*, OPENSEARCH_*).
Add an internal engine
- Add
src/env/read<Engine>Env.ts— read<ENGINE>_*and validate its required fields. - Add one entry to
INTERNAL_ENV_READERSininternalEngines.ts.
