~/bend-docscommunity

migrate.bend checks

raw source on the hub · import bend-kit-migrate@0.2.0.0/migrate.bend as Migrate

Versioned subscription records: validated JSON decode, proved migrations, and encode. Source: https://github.com/paymog/bend-kit/tree/main/migrate

3 imports
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
import bend-kit-json@0.6.1.1/json.bend as Json

Types

type Period source · line 6 · raw

Data

type Status source · line 10 · raw

Data

type V1 source · line 16 · raw

Type

v1: a monthly price and an on/off flag.

type V2 source · line 20 · raw

Type

v2: a price per billing period, a three-state status, and an optional support note.

type V3 source · line 24 · raw

Type

v3: v2 without the support note.

type Record source · line 28 · raw

Type

A decoded record and the version it was written in.

type Terms source · line 34 · raw

Type

What a subscription means to billing: who, which plan, the price per period, and the status.

type Dropped source · line 38 · raw

Type

What v2 to v3 discards.

type Key source · line 42 · raw

Data

The JSON field names of every version.

type Error source · line 53 · raw

Type

type Tag source · line 194 · raw

Data

A name of at most 16 bytes: its length and its first four little-endian words, zero past the end.

type Scalar source · line 349 · raw

Type

A JSON field value, reduced to what records use. A number keeps its digits until the record is built.

type Slots source · line 371 · raw

Type

Every field of a record object, by key, before the version picks which ones it allows.

Definitions

def Status.of_active source · line 68 · raw

@a:Bool -> Status

v1 had no pause: an inactive v1 subscription is cancelled.

def V1.terms source · line 75 · raw

@r:V1 -> Terms

def V2.terms source · line 79 · raw

@r:V2 -> Terms

def V3.terms source · line 83 · raw

@r:V3 -> Terms

def Record.terms source · line 87 · raw

@r:Record -> Terms

def Terms.problem source · line 97 · raw

@+len:U32 -> @+c:U32 -> Maybe<&2, Key>

The first business rule broken by a plan of len bytes and a price of c: an empty plan or a zero price.

def none source · line 100 · raw

@m:Maybe<&2, Key> -> Bool

def Terms.valid source · line 107 · raw

@t:Terms -> Bool

def Record.problem source · line 113 · raw

@r:Record -> Pair(Record, Maybe<&2, Key>)

The record back, and the first business rule it breaks.

def Record.valid.of source · line 122 · raw

@p:Pair(Record, Maybe<&2, Key>) -> Bool

def Record.valid source · line 126 · raw

@r:Record -> Bool

def V1.up source · line 133 · raw

@r:V1 -> V2

v1 to v2. Total; V2.down undoes it.

def V2.down.note source · line 137 · raw

@n:Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @i:U32 -> @p:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @c:U32 -> @a:Bool -> Result<&1, &1, Error, V1>

def V2.down.status source · line 144 · raw

@s:Status -> @i:U32 -> @p:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @c:U32 -> @n:Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Result<&1, &1, Error, V1>

def V2.down.period source · line 153 · raw

@pe:Period -> @i:U32 -> @p:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @c:U32 -> @s:Status -> @n:Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Result<&1, &1, Error, V1>

def V2.down source · line 161 · raw

@r:V2 -> Result<&1, &1, Error, V1>

v2 to v1, for a monthly record that is not paused and has no note.

def V2.up source · line 166 · raw

@r:V2 -> Pair(V3, Dropped)

v2 to v3. Lossy: it drops the note and returns it.

def V3.restore source · line 171 · raw

@r:V3 -> @d:Dropped -> V2

The v2 record that V2.up turned into r and d.

def V3.down source · line 177 · raw

@r:V3 -> V2

v3 to v2, with no note.

def Record.upgrade source · line 181 · raw

@r:Record -> Pair(V3, Dropped)

Any version to v3, with what the chain dropped.

def Tag.eq source · line 197 · raw

@a:Tag -> @b:Tag -> Bool

def Tag.word source · line 202 · raw

@ok:Bool -> @a:Array<U32> -> @+i:U32 -> Pair(Array<U32>, U32)

def Tag.of.w3 source · line 209 · raw

@+len:U32 -> @+w0:U32 -> @+w1:U32 -> @+w2:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag)

def Tag.of.w2 source · line 213 · raw

@+len:U32 -> @+n:U32 -> @+w0:U32 -> @+w1:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag)

def Tag.of.w1 source · line 217 · raw

@+len:U32 -> @+n:U32 -> @+w0:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag)

def Tag.of.w0 source · line 221 · raw

@+len:U32 -> @+n:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag)

def Tag.of source · line 226 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag)

The bytes back, and their tag. Bytes past 16 are not read, but the length still differs.

def Tag.set source · line 231 · raw

@ok:Bool -> @a:Array<U32> -> @+i:U32 -> @+w:U32 -> Array<U32>

def Tag.bytes source · line 238 · raw

@t:Tag -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

def Key.tag source · line 243 · raw

@k:Key -> Tag

def Key.bytes source · line 265 · raw

@k:Key -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

The key as UTF-8 JSON text.

def Key.is source · line 268 · raw

@k:Key -> @+t:Tag -> @rest:Maybe<&2, Key> -> Maybe<&2, Key>

def Key.find source · line 272 · raw

@+t:Tag -> Maybe<&2, Key>

def Period.tag source · line 275 · raw

@p:Period -> Tag

def Status.tag source · line 282 · raw

@s:Status -> Tag

def Period.find source · line 291 · raw

@+t:Tag -> Maybe<&2, Period>

def Status.find source · line 294 · raw

@+t:Tag -> Maybe<&2, Status>

def u32.over source · line 300 · raw

@+acc:U32 -> @+d:U32 -> Bool

def u32.end source · line 303 · raw

@ok:Bool -> @+acc:U32 -> Maybe<&2, U32>

def u32.go source · line 310 · raw

@n:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> @+acc:U32 -> @ok:Bool -> Maybe<&2, U32>

def u32.first source · line 319 · raw

@+len:U32 -> @r:Pair(Array<U32>, U32) -> Maybe<&2, U32>

def u32.read source · line 325 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Maybe<&2, U32>

Decimal digits with no sign, fraction, exponent, or leading zero, below 2^32.

def u32.width source · line 329 · raw

@+n:U32 -> U32

def u32.fill source · line 332 · raw

@f:Nat -> @a:Array<U32> -> @+i:U32 -> @+n:U32 -> Array<U32>

def u32.text source · line 341 · raw

@+n:U32 -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

n in decimal digits.

def scalar source · line 355 · raw

@v:0x040b6c79c72da50288552227f006b061/json.Val -> Scalar

def Slots.empty source · line 374 · raw

Slots

def slot.fill source · line 377 · raw

@m:Maybe<&1, Scalar> -> @x:Scalar -> @k:Key -> Result<&1, &1, Error, Maybe<&1, Scalar>>

def Slots.set source · line 384 · raw

@k:Key -> @x:Scalar -> @s:Slots -> Result<&1, &1, Error, Slots>

def Slots.put source · line 414 · raw

@m:Maybe<&2, Key> -> @k:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @x:Scalar -> @s:Slots -> Result<&1, &1, Error, Slots>

def Slots.key source · line 421 · raw

@p:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag) -> @x:Scalar -> @s:Slots -> Result<&1, &1, Error, Slots>

def collect.put source · line 425 · raw

@acc:Result<&1, &1, Error, Slots> -> @k:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @v:0x040b6c79c72da50288552227f006b061/json.Val -> Result<&1, &1, Error, Slots>

def collect source · line 433 · raw

@kvs:List<&1, Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x040b6c79c72da50288552227f006b061/json.Val)> -> @acc:Result<&1, &1, Error, Slots> -> Result<&1, &1, Error, Slots>

Files each field under its key. An unknown or repeated key stops the walk.

def need.num source · line 440 · raw

@m:Maybe<&1, Scalar> -> @k:Key -> Result<&1, &1, Error, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>

def need.flag source · line 449 · raw

@m:Maybe<&1, Scalar> -> @k:Key -> Result<&1, &1, Error, Bool>

def need.str source · line 458 · raw

@m:Maybe<&1, Scalar> -> @k:Key -> Result<&1, &1, Error, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>

def opt.str source · line 467 · raw

@m:Maybe<&1, Scalar> -> @k:Key -> Result<&1, &1, Error, Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>>

def unexpected source · line 477 · raw

@m:Maybe<&1, Scalar> -> @k:Key -> Result<&1, &1, Error, Unit>

A field that this version does not define.

def found source · line 484 · raw

@-A:Data -> @m:Maybe<&2, A> -> @k:Key -> Result<&1, &1, Error, A>

def name.period source · line 491 · raw

@p:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag) -> Result<&1, &1, Error, Period>

def name.status source · line 495 · raw

@p:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Tag) -> Result<&1, &1, Error, Status>

def need.period source · line 499 · raw

@m:Maybe<&1, Scalar> -> Result<&1, &1, Error, Period>

def opt.period source · line 509 · raw

@m:Maybe<&1, Scalar> -> Result<&1, &1, Error, Period>

An absent v2 period is monthly.

def need.status source · line 518 · raw

@m:Maybe<&1, Scalar> -> Result<&1, &1, Error, Status>

def V1.finish source · line 527 · raw

@mi:Maybe<&2, U32> -> @p:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @mc:Maybe<&2, U32> -> @a:Bool -> Result<&1, &1, Error, Record>

def build.v1 source · line 533 · raw

@s:Slots -> Result<&1, &1, Error, Record>

def V2.finish source · line 546 · raw

@mi:Maybe<&2, U32> -> @p:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @mc:Maybe<&2, U32> -> @pe:Period -> @s:Status -> @n:Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Result<&1, &1, Error, Record>

def build.v2 source · line 552 · raw

@s:Slots -> Result<&1, &1, Error, Record>

def V3.finish source · line 565 · raw

@mi:Maybe<&2, U32> -> @p:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @mc:Maybe<&2, U32> -> @pe:Period -> @s:Status -> Result<&1, &1, Error, Record>

def build.v3 source · line 571 · raw

@s:Slots -> Result<&1, &1, Error, Record>

def build.at source · line 584 · raw

@+v:U32 -> @s:Slots -> Result<&1, &1, Error, Record>

def build.ver source · line 595 · raw

@m:Maybe<&2, U32> -> @s:Slots -> Result<&1, &1, Error, Record>

def build.raw source · line 602 · raw

@r:Result<&1, &1, Error, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @s:Slots -> Result<&1, &1, Error, Record>

def build source · line 609 · raw

@s:Slots -> Result<&1, &1, Error, Record>

def decode.shape source · line 614 · raw

@v:0x040b6c79c72da50288552227f006b061/json.Val -> Result<&1, &1, Error, Record>

The record an object describes, before the business rules.

def Record.check.if source · line 621 · raw

@m:Maybe<&2, Key> -> @r:Record -> Result<&1, &1, Error, Record>

def Record.check.of source · line 628 · raw

@p:Pair(Record, Maybe<&2, Key>) -> Result<&1, &1, Error, Record>

def Record.check source · line 633 · raw

@r:Record -> Result<&1, &1, Error, Record>

r when it keeps the business rules.

def decode.val source · line 637 · raw

@v:0x040b6c79c72da50288552227f006b061/json.Val -> Result<&1, &1, Error, Record>

One record from a parsed JSON value. Only a valid record decodes.

def decode.parsed source · line 640 · raw

@m:Maybe<&1, 0x040b6c79c72da50288552227f006b061/json.Val> -> Result<&1, &1, Error, Record>

def decode source · line 648 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Result<&1, &1, Error, Record>

One record from UTF-8 JSON: an object nested no deeper than one level.

def kv source · line 654 · raw

@k:Key -> @v:0x040b6c79c72da50288552227f006b061/json.Val -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x040b6c79c72da50288552227f006b061/json.Val)

def num source · line 657 · raw

@+n:U32 -> 0x040b6c79c72da50288552227f006b061/json.Val

def Period.json source · line 660 · raw

@p:Period -> 0x040b6c79c72da50288552227f006b061/json.Val

def Status.json source · line 663 · raw

@s:Status -> 0x040b6c79c72da50288552227f006b061/json.Val

def V1.json source · line 666 · raw

@r:V1 -> 0x040b6c79c72da50288552227f006b061/json.Val

def V2.note source · line 670 · raw

@n:Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> List<&1, Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x040b6c79c72da50288552227f006b061/json.Val)>

def V2.json source · line 677 · raw

@r:V2 -> 0x040b6c79c72da50288552227f006b061/json.Val

def V3.json source · line 681 · raw

@r:V3 -> 0x040b6c79c72da50288552227f006b061/json.Val

def Record.json source · line 686 · raw

@r:Record -> 0x040b6c79c72da50288552227f006b061/json.Val

The record as a JSON object in its own version.

def encode source · line 695 · raw

@r:Record -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes