effect-inngest 0.1.3 → 0.3.0-beta.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.
Files changed (141) hide show
  1. package/README.md +89 -67
  2. package/dist/Client.d.ts +76 -28
  3. package/dist/Client.js +92 -30
  4. package/dist/Event.d.ts +43 -0
  5. package/dist/Event.js +46 -0
  6. package/dist/Events.d.ts +48 -76
  7. package/dist/Events.js +18 -23
  8. package/dist/Function.d.ts +46 -19
  9. package/dist/Function.js +32 -22
  10. package/dist/Group.d.ts +19 -8
  11. package/dist/Group.js +30 -72
  12. package/dist/HttpApi.d.ts +51 -56
  13. package/dist/HttpApi.js +38 -21
  14. package/dist/_virtual/_rolldown/runtime.js +13 -0
  15. package/dist/index.d.ts +2 -1
  16. package/dist/index.js +3 -3
  17. package/dist/internal/checkpoint/Config.d.ts +10 -0
  18. package/dist/internal/checkpoint/Config.js +29 -0
  19. package/dist/internal/checkpoint/Error.d.ts +11 -0
  20. package/dist/internal/checkpoint/Error.js +8 -0
  21. package/dist/internal/checkpoint/State.d.ts +1 -0
  22. package/dist/internal/checkpoint/State.js +54 -0
  23. package/dist/internal/checkpoint.d.ts +2 -0
  24. package/dist/internal/codec/EventPayload.d.ts +6 -0
  25. package/dist/internal/codec/EventPayload.js +60 -0
  26. package/dist/internal/codec/StepResult.js +55 -0
  27. package/dist/internal/domain/ExecutionInput.d.ts +40 -0
  28. package/dist/internal/domain/ExecutionInput.js +57 -0
  29. package/dist/internal/domain/ExecutionSuspension.d.ts +34 -0
  30. package/dist/internal/domain/ExecutionSuspension.js +64 -0
  31. package/dist/internal/domain/FunctionDefinition.js +13 -0
  32. package/dist/internal/domain/Memo.d.ts +22 -0
  33. package/dist/internal/domain/Memo.js +18 -0
  34. package/dist/internal/domain/StepCommand.d.ts +79 -0
  35. package/dist/internal/domain/StepCommand.js +124 -0
  36. package/dist/internal/domain/StepInfo.d.ts +12 -0
  37. package/dist/internal/domain/StepInfo.js +10 -0
  38. package/dist/internal/domain/StepInput.d.ts +10 -0
  39. package/dist/internal/driver.js +15 -114
  40. package/dist/internal/errors.d.ts +21 -48
  41. package/dist/internal/errors.js +9 -44
  42. package/dist/internal/execution/CheckpointRun.js +25 -0
  43. package/dist/internal/execution/ExecutionFailure.js +19 -0
  44. package/dist/internal/execution/ExecutionHeaders.js +58 -0
  45. package/dist/internal/execution/ExecutionResponse.js +68 -0
  46. package/dist/internal/execution/ExecutionResult.js +56 -0
  47. package/dist/internal/execution/ExecutionScope.js +30 -0
  48. package/dist/internal/execution/HandlerRun.js +16 -0
  49. package/dist/internal/handler.d.ts +5 -16
  50. package/dist/internal/handler.js +128 -96
  51. package/dist/internal/protocol.d.ts +143 -1
  52. package/dist/internal/protocol.js +333 -138
  53. package/dist/internal/runtime/CheckpointContext.js +5 -0
  54. package/dist/internal/runtime/HandlerContext.d.ts +13 -0
  55. package/dist/internal/runtime/HandlerContext.js +19 -0
  56. package/dist/internal/runtime/HandlerFiberScope.d.ts +10 -0
  57. package/dist/internal/runtime/HandlerFiberScope.js +5 -0
  58. package/dist/internal/runtime/StepCommandBus.d.ts +27 -0
  59. package/dist/internal/runtime/StepCommandBus.js +76 -0
  60. package/dist/internal/runtime/StepIdentity.d.ts +27 -0
  61. package/dist/internal/runtime/StepIdentity.js +46 -0
  62. package/dist/internal/runtime/StepTools.d.ts +83 -0
  63. package/dist/internal/runtime/StepTools.js +76 -0
  64. package/dist/internal/runtime/steps/InvokeStep.js +43 -0
  65. package/dist/internal/runtime/steps/SendEventStep.js +46 -0
  66. package/dist/internal/runtime/steps/SleepStep.js +22 -0
  67. package/dist/internal/runtime/steps/SleepUntilStep.js +22 -0
  68. package/dist/internal/runtime/steps/StepRun.js +48 -0
  69. package/dist/internal/runtime/steps/WaitForEventStep.js +27 -0
  70. package/dist/internal/serve/HttpApp.js +71 -0
  71. package/dist/internal/serve/Request.js +23 -0
  72. package/dist/internal/serve/Signature.d.ts +11 -0
  73. package/dist/internal/serve/Signature.js +123 -0
  74. package/dist/internal/wire/Duration.js +19 -0
  75. package/dist/internal/wire/Timestamp.js +14 -0
  76. package/package.json +34 -22
  77. package/src/Client.ts +269 -91
  78. package/src/Event.ts +107 -0
  79. package/src/Events.ts +50 -30
  80. package/src/Function.ts +102 -46
  81. package/src/Group.ts +56 -108
  82. package/src/HttpApi.ts +40 -30
  83. package/src/index.ts +21 -11
  84. package/src/internal/checkpoint/Config.ts +74 -0
  85. package/src/internal/checkpoint/Error.ts +6 -0
  86. package/src/internal/checkpoint/State.ts +107 -0
  87. package/src/internal/checkpoint.ts +3 -0
  88. package/src/internal/codec/EventPayload.ts +98 -0
  89. package/src/internal/codec/StepResult.ts +95 -0
  90. package/src/internal/domain/ExecutionInput.ts +66 -0
  91. package/src/internal/domain/ExecutionSuspension.ts +79 -0
  92. package/src/internal/domain/FunctionDefinition.ts +30 -0
  93. package/src/internal/domain/Memo.ts +28 -0
  94. package/src/internal/domain/StepCommand.ts +166 -0
  95. package/src/internal/domain/StepInfo.ts +8 -0
  96. package/src/internal/domain/StepInput.ts +10 -0
  97. package/src/internal/driver.ts +27 -185
  98. package/src/internal/errors.ts +14 -108
  99. package/src/internal/execution/CheckpointRun.ts +33 -0
  100. package/src/internal/execution/ExecutionFailure.ts +19 -0
  101. package/src/internal/execution/ExecutionHeaders.ts +86 -0
  102. package/src/internal/execution/ExecutionResponse.ts +79 -0
  103. package/src/internal/execution/ExecutionResult.ts +57 -0
  104. package/src/internal/execution/ExecutionScope.ts +41 -0
  105. package/src/internal/execution/HandlerRun.ts +38 -0
  106. package/src/internal/handler.ts +222 -172
  107. package/src/internal/protocol.ts +289 -78
  108. package/src/internal/runtime/CheckpointContext.ts +7 -0
  109. package/src/internal/runtime/HandlerContext.ts +21 -0
  110. package/src/internal/runtime/HandlerFiberScope.ts +9 -0
  111. package/src/internal/runtime/StepCommandBus.ts +129 -0
  112. package/src/internal/runtime/StepIdentity.ts +67 -0
  113. package/src/internal/runtime/StepTools.ts +161 -0
  114. package/src/internal/runtime/steps/InvokeStep.ts +71 -0
  115. package/src/internal/runtime/steps/SendEventStep.ts +67 -0
  116. package/src/internal/runtime/steps/SleepStep.ts +34 -0
  117. package/src/internal/runtime/steps/SleepUntilStep.ts +34 -0
  118. package/src/internal/runtime/steps/StepRun.ts +95 -0
  119. package/src/internal/runtime/steps/WaitForEventStep.ts +55 -0
  120. package/src/internal/serve/HttpApp.ts +123 -0
  121. package/src/internal/serve/Request.ts +27 -0
  122. package/src/internal/serve/Signature.ts +170 -0
  123. package/src/internal/wire/Duration.ts +31 -0
  124. package/src/internal/wire/Timestamp.ts +11 -0
  125. package/dist/_virtual/rolldown_runtime.js +0 -18
  126. package/dist/internal/constants.js +0 -15
  127. package/dist/internal/driver.d.ts +0 -5
  128. package/dist/internal/helpers.js +0 -44
  129. package/dist/internal/interrupts.d.ts +0 -2
  130. package/dist/internal/interrupts.js +0 -45
  131. package/dist/internal/memo.js +0 -56
  132. package/dist/internal/signature.d.ts +0 -18
  133. package/dist/internal/signature.js +0 -97
  134. package/dist/internal/step.d.ts +0 -59
  135. package/dist/internal/step.js +0 -192
  136. package/src/internal/constants.ts +0 -11
  137. package/src/internal/helpers.ts +0 -58
  138. package/src/internal/interrupts.ts +0 -62
  139. package/src/internal/memo.ts +0 -73
  140. package/src/internal/signature.ts +0 -158
  141. package/src/internal/step.ts +0 -394
@@ -0,0 +1,43 @@
1
+ import { Schema } from "effect";
2
+ import { MakeOptions } from "effect/Schema";
3
+
4
+ //#region src/Event.d.ts
5
+ declare namespace Event_d_exports {
6
+ export { EventData, EventDefinition, EventEnvelope, EventType, isEventSchema, make };
7
+ }
8
+ declare const TypeId: unique symbol;
9
+ interface EventOptions extends MakeOptions {
10
+ readonly id?: string;
11
+ readonly ts?: number;
12
+ readonly v?: string;
13
+ }
14
+ interface EventEnvelope<Name extends string, Data> extends EventOptions {
15
+ readonly name: Name;
16
+ readonly data: Data;
17
+ }
18
+ type EventFields<Name extends string, DataSchema extends Schema.Top> = {
19
+ readonly name: Schema.tag<Name>;
20
+ readonly data: DataSchema;
21
+ readonly id: Schema.optional<Schema.String>;
22
+ readonly ts: Schema.optional<Schema.Number>;
23
+ readonly v: Schema.optional<Schema.String>;
24
+ };
25
+ type EventStruct<Name extends string, DataSchema extends Schema.Top> = Schema.Struct<EventFields<Name, DataSchema>>;
26
+ type EventConstructor<Name extends string, DataSchema extends Schema.Top> = abstract new (_: never) => EventEnvelope<Name, Schema.Schema.Type<DataSchema>>;
27
+ type PayloadConstructor<Name extends string, DataSchema extends Schema.Top> = {
28
+ bivariance(data: Schema.Schema.Type<DataSchema>, options?: EventOptions): EventEnvelope<Name, Schema.Schema.Type<DataSchema>>;
29
+ }["bivariance"];
30
+ type EventDefinition<Name extends string = string, DataSchema extends Schema.Top = Schema.Top> = EventConstructor<Name, DataSchema> & Omit<Schema.Opaque<EventEnvelope<Name, Schema.Schema.Type<DataSchema>>, EventStruct<Name, DataSchema>, {}>, "make" | "~type.make"> & {
31
+ readonly [TypeId]: typeof TypeId;
32
+ readonly identifier: Name;
33
+ readonly schema: DataSchema;
34
+ readonly make: unknown extends Schema.Schema.Type<DataSchema> ? (data: never, options?: EventOptions) => EventEnvelope<Name, unknown> : PayloadConstructor<Name, DataSchema>;
35
+ readonly "~type.make": EventEnvelope<Name, Schema.Schema.Type<DataSchema>>;
36
+ };
37
+ type EventData<Event extends EventDefinition> = Event extends EventDefinition<any, infer S> ? Schema.Schema.Type<S> : never;
38
+ type EventType<Event extends EventDefinition> = Event extends EventDefinition<infer Name, infer S> ? EventEnvelope<Name, Schema.Schema.Type<S>> : never;
39
+ declare function make<const Name extends string>(name: Name): EventDefinition<Name, Schema.Struct<{}>>;
40
+ declare function make<const Name extends string, const DataSchema extends Schema.Top>(name: Name, schema: DataSchema): EventDefinition<Name, DataSchema>;
41
+ declare const isEventSchema: (value: unknown) => value is EventDefinition;
42
+ //#endregion
43
+ export { EventDefinition, EventType, Event_d_exports };
package/dist/Event.js ADDED
@@ -0,0 +1,46 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { Predicate, Schema } from "effect";
3
+ //#region src/Event.ts
4
+ /**
5
+ * Public event definitions.
6
+ *
7
+ * Inngest events are protocol-shaped: `{ name, data, id?, ts?, v? }`.
8
+ * The event name is the discriminator; user payload lives under `data`.
9
+ *
10
+ * @since 0.1.0
11
+ */
12
+ var Event_exports = /* @__PURE__ */ __exportAll({
13
+ isEventSchema: () => isEventSchema,
14
+ make: () => make
15
+ });
16
+ const TypeId = Symbol.for("effect-inngest/Event");
17
+ function make(name, schema = Schema.Struct({})) {
18
+ const fields = {
19
+ name: Schema.tag(name),
20
+ data: schema,
21
+ id: Schema.optional(Schema.String),
22
+ ts: Schema.optional(Schema.Number),
23
+ v: Schema.optional(Schema.String)
24
+ };
25
+ const Event = Schema.Opaque()(Schema.Struct(fields));
26
+ class InngestEvent {
27
+ static [TypeId] = TypeId;
28
+ static identifier = name;
29
+ static schema = schema;
30
+ static make(data, options) {
31
+ const { id, ts, v } = options ?? {};
32
+ return {
33
+ name,
34
+ data,
35
+ id,
36
+ ts,
37
+ v
38
+ };
39
+ }
40
+ }
41
+ Object.setPrototypeOf(InngestEvent, Event);
42
+ return InngestEvent;
43
+ }
44
+ const isEventSchema = (value) => Schema.isSchema(value) && Predicate.hasProperty(value, TypeId);
45
+ //#endregion
46
+ export { Event_exports, make };
package/dist/Events.d.ts CHANGED
@@ -1,110 +1,82 @@
1
- import * as Schema from "effect/Schema";
1
+ import { EventDefinition } from "./Event.js";
2
+ import { Schema } from "effect";
2
3
 
3
4
  //#region src/Events.d.ts
4
5
  declare namespace Events_d_exports {
5
6
  export { FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
6
7
  }
7
- declare const JsonError_base: Schema.Class<JsonError, {
8
- name: typeof Schema.String;
9
- message: typeof Schema.String;
10
- stack: Schema.optional<typeof Schema.String>;
11
- cause: Schema.optional<typeof Schema.Unknown>;
12
- }, Schema.Struct.Encoded<{
13
- name: typeof Schema.String;
14
- message: typeof Schema.String;
15
- stack: Schema.optional<typeof Schema.String>;
16
- cause: Schema.optional<typeof Schema.Unknown>;
17
- }>, never, {
18
- readonly name: string;
19
- } & {
20
- readonly message: string;
21
- } & {
22
- readonly stack?: string | undefined;
23
- } & {
24
- readonly cause?: unknown;
25
- }, {}, {}>;
8
+ declare const JsonError_base: Schema.Class<JsonError, Schema.Struct<{
9
+ readonly name: Schema.String;
10
+ readonly message: Schema.String;
11
+ readonly stack: Schema.optional<Schema.String>;
12
+ readonly cause: Schema.optional<Schema.Unknown>;
13
+ }>, {}>;
26
14
  /**
27
15
  * Error structure used in internal Inngest events.
28
16
  * @since 0.1.0
29
17
  */
30
18
  declare class JsonError extends JsonError_base {}
31
- declare const FunctionFailed_base: Schema.TaggedClass<FunctionFailed, "inngest/function.failed", {
32
- readonly _tag: Schema.tag<"inngest/function.failed">;
33
- } & {
34
- function_id: typeof Schema.String;
35
- run_id: typeof Schema.String;
36
- error: typeof JsonError;
37
- event: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
38
- }>;
39
19
  /**
40
20
  * Sent when a function fails after exhausting all retries.
41
21
  * Trigger on this to handle failures (e.g., alerting, cleanup).
42
22
  * @since 0.1.0
43
23
  */
44
- declare class FunctionFailed extends FunctionFailed_base {}
45
- declare const FunctionFinishedError_base: Schema.TaggedClass<FunctionFinishedError, "inngest/function.finished", {
46
- readonly _tag: Schema.tag<"inngest/function.finished">;
47
- } & {
48
- function_id: typeof Schema.String;
49
- run_id: typeof Schema.String;
50
- correlation_id: Schema.optional<typeof Schema.String>;
51
- error: typeof JsonError;
52
- }>;
53
- /**
54
- * Sent when a function finishes with an error.
55
- * @since 0.1.0
56
- */
57
- declare class FunctionFinishedError extends FunctionFinishedError_base {}
58
- declare const FunctionFinishedSuccess_base: Schema.TaggedClass<FunctionFinishedSuccess, "inngest/function.finished", {
59
- readonly _tag: Schema.tag<"inngest/function.finished">;
60
- } & {
61
- function_id: typeof Schema.String;
62
- run_id: typeof Schema.String;
63
- correlation_id: Schema.optional<typeof Schema.String>;
64
- result: typeof Schema.Unknown;
65
- }>;
66
- /**
67
- * Sent when a function finishes successfully.
68
- * @since 0.1.0
69
- */
70
- declare class FunctionFinishedSuccess extends FunctionFinishedSuccess_base {}
24
+ declare const FunctionFailed: EventDefinition<"inngest/function.failed", Schema.Struct<{
25
+ readonly function_id: Schema.String;
26
+ readonly run_id: Schema.String;
27
+ readonly error: typeof JsonError;
28
+ readonly event: Schema.$Record<Schema.String, Schema.Unknown>;
29
+ }>>;
30
+ declare const FunctionFinishedError: EventDefinition<"inngest/function.finished", Schema.Struct<{
31
+ readonly function_id: Schema.String;
32
+ readonly run_id: Schema.String;
33
+ readonly correlation_id: Schema.optional<Schema.String>;
34
+ readonly error: typeof JsonError;
35
+ }>>;
36
+ declare const FunctionFinishedSuccess: EventDefinition<"inngest/function.finished", Schema.Struct<{
37
+ readonly function_id: Schema.String;
38
+ readonly run_id: Schema.String;
39
+ readonly correlation_id: Schema.optional<Schema.String>;
40
+ readonly result: Schema.Unknown;
41
+ }>>;
71
42
  /**
72
43
  * Union of both FunctionFinished variants.
73
44
  * @since 0.1.0
74
45
  */
75
- declare const FunctionFinished: Schema.Union<[typeof FunctionFinishedError, typeof FunctionFinishedSuccess]>;
46
+ declare const FunctionFinished: EventDefinition<"inngest/function.finished", Schema.Union<readonly [Schema.Struct<{
47
+ readonly function_id: Schema.String;
48
+ readonly run_id: Schema.String;
49
+ readonly correlation_id: Schema.optional<Schema.String>;
50
+ readonly error: typeof JsonError;
51
+ }>, Schema.Struct<{
52
+ readonly function_id: Schema.String;
53
+ readonly run_id: Schema.String;
54
+ readonly correlation_id: Schema.optional<Schema.String>;
55
+ readonly result: Schema.Unknown;
56
+ }>]>>;
76
57
  type FunctionFinished = typeof FunctionFinished.Type;
77
- declare const FunctionCancelled_base: Schema.TaggedClass<FunctionCancelled, "inngest/function.cancelled", {
78
- readonly _tag: Schema.tag<"inngest/function.cancelled">;
79
- } & {
80
- function_id: typeof Schema.String;
81
- run_id: typeof Schema.String;
82
- correlation_id: Schema.optional<typeof Schema.String>;
83
- }>;
84
58
  /**
85
59
  * Sent when a function is cancelled.
86
60
  * @since 0.1.0
87
61
  */
88
- declare class FunctionCancelled extends FunctionCancelled_base {}
89
- declare const FunctionInvoked_base: Schema.TaggedClass<FunctionInvoked, "inngest/function.invoked", {
90
- readonly _tag: Schema.tag<"inngest/function.invoked">;
91
- } & {
92
- data: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
93
- }>;
62
+ declare const FunctionCancelled: EventDefinition<"inngest/function.cancelled", Schema.Struct<{
63
+ readonly function_id: Schema.String;
64
+ readonly run_id: Schema.String;
65
+ readonly correlation_id: Schema.optional<Schema.String>;
66
+ }>>;
94
67
  /**
95
68
  * Sent when a function is invoked via step.invoke().
96
69
  * @since 0.1.0
97
70
  */
98
- declare class FunctionInvoked extends FunctionInvoked_base {}
99
- declare const ScheduledTimer_base: Schema.TaggedClass<ScheduledTimer, "inngest/scheduled.timer", {
100
- readonly _tag: Schema.tag<"inngest/scheduled.timer">;
101
- } & {
102
- cron: typeof Schema.String;
103
- }>;
71
+ declare const FunctionInvoked: EventDefinition<"inngest/function.invoked", Schema.StructWithRest<Schema.Struct<{
72
+ readonly _inngest: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
73
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
104
74
  /**
105
75
  * Sent when a cron trigger fires.
106
76
  * @since 0.1.0
107
77
  */
108
- declare class ScheduledTimer extends ScheduledTimer_base {}
78
+ declare const ScheduledTimer: EventDefinition<"inngest/scheduled.timer", Schema.Struct<{
79
+ readonly cron: Schema.String;
80
+ }>>;
109
81
  //#endregion
110
82
  export { Events_d_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
package/dist/Events.js CHANGED
@@ -1,6 +1,6 @@
1
- import { __exportAll } from "./_virtual/rolldown_runtime.js";
2
- import * as Schema from "effect/Schema";
3
-
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { make } from "./Event.js";
3
+ import { Schema } from "effect";
4
4
  //#region src/Events.ts
5
5
  /**
6
6
  * Internal Inngest events that the platform sends automatically.
@@ -32,62 +32,57 @@ var JsonError = class extends Schema.Class("JsonError")({
32
32
  * Trigger on this to handle failures (e.g., alerting, cleanup).
33
33
  * @since 0.1.0
34
34
  */
35
- var FunctionFailed = class extends Schema.TaggedClass()("inngest/function.failed", {
35
+ const FunctionFailed = make("inngest/function.failed", Schema.Struct({
36
36
  function_id: Schema.String,
37
37
  run_id: Schema.String,
38
38
  error: JsonError,
39
- event: Schema.Record({
40
- key: Schema.String,
41
- value: Schema.Unknown
42
- })
43
- }) {};
39
+ event: Schema.Record(Schema.String, Schema.Unknown)
40
+ }));
44
41
  /**
45
42
  * Sent when a function finishes with an error.
46
43
  * @since 0.1.0
47
44
  */
48
- var FunctionFinishedError = class extends Schema.TaggedClass()("inngest/function.finished", {
45
+ const FunctionFinishedErrorData = Schema.Struct({
49
46
  function_id: Schema.String,
50
47
  run_id: Schema.String,
51
48
  correlation_id: Schema.optional(Schema.String),
52
49
  error: JsonError
53
- }) {};
50
+ });
51
+ const FunctionFinishedError = make("inngest/function.finished", FunctionFinishedErrorData);
54
52
  /**
55
53
  * Sent when a function finishes successfully.
56
54
  * @since 0.1.0
57
55
  */
58
- var FunctionFinishedSuccess = class extends Schema.TaggedClass()("inngest/function.finished", {
56
+ const FunctionFinishedSuccessData = Schema.Struct({
59
57
  function_id: Schema.String,
60
58
  run_id: Schema.String,
61
59
  correlation_id: Schema.optional(Schema.String),
62
60
  result: Schema.Unknown
63
- }) {};
61
+ });
62
+ const FunctionFinishedSuccess = make("inngest/function.finished", FunctionFinishedSuccessData);
64
63
  /**
65
64
  * Union of both FunctionFinished variants.
66
65
  * @since 0.1.0
67
66
  */
68
- const FunctionFinished = Schema.Union(FunctionFinishedError, FunctionFinishedSuccess);
67
+ const FunctionFinished = make("inngest/function.finished", Schema.Union([FunctionFinishedErrorData, FunctionFinishedSuccessData]));
69
68
  /**
70
69
  * Sent when a function is cancelled.
71
70
  * @since 0.1.0
72
71
  */
73
- var FunctionCancelled = class extends Schema.TaggedClass()("inngest/function.cancelled", {
72
+ const FunctionCancelled = make("inngest/function.cancelled", Schema.Struct({
74
73
  function_id: Schema.String,
75
74
  run_id: Schema.String,
76
75
  correlation_id: Schema.optional(Schema.String)
77
- }) {};
76
+ }));
78
77
  /**
79
78
  * Sent when a function is invoked via step.invoke().
80
79
  * @since 0.1.0
81
80
  */
82
- var FunctionInvoked = class extends Schema.TaggedClass()("inngest/function.invoked", { data: Schema.optional(Schema.Record({
83
- key: Schema.String,
84
- value: Schema.Unknown
85
- })) }) {};
81
+ const FunctionInvoked = make("inngest/function.invoked", Schema.StructWithRest(Schema.Struct({ _inngest: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)) }), [Schema.Record(Schema.String, Schema.Unknown)]));
86
82
  /**
87
83
  * Sent when a cron trigger fires.
88
84
  * @since 0.1.0
89
85
  */
90
- var ScheduledTimer = class extends Schema.TaggedClass()("inngest/scheduled.timer", { cron: Schema.String }) {};
91
-
86
+ const ScheduledTimer = make("inngest/scheduled.timer", Schema.Struct({ cron: Schema.String }));
92
87
  //#endregion
93
- export { Events_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
88
+ export { Events_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
@@ -1,8 +1,11 @@
1
+ import { CheckpointingOption } from "./internal/checkpoint/Config.js";
2
+ import { EventDefinition, EventType } from "./Event.js";
1
3
  import { Duration, Schema } from "effect";
4
+ import { Pipeable } from "effect/Pipeable";
2
5
 
3
6
  //#region src/Function.d.ts
4
7
  declare namespace Function_d_exports {
5
- export { CronTrigger, EventTrigger, FunctionOptions, InngestFunction, Trigger, TriggerInput, TypeId, make };
8
+ export { CheckpointingOption, CronTrigger, EventTrigger, FunctionOptions, InngestFunction, Trigger, TriggerInput, TypeId, make };
6
9
  }
7
10
  /**
8
11
  * @since 0.1.0
@@ -14,9 +17,7 @@ declare const TypeId: unique symbol;
14
17
  * @category type ids
15
18
  */
16
19
  type TypeId = typeof TypeId;
17
- type EventSchema = Schema.Schema.Any & {
18
- readonly _tag: string;
19
- };
20
+ type EventSchema = EventDefinition;
20
21
  /**
21
22
  * An event-based trigger configuration.
22
23
  *
@@ -88,7 +89,7 @@ interface RateLimitOption {
88
89
  /**
89
90
  * The period of time to allow the function to run `limit` times.
90
91
  */
91
- readonly period: Duration.DurationInput;
92
+ readonly period: Duration.Input;
92
93
  }
93
94
  interface ThrottleOption {
94
95
  /**
@@ -106,7 +107,7 @@ interface ThrottleOption {
106
107
  * The period of time for the rate limit. Run starts are evenly spaced through
107
108
  * the given period. The minimum granularity is 1 second.
108
109
  */
109
- readonly period: Duration.DurationInput;
110
+ readonly period: Duration.Input;
110
111
  /**
111
112
  * The number of runs allowed to start in the given window in a single burst.
112
113
  * A burst > 1 bypasses smoothing for the burst and allows many runs to start
@@ -122,13 +123,13 @@ interface DebounceOption {
122
123
  /**
123
124
  * The period of time to delay after receiving the last trigger to run the function.
124
125
  */
125
- readonly period: Duration.DurationInput;
126
+ readonly period: Duration.Input;
126
127
  /**
127
128
  * The maximum time that a debounce can be extended before running.
128
129
  * If events are continually received within the given period, a function
129
130
  * will always run after the given timeout period.
130
131
  */
131
- readonly timeout?: Duration.DurationInput;
132
+ readonly timeout?: Duration.Input;
132
133
  }
133
134
  interface BatchEventsOption {
134
135
  /**
@@ -140,7 +141,7 @@ interface BatchEventsOption {
140
141
  * If timeout is reached, the function will be invoked with a batch
141
142
  * even if it's not filled up to `maxSize`.
142
143
  */
143
- readonly timeout: Duration.DurationInput;
144
+ readonly timeout: Duration.Input;
144
145
  /**
145
146
  * An optional key to use for batching.
146
147
  */
@@ -169,13 +170,13 @@ interface TimeoutsOption {
169
170
  * This is, essentially, the amount of time that a function sits in the
170
171
  * queue before starting.
171
172
  */
172
- readonly start?: Duration.DurationInput;
173
+ readonly start?: Duration.Input;
173
174
  /**
174
175
  * Finish represents the time between a function starting and the function
175
176
  * finishing. If a function takes longer than this time to finish, the
176
177
  * function is marked as cancelled.
177
178
  */
178
- readonly finish?: Duration.DurationInput;
179
+ readonly finish?: Duration.Input;
179
180
  }
180
181
  interface SingletonOption {
181
182
  /**
@@ -208,7 +209,7 @@ interface CancellationOption {
208
209
  * specified, cancellation triggers are valid for up to a year or until the
209
210
  * function ends.
210
211
  */
211
- readonly timeout?: Duration.DurationInput;
212
+ readonly timeout?: Duration.Input;
212
213
  }
213
214
  type Retries = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
214
215
  /**
@@ -278,6 +279,19 @@ interface FunctionOptions {
278
279
  * Batch events configuration.
279
280
  */
280
281
  readonly batchEvents?: BatchEventsOption;
282
+ /**
283
+ * Whether to use checkpointing for executions of this function. Overrides
284
+ * the client-level `checkpointing` setting.
285
+ *
286
+ * - `false` disables checkpointing for this function.
287
+ * - `true` enables checkpointing with safe defaults
288
+ * (`bufferedSteps: 1`, `maxInterval: 0`, `maxRuntime: 10s`).
289
+ * - An object lets you tune `bufferedSteps`, `maxInterval`, `maxRuntime`.
290
+ *
291
+ * Defaults to inheriting from the client-level setting (which itself
292
+ * defaults to enabled with safe defaults).
293
+ */
294
+ readonly checkpointing?: CheckpointingOption;
281
295
  }
282
296
  interface RegistrationConfig {
283
297
  readonly appId: string;
@@ -329,7 +343,11 @@ interface FunctionRegistration {
329
343
  readonly period: string;
330
344
  readonly timeout?: string;
331
345
  };
332
- readonly concurrency?: ReadonlyArray<{
346
+ readonly concurrency?: {
347
+ readonly key?: string;
348
+ readonly limit: number;
349
+ readonly scope?: string;
350
+ } | ReadonlyArray<{
333
351
  readonly key?: string;
334
352
  readonly limit: number;
335
353
  readonly scope?: string;
@@ -347,6 +365,11 @@ interface FunctionRegistration {
347
365
  readonly key?: string;
348
366
  };
349
367
  readonly idempotency?: string;
368
+ readonly checkpoint?: {
369
+ readonly batch_steps: number;
370
+ readonly batch_interval: string;
371
+ readonly max_runtime: string;
372
+ };
350
373
  }
351
374
  /**
352
375
  * An Inngest function definition.
@@ -354,7 +377,7 @@ interface FunctionRegistration {
354
377
  * @since 0.1.0
355
378
  * @category models
356
379
  */
357
- interface InngestFunction<Tag extends string, Triggers extends Trigger, Success extends Schema.Schema.Any, Options extends FunctionOptions = FunctionOptions> {
380
+ interface InngestFunction<Tag extends string, Triggers extends Trigger, Success extends Schema.Codec<unknown, unknown, never, never>, Options extends FunctionOptions = FunctionOptions> extends Pipeable {
358
381
  readonly [TypeId]: TypeId;
359
382
  readonly _tag: Tag;
360
383
  readonly key: string;
@@ -368,12 +391,16 @@ interface InngestFunction<Tag extends string, Triggers extends Trigger, Success
368
391
  * @category models
369
392
  */
370
393
  declare namespace InngestFunction {
371
- type Any = InngestFunction<string, Trigger, Schema.Schema.Any, FunctionOptions>;
394
+ type Any = InngestFunction<string, Trigger, Schema.Codec<any, any, never, never>, FunctionOptions>;
372
395
  type Tag<F> = F extends InngestFunction<infer T, any, any, any> ? T : never;
373
396
  type Triggers<F> = F extends InngestFunction<any, infer T, any, any> ? T : never;
374
397
  type Events<F> = F extends InngestFunction<any, infer T, any, any> ? (T extends EventTrigger<infer E> ? E : never) : never;
375
- type EventType<F> = F extends InngestFunction<any, infer T, any, any> ? T extends EventTrigger<infer E> ? Schema.Schema.Type<E> : never : never;
376
- type Success<F> = F extends InngestFunction<any, any, infer S, any> ? Schema.Schema.Type<S> : never;
398
+ type EventPayload<F> = EventType<Events<F>>;
399
+ type EventType<F> = Options<F> extends {
400
+ readonly batchEvents: BatchEventsOption;
401
+ } ? ReadonlyArray<EventPayload<F>> : EventPayload<F>;
402
+ type SuccessSchema<F> = F extends InngestFunction<any, any, infer S, any> ? S : never;
403
+ type Success<F> = Schema.Schema.Type<SuccessSchema<F>>;
377
404
  type Options<F> = F extends InngestFunction<any, any, any, infer O> ? O : never;
378
405
  }
379
406
  type NormalizeTriggers<T extends TriggerInput> = T extends ReadonlyArray<Trigger> ? T[number] : T;
@@ -410,9 +437,9 @@ type NormalizeTriggers<T extends TriggerInput> = T extends ReadonlyArray<Trigger
410
437
  * })
411
438
  * ```
412
439
  */
413
- declare function make<const Tag extends string, T extends TriggerInput, S extends Schema.Schema.Any, const O extends FunctionOptions = {}>(tag: Tag, options: {
440
+ declare function make<const Tag extends string, T extends TriggerInput, S extends Schema.Codec<unknown, unknown, never, never>, const O extends FunctionOptions = {}>(tag: Tag, options: {
414
441
  readonly trigger: T;
415
442
  readonly success: S;
416
443
  } & O): InngestFunction<Tag, NormalizeTriggers<T>, S, O>;
417
444
  //#endregion
418
- export { CronTrigger, EventTrigger, FunctionOptions, Function_d_exports, InngestFunction, Trigger, TriggerInput, TypeId, make };
445
+ export { type CheckpointingOption, CronTrigger, EventTrigger, FunctionOptions, Function_d_exports, InngestFunction, Trigger, TriggerInput, TypeId, make };
package/dist/Function.js CHANGED
@@ -1,7 +1,8 @@
1
- import { __exportAll } from "./_virtual/rolldown_runtime.js";
2
- import { timeStr } from "./internal/helpers.js";
3
- import { Array, Duration, Predicate, Schema } from "effect";
4
-
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { InngestDuration } from "./internal/wire/Duration.js";
3
+ import { resolveConfig, toRegistration } from "./internal/checkpoint/Config.js";
4
+ import { Array, Duration, Option, Predicate, Schema } from "effect";
5
+ import { pipeArguments } from "effect/Pipeable";
5
6
  //#region src/Function.ts
6
7
  /**
7
8
  * @since 0.1.0
@@ -16,12 +17,16 @@ var Function_exports = /* @__PURE__ */ __exportAll({
16
17
  */
17
18
  const TypeId = Symbol.for("effect-inngest/Function");
18
19
  const isEventTrigger = (t) => Predicate.hasProperty(t, "event");
20
+ const encodeDuration = (input) => Schema.encodeSync(InngestDuration)(Duration.fromInputUnsafe(input));
19
21
  const Proto = {
20
22
  [TypeId]: TypeId,
23
+ pipe() {
24
+ return pipeArguments(this, arguments);
25
+ },
21
26
  toRegistration(config) {
22
27
  const triggers = [];
23
28
  for (const t of this.triggers) if (isEventTrigger(t)) triggers.push({
24
- event: t.event._tag,
29
+ event: t.event.identifier,
25
30
  expression: t.if
26
31
  });
27
32
  else triggers.push({ cron: t.cron });
@@ -29,33 +34,35 @@ const Proto = {
29
34
  const cancel = opts.cancelOn?.map((c) => ({
30
35
  event: c.event,
31
36
  if: c.if,
32
- timeout: c.timeout ? timeStr(c.timeout) : void 0
37
+ timeout: c.timeout ? encodeDuration(c.timeout) : void 0
33
38
  }));
34
39
  const timeouts = opts.timeouts?.start || opts.timeouts?.finish ? {
35
- start: opts.timeouts.start ? timeStr(opts.timeouts.start) : void 0,
36
- finish: opts.timeouts.finish ? timeStr(opts.timeouts.finish) : void 0
40
+ start: opts.timeouts.start ? encodeDuration(opts.timeouts.start) : void 0,
41
+ finish: opts.timeouts.finish ? encodeDuration(opts.timeouts.finish) : void 0
37
42
  } : void 0;
38
43
  const rateLimit = opts.rateLimit ? {
39
44
  key: opts.rateLimit.key,
40
45
  limit: opts.rateLimit.limit,
41
- period: timeStr(opts.rateLimit.period)
46
+ period: encodeDuration(opts.rateLimit.period)
42
47
  } : void 0;
43
48
  const throttle = opts.throttle ? {
44
49
  key: opts.throttle.key,
45
50
  limit: opts.throttle.limit,
46
- period: timeStr(opts.throttle.period),
51
+ period: encodeDuration(opts.throttle.period),
47
52
  burst: opts.throttle.burst
48
53
  } : void 0;
49
54
  const debounce = opts.debounce ? {
50
55
  key: opts.debounce.key,
51
- period: timeStr(opts.debounce.period),
52
- timeout: opts.debounce.timeout ? timeStr(opts.debounce.timeout) : void 0
56
+ period: encodeDuration(opts.debounce.period),
57
+ timeout: opts.debounce.timeout ? encodeDuration(opts.debounce.timeout) : void 0
53
58
  } : void 0;
54
- const concurrency = opts.concurrency != null ? typeof opts.concurrency === "number" ? [{ limit: opts.concurrency }] : Array.ensure(opts.concurrency).map((c) => ({
55
- key: c.key,
56
- limit: c.limit,
57
- scope: c.scope
58
- })) : void 0;
59
+ const serializeConcurrencyOption = (option) => ({
60
+ key: option.key,
61
+ limit: option.limit,
62
+ scope: option.scope
63
+ });
64
+ const isConcurrencyOptions = (value) => Array.isArray(value);
65
+ const concurrency = Option.fromNullishOr(opts.concurrency).pipe(Option.map((value) => Predicate.isNumber(value) ? { limit: value } : isConcurrencyOptions(value) ? Array.map(value, serializeConcurrencyOption) : serializeConcurrencyOption(value)), Option.getOrUndefined);
59
66
  const priority = opts.priority ? { run: opts.priority.run } : void 0;
60
67
  const singleton = opts.singleton ? {
61
68
  key: opts.singleton.key,
@@ -63,10 +70,13 @@ const Proto = {
63
70
  } : void 0;
64
71
  const batchEvents = opts.batchEvents ? {
65
72
  maxSize: opts.batchEvents.maxSize,
66
- timeout: timeStr(opts.batchEvents.timeout),
73
+ timeout: encodeDuration(opts.batchEvents.timeout),
67
74
  key: opts.batchEvents.key
68
75
  } : void 0;
69
76
  const idempotency = opts.idempotency;
77
+ const retries = Predicate.isNotUndefined(opts.retries) ? { attempts: opts.retries } : void 0;
78
+ const resolvedCheckpoint = Predicate.isNotUndefined(opts.checkpointing) ? resolveConfig(opts.checkpointing, void 0) : void 0;
79
+ const checkpoint = resolvedCheckpoint ? toRegistration(resolvedCheckpoint) : void 0;
70
80
  const fnId = `${config.appId}-${this._tag}`;
71
81
  const stepUrl = new URL(config.url);
72
82
  stepUrl.searchParams.set("fnId", fnId);
@@ -82,7 +92,7 @@ const Proto = {
82
92
  type: "http",
83
93
  url: stepUrl.href
84
94
  },
85
- retries: { attempts: opts.retries ?? 3 }
95
+ retries
86
96
  } },
87
97
  cancel: cancel && cancel.length > 0 ? cancel : void 0,
88
98
  timeouts,
@@ -93,7 +103,8 @@ const Proto = {
93
103
  priority,
94
104
  singleton,
95
105
  batchEvents,
96
- idempotency
106
+ idempotency,
107
+ checkpoint
97
108
  };
98
109
  }
99
110
  };
@@ -139,6 +150,5 @@ function make(tag, options) {
139
150
  fn.options = options;
140
151
  return fn;
141
152
  }
142
-
143
153
  //#endregion
144
- export { Function_exports, TypeId, make };
154
+ export { Function_exports, TypeId, make };