Explorer

core.value-conforms

description
Whether the value (core.value) has the shape of the type part declaration (the expression of a type part). References to type parts are looked up in declarations; unknown ones accept any value. The server checks the shape of submitted events with this. See docs/event.md
type
Fn(
  value: @core.value,
  declaration: @core.expression,
  declarations: List<@core.type-declaration-entry>
) -> Boolean
expression
fn(value$0, declaration$1, declarations$2) =>
  match $1 {
    #type_number(_) =>
      match $0 {
        #number(v$10) =>
          true,
        _ =>
          false
      },
    #type_float(_) =>
      match $0 {
        #float(v$10) =>
          true,
        _ =>
          false
      },
    #type_string(_) =>
      match $0 {
        #string(v$10) =>
          true,
        _ =>
          false
      },
    #type_boolean(_) =>
      match $0 {
        #boolean(v$10) =>
          true,
        _ =>
          false
      },
    #type_list(list_type$3) =>
      match $0 {
        #list(items$11) =>
          @core.value-list-items-conform(items: $11, item_type: $3.item_type, declarations: $2, index: 0),
        _ =>
          false
      },
    #type_record(declared$4) =>
      match $0 {
        #record(fields$12) =>
          @core.and(
            left: @core.value-record-keys-declared(fields: $12, declared: $4, index: 0),
            right: @core.value-record-fields-conform(fields: $12, declared: $4, declarations: $2, index: 0)
          ),
        _ =>
          false
      },
    #type_union(variants$5) =>
      match $0 {
        #variant(variant$13) =>
          match @core.declared-variant-find(variants: $5, tag: $13.tag, index: 0) {
            #none(_) =>
              false,
            #some(declared_variant$14) =>
              match $14.payload_type {
                #none(_) =>
                  match $13.payload {
                    #unit(_) =>
                      true,
                    _ =>
                      false
                  },
                #some(payload_type$15) =>
                  @core.value-conforms(value: $13.payload, declaration: $15, declarations: $2)
              }
          },
        _ =>
          false
      },
    #part_reference(reference$6) =>
      match @core.type-declaration-find(declarations: $2, id: $6.part_definition_event_hash, index: 0) {
        #none(_) =>
          true,
        #some(found$16) =>
          @core.value-conforms(value: $0, declaration: $16, declarations: $2)
      },
    _ =>
      true
  }
visibility
public
core.value-conforms (project definy, branch main, snapshot CfIAXM725tR74SWd4aoTUz4-JJQfqnllblZbQ2Sv204)
id: 3FyZ-GbY60sCoyg648OA-l131lVzIxO69Q4MCYaDo4s
content hash: rCMu2OJVTYQhf1Hu5SyIub2A6eLGW1rE164BczefYGk