Skip to documentation
SLOP

tiny.zen.SiteCatalogStorage

Reference tiny.zen SiteCatalogStorage

Defined in tiny.zen.

API (21)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.zenSiteCatalogStorage
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/zen/src/site/catalog/storage.zig:19

zig
pub const Storage = struct {    phase: alloc_phase.capacity.Phase,    capacity: capacity_mod.Capacity,    bytes: []align(capacity_mod.storage_alignment) u8,    entries: []model.Entry,    text: []u8,    pages: usize = 0,    text_bytes: usize = 0,    rejected_entry_count: u64 = 0,    sealed: bool = false,    pub const Limits: type = capacity_mod.Limits;    pub const Capacity: type = capacity_mod.Capacity;    pub const Exhaustion: type = model.Exhaustion;    pub const InitError = std.mem.Allocator.Error || capacity_mod.DeriveError;    pub const AppendError: type = model.Error;    pub const claim: alloc_phase.capacity.Declaration = .{        .source = .{            .id = "zen.site_catalog_storage",            .kind = .phase_static,            .limit_source = .caller,            .storage = .{                .covered = &.{                    .{                        .id = "retained_site_catalog_entry_descriptors",                        .lifetime = .steady,                        .detail = "retained site catalog entry descriptors",                    },                    .{                        .id = "retained_path_url_title_and_date_bytes",                        .lifetime = .steady,                        .detail = "retained path, URL, title, and date bytes",                    },                },                .excluded = &.{                    "caller-owned limits, source paths, Markdown page bytes, and frontmatter scratch",                    "filesystem walkers, rendered pages, theme output, page-list expansion, and assets",                },            },            .capacity = .{                .inputs = &.{                    alloc_phase.capacity.bindInput(Limits, "max_pages", "max_pages"),                    alloc_phase.capacity.bindInput(Limits, "max_text_bytes", "max_text_bytes"),                },                .type_selectors = &.{                    alloc_phase.capacity.bindType(model.Entry, "entry"),                },                .nodes = &.{                    .{ .input = 0 },                    .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 } } },                    .{ .alignment = .{ .node = 1, .alignment = .{ .literal = 16 } } },                    .{ .input = 1 },                    .{ .add = .{ .left = 2, .right = 3 } },                },                .assertions = &.{.{                    .scope = .closure_total,                    .measure = .retained,                    .relation = .exact,                    .expression = 4,                }},            },            .overload = .{                .kind = .reject_before_mutation,                .detail = "entry demand rejects before mutation; rejection telemetry advances",            },            .risks = .{                .transitive = .{                    .status = .witnessed,                    .detail = "append, sort, and borrow use only exact preacquired storage",                },                .foreign = .{                    .status = .excluded,                    .detail = "directory walks and page reads are excluded site-build effects",                },            },            .obligations = &.{                .{ .key = "zen_site_catalog_capacity", .role = .capacity_model },                .{ .key = "zen_site_catalog_acquisition", .role = .custom },                .{ .key = "zen_site_catalog_oom", .role = .custom },                .{ .key = "zen_site_catalog_boundaries", .role = .overload },                .{ .key = "zen_site_catalog_atomic_rejection", .role = .overload },                .{ .key = "zen_site_catalog_sealed", .role = .transitive_risk },                .{ .key = "zen_site_catalog_root", .role = .custom },                .{ .key = "zen_site_catalog_consumer", .role = .foreign_risk },            },        },        .bindings = .{            .owner = @This(),            .seal = .{                .family = alloc_phase.capacity.selector(@This().activate),                .premise = .{                    .class = .checked_semantic_fact,                    .authority = .checker,                },            },            .teardown = .{                .family = alloc_phase.capacity.selector(@This().deinit),                .premise = .{                    .class = .checked_semantic_fact,                    .authority = .checker,                },            },        },    };    pub fn init(allocator: std.mem.Allocator, limits: Limits) InitError!Storage {        const capacity = try Capacity.derive(limits);        const bytes = try allocator.alignedAlloc(            u8,            .fromByteUnits(capacity_mod.storage_alignment),            capacity.storage_bytes,        );        std.debug.assert(bytes.len == capacity.storage_bytes);        const storage = Storage{            .phase = .initialization,            .capacity = capacity,            .bytes = bytes,            .entries = typedSlice(model.Entry, bytes, capacity.entries_offset, limits.max_pages),            .text = bytes[capacity.text_offset..][0..limits.max_text_bytes],        };        storage.assertStorage();        std.debug.assert(storage.pages == 0);        std.debug.assert(storage.text_bytes == 0);        return storage;    }    pub fn activate(self: *Storage) void {        std.debug.assert(self.phase == .initialization);        std.debug.assert(!self.sealed);        std.debug.assert(self.pages == 0);        std.debug.assert(self.text_bytes == 0);        self.assertStorage();        self.phase = .steady;    }    pub fn append(self: *Storage, input: model.EntryInput) AppendError!*const model.Entry {        std.debug.assert(self.phase == .steady);        std.debug.assert(!self.sealed);        std.debug.assert(self.pages <= self.entries.len);        std.debug.assert(self.text_bytes <= self.text.len);        const demand = plan_mod.Demand.fromInput(input);        const demand_bytes = demand.textBytes() catch |err| return self.reject(err);        std.debug.assert(demand_bytes >= input.relative_path.len);        const next_pages = std.math.add(usize, self.pages, 1) catch            return self.reject(error.CapacityOverflow);        if (next_pages > self.entries.len) {            return self.reject(error.SiteCatalogPageCapacityExceeded);        }        const next_text = std.math.add(usize, self.text_bytes, demand_bytes) catch            return self.reject(error.CapacityOverflow);        if (next_text > self.text.len) {            return self.reject(error.SiteCatalogTextCapacityExceeded);        }        var cursor = self.text_bytes;        const relative_path = self.appendText(&cursor, input.relative_path);        const url = self.appendText(&cursor, input.url);        const title = self.appendText(&cursor, input.title);        const date = self.appendText(&cursor, input.date);        const type_label = self.appendText(&cursor, input.type_label);        std.debug.assert(cursor == next_text);        self.entries[self.pages] = .{            .relative_path = relative_path,            .url = url,            .title = title,            .date = date,            .section = model.section(relative_path),            .type_label = type_label,            .dispatch = input.dispatch,            .draft = input.draft,            .slop = input.slop,        };        self.pages = next_pages;        self.text_bytes = next_text;        self.assertStorage();        const entry = &self.entries[self.pages - 1];        std.debug.assert(entry.relative_path.len == input.relative_path.len);        std.debug.assert(entry.url.len == input.url.len);        std.debug.assert(entry.title.len == input.title.len);        std.debug.assert(entry.date.len == input.date.len);        std.debug.assert(entry.type_label.len == input.type_label.len);        std.debug.assert(entry.dispatch == input.dispatch);        return entry;    }    pub fn seal(self: *Storage, base: []const u8) model.Catalog {        std.debug.assert(self.phase == .steady);        std.debug.assert(!self.sealed);        std.mem.sort(model.Entry, self.entries[0..self.pages], {}, model.lessThan);        self.sealed = true;        self.assertStorage();        for (self.entries[0..self.pages], 0..) |entry, index| {            if (index != 0) {                std.debug.assert(!model.lessThan({}, entry, self.entries[index - 1]));            }        }        return .{ .base = base, .pages = self.entries[0..self.pages] };    }    pub fn status(self: *const Storage) Status {        return .{            .phase = self.phase,            .sealed = self.sealed,            .storage_bytes = self.capacity.storage_bytes,            .max_pages = self.capacity.limits.max_pages,            .max_text_bytes = self.capacity.limits.max_text_bytes,            .pages = self.pages,            .text_bytes = self.text_bytes,            .rejected_entry_count = self.rejected_entry_count,        };    }    pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void {        std.debug.assert(self.phase != .teardown);        self.assertStorage();        self.phase = .teardown;        allocator.free(self.bytes);        self.bytes = &.{};        self.entries = &.{};        self.text = &.{};        self.pages = 0;        self.text_bytes = 0;    }    fn appendText(self: *Storage, cursor: *usize, source: []const u8) []const u8 {        std.debug.assert(cursor.* <= self.text.len);        std.debug.assert(source.len <= self.text.len - cursor.*);        const start = cursor.*;        @memcpy(self.text[start..][0..source.len], source);        cursor.* += source.len;        return self.text[start..cursor.*];    }    fn reject(self: *Storage, err: model.Error) model.Error {        std.debug.assert(self.phase == .steady);        std.debug.assert(!self.sealed);        self.assertStorage();        self.rejected_entry_count +|= 1;        return err;    }    fn assertStorage(self: *const Storage) void {        std.debug.assert(self.bytes.len == self.capacity.storage_bytes);        std.debug.assert(self.entries.len == self.capacity.limits.max_pages);        std.debug.assert(self.text.len == self.capacity.limits.max_text_bytes);        std.debug.assert(self.pages <= self.entries.len);        std.debug.assert(self.text_bytes <= self.text.len);        std.debug.assert(@intFromPtr(self.bytes.ptr) % capacity_mod.storage_alignment == 0);        if (self.sealed) std.debug.assert(self.phase == .steady);    }};

Source: lib/zen/src/root.zig:288

zig
/// Append-only storage whose `seal` result borrows its sorted entries and text.pub const SiteCatalogStorage = site_catalog.Storage;
Called byCallstest sourcelib.zen.src.site.catalog.storagetest: site catalog storage acquires o...private sourcelib.zen.src.site.catalog.storage.StorageassertStorageSiteCatalogStorageactivate
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersprivate sourcelib.zen.src.site.catalog.modelsectionprivate sourcelib.zen.src.site.catalog.storage.StorageappendTextprivate sourcelib.zen.src.site.catalog.storage.StorageassertStorageprivate sourcelib.zen.src.site.catalog.storage.StoragerejectSiteCatalogStorageappend
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsprivate sourcelib.zen.src.site.catalog.storagecheckInitFailurestest sourcelib.zen.src.site.catalog.storagetest: site catalog storage acquires o...private sourcelib.zen.src.site.catalog.storage.StorageassertStorageSiteCatalogStoragedeinit
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsprivate sourcelib.zen.src.site.catalog.storagecheckInitFailurestest sourcelib.zen.src.site.catalog.storagetest: site catalog storage acquires o...private sourcelib.zen.src.site.catalog.storagetypedSliceSiteCatalogStorageinit
Static calls · unresolved targets: 1 · external targets: 2.
Called byCallstest sourcelib.zen.src.site.catalog.testtest: site catalog seals an empty sta...private sourcelib.zen.src.site.catalog.modellessThanprivate sourcelib.zen.src.site.catalog.storage.StorageassertStorageSiteCatalogStorageseal
Static calls · unresolved targets: 0 · external targets: 0.

Also reachable as

site.catalog.Storage.

Audit

Definitions13
Public names26
Members9
Version26.7.0
Revisiondaab053ee433