Skip to main content

Resource

Callable

  • Resource<T>(packageName: string, resourceName: string, schema: Constructable<ResourceSchema<T>>, options?: { destroyLosesData?: boolean; 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: any) => 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 whose properties hold a name the cloud requires unique declares it in options.uniqueProperties, and generate refuses two values of path that share the values of within, whether they come from two resources of the class or from one.

    @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 octo cannot put back from its inputs - a table's rows, a filesystem's files - sets options.destroyLosesData, and every destroy terraform plans of it is reported as losing data.

    @example
    @Resource<MyTable>('@example', 'my-table', MyTableSchema, { destroyLosesData: true })
    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

      a string that uniquely represents the name of the resource.

    • schema: Constructable<ResourceSchema<T>>

      The schema of the resource.

    • options: { destroyLosesData?: boolean; 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 marks the resource as holding data that is lost when it is destroyed. Validate, and apply's check for destroys, add a message to each destroy of it, whatever the cause.

      uniqueProperties lists the names the cloud requires unique, one entry per name.

      • 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. A resource missing one is refused. An empty within makes the name unique across the app.

      Only resources of one class are compared with each other, and a class declaring no names is not checked.

      • optionaldestroyLosesData: boolean = false
      • 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: any) => void

    The decorated class.

      • (constructor: any): void
      • Parameters

        • constructor: any

        Returns void