two-stroke 2.0.0 → 3.0.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/package.json +1 -1
- package/src/index.ts +12 -44
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { verify as jwkVerify } from "jwk-subtle";
|
|
2
2
|
import { verify as pbkdfVerify } from "pbkdf-subtle";
|
|
3
3
|
import { Toucan } from "toucan-js";
|
|
4
|
-
import {
|
|
4
|
+
import { SafeParseReturnType, ZodObject, ZodSchema, z } from "zod";
|
|
5
5
|
import { openAPI } from "./open-api";
|
|
6
6
|
import { Env, Handler, Route } from "./types";
|
|
7
7
|
|
|
@@ -288,56 +288,24 @@ export function twoStroke<T extends Env>(title: string, release: string) {
|
|
|
288
288
|
}
|
|
289
289
|
throw Error("Invalid");
|
|
290
290
|
},
|
|
291
|
-
queueHandler<I extends ZodSchema
|
|
291
|
+
queueHandler<I extends ZodSchema>(
|
|
292
292
|
input: I,
|
|
293
293
|
handler: (c: {
|
|
294
294
|
env: T;
|
|
295
|
-
batch: MessageBatch<
|
|
296
|
-
sentry: Toucan;
|
|
297
|
-
}) => Promise<void>,
|
|
298
|
-
parseFailedHandler?: (c: {
|
|
299
|
-
env: T;
|
|
300
|
-
batch: MessageBatch & {
|
|
301
|
-
messages: (Message<unknown> & {
|
|
302
|
-
error: SafeParseError<z.input<I>>;
|
|
303
|
-
})[];
|
|
304
|
-
};
|
|
295
|
+
batch: MessageBatch<z.input<I>>;
|
|
305
296
|
sentry: Toucan;
|
|
297
|
+
parsedBatch: SafeParseReturnType<z.input<I>, z.infer<I>>[];
|
|
306
298
|
}) => Promise<void>,
|
|
307
299
|
) {
|
|
308
300
|
_queue = async ({ batch, env, sentry }) => {
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
> = input.safeParse(message.body);
|
|
318
|
-
if (!body.success) {
|
|
319
|
-
console.error(body.error, message);
|
|
320
|
-
return {
|
|
321
|
-
messages: acc.messages,
|
|
322
|
-
failed: [...acc.failed, { ...message, error: body }],
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return {
|
|
327
|
-
messages: [...acc.messages, { ...message, body: body.data }],
|
|
328
|
-
failed: acc.failed,
|
|
329
|
-
};
|
|
330
|
-
},
|
|
331
|
-
{ messages: [], failed: [] },
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
await handler({ batch: { ...batch, messages }, env, sentry });
|
|
335
|
-
if (failed.length > 0)
|
|
336
|
-
await parseFailedHandler?.({
|
|
337
|
-
batch: { ...batch, messages: failed },
|
|
338
|
-
env,
|
|
339
|
-
sentry,
|
|
340
|
-
});
|
|
301
|
+
const parsedBatch = batch.messages.map((message) => {
|
|
302
|
+
const passed = input.safeParse(message.body);
|
|
303
|
+
if (!passed.success) {
|
|
304
|
+
console.error(passed.error, message);
|
|
305
|
+
}
|
|
306
|
+
return passed;
|
|
307
|
+
});
|
|
308
|
+
await handler({ batch, env, sentry, parsedBatch });
|
|
341
309
|
console.log("Queue batch finished");
|
|
342
310
|
};
|
|
343
311
|
},
|