two-stroke 4.1.11 → 4.2.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 CHANGED
@@ -10,20 +10,20 @@
10
10
  "dependencies": {
11
11
  "@anatine/zod-openapi": "^2.2.7",
12
12
  "@asteasolutions/zod-to-openapi": "^7.3.0",
13
- "@cloudflare/vitest-pool-workers": "^0.8.0",
14
- "@cloudflare/workers-types": "^4.20250313.0",
15
- "@sentry/cli": "^2.42.3",
16
- "@types/node": "^22.13.10",
17
- "@typescript-eslint/eslint-plugin": "^8.26.1",
18
- "@typescript-eslint/parser": "^8.26.1",
19
- "@vitest/coverage-istanbul": "^3.0.8",
13
+ "@cloudflare/vitest-pool-workers": "^0.8.8",
14
+ "@cloudflare/workers-types": "^4.20250327.0",
15
+ "@sentry/cli": "^2.43.0",
16
+ "@types/node": "^22.13.14",
17
+ "@typescript-eslint/eslint-plugin": "^8.28.0",
18
+ "@typescript-eslint/parser": "^8.28.0",
19
+ "@vitest/coverage-istanbul": "^3.0.9",
20
20
  "eslint-config-prettier": "^10.1.1",
21
- "eslint-config-two-stroke": "^1.1.11",
21
+ "eslint-config-two-stroke": "^1.1.12",
22
22
  "eslint-config-typescript": "^3.0.0",
23
23
  "jose": "^6.0.10",
24
24
  "jwk-subtle": "^1.0.7",
25
- "miniflare": "^4.20250310.0",
26
- "openapi-fetch": "^0.13.4",
25
+ "miniflare": "^4.20250321.1",
26
+ "openapi-fetch": "^0.13.5",
27
27
  "openapi-typescript": "^7.6.1",
28
28
  "openapi3-ts": "^4.4.0",
29
29
  "pbkdf-subtle": "^1.0.0",
@@ -52,12 +52,12 @@
52
52
  "name": "two-stroke",
53
53
  "packageManager": "yarn@4.6.0",
54
54
  "type": "module",
55
- "version": "4.1.11",
55
+ "version": "4.2.0",
56
56
  "devDependencies": {
57
57
  "@types/eslint": "^9.6.1",
58
- "eslint": "^9.22.0",
58
+ "eslint": "^9.23.0",
59
59
  "prettier": "^3.5.3",
60
60
  "typescript": "^5.8.2",
61
- "vitest": "^3.0.8"
61
+ "vitest": "^3.0.9"
62
62
  }
63
63
  }
package/src/index.ts CHANGED
@@ -24,7 +24,7 @@ export function twoStroke<T extends Env>(title: string, release: string) {
24
24
  method: "GET",
25
25
  path: "/doc",
26
26
  matcher: /^\/doc$/,
27
- output: z.object({}),
27
+ output: z.any(),
28
28
  handler: openAPI(title, release, noAuth, routes),
29
29
  });
30
30
  const crons: {
@@ -87,12 +87,19 @@ export function twoStroke<T extends Env>(title: string, release: string) {
87
87
  });
88
88
  }
89
89
  if (route.method === "POST" || route.method === "PUT") {
90
- const rawBody =
91
- req.headers.get("Content-Type") ===
92
- "application/x-www-form-urlencoded"
90
+ const rawBody = route.input
91
+ ? req.headers.get("Content-Type") ===
92
+ "application/x-www-form-urlencoded"
93
93
  ? Object.fromEntries(new URLSearchParams(await req.text()))
94
- : await req.json();
95
- const body = route.input.safeParse(rawBody);
94
+ : await req.json()
95
+ : undefined;
96
+ const body = route.input
97
+ ? route.input.safeParse(rawBody)
98
+ : {
99
+ success: true,
100
+ data: undefined,
101
+ error: undefined,
102
+ };
96
103
  if (body.success)
97
104
  response = await route.handler({
98
105
  req,
@@ -345,7 +352,7 @@ export function twoStroke<T extends Env>(title: string, release: string) {
345
352
  },
346
353
 
347
354
  post<
348
- I extends ZodSchema,
355
+ I extends ZodSchema | undefined,
349
356
  O extends ZodSchema,
350
357
  A,
351
358
  P extends string,
package/src/open-api.ts CHANGED
@@ -61,14 +61,16 @@ export const openAPI =
61
61
  request:
62
62
  route.method === "POST" || route.method === "PUT"
63
63
  ? {
64
- body: {
65
- content: {
66
- "application/json": {
67
- schema: route.input,
68
- },
69
- },
70
- required: true,
71
- },
64
+ body: route.input
65
+ ? {
66
+ content: {
67
+ "application/json": {
68
+ schema: route.input,
69
+ },
70
+ },
71
+ required: true,
72
+ }
73
+ : undefined,
72
74
  query: route.params,
73
75
  params,
74
76
  }
package/src/test.ts CHANGED
@@ -42,10 +42,10 @@ export const setupTests = async <Paths extends {}>() => {
42
42
  // Hack around Cloudflare not setting
43
43
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
44
44
  // @ts-expect-error
45
- publicKey[Symbol.toStringTag] = 'CryptoKey';
45
+ publicKey[Symbol.toStringTag] = "CryptoKey";
46
46
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
47
47
  // @ts-expect-error
48
- privateKey[Symbol.toStringTag] = 'CryptoKey';
48
+ privateKey[Symbol.toStringTag] = "CryptoKey";
49
49
  const jwk = await exportJWK(publicKey);
50
50
  jwk.kid = "test";
51
51
  jwk.alg = "RS256";
package/src/types.ts CHANGED
@@ -29,7 +29,7 @@ export type Route<T extends Env, A> =
29
29
  method: "POST" | "PUT";
30
30
  path: string;
31
31
  matcher: RegExp;
32
- input: ZodSchema;
32
+ input: ZodSchema | undefined;
33
33
  output: ZodSchema;
34
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
35
  handler: Handler<T, any, any, A, string>;