@pikku/lambda 0.6.3
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/CHANGELOG.md +42 -0
- package/README.md +3 -0
- package/dist/http/anywhere-http.d.ts +3 -0
- package/dist/http/anywhere-http.js +13 -0
- package/dist/http/anywhere-http.js.map +1 -0
- package/dist/http/cors-http.d.ts +3 -0
- package/dist/http/cors-http.js +35 -0
- package/dist/http/cors-http.js.map +1 -0
- package/dist/http/corsless-http.d.ts +3 -0
- package/dist/http/corsless-http.js +9 -0
- package/dist/http/corsless-http.js.map +1 -0
- package/dist/http/general-http-handler.d.ts +5 -0
- package/dist/http/general-http-handler.js +28 -0
- package/dist/http/general-http-handler.js.map +1 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.js +4 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/pikku-api-gateway-lambda-request.d.ts +12 -0
- package/dist/pikku-api-gateway-lambda-request.js +24 -0
- package/dist/pikku-api-gateway-lambda-request.js.map +1 -0
- package/dist/pikku-api-gateway-lambda-response.d.ts +15 -0
- package/dist/pikku-api-gateway-lambda-response.js +32 -0
- package/dist/pikku-api-gateway-lambda-response.js.map +1 -0
- package/dist/websocket/index.d.ts +4 -0
- package/dist/websocket/index.js +5 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/lambda-channel-handler.d.ts +4 -0
- package/dist/websocket/lambda-channel-handler.js +29 -0
- package/dist/websocket/lambda-channel-handler.js.map +1 -0
- package/dist/websocket/lambda-eventhub-service.d.ts +14 -0
- package/dist/websocket/lambda-eventhub-service.js +27 -0
- package/dist/websocket/lambda-eventhub-service.js.map +1 -0
- package/dist/websocket/utils.d.ts +13 -0
- package/dist/websocket/utils.js +59 -0
- package/dist/websocket/utils.js.map +1 -0
- package/dist/websocket/websocket-connect.d.ts +4 -0
- package/dist/websocket/websocket-connect.js +19 -0
- package/dist/websocket/websocket-connect.js.map +1 -0
- package/dist/websocket/websocket-disconnect.d.ts +4 -0
- package/dist/websocket/websocket-disconnect.js +12 -0
- package/dist/websocket/websocket-disconnect.js.map +1 -0
- package/dist/websocket/websocket-message.d.ts +4 -0
- package/dist/websocket/websocket-message.js +22 -0
- package/dist/websocket/websocket-message.js.map +1 -0
- package/dist/websocket/websocket-types.d.ts +7 -0
- package/dist/websocket/websocket-types.js +2 -0
- package/dist/websocket/websocket-types.js.map +1 -0
- package/package.json +37 -0
- package/run-tests.sh +53 -0
- package/src/http/anywhere-http.ts +39 -0
- package/src/http/cors-http.ts +70 -0
- package/src/http/corsless-http.ts +33 -0
- package/src/http/general-http-handler.ts +59 -0
- package/src/http/index.ts +3 -0
- package/src/index.ts +1 -0
- package/src/pikku-api-gateway-lambda-request.ts +31 -0
- package/src/pikku-api-gateway-lambda-response.ts +41 -0
- package/src/websocket/index.ts +4 -0
- package/src/websocket/lambda-channel-handler.ts +63 -0
- package/src/websocket/lambda-eventhub-service.ts +59 -0
- package/src/websocket/utils.ts +95 -0
- package/src/websocket/websocket-connect.ts +41 -0
- package/src/websocket/websocket-disconnect.ts +35 -0
- package/src/websocket/websocket-message.ts +48 -0
- package/src/websocket/websocket-types.ts +22 -0
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CoreSingletonServices,
|
|
3
|
+
CoreServices,
|
|
4
|
+
CoreUserSession,
|
|
5
|
+
} from '@pikku/core'
|
|
6
|
+
import { runChannelMessage } from '@pikku/core/channel/serverless'
|
|
7
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
|
|
8
|
+
import { PikkuAPIGatewayLambdaResponse } from '../pikku-api-gateway-lambda-response.js'
|
|
9
|
+
import { getServerlessDependencies } from './utils.js'
|
|
10
|
+
import { WebsocketParams } from './websocket-types.js'
|
|
11
|
+
|
|
12
|
+
export const processWebsocketMessage = async <
|
|
13
|
+
SingletonServices extends CoreSingletonServices,
|
|
14
|
+
Services extends CoreServices<SingletonServices>,
|
|
15
|
+
UserSession extends CoreUserSession,
|
|
16
|
+
>(
|
|
17
|
+
event: APIGatewayProxyEvent,
|
|
18
|
+
{
|
|
19
|
+
singletonServices,
|
|
20
|
+
createSessionServices,
|
|
21
|
+
channelStore,
|
|
22
|
+
}: WebsocketParams<SingletonServices, Services, UserSession>
|
|
23
|
+
): Promise<APIGatewayProxyResult> => {
|
|
24
|
+
const runnerParams = getServerlessDependencies(
|
|
25
|
+
singletonServices.logger,
|
|
26
|
+
channelStore,
|
|
27
|
+
event
|
|
28
|
+
)
|
|
29
|
+
const response = new PikkuAPIGatewayLambdaResponse()
|
|
30
|
+
try {
|
|
31
|
+
const result = await runChannelMessage(
|
|
32
|
+
{
|
|
33
|
+
...runnerParams,
|
|
34
|
+
singletonServices: singletonServices as any,
|
|
35
|
+
createSessionServices: createSessionServices as any,
|
|
36
|
+
},
|
|
37
|
+
event.body
|
|
38
|
+
)
|
|
39
|
+
if (result) {
|
|
40
|
+
// TODO: Support non json
|
|
41
|
+
response.setJson(result as any)
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// Error should have already been handled by runHTTPRoute
|
|
45
|
+
console.error(e)
|
|
46
|
+
}
|
|
47
|
+
return response.getLambdaResponse()
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CoreSingletonServices,
|
|
3
|
+
CoreServices,
|
|
4
|
+
CoreUserSession,
|
|
5
|
+
CreateSessionServices,
|
|
6
|
+
MakeRequired,
|
|
7
|
+
} from '@pikku/core'
|
|
8
|
+
import { ChannelStore } from '@pikku/core/channel'
|
|
9
|
+
|
|
10
|
+
export type WebsocketParams<
|
|
11
|
+
SingletonServices extends CoreSingletonServices,
|
|
12
|
+
Services extends CoreServices<SingletonServices>,
|
|
13
|
+
UserSession extends CoreUserSession,
|
|
14
|
+
> = {
|
|
15
|
+
channelStore: ChannelStore
|
|
16
|
+
singletonServices: MakeRequired<SingletonServices, 'eventHub'>
|
|
17
|
+
createSessionServices?: CreateSessionServices<
|
|
18
|
+
SingletonServices,
|
|
19
|
+
Services,
|
|
20
|
+
UserSession
|
|
21
|
+
>
|
|
22
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"module": "Node16",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"target": "esnext",
|
|
8
|
+
"declaration": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["bin/**/*.ts", "src/**/*.ts"],
|
|
11
|
+
"exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
|
|
12
|
+
"references": [
|
|
13
|
+
{
|
|
14
|
+
"path": "../../core/tsconfig.json"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/index.ts","./src/pikku-api-gateway-lambda-request.ts","./src/pikku-api-gateway-lambda-response.ts","./src/http/anywhere-http.ts","./src/http/cors-http.ts","./src/http/corsless-http.ts","./src/http/general-http-handler.ts","./src/http/index.ts","./src/websocket/index.ts","./src/websocket/lambda-channel-handler.ts","./src/websocket/lambda-eventhub-service.ts","./src/websocket/utils.ts","./src/websocket/websocket-connect.ts","./src/websocket/websocket-disconnect.ts","./src/websocket/websocket-message.ts","./src/websocket/websocket-types.ts"],"version":"5.7.3"}
|