Dex TypeScript SDK 1.32.0
    Preparing search index...

    Class Attribute<T>

    Defines a typed, durable singleton value owned by a Flow.

    const status = new Attribute("status", stringCodec, {
    type: IndexType.KEYWORD,
    });
    const persistence: PersistenceSchema = { attributes: [status] };

    Type Parameters

    • T

      Value encoded by the Attribute's codec.

    Index

    Constructors

    • Creates an Attribute definition for a PersistenceSchema.

      Type Parameters

      • T

      Parameters

      • name: string

        Non-empty logical name without /, unique within the Flow.

      • codec: Codec<T>

        Value codec used by handlers and Client calls.

      • Optionalindex: AttributeIndex

        Optional visibility search index.

      Returns Attribute<T>

    Properties

    codec: Codec<T>

    Value codec used by handlers and Client calls.

    Optional visibility search index.

    name: string

    Non-empty logical name without /, unique within the Flow.

    Methods

    • Stages deletion in the current decision.

      Parameters

      • context: Context

        Current Step or RPC Context.

      Returns void

    • Reads the current value from handler decision state.

      Parameters

      • context: Context

        Current Step or RPC Context.

      Returns T

      The decoded Attribute value.

    • Returns an immutable Attribute definition for short-lived secrets that Dex can permanently delete.

      Use this option for values such as API keys that must not remain in Flow history. Dex stores each value of a hard-delete Attribute only in the Dex blob store, never in Flow history. Deleting the Attribute or setting it to null or undefined permanently deletes the stored value. Register the returned definition in the Flow's PersistenceSchema. Use that same definition for handler reads and writes, InitialAttribute values, and SubFlow initial Attributes.

      Only string and object values are supported. Object values include JSON values and byte arrays. Numeric and Boolean values are rejected. A built-in numeric or Boolean codec fails here. A custom codec that encodes a number or Boolean fails when the value is written. Deletion is always allowed. A hard-delete Attribute cannot have an index and cannot use Attribute.syncToAttributeStore. Client.waitForAttributeMatch rejects a hard-delete Attribute before contacting Dex.

      Writes require a Dex Server with an enabled blob store and Server protocol version 3 or later. Otherwise, the write fails. The Client checks the Server protocol version once before its first hard-delete write. The Worker checks it at startup and fails any handler result that writes a hard-delete Attribute to an older Server. Step and RPC handlers receive the value inline. The SDK never stores it in the local blob cache.

      Limitations:

      • Each Flow keeps one stored copy per Attribute key and overwrites it in place.
      • A Step or RPC attempt writes or deletes the stored value before Dex commits its result. A retried attempt, other Steps and RPCs, and Client reads can therefore observe a write or deletion from an attempt that later failed.
      • When concurrent Steps or RPCs write the same key, the final stored value may not be the value of the last committed write.
      • A failed startFlow or SubFlow start for a Flow ID that is already running still overwrites the running Flow's stored value. A null initial value deletes it.
      • Executions that reuse a Flow ID share the stored value.
      • Client.timeTravel does not restore a deleted value. A deleted value reads as absent.
      • A Flow retry or a restarted SubFlow starts from the original initial value. If an earlier run deleted that value, the new run reads it as absent.
      • Removing Attribute.hardDeleteOnNull from a definition leaves the stored value in place until Dex removes the Flow. Delete the value with the hard-delete definition first.
      • Values remain until they are deleted, or until Dex removes the Flow through retention and blob cleanup.
      • Blob store backups or bucket versioning can retain copies outside Dex's control.

      Returns Attribute<T>

      A new hard-delete definition; this definition remains unchanged.

      const apiKey = new Attribute("api-key", stringCodec).hardDeleteOnNull();

      class CallVendorStep implements Step<string> {
      public readonly inputCodec = stringCodec;

      public getStepType(): string {
      return "CallVendorStep";
      }

      public async execute(context: Context, vendorUrl: string): Promise<StepDecision> {
      const response = await fetch(vendorUrl, {
      headers: { authorization: `Bearer ${apiKey.get(context)}` },
      });
      apiKey.delete(context);
      return gracefulComplete(response.status);
      }
      }

      class VendorCallFlow implements Flow<string> {
      private readonly callVendor = new CallVendorStep();

      public getFlowType(): string {
      return "VendorCallFlow";
      }

      public getSteps() {
      return StepList.startStep(this.callVendor);
      }

      public getPersistenceSchema(): PersistenceSchema {
      return { attributes: [apiKey] };
      }
      }

      const flow = new VendorCallFlow();
      const client = new Client(new Registry([flow]), cache);
      await client.startFlow(flow, "vendor-call-42", "https://vendor.example/report", {
      attributes: [InitialAttribute.of(apiKey, process.env.VENDOR_API_KEY ?? "")],
      });

      When this definition has an index, uses Attribute Store synchronization, or uses a built-in numeric or Boolean codec.

    • Stages a value to persist with the current decision.

      Parameters

      • context: Context

        Current Step or RPC Context.

      • value: T

        Typed value to persist.

      Returns void

    • Returns an immutable Attribute definition whose writes are projected to the Flow's Attribute Store.

      Projection is asynchronous and latest-state only. Deletion writes SQL NULL, projection failures do not roll back Flow Attribute writes, and the Flow must select a configured Attribute Store name.

      Returns Attribute<T>

      A new synced definition; this definition remains unchanged.

      When this definition uses Attribute.hardDeleteOnNull.