跳到主要内容

std/versioned

std/versioned

导入自 @norbital-ai/std/versioned

std/versioned (§3.7, §6.3 "Versioned lineage", PH GAP-4): pure helpers over the rows of the lineage recipe (period, sealed_at, voided_at, void_reason, sealed-only noOverlap). A sealed version never changes except for a shortened period (its successor was sealed) or one void with a reason; a correction is a new draft built by cloneNext and sealed over the old version. The seal's write is held by the collection's update grant (§3.8).

Lineage type

type Lineage = {
    readonly id: string;
    readonly period: DatePeriod;
    readonly sealed_at?: Instant | string | null;
    readonly voided_at?: Instant | string | null;
    readonly void_reason?: string | null;
};

The columns of a versioned row these helpers read.

成员

名称类型说明
idstring
periodDatePeriod
sealed_at?Instant | string | null
voided_at?Instant | string | null
void_reason?string | null

源码: packages/std/src/versioned.ts:9

cloneNext function

function cloneNext<V extends Lineage, R extends Rows = {}>(version: V, from: PlainDate | string, children?: R): Omit<V, Carried> & { period: DatePeriod; } & { [K in keyof R]: { create: Omit<R[K][number], "id" | "revision">[]; }; }

The create input of the successor draft: the version's own values (as the caller selected them) from from, open, unsealed, with each relation's rows as explicit nested creates.

参数

名称类型说明
versionV
  • id: string
  • period: DatePeriod
  • sealed_at?: Instant | string | null
  • voided_at?: Instant | string | null
  • void_reason?: string | null
fromPlainDate | string
children?R

源码: packages/std/src/versioned.ts:133

onlyShortens function

function onlyShortens(before: Lineage, input: Input): string | null

For a sealed version's update: null when every change is an earlier end of its period (or a void, which voidOnce judges), else the refusal. Nested relation writes (its lines) are changes, so they are refused too.

参数

名称类型说明
beforeLineage
  • id: string
  • period: DatePeriod
  • sealed_at?: Instant | string | null
  • voided_at?: Instant | string | null
  • void_reason?: string | null
inputInput

源码: packages/std/src/versioned.ts:84

sealWrites function

function sealWrites<V extends Lineage>(draft: V, sealed: readonly V[], now: Instant | string): { target: V["id"]; set: { period: DatePeriod; sealed_at?: Instant | string; }; }[]

The one update list (X-24) that seals draft: the sealed version it follows ends the day before it starts, and the draft ends the day before the next sealed version, so the sealed-only noOverlap holds in the one statement.

参数

名称类型说明
draftV
  • id: string
  • period: DatePeriod
  • sealed_at?: Instant | string | null
  • voided_at?: Instant | string | null
  • void_reason?: string | null
sealedreadonly V[]
nowInstant | string

源码: packages/std/src/versioned.ts:42

voidOnce function

function voidOnce(before: Lineage, input: Input): string | null

For a sealed version's update: one void, with a reason, never undone or reworded; null when admitted.

参数

名称类型说明
beforeLineage
  • id: string
  • period: DatePeriod
  • sealed_at?: Instant | string | null
  • voided_at?: Instant | string | null
  • void_reason?: string | null
inputInput

源码: packages/std/src/versioned.ts:107