Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace ResourceProcessors

Index

Type aliases

Type aliases

All

All: <N>(collectionName: N, document: graphql.DocumentNode) => Process<Resource<N>[]>

resources.all

Retrieves full or partial representations of all known resources for a given collection name. Parameter document is a GraphQL DocumentNode that defines a fragment on the resource object type, to control which fields are returned.

Note: This function returns a generator. For async behavior, use with a ProcessorRunner such as that returned by Run.forDb or Project.run.

example
import gql from "graphql-tag";
import { connect, Resources, Process } from "@truffle/db";

const db = connect({
  // ...
});

const { Run, resources } = Process;

const { run } = Run.forDb(db);

const sources: Pick<
  Resources.Resource<"sources">,
  "contents"
>[] = await run(resources.all, "sources", gql`
  fragment Contents on Source {
    contents
  }
`);

Type declaration

    • <N>(collectionName: N, document: graphql.DocumentNode): Process<Resource<N>[]>
    • Type parameters

      Parameters

      • collectionName: N
      • document: graphql.DocumentNode

      Returns Process<Resource<N>[]>

Find

Find: <N>(collectionName: N, ids: (string | undefined)[], document: graphql.DocumentNode) => Process<(Resource<N> | undefined)[]>

resources.find

Retrieves full or partial representations of all resources in a list of given IDs. Parameter document is a GraphQL DocumentNode that defines a fragment on the resource object type, to control which fields are returned.

The resulting array will always have the same length as the provided IDs, with each result corresponding to the ID at the same index. Unknown IDs will have null entries in the resulting array.

Note: This function returns a generator. For async behavior, use with a ProcessorRunner such as that returned by Run.forDb or Project.run.

example
import gql from "graphql-tag";
import { connect, Process } from "@truffle/db";

const db = connect({
  // ...
});

const { Run, resources } = Process;

const { run } = Run.forDb(db);

const sources: (
 | Pick<Resources.Resource<"sources">, "contents">
 | null
)[] = await run(resources.find, "sources", ["0x...", "0x..."], gql`
  fragment Contents on Source {
    contents
  }
`);

Type declaration

    • <N>(collectionName: N, ids: (string | undefined)[], document: graphql.DocumentNode): Process<(Resource<N> | undefined)[]>
    • Type parameters

      Parameters

      • collectionName: N
      • ids: (string | undefined)[]
      • document: graphql.DocumentNode

      Returns Process<(Resource<N> | undefined)[]>

Get

Get: <N>(collectionName: N, id: string, document: graphql.DocumentNode) => Process<Resource<N> | undefined>

resources.get

Retrieves full or partial representations of a resource given its ID. Parameter document is a GraphQL DocumentNode that defines a fragment on the resource object type, to control which fields are returned.

Note: This function returns a generator. For async behavior, use with a ProcessorRunner such as that returned by Run.forDb or Project.run.

example
import gql from "graphql-tag";
import { connect, Process } from "@truffle/db";

const db = connect({
  // ...
});

const { Run, resources } = Process;

const { run } = Run.forDb(db);

const { contents } = await run(resources.get, "sources", "0x...", gql`
  fragment Contents on Source {
    contents
  }
`);

Type declaration

    • <N>(collectionName: N, id: string, document: graphql.DocumentNode): Process<Resource<N> | undefined>
    • Type parameters

      Parameters

      • collectionName: N
      • id: string
      • document: graphql.DocumentNode

      Returns Process<Resource<N> | undefined>

Load

Load: <N>(collectionName: N, inputs: (Input<N> | undefined)[]) => Process<(IdObject<N> | undefined)[]>

resources.load

Loads resource inputs and processes into corresponding IdObjects.

The resulting array will always have the same length as the inputs, with each result corresponding to the input at the same index. Invalid inputs correspond to null resource results.

Note: This function returns a generator. For async behavior, use with a ProcessorRunner such as that returned by Run.forDb or Project.run.

example
import { connect, Resources, Process } from "@truffle/db";

const db = connect({
  // ...
});

const { Run, resources } = Process;

const { run } = Run.forDb(db);

const sources: (
  | Resources.IdObject<"sources">
  | null
)[] = await run(resources.load, "sources", [
  { sourcePath: "...", contents: "..." }
]);

Type declaration

    • <N>(collectionName: N, inputs: (Input<N> | undefined)[]): Process<(IdObject<N> | undefined)[]>
    • Type parameters

      Parameters

      • collectionName: N
      • inputs: (Input<N> | undefined)[]

      Returns Process<(IdObject<N> | undefined)[]>

Generated using TypeDoc