inngest
Version:
Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.
1 lines • 2.75 kB
Source Map (JSON)
{"version":3,"file":"lazyOps.cjs","names":["StepMode"],"sources":["../../../src/components/execution/lazyOps.ts"],"sourcesContent":["import { type OutgoingOp, StepMode } from \"../../types.ts\";\nimport type { MatchOpFn, StepToolOptions } from \"../InngestStepTools.ts\";\n\n/**\n * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be\n * buffered until the next outbound wire message (e.g. checkpointing a\n * `step.run`).\n *\n * The engine owns shipping. This helper owns the buffer.\n */\nexport class LazyOps {\n private buffer: OutgoingOp[] = [];\n\n // Tracks every id pushed during this execution, including those already\n // drained. `buffer` alone can't answer \"have we seen this id?\" once a\n // checkpoint ships its contents, so duplicates that straddle a drain would\n // otherwise slip through.\n private pushedIds: Set<string> = new Set();\n\n /**\n * Number of ops waiting to ship.\n */\n get length(): number {\n return this.buffer.length;\n }\n\n /**\n * Whether an op with this hashed id has been pushed in this execution\n * (whether or not it has since been drained).\n */\n hasId(id: string): boolean {\n return this.pushedIds.has(id);\n }\n\n /**\n * Take ownership of buffered ops and clear the buffer. Callers ship them on\n * whichever wire message comes next.\n */\n drain(): OutgoingOp[] {\n if (this.buffer.length === 0) {\n return [];\n }\n const ops = this.buffer;\n this.buffer = [];\n return ops;\n }\n\n /**\n * Buffer an op for later shipment.\n */\n push(op: OutgoingOp): void {\n this.buffer.push(op);\n this.pushedIds.add(op.id);\n }\n\n /**\n * Record that an id has been observed in this execution without buffering\n * an op for it. Used to consume a `priorDefers` replay match so that\n * subsequent encounters of the same id surface as duplicates.\n */\n markSeen(id: string): void {\n this.pushedIds.add(id);\n }\n}\n\n/**\n * True when a step being registered is an opcode-only sync op (no local\n * handler, sync mode).\n */\nexport function isLazyOp(\n opts: StepToolOptions | undefined,\n opId: ReturnType<MatchOpFn>,\n): boolean {\n return !opts?.fn && opId.mode === StepMode.Sync;\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,UAAb,MAAqB;CACnB,AAAQ,SAAuB,EAAE;CAMjC,AAAQ,4BAAyB,IAAI,KAAK;;;;CAK1C,IAAI,SAAiB;AACnB,SAAO,KAAK,OAAO;;;;;;CAOrB,MAAM,IAAqB;AACzB,SAAO,KAAK,UAAU,IAAI,GAAG;;;;;;CAO/B,QAAsB;AACpB,MAAI,KAAK,OAAO,WAAW,EACzB,QAAO,EAAE;EAEX,MAAM,MAAM,KAAK;AACjB,OAAK,SAAS,EAAE;AAChB,SAAO;;;;;CAMT,KAAK,IAAsB;AACzB,OAAK,OAAO,KAAK,GAAG;AACpB,OAAK,UAAU,IAAI,GAAG,GAAG;;;;;;;CAQ3B,SAAS,IAAkB;AACzB,OAAK,UAAU,IAAI,GAAG;;;;;;;AAQ1B,SAAgB,SACd,MACA,MACS;AACT,QAAO,CAAC,MAAM,MAAM,KAAK,SAASA,uBAAS"}