WRDWritableSchema | WebHare Platform SDK
WebHare Platform SDK
    Preparing search index...

    Interface WRDWritableSchema<S>

    A WRD schema opened for metadata changes (creating types, updating attributes etc). Obtain one using wrd(tag, { writeMetadata: true }). These objects are never shared with other wrd() callers

    interface WRDWritableSchema<S extends SchemaTypeDefinition = AnySchemaType> {
        tag: string;
        __clearCache(): void;
        __ensureSchemaData(
            __namedParameters?: { refresh?: boolean },
        ): Promise<SchemaData>;
        __getTypeTag(type: number): Promise<string | null>;
        __getWRDSchema(): Promise<HSVMObject>;
        __reloadAfterMetadataChange(): Promise<void>;
        __toWRDTypeId(tag: string | undefined): Promise<number>;
        "[getWRDSchemaType]"(
            type: string,
            allowMissingType: true,
        ): Promise<HSVMObject | null>;
        "[getWRDSchemaType]"(
            type: string,
            allowMissingType: false,
        ): Promise<HSVMObject>;
        close<T extends string>(
            type: T,
            ids: number | number[],
            options?: EntityCloseOptions,
        ): Promise<void>;
        createType(
            tag: string,
            config: Partial<WRDTypeMetadata> & Pick<WRDTypeMetadata, "metaType">,
        ): Promise<WRDWritableType<S, string>>;
        delete<T extends string>(type: T, ids: number | number[]): Promise<void>;
        describeType(tagOrId: string | number): Promise<WRDTypeMetadata | null>;
        enrich<
            T extends string,
            EnrichKey extends string,
            DataRow extends { [K in string]: number | null },
            Mapping extends EnrichOutputMap<S[T]>,
            RightOuterJoin extends boolean = false,
        >(
            type: T,
            data: DataRow[],
            field: EnrichKey,
            mapping: Mapping,
            options?: {
                allowMissing?: RightOuterJoin;
                historyMode?: HistoryModeData | SimpleHistoryMode;
                rightOuterJoin?: RightOuterJoin;
            },
        ): WRDEnrichResult<S, T, EnrichKey, DataRow, Mapping, RightOuterJoin>;
        exists(): Promise<boolean>;
        extendWith<T extends SchemaTypeDefinition>(): WRDSchema<
            CombineSchemas<S, T>,
        >;
        find<T extends string>(
            type: T,
            query: MatchObjectQueryable<S[T]>,
            options?: { historyMode?: HistoryModeData | SimpleHistoryMode },
        ): Promise<number | null>;
        getEventMasks(
            type: keyof S & string | (keyof S & string)[],
        ): Promise<string[]>;
        getFields<
            M extends
                string
                | { [K: string]: OutputMap<S[T]> }
                | readonly AttrRef<S[T]>[],
            T extends string,
        >(
            type: T,
            id: WRDEntityMatch<WRDSchemaType<S>, T>,
            mapping: M,
            options: GetFieldsOptions & { allowMissing: true; export: true },
        ): Promise<
            MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, true>
            | null,
        >;
        getFields<
            M extends
                string
                | { [K: string]: OutputMap<S[T]> }
                | readonly AttrRef<S[T]>[],
            T extends string,
        >(
            type: T,
            id: WRDEntityMatch<WRDSchemaType<S>, T>,
            mapping: M,
            options: GetFieldsOptions & { allowMissing: true; export?: false },
        ): Promise<
            MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, false>
            | null,
        >;
        getFields<
            M extends
                string
                | { [K: string]: OutputMap<S[T]> }
                | readonly AttrRef<S[T]>[],
            T extends string,
        >(
            type: T,
            id: WRDEntityMatch<WRDSchemaType<S>, T>,
            mapping: M,
            options: GetFieldsOptions & { export: true },
        ): Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, true>>;
        getFields<
            M extends
                string
                | { [K: string]: OutputMap<S[T]> }
                | readonly AttrRef<S[T]>[],
            T extends string,
        >(
            type: T,
            id: WRDEntityMatch<WRDSchemaType<S>, T>,
            mapping: M,
            options: GetFieldsOptions & { export?: false },
        ): Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, false>>;
        getFields<
            M extends
                string
                | { [K: string]: OutputMap<S[T]> }
                | readonly AttrRef<S[T]>[],
            T extends string,
        >(
            type: T,
            id: WRDEntityMatch<WRDSchemaType<S>, T>,
            mapping: M,
        ): Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, false>>;
        getFields<
            M extends
                string
                | { [K: string]: OutputMap<S[T]> }
                | readonly AttrRef<S[T]>[],
            T extends string,
            Export extends boolean,
        >(
            type: T,
            id: WRDEntityMatch<WRDSchemaType<S>, T>,
            mapping: M,
            options?: GetFieldsOptions,
        ): Promise<
            MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, Export>
            | null,
        >;
        getId(opts: { allowMissing: true }): Promise<number | null>;
        getId(opts?: { allowMissing?: boolean }): Promise<number>;
        getNextGuid<T extends string>(type: T): string;
        getNextId<T extends string>(type: T): Promise<number>;
        getType<T extends string>(type: T): WRDWritableType<S, T>;
        hasType(tag: string): Promise<boolean>;
        insert<T extends string>(
            type: T,
            value: Partial<WRDInsertable<S[T]>>,
            options: { importMode?: boolean; temp: true },
        ): Promise<number>;
        insert<T extends string>(
            type: T,
            value: Partial<WRDInsertable<S[T]>>,
            options: { importMode: true; temp?: boolean },
        ): Promise<number>;
        insert<T extends string>(
            type: T,
            value: Simplify<
                {
                    [K in string
                    | number
                    | symbol as ToWRDAttr<S[T][K]>["__insertable"] extends true
                        ? false extends ToWRDAttr<S[T][K]>["__required"] ? K : never
                        : never]?: GetInputType<S[T][K]>
                } & {
                    [K in string
                    | number
                    | symbol as InsertableAndRequired<ToWRDAttr<S[T][K]>> extends true
                        ? K
                        : never]: GetInputType<S[T][K]>
                },
            >,
            options?: { importMode?: boolean; temp?: boolean },
        ): Promise<number>;
        listTypes(): Promise<
            IteratorObject<
                {
                    id: number;
                    metaType: "object"
                    | "link"
                    | "domain"
                    | "attachment";
                    tag: string;
                },
                undefined,
                unknown,
            >,
        >;
        modify<T extends string>(type: T): WRDModificationBuilder<S, T>;
        query<T extends string>(type: T): WRDSingleQueryBuilder<S, T, null>;
        search<T extends string, F extends string>(
            type: T,
            field: F,
            value: WhereValueOptions<S[T], F, WhereConditions<S[T], F> & "=">["value"],
            options?: GetOptionsIfExists<
                WhereValueOptions<S[T], F, WhereConditions<S[T], F> & "=">,
                object,
            > & { historyMode?: HistoryModeData | SimpleHistoryMode },
        ): Promise<number | null>;
        update<T extends string>(
            type: T,
            entity: WRDEntityMatch<WRDSchemaType<S>, T>,
            value: WRDUpdatable<S[T]>,
            options?: { importMode?: boolean },
        ): Promise<void>;
        updateSchema(updates: SchemaUpdates): Promise<void>;
        upsert<T extends string, Q extends object, U extends object>(
            type: T,
            query: Q & Pick<WRDUpdatable<S[T]>, keyof S[T] & keyof WRDUpdatable<S[T]>> & MatchObjectQueryable<
                S[T],
            > & Record<
                Exclude<keyof Q, keyof S[T] | keyof S[T] & keyof WRDUpdatable<S[T]>>,
                never,
            >,
            value: U & WRDUpdatable<S[T]> & Record<
                Exclude<keyof U, keyof WRDUpdatable<S[T]>>,
                never,
            >,
            ...options: UpsertOptions<
                Omit<
                    Simplify<
                        {
                            [K in string
                            | number
                            | symbol as ToWRDAttr<S[T][K]>["__insertable"] extends true
                                ? false extends ToWRDAttr<(...)[(...)][K]>["__required"]
                                    ? K
                                    : never
                                : never]?: GetInputType<S[T][K]>
                        } & {
                            [K in string
                            | number
                            | symbol as InsertableAndRequired<ToWRDAttr<S[T][K]>> extends true
                                ? K
                                : never]: GetInputType<S[T][K]>
                        },
                    >,
                    RequiredKeys<Q>
                    | RequiredKeys<U>,
                >,
                { historyMode?: HistoryModeData | SimpleHistoryMode },
            >,
        ): Promise<[number, boolean]>;
    }

    Type Parameters

    Hierarchy (View Summary)

    Index

    Properties

    tag: string

    Methods

    • Parameters

      • __namedParameters: { refresh?: boolean } = {}

      Returns Promise<SchemaData>

    • Parameters

      • type: number

      Returns Promise<string | null>

    • Reload our schema data after a metadata change, and immediately invalidate the cached data of other schema objects in this process referring to the same schema (they would otherwise only be invalidated after commit)

      Returns Promise<void>

    • Parameters

      • tag: string | undefined

      Returns Promise<number>

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • ids: number | number[]
      • Optionaloptions: EntityCloseOptions

      Returns Promise<void>

    • Parameters

      • tag: string
      • config: Partial<WRDTypeMetadata> & Pick<WRDTypeMetadata, "metaType">

      Returns Promise<WRDWritableType<S, string>>

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • ids: number | number[]

      Returns Promise<void>

    • Describe a wrdType

      Parameters

      • tagOrId: string | number

        Either the string tag or the type number to describe

      Returns Promise<WRDTypeMetadata | null>

    • Type Parameters

      • T extends string
      • EnrichKey extends string
      • DataRow extends { [K in string]: number | null }
      • Mapping extends EnrichOutputMap<S[T]>
      • RightOuterJoin extends boolean = false

      Parameters

      • type: T
      • data: DataRow[]
      • field: EnrichKey
      • mapping: Mapping
      • options: {
            allowMissing?: RightOuterJoin;
            historyMode?: HistoryModeData | SimpleHistoryMode;
            rightOuterJoin?: RightOuterJoin;
        } = {}
        • OptionalallowMissing?: RightOuterJoin

          Keep original data records even if no match was found

        • OptionalhistoryMode?: HistoryModeData | SimpleHistoryMode

          History mode for matching enriching records

        • OptionalrightOuterJoin?: RightOuterJoin

          With the modern wrd() API you should switch to allowMissing: true

      Returns WRDEnrichResult<S, T, EnrichKey, DataRow, Mapping, RightOuterJoin>

    • Test whether this schema actually exists in the database

      Returns Promise<boolean>

    • Type Parameters

      • T extends SchemaTypeDefinition

      Returns WRDSchema<CombineSchemas<S, T>>

    • Returns the wrdId of the entity that matches the properties of the query object.

      Type Parameters

      • T extends string

      Parameters

      • type: T

        Type to search in

      • query: MatchObjectQueryable<S[T]>

        Query object (field-value pairs)

      • Optionaloptions: { historyMode?: HistoryModeData | SimpleHistoryMode }

        Options for the search

      Returns Promise<number | null>

    • Parameters

      • type: keyof S & string | (keyof S & string)[]

      Returns Promise<string[]>

    • Type Parameters

      • M extends string | { [K: string]: OutputMap<S[T]> } | readonly AttrRef<S[T]>[]
      • T extends string

      Parameters

      Returns Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, true> | null>

    • Type Parameters

      • M extends string | { [K: string]: OutputMap<S[T]> } | readonly AttrRef<S[T]>[]
      • T extends string

      Parameters

      Returns Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, false> | null>

    • Type Parameters

      • M extends string | { [K: string]: OutputMap<S[T]> } | readonly AttrRef<S[T]>[]
      • T extends string

      Parameters

      Returns Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, true>>

    • Type Parameters

      • M extends string | { [K: string]: OutputMap<S[T]> } | readonly AttrRef<S[T]>[]
      • T extends string

      Parameters

      Returns Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, false>>

    • Type Parameters

      • M extends string | { [K: string]: OutputMap<S[T]> } | readonly AttrRef<S[T]>[]
      • T extends string

      Parameters

      Returns Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, false>>

    • Type Parameters

      • M extends string | { [K: string]: OutputMap<S[T]> } | readonly AttrRef<S[T]>[]
      • T extends string
      • Export extends boolean

      Parameters

      Returns Promise<MapRecordOutputMap<S[T], RecordizeOutputMap<S[T], M>, Export> | null>

    • Parameters

      • opts: { allowMissing: true }

      Returns Promise<number | null>

    • Parameters

      • Optionalopts: { allowMissing?: boolean }

      Returns Promise<number>

    • Reserve a wrdGuid

      Type Parameters

      • T extends string

      Parameters

      • type: T

      Returns string

    • Reserve a wrdId

      Type Parameters

      • T extends string

      Parameters

      • type: T

      Returns Promise<number>

    • Test whether a type exists in this schema

      Parameters

      • tag: string

      Returns Promise<boolean>

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • value: Partial<WRDInsertable<S[T]>>
      • options: { importMode?: boolean; temp: true }

      Returns Promise<number>

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • value: Partial<WRDInsertable<S[T]>>
      • options: { importMode: true; temp?: boolean }

      Returns Promise<number>

    • Type Parameters

      • T extends string

      Parameters

      • type: T
      • value: Simplify<
            {
                [K in string
                | number
                | symbol as ToWRDAttr<S[T][K]>["__insertable"] extends true
                    ? false extends ToWRDAttr<S[T][K]>["__required"] ? K : never
                    : never]?: GetInputType<S[T][K]>
            } & {
                [K in string
                | number
                | symbol as InsertableAndRequired<ToWRDAttr<S[T][K]>> extends true
                    ? K
                    : never]: GetInputType<S[T][K]>
            },
        >
      • Optionaloptions: { importMode?: boolean; temp?: boolean }

      Returns Promise<number>

    • Returns Promise<
          IteratorObject<
              {
                  id: number;
                  metaType: "object"
                  | "link"
                  | "domain"
                  | "attachment";
                  tag: string;
              },
              undefined,
              unknown,
          >,
      >

    • Type Parameters

      • T extends string

      Parameters

      • type: T

      Returns WRDModificationBuilder<S, T>

    • Type Parameters

      • T extends string

      Parameters

      • type: T

      Returns WRDSingleQueryBuilder<S, T, null>

    • Returns the wrdId of an entity that has a field with a specific value, or null if not found.

      Type Parameters

      • T extends string
      • F extends string

      Parameters

      • type: T
      • field: F

        Field to filter on

      • value: WhereValueOptions<S[T], F, WhereConditions<S[T], F> & "=">["value"]

        Value to match (using condition "=")

      • Optionaloptions: GetOptionsIfExists<
            WhereValueOptions<S[T], F, WhereConditions<S[T], F> & "=">,
            object,
        > & { historyMode?: HistoryModeData | SimpleHistoryMode }

        Additional options for the filter

      Returns Promise<number | null>

      /// Returns the wrdId of an entity with the first name "John" (or null if no such entity exists)
      const result = await schema.search("wrdPerson", "wrdFirstName", "John");
    • Updates fields of a specific entity

      Type Parameters

      • T extends string

      Parameters

      • type: T
      • entity: WRDEntityMatch<WRDSchemaType<S>, T>

        wrdId of the entity to update, or a query object to find the entity (throws if none or multiple entities match the query)

      • value: WRDUpdatable<S[T]>

        Value to match (using condition "=")

      • Optionaloptions: { importMode?: boolean }

        Additional options for the filter

      Returns Promise<void>

      /// Returns the wrdId of an entity with the first name "John" (or null if no such entity exists)
      const result = await schema.search("wrdPerson", "wrdFirstName", "John");
    • Parameters

      • updates: SchemaUpdates

      Returns Promise<void>

    • Insert an entity, or update if it exists

      Type Parameters

      • T extends string
      • Q extends object
      • U extends object

      Parameters

      • type: T
      • query: Q & Pick<WRDUpdatable<S[T]>, keyof S[T] & keyof WRDUpdatable<S[T]>> & MatchObjectQueryable<
            S[T],
        > & Record<
            Exclude<keyof Q, keyof S[T] | keyof S[T] & keyof WRDUpdatable<S[T]>>,
            never,
        >
      • value: U & WRDUpdatable<S[T]> & Record<
            Exclude<keyof U, keyof WRDUpdatable<S[T]>>,
            never,
        >
      • ...options: UpsertOptions<
            Omit<
                Simplify<
                    {
                        [K in string
                        | number
                        | symbol as ToWRDAttr<S[T][K]>["__insertable"] extends true
                            ? false extends ToWRDAttr<(...)[(...)][K]>["__required"] ? K : never
                            : never]?: GetInputType<S[T][K]>
                    } & {
                        [K in string
                        | number
                        | symbol as InsertableAndRequired<ToWRDAttr<S[T][K]>> extends true
                            ? K
                            : never]: GetInputType<S[T][K]>
                    },
                >,
                RequiredKeys<Q>
                | RequiredKeys<U>,
            >,
            { historyMode?: HistoryModeData | SimpleHistoryMode },
        >

      Returns Promise<[number, boolean]>