@metreeca/blue - v0.9.1
    Preparing search index...

    Function resource

    Creates resource shapes.

    • Creates a resource shape from property definitions.

      Accepts Entry values including full Property definitions, naked Range values for concise syntax, and Id/Type markers:

      • name: required(string()) is equivalent to name: property(required(string()))

      Type Parameters

      • E extends { readonly [property: string]: Entry }

        The entries record type

      Parameters

      • entries: E

        The property definitions

      Returns ResourceShape & { model: Composition<E> }

      A shape for validating resources with the specified properties

      const Person = resource({
      name: required(string()), // naked range
      age: property(optional(integer())) // full property
      });
    • Creates a resource shape with constraints.

      When constraints includes extends, the returned shape type includes inherited properties from the parent shape(s). Otherwise, the shape type includes only the own properties.

      Accepts Entry values including full Property definitions, naked Range values for concise syntax, and Id/Type markers.

      Warning

      When inheriting from multiple shapes, namespaces are inconsistent if some parents define a namespace while others don't, or if parents define different namespace IRIs. In such cases, an overriding namespace must be declared.

      Type Parameters

      • const C extends ResourceConstraints

        The constraints type (used to infer inheritance)

      • E extends { readonly [property: string]: Entry }

        The entries record type

      Parameters

      • constraints: C & {
            validators?: readonly Validator<
                {
                    readonly [K in string
                    | number
                    | symbol as Projection<K & string>]: Content<E[K]>
                } & {
                    readonly [K in string
                    | number
                    | symbol as Projection<K & string>]?: Exclude<
                        Content<(...)[(...)]>,
                        undefined,
                    >
                } & Inheritance<C>,
            >[];
        }

        Shape constraints including namespace, name, validators, and optionally extends

      • entries: E & Overrides<E, Inheritance<C>>

        The property definitions

      Returns ResourceShape & {
          model: {
              readonly [K in string | number | symbol as Projection<K & string>]: Content<
                  E[K],
              >
          } & {
              readonly [K in string
              | number
              | symbol as Projection<K & string>]?: Exclude<Content<E[K]>, undefined>
          } & Inheritance<C>;
      }

      A shape for validating resources, including inherited properties if extends is specified

      If namespace is not a function

      If multiple parents have inconsistent namespaces and no overriding namespace is declared

      // without inheritance
      const Person = resource({ namespace: schema }, {
      name: required(string()) // naked range
      });

      // with inheritance
      const Employee = resource({ extends: Person }, {
      department: required(string()) // naked range
      });