inngest 0.7.0 → 0.7.1
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/cloudflare.js +1 -1
- package/cloudflare.js.map +1 -1
- package/components/Inngest.d.ts +45 -5
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +12 -3
- package/components/Inngest.js.map +1 -1
- package/components/InngestFunction.d.ts +22 -4
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +112 -30
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestStepTools.d.ts +126 -0
- package/components/InngestStepTools.d.ts.map +1 -0
- package/components/InngestStepTools.js +287 -0
- package/components/InngestStepTools.js.map +1 -0
- package/express.d.ts.map +1 -1
- package/express.js +20 -10
- package/express.js.map +1 -1
- package/helpers/func.d.ts +13 -3
- package/helpers/func.d.ts.map +1 -1
- package/helpers/func.js +29 -4
- package/helpers/func.js.map +1 -1
- package/helpers/strings.d.ts +8 -0
- package/helpers/strings.d.ts.map +1 -1
- package/helpers/strings.js +60 -1
- package/helpers/strings.js.map +1 -1
- package/helpers/types.d.ts +26 -0
- package/helpers/types.d.ts.map +1 -1
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/landing.d.ts +1 -1
- package/landing.d.ts.map +1 -1
- package/landing.js +1 -1
- package/landing.js.map +1 -1
- package/next.js +1 -1
- package/next.js.map +1 -1
- package/package.json +7 -3
- package/redwood.js +1 -1
- package/redwood.js.map +1 -1
- package/remix.js +1 -1
- package/remix.js.map +1 -1
- package/types.d.ts +127 -11
- package/types.d.ts.map +1 -1
- package/types.js +11 -0
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/components/InngestStep.d.ts +0 -15
- package/components/InngestStep.d.ts.map +0 -1
- package/components/InngestStep.js +0 -37
- package/components/InngestStep.js.map +0 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createStepTools = exports.StepFlowInterrupt = void 0;
|
|
7
|
+
const hash_js_1 = require("hash.js");
|
|
8
|
+
const sigmund_1 = __importDefault(require("sigmund"));
|
|
9
|
+
const strings_1 = require("../helpers/strings");
|
|
10
|
+
const types_1 = require("../types");
|
|
11
|
+
/**
|
|
12
|
+
* A unique class used to interrupt the flow of a step. It is intended to be
|
|
13
|
+
* thrown and caught using `instanceof StepFlowInterrupt`.
|
|
14
|
+
*/
|
|
15
|
+
class StepFlowInterrupt {
|
|
16
|
+
}
|
|
17
|
+
exports.StepFlowInterrupt = StepFlowInterrupt;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new set of step function tools ready to be used in a step function.
|
|
20
|
+
* This function should be run and a fresh set of tools provided every time a
|
|
21
|
+
* function is run.
|
|
22
|
+
*
|
|
23
|
+
* An op stack (function state) is passed in as well as some mutable properties
|
|
24
|
+
* that the tools can use to submit a new op.
|
|
25
|
+
*
|
|
26
|
+
* Broadly, each tool is responsible for potentially filling itself with data
|
|
27
|
+
* from the op stack and submitting an op, interrupting the step function when
|
|
28
|
+
* it does so.
|
|
29
|
+
*
|
|
30
|
+
* This feels better being a class, but class bindings are lost (i.e. `this`
|
|
31
|
+
* becomes `undefined`) if a user destructures the tools within their step
|
|
32
|
+
* function. Thus, we must instead use closures for this functionality.
|
|
33
|
+
*/
|
|
34
|
+
const createStepTools = (_opStack) => {
|
|
35
|
+
/**
|
|
36
|
+
* A boolean to represent that we're currently running through the op stack of
|
|
37
|
+
* the function to decide what to do next.
|
|
38
|
+
*
|
|
39
|
+
* When we've finished reading the op stack to set the function's state and
|
|
40
|
+
* have a new operation to run, we set this to `false` to indicate that we've
|
|
41
|
+
* found the next operation and will no longer attempt any other actions.
|
|
42
|
+
*
|
|
43
|
+
* We use this instead of `Boolean(state.nextOp)` because some operations may
|
|
44
|
+
* accidentally not set `state.nextOp`, so we need another way to know that we
|
|
45
|
+
* have found the next potential operation.
|
|
46
|
+
*/
|
|
47
|
+
let readingFromStack = true;
|
|
48
|
+
/**
|
|
49
|
+
* We use pos to ensure that hashes are unique for each step and a function
|
|
50
|
+
* will produce the same IDs and outputs every time.
|
|
51
|
+
*
|
|
52
|
+
* Each time attempt to fetch data for an operation, we increment this value
|
|
53
|
+
* and include it in the hash for that op.
|
|
54
|
+
*/
|
|
55
|
+
let pos = 0;
|
|
56
|
+
/**
|
|
57
|
+
* Perform a shallow clone of the opstack to ensure we're not removing
|
|
58
|
+
* elements from the original.
|
|
59
|
+
*/
|
|
60
|
+
const opStack = Object.assign({}, _opStack);
|
|
61
|
+
/**
|
|
62
|
+
* Returns [true, any] if the next op matches the next past op.
|
|
63
|
+
*
|
|
64
|
+
* Returns [false, undefined] if the next op didn't match or we ran out of
|
|
65
|
+
* stack. In either case, we should run the next op.
|
|
66
|
+
*/
|
|
67
|
+
const getNextPastOpData = (op) => {
|
|
68
|
+
const next = opStack[op.id];
|
|
69
|
+
// if the data is undefined, it hasn't ran. Any other data, such
|
|
70
|
+
// as false, null, etc. indicates that the step has already ran as
|
|
71
|
+
// state was persisted.
|
|
72
|
+
return [next !== undefined, next];
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* A local helper used to create tools that can be used to submit an op.
|
|
76
|
+
*
|
|
77
|
+
* It will handle filling any data from the op stack and will provide tools to
|
|
78
|
+
* a given function to safely submit synchronous or asynchronous ops.
|
|
79
|
+
*
|
|
80
|
+
* When using this function, a generic type should be provided which is the
|
|
81
|
+
* function signature exposed to the user.
|
|
82
|
+
*/
|
|
83
|
+
const createTool = (
|
|
84
|
+
/**
|
|
85
|
+
* A function that returns an ID for this op. This is used to ensure that
|
|
86
|
+
* the op stack is correctly filled, submitted, and retrieved with the same
|
|
87
|
+
* ID.
|
|
88
|
+
*
|
|
89
|
+
* It is passed the arguments passed by the user.
|
|
90
|
+
*
|
|
91
|
+
* Most simple tools will likely only need to define this.
|
|
92
|
+
*/
|
|
93
|
+
matchOp,
|
|
94
|
+
/**
|
|
95
|
+
* Optionally, we can also provide a function that will be called with the
|
|
96
|
+
* data passed by the user in order to submit a new op.
|
|
97
|
+
*
|
|
98
|
+
* By default - if this is not provided - this will be a simple function
|
|
99
|
+
* that runs the `submitOp()` tool passed to it.
|
|
100
|
+
*
|
|
101
|
+
* This is useful for tools that need to do some kind of async processing
|
|
102
|
+
* before submitting an op, or tools that need to adjust the op they're
|
|
103
|
+
* submitting.
|
|
104
|
+
*/
|
|
105
|
+
fn) => {
|
|
106
|
+
return ((...args) => {
|
|
107
|
+
/**
|
|
108
|
+
* If we already have the next op to run, then we've already received
|
|
109
|
+
* output from another tool and should no longer continue.
|
|
110
|
+
*/
|
|
111
|
+
if (!readingFromStack) {
|
|
112
|
+
throw new StepFlowInterrupt();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Fetch the next op to run from the tool we want to run.
|
|
116
|
+
*/
|
|
117
|
+
const unhashedOpId = matchOp(...args);
|
|
118
|
+
/**
|
|
119
|
+
* Hash the operation ID.
|
|
120
|
+
*/
|
|
121
|
+
const opId = Object.assign(Object.assign({}, unhashedOpId), { id: hashOp(unhashedOpId, pos++) });
|
|
122
|
+
const [found, data] = getNextPastOpData(opId);
|
|
123
|
+
if (found) {
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
125
|
+
return data;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set `readingFromStack` to false to indicate that we've found the next
|
|
129
|
+
* op to run.
|
|
130
|
+
*/
|
|
131
|
+
readingFromStack = false;
|
|
132
|
+
const submitOp = (...args) => {
|
|
133
|
+
state.nextOp = new Promise((resolve) => resolve(args[0])).then((data) => (Object.assign(Object.assign({}, opId), (args.length ? { data } : {}))));
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* If we've been passed a custom function to run in response to user data,
|
|
137
|
+
* run that now. That function will then be responsible for submitting an
|
|
138
|
+
* op.
|
|
139
|
+
*
|
|
140
|
+
* If we haven't been given this, simply submit the op.
|
|
141
|
+
*/
|
|
142
|
+
if (fn) {
|
|
143
|
+
fn({ submitOp }, ...args);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
submitOp();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* If we've run the tool and it hasn't submitted an op, then we should
|
|
150
|
+
* throw. This is exceedingly unexpected and indicates that a tool has
|
|
151
|
+
* a bug.
|
|
152
|
+
*/
|
|
153
|
+
if (!state.nextOp) {
|
|
154
|
+
throw new Error("No operation was submitted by a tool");
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* If we're here, we've attempted to use a tool and should therefore throw
|
|
158
|
+
* an error to stop the function from running.
|
|
159
|
+
*/
|
|
160
|
+
throw new StepFlowInterrupt();
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const state = {
|
|
164
|
+
nextOp: undefined,
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Define the set of tools the user has access to for their step functions.
|
|
168
|
+
*
|
|
169
|
+
* Each key is the function name and is expected to run `createTool` and pass
|
|
170
|
+
* a generic type for that function as it will appear in the user's code.
|
|
171
|
+
*/
|
|
172
|
+
const tools = {
|
|
173
|
+
/**
|
|
174
|
+
* Wait for a particular event to be received before continuing. When the
|
|
175
|
+
* event is received, it will be returned.
|
|
176
|
+
*
|
|
177
|
+
* You can also provide options to control the particular event that is
|
|
178
|
+
* received, for example to ensure that a user ID matches between two
|
|
179
|
+
* events, or to only wait a maximum amount of time before giving up and
|
|
180
|
+
* returning `null` instead of any event data.
|
|
181
|
+
*/
|
|
182
|
+
waitForEvent: createTool((
|
|
183
|
+
/**
|
|
184
|
+
* The event name to wait for.
|
|
185
|
+
*/
|
|
186
|
+
event,
|
|
187
|
+
/**
|
|
188
|
+
* Options to control the event we're waiting for.
|
|
189
|
+
*/
|
|
190
|
+
opts) => {
|
|
191
|
+
const matchOpts = {
|
|
192
|
+
ttl: (0, strings_1.timeStr)(opts.timeout),
|
|
193
|
+
};
|
|
194
|
+
if (opts === null || opts === void 0 ? void 0 : opts.match) {
|
|
195
|
+
matchOpts.match = `event.${opts.match} == async.${opts.match}`;
|
|
196
|
+
}
|
|
197
|
+
else if (opts === null || opts === void 0 ? void 0 : opts.if) {
|
|
198
|
+
matchOpts.match = opts.if;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
op: types_1.StepOpCode.WaitForEvent,
|
|
202
|
+
name: event,
|
|
203
|
+
opts: matchOpts,
|
|
204
|
+
};
|
|
205
|
+
}),
|
|
206
|
+
/**
|
|
207
|
+
* Use this tool to run business logic. Each call to `run` will be retried
|
|
208
|
+
* individually, meaning you can compose complex workflows that safely
|
|
209
|
+
* retry dependent asynchronous actions.
|
|
210
|
+
*
|
|
211
|
+
* The function you pass to `run` will be called only when this "step" is to
|
|
212
|
+
* be executed and can be synchronous or asynchronous.
|
|
213
|
+
*
|
|
214
|
+
* In either case, the return value of the function will be the return value
|
|
215
|
+
* of the `run` tool, meaning you can return and reason about return data
|
|
216
|
+
* for next steps.
|
|
217
|
+
*/
|
|
218
|
+
run: createTool((name) => {
|
|
219
|
+
return {
|
|
220
|
+
op: types_1.StepOpCode.RunStep,
|
|
221
|
+
name,
|
|
222
|
+
};
|
|
223
|
+
}, ({ submitOp }, _name, fn) => {
|
|
224
|
+
submitOp(fn());
|
|
225
|
+
}),
|
|
226
|
+
/**
|
|
227
|
+
* Wait a specified amount of time before continuing.
|
|
228
|
+
*
|
|
229
|
+
* The time to wait can be specified using a `number` of milliseconds or an
|
|
230
|
+
* `ms`-compatible time string like `"1 hour"`, `"30 mins"`, or `"2.5d"`.
|
|
231
|
+
*
|
|
232
|
+
* {@link https://npm.im/ms}
|
|
233
|
+
*
|
|
234
|
+
* To wait until a particular date, use `sleepUntil` instead.
|
|
235
|
+
*/
|
|
236
|
+
sleep: createTool((time) => {
|
|
237
|
+
/**
|
|
238
|
+
* The presence of this operation in the returned stack indicates that the
|
|
239
|
+
* sleep is over and we should continue execution.
|
|
240
|
+
*/
|
|
241
|
+
return {
|
|
242
|
+
op: types_1.StepOpCode.Sleep,
|
|
243
|
+
name: (0, strings_1.timeStr)(time),
|
|
244
|
+
};
|
|
245
|
+
}),
|
|
246
|
+
/**
|
|
247
|
+
* Wait until a particular date before continuing by passing a `Date`.
|
|
248
|
+
*
|
|
249
|
+
* To wait for a particular amount of time, use `sleep` instead.
|
|
250
|
+
*/
|
|
251
|
+
sleepUntil: createTool((time) => {
|
|
252
|
+
/**
|
|
253
|
+
* The presence of this operation in the returned stack indicates that the
|
|
254
|
+
* sleep is over and we should continue execution.
|
|
255
|
+
*/
|
|
256
|
+
return {
|
|
257
|
+
op: types_1.StepOpCode.Sleep,
|
|
258
|
+
name: (0, strings_1.timeStr)(time),
|
|
259
|
+
};
|
|
260
|
+
}),
|
|
261
|
+
};
|
|
262
|
+
return [tools, state];
|
|
263
|
+
};
|
|
264
|
+
exports.createStepTools = createStepTools;
|
|
265
|
+
/**
|
|
266
|
+
* Create a unique hash of an operation using only a subset of the operation's
|
|
267
|
+
* properties; will never use `data` and will guarantee the order of the object
|
|
268
|
+
* so we don't rely on individual tools for that.
|
|
269
|
+
*/
|
|
270
|
+
const hashOp = (
|
|
271
|
+
/**
|
|
272
|
+
* The op to generate a hash from. We only use a subset of the op's properties
|
|
273
|
+
* when creating the hash.
|
|
274
|
+
*/
|
|
275
|
+
op,
|
|
276
|
+
/**
|
|
277
|
+
* The position in the "stack" that this was called from. We use this to
|
|
278
|
+
* ensure that the hash is unique for each step and in-line with what we
|
|
279
|
+
* expect the stack to be.
|
|
280
|
+
*/
|
|
281
|
+
pos) => {
|
|
282
|
+
return ((0, hash_js_1.sha1)()
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
284
|
+
.update((0, sigmund_1.default)({ pos, op: op.op, name: op.name, opts: op.opts }))
|
|
285
|
+
.digest("hex"));
|
|
286
|
+
};
|
|
287
|
+
//# sourceMappingURL=InngestStepTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InngestStepTools.js","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA+B;AAC/B,sDAA8B;AAC9B,gDAA6C;AAE7C,oCAA2E;AAE3E;;;GAGG;AACH,MAAa,iBAAiB;CAAG;AAAjC,8CAAiC;AAEjC;;;;;;;;;;;;;;;GAeG;AACI,MAAM,eAAe,GAAG,CAI7B,QAAiB,EACjB,EAAE;IACF;;;;;;;;;;;OAWG;IACH,IAAI,gBAAgB,GAAG,IAAI,CAAC;IAE5B;;;;;;OAMG;IACH,IAAI,GAAG,GAAG,CAAC,CAAC;IAEZ;;;OAGG;IACH,MAAM,OAAO,qBAAQ,QAAQ,CAAE,CAAC;IAEhC;;;;;OAKG;IACH,MAAM,iBAAiB,GAAG,CACxB,EAAY,EACgD,EAAE;QAC9D,MAAM,IAAI,GAAY,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,iEAAiE;QACjE,kEAAkE;QAClE,uBAAuB;QACvB,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,IAAW,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEF;;;;;;;;OAQG;IACH,MAAM,UAAU,GAAG;IACjB;;;;;;;;OAQG;IACH,OAKO;IAEP;;;;;;;;;;OAUG;IACH,EAeQ,EACL,EAAE;QACL,OAAO,CAAC,CAAC,GAAG,IAAmB,EAAE,EAAE;YACjC;;;eAGG;YACH,IAAI,CAAC,gBAAgB,EAAE;gBACrB,MAAM,IAAI,iBAAiB,EAAE,CAAC;aAC/B;YAED;;eAEG;YACH,MAAM,YAAY,GAAO,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;YAE1C;;eAEG;YACH,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gBAAgB,GAW3B;IAEM,aAAa,IAAI,GAAG;cAqFX,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,eAAe,CAAC;IA2C3B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc,EAAE;IAI7C;;;;;OAKG;IACH,SAAS,KAAK,SAAS,IAAI;QACzB,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC;QAC/B,MAAM,EAAE,MAAM;KACf,CAEA;IAED;;;;;OAKG;IACH,SAAS,CAAC,MAAM;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GACZ,GAAG;IAON,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,eAAe;cAgBjC,QAAQ,CACtB,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAiE/C,OAAO,KAAK,MAAM,GAEjB;IAED,SAAS,CAAC,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO;IAIvE,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAItC,SAAS,CAAC,YAAY,IAAI,MAAM;CAGjC"}
|
package/express.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.InngestCommHandler = exports.serve = void 0;
|
|
7
|
-
const
|
|
4
|
+
const hash_js_1 = require("hash.js");
|
|
8
5
|
const zod_1 = require("zod");
|
|
9
6
|
const consts_1 = require("./helpers/consts");
|
|
10
7
|
const devserver_1 = require("./helpers/devserver");
|
|
@@ -104,7 +101,7 @@ class InngestCommHandler {
|
|
|
104
101
|
const prefix = ((_a = this.signingKey.match(/^signkey-(test|prod)-/)) === null || _a === void 0 ? void 0 : _a.shift()) || "";
|
|
105
102
|
const key = this.signingKey.replace(/^signkey-(test|prod)-/, "");
|
|
106
103
|
// Decode the key from its hex representation into a bytestream
|
|
107
|
-
return `${prefix}${(0,
|
|
104
|
+
return `${prefix}${(0, hash_js_1.sha256)().update(key, "hex").digest("hex")}`;
|
|
108
105
|
}
|
|
109
106
|
createHandler() {
|
|
110
107
|
return async (req, res) => {
|
|
@@ -124,11 +121,11 @@ class InngestCommHandler {
|
|
|
124
121
|
if (!this.signingKey && process.env[consts_1.envKeys.SigningKey]) {
|
|
125
122
|
this.signingKey = process.env[consts_1.envKeys.SigningKey];
|
|
126
123
|
}
|
|
127
|
-
this._isProd = process.env.ENVIRONMENT === "production";
|
|
124
|
+
this._isProd = process.env.ENVIRONMENT === "production" || process.env.NODE_ENV === "production";
|
|
128
125
|
switch (req.method) {
|
|
129
126
|
case "GET": {
|
|
130
127
|
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]);
|
|
131
|
-
if (!showLandingPage)
|
|
128
|
+
if (this._isProd || !showLandingPage)
|
|
132
129
|
break;
|
|
133
130
|
if (Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect)) {
|
|
134
131
|
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)(process.env[consts_1.envKeys.DevServerUrl])
|
|
@@ -171,10 +168,23 @@ class InngestCommHandler {
|
|
|
171
168
|
if (!fn) {
|
|
172
169
|
throw new Error(`Could not find function with ID "${functionId}"`);
|
|
173
170
|
}
|
|
174
|
-
const
|
|
171
|
+
const { event, steps } = zod_1.z
|
|
172
|
+
.object({
|
|
173
|
+
event: zod_1.z.object({}).passthrough(),
|
|
174
|
+
steps: zod_1.z.object({}).passthrough().optional().nullable(),
|
|
175
|
+
})
|
|
176
|
+
.parse(data);
|
|
177
|
+
const ret = await fn["runFn"]({ event }, steps || {});
|
|
178
|
+
const isOp = ret[0];
|
|
179
|
+
if (isOp) {
|
|
180
|
+
return {
|
|
181
|
+
status: 206,
|
|
182
|
+
body: ret[1],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
175
185
|
return {
|
|
176
186
|
status: 200,
|
|
177
|
-
body,
|
|
187
|
+
body: ret[1],
|
|
178
188
|
};
|
|
179
189
|
}
|
|
180
190
|
catch (err) {
|
|
@@ -232,7 +242,7 @@ class InngestCommHandler {
|
|
|
232
242
|
v: "0.1",
|
|
233
243
|
};
|
|
234
244
|
// Calculate the checksum of the body... without the checksum itself being included.
|
|
235
|
-
body.hash = (0,
|
|
245
|
+
body.hash = (0, hash_js_1.sha256)().update(JSON.stringify(body)).digest("hex");
|
|
236
246
|
return body;
|
|
237
247
|
}
|
|
238
248
|
async register(url, devServerHost) {
|
package/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":";;;AACA,qCAAiC;AACjC,6BAAwB;AAGxB,6CAAsD;AACtD,mDAAuE;AACvE,6CAA8C;AAC9C,uCAAoC;AAQpC,uCAAoC;AAEpC;;GAEG;AACH,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;IAC/B,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAC9C,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,yBAAyB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,mBAAU,EAAC,SAAS,CAAC,mCAAI,IAAI,CAAC;IAC/D,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAES,YAAY;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA1XD,gDA0XC"}
|
package/helpers/func.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InngestFunction } from "../components/InngestFunction";
|
|
2
|
-
import type { EventPayload, FunctionOptions,
|
|
2
|
+
import type { EventPayload, FunctionOptions, MultiStepFn, SingleStepFn } from "../types";
|
|
3
3
|
import type { EventName } from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* Given an event to listen to, run the given function when that event is
|
|
@@ -7,11 +7,21 @@ import type { EventName } from "./types";
|
|
|
7
7
|
*
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
export declare const createFunction: <Event_1 extends EventPayload>(nameOrOpts: string | FunctionOptions, event: EventName<Event_1>, fn:
|
|
10
|
+
export declare const createFunction: <Event_1 extends EventPayload>(nameOrOpts: string | FunctionOptions, event: EventName<Event_1>, fn: SingleStepFn<Event_1, string, "step">) => InngestFunction<any>;
|
|
11
11
|
/**
|
|
12
12
|
* Run the given `fn` at a specified time or on a schedule given by `cron`.
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
export declare const createScheduledFunction: (nameOrOpts: string | FunctionOptions, cron: string, fn:
|
|
16
|
+
export declare const createScheduledFunction: (nameOrOpts: string | FunctionOptions, cron: string, fn: SingleStepFn<null, string, "step">) => InngestFunction<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Given an event to listen to, run the given step function when that event is
|
|
19
|
+
* seen.
|
|
20
|
+
*
|
|
21
|
+
* These can be used to build multi-step, serverless workflows with delays,
|
|
22
|
+
* conditional logic, and coordination between events.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const createStepFunction: <T extends EventPayload>(nameOrOpts: string | FunctionOptions, event: EventName<T>, fn: MultiStepFn<Record<T["name"], T>, T["name"], string, "step">) => InngestFunction<any>;
|
|
17
27
|
//# sourceMappingURL=func.d.ts.map
|
package/helpers/func.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"func.d.ts","sourceRoot":"","sources":["../../src/helpers/func.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"func.d.ts","sourceRoot":"","sources":["../../src/helpers/func.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,6CAKb,MAAM,GAAG,eAAe,2EAWnC,gBAAgB,GAAG,CAMrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,eAKtB,MAAM,GAAG,eAAe,QAY9B,MAAM,MAKR,aAAa,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KACrC,gBAAgB,GAAG,CAMrB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,uCAKjB,MAAM,GAAG,eAAe,4FAWnC,gBAAgB,GAAG,CAMrB,CAAC"}
|
package/helpers/func.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createScheduledFunction = exports.createFunction = void 0;
|
|
3
|
+
exports.createStepFunction = exports.createScheduledFunction = exports.createFunction = void 0;
|
|
4
4
|
const InngestFunction_1 = require("../components/InngestFunction");
|
|
5
|
-
const InngestStep_1 = require("../components/InngestStep");
|
|
6
5
|
/**
|
|
7
6
|
* Given an event to listen to, run the given function when that event is
|
|
8
7
|
* seen.
|
|
@@ -23,7 +22,7 @@ event,
|
|
|
23
22
|
* The function to run when the event is received.
|
|
24
23
|
*/
|
|
25
24
|
fn) => {
|
|
26
|
-
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event },
|
|
25
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event }, fn);
|
|
27
26
|
};
|
|
28
27
|
exports.createFunction = createFunction;
|
|
29
28
|
/**
|
|
@@ -52,7 +51,33 @@ cron,
|
|
|
52
51
|
* The function to run.
|
|
53
52
|
*/
|
|
54
53
|
fn) => {
|
|
55
|
-
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { cron },
|
|
54
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { cron }, fn);
|
|
56
55
|
};
|
|
57
56
|
exports.createScheduledFunction = createScheduledFunction;
|
|
57
|
+
/**
|
|
58
|
+
* Given an event to listen to, run the given step function when that event is
|
|
59
|
+
* seen.
|
|
60
|
+
*
|
|
61
|
+
* These can be used to build multi-step, serverless workflows with delays,
|
|
62
|
+
* conditional logic, and coordination between events.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
const createStepFunction = (
|
|
67
|
+
/**
|
|
68
|
+
* The name or options for this Inngest function - providing options is
|
|
69
|
+
* useful for defining a custom ID.
|
|
70
|
+
*/
|
|
71
|
+
nameOrOpts,
|
|
72
|
+
/**
|
|
73
|
+
* The event to listen for.
|
|
74
|
+
*/
|
|
75
|
+
event,
|
|
76
|
+
/**
|
|
77
|
+
* The function to run when the event is received.
|
|
78
|
+
*/
|
|
79
|
+
fn) => {
|
|
80
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event }, fn);
|
|
81
|
+
};
|
|
82
|
+
exports.createStepFunction = createStepFunction;
|
|
58
83
|
//# sourceMappingURL=func.js.map
|
package/helpers/func.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"func.js","sourceRoot":"","sources":["../../src/helpers/func.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;
|
|
1
|
+
{"version":3,"file":"func.js","sourceRoot":"","sources":["../../src/helpers/func.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAShE;;;;;GAKG;AACI,MAAM,cAAc,GAAG;AAC5B;;;GAGG;AACH,UAAoC;AAEpC;;GAEG;AACH,KAAuB;AAEvB;;GAEG;AACH,EAAuC,EACjB,EAAE;IACxB,OAAO,IAAI,iCAAe,CACxB,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,EAClE,EAAE,KAAK,EAAE,KAAe,EAAE,EAC1B,EAAE,CACH,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,cAAc,kBAsBzB;AAEF;;;;GAIG;AACI,MAAM,uBAAuB,GAAG;AACrC;;;GAGG;AACH,UAAoC;AAEpC;;;;;;;;;GASG;AACH,IAAY;AAEZ;;GAEG;AACH,EAAsC,EAChB,EAAE;IACxB,OAAO,IAAI,iCAAe,CACxB,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,EAClE,EAAE,IAAI,EAAE,EACR,EAAE,CACH,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,uBAAuB,2BA6BlC;AAEF;;;;;;;;GAQG;AACI,MAAM,kBAAkB,GAAG;AAChC;;;GAGG;AACH,UAAoC;AAEpC;;GAEG;AACH,KAAmB;AAEnB;;GAEG;AACH,EAAgE,EAC1C,EAAE;IACxB,OAAO,IAAI,iCAAe,CACxB,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,EAClE,EAAE,KAAK,EAAE,KAAe,EAAE,EAC1B,EAAE,CACH,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,kBAAkB,sBAsB7B"}
|
package/helpers/strings.d.ts
CHANGED
|
@@ -2,4 +2,12 @@
|
|
|
2
2
|
* Returns a slugified string used ot generate consistent IDs.
|
|
3
3
|
*/
|
|
4
4
|
export declare const slugify: (str: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Convert a given `Date`, `number`, or `ms`-compatible `string` to a
|
|
7
|
+
* Inngest sleep-compatible time string (e.g. `"1d"` or `"2h3010s"`).
|
|
8
|
+
*
|
|
9
|
+
* Can optionally provide a `now` date to use as the base for the calculation,
|
|
10
|
+
* otherwise a new date will be created on invocation.
|
|
11
|
+
*/
|
|
12
|
+
export declare const timeStr: (input: string | number | Date, now?: Date) => string;
|
|
5
13
|
//# sourceMappingURL=strings.d.ts.map
|
package/helpers/strings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,QAAS,MAAM,KAAG,MASrC,CAAC;AAqBF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,UAIX,MAAM,GAAG,MAAM,GAAG,IAAI,iBAM5B,MAiCF,CAAC"}
|
package/helpers/strings.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.slugify = void 0;
|
|
6
|
+
exports.timeStr = exports.slugify = void 0;
|
|
7
|
+
const ms_1 = __importDefault(require("ms"));
|
|
4
8
|
/**
|
|
5
9
|
* Returns a slugified string used ot generate consistent IDs.
|
|
6
10
|
*/
|
|
@@ -15,4 +19,59 @@ const slugify = (str) => {
|
|
|
15
19
|
.join(join);
|
|
16
20
|
};
|
|
17
21
|
exports.slugify = slugify;
|
|
22
|
+
const millisecond = 1;
|
|
23
|
+
const second = millisecond * 1000;
|
|
24
|
+
const minute = second * 60;
|
|
25
|
+
const hour = minute * 60;
|
|
26
|
+
const day = hour * 24;
|
|
27
|
+
const week = day * 7;
|
|
28
|
+
/**
|
|
29
|
+
* A collection of periods in milliseconds and their suffixes used when creating
|
|
30
|
+
* time strings.
|
|
31
|
+
*/
|
|
32
|
+
const periods = [
|
|
33
|
+
["w", week],
|
|
34
|
+
["d", day],
|
|
35
|
+
["h", hour],
|
|
36
|
+
["m", minute],
|
|
37
|
+
["s", second],
|
|
38
|
+
];
|
|
39
|
+
/**
|
|
40
|
+
* Convert a given `Date`, `number`, or `ms`-compatible `string` to a
|
|
41
|
+
* Inngest sleep-compatible time string (e.g. `"1d"` or `"2h3010s"`).
|
|
42
|
+
*
|
|
43
|
+
* Can optionally provide a `now` date to use as the base for the calculation,
|
|
44
|
+
* otherwise a new date will be created on invocation.
|
|
45
|
+
*/
|
|
46
|
+
const timeStr = (
|
|
47
|
+
/**
|
|
48
|
+
* The future date to use to convert to a time string.
|
|
49
|
+
*/
|
|
50
|
+
input,
|
|
51
|
+
/**
|
|
52
|
+
* Optionally provide a date to use as the base for the calculation.
|
|
53
|
+
*/
|
|
54
|
+
now = new Date()) => {
|
|
55
|
+
let date = input;
|
|
56
|
+
if (typeof date === "string" || typeof date === "number") {
|
|
57
|
+
const numTimeout = typeof date === "string" ? (0, ms_1.default)(date) : date;
|
|
58
|
+
date = new Date(Date.now() + numTimeout);
|
|
59
|
+
}
|
|
60
|
+
now.setMilliseconds(0);
|
|
61
|
+
date.setMilliseconds(0);
|
|
62
|
+
const isValidDate = !isNaN(date.getTime());
|
|
63
|
+
if (!isValidDate) {
|
|
64
|
+
throw new Error("Invalid date given to convert to time string");
|
|
65
|
+
}
|
|
66
|
+
const timeNum = date.getTime() - now.getTime();
|
|
67
|
+
const [, timeStr] = periods.reduce(([num, str], [suffix, period]) => {
|
|
68
|
+
const numPeriods = Math.floor(num / period);
|
|
69
|
+
if (numPeriods > 0) {
|
|
70
|
+
return [num % period, `${str}${numPeriods}${suffix}`];
|
|
71
|
+
}
|
|
72
|
+
return [num, str];
|
|
73
|
+
}, [timeNum, ""]);
|
|
74
|
+
return timeStr;
|
|
75
|
+
};
|
|
76
|
+
exports.timeStr = timeStr;
|
|
18
77
|
//# sourceMappingURL=strings.js.map
|
package/helpers/strings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AAEpB;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE;IAC7C,MAAM,IAAI,GAAG,GAAG,CAAC;IACjB,OAAO,GAAG;SACP,WAAW,EAAE;SACb,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC;SAC7B,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;SACpB,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC;AATW,QAAA,OAAO,WASlB;AAEF,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;AAClC,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC;AAC3B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AAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE;QAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;QAE5C,IAAI,UAAU,GAAG,CAAC,EAAE;YAClB,OAAO,CAAC,GAAG,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,CAAC;SACvD;QAED,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpB,CAAC,EACD,CAAC,OAAO,EAAE,EAAE,CAAC,CACd,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AA3CW,QAAA,OAAO,WA2ClB"}
|
package/helpers/types.d.ts
CHANGED
|
@@ -25,4 +25,30 @@ export declare type SendEventPayload<Events extends Record<string, EventPayload>
|
|
|
25
25
|
* Retrieve an event's name based on the given payload. Defaults to `string`.
|
|
26
26
|
*/
|
|
27
27
|
export declare type EventName<Event extends EventPayload> = Event extends EventPayload ? Event["name"] : string;
|
|
28
|
+
/**
|
|
29
|
+
* A list of simple, JSON-compatible, primitive types that contain no other
|
|
30
|
+
* values.
|
|
31
|
+
*/
|
|
32
|
+
export declare type Primitive = string | number | boolean | undefined | null;
|
|
33
|
+
/**
|
|
34
|
+
* Given a key and a value, create a string that would be used to access that
|
|
35
|
+
* property in code.
|
|
36
|
+
*/
|
|
37
|
+
declare type StringPath<K extends string | number, V> = V extends Primitive ? `${K}` : `${K}` | `${K}.${Path<V>}`;
|
|
38
|
+
/**
|
|
39
|
+
* Given an object or array, recursively return all string paths used to access
|
|
40
|
+
* properties within those objects.
|
|
41
|
+
*/
|
|
42
|
+
declare type Path<T> = T extends Array<infer V> ? StringPath<number, V> : {
|
|
43
|
+
[K in keyof T]-?: StringPath<K & string, T[K]>;
|
|
44
|
+
}[keyof T];
|
|
45
|
+
/**
|
|
46
|
+
* Given an object, recursively return all string paths used to access
|
|
47
|
+
* properties within that object as if you were in code.
|
|
48
|
+
*
|
|
49
|
+
* This is an exported helper method to ensure we only try to access object
|
|
50
|
+
* paths of known objects.
|
|
51
|
+
*/
|
|
52
|
+
export declare type ObjectPaths<T extends Record<string, any>> = Path<T>;
|
|
53
|
+
export {};
|
|
28
54
|
//# sourceMappingURL=types.d.ts.map
|