zap.ts

The zap.ts authoring API — the builder a config's default export receives.

A @fuzdev/zap config is a module whose default export is a (zap, ctx) => void | Promise<void>: it calls the ZapBuilder methods to declare the target, resources, and deploy block. The builder collects those declarations into the JSON the Rust engine parses against crates/zap_types/src/schema/ (mirrored by schema.ts); the builder shim injects each resource's type discriminant, so authors never write type.

Resource payload types are imported from schema.ts and re-exported here, so a config can pull everything it needs from one module.

import type {ZapBuilder, FileResource} from '@fuzdev/zap/zap.ts';
view source

Declarations
#

3 declarations

ZapBuilder
#

zap.ts view source

ZapBuilder import type {ZapBuilder} from '@fuzdev/zap/zap.js';

The builder a config declares against. Every method returns the builder for chaining; the resource methods take ResourceIdentity intersected with the kind-specific payload (the shim adds type).

target

Declare the zap.target({...}) machine descriptor (local or remote SSH).

type (config: TargetInput): ZapBuilder

config

returns ZapBuilder

deploy

Declare the zap.deploy({...}) release-management block zap deploy ships with.

type (config: DeploySpec): ZapBuilder

config

returns ZapBuilder

env

A reference to the operator environment variable name: the value is read from the environment of the machine zap runs on, when the field holding the reference is used — never while the config is evaluated, which has no environment.

The result is a string to place in a field that takes a reference — whole (host: zap.env('DEPLOY_HOST')), interpolated into a template literal, or concatenated (path: '/srv/' + zap.env('APP') + '/data'). It is opaque: it holds a marker, not the value, so slicing, splitting, case-changing, or encoding it leaves something that is no longer a reference: the config fails to evaluate when part of the marker survives, and otherwise the result is ordinary text. A field that takes no reference rejects one, naming the field. A recipe, which has no builder, calls env_ref from @fuzdev/zap/env_ref.ts for the same string.

type (name: string): string

name

the variable's name: a letter or _, then letters, digits, or _

type string
returns string

a marked string standing for the variable's value

throws

  • Error - if `name` is not an environment variable's name

mask

Declare env-var names secret: ones zap doesn't recognize by where they are used, their name, or the form of their value. Each is a variable's name — 'LICENSE_CODE', not zap.env('LICENSE_CODE') — and POSIX ([A-Za-z_][A-Za-z0-9_]*); anything else throws when called.

type (...vars: string[]): ZapBuilder

vars

type string[]
returns ZapBuilder

unmask

Declare env-var names not secret, where zap reads one as a secret by its name or the form of its value and it isn't. Each is a variable's name, POSIX ([A-Za-z_][A-Za-z0-9_]*); anything else throws when called. Unmasking a variable the config uses as a fetch credential (auth) is rejected when the config is read.

type (...vars: string[]): ZapBuilder

vars

type string[]
returns ZapBuilder

pkg

Declare a package resource — a system package via a package manager.

type (config: ResourceIdentity & PackageResource): ZapBuilder

config

returns ZapBuilder

apt_repo

Declare an apt_repo resource — a GPG key + sources list.

type (config: ResourceIdentity & AptRepoResource): ZapBuilder

config

returns ZapBuilder

script

Declare a script resource — an idempotent command (check / run).

type (config: ResourceIdentity & ScriptResource): ZapBuilder

config

returns ZapBuilder

installer

Declare an installer resource — software via a curl-piped script.

type (config: ResourceIdentity & InstallerResource): ZapBuilder

config

returns ZapBuilder

user

Declare a user resource — a Unix user (shell, home mode, SSH keys, sudoers).

type (config: ResourceIdentity & UserResource): ZapBuilder

config

returns ZapBuilder

directory

Declare a directory resource — a directory with managed permissions.

type (config: ResourceIdentity & DirectoryResource): ZapBuilder

config

returns ZapBuilder

file

Declare a file resource — a file with managed content.

type (config: ResourceIdentity & FileResource): ZapBuilder

config

returns ZapBuilder

link

Declare a link resource — a symbolic link.

type (config: ResourceIdentity & LinkResource): ZapBuilder

config

returns ZapBuilder

service

Declare a service resource — service lifecycle management.

type (config: ResourceIdentity & ServiceResource): ZapBuilder

config

returns ZapBuilder

database

Declare a database resource (PostgreSQL only).

type (config: ResourceIdentity & DatabaseResource): ZapBuilder

config

returns ZapBuilder

swap

Declare a swap resource — a swap file.

type (config: ResourceIdentity & SwapResource): ZapBuilder

config

returns ZapBuilder

firewall

Declare a firewall resource — firewall rules (ufw or nftables).

type (config: ResourceIdentity & FirewallResource): ZapBuilder

config

returns ZapBuilder

verify

Declare a verify resource — assertions checked at detection and again at its place in dependency order on a wetrun; one still failing there fails the run.

type (config: ResourceIdentity & VerifyResource): ZapBuilder

config

returns ZapBuilder

pipeline

Declare a pipeline resource — imperative multi-step execution.

type (config: ResourceIdentity & PipelineResource): ZapBuilder

config

returns ZapBuilder

build

Declare a build resource — fetch a verified source, build it, install to output.

type (config: ResourceIdentity & BuildResource): ZapBuilder

config

returns ZapBuilder

ZapConfigModule
#

zap.ts view source

ZapConfigModule import type {ZapConfigModule} from '@fuzdev/zap/zap.js';

The default-export signature of a zap.ts config — a pure (zap, ctx) function with no ambient authority. It may be async: zap waits for the promise, and a builder call made after it settles fails the evaluation, even when the config catches the error (a guard against a forgotten await).

(call)

type (zap: ZapBuilder, ctx: ZapContext): void | Promise<void>

zap

ctx

returns void | Promise<void>

ZapContext
#

zap.ts view source

ZapContext import type {ZapContext} from '@fuzdev/zap/zap.js';

Plan-time inputs to a config's default export. There are none, so it is empty: the same zap.ts always evals to the same declared state (the changeset built from it then depends on what detection finds on the target).

Re-exports
#

Depends on
#