# Class Project

Abstraction for connecting @truffle/db to a Truffle project

This class affords an interface between Truffle and @truffle/db, specifically for the purposes of ingesting @truffle/workflow-compile results and contract instance information from @truffle/contract-schema artifact files.

Unless you are building tools that work with Truffle's various packages directly, you probably don't need to use this class.

#### Example

To instantiate this abstraction:

    import { connect, Project } from "@truffle/db";

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

    const project = await Project.initialize({
      db,
      project: {
        directory: "/path/to/project/dir"
      }
    });

#### Hierarchy

- Project
  - ConnectedProject

- Defined in packages/db/src/project/index.ts:76

#####
Index

### Constructor

connect

### Truffle-specific

loadCompile

### Other

id
assignNames

### Processor

run

## Constructor

### connect

- connect(options): ConnectedProject

- Accept a provider to enable workflows that require communicating with the underlying blockchain network.

  #### Parameters

  - ##### options: {
    provider: Provider;
    }

    - ##### provider: Provider

  #### Returns ConnectedProject

  - Defined in packages/db/src/project/index.ts:163

## Truffle-specific

### loadCompile

- loadCompile(options): Promise<{
  compilations: Project.LoadCompile.Compilation[];
  contracts: Project.LoadCompile.Contract[];
  }>

- Accept a compilation result and process it to save all relevant resources ([[DataModel.Source | Source]], [[DataModel.Bytecode | Bytecode]], [[DataModel.Compilation | Compilation]], [[DataModel.Contract | Contract]])

  This returns the same WorkflowCompileResult but with additional references to each of the added resources.

  #### Parameters

  - ##### options: {
    result: WorkflowCompileResult;
    }

    - ##### result: WorkflowCompileResult

  #### Returns Promise<{
  compilations: Project.LoadCompile.Compilation[];
  contracts: Project.LoadCompile.Contract[];
  }>

  - Defined in packages/db/src/project/index.ts:92

## Other

### id

- get id(): string

- #### Returns string

  - Defined in packages/db/src/project/index.ts:77

### assignNames

- assignNames<N>(options): Promise<{
  assignments: {
  [K in Resources.NamedCollectionName]: Resources.IdObject<"nameRecords">[]
  };
  }>

- Update name pointers for this project. Currently affords name-keeping for [[DataModel.Network | Network]] and [[DataModel.Contract | Contract]] resources (e.g., naming [[DataModel.ContractInstance | ContractInstance]] resources is not supported directly)

  This saves [[DataModel.NameRecord | NameRecord]] and [[DataModel.ProjectName | ProjectName]] resources to @truffle/db.

  Returns a list of NameRecord resources for completeness, although these may be regarded as an internal concern. ProjectName resources are not returned because they are mutable; returned representations would be impermanent.

  #### Type Parameters

  - #### N extends Resources.NamedCollectionName

    Either `"contracts"`, `"networks"`, or `"contracts" | "networks"`.

  #### Parameters

  - ##### options: {
    assignments: {
    [K in Resources.NamedCollectionName]: Resources.IdObject<K>[]
    };
    }

    - ##### assignments: {
      [K in Resources.NamedCollectionName]: Resources.IdObject<K>[]
      }

      Object whose keys belong to the set of named collection names and whose values are [[IdObject | IdObjects]] for resources of that collection.

  #### Returns Promise<{
  assignments: {
  [K in Resources.NamedCollectionName]: Resources.IdObject<"nameRecords">[]
  };
  }>

  #### Example

      await project.assignNames({
        assignments: {
          contracts: [
            { id: "<contract1-id>" },
            { id: "<contract2-id>" },
            // ...
          }
        }
      });

  - Defined in packages/db/src/project/index.ts:135

## Processor

### run

- run<A, T, R>(processor, ...args): Promise<T>

- Run a given [[Process.Processor | Processor]] with specified arguments.

  This method is a [[Meta.Process.ProcessorRunner | ProcessorRunner]] and can be used to `await` (e.g.) the processors defined by [[Process.resources | Process's `resources`]].

  #### Type Parameters

  - #### A extends unknown[]

  - #### T = any

  - #### R extends undefined | RequestType = undefined

  #### Parameters

  - ##### processor: Processor<A, T, R>

  - ##### `Rest` ...args: A

  #### Returns Promise<T>

  - Defined in packages/db/src/project/index.ts:181

Generated using TypeDoc