Hyperlinkv0.8.0-beta.28

Process

Process.buildProcessSpecconstsrc/Process.ts:1642
<
  A extends Schema.Top = Schema.Void,
  E extends Schema.Top = Schema.Never
>(wire?: {
  readonly success?: A
  readonly error?: E
}): {
  events: Hyperlink.Method<
    undefined,
    Schema.Union<
      readonly [
        Schema.TaggedStruct<
          "Started",
          {
            readonly key: Schema.String
            readonly scheduleKey: Schema.NullOr<Schema.String>
            readonly startedAt: Schema.Number
            readonly isStartupRun: Schema.Boolean
          }
        >,
        Schema.TaggedStruct<
          "Completed",
          | {
              readonly key: Schema.String
              readonly scheduleKey: Schema.NullOr<Schema.String>
              readonly startedAt: Schema.Number
              readonly completedAt: Schema.Number
              readonly durationMs: Schema.Number
              readonly isStartupRun: Schema.Boolean
            }
          | {
              success: Schema.optional<Schema.Top>
              key: Schema.String
              scheduleKey: Schema.NullOr<Schema.String>
              startedAt: Schema.Number
              completedAt: Schema.Number
              durationMs: Schema.Number
              isStartupRun: Schema.Boolean
            }
        >,
        Schema.TaggedStruct<
          "Failed",
          {
            error: Schema.Top | Schema.String
            key: Schema.String
            scheduleKey: Schema.NullOr<Schema.String>
            startedAt: Schema.Number
            completedAt: Schema.Number
            durationMs: Schema.Number
            isStartupRun: Schema.Boolean
          }
        >,
        Schema.TaggedStruct<
          "Interrupted",
          {
            readonly key: Schema.String
            readonly scheduleKey: Schema.NullOr<Schema.String>
            readonly startedAt: Schema.Number
            readonly completedAt: Schema.Number
            readonly durationMs: Schema.Number
            readonly isStartupRun: Schema.Boolean
          }
        >
      ]
    >,
    Schema.Never,
    true,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
  run:
    | Hyperlink.Method<
        undefined,
        Schema.Void | A,
        Schema.Never,
        false,
        Hyperlink.MethodAnnotations & { description: string },
        Hyperlink.Derive
      >
    | Hyperlink.Method<
        undefined,
        Schema.Void | A,
        E,
        false,
        Hyperlink.MethodAnnotations & { description: string },
        Hyperlink.Derive
      >
  status: Hyperlink.Marked<
    Hyperlink.Method<
      undefined,
      Schema.Struct<{
        readonly supervising: Schema.Boolean
        readonly armed: Schema.Boolean
        readonly activeInstances: Schema.Number
        readonly nextTriggerRun: Schema.optionalKey<Schema.DateTimeUtc>
        readonly nextScheduleTransition: Schema.optionalKey<Schema.DateTimeUtc>
        readonly nextPollCadence: Schema.optionalKey<Schema.Duration>
        readonly runsStarted: Schema.Number
        readonly runsSucceeded: Schema.Number
        readonly runsFailed: Schema.Number
        readonly lastRunStartedAt: Schema.optionalKey<Schema.DateTimeUtc>
        readonly lastRunDurationMillis: Schema.optionalKey<Schema.Number>
      }>,
      Schema.Never,
      true,
      Hyperlink.MethodAnnotations & { description: string },
      Hyperlink.Derive
    >,
    { readonly _tag: "ref" }
  >
  start: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
  stop: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & {
      description: string
      destructive: true
    },
    Hyperlink.Derive
  >
  wake: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
  resetCadence: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
}

Build a process instance spec — control surface, live events stream, and a typed manual run RPC. Event element schema matches the durable store union (processExecutionEventFor with the tag's optional success / error).

wire schemaseventsrunprocessExecutionEventFor
Source src/Process.ts:164225 lines
export const buildProcessSpec = <
  A extends Schema.Top = typeof Schema.Void,
  E extends Schema.Top = typeof Schema.Never,
>(wire?: {
  readonly success?: A;
  readonly error?: E;
}) => {
  // Same schema helper as the durable store (`processStoreEventSchema`) so persist == stream on the wire.
  const eventSchema = processStoreEventSchema(wire?.success, wire?.error);
  return {
    ...processControlSpec,
    events: Hyperlink.stream(eventSchema).annotate({
      description:
        "Live execution lifecycle (Started / Completed / Failed / Interrupted). Same union as the " +
        "durable Process.store journal — persist == stream.",
    }),
    run: (wire?.error !== undefined
      ? Hyperlink.effect(wire?.success ?? Schema.Void, wire.error)
      : Hyperlink.effect(wire?.success ?? Schema.Void)
    ).annotate({
      description:
        "Run the process worker effect once, tracked — returns success; failures typed on error.",
    }),
  };
};
Referenced by 2 symbols