@servicenow/sdk - v4.7.0
    Preparing search index...

    Type Alias PluginConfig<Nodes, Shapes, Records>

    type PluginConfig<
        Nodes extends SupportedKindName[] = SupportedKindName[],
        Shapes extends ShapeClass[] = ShapeClass[],
        Records extends string[] = string[],
    > = {
        docs?: any[];
        files?: {
            entryPoint?: boolean;
            matcher?: RegExp | FileMatcher;
            toRecord?(
                file: File,
                context: Context,
            ): Result<Record> | Promise<Result<Record>>;
        }[];
        name: `${string}Plugin`;
        nodes?: {
            [I in keyof Nodes]: {
                entryPoint?: boolean;
                fileTypes?: FileType[];
                node: Nodes[I];
                toShape?(
                    node: SupportedNodeByKindName<Nodes[I]>,
                    context: Context,
                ): Result<Shape<unknown>> | Promise<Result<Shape<unknown>>>;
            }
        };
        records?: {
            [T in Records[number]]: {
                coalesce?: CoalesceStrategy;
                composite?: boolean;
                diff?: (
                    existing: Database,
                    incoming: Database,
                    descendants: Database,
                    context: Context,
                ) => Promise<Result<Database>>;
                relationships?: Relationships;
                getUpdateName?(
                    record: Record,
                    context: Context,
                ): Result<string> | Promise<Result<string>>;
                toFile?(
                    record: Record,
                    context: RecordContext,
                ):
                    | Result<OutputFile | OutputFile[]>
                    | Promise<Result<OutputFile | OutputFile[]>>;
                toShape?(
                    record: Record,
                    context: RecordContext,
                ): Result<Shape<unknown>> | Promise<Result<Shape<unknown>>>;
            }
        };
        shapes?: {
            [I in keyof Shapes]: Shapes[I] extends ShapeClass<infer S>
                ? {
                    fileTypes?: FileType[];
                    shape: Shapes[I];
                    commit?(
                        shape: S,
                        target: Node,
                        context: CommitContext,
                    ): CommitResult | Promise<CommitResult>;
                    getTarget?(
                        shape: S,
                        context: Context,
                    ): Result<Node<tsc.Node>> | Promise<Result<Node<tsc.Node>>>;
                    inspect?(shape: S, context: Context): void;
                    toRecord?(
                        shape: S,
                        context: Context,
                    ): Result<Record> | Promise<Result<Record>>;
                    toSubclass?(shape: S, context: Context): Result<S> | Promise<Result<S>>;
                }
                : never
        };
    }

    Type Parameters

    Index

    Properties

    docs?: any[]

    This property is no longer read and will be removed in a future release.

    files?: {
        entryPoint?: boolean;
        matcher?: RegExp | FileMatcher;
        toRecord?(
            file: File,
            context: Context,
        ): Result<Record> | Promise<Result<Record>>;
    }[]

    The files this plugin handles. Plugins that do not introduce new file types should not need to implement anything here.

    Type Declaration

    • OptionalentryPoint?: boolean

      Indicates whether this file should be parsed as an entry point when generating output. (Default: false)

    • Optionalmatcher?: RegExp | FileMatcher

      A regex pattern or predicate to apply to a file's path to determine if it should be handled by this plugin.

    • toRecord?: function
      • Transforms a file into record(s).

        Parameters

        • file: File

          The file to transform

        • context: Context

          Context object with useful services and information

        Returns Result<Record> | Promise<Result<Record>>

        A result indicating whether the transformation was successful and, if so, the resulting record(s)

    name: `${string}Plugin`

    The name of the plugin. Must end with "Plugin" suffix. This name is used in metrics and error messages.

    nodes?: {
        [I in keyof Nodes]: {
            entryPoint?: boolean;
            fileTypes?: FileType[];
            node: Nodes[I];
            toShape?(
                node: SupportedNodeByKindName<Nodes[I]>,
                context: Context,
            ): Result<Shape<unknown>> | Promise<Result<Shape<unknown>>>;
        }
    }

    The TypeScript AST nodes this plugin handles. Plugins that do not introduce new syntax should not need to define any handlers here.

    records?: {
        [T in Records[number]]: {
            coalesce?: CoalesceStrategy;
            composite?: boolean;
            diff?: (
                existing: Database,
                incoming: Database,
                descendants: Database,
                context: Context,
            ) => Promise<Result<Database>>;
            relationships?: Relationships;
            getUpdateName?(
                record: Record,
                context: Context,
            ): Result<string> | Promise<Result<string>>;
            toFile?(
                record: Record,
                context: RecordContext,
            ):
                | Result<OutputFile | OutputFile[]>
                | Promise<Result<OutputFile | OutputFile[]>>;
            toShape?(
                record: Record,
                context: RecordContext,
            ): Result<Shape<unknown>> | Promise<Result<Shape<unknown>>>;
        }
    }

    The records this plugin handles. The keys of this object are the names of the tables to be handled, and the values are handlers which can implement the following:

    • Transform functions that turn records into shapes (toShape)
    • Transform functions that turn records into files (toFile)
    • Relationship mappings
    • Coalesce strategies
    shapes?: {
        [I in keyof Shapes]: Shapes[I] extends ShapeClass<infer S>
            ? {
                fileTypes?: FileType[];
                shape: Shapes[I];
                commit?(
                    shape: S,
                    target: Node,
                    context: CommitContext,
                ): CommitResult | Promise<CommitResult>;
                getTarget?(
                    shape: S,
                    context: Context,
                ): Result<Node<tsc.Node>> | Promise<Result<Node<tsc.Node>>>;
                inspect?(shape: S, context: Context): void;
                toRecord?(
                    shape: S,
                    context: Context,
                ): Result<Record> | Promise<Result<Record>>;
                toSubclass?(shape: S, context: Context): Result<S> | Promise<Result<S>>;
            }
            : never
    }

    The shapes this plugin handles. Each shape handler can implement the following:

    • Transform functions that turn shapes into records (toRecord)
    • Transform functions that turn shapes into more specialized subclasses of those shapes (toSubclass)
    • Commit functions that mutate TypeScript nodes to match shapes (commit)
    • Inspect functions that can examine shapes for diagnostic purposes (inspect)