inngest 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/api/schema.d.cts +2 -2
- package/api/schema.d.cts.map +1 -1
- package/api/schema.d.ts +2 -2
- package/api/schema.d.ts.map +1 -1
- package/components/DeferredFunction.cjs +66 -0
- package/components/DeferredFunction.cjs.map +1 -0
- package/components/DeferredFunction.d.cts +99 -0
- package/components/DeferredFunction.d.cts.map +1 -0
- package/components/DeferredFunction.d.ts +99 -0
- package/components/DeferredFunction.d.ts.map +1 -0
- package/components/DeferredFunction.js +65 -0
- package/components/DeferredFunction.js.map +1 -0
- package/components/Inngest.cjs +5 -2
- package/components/Inngest.cjs.map +1 -1
- package/components/Inngest.d.cts +4 -3
- package/components/Inngest.d.cts.map +1 -1
- package/components/Inngest.d.ts +4 -3
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +5 -2
- package/components/Inngest.js.map +1 -1
- package/components/InngestCommHandler.cjs +28 -23
- package/components/InngestCommHandler.cjs.map +1 -1
- package/components/InngestCommHandler.d.cts +9 -4
- package/components/InngestCommHandler.d.cts.map +1 -1
- package/components/InngestCommHandler.d.ts +9 -4
- package/components/InngestCommHandler.d.ts.map +1 -1
- package/components/InngestCommHandler.js +28 -23
- package/components/InngestCommHandler.js.map +1 -1
- package/components/InngestFunction.cjs +27 -19
- package/components/InngestFunction.cjs.map +1 -1
- package/components/InngestFunction.d.cts +6 -1
- package/components/InngestFunction.d.cts.map +1 -1
- package/components/InngestFunction.d.ts +6 -1
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +27 -19
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestGroupTools.cjs +1 -1
- package/components/InngestGroupTools.cjs.map +1 -1
- package/components/InngestGroupTools.js +1 -1
- package/components/InngestGroupTools.js.map +1 -1
- package/components/connect/config.cjs +2 -0
- package/components/connect/config.cjs.map +1 -1
- package/components/connect/config.js +2 -0
- package/components/connect/config.js.map +1 -1
- package/components/execution/InngestExecution.cjs.map +1 -1
- package/components/execution/InngestExecution.d.cts +19 -2
- package/components/execution/InngestExecution.d.cts.map +1 -1
- package/components/execution/InngestExecution.d.ts +19 -2
- package/components/execution/InngestExecution.d.ts.map +1 -1
- package/components/execution/InngestExecution.js.map +1 -1
- package/components/execution/engine.cjs +232 -27
- package/components/execution/engine.cjs.map +1 -1
- package/components/execution/engine.d.cts +14 -0
- package/components/execution/engine.d.cts.map +1 -1
- package/components/execution/engine.d.ts +14 -0
- package/components/execution/engine.d.ts.map +1 -1
- package/components/execution/engine.js +232 -27
- package/components/execution/engine.js.map +1 -1
- package/components/execution/lazyOps.cjs +64 -0
- package/components/execution/lazyOps.cjs.map +1 -0
- package/components/execution/lazyOps.d.cts +42 -0
- package/components/execution/lazyOps.d.cts.map +1 -0
- package/components/execution/lazyOps.d.ts +42 -0
- package/components/execution/lazyOps.d.ts.map +1 -0
- package/components/execution/lazyOps.js +63 -0
- package/components/execution/lazyOps.js.map +1 -0
- package/components/execution/otel/middleware.d.cts +6 -3
- package/components/execution/otel/middleware.d.cts.map +1 -1
- package/components/execution/otel/middleware.d.ts +6 -3
- package/components/execution/otel/middleware.d.ts.map +1 -1
- package/components/middleware/middleware.cjs.map +1 -1
- package/components/middleware/middleware.d.cts +1 -1
- package/components/middleware/middleware.d.cts.map +1 -1
- package/components/middleware/middleware.d.ts +1 -1
- package/components/middleware/middleware.d.ts.map +1 -1
- package/components/middleware/middleware.js.map +1 -1
- package/components/middleware/utils.cjs +1 -0
- package/components/middleware/utils.cjs.map +1 -1
- package/components/middleware/utils.js +1 -0
- package/components/middleware/utils.js.map +1 -1
- package/components/realtime/types.d.cts +4 -4
- package/components/realtime/types.d.cts.map +1 -1
- package/components/realtime/types.d.ts +4 -4
- package/components/realtime/types.d.ts.map +1 -1
- package/components/triggers/typeHelpers.cjs.map +1 -1
- package/components/triggers/typeHelpers.d.cts +11 -0
- package/components/triggers/typeHelpers.d.cts.map +1 -1
- package/components/triggers/typeHelpers.d.ts +11 -0
- package/components/triggers/typeHelpers.d.ts.map +1 -1
- package/components/triggers/typeHelpers.js.map +1 -1
- package/experimental.cjs +3 -0
- package/experimental.d.cts +2 -1
- package/experimental.d.ts +2 -1
- package/experimental.js +2 -1
- package/helpers/consts.cjs +6 -0
- package/helpers/consts.cjs.map +1 -1
- package/helpers/consts.d.cts +6 -0
- package/helpers/consts.d.cts.map +1 -1
- package/helpers/consts.d.ts +6 -0
- package/helpers/consts.d.ts.map +1 -1
- package/helpers/consts.js +6 -0
- package/helpers/consts.js.map +1 -1
- package/helpers/functions.cjs +1 -0
- package/helpers/functions.cjs.map +1 -1
- package/helpers/functions.js +1 -0
- package/helpers/functions.js.map +1 -1
- package/helpers/marker.cjs +21 -0
- package/helpers/marker.cjs.map +1 -0
- package/helpers/marker.d.cts +12 -0
- package/helpers/marker.d.cts.map +1 -0
- package/helpers/marker.d.ts +12 -0
- package/helpers/marker.d.ts.map +1 -0
- package/helpers/marker.js +19 -0
- package/helpers/marker.js.map +1 -0
- package/package.json +2 -2
- package/proto/src/components/connect/protobuf/connect.cjs +11 -2
- package/proto/src/components/connect/protobuf/connect.cjs.map +1 -1
- package/proto/src/components/connect/protobuf/connect.js +11 -2
- package/proto/src/components/connect/protobuf/connect.js.map +1 -1
- package/types.cjs +2 -0
- package/types.cjs.map +1 -1
- package/types.d.cts +52 -18
- package/types.d.cts.map +1 -1
- package/types.d.ts +52 -18
- package/types.d.ts.map +1 -1
- package/types.js +2 -0
- package/types.js.map +1 -1
- package/version.cjs +1 -1
- package/version.cjs.map +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# inngest
|
|
2
2
|
|
|
3
|
+
## 4.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1508](https://github.com/inngest/inngest-js/pull/1508) [`4771b424`](https://github.com/inngest/inngest-js/commit/4771b42402f9e2f435417b65f4e5a38e54e398af) Thanks [@amh4r](https://github.com/amh4r)! - Add experimental support for deferred functions
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#1512](https://github.com/inngest/inngest-js/pull/1512) [`be675a3d`](https://github.com/inngest/inngest-js/commit/be675a3d3c2a39b415ded8db5e2626e22b941760) Thanks [@amh4r](https://github.com/amh4r)! - Fix waitForSignal not in middleware StepType union
|
|
12
|
+
|
|
13
|
+
- [#1513](https://github.com/inngest/inngest-js/pull/1513) [`cbad05c3`](https://github.com/inngest/inngest-js/commit/cbad05c3052de84defe36797c23eb0da295022fb) Thanks [@jakobevangelista](https://github.com/jakobevangelista)! - Standardize variant naming to `variant` instead of `variant_selected`
|
|
14
|
+
|
|
15
|
+
- [#1516](https://github.com/inngest/inngest-js/pull/1516) [`1bca44a8`](https://github.com/inngest/inngest-js/commit/1bca44a8293d6d44e93266fbe3e8dd4dc7e0fa73) Thanks [@BrunoScheufler](https://github.com/BrunoScheufler)! - - Add Request ID & Job ID to context and logs
|
|
16
|
+
|
|
3
17
|
## 4.3.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/api/schema.d.cts
CHANGED
|
@@ -6,11 +6,11 @@ declare const errorSchema: z.ZodObject<{
|
|
|
6
6
|
error: z.ZodString;
|
|
7
7
|
status: z.ZodNumber;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
9
|
-
error: string;
|
|
10
9
|
status: number;
|
|
11
|
-
}, {
|
|
12
10
|
error: string;
|
|
11
|
+
}, {
|
|
13
12
|
status: number;
|
|
13
|
+
error: string;
|
|
14
14
|
}>;
|
|
15
15
|
type ErrorResponse = z.infer<typeof errorSchema>;
|
|
16
16
|
declare const stepSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodObject<{
|
package/api/schema.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.cts","names":[],"sources":["../../src/api/schema.ts"],"sourcesContent":[],"mappings":";;;;cAGa,aAAW,CAAA,CAAA;;EAAX,MAAA,aAGX;CAAA,EAAA,OAAA,cAAA,EAAA;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.cts","names":[],"sources":["../../src/api/schema.ts"],"sourcesContent":[],"mappings":";;;;cAGa,aAAW,CAAA,CAAA;;EAAX,MAAA,aAGX;CAAA,EAAA,OAAA,cAAA,EAAA;;;;QAHsB,EAAA,MAAA;EAAA,KAAA,EAAA,MAAA;AAIxB,CAAA,CAAA;AAAyB,KAAb,aAAA,GAAgB,CAAA,CAAE,KAAL,CAAA,OAAkB,WAAlB,CAAA;AAAkB,cAE9B,UAF8B,EAEpB,CAAA,CAAA,UAFoB,CAEpB,CAAA,CAAA,SAFoB,CAEpB,CAAA,CAAA,SAFoB,EAEpB,CAAA,CAAA,QAFoB,CAAA,CAEpB,CAAA,CAAA,QAFoB,CAAA,CAEpB,CAAA,CAAA,QAFoB,CAAA,CAEpB,CAAA,CAAA,SAFoB,CAAA;MAAf,cAAE,cAAA,aAAA,CAAA,MAAA,CAAA,CAAA,CAAA;EAAK,IAAA,cAAA,SAAA,EAAA,GAAA,EAAA,GAAA,CAAA;AAEnC,CAAA,EAAA,QAAa,cAuCC,EAAA;EAAA,IAAA,EAAA,MAAA;MAvCS,CAAA,EAAA,GAAA;;;;;;;WAAA,cAAA,EAAA;;;;;;;;;;;;;;;;;;MAAA;;;IAAA,KAAA,CAAA,EAAA,OAAA;;MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;CAAA,CAAA,CAAA,CAAA,aAAA,CAAA;EAyCX,IAAA,cAAa,cAAA,aAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EAAA,KAAA,cAAA,SAAA,EAAA,GAAA,EAAA,GAAA,CAAA;WAAkB,cAAA,EAAA;MAAf,EAAE,OAAA;EAAK,KAAA,CAAA,EAAA,GAAA;AAEnC,CAAA,EAAA;EAEC,IAAA,CAAA,EAAA,OAAA,GAAA,SAAA;OAFuB,CAAA,EAAA,GAAA;kBAAA,SAAA,EAAA;MAAA,EAAA,MAAA;MAAA,EAAA,GAAA;OAAA,CAAA,CAAA,CAAA,CAAA;AAAA,KAFZ,aAAA,GAAgB,CAAA,CAAE,KAEN,CAAA,OAFmB,UAEnB,CAAA;AAAA,cAAX,WAAW,EAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA,CAAA,CAAA,CAAA,SAAA,EAAA,CAAA,CAAA,MAAA,CAAA,EAAA,YAAA,CAAA,GAAA,CAAA,EAAA,MAAA,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,EAAA,MAAA,CAAA;AAAA,KAGZ,aAAA,GAAgB,CAAA,CAAE,KAHN,CAAA,OAGmB,WAHnB,CAAA"}
|
package/api/schema.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ declare const errorSchema: z.ZodObject<{
|
|
|
6
6
|
error: z.ZodString;
|
|
7
7
|
status: z.ZodNumber;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
9
|
-
error: string;
|
|
10
9
|
status: number;
|
|
11
|
-
}, {
|
|
12
10
|
error: string;
|
|
11
|
+
}, {
|
|
13
12
|
status: number;
|
|
13
|
+
error: string;
|
|
14
14
|
}>;
|
|
15
15
|
type ErrorResponse = z.infer<typeof errorSchema>;
|
|
16
16
|
declare const stepSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodObject<{
|
package/api/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/api/schema.ts"],"sourcesContent":[],"mappings":";;;;cAGa,aAAW,CAAA,CAAA;;EAAX,MAAA,aAGX;CAAA,EAAA,O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AAA,CAAA,CAAA,CAAA;AAAA,KAFZ,aAAA,GAAgB,CAAA,CAAE,KAEN,CAAA,OAFmB,UAEnB,CAAA;AAAA,cAAX,WAAW,EAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA,CAAA,CAAA,CAAA,SAAA,EAAA,CAAA,CAAA,MAAA,CAAA,EAAA,YAAA,CAAA,GAAA,CAAA,EAAA,MAAA,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,EAAA,MAAA,CAAA;AAAA,KAGZ,aAAA,GAAgB,CAAA,CAAE,KAHN,CAAA,OAGmB,WAHnB,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const require_consts = require('../helpers/consts.cjs');
|
|
2
|
+
const require_marker = require('../helpers/marker.cjs');
|
|
3
|
+
const require_InngestFunction = require('./InngestFunction.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/components/DeferredFunction.ts
|
|
6
|
+
const idDenyRegex = /['\\\n\r]/;
|
|
7
|
+
/**
|
|
8
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
9
|
+
* a major version bump.
|
|
10
|
+
*
|
|
11
|
+
* A defer (companion) function created via `createDefer(...)`. Real
|
|
12
|
+
* `InngestFunction` at runtime, but with the trigger pinned to
|
|
13
|
+
* `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and
|
|
14
|
+
* `onFailure` disallowed, and the schema carried as a typed instance
|
|
15
|
+
* property so callers of `defer(id, { function, data })` can extract it.
|
|
16
|
+
*
|
|
17
|
+
* Identify a defer function at runtime via `isDeferredFunction(value)` from
|
|
18
|
+
* `helpers/marker.ts`. Prefer that over `instanceof`, which fails across
|
|
19
|
+
* duplicate SDK copies in the same process.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
var DeferredFunction = class extends require_InngestFunction.InngestFunction {
|
|
24
|
+
schema;
|
|
25
|
+
[require_marker.markerKey] = { kind: "deferredFunction" };
|
|
26
|
+
constructor(client, opts, handler, schema) {
|
|
27
|
+
if (idDenyRegex.test(opts.id)) throw new Error(`invalid id "${opts.id}"; must match ${idDenyRegex.source}`);
|
|
28
|
+
super(client, {
|
|
29
|
+
...opts,
|
|
30
|
+
triggers: []
|
|
31
|
+
}, handler);
|
|
32
|
+
this.schema = schema;
|
|
33
|
+
}
|
|
34
|
+
getConfigTriggers(fnId) {
|
|
35
|
+
return [{
|
|
36
|
+
event: require_consts.internalEvents.DeferredSchedule,
|
|
37
|
+
expression: `event.data._inngest.fn_slug == '${fnId}'`
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
43
|
+
* a major version bump.
|
|
44
|
+
*
|
|
45
|
+
* Create a typed defer function. One `createDefer` call = one Inngest
|
|
46
|
+
* function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id,
|
|
47
|
+
* { function, data })` get the data type inferred from the schema.
|
|
48
|
+
*
|
|
49
|
+
* Mirrors `inngest.createFunction(opts, handler)`, with three differences:
|
|
50
|
+
* the client is the first positional arg, `triggers` is not accepted (the
|
|
51
|
+
* SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema`
|
|
52
|
+
* describes the payload that callers will send via `defer(id, { function,
|
|
53
|
+
* data })`.
|
|
54
|
+
*
|
|
55
|
+
* Pass the result to `serve()` alongside regular functions so the SDK
|
|
56
|
+
* registers it.
|
|
57
|
+
*/
|
|
58
|
+
function createDefer(client, options, handler) {
|
|
59
|
+
const { schema, ...rest } = options;
|
|
60
|
+
return new DeferredFunction(client, rest, handler, schema);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
exports.DeferredFunction = DeferredFunction;
|
|
65
|
+
exports.createDefer = createDefer;
|
|
66
|
+
//# sourceMappingURL=DeferredFunction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredFunction.cjs","names":["InngestFunction","markerKey","internalEvents"],"sources":["../../src/components/DeferredFunction.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { internalEvents } from \"../helpers/consts.ts\";\nimport { type Marker, markerKey } from \"../helpers/marker.ts\";\nimport type {\n ApplyAllMiddlewareCtxExtensions,\n ApplyAllMiddlewareStepExtensions,\n BaseContext,\n FunctionConfig,\n Handler,\n} from \"../types.ts\";\nimport type {\n builtInMiddleware,\n ClientOptionsFromInngest,\n Inngest,\n} from \"./Inngest.ts\";\nimport { InngestFunction } from \"./InngestFunction.ts\";\nimport type { createStepTools } from \"./InngestStepTools.ts\";\nimport type { Middleware } from \"./middleware/index.ts\";\n\nconst idDenyRegex = /['\\\\\\n\\r]/;\n\n/**\n * EXPERIMENTAL: This API is not yet stable and may change in the future without\n * a major version bump.\n *\n * A defer (companion) function created via `createDefer(...)`. Real\n * `InngestFunction` at runtime, but with the trigger pinned to\n * `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and\n * `onFailure` disallowed, and the schema carried as a typed instance\n * property so callers of `defer(id, { function, data })` can extract it.\n *\n * Identify a defer function at runtime via `isDeferredFunction(value)` from\n * `helpers/marker.ts`. Prefer that over `instanceof`, which fails across\n * duplicate SDK copies in the same process.\n *\n * @public\n */\nexport class DeferredFunction<\n TSchema extends\n | StandardSchemaV1<Record<string, unknown>>\n | undefined = undefined,\n> extends InngestFunction<\n InngestFunction.Options<[], never>,\n Handler.Any,\n never,\n Inngest.Any,\n []\n> {\n readonly schema: TSchema;\n readonly [markerKey]: Marker = { kind: \"deferredFunction\" };\n\n constructor(\n client: Inngest.Any,\n opts: DeferredFunction.Options,\n handler: Handler.Any,\n schema: TSchema,\n ) {\n // The id is interpolated into a CEL trigger expression\n // (`event.data._inngest.fn_slug == '${fnId}'`). Reject characters that\n // would break the single-quoted string literal.\n if (idDenyRegex.test(opts.id)) {\n throw new Error(\n `invalid id \"${opts.id}\"; must match ${idDenyRegex.source}`,\n );\n }\n super(\n client,\n { ...opts, triggers: [] } as InngestFunction.Options<[], never>,\n handler,\n );\n this.schema = schema;\n }\n\n protected override getConfigTriggers(\n fnId: string,\n ): FunctionConfig[\"triggers\"] {\n return [\n {\n event: internalEvents.DeferredSchedule,\n expression: `event.data._inngest.fn_slug == '${fnId}'`,\n },\n ];\n }\n}\n\n/**\n * @public\n */\nexport namespace DeferredFunction {\n /**\n * Matches any `DeferredFunction` regardless of its schema. Use as the\n * constraint for the `function` argument of `defer()`.\n */\n // biome-ignore lint/suspicious/noExplicitAny: widest schema constraint for inference\n export type Any = DeferredFunction<StandardSchemaV1<any> | undefined>;\n\n /**\n * The user-facing options accepted by `createDefer(client, opts, handler)`.\n * Mirrors `InngestFunction.Options` minus `triggers` (implicit), `onFailure`\n * (not yet supported), and `batchEvents` (each `defer(...)` is its own run).\n */\n export type Options = Omit<\n InngestFunction.Options<[], never>,\n \"triggers\" | \"onFailure\" | \"batchEvents\"\n >;\n}\n\n/**\n * The `event` shape a defer handler receives. With a schema, `data`\n * narrows to its inferred type; without one, it falls back to\n * `Record<string, any>`.\n */\ntype DeferEvent<TSchema> = {\n name: internalEvents.DeferredSchedule;\n data: TSchema extends StandardSchemaV1<\n infer D extends Record<string, unknown>\n >\n ? D\n : // biome-ignore lint/suspicious/noExplicitAny: no schema = any\n Record<string, any>;\n};\n\n/**\n * Base ctx shape for a defer handler: the standard function context\n * (`runId`, `attempt`, `group`, `step` with middleware step extensions)\n * with `event`/`events` pinned to `inngest/deferred.schedule` and the\n * schema-typed payload.\n */\ntype BaseDeferCtx<\n TClient extends Inngest.Any,\n TFnMiddleware extends Middleware.Class[] | undefined,\n TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined,\n> = Omit<BaseContext<TClient>, \"event\" | \"events\" | \"step\"> & {\n event: DeferEvent<TSchema>;\n events: [DeferEvent<TSchema>];\n step: ReturnType<typeof createStepTools<TClient, TFnMiddleware>> &\n ApplyAllMiddlewareStepExtensions<\n ClientOptionsFromInngest<TClient>[\"middleware\"]\n > &\n ApplyAllMiddlewareStepExtensions<TFnMiddleware>;\n};\n\n/**\n * Input type for `createDefer`. Same shape as `DeferredFunction.Options`\n * plus `schema` (the StandardSchema describing `event.data` that flows\n * to caller `defer(id, { function, data })` call sites) and `middleware`.\n */\nexport type CreateDeferInput<\n TFnMiddleware extends Middleware.Class[] | undefined,\n TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined,\n> = DeferredFunction.Options & {\n schema?: TSchema;\n middleware?: TFnMiddleware;\n};\n\n/**\n * EXPERIMENTAL: This API is not yet stable and may change in the future without\n * a major version bump.\n *\n * Create a typed defer function. One `createDefer` call = one Inngest\n * function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id,\n * { function, data })` get the data type inferred from the schema.\n *\n * Mirrors `inngest.createFunction(opts, handler)`, with three differences:\n * the client is the first positional arg, `triggers` is not accepted (the\n * SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema`\n * describes the payload that callers will send via `defer(id, { function,\n * data })`.\n *\n * Pass the result to `serve()` alongside regular functions so the SDK\n * registers it.\n */\nexport function createDefer<\n TClient extends Inngest.Any,\n TSchema extends\n | StandardSchemaV1<Record<string, unknown>>\n | undefined = undefined,\n const TFnMiddleware extends Middleware.Class[] | undefined = undefined,\n THandler extends Handler.Any = (\n ctx: BaseDeferCtx<TClient, TFnMiddleware, TSchema> &\n ApplyAllMiddlewareCtxExtensions<\n [...ReturnType<typeof builtInMiddleware>]\n > &\n ApplyAllMiddlewareCtxExtensions<\n ClientOptionsFromInngest<TClient>[\"middleware\"]\n > &\n ApplyAllMiddlewareCtxExtensions<TFnMiddleware>,\n ) => unknown,\n>(\n client: TClient,\n options: CreateDeferInput<TFnMiddleware, TSchema>,\n handler: THandler,\n): DeferredFunction<TSchema> {\n const { schema, ...rest } = options;\n return new DeferredFunction<TSchema>(\n client,\n rest,\n handler as Handler.Any,\n schema as TSchema,\n );\n}\n"],"mappings":";;;;;AAmBA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,IAAa,mBAAb,cAIUA,wCAMR;CACA,AAAS;CACT,CAAUC,4BAAqB,EAAE,MAAM,oBAAoB;CAE3D,YACE,QACA,MACA,SACA,QACA;AAIA,MAAI,YAAY,KAAK,KAAK,GAAG,CAC3B,OAAM,IAAI,MACR,eAAe,KAAK,GAAG,gBAAgB,YAAY,SACpD;AAEH,QACE,QACA;GAAE,GAAG;GAAM,UAAU,EAAE;GAAE,EACzB,QACD;AACD,OAAK,SAAS;;CAGhB,AAAmB,kBACjB,MAC4B;AAC5B,SAAO,CACL;GACE,OAAOC,8BAAe;GACtB,YAAY,mCAAmC,KAAK;GACrD,CACF;;;;;;;;;;;;;;;;;;;;AA2FL,SAAgB,YAiBd,QACA,SACA,SAC2B;CAC3B,MAAM,EAAE,QAAQ,GAAG,SAAS;AAC5B,QAAO,IAAI,iBACT,QACA,MACA,SACA,OACD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { internalEvents } from "../helpers/consts.cjs";
|
|
2
|
+
import { Marker, markerKey } from "../helpers/marker.cjs";
|
|
3
|
+
import { Middleware } from "./middleware/middleware.cjs";
|
|
4
|
+
import { createStepTools } from "./InngestStepTools.cjs";
|
|
5
|
+
import { InngestFunction } from "./InngestFunction.cjs";
|
|
6
|
+
import { ApplyAllMiddlewareCtxExtensions, ApplyAllMiddlewareStepExtensions, BaseContext, FunctionConfig, Handler } from "../types.cjs";
|
|
7
|
+
import { ClientOptionsFromInngest, Inngest, builtInMiddleware } from "./Inngest.cjs";
|
|
8
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
9
|
+
|
|
10
|
+
//#region src/components/DeferredFunction.d.ts
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
14
|
+
* a major version bump.
|
|
15
|
+
*
|
|
16
|
+
* A defer (companion) function created via `createDefer(...)`. Real
|
|
17
|
+
* `InngestFunction` at runtime, but with the trigger pinned to
|
|
18
|
+
* `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and
|
|
19
|
+
* `onFailure` disallowed, and the schema carried as a typed instance
|
|
20
|
+
* property so callers of `defer(id, { function, data })` can extract it.
|
|
21
|
+
*
|
|
22
|
+
* Identify a defer function at runtime via `isDeferredFunction(value)` from
|
|
23
|
+
* `helpers/marker.ts`. Prefer that over `instanceof`, which fails across
|
|
24
|
+
* duplicate SDK copies in the same process.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare class DeferredFunction<TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined> extends InngestFunction<InngestFunction.Options<[], never>, Handler.Any, never, Inngest.Any, []> {
|
|
29
|
+
readonly schema: TSchema;
|
|
30
|
+
readonly [markerKey]: Marker;
|
|
31
|
+
constructor(client: Inngest.Any, opts: DeferredFunction.Options, handler: Handler.Any, schema: TSchema);
|
|
32
|
+
protected getConfigTriggers(fnId: string): FunctionConfig["triggers"];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
declare namespace DeferredFunction {
|
|
38
|
+
/**
|
|
39
|
+
* Matches any `DeferredFunction` regardless of its schema. Use as the
|
|
40
|
+
* constraint for the `function` argument of `defer()`.
|
|
41
|
+
*/
|
|
42
|
+
type Any = DeferredFunction<StandardSchemaV1<any> | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* The user-facing options accepted by `createDefer(client, opts, handler)`.
|
|
45
|
+
* Mirrors `InngestFunction.Options` minus `triggers` (implicit), `onFailure`
|
|
46
|
+
* (not yet supported), and `batchEvents` (each `defer(...)` is its own run).
|
|
47
|
+
*/
|
|
48
|
+
type Options = Omit<InngestFunction.Options<[], never>, "triggers" | "onFailure" | "batchEvents">;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The `event` shape a defer handler receives. With a schema, `data`
|
|
52
|
+
* narrows to its inferred type; without one, it falls back to
|
|
53
|
+
* `Record<string, any>`.
|
|
54
|
+
*/
|
|
55
|
+
type DeferEvent<TSchema> = {
|
|
56
|
+
name: internalEvents.DeferredSchedule;
|
|
57
|
+
data: TSchema extends StandardSchemaV1<infer D extends Record<string, unknown>> ? D : Record<string, any>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Base ctx shape for a defer handler: the standard function context
|
|
61
|
+
* (`runId`, `attempt`, `group`, `step` with middleware step extensions)
|
|
62
|
+
* with `event`/`events` pinned to `inngest/deferred.schedule` and the
|
|
63
|
+
* schema-typed payload.
|
|
64
|
+
*/
|
|
65
|
+
type BaseDeferCtx<TClient extends Inngest.Any, TFnMiddleware extends Middleware.Class[] | undefined, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined> = Omit<BaseContext<TClient>, "event" | "events" | "step"> & {
|
|
66
|
+
event: DeferEvent<TSchema>;
|
|
67
|
+
events: [DeferEvent<TSchema>];
|
|
68
|
+
step: ReturnType<typeof createStepTools<TClient, TFnMiddleware>> & ApplyAllMiddlewareStepExtensions<ClientOptionsFromInngest<TClient>["middleware"]> & ApplyAllMiddlewareStepExtensions<TFnMiddleware>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Input type for `createDefer`. Same shape as `DeferredFunction.Options`
|
|
72
|
+
* plus `schema` (the StandardSchema describing `event.data` that flows
|
|
73
|
+
* to caller `defer(id, { function, data })` call sites) and `middleware`.
|
|
74
|
+
*/
|
|
75
|
+
type CreateDeferInput<TFnMiddleware extends Middleware.Class[] | undefined, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined> = DeferredFunction.Options & {
|
|
76
|
+
schema?: TSchema;
|
|
77
|
+
middleware?: TFnMiddleware;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
81
|
+
* a major version bump.
|
|
82
|
+
*
|
|
83
|
+
* Create a typed defer function. One `createDefer` call = one Inngest
|
|
84
|
+
* function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id,
|
|
85
|
+
* { function, data })` get the data type inferred from the schema.
|
|
86
|
+
*
|
|
87
|
+
* Mirrors `inngest.createFunction(opts, handler)`, with three differences:
|
|
88
|
+
* the client is the first positional arg, `triggers` is not accepted (the
|
|
89
|
+
* SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema`
|
|
90
|
+
* describes the payload that callers will send via `defer(id, { function,
|
|
91
|
+
* data })`.
|
|
92
|
+
*
|
|
93
|
+
* Pass the result to `serve()` alongside regular functions so the SDK
|
|
94
|
+
* registers it.
|
|
95
|
+
*/
|
|
96
|
+
declare function createDefer<TClient extends Inngest.Any, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined, const TFnMiddleware extends Middleware.Class[] | undefined = undefined, THandler extends Handler.Any = (ctx: BaseDeferCtx<TClient, TFnMiddleware, TSchema> & ApplyAllMiddlewareCtxExtensions<[...ReturnType<typeof builtInMiddleware>]> & ApplyAllMiddlewareCtxExtensions<ClientOptionsFromInngest<TClient>["middleware"]> & ApplyAllMiddlewareCtxExtensions<TFnMiddleware>) => unknown>(client: TClient, options: CreateDeferInput<TFnMiddleware, TSchema>, handler: THandler): DeferredFunction<TSchema>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { DeferredFunction, createDefer };
|
|
99
|
+
//# sourceMappingURL=DeferredFunction.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredFunction.d.cts","names":[],"sources":["../../src/components/DeferredFunction.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;AAsCK,cAtCQ,gBAsCR,CAAA,gBApCC,gBAoCD,CApCkB,MAoClB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,GAAA,SAAA,GAAA,SAAA,CAAA,SAlCK,eAkCL,CAjCH,eAAA,CAAgB,OAiCb,CAAA,EAAA,EAAA,KAAA,CAAA,EAhCH,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import { Marker, markerKey } from "../helpers/marker.js";
|
|
3
|
+
import { Middleware } from "./middleware/middleware.js";
|
|
4
|
+
import { createStepTools } from "./InngestStepTools.js";
|
|
5
|
+
import { InngestFunction } from "./InngestFunction.js";
|
|
6
|
+
import { ApplyAllMiddlewareCtxExtensions, ApplyAllMiddlewareStepExtensions, BaseContext, FunctionConfig, Handler } from "../types.js";
|
|
7
|
+
import { ClientOptionsFromInngest, Inngest, builtInMiddleware } from "./Inngest.js";
|
|
8
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
9
|
+
|
|
10
|
+
//#region src/components/DeferredFunction.d.ts
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
14
|
+
* a major version bump.
|
|
15
|
+
*
|
|
16
|
+
* A defer (companion) function created via `createDefer(...)`. Real
|
|
17
|
+
* `InngestFunction` at runtime, but with the trigger pinned to
|
|
18
|
+
* `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and
|
|
19
|
+
* `onFailure` disallowed, and the schema carried as a typed instance
|
|
20
|
+
* property so callers of `defer(id, { function, data })` can extract it.
|
|
21
|
+
*
|
|
22
|
+
* Identify a defer function at runtime via `isDeferredFunction(value)` from
|
|
23
|
+
* `helpers/marker.ts`. Prefer that over `instanceof`, which fails across
|
|
24
|
+
* duplicate SDK copies in the same process.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare class DeferredFunction<TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined> extends InngestFunction<InngestFunction.Options<[], never>, Handler.Any, never, Inngest.Any, []> {
|
|
29
|
+
readonly schema: TSchema;
|
|
30
|
+
readonly [markerKey]: Marker;
|
|
31
|
+
constructor(client: Inngest.Any, opts: DeferredFunction.Options, handler: Handler.Any, schema: TSchema);
|
|
32
|
+
protected getConfigTriggers(fnId: string): FunctionConfig["triggers"];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
declare namespace DeferredFunction {
|
|
38
|
+
/**
|
|
39
|
+
* Matches any `DeferredFunction` regardless of its schema. Use as the
|
|
40
|
+
* constraint for the `function` argument of `defer()`.
|
|
41
|
+
*/
|
|
42
|
+
type Any = DeferredFunction<StandardSchemaV1<any> | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* The user-facing options accepted by `createDefer(client, opts, handler)`.
|
|
45
|
+
* Mirrors `InngestFunction.Options` minus `triggers` (implicit), `onFailure`
|
|
46
|
+
* (not yet supported), and `batchEvents` (each `defer(...)` is its own run).
|
|
47
|
+
*/
|
|
48
|
+
type Options = Omit<InngestFunction.Options<[], never>, "triggers" | "onFailure" | "batchEvents">;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The `event` shape a defer handler receives. With a schema, `data`
|
|
52
|
+
* narrows to its inferred type; without one, it falls back to
|
|
53
|
+
* `Record<string, any>`.
|
|
54
|
+
*/
|
|
55
|
+
type DeferEvent<TSchema> = {
|
|
56
|
+
name: internalEvents.DeferredSchedule;
|
|
57
|
+
data: TSchema extends StandardSchemaV1<infer D extends Record<string, unknown>> ? D : Record<string, any>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Base ctx shape for a defer handler: the standard function context
|
|
61
|
+
* (`runId`, `attempt`, `group`, `step` with middleware step extensions)
|
|
62
|
+
* with `event`/`events` pinned to `inngest/deferred.schedule` and the
|
|
63
|
+
* schema-typed payload.
|
|
64
|
+
*/
|
|
65
|
+
type BaseDeferCtx<TClient extends Inngest.Any, TFnMiddleware extends Middleware.Class[] | undefined, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined> = Omit<BaseContext<TClient>, "event" | "events" | "step"> & {
|
|
66
|
+
event: DeferEvent<TSchema>;
|
|
67
|
+
events: [DeferEvent<TSchema>];
|
|
68
|
+
step: ReturnType<typeof createStepTools<TClient, TFnMiddleware>> & ApplyAllMiddlewareStepExtensions<ClientOptionsFromInngest<TClient>["middleware"]> & ApplyAllMiddlewareStepExtensions<TFnMiddleware>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Input type for `createDefer`. Same shape as `DeferredFunction.Options`
|
|
72
|
+
* plus `schema` (the StandardSchema describing `event.data` that flows
|
|
73
|
+
* to caller `defer(id, { function, data })` call sites) and `middleware`.
|
|
74
|
+
*/
|
|
75
|
+
type CreateDeferInput<TFnMiddleware extends Middleware.Class[] | undefined, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined> = DeferredFunction.Options & {
|
|
76
|
+
schema?: TSchema;
|
|
77
|
+
middleware?: TFnMiddleware;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
81
|
+
* a major version bump.
|
|
82
|
+
*
|
|
83
|
+
* Create a typed defer function. One `createDefer` call = one Inngest
|
|
84
|
+
* function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id,
|
|
85
|
+
* { function, data })` get the data type inferred from the schema.
|
|
86
|
+
*
|
|
87
|
+
* Mirrors `inngest.createFunction(opts, handler)`, with three differences:
|
|
88
|
+
* the client is the first positional arg, `triggers` is not accepted (the
|
|
89
|
+
* SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema`
|
|
90
|
+
* describes the payload that callers will send via `defer(id, { function,
|
|
91
|
+
* data })`.
|
|
92
|
+
*
|
|
93
|
+
* Pass the result to `serve()` alongside regular functions so the SDK
|
|
94
|
+
* registers it.
|
|
95
|
+
*/
|
|
96
|
+
declare function createDefer<TClient extends Inngest.Any, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined, const TFnMiddleware extends Middleware.Class[] | undefined = undefined, THandler extends Handler.Any = (ctx: BaseDeferCtx<TClient, TFnMiddleware, TSchema> & ApplyAllMiddlewareCtxExtensions<[...ReturnType<typeof builtInMiddleware>]> & ApplyAllMiddlewareCtxExtensions<ClientOptionsFromInngest<TClient>["middleware"]> & ApplyAllMiddlewareCtxExtensions<TFnMiddleware>) => unknown>(client: TClient, options: CreateDeferInput<TFnMiddleware, TSchema>, handler: THandler): DeferredFunction<TSchema>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { DeferredFunction, createDefer };
|
|
99
|
+
//# sourceMappingURL=DeferredFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredFunction.d.ts","names":[],"sources":["../../src/components/DeferredFunction.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;AAsCK,cAtCQ,gBAsCR,CAAA,gBApCC,gBAoCD,CApCkB,MAoClB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,GAAA,SAAA,GAAA,SAAA,CAAA,SAlCK,eAkCL,CAjCH,eAAA,CAAgB,OAiCb,CAAA,EAAA,EAAA,KAAA,CAAA,EAhCH,OAAA,CAAQ,GAgCL,EAAA,KAAA,EA9BH,OAAA,CAAQ,GA8BL,EAAA;EAlCoB,SAAA,MAAA,EAON,OAPM;EA+CR,UAvCL,SAAA,CAuCqB,EAvCT,MAuCS;EAAA,WAAA,CAAA,MAAA,EApCrB,OAAA,CAAQ,GAoCa,EAAA,IAAA,EAnCvB,gBAAA,CAAiB,OAmCM,EAAA,OAAA,EAlCpB,OAAA,CAAQ,GAkCY,EAAA,MAAA,EAjCrB,OAiCqB;YAMI,iBAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAnBhC,cAmBgC,CAAA,UAAA,CAAA;;;;;AAkBhC,kBAxBY,gBAAA,CAwBF;EAAA;;;;OAES,GAAA,GApBJ,gBAoBI,CApBa,gBAoBb,CAAA,GAAA,CAAA,GAAA,SAAA,CAAA;;;;AAKZ;;OAUM,OAAQ,GA5BF,IA4BE,CA3BtB,eAAA,CAAgB,OA2BM,CAAA,EAAA,EAAA,KAAA,CAAA,EAAA,UAAA,GAAA,WAAA,GAAA,aAAA,CAAA;;;;;;;KAjBrB,UAqBe,CA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,CAAW,KASnC,EAAA,GAAA,SAAA,GAAA,SAAA,EAAA,iBARa,OAAA,CAAQ,GAQrB,GAAA,CAAA,GAAA,EAPG,YAOH,CAPgB,OAOhB,EAPyB,aAOzB,EAPwC,OAOxC,CAAA,GANA,+BAMA,CAAA,IALM,UAQF,CAAA,OARoB,iBAQpB,CAAA,KANJ,+BAOsB,CANpB,wBAMoB,CANK,OAML,CAAA,CAAA,YAAA,CAAA,CAAA,GAJtB,+BAIsB,CAJU,aAIV,CAAA,EAAA,GAAA,OAAA,CAAA,CAAA,MAAA,EADlB,OACkB,EAAA,OAAA,EAAjB,gBAAiB,CAAA,aAAA,EAAe,OAAf,CAAA,EAAA,OAAA,EACjB,QADiB,CAAA,EAEzB,gBAFyB,CAER,OAFQ,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { internalEvents } from "../helpers/consts.js";
|
|
2
|
+
import { markerKey } from "../helpers/marker.js";
|
|
3
|
+
import { InngestFunction } from "./InngestFunction.js";
|
|
4
|
+
|
|
5
|
+
//#region src/components/DeferredFunction.ts
|
|
6
|
+
const idDenyRegex = /['\\\n\r]/;
|
|
7
|
+
/**
|
|
8
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
9
|
+
* a major version bump.
|
|
10
|
+
*
|
|
11
|
+
* A defer (companion) function created via `createDefer(...)`. Real
|
|
12
|
+
* `InngestFunction` at runtime, but with the trigger pinned to
|
|
13
|
+
* `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and
|
|
14
|
+
* `onFailure` disallowed, and the schema carried as a typed instance
|
|
15
|
+
* property so callers of `defer(id, { function, data })` can extract it.
|
|
16
|
+
*
|
|
17
|
+
* Identify a defer function at runtime via `isDeferredFunction(value)` from
|
|
18
|
+
* `helpers/marker.ts`. Prefer that over `instanceof`, which fails across
|
|
19
|
+
* duplicate SDK copies in the same process.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
var DeferredFunction = class extends InngestFunction {
|
|
24
|
+
schema;
|
|
25
|
+
[markerKey] = { kind: "deferredFunction" };
|
|
26
|
+
constructor(client, opts, handler, schema) {
|
|
27
|
+
if (idDenyRegex.test(opts.id)) throw new Error(`invalid id "${opts.id}"; must match ${idDenyRegex.source}`);
|
|
28
|
+
super(client, {
|
|
29
|
+
...opts,
|
|
30
|
+
triggers: []
|
|
31
|
+
}, handler);
|
|
32
|
+
this.schema = schema;
|
|
33
|
+
}
|
|
34
|
+
getConfigTriggers(fnId) {
|
|
35
|
+
return [{
|
|
36
|
+
event: internalEvents.DeferredSchedule,
|
|
37
|
+
expression: `event.data._inngest.fn_slug == '${fnId}'`
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* EXPERIMENTAL: This API is not yet stable and may change in the future without
|
|
43
|
+
* a major version bump.
|
|
44
|
+
*
|
|
45
|
+
* Create a typed defer function. One `createDefer` call = one Inngest
|
|
46
|
+
* function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id,
|
|
47
|
+
* { function, data })` get the data type inferred from the schema.
|
|
48
|
+
*
|
|
49
|
+
* Mirrors `inngest.createFunction(opts, handler)`, with three differences:
|
|
50
|
+
* the client is the first positional arg, `triggers` is not accepted (the
|
|
51
|
+
* SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema`
|
|
52
|
+
* describes the payload that callers will send via `defer(id, { function,
|
|
53
|
+
* data })`.
|
|
54
|
+
*
|
|
55
|
+
* Pass the result to `serve()` alongside regular functions so the SDK
|
|
56
|
+
* registers it.
|
|
57
|
+
*/
|
|
58
|
+
function createDefer(client, options, handler) {
|
|
59
|
+
const { schema, ...rest } = options;
|
|
60
|
+
return new DeferredFunction(client, rest, handler, schema);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { DeferredFunction, createDefer };
|
|
65
|
+
//# sourceMappingURL=DeferredFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeferredFunction.js","names":[],"sources":["../../src/components/DeferredFunction.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { internalEvents } from \"../helpers/consts.ts\";\nimport { type Marker, markerKey } from \"../helpers/marker.ts\";\nimport type {\n ApplyAllMiddlewareCtxExtensions,\n ApplyAllMiddlewareStepExtensions,\n BaseContext,\n FunctionConfig,\n Handler,\n} from \"../types.ts\";\nimport type {\n builtInMiddleware,\n ClientOptionsFromInngest,\n Inngest,\n} from \"./Inngest.ts\";\nimport { InngestFunction } from \"./InngestFunction.ts\";\nimport type { createStepTools } from \"./InngestStepTools.ts\";\nimport type { Middleware } from \"./middleware/index.ts\";\n\nconst idDenyRegex = /['\\\\\\n\\r]/;\n\n/**\n * EXPERIMENTAL: This API is not yet stable and may change in the future without\n * a major version bump.\n *\n * A defer (companion) function created via `createDefer(...)`. Real\n * `InngestFunction` at runtime, but with the trigger pinned to\n * `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and\n * `onFailure` disallowed, and the schema carried as a typed instance\n * property so callers of `defer(id, { function, data })` can extract it.\n *\n * Identify a defer function at runtime via `isDeferredFunction(value)` from\n * `helpers/marker.ts`. Prefer that over `instanceof`, which fails across\n * duplicate SDK copies in the same process.\n *\n * @public\n */\nexport class DeferredFunction<\n TSchema extends\n | StandardSchemaV1<Record<string, unknown>>\n | undefined = undefined,\n> extends InngestFunction<\n InngestFunction.Options<[], never>,\n Handler.Any,\n never,\n Inngest.Any,\n []\n> {\n readonly schema: TSchema;\n readonly [markerKey]: Marker = { kind: \"deferredFunction\" };\n\n constructor(\n client: Inngest.Any,\n opts: DeferredFunction.Options,\n handler: Handler.Any,\n schema: TSchema,\n ) {\n // The id is interpolated into a CEL trigger expression\n // (`event.data._inngest.fn_slug == '${fnId}'`). Reject characters that\n // would break the single-quoted string literal.\n if (idDenyRegex.test(opts.id)) {\n throw new Error(\n `invalid id \"${opts.id}\"; must match ${idDenyRegex.source}`,\n );\n }\n super(\n client,\n { ...opts, triggers: [] } as InngestFunction.Options<[], never>,\n handler,\n );\n this.schema = schema;\n }\n\n protected override getConfigTriggers(\n fnId: string,\n ): FunctionConfig[\"triggers\"] {\n return [\n {\n event: internalEvents.DeferredSchedule,\n expression: `event.data._inngest.fn_slug == '${fnId}'`,\n },\n ];\n }\n}\n\n/**\n * @public\n */\nexport namespace DeferredFunction {\n /**\n * Matches any `DeferredFunction` regardless of its schema. Use as the\n * constraint for the `function` argument of `defer()`.\n */\n // biome-ignore lint/suspicious/noExplicitAny: widest schema constraint for inference\n export type Any = DeferredFunction<StandardSchemaV1<any> | undefined>;\n\n /**\n * The user-facing options accepted by `createDefer(client, opts, handler)`.\n * Mirrors `InngestFunction.Options` minus `triggers` (implicit), `onFailure`\n * (not yet supported), and `batchEvents` (each `defer(...)` is its own run).\n */\n export type Options = Omit<\n InngestFunction.Options<[], never>,\n \"triggers\" | \"onFailure\" | \"batchEvents\"\n >;\n}\n\n/**\n * The `event` shape a defer handler receives. With a schema, `data`\n * narrows to its inferred type; without one, it falls back to\n * `Record<string, any>`.\n */\ntype DeferEvent<TSchema> = {\n name: internalEvents.DeferredSchedule;\n data: TSchema extends StandardSchemaV1<\n infer D extends Record<string, unknown>\n >\n ? D\n : // biome-ignore lint/suspicious/noExplicitAny: no schema = any\n Record<string, any>;\n};\n\n/**\n * Base ctx shape for a defer handler: the standard function context\n * (`runId`, `attempt`, `group`, `step` with middleware step extensions)\n * with `event`/`events` pinned to `inngest/deferred.schedule` and the\n * schema-typed payload.\n */\ntype BaseDeferCtx<\n TClient extends Inngest.Any,\n TFnMiddleware extends Middleware.Class[] | undefined,\n TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined,\n> = Omit<BaseContext<TClient>, \"event\" | \"events\" | \"step\"> & {\n event: DeferEvent<TSchema>;\n events: [DeferEvent<TSchema>];\n step: ReturnType<typeof createStepTools<TClient, TFnMiddleware>> &\n ApplyAllMiddlewareStepExtensions<\n ClientOptionsFromInngest<TClient>[\"middleware\"]\n > &\n ApplyAllMiddlewareStepExtensions<TFnMiddleware>;\n};\n\n/**\n * Input type for `createDefer`. Same shape as `DeferredFunction.Options`\n * plus `schema` (the StandardSchema describing `event.data` that flows\n * to caller `defer(id, { function, data })` call sites) and `middleware`.\n */\nexport type CreateDeferInput<\n TFnMiddleware extends Middleware.Class[] | undefined,\n TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined,\n> = DeferredFunction.Options & {\n schema?: TSchema;\n middleware?: TFnMiddleware;\n};\n\n/**\n * EXPERIMENTAL: This API is not yet stable and may change in the future without\n * a major version bump.\n *\n * Create a typed defer function. One `createDefer` call = one Inngest\n * function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id,\n * { function, data })` get the data type inferred from the schema.\n *\n * Mirrors `inngest.createFunction(opts, handler)`, with three differences:\n * the client is the first positional arg, `triggers` is not accepted (the\n * SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema`\n * describes the payload that callers will send via `defer(id, { function,\n * data })`.\n *\n * Pass the result to `serve()` alongside regular functions so the SDK\n * registers it.\n */\nexport function createDefer<\n TClient extends Inngest.Any,\n TSchema extends\n | StandardSchemaV1<Record<string, unknown>>\n | undefined = undefined,\n const TFnMiddleware extends Middleware.Class[] | undefined = undefined,\n THandler extends Handler.Any = (\n ctx: BaseDeferCtx<TClient, TFnMiddleware, TSchema> &\n ApplyAllMiddlewareCtxExtensions<\n [...ReturnType<typeof builtInMiddleware>]\n > &\n ApplyAllMiddlewareCtxExtensions<\n ClientOptionsFromInngest<TClient>[\"middleware\"]\n > &\n ApplyAllMiddlewareCtxExtensions<TFnMiddleware>,\n ) => unknown,\n>(\n client: TClient,\n options: CreateDeferInput<TFnMiddleware, TSchema>,\n handler: THandler,\n): DeferredFunction<TSchema> {\n const { schema, ...rest } = options;\n return new DeferredFunction<TSchema>(\n client,\n rest,\n handler as Handler.Any,\n schema as TSchema,\n );\n}\n"],"mappings":";;;;;AAmBA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,IAAa,mBAAb,cAIU,gBAMR;CACA,AAAS;CACT,CAAU,aAAqB,EAAE,MAAM,oBAAoB;CAE3D,YACE,QACA,MACA,SACA,QACA;AAIA,MAAI,YAAY,KAAK,KAAK,GAAG,CAC3B,OAAM,IAAI,MACR,eAAe,KAAK,GAAG,gBAAgB,YAAY,SACpD;AAEH,QACE,QACA;GAAE,GAAG;GAAM,UAAU,EAAE;GAAE,EACzB,QACD;AACD,OAAK,SAAS;;CAGhB,AAAmB,kBACjB,MAC4B;AAC5B,SAAO,CACL;GACE,OAAO,eAAe;GACtB,YAAY,mCAAmC,KAAK;GACrD,CACF;;;;;;;;;;;;;;;;;;;;AA2FL,SAAgB,YAiBd,QACA,SACA,SAC2B;CAC3B,MAAM,EAAE,QAAQ,GAAG,SAAS;AAC5B,QAAO,IAAI,iBACT,QACA,MACA,SACA,OACD"}
|
package/components/Inngest.cjs
CHANGED
|
@@ -576,10 +576,13 @@ function builtInMiddleware(baseLogger) {
|
|
|
576
576
|
transformFunctionInput(arg) {
|
|
577
577
|
let logger = baseLogger;
|
|
578
578
|
if ("child" in logger) try {
|
|
579
|
-
|
|
579
|
+
const childMetadata = {
|
|
580
580
|
runID: arg.ctx.runId,
|
|
581
581
|
eventName: arg.ctx.event.name
|
|
582
|
-
}
|
|
582
|
+
};
|
|
583
|
+
if (typeof arg.ctx.requestId !== "undefined") childMetadata.requestId = arg.ctx.requestId;
|
|
584
|
+
if (typeof arg.ctx.jobId !== "undefined") childMetadata.jobId = arg.ctx.jobId;
|
|
585
|
+
logger = logger.child(childMetadata);
|
|
583
586
|
} catch (err) {
|
|
584
587
|
logger.error({ err }, "failed to create \"childLogger\" with error");
|
|
585
588
|
}
|