~/bend-docscommunity

migrate.bend checks

raw source on the hub · import bend-kit-migrate@0.1.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

4 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
import bend-kit-encoding@0.4.0.0/encoding.bend as Encoding

Types

type Period source · line 7 · raw

Data

type Status source · line 11 · raw

Data

type V1 source · line 17 · raw

Data

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

type V2 source · line 21 · raw

Data

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

type V3 source · line 25 · raw

Data

v3: v2 without the support note.

type Record source · line 29 · raw

Data

A decoded record and the version it was written in.

type Terms source · line 35 · raw

Data

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

type Dropped source · line 39 · raw

Data

What v2 to v3 discards.

type Error source · line 42 · raw

Data

type Scalar source · line 170 · raw

Data

A JSON field value, reduced to what records use.

type Field source · line 199 · raw

Data

One object field: its decoded key and its value.

Definitions

def Status.of_active source · line 56 · raw

@a:Bool -> Status

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

def V1.terms source · line 63 · raw

@r:V1 -> Terms

def V2.terms source · line 67 · raw

@r:V2 -> Terms

def V3.terms source · line 71 · raw

@r:V3 -> Terms

def Record.terms source · line 75 · raw

@r:Record -> Terms

def Terms.cents source · line 84 · raw

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

def none source · line 87 · raw

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

def Terms.problem source · line 95 · raw

@t:Terms -> Maybe<&2, String>

The first business rule the terms break: an empty plan or a zero price.

def Terms.valid source · line 99 · raw

@t:Terms -> Bool

def Record.valid source · line 102 · raw

@r:Record -> Bool

def V1.up source · line 109 · raw

@r:V1 -> V2

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

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

@n:String -> @i:U32 -> @p:String -> @c:U32 -> @a:Bool -> Result<&2, &2, Error, V1>

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

@s:Status -> @i:U32 -> @p:String -> @c:U32 -> @n:String -> Result<&2, &2, Error, V1>

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

@pe:Period -> @i:U32 -> @p:String -> @c:U32 -> @s:Status -> @n:String -> Result<&2, &2, Error, V1>

def V2.down source · line 137 · raw

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

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

def V2.up source · line 142 · raw

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

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

def V3.restore source · line 147 · raw

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

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

def V3.down source · line 153 · raw

@r:V3 -> V2

v3 to v2, with an empty note.

def Record.upgrade source · line 157 · raw

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

Any version to v3, with what the chain dropped.

def scalar.num source · line 176 · raw

@m:Maybe<&2, U32> -> Scalar

def scalar source · line 183 · raw

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

def fields.of source · line 202 · raw

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

def fields.get source · line 209 · raw

@fs:List<&2, Field> -> @+k:String -> Maybe<&2, Scalar>

def fields.has source · line 216 · raw

@fs:List<&2, Field> -> @+k:String -> Bool

def has source · line 223 · raw

@xs:List<&2, String> -> @+k:String -> Bool

def fields.bad source · line 231 · raw

@fs:List<&2, Field> -> @+known:List<&2, String> -> Maybe<&2, Error>

The first key that the version does not define, or that repeats.

def only source · line 238 · raw

@m:Maybe<&2, Error> -> Result<&2, &2, Error, Unit>

def need.u32 source · line 245 · raw

@m:Maybe<&2, Scalar> -> @+f:String -> Result<&2, &2, Error, U32>

def need.flag source · line 254 · raw

@m:Maybe<&2, Scalar> -> @+f:String -> Result<&2, &2, Error, Bool>

def need.str source · line 263 · raw

@m:Maybe<&2, Scalar> -> @+f:String -> Result<&2, &2, Error, String>

def opt.str source · line 273 · raw

@m:Maybe<&2, Scalar> -> @d:String -> @+f:String -> Result<&2, &2, Error, String>

An optional string field: absent gives d.

def Period.of source · line 282 · raw

@+s:String -> Result<&2, &2, Error, Period>

def Status.of source · line 285 · raw

@+s:String -> Result<&2, &2, Error, Status>

def decode.v1 source · line 288 · raw

@+fs:List<&2, Field> -> Result<&2, &2, Error, Record>

def decode.v2 source · line 297 · raw

@+fs:List<&2, Field> -> Result<&2, &2, Error, Record>

def decode.v3 source · line 310 · raw

@+fs:List<&2, Field> -> Result<&2, &2, Error, Record>

def decode.at source · line 322 · raw

@+n:U32 -> @+fs:List<&2, Field> -> Result<&2, &2, Error, Record>

def decode.version source · line 333 · raw

@m:Maybe<&2, Scalar> -> @+fs:List<&2, Field> -> Result<&2, &2, Error, Record>

def decode.shape source · line 342 · raw

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

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

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

def Record.check source · line 358 · raw

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

r when its terms keep the business rules.

def decode.val source · line 363 · raw

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

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

def decode.parsed source · line 366 · raw

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

def decode source · line 374 · raw

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

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

def num source · line 380 · raw

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

def str source · line 383 · raw

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

def kv source · line 386 · raw

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

def Period.name source · line 389 · raw

@p:Period -> String

def Status.name source · line 396 · raw

@s:Status -> String

def V1.json source · line 405 · raw

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

def V2.json source · line 409 · raw

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

def V3.json source · line 413 · raw

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

def Record.json source · line 418 · raw

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

The record as a JSON object in its own version.

def encode source · line 427 · raw

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