Hierarchy

  • DataPowers

Index

Methods

Methods

Static delete

  • delete(keyOrFilename: string, options?: DeleteOptions): Promise<boolean>
  • Delete data based on type and scope in options.

    throws

    {TypeError} when keyOrFilename is missing.

    example

    Deleting Skill or Organization scope file or JSON store data from within a skill code

    // Ensure you import DataPowers
    import { DataPowers, DataScope, DataTypes } from "@andi/powers";
    await DataPowers.delete("keyName", { type: DataType.File });
    await DataPowers.delete("keyName", { scope: DataScope.Organization });

    Parameters

    • keyOrFilename: string

      Name of key for JSON store or filename for file store.

    • Optional options: DeleteOptions

      DeleteOptions.

    Returns Promise<boolean>

Static get

  • get<T>(keyOrFilename: string, options?: GetOptions): Promise<T>
  • Retrieve data based on type and scope in options. Defaults to DataType.Json and DataScope.Skill.

    throws

    {TypeError} when keyOrFilename is missing.

    remarks

    Retrieving data for DataType.Json will not maintain order of keys within JSON objects (and arrays).

    example

    Getting different types of data from within your skill code

    // Ensure you import DataPowers
    import { DataPowers, DataScope, CsvParseOptions } from "@andi/powers";
    
    const key = "my-key-name-here";
    // getting a number
    const counter = await DataPowers.get<number>(key);
    // getting a complex object from different `scope`
    const obj = await DataPowers.get<any>(key, { scope: DataScope.Organization });
    // getting a text file data
    const textData = await DataPowers.get<string>("my-text-file.txt", { type: DataType.File, parseOptions: "text" });
    // getting raw buffer from a file
    const buf = await DataPowers.get<Buffer>("sample-file.txt", { type: DataType.File, scope: DataScope.Organization, parseOptions: "buffer" });
    // getting csv rows
    type MyRow = {
        id: string;
        city: string;
        zip: string;
    };
    const csvParseOptions: CsvParseOptions = { delimiter: ","};
    const csvRows = await DataPowers.get<MyRow[]>("my-test.csv", { type: DataType.File, parseOptions: csvParseOptions });

    Type parameters

    • T = unknown

    Parameters

    • keyOrFilename: string

      Name of key for JSON store or filename for file store.

    • Optional options: GetOptions

      GetOptions.

    Returns Promise<T>

Static search

  • search<T>(keyOrFilename: string, options: SearchOptions): Promise<T[]>
  • Search data based on type and scope in options.

    throws

    {TypeError} when keyOrFilename is missing.

    throws

    {TypeError} when searchOptions is missing.

    remarks

    No guarantee of order of keys within JSON objects (and arrays).

    example

    Searching data rows from within a skill code

    // Ensure you import DataPowers
    import { DataPowers, Condition, Operator } from "@andi/powers";
    
    // searching data rows - exampleRows below shows how your csv data will represent in JavaScript
    const exampleRows = [{rateType: "floating", rate: 10, region: "FL"}, {rateType: "fixed", rate: 12, region: "FL"}, {rateType: "floating", rate: 11, region: "NC"}];
    const condition: Condition = { key: "region", operator: Operator.Equals, value: "FL" };
    const searchOptions: SearchOptions = { where: condition, select: ["rateType", "rate"]};
    const results = await DataPowers.search<any>("my-test.csv", searchOptions);
    // your results array will look like [{rateType: "floating", rate: 10}, {rateType: "fixed", rate: 12}]

    Type parameters

    • T = unknown

    Parameters

    • keyOrFilename: string

      Filename.

    • options: SearchOptions

      SearchOptions.

    Returns Promise<T[]>

    • T[]. Empty array when no search match is found.

Static set

  • set<T>(keyOrFilename: string, value: T, options?: SaveOptions): Promise<boolean>
  • Sets data based on type and scope in options. Defaults to DataType.Json and DataScope.Skill.

    throws

    {TypeError} when keyOrFilename is missing.

    throws

    {TypeError} when value is missing.

    throws

    {RangeError} when value is greater than 256 KB for DataType.Json or 1 MB for DataType.File.

    example

    Setting different types of data from within a skill code

    // Ensure you import DataPowers
    import { DataPowers, DataScope, DataType } from "@andi/powers";
    
    const key = "my-key-name-here";
    // setting a number
    await DataPowers.set<number>(key, 10);
    // setting a complex object
    const obj = { a: "test", b: 1, c: true};
    await DataPowers.set<any>(key, obj, { scope: DataScope.Organization });
    // setting a text file data
    const textData = await DataPowers.set<string>("my-text-file.txt", "sample test here", { scope: DataScope.Skill, type: DataType.File });
    // setting raw buffer in a file
    await DataPowers.set<Buffer>("sample-file.txt", Buffer.from("sample test"), { scope: DataScope.Skill, type: DataType.File});

    Type parameters

    • T = unknown

    Parameters

    • keyOrFilename: string

      Name of key for JSON store or filename for file store.

    • value: T
    • Optional options: SaveOptions

      SaveOptions.

    Returns Promise<boolean>

Generated using TypeDoc