Skip to content

Commit

Permalink
refactor: examples to use es6 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 27, 2022
1 parent 83835dd commit 6953f23
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 43 deletions.
4 changes: 1 addition & 3 deletions examples/events/http/handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const { stringify } = JSON

exports.hello = async function hello() {
export async function hello() {
return {
body: stringify({
foo: 'bar',
Expand Down
4 changes: 2 additions & 2 deletions examples/events/http/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "http-example",
"version": "1.0.0",
"main": "handler.js",
"type": "module",
"exports": "./handler.js",
"scripts": {
"start": "serverless offline start"
},
Expand Down
4 changes: 1 addition & 3 deletions examples/events/httpApi/handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const { stringify } = JSON

exports.hello = async function hello() {
export async function hello() {
return {
body: stringify({
foo: 'bar',
Expand Down
4 changes: 2 additions & 2 deletions examples/events/httpApi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "http-example",
"version": "1.0.0",
"main": "handler.js",
"type": "module",
"exports": "./handler.js",
"scripts": {
"start": "serverless offline start"
},
Expand Down
6 changes: 2 additions & 4 deletions examples/events/schedule/handler.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'

exports.schedule1 = async function schedule1() {
export async function schedule1() {
console.log('Scheduler 1 running ...')
}

exports.schedule2 = async function schedule2(event) {
export async function schedule2(event) {
console.log('Scheduler 2 running ...', event)
}
4 changes: 2 additions & 2 deletions examples/events/schedule/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "schedule-example",
"version": "1.0.0",
"main": "handler.js",
"type": "module",
"exports": "./handler.js",
"scripts": {
"start": "serverless offline start"
},
Expand Down
21 changes: 13 additions & 8 deletions examples/events/websocket/handler.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
'use strict'

const { stringify } = JSON

exports.connect = async function connect() {
export async function connect() {
return {
body: stringify({ foo: 'bar' }),
body: stringify({
foo: 'bar',
}),
statusCode: 200,
}
}

exports.disconnect = async function disconnect() {
export async function disconnect() {
return {
body: stringify({ foo: 'bar' }),
body: stringify({
foo: 'bar',
}),
statusCode: 200,
}
}

exports.default = async function _default() {
// eslint-disable-next-line no-underscore-dangle
export async function _default() {
return {
body: stringify({ foo: 'bar' }),
body: stringify({
foo: 'bar',
}),
statusCode: 200,
}
}
4 changes: 2 additions & 2 deletions examples/events/websocket/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "websocket-example",
"version": "1.0.0",
"main": "handler.js",
"type": "module",
"exports": "./handler.js",
"scripts": {
"start": "serverless offline start"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/events/websocket/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ functions:
events:
- websocket:
route: $default
handler: handler.default
handler: handler._default
18 changes: 9 additions & 9 deletions examples/lambda-invoke/handler.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
'use strict'

const { Buffer } = require('node:buffer')
const { config, Lambda } = require('aws-sdk')
import { Buffer } from 'node:buffer'
import aws from 'aws-sdk'

const { stringify } = JSON

config.update({
aws.config.update({
accessKeyId: 'ABC',
secretAccessKey: 'SECRET',
})

const lambda = new Lambda({
const lambda = new aws.Lambda({
apiVersion: '2015-03-31',
endpoint: 'http://localhost:3002',
})

exports.hello = async function hello() {
export async function hello() {
const clientContextData = stringify({
foo: 'foo',
})
Expand All @@ -24,7 +22,9 @@ exports.hello = async function hello() {
ClientContext: Buffer.from(clientContextData).toString('base64'),
FunctionName: 'lambda-invoke-dev-toBeInvoked',
InvocationType: 'RequestResponse',
Payload: stringify({ bar: 'bar' }),
Payload: stringify({
bar: 'bar',
}),
}

const response = await lambda.invoke(params).promise()
Expand All @@ -35,7 +35,7 @@ exports.hello = async function hello() {
}
}

exports.toBeInvoked = async function toBeInvoked(event, context) {
export async function toBeInvoked(event, context) {
return {
clientContext: context.clientContext,
event,
Expand Down
4 changes: 2 additions & 2 deletions examples/lambda-invoke/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lambda-invoke-example",
"version": "1.0.0",
"main": "handler.js",
"type": "module",
"exports": "./handler.js",
"scripts": {
"start": "serverless offline start"
},
Expand Down
3 changes: 2 additions & 1 deletion examples/tools/nodemon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "nodemon-example",
"version": "1.0.0",
"type": "module",
"exports": "./src/handler.js",
"scripts": {
"start": "nodemon ./node_modules/.bin/serverless offline start",
"start:alt": "nodemon --exec serverless offline start"
Expand Down
4 changes: 1 addition & 3 deletions examples/tools/nodemon/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const { stringify } = JSON

exports.hello = async function hello() {
export async function hello() {
return {
body: stringify({
hello: 'nodemon',
Expand Down
1 change: 1 addition & 0 deletions examples/tools/serverless-plugin-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "serverless-plugin-typescript-example",
"type": "module",
"devDependencies": {
"@types/aws-lambda": "8.10.102",
"serverless": "3.22.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/tools/serverless-plugin-typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "ES2020",
"moduleResolution": "Node",
"strictNullChecks": true,
"strict": true,
"target": "ES2020"
}
}

0 comments on commit 6953f23

Please sign in to comment.