mask static method

Record mask({
  1. PulseEphemeralPolicy? policy,
  2. PulseContext? context,
  3. dynamic payload,
  4. dynamic type,
  5. DateTime? timestamp,
  6. Cell? source,
  7. String? step,
  8. Function? onComplete,
  9. Function? onError,
  10. Function? onProgress,
  11. int? priority,
  12. dynamic user,
  13. Pulse? pulse,
  14. Pulse? parent,
  15. Function? scrutinize,
})

Implementation

static Record mask({
  PulseEphemeralPolicy? policy,
  PulseContext? context,
  dynamic payload,
  dynamic type,
  DateTime? timestamp,
  Cell? source,
  String? step,
  Function? onComplete,
  Function? onError,
  Function? onProgress,
  int? priority,
  dynamic user,
  Pulse? pulse,
  Pulse? parent,
  Function? scrutinize,
}) {
  final isGoverned = policy != null || context != null ? true : false;

  // Physical reality (Payload, Source, Timestamp, Policy).
  final primaryMask = ((payload != null ? 1 : 0) |
      (source != null ? 2 : 0) |
      (timestamp != null ? 4 : 0) |
      (policy != null ? 8 : 0) |
      (isGoverned ? 16 : 0));

  final primary = switch (primaryMask) {
    0 => (),
    1 => (payload: payload),
    2 => (source: source),
    3 => (payload: payload, source: source),
    4 => (timestamp: timestamp),
    5 => (payload: payload, timestamp: timestamp),
    6 => (source: source, timestamp: timestamp),
    7 => (payload: payload, source: source, timestamp: timestamp),
    8 => (policy: policy),
    9 => (payload: payload, policy: policy),
    10 => (source: source, policy: policy),
    11 => (payload: payload, source: source, policy: policy),
    12 => (timestamp: timestamp, policy: policy),
    13 => (payload: payload, timestamp: timestamp, policy: policy),
    14 => (source: source, timestamp: timestamp, policy: policy),
    15 => (
        payload: payload,
        source: source,
        timestamp: timestamp,
        policy: policy
      ),
    16 => (isGoverned: isGoverned),
    17 => (payload: payload, isGoverned: isGoverned),
    18 => (source: source, isGoverned: isGoverned),
    19 => (payload: payload, source: source, isGoverned: isGoverned),
    20 => (timestamp: timestamp, isGoverned: isGoverned),
    21 => (payload: payload, timestamp: timestamp, isGoverned: isGoverned),
    22 => (source: source, timestamp: timestamp, isGoverned: isGoverned),
    23 => (
        payload: payload,
        source: source,
        timestamp: timestamp,
        isGoverned: isGoverned
      ),
    24 => (policy: policy, isGoverned: isGoverned),
    25 => (payload: payload, policy: policy, isGoverned: isGoverned),
    26 => (source: source, policy: policy, isGoverned: isGoverned),
    27 => (
        payload: payload,
        source: source,
        policy: policy,
        isGoverned: isGoverned
      ),
    28 => (timestamp: timestamp, policy: policy, isGoverned: isGoverned),
    29 => (
        payload: payload,
        timestamp: timestamp,
        policy: policy,
        isGoverned: isGoverned
      ),
    30 => (
        source: source,
        timestamp: timestamp,
        policy: policy,
        isGoverned: isGoverned
      ),
    31 => (
        payload: payload,
        source: source,
        timestamp: timestamp,
        policy: policy,
        isGoverned: isGoverned
      ),
    _ => ()
  };

  // Architectural placement (Type, Context, Metadata, Step).
  final secondaryMask = ((type != null ? 1 : 0) |
      (context != null ? 2 : 0) |
      (step != null ? 4 : 0));

  final secondary = switch (secondaryMask) {
    0 => (),
    1 => (type: type),
    2 => (context: context),
    3 => (type: type, context: context),
    4 => (step: step),
    5 => (type: type, step: step),
    6 => (context: context, step: step),
    7 => (type: type, context: context, step: step),
    _ => ()
  };

  // Tertiary: Governance and Provenance (Priority, Actor, Reason).
  // This represents the "Who" and "Why" behind the signal,
  final tertiaryMask = ((priority != null ? 1 : 0) |
      (user != null ? 2 : 0) |
      (scrutinize != null ? 4 : 0));

  final tertiary = switch (tertiaryMask) {
    0 => (),
    1 => (priority: priority),
    2 => (user: user),
    3 => (priority: priority, user: user),
    4 => (scrutinize: scrutinize),
    5 => (priority: priority, scrutinize: scrutinize),
    6 => (user: user, scrutinize: scrutinize),
    7 => (priority: priority, user: user, scrutinize: scrutinize),
    _ => ()
  };

  final callbackMask = ((onComplete != null ? 1 : 0) |
      (onError != null ? 2 : 0) |
      (onProgress != null ? 4 : 0));

  final callbacks = switch (callbackMask) {
    0 => (),
    1 => (onComplete: onComplete, branches: Box<int>(1)),
    2 => (onError: onError),
    3 => (onComplete: onComplete, branches: Box<int>(1), onError: onError),
    4 => (onProgress: onProgress),
    5 => (
        onComplete: onComplete,
        branches: Box<int>(1),
        onProgress: onProgress
      ),
    6 => (onError: onError, onProgress: onProgress),
    7 => (
        onComplete: onComplete,
        branches: Box<int>(1),
        onError: onError,
        onProgress: onProgress
      ),
    _ => ()
  };

  final finalMask = ((primaryMask > 0 ? 1 : 0) |
          (secondaryMask > 0 ? 2 : 0) |
          (tertiaryMask > 0 ? 4 : 0) |
          (callbackMask > 0 ? 8 : 0) |
          (parent != null ? 16 : 0)) |
      (pulse != null ? 32 : 0);

  // Field-level shape tag packed into one int. Accessors test these bits
  // and then read record fields directly — exception-free hot path.
  final shape = primaryMask |
      (secondaryMask << 8) |
      (tertiaryMask << 16) |
      (callbackMask << 24) |
      ((parent != null ? 1 : 0) << 5) |
      ((pulse != null ? 1 : 0) << 6);

  return switch (finalMask) {
    0 => (shape: shape, cycleChecker: FinalBox<CycleChecker>()),
    1 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary)
      ),
    2 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary)
      ),
    3 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary)
      ),
    4 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary)
      ),
    5 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary)
      ),
    6 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, tertiary: tertiary)
      ),
    7 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, tertiary: tertiary)
      ),
    8 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (callbacks: callbacks)
      ),
    9 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, callbacks: callbacks)
      ),
    10 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, callbacks: callbacks)
      ),
    11 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, callbacks: callbacks)
      ),
    12 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary, callbacks: callbacks)
      ),
    13 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary, callbacks: callbacks)
      ),
    14 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, tertiary: tertiary, callbacks: callbacks)
      ),
    15 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          primary: primary,
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        )
      ),
    16 => (shape: shape, parent: parent),
    17 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary),
        parent: parent
      ),
    18 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary),
        parent: parent
      ),
    19 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary),
        parent: parent
      ),
    20 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary),
        parent: parent
      ),
    21 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary),
        parent: parent
      ),
    22 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, tertiary: tertiary),
        parent: parent
      ),
    23 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, tertiary: tertiary),
        parent: parent
      ),
    24 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (callbacks: callbacks),
        parent: parent
      ),
    25 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, callbacks: callbacks),
        parent: parent
      ),
    26 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, callbacks: callbacks),
        parent: parent
      ),
    27 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, callbacks: callbacks),
        parent: parent
      ),
    28 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary, callbacks: callbacks),
        parent: parent
      ),
    29 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary, callbacks: callbacks),
        parent: parent
      ),
    30 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        ),
        parent: parent
      ),
    31 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          primary: primary,
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        ),
        parent: parent
      ),
    32 => (shape: shape, pulse: pulse),
    33 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary),
        pulse: pulse
      ),
    34 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary),
        pulse: pulse
      ),
    35 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary),
        pulse: pulse
      ),
    36 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary),
        pulse: pulse
      ),
    37 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary),
        pulse: pulse
      ),
    38 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, tertiary: tertiary),
        pulse: pulse
      ),
    39 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, tertiary: tertiary),
        pulse: pulse
      ),
    40 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (callbacks: callbacks),
        pulse: pulse
      ),
    41 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, callbacks: callbacks),
        pulse: pulse
      ),
    42 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, callbacks: callbacks),
        pulse: pulse
      ),
    43 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, callbacks: callbacks),
        pulse: pulse
      ),
    44 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary, callbacks: callbacks),
        pulse: pulse
      ),
    45 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary, callbacks: callbacks),
        pulse: pulse
      ),
    46 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        ),
        pulse: pulse
      ),
    47 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          primary: primary,
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        ),
        pulse: pulse
      ),
    48 => (shape: shape, parent: parent, pulse: pulse),
    49 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary),
        parent: parent,
        pulse: pulse
      ),
    50 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary),
        parent: parent,
        pulse: pulse
      ),
    51 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary),
        parent: parent,
        pulse: pulse
      ),
    52 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary),
        parent: parent,
        pulse: pulse
      ),
    53 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary),
        parent: parent,
        pulse: pulse
      ),
    54 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, tertiary: tertiary),
        parent: parent,
        pulse: pulse
      ),
    55 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, tertiary: tertiary),
        parent: parent,
        pulse: pulse
      ),
    56 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (callbacks: callbacks),
        parent: parent,
        pulse: pulse
      ),
    57 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, callbacks: callbacks),
        parent: parent,
        pulse: pulse
      ),
    58 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (secondary: secondary, callbacks: callbacks),
        parent: parent,
        pulse: pulse
      ),
    59 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, secondary: secondary, callbacks: callbacks),
        parent: parent,
        pulse: pulse
      ),
    60 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (tertiary: tertiary, callbacks: callbacks),
        parent: parent,
        pulse: pulse
      ),
    61 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (primary: primary, tertiary: tertiary, callbacks: callbacks),
        parent: parent,
        pulse: pulse
      ),
    62 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        ),
        parent: parent,
        pulse: pulse
      ),
    63 => (
        shape: shape,
        cycleChecker: FinalBox<CycleChecker>(),
        root: (
          primary: primary,
          secondary: secondary,
          tertiary: tertiary,
          callbacks: callbacks
        ),
        parent: parent,
        pulse: pulse
      ),
    _ => ()
  };
}