Skip to content

Commit

Permalink
feat: update function templates to v2 (#6939)
Browse files Browse the repository at this point in the history
* feat: hello-world js example to mjs

* feat: remove identity example

* feat: remove sanity templates

* feat: scheduled function to esm

* feat: remove submission-create example because 3rd party docs out of date

* feat: typescript hello world and make js same

* feat: typescript scheduled function

* test: update tests
  • Loading branch information
sarahetter authored Nov 29, 2024
1 parent 4e668f2 commit 40dafd5
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 326 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = {
},
// Example functions
{
files: ['functions-templates/**/*.js'],
files: ['functions-templates/**/*.mjs', 'functions-templates/**/*.mts'],
rules: {
'require-await': 0,
'import/no-unresolved': 0,
Expand All @@ -80,6 +80,8 @@ module.exports = {
'no-undef': 0,
'no-unused-vars': 0,
'arrow-body-style': 0,
'n/no-unsupported-features/node-builtins': 0,
camelcase: 0,
},
parserOptions: {
sourceType: 'module',
Expand Down
17 changes: 0 additions & 17 deletions functions-templates/javascript/hello-world/{{name}}.js

This file was deleted.

13 changes: 13 additions & 0 deletions functions-templates/javascript/hello-world/{{name}}.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Docs on request and context https://docs.netlify.com/functions/build/#code-your-function-2
export default (request, context) => {
try {
const url = new URL(request.url)
const subject = url.searchParams.get('name') || 'World'

return new Response(`Hello ${subject}`)
} catch (error) {
return new Response(error.toString(), {
status: 500,
})
}
}

This file was deleted.

29 changes: 0 additions & 29 deletions functions-templates/javascript/identity-signup/{{name}}.js

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions functions-templates/javascript/sanity-create/package.json

This file was deleted.

72 changes: 0 additions & 72 deletions functions-templates/javascript/sanity-create/{{name}}.js

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions functions-templates/javascript/sanity-groq/package.json

This file was deleted.

56 changes: 0 additions & 56 deletions functions-templates/javascript/sanity-groq/{{name}}.js

This file was deleted.

12 changes: 0 additions & 12 deletions functions-templates/javascript/scheduled-function/{{name}}.js

This file was deleted.

11 changes: 11 additions & 0 deletions functions-templates/javascript/scheduled-function/{{name}}.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// To learn about scheduled functions and supported cron extensions,
// see: https://ntl.fyi/sched-func
export default async (req) => {
const { next_run } = await req.json()

console.log('Received event! Next invocation at:', next_run)
}

export const config = {
schedule: '@hourly',
}

This file was deleted.

19 changes: 0 additions & 19 deletions functions-templates/javascript/submission-created/package.json

This file was deleted.

29 changes: 0 additions & 29 deletions functions-templates/javascript/submission-created/{{name}}.js

This file was deleted.

14 changes: 14 additions & 0 deletions functions-templates/typescript/hello-world/{{name}}.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Context } from '@netlify/functions'

export default (request: Request, context: Context) => {
try {
const url = new URL(request.url)
const subject = url.searchParams.get('name') || 'World'

return new Response(`Hello ${subject}`)
} catch (error) {
return new Response(error.toString(), {
status: 500,
})
}
}
12 changes: 0 additions & 12 deletions functions-templates/typescript/hello-world/{{name}}.ts

This file was deleted.

11 changes: 11 additions & 0 deletions functions-templates/typescript/scheduled-function/{{name}}.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Config } from "@netlify/functions"

export default async (req: Request) => {
const { next_run } = await req.json()

console.log("Received event! Next invocation at:", next_run)
}

export const config: Config = {
schedule: "@hourly"
}
Loading

0 comments on commit 40dafd5

Please sign in to comment.