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.94 kB
Source Map (JSON)
{"version":3,"file":"assertions.cjs","names":["Inngest","InngestFunction","headerKeys"],"sources":["../../src/helpers/assertions.ts"],"sourcesContent":["/**\n * While developers can often use `instanceof` to check if an object is a class\n * instance, this is not always reliable, especially when dealing with objects\n * that may have been created in different execution contexts or across\n * different versions of the library.\n *\n * This module provides a set of type guards that use `*.Like` interfaces to\n * recognize the objects instead of any other typing.\n *\n * These can be used internally and externally.\n *\n * @module\n */\n\nimport { Inngest } from \"../components/Inngest.ts\";\nimport { InngestEndpointAdapter } from \"../components/InngestEndpointAdapter.ts\";\nimport { InngestFunction } from \"../components/InngestFunction.ts\";\nimport { headerKeys } from \"./consts.ts\";\n\n/**\n * Asserts that the given `input` is an `Inngest` object.\n */\nexport const isInngest = (\n /**\n * The input to check.\n */\n input: unknown,\n): input is Inngest.Any => {\n // biome-ignore lint/suspicious/noExplicitAny: we're happy that it could be anything here\n return (input as any)[Symbol.toStringTag] === Inngest.Tag;\n};\n\n/**\n * Asserts that the given `input` is an `InngestFunction` object.\n */\nexport const isInngestFunction = (\n /**\n * The input to check.\n */\n input: unknown,\n): input is InngestFunction.Any => {\n // biome-ignore lint/suspicious/noExplicitAny: we're happy that it could be anything here\n return (input as any)[Symbol.toStringTag] === InngestFunction.Tag;\n};\n\n/**\n * Asserts that the given `input` is a request originating from Inngest.\n */\nexport const isInngestRequest = (\n /**\n * The input to check.\n */\n input: unknown,\n): boolean => {\n try {\n const runId = (input as Request).headers.get(headerKeys.InngestRunId);\n const signature = (input as Request).headers.get(headerKeys.Signature);\n\n // Note that the signature just has to be present; in Dev it'll be empty,\n // but still set to `\"\"`.\n return Boolean(runId && typeof signature === \"string\");\n } catch {\n return false;\n }\n};\n\n/**\n * Asserts that the given `input` is an `InngestEndpointAdapter` object.\n */\nexport const isInngestEndpointAdapter = (\n /**\n * The input to check.\n */\n input: unknown,\n): input is InngestEndpointAdapter.Like => {\n // biome-ignore lint/suspicious/noExplicitAny: we're happy that it could be anything here\n return (input as any)[Symbol.toStringTag] === InngestEndpointAdapter.Tag;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,aAIX,UACyB;AAEzB,QAAQ,MAAc,OAAO,iBAAiBA,wBAAQ;;;;;AAMxD,MAAa,qBAIX,UACiC;AAEjC,QAAQ,MAAc,OAAO,iBAAiBC,wCAAgB;;;;;AAMhE,MAAa,oBAIX,UACY;AACZ,KAAI;EACF,MAAM,QAAS,MAAkB,QAAQ,IAAIC,0BAAW,aAAa;EACrE,MAAM,YAAa,MAAkB,QAAQ,IAAIA,0BAAW,UAAU;AAItE,SAAO,QAAQ,SAAS,OAAO,cAAc,SAAS;SAChD;AACN,SAAO"}