create-cloudflare 0.0.0-fa045c93 → 0.0.0-fa1016cf

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 (55) hide show
  1. package/dist/cli.js +1453 -2300
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +23 -23
  4. package/templates/analog/c3.ts +4 -4
  5. package/templates/angular/c3.ts +2 -2
  6. package/templates/astro/c3.ts +3 -3
  7. package/templates/common/js/package.json +1 -1
  8. package/templates/common/ts/package.json +2 -2
  9. package/templates/common/ts/src/ab-test.ts +2 -2
  10. package/templates/common/ts/src/index.ts +2 -2
  11. package/templates/common/ts/src/proxy.ts +2 -2
  12. package/templates/common/ts/src/redirect.ts +2 -2
  13. package/templates/common/ts/tsconfig.json +1 -1
  14. package/templates/hello-world/js/package.json +3 -3
  15. package/templates/hello-world/js/vitest.config.js +8 -8
  16. package/templates/hello-world/ts/package.json +4 -4
  17. package/templates/hello-world/ts/src/index.ts +2 -2
  18. package/templates/hello-world/ts/test/tsconfig.json +6 -9
  19. package/templates/hello-world/ts/tsconfig.json +1 -1
  20. package/templates/hello-world/ts/vitest.config.mts +11 -0
  21. package/templates/hello-world-durable-object/c3.ts +1 -1
  22. package/templates/hello-world-durable-object/js/package.json +1 -1
  23. package/templates/hello-world-durable-object/js/src/index.js +1 -1
  24. package/templates/hello-world-durable-object/js/wrangler.toml +1 -1
  25. package/templates/hello-world-durable-object/ts/package.json +2 -2
  26. package/templates/hello-world-durable-object/ts/src/index.ts +3 -3
  27. package/templates/hello-world-durable-object/ts/tsconfig.json +1 -1
  28. package/templates/hello-world-durable-object/ts/wrangler.toml +2 -2
  29. package/templates/hello-world-python/py/package.json +1 -1
  30. package/templates/hono/c3.ts +1 -1
  31. package/templates/next/c3.ts +8 -6
  32. package/templates/nuxt/c3.ts +8 -9
  33. package/templates/openapi/ts/README.md +3 -3
  34. package/templates/openapi/ts/package.json +5 -3
  35. package/templates/openapi/ts/src/endpoints/taskCreate.ts +26 -16
  36. package/templates/openapi/ts/src/endpoints/taskDelete.ts +20 -19
  37. package/templates/openapi/ts/src/endpoints/taskFetch.ts +30 -23
  38. package/templates/openapi/ts/src/endpoints/taskList.ts +27 -24
  39. package/templates/openapi/ts/src/index.ts +14 -20
  40. package/templates/openapi/ts/src/types.ts +9 -8
  41. package/templates/pre-existing/c3.ts +5 -5
  42. package/templates/pre-existing/js/package.json +1 -1
  43. package/templates/queues/js/package.json +1 -1
  44. package/templates/queues/ts/package.json +2 -2
  45. package/templates/queues/ts/src/index.ts +3 -3
  46. package/templates/queues/ts/tsconfig.json +1 -1
  47. package/templates/qwik/c3.ts +3 -3
  48. package/templates/scheduled/js/package.json +3 -3
  49. package/templates/scheduled/js/src/index.js +8 -1
  50. package/templates/scheduled/ts/package.json +4 -4
  51. package/templates/scheduled/ts/src/index.ts +3 -3
  52. package/templates/scheduled/ts/tsconfig.json +1 -1
  53. package/templates/solid/c3.ts +11 -9
  54. package/templates/svelte/c3.ts +6 -6
  55. package/templates/hello-world/ts/vitest.config.ts +0 -11
@@ -22,7 +22,7 @@ const configure = async (ctx: C3Context) => {
22
22
  silent: true,
23
23
  startText: "Installing adapter",
24
24
  doneText: `${brandColor("installed")} ${dim(
25
- `via \`${npx} astro add cloudflare\``
25
+ `via \`${npx} astro add cloudflare\``,
26
26
  )}`,
27
27
  });
28
28
 
@@ -49,7 +49,7 @@ const updateAstroConfig = () => {
49
49
  b.identifier("platformProxy"),
50
50
  b.objectExpression([
51
51
  b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
52
- ])
52
+ ]),
53
53
  ),
54
54
  ]),
55
55
  ];
@@ -77,7 +77,7 @@ const updateEnvDeclaration = (ctx: C3Context) => {
77
77
  // Preserve comments with the new body
78
78
  const comments = n.get("comments").value;
79
79
  n.node.comments = comments.map((c: recast.types.namedTypes.CommentLine) =>
80
- b.commentLine(c.value)
80
+ b.commentLine(c.value),
81
81
  );
82
82
 
83
83
  // Add the patch
@@ -9,6 +9,6 @@
9
9
  },
10
10
  "devDependencies": {
11
11
  "itty-router": "^3.0.12",
12
- "wrangler": "^3.0.0"
12
+ "wrangler": "^3.60.3"
13
13
  }
14
14
  }
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "devDependencies": {
12
12
  "itty-router": "^3.0.12",
13
- "typescript": "^5.0.4",
14
- "wrangler": "^3.0.0"
13
+ "typescript": "^5.5.2",
14
+ "wrangler": "^3.60.3"
15
15
  }
16
16
  }
@@ -6,7 +6,7 @@ const EXPERIMENTS = [
6
6
  ];
7
7
 
8
8
  export default {
9
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
9
+ async fetch(request, env, ctx): Promise<Response> {
10
10
  const fingerprint = [request.headers.get('cf-connecting-ip'), request.cf?.postalCode]; // add any values you want considered as a fingerprint
11
11
  const activeExperiments = await getActiveExperiments(fingerprint, EXPERIMENTS);
12
12
 
@@ -22,7 +22,7 @@ export default {
22
22
 
23
23
  return rewriter.transform(res);
24
24
  },
25
- };
25
+ } satisfies ExportedHandler<Env>;
26
26
 
27
27
  // Get active experiments by hashing a fingerprint
28
28
  async function getActiveExperiments(fingerprint: unknown, experiments: Array<{ name: string; threshold: number }>) {
@@ -19,7 +19,7 @@ import apiRouter from './router';
19
19
  export default {
20
20
  // The fetch handler is invoked when this worker receives a HTTP(S) request
21
21
  // and should return a Response (optionally wrapped in a Promise)
22
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
22
+ async fetch(request, env, ctx): Promise<Response> {
23
23
  // You'll find it helpful to parse the request.url string into a URL object. Learn more at https://developer.mozilla.org/en-US/docs/Web/API/URL
24
24
  const url = new URL(request.url);
25
25
 
@@ -46,4 +46,4 @@ export default {
46
46
  { headers: { 'Content-Type': 'text/html' } }
47
47
  );
48
48
  },
49
- };
49
+ } satisfies ExportedHandler<Env>;
@@ -1,5 +1,5 @@
1
1
  export default {
2
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
2
+ async fetch(request, env, ctx): Promise<Response> {
3
3
  const url = new URL(request.url);
4
4
 
5
5
  const proxyUrl = url.searchParams.get('proxyUrl'); // get a query param value (?proxyUrl=...)
@@ -20,4 +20,4 @@ export default {
20
20
 
21
21
  return res;
22
22
  },
23
- };
23
+ } satisfies ExportedHandler<Env>;
@@ -1,5 +1,5 @@
1
1
  export default {
2
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
2
+ async fetch(request, env, ctx): Promise<Response> {
3
3
  const url = new URL(request.url);
4
4
  const redirectUrl = url.searchParams.get('redirectUrl'); // get a query param value (?redirectUrl=...)
5
5
 
@@ -10,4 +10,4 @@ export default {
10
10
  // The Response class has static methods to create common Response objects as a convenience
11
11
  return Response.redirect(redirectUrl);
12
12
  },
13
- };
13
+ } satisfies ExportedHandler<Env>;
@@ -13,7 +13,7 @@
13
13
  /* Language and Environment */
14
14
  "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  "lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
16
- "jsx": "react" /* Specify what JSX code is generated. */,
16
+ "jsx": "react-jsx" /* Specify what JSX code is generated. */,
17
17
  // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
18
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
19
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
@@ -9,8 +9,8 @@
9
9
  "test": "vitest"
10
10
  },
11
11
  "devDependencies": {
12
- "wrangler": "^3.0.0",
13
- "vitest": "1.3.0",
14
- "@cloudflare/vitest-pool-workers": "^0.1.0"
12
+ "@cloudflare/vitest-pool-workers": "^0.4.5",
13
+ "wrangler": "^3.60.3",
14
+ "vitest": "1.5.0"
15
15
  }
16
16
  }
@@ -1,11 +1,11 @@
1
- import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
1
+ import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
2
2
 
3
3
  export default defineWorkersConfig({
4
- test: {
5
- poolOptions: {
6
- workers: {
7
- wrangler: { configPath: "./wrangler.toml" },
8
- },
9
- },
10
- },
4
+ test: {
5
+ poolOptions: {
6
+ workers: {
7
+ wrangler: { configPath: './wrangler.toml' },
8
+ },
9
+ },
10
+ },
11
11
  });
@@ -10,9 +10,9 @@
10
10
  "cf-typegen": "wrangler types"
11
11
  },
12
12
  "devDependencies": {
13
- "typescript": "^5.0.4",
14
- "wrangler": "^3.0.0",
15
- "vitest": "1.3.0",
16
- "@cloudflare/vitest-pool-workers": "^0.1.0"
13
+ "@cloudflare/vitest-pool-workers": "^0.4.5",
14
+ "typescript": "^5.5.2",
15
+ "vitest": "1.5.0",
16
+ "wrangler": "^3.60.3"
17
17
  }
18
18
  }
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  export default {
15
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
15
+ async fetch(request, env, ctx): Promise<Response> {
16
16
  return new Response('Hello World!');
17
17
  },
18
- };
18
+ } satisfies ExportedHandler<Env>;
@@ -1,11 +1,8 @@
1
1
  {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "types": [
5
- "@cloudflare/workers-types/experimental",
6
- "@cloudflare/vitest-pool-workers"
7
- ]
8
- },
9
- "include": ["./**/*.ts", "../src/env.d.ts"],
10
- "exclude": []
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["@cloudflare/workers-types/experimental", "@cloudflare/vitest-pool-workers"]
5
+ },
6
+ "include": ["./**/*.ts", "../src/env.d.ts"],
7
+ "exclude": []
11
8
  }
@@ -13,7 +13,7 @@
13
13
  /* Language and Environment */
14
14
  "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  "lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
16
- "jsx": "react" /* Specify what JSX code is generated. */,
16
+ "jsx": "react-jsx" /* Specify what JSX code is generated. */,
17
17
  // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
18
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
19
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
@@ -0,0 +1,11 @@
1
+ import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
2
+
3
+ export default defineWorkersConfig({
4
+ test: {
5
+ poolOptions: {
6
+ workers: {
7
+ wrangler: { configPath: './wrangler.toml' },
8
+ },
9
+ },
10
+ },
11
+ });
@@ -1,7 +1,7 @@
1
1
  export default {
2
2
  configVersion: 1,
3
3
  id: "hello-world-durable-object",
4
- displayName: '"Hello World" Durable Object',
4
+ displayName: "Co-ordination / multiplayer API (using Durable Objects)",
5
5
  platform: "workers",
6
6
  copyFiles: {
7
7
  variants: {
@@ -8,6 +8,6 @@
8
8
  "start": "wrangler dev"
9
9
  },
10
10
  "devDependencies": {
11
- "wrangler": "^3.0.0"
11
+ "wrangler": "^3.60.3"
12
12
  }
13
13
  }
@@ -32,7 +32,7 @@ export class MyDurableObject extends DurableObject {
32
32
 
33
33
  /**
34
34
  * The Durable Object exposes an RPC method sayHello which will be invoked when when a Durable
35
- * Object instance receives a request from a Worker via the same method invokation on the stub
35
+ * Object instance receives a request from a Worker via the same method invocation on the stub
36
36
  *
37
37
  * @param {string} name - The name provided to a Durable Object instance from a Worker
38
38
  * @returns {Promise<string>} The greeting to be sent back to the Worker
@@ -1,6 +1,6 @@
1
1
  #:schema node_modules/wrangler/config-schema.json
2
2
  name = "<TBD>"
3
- main = "src/index.ts"
3
+ main = "src/index.js"
4
4
  compatibility_date = "<TBD>"
5
5
 
6
6
  # Automatically place your workloads in an optimal location to minimize latency.
@@ -9,7 +9,7 @@
9
9
  "cf-typegen": "wrangler types"
10
10
  },
11
11
  "devDependencies": {
12
- "typescript": "^5.0.4",
13
- "wrangler": "^3.0.0"
12
+ "typescript": "^5.5.2",
13
+ "wrangler": "^3.60.3"
14
14
  }
15
15
  }
@@ -49,7 +49,7 @@ export class MyDurableObject extends DurableObject {
49
49
 
50
50
  /**
51
51
  * The Durable Object exposes an RPC method sayHello which will be invoked when when a Durable
52
- * Object instance receives a request from a Worker via the same method invokation on the stub
52
+ * Object instance receives a request from a Worker via the same method invocation on the stub
53
53
  *
54
54
  * @param name - The name provided to a Durable Object instance from a Worker
55
55
  * @returns The greeting to be sent back to the Worker
@@ -68,7 +68,7 @@ export default {
68
68
  * @param ctx - The execution context of the Worker
69
69
  * @returns The response to be sent back to the client
70
70
  */
71
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
71
+ async fetch(request, env, ctx): Promise<Response> {
72
72
  // We will create a `DurableObjectId` using the pathname from the Worker request
73
73
  // This id refers to a unique instance of our 'MyDurableObject' class above
74
74
  let id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
@@ -83,4 +83,4 @@ export default {
83
83
 
84
84
  return new Response(greeting);
85
85
  },
86
- };
86
+ } satisfies ExportedHandler<Env>;
@@ -13,7 +13,7 @@
13
13
  /* Language and Environment */
14
14
  "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  "lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
16
- "jsx": "react" /* Specify what JSX code is generated. */,
16
+ "jsx": "react-jsx" /* Specify what JSX code is generated. */,
17
17
  // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
18
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
19
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
@@ -48,13 +48,13 @@ compatibility_date = "<TBD>"
48
48
 
49
49
  # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
50
50
  # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
51
- # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
51
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
52
52
  [[durable_objects.bindings]]
53
53
  name = "MY_DURABLE_OBJECT"
54
54
  class_name = "MyDurableObject"
55
55
 
56
56
  # Durable Object migrations.
57
- # Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
57
+ # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
58
58
  [[migrations]]
59
59
  tag = "v1"
60
60
  new_classes = ["MyDurableObject"]
@@ -8,6 +8,6 @@
8
8
  "start": "wrangler dev"
9
9
  },
10
10
  "devDependencies": {
11
- "wrangler": "^3.0.0"
11
+ "wrangler": "^3.60.3"
12
12
  }
13
13
  }
@@ -35,7 +35,7 @@ const configure = async (ctx: C3Context) => {
35
35
  // Insert the env declaration after the last import (but before the rest of the body)
36
36
  visitProgram: function (n) {
37
37
  const lastImportIndex = n.node.body.findLastIndex(
38
- (t) => t.type === "ImportDeclaration"
38
+ (t) => t.type === "ImportDeclaration",
39
39
  );
40
40
  const lastImport = n.get("body", lastImportIndex);
41
41
  lastImport.insertAfter(...snippets.bindingsTypeTs);
@@ -35,7 +35,7 @@ const generate = async (ctx: C3Context) => {
35
35
  // (instead of making it a special case which needs extra care)
36
36
  const newTomlContent = wranglerToml.replace(
37
37
  /#\s+\[\[kv_namespaces\]\]\n#\s+binding\s+=\s+"MY_KV_NAMESPACE"\n#\s+id\s+=\s+"[a-zA-Z0-9]+?"/,
38
- ($1) => `# KV Example:\n${$1}`
38
+ ($1) => `# KV Example:\n${$1}`,
39
39
  );
40
40
 
41
41
  if (!/# KV Example/.test(newTomlContent)) {
@@ -97,7 +97,7 @@ const configure = async (ctx: C3Context) => {
97
97
  if (usesTs) {
98
98
  copyFile(
99
99
  join(getTemplatePath(ctx), "env.d.ts"),
100
- join(projectPath, "env.d.ts")
100
+ join(projectPath, "env.d.ts"),
101
101
  );
102
102
  updateStatus("Created an env.d.ts file");
103
103
  }
@@ -112,7 +112,7 @@ const configure = async (ctx: C3Context) => {
112
112
 
113
113
  copyFile(
114
114
  join(getTemplatePath(ctx), "README.md"),
115
- join(projectPath, "README.md")
115
+ join(projectPath, "README.md"),
116
116
  );
117
117
  updateStatus("Updated the README file");
118
118
 
@@ -120,15 +120,17 @@ const configure = async (ctx: C3Context) => {
120
120
  };
121
121
 
122
122
  export const shouldInstallNextOnPagesEslintPlugin = async (
123
- ctx: C3Context
123
+ ctx: C3Context,
124
124
  ): Promise<boolean> => {
125
125
  const eslintUsage = usesEslint(ctx);
126
126
 
127
- if (!eslintUsage.used) return false;
127
+ if (!eslintUsage.used) {
128
+ return false;
129
+ }
128
130
 
129
131
  if (eslintUsage.configType !== ".eslintrc.json") {
130
132
  warn(
131
- `Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`
133
+ `Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`,
132
134
  );
133
135
  return false;
134
136
  }
@@ -2,7 +2,7 @@ import { logRaw } from "@cloudflare/cli";
2
2
  import { brandColor, dim } from "@cloudflare/cli/colors";
3
3
  import { spinner } from "@cloudflare/cli/interactive";
4
4
  import { runFrameworkGenerator } from "frameworks/index";
5
- import { transformFile } from "helpers/codemod";
5
+ import { mergeObjectProperties, transformFile } from "helpers/codemod";
6
6
  import { getLatestTypesEntrypoint } from "helpers/compatDate";
7
7
  import { readFile, writeFile } from "helpers/files";
8
8
  import { detectPackageManager } from "helpers/packageManagers";
@@ -82,25 +82,24 @@ const updateNuxtConfig = () => {
82
82
  b.objectExpression([
83
83
  b.objectProperty(
84
84
  b.identifier("preset"),
85
- b.stringLiteral("cloudflare-pages")
85
+ b.stringLiteral("cloudflare-pages"),
86
86
  ),
87
- ])
87
+ ]),
88
88
  );
89
89
 
90
90
  const moduleDef = b.objectProperty(
91
91
  b.identifier("modules"),
92
- b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")])
92
+ b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")]),
93
93
  );
94
94
 
95
95
  transformFile(configFile, {
96
96
  visitCallExpression: function (n) {
97
97
  const callee = n.node.callee as recast.types.namedTypes.Identifier;
98
98
  if (callee.name === "defineNuxtConfig") {
99
- const obj = n.node
100
- .arguments[0] as recast.types.namedTypes.ObjectExpression;
101
-
102
- obj.properties.push(presetDef);
103
- obj.properties.push(moduleDef);
99
+ mergeObjectProperties(
100
+ n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
101
+ [presetDef, moduleDef],
102
+ );
104
103
  }
105
104
 
106
105
  return this.traverse(n);
@@ -1,6 +1,6 @@
1
1
  # Cloudflare Workers OpenAPI 3.1
2
2
 
3
- This is a Cloudflare Worker with OpenAPI 3.1 using [itty-router-openapi](https://github.com/cloudflare/itty-router-openapi).
3
+ This is a Cloudflare Worker with OpenAPI 3.1 using [chanfana](https://github.com/cloudflare/chanfana) and [Hono](https://github.com/honojs/hono).
4
4
 
5
5
  This is an example project made to be used as a quick start into building OpenAPI compliant Workers that generates the
6
6
  `openapi.json` schema automatically from code and validates the incoming request to the defined parameters or request body.
@@ -16,10 +16,10 @@ This is an example project made to be used as a quick start into building OpenAP
16
16
 
17
17
  1. Your main router is defined in `src/index.ts`.
18
18
  2. Each endpoint has its own file in `src/endpoints/`.
19
- 3. For more information read the [itty-router-openapi official documentation](https://cloudflare.github.io/itty-router-openapi/).
19
+ 3. For more information read the [chanfana documentation](https://chanfana.pages.dev/) and [Hono documentation](https://hono.dev/docs).
20
20
 
21
21
  ## Development
22
22
 
23
23
  1. Run `wrangler dev` to start a local instance of the API.
24
- 2. Open `http://localhost:9000/` in your browser to see the Swagger interface where you can try the endpoints.
24
+ 2. Open `http://localhost:8787/` in your browser to see the Swagger interface where you can try the endpoints.
25
25
  3. Changes made in the `src/` folder will automatically trigger the server to reload, you only need to refresh the Swagger interface.
@@ -9,11 +9,13 @@
9
9
  "cf-typegen": "wrangler types"
10
10
  },
11
11
  "dependencies": {
12
- "@cloudflare/itty-router-openapi": "^1.0.1"
12
+ "chanfana": "^2.0.2",
13
+ "zod": "^3.23.8",
14
+ "hono": "^4.4.7"
13
15
  },
14
16
  "devDependencies": {
15
- "@types/node": "^20.5.7",
17
+ "@types/node": "20.8.3",
16
18
  "@types/service-worker-mock": "^2.0.1",
17
- "wrangler": "^3.0.0"
19
+ "wrangler": "^3.60.3"
18
20
  }
19
21
  }
@@ -1,33 +1,43 @@
1
- import {
2
- OpenAPIRoute,
3
- OpenAPIRouteSchema,
4
- } from "@cloudflare/itty-router-openapi";
1
+ import { Bool, OpenAPIRoute } from "chanfana";
2
+ import { z } from "zod";
5
3
  import { Task } from "../types";
6
4
 
7
5
  export class TaskCreate extends OpenAPIRoute {
8
- static schema: OpenAPIRouteSchema = {
6
+ schema = {
9
7
  tags: ["Tasks"],
10
8
  summary: "Create a new Task",
11
- requestBody: Task,
9
+ request: {
10
+ body: {
11
+ content: {
12
+ "application/json": {
13
+ schema: Task,
14
+ },
15
+ },
16
+ },
17
+ },
12
18
  responses: {
13
19
  "200": {
14
20
  description: "Returns the created task",
15
- schema: {
16
- success: Boolean,
17
- result: {
18
- task: Task,
21
+ content: {
22
+ "application/json": {
23
+ schema: z.object({
24
+ series: z.object({
25
+ success: Bool(),
26
+ result: z.object({
27
+ task: Task,
28
+ }),
29
+ }),
30
+ }),
19
31
  },
20
32
  },
21
33
  },
22
34
  },
23
35
  };
24
36
 
25
- async handle(
26
- request: Request,
27
- env: any,
28
- context: any,
29
- data: Record<string, any>
30
- ) {
37
+ async handle(c) {
38
+ // Get validated data
39
+ const data = await this.getValidatedData<typeof this.schema>();
40
+
31
41
  // Retrieve the validated request body
32
42
  const taskToCreate = data.body;
33
43
 
@@ -1,38 +1,39 @@
1
- import {
2
- OpenAPIRoute,
3
- OpenAPIRouteSchema,
4
- Path,
5
- } from "@cloudflare/itty-router-openapi";
1
+ import { Bool, OpenAPIRoute, Str } from "chanfana";
2
+ import { z } from "zod";
6
3
  import { Task } from "../types";
7
4
 
8
5
  export class TaskDelete extends OpenAPIRoute {
9
- static schema: OpenAPIRouteSchema = {
6
+ schema = {
10
7
  tags: ["Tasks"],
11
8
  summary: "Delete a Task",
12
- parameters: {
13
- taskSlug: Path(String, {
14
- description: "Task slug",
9
+ request: {
10
+ params: z.object({
11
+ taskSlug: Str({ description: "Task slug" }),
15
12
  }),
16
13
  },
17
14
  responses: {
18
15
  "200": {
19
16
  description: "Returns if the task was deleted successfully",
20
- schema: {
21
- success: Boolean,
22
- result: {
23
- task: Task,
17
+ content: {
18
+ "application/json": {
19
+ schema: z.object({
20
+ series: z.object({
21
+ success: Bool(),
22
+ result: z.object({
23
+ task: Task,
24
+ }),
25
+ }),
26
+ }),
24
27
  },
25
28
  },
26
29
  },
27
30
  },
28
31
  };
29
32
 
30
- async handle(
31
- request: Request,
32
- env: any,
33
- context: any,
34
- data: Record<string, any>
35
- ) {
33
+ async handle(c) {
34
+ // Get validated data
35
+ const data = await this.getValidatedData<typeof this.schema>();
36
+
36
37
  // Retrieve the validated slug
37
38
  const { taskSlug } = data.params;
38
39