Skip to main content

Resource

Callable

  • Resource<T>(packageName: string, resourceName: string, schema: Constructable<ResourceSchema<T>>, options?: { destroyLosesData?: string[]; uniqueProperties?: { path: { [ K in string ]-?: unknown extends ResourceSchema<T>[properties][K] ? K | `${K}.${string}` | `${K}[]` | `${K}[].${string}` : NonNullable<...[...][K]> extends readonly E[] ? (NonNullable<...> extends string ? `${...}[]` : never) | (NonNullable<...> extends object ? `${...}[].${...}` : never) : NonNullable<...[...]> extends string ? K : NonNullable<...> extends object ? `${...}.${...}` : never }[keyof ResourceSchema<T>[properties] & string]; within: (keyof ResourceSchema<T>[properties] & string)[] }[] }): (constructor: Constructable<T>) => void

  • A @Resource is a class decorator and must be placed on top of a class representing a resource.

    • A resource must also extend the AResource class.
    • For type safety, the type of resource being decorated is passed to the decorator.
    @example
    @Resource<MyResource>('@example', 'my-name', MyResourceSchema)
    export class MyResource extends AResource<MyResourceSchema, MyResource> { ... }

    A resource holding names the cloud requires unique:

    @example
    @Resource<MyTable>('@example', 'my-table', MyTableSchema, {
    uniqueProperties: [
    { path: 'tableName', within: ['accountId', 'regionId'] },
    { path: 'indexes[].name', within: ['accountId', 'regionId'] },
    ],
    })
    export class MyTable extends AResource<MyTableSchema, MyTable> { ... }

    A resource holding data a destroy loses:

    @example
    @Resource<MyTable>('@example', 'my-table', MyTableSchema, { destroyLosesData: ['aws_dynamodb_table'] })
    export class MyTable extends AResource<MyTableSchema, MyTable> { ... }
    @group

    Decorators

    @see

    Definition of Resources.


    Type parameters

    • T: UnknownResource

    Parameters

    • packageName: string

      The name of the package under which the resource is registered. Selecting a unique package name helps avoid collisions between same resource class names across different libraries. You will reuse the same package name throughout your library for different Octo components you create.

    • resourceName: string

      The resource's name, unique in its package.

    • schema: Constructable<ResourceSchema<T>>

      The schema of the resource.

    • options: { destroyLosesData?: string[]; uniqueProperties?: { path: { [ K in string ]-?: unknown extends ResourceSchema<T>[properties][K] ? K | `${K}.${string}` | `${K}[]` | `${K}[].${string}` : NonNullable<...[...][K]> extends readonly E[] ? (NonNullable<...> extends string ? `${...}[]` : never) | (NonNullable<...> extends object ? `${...}[].${...}` : never) : NonNullable<...[...]> extends string ? K : NonNullable<...> extends object ? `${...}.${...}` : never }[keyof ResourceSchema<T>[properties] & string]; within: (keyof ResourceSchema<T>[properties] & string)[] }[] } = {}

      Optional settings of the resource. destroyLosesData names the Terraform types of the blocks holding data that is lost when one is destroyed, such as aws_s3_bucket but not its policy. Validate, and apply's check for destroys, add a message to each destroy of such a block, whatever the cause. Set it on a resource holding data octo cannot put back, such as rows, objects or images; not on content octo rewrites every apply, nor on a loss that breaks loudly. A named type the resource renders no block of is refused at generate; a block holding data added to the resource later is marked only once its type is named here.

      uniqueProperties lists the names the cloud requires unique, one entry per name: every one the provider's documentation says it keeps unique.

      • path is a dot path through the resource's properties, with [] after a key holding an array. A resource with no value at path is not checked.
      • within names the properties whose values form the name's domain, as the provider's documentation states it. A resource missing one is refused. An empty within makes the name unique across the app.

      Generate refuses two values of path that share the values of within, whether they come from two resources of the class or from one. Only resources of one class are compared with each other, and a class declaring no names is not checked.

      • optionaldestroyLosesData: string[] = []
      • optionaluniqueProperties: { path: { [ K in string ]-?: unknown extends ResourceSchema<T>[properties][K] ? K | `${K}.${string}` | `${K}[]` | `${K}[].${string}` : NonNullable<...[...][K]> extends readonly E[] ? (NonNullable<...> extends string ? `${...}[]` : never) | (NonNullable<...> extends object ? `${...}[].${...}` : never) : NonNullable<...[...]> extends string ? K : NonNullable<...> extends object ? `${...}.${...}` : never }[keyof ResourceSchema<T>[properties] & string]; within: (keyof ResourceSchema<T>[properties] & string)[] }[] = []

    Returns (constructor: Constructable<T>) => void

    The decorated class.